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/ip/ip_source_and_port_range_check.h>
49 #include <vnet/policer/xlate.h>
50 #include <vnet/policer/policer.h>
51 #include <vnet/policer/police.h>
53 #include "vat/json_format.h"
57 #define vl_typedefs /* define message structures */
58 #include <vpp-api/vpe_all_api_h.h>
61 /* declare message handlers for each api */
63 #define vl_endianfun /* define message structures */
64 #include <vpp-api/vpe_all_api_h.h>
67 /* instantiate all the print functions we know about */
68 #define vl_print(handle, ...)
70 #include <vpp-api/vpe_all_api_h.h>
73 uword unformat_sw_if_index (unformat_input_t * input, va_list * args)
75 vat_main_t * vam = va_arg (*args, vat_main_t *);
76 u32 * result = va_arg (*args, u32 *);
80 if (!unformat (input, "%s", &if_name))
83 p = hash_get_mem (vam->sw_if_index_by_interface_name, if_name);
90 /* Parse an IP4 address %d.%d.%d.%d. */
91 uword unformat_ip4_address (unformat_input_t * input, va_list * args)
93 u8 * result = va_arg (*args, u8 *);
96 if (! unformat (input, "%d.%d.%d.%d", &a[0], &a[1], &a[2], &a[3]))
99 if (a[0] >= 256 || a[1] >= 256 || a[2] >= 256 || a[3] >= 256)
112 unformat_ethernet_address (unformat_input_t * input, va_list * args)
114 u8 * result = va_arg (*args, u8 *);
117 if (! unformat (input, "%_%x:%x:%x:%x:%x:%x%_",
118 &a[0], &a[1], &a[2], &a[3], &a[4], &a[5]))
122 for (i = 0; i < 6; i++)
123 if (a[i] >= (1 << 8))
126 for (i = 0; i < 6; i++)
132 /* Returns ethernet type as an int in host byte order. */
134 unformat_ethernet_type_host_byte_order (unformat_input_t * input,
137 u16 * result = va_arg (*args, u16 *);
141 if (unformat (input, "0x%x", &type)
142 || unformat (input, "%d", &type))
144 if (type >= (1 << 16))
152 /* Parse an IP6 address. */
153 uword unformat_ip6_address (unformat_input_t * input, va_list * args)
155 ip6_address_t * result = va_arg (*args, ip6_address_t *);
157 uword hex_quad, n_hex_quads, hex_digit, n_hex_digits;
158 uword c, n_colon, double_colon_index;
160 n_hex_quads = hex_quad = n_hex_digits = n_colon = 0;
161 double_colon_index = ARRAY_LEN (hex_quads);
162 while ((c = unformat_get_input (input)) != UNFORMAT_END_OF_INPUT)
165 if (c >= '0' && c <= '9')
167 else if (c >= 'a' && c <= 'f')
168 hex_digit = c + 10 - 'a';
169 else if (c >= 'A' && c <= 'F')
170 hex_digit = c + 10 - 'A';
171 else if (c == ':' && n_colon < 2)
175 unformat_put_input (input);
179 /* Too many hex quads. */
180 if (n_hex_quads >= ARRAY_LEN (hex_quads))
185 hex_quad = (hex_quad << 4) | hex_digit;
187 /* Hex quad must fit in 16 bits. */
188 if (n_hex_digits >= 4)
195 /* Save position of :: */
198 /* More than one :: ? */
199 if (double_colon_index < ARRAY_LEN (hex_quads))
201 double_colon_index = n_hex_quads;
204 if (n_colon > 0 && n_hex_digits > 0)
206 hex_quads[n_hex_quads++] = hex_quad;
212 if (n_hex_digits > 0)
213 hex_quads[n_hex_quads++] = hex_quad;
218 /* Expand :: to appropriate number of zero hex quads. */
219 if (double_colon_index < ARRAY_LEN (hex_quads))
221 word n_zero = ARRAY_LEN (hex_quads) - n_hex_quads;
223 for (i = n_hex_quads - 1; i >= (signed) double_colon_index; i--)
224 hex_quads[n_zero + i] = hex_quads[i];
226 for (i = 0; i < n_zero; i++)
227 hex_quads[double_colon_index + i] = 0;
229 n_hex_quads = ARRAY_LEN (hex_quads);
232 /* Too few hex quads given. */
233 if (n_hex_quads < ARRAY_LEN (hex_quads))
236 for (i = 0; i < ARRAY_LEN (hex_quads); i++)
237 result->as_u16[i] = clib_host_to_net_u16 (hex_quads[i]);
244 unformat_ipsec_policy_action (unformat_input_t * input, va_list * args)
247 u32 * r = va_arg (*args, u32 *);
250 #define _(v,f,s) else if (unformat (input, s)) *r = IPSEC_POLICY_ACTION_##f;
251 foreach_ipsec_policy_action
262 unformat_ipsec_crypto_alg (unformat_input_t * input, va_list * args)
265 u32 * r = va_arg (*args, u32 *);
268 #define _(v,f,s) else if (unformat (input, s)) *r = IPSEC_CRYPTO_ALG_##f;
269 foreach_ipsec_crypto_alg
280 format_ipsec_crypto_alg (u8 * s, va_list * args)
283 u32 i = va_arg (*args, u32);
288 #define _(v,f,str) case IPSEC_CRYPTO_ALG_##f: t = (u8 *) str; break;
289 foreach_ipsec_crypto_alg
292 return format (s, "unknown");
294 return format (s, "%s", t);
296 return format (s, "Unimplemented");
301 unformat_ipsec_integ_alg (unformat_input_t * input, va_list * args)
304 u32 * r = va_arg (*args, u32 *);
307 #define _(v,f,s) else if (unformat (input, s)) *r = IPSEC_INTEG_ALG_##f;
308 foreach_ipsec_integ_alg
319 format_ipsec_integ_alg (u8 * s, va_list * args)
322 u32 i = va_arg (*args, u32);
327 #define _(v,f,str) case IPSEC_INTEG_ALG_##f: t = (u8 *) str; break;
328 foreach_ipsec_integ_alg
331 return format (s, "unknown");
333 return format (s, "%s", t);
335 return format (s, "Unsupported");
340 unformat_ikev2_auth_method (unformat_input_t * input, va_list * args)
343 u32 * r = va_arg (*args, u32 *);
346 #define _(v,f,s) else if (unformat (input, s)) *r = IKEV2_AUTH_METHOD_##f;
347 foreach_ikev2_auth_method
358 unformat_ikev2_id_type (unformat_input_t * input, va_list * args)
361 u32 * r = va_arg (*args, u32 *);
364 #define _(v,f,s) else if (unformat (input, s)) *r = IKEV2_ID_TYPE_##f;
365 foreach_ikev2_id_type
376 unformat_policer_rate_type (unformat_input_t * input, va_list * args)
378 u8 * r = va_arg (*args, u8 *);
380 if (unformat (input, "kbps"))
381 *r = SSE2_QOS_RATE_KBPS;
382 else if (unformat(input, "pps"))
383 *r = SSE2_QOS_RATE_PPS;
390 unformat_policer_round_type (unformat_input_t * input, va_list * args)
392 u8 * r = va_arg (*args, u8 *);
394 if (unformat(input, "closest"))
395 *r = SSE2_QOS_ROUND_TO_CLOSEST;
396 else if (unformat (input, "up"))
397 *r = SSE2_QOS_ROUND_TO_UP;
398 else if (unformat (input, "down"))
399 *r = SSE2_QOS_ROUND_TO_DOWN;
406 unformat_policer_type (unformat_input_t * input, va_list * args)
408 u8 * r = va_arg (*args, u8 *);
410 if (unformat (input, "1r2c"))
411 *r = SSE2_QOS_POLICER_TYPE_1R2C;
412 else if (unformat (input, "1r3c"))
413 *r = SSE2_QOS_POLICER_TYPE_1R3C_RFC_2697;
414 else if (unformat (input, "2r3c-2698"))
415 *r = SSE2_QOS_POLICER_TYPE_2R3C_RFC_2698;
416 else if (unformat (input, "2r3c-4115"))
417 *r = SSE2_QOS_POLICER_TYPE_2R3C_RFC_4115;
418 else if (unformat (input, "2r3c-mef5cf1"))
419 *r = SSE2_QOS_POLICER_TYPE_2R3C_RFC_MEF5CF1;
426 unformat_dscp (unformat_input_t * input, va_list * va)
428 u8 * r = va_arg (*va, u8 *);
431 #define _(v,f,str) else if (unformat (input, str)) *r = VNET_DSCP_##f;
440 unformat_policer_action_type (unformat_input_t * input, va_list * va)
442 sse2_qos_pol_action_params_st * a
443 = va_arg (*va, sse2_qos_pol_action_params_st *);
445 if (unformat (input, "drop"))
446 a->action_type = SSE2_QOS_ACTION_DROP;
447 else if (unformat (input, "transmit"))
448 a->action_type = SSE2_QOS_ACTION_TRANSMIT;
449 else if (unformat (input, "mark-and-transmit %U", unformat_dscp, &a->dscp))
450 a->action_type = SSE2_QOS_ACTION_MARK_AND_TRANSMIT;
457 unformat_classify_table_type (unformat_input_t * input, va_list * va)
459 u32 * r = va_arg (*va, u32 *);
462 if (unformat (input, "ip4"))
463 tid = POLICER_CLASSIFY_TABLE_IP4;
464 else if (unformat (input, "ip6"))
465 tid = POLICER_CLASSIFY_TABLE_IP6;
466 else if (unformat (input, "l2"))
467 tid = POLICER_CLASSIFY_TABLE_L2;
475 u8 * format_ip4_address (u8 * s, va_list * args)
477 u8 * a = va_arg (*args, u8 *);
478 return format (s, "%d.%d.%d.%d", a[0], a[1], a[2], a[3]);
481 u8 * format_ip6_address (u8 * s, va_list * args)
483 ip6_address_t * a = va_arg (*args, ip6_address_t *);
484 u32 i, i_max_n_zero, max_n_zeros, i_first_zero, n_zeros, last_double_colon;
486 i_max_n_zero = ARRAY_LEN (a->as_u16);
488 i_first_zero = i_max_n_zero;
490 for (i = 0; i < ARRAY_LEN (a->as_u16); i++)
492 u32 is_zero = a->as_u16[i] == 0;
493 if (is_zero && i_first_zero >= ARRAY_LEN (a->as_u16))
499 if ((! is_zero && n_zeros > max_n_zeros)
500 || (i + 1 >= ARRAY_LEN (a->as_u16) && n_zeros > max_n_zeros))
502 i_max_n_zero = i_first_zero;
503 max_n_zeros = n_zeros;
504 i_first_zero = ARRAY_LEN (a->as_u16);
509 last_double_colon = 0;
510 for (i = 0; i < ARRAY_LEN (a->as_u16); i++)
512 if (i == i_max_n_zero && max_n_zeros > 1)
514 s = format (s, "::");
515 i += max_n_zeros - 1;
516 last_double_colon = 1;
520 s = format (s, "%s%x",
521 (last_double_colon || i == 0) ? "" : ":",
522 clib_net_to_host_u16 (a->as_u16[i]));
523 last_double_colon = 0;
530 /* Format an IP46 address. */
531 u8 * format_ip46_address (u8 * s, va_list * args)
533 ip46_address_t *ip46 = va_arg (*args, ip46_address_t *);
534 ip46_type_t type = va_arg (*args, ip46_type_t);
540 is_ip4 = ip46_address_is_ip4(ip46);
551 format(s, "%U", format_ip4_address, &ip46->ip4):
552 format(s, "%U", format_ip6_address, &ip46->ip6);
555 u8 * format_ethernet_address (u8 * s, va_list * args)
557 u8 * a = va_arg (*args, u8 *);
559 return format (s, "%02x:%02x:%02x:%02x:%02x:%02x",
560 a[0], a[1], a[2], a[3], a[4], a[5]);
563 void increment_v4_address (ip4_address_t * a)
567 v = ntohl(a->as_u32) + 1;
568 a->as_u32 = ntohl(v);
571 void increment_v6_address (ip6_address_t * a)
575 v0 = clib_net_to_host_u64 (a->as_u64[0]);
576 v1 = clib_net_to_host_u64 (a->as_u64[1]);
581 a->as_u64[0] = clib_net_to_host_u64 (v0);
582 a->as_u64[1] = clib_net_to_host_u64 (v1);
585 void increment_mac_address (u64 *mac)
589 tmp = clib_net_to_host_u64(tmp);
590 tmp += 1<<16; /* skip unused (least significant) octets */
591 tmp = clib_host_to_net_u64 (tmp);
595 static void vl_api_create_loopback_reply_t_handler
596 (vl_api_create_loopback_reply_t * mp)
598 vat_main_t * vam = &vat_main;
599 i32 retval = ntohl(mp->retval);
601 vam->retval = retval;
602 vam->regenerate_interface_table = 1;
603 vam->sw_if_index = ntohl (mp->sw_if_index);
604 vam->result_ready = 1;
607 static void vl_api_create_loopback_reply_t_handler_json
608 (vl_api_create_loopback_reply_t * mp)
610 vat_main_t * vam = &vat_main;
611 vat_json_node_t node;
613 vat_json_init_object(&node);
614 vat_json_object_add_int(&node, "retval", ntohl(mp->retval));
615 vat_json_object_add_uint(&node, "sw_if_index", ntohl(mp->sw_if_index));
617 vat_json_print(vam->ofp, &node);
618 vat_json_free(&node);
619 vam->retval = ntohl(mp->retval);
620 vam->result_ready = 1;
623 static void vl_api_af_packet_create_reply_t_handler
624 (vl_api_af_packet_create_reply_t * mp)
626 vat_main_t * vam = &vat_main;
627 i32 retval = ntohl(mp->retval);
629 vam->retval = retval;
630 vam->regenerate_interface_table = 1;
631 vam->sw_if_index = ntohl (mp->sw_if_index);
632 vam->result_ready = 1;
635 static void vl_api_af_packet_create_reply_t_handler_json
636 (vl_api_af_packet_create_reply_t * mp)
638 vat_main_t * vam = &vat_main;
639 vat_json_node_t node;
641 vat_json_init_object(&node);
642 vat_json_object_add_int(&node, "retval", ntohl(mp->retval));
643 vat_json_object_add_uint(&node, "sw_if_index", ntohl(mp->sw_if_index));
645 vat_json_print(vam->ofp, &node);
646 vat_json_free(&node);
648 vam->retval = ntohl(mp->retval);
649 vam->result_ready = 1;
652 static void vl_api_create_vlan_subif_reply_t_handler
653 (vl_api_create_vlan_subif_reply_t * mp)
655 vat_main_t * vam = &vat_main;
656 i32 retval = ntohl(mp->retval);
658 vam->retval = retval;
659 vam->regenerate_interface_table = 1;
660 vam->sw_if_index = ntohl (mp->sw_if_index);
661 vam->result_ready = 1;
664 static void vl_api_create_vlan_subif_reply_t_handler_json
665 (vl_api_create_vlan_subif_reply_t * mp)
667 vat_main_t * vam = &vat_main;
668 vat_json_node_t node;
670 vat_json_init_object(&node);
671 vat_json_object_add_int(&node, "retval", ntohl(mp->retval));
672 vat_json_object_add_uint(&node, "sw_if_index", ntohl(mp->sw_if_index));
674 vat_json_print(vam->ofp, &node);
675 vat_json_free(&node);
677 vam->retval = ntohl(mp->retval);
678 vam->result_ready = 1;
681 static void vl_api_create_subif_reply_t_handler
682 (vl_api_create_subif_reply_t * mp)
684 vat_main_t * vam = &vat_main;
685 i32 retval = ntohl(mp->retval);
687 vam->retval = retval;
688 vam->regenerate_interface_table = 1;
689 vam->sw_if_index = ntohl (mp->sw_if_index);
690 vam->result_ready = 1;
693 static void vl_api_create_subif_reply_t_handler_json
694 (vl_api_create_subif_reply_t * mp)
696 vat_main_t * vam = &vat_main;
697 vat_json_node_t node;
699 vat_json_init_object(&node);
700 vat_json_object_add_int(&node, "retval", ntohl(mp->retval));
701 vat_json_object_add_uint(&node, "sw_if_index", ntohl(mp->sw_if_index));
703 vat_json_print(vam->ofp, &node);
704 vat_json_free(&node);
706 vam->retval = ntohl(mp->retval);
707 vam->result_ready = 1;
710 static void vl_api_interface_name_renumber_reply_t_handler
711 (vl_api_interface_name_renumber_reply_t * mp)
713 vat_main_t * vam = &vat_main;
714 i32 retval = ntohl(mp->retval);
716 vam->retval = retval;
717 vam->regenerate_interface_table = 1;
718 vam->result_ready = 1;
721 static void vl_api_interface_name_renumber_reply_t_handler_json
722 (vl_api_interface_name_renumber_reply_t * mp)
724 vat_main_t * vam = &vat_main;
725 vat_json_node_t node;
727 vat_json_init_object(&node);
728 vat_json_object_add_int(&node, "retval", ntohl(mp->retval));
730 vat_json_print(vam->ofp, &node);
731 vat_json_free(&node);
733 vam->retval = ntohl(mp->retval);
734 vam->result_ready = 1;
738 * Special-case: build the interface table, maintain
739 * the next loopback sw_if_index vbl.
741 static void vl_api_sw_interface_details_t_handler
742 (vl_api_sw_interface_details_t * mp)
744 vat_main_t * vam = &vat_main;
745 u8 * s = format (0, "%s%c", mp->interface_name, 0);
747 hash_set_mem (vam->sw_if_index_by_interface_name, s,
748 ntohl(mp->sw_if_index));
750 /* In sub interface case, fill the sub interface table entry */
751 if (mp->sw_if_index != mp->sup_sw_if_index) {
752 sw_interface_subif_t * sub = NULL;
754 vec_add2(vam->sw_if_subif_table, sub, 1);
756 vec_validate(sub->interface_name, strlen((char *)s) + 1);
757 strncpy((char *)sub->interface_name, (char *)s,
758 vec_len(sub->interface_name));
759 sub->sw_if_index = ntohl(mp->sw_if_index);
760 sub->sub_id = ntohl(mp->sub_id);
762 sub->sub_dot1ad = mp->sub_dot1ad;
763 sub->sub_number_of_tags = mp->sub_number_of_tags;
764 sub->sub_outer_vlan_id = ntohs(mp->sub_outer_vlan_id);
765 sub->sub_inner_vlan_id = ntohs(mp->sub_inner_vlan_id);
766 sub->sub_exact_match = mp->sub_exact_match;
767 sub->sub_default = mp->sub_default;
768 sub->sub_outer_vlan_id_any = mp->sub_outer_vlan_id_any;
769 sub->sub_inner_vlan_id_any = mp->sub_inner_vlan_id_any;
771 /* vlan tag rewrite */
772 sub->vtr_op = ntohl(mp->vtr_op);
773 sub->vtr_push_dot1q = ntohl(mp->vtr_push_dot1q);
774 sub->vtr_tag1 = ntohl(mp->vtr_tag1);
775 sub->vtr_tag2 = ntohl(mp->vtr_tag2);
779 static void vl_api_sw_interface_details_t_handler_json
780 (vl_api_sw_interface_details_t * mp)
782 vat_main_t * vam = &vat_main;
783 vat_json_node_t *node = NULL;
785 if (VAT_JSON_ARRAY != vam->json_tree.type) {
786 ASSERT(VAT_JSON_NONE == vam->json_tree.type);
787 vat_json_init_array(&vam->json_tree);
789 node = vat_json_array_add(&vam->json_tree);
791 vat_json_init_object(node);
792 vat_json_object_add_uint(node, "sw_if_index", ntohl(mp->sw_if_index));
793 vat_json_object_add_uint(node, "sup_sw_if_index", ntohl(mp->sup_sw_if_index));
794 vat_json_object_add_uint(node, "l2_address_length", ntohl(mp->l2_address_length));
795 vat_json_object_add_bytes(node, "l2_address", mp->l2_address, sizeof(mp->l2_address));
796 vat_json_object_add_string_copy(node, "interface_name", mp->interface_name);
797 vat_json_object_add_uint(node, "admin_up_down", mp->admin_up_down);
798 vat_json_object_add_uint(node, "link_up_down", mp->link_up_down);
799 vat_json_object_add_uint(node, "link_duplex", mp->link_duplex);
800 vat_json_object_add_uint(node, "link_speed", mp->link_speed);
801 vat_json_object_add_uint(node, "mtu", ntohs(mp->link_mtu));
802 vat_json_object_add_uint(node, "sub_id", ntohl(mp->sub_id));
803 vat_json_object_add_uint(node, "sub_dot1ad", mp->sub_dot1ad);
804 vat_json_object_add_uint(node, "sub_number_of_tags", mp->sub_number_of_tags);
805 vat_json_object_add_uint(node, "sub_outer_vlan_id", ntohs(mp->sub_outer_vlan_id));
806 vat_json_object_add_uint(node, "sub_inner_vlan_id", ntohs(mp->sub_inner_vlan_id));
807 vat_json_object_add_uint(node, "sub_exact_match", mp->sub_exact_match);
808 vat_json_object_add_uint(node, "sub_default", mp->sub_default);
809 vat_json_object_add_uint(node, "sub_outer_vlan_id_any", mp->sub_outer_vlan_id_any);
810 vat_json_object_add_uint(node, "sub_inner_vlan_id_any", mp->sub_inner_vlan_id_any);
811 vat_json_object_add_uint(node, "vtr_op", ntohl(mp->vtr_op));
812 vat_json_object_add_uint(node, "vtr_push_dot1q", ntohl(mp->vtr_push_dot1q));
813 vat_json_object_add_uint(node, "vtr_tag1", ntohl(mp->vtr_tag1));
814 vat_json_object_add_uint(node, "vtr_tag2", ntohl(mp->vtr_tag2));
817 static void vl_api_sw_interface_set_flags_t_handler
818 (vl_api_sw_interface_set_flags_t * mp)
820 vat_main_t * vam = &vat_main;
821 if (vam->interface_event_display)
822 errmsg ("interface flags: sw_if_index %d %s %s\n",
823 ntohl(mp->sw_if_index),
824 mp->admin_up_down ? "admin-up" : "admin-down",
825 mp->link_up_down ? "link-up" : "link-down");
828 static void vl_api_sw_interface_set_flags_t_handler_json
829 (vl_api_sw_interface_set_flags_t * mp)
831 /* JSON output not supported */
834 static void vl_api_cli_reply_t_handler
835 (vl_api_cli_reply_t * mp)
837 vat_main_t * vam = &vat_main;
838 i32 retval = ntohl(mp->retval);
840 vam->retval = retval;
841 vam->shmem_result = (u8 *) mp->reply_in_shmem;
842 vam->result_ready = 1;
845 static void vl_api_cli_reply_t_handler_json
846 (vl_api_cli_reply_t * mp)
848 vat_main_t * vam = &vat_main;
849 vat_json_node_t node;
850 api_main_t * am = &api_main;
854 vat_json_init_object(&node);
855 vat_json_object_add_int(&node, "retval", ntohl(mp->retval));
856 vat_json_object_add_uint(&node, "reply_in_shmem",
857 ntohl(mp->reply_in_shmem));
858 /* Toss the shared-memory original... */
859 pthread_mutex_lock (&am->vlib_rp->mutex);
860 oldheap = svm_push_data_heap (am->vlib_rp);
862 reply = (u8 *)(mp->reply_in_shmem);
865 svm_pop_heap (oldheap);
866 pthread_mutex_unlock (&am->vlib_rp->mutex);
868 vat_json_print(vam->ofp, &node);
869 vat_json_free(&node);
871 vam->retval = ntohl(mp->retval);
872 vam->result_ready = 1;
875 static void vl_api_classify_add_del_table_reply_t_handler
876 (vl_api_classify_add_del_table_reply_t * mp)
878 vat_main_t * vam = &vat_main;
879 i32 retval = ntohl(mp->retval);
880 if (vam->async_mode) {
881 vam->async_errors += (retval < 0);
883 vam->retval = retval;
885 ((mp->new_table_index != 0xFFFFFFFF) ||
886 (mp->skip_n_vectors != 0xFFFFFFFF) ||
887 (mp->match_n_vectors != 0xFFFFFFFF)))
889 * Note: this is just barely thread-safe, depends on
890 * the main thread spinning waiting for an answer...
892 errmsg ("new index %d, skip_n_vectors %d, match_n_vectors %d\n",
893 ntohl(mp->new_table_index),
894 ntohl(mp->skip_n_vectors), ntohl(mp->match_n_vectors));
895 vam->result_ready = 1;
899 static void vl_api_classify_add_del_table_reply_t_handler_json
900 (vl_api_classify_add_del_table_reply_t * mp)
902 vat_main_t * vam = &vat_main;
903 vat_json_node_t node;
905 vat_json_init_object(&node);
906 vat_json_object_add_int(&node, "retval", ntohl(mp->retval));
907 vat_json_object_add_uint(&node, "new_table_index", ntohl(mp->new_table_index));
908 vat_json_object_add_uint(&node, "skip_n_vectors", ntohl(mp->skip_n_vectors));
909 vat_json_object_add_uint(&node, "match_n_vectors", ntohl(mp->match_n_vectors));
911 vat_json_print(vam->ofp, &node);
912 vat_json_free(&node);
914 vam->retval = ntohl(mp->retval);
915 vam->result_ready = 1;
918 static void vl_api_get_node_index_reply_t_handler
919 (vl_api_get_node_index_reply_t * mp)
921 vat_main_t * vam = &vat_main;
922 i32 retval = ntohl(mp->retval);
923 if (vam->async_mode) {
924 vam->async_errors += (retval < 0);
926 vam->retval = retval;
928 errmsg ("node index %d\n", ntohl(mp->node_index));
929 vam->result_ready = 1;
933 static void vl_api_get_node_index_reply_t_handler_json
934 (vl_api_get_node_index_reply_t * mp)
936 vat_main_t * vam = &vat_main;
937 vat_json_node_t node;
939 vat_json_init_object(&node);
940 vat_json_object_add_int(&node, "retval", ntohl(mp->retval));
941 vat_json_object_add_uint(&node, "node_index", ntohl(mp->node_index));
943 vat_json_print(vam->ofp, &node);
944 vat_json_free(&node);
946 vam->retval = ntohl(mp->retval);
947 vam->result_ready = 1;
950 static void vl_api_get_next_index_reply_t_handler
951 (vl_api_get_next_index_reply_t * mp)
953 vat_main_t * vam = &vat_main;
954 i32 retval = ntohl(mp->retval);
955 if (vam->async_mode) {
956 vam->async_errors += (retval < 0);
958 vam->retval = retval;
960 errmsg ("next node index %d\n", ntohl(mp->next_index));
961 vam->result_ready = 1;
965 static void vl_api_get_next_index_reply_t_handler_json
966 (vl_api_get_next_index_reply_t * mp)
968 vat_main_t * vam = &vat_main;
969 vat_json_node_t node;
971 vat_json_init_object(&node);
972 vat_json_object_add_int(&node, "retval", ntohl(mp->retval));
973 vat_json_object_add_uint(&node, "next_index", ntohl(mp->next_index));
975 vat_json_print(vam->ofp, &node);
976 vat_json_free(&node);
978 vam->retval = ntohl(mp->retval);
979 vam->result_ready = 1;
982 static void vl_api_add_node_next_reply_t_handler
983 (vl_api_add_node_next_reply_t * mp)
985 vat_main_t * vam = &vat_main;
986 i32 retval = ntohl(mp->retval);
987 if (vam->async_mode) {
988 vam->async_errors += (retval < 0);
990 vam->retval = retval;
992 errmsg ("next index %d\n", ntohl(mp->next_index));
993 vam->result_ready = 1;
997 static void vl_api_add_node_next_reply_t_handler_json
998 (vl_api_add_node_next_reply_t * mp)
1000 vat_main_t * vam = &vat_main;
1001 vat_json_node_t node;
1003 vat_json_init_object(&node);
1004 vat_json_object_add_int(&node, "retval", ntohl(mp->retval));
1005 vat_json_object_add_uint(&node, "next_index", ntohl(mp->next_index));
1007 vat_json_print(vam->ofp, &node);
1008 vat_json_free(&node);
1010 vam->retval = ntohl(mp->retval);
1011 vam->result_ready = 1;
1014 static void vl_api_mpls_gre_add_del_tunnel_reply_t_handler
1015 (vl_api_mpls_gre_add_del_tunnel_reply_t * mp)
1017 vat_main_t * vam = &vat_main;
1018 i32 retval = ntohl(mp->retval);
1019 u32 sw_if_index = ntohl(mp->tunnel_sw_if_index);
1021 if (retval >= 0 && sw_if_index != (u32)~0) {
1022 errmsg ("tunnel_sw_if_index %d\n", sw_if_index);
1024 vam->retval = retval;
1025 vam->result_ready = 1;
1028 static void vl_api_mpls_gre_add_del_tunnel_reply_t_handler_json
1029 (vl_api_mpls_gre_add_del_tunnel_reply_t * mp)
1031 vat_main_t * vam = &vat_main;
1032 vat_json_node_t node;
1034 vat_json_init_object(&node);
1035 vat_json_object_add_int(&node, "retval", ntohl(mp->retval));
1036 vat_json_object_add_uint(&node, "tunnel_sw_if_index", ntohl(mp->tunnel_sw_if_index));
1038 vat_json_print(vam->ofp, &node);
1039 vat_json_free(&node);
1041 vam->retval = ntohl(mp->retval);
1042 vam->result_ready = 1;
1046 static void vl_api_show_version_reply_t_handler
1047 (vl_api_show_version_reply_t * mp)
1049 vat_main_t * vam = &vat_main;
1050 i32 retval = ntohl(mp->retval);
1053 errmsg (" program: %s\n", mp->program);
1054 errmsg (" version: %s\n", mp->version);
1055 errmsg (" build date: %s\n", mp->build_date);
1056 errmsg ("build directory: %s\n", mp->build_directory);
1058 vam->retval = retval;
1059 vam->result_ready = 1;
1062 static void vl_api_show_version_reply_t_handler_json
1063 (vl_api_show_version_reply_t * mp)
1065 vat_main_t * vam = &vat_main;
1066 vat_json_node_t node;
1068 vat_json_init_object(&node);
1069 vat_json_object_add_int(&node, "retval", ntohl(mp->retval));
1070 vat_json_object_add_string_copy(&node, "program", mp->program);
1071 vat_json_object_add_string_copy(&node, "version", mp->version);
1072 vat_json_object_add_string_copy(&node, "build_date", mp->build_date);
1073 vat_json_object_add_string_copy(&node, "build_directory", mp->build_directory);
1075 vat_json_print(vam->ofp, &node);
1076 vat_json_free(&node);
1078 vam->retval = ntohl(mp->retval);
1079 vam->result_ready = 1;
1082 static void vl_api_ip4_arp_event_t_handler
1083 (vl_api_ip4_arp_event_t * mp)
1085 vat_main_t * vam = &vat_main;
1086 errmsg ("arp event: address %U new mac %U sw_if_index %d\n",
1087 format_ip4_address, &mp->address,
1088 format_ethernet_address, mp->new_mac, mp->sw_if_index);
1091 static void vl_api_ip4_arp_event_t_handler_json
1092 (vl_api_ip4_arp_event_t * mp)
1094 /* JSON output not supported */
1098 * Special-case: build the bridge domain table, maintain
1099 * the next bd id vbl.
1101 static void vl_api_bridge_domain_details_t_handler
1102 (vl_api_bridge_domain_details_t * mp)
1104 vat_main_t * vam = &vat_main;
1105 u32 n_sw_ifs = ntohl (mp->n_sw_ifs);
1107 fformat (vam->ofp, "\n%-3s %-3s %-3s %-3s %-3s %-3s\n",
1108 " ID", "LRN", "FWD", "FLD", "BVI", "#IF");
1110 fformat (vam->ofp, "%3d %3d %3d %3d %3d %3d\n",
1111 ntohl (mp->bd_id), mp->learn, mp->forward,
1112 mp->flood, ntohl (mp->bvi_sw_if_index), n_sw_ifs);
1115 fformat (vam->ofp, "\n\n%s %s %s\n", "sw_if_index", "SHG",
1119 static void vl_api_bridge_domain_details_t_handler_json
1120 (vl_api_bridge_domain_details_t * mp)
1122 vat_main_t * vam = &vat_main;
1123 vat_json_node_t *node, *array = NULL;
1125 if (VAT_JSON_ARRAY != vam->json_tree.type) {
1126 ASSERT(VAT_JSON_NONE == vam->json_tree.type);
1127 vat_json_init_array(&vam->json_tree);
1129 node = vat_json_array_add(&vam->json_tree);
1131 vat_json_init_object(node);
1132 vat_json_object_add_uint(node, "bd_id", ntohl(mp->bd_id));
1133 vat_json_object_add_uint(node, "flood", mp->flood);
1134 vat_json_object_add_uint(node, "forward", mp->forward);
1135 vat_json_object_add_uint(node, "learn", mp->learn);
1136 vat_json_object_add_uint(node, "bvi_sw_if_index", ntohl(mp->bvi_sw_if_index));
1137 vat_json_object_add_uint(node, "n_sw_ifs", ntohl(mp->n_sw_ifs));
1138 array = vat_json_object_add(node, "sw_if");
1139 vat_json_init_array(array);
1143 * Special-case: build the bridge domain sw if table.
1145 static void vl_api_bridge_domain_sw_if_details_t_handler
1146 (vl_api_bridge_domain_sw_if_details_t * mp)
1148 vat_main_t * vam = &vat_main;
1150 u8 * sw_if_name = 0;
1153 sw_if_index = ntohl (mp->sw_if_index);
1154 hash_foreach_pair (p, vam->sw_if_index_by_interface_name,
1156 if ((u32) p->value[0] == sw_if_index) {
1157 sw_if_name = (u8 *)(p->key);
1162 fformat (vam->ofp, "%7d %3d %s", sw_if_index,
1163 mp->shg, sw_if_name ? (char *)sw_if_name :
1164 "sw_if_index not found!");
1167 static void vl_api_bridge_domain_sw_if_details_t_handler_json
1168 (vl_api_bridge_domain_sw_if_details_t * mp)
1170 vat_main_t * vam = &vat_main;
1171 vat_json_node_t *node = NULL;
1172 uword last_index = 0;
1174 ASSERT(VAT_JSON_ARRAY == vam->json_tree.type);
1175 ASSERT(vec_len(vam->json_tree.array) >= 1);
1176 last_index = vec_len(vam->json_tree.array) - 1;
1177 node = &vam->json_tree.array[last_index];
1178 node = vat_json_object_get_element(node, "sw_if");
1179 ASSERT(NULL != node);
1180 node = vat_json_array_add(node);
1182 vat_json_init_object(node);
1183 vat_json_object_add_uint(node, "bd_id", ntohl(mp->bd_id));
1184 vat_json_object_add_uint(node, "sw_if_index", ntohl(mp->sw_if_index));
1185 vat_json_object_add_uint(node, "shg", mp->shg);
1188 static void vl_api_control_ping_reply_t_handler
1189 (vl_api_control_ping_reply_t * mp)
1191 vat_main_t * vam = &vat_main;
1192 i32 retval = ntohl(mp->retval);
1193 if (vam->async_mode) {
1194 vam->async_errors += (retval < 0);
1196 vam->retval = retval;
1197 vam->result_ready = 1;
1201 static void vl_api_control_ping_reply_t_handler_json
1202 (vl_api_control_ping_reply_t * mp)
1204 vat_main_t * vam = &vat_main;
1205 i32 retval = ntohl(mp->retval);
1207 if (VAT_JSON_NONE != vam->json_tree.type) {
1208 vat_json_print(vam->ofp, &vam->json_tree);
1209 vat_json_free(&vam->json_tree);
1210 vam->json_tree.type = VAT_JSON_NONE;
1213 vat_json_init_array(&vam->json_tree);
1214 vat_json_print(vam->ofp, &vam->json_tree);
1215 vam->json_tree.type = VAT_JSON_NONE;
1218 vam->retval = retval;
1219 vam->result_ready = 1;
1222 static void vl_api_noprint_control_ping_reply_t_handler
1223 (vl_api_noprint_control_ping_reply_t * mp)
1225 vat_main_t * vam = &vat_main;
1226 i32 retval = ntohl(mp->retval);
1227 if (vam->async_mode) {
1228 vam->async_errors += (retval < 0);
1230 vam->retval = retval;
1231 vam->result_ready = 1;
1235 static void vl_api_noprint_control_ping_reply_t_handler_json
1236 (vl_api_noprint_control_ping_reply_t * mp)
1238 vat_main_t * vam = &vat_main;
1239 i32 retval = ntohl(mp->retval);
1241 if (vam->noprint_msg) {
1242 vam->retval = retval;
1243 vam->result_ready = 1;
1247 if (VAT_JSON_NONE != vam->json_tree.type) {
1248 vat_json_print(vam->ofp, &vam->json_tree);
1249 vat_json_free(&vam->json_tree);
1250 vam->json_tree.type = VAT_JSON_NONE;
1253 vat_json_init_array(&vam->json_tree);
1254 vat_json_print(vam->ofp, &vam->json_tree);
1255 vam->json_tree.type = VAT_JSON_NONE;
1258 vam->retval = retval;
1259 vam->result_ready = 1;
1262 static void vl_api_l2_flags_reply_t_handler
1263 (vl_api_l2_flags_reply_t * mp)
1265 vat_main_t * vam = &vat_main;
1266 i32 retval = ntohl(mp->retval);
1267 if (vam->async_mode) {
1268 vam->async_errors += (retval < 0);
1270 vam->retval = retval;
1271 vam->result_ready = 1;
1275 static void vl_api_l2_flags_reply_t_handler_json
1276 (vl_api_l2_flags_reply_t * mp)
1278 vat_main_t * vam = &vat_main;
1279 vat_json_node_t node;
1281 vat_json_init_object(&node);
1282 vat_json_object_add_int(&node, "retval", ntohl(mp->retval));
1283 vat_json_object_add_uint(&node, "resulting_feature_bitmap", ntohl(mp->resulting_feature_bitmap));
1285 vat_json_print(vam->ofp, &node);
1286 vat_json_free(&node);
1288 vam->retval = ntohl(mp->retval);
1289 vam->result_ready = 1;
1292 static void vl_api_bridge_flags_reply_t_handler
1293 (vl_api_bridge_flags_reply_t * mp)
1295 vat_main_t * vam = &vat_main;
1296 i32 retval = ntohl(mp->retval);
1297 if (vam->async_mode) {
1298 vam->async_errors += (retval < 0);
1300 vam->retval = retval;
1301 vam->result_ready = 1;
1305 static void vl_api_bridge_flags_reply_t_handler_json
1306 (vl_api_bridge_flags_reply_t * mp)
1308 vat_main_t * vam = &vat_main;
1309 vat_json_node_t node;
1311 vat_json_init_object(&node);
1312 vat_json_object_add_int(&node, "retval", ntohl(mp->retval));
1313 vat_json_object_add_uint(&node, "resulting_feature_bitmap", ntohl(mp->resulting_feature_bitmap));
1315 vat_json_print(vam->ofp, &node);
1316 vat_json_free(&node);
1318 vam->retval = ntohl(mp->retval);
1319 vam->result_ready = 1;
1322 static void vl_api_tap_connect_reply_t_handler
1323 (vl_api_tap_connect_reply_t * mp)
1325 vat_main_t * vam = &vat_main;
1326 i32 retval = ntohl(mp->retval);
1327 if (vam->async_mode) {
1328 vam->async_errors += (retval < 0);
1330 vam->retval = retval;
1331 vam->sw_if_index = ntohl (mp->sw_if_index);
1332 vam->result_ready = 1;
1337 static void vl_api_tap_connect_reply_t_handler_json
1338 (vl_api_tap_connect_reply_t * mp)
1340 vat_main_t * vam = &vat_main;
1341 vat_json_node_t node;
1343 vat_json_init_object(&node);
1344 vat_json_object_add_int(&node, "retval", ntohl(mp->retval));
1345 vat_json_object_add_uint(&node, "sw_if_index", ntohl(mp->sw_if_index));
1347 vat_json_print(vam->ofp, &node);
1348 vat_json_free(&node);
1350 vam->retval = ntohl(mp->retval);
1351 vam->result_ready = 1;
1355 static void vl_api_tap_modify_reply_t_handler
1356 (vl_api_tap_modify_reply_t * mp)
1358 vat_main_t * vam = &vat_main;
1359 i32 retval = ntohl(mp->retval);
1360 if (vam->async_mode) {
1361 vam->async_errors += (retval < 0);
1363 vam->retval = retval;
1364 vam->sw_if_index = ntohl (mp->sw_if_index);
1365 vam->result_ready = 1;
1369 static void vl_api_tap_modify_reply_t_handler_json
1370 (vl_api_tap_modify_reply_t * mp)
1372 vat_main_t * vam = &vat_main;
1373 vat_json_node_t node;
1375 vat_json_init_object(&node);
1376 vat_json_object_add_int(&node, "retval", ntohl(mp->retval));
1377 vat_json_object_add_uint(&node, "sw_if_index", ntohl(mp->sw_if_index));
1379 vat_json_print(vam->ofp, &node);
1380 vat_json_free(&node);
1382 vam->retval = ntohl(mp->retval);
1383 vam->result_ready = 1;
1386 static void vl_api_tap_delete_reply_t_handler
1387 (vl_api_tap_delete_reply_t * mp)
1389 vat_main_t * vam = &vat_main;
1390 i32 retval = ntohl(mp->retval);
1391 if (vam->async_mode) {
1392 vam->async_errors += (retval < 0);
1394 vam->retval = retval;
1395 vam->result_ready = 1;
1399 static void vl_api_tap_delete_reply_t_handler_json
1400 (vl_api_tap_delete_reply_t * mp)
1402 vat_main_t * vam = &vat_main;
1403 vat_json_node_t node;
1405 vat_json_init_object(&node);
1406 vat_json_object_add_int(&node, "retval", ntohl(mp->retval));
1408 vat_json_print(vam->ofp, &node);
1409 vat_json_free(&node);
1411 vam->retval = ntohl(mp->retval);
1412 vam->result_ready = 1;
1415 static void vl_api_mpls_ethernet_add_del_tunnel_reply_t_handler
1416 (vl_api_mpls_ethernet_add_del_tunnel_reply_t * mp)
1418 vat_main_t * vam = &vat_main;
1419 i32 retval = ntohl(mp->retval);
1420 if (vam->async_mode) {
1421 vam->async_errors += (retval < 0);
1423 vam->retval = retval;
1424 vam->result_ready = 1;
1428 static void vl_api_mpls_ethernet_add_del_tunnel_reply_t_handler_json
1429 (vl_api_mpls_ethernet_add_del_tunnel_reply_t * mp)
1431 vat_main_t * vam = &vat_main;
1432 vat_json_node_t node;
1434 vat_json_init_object(&node);
1435 vat_json_object_add_int(&node, "retval", ntohl(mp->retval));
1436 vat_json_object_add_uint(&node, "tunnel_sw_if_index", ntohl(mp->tunnel_sw_if_index));
1438 vat_json_print(vam->ofp, &node);
1439 vat_json_free(&node);
1441 vam->retval = ntohl(mp->retval);
1442 vam->result_ready = 1;
1445 static void vl_api_l2tpv3_create_tunnel_reply_t_handler
1446 (vl_api_l2tpv3_create_tunnel_reply_t * mp)
1448 vat_main_t * vam = &vat_main;
1449 i32 retval = ntohl(mp->retval);
1450 if (vam->async_mode) {
1451 vam->async_errors += (retval < 0);
1453 vam->retval = retval;
1454 vam->sw_if_index = ntohl (mp->sw_if_index);
1455 vam->result_ready = 1;
1459 static void vl_api_l2tpv3_create_tunnel_reply_t_handler_json
1460 (vl_api_l2tpv3_create_tunnel_reply_t * mp)
1462 vat_main_t * vam = &vat_main;
1463 vat_json_node_t node;
1465 vat_json_init_object(&node);
1466 vat_json_object_add_int(&node, "retval", ntohl(mp->retval));
1467 vat_json_object_add_uint(&node, "sw_if_index", ntohl(mp->sw_if_index));
1469 vat_json_print(vam->ofp, &node);
1470 vat_json_free(&node);
1472 vam->retval = ntohl(mp->retval);
1473 vam->result_ready = 1;
1476 static void vl_api_vxlan_add_del_tunnel_reply_t_handler
1477 (vl_api_vxlan_add_del_tunnel_reply_t * mp)
1479 vat_main_t * vam = &vat_main;
1480 i32 retval = ntohl(mp->retval);
1481 if (vam->async_mode) {
1482 vam->async_errors += (retval < 0);
1484 vam->retval = retval;
1485 vam->sw_if_index = ntohl (mp->sw_if_index);
1486 vam->result_ready = 1;
1490 static void vl_api_vxlan_add_del_tunnel_reply_t_handler_json
1491 (vl_api_vxlan_add_del_tunnel_reply_t * mp)
1493 vat_main_t * vam = &vat_main;
1494 vat_json_node_t node;
1496 vat_json_init_object(&node);
1497 vat_json_object_add_int(&node, "retval", ntohl(mp->retval));
1498 vat_json_object_add_uint(&node, "sw_if_index", ntohl(mp->sw_if_index));
1500 vat_json_print(vam->ofp, &node);
1501 vat_json_free(&node);
1503 vam->retval = ntohl(mp->retval);
1504 vam->result_ready = 1;
1507 static void vl_api_gre_add_del_tunnel_reply_t_handler
1508 (vl_api_gre_add_del_tunnel_reply_t * mp)
1510 vat_main_t * vam = &vat_main;
1511 i32 retval = ntohl(mp->retval);
1512 if (vam->async_mode) {
1513 vam->async_errors += (retval < 0);
1515 vam->retval = retval;
1516 vam->sw_if_index = ntohl (mp->sw_if_index);
1517 vam->result_ready = 1;
1521 static void vl_api_gre_add_del_tunnel_reply_t_handler_json
1522 (vl_api_gre_add_del_tunnel_reply_t * mp)
1524 vat_main_t * vam = &vat_main;
1525 vat_json_node_t node;
1527 vat_json_init_object(&node);
1528 vat_json_object_add_int(&node, "retval", ntohl(mp->retval));
1529 vat_json_object_add_uint(&node, "sw_if_index", ntohl(mp->sw_if_index));
1531 vat_json_print(vam->ofp, &node);
1532 vat_json_free(&node);
1534 vam->retval = ntohl(mp->retval);
1535 vam->result_ready = 1;
1538 static void vl_api_create_vhost_user_if_reply_t_handler
1539 (vl_api_create_vhost_user_if_reply_t * mp)
1541 vat_main_t * vam = &vat_main;
1542 i32 retval = ntohl(mp->retval);
1543 if (vam->async_mode) {
1544 vam->async_errors += (retval < 0);
1546 vam->retval = retval;
1547 vam->sw_if_index = ntohl (mp->sw_if_index);
1548 vam->result_ready = 1;
1552 static void vl_api_create_vhost_user_if_reply_t_handler_json
1553 (vl_api_create_vhost_user_if_reply_t * mp)
1555 vat_main_t * vam = &vat_main;
1556 vat_json_node_t node;
1558 vat_json_init_object(&node);
1559 vat_json_object_add_int(&node, "retval", ntohl(mp->retval));
1560 vat_json_object_add_uint(&node, "sw_if_index", ntohl(mp->sw_if_index));
1562 vat_json_print(vam->ofp, &node);
1563 vat_json_free(&node);
1565 vam->retval = ntohl(mp->retval);
1566 vam->result_ready = 1;
1569 static void vl_api_ip_address_details_t_handler
1570 (vl_api_ip_address_details_t * mp)
1572 vat_main_t * vam = &vat_main;
1573 static ip_address_details_t empty_ip_address_details = {{0}};
1574 ip_address_details_t * address = NULL;
1575 ip_details_t * current_ip_details = NULL;
1576 ip_details_t * details = NULL;
1578 details = vam->ip_details_by_sw_if_index[vam->is_ipv6];
1580 if (!details || vam->current_sw_if_index >= vec_len(details)
1581 || !details[vam->current_sw_if_index].present) {
1582 errmsg ("ip address details arrived but not stored\n");
1583 errmsg ("ip_dump should be called first\n");
1587 current_ip_details = vec_elt_at_index(details,
1588 vam->current_sw_if_index);
1590 #define addresses (current_ip_details->addr)
1592 vec_validate_init_empty(addresses, vec_len(addresses),
1593 empty_ip_address_details);
1595 address = vec_elt_at_index(addresses, vec_len(addresses) - 1);
1597 clib_memcpy(&address->ip, &mp->ip, sizeof(address->ip));
1598 address->prefix_length = mp->prefix_length;
1602 static void vl_api_ip_address_details_t_handler_json
1603 (vl_api_ip_address_details_t * mp)
1605 vat_main_t * vam = &vat_main;
1606 vat_json_node_t *node = NULL;
1607 struct in6_addr ip6;
1610 if (VAT_JSON_ARRAY != vam->json_tree.type) {
1611 ASSERT(VAT_JSON_NONE == vam->json_tree.type);
1612 vat_json_init_array(&vam->json_tree);
1614 node = vat_json_array_add(&vam->json_tree);
1616 vat_json_init_object(node);
1618 clib_memcpy(&ip6, mp->ip, sizeof(ip6));
1619 vat_json_object_add_ip6(node, "ip", ip6);
1621 clib_memcpy(&ip4, mp->ip, sizeof(ip4));
1622 vat_json_object_add_ip4(node, "ip", ip4);
1624 vat_json_object_add_uint(node, "prefix_length", mp->prefix_length);
1627 static void vl_api_ip_details_t_handler (vl_api_ip_details_t * mp)
1629 vat_main_t * vam = &vat_main;
1630 static ip_details_t empty_ip_details = {0};
1631 ip_details_t * ip = NULL;
1632 u32 sw_if_index = ~0;
1634 sw_if_index = ntohl(mp->sw_if_index);
1636 vec_validate_init_empty(vam->ip_details_by_sw_if_index[vam->is_ipv6],
1637 sw_if_index, empty_ip_details);
1639 ip = vec_elt_at_index(vam->ip_details_by_sw_if_index[vam->is_ipv6],
1645 static void vl_api_ip_details_t_handler_json (vl_api_ip_details_t * mp)
1647 vat_main_t * vam = &vat_main;
1649 if (VAT_JSON_ARRAY != vam->json_tree.type) {
1650 ASSERT(VAT_JSON_NONE == vam->json_tree.type);
1651 vat_json_init_array(&vam->json_tree);
1653 vat_json_array_add_uint(&vam->json_tree, clib_net_to_host_u32(mp->sw_if_index));
1656 static void vl_api_map_domain_details_t_handler_json
1657 (vl_api_map_domain_details_t * mp)
1659 vat_json_node_t * node = NULL;
1660 vat_main_t * vam = &vat_main;
1661 struct in6_addr ip6;
1664 if (VAT_JSON_ARRAY != vam->json_tree.type) {
1665 ASSERT(VAT_JSON_NONE == vam->json_tree.type);
1666 vat_json_init_array(&vam->json_tree);
1669 node = vat_json_array_add(&vam->json_tree);
1670 vat_json_init_object(node);
1672 vat_json_object_add_uint(node, "domain_index", clib_net_to_host_u32(mp->domain_index));
1673 clib_memcpy(&ip6, mp->ip6_prefix, sizeof(ip6));
1674 vat_json_object_add_ip6(node, "ip6_prefix", ip6);
1675 clib_memcpy(&ip4, mp->ip4_prefix, sizeof(ip4));
1676 vat_json_object_add_ip4(node, "ip4_prefix", ip4);
1677 clib_memcpy(&ip6, mp->ip6_src, sizeof(ip6));
1678 vat_json_object_add_ip6(node, "ip6_src", ip6);
1679 vat_json_object_add_int(node, "ip6_prefix_len", mp->ip6_prefix_len);
1680 vat_json_object_add_int(node, "ip4_prefix_len", mp->ip4_prefix_len);
1681 vat_json_object_add_int(node, "ip6_src_len", mp->ip6_src_len);
1682 vat_json_object_add_int(node, "ea_bits_len", mp->ea_bits_len);
1683 vat_json_object_add_int(node, "psid_offset", mp->psid_offset);
1684 vat_json_object_add_int(node, "psid_length", mp->psid_length);
1685 vat_json_object_add_uint(node, "flags", mp->flags);
1686 vat_json_object_add_uint(node, "mtu", clib_net_to_host_u16(mp->mtu));
1687 vat_json_object_add_int(node, "is_translation", mp->is_translation);
1690 static void vl_api_map_domain_details_t_handler
1691 (vl_api_map_domain_details_t * mp)
1693 vat_main_t * vam = &vat_main;
1695 if (mp->is_translation) {
1696 fformat(vam->ofp, "* %U/%d (ipv4-prefix) %U/%d (ipv6-prefix) %U/%d (ip6-src) index: %u\n",
1697 format_ip4_address, mp->ip4_prefix, mp->ip4_prefix_len,
1698 format_ip6_address, mp->ip6_prefix, mp->ip6_prefix_len,
1699 format_ip6_address, mp->ip6_src, mp->ip6_src_len, clib_net_to_host_u32(mp->domain_index));
1701 fformat(vam->ofp, "* %U/%d (ipv4-prefix) %U/%d (ipv6-prefix) %U (ip6-src) index: %u\n",
1702 format_ip4_address, mp->ip4_prefix, mp->ip4_prefix_len,
1703 format_ip6_address, mp->ip6_prefix, mp->ip6_prefix_len,
1704 format_ip6_address, mp->ip6_src, clib_net_to_host_u32(mp->domain_index));
1706 fformat(vam->ofp, " ea-len %d psid-offset %d psid-len %d mtu %d %s\n",
1707 mp->ea_bits_len, mp->psid_offset, mp->psid_length, mp->mtu, mp->is_translation? "map-t":"");
1710 static void vl_api_map_rule_details_t_handler_json
1711 (vl_api_map_rule_details_t * mp)
1713 struct in6_addr ip6;
1714 vat_json_node_t * node = NULL;
1715 vat_main_t * vam = &vat_main;
1717 if (VAT_JSON_ARRAY != vam->json_tree.type) {
1718 ASSERT(VAT_JSON_NONE == vam->json_tree.type);
1719 vat_json_init_array(&vam->json_tree);
1722 node = vat_json_array_add(&vam->json_tree);
1723 vat_json_init_object(node);
1725 vat_json_object_add_uint(node, "psid", clib_net_to_host_u16(mp->psid));
1726 clib_memcpy(&ip6, mp->ip6_dst, sizeof(ip6));
1727 vat_json_object_add_ip6(node, "ip6_dst", ip6);
1730 static void vl_api_map_rule_details_t_handler
1731 (vl_api_map_rule_details_t * mp)
1733 vat_main_t * vam = &vat_main;
1734 fformat(vam->ofp, " %d (psid) %U (ip6-dst)\n", clib_net_to_host_u16(mp->psid),
1735 format_ip6_address, mp->ip6_dst);
1738 static void vl_api_dhcp_compl_event_t_handler
1739 (vl_api_dhcp_compl_event_t * mp)
1741 vat_main_t * vam = &vat_main;
1742 errmsg ("DHCP compl event: pid %d %s hostname %s host_addr %U "
1743 "router_addr %U host_mac %U\n",
1744 mp->pid, mp->is_ipv6 ? "ipv6":"ipv4", mp->hostname,
1745 format_ip4_address, &mp->host_address,
1746 format_ip4_address, &mp->router_address,
1747 format_ethernet_address, mp->host_mac);
1750 static void vl_api_dhcp_compl_event_t_handler_json
1751 (vl_api_dhcp_compl_event_t * mp)
1753 /* JSON output not supported */
1756 static void set_simple_interface_counter (u8 vnet_counter_type, u32 sw_if_index,
1759 vat_main_t * vam = &vat_main;
1760 static u64 default_counter = 0;
1762 vec_validate_init_empty(vam->simple_interface_counters, vnet_counter_type, NULL);
1763 vec_validate_init_empty(vam->simple_interface_counters[vnet_counter_type],
1764 sw_if_index, default_counter);
1765 vam->simple_interface_counters[vnet_counter_type][sw_if_index] = counter;
1768 static void set_combined_interface_counter (u8 vnet_counter_type, u32 sw_if_index,
1769 interface_counter_t counter)
1771 vat_main_t * vam = &vat_main;
1772 static interface_counter_t default_counter = {0, };
1774 vec_validate_init_empty(vam->combined_interface_counters, vnet_counter_type, NULL);
1775 vec_validate_init_empty(vam->combined_interface_counters[vnet_counter_type],
1776 sw_if_index, default_counter);
1777 vam->combined_interface_counters[vnet_counter_type][sw_if_index] = counter;
1780 static void vl_api_vnet_interface_counters_t_handler
1781 (vl_api_vnet_interface_counters_t *mp)
1786 static void vl_api_vnet_interface_counters_t_handler_json
1787 (vl_api_vnet_interface_counters_t *mp)
1789 interface_counter_t counter;
1794 u32 first_sw_if_index;
1797 count = ntohl(mp->count);
1798 first_sw_if_index = ntohl(mp->first_sw_if_index);
1800 if (!mp->is_combined) {
1801 v_packets = (u64*)&mp->data;
1802 for (i = 0; i < count; i++) {
1803 packets = clib_net_to_host_u64(clib_mem_unaligned(v_packets, u64));
1804 set_simple_interface_counter(mp->vnet_counter_type,
1805 first_sw_if_index + i, packets);
1809 v = (vlib_counter_t*)&mp->data;
1810 for (i = 0; i < count; i++) {
1811 counter.packets = clib_net_to_host_u64(
1812 clib_mem_unaligned(&v->packets, u64));
1813 counter.bytes = clib_net_to_host_u64(
1814 clib_mem_unaligned(&v->bytes, u64));
1815 set_combined_interface_counter(mp->vnet_counter_type,
1816 first_sw_if_index + i, counter);
1822 static u32 ip4_fib_counters_get_vrf_index_by_vrf_id (u32 vrf_id)
1824 vat_main_t * vam = &vat_main;
1827 for (i = 0; i < vec_len(vam->ip4_fib_counters_vrf_id_by_index); i++) {
1828 if (vam->ip4_fib_counters_vrf_id_by_index[i] == vrf_id) {
1835 static u32 ip6_fib_counters_get_vrf_index_by_vrf_id (u32 vrf_id)
1837 vat_main_t * vam = &vat_main;
1840 for (i = 0; i < vec_len(vam->ip6_fib_counters_vrf_id_by_index); i++) {
1841 if (vam->ip6_fib_counters_vrf_id_by_index[i] == vrf_id) {
1848 static void vl_api_vnet_ip4_fib_counters_t_handler
1849 (vl_api_vnet_ip4_fib_counters_t *mp)
1854 static void vl_api_vnet_ip4_fib_counters_t_handler_json
1855 (vl_api_vnet_ip4_fib_counters_t *mp)
1857 vat_main_t * vam = &vat_main;
1858 vl_api_ip4_fib_counter_t *v;
1859 ip4_fib_counter_t *counter;
1866 vrf_id = ntohl(mp->vrf_id);
1867 vrf_index = ip4_fib_counters_get_vrf_index_by_vrf_id(vrf_id);
1868 if (~0 == vrf_index) {
1869 vrf_index = vec_len(vam->ip4_fib_counters_vrf_id_by_index);
1870 vec_validate(vam->ip4_fib_counters_vrf_id_by_index, vrf_index);
1871 vam->ip4_fib_counters_vrf_id_by_index[vrf_index] = vrf_id;
1872 vec_validate(vam->ip4_fib_counters, vrf_index);
1873 vam->ip4_fib_counters[vrf_index] = NULL;
1876 vec_free(vam->ip4_fib_counters[vrf_index]);
1877 v = (vl_api_ip4_fib_counter_t*)&mp->c;
1878 count = ntohl(mp->count);
1879 for (i = 0; i < count; i++) {
1880 vec_validate(vam->ip4_fib_counters[vrf_index], i);
1881 counter = &vam->ip4_fib_counters[vrf_index][i];
1882 clib_memcpy(&ip4, &v->address, sizeof(ip4));
1883 counter->address = ip4;
1884 counter->address_length = v->address_length;
1885 counter->packets = clib_net_to_host_u64(v->packets);
1886 counter->bytes = clib_net_to_host_u64(v->bytes);
1891 static void vl_api_vnet_ip6_fib_counters_t_handler
1892 (vl_api_vnet_ip6_fib_counters_t *mp)
1897 static void vl_api_vnet_ip6_fib_counters_t_handler_json
1898 (vl_api_vnet_ip6_fib_counters_t *mp)
1900 vat_main_t * vam = &vat_main;
1901 vl_api_ip6_fib_counter_t *v;
1902 ip6_fib_counter_t *counter;
1903 struct in6_addr ip6;
1909 vrf_id = ntohl(mp->vrf_id);
1910 vrf_index = ip6_fib_counters_get_vrf_index_by_vrf_id(vrf_id);
1911 if (~0 == vrf_index) {
1912 vrf_index = vec_len(vam->ip6_fib_counters_vrf_id_by_index);
1913 vec_validate(vam->ip6_fib_counters_vrf_id_by_index, vrf_index);
1914 vam->ip6_fib_counters_vrf_id_by_index[vrf_index] = vrf_id;
1915 vec_validate(vam->ip6_fib_counters, vrf_index);
1916 vam->ip6_fib_counters[vrf_index] = NULL;
1919 vec_free(vam->ip6_fib_counters[vrf_index]);
1920 v = (vl_api_ip6_fib_counter_t*)&mp->c;
1921 count = ntohl(mp->count);
1922 for (i = 0; i < count; i++) {
1923 vec_validate(vam->ip6_fib_counters[vrf_index], i);
1924 counter = &vam->ip6_fib_counters[vrf_index][i];
1925 clib_memcpy(&ip6, &v->address, sizeof(ip6));
1926 counter->address = ip6;
1927 counter->address_length = v->address_length;
1928 counter->packets = clib_net_to_host_u64(v->packets);
1929 counter->bytes = clib_net_to_host_u64(v->bytes);
1934 static void vl_api_get_first_msg_id_reply_t_handler
1935 (vl_api_get_first_msg_id_reply_t * mp)
1937 vat_main_t * vam = &vat_main;
1938 i32 retval = ntohl(mp->retval);
1940 if (vam->async_mode) {
1941 vam->async_errors += (retval < 0);
1943 vam->retval = retval;
1944 vam->result_ready = 1;
1947 errmsg ("first message id %d\n", ntohs(mp->first_msg_id));
1951 static void vl_api_get_first_msg_id_reply_t_handler_json
1952 (vl_api_get_first_msg_id_reply_t * mp)
1954 vat_main_t * vam = &vat_main;
1955 vat_json_node_t node;
1957 vat_json_init_object(&node);
1958 vat_json_object_add_int(&node, "retval", ntohl(mp->retval));
1959 vat_json_object_add_uint(&node, "first_msg_id",
1960 (uint) ntohs(mp->first_msg_id));
1962 vat_json_print(vam->ofp, &node);
1963 vat_json_free(&node);
1965 vam->retval = ntohl(mp->retval);
1966 vam->result_ready = 1;
1969 static void vl_api_get_node_graph_reply_t_handler
1970 (vl_api_get_node_graph_reply_t * mp)
1972 vat_main_t * vam = &vat_main;
1973 api_main_t * am = &api_main;
1974 i32 retval = ntohl(mp->retval);
1975 u8 * pvt_copy, * reply;
1980 if (vam->async_mode) {
1981 vam->async_errors += (retval < 0);
1983 vam->retval = retval;
1984 vam->result_ready = 1;
1987 /* "Should never happen..." */
1991 reply = (u8 *)(mp->reply_in_shmem);
1992 pvt_copy = vec_dup (reply);
1994 /* Toss the shared-memory original... */
1995 pthread_mutex_lock (&am->vlib_rp->mutex);
1996 oldheap = svm_push_data_heap (am->vlib_rp);
2000 svm_pop_heap (oldheap);
2001 pthread_mutex_unlock (&am->vlib_rp->mutex);
2003 if (vam->graph_nodes) {
2004 hash_free (vam->graph_node_index_by_name);
2006 for (i = 0; i < vec_len (vam->graph_nodes); i++) {
2007 node = vam->graph_nodes[i];
2008 vec_free (node->name);
2009 vec_free (node->next_nodes);
2012 vec_free(vam->graph_nodes);
2015 vam->graph_node_index_by_name = hash_create_string (0, sizeof(uword));
2016 vam->graph_nodes = vlib_node_unserialize (pvt_copy);
2017 vec_free (pvt_copy);
2019 for (i = 0; i < vec_len (vam->graph_nodes); i++) {
2020 node = vam->graph_nodes[i];
2021 hash_set_mem (vam->graph_node_index_by_name, node->name, i);
2025 static void vl_api_get_node_graph_reply_t_handler_json
2026 (vl_api_get_node_graph_reply_t * mp)
2028 vat_main_t * vam = &vat_main;
2029 api_main_t * am = &api_main;
2031 vat_json_node_t node;
2034 /* $$$$ make this real? */
2035 vat_json_init_object(&node);
2036 vat_json_object_add_int(&node, "retval", ntohl(mp->retval));
2037 vat_json_object_add_uint(&node, "reply_in_shmem", mp->reply_in_shmem);
2039 reply = (u8 *)(mp->reply_in_shmem);
2041 /* Toss the shared-memory original... */
2042 pthread_mutex_lock (&am->vlib_rp->mutex);
2043 oldheap = svm_push_data_heap (am->vlib_rp);
2047 svm_pop_heap (oldheap);
2048 pthread_mutex_unlock (&am->vlib_rp->mutex);
2050 vat_json_print(vam->ofp, &node);
2051 vat_json_free(&node);
2053 vam->retval = ntohl(mp->retval);
2054 vam->result_ready = 1;
2058 vl_api_lisp_locator_details_t_handler (
2059 vl_api_lisp_locator_details_t *mp)
2061 vat_main_t *vam = &vat_main;
2065 memset(&loc, 0, sizeof(loc));
2066 if (vam->noprint_msg) {
2067 loc.local = mp->local;
2068 loc.priority = mp->priority;
2069 loc.weight = mp->weight;
2071 loc.sw_if_index = ntohl(mp->sw_if_index);
2073 loc.is_ipv6 = mp->is_ipv6;
2074 clib_memcpy(loc.ip_address, mp->ip_address, sizeof(loc.ip_address));
2076 vec_add1(vam->locator_msg, loc);
2079 tmp_str = format(tmp_str, "%=16d%=16d%=16d\n",
2080 ntohl(mp->sw_if_index),
2084 tmp_str = format(tmp_str, "%=16U%=16d%=16d\n",
2085 mp->is_ipv6 ? format_ip6_address :
2092 fformat(vam->ofp, "%s", tmp_str);
2099 vl_api_lisp_locator_details_t_handler_json (
2100 vl_api_lisp_locator_details_t *mp)
2102 vat_main_t *vam = &vat_main;
2103 vat_json_node_t *node = NULL;
2105 struct in6_addr ip6;
2108 memset(&loc, 0, sizeof(loc));
2109 if (vam->noprint_msg) {
2110 loc.local = mp->local;
2111 loc.priority = mp->priority;
2112 loc.weight = mp->weight;
2114 loc.sw_if_index = ntohl(mp->sw_if_index);
2116 loc.is_ipv6 = mp->is_ipv6;
2117 clib_memcpy(loc.ip_address, mp->ip_address, sizeof(loc.ip_address));
2119 vec_add1(vam->locator_msg, loc);
2123 if (VAT_JSON_ARRAY != vam->json_tree.type) {
2124 ASSERT(VAT_JSON_NONE == vam->json_tree.type);
2125 vat_json_init_array(&vam->json_tree);
2127 node = vat_json_array_add(&vam->json_tree);
2129 vat_json_init_object(node);
2132 vat_json_object_add_uint(node, "locator_index", ntohl(mp->sw_if_index));
2135 clib_memcpy(&ip6, mp->ip_address, sizeof(ip6));
2136 vat_json_object_add_ip6(node, "locator", ip6);
2138 clib_memcpy(&ip4, mp->ip_address, sizeof(ip4));
2139 vat_json_object_add_ip4(node, "locator", ip4);
2142 vat_json_object_add_uint(node, "priority", mp->priority);
2143 vat_json_object_add_uint(node, "weight", mp->weight);
2147 vl_api_lisp_locator_set_details_t_handler (
2148 vl_api_lisp_locator_set_details_t *mp)
2150 vat_main_t *vam = &vat_main;
2151 locator_set_msg_t ls;
2153 ls.locator_set_index = ntohl(mp->locator_set_index);
2154 ls.locator_set_name = format(0, "%s", mp->locator_set_name);
2155 vec_add1(vam->locator_set_msg, ls);
2159 vl_api_lisp_locator_set_details_t_handler_json (
2160 vl_api_lisp_locator_set_details_t *mp)
2162 vat_main_t *vam = &vat_main;
2163 locator_set_msg_t ls;
2165 ls.locator_set_index = ntohl(mp->locator_set_index);
2166 ls.locator_set_name = format(0, "%s", mp->locator_set_name);
2167 vec_add1(vam->locator_set_msg, ls);
2171 vl_api_lisp_eid_table_details_t_handler (
2172 vl_api_lisp_eid_table_details_t * mp)
2174 vat_main_t *vam = &vat_main;
2175 eid_table_t eid_table;
2177 memset(&eid_table, 0, sizeof(eid_table));
2178 eid_table.is_local = mp->is_local;
2179 eid_table.locator_set_index = mp->locator_set_index;
2180 eid_table.eid_type = mp->eid_type;
2181 eid_table.vni = mp->vni;
2182 eid_table.eid_prefix_len = mp->eid_prefix_len;
2183 eid_table.ttl = mp->ttl;
2184 eid_table.authoritative = mp->authoritative;
2185 clib_memcpy(eid_table.eid, mp->eid, sizeof(eid_table.eid));
2186 vec_add1(vam->eid_tables, eid_table);
2190 vl_api_lisp_eid_table_details_t_handler_json (
2191 vl_api_lisp_eid_table_details_t * mp)
2193 vat_main_t *vam = &vat_main;
2194 eid_table_t eid_table;
2196 memset(&eid_table, 0, sizeof(eid_table));
2197 eid_table.is_local = mp->is_local;
2198 eid_table.locator_set_index = mp->locator_set_index;
2199 eid_table.eid_type = mp->eid_type;
2200 eid_table.vni = mp->vni;
2201 eid_table.eid_prefix_len = mp->eid_prefix_len;
2202 eid_table.ttl = mp->ttl;
2203 eid_table.authoritative = mp->authoritative;
2204 clib_memcpy(eid_table.eid, mp->eid, sizeof(eid_table.eid));
2205 vec_add1(vam->eid_tables, eid_table);
2209 vl_api_lisp_eid_table_map_details_t_handler (
2210 vl_api_lisp_eid_table_map_details_t *mp)
2212 vat_main_t *vam = &vat_main;
2214 u8 * line = format(0, "%=10d%=10d",
2215 clib_net_to_host_u32 (mp->vni),
2216 clib_net_to_host_u32 (mp->vrf));
2217 fformat(vam->ofp, "%v\n", line);
2222 vl_api_lisp_eid_table_map_details_t_handler_json (
2223 vl_api_lisp_eid_table_map_details_t *mp)
2225 vat_main_t *vam = &vat_main;
2226 vat_json_node_t *node = NULL;
2228 if (VAT_JSON_ARRAY != vam->json_tree.type) {
2229 ASSERT(VAT_JSON_NONE == vam->json_tree.type);
2230 vat_json_init_array(&vam->json_tree);
2232 node = vat_json_array_add(&vam->json_tree);
2233 vat_json_init_object(node);
2234 vat_json_object_add_uint(node, "vrf", clib_net_to_host_u32 (mp->vrf));
2235 vat_json_object_add_uint(node, "vni", clib_net_to_host_u32 (mp->vni));
2241 format_decap_next (u8 * s, va_list * args)
2243 u32 next_index = va_arg (*args, u32);
2247 case LISP_GPE_INPUT_NEXT_DROP:
2248 return format (s, "drop");
2249 case LISP_GPE_INPUT_NEXT_IP4_INPUT:
2250 return format (s, "ip4");
2251 case LISP_GPE_INPUT_NEXT_IP6_INPUT:
2252 return format (s, "ip6");
2254 return format (s, "unknown %d", next_index);
2260 vl_api_lisp_gpe_tunnel_details_t_handler (vl_api_lisp_gpe_tunnel_details_t *mp)
2262 vat_main_t *vam = &vat_main;
2264 u8 *flag_str = NULL;
2266 iid_str = format(0, "%d (0x%x)", ntohl(mp->iid), ntohl(mp->iid));
2268 #define _(n,v) if (mp->flags & v) flag_str = format (flag_str, "%s-bit ", #n);
2269 foreach_lisp_gpe_flag_bit;
2272 fformat(vam->ofp, "%=20d%=30U%=16U%=16d%=16d%=16U"
2273 "%=16d%=16d%=16sd=16d%=16s%=16s\n",
2275 mp->is_ipv6 ? format_ip6_address : format_ip4_address,
2277 mp->is_ipv6 ? format_ip6_address : format_ip4_address,
2279 ntohl(mp->encap_fib_id),
2280 ntohl(mp->decap_fib_id),
2281 format_decap_next, ntohl(mp->dcap_next),
2293 vl_api_lisp_gpe_tunnel_details_t_handler_json (
2294 vl_api_lisp_gpe_tunnel_details_t *mp)
2296 vat_main_t *vam = &vat_main;
2297 vat_json_node_t *node = NULL;
2298 struct in6_addr ip6;
2302 next_decap_str = format(0, "%U", format_decap_next, htonl(mp->dcap_next));
2304 if (VAT_JSON_ARRAY != vam->json_tree.type) {
2305 ASSERT(VAT_JSON_NONE == vam->json_tree.type);
2306 vat_json_init_array(&vam->json_tree);
2308 node = vat_json_array_add(&vam->json_tree);
2310 vat_json_init_object(node);
2311 vat_json_object_add_uint(node, "tunel", mp->tunnels);
2313 clib_memcpy(&ip6, mp->source_ip, sizeof(ip6));
2314 vat_json_object_add_ip6(node, "source address", ip6);
2315 clib_memcpy(&ip6, mp->destination_ip, sizeof(ip6));
2316 vat_json_object_add_ip6(node, "destination address", ip6);
2318 clib_memcpy(&ip4, mp->source_ip, sizeof(ip4));
2319 vat_json_object_add_ip4(node, "source address", ip4);
2320 clib_memcpy(&ip4, mp->destination_ip, sizeof(ip4));
2321 vat_json_object_add_ip4(node, "destination address", ip4);
2323 vat_json_object_add_uint(node, "fib encap", ntohl(mp->encap_fib_id));
2324 vat_json_object_add_uint(node, "fib decap", ntohl(mp->decap_fib_id));
2325 vat_json_object_add_string_copy(node, "decap next", next_decap_str);
2326 vat_json_object_add_uint(node, "lisp version", mp->ver_res >> 6);
2327 vat_json_object_add_uint(node, "flags", mp->flags);
2328 vat_json_object_add_uint(node, "next protocol", mp->next_protocol);
2329 vat_json_object_add_uint(node, "ver_res", mp->ver_res);
2330 vat_json_object_add_uint(node, "res", mp->res);
2331 vat_json_object_add_uint(node, "iid", ntohl(mp->iid));
2333 vec_free(next_decap_str);
2337 vl_api_lisp_map_resolver_details_t_handler (
2338 vl_api_lisp_map_resolver_details_t *mp)
2340 vat_main_t *vam = &vat_main;
2342 fformat(vam->ofp, "%=20U\n",
2343 mp->is_ipv6 ? format_ip6_address : format_ip4_address,
2348 vl_api_lisp_map_resolver_details_t_handler_json (
2349 vl_api_lisp_map_resolver_details_t *mp)
2351 vat_main_t *vam = &vat_main;
2352 vat_json_node_t *node = NULL;
2353 struct in6_addr ip6;
2356 if (VAT_JSON_ARRAY != vam->json_tree.type) {
2357 ASSERT(VAT_JSON_NONE == vam->json_tree.type);
2358 vat_json_init_array(&vam->json_tree);
2360 node = vat_json_array_add(&vam->json_tree);
2362 vat_json_init_object(node);
2364 clib_memcpy(&ip6, mp->ip_address, sizeof(ip6));
2365 vat_json_object_add_ip6(node, "map resolver", ip6);
2367 clib_memcpy(&ip4, mp->ip_address, sizeof(ip4));
2368 vat_json_object_add_ip4(node, "map resolver", ip4);
2373 vl_api_show_lisp_status_reply_t_handler
2374 (vl_api_show_lisp_status_reply_t * mp)
2376 vat_main_t *vam = &vat_main;
2377 i32 retval = ntohl(mp->retval);
2380 fformat(vam->ofp, "feature: %s\ngpe: %s\n",
2381 mp->feature_status ? "enabled" : "disabled",
2382 mp->gpe_status ? "enabled" : "disabled");
2385 vam->retval = retval;
2386 vam->result_ready = 1;
2390 vl_api_show_lisp_status_reply_t_handler_json
2391 (vl_api_show_lisp_status_reply_t *mp)
2393 vat_main_t *vam = &vat_main;
2394 vat_json_node_t node;
2395 u8 * gpe_status = NULL;
2396 u8 * feature_status = NULL;
2398 gpe_status = format (0, "%s", mp->gpe_status ? "enabled" : "disabled");
2399 feature_status = format (0, "%s",
2400 mp->feature_status ? "enabled" : "disabled");
2401 vec_add1 (gpe_status, 0);
2402 vec_add1 (feature_status, 0);
2404 vat_json_init_object(&node);
2405 vat_json_object_add_string_copy(&node, "gpe_status", gpe_status);
2406 vat_json_object_add_string_copy(&node, "feature_status", feature_status);
2408 vec_free (gpe_status);
2409 vec_free (feature_status);
2411 vat_json_print(vam->ofp, &node);
2412 vat_json_free(&node);
2414 vam->retval = ntohl(mp->retval);
2415 vam->result_ready = 1;
2419 vl_api_lisp_get_map_request_itr_rlocs_reply_t_handler (
2420 vl_api_lisp_get_map_request_itr_rlocs_reply_t * mp)
2422 vat_main_t * vam = &vat_main;
2423 i32 retval = ntohl(mp->retval);
2426 fformat(vam->ofp, "%=20s\n",
2427 mp->locator_set_name);
2430 vam->retval = retval;
2431 vam->result_ready = 1;
2435 vl_api_lisp_get_map_request_itr_rlocs_reply_t_handler_json (
2436 vl_api_lisp_get_map_request_itr_rlocs_reply_t * mp)
2438 vat_main_t * vam = &vat_main;
2439 vat_json_node_t * node = NULL;
2441 if (VAT_JSON_ARRAY != vam->json_tree.type) {
2442 ASSERT(VAT_JSON_NONE == vam->json_tree.type);
2443 vat_json_init_array(&vam->json_tree);
2445 node = vat_json_array_add(&vam->json_tree);
2447 vat_json_init_object(node);
2448 vat_json_object_add_string_copy(node, "itr-rlocs", mp->locator_set_name);
2450 vat_json_print(vam->ofp, node);
2451 vat_json_free(node);
2453 vam->retval = ntohl(mp->retval);
2454 vam->result_ready = 1;
2458 vl_api_show_lisp_pitr_reply_t_handler (vl_api_show_lisp_pitr_reply_t * mp)
2460 vat_main_t *vam = &vat_main;
2461 i32 retval = ntohl(mp->retval);
2464 fformat(vam->ofp, "%-20s%-16s\n",
2465 mp->status ? "enabled" : "disabled",
2466 mp->status ? (char *) mp->locator_set_name : "");
2469 vam->retval = retval;
2470 vam->result_ready = 1;
2474 vl_api_show_lisp_pitr_reply_t_handler_json (vl_api_show_lisp_pitr_reply_t * mp)
2476 vat_main_t *vam = &vat_main;
2477 vat_json_node_t node;
2480 status = format (0, "%s", mp->status ? "enabled" : "disabled");
2481 vec_add1 (status, 0);
2483 vat_json_init_object(&node);
2484 vat_json_object_add_string_copy(&node, "status", status);
2486 vat_json_object_add_string_copy(&node, "locator_set", mp->locator_set_name);
2491 vat_json_print(vam->ofp, &node);
2492 vat_json_free(&node);
2494 vam->retval = ntohl(mp->retval);
2495 vam->result_ready = 1;
2498 static u8 * format_policer_type (u8 * s, va_list * va)
2500 u32 i = va_arg (*va, u32);
2502 if (i == SSE2_QOS_POLICER_TYPE_1R2C)
2503 s = format (s, "1r2c");
2504 else if (i == SSE2_QOS_POLICER_TYPE_1R3C_RFC_2697)
2505 s = format (s, "1r3c");
2506 else if (i == SSE2_QOS_POLICER_TYPE_2R3C_RFC_2698)
2507 s = format (s, "2r3c-2698");
2508 else if (i == SSE2_QOS_POLICER_TYPE_2R3C_RFC_4115)
2509 s = format (s, "2r3c-4115");
2510 else if (i == SSE2_QOS_POLICER_TYPE_2R3C_RFC_MEF5CF1)
2511 s = format (s, "2r3c-mef5cf1");
2513 s = format (s, "ILLEGAL");
2517 static u8 * format_policer_rate_type (u8 * s, va_list * va)
2519 u32 i = va_arg (*va, u32);
2521 if (i == SSE2_QOS_RATE_KBPS)
2522 s = format (s, "kbps");
2523 else if (i == SSE2_QOS_RATE_PPS)
2524 s = format(s, "pps");
2526 s = format (s, "ILLEGAL");
2530 static u8 * format_policer_round_type (u8 * s, va_list * va)
2532 u32 i = va_arg (*va, u32);
2534 if (i == SSE2_QOS_ROUND_TO_CLOSEST)
2535 s = format(s, "closest");
2536 else if (i == SSE2_QOS_ROUND_TO_UP)
2537 s = format (s, "up");
2538 else if (i == SSE2_QOS_ROUND_TO_DOWN)
2539 s = format (s, "down");
2541 s = format (s, "ILLEGAL");
2545 static u8 * format_policer_action_type (u8 * s, va_list * va)
2547 u32 i = va_arg (*va, u32);
2549 if (i == SSE2_QOS_ACTION_DROP)
2550 s = format (s, "drop");
2551 else if (i == SSE2_QOS_ACTION_TRANSMIT)
2552 s = format (s, "transmit");
2553 else if (i == SSE2_QOS_ACTION_MARK_AND_TRANSMIT)
2554 s = format (s, "mark-and-transmit");
2556 s = format (s, "ILLEGAL");
2560 static u8 * format_dscp (u8 * s, va_list * va)
2562 u32 i = va_arg (*va, u32);
2566 #define _(v,f,str) case VNET_DSCP_##f: t = str; break;
2570 return format (s, "ILLEGAL");
2572 s = format (s, "%s", t);
2576 static void vl_api_policer_details_t_handler
2577 (vl_api_policer_details_t * mp)
2579 vat_main_t * vam = &vat_main;
2580 u8 *conform_dscp_str, *exceed_dscp_str, *violate_dscp_str;
2582 if (mp->conform_action_type == SSE2_QOS_ACTION_MARK_AND_TRANSMIT)
2583 conform_dscp_str = format(0, "%U", format_dscp, mp->conform_dscp);
2585 conform_dscp_str = format(0, "");
2587 if (mp->exceed_action_type == SSE2_QOS_ACTION_MARK_AND_TRANSMIT)
2588 exceed_dscp_str = format(0, "%U", format_dscp, mp->exceed_dscp);
2590 exceed_dscp_str = format(0, "");
2592 if (mp->violate_action_type == SSE2_QOS_ACTION_MARK_AND_TRANSMIT)
2593 violate_dscp_str = format(0, "%U", format_dscp, mp->violate_dscp);
2595 violate_dscp_str = format(0, "");
2597 fformat (vam->ofp, "Name \"%s\", type %U, cir %u, eir %u, cb %u, eb %u, "
2598 "rate type %U, round type %U, %s rate, %s color-aware, "
2599 "cir %u tok/period, pir %u tok/period, scale %u, cur lim %u, "
2600 "cur bkt %u, ext lim %u, ext bkt %u, last update %llu"
2601 "conform action %U%s, exceed action %U%s, violate action %U%s\n",
2603 format_policer_type, mp->type,
2606 clib_net_to_host_u64(mp->cb),
2607 clib_net_to_host_u64(mp->eb),
2608 format_policer_rate_type, mp->rate_type,
2609 format_policer_round_type, mp->round_type,
2610 mp->single_rate ? "single" : "dual",
2611 mp->color_aware ? "is" : "not",
2612 ntohl(mp->cir_tokens_per_period),
2613 ntohl(mp->pir_tokens_per_period),
2615 ntohl(mp->current_limit),
2616 ntohl(mp->current_bucket),
2617 ntohl(mp->extended_limit),
2618 ntohl(mp->extended_bucket),
2619 clib_net_to_host_u64(mp->last_update_time),
2620 format_policer_action_type, mp->conform_action_type,
2622 format_policer_action_type, mp->exceed_action_type,
2624 format_policer_action_type, mp->violate_action_type,
2627 vec_free(conform_dscp_str);
2628 vec_free(exceed_dscp_str);
2629 vec_free(violate_dscp_str);
2632 static void vl_api_policer_details_t_handler_json
2633 (vl_api_policer_details_t * mp)
2635 vat_main_t * vam = &vat_main;
2636 vat_json_node_t *node;
2637 u8 *rate_type_str, *round_type_str, *type_str;
2638 u8 *conform_action_str, *exceed_action_str, *violate_action_str;
2640 rate_type_str = format(0, "%U", format_policer_rate_type, mp->rate_type);
2641 round_type_str = format(0, "%U", format_policer_round_type, mp->round_type);
2642 type_str = format(0, "%U", format_policer_type, mp->type);
2643 conform_action_str = format(0, "%U", format_policer_action_type,
2644 mp->conform_action_type);
2645 exceed_action_str = format(0, "%U", format_policer_action_type,
2646 mp->exceed_action_type);
2647 violate_action_str = format(0, "%U", format_policer_action_type,
2648 mp->violate_action_type);
2650 if (VAT_JSON_ARRAY != vam->json_tree.type) {
2651 ASSERT(VAT_JSON_NONE == vam->json_tree.type);
2652 vat_json_init_array(&vam->json_tree);
2654 node = vat_json_array_add(&vam->json_tree);
2656 vat_json_init_object(node);
2657 vat_json_object_add_string_copy(node, "name", mp->name);
2658 vat_json_object_add_uint(node, "cir", ntohl(mp->cir));
2659 vat_json_object_add_uint(node, "eir", ntohl(mp->eir));
2660 vat_json_object_add_uint(node, "cb", ntohl(mp->cb));
2661 vat_json_object_add_uint(node, "eb", ntohl(mp->eb));
2662 vat_json_object_add_string_copy(node, "rate_type", rate_type_str);
2663 vat_json_object_add_string_copy(node, "round_type", round_type_str);
2664 vat_json_object_add_string_copy(node, "type", type_str);
2665 vat_json_object_add_uint(node, "single_rate", mp->single_rate);
2666 vat_json_object_add_uint(node, "color_aware", mp->color_aware);
2667 vat_json_object_add_uint(node, "scale", ntohl(mp->scale));
2668 vat_json_object_add_uint(node, "cir_tokens_per_period",
2669 ntohl(mp->cir_tokens_per_period));
2670 vat_json_object_add_uint(node, "eir_tokens_per_period",
2671 ntohl(mp->pir_tokens_per_period));
2672 vat_json_object_add_uint(node, "current_limit", ntohl(mp->current_limit));
2673 vat_json_object_add_uint(node, "current_bucket", ntohl(mp->current_bucket));
2674 vat_json_object_add_uint(node, "extended_limit", ntohl(mp->extended_limit));
2675 vat_json_object_add_uint(node, "extended_bucket",
2676 ntohl(mp->extended_bucket));
2677 vat_json_object_add_uint(node, "last_update_time",
2678 ntohl(mp->last_update_time));
2679 vat_json_object_add_string_copy(node, "conform_action", conform_action_str);
2680 if (mp->conform_action_type == SSE2_QOS_ACTION_MARK_AND_TRANSMIT) {
2681 u8 *dscp_str = format(0, "%U", format_dscp, mp->conform_dscp);
2682 vat_json_object_add_string_copy(node, "conform_dscp", dscp_str);
2685 vat_json_object_add_string_copy(node, "exceed_action", exceed_action_str);
2686 if (mp->exceed_action_type == SSE2_QOS_ACTION_MARK_AND_TRANSMIT) {
2687 u8 *dscp_str = format(0, "%U", format_dscp, mp->exceed_dscp);
2688 vat_json_object_add_string_copy(node, "exceed_dscp", dscp_str);
2691 vat_json_object_add_string_copy(node, "violate_action", violate_action_str);
2692 if (mp->violate_action_type == SSE2_QOS_ACTION_MARK_AND_TRANSMIT) {
2693 u8 *dscp_str = format(0, "%U", format_dscp, mp->violate_dscp);
2694 vat_json_object_add_string_copy(node, "violate_dscp", dscp_str);
2698 vec_free(rate_type_str);
2699 vec_free(round_type_str);
2701 vec_free(conform_action_str);
2702 vec_free(exceed_action_str);
2703 vec_free(violate_action_str);
2706 static void vl_api_classify_table_ids_reply_t_handler (vl_api_classify_table_ids_reply_t * mp)
2708 vat_main_t * vam = &vat_main;
2709 int i, count = ntohl(mp->count);
2712 fformat (vam->ofp, "classify table ids (%d) : ", count);
2713 for (i = 0; i < count; i++)
2715 fformat (vam->ofp, "%d", ntohl(mp->ids[i]));
2716 fformat (vam->ofp, (i<count-1)?",":"\n");
2718 vam->retval = ntohl(mp->retval);
2719 vam->result_ready = 1;
2722 static void vl_api_classify_table_ids_reply_t_handler_json (vl_api_classify_table_ids_reply_t * mp)
2724 vat_main_t * vam = &vat_main;
2725 int i, count = ntohl(mp->count);
2728 vat_json_node_t node;
2730 vat_json_init_object(&node);
2731 for (i = 0; i < count; i++)
2733 vat_json_object_add_uint(&node, "table_id", ntohl(mp->ids[i]));
2735 vat_json_print(vam->ofp, &node);
2736 vat_json_free(&node);
2738 vam->retval = ntohl(mp->retval);
2739 vam->result_ready = 1;
2742 static void vl_api_classify_table_by_interface_reply_t_handler (vl_api_classify_table_by_interface_reply_t * mp)
2744 vat_main_t * vam = &vat_main;
2747 table_id = ntohl(mp->l2_table_id);
2749 fformat (vam->ofp, "l2 table id : %d\n", table_id);
2751 fformat (vam->ofp, "l2 table id : No input ACL tables configured\n");
2752 table_id = ntohl(mp->ip4_table_id);
2754 fformat (vam->ofp, "ip4 table id : %d\n", table_id);
2756 fformat (vam->ofp, "ip4 table id : No input ACL tables configured\n");
2757 table_id = ntohl(mp->ip6_table_id);
2759 fformat (vam->ofp, "ip6 table id : %d\n", table_id);
2761 fformat (vam->ofp, "ip6 table id : No input ACL tables configured\n");
2762 vam->retval = ntohl(mp->retval);
2763 vam->result_ready = 1;
2766 static void vl_api_classify_table_by_interface_reply_t_handler_json (vl_api_classify_table_by_interface_reply_t * mp)
2768 vat_main_t * vam = &vat_main;
2769 vat_json_node_t node;
2771 vat_json_init_object(&node);
2773 vat_json_object_add_int(&node, "l2_table_id", ntohl(mp->l2_table_id));
2774 vat_json_object_add_int(&node, "ip4_table_id", ntohl(mp->ip4_table_id));
2775 vat_json_object_add_int(&node, "ip6_table_id", ntohl(mp->ip6_table_id));
2777 vat_json_print(vam->ofp, &node);
2778 vat_json_free(&node);
2780 vam->retval = ntohl(mp->retval);
2781 vam->result_ready = 1;
2784 static void vl_api_policer_add_del_reply_t_handler
2785 (vl_api_policer_add_del_reply_t * mp)
2787 vat_main_t * vam = &vat_main;
2788 i32 retval = ntohl(mp->retval);
2789 if (vam->async_mode) {
2790 vam->async_errors += (retval < 0);
2792 vam->retval = retval;
2793 vam->result_ready = 1;
2794 if (retval == 0 && mp->policer_index != 0xFFFFFFFF)
2796 * Note: this is just barely thread-safe, depends on
2797 * the main thread spinning waiting for an answer...
2799 errmsg ("policer index %d\n", ntohl(mp->policer_index));
2803 static void vl_api_policer_add_del_reply_t_handler_json
2804 (vl_api_policer_add_del_reply_t * mp)
2806 vat_main_t * vam = &vat_main;
2807 vat_json_node_t node;
2809 vat_json_init_object(&node);
2810 vat_json_object_add_int(&node, "retval", ntohl(mp->retval));
2811 vat_json_object_add_uint(&node, "policer_index", ntohl(mp->policer_index));
2813 vat_json_print(vam->ofp, &node);
2814 vat_json_free(&node);
2816 vam->retval = ntohl(mp->retval);
2817 vam->result_ready = 1;
2820 /* Format hex dump. */
2821 u8 * format_hex_bytes (u8 * s, va_list * va)
2823 u8 * bytes = va_arg (*va, u8 *);
2824 int n_bytes = va_arg (*va, int);
2827 /* Print short or long form depending on byte count. */
2828 uword short_form = n_bytes <= 32;
2829 uword indent = format_get_indent (s);
2834 for (i = 0; i < n_bytes; i++)
2836 if (! short_form && (i % 32) == 0)
2837 s = format (s, "%08x: ", i);
2838 s = format (s, "%02x", bytes[i]);
2839 if (! short_form && ((i + 1) % 32) == 0 && (i + 1) < n_bytes)
2840 s = format (s, "\n%U", format_white_space, indent);
2846 static void vl_api_classify_table_info_reply_t_handler (vl_api_classify_table_info_reply_t * mp)
2848 vat_main_t * vam = &vat_main;
2849 i32 retval = ntohl(mp->retval);
2851 fformat (vam->ofp, "classify table info :\n");
2852 fformat (vam->ofp, "sessions: %d nexttbl: %d nextnode: %d\n", ntohl(mp->active_sessions), ntohl(mp->next_table_index), ntohl(mp->miss_next_index));
2853 fformat (vam->ofp, "nbuckets: %d skip: %d match: %d\n", ntohl(mp->nbuckets), ntohl(mp->skip_n_vectors), ntohl(mp->match_n_vectors));
2854 fformat (vam->ofp, "mask: %U\n", format_hex_bytes, mp->mask, ntohl(mp->mask_length));
2856 vam->retval = retval;
2857 vam->result_ready = 1;
2860 static void vl_api_classify_table_info_reply_t_handler_json (vl_api_classify_table_info_reply_t * mp)
2862 vat_main_t * vam = &vat_main;
2863 vat_json_node_t node;
2865 i32 retval = ntohl(mp->retval);
2867 vat_json_init_object(&node);
2869 vat_json_object_add_int(&node, "sessions", ntohl(mp->active_sessions));
2870 vat_json_object_add_int(&node, "nexttbl", ntohl(mp->next_table_index));
2871 vat_json_object_add_int(&node, "nextnode", ntohl(mp->miss_next_index));
2872 vat_json_object_add_int(&node, "nbuckets", ntohl(mp->nbuckets));
2873 vat_json_object_add_int(&node, "skip", ntohl(mp->skip_n_vectors));
2874 vat_json_object_add_int(&node, "match", ntohl(mp->match_n_vectors));
2875 u8 * s = format (0, "%U%c",format_hex_bytes, mp->mask, ntohl(mp->mask_length), 0);
2876 vat_json_object_add_string_copy(&node, "mask", s);
2878 vat_json_print(vam->ofp, &node);
2879 vat_json_free(&node);
2881 vam->retval = ntohl(mp->retval);
2882 vam->result_ready = 1;
2885 static void vl_api_classify_session_details_t_handler (vl_api_classify_session_details_t * mp)
2887 vat_main_t * vam = &vat_main;
2889 fformat (vam->ofp, "next_index: %d advance: %d opaque: %d ", ntohl(mp->hit_next_index), ntohl(mp->advance), ntohl(mp->opaque_index));
2890 fformat (vam->ofp, "mask: %U\n", format_hex_bytes, mp->match, ntohl(mp->match_length));
2893 static void vl_api_classify_session_details_t_handler_json (vl_api_classify_session_details_t * mp)
2895 vat_main_t * vam = &vat_main;
2896 vat_json_node_t *node = NULL;
2898 if (VAT_JSON_ARRAY != vam->json_tree.type) {
2899 ASSERT(VAT_JSON_NONE == vam->json_tree.type);
2900 vat_json_init_array(&vam->json_tree);
2902 node = vat_json_array_add(&vam->json_tree);
2904 vat_json_init_object(node);
2905 vat_json_object_add_int(node, "next_index", ntohl(mp->hit_next_index));
2906 vat_json_object_add_int(node, "advance", ntohl(mp->advance));
2907 vat_json_object_add_int(node, "opaque", ntohl(mp->opaque_index));
2908 u8 * s = format (0, "%U%c",format_hex_bytes, mp->match, ntohl(mp->match_length), 0);
2909 vat_json_object_add_string_copy(node, "match", s);
2912 static void vl_api_pg_create_interface_reply_t_handler
2913 (vl_api_pg_create_interface_reply_t * mp)
2915 vat_main_t * vam = &vat_main;
2917 vam->retval = ntohl(mp->retval);
2918 vam->result_ready = 1;
2921 static void vl_api_pg_create_interface_reply_t_handler_json
2922 (vl_api_pg_create_interface_reply_t * mp)
2924 vat_main_t * vam = &vat_main;
2925 vat_json_node_t node;
2927 i32 retval = ntohl(mp->retval);
2929 vat_json_init_object(&node);
2931 vat_json_object_add_int(&node, "sw_if_index", ntohl(mp->sw_if_index));
2933 vat_json_print(vam->ofp, &node);
2934 vat_json_free(&node);
2936 vam->retval = ntohl(mp->retval);
2937 vam->result_ready = 1;
2940 static void vl_api_policer_classify_details_t_handler
2941 (vl_api_policer_classify_details_t * mp)
2943 vat_main_t * vam = &vat_main;
2945 fformat (vam->ofp, "%10d%20d\n", ntohl(mp->sw_if_index),
2946 ntohl(mp->table_index));
2949 static void vl_api_policer_classify_details_t_handler_json
2950 (vl_api_policer_classify_details_t * mp)
2952 vat_main_t * vam = &vat_main;
2953 vat_json_node_t * node;
2955 if (VAT_JSON_ARRAY != vam->json_tree.type) {
2956 ASSERT(VAT_JSON_NONE == vam->json_tree.type);
2957 vat_json_init_array(&vam->json_tree);
2959 node = vat_json_array_add(&vam->json_tree);
2961 vat_json_init_object(node);
2962 vat_json_object_add_uint(node, "sw_if_index", ntohl(mp->sw_if_index));
2963 vat_json_object_add_uint(node, "table_index", ntohl(mp->table_index));
2967 #define vl_api_vnet_ip4_fib_counters_t_endian vl_noop_handler
2968 #define vl_api_vnet_ip4_fib_counters_t_print vl_noop_handler
2969 #define vl_api_vnet_ip6_fib_counters_t_endian vl_noop_handler
2970 #define vl_api_vnet_ip6_fib_counters_t_print vl_noop_handler
2973 * Generate boilerplate reply handlers, which
2974 * dig the return value out of the xxx_reply_t API message,
2975 * stick it into vam->retval, and set vam->result_ready
2977 * Could also do this by pointing N message decode slots at
2978 * a single function, but that could break in subtle ways.
2981 #define foreach_standard_reply_retval_handler \
2982 _(sw_interface_set_flags_reply) \
2983 _(sw_interface_add_del_address_reply) \
2984 _(sw_interface_set_table_reply) \
2985 _(sw_interface_set_vpath_reply) \
2986 _(sw_interface_set_l2_bridge_reply) \
2987 _(bridge_domain_add_del_reply) \
2988 _(sw_interface_set_l2_xconnect_reply) \
2989 _(l2fib_add_del_reply) \
2990 _(ip_add_del_route_reply) \
2991 _(proxy_arp_add_del_reply) \
2992 _(proxy_arp_intfc_enable_disable_reply) \
2993 _(mpls_add_del_encap_reply) \
2994 _(mpls_add_del_decap_reply) \
2995 _(mpls_ethernet_add_del_tunnel_2_reply) \
2996 _(sw_interface_set_unnumbered_reply) \
2997 _(ip_neighbor_add_del_reply) \
2998 _(reset_vrf_reply) \
2999 _(oam_add_del_reply) \
3000 _(reset_fib_reply) \
3001 _(dhcp_proxy_config_reply) \
3002 _(dhcp_proxy_config_2_reply) \
3003 _(dhcp_proxy_set_vss_reply) \
3004 _(dhcp_client_config_reply) \
3005 _(set_ip_flow_hash_reply) \
3006 _(sw_interface_ip6_enable_disable_reply) \
3007 _(sw_interface_ip6_set_link_local_address_reply) \
3008 _(sw_interface_ip6nd_ra_prefix_reply) \
3009 _(sw_interface_ip6nd_ra_config_reply) \
3010 _(set_arp_neighbor_limit_reply) \
3011 _(l2_patch_add_del_reply) \
3012 _(sr_tunnel_add_del_reply) \
3013 _(sr_policy_add_del_reply) \
3014 _(sr_multicast_map_add_del_reply) \
3015 _(classify_add_del_session_reply) \
3016 _(classify_set_interface_ip_table_reply) \
3017 _(classify_set_interface_l2_tables_reply) \
3018 _(l2tpv3_set_tunnel_cookies_reply) \
3019 _(l2tpv3_interface_enable_disable_reply) \
3020 _(l2tpv3_set_lookup_key_reply) \
3021 _(l2_fib_clear_table_reply) \
3022 _(l2_interface_efp_filter_reply) \
3023 _(l2_interface_vlan_tag_rewrite_reply) \
3024 _(modify_vhost_user_if_reply) \
3025 _(delete_vhost_user_if_reply) \
3026 _(want_ip4_arp_events_reply) \
3027 _(input_acl_set_interface_reply) \
3028 _(ipsec_spd_add_del_reply) \
3029 _(ipsec_interface_add_del_spd_reply) \
3030 _(ipsec_spd_add_del_entry_reply) \
3031 _(ipsec_sad_add_del_entry_reply) \
3032 _(ipsec_sa_set_key_reply) \
3033 _(ikev2_profile_add_del_reply) \
3034 _(ikev2_profile_set_auth_reply) \
3035 _(ikev2_profile_set_id_reply) \
3036 _(ikev2_profile_set_ts_reply) \
3037 _(ikev2_set_local_key_reply) \
3038 _(delete_loopback_reply) \
3039 _(bd_ip_mac_add_del_reply) \
3040 _(map_del_domain_reply) \
3041 _(map_add_del_rule_reply) \
3042 _(want_interface_events_reply) \
3043 _(want_stats_reply) \
3044 _(cop_interface_enable_disable_reply) \
3045 _(cop_whitelist_enable_disable_reply) \
3046 _(sw_interface_clear_stats_reply) \
3047 _(trace_profile_add_reply) \
3048 _(trace_profile_apply_reply) \
3049 _(trace_profile_del_reply) \
3050 _(lisp_add_del_locator_set_reply) \
3051 _(lisp_add_del_locator_reply) \
3052 _(lisp_add_del_local_eid_reply) \
3053 _(lisp_add_del_remote_mapping_reply) \
3054 _(lisp_add_del_adjacency_reply) \
3055 _(lisp_gpe_add_del_fwd_entry_reply) \
3056 _(lisp_add_del_map_resolver_reply) \
3057 _(lisp_gpe_enable_disable_reply) \
3058 _(lisp_gpe_add_del_iface_reply) \
3059 _(lisp_enable_disable_reply) \
3060 _(lisp_pitr_set_locator_set_reply) \
3061 _(lisp_add_del_map_request_itr_rlocs_reply) \
3062 _(lisp_eid_table_add_del_map_reply) \
3063 _(vxlan_gpe_add_del_tunnel_reply) \
3064 _(af_packet_delete_reply) \
3065 _(policer_classify_set_interface_reply) \
3066 _(netmap_create_reply) \
3067 _(netmap_delete_reply) \
3068 _(ipfix_enable_reply) \
3069 _(pg_capture_reply) \
3070 _(pg_enable_disable_reply) \
3071 _(ip_source_and_port_range_check_add_del_reply) \
3072 _(ip_source_and_port_range_check_interface_add_del_reply)
3075 static void vl_api_##n##_t_handler \
3076 (vl_api_##n##_t * mp) \
3078 vat_main_t * vam = &vat_main; \
3079 i32 retval = ntohl(mp->retval); \
3080 if (vam->async_mode) { \
3081 vam->async_errors += (retval < 0); \
3083 vam->retval = retval; \
3084 vam->result_ready = 1; \
3087 foreach_standard_reply_retval_handler;
3091 static void vl_api_##n##_t_handler_json \
3092 (vl_api_##n##_t * mp) \
3094 vat_main_t * vam = &vat_main; \
3095 vat_json_node_t node; \
3096 vat_json_init_object(&node); \
3097 vat_json_object_add_int(&node, "retval", ntohl(mp->retval)); \
3098 vat_json_print(vam->ofp, &node); \
3099 vam->retval = ntohl(mp->retval); \
3100 vam->result_ready = 1; \
3102 foreach_standard_reply_retval_handler;
3106 * Table of message reply handlers, must include boilerplate handlers
3110 #define foreach_vpe_api_reply_msg \
3111 _(CREATE_LOOPBACK_REPLY, create_loopback_reply) \
3112 _(SW_INTERFACE_DETAILS, sw_interface_details) \
3113 _(SW_INTERFACE_SET_FLAGS, sw_interface_set_flags) \
3114 _(SW_INTERFACE_SET_FLAGS_REPLY, sw_interface_set_flags_reply) \
3115 _(CONTROL_PING_REPLY, control_ping_reply) \
3116 _(NOPRINT_CONTROL_PING_REPLY, noprint_control_ping_reply) \
3117 _(CLI_REPLY, cli_reply) \
3118 _(SW_INTERFACE_ADD_DEL_ADDRESS_REPLY, \
3119 sw_interface_add_del_address_reply) \
3120 _(SW_INTERFACE_SET_TABLE_REPLY, sw_interface_set_table_reply) \
3121 _(SW_INTERFACE_SET_VPATH_REPLY, sw_interface_set_vpath_reply) \
3122 _(SW_INTERFACE_SET_L2_XCONNECT_REPLY, \
3123 sw_interface_set_l2_xconnect_reply) \
3124 _(SW_INTERFACE_SET_L2_BRIDGE_REPLY, \
3125 sw_interface_set_l2_bridge_reply) \
3126 _(BRIDGE_DOMAIN_ADD_DEL_REPLY, bridge_domain_add_del_reply) \
3127 _(BRIDGE_DOMAIN_DETAILS, bridge_domain_details) \
3128 _(BRIDGE_DOMAIN_SW_IF_DETAILS, bridge_domain_sw_if_details) \
3129 _(L2FIB_ADD_DEL_REPLY, l2fib_add_del_reply) \
3130 _(L2_FLAGS_REPLY, l2_flags_reply) \
3131 _(BRIDGE_FLAGS_REPLY, bridge_flags_reply) \
3132 _(TAP_CONNECT_REPLY, tap_connect_reply) \
3133 _(TAP_MODIFY_REPLY, tap_modify_reply) \
3134 _(TAP_DELETE_REPLY, tap_delete_reply) \
3135 _(SW_INTERFACE_TAP_DETAILS, sw_interface_tap_details) \
3136 _(IP_ADD_DEL_ROUTE_REPLY, ip_add_del_route_reply) \
3137 _(PROXY_ARP_ADD_DEL_REPLY, proxy_arp_add_del_reply) \
3138 _(PROXY_ARP_INTFC_ENABLE_DISABLE_REPLY, \
3139 proxy_arp_intfc_enable_disable_reply) \
3140 _(MPLS_ADD_DEL_ENCAP_REPLY, mpls_add_del_encap_reply) \
3141 _(MPLS_ADD_DEL_DECAP_REPLY, mpls_add_del_decap_reply) \
3142 _(MPLS_GRE_ADD_DEL_TUNNEL_REPLY, mpls_gre_add_del_tunnel_reply) \
3143 _(MPLS_ETHERNET_ADD_DEL_TUNNEL_REPLY, \
3144 mpls_ethernet_add_del_tunnel_reply) \
3145 _(MPLS_ETHERNET_ADD_DEL_TUNNEL_2_REPLY, \
3146 mpls_ethernet_add_del_tunnel_2_reply) \
3147 _(SW_INTERFACE_SET_UNNUMBERED_REPLY, \
3148 sw_interface_set_unnumbered_reply) \
3149 _(IP_NEIGHBOR_ADD_DEL_REPLY, ip_neighbor_add_del_reply) \
3150 _(RESET_VRF_REPLY, reset_vrf_reply) \
3151 _(CREATE_VLAN_SUBIF_REPLY, create_vlan_subif_reply) \
3152 _(CREATE_SUBIF_REPLY, create_subif_reply) \
3153 _(OAM_ADD_DEL_REPLY, oam_add_del_reply) \
3154 _(RESET_FIB_REPLY, reset_fib_reply) \
3155 _(DHCP_PROXY_CONFIG_REPLY, dhcp_proxy_config_reply) \
3156 _(DHCP_PROXY_CONFIG_2_REPLY, dhcp_proxy_config_2_reply) \
3157 _(DHCP_PROXY_SET_VSS_REPLY, dhcp_proxy_set_vss_reply) \
3158 _(DHCP_CLIENT_CONFIG_REPLY, dhcp_client_config_reply) \
3159 _(SET_IP_FLOW_HASH_REPLY, set_ip_flow_hash_reply) \
3160 _(SW_INTERFACE_IP6_ENABLE_DISABLE_REPLY, \
3161 sw_interface_ip6_enable_disable_reply) \
3162 _(SW_INTERFACE_IP6_SET_LINK_LOCAL_ADDRESS_REPLY, \
3163 sw_interface_ip6_set_link_local_address_reply) \
3164 _(SW_INTERFACE_IP6ND_RA_PREFIX_REPLY, \
3165 sw_interface_ip6nd_ra_prefix_reply) \
3166 _(SW_INTERFACE_IP6ND_RA_CONFIG_REPLY, \
3167 sw_interface_ip6nd_ra_config_reply) \
3168 _(SET_ARP_NEIGHBOR_LIMIT_REPLY, set_arp_neighbor_limit_reply) \
3169 _(L2_PATCH_ADD_DEL_REPLY, l2_patch_add_del_reply) \
3170 _(SR_TUNNEL_ADD_DEL_REPLY, sr_tunnel_add_del_reply) \
3171 _(SR_POLICY_ADD_DEL_REPLY, sr_policy_add_del_reply) \
3172 _(SR_MULTICAST_MAP_ADD_DEL_REPLY, sr_multicast_map_add_del_reply) \
3173 _(CLASSIFY_ADD_DEL_TABLE_REPLY, classify_add_del_table_reply) \
3174 _(CLASSIFY_ADD_DEL_SESSION_REPLY, classify_add_del_session_reply) \
3175 _(CLASSIFY_SET_INTERFACE_IP_TABLE_REPLY, \
3176 classify_set_interface_ip_table_reply) \
3177 _(CLASSIFY_SET_INTERFACE_L2_TABLES_REPLY, \
3178 classify_set_interface_l2_tables_reply) \
3179 _(GET_NODE_INDEX_REPLY, get_node_index_reply) \
3180 _(ADD_NODE_NEXT_REPLY, add_node_next_reply) \
3181 _(L2TPV3_CREATE_TUNNEL_REPLY, l2tpv3_create_tunnel_reply) \
3182 _(L2TPV3_SET_TUNNEL_COOKIES_REPLY, l2tpv3_set_tunnel_cookies_reply) \
3183 _(L2TPV3_INTERFACE_ENABLE_DISABLE_REPLY, \
3184 l2tpv3_interface_enable_disable_reply) \
3185 _(L2TPV3_SET_LOOKUP_KEY_REPLY, l2tpv3_set_lookup_key_reply) \
3186 _(SW_IF_L2TPV3_TUNNEL_DETAILS, sw_if_l2tpv3_tunnel_details) \
3187 _(VXLAN_ADD_DEL_TUNNEL_REPLY, vxlan_add_del_tunnel_reply) \
3188 _(VXLAN_TUNNEL_DETAILS, vxlan_tunnel_details) \
3189 _(GRE_ADD_DEL_TUNNEL_REPLY, gre_add_del_tunnel_reply) \
3190 _(GRE_TUNNEL_DETAILS, gre_tunnel_details) \
3191 _(L2_FIB_CLEAR_TABLE_REPLY, l2_fib_clear_table_reply) \
3192 _(L2_INTERFACE_EFP_FILTER_REPLY, l2_interface_efp_filter_reply) \
3193 _(L2_INTERFACE_VLAN_TAG_REWRITE_REPLY, l2_interface_vlan_tag_rewrite_reply) \
3194 _(SW_INTERFACE_VHOST_USER_DETAILS, sw_interface_vhost_user_details) \
3195 _(CREATE_VHOST_USER_IF_REPLY, create_vhost_user_if_reply) \
3196 _(MODIFY_VHOST_USER_IF_REPLY, modify_vhost_user_if_reply) \
3197 _(DELETE_VHOST_USER_IF_REPLY, delete_vhost_user_if_reply) \
3198 _(SHOW_VERSION_REPLY, show_version_reply) \
3199 _(L2_FIB_TABLE_ENTRY, l2_fib_table_entry) \
3200 _(VXLAN_GPE_ADD_DEL_TUNNEL_REPLY, vxlan_gpe_add_del_tunnel_reply) \
3201 _(VXLAN_GPE_TUNNEL_DETAILS, vxlan_gpe_tunnel_details) \
3202 _(INTERFACE_NAME_RENUMBER_REPLY, interface_name_renumber_reply) \
3203 _(WANT_IP4_ARP_EVENTS_REPLY, want_ip4_arp_events_reply) \
3204 _(IP4_ARP_EVENT, ip4_arp_event) \
3205 _(INPUT_ACL_SET_INTERFACE_REPLY, input_acl_set_interface_reply) \
3206 _(IP_ADDRESS_DETAILS, ip_address_details) \
3207 _(IP_DETAILS, ip_details) \
3208 _(IPSEC_SPD_ADD_DEL_REPLY, ipsec_spd_add_del_reply) \
3209 _(IPSEC_INTERFACE_ADD_DEL_SPD_REPLY, ipsec_interface_add_del_spd_reply) \
3210 _(IPSEC_SPD_ADD_DEL_ENTRY_REPLY, ipsec_spd_add_del_entry_reply) \
3211 _(IPSEC_SAD_ADD_DEL_ENTRY_REPLY, ipsec_sad_add_del_entry_reply) \
3212 _(IPSEC_SA_SET_KEY_REPLY, ipsec_sa_set_key_reply) \
3213 _(IKEV2_PROFILE_ADD_DEL_REPLY, ikev2_profile_add_del_reply) \
3214 _(IKEV2_PROFILE_SET_AUTH_REPLY, ikev2_profile_set_auth_reply) \
3215 _(IKEV2_PROFILE_SET_ID_REPLY, ikev2_profile_set_id_reply) \
3216 _(IKEV2_PROFILE_SET_TS_REPLY, ikev2_profile_set_ts_reply) \
3217 _(IKEV2_SET_LOCAL_KEY_REPLY, ikev2_set_local_key_reply) \
3218 _(DELETE_LOOPBACK_REPLY, delete_loopback_reply) \
3219 _(BD_IP_MAC_ADD_DEL_REPLY, bd_ip_mac_add_del_reply) \
3220 _(DHCP_COMPL_EVENT, dhcp_compl_event) \
3221 _(VNET_INTERFACE_COUNTERS, vnet_interface_counters) \
3222 _(VNET_IP4_FIB_COUNTERS, vnet_ip4_fib_counters) \
3223 _(VNET_IP6_FIB_COUNTERS, vnet_ip6_fib_counters) \
3224 _(MAP_ADD_DOMAIN_REPLY, map_add_domain_reply) \
3225 _(MAP_DEL_DOMAIN_REPLY, map_del_domain_reply) \
3226 _(MAP_ADD_DEL_RULE_REPLY, map_add_del_rule_reply) \
3227 _(MAP_DOMAIN_DETAILS, map_domain_details) \
3228 _(MAP_RULE_DETAILS, map_rule_details) \
3229 _(WANT_INTERFACE_EVENTS_REPLY, want_interface_events_reply) \
3230 _(WANT_STATS_REPLY, want_stats_reply) \
3231 _(GET_FIRST_MSG_ID_REPLY, get_first_msg_id_reply) \
3232 _(COP_INTERFACE_ENABLE_DISABLE_REPLY, cop_interface_enable_disable_reply) \
3233 _(COP_WHITELIST_ENABLE_DISABLE_REPLY, cop_whitelist_enable_disable_reply) \
3234 _(GET_NODE_GRAPH_REPLY, get_node_graph_reply) \
3235 _(SW_INTERFACE_CLEAR_STATS_REPLY, sw_interface_clear_stats_reply) \
3236 _(TRACE_PROFILE_ADD_REPLY, trace_profile_add_reply) \
3237 _(TRACE_PROFILE_APPLY_REPLY, trace_profile_apply_reply) \
3238 _(TRACE_PROFILE_DEL_REPLY, trace_profile_del_reply) \
3239 _(LISP_ADD_DEL_LOCATOR_SET_REPLY, lisp_add_del_locator_set_reply) \
3240 _(LISP_ADD_DEL_LOCATOR_REPLY, lisp_add_del_locator_reply) \
3241 _(LISP_ADD_DEL_LOCAL_EID_REPLY, lisp_add_del_local_eid_reply) \
3242 _(LISP_ADD_DEL_REMOTE_MAPPING_REPLY, lisp_add_del_remote_mapping_reply) \
3243 _(LISP_ADD_DEL_ADJACENCY_REPLY, lisp_add_del_adjacency_reply) \
3244 _(LISP_GPE_ADD_DEL_FWD_ENTRY_REPLY, lisp_gpe_add_del_fwd_entry_reply) \
3245 _(LISP_ADD_DEL_MAP_RESOLVER_REPLY, lisp_add_del_map_resolver_reply) \
3246 _(LISP_GPE_ENABLE_DISABLE_REPLY, lisp_gpe_enable_disable_reply) \
3247 _(LISP_ENABLE_DISABLE_REPLY, lisp_enable_disable_reply) \
3248 _(LISP_PITR_SET_LOCATOR_SET_REPLY, lisp_pitr_set_locator_set_reply) \
3249 _(LISP_EID_TABLE_ADD_DEL_MAP_REPLY, lisp_eid_table_add_del_map_reply) \
3250 _(LISP_GPE_ADD_DEL_IFACE_REPLY, lisp_gpe_add_del_iface_reply) \
3251 _(LISP_LOCATOR_SET_DETAILS, lisp_locator_set_details) \
3252 _(LISP_LOCATOR_DETAILS, lisp_locator_details) \
3253 _(LISP_EID_TABLE_DETAILS, lisp_eid_table_details) \
3254 _(LISP_EID_TABLE_MAP_DETAILS, lisp_eid_table_map_details) \
3255 _(LISP_GPE_TUNNEL_DETAILS, lisp_gpe_tunnel_details) \
3256 _(LISP_MAP_RESOLVER_DETAILS, lisp_map_resolver_details) \
3257 _(SHOW_LISP_STATUS_REPLY, show_lisp_status_reply) \
3258 _(LISP_ADD_DEL_MAP_REQUEST_ITR_RLOCS_REPLY, \
3259 lisp_add_del_map_request_itr_rlocs_reply) \
3260 _(LISP_GET_MAP_REQUEST_ITR_RLOCS_REPLY, \
3261 lisp_get_map_request_itr_rlocs_reply) \
3262 _(SHOW_LISP_PITR_REPLY, show_lisp_pitr_reply) \
3263 _(AF_PACKET_CREATE_REPLY, af_packet_create_reply) \
3264 _(AF_PACKET_DELETE_REPLY, af_packet_delete_reply) \
3265 _(POLICER_ADD_DEL_REPLY, policer_add_del_reply) \
3266 _(POLICER_DETAILS, policer_details) \
3267 _(POLICER_CLASSIFY_SET_INTERFACE_REPLY, policer_classify_set_interface_reply) \
3268 _(POLICER_CLASSIFY_DETAILS, policer_classify_details) \
3269 _(NETMAP_CREATE_REPLY, netmap_create_reply) \
3270 _(NETMAP_DELETE_REPLY, netmap_delete_reply) \
3271 _(MPLS_GRE_TUNNEL_DETAILS, mpls_gre_tunnel_details) \
3272 _(MPLS_ETH_TUNNEL_DETAILS, mpls_eth_tunnel_details) \
3273 _(MPLS_FIB_ENCAP_DETAILS, mpls_fib_encap_details) \
3274 _(MPLS_FIB_DECAP_DETAILS, mpls_fib_decap_details) \
3275 _(CLASSIFY_TABLE_IDS_REPLY, classify_table_ids_reply) \
3276 _(CLASSIFY_TABLE_BY_INTERFACE_REPLY, classify_table_by_interface_reply) \
3277 _(CLASSIFY_TABLE_INFO_REPLY, classify_table_info_reply) \
3278 _(CLASSIFY_SESSION_DETAILS, classify_session_details) \
3279 _(IPFIX_ENABLE_REPLY, ipfix_enable_reply) \
3280 _(IPFIX_DETAILS, ipfix_details) \
3281 _(GET_NEXT_INDEX_REPLY, get_next_index_reply) \
3282 _(PG_CREATE_INTERFACE_REPLY, pg_create_interface_reply) \
3283 _(PG_CAPTURE_REPLY, pg_capture_reply) \
3284 _(PG_ENABLE_DISABLE_REPLY, pg_enable_disable_reply) \
3285 _(IP_SOURCE_AND_PORT_RANGE_CHECK_ADD_DEL_REPLY, \
3286 ip_source_and_port_range_check_add_del_reply) \
3287 _(IP_SOURCE_AND_PORT_RANGE_CHECK_INTERFACE_ADD_DEL_REPLY, \
3288 ip_source_and_port_range_check_interface_add_del_reply)
3290 /* M: construct, but don't yet send a message */
3294 vam->result_ready = 0; \
3295 mp = vl_msg_api_alloc(sizeof(*mp)); \
3296 memset (mp, 0, sizeof (*mp)); \
3297 mp->_vl_msg_id = ntohs (VL_API_##T); \
3298 mp->client_index = vam->my_client_index; \
3303 vam->result_ready = 0; \
3304 mp = vl_msg_api_alloc(sizeof(*mp)+(n)); \
3305 memset (mp, 0, sizeof (*mp)); \
3306 mp->_vl_msg_id = ntohs (VL_API_##T); \
3307 mp->client_index = vam->my_client_index; \
3311 /* S: send a message */
3312 #define S (vl_msg_api_send_shmem (vam->vl_input_queue, (u8 *)&mp))
3314 /* W: wait for results, with timeout */
3317 timeout = vat_time_now (vam) + 1.0; \
3319 while (vat_time_now (vam) < timeout) { \
3320 if (vam->result_ready == 1) { \
3321 return (vam->retval); \
3327 /* W2: wait for results, with timeout */
3330 timeout = vat_time_now (vam) + 1.0; \
3332 while (vat_time_now (vam) < timeout) { \
3333 if (vam->result_ready == 1) { \
3335 return (vam->retval); \
3341 /* W_L: wait for results, with timeout */
3344 timeout = vat_time_now (vam) + 1.0; \
3346 while (vat_time_now (vam) < timeout) { \
3347 if (vam->result_ready == 1) { \
3349 return (vam->retval); \
3352 vam->noprint_msg = 0; \
3362 #define STR_VTR_OP_CASE(op) \
3363 case L2_VTR_ ## op: \
3366 static const char *str_vtr_op(u32 vtr_op)
3369 STR_VTR_OP_CASE(DISABLED);
3370 STR_VTR_OP_CASE(PUSH_1);
3371 STR_VTR_OP_CASE(PUSH_2);
3372 STR_VTR_OP_CASE(POP_1);
3373 STR_VTR_OP_CASE(POP_2);
3374 STR_VTR_OP_CASE(TRANSLATE_1_1);
3375 STR_VTR_OP_CASE(TRANSLATE_1_2);
3376 STR_VTR_OP_CASE(TRANSLATE_2_1);
3377 STR_VTR_OP_CASE(TRANSLATE_2_2);
3383 static int dump_sub_interface_table (vat_main_t * vam)
3385 const sw_interface_subif_t * sub = NULL;
3387 if (vam->json_output) {
3388 clib_warning ("JSON output supported only for VPE API calls and dump_stats_table");
3393 "%-30s%-12s%-11s%-7s%-5s%-9s%-9s%-6s%-8s%-10s%-10s\n",
3394 "Interface", "sw_if_index",
3395 "sub id", "dot1ad", "tags", "outer id",
3396 "inner id", "exact", "default",
3397 "outer any", "inner any");
3399 vec_foreach (sub, vam->sw_if_subif_table) {
3401 "%-30s%-12d%-11d%-7s%-5d%-9d%-9d%-6d%-8d%-10d%-10d\n",
3402 sub->interface_name,
3404 sub->sub_id, sub->sub_dot1ad ? "dot1ad" : "dot1q",
3405 sub->sub_number_of_tags, sub->sub_outer_vlan_id,
3406 sub->sub_inner_vlan_id, sub->sub_exact_match, sub->sub_default,
3407 sub->sub_outer_vlan_id_any, sub->sub_inner_vlan_id_any);
3408 if (sub->vtr_op != L2_VTR_DISABLED) {
3410 " vlan-tag-rewrite - op: %-14s [ dot1q: %d "
3411 "tag1: %d tag2: %d ]\n",
3412 str_vtr_op(sub->vtr_op), sub->vtr_push_dot1q,
3413 sub->vtr_tag1, sub->vtr_tag2);
3420 static int name_sort_cmp (void * a1, void * a2)
3422 name_sort_t * n1 = a1;
3423 name_sort_t * n2 = a2;
3425 return strcmp ((char *)n1->name, (char *)n2->name);
3428 static int dump_interface_table (vat_main_t * vam)
3431 name_sort_t * nses = 0, * ns;
3433 if (vam->json_output) {
3434 clib_warning ("JSON output supported only for VPE API calls and dump_stats_table");
3438 hash_foreach_pair (p, vam->sw_if_index_by_interface_name,
3440 vec_add2 (nses, ns, 1);
3441 ns->name = (u8 *)(p->key);
3442 ns->value = (u32) p->value[0];
3445 vec_sort_with_function (nses, name_sort_cmp);
3447 fformat (vam->ofp, "%-25s%-15s\n", "Interface", "sw_if_index");
3448 vec_foreach (ns, nses) {
3449 fformat (vam->ofp, "%-25s%-15d\n", ns->name, ns->value);
3455 static int dump_ip_table (vat_main_t * vam, int is_ipv6)
3457 const ip_details_t * det = NULL;
3458 const ip_address_details_t * address = NULL;
3469 vec_foreach (det, vam->ip_details_by_sw_if_index[is_ipv6]) {
3471 if (!det->present) {
3479 "Address", "Prefix length");
3483 vec_foreach (address, det->addr) {
3486 is_ipv6 ? format_ip6_address : format_ip4_address,
3488 address->prefix_length);
3495 static int dump_ipv4_table (vat_main_t * vam)
3497 if (vam->json_output) {
3498 clib_warning ("JSON output supported only for VPE API calls and dump_stats_table");
3502 return dump_ip_table (vam, 0);
3505 static int dump_ipv6_table (vat_main_t * vam)
3507 if (vam->json_output) {
3508 clib_warning ("JSON output supported only for VPE API calls and dump_stats_table");
3512 return dump_ip_table (vam, 1);
3515 static char* counter_type_to_str (u8 counter_type, u8 is_combined)
3518 switch(counter_type) {
3519 case VNET_INTERFACE_COUNTER_DROP:
3521 case VNET_INTERFACE_COUNTER_PUNT:
3523 case VNET_INTERFACE_COUNTER_IP4:
3525 case VNET_INTERFACE_COUNTER_IP6:
3527 case VNET_INTERFACE_COUNTER_RX_NO_BUF:
3529 case VNET_INTERFACE_COUNTER_RX_MISS:
3531 case VNET_INTERFACE_COUNTER_RX_ERROR:
3533 case VNET_INTERFACE_COUNTER_TX_ERROR:
3536 return "INVALID-COUNTER-TYPE";
3539 switch(counter_type) {
3540 case VNET_INTERFACE_COUNTER_RX:
3542 case VNET_INTERFACE_COUNTER_TX:
3545 return "INVALID-COUNTER-TYPE";
3550 static int dump_stats_table (vat_main_t * vam)
3552 vat_json_node_t node;
3553 vat_json_node_t *msg_array;
3554 vat_json_node_t *msg;
3555 vat_json_node_t *counter_array;
3556 vat_json_node_t *counter;
3557 interface_counter_t c;
3559 ip4_fib_counter_t *c4;
3560 ip6_fib_counter_t *c6;
3563 if (!vam->json_output) {
3564 clib_warning ("dump_stats_table supported only in JSON format");
3568 vat_json_init_object(&node);
3570 /* interface counters */
3571 msg_array = vat_json_object_add(&node, "interface_counters");
3572 vat_json_init_array(msg_array);
3573 for (i = 0; i < vec_len(vam->simple_interface_counters); i++) {
3574 msg = vat_json_array_add(msg_array);
3575 vat_json_init_object(msg);
3576 vat_json_object_add_string_copy(msg, "vnet_counter_type",
3577 (u8*)counter_type_to_str(i, 0));
3578 vat_json_object_add_int(msg, "is_combined", 0);
3579 counter_array = vat_json_object_add(msg, "data");
3580 vat_json_init_array(counter_array);
3581 for (j = 0; j < vec_len(vam->simple_interface_counters[i]); j++) {
3582 packets = vam->simple_interface_counters[i][j];
3583 vat_json_array_add_uint(counter_array, packets);
3586 for (i = 0; i < vec_len(vam->combined_interface_counters); i++) {
3587 msg = vat_json_array_add(msg_array);
3588 vat_json_init_object(msg);
3589 vat_json_object_add_string_copy(msg, "vnet_counter_type",
3590 (u8*)counter_type_to_str(i, 1));
3591 vat_json_object_add_int(msg, "is_combined", 1);
3592 counter_array = vat_json_object_add(msg, "data");
3593 vat_json_init_array(counter_array);
3594 for (j = 0; j < vec_len(vam->combined_interface_counters[i]); j++) {
3595 c = vam->combined_interface_counters[i][j];
3596 counter = vat_json_array_add(counter_array);
3597 vat_json_init_object(counter);
3598 vat_json_object_add_uint(counter, "packets", c.packets);
3599 vat_json_object_add_uint(counter, "bytes", c.bytes);
3603 /* ip4 fib counters */
3604 msg_array = vat_json_object_add(&node, "ip4_fib_counters");
3605 vat_json_init_array(msg_array);
3606 for (i = 0; i < vec_len(vam->ip4_fib_counters); i++) {
3607 msg = vat_json_array_add(msg_array);
3608 vat_json_init_object(msg);
3609 vat_json_object_add_uint(msg, "vrf_id", vam->ip4_fib_counters_vrf_id_by_index[i]);
3610 counter_array = vat_json_object_add(msg, "c");
3611 vat_json_init_array(counter_array);
3612 for (j = 0; j < vec_len(vam->ip4_fib_counters[i]); j++) {
3613 counter = vat_json_array_add(counter_array);
3614 vat_json_init_object(counter);
3615 c4 = &vam->ip4_fib_counters[i][j];
3616 vat_json_object_add_ip4(counter, "address", c4->address);
3617 vat_json_object_add_uint(counter, "address_length", c4->address_length);
3618 vat_json_object_add_uint(counter, "packets", c4->packets);
3619 vat_json_object_add_uint(counter, "bytes", c4->bytes);
3623 /* ip6 fib counters */
3624 msg_array = vat_json_object_add(&node, "ip6_fib_counters");
3625 vat_json_init_array(msg_array);
3626 for (i = 0; i < vec_len(vam->ip6_fib_counters); i++) {
3627 msg = vat_json_array_add(msg_array);
3628 vat_json_init_object(msg);
3629 vat_json_object_add_uint(msg, "vrf_id", vam->ip6_fib_counters_vrf_id_by_index[i]);
3630 counter_array = vat_json_object_add(msg, "c");
3631 vat_json_init_array(counter_array);
3632 for (j = 0; j < vec_len(vam->ip6_fib_counters[i]); j++) {
3633 counter = vat_json_array_add(counter_array);
3634 vat_json_init_object(counter);
3635 c6 = &vam->ip6_fib_counters[i][j];
3636 vat_json_object_add_ip6(counter, "address", c6->address);
3637 vat_json_object_add_uint(counter, "address_length", c6->address_length);
3638 vat_json_object_add_uint(counter, "packets", c6->packets);
3639 vat_json_object_add_uint(counter, "bytes", c6->bytes);
3643 vat_json_print(vam->ofp, &node);
3644 vat_json_free(&node);
3649 int exec (vat_main_t * vam)
3651 api_main_t * am = &api_main;
3652 vl_api_cli_request_t *mp;
3656 unformat_input_t * i = vam->input;
3658 if (vec_len(i->buffer) == 0)
3661 if (vam->exec_mode == 0 && unformat (i, "mode")) {
3665 if (vam->exec_mode == 1 &&
3666 (unformat (i, "exit") || unformat (i, "quit"))) {
3672 M(CLI_REQUEST, cli_request);
3675 * Copy cmd into shared memory.
3676 * In order for the CLI command to work, it
3677 * must be a vector ending in \n, not a C-string ending
3680 pthread_mutex_lock (&am->vlib_rp->mutex);
3681 oldheap = svm_push_data_heap (am->vlib_rp);
3683 vec_validate (cmd, vec_len(vam->input->buffer)-1);
3684 clib_memcpy (cmd, vam->input->buffer, vec_len(vam->input->buffer));
3686 svm_pop_heap (oldheap);
3687 pthread_mutex_unlock (&am->vlib_rp->mutex);
3689 mp->cmd_in_shmem = (u64) cmd;
3691 timeout = vat_time_now (vam) + 10.0;
3693 while (vat_time_now (vam) < timeout) {
3694 if (vam->result_ready == 1) {
3696 if (vam->shmem_result != NULL)
3697 fformat (vam->ofp, "%s", vam->shmem_result);
3698 pthread_mutex_lock (&am->vlib_rp->mutex);
3699 oldheap = svm_push_data_heap (am->vlib_rp);
3701 free_me = (u8 *)vam->shmem_result;
3704 svm_pop_heap (oldheap);
3705 pthread_mutex_unlock (&am->vlib_rp->mutex);
3712 static int api_create_loopback (vat_main_t * vam)
3714 unformat_input_t * i = vam->input;
3715 vl_api_create_loopback_t *mp;
3720 memset (mac_address, 0, sizeof (mac_address));
3722 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
3724 if (unformat (i, "mac %U", unformat_ethernet_address, mac_address))
3730 /* Construct the API message */
3731 M(CREATE_LOOPBACK, create_loopback);
3733 clib_memcpy (mp->mac_address, mac_address, sizeof (mac_address));
3738 static int api_delete_loopback (vat_main_t * vam)
3740 unformat_input_t * i = vam->input;
3741 vl_api_delete_loopback_t *mp;
3743 u32 sw_if_index = ~0;
3745 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
3747 if (unformat (i, "sw_if_index %d", &sw_if_index))
3753 if (sw_if_index == ~0)
3755 errmsg ("missing sw_if_index\n");
3759 /* Construct the API message */
3760 M(DELETE_LOOPBACK, delete_loopback);
3761 mp->sw_if_index = ntohl (sw_if_index);
3766 static int api_want_stats (vat_main_t * vam)
3768 unformat_input_t * i = vam->input;
3769 vl_api_want_stats_t * mp;
3773 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
3775 if (unformat (i, "enable"))
3777 else if (unformat (i, "disable"))
3785 errmsg ("missing enable|disable\n");
3789 M(WANT_STATS, want_stats);
3790 mp->enable_disable = enable;
3795 static int api_want_interface_events (vat_main_t * vam)
3797 unformat_input_t * i = vam->input;
3798 vl_api_want_interface_events_t * mp;
3802 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
3804 if (unformat (i, "enable"))
3806 else if (unformat (i, "disable"))
3814 errmsg ("missing enable|disable\n");
3818 M(WANT_INTERFACE_EVENTS, want_interface_events);
3819 mp->enable_disable = enable;
3821 vam->interface_event_display = enable;
3827 /* Note: non-static, called once to set up the initial intfc table */
3828 int api_sw_interface_dump (vat_main_t * vam)
3830 vl_api_sw_interface_dump_t *mp;
3833 name_sort_t * nses = 0, * ns;
3834 sw_interface_subif_t * sub = NULL;
3836 /* Toss the old name table */
3837 hash_foreach_pair (p, vam->sw_if_index_by_interface_name,
3839 vec_add2 (nses, ns, 1);
3840 ns->name = (u8 *)(p->key);
3841 ns->value = (u32) p->value[0];
3844 hash_free (vam->sw_if_index_by_interface_name);
3846 vec_foreach (ns, nses)
3847 vec_free (ns->name);
3851 vec_foreach (sub, vam->sw_if_subif_table) {
3852 vec_free (sub->interface_name);
3854 vec_free (vam->sw_if_subif_table);
3856 /* recreate the interface name hash table */
3857 vam->sw_if_index_by_interface_name
3858 = hash_create_string (0, sizeof(uword));
3860 /* Get list of ethernets */
3861 M(SW_INTERFACE_DUMP, sw_interface_dump);
3862 mp->name_filter_valid = 1;
3863 strncpy ((char *) mp->name_filter, "Ether", sizeof(mp->name_filter)-1);
3866 /* and local / loopback interfaces */
3867 M(SW_INTERFACE_DUMP, sw_interface_dump);
3868 mp->name_filter_valid = 1;
3869 strncpy ((char *) mp->name_filter, "lo", sizeof(mp->name_filter)-1);
3873 /* and vxlan-gpe tunnel interfaces */
3874 M(SW_INTERFACE_DUMP, sw_interface_dump);
3875 mp->name_filter_valid = 1;
3876 strncpy ((char *) mp->name_filter, "vxlan_gpe", sizeof(mp->name_filter)-1);
3879 /* and vxlan tunnel interfaces */
3880 M(SW_INTERFACE_DUMP, sw_interface_dump);
3881 mp->name_filter_valid = 1;
3882 strncpy ((char *) mp->name_filter, "vxlan", sizeof(mp->name_filter)-1);
3885 /* and host (af_packet) interfaces */
3886 M(SW_INTERFACE_DUMP, sw_interface_dump);
3887 mp->name_filter_valid = 1;
3888 strncpy ((char *) mp->name_filter, "host", sizeof(mp->name_filter)-1);
3891 /* and l2tpv3 tunnel interfaces */
3892 M(SW_INTERFACE_DUMP, sw_interface_dump);
3893 mp->name_filter_valid = 1;
3894 strncpy ((char *) mp->name_filter, "l2tpv3_tunnel", sizeof(mp->name_filter)-1);
3897 /* and GRE tunnel interfaces */
3898 M(SW_INTERFACE_DUMP, sw_interface_dump);
3899 mp->name_filter_valid = 1;
3900 strncpy ((char *) mp->name_filter, "gre", sizeof(mp->name_filter)-1);
3903 /* Use a control ping for synchronization */
3905 vl_api_control_ping_t * mp;
3906 M(CONTROL_PING, control_ping);
3912 static int api_sw_interface_set_flags (vat_main_t * vam)
3914 unformat_input_t * i = vam->input;
3915 vl_api_sw_interface_set_flags_t *mp;
3918 u8 sw_if_index_set = 0;
3919 u8 admin_up = 0, link_up = 0;
3921 /* Parse args required to build the message */
3922 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
3923 if (unformat (i, "admin-up"))
3925 else if (unformat (i, "admin-down"))
3927 else if (unformat (i, "link-up"))
3929 else if (unformat (i, "link-down"))
3931 else if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
3932 sw_if_index_set = 1;
3933 else if (unformat (i, "sw_if_index %d", &sw_if_index))
3934 sw_if_index_set = 1;
3939 if (sw_if_index_set == 0) {
3940 errmsg ("missing interface name or sw_if_index\n");
3944 /* Construct the API message */
3945 M(SW_INTERFACE_SET_FLAGS, sw_interface_set_flags);
3946 mp->sw_if_index = ntohl (sw_if_index);
3947 mp->admin_up_down = admin_up;
3948 mp->link_up_down = link_up;
3953 /* Wait for a reply, return the good/bad news... */
3957 static int api_sw_interface_clear_stats (vat_main_t * vam)
3959 unformat_input_t * i = vam->input;
3960 vl_api_sw_interface_clear_stats_t *mp;
3963 u8 sw_if_index_set = 0;
3965 /* Parse args required to build the message */
3966 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
3967 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
3968 sw_if_index_set = 1;
3969 else if (unformat (i, "sw_if_index %d", &sw_if_index))
3970 sw_if_index_set = 1;
3975 /* Construct the API message */
3976 M(SW_INTERFACE_CLEAR_STATS, sw_interface_clear_stats);
3978 if (sw_if_index_set == 1)
3979 mp->sw_if_index = ntohl (sw_if_index);
3981 mp->sw_if_index = ~0;
3986 /* Wait for a reply, return the good/bad news... */
3990 static int api_sw_interface_add_del_address (vat_main_t * vam)
3992 unformat_input_t * i = vam->input;
3993 vl_api_sw_interface_add_del_address_t *mp;
3996 u8 sw_if_index_set = 0;
3997 u8 is_add = 1, del_all = 0;
3998 u32 address_length = 0;
3999 u8 v4_address_set = 0;
4000 u8 v6_address_set = 0;
4001 ip4_address_t v4address;
4002 ip6_address_t v6address;
4004 /* Parse args required to build the message */
4005 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
4006 if (unformat (i, "del-all"))
4008 else if (unformat (i, "del"))
4010 else if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
4011 sw_if_index_set = 1;
4012 else if (unformat (i, "sw_if_index %d", &sw_if_index))
4013 sw_if_index_set = 1;
4014 else if (unformat (i, "%U/%d",
4015 unformat_ip4_address, &v4address,
4018 else if (unformat (i, "%U/%d",
4019 unformat_ip6_address, &v6address,
4026 if (sw_if_index_set == 0) {
4027 errmsg ("missing interface name or sw_if_index\n");
4030 if (v4_address_set && v6_address_set) {
4031 errmsg ("both v4 and v6 addresses set\n");
4034 if (!v4_address_set && !v6_address_set && !del_all) {
4035 errmsg ("no addresses set\n");
4039 /* Construct the API message */
4040 M(SW_INTERFACE_ADD_DEL_ADDRESS, sw_interface_add_del_address);
4042 mp->sw_if_index = ntohl (sw_if_index);
4043 mp->is_add = is_add;
4044 mp->del_all = del_all;
4045 if (v6_address_set) {
4047 clib_memcpy (mp->address, &v6address, sizeof (v6address));
4049 clib_memcpy (mp->address, &v4address, sizeof (v4address));
4051 mp->address_length = address_length;
4056 /* Wait for a reply, return good/bad news */
4060 static int api_sw_interface_set_table (vat_main_t * vam)
4062 unformat_input_t * i = vam->input;
4063 vl_api_sw_interface_set_table_t *mp;
4065 u32 sw_if_index, vrf_id = 0;
4066 u8 sw_if_index_set = 0;
4069 /* Parse args required to build the message */
4070 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
4071 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
4072 sw_if_index_set = 1;
4073 else if (unformat (i, "sw_if_index %d", &sw_if_index))
4074 sw_if_index_set = 1;
4075 else if (unformat (i, "vrf %d", &vrf_id))
4077 else if (unformat (i, "ipv6"))
4083 if (sw_if_index_set == 0) {
4084 errmsg ("missing interface name or sw_if_index\n");
4088 /* Construct the API message */
4089 M(SW_INTERFACE_SET_TABLE, sw_interface_set_table);
4091 mp->sw_if_index = ntohl (sw_if_index);
4092 mp->is_ipv6 = is_ipv6;
4093 mp->vrf_id = ntohl (vrf_id);
4098 /* Wait for a reply... */
4102 static int api_sw_interface_set_vpath (vat_main_t * vam)
4104 unformat_input_t * i = vam->input;
4105 vl_api_sw_interface_set_vpath_t *mp;
4107 u32 sw_if_index = 0;
4108 u8 sw_if_index_set = 0;
4111 /* Parse args required to build the message */
4112 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
4113 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
4114 sw_if_index_set = 1;
4115 else if (unformat (i, "sw_if_index %d", &sw_if_index))
4116 sw_if_index_set = 1;
4117 else if (unformat (i, "enable"))
4119 else if (unformat (i, "disable"))
4125 if (sw_if_index_set == 0) {
4126 errmsg ("missing interface name or sw_if_index\n");
4130 /* Construct the API message */
4131 M(SW_INTERFACE_SET_VPATH, sw_interface_set_vpath);
4133 mp->sw_if_index = ntohl (sw_if_index);
4134 mp->enable = is_enable;
4139 /* Wait for a reply... */
4143 static int api_sw_interface_set_l2_xconnect (vat_main_t * vam)
4145 unformat_input_t * i = vam->input;
4146 vl_api_sw_interface_set_l2_xconnect_t *mp;
4149 u8 rx_sw_if_index_set = 0;
4151 u8 tx_sw_if_index_set = 0;
4154 /* Parse args required to build the message */
4155 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
4156 if (unformat (i, "rx_sw_if_index %d", &rx_sw_if_index))
4157 rx_sw_if_index_set = 1;
4158 else if (unformat (i, "tx_sw_if_index %d", &tx_sw_if_index))
4159 tx_sw_if_index_set = 1;
4160 else if (unformat (i, "rx")) {
4161 if (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
4162 if (unformat (i, "%U", unformat_sw_if_index, vam,
4164 rx_sw_if_index_set = 1;
4167 } else if (unformat (i, "tx")) {
4168 if (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
4169 if (unformat (i, "%U", unformat_sw_if_index, vam,
4171 tx_sw_if_index_set = 1;
4174 } else if (unformat (i, "enable"))
4176 else if (unformat (i, "disable"))
4182 if (rx_sw_if_index_set == 0) {
4183 errmsg ("missing rx interface name or rx_sw_if_index\n");
4187 if (enable && (tx_sw_if_index_set == 0)) {
4188 errmsg ("missing tx interface name or tx_sw_if_index\n");
4192 M(SW_INTERFACE_SET_L2_XCONNECT, sw_interface_set_l2_xconnect);
4194 mp->rx_sw_if_index = ntohl(rx_sw_if_index);
4195 mp->tx_sw_if_index = ntohl(tx_sw_if_index);
4196 mp->enable = enable;
4203 static int api_sw_interface_set_l2_bridge (vat_main_t * vam)
4205 unformat_input_t * i = vam->input;
4206 vl_api_sw_interface_set_l2_bridge_t *mp;
4209 u8 rx_sw_if_index_set = 0;
4216 /* Parse args required to build the message */
4217 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
4218 if (unformat (i, "sw_if_index %d", &rx_sw_if_index))
4219 rx_sw_if_index_set = 1;
4220 else if (unformat (i, "bd_id %d", &bd_id))
4222 else if (unformat (i, "%U", unformat_sw_if_index, vam,
4224 rx_sw_if_index_set = 1;
4225 else if (unformat (i, "shg %d", &shg))
4227 else if (unformat (i, "bvi"))
4229 else if (unformat (i, "enable"))
4231 else if (unformat (i, "disable"))
4237 if (rx_sw_if_index_set == 0) {
4238 errmsg ("missing rx interface name or sw_if_index\n");
4242 if (enable && (bd_id_set == 0)) {
4243 errmsg ("missing bridge domain\n");
4247 M(SW_INTERFACE_SET_L2_BRIDGE, sw_interface_set_l2_bridge);
4249 mp->rx_sw_if_index = ntohl(rx_sw_if_index);
4250 mp->bd_id = ntohl(bd_id);
4253 mp->enable = enable;
4260 static int api_bridge_domain_dump (vat_main_t * vam)
4262 unformat_input_t * i = vam->input;
4263 vl_api_bridge_domain_dump_t *mp;
4267 /* Parse args required to build the message */
4268 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
4269 if (unformat (i, "bd_id %d", &bd_id))
4275 M(BRIDGE_DOMAIN_DUMP, bridge_domain_dump);
4276 mp->bd_id = ntohl(bd_id);
4279 /* Use a control ping for synchronization */
4281 vl_api_control_ping_t * mp;
4282 M(CONTROL_PING, control_ping);
4291 static int api_bridge_domain_add_del (vat_main_t * vam)
4293 unformat_input_t * i = vam->input;
4294 vl_api_bridge_domain_add_del_t *mp;
4298 u32 flood = 1, forward = 1, learn = 1, uu_flood = 1, arp_term = 0;
4300 /* Parse args required to build the message */
4301 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
4302 if (unformat (i, "bd_id %d", &bd_id))
4304 else if (unformat (i, "flood %d", &flood))
4306 else if (unformat (i, "uu-flood %d", &uu_flood))
4308 else if (unformat (i, "forward %d", &forward))
4310 else if (unformat (i, "learn %d", &learn))
4312 else if (unformat (i, "arp-term %d", &arp_term))
4314 else if (unformat (i, "del")) {
4316 flood = uu_flood = forward = learn = 0;
4323 errmsg ("missing bridge domain\n");
4327 M(BRIDGE_DOMAIN_ADD_DEL, bridge_domain_add_del);
4329 mp->bd_id = ntohl(bd_id);
4331 mp->uu_flood = uu_flood;
4332 mp->forward = forward;
4334 mp->arp_term = arp_term;
4335 mp->is_add = is_add;
4342 static int api_l2fib_add_del (vat_main_t * vam)
4344 unformat_input_t * i = vam->input;
4345 vl_api_l2fib_add_del_t *mp;
4352 u8 sw_if_index_set = 0;
4361 /* Parse args required to build the message */
4362 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
4363 if (unformat (i, "mac %U", unformat_ethernet_address, &mac))
4365 else if (unformat (i, "bd_id %d", &bd_id))
4367 else if (unformat (i, "sw_if_index %d", &sw_if_index))
4368 sw_if_index_set = 1;
4369 else if (unformat (i, "sw_if")) {
4370 if (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
4371 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
4372 sw_if_index_set = 1;
4375 } else if (unformat (i, "static"))
4377 else if (unformat (i, "filter")) {
4380 } else if (unformat (i, "bvi")) {
4383 } else if (unformat (i, "del"))
4385 else if (unformat (i, "count %d", &count))
4392 errmsg ("missing mac address\n");
4396 if (bd_id_set == 0) {
4397 errmsg ("missing bridge domain\n");
4401 if (is_add && (sw_if_index_set == 0)) {
4402 errmsg ("missing interface name or sw_if_index\n");
4407 /* Turn on async mode */
4408 vam->async_mode = 1;
4409 vam->async_errors = 0;
4410 before = vat_time_now(vam);
4413 for (j = 0; j < count; j++) {
4414 M(L2FIB_ADD_DEL, l2fib_add_del);
4417 mp->bd_id = ntohl(bd_id);
4418 mp->is_add = is_add;
4421 mp->sw_if_index = ntohl(sw_if_index);
4422 mp->static_mac = static_mac;
4423 mp->filter_mac = filter_mac;
4424 mp->bvi_mac = bvi_mac;
4426 increment_mac_address (&mac);
4432 vl_api_control_ping_t * mp;
4435 /* Shut off async mode */
4436 vam->async_mode = 0;
4438 M(CONTROL_PING, control_ping);
4441 timeout = vat_time_now(vam) + 1.0;
4442 while (vat_time_now (vam) < timeout)
4443 if (vam->result_ready == 1)
4448 if (vam->retval == -99)
4449 errmsg ("timeout\n");
4451 if (vam->async_errors > 0) {
4452 errmsg ("%d asynchronous errors\n", vam->async_errors);
4455 vam->async_errors = 0;
4456 after = vat_time_now(vam);
4458 fformat(vam->ofp, "%d routes in %.6f secs, %.2f routes/sec\n",
4459 count, after - before, count / (after - before));
4461 /* Wait for a reply... */
4464 /* Return the good/bad news */
4465 return (vam->retval);
4468 static int api_l2_flags (vat_main_t * vam)
4470 unformat_input_t * i = vam->input;
4471 vl_api_l2_flags_t *mp;
4474 u32 feature_bitmap = 0;
4475 u8 sw_if_index_set = 0;
4477 /* Parse args required to build the message */
4478 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
4479 if (unformat (i, "sw_if_index %d", &sw_if_index))
4480 sw_if_index_set = 1;
4481 else if (unformat (i, "sw_if")) {
4482 if (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
4483 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
4484 sw_if_index_set = 1;
4487 } else if (unformat (i, "learn"))
4488 feature_bitmap |= L2INPUT_FEAT_LEARN;
4489 else if (unformat (i, "forward"))
4490 feature_bitmap |= L2INPUT_FEAT_FWD;
4491 else if (unformat (i, "flood"))
4492 feature_bitmap |= L2INPUT_FEAT_FLOOD;
4493 else if (unformat (i, "uu-flood"))
4494 feature_bitmap |= L2INPUT_FEAT_UU_FLOOD;
4499 if (sw_if_index_set == 0) {
4500 errmsg ("missing interface name or sw_if_index\n");
4504 M(L2_FLAGS, l2_flags);
4506 mp->sw_if_index = ntohl(sw_if_index);
4507 mp->feature_bitmap = ntohl(feature_bitmap);
4514 static int api_bridge_flags (vat_main_t * vam)
4516 unformat_input_t * i = vam->input;
4517 vl_api_bridge_flags_t *mp;
4524 /* Parse args required to build the message */
4525 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
4526 if (unformat (i, "bd_id %d", &bd_id))
4528 else if (unformat (i, "learn"))
4530 else if (unformat (i, "forward"))
4532 else if (unformat (i, "flood"))
4534 else if (unformat (i, "uu-flood"))
4535 flags |= L2_UU_FLOOD;
4536 else if (unformat (i, "arp-term"))
4537 flags |= L2_ARP_TERM;
4538 else if (unformat (i, "off"))
4540 else if (unformat (i, "disable"))
4546 if (bd_id_set == 0) {
4547 errmsg ("missing bridge domain\n");
4551 M(BRIDGE_FLAGS, bridge_flags);
4553 mp->bd_id = ntohl(bd_id);
4554 mp->feature_bitmap = ntohl(flags);
4555 mp->is_set = is_set;
4562 static int api_bd_ip_mac_add_del (vat_main_t * vam)
4564 unformat_input_t * i = vam->input;
4565 vl_api_bd_ip_mac_add_del_t *mp;
4573 ip4_address_t v4addr;
4574 ip6_address_t v6addr;
4578 /* Parse args required to build the message */
4579 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
4580 if (unformat (i, "bd_id %d", &bd_id)) {
4582 } else if (unformat (i, "%U", unformat_ip4_address, &v4addr)) {
4584 } else if (unformat (i, "%U", unformat_ip6_address, &v6addr)) {
4587 } else if (unformat (i, "%U", unformat_ethernet_address, macaddr)) {
4589 } else if (unformat (i, "del"))
4595 if (bd_id_set == 0) {
4596 errmsg ("missing bridge domain\n");
4598 } else if (ip_set == 0) {
4599 errmsg ("missing IP address\n");
4601 } else if (mac_set == 0) {
4602 errmsg ("missing MAC address\n");
4606 M(BD_IP_MAC_ADD_DEL, bd_ip_mac_add_del);
4608 mp->bd_id = ntohl(bd_id);
4609 mp->is_ipv6 = is_ipv6;
4610 mp->is_add = is_add;
4612 clib_memcpy (mp->ip_address, &v6addr, sizeof (v6addr));
4613 else clib_memcpy (mp->ip_address, &v4addr, sizeof (v4addr));
4614 clib_memcpy (mp->mac_address, macaddr, 6);
4620 static int api_tap_connect (vat_main_t * vam)
4622 unformat_input_t * i = vam->input;
4623 vl_api_tap_connect_t *mp;
4630 memset (mac_address, 0, sizeof (mac_address));
4632 /* Parse args required to build the message */
4633 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
4634 if (unformat (i, "mac %U", unformat_ethernet_address, mac_address)) {
4637 else if (unformat (i, "random-mac"))
4639 else if (unformat (i, "tapname %s", &tap_name))
4645 if (name_set == 0) {
4646 errmsg ("missing tap name\n");
4649 if (vec_len (tap_name) > 63) {
4650 errmsg ("tap name too long\n");
4652 vec_add1 (tap_name, 0);
4654 /* Construct the API message */
4655 M(TAP_CONNECT, tap_connect);
4657 mp->use_random_mac = random_mac;
4658 clib_memcpy (mp->mac_address, mac_address, 6);
4659 clib_memcpy (mp->tap_name, tap_name, vec_len (tap_name));
4660 vec_free (tap_name);
4665 /* Wait for a reply... */
4669 static int api_tap_modify (vat_main_t * vam)
4671 unformat_input_t * i = vam->input;
4672 vl_api_tap_modify_t *mp;
4678 u32 sw_if_index = ~0;
4679 u8 sw_if_index_set = 0;
4681 memset (mac_address, 0, sizeof (mac_address));
4683 /* Parse args required to build the message */
4684 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
4685 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
4686 sw_if_index_set = 1;
4687 else if (unformat (i, "sw_if_index %d", &sw_if_index))
4688 sw_if_index_set = 1;
4689 else if (unformat (i, "mac %U", unformat_ethernet_address, mac_address)) {
4692 else if (unformat (i, "random-mac"))
4694 else if (unformat (i, "tapname %s", &tap_name))
4700 if (sw_if_index_set == 0) {
4701 errmsg ("missing vpp interface name");
4704 if (name_set == 0) {
4705 errmsg ("missing tap name\n");
4708 if (vec_len (tap_name) > 63) {
4709 errmsg ("tap name too long\n");
4711 vec_add1 (tap_name, 0);
4713 /* Construct the API message */
4714 M(TAP_MODIFY, tap_modify);
4716 mp->use_random_mac = random_mac;
4717 mp->sw_if_index = ntohl(sw_if_index);
4718 clib_memcpy (mp->mac_address, mac_address, 6);
4719 clib_memcpy (mp->tap_name, tap_name, vec_len (tap_name));
4720 vec_free (tap_name);
4725 /* Wait for a reply... */
4729 static int api_tap_delete (vat_main_t * vam)
4731 unformat_input_t * i = vam->input;
4732 vl_api_tap_delete_t *mp;
4734 u32 sw_if_index = ~0;
4735 u8 sw_if_index_set = 0;
4737 /* Parse args required to build the message */
4738 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
4739 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
4740 sw_if_index_set = 1;
4741 else if (unformat (i, "sw_if_index %d", &sw_if_index))
4742 sw_if_index_set = 1;
4747 if (sw_if_index_set == 0) {
4748 errmsg ("missing vpp interface name");
4752 /* Construct the API message */
4753 M(TAP_DELETE, tap_delete);
4755 mp->sw_if_index = ntohl(sw_if_index);
4760 /* Wait for a reply... */
4764 static int api_ip_add_del_route (vat_main_t * vam)
4766 unformat_input_t * i = vam->input;
4767 vl_api_ip_add_del_route_t *mp;
4769 u32 sw_if_index = ~0, vrf_id = 0;
4770 u8 sw_if_index_set = 0;
4772 u8 is_local = 0, is_drop = 0;
4773 u8 create_vrf_if_needed = 0;
4775 u8 next_hop_weight = 1;
4777 u8 is_multipath = 0;
4779 u8 address_length_set = 0;
4780 u32 lookup_in_vrf = 0;
4781 u32 resolve_attempts = 0;
4782 u32 dst_address_length = 0;
4783 u8 next_hop_set = 0;
4784 ip4_address_t v4_dst_address, v4_next_hop_address;
4785 ip6_address_t v6_dst_address, v6_next_hop_address;
4789 u32 random_add_del = 0;
4790 u32 * random_vector = 0;
4791 uword * random_hash;
4792 u32 random_seed = 0xdeaddabe;
4793 u32 classify_table_index = ~0;
4796 /* Parse args required to build the message */
4797 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
4798 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
4799 sw_if_index_set = 1;
4800 else if (unformat (i, "sw_if_index %d", &sw_if_index))
4801 sw_if_index_set = 1;
4802 else if (unformat (i, "%U", unformat_ip4_address,
4807 else if (unformat (i, "%U", unformat_ip6_address, &v6_dst_address)) {
4811 else if (unformat (i, "/%d", &dst_address_length)) {
4812 address_length_set = 1;
4815 else if (is_ipv6 == 0 && unformat (i, "via %U", unformat_ip4_address,
4816 &v4_next_hop_address)) {
4819 else if (is_ipv6 == 1 && unformat (i, "via %U", unformat_ip6_address,
4820 &v6_next_hop_address)) {
4823 else if (unformat (i, "resolve-attempts %d", &resolve_attempts))
4825 else if (unformat (i, "weight %d", &next_hop_weight))
4827 else if (unformat (i, "drop")) {
4829 } else if (unformat (i, "local")) {
4831 } else if (unformat (i, "classify %d", &classify_table_index)) {
4833 } else if (unformat (i, "del"))
4835 else if (unformat (i, "add"))
4837 else if (unformat (i, "not-last"))
4839 else if (unformat (i, "multipath"))
4841 else if (unformat (i, "vrf %d", &vrf_id))
4843 else if (unformat (i, "create-vrf"))
4844 create_vrf_if_needed = 1;
4845 else if (unformat (i, "count %d", &count))
4847 else if (unformat (i, "lookup-in-vrf %d", &lookup_in_vrf))
4849 else if (unformat (i, "random"))
4851 else if (unformat (i, "seed %d", &random_seed))
4854 clib_warning ("parse error '%U'", format_unformat_error, i);
4859 if (resolve_attempts > 0 && sw_if_index_set == 0) {
4860 errmsg ("ARP resolution needs explicit interface or sw_if_index\n");
4864 if (!next_hop_set && !is_drop && !is_local && !is_classify) {
4865 errmsg ("next hop / local / drop / classify not set\n");
4869 if (address_set == 0) {
4870 errmsg ("missing addresses\n");
4874 if (address_length_set == 0) {
4875 errmsg ("missing address length\n");
4879 /* Generate a pile of unique, random routes */
4880 if (random_add_del) {
4881 u32 this_random_address;
4882 random_hash = hash_create (count, sizeof(uword));
4884 hash_set (random_hash, v4_next_hop_address.as_u32, 1);
4885 for (j = 0; j <= count; j++) {
4887 this_random_address = random_u32 (&random_seed);
4888 this_random_address =
4889 clib_host_to_net_u32 (this_random_address);
4890 } while (hash_get (random_hash, this_random_address));
4891 vec_add1 (random_vector, this_random_address);
4892 hash_set (random_hash, this_random_address, 1);
4894 hash_free (random_hash);
4895 v4_dst_address.as_u32 = random_vector[0];
4899 /* Turn on async mode */
4900 vam->async_mode = 1;
4901 vam->async_errors = 0;
4902 before = vat_time_now(vam);
4905 for (j = 0; j < count; j++) {
4906 /* Construct the API message */
4907 M(IP_ADD_DEL_ROUTE, ip_add_del_route);
4909 mp->next_hop_sw_if_index = ntohl (sw_if_index);
4910 mp->vrf_id = ntohl (vrf_id);
4911 if (resolve_attempts > 0) {
4912 mp->resolve_attempts = ntohl (resolve_attempts);
4913 mp->resolve_if_needed = 1;
4915 mp->create_vrf_if_needed = create_vrf_if_needed;
4917 mp->is_add = is_add;
4918 mp->is_drop = is_drop;
4919 mp->is_ipv6 = is_ipv6;
4920 mp->is_local = is_local;
4921 mp->is_classify = is_classify;
4922 mp->is_multipath = is_multipath;
4923 mp->not_last = not_last;
4924 mp->next_hop_weight = next_hop_weight;
4925 mp->dst_address_length = dst_address_length;
4926 mp->lookup_in_vrf = ntohl(lookup_in_vrf);
4927 mp->classify_table_index = ntohl(classify_table_index);
4930 clib_memcpy (mp->dst_address, &v6_dst_address, sizeof (v6_dst_address));
4932 clib_memcpy (mp->next_hop_address, &v6_next_hop_address,
4933 sizeof (v6_next_hop_address));
4934 increment_v6_address (&v6_dst_address);
4936 clib_memcpy (mp->dst_address, &v4_dst_address, sizeof (v4_dst_address));
4938 clib_memcpy (mp->next_hop_address, &v4_next_hop_address,
4939 sizeof (v4_next_hop_address));
4941 v4_dst_address.as_u32 = random_vector[j+1];
4943 increment_v4_address (&v4_dst_address);
4949 /* When testing multiple add/del ops, use a control-ping to sync */
4951 vl_api_control_ping_t * mp;
4954 /* Shut off async mode */
4955 vam->async_mode = 0;
4957 M(CONTROL_PING, control_ping);
4960 timeout = vat_time_now(vam) + 1.0;
4961 while (vat_time_now (vam) < timeout)
4962 if (vam->result_ready == 1)
4967 if (vam->retval == -99)
4968 errmsg ("timeout\n");
4970 if (vam->async_errors > 0) {
4971 errmsg ("%d asynchronous errors\n", vam->async_errors);
4974 vam->async_errors = 0;
4975 after = vat_time_now(vam);
4977 fformat(vam->ofp, "%d routes in %.6f secs, %.2f routes/sec\n",
4978 count, after - before, count / (after - before));
4980 /* Wait for a reply... */
4984 /* Return the good/bad news */
4985 return (vam->retval);
4988 static int api_proxy_arp_add_del (vat_main_t * vam)
4990 unformat_input_t * i = vam->input;
4991 vl_api_proxy_arp_add_del_t *mp;
4995 ip4_address_t lo, hi;
4998 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
4999 if (unformat (i, "vrf %d", &vrf_id))
5001 else if (unformat (i, "%U - %U", unformat_ip4_address, &lo,
5002 unformat_ip4_address, &hi))
5004 else if (unformat (i, "del"))
5007 clib_warning ("parse error '%U'", format_unformat_error, i);
5012 if (range_set == 0) {
5013 errmsg ("address range not set\n");
5017 M(PROXY_ARP_ADD_DEL, proxy_arp_add_del);
5019 mp->vrf_id = ntohl(vrf_id);
5020 mp->is_add = is_add;
5021 clib_memcpy(mp->low_address, &lo, sizeof (mp->low_address));
5022 clib_memcpy(mp->hi_address, &hi, sizeof (mp->hi_address));
5029 static int api_proxy_arp_intfc_enable_disable (vat_main_t * vam)
5031 unformat_input_t * i = vam->input;
5032 vl_api_proxy_arp_intfc_enable_disable_t *mp;
5036 u8 sw_if_index_set = 0;
5038 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
5039 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
5040 sw_if_index_set = 1;
5041 else if (unformat (i, "sw_if_index %d", &sw_if_index))
5042 sw_if_index_set = 1;
5043 else if (unformat (i, "enable"))
5045 else if (unformat (i, "disable"))
5048 clib_warning ("parse error '%U'", format_unformat_error, i);
5053 if (sw_if_index_set == 0) {
5054 errmsg ("missing interface name or sw_if_index\n");
5058 M(PROXY_ARP_INTFC_ENABLE_DISABLE, proxy_arp_intfc_enable_disable);
5060 mp->sw_if_index = ntohl(sw_if_index);
5061 mp->enable_disable = enable;
5068 static int api_mpls_add_del_decap (vat_main_t * vam)
5070 unformat_input_t * i = vam->input;
5071 vl_api_mpls_add_del_decap_t *mp;
5080 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
5081 if (unformat (i, "rx_vrf_id %d", &rx_vrf_id))
5083 else if (unformat (i, "tx_vrf_id %d", &tx_vrf_id))
5085 else if (unformat (i, "label %d", &label))
5087 else if (unformat (i, "next-index %d", &next_index))
5089 else if (unformat (i, "del"))
5091 else if (unformat (i, "s-bit-clear"))
5094 clib_warning ("parse error '%U'", format_unformat_error, i);
5099 M(MPLS_ADD_DEL_DECAP, mpls_add_del_decap);
5101 mp->rx_vrf_id = ntohl(rx_vrf_id);
5102 mp->tx_vrf_id = ntohl(tx_vrf_id);
5103 mp->label = ntohl(label);
5104 mp->next_index = ntohl(next_index);
5106 mp->is_add = is_add;
5113 static int api_mpls_add_del_encap (vat_main_t * vam)
5115 unformat_input_t * i = vam->input;
5116 vl_api_mpls_add_del_encap_t *mp;
5121 ip4_address_t dst_address;
5124 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
5125 if (unformat (i, "vrf %d", &vrf_id))
5127 else if (unformat (i, "label %d", &label))
5128 vec_add1 (labels, ntohl(label));
5129 else if (unformat (i, "dst %U", unformat_ip4_address, &dst_address))
5131 else if (unformat (i, "del"))
5134 clib_warning ("parse error '%U'", format_unformat_error, i);
5139 if (vec_len (labels) == 0) {
5140 errmsg ("missing encap label stack\n");
5144 M2(MPLS_ADD_DEL_ENCAP, mpls_add_del_encap,
5145 sizeof (u32) * vec_len (labels));
5147 mp->vrf_id = ntohl(vrf_id);
5148 clib_memcpy(mp->dst_address, &dst_address, sizeof (dst_address));
5149 mp->is_add = is_add;
5150 mp->nlabels = vec_len (labels);
5151 clib_memcpy(mp->labels, labels, sizeof(u32)*mp->nlabels);
5160 static int api_mpls_gre_add_del_tunnel (vat_main_t * vam)
5162 unformat_input_t * i = vam->input;
5163 vl_api_mpls_gre_add_del_tunnel_t *mp;
5165 u32 inner_vrf_id = 0;
5166 u32 outer_vrf_id = 0;
5167 ip4_address_t src_address;
5168 ip4_address_t dst_address;
5169 ip4_address_t intfc_address;
5171 u8 intfc_address_length = 0;
5175 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
5176 if (unformat (i, "inner_vrf_id %d", &inner_vrf_id))
5178 else if (unformat (i, "outer_vrf_id %d", &outer_vrf_id))
5180 else if (unformat (i, "src %U", unformat_ip4_address, &src_address))
5182 else if (unformat (i, "dst %U", unformat_ip4_address, &dst_address))
5184 else if (unformat (i, "adj %U/%d", unformat_ip4_address,
5185 &intfc_address, &tmp))
5186 intfc_address_length = tmp;
5187 else if (unformat (i, "l2-only"))
5189 else if (unformat (i, "del"))
5192 clib_warning ("parse error '%U'", format_unformat_error, i);
5197 M(MPLS_GRE_ADD_DEL_TUNNEL, mpls_gre_add_del_tunnel);
5199 mp->inner_vrf_id = ntohl(inner_vrf_id);
5200 mp->outer_vrf_id = ntohl(outer_vrf_id);
5201 clib_memcpy(mp->src_address, &src_address, sizeof (src_address));
5202 clib_memcpy(mp->dst_address, &dst_address, sizeof (dst_address));
5203 clib_memcpy(mp->intfc_address, &intfc_address, sizeof (intfc_address));
5204 mp->intfc_address_length = intfc_address_length;
5205 mp->l2_only = l2_only;
5206 mp->is_add = is_add;
5213 static int api_mpls_ethernet_add_del_tunnel (vat_main_t * vam)
5215 unformat_input_t * i = vam->input;
5216 vl_api_mpls_ethernet_add_del_tunnel_t *mp;
5218 u32 inner_vrf_id = 0;
5219 ip4_address_t intfc_address;
5220 u8 dst_mac_address[6];
5223 u8 intfc_address_length = 0;
5227 int tx_sw_if_index_set = 0;
5229 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
5230 if (unformat (i, "vrf %d", &inner_vrf_id))
5232 else if (unformat (i, "adj %U/%d", unformat_ip4_address,
5233 &intfc_address, &tmp))
5234 intfc_address_length = tmp;
5235 else if (unformat (i, "%U",
5236 unformat_sw_if_index, vam, &tx_sw_if_index))
5237 tx_sw_if_index_set = 1;
5238 else if (unformat (i, "tx_sw_if_index %d", &tx_sw_if_index))
5239 tx_sw_if_index_set = 1;
5240 else if (unformat (i, "dst %U", unformat_ethernet_address,
5243 else if (unformat (i, "l2-only"))
5245 else if (unformat (i, "del"))
5248 clib_warning ("parse error '%U'", format_unformat_error, i);
5254 errmsg ("dst (mac address) not set\n");
5257 if (!tx_sw_if_index_set) {
5258 errmsg ("tx-intfc not set\n");
5262 M(MPLS_ETHERNET_ADD_DEL_TUNNEL, mpls_ethernet_add_del_tunnel);
5264 mp->vrf_id = ntohl(inner_vrf_id);
5265 clib_memcpy (mp->adj_address, &intfc_address, sizeof (intfc_address));
5266 mp->adj_address_length = intfc_address_length;
5267 clib_memcpy (mp->dst_mac_address, dst_mac_address, sizeof (dst_mac_address));
5268 mp->tx_sw_if_index = ntohl(tx_sw_if_index);
5269 mp->l2_only = l2_only;
5270 mp->is_add = is_add;
5277 static int api_mpls_ethernet_add_del_tunnel_2 (vat_main_t * vam)
5279 unformat_input_t * i = vam->input;
5280 vl_api_mpls_ethernet_add_del_tunnel_2_t *mp;
5282 u32 inner_vrf_id = 0;
5283 u32 outer_vrf_id = 0;
5284 ip4_address_t adj_address;
5285 int adj_address_set = 0;
5286 ip4_address_t next_hop_address;
5287 int next_hop_address_set = 0;
5289 u8 adj_address_length = 0;
5292 u32 resolve_attempts = 5;
5293 u8 resolve_if_needed = 1;
5295 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
5296 if (unformat (i, "inner_vrf_id %d", &inner_vrf_id))
5298 else if (unformat (i, "outer_vrf_id %d", &outer_vrf_id))
5300 else if (unformat (i, "adj %U/%d", unformat_ip4_address,
5301 &adj_address, &tmp)) {
5302 adj_address_length = tmp;
5303 adj_address_set = 1;
5305 else if (unformat (i, "next-hop %U", unformat_ip4_address,
5307 next_hop_address_set = 1;
5308 else if (unformat (i, "resolve-attempts %d", &resolve_attempts))
5310 else if (unformat (i, "resolve-if-needed %d", &tmp))
5311 resolve_if_needed = tmp;
5312 else if (unformat (i, "l2-only"))
5314 else if (unformat (i, "del"))
5317 clib_warning ("parse error '%U'", format_unformat_error, i);
5322 if (!adj_address_set) {
5323 errmsg ("adjacency address/mask not set\n");
5326 if (!next_hop_address_set) {
5327 errmsg ("ip4 next hop address (in outer fib) not set\n");
5331 M(MPLS_ETHERNET_ADD_DEL_TUNNEL_2, mpls_ethernet_add_del_tunnel_2);
5333 mp->inner_vrf_id = ntohl(inner_vrf_id);
5334 mp->outer_vrf_id = ntohl(outer_vrf_id);
5335 mp->resolve_attempts = ntohl(resolve_attempts);
5336 mp->resolve_if_needed = resolve_if_needed;
5337 mp->is_add = is_add;
5338 mp->l2_only = l2_only;
5339 clib_memcpy (mp->adj_address, &adj_address, sizeof (adj_address));
5340 mp->adj_address_length = adj_address_length;
5341 clib_memcpy (mp->next_hop_ip4_address_in_outer_vrf, &next_hop_address,
5342 sizeof (next_hop_address));
5349 static int api_sw_interface_set_unnumbered (vat_main_t * vam)
5351 unformat_input_t * i = vam->input;
5352 vl_api_sw_interface_set_unnumbered_t *mp;
5357 u8 sw_if_index_set = 0;
5359 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
5360 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
5361 sw_if_index_set = 1;
5362 else if (unformat (i, "sw_if_index %d", &sw_if_index))
5363 sw_if_index_set = 1;
5364 else if (unformat (i, "unnum_if_index %d", &unnum_sw_index))
5366 else if (unformat (i, "del"))
5369 clib_warning ("parse error '%U'", format_unformat_error, i);
5374 if (sw_if_index_set == 0) {
5375 errmsg ("missing interface name or sw_if_index\n");
5379 M(SW_INTERFACE_SET_UNNUMBERED, sw_interface_set_unnumbered);
5381 mp->sw_if_index = ntohl(sw_if_index);
5382 mp->unnumbered_sw_if_index = ntohl(unnum_sw_index);
5383 mp->is_add = is_add;
5390 static int api_ip_neighbor_add_del (vat_main_t * vam)
5392 unformat_input_t * i = vam->input;
5393 vl_api_ip_neighbor_add_del_t *mp;
5396 u8 sw_if_index_set = 0;
5402 u8 v4_address_set = 0;
5403 u8 v6_address_set = 0;
5404 ip4_address_t v4address;
5405 ip6_address_t v6address;
5407 memset (mac_address, 0, sizeof (mac_address));
5409 /* Parse args required to build the message */
5410 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
5411 if (unformat (i, "mac %U", unformat_ethernet_address, mac_address)) {
5414 else if (unformat (i, "del"))
5416 else if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
5417 sw_if_index_set = 1;
5418 else if (unformat (i, "sw_if_index %d", &sw_if_index))
5419 sw_if_index_set = 1;
5420 else if (unformat (i, "is_static"))
5422 else if (unformat (i, "vrf %d", &vrf_id))
5424 else if (unformat (i, "dst %U",
5425 unformat_ip4_address, &v4address))
5427 else if (unformat (i, "dst %U",
5428 unformat_ip6_address, &v6address))
5431 clib_warning ("parse error '%U'", format_unformat_error, i);
5436 if (sw_if_index_set == 0) {
5437 errmsg ("missing interface name or sw_if_index\n");
5440 if (v4_address_set && v6_address_set) {
5441 errmsg ("both v4 and v6 addresses set\n");
5444 if (!v4_address_set && !v6_address_set) {
5445 errmsg ("no address set\n");
5449 /* Construct the API message */
5450 M(IP_NEIGHBOR_ADD_DEL, ip_neighbor_add_del);
5452 mp->sw_if_index = ntohl (sw_if_index);
5453 mp->is_add = is_add;
5454 mp->vrf_id = ntohl (vrf_id);
5455 mp->is_static = is_static;
5457 clib_memcpy (mp->mac_address, mac_address, 6);
5458 if (v6_address_set) {
5460 clib_memcpy (mp->dst_address, &v6address, sizeof (v6address));
5462 /* mp->is_ipv6 = 0; via memset in M macro above */
5463 clib_memcpy (mp->dst_address, &v4address, sizeof (v4address));
5469 /* Wait for a reply, return good/bad news */
5476 static int api_reset_vrf (vat_main_t * vam)
5478 unformat_input_t * i = vam->input;
5479 vl_api_reset_vrf_t *mp;
5485 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
5486 if (unformat (i, "vrf %d", &vrf_id))
5488 else if (unformat (i, "ipv6"))
5491 clib_warning ("parse error '%U'", format_unformat_error, i);
5496 if (vrf_id_set == 0) {
5497 errmsg ("missing vrf id\n");
5501 M(RESET_VRF, reset_vrf);
5503 mp->vrf_id = ntohl(vrf_id);
5504 mp->is_ipv6 = is_ipv6;
5511 static int api_create_vlan_subif (vat_main_t * vam)
5513 unformat_input_t * i = vam->input;
5514 vl_api_create_vlan_subif_t *mp;
5517 u8 sw_if_index_set = 0;
5521 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
5522 if (unformat (i, "sw_if_index %d", &sw_if_index))
5523 sw_if_index_set = 1;
5524 else if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
5525 sw_if_index_set = 1;
5526 else if (unformat (i, "vlan %d", &vlan_id))
5529 clib_warning ("parse error '%U'", format_unformat_error, i);
5534 if (sw_if_index_set == 0) {
5535 errmsg ("missing interface name or sw_if_index\n");
5539 if (vlan_id_set == 0) {
5540 errmsg ("missing vlan_id\n");
5543 M(CREATE_VLAN_SUBIF, create_vlan_subif);
5545 mp->sw_if_index = ntohl(sw_if_index);
5546 mp->vlan_id = ntohl(vlan_id);
5553 #define foreach_create_subif_bit \
5560 _(outer_vlan_id_any) \
5561 _(inner_vlan_id_any)
5563 static int api_create_subif (vat_main_t * vam)
5565 unformat_input_t * i = vam->input;
5566 vl_api_create_subif_t *mp;
5569 u8 sw_if_index_set = 0;
5576 u32 exact_match = 0;
5577 u32 default_sub = 0;
5578 u32 outer_vlan_id_any = 0;
5579 u32 inner_vlan_id_any = 0;
5581 u16 outer_vlan_id = 0;
5582 u16 inner_vlan_id = 0;
5584 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
5585 if (unformat (i, "sw_if_index %d", &sw_if_index))
5586 sw_if_index_set = 1;
5587 else if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
5588 sw_if_index_set = 1;
5589 else if (unformat (i, "sub_id %d", &sub_id))
5591 else if (unformat (i, "outer_vlan_id %d", &tmp))
5592 outer_vlan_id = tmp;
5593 else if (unformat (i, "inner_vlan_id %d", &tmp))
5594 inner_vlan_id = tmp;
5596 #define _(a) else if (unformat (i, #a)) a = 1 ;
5597 foreach_create_subif_bit
5601 clib_warning ("parse error '%U'", format_unformat_error, i);
5606 if (sw_if_index_set == 0) {
5607 errmsg ("missing interface name or sw_if_index\n");
5611 if (sub_id_set == 0) {
5612 errmsg ("missing sub_id\n");
5615 M(CREATE_SUBIF, create_subif);
5617 mp->sw_if_index = ntohl(sw_if_index);
5618 mp->sub_id = ntohl(sub_id);
5620 #define _(a) mp->a = a;
5621 foreach_create_subif_bit;
5624 mp->outer_vlan_id = ntohs (outer_vlan_id);
5625 mp->inner_vlan_id = ntohs (inner_vlan_id);
5632 static int api_oam_add_del (vat_main_t * vam)
5634 unformat_input_t * i = vam->input;
5635 vl_api_oam_add_del_t *mp;
5639 ip4_address_t src, dst;
5643 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
5644 if (unformat (i, "vrf %d", &vrf_id))
5646 else if (unformat (i, "src %U", unformat_ip4_address, &src))
5648 else if (unformat (i, "dst %U", unformat_ip4_address, &dst))
5650 else if (unformat (i, "del"))
5653 clib_warning ("parse error '%U'", format_unformat_error, i);
5659 errmsg ("missing src addr\n");
5664 errmsg ("missing dst addr\n");
5668 M(OAM_ADD_DEL, oam_add_del);
5670 mp->vrf_id = ntohl(vrf_id);
5671 mp->is_add = is_add;
5672 clib_memcpy(mp->src_address, &src, sizeof (mp->src_address));
5673 clib_memcpy(mp->dst_address, &dst, sizeof (mp->dst_address));
5680 static int api_reset_fib (vat_main_t * vam)
5682 unformat_input_t * i = vam->input;
5683 vl_api_reset_fib_t *mp;
5689 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
5690 if (unformat (i, "vrf %d", &vrf_id))
5692 else if (unformat (i, "ipv6"))
5695 clib_warning ("parse error '%U'", format_unformat_error, i);
5700 if (vrf_id_set == 0) {
5701 errmsg ("missing vrf id\n");
5705 M(RESET_FIB, reset_fib);
5707 mp->vrf_id = ntohl(vrf_id);
5708 mp->is_ipv6 = is_ipv6;
5715 static int api_dhcp_proxy_config (vat_main_t * vam)
5717 unformat_input_t * i = vam->input;
5718 vl_api_dhcp_proxy_config_t *mp;
5723 u8 v4_address_set = 0;
5724 u8 v6_address_set = 0;
5725 ip4_address_t v4address;
5726 ip6_address_t v6address;
5727 u8 v4_src_address_set = 0;
5728 u8 v6_src_address_set = 0;
5729 ip4_address_t v4srcaddress;
5730 ip6_address_t v6srcaddress;
5732 /* Parse args required to build the message */
5733 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
5734 if (unformat (i, "del"))
5736 else if (unformat (i, "vrf %d", &vrf_id))
5738 else if (unformat (i, "insert-cid %d", &insert_cid))
5740 else if (unformat (i, "svr %U",
5741 unformat_ip4_address, &v4address))
5743 else if (unformat (i, "svr %U",
5744 unformat_ip6_address, &v6address))
5746 else if (unformat (i, "src %U",
5747 unformat_ip4_address, &v4srcaddress))
5748 v4_src_address_set = 1;
5749 else if (unformat (i, "src %U",
5750 unformat_ip6_address, &v6srcaddress))
5751 v6_src_address_set = 1;
5756 if (v4_address_set && v6_address_set) {
5757 errmsg ("both v4 and v6 server addresses set\n");
5760 if (!v4_address_set && !v6_address_set) {
5761 errmsg ("no server addresses set\n");
5765 if (v4_src_address_set && v6_src_address_set) {
5766 errmsg ("both v4 and v6 src addresses set\n");
5769 if (!v4_src_address_set && !v6_src_address_set) {
5770 errmsg ("no src addresses set\n");
5774 if (!(v4_src_address_set && v4_address_set) &&
5775 !(v6_src_address_set && v6_address_set)) {
5776 errmsg ("no matching server and src addresses set\n");
5780 /* Construct the API message */
5781 M(DHCP_PROXY_CONFIG, dhcp_proxy_config);
5783 mp->insert_circuit_id = insert_cid;
5784 mp->is_add = is_add;
5785 mp->vrf_id = ntohl (vrf_id);
5786 if (v6_address_set) {
5788 clib_memcpy (mp->dhcp_server, &v6address, sizeof (v6address));
5789 clib_memcpy (mp->dhcp_src_address, &v6srcaddress, sizeof (v6address));
5791 clib_memcpy (mp->dhcp_server, &v4address, sizeof (v4address));
5792 clib_memcpy (mp->dhcp_src_address, &v4srcaddress, sizeof (v4address));
5798 /* Wait for a reply, return good/bad news */
5804 static int api_dhcp_proxy_config_2 (vat_main_t * vam)
5806 unformat_input_t * i = vam->input;
5807 vl_api_dhcp_proxy_config_2_t *mp;
5810 u32 server_vrf_id = 0;
5813 u8 v4_address_set = 0;
5814 u8 v6_address_set = 0;
5815 ip4_address_t v4address;
5816 ip6_address_t v6address;
5817 u8 v4_src_address_set = 0;
5818 u8 v6_src_address_set = 0;
5819 ip4_address_t v4srcaddress;
5820 ip6_address_t v6srcaddress;
5822 /* Parse args required to build the message */
5823 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
5824 if (unformat (i, "del"))
5826 else if (unformat (i, "rx_vrf_id %d", &rx_vrf_id))
5828 else if (unformat (i, "server_vrf_id %d", &server_vrf_id))
5830 else if (unformat (i, "insert-cid %d", &insert_cid))
5832 else if (unformat (i, "svr %U",
5833 unformat_ip4_address, &v4address))
5835 else if (unformat (i, "svr %U",
5836 unformat_ip6_address, &v6address))
5838 else if (unformat (i, "src %U",
5839 unformat_ip4_address, &v4srcaddress))
5840 v4_src_address_set = 1;
5841 else if (unformat (i, "src %U",
5842 unformat_ip6_address, &v6srcaddress))
5843 v6_src_address_set = 1;
5848 if (v4_address_set && v6_address_set) {
5849 errmsg ("both v4 and v6 server addresses set\n");
5852 if (!v4_address_set && !v6_address_set) {
5853 errmsg ("no server addresses set\n");
5857 if (v4_src_address_set && v6_src_address_set) {
5858 errmsg ("both v4 and v6 src addresses set\n");
5861 if (!v4_src_address_set && !v6_src_address_set) {
5862 errmsg ("no src addresses set\n");
5866 if (!(v4_src_address_set && v4_address_set) &&
5867 !(v6_src_address_set && v6_address_set)) {
5868 errmsg ("no matching server and src addresses set\n");
5872 /* Construct the API message */
5873 M(DHCP_PROXY_CONFIG_2, dhcp_proxy_config_2);
5875 mp->insert_circuit_id = insert_cid;
5876 mp->is_add = is_add;
5877 mp->rx_vrf_id = ntohl (rx_vrf_id);
5878 mp->server_vrf_id = ntohl (server_vrf_id);
5879 if (v6_address_set) {
5881 clib_memcpy (mp->dhcp_server, &v6address, sizeof (v6address));
5882 clib_memcpy (mp->dhcp_src_address, &v6srcaddress, sizeof (v6address));
5884 clib_memcpy (mp->dhcp_server, &v4address, sizeof (v4address));
5885 clib_memcpy (mp->dhcp_src_address, &v4srcaddress, sizeof (v4address));
5891 /* Wait for a reply, return good/bad news */
5897 static int api_dhcp_proxy_set_vss (vat_main_t * vam)
5899 unformat_input_t * i = vam->input;
5900 vl_api_dhcp_proxy_set_vss_t *mp;
5911 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
5912 if (unformat (i, "tbl_id %d", &tbl_id))
5914 if (unformat (i, "fib_id %d", &fib_id))
5916 if (unformat (i, "oui %d", &oui))
5918 else if (unformat (i, "ipv6"))
5920 else if (unformat (i, "del"))
5923 clib_warning ("parse error '%U'", format_unformat_error, i);
5928 if (tbl_id_set == 0) {
5929 errmsg ("missing tbl id\n");
5933 if (fib_id_set == 0) {
5934 errmsg ("missing fib id\n");
5938 errmsg ("missing oui\n");
5942 M(DHCP_PROXY_SET_VSS, dhcp_proxy_set_vss);
5943 mp->tbl_id = ntohl(tbl_id);
5944 mp->fib_id = ntohl(fib_id);
5945 mp->oui = ntohl(oui);
5946 mp->is_ipv6 = is_ipv6;
5947 mp->is_add = is_add;
5954 static int api_dhcp_client_config (vat_main_t * vam)
5956 unformat_input_t * i = vam->input;
5957 vl_api_dhcp_client_config_t *mp;
5960 u8 sw_if_index_set = 0;
5963 u8 disable_event = 0;
5965 /* Parse args required to build the message */
5966 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
5967 if (unformat (i, "del"))
5969 else if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
5970 sw_if_index_set = 1;
5971 else if (unformat (i, "sw_if_index %d", &sw_if_index))
5972 sw_if_index_set = 1;
5973 else if (unformat (i, "hostname %s", &hostname))
5975 else if (unformat (i, "disable_event"))
5981 if (sw_if_index_set == 0) {
5982 errmsg ("missing interface name or sw_if_index\n");
5986 if (vec_len (hostname) > 63) {
5987 errmsg ("hostname too long\n");
5989 vec_add1 (hostname, 0);
5991 /* Construct the API message */
5992 M(DHCP_CLIENT_CONFIG, dhcp_client_config);
5994 mp->sw_if_index = ntohl (sw_if_index);
5995 clib_memcpy (mp->hostname, hostname, vec_len (hostname));
5996 vec_free (hostname);
5997 mp->is_add = is_add;
5998 mp->want_dhcp_event = disable_event ? 0 : 1;
6004 /* Wait for a reply, return good/bad news */
6010 static int api_set_ip_flow_hash (vat_main_t * vam)
6012 unformat_input_t * i = vam->input;
6013 vl_api_set_ip_flow_hash_t *mp;
6025 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
6026 if (unformat (i, "vrf %d", &vrf_id))
6028 else if (unformat (i, "ipv6"))
6030 else if (unformat (i, "src"))
6032 else if (unformat (i, "dst"))
6034 else if (unformat (i, "sport"))
6036 else if (unformat (i, "dport"))
6038 else if (unformat (i, "proto"))
6040 else if (unformat (i, "reverse"))
6044 clib_warning ("parse error '%U'", format_unformat_error, i);
6049 if (vrf_id_set == 0) {
6050 errmsg ("missing vrf id\n");
6054 M(SET_IP_FLOW_HASH, set_ip_flow_hash);
6060 mp->reverse = reverse;
6061 mp->vrf_id = ntohl(vrf_id);
6062 mp->is_ipv6 = is_ipv6;
6069 static int api_sw_interface_ip6_enable_disable (vat_main_t * vam)
6071 unformat_input_t * i = vam->input;
6072 vl_api_sw_interface_ip6_enable_disable_t *mp;
6075 u8 sw_if_index_set = 0;
6078 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
6079 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
6080 sw_if_index_set = 1;
6081 else if (unformat (i, "sw_if_index %d", &sw_if_index))
6082 sw_if_index_set = 1;
6083 else if (unformat (i, "enable"))
6085 else if (unformat (i, "disable"))
6088 clib_warning ("parse error '%U'", format_unformat_error, i);
6093 if (sw_if_index_set == 0) {
6094 errmsg ("missing interface name or sw_if_index\n");
6098 M(SW_INTERFACE_IP6_ENABLE_DISABLE, sw_interface_ip6_enable_disable);
6100 mp->sw_if_index = ntohl(sw_if_index);
6101 mp->enable = enable;
6108 static int api_sw_interface_ip6_set_link_local_address (vat_main_t * vam)
6110 unformat_input_t * i = vam->input;
6111 vl_api_sw_interface_ip6_set_link_local_address_t *mp;
6114 u8 sw_if_index_set = 0;
6115 u32 address_length = 0;
6116 u8 v6_address_set = 0;
6117 ip6_address_t v6address;
6119 /* Parse args required to build the message */
6120 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
6121 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
6122 sw_if_index_set = 1;
6123 else if (unformat (i, "sw_if_index %d", &sw_if_index))
6124 sw_if_index_set = 1;
6125 else if (unformat (i, "%U/%d",
6126 unformat_ip6_address, &v6address,
6133 if (sw_if_index_set == 0) {
6134 errmsg ("missing interface name or sw_if_index\n");
6137 if (!v6_address_set) {
6138 errmsg ("no address set\n");
6142 /* Construct the API message */
6143 M(SW_INTERFACE_IP6_SET_LINK_LOCAL_ADDRESS, \
6144 sw_interface_ip6_set_link_local_address);
6146 mp->sw_if_index = ntohl (sw_if_index);
6147 clib_memcpy (mp->address, &v6address, sizeof (v6address));
6148 mp->address_length = address_length;
6153 /* Wait for a reply, return good/bad news */
6161 static int api_sw_interface_ip6nd_ra_prefix (vat_main_t * vam)
6163 unformat_input_t * i = vam->input;
6164 vl_api_sw_interface_ip6nd_ra_prefix_t *mp;
6167 u8 sw_if_index_set = 0;
6168 u32 address_length = 0;
6169 u8 v6_address_set = 0;
6170 ip6_address_t v6address;
6172 u8 no_advertise = 0;
6174 u8 no_autoconfig = 0;
6177 u32 val_lifetime = 0;
6178 u32 pref_lifetime = 0;
6180 /* Parse args required to build the message */
6181 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
6182 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
6183 sw_if_index_set = 1;
6184 else if (unformat (i, "sw_if_index %d", &sw_if_index))
6185 sw_if_index_set = 1;
6186 else if (unformat (i, "%U/%d",
6187 unformat_ip6_address, &v6address,
6190 else if (unformat (i, "val_life %d", &val_lifetime))
6192 else if (unformat (i, "pref_life %d", &pref_lifetime))
6194 else if (unformat (i, "def"))
6196 else if (unformat (i, "noadv"))
6198 else if (unformat (i, "offl"))
6200 else if (unformat (i, "noauto"))
6202 else if (unformat (i, "nolink"))
6204 else if (unformat (i, "isno"))
6207 clib_warning ("parse error '%U'", format_unformat_error, i);
6212 if (sw_if_index_set == 0) {
6213 errmsg ("missing interface name or sw_if_index\n");
6216 if (!v6_address_set) {
6217 errmsg ("no address set\n");
6221 /* Construct the API message */
6222 M(SW_INTERFACE_IP6ND_RA_PREFIX, sw_interface_ip6nd_ra_prefix);
6224 mp->sw_if_index = ntohl (sw_if_index);
6225 clib_memcpy (mp->address, &v6address, sizeof (v6address));
6226 mp->address_length = address_length;
6227 mp->use_default = use_default;
6228 mp->no_advertise = no_advertise;
6229 mp->off_link = off_link;
6230 mp->no_autoconfig = no_autoconfig;
6231 mp->no_onlink = no_onlink;
6233 mp->val_lifetime = ntohl(val_lifetime);
6234 mp->pref_lifetime = ntohl(pref_lifetime);
6239 /* Wait for a reply, return good/bad news */
6246 static int api_sw_interface_ip6nd_ra_config (vat_main_t * vam)
6248 unformat_input_t * i = vam->input;
6249 vl_api_sw_interface_ip6nd_ra_config_t *mp;
6252 u8 sw_if_index_set = 0;
6257 u8 send_unicast = 0;
6260 u8 default_router = 0;
6261 u32 max_interval = 0;
6262 u32 min_interval = 0;
6264 u32 initial_count = 0;
6265 u32 initial_interval = 0;
6268 /* Parse args required to build the message */
6269 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
6270 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
6271 sw_if_index_set = 1;
6272 else if (unformat (i, "sw_if_index %d", &sw_if_index))
6273 sw_if_index_set = 1;
6274 else if (unformat (i, "maxint %d", &max_interval))
6276 else if (unformat (i, "minint %d", &min_interval))
6278 else if (unformat (i, "life %d", &lifetime))
6280 else if (unformat (i, "count %d", &initial_count))
6282 else if (unformat (i, "interval %d", &initial_interval))
6284 else if (unformat (i, "suppress") || unformat (i, "surpress"))
6286 else if (unformat (i, "managed"))
6288 else if (unformat (i, "other"))
6290 else if (unformat (i, "ll"))
6292 else if (unformat (i, "send"))
6294 else if (unformat (i, "cease"))
6296 else if (unformat (i, "isno"))
6298 else if (unformat (i, "def"))
6301 clib_warning ("parse error '%U'", format_unformat_error, i);
6306 if (sw_if_index_set == 0) {
6307 errmsg ("missing interface name or sw_if_index\n");
6311 /* Construct the API message */
6312 M(SW_INTERFACE_IP6ND_RA_CONFIG, sw_interface_ip6nd_ra_config);
6314 mp->sw_if_index = ntohl (sw_if_index);
6315 mp->max_interval = ntohl(max_interval);
6316 mp->min_interval = ntohl(min_interval);
6317 mp->lifetime = ntohl(lifetime);
6318 mp->initial_count = ntohl(initial_count);
6319 mp->initial_interval = ntohl(initial_interval);
6320 mp->suppress = suppress;
6321 mp->managed = managed;
6323 mp->ll_option = ll_option;
6324 mp->send_unicast = send_unicast;
6327 mp->default_router = default_router;
6332 /* Wait for a reply, return good/bad news */
6339 static int api_set_arp_neighbor_limit (vat_main_t * vam)
6341 unformat_input_t * i = vam->input;
6342 vl_api_set_arp_neighbor_limit_t *mp;
6348 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
6349 if (unformat (i, "arp_nbr_limit %d", &arp_nbr_limit))
6351 else if (unformat (i, "ipv6"))
6354 clib_warning ("parse error '%U'", format_unformat_error, i);
6359 if (limit_set == 0) {
6360 errmsg ("missing limit value\n");
6364 M(SET_ARP_NEIGHBOR_LIMIT, set_arp_neighbor_limit);
6366 mp->arp_neighbor_limit = ntohl(arp_nbr_limit);
6367 mp->is_ipv6 = is_ipv6;
6374 static int api_l2_patch_add_del (vat_main_t * vam)
6376 unformat_input_t * i = vam->input;
6377 vl_api_l2_patch_add_del_t *mp;
6380 u8 rx_sw_if_index_set = 0;
6382 u8 tx_sw_if_index_set = 0;
6385 /* Parse args required to build the message */
6386 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
6387 if (unformat (i, "rx_sw_if_index %d", &rx_sw_if_index))
6388 rx_sw_if_index_set = 1;
6389 else if (unformat (i, "tx_sw_if_index %d", &tx_sw_if_index))
6390 tx_sw_if_index_set = 1;
6391 else if (unformat (i, "rx")) {
6392 if (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
6393 if (unformat (i, "%U", unformat_sw_if_index, vam,
6395 rx_sw_if_index_set = 1;
6398 } else if (unformat (i, "tx")) {
6399 if (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
6400 if (unformat (i, "%U", unformat_sw_if_index, vam,
6402 tx_sw_if_index_set = 1;
6405 } else if (unformat (i, "del"))
6411 if (rx_sw_if_index_set == 0) {
6412 errmsg ("missing rx interface name or rx_sw_if_index\n");
6416 if (tx_sw_if_index_set == 0) {
6417 errmsg ("missing tx interface name or tx_sw_if_index\n");
6421 M(L2_PATCH_ADD_DEL, l2_patch_add_del);
6423 mp->rx_sw_if_index = ntohl(rx_sw_if_index);
6424 mp->tx_sw_if_index = ntohl(tx_sw_if_index);
6425 mp->is_add = is_add;
6431 static int api_trace_profile_add (vat_main_t *vam)
6433 unformat_input_t * input = vam->input;
6434 vl_api_trace_profile_add_t *mp;
6437 u32 trace_option_elts = 0;
6438 u32 trace_type = 0, node_id = 0, app_data = 0, trace_tsp = 2;
6439 int has_pow_option = 0;
6440 int has_ppc_option = 0;
6442 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
6444 if (unformat (input, "id %d trace-type 0x%x trace-elts %d "
6445 "trace-tsp %d node-id 0x%x app-data 0x%x",
6446 &id, &trace_type, &trace_option_elts, &trace_tsp,
6447 &node_id, &app_data))
6449 else if (unformat (input, "pow"))
6451 else if (unformat (input, "ppc encap"))
6452 has_ppc_option = PPC_ENCAP;
6453 else if (unformat (input, "ppc decap"))
6454 has_ppc_option = PPC_DECAP;
6455 else if (unformat (input, "ppc none"))
6456 has_ppc_option = PPC_NONE;
6460 M(TRACE_PROFILE_ADD, trace_profile_add);
6462 mp->trace_type = trace_type;
6463 mp->trace_num_elt = trace_option_elts;
6464 mp->trace_ppc = has_ppc_option;
6465 mp->trace_app_data = htonl(app_data);
6466 mp->pow_enable = has_pow_option;
6467 mp->trace_tsp = trace_tsp;
6468 mp->node_id = htonl(node_id);
6475 static int api_trace_profile_apply (vat_main_t *vam)
6477 unformat_input_t * input = vam->input;
6478 vl_api_trace_profile_apply_t *mp;
6481 u32 mask_width = ~0;
6488 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
6490 if (unformat (input, "%U/%d",
6491 unformat_ip6_address, &addr, &mask_width))
6493 else if (unformat (input, "id %d", &id))
6495 else if (unformat (input, "vrf-id %d", &vrf_id))
6497 else if (unformat (input, "add"))
6499 else if (unformat (input, "pop"))
6501 else if (unformat (input, "none"))
6507 if ((is_add + is_pop + is_none) != 1) {
6508 errmsg("One of (add, pop, none) required");
6511 if (mask_width == ~0) {
6512 errmsg("<address>/<mask-width> required");
6515 M(TRACE_PROFILE_APPLY, trace_profile_apply);
6516 clib_memcpy(mp->dest_ipv6, &addr, sizeof(mp->dest_ipv6));
6518 mp->prefix_length = htonl(mask_width);
6519 mp->vrf_id = htonl(vrf_id);
6521 mp->trace_op = IOAM_HBYH_ADD;
6523 mp->trace_op = IOAM_HBYH_POP;
6525 mp->trace_op = IOAM_HBYH_MOD;
6537 static int api_trace_profile_del (vat_main_t *vam)
6539 vl_api_trace_profile_del_t *mp;
6542 M(TRACE_PROFILE_DEL, trace_profile_del);
6547 static int api_sr_tunnel_add_del (vat_main_t * vam)
6549 unformat_input_t * i = vam->input;
6550 vl_api_sr_tunnel_add_del_t *mp;
6554 ip6_address_t src_address;
6555 int src_address_set = 0;
6556 ip6_address_t dst_address;
6558 int dst_address_set = 0;
6560 u32 rx_table_id = 0;
6561 u32 tx_table_id = 0;
6562 ip6_address_t * segments = 0;
6563 ip6_address_t * this_seg;
6564 ip6_address_t * tags = 0;
6565 ip6_address_t * this_tag;
6566 ip6_address_t next_address, tag;
6568 u8 * policy_name = 0;
6570 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
6572 if (unformat (i, "del"))
6574 else if (unformat (i, "name %s", &name))
6576 else if (unformat (i, "policy %s", &policy_name))
6578 else if (unformat (i, "rx_fib_id %d", &rx_table_id))
6580 else if (unformat (i, "tx_fib_id %d", &tx_table_id))
6582 else if (unformat (i, "src %U", unformat_ip6_address, &src_address))
6583 src_address_set = 1;
6584 else if (unformat (i, "dst %U/%d",
6585 unformat_ip6_address, &dst_address,
6587 dst_address_set = 1;
6588 else if (unformat (i, "next %U", unformat_ip6_address,
6591 vec_add2 (segments, this_seg, 1);
6592 clib_memcpy (this_seg->as_u8, next_address.as_u8, sizeof (*this_seg));
6594 else if (unformat (i, "tag %U", unformat_ip6_address,
6597 vec_add2 (tags, this_tag, 1);
6598 clib_memcpy (this_tag->as_u8, tag.as_u8, sizeof (*this_tag));
6600 else if (unformat (i, "clean"))
6601 flags |= IP6_SR_HEADER_FLAG_CLEANUP;
6602 else if (unformat (i, "protected"))
6603 flags |= IP6_SR_HEADER_FLAG_PROTECTED;
6604 else if (unformat (i, "InPE %d", &pl_index))
6606 if (pl_index <= 0 || pl_index > 4)
6608 pl_index_range_error:
6609 errmsg ("pl index %d out of range\n", pl_index);
6612 flags |= IP6_SR_HEADER_FLAG_PL_ELT_INGRESS_PE << (3*(pl_index - 1));
6614 else if (unformat (i, "EgPE %d", &pl_index))
6616 if (pl_index <= 0 || pl_index > 4)
6617 goto pl_index_range_error;
6618 flags |= IP6_SR_HEADER_FLAG_PL_ELT_EGRESS_PE << (3*(pl_index - 1));
6620 else if (unformat (i, "OrgSrc %d", &pl_index))
6622 if (pl_index <= 0 || pl_index > 4)
6623 goto pl_index_range_error;
6624 flags |= IP6_SR_HEADER_FLAG_PL_ELT_ORIG_SRC_ADDR << (3*(pl_index - 1));
6630 if (!src_address_set)
6632 errmsg ("src address required\n");
6636 if (!dst_address_set)
6638 errmsg ("dst address required\n");
6644 errmsg ("at least one sr segment required\n");
6648 M2(SR_TUNNEL_ADD_DEL, sr_tunnel_add_del,
6649 vec_len(segments) * sizeof (ip6_address_t)
6650 + vec_len(tags) * sizeof (ip6_address_t));
6652 clib_memcpy (mp->src_address, &src_address, sizeof (mp->src_address));
6653 clib_memcpy (mp->dst_address, &dst_address, sizeof (mp->dst_address));
6654 mp->dst_mask_width = dst_mask_width;
6655 mp->flags_net_byte_order = clib_host_to_net_u16 (flags);
6656 mp->n_segments = vec_len (segments);
6657 mp->n_tags = vec_len (tags);
6658 mp->is_add = is_del == 0;
6659 clib_memcpy (mp->segs_and_tags, segments,
6660 vec_len(segments)* sizeof (ip6_address_t));
6661 clib_memcpy (mp->segs_and_tags + vec_len(segments)*sizeof (ip6_address_t),
6662 tags, vec_len(tags)* sizeof (ip6_address_t));
6664 mp->outer_vrf_id = ntohl (rx_table_id);
6665 mp->inner_vrf_id = ntohl (tx_table_id);
6666 memcpy (mp->name, name, vec_len(name));
6667 memcpy (mp->policy_name, policy_name, vec_len(policy_name));
6669 vec_free (segments);
6676 static int api_sr_policy_add_del (vat_main_t * vam)
6678 unformat_input_t * input = vam->input;
6679 vl_api_sr_policy_add_del_t *mp;
6683 u8 * tunnel_name = 0;
6684 u8 ** tunnel_names = 0;
6689 int tunnel_names_length = 1; // Init to 1 to offset the #tunnel_names counter byte
6690 int tun_name_len = 0; // Different naming convention used as confusing these would be "bad" (TM)
6692 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
6694 if (unformat (input, "del"))
6696 else if (unformat (input, "name %s", &name))
6698 else if (unformat (input, "tunnel %s", &tunnel_name))
6702 vec_add1 (tunnel_names, tunnel_name);
6704 - length = #bytes to store in serial vector
6705 - +1 = byte to store that length
6707 tunnel_names_length += (vec_len (tunnel_name) + 1);
6718 errmsg ("policy name required\n");
6722 if ((!tunnel_set) && (!is_del))
6724 errmsg ("tunnel name required\n");
6728 M2(SR_POLICY_ADD_DEL, sr_policy_add_del, tunnel_names_length);
6732 mp->is_add = !is_del;
6734 memcpy (mp->name, name, vec_len(name));
6735 // Since mp->tunnel_names is of type u8[0] and not a u8 *, u8 ** needs to be serialized
6736 u8 * serial_orig = 0;
6737 vec_validate (serial_orig, tunnel_names_length);
6738 *serial_orig = vec_len(tunnel_names); // Store the number of tunnels as length in first byte of serialized vector
6739 serial_orig += 1; // Move along one byte to store the length of first tunnel_name
6741 for (j=0; j < vec_len(tunnel_names); j++)
6743 tun_name_len = vec_len (tunnel_names[j]);
6744 *serial_orig = tun_name_len; // Store length of tunnel name in first byte of Length/Value pair
6745 serial_orig += 1; // Move along one byte to store the actual tunnel name
6746 memcpy (serial_orig, tunnel_names[j], tun_name_len);
6747 serial_orig += tun_name_len; // Advance past the copy
6749 memcpy (mp->tunnel_names, serial_orig - tunnel_names_length, tunnel_names_length); // Regress serial_orig to head then copy fwd
6751 vec_free (tunnel_names);
6752 vec_free (tunnel_name);
6758 static int api_sr_multicast_map_add_del (vat_main_t * vam)
6760 unformat_input_t * input = vam->input;
6761 vl_api_sr_multicast_map_add_del_t *mp;
6764 ip6_address_t multicast_address;
6765 u8 * policy_name = 0;
6766 int multicast_address_set = 0;
6768 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
6770 if (unformat (input, "del"))
6772 else if (unformat (input, "address %U", unformat_ip6_address, &multicast_address))
6773 multicast_address_set = 1;
6774 else if (unformat (input, "sr-policy %s", &policy_name))
6780 if (!is_del && !policy_name)
6782 errmsg ("sr-policy name required\n");
6787 if (!multicast_address_set)
6789 errmsg ("address required\n");
6793 M(SR_MULTICAST_MAP_ADD_DEL, sr_multicast_map_add_del);
6795 mp->is_add = !is_del;
6796 memcpy (mp->policy_name, policy_name, vec_len(policy_name));
6797 clib_memcpy (mp->multicast_address, &multicast_address, sizeof (mp->multicast_address));
6800 vec_free (policy_name);
6807 #define foreach_ip4_proto_field \
6817 uword unformat_ip4_mask (unformat_input_t * input, va_list * args)
6819 u8 ** maskp = va_arg (*args, u8 **);
6821 u8 found_something = 0;
6824 #define _(a) u8 a=0;
6825 foreach_ip4_proto_field;
6831 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
6833 if (unformat (input, "version"))
6835 else if (unformat (input, "hdr_length"))
6837 else if (unformat (input, "src"))
6839 else if (unformat (input, "dst"))
6841 else if (unformat (input, "proto"))
6844 #define _(a) else if (unformat (input, #a)) a=1;
6845 foreach_ip4_proto_field
6851 #define _(a) found_something += a;
6852 foreach_ip4_proto_field;
6855 if (found_something == 0)
6858 vec_validate (mask, sizeof (*ip) - 1);
6860 ip = (ip4_header_t *) mask;
6862 #define _(a) if (a) memset (&ip->a, 0xff, sizeof (ip->a));
6863 foreach_ip4_proto_field;
6866 ip->ip_version_and_header_length = 0;
6869 ip->ip_version_and_header_length |= 0xF0;
6872 ip->ip_version_and_header_length |= 0x0F;
6878 #define foreach_ip6_proto_field \
6885 uword unformat_ip6_mask (unformat_input_t * input, va_list * args)
6887 u8 ** maskp = va_arg (*args, u8 **);
6889 u8 found_something = 0;
6891 u32 ip_version_traffic_class_and_flow_label;
6893 #define _(a) u8 a=0;
6894 foreach_ip6_proto_field;
6897 u8 traffic_class = 0;
6900 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
6902 if (unformat (input, "version"))
6904 else if (unformat (input, "traffic-class"))
6906 else if (unformat (input, "flow-label"))
6908 else if (unformat (input, "src"))
6910 else if (unformat (input, "dst"))
6912 else if (unformat (input, "proto"))
6915 #define _(a) else if (unformat (input, #a)) a=1;
6916 foreach_ip6_proto_field
6922 #define _(a) found_something += a;
6923 foreach_ip6_proto_field;
6926 if (found_something == 0)
6929 vec_validate (mask, sizeof (*ip) - 1);
6931 ip = (ip6_header_t *) mask;
6933 #define _(a) if (a) memset (&ip->a, 0xff, sizeof (ip->a));
6934 foreach_ip6_proto_field;
6937 ip_version_traffic_class_and_flow_label = 0;
6940 ip_version_traffic_class_and_flow_label |= 0xF0000000;
6943 ip_version_traffic_class_and_flow_label |= 0x0FF00000;
6946 ip_version_traffic_class_and_flow_label |= 0x000FFFFF;
6948 ip->ip_version_traffic_class_and_flow_label =
6949 clib_host_to_net_u32 (ip_version_traffic_class_and_flow_label);
6955 uword unformat_l3_mask (unformat_input_t * input, va_list * args)
6957 u8 ** maskp = va_arg (*args, u8 **);
6959 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) {
6960 if (unformat (input, "ip4 %U", unformat_ip4_mask, maskp))
6962 else if (unformat (input, "ip6 %U", unformat_ip6_mask, maskp))
6970 uword unformat_l2_mask (unformat_input_t * input, va_list * args)
6972 u8 ** maskp = va_arg (*args, u8 **);
6987 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) {
6988 if (unformat (input, "src"))
6990 else if (unformat (input, "dst"))
6992 else if (unformat (input, "proto"))
6994 else if (unformat (input, "tag1"))
6996 else if (unformat (input, "tag2"))
6998 else if (unformat (input, "ignore-tag1"))
7000 else if (unformat (input, "ignore-tag2"))
7002 else if (unformat (input, "cos1"))
7004 else if (unformat (input, "cos2"))
7006 else if (unformat (input, "dot1q"))
7008 else if (unformat (input, "dot1ad"))
7013 if ((src + dst + proto + tag1 + tag2 + dot1q + dot1ad +
7014 ignore_tag1 + ignore_tag2 + cos1 + cos2) == 0)
7017 if (tag1 || ignore_tag1 || cos1 || dot1q)
7019 if (tag2 || ignore_tag2 || cos2 || dot1ad)
7022 vec_validate (mask, len-1);
7025 memset (mask, 0xff, 6);
7028 memset (mask + 6, 0xff, 6);
7032 /* inner vlan tag */
7041 mask[21] = mask [20] = 0xff;
7062 mask[16] = mask [17] = 0xff;
7072 mask[12] = mask [13] = 0xff;
7078 uword unformat_classify_mask (unformat_input_t * input, va_list * args)
7080 u8 ** maskp = va_arg (*args, u8 **);
7081 u32 * skipp = va_arg (*args, u32 *);
7082 u32 * matchp = va_arg (*args, u32 *);
7089 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) {
7090 if (unformat (input, "hex %U", unformat_hex_string, &mask))
7092 else if (unformat (input, "l2 %U", unformat_l2_mask, &l2))
7094 else if (unformat (input, "l3 %U", unformat_l3_mask, &l3))
7100 if (mask || l2 || l3)
7104 /* "With a free Ethernet header in every package" */
7106 vec_validate (l2, 13);
7108 vec_append (mask, l3);
7112 /* Scan forward looking for the first significant mask octet */
7113 for (i = 0; i < vec_len (mask); i++)
7117 /* compute (skip, match) params */
7118 *skipp = i / sizeof(u32x4);
7119 vec_delete (mask, *skipp * sizeof(u32x4), 0);
7121 /* Pad mask to an even multiple of the vector size */
7122 while (vec_len (mask) % sizeof (u32x4))
7125 match = vec_len (mask) / sizeof (u32x4);
7127 for (i = match*sizeof(u32x4); i > 0; i-= sizeof(u32x4))
7129 u64 *tmp = (u64 *)(mask + (i-sizeof(u32x4)));
7130 if (*tmp || *(tmp+1))
7135 clib_warning ("BUG: match 0");
7137 _vec_len (mask) = match * sizeof(u32x4);
7148 #define foreach_l2_next \
7150 _(ethernet, ETHERNET_INPUT) \
7154 uword unformat_l2_next_index (unformat_input_t * input, va_list * args)
7156 u32 * miss_next_indexp = va_arg (*args, u32 *);
7161 if (unformat (input, #n)) { next_index = L2_CLASSIFY_NEXT_##N; goto out;}
7165 if (unformat (input, "%d", &tmp))
7174 *miss_next_indexp = next_index;
7178 #define foreach_ip_next \
7184 uword unformat_ip_next_index (unformat_input_t * input, va_list * args)
7186 u32 * miss_next_indexp = va_arg (*args, u32 *);
7191 if (unformat (input, #n)) { next_index = IP_LOOKUP_NEXT_##N; goto out;}
7195 if (unformat (input, "%d", &tmp))
7204 *miss_next_indexp = next_index;
7208 #define foreach_acl_next \
7211 uword unformat_acl_next_index (unformat_input_t * input, va_list * args)
7213 u32 * miss_next_indexp = va_arg (*args, u32 *);
7218 if (unformat (input, #n)) { next_index = ACL_NEXT_INDEX_##N; goto out;}
7222 if (unformat (input, "permit"))
7227 else if (unformat (input, "%d", &tmp))
7236 *miss_next_indexp = next_index;
7240 uword unformat_policer_precolor (unformat_input_t * input, va_list * args)
7242 u32 * r = va_arg (*args, u32 *);
7244 if (unformat (input, "conform-color"))
7245 *r = POLICE_CONFORM;
7246 else if (unformat (input, "exceed-color"))
7254 static int api_classify_add_del_table (vat_main_t * vam)
7256 unformat_input_t * i = vam->input;
7257 vl_api_classify_add_del_table_t *mp;
7263 u32 table_index = ~0;
7264 u32 next_table_index = ~0;
7265 u32 miss_next_index = ~0;
7266 u32 memory_size = 32<<20;
7270 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
7271 if (unformat (i, "del"))
7273 else if (unformat (i, "buckets %d", &nbuckets))
7275 else if (unformat (i, "memory_size %d", &memory_size))
7277 else if (unformat (i, "skip %d", &skip))
7279 else if (unformat (i, "match %d", &match))
7281 else if (unformat (i, "table %d", &table_index))
7283 else if (unformat (i, "mask %U", unformat_classify_mask,
7284 &mask, &skip, &match))
7286 else if (unformat (i, "next-table %d", &next_table_index))
7288 else if (unformat (i, "miss-next %U", unformat_ip_next_index,
7291 else if (unformat (i, "l2-miss-next %U", unformat_l2_next_index,
7294 else if (unformat (i, "acl-miss-next %U", unformat_acl_next_index,
7301 if (is_add && mask == 0) {
7302 errmsg ("Mask required\n");
7306 if (is_add && skip == ~0) {
7307 errmsg ("skip count required\n");
7311 if (is_add && match == ~0) {
7312 errmsg ("match count required\n");
7316 if (!is_add && table_index == ~0) {
7317 errmsg ("table index required for delete\n");
7321 M2 (CLASSIFY_ADD_DEL_TABLE, classify_add_del_table,
7324 mp->is_add = is_add;
7325 mp->table_index = ntohl(table_index);
7326 mp->nbuckets = ntohl(nbuckets);
7327 mp->memory_size = ntohl(memory_size);
7328 mp->skip_n_vectors = ntohl(skip);
7329 mp->match_n_vectors = ntohl(match);
7330 mp->next_table_index = ntohl(next_table_index);
7331 mp->miss_next_index = ntohl(miss_next_index);
7332 clib_memcpy (mp->mask, mask, vec_len(mask));
7340 uword unformat_ip4_match (unformat_input_t * input, va_list * args)
7342 u8 ** matchp = va_arg (*args, u8 **);
7349 int src = 0, dst = 0;
7350 ip4_address_t src_val, dst_val;
7357 int fragment_id = 0;
7358 u32 fragment_id_val;
7364 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
7366 if (unformat (input, "version %d", &version_val))
7368 else if (unformat (input, "hdr_length %d", &hdr_length_val))
7370 else if (unformat (input, "src %U", unformat_ip4_address, &src_val))
7372 else if (unformat (input, "dst %U", unformat_ip4_address, &dst_val))
7374 else if (unformat (input, "proto %d", &proto_val))
7376 else if (unformat (input, "tos %d", &tos_val))
7378 else if (unformat (input, "length %d", &length_val))
7380 else if (unformat (input, "fragment_id %d", &fragment_id_val))
7382 else if (unformat (input, "ttl %d", &ttl_val))
7384 else if (unformat (input, "checksum %d", &checksum_val))
7390 if (version + hdr_length + src + dst + proto + tos + length + fragment_id
7391 + ttl + checksum == 0)
7395 * Aligned because we use the real comparison functions
7397 vec_validate_aligned (match, sizeof (*ip) - 1, sizeof(u32x4));
7399 ip = (ip4_header_t *) match;
7401 /* These are realistically matched in practice */
7403 ip->src_address.as_u32 = src_val.as_u32;
7406 ip->dst_address.as_u32 = dst_val.as_u32;
7409 ip->protocol = proto_val;
7412 /* These are not, but they're included for completeness */
7414 ip->ip_version_and_header_length |= (version_val & 0xF)<<4;
7417 ip->ip_version_and_header_length |= (hdr_length_val & 0xF);
7423 ip->length = length_val;
7429 ip->checksum = checksum_val;
7435 uword unformat_ip6_match (unformat_input_t * input, va_list * args)
7437 u8 ** matchp = va_arg (*args, u8 **);
7443 u32 traffic_class_val;
7446 int src = 0, dst = 0;
7447 ip6_address_t src_val, dst_val;
7450 int payload_length = 0;
7451 u32 payload_length_val;
7454 u32 ip_version_traffic_class_and_flow_label;
7456 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
7458 if (unformat (input, "version %d", &version_val))
7460 else if (unformat (input, "traffic_class %d", &traffic_class_val))
7462 else if (unformat (input, "flow_label %d", &flow_label_val))
7464 else if (unformat (input, "src %U", unformat_ip6_address, &src_val))
7466 else if (unformat (input, "dst %U", unformat_ip6_address, &dst_val))
7468 else if (unformat (input, "proto %d", &proto_val))
7470 else if (unformat (input, "payload_length %d", &payload_length_val))
7472 else if (unformat (input, "hop_limit %d", &hop_limit_val))
7478 if (version + traffic_class + flow_label + src + dst + proto +
7479 payload_length + hop_limit == 0)
7483 * Aligned because we use the real comparison functions
7485 vec_validate_aligned (match, sizeof (*ip) - 1, sizeof(u32x4));
7487 ip = (ip6_header_t *) match;
7490 clib_memcpy (&ip->src_address, &src_val, sizeof (ip->src_address));
7493 clib_memcpy (&ip->dst_address, &dst_val, sizeof (ip->dst_address));
7496 ip->protocol = proto_val;
7498 ip_version_traffic_class_and_flow_label = 0;
7501 ip_version_traffic_class_and_flow_label |= (version_val & 0xF) << 28;
7504 ip_version_traffic_class_and_flow_label |= (traffic_class_val & 0xFF) << 20;
7507 ip_version_traffic_class_and_flow_label |= (flow_label_val & 0xFFFFF);
7509 ip->ip_version_traffic_class_and_flow_label =
7510 clib_host_to_net_u32 (ip_version_traffic_class_and_flow_label);
7513 ip->payload_length = clib_host_to_net_u16 (payload_length_val);
7516 ip->hop_limit = hop_limit_val;
7522 uword unformat_l3_match (unformat_input_t * input, va_list * args)
7524 u8 ** matchp = va_arg (*args, u8 **);
7526 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) {
7527 if (unformat (input, "ip4 %U", unformat_ip4_match, matchp))
7529 else if (unformat (input, "ip6 %U", unformat_ip6_match, matchp))
7537 uword unformat_vlan_tag (unformat_input_t * input, va_list * args)
7539 u8 * tagp = va_arg (*args, u8 *);
7542 if (unformat(input, "%d", &tag))
7544 tagp[0] = (tag>>8) & 0x0F;
7545 tagp[1] = tag & 0xFF;
7552 uword unformat_l2_match (unformat_input_t * input, va_list * args)
7554 u8 ** matchp = va_arg (*args, u8 **);
7574 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) {
7575 if (unformat (input, "src %U", unformat_ethernet_address, &src_val))
7577 else if (unformat (input, "dst %U", unformat_ethernet_address, &dst_val))
7579 else if (unformat (input, "proto %U",
7580 unformat_ethernet_type_host_byte_order, &proto_val))
7582 else if (unformat (input, "tag1 %U", unformat_vlan_tag, tag1_val))
7584 else if (unformat (input, "tag2 %U", unformat_vlan_tag, tag2_val))
7586 else if (unformat (input, "ignore-tag1"))
7588 else if (unformat (input, "ignore-tag2"))
7590 else if (unformat (input, "cos1 %d", &cos1_val))
7592 else if (unformat (input, "cos2 %d", &cos2_val))
7597 if ((src + dst + proto + tag1 + tag2 +
7598 ignore_tag1 + ignore_tag2 + cos1 + cos2) == 0)
7601 if (tag1 || ignore_tag1 || cos1)
7603 if (tag2 || ignore_tag2 || cos2)
7606 vec_validate_aligned (match, len-1, sizeof(u32x4));
7609 clib_memcpy (match, dst_val, 6);
7612 clib_memcpy (match + 6, src_val, 6);
7616 /* inner vlan tag */
7617 match[19] = tag2_val[1];
7618 match[18] = tag2_val[0];
7620 match [18] |= (cos2_val & 0x7) << 5;
7623 match[21] = proto_val & 0xff;
7624 match[20] = proto_val >> 8;
7628 match [15] = tag1_val[1];
7629 match [14] = tag1_val[0];
7632 match [14] |= (cos1_val & 0x7) << 5;
7638 match [15] = tag1_val[1];
7639 match [14] = tag1_val[0];
7642 match[17] = proto_val & 0xff;
7643 match[16] = proto_val >> 8;
7646 match [14] |= (cos1_val & 0x7) << 5;
7652 match [18] |= (cos2_val & 0x7) << 5;
7654 match [14] |= (cos1_val & 0x7) << 5;
7657 match[13] = proto_val & 0xff;
7658 match[12] = proto_val >> 8;
7666 uword unformat_classify_match (unformat_input_t * input, va_list * args)
7668 u8 ** matchp = va_arg (*args, u8 **);
7669 u32 skip_n_vectors = va_arg (*args, u32);
7670 u32 match_n_vectors = va_arg (*args, u32);
7676 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) {
7677 if (unformat (input, "hex %U", unformat_hex_string, &match))
7679 else if (unformat (input, "l2 %U", unformat_l2_match, &l2))
7681 else if (unformat (input, "l3 %U", unformat_l3_match, &l3))
7687 if (match || l2 || l3)
7691 /* "Win a free Ethernet header in every packet" */
7693 vec_validate_aligned (l2, 13, sizeof(u32x4));
7695 vec_append_aligned (match, l3, sizeof(u32x4));
7699 /* Make sure the vector is big enough even if key is all 0's */
7700 vec_validate_aligned
7701 (match, ((match_n_vectors + skip_n_vectors) * sizeof(u32x4)) - 1,
7704 /* Set size, include skipped vectors*/
7705 _vec_len (match) = (match_n_vectors+skip_n_vectors) * sizeof(u32x4);
7715 static int api_classify_add_del_session (vat_main_t * vam)
7717 unformat_input_t * i = vam->input;
7718 vl_api_classify_add_del_session_t *mp;
7720 u32 table_index = ~0;
7721 u32 hit_next_index = ~0;
7722 u32 opaque_index = ~0;
7726 u32 skip_n_vectors = 0;
7727 u32 match_n_vectors = 0;
7730 * Warning: you have to supply skip_n and match_n
7731 * because the API client cant simply look at the classify
7735 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
7736 if (unformat (i, "del"))
7738 else if (unformat (i, "hit-next %U", unformat_ip_next_index,
7741 else if (unformat (i, "l2-hit-next %U", unformat_l2_next_index,
7744 else if (unformat (i, "acl-hit-next %U", unformat_acl_next_index,
7747 else if (unformat (i, "policer-hit-next %d", &hit_next_index))
7749 else if (unformat (i, "%U", unformat_policer_precolor, &opaque_index))
7751 else if (unformat (i, "opaque-index %d", &opaque_index))
7753 else if (unformat (i, "skip_n %d", &skip_n_vectors))
7755 else if (unformat (i, "match_n %d", &match_n_vectors))
7757 else if (unformat (i, "match %U", unformat_classify_match,
7758 &match, skip_n_vectors, match_n_vectors))
7760 else if (unformat (i, "advance %d", &advance))
7762 else if (unformat (i, "table-index %d", &table_index))
7768 if (table_index == ~0) {
7769 errmsg ("Table index required\n");
7773 if (is_add && match == 0) {
7774 errmsg ("Match value required\n");
7778 M2 (CLASSIFY_ADD_DEL_SESSION, classify_add_del_session,
7781 mp->is_add = is_add;
7782 mp->table_index = ntohl(table_index);
7783 mp->hit_next_index = ntohl(hit_next_index);
7784 mp->opaque_index = ntohl(opaque_index);
7785 mp->advance = ntohl(advance);
7786 clib_memcpy (mp->match, match, vec_len(match));
7793 static int api_classify_set_interface_ip_table (vat_main_t * vam)
7795 unformat_input_t * i = vam->input;
7796 vl_api_classify_set_interface_ip_table_t *mp;
7799 int sw_if_index_set;
7800 u32 table_index = ~0;
7803 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
7804 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
7805 sw_if_index_set = 1;
7806 else if (unformat (i, "sw_if_index %d", &sw_if_index))
7807 sw_if_index_set = 1;
7808 else if (unformat (i, "table %d", &table_index))
7811 clib_warning ("parse error '%U'", format_unformat_error, i);
7816 if (sw_if_index_set == 0) {
7817 errmsg ("missing interface name or sw_if_index\n");
7822 M(CLASSIFY_SET_INTERFACE_IP_TABLE, classify_set_interface_ip_table);
7824 mp->sw_if_index = ntohl(sw_if_index);
7825 mp->table_index = ntohl(table_index);
7826 mp->is_ipv6 = is_ipv6;
7833 static int api_classify_set_interface_l2_tables (vat_main_t * vam)
7835 unformat_input_t * i = vam->input;
7836 vl_api_classify_set_interface_l2_tables_t *mp;
7839 int sw_if_index_set;
7840 u32 ip4_table_index = ~0;
7841 u32 ip6_table_index = ~0;
7842 u32 other_table_index = ~0;
7844 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
7845 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
7846 sw_if_index_set = 1;
7847 else if (unformat (i, "sw_if_index %d", &sw_if_index))
7848 sw_if_index_set = 1;
7849 else if (unformat (i, "ip4-table %d", &ip4_table_index))
7851 else if (unformat (i, "ip6-table %d", &ip6_table_index))
7853 else if (unformat (i, "other-table %d", &other_table_index))
7856 clib_warning ("parse error '%U'", format_unformat_error, i);
7861 if (sw_if_index_set == 0) {
7862 errmsg ("missing interface name or sw_if_index\n");
7867 M(CLASSIFY_SET_INTERFACE_L2_TABLES, classify_set_interface_l2_tables);
7869 mp->sw_if_index = ntohl(sw_if_index);
7870 mp->ip4_table_index = ntohl(ip4_table_index);
7871 mp->ip6_table_index = ntohl(ip6_table_index);
7872 mp->other_table_index = ntohl(other_table_index);
7880 static int api_ipfix_enable (vat_main_t * vam)
7882 unformat_input_t * i = vam->input;
7883 vl_api_ipfix_enable_t *mp;
7884 ip4_address_t collector_address;
7885 u8 collector_address_set = 0;
7886 u32 collector_port = ~0;
7887 ip4_address_t src_address;
7888 u8 src_address_set = 0;
7891 u32 template_interval = ~0;
7894 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
7895 if (unformat (i, "collector_address %U", unformat_ip4_address,
7896 &collector_address))
7897 collector_address_set = 1;
7898 else if (unformat (i, "collector_port %d", &collector_port))
7900 else if (unformat (i, "src_address %U", unformat_ip4_address,
7902 src_address_set = 1;
7903 else if (unformat (i, "vrf_id %d", &vrf_id))
7905 else if (unformat (i, "path_mtu %d", &path_mtu))
7907 else if (unformat (i, "template_interval %d", &template_interval))
7913 if (collector_address_set == 0) {
7914 errmsg ("collector_address required\n");
7918 if (src_address_set == 0) {
7919 errmsg ("src_address required\n");
7923 M (IPFIX_ENABLE, ipfix_enable);
7925 memcpy(mp->collector_address, collector_address.data,
7926 sizeof(collector_address.data));
7927 mp->collector_port = htons((u16)collector_port);
7928 memcpy(mp->src_address, src_address.data,
7929 sizeof(src_address.data));
7930 mp->vrf_id = htonl(vrf_id);
7931 mp->path_mtu = htonl(path_mtu);
7932 mp->template_interval = htonl(template_interval);
7938 static int api_get_node_index (vat_main_t * vam)
7940 unformat_input_t * i = vam->input;
7941 vl_api_get_node_index_t * mp;
7945 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
7946 if (unformat (i, "node %s", &name))
7952 errmsg ("node name required\n");
7955 if (vec_len (name) >= ARRAY_LEN(mp->node_name)) {
7956 errmsg ("node name too long, max %d\n", ARRAY_LEN(mp->node_name));
7960 M(GET_NODE_INDEX, get_node_index);
7961 clib_memcpy (mp->node_name, name, vec_len(name));
7969 static int api_get_next_index (vat_main_t * vam)
7971 unformat_input_t * i = vam->input;
7972 vl_api_get_next_index_t * mp;
7974 u8 * node_name = 0, * next_node_name = 0;
7976 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
7977 if (unformat (i, "node-name %s", &node_name))
7979 else if (unformat (i, "next-node-name %s", &next_node_name))
7983 if (node_name == 0) {
7984 errmsg ("node name required\n");
7987 if (vec_len (node_name) >= ARRAY_LEN(mp->node_name)) {
7988 errmsg ("node name too long, max %d\n", ARRAY_LEN(mp->node_name));
7992 if (next_node_name == 0) {
7993 errmsg ("next node name required\n");
7996 if (vec_len (next_node_name) >= ARRAY_LEN(mp->next_name)) {
7997 errmsg ("next node name too long, max %d\n", ARRAY_LEN(mp->next_name));
8001 M(GET_NEXT_INDEX, get_next_index);
8002 clib_memcpy (mp->node_name, node_name, vec_len(node_name));
8003 clib_memcpy (mp->next_name, next_node_name, vec_len(next_node_name));
8004 vec_free(node_name);
8005 vec_free(next_node_name);
8012 static int api_add_node_next (vat_main_t * vam)
8014 unformat_input_t * i = vam->input;
8015 vl_api_add_node_next_t * mp;
8020 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
8021 if (unformat (i, "node %s", &name))
8023 else if (unformat (i, "next %s", &next))
8029 errmsg ("node name required\n");
8032 if (vec_len (name) >= ARRAY_LEN(mp->node_name)) {
8033 errmsg ("node name too long, max %d\n", ARRAY_LEN(mp->node_name));
8037 errmsg ("next node required\n");
8040 if (vec_len (next) >= ARRAY_LEN(mp->next_name)) {
8041 errmsg ("next name too long, max %d\n", ARRAY_LEN(mp->next_name));
8045 M(ADD_NODE_NEXT, add_node_next);
8046 clib_memcpy (mp->node_name, name, vec_len(name));
8047 clib_memcpy (mp->next_name, next, vec_len(next));
8056 static int api_l2tpv3_create_tunnel (vat_main_t * vam)
8058 unformat_input_t * i = vam->input;
8059 ip6_address_t client_address, our_address;
8060 int client_address_set = 0;
8061 int our_address_set = 0;
8062 u32 local_session_id = 0;
8063 u32 remote_session_id = 0;
8064 u64 local_cookie = 0;
8065 u64 remote_cookie = 0;
8066 u8 l2_sublayer_present = 0;
8067 vl_api_l2tpv3_create_tunnel_t * mp;
8070 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
8071 if (unformat (i, "client_address %U", unformat_ip6_address,
8073 client_address_set = 1;
8074 else if (unformat (i, "our_address %U", unformat_ip6_address,
8076 our_address_set = 1;
8077 else if (unformat (i, "local_session_id %d", &local_session_id))
8079 else if (unformat (i, "remote_session_id %d", &remote_session_id))
8081 else if (unformat (i, "local_cookie %lld", &local_cookie))
8083 else if (unformat (i, "remote_cookie %lld", &remote_cookie))
8085 else if (unformat (i, "l2-sublayer-present"))
8086 l2_sublayer_present = 1;
8091 if (client_address_set == 0) {
8092 errmsg ("client_address required\n");
8096 if (our_address_set == 0) {
8097 errmsg ("our_address required\n");
8101 M(L2TPV3_CREATE_TUNNEL, l2tpv3_create_tunnel);
8103 clib_memcpy (mp->client_address, client_address.as_u8,
8104 sizeof (mp->client_address));
8106 clib_memcpy (mp->our_address, our_address.as_u8,
8107 sizeof (mp->our_address));
8109 mp->local_session_id = ntohl (local_session_id);
8110 mp->remote_session_id = ntohl (remote_session_id);
8111 mp->local_cookie = clib_host_to_net_u64 (local_cookie);
8112 mp->remote_cookie = clib_host_to_net_u64 (remote_cookie);
8113 mp->l2_sublayer_present = l2_sublayer_present;
8121 static int api_l2tpv3_set_tunnel_cookies (vat_main_t * vam)
8123 unformat_input_t * i = vam->input;
8125 u8 sw_if_index_set = 0;
8126 u64 new_local_cookie = 0;
8127 u64 new_remote_cookie = 0;
8128 vl_api_l2tpv3_set_tunnel_cookies_t *mp;
8131 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
8132 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
8133 sw_if_index_set = 1;
8134 else if (unformat (i, "sw_if_index %d", &sw_if_index))
8135 sw_if_index_set = 1;
8136 else if (unformat (i, "new_local_cookie %lld", &new_local_cookie))
8138 else if (unformat (i, "new_remote_cookie %lld", &new_remote_cookie))
8144 if (sw_if_index_set == 0) {
8145 errmsg ("missing interface name or sw_if_index\n");
8149 M(L2TPV3_SET_TUNNEL_COOKIES, l2tpv3_set_tunnel_cookies);
8151 mp->sw_if_index = ntohl(sw_if_index);
8152 mp->new_local_cookie = clib_host_to_net_u64 (new_local_cookie);
8153 mp->new_remote_cookie = clib_host_to_net_u64 (new_remote_cookie);
8160 static int api_l2tpv3_interface_enable_disable (vat_main_t * vam)
8162 unformat_input_t * i = vam->input;
8163 vl_api_l2tpv3_interface_enable_disable_t *mp;
8166 u8 sw_if_index_set = 0;
8167 u8 enable_disable = 1;
8169 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
8170 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
8171 sw_if_index_set = 1;
8172 else if (unformat (i, "sw_if_index %d", &sw_if_index))
8173 sw_if_index_set = 1;
8174 else if (unformat (i, "enable"))
8176 else if (unformat (i, "disable"))
8182 if (sw_if_index_set == 0) {
8183 errmsg ("missing interface name or sw_if_index\n");
8187 M(L2TPV3_INTERFACE_ENABLE_DISABLE, l2tpv3_interface_enable_disable);
8189 mp->sw_if_index = ntohl(sw_if_index);
8190 mp->enable_disable = enable_disable;
8197 static int api_l2tpv3_set_lookup_key (vat_main_t * vam)
8199 unformat_input_t * i = vam->input;
8200 vl_api_l2tpv3_set_lookup_key_t * mp;
8204 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
8205 if (unformat (i, "lookup_v6_src"))
8206 key = L2T_LOOKUP_SRC_ADDRESS;
8207 else if (unformat (i, "lookup_v6_dst"))
8208 key = L2T_LOOKUP_DST_ADDRESS;
8209 else if (unformat (i, "lookup_session_id"))
8210 key = L2T_LOOKUP_SESSION_ID;
8215 if (key == (u8) ~0) {
8216 errmsg ("l2tp session lookup key unset\n");
8220 M(L2TPV3_SET_LOOKUP_KEY, l2tpv3_set_lookup_key);
8229 static void vl_api_sw_if_l2tpv3_tunnel_details_t_handler
8230 (vl_api_sw_if_l2tpv3_tunnel_details_t * mp)
8232 vat_main_t * vam = &vat_main;
8234 fformat(vam->ofp, "* %U (our) %U (client) (sw_if_index %d)\n",
8235 format_ip6_address, mp->our_address,
8236 format_ip6_address, mp->client_address,
8237 clib_net_to_host_u32(mp->sw_if_index));
8239 fformat (vam->ofp, " local cookies %016llx %016llx remote cookie %016llx\n",
8240 clib_net_to_host_u64 (mp->local_cookie[0]),
8241 clib_net_to_host_u64 (mp->local_cookie[1]),
8242 clib_net_to_host_u64 (mp->remote_cookie));
8244 fformat (vam->ofp, " local session-id %d remote session-id %d\n",
8245 clib_net_to_host_u32 (mp->local_session_id),
8246 clib_net_to_host_u32 (mp->remote_session_id));
8248 fformat (vam->ofp, " l2 specific sublayer %s\n\n",
8249 mp->l2_sublayer_present ? "preset" : "absent");
8253 static void vl_api_sw_if_l2tpv3_tunnel_details_t_handler_json
8254 (vl_api_sw_if_l2tpv3_tunnel_details_t * mp)
8256 vat_main_t * vam = &vat_main;
8257 vat_json_node_t *node = NULL;
8258 struct in6_addr addr;
8260 if (VAT_JSON_ARRAY != vam->json_tree.type) {
8261 ASSERT(VAT_JSON_NONE == vam->json_tree.type);
8262 vat_json_init_array(&vam->json_tree);
8264 node = vat_json_array_add(&vam->json_tree);
8266 vat_json_init_object(node);
8268 clib_memcpy(&addr, mp->our_address, sizeof(addr));
8269 vat_json_object_add_ip6(node, "our_address", addr);
8270 clib_memcpy(&addr, mp->client_address, sizeof(addr));
8271 vat_json_object_add_ip6(node, "client_address", addr);
8273 vat_json_node_t * lc = vat_json_object_add(node, "local_cookie");
8274 vat_json_init_array(lc);
8275 vat_json_array_add_uint(lc, clib_net_to_host_u64(mp->local_cookie[0]));
8276 vat_json_array_add_uint(lc, clib_net_to_host_u64(mp->local_cookie[1]));
8277 vat_json_object_add_uint(node, "remote_cookie", clib_net_to_host_u64(mp->remote_cookie));
8279 printf("local id: %u", clib_net_to_host_u32(mp->local_session_id));
8280 vat_json_object_add_uint(node, "local_session_id", clib_net_to_host_u32(mp->local_session_id));
8281 vat_json_object_add_uint(node, "remote_session_id", clib_net_to_host_u32(mp->remote_session_id));
8282 vat_json_object_add_string_copy(node, "l2_sublayer", mp->l2_sublayer_present ?
8283 (u8*)"present" : (u8*)"absent");
8286 static int api_sw_if_l2tpv3_tunnel_dump (vat_main_t * vam)
8288 vl_api_sw_if_l2tpv3_tunnel_dump_t *mp;
8291 /* Get list of l2tpv3-tunnel interfaces */
8292 M(SW_IF_L2TPV3_TUNNEL_DUMP, sw_if_l2tpv3_tunnel_dump);
8295 /* Use a control ping for synchronization */
8297 vl_api_control_ping_t * mp;
8298 M(CONTROL_PING, control_ping);
8305 static void vl_api_sw_interface_tap_details_t_handler
8306 (vl_api_sw_interface_tap_details_t * mp)
8308 vat_main_t * vam = &vat_main;
8310 fformat(vam->ofp, "%-16s %d\n",
8312 clib_net_to_host_u32(mp->sw_if_index));
8315 static void vl_api_sw_interface_tap_details_t_handler_json
8316 (vl_api_sw_interface_tap_details_t * mp)
8318 vat_main_t * vam = &vat_main;
8319 vat_json_node_t *node = NULL;
8321 if (VAT_JSON_ARRAY != vam->json_tree.type) {
8322 ASSERT(VAT_JSON_NONE == vam->json_tree.type);
8323 vat_json_init_array(&vam->json_tree);
8325 node = vat_json_array_add(&vam->json_tree);
8327 vat_json_init_object(node);
8328 vat_json_object_add_uint(node, "sw_if_index", ntohl(mp->sw_if_index));
8329 vat_json_object_add_string_copy(node, "dev_name", mp->dev_name);
8332 static int api_sw_interface_tap_dump (vat_main_t * vam)
8334 vl_api_sw_interface_tap_dump_t *mp;
8337 fformat(vam->ofp, "\n%-16s %s\n", "dev_name", "sw_if_index");
8338 /* Get list of tap interfaces */
8339 M(SW_INTERFACE_TAP_DUMP, sw_interface_tap_dump);
8342 /* Use a control ping for synchronization */
8344 vl_api_control_ping_t * mp;
8345 M(CONTROL_PING, control_ping);
8351 static uword unformat_vxlan_decap_next
8352 (unformat_input_t * input, va_list * args)
8354 u32 * result = va_arg (*args, u32 *);
8357 if (unformat (input, "drop"))
8358 *result = VXLAN_INPUT_NEXT_DROP;
8359 else if (unformat (input, "ip4"))
8360 *result = VXLAN_INPUT_NEXT_IP4_INPUT;
8361 else if (unformat (input, "ip6"))
8362 *result = VXLAN_INPUT_NEXT_IP6_INPUT;
8363 else if (unformat (input, "l2"))
8364 *result = VXLAN_INPUT_NEXT_L2_INPUT;
8365 else if (unformat (input, "%d", &tmp))
8372 static int api_vxlan_add_del_tunnel (vat_main_t * vam)
8374 unformat_input_t * line_input = vam->input;
8375 vl_api_vxlan_add_del_tunnel_t *mp;
8377 ip4_address_t src4, dst4;
8378 ip6_address_t src6, dst6;
8380 u8 ipv4_set = 0, ipv6_set = 0;
8383 u32 encap_vrf_id = 0;
8384 u32 decap_next_index = ~0;
8387 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) {
8388 if (unformat (line_input, "del"))
8390 else if (unformat (line_input, "src %U",
8391 unformat_ip4_address, &src4))
8396 else if (unformat (line_input, "dst %U",
8397 unformat_ip4_address, &dst4))
8402 else if (unformat (line_input, "src %U",
8403 unformat_ip6_address, &src6))
8408 else if (unformat (line_input, "dst %U",
8409 unformat_ip6_address, &dst6))
8414 else if (unformat (line_input, "encap-vrf-id %d", &encap_vrf_id))
8416 else if (unformat (line_input, "decap-next %U",
8417 unformat_vxlan_decap_next, &decap_next_index))
8419 else if (unformat (line_input, "vni %d", &vni))
8422 errmsg ("parse error '%U'\n", format_unformat_error, line_input);
8428 errmsg ("tunnel src address not specified\n");
8432 errmsg ("tunnel dst address not specified\n");
8436 if (ipv4_set && ipv6_set) {
8437 errmsg ("both IPv4 and IPv6 addresses specified");
8441 if ((vni == 0) || (vni>>24)) {
8442 errmsg ("vni not specified or out of range\n");
8446 M (VXLAN_ADD_DEL_TUNNEL, vxlan_add_del_tunnel);
8449 clib_memcpy(&mp->src_address, &src6, sizeof(src6));
8450 clib_memcpy(&mp->dst_address, &dst6, sizeof(dst6));
8452 clib_memcpy(&mp->src_address, &src4, sizeof(src4));
8453 clib_memcpy(&mp->dst_address, &dst4, sizeof(dst4));
8455 mp->encap_vrf_id = ntohl(encap_vrf_id);
8456 mp->decap_next_index = ntohl(decap_next_index);
8457 mp->vni = ntohl(vni);
8458 mp->is_add = is_add;
8459 mp->is_ipv6 = ipv6_set;
8466 static void vl_api_vxlan_tunnel_details_t_handler
8467 (vl_api_vxlan_tunnel_details_t * mp)
8469 vat_main_t * vam = &vat_main;
8471 fformat(vam->ofp, "%11d%24U%24U%14d%18d%13d\n",
8472 ntohl(mp->sw_if_index),
8473 format_ip46_address, &(mp->src_address[0]),
8475 format_ip46_address, &(mp->dst_address[0]),
8477 ntohl(mp->encap_vrf_id),
8478 ntohl(mp->decap_next_index),
8482 static void vl_api_vxlan_tunnel_details_t_handler_json
8483 (vl_api_vxlan_tunnel_details_t * mp)
8485 vat_main_t * vam = &vat_main;
8486 vat_json_node_t *node = NULL;
8488 struct in6_addr ip6;
8490 if (VAT_JSON_ARRAY != vam->json_tree.type) {
8491 ASSERT(VAT_JSON_NONE == vam->json_tree.type);
8492 vat_json_init_array(&vam->json_tree);
8494 node = vat_json_array_add(&vam->json_tree);
8496 vat_json_init_object(node);
8497 vat_json_object_add_uint(node, "sw_if_index", ntohl(mp->sw_if_index));
8499 clib_memcpy(&ip6, &(mp->src_address[0]), sizeof(ip6));
8500 vat_json_object_add_ip6(node, "src_address", ip6);
8501 clib_memcpy(&ip6, &(mp->dst_address[0]), sizeof(ip6));
8502 vat_json_object_add_ip6(node, "dst_address", ip6);
8504 clib_memcpy(&ip4, &(mp->src_address[0]), sizeof(ip4));
8505 vat_json_object_add_ip4(node, "src_address", ip4);
8506 clib_memcpy(&ip4, &(mp->dst_address[0]), sizeof(ip4));
8507 vat_json_object_add_ip4(node, "dst_address", ip4);
8509 vat_json_object_add_uint(node, "encap_vrf_id", ntohl(mp->encap_vrf_id));
8510 vat_json_object_add_uint(node, "decap_next_index", ntohl(mp->decap_next_index));
8511 vat_json_object_add_uint(node, "vni", ntohl(mp->vni));
8512 vat_json_object_add_uint(node, "is_ipv6", mp->is_ipv6 ? 1 : 0);
8515 static int api_vxlan_tunnel_dump (vat_main_t * vam)
8517 unformat_input_t * i = vam->input;
8518 vl_api_vxlan_tunnel_dump_t *mp;
8521 u8 sw_if_index_set = 0;
8523 /* Parse args required to build the message */
8524 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
8525 if (unformat (i, "sw_if_index %d", &sw_if_index))
8526 sw_if_index_set = 1;
8531 if (sw_if_index_set == 0) {
8535 if (!vam->json_output) {
8536 fformat(vam->ofp, "%11s%24s%24s%14s%18s%13s\n",
8537 "sw_if_index", "src_address", "dst_address",
8538 "encap_vrf_id", "decap_next_index", "vni");
8541 /* Get list of vxlan-tunnel interfaces */
8542 M(VXLAN_TUNNEL_DUMP, vxlan_tunnel_dump);
8544 mp->sw_if_index = htonl(sw_if_index);
8548 /* Use a control ping for synchronization */
8550 vl_api_control_ping_t * mp;
8551 M(CONTROL_PING, control_ping);
8557 static int api_gre_add_del_tunnel (vat_main_t * vam)
8559 unformat_input_t * line_input = vam->input;
8560 vl_api_gre_add_del_tunnel_t *mp;
8562 ip4_address_t src4, dst4;
8566 u32 outer_fib_id = 0;
8568 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) {
8569 if (unformat (line_input, "del"))
8571 else if (unformat (line_input, "src %U",
8572 unformat_ip4_address, &src4))
8574 else if (unformat (line_input, "dst %U",
8575 unformat_ip4_address, &dst4))
8577 else if (unformat (line_input, "outer-fib-id %d", &outer_fib_id))
8580 errmsg ("parse error '%U'\n", format_unformat_error, line_input);
8586 errmsg ("tunnel src address not specified\n");
8590 errmsg ("tunnel dst address not specified\n");
8595 M (GRE_ADD_DEL_TUNNEL, gre_add_del_tunnel);
8597 clib_memcpy(&mp->src_address, &src4, sizeof(src4));
8598 clib_memcpy(&mp->dst_address, &dst4, sizeof(dst4));
8599 mp->outer_fib_id = ntohl(outer_fib_id);
8600 mp->is_add = is_add;
8607 static void vl_api_gre_tunnel_details_t_handler
8608 (vl_api_gre_tunnel_details_t * mp)
8610 vat_main_t * vam = &vat_main;
8612 fformat(vam->ofp, "%11d%15U%15U%14d\n",
8613 ntohl(mp->sw_if_index),
8614 format_ip4_address, &mp->src_address,
8615 format_ip4_address, &mp->dst_address,
8616 ntohl(mp->outer_fib_id));
8619 static void vl_api_gre_tunnel_details_t_handler_json
8620 (vl_api_gre_tunnel_details_t * mp)
8622 vat_main_t * vam = &vat_main;
8623 vat_json_node_t *node = NULL;
8626 if (VAT_JSON_ARRAY != vam->json_tree.type) {
8627 ASSERT(VAT_JSON_NONE == vam->json_tree.type);
8628 vat_json_init_array(&vam->json_tree);
8630 node = vat_json_array_add(&vam->json_tree);
8632 vat_json_init_object(node);
8633 vat_json_object_add_uint(node, "sw_if_index", ntohl(mp->sw_if_index));
8634 clib_memcpy(&ip4, &mp->src_address, sizeof(ip4));
8635 vat_json_object_add_ip4(node, "src_address", ip4);
8636 clib_memcpy(&ip4, &mp->dst_address, sizeof(ip4));
8637 vat_json_object_add_ip4(node, "dst_address", ip4);
8638 vat_json_object_add_uint(node, "outer_fib_id", ntohl(mp->outer_fib_id));
8641 static int api_gre_tunnel_dump (vat_main_t * vam)
8643 unformat_input_t * i = vam->input;
8644 vl_api_gre_tunnel_dump_t *mp;
8647 u8 sw_if_index_set = 0;
8649 /* Parse args required to build the message */
8650 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
8651 if (unformat (i, "sw_if_index %d", &sw_if_index))
8652 sw_if_index_set = 1;
8657 if (sw_if_index_set == 0) {
8661 if (!vam->json_output) {
8662 fformat(vam->ofp, "%11s%15s%15s%14s\n",
8663 "sw_if_index", "src_address", "dst_address",
8667 /* Get list of gre-tunnel interfaces */
8668 M(GRE_TUNNEL_DUMP, gre_tunnel_dump);
8670 mp->sw_if_index = htonl(sw_if_index);
8674 /* Use a control ping for synchronization */
8676 vl_api_control_ping_t * mp;
8677 M(CONTROL_PING, control_ping);
8683 static int api_l2_fib_clear_table (vat_main_t * vam)
8685 // unformat_input_t * i = vam->input;
8686 vl_api_l2_fib_clear_table_t *mp;
8689 M(L2_FIB_CLEAR_TABLE, l2_fib_clear_table);
8696 static int api_l2_interface_efp_filter (vat_main_t * vam)
8698 unformat_input_t * i = vam->input;
8699 vl_api_l2_interface_efp_filter_t *mp;
8703 u8 sw_if_index_set = 0;
8705 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
8706 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
8707 sw_if_index_set = 1;
8708 else if (unformat (i, "sw_if_index %d", &sw_if_index))
8709 sw_if_index_set = 1;
8710 else if (unformat (i, "enable"))
8712 else if (unformat (i, "disable"))
8715 clib_warning ("parse error '%U'", format_unformat_error, i);
8720 if (sw_if_index_set == 0) {
8721 errmsg ("missing sw_if_index\n");
8725 M(L2_INTERFACE_EFP_FILTER, l2_interface_efp_filter);
8727 mp->sw_if_index = ntohl(sw_if_index);
8728 mp->enable_disable = enable;
8735 #define foreach_vtr_op \
8736 _("disable", L2_VTR_DISABLED) \
8737 _("push-1", L2_VTR_PUSH_1) \
8738 _("push-2", L2_VTR_PUSH_2) \
8739 _("pop-1", L2_VTR_POP_1) \
8740 _("pop-2", L2_VTR_POP_2) \
8741 _("translate-1-1", L2_VTR_TRANSLATE_1_1) \
8742 _("translate-1-2", L2_VTR_TRANSLATE_1_2) \
8743 _("translate-2-1", L2_VTR_TRANSLATE_2_1) \
8744 _("translate-2-2", L2_VTR_TRANSLATE_2_2)
8746 static int api_l2_interface_vlan_tag_rewrite (vat_main_t * vam)
8748 unformat_input_t * i = vam->input;
8749 vl_api_l2_interface_vlan_tag_rewrite_t *mp;
8752 u8 sw_if_index_set = 0;
8759 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
8760 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
8761 sw_if_index_set = 1;
8762 else if (unformat (i, "sw_if_index %d", &sw_if_index))
8763 sw_if_index_set = 1;
8764 else if (unformat (i, "vtr_op %d", &vtr_op))
8766 #define _(n,v) else if (unformat(i, n)) {vtr_op = v; vtr_op_set = 1;}
8770 else if (unformat (i, "push_dot1q %d", &push_dot1q))
8772 else if (unformat (i, "tag1 %d", &tag1))
8774 else if (unformat (i, "tag2 %d", &tag2))
8777 clib_warning ("parse error '%U'", format_unformat_error, i);
8782 if ((sw_if_index_set == 0)||(vtr_op_set == 0)) {
8783 errmsg ("missing vtr operation or sw_if_index\n");
8787 M(L2_INTERFACE_VLAN_TAG_REWRITE, l2_interface_vlan_tag_rewrite)
8789 mp->sw_if_index = ntohl(sw_if_index);
8790 mp->vtr_op = ntohl(vtr_op);
8791 mp->push_dot1q = ntohl(push_dot1q);
8792 mp->tag1 = ntohl(tag1);
8793 mp->tag2 = ntohl(tag2);
8800 static int api_create_vhost_user_if (vat_main_t * vam)
8802 unformat_input_t * i = vam->input;
8803 vl_api_create_vhost_user_if_t *mp;
8807 u8 file_name_set = 0;
8808 u32 custom_dev_instance = ~0;
8810 u8 use_custom_mac = 0;
8812 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
8813 if (unformat (i, "socket %s", &file_name)) {
8816 else if (unformat (i, "renumber %"PRIu32, &custom_dev_instance))
8818 else if (unformat (i, "mac %U", unformat_ethernet_address, hwaddr))
8820 else if (unformat (i, "server"))
8826 if (file_name_set == 0) {
8827 errmsg ("missing socket file name\n");
8831 if (vec_len (file_name) > 255) {
8832 errmsg ("socket file name too long\n");
8835 vec_add1 (file_name, 0);
8837 M(CREATE_VHOST_USER_IF, create_vhost_user_if);
8839 mp->is_server = is_server;
8840 clib_memcpy(mp->sock_filename, file_name, vec_len(file_name));
8841 vec_free(file_name);
8842 if (custom_dev_instance != ~0) {
8844 mp->custom_dev_instance = ntohl(custom_dev_instance);
8846 mp->use_custom_mac = use_custom_mac;
8847 clib_memcpy(mp->mac_address, hwaddr, 6);
8854 static int api_modify_vhost_user_if (vat_main_t * vam)
8856 unformat_input_t * i = vam->input;
8857 vl_api_modify_vhost_user_if_t *mp;
8861 u8 file_name_set = 0;
8862 u32 custom_dev_instance = ~0;
8863 u8 sw_if_index_set = 0;
8864 u32 sw_if_index = (u32)~0;
8866 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
8867 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
8868 sw_if_index_set = 1;
8869 else if (unformat (i, "sw_if_index %d", &sw_if_index))
8870 sw_if_index_set = 1;
8871 else if (unformat (i, "socket %s", &file_name)) {
8874 else if (unformat (i, "renumber %"PRIu32, &custom_dev_instance))
8876 else if (unformat (i, "server"))
8882 if (sw_if_index_set == 0) {
8883 errmsg ("missing sw_if_index or interface name\n");
8887 if (file_name_set == 0) {
8888 errmsg ("missing socket file name\n");
8892 if (vec_len (file_name) > 255) {
8893 errmsg ("socket file name too long\n");
8896 vec_add1 (file_name, 0);
8898 M(MODIFY_VHOST_USER_IF, modify_vhost_user_if);
8900 mp->sw_if_index = ntohl(sw_if_index);
8901 mp->is_server = is_server;
8902 clib_memcpy(mp->sock_filename, file_name, vec_len(file_name));
8903 vec_free(file_name);
8904 if (custom_dev_instance != ~0) {
8906 mp->custom_dev_instance = ntohl(custom_dev_instance);
8914 static int api_delete_vhost_user_if (vat_main_t * vam)
8916 unformat_input_t * i = vam->input;
8917 vl_api_delete_vhost_user_if_t *mp;
8919 u32 sw_if_index = ~0;
8920 u8 sw_if_index_set = 0;
8922 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
8923 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
8924 sw_if_index_set = 1;
8925 else if (unformat (i, "sw_if_index %d", &sw_if_index))
8926 sw_if_index_set = 1;
8931 if (sw_if_index_set == 0) {
8932 errmsg ("missing sw_if_index or interface name\n");
8937 M(DELETE_VHOST_USER_IF, delete_vhost_user_if);
8939 mp->sw_if_index = ntohl(sw_if_index);
8946 static void vl_api_sw_interface_vhost_user_details_t_handler
8947 (vl_api_sw_interface_vhost_user_details_t * mp)
8949 vat_main_t * vam = &vat_main;
8951 fformat(vam->ofp, "%-25s %3" PRIu32 " %6" PRIu32 " %8x %6d %7d %s\n",
8952 (char *)mp->interface_name,
8953 ntohl(mp->sw_if_index), ntohl(mp->virtio_net_hdr_sz),
8954 clib_net_to_host_u64(mp->features), mp->is_server,
8955 ntohl(mp->num_regions), (char *)mp->sock_filename);
8956 fformat(vam->ofp, " Status: '%s'\n", strerror(ntohl(mp->sock_errno)));
8959 static void vl_api_sw_interface_vhost_user_details_t_handler_json
8960 (vl_api_sw_interface_vhost_user_details_t * mp)
8962 vat_main_t * vam = &vat_main;
8963 vat_json_node_t *node = NULL;
8965 if (VAT_JSON_ARRAY != vam->json_tree.type) {
8966 ASSERT(VAT_JSON_NONE == vam->json_tree.type);
8967 vat_json_init_array(&vam->json_tree);
8969 node = vat_json_array_add(&vam->json_tree);
8971 vat_json_init_object(node);
8972 vat_json_object_add_uint(node, "sw_if_index", ntohl(mp->sw_if_index));
8973 vat_json_object_add_string_copy(node, "interface_name", mp->interface_name);
8974 vat_json_object_add_uint(node, "virtio_net_hdr_sz", ntohl(mp->virtio_net_hdr_sz));
8975 vat_json_object_add_uint(node, "features", clib_net_to_host_u64(mp->features));
8976 vat_json_object_add_uint(node, "is_server", mp->is_server);
8977 vat_json_object_add_string_copy(node, "sock_filename", mp->sock_filename);
8978 vat_json_object_add_uint(node, "num_regions", ntohl(mp->num_regions));
8979 vat_json_object_add_uint(node, "sock_errno", ntohl(mp->sock_errno));
8982 static int api_sw_interface_vhost_user_dump (vat_main_t * vam)
8984 vl_api_sw_interface_vhost_user_dump_t *mp;
8986 fformat(vam->ofp, "Interface name idx hdr_sz features server regions filename\n");
8988 /* Get list of vhost-user interfaces */
8989 M(SW_INTERFACE_VHOST_USER_DUMP, sw_interface_vhost_user_dump);
8992 /* Use a control ping for synchronization */
8994 vl_api_control_ping_t * mp;
8995 M(CONTROL_PING, control_ping);
9001 static int api_show_version (vat_main_t * vam)
9003 vl_api_show_version_t *mp;
9006 M(SHOW_VERSION, show_version);
9014 static int api_vxlan_gpe_add_del_tunnel (vat_main_t * vam)
9016 unformat_input_t * line_input = vam->input;
9017 vl_api_vxlan_gpe_add_del_tunnel_t *mp;
9019 ip4_address_t local4, remote4;
9020 ip6_address_t local6, remote6;
9022 u8 ipv4_set = 0, ipv6_set = 0;
9025 u32 encap_vrf_id = 0;
9026 u32 decap_vrf_id = 0;
9031 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) {
9032 if (unformat (line_input, "del"))
9034 else if (unformat (line_input, "local %U",
9035 unformat_ip4_address, &local4))
9040 else if (unformat (line_input, "remote %U",
9041 unformat_ip4_address, &remote4))
9046 else if (unformat (line_input, "local %U",
9047 unformat_ip6_address, &local6))
9052 else if (unformat (line_input, "remote %U",
9053 unformat_ip6_address, &remote6))
9058 else if (unformat (line_input, "encap-vrf-id %d", &encap_vrf_id))
9060 else if (unformat (line_input, "decap-vrf-id %d", &decap_vrf_id))
9062 else if (unformat (line_input, "vni %d", &vni))
9064 else if (unformat(line_input, "next-ip4"))
9066 else if (unformat(line_input, "next-ip6"))
9068 else if (unformat(line_input, "next-ethernet"))
9070 else if (unformat(line_input, "next-nsh"))
9073 errmsg ("parse error '%U'\n", format_unformat_error, line_input);
9078 if (local_set == 0) {
9079 errmsg ("tunnel local address not specified\n");
9082 if (remote_set == 0) {
9083 errmsg ("tunnel remote address not specified\n");
9086 if (ipv4_set && ipv6_set) {
9087 errmsg ("both IPv4 and IPv6 addresses specified");
9092 errmsg ("vni not specified\n");
9096 M(VXLAN_GPE_ADD_DEL_TUNNEL, vxlan_gpe_add_del_tunnel);
9100 clib_memcpy(&mp->local, &local6, sizeof(local6));
9101 clib_memcpy(&mp->remote, &remote6, sizeof(remote6));
9103 clib_memcpy(&mp->local, &local4, sizeof(local4));
9104 clib_memcpy(&mp->remote, &remote4, sizeof(remote4));
9107 mp->encap_vrf_id = ntohl(encap_vrf_id);
9108 mp->decap_vrf_id = ntohl(decap_vrf_id);
9109 mp->protocol = ntohl(protocol);
9110 mp->vni = ntohl(vni);
9111 mp->is_add = is_add;
9112 mp->is_ipv6 = ipv6_set;
9119 static void vl_api_vxlan_gpe_tunnel_details_t_handler
9120 (vl_api_vxlan_gpe_tunnel_details_t * mp)
9122 vat_main_t * vam = &vat_main;
9124 fformat(vam->ofp, "%11d%24U%24U%13d%12d%14d%14d\n",
9125 ntohl(mp->sw_if_index),
9126 format_ip46_address, &(mp->local[0]),
9127 format_ip46_address, &(mp->remote[0]),
9129 ntohl(mp->protocol),
9130 ntohl(mp->encap_vrf_id),
9131 ntohl(mp->decap_vrf_id));
9134 static void vl_api_vxlan_gpe_tunnel_details_t_handler_json
9135 (vl_api_vxlan_gpe_tunnel_details_t * mp)
9137 vat_main_t * vam = &vat_main;
9138 vat_json_node_t *node = NULL;
9140 struct in6_addr ip6;
9142 if (VAT_JSON_ARRAY != vam->json_tree.type) {
9143 ASSERT(VAT_JSON_NONE == vam->json_tree.type);
9144 vat_json_init_array(&vam->json_tree);
9146 node = vat_json_array_add(&vam->json_tree);
9148 vat_json_init_object(node);
9149 vat_json_object_add_uint(node, "sw_if_index", ntohl(mp->sw_if_index));
9151 clib_memcpy(&ip6, &(mp->local[0]), sizeof(ip6));
9152 vat_json_object_add_ip6(node, "local", ip6);
9153 clib_memcpy(&ip6, &(mp->remote[0]), sizeof(ip6));
9154 vat_json_object_add_ip6(node, "remote", ip6);
9156 clib_memcpy(&ip4, &(mp->local[0]), sizeof(ip4));
9157 vat_json_object_add_ip4(node, "local", ip4);
9158 clib_memcpy(&ip4, &(mp->remote[0]), sizeof(ip4));
9159 vat_json_object_add_ip4(node, "remote", ip4);
9161 vat_json_object_add_uint(node, "vni", ntohl(mp->vni));
9162 vat_json_object_add_uint(node, "protocol", ntohl(mp->protocol));
9163 vat_json_object_add_uint(node, "encap_vrf_id", ntohl(mp->encap_vrf_id));
9164 vat_json_object_add_uint(node, "decap_vrf_id", ntohl(mp->decap_vrf_id));
9165 vat_json_object_add_uint(node, "is_ipv6", mp->is_ipv6 ? 1 : 0);
9168 static int api_vxlan_gpe_tunnel_dump (vat_main_t * vam)
9170 unformat_input_t * i = vam->input;
9171 vl_api_vxlan_gpe_tunnel_dump_t *mp;
9174 u8 sw_if_index_set = 0;
9176 /* Parse args required to build the message */
9177 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
9178 if (unformat (i, "sw_if_index %d", &sw_if_index))
9179 sw_if_index_set = 1;
9184 if (sw_if_index_set == 0) {
9188 if (!vam->json_output) {
9189 fformat(vam->ofp, "%11s%24s%24s%13s%15s%14s%14s\n",
9190 "sw_if_index", "local", "remote", "vni",
9191 "protocol","encap_vrf_id", "decap_vrf_id");
9194 /* Get list of vxlan-tunnel interfaces */
9195 M(VXLAN_GPE_TUNNEL_DUMP, vxlan_gpe_tunnel_dump);
9197 mp->sw_if_index = htonl(sw_if_index);
9201 /* Use a control ping for synchronization */
9203 vl_api_control_ping_t * mp;
9204 M(CONTROL_PING, control_ping);
9210 u8 * format_l2_fib_mac_address (u8 * s, va_list * args)
9212 u8 * a = va_arg (*args, u8 *);
9214 return format (s, "%02x:%02x:%02x:%02x:%02x:%02x",
9215 a[2], a[3], a[4], a[5], a[6], a[7]);
9218 static void vl_api_l2_fib_table_entry_t_handler
9219 (vl_api_l2_fib_table_entry_t * mp)
9221 vat_main_t * vam = &vat_main;
9223 fformat(vam->ofp, "%3" PRIu32 " %U %3" PRIu32
9225 ntohl(mp->bd_id), format_l2_fib_mac_address, &mp->mac,
9226 ntohl(mp->sw_if_index), mp->static_mac, mp->filter_mac,
9230 static void vl_api_l2_fib_table_entry_t_handler_json
9231 (vl_api_l2_fib_table_entry_t * mp)
9233 vat_main_t * vam = &vat_main;
9234 vat_json_node_t *node = NULL;
9236 if (VAT_JSON_ARRAY != vam->json_tree.type) {
9237 ASSERT(VAT_JSON_NONE == vam->json_tree.type);
9238 vat_json_init_array(&vam->json_tree);
9240 node = vat_json_array_add(&vam->json_tree);
9242 vat_json_init_object(node);
9243 vat_json_object_add_uint(node, "bd_id", ntohl(mp->bd_id));
9244 vat_json_object_add_uint(node, "mac", clib_net_to_host_u64(mp->mac));
9245 vat_json_object_add_uint(node, "sw_if_index", ntohl(mp->sw_if_index));
9246 vat_json_object_add_uint(node, "static_mac", mp->static_mac);
9247 vat_json_object_add_uint(node, "filter_mac", mp->filter_mac);
9248 vat_json_object_add_uint(node, "bvi_mac", mp->bvi_mac);
9251 static int api_l2_fib_table_dump (vat_main_t * vam)
9253 unformat_input_t * i = vam->input;
9254 vl_api_l2_fib_table_dump_t *mp;
9259 /* Parse args required to build the message */
9260 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
9261 if (unformat (i, "bd_id %d", &bd_id))
9267 if (bd_id_set == 0) {
9268 errmsg ("missing bridge domain\n");
9272 fformat(vam->ofp, "BD-ID Mac Address sw-ndx Static Filter BVI\n");
9274 /* Get list of l2 fib entries */
9275 M(L2_FIB_TABLE_DUMP, l2_fib_table_dump);
9277 mp->bd_id = ntohl(bd_id);
9280 /* Use a control ping for synchronization */
9282 vl_api_control_ping_t * mp;
9283 M(CONTROL_PING, control_ping);
9291 api_interface_name_renumber (vat_main_t * vam)
9293 unformat_input_t * line_input = vam->input;
9294 vl_api_interface_name_renumber_t *mp;
9295 u32 sw_if_index = ~0;
9297 u32 new_show_dev_instance = ~0;
9299 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) {
9300 if (unformat (line_input, "%U", unformat_sw_if_index, vam,
9303 else if (unformat (line_input, "sw_if_index %d", &sw_if_index))
9305 else if (unformat (line_input, "new_show_dev_instance %d",
9306 &new_show_dev_instance))
9312 if (sw_if_index == ~0) {
9313 errmsg ("missing interface name or sw_if_index\n");
9317 if (new_show_dev_instance == ~0) {
9318 errmsg ("missing new_show_dev_instance\n");
9322 M(INTERFACE_NAME_RENUMBER, interface_name_renumber);
9324 mp->sw_if_index = ntohl (sw_if_index);
9325 mp->new_show_dev_instance = ntohl (new_show_dev_instance);
9331 api_want_ip4_arp_events (vat_main_t * vam)
9333 unformat_input_t * line_input = vam->input;
9334 vl_api_want_ip4_arp_events_t * mp;
9336 ip4_address_t address;
9337 int address_set = 0;
9338 u32 enable_disable = 1;
9340 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) {
9341 if (unformat (line_input, "address %U",
9342 unformat_ip4_address, &address))
9344 else if (unformat (line_input, "del"))
9350 if (address_set == 0) {
9351 errmsg ("missing addresses\n");
9355 M(WANT_IP4_ARP_EVENTS, want_ip4_arp_events);
9356 mp->enable_disable = enable_disable;
9358 mp->address = address.as_u32;
9363 static int api_input_acl_set_interface (vat_main_t * vam)
9365 unformat_input_t * i = vam->input;
9366 vl_api_input_acl_set_interface_t *mp;
9369 int sw_if_index_set;
9370 u32 ip4_table_index = ~0;
9371 u32 ip6_table_index = ~0;
9372 u32 l2_table_index = ~0;
9375 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
9376 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
9377 sw_if_index_set = 1;
9378 else if (unformat (i, "sw_if_index %d", &sw_if_index))
9379 sw_if_index_set = 1;
9380 else if (unformat (i, "del"))
9382 else if (unformat (i, "ip4-table %d", &ip4_table_index))
9384 else if (unformat (i, "ip6-table %d", &ip6_table_index))
9386 else if (unformat (i, "l2-table %d", &l2_table_index))
9389 clib_warning ("parse error '%U'", format_unformat_error, i);
9394 if (sw_if_index_set == 0) {
9395 errmsg ("missing interface name or sw_if_index\n");
9399 M(INPUT_ACL_SET_INTERFACE, input_acl_set_interface);
9401 mp->sw_if_index = ntohl(sw_if_index);
9402 mp->ip4_table_index = ntohl(ip4_table_index);
9403 mp->ip6_table_index = ntohl(ip6_table_index);
9404 mp->l2_table_index = ntohl(l2_table_index);
9405 mp->is_add = is_add;
9413 api_ip_address_dump (vat_main_t * vam)
9415 unformat_input_t * i = vam->input;
9416 vl_api_ip_address_dump_t * mp;
9417 u32 sw_if_index = ~0;
9418 u8 sw_if_index_set = 0;
9423 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
9424 if (unformat (i, "sw_if_index %d", &sw_if_index))
9425 sw_if_index_set = 1;
9426 else if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
9427 sw_if_index_set = 1;
9428 else if (unformat (i, "ipv4"))
9430 else if (unformat (i, "ipv6"))
9436 if (ipv4_set && ipv6_set) {
9437 errmsg ("ipv4 and ipv6 flags cannot be both set\n");
9441 if ((!ipv4_set) && (!ipv6_set)) {
9442 errmsg ("no ipv4 nor ipv6 flag set\n");
9446 if (sw_if_index_set == 0) {
9447 errmsg ("missing interface name or sw_if_index\n");
9451 vam->current_sw_if_index = sw_if_index;
9452 vam->is_ipv6 = ipv6_set;
9454 M(IP_ADDRESS_DUMP, ip_address_dump);
9455 mp->sw_if_index = ntohl(sw_if_index);
9456 mp->is_ipv6 = ipv6_set;
9459 /* Use a control ping for synchronization */
9461 vl_api_control_ping_t * mp;
9462 M(CONTROL_PING, control_ping);
9469 api_ip_dump (vat_main_t * vam)
9471 vl_api_ip_dump_t * mp;
9472 unformat_input_t * in = vam->input;
9479 while (unformat_check_input (in) != UNFORMAT_END_OF_INPUT) {
9480 if (unformat (in, "ipv4"))
9482 else if (unformat (in, "ipv6"))
9488 if (ipv4_set && ipv6_set) {
9489 errmsg ("ipv4 and ipv6 flags cannot be both set\n");
9493 if ((!ipv4_set) && (!ipv6_set)) {
9494 errmsg ("no ipv4 nor ipv6 flag set\n");
9499 vam->is_ipv6 = is_ipv6;
9502 for (i = 0; i < vec_len(vam->ip_details_by_sw_if_index[is_ipv6]); i++) {
9503 vec_free(vam->ip_details_by_sw_if_index[is_ipv6][i].addr);
9505 vec_free(vam->ip_details_by_sw_if_index[is_ipv6]);
9507 M(IP_DUMP, ip_dump);
9508 mp->is_ipv6 = ipv6_set;
9511 /* Use a control ping for synchronization */
9513 vl_api_control_ping_t * mp;
9514 M(CONTROL_PING, control_ping);
9521 api_ipsec_spd_add_del (vat_main_t * vam)
9524 unformat_input_t * i = vam->input;
9525 vl_api_ipsec_spd_add_del_t *mp;
9530 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
9531 if (unformat (i, "spd_id %d", &spd_id))
9533 else if (unformat (i, "del"))
9536 clib_warning ("parse error '%U'", format_unformat_error, i);
9541 errmsg ("spd_id must be set\n");
9545 M(IPSEC_SPD_ADD_DEL, ipsec_spd_add_del);
9547 mp->spd_id = ntohl(spd_id);
9548 mp->is_add = is_add;
9554 clib_warning ("unsupported (no dpdk)");
9560 api_ipsec_interface_add_del_spd (vat_main_t * vam)
9563 unformat_input_t * i = vam->input;
9564 vl_api_ipsec_interface_add_del_spd_t *mp;
9567 u8 sw_if_index_set = 0;
9568 u32 spd_id = (u32) ~0;
9571 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
9572 if (unformat (i, "del"))
9574 else if (unformat (i, "spd_id %d", &spd_id))
9576 else if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
9577 sw_if_index_set = 1;
9578 else if (unformat (i, "sw_if_index %d", &sw_if_index))
9579 sw_if_index_set = 1;
9581 clib_warning ("parse error '%U'", format_unformat_error, i);
9587 if (spd_id == (u32) ~0) {
9588 errmsg ("spd_id must be set\n");
9592 if (sw_if_index_set == 0) {
9593 errmsg ("missing interface name or sw_if_index\n");
9597 M(IPSEC_INTERFACE_ADD_DEL_SPD, ipsec_interface_add_del_spd);
9599 mp->spd_id = ntohl(spd_id);
9600 mp->sw_if_index = ntohl (sw_if_index);
9601 mp->is_add = is_add;
9607 clib_warning ("unsupported (no dpdk)");
9613 api_ipsec_spd_add_del_entry (vat_main_t * vam)
9616 unformat_input_t * i = vam->input;
9617 vl_api_ipsec_spd_add_del_entry_t *mp;
9619 u8 is_add = 1, is_outbound = 0, is_ipv6 = 0, is_ip_any = 1;
9620 u32 spd_id, sa_id, protocol = 0, policy = 0;
9622 u32 rport_start = 0, rport_stop = (u32) ~0;
9623 u32 lport_start = 0, lport_stop = (u32) ~0;
9624 ip4_address_t laddr4_start, laddr4_stop, raddr4_start, raddr4_stop;
9625 ip6_address_t laddr6_start, laddr6_stop, raddr6_start, raddr6_stop;
9627 laddr4_start.as_u32 = raddr4_start.as_u32 = 0;
9628 laddr4_stop.as_u32 = raddr4_stop.as_u32 = (u32) ~0;
9629 laddr6_start.as_u64[0] = raddr6_start.as_u64[0] = 0;
9630 laddr6_start.as_u64[1] = raddr6_start.as_u64[1] = 0;
9631 laddr6_stop.as_u64[0] = raddr6_stop.as_u64[0] = (u64) ~0;
9632 laddr6_stop.as_u64[1] = raddr6_stop.as_u64[1] = (u64) ~0;
9634 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
9635 if (unformat (i, "del"))
9637 if (unformat (i, "outbound"))
9639 if (unformat (i, "inbound"))
9641 else if (unformat (i, "spd_id %d", &spd_id))
9643 else if (unformat (i, "sa_id %d", &sa_id))
9645 else if (unformat (i, "priority %d", &priority))
9647 else if (unformat (i, "protocol %d", &protocol))
9649 else if (unformat (i, "lport_start %d", &lport_start))
9651 else if (unformat (i, "lport_stop %d", &lport_stop))
9653 else if (unformat (i, "rport_start %d", &rport_start))
9655 else if (unformat (i, "rport_stop %d", &rport_stop))
9657 else if (unformat (i, "laddr_start %U", unformat_ip4_address, &laddr4_start))
9662 else if (unformat (i, "laddr_stop %U", unformat_ip4_address, &laddr4_stop))
9667 else if (unformat (i, "raddr_start %U", unformat_ip4_address, &raddr4_start))
9672 else if (unformat (i, "raddr_stop %U", unformat_ip4_address, &raddr4_stop))
9677 else if (unformat (i, "laddr_start %U", unformat_ip6_address, &laddr6_start))
9682 else if (unformat (i, "laddr_stop %U", unformat_ip6_address, &laddr6_stop))
9687 else if (unformat (i, "raddr_start %U", unformat_ip6_address, &raddr6_start))
9692 else if (unformat (i, "raddr_stop %U", unformat_ip6_address, &raddr6_stop))
9697 else if (unformat (i, "action %U", unformat_ipsec_policy_action, &policy))
9699 if (policy == IPSEC_POLICY_ACTION_RESOLVE) {
9700 clib_warning ("unsupported action: 'resolve'");
9705 clib_warning ("parse error '%U'", format_unformat_error, i);
9711 M(IPSEC_SPD_ADD_DEL_ENTRY, ipsec_spd_add_del_entry);
9713 mp->spd_id = ntohl(spd_id);
9714 mp->priority = ntohl(priority);
9715 mp->is_outbound = is_outbound;
9717 mp->is_ipv6 = is_ipv6;
9718 if (is_ipv6 || is_ip_any) {
9719 clib_memcpy (mp->remote_address_start, &raddr6_start, sizeof(ip6_address_t));
9720 clib_memcpy (mp->remote_address_stop, &raddr6_stop, sizeof(ip6_address_t));
9721 clib_memcpy (mp->local_address_start, &laddr6_start, sizeof(ip6_address_t));
9722 clib_memcpy (mp->local_address_stop, &laddr6_stop, sizeof(ip6_address_t));
9724 clib_memcpy (mp->remote_address_start, &raddr4_start, sizeof(ip4_address_t));
9725 clib_memcpy (mp->remote_address_stop, &raddr4_stop, sizeof(ip4_address_t));
9726 clib_memcpy (mp->local_address_start, &laddr4_start, sizeof(ip4_address_t));
9727 clib_memcpy (mp->local_address_stop, &laddr4_stop, sizeof(ip4_address_t));
9729 mp->protocol = (u8) protocol;
9730 mp->local_port_start = ntohs((u16) lport_start);
9731 mp->local_port_stop = ntohs((u16) lport_stop);
9732 mp->remote_port_start = ntohs((u16) rport_start);
9733 mp->remote_port_stop = ntohs((u16) rport_stop);
9734 mp->policy = (u8) policy;
9735 mp->sa_id = ntohl(sa_id);
9736 mp->is_add = is_add;
9737 mp->is_ip_any = is_ip_any;
9742 clib_warning ("unsupported (no dpdk)");
9748 api_ipsec_sad_add_del_entry (vat_main_t * vam)
9751 unformat_input_t * i = vam->input;
9752 vl_api_ipsec_sad_add_del_entry_t *mp;
9755 u8 * ck = 0, * ik = 0;
9758 u8 protocol = IPSEC_PROTOCOL_AH;
9759 u8 is_tunnel = 0, is_tunnel_ipv6 = 0;
9760 u32 crypto_alg = 0, integ_alg = 0;
9761 ip4_address_t tun_src4;
9762 ip4_address_t tun_dst4;
9763 ip6_address_t tun_src6;
9764 ip6_address_t tun_dst6;
9766 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
9767 if (unformat (i, "del"))
9769 else if (unformat (i, "sad_id %d", &sad_id))
9771 else if (unformat (i, "spi %d", &spi))
9773 else if (unformat (i, "esp"))
9774 protocol = IPSEC_PROTOCOL_ESP;
9775 else if (unformat (i, "tunnel_src %U", unformat_ip4_address, &tun_src4)) {
9779 else if (unformat (i, "tunnel_dst %U", unformat_ip4_address, &tun_dst4)) {
9783 else if (unformat (i, "tunnel_src %U", unformat_ip6_address, &tun_src6)) {
9787 else if (unformat (i, "tunnel_dst %U", unformat_ip6_address, &tun_dst6)) {
9791 else if (unformat (i, "crypto_alg %U", unformat_ipsec_crypto_alg, &crypto_alg)) {
9792 if (crypto_alg < IPSEC_CRYPTO_ALG_AES_CBC_128 ||
9793 crypto_alg > IPSEC_INTEG_ALG_SHA_512_256) {
9794 clib_warning ("unsupported crypto-alg: '%U'",
9795 format_ipsec_crypto_alg, crypto_alg);
9799 else if (unformat (i, "crypto_key %U", unformat_hex_string, &ck))
9801 else if (unformat (i, "integ_alg %U", unformat_ipsec_integ_alg, &integ_alg)) {
9802 if (integ_alg < IPSEC_INTEG_ALG_SHA1_96 ||
9803 integ_alg > IPSEC_INTEG_ALG_SHA_512_256) {
9804 clib_warning ("unsupported integ-alg: '%U'",
9805 format_ipsec_integ_alg, integ_alg);
9809 else if (unformat (i, "integ_key %U", unformat_hex_string, &ik))
9812 clib_warning ("parse error '%U'", format_unformat_error, i);
9818 M(IPSEC_SAD_ADD_DEL_ENTRY, ipsec_sad_add_del_entry);
9820 mp->sad_id = ntohl(sad_id);
9821 mp->is_add = is_add;
9822 mp->protocol = protocol;
9823 mp->spi = ntohl(spi);
9824 mp->is_tunnel = is_tunnel;
9825 mp->is_tunnel_ipv6 = is_tunnel_ipv6;
9826 mp->crypto_algorithm = crypto_alg;
9827 mp->integrity_algorithm = integ_alg;
9828 mp->crypto_key_length = vec_len(ck);
9829 mp->integrity_key_length = vec_len(ik);
9831 if (mp->crypto_key_length > sizeof(mp->crypto_key))
9832 mp->crypto_key_length = sizeof(mp->crypto_key);
9834 if (mp->integrity_key_length > sizeof(mp->integrity_key))
9835 mp->integrity_key_length = sizeof(mp->integrity_key);
9837 clib_memcpy (mp->crypto_key, ck, mp->crypto_key_length);
9838 clib_memcpy (mp->integrity_key, ik, mp->integrity_key_length);
9841 if (is_tunnel_ipv6) {
9842 clib_memcpy (mp->tunnel_src_address, &tun_src6, sizeof(ip6_address_t));
9843 clib_memcpy (mp->tunnel_dst_address, &tun_dst6, sizeof(ip6_address_t));
9845 clib_memcpy (mp->tunnel_src_address, &tun_src4, sizeof(ip4_address_t));
9846 clib_memcpy (mp->tunnel_dst_address, &tun_dst4, sizeof(ip4_address_t));
9854 clib_warning ("unsupported (no dpdk)");
9860 api_ipsec_sa_set_key (vat_main_t * vam)
9863 unformat_input_t * i = vam->input;
9864 vl_api_ipsec_sa_set_key_t *mp;
9867 u8 * ck = 0, * ik = 0;
9869 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
9870 if (unformat (i, "sa_id %d", &sa_id))
9872 else if (unformat (i, "crypto_key %U", unformat_hex_string, &ck))
9874 else if (unformat (i, "integ_key %U", unformat_hex_string, &ik))
9877 clib_warning ("parse error '%U'", format_unformat_error, i);
9882 M(IPSEC_SA_SET_KEY, ipsec_set_sa_key);
9884 mp->sa_id = ntohl(sa_id);
9885 mp->crypto_key_length = vec_len(ck);
9886 mp->integrity_key_length = vec_len(ik);
9888 if (mp->crypto_key_length > sizeof(mp->crypto_key))
9889 mp->crypto_key_length = sizeof(mp->crypto_key);
9891 if (mp->integrity_key_length > sizeof(mp->integrity_key))
9892 mp->integrity_key_length = sizeof(mp->integrity_key);
9894 clib_memcpy (mp->crypto_key, ck, mp->crypto_key_length);
9895 clib_memcpy (mp->integrity_key, ik, mp->integrity_key_length);
9901 clib_warning ("unsupported (no dpdk)");
9907 api_ikev2_profile_add_del (vat_main_t * vam)
9910 unformat_input_t * i = vam->input;
9911 vl_api_ikev2_profile_add_del_t * mp;
9916 const char * valid_chars = "a-zA-Z0-9_";
9918 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
9919 if (unformat (i, "del"))
9921 else if (unformat (i, "name %U", unformat_token, valid_chars, &name))
9924 errmsg ("parse error '%U'", format_unformat_error, i);
9929 if (!vec_len (name)) {
9930 errmsg ("profile name must be specified");
9934 if (vec_len (name) > 64) {
9935 errmsg ("profile name too long");
9939 M(IKEV2_PROFILE_ADD_DEL, ikev2_profile_add_del);
9941 clib_memcpy(mp->name, name, vec_len (name));
9942 mp->is_add = is_add;
9949 clib_warning ("unsupported (no dpdk)");
9955 api_ikev2_profile_set_auth (vat_main_t * vam)
9958 unformat_input_t * i = vam->input;
9959 vl_api_ikev2_profile_set_auth_t * mp;
9963 u32 auth_method = 0;
9966 const char * valid_chars = "a-zA-Z0-9_";
9968 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
9969 if (unformat (i, "name %U", unformat_token, valid_chars, &name))
9971 else if (unformat (i, "auth_method %U",
9972 unformat_ikev2_auth_method, &auth_method))
9974 else if (unformat (i, "auth_data 0x%U", unformat_hex_string, &data))
9976 else if (unformat (i, "auth_data %v", &data))
9979 errmsg ("parse error '%U'", format_unformat_error, i);
9984 if (!vec_len (name)) {
9985 errmsg ("profile name must be specified");
9989 if (vec_len (name) > 64) {
9990 errmsg ("profile name too long");
9994 if (!vec_len(data)) {
9995 errmsg ("auth_data must be specified");
10000 errmsg ("auth_method must be specified");
10004 M(IKEV2_PROFILE_SET_AUTH, ikev2_profile_set_auth);
10006 mp->is_hex = is_hex;
10007 mp->auth_method = (u8) auth_method;
10008 mp->data_len = vec_len (data);
10009 clib_memcpy (mp->name, name, vec_len (name));
10010 clib_memcpy (mp->data, data, vec_len (data));
10018 clib_warning ("unsupported (no dpdk)");
10024 api_ikev2_profile_set_id (vat_main_t * vam)
10027 unformat_input_t * i = vam->input;
10028 vl_api_ikev2_profile_set_id_t * mp;
10036 const char * valid_chars = "a-zA-Z0-9_";
10038 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
10039 if (unformat (i, "name %U", unformat_token, valid_chars, &name))
10040 vec_add1 (name, 0);
10041 else if (unformat (i, "id_type %U",
10042 unformat_ikev2_id_type, &id_type))
10044 else if (unformat (i, "id_data %U", unformat_ip4_address, &ip4))
10046 data = vec_new(u8, 4);
10047 clib_memcpy(data, ip4.as_u8, 4);
10049 else if (unformat (i, "id_data 0x%U", unformat_hex_string, &data))
10051 else if (unformat (i, "id_data %v", &data))
10053 else if (unformat (i, "local"))
10055 else if (unformat (i, "remote"))
10058 errmsg ("parse error '%U'", format_unformat_error, i);
10063 if (!vec_len (name)) {
10064 errmsg ("profile name must be specified");
10068 if (vec_len (name) > 64) {
10069 errmsg ("profile name too long");
10073 if (!vec_len(data)) {
10074 errmsg ("id_data must be specified");
10079 errmsg ("id_type must be specified");
10083 M(IKEV2_PROFILE_SET_ID, ikev2_profile_set_id);
10085 mp->is_local = is_local;
10086 mp->id_type = (u8) id_type;
10087 mp->data_len = vec_len (data);
10088 clib_memcpy (mp->name, name, vec_len (name));
10089 clib_memcpy (mp->data, data, vec_len (data));
10097 clib_warning ("unsupported (no dpdk)");
10103 api_ikev2_profile_set_ts (vat_main_t * vam)
10106 unformat_input_t * i = vam->input;
10107 vl_api_ikev2_profile_set_ts_t * mp;
10111 u32 proto = 0, start_port = 0, end_port = (u32) ~0;
10112 ip4_address_t start_addr, end_addr;
10114 const char * valid_chars = "a-zA-Z0-9_";
10116 start_addr.as_u32 = 0;
10117 end_addr.as_u32 = (u32) ~0;
10119 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
10120 if (unformat (i, "name %U", unformat_token, valid_chars, &name))
10121 vec_add1 (name, 0);
10122 else if (unformat (i, "protocol %d", &proto))
10124 else if (unformat (i, "start_port %d", &start_port))
10126 else if (unformat (i, "end_port %d", &end_port))
10128 else if (unformat (i, "start_addr %U", unformat_ip4_address, &start_addr))
10130 else if (unformat (i, "end_addr %U", unformat_ip4_address, &end_addr))
10132 else if (unformat (i, "local"))
10134 else if (unformat (i, "remote"))
10137 errmsg ("parse error '%U'", format_unformat_error, i);
10142 if (!vec_len (name)) {
10143 errmsg ("profile name must be specified");
10147 if (vec_len (name) > 64) {
10148 errmsg ("profile name too long");
10152 M(IKEV2_PROFILE_SET_TS, ikev2_profile_set_ts);
10154 mp->is_local = is_local;
10155 mp->proto = (u8) proto;
10156 mp->start_port = (u16) start_port;
10157 mp->end_port = (u16) end_port;
10158 mp->start_addr = start_addr.as_u32;
10159 mp->end_addr = end_addr.as_u32;
10160 clib_memcpy (mp->name, name, vec_len (name));
10167 clib_warning ("unsupported (no dpdk)");
10173 api_ikev2_set_local_key (vat_main_t * vam)
10176 unformat_input_t * i = vam->input;
10177 vl_api_ikev2_set_local_key_t * mp;
10181 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
10182 if (unformat (i, "file %v", &file))
10183 vec_add1 (file, 0);
10185 errmsg ("parse error '%U'", format_unformat_error, i);
10190 if (!vec_len (file)) {
10191 errmsg ("RSA key file must be specified");
10195 if (vec_len (file) > 256) {
10196 errmsg ("file name too long");
10200 M(IKEV2_SET_LOCAL_KEY, ikev2_set_local_key);
10202 clib_memcpy (mp->key_file, file, vec_len (file));
10209 clib_warning ("unsupported (no dpdk)");
10217 static int api_map_add_domain (vat_main_t * vam)
10219 unformat_input_t *i = vam->input;
10220 vl_api_map_add_domain_t *mp;
10223 ip4_address_t ip4_prefix;
10224 ip6_address_t ip6_prefix;
10225 ip6_address_t ip6_src;
10226 u32 num_m_args = 0;
10227 u32 ip6_prefix_len, ip4_prefix_len, ea_bits_len, psid_offset,
10229 u8 is_translation = 0;
10231 u8 ip6_src_len = 128;
10233 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
10234 if (unformat (i, "ip4-pfx %U/%d", unformat_ip4_address,
10235 &ip4_prefix, &ip4_prefix_len))
10237 else if (unformat (i, "ip6-pfx %U/%d", unformat_ip6_address,
10238 &ip6_prefix, &ip6_prefix_len))
10240 else if (unformat (i, "ip6-src %U/%d", unformat_ip6_address, &ip6_src, &ip6_src_len))
10242 else if (unformat (i, "ip6-src %U", unformat_ip6_address, &ip6_src))
10244 else if (unformat (i, "ea-bits-len %d", &ea_bits_len))
10246 else if (unformat (i, "psid-offset %d", &psid_offset))
10248 else if (unformat (i, "psid-len %d", &psid_length))
10250 else if (unformat (i, "mtu %d", &mtu))
10252 else if (unformat (i, "map-t"))
10253 is_translation = 1;
10255 clib_warning ("parse error '%U'", format_unformat_error, i);
10260 if (num_m_args != 6) {
10261 errmsg("mandatory argument(s) missing\n");
10265 /* Construct the API message */
10266 M(MAP_ADD_DOMAIN, map_add_domain);
10268 clib_memcpy(mp->ip4_prefix, &ip4_prefix, sizeof(ip4_prefix));
10269 mp->ip4_prefix_len = ip4_prefix_len;
10271 clib_memcpy(mp->ip6_prefix, &ip6_prefix, sizeof(ip6_prefix));
10272 mp->ip6_prefix_len = ip6_prefix_len;
10274 clib_memcpy(mp->ip6_src, &ip6_src, sizeof(ip6_src));
10275 mp->ip6_src_prefix_len = ip6_src_len;
10277 mp->ea_bits_len = ea_bits_len;
10278 mp->psid_offset = psid_offset;
10279 mp->psid_length = psid_length;
10280 mp->is_translation = is_translation;
10281 mp->mtu = htons(mtu);
10286 /* Wait for a reply, return good/bad news */
10290 static int api_map_del_domain (vat_main_t * vam)
10292 unformat_input_t *i = vam->input;
10293 vl_api_map_del_domain_t *mp;
10296 u32 num_m_args = 0;
10299 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
10300 if (unformat (i, "index %d", &index))
10303 clib_warning ("parse error '%U'", format_unformat_error, i);
10308 if (num_m_args != 1) {
10309 errmsg("mandatory argument(s) missing\n");
10313 /* Construct the API message */
10314 M(MAP_DEL_DOMAIN, map_del_domain);
10316 mp->index = ntohl(index);
10321 /* Wait for a reply, return good/bad news */
10325 static int api_map_add_del_rule (vat_main_t * vam)
10327 unformat_input_t *i = vam->input;
10328 vl_api_map_add_del_rule_t *mp;
10331 ip6_address_t ip6_dst;
10332 u32 num_m_args = 0, index, psid;
10334 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
10335 if (unformat (i, "index %d", &index))
10337 else if (unformat (i, "psid %d", &psid))
10339 else if (unformat (i, "dst %U", unformat_ip6_address, &ip6_dst))
10341 else if (unformat (i, "del")) {
10344 clib_warning ("parse error '%U'", format_unformat_error, i);
10349 /* Construct the API message */
10350 M(MAP_ADD_DEL_RULE, map_add_del_rule);
10352 mp->index = ntohl(index);
10353 mp->is_add = is_add;
10354 clib_memcpy(mp->ip6_dst, &ip6_dst, sizeof(ip6_dst));
10355 mp->psid = ntohs(psid);
10360 /* Wait for a reply, return good/bad news */
10364 static int api_map_domain_dump (vat_main_t * vam)
10366 vl_api_map_domain_dump_t *mp;
10369 /* Construct the API message */
10370 M(MAP_DOMAIN_DUMP, map_domain_dump);
10375 /* Use a control ping for synchronization */
10377 vl_api_control_ping_t * mp;
10378 M(CONTROL_PING, control_ping);
10384 static int api_map_rule_dump (vat_main_t * vam)
10386 unformat_input_t *i = vam->input;
10387 vl_api_map_rule_dump_t *mp;
10389 u32 domain_index = ~0;
10391 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
10392 if (unformat (i, "index %u", &domain_index))
10398 if (domain_index == ~0) {
10399 clib_warning("parse error: domain index expected");
10403 /* Construct the API message */
10404 M(MAP_RULE_DUMP, map_rule_dump);
10406 mp->domain_index = htonl(domain_index);
10411 /* Use a control ping for synchronization */
10413 vl_api_control_ping_t * mp;
10414 M(CONTROL_PING, control_ping);
10420 static void vl_api_map_add_domain_reply_t_handler
10421 (vl_api_map_add_domain_reply_t * mp)
10423 vat_main_t * vam = &vat_main;
10424 i32 retval = ntohl(mp->retval);
10426 if (vam->async_mode) {
10427 vam->async_errors += (retval < 0);
10429 vam->retval = retval;
10430 vam->result_ready = 1;
10434 static void vl_api_map_add_domain_reply_t_handler_json
10435 (vl_api_map_add_domain_reply_t * mp)
10437 vat_main_t * vam = &vat_main;
10438 vat_json_node_t node;
10440 vat_json_init_object(&node);
10441 vat_json_object_add_int(&node, "retval", ntohl(mp->retval));
10442 vat_json_object_add_uint(&node, "index", ntohl(mp->index));
10444 vat_json_print(vam->ofp, &node);
10445 vat_json_free(&node);
10447 vam->retval = ntohl(mp->retval);
10448 vam->result_ready = 1;
10452 api_get_first_msg_id (vat_main_t * vam)
10454 vl_api_get_first_msg_id_t * mp;
10456 unformat_input_t * i = vam->input;
10460 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
10461 if (unformat (i, "client %s", &name))
10467 if (name_set == 0) {
10468 errmsg ("missing client name\n");
10471 vec_add1 (name, 0);
10473 if (vec_len (name) > 63) {
10474 errmsg ("client name too long\n");
10478 M(GET_FIRST_MSG_ID, get_first_msg_id);
10479 clib_memcpy (mp->name, name, vec_len(name));
10485 static int api_cop_interface_enable_disable (vat_main_t * vam)
10487 unformat_input_t * line_input = vam->input;
10488 vl_api_cop_interface_enable_disable_t * mp;
10490 u32 sw_if_index = ~0;
10491 u8 enable_disable = 1;
10493 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) {
10494 if (unformat (line_input, "disable"))
10495 enable_disable = 0;
10496 if (unformat (line_input, "enable"))
10497 enable_disable = 1;
10498 else if (unformat (line_input, "%U", unformat_sw_if_index,
10499 vam, &sw_if_index))
10501 else if (unformat (line_input, "sw_if_index %d", &sw_if_index))
10507 if (sw_if_index == ~0) {
10508 errmsg ("missing interface name or sw_if_index\n");
10512 /* Construct the API message */
10513 M(COP_INTERFACE_ENABLE_DISABLE, cop_interface_enable_disable);
10514 mp->sw_if_index = ntohl(sw_if_index);
10515 mp->enable_disable = enable_disable;
10519 /* Wait for the reply */
10523 static int api_cop_whitelist_enable_disable (vat_main_t * vam)
10525 unformat_input_t * line_input = vam->input;
10526 vl_api_cop_whitelist_enable_disable_t * mp;
10528 u32 sw_if_index = ~0;
10529 u8 ip4=0, ip6=0, default_cop=0;
10532 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) {
10533 if (unformat (line_input, "ip4"))
10535 else if (unformat (line_input, "ip6"))
10537 else if (unformat (line_input, "default"))
10539 else if (unformat (line_input, "%U", unformat_sw_if_index,
10540 vam, &sw_if_index))
10542 else if (unformat (line_input, "sw_if_index %d", &sw_if_index))
10544 else if (unformat (line_input, "fib-id %d", &fib_id))
10550 if (sw_if_index == ~0) {
10551 errmsg ("missing interface name or sw_if_index\n");
10555 /* Construct the API message */
10556 M(COP_WHITELIST_ENABLE_DISABLE, cop_whitelist_enable_disable);
10557 mp->sw_if_index = ntohl(sw_if_index);
10558 mp->fib_id = ntohl(fib_id);
10561 mp->default_cop = default_cop;
10565 /* Wait for the reply */
10569 static int api_get_node_graph (vat_main_t * vam)
10571 vl_api_get_node_graph_t * mp;
10574 M(GET_NODE_GRAPH, get_node_graph);
10578 /* Wait for the reply */
10582 /** Used for parsing LISP eids */
10583 typedef CLIB_PACKED(struct{
10584 u8 addr[16]; /**< eid address */
10585 u32 len; /**< prefix length if IP */
10586 u8 type; /**< type of eid */
10590 unformat_lisp_eid_vat (unformat_input_t * input, va_list * args)
10592 lisp_eid_vat_t * a = va_arg(*args, lisp_eid_vat_t *);
10594 memset(a, 0, sizeof(a[0]));
10596 if (unformat (input, "%U/%d", unformat_ip4_address, a->addr, &a->len)) {
10597 a->type = 0; /* ipv4 type */
10598 } else if (unformat (input, "%U/%d", unformat_ip6_address, a->addr,
10600 a->type = 1; /* ipv6 type */
10601 } else if (unformat (input, "%U", unformat_ethernet_address, a->addr)) {
10602 a->type = 2; /* mac type */
10607 if ((a->type == 0 && a->len > 32) || (a->type == 1 && a->len > 128)) {
10615 lisp_eid_size_vat (u8 type)
10629 lisp_eid_put_vat (u8 * dst, u8 eid[16], u8 type)
10631 clib_memcpy(dst, eid, lisp_eid_size_vat(type));
10634 /** Used for transferring locators via VPP API */
10635 typedef CLIB_PACKED(struct
10637 u32 sw_if_index; /**< locator sw_if_index */
10638 u8 priority; /**< locator priority */
10639 u8 weight; /**< locator weight */
10643 api_lisp_add_del_locator_set(vat_main_t * vam)
10645 unformat_input_t * input = vam->input;
10646 vl_api_lisp_add_del_locator_set_t *mp;
10649 u8 *locator_set_name = NULL;
10650 u8 locator_set_name_set = 0;
10651 ls_locator_t locator, * locators = 0;
10652 u32 sw_if_index, priority, weight;
10654 /* Parse args required to build the message */
10655 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) {
10656 if (unformat(input, "del")) {
10658 } else if (unformat(input, "locator-set %s", &locator_set_name)) {
10659 locator_set_name_set = 1;
10660 } else if (unformat(input, "sw_if_index %u p %u w %u",
10661 &sw_if_index, &priority, &weight)) {
10662 locator.sw_if_index = htonl(sw_if_index);
10663 locator.priority = priority;
10664 locator.weight = weight;
10665 vec_add1(locators, locator);
10666 } else if (unformat(input, "iface %U p %u w %u", unformat_sw_if_index,
10667 vam, &sw_if_index, &priority, &weight)) {
10668 locator.sw_if_index = htonl(sw_if_index);
10669 locator.priority = priority;
10670 locator.weight = weight;
10671 vec_add1(locators, locator);
10676 if (locator_set_name_set == 0) {
10677 errmsg ("missing locator-set name");
10678 vec_free(locators);
10682 if (vec_len(locator_set_name) > 64) {
10683 errmsg ("locator-set name too long\n");
10684 vec_free(locator_set_name);
10685 vec_free(locators);
10688 vec_add1(locator_set_name, 0);
10690 /* Construct the API message */
10691 M(LISP_ADD_DEL_LOCATOR_SET, lisp_add_del_locator_set);
10693 mp->is_add = is_add;
10694 clib_memcpy(mp->locator_set_name, locator_set_name,
10695 vec_len(locator_set_name));
10696 vec_free(locator_set_name);
10698 mp->locator_num = vec_len (locators);
10699 clib_memcpy (mp->locators, locators,
10700 (sizeof (ls_locator_t) * vec_len (locators)));
10701 vec_free (locators);
10706 /* Wait for a reply... */
10714 api_lisp_add_del_locator(vat_main_t * vam)
10716 unformat_input_t * input = vam->input;
10717 vl_api_lisp_add_del_locator_t *mp;
10719 u32 tmp_if_index = ~0;
10720 u32 sw_if_index = ~0;
10721 u8 sw_if_index_set = 0;
10722 u8 sw_if_index_if_name_set = 0;
10724 u8 priority_set = 0;
10728 u8 *locator_set_name = NULL;
10729 u8 locator_set_name_set = 0;
10731 /* Parse args required to build the message */
10732 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) {
10733 if (unformat(input, "del")) {
10735 } else if (unformat(input, "locator-set %s", &locator_set_name)) {
10736 locator_set_name_set = 1;
10737 } else if (unformat(input, "iface %U", unformat_sw_if_index, vam,
10739 sw_if_index_if_name_set = 1;
10740 sw_if_index = tmp_if_index;
10741 } else if (unformat(input,"sw_if_index %d", &tmp_if_index)) {
10742 sw_if_index_set = 1;
10743 sw_if_index = tmp_if_index;
10744 } else if (unformat(input, "p %d", &priority)) {
10746 } else if (unformat(input, "w %d", &weight)) {
10752 if (locator_set_name_set == 0) {
10753 errmsg ("missing locator-set name");
10757 if (sw_if_index_set == 0 && sw_if_index_if_name_set == 0) {
10758 errmsg ("missing sw_if_index");
10759 vec_free(locator_set_name);
10763 if (sw_if_index_set != 0 && sw_if_index_if_name_set != 0) {
10764 errmsg ("cannot use both params interface name and sw_if_index");
10765 vec_free(locator_set_name);
10769 if (priority_set == 0) {
10770 errmsg ("missing locator-set priority\n");
10771 vec_free(locator_set_name);
10775 if (weight_set == 0) {
10776 errmsg ("missing locator-set weight\n");
10777 vec_free(locator_set_name);
10781 if (vec_len(locator_set_name) > 64) {
10782 errmsg ("locator-set name too long\n");
10783 vec_free(locator_set_name);
10786 vec_add1(locator_set_name, 0);
10788 /* Construct the API message */
10789 M(LISP_ADD_DEL_LOCATOR, lisp_add_del_locator);
10791 mp->is_add = is_add;
10792 mp->sw_if_index = ntohl(sw_if_index);
10793 mp->priority = priority;
10794 mp->weight = weight;
10795 clib_memcpy(mp->locator_set_name, locator_set_name,
10796 vec_len(locator_set_name));
10797 vec_free(locator_set_name);
10802 /* Wait for a reply... */
10810 api_lisp_add_del_local_eid(vat_main_t * vam)
10812 unformat_input_t * input = vam->input;
10813 vl_api_lisp_add_del_local_eid_t *mp;
10817 lisp_eid_vat_t _eid, *eid = &_eid;
10818 u8 *locator_set_name = 0;
10819 u8 locator_set_name_set = 0;
10822 /* Parse args required to build the message */
10823 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) {
10824 if (unformat(input, "del")) {
10826 } else if (unformat(input, "vni %d", &vni)) {
10828 } else if (unformat(input, "eid %U", unformat_lisp_eid_vat, eid)) {
10830 } else if (unformat(input, "locator-set %s", &locator_set_name)) {
10831 locator_set_name_set = 1;
10836 if (locator_set_name_set == 0) {
10837 errmsg ("missing locator-set name\n");
10841 if (0 == eid_set) {
10842 errmsg ("EID address not set!");
10843 vec_free(locator_set_name);
10847 if (vec_len(locator_set_name) > 64) {
10848 errmsg ("locator-set name too long\n");
10849 vec_free(locator_set_name);
10852 vec_add1(locator_set_name, 0);
10854 /* Construct the API message */
10855 M(LISP_ADD_DEL_LOCAL_EID, lisp_add_del_local_eid);
10857 mp->is_add = is_add;
10858 lisp_eid_put_vat (mp->eid, eid->addr, eid->type);
10859 mp->eid_type = eid->type;
10860 mp->prefix_len = eid->len;
10861 mp->vni = clib_host_to_net_u32(vni);
10862 clib_memcpy(mp->locator_set_name, locator_set_name,
10863 vec_len(locator_set_name));
10865 vec_free(locator_set_name);
10870 /* Wait for a reply... */
10877 /** Used for transferring locators via VPP API */
10878 typedef CLIB_PACKED(struct
10880 u8 is_ip4; /**< is locator an IPv4 address? */
10881 u8 priority; /**< locator priority */
10882 u8 weight; /**< locator weight */
10883 u8 addr[16]; /**< IPv4/IPv6 address */
10887 api_lisp_gpe_add_del_fwd_entry(vat_main_t * vam)
10889 unformat_input_t * input = vam->input;
10890 vl_api_lisp_gpe_add_del_fwd_entry_t *mp;
10893 lisp_eid_vat_t _rmt_eid, * rmt_eid = &_rmt_eid;
10894 lisp_eid_vat_t _lcl_eid, * lcl_eid = &_lcl_eid;
10895 u8 rmt_eid_set = 0, lcl_eid_set = 0;
10896 u32 action = ~0, p, w;
10897 ip4_address_t rmt_rloc4, lcl_rloc4;
10898 ip6_address_t rmt_rloc6, lcl_rloc6;
10899 rloc_t * rmt_locs = 0, * lcl_locs = 0, rloc, * curr_rloc = 0;
10901 /* Parse args required to build the message */
10902 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) {
10903 if (unformat(input, "del")) {
10905 } else if (unformat(input, "rmt_eid %U", unformat_lisp_eid_vat,
10908 } else if (unformat(input, "lcl_eid %U", unformat_lisp_eid_vat,
10911 } else if (unformat(input, "p %d w %d", &p, &w)) {
10913 errmsg ("No RLOC configured for setting priority/weight!");
10916 curr_rloc->priority = p;
10917 curr_rloc->weight = w;
10918 } else if (unformat(input, "loc-pair %U %U", unformat_ip4_address,
10919 &lcl_rloc4, unformat_ip4_address, &rmt_rloc4)) {
10921 clib_memcpy (&rloc.addr, &lcl_rloc4, sizeof (lcl_rloc4));
10922 vec_add1 (lcl_locs, rloc);
10923 clib_memcpy (&rloc.addr, &rmt_rloc4, sizeof (rmt_rloc4));
10924 vec_add1 (rmt_locs, rloc);
10925 curr_rloc = &rmt_locs[vec_len (rmt_locs) - 1];
10926 } else if (unformat(input, "loc-pair %U", unformat_ip6_address,
10927 &lcl_rloc6, unformat_ip6_address, &rmt_rloc6)) {
10929 clib_memcpy (&rloc.addr, &lcl_rloc6, sizeof (lcl_rloc6));
10930 vec_add1 (lcl_locs, rloc);
10931 clib_memcpy (&rloc.addr, &rmt_rloc6, sizeof (rmt_rloc6));
10932 vec_add1 (rmt_locs, rloc);
10933 curr_rloc = &rmt_locs[vec_len (rmt_locs) - 1];
10934 } else if (unformat(input, "action %d", &action)) {
10937 clib_warning ("parse error '%U'", format_unformat_error, input);
10942 if (!rmt_eid_set) {
10943 errmsg ("remote eid addresses not set\n");
10947 if (lcl_eid_set && rmt_eid->type != lcl_eid->type) {
10948 errmsg ("eid types don't match\n");
10952 /* Construct the API message */
10953 M(LISP_GPE_ADD_DEL_FWD_ENTRY, lisp_gpe_add_del_fwd_entry);
10955 mp->is_add = is_add;
10956 lisp_eid_put_vat (mp->rmt_eid, rmt_eid->addr, rmt_eid->type);
10957 lisp_eid_put_vat (mp->lcl_eid, lcl_eid->addr, lcl_eid->type);
10958 mp->eid_type = rmt_eid->type;
10959 mp->rmt_len = rmt_eid->len;
10960 mp->lcl_len = lcl_eid->len;
10962 mp->loc_num = vec_len (rmt_locs);
10963 clib_memcpy (mp->lcl_locs, lcl_locs,
10964 (sizeof(rloc_t) * vec_len(lcl_locs)));
10965 clib_memcpy (mp->rmt_locs, rmt_locs,
10966 (sizeof(rloc_t) * vec_len(rmt_locs)));
10967 vec_free(lcl_locs);
10968 vec_free(rmt_locs);
10973 /* Wait for a reply... */
10981 api_lisp_add_del_map_resolver(vat_main_t * vam)
10983 unformat_input_t * input = vam->input;
10984 vl_api_lisp_add_del_map_resolver_t *mp;
10989 ip4_address_t ipv4;
10990 ip6_address_t ipv6;
10992 /* Parse args required to build the message */
10993 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) {
10994 if (unformat(input, "del")) {
10996 } else if (unformat(input, "%U", unformat_ip4_address, &ipv4)) {
10998 } else if (unformat(input, "%U", unformat_ip6_address, &ipv6)) {
11004 if (ipv4_set && ipv6_set) {
11005 errmsg ("both eid v4 and v6 addresses set\n");
11009 if (!ipv4_set && !ipv6_set) {
11010 errmsg ("eid addresses not set\n");
11014 /* Construct the API message */
11015 M(LISP_ADD_DEL_MAP_RESOLVER, lisp_add_del_map_resolver);
11017 mp->is_add = is_add;
11020 clib_memcpy(mp->ip_address, &ipv6, sizeof(ipv6));
11023 clib_memcpy(mp->ip_address, &ipv4, sizeof(ipv4));
11029 /* Wait for a reply... */
11037 api_lisp_gpe_enable_disable (vat_main_t * vam)
11039 unformat_input_t * input = vam->input;
11040 vl_api_lisp_gpe_enable_disable_t *mp;
11045 /* Parse args required to build the message */
11046 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) {
11047 if (unformat(input, "enable")) {
11050 } else if (unformat(input, "disable")) {
11058 errmsg("Value not set\n");
11062 /* Construct the API message */
11063 M(LISP_GPE_ENABLE_DISABLE, lisp_gpe_enable_disable);
11070 /* Wait for a reply... */
11078 api_lisp_enable_disable (vat_main_t * vam)
11080 unformat_input_t * input = vam->input;
11081 vl_api_lisp_enable_disable_t *mp;
11086 /* Parse args required to build the message */
11087 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
11089 if (unformat (input, "enable"))
11094 else if (unformat (input, "disable"))
11104 errmsg ("Value not set\n");
11108 /* Construct the API message */
11109 M(LISP_ENABLE_DISABLE, lisp_enable_disable);
11116 /* Wait for a reply... */
11124 * Enable/disable LISP proxy ITR.
11126 * @param vam vpp API test context
11127 * @return return code
11130 api_lisp_pitr_set_locator_set (vat_main_t * vam)
11133 u8 ls_name_set = 0;
11134 unformat_input_t * input = vam->input;
11135 vl_api_lisp_pitr_set_locator_set_t * mp;
11139 /* Parse args required to build the message */
11140 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
11142 if (unformat (input, "del"))
11144 else if (unformat (input, "locator-set %s", &ls_name))
11148 errmsg ("parse error '%U'", format_unformat_error, input);
11155 errmsg ("locator-set name not set!");
11159 M(LISP_PITR_SET_LOCATOR_SET, lisp_pitr_set_locator_set);
11161 mp->is_add = is_add;
11162 clib_memcpy (mp->ls_name, ls_name, vec_len (ls_name));
11163 vec_free (ls_name);
11168 /* wait for reply */
11176 api_show_lisp_pitr (vat_main_t * vam)
11178 vl_api_show_lisp_pitr_t *mp;
11181 if (!vam->json_output) {
11182 fformat(vam->ofp, "%=20s\n",
11186 M(SHOW_LISP_PITR, show_lisp_pitr);
11190 /* Wait for a reply... */
11198 * Add/delete mapping between vni and vrf
11201 api_lisp_eid_table_add_del_map (vat_main_t * vam)
11204 unformat_input_t * input = vam->input;
11205 vl_api_lisp_eid_table_add_del_map_t *mp;
11206 u8 is_add = 1, vni_set = 0, vrf_set = 0, bd_index_set = 0;
11207 u32 vni, vrf, bd_index;
11209 /* Parse args required to build the message */
11210 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
11212 if (unformat (input, "del"))
11214 else if (unformat(input, "vrf %d", &vrf))
11216 else if (unformat(input, "bd_index %d", &bd_index))
11218 else if (unformat(input, "vni %d", &vni))
11224 if (!vni_set || (!vrf_set && !bd_index_set))
11226 errmsg ("missing arguments!");
11230 M(LISP_EID_TABLE_ADD_DEL_MAP, lisp_eid_table_add_del_map);
11232 mp->is_add = is_add;
11233 mp->vni = htonl (vni);
11234 mp->dp_table = htonl (vrf);
11235 mp->is_l2 = bd_index_set;
11240 /* wait for reply */
11248 * Add/del remote mapping to/from LISP control plane
11250 * @param vam vpp API test context
11251 * @return return code
11254 api_lisp_add_del_remote_mapping (vat_main_t * vam)
11256 unformat_input_t * input = vam->input;
11257 vl_api_lisp_add_del_remote_mapping_t *mp;
11260 //TODO: seid need remove
11261 lisp_eid_vat_t _eid, * eid = &_eid;
11262 lisp_eid_vat_t _seid, * seid = &_seid;
11263 u8 is_add = 1, del_all = 0, eid_set = 0;
11264 u32 action = ~0, p, w;
11265 ip4_address_t rloc4;
11266 ip6_address_t rloc6;
11267 rloc_t * rlocs = 0, rloc, * curr_rloc = 0;
11269 /* Parse args required to build the message */
11270 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) {
11271 if (unformat(input, "del-all")) {
11273 } else if (unformat(input, "del")) {
11275 } else if (unformat(input, "add")) {
11277 } else if (unformat(input, "deid %U", unformat_lisp_eid_vat, eid)) {
11279 } else if (unformat(input, "seid %U", unformat_lisp_eid_vat, &seid)) {
11280 //TODO: Need remove, but first must be remove from CSIT test
11281 } else if (unformat(input, "vni %d", &vni)) {
11283 } else if (unformat(input, "p %d w %d", &p, &w)) {
11285 errmsg ("No RLOC configured for setting priority/weight!");
11288 curr_rloc->priority = p;
11289 curr_rloc->weight = w;
11290 } else if (unformat(input, "rloc %U", unformat_ip4_address, &rloc4)) {
11292 clib_memcpy (&rloc.addr, &rloc4, sizeof (rloc4));
11293 vec_add1 (rlocs, rloc);
11294 curr_rloc = &rlocs[vec_len (rlocs) - 1];
11295 } else if (unformat(input, "rloc %U", unformat_ip6_address, &rloc6)) {
11297 clib_memcpy (&rloc.addr, &rloc6, sizeof (rloc6));
11298 vec_add1 (rlocs, rloc);
11299 curr_rloc = &rlocs[vec_len (rlocs) - 1];
11300 } else if (unformat(input, "action %d", &action)) {
11303 clib_warning ("parse error '%U'", format_unformat_error, input);
11308 if (0 == eid_set) {
11309 errmsg ("missing params!");
11313 if (is_add && (~0 == action)
11314 && 0 == vec_len (rlocs)) {
11315 errmsg ("no action set for negative map-reply!");
11319 M(LISP_ADD_DEL_REMOTE_MAPPING, lisp_add_del_remote_mapping);
11320 mp->is_add = is_add;
11321 mp->vni = htonl (vni);
11322 mp->action = (u8) action;
11323 mp->eid_len = eid->len;
11324 mp->del_all = del_all;
11325 mp->eid_type = eid->type;
11326 lisp_eid_put_vat(mp->eid, eid->addr, eid->type);
11328 mp->rloc_num = vec_len (rlocs);
11329 clib_memcpy (mp->rlocs, rlocs, (sizeof (rloc_t) * vec_len (rlocs)));
11335 /* Wait for a reply... */
11343 * Add/del LISP adjacency. Saves mapping in LISP control plane and updates
11344 * forwarding entries in data-plane accordingly.
11346 * @param vam vpp API test context
11347 * @return return code
11350 api_lisp_add_del_adjacency (vat_main_t * vam)
11352 unformat_input_t * input = vam->input;
11353 vl_api_lisp_add_del_adjacency_t *mp;
11356 ip4_address_t seid4, deid4;
11357 ip6_address_t seid6, deid6;
11358 u8 deid_mac[6] = {0};
11359 u8 seid_mac[6] = {0};
11360 u8 deid_type, seid_type;
11361 u32 seid_len = 0, deid_len = 0, len;
11364 seid_type = deid_type = (u8)~0;
11366 /* Parse args required to build the message */
11367 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) {
11368 if (unformat(input, "del")) {
11370 } else if (unformat(input, "add")) {
11372 } else if (unformat(input, "deid %U/%d", unformat_ip4_address,
11374 deid_type = 0; /* ipv4 */
11376 } else if (unformat(input, "deid %U/%d", unformat_ip6_address,
11378 deid_type = 1; /* ipv6 */
11380 } else if (unformat(input, "deid %U", unformat_ethernet_address,
11382 deid_type = 2; /* mac */
11383 } else if (unformat(input, "seid %U/%d", unformat_ip4_address,
11385 seid_type = 0; /* ipv4 */
11387 } else if (unformat(input, "seid %U/%d", unformat_ip6_address,
11389 seid_type = 1; /* ipv6 */
11391 } else if (unformat(input, "seid %U", unformat_ethernet_address,
11393 seid_type = 2; /* mac */
11394 } else if (unformat(input, "vni %d", &vni)) {
11397 errmsg ("parse error '%U'", format_unformat_error, input);
11402 if ((u8)~0 == deid_type) {
11403 errmsg ("missing params!");
11407 if (seid_type != deid_type) {
11408 errmsg ("source and destination EIDs are of different types!");
11412 M(LISP_ADD_DEL_ADJACENCY, lisp_add_del_adjacency);
11413 mp->is_add = is_add;
11414 mp->vni = htonl (vni);
11415 mp->seid_len = seid_len;
11416 mp->deid_len = deid_len;
11417 mp->eid_type = deid_type;
11419 switch (mp->eid_type) {
11421 clib_memcpy (mp->seid, &seid4, sizeof (seid4));
11422 clib_memcpy (mp->deid, &deid4, sizeof (deid4));
11425 clib_memcpy (mp->seid, &seid6, sizeof (seid6));
11426 clib_memcpy (mp->deid, &deid6, sizeof (deid6));
11429 clib_memcpy (mp->seid, seid_mac, 6);
11430 clib_memcpy (mp->deid, deid_mac, 6);
11433 errmsg ("unknown EID type %d!", mp->eid_type);
11440 /* Wait for a reply... */
11448 api_lisp_gpe_add_del_iface(vat_main_t * vam)
11450 unformat_input_t * input = vam->input;
11451 vl_api_lisp_gpe_add_del_iface_t *mp;
11453 u8 is_set = 0, is_add = 1, is_l2 = 0;
11456 /* Parse args required to build the message */
11457 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) {
11458 if (unformat(input, "up")) {
11461 } else if (unformat(input, "down")) {
11464 } else if (unformat(input, "table_id %d", &dp_table)) {
11466 } else if (unformat(input, "bd_id %d", &dp_table)) {
11468 } else if (unformat(input, "vni %d", &vni)) {
11475 errmsg("Value not set\n");
11479 /* Construct the API message */
11480 M(LISP_GPE_ADD_DEL_IFACE, lisp_gpe_add_del_iface);
11482 mp->is_add = is_add;
11483 mp->dp_table = dp_table;
11490 /* Wait for a reply... */
11498 * Add/del map request itr rlocs from LISP control plane and updates
11500 * @param vam vpp API test context
11501 * @return return code
11504 api_lisp_add_del_map_request_itr_rlocs(vat_main_t * vam)
11506 unformat_input_t * input = vam->input;
11507 vl_api_lisp_add_del_map_request_itr_rlocs_t *mp;
11509 u8 *locator_set_name = 0;
11510 u8 locator_set_name_set = 0;
11513 /* Parse args required to build the message */
11514 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) {
11515 if (unformat(input, "del")) {
11517 } else if (unformat(input, "%_%v%_", &locator_set_name)) {
11518 locator_set_name_set = 1;
11520 clib_warning ("parse error '%U'", format_unformat_error, input);
11525 if (is_add && !locator_set_name_set) {
11526 errmsg ("itr-rloc is not set!");
11530 if (is_add && vec_len(locator_set_name) > 64) {
11531 errmsg ("itr-rloc locator-set name too long\n");
11532 vec_free(locator_set_name);
11536 M(LISP_ADD_DEL_MAP_REQUEST_ITR_RLOCS, lisp_add_del_map_request_itr_rlocs);
11537 mp->is_add = is_add;
11539 clib_memcpy (mp->locator_set_name , locator_set_name,
11540 vec_len(locator_set_name));
11542 memset(mp->locator_set_name, 0, sizeof(mp->locator_set_name));
11544 vec_free (locator_set_name);
11549 /* Wait for a reply... */
11557 lisp_locator_dump_send_msg(vat_main_t * vam, u32 locator_set_index, u8 filter)
11559 vl_api_lisp_locator_dump_t *mp;
11562 M(LISP_LOCATOR_DUMP, lisp_locator_dump);
11564 mp->locator_set_index = htonl(locator_set_index);
11565 mp->filter = filter;
11570 /* Use a control ping for synchronization */
11572 vl_api_noprint_control_ping_t * mp;
11573 M(NOPRINT_CONTROL_PING, noprint_control_ping);
11576 /* Wait for a reply... */
11581 clean_locator_set_message(vat_main_t * vam)
11583 locator_set_msg_t * ls = 0;
11585 vec_foreach (ls, vam->locator_set_msg) {
11586 vec_free(ls->locator_set_name);
11589 vec_free(vam->locator_set_msg);
11593 print_locator_in_locator_set(vat_main_t * vam, u8 filter)
11595 locator_set_msg_t * ls;
11596 locator_msg_t * loc;
11598 int i = 0, ret = 0;
11600 vec_foreach(ls, vam->locator_set_msg) {
11601 ret = lisp_locator_dump_send_msg(vam, ls->locator_set_index, filter);
11603 vec_free(vam->locator_msg);
11604 clean_locator_set_message(vam);
11608 tmp_str = format(0, "%=20s%=16d%s", ls->locator_set_name,
11609 ls->locator_set_index,
11610 vec_len(vam->locator_msg) ? "" : "\n");
11612 vec_foreach(loc, vam->locator_msg) {
11614 tmp_str = format(tmp_str, "%=37s", " ");
11617 tmp_str = format(tmp_str, "%=16d%=16d%=16d\n",
11622 tmp_str = format(tmp_str, "%=16U%=16d%=16d\n",
11623 loc->is_ipv6 ? format_ip6_address :
11624 format_ip4_address,
11632 fformat(vam->ofp, "%s", tmp_str);
11634 vec_free(vam->locator_msg);
11637 clean_locator_set_message(vam);
11643 json_locator_in_locator_set(vat_main_t * vam, u8 filter)
11645 locator_set_msg_t * ls;
11646 locator_msg_t * loc;
11647 vat_json_node_t * node = NULL;
11648 vat_json_node_t * locator_array;
11649 vat_json_node_t * locator;
11650 struct in6_addr ip6;
11651 struct in_addr ip4;
11654 if (!vec_len(vam->locator_set_msg)) {
11655 /* just print [] */
11656 vat_json_init_array(&vam->json_tree);
11657 vat_json_print(vam->ofp, &vam->json_tree);
11658 vam->json_tree.type = VAT_JSON_NONE;
11662 if (VAT_JSON_ARRAY != vam->json_tree.type) {
11663 ASSERT(VAT_JSON_NONE == vam->json_tree.type);
11664 vat_json_init_array(&vam->json_tree);
11667 vec_foreach(ls, vam->locator_set_msg) {
11668 ret = lisp_locator_dump_send_msg(vam, ls->locator_set_index, filter);
11670 vec_free(ls->locator_set_name);
11671 vec_free(vam->locator_msg);
11672 vec_free(vam->locator_set_msg);
11673 vat_json_free(&vam->json_tree);
11674 vam->json_tree.type = VAT_JSON_NONE;
11678 node = vat_json_array_add(&vam->json_tree);
11679 vat_json_init_object(node);
11681 vat_json_object_add_uint(node, "locator-set-index",
11682 ls->locator_set_index);
11683 vat_json_object_add_string_copy(node, "locator-set",
11684 ls->locator_set_name);
11685 locator_array = vat_json_object_add_list(node, "locator");
11686 vec_foreach(loc, vam->locator_msg) {
11687 locator = vat_json_array_add(locator_array);
11688 vat_json_init_object(locator);
11690 vat_json_object_add_uint(locator, "locator-index",
11693 if (loc->is_ipv6) {
11694 clib_memcpy(&ip6, loc->ip_address, sizeof(ip6));
11695 vat_json_object_add_ip6(locator, "locator", ip6);
11697 clib_memcpy(&ip4, loc->ip_address, sizeof(ip4));
11698 vat_json_object_add_ip4(locator, "locator", ip4);
11701 vat_json_object_add_uint(locator, "priority", loc->priority);
11702 vat_json_object_add_uint(locator, "weight", loc->weight);
11705 vec_free(ls->locator_set_name);
11706 vec_free(vam->locator_msg);
11709 vat_json_print(vam->ofp, &vam->json_tree);
11710 vat_json_free(&vam->json_tree);
11711 vam->json_tree.type = VAT_JSON_NONE;
11713 vec_free(vam->locator_set_msg);
11719 get_locator_set_index_from_msg(vat_main_t * vam, u8 * locator_set,
11720 u32 * locator_set_index)
11722 locator_set_msg_t * ls;
11725 * locator_set_index = ~0;
11727 if (!vec_len(vam->locator_set_msg)) {
11731 vec_foreach(ls, vam->locator_set_msg) {
11732 if (!strcmp((char *) locator_set, (char *) ls->locator_set_name)) {
11733 * locator_set_index = ls->locator_set_index;
11734 vec_free(vam->locator_set_msg);
11739 vec_free(vam->locator_set_msg);
11745 get_locator_set_index(vat_main_t * vam, u8 * locator_set,
11746 u32 * locator_set_index)
11748 vl_api_lisp_locator_set_dump_t *mp;
11751 M(LISP_LOCATOR_SET_DUMP, lisp_locator_set_dump);
11755 /* Use a control ping for synchronization */
11757 vl_api_noprint_control_ping_t * mp;
11758 M(NOPRINT_CONTROL_PING, noprint_control_ping);
11762 vam->noprint_msg = 1;
11763 /* Wait for a reply... */
11765 get_locator_set_index_from_msg(vam, locator_set, locator_set_index);
11766 vam->noprint_msg = 0;
11774 lisp_locator_dump(vat_main_t * vam, u32 locator_set_index, u8 * locator_set,
11781 if (!vam->json_output) {
11782 fformat(vam->ofp, "%=20s%=16s%=16s\n",
11783 "locator", "priority", "weight");
11787 ret = get_locator_set_index(vam, locator_set, &locator_set_index);
11790 if (!ret && ~0 == locator_set_index) {
11794 ret = lisp_locator_dump_send_msg(vam, locator_set_index, filter);
11800 lisp_locator_set_dump(vat_main_t * vam, u8 filter)
11802 vl_api_lisp_locator_set_dump_t *mp;
11805 if (!vam->json_output) {
11806 fformat(vam->ofp, "%=20s%=16s%=16s%=16s%=16s\n",
11807 "locator-set", "locator-set-index", "locator", "priority",
11811 vam->noprint_msg = 1;
11813 M(LISP_LOCATOR_SET_DUMP, lisp_locator_set_dump);
11815 mp->filter = filter;
11820 /* Use a control ping for synchronization */
11822 vl_api_noprint_control_ping_t * mp;
11823 M(NOPRINT_CONTROL_PING, noprint_control_ping);
11827 /* Wait for a reply... */
11829 if (vam->noprint_msg) {
11830 if (!vam->json_output) {
11831 print_locator_in_locator_set(vam, filter);
11833 json_locator_in_locator_set(vam, filter);
11837 vam->noprint_msg = 0;
11845 api_lisp_locator_set_dump(vat_main_t *vam)
11847 unformat_input_t * input = vam->input;
11848 vam->noprint_msg = 0;
11849 u32 locator_set_index = ~0;
11850 u8 locator_set_index_set = 0;
11851 u8 * locator_set = 0;
11852 u8 locator_set_set = 0;
11856 /* Parse args required to build the message */
11857 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) {
11858 if (unformat(input, "locator-set-index %u", &locator_set_index)) {
11859 locator_set_index_set = 1;
11860 } else if (unformat(input, "locator-set %s", &locator_set)) {
11861 locator_set_set = 1;
11862 } else if (unformat(input, "local")) {
11864 } else if (unformat(input, "remote")) {
11871 if (locator_set_index_set && locator_set_set) {
11872 errmsg ("use only input parameter!\n");
11876 if (locator_set_index_set || locator_set_set) {
11877 ret = lisp_locator_dump(vam, locator_set_index, locator_set, filter);
11879 ret = lisp_locator_set_dump(vam, filter);
11882 vec_free(locator_set);
11888 api_lisp_eid_table_map_dump(vat_main_t *vam)
11890 vl_api_lisp_eid_table_map_dump_t *mp;
11893 if (!vam->json_output) {
11894 fformat (vam->ofp, "%=10s%=10s\n", "VNI", "VRF");
11897 M(LISP_EID_TABLE_MAP_DUMP, lisp_eid_table_map_dump);
11902 /* Use a control ping for synchronization */
11904 vl_api_control_ping_t * mp;
11905 M(CONTROL_PING, control_ping);
11908 /* Wait for a reply... */
11916 get_locator_set(vat_main_t * vam)
11918 vl_api_lisp_locator_set_dump_t *mp;
11921 M(LISP_LOCATOR_SET_DUMP, lisp_locator_set_dump);
11925 /* Use a control ping for synchronization */
11927 vl_api_noprint_control_ping_t * mp;
11928 M(NOPRINT_CONTROL_PING, noprint_control_ping);
11932 /* Wait for a reply... */
11940 format_eid_for_eid_table(vat_main_t *vam, u8 * str, eid_table_t * eid_table,
11943 u8 * (*format_eid)(u8 *, va_list *) = 0;
11945 ASSERT(vam != NULL);
11946 ASSERT(eid_table != NULL);
11952 switch (eid_table->eid_type)
11956 format_eid = (eid_table->eid_type ? format_ip6_address :
11957 format_ip4_address);
11958 str = format(0, "[%d] %U/%d",
11959 clib_net_to_host_u32 (eid_table->vni),
11960 format_eid, eid_table->eid, eid_table->eid_prefix_len);
11963 str = format(0, "[%d] %U",
11964 clib_net_to_host_u32 (eid_table->vni),
11965 format_ethernet_address, eid_table->eid);
11968 errmsg ("unknown EID type %d!", eid_table->eid_type);
11979 format_locator_set_for_eid_table(vat_main_t * vam, u8 * str,
11980 eid_table_t * eid_table)
11982 locator_set_msg_t * ls = 0;
11984 ASSERT(vam != NULL);
11985 ASSERT(eid_table != NULL);
11987 if (eid_table->is_local) {
11988 vec_foreach (ls, vam->locator_set_msg) {
11989 if (ls->locator_set_index == eid_table->locator_set_index) {
11990 str = format(0, "local(%s)", ls->locator_set_name);
11995 str = format(0, "local(N/A)");
11997 str = format(0, "remote");
12004 format_locator_for_eid_table(vat_main_t * vam, u8 * str,
12005 eid_table_t * eid_table)
12007 locator_msg_t * loc = 0;
12008 int first_line = 1;
12010 ASSERT(vam != NULL);
12011 ASSERT(eid_table != NULL);
12013 vec_foreach(loc, vam->locator_msg) {
12016 str = format(str, "%-55s%-d\n", " ", loc->sw_if_index);
12018 str = format(str, "%=55s%-U\n", " ",
12019 loc->is_ipv6 ? format_ip6_address :
12020 format_ip4_address,
12028 str = format(str, "%-30d%-20u%-u\n", loc->sw_if_index,
12029 eid_table->ttl, eid_table->authoritative);
12031 str = format(str, "%-30U%-20u%-u\n",
12032 loc->is_ipv6 ? format_ip6_address :
12033 format_ip4_address,
12034 loc->ip_address, eid_table->ttl,
12035 eid_table->authoritative);
12044 print_lisp_eid_table_dump(vat_main_t * vam)
12046 eid_table_t * eid_table = 0;
12047 u8 * tmp_str = 0, * tmp_str2 = 0;
12050 ASSERT(vam != NULL);
12052 ret = get_locator_set(vam);
12054 vec_free(vam->eid_tables);
12058 fformat(vam->ofp, "%-35s%-20s%-30s%-20s%-s\n", "EID", "type", "locators",
12059 "ttl", "authoritative");
12061 vec_foreach(eid_table, vam->eid_tables) {
12062 ret = lisp_locator_dump_send_msg(vam, eid_table->locator_set_index, 0);
12064 vec_free(vam->locator_msg);
12065 clean_locator_set_message(vam);
12066 vec_free(vam->eid_tables);
12070 tmp_str2 = format_eid_for_eid_table(vam, tmp_str2, eid_table, &ret);
12072 vec_free(vam->locator_msg);
12073 clean_locator_set_message(vam);
12074 vec_free(vam->eid_tables);
12078 tmp_str = format(0, "%-35s", tmp_str2);
12079 vec_free(tmp_str2);
12081 tmp_str2 = format_locator_set_for_eid_table(vam, tmp_str2, eid_table);
12082 tmp_str = format(tmp_str, "%-20s", tmp_str2);
12083 vec_free(tmp_str2);
12085 tmp_str2 = format_locator_for_eid_table(vam, tmp_str2, eid_table);
12086 tmp_str = format(tmp_str, "%-s", tmp_str2);
12087 vec_free(tmp_str2);
12089 fformat(vam->ofp, "%s", tmp_str);
12091 vec_free(vam->locator_msg);
12094 clean_locator_set_message(vam);
12095 vec_free(vam->eid_tables);
12101 json_locator_set_for_eid_table(vat_main_t * vam, vat_json_node_t * node,
12102 eid_table_t * eid_table)
12104 locator_set_msg_t * ls = 0;
12107 ASSERT(vam != NULL);
12108 ASSERT(node != NULL);
12109 ASSERT(eid_table != NULL);
12111 if (eid_table->is_local) {
12112 vec_foreach (ls, vam->locator_set_msg) {
12113 if (ls->locator_set_index == eid_table->locator_set_index) {
12114 vat_json_object_add_string_copy(node, "locator-set",
12115 ls->locator_set_name);
12120 s = format(0, "N/A");
12122 vat_json_object_add_string_copy(node, "locator-set", s);
12125 s = format(0, "remote");
12127 vat_json_object_add_string_copy(node, "locator-set", s);
12133 json_eid_for_eid_table(vat_main_t * vam, vat_json_node_t * node,
12134 eid_table_t * eid_table)
12137 struct in6_addr ip6;
12138 struct in_addr ip4;
12140 ASSERT(vam != NULL);
12141 ASSERT(node != NULL);
12142 ASSERT(eid_table != NULL);
12144 switch (eid_table->eid_type)
12147 clib_memcpy(&ip4, eid_table->eid, sizeof(ip4));
12148 vat_json_object_add_ip4(node, "eid", ip4);
12149 vat_json_object_add_uint(node, "eid-prefix-len",
12150 eid_table->eid_prefix_len);
12153 clib_memcpy(&ip6, eid_table->eid, sizeof(ip6));
12154 vat_json_object_add_ip6(node, "eid", ip6);
12155 vat_json_object_add_uint(node, "eid-prefix-len",
12156 eid_table->eid_prefix_len);
12159 s = format (0, "%U", format_ethernet_address, eid_table->eid);
12161 vat_json_object_add_string_copy(node, "eid", s);
12165 errmsg ("unknown EID type %d!", eid_table->eid_type);
12173 json_locator_for_eid_table(vat_main_t * vam, vat_json_node_t * node,
12174 eid_table_t * eid_table)
12176 locator_msg_t * loc = 0;
12177 vat_json_node_t * locator_array = 0;
12178 vat_json_node_t * locator = 0;
12179 struct in6_addr ip6;
12180 struct in_addr ip4;
12182 ASSERT(vam != NULL);
12183 ASSERT(node != NULL);
12184 ASSERT(eid_table != NULL);
12186 locator_array = vat_json_object_add_list(node, "locator");
12187 vec_foreach(loc, vam->locator_msg) {
12188 locator = vat_json_array_add(locator_array);
12189 vat_json_init_object(locator);
12191 vat_json_object_add_uint(locator, "locator-index",
12194 if (loc->is_ipv6) {
12195 clib_memcpy(&ip6, loc->ip_address, sizeof(ip6));
12196 vat_json_object_add_ip6(locator, "locator", ip6);
12198 clib_memcpy(&ip4, loc->ip_address, sizeof(ip4));
12199 vat_json_object_add_ip4(locator, "locator", ip4);
12206 json_lisp_eid_table_dump(vat_main_t * vam)
12208 eid_table_t * eid_table;
12209 vat_json_node_t * node = 0;
12212 ASSERT(vam != NULL);
12214 ret = get_locator_set(vam);
12216 vec_free(vam->eid_tables);
12220 if (!vec_len(vam->eid_tables)) {
12221 /* just print [] */
12222 vat_json_init_array(&vam->json_tree);
12223 vat_json_print(vam->ofp, &vam->json_tree);
12224 vam->json_tree.type = VAT_JSON_NONE;
12228 if (VAT_JSON_ARRAY != vam->json_tree.type) {
12229 ASSERT(VAT_JSON_NONE == vam->json_tree.type);
12230 vat_json_init_array(&vam->json_tree);
12233 vec_foreach(eid_table, vam->eid_tables) {
12234 ret = lisp_locator_dump_send_msg(vam, eid_table->locator_set_index, 0);
12236 vec_free(vam->locator_msg);
12237 vec_free(vam->eid_tables);
12238 clean_locator_set_message(vam);
12239 vat_json_free(&vam->json_tree);
12240 vam->json_tree.type = VAT_JSON_NONE;
12244 node = vat_json_array_add(&vam->json_tree);
12245 vat_json_init_object(node);
12247 vat_json_object_add_uint(node, "vni", eid_table->vni);
12249 json_locator_set_for_eid_table(vam, node, eid_table);
12250 ret = json_eid_for_eid_table(vam, node, eid_table);
12252 vec_free(vam->locator_msg);
12253 vec_free(vam->eid_tables);
12254 clean_locator_set_message(vam);
12255 vat_json_free(&vam->json_tree);
12256 vam->json_tree.type = VAT_JSON_NONE;
12260 json_locator_for_eid_table(vam, node, eid_table);
12262 vat_json_object_add_uint(node, "ttl", eid_table->ttl);
12263 vat_json_object_add_uint(node, "authoritative",
12264 eid_table->authoritative);
12266 vec_free(vam->locator_msg);
12269 vat_json_print(vam->ofp, &vam->json_tree);
12270 vat_json_free(&vam->json_tree);
12271 vam->json_tree.type = VAT_JSON_NONE;
12273 clean_locator_set_message(vam);
12274 vec_free(vam->eid_tables);
12280 api_lisp_eid_table_dump(vat_main_t *vam)
12282 unformat_input_t * i = vam->input;
12283 vl_api_lisp_eid_table_dump_t *mp;
12285 struct in_addr ip4;
12286 struct in6_addr ip6;
12288 u8 eid_type = ~0, eid_set = 0;
12289 u32 prefix_length = ~0, t, vni = 0;
12292 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
12293 if (unformat (i, "eid %U/%d", unformat_ip4_address, &ip4, &t)) {
12297 } else if (unformat (i, "eid %U/%d", unformat_ip6_address, &ip6, &t)) {
12301 } else if (unformat (i, "eid %U", unformat_ethernet_address, mac)) {
12304 } else if (unformat (i, "vni %d", &t)) {
12306 } else if (unformat (i, "local")) {
12308 } else if (unformat (i, "remote")) {
12311 errmsg ("parse error '%U'", format_unformat_error, i);
12316 M(LISP_EID_TABLE_DUMP, lisp_eid_table_dump);
12318 mp->filter = filter;
12321 mp->vni = htonl (vni);
12322 mp->eid_type = eid_type;
12323 switch (eid_type) {
12325 mp->prefix_length = prefix_length;
12326 clib_memcpy (mp->eid, &ip4, sizeof (ip4));
12329 mp->prefix_length = prefix_length;
12330 clib_memcpy (mp->eid, &ip6, sizeof (ip6));
12333 clib_memcpy (mp->eid, mac, sizeof (mac));
12336 errmsg ("unknown EID type %d!", eid_type);
12341 vam->noprint_msg = 1;
12346 /* Use a control ping for synchronization */
12348 vl_api_noprint_control_ping_t * mp;
12349 M(NOPRINT_CONTROL_PING, noprint_control_ping);
12353 /* Wait for a reply... */
12355 if (vam->noprint_msg) {
12356 if (!vam->json_output) {
12357 vam->retval = print_lisp_eid_table_dump(vam);
12359 vam->retval = json_lisp_eid_table_dump(vam);
12363 vam->noprint_msg = 0;
12371 api_lisp_gpe_tunnel_dump(vat_main_t *vam)
12373 vl_api_lisp_gpe_tunnel_dump_t *mp;
12376 if (!vam->json_output) {
12377 fformat(vam->ofp, "%=20s%=30s%=16s%=16s%=16s%=16s"
12378 "%=16s%=16s%=16s%=16s%=16s\n",
12379 "Tunel", "Source", "Destination", "Fib encap", "Fib decap",
12380 "Decap next", "Lisp version", "Flags", "Next protocol",
12381 "ver_res", "res", "iid");
12384 M(LISP_GPE_TUNNEL_DUMP, lisp_gpe_tunnel_dump);
12388 /* Use a control ping for synchronization */
12390 vl_api_control_ping_t * mp;
12391 M(CONTROL_PING, control_ping);
12394 /* Wait for a reply... */
12402 api_lisp_map_resolver_dump(vat_main_t *vam)
12404 vl_api_lisp_map_resolver_dump_t *mp;
12407 if (!vam->json_output) {
12408 fformat(vam->ofp, "%=20s\n",
12412 M(LISP_MAP_RESOLVER_DUMP, lisp_map_resolver_dump);
12416 /* Use a control ping for synchronization */
12418 vl_api_control_ping_t * mp;
12419 M(CONTROL_PING, control_ping);
12422 /* Wait for a reply... */
12430 api_show_lisp_status(vat_main_t *vam)
12432 vl_api_show_lisp_status_t *mp;
12435 if (!vam->json_output) {
12436 fformat(vam->ofp, "%-20s%-16s\n",
12437 "lisp status", "locator-set");
12440 M(SHOW_LISP_STATUS, show_lisp_status);
12443 /* Wait for a reply... */
12451 api_lisp_get_map_request_itr_rlocs(vat_main_t *vam)
12453 vl_api_lisp_get_map_request_itr_rlocs_t *mp;
12456 if (!vam->json_output) {
12457 fformat(vam->ofp, "%=20s\n",
12461 M(LISP_GET_MAP_REQUEST_ITR_RLOCS, lisp_get_map_request_itr_rlocs);
12464 /* Wait for a reply... */
12472 api_af_packet_create (vat_main_t * vam)
12474 unformat_input_t * i = vam->input;
12475 vl_api_af_packet_create_t * mp;
12477 u8 * host_if_name = 0;
12479 u8 random_hw_addr = 1;
12481 memset (hw_addr, 0, sizeof (hw_addr));
12483 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
12484 if (unformat (i, "name %s", &host_if_name))
12485 vec_add1 (host_if_name, 0);
12486 else if (unformat (i, "hw_addr %U", unformat_ethernet_address, hw_addr))
12487 random_hw_addr = 0;
12492 if (!vec_len (host_if_name)) {
12493 errmsg ("host-interface name must be specified");
12497 if (vec_len (host_if_name) > 64) {
12498 errmsg ("host-interface name too long");
12502 M(AF_PACKET_CREATE, af_packet_create);
12504 clib_memcpy (mp->host_if_name, host_if_name, vec_len (host_if_name));
12505 clib_memcpy (mp->hw_addr, hw_addr, 6);
12506 mp->use_random_hw_addr = random_hw_addr;
12507 vec_free (host_if_name);
12509 S; W2(fprintf(vam->ofp," new sw_if_index = %d ", vam->sw_if_index));
12515 api_af_packet_delete (vat_main_t * vam)
12517 unformat_input_t * i = vam->input;
12518 vl_api_af_packet_delete_t * mp;
12520 u8 * host_if_name = 0;
12522 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
12523 if (unformat (i, "name %s", &host_if_name))
12524 vec_add1 (host_if_name, 0);
12529 if (!vec_len (host_if_name)) {
12530 errmsg ("host-interface name must be specified");
12534 if (vec_len (host_if_name) > 64) {
12535 errmsg ("host-interface name too long");
12539 M(AF_PACKET_DELETE, af_packet_delete);
12541 clib_memcpy (mp->host_if_name, host_if_name, vec_len (host_if_name));
12542 vec_free (host_if_name);
12550 api_policer_add_del (vat_main_t * vam)
12552 unformat_input_t * i = vam->input;
12553 vl_api_policer_add_del_t * mp;
12564 u8 color_aware = 0;
12565 sse2_qos_pol_action_params_st conform_action, exceed_action, violate_action;
12567 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
12568 if (unformat (i, "del"))
12570 else if (unformat (i, "name %s", &name))
12571 vec_add1 (name, 0);
12572 else if (unformat (i, "cir %u", &cir))
12574 else if (unformat (i, "eir %u", &eir))
12576 else if (unformat (i, "cb %u", &cb))
12578 else if (unformat (i, "eb %u", &eb))
12580 else if (unformat (i, "rate_type %U", unformat_policer_rate_type,
12583 else if (unformat (i, "round_type %U", unformat_policer_round_type,
12586 else if (unformat (i, "type %U", unformat_policer_type, &type))
12588 else if (unformat (i, "conform_action %U", unformat_policer_action_type,
12591 else if (unformat (i, "exceed_action %U", unformat_policer_action_type,
12594 else if (unformat (i, "violate_action %U", unformat_policer_action_type,
12597 else if (unformat (i, "color-aware"))
12603 if (!vec_len (name)) {
12604 errmsg ("policer name must be specified");
12608 if (vec_len (name) > 64) {
12609 errmsg ("policer name too long");
12613 M(POLICER_ADD_DEL, policer_add_del);
12615 clib_memcpy (mp->name, name, vec_len (name));
12617 mp->is_add = is_add;
12622 mp->rate_type = rate_type;
12623 mp->round_type = round_type;
12625 mp->conform_action_type = conform_action.action_type;
12626 mp->conform_dscp = conform_action.dscp;
12627 mp->exceed_action_type = exceed_action.action_type;
12628 mp->exceed_dscp = exceed_action.dscp;
12629 mp->violate_action_type = violate_action.action_type;
12630 mp->violate_dscp = violate_action.dscp;
12631 mp->color_aware = color_aware;
12639 api_policer_dump(vat_main_t *vam)
12641 unformat_input_t * i = vam->input;
12642 vl_api_policer_dump_t *mp;
12644 u8 *match_name = 0;
12645 u8 match_name_valid = 0;
12647 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
12648 if (unformat (i, "name %s", &match_name)) {
12649 vec_add1 (match_name, 0);
12650 match_name_valid = 1;
12655 M(POLICER_DUMP, policer_dump);
12656 mp->match_name_valid = match_name_valid;
12657 clib_memcpy (mp->match_name, match_name, vec_len (match_name));
12658 vec_free (match_name);
12662 /* Use a control ping for synchronization */
12664 vl_api_control_ping_t * mp;
12665 M(CONTROL_PING, control_ping);
12668 /* Wait for a reply... */
12676 api_policer_classify_set_interface (vat_main_t * vam)
12678 unformat_input_t * i = vam->input;
12679 vl_api_policer_classify_set_interface_t *mp;
12682 int sw_if_index_set;
12683 u32 ip4_table_index = ~0;
12684 u32 ip6_table_index = ~0;
12685 u32 l2_table_index = ~0;
12688 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
12689 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
12690 sw_if_index_set = 1;
12691 else if (unformat (i, "sw_if_index %d", &sw_if_index))
12692 sw_if_index_set = 1;
12693 else if (unformat (i, "del"))
12695 else if (unformat (i, "ip4-table %d", &ip4_table_index))
12697 else if (unformat (i, "ip6-table %d", &ip6_table_index))
12699 else if (unformat (i, "l2-table %d", &l2_table_index))
12702 clib_warning ("parse error '%U'", format_unformat_error, i);
12707 if (sw_if_index_set == 0) {
12708 errmsg ("missing interface name or sw_if_index\n");
12712 M(POLICER_CLASSIFY_SET_INTERFACE, policer_classify_set_interface);
12714 mp->sw_if_index = ntohl(sw_if_index);
12715 mp->ip4_table_index = ntohl(ip4_table_index);
12716 mp->ip6_table_index = ntohl(ip6_table_index);
12717 mp->l2_table_index = ntohl(l2_table_index);
12718 mp->is_add = is_add;
12726 api_policer_classify_dump(vat_main_t *vam)
12728 unformat_input_t * i = vam->input;
12729 vl_api_policer_classify_dump_t *mp;
12731 u8 type = POLICER_CLASSIFY_N_TABLES;
12733 if (unformat (i, "type %U", unformat_classify_table_type, &type))
12736 errmsg ("classify table type must be specified\n");
12740 if (!vam->json_output) {
12741 fformat(vam->ofp, "%10s%20s\n", "Intfc idx", "Classify table");
12744 M(POLICER_CLASSIFY_DUMP, policer_classify_dump);
12749 /* Use a control ping for synchronization */
12751 vl_api_control_ping_t * mp;
12752 M(CONTROL_PING, control_ping);
12755 /* Wait for a reply... */
12763 api_netmap_create (vat_main_t * vam)
12765 unformat_input_t * i = vam->input;
12766 vl_api_netmap_create_t * mp;
12770 u8 random_hw_addr = 1;
12774 memset (hw_addr, 0, sizeof (hw_addr));
12776 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
12777 if (unformat (i, "name %s", &if_name))
12778 vec_add1 (if_name, 0);
12779 else if (unformat (i, "hw_addr %U", unformat_ethernet_address, hw_addr))
12780 random_hw_addr = 0;
12781 else if (unformat (i, "pipe"))
12783 else if (unformat (i, "master"))
12785 else if (unformat (i, "slave"))
12791 if (!vec_len (if_name)) {
12792 errmsg ("interface name must be specified");
12796 if (vec_len (if_name) > 64) {
12797 errmsg ("interface name too long");
12801 M(NETMAP_CREATE, netmap_create);
12803 clib_memcpy (mp->netmap_if_name, if_name, vec_len (if_name));
12804 clib_memcpy (mp->hw_addr, hw_addr, 6);
12805 mp->use_random_hw_addr = random_hw_addr;
12806 mp->is_pipe = is_pipe;
12807 mp->is_master = is_master;
12808 vec_free (if_name);
12816 api_netmap_delete (vat_main_t * vam)
12818 unformat_input_t * i = vam->input;
12819 vl_api_netmap_delete_t * mp;
12823 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
12824 if (unformat (i, "name %s", &if_name))
12825 vec_add1 (if_name, 0);
12830 if (!vec_len (if_name)) {
12831 errmsg ("interface name must be specified");
12835 if (vec_len (if_name) > 64) {
12836 errmsg ("interface name too long");
12840 M(NETMAP_DELETE, netmap_delete);
12842 clib_memcpy (mp->netmap_if_name, if_name, vec_len (if_name));
12843 vec_free (if_name);
12850 static void vl_api_mpls_gre_tunnel_details_t_handler
12851 (vl_api_mpls_gre_tunnel_details_t * mp)
12853 vat_main_t * vam = &vat_main;
12855 i32 len = ntohl(mp->nlabels);
12857 if (mp->l2_only == 0) {
12858 fformat(vam->ofp, "[%d]: src %U, dst %U, adj %U/%d, labels ",
12859 ntohl(mp->tunnel_index),
12860 format_ip4_address, &mp->tunnel_src,
12861 format_ip4_address, &mp->tunnel_dst,
12862 format_ip4_address, &mp->intfc_address,
12863 ntohl(mp->mask_width));
12864 for (i = 0; i < len; i++) {
12865 fformat(vam->ofp, "%u ", ntohl(mp->labels[i]));
12867 fformat(vam->ofp, "\n");
12868 fformat(vam->ofp, " inner fib index %d, outer fib index %d\n",
12869 ntohl(mp->inner_fib_index), ntohl(mp->outer_fib_index));
12871 fformat(vam->ofp, "[%d]: src %U, dst %U, key %U, labels ",
12872 ntohl(mp->tunnel_index),
12873 format_ip4_address, &mp->tunnel_src,
12874 format_ip4_address, &mp->tunnel_dst,
12875 format_ip4_address, &mp->intfc_address);
12876 for (i = 0; i < len; i++) {
12877 fformat(vam->ofp, "%u ", ntohl(mp->labels[i]));
12879 fformat(vam->ofp, "\n");
12880 fformat(vam->ofp, " l2 interface %d, outer fib index %d\n",
12881 ntohl(mp->hw_if_index), ntohl(mp->outer_fib_index));
12885 static void vl_api_mpls_gre_tunnel_details_t_handler_json
12886 (vl_api_mpls_gre_tunnel_details_t * mp)
12888 vat_main_t * vam = &vat_main;
12889 vat_json_node_t *node = NULL;
12890 struct in_addr ip4;
12892 i32 len = ntohl(mp->nlabels);
12894 if (VAT_JSON_ARRAY != vam->json_tree.type) {
12895 ASSERT(VAT_JSON_NONE == vam->json_tree.type);
12896 vat_json_init_array(&vam->json_tree);
12898 node = vat_json_array_add(&vam->json_tree);
12900 vat_json_init_object(node);
12901 vat_json_object_add_uint(node, "tunnel_index", ntohl(mp->tunnel_index));
12902 clib_memcpy(&ip4, &(mp->intfc_address), sizeof(ip4));
12903 vat_json_object_add_ip4(node, "intfc_address", ip4);
12904 vat_json_object_add_uint(node, "inner_fib_index", ntohl(mp->inner_fib_index));
12905 vat_json_object_add_uint(node, "mask_width", ntohl(mp->mask_width));
12906 vat_json_object_add_uint(node, "encap_index", ntohl(mp->encap_index));
12907 vat_json_object_add_uint(node, "hw_if_index", ntohl(mp->hw_if_index));
12908 vat_json_object_add_uint(node, "l2_only", ntohl(mp->l2_only));
12909 clib_memcpy(&ip4, &(mp->tunnel_src), sizeof(ip4));
12910 vat_json_object_add_ip4(node, "tunnel_src", ip4);
12911 clib_memcpy(&ip4, &(mp->tunnel_dst), sizeof(ip4));
12912 vat_json_object_add_ip4(node, "tunnel_dst", ip4);
12913 vat_json_object_add_uint(node, "outer_fib_index", ntohl(mp->outer_fib_index));
12914 vat_json_object_add_uint(node, "label_count", len);
12915 for (i = 0; i < len; i++) {
12916 vat_json_object_add_uint(node, "label", ntohl(mp->labels[i]));
12920 static int api_mpls_gre_tunnel_dump (vat_main_t * vam)
12922 vl_api_mpls_gre_tunnel_dump_t *mp;
12926 /* Parse args required to build the message */
12927 while (unformat_check_input (vam->input) != UNFORMAT_END_OF_INPUT) {
12928 if (!unformat (vam->input, "tunnel_index %d", &index)) {
12934 fformat(vam->ofp, " tunnel_index %d\n", index);
12936 M(MPLS_GRE_TUNNEL_DUMP, mpls_gre_tunnel_dump);
12937 mp->tunnel_index = htonl(index);
12940 /* Use a control ping for synchronization */
12942 vl_api_control_ping_t * mp;
12943 M(CONTROL_PING, control_ping);
12949 static void vl_api_mpls_eth_tunnel_details_t_handler
12950 (vl_api_mpls_eth_tunnel_details_t * mp)
12952 vat_main_t * vam = &vat_main;
12954 i32 len = ntohl(mp->nlabels);
12956 fformat(vam->ofp, "[%d]: dst %U, adj %U/%d, labels ",
12957 ntohl(mp->tunnel_index),
12958 format_ethernet_address, &mp->tunnel_dst_mac,
12959 format_ip4_address, &mp->intfc_address,
12960 ntohl(mp->mask_width));
12961 for (i = 0; i < len; i++) {
12962 fformat(vam->ofp, "%u ", ntohl(mp->labels[i]));
12964 fformat(vam->ofp, "\n");
12965 fformat(vam->ofp, " tx on %d, rx fib index %d\n",
12966 ntohl(mp->tx_sw_if_index),
12967 ntohl(mp->inner_fib_index));
12970 static void vl_api_mpls_eth_tunnel_details_t_handler_json
12971 (vl_api_mpls_eth_tunnel_details_t * mp)
12973 vat_main_t * vam = &vat_main;
12974 vat_json_node_t *node = NULL;
12975 struct in_addr ip4;
12977 i32 len = ntohl(mp->nlabels);
12979 if (VAT_JSON_ARRAY != vam->json_tree.type) {
12980 ASSERT(VAT_JSON_NONE == vam->json_tree.type);
12981 vat_json_init_array(&vam->json_tree);
12983 node = vat_json_array_add(&vam->json_tree);
12985 vat_json_init_object(node);
12986 vat_json_object_add_uint(node, "tunnel_index", ntohl(mp->tunnel_index));
12987 clib_memcpy(&ip4, &(mp->intfc_address), sizeof(ip4));
12988 vat_json_object_add_ip4(node, "intfc_address", ip4);
12989 vat_json_object_add_uint(node, "inner_fib_index", ntohl(mp->inner_fib_index));
12990 vat_json_object_add_uint(node, "mask_width", ntohl(mp->mask_width));
12991 vat_json_object_add_uint(node, "encap_index", ntohl(mp->encap_index));
12992 vat_json_object_add_uint(node, "hw_if_index", ntohl(mp->hw_if_index));
12993 vat_json_object_add_uint(node, "l2_only", ntohl(mp->l2_only));
12994 vat_json_object_add_string_copy(node, "tunnel_dst_mac",
12995 format(0, "%U", format_ethernet_address, &mp->tunnel_dst_mac));
12996 vat_json_object_add_uint(node, "tx_sw_if_index", ntohl(mp->tx_sw_if_index));
12997 vat_json_object_add_uint(node, "label_count", len);
12998 for (i = 0; i < len; i++) {
12999 vat_json_object_add_uint(node, "label", ntohl(mp->labels[i]));
13003 static int api_mpls_eth_tunnel_dump (vat_main_t * vam)
13005 vl_api_mpls_eth_tunnel_dump_t *mp;
13009 /* Parse args required to build the message */
13010 while (unformat_check_input (vam->input) != UNFORMAT_END_OF_INPUT) {
13011 if (!unformat (vam->input, "tunnel_index %d", &index)) {
13017 fformat(vam->ofp, " tunnel_index %d\n", index);
13019 M(MPLS_ETH_TUNNEL_DUMP, mpls_eth_tunnel_dump);
13020 mp->tunnel_index = htonl(index);
13023 /* Use a control ping for synchronization */
13025 vl_api_control_ping_t * mp;
13026 M(CONTROL_PING, control_ping);
13032 static void vl_api_mpls_fib_encap_details_t_handler
13033 (vl_api_mpls_fib_encap_details_t * mp)
13035 vat_main_t * vam = &vat_main;
13037 i32 len = ntohl(mp->nlabels);
13039 fformat(vam->ofp, "table %d, dest %U, label ",
13040 ntohl(mp->fib_index),
13041 format_ip4_address, &mp->dest,
13043 for (i = 0; i < len; i++) {
13044 fformat(vam->ofp, "%u ", ntohl(mp->labels[i]));
13046 fformat(vam->ofp, "\n");
13049 static void vl_api_mpls_fib_encap_details_t_handler_json
13050 (vl_api_mpls_fib_encap_details_t * mp)
13052 vat_main_t * vam = &vat_main;
13053 vat_json_node_t *node = NULL;
13055 i32 len = ntohl(mp->nlabels);
13056 struct in_addr ip4;
13058 if (VAT_JSON_ARRAY != vam->json_tree.type) {
13059 ASSERT(VAT_JSON_NONE == vam->json_tree.type);
13060 vat_json_init_array(&vam->json_tree);
13062 node = vat_json_array_add(&vam->json_tree);
13064 vat_json_init_object(node);
13065 vat_json_object_add_uint(node, "table", ntohl(mp->fib_index));
13066 vat_json_object_add_uint(node, "entry_index", ntohl(mp->entry_index));
13067 clib_memcpy(&ip4, &(mp->dest), sizeof(ip4));
13068 vat_json_object_add_ip4(node, "dest", ip4);
13069 vat_json_object_add_uint(node, "s_bit", ntohl(mp->s_bit));
13070 vat_json_object_add_uint(node, "label_count", len);
13071 for (i = 0; i < len; i++) {
13072 vat_json_object_add_uint(node, "label", ntohl(mp->labels[i]));
13076 static int api_mpls_fib_encap_dump (vat_main_t * vam)
13078 vl_api_mpls_fib_encap_dump_t *mp;
13081 M(MPLS_FIB_ENCAP_DUMP, mpls_fib_encap_dump);
13084 /* Use a control ping for synchronization */
13086 vl_api_control_ping_t * mp;
13087 M(CONTROL_PING, control_ping);
13093 static void vl_api_mpls_fib_decap_details_t_handler
13094 (vl_api_mpls_fib_decap_details_t * mp)
13096 vat_main_t * vam = &vat_main;
13098 fformat(vam->ofp, "RX table %d, TX table/intfc %u, swif_tag '%s', label %u, s_bit %u\n",
13099 ntohl(mp->rx_table_id),
13100 ntohl(mp->tx_table_id),
13106 static void vl_api_mpls_fib_decap_details_t_handler_json
13107 (vl_api_mpls_fib_decap_details_t * mp)
13109 vat_main_t * vam = &vat_main;
13110 vat_json_node_t *node = NULL;
13111 struct in_addr ip4;
13113 if (VAT_JSON_ARRAY != vam->json_tree.type) {
13114 ASSERT(VAT_JSON_NONE == vam->json_tree.type);
13115 vat_json_init_array(&vam->json_tree);
13117 node = vat_json_array_add(&vam->json_tree);
13119 vat_json_init_object(node);
13120 vat_json_object_add_uint(node, "table", ntohl(mp->fib_index));
13121 vat_json_object_add_uint(node, "entry_index", ntohl(mp->entry_index));
13122 clib_memcpy(&ip4, &(mp->dest), sizeof(ip4));
13123 vat_json_object_add_ip4(node, "dest", ip4);
13124 vat_json_object_add_uint(node, "s_bit", ntohl(mp->s_bit));
13125 vat_json_object_add_uint(node, "label", ntohl(mp->label));
13126 vat_json_object_add_uint(node, "rx_table_id", ntohl(mp->rx_table_id));
13127 vat_json_object_add_uint(node, "tx_table_id", ntohl(mp->tx_table_id));
13128 vat_json_object_add_string_copy(node, "swif_tag", mp->swif_tag);
13131 static int api_mpls_fib_decap_dump (vat_main_t * vam)
13133 vl_api_mpls_fib_decap_dump_t *mp;
13136 M(MPLS_FIB_DECAP_DUMP, mpls_fib_decap_dump);
13139 /* Use a control ping for synchronization */
13141 vl_api_control_ping_t * mp;
13142 M(CONTROL_PING, control_ping);
13148 int api_classify_table_ids (vat_main_t *vam)
13150 vl_api_classify_table_ids_t *mp;
13153 /* Construct the API message */
13154 M(CLASSIFY_TABLE_IDS, classify_table_ids);
13162 int api_classify_table_by_interface (vat_main_t *vam)
13164 unformat_input_t * input = vam->input;
13165 vl_api_classify_table_by_interface_t *mp;
13168 u32 sw_if_index = ~0;
13169 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) {
13170 if (unformat (input, "%U", unformat_sw_if_index, vam, &sw_if_index))
13172 else if (unformat (input, "sw_if_index %d", &sw_if_index))
13177 if (sw_if_index == ~0) {
13178 errmsg ("missing interface name or sw_if_index\n");
13182 /* Construct the API message */
13183 M(CLASSIFY_TABLE_BY_INTERFACE, classify_table_by_interface);
13185 mp->sw_if_index = ntohl(sw_if_index);
13192 int api_classify_table_info (vat_main_t *vam)
13194 unformat_input_t * input = vam->input;
13195 vl_api_classify_table_info_t *mp;
13199 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) {
13200 if (unformat (input, "table_id %d", &table_id))
13205 if (table_id == ~0) {
13206 errmsg ("missing table id\n");
13210 /* Construct the API message */
13211 M(CLASSIFY_TABLE_INFO, classify_table_info);
13213 mp->table_id = ntohl(table_id);
13220 int api_classify_session_dump (vat_main_t *vam)
13222 unformat_input_t * input = vam->input;
13223 vl_api_classify_session_dump_t *mp;
13227 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) {
13228 if (unformat (input, "table_id %d", &table_id))
13233 if (table_id == ~0) {
13234 errmsg ("missing table id\n");
13238 /* Construct the API message */
13239 M(CLASSIFY_SESSION_DUMP, classify_session_dump);
13241 mp->table_id = ntohl(table_id);
13244 /* Use a control ping for synchronization */
13246 vl_api_control_ping_t * mp;
13247 M(CONTROL_PING, control_ping);
13255 static void vl_api_ipfix_details_t_handler (vl_api_ipfix_details_t * mp)
13257 vat_main_t * vam = &vat_main;
13259 fformat(vam->ofp, "collector_address %U, collector_port %d, "
13260 "src_address %U, fib_index %u, path_mtu %u, "
13261 "template_interval %u\n",
13262 format_ip4_address, mp->collector_address,
13263 ntohs(mp->collector_port),
13264 format_ip4_address, mp->src_address,
13265 ntohl(mp->fib_index),
13266 ntohl(mp->path_mtu),
13267 ntohl(mp->template_interval));
13270 vam->result_ready = 1;
13273 static void vl_api_ipfix_details_t_handler_json
13274 (vl_api_ipfix_details_t * mp)
13276 vat_main_t * vam = &vat_main;
13277 vat_json_node_t node;
13278 struct in_addr collector_address;
13279 struct in_addr src_address;
13281 vat_json_init_object(&node);
13282 clib_memcpy(&collector_address, &mp->collector_address,
13283 sizeof(collector_address));
13284 vat_json_object_add_ip4(&node, "collector_address", collector_address);
13285 vat_json_object_add_uint(&node, "collector_port",
13286 ntohs(mp->collector_port));
13287 clib_memcpy(&src_address, &mp->src_address, sizeof(src_address));
13288 vat_json_object_add_ip4(&node, "src_address", src_address);
13289 vat_json_object_add_uint(&node, "fib_index", ntohl(mp->fib_index));
13290 vat_json_object_add_uint(&node, "path_mtu", ntohl(mp->path_mtu));
13291 vat_json_object_add_uint(&node, "template_interval",
13292 ntohl(mp->template_interval));
13294 vat_json_print(vam->ofp, &node);
13295 vat_json_free(&node);
13297 vam->result_ready = 1;
13300 int api_ipfix_dump (vat_main_t *vam)
13302 vl_api_ipfix_dump_t *mp;
13305 /* Construct the API message */
13306 M(IPFIX_DUMP, ipfix_dump);
13314 int api_pg_create_interface (vat_main_t *vam)
13316 unformat_input_t * input = vam->input;
13317 vl_api_pg_create_interface_t *mp;
13321 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) {
13322 if (unformat (input, "if_id %d", &if_id))
13328 errmsg ("missing pg interface index\n");
13332 /* Construct the API message */
13333 M(PG_CREATE_INTERFACE, pg_create_interface);
13335 mp->interface_id = ntohl(if_id);
13342 int api_pg_capture (vat_main_t *vam)
13344 unformat_input_t * input = vam->input;
13345 vl_api_pg_capture_t *mp;
13351 u8 pcap_file_set = 0;
13352 u8 * pcap_file = 0;
13353 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) {
13354 if (unformat (input, "if_id %d", &if_id))
13356 else if (unformat (input, "pcap %s", &pcap_file))
13358 else if (unformat (input, "count %d", &count))
13360 else if (unformat (input, "disable"))
13366 errmsg ("missing pg interface index\n");
13369 if (pcap_file_set>0) {
13370 if (vec_len (pcap_file) > 255) {
13371 errmsg ("pcap file name is too long\n");
13376 u32 name_len = vec_len(pcap_file);
13377 /* Construct the API message */
13378 M(PG_CAPTURE, pg_capture);
13380 mp->interface_id = ntohl(if_id);
13381 mp->is_enabled = enable;
13382 mp->count = ntohl(count);
13383 mp->pcap_name_length = ntohl(name_len);
13384 if (pcap_file_set != 0) {
13385 clib_memcpy(mp->pcap_file_name, pcap_file, name_len);
13387 vec_free(pcap_file);
13394 int api_pg_enable_disable (vat_main_t *vam)
13396 unformat_input_t * input = vam->input;
13397 vl_api_pg_enable_disable_t *mp;
13401 u8 stream_name_set = 0;
13402 u8 * stream_name = 0;
13403 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) {
13404 if (unformat (input, "stream %s", &stream_name))
13405 stream_name_set = 1;
13406 else if (unformat (input, "disable"))
13412 if (stream_name_set>0) {
13413 if (vec_len (stream_name) > 255) {
13414 errmsg ("stream name too long\n");
13419 u32 name_len = vec_len(stream_name);
13420 /* Construct the API message */
13421 M(PG_ENABLE_DISABLE, pg_enable_disable);
13423 mp->is_enabled = enable;
13424 if (stream_name_set != 0) {
13425 mp->stream_name_length = ntohl(name_len);
13426 clib_memcpy(mp->stream_name, stream_name, name_len);
13428 vec_free(stream_name);
13435 int api_ip_source_and_port_range_check_add_del (vat_main_t *vam)
13437 unformat_input_t * input = vam->input;
13438 vl_api_ip_source_and_port_range_check_add_del_t *mp;
13441 u16 * low_ports = 0;
13442 u16 * high_ports = 0;
13445 ip4_address_t ip4_addr;
13446 ip6_address_t ip6_addr;
13454 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
13456 if (unformat (input, "%U/%d", unformat_ip4_address, &ip4_addr, &length))
13460 else if (unformat (input, "%U/%d", unformat_ip6_address, &ip6_addr, &length))
13465 else if (unformat (input, "vrf %d", &vrf_id))
13467 else if (unformat (input, "del"))
13469 else if (unformat (input, "port %d", &tmp))
13471 if (tmp == 0 || tmp > 65535) {
13472 errmsg ("port %d out of range", tmp);
13476 this_hi = this_low + 1;
13477 vec_add1 (low_ports, this_low);
13478 vec_add1 (high_ports, this_hi);
13480 else if (unformat (input, "range %d - %d", &tmp, &tmp2))
13482 if ((tmp > tmp2) ||
13485 errmsg ("incorrect range parameters\n");
13489 /* Note: in debug CLI +1 is added to high before
13490 passing to real fn that does "the work"
13491 (ip_source_and_port_range_check_add_del).
13492 This fn is a wrapper around the binary API fn a
13493 control plane will call, which expects this increment
13494 to have occurred. Hence letting the binary API control
13495 plane fn do the increment for consistency between VAT
13496 and other control planes.
13499 vec_add1 (low_ports, this_low);
13500 vec_add1 (high_ports, this_hi);
13506 if (prefix_set == 0) {
13507 errmsg ("<address>/<mask> not specified\n");
13511 if (vrf_id == ~0) {
13512 errmsg ("VRF ID required, not specified\n");
13517 errmsg ("VRF ID should not be default. Should be distinct VRF for this purpose.\n");
13521 if (vec_len(low_ports) == 0) {
13522 errmsg ("At least one port or port range required\n");
13526 M(IP_SOURCE_AND_PORT_RANGE_CHECK_ADD_DEL, ip_source_and_port_range_check_add_del);
13528 mp->is_add = is_add;
13532 clib_memcpy (mp->address, &ip6_addr, sizeof (ip6_addr));
13535 clib_memcpy (mp->address, &ip4_addr, sizeof (ip4_addr));
13538 mp->mask_length = length;
13539 mp->number_of_ranges = vec_len (low_ports);
13541 clib_memcpy (mp->low_ports, low_ports, vec_len(low_ports));
13542 vec_free(low_ports);
13544 clib_memcpy (mp->high_ports, high_ports, vec_len(high_ports));
13545 vec_free (high_ports);
13547 mp->vrf_id = ntohl(vrf_id);
13554 int api_ip_source_and_port_range_check_interface_add_del (vat_main_t * vam)
13556 unformat_input_t * input = vam->input;
13557 vl_api_ip_source_and_port_range_check_interface_add_del_t *mp;
13559 u32 sw_if_index = ~0;
13563 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
13565 if (unformat (input, "%U", unformat_sw_if_index, vam, &sw_if_index))
13567 else if (unformat (input, "sw_if_index %d", &sw_if_index))
13569 else if (unformat (input, "vrf %d", &vrf_id))
13571 else if (unformat (input, "del"))
13577 if (sw_if_index == ~0) {
13578 errmsg ("Interface required but not specified\n");
13582 if (vrf_id == ~0) {
13583 errmsg ("VRF ID required but not specified\n");
13588 errmsg ("VRF ID should not be default. Should be distinct VRF for this purpose.\n");
13592 /* Construct the API message */
13593 M(IP_SOURCE_AND_PORT_RANGE_CHECK_INTERFACE_ADD_DEL, ip_source_and_port_range_check_interface_add_del);
13595 mp->sw_if_index = ntohl (sw_if_index);
13596 mp->is_add = is_add;
13597 mp->vrf_id = ntohl (vrf_id);
13602 /* Wait for a reply... */
13606 static int q_or_quit (vat_main_t * vam)
13608 longjmp (vam->jump_buf, 1);
13609 return 0; /* not so much */
13611 static int q (vat_main_t * vam) {return q_or_quit (vam);}
13612 static int quit (vat_main_t * vam) {return q_or_quit (vam);}
13614 static int comment (vat_main_t * vam)
13619 static int cmd_cmp (void * a1, void * a2)
13624 return strcmp ((char *)(c1[0]), (char *)(c2[0]));
13627 static int help (vat_main_t * vam)
13632 unformat_input_t * i = vam->input;
13635 if (unformat (i, "%s", &name)) {
13640 hs = hash_get_mem (vam->help_by_name, name);
13642 fformat (vam->ofp, "usage: %s %s\n", name, hs[0]);
13644 fformat (vam->ofp, "No such msg / command '%s'\n", name);
13649 fformat(vam->ofp, "Help is available for the following:\n");
13651 hash_foreach_pair (p, vam->function_by_name,
13653 vec_add1 (cmds, (u8 *)(p->key));
13656 vec_sort_with_function (cmds, cmd_cmp);
13658 for (j = 0; j < vec_len(cmds); j++)
13659 fformat (vam->ofp, "%s\n", cmds[j]);
13665 static int set (vat_main_t * vam)
13667 u8 * name = 0, * value = 0;
13668 unformat_input_t * i = vam->input;
13670 if (unformat (i, "%s", &name)) {
13671 /* The input buffer is a vector, not a string. */
13672 value = vec_dup (i->buffer);
13673 vec_delete (value, i->index, 0);
13674 /* Almost certainly has a trailing newline */
13675 if (value[vec_len(value)-1] == '\n')
13676 value[vec_len(value)-1] = 0;
13677 /* Make sure it's a proper string, one way or the other */
13678 vec_add1 (value, 0);
13679 (void) clib_macro_set_value (&vam->macro_main,
13680 (char *)name, (char *)value);
13683 errmsg ("usage: set <name> <value>\n");
13690 static int unset (vat_main_t * vam)
13694 if (unformat (vam->input, "%s", &name))
13695 if (clib_macro_unset (&vam->macro_main, (char *)name) == 1)
13696 errmsg ("unset: %s wasn't set\n", name);
13707 static int macro_sort_cmp (void * a1, void * a2)
13709 macro_sort_t * s1 = a1;
13710 macro_sort_t * s2 = a2;
13712 return strcmp ((char *)(s1->name), (char *)(s2->name));
13715 static int dump_macro_table (vat_main_t * vam)
13717 macro_sort_t * sort_me = 0, * sm;
13721 hash_foreach_pair (p, vam->macro_main.the_value_table_hash,
13723 vec_add2 (sort_me, sm, 1);
13724 sm->name = (u8 *)(p->key);
13725 sm->value = (u8 *) (p->value[0]);
13728 vec_sort_with_function (sort_me, macro_sort_cmp);
13730 if (vec_len(sort_me))
13731 fformat (vam->ofp, "%-15s%s\n", "Name", "Value");
13733 fformat (vam->ofp, "The macro table is empty...\n");
13735 for (i = 0; i < vec_len (sort_me); i++)
13736 fformat (vam->ofp, "%-15s%s\n", sort_me[i].name,
13741 static int dump_node_table (vat_main_t * vam)
13744 vlib_node_t * node, * next_node;
13746 if (vec_len (vam->graph_nodes) == 0) {
13747 fformat (vam->ofp, "Node table empty, issue get_node_graph...\n");
13751 for (i = 0; i < vec_len (vam->graph_nodes); i++) {
13752 node = vam->graph_nodes[i];
13753 fformat (vam->ofp, "[%d] %s\n", i, node->name);
13754 for (j = 0; j < vec_len (node->next_nodes); j++) {
13755 if (node->next_nodes[j] != ~0) {
13756 next_node = vam->graph_nodes[node->next_nodes[j]];
13757 fformat (vam->ofp, " [%d] %s\n", j, next_node->name);
13764 static int search_node_table (vat_main_t * vam)
13766 unformat_input_t * line_input = vam->input;
13769 vlib_node_t * node, * next_node;
13772 if (vam->graph_node_index_by_name == 0) {
13773 fformat (vam->ofp, "Node table empty, issue get_node_graph...\n");
13777 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) {
13778 if (unformat (line_input, "%s", &node_to_find)) {
13779 vec_add1 (node_to_find, 0);
13780 p = hash_get_mem (vam->graph_node_index_by_name, node_to_find);
13782 fformat (vam->ofp, "%s not found...\n", node_to_find);
13785 node = vam->graph_nodes[p[0]];
13786 fformat (vam->ofp, "[%d] %s\n", p[0], node->name);
13787 for (j = 0; j < vec_len (node->next_nodes); j++) {
13788 if (node->next_nodes[j] != ~0) {
13789 next_node = vam->graph_nodes[node->next_nodes[j]];
13790 fformat (vam->ofp, " [%d] %s\n", j, next_node->name);
13796 clib_warning ("parse error '%U'", format_unformat_error,
13802 vec_free(node_to_find);
13810 static int script (vat_main_t * vam)
13813 char * save_current_file;
13814 unformat_input_t save_input;
13815 jmp_buf save_jump_buf;
13816 u32 save_line_number;
13818 FILE * new_fp, * save_ifp;
13820 if (unformat (vam->input, "%s", &s)) {
13821 new_fp = fopen ((char *)s, "r");
13823 errmsg ("Couldn't open script file %s\n", s);
13828 errmsg ("Missing script name\n");
13832 clib_memcpy (&save_input, &vam->input, sizeof (save_input));
13833 clib_memcpy (&save_jump_buf, &vam->jump_buf, sizeof (save_jump_buf));
13834 save_ifp = vam->ifp;
13835 save_line_number = vam->input_line_number;
13836 save_current_file = (char *) vam->current_file;
13838 vam->input_line_number = 0;
13840 vam->current_file = s;
13843 clib_memcpy (&vam->input, &save_input, sizeof (vam->input));
13844 clib_memcpy (&vam->jump_buf, &save_jump_buf, sizeof (save_jump_buf));
13845 vam->ifp = save_ifp;
13846 vam->input_line_number = save_line_number;
13847 vam->current_file = (u8 *) save_current_file;
13853 static int echo (vat_main_t * vam)
13855 fformat (vam->ofp, "%v", vam->input->buffer);
13859 /* List of API message constructors, CLI names map to api_xxx */
13860 #define foreach_vpe_api_msg \
13861 _(create_loopback,"[mac <mac-addr>]") \
13862 _(sw_interface_dump,"") \
13863 _(sw_interface_set_flags, \
13864 "<intfc> | sw_if_index <id> admin-up | admin-down link-up | link down") \
13865 _(sw_interface_add_del_address, \
13866 "<intfc> | sw_if_index <id> <ip4-address> | <ip6-address> [del] [del-all] ") \
13867 _(sw_interface_set_table, \
13868 "<intfc> | sw_if_index <id> vrf <table-id> [ipv6]") \
13869 _(sw_interface_set_vpath, \
13870 "<intfc> | sw_if_index <id> enable | disable") \
13871 _(sw_interface_set_l2_xconnect, \
13872 "rx <intfc> | rx_sw_if_index <id> tx <intfc> | tx_sw_if_index <id>\n" \
13873 "enable | disable") \
13874 _(sw_interface_set_l2_bridge, \
13875 "rx <intfc> | rx_sw_if_index <id> bd_id <bridge-domain-id>\n" \
13876 "[shg <split-horizon-group>] [bvi]\n" \
13877 "enable | disable") \
13878 _(bridge_domain_add_del, \
13879 "bd_id <bridge-domain-id> [flood 1|0] [uu-flood 1|0] [forward 1|0] [learn 1|0] [arp-term 1|0] [del]\n")\
13880 _(bridge_domain_dump, "[bd_id <bridge-domain-id>]\n") \
13882 "mac <mac-addr> bd_id <bridge-domain-id> [del] | sw_if <intfc> | sw_if_index <id> [static] [filter] [bvi] [count <nn>]\n") \
13884 "sw_if <intfc> | sw_if_index <id> [learn] [forward] [uu-flood] [flood]\n") \
13886 "bd_id <bridge-domain-id> [learn] [forward] [uu-flood] [flood] [arp-term] [disable]\n") \
13888 "tapname <name> mac <mac-addr> | random-mac") \
13890 "<vpp-if-name> | sw_if_index <id> tapname <name> mac <mac-addr> | random-mac") \
13892 "<vpp-if-name> | sw_if_index <id>") \
13893 _(sw_interface_tap_dump, "") \
13894 _(ip_add_del_route, \
13895 "<addr>/<mask> via <addr> [vrf <n>]\n" \
13896 "[<intfc> | sw_if_index <id>] [resolve-attempts <n>]\n" \
13897 "[weight <n>] [drop] [local] [classify <n>] [del]\n" \
13898 "[multipath] [count <n>]") \
13899 _(proxy_arp_add_del, \
13900 "<lo-ip4-addr> - <hi-ip4-addr> [vrf <n>] [del]") \
13901 _(proxy_arp_intfc_enable_disable, \
13902 "<intfc> | sw_if_index <id> enable | disable") \
13903 _(mpls_add_del_encap, \
13904 "label <n> dst <ip4-addr> [vrf <n>] [del]") \
13905 _(mpls_add_del_decap, \
13906 "label <n> [rx_vrf_id <n>] [tx_vrf_id] [s-bit-clear][del]") \
13907 _(mpls_gre_add_del_tunnel, \
13908 "inner_vrf_id <n> outer_vrf_id <n> src <ip4-address> dst <ip4-address>\n" \
13909 "adj <ip4-address>/<mask-width> [del]") \
13910 _(sw_interface_set_unnumbered, \
13911 "<intfc> | sw_if_index <id> unnum_if_index <id> [del]") \
13912 _(ip_neighbor_add_del, \
13913 "(<intfc> | sw_if_index <id>) dst <ip46-address> " \
13914 "[mac <mac-addr>] [vrf <vrf-id>] [is_static] [del]") \
13915 _(reset_vrf, "vrf <id> [ipv6]") \
13916 _(create_vlan_subif, "<intfc> | sw_if_index <id> vlan <n>") \
13917 _(create_subif, "<intfc> | sw_if_index <id> sub_id <n>\n" \
13918 "[outer_vlan_id <n>][inner_vlan_id <n>]\n" \
13919 "[no_tags][one_tag][two_tags][dot1ad][exact_match][default_sub]\n" \
13920 "[outer_vlan_id_any][inner_vlan_id_any]") \
13921 _(oam_add_del, "src <ip4-address> dst <ip4-address> [vrf <n>] [del]") \
13922 _(reset_fib, "vrf <n> [ipv6]") \
13923 _(dhcp_proxy_config, \
13924 "svr <v46-address> src <v46-address>\n" \
13925 "insert-cid <n> [del]") \
13926 _(dhcp_proxy_config_2, \
13927 "svr <v46-address> src <v46-address>\n" \
13928 "rx_vrf_id <nn> server_vrf_id <nn> insert-cid <n> [del]") \
13929 _(dhcp_proxy_set_vss, \
13930 "tbl_id <n> fib_id <n> oui <n> [ipv6] [del]") \
13931 _(dhcp_client_config, \
13932 "<intfc> | sw_if_index <id> [hostname <name>] [disable_event] [del]") \
13933 _(set_ip_flow_hash, \
13934 "vrf <n> [src] [dst] [sport] [dport] [proto] [reverse] [ipv6]") \
13935 _(sw_interface_ip6_enable_disable, \
13936 "<intfc> | sw_if_index <id> enable | disable") \
13937 _(sw_interface_ip6_set_link_local_address, \
13938 "<intfc> | sw_if_index <id> <ip6-address>/<mask-width>") \
13939 _(sw_interface_ip6nd_ra_prefix, \
13940 "<intfc> | sw_if_index <id> <ip6-address>/<mask-width>\n" \
13941 "val_life <n> pref_life <n> [def] [noadv] [offl] [noauto]\n" \
13942 "[nolink] [isno]") \
13943 _(sw_interface_ip6nd_ra_config, \
13944 "<intfc> | sw_if_index <id> [maxint <n>] [minint <n>]\n" \
13945 "[life <n>] [count <n>] [interval <n>] [suppress]\n" \
13946 "[managed] [other] [ll] [send] [cease] [isno] [def]") \
13947 _(set_arp_neighbor_limit, "arp_nbr_limit <n> [ipv6]") \
13948 _(l2_patch_add_del, \
13949 "rx <intfc> | rx_sw_if_index <id> tx <intfc> | tx_sw_if_index <id>\n" \
13950 "enable | disable") \
13951 _(mpls_ethernet_add_del_tunnel, \
13952 "tx <intfc> | tx_sw_if_index <n> dst <mac-addr>\n" \
13953 "adj <ip4-addr>/<mw> dst <mac-addr> [del]") \
13954 _(mpls_ethernet_add_del_tunnel_2, \
13955 "inner_vrf_id <n> outer_vrf_id <n> next-hop <ip4-addr>\n" \
13956 "resolve-attempts <n> resolve-if-needed 0 | 1 [del]") \
13957 _(sr_tunnel_add_del, \
13958 "[name <name>] src <ip6-addr> dst <ip6-addr>/<mw> \n" \
13959 "(next <ip6-addr>)+ [tag <ip6-addr>]* [clean] [reroute] \n" \
13960 "[policy <policy_name>]") \
13961 _(sr_policy_add_del, \
13962 "name <name> tunnel <tunnel-name> [tunnel <tunnel-name>]* [del]") \
13963 _(sr_multicast_map_add_del, \
13964 "address [ip6 multicast address] sr-policy [policy name] [del]") \
13965 _(classify_add_del_table, \
13966 "buckets <nn> [skip <n>] [match <n>] [memory_size <nn-bytes>]\n" \
13967 "[del] mask <mask-value>\n" \
13968 " [l2-miss-next | miss-next | acl-miss-next] <name|nn>") \
13969 _(classify_add_del_session, \
13970 "[hit-next|l2-hit-next|acl-hit-next|policer-hit-next] <name|nn>\n" \
13971 " table-index <nn> skip_n <nn> match_n <nn> match [hex] [l2]\n" \
13972 " [l3 [ip4|ip6]]") \
13973 _(classify_set_interface_ip_table, \
13974 "<intfc> | sw_if_index <nn> table <nn>") \
13975 _(classify_set_interface_l2_tables, \
13976 "<intfc> | sw_if_index <nn> [ip4-table <nn>] [ip6-table <nn>]\n" \
13977 " [other-table <nn>]") \
13978 _(get_node_index, "node <node-name") \
13979 _(add_node_next, "node <node-name> next <next-node-name>") \
13980 _(l2tpv3_create_tunnel, \
13981 "client_address <ip6-addr> our_address <ip6-addr>\n" \
13982 "[local_session_id <nn>][remote_session_id <nn>][local_cookie <nn>]\n"\
13983 "[remote_cookie <nn>]\n[l2-sublayer-preset]\n") \
13984 _(l2tpv3_set_tunnel_cookies, \
13985 "<intfc> | sw_if_index <nn> [new_local_cookie <nn>]\n" \
13986 "[new_remote_cookie <nn>]\n") \
13987 _(l2tpv3_interface_enable_disable, \
13988 "<intfc> | sw_if_index <nn> enable | disable") \
13989 _(l2tpv3_set_lookup_key, \
13990 "lookup_v6_src | lookup_v6_dst | lookup_session_id") \
13991 _(sw_if_l2tpv3_tunnel_dump, "") \
13992 _(vxlan_add_del_tunnel, \
13993 "src <ip-addr> dst <ip-addr> vni <vni> [encap-vrf-id <nn>]\n" \
13994 " [decap-next l2|ip4|ip6] [del]") \
13995 _(vxlan_tunnel_dump, "[<intfc> | sw_if_index <nn>]") \
13996 _(gre_add_del_tunnel, \
13997 "src <ip4-addr> dst <ip4-addr> [outer-fib-id <nn>] [del]\n") \
13998 _(gre_tunnel_dump, "[<intfc> | sw_if_index <nn>]") \
13999 _(l2_fib_clear_table, "") \
14000 _(l2_interface_efp_filter, "sw_if_index <nn> enable | disable") \
14001 _(l2_interface_vlan_tag_rewrite, \
14002 "<intfc> | sw_if_index <nn> \n" \
14003 "[disable][push-[1|2]][pop-[1|2]][translate-1-[1|2]] \n" \
14004 "[translate-2-[1|2]] [push_dot1q 0] tag1 <nn> tag2 <nn>") \
14005 _(create_vhost_user_if, \
14006 "socket <filename> [server] [renumber <dev_instance>] " \
14007 "[mac <mac_address>]") \
14008 _(modify_vhost_user_if, \
14009 "<intfc> | sw_if_index <nn> socket <filename>\n" \
14010 "[server] [renumber <dev_instance>]") \
14011 _(delete_vhost_user_if, "<intfc> | sw_if_index <nn>") \
14012 _(sw_interface_vhost_user_dump, "") \
14013 _(show_version, "") \
14014 _(vxlan_gpe_add_del_tunnel, \
14015 "local <addr> remote <addr> vni <nn>\n" \
14016 "[encap-vrf-id <nn>] [decap-vrf-id <nn>] [next-ip4][next-ip6]" \
14017 "[next-ethernet] [next-nsh]\n") \
14018 _(vxlan_gpe_tunnel_dump, "[<intfc> | sw_if_index <nn>]") \
14019 _(l2_fib_table_dump, "bd_id <bridge-domain-id>") \
14020 _(interface_name_renumber, \
14021 "<intfc> | sw_if_index <nn> new_show_dev_instance <nn>") \
14022 _(input_acl_set_interface, \
14023 "<intfc> | sw_if_index <nn> [ip4-table <nn>] [ip6-table <nn>]\n" \
14024 " [l2-table <nn>] [del]") \
14025 _(want_ip4_arp_events, "address <ip4-address> [del]") \
14026 _(ip_address_dump, "(ipv4 | ipv6) (<intfc> | sw_if_index <id>)") \
14027 _(ip_dump, "ipv4 | ipv6") \
14028 _(ipsec_spd_add_del, "spd_id <n> [del]") \
14029 _(ipsec_interface_add_del_spd, "(<intfc> | sw_if_index <id>)\n" \
14031 _(ipsec_sad_add_del_entry, "sad_id <n> spi <n> crypto_alg <alg>\n" \
14032 " crypto_key <hex> tunnel_src <ip4|ip6> tunnel_dst <ip4|ip6>\n" \
14033 " integ_alg <alg> integ_key <hex>") \
14034 _(ipsec_spd_add_del_entry, "spd_id <n> priority <n> action <action>\n" \
14035 " (inbound|outbound) [sa_id <n>] laddr_start <ip4|ip6>\n" \
14036 " laddr_stop <ip4|ip6> raddr_start <ip4|ip6> raddr_stop <ip4|ip6>\n" \
14037 " [lport_start <n> lport_stop <n>] [rport_start <n> rport_stop <n>]" )\
14038 _(ipsec_sa_set_key, "sa_id <n> crypto_key <hex> integ_key <hex>") \
14039 _(ikev2_profile_add_del, "name <profile_name> [del]") \
14040 _(ikev2_profile_set_auth, "name <profile_name> auth_method <method>\n" \
14041 "(auth_data 0x<data> | auth_data <data>)") \
14042 _(ikev2_profile_set_id, "name <profile_name> id_type <type>\n" \
14043 "(id_data 0x<data> | id_data <data>) (local|remote)") \
14044 _(ikev2_profile_set_ts, "name <profile_name> protocol <proto>\n" \
14045 "start_port <port> end_port <port> start_addr <ip4> end_addr <ip4>\n" \
14046 "(local|remote)") \
14047 _(ikev2_set_local_key, "file <absolute_file_path>") \
14048 _(delete_loopback,"sw_if_index <nn>") \
14049 _(bd_ip_mac_add_del, "bd_id <bridge-domain-id> <ip4/6-addr> <mac-addr> [del]") \
14050 _(map_add_domain, \
14051 "ip4-pfx <ip4pfx> ip6-pfx <ip6pfx> " \
14052 "ip6-src <ip6addr> " \
14053 "ea-bits-len <n> psid-offset <n> psid-len <n>") \
14054 _(map_del_domain, "index <n>") \
14055 _(map_add_del_rule, \
14056 "index <n> psid <n> dst <ip6addr> [del]") \
14057 _(map_domain_dump, "") \
14058 _(map_rule_dump, "index <map-domain>") \
14059 _(want_interface_events, "enable|disable") \
14060 _(want_stats,"enable|disable") \
14061 _(get_first_msg_id, "client <name>") \
14062 _(cop_interface_enable_disable, "<intfc> | sw_if_index <nn> [disable]") \
14063 _(cop_whitelist_enable_disable, "<intfc> | sw_if_index <nn>\n" \
14064 "fib-id <nn> [ip4][ip6][default]") \
14065 _(get_node_graph, " ") \
14066 _(sw_interface_clear_stats,"<intfc> | sw_if_index <nn>") \
14067 _(trace_profile_add, "id <nn> trace-type <0x1f|0x3|0x9|0x11|0x19> " \
14068 "trace-elts <nn> trace-tsp <0|1|2|3> node-id <node id in hex> " \
14069 "app-data <app_data in hex> [pow] [ppc <encap|decap>]") \
14070 _(trace_profile_apply, "id <nn> <ip6-address>/<width>" \
14071 " vrf_id <nn> add | pop | none") \
14072 _(trace_profile_del, "") \
14073 _(lisp_add_del_locator_set, "locator-set <locator_name> [iface <intf> |"\
14074 " sw_if_index <sw_if_index> p <priority> " \
14075 "w <weight>] [del]") \
14076 _(lisp_add_del_locator, "locator-set <locator_name> " \
14077 "iface <intf> | sw_if_index <sw_if_index> " \
14078 "p <priority> w <weight> [del]") \
14079 _(lisp_add_del_local_eid,"vni <vni> eid " \
14080 "<ipv4|ipv6>/<prefix> | <L2 address> " \
14081 "locator-set <locator_name> [del]") \
14082 _(lisp_gpe_add_del_fwd_entry, "rmt_eid <eid> [lcl_eid <eid>] vni <vni>" \
14083 "dp_table <table> loc-pair <lcl_loc> <rmt_loc> ... [del]") \
14084 _(lisp_add_del_map_resolver, "<ip4|6-addr> [del]") \
14085 _(lisp_gpe_enable_disable, "enable|disable") \
14086 _(lisp_enable_disable, "enable|disable") \
14087 _(lisp_gpe_add_del_iface, "up|down") \
14088 _(lisp_add_del_remote_mapping, "add|del vni <vni> deid <dest-eid> " \
14089 "rloc <locator> p <prio> " \
14090 "w <weight> [rloc <loc> ... ] " \
14091 "action <action> [del-all]") \
14092 _(lisp_add_del_adjacency, "add|del vni <vni> deid <dest-eid> seid " \
14093 "<src-eid> rloc <locator> p <prio> w <weight>"\
14094 "[rloc <loc> ... ] action <action>") \
14095 _(lisp_pitr_set_locator_set, "locator-set <loc-set-name> | del") \
14096 _(lisp_add_del_map_request_itr_rlocs, "<loc-set-name> [del]") \
14097 _(lisp_eid_table_add_del_map, "[del] vni <vni> vrf <vrf>") \
14098 _(lisp_locator_set_dump, "[locator-set-index <ls-index> | " \
14099 "locator-set <loc-set-name>] [local | remote]")\
14100 _(lisp_eid_table_dump, "[eid <ipv4|ipv6>/<prefix> | <mac>] [vni] " \
14101 "[local] | [remote]") \
14102 _(lisp_eid_table_map_dump, "") \
14103 _(lisp_gpe_tunnel_dump, "") \
14104 _(lisp_map_resolver_dump, "") \
14105 _(show_lisp_status, "") \
14106 _(lisp_get_map_request_itr_rlocs, "") \
14107 _(show_lisp_pitr, "") \
14108 _(af_packet_create, "name <host interface name> [hw_addr <mac>]") \
14109 _(af_packet_delete, "name <host interface name>") \
14110 _(policer_add_del, "name <policer name> <params> [del]") \
14111 _(policer_dump, "[name <policer name>]") \
14112 _(policer_classify_set_interface, \
14113 "<intfc> | sw_if_index <nn> [ip4-table <nn>] [ip6-table <nn>]\n" \
14114 " [l2-table <nn>] [del]") \
14115 _(policer_classify_dump, "type [ip4|ip6|l2]") \
14116 _(netmap_create, "name <interface name> [hw-addr <mac>] [pipe] " \
14117 "[master|slave]") \
14118 _(netmap_delete, "name <interface name>") \
14119 _(mpls_gre_tunnel_dump, "tunnel_index <tunnel-id>") \
14120 _(mpls_eth_tunnel_dump, "tunnel_index <tunnel-id>") \
14121 _(mpls_fib_encap_dump, "") \
14122 _(mpls_fib_decap_dump, "") \
14123 _(classify_table_ids, "") \
14124 _(classify_table_by_interface, "sw_if_index <sw_if_index>") \
14125 _(classify_table_info, "table_id <nn>") \
14126 _(classify_session_dump, "table_id <nn>") \
14127 _(ipfix_enable, "collector_address <ip4> [collector_port <nn>] " \
14128 "src_address <ip4> [fib_id <nn>] [path_mtu <nn>] " \
14129 "[template_interval <nn>]") \
14130 _(ipfix_dump, "") \
14131 _(get_next_index, "node-name <node-name> next-node-name <node-name>") \
14132 _(pg_create_interface, "if_id <nn>") \
14133 _(pg_capture, "if_id <nnn> pcap <file_name> count <nnn> [disable]") \
14134 _(pg_enable_disable, "[stream <id>] disable") \
14135 _(ip_source_and_port_range_check_add_del, \
14136 "<ip-addr>/<mask> range <nn>-<nn> vrf <id>") \
14137 _(ip_source_and_port_range_check_interface_add_del, \
14138 "<intf> | sw_if_index <nn> vrf <id>")
14140 /* List of command functions, CLI names map directly to functions */
14141 #define foreach_cli_function \
14142 _(comment, "usage: comment <ignore-rest-of-line>") \
14143 _(dump_interface_table, "usage: dump_interface_table") \
14144 _(dump_sub_interface_table, "usage: dump_sub_interface_table") \
14145 _(dump_ipv4_table, "usage: dump_ipv4_table") \
14146 _(dump_ipv6_table, "usage: dump_ipv6_table") \
14147 _(dump_stats_table, "usage: dump_stats_table") \
14148 _(dump_macro_table, "usage: dump_macro_table ") \
14149 _(dump_node_table, "usage: dump_node_table") \
14150 _(echo, "usage: echo <message>") \
14151 _(exec, "usage: exec <vpe-debug-CLI-command>") \
14152 _(help, "usage: help") \
14153 _(q, "usage: quit") \
14154 _(quit, "usage: quit") \
14155 _(search_node_table, "usage: search_node_table <name>...") \
14156 _(set, "usage: set <variable-name> <value>") \
14157 _(script, "usage: script <file-name>") \
14158 _(unset, "usage: unset <variable-name>")
14161 static void vl_api_##n##_t_handler_uni \
14162 (vl_api_##n##_t * mp) \
14164 vat_main_t * vam = &vat_main; \
14165 if (vam->json_output) { \
14166 vl_api_##n##_t_handler_json(mp); \
14168 vl_api_##n##_t_handler(mp); \
14171 foreach_vpe_api_reply_msg;
14174 void vat_api_hookup (vat_main_t *vam)
14177 vl_msg_api_set_handlers(VL_API_##N, #n, \
14178 vl_api_##n##_t_handler_uni, \
14180 vl_api_##n##_t_endian, \
14181 vl_api_##n##_t_print, \
14182 sizeof(vl_api_##n##_t), 1);
14183 foreach_vpe_api_reply_msg;
14186 vl_msg_api_set_first_available_msg_id (VL_MSG_FIRST_AVAILABLE);
14188 vam->sw_if_index_by_interface_name =
14189 hash_create_string (0, sizeof (uword));
14191 vam->function_by_name =
14192 hash_create_string (0, sizeof(uword));
14194 vam->help_by_name =
14195 hash_create_string (0, sizeof(uword));
14197 /* API messages we can send */
14198 #define _(n,h) hash_set_mem (vam->function_by_name, #n, api_##n);
14199 foreach_vpe_api_msg;
14203 #define _(n,h) hash_set_mem (vam->help_by_name, #n, h);
14204 foreach_vpe_api_msg;
14207 /* CLI functions */
14208 #define _(n,h) hash_set_mem (vam->function_by_name, #n, n);
14209 foreach_cli_function;
14213 #define _(n,h) hash_set_mem (vam->help_by_name, #n, h);
14214 foreach_cli_function;
14218 #undef vl_api_version
14219 #define vl_api_version(n,v) static u32 vpe_api_version = v;
14220 #include <vpp-api/vpe.api.h>
14221 #undef vl_api_version
14223 void vl_client_add_api_signatures (vl_api_memclnt_create_t *mp)
14226 * Send the main API signature in slot 0. This bit of code must
14227 * match the checks in ../vpe/api/api.c: vl_msg_api_version_check().
14229 mp->api_versions[0] = clib_host_to_net_u32 (vpe_api_version);