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 <api/vpe_msg_enum.h>
34 #include <vnet/l2/l2_classify.h>
35 #include <vnet/l2/l2_vtr.h>
36 #include <vnet/classify/input_acl.h>
37 #include <vnet/mpls-gre/mpls.h>
39 #include <vnet/ipsec/ipsec.h>
40 #include <vnet/ipsec/ikev2.h>
44 #include <vnet/map/map.h>
45 #include <vnet/cop/cop.h>
46 #include <vnet/ip/ip6_hop_by_hop.h>
47 #include <vnet/policer/xlate.h>
49 #include "vat/json_format.h"
51 #define vl_typedefs /* define message structures */
52 #include <api/vpe_all_api_h.h>
55 /* declare message handlers for each api */
57 #define vl_endianfun /* define message structures */
58 #include <api/vpe_all_api_h.h>
61 /* instantiate all the print functions we know about */
62 #define vl_print(handle, ...)
64 #include <api/vpe_all_api_h.h>
67 uword unformat_sw_if_index (unformat_input_t * input, va_list * args)
69 vat_main_t * vam = va_arg (*args, vat_main_t *);
70 u32 * result = va_arg (*args, u32 *);
74 if (!unformat (input, "%s", &if_name))
77 p = hash_get_mem (vam->sw_if_index_by_interface_name, if_name);
84 /* Parse an IP4 address %d.%d.%d.%d. */
85 uword unformat_ip4_address (unformat_input_t * input, va_list * args)
87 u8 * result = va_arg (*args, u8 *);
90 if (! unformat (input, "%d.%d.%d.%d", &a[0], &a[1], &a[2], &a[3]))
93 if (a[0] >= 256 || a[1] >= 256 || a[2] >= 256 || a[3] >= 256)
106 unformat_ethernet_address (unformat_input_t * input, va_list * args)
108 u8 * result = va_arg (*args, u8 *);
111 if (! unformat (input, "%_%x:%x:%x:%x:%x:%x%_",
112 &a[0], &a[1], &a[2], &a[3], &a[4], &a[5]))
116 for (i = 0; i < 6; i++)
117 if (a[i] >= (1 << 8))
120 for (i = 0; i < 6; i++)
126 /* Returns ethernet type as an int in host byte order. */
128 unformat_ethernet_type_host_byte_order (unformat_input_t * input,
131 u16 * result = va_arg (*args, u16 *);
135 if (unformat (input, "0x%x", &type)
136 || unformat (input, "%d", &type))
138 if (type >= (1 << 16))
146 /* Parse an IP6 address. */
147 uword unformat_ip6_address (unformat_input_t * input, va_list * args)
149 ip6_address_t * result = va_arg (*args, ip6_address_t *);
151 uword hex_quad, n_hex_quads, hex_digit, n_hex_digits;
152 uword c, n_colon, double_colon_index;
154 n_hex_quads = hex_quad = n_hex_digits = n_colon = 0;
155 double_colon_index = ARRAY_LEN (hex_quads);
156 while ((c = unformat_get_input (input)) != UNFORMAT_END_OF_INPUT)
159 if (c >= '0' && c <= '9')
161 else if (c >= 'a' && c <= 'f')
162 hex_digit = c + 10 - 'a';
163 else if (c >= 'A' && c <= 'F')
164 hex_digit = c + 10 - 'A';
165 else if (c == ':' && n_colon < 2)
169 unformat_put_input (input);
173 /* Too many hex quads. */
174 if (n_hex_quads >= ARRAY_LEN (hex_quads))
179 hex_quad = (hex_quad << 4) | hex_digit;
181 /* Hex quad must fit in 16 bits. */
182 if (n_hex_digits >= 4)
189 /* Save position of :: */
192 /* More than one :: ? */
193 if (double_colon_index < ARRAY_LEN (hex_quads))
195 double_colon_index = n_hex_quads;
198 if (n_colon > 0 && n_hex_digits > 0)
200 hex_quads[n_hex_quads++] = hex_quad;
206 if (n_hex_digits > 0)
207 hex_quads[n_hex_quads++] = hex_quad;
212 /* Expand :: to appropriate number of zero hex quads. */
213 if (double_colon_index < ARRAY_LEN (hex_quads))
215 word n_zero = ARRAY_LEN (hex_quads) - n_hex_quads;
217 for (i = n_hex_quads - 1; i >= (signed) double_colon_index; i--)
218 hex_quads[n_zero + i] = hex_quads[i];
220 for (i = 0; i < n_zero; i++)
221 hex_quads[double_colon_index + i] = 0;
223 n_hex_quads = ARRAY_LEN (hex_quads);
226 /* Too few hex quads given. */
227 if (n_hex_quads < ARRAY_LEN (hex_quads))
230 for (i = 0; i < ARRAY_LEN (hex_quads); i++)
231 result->as_u16[i] = clib_host_to_net_u16 (hex_quads[i]);
238 unformat_ipsec_policy_action (unformat_input_t * input, va_list * args)
241 u32 * r = va_arg (*args, u32 *);
244 #define _(v,f,s) else if (unformat (input, s)) *r = IPSEC_POLICY_ACTION_##f;
245 foreach_ipsec_policy_action
256 unformat_ipsec_crypto_alg (unformat_input_t * input, va_list * args)
259 u32 * r = va_arg (*args, u32 *);
262 #define _(v,f,s) else if (unformat (input, s)) *r = IPSEC_CRYPTO_ALG_##f;
263 foreach_ipsec_crypto_alg
274 format_ipsec_crypto_alg (u8 * s, va_list * args)
277 u32 i = va_arg (*args, u32);
282 #define _(v,f,str) case IPSEC_CRYPTO_ALG_##f: t = (u8 *) str; break;
283 foreach_ipsec_crypto_alg
286 return format (s, "unknown");
288 return format (s, "%s", t);
290 return format (s, "Unimplemented");
295 unformat_ipsec_integ_alg (unformat_input_t * input, va_list * args)
298 u32 * r = va_arg (*args, u32 *);
301 #define _(v,f,s) else if (unformat (input, s)) *r = IPSEC_INTEG_ALG_##f;
302 foreach_ipsec_integ_alg
313 format_ipsec_integ_alg (u8 * s, va_list * args)
316 u32 i = va_arg (*args, u32);
321 #define _(v,f,str) case IPSEC_INTEG_ALG_##f: t = (u8 *) str; break;
322 foreach_ipsec_integ_alg
325 return format (s, "unknown");
327 return format (s, "%s", t);
329 return format (s, "Unsupported");
334 unformat_ikev2_auth_method (unformat_input_t * input, va_list * args)
337 u32 * r = va_arg (*args, u32 *);
340 #define _(v,f,s) else if (unformat (input, s)) *r = IKEV2_AUTH_METHOD_##f;
341 foreach_ikev2_auth_method
352 unformat_ikev2_id_type (unformat_input_t * input, va_list * args)
355 u32 * r = va_arg (*args, u32 *);
358 #define _(v,f,s) else if (unformat (input, s)) *r = IKEV2_ID_TYPE_##f;
359 foreach_ikev2_id_type
370 unformat_policer_rate_type (unformat_input_t * input, va_list * args)
372 u8 * r = va_arg (*args, u8 *);
374 if (unformat (input, "kbps"))
375 *r = SSE2_QOS_RATE_KBPS;
376 else if (unformat(input, "pps"))
377 *r = SSE2_QOS_RATE_PPS;
384 unformat_policer_round_type (unformat_input_t * input, va_list * args)
386 u8 * r = va_arg (*args, u8 *);
388 if (unformat(input, "closest"))
389 *r = SSE2_QOS_ROUND_TO_CLOSEST;
390 else if (unformat (input, "up"))
391 *r = SSE2_QOS_ROUND_TO_UP;
392 else if (unformat (input, "down"))
393 *r = SSE2_QOS_ROUND_TO_DOWN;
400 unformat_policer_type (unformat_input_t * input, va_list * args)
402 u8 * r = va_arg (*args, u8 *);
404 if (unformat (input, "1r2c"))
405 *r = SSE2_QOS_POLICER_TYPE_1R2C;
406 else if (unformat (input, "1r3c"))
407 *r = SSE2_QOS_POLICER_TYPE_1R3C_RFC_2697;
408 else if (unformat (input, "2r3c-2698"))
409 *r = SSE2_QOS_POLICER_TYPE_2R3C_RFC_2698;
410 else if (unformat (input, "2r3c-4115"))
411 *r = SSE2_QOS_POLICER_TYPE_2R3C_RFC_4115;
412 else if (unformat (input, "2r3c-mef5cf1"))
413 *r = SSE2_QOS_POLICER_TYPE_2R3C_RFC_MEF5CF1;
419 u8 * format_ip4_address (u8 * s, va_list * args)
421 u8 * a = va_arg (*args, u8 *);
422 return format (s, "%d.%d.%d.%d", a[0], a[1], a[2], a[3]);
425 u8 * format_ip6_address (u8 * s, va_list * args)
427 ip6_address_t * a = va_arg (*args, ip6_address_t *);
428 u32 i, i_max_n_zero, max_n_zeros, i_first_zero, n_zeros, last_double_colon;
430 i_max_n_zero = ARRAY_LEN (a->as_u16);
432 i_first_zero = i_max_n_zero;
434 for (i = 0; i < ARRAY_LEN (a->as_u16); i++)
436 u32 is_zero = a->as_u16[i] == 0;
437 if (is_zero && i_first_zero >= ARRAY_LEN (a->as_u16))
443 if ((! is_zero && n_zeros > max_n_zeros)
444 || (i + 1 >= ARRAY_LEN (a->as_u16) && n_zeros > max_n_zeros))
446 i_max_n_zero = i_first_zero;
447 max_n_zeros = n_zeros;
448 i_first_zero = ARRAY_LEN (a->as_u16);
453 last_double_colon = 0;
454 for (i = 0; i < ARRAY_LEN (a->as_u16); i++)
456 if (i == i_max_n_zero && max_n_zeros > 1)
458 s = format (s, "::");
459 i += max_n_zeros - 1;
460 last_double_colon = 1;
464 s = format (s, "%s%x",
465 (last_double_colon || i == 0) ? "" : ":",
466 clib_net_to_host_u16 (a->as_u16[i]));
467 last_double_colon = 0;
474 /* Format an IP46 address. */
475 u8 * format_ip46_address (u8 * s, va_list * args)
477 ip46_address_t *ip46 = va_arg (*args, ip46_address_t *);
478 ip46_type_t type = va_arg (*args, ip46_type_t);
484 is_ip4 = ip46_address_is_ip4(ip46);
495 format(s, "%U", format_ip4_address, &ip46->ip4):
496 format(s, "%U", format_ip6_address, &ip46->ip6);
499 u8 * format_ethernet_address (u8 * s, va_list * args)
501 u8 * a = va_arg (*args, u8 *);
503 return format (s, "%02x:%02x:%02x:%02x:%02x:%02x",
504 a[0], a[1], a[2], a[3], a[4], a[5]);
507 void increment_v4_address (ip4_address_t * a)
511 v = ntohl(a->as_u32) + 1;
512 a->as_u32 = ntohl(v);
515 void increment_v6_address (ip6_address_t * a)
519 v0 = clib_net_to_host_u64 (a->as_u64[0]);
520 v1 = clib_net_to_host_u64 (a->as_u64[1]);
525 a->as_u64[0] = clib_net_to_host_u64 (v0);
526 a->as_u64[1] = clib_net_to_host_u64 (v1);
530 static void vl_api_create_loopback_reply_t_handler
531 (vl_api_create_loopback_reply_t * mp)
533 vat_main_t * vam = &vat_main;
534 i32 retval = ntohl(mp->retval);
536 vam->retval = retval;
537 vam->regenerate_interface_table = 1;
538 vam->sw_if_index = ntohl (mp->sw_if_index);
539 vam->result_ready = 1;
542 static void vl_api_create_loopback_reply_t_handler_json
543 (vl_api_create_loopback_reply_t * mp)
545 vat_main_t * vam = &vat_main;
546 vat_json_node_t node;
548 vat_json_init_object(&node);
549 vat_json_object_add_int(&node, "retval", ntohl(mp->retval));
550 vat_json_object_add_uint(&node, "sw_if_index", ntohl(mp->sw_if_index));
552 vat_json_print(vam->ofp, &node);
553 vat_json_free(&node);
554 vam->retval = ntohl(mp->retval);
555 vam->result_ready = 1;
558 static void vl_api_af_packet_create_reply_t_handler
559 (vl_api_af_packet_create_reply_t * mp)
561 vat_main_t * vam = &vat_main;
562 i32 retval = ntohl(mp->retval);
564 vam->retval = retval;
565 vam->regenerate_interface_table = 1;
566 vam->sw_if_index = ntohl (mp->sw_if_index);
567 vam->result_ready = 1;
570 static void vl_api_af_packet_create_reply_t_handler_json
571 (vl_api_af_packet_create_reply_t * mp)
573 vat_main_t * vam = &vat_main;
574 vat_json_node_t node;
576 vat_json_init_object(&node);
577 vat_json_object_add_int(&node, "retval", ntohl(mp->retval));
578 vat_json_object_add_uint(&node, "sw_if_index", ntohl(mp->sw_if_index));
580 vat_json_print(vam->ofp, &node);
581 vat_json_free(&node);
583 vam->retval = ntohl(mp->retval);
584 vam->result_ready = 1;
587 static void vl_api_create_vlan_subif_reply_t_handler
588 (vl_api_create_vlan_subif_reply_t * mp)
590 vat_main_t * vam = &vat_main;
591 i32 retval = ntohl(mp->retval);
593 vam->retval = retval;
594 vam->regenerate_interface_table = 1;
595 vam->sw_if_index = ntohl (mp->sw_if_index);
596 vam->result_ready = 1;
599 static void vl_api_create_vlan_subif_reply_t_handler_json
600 (vl_api_create_vlan_subif_reply_t * mp)
602 vat_main_t * vam = &vat_main;
603 vat_json_node_t node;
605 vat_json_init_object(&node);
606 vat_json_object_add_int(&node, "retval", ntohl(mp->retval));
607 vat_json_object_add_uint(&node, "sw_if_index", ntohl(mp->sw_if_index));
609 vat_json_print(vam->ofp, &node);
610 vat_json_free(&node);
612 vam->retval = ntohl(mp->retval);
613 vam->result_ready = 1;
616 static void vl_api_create_subif_reply_t_handler
617 (vl_api_create_subif_reply_t * mp)
619 vat_main_t * vam = &vat_main;
620 i32 retval = ntohl(mp->retval);
622 vam->retval = retval;
623 vam->regenerate_interface_table = 1;
624 vam->sw_if_index = ntohl (mp->sw_if_index);
625 vam->result_ready = 1;
628 static void vl_api_create_subif_reply_t_handler_json
629 (vl_api_create_subif_reply_t * mp)
631 vat_main_t * vam = &vat_main;
632 vat_json_node_t node;
634 vat_json_init_object(&node);
635 vat_json_object_add_int(&node, "retval", ntohl(mp->retval));
636 vat_json_object_add_uint(&node, "sw_if_index", ntohl(mp->sw_if_index));
638 vat_json_print(vam->ofp, &node);
639 vat_json_free(&node);
641 vam->retval = ntohl(mp->retval);
642 vam->result_ready = 1;
645 static void vl_api_interface_name_renumber_reply_t_handler
646 (vl_api_interface_name_renumber_reply_t * mp)
648 vat_main_t * vam = &vat_main;
649 i32 retval = ntohl(mp->retval);
651 vam->retval = retval;
652 vam->regenerate_interface_table = 1;
653 vam->result_ready = 1;
656 static void vl_api_interface_name_renumber_reply_t_handler_json
657 (vl_api_interface_name_renumber_reply_t * mp)
659 vat_main_t * vam = &vat_main;
660 vat_json_node_t node;
662 vat_json_init_object(&node);
663 vat_json_object_add_int(&node, "retval", ntohl(mp->retval));
665 vat_json_print(vam->ofp, &node);
666 vat_json_free(&node);
668 vam->retval = ntohl(mp->retval);
669 vam->result_ready = 1;
673 * Special-case: build the interface table, maintain
674 * the next loopback sw_if_index vbl.
676 static void vl_api_sw_interface_details_t_handler
677 (vl_api_sw_interface_details_t * mp)
679 vat_main_t * vam = &vat_main;
680 u8 * s = format (0, "%s%c", mp->interface_name, 0);
682 hash_set_mem (vam->sw_if_index_by_interface_name, s,
683 ntohl(mp->sw_if_index));
685 /* In sub interface case, fill the sub interface table entry */
686 if (mp->sw_if_index != mp->sup_sw_if_index) {
687 sw_interface_subif_t * sub = NULL;
689 vec_add2(vam->sw_if_subif_table, sub, 1);
691 vec_validate(sub->interface_name, strlen((char *)s) + 1);
692 strncpy((char *)sub->interface_name, (char *)s,
693 vec_len(sub->interface_name));
694 sub->sw_if_index = ntohl(mp->sw_if_index);
695 sub->sub_id = ntohl(mp->sub_id);
697 sub->sub_dot1ad = mp->sub_dot1ad;
698 sub->sub_number_of_tags = mp->sub_number_of_tags;
699 sub->sub_outer_vlan_id = ntohs(mp->sub_outer_vlan_id);
700 sub->sub_inner_vlan_id = ntohs(mp->sub_inner_vlan_id);
701 sub->sub_exact_match = mp->sub_exact_match;
702 sub->sub_default = mp->sub_default;
703 sub->sub_outer_vlan_id_any = mp->sub_outer_vlan_id_any;
704 sub->sub_inner_vlan_id_any = mp->sub_inner_vlan_id_any;
706 /* vlan tag rewrite */
707 sub->vtr_op = ntohl(mp->vtr_op);
708 sub->vtr_push_dot1q = ntohl(mp->vtr_push_dot1q);
709 sub->vtr_tag1 = ntohl(mp->vtr_tag1);
710 sub->vtr_tag2 = ntohl(mp->vtr_tag2);
714 static void vl_api_sw_interface_details_t_handler_json
715 (vl_api_sw_interface_details_t * mp)
717 vat_main_t * vam = &vat_main;
718 vat_json_node_t *node = NULL;
720 if (VAT_JSON_ARRAY != vam->json_tree.type) {
721 ASSERT(VAT_JSON_NONE == vam->json_tree.type);
722 vat_json_init_array(&vam->json_tree);
724 node = vat_json_array_add(&vam->json_tree);
726 vat_json_init_object(node);
727 vat_json_object_add_uint(node, "sw_if_index", ntohl(mp->sw_if_index));
728 vat_json_object_add_uint(node, "sup_sw_if_index", ntohl(mp->sup_sw_if_index));
729 vat_json_object_add_uint(node, "l2_address_length", ntohl(mp->l2_address_length));
730 vat_json_object_add_bytes(node, "l2_address", mp->l2_address, sizeof(mp->l2_address));
731 vat_json_object_add_string_copy(node, "interface_name", mp->interface_name);
732 vat_json_object_add_uint(node, "admin_up_down", mp->admin_up_down);
733 vat_json_object_add_uint(node, "link_up_down", mp->link_up_down);
734 vat_json_object_add_uint(node, "link_duplex", mp->link_duplex);
735 vat_json_object_add_uint(node, "link_speed", mp->link_speed);
736 vat_json_object_add_uint(node, "mtu", ntohs(mp->link_mtu));
737 vat_json_object_add_uint(node, "sub_id", ntohl(mp->sub_id));
738 vat_json_object_add_uint(node, "sub_dot1ad", mp->sub_dot1ad);
739 vat_json_object_add_uint(node, "sub_number_of_tags", mp->sub_number_of_tags);
740 vat_json_object_add_uint(node, "sub_outer_vlan_id", ntohs(mp->sub_outer_vlan_id));
741 vat_json_object_add_uint(node, "sub_inner_vlan_id", ntohs(mp->sub_inner_vlan_id));
742 vat_json_object_add_uint(node, "sub_exact_match", mp->sub_exact_match);
743 vat_json_object_add_uint(node, "sub_default", mp->sub_default);
744 vat_json_object_add_uint(node, "sub_outer_vlan_id_any", mp->sub_outer_vlan_id_any);
745 vat_json_object_add_uint(node, "sub_inner_vlan_id_any", mp->sub_inner_vlan_id_any);
746 vat_json_object_add_uint(node, "vtr_op", ntohl(mp->vtr_op));
747 vat_json_object_add_uint(node, "vtr_push_dot1q", ntohl(mp->vtr_push_dot1q));
748 vat_json_object_add_uint(node, "vtr_tag1", ntohl(mp->vtr_tag1));
749 vat_json_object_add_uint(node, "vtr_tag2", ntohl(mp->vtr_tag2));
752 static void vl_api_sw_interface_set_flags_t_handler
753 (vl_api_sw_interface_set_flags_t * mp)
755 vat_main_t * vam = &vat_main;
756 if (vam->interface_event_display)
757 errmsg ("interface flags: sw_if_index %d %s %s\n",
758 ntohl(mp->sw_if_index),
759 mp->admin_up_down ? "admin-up" : "admin-down",
760 mp->link_up_down ? "link-up" : "link-down");
763 static void vl_api_sw_interface_set_flags_t_handler_json
764 (vl_api_sw_interface_set_flags_t * mp)
766 /* JSON output not supported */
769 static void vl_api_cli_reply_t_handler
770 (vl_api_cli_reply_t * mp)
772 vat_main_t * vam = &vat_main;
773 i32 retval = ntohl(mp->retval);
775 vam->retval = retval;
776 vam->shmem_result = (u8 *) mp->reply_in_shmem;
777 vam->result_ready = 1;
780 static void vl_api_cli_reply_t_handler_json
781 (vl_api_cli_reply_t * mp)
783 vat_main_t * vam = &vat_main;
784 vat_json_node_t node;
785 api_main_t * am = &api_main;
789 vat_json_init_object(&node);
790 vat_json_object_add_int(&node, "retval", ntohl(mp->retval));
791 vat_json_object_add_uint(&node, "reply_in_shmem",
792 ntohl(mp->reply_in_shmem));
793 /* Toss the shared-memory original... */
794 pthread_mutex_lock (&am->vlib_rp->mutex);
795 oldheap = svm_push_data_heap (am->vlib_rp);
797 reply = (u8 *)(mp->reply_in_shmem);
800 svm_pop_heap (oldheap);
801 pthread_mutex_unlock (&am->vlib_rp->mutex);
803 vat_json_print(vam->ofp, &node);
804 vat_json_free(&node);
806 vam->retval = ntohl(mp->retval);
807 vam->result_ready = 1;
810 static void vl_api_classify_add_del_table_reply_t_handler
811 (vl_api_classify_add_del_table_reply_t * mp)
813 vat_main_t * vam = &vat_main;
814 i32 retval = ntohl(mp->retval);
815 if (vam->async_mode) {
816 vam->async_errors += (retval < 0);
818 vam->retval = retval;
820 ((mp->new_table_index != 0xFFFFFFFF) ||
821 (mp->skip_n_vectors != 0xFFFFFFFF) ||
822 (mp->match_n_vectors != 0xFFFFFFFF)))
824 * Note: this is just barely thread-safe, depends on
825 * the main thread spinning waiting for an answer...
827 errmsg ("new index %d, skip_n_vectors %d, match_n_vectors %d\n",
828 ntohl(mp->new_table_index),
829 ntohl(mp->skip_n_vectors), ntohl(mp->match_n_vectors));
830 vam->result_ready = 1;
834 static void vl_api_classify_add_del_table_reply_t_handler_json
835 (vl_api_classify_add_del_table_reply_t * mp)
837 vat_main_t * vam = &vat_main;
838 vat_json_node_t node;
840 vat_json_init_object(&node);
841 vat_json_object_add_int(&node, "retval", ntohl(mp->retval));
842 vat_json_object_add_uint(&node, "new_table_index", ntohl(mp->new_table_index));
843 vat_json_object_add_uint(&node, "skip_n_vectors", ntohl(mp->skip_n_vectors));
844 vat_json_object_add_uint(&node, "match_n_vectors", ntohl(mp->match_n_vectors));
846 vat_json_print(vam->ofp, &node);
847 vat_json_free(&node);
849 vam->retval = ntohl(mp->retval);
850 vam->result_ready = 1;
853 static void vl_api_get_node_index_reply_t_handler
854 (vl_api_get_node_index_reply_t * mp)
856 vat_main_t * vam = &vat_main;
857 i32 retval = ntohl(mp->retval);
858 if (vam->async_mode) {
859 vam->async_errors += (retval < 0);
861 vam->retval = retval;
863 errmsg ("node index %d\n", ntohl(mp->node_index));
864 vam->result_ready = 1;
868 static void vl_api_get_node_index_reply_t_handler_json
869 (vl_api_get_node_index_reply_t * mp)
871 vat_main_t * vam = &vat_main;
872 vat_json_node_t node;
874 vat_json_init_object(&node);
875 vat_json_object_add_int(&node, "retval", ntohl(mp->retval));
876 vat_json_object_add_uint(&node, "node_index", ntohl(mp->node_index));
878 vat_json_print(vam->ofp, &node);
879 vat_json_free(&node);
881 vam->retval = ntohl(mp->retval);
882 vam->result_ready = 1;
885 static void vl_api_add_node_next_reply_t_handler
886 (vl_api_add_node_next_reply_t * mp)
888 vat_main_t * vam = &vat_main;
889 i32 retval = ntohl(mp->retval);
890 if (vam->async_mode) {
891 vam->async_errors += (retval < 0);
893 vam->retval = retval;
895 errmsg ("next index %d\n", ntohl(mp->next_index));
896 vam->result_ready = 1;
900 static void vl_api_add_node_next_reply_t_handler_json
901 (vl_api_add_node_next_reply_t * mp)
903 vat_main_t * vam = &vat_main;
904 vat_json_node_t node;
906 vat_json_init_object(&node);
907 vat_json_object_add_int(&node, "retval", ntohl(mp->retval));
908 vat_json_object_add_uint(&node, "next_index", ntohl(mp->next_index));
910 vat_json_print(vam->ofp, &node);
911 vat_json_free(&node);
913 vam->retval = ntohl(mp->retval);
914 vam->result_ready = 1;
917 static void vl_api_mpls_gre_add_del_tunnel_reply_t_handler
918 (vl_api_mpls_gre_add_del_tunnel_reply_t * mp)
920 vat_main_t * vam = &vat_main;
921 i32 retval = ntohl(mp->retval);
922 u32 sw_if_index = ntohl(mp->tunnel_sw_if_index);
924 if (retval >= 0 && sw_if_index != (u32)~0) {
925 errmsg ("tunnel_sw_if_index %d\n", sw_if_index);
927 vam->retval = retval;
928 vam->result_ready = 1;
931 static void vl_api_mpls_gre_add_del_tunnel_reply_t_handler_json
932 (vl_api_mpls_gre_add_del_tunnel_reply_t * mp)
934 vat_main_t * vam = &vat_main;
935 vat_json_node_t node;
937 vat_json_init_object(&node);
938 vat_json_object_add_int(&node, "retval", ntohl(mp->retval));
939 vat_json_object_add_uint(&node, "tunnel_sw_if_index", ntohl(mp->tunnel_sw_if_index));
941 vat_json_print(vam->ofp, &node);
942 vat_json_free(&node);
944 vam->retval = ntohl(mp->retval);
945 vam->result_ready = 1;
949 static void vl_api_show_version_reply_t_handler
950 (vl_api_show_version_reply_t * mp)
952 vat_main_t * vam = &vat_main;
953 i32 retval = ntohl(mp->retval);
956 errmsg (" program: %s\n", mp->program);
957 errmsg (" version: %s\n", mp->version);
958 errmsg (" build date: %s\n", mp->build_date);
959 errmsg ("build directory: %s\n", mp->build_directory);
961 vam->retval = retval;
962 vam->result_ready = 1;
965 static void vl_api_show_version_reply_t_handler_json
966 (vl_api_show_version_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_string_copy(&node, "program", mp->program);
974 vat_json_object_add_string_copy(&node, "version", mp->version);
975 vat_json_object_add_string_copy(&node, "build_date", mp->build_date);
976 vat_json_object_add_string_copy(&node, "build_directory", mp->build_directory);
978 vat_json_print(vam->ofp, &node);
979 vat_json_free(&node);
981 vam->retval = ntohl(mp->retval);
982 vam->result_ready = 1;
985 static void vl_api_ip4_arp_event_t_handler
986 (vl_api_ip4_arp_event_t * mp)
988 vat_main_t * vam = &vat_main;
989 errmsg ("arp event: address %U new mac %U sw_if_index %d\n",
990 format_ip4_address, &mp->address,
991 format_ethernet_address, mp->new_mac, mp->sw_if_index);
994 static void vl_api_ip4_arp_event_t_handler_json
995 (vl_api_ip4_arp_event_t * mp)
997 /* JSON output not supported */
1001 * Special-case: build the bridge domain table, maintain
1002 * the next bd id vbl.
1004 static void vl_api_bridge_domain_details_t_handler
1005 (vl_api_bridge_domain_details_t * mp)
1007 vat_main_t * vam = &vat_main;
1008 u32 n_sw_ifs = ntohl (mp->n_sw_ifs);
1010 fformat (vam->ofp, "\n%-3s %-3s %-3s %-3s %-3s %-3s\n",
1011 " ID", "LRN", "FWD", "FLD", "BVI", "#IF");
1013 fformat (vam->ofp, "%3d %3d %3d %3d %3d %3d\n",
1014 ntohl (mp->bd_id), mp->learn, mp->forward,
1015 mp->flood, ntohl (mp->bvi_sw_if_index), n_sw_ifs);
1018 fformat (vam->ofp, "\n\n%s %s %s\n", "sw_if_index", "SHG",
1022 static void vl_api_bridge_domain_details_t_handler_json
1023 (vl_api_bridge_domain_details_t * mp)
1025 vat_main_t * vam = &vat_main;
1026 vat_json_node_t *node, *array = NULL;
1028 if (VAT_JSON_ARRAY != vam->json_tree.type) {
1029 ASSERT(VAT_JSON_NONE == vam->json_tree.type);
1030 vat_json_init_array(&vam->json_tree);
1032 node = vat_json_array_add(&vam->json_tree);
1034 vat_json_init_object(node);
1035 vat_json_object_add_uint(node, "bd_id", ntohl(mp->bd_id));
1036 vat_json_object_add_uint(node, "flood", mp->flood);
1037 vat_json_object_add_uint(node, "forward", mp->forward);
1038 vat_json_object_add_uint(node, "learn", mp->learn);
1039 vat_json_object_add_uint(node, "bvi_sw_if_index", ntohl(mp->bvi_sw_if_index));
1040 vat_json_object_add_uint(node, "n_sw_ifs", ntohl(mp->n_sw_ifs));
1041 array = vat_json_object_add(node, "sw_if");
1042 vat_json_init_array(array);
1046 * Special-case: build the bridge domain sw if table.
1048 static void vl_api_bridge_domain_sw_if_details_t_handler
1049 (vl_api_bridge_domain_sw_if_details_t * mp)
1051 vat_main_t * vam = &vat_main;
1053 u8 * sw_if_name = 0;
1056 sw_if_index = ntohl (mp->sw_if_index);
1057 hash_foreach_pair (p, vam->sw_if_index_by_interface_name,
1059 if ((u32) p->value[0] == sw_if_index) {
1060 sw_if_name = (u8 *)(p->key);
1065 fformat (vam->ofp, "%7d %3d %s", sw_if_index,
1066 mp->shg, sw_if_name ? (char *)sw_if_name :
1067 "sw_if_index not found!");
1070 static void vl_api_bridge_domain_sw_if_details_t_handler_json
1071 (vl_api_bridge_domain_sw_if_details_t * mp)
1073 vat_main_t * vam = &vat_main;
1074 vat_json_node_t *node = NULL;
1075 uword last_index = 0;
1077 ASSERT(VAT_JSON_ARRAY == vam->json_tree.type);
1078 ASSERT(vec_len(vam->json_tree.array) >= 1);
1079 last_index = vec_len(vam->json_tree.array) - 1;
1080 node = &vam->json_tree.array[last_index];
1081 node = vat_json_object_get_element(node, "sw_if");
1082 ASSERT(NULL != node);
1083 node = vat_json_array_add(node);
1085 vat_json_init_object(node);
1086 vat_json_object_add_uint(node, "bd_id", ntohl(mp->bd_id));
1087 vat_json_object_add_uint(node, "sw_if_index", ntohl(mp->sw_if_index));
1088 vat_json_object_add_uint(node, "shg", mp->shg);
1091 static void vl_api_control_ping_reply_t_handler
1092 (vl_api_control_ping_reply_t * mp)
1094 vat_main_t * vam = &vat_main;
1095 i32 retval = ntohl(mp->retval);
1096 if (vam->async_mode) {
1097 vam->async_errors += (retval < 0);
1099 vam->retval = retval;
1100 vam->result_ready = 1;
1104 static void vl_api_control_ping_reply_t_handler_json
1105 (vl_api_control_ping_reply_t * mp)
1107 vat_main_t * vam = &vat_main;
1108 i32 retval = ntohl(mp->retval);
1110 if (VAT_JSON_NONE != vam->json_tree.type) {
1111 vat_json_print(vam->ofp, &vam->json_tree);
1112 vat_json_free(&vam->json_tree);
1113 vam->json_tree.type = VAT_JSON_NONE;
1116 vat_json_init_array(&vam->json_tree);
1117 vat_json_print(vam->ofp, &vam->json_tree);
1118 vam->json_tree.type = VAT_JSON_NONE;
1121 vam->retval = retval;
1122 vam->result_ready = 1;
1125 static void vl_api_l2_flags_reply_t_handler
1126 (vl_api_l2_flags_reply_t * mp)
1128 vat_main_t * vam = &vat_main;
1129 i32 retval = ntohl(mp->retval);
1130 if (vam->async_mode) {
1131 vam->async_errors += (retval < 0);
1133 vam->retval = retval;
1134 vam->result_ready = 1;
1138 static void vl_api_l2_flags_reply_t_handler_json
1139 (vl_api_l2_flags_reply_t * mp)
1141 vat_main_t * vam = &vat_main;
1142 vat_json_node_t node;
1144 vat_json_init_object(&node);
1145 vat_json_object_add_int(&node, "retval", ntohl(mp->retval));
1146 vat_json_object_add_uint(&node, "resulting_feature_bitmap", ntohl(mp->resulting_feature_bitmap));
1148 vat_json_print(vam->ofp, &node);
1149 vat_json_free(&node);
1151 vam->retval = ntohl(mp->retval);
1152 vam->result_ready = 1;
1155 static void vl_api_bridge_flags_reply_t_handler
1156 (vl_api_bridge_flags_reply_t * mp)
1158 vat_main_t * vam = &vat_main;
1159 i32 retval = ntohl(mp->retval);
1160 if (vam->async_mode) {
1161 vam->async_errors += (retval < 0);
1163 vam->retval = retval;
1164 vam->result_ready = 1;
1168 static void vl_api_bridge_flags_reply_t_handler_json
1169 (vl_api_bridge_flags_reply_t * mp)
1171 vat_main_t * vam = &vat_main;
1172 vat_json_node_t node;
1174 vat_json_init_object(&node);
1175 vat_json_object_add_int(&node, "retval", ntohl(mp->retval));
1176 vat_json_object_add_uint(&node, "resulting_feature_bitmap", ntohl(mp->resulting_feature_bitmap));
1178 vat_json_print(vam->ofp, &node);
1179 vat_json_free(&node);
1181 vam->retval = ntohl(mp->retval);
1182 vam->result_ready = 1;
1185 static void vl_api_tap_connect_reply_t_handler
1186 (vl_api_tap_connect_reply_t * mp)
1188 vat_main_t * vam = &vat_main;
1189 i32 retval = ntohl(mp->retval);
1190 if (vam->async_mode) {
1191 vam->async_errors += (retval < 0);
1193 vam->retval = retval;
1194 vam->sw_if_index = ntohl (mp->sw_if_index);
1195 vam->result_ready = 1;
1200 static void vl_api_tap_connect_reply_t_handler_json
1201 (vl_api_tap_connect_reply_t * mp)
1203 vat_main_t * vam = &vat_main;
1204 vat_json_node_t node;
1206 vat_json_init_object(&node);
1207 vat_json_object_add_int(&node, "retval", ntohl(mp->retval));
1208 vat_json_object_add_uint(&node, "sw_if_index", ntohl(mp->sw_if_index));
1210 vat_json_print(vam->ofp, &node);
1211 vat_json_free(&node);
1213 vam->retval = ntohl(mp->retval);
1214 vam->result_ready = 1;
1218 static void vl_api_tap_modify_reply_t_handler
1219 (vl_api_tap_modify_reply_t * mp)
1221 vat_main_t * vam = &vat_main;
1222 i32 retval = ntohl(mp->retval);
1223 if (vam->async_mode) {
1224 vam->async_errors += (retval < 0);
1226 vam->retval = retval;
1227 vam->sw_if_index = ntohl (mp->sw_if_index);
1228 vam->result_ready = 1;
1232 static void vl_api_tap_modify_reply_t_handler_json
1233 (vl_api_tap_modify_reply_t * mp)
1235 vat_main_t * vam = &vat_main;
1236 vat_json_node_t node;
1238 vat_json_init_object(&node);
1239 vat_json_object_add_int(&node, "retval", ntohl(mp->retval));
1240 vat_json_object_add_uint(&node, "sw_if_index", ntohl(mp->sw_if_index));
1242 vat_json_print(vam->ofp, &node);
1243 vat_json_free(&node);
1245 vam->retval = ntohl(mp->retval);
1246 vam->result_ready = 1;
1249 static void vl_api_tap_delete_reply_t_handler
1250 (vl_api_tap_delete_reply_t * mp)
1252 vat_main_t * vam = &vat_main;
1253 i32 retval = ntohl(mp->retval);
1254 if (vam->async_mode) {
1255 vam->async_errors += (retval < 0);
1257 vam->retval = retval;
1258 vam->result_ready = 1;
1262 static void vl_api_tap_delete_reply_t_handler_json
1263 (vl_api_tap_delete_reply_t * mp)
1265 vat_main_t * vam = &vat_main;
1266 vat_json_node_t node;
1268 vat_json_init_object(&node);
1269 vat_json_object_add_int(&node, "retval", ntohl(mp->retval));
1271 vat_json_print(vam->ofp, &node);
1272 vat_json_free(&node);
1274 vam->retval = ntohl(mp->retval);
1275 vam->result_ready = 1;
1278 static void vl_api_mpls_ethernet_add_del_tunnel_reply_t_handler
1279 (vl_api_mpls_ethernet_add_del_tunnel_reply_t * mp)
1281 vat_main_t * vam = &vat_main;
1282 i32 retval = ntohl(mp->retval);
1283 if (vam->async_mode) {
1284 vam->async_errors += (retval < 0);
1286 vam->retval = retval;
1287 vam->result_ready = 1;
1291 static void vl_api_mpls_ethernet_add_del_tunnel_reply_t_handler_json
1292 (vl_api_mpls_ethernet_add_del_tunnel_reply_t * mp)
1294 vat_main_t * vam = &vat_main;
1295 vat_json_node_t node;
1297 vat_json_init_object(&node);
1298 vat_json_object_add_int(&node, "retval", ntohl(mp->retval));
1299 vat_json_object_add_uint(&node, "tunnel_sw_if_index", ntohl(mp->tunnel_sw_if_index));
1301 vat_json_print(vam->ofp, &node);
1302 vat_json_free(&node);
1304 vam->retval = ntohl(mp->retval);
1305 vam->result_ready = 1;
1308 static void vl_api_l2tpv3_create_tunnel_reply_t_handler
1309 (vl_api_l2tpv3_create_tunnel_reply_t * mp)
1311 vat_main_t * vam = &vat_main;
1312 i32 retval = ntohl(mp->retval);
1313 if (vam->async_mode) {
1314 vam->async_errors += (retval < 0);
1316 vam->retval = retval;
1317 vam->sw_if_index = ntohl (mp->sw_if_index);
1318 vam->result_ready = 1;
1322 static void vl_api_l2tpv3_create_tunnel_reply_t_handler_json
1323 (vl_api_l2tpv3_create_tunnel_reply_t * mp)
1325 vat_main_t * vam = &vat_main;
1326 vat_json_node_t node;
1328 vat_json_init_object(&node);
1329 vat_json_object_add_int(&node, "retval", ntohl(mp->retval));
1330 vat_json_object_add_uint(&node, "sw_if_index", ntohl(mp->sw_if_index));
1332 vat_json_print(vam->ofp, &node);
1333 vat_json_free(&node);
1335 vam->retval = ntohl(mp->retval);
1336 vam->result_ready = 1;
1339 static void vl_api_vxlan_add_del_tunnel_reply_t_handler
1340 (vl_api_vxlan_add_del_tunnel_reply_t * mp)
1342 vat_main_t * vam = &vat_main;
1343 i32 retval = ntohl(mp->retval);
1344 if (vam->async_mode) {
1345 vam->async_errors += (retval < 0);
1347 vam->retval = retval;
1348 vam->sw_if_index = ntohl (mp->sw_if_index);
1349 vam->result_ready = 1;
1353 static void vl_api_vxlan_add_del_tunnel_reply_t_handler_json
1354 (vl_api_vxlan_add_del_tunnel_reply_t * mp)
1356 vat_main_t * vam = &vat_main;
1357 vat_json_node_t node;
1359 vat_json_init_object(&node);
1360 vat_json_object_add_int(&node, "retval", ntohl(mp->retval));
1361 vat_json_object_add_uint(&node, "sw_if_index", ntohl(mp->sw_if_index));
1363 vat_json_print(vam->ofp, &node);
1364 vat_json_free(&node);
1366 vam->retval = ntohl(mp->retval);
1367 vam->result_ready = 1;
1370 static void vl_api_gre_add_del_tunnel_reply_t_handler
1371 (vl_api_gre_add_del_tunnel_reply_t * mp)
1373 vat_main_t * vam = &vat_main;
1374 i32 retval = ntohl(mp->retval);
1375 if (vam->async_mode) {
1376 vam->async_errors += (retval < 0);
1378 vam->retval = retval;
1379 vam->sw_if_index = ntohl (mp->sw_if_index);
1380 vam->result_ready = 1;
1384 static void vl_api_gre_add_del_tunnel_reply_t_handler_json
1385 (vl_api_gre_add_del_tunnel_reply_t * mp)
1387 vat_main_t * vam = &vat_main;
1388 vat_json_node_t node;
1390 vat_json_init_object(&node);
1391 vat_json_object_add_int(&node, "retval", ntohl(mp->retval));
1392 vat_json_object_add_uint(&node, "sw_if_index", ntohl(mp->sw_if_index));
1394 vat_json_print(vam->ofp, &node);
1395 vat_json_free(&node);
1397 vam->retval = ntohl(mp->retval);
1398 vam->result_ready = 1;
1401 static void vl_api_create_vhost_user_if_reply_t_handler
1402 (vl_api_create_vhost_user_if_reply_t * mp)
1404 vat_main_t * vam = &vat_main;
1405 i32 retval = ntohl(mp->retval);
1406 if (vam->async_mode) {
1407 vam->async_errors += (retval < 0);
1409 vam->retval = retval;
1410 vam->sw_if_index = ntohl (mp->sw_if_index);
1411 vam->result_ready = 1;
1415 static void vl_api_create_vhost_user_if_reply_t_handler_json
1416 (vl_api_create_vhost_user_if_reply_t * mp)
1418 vat_main_t * vam = &vat_main;
1419 vat_json_node_t node;
1421 vat_json_init_object(&node);
1422 vat_json_object_add_int(&node, "retval", ntohl(mp->retval));
1423 vat_json_object_add_uint(&node, "sw_if_index", ntohl(mp->sw_if_index));
1425 vat_json_print(vam->ofp, &node);
1426 vat_json_free(&node);
1428 vam->retval = ntohl(mp->retval);
1429 vam->result_ready = 1;
1432 static void vl_api_ip_address_details_t_handler
1433 (vl_api_ip_address_details_t * mp)
1435 vat_main_t * vam = &vat_main;
1436 static ip_address_details_t empty_ip_address_details = {{0}};
1437 ip_address_details_t * address = NULL;
1438 ip_details_t * current_ip_details = NULL;
1439 ip_details_t * details = NULL;
1441 details = vam->ip_details_by_sw_if_index[vam->is_ipv6];
1443 if (!details || vam->current_sw_if_index >= vec_len(details)
1444 || !details[vam->current_sw_if_index].present) {
1445 errmsg ("ip address details arrived but not stored\n");
1446 errmsg ("ip_dump should be called first\n");
1450 current_ip_details = vec_elt_at_index(details,
1451 vam->current_sw_if_index);
1453 #define addresses (current_ip_details->addr)
1455 vec_validate_init_empty(addresses, vec_len(addresses),
1456 empty_ip_address_details);
1458 address = vec_elt_at_index(addresses, vec_len(addresses) - 1);
1460 clib_memcpy(&address->ip, &mp->ip, sizeof(address->ip));
1461 address->prefix_length = mp->prefix_length;
1465 static void vl_api_ip_address_details_t_handler_json
1466 (vl_api_ip_address_details_t * mp)
1468 vat_main_t * vam = &vat_main;
1469 vat_json_node_t *node = NULL;
1470 struct in6_addr ip6;
1473 if (VAT_JSON_ARRAY != vam->json_tree.type) {
1474 ASSERT(VAT_JSON_NONE == vam->json_tree.type);
1475 vat_json_init_array(&vam->json_tree);
1477 node = vat_json_array_add(&vam->json_tree);
1479 vat_json_init_object(node);
1481 clib_memcpy(&ip6, mp->ip, sizeof(ip6));
1482 vat_json_object_add_ip6(node, "ip", ip6);
1484 clib_memcpy(&ip4, mp->ip, sizeof(ip4));
1485 vat_json_object_add_ip4(node, "ip", ip4);
1487 vat_json_object_add_uint(node, "prefix_length", mp->prefix_length);
1490 static void vl_api_ip_details_t_handler (vl_api_ip_details_t * mp)
1492 vat_main_t * vam = &vat_main;
1493 static ip_details_t empty_ip_details = {0};
1494 ip_details_t * ip = NULL;
1495 u32 sw_if_index = ~0;
1497 sw_if_index = ntohl(mp->sw_if_index);
1499 vec_validate_init_empty(vam->ip_details_by_sw_if_index[vam->is_ipv6],
1500 sw_if_index, empty_ip_details);
1502 ip = vec_elt_at_index(vam->ip_details_by_sw_if_index[vam->is_ipv6],
1508 static void vl_api_ip_details_t_handler_json (vl_api_ip_details_t * mp)
1510 vat_main_t * vam = &vat_main;
1512 if (VAT_JSON_ARRAY != vam->json_tree.type) {
1513 ASSERT(VAT_JSON_NONE == vam->json_tree.type);
1514 vat_json_init_array(&vam->json_tree);
1516 vat_json_array_add_uint(&vam->json_tree, clib_net_to_host_u32(mp->sw_if_index));
1519 static void vl_api_map_domain_details_t_handler_json
1520 (vl_api_map_domain_details_t * mp)
1522 vat_json_node_t * node = NULL;
1523 vat_main_t * vam = &vat_main;
1524 struct in6_addr ip6;
1527 if (VAT_JSON_ARRAY != vam->json_tree.type) {
1528 ASSERT(VAT_JSON_NONE == vam->json_tree.type);
1529 vat_json_init_array(&vam->json_tree);
1532 node = vat_json_array_add(&vam->json_tree);
1533 vat_json_init_object(node);
1535 vat_json_object_add_uint(node, "domain_index", clib_net_to_host_u32(mp->domain_index));
1536 clib_memcpy(&ip6, mp->ip6_prefix, sizeof(ip6));
1537 vat_json_object_add_ip6(node, "ip6_prefix", ip6);
1538 clib_memcpy(&ip4, mp->ip4_prefix, sizeof(ip4));
1539 vat_json_object_add_ip4(node, "ip4_prefix", ip4);
1540 clib_memcpy(&ip6, mp->ip6_src, sizeof(ip6));
1541 vat_json_object_add_ip6(node, "ip6_src", ip6);
1542 vat_json_object_add_int(node, "ip6_prefix_len", mp->ip6_prefix_len);
1543 vat_json_object_add_int(node, "ip4_prefix_len", mp->ip4_prefix_len);
1544 vat_json_object_add_int(node, "ip6_src_len", mp->ip6_src_len);
1545 vat_json_object_add_int(node, "ea_bits_len", mp->ea_bits_len);
1546 vat_json_object_add_int(node, "psid_offset", mp->psid_offset);
1547 vat_json_object_add_int(node, "psid_length", mp->psid_length);
1548 vat_json_object_add_uint(node, "flags", mp->flags);
1549 vat_json_object_add_uint(node, "mtu", clib_net_to_host_u16(mp->mtu));
1550 vat_json_object_add_int(node, "is_translation", mp->is_translation);
1553 static void vl_api_map_domain_details_t_handler
1554 (vl_api_map_domain_details_t * mp)
1556 vat_main_t * vam = &vat_main;
1558 if (mp->is_translation) {
1559 fformat(vam->ofp, "* %U/%d (ipv4-prefix) %U/%d (ipv6-prefix) %U/%d (ip6-src) index: %u\n",
1560 format_ip4_address, mp->ip4_prefix, mp->ip4_prefix_len,
1561 format_ip6_address, mp->ip6_prefix, mp->ip6_prefix_len,
1562 format_ip6_address, mp->ip6_src, mp->ip6_src_len, clib_net_to_host_u32(mp->domain_index));
1564 fformat(vam->ofp, "* %U/%d (ipv4-prefix) %U/%d (ipv6-prefix) %U (ip6-src) index: %u\n",
1565 format_ip4_address, mp->ip4_prefix, mp->ip4_prefix_len,
1566 format_ip6_address, mp->ip6_prefix, mp->ip6_prefix_len,
1567 format_ip6_address, mp->ip6_src, clib_net_to_host_u32(mp->domain_index));
1569 fformat(vam->ofp, " ea-len %d psid-offset %d psid-len %d mtu %d %s\n",
1570 mp->ea_bits_len, mp->psid_offset, mp->psid_length, mp->mtu, mp->is_translation? "map-t":"");
1573 static void vl_api_map_rule_details_t_handler_json
1574 (vl_api_map_rule_details_t * mp)
1576 struct in6_addr ip6;
1577 vat_json_node_t * node = NULL;
1578 vat_main_t * vam = &vat_main;
1580 if (VAT_JSON_ARRAY != vam->json_tree.type) {
1581 ASSERT(VAT_JSON_NONE == vam->json_tree.type);
1582 vat_json_init_array(&vam->json_tree);
1585 node = vat_json_array_add(&vam->json_tree);
1586 vat_json_init_object(node);
1588 vat_json_object_add_uint(node, "psid", clib_net_to_host_u16(mp->psid));
1589 clib_memcpy(&ip6, mp->ip6_dst, sizeof(ip6));
1590 vat_json_object_add_ip6(node, "ip6_dst", ip6);
1593 static void vl_api_map_rule_details_t_handler
1594 (vl_api_map_rule_details_t * mp)
1596 vat_main_t * vam = &vat_main;
1597 fformat(vam->ofp, " %d (psid) %U (ip6-dst)\n", clib_net_to_host_u16(mp->psid),
1598 format_ip6_address, mp->ip6_dst);
1601 static void vl_api_dhcp_compl_event_t_handler
1602 (vl_api_dhcp_compl_event_t * mp)
1604 vat_main_t * vam = &vat_main;
1605 errmsg ("DHCP compl event: pid %d %s hostname %s host_addr %U "
1606 "router_addr %U host_mac %U\n",
1607 mp->pid, mp->is_ipv6 ? "ipv6":"ipv4", mp->hostname,
1608 format_ip4_address, &mp->host_address,
1609 format_ip4_address, &mp->router_address,
1610 format_ethernet_address, mp->host_mac);
1613 static void vl_api_dhcp_compl_event_t_handler_json
1614 (vl_api_dhcp_compl_event_t * mp)
1616 /* JSON output not supported */
1619 static void set_simple_interface_counter (u8 vnet_counter_type, u32 sw_if_index,
1622 vat_main_t * vam = &vat_main;
1623 static u64 default_counter = 0;
1625 vec_validate_init_empty(vam->simple_interface_counters, vnet_counter_type, NULL);
1626 vec_validate_init_empty(vam->simple_interface_counters[vnet_counter_type],
1627 sw_if_index, default_counter);
1628 vam->simple_interface_counters[vnet_counter_type][sw_if_index] = counter;
1631 static void set_combined_interface_counter (u8 vnet_counter_type, u32 sw_if_index,
1632 interface_counter_t counter)
1634 vat_main_t * vam = &vat_main;
1635 static interface_counter_t default_counter = {0, };
1637 vec_validate_init_empty(vam->combined_interface_counters, vnet_counter_type, NULL);
1638 vec_validate_init_empty(vam->combined_interface_counters[vnet_counter_type],
1639 sw_if_index, default_counter);
1640 vam->combined_interface_counters[vnet_counter_type][sw_if_index] = counter;
1643 static void vl_api_vnet_interface_counters_t_handler
1644 (vl_api_vnet_interface_counters_t *mp)
1649 static void vl_api_vnet_interface_counters_t_handler_json
1650 (vl_api_vnet_interface_counters_t *mp)
1652 interface_counter_t counter;
1657 u32 first_sw_if_index;
1660 count = ntohl(mp->count);
1661 first_sw_if_index = ntohl(mp->first_sw_if_index);
1663 if (!mp->is_combined) {
1664 v_packets = (u64*)&mp->data;
1665 for (i = 0; i < count; i++) {
1666 packets = clib_net_to_host_u64(clib_mem_unaligned(v_packets, u64));
1667 set_simple_interface_counter(mp->vnet_counter_type,
1668 first_sw_if_index + i, packets);
1672 v = (vlib_counter_t*)&mp->data;
1673 for (i = 0; i < count; i++) {
1674 counter.packets = clib_net_to_host_u64(
1675 clib_mem_unaligned(&v->packets, u64));
1676 counter.bytes = clib_net_to_host_u64(
1677 clib_mem_unaligned(&v->bytes, u64));
1678 set_combined_interface_counter(mp->vnet_counter_type,
1679 first_sw_if_index + i, counter);
1685 static u32 ip4_fib_counters_get_vrf_index_by_vrf_id (u32 vrf_id)
1687 vat_main_t * vam = &vat_main;
1690 for (i = 0; i < vec_len(vam->ip4_fib_counters_vrf_id_by_index); i++) {
1691 if (vam->ip4_fib_counters_vrf_id_by_index[i] == vrf_id) {
1698 static u32 ip6_fib_counters_get_vrf_index_by_vrf_id (u32 vrf_id)
1700 vat_main_t * vam = &vat_main;
1703 for (i = 0; i < vec_len(vam->ip6_fib_counters_vrf_id_by_index); i++) {
1704 if (vam->ip6_fib_counters_vrf_id_by_index[i] == vrf_id) {
1711 static void vl_api_vnet_ip4_fib_counters_t_handler
1712 (vl_api_vnet_ip4_fib_counters_t *mp)
1717 static void vl_api_vnet_ip4_fib_counters_t_handler_json
1718 (vl_api_vnet_ip4_fib_counters_t *mp)
1720 vat_main_t * vam = &vat_main;
1721 vl_api_ip4_fib_counter_t *v;
1722 ip4_fib_counter_t *counter;
1729 vrf_id = ntohl(mp->vrf_id);
1730 vrf_index = ip4_fib_counters_get_vrf_index_by_vrf_id(vrf_id);
1731 if (~0 == vrf_index) {
1732 vrf_index = vec_len(vam->ip4_fib_counters_vrf_id_by_index);
1733 vec_validate(vam->ip4_fib_counters_vrf_id_by_index, vrf_index);
1734 vam->ip4_fib_counters_vrf_id_by_index[vrf_index] = vrf_id;
1735 vec_validate(vam->ip4_fib_counters, vrf_index);
1736 vam->ip4_fib_counters[vrf_index] = NULL;
1739 vec_free(vam->ip4_fib_counters[vrf_index]);
1740 v = (vl_api_ip4_fib_counter_t*)&mp->c;
1741 count = ntohl(mp->count);
1742 for (i = 0; i < count; i++) {
1743 vec_validate(vam->ip4_fib_counters[vrf_index], i);
1744 counter = &vam->ip4_fib_counters[vrf_index][i];
1745 clib_memcpy(&ip4, &v->address, sizeof(ip4));
1746 counter->address = ip4;
1747 counter->address_length = v->address_length;
1748 counter->packets = clib_net_to_host_u64(v->packets);
1749 counter->bytes = clib_net_to_host_u64(v->bytes);
1754 static void vl_api_vnet_ip6_fib_counters_t_handler
1755 (vl_api_vnet_ip6_fib_counters_t *mp)
1760 static void vl_api_vnet_ip6_fib_counters_t_handler_json
1761 (vl_api_vnet_ip6_fib_counters_t *mp)
1763 vat_main_t * vam = &vat_main;
1764 vl_api_ip6_fib_counter_t *v;
1765 ip6_fib_counter_t *counter;
1766 struct in6_addr ip6;
1772 vrf_id = ntohl(mp->vrf_id);
1773 vrf_index = ip6_fib_counters_get_vrf_index_by_vrf_id(vrf_id);
1774 if (~0 == vrf_index) {
1775 vrf_index = vec_len(vam->ip6_fib_counters_vrf_id_by_index);
1776 vec_validate(vam->ip6_fib_counters_vrf_id_by_index, vrf_index);
1777 vam->ip6_fib_counters_vrf_id_by_index[vrf_index] = vrf_id;
1778 vec_validate(vam->ip6_fib_counters, vrf_index);
1779 vam->ip6_fib_counters[vrf_index] = NULL;
1782 vec_free(vam->ip6_fib_counters[vrf_index]);
1783 v = (vl_api_ip6_fib_counter_t*)&mp->c;
1784 count = ntohl(mp->count);
1785 for (i = 0; i < count; i++) {
1786 vec_validate(vam->ip6_fib_counters[vrf_index], i);
1787 counter = &vam->ip6_fib_counters[vrf_index][i];
1788 clib_memcpy(&ip6, &v->address, sizeof(ip6));
1789 counter->address = ip6;
1790 counter->address_length = v->address_length;
1791 counter->packets = clib_net_to_host_u64(v->packets);
1792 counter->bytes = clib_net_to_host_u64(v->bytes);
1797 static void vl_api_get_first_msg_id_reply_t_handler
1798 (vl_api_get_first_msg_id_reply_t * mp)
1800 vat_main_t * vam = &vat_main;
1801 i32 retval = ntohl(mp->retval);
1803 if (vam->async_mode) {
1804 vam->async_errors += (retval < 0);
1806 vam->retval = retval;
1807 vam->result_ready = 1;
1810 errmsg ("first message id %d\n", ntohs(mp->first_msg_id));
1814 static void vl_api_get_first_msg_id_reply_t_handler_json
1815 (vl_api_get_first_msg_id_reply_t * mp)
1817 vat_main_t * vam = &vat_main;
1818 vat_json_node_t node;
1820 vat_json_init_object(&node);
1821 vat_json_object_add_int(&node, "retval", ntohl(mp->retval));
1822 vat_json_object_add_uint(&node, "first_msg_id",
1823 (uint) ntohs(mp->first_msg_id));
1825 vat_json_print(vam->ofp, &node);
1826 vat_json_free(&node);
1828 vam->retval = ntohl(mp->retval);
1829 vam->result_ready = 1;
1832 static void vl_api_get_node_graph_reply_t_handler
1833 (vl_api_get_node_graph_reply_t * mp)
1835 vat_main_t * vam = &vat_main;
1836 api_main_t * am = &api_main;
1837 i32 retval = ntohl(mp->retval);
1838 u8 * pvt_copy, * reply;
1843 if (vam->async_mode) {
1844 vam->async_errors += (retval < 0);
1846 vam->retval = retval;
1847 vam->result_ready = 1;
1850 /* "Should never happen..." */
1854 reply = (u8 *)(mp->reply_in_shmem);
1855 pvt_copy = vec_dup (reply);
1857 /* Toss the shared-memory original... */
1858 pthread_mutex_lock (&am->vlib_rp->mutex);
1859 oldheap = svm_push_data_heap (am->vlib_rp);
1863 svm_pop_heap (oldheap);
1864 pthread_mutex_unlock (&am->vlib_rp->mutex);
1866 if (vam->graph_nodes) {
1867 hash_free (vam->graph_node_index_by_name);
1869 for (i = 0; i < vec_len (vam->graph_nodes); i++) {
1870 node = vam->graph_nodes[i];
1871 vec_free (node->name);
1872 vec_free (node->next_nodes);
1875 vec_free(vam->graph_nodes);
1878 vam->graph_node_index_by_name = hash_create_string (0, sizeof(uword));
1879 vam->graph_nodes = vlib_node_unserialize (pvt_copy);
1880 vec_free (pvt_copy);
1882 for (i = 0; i < vec_len (vam->graph_nodes); i++) {
1883 node = vam->graph_nodes[i];
1884 hash_set_mem (vam->graph_node_index_by_name, node->name, i);
1888 static void vl_api_get_node_graph_reply_t_handler_json
1889 (vl_api_get_node_graph_reply_t * mp)
1891 vat_main_t * vam = &vat_main;
1892 api_main_t * am = &api_main;
1894 vat_json_node_t node;
1897 /* $$$$ make this real? */
1898 vat_json_init_object(&node);
1899 vat_json_object_add_int(&node, "retval", ntohl(mp->retval));
1900 vat_json_object_add_uint(&node, "reply_in_shmem", mp->reply_in_shmem);
1902 reply = (u8 *)(mp->reply_in_shmem);
1904 /* Toss the shared-memory original... */
1905 pthread_mutex_lock (&am->vlib_rp->mutex);
1906 oldheap = svm_push_data_heap (am->vlib_rp);
1910 svm_pop_heap (oldheap);
1911 pthread_mutex_unlock (&am->vlib_rp->mutex);
1913 vat_json_print(vam->ofp, &node);
1914 vat_json_free(&node);
1916 vam->retval = ntohl(mp->retval);
1917 vam->result_ready = 1;
1921 vl_api_lisp_locator_set_details_t_handler (
1922 vl_api_lisp_locator_set_details_t *mp)
1924 vat_main_t *vam = &vat_main;
1925 u8 * tmp_str = NULL;
1928 fformat(vam->ofp, "%=20s%=16d%=16d%=16d\n",
1929 mp->locator_set_name,
1930 ntohl(mp->sw_if_index),
1934 tmp_str = format(0,"%U/%d",
1935 mp->is_ipv6 ? format_ip6_address : format_ip4_address,
1939 fformat(vam->ofp, "%=20s%=16s%=16d%=16d\n",
1940 mp->locator_set_name,
1949 vl_api_lisp_locator_set_details_t_handler_json (
1950 vl_api_lisp_locator_set_details_t *mp)
1952 vat_main_t *vam = &vat_main;
1953 vat_json_node_t *node = NULL;
1954 struct in6_addr ip6;
1957 if (VAT_JSON_ARRAY != vam->json_tree.type) {
1958 ASSERT(VAT_JSON_NONE == vam->json_tree.type);
1959 vat_json_init_array(&vam->json_tree);
1961 node = vat_json_array_add(&vam->json_tree);
1963 vat_json_init_object(node);
1964 vat_json_object_add_string_copy(node, "locator-set", mp->locator_set_name);
1966 vat_json_object_add_uint(node, "locator", ntohl(mp->sw_if_index));
1969 clib_memcpy(&ip6, mp->ip_address, sizeof(ip6));
1970 vat_json_object_add_ip6(node, "locator", ip6);
1972 clib_memcpy(&ip4, mp->ip_address, sizeof(ip4));
1973 vat_json_object_add_ip4(node, "locator", ip4);
1975 vat_json_object_add_uint(node, "prefix-length", mp->prefix_len);
1977 vat_json_object_add_uint(node, "priority", mp->priority);
1978 vat_json_object_add_uint(node, "weight", mp->weight);
1982 vl_api_lisp_local_eid_table_details_t_handler (
1983 vl_api_lisp_local_eid_table_details_t *mp)
1985 vat_main_t *vam = &vat_main;
1988 prefix = format(0, "[&d] %U/%d",
1989 clib_net_to_host_u32 (mp->vni),
1990 mp->eid_is_ipv6 ? format_ip6_address : format_ip4_address,
1992 mp->eid_prefix_len);
1994 fformat(vam->ofp, "%=20s%=30s\n",
1995 mp->locator_set_name, prefix);
2001 vl_api_lisp_local_eid_table_details_t_handler_json (
2002 vl_api_lisp_local_eid_table_details_t *mp)
2004 vat_main_t *vam = &vat_main;
2005 vat_json_node_t *node = NULL;
2006 struct in6_addr ip6;
2009 if (VAT_JSON_ARRAY != vam->json_tree.type) {
2010 ASSERT(VAT_JSON_NONE == vam->json_tree.type);
2011 vat_json_init_array(&vam->json_tree);
2013 node = vat_json_array_add(&vam->json_tree);
2015 vat_json_init_object(node);
2016 vat_json_object_add_string_copy(node, "locator-set", mp->locator_set_name);
2017 if (mp->eid_is_ipv6) {
2018 clib_memcpy(&ip6, mp->eid_ip_address, sizeof(ip6));
2019 vat_json_object_add_ip6(node, "eid address", ip6);
2021 clib_memcpy(&ip4, mp->eid_ip_address, sizeof(ip4));
2022 vat_json_object_add_ip4(node, "eid address", ip4);
2024 vat_json_object_add_uint(node, "vni", clib_net_to_host_u32 (mp->vni));
2025 vat_json_object_add_uint(node, "eid prefix len", mp->eid_prefix_len);
2029 format_decap_next (u8 * s, va_list * args)
2031 u32 next_index = va_arg (*args, u32);
2035 case LISP_GPE_INPUT_NEXT_DROP:
2036 return format (s, "drop");
2037 case LISP_GPE_INPUT_NEXT_IP4_INPUT:
2038 return format (s, "ip4");
2039 case LISP_GPE_INPUT_NEXT_IP6_INPUT:
2040 return format (s, "ip6");
2042 return format (s, "unknown %d", next_index);
2048 vl_api_lisp_gpe_tunnel_details_t_handler (vl_api_lisp_gpe_tunnel_details_t *mp)
2050 vat_main_t *vam = &vat_main;
2052 u8 *flag_str = NULL;
2054 iid_str = format(0, "%d (0x%x)", ntohl(mp->iid), ntohl(mp->iid));
2056 #define _(n,v) if (mp->flags & v) flag_str = format (flag_str, "%s-bit ", #n);
2057 foreach_lisp_gpe_flag_bit;
2060 fformat(vam->ofp, "%=20d%=30U%=16U%=16d%=16d%=16U"
2061 "%=16d%=16d%=16sd=16d%=16s%=16s\n",
2063 mp->is_ipv6 ? format_ip6_address : format_ip4_address,
2065 mp->is_ipv6 ? format_ip6_address : format_ip4_address,
2067 ntohl(mp->encap_fib_id),
2068 ntohl(mp->decap_fib_id),
2069 format_decap_next, ntohl(mp->dcap_next),
2081 vl_api_lisp_gpe_tunnel_details_t_handler_json (
2082 vl_api_lisp_gpe_tunnel_details_t *mp)
2084 vat_main_t *vam = &vat_main;
2085 vat_json_node_t *node = NULL;
2086 struct in6_addr ip6;
2090 next_decap_str = format(0, "%U", format_decap_next, htonl(mp->dcap_next));
2092 if (VAT_JSON_ARRAY != vam->json_tree.type) {
2093 ASSERT(VAT_JSON_NONE == vam->json_tree.type);
2094 vat_json_init_array(&vam->json_tree);
2096 node = vat_json_array_add(&vam->json_tree);
2098 vat_json_init_object(node);
2099 vat_json_object_add_uint(node, "tunel", mp->tunnels);
2101 clib_memcpy(&ip6, mp->source_ip, sizeof(ip6));
2102 vat_json_object_add_ip6(node, "source address", ip6);
2103 clib_memcpy(&ip6, mp->destination_ip, sizeof(ip6));
2104 vat_json_object_add_ip6(node, "destination address", ip6);
2106 clib_memcpy(&ip4, mp->source_ip, sizeof(ip4));
2107 vat_json_object_add_ip4(node, "source address", ip4);
2108 clib_memcpy(&ip4, mp->destination_ip, sizeof(ip4));
2109 vat_json_object_add_ip4(node, "destination address", ip4);
2111 vat_json_object_add_uint(node, "fib encap", ntohl(mp->encap_fib_id));
2112 vat_json_object_add_uint(node, "fib decap", ntohl(mp->decap_fib_id));
2113 vat_json_object_add_string_copy(node, "decap next", next_decap_str);
2114 vat_json_object_add_uint(node, "lisp version", mp->ver_res >> 6);
2115 vat_json_object_add_uint(node, "flags", mp->flags);
2116 vat_json_object_add_uint(node, "next protocol", mp->next_protocol);
2117 vat_json_object_add_uint(node, "ver_res", mp->ver_res);
2118 vat_json_object_add_uint(node, "res", mp->res);
2119 vat_json_object_add_uint(node, "iid", ntohl(mp->iid));
2121 vec_free(next_decap_str);
2125 vl_api_lisp_map_resolver_details_t_handler (
2126 vl_api_lisp_map_resolver_details_t *mp)
2128 vat_main_t *vam = &vat_main;
2130 fformat(vam->ofp, "%=20U\n",
2131 mp->is_ipv6 ? format_ip6_address : format_ip4_address,
2136 vl_api_lisp_map_resolver_details_t_handler_json (
2137 vl_api_lisp_map_resolver_details_t *mp)
2139 vat_main_t *vam = &vat_main;
2140 vat_json_node_t *node = NULL;
2141 struct in6_addr ip6;
2144 if (VAT_JSON_ARRAY != vam->json_tree.type) {
2145 ASSERT(VAT_JSON_NONE == vam->json_tree.type);
2146 vat_json_init_array(&vam->json_tree);
2148 node = vat_json_array_add(&vam->json_tree);
2150 vat_json_init_object(node);
2152 clib_memcpy(&ip6, mp->ip_address, sizeof(ip6));
2153 vat_json_object_add_ip6(node, "map resolver", ip6);
2155 clib_memcpy(&ip4, mp->ip_address, sizeof(ip4));
2156 vat_json_object_add_ip4(node, "map resolver", ip4);
2161 vl_api_lisp_enable_disable_status_details_t_handler
2162 (vl_api_lisp_enable_disable_status_details_t *mp)
2164 vat_main_t *vam = &vat_main;
2166 fformat(vam->ofp, "feature: %s\ngpe: %s\n",
2167 mp->feature_status ? "enabled" : "disabled",
2168 mp->gpe_status ? "enabled" : "disabled");
2172 vl_api_lisp_enable_disable_status_details_t_handler_json
2173 (vl_api_lisp_enable_disable_status_details_t *mp)
2175 vat_main_t *vam = &vat_main;
2176 vat_json_node_t *node = NULL;
2177 u8 * gpe_status = NULL;
2178 u8 * feature_status = NULL;
2180 gpe_status = format (0, "%s", mp->gpe_status ? "enabled" : "disabled");
2181 feature_status = format (0, "%s",
2182 mp->feature_status ? "enabled" : "disabled");
2183 vec_add1 (gpe_status, 0);
2184 vec_add1 (feature_status, 0);
2186 if (VAT_JSON_ARRAY != vam->json_tree.type) {
2187 ASSERT(VAT_JSON_NONE == vam->json_tree.type);
2188 vat_json_init_array(&vam->json_tree);
2190 node = vat_json_array_add(&vam->json_tree);
2192 vat_json_init_object(node);
2193 vat_json_object_add_string_copy(node, "gpe_status", gpe_status);
2194 vat_json_object_add_string_copy(node, "feature_status", feature_status);
2196 vec_free (gpe_status);
2197 vec_free (feature_status);
2201 vl_api_lisp_get_map_request_itr_rlocs_reply_t_handler (
2202 vl_api_lisp_get_map_request_itr_rlocs_reply_t * mp)
2204 vat_main_t * vam = &vat_main;
2205 i32 retval = ntohl(mp->retval);
2208 fformat(vam->ofp, "%=20s\n",
2209 mp->locator_set_name);
2212 vam->retval = retval;
2213 vam->result_ready = 1;
2217 vl_api_lisp_get_map_request_itr_rlocs_reply_t_handler_json (
2218 vl_api_lisp_get_map_request_itr_rlocs_reply_t * mp)
2220 vat_main_t * vam = &vat_main;
2221 vat_json_node_t * node = NULL;
2223 if (VAT_JSON_ARRAY != vam->json_tree.type) {
2224 ASSERT(VAT_JSON_NONE == vam->json_tree.type);
2225 vat_json_init_array(&vam->json_tree);
2227 node = vat_json_array_add(&vam->json_tree);
2229 vat_json_init_object(node);
2230 vat_json_object_add_string_copy(node, "itr-rlocs", mp->locator_set_name);
2232 vat_json_print(vam->ofp, node);
2233 vat_json_free(node);
2235 vam->retval = ntohl(mp->retval);
2236 vam->result_ready = 1;
2239 static u8 * format_policer_type (u8 * s, va_list * va)
2241 u32 i = va_arg (*va, u32);
2243 if (i == SSE2_QOS_POLICER_TYPE_1R2C)
2244 s = format (s, "1r2c");
2245 else if (i == SSE2_QOS_POLICER_TYPE_1R3C_RFC_2697)
2246 s = format (s, "1r3c");
2247 else if (i == SSE2_QOS_POLICER_TYPE_2R3C_RFC_2698)
2248 s = format (s, "2r3c-2698");
2249 else if (i == SSE2_QOS_POLICER_TYPE_2R3C_RFC_4115)
2250 s = format (s, "2r3c-4115");
2251 else if (i == SSE2_QOS_POLICER_TYPE_2R3C_RFC_MEF5CF1)
2252 s = format (s, "2r3c-mef5cf1");
2254 s = format (s, "ILLEGAL");
2258 static u8 * format_policer_rate_type (u8 * s, va_list * va)
2260 u32 i = va_arg (*va, u32);
2262 if (i == SSE2_QOS_RATE_KBPS)
2263 s = format (s, "kbps");
2264 else if (i == SSE2_QOS_RATE_PPS)
2265 s = format(s, "pps");
2267 s = format (s, "ILLEGAL");
2271 static u8 * format_policer_round_type (u8 * s, va_list * va)
2273 u32 i = va_arg (*va, u32);
2275 if (i == SSE2_QOS_ROUND_TO_CLOSEST)
2276 s = format(s, "closest");
2277 else if (i == SSE2_QOS_ROUND_TO_UP)
2278 s = format (s, "up");
2279 else if (i == SSE2_QOS_ROUND_TO_DOWN)
2280 s = format (s, "down");
2282 s = format (s, "ILLEGAL");
2286 static void vl_api_policer_details_t_handler
2287 (vl_api_policer_details_t * mp)
2289 vat_main_t * vam = &vat_main;
2291 fformat (vam->ofp, "Name \"%s\", type %U, cir %u, eir %u, cb %u, eb %u, "
2292 "rate type %U, round type %U, %s rate, %s color-aware, "
2293 "cir %u tok/period, pir %u tok/period, scale %u, cur lim %u, "
2294 "cur bkt %u, ext lim %u, ext bkt %u, last update %llu\n",
2296 format_policer_type, mp->type,
2301 format_policer_rate_type, mp->rate_type,
2302 format_policer_round_type, mp->round_type,
2303 mp->single_rate ? "single" : "dual",
2304 mp->color_aware ? "is" : "not",
2305 ntohl(mp->cir_tokens_per_period),
2306 ntohl(mp->pir_tokens_per_period),
2308 ntohl(mp->current_limit),
2309 ntohl(mp->current_bucket),
2310 ntohl(mp->extended_limit),
2311 ntohl(mp->extended_bucket),
2312 clib_net_to_host_u64(mp->last_update_time));
2315 static void vl_api_policer_details_t_handler_json
2316 (vl_api_policer_details_t * mp)
2318 vat_main_t * vam = &vat_main;
2319 vat_json_node_t *node;
2320 u8 *rate_type_str, *round_type_str, *type_str;
2322 rate_type_str = format(0, "%U", format_policer_rate_type, mp->rate_type);
2323 round_type_str = format(0, "%U", format_policer_round_type, mp->round_type);
2324 type_str = format(0, "%U", format_policer_type, mp->type);
2326 if (VAT_JSON_ARRAY != vam->json_tree.type) {
2327 ASSERT(VAT_JSON_NONE == vam->json_tree.type);
2328 vat_json_init_array(&vam->json_tree);
2330 node = vat_json_array_add(&vam->json_tree);
2332 vat_json_init_object(node);
2333 vat_json_object_add_string_copy(node, "name", mp->name);
2334 vat_json_object_add_uint(node, "cir", ntohl(mp->cir));
2335 vat_json_object_add_uint(node, "eir", ntohl(mp->eir));
2336 vat_json_object_add_uint(node, "cb", ntohl(mp->cb));
2337 vat_json_object_add_uint(node, "eb", ntohl(mp->eb));
2338 vat_json_object_add_string_copy(node, "rate_type", rate_type_str);
2339 vat_json_object_add_string_copy(node, "round_type", round_type_str);
2340 vat_json_object_add_string_copy(node, "type", type_str);
2341 vat_json_object_add_uint(node, "single_rate", mp->single_rate);
2342 vat_json_object_add_uint(node, "color_aware", mp->color_aware);
2343 vat_json_object_add_uint(node, "scale", ntohl(mp->scale));
2344 vat_json_object_add_uint(node, "cir_tokens_per_period",
2345 ntohl(mp->cir_tokens_per_period));
2346 vat_json_object_add_uint(node, "eir_tokens_per_period",
2347 ntohl(mp->pir_tokens_per_period));
2348 vat_json_object_add_uint(node, "current_limit", ntohl(mp->current_limit));
2349 vat_json_object_add_uint(node, "current_bucket", ntohl(mp->current_bucket));
2350 vat_json_object_add_uint(node, "extended_limit", ntohl(mp->extended_limit));
2351 vat_json_object_add_uint(node, "extended_bucket",
2352 ntohl(mp->extended_bucket));
2353 vat_json_object_add_uint(node, "last_update_time",
2354 ntohl(mp->last_update_time));
2356 vec_free(rate_type_str);
2357 vec_free(round_type_str);
2361 static void vl_api_classify_table_ids_reply_t_handler (vl_api_classify_table_ids_reply_t * mp)
2363 vat_main_t * vam = &vat_main;
2364 int i, count = ntohl(mp->count);
2367 fformat (vam->ofp, "classify table ids (%d) : ", count);
2368 for (i = 0; i < count; i++)
2370 fformat (vam->ofp, "%d", ntohl(mp->ids[i]));
2371 fformat (vam->ofp, (i<count-1)?",":"\n");
2373 vam->retval = ntohl(mp->retval);
2374 vam->result_ready = 1;
2377 static void vl_api_classify_table_ids_reply_t_handler_json (vl_api_classify_table_ids_reply_t * mp)
2379 vat_main_t * vam = &vat_main;
2380 int i, count = ntohl(mp->count);
2383 vat_json_node_t node;
2385 vat_json_init_object(&node);
2386 for (i = 0; i < count; i++)
2388 vat_json_object_add_uint(&node, "table_id", ntohl(mp->ids[i]));
2390 vat_json_print(vam->ofp, &node);
2391 vat_json_free(&node);
2393 vam->retval = ntohl(mp->retval);
2394 vam->result_ready = 1;
2397 static void vl_api_classify_table_by_interface_reply_t_handler (vl_api_classify_table_by_interface_reply_t * mp)
2399 vat_main_t * vam = &vat_main;
2402 table_id = ntohl(mp->l2_table_id);
2404 fformat (vam->ofp, "l2 table id : %d\n", table_id);
2406 fformat (vam->ofp, "l2 table id : No input ACL tables configured\n");
2407 table_id = ntohl(mp->ip4_table_id);
2409 fformat (vam->ofp, "ip4 table id : %d\n", table_id);
2411 fformat (vam->ofp, "ip4 table id : No input ACL tables configured\n");
2412 table_id = ntohl(mp->ip6_table_id);
2414 fformat (vam->ofp, "ip6 table id : %d\n", table_id);
2416 fformat (vam->ofp, "ip6 table id : No input ACL tables configured\n");
2417 vam->retval = ntohl(mp->retval);
2418 vam->result_ready = 1;
2421 static void vl_api_classify_table_by_interface_reply_t_handler_json (vl_api_classify_table_by_interface_reply_t * mp)
2423 vat_main_t * vam = &vat_main;
2424 vat_json_node_t node;
2426 vat_json_init_object(&node);
2428 vat_json_object_add_int(&node, "l2_table_id", ntohl(mp->l2_table_id));
2429 vat_json_object_add_int(&node, "ip4_table_id", ntohl(mp->ip4_table_id));
2430 vat_json_object_add_int(&node, "ip6_table_id", ntohl(mp->ip6_table_id));
2432 vat_json_print(vam->ofp, &node);
2433 vat_json_free(&node);
2435 vam->retval = ntohl(mp->retval);
2436 vam->result_ready = 1;
2439 /* Format hex dump. */
2440 u8 * format_hex_bytes (u8 * s, va_list * va)
2442 u8 * bytes = va_arg (*va, u8 *);
2443 int n_bytes = va_arg (*va, int);
2446 /* Print short or long form depending on byte count. */
2447 uword short_form = n_bytes <= 32;
2448 uword indent = format_get_indent (s);
2453 for (i = 0; i < n_bytes; i++)
2455 if (! short_form && (i % 32) == 0)
2456 s = format (s, "%08x: ", i);
2457 s = format (s, "%02x", bytes[i]);
2458 if (! short_form && ((i + 1) % 32) == 0 && (i + 1) < n_bytes)
2459 s = format (s, "\n%U", format_white_space, indent);
2465 static void vl_api_classify_table_info_reply_t_handler (vl_api_classify_table_info_reply_t * mp)
2467 vat_main_t * vam = &vat_main;
2468 i32 retval = ntohl(mp->retval);
2470 fformat (vam->ofp, "classify table info :\n");
2471 fformat (vam->ofp, "sessions: %d nexttbl: %d nextnode: %d\n", ntohl(mp->active_sessions), ntohl(mp->next_table_index), ntohl(mp->miss_next_index));
2472 fformat (vam->ofp, "nbuckets: %d skip: %d match: %d\n", ntohl(mp->nbuckets), ntohl(mp->skip_n_vectors), ntohl(mp->match_n_vectors));
2473 fformat (vam->ofp, "mask: %U\n", format_hex_bytes, mp->mask, ntohl(mp->mask_length));
2475 vam->retval = retval;
2476 vam->result_ready = 1;
2479 static void vl_api_classify_table_info_reply_t_handler_json (vl_api_classify_table_info_reply_t * mp)
2481 vat_main_t * vam = &vat_main;
2482 vat_json_node_t node;
2484 i32 retval = ntohl(mp->retval);
2486 vat_json_init_object(&node);
2488 vat_json_object_add_int(&node, "sessions", ntohl(mp->active_sessions));
2489 vat_json_object_add_int(&node, "nexttbl", ntohl(mp->next_table_index));
2490 vat_json_object_add_int(&node, "nextnode", ntohl(mp->miss_next_index));
2491 vat_json_object_add_int(&node, "nbuckets", ntohl(mp->nbuckets));
2492 vat_json_object_add_int(&node, "skip", ntohl(mp->skip_n_vectors));
2493 vat_json_object_add_int(&node, "match", ntohl(mp->match_n_vectors));
2494 u8 * s = format (0, "%U%c",format_hex_bytes, mp->mask, ntohl(mp->mask_length), 0);
2495 vat_json_object_add_string_copy(&node, "mask", s);
2497 vat_json_print(vam->ofp, &node);
2498 vat_json_free(&node);
2500 vam->retval = ntohl(mp->retval);
2501 vam->result_ready = 1;
2504 static void vl_api_classify_session_details_t_handler (vl_api_classify_session_details_t * mp)
2506 vat_main_t * vam = &vat_main;
2508 fformat (vam->ofp, "next_index: %d advance: %d opaque: %d ", ntohl(mp->hit_next_index), ntohl(mp->advance), ntohl(mp->opaque_index));
2509 fformat (vam->ofp, "mask: %U\n", format_hex_bytes, mp->match, ntohl(mp->match_length));
2512 static void vl_api_classify_session_details_t_handler_json (vl_api_classify_session_details_t * mp)
2514 vat_main_t * vam = &vat_main;
2515 vat_json_node_t *node = NULL;
2517 if (VAT_JSON_ARRAY != vam->json_tree.type) {
2518 ASSERT(VAT_JSON_NONE == vam->json_tree.type);
2519 vat_json_init_array(&vam->json_tree);
2521 node = vat_json_array_add(&vam->json_tree);
2523 vat_json_init_object(node);
2524 vat_json_object_add_int(node, "next_index", ntohl(mp->hit_next_index));
2525 vat_json_object_add_int(node, "advance", ntohl(mp->advance));
2526 vat_json_object_add_int(node, "opaque", ntohl(mp->opaque_index));
2527 u8 * s = format (0, "%U%c",format_hex_bytes, mp->match, ntohl(mp->match_length), 0);
2528 vat_json_object_add_string_copy(node, "match", s);
2531 #define vl_api_vnet_ip4_fib_counters_t_endian vl_noop_handler
2532 #define vl_api_vnet_ip4_fib_counters_t_print vl_noop_handler
2533 #define vl_api_vnet_ip6_fib_counters_t_endian vl_noop_handler
2534 #define vl_api_vnet_ip6_fib_counters_t_print vl_noop_handler
2537 * Generate boilerplate reply handlers, which
2538 * dig the return value out of the xxx_reply_t API message,
2539 * stick it into vam->retval, and set vam->result_ready
2541 * Could also do this by pointing N message decode slots at
2542 * a single function, but that could break in subtle ways.
2545 #define foreach_standard_reply_retval_handler \
2546 _(sw_interface_set_flags_reply) \
2547 _(sw_interface_add_del_address_reply) \
2548 _(sw_interface_set_table_reply) \
2549 _(sw_interface_set_vpath_reply) \
2550 _(sw_interface_set_l2_bridge_reply) \
2551 _(bridge_domain_add_del_reply) \
2552 _(sw_interface_set_l2_xconnect_reply) \
2553 _(l2fib_add_del_reply) \
2554 _(ip_add_del_route_reply) \
2555 _(proxy_arp_add_del_reply) \
2556 _(proxy_arp_intfc_enable_disable_reply) \
2557 _(mpls_add_del_encap_reply) \
2558 _(mpls_add_del_decap_reply) \
2559 _(mpls_ethernet_add_del_tunnel_2_reply) \
2560 _(sw_interface_set_unnumbered_reply) \
2561 _(ip_neighbor_add_del_reply) \
2562 _(reset_vrf_reply) \
2563 _(oam_add_del_reply) \
2564 _(reset_fib_reply) \
2565 _(dhcp_proxy_config_reply) \
2566 _(dhcp_proxy_config_2_reply) \
2567 _(dhcp_proxy_set_vss_reply) \
2568 _(dhcp_client_config_reply) \
2569 _(set_ip_flow_hash_reply) \
2570 _(sw_interface_ip6_enable_disable_reply) \
2571 _(sw_interface_ip6_set_link_local_address_reply) \
2572 _(sw_interface_ip6nd_ra_prefix_reply) \
2573 _(sw_interface_ip6nd_ra_config_reply) \
2574 _(set_arp_neighbor_limit_reply) \
2575 _(l2_patch_add_del_reply) \
2576 _(sr_tunnel_add_del_reply) \
2577 _(sr_policy_add_del_reply) \
2578 _(sr_multicast_map_add_del_reply) \
2579 _(classify_add_del_session_reply) \
2580 _(classify_set_interface_ip_table_reply) \
2581 _(classify_set_interface_l2_tables_reply) \
2582 _(l2tpv3_set_tunnel_cookies_reply) \
2583 _(l2tpv3_interface_enable_disable_reply) \
2584 _(l2tpv3_set_lookup_key_reply) \
2585 _(l2_fib_clear_table_reply) \
2586 _(l2_interface_efp_filter_reply) \
2587 _(l2_interface_vlan_tag_rewrite_reply) \
2588 _(modify_vhost_user_if_reply) \
2589 _(delete_vhost_user_if_reply) \
2590 _(want_ip4_arp_events_reply) \
2591 _(input_acl_set_interface_reply) \
2592 _(ipsec_spd_add_del_reply) \
2593 _(ipsec_interface_add_del_spd_reply) \
2594 _(ipsec_spd_add_del_entry_reply) \
2595 _(ipsec_sad_add_del_entry_reply) \
2596 _(ipsec_sa_set_key_reply) \
2597 _(ikev2_profile_add_del_reply) \
2598 _(ikev2_profile_set_auth_reply) \
2599 _(ikev2_profile_set_id_reply) \
2600 _(ikev2_profile_set_ts_reply) \
2601 _(ikev2_set_local_key_reply) \
2602 _(delete_loopback_reply) \
2603 _(bd_ip_mac_add_del_reply) \
2604 _(map_del_domain_reply) \
2605 _(map_add_del_rule_reply) \
2606 _(want_interface_events_reply) \
2607 _(want_stats_reply) \
2608 _(cop_interface_enable_disable_reply) \
2609 _(cop_whitelist_enable_disable_reply) \
2610 _(sw_interface_clear_stats_reply) \
2611 _(trace_profile_add_reply) \
2612 _(trace_profile_apply_reply) \
2613 _(trace_profile_del_reply) \
2614 _(lisp_add_del_locator_set_reply) \
2615 _(lisp_add_del_locator_reply) \
2616 _(lisp_add_del_local_eid_reply) \
2617 _(lisp_gpe_add_del_fwd_entry_reply) \
2618 _(lisp_add_del_map_resolver_reply) \
2619 _(lisp_gpe_enable_disable_reply) \
2620 _(lisp_gpe_add_del_iface_reply) \
2621 _(lisp_enable_disable_reply) \
2622 _(lisp_pitr_set_locator_set_reply) \
2623 _(lisp_add_del_map_request_itr_rlocs_reply) \
2624 _(lisp_eid_table_add_del_map_reply) \
2625 _(vxlan_gpe_add_del_tunnel_reply) \
2626 _(af_packet_delete_reply) \
2627 _(policer_add_del_reply) \
2628 _(netmap_create_reply) \
2629 _(netmap_delete_reply)
2632 static void vl_api_##n##_t_handler \
2633 (vl_api_##n##_t * mp) \
2635 vat_main_t * vam = &vat_main; \
2636 i32 retval = ntohl(mp->retval); \
2637 if (vam->async_mode) { \
2638 vam->async_errors += (retval < 0); \
2640 vam->retval = retval; \
2641 vam->result_ready = 1; \
2644 foreach_standard_reply_retval_handler;
2648 static void vl_api_##n##_t_handler_json \
2649 (vl_api_##n##_t * mp) \
2651 vat_main_t * vam = &vat_main; \
2652 vat_json_node_t node; \
2653 vat_json_init_object(&node); \
2654 vat_json_object_add_int(&node, "retval", ntohl(mp->retval)); \
2655 vat_json_print(vam->ofp, &node); \
2656 vam->retval = ntohl(mp->retval); \
2657 vam->result_ready = 1; \
2659 foreach_standard_reply_retval_handler;
2663 * Table of message reply handlers, must include boilerplate handlers
2667 #define foreach_vpe_api_reply_msg \
2668 _(CREATE_LOOPBACK_REPLY, create_loopback_reply) \
2669 _(SW_INTERFACE_DETAILS, sw_interface_details) \
2670 _(SW_INTERFACE_SET_FLAGS, sw_interface_set_flags) \
2671 _(SW_INTERFACE_SET_FLAGS_REPLY, sw_interface_set_flags_reply) \
2672 _(CONTROL_PING_REPLY, control_ping_reply) \
2673 _(CLI_REPLY, cli_reply) \
2674 _(SW_INTERFACE_ADD_DEL_ADDRESS_REPLY, \
2675 sw_interface_add_del_address_reply) \
2676 _(SW_INTERFACE_SET_TABLE_REPLY, sw_interface_set_table_reply) \
2677 _(SW_INTERFACE_SET_VPATH_REPLY, sw_interface_set_vpath_reply) \
2678 _(SW_INTERFACE_SET_L2_XCONNECT_REPLY, \
2679 sw_interface_set_l2_xconnect_reply) \
2680 _(SW_INTERFACE_SET_L2_BRIDGE_REPLY, \
2681 sw_interface_set_l2_bridge_reply) \
2682 _(BRIDGE_DOMAIN_ADD_DEL_REPLY, bridge_domain_add_del_reply) \
2683 _(BRIDGE_DOMAIN_DETAILS, bridge_domain_details) \
2684 _(BRIDGE_DOMAIN_SW_IF_DETAILS, bridge_domain_sw_if_details) \
2685 _(L2FIB_ADD_DEL_REPLY, l2fib_add_del_reply) \
2686 _(L2_FLAGS_REPLY, l2_flags_reply) \
2687 _(BRIDGE_FLAGS_REPLY, bridge_flags_reply) \
2688 _(TAP_CONNECT_REPLY, tap_connect_reply) \
2689 _(TAP_MODIFY_REPLY, tap_modify_reply) \
2690 _(TAP_DELETE_REPLY, tap_delete_reply) \
2691 _(SW_INTERFACE_TAP_DETAILS, sw_interface_tap_details) \
2692 _(IP_ADD_DEL_ROUTE_REPLY, ip_add_del_route_reply) \
2693 _(PROXY_ARP_ADD_DEL_REPLY, proxy_arp_add_del_reply) \
2694 _(PROXY_ARP_INTFC_ENABLE_DISABLE_REPLY, \
2695 proxy_arp_intfc_enable_disable_reply) \
2696 _(MPLS_ADD_DEL_ENCAP_REPLY, mpls_add_del_encap_reply) \
2697 _(MPLS_ADD_DEL_DECAP_REPLY, mpls_add_del_decap_reply) \
2698 _(MPLS_GRE_ADD_DEL_TUNNEL_REPLY, mpls_gre_add_del_tunnel_reply) \
2699 _(MPLS_ETHERNET_ADD_DEL_TUNNEL_REPLY, \
2700 mpls_ethernet_add_del_tunnel_reply) \
2701 _(MPLS_ETHERNET_ADD_DEL_TUNNEL_2_REPLY, \
2702 mpls_ethernet_add_del_tunnel_2_reply) \
2703 _(SW_INTERFACE_SET_UNNUMBERED_REPLY, \
2704 sw_interface_set_unnumbered_reply) \
2705 _(IP_NEIGHBOR_ADD_DEL_REPLY, ip_neighbor_add_del_reply) \
2706 _(RESET_VRF_REPLY, reset_vrf_reply) \
2707 _(CREATE_VLAN_SUBIF_REPLY, create_vlan_subif_reply) \
2708 _(CREATE_SUBIF_REPLY, create_subif_reply) \
2709 _(OAM_ADD_DEL_REPLY, oam_add_del_reply) \
2710 _(RESET_FIB_REPLY, reset_fib_reply) \
2711 _(DHCP_PROXY_CONFIG_REPLY, dhcp_proxy_config_reply) \
2712 _(DHCP_PROXY_CONFIG_2_REPLY, dhcp_proxy_config_2_reply) \
2713 _(DHCP_PROXY_SET_VSS_REPLY, dhcp_proxy_set_vss_reply) \
2714 _(DHCP_CLIENT_CONFIG_REPLY, dhcp_client_config_reply) \
2715 _(SET_IP_FLOW_HASH_REPLY, set_ip_flow_hash_reply) \
2716 _(SW_INTERFACE_IP6_ENABLE_DISABLE_REPLY, \
2717 sw_interface_ip6_enable_disable_reply) \
2718 _(SW_INTERFACE_IP6_SET_LINK_LOCAL_ADDRESS_REPLY, \
2719 sw_interface_ip6_set_link_local_address_reply) \
2720 _(SW_INTERFACE_IP6ND_RA_PREFIX_REPLY, \
2721 sw_interface_ip6nd_ra_prefix_reply) \
2722 _(SW_INTERFACE_IP6ND_RA_CONFIG_REPLY, \
2723 sw_interface_ip6nd_ra_config_reply) \
2724 _(SET_ARP_NEIGHBOR_LIMIT_REPLY, set_arp_neighbor_limit_reply) \
2725 _(L2_PATCH_ADD_DEL_REPLY, l2_patch_add_del_reply) \
2726 _(SR_TUNNEL_ADD_DEL_REPLY, sr_tunnel_add_del_reply) \
2727 _(SR_POLICY_ADD_DEL_REPLY, sr_policy_add_del_reply) \
2728 _(SR_MULTICAST_MAP_ADD_DEL_REPLY, sr_multicast_map_add_del_reply) \
2729 _(CLASSIFY_ADD_DEL_TABLE_REPLY, classify_add_del_table_reply) \
2730 _(CLASSIFY_ADD_DEL_SESSION_REPLY, classify_add_del_session_reply) \
2731 _(CLASSIFY_SET_INTERFACE_IP_TABLE_REPLY, \
2732 classify_set_interface_ip_table_reply) \
2733 _(CLASSIFY_SET_INTERFACE_L2_TABLES_REPLY, \
2734 classify_set_interface_l2_tables_reply) \
2735 _(GET_NODE_INDEX_REPLY, get_node_index_reply) \
2736 _(ADD_NODE_NEXT_REPLY, add_node_next_reply) \
2737 _(L2TPV3_CREATE_TUNNEL_REPLY, l2tpv3_create_tunnel_reply) \
2738 _(L2TPV3_SET_TUNNEL_COOKIES_REPLY, l2tpv3_set_tunnel_cookies_reply) \
2739 _(L2TPV3_INTERFACE_ENABLE_DISABLE_REPLY, \
2740 l2tpv3_interface_enable_disable_reply) \
2741 _(L2TPV3_SET_LOOKUP_KEY_REPLY, l2tpv3_set_lookup_key_reply) \
2742 _(SW_IF_L2TPV3_TUNNEL_DETAILS, sw_if_l2tpv3_tunnel_details) \
2743 _(VXLAN_ADD_DEL_TUNNEL_REPLY, vxlan_add_del_tunnel_reply) \
2744 _(VXLAN_TUNNEL_DETAILS, vxlan_tunnel_details) \
2745 _(GRE_ADD_DEL_TUNNEL_REPLY, gre_add_del_tunnel_reply) \
2746 _(GRE_TUNNEL_DETAILS, gre_tunnel_details) \
2747 _(L2_FIB_CLEAR_TABLE_REPLY, l2_fib_clear_table_reply) \
2748 _(L2_INTERFACE_EFP_FILTER_REPLY, l2_interface_efp_filter_reply) \
2749 _(L2_INTERFACE_VLAN_TAG_REWRITE_REPLY, l2_interface_vlan_tag_rewrite_reply) \
2750 _(SW_INTERFACE_VHOST_USER_DETAILS, sw_interface_vhost_user_details) \
2751 _(CREATE_VHOST_USER_IF_REPLY, create_vhost_user_if_reply) \
2752 _(MODIFY_VHOST_USER_IF_REPLY, modify_vhost_user_if_reply) \
2753 _(DELETE_VHOST_USER_IF_REPLY, delete_vhost_user_if_reply) \
2754 _(SHOW_VERSION_REPLY, show_version_reply) \
2755 _(L2_FIB_TABLE_ENTRY, l2_fib_table_entry) \
2756 _(VXLAN_GPE_ADD_DEL_TUNNEL_REPLY, vxlan_gpe_add_del_tunnel_reply) \
2757 _(VXLAN_GPE_TUNNEL_DETAILS, vxlan_gpe_tunnel_details) \
2758 _(INTERFACE_NAME_RENUMBER_REPLY, interface_name_renumber_reply) \
2759 _(WANT_IP4_ARP_EVENTS_REPLY, want_ip4_arp_events_reply) \
2760 _(IP4_ARP_EVENT, ip4_arp_event) \
2761 _(INPUT_ACL_SET_INTERFACE_REPLY, input_acl_set_interface_reply) \
2762 _(IP_ADDRESS_DETAILS, ip_address_details) \
2763 _(IP_DETAILS, ip_details) \
2764 _(IPSEC_SPD_ADD_DEL_REPLY, ipsec_spd_add_del_reply) \
2765 _(IPSEC_INTERFACE_ADD_DEL_SPD_REPLY, ipsec_interface_add_del_spd_reply) \
2766 _(IPSEC_SPD_ADD_DEL_ENTRY_REPLY, ipsec_spd_add_del_entry_reply) \
2767 _(IPSEC_SAD_ADD_DEL_ENTRY_REPLY, ipsec_sad_add_del_entry_reply) \
2768 _(IPSEC_SA_SET_KEY_REPLY, ipsec_sa_set_key_reply) \
2769 _(IKEV2_PROFILE_ADD_DEL_REPLY, ikev2_profile_add_del_reply) \
2770 _(IKEV2_PROFILE_SET_AUTH_REPLY, ikev2_profile_set_auth_reply) \
2771 _(IKEV2_PROFILE_SET_ID_REPLY, ikev2_profile_set_id_reply) \
2772 _(IKEV2_PROFILE_SET_TS_REPLY, ikev2_profile_set_ts_reply) \
2773 _(IKEV2_SET_LOCAL_KEY_REPLY, ikev2_set_local_key_reply) \
2774 _(DELETE_LOOPBACK_REPLY, delete_loopback_reply) \
2775 _(BD_IP_MAC_ADD_DEL_REPLY, bd_ip_mac_add_del_reply) \
2776 _(DHCP_COMPL_EVENT, dhcp_compl_event) \
2777 _(VNET_INTERFACE_COUNTERS, vnet_interface_counters) \
2778 _(VNET_IP4_FIB_COUNTERS, vnet_ip4_fib_counters) \
2779 _(VNET_IP6_FIB_COUNTERS, vnet_ip6_fib_counters) \
2780 _(MAP_ADD_DOMAIN_REPLY, map_add_domain_reply) \
2781 _(MAP_DEL_DOMAIN_REPLY, map_del_domain_reply) \
2782 _(MAP_ADD_DEL_RULE_REPLY, map_add_del_rule_reply) \
2783 _(MAP_DOMAIN_DETAILS, map_domain_details) \
2784 _(MAP_RULE_DETAILS, map_rule_details) \
2785 _(WANT_INTERFACE_EVENTS_REPLY, want_interface_events_reply) \
2786 _(WANT_STATS_REPLY, want_stats_reply) \
2787 _(GET_FIRST_MSG_ID_REPLY, get_first_msg_id_reply) \
2788 _(COP_INTERFACE_ENABLE_DISABLE_REPLY, cop_interface_enable_disable_reply) \
2789 _(COP_WHITELIST_ENABLE_DISABLE_REPLY, cop_whitelist_enable_disable_reply) \
2790 _(GET_NODE_GRAPH_REPLY, get_node_graph_reply) \
2791 _(SW_INTERFACE_CLEAR_STATS_REPLY, sw_interface_clear_stats_reply) \
2792 _(TRACE_PROFILE_ADD_REPLY, trace_profile_add_reply) \
2793 _(TRACE_PROFILE_APPLY_REPLY, trace_profile_apply_reply) \
2794 _(TRACE_PROFILE_DEL_REPLY, trace_profile_del_reply) \
2795 _(LISP_ADD_DEL_LOCATOR_SET_REPLY, lisp_add_del_locator_set_reply) \
2796 _(LISP_ADD_DEL_LOCATOR_REPLY, lisp_add_del_locator_reply) \
2797 _(LISP_ADD_DEL_LOCAL_EID_REPLY, lisp_add_del_local_eid_reply) \
2798 _(LISP_GPE_ADD_DEL_FWD_ENTRY_REPLY, lisp_gpe_add_del_fwd_entry_reply) \
2799 _(LISP_ADD_DEL_MAP_RESOLVER_REPLY, lisp_add_del_map_resolver_reply) \
2800 _(LISP_GPE_ENABLE_DISABLE_REPLY, lisp_gpe_enable_disable_reply) \
2801 _(LISP_ENABLE_DISABLE_REPLY, lisp_enable_disable_reply) \
2802 _(LISP_PITR_SET_LOCATOR_SET_REPLY, lisp_pitr_set_locator_set_reply) \
2803 _(LISP_EID_TABLE_ADD_DEL_MAP_REPLY, lisp_eid_table_add_del_map_reply) \
2804 _(LISP_GPE_ADD_DEL_IFACE_REPLY, lisp_gpe_add_del_iface_reply) \
2805 _(LISP_LOCATOR_SET_DETAILS, lisp_locator_set_details) \
2806 _(LISP_LOCAL_EID_TABLE_DETAILS, lisp_local_eid_table_details) \
2807 _(LISP_GPE_TUNNEL_DETAILS, lisp_gpe_tunnel_details) \
2808 _(LISP_MAP_RESOLVER_DETAILS, lisp_map_resolver_details) \
2809 _(LISP_ENABLE_DISABLE_STATUS_DETAILS, \
2810 lisp_enable_disable_status_details) \
2811 _(LISP_ADD_DEL_MAP_REQUEST_ITR_RLOCS_REPLY, \
2812 lisp_add_del_map_request_itr_rlocs_reply) \
2813 _(LISP_GET_MAP_REQUEST_ITR_RLOCS_REPLY, \
2814 lisp_get_map_request_itr_rlocs_reply) \
2815 _(AF_PACKET_CREATE_REPLY, af_packet_create_reply) \
2816 _(AF_PACKET_DELETE_REPLY, af_packet_delete_reply) \
2817 _(POLICER_ADD_DEL_REPLY, policer_add_del_reply) \
2818 _(POLICER_DETAILS, policer_details) \
2819 _(NETMAP_CREATE_REPLY, netmap_create_reply) \
2820 _(NETMAP_DELETE_REPLY, netmap_delete_reply) \
2821 _(MPLS_GRE_TUNNEL_DETAILS, mpls_gre_tunnel_details) \
2822 _(MPLS_ETH_TUNNEL_DETAILS, mpls_eth_tunnel_details) \
2823 _(MPLS_FIB_ENCAP_DETAILS, mpls_fib_encap_details) \
2824 _(MPLS_FIB_DECAP_DETAILS, mpls_fib_decap_details) \
2825 _(CLASSIFY_TABLE_IDS_REPLY, classify_table_ids_reply) \
2826 _(CLASSIFY_TABLE_BY_INTERFACE_REPLY, classify_table_by_interface_reply) \
2827 _(CLASSIFY_TABLE_INFO_REPLY, classify_table_info_reply) \
2828 _(CLASSIFY_SESSION_DETAILS, classify_session_details)
2830 /* M: construct, but don't yet send a message */
2834 vam->result_ready = 0; \
2835 mp = vl_msg_api_alloc(sizeof(*mp)); \
2836 memset (mp, 0, sizeof (*mp)); \
2837 mp->_vl_msg_id = ntohs (VL_API_##T); \
2838 mp->client_index = vam->my_client_index; \
2843 vam->result_ready = 0; \
2844 mp = vl_msg_api_alloc(sizeof(*mp)+(n)); \
2845 memset (mp, 0, sizeof (*mp)); \
2846 mp->_vl_msg_id = ntohs (VL_API_##T); \
2847 mp->client_index = vam->my_client_index; \
2851 /* S: send a message */
2852 #define S (vl_msg_api_send_shmem (vam->vl_input_queue, (u8 *)&mp))
2854 /* W: wait for results, with timeout */
2857 timeout = vat_time_now (vam) + 1.0; \
2859 while (vat_time_now (vam) < timeout) { \
2860 if (vam->result_ready == 1) { \
2861 return (vam->retval); \
2867 /* W2: wait for results, with timeout */
2870 timeout = vat_time_now (vam) + 1.0; \
2872 while (vat_time_now (vam) < timeout) { \
2873 if (vam->result_ready == 1) { \
2875 return (vam->retval); \
2887 #define STR_VTR_OP_CASE(op) \
2888 case L2_VTR_ ## op: \
2891 static const char *str_vtr_op(u32 vtr_op)
2894 STR_VTR_OP_CASE(DISABLED);
2895 STR_VTR_OP_CASE(PUSH_1);
2896 STR_VTR_OP_CASE(PUSH_2);
2897 STR_VTR_OP_CASE(POP_1);
2898 STR_VTR_OP_CASE(POP_2);
2899 STR_VTR_OP_CASE(TRANSLATE_1_1);
2900 STR_VTR_OP_CASE(TRANSLATE_1_2);
2901 STR_VTR_OP_CASE(TRANSLATE_2_1);
2902 STR_VTR_OP_CASE(TRANSLATE_2_2);
2908 static int dump_sub_interface_table (vat_main_t * vam)
2910 const sw_interface_subif_t * sub = NULL;
2912 if (vam->json_output) {
2913 clib_warning ("JSON output supported only for VPE API calls and dump_stats_table");
2918 "%-30s%-12s%-11s%-7s%-5s%-9s%-9s%-6s%-8s%-10s%-10s\n",
2919 "Interface", "sw_if_index",
2920 "sub id", "dot1ad", "tags", "outer id",
2921 "inner id", "exact", "default",
2922 "outer any", "inner any");
2924 vec_foreach (sub, vam->sw_if_subif_table) {
2926 "%-30s%-12d%-11d%-7s%-5d%-9d%-9d%-6d%-8d%-10d%-10d\n",
2927 sub->interface_name,
2929 sub->sub_id, sub->sub_dot1ad ? "dot1ad" : "dot1q",
2930 sub->sub_number_of_tags, sub->sub_outer_vlan_id,
2931 sub->sub_inner_vlan_id, sub->sub_exact_match, sub->sub_default,
2932 sub->sub_outer_vlan_id_any, sub->sub_inner_vlan_id_any);
2933 if (sub->vtr_op != L2_VTR_DISABLED) {
2935 " vlan-tag-rewrite - op: %-14s [ dot1q: %d "
2936 "tag1: %d tag2: %d ]\n",
2937 str_vtr_op(sub->vtr_op), sub->vtr_push_dot1q,
2938 sub->vtr_tag1, sub->vtr_tag2);
2945 static int name_sort_cmp (void * a1, void * a2)
2947 name_sort_t * n1 = a1;
2948 name_sort_t * n2 = a2;
2950 return strcmp ((char *)n1->name, (char *)n2->name);
2953 static int dump_interface_table (vat_main_t * vam)
2956 name_sort_t * nses = 0, * ns;
2958 if (vam->json_output) {
2959 clib_warning ("JSON output supported only for VPE API calls and dump_stats_table");
2963 hash_foreach_pair (p, vam->sw_if_index_by_interface_name,
2965 vec_add2 (nses, ns, 1);
2966 ns->name = (u8 *)(p->key);
2967 ns->value = (u32) p->value[0];
2970 vec_sort_with_function (nses, name_sort_cmp);
2972 fformat (vam->ofp, "%-25s%-15s\n", "Interface", "sw_if_index");
2973 vec_foreach (ns, nses) {
2974 fformat (vam->ofp, "%-25s%-15d\n", ns->name, ns->value);
2980 static int dump_ip_table (vat_main_t * vam, int is_ipv6)
2982 const ip_details_t * det = NULL;
2983 const ip_address_details_t * address = NULL;
2994 vec_foreach (det, vam->ip_details_by_sw_if_index[is_ipv6]) {
2996 if (!det->present) {
3004 "Address", "Prefix length");
3008 vec_foreach (address, det->addr) {
3011 is_ipv6 ? format_ip6_address : format_ip4_address,
3013 address->prefix_length);
3020 static int dump_ipv4_table (vat_main_t * vam)
3022 if (vam->json_output) {
3023 clib_warning ("JSON output supported only for VPE API calls and dump_stats_table");
3027 return dump_ip_table (vam, 0);
3030 static int dump_ipv6_table (vat_main_t * vam)
3032 if (vam->json_output) {
3033 clib_warning ("JSON output supported only for VPE API calls and dump_stats_table");
3037 return dump_ip_table (vam, 1);
3040 static char* counter_type_to_str (u8 counter_type, u8 is_combined)
3043 switch(counter_type) {
3044 case VNET_INTERFACE_COUNTER_DROP:
3046 case VNET_INTERFACE_COUNTER_PUNT:
3048 case VNET_INTERFACE_COUNTER_IP4:
3050 case VNET_INTERFACE_COUNTER_IP6:
3052 case VNET_INTERFACE_COUNTER_RX_NO_BUF:
3054 case VNET_INTERFACE_COUNTER_RX_MISS:
3056 case VNET_INTERFACE_COUNTER_RX_ERROR:
3058 case VNET_INTERFACE_COUNTER_TX_ERROR:
3061 return "INVALID-COUNTER-TYPE";
3064 switch(counter_type) {
3065 case VNET_INTERFACE_COUNTER_RX:
3067 case VNET_INTERFACE_COUNTER_TX:
3070 return "INVALID-COUNTER-TYPE";
3075 static int dump_stats_table (vat_main_t * vam)
3077 vat_json_node_t node;
3078 vat_json_node_t *msg_array;
3079 vat_json_node_t *msg;
3080 vat_json_node_t *counter_array;
3081 vat_json_node_t *counter;
3082 interface_counter_t c;
3084 ip4_fib_counter_t *c4;
3085 ip6_fib_counter_t *c6;
3088 if (!vam->json_output) {
3089 clib_warning ("dump_stats_table supported only in JSON format");
3093 vat_json_init_object(&node);
3095 /* interface counters */
3096 msg_array = vat_json_object_add(&node, "interface_counters");
3097 vat_json_init_array(msg_array);
3098 for (i = 0; i < vec_len(vam->simple_interface_counters); i++) {
3099 msg = vat_json_array_add(msg_array);
3100 vat_json_init_object(msg);
3101 vat_json_object_add_string_copy(msg, "vnet_counter_type",
3102 (u8*)counter_type_to_str(i, 0));
3103 vat_json_object_add_int(msg, "is_combined", 0);
3104 counter_array = vat_json_object_add(msg, "data");
3105 vat_json_init_array(counter_array);
3106 for (j = 0; j < vec_len(vam->simple_interface_counters[i]); j++) {
3107 packets = vam->simple_interface_counters[i][j];
3108 vat_json_array_add_uint(counter_array, packets);
3111 for (i = 0; i < vec_len(vam->combined_interface_counters); i++) {
3112 msg = vat_json_array_add(msg_array);
3113 vat_json_init_object(msg);
3114 vat_json_object_add_string_copy(msg, "vnet_counter_type",
3115 (u8*)counter_type_to_str(i, 1));
3116 vat_json_object_add_int(msg, "is_combined", 1);
3117 counter_array = vat_json_object_add(msg, "data");
3118 vat_json_init_array(counter_array);
3119 for (j = 0; j < vec_len(vam->combined_interface_counters[i]); j++) {
3120 c = vam->combined_interface_counters[i][j];
3121 counter = vat_json_array_add(counter_array);
3122 vat_json_init_object(counter);
3123 vat_json_object_add_uint(counter, "packets", c.packets);
3124 vat_json_object_add_uint(counter, "bytes", c.bytes);
3128 /* ip4 fib counters */
3129 msg_array = vat_json_object_add(&node, "ip4_fib_counters");
3130 vat_json_init_array(msg_array);
3131 for (i = 0; i < vec_len(vam->ip4_fib_counters); i++) {
3132 msg = vat_json_array_add(msg_array);
3133 vat_json_init_object(msg);
3134 vat_json_object_add_uint(msg, "vrf_id", vam->ip4_fib_counters_vrf_id_by_index[i]);
3135 counter_array = vat_json_object_add(msg, "c");
3136 vat_json_init_array(counter_array);
3137 for (j = 0; j < vec_len(vam->ip4_fib_counters[i]); j++) {
3138 counter = vat_json_array_add(counter_array);
3139 vat_json_init_object(counter);
3140 c4 = &vam->ip4_fib_counters[i][j];
3141 vat_json_object_add_ip4(counter, "address", c4->address);
3142 vat_json_object_add_uint(counter, "address_length", c4->address_length);
3143 vat_json_object_add_uint(counter, "packets", c4->packets);
3144 vat_json_object_add_uint(counter, "bytes", c4->bytes);
3148 /* ip6 fib counters */
3149 msg_array = vat_json_object_add(&node, "ip6_fib_counters");
3150 vat_json_init_array(msg_array);
3151 for (i = 0; i < vec_len(vam->ip6_fib_counters); i++) {
3152 msg = vat_json_array_add(msg_array);
3153 vat_json_init_object(msg);
3154 vat_json_object_add_uint(msg, "vrf_id", vam->ip6_fib_counters_vrf_id_by_index[i]);
3155 counter_array = vat_json_object_add(msg, "c");
3156 vat_json_init_array(counter_array);
3157 for (j = 0; j < vec_len(vam->ip6_fib_counters[i]); j++) {
3158 counter = vat_json_array_add(counter_array);
3159 vat_json_init_object(counter);
3160 c6 = &vam->ip6_fib_counters[i][j];
3161 vat_json_object_add_ip6(counter, "address", c6->address);
3162 vat_json_object_add_uint(counter, "address_length", c6->address_length);
3163 vat_json_object_add_uint(counter, "packets", c6->packets);
3164 vat_json_object_add_uint(counter, "bytes", c6->bytes);
3168 vat_json_print(vam->ofp, &node);
3169 vat_json_free(&node);
3174 int exec (vat_main_t * vam)
3176 api_main_t * am = &api_main;
3177 vl_api_cli_request_t *mp;
3181 unformat_input_t * i = vam->input;
3183 if (vec_len(i->buffer) == 0)
3186 if (vam->exec_mode == 0 && unformat (i, "mode")) {
3190 if (vam->exec_mode == 1 &&
3191 (unformat (i, "exit") || unformat (i, "quit"))) {
3197 M(CLI_REQUEST, cli_request);
3200 * Copy cmd into shared memory.
3201 * In order for the CLI command to work, it
3202 * must be a vector ending in \n, not a C-string ending
3205 pthread_mutex_lock (&am->vlib_rp->mutex);
3206 oldheap = svm_push_data_heap (am->vlib_rp);
3208 vec_validate (cmd, vec_len(vam->input->buffer)-1);
3209 clib_memcpy (cmd, vam->input->buffer, vec_len(vam->input->buffer));
3211 svm_pop_heap (oldheap);
3212 pthread_mutex_unlock (&am->vlib_rp->mutex);
3214 mp->cmd_in_shmem = (u64) cmd;
3216 timeout = vat_time_now (vam) + 10.0;
3218 while (vat_time_now (vam) < timeout) {
3219 if (vam->result_ready == 1) {
3221 if (vam->shmem_result != NULL)
3222 fformat (vam->ofp, "%s", vam->shmem_result);
3223 pthread_mutex_lock (&am->vlib_rp->mutex);
3224 oldheap = svm_push_data_heap (am->vlib_rp);
3226 free_me = (u8 *)vam->shmem_result;
3229 svm_pop_heap (oldheap);
3230 pthread_mutex_unlock (&am->vlib_rp->mutex);
3237 static int api_create_loopback (vat_main_t * vam)
3239 unformat_input_t * i = vam->input;
3240 vl_api_create_loopback_t *mp;
3245 memset (mac_address, 0, sizeof (mac_address));
3247 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
3249 if (unformat (i, "mac %U", unformat_ethernet_address, mac_address))
3255 /* Construct the API message */
3256 M(CREATE_LOOPBACK, create_loopback);
3258 clib_memcpy (mp->mac_address, mac_address, sizeof (mac_address));
3263 static int api_delete_loopback (vat_main_t * vam)
3265 unformat_input_t * i = vam->input;
3266 vl_api_delete_loopback_t *mp;
3268 u32 sw_if_index = ~0;
3270 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
3272 if (unformat (i, "sw_if_index %d", &sw_if_index))
3278 if (sw_if_index == ~0)
3280 errmsg ("missing sw_if_index\n");
3284 /* Construct the API message */
3285 M(DELETE_LOOPBACK, delete_loopback);
3286 mp->sw_if_index = ntohl (sw_if_index);
3291 static int api_want_stats (vat_main_t * vam)
3293 unformat_input_t * i = vam->input;
3294 vl_api_want_stats_t * mp;
3298 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
3300 if (unformat (i, "enable"))
3302 else if (unformat (i, "disable"))
3310 errmsg ("missing enable|disable\n");
3314 M(WANT_STATS, want_stats);
3315 mp->enable_disable = enable;
3320 static int api_want_interface_events (vat_main_t * vam)
3322 unformat_input_t * i = vam->input;
3323 vl_api_want_interface_events_t * mp;
3327 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
3329 if (unformat (i, "enable"))
3331 else if (unformat (i, "disable"))
3339 errmsg ("missing enable|disable\n");
3343 M(WANT_INTERFACE_EVENTS, want_interface_events);
3344 mp->enable_disable = enable;
3346 vam->interface_event_display = enable;
3352 /* Note: non-static, called once to set up the initial intfc table */
3353 int api_sw_interface_dump (vat_main_t * vam)
3355 vl_api_sw_interface_dump_t *mp;
3358 name_sort_t * nses = 0, * ns;
3359 sw_interface_subif_t * sub = NULL;
3361 /* Toss the old name table */
3362 hash_foreach_pair (p, vam->sw_if_index_by_interface_name,
3364 vec_add2 (nses, ns, 1);
3365 ns->name = (u8 *)(p->key);
3366 ns->value = (u32) p->value[0];
3369 hash_free (vam->sw_if_index_by_interface_name);
3371 vec_foreach (ns, nses)
3372 vec_free (ns->name);
3376 vec_foreach (sub, vam->sw_if_subif_table) {
3377 vec_free (sub->interface_name);
3379 vec_free (vam->sw_if_subif_table);
3381 /* recreate the interface name hash table */
3382 vam->sw_if_index_by_interface_name
3383 = hash_create_string (0, sizeof(uword));
3385 /* Get list of ethernets */
3386 M(SW_INTERFACE_DUMP, sw_interface_dump);
3387 mp->name_filter_valid = 1;
3388 strncpy ((char *) mp->name_filter, "Ether", sizeof(mp->name_filter)-1);
3391 /* and local / loopback interfaces */
3392 M(SW_INTERFACE_DUMP, sw_interface_dump);
3393 mp->name_filter_valid = 1;
3394 strncpy ((char *) mp->name_filter, "lo", sizeof(mp->name_filter)-1);
3398 /* and vxlan-gpe tunnel interfaces */
3399 M(SW_INTERFACE_DUMP, sw_interface_dump);
3400 mp->name_filter_valid = 1;
3401 strncpy ((char *) mp->name_filter, "vxlan_gpe", sizeof(mp->name_filter)-1);
3404 /* and vxlan tunnel interfaces */
3405 M(SW_INTERFACE_DUMP, sw_interface_dump);
3406 mp->name_filter_valid = 1;
3407 strncpy ((char *) mp->name_filter, "vxlan", sizeof(mp->name_filter)-1);
3410 /* and host (af_packet) interfaces */
3411 M(SW_INTERFACE_DUMP, sw_interface_dump);
3412 mp->name_filter_valid = 1;
3413 strncpy ((char *) mp->name_filter, "host", sizeof(mp->name_filter)-1);
3416 /* and l2tpv3 tunnel interfaces */
3417 M(SW_INTERFACE_DUMP, sw_interface_dump);
3418 mp->name_filter_valid = 1;
3419 strncpy ((char *) mp->name_filter, "l2tpv3_tunnel", sizeof(mp->name_filter)-1);
3422 /* and GRE tunnel interfaces */
3423 M(SW_INTERFACE_DUMP, sw_interface_dump);
3424 mp->name_filter_valid = 1;
3425 strncpy ((char *) mp->name_filter, "gre", sizeof(mp->name_filter)-1);
3428 /* Use a control ping for synchronization */
3430 vl_api_control_ping_t * mp;
3431 M(CONTROL_PING, control_ping);
3437 static int api_sw_interface_set_flags (vat_main_t * vam)
3439 unformat_input_t * i = vam->input;
3440 vl_api_sw_interface_set_flags_t *mp;
3443 u8 sw_if_index_set = 0;
3444 u8 admin_up = 0, link_up = 0;
3446 /* Parse args required to build the message */
3447 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
3448 if (unformat (i, "admin-up"))
3450 else if (unformat (i, "admin-down"))
3452 else if (unformat (i, "link-up"))
3454 else if (unformat (i, "link-down"))
3456 else if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
3457 sw_if_index_set = 1;
3458 else if (unformat (i, "sw_if_index %d", &sw_if_index))
3459 sw_if_index_set = 1;
3464 if (sw_if_index_set == 0) {
3465 errmsg ("missing interface name or sw_if_index\n");
3469 /* Construct the API message */
3470 M(SW_INTERFACE_SET_FLAGS, sw_interface_set_flags);
3471 mp->sw_if_index = ntohl (sw_if_index);
3472 mp->admin_up_down = admin_up;
3473 mp->link_up_down = link_up;
3478 /* Wait for a reply, return the good/bad news... */
3482 static int api_sw_interface_clear_stats (vat_main_t * vam)
3484 unformat_input_t * i = vam->input;
3485 vl_api_sw_interface_clear_stats_t *mp;
3488 u8 sw_if_index_set = 0;
3490 /* Parse args required to build the message */
3491 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
3492 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
3493 sw_if_index_set = 1;
3494 else if (unformat (i, "sw_if_index %d", &sw_if_index))
3495 sw_if_index_set = 1;
3500 /* Construct the API message */
3501 M(SW_INTERFACE_CLEAR_STATS, sw_interface_clear_stats);
3503 if (sw_if_index_set == 1)
3504 mp->sw_if_index = ntohl (sw_if_index);
3506 mp->sw_if_index = ~0;
3511 /* Wait for a reply, return the good/bad news... */
3515 static int api_sw_interface_add_del_address (vat_main_t * vam)
3517 unformat_input_t * i = vam->input;
3518 vl_api_sw_interface_add_del_address_t *mp;
3521 u8 sw_if_index_set = 0;
3522 u8 is_add = 1, del_all = 0;
3523 u32 address_length = 0;
3524 u8 v4_address_set = 0;
3525 u8 v6_address_set = 0;
3526 ip4_address_t v4address;
3527 ip6_address_t v6address;
3529 /* Parse args required to build the message */
3530 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
3531 if (unformat (i, "del-all"))
3533 else if (unformat (i, "del"))
3535 else if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
3536 sw_if_index_set = 1;
3537 else if (unformat (i, "sw_if_index %d", &sw_if_index))
3538 sw_if_index_set = 1;
3539 else if (unformat (i, "%U/%d",
3540 unformat_ip4_address, &v4address,
3543 else if (unformat (i, "%U/%d",
3544 unformat_ip6_address, &v6address,
3551 if (sw_if_index_set == 0) {
3552 errmsg ("missing interface name or sw_if_index\n");
3555 if (v4_address_set && v6_address_set) {
3556 errmsg ("both v4 and v6 addresses set\n");
3559 if (!v4_address_set && !v6_address_set && !del_all) {
3560 errmsg ("no addresses set\n");
3564 /* Construct the API message */
3565 M(SW_INTERFACE_ADD_DEL_ADDRESS, sw_interface_add_del_address);
3567 mp->sw_if_index = ntohl (sw_if_index);
3568 mp->is_add = is_add;
3569 mp->del_all = del_all;
3570 if (v6_address_set) {
3572 clib_memcpy (mp->address, &v6address, sizeof (v6address));
3574 clib_memcpy (mp->address, &v4address, sizeof (v4address));
3576 mp->address_length = address_length;
3581 /* Wait for a reply, return good/bad news */
3585 static int api_sw_interface_set_table (vat_main_t * vam)
3587 unformat_input_t * i = vam->input;
3588 vl_api_sw_interface_set_table_t *mp;
3590 u32 sw_if_index, vrf_id = 0;
3591 u8 sw_if_index_set = 0;
3594 /* Parse args required to build the message */
3595 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
3596 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
3597 sw_if_index_set = 1;
3598 else if (unformat (i, "sw_if_index %d", &sw_if_index))
3599 sw_if_index_set = 1;
3600 else if (unformat (i, "vrf %d", &vrf_id))
3602 else if (unformat (i, "ipv6"))
3608 if (sw_if_index_set == 0) {
3609 errmsg ("missing interface name or sw_if_index\n");
3613 /* Construct the API message */
3614 M(SW_INTERFACE_SET_TABLE, sw_interface_set_table);
3616 mp->sw_if_index = ntohl (sw_if_index);
3617 mp->is_ipv6 = is_ipv6;
3618 mp->vrf_id = ntohl (vrf_id);
3623 /* Wait for a reply... */
3627 static int api_sw_interface_set_vpath (vat_main_t * vam)
3629 unformat_input_t * i = vam->input;
3630 vl_api_sw_interface_set_vpath_t *mp;
3632 u32 sw_if_index = 0;
3633 u8 sw_if_index_set = 0;
3636 /* Parse args required to build the message */
3637 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
3638 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
3639 sw_if_index_set = 1;
3640 else if (unformat (i, "sw_if_index %d", &sw_if_index))
3641 sw_if_index_set = 1;
3642 else if (unformat (i, "enable"))
3644 else if (unformat (i, "disable"))
3650 if (sw_if_index_set == 0) {
3651 errmsg ("missing interface name or sw_if_index\n");
3655 /* Construct the API message */
3656 M(SW_INTERFACE_SET_VPATH, sw_interface_set_vpath);
3658 mp->sw_if_index = ntohl (sw_if_index);
3659 mp->enable = is_enable;
3664 /* Wait for a reply... */
3668 static int api_sw_interface_set_l2_xconnect (vat_main_t * vam)
3670 unformat_input_t * i = vam->input;
3671 vl_api_sw_interface_set_l2_xconnect_t *mp;
3674 u8 rx_sw_if_index_set = 0;
3676 u8 tx_sw_if_index_set = 0;
3679 /* Parse args required to build the message */
3680 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
3681 if (unformat (i, "rx_sw_if_index %d", &rx_sw_if_index))
3682 rx_sw_if_index_set = 1;
3683 else if (unformat (i, "tx_sw_if_index %d", &tx_sw_if_index))
3684 tx_sw_if_index_set = 1;
3685 else if (unformat (i, "rx")) {
3686 if (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
3687 if (unformat (i, "%U", unformat_sw_if_index, vam,
3689 rx_sw_if_index_set = 1;
3692 } else if (unformat (i, "tx")) {
3693 if (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
3694 if (unformat (i, "%U", unformat_sw_if_index, vam,
3696 tx_sw_if_index_set = 1;
3699 } else if (unformat (i, "enable"))
3701 else if (unformat (i, "disable"))
3707 if (rx_sw_if_index_set == 0) {
3708 errmsg ("missing rx interface name or rx_sw_if_index\n");
3712 if (enable && (tx_sw_if_index_set == 0)) {
3713 errmsg ("missing tx interface name or tx_sw_if_index\n");
3717 M(SW_INTERFACE_SET_L2_XCONNECT, sw_interface_set_l2_xconnect);
3719 mp->rx_sw_if_index = ntohl(rx_sw_if_index);
3720 mp->tx_sw_if_index = ntohl(tx_sw_if_index);
3721 mp->enable = enable;
3728 static int api_sw_interface_set_l2_bridge (vat_main_t * vam)
3730 unformat_input_t * i = vam->input;
3731 vl_api_sw_interface_set_l2_bridge_t *mp;
3734 u8 rx_sw_if_index_set = 0;
3741 /* Parse args required to build the message */
3742 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
3743 if (unformat (i, "sw_if_index %d", &rx_sw_if_index))
3744 rx_sw_if_index_set = 1;
3745 else if (unformat (i, "bd_id %d", &bd_id))
3747 else if (unformat (i, "%U", unformat_sw_if_index, vam,
3749 rx_sw_if_index_set = 1;
3750 else if (unformat (i, "shg %d", &shg))
3752 else if (unformat (i, "bvi"))
3754 else if (unformat (i, "enable"))
3756 else if (unformat (i, "disable"))
3762 if (rx_sw_if_index_set == 0) {
3763 errmsg ("missing rx interface name or sw_if_index\n");
3767 if (enable && (bd_id_set == 0)) {
3768 errmsg ("missing bridge domain\n");
3772 M(SW_INTERFACE_SET_L2_BRIDGE, sw_interface_set_l2_bridge);
3774 mp->rx_sw_if_index = ntohl(rx_sw_if_index);
3775 mp->bd_id = ntohl(bd_id);
3778 mp->enable = enable;
3785 static int api_bridge_domain_dump (vat_main_t * vam)
3787 unformat_input_t * i = vam->input;
3788 vl_api_bridge_domain_dump_t *mp;
3792 /* Parse args required to build the message */
3793 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
3794 if (unformat (i, "bd_id %d", &bd_id))
3800 M(BRIDGE_DOMAIN_DUMP, bridge_domain_dump);
3801 mp->bd_id = ntohl(bd_id);
3804 /* Use a control ping for synchronization */
3806 vl_api_control_ping_t * mp;
3807 M(CONTROL_PING, control_ping);
3816 static int api_bridge_domain_add_del (vat_main_t * vam)
3818 unformat_input_t * i = vam->input;
3819 vl_api_bridge_domain_add_del_t *mp;
3823 u32 flood = 1, forward = 1, learn = 1, uu_flood = 1, arp_term = 0;
3825 /* Parse args required to build the message */
3826 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
3827 if (unformat (i, "bd_id %d", &bd_id))
3829 else if (unformat (i, "flood %d", &flood))
3831 else if (unformat (i, "uu-flood %d", &uu_flood))
3833 else if (unformat (i, "forward %d", &forward))
3835 else if (unformat (i, "learn %d", &learn))
3837 else if (unformat (i, "arp-term %d", &arp_term))
3839 else if (unformat (i, "del")) {
3841 flood = uu_flood = forward = learn = 0;
3848 errmsg ("missing bridge domain\n");
3852 M(BRIDGE_DOMAIN_ADD_DEL, bridge_domain_add_del);
3854 mp->bd_id = ntohl(bd_id);
3856 mp->uu_flood = uu_flood;
3857 mp->forward = forward;
3859 mp->arp_term = arp_term;
3860 mp->is_add = is_add;
3867 static int api_l2fib_add_del (vat_main_t * vam)
3869 unformat_input_t * i = vam->input;
3870 vl_api_l2fib_add_del_t *mp;
3877 u8 sw_if_index_set = 0;
3882 /* Parse args required to build the message */
3883 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
3884 if (unformat (i, "mac %U", unformat_ethernet_address, &mac))
3886 else if (unformat (i, "bd_id %d", &bd_id))
3888 else if (unformat (i, "sw_if_index %d", &sw_if_index))
3889 sw_if_index_set = 1;
3890 else if (unformat (i, "sw_if")) {
3891 if (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
3892 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
3893 sw_if_index_set = 1;
3896 } else if (unformat (i, "static"))
3898 else if (unformat (i, "filter")) {
3901 } else if (unformat (i, "del"))
3908 errmsg ("missing mac address\n");
3912 if (bd_id_set == 0) {
3913 errmsg ("missing bridge domain\n");
3917 if (is_add && (sw_if_index_set == 0)) {
3918 errmsg ("missing interface name or sw_if_index\n");
3922 M(L2FIB_ADD_DEL, l2fib_add_del);
3925 mp->bd_id = ntohl(bd_id);
3926 mp->is_add = is_add;
3929 mp->sw_if_index = ntohl(sw_if_index);
3930 mp->static_mac = static_mac;
3931 mp->filter_mac = filter_mac;
3939 static int api_l2_flags (vat_main_t * vam)
3941 unformat_input_t * i = vam->input;
3942 vl_api_l2_flags_t *mp;
3945 u32 feature_bitmap = 0;
3946 u8 sw_if_index_set = 0;
3948 /* Parse args required to build the message */
3949 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
3950 if (unformat (i, "sw_if_index %d", &sw_if_index))
3951 sw_if_index_set = 1;
3952 else if (unformat (i, "sw_if")) {
3953 if (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
3954 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
3955 sw_if_index_set = 1;
3958 } else if (unformat (i, "learn"))
3959 feature_bitmap |= L2INPUT_FEAT_LEARN;
3960 else if (unformat (i, "forward"))
3961 feature_bitmap |= L2INPUT_FEAT_FWD;
3962 else if (unformat (i, "flood"))
3963 feature_bitmap |= L2INPUT_FEAT_FLOOD;
3964 else if (unformat (i, "uu-flood"))
3965 feature_bitmap |= L2INPUT_FEAT_UU_FLOOD;
3970 if (sw_if_index_set == 0) {
3971 errmsg ("missing interface name or sw_if_index\n");
3975 M(L2_FLAGS, l2_flags);
3977 mp->sw_if_index = ntohl(sw_if_index);
3978 mp->feature_bitmap = ntohl(feature_bitmap);
3985 static int api_bridge_flags (vat_main_t * vam)
3987 unformat_input_t * i = vam->input;
3988 vl_api_bridge_flags_t *mp;
3995 /* Parse args required to build the message */
3996 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
3997 if (unformat (i, "bd_id %d", &bd_id))
3999 else if (unformat (i, "learn"))
4001 else if (unformat (i, "forward"))
4003 else if (unformat (i, "flood"))
4005 else if (unformat (i, "uu-flood"))
4006 flags |= L2_UU_FLOOD;
4007 else if (unformat (i, "arp-term"))
4008 flags |= L2_ARP_TERM;
4009 else if (unformat (i, "off"))
4011 else if (unformat (i, "disable"))
4017 if (bd_id_set == 0) {
4018 errmsg ("missing bridge domain\n");
4022 M(BRIDGE_FLAGS, bridge_flags);
4024 mp->bd_id = ntohl(bd_id);
4025 mp->feature_bitmap = ntohl(flags);
4026 mp->is_set = is_set;
4033 static int api_bd_ip_mac_add_del (vat_main_t * vam)
4035 unformat_input_t * i = vam->input;
4036 vl_api_bd_ip_mac_add_del_t *mp;
4044 ip4_address_t v4addr;
4045 ip6_address_t v6addr;
4049 /* Parse args required to build the message */
4050 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
4051 if (unformat (i, "bd_id %d", &bd_id)) {
4053 } else if (unformat (i, "%U", unformat_ip4_address, &v4addr)) {
4055 } else if (unformat (i, "%U", unformat_ip6_address, &v6addr)) {
4058 } else if (unformat (i, "%U", unformat_ethernet_address, macaddr)) {
4060 } else if (unformat (i, "del"))
4066 if (bd_id_set == 0) {
4067 errmsg ("missing bridge domain\n");
4069 } else if (ip_set == 0) {
4070 errmsg ("missing IP address\n");
4072 } else if (mac_set == 0) {
4073 errmsg ("missing MAC address\n");
4077 M(BD_IP_MAC_ADD_DEL, bd_ip_mac_add_del);
4079 mp->bd_id = ntohl(bd_id);
4080 mp->is_ipv6 = is_ipv6;
4081 mp->is_add = is_add;
4083 clib_memcpy (mp->ip_address, &v6addr, sizeof (v6addr));
4084 else clib_memcpy (mp->ip_address, &v4addr, sizeof (v4addr));
4085 clib_memcpy (mp->mac_address, macaddr, 6);
4091 static int api_tap_connect (vat_main_t * vam)
4093 unformat_input_t * i = vam->input;
4094 vl_api_tap_connect_t *mp;
4101 memset (mac_address, 0, sizeof (mac_address));
4103 /* Parse args required to build the message */
4104 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
4105 if (unformat (i, "mac %U", unformat_ethernet_address, mac_address)) {
4108 else if (unformat (i, "random-mac"))
4110 else if (unformat (i, "tapname %s", &tap_name))
4116 if (name_set == 0) {
4117 errmsg ("missing tap name\n");
4120 if (vec_len (tap_name) > 63) {
4121 errmsg ("tap name too long\n");
4123 vec_add1 (tap_name, 0);
4125 /* Construct the API message */
4126 M(TAP_CONNECT, tap_connect);
4128 mp->use_random_mac = random_mac;
4129 clib_memcpy (mp->mac_address, mac_address, 6);
4130 clib_memcpy (mp->tap_name, tap_name, vec_len (tap_name));
4131 vec_free (tap_name);
4136 /* Wait for a reply... */
4140 static int api_tap_modify (vat_main_t * vam)
4142 unformat_input_t * i = vam->input;
4143 vl_api_tap_modify_t *mp;
4149 u32 sw_if_index = ~0;
4150 u8 sw_if_index_set = 0;
4152 memset (mac_address, 0, sizeof (mac_address));
4154 /* Parse args required to build the message */
4155 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
4156 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
4157 sw_if_index_set = 1;
4158 else if (unformat (i, "sw_if_index %d", &sw_if_index))
4159 sw_if_index_set = 1;
4160 else if (unformat (i, "mac %U", unformat_ethernet_address, mac_address)) {
4163 else if (unformat (i, "random-mac"))
4165 else if (unformat (i, "tapname %s", &tap_name))
4171 if (sw_if_index_set == 0) {
4172 errmsg ("missing vpp interface name");
4175 if (name_set == 0) {
4176 errmsg ("missing tap name\n");
4179 if (vec_len (tap_name) > 63) {
4180 errmsg ("tap name too long\n");
4182 vec_add1 (tap_name, 0);
4184 /* Construct the API message */
4185 M(TAP_MODIFY, tap_modify);
4187 mp->use_random_mac = random_mac;
4188 mp->sw_if_index = ntohl(sw_if_index);
4189 clib_memcpy (mp->mac_address, mac_address, 6);
4190 clib_memcpy (mp->tap_name, tap_name, vec_len (tap_name));
4191 vec_free (tap_name);
4196 /* Wait for a reply... */
4200 static int api_tap_delete (vat_main_t * vam)
4202 unformat_input_t * i = vam->input;
4203 vl_api_tap_delete_t *mp;
4205 u32 sw_if_index = ~0;
4206 u8 sw_if_index_set = 0;
4208 /* Parse args required to build the message */
4209 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
4210 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
4211 sw_if_index_set = 1;
4212 else if (unformat (i, "sw_if_index %d", &sw_if_index))
4213 sw_if_index_set = 1;
4218 if (sw_if_index_set == 0) {
4219 errmsg ("missing vpp interface name");
4223 /* Construct the API message */
4224 M(TAP_DELETE, tap_delete);
4226 mp->sw_if_index = ntohl(sw_if_index);
4231 /* Wait for a reply... */
4235 static int api_ip_add_del_route (vat_main_t * vam)
4237 unformat_input_t * i = vam->input;
4238 vl_api_ip_add_del_route_t *mp;
4240 u32 sw_if_index = 0, vrf_id = 0;
4241 u8 sw_if_index_set = 0;
4243 u8 is_local = 0, is_drop = 0;
4244 u8 create_vrf_if_needed = 0;
4246 u8 next_hop_weight = 1;
4248 u8 is_multipath = 0;
4250 u8 address_length_set = 0;
4251 u32 lookup_in_vrf = 0;
4252 u32 resolve_attempts = 0;
4253 u32 dst_address_length = 0;
4254 u8 next_hop_set = 0;
4255 ip4_address_t v4_dst_address, v4_next_hop_address;
4256 ip6_address_t v6_dst_address, v6_next_hop_address;
4260 u32 random_add_del = 0;
4261 u32 * random_vector = 0;
4262 uword * random_hash;
4263 u32 random_seed = 0xdeaddabe;
4264 u32 classify_table_index = ~0;
4267 /* Parse args required to build the message */
4268 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
4269 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
4270 sw_if_index_set = 1;
4271 else if (unformat (i, "sw_if_index %d", &sw_if_index))
4272 sw_if_index_set = 1;
4273 else if (unformat (i, "%U", unformat_ip4_address,
4278 else if (unformat (i, "%U", unformat_ip6_address, &v6_dst_address)) {
4282 else if (unformat (i, "/%d", &dst_address_length)) {
4283 address_length_set = 1;
4286 else if (is_ipv6 == 0 && unformat (i, "via %U", unformat_ip4_address,
4287 &v4_next_hop_address)) {
4290 else if (is_ipv6 == 1 && unformat (i, "via %U", unformat_ip6_address,
4291 &v6_next_hop_address)) {
4294 else if (unformat (i, "resolve-attempts %d", &resolve_attempts))
4296 else if (unformat (i, "weight %d", &next_hop_weight))
4298 else if (unformat (i, "drop")) {
4300 } else if (unformat (i, "local")) {
4302 } else if (unformat (i, "classify %d", &classify_table_index)) {
4304 } else if (unformat (i, "del"))
4306 else if (unformat (i, "add"))
4308 else if (unformat (i, "not-last"))
4310 else if (unformat (i, "multipath"))
4312 else if (unformat (i, "vrf %d", &vrf_id))
4314 else if (unformat (i, "create-vrf"))
4315 create_vrf_if_needed = 1;
4316 else if (unformat (i, "count %d", &count))
4318 else if (unformat (i, "lookup-in-vrf %d", &lookup_in_vrf))
4320 else if (unformat (i, "random"))
4322 else if (unformat (i, "seed %d", &random_seed))
4325 clib_warning ("parse error '%U'", format_unformat_error, i);
4330 if (resolve_attempts > 0 && sw_if_index_set == 0) {
4331 errmsg ("ARP resolution needs explicit interface or sw_if_index\n");
4335 if (!next_hop_set && !is_drop && !is_local && !is_classify) {
4336 errmsg ("next hop / local / drop / classify not set\n");
4340 if (address_set == 0) {
4341 errmsg ("missing addresses\n");
4345 if (address_length_set == 0) {
4346 errmsg ("missing address length\n");
4350 /* Generate a pile of unique, random routes */
4351 if (random_add_del) {
4352 u32 this_random_address;
4353 random_hash = hash_create (count, sizeof(uword));
4355 hash_set (random_hash, v4_next_hop_address.as_u32, 1);
4356 for (j = 0; j <= count; j++) {
4358 this_random_address = random_u32 (&random_seed);
4359 this_random_address =
4360 clib_host_to_net_u32 (this_random_address);
4361 } while (hash_get (random_hash, this_random_address));
4362 vec_add1 (random_vector, this_random_address);
4363 hash_set (random_hash, this_random_address, 1);
4365 hash_free (random_hash);
4366 v4_dst_address.as_u32 = random_vector[0];
4370 /* Turn on async mode */
4371 vam->async_mode = 1;
4372 vam->async_errors = 0;
4373 before = vat_time_now(vam);
4376 for (j = 0; j < count; j++) {
4377 /* Construct the API message */
4378 M(IP_ADD_DEL_ROUTE, ip_add_del_route);
4380 mp->next_hop_sw_if_index = ntohl (sw_if_index);
4381 mp->vrf_id = ntohl (vrf_id);
4382 if (resolve_attempts > 0) {
4383 mp->resolve_attempts = ntohl (resolve_attempts);
4384 mp->resolve_if_needed = 1;
4386 mp->create_vrf_if_needed = create_vrf_if_needed;
4388 mp->is_add = is_add;
4389 mp->is_drop = is_drop;
4390 mp->is_ipv6 = is_ipv6;
4391 mp->is_local = is_local;
4392 mp->is_classify = is_classify;
4393 mp->is_multipath = is_multipath;
4394 mp->not_last = not_last;
4395 mp->next_hop_weight = next_hop_weight;
4396 mp->dst_address_length = dst_address_length;
4397 mp->lookup_in_vrf = ntohl(lookup_in_vrf);
4398 mp->classify_table_index = ntohl(classify_table_index);
4401 clib_memcpy (mp->dst_address, &v6_dst_address, sizeof (v6_dst_address));
4403 clib_memcpy (mp->next_hop_address, &v6_next_hop_address,
4404 sizeof (v6_next_hop_address));
4405 increment_v6_address (&v6_dst_address);
4407 clib_memcpy (mp->dst_address, &v4_dst_address, sizeof (v4_dst_address));
4409 clib_memcpy (mp->next_hop_address, &v4_next_hop_address,
4410 sizeof (v4_next_hop_address));
4412 v4_dst_address.as_u32 = random_vector[j+1];
4414 increment_v4_address (&v4_dst_address);
4420 /* When testing multiple add/del ops, use a control-ping to sync */
4422 vl_api_control_ping_t * mp;
4425 /* Shut off async mode */
4426 vam->async_mode = 0;
4428 M(CONTROL_PING, control_ping);
4431 timeout = vat_time_now(vam) + 1.0;
4432 while (vat_time_now (vam) < timeout)
4433 if (vam->result_ready == 1)
4438 if (vam->retval == -99)
4439 errmsg ("timeout\n");
4441 if (vam->async_errors > 0) {
4442 errmsg ("%d asynchronous errors\n", vam->async_errors);
4445 vam->async_errors = 0;
4446 after = vat_time_now(vam);
4448 fformat(vam->ofp, "%d routes in %.6f secs, %.2f routes/sec\n",
4449 count, after - before, count / (after - before));
4451 /* Wait for a reply... */
4455 /* Return the good/bad news */
4456 return (vam->retval);
4459 static int api_proxy_arp_add_del (vat_main_t * vam)
4461 unformat_input_t * i = vam->input;
4462 vl_api_proxy_arp_add_del_t *mp;
4466 ip4_address_t lo, hi;
4469 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
4470 if (unformat (i, "vrf %d", &vrf_id))
4472 else if (unformat (i, "%U - %U", unformat_ip4_address, &lo,
4473 unformat_ip4_address, &hi))
4475 else if (unformat (i, "del"))
4478 clib_warning ("parse error '%U'", format_unformat_error, i);
4483 if (range_set == 0) {
4484 errmsg ("address range not set\n");
4488 M(PROXY_ARP_ADD_DEL, proxy_arp_add_del);
4490 mp->vrf_id = ntohl(vrf_id);
4491 mp->is_add = is_add;
4492 clib_memcpy(mp->low_address, &lo, sizeof (mp->low_address));
4493 clib_memcpy(mp->hi_address, &hi, sizeof (mp->hi_address));
4500 static int api_proxy_arp_intfc_enable_disable (vat_main_t * vam)
4502 unformat_input_t * i = vam->input;
4503 vl_api_proxy_arp_intfc_enable_disable_t *mp;
4507 u8 sw_if_index_set = 0;
4509 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
4510 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
4511 sw_if_index_set = 1;
4512 else if (unformat (i, "sw_if_index %d", &sw_if_index))
4513 sw_if_index_set = 1;
4514 else if (unformat (i, "enable"))
4516 else if (unformat (i, "disable"))
4519 clib_warning ("parse error '%U'", format_unformat_error, i);
4524 if (sw_if_index_set == 0) {
4525 errmsg ("missing interface name or sw_if_index\n");
4529 M(PROXY_ARP_INTFC_ENABLE_DISABLE, proxy_arp_intfc_enable_disable);
4531 mp->sw_if_index = ntohl(sw_if_index);
4532 mp->enable_disable = enable;
4539 static int api_mpls_add_del_decap (vat_main_t * vam)
4541 unformat_input_t * i = vam->input;
4542 vl_api_mpls_add_del_decap_t *mp;
4551 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
4552 if (unformat (i, "rx_vrf_id %d", &rx_vrf_id))
4554 else if (unformat (i, "tx_vrf_id %d", &tx_vrf_id))
4556 else if (unformat (i, "label %d", &label))
4558 else if (unformat (i, "next-index %d", &next_index))
4560 else if (unformat (i, "del"))
4562 else if (unformat (i, "s-bit-clear"))
4565 clib_warning ("parse error '%U'", format_unformat_error, i);
4570 M(MPLS_ADD_DEL_DECAP, mpls_add_del_decap);
4572 mp->rx_vrf_id = ntohl(rx_vrf_id);
4573 mp->tx_vrf_id = ntohl(tx_vrf_id);
4574 mp->label = ntohl(label);
4575 mp->next_index = ntohl(next_index);
4577 mp->is_add = is_add;
4584 static int api_mpls_add_del_encap (vat_main_t * vam)
4586 unformat_input_t * i = vam->input;
4587 vl_api_mpls_add_del_encap_t *mp;
4592 ip4_address_t dst_address;
4595 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
4596 if (unformat (i, "vrf %d", &vrf_id))
4598 else if (unformat (i, "label %d", &label))
4599 vec_add1 (labels, ntohl(label));
4600 else if (unformat (i, "dst %U", unformat_ip4_address, &dst_address))
4602 else if (unformat (i, "del"))
4605 clib_warning ("parse error '%U'", format_unformat_error, i);
4610 if (vec_len (labels) == 0) {
4611 errmsg ("missing encap label stack\n");
4615 M2(MPLS_ADD_DEL_ENCAP, mpls_add_del_encap,
4616 sizeof (u32) * vec_len (labels));
4618 mp->vrf_id = ntohl(vrf_id);
4619 clib_memcpy(mp->dst_address, &dst_address, sizeof (dst_address));
4620 mp->is_add = is_add;
4621 mp->nlabels = vec_len (labels);
4622 clib_memcpy(mp->labels, labels, sizeof(u32)*mp->nlabels);
4631 static int api_mpls_gre_add_del_tunnel (vat_main_t * vam)
4633 unformat_input_t * i = vam->input;
4634 vl_api_mpls_gre_add_del_tunnel_t *mp;
4636 u32 inner_vrf_id = 0;
4637 u32 outer_vrf_id = 0;
4638 ip4_address_t src_address;
4639 ip4_address_t dst_address;
4640 ip4_address_t intfc_address;
4642 u8 intfc_address_length = 0;
4646 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
4647 if (unformat (i, "inner_vrf_id %d", &inner_vrf_id))
4649 else if (unformat (i, "outer_vrf_id %d", &outer_vrf_id))
4651 else if (unformat (i, "src %U", unformat_ip4_address, &src_address))
4653 else if (unformat (i, "dst %U", unformat_ip4_address, &dst_address))
4655 else if (unformat (i, "adj %U/%d", unformat_ip4_address,
4656 &intfc_address, &tmp))
4657 intfc_address_length = tmp;
4658 else if (unformat (i, "l2-only"))
4660 else if (unformat (i, "del"))
4663 clib_warning ("parse error '%U'", format_unformat_error, i);
4668 M(MPLS_GRE_ADD_DEL_TUNNEL, mpls_gre_add_del_tunnel);
4670 mp->inner_vrf_id = ntohl(inner_vrf_id);
4671 mp->outer_vrf_id = ntohl(outer_vrf_id);
4672 clib_memcpy(mp->src_address, &src_address, sizeof (src_address));
4673 clib_memcpy(mp->dst_address, &dst_address, sizeof (dst_address));
4674 clib_memcpy(mp->intfc_address, &intfc_address, sizeof (intfc_address));
4675 mp->intfc_address_length = intfc_address_length;
4676 mp->l2_only = l2_only;
4677 mp->is_add = is_add;
4684 static int api_mpls_ethernet_add_del_tunnel (vat_main_t * vam)
4686 unformat_input_t * i = vam->input;
4687 vl_api_mpls_ethernet_add_del_tunnel_t *mp;
4689 u32 inner_vrf_id = 0;
4690 ip4_address_t intfc_address;
4691 u8 dst_mac_address[6];
4694 u8 intfc_address_length = 0;
4698 int tx_sw_if_index_set = 0;
4700 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
4701 if (unformat (i, "vrf %d", &inner_vrf_id))
4703 else if (unformat (i, "adj %U/%d", unformat_ip4_address,
4704 &intfc_address, &tmp))
4705 intfc_address_length = tmp;
4706 else if (unformat (i, "%U",
4707 unformat_sw_if_index, vam, &tx_sw_if_index))
4708 tx_sw_if_index_set = 1;
4709 else if (unformat (i, "tx_sw_if_index %d", &tx_sw_if_index))
4710 tx_sw_if_index_set = 1;
4711 else if (unformat (i, "dst %U", unformat_ethernet_address,
4714 else if (unformat (i, "l2-only"))
4716 else if (unformat (i, "del"))
4719 clib_warning ("parse error '%U'", format_unformat_error, i);
4725 errmsg ("dst (mac address) not set\n");
4728 if (!tx_sw_if_index_set) {
4729 errmsg ("tx-intfc not set\n");
4733 M(MPLS_ETHERNET_ADD_DEL_TUNNEL, mpls_ethernet_add_del_tunnel);
4735 mp->vrf_id = ntohl(inner_vrf_id);
4736 clib_memcpy (mp->adj_address, &intfc_address, sizeof (intfc_address));
4737 mp->adj_address_length = intfc_address_length;
4738 clib_memcpy (mp->dst_mac_address, dst_mac_address, sizeof (dst_mac_address));
4739 mp->tx_sw_if_index = ntohl(tx_sw_if_index);
4740 mp->l2_only = l2_only;
4741 mp->is_add = is_add;
4748 static int api_mpls_ethernet_add_del_tunnel_2 (vat_main_t * vam)
4750 unformat_input_t * i = vam->input;
4751 vl_api_mpls_ethernet_add_del_tunnel_2_t *mp;
4753 u32 inner_vrf_id = 0;
4754 u32 outer_vrf_id = 0;
4755 ip4_address_t adj_address;
4756 int adj_address_set = 0;
4757 ip4_address_t next_hop_address;
4758 int next_hop_address_set = 0;
4760 u8 adj_address_length = 0;
4763 u32 resolve_attempts = 5;
4764 u8 resolve_if_needed = 1;
4766 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
4767 if (unformat (i, "inner_vrf_id %d", &inner_vrf_id))
4769 else if (unformat (i, "outer_vrf_id %d", &outer_vrf_id))
4771 else if (unformat (i, "adj %U/%d", unformat_ip4_address,
4772 &adj_address, &tmp)) {
4773 adj_address_length = tmp;
4774 adj_address_set = 1;
4776 else if (unformat (i, "next-hop %U", unformat_ip4_address,
4778 next_hop_address_set = 1;
4779 else if (unformat (i, "resolve-attempts %d", &resolve_attempts))
4781 else if (unformat (i, "resolve-if-needed %d", &tmp))
4782 resolve_if_needed = tmp;
4783 else if (unformat (i, "l2-only"))
4785 else if (unformat (i, "del"))
4788 clib_warning ("parse error '%U'", format_unformat_error, i);
4793 if (!adj_address_set) {
4794 errmsg ("adjacency address/mask not set\n");
4797 if (!next_hop_address_set) {
4798 errmsg ("ip4 next hop address (in outer fib) not set\n");
4802 M(MPLS_ETHERNET_ADD_DEL_TUNNEL_2, mpls_ethernet_add_del_tunnel_2);
4804 mp->inner_vrf_id = ntohl(inner_vrf_id);
4805 mp->outer_vrf_id = ntohl(outer_vrf_id);
4806 mp->resolve_attempts = ntohl(resolve_attempts);
4807 mp->resolve_if_needed = resolve_if_needed;
4808 mp->is_add = is_add;
4809 mp->l2_only = l2_only;
4810 clib_memcpy (mp->adj_address, &adj_address, sizeof (adj_address));
4811 mp->adj_address_length = adj_address_length;
4812 clib_memcpy (mp->next_hop_ip4_address_in_outer_vrf, &next_hop_address,
4813 sizeof (next_hop_address));
4820 static int api_sw_interface_set_unnumbered (vat_main_t * vam)
4822 unformat_input_t * i = vam->input;
4823 vl_api_sw_interface_set_unnumbered_t *mp;
4828 u8 sw_if_index_set = 0;
4830 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
4831 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
4832 sw_if_index_set = 1;
4833 else if (unformat (i, "sw_if_index %d", &sw_if_index))
4834 sw_if_index_set = 1;
4835 else if (unformat (i, "unnum_if_index %d", &unnum_sw_index))
4837 else if (unformat (i, "del"))
4840 clib_warning ("parse error '%U'", format_unformat_error, i);
4845 if (sw_if_index_set == 0) {
4846 errmsg ("missing interface name or sw_if_index\n");
4850 M(SW_INTERFACE_SET_UNNUMBERED, sw_interface_set_unnumbered);
4852 mp->sw_if_index = ntohl(sw_if_index);
4853 mp->unnumbered_sw_if_index = ntohl(unnum_sw_index);
4854 mp->is_add = is_add;
4861 static int api_ip_neighbor_add_del (vat_main_t * vam)
4863 unformat_input_t * i = vam->input;
4864 vl_api_ip_neighbor_add_del_t *mp;
4867 u8 sw_if_index_set = 0;
4873 u8 v4_address_set = 0;
4874 u8 v6_address_set = 0;
4875 ip4_address_t v4address;
4876 ip6_address_t v6address;
4878 memset (mac_address, 0, sizeof (mac_address));
4880 /* Parse args required to build the message */
4881 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
4882 if (unformat (i, "mac %U", unformat_ethernet_address, mac_address)) {
4885 else if (unformat (i, "del"))
4887 else if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
4888 sw_if_index_set = 1;
4889 else if (unformat (i, "sw_if_index %d", &sw_if_index))
4890 sw_if_index_set = 1;
4891 else if (unformat (i, "is_static"))
4893 else if (unformat (i, "vrf %d", &vrf_id))
4895 else if (unformat (i, "dst %U",
4896 unformat_ip4_address, &v4address))
4898 else if (unformat (i, "dst %U",
4899 unformat_ip6_address, &v6address))
4902 clib_warning ("parse error '%U'", format_unformat_error, i);
4907 if (sw_if_index_set == 0) {
4908 errmsg ("missing interface name or sw_if_index\n");
4911 if (v4_address_set && v6_address_set) {
4912 errmsg ("both v4 and v6 addresses set\n");
4915 if (!v4_address_set && !v6_address_set) {
4916 errmsg ("no addresses set\n");
4920 /* Construct the API message */
4921 M(IP_NEIGHBOR_ADD_DEL, ip_neighbor_add_del);
4923 mp->sw_if_index = ntohl (sw_if_index);
4924 mp->is_add = is_add;
4925 mp->vrf_id = ntohl (vrf_id);
4926 mp->is_static = is_static;
4928 clib_memcpy (mp->mac_address, mac_address, 6);
4929 if (v6_address_set) {
4931 clib_memcpy (mp->dst_address, &v6address, sizeof (v6address));
4933 /* mp->is_ipv6 = 0; via memset in M macro above */
4934 clib_memcpy (mp->dst_address, &v4address, sizeof (v4address));
4940 /* Wait for a reply, return good/bad news */
4947 static int api_reset_vrf (vat_main_t * vam)
4949 unformat_input_t * i = vam->input;
4950 vl_api_reset_vrf_t *mp;
4956 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
4957 if (unformat (i, "vrf %d", &vrf_id))
4959 else if (unformat (i, "ipv6"))
4962 clib_warning ("parse error '%U'", format_unformat_error, i);
4967 if (vrf_id_set == 0) {
4968 errmsg ("missing vrf id\n");
4972 M(RESET_VRF, reset_vrf);
4974 mp->vrf_id = ntohl(vrf_id);
4975 mp->is_ipv6 = is_ipv6;
4982 static int api_create_vlan_subif (vat_main_t * vam)
4984 unformat_input_t * i = vam->input;
4985 vl_api_create_vlan_subif_t *mp;
4988 u8 sw_if_index_set = 0;
4992 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
4993 if (unformat (i, "sw_if_index %d", &sw_if_index))
4994 sw_if_index_set = 1;
4995 else if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
4996 sw_if_index_set = 1;
4997 else if (unformat (i, "vlan %d", &vlan_id))
5000 clib_warning ("parse error '%U'", format_unformat_error, i);
5005 if (sw_if_index_set == 0) {
5006 errmsg ("missing interface name or sw_if_index\n");
5010 if (vlan_id_set == 0) {
5011 errmsg ("missing vlan_id\n");
5014 M(CREATE_VLAN_SUBIF, create_vlan_subif);
5016 mp->sw_if_index = ntohl(sw_if_index);
5017 mp->vlan_id = ntohl(vlan_id);
5024 #define foreach_create_subif_bit \
5031 _(outer_vlan_id_any) \
5032 _(inner_vlan_id_any)
5034 static int api_create_subif (vat_main_t * vam)
5036 unformat_input_t * i = vam->input;
5037 vl_api_create_subif_t *mp;
5040 u8 sw_if_index_set = 0;
5047 u32 exact_match = 0;
5048 u32 default_sub = 0;
5049 u32 outer_vlan_id_any = 0;
5050 u32 inner_vlan_id_any = 0;
5052 u16 outer_vlan_id = 0;
5053 u16 inner_vlan_id = 0;
5055 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
5056 if (unformat (i, "sw_if_index %d", &sw_if_index))
5057 sw_if_index_set = 1;
5058 else if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
5059 sw_if_index_set = 1;
5060 else if (unformat (i, "sub_id %d", &sub_id))
5062 else if (unformat (i, "outer_vlan_id %d", &tmp))
5063 outer_vlan_id = tmp;
5064 else if (unformat (i, "inner_vlan_id %d", &tmp))
5065 inner_vlan_id = tmp;
5067 #define _(a) else if (unformat (i, #a)) a = 1 ;
5068 foreach_create_subif_bit
5072 clib_warning ("parse error '%U'", format_unformat_error, i);
5077 if (sw_if_index_set == 0) {
5078 errmsg ("missing interface name or sw_if_index\n");
5082 if (sub_id_set == 0) {
5083 errmsg ("missing sub_id\n");
5086 M(CREATE_SUBIF, create_subif);
5088 mp->sw_if_index = ntohl(sw_if_index);
5089 mp->sub_id = ntohl(sub_id);
5091 #define _(a) mp->a = a;
5092 foreach_create_subif_bit;
5095 mp->outer_vlan_id = ntohs (outer_vlan_id);
5096 mp->inner_vlan_id = ntohs (inner_vlan_id);
5103 static int api_oam_add_del (vat_main_t * vam)
5105 unformat_input_t * i = vam->input;
5106 vl_api_oam_add_del_t *mp;
5110 ip4_address_t src, dst;
5114 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
5115 if (unformat (i, "vrf %d", &vrf_id))
5117 else if (unformat (i, "src %U", unformat_ip4_address, &src))
5119 else if (unformat (i, "dst %U", unformat_ip4_address, &dst))
5121 else if (unformat (i, "del"))
5124 clib_warning ("parse error '%U'", format_unformat_error, i);
5130 errmsg ("missing src addr\n");
5135 errmsg ("missing dst addr\n");
5139 M(OAM_ADD_DEL, oam_add_del);
5141 mp->vrf_id = ntohl(vrf_id);
5142 mp->is_add = is_add;
5143 clib_memcpy(mp->src_address, &src, sizeof (mp->src_address));
5144 clib_memcpy(mp->dst_address, &dst, sizeof (mp->dst_address));
5151 static int api_reset_fib (vat_main_t * vam)
5153 unformat_input_t * i = vam->input;
5154 vl_api_reset_fib_t *mp;
5160 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
5161 if (unformat (i, "vrf %d", &vrf_id))
5163 else if (unformat (i, "ipv6"))
5166 clib_warning ("parse error '%U'", format_unformat_error, i);
5171 if (vrf_id_set == 0) {
5172 errmsg ("missing vrf id\n");
5176 M(RESET_FIB, reset_fib);
5178 mp->vrf_id = ntohl(vrf_id);
5179 mp->is_ipv6 = is_ipv6;
5186 static int api_dhcp_proxy_config (vat_main_t * vam)
5188 unformat_input_t * i = vam->input;
5189 vl_api_dhcp_proxy_config_t *mp;
5194 u8 v4_address_set = 0;
5195 u8 v6_address_set = 0;
5196 ip4_address_t v4address;
5197 ip6_address_t v6address;
5198 u8 v4_src_address_set = 0;
5199 u8 v6_src_address_set = 0;
5200 ip4_address_t v4srcaddress;
5201 ip6_address_t v6srcaddress;
5203 /* Parse args required to build the message */
5204 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
5205 if (unformat (i, "del"))
5207 else if (unformat (i, "vrf %d", &vrf_id))
5209 else if (unformat (i, "insert-cid %d", &insert_cid))
5211 else if (unformat (i, "svr %U",
5212 unformat_ip4_address, &v4address))
5214 else if (unformat (i, "svr %U",
5215 unformat_ip6_address, &v6address))
5217 else if (unformat (i, "src %U",
5218 unformat_ip4_address, &v4srcaddress))
5219 v4_src_address_set = 1;
5220 else if (unformat (i, "src %U",
5221 unformat_ip6_address, &v6srcaddress))
5222 v6_src_address_set = 1;
5227 if (v4_address_set && v6_address_set) {
5228 errmsg ("both v4 and v6 server addresses set\n");
5231 if (!v4_address_set && !v6_address_set) {
5232 errmsg ("no server addresses set\n");
5236 if (v4_src_address_set && v6_src_address_set) {
5237 errmsg ("both v4 and v6 src addresses set\n");
5240 if (!v4_src_address_set && !v6_src_address_set) {
5241 errmsg ("no src addresses set\n");
5245 if (!(v4_src_address_set && v4_address_set) &&
5246 !(v6_src_address_set && v6_address_set)) {
5247 errmsg ("no matching server and src addresses set\n");
5251 /* Construct the API message */
5252 M(DHCP_PROXY_CONFIG, dhcp_proxy_config);
5254 mp->insert_circuit_id = insert_cid;
5255 mp->is_add = is_add;
5256 mp->vrf_id = ntohl (vrf_id);
5257 if (v6_address_set) {
5259 clib_memcpy (mp->dhcp_server, &v6address, sizeof (v6address));
5260 clib_memcpy (mp->dhcp_src_address, &v6srcaddress, sizeof (v6address));
5262 clib_memcpy (mp->dhcp_server, &v4address, sizeof (v4address));
5263 clib_memcpy (mp->dhcp_src_address, &v4srcaddress, sizeof (v4address));
5269 /* Wait for a reply, return good/bad news */
5275 static int api_dhcp_proxy_config_2 (vat_main_t * vam)
5277 unformat_input_t * i = vam->input;
5278 vl_api_dhcp_proxy_config_2_t *mp;
5281 u32 server_vrf_id = 0;
5284 u8 v4_address_set = 0;
5285 u8 v6_address_set = 0;
5286 ip4_address_t v4address;
5287 ip6_address_t v6address;
5288 u8 v4_src_address_set = 0;
5289 u8 v6_src_address_set = 0;
5290 ip4_address_t v4srcaddress;
5291 ip6_address_t v6srcaddress;
5293 /* Parse args required to build the message */
5294 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
5295 if (unformat (i, "del"))
5297 else if (unformat (i, "rx_vrf_id %d", &rx_vrf_id))
5299 else if (unformat (i, "server_vrf_id %d", &server_vrf_id))
5301 else if (unformat (i, "insert-cid %d", &insert_cid))
5303 else if (unformat (i, "svr %U",
5304 unformat_ip4_address, &v4address))
5306 else if (unformat (i, "svr %U",
5307 unformat_ip6_address, &v6address))
5309 else if (unformat (i, "src %U",
5310 unformat_ip4_address, &v4srcaddress))
5311 v4_src_address_set = 1;
5312 else if (unformat (i, "src %U",
5313 unformat_ip6_address, &v6srcaddress))
5314 v6_src_address_set = 1;
5319 if (v4_address_set && v6_address_set) {
5320 errmsg ("both v4 and v6 server addresses set\n");
5323 if (!v4_address_set && !v6_address_set) {
5324 errmsg ("no server addresses set\n");
5328 if (v4_src_address_set && v6_src_address_set) {
5329 errmsg ("both v4 and v6 src addresses set\n");
5332 if (!v4_src_address_set && !v6_src_address_set) {
5333 errmsg ("no src addresses set\n");
5337 if (!(v4_src_address_set && v4_address_set) &&
5338 !(v6_src_address_set && v6_address_set)) {
5339 errmsg ("no matching server and src addresses set\n");
5343 /* Construct the API message */
5344 M(DHCP_PROXY_CONFIG_2, dhcp_proxy_config_2);
5346 mp->insert_circuit_id = insert_cid;
5347 mp->is_add = is_add;
5348 mp->rx_vrf_id = ntohl (rx_vrf_id);
5349 mp->server_vrf_id = ntohl (server_vrf_id);
5350 if (v6_address_set) {
5352 clib_memcpy (mp->dhcp_server, &v6address, sizeof (v6address));
5353 clib_memcpy (mp->dhcp_src_address, &v6srcaddress, sizeof (v6address));
5355 clib_memcpy (mp->dhcp_server, &v4address, sizeof (v4address));
5356 clib_memcpy (mp->dhcp_src_address, &v4srcaddress, sizeof (v4address));
5362 /* Wait for a reply, return good/bad news */
5368 static int api_dhcp_proxy_set_vss (vat_main_t * vam)
5370 unformat_input_t * i = vam->input;
5371 vl_api_dhcp_proxy_set_vss_t *mp;
5382 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
5383 if (unformat (i, "tbl_id %d", &tbl_id))
5385 if (unformat (i, "fib_id %d", &fib_id))
5387 if (unformat (i, "oui %d", &oui))
5389 else if (unformat (i, "ipv6"))
5391 else if (unformat (i, "del"))
5394 clib_warning ("parse error '%U'", format_unformat_error, i);
5399 if (tbl_id_set == 0) {
5400 errmsg ("missing tbl id\n");
5404 if (fib_id_set == 0) {
5405 errmsg ("missing fib id\n");
5409 errmsg ("missing oui\n");
5413 M(DHCP_PROXY_SET_VSS, dhcp_proxy_set_vss);
5414 mp->tbl_id = ntohl(tbl_id);
5415 mp->fib_id = ntohl(fib_id);
5416 mp->oui = ntohl(oui);
5417 mp->is_ipv6 = is_ipv6;
5418 mp->is_add = is_add;
5425 static int api_dhcp_client_config (vat_main_t * vam)
5427 unformat_input_t * i = vam->input;
5428 vl_api_dhcp_client_config_t *mp;
5431 u8 sw_if_index_set = 0;
5434 u8 disable_event = 0;
5436 /* Parse args required to build the message */
5437 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
5438 if (unformat (i, "del"))
5440 else if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
5441 sw_if_index_set = 1;
5442 else if (unformat (i, "sw_if_index %d", &sw_if_index))
5443 sw_if_index_set = 1;
5444 else if (unformat (i, "hostname %s", &hostname))
5446 else if (unformat (i, "disable_event"))
5452 if (sw_if_index_set == 0) {
5453 errmsg ("missing interface name or sw_if_index\n");
5457 if (vec_len (hostname) > 63) {
5458 errmsg ("hostname too long\n");
5460 vec_add1 (hostname, 0);
5462 /* Construct the API message */
5463 M(DHCP_CLIENT_CONFIG, dhcp_client_config);
5465 mp->sw_if_index = ntohl (sw_if_index);
5466 clib_memcpy (mp->hostname, hostname, vec_len (hostname));
5467 vec_free (hostname);
5468 mp->is_add = is_add;
5469 mp->want_dhcp_event = disable_event ? 0 : 1;
5475 /* Wait for a reply, return good/bad news */
5481 static int api_set_ip_flow_hash (vat_main_t * vam)
5483 unformat_input_t * i = vam->input;
5484 vl_api_set_ip_flow_hash_t *mp;
5496 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
5497 if (unformat (i, "vrf %d", &vrf_id))
5499 else if (unformat (i, "ipv6"))
5501 else if (unformat (i, "src"))
5503 else if (unformat (i, "dst"))
5505 else if (unformat (i, "sport"))
5507 else if (unformat (i, "dport"))
5509 else if (unformat (i, "proto"))
5511 else if (unformat (i, "reverse"))
5515 clib_warning ("parse error '%U'", format_unformat_error, i);
5520 if (vrf_id_set == 0) {
5521 errmsg ("missing vrf id\n");
5525 M(SET_IP_FLOW_HASH, set_ip_flow_hash);
5531 mp->reverse = reverse;
5532 mp->vrf_id = ntohl(vrf_id);
5533 mp->is_ipv6 = is_ipv6;
5540 static int api_sw_interface_ip6_enable_disable (vat_main_t * vam)
5542 unformat_input_t * i = vam->input;
5543 vl_api_sw_interface_ip6_enable_disable_t *mp;
5546 u8 sw_if_index_set = 0;
5549 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
5550 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
5551 sw_if_index_set = 1;
5552 else if (unformat (i, "sw_if_index %d", &sw_if_index))
5553 sw_if_index_set = 1;
5554 else if (unformat (i, "enable"))
5556 else if (unformat (i, "disable"))
5559 clib_warning ("parse error '%U'", format_unformat_error, i);
5564 if (sw_if_index_set == 0) {
5565 errmsg ("missing interface name or sw_if_index\n");
5569 M(SW_INTERFACE_IP6_ENABLE_DISABLE, sw_interface_ip6_enable_disable);
5571 mp->sw_if_index = ntohl(sw_if_index);
5572 mp->enable = enable;
5579 static int api_sw_interface_ip6_set_link_local_address (vat_main_t * vam)
5581 unformat_input_t * i = vam->input;
5582 vl_api_sw_interface_ip6_set_link_local_address_t *mp;
5585 u8 sw_if_index_set = 0;
5586 u32 address_length = 0;
5587 u8 v6_address_set = 0;
5588 ip6_address_t v6address;
5590 /* Parse args required to build the message */
5591 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
5592 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
5593 sw_if_index_set = 1;
5594 else if (unformat (i, "sw_if_index %d", &sw_if_index))
5595 sw_if_index_set = 1;
5596 else if (unformat (i, "%U/%d",
5597 unformat_ip6_address, &v6address,
5604 if (sw_if_index_set == 0) {
5605 errmsg ("missing interface name or sw_if_index\n");
5608 if (!v6_address_set) {
5609 errmsg ("no address set\n");
5613 /* Construct the API message */
5614 M(SW_INTERFACE_IP6_SET_LINK_LOCAL_ADDRESS, \
5615 sw_interface_ip6_set_link_local_address);
5617 mp->sw_if_index = ntohl (sw_if_index);
5618 clib_memcpy (mp->address, &v6address, sizeof (v6address));
5619 mp->address_length = address_length;
5624 /* Wait for a reply, return good/bad news */
5632 static int api_sw_interface_ip6nd_ra_prefix (vat_main_t * vam)
5634 unformat_input_t * i = vam->input;
5635 vl_api_sw_interface_ip6nd_ra_prefix_t *mp;
5638 u8 sw_if_index_set = 0;
5639 u32 address_length = 0;
5640 u8 v6_address_set = 0;
5641 ip6_address_t v6address;
5643 u8 no_advertise = 0;
5645 u8 no_autoconfig = 0;
5648 u32 val_lifetime = 0;
5649 u32 pref_lifetime = 0;
5651 /* Parse args required to build the message */
5652 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
5653 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
5654 sw_if_index_set = 1;
5655 else if (unformat (i, "sw_if_index %d", &sw_if_index))
5656 sw_if_index_set = 1;
5657 else if (unformat (i, "%U/%d",
5658 unformat_ip6_address, &v6address,
5661 else if (unformat (i, "val_life %d", &val_lifetime))
5663 else if (unformat (i, "pref_life %d", &pref_lifetime))
5665 else if (unformat (i, "def"))
5667 else if (unformat (i, "noadv"))
5669 else if (unformat (i, "offl"))
5671 else if (unformat (i, "noauto"))
5673 else if (unformat (i, "nolink"))
5675 else if (unformat (i, "isno"))
5678 clib_warning ("parse error '%U'", format_unformat_error, i);
5683 if (sw_if_index_set == 0) {
5684 errmsg ("missing interface name or sw_if_index\n");
5687 if (!v6_address_set) {
5688 errmsg ("no address set\n");
5692 /* Construct the API message */
5693 M(SW_INTERFACE_IP6ND_RA_PREFIX, sw_interface_ip6nd_ra_prefix);
5695 mp->sw_if_index = ntohl (sw_if_index);
5696 clib_memcpy (mp->address, &v6address, sizeof (v6address));
5697 mp->address_length = address_length;
5698 mp->use_default = use_default;
5699 mp->no_advertise = no_advertise;
5700 mp->off_link = off_link;
5701 mp->no_autoconfig = no_autoconfig;
5702 mp->no_onlink = no_onlink;
5704 mp->val_lifetime = ntohl(val_lifetime);
5705 mp->pref_lifetime = ntohl(pref_lifetime);
5710 /* Wait for a reply, return good/bad news */
5717 static int api_sw_interface_ip6nd_ra_config (vat_main_t * vam)
5719 unformat_input_t * i = vam->input;
5720 vl_api_sw_interface_ip6nd_ra_config_t *mp;
5723 u8 sw_if_index_set = 0;
5728 u8 send_unicast = 0;
5731 u8 default_router = 0;
5732 u32 max_interval = 0;
5733 u32 min_interval = 0;
5735 u32 initial_count = 0;
5736 u32 initial_interval = 0;
5739 /* Parse args required to build the message */
5740 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
5741 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
5742 sw_if_index_set = 1;
5743 else if (unformat (i, "sw_if_index %d", &sw_if_index))
5744 sw_if_index_set = 1;
5745 else if (unformat (i, "maxint %d", &max_interval))
5747 else if (unformat (i, "minint %d", &min_interval))
5749 else if (unformat (i, "life %d", &lifetime))
5751 else if (unformat (i, "count %d", &initial_count))
5753 else if (unformat (i, "interval %d", &initial_interval))
5755 else if (unformat (i, "surpress"))
5757 else if (unformat (i, "managed"))
5759 else if (unformat (i, "other"))
5761 else if (unformat (i, "ll"))
5763 else if (unformat (i, "send"))
5765 else if (unformat (i, "cease"))
5767 else if (unformat (i, "isno"))
5769 else if (unformat (i, "def"))
5772 clib_warning ("parse error '%U'", format_unformat_error, i);
5777 if (sw_if_index_set == 0) {
5778 errmsg ("missing interface name or sw_if_index\n");
5782 /* Construct the API message */
5783 M(SW_INTERFACE_IP6ND_RA_CONFIG, sw_interface_ip6nd_ra_config);
5785 mp->sw_if_index = ntohl (sw_if_index);
5786 mp->max_interval = ntohl(max_interval);
5787 mp->min_interval = ntohl(min_interval);
5788 mp->lifetime = ntohl(lifetime);
5789 mp->initial_count = ntohl(initial_count);
5790 mp->initial_interval = ntohl(initial_interval);
5791 mp->surpress = surpress;
5792 mp->managed = managed;
5794 mp->ll_option = ll_option;
5795 mp->send_unicast = send_unicast;
5798 mp->default_router = default_router;
5803 /* Wait for a reply, return good/bad news */
5810 static int api_set_arp_neighbor_limit (vat_main_t * vam)
5812 unformat_input_t * i = vam->input;
5813 vl_api_set_arp_neighbor_limit_t *mp;
5819 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
5820 if (unformat (i, "arp_nbr_limit %d", &arp_nbr_limit))
5822 else if (unformat (i, "ipv6"))
5825 clib_warning ("parse error '%U'", format_unformat_error, i);
5830 if (limit_set == 0) {
5831 errmsg ("missing limit value\n");
5835 M(SET_ARP_NEIGHBOR_LIMIT, set_arp_neighbor_limit);
5837 mp->arp_neighbor_limit = ntohl(arp_nbr_limit);
5838 mp->is_ipv6 = is_ipv6;
5845 static int api_l2_patch_add_del (vat_main_t * vam)
5847 unformat_input_t * i = vam->input;
5848 vl_api_l2_patch_add_del_t *mp;
5851 u8 rx_sw_if_index_set = 0;
5853 u8 tx_sw_if_index_set = 0;
5856 /* Parse args required to build the message */
5857 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
5858 if (unformat (i, "rx_sw_if_index %d", &rx_sw_if_index))
5859 rx_sw_if_index_set = 1;
5860 else if (unformat (i, "tx_sw_if_index %d", &tx_sw_if_index))
5861 tx_sw_if_index_set = 1;
5862 else if (unformat (i, "rx")) {
5863 if (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
5864 if (unformat (i, "%U", unformat_sw_if_index, vam,
5866 rx_sw_if_index_set = 1;
5869 } else if (unformat (i, "tx")) {
5870 if (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
5871 if (unformat (i, "%U", unformat_sw_if_index, vam,
5873 tx_sw_if_index_set = 1;
5876 } else if (unformat (i, "del"))
5882 if (rx_sw_if_index_set == 0) {
5883 errmsg ("missing rx interface name or rx_sw_if_index\n");
5887 if (tx_sw_if_index_set == 0) {
5888 errmsg ("missing tx interface name or tx_sw_if_index\n");
5892 M(L2_PATCH_ADD_DEL, l2_patch_add_del);
5894 mp->rx_sw_if_index = ntohl(rx_sw_if_index);
5895 mp->tx_sw_if_index = ntohl(tx_sw_if_index);
5896 mp->is_add = is_add;
5902 static int api_trace_profile_add (vat_main_t *vam)
5904 unformat_input_t * input = vam->input;
5905 vl_api_trace_profile_add_t *mp;
5908 u32 trace_option_elts = 0;
5909 u32 trace_type = 0, node_id = 0, app_data = 0, trace_tsp = 2;
5910 int has_pow_option = 0;
5911 int has_ppc_option = 0;
5913 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
5915 if (unformat (input, "id %d trace-type 0x%x trace-elts %d "
5916 "trace-tsp %d node-id 0x%x app-data 0x%x",
5917 &id, &trace_type, &trace_option_elts, &trace_tsp,
5918 &node_id, &app_data))
5920 else if (unformat (input, "pow"))
5922 else if (unformat (input, "ppc encap"))
5923 has_ppc_option = PPC_ENCAP;
5924 else if (unformat (input, "ppc decap"))
5925 has_ppc_option = PPC_DECAP;
5926 else if (unformat (input, "ppc none"))
5927 has_ppc_option = PPC_NONE;
5931 M(TRACE_PROFILE_ADD, trace_profile_add);
5933 mp->trace_type = trace_type;
5934 mp->trace_num_elt = trace_option_elts;
5935 mp->trace_ppc = has_ppc_option;
5936 mp->trace_app_data = htonl(app_data);
5937 mp->pow_enable = has_pow_option;
5938 mp->trace_tsp = trace_tsp;
5939 mp->node_id = htonl(node_id);
5946 static int api_trace_profile_apply (vat_main_t *vam)
5948 unformat_input_t * input = vam->input;
5949 vl_api_trace_profile_apply_t *mp;
5952 u32 mask_width = ~0;
5959 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
5961 if (unformat (input, "%U/%d",
5962 unformat_ip6_address, &addr, &mask_width))
5964 else if (unformat (input, "id %d", &id))
5966 else if (unformat (input, "vrf-id %d", &vrf_id))
5968 else if (unformat (input, "add"))
5970 else if (unformat (input, "pop"))
5972 else if (unformat (input, "none"))
5978 if ((is_add + is_pop + is_none) != 1) {
5979 errmsg("One of (add, pop, none) required");
5982 if (mask_width == ~0) {
5983 errmsg("<address>/<mask-width> required");
5986 M(TRACE_PROFILE_APPLY, trace_profile_apply);
5987 clib_memcpy(mp->dest_ipv6, &addr, sizeof(mp->dest_ipv6));
5989 mp->prefix_length = htonl(mask_width);
5990 mp->vrf_id = htonl(vrf_id);
5992 mp->trace_op = IOAM_HBYH_ADD;
5994 mp->trace_op = IOAM_HBYH_POP;
5996 mp->trace_op = IOAM_HBYH_MOD;
6008 static int api_trace_profile_del (vat_main_t *vam)
6010 vl_api_trace_profile_del_t *mp;
6013 M(TRACE_PROFILE_DEL, trace_profile_del);
6018 static int api_sr_tunnel_add_del (vat_main_t * vam)
6020 unformat_input_t * i = vam->input;
6021 vl_api_sr_tunnel_add_del_t *mp;
6025 ip6_address_t src_address;
6026 int src_address_set = 0;
6027 ip6_address_t dst_address;
6029 int dst_address_set = 0;
6031 u32 rx_table_id = 0;
6032 u32 tx_table_id = 0;
6033 ip6_address_t * segments = 0;
6034 ip6_address_t * this_seg;
6035 ip6_address_t * tags = 0;
6036 ip6_address_t * this_tag;
6037 ip6_address_t next_address, tag;
6039 u8 * policy_name = 0;
6041 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
6043 if (unformat (i, "del"))
6045 else if (unformat (i, "name %s", &name))
6047 else if (unformat (i, "policy %s", &policy_name))
6049 else if (unformat (i, "rx_fib_id %d", &rx_table_id))
6051 else if (unformat (i, "tx_fib_id %d", &tx_table_id))
6053 else if (unformat (i, "src %U", unformat_ip6_address, &src_address))
6054 src_address_set = 1;
6055 else if (unformat (i, "dst %U/%d",
6056 unformat_ip6_address, &dst_address,
6058 dst_address_set = 1;
6059 else if (unformat (i, "next %U", unformat_ip6_address,
6062 vec_add2 (segments, this_seg, 1);
6063 clib_memcpy (this_seg->as_u8, next_address.as_u8, sizeof (*this_seg));
6065 else if (unformat (i, "tag %U", unformat_ip6_address,
6068 vec_add2 (tags, this_tag, 1);
6069 clib_memcpy (this_tag->as_u8, tag.as_u8, sizeof (*this_tag));
6071 else if (unformat (i, "clean"))
6072 flags |= IP6_SR_HEADER_FLAG_CLEANUP;
6073 else if (unformat (i, "protected"))
6074 flags |= IP6_SR_HEADER_FLAG_PROTECTED;
6075 else if (unformat (i, "InPE %d", &pl_index))
6077 if (pl_index <= 0 || pl_index > 4)
6079 pl_index_range_error:
6080 errmsg ("pl index %d out of range\n", pl_index);
6083 flags |= IP6_SR_HEADER_FLAG_PL_ELT_INGRESS_PE << (3*(pl_index - 1));
6085 else if (unformat (i, "EgPE %d", &pl_index))
6087 if (pl_index <= 0 || pl_index > 4)
6088 goto pl_index_range_error;
6089 flags |= IP6_SR_HEADER_FLAG_PL_ELT_EGRESS_PE << (3*(pl_index - 1));
6091 else if (unformat (i, "OrgSrc %d", &pl_index))
6093 if (pl_index <= 0 || pl_index > 4)
6094 goto pl_index_range_error;
6095 flags |= IP6_SR_HEADER_FLAG_PL_ELT_ORIG_SRC_ADDR << (3*(pl_index - 1));
6101 if (!src_address_set)
6103 errmsg ("src address required\n");
6107 if (!dst_address_set)
6109 errmsg ("dst address required\n");
6115 errmsg ("at least one sr segment required\n");
6119 M2(SR_TUNNEL_ADD_DEL, sr_tunnel_add_del,
6120 vec_len(segments) * sizeof (ip6_address_t)
6121 + vec_len(tags) * sizeof (ip6_address_t));
6123 clib_memcpy (mp->src_address, &src_address, sizeof (mp->src_address));
6124 clib_memcpy (mp->dst_address, &dst_address, sizeof (mp->dst_address));
6125 mp->dst_mask_width = dst_mask_width;
6126 mp->flags_net_byte_order = clib_host_to_net_u16 (flags);
6127 mp->n_segments = vec_len (segments);
6128 mp->n_tags = vec_len (tags);
6129 mp->is_add = is_del == 0;
6130 clib_memcpy (mp->segs_and_tags, segments,
6131 vec_len(segments)* sizeof (ip6_address_t));
6132 clib_memcpy (mp->segs_and_tags + vec_len(segments)*sizeof (ip6_address_t),
6133 tags, vec_len(tags)* sizeof (ip6_address_t));
6135 mp->outer_vrf_id = ntohl (rx_table_id);
6136 mp->inner_vrf_id = ntohl (tx_table_id);
6137 memcpy (mp->name, name, vec_len(name));
6138 memcpy (mp->policy_name, policy_name, vec_len(policy_name));
6140 vec_free (segments);
6147 static int api_sr_policy_add_del (vat_main_t * vam)
6149 unformat_input_t * input = vam->input;
6150 vl_api_sr_policy_add_del_t *mp;
6154 u8 * tunnel_name = 0;
6155 u8 ** tunnel_names = 0;
6160 int tunnel_names_length = 1; // Init to 1 to offset the #tunnel_names counter byte
6161 int tun_name_len = 0; // Different naming convention used as confusing these would be "bad" (TM)
6163 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
6165 if (unformat (input, "del"))
6167 else if (unformat (input, "name %s", &name))
6169 else if (unformat (input, "tunnel %s", &tunnel_name))
6173 vec_add1 (tunnel_names, tunnel_name);
6175 - length = #bytes to store in serial vector
6176 - +1 = byte to store that length
6178 tunnel_names_length += (vec_len (tunnel_name) + 1);
6189 errmsg ("policy name required\n");
6193 if ((!tunnel_set) && (!is_del))
6195 errmsg ("tunnel name required\n");
6199 M2(SR_POLICY_ADD_DEL, sr_policy_add_del, tunnel_names_length);
6203 mp->is_add = !is_del;
6205 memcpy (mp->name, name, vec_len(name));
6206 // Since mp->tunnel_names is of type u8[0] and not a u8 *, u8 ** needs to be serialized
6207 u8 * serial_orig = 0;
6208 vec_validate (serial_orig, tunnel_names_length);
6209 *serial_orig = vec_len(tunnel_names); // Store the number of tunnels as length in first byte of serialized vector
6210 serial_orig += 1; // Move along one byte to store the length of first tunnel_name
6212 for (j=0; j < vec_len(tunnel_names); j++)
6214 tun_name_len = vec_len (tunnel_names[j]);
6215 *serial_orig = tun_name_len; // Store length of tunnel name in first byte of Length/Value pair
6216 serial_orig += 1; // Move along one byte to store the actual tunnel name
6217 memcpy (serial_orig, tunnel_names[j], tun_name_len);
6218 serial_orig += tun_name_len; // Advance past the copy
6220 memcpy (mp->tunnel_names, serial_orig - tunnel_names_length, tunnel_names_length); // Regress serial_orig to head then copy fwd
6222 vec_free (tunnel_names);
6223 vec_free (tunnel_name);
6229 static int api_sr_multicast_map_add_del (vat_main_t * vam)
6231 unformat_input_t * input = vam->input;
6232 vl_api_sr_multicast_map_add_del_t *mp;
6235 ip6_address_t multicast_address;
6236 u8 * policy_name = 0;
6237 int multicast_address_set = 0;
6239 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
6241 if (unformat (input, "del"))
6243 else if (unformat (input, "address %U", unformat_ip6_address, &multicast_address))
6244 multicast_address_set = 1;
6245 else if (unformat (input, "sr-policy %s", &policy_name))
6251 if (!is_del && !policy_name)
6253 errmsg ("sr-policy name required\n");
6258 if (!multicast_address_set)
6260 errmsg ("address required\n");
6264 M(SR_MULTICAST_MAP_ADD_DEL, sr_multicast_map_add_del);
6266 mp->is_add = !is_del;
6267 memcpy (mp->policy_name, policy_name, vec_len(policy_name));
6268 clib_memcpy (mp->multicast_address, &multicast_address, sizeof (mp->multicast_address));
6271 vec_free (policy_name);
6278 #define foreach_ip4_proto_field \
6288 uword unformat_ip4_mask (unformat_input_t * input, va_list * args)
6290 u8 ** maskp = va_arg (*args, u8 **);
6292 u8 found_something = 0;
6295 #define _(a) u8 a=0;
6296 foreach_ip4_proto_field;
6302 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
6304 if (unformat (input, "version"))
6306 else if (unformat (input, "hdr_length"))
6308 else if (unformat (input, "src"))
6310 else if (unformat (input, "dst"))
6312 else if (unformat (input, "proto"))
6315 #define _(a) else if (unformat (input, #a)) a=1;
6316 foreach_ip4_proto_field
6322 #define _(a) found_something += a;
6323 foreach_ip4_proto_field;
6326 if (found_something == 0)
6329 vec_validate (mask, sizeof (*ip) - 1);
6331 ip = (ip4_header_t *) mask;
6333 #define _(a) if (a) memset (&ip->a, 0xff, sizeof (ip->a));
6334 foreach_ip4_proto_field;
6337 ip->ip_version_and_header_length = 0;
6340 ip->ip_version_and_header_length |= 0xF0;
6343 ip->ip_version_and_header_length |= 0x0F;
6349 #define foreach_ip6_proto_field \
6356 uword unformat_ip6_mask (unformat_input_t * input, va_list * args)
6358 u8 ** maskp = va_arg (*args, u8 **);
6360 u8 found_something = 0;
6362 u32 ip_version_traffic_class_and_flow_label;
6364 #define _(a) u8 a=0;
6365 foreach_ip6_proto_field;
6368 u8 traffic_class = 0;
6371 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
6373 if (unformat (input, "version"))
6375 else if (unformat (input, "traffic-class"))
6377 else if (unformat (input, "flow-label"))
6379 else if (unformat (input, "src"))
6381 else if (unformat (input, "dst"))
6383 else if (unformat (input, "proto"))
6386 #define _(a) else if (unformat (input, #a)) a=1;
6387 foreach_ip6_proto_field
6393 #define _(a) found_something += a;
6394 foreach_ip6_proto_field;
6397 if (found_something == 0)
6400 vec_validate (mask, sizeof (*ip) - 1);
6402 ip = (ip6_header_t *) mask;
6404 #define _(a) if (a) memset (&ip->a, 0xff, sizeof (ip->a));
6405 foreach_ip6_proto_field;
6408 ip_version_traffic_class_and_flow_label = 0;
6411 ip_version_traffic_class_and_flow_label |= 0xF0000000;
6414 ip_version_traffic_class_and_flow_label |= 0x0FF00000;
6417 ip_version_traffic_class_and_flow_label |= 0x000FFFFF;
6419 ip->ip_version_traffic_class_and_flow_label =
6420 clib_host_to_net_u32 (ip_version_traffic_class_and_flow_label);
6426 uword unformat_l3_mask (unformat_input_t * input, va_list * args)
6428 u8 ** maskp = va_arg (*args, u8 **);
6430 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) {
6431 if (unformat (input, "ip4 %U", unformat_ip4_mask, maskp))
6433 else if (unformat (input, "ip6 %U", unformat_ip6_mask, maskp))
6441 uword unformat_l2_mask (unformat_input_t * input, va_list * args)
6443 u8 ** maskp = va_arg (*args, u8 **);
6458 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) {
6459 if (unformat (input, "src"))
6461 else if (unformat (input, "dst"))
6463 else if (unformat (input, "proto"))
6465 else if (unformat (input, "tag1"))
6467 else if (unformat (input, "tag2"))
6469 else if (unformat (input, "ignore-tag1"))
6471 else if (unformat (input, "ignore-tag2"))
6473 else if (unformat (input, "cos1"))
6475 else if (unformat (input, "cos2"))
6477 else if (unformat (input, "dot1q"))
6479 else if (unformat (input, "dot1ad"))
6484 if ((src + dst + proto + tag1 + tag2 + dot1q + dot1ad +
6485 ignore_tag1 + ignore_tag2 + cos1 + cos2) == 0)
6488 if (tag1 || ignore_tag1 || cos1 || dot1q)
6490 if (tag2 || ignore_tag2 || cos2 || dot1ad)
6493 vec_validate (mask, len-1);
6496 memset (mask, 0xff, 6);
6499 memset (mask + 6, 0xff, 6);
6503 /* inner vlan tag */
6512 mask[21] = mask [20] = 0xff;
6533 mask[16] = mask [17] = 0xff;
6543 mask[12] = mask [13] = 0xff;
6549 uword unformat_classify_mask (unformat_input_t * input, va_list * args)
6551 u8 ** maskp = va_arg (*args, u8 **);
6552 u32 * skipp = va_arg (*args, u32 *);
6553 u32 * matchp = va_arg (*args, u32 *);
6560 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) {
6561 if (unformat (input, "hex %U", unformat_hex_string, &mask))
6563 else if (unformat (input, "l2 %U", unformat_l2_mask, &l2))
6565 else if (unformat (input, "l3 %U", unformat_l3_mask, &l3))
6571 if (mask || l2 || l3)
6575 /* "With a free Ethernet header in every package" */
6577 vec_validate (l2, 13);
6579 vec_append (mask, l3);
6583 /* Scan forward looking for the first significant mask octet */
6584 for (i = 0; i < vec_len (mask); i++)
6588 /* compute (skip, match) params */
6589 *skipp = i / sizeof(u32x4);
6590 vec_delete (mask, *skipp * sizeof(u32x4), 0);
6592 /* Pad mask to an even multiple of the vector size */
6593 while (vec_len (mask) % sizeof (u32x4))
6596 match = vec_len (mask) / sizeof (u32x4);
6598 for (i = match*sizeof(u32x4); i > 0; i-= sizeof(u32x4))
6600 u64 *tmp = (u64 *)(mask + (i-sizeof(u32x4)));
6601 if (*tmp || *(tmp+1))
6606 clib_warning ("BUG: match 0");
6608 _vec_len (mask) = match * sizeof(u32x4);
6619 #define foreach_l2_next \
6621 _(ethernet, ETHERNET_INPUT) \
6625 uword unformat_l2_next_index (unformat_input_t * input, va_list * args)
6627 u32 * miss_next_indexp = va_arg (*args, u32 *);
6632 if (unformat (input, #n)) { next_index = L2_CLASSIFY_NEXT_##N; goto out;}
6636 if (unformat (input, "%d", &tmp))
6645 *miss_next_indexp = next_index;
6649 #define foreach_ip_next \
6655 uword unformat_ip_next_index (unformat_input_t * input, va_list * args)
6657 u32 * miss_next_indexp = va_arg (*args, u32 *);
6662 if (unformat (input, #n)) { next_index = IP_LOOKUP_NEXT_##N; goto out;}
6666 if (unformat (input, "%d", &tmp))
6675 *miss_next_indexp = next_index;
6679 #define foreach_acl_next \
6682 uword unformat_acl_next_index (unformat_input_t * input, va_list * args)
6684 u32 * miss_next_indexp = va_arg (*args, u32 *);
6689 if (unformat (input, #n)) { next_index = ACL_NEXT_INDEX_##N; goto out;}
6693 if (unformat (input, "permit"))
6698 else if (unformat (input, "%d", &tmp))
6707 *miss_next_indexp = next_index;
6711 static int api_classify_add_del_table (vat_main_t * vam)
6713 unformat_input_t * i = vam->input;
6714 vl_api_classify_add_del_table_t *mp;
6720 u32 table_index = ~0;
6721 u32 next_table_index = ~0;
6722 u32 miss_next_index = ~0;
6723 u32 memory_size = 32<<20;
6727 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
6728 if (unformat (i, "del"))
6730 else if (unformat (i, "buckets %d", &nbuckets))
6732 else if (unformat (i, "memory_size %d", &memory_size))
6734 else if (unformat (i, "skip %d", &skip))
6736 else if (unformat (i, "match %d", &match))
6738 else if (unformat (i, "table %d", &table_index))
6740 else if (unformat (i, "mask %U", unformat_classify_mask,
6741 &mask, &skip, &match))
6743 else if (unformat (i, "next-table %d", &next_table_index))
6745 else if (unformat (i, "miss-next %U", unformat_ip_next_index,
6748 else if (unformat (i, "l2-miss-next %U", unformat_l2_next_index,
6751 else if (unformat (i, "acl-miss-next %U", unformat_acl_next_index,
6758 if (is_add && mask == 0) {
6759 errmsg ("Mask required\n");
6763 if (is_add && skip == ~0) {
6764 errmsg ("skip count required\n");
6768 if (is_add && match == ~0) {
6769 errmsg ("match count required\n");
6773 if (!is_add && table_index == ~0) {
6774 errmsg ("table index required for delete\n");
6778 M2 (CLASSIFY_ADD_DEL_TABLE, classify_add_del_table,
6781 mp->is_add = is_add;
6782 mp->table_index = ntohl(table_index);
6783 mp->nbuckets = ntohl(nbuckets);
6784 mp->memory_size = ntohl(memory_size);
6785 mp->skip_n_vectors = ntohl(skip);
6786 mp->match_n_vectors = ntohl(match);
6787 mp->next_table_index = ntohl(next_table_index);
6788 mp->miss_next_index = ntohl(miss_next_index);
6789 clib_memcpy (mp->mask, mask, vec_len(mask));
6797 uword unformat_ip4_match (unformat_input_t * input, va_list * args)
6799 u8 ** matchp = va_arg (*args, u8 **);
6806 int src = 0, dst = 0;
6807 ip4_address_t src_val, dst_val;
6814 int fragment_id = 0;
6815 u32 fragment_id_val;
6821 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
6823 if (unformat (input, "version %d", &version_val))
6825 else if (unformat (input, "hdr_length %d", &hdr_length_val))
6827 else if (unformat (input, "src %U", unformat_ip4_address, &src_val))
6829 else if (unformat (input, "dst %U", unformat_ip4_address, &dst_val))
6831 else if (unformat (input, "proto %d", &proto_val))
6833 else if (unformat (input, "tos %d", &tos_val))
6835 else if (unformat (input, "length %d", &length_val))
6837 else if (unformat (input, "fragment_id %d", &fragment_id_val))
6839 else if (unformat (input, "ttl %d", &ttl_val))
6841 else if (unformat (input, "checksum %d", &checksum_val))
6847 if (version + hdr_length + src + dst + proto + tos + length + fragment_id
6848 + ttl + checksum == 0)
6852 * Aligned because we use the real comparison functions
6854 vec_validate_aligned (match, sizeof (*ip) - 1, sizeof(u32x4));
6856 ip = (ip4_header_t *) match;
6858 /* These are realistically matched in practice */
6860 ip->src_address.as_u32 = src_val.as_u32;
6863 ip->dst_address.as_u32 = dst_val.as_u32;
6866 ip->protocol = proto_val;
6869 /* These are not, but they're included for completeness */
6871 ip->ip_version_and_header_length |= (version_val & 0xF)<<4;
6874 ip->ip_version_and_header_length |= (hdr_length_val & 0xF);
6880 ip->length = length_val;
6886 ip->checksum = checksum_val;
6892 uword unformat_ip6_match (unformat_input_t * input, va_list * args)
6894 u8 ** matchp = va_arg (*args, u8 **);
6900 u32 traffic_class_val;
6903 int src = 0, dst = 0;
6904 ip6_address_t src_val, dst_val;
6907 int payload_length = 0;
6908 u32 payload_length_val;
6911 u32 ip_version_traffic_class_and_flow_label;
6913 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
6915 if (unformat (input, "version %d", &version_val))
6917 else if (unformat (input, "traffic_class %d", &traffic_class_val))
6919 else if (unformat (input, "flow_label %d", &flow_label_val))
6921 else if (unformat (input, "src %U", unformat_ip6_address, &src_val))
6923 else if (unformat (input, "dst %U", unformat_ip6_address, &dst_val))
6925 else if (unformat (input, "proto %d", &proto_val))
6927 else if (unformat (input, "payload_length %d", &payload_length_val))
6929 else if (unformat (input, "hop_limit %d", &hop_limit_val))
6935 if (version + traffic_class + flow_label + src + dst + proto +
6936 payload_length + hop_limit == 0)
6940 * Aligned because we use the real comparison functions
6942 vec_validate_aligned (match, sizeof (*ip) - 1, sizeof(u32x4));
6944 ip = (ip6_header_t *) match;
6947 clib_memcpy (&ip->src_address, &src_val, sizeof (ip->src_address));
6950 clib_memcpy (&ip->dst_address, &dst_val, sizeof (ip->dst_address));
6953 ip->protocol = proto_val;
6955 ip_version_traffic_class_and_flow_label = 0;
6958 ip_version_traffic_class_and_flow_label |= (version_val & 0xF) << 28;
6961 ip_version_traffic_class_and_flow_label |= (traffic_class_val & 0xFF) << 20;
6964 ip_version_traffic_class_and_flow_label |= (flow_label_val & 0xFFFFF);
6966 ip->ip_version_traffic_class_and_flow_label =
6967 clib_host_to_net_u32 (ip_version_traffic_class_and_flow_label);
6970 ip->payload_length = clib_host_to_net_u16 (payload_length_val);
6973 ip->hop_limit = hop_limit_val;
6979 uword unformat_l3_match (unformat_input_t * input, va_list * args)
6981 u8 ** matchp = va_arg (*args, u8 **);
6983 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) {
6984 if (unformat (input, "ip4 %U", unformat_ip4_match, matchp))
6986 else if (unformat (input, "ip6 %U", unformat_ip6_match, matchp))
6994 uword unformat_vlan_tag (unformat_input_t * input, va_list * args)
6996 u8 * tagp = va_arg (*args, u8 *);
6999 if (unformat(input, "%d", &tag))
7001 tagp[0] = (tag>>8) & 0x0F;
7002 tagp[1] = tag & 0xFF;
7009 uword unformat_l2_match (unformat_input_t * input, va_list * args)
7011 u8 ** matchp = va_arg (*args, u8 **);
7031 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) {
7032 if (unformat (input, "src %U", unformat_ethernet_address, &src_val))
7034 else if (unformat (input, "dst %U", unformat_ethernet_address, &dst_val))
7036 else if (unformat (input, "proto %U",
7037 unformat_ethernet_type_host_byte_order, &proto_val))
7039 else if (unformat (input, "tag1 %U", unformat_vlan_tag, tag1_val))
7041 else if (unformat (input, "tag2 %U", unformat_vlan_tag, tag2_val))
7043 else if (unformat (input, "ignore-tag1"))
7045 else if (unformat (input, "ignore-tag2"))
7047 else if (unformat (input, "cos1 %d", &cos1_val))
7049 else if (unformat (input, "cos2 %d", &cos2_val))
7054 if ((src + dst + proto + tag1 + tag2 +
7055 ignore_tag1 + ignore_tag2 + cos1 + cos2) == 0)
7058 if (tag1 || ignore_tag1 || cos1)
7060 if (tag2 || ignore_tag2 || cos2)
7063 vec_validate_aligned (match, len-1, sizeof(u32x4));
7066 clib_memcpy (match, dst_val, 6);
7069 clib_memcpy (match + 6, src_val, 6);
7073 /* inner vlan tag */
7074 match[19] = tag2_val[1];
7075 match[18] = tag2_val[0];
7077 match [18] |= (cos2_val & 0x7) << 5;
7080 match[21] = proto_val & 0xff;
7081 match[20] = proto_val >> 8;
7085 match [15] = tag1_val[1];
7086 match [14] = tag1_val[0];
7089 match [14] |= (cos1_val & 0x7) << 5;
7095 match [15] = tag1_val[1];
7096 match [14] = tag1_val[0];
7099 match[17] = proto_val & 0xff;
7100 match[16] = proto_val >> 8;
7103 match [14] |= (cos1_val & 0x7) << 5;
7109 match [18] |= (cos2_val & 0x7) << 5;
7111 match [14] |= (cos1_val & 0x7) << 5;
7114 match[13] = proto_val & 0xff;
7115 match[12] = proto_val >> 8;
7123 uword unformat_classify_match (unformat_input_t * input, va_list * args)
7125 u8 ** matchp = va_arg (*args, u8 **);
7126 u32 skip_n_vectors = va_arg (*args, u32);
7127 u32 match_n_vectors = va_arg (*args, u32);
7133 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) {
7134 if (unformat (input, "hex %U", unformat_hex_string, &match))
7136 else if (unformat (input, "l2 %U", unformat_l2_match, &l2))
7138 else if (unformat (input, "l3 %U", unformat_l3_match, &l3))
7144 if (match || l2 || l3)
7148 /* "Win a free Ethernet header in every packet" */
7150 vec_validate_aligned (l2, 13, sizeof(u32x4));
7152 vec_append_aligned (match, l3, sizeof(u32x4));
7156 /* Make sure the vector is big enough even if key is all 0's */
7157 vec_validate_aligned
7158 (match, ((match_n_vectors + skip_n_vectors) * sizeof(u32x4)) - 1,
7161 /* Set size, include skipped vectors*/
7162 _vec_len (match) = (match_n_vectors+skip_n_vectors) * sizeof(u32x4);
7172 static int api_classify_add_del_session (vat_main_t * vam)
7174 unformat_input_t * i = vam->input;
7175 vl_api_classify_add_del_session_t *mp;
7177 u32 table_index = ~0;
7178 u32 hit_next_index = ~0;
7179 u32 opaque_index = ~0;
7183 u32 skip_n_vectors = 0;
7184 u32 match_n_vectors = 0;
7187 * Warning: you have to supply skip_n and match_n
7188 * because the API client cant simply look at the classify
7192 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
7193 if (unformat (i, "del"))
7195 else if (unformat (i, "hit-next %U", unformat_ip_next_index,
7198 else if (unformat (i, "l2-hit-next %U", unformat_l2_next_index,
7201 else if (unformat (i, "acl-hit-next %U", unformat_acl_next_index,
7204 else if (unformat (i, "opaque-index %d", &opaque_index))
7206 else if (unformat (i, "skip_n %d", &skip_n_vectors))
7208 else if (unformat (i, "match_n %d", &match_n_vectors))
7210 else if (unformat (i, "match %U", unformat_classify_match,
7211 &match, skip_n_vectors, match_n_vectors))
7213 else if (unformat (i, "advance %d", &advance))
7215 else if (unformat (i, "table-index %d", &table_index))
7221 if (table_index == ~0) {
7222 errmsg ("Table index required\n");
7226 if (is_add && match == 0) {
7227 errmsg ("Match value required\n");
7231 M2 (CLASSIFY_ADD_DEL_SESSION, classify_add_del_session,
7234 mp->is_add = is_add;
7235 mp->table_index = ntohl(table_index);
7236 mp->hit_next_index = ntohl(hit_next_index);
7237 mp->opaque_index = ntohl(opaque_index);
7238 mp->advance = ntohl(advance);
7239 clib_memcpy (mp->match, match, vec_len(match));
7246 static int api_classify_set_interface_ip_table (vat_main_t * vam)
7248 unformat_input_t * i = vam->input;
7249 vl_api_classify_set_interface_ip_table_t *mp;
7252 int sw_if_index_set;
7253 u32 table_index = ~0;
7256 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
7257 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
7258 sw_if_index_set = 1;
7259 else if (unformat (i, "sw_if_index %d", &sw_if_index))
7260 sw_if_index_set = 1;
7261 else if (unformat (i, "table %d", &table_index))
7264 clib_warning ("parse error '%U'", format_unformat_error, i);
7269 if (sw_if_index_set == 0) {
7270 errmsg ("missing interface name or sw_if_index\n");
7275 M(CLASSIFY_SET_INTERFACE_IP_TABLE, classify_set_interface_ip_table);
7277 mp->sw_if_index = ntohl(sw_if_index);
7278 mp->table_index = ntohl(table_index);
7279 mp->is_ipv6 = is_ipv6;
7286 static int api_classify_set_interface_l2_tables (vat_main_t * vam)
7288 unformat_input_t * i = vam->input;
7289 vl_api_classify_set_interface_l2_tables_t *mp;
7292 int sw_if_index_set;
7293 u32 ip4_table_index = ~0;
7294 u32 ip6_table_index = ~0;
7295 u32 other_table_index = ~0;
7297 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
7298 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
7299 sw_if_index_set = 1;
7300 else if (unformat (i, "sw_if_index %d", &sw_if_index))
7301 sw_if_index_set = 1;
7302 else if (unformat (i, "ip4-table %d", &ip4_table_index))
7304 else if (unformat (i, "ip6-table %d", &ip6_table_index))
7306 else if (unformat (i, "other-table %d", &other_table_index))
7309 clib_warning ("parse error '%U'", format_unformat_error, i);
7314 if (sw_if_index_set == 0) {
7315 errmsg ("missing interface name or sw_if_index\n");
7320 M(CLASSIFY_SET_INTERFACE_L2_TABLES, classify_set_interface_l2_tables);
7322 mp->sw_if_index = ntohl(sw_if_index);
7323 mp->ip4_table_index = ntohl(ip4_table_index);
7324 mp->ip6_table_index = ntohl(ip6_table_index);
7325 mp->other_table_index = ntohl(other_table_index);
7333 static int api_get_node_index (vat_main_t * vam)
7335 unformat_input_t * i = vam->input;
7336 vl_api_get_node_index_t * mp;
7340 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
7341 if (unformat (i, "node %s", &name))
7347 errmsg ("node name required\n");
7350 if (vec_len (name) >= ARRAY_LEN(mp->node_name)) {
7351 errmsg ("node name too long, max %d\n", ARRAY_LEN(mp->node_name));
7355 M(GET_NODE_INDEX, get_node_index);
7356 clib_memcpy (mp->node_name, name, vec_len(name));
7364 static int api_add_node_next (vat_main_t * vam)
7366 unformat_input_t * i = vam->input;
7367 vl_api_add_node_next_t * mp;
7372 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
7373 if (unformat (i, "node %s", &name))
7375 else if (unformat (i, "next %s", &next))
7381 errmsg ("node name required\n");
7384 if (vec_len (name) >= ARRAY_LEN(mp->node_name)) {
7385 errmsg ("node name too long, max %d\n", ARRAY_LEN(mp->node_name));
7389 errmsg ("next node required\n");
7392 if (vec_len (next) >= ARRAY_LEN(mp->next_name)) {
7393 errmsg ("next name too long, max %d\n", ARRAY_LEN(mp->next_name));
7397 M(ADD_NODE_NEXT, add_node_next);
7398 clib_memcpy (mp->node_name, name, vec_len(name));
7399 clib_memcpy (mp->next_name, next, vec_len(next));
7408 static int api_l2tpv3_create_tunnel (vat_main_t * vam)
7410 unformat_input_t * i = vam->input;
7411 ip6_address_t client_address, our_address;
7412 int client_address_set = 0;
7413 int our_address_set = 0;
7414 u32 local_session_id = 0;
7415 u32 remote_session_id = 0;
7416 u64 local_cookie = 0;
7417 u64 remote_cookie = 0;
7418 u8 l2_sublayer_present = 0;
7419 vl_api_l2tpv3_create_tunnel_t * mp;
7422 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
7423 if (unformat (i, "client_address %U", unformat_ip6_address,
7425 client_address_set = 1;
7426 else if (unformat (i, "our_address %U", unformat_ip6_address,
7428 our_address_set = 1;
7429 else if (unformat (i, "local_session_id %d", &local_session_id))
7431 else if (unformat (i, "remote_session_id %d", &remote_session_id))
7433 else if (unformat (i, "local_cookie %lld", &local_cookie))
7435 else if (unformat (i, "remote_cookie %lld", &remote_cookie))
7437 else if (unformat (i, "l2-sublayer-present"))
7438 l2_sublayer_present = 1;
7443 if (client_address_set == 0) {
7444 errmsg ("client_address required\n");
7448 if (our_address_set == 0) {
7449 errmsg ("our_address required\n");
7453 M(L2TPV3_CREATE_TUNNEL, l2tpv3_create_tunnel);
7455 clib_memcpy (mp->client_address, client_address.as_u8,
7456 sizeof (mp->client_address));
7458 clib_memcpy (mp->our_address, our_address.as_u8,
7459 sizeof (mp->our_address));
7461 mp->local_session_id = ntohl (local_session_id);
7462 mp->remote_session_id = ntohl (remote_session_id);
7463 mp->local_cookie = clib_host_to_net_u64 (local_cookie);
7464 mp->remote_cookie = clib_host_to_net_u64 (remote_cookie);
7465 mp->l2_sublayer_present = l2_sublayer_present;
7473 static int api_l2tpv3_set_tunnel_cookies (vat_main_t * vam)
7475 unformat_input_t * i = vam->input;
7477 u8 sw_if_index_set = 0;
7478 u64 new_local_cookie = 0;
7479 u64 new_remote_cookie = 0;
7480 vl_api_l2tpv3_set_tunnel_cookies_t *mp;
7483 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
7484 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
7485 sw_if_index_set = 1;
7486 else if (unformat (i, "sw_if_index %d", &sw_if_index))
7487 sw_if_index_set = 1;
7488 else if (unformat (i, "new_local_cookie %lld", &new_local_cookie))
7490 else if (unformat (i, "new_remote_cookie %lld", &new_remote_cookie))
7496 if (sw_if_index_set == 0) {
7497 errmsg ("missing interface name or sw_if_index\n");
7501 M(L2TPV3_SET_TUNNEL_COOKIES, l2tpv3_set_tunnel_cookies);
7503 mp->sw_if_index = ntohl(sw_if_index);
7504 mp->new_local_cookie = clib_host_to_net_u64 (new_local_cookie);
7505 mp->new_remote_cookie = clib_host_to_net_u64 (new_remote_cookie);
7512 static int api_l2tpv3_interface_enable_disable (vat_main_t * vam)
7514 unformat_input_t * i = vam->input;
7515 vl_api_l2tpv3_interface_enable_disable_t *mp;
7518 u8 sw_if_index_set = 0;
7519 u8 enable_disable = 1;
7521 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
7522 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
7523 sw_if_index_set = 1;
7524 else if (unformat (i, "sw_if_index %d", &sw_if_index))
7525 sw_if_index_set = 1;
7526 else if (unformat (i, "enable"))
7528 else if (unformat (i, "disable"))
7534 if (sw_if_index_set == 0) {
7535 errmsg ("missing interface name or sw_if_index\n");
7539 M(L2TPV3_INTERFACE_ENABLE_DISABLE, l2tpv3_interface_enable_disable);
7541 mp->sw_if_index = ntohl(sw_if_index);
7542 mp->enable_disable = enable_disable;
7549 static int api_l2tpv3_set_lookup_key (vat_main_t * vam)
7551 unformat_input_t * i = vam->input;
7552 vl_api_l2tpv3_set_lookup_key_t * mp;
7556 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
7557 if (unformat (i, "lookup_v6_src"))
7558 key = L2T_LOOKUP_SRC_ADDRESS;
7559 else if (unformat (i, "lookup_v6_dst"))
7560 key = L2T_LOOKUP_DST_ADDRESS;
7561 else if (unformat (i, "lookup_session_id"))
7562 key = L2T_LOOKUP_SESSION_ID;
7567 if (key == (u8) ~0) {
7568 errmsg ("l2tp session lookup key unset\n");
7572 M(L2TPV3_SET_LOOKUP_KEY, l2tpv3_set_lookup_key);
7581 static void vl_api_sw_if_l2tpv3_tunnel_details_t_handler
7582 (vl_api_sw_if_l2tpv3_tunnel_details_t * mp)
7584 vat_main_t * vam = &vat_main;
7586 fformat(vam->ofp, "* %U (our) %U (client) (sw_if_index %d)\n",
7587 format_ip6_address, mp->our_address,
7588 format_ip6_address, mp->client_address,
7589 clib_net_to_host_u32(mp->sw_if_index));
7591 fformat (vam->ofp, " local cookies %016llx %016llx remote cookie %016llx\n",
7592 clib_net_to_host_u64 (mp->local_cookie[0]),
7593 clib_net_to_host_u64 (mp->local_cookie[1]),
7594 clib_net_to_host_u64 (mp->remote_cookie));
7596 fformat (vam->ofp, " local session-id %d remote session-id %d\n",
7597 clib_net_to_host_u32 (mp->local_session_id),
7598 clib_net_to_host_u32 (mp->remote_session_id));
7600 fformat (vam->ofp, " l2 specific sublayer %s\n\n",
7601 mp->l2_sublayer_present ? "preset" : "absent");
7605 static void vl_api_sw_if_l2tpv3_tunnel_details_t_handler_json
7606 (vl_api_sw_if_l2tpv3_tunnel_details_t * mp)
7608 vat_main_t * vam = &vat_main;
7609 vat_json_node_t *node = NULL;
7610 struct in6_addr addr;
7612 if (VAT_JSON_ARRAY != vam->json_tree.type) {
7613 ASSERT(VAT_JSON_NONE == vam->json_tree.type);
7614 vat_json_init_array(&vam->json_tree);
7616 node = vat_json_array_add(&vam->json_tree);
7618 vat_json_init_object(node);
7620 clib_memcpy(&addr, mp->our_address, sizeof(addr));
7621 vat_json_object_add_ip6(node, "our_address", addr);
7622 clib_memcpy(&addr, mp->client_address, sizeof(addr));
7623 vat_json_object_add_ip6(node, "client_address", addr);
7625 vat_json_node_t * lc = vat_json_object_add(node, "local_cookie");
7626 vat_json_init_array(lc);
7627 vat_json_array_add_uint(lc, clib_net_to_host_u64(mp->local_cookie[0]));
7628 vat_json_array_add_uint(lc, clib_net_to_host_u64(mp->local_cookie[1]));
7629 vat_json_object_add_uint(node, "remote_cookie", clib_net_to_host_u64(mp->remote_cookie));
7631 printf("local id: %u", clib_net_to_host_u32(mp->local_session_id));
7632 vat_json_object_add_uint(node, "local_session_id", clib_net_to_host_u32(mp->local_session_id));
7633 vat_json_object_add_uint(node, "remote_session_id", clib_net_to_host_u32(mp->remote_session_id));
7634 vat_json_object_add_string_copy(node, "l2_sublayer", mp->l2_sublayer_present ?
7635 (u8*)"present" : (u8*)"absent");
7638 static int api_sw_if_l2tpv3_tunnel_dump (vat_main_t * vam)
7640 vl_api_sw_if_l2tpv3_tunnel_dump_t *mp;
7643 /* Get list of l2tpv3-tunnel interfaces */
7644 M(SW_IF_L2TPV3_TUNNEL_DUMP, sw_if_l2tpv3_tunnel_dump);
7647 /* Use a control ping for synchronization */
7649 vl_api_control_ping_t * mp;
7650 M(CONTROL_PING, control_ping);
7657 static void vl_api_sw_interface_tap_details_t_handler
7658 (vl_api_sw_interface_tap_details_t * mp)
7660 vat_main_t * vam = &vat_main;
7662 fformat(vam->ofp, "%-16s %d\n",
7664 clib_net_to_host_u32(mp->sw_if_index));
7667 static void vl_api_sw_interface_tap_details_t_handler_json
7668 (vl_api_sw_interface_tap_details_t * mp)
7670 vat_main_t * vam = &vat_main;
7671 vat_json_node_t *node = NULL;
7673 if (VAT_JSON_ARRAY != vam->json_tree.type) {
7674 ASSERT(VAT_JSON_NONE == vam->json_tree.type);
7675 vat_json_init_array(&vam->json_tree);
7677 node = vat_json_array_add(&vam->json_tree);
7679 vat_json_init_object(node);
7680 vat_json_object_add_uint(node, "sw_if_index", ntohl(mp->sw_if_index));
7681 vat_json_object_add_string_copy(node, "dev_name", mp->dev_name);
7684 static int api_sw_interface_tap_dump (vat_main_t * vam)
7686 vl_api_sw_interface_tap_dump_t *mp;
7689 fformat(vam->ofp, "\n%-16s %s\n", "dev_name", "sw_if_index");
7690 /* Get list of tap interfaces */
7691 M(SW_INTERFACE_TAP_DUMP, sw_interface_tap_dump);
7694 /* Use a control ping for synchronization */
7696 vl_api_control_ping_t * mp;
7697 M(CONTROL_PING, control_ping);
7703 static uword unformat_vxlan_decap_next
7704 (unformat_input_t * input, va_list * args)
7706 u32 * result = va_arg (*args, u32 *);
7709 if (unformat (input, "drop"))
7710 *result = VXLAN_INPUT_NEXT_DROP;
7711 else if (unformat (input, "ip4"))
7712 *result = VXLAN_INPUT_NEXT_IP4_INPUT;
7713 else if (unformat (input, "ip6"))
7714 *result = VXLAN_INPUT_NEXT_IP6_INPUT;
7715 else if (unformat (input, "l2"))
7716 *result = VXLAN_INPUT_NEXT_L2_INPUT;
7717 else if (unformat (input, "%d", &tmp))
7724 static int api_vxlan_add_del_tunnel (vat_main_t * vam)
7726 unformat_input_t * line_input = vam->input;
7727 vl_api_vxlan_add_del_tunnel_t *mp;
7729 ip4_address_t src4, dst4;
7730 ip6_address_t src6, dst6;
7732 u8 ipv4_set = 0, ipv6_set = 0;
7735 u32 encap_vrf_id = 0;
7736 u32 decap_next_index = ~0;
7739 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) {
7740 if (unformat (line_input, "del"))
7742 else if (unformat (line_input, "src %U",
7743 unformat_ip4_address, &src4))
7748 else if (unformat (line_input, "dst %U",
7749 unformat_ip4_address, &dst4))
7754 else if (unformat (line_input, "src %U",
7755 unformat_ip6_address, &src6))
7760 else if (unformat (line_input, "dst %U",
7761 unformat_ip6_address, &dst6))
7766 else if (unformat (line_input, "encap-vrf-id %d", &encap_vrf_id))
7768 else if (unformat (line_input, "decap-next %U",
7769 unformat_vxlan_decap_next, &decap_next_index))
7771 else if (unformat (line_input, "vni %d", &vni))
7774 errmsg ("parse error '%U'\n", format_unformat_error, line_input);
7780 errmsg ("tunnel src address not specified\n");
7784 errmsg ("tunnel dst address not specified\n");
7788 if (ipv4_set && ipv6_set) {
7789 errmsg ("both IPv4 and IPv6 addresses specified");
7793 if ((vni == 0) || (vni>>24)) {
7794 errmsg ("vni not specified or out of range\n");
7798 M (VXLAN_ADD_DEL_TUNNEL, vxlan_add_del_tunnel);
7801 clib_memcpy(&mp->src_address, &src6, sizeof(src6));
7802 clib_memcpy(&mp->dst_address, &dst6, sizeof(dst6));
7804 clib_memcpy(&mp->src_address, &src4, sizeof(src4));
7805 clib_memcpy(&mp->dst_address, &dst4, sizeof(dst4));
7807 mp->encap_vrf_id = ntohl(encap_vrf_id);
7808 mp->decap_next_index = ntohl(decap_next_index);
7809 mp->vni = ntohl(vni);
7810 mp->is_add = is_add;
7811 mp->is_ipv6 = ipv6_set;
7818 static void vl_api_vxlan_tunnel_details_t_handler
7819 (vl_api_vxlan_tunnel_details_t * mp)
7821 vat_main_t * vam = &vat_main;
7823 fformat(vam->ofp, "%11d%24U%24U%14d%18d%13d\n",
7824 ntohl(mp->sw_if_index),
7825 format_ip46_address, &(mp->src_address[0]),
7827 format_ip46_address, &(mp->dst_address[0]),
7829 ntohl(mp->encap_vrf_id),
7830 ntohl(mp->decap_next_index),
7834 static void vl_api_vxlan_tunnel_details_t_handler_json
7835 (vl_api_vxlan_tunnel_details_t * mp)
7837 vat_main_t * vam = &vat_main;
7838 vat_json_node_t *node = NULL;
7840 struct in6_addr ip6;
7842 if (VAT_JSON_ARRAY != vam->json_tree.type) {
7843 ASSERT(VAT_JSON_NONE == vam->json_tree.type);
7844 vat_json_init_array(&vam->json_tree);
7846 node = vat_json_array_add(&vam->json_tree);
7848 vat_json_init_object(node);
7849 vat_json_object_add_uint(node, "sw_if_index", ntohl(mp->sw_if_index));
7851 clib_memcpy(&ip6, &(mp->src_address[0]), sizeof(ip6));
7852 vat_json_object_add_ip6(node, "src_address", ip6);
7853 clib_memcpy(&ip6, &(mp->dst_address[0]), sizeof(ip6));
7854 vat_json_object_add_ip6(node, "dst_address", ip6);
7856 clib_memcpy(&ip4, &(mp->src_address[0]), sizeof(ip4));
7857 vat_json_object_add_ip4(node, "src_address", ip4);
7858 clib_memcpy(&ip4, &(mp->dst_address[0]), sizeof(ip4));
7859 vat_json_object_add_ip4(node, "dst_address", ip4);
7861 vat_json_object_add_uint(node, "encap_vrf_id", ntohl(mp->encap_vrf_id));
7862 vat_json_object_add_uint(node, "decap_next_index", ntohl(mp->decap_next_index));
7863 vat_json_object_add_uint(node, "vni", ntohl(mp->vni));
7864 vat_json_object_add_uint(node, "is_ipv6", mp->is_ipv6 ? 1 : 0);
7867 static int api_vxlan_tunnel_dump (vat_main_t * vam)
7869 unformat_input_t * i = vam->input;
7870 vl_api_vxlan_tunnel_dump_t *mp;
7873 u8 sw_if_index_set = 0;
7875 /* Parse args required to build the message */
7876 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
7877 if (unformat (i, "sw_if_index %d", &sw_if_index))
7878 sw_if_index_set = 1;
7883 if (sw_if_index_set == 0) {
7887 if (!vam->json_output) {
7888 fformat(vam->ofp, "%11s%24s%24s%14s%18s%13s\n",
7889 "sw_if_index", "src_address", "dst_address",
7890 "encap_vrf_id", "decap_next_index", "vni");
7893 /* Get list of vxlan-tunnel interfaces */
7894 M(VXLAN_TUNNEL_DUMP, vxlan_tunnel_dump);
7896 mp->sw_if_index = htonl(sw_if_index);
7900 /* Use a control ping for synchronization */
7902 vl_api_control_ping_t * mp;
7903 M(CONTROL_PING, control_ping);
7909 static int api_gre_add_del_tunnel (vat_main_t * vam)
7911 unformat_input_t * line_input = vam->input;
7912 vl_api_gre_add_del_tunnel_t *mp;
7914 ip4_address_t src4, dst4;
7918 u32 outer_fib_id = 0;
7920 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) {
7921 if (unformat (line_input, "del"))
7923 else if (unformat (line_input, "src %U",
7924 unformat_ip4_address, &src4))
7926 else if (unformat (line_input, "dst %U",
7927 unformat_ip4_address, &dst4))
7929 else if (unformat (line_input, "outer-fib-id %d", &outer_fib_id))
7932 errmsg ("parse error '%U'\n", format_unformat_error, line_input);
7938 errmsg ("tunnel src address not specified\n");
7942 errmsg ("tunnel dst address not specified\n");
7947 M (GRE_ADD_DEL_TUNNEL, gre_add_del_tunnel);
7949 clib_memcpy(&mp->src_address, &src4, sizeof(src4));
7950 clib_memcpy(&mp->dst_address, &dst4, sizeof(dst4));
7951 mp->outer_table_id = ntohl(outer_fib_id);
7952 mp->is_add = is_add;
7959 static void vl_api_gre_tunnel_details_t_handler
7960 (vl_api_gre_tunnel_details_t * mp)
7962 vat_main_t * vam = &vat_main;
7964 fformat(vam->ofp, "%11d%15U%15U%14d\n",
7965 ntohl(mp->sw_if_index),
7966 format_ip4_address, &mp->src_address,
7967 format_ip4_address, &mp->dst_address,
7968 ntohl(mp->outer_table_id));
7971 static void vl_api_gre_tunnel_details_t_handler_json
7972 (vl_api_gre_tunnel_details_t * mp)
7974 vat_main_t * vam = &vat_main;
7975 vat_json_node_t *node = NULL;
7978 if (VAT_JSON_ARRAY != vam->json_tree.type) {
7979 ASSERT(VAT_JSON_NONE == vam->json_tree.type);
7980 vat_json_init_array(&vam->json_tree);
7982 node = vat_json_array_add(&vam->json_tree);
7984 vat_json_init_object(node);
7985 vat_json_object_add_uint(node, "sw_if_index", ntohl(mp->sw_if_index));
7986 clib_memcpy(&ip4, &mp->src_address, sizeof(ip4));
7987 vat_json_object_add_ip4(node, "src_address", ip4);
7988 clib_memcpy(&ip4, &mp->dst_address, sizeof(ip4));
7989 vat_json_object_add_ip4(node, "dst_address", ip4);
7990 vat_json_object_add_uint(node, "outer_fib_id", ntohl(mp->outer_table_id));
7993 static int api_gre_tunnel_dump (vat_main_t * vam)
7995 unformat_input_t * i = vam->input;
7996 vl_api_gre_tunnel_dump_t *mp;
7999 u8 sw_if_index_set = 0;
8001 /* Parse args required to build the message */
8002 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
8003 if (unformat (i, "sw_if_index %d", &sw_if_index))
8004 sw_if_index_set = 1;
8009 if (sw_if_index_set == 0) {
8013 if (!vam->json_output) {
8014 fformat(vam->ofp, "%11s%15s%15s%14s\n",
8015 "sw_if_index", "src_address", "dst_address",
8019 /* Get list of gre-tunnel interfaces */
8020 M(GRE_TUNNEL_DUMP, gre_tunnel_dump);
8022 mp->sw_if_index = htonl(sw_if_index);
8026 /* Use a control ping for synchronization */
8028 vl_api_control_ping_t * mp;
8029 M(CONTROL_PING, control_ping);
8035 static int api_l2_fib_clear_table (vat_main_t * vam)
8037 // unformat_input_t * i = vam->input;
8038 vl_api_l2_fib_clear_table_t *mp;
8041 M(L2_FIB_CLEAR_TABLE, l2_fib_clear_table);
8048 static int api_l2_interface_efp_filter (vat_main_t * vam)
8050 unformat_input_t * i = vam->input;
8051 vl_api_l2_interface_efp_filter_t *mp;
8055 u8 sw_if_index_set = 0;
8057 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
8058 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
8059 sw_if_index_set = 1;
8060 else if (unformat (i, "sw_if_index %d", &sw_if_index))
8061 sw_if_index_set = 1;
8062 else if (unformat (i, "enable"))
8064 else if (unformat (i, "disable"))
8067 clib_warning ("parse error '%U'", format_unformat_error, i);
8072 if (sw_if_index_set == 0) {
8073 errmsg ("missing sw_if_index\n");
8077 M(L2_INTERFACE_EFP_FILTER, l2_interface_efp_filter);
8079 mp->sw_if_index = ntohl(sw_if_index);
8080 mp->enable_disable = enable;
8087 #define foreach_vtr_op \
8088 _("disable", L2_VTR_DISABLED) \
8089 _("push-1", L2_VTR_PUSH_1) \
8090 _("push-2", L2_VTR_PUSH_2) \
8091 _("pop-1", L2_VTR_POP_1) \
8092 _("pop-2", L2_VTR_POP_2) \
8093 _("translate-1-1", L2_VTR_TRANSLATE_1_1) \
8094 _("translate-1-2", L2_VTR_TRANSLATE_1_2) \
8095 _("translate-2-1", L2_VTR_TRANSLATE_2_1) \
8096 _("translate-2-2", L2_VTR_TRANSLATE_2_2)
8098 static int api_l2_interface_vlan_tag_rewrite (vat_main_t * vam)
8100 unformat_input_t * i = vam->input;
8101 vl_api_l2_interface_vlan_tag_rewrite_t *mp;
8104 u8 sw_if_index_set = 0;
8111 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
8112 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
8113 sw_if_index_set = 1;
8114 else if (unformat (i, "sw_if_index %d", &sw_if_index))
8115 sw_if_index_set = 1;
8116 else if (unformat (i, "vtr_op %d", &vtr_op))
8118 #define _(n,v) else if (unformat(i, n)) {vtr_op = v; vtr_op_set = 1;}
8122 else if (unformat (i, "push_dot1q %d", &push_dot1q))
8124 else if (unformat (i, "tag1 %d", &tag1))
8126 else if (unformat (i, "tag2 %d", &tag2))
8129 clib_warning ("parse error '%U'", format_unformat_error, i);
8134 if ((sw_if_index_set == 0)||(vtr_op_set == 0)) {
8135 errmsg ("missing vtr operation or sw_if_index\n");
8139 M(L2_INTERFACE_VLAN_TAG_REWRITE, l2_interface_vlan_tag_rewrite)
8141 mp->sw_if_index = ntohl(sw_if_index);
8142 mp->vtr_op = ntohl(vtr_op);
8143 mp->push_dot1q = ntohl(push_dot1q);
8144 mp->tag1 = ntohl(tag1);
8145 mp->tag2 = ntohl(tag2);
8152 static int api_create_vhost_user_if (vat_main_t * vam)
8154 unformat_input_t * i = vam->input;
8155 vl_api_create_vhost_user_if_t *mp;
8159 u8 file_name_set = 0;
8160 u32 custom_dev_instance = ~0;
8162 u8 use_custom_mac = 0;
8164 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
8165 if (unformat (i, "socket %s", &file_name)) {
8168 else if (unformat (i, "renumber %"PRIu32, &custom_dev_instance))
8170 else if (unformat (i, "mac %U", unformat_ethernet_address, hwaddr))
8172 else if (unformat (i, "server"))
8178 if (file_name_set == 0) {
8179 errmsg ("missing socket file name\n");
8183 if (vec_len (file_name) > 255) {
8184 errmsg ("socket file name too long\n");
8187 vec_add1 (file_name, 0);
8189 M(CREATE_VHOST_USER_IF, create_vhost_user_if);
8191 mp->is_server = is_server;
8192 clib_memcpy(mp->sock_filename, file_name, vec_len(file_name));
8193 vec_free(file_name);
8194 if (custom_dev_instance != ~0) {
8196 mp->custom_dev_instance = ntohl(custom_dev_instance);
8198 mp->use_custom_mac = use_custom_mac;
8199 clib_memcpy(mp->mac_address, hwaddr, 6);
8206 static int api_modify_vhost_user_if (vat_main_t * vam)
8208 unformat_input_t * i = vam->input;
8209 vl_api_modify_vhost_user_if_t *mp;
8213 u8 file_name_set = 0;
8214 u32 custom_dev_instance = ~0;
8215 u8 sw_if_index_set = 0;
8216 u32 sw_if_index = (u32)~0;
8218 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
8219 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
8220 sw_if_index_set = 1;
8221 else if (unformat (i, "sw_if_index %d", &sw_if_index))
8222 sw_if_index_set = 1;
8223 else if (unformat (i, "socket %s", &file_name)) {
8226 else if (unformat (i, "renumber %"PRIu32, &custom_dev_instance))
8228 else if (unformat (i, "server"))
8234 if (sw_if_index_set == 0) {
8235 errmsg ("missing sw_if_index or interface name\n");
8239 if (file_name_set == 0) {
8240 errmsg ("missing socket file name\n");
8244 if (vec_len (file_name) > 255) {
8245 errmsg ("socket file name too long\n");
8248 vec_add1 (file_name, 0);
8250 M(MODIFY_VHOST_USER_IF, modify_vhost_user_if);
8252 mp->sw_if_index = ntohl(sw_if_index);
8253 mp->is_server = is_server;
8254 clib_memcpy(mp->sock_filename, file_name, vec_len(file_name));
8255 vec_free(file_name);
8256 if (custom_dev_instance != ~0) {
8258 mp->custom_dev_instance = ntohl(custom_dev_instance);
8266 static int api_delete_vhost_user_if (vat_main_t * vam)
8268 unformat_input_t * i = vam->input;
8269 vl_api_delete_vhost_user_if_t *mp;
8271 u32 sw_if_index = ~0;
8272 u8 sw_if_index_set = 0;
8274 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
8275 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
8276 sw_if_index_set = 1;
8277 else if (unformat (i, "sw_if_index %d", &sw_if_index))
8278 sw_if_index_set = 1;
8283 if (sw_if_index_set == 0) {
8284 errmsg ("missing sw_if_index or interface name\n");
8289 M(DELETE_VHOST_USER_IF, delete_vhost_user_if);
8291 mp->sw_if_index = ntohl(sw_if_index);
8298 static void vl_api_sw_interface_vhost_user_details_t_handler
8299 (vl_api_sw_interface_vhost_user_details_t * mp)
8301 vat_main_t * vam = &vat_main;
8303 fformat(vam->ofp, "%-25s %3" PRIu32 " %6" PRIu32 " %8x %6d %7d %s\n",
8304 (char *)mp->interface_name,
8305 ntohl(mp->sw_if_index), ntohl(mp->virtio_net_hdr_sz),
8306 clib_net_to_host_u64(mp->features), mp->is_server,
8307 ntohl(mp->num_regions), (char *)mp->sock_filename);
8308 fformat(vam->ofp, " Status: '%s'\n", strerror(ntohl(mp->sock_errno)));
8311 static void vl_api_sw_interface_vhost_user_details_t_handler_json
8312 (vl_api_sw_interface_vhost_user_details_t * mp)
8314 vat_main_t * vam = &vat_main;
8315 vat_json_node_t *node = NULL;
8317 if (VAT_JSON_ARRAY != vam->json_tree.type) {
8318 ASSERT(VAT_JSON_NONE == vam->json_tree.type);
8319 vat_json_init_array(&vam->json_tree);
8321 node = vat_json_array_add(&vam->json_tree);
8323 vat_json_init_object(node);
8324 vat_json_object_add_uint(node, "sw_if_index", ntohl(mp->sw_if_index));
8325 vat_json_object_add_string_copy(node, "interface_name", mp->interface_name);
8326 vat_json_object_add_uint(node, "virtio_net_hdr_sz", ntohl(mp->virtio_net_hdr_sz));
8327 vat_json_object_add_uint(node, "features", clib_net_to_host_u64(mp->features));
8328 vat_json_object_add_uint(node, "is_server", mp->is_server);
8329 vat_json_object_add_string_copy(node, "sock_filename", mp->sock_filename);
8330 vat_json_object_add_uint(node, "num_regions", ntohl(mp->num_regions));
8331 vat_json_object_add_uint(node, "sock_errno", ntohl(mp->sock_errno));
8334 static int api_sw_interface_vhost_user_dump (vat_main_t * vam)
8336 vl_api_sw_interface_vhost_user_dump_t *mp;
8338 fformat(vam->ofp, "Interface name idx hdr_sz features server regions filename\n");
8340 /* Get list of vhost-user interfaces */
8341 M(SW_INTERFACE_VHOST_USER_DUMP, sw_interface_vhost_user_dump);
8344 /* Use a control ping for synchronization */
8346 vl_api_control_ping_t * mp;
8347 M(CONTROL_PING, control_ping);
8353 static int api_show_version (vat_main_t * vam)
8355 vl_api_show_version_t *mp;
8358 M(SHOW_VERSION, show_version);
8366 static int api_vxlan_gpe_add_del_tunnel (vat_main_t * vam)
8368 unformat_input_t * line_input = vam->input;
8369 vl_api_vxlan_gpe_add_del_tunnel_t *mp;
8371 ip4_address_t local4, remote4;
8372 ip6_address_t local6, remote6;
8374 u8 ipv4_set = 0, ipv6_set = 0;
8377 u32 encap_vrf_id = 0;
8378 u32 decap_vrf_id = 0;
8383 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) {
8384 if (unformat (line_input, "del"))
8386 else if (unformat (line_input, "local %U",
8387 unformat_ip4_address, &local4))
8392 else if (unformat (line_input, "remote %U",
8393 unformat_ip4_address, &remote4))
8398 else if (unformat (line_input, "local %U",
8399 unformat_ip6_address, &local6))
8404 else if (unformat (line_input, "remote %U",
8405 unformat_ip6_address, &remote6))
8410 else if (unformat (line_input, "encap-vrf-id %d", &encap_vrf_id))
8412 else if (unformat (line_input, "decap-vrf-id %d", &decap_vrf_id))
8414 else if (unformat (line_input, "vni %d", &vni))
8416 else if (unformat(line_input, "next-ip4"))
8418 else if (unformat(line_input, "next-ip6"))
8420 else if (unformat(line_input, "next-ethernet"))
8422 else if (unformat(line_input, "next-nsh"))
8425 errmsg ("parse error '%U'\n", format_unformat_error, line_input);
8430 if (local_set == 0) {
8431 errmsg ("tunnel local address not specified\n");
8434 if (remote_set == 0) {
8435 errmsg ("tunnel remote address not specified\n");
8438 if (ipv4_set && ipv6_set) {
8439 errmsg ("both IPv4 and IPv6 addresses specified");
8444 errmsg ("vni not specified\n");
8448 M(VXLAN_GPE_ADD_DEL_TUNNEL, vxlan_gpe_add_del_tunnel);
8452 clib_memcpy(&mp->local, &local6, sizeof(local6));
8453 clib_memcpy(&mp->remote, &remote6, sizeof(remote6));
8455 clib_memcpy(&mp->local, &local4, sizeof(local4));
8456 clib_memcpy(&mp->remote, &remote4, sizeof(remote4));
8459 mp->encap_vrf_id = ntohl(encap_vrf_id);
8460 mp->decap_vrf_id = ntohl(decap_vrf_id);
8461 mp->protocol = ntohl(protocol);
8462 mp->vni = ntohl(vni);
8463 mp->is_add = is_add;
8464 mp->is_ipv6 = ipv6_set;
8471 static void vl_api_vxlan_gpe_tunnel_details_t_handler
8472 (vl_api_vxlan_gpe_tunnel_details_t * mp)
8474 vat_main_t * vam = &vat_main;
8476 fformat(vam->ofp, "%11d%24U%24U%13d%12d%14d%14d\n",
8477 ntohl(mp->sw_if_index),
8478 format_ip46_address, &(mp->local[0]),
8479 format_ip46_address, &(mp->remote[0]),
8481 ntohl(mp->protocol),
8482 ntohl(mp->encap_vrf_id),
8483 ntohl(mp->decap_vrf_id));
8486 static void vl_api_vxlan_gpe_tunnel_details_t_handler_json
8487 (vl_api_vxlan_gpe_tunnel_details_t * mp)
8489 vat_main_t * vam = &vat_main;
8490 vat_json_node_t *node = NULL;
8492 struct in6_addr ip6;
8494 if (VAT_JSON_ARRAY != vam->json_tree.type) {
8495 ASSERT(VAT_JSON_NONE == vam->json_tree.type);
8496 vat_json_init_array(&vam->json_tree);
8498 node = vat_json_array_add(&vam->json_tree);
8500 vat_json_init_object(node);
8501 vat_json_object_add_uint(node, "sw_if_index", ntohl(mp->sw_if_index));
8503 clib_memcpy(&ip6, &(mp->local[0]), sizeof(ip6));
8504 vat_json_object_add_ip6(node, "local", ip6);
8505 clib_memcpy(&ip6, &(mp->remote[0]), sizeof(ip6));
8506 vat_json_object_add_ip6(node, "remote", ip6);
8508 clib_memcpy(&ip4, &(mp->local[0]), sizeof(ip4));
8509 vat_json_object_add_ip4(node, "local", ip4);
8510 clib_memcpy(&ip4, &(mp->remote[0]), sizeof(ip4));
8511 vat_json_object_add_ip4(node, "remote", ip4);
8513 vat_json_object_add_uint(node, "vni", ntohl(mp->vni));
8514 vat_json_object_add_uint(node, "protocol", ntohl(mp->protocol));
8515 vat_json_object_add_uint(node, "encap_vrf_id", ntohl(mp->encap_vrf_id));
8516 vat_json_object_add_uint(node, "decap_vrf_id", ntohl(mp->decap_vrf_id));
8517 vat_json_object_add_uint(node, "is_ipv6", mp->is_ipv6 ? 1 : 0);
8520 static int api_vxlan_gpe_tunnel_dump (vat_main_t * vam)
8522 unformat_input_t * i = vam->input;
8523 vl_api_vxlan_gpe_tunnel_dump_t *mp;
8526 u8 sw_if_index_set = 0;
8528 /* Parse args required to build the message */
8529 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
8530 if (unformat (i, "sw_if_index %d", &sw_if_index))
8531 sw_if_index_set = 1;
8536 if (sw_if_index_set == 0) {
8540 if (!vam->json_output) {
8541 fformat(vam->ofp, "%11s%24s%24s%13s%15s%14s%14s\n",
8542 "sw_if_index", "local", "remote", "vni",
8543 "protocol","encap_vrf_id", "decap_vrf_id");
8546 /* Get list of vxlan-tunnel interfaces */
8547 M(VXLAN_GPE_TUNNEL_DUMP, vxlan_gpe_tunnel_dump);
8549 mp->sw_if_index = htonl(sw_if_index);
8553 /* Use a control ping for synchronization */
8555 vl_api_control_ping_t * mp;
8556 M(CONTROL_PING, control_ping);
8562 u8 * format_l2_fib_mac_address (u8 * s, va_list * args)
8564 u8 * a = va_arg (*args, u8 *);
8566 return format (s, "%02x:%02x:%02x:%02x:%02x:%02x",
8567 a[2], a[3], a[4], a[5], a[6], a[7]);
8570 static void vl_api_l2_fib_table_entry_t_handler
8571 (vl_api_l2_fib_table_entry_t * mp)
8573 vat_main_t * vam = &vat_main;
8575 fformat(vam->ofp, "%3" PRIu32 " %U %3" PRIu32
8577 ntohl(mp->bd_id), format_l2_fib_mac_address, &mp->mac,
8578 ntohl(mp->sw_if_index), mp->static_mac, mp->filter_mac,
8582 static void vl_api_l2_fib_table_entry_t_handler_json
8583 (vl_api_l2_fib_table_entry_t * mp)
8585 vat_main_t * vam = &vat_main;
8586 vat_json_node_t *node = NULL;
8588 if (VAT_JSON_ARRAY != vam->json_tree.type) {
8589 ASSERT(VAT_JSON_NONE == vam->json_tree.type);
8590 vat_json_init_array(&vam->json_tree);
8592 node = vat_json_array_add(&vam->json_tree);
8594 vat_json_init_object(node);
8595 vat_json_object_add_uint(node, "bd_id", ntohl(mp->bd_id));
8596 vat_json_object_add_uint(node, "mac", clib_net_to_host_u64(mp->mac));
8597 vat_json_object_add_uint(node, "sw_if_index", ntohl(mp->sw_if_index));
8598 vat_json_object_add_uint(node, "static_mac", mp->static_mac);
8599 vat_json_object_add_uint(node, "filter_mac", mp->filter_mac);
8600 vat_json_object_add_uint(node, "bvi_mac", mp->bvi_mac);
8603 static int api_l2_fib_table_dump (vat_main_t * vam)
8605 unformat_input_t * i = vam->input;
8606 vl_api_l2_fib_table_dump_t *mp;
8611 /* Parse args required to build the message */
8612 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
8613 if (unformat (i, "bd_id %d", &bd_id))
8619 if (bd_id_set == 0) {
8620 errmsg ("missing bridge domain\n");
8624 fformat(vam->ofp, "BD-ID Mac Address sw-ndx Static Filter BVI\n");
8626 /* Get list of l2 fib entries */
8627 M(L2_FIB_TABLE_DUMP, l2_fib_table_dump);
8629 mp->bd_id = ntohl(bd_id);
8632 /* Use a control ping for synchronization */
8634 vl_api_control_ping_t * mp;
8635 M(CONTROL_PING, control_ping);
8643 api_interface_name_renumber (vat_main_t * vam)
8645 unformat_input_t * line_input = vam->input;
8646 vl_api_interface_name_renumber_t *mp;
8647 u32 sw_if_index = ~0;
8649 u32 new_show_dev_instance = ~0;
8651 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) {
8652 if (unformat (line_input, "%U", unformat_sw_if_index, vam,
8655 else if (unformat (line_input, "sw_if_index %d", &sw_if_index))
8657 else if (unformat (line_input, "new_show_dev_instance %d",
8658 &new_show_dev_instance))
8664 if (sw_if_index == ~0) {
8665 errmsg ("missing interface name or sw_if_index\n");
8669 if (new_show_dev_instance == ~0) {
8670 errmsg ("missing new_show_dev_instance\n");
8674 M(INTERFACE_NAME_RENUMBER, interface_name_renumber);
8676 mp->sw_if_index = ntohl (sw_if_index);
8677 mp->new_show_dev_instance = ntohl (new_show_dev_instance);
8683 api_want_ip4_arp_events (vat_main_t * vam)
8685 unformat_input_t * line_input = vam->input;
8686 vl_api_want_ip4_arp_events_t * mp;
8688 ip4_address_t address;
8689 int address_set = 0;
8690 u32 enable_disable = 1;
8692 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) {
8693 if (unformat (line_input, "address %U",
8694 unformat_ip4_address, &address))
8696 else if (unformat (line_input, "del"))
8702 if (address_set == 0) {
8703 errmsg ("missing addresses\n");
8707 M(WANT_IP4_ARP_EVENTS, want_ip4_arp_events);
8708 mp->enable_disable = enable_disable;
8710 mp->address = address.as_u32;
8715 static int api_input_acl_set_interface (vat_main_t * vam)
8717 unformat_input_t * i = vam->input;
8718 vl_api_input_acl_set_interface_t *mp;
8721 int sw_if_index_set;
8722 u32 ip4_table_index = ~0;
8723 u32 ip6_table_index = ~0;
8724 u32 l2_table_index = ~0;
8727 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
8728 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
8729 sw_if_index_set = 1;
8730 else if (unformat (i, "sw_if_index %d", &sw_if_index))
8731 sw_if_index_set = 1;
8732 else if (unformat (i, "del"))
8734 else if (unformat (i, "ip4-table %d", &ip4_table_index))
8736 else if (unformat (i, "ip6-table %d", &ip6_table_index))
8738 else if (unformat (i, "l2-table %d", &l2_table_index))
8741 clib_warning ("parse error '%U'", format_unformat_error, i);
8746 if (sw_if_index_set == 0) {
8747 errmsg ("missing interface name or sw_if_index\n");
8751 M(INPUT_ACL_SET_INTERFACE, input_acl_set_interface);
8753 mp->sw_if_index = ntohl(sw_if_index);
8754 mp->ip4_table_index = ntohl(ip4_table_index);
8755 mp->ip6_table_index = ntohl(ip6_table_index);
8756 mp->l2_table_index = ntohl(l2_table_index);
8757 mp->is_add = is_add;
8765 api_ip_address_dump (vat_main_t * vam)
8767 unformat_input_t * i = vam->input;
8768 vl_api_ip_address_dump_t * mp;
8769 u32 sw_if_index = ~0;
8770 u8 sw_if_index_set = 0;
8775 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
8776 if (unformat (i, "sw_if_index %d", &sw_if_index))
8777 sw_if_index_set = 1;
8778 else if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
8779 sw_if_index_set = 1;
8780 else if (unformat (i, "ipv4"))
8782 else if (unformat (i, "ipv6"))
8788 if (ipv4_set && ipv6_set) {
8789 errmsg ("ipv4 and ipv6 flags cannot be both set\n");
8793 if ((!ipv4_set) && (!ipv6_set)) {
8794 errmsg ("no ipv4 nor ipv6 flag set\n");
8798 if (sw_if_index_set == 0) {
8799 errmsg ("missing interface name or sw_if_index\n");
8803 vam->current_sw_if_index = sw_if_index;
8804 vam->is_ipv6 = ipv6_set;
8806 M(IP_ADDRESS_DUMP, ip_address_dump);
8807 mp->sw_if_index = ntohl(sw_if_index);
8808 mp->is_ipv6 = ipv6_set;
8811 /* Use a control ping for synchronization */
8813 vl_api_control_ping_t * mp;
8814 M(CONTROL_PING, control_ping);
8821 api_ip_dump (vat_main_t * vam)
8823 vl_api_ip_dump_t * mp;
8824 unformat_input_t * in = vam->input;
8831 while (unformat_check_input (in) != UNFORMAT_END_OF_INPUT) {
8832 if (unformat (in, "ipv4"))
8834 else if (unformat (in, "ipv6"))
8840 if (ipv4_set && ipv6_set) {
8841 errmsg ("ipv4 and ipv6 flags cannot be both set\n");
8845 if ((!ipv4_set) && (!ipv6_set)) {
8846 errmsg ("no ipv4 nor ipv6 flag set\n");
8851 vam->is_ipv6 = is_ipv6;
8854 for (i = 0; i < vec_len(vam->ip_details_by_sw_if_index[is_ipv6]); i++) {
8855 vec_free(vam->ip_details_by_sw_if_index[is_ipv6][i].addr);
8857 vec_free(vam->ip_details_by_sw_if_index[is_ipv6]);
8859 M(IP_DUMP, ip_dump);
8860 mp->is_ipv6 = ipv6_set;
8863 /* Use a control ping for synchronization */
8865 vl_api_control_ping_t * mp;
8866 M(CONTROL_PING, control_ping);
8873 api_ipsec_spd_add_del (vat_main_t * vam)
8876 unformat_input_t * i = vam->input;
8877 vl_api_ipsec_spd_add_del_t *mp;
8882 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
8883 if (unformat (i, "spd_id %d", &spd_id))
8885 else if (unformat (i, "del"))
8888 clib_warning ("parse error '%U'", format_unformat_error, i);
8893 errmsg ("spd_id must be set\n");
8897 M(IPSEC_SPD_ADD_DEL, ipsec_spd_add_del);
8899 mp->spd_id = ntohl(spd_id);
8900 mp->is_add = is_add;
8906 clib_warning ("unsupported (no dpdk)");
8912 api_ipsec_interface_add_del_spd (vat_main_t * vam)
8915 unformat_input_t * i = vam->input;
8916 vl_api_ipsec_interface_add_del_spd_t *mp;
8919 u8 sw_if_index_set = 0;
8920 u32 spd_id = (u32) ~0;
8923 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
8924 if (unformat (i, "del"))
8926 else if (unformat (i, "spd_id %d", &spd_id))
8928 else if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
8929 sw_if_index_set = 1;
8930 else if (unformat (i, "sw_if_index %d", &sw_if_index))
8931 sw_if_index_set = 1;
8933 clib_warning ("parse error '%U'", format_unformat_error, i);
8939 if (spd_id == (u32) ~0) {
8940 errmsg ("spd_id must be set\n");
8944 if (sw_if_index_set == 0) {
8945 errmsg ("missing interface name or sw_if_index\n");
8949 M(IPSEC_INTERFACE_ADD_DEL_SPD, ipsec_interface_add_del_spd);
8951 mp->spd_id = ntohl(spd_id);
8952 mp->sw_if_index = ntohl (sw_if_index);
8953 mp->is_add = is_add;
8959 clib_warning ("unsupported (no dpdk)");
8965 api_ipsec_spd_add_del_entry (vat_main_t * vam)
8968 unformat_input_t * i = vam->input;
8969 vl_api_ipsec_spd_add_del_entry_t *mp;
8971 u8 is_add = 1, is_outbound = 0, is_ipv6 = 0, is_ip_any = 1;
8972 u32 spd_id, sa_id, protocol = 0, policy = 0;
8974 u32 rport_start = 0, rport_stop = (u32) ~0;
8975 u32 lport_start = 0, lport_stop = (u32) ~0;
8976 ip4_address_t laddr4_start, laddr4_stop, raddr4_start, raddr4_stop;
8977 ip6_address_t laddr6_start, laddr6_stop, raddr6_start, raddr6_stop;
8979 laddr4_start.as_u32 = raddr4_start.as_u32 = 0;
8980 laddr4_stop.as_u32 = raddr4_stop.as_u32 = (u32) ~0;
8981 laddr6_start.as_u64[0] = raddr6_start.as_u64[0] = 0;
8982 laddr6_start.as_u64[1] = raddr6_start.as_u64[1] = 0;
8983 laddr6_stop.as_u64[0] = raddr6_stop.as_u64[0] = (u64) ~0;
8984 laddr6_stop.as_u64[1] = raddr6_stop.as_u64[1] = (u64) ~0;
8986 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
8987 if (unformat (i, "del"))
8989 if (unformat (i, "outbound"))
8991 if (unformat (i, "inbound"))
8993 else if (unformat (i, "spd_id %d", &spd_id))
8995 else if (unformat (i, "sa_id %d", &sa_id))
8997 else if (unformat (i, "priority %d", &priority))
8999 else if (unformat (i, "protocol %d", &protocol))
9001 else if (unformat (i, "lport_start %d", &lport_start))
9003 else if (unformat (i, "lport_stop %d", &lport_stop))
9005 else if (unformat (i, "rport_start %d", &rport_start))
9007 else if (unformat (i, "rport_stop %d", &rport_stop))
9009 else if (unformat (i, "laddr_start %U", unformat_ip4_address, &laddr4_start))
9014 else if (unformat (i, "laddr_stop %U", unformat_ip4_address, &laddr4_stop))
9019 else if (unformat (i, "raddr_start %U", unformat_ip4_address, &raddr4_start))
9024 else if (unformat (i, "raddr_stop %U", unformat_ip4_address, &raddr4_stop))
9029 else if (unformat (i, "laddr_start %U", unformat_ip6_address, &laddr6_start))
9034 else if (unformat (i, "laddr_stop %U", unformat_ip6_address, &laddr6_stop))
9039 else if (unformat (i, "raddr_start %U", unformat_ip6_address, &raddr6_start))
9044 else if (unformat (i, "raddr_stop %U", unformat_ip6_address, &raddr6_stop))
9049 else if (unformat (i, "action %U", unformat_ipsec_policy_action, &policy))
9051 if (policy == IPSEC_POLICY_ACTION_RESOLVE) {
9052 clib_warning ("unsupported action: 'resolve'");
9057 clib_warning ("parse error '%U'", format_unformat_error, i);
9063 M(IPSEC_SPD_ADD_DEL_ENTRY, ipsec_spd_add_del_entry);
9065 mp->spd_id = ntohl(spd_id);
9066 mp->priority = ntohl(priority);
9067 mp->is_outbound = is_outbound;
9069 mp->is_ipv6 = is_ipv6;
9070 if (is_ipv6 || is_ip_any) {
9071 clib_memcpy (mp->remote_address_start, &raddr6_start, sizeof(ip6_address_t));
9072 clib_memcpy (mp->remote_address_stop, &raddr6_stop, sizeof(ip6_address_t));
9073 clib_memcpy (mp->local_address_start, &laddr6_start, sizeof(ip6_address_t));
9074 clib_memcpy (mp->local_address_stop, &laddr6_stop, sizeof(ip6_address_t));
9076 clib_memcpy (mp->remote_address_start, &raddr4_start, sizeof(ip4_address_t));
9077 clib_memcpy (mp->remote_address_stop, &raddr4_stop, sizeof(ip4_address_t));
9078 clib_memcpy (mp->local_address_start, &laddr4_start, sizeof(ip4_address_t));
9079 clib_memcpy (mp->local_address_stop, &laddr4_stop, sizeof(ip4_address_t));
9081 mp->protocol = (u8) protocol;
9082 mp->local_port_start = ntohs((u16) lport_start);
9083 mp->local_port_stop = ntohs((u16) lport_stop);
9084 mp->remote_port_start = ntohs((u16) rport_start);
9085 mp->remote_port_stop = ntohs((u16) rport_stop);
9086 mp->policy = (u8) policy;
9087 mp->sa_id = ntohl(sa_id);
9088 mp->is_add = is_add;
9089 mp->is_ip_any = is_ip_any;
9094 clib_warning ("unsupported (no dpdk)");
9100 api_ipsec_sad_add_del_entry (vat_main_t * vam)
9103 unformat_input_t * i = vam->input;
9104 vl_api_ipsec_sad_add_del_entry_t *mp;
9110 u8 protocol = IPSEC_PROTOCOL_AH;
9111 u8 is_tunnel = 0, is_tunnel_ipv6 = 0;
9112 u32 crypto_alg = 0, integ_alg = 0;
9113 ip4_address_t tun_src4;
9114 ip4_address_t tun_dst4;
9115 ip6_address_t tun_src6;
9116 ip6_address_t tun_dst6;
9118 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
9119 if (unformat (i, "del"))
9121 else if (unformat (i, "sad_id %d", &sad_id))
9123 else if (unformat (i, "spi %d", &spi))
9125 else if (unformat (i, "esp"))
9126 protocol = IPSEC_PROTOCOL_ESP;
9127 else if (unformat (i, "tunnel_src %U", unformat_ip4_address, &tun_src4)) {
9131 else if (unformat (i, "tunnel_dst %U", unformat_ip4_address, &tun_dst4)) {
9135 else if (unformat (i, "tunnel_src %U", unformat_ip6_address, &tun_src6)) {
9139 else if (unformat (i, "tunnel_dst %U", unformat_ip6_address, &tun_dst6)) {
9143 else if (unformat (i, "crypto_alg %U", unformat_ipsec_crypto_alg, &crypto_alg)) {
9144 if (crypto_alg < IPSEC_CRYPTO_ALG_AES_CBC_128 ||
9145 crypto_alg > IPSEC_INTEG_ALG_SHA_512_256) {
9146 clib_warning ("unsupported crypto-alg: '%U'",
9147 format_ipsec_crypto_alg, crypto_alg);
9151 else if (unformat (i, "crypto_key %U", unformat_hex_string, &ck))
9153 else if (unformat (i, "integ_alg %U", unformat_ipsec_integ_alg, &integ_alg)) {
9154 if (integ_alg < IPSEC_INTEG_ALG_SHA1_96 ||
9155 integ_alg > IPSEC_INTEG_ALG_SHA_512_256) {
9156 clib_warning ("unsupported integ-alg: '%U'",
9157 format_ipsec_integ_alg, integ_alg);
9161 else if (unformat (i, "integ_key %U", unformat_hex_string, &ik))
9164 clib_warning ("parse error '%U'", format_unformat_error, i);
9170 M(IPSEC_SAD_ADD_DEL_ENTRY, ipsec_sad_add_del_entry);
9172 mp->sad_id = ntohl(sad_id);
9173 mp->is_add = is_add;
9174 mp->protocol = protocol;
9175 mp->spi = ntohl(spi);
9176 mp->is_tunnel = is_tunnel;
9177 mp->is_tunnel_ipv6 = is_tunnel_ipv6;
9178 mp->crypto_algorithm = crypto_alg;
9179 mp->integrity_algorithm = integ_alg;
9180 mp->crypto_key_length = vec_len(ck);
9181 mp->integrity_key_length = vec_len(ik);
9183 if (mp->crypto_key_length > sizeof(mp->crypto_key))
9184 mp->crypto_key_length = sizeof(mp->crypto_key);
9186 if (mp->integrity_key_length > sizeof(mp->integrity_key))
9187 mp->integrity_key_length = sizeof(mp->integrity_key);
9189 clib_memcpy (mp->crypto_key, ck, mp->crypto_key_length);
9190 clib_memcpy (mp->integrity_key, ik, mp->integrity_key_length);
9193 if (is_tunnel_ipv6) {
9194 clib_memcpy (mp->tunnel_src_address, &tun_src6, sizeof(ip6_address_t));
9195 clib_memcpy (mp->tunnel_dst_address, &tun_dst6, sizeof(ip6_address_t));
9197 clib_memcpy (mp->tunnel_src_address, &tun_src4, sizeof(ip4_address_t));
9198 clib_memcpy (mp->tunnel_dst_address, &tun_dst4, sizeof(ip4_address_t));
9206 clib_warning ("unsupported (no dpdk)");
9212 api_ipsec_sa_set_key (vat_main_t * vam)
9215 unformat_input_t * i = vam->input;
9216 vl_api_ipsec_sa_set_key_t *mp;
9221 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
9222 if (unformat (i, "sa_id %d", &sa_id))
9224 else if (unformat (i, "crypto_key %U", unformat_hex_string, &ck))
9226 else if (unformat (i, "integ_key %U", unformat_hex_string, &ik))
9229 clib_warning ("parse error '%U'", format_unformat_error, i);
9234 M(IPSEC_SA_SET_KEY, ipsec_set_sa_key);
9236 mp->sa_id = ntohl(sa_id);
9237 mp->crypto_key_length = vec_len(ck);
9238 mp->integrity_key_length = vec_len(ik);
9240 if (mp->crypto_key_length > sizeof(mp->crypto_key))
9241 mp->crypto_key_length = sizeof(mp->crypto_key);
9243 if (mp->integrity_key_length > sizeof(mp->integrity_key))
9244 mp->integrity_key_length = sizeof(mp->integrity_key);
9246 clib_memcpy (mp->crypto_key, ck, mp->crypto_key_length);
9247 clib_memcpy (mp->integrity_key, ik, mp->integrity_key_length);
9253 clib_warning ("unsupported (no dpdk)");
9259 api_ikev2_profile_add_del (vat_main_t * vam)
9262 unformat_input_t * i = vam->input;
9263 vl_api_ikev2_profile_add_del_t * mp;
9268 const char * valid_chars = "a-zA-Z0-9_";
9270 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
9271 if (unformat (i, "del"))
9273 else if (unformat (i, "name %U", unformat_token, valid_chars, &name))
9276 errmsg ("parse error '%U'", format_unformat_error, i);
9281 if (!vec_len (name)) {
9282 errmsg ("profile name must be specified");
9286 if (vec_len (name) > 64) {
9287 errmsg ("profile name too long");
9291 M(IKEV2_PROFILE_ADD_DEL, ikev2_profile_add_del);
9293 clib_memcpy(mp->name, name, vec_len (name));
9294 mp->is_add = is_add;
9301 clib_warning ("unsupported (no dpdk)");
9307 api_ikev2_profile_set_auth (vat_main_t * vam)
9310 unformat_input_t * i = vam->input;
9311 vl_api_ikev2_profile_set_auth_t * mp;
9315 u32 auth_method = 0;
9318 const char * valid_chars = "a-zA-Z0-9_";
9320 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
9321 if (unformat (i, "name %U", unformat_token, valid_chars, &name))
9323 else if (unformat (i, "auth_method %U",
9324 unformat_ikev2_auth_method, &auth_method))
9326 else if (unformat (i, "auth_data 0x%U", unformat_hex_string, &data))
9328 else if (unformat (i, "auth_data %v", &data))
9331 errmsg ("parse error '%U'", format_unformat_error, i);
9336 if (!vec_len (name)) {
9337 errmsg ("profile name must be specified");
9341 if (vec_len (name) > 64) {
9342 errmsg ("profile name too long");
9346 if (!vec_len(data)) {
9347 errmsg ("auth_data must be specified");
9352 errmsg ("auth_method must be specified");
9356 M(IKEV2_PROFILE_SET_AUTH, ikev2_profile_set_auth);
9358 mp->is_hex = is_hex;
9359 mp->auth_method = (u8) auth_method;
9360 mp->data_len = vec_len (data);
9361 clib_memcpy (mp->name, name, vec_len (name));
9362 clib_memcpy (mp->data, data, vec_len (data));
9370 clib_warning ("unsupported (no dpdk)");
9376 api_ikev2_profile_set_id (vat_main_t * vam)
9379 unformat_input_t * i = vam->input;
9380 vl_api_ikev2_profile_set_id_t * mp;
9388 const char * valid_chars = "a-zA-Z0-9_";
9390 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
9391 if (unformat (i, "name %U", unformat_token, valid_chars, &name))
9393 else if (unformat (i, "id_type %U",
9394 unformat_ikev2_id_type, &id_type))
9396 else if (unformat (i, "id_data %U", unformat_ip4_address, &ip4))
9398 data = vec_new(u8, 4);
9399 clib_memcpy(data, ip4.as_u8, 4);
9401 else if (unformat (i, "id_data 0x%U", unformat_hex_string, &data))
9403 else if (unformat (i, "id_data %v", &data))
9405 else if (unformat (i, "local"))
9407 else if (unformat (i, "remote"))
9410 errmsg ("parse error '%U'", format_unformat_error, i);
9415 if (!vec_len (name)) {
9416 errmsg ("profile name must be specified");
9420 if (vec_len (name) > 64) {
9421 errmsg ("profile name too long");
9425 if (!vec_len(data)) {
9426 errmsg ("id_data must be specified");
9431 errmsg ("id_type must be specified");
9435 M(IKEV2_PROFILE_SET_ID, ikev2_profile_set_id);
9437 mp->is_local = is_local;
9438 mp->id_type = (u8) id_type;
9439 mp->data_len = vec_len (data);
9440 clib_memcpy (mp->name, name, vec_len (name));
9441 clib_memcpy (mp->data, data, vec_len (data));
9449 clib_warning ("unsupported (no dpdk)");
9455 api_ikev2_profile_set_ts (vat_main_t * vam)
9458 unformat_input_t * i = vam->input;
9459 vl_api_ikev2_profile_set_ts_t * mp;
9463 u32 proto = 0, start_port = 0, end_port = (u32) ~0;
9464 ip4_address_t start_addr, end_addr;
9466 const char * valid_chars = "a-zA-Z0-9_";
9468 start_addr.as_u32 = 0;
9469 end_addr.as_u32 = (u32) ~0;
9471 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
9472 if (unformat (i, "name %U", unformat_token, valid_chars, &name))
9474 else if (unformat (i, "protocol %d", &proto))
9476 else if (unformat (i, "start_port %d", &start_port))
9478 else if (unformat (i, "end_port %d", &end_port))
9480 else if (unformat (i, "start_addr %U", unformat_ip4_address, &start_addr))
9482 else if (unformat (i, "end_addr %U", unformat_ip4_address, &end_addr))
9484 else if (unformat (i, "local"))
9486 else if (unformat (i, "remote"))
9489 errmsg ("parse error '%U'", format_unformat_error, i);
9494 if (!vec_len (name)) {
9495 errmsg ("profile name must be specified");
9499 if (vec_len (name) > 64) {
9500 errmsg ("profile name too long");
9504 M(IKEV2_PROFILE_SET_TS, ikev2_profile_set_ts);
9506 mp->is_local = is_local;
9507 mp->proto = (u8) proto;
9508 mp->start_port = (u16) start_port;
9509 mp->end_port = (u16) end_port;
9510 mp->start_addr = start_addr.as_u32;
9511 mp->end_addr = end_addr.as_u32;
9512 clib_memcpy (mp->name, name, vec_len (name));
9519 clib_warning ("unsupported (no dpdk)");
9525 api_ikev2_set_local_key (vat_main_t * vam)
9528 unformat_input_t * i = vam->input;
9529 vl_api_ikev2_set_local_key_t * mp;
9533 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
9534 if (unformat (i, "file %v", &file))
9537 errmsg ("parse error '%U'", format_unformat_error, i);
9542 if (!vec_len (file)) {
9543 errmsg ("RSA key file must be specified");
9547 if (vec_len (file) > 256) {
9548 errmsg ("file name too long");
9552 M(IKEV2_SET_LOCAL_KEY, ikev2_set_local_key);
9554 clib_memcpy (mp->key_file, file, vec_len (file));
9561 clib_warning ("unsupported (no dpdk)");
9569 static int api_map_add_domain (vat_main_t * vam)
9571 unformat_input_t *i = vam->input;
9572 vl_api_map_add_domain_t *mp;
9575 ip4_address_t ip4_prefix;
9576 ip6_address_t ip6_prefix;
9577 ip6_address_t ip6_src;
9579 u32 ip6_prefix_len, ip4_prefix_len, ea_bits_len, psid_offset,
9581 u8 is_translation = 0;
9583 u8 ip6_src_len = 128;
9585 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
9586 if (unformat (i, "ip4-pfx %U/%d", unformat_ip4_address,
9587 &ip4_prefix, &ip4_prefix_len))
9589 else if (unformat (i, "ip6-pfx %U/%d", unformat_ip6_address,
9590 &ip6_prefix, &ip6_prefix_len))
9592 else if (unformat (i, "ip6-src %U/%d", unformat_ip6_address, &ip6_src, &ip6_src_len))
9594 else if (unformat (i, "ip6-src %U", unformat_ip6_address, &ip6_src))
9596 else if (unformat (i, "ea-bits-len %d", &ea_bits_len))
9598 else if (unformat (i, "psid-offset %d", &psid_offset))
9600 else if (unformat (i, "psid-len %d", &psid_length))
9602 else if (unformat (i, "mtu %d", &mtu))
9604 else if (unformat (i, "map-t"))
9607 clib_warning ("parse error '%U'", format_unformat_error, i);
9612 if (num_m_args != 6) {
9613 errmsg("mandatory argument(s) missing\n");
9617 /* Construct the API message */
9618 M(MAP_ADD_DOMAIN, map_add_domain);
9620 clib_memcpy(mp->ip4_prefix, &ip4_prefix, sizeof(ip4_prefix));
9621 mp->ip4_prefix_len = ip4_prefix_len;
9623 clib_memcpy(mp->ip6_prefix, &ip6_prefix, sizeof(ip6_prefix));
9624 mp->ip6_prefix_len = ip6_prefix_len;
9626 clib_memcpy(mp->ip6_src, &ip6_src, sizeof(ip6_src));
9627 mp->ip6_src_prefix_len = ip6_src_len;
9629 mp->ea_bits_len = ea_bits_len;
9630 mp->psid_offset = psid_offset;
9631 mp->psid_length = psid_length;
9632 mp->is_translation = is_translation;
9633 mp->mtu = htons(mtu);
9638 /* Wait for a reply, return good/bad news */
9642 static int api_map_del_domain (vat_main_t * vam)
9644 unformat_input_t *i = vam->input;
9645 vl_api_map_del_domain_t *mp;
9651 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
9652 if (unformat (i, "index %d", &index))
9655 clib_warning ("parse error '%U'", format_unformat_error, i);
9660 if (num_m_args != 1) {
9661 errmsg("mandatory argument(s) missing\n");
9665 /* Construct the API message */
9666 M(MAP_DEL_DOMAIN, map_del_domain);
9668 mp->index = ntohl(index);
9673 /* Wait for a reply, return good/bad news */
9677 static int api_map_add_del_rule (vat_main_t * vam)
9679 unformat_input_t *i = vam->input;
9680 vl_api_map_add_del_rule_t *mp;
9683 ip6_address_t ip6_dst;
9684 u32 num_m_args = 0, index, psid;
9686 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
9687 if (unformat (i, "index %d", &index))
9689 else if (unformat (i, "psid %d", &psid))
9691 else if (unformat (i, "dst %U", unformat_ip6_address, &ip6_dst))
9693 else if (unformat (i, "del")) {
9696 clib_warning ("parse error '%U'", format_unformat_error, i);
9701 /* Construct the API message */
9702 M(MAP_ADD_DEL_RULE, map_add_del_rule);
9704 mp->index = ntohl(index);
9705 mp->is_add = is_add;
9706 clib_memcpy(mp->ip6_dst, &ip6_dst, sizeof(ip6_dst));
9707 mp->psid = ntohs(psid);
9712 /* Wait for a reply, return good/bad news */
9716 static int api_map_domain_dump (vat_main_t * vam)
9718 vl_api_map_domain_dump_t *mp;
9721 /* Construct the API message */
9722 M(MAP_DOMAIN_DUMP, map_domain_dump);
9727 /* Use a control ping for synchronization */
9729 vl_api_control_ping_t * mp;
9730 M(CONTROL_PING, control_ping);
9736 static int api_map_rule_dump (vat_main_t * vam)
9738 unformat_input_t *i = vam->input;
9739 vl_api_map_rule_dump_t *mp;
9741 u32 domain_index = ~0;
9743 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
9744 if (unformat (i, "index %u", &domain_index))
9750 if (domain_index == ~0) {
9751 clib_warning("parse error: domain index expected");
9755 /* Construct the API message */
9756 M(MAP_RULE_DUMP, map_rule_dump);
9758 mp->domain_index = htonl(domain_index);
9763 /* Use a control ping for synchronization */
9765 vl_api_control_ping_t * mp;
9766 M(CONTROL_PING, control_ping);
9772 static void vl_api_map_add_domain_reply_t_handler
9773 (vl_api_map_add_domain_reply_t * mp)
9775 vat_main_t * vam = &vat_main;
9776 i32 retval = ntohl(mp->retval);
9778 if (vam->async_mode) {
9779 vam->async_errors += (retval < 0);
9781 vam->retval = retval;
9782 vam->result_ready = 1;
9786 static void vl_api_map_add_domain_reply_t_handler_json
9787 (vl_api_map_add_domain_reply_t * mp)
9789 vat_main_t * vam = &vat_main;
9790 vat_json_node_t node;
9792 vat_json_init_object(&node);
9793 vat_json_object_add_int(&node, "retval", ntohl(mp->retval));
9794 vat_json_object_add_uint(&node, "index", ntohl(mp->index));
9796 vat_json_print(vam->ofp, &node);
9797 vat_json_free(&node);
9799 vam->retval = ntohl(mp->retval);
9800 vam->result_ready = 1;
9804 api_get_first_msg_id (vat_main_t * vam)
9806 vl_api_get_first_msg_id_t * mp;
9808 unformat_input_t * i = vam->input;
9812 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
9813 if (unformat (i, "client %s", &name))
9819 if (name_set == 0) {
9820 errmsg ("missing client name\n");
9825 if (vec_len (name) > 63) {
9826 errmsg ("client name too long\n");
9830 M(GET_FIRST_MSG_ID, get_first_msg_id);
9831 clib_memcpy (mp->name, name, vec_len(name));
9837 static int api_cop_interface_enable_disable (vat_main_t * vam)
9839 unformat_input_t * line_input = vam->input;
9840 vl_api_cop_interface_enable_disable_t * mp;
9842 u32 sw_if_index = ~0;
9843 u8 enable_disable = 1;
9845 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) {
9846 if (unformat (line_input, "disable"))
9848 if (unformat (line_input, "enable"))
9850 else if (unformat (line_input, "%U", unformat_sw_if_index,
9853 else if (unformat (line_input, "sw_if_index %d", &sw_if_index))
9859 if (sw_if_index == ~0) {
9860 errmsg ("missing interface name or sw_if_index\n");
9864 /* Construct the API message */
9865 M(COP_INTERFACE_ENABLE_DISABLE, cop_interface_enable_disable);
9866 mp->sw_if_index = ntohl(sw_if_index);
9867 mp->enable_disable = enable_disable;
9871 /* Wait for the reply */
9875 static int api_cop_whitelist_enable_disable (vat_main_t * vam)
9877 unformat_input_t * line_input = vam->input;
9878 vl_api_cop_whitelist_enable_disable_t * mp;
9880 u32 sw_if_index = ~0;
9881 u8 ip4=0, ip6=0, default_cop=0;
9884 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) {
9885 if (unformat (line_input, "ip4"))
9887 else if (unformat (line_input, "ip6"))
9889 else if (unformat (line_input, "default"))
9891 else if (unformat (line_input, "%U", unformat_sw_if_index,
9894 else if (unformat (line_input, "sw_if_index %d", &sw_if_index))
9896 else if (unformat (line_input, "fib-id %d", &fib_id))
9902 if (sw_if_index == ~0) {
9903 errmsg ("missing interface name or sw_if_index\n");
9907 /* Construct the API message */
9908 M(COP_WHITELIST_ENABLE_DISABLE, cop_whitelist_enable_disable);
9909 mp->sw_if_index = ntohl(sw_if_index);
9910 mp->fib_id = ntohl(fib_id);
9913 mp->default_cop = default_cop;
9917 /* Wait for the reply */
9921 static int api_get_node_graph (vat_main_t * vam)
9923 vl_api_get_node_graph_t * mp;
9926 M(GET_NODE_GRAPH, get_node_graph);
9930 /* Wait for the reply */
9935 api_lisp_add_del_locator_set(vat_main_t * vam)
9937 unformat_input_t * input = vam->input;
9938 vl_api_lisp_add_del_locator_set_t *mp;
9941 u8 *locator_set_name = NULL;
9942 u8 locator_set_name_set = 0;
9944 /* Parse args required to build the message */
9945 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) {
9946 if (unformat(input, "del")) {
9948 } else if (unformat(input, "locator-set %s", &locator_set_name)) {
9949 locator_set_name_set = 1;
9954 if (locator_set_name_set == 0) {
9955 errmsg ("missing locator-set name");
9959 if (vec_len(locator_set_name) > 64) {
9960 errmsg ("locator-set name too long\n");
9961 vec_free(locator_set_name);
9964 vec_add1(locator_set_name, 0);
9966 /* Construct the API message */
9967 M(LISP_ADD_DEL_LOCATOR_SET, lisp_add_del_locator_set);
9969 mp->is_add = is_add;
9970 clib_memcpy(mp->locator_set_name, locator_set_name,
9971 vec_len(locator_set_name));
9972 vec_free(locator_set_name);
9977 /* Wait for a reply... */
9985 api_lisp_add_del_locator(vat_main_t * vam)
9987 unformat_input_t * input = vam->input;
9988 vl_api_lisp_add_del_locator_t *mp;
9990 u32 tmp_if_index = ~0;
9991 u32 sw_if_index = ~0;
9992 u8 sw_if_index_set = 0;
9993 u8 sw_if_index_if_name_set = 0;
9995 u8 priority_set = 0;
9999 u8 *locator_set_name = NULL;
10000 u8 locator_set_name_set = 0;
10002 /* Parse args required to build the message */
10003 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) {
10004 if (unformat(input, "del")) {
10006 } else if (unformat(input, "locator-set %s", &locator_set_name)) {
10007 locator_set_name_set = 1;
10008 } else if (unformat(input, "iface %U", unformat_sw_if_index, vam,
10010 sw_if_index_if_name_set = 1;
10011 sw_if_index = tmp_if_index;
10012 } else if (unformat(input,"sw_if_index %d", &tmp_if_index)) {
10013 sw_if_index_set = 1;
10014 sw_if_index = tmp_if_index;
10015 } else if (unformat(input, "p %d", &priority)) {
10017 } else if (unformat(input, "w %d", &weight)) {
10023 if (locator_set_name_set == 0) {
10024 errmsg ("missing locator-set name");
10028 if (sw_if_index_set == 0 && sw_if_index_if_name_set == 0) {
10029 errmsg ("missing sw_if_index");
10030 vec_free(locator_set_name);
10034 if (sw_if_index_set != 0 && sw_if_index_if_name_set != 0) {
10035 errmsg ("cannot use both params interface name and sw_if_index");
10036 vec_free(locator_set_name);
10040 if (priority_set == 0) {
10041 errmsg ("missing locator-set priority\n");
10042 vec_free(locator_set_name);
10046 if (weight_set == 0) {
10047 errmsg ("missing locator-set weight\n");
10048 vec_free(locator_set_name);
10052 if (vec_len(locator_set_name) > 64) {
10053 errmsg ("locator-set name too long\n");
10054 vec_free(locator_set_name);
10057 vec_add1(locator_set_name, 0);
10059 /* Construct the API message */
10060 M(LISP_ADD_DEL_LOCATOR, lisp_add_del_locator);
10062 mp->is_add = is_add;
10063 mp->sw_if_index = ntohl(sw_if_index);
10064 mp->priority = priority;
10065 mp->weight = weight;
10066 clib_memcpy(mp->locator_set_name, locator_set_name,
10067 vec_len(locator_set_name));
10068 vec_free(locator_set_name);
10073 /* Wait for a reply... */
10081 api_lisp_add_del_local_eid(vat_main_t * vam)
10083 unformat_input_t * input = vam->input;
10084 vl_api_lisp_add_del_local_eid_t *mp;
10089 ip4_address_t eidv4;
10090 ip6_address_t eidv6;
10091 u8 tmp_eid_lenght = ~0;
10092 u8 eid_lenght = ~0;
10093 u8 *locator_set_name = NULL;
10094 u8 locator_set_name_set = 0;
10097 /* Parse args required to build the message */
10098 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) {
10099 if (unformat(input, "del")) {
10101 } else if (unformat(input, "vni &d", &vni)) {
10103 } else if (unformat(input, "eid %U/%d", unformat_ip4_address,
10104 &eidv4, &tmp_eid_lenght)) {
10105 eid_lenght = tmp_eid_lenght;
10107 } else if (unformat(input, "eid %U/%d", unformat_ip6_address,
10108 &eidv6, &tmp_eid_lenght)) {
10109 eid_lenght = tmp_eid_lenght;
10111 } else if (unformat(input, "locator-set %s", &locator_set_name)) {
10112 locator_set_name_set = 1;
10117 if (locator_set_name_set == 0) {
10118 errmsg ("missing locator-set name\n");
10122 if (vec_len(locator_set_name) > 64) {
10123 errmsg ("locator-set name too long\n");
10124 vec_free(locator_set_name);
10127 vec_add1(locator_set_name, 0);
10129 if (eidv4_set && eidv6_set) {
10130 errmsg ("both eid v4 and v6 addresses set\n");
10131 vec_free(locator_set_name);
10135 if (!eidv4_set && !eidv6_set) {
10136 errmsg ("eid addresses not set\n");
10137 vec_free(locator_set_name);
10141 if (eidv4_set && eid_lenght > 32) {
10142 errmsg ("eid prefix to big\n");
10143 vec_free(locator_set_name);
10147 if (eidv6_set && eid_lenght > 128) {
10148 errmsg ("eid prefix to big\n");
10149 vec_free(locator_set_name);
10153 /* Construct the API message */
10154 M(LISP_ADD_DEL_LOCAL_EID, lisp_add_del_local_eid);
10156 mp->is_add = is_add;
10159 clib_memcpy(mp->ip_address, &eidv6, sizeof(eidv6));
10162 clib_memcpy(mp->ip_address, &eidv4, sizeof(eidv4));
10164 mp->prefix_len = eid_lenght;
10165 mp->vni = clib_host_to_net_u32(vni);
10166 clib_memcpy(mp->locator_set_name, locator_set_name,
10167 vec_len(locator_set_name));
10168 vec_free(locator_set_name);
10173 /* Wait for a reply... */
10181 api_lisp_gpe_add_del_fwd_entry(vat_main_t * vam)
10183 unformat_input_t * input = vam->input;
10184 vl_api_lisp_gpe_add_del_fwd_entry_t *mp;
10187 u8 eidv4_set = 0, slocv4_set = 0, dlocv4_set = 0;
10188 u8 eidv6_set = 0, slocv6_set = 0, dlocv6_set = 0;
10189 ip4_address_t eidv4, slocv4, dlocv4;
10190 ip6_address_t eidv6, slocv6, dlocv6;
10191 u8 tmp_eid_lenght = ~0;
10192 u8 eid_lenght = ~0;
10194 /* Parse args required to build the message */
10195 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) {
10196 if (unformat(input, "del")) {
10198 } else if (unformat(input, "eid %U/%d", unformat_ip4_address,
10199 &eidv4, &tmp_eid_lenght)) {
10200 eid_lenght = tmp_eid_lenght;
10202 } else if (unformat(input, "eid %U/%d", unformat_ip6_address,
10203 &eidv6, &tmp_eid_lenght)) {
10204 eid_lenght = tmp_eid_lenght;
10206 } else if (unformat(input, "sloc %U", unformat_ip4_address, &slocv4)) {
10208 } else if (unformat(input, "sloc %U", unformat_ip6_address, &slocv6)) {
10210 } else if (unformat(input, "dloc %U", unformat_ip4_address, &dlocv4)) {
10212 } else if (unformat(input, "dloc %U", unformat_ip6_address, &dlocv6)) {
10218 if (eidv4_set && eidv6_set) {
10219 errmsg ("both eid v4 and v6 addresses set\n");
10223 if (!eidv4_set && !eidv6_set) {
10224 errmsg ("eid addresses not set\n");
10228 if (slocv4_set && slocv6_set) {
10229 errmsg ("both source v4 and v6 addresses set\n");
10233 if (!slocv4_set && !slocv6_set) {
10234 errmsg ("source addresses not set\n");
10238 if (dlocv4_set && dlocv6_set) {
10239 errmsg ("both destination v4 and v6 addresses set\n");
10243 if (dlocv4_set && dlocv6_set) {
10244 errmsg ("destination addresses not set\n");
10248 if (!(slocv4_set == dlocv4_set && slocv6_set == dlocv6_set)) {
10249 errmsg ("mixing type of source and destination address\n");
10253 /* Construct the API message */
10254 M(LISP_GPE_ADD_DEL_FWD_ENTRY, lisp_gpe_add_del_fwd_entry);
10256 mp->is_add = is_add;
10258 mp->eid_is_ipv6 = 1;
10259 clib_memcpy(mp->eid_ip_address, &eidv6, sizeof(eidv6));
10261 mp->eid_is_ipv6 = 0;
10262 clib_memcpy(mp->eid_ip_address, &eidv4, sizeof(eidv4));
10264 mp->eid_prefix_len = eid_lenght;
10266 mp->address_is_ipv6 = 1;
10267 clib_memcpy(mp->source_ip_address, &slocv6, sizeof(slocv6));
10268 clib_memcpy(mp->destination_ip_address, &dlocv6, sizeof(dlocv6));
10270 mp->address_is_ipv6 = 0;
10271 clib_memcpy(mp->source_ip_address, &slocv4, sizeof(slocv4));
10272 clib_memcpy(mp->destination_ip_address, &dlocv4, sizeof(dlocv4));
10278 /* Wait for a reply... */
10286 api_lisp_add_del_map_resolver(vat_main_t * vam)
10288 unformat_input_t * input = vam->input;
10289 vl_api_lisp_add_del_map_resolver_t *mp;
10294 ip4_address_t ipv4;
10295 ip6_address_t ipv6;
10297 /* Parse args required to build the message */
10298 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) {
10299 if (unformat(input, "del")) {
10301 } else if (unformat(input, "%U", unformat_ip4_address, &ipv4)) {
10303 } else if (unformat(input, "%U", unformat_ip6_address, &ipv6)) {
10309 if (ipv4_set && ipv6_set) {
10310 errmsg ("both eid v4 and v6 addresses set\n");
10314 if (!ipv4_set && !ipv6_set) {
10315 errmsg ("eid addresses not set\n");
10319 /* Construct the API message */
10320 M(LISP_ADD_DEL_MAP_RESOLVER, lisp_add_del_map_resolver);
10322 mp->is_add = is_add;
10325 clib_memcpy(mp->ip_address, &ipv6, sizeof(ipv6));
10328 clib_memcpy(mp->ip_address, &ipv4, sizeof(ipv4));
10334 /* Wait for a reply... */
10342 api_lisp_gpe_enable_disable (vat_main_t * vam)
10344 unformat_input_t * input = vam->input;
10345 vl_api_lisp_gpe_enable_disable_t *mp;
10350 /* Parse args required to build the message */
10351 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) {
10352 if (unformat(input, "enable")) {
10355 } else if (unformat(input, "disable")) {
10363 errmsg("Value not set\n");
10367 /* Construct the API message */
10368 M(LISP_GPE_ENABLE_DISABLE, lisp_gpe_enable_disable);
10375 /* Wait for a reply... */
10383 api_lisp_enable_disable (vat_main_t * vam)
10385 unformat_input_t * input = vam->input;
10386 vl_api_lisp_enable_disable_t *mp;
10391 /* Parse args required to build the message */
10392 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
10394 if (unformat (input, "enable"))
10399 else if (unformat (input, "disable"))
10409 errmsg ("Value not set\n");
10413 /* Construct the API message */
10414 M(LISP_ENABLE_DISABLE, lisp_enable_disable);
10421 /* Wait for a reply... */
10428 /** Used for transferring locators via VPP API */
10429 typedef CLIB_PACKED(struct
10431 u8 is_ip4; /**< is locator an IPv4 address? */
10432 u8 addr[16]; /**< IPv4/IPv6 address */
10436 * Enable/disable LISP proxy ITR.
10438 * @param vam vpp API test context
10439 * @return return code
10442 api_lisp_pitr_set_locator_set (vat_main_t * vam)
10445 u8 ls_name_set = 0;
10446 unformat_input_t * input = vam->input;
10447 vl_api_lisp_pitr_set_locator_set_t * mp;
10451 /* Parse args required to build the message */
10452 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
10454 if (unformat (input, "del"))
10456 else if (unformat (input, "locator-set %s", &ls_name))
10460 errmsg ("parse error '%U'", format_unformat_error, input);
10467 errmsg ("locator-set name not set!");
10471 M(LISP_PITR_SET_LOCATOR_SET, lisp_pitr_set_locator_set);
10473 mp->is_add = is_add;
10474 clib_memcpy (mp->ls_name, ls_name, vec_len (ls_name));
10475 vec_free (ls_name);
10480 /* wait for reply */
10488 * Add/delete mapping between vni and vrf
10491 api_lisp_eid_table_add_del_map (vat_main_t * vam)
10494 unformat_input_t * input = vam->input;
10495 vl_api_lisp_eid_table_add_del_map_t *mp;
10496 u8 is_add = 1, vni_set = 0, vrf_set = 0;
10499 /* Parse args required to build the message */
10500 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
10502 if (unformat (input, "del"))
10504 else if (unformat(input, "vrf %d", &vrf))
10506 else if (unformat(input, "vni %d", &vni))
10512 if (!vni_set || !vrf_set)
10514 errmsg ("missing arguments!");
10518 M(LISP_EID_TABLE_ADD_DEL_MAP, lisp_eid_table_add_del_map);
10520 mp->is_add = is_add;
10521 mp->vni = htonl (vni);
10522 mp->vrf = htonl (vrf);
10527 /* wait for reply */
10535 * Add/del remote mapping from LISP control plane and updates
10536 * forwarding entries in data-plane accordingly.
10538 * @param vam vpp API test context
10539 * @return return code
10542 api_lisp_add_del_remote_mapping (vat_main_t * vam)
10544 unformat_input_t * input = vam->input;
10545 vl_api_lisp_add_del_remote_mapping_t *mp;
10548 u8 seid_set = 0, deid_set = 0;
10549 ip4_address_t seid4, deid4, rloc4;
10550 ip6_address_t seid6, deid6, rloc6;
10551 u32 seid_len = 0, deid_len = 0, len;
10552 u8 deid_is_ip4 = 0, seid_is_ip4 = 0;
10553 u8 is_add = 1, del_all = 0;
10555 rloc_t * rlocs = 0, rloc;
10557 /* Parse args required to build the message */
10558 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) {
10559 if (unformat(input, "del-all")) {
10561 } else if (unformat(input, "del")) {
10563 } else if (unformat(input, "add")) {
10565 } else if (unformat(input, "deid %U/%d", unformat_ip4_address,
10570 } else if (unformat(input, "deid %U/%d", unformat_ip6_address,
10575 } else if (unformat(input, "seid %U/%d", unformat_ip4_address,
10580 } else if (unformat(input, "seid %U/%d", unformat_ip6_address,
10585 } else if (unformat(input, "vni %d", &vni)) {
10587 } else if (unformat(input, "rloc %U", unformat_ip4_address, &rloc4)) {
10589 clib_memcpy (&rloc.addr, &rloc4, sizeof (rloc4));
10590 vec_add1 (rlocs, rloc);
10591 } else if (unformat(input, "rloc %U", unformat_ip6_address, &rloc6)) {
10593 clib_memcpy (&rloc.addr, &rloc6, sizeof (rloc6));
10594 vec_add1 (rlocs, rloc);
10595 } else if (unformat(input, "action %d", &action)) {
10598 clib_warning ("parse error '%U'", format_unformat_error, input);
10603 if (!seid_set || !deid_set) {
10604 errmsg ("missing params!");
10608 if (seid_is_ip4 != deid_is_ip4) {
10609 errmsg ("source and destination EIDs are not in " "same IP family!");
10613 if (is_add && (~0 == action)
10614 && 0 == vec_len (rlocs)) {
10615 errmsg ("no action set for negative map-reply!");
10619 M(LISP_ADD_DEL_REMOTE_MAPPING, lisp_add_del_remote_mapping);
10620 mp->is_add = is_add;
10621 mp->vni = htonl (vni);
10622 mp->seid_len = seid_len;
10623 mp->action = (u8) action;
10624 mp->deid_len = deid_len;
10625 mp->del_all = del_all;
10627 mp->eid_is_ip4 = 1;
10628 clib_memcpy (mp->seid, &seid4, sizeof (seid4));
10630 mp->eid_is_ip4 = 0;
10631 clib_memcpy (mp->seid, &seid6, sizeof (seid6));
10635 mp->eid_is_ip4 = 1;
10636 clib_memcpy (mp->deid, &deid4, sizeof (deid4));
10638 mp->eid_is_ip4 = 0;
10639 clib_memcpy (mp->deid, &deid6, sizeof (deid6));
10642 mp->rloc_num = vec_len (rlocs);
10643 clib_memcpy (mp->rlocs, rlocs, (sizeof (rloc_t) * vec_len (rlocs)));
10649 /* Wait for a reply... */
10657 api_lisp_gpe_add_del_iface(vat_main_t * vam)
10659 unformat_input_t * input = vam->input;
10660 vl_api_lisp_gpe_add_del_iface_t *mp;
10666 /* Parse args required to build the message */
10667 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) {
10668 if (unformat(input, "up")) {
10671 } else if (unformat(input, "down")) {
10674 } else if (unformat(input, "table_id %d", &table_id)) {
10676 } else if (unformat(input, "vni %d", &vni)) {
10683 errmsg("Value not set\n");
10687 /* Construct the API message */
10688 M(LISP_GPE_ADD_DEL_IFACE, lisp_gpe_add_del_iface);
10690 mp->is_add = is_add;
10691 mp->table_id = table_id;
10697 /* Wait for a reply... */
10705 * Add/del map request itr rlocs from LISP control plane and updates
10707 * @param vam vpp API test context
10708 * @return return code
10711 api_lisp_add_del_map_request_itr_rlocs(vat_main_t * vam)
10713 unformat_input_t * input = vam->input;
10714 vl_api_lisp_add_del_map_request_itr_rlocs_t *mp;
10716 u8 *locator_set_name = 0;
10717 u8 locator_set_name_set = 0;
10720 /* Parse args required to build the message */
10721 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) {
10722 if (unformat(input, "del")) {
10724 } else if (unformat(input, "%_%v%_", &locator_set_name)) {
10725 locator_set_name_set = 1;
10727 clib_warning ("parse error '%U'", format_unformat_error, input);
10732 if (is_add && !locator_set_name_set) {
10733 errmsg ("itr-rloc is not set!");
10737 if (is_add && vec_len(locator_set_name) > 64) {
10738 errmsg ("itr-rloc locator-set name too long\n");
10739 vec_free(locator_set_name);
10743 M(LISP_ADD_DEL_MAP_REQUEST_ITR_RLOCS, lisp_add_del_map_request_itr_rlocs);
10744 mp->is_add = is_add;
10746 clib_memcpy (mp->locator_set_name , locator_set_name,
10747 vec_len(locator_set_name));
10749 memset(mp->locator_set_name, 0, sizeof(mp->locator_set_name));
10751 vec_free (locator_set_name);
10756 /* Wait for a reply... */
10764 api_lisp_locator_set_dump(vat_main_t *vam)
10766 vl_api_lisp_locator_set_dump_t *mp;
10769 if (!vam->json_output) {
10770 fformat(vam->ofp, "%=20s%=16s%=16s%=16s\n",
10771 "Locator-set", "Locator", "Priority", "Weight");
10774 M(LISP_LOCATOR_SET_DUMP, lisp_locator_set_dump);
10778 /* Use a control ping for synchronization */
10780 vl_api_control_ping_t * mp;
10781 M(CONTROL_PING, control_ping);
10784 /* Wait for a reply... */
10792 api_lisp_local_eid_table_dump(vat_main_t *vam)
10794 vl_api_lisp_local_eid_table_dump_t *mp;
10797 if (!vam->json_output) {
10798 fformat(vam->ofp, "%=20s%=30s\n",
10799 "Locator-set", "Eid");
10802 M(LISP_LOCAL_EID_TABLE_DUMP, lisp_local_eid_table_dump);
10806 /* Use a control ping for synchronization */
10808 vl_api_control_ping_t * mp;
10809 M(CONTROL_PING, control_ping);
10812 /* Wait for a reply... */
10820 api_lisp_gpe_tunnel_dump(vat_main_t *vam)
10822 vl_api_lisp_gpe_tunnel_dump_t *mp;
10825 if (!vam->json_output) {
10826 fformat(vam->ofp, "%=20s%=30s%=16s%=16s%=16s%=16s"
10827 "%=16s%=16s%=16s%=16s%=16s\n",
10828 "Tunel", "Source", "Destination", "Fib encap", "Fib decap",
10829 "Decap next", "Lisp version", "Flags", "Next protocol",
10830 "ver_res", "res", "iid");
10833 M(LISP_GPE_TUNNEL_DUMP, lisp_gpe_tunnel_dump);
10837 /* Use a control ping for synchronization */
10839 vl_api_control_ping_t * mp;
10840 M(CONTROL_PING, control_ping);
10843 /* Wait for a reply... */
10851 api_lisp_map_resolver_dump(vat_main_t *vam)
10853 vl_api_lisp_map_resolver_dump_t *mp;
10856 if (!vam->json_output) {
10857 fformat(vam->ofp, "%=20s\n",
10861 M(LISP_MAP_RESOLVER_DUMP, lisp_map_resolver_dump);
10865 /* Use a control ping for synchronization */
10867 vl_api_control_ping_t * mp;
10868 M(CONTROL_PING, control_ping);
10871 /* Wait for a reply... */
10879 api_lisp_enable_disable_status_dump(vat_main_t *vam)
10881 vl_api_lisp_enable_disable_status_dump_t *mp;
10884 if (!vam->json_output) {
10885 fformat(vam->ofp, "%=20s\n",
10889 M(LISP_ENABLE_DISABLE_STATUS_DUMP,
10890 lisp_enable_disable_status_dump);
10894 /* Use a control ping for synchronization */
10896 vl_api_control_ping_t * mp;
10897 M(CONTROL_PING, control_ping);
10900 /* Wait for a reply... */
10908 api_lisp_get_map_request_itr_rlocs(vat_main_t *vam)
10910 vl_api_lisp_get_map_request_itr_rlocs_t *mp;
10913 if (!vam->json_output) {
10914 fformat(vam->ofp, "%=20s\n",
10918 M(LISP_GET_MAP_REQUEST_ITR_RLOCS, lisp_get_map_request_itr_rlocs);
10921 /* Wait for a reply... */
10929 api_af_packet_create (vat_main_t * vam)
10931 unformat_input_t * i = vam->input;
10932 vl_api_af_packet_create_t * mp;
10934 u8 * host_if_name = 0;
10936 u8 random_hw_addr = 1;
10938 memset (hw_addr, 0, sizeof (hw_addr));
10940 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
10941 if (unformat (i, "name %s", &host_if_name))
10942 vec_add1 (host_if_name, 0);
10943 else if (unformat (i, "hw_addr %U", unformat_ethernet_address, hw_addr))
10944 random_hw_addr = 0;
10949 if (!vec_len (host_if_name)) {
10950 errmsg ("host-interface name must be specified");
10954 if (vec_len (host_if_name) > 64) {
10955 errmsg ("host-interface name too long");
10959 M(AF_PACKET_CREATE, af_packet_create);
10961 clib_memcpy (mp->host_if_name, host_if_name, vec_len (host_if_name));
10962 clib_memcpy (mp->hw_addr, hw_addr, 6);
10963 mp->use_random_hw_addr = random_hw_addr;
10964 vec_free (host_if_name);
10966 S; W2(fprintf(vam->ofp," new sw_if_index = %d ", vam->sw_if_index));
10972 api_af_packet_delete (vat_main_t * vam)
10974 unformat_input_t * i = vam->input;
10975 vl_api_af_packet_delete_t * mp;
10977 u8 * host_if_name = 0;
10979 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
10980 if (unformat (i, "name %s", &host_if_name))
10981 vec_add1 (host_if_name, 0);
10986 if (!vec_len (host_if_name)) {
10987 errmsg ("host-interface name must be specified");
10991 if (vec_len (host_if_name) > 64) {
10992 errmsg ("host-interface name too long");
10996 M(AF_PACKET_DELETE, af_packet_delete);
10998 clib_memcpy (mp->host_if_name, host_if_name, vec_len (host_if_name));
10999 vec_free (host_if_name);
11007 api_policer_add_del (vat_main_t * vam)
11009 unformat_input_t * i = vam->input;
11010 vl_api_policer_add_del_t * mp;
11022 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
11023 if (unformat (i, "del"))
11025 else if (unformat (i, "name %s", &name))
11026 vec_add1 (name, 0);
11027 else if (unformat (i, "cir %u", &cir))
11029 else if (unformat (i, "eir %u", &eir))
11031 else if (unformat (i, "cb %u", &cb))
11033 else if (unformat (i, "eb %u", &eb))
11035 else if (unformat (i, "rate_type %U", unformat_policer_rate_type,
11038 else if (unformat (i, "round_type %U", unformat_policer_round_type,
11041 else if (unformat (i, "type %U", unformat_policer_type, &type))
11047 if (!vec_len (name)) {
11048 errmsg ("policer name must be specified");
11052 if (vec_len (name) > 64) {
11053 errmsg ("policer name too long");
11057 M(POLICER_ADD_DEL, policer_add_del);
11059 clib_memcpy (mp->name, name, vec_len (name));
11061 mp->is_add = is_add;
11066 mp->rate_type = rate_type;
11067 mp->round_type = round_type;
11076 api_policer_dump(vat_main_t *vam)
11078 unformat_input_t * i = vam->input;
11079 vl_api_policer_dump_t *mp;
11081 u8 *match_name = 0;
11082 u8 match_name_valid = 0;
11084 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
11085 if (unformat (i, "name %s", &match_name)) {
11086 vec_add1 (match_name, 0);
11087 match_name_valid = 1;
11092 M(POLICER_DUMP, policer_dump);
11093 mp->match_name_valid = match_name_valid;
11094 clib_memcpy (mp->match_name, match_name, vec_len (match_name));
11095 vec_free (match_name);
11099 /* Use a control ping for synchronization */
11101 vl_api_control_ping_t * mp;
11102 M(CONTROL_PING, control_ping);
11105 /* Wait for a reply... */
11113 api_netmap_create (vat_main_t * vam)
11115 unformat_input_t * i = vam->input;
11116 vl_api_netmap_create_t * mp;
11120 u8 random_hw_addr = 1;
11124 memset (hw_addr, 0, sizeof (hw_addr));
11126 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
11127 if (unformat (i, "name %s", &if_name))
11128 vec_add1 (if_name, 0);
11129 else if (unformat (i, "hw_addr %U", unformat_ethernet_address, hw_addr))
11130 random_hw_addr = 0;
11131 else if (unformat (i, "pipe"))
11133 else if (unformat (i, "master"))
11135 else if (unformat (i, "slave"))
11141 if (!vec_len (if_name)) {
11142 errmsg ("interface name must be specified");
11146 if (vec_len (if_name) > 64) {
11147 errmsg ("interface name too long");
11151 M(NETMAP_CREATE, netmap_create);
11153 clib_memcpy (mp->netmap_if_name, if_name, vec_len (if_name));
11154 clib_memcpy (mp->hw_addr, hw_addr, 6);
11155 mp->use_random_hw_addr = random_hw_addr;
11156 mp->is_pipe = is_pipe;
11157 mp->is_master = is_master;
11158 vec_free (if_name);
11166 api_netmap_delete (vat_main_t * vam)
11168 unformat_input_t * i = vam->input;
11169 vl_api_netmap_delete_t * mp;
11173 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
11174 if (unformat (i, "name %s", &if_name))
11175 vec_add1 (if_name, 0);
11180 if (!vec_len (if_name)) {
11181 errmsg ("interface name must be specified");
11185 if (vec_len (if_name) > 64) {
11186 errmsg ("interface name too long");
11190 M(NETMAP_DELETE, netmap_delete);
11192 clib_memcpy (mp->netmap_if_name, if_name, vec_len (if_name));
11193 vec_free (if_name);
11200 static void vl_api_mpls_gre_tunnel_details_t_handler
11201 (vl_api_mpls_gre_tunnel_details_t * mp)
11203 vat_main_t * vam = &vat_main;
11205 i32 len = ntohl(mp->nlabels);
11207 if (mp->l2_only == 0) {
11208 fformat(vam->ofp, "[%d]: src %U, dst %U, adj %U/%d, labels ",
11209 ntohl(mp->tunnel_index),
11210 format_ip4_address, &mp->tunnel_src,
11211 format_ip4_address, &mp->tunnel_dst,
11212 format_ip4_address, &mp->intfc_address,
11213 ntohl(mp->mask_width));
11214 for (i = 0; i < len; i++) {
11215 fformat(vam->ofp, "%u ", ntohl(mp->labels[i]));
11217 fformat(vam->ofp, "\n");
11218 fformat(vam->ofp, " inner fib index %d, outer fib index %d\n",
11219 ntohl(mp->inner_fib_index), ntohl(mp->outer_fib_index));
11221 fformat(vam->ofp, "[%d]: src %U, dst %U, key %U, labels ",
11222 ntohl(mp->tunnel_index),
11223 format_ip4_address, &mp->tunnel_src,
11224 format_ip4_address, &mp->tunnel_dst,
11225 format_ip4_address, &mp->intfc_address);
11226 for (i = 0; i < len; i++) {
11227 fformat(vam->ofp, "%u ", ntohl(mp->labels[i]));
11229 fformat(vam->ofp, "\n");
11230 fformat(vam->ofp, " l2 interface %d, outer fib index %d\n",
11231 ntohl(mp->hw_if_index), ntohl(mp->outer_fib_index));
11235 static void vl_api_mpls_gre_tunnel_details_t_handler_json
11236 (vl_api_mpls_gre_tunnel_details_t * mp)
11238 vat_main_t * vam = &vat_main;
11239 vat_json_node_t *node = NULL;
11240 struct in_addr ip4;
11242 i32 len = ntohl(mp->nlabels);
11244 if (VAT_JSON_ARRAY != vam->json_tree.type) {
11245 ASSERT(VAT_JSON_NONE == vam->json_tree.type);
11246 vat_json_init_array(&vam->json_tree);
11248 node = vat_json_array_add(&vam->json_tree);
11250 vat_json_init_object(node);
11251 vat_json_object_add_uint(node, "tunnel_index", ntohl(mp->tunnel_index));
11252 clib_memcpy(&ip4, &(mp->intfc_address), sizeof(ip4));
11253 vat_json_object_add_ip4(node, "intfc_address", ip4);
11254 vat_json_object_add_uint(node, "inner_fib_index", ntohl(mp->inner_fib_index));
11255 vat_json_object_add_uint(node, "mask_width", ntohl(mp->mask_width));
11256 vat_json_object_add_uint(node, "encap_index", ntohl(mp->encap_index));
11257 vat_json_object_add_uint(node, "hw_if_index", ntohl(mp->hw_if_index));
11258 vat_json_object_add_uint(node, "l2_only", ntohl(mp->l2_only));
11259 clib_memcpy(&ip4, &(mp->tunnel_src), sizeof(ip4));
11260 vat_json_object_add_ip4(node, "tunnel_src", ip4);
11261 clib_memcpy(&ip4, &(mp->tunnel_dst), sizeof(ip4));
11262 vat_json_object_add_ip4(node, "tunnel_dst", ip4);
11263 vat_json_object_add_uint(node, "outer_fib_index", ntohl(mp->outer_fib_index));
11264 vat_json_object_add_uint(node, "label_count", len);
11265 for (i = 0; i < len; i++) {
11266 vat_json_object_add_uint(node, "label", ntohl(mp->labels[i]));
11270 static int api_mpls_gre_tunnel_dump (vat_main_t * vam)
11272 vl_api_mpls_gre_tunnel_dump_t *mp;
11276 /* Parse args required to build the message */
11277 while (unformat_check_input (vam->input) != UNFORMAT_END_OF_INPUT) {
11278 if (!unformat (vam->input, "tunnel_index %d", &index)) {
11284 fformat(vam->ofp, " tunnel_index %d\n", index);
11286 M(MPLS_GRE_TUNNEL_DUMP, mpls_gre_tunnel_dump);
11287 mp->tunnel_index = htonl(index);
11290 /* Use a control ping for synchronization */
11292 vl_api_control_ping_t * mp;
11293 M(CONTROL_PING, control_ping);
11299 static void vl_api_mpls_eth_tunnel_details_t_handler
11300 (vl_api_mpls_eth_tunnel_details_t * mp)
11302 vat_main_t * vam = &vat_main;
11304 i32 len = ntohl(mp->nlabels);
11306 fformat(vam->ofp, "[%d]: dst %U, adj %U/%d, labels ",
11307 ntohl(mp->tunnel_index),
11308 format_ethernet_address, &mp->tunnel_dst_mac,
11309 format_ip4_address, &mp->intfc_address,
11310 ntohl(mp->mask_width));
11311 for (i = 0; i < len; i++) {
11312 fformat(vam->ofp, "%u ", ntohl(mp->labels[i]));
11314 fformat(vam->ofp, "\n");
11315 fformat(vam->ofp, " tx on %d, rx fib index %d\n",
11316 ntohl(mp->tx_sw_if_index),
11317 ntohl(mp->inner_fib_index));
11320 static void vl_api_mpls_eth_tunnel_details_t_handler_json
11321 (vl_api_mpls_eth_tunnel_details_t * mp)
11323 vat_main_t * vam = &vat_main;
11324 vat_json_node_t *node = NULL;
11325 struct in_addr ip4;
11327 i32 len = ntohl(mp->nlabels);
11329 if (VAT_JSON_ARRAY != vam->json_tree.type) {
11330 ASSERT(VAT_JSON_NONE == vam->json_tree.type);
11331 vat_json_init_array(&vam->json_tree);
11333 node = vat_json_array_add(&vam->json_tree);
11335 vat_json_init_object(node);
11336 vat_json_object_add_uint(node, "tunnel_index", ntohl(mp->tunnel_index));
11337 clib_memcpy(&ip4, &(mp->intfc_address), sizeof(ip4));
11338 vat_json_object_add_ip4(node, "intfc_address", ip4);
11339 vat_json_object_add_uint(node, "inner_fib_index", ntohl(mp->inner_fib_index));
11340 vat_json_object_add_uint(node, "mask_width", ntohl(mp->mask_width));
11341 vat_json_object_add_uint(node, "encap_index", ntohl(mp->encap_index));
11342 vat_json_object_add_uint(node, "hw_if_index", ntohl(mp->hw_if_index));
11343 vat_json_object_add_uint(node, "l2_only", ntohl(mp->l2_only));
11344 vat_json_object_add_string_copy(node, "tunnel_dst_mac",
11345 format(0, "%U", format_ethernet_address, &mp->tunnel_dst_mac));
11346 vat_json_object_add_uint(node, "tx_sw_if_index", ntohl(mp->tx_sw_if_index));
11347 vat_json_object_add_uint(node, "label_count", len);
11348 for (i = 0; i < len; i++) {
11349 vat_json_object_add_uint(node, "label", ntohl(mp->labels[i]));
11353 static int api_mpls_eth_tunnel_dump (vat_main_t * vam)
11355 vl_api_mpls_eth_tunnel_dump_t *mp;
11359 /* Parse args required to build the message */
11360 while (unformat_check_input (vam->input) != UNFORMAT_END_OF_INPUT) {
11361 if (!unformat (vam->input, "tunnel_index %d", &index)) {
11367 fformat(vam->ofp, " tunnel_index %d\n", index);
11369 M(MPLS_ETH_TUNNEL_DUMP, mpls_eth_tunnel_dump);
11370 mp->tunnel_index = htonl(index);
11373 /* Use a control ping for synchronization */
11375 vl_api_control_ping_t * mp;
11376 M(CONTROL_PING, control_ping);
11382 static void vl_api_mpls_fib_encap_details_t_handler
11383 (vl_api_mpls_fib_encap_details_t * mp)
11385 vat_main_t * vam = &vat_main;
11387 i32 len = ntohl(mp->nlabels);
11389 fformat(vam->ofp, "table %d, dest %U, label ",
11390 ntohl(mp->fib_index),
11391 format_ip4_address, &mp->dest,
11393 for (i = 0; i < len; i++) {
11394 fformat(vam->ofp, "%u ", ntohl(mp->labels[i]));
11396 fformat(vam->ofp, "\n");
11399 static void vl_api_mpls_fib_encap_details_t_handler_json
11400 (vl_api_mpls_fib_encap_details_t * mp)
11402 vat_main_t * vam = &vat_main;
11403 vat_json_node_t *node = NULL;
11405 i32 len = ntohl(mp->nlabels);
11406 struct in_addr ip4;
11408 if (VAT_JSON_ARRAY != vam->json_tree.type) {
11409 ASSERT(VAT_JSON_NONE == vam->json_tree.type);
11410 vat_json_init_array(&vam->json_tree);
11412 node = vat_json_array_add(&vam->json_tree);
11414 vat_json_init_object(node);
11415 vat_json_object_add_uint(node, "table", ntohl(mp->fib_index));
11416 vat_json_object_add_uint(node, "entry_index", ntohl(mp->entry_index));
11417 clib_memcpy(&ip4, &(mp->dest), sizeof(ip4));
11418 vat_json_object_add_ip4(node, "dest", ip4);
11419 vat_json_object_add_uint(node, "s_bit", ntohl(mp->s_bit));
11420 vat_json_object_add_uint(node, "label_count", len);
11421 for (i = 0; i < len; i++) {
11422 vat_json_object_add_uint(node, "label", ntohl(mp->labels[i]));
11426 static int api_mpls_fib_encap_dump (vat_main_t * vam)
11428 vl_api_mpls_fib_encap_dump_t *mp;
11431 M(MPLS_FIB_ENCAP_DUMP, mpls_fib_encap_dump);
11434 /* Use a control ping for synchronization */
11436 vl_api_control_ping_t * mp;
11437 M(CONTROL_PING, control_ping);
11443 static void vl_api_mpls_fib_decap_details_t_handler
11444 (vl_api_mpls_fib_decap_details_t * mp)
11446 vat_main_t * vam = &vat_main;
11448 fformat(vam->ofp, "RX table %d, TX table/intfc %u, swif_tag '%s', label %u, s_bit %u\n",
11449 ntohl(mp->rx_table_id),
11450 ntohl(mp->tx_table_id),
11456 static void vl_api_mpls_fib_decap_details_t_handler_json
11457 (vl_api_mpls_fib_decap_details_t * mp)
11459 vat_main_t * vam = &vat_main;
11460 vat_json_node_t *node = NULL;
11461 struct in_addr ip4;
11463 if (VAT_JSON_ARRAY != vam->json_tree.type) {
11464 ASSERT(VAT_JSON_NONE == vam->json_tree.type);
11465 vat_json_init_array(&vam->json_tree);
11467 node = vat_json_array_add(&vam->json_tree);
11469 vat_json_init_object(node);
11470 vat_json_object_add_uint(node, "table", ntohl(mp->fib_index));
11471 vat_json_object_add_uint(node, "entry_index", ntohl(mp->entry_index));
11472 clib_memcpy(&ip4, &(mp->dest), sizeof(ip4));
11473 vat_json_object_add_ip4(node, "dest", ip4);
11474 vat_json_object_add_uint(node, "s_bit", ntohl(mp->s_bit));
11475 vat_json_object_add_uint(node, "label", ntohl(mp->label));
11476 vat_json_object_add_uint(node, "rx_table_id", ntohl(mp->rx_table_id));
11477 vat_json_object_add_uint(node, "tx_table_id", ntohl(mp->tx_table_id));
11478 vat_json_object_add_string_copy(node, "swif_tag", mp->swif_tag);
11481 static int api_mpls_fib_decap_dump (vat_main_t * vam)
11483 vl_api_mpls_fib_decap_dump_t *mp;
11486 M(MPLS_FIB_DECAP_DUMP, mpls_fib_decap_dump);
11489 /* Use a control ping for synchronization */
11491 vl_api_control_ping_t * mp;
11492 M(CONTROL_PING, control_ping);
11498 int api_classify_table_ids (vat_main_t *vam)
11500 vl_api_classify_table_ids_t *mp;
11503 /* Construct the API message */
11504 M(CLASSIFY_TABLE_IDS, classify_table_ids);
11512 int api_classify_table_by_interface (vat_main_t *vam)
11514 unformat_input_t * input = vam->input;
11515 vl_api_classify_table_by_interface_t *mp;
11518 u32 sw_if_index = ~0;
11519 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) {
11520 if (unformat (input, "%U", unformat_sw_if_index, vam, &sw_if_index))
11522 else if (unformat (input, "sw_if_index %d", &sw_if_index))
11527 if (sw_if_index == ~0) {
11528 errmsg ("missing interface name or sw_if_index\n");
11532 /* Construct the API message */
11533 M(CLASSIFY_TABLE_BY_INTERFACE, classify_table_by_interface);
11535 mp->sw_if_index = ntohl(sw_if_index);
11542 int api_classify_table_info (vat_main_t *vam)
11544 unformat_input_t * input = vam->input;
11545 vl_api_classify_table_info_t *mp;
11549 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) {
11550 if (unformat (input, "table_id %d", &table_id))
11555 if (table_id == ~0) {
11556 errmsg ("missing table id\n");
11560 /* Construct the API message */
11561 M(CLASSIFY_TABLE_INFO, classify_table_info);
11563 mp->table_id = ntohl(table_id);
11570 int api_classify_session_dump (vat_main_t *vam)
11572 unformat_input_t * input = vam->input;
11573 vl_api_classify_session_dump_t *mp;
11577 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) {
11578 if (unformat (input, "table_id %d", &table_id))
11583 if (table_id == ~0) {
11584 errmsg ("missing table id\n");
11588 /* Construct the API message */
11589 M(CLASSIFY_SESSION_DUMP, classify_session_dump);
11591 mp->table_id = ntohl(table_id);
11594 /* Use a control ping for synchronization */
11596 vl_api_control_ping_t * mp;
11597 M(CONTROL_PING, control_ping);
11605 static int q_or_quit (vat_main_t * vam)
11607 longjmp (vam->jump_buf, 1);
11608 return 0; /* not so much */
11610 static int q (vat_main_t * vam) {return q_or_quit (vam);}
11611 static int quit (vat_main_t * vam) {return q_or_quit (vam);}
11613 static int comment (vat_main_t * vam)
11618 static int cmd_cmp (void * a1, void * a2)
11623 return strcmp ((char *)(c1[0]), (char *)(c2[0]));
11626 static int help (vat_main_t * vam)
11631 unformat_input_t * i = vam->input;
11634 if (unformat (i, "%s", &name)) {
11639 hs = hash_get_mem (vam->help_by_name, name);
11641 fformat (vam->ofp, "usage: %s %s\n", name, hs[0]);
11643 fformat (vam->ofp, "No such msg / command '%s'\n", name);
11648 fformat(vam->ofp, "Help is available for the following:\n");
11650 hash_foreach_pair (p, vam->function_by_name,
11652 vec_add1 (cmds, (u8 *)(p->key));
11655 vec_sort_with_function (cmds, cmd_cmp);
11657 for (j = 0; j < vec_len(cmds); j++)
11658 fformat (vam->ofp, "%s\n", cmds[j]);
11664 static int set (vat_main_t * vam)
11666 u8 * name = 0, * value = 0;
11667 unformat_input_t * i = vam->input;
11669 if (unformat (i, "%s", &name)) {
11670 /* The input buffer is a vector, not a string. */
11671 value = vec_dup (i->buffer);
11672 vec_delete (value, i->index, 0);
11673 /* Almost certainly has a trailing newline */
11674 if (value[vec_len(value)-1] == '\n')
11675 value[vec_len(value)-1] = 0;
11676 /* Make sure it's a proper string, one way or the other */
11677 vec_add1 (value, 0);
11678 (void) clib_macro_set_value (&vam->macro_main,
11679 (char *)name, (char *)value);
11682 errmsg ("usage: set <name> <value>\n");
11689 static int unset (vat_main_t * vam)
11693 if (unformat (vam->input, "%s", &name))
11694 if (clib_macro_unset (&vam->macro_main, (char *)name) == 1)
11695 errmsg ("unset: %s wasn't set\n", name);
11706 static int macro_sort_cmp (void * a1, void * a2)
11708 macro_sort_t * s1 = a1;
11709 macro_sort_t * s2 = a2;
11711 return strcmp ((char *)(s1->name), (char *)(s2->name));
11714 static int dump_macro_table (vat_main_t * vam)
11716 macro_sort_t * sort_me = 0, * sm;
11720 hash_foreach_pair (p, vam->macro_main.the_value_table_hash,
11722 vec_add2 (sort_me, sm, 1);
11723 sm->name = (u8 *)(p->key);
11724 sm->value = (u8 *) (p->value[0]);
11727 vec_sort_with_function (sort_me, macro_sort_cmp);
11729 if (vec_len(sort_me))
11730 fformat (vam->ofp, "%-15s%s\n", "Name", "Value");
11732 fformat (vam->ofp, "The macro table is empty...\n");
11734 for (i = 0; i < vec_len (sort_me); i++)
11735 fformat (vam->ofp, "%-15s%s\n", sort_me[i].name,
11740 static int dump_node_table (vat_main_t * vam)
11743 vlib_node_t * node, * next_node;
11745 if (vec_len (vam->graph_nodes) == 0) {
11746 fformat (vam->ofp, "Node table empty, issue get_node_graph...\n");
11750 for (i = 0; i < vec_len (vam->graph_nodes); i++) {
11751 node = vam->graph_nodes[i];
11752 fformat (vam->ofp, "[%d] %s\n", i, node->name);
11753 for (j = 0; j < vec_len (node->next_nodes); j++) {
11754 if (node->next_nodes[j] != ~0) {
11755 next_node = vam->graph_nodes[node->next_nodes[j]];
11756 fformat (vam->ofp, " [%d] %s\n", j, next_node->name);
11763 static int search_node_table (vat_main_t * vam)
11765 unformat_input_t * line_input = vam->input;
11768 vlib_node_t * node, * next_node;
11771 if (vam->graph_node_index_by_name == 0) {
11772 fformat (vam->ofp, "Node table empty, issue get_node_graph...\n");
11776 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) {
11777 if (unformat (line_input, "%s", &node_to_find)) {
11778 vec_add1 (node_to_find, 0);
11779 p = hash_get_mem (vam->graph_node_index_by_name, node_to_find);
11781 fformat (vam->ofp, "%s not found...\n", node_to_find);
11784 node = vam->graph_nodes[p[0]];
11785 fformat (vam->ofp, "[%d] %s\n", p[0], node->name);
11786 for (j = 0; j < vec_len (node->next_nodes); j++) {
11787 if (node->next_nodes[j] != ~0) {
11788 next_node = vam->graph_nodes[node->next_nodes[j]];
11789 fformat (vam->ofp, " [%d] %s\n", j, next_node->name);
11795 clib_warning ("parse error '%U'", format_unformat_error,
11801 vec_free(node_to_find);
11809 static int script (vat_main_t * vam)
11812 char * save_current_file;
11813 unformat_input_t save_input;
11814 jmp_buf save_jump_buf;
11815 u32 save_line_number;
11817 FILE * new_fp, * save_ifp;
11819 if (unformat (vam->input, "%s", &s)) {
11820 new_fp = fopen ((char *)s, "r");
11822 errmsg ("Couldn't open script file %s\n", s);
11827 errmsg ("Missing script name\n");
11831 clib_memcpy (&save_input, &vam->input, sizeof (save_input));
11832 clib_memcpy (&save_jump_buf, &vam->jump_buf, sizeof (save_jump_buf));
11833 save_ifp = vam->ifp;
11834 save_line_number = vam->input_line_number;
11835 save_current_file = (char *) vam->current_file;
11837 vam->input_line_number = 0;
11839 vam->current_file = s;
11842 clib_memcpy (&vam->input, &save_input, sizeof (vam->input));
11843 clib_memcpy (&vam->jump_buf, &save_jump_buf, sizeof (save_jump_buf));
11844 vam->ifp = save_ifp;
11845 vam->input_line_number = save_line_number;
11846 vam->current_file = (u8 *) save_current_file;
11852 static int echo (vat_main_t * vam)
11854 fformat (vam->ofp, "%v", vam->input->buffer);
11858 /* List of API message constructors, CLI names map to api_xxx */
11859 #define foreach_vpe_api_msg \
11860 _(create_loopback,"[mac <mac-addr>]") \
11861 _(sw_interface_dump,"") \
11862 _(sw_interface_set_flags, \
11863 "<intfc> | sw_if_index <id> admin-up | admin-down link-up | link down") \
11864 _(sw_interface_add_del_address, \
11865 "<intfc> | sw_if_index <id> <ip4-address> | <ip6-address> [del] [del-all] ") \
11866 _(sw_interface_set_table, \
11867 "<intfc> | sw_if_index <id> vrf <table-id> [ipv6]") \
11868 _(sw_interface_set_vpath, \
11869 "<intfc> | sw_if_index <id> enable | disable") \
11870 _(sw_interface_set_l2_xconnect, \
11871 "rx <intfc> | rx_sw_if_index <id> tx <intfc> | tx_sw_if_index <id>\n" \
11872 "enable | disable") \
11873 _(sw_interface_set_l2_bridge, \
11874 "rx <intfc> | rx_sw_if_index <id> bd_id <bridge-domain-id>\n" \
11875 "[shg <split-horizon-group>] [bvi]\n" \
11876 "enable | disable") \
11877 _(bridge_domain_add_del, \
11878 "bd_id <bridge-domain-id> [flood 1|0] [uu-flood 1|0] [forward 1|0] [learn 1|0] [arp-term 1|0] [del]\n")\
11879 _(bridge_domain_dump, "[bd_id <bridge-domain-id>]\n") \
11881 "mac <mac-addr> bd_id <bridge-domain-id> [del] | sw_if <intfc> | sw_if_index <id> [static] [filter] [bvi]\n") \
11883 "sw_if <intfc> | sw_if_index <id> [learn] [forward] [uu-flood] [flood]\n") \
11885 "bd_id <bridge-domain-id> [learn] [forward] [uu-flood] [flood] [arp-term] [disable]\n") \
11887 "tapname <name> mac <mac-addr> | random-mac") \
11889 "<vpp-if-name> | sw_if_index <id> tapname <name> mac <mac-addr> | random-mac") \
11891 "<vpp-if-name> | sw_if_index <id>") \
11892 _(sw_interface_tap_dump, "") \
11893 _(ip_add_del_route, \
11894 "<addr>/<mask> via <addr> [vrf <n>]\n" \
11895 "[<intfc> | sw_if_index <id>] [resolve-attempts <n>]\n" \
11896 "[weight <n>] [drop] [local] [classify <n>] [del]\n" \
11897 "[multipath] [count <n>]") \
11898 _(proxy_arp_add_del, \
11899 "<lo-ip4-addr> - <hi-ip4-addr> [vrf <n>] [del]") \
11900 _(proxy_arp_intfc_enable_disable, \
11901 "<intfc> | sw_if_index <id> enable | disable") \
11902 _(mpls_add_del_encap, \
11903 "label <n> dst <ip4-addr> [vrf <n>] [del]") \
11904 _(mpls_add_del_decap, \
11905 "label <n> [rx_vrf_id <n>] [tx_vrf_id] [s-bit-clear][del]") \
11906 _(mpls_gre_add_del_tunnel, \
11907 "inner_vrf_id <n> outer_vrf_id <n> src <ip4-address> dst <ip4-address>\n" \
11908 "adj <ip4-address>/<mask-width> [del]") \
11909 _(sw_interface_set_unnumbered, \
11910 "<intfc> | sw_if_index <id> unnum_if_index <id> [del]") \
11911 _(ip_neighbor_add_del, \
11912 "<intfc> | sw_if_index <id> dst <ip46-address> mac <mac-addr>") \
11913 _(reset_vrf, "vrf <id> [ipv6]") \
11914 _(create_vlan_subif, "<intfc> | sw_if_index <id> vlan <n>") \
11915 _(create_subif, "<intfc> | sw_if_index <id> sub_id <n>\n" \
11916 "[outer_vlan_id <n>][inner_vlan_id <n>]\n" \
11917 "[no_tags][one_tag][two_tags][dot1ad][exact_match][default_sub]\n" \
11918 "[outer_vlan_id_any][inner_vlan_id_any]") \
11919 _(oam_add_del, "src <ip4-address> dst <ip4-address> [vrf <n>] [del]") \
11920 _(reset_fib, "vrf <n> [ipv6]") \
11921 _(dhcp_proxy_config, \
11922 "svr <v46-address> src <v46-address>\n" \
11923 "insert-cid <n> [del]") \
11924 _(dhcp_proxy_config_2, \
11925 "svr <v46-address> src <v46-address>\n" \
11926 "rx_vrf_id <nn> server_vrf_id <nn> insert-cid <n> [del]") \
11927 _(dhcp_proxy_set_vss, \
11928 "tbl_id <n> fib_id <n> oui <n> [ipv6] [del]") \
11929 _(dhcp_client_config, \
11930 "<intfc> | sw_if_index <id> [hostname <name>] [disable_event] [del]") \
11931 _(set_ip_flow_hash, \
11932 "vrf <n> [src] [dst] [sport] [dport] [proto] [reverse] [ipv6]") \
11933 _(sw_interface_ip6_enable_disable, \
11934 "<intfc> | sw_if_index <id> enable | disable") \
11935 _(sw_interface_ip6_set_link_local_address, \
11936 "<intfc> | sw_if_index <id> <ip6-address>/<mask-width>") \
11937 _(sw_interface_ip6nd_ra_prefix, \
11938 "<intfc> | sw_if_index <id> <ip6-address>/<mask-width>\n" \
11939 "val_life <n> pref_life <n> [def] [noadv] [offl] [noauto]\n" \
11940 "[nolink] [isno]") \
11941 _(sw_interface_ip6nd_ra_config, \
11942 "<intfc> | sw_if_index <id> [maxint <n>] [minint <n>]\n" \
11943 "[life <n>] [count <n>] [interval <n>] [surpress]\n" \
11944 "[managed] [other] [ll] [send] [cease] [isno] [def]") \
11945 _(set_arp_neighbor_limit, "arp_nbr_limit <n> [ipv6]") \
11946 _(l2_patch_add_del, \
11947 "rx <intfc> | rx_sw_if_index <id> tx <intfc> | tx_sw_if_index <id>\n" \
11948 "enable | disable") \
11949 _(mpls_ethernet_add_del_tunnel, \
11950 "tx <intfc> | tx_sw_if_index <n> dst <mac-addr>\n" \
11951 "adj <ip4-addr>/<mw> dst <mac-addr> [del]") \
11952 _(mpls_ethernet_add_del_tunnel_2, \
11953 "inner_vrf_id <n> outer_vrf_id <n> next-hop <ip4-addr>\n" \
11954 "resolve-attempts <n> resolve-if-needed 0 | 1 [del]") \
11955 _(sr_tunnel_add_del, \
11956 "[name <name>] src <ip6-addr> dst <ip6-addr>/<mw> \n" \
11957 "(next <ip6-addr>)+ [tag <ip6-addr>]* [clean] [reroute] \n" \
11958 "[policy <policy_name>]") \
11959 _(sr_policy_add_del, \
11960 "name <name> tunnel <tunnel-name> [tunnel <tunnel-name>]* [del]") \
11961 _(sr_multicast_map_add_del, \
11962 "address [ip6 multicast address] sr-policy [policy name] [del]") \
11963 _(classify_add_del_table, \
11964 "buckets <nn> [skip <n>] [match <n>] [memory_size <nn-bytes>]\n" \
11965 "[del] mask <mask-value>\n" \
11966 " [l2-miss-next | miss-next | acl-miss-next] <name|nn>") \
11967 _(classify_add_del_session, \
11968 "[hit-next|l2-hit-next|acl-hit-next] <name|nn> table-index <nn>\n" \
11969 "skip_n <nn> match_n <nn> match [hex] [l2] [l3 [ip4|ip6]]") \
11970 _(classify_set_interface_ip_table, \
11971 "<intfc> | sw_if_index <nn> table <nn>") \
11972 _(classify_set_interface_l2_tables, \
11973 "<intfc> | sw_if_index <nn> [ip4-table <nn>] [ip6-table <nn>]\n" \
11974 " [other-table <nn>]") \
11975 _(get_node_index, "node <node-name") \
11976 _(add_node_next, "node <node-name> next <next-node-name>") \
11977 _(l2tpv3_create_tunnel, \
11978 "client_address <ip6-addr> our_address <ip6-addr>\n" \
11979 "[local_session_id <nn>][remote_session_id <nn>][local_cookie <nn>]\n"\
11980 "[remote_cookie <nn>]\n[l2-sublayer-preset]\n") \
11981 _(l2tpv3_set_tunnel_cookies, \
11982 "<intfc> | sw_if_index <nn> [new_local_cookie <nn>]\n" \
11983 "[new_remote_cookie <nn>]\n") \
11984 _(l2tpv3_interface_enable_disable, \
11985 "<intfc> | sw_if_index <nn> enable | disable") \
11986 _(l2tpv3_set_lookup_key, \
11987 "lookup_v6_src | lookup_v6_dst | lookup_session_id") \
11988 _(sw_if_l2tpv3_tunnel_dump, "") \
11989 _(vxlan_add_del_tunnel, \
11990 "src <ip-addr> dst <ip-addr> vni <vni> [encap-vrf-id <nn>]\n" \
11991 " [decap-next l2|ip4|ip6] [del]") \
11992 _(vxlan_tunnel_dump, "[<intfc> | sw_if_index <nn>]") \
11993 _(gre_add_del_tunnel, \
11994 "src <ip4-addr> dst <ip4-addr> [outer-fib-id <nn>] [del]\n") \
11995 _(gre_tunnel_dump, "[<intfc> | sw_if_index <nn>]") \
11996 _(l2_fib_clear_table, "") \
11997 _(l2_interface_efp_filter, "sw_if_index <nn> enable | disable") \
11998 _(l2_interface_vlan_tag_rewrite, \
11999 "<intfc> | sw_if_index <nn> \n" \
12000 "[disable][push-[1|2]][pop-[1|2]][translate-1-[1|2]] \n" \
12001 "[translate-2-[1|2]] [push_dot1q 0] tag1 <nn> tag2 <nn>") \
12002 _(create_vhost_user_if, \
12003 "socket <filename> [server] [renumber <dev_instance>] " \
12004 "[mac <mac_address>]") \
12005 _(modify_vhost_user_if, \
12006 "<intfc> | sw_if_index <nn> socket <filename>\n" \
12007 "[server] [renumber <dev_instance>]") \
12008 _(delete_vhost_user_if, "<intfc> | sw_if_index <nn>") \
12009 _(sw_interface_vhost_user_dump, "") \
12010 _(show_version, "") \
12011 _(vxlan_gpe_add_del_tunnel, \
12012 "local <addr> remote <addr> vni <nn>\n" \
12013 "[encap-vrf-id <nn>] [decap-vrf-id <nn>] [next-ip4][next-ip6]" \
12014 "[next-ethernet] [next-nsh]\n") \
12015 _(vxlan_gpe_tunnel_dump, "[<intfc> | sw_if_index <nn>]") \
12016 _(l2_fib_table_dump, "bd_id <bridge-domain-id>") \
12017 _(interface_name_renumber, \
12018 "<intfc> | sw_if_index <nn> new_show_dev_instance <nn>") \
12019 _(input_acl_set_interface, \
12020 "<intfc> | sw_if_index <nn> [ip4-table <nn>] [ip6-table <nn>]\n" \
12021 " [l2-table <nn>] [del]") \
12022 _(want_ip4_arp_events, "address <ip4-address> [del]") \
12023 _(ip_address_dump, "(ipv4 | ipv6) (<intfc> | sw_if_index <id>)") \
12024 _(ip_dump, "ipv4 | ipv6") \
12025 _(ipsec_spd_add_del, "spd_id <n> [del]") \
12026 _(ipsec_interface_add_del_spd, "(<intfc> | sw_if_index <id>)\n" \
12028 _(ipsec_sad_add_del_entry, "sad_id <n> spi <n> crypto_alg <alg>\n" \
12029 " crypto_key <hex> tunnel_src <ip4|ip6> tunnel_dst <ip4|ip6>\n" \
12030 " integ_alg <alg> integ_key <hex>") \
12031 _(ipsec_spd_add_del_entry, "spd_id <n> priority <n> action <action>\n" \
12032 " (inbound|outbound) [sa_id <n>] laddr_start <ip4|ip6>\n" \
12033 " laddr_stop <ip4|ip6> raddr_start <ip4|ip6> raddr_stop <ip4|ip6>\n" \
12034 " [lport_start <n> lport_stop <n>] [rport_start <n> rport_stop <n>]" )\
12035 _(ipsec_sa_set_key, "sa_id <n> crypto_key <hex> integ_key <hex>") \
12036 _(ikev2_profile_add_del, "name <profile_name> [del]") \
12037 _(ikev2_profile_set_auth, "name <profile_name> auth_method <method>\n" \
12038 "(auth_data 0x<data> | auth_data <data>)") \
12039 _(ikev2_profile_set_id, "name <profile_name> id_type <type>\n" \
12040 "(id_data 0x<data> | id_data <data>) (local|remote)") \
12041 _(ikev2_profile_set_ts, "name <profile_name> protocol <proto>\n" \
12042 "start_port <port> end_port <port> start_addr <ip4> end_addr <ip4>\n" \
12043 "(local|remote)") \
12044 _(ikev2_set_local_key, "file <absolute_file_path>") \
12045 _(delete_loopback,"sw_if_index <nn>") \
12046 _(bd_ip_mac_add_del, "bd_id <bridge-domain-id> <ip4/6-addr> <mac-addr> [del]") \
12047 _(map_add_domain, \
12048 "ip4-pfx <ip4pfx> ip6-pfx <ip6pfx> " \
12049 "ip6-src <ip6addr> " \
12050 "ea-bits-len <n> psid-offset <n> psid-len <n>") \
12051 _(map_del_domain, "index <n>") \
12052 _(map_add_del_rule, \
12053 "index <n> psid <n> dst <ip6addr> [del]") \
12054 _(map_domain_dump, "") \
12055 _(map_rule_dump, "index <map-domain>") \
12056 _(want_interface_events, "enable|disable") \
12057 _(want_stats,"enable|disable") \
12058 _(get_first_msg_id, "client <name>") \
12059 _(cop_interface_enable_disable, "<intfc> | sw_if_index <nn> [disable]") \
12060 _(cop_whitelist_enable_disable, "<intfc> | sw_if_index <nn>\n" \
12061 "fib-id <nn> [ip4][ip6][default]") \
12062 _(get_node_graph, " ") \
12063 _(sw_interface_clear_stats,"<intfc> | sw_if_index <nn>") \
12064 _(trace_profile_add, "id <nn> trace-type <0x1f|0x3|0x9|0x11|0x19> " \
12065 "trace-elts <nn> trace-tsp <0|1|2|3> node-id <node id in hex> " \
12066 "app-data <app_data in hex> [pow] [ppc <encap|decap>]") \
12067 _(trace_profile_apply, "id <nn> <ip6-address>/<width>" \
12068 " vrf_id <nn> add | pop | none") \
12069 _(trace_profile_del, "") \
12070 _(lisp_add_del_locator_set, "locator-set <locator_name> [del]") \
12071 _(lisp_add_del_locator, "locator-set <locator_name> " \
12072 "iface <intf> | sw_if_index <sw_if_index> " \
12073 "p <priority> w <weight> [del]") \
12074 _(lisp_add_del_local_eid, "<ipv4|ipv6>/<prefix> " \
12075 "locator-set <locator_name> [del]") \
12076 _(lisp_gpe_add_del_fwd_entry, "eid <ip4|6-addr>/<prefix> " \
12077 "sloc <ip4/6-addr> dloc <ip4|6-addr> [del]") \
12078 _(lisp_add_del_map_resolver, "<ip4|6-addr> [del]") \
12079 _(lisp_gpe_enable_disable, "enable|disable") \
12080 _(lisp_enable_disable, "enable|disable") \
12081 _(lisp_gpe_add_del_iface, "up|down") \
12082 _(lisp_add_del_remote_mapping, "add|del vni <vni> table-id <id> " \
12083 "deid <dest-eid> seid" \
12084 " <src-eid> rloc <locator> " \
12085 "[rloc <loc> ... ]") \
12086 _(lisp_pitr_set_locator_set, "locator-set <loc-set-name> | del") \
12087 _(lisp_add_del_map_request_itr_rlocs, "<loc-set-name> [del]") \
12088 _(lisp_eid_table_add_del_map, "[del] vni <vni> vrf <vrf>") \
12089 _(lisp_locator_set_dump, "") \
12090 _(lisp_local_eid_table_dump, "") \
12091 _(lisp_gpe_tunnel_dump, "") \
12092 _(lisp_map_resolver_dump, "") \
12093 _(lisp_enable_disable_status_dump, "") \
12094 _(lisp_get_map_request_itr_rlocs, "") \
12095 _(af_packet_create, "name <host interface name> [hw_addr <mac>]") \
12096 _(af_packet_delete, "name <host interface name>") \
12097 _(policer_add_del, "name <policer name> <params> [del]") \
12098 _(policer_dump, "[name <policer name>]") \
12099 _(netmap_create, "name <interface name> [hw-addr <mac>] [pipe] " \
12100 "[master|slave]") \
12101 _(netmap_delete, "name <interface name>") \
12102 _(mpls_gre_tunnel_dump, "tunnel_index <tunnel-id>") \
12103 _(mpls_eth_tunnel_dump, "tunnel_index <tunnel-id>") \
12104 _(mpls_fib_encap_dump, "") \
12105 _(mpls_fib_decap_dump, "") \
12106 _(classify_table_ids, "") \
12107 _(classify_table_by_interface, "sw_if_index <sw_if_index>") \
12108 _(classify_table_info, "table_id <nn>") \
12109 _(classify_session_dump, "table_id <nn>")
12111 /* List of command functions, CLI names map directly to functions */
12112 #define foreach_cli_function \
12113 _(comment, "usage: comment <ignore-rest-of-line>") \
12114 _(dump_interface_table, "usage: dump_interface_table") \
12115 _(dump_sub_interface_table, "usage: dump_sub_interface_table") \
12116 _(dump_ipv4_table, "usage: dump_ipv4_table") \
12117 _(dump_ipv6_table, "usage: dump_ipv6_table") \
12118 _(dump_stats_table, "usage: dump_stats_table") \
12119 _(dump_macro_table, "usage: dump_macro_table ") \
12120 _(dump_node_table, "usage: dump_node_table") \
12121 _(echo, "usage: echo <message>") \
12122 _(exec, "usage: exec <vpe-debug-CLI-command>") \
12123 _(help, "usage: help") \
12124 _(q, "usage: quit") \
12125 _(quit, "usage: quit") \
12126 _(search_node_table, "usage: search_node_table <name>...") \
12127 _(set, "usage: set <variable-name> <value>") \
12128 _(script, "usage: script <file-name>") \
12129 _(unset, "usage: unset <variable-name>")
12132 static void vl_api_##n##_t_handler_uni \
12133 (vl_api_##n##_t * mp) \
12135 vat_main_t * vam = &vat_main; \
12136 if (vam->json_output) { \
12137 vl_api_##n##_t_handler_json(mp); \
12139 vl_api_##n##_t_handler(mp); \
12142 foreach_vpe_api_reply_msg;
12145 void vat_api_hookup (vat_main_t *vam)
12148 vl_msg_api_set_handlers(VL_API_##N, #n, \
12149 vl_api_##n##_t_handler_uni, \
12151 vl_api_##n##_t_endian, \
12152 vl_api_##n##_t_print, \
12153 sizeof(vl_api_##n##_t), 1);
12154 foreach_vpe_api_reply_msg;
12157 vl_msg_api_set_first_available_msg_id (VL_MSG_FIRST_AVAILABLE);
12159 vam->sw_if_index_by_interface_name =
12160 hash_create_string (0, sizeof (uword));
12162 vam->function_by_name =
12163 hash_create_string (0, sizeof(uword));
12165 vam->help_by_name =
12166 hash_create_string (0, sizeof(uword));
12168 /* API messages we can send */
12169 #define _(n,h) hash_set_mem (vam->function_by_name, #n, api_##n);
12170 foreach_vpe_api_msg;
12174 #define _(n,h) hash_set_mem (vam->help_by_name, #n, h);
12175 foreach_vpe_api_msg;
12178 /* CLI functions */
12179 #define _(n,h) hash_set_mem (vam->function_by_name, #n, n);
12180 foreach_cli_function;
12184 #define _(n,h) hash_set_mem (vam->help_by_name, #n, h);
12185 foreach_cli_function;
12189 #undef vl_api_version
12190 #define vl_api_version(n,v) static u32 vpe_api_version = v;
12191 #include <api/vpe.api.h>
12192 #undef vl_api_version
12194 void vl_client_add_api_signatures (vl_api_memclnt_create_t *mp)
12197 * Send the main API signature in slot 0. This bit of code must
12198 * match the checks in ../vpe/api/api.c: vl_msg_api_version_check().
12200 mp->api_versions[0] = clib_host_to_net_u32 (vpe_api_version);