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>
38 #include <vnet/ipsec/ipsec.h>
39 #include <vnet/ipsec/ikev2.h>
43 #include <vnet/map/map.h>
44 #include <vnet/cop/cop.h>
45 #include <vnet/ip/ip6_hop_by_hop.h>
46 #include <vnet/policer/xlate.h>
48 #include "vat/json_format.h"
50 #define vl_typedefs /* define message structures */
51 #include <api/vpe_all_api_h.h>
54 /* declare message handlers for each api */
56 #define vl_endianfun /* define message structures */
57 #include <api/vpe_all_api_h.h>
60 /* instantiate all the print functions we know about */
61 #define vl_print(handle, ...)
63 #include <api/vpe_all_api_h.h>
66 uword unformat_sw_if_index (unformat_input_t * input, va_list * args)
68 vat_main_t * vam = va_arg (*args, vat_main_t *);
69 u32 * result = va_arg (*args, u32 *);
73 if (!unformat (input, "%s", &if_name))
76 p = hash_get_mem (vam->sw_if_index_by_interface_name, if_name);
83 /* Parse an IP4 address %d.%d.%d.%d. */
84 uword unformat_ip4_address (unformat_input_t * input, va_list * args)
86 u8 * result = va_arg (*args, u8 *);
89 if (! unformat (input, "%d.%d.%d.%d", &a[0], &a[1], &a[2], &a[3]))
92 if (a[0] >= 256 || a[1] >= 256 || a[2] >= 256 || a[3] >= 256)
105 unformat_ethernet_address (unformat_input_t * input, va_list * args)
107 u8 * result = va_arg (*args, u8 *);
110 if (! unformat (input, "%_%x:%x:%x:%x:%x:%x%_",
111 &a[0], &a[1], &a[2], &a[3], &a[4], &a[5]))
115 for (i = 0; i < 6; i++)
116 if (a[i] >= (1 << 8))
119 for (i = 0; i < 6; i++)
125 /* Returns ethernet type as an int in host byte order. */
127 unformat_ethernet_type_host_byte_order (unformat_input_t * input,
130 u16 * result = va_arg (*args, u16 *);
134 if (unformat (input, "0x%x", &type)
135 || unformat (input, "%d", &type))
137 if (type >= (1 << 16))
145 /* Parse an IP6 address. */
146 uword unformat_ip6_address (unformat_input_t * input, va_list * args)
148 ip6_address_t * result = va_arg (*args, ip6_address_t *);
150 uword hex_quad, n_hex_quads, hex_digit, n_hex_digits;
151 uword c, n_colon, double_colon_index;
153 n_hex_quads = hex_quad = n_hex_digits = n_colon = 0;
154 double_colon_index = ARRAY_LEN (hex_quads);
155 while ((c = unformat_get_input (input)) != UNFORMAT_END_OF_INPUT)
158 if (c >= '0' && c <= '9')
160 else if (c >= 'a' && c <= 'f')
161 hex_digit = c + 10 - 'a';
162 else if (c >= 'A' && c <= 'F')
163 hex_digit = c + 10 - 'A';
164 else if (c == ':' && n_colon < 2)
168 unformat_put_input (input);
172 /* Too many hex quads. */
173 if (n_hex_quads >= ARRAY_LEN (hex_quads))
178 hex_quad = (hex_quad << 4) | hex_digit;
180 /* Hex quad must fit in 16 bits. */
181 if (n_hex_digits >= 4)
188 /* Save position of :: */
191 /* More than one :: ? */
192 if (double_colon_index < ARRAY_LEN (hex_quads))
194 double_colon_index = n_hex_quads;
197 if (n_colon > 0 && n_hex_digits > 0)
199 hex_quads[n_hex_quads++] = hex_quad;
205 if (n_hex_digits > 0)
206 hex_quads[n_hex_quads++] = hex_quad;
211 /* Expand :: to appropriate number of zero hex quads. */
212 if (double_colon_index < ARRAY_LEN (hex_quads))
214 word n_zero = ARRAY_LEN (hex_quads) - n_hex_quads;
216 for (i = n_hex_quads - 1; i >= (signed) double_colon_index; i--)
217 hex_quads[n_zero + i] = hex_quads[i];
219 for (i = 0; i < n_zero; i++)
220 hex_quads[double_colon_index + i] = 0;
222 n_hex_quads = ARRAY_LEN (hex_quads);
225 /* Too few hex quads given. */
226 if (n_hex_quads < ARRAY_LEN (hex_quads))
229 for (i = 0; i < ARRAY_LEN (hex_quads); i++)
230 result->as_u16[i] = clib_host_to_net_u16 (hex_quads[i]);
237 unformat_ipsec_policy_action (unformat_input_t * input, va_list * args)
240 u32 * r = va_arg (*args, u32 *);
243 #define _(v,f,s) else if (unformat (input, s)) *r = IPSEC_POLICY_ACTION_##f;
244 foreach_ipsec_policy_action
255 unformat_ipsec_crypto_alg (unformat_input_t * input, va_list * args)
258 u32 * r = va_arg (*args, u32 *);
261 #define _(v,f,s) else if (unformat (input, s)) *r = IPSEC_CRYPTO_ALG_##f;
262 foreach_ipsec_crypto_alg
273 format_ipsec_crypto_alg (u8 * s, va_list * args)
276 u32 i = va_arg (*args, u32);
281 #define _(v,f,str) case IPSEC_CRYPTO_ALG_##f: t = (u8 *) str; break;
282 foreach_ipsec_crypto_alg
285 return format (s, "unknown");
287 return format (s, "%s", t);
289 return format (s, "Unimplemented");
294 unformat_ipsec_integ_alg (unformat_input_t * input, va_list * args)
297 u32 * r = va_arg (*args, u32 *);
300 #define _(v,f,s) else if (unformat (input, s)) *r = IPSEC_INTEG_ALG_##f;
301 foreach_ipsec_integ_alg
312 format_ipsec_integ_alg (u8 * s, va_list * args)
315 u32 i = va_arg (*args, u32);
320 #define _(v,f,str) case IPSEC_INTEG_ALG_##f: t = (u8 *) str; break;
321 foreach_ipsec_integ_alg
324 return format (s, "unknown");
326 return format (s, "%s", t);
328 return format (s, "Unsupported");
333 unformat_ikev2_auth_method (unformat_input_t * input, va_list * args)
336 u32 * r = va_arg (*args, u32 *);
339 #define _(v,f,s) else if (unformat (input, s)) *r = IKEV2_AUTH_METHOD_##f;
340 foreach_ikev2_auth_method
351 unformat_ikev2_id_type (unformat_input_t * input, va_list * args)
354 u32 * r = va_arg (*args, u32 *);
357 #define _(v,f,s) else if (unformat (input, s)) *r = IKEV2_ID_TYPE_##f;
358 foreach_ikev2_id_type
369 unformat_policer_rate_type (unformat_input_t * input, va_list * args)
371 u8 * r = va_arg (*args, u8 *);
373 if (unformat (input, "kbps"))
374 *r = SSE2_QOS_RATE_KBPS;
375 else if (unformat(input, "pps"))
376 *r = SSE2_QOS_RATE_PPS;
383 unformat_policer_round_type (unformat_input_t * input, va_list * args)
385 u8 * r = va_arg (*args, u8 *);
387 if (unformat(input, "closest"))
388 *r = SSE2_QOS_ROUND_TO_CLOSEST;
389 else if (unformat (input, "up"))
390 *r = SSE2_QOS_ROUND_TO_UP;
391 else if (unformat (input, "down"))
392 *r = SSE2_QOS_ROUND_TO_DOWN;
399 unformat_policer_type (unformat_input_t * input, va_list * args)
401 u8 * r = va_arg (*args, u8 *);
403 if (unformat (input, "1r2c"))
404 *r = SSE2_QOS_POLICER_TYPE_1R2C;
405 else if (unformat (input, "1r3c"))
406 *r = SSE2_QOS_POLICER_TYPE_1R3C_RFC_2697;
407 else if (unformat (input, "2r3c-2698"))
408 *r = SSE2_QOS_POLICER_TYPE_2R3C_RFC_2698;
409 else if (unformat (input, "2r3c-4115"))
410 *r = SSE2_QOS_POLICER_TYPE_2R3C_RFC_4115;
411 else if (unformat (input, "2r3c-mef5cf1"))
412 *r = SSE2_QOS_POLICER_TYPE_2R3C_RFC_MEF5CF1;
418 u8 * format_ip4_address (u8 * s, va_list * args)
420 u8 * a = va_arg (*args, u8 *);
421 return format (s, "%d.%d.%d.%d", a[0], a[1], a[2], a[3]);
424 u8 * format_ip6_address (u8 * s, va_list * args)
426 ip6_address_t * a = va_arg (*args, ip6_address_t *);
427 u32 i, i_max_n_zero, max_n_zeros, i_first_zero, n_zeros, last_double_colon;
429 i_max_n_zero = ARRAY_LEN (a->as_u16);
431 i_first_zero = i_max_n_zero;
433 for (i = 0; i < ARRAY_LEN (a->as_u16); i++)
435 u32 is_zero = a->as_u16[i] == 0;
436 if (is_zero && i_first_zero >= ARRAY_LEN (a->as_u16))
442 if ((! is_zero && n_zeros > max_n_zeros)
443 || (i + 1 >= ARRAY_LEN (a->as_u16) && n_zeros > max_n_zeros))
445 i_max_n_zero = i_first_zero;
446 max_n_zeros = n_zeros;
447 i_first_zero = ARRAY_LEN (a->as_u16);
452 last_double_colon = 0;
453 for (i = 0; i < ARRAY_LEN (a->as_u16); i++)
455 if (i == i_max_n_zero && max_n_zeros > 1)
457 s = format (s, "::");
458 i += max_n_zeros - 1;
459 last_double_colon = 1;
463 s = format (s, "%s%x",
464 (last_double_colon || i == 0) ? "" : ":",
465 clib_net_to_host_u16 (a->as_u16[i]));
466 last_double_colon = 0;
473 /* Format an IP46 address. */
474 u8 * format_ip46_address (u8 * s, va_list * args)
476 ip46_address_t *ip46 = va_arg (*args, ip46_address_t *);
477 ip46_type_t type = va_arg (*args, ip46_type_t);
483 is_ip4 = ip46_address_is_ip4(ip46);
494 format(s, "%U", format_ip4_address, &ip46->ip4):
495 format(s, "%U", format_ip6_address, &ip46->ip6);
498 u8 * format_ethernet_address (u8 * s, va_list * args)
500 u8 * a = va_arg (*args, u8 *);
502 return format (s, "%02x:%02x:%02x:%02x:%02x:%02x",
503 a[0], a[1], a[2], a[3], a[4], a[5]);
506 void increment_v4_address (ip4_address_t * a)
510 v = ntohl(a->as_u32) + 1;
511 a->as_u32 = ntohl(v);
514 void increment_v6_address (ip6_address_t * a)
518 v0 = clib_net_to_host_u64 (a->as_u64[0]);
519 v1 = clib_net_to_host_u64 (a->as_u64[1]);
524 a->as_u64[0] = clib_net_to_host_u64 (v0);
525 a->as_u64[1] = clib_net_to_host_u64 (v1);
529 static void vl_api_create_loopback_reply_t_handler
530 (vl_api_create_loopback_reply_t * mp)
532 vat_main_t * vam = &vat_main;
533 i32 retval = ntohl(mp->retval);
535 vam->retval = retval;
536 vam->regenerate_interface_table = 1;
537 vam->sw_if_index = ntohl (mp->sw_if_index);
538 vam->result_ready = 1;
541 static void vl_api_create_loopback_reply_t_handler_json
542 (vl_api_create_loopback_reply_t * mp)
544 vat_main_t * vam = &vat_main;
545 vat_json_node_t node;
547 vat_json_init_object(&node);
548 vat_json_object_add_int(&node, "retval", ntohl(mp->retval));
549 vat_json_object_add_uint(&node, "sw_if_index", ntohl(mp->sw_if_index));
551 vat_json_print(vam->ofp, &node);
552 vat_json_free(&node);
553 vam->retval = ntohl(mp->retval);
554 vam->result_ready = 1;
557 static void vl_api_af_packet_create_reply_t_handler
558 (vl_api_af_packet_create_reply_t * mp)
560 vat_main_t * vam = &vat_main;
561 i32 retval = ntohl(mp->retval);
563 vam->retval = retval;
564 vam->regenerate_interface_table = 1;
565 vam->sw_if_index = ntohl (mp->sw_if_index);
566 vam->result_ready = 1;
569 static void vl_api_af_packet_create_reply_t_handler_json
570 (vl_api_af_packet_create_reply_t * mp)
572 vat_main_t * vam = &vat_main;
573 vat_json_node_t node;
575 vat_json_init_object(&node);
576 vat_json_object_add_int(&node, "retval", ntohl(mp->retval));
577 vat_json_object_add_uint(&node, "sw_if_index", ntohl(mp->sw_if_index));
579 vat_json_print(vam->ofp, &node);
580 vat_json_free(&node);
582 vam->retval = ntohl(mp->retval);
583 vam->result_ready = 1;
586 static void vl_api_create_vlan_subif_reply_t_handler
587 (vl_api_create_vlan_subif_reply_t * mp)
589 vat_main_t * vam = &vat_main;
590 i32 retval = ntohl(mp->retval);
592 vam->retval = retval;
593 vam->regenerate_interface_table = 1;
594 vam->sw_if_index = ntohl (mp->sw_if_index);
595 vam->result_ready = 1;
598 static void vl_api_create_vlan_subif_reply_t_handler_json
599 (vl_api_create_vlan_subif_reply_t * mp)
601 vat_main_t * vam = &vat_main;
602 vat_json_node_t node;
604 vat_json_init_object(&node);
605 vat_json_object_add_int(&node, "retval", ntohl(mp->retval));
606 vat_json_object_add_uint(&node, "sw_if_index", ntohl(mp->sw_if_index));
608 vat_json_print(vam->ofp, &node);
609 vat_json_free(&node);
611 vam->retval = ntohl(mp->retval);
612 vam->result_ready = 1;
615 static void vl_api_create_subif_reply_t_handler
616 (vl_api_create_subif_reply_t * mp)
618 vat_main_t * vam = &vat_main;
619 i32 retval = ntohl(mp->retval);
621 vam->retval = retval;
622 vam->regenerate_interface_table = 1;
623 vam->sw_if_index = ntohl (mp->sw_if_index);
624 vam->result_ready = 1;
627 static void vl_api_create_subif_reply_t_handler_json
628 (vl_api_create_subif_reply_t * mp)
630 vat_main_t * vam = &vat_main;
631 vat_json_node_t node;
633 vat_json_init_object(&node);
634 vat_json_object_add_int(&node, "retval", ntohl(mp->retval));
635 vat_json_object_add_uint(&node, "sw_if_index", ntohl(mp->sw_if_index));
637 vat_json_print(vam->ofp, &node);
638 vat_json_free(&node);
640 vam->retval = ntohl(mp->retval);
641 vam->result_ready = 1;
644 static void vl_api_interface_name_renumber_reply_t_handler
645 (vl_api_interface_name_renumber_reply_t * mp)
647 vat_main_t * vam = &vat_main;
648 i32 retval = ntohl(mp->retval);
650 vam->retval = retval;
651 vam->regenerate_interface_table = 1;
652 vam->result_ready = 1;
655 static void vl_api_interface_name_renumber_reply_t_handler_json
656 (vl_api_interface_name_renumber_reply_t * mp)
658 vat_main_t * vam = &vat_main;
659 vat_json_node_t node;
661 vat_json_init_object(&node);
662 vat_json_object_add_int(&node, "retval", ntohl(mp->retval));
664 vat_json_print(vam->ofp, &node);
665 vat_json_free(&node);
667 vam->retval = ntohl(mp->retval);
668 vam->result_ready = 1;
672 * Special-case: build the interface table, maintain
673 * the next loopback sw_if_index vbl.
675 static void vl_api_sw_interface_details_t_handler
676 (vl_api_sw_interface_details_t * mp)
678 vat_main_t * vam = &vat_main;
679 u8 * s = format (0, "%s%c", mp->interface_name, 0);
681 hash_set_mem (vam->sw_if_index_by_interface_name, s,
682 ntohl(mp->sw_if_index));
684 /* In sub interface case, fill the sub interface table entry */
685 if (mp->sw_if_index != mp->sup_sw_if_index) {
686 sw_interface_subif_t * sub = NULL;
688 vec_add2(vam->sw_if_subif_table, sub, 1);
690 vec_validate(sub->interface_name, strlen((char *)s) + 1);
691 strncpy((char *)sub->interface_name, (char *)s,
692 vec_len(sub->interface_name));
693 sub->sw_if_index = ntohl(mp->sw_if_index);
694 sub->sub_id = ntohl(mp->sub_id);
696 sub->sub_dot1ad = mp->sub_dot1ad;
697 sub->sub_number_of_tags = mp->sub_number_of_tags;
698 sub->sub_outer_vlan_id = ntohs(mp->sub_outer_vlan_id);
699 sub->sub_inner_vlan_id = ntohs(mp->sub_inner_vlan_id);
700 sub->sub_exact_match = mp->sub_exact_match;
701 sub->sub_default = mp->sub_default;
702 sub->sub_outer_vlan_id_any = mp->sub_outer_vlan_id_any;
703 sub->sub_inner_vlan_id_any = mp->sub_inner_vlan_id_any;
705 /* vlan tag rewrite */
706 sub->vtr_op = ntohl(mp->vtr_op);
707 sub->vtr_push_dot1q = ntohl(mp->vtr_push_dot1q);
708 sub->vtr_tag1 = ntohl(mp->vtr_tag1);
709 sub->vtr_tag2 = ntohl(mp->vtr_tag2);
713 static void vl_api_sw_interface_details_t_handler_json
714 (vl_api_sw_interface_details_t * mp)
716 vat_main_t * vam = &vat_main;
717 vat_json_node_t *node = NULL;
719 if (VAT_JSON_ARRAY != vam->json_tree.type) {
720 ASSERT(VAT_JSON_NONE == vam->json_tree.type);
721 vat_json_init_array(&vam->json_tree);
723 node = vat_json_array_add(&vam->json_tree);
725 vat_json_init_object(node);
726 vat_json_object_add_uint(node, "sw_if_index", ntohl(mp->sw_if_index));
727 vat_json_object_add_uint(node, "sup_sw_if_index", ntohl(mp->sup_sw_if_index));
728 vat_json_object_add_uint(node, "l2_address_length", ntohl(mp->l2_address_length));
729 vat_json_object_add_bytes(node, "l2_address", mp->l2_address, sizeof(mp->l2_address));
730 vat_json_object_add_string_copy(node, "interface_name", mp->interface_name);
731 vat_json_object_add_uint(node, "admin_up_down", mp->admin_up_down);
732 vat_json_object_add_uint(node, "link_up_down", mp->link_up_down);
733 vat_json_object_add_uint(node, "link_duplex", mp->link_duplex);
734 vat_json_object_add_uint(node, "link_speed", mp->link_speed);
735 vat_json_object_add_uint(node, "mtu", ntohs(mp->link_mtu));
736 vat_json_object_add_uint(node, "sub_id", ntohl(mp->sub_id));
737 vat_json_object_add_uint(node, "sub_dot1ad", mp->sub_dot1ad);
738 vat_json_object_add_uint(node, "sub_number_of_tags", mp->sub_number_of_tags);
739 vat_json_object_add_uint(node, "sub_outer_vlan_id", ntohs(mp->sub_outer_vlan_id));
740 vat_json_object_add_uint(node, "sub_inner_vlan_id", ntohs(mp->sub_inner_vlan_id));
741 vat_json_object_add_uint(node, "sub_exact_match", mp->sub_exact_match);
742 vat_json_object_add_uint(node, "sub_default", mp->sub_default);
743 vat_json_object_add_uint(node, "sub_outer_vlan_id_any", mp->sub_outer_vlan_id_any);
744 vat_json_object_add_uint(node, "sub_inner_vlan_id_any", mp->sub_inner_vlan_id_any);
745 vat_json_object_add_uint(node, "vtr_op", ntohl(mp->vtr_op));
746 vat_json_object_add_uint(node, "vtr_push_dot1q", ntohl(mp->vtr_push_dot1q));
747 vat_json_object_add_uint(node, "vtr_tag1", ntohl(mp->vtr_tag1));
748 vat_json_object_add_uint(node, "vtr_tag2", ntohl(mp->vtr_tag2));
751 static void vl_api_sw_interface_set_flags_t_handler
752 (vl_api_sw_interface_set_flags_t * mp)
754 vat_main_t * vam = &vat_main;
755 if (vam->interface_event_display)
756 errmsg ("interface flags: sw_if_index %d %s %s\n",
757 ntohl(mp->sw_if_index),
758 mp->admin_up_down ? "admin-up" : "admin-down",
759 mp->link_up_down ? "link-up" : "link-down");
762 static void vl_api_sw_interface_set_flags_t_handler_json
763 (vl_api_sw_interface_set_flags_t * mp)
765 /* JSON output not supported */
768 static void vl_api_cli_reply_t_handler
769 (vl_api_cli_reply_t * mp)
771 vat_main_t * vam = &vat_main;
772 i32 retval = ntohl(mp->retval);
774 vam->retval = retval;
775 vam->shmem_result = (u8 *) mp->reply_in_shmem;
776 vam->result_ready = 1;
779 static void vl_api_cli_reply_t_handler_json
780 (vl_api_cli_reply_t * mp)
782 vat_main_t * vam = &vat_main;
783 vat_json_node_t node;
784 api_main_t * am = &api_main;
788 vat_json_init_object(&node);
789 vat_json_object_add_int(&node, "retval", ntohl(mp->retval));
790 vat_json_object_add_uint(&node, "reply_in_shmem",
791 ntohl(mp->reply_in_shmem));
792 /* Toss the shared-memory original... */
793 pthread_mutex_lock (&am->vlib_rp->mutex);
794 oldheap = svm_push_data_heap (am->vlib_rp);
796 reply = (u8 *)(mp->reply_in_shmem);
799 svm_pop_heap (oldheap);
800 pthread_mutex_unlock (&am->vlib_rp->mutex);
802 vat_json_print(vam->ofp, &node);
803 vat_json_free(&node);
805 vam->retval = ntohl(mp->retval);
806 vam->result_ready = 1;
809 static void vl_api_classify_add_del_table_reply_t_handler
810 (vl_api_classify_add_del_table_reply_t * mp)
812 vat_main_t * vam = &vat_main;
813 i32 retval = ntohl(mp->retval);
814 if (vam->async_mode) {
815 vam->async_errors += (retval < 0);
817 vam->retval = retval;
819 ((mp->new_table_index != 0xFFFFFFFF) ||
820 (mp->skip_n_vectors != 0xFFFFFFFF) ||
821 (mp->match_n_vectors != 0xFFFFFFFF)))
823 * Note: this is just barely thread-safe, depends on
824 * the main thread spinning waiting for an answer...
826 errmsg ("new index %d, skip_n_vectors %d, match_n_vectors %d\n",
827 ntohl(mp->new_table_index),
828 ntohl(mp->skip_n_vectors), ntohl(mp->match_n_vectors));
829 vam->result_ready = 1;
833 static void vl_api_classify_add_del_table_reply_t_handler_json
834 (vl_api_classify_add_del_table_reply_t * mp)
836 vat_main_t * vam = &vat_main;
837 vat_json_node_t node;
839 vat_json_init_object(&node);
840 vat_json_object_add_int(&node, "retval", ntohl(mp->retval));
841 vat_json_object_add_uint(&node, "new_table_index", ntohl(mp->new_table_index));
842 vat_json_object_add_uint(&node, "skip_n_vectors", ntohl(mp->skip_n_vectors));
843 vat_json_object_add_uint(&node, "match_n_vectors", ntohl(mp->match_n_vectors));
845 vat_json_print(vam->ofp, &node);
846 vat_json_free(&node);
848 vam->retval = ntohl(mp->retval);
849 vam->result_ready = 1;
852 static void vl_api_get_node_index_reply_t_handler
853 (vl_api_get_node_index_reply_t * mp)
855 vat_main_t * vam = &vat_main;
856 i32 retval = ntohl(mp->retval);
857 if (vam->async_mode) {
858 vam->async_errors += (retval < 0);
860 vam->retval = retval;
862 errmsg ("node index %d\n", ntohl(mp->node_index));
863 vam->result_ready = 1;
867 static void vl_api_get_node_index_reply_t_handler_json
868 (vl_api_get_node_index_reply_t * mp)
870 vat_main_t * vam = &vat_main;
871 vat_json_node_t node;
873 vat_json_init_object(&node);
874 vat_json_object_add_int(&node, "retval", ntohl(mp->retval));
875 vat_json_object_add_uint(&node, "node_index", ntohl(mp->node_index));
877 vat_json_print(vam->ofp, &node);
878 vat_json_free(&node);
880 vam->retval = ntohl(mp->retval);
881 vam->result_ready = 1;
884 static void vl_api_add_node_next_reply_t_handler
885 (vl_api_add_node_next_reply_t * mp)
887 vat_main_t * vam = &vat_main;
888 i32 retval = ntohl(mp->retval);
889 if (vam->async_mode) {
890 vam->async_errors += (retval < 0);
892 vam->retval = retval;
894 errmsg ("next index %d\n", ntohl(mp->next_index));
895 vam->result_ready = 1;
899 static void vl_api_add_node_next_reply_t_handler_json
900 (vl_api_add_node_next_reply_t * mp)
902 vat_main_t * vam = &vat_main;
903 vat_json_node_t node;
905 vat_json_init_object(&node);
906 vat_json_object_add_int(&node, "retval", ntohl(mp->retval));
907 vat_json_object_add_uint(&node, "next_index", ntohl(mp->next_index));
909 vat_json_print(vam->ofp, &node);
910 vat_json_free(&node);
912 vam->retval = ntohl(mp->retval);
913 vam->result_ready = 1;
916 static void vl_api_mpls_gre_add_del_tunnel_reply_t_handler
917 (vl_api_mpls_gre_add_del_tunnel_reply_t * mp)
919 vat_main_t * vam = &vat_main;
920 i32 retval = ntohl(mp->retval);
921 u32 sw_if_index = ntohl(mp->tunnel_sw_if_index);
923 if (retval >= 0 && sw_if_index != (u32)~0) {
924 errmsg ("tunnel_sw_if_index %d\n", sw_if_index);
926 vam->retval = retval;
927 vam->result_ready = 1;
930 static void vl_api_mpls_gre_add_del_tunnel_reply_t_handler_json
931 (vl_api_mpls_gre_add_del_tunnel_reply_t * mp)
933 vat_main_t * vam = &vat_main;
934 vat_json_node_t node;
936 vat_json_init_object(&node);
937 vat_json_object_add_int(&node, "retval", ntohl(mp->retval));
938 vat_json_object_add_uint(&node, "tunnel_sw_if_index", ntohl(mp->tunnel_sw_if_index));
940 vat_json_print(vam->ofp, &node);
941 vat_json_free(&node);
943 vam->retval = ntohl(mp->retval);
944 vam->result_ready = 1;
948 static void vl_api_show_version_reply_t_handler
949 (vl_api_show_version_reply_t * mp)
951 vat_main_t * vam = &vat_main;
952 i32 retval = ntohl(mp->retval);
955 errmsg (" program: %s\n", mp->program);
956 errmsg (" version: %s\n", mp->version);
957 errmsg (" build date: %s\n", mp->build_date);
958 errmsg ("build directory: %s\n", mp->build_directory);
960 vam->retval = retval;
961 vam->result_ready = 1;
964 static void vl_api_show_version_reply_t_handler_json
965 (vl_api_show_version_reply_t * mp)
967 vat_main_t * vam = &vat_main;
968 vat_json_node_t node;
970 vat_json_init_object(&node);
971 vat_json_object_add_int(&node, "retval", ntohl(mp->retval));
972 vat_json_object_add_string_copy(&node, "program", mp->program);
973 vat_json_object_add_string_copy(&node, "version", mp->version);
974 vat_json_object_add_string_copy(&node, "build_date", mp->build_date);
975 vat_json_object_add_string_copy(&node, "build_directory", mp->build_directory);
977 vat_json_print(vam->ofp, &node);
978 vat_json_free(&node);
980 vam->retval = ntohl(mp->retval);
981 vam->result_ready = 1;
984 static void vl_api_ip4_arp_event_t_handler
985 (vl_api_ip4_arp_event_t * mp)
987 vat_main_t * vam = &vat_main;
988 errmsg ("arp event: address %U new mac %U sw_if_index %d\n",
989 format_ip4_address, &mp->address,
990 format_ethernet_address, mp->new_mac, mp->sw_if_index);
993 static void vl_api_ip4_arp_event_t_handler_json
994 (vl_api_ip4_arp_event_t * mp)
996 /* JSON output not supported */
1000 * Special-case: build the bridge domain table, maintain
1001 * the next bd id vbl.
1003 static void vl_api_bridge_domain_details_t_handler
1004 (vl_api_bridge_domain_details_t * mp)
1006 vat_main_t * vam = &vat_main;
1007 u32 n_sw_ifs = ntohl (mp->n_sw_ifs);
1009 fformat (vam->ofp, "\n%-3s %-3s %-3s %-3s %-3s %-3s\n",
1010 " ID", "LRN", "FWD", "FLD", "BVI", "#IF");
1012 fformat (vam->ofp, "%3d %3d %3d %3d %3d %3d\n",
1013 ntohl (mp->bd_id), mp->learn, mp->forward,
1014 mp->flood, ntohl (mp->bvi_sw_if_index), n_sw_ifs);
1017 fformat (vam->ofp, "\n\n%s %s %s\n", "sw_if_index", "SHG",
1021 static void vl_api_bridge_domain_details_t_handler_json
1022 (vl_api_bridge_domain_details_t * mp)
1024 vat_main_t * vam = &vat_main;
1025 vat_json_node_t *node, *array = NULL;
1027 if (VAT_JSON_ARRAY != vam->json_tree.type) {
1028 ASSERT(VAT_JSON_NONE == vam->json_tree.type);
1029 vat_json_init_array(&vam->json_tree);
1031 node = vat_json_array_add(&vam->json_tree);
1033 vat_json_init_object(node);
1034 vat_json_object_add_uint(node, "bd_id", ntohl(mp->bd_id));
1035 vat_json_object_add_uint(node, "flood", mp->flood);
1036 vat_json_object_add_uint(node, "forward", mp->forward);
1037 vat_json_object_add_uint(node, "learn", mp->learn);
1038 vat_json_object_add_uint(node, "bvi_sw_if_index", ntohl(mp->bvi_sw_if_index));
1039 vat_json_object_add_uint(node, "n_sw_ifs", ntohl(mp->n_sw_ifs));
1040 array = vat_json_object_add(node, "sw_if");
1041 vat_json_init_array(array);
1045 * Special-case: build the bridge domain sw if table.
1047 static void vl_api_bridge_domain_sw_if_details_t_handler
1048 (vl_api_bridge_domain_sw_if_details_t * mp)
1050 vat_main_t * vam = &vat_main;
1052 u8 * sw_if_name = 0;
1055 sw_if_index = ntohl (mp->sw_if_index);
1056 hash_foreach_pair (p, vam->sw_if_index_by_interface_name,
1058 if ((u32) p->value[0] == sw_if_index) {
1059 sw_if_name = (u8 *)(p->key);
1064 fformat (vam->ofp, "%7d %3d %s", sw_if_index,
1065 mp->shg, sw_if_name ? (char *)sw_if_name :
1066 "sw_if_index not found!");
1069 static void vl_api_bridge_domain_sw_if_details_t_handler_json
1070 (vl_api_bridge_domain_sw_if_details_t * mp)
1072 vat_main_t * vam = &vat_main;
1073 vat_json_node_t *node = NULL;
1074 uword last_index = 0;
1076 ASSERT(VAT_JSON_ARRAY == vam->json_tree.type);
1077 ASSERT(vec_len(vam->json_tree.array) >= 1);
1078 last_index = vec_len(vam->json_tree.array) - 1;
1079 node = &vam->json_tree.array[last_index];
1080 node = vat_json_object_get_element(node, "sw_if");
1081 ASSERT(NULL != node);
1082 node = vat_json_array_add(node);
1084 vat_json_init_object(node);
1085 vat_json_object_add_uint(node, "bd_id", ntohl(mp->bd_id));
1086 vat_json_object_add_uint(node, "sw_if_index", ntohl(mp->sw_if_index));
1087 vat_json_object_add_uint(node, "shg", mp->shg);
1090 static void vl_api_control_ping_reply_t_handler
1091 (vl_api_control_ping_reply_t * mp)
1093 vat_main_t * vam = &vat_main;
1094 i32 retval = ntohl(mp->retval);
1095 if (vam->async_mode) {
1096 vam->async_errors += (retval < 0);
1098 vam->retval = retval;
1099 vam->result_ready = 1;
1103 static void vl_api_control_ping_reply_t_handler_json
1104 (vl_api_control_ping_reply_t * mp)
1106 vat_main_t * vam = &vat_main;
1107 i32 retval = ntohl(mp->retval);
1109 if (VAT_JSON_NONE != vam->json_tree.type) {
1110 vat_json_print(vam->ofp, &vam->json_tree);
1111 vat_json_free(&vam->json_tree);
1112 vam->json_tree.type = VAT_JSON_NONE;
1115 vat_json_init_array(&vam->json_tree);
1116 vat_json_print(vam->ofp, &vam->json_tree);
1117 vam->json_tree.type = VAT_JSON_NONE;
1120 vam->retval = retval;
1121 vam->result_ready = 1;
1124 static void vl_api_l2_flags_reply_t_handler
1125 (vl_api_l2_flags_reply_t * mp)
1127 vat_main_t * vam = &vat_main;
1128 i32 retval = ntohl(mp->retval);
1129 if (vam->async_mode) {
1130 vam->async_errors += (retval < 0);
1132 vam->retval = retval;
1133 vam->result_ready = 1;
1137 static void vl_api_l2_flags_reply_t_handler_json
1138 (vl_api_l2_flags_reply_t * mp)
1140 vat_main_t * vam = &vat_main;
1141 vat_json_node_t node;
1143 vat_json_init_object(&node);
1144 vat_json_object_add_int(&node, "retval", ntohl(mp->retval));
1145 vat_json_object_add_uint(&node, "resulting_feature_bitmap", ntohl(mp->resulting_feature_bitmap));
1147 vat_json_print(vam->ofp, &node);
1148 vat_json_free(&node);
1150 vam->retval = ntohl(mp->retval);
1151 vam->result_ready = 1;
1154 static void vl_api_bridge_flags_reply_t_handler
1155 (vl_api_bridge_flags_reply_t * mp)
1157 vat_main_t * vam = &vat_main;
1158 i32 retval = ntohl(mp->retval);
1159 if (vam->async_mode) {
1160 vam->async_errors += (retval < 0);
1162 vam->retval = retval;
1163 vam->result_ready = 1;
1167 static void vl_api_bridge_flags_reply_t_handler_json
1168 (vl_api_bridge_flags_reply_t * mp)
1170 vat_main_t * vam = &vat_main;
1171 vat_json_node_t node;
1173 vat_json_init_object(&node);
1174 vat_json_object_add_int(&node, "retval", ntohl(mp->retval));
1175 vat_json_object_add_uint(&node, "resulting_feature_bitmap", ntohl(mp->resulting_feature_bitmap));
1177 vat_json_print(vam->ofp, &node);
1178 vat_json_free(&node);
1180 vam->retval = ntohl(mp->retval);
1181 vam->result_ready = 1;
1184 static void vl_api_tap_connect_reply_t_handler
1185 (vl_api_tap_connect_reply_t * mp)
1187 vat_main_t * vam = &vat_main;
1188 i32 retval = ntohl(mp->retval);
1189 if (vam->async_mode) {
1190 vam->async_errors += (retval < 0);
1192 vam->retval = retval;
1193 vam->sw_if_index = ntohl (mp->sw_if_index);
1194 vam->result_ready = 1;
1199 static void vl_api_tap_connect_reply_t_handler_json
1200 (vl_api_tap_connect_reply_t * mp)
1202 vat_main_t * vam = &vat_main;
1203 vat_json_node_t node;
1205 vat_json_init_object(&node);
1206 vat_json_object_add_int(&node, "retval", ntohl(mp->retval));
1207 vat_json_object_add_uint(&node, "sw_if_index", ntohl(mp->sw_if_index));
1209 vat_json_print(vam->ofp, &node);
1210 vat_json_free(&node);
1212 vam->retval = ntohl(mp->retval);
1213 vam->result_ready = 1;
1217 static void vl_api_tap_modify_reply_t_handler
1218 (vl_api_tap_modify_reply_t * mp)
1220 vat_main_t * vam = &vat_main;
1221 i32 retval = ntohl(mp->retval);
1222 if (vam->async_mode) {
1223 vam->async_errors += (retval < 0);
1225 vam->retval = retval;
1226 vam->sw_if_index = ntohl (mp->sw_if_index);
1227 vam->result_ready = 1;
1231 static void vl_api_tap_modify_reply_t_handler_json
1232 (vl_api_tap_modify_reply_t * mp)
1234 vat_main_t * vam = &vat_main;
1235 vat_json_node_t node;
1237 vat_json_init_object(&node);
1238 vat_json_object_add_int(&node, "retval", ntohl(mp->retval));
1239 vat_json_object_add_uint(&node, "sw_if_index", ntohl(mp->sw_if_index));
1241 vat_json_print(vam->ofp, &node);
1242 vat_json_free(&node);
1244 vam->retval = ntohl(mp->retval);
1245 vam->result_ready = 1;
1248 static void vl_api_tap_delete_reply_t_handler
1249 (vl_api_tap_delete_reply_t * mp)
1251 vat_main_t * vam = &vat_main;
1252 i32 retval = ntohl(mp->retval);
1253 if (vam->async_mode) {
1254 vam->async_errors += (retval < 0);
1256 vam->retval = retval;
1257 vam->result_ready = 1;
1261 static void vl_api_tap_delete_reply_t_handler_json
1262 (vl_api_tap_delete_reply_t * mp)
1264 vat_main_t * vam = &vat_main;
1265 vat_json_node_t node;
1267 vat_json_init_object(&node);
1268 vat_json_object_add_int(&node, "retval", ntohl(mp->retval));
1270 vat_json_print(vam->ofp, &node);
1271 vat_json_free(&node);
1273 vam->retval = ntohl(mp->retval);
1274 vam->result_ready = 1;
1277 static void vl_api_mpls_ethernet_add_del_tunnel_reply_t_handler
1278 (vl_api_mpls_ethernet_add_del_tunnel_reply_t * mp)
1280 vat_main_t * vam = &vat_main;
1281 i32 retval = ntohl(mp->retval);
1282 if (vam->async_mode) {
1283 vam->async_errors += (retval < 0);
1285 vam->retval = retval;
1286 vam->result_ready = 1;
1290 static void vl_api_mpls_ethernet_add_del_tunnel_reply_t_handler_json
1291 (vl_api_mpls_ethernet_add_del_tunnel_reply_t * mp)
1293 vat_main_t * vam = &vat_main;
1294 vat_json_node_t node;
1296 vat_json_init_object(&node);
1297 vat_json_object_add_int(&node, "retval", ntohl(mp->retval));
1298 vat_json_object_add_uint(&node, "tunnel_sw_if_index", ntohl(mp->tunnel_sw_if_index));
1300 vat_json_print(vam->ofp, &node);
1301 vat_json_free(&node);
1303 vam->retval = ntohl(mp->retval);
1304 vam->result_ready = 1;
1307 static void vl_api_l2tpv3_create_tunnel_reply_t_handler
1308 (vl_api_l2tpv3_create_tunnel_reply_t * mp)
1310 vat_main_t * vam = &vat_main;
1311 i32 retval = ntohl(mp->retval);
1312 if (vam->async_mode) {
1313 vam->async_errors += (retval < 0);
1315 vam->retval = retval;
1316 vam->sw_if_index = ntohl (mp->sw_if_index);
1317 vam->result_ready = 1;
1321 static void vl_api_l2tpv3_create_tunnel_reply_t_handler_json
1322 (vl_api_l2tpv3_create_tunnel_reply_t * mp)
1324 vat_main_t * vam = &vat_main;
1325 vat_json_node_t node;
1327 vat_json_init_object(&node);
1328 vat_json_object_add_int(&node, "retval", ntohl(mp->retval));
1329 vat_json_object_add_uint(&node, "sw_if_index", ntohl(mp->sw_if_index));
1331 vat_json_print(vam->ofp, &node);
1332 vat_json_free(&node);
1334 vam->retval = ntohl(mp->retval);
1335 vam->result_ready = 1;
1338 static void vl_api_vxlan_add_del_tunnel_reply_t_handler
1339 (vl_api_vxlan_add_del_tunnel_reply_t * mp)
1341 vat_main_t * vam = &vat_main;
1342 i32 retval = ntohl(mp->retval);
1343 if (vam->async_mode) {
1344 vam->async_errors += (retval < 0);
1346 vam->retval = retval;
1347 vam->sw_if_index = ntohl (mp->sw_if_index);
1348 vam->result_ready = 1;
1352 static void vl_api_vxlan_add_del_tunnel_reply_t_handler_json
1353 (vl_api_vxlan_add_del_tunnel_reply_t * mp)
1355 vat_main_t * vam = &vat_main;
1356 vat_json_node_t node;
1358 vat_json_init_object(&node);
1359 vat_json_object_add_int(&node, "retval", ntohl(mp->retval));
1360 vat_json_object_add_uint(&node, "sw_if_index", ntohl(mp->sw_if_index));
1362 vat_json_print(vam->ofp, &node);
1363 vat_json_free(&node);
1365 vam->retval = ntohl(mp->retval);
1366 vam->result_ready = 1;
1369 static void vl_api_gre_add_del_tunnel_reply_t_handler
1370 (vl_api_gre_add_del_tunnel_reply_t * mp)
1372 vat_main_t * vam = &vat_main;
1373 i32 retval = ntohl(mp->retval);
1374 if (vam->async_mode) {
1375 vam->async_errors += (retval < 0);
1377 vam->retval = retval;
1378 vam->sw_if_index = ntohl (mp->sw_if_index);
1379 vam->result_ready = 1;
1383 static void vl_api_gre_add_del_tunnel_reply_t_handler_json
1384 (vl_api_gre_add_del_tunnel_reply_t * mp)
1386 vat_main_t * vam = &vat_main;
1387 vat_json_node_t node;
1389 vat_json_init_object(&node);
1390 vat_json_object_add_int(&node, "retval", ntohl(mp->retval));
1391 vat_json_object_add_uint(&node, "sw_if_index", ntohl(mp->sw_if_index));
1393 vat_json_print(vam->ofp, &node);
1394 vat_json_free(&node);
1396 vam->retval = ntohl(mp->retval);
1397 vam->result_ready = 1;
1400 static void vl_api_create_vhost_user_if_reply_t_handler
1401 (vl_api_create_vhost_user_if_reply_t * mp)
1403 vat_main_t * vam = &vat_main;
1404 i32 retval = ntohl(mp->retval);
1405 if (vam->async_mode) {
1406 vam->async_errors += (retval < 0);
1408 vam->retval = retval;
1409 vam->sw_if_index = ntohl (mp->sw_if_index);
1410 vam->result_ready = 1;
1414 static void vl_api_create_vhost_user_if_reply_t_handler_json
1415 (vl_api_create_vhost_user_if_reply_t * mp)
1417 vat_main_t * vam = &vat_main;
1418 vat_json_node_t node;
1420 vat_json_init_object(&node);
1421 vat_json_object_add_int(&node, "retval", ntohl(mp->retval));
1422 vat_json_object_add_uint(&node, "sw_if_index", ntohl(mp->sw_if_index));
1424 vat_json_print(vam->ofp, &node);
1425 vat_json_free(&node);
1427 vam->retval = ntohl(mp->retval);
1428 vam->result_ready = 1;
1431 static void vl_api_ip_address_details_t_handler
1432 (vl_api_ip_address_details_t * mp)
1434 vat_main_t * vam = &vat_main;
1435 static ip_address_details_t empty_ip_address_details = {{0}};
1436 ip_address_details_t * address = NULL;
1437 ip_details_t * current_ip_details = NULL;
1438 ip_details_t * details = NULL;
1440 details = vam->ip_details_by_sw_if_index[vam->is_ipv6];
1442 if (!details || vam->current_sw_if_index >= vec_len(details)
1443 || !details[vam->current_sw_if_index].present) {
1444 errmsg ("ip address details arrived but not stored\n");
1445 errmsg ("ip_dump should be called first\n");
1449 current_ip_details = vec_elt_at_index(details,
1450 vam->current_sw_if_index);
1452 #define addresses (current_ip_details->addr)
1454 vec_validate_init_empty(addresses, vec_len(addresses),
1455 empty_ip_address_details);
1457 address = vec_elt_at_index(addresses, vec_len(addresses) - 1);
1459 clib_memcpy(&address->ip, &mp->ip, sizeof(address->ip));
1460 address->prefix_length = mp->prefix_length;
1464 static void vl_api_ip_address_details_t_handler_json
1465 (vl_api_ip_address_details_t * mp)
1467 vat_main_t * vam = &vat_main;
1468 vat_json_node_t *node = NULL;
1469 struct in6_addr ip6;
1472 if (VAT_JSON_ARRAY != vam->json_tree.type) {
1473 ASSERT(VAT_JSON_NONE == vam->json_tree.type);
1474 vat_json_init_array(&vam->json_tree);
1476 node = vat_json_array_add(&vam->json_tree);
1478 vat_json_init_object(node);
1480 clib_memcpy(&ip6, mp->ip, sizeof(ip6));
1481 vat_json_object_add_ip6(node, "ip", ip6);
1483 clib_memcpy(&ip4, mp->ip, sizeof(ip4));
1484 vat_json_object_add_ip4(node, "ip", ip4);
1486 vat_json_object_add_uint(node, "prefix_length", mp->prefix_length);
1489 static void vl_api_ip_details_t_handler (vl_api_ip_details_t * mp)
1491 vat_main_t * vam = &vat_main;
1492 static ip_details_t empty_ip_details = {0};
1493 ip_details_t * ip = NULL;
1494 u32 sw_if_index = ~0;
1496 sw_if_index = ntohl(mp->sw_if_index);
1498 vec_validate_init_empty(vam->ip_details_by_sw_if_index[vam->is_ipv6],
1499 sw_if_index, empty_ip_details);
1501 ip = vec_elt_at_index(vam->ip_details_by_sw_if_index[vam->is_ipv6],
1507 static void vl_api_ip_details_t_handler_json (vl_api_ip_details_t * mp)
1509 vat_main_t * vam = &vat_main;
1511 if (VAT_JSON_ARRAY != vam->json_tree.type) {
1512 ASSERT(VAT_JSON_NONE == vam->json_tree.type);
1513 vat_json_init_array(&vam->json_tree);
1515 vat_json_array_add_uint(&vam->json_tree, clib_net_to_host_u32(mp->sw_if_index));
1518 static void vl_api_map_domain_details_t_handler_json
1519 (vl_api_map_domain_details_t * mp)
1521 vat_json_node_t * node = NULL;
1522 vat_main_t * vam = &vat_main;
1523 struct in6_addr ip6;
1526 if (VAT_JSON_ARRAY != vam->json_tree.type) {
1527 ASSERT(VAT_JSON_NONE == vam->json_tree.type);
1528 vat_json_init_array(&vam->json_tree);
1531 node = vat_json_array_add(&vam->json_tree);
1532 vat_json_init_object(node);
1534 vat_json_object_add_uint(node, "domain_index", clib_net_to_host_u32(mp->domain_index));
1535 clib_memcpy(&ip6, mp->ip6_prefix, sizeof(ip6));
1536 vat_json_object_add_ip6(node, "ip6_prefix", ip6);
1537 clib_memcpy(&ip4, mp->ip4_prefix, sizeof(ip4));
1538 vat_json_object_add_ip4(node, "ip4_prefix", ip4);
1539 clib_memcpy(&ip6, mp->ip6_src, sizeof(ip6));
1540 vat_json_object_add_ip6(node, "ip6_src", ip6);
1541 vat_json_object_add_int(node, "ip6_prefix_len", mp->ip6_prefix_len);
1542 vat_json_object_add_int(node, "ip4_prefix_len", mp->ip4_prefix_len);
1543 vat_json_object_add_int(node, "ip6_src_len", mp->ip6_src_len);
1544 vat_json_object_add_int(node, "ea_bits_len", mp->ea_bits_len);
1545 vat_json_object_add_int(node, "psid_offset", mp->psid_offset);
1546 vat_json_object_add_int(node, "psid_length", mp->psid_length);
1547 vat_json_object_add_uint(node, "flags", mp->flags);
1548 vat_json_object_add_uint(node, "mtu", clib_net_to_host_u16(mp->mtu));
1549 vat_json_object_add_int(node, "is_translation", mp->is_translation);
1552 static void vl_api_map_domain_details_t_handler
1553 (vl_api_map_domain_details_t * mp)
1555 vat_main_t * vam = &vat_main;
1557 if (mp->is_translation) {
1558 fformat(vam->ofp, "* %U/%d (ipv4-prefix) %U/%d (ipv6-prefix) %U/%d (ip6-src) index: %u\n",
1559 format_ip4_address, mp->ip4_prefix, mp->ip4_prefix_len,
1560 format_ip6_address, mp->ip6_prefix, mp->ip6_prefix_len,
1561 format_ip6_address, mp->ip6_src, mp->ip6_src_len, clib_net_to_host_u32(mp->domain_index));
1563 fformat(vam->ofp, "* %U/%d (ipv4-prefix) %U/%d (ipv6-prefix) %U (ip6-src) index: %u\n",
1564 format_ip4_address, mp->ip4_prefix, mp->ip4_prefix_len,
1565 format_ip6_address, mp->ip6_prefix, mp->ip6_prefix_len,
1566 format_ip6_address, mp->ip6_src, clib_net_to_host_u32(mp->domain_index));
1568 fformat(vam->ofp, " ea-len %d psid-offset %d psid-len %d mtu %d %s\n",
1569 mp->ea_bits_len, mp->psid_offset, mp->psid_length, mp->mtu, mp->is_translation? "map-t":"");
1572 static void vl_api_map_rule_details_t_handler_json
1573 (vl_api_map_rule_details_t * mp)
1575 struct in6_addr ip6;
1576 vat_json_node_t * node = NULL;
1577 vat_main_t * vam = &vat_main;
1579 if (VAT_JSON_ARRAY != vam->json_tree.type) {
1580 ASSERT(VAT_JSON_NONE == vam->json_tree.type);
1581 vat_json_init_array(&vam->json_tree);
1584 node = vat_json_array_add(&vam->json_tree);
1585 vat_json_init_object(node);
1587 vat_json_object_add_uint(node, "psid", clib_net_to_host_u16(mp->psid));
1588 clib_memcpy(&ip6, mp->ip6_dst, sizeof(ip6));
1589 vat_json_object_add_ip6(node, "ip6_dst", ip6);
1592 static void vl_api_map_rule_details_t_handler
1593 (vl_api_map_rule_details_t * mp)
1595 vat_main_t * vam = &vat_main;
1596 fformat(vam->ofp, " %d (psid) %U (ip6-dst)\n", clib_net_to_host_u16(mp->psid),
1597 format_ip6_address, mp->ip6_dst);
1600 static void vl_api_dhcp_compl_event_t_handler
1601 (vl_api_dhcp_compl_event_t * mp)
1603 vat_main_t * vam = &vat_main;
1604 errmsg ("DHCP compl event: pid %d %s hostname %s host_addr %U "
1605 "router_addr %U host_mac %U\n",
1606 mp->pid, mp->is_ipv6 ? "ipv6":"ipv4", mp->hostname,
1607 format_ip4_address, &mp->host_address,
1608 format_ip4_address, &mp->router_address,
1609 format_ethernet_address, mp->host_mac);
1612 static void vl_api_dhcp_compl_event_t_handler_json
1613 (vl_api_dhcp_compl_event_t * mp)
1615 /* JSON output not supported */
1618 static void set_simple_interface_counter (u8 vnet_counter_type, u32 sw_if_index,
1621 vat_main_t * vam = &vat_main;
1622 static u64 default_counter = 0;
1624 vec_validate_init_empty(vam->simple_interface_counters, vnet_counter_type, NULL);
1625 vec_validate_init_empty(vam->simple_interface_counters[vnet_counter_type],
1626 sw_if_index, default_counter);
1627 vam->simple_interface_counters[vnet_counter_type][sw_if_index] = counter;
1630 static void set_combined_interface_counter (u8 vnet_counter_type, u32 sw_if_index,
1631 interface_counter_t counter)
1633 vat_main_t * vam = &vat_main;
1634 static interface_counter_t default_counter = {0, };
1636 vec_validate_init_empty(vam->combined_interface_counters, vnet_counter_type, NULL);
1637 vec_validate_init_empty(vam->combined_interface_counters[vnet_counter_type],
1638 sw_if_index, default_counter);
1639 vam->combined_interface_counters[vnet_counter_type][sw_if_index] = counter;
1642 static void vl_api_vnet_interface_counters_t_handler
1643 (vl_api_vnet_interface_counters_t *mp)
1648 static void vl_api_vnet_interface_counters_t_handler_json
1649 (vl_api_vnet_interface_counters_t *mp)
1651 interface_counter_t counter;
1656 u32 first_sw_if_index;
1659 count = ntohl(mp->count);
1660 first_sw_if_index = ntohl(mp->first_sw_if_index);
1662 if (!mp->is_combined) {
1663 v_packets = (u64*)&mp->data;
1664 for (i = 0; i < count; i++) {
1665 packets = clib_net_to_host_u64(clib_mem_unaligned(v_packets, u64));
1666 set_simple_interface_counter(mp->vnet_counter_type,
1667 first_sw_if_index + i, packets);
1671 v = (vlib_counter_t*)&mp->data;
1672 for (i = 0; i < count; i++) {
1673 counter.packets = clib_net_to_host_u64(
1674 clib_mem_unaligned(&v->packets, u64));
1675 counter.bytes = clib_net_to_host_u64(
1676 clib_mem_unaligned(&v->bytes, u64));
1677 set_combined_interface_counter(mp->vnet_counter_type,
1678 first_sw_if_index + i, counter);
1684 static u32 ip4_fib_counters_get_vrf_index_by_vrf_id (u32 vrf_id)
1686 vat_main_t * vam = &vat_main;
1689 for (i = 0; i < vec_len(vam->ip4_fib_counters_vrf_id_by_index); i++) {
1690 if (vam->ip4_fib_counters_vrf_id_by_index[i] == vrf_id) {
1697 static u32 ip6_fib_counters_get_vrf_index_by_vrf_id (u32 vrf_id)
1699 vat_main_t * vam = &vat_main;
1702 for (i = 0; i < vec_len(vam->ip6_fib_counters_vrf_id_by_index); i++) {
1703 if (vam->ip6_fib_counters_vrf_id_by_index[i] == vrf_id) {
1710 static void vl_api_vnet_ip4_fib_counters_t_handler
1711 (vl_api_vnet_ip4_fib_counters_t *mp)
1716 static void vl_api_vnet_ip4_fib_counters_t_handler_json
1717 (vl_api_vnet_ip4_fib_counters_t *mp)
1719 vat_main_t * vam = &vat_main;
1720 vl_api_ip4_fib_counter_t *v;
1721 ip4_fib_counter_t *counter;
1728 vrf_id = ntohl(mp->vrf_id);
1729 vrf_index = ip4_fib_counters_get_vrf_index_by_vrf_id(vrf_id);
1730 if (~0 == vrf_index) {
1731 vrf_index = vec_len(vam->ip4_fib_counters_vrf_id_by_index);
1732 vec_validate(vam->ip4_fib_counters_vrf_id_by_index, vrf_index);
1733 vam->ip4_fib_counters_vrf_id_by_index[vrf_index] = vrf_id;
1734 vec_validate(vam->ip4_fib_counters, vrf_index);
1735 vam->ip4_fib_counters[vrf_index] = NULL;
1738 vec_free(vam->ip4_fib_counters[vrf_index]);
1739 v = (vl_api_ip4_fib_counter_t*)&mp->c;
1740 count = ntohl(mp->count);
1741 for (i = 0; i < count; i++) {
1742 vec_validate(vam->ip4_fib_counters[vrf_index], i);
1743 counter = &vam->ip4_fib_counters[vrf_index][i];
1744 clib_memcpy(&ip4, &v->address, sizeof(ip4));
1745 counter->address = ip4;
1746 counter->address_length = v->address_length;
1747 counter->packets = clib_net_to_host_u64(v->packets);
1748 counter->bytes = clib_net_to_host_u64(v->bytes);
1753 static void vl_api_vnet_ip6_fib_counters_t_handler
1754 (vl_api_vnet_ip6_fib_counters_t *mp)
1759 static void vl_api_vnet_ip6_fib_counters_t_handler_json
1760 (vl_api_vnet_ip6_fib_counters_t *mp)
1762 vat_main_t * vam = &vat_main;
1763 vl_api_ip6_fib_counter_t *v;
1764 ip6_fib_counter_t *counter;
1765 struct in6_addr ip6;
1771 vrf_id = ntohl(mp->vrf_id);
1772 vrf_index = ip6_fib_counters_get_vrf_index_by_vrf_id(vrf_id);
1773 if (~0 == vrf_index) {
1774 vrf_index = vec_len(vam->ip6_fib_counters_vrf_id_by_index);
1775 vec_validate(vam->ip6_fib_counters_vrf_id_by_index, vrf_index);
1776 vam->ip6_fib_counters_vrf_id_by_index[vrf_index] = vrf_id;
1777 vec_validate(vam->ip6_fib_counters, vrf_index);
1778 vam->ip6_fib_counters[vrf_index] = NULL;
1781 vec_free(vam->ip6_fib_counters[vrf_index]);
1782 v = (vl_api_ip6_fib_counter_t*)&mp->c;
1783 count = ntohl(mp->count);
1784 for (i = 0; i < count; i++) {
1785 vec_validate(vam->ip6_fib_counters[vrf_index], i);
1786 counter = &vam->ip6_fib_counters[vrf_index][i];
1787 clib_memcpy(&ip6, &v->address, sizeof(ip6));
1788 counter->address = ip6;
1789 counter->address_length = v->address_length;
1790 counter->packets = clib_net_to_host_u64(v->packets);
1791 counter->bytes = clib_net_to_host_u64(v->bytes);
1796 static void vl_api_get_first_msg_id_reply_t_handler
1797 (vl_api_get_first_msg_id_reply_t * mp)
1799 vat_main_t * vam = &vat_main;
1800 i32 retval = ntohl(mp->retval);
1802 if (vam->async_mode) {
1803 vam->async_errors += (retval < 0);
1805 vam->retval = retval;
1806 vam->result_ready = 1;
1809 errmsg ("first message id %d\n", ntohs(mp->first_msg_id));
1813 static void vl_api_get_first_msg_id_reply_t_handler_json
1814 (vl_api_get_first_msg_id_reply_t * mp)
1816 vat_main_t * vam = &vat_main;
1817 vat_json_node_t node;
1819 vat_json_init_object(&node);
1820 vat_json_object_add_int(&node, "retval", ntohl(mp->retval));
1821 vat_json_object_add_uint(&node, "first_msg_id",
1822 (uint) ntohs(mp->first_msg_id));
1824 vat_json_print(vam->ofp, &node);
1825 vat_json_free(&node);
1827 vam->retval = ntohl(mp->retval);
1828 vam->result_ready = 1;
1831 static void vl_api_get_node_graph_reply_t_handler
1832 (vl_api_get_node_graph_reply_t * mp)
1834 vat_main_t * vam = &vat_main;
1835 api_main_t * am = &api_main;
1836 i32 retval = ntohl(mp->retval);
1837 u8 * pvt_copy, * reply;
1842 if (vam->async_mode) {
1843 vam->async_errors += (retval < 0);
1845 vam->retval = retval;
1846 vam->result_ready = 1;
1849 /* "Should never happen..." */
1853 reply = (u8 *)(mp->reply_in_shmem);
1854 pvt_copy = vec_dup (reply);
1856 /* Toss the shared-memory original... */
1857 pthread_mutex_lock (&am->vlib_rp->mutex);
1858 oldheap = svm_push_data_heap (am->vlib_rp);
1862 svm_pop_heap (oldheap);
1863 pthread_mutex_unlock (&am->vlib_rp->mutex);
1865 if (vam->graph_nodes) {
1866 hash_free (vam->graph_node_index_by_name);
1868 for (i = 0; i < vec_len (vam->graph_nodes); i++) {
1869 node = vam->graph_nodes[i];
1870 vec_free (node->name);
1871 vec_free (node->next_nodes);
1874 vec_free(vam->graph_nodes);
1877 vam->graph_node_index_by_name = hash_create_string (0, sizeof(uword));
1878 vam->graph_nodes = vlib_node_unserialize (pvt_copy);
1879 vec_free (pvt_copy);
1881 for (i = 0; i < vec_len (vam->graph_nodes); i++) {
1882 node = vam->graph_nodes[i];
1883 hash_set_mem (vam->graph_node_index_by_name, node->name, i);
1887 static void vl_api_get_node_graph_reply_t_handler_json
1888 (vl_api_get_node_graph_reply_t * mp)
1890 vat_main_t * vam = &vat_main;
1891 api_main_t * am = &api_main;
1893 vat_json_node_t node;
1896 /* $$$$ make this real? */
1897 vat_json_init_object(&node);
1898 vat_json_object_add_int(&node, "retval", ntohl(mp->retval));
1899 vat_json_object_add_uint(&node, "reply_in_shmem", mp->reply_in_shmem);
1901 reply = (u8 *)(mp->reply_in_shmem);
1903 /* Toss the shared-memory original... */
1904 pthread_mutex_lock (&am->vlib_rp->mutex);
1905 oldheap = svm_push_data_heap (am->vlib_rp);
1909 svm_pop_heap (oldheap);
1910 pthread_mutex_unlock (&am->vlib_rp->mutex);
1912 vat_json_print(vam->ofp, &node);
1913 vat_json_free(&node);
1915 vam->retval = ntohl(mp->retval);
1916 vam->result_ready = 1;
1920 vl_api_lisp_locator_set_details_t_handler (
1921 vl_api_lisp_locator_set_details_t *mp)
1923 vat_main_t *vam = &vat_main;
1924 u8 * tmp_str = NULL;
1927 fformat(vam->ofp, "%=20s%=16d%=16d%=16d\n",
1928 mp->locator_set_name,
1929 ntohl(mp->sw_if_index),
1933 tmp_str = format(0,"%U/%d",
1934 mp->is_ipv6 ? format_ip6_address : format_ip4_address,
1938 fformat(vam->ofp, "%=20s%=16s%=16d%=16d\n",
1939 mp->locator_set_name,
1948 vl_api_lisp_locator_set_details_t_handler_json (
1949 vl_api_lisp_locator_set_details_t *mp)
1951 vat_main_t *vam = &vat_main;
1952 vat_json_node_t *node = NULL;
1953 struct in6_addr ip6;
1956 if (VAT_JSON_ARRAY != vam->json_tree.type) {
1957 ASSERT(VAT_JSON_NONE == vam->json_tree.type);
1958 vat_json_init_array(&vam->json_tree);
1960 node = vat_json_array_add(&vam->json_tree);
1962 vat_json_init_object(node);
1963 vat_json_object_add_string_copy(node, "locator-set", mp->locator_set_name);
1965 vat_json_object_add_uint(node, "locator", ntohl(mp->sw_if_index));
1968 clib_memcpy(&ip6, mp->ip_address, sizeof(ip6));
1969 vat_json_object_add_ip6(node, "locator", ip6);
1971 clib_memcpy(&ip4, mp->ip_address, sizeof(ip4));
1972 vat_json_object_add_ip4(node, "locator", ip4);
1974 vat_json_object_add_uint(node, "prefix-length", mp->prefix_len);
1976 vat_json_object_add_uint(node, "priority", mp->priority);
1977 vat_json_object_add_uint(node, "weight", mp->weight);
1981 vl_api_lisp_local_eid_table_details_t_handler (
1982 vl_api_lisp_local_eid_table_details_t *mp)
1984 vat_main_t *vam = &vat_main;
1987 prefix = format(0, "%U/%d",
1988 mp->eid_is_ipv6 ? format_ip6_address : format_ip4_address,
1990 mp->eid_prefix_len);
1992 fformat(vam->ofp, "%=20s%=30s\n",
1993 mp->locator_set_name, prefix);
1999 vl_api_lisp_local_eid_table_details_t_handler_json (
2000 vl_api_lisp_local_eid_table_details_t *mp)
2002 vat_main_t *vam = &vat_main;
2003 vat_json_node_t *node = NULL;
2004 struct in6_addr ip6;
2007 if (VAT_JSON_ARRAY != vam->json_tree.type) {
2008 ASSERT(VAT_JSON_NONE == vam->json_tree.type);
2009 vat_json_init_array(&vam->json_tree);
2011 node = vat_json_array_add(&vam->json_tree);
2013 vat_json_init_object(node);
2014 vat_json_object_add_string_copy(node, "locator-set", mp->locator_set_name);
2015 if (mp->eid_is_ipv6) {
2016 clib_memcpy(&ip6, mp->eid_ip_address, sizeof(ip6));
2017 vat_json_object_add_ip6(node, "eid address", ip6);
2019 clib_memcpy(&ip4, mp->eid_ip_address, sizeof(ip4));
2020 vat_json_object_add_ip4(node, "eid address", ip4);
2022 vat_json_object_add_uint(node, "eid prefix len", mp->eid_prefix_len);
2026 format_decap_next (u8 * s, va_list * args)
2028 u32 next_index = va_arg (*args, u32);
2032 case LISP_GPE_INPUT_NEXT_DROP:
2033 return format (s, "drop");
2034 case LISP_GPE_INPUT_NEXT_IP4_INPUT:
2035 return format (s, "ip4");
2036 case LISP_GPE_INPUT_NEXT_IP6_INPUT:
2037 return format (s, "ip6");
2039 return format (s, "unknown %d", next_index);
2045 vl_api_lisp_gpe_tunnel_details_t_handler (vl_api_lisp_gpe_tunnel_details_t *mp)
2047 vat_main_t *vam = &vat_main;
2049 u8 *flag_str = NULL;
2051 iid_str = format(0, "%d (0x%x)", ntohl(mp->iid), ntohl(mp->iid));
2053 #define _(n,v) if (mp->flags & v) flag_str = format (flag_str, "%s-bit ", #n);
2054 foreach_lisp_gpe_flag_bit;
2057 fformat(vam->ofp, "%=20d%=30U%=16U%=16d%=16d%=16U"
2058 "%=16d%=16d%=16sd=16d%=16s%=16s\n",
2060 mp->is_ipv6 ? format_ip6_address : format_ip4_address,
2062 mp->is_ipv6 ? format_ip6_address : format_ip4_address,
2064 ntohl(mp->encap_fib_id),
2065 ntohl(mp->decap_fib_id),
2066 format_decap_next, ntohl(mp->dcap_next),
2078 vl_api_lisp_gpe_tunnel_details_t_handler_json (
2079 vl_api_lisp_gpe_tunnel_details_t *mp)
2081 vat_main_t *vam = &vat_main;
2082 vat_json_node_t *node = NULL;
2083 struct in6_addr ip6;
2087 next_decap_str = format(0, "%U", format_decap_next, htonl(mp->dcap_next));
2089 if (VAT_JSON_ARRAY != vam->json_tree.type) {
2090 ASSERT(VAT_JSON_NONE == vam->json_tree.type);
2091 vat_json_init_array(&vam->json_tree);
2093 node = vat_json_array_add(&vam->json_tree);
2095 vat_json_init_object(node);
2096 vat_json_object_add_uint(node, "tunel", mp->tunnels);
2098 clib_memcpy(&ip6, mp->source_ip, sizeof(ip6));
2099 vat_json_object_add_ip6(node, "source address", ip6);
2100 clib_memcpy(&ip6, mp->destination_ip, sizeof(ip6));
2101 vat_json_object_add_ip6(node, "destination address", ip6);
2103 clib_memcpy(&ip4, mp->source_ip, sizeof(ip4));
2104 vat_json_object_add_ip4(node, "source address", ip4);
2105 clib_memcpy(&ip4, mp->destination_ip, sizeof(ip4));
2106 vat_json_object_add_ip4(node, "destination address", ip4);
2108 vat_json_object_add_uint(node, "fib encap", ntohl(mp->encap_fib_id));
2109 vat_json_object_add_uint(node, "fib decap", ntohl(mp->decap_fib_id));
2110 vat_json_object_add_string_copy(node, "decap next", next_decap_str);
2111 vat_json_object_add_uint(node, "lisp version", mp->ver_res >> 6);
2112 vat_json_object_add_uint(node, "flags", mp->flags);
2113 vat_json_object_add_uint(node, "next protocol", mp->next_protocol);
2114 vat_json_object_add_uint(node, "ver_res", mp->ver_res);
2115 vat_json_object_add_uint(node, "res", mp->res);
2116 vat_json_object_add_uint(node, "iid", ntohl(mp->iid));
2118 vec_free(next_decap_str);
2122 vl_api_lisp_map_resolver_details_t_handler (
2123 vl_api_lisp_map_resolver_details_t *mp)
2125 vat_main_t *vam = &vat_main;
2127 fformat(vam->ofp, "%=20U\n",
2128 mp->is_ipv6 ? format_ip6_address : format_ip4_address,
2133 vl_api_lisp_map_resolver_details_t_handler_json (
2134 vl_api_lisp_map_resolver_details_t *mp)
2136 vat_main_t *vam = &vat_main;
2137 vat_json_node_t *node = NULL;
2138 struct in6_addr ip6;
2141 if (VAT_JSON_ARRAY != vam->json_tree.type) {
2142 ASSERT(VAT_JSON_NONE == vam->json_tree.type);
2143 vat_json_init_array(&vam->json_tree);
2145 node = vat_json_array_add(&vam->json_tree);
2147 vat_json_init_object(node);
2149 clib_memcpy(&ip6, mp->ip_address, sizeof(ip6));
2150 vat_json_object_add_ip6(node, "map resolver", ip6);
2152 clib_memcpy(&ip4, mp->ip_address, sizeof(ip4));
2153 vat_json_object_add_ip4(node, "map resolver", ip4);
2158 vl_api_lisp_enable_disable_status_details_t_handler
2159 (vl_api_lisp_enable_disable_status_details_t *mp)
2161 vat_main_t *vam = &vat_main;
2163 fformat(vam->ofp, "feature: %s\ngpe: %s\n",
2164 mp->feature_status ? "enabled" : "disabled",
2165 mp->gpe_status ? "enabled" : "disabled");
2169 vl_api_lisp_enable_disable_status_details_t_handler_json
2170 (vl_api_lisp_enable_disable_status_details_t *mp)
2172 vat_main_t *vam = &vat_main;
2173 vat_json_node_t *node = NULL;
2174 u8 * gpe_status = NULL;
2175 u8 * feature_status = NULL;
2177 gpe_status = format (0, "%s", mp->gpe_status ? "enabled" : "disabled");
2178 feature_status = format (0, "%s",
2179 mp->feature_status ? "enabled" : "disabled");
2180 vec_add1 (gpe_status, 0);
2181 vec_add1 (feature_status, 0);
2183 if (VAT_JSON_ARRAY != vam->json_tree.type) {
2184 ASSERT(VAT_JSON_NONE == vam->json_tree.type);
2185 vat_json_init_array(&vam->json_tree);
2187 node = vat_json_array_add(&vam->json_tree);
2189 vat_json_init_object(node);
2190 vat_json_object_add_string_copy(node, "gpe_status", gpe_status);
2191 vat_json_object_add_string_copy(node, "feature_status", feature_status);
2193 vec_free (gpe_status);
2194 vec_free (feature_status);
2198 vl_api_lisp_get_map_request_itr_rlocs_reply_t_handler (
2199 vl_api_lisp_get_map_request_itr_rlocs_reply_t * mp)
2201 vat_main_t * vam = &vat_main;
2202 i32 retval = ntohl(mp->retval);
2205 fformat(vam->ofp, "%=20s\n",
2206 mp->locator_set_name);
2209 vam->retval = retval;
2210 vam->result_ready = 1;
2214 vl_api_lisp_get_map_request_itr_rlocs_reply_t_handler_json (
2215 vl_api_lisp_get_map_request_itr_rlocs_reply_t * mp)
2217 vat_main_t * vam = &vat_main;
2218 vat_json_node_t * node = NULL;
2220 if (VAT_JSON_ARRAY != vam->json_tree.type) {
2221 ASSERT(VAT_JSON_NONE == vam->json_tree.type);
2222 vat_json_init_array(&vam->json_tree);
2224 node = vat_json_array_add(&vam->json_tree);
2226 vat_json_init_object(node);
2227 vat_json_object_add_string_copy(node, "itr-rlocs", mp->locator_set_name);
2229 vat_json_print(vam->ofp, node);
2230 vat_json_free(node);
2232 vam->retval = ntohl(mp->retval);
2233 vam->result_ready = 1;
2236 static u8 * format_policer_type (u8 * s, va_list * va)
2238 u32 i = va_arg (*va, u32);
2240 if (i == SSE2_QOS_POLICER_TYPE_1R2C)
2241 s = format (s, "1r2c");
2242 else if (i == SSE2_QOS_POLICER_TYPE_1R3C_RFC_2697)
2243 s = format (s, "1r3c");
2244 else if (i == SSE2_QOS_POLICER_TYPE_2R3C_RFC_2698)
2245 s = format (s, "2r3c-2698");
2246 else if (i == SSE2_QOS_POLICER_TYPE_2R3C_RFC_4115)
2247 s = format (s, "2r3c-4115");
2248 else if (i == SSE2_QOS_POLICER_TYPE_2R3C_RFC_MEF5CF1)
2249 s = format (s, "2r3c-mef5cf1");
2251 s = format (s, "ILLEGAL");
2255 static u8 * format_policer_rate_type (u8 * s, va_list * va)
2257 u32 i = va_arg (*va, u32);
2259 if (i == SSE2_QOS_RATE_KBPS)
2260 s = format (s, "kbps");
2261 else if (i == SSE2_QOS_RATE_PPS)
2262 s = format(s, "pps");
2264 s = format (s, "ILLEGAL");
2268 static u8 * format_policer_round_type (u8 * s, va_list * va)
2270 u32 i = va_arg (*va, u32);
2272 if (i == SSE2_QOS_ROUND_TO_CLOSEST)
2273 s = format(s, "closest");
2274 else if (i == SSE2_QOS_ROUND_TO_UP)
2275 s = format (s, "up");
2276 else if (i == SSE2_QOS_ROUND_TO_DOWN)
2277 s = format (s, "down");
2279 s = format (s, "ILLEGAL");
2283 static void vl_api_policer_details_t_handler
2284 (vl_api_policer_details_t * mp)
2286 vat_main_t * vam = &vat_main;
2288 fformat (vam->ofp, "Name \"%s\", type %U, cir %u, eir %u, cb %u, eb %u, "
2289 "rate type %U, round type %U, %s rate, %s color-aware, "
2290 "cir %u tok/period, pir %u tok/period, scale %u, cur lim %u, "
2291 "cur bkt %u, ext lim %u, ext bkt %u, last update %llu\n",
2293 format_policer_type, mp->type,
2298 format_policer_rate_type, mp->rate_type,
2299 format_policer_round_type, mp->round_type,
2300 mp->single_rate ? "single" : "dual",
2301 mp->color_aware ? "is" : "not",
2302 ntohl(mp->cir_tokens_per_period),
2303 ntohl(mp->pir_tokens_per_period),
2305 ntohl(mp->current_limit),
2306 ntohl(mp->current_bucket),
2307 ntohl(mp->extended_limit),
2308 ntohl(mp->extended_bucket),
2309 clib_net_to_host_u64(mp->last_update_time));
2312 static void vl_api_policer_details_t_handler_json
2313 (vl_api_policer_details_t * mp)
2315 vat_main_t * vam = &vat_main;
2316 vat_json_node_t *node;
2317 u8 *rate_type_str, *round_type_str, *type_str;
2319 rate_type_str = format(0, "%U", format_policer_rate_type, mp->rate_type);
2320 round_type_str = format(0, "%U", format_policer_round_type, mp->round_type);
2321 type_str = format(0, "%U", format_policer_type, mp->type);
2323 if (VAT_JSON_ARRAY != vam->json_tree.type) {
2324 ASSERT(VAT_JSON_NONE == vam->json_tree.type);
2325 vat_json_init_array(&vam->json_tree);
2327 node = vat_json_array_add(&vam->json_tree);
2329 vat_json_init_object(node);
2330 vat_json_object_add_string_copy(node, "name", mp->name);
2331 vat_json_object_add_uint(node, "cir", ntohl(mp->cir));
2332 vat_json_object_add_uint(node, "eir", ntohl(mp->eir));
2333 vat_json_object_add_uint(node, "cb", ntohl(mp->cb));
2334 vat_json_object_add_uint(node, "eb", ntohl(mp->eb));
2335 vat_json_object_add_string_copy(node, "rate_type", rate_type_str);
2336 vat_json_object_add_string_copy(node, "round_type", round_type_str);
2337 vat_json_object_add_string_copy(node, "type", type_str);
2338 vat_json_object_add_uint(node, "single_rate", mp->single_rate);
2339 vat_json_object_add_uint(node, "color_aware", mp->color_aware);
2340 vat_json_object_add_uint(node, "scale", ntohl(mp->scale));
2341 vat_json_object_add_uint(node, "cir_tokens_per_period",
2342 ntohl(mp->cir_tokens_per_period));
2343 vat_json_object_add_uint(node, "eir_tokens_per_period",
2344 ntohl(mp->pir_tokens_per_period));
2345 vat_json_object_add_uint(node, "current_limit", ntohl(mp->current_limit));
2346 vat_json_object_add_uint(node, "current_bucket", ntohl(mp->current_bucket));
2347 vat_json_object_add_uint(node, "extended_limit", ntohl(mp->extended_limit));
2348 vat_json_object_add_uint(node, "extended_bucket",
2349 ntohl(mp->extended_bucket));
2350 vat_json_object_add_uint(node, "last_update_time",
2351 ntohl(mp->last_update_time));
2353 vec_free(rate_type_str);
2354 vec_free(round_type_str);
2359 #define vl_api_vnet_ip4_fib_counters_t_endian vl_noop_handler
2360 #define vl_api_vnet_ip4_fib_counters_t_print vl_noop_handler
2361 #define vl_api_vnet_ip6_fib_counters_t_endian vl_noop_handler
2362 #define vl_api_vnet_ip6_fib_counters_t_print vl_noop_handler
2365 * Generate boilerplate reply handlers, which
2366 * dig the return value out of the xxx_reply_t API message,
2367 * stick it into vam->retval, and set vam->result_ready
2369 * Could also do this by pointing N message decode slots at
2370 * a single function, but that could break in subtle ways.
2373 #define foreach_standard_reply_retval_handler \
2374 _(sw_interface_set_flags_reply) \
2375 _(sw_interface_add_del_address_reply) \
2376 _(sw_interface_set_table_reply) \
2377 _(sw_interface_set_vpath_reply) \
2378 _(sw_interface_set_l2_bridge_reply) \
2379 _(bridge_domain_add_del_reply) \
2380 _(sw_interface_set_l2_xconnect_reply) \
2381 _(l2fib_add_del_reply) \
2382 _(ip_add_del_route_reply) \
2383 _(proxy_arp_add_del_reply) \
2384 _(proxy_arp_intfc_enable_disable_reply) \
2385 _(mpls_add_del_encap_reply) \
2386 _(mpls_add_del_decap_reply) \
2387 _(mpls_ethernet_add_del_tunnel_2_reply) \
2388 _(sw_interface_set_unnumbered_reply) \
2389 _(ip_neighbor_add_del_reply) \
2390 _(reset_vrf_reply) \
2391 _(oam_add_del_reply) \
2392 _(reset_fib_reply) \
2393 _(dhcp_proxy_config_reply) \
2394 _(dhcp_proxy_config_2_reply) \
2395 _(dhcp_proxy_set_vss_reply) \
2396 _(dhcp_client_config_reply) \
2397 _(set_ip_flow_hash_reply) \
2398 _(sw_interface_ip6_enable_disable_reply) \
2399 _(sw_interface_ip6_set_link_local_address_reply) \
2400 _(sw_interface_ip6nd_ra_prefix_reply) \
2401 _(sw_interface_ip6nd_ra_config_reply) \
2402 _(set_arp_neighbor_limit_reply) \
2403 _(l2_patch_add_del_reply) \
2404 _(sr_tunnel_add_del_reply) \
2405 _(sr_policy_add_del_reply) \
2406 _(sr_multicast_map_add_del_reply) \
2407 _(classify_add_del_session_reply) \
2408 _(classify_set_interface_ip_table_reply) \
2409 _(classify_set_interface_l2_tables_reply) \
2410 _(l2tpv3_set_tunnel_cookies_reply) \
2411 _(l2tpv3_interface_enable_disable_reply) \
2412 _(l2tpv3_set_lookup_key_reply) \
2413 _(l2_fib_clear_table_reply) \
2414 _(l2_interface_efp_filter_reply) \
2415 _(l2_interface_vlan_tag_rewrite_reply) \
2416 _(modify_vhost_user_if_reply) \
2417 _(delete_vhost_user_if_reply) \
2418 _(want_ip4_arp_events_reply) \
2419 _(input_acl_set_interface_reply) \
2420 _(ipsec_spd_add_del_reply) \
2421 _(ipsec_interface_add_del_spd_reply) \
2422 _(ipsec_spd_add_del_entry_reply) \
2423 _(ipsec_sad_add_del_entry_reply) \
2424 _(ipsec_sa_set_key_reply) \
2425 _(ikev2_profile_add_del_reply) \
2426 _(ikev2_profile_set_auth_reply) \
2427 _(ikev2_profile_set_id_reply) \
2428 _(ikev2_profile_set_ts_reply) \
2429 _(ikev2_set_local_key_reply) \
2430 _(delete_loopback_reply) \
2431 _(bd_ip_mac_add_del_reply) \
2432 _(map_del_domain_reply) \
2433 _(map_add_del_rule_reply) \
2434 _(want_interface_events_reply) \
2435 _(want_stats_reply) \
2436 _(cop_interface_enable_disable_reply) \
2437 _(cop_whitelist_enable_disable_reply) \
2438 _(sw_interface_clear_stats_reply) \
2439 _(trace_profile_add_reply) \
2440 _(trace_profile_apply_reply) \
2441 _(trace_profile_del_reply) \
2442 _(lisp_add_del_locator_set_reply) \
2443 _(lisp_add_del_locator_reply) \
2444 _(lisp_add_del_local_eid_reply) \
2445 _(lisp_gpe_add_del_fwd_entry_reply) \
2446 _(lisp_add_del_map_resolver_reply) \
2447 _(lisp_gpe_enable_disable_reply) \
2448 _(lisp_gpe_add_del_iface_reply) \
2449 _(lisp_enable_disable_reply) \
2450 _(lisp_pitr_set_locator_set_reply) \
2451 _(lisp_add_del_map_request_itr_rlocs_reply) \
2452 _(vxlan_gpe_add_del_tunnel_reply) \
2453 _(af_packet_delete_reply) \
2454 _(policer_add_del_reply) \
2455 _(netmap_create_reply) \
2456 _(netmap_delete_reply)
2459 static void vl_api_##n##_t_handler \
2460 (vl_api_##n##_t * mp) \
2462 vat_main_t * vam = &vat_main; \
2463 i32 retval = ntohl(mp->retval); \
2464 if (vam->async_mode) { \
2465 vam->async_errors += (retval < 0); \
2467 vam->retval = retval; \
2468 vam->result_ready = 1; \
2471 foreach_standard_reply_retval_handler;
2475 static void vl_api_##n##_t_handler_json \
2476 (vl_api_##n##_t * mp) \
2478 vat_main_t * vam = &vat_main; \
2479 vat_json_node_t node; \
2480 vat_json_init_object(&node); \
2481 vat_json_object_add_int(&node, "retval", ntohl(mp->retval)); \
2482 vat_json_print(vam->ofp, &node); \
2483 vam->retval = ntohl(mp->retval); \
2484 vam->result_ready = 1; \
2486 foreach_standard_reply_retval_handler;
2490 * Table of message reply handlers, must include boilerplate handlers
2494 #define foreach_vpe_api_reply_msg \
2495 _(CREATE_LOOPBACK_REPLY, create_loopback_reply) \
2496 _(SW_INTERFACE_DETAILS, sw_interface_details) \
2497 _(SW_INTERFACE_SET_FLAGS, sw_interface_set_flags) \
2498 _(SW_INTERFACE_SET_FLAGS_REPLY, sw_interface_set_flags_reply) \
2499 _(CONTROL_PING_REPLY, control_ping_reply) \
2500 _(CLI_REPLY, cli_reply) \
2501 _(SW_INTERFACE_ADD_DEL_ADDRESS_REPLY, \
2502 sw_interface_add_del_address_reply) \
2503 _(SW_INTERFACE_SET_TABLE_REPLY, sw_interface_set_table_reply) \
2504 _(SW_INTERFACE_SET_VPATH_REPLY, sw_interface_set_vpath_reply) \
2505 _(SW_INTERFACE_SET_L2_XCONNECT_REPLY, \
2506 sw_interface_set_l2_xconnect_reply) \
2507 _(SW_INTERFACE_SET_L2_BRIDGE_REPLY, \
2508 sw_interface_set_l2_bridge_reply) \
2509 _(BRIDGE_DOMAIN_ADD_DEL_REPLY, bridge_domain_add_del_reply) \
2510 _(BRIDGE_DOMAIN_DETAILS, bridge_domain_details) \
2511 _(BRIDGE_DOMAIN_SW_IF_DETAILS, bridge_domain_sw_if_details) \
2512 _(L2FIB_ADD_DEL_REPLY, l2fib_add_del_reply) \
2513 _(L2_FLAGS_REPLY, l2_flags_reply) \
2514 _(BRIDGE_FLAGS_REPLY, bridge_flags_reply) \
2515 _(TAP_CONNECT_REPLY, tap_connect_reply) \
2516 _(TAP_MODIFY_REPLY, tap_modify_reply) \
2517 _(TAP_DELETE_REPLY, tap_delete_reply) \
2518 _(SW_INTERFACE_TAP_DETAILS, sw_interface_tap_details) \
2519 _(IP_ADD_DEL_ROUTE_REPLY, ip_add_del_route_reply) \
2520 _(PROXY_ARP_ADD_DEL_REPLY, proxy_arp_add_del_reply) \
2521 _(PROXY_ARP_INTFC_ENABLE_DISABLE_REPLY, \
2522 proxy_arp_intfc_enable_disable_reply) \
2523 _(MPLS_ADD_DEL_ENCAP_REPLY, mpls_add_del_encap_reply) \
2524 _(MPLS_ADD_DEL_DECAP_REPLY, mpls_add_del_decap_reply) \
2525 _(MPLS_GRE_ADD_DEL_TUNNEL_REPLY, mpls_gre_add_del_tunnel_reply) \
2526 _(MPLS_ETHERNET_ADD_DEL_TUNNEL_REPLY, \
2527 mpls_ethernet_add_del_tunnel_reply) \
2528 _(MPLS_ETHERNET_ADD_DEL_TUNNEL_2_REPLY, \
2529 mpls_ethernet_add_del_tunnel_2_reply) \
2530 _(SW_INTERFACE_SET_UNNUMBERED_REPLY, \
2531 sw_interface_set_unnumbered_reply) \
2532 _(IP_NEIGHBOR_ADD_DEL_REPLY, ip_neighbor_add_del_reply) \
2533 _(RESET_VRF_REPLY, reset_vrf_reply) \
2534 _(CREATE_VLAN_SUBIF_REPLY, create_vlan_subif_reply) \
2535 _(CREATE_SUBIF_REPLY, create_subif_reply) \
2536 _(OAM_ADD_DEL_REPLY, oam_add_del_reply) \
2537 _(RESET_FIB_REPLY, reset_fib_reply) \
2538 _(DHCP_PROXY_CONFIG_REPLY, dhcp_proxy_config_reply) \
2539 _(DHCP_PROXY_CONFIG_2_REPLY, dhcp_proxy_config_2_reply) \
2540 _(DHCP_PROXY_SET_VSS_REPLY, dhcp_proxy_set_vss_reply) \
2541 _(DHCP_CLIENT_CONFIG_REPLY, dhcp_client_config_reply) \
2542 _(SET_IP_FLOW_HASH_REPLY, set_ip_flow_hash_reply) \
2543 _(SW_INTERFACE_IP6_ENABLE_DISABLE_REPLY, \
2544 sw_interface_ip6_enable_disable_reply) \
2545 _(SW_INTERFACE_IP6_SET_LINK_LOCAL_ADDRESS_REPLY, \
2546 sw_interface_ip6_set_link_local_address_reply) \
2547 _(SW_INTERFACE_IP6ND_RA_PREFIX_REPLY, \
2548 sw_interface_ip6nd_ra_prefix_reply) \
2549 _(SW_INTERFACE_IP6ND_RA_CONFIG_REPLY, \
2550 sw_interface_ip6nd_ra_config_reply) \
2551 _(SET_ARP_NEIGHBOR_LIMIT_REPLY, set_arp_neighbor_limit_reply) \
2552 _(L2_PATCH_ADD_DEL_REPLY, l2_patch_add_del_reply) \
2553 _(SR_TUNNEL_ADD_DEL_REPLY, sr_tunnel_add_del_reply) \
2554 _(SR_POLICY_ADD_DEL_REPLY, sr_policy_add_del_reply) \
2555 _(SR_MULTICAST_MAP_ADD_DEL_REPLY, sr_multicast_map_add_del_reply) \
2556 _(CLASSIFY_ADD_DEL_TABLE_REPLY, classify_add_del_table_reply) \
2557 _(CLASSIFY_ADD_DEL_SESSION_REPLY, classify_add_del_session_reply) \
2558 _(CLASSIFY_SET_INTERFACE_IP_TABLE_REPLY, \
2559 classify_set_interface_ip_table_reply) \
2560 _(CLASSIFY_SET_INTERFACE_L2_TABLES_REPLY, \
2561 classify_set_interface_l2_tables_reply) \
2562 _(GET_NODE_INDEX_REPLY, get_node_index_reply) \
2563 _(ADD_NODE_NEXT_REPLY, add_node_next_reply) \
2564 _(L2TPV3_CREATE_TUNNEL_REPLY, l2tpv3_create_tunnel_reply) \
2565 _(L2TPV3_SET_TUNNEL_COOKIES_REPLY, l2tpv3_set_tunnel_cookies_reply) \
2566 _(L2TPV3_INTERFACE_ENABLE_DISABLE_REPLY, \
2567 l2tpv3_interface_enable_disable_reply) \
2568 _(L2TPV3_SET_LOOKUP_KEY_REPLY, l2tpv3_set_lookup_key_reply) \
2569 _(SW_IF_L2TPV3_TUNNEL_DETAILS, sw_if_l2tpv3_tunnel_details) \
2570 _(VXLAN_ADD_DEL_TUNNEL_REPLY, vxlan_add_del_tunnel_reply) \
2571 _(VXLAN_TUNNEL_DETAILS, vxlan_tunnel_details) \
2572 _(GRE_ADD_DEL_TUNNEL_REPLY, gre_add_del_tunnel_reply) \
2573 _(GRE_TUNNEL_DETAILS, gre_tunnel_details) \
2574 _(L2_FIB_CLEAR_TABLE_REPLY, l2_fib_clear_table_reply) \
2575 _(L2_INTERFACE_EFP_FILTER_REPLY, l2_interface_efp_filter_reply) \
2576 _(L2_INTERFACE_VLAN_TAG_REWRITE_REPLY, l2_interface_vlan_tag_rewrite_reply) \
2577 _(SW_INTERFACE_VHOST_USER_DETAILS, sw_interface_vhost_user_details) \
2578 _(CREATE_VHOST_USER_IF_REPLY, create_vhost_user_if_reply) \
2579 _(MODIFY_VHOST_USER_IF_REPLY, modify_vhost_user_if_reply) \
2580 _(DELETE_VHOST_USER_IF_REPLY, delete_vhost_user_if_reply) \
2581 _(SHOW_VERSION_REPLY, show_version_reply) \
2582 _(L2_FIB_TABLE_ENTRY, l2_fib_table_entry) \
2583 _(VXLAN_GPE_ADD_DEL_TUNNEL_REPLY, vxlan_gpe_add_del_tunnel_reply) \
2584 _(VXLAN_GPE_TUNNEL_DETAILS, vxlan_gpe_tunnel_details) \
2585 _(INTERFACE_NAME_RENUMBER_REPLY, interface_name_renumber_reply) \
2586 _(WANT_IP4_ARP_EVENTS_REPLY, want_ip4_arp_events_reply) \
2587 _(IP4_ARP_EVENT, ip4_arp_event) \
2588 _(INPUT_ACL_SET_INTERFACE_REPLY, input_acl_set_interface_reply) \
2589 _(IP_ADDRESS_DETAILS, ip_address_details) \
2590 _(IP_DETAILS, ip_details) \
2591 _(IPSEC_SPD_ADD_DEL_REPLY, ipsec_spd_add_del_reply) \
2592 _(IPSEC_INTERFACE_ADD_DEL_SPD_REPLY, ipsec_interface_add_del_spd_reply) \
2593 _(IPSEC_SPD_ADD_DEL_ENTRY_REPLY, ipsec_spd_add_del_entry_reply) \
2594 _(IPSEC_SAD_ADD_DEL_ENTRY_REPLY, ipsec_sad_add_del_entry_reply) \
2595 _(IPSEC_SA_SET_KEY_REPLY, ipsec_sa_set_key_reply) \
2596 _(IKEV2_PROFILE_ADD_DEL_REPLY, ikev2_profile_add_del_reply) \
2597 _(IKEV2_PROFILE_SET_AUTH_REPLY, ikev2_profile_set_auth_reply) \
2598 _(IKEV2_PROFILE_SET_ID_REPLY, ikev2_profile_set_id_reply) \
2599 _(IKEV2_PROFILE_SET_TS_REPLY, ikev2_profile_set_ts_reply) \
2600 _(IKEV2_SET_LOCAL_KEY_REPLY, ikev2_set_local_key_reply) \
2601 _(DELETE_LOOPBACK_REPLY, delete_loopback_reply) \
2602 _(BD_IP_MAC_ADD_DEL_REPLY, bd_ip_mac_add_del_reply) \
2603 _(DHCP_COMPL_EVENT, dhcp_compl_event) \
2604 _(VNET_INTERFACE_COUNTERS, vnet_interface_counters) \
2605 _(VNET_IP4_FIB_COUNTERS, vnet_ip4_fib_counters) \
2606 _(VNET_IP6_FIB_COUNTERS, vnet_ip6_fib_counters) \
2607 _(MAP_ADD_DOMAIN_REPLY, map_add_domain_reply) \
2608 _(MAP_DEL_DOMAIN_REPLY, map_del_domain_reply) \
2609 _(MAP_ADD_DEL_RULE_REPLY, map_add_del_rule_reply) \
2610 _(MAP_DOMAIN_DETAILS, map_domain_details) \
2611 _(MAP_RULE_DETAILS, map_rule_details) \
2612 _(WANT_INTERFACE_EVENTS_REPLY, want_interface_events_reply) \
2613 _(WANT_STATS_REPLY, want_stats_reply) \
2614 _(GET_FIRST_MSG_ID_REPLY, get_first_msg_id_reply) \
2615 _(COP_INTERFACE_ENABLE_DISABLE_REPLY, cop_interface_enable_disable_reply) \
2616 _(COP_WHITELIST_ENABLE_DISABLE_REPLY, cop_whitelist_enable_disable_reply) \
2617 _(GET_NODE_GRAPH_REPLY, get_node_graph_reply) \
2618 _(SW_INTERFACE_CLEAR_STATS_REPLY, sw_interface_clear_stats_reply) \
2619 _(TRACE_PROFILE_ADD_REPLY, trace_profile_add_reply) \
2620 _(TRACE_PROFILE_APPLY_REPLY, trace_profile_apply_reply) \
2621 _(TRACE_PROFILE_DEL_REPLY, trace_profile_del_reply) \
2622 _(LISP_ADD_DEL_LOCATOR_SET_REPLY, lisp_add_del_locator_set_reply) \
2623 _(LISP_ADD_DEL_LOCATOR_REPLY, lisp_add_del_locator_reply) \
2624 _(LISP_ADD_DEL_LOCAL_EID_REPLY, lisp_add_del_local_eid_reply) \
2625 _(LISP_GPE_ADD_DEL_FWD_ENTRY_REPLY, lisp_gpe_add_del_fwd_entry_reply) \
2626 _(LISP_ADD_DEL_MAP_RESOLVER_REPLY, lisp_add_del_map_resolver_reply) \
2627 _(LISP_GPE_ENABLE_DISABLE_REPLY, lisp_gpe_enable_disable_reply) \
2628 _(LISP_ENABLE_DISABLE_REPLY, lisp_enable_disable_reply) \
2629 _(LISP_PITR_SET_LOCATOR_SET_REPLY, lisp_pitr_set_locator_set_reply) \
2630 _(LISP_GPE_ADD_DEL_IFACE_REPLY, lisp_gpe_add_del_iface_reply) \
2631 _(LISP_LOCATOR_SET_DETAILS, lisp_locator_set_details) \
2632 _(LISP_LOCAL_EID_TABLE_DETAILS, lisp_local_eid_table_details) \
2633 _(LISP_GPE_TUNNEL_DETAILS, lisp_gpe_tunnel_details) \
2634 _(LISP_MAP_RESOLVER_DETAILS, lisp_map_resolver_details) \
2635 _(LISP_ENABLE_DISABLE_STATUS_DETAILS, \
2636 lisp_enable_disable_status_details) \
2637 _(LISP_ADD_DEL_MAP_REQUEST_ITR_RLOCS_REPLY, \
2638 lisp_add_del_map_request_itr_rlocs_reply) \
2639 _(LISP_GET_MAP_REQUEST_ITR_RLOCS_REPLY, \
2640 lisp_get_map_request_itr_rlocs_reply) \
2641 _(AF_PACKET_CREATE_REPLY, af_packet_create_reply) \
2642 _(AF_PACKET_DELETE_REPLY, af_packet_delete_reply) \
2643 _(POLICER_ADD_DEL_REPLY, policer_add_del_reply) \
2644 _(POLICER_DETAILS, policer_details) \
2645 _(NETMAP_CREATE_REPLY, netmap_create_reply) \
2646 _(NETMAP_DELETE_REPLY, netmap_delete_reply)
2648 /* M: construct, but don't yet send a message */
2652 vam->result_ready = 0; \
2653 mp = vl_msg_api_alloc(sizeof(*mp)); \
2654 memset (mp, 0, sizeof (*mp)); \
2655 mp->_vl_msg_id = ntohs (VL_API_##T); \
2656 mp->client_index = vam->my_client_index; \
2661 vam->result_ready = 0; \
2662 mp = vl_msg_api_alloc(sizeof(*mp)+(n)); \
2663 memset (mp, 0, sizeof (*mp)); \
2664 mp->_vl_msg_id = ntohs (VL_API_##T); \
2665 mp->client_index = vam->my_client_index; \
2669 /* S: send a message */
2670 #define S (vl_msg_api_send_shmem (vam->vl_input_queue, (u8 *)&mp))
2672 /* W: wait for results, with timeout */
2675 timeout = vat_time_now (vam) + 1.0; \
2677 while (vat_time_now (vam) < timeout) { \
2678 if (vam->result_ready == 1) { \
2679 return (vam->retval); \
2685 /* W2: wait for results, with timeout */
2688 timeout = vat_time_now (vam) + 1.0; \
2690 while (vat_time_now (vam) < timeout) { \
2691 if (vam->result_ready == 1) { \
2693 return (vam->retval); \
2705 #define STR_VTR_OP_CASE(op) \
2706 case L2_VTR_ ## op: \
2709 static const char *str_vtr_op(u32 vtr_op)
2712 STR_VTR_OP_CASE(DISABLED);
2713 STR_VTR_OP_CASE(PUSH_1);
2714 STR_VTR_OP_CASE(PUSH_2);
2715 STR_VTR_OP_CASE(POP_1);
2716 STR_VTR_OP_CASE(POP_2);
2717 STR_VTR_OP_CASE(TRANSLATE_1_1);
2718 STR_VTR_OP_CASE(TRANSLATE_1_2);
2719 STR_VTR_OP_CASE(TRANSLATE_2_1);
2720 STR_VTR_OP_CASE(TRANSLATE_2_2);
2726 static int dump_sub_interface_table (vat_main_t * vam)
2728 const sw_interface_subif_t * sub = NULL;
2730 if (vam->json_output) {
2731 clib_warning ("JSON output supported only for VPE API calls and dump_stats_table");
2736 "%-30s%-12s%-11s%-7s%-5s%-9s%-9s%-6s%-8s%-10s%-10s\n",
2737 "Interface", "sw_if_index",
2738 "sub id", "dot1ad", "tags", "outer id",
2739 "inner id", "exact", "default",
2740 "outer any", "inner any");
2742 vec_foreach (sub, vam->sw_if_subif_table) {
2744 "%-30s%-12d%-11d%-7s%-5d%-9d%-9d%-6d%-8d%-10d%-10d\n",
2745 sub->interface_name,
2747 sub->sub_id, sub->sub_dot1ad ? "dot1ad" : "dot1q",
2748 sub->sub_number_of_tags, sub->sub_outer_vlan_id,
2749 sub->sub_inner_vlan_id, sub->sub_exact_match, sub->sub_default,
2750 sub->sub_outer_vlan_id_any, sub->sub_inner_vlan_id_any);
2751 if (sub->vtr_op != L2_VTR_DISABLED) {
2753 " vlan-tag-rewrite - op: %-14s [ dot1q: %d "
2754 "tag1: %d tag2: %d ]\n",
2755 str_vtr_op(sub->vtr_op), sub->vtr_push_dot1q,
2756 sub->vtr_tag1, sub->vtr_tag2);
2763 static int name_sort_cmp (void * a1, void * a2)
2765 name_sort_t * n1 = a1;
2766 name_sort_t * n2 = a2;
2768 return strcmp ((char *)n1->name, (char *)n2->name);
2771 static int dump_interface_table (vat_main_t * vam)
2774 name_sort_t * nses = 0, * ns;
2776 if (vam->json_output) {
2777 clib_warning ("JSON output supported only for VPE API calls and dump_stats_table");
2781 hash_foreach_pair (p, vam->sw_if_index_by_interface_name,
2783 vec_add2 (nses, ns, 1);
2784 ns->name = (u8 *)(p->key);
2785 ns->value = (u32) p->value[0];
2788 vec_sort_with_function (nses, name_sort_cmp);
2790 fformat (vam->ofp, "%-25s%-15s\n", "Interface", "sw_if_index");
2791 vec_foreach (ns, nses) {
2792 fformat (vam->ofp, "%-25s%-15d\n", ns->name, ns->value);
2798 static int dump_ip_table (vat_main_t * vam, int is_ipv6)
2800 const ip_details_t * det = NULL;
2801 const ip_address_details_t * address = NULL;
2812 vec_foreach (det, vam->ip_details_by_sw_if_index[is_ipv6]) {
2814 if (!det->present) {
2822 "Address", "Prefix length");
2826 vec_foreach (address, det->addr) {
2829 is_ipv6 ? format_ip6_address : format_ip4_address,
2831 address->prefix_length);
2838 static int dump_ipv4_table (vat_main_t * vam)
2840 if (vam->json_output) {
2841 clib_warning ("JSON output supported only for VPE API calls and dump_stats_table");
2845 return dump_ip_table (vam, 0);
2848 static int dump_ipv6_table (vat_main_t * vam)
2850 if (vam->json_output) {
2851 clib_warning ("JSON output supported only for VPE API calls and dump_stats_table");
2855 return dump_ip_table (vam, 1);
2858 static char* counter_type_to_str (u8 counter_type, u8 is_combined)
2861 switch(counter_type) {
2862 case VNET_INTERFACE_COUNTER_DROP:
2864 case VNET_INTERFACE_COUNTER_PUNT:
2866 case VNET_INTERFACE_COUNTER_IP4:
2868 case VNET_INTERFACE_COUNTER_IP6:
2870 case VNET_INTERFACE_COUNTER_RX_NO_BUF:
2872 case VNET_INTERFACE_COUNTER_RX_MISS:
2874 case VNET_INTERFACE_COUNTER_RX_ERROR:
2876 case VNET_INTERFACE_COUNTER_TX_ERROR:
2879 return "INVALID-COUNTER-TYPE";
2882 switch(counter_type) {
2883 case VNET_INTERFACE_COUNTER_RX:
2885 case VNET_INTERFACE_COUNTER_TX:
2888 return "INVALID-COUNTER-TYPE";
2893 static int dump_stats_table (vat_main_t * vam)
2895 vat_json_node_t node;
2896 vat_json_node_t *msg_array;
2897 vat_json_node_t *msg;
2898 vat_json_node_t *counter_array;
2899 vat_json_node_t *counter;
2900 interface_counter_t c;
2902 ip4_fib_counter_t *c4;
2903 ip6_fib_counter_t *c6;
2906 if (!vam->json_output) {
2907 clib_warning ("dump_stats_table supported only in JSON format");
2911 vat_json_init_object(&node);
2913 /* interface counters */
2914 msg_array = vat_json_object_add(&node, "interface_counters");
2915 vat_json_init_array(msg_array);
2916 for (i = 0; i < vec_len(vam->simple_interface_counters); i++) {
2917 msg = vat_json_array_add(msg_array);
2918 vat_json_init_object(msg);
2919 vat_json_object_add_string_copy(msg, "vnet_counter_type",
2920 (u8*)counter_type_to_str(i, 0));
2921 vat_json_object_add_int(msg, "is_combined", 0);
2922 counter_array = vat_json_object_add(msg, "data");
2923 vat_json_init_array(counter_array);
2924 for (j = 0; j < vec_len(vam->simple_interface_counters[i]); j++) {
2925 packets = vam->simple_interface_counters[i][j];
2926 vat_json_array_add_uint(counter_array, packets);
2929 for (i = 0; i < vec_len(vam->combined_interface_counters); i++) {
2930 msg = vat_json_array_add(msg_array);
2931 vat_json_init_object(msg);
2932 vat_json_object_add_string_copy(msg, "vnet_counter_type",
2933 (u8*)counter_type_to_str(i, 1));
2934 vat_json_object_add_int(msg, "is_combined", 1);
2935 counter_array = vat_json_object_add(msg, "data");
2936 vat_json_init_array(counter_array);
2937 for (j = 0; j < vec_len(vam->combined_interface_counters[i]); j++) {
2938 c = vam->combined_interface_counters[i][j];
2939 counter = vat_json_array_add(counter_array);
2940 vat_json_init_object(counter);
2941 vat_json_object_add_uint(counter, "packets", c.packets);
2942 vat_json_object_add_uint(counter, "bytes", c.bytes);
2946 /* ip4 fib counters */
2947 msg_array = vat_json_object_add(&node, "ip4_fib_counters");
2948 vat_json_init_array(msg_array);
2949 for (i = 0; i < vec_len(vam->ip4_fib_counters); i++) {
2950 msg = vat_json_array_add(msg_array);
2951 vat_json_init_object(msg);
2952 vat_json_object_add_uint(msg, "vrf_id", vam->ip4_fib_counters_vrf_id_by_index[i]);
2953 counter_array = vat_json_object_add(msg, "c");
2954 vat_json_init_array(counter_array);
2955 for (j = 0; j < vec_len(vam->ip4_fib_counters[i]); j++) {
2956 counter = vat_json_array_add(counter_array);
2957 vat_json_init_object(counter);
2958 c4 = &vam->ip4_fib_counters[i][j];
2959 vat_json_object_add_ip4(counter, "address", c4->address);
2960 vat_json_object_add_uint(counter, "address_length", c4->address_length);
2961 vat_json_object_add_uint(counter, "packets", c4->packets);
2962 vat_json_object_add_uint(counter, "bytes", c4->bytes);
2966 /* ip6 fib counters */
2967 msg_array = vat_json_object_add(&node, "ip6_fib_counters");
2968 vat_json_init_array(msg_array);
2969 for (i = 0; i < vec_len(vam->ip6_fib_counters); i++) {
2970 msg = vat_json_array_add(msg_array);
2971 vat_json_init_object(msg);
2972 vat_json_object_add_uint(msg, "vrf_id", vam->ip6_fib_counters_vrf_id_by_index[i]);
2973 counter_array = vat_json_object_add(msg, "c");
2974 vat_json_init_array(counter_array);
2975 for (j = 0; j < vec_len(vam->ip6_fib_counters[i]); j++) {
2976 counter = vat_json_array_add(counter_array);
2977 vat_json_init_object(counter);
2978 c6 = &vam->ip6_fib_counters[i][j];
2979 vat_json_object_add_ip6(counter, "address", c6->address);
2980 vat_json_object_add_uint(counter, "address_length", c6->address_length);
2981 vat_json_object_add_uint(counter, "packets", c6->packets);
2982 vat_json_object_add_uint(counter, "bytes", c6->bytes);
2986 vat_json_print(vam->ofp, &node);
2987 vat_json_free(&node);
2992 int exec (vat_main_t * vam)
2994 api_main_t * am = &api_main;
2995 vl_api_cli_request_t *mp;
2999 unformat_input_t * i = vam->input;
3001 if (vec_len(i->buffer) == 0)
3004 if (vam->exec_mode == 0 && unformat (i, "mode")) {
3008 if (vam->exec_mode == 1 &&
3009 (unformat (i, "exit") || unformat (i, "quit"))) {
3015 M(CLI_REQUEST, cli_request);
3018 * Copy cmd into shared memory.
3019 * In order for the CLI command to work, it
3020 * must be a vector ending in \n, not a C-string ending
3023 pthread_mutex_lock (&am->vlib_rp->mutex);
3024 oldheap = svm_push_data_heap (am->vlib_rp);
3026 vec_validate (cmd, vec_len(vam->input->buffer)-1);
3027 clib_memcpy (cmd, vam->input->buffer, vec_len(vam->input->buffer));
3029 svm_pop_heap (oldheap);
3030 pthread_mutex_unlock (&am->vlib_rp->mutex);
3032 mp->cmd_in_shmem = (u64) cmd;
3034 timeout = vat_time_now (vam) + 10.0;
3036 while (vat_time_now (vam) < timeout) {
3037 if (vam->result_ready == 1) {
3039 if (vam->shmem_result != NULL)
3040 fformat (vam->ofp, "%s", vam->shmem_result);
3041 pthread_mutex_lock (&am->vlib_rp->mutex);
3042 oldheap = svm_push_data_heap (am->vlib_rp);
3044 free_me = (u8 *)vam->shmem_result;
3047 svm_pop_heap (oldheap);
3048 pthread_mutex_unlock (&am->vlib_rp->mutex);
3055 static int api_create_loopback (vat_main_t * vam)
3057 unformat_input_t * i = vam->input;
3058 vl_api_create_loopback_t *mp;
3063 memset (mac_address, 0, sizeof (mac_address));
3065 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
3067 if (unformat (i, "mac %U", unformat_ethernet_address, mac_address))
3073 /* Construct the API message */
3074 M(CREATE_LOOPBACK, create_loopback);
3076 clib_memcpy (mp->mac_address, mac_address, sizeof (mac_address));
3081 static int api_delete_loopback (vat_main_t * vam)
3083 unformat_input_t * i = vam->input;
3084 vl_api_delete_loopback_t *mp;
3086 u32 sw_if_index = ~0;
3088 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
3090 if (unformat (i, "sw_if_index %d", &sw_if_index))
3096 if (sw_if_index == ~0)
3098 errmsg ("missing sw_if_index\n");
3102 /* Construct the API message */
3103 M(DELETE_LOOPBACK, delete_loopback);
3104 mp->sw_if_index = ntohl (sw_if_index);
3109 static int api_want_stats (vat_main_t * vam)
3111 unformat_input_t * i = vam->input;
3112 vl_api_want_stats_t * mp;
3116 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
3118 if (unformat (i, "enable"))
3120 else if (unformat (i, "disable"))
3128 errmsg ("missing enable|disable\n");
3132 M(WANT_STATS, want_stats);
3133 mp->enable_disable = enable;
3138 static int api_want_interface_events (vat_main_t * vam)
3140 unformat_input_t * i = vam->input;
3141 vl_api_want_interface_events_t * mp;
3145 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
3147 if (unformat (i, "enable"))
3149 else if (unformat (i, "disable"))
3157 errmsg ("missing enable|disable\n");
3161 M(WANT_INTERFACE_EVENTS, want_interface_events);
3162 mp->enable_disable = enable;
3164 vam->interface_event_display = enable;
3170 /* Note: non-static, called once to set up the initial intfc table */
3171 int api_sw_interface_dump (vat_main_t * vam)
3173 vl_api_sw_interface_dump_t *mp;
3176 name_sort_t * nses = 0, * ns;
3177 sw_interface_subif_t * sub = NULL;
3179 /* Toss the old name table */
3180 hash_foreach_pair (p, vam->sw_if_index_by_interface_name,
3182 vec_add2 (nses, ns, 1);
3183 ns->name = (u8 *)(p->key);
3184 ns->value = (u32) p->value[0];
3187 hash_free (vam->sw_if_index_by_interface_name);
3189 vec_foreach (ns, nses)
3190 vec_free (ns->name);
3194 vec_foreach (sub, vam->sw_if_subif_table) {
3195 vec_free (sub->interface_name);
3197 vec_free (vam->sw_if_subif_table);
3199 /* recreate the interface name hash table */
3200 vam->sw_if_index_by_interface_name
3201 = hash_create_string (0, sizeof(uword));
3203 /* Get list of ethernets */
3204 M(SW_INTERFACE_DUMP, sw_interface_dump);
3205 mp->name_filter_valid = 1;
3206 strncpy ((char *) mp->name_filter, "Ether", sizeof(mp->name_filter)-1);
3209 /* and local / loopback interfaces */
3210 M(SW_INTERFACE_DUMP, sw_interface_dump);
3211 mp->name_filter_valid = 1;
3212 strncpy ((char *) mp->name_filter, "lo", sizeof(mp->name_filter)-1);
3216 /* and vxlan-gpe tunnel interfaces */
3217 M(SW_INTERFACE_DUMP, sw_interface_dump);
3218 mp->name_filter_valid = 1;
3219 strncpy ((char *) mp->name_filter, "vxlan_gpe", sizeof(mp->name_filter)-1);
3222 /* and vxlan tunnel interfaces */
3223 M(SW_INTERFACE_DUMP, sw_interface_dump);
3224 mp->name_filter_valid = 1;
3225 strncpy ((char *) mp->name_filter, "vxlan", sizeof(mp->name_filter)-1);
3228 /* and host (af_packet) interfaces */
3229 M(SW_INTERFACE_DUMP, sw_interface_dump);
3230 mp->name_filter_valid = 1;
3231 strncpy ((char *) mp->name_filter, "host", sizeof(mp->name_filter)-1);
3234 /* and l2tpv3 tunnel interfaces */
3235 M(SW_INTERFACE_DUMP, sw_interface_dump);
3236 mp->name_filter_valid = 1;
3237 strncpy ((char *) mp->name_filter, "l2tpv3_tunnel", sizeof(mp->name_filter)-1);
3240 /* and GRE tunnel interfaces */
3241 M(SW_INTERFACE_DUMP, sw_interface_dump);
3242 mp->name_filter_valid = 1;
3243 strncpy ((char *) mp->name_filter, "gre", sizeof(mp->name_filter)-1);
3246 /* Use a control ping for synchronization */
3248 vl_api_control_ping_t * mp;
3249 M(CONTROL_PING, control_ping);
3255 static int api_sw_interface_set_flags (vat_main_t * vam)
3257 unformat_input_t * i = vam->input;
3258 vl_api_sw_interface_set_flags_t *mp;
3261 u8 sw_if_index_set = 0;
3262 u8 admin_up = 0, link_up = 0;
3264 /* Parse args required to build the message */
3265 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
3266 if (unformat (i, "admin-up"))
3268 else if (unformat (i, "admin-down"))
3270 else if (unformat (i, "link-up"))
3272 else if (unformat (i, "link-down"))
3274 else if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
3275 sw_if_index_set = 1;
3276 else if (unformat (i, "sw_if_index %d", &sw_if_index))
3277 sw_if_index_set = 1;
3282 if (sw_if_index_set == 0) {
3283 errmsg ("missing interface name or sw_if_index\n");
3287 /* Construct the API message */
3288 M(SW_INTERFACE_SET_FLAGS, sw_interface_set_flags);
3289 mp->sw_if_index = ntohl (sw_if_index);
3290 mp->admin_up_down = admin_up;
3291 mp->link_up_down = link_up;
3296 /* Wait for a reply, return the good/bad news... */
3300 static int api_sw_interface_clear_stats (vat_main_t * vam)
3302 unformat_input_t * i = vam->input;
3303 vl_api_sw_interface_clear_stats_t *mp;
3306 u8 sw_if_index_set = 0;
3308 /* Parse args required to build the message */
3309 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
3310 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
3311 sw_if_index_set = 1;
3312 else if (unformat (i, "sw_if_index %d", &sw_if_index))
3313 sw_if_index_set = 1;
3318 /* Construct the API message */
3319 M(SW_INTERFACE_CLEAR_STATS, sw_interface_clear_stats);
3321 if (sw_if_index_set == 1)
3322 mp->sw_if_index = ntohl (sw_if_index);
3324 mp->sw_if_index = ~0;
3329 /* Wait for a reply, return the good/bad news... */
3333 static int api_sw_interface_add_del_address (vat_main_t * vam)
3335 unformat_input_t * i = vam->input;
3336 vl_api_sw_interface_add_del_address_t *mp;
3339 u8 sw_if_index_set = 0;
3340 u8 is_add = 1, del_all = 0;
3341 u32 address_length = 0;
3342 u8 v4_address_set = 0;
3343 u8 v6_address_set = 0;
3344 ip4_address_t v4address;
3345 ip6_address_t v6address;
3347 /* Parse args required to build the message */
3348 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
3349 if (unformat (i, "del-all"))
3351 else if (unformat (i, "del"))
3353 else if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
3354 sw_if_index_set = 1;
3355 else if (unformat (i, "sw_if_index %d", &sw_if_index))
3356 sw_if_index_set = 1;
3357 else if (unformat (i, "%U/%d",
3358 unformat_ip4_address, &v4address,
3361 else if (unformat (i, "%U/%d",
3362 unformat_ip6_address, &v6address,
3369 if (sw_if_index_set == 0) {
3370 errmsg ("missing interface name or sw_if_index\n");
3373 if (v4_address_set && v6_address_set) {
3374 errmsg ("both v4 and v6 addresses set\n");
3377 if (!v4_address_set && !v6_address_set && !del_all) {
3378 errmsg ("no addresses set\n");
3382 /* Construct the API message */
3383 M(SW_INTERFACE_ADD_DEL_ADDRESS, sw_interface_add_del_address);
3385 mp->sw_if_index = ntohl (sw_if_index);
3386 mp->is_add = is_add;
3387 mp->del_all = del_all;
3388 if (v6_address_set) {
3390 clib_memcpy (mp->address, &v6address, sizeof (v6address));
3392 clib_memcpy (mp->address, &v4address, sizeof (v4address));
3394 mp->address_length = address_length;
3399 /* Wait for a reply, return good/bad news */
3403 static int api_sw_interface_set_table (vat_main_t * vam)
3405 unformat_input_t * i = vam->input;
3406 vl_api_sw_interface_set_table_t *mp;
3408 u32 sw_if_index, vrf_id = 0;
3409 u8 sw_if_index_set = 0;
3412 /* Parse args required to build the message */
3413 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
3414 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
3415 sw_if_index_set = 1;
3416 else if (unformat (i, "sw_if_index %d", &sw_if_index))
3417 sw_if_index_set = 1;
3418 else if (unformat (i, "vrf %d", &vrf_id))
3420 else if (unformat (i, "ipv6"))
3426 if (sw_if_index_set == 0) {
3427 errmsg ("missing interface name or sw_if_index\n");
3431 /* Construct the API message */
3432 M(SW_INTERFACE_SET_TABLE, sw_interface_set_table);
3434 mp->sw_if_index = ntohl (sw_if_index);
3435 mp->is_ipv6 = is_ipv6;
3436 mp->vrf_id = ntohl (vrf_id);
3441 /* Wait for a reply... */
3445 static int api_sw_interface_set_vpath (vat_main_t * vam)
3447 unformat_input_t * i = vam->input;
3448 vl_api_sw_interface_set_vpath_t *mp;
3450 u32 sw_if_index = 0;
3451 u8 sw_if_index_set = 0;
3454 /* Parse args required to build the message */
3455 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
3456 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;
3460 else if (unformat (i, "enable"))
3462 else if (unformat (i, "disable"))
3468 if (sw_if_index_set == 0) {
3469 errmsg ("missing interface name or sw_if_index\n");
3473 /* Construct the API message */
3474 M(SW_INTERFACE_SET_VPATH, sw_interface_set_vpath);
3476 mp->sw_if_index = ntohl (sw_if_index);
3477 mp->enable = is_enable;
3482 /* Wait for a reply... */
3486 static int api_sw_interface_set_l2_xconnect (vat_main_t * vam)
3488 unformat_input_t * i = vam->input;
3489 vl_api_sw_interface_set_l2_xconnect_t *mp;
3492 u8 rx_sw_if_index_set = 0;
3494 u8 tx_sw_if_index_set = 0;
3497 /* Parse args required to build the message */
3498 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
3499 if (unformat (i, "rx_sw_if_index %d", &rx_sw_if_index))
3500 rx_sw_if_index_set = 1;
3501 else if (unformat (i, "tx_sw_if_index %d", &tx_sw_if_index))
3502 tx_sw_if_index_set = 1;
3503 else if (unformat (i, "rx")) {
3504 if (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
3505 if (unformat (i, "%U", unformat_sw_if_index, vam,
3507 rx_sw_if_index_set = 1;
3510 } else if (unformat (i, "tx")) {
3511 if (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
3512 if (unformat (i, "%U", unformat_sw_if_index, vam,
3514 tx_sw_if_index_set = 1;
3517 } else if (unformat (i, "enable"))
3519 else if (unformat (i, "disable"))
3525 if (rx_sw_if_index_set == 0) {
3526 errmsg ("missing rx interface name or rx_sw_if_index\n");
3530 if (enable && (tx_sw_if_index_set == 0)) {
3531 errmsg ("missing tx interface name or tx_sw_if_index\n");
3535 M(SW_INTERFACE_SET_L2_XCONNECT, sw_interface_set_l2_xconnect);
3537 mp->rx_sw_if_index = ntohl(rx_sw_if_index);
3538 mp->tx_sw_if_index = ntohl(tx_sw_if_index);
3539 mp->enable = enable;
3546 static int api_sw_interface_set_l2_bridge (vat_main_t * vam)
3548 unformat_input_t * i = vam->input;
3549 vl_api_sw_interface_set_l2_bridge_t *mp;
3552 u8 rx_sw_if_index_set = 0;
3559 /* Parse args required to build the message */
3560 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
3561 if (unformat (i, "sw_if_index %d", &rx_sw_if_index))
3562 rx_sw_if_index_set = 1;
3563 else if (unformat (i, "bd_id %d", &bd_id))
3565 else if (unformat (i, "%U", unformat_sw_if_index, vam,
3567 rx_sw_if_index_set = 1;
3568 else if (unformat (i, "shg %d", &shg))
3570 else if (unformat (i, "bvi"))
3572 else if (unformat (i, "enable"))
3574 else if (unformat (i, "disable"))
3580 if (rx_sw_if_index_set == 0) {
3581 errmsg ("missing rx interface name or sw_if_index\n");
3585 if (enable && (bd_id_set == 0)) {
3586 errmsg ("missing bridge domain\n");
3590 M(SW_INTERFACE_SET_L2_BRIDGE, sw_interface_set_l2_bridge);
3592 mp->rx_sw_if_index = ntohl(rx_sw_if_index);
3593 mp->bd_id = ntohl(bd_id);
3596 mp->enable = enable;
3603 static int api_bridge_domain_dump (vat_main_t * vam)
3605 unformat_input_t * i = vam->input;
3606 vl_api_bridge_domain_dump_t *mp;
3610 /* Parse args required to build the message */
3611 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
3612 if (unformat (i, "bd_id %d", &bd_id))
3618 M(BRIDGE_DOMAIN_DUMP, bridge_domain_dump);
3619 mp->bd_id = ntohl(bd_id);
3622 /* Use a control ping for synchronization */
3624 vl_api_control_ping_t * mp;
3625 M(CONTROL_PING, control_ping);
3634 static int api_bridge_domain_add_del (vat_main_t * vam)
3636 unformat_input_t * i = vam->input;
3637 vl_api_bridge_domain_add_del_t *mp;
3641 u32 flood = 1, forward = 1, learn = 1, uu_flood = 1, arp_term = 0;
3643 /* Parse args required to build the message */
3644 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
3645 if (unformat (i, "bd_id %d", &bd_id))
3647 else if (unformat (i, "flood %d", &flood))
3649 else if (unformat (i, "uu-flood %d", &uu_flood))
3651 else if (unformat (i, "forward %d", &forward))
3653 else if (unformat (i, "learn %d", &learn))
3655 else if (unformat (i, "arp-term %d", &arp_term))
3657 else if (unformat (i, "del")) {
3659 flood = uu_flood = forward = learn = 0;
3666 errmsg ("missing bridge domain\n");
3670 M(BRIDGE_DOMAIN_ADD_DEL, bridge_domain_add_del);
3672 mp->bd_id = ntohl(bd_id);
3674 mp->uu_flood = uu_flood;
3675 mp->forward = forward;
3677 mp->arp_term = arp_term;
3678 mp->is_add = is_add;
3685 static int api_l2fib_add_del (vat_main_t * vam)
3687 unformat_input_t * i = vam->input;
3688 vl_api_l2fib_add_del_t *mp;
3695 u8 sw_if_index_set = 0;
3700 /* Parse args required to build the message */
3701 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
3702 if (unformat (i, "mac %U", unformat_ethernet_address, &mac))
3704 else if (unformat (i, "bd_id %d", &bd_id))
3706 else if (unformat (i, "sw_if_index %d", &sw_if_index))
3707 sw_if_index_set = 1;
3708 else if (unformat (i, "sw_if")) {
3709 if (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
3710 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
3711 sw_if_index_set = 1;
3714 } else if (unformat (i, "static"))
3716 else if (unformat (i, "filter")) {
3719 } else if (unformat (i, "del"))
3726 errmsg ("missing mac address\n");
3730 if (bd_id_set == 0) {
3731 errmsg ("missing bridge domain\n");
3735 if (is_add && (sw_if_index_set == 0)) {
3736 errmsg ("missing interface name or sw_if_index\n");
3740 M(L2FIB_ADD_DEL, l2fib_add_del);
3743 mp->bd_id = ntohl(bd_id);
3744 mp->is_add = is_add;
3747 mp->sw_if_index = ntohl(sw_if_index);
3748 mp->static_mac = static_mac;
3749 mp->filter_mac = filter_mac;
3757 static int api_l2_flags (vat_main_t * vam)
3759 unformat_input_t * i = vam->input;
3760 vl_api_l2_flags_t *mp;
3763 u32 feature_bitmap = 0;
3764 u8 sw_if_index_set = 0;
3766 /* Parse args required to build the message */
3767 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
3768 if (unformat (i, "sw_if_index %d", &sw_if_index))
3769 sw_if_index_set = 1;
3770 else if (unformat (i, "sw_if")) {
3771 if (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
3772 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
3773 sw_if_index_set = 1;
3776 } else if (unformat (i, "learn"))
3777 feature_bitmap |= L2INPUT_FEAT_LEARN;
3778 else if (unformat (i, "forward"))
3779 feature_bitmap |= L2INPUT_FEAT_FWD;
3780 else if (unformat (i, "flood"))
3781 feature_bitmap |= L2INPUT_FEAT_FLOOD;
3782 else if (unformat (i, "uu-flood"))
3783 feature_bitmap |= L2INPUT_FEAT_UU_FLOOD;
3788 if (sw_if_index_set == 0) {
3789 errmsg ("missing interface name or sw_if_index\n");
3793 M(L2_FLAGS, l2_flags);
3795 mp->sw_if_index = ntohl(sw_if_index);
3796 mp->feature_bitmap = ntohl(feature_bitmap);
3803 static int api_bridge_flags (vat_main_t * vam)
3805 unformat_input_t * i = vam->input;
3806 vl_api_bridge_flags_t *mp;
3813 /* Parse args required to build the message */
3814 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
3815 if (unformat (i, "bd_id %d", &bd_id))
3817 else if (unformat (i, "learn"))
3819 else if (unformat (i, "forward"))
3821 else if (unformat (i, "flood"))
3823 else if (unformat (i, "uu-flood"))
3824 flags |= L2_UU_FLOOD;
3825 else if (unformat (i, "arp-term"))
3826 flags |= L2_ARP_TERM;
3827 else if (unformat (i, "off"))
3829 else if (unformat (i, "disable"))
3835 if (bd_id_set == 0) {
3836 errmsg ("missing bridge domain\n");
3840 M(BRIDGE_FLAGS, bridge_flags);
3842 mp->bd_id = ntohl(bd_id);
3843 mp->feature_bitmap = ntohl(flags);
3844 mp->is_set = is_set;
3851 static int api_bd_ip_mac_add_del (vat_main_t * vam)
3853 unformat_input_t * i = vam->input;
3854 vl_api_bd_ip_mac_add_del_t *mp;
3862 ip4_address_t v4addr;
3863 ip6_address_t v6addr;
3867 /* Parse args required to build the message */
3868 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
3869 if (unformat (i, "bd_id %d", &bd_id)) {
3871 } else if (unformat (i, "%U", unformat_ip4_address, &v4addr)) {
3873 } else if (unformat (i, "%U", unformat_ip6_address, &v6addr)) {
3876 } else if (unformat (i, "%U", unformat_ethernet_address, macaddr)) {
3878 } else if (unformat (i, "del"))
3884 if (bd_id_set == 0) {
3885 errmsg ("missing bridge domain\n");
3887 } else if (ip_set == 0) {
3888 errmsg ("missing IP address\n");
3890 } else if (mac_set == 0) {
3891 errmsg ("missing MAC address\n");
3895 M(BD_IP_MAC_ADD_DEL, bd_ip_mac_add_del);
3897 mp->bd_id = ntohl(bd_id);
3898 mp->is_ipv6 = is_ipv6;
3899 mp->is_add = is_add;
3901 clib_memcpy (mp->ip_address, &v6addr, sizeof (v6addr));
3902 else clib_memcpy (mp->ip_address, &v4addr, sizeof (v4addr));
3903 clib_memcpy (mp->mac_address, macaddr, 6);
3909 static int api_tap_connect (vat_main_t * vam)
3911 unformat_input_t * i = vam->input;
3912 vl_api_tap_connect_t *mp;
3919 memset (mac_address, 0, sizeof (mac_address));
3921 /* Parse args required to build the message */
3922 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
3923 if (unformat (i, "mac %U", unformat_ethernet_address, mac_address)) {
3926 else if (unformat (i, "random-mac"))
3928 else if (unformat (i, "tapname %s", &tap_name))
3934 if (name_set == 0) {
3935 errmsg ("missing tap name\n");
3938 if (vec_len (tap_name) > 63) {
3939 errmsg ("tap name too long\n");
3941 vec_add1 (tap_name, 0);
3943 /* Construct the API message */
3944 M(TAP_CONNECT, tap_connect);
3946 mp->use_random_mac = random_mac;
3947 clib_memcpy (mp->mac_address, mac_address, 6);
3948 clib_memcpy (mp->tap_name, tap_name, vec_len (tap_name));
3949 vec_free (tap_name);
3954 /* Wait for a reply... */
3958 static int api_tap_modify (vat_main_t * vam)
3960 unformat_input_t * i = vam->input;
3961 vl_api_tap_modify_t *mp;
3967 u32 sw_if_index = ~0;
3968 u8 sw_if_index_set = 0;
3970 memset (mac_address, 0, sizeof (mac_address));
3972 /* Parse args required to build the message */
3973 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
3974 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
3975 sw_if_index_set = 1;
3976 else if (unformat (i, "sw_if_index %d", &sw_if_index))
3977 sw_if_index_set = 1;
3978 else if (unformat (i, "mac %U", unformat_ethernet_address, mac_address)) {
3981 else if (unformat (i, "random-mac"))
3983 else if (unformat (i, "tapname %s", &tap_name))
3989 if (sw_if_index_set == 0) {
3990 errmsg ("missing vpp interface name");
3993 if (name_set == 0) {
3994 errmsg ("missing tap name\n");
3997 if (vec_len (tap_name) > 63) {
3998 errmsg ("tap name too long\n");
4000 vec_add1 (tap_name, 0);
4002 /* Construct the API message */
4003 M(TAP_MODIFY, tap_modify);
4005 mp->use_random_mac = random_mac;
4006 mp->sw_if_index = ntohl(sw_if_index);
4007 clib_memcpy (mp->mac_address, mac_address, 6);
4008 clib_memcpy (mp->tap_name, tap_name, vec_len (tap_name));
4009 vec_free (tap_name);
4014 /* Wait for a reply... */
4018 static int api_tap_delete (vat_main_t * vam)
4020 unformat_input_t * i = vam->input;
4021 vl_api_tap_delete_t *mp;
4023 u32 sw_if_index = ~0;
4024 u8 sw_if_index_set = 0;
4026 /* Parse args required to build the message */
4027 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
4028 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
4029 sw_if_index_set = 1;
4030 else if (unformat (i, "sw_if_index %d", &sw_if_index))
4031 sw_if_index_set = 1;
4036 if (sw_if_index_set == 0) {
4037 errmsg ("missing vpp interface name");
4041 /* Construct the API message */
4042 M(TAP_DELETE, tap_delete);
4044 mp->sw_if_index = ntohl(sw_if_index);
4049 /* Wait for a reply... */
4053 static int api_ip_add_del_route (vat_main_t * vam)
4055 unformat_input_t * i = vam->input;
4056 vl_api_ip_add_del_route_t *mp;
4058 u32 sw_if_index = 0, vrf_id = 0;
4059 u8 sw_if_index_set = 0;
4061 u8 is_local = 0, is_drop = 0;
4062 u8 create_vrf_if_needed = 0;
4064 u8 next_hop_weight = 1;
4066 u8 is_multipath = 0;
4068 u8 address_length_set = 0;
4069 u32 lookup_in_vrf = 0;
4070 u32 resolve_attempts = 0;
4071 u32 dst_address_length = 0;
4072 u8 next_hop_set = 0;
4073 ip4_address_t v4_dst_address, v4_next_hop_address;
4074 ip6_address_t v6_dst_address, v6_next_hop_address;
4078 u32 random_add_del = 0;
4079 u32 * random_vector = 0;
4080 uword * random_hash;
4081 u32 random_seed = 0xdeaddabe;
4082 u32 classify_table_index = ~0;
4085 /* Parse args required to build the message */
4086 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
4087 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
4088 sw_if_index_set = 1;
4089 else if (unformat (i, "sw_if_index %d", &sw_if_index))
4090 sw_if_index_set = 1;
4091 else if (unformat (i, "%U", unformat_ip4_address,
4096 else if (unformat (i, "%U", unformat_ip6_address, &v6_dst_address)) {
4100 else if (unformat (i, "/%d", &dst_address_length)) {
4101 address_length_set = 1;
4104 else if (is_ipv6 == 0 && unformat (i, "via %U", unformat_ip4_address,
4105 &v4_next_hop_address)) {
4108 else if (is_ipv6 == 1 && unformat (i, "via %U", unformat_ip6_address,
4109 &v6_next_hop_address)) {
4112 else if (unformat (i, "resolve-attempts %d", &resolve_attempts))
4114 else if (unformat (i, "weight %d", &next_hop_weight))
4116 else if (unformat (i, "drop")) {
4118 } else if (unformat (i, "local")) {
4120 } else if (unformat (i, "classify %d", &classify_table_index)) {
4122 } else if (unformat (i, "del"))
4124 else if (unformat (i, "add"))
4126 else if (unformat (i, "not-last"))
4128 else if (unformat (i, "multipath"))
4130 else if (unformat (i, "vrf %d", &vrf_id))
4132 else if (unformat (i, "create-vrf"))
4133 create_vrf_if_needed = 1;
4134 else if (unformat (i, "count %d", &count))
4136 else if (unformat (i, "lookup-in-vrf %d", &lookup_in_vrf))
4138 else if (unformat (i, "random"))
4140 else if (unformat (i, "seed %d", &random_seed))
4143 clib_warning ("parse error '%U'", format_unformat_error, i);
4148 if (resolve_attempts > 0 && sw_if_index_set == 0) {
4149 errmsg ("ARP resolution needs explicit interface or sw_if_index\n");
4153 if (!next_hop_set && !is_drop && !is_local && !is_classify) {
4154 errmsg ("next hop / local / drop / classify not set\n");
4158 if (address_set == 0) {
4159 errmsg ("missing addresses\n");
4163 if (address_length_set == 0) {
4164 errmsg ("missing address length\n");
4168 /* Generate a pile of unique, random routes */
4169 if (random_add_del) {
4170 u32 this_random_address;
4171 random_hash = hash_create (count, sizeof(uword));
4173 hash_set (random_hash, v4_next_hop_address.as_u32, 1);
4174 for (j = 0; j <= count; j++) {
4176 this_random_address = random_u32 (&random_seed);
4177 this_random_address =
4178 clib_host_to_net_u32 (this_random_address);
4179 } while (hash_get (random_hash, this_random_address));
4180 vec_add1 (random_vector, this_random_address);
4181 hash_set (random_hash, this_random_address, 1);
4183 hash_free (random_hash);
4184 v4_dst_address.as_u32 = random_vector[0];
4188 /* Turn on async mode */
4189 vam->async_mode = 1;
4190 vam->async_errors = 0;
4191 before = vat_time_now(vam);
4194 for (j = 0; j < count; j++) {
4195 /* Construct the API message */
4196 M(IP_ADD_DEL_ROUTE, ip_add_del_route);
4198 mp->next_hop_sw_if_index = ntohl (sw_if_index);
4199 mp->vrf_id = ntohl (vrf_id);
4200 if (resolve_attempts > 0) {
4201 mp->resolve_attempts = ntohl (resolve_attempts);
4202 mp->resolve_if_needed = 1;
4204 mp->create_vrf_if_needed = create_vrf_if_needed;
4206 mp->is_add = is_add;
4207 mp->is_drop = is_drop;
4208 mp->is_ipv6 = is_ipv6;
4209 mp->is_local = is_local;
4210 mp->is_classify = is_classify;
4211 mp->is_multipath = is_multipath;
4212 mp->not_last = not_last;
4213 mp->next_hop_weight = next_hop_weight;
4214 mp->dst_address_length = dst_address_length;
4215 mp->lookup_in_vrf = ntohl(lookup_in_vrf);
4216 mp->classify_table_index = ntohl(classify_table_index);
4219 clib_memcpy (mp->dst_address, &v6_dst_address, sizeof (v6_dst_address));
4221 clib_memcpy (mp->next_hop_address, &v6_next_hop_address,
4222 sizeof (v6_next_hop_address));
4223 increment_v6_address (&v6_dst_address);
4225 clib_memcpy (mp->dst_address, &v4_dst_address, sizeof (v4_dst_address));
4227 clib_memcpy (mp->next_hop_address, &v4_next_hop_address,
4228 sizeof (v4_next_hop_address));
4230 v4_dst_address.as_u32 = random_vector[j+1];
4232 increment_v4_address (&v4_dst_address);
4238 /* When testing multiple add/del ops, use a control-ping to sync */
4240 vl_api_control_ping_t * mp;
4243 /* Shut off async mode */
4244 vam->async_mode = 0;
4246 M(CONTROL_PING, control_ping);
4249 timeout = vat_time_now(vam) + 1.0;
4250 while (vat_time_now (vam) < timeout)
4251 if (vam->result_ready == 1)
4256 if (vam->retval == -99)
4257 errmsg ("timeout\n");
4259 if (vam->async_errors > 0) {
4260 errmsg ("%d asynchronous errors\n", vam->async_errors);
4263 vam->async_errors = 0;
4264 after = vat_time_now(vam);
4266 fformat(vam->ofp, "%d routes in %.6f secs, %.2f routes/sec\n",
4267 count, after - before, count / (after - before));
4269 /* Wait for a reply... */
4273 /* Return the good/bad news */
4274 return (vam->retval);
4277 static int api_proxy_arp_add_del (vat_main_t * vam)
4279 unformat_input_t * i = vam->input;
4280 vl_api_proxy_arp_add_del_t *mp;
4284 ip4_address_t lo, hi;
4287 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
4288 if (unformat (i, "vrf %d", &vrf_id))
4290 else if (unformat (i, "%U - %U", unformat_ip4_address, &lo,
4291 unformat_ip4_address, &hi))
4293 else if (unformat (i, "del"))
4296 clib_warning ("parse error '%U'", format_unformat_error, i);
4301 if (range_set == 0) {
4302 errmsg ("address range not set\n");
4306 M(PROXY_ARP_ADD_DEL, proxy_arp_add_del);
4308 mp->vrf_id = ntohl(vrf_id);
4309 mp->is_add = is_add;
4310 clib_memcpy(mp->low_address, &lo, sizeof (mp->low_address));
4311 clib_memcpy(mp->hi_address, &hi, sizeof (mp->hi_address));
4318 static int api_proxy_arp_intfc_enable_disable (vat_main_t * vam)
4320 unformat_input_t * i = vam->input;
4321 vl_api_proxy_arp_intfc_enable_disable_t *mp;
4325 u8 sw_if_index_set = 0;
4327 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
4328 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
4329 sw_if_index_set = 1;
4330 else if (unformat (i, "sw_if_index %d", &sw_if_index))
4331 sw_if_index_set = 1;
4332 else if (unformat (i, "enable"))
4334 else if (unformat (i, "disable"))
4337 clib_warning ("parse error '%U'", format_unformat_error, i);
4342 if (sw_if_index_set == 0) {
4343 errmsg ("missing interface name or sw_if_index\n");
4347 M(PROXY_ARP_INTFC_ENABLE_DISABLE, proxy_arp_intfc_enable_disable);
4349 mp->sw_if_index = ntohl(sw_if_index);
4350 mp->enable_disable = enable;
4357 static int api_mpls_add_del_decap (vat_main_t * vam)
4359 unformat_input_t * i = vam->input;
4360 vl_api_mpls_add_del_decap_t *mp;
4369 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
4370 if (unformat (i, "rx_vrf_id %d", &rx_vrf_id))
4372 else if (unformat (i, "tx_vrf_id %d", &tx_vrf_id))
4374 else if (unformat (i, "label %d", &label))
4376 else if (unformat (i, "next-index %d", &next_index))
4378 else if (unformat (i, "del"))
4380 else if (unformat (i, "s-bit-clear"))
4383 clib_warning ("parse error '%U'", format_unformat_error, i);
4388 M(MPLS_ADD_DEL_DECAP, mpls_add_del_decap);
4390 mp->rx_vrf_id = ntohl(rx_vrf_id);
4391 mp->tx_vrf_id = ntohl(tx_vrf_id);
4392 mp->label = ntohl(label);
4393 mp->next_index = ntohl(next_index);
4395 mp->is_add = is_add;
4402 static int api_mpls_add_del_encap (vat_main_t * vam)
4404 unformat_input_t * i = vam->input;
4405 vl_api_mpls_add_del_encap_t *mp;
4410 ip4_address_t dst_address;
4413 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
4414 if (unformat (i, "vrf %d", &vrf_id))
4416 else if (unformat (i, "label %d", &label))
4417 vec_add1 (labels, ntohl(label));
4418 else if (unformat (i, "dst %U", unformat_ip4_address, &dst_address))
4420 else if (unformat (i, "del"))
4423 clib_warning ("parse error '%U'", format_unformat_error, i);
4428 if (vec_len (labels) == 0) {
4429 errmsg ("missing encap label stack\n");
4433 M2(MPLS_ADD_DEL_ENCAP, mpls_add_del_encap,
4434 sizeof (u32) * vec_len (labels));
4436 mp->vrf_id = ntohl(vrf_id);
4437 clib_memcpy(mp->dst_address, &dst_address, sizeof (dst_address));
4438 mp->is_add = is_add;
4439 mp->nlabels = vec_len (labels);
4440 clib_memcpy(mp->labels, labels, sizeof(u32)*mp->nlabels);
4449 static int api_mpls_gre_add_del_tunnel (vat_main_t * vam)
4451 unformat_input_t * i = vam->input;
4452 vl_api_mpls_gre_add_del_tunnel_t *mp;
4454 u32 inner_vrf_id = 0;
4455 u32 outer_vrf_id = 0;
4456 ip4_address_t src_address;
4457 ip4_address_t dst_address;
4458 ip4_address_t intfc_address;
4460 u8 intfc_address_length = 0;
4464 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
4465 if (unformat (i, "inner_vrf_id %d", &inner_vrf_id))
4467 else if (unformat (i, "outer_vrf_id %d", &outer_vrf_id))
4469 else if (unformat (i, "src %U", unformat_ip4_address, &src_address))
4471 else if (unformat (i, "dst %U", unformat_ip4_address, &dst_address))
4473 else if (unformat (i, "adj %U/%d", unformat_ip4_address,
4474 &intfc_address, &tmp))
4475 intfc_address_length = tmp;
4476 else if (unformat (i, "l2-only"))
4478 else if (unformat (i, "del"))
4481 clib_warning ("parse error '%U'", format_unformat_error, i);
4486 M(MPLS_GRE_ADD_DEL_TUNNEL, mpls_gre_add_del_tunnel);
4488 mp->inner_vrf_id = ntohl(inner_vrf_id);
4489 mp->outer_vrf_id = ntohl(outer_vrf_id);
4490 clib_memcpy(mp->src_address, &src_address, sizeof (src_address));
4491 clib_memcpy(mp->dst_address, &dst_address, sizeof (dst_address));
4492 clib_memcpy(mp->intfc_address, &intfc_address, sizeof (intfc_address));
4493 mp->intfc_address_length = intfc_address_length;
4494 mp->l2_only = l2_only;
4495 mp->is_add = is_add;
4502 static int api_mpls_ethernet_add_del_tunnel (vat_main_t * vam)
4504 unformat_input_t * i = vam->input;
4505 vl_api_mpls_ethernet_add_del_tunnel_t *mp;
4507 u32 inner_vrf_id = 0;
4508 ip4_address_t intfc_address;
4509 u8 dst_mac_address[6];
4512 u8 intfc_address_length = 0;
4516 int tx_sw_if_index_set = 0;
4518 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
4519 if (unformat (i, "vrf %d", &inner_vrf_id))
4521 else if (unformat (i, "adj %U/%d", unformat_ip4_address,
4522 &intfc_address, &tmp))
4523 intfc_address_length = tmp;
4524 else if (unformat (i, "%U",
4525 unformat_sw_if_index, vam, &tx_sw_if_index))
4526 tx_sw_if_index_set = 1;
4527 else if (unformat (i, "tx_sw_if_index %d", &tx_sw_if_index))
4528 tx_sw_if_index_set = 1;
4529 else if (unformat (i, "dst %U", unformat_ethernet_address,
4532 else if (unformat (i, "l2-only"))
4534 else if (unformat (i, "del"))
4537 clib_warning ("parse error '%U'", format_unformat_error, i);
4543 errmsg ("dst (mac address) not set\n");
4546 if (!tx_sw_if_index_set) {
4547 errmsg ("tx-intfc not set\n");
4551 M(MPLS_ETHERNET_ADD_DEL_TUNNEL, mpls_ethernet_add_del_tunnel);
4553 mp->vrf_id = ntohl(inner_vrf_id);
4554 clib_memcpy (mp->adj_address, &intfc_address, sizeof (intfc_address));
4555 mp->adj_address_length = intfc_address_length;
4556 clib_memcpy (mp->dst_mac_address, dst_mac_address, sizeof (dst_mac_address));
4557 mp->tx_sw_if_index = ntohl(tx_sw_if_index);
4558 mp->l2_only = l2_only;
4559 mp->is_add = is_add;
4566 static int api_mpls_ethernet_add_del_tunnel_2 (vat_main_t * vam)
4568 unformat_input_t * i = vam->input;
4569 vl_api_mpls_ethernet_add_del_tunnel_2_t *mp;
4571 u32 inner_vrf_id = 0;
4572 u32 outer_vrf_id = 0;
4573 ip4_address_t adj_address;
4574 int adj_address_set = 0;
4575 ip4_address_t next_hop_address;
4576 int next_hop_address_set = 0;
4578 u8 adj_address_length = 0;
4581 u32 resolve_attempts = 5;
4582 u8 resolve_if_needed = 1;
4584 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
4585 if (unformat (i, "inner_vrf_id %d", &inner_vrf_id))
4587 else if (unformat (i, "outer_vrf_id %d", &outer_vrf_id))
4589 else if (unformat (i, "adj %U/%d", unformat_ip4_address,
4590 &adj_address, &tmp)) {
4591 adj_address_length = tmp;
4592 adj_address_set = 1;
4594 else if (unformat (i, "next-hop %U", unformat_ip4_address,
4596 next_hop_address_set = 1;
4597 else if (unformat (i, "resolve-attempts %d", &resolve_attempts))
4599 else if (unformat (i, "resolve-if-needed %d", &tmp))
4600 resolve_if_needed = tmp;
4601 else if (unformat (i, "l2-only"))
4603 else if (unformat (i, "del"))
4606 clib_warning ("parse error '%U'", format_unformat_error, i);
4611 if (!adj_address_set) {
4612 errmsg ("adjacency address/mask not set\n");
4615 if (!next_hop_address_set) {
4616 errmsg ("ip4 next hop address (in outer fib) not set\n");
4620 M(MPLS_ETHERNET_ADD_DEL_TUNNEL_2, mpls_ethernet_add_del_tunnel_2);
4622 mp->inner_vrf_id = ntohl(inner_vrf_id);
4623 mp->outer_vrf_id = ntohl(outer_vrf_id);
4624 mp->resolve_attempts = ntohl(resolve_attempts);
4625 mp->resolve_if_needed = resolve_if_needed;
4626 mp->is_add = is_add;
4627 mp->l2_only = l2_only;
4628 clib_memcpy (mp->adj_address, &adj_address, sizeof (adj_address));
4629 mp->adj_address_length = adj_address_length;
4630 clib_memcpy (mp->next_hop_ip4_address_in_outer_vrf, &next_hop_address,
4631 sizeof (next_hop_address));
4638 static int api_sw_interface_set_unnumbered (vat_main_t * vam)
4640 unformat_input_t * i = vam->input;
4641 vl_api_sw_interface_set_unnumbered_t *mp;
4646 u8 sw_if_index_set = 0;
4648 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
4649 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
4650 sw_if_index_set = 1;
4651 else if (unformat (i, "sw_if_index %d", &sw_if_index))
4652 sw_if_index_set = 1;
4653 else if (unformat (i, "unnum_if_index %d", &unnum_sw_index))
4655 else if (unformat (i, "del"))
4658 clib_warning ("parse error '%U'", format_unformat_error, i);
4663 if (sw_if_index_set == 0) {
4664 errmsg ("missing interface name or sw_if_index\n");
4668 M(SW_INTERFACE_SET_UNNUMBERED, sw_interface_set_unnumbered);
4670 mp->sw_if_index = ntohl(sw_if_index);
4671 mp->unnumbered_sw_if_index = ntohl(unnum_sw_index);
4672 mp->is_add = is_add;
4679 static int api_ip_neighbor_add_del (vat_main_t * vam)
4681 unformat_input_t * i = vam->input;
4682 vl_api_ip_neighbor_add_del_t *mp;
4685 u8 sw_if_index_set = 0;
4691 u8 v4_address_set = 0;
4692 u8 v6_address_set = 0;
4693 ip4_address_t v4address;
4694 ip6_address_t v6address;
4696 memset (mac_address, 0, sizeof (mac_address));
4698 /* Parse args required to build the message */
4699 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
4700 if (unformat (i, "mac %U", unformat_ethernet_address, mac_address)) {
4703 else if (unformat (i, "del"))
4705 else if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
4706 sw_if_index_set = 1;
4707 else if (unformat (i, "sw_if_index %d", &sw_if_index))
4708 sw_if_index_set = 1;
4709 else if (unformat (i, "is_static"))
4711 else if (unformat (i, "vrf %d", &vrf_id))
4713 else if (unformat (i, "dst %U",
4714 unformat_ip4_address, &v4address))
4716 else if (unformat (i, "dst %U",
4717 unformat_ip6_address, &v6address))
4720 clib_warning ("parse error '%U'", format_unformat_error, i);
4725 if (sw_if_index_set == 0) {
4726 errmsg ("missing interface name or sw_if_index\n");
4729 if (v4_address_set && v6_address_set) {
4730 errmsg ("both v4 and v6 addresses set\n");
4733 if (!v4_address_set && !v6_address_set) {
4734 errmsg ("no addresses set\n");
4738 /* Construct the API message */
4739 M(IP_NEIGHBOR_ADD_DEL, ip_neighbor_add_del);
4741 mp->sw_if_index = ntohl (sw_if_index);
4742 mp->is_add = is_add;
4743 mp->vrf_id = ntohl (vrf_id);
4744 mp->is_static = is_static;
4746 clib_memcpy (mp->mac_address, mac_address, 6);
4747 if (v6_address_set) {
4749 clib_memcpy (mp->dst_address, &v6address, sizeof (v6address));
4751 /* mp->is_ipv6 = 0; via memset in M macro above */
4752 clib_memcpy (mp->dst_address, &v4address, sizeof (v4address));
4758 /* Wait for a reply, return good/bad news */
4765 static int api_reset_vrf (vat_main_t * vam)
4767 unformat_input_t * i = vam->input;
4768 vl_api_reset_vrf_t *mp;
4774 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
4775 if (unformat (i, "vrf %d", &vrf_id))
4777 else if (unformat (i, "ipv6"))
4780 clib_warning ("parse error '%U'", format_unformat_error, i);
4785 if (vrf_id_set == 0) {
4786 errmsg ("missing vrf id\n");
4790 M(RESET_VRF, reset_vrf);
4792 mp->vrf_id = ntohl(vrf_id);
4793 mp->is_ipv6 = is_ipv6;
4800 static int api_create_vlan_subif (vat_main_t * vam)
4802 unformat_input_t * i = vam->input;
4803 vl_api_create_vlan_subif_t *mp;
4806 u8 sw_if_index_set = 0;
4810 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
4811 if (unformat (i, "sw_if_index %d", &sw_if_index))
4812 sw_if_index_set = 1;
4813 else if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
4814 sw_if_index_set = 1;
4815 else if (unformat (i, "vlan %d", &vlan_id))
4818 clib_warning ("parse error '%U'", format_unformat_error, i);
4823 if (sw_if_index_set == 0) {
4824 errmsg ("missing interface name or sw_if_index\n");
4828 if (vlan_id_set == 0) {
4829 errmsg ("missing vlan_id\n");
4832 M(CREATE_VLAN_SUBIF, create_vlan_subif);
4834 mp->sw_if_index = ntohl(sw_if_index);
4835 mp->vlan_id = ntohl(vlan_id);
4842 #define foreach_create_subif_bit \
4849 _(outer_vlan_id_any) \
4850 _(inner_vlan_id_any)
4852 static int api_create_subif (vat_main_t * vam)
4854 unformat_input_t * i = vam->input;
4855 vl_api_create_subif_t *mp;
4858 u8 sw_if_index_set = 0;
4865 u32 exact_match = 0;
4866 u32 default_sub = 0;
4867 u32 outer_vlan_id_any = 0;
4868 u32 inner_vlan_id_any = 0;
4870 u16 outer_vlan_id = 0;
4871 u16 inner_vlan_id = 0;
4873 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
4874 if (unformat (i, "sw_if_index %d", &sw_if_index))
4875 sw_if_index_set = 1;
4876 else if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
4877 sw_if_index_set = 1;
4878 else if (unformat (i, "sub_id %d", &sub_id))
4880 else if (unformat (i, "outer_vlan_id %d", &tmp))
4881 outer_vlan_id = tmp;
4882 else if (unformat (i, "inner_vlan_id %d", &tmp))
4883 inner_vlan_id = tmp;
4885 #define _(a) else if (unformat (i, #a)) a = 1 ;
4886 foreach_create_subif_bit
4890 clib_warning ("parse error '%U'", format_unformat_error, i);
4895 if (sw_if_index_set == 0) {
4896 errmsg ("missing interface name or sw_if_index\n");
4900 if (sub_id_set == 0) {
4901 errmsg ("missing sub_id\n");
4904 M(CREATE_SUBIF, create_subif);
4906 mp->sw_if_index = ntohl(sw_if_index);
4907 mp->sub_id = ntohl(sub_id);
4909 #define _(a) mp->a = a;
4910 foreach_create_subif_bit;
4913 mp->outer_vlan_id = ntohs (outer_vlan_id);
4914 mp->inner_vlan_id = ntohs (inner_vlan_id);
4921 static int api_oam_add_del (vat_main_t * vam)
4923 unformat_input_t * i = vam->input;
4924 vl_api_oam_add_del_t *mp;
4928 ip4_address_t src, dst;
4932 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
4933 if (unformat (i, "vrf %d", &vrf_id))
4935 else if (unformat (i, "src %U", unformat_ip4_address, &src))
4937 else if (unformat (i, "dst %U", unformat_ip4_address, &dst))
4939 else if (unformat (i, "del"))
4942 clib_warning ("parse error '%U'", format_unformat_error, i);
4948 errmsg ("missing src addr\n");
4953 errmsg ("missing dst addr\n");
4957 M(OAM_ADD_DEL, oam_add_del);
4959 mp->vrf_id = ntohl(vrf_id);
4960 mp->is_add = is_add;
4961 clib_memcpy(mp->src_address, &src, sizeof (mp->src_address));
4962 clib_memcpy(mp->dst_address, &dst, sizeof (mp->dst_address));
4969 static int api_reset_fib (vat_main_t * vam)
4971 unformat_input_t * i = vam->input;
4972 vl_api_reset_fib_t *mp;
4978 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
4979 if (unformat (i, "vrf %d", &vrf_id))
4981 else if (unformat (i, "ipv6"))
4984 clib_warning ("parse error '%U'", format_unformat_error, i);
4989 if (vrf_id_set == 0) {
4990 errmsg ("missing vrf id\n");
4994 M(RESET_FIB, reset_fib);
4996 mp->vrf_id = ntohl(vrf_id);
4997 mp->is_ipv6 = is_ipv6;
5004 static int api_dhcp_proxy_config (vat_main_t * vam)
5006 unformat_input_t * i = vam->input;
5007 vl_api_dhcp_proxy_config_t *mp;
5012 u8 v4_address_set = 0;
5013 u8 v6_address_set = 0;
5014 ip4_address_t v4address;
5015 ip6_address_t v6address;
5016 u8 v4_src_address_set = 0;
5017 u8 v6_src_address_set = 0;
5018 ip4_address_t v4srcaddress;
5019 ip6_address_t v6srcaddress;
5021 /* Parse args required to build the message */
5022 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
5023 if (unformat (i, "del"))
5025 else if (unformat (i, "vrf %d", &vrf_id))
5027 else if (unformat (i, "insert-cid %d", &insert_cid))
5029 else if (unformat (i, "svr %U",
5030 unformat_ip4_address, &v4address))
5032 else if (unformat (i, "svr %U",
5033 unformat_ip6_address, &v6address))
5035 else if (unformat (i, "src %U",
5036 unformat_ip4_address, &v4srcaddress))
5037 v4_src_address_set = 1;
5038 else if (unformat (i, "src %U",
5039 unformat_ip6_address, &v6srcaddress))
5040 v6_src_address_set = 1;
5045 if (v4_address_set && v6_address_set) {
5046 errmsg ("both v4 and v6 server addresses set\n");
5049 if (!v4_address_set && !v6_address_set) {
5050 errmsg ("no server addresses set\n");
5054 if (v4_src_address_set && v6_src_address_set) {
5055 errmsg ("both v4 and v6 src addresses set\n");
5058 if (!v4_src_address_set && !v6_src_address_set) {
5059 errmsg ("no src addresses set\n");
5063 if (!(v4_src_address_set && v4_address_set) &&
5064 !(v6_src_address_set && v6_address_set)) {
5065 errmsg ("no matching server and src addresses set\n");
5069 /* Construct the API message */
5070 M(DHCP_PROXY_CONFIG, dhcp_proxy_config);
5072 mp->insert_circuit_id = insert_cid;
5073 mp->is_add = is_add;
5074 mp->vrf_id = ntohl (vrf_id);
5075 if (v6_address_set) {
5077 clib_memcpy (mp->dhcp_server, &v6address, sizeof (v6address));
5078 clib_memcpy (mp->dhcp_src_address, &v6srcaddress, sizeof (v6address));
5080 clib_memcpy (mp->dhcp_server, &v4address, sizeof (v4address));
5081 clib_memcpy (mp->dhcp_src_address, &v4srcaddress, sizeof (v4address));
5087 /* Wait for a reply, return good/bad news */
5093 static int api_dhcp_proxy_config_2 (vat_main_t * vam)
5095 unformat_input_t * i = vam->input;
5096 vl_api_dhcp_proxy_config_2_t *mp;
5099 u32 server_vrf_id = 0;
5102 u8 v4_address_set = 0;
5103 u8 v6_address_set = 0;
5104 ip4_address_t v4address;
5105 ip6_address_t v6address;
5106 u8 v4_src_address_set = 0;
5107 u8 v6_src_address_set = 0;
5108 ip4_address_t v4srcaddress;
5109 ip6_address_t v6srcaddress;
5111 /* Parse args required to build the message */
5112 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
5113 if (unformat (i, "del"))
5115 else if (unformat (i, "rx_vrf_id %d", &rx_vrf_id))
5117 else if (unformat (i, "server_vrf_id %d", &server_vrf_id))
5119 else if (unformat (i, "insert-cid %d", &insert_cid))
5121 else if (unformat (i, "svr %U",
5122 unformat_ip4_address, &v4address))
5124 else if (unformat (i, "svr %U",
5125 unformat_ip6_address, &v6address))
5127 else if (unformat (i, "src %U",
5128 unformat_ip4_address, &v4srcaddress))
5129 v4_src_address_set = 1;
5130 else if (unformat (i, "src %U",
5131 unformat_ip6_address, &v6srcaddress))
5132 v6_src_address_set = 1;
5137 if (v4_address_set && v6_address_set) {
5138 errmsg ("both v4 and v6 server addresses set\n");
5141 if (!v4_address_set && !v6_address_set) {
5142 errmsg ("no server addresses set\n");
5146 if (v4_src_address_set && v6_src_address_set) {
5147 errmsg ("both v4 and v6 src addresses set\n");
5150 if (!v4_src_address_set && !v6_src_address_set) {
5151 errmsg ("no src addresses set\n");
5155 if (!(v4_src_address_set && v4_address_set) &&
5156 !(v6_src_address_set && v6_address_set)) {
5157 errmsg ("no matching server and src addresses set\n");
5161 /* Construct the API message */
5162 M(DHCP_PROXY_CONFIG_2, dhcp_proxy_config_2);
5164 mp->insert_circuit_id = insert_cid;
5165 mp->is_add = is_add;
5166 mp->rx_vrf_id = ntohl (rx_vrf_id);
5167 mp->server_vrf_id = ntohl (server_vrf_id);
5168 if (v6_address_set) {
5170 clib_memcpy (mp->dhcp_server, &v6address, sizeof (v6address));
5171 clib_memcpy (mp->dhcp_src_address, &v6srcaddress, sizeof (v6address));
5173 clib_memcpy (mp->dhcp_server, &v4address, sizeof (v4address));
5174 clib_memcpy (mp->dhcp_src_address, &v4srcaddress, sizeof (v4address));
5180 /* Wait for a reply, return good/bad news */
5186 static int api_dhcp_proxy_set_vss (vat_main_t * vam)
5188 unformat_input_t * i = vam->input;
5189 vl_api_dhcp_proxy_set_vss_t *mp;
5200 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
5201 if (unformat (i, "tbl_id %d", &tbl_id))
5203 if (unformat (i, "fib_id %d", &fib_id))
5205 if (unformat (i, "oui %d", &oui))
5207 else if (unformat (i, "ipv6"))
5209 else if (unformat (i, "del"))
5212 clib_warning ("parse error '%U'", format_unformat_error, i);
5217 if (tbl_id_set == 0) {
5218 errmsg ("missing tbl id\n");
5222 if (fib_id_set == 0) {
5223 errmsg ("missing fib id\n");
5227 errmsg ("missing oui\n");
5231 M(DHCP_PROXY_SET_VSS, dhcp_proxy_set_vss);
5232 mp->tbl_id = ntohl(tbl_id);
5233 mp->fib_id = ntohl(fib_id);
5234 mp->oui = ntohl(oui);
5235 mp->is_ipv6 = is_ipv6;
5236 mp->is_add = is_add;
5243 static int api_dhcp_client_config (vat_main_t * vam)
5245 unformat_input_t * i = vam->input;
5246 vl_api_dhcp_client_config_t *mp;
5249 u8 sw_if_index_set = 0;
5252 u8 disable_event = 0;
5254 /* Parse args required to build the message */
5255 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
5256 if (unformat (i, "del"))
5258 else if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
5259 sw_if_index_set = 1;
5260 else if (unformat (i, "sw_if_index %d", &sw_if_index))
5261 sw_if_index_set = 1;
5262 else if (unformat (i, "hostname %s", &hostname))
5264 else if (unformat (i, "disable_event"))
5270 if (sw_if_index_set == 0) {
5271 errmsg ("missing interface name or sw_if_index\n");
5275 if (vec_len (hostname) > 63) {
5276 errmsg ("hostname too long\n");
5278 vec_add1 (hostname, 0);
5280 /* Construct the API message */
5281 M(DHCP_CLIENT_CONFIG, dhcp_client_config);
5283 mp->sw_if_index = ntohl (sw_if_index);
5284 clib_memcpy (mp->hostname, hostname, vec_len (hostname));
5285 vec_free (hostname);
5286 mp->is_add = is_add;
5287 mp->want_dhcp_event = disable_event ? 0 : 1;
5293 /* Wait for a reply, return good/bad news */
5299 static int api_set_ip_flow_hash (vat_main_t * vam)
5301 unformat_input_t * i = vam->input;
5302 vl_api_set_ip_flow_hash_t *mp;
5314 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
5315 if (unformat (i, "vrf %d", &vrf_id))
5317 else if (unformat (i, "ipv6"))
5319 else if (unformat (i, "src"))
5321 else if (unformat (i, "dst"))
5323 else if (unformat (i, "sport"))
5325 else if (unformat (i, "dport"))
5327 else if (unformat (i, "proto"))
5329 else if (unformat (i, "reverse"))
5333 clib_warning ("parse error '%U'", format_unformat_error, i);
5338 if (vrf_id_set == 0) {
5339 errmsg ("missing vrf id\n");
5343 M(SET_IP_FLOW_HASH, set_ip_flow_hash);
5349 mp->reverse = reverse;
5350 mp->vrf_id = ntohl(vrf_id);
5351 mp->is_ipv6 = is_ipv6;
5358 static int api_sw_interface_ip6_enable_disable (vat_main_t * vam)
5360 unformat_input_t * i = vam->input;
5361 vl_api_sw_interface_ip6_enable_disable_t *mp;
5364 u8 sw_if_index_set = 0;
5367 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
5368 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
5369 sw_if_index_set = 1;
5370 else if (unformat (i, "sw_if_index %d", &sw_if_index))
5371 sw_if_index_set = 1;
5372 else if (unformat (i, "enable"))
5374 else if (unformat (i, "disable"))
5377 clib_warning ("parse error '%U'", format_unformat_error, i);
5382 if (sw_if_index_set == 0) {
5383 errmsg ("missing interface name or sw_if_index\n");
5387 M(SW_INTERFACE_IP6_ENABLE_DISABLE, sw_interface_ip6_enable_disable);
5389 mp->sw_if_index = ntohl(sw_if_index);
5390 mp->enable = enable;
5397 static int api_sw_interface_ip6_set_link_local_address (vat_main_t * vam)
5399 unformat_input_t * i = vam->input;
5400 vl_api_sw_interface_ip6_set_link_local_address_t *mp;
5403 u8 sw_if_index_set = 0;
5404 u32 address_length = 0;
5405 u8 v6_address_set = 0;
5406 ip6_address_t v6address;
5408 /* Parse args required to build the message */
5409 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
5410 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
5411 sw_if_index_set = 1;
5412 else if (unformat (i, "sw_if_index %d", &sw_if_index))
5413 sw_if_index_set = 1;
5414 else if (unformat (i, "%U/%d",
5415 unformat_ip6_address, &v6address,
5422 if (sw_if_index_set == 0) {
5423 errmsg ("missing interface name or sw_if_index\n");
5426 if (!v6_address_set) {
5427 errmsg ("no address set\n");
5431 /* Construct the API message */
5432 M(SW_INTERFACE_IP6_SET_LINK_LOCAL_ADDRESS, \
5433 sw_interface_ip6_set_link_local_address);
5435 mp->sw_if_index = ntohl (sw_if_index);
5436 clib_memcpy (mp->address, &v6address, sizeof (v6address));
5437 mp->address_length = address_length;
5442 /* Wait for a reply, return good/bad news */
5450 static int api_sw_interface_ip6nd_ra_prefix (vat_main_t * vam)
5452 unformat_input_t * i = vam->input;
5453 vl_api_sw_interface_ip6nd_ra_prefix_t *mp;
5456 u8 sw_if_index_set = 0;
5457 u32 address_length = 0;
5458 u8 v6_address_set = 0;
5459 ip6_address_t v6address;
5461 u8 no_advertise = 0;
5463 u8 no_autoconfig = 0;
5466 u32 val_lifetime = 0;
5467 u32 pref_lifetime = 0;
5469 /* Parse args required to build the message */
5470 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
5471 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
5472 sw_if_index_set = 1;
5473 else if (unformat (i, "sw_if_index %d", &sw_if_index))
5474 sw_if_index_set = 1;
5475 else if (unformat (i, "%U/%d",
5476 unformat_ip6_address, &v6address,
5479 else if (unformat (i, "val_life %d", &val_lifetime))
5481 else if (unformat (i, "pref_life %d", &pref_lifetime))
5483 else if (unformat (i, "def"))
5485 else if (unformat (i, "noadv"))
5487 else if (unformat (i, "offl"))
5489 else if (unformat (i, "noauto"))
5491 else if (unformat (i, "nolink"))
5493 else if (unformat (i, "isno"))
5496 clib_warning ("parse error '%U'", format_unformat_error, i);
5501 if (sw_if_index_set == 0) {
5502 errmsg ("missing interface name or sw_if_index\n");
5505 if (!v6_address_set) {
5506 errmsg ("no address set\n");
5510 /* Construct the API message */
5511 M(SW_INTERFACE_IP6ND_RA_PREFIX, sw_interface_ip6nd_ra_prefix);
5513 mp->sw_if_index = ntohl (sw_if_index);
5514 clib_memcpy (mp->address, &v6address, sizeof (v6address));
5515 mp->address_length = address_length;
5516 mp->use_default = use_default;
5517 mp->no_advertise = no_advertise;
5518 mp->off_link = off_link;
5519 mp->no_autoconfig = no_autoconfig;
5520 mp->no_onlink = no_onlink;
5522 mp->val_lifetime = ntohl(val_lifetime);
5523 mp->pref_lifetime = ntohl(pref_lifetime);
5528 /* Wait for a reply, return good/bad news */
5535 static int api_sw_interface_ip6nd_ra_config (vat_main_t * vam)
5537 unformat_input_t * i = vam->input;
5538 vl_api_sw_interface_ip6nd_ra_config_t *mp;
5541 u8 sw_if_index_set = 0;
5546 u8 send_unicast = 0;
5549 u8 default_router = 0;
5550 u32 max_interval = 0;
5551 u32 min_interval = 0;
5553 u32 initial_count = 0;
5554 u32 initial_interval = 0;
5557 /* Parse args required to build the message */
5558 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
5559 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
5560 sw_if_index_set = 1;
5561 else if (unformat (i, "sw_if_index %d", &sw_if_index))
5562 sw_if_index_set = 1;
5563 else if (unformat (i, "maxint %d", &max_interval))
5565 else if (unformat (i, "minint %d", &min_interval))
5567 else if (unformat (i, "life %d", &lifetime))
5569 else if (unformat (i, "count %d", &initial_count))
5571 else if (unformat (i, "interval %d", &initial_interval))
5573 else if (unformat (i, "surpress"))
5575 else if (unformat (i, "managed"))
5577 else if (unformat (i, "other"))
5579 else if (unformat (i, "ll"))
5581 else if (unformat (i, "send"))
5583 else if (unformat (i, "cease"))
5585 else if (unformat (i, "isno"))
5587 else if (unformat (i, "def"))
5590 clib_warning ("parse error '%U'", format_unformat_error, i);
5595 if (sw_if_index_set == 0) {
5596 errmsg ("missing interface name or sw_if_index\n");
5600 /* Construct the API message */
5601 M(SW_INTERFACE_IP6ND_RA_CONFIG, sw_interface_ip6nd_ra_config);
5603 mp->sw_if_index = ntohl (sw_if_index);
5604 mp->max_interval = ntohl(max_interval);
5605 mp->min_interval = ntohl(min_interval);
5606 mp->lifetime = ntohl(lifetime);
5607 mp->initial_count = ntohl(initial_count);
5608 mp->initial_interval = ntohl(initial_interval);
5609 mp->surpress = surpress;
5610 mp->managed = managed;
5612 mp->ll_option = ll_option;
5613 mp->send_unicast = send_unicast;
5616 mp->default_router = default_router;
5621 /* Wait for a reply, return good/bad news */
5628 static int api_set_arp_neighbor_limit (vat_main_t * vam)
5630 unformat_input_t * i = vam->input;
5631 vl_api_set_arp_neighbor_limit_t *mp;
5637 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
5638 if (unformat (i, "arp_nbr_limit %d", &arp_nbr_limit))
5640 else if (unformat (i, "ipv6"))
5643 clib_warning ("parse error '%U'", format_unformat_error, i);
5648 if (limit_set == 0) {
5649 errmsg ("missing limit value\n");
5653 M(SET_ARP_NEIGHBOR_LIMIT, set_arp_neighbor_limit);
5655 mp->arp_neighbor_limit = ntohl(arp_nbr_limit);
5656 mp->is_ipv6 = is_ipv6;
5663 static int api_l2_patch_add_del (vat_main_t * vam)
5665 unformat_input_t * i = vam->input;
5666 vl_api_l2_patch_add_del_t *mp;
5669 u8 rx_sw_if_index_set = 0;
5671 u8 tx_sw_if_index_set = 0;
5674 /* Parse args required to build the message */
5675 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
5676 if (unformat (i, "rx_sw_if_index %d", &rx_sw_if_index))
5677 rx_sw_if_index_set = 1;
5678 else if (unformat (i, "tx_sw_if_index %d", &tx_sw_if_index))
5679 tx_sw_if_index_set = 1;
5680 else if (unformat (i, "rx")) {
5681 if (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
5682 if (unformat (i, "%U", unformat_sw_if_index, vam,
5684 rx_sw_if_index_set = 1;
5687 } else if (unformat (i, "tx")) {
5688 if (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
5689 if (unformat (i, "%U", unformat_sw_if_index, vam,
5691 tx_sw_if_index_set = 1;
5694 } else if (unformat (i, "del"))
5700 if (rx_sw_if_index_set == 0) {
5701 errmsg ("missing rx interface name or rx_sw_if_index\n");
5705 if (tx_sw_if_index_set == 0) {
5706 errmsg ("missing tx interface name or tx_sw_if_index\n");
5710 M(L2_PATCH_ADD_DEL, l2_patch_add_del);
5712 mp->rx_sw_if_index = ntohl(rx_sw_if_index);
5713 mp->tx_sw_if_index = ntohl(tx_sw_if_index);
5714 mp->is_add = is_add;
5720 static int api_trace_profile_add (vat_main_t *vam)
5722 unformat_input_t * input = vam->input;
5723 vl_api_trace_profile_add_t *mp;
5726 u32 trace_option_elts = 0;
5727 u32 trace_type = 0, node_id = 0, app_data = 0, trace_tsp = 2;
5728 int has_pow_option = 0;
5729 int has_ppc_option = 0;
5731 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
5733 if (unformat (input, "id %d trace-type 0x%x trace-elts %d "
5734 "trace-tsp %d node-id 0x%x app-data 0x%x",
5735 &id, &trace_type, &trace_option_elts, &trace_tsp,
5736 &node_id, &app_data))
5738 else if (unformat (input, "pow"))
5740 else if (unformat (input, "ppc encap"))
5741 has_ppc_option = PPC_ENCAP;
5742 else if (unformat (input, "ppc decap"))
5743 has_ppc_option = PPC_DECAP;
5744 else if (unformat (input, "ppc none"))
5745 has_ppc_option = PPC_NONE;
5749 M(TRACE_PROFILE_ADD, trace_profile_add);
5751 mp->trace_type = trace_type;
5752 mp->trace_num_elt = trace_option_elts;
5753 mp->trace_ppc = has_ppc_option;
5754 mp->trace_app_data = htonl(app_data);
5755 mp->pow_enable = has_pow_option;
5756 mp->trace_tsp = trace_tsp;
5757 mp->node_id = htonl(node_id);
5764 static int api_trace_profile_apply (vat_main_t *vam)
5766 unformat_input_t * input = vam->input;
5767 vl_api_trace_profile_apply_t *mp;
5770 u32 mask_width = ~0;
5777 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
5779 if (unformat (input, "%U/%d",
5780 unformat_ip6_address, &addr, &mask_width))
5782 else if (unformat (input, "id %d", &id))
5784 else if (unformat (input, "vrf-id %d", &vrf_id))
5786 else if (unformat (input, "add"))
5788 else if (unformat (input, "pop"))
5790 else if (unformat (input, "none"))
5796 if ((is_add + is_pop + is_none) != 1) {
5797 errmsg("One of (add, pop, none) required");
5800 if (mask_width == ~0) {
5801 errmsg("<address>/<mask-width> required");
5804 M(TRACE_PROFILE_APPLY, trace_profile_apply);
5805 clib_memcpy(mp->dest_ipv6, &addr, sizeof(mp->dest_ipv6));
5807 mp->prefix_length = htonl(mask_width);
5808 mp->vrf_id = htonl(vrf_id);
5810 mp->trace_op = IOAM_HBYH_ADD;
5812 mp->trace_op = IOAM_HBYH_POP;
5814 mp->trace_op = IOAM_HBYH_MOD;
5826 static int api_trace_profile_del (vat_main_t *vam)
5828 vl_api_trace_profile_del_t *mp;
5831 M(TRACE_PROFILE_DEL, trace_profile_del);
5836 static int api_sr_tunnel_add_del (vat_main_t * vam)
5838 unformat_input_t * i = vam->input;
5839 vl_api_sr_tunnel_add_del_t *mp;
5843 ip6_address_t src_address;
5844 int src_address_set = 0;
5845 ip6_address_t dst_address;
5847 int dst_address_set = 0;
5849 u32 rx_table_id = 0;
5850 u32 tx_table_id = 0;
5851 ip6_address_t * segments = 0;
5852 ip6_address_t * this_seg;
5853 ip6_address_t * tags = 0;
5854 ip6_address_t * this_tag;
5855 ip6_address_t next_address, tag;
5857 u8 * policy_name = 0;
5859 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
5861 if (unformat (i, "del"))
5863 else if (unformat (i, "name %s", &name))
5865 else if (unformat (i, "policy %s", &policy_name))
5867 else if (unformat (i, "rx_fib_id %d", &rx_table_id))
5869 else if (unformat (i, "tx_fib_id %d", &tx_table_id))
5871 else if (unformat (i, "src %U", unformat_ip6_address, &src_address))
5872 src_address_set = 1;
5873 else if (unformat (i, "dst %U/%d",
5874 unformat_ip6_address, &dst_address,
5876 dst_address_set = 1;
5877 else if (unformat (i, "next %U", unformat_ip6_address,
5880 vec_add2 (segments, this_seg, 1);
5881 clib_memcpy (this_seg->as_u8, next_address.as_u8, sizeof (*this_seg));
5883 else if (unformat (i, "tag %U", unformat_ip6_address,
5886 vec_add2 (tags, this_tag, 1);
5887 clib_memcpy (this_tag->as_u8, tag.as_u8, sizeof (*this_tag));
5889 else if (unformat (i, "clean"))
5890 flags |= IP6_SR_HEADER_FLAG_CLEANUP;
5891 else if (unformat (i, "protected"))
5892 flags |= IP6_SR_HEADER_FLAG_PROTECTED;
5893 else if (unformat (i, "InPE %d", &pl_index))
5895 if (pl_index <= 0 || pl_index > 4)
5897 pl_index_range_error:
5898 errmsg ("pl index %d out of range\n", pl_index);
5901 flags |= IP6_SR_HEADER_FLAG_PL_ELT_INGRESS_PE << (3*(pl_index - 1));
5903 else if (unformat (i, "EgPE %d", &pl_index))
5905 if (pl_index <= 0 || pl_index > 4)
5906 goto pl_index_range_error;
5907 flags |= IP6_SR_HEADER_FLAG_PL_ELT_EGRESS_PE << (3*(pl_index - 1));
5909 else if (unformat (i, "OrgSrc %d", &pl_index))
5911 if (pl_index <= 0 || pl_index > 4)
5912 goto pl_index_range_error;
5913 flags |= IP6_SR_HEADER_FLAG_PL_ELT_ORIG_SRC_ADDR << (3*(pl_index - 1));
5919 if (!src_address_set)
5921 errmsg ("src address required\n");
5925 if (!dst_address_set)
5927 errmsg ("dst address required\n");
5933 errmsg ("at least one sr segment required\n");
5937 M2(SR_TUNNEL_ADD_DEL, sr_tunnel_add_del,
5938 vec_len(segments) * sizeof (ip6_address_t)
5939 + vec_len(tags) * sizeof (ip6_address_t));
5941 clib_memcpy (mp->src_address, &src_address, sizeof (mp->src_address));
5942 clib_memcpy (mp->dst_address, &dst_address, sizeof (mp->dst_address));
5943 mp->dst_mask_width = dst_mask_width;
5944 mp->flags_net_byte_order = clib_host_to_net_u16 (flags);
5945 mp->n_segments = vec_len (segments);
5946 mp->n_tags = vec_len (tags);
5947 mp->is_add = is_del == 0;
5948 clib_memcpy (mp->segs_and_tags, segments,
5949 vec_len(segments)* sizeof (ip6_address_t));
5950 clib_memcpy (mp->segs_and_tags + vec_len(segments)*sizeof (ip6_address_t),
5951 tags, vec_len(tags)* sizeof (ip6_address_t));
5953 mp->outer_vrf_id = ntohl (rx_table_id);
5954 mp->inner_vrf_id = ntohl (tx_table_id);
5955 memcpy (mp->name, name, vec_len(name));
5956 memcpy (mp->policy_name, policy_name, vec_len(policy_name));
5958 vec_free (segments);
5965 static int api_sr_policy_add_del (vat_main_t * vam)
5967 unformat_input_t * input = vam->input;
5968 vl_api_sr_policy_add_del_t *mp;
5972 u8 * tunnel_name = 0;
5973 u8 ** tunnel_names = 0;
5978 int tunnel_names_length = 1; // Init to 1 to offset the #tunnel_names counter byte
5979 int tun_name_len = 0; // Different naming convention used as confusing these would be "bad" (TM)
5981 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
5983 if (unformat (input, "del"))
5985 else if (unformat (input, "name %s", &name))
5987 else if (unformat (input, "tunnel %s", &tunnel_name))
5991 vec_add1 (tunnel_names, tunnel_name);
5993 - length = #bytes to store in serial vector
5994 - +1 = byte to store that length
5996 tunnel_names_length += (vec_len (tunnel_name) + 1);
6007 errmsg ("policy name required\n");
6011 if ((!tunnel_set) && (!is_del))
6013 errmsg ("tunnel name required\n");
6017 M2(SR_POLICY_ADD_DEL, sr_policy_add_del, tunnel_names_length);
6021 mp->is_add = !is_del;
6023 memcpy (mp->name, name, vec_len(name));
6024 // Since mp->tunnel_names is of type u8[0] and not a u8 *, u8 ** needs to be serialized
6025 u8 * serial_orig = 0;
6026 vec_validate (serial_orig, tunnel_names_length);
6027 *serial_orig = vec_len(tunnel_names); // Store the number of tunnels as length in first byte of serialized vector
6028 serial_orig += 1; // Move along one byte to store the length of first tunnel_name
6030 for (j=0; j < vec_len(tunnel_names); j++)
6032 tun_name_len = vec_len (tunnel_names[j]);
6033 *serial_orig = tun_name_len; // Store length of tunnel name in first byte of Length/Value pair
6034 serial_orig += 1; // Move along one byte to store the actual tunnel name
6035 memcpy (serial_orig, tunnel_names[j], tun_name_len);
6036 serial_orig += tun_name_len; // Advance past the copy
6038 memcpy (mp->tunnel_names, serial_orig - tunnel_names_length, tunnel_names_length); // Regress serial_orig to head then copy fwd
6040 vec_free (tunnel_names);
6041 vec_free (tunnel_name);
6047 static int api_sr_multicast_map_add_del (vat_main_t * vam)
6049 unformat_input_t * input = vam->input;
6050 vl_api_sr_multicast_map_add_del_t *mp;
6053 ip6_address_t multicast_address;
6054 u8 * policy_name = 0;
6055 int multicast_address_set = 0;
6057 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
6059 if (unformat (input, "del"))
6061 else if (unformat (input, "address %U", unformat_ip6_address, &multicast_address))
6062 multicast_address_set = 1;
6063 else if (unformat (input, "sr-policy %s", &policy_name))
6069 if (!is_del && !policy_name)
6071 errmsg ("sr-policy name required\n");
6076 if (!multicast_address_set)
6078 errmsg ("address required\n");
6082 M(SR_MULTICAST_MAP_ADD_DEL, sr_multicast_map_add_del);
6084 mp->is_add = !is_del;
6085 memcpy (mp->policy_name, policy_name, vec_len(policy_name));
6086 clib_memcpy (mp->multicast_address, &multicast_address, sizeof (mp->multicast_address));
6089 vec_free (policy_name);
6096 #define foreach_ip4_proto_field \
6106 uword unformat_ip4_mask (unformat_input_t * input, va_list * args)
6108 u8 ** maskp = va_arg (*args, u8 **);
6110 u8 found_something = 0;
6113 #define _(a) u8 a=0;
6114 foreach_ip4_proto_field;
6120 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
6122 if (unformat (input, "version"))
6124 else if (unformat (input, "hdr_length"))
6126 else if (unformat (input, "src"))
6128 else if (unformat (input, "dst"))
6130 else if (unformat (input, "proto"))
6133 #define _(a) else if (unformat (input, #a)) a=1;
6134 foreach_ip4_proto_field
6140 #define _(a) found_something += a;
6141 foreach_ip4_proto_field;
6144 if (found_something == 0)
6147 vec_validate (mask, sizeof (*ip) - 1);
6149 ip = (ip4_header_t *) mask;
6151 #define _(a) if (a) memset (&ip->a, 0xff, sizeof (ip->a));
6152 foreach_ip4_proto_field;
6155 ip->ip_version_and_header_length = 0;
6158 ip->ip_version_and_header_length |= 0xF0;
6161 ip->ip_version_and_header_length |= 0x0F;
6167 #define foreach_ip6_proto_field \
6174 uword unformat_ip6_mask (unformat_input_t * input, va_list * args)
6176 u8 ** maskp = va_arg (*args, u8 **);
6178 u8 found_something = 0;
6180 u32 ip_version_traffic_class_and_flow_label;
6182 #define _(a) u8 a=0;
6183 foreach_ip6_proto_field;
6186 u8 traffic_class = 0;
6189 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
6191 if (unformat (input, "version"))
6193 else if (unformat (input, "traffic-class"))
6195 else if (unformat (input, "flow-label"))
6197 else if (unformat (input, "src"))
6199 else if (unformat (input, "dst"))
6201 else if (unformat (input, "proto"))
6204 #define _(a) else if (unformat (input, #a)) a=1;
6205 foreach_ip6_proto_field
6211 #define _(a) found_something += a;
6212 foreach_ip6_proto_field;
6215 if (found_something == 0)
6218 vec_validate (mask, sizeof (*ip) - 1);
6220 ip = (ip6_header_t *) mask;
6222 #define _(a) if (a) memset (&ip->a, 0xff, sizeof (ip->a));
6223 foreach_ip6_proto_field;
6226 ip_version_traffic_class_and_flow_label = 0;
6229 ip_version_traffic_class_and_flow_label |= 0xF0000000;
6232 ip_version_traffic_class_and_flow_label |= 0x0FF00000;
6235 ip_version_traffic_class_and_flow_label |= 0x000FFFFF;
6237 ip->ip_version_traffic_class_and_flow_label =
6238 clib_host_to_net_u32 (ip_version_traffic_class_and_flow_label);
6244 uword unformat_l3_mask (unformat_input_t * input, va_list * args)
6246 u8 ** maskp = va_arg (*args, u8 **);
6248 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) {
6249 if (unformat (input, "ip4 %U", unformat_ip4_mask, maskp))
6251 else if (unformat (input, "ip6 %U", unformat_ip6_mask, maskp))
6259 uword unformat_l2_mask (unformat_input_t * input, va_list * args)
6261 u8 ** maskp = va_arg (*args, u8 **);
6276 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) {
6277 if (unformat (input, "src"))
6279 else if (unformat (input, "dst"))
6281 else if (unformat (input, "proto"))
6283 else if (unformat (input, "tag1"))
6285 else if (unformat (input, "tag2"))
6287 else if (unformat (input, "ignore-tag1"))
6289 else if (unformat (input, "ignore-tag2"))
6291 else if (unformat (input, "cos1"))
6293 else if (unformat (input, "cos2"))
6295 else if (unformat (input, "dot1q"))
6297 else if (unformat (input, "dot1ad"))
6302 if ((src + dst + proto + tag1 + tag2 + dot1q + dot1ad +
6303 ignore_tag1 + ignore_tag2 + cos1 + cos2) == 0)
6306 if (tag1 || ignore_tag1 || cos1 || dot1q)
6308 if (tag2 || ignore_tag2 || cos2 || dot1ad)
6311 vec_validate (mask, len-1);
6314 memset (mask, 0xff, 6);
6317 memset (mask + 6, 0xff, 6);
6321 /* inner vlan tag */
6330 mask[21] = mask [20] = 0xff;
6351 mask[16] = mask [17] = 0xff;
6361 mask[12] = mask [13] = 0xff;
6367 uword unformat_classify_mask (unformat_input_t * input, va_list * args)
6369 u8 ** maskp = va_arg (*args, u8 **);
6370 u32 * skipp = va_arg (*args, u32 *);
6371 u32 * matchp = va_arg (*args, u32 *);
6378 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) {
6379 if (unformat (input, "hex %U", unformat_hex_string, &mask))
6381 else if (unformat (input, "l2 %U", unformat_l2_mask, &l2))
6383 else if (unformat (input, "l3 %U", unformat_l3_mask, &l3))
6389 if (mask || l2 || l3)
6393 /* "With a free Ethernet header in every package" */
6395 vec_validate (l2, 13);
6397 vec_append (mask, l3);
6401 /* Scan forward looking for the first significant mask octet */
6402 for (i = 0; i < vec_len (mask); i++)
6406 /* compute (skip, match) params */
6407 *skipp = i / sizeof(u32x4);
6408 vec_delete (mask, *skipp * sizeof(u32x4), 0);
6410 /* Pad mask to an even multiple of the vector size */
6411 while (vec_len (mask) % sizeof (u32x4))
6414 match = vec_len (mask) / sizeof (u32x4);
6416 for (i = match*sizeof(u32x4); i > 0; i-= sizeof(u32x4))
6418 u64 *tmp = (u64 *)(mask + (i-sizeof(u32x4)));
6419 if (*tmp || *(tmp+1))
6424 clib_warning ("BUG: match 0");
6426 _vec_len (mask) = match * sizeof(u32x4);
6437 #define foreach_l2_next \
6439 _(ethernet, ETHERNET_INPUT) \
6443 uword unformat_l2_next_index (unformat_input_t * input, va_list * args)
6445 u32 * miss_next_indexp = va_arg (*args, u32 *);
6450 if (unformat (input, #n)) { next_index = L2_CLASSIFY_NEXT_##N; goto out;}
6454 if (unformat (input, "%d", &tmp))
6463 *miss_next_indexp = next_index;
6467 #define foreach_ip_next \
6473 uword unformat_ip_next_index (unformat_input_t * input, va_list * args)
6475 u32 * miss_next_indexp = va_arg (*args, u32 *);
6480 if (unformat (input, #n)) { next_index = IP_LOOKUP_NEXT_##N; goto out;}
6484 if (unformat (input, "%d", &tmp))
6493 *miss_next_indexp = next_index;
6497 #define foreach_acl_next \
6500 uword unformat_acl_next_index (unformat_input_t * input, va_list * args)
6502 u32 * miss_next_indexp = va_arg (*args, u32 *);
6507 if (unformat (input, #n)) { next_index = ACL_NEXT_INDEX_##N; goto out;}
6511 if (unformat (input, "permit"))
6516 else if (unformat (input, "%d", &tmp))
6525 *miss_next_indexp = next_index;
6529 static int api_classify_add_del_table (vat_main_t * vam)
6531 unformat_input_t * i = vam->input;
6532 vl_api_classify_add_del_table_t *mp;
6538 u32 table_index = ~0;
6539 u32 next_table_index = ~0;
6540 u32 miss_next_index = ~0;
6541 u32 memory_size = 32<<20;
6545 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
6546 if (unformat (i, "del"))
6548 else if (unformat (i, "buckets %d", &nbuckets))
6550 else if (unformat (i, "memory_size %d", &memory_size))
6552 else if (unformat (i, "skip %d", &skip))
6554 else if (unformat (i, "match %d", &match))
6556 else if (unformat (i, "table %d", &table_index))
6558 else if (unformat (i, "mask %U", unformat_classify_mask,
6559 &mask, &skip, &match))
6561 else if (unformat (i, "next-table %d", &next_table_index))
6563 else if (unformat (i, "miss-next %U", unformat_ip_next_index,
6566 else if (unformat (i, "l2-miss-next %U", unformat_l2_next_index,
6569 else if (unformat (i, "acl-miss-next %U", unformat_acl_next_index,
6576 if (is_add && mask == 0) {
6577 errmsg ("Mask required\n");
6581 if (is_add && skip == ~0) {
6582 errmsg ("skip count required\n");
6586 if (is_add && match == ~0) {
6587 errmsg ("match count required\n");
6591 if (!is_add && table_index == ~0) {
6592 errmsg ("table index required for delete\n");
6596 M2 (CLASSIFY_ADD_DEL_TABLE, classify_add_del_table,
6599 mp->is_add = is_add;
6600 mp->table_index = ntohl(table_index);
6601 mp->nbuckets = ntohl(nbuckets);
6602 mp->memory_size = ntohl(memory_size);
6603 mp->skip_n_vectors = ntohl(skip);
6604 mp->match_n_vectors = ntohl(match);
6605 mp->next_table_index = ntohl(next_table_index);
6606 mp->miss_next_index = ntohl(miss_next_index);
6607 clib_memcpy (mp->mask, mask, vec_len(mask));
6615 uword unformat_ip4_match (unformat_input_t * input, va_list * args)
6617 u8 ** matchp = va_arg (*args, u8 **);
6624 int src = 0, dst = 0;
6625 ip4_address_t src_val, dst_val;
6632 int fragment_id = 0;
6633 u32 fragment_id_val;
6639 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
6641 if (unformat (input, "version %d", &version_val))
6643 else if (unformat (input, "hdr_length %d", &hdr_length_val))
6645 else if (unformat (input, "src %U", unformat_ip4_address, &src_val))
6647 else if (unformat (input, "dst %U", unformat_ip4_address, &dst_val))
6649 else if (unformat (input, "proto %d", &proto_val))
6651 else if (unformat (input, "tos %d", &tos_val))
6653 else if (unformat (input, "length %d", &length_val))
6655 else if (unformat (input, "fragment_id %d", &fragment_id_val))
6657 else if (unformat (input, "ttl %d", &ttl_val))
6659 else if (unformat (input, "checksum %d", &checksum_val))
6665 if (version + hdr_length + src + dst + proto + tos + length + fragment_id
6666 + ttl + checksum == 0)
6670 * Aligned because we use the real comparison functions
6672 vec_validate_aligned (match, sizeof (*ip) - 1, sizeof(u32x4));
6674 ip = (ip4_header_t *) match;
6676 /* These are realistically matched in practice */
6678 ip->src_address.as_u32 = src_val.as_u32;
6681 ip->dst_address.as_u32 = dst_val.as_u32;
6684 ip->protocol = proto_val;
6687 /* These are not, but they're included for completeness */
6689 ip->ip_version_and_header_length |= (version_val & 0xF)<<4;
6692 ip->ip_version_and_header_length |= (hdr_length_val & 0xF);
6698 ip->length = length_val;
6704 ip->checksum = checksum_val;
6710 uword unformat_ip6_match (unformat_input_t * input, va_list * args)
6712 u8 ** matchp = va_arg (*args, u8 **);
6718 u32 traffic_class_val;
6721 int src = 0, dst = 0;
6722 ip6_address_t src_val, dst_val;
6725 int payload_length = 0;
6726 u32 payload_length_val;
6729 u32 ip_version_traffic_class_and_flow_label;
6731 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
6733 if (unformat (input, "version %d", &version_val))
6735 else if (unformat (input, "traffic_class %d", &traffic_class_val))
6737 else if (unformat (input, "flow_label %d", &flow_label_val))
6739 else if (unformat (input, "src %U", unformat_ip6_address, &src_val))
6741 else if (unformat (input, "dst %U", unformat_ip6_address, &dst_val))
6743 else if (unformat (input, "proto %d", &proto_val))
6745 else if (unformat (input, "payload_length %d", &payload_length_val))
6747 else if (unformat (input, "hop_limit %d", &hop_limit_val))
6753 if (version + traffic_class + flow_label + src + dst + proto +
6754 payload_length + hop_limit == 0)
6758 * Aligned because we use the real comparison functions
6760 vec_validate_aligned (match, sizeof (*ip) - 1, sizeof(u32x4));
6762 ip = (ip6_header_t *) match;
6765 clib_memcpy (&ip->src_address, &src_val, sizeof (ip->src_address));
6768 clib_memcpy (&ip->dst_address, &dst_val, sizeof (ip->dst_address));
6771 ip->protocol = proto_val;
6773 ip_version_traffic_class_and_flow_label = 0;
6776 ip_version_traffic_class_and_flow_label |= (version_val & 0xF) << 28;
6779 ip_version_traffic_class_and_flow_label |= (traffic_class_val & 0xFF) << 20;
6782 ip_version_traffic_class_and_flow_label |= (flow_label_val & 0xFFFFF);
6784 ip->ip_version_traffic_class_and_flow_label =
6785 clib_host_to_net_u32 (ip_version_traffic_class_and_flow_label);
6788 ip->payload_length = clib_host_to_net_u16 (payload_length_val);
6791 ip->hop_limit = hop_limit_val;
6797 uword unformat_l3_match (unformat_input_t * input, va_list * args)
6799 u8 ** matchp = va_arg (*args, u8 **);
6801 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) {
6802 if (unformat (input, "ip4 %U", unformat_ip4_match, matchp))
6804 else if (unformat (input, "ip6 %U", unformat_ip6_match, matchp))
6812 uword unformat_vlan_tag (unformat_input_t * input, va_list * args)
6814 u8 * tagp = va_arg (*args, u8 *);
6817 if (unformat(input, "%d", &tag))
6819 tagp[0] = (tag>>8) & 0x0F;
6820 tagp[1] = tag & 0xFF;
6827 uword unformat_l2_match (unformat_input_t * input, va_list * args)
6829 u8 ** matchp = va_arg (*args, u8 **);
6849 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) {
6850 if (unformat (input, "src %U", unformat_ethernet_address, &src_val))
6852 else if (unformat (input, "dst %U", unformat_ethernet_address, &dst_val))
6854 else if (unformat (input, "proto %U",
6855 unformat_ethernet_type_host_byte_order, &proto_val))
6857 else if (unformat (input, "tag1 %U", unformat_vlan_tag, tag1_val))
6859 else if (unformat (input, "tag2 %U", unformat_vlan_tag, tag2_val))
6861 else if (unformat (input, "ignore-tag1"))
6863 else if (unformat (input, "ignore-tag2"))
6865 else if (unformat (input, "cos1 %d", &cos1_val))
6867 else if (unformat (input, "cos2 %d", &cos2_val))
6872 if ((src + dst + proto + tag1 + tag2 +
6873 ignore_tag1 + ignore_tag2 + cos1 + cos2) == 0)
6876 if (tag1 || ignore_tag1 || cos1)
6878 if (tag2 || ignore_tag2 || cos2)
6881 vec_validate_aligned (match, len-1, sizeof(u32x4));
6884 clib_memcpy (match, dst_val, 6);
6887 clib_memcpy (match + 6, src_val, 6);
6891 /* inner vlan tag */
6892 match[19] = tag2_val[1];
6893 match[18] = tag2_val[0];
6895 match [18] |= (cos2_val & 0x7) << 5;
6898 match[21] = proto_val & 0xff;
6899 match[20] = proto_val >> 8;
6903 match [15] = tag1_val[1];
6904 match [14] = tag1_val[0];
6907 match [14] |= (cos1_val & 0x7) << 5;
6913 match [15] = tag1_val[1];
6914 match [14] = tag1_val[0];
6917 match[17] = proto_val & 0xff;
6918 match[16] = proto_val >> 8;
6921 match [14] |= (cos1_val & 0x7) << 5;
6927 match [18] |= (cos2_val & 0x7) << 5;
6929 match [14] |= (cos1_val & 0x7) << 5;
6932 match[13] = proto_val & 0xff;
6933 match[12] = proto_val >> 8;
6941 uword unformat_classify_match (unformat_input_t * input, va_list * args)
6943 u8 ** matchp = va_arg (*args, u8 **);
6944 u32 skip_n_vectors = va_arg (*args, u32);
6945 u32 match_n_vectors = va_arg (*args, u32);
6951 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) {
6952 if (unformat (input, "hex %U", unformat_hex_string, &match))
6954 else if (unformat (input, "l2 %U", unformat_l2_match, &l2))
6956 else if (unformat (input, "l3 %U", unformat_l3_match, &l3))
6962 if (match || l2 || l3)
6966 /* "Win a free Ethernet header in every packet" */
6968 vec_validate_aligned (l2, 13, sizeof(u32x4));
6970 vec_append_aligned (match, l3, sizeof(u32x4));
6974 /* Make sure the vector is big enough even if key is all 0's */
6975 vec_validate_aligned
6976 (match, ((match_n_vectors + skip_n_vectors) * sizeof(u32x4)) - 1,
6979 /* Set size, include skipped vectors*/
6980 _vec_len (match) = (match_n_vectors+skip_n_vectors) * sizeof(u32x4);
6990 static int api_classify_add_del_session (vat_main_t * vam)
6992 unformat_input_t * i = vam->input;
6993 vl_api_classify_add_del_session_t *mp;
6995 u32 table_index = ~0;
6996 u32 hit_next_index = ~0;
6997 u32 opaque_index = ~0;
7001 u32 skip_n_vectors = 0;
7002 u32 match_n_vectors = 0;
7005 * Warning: you have to supply skip_n and match_n
7006 * because the API client cant simply look at the classify
7010 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
7011 if (unformat (i, "del"))
7013 else if (unformat (i, "hit-next %U", unformat_ip_next_index,
7016 else if (unformat (i, "l2-hit-next %U", unformat_l2_next_index,
7019 else if (unformat (i, "acl-hit-next %U", unformat_acl_next_index,
7022 else if (unformat (i, "opaque-index %d", &opaque_index))
7024 else if (unformat (i, "skip_n %d", &skip_n_vectors))
7026 else if (unformat (i, "match_n %d", &match_n_vectors))
7028 else if (unformat (i, "match %U", unformat_classify_match,
7029 &match, skip_n_vectors, match_n_vectors))
7031 else if (unformat (i, "advance %d", &advance))
7033 else if (unformat (i, "table-index %d", &table_index))
7039 if (table_index == ~0) {
7040 errmsg ("Table index required\n");
7044 if (is_add && match == 0) {
7045 errmsg ("Match value required\n");
7049 M2 (CLASSIFY_ADD_DEL_SESSION, classify_add_del_session,
7052 mp->is_add = is_add;
7053 mp->table_index = ntohl(table_index);
7054 mp->hit_next_index = ntohl(hit_next_index);
7055 mp->opaque_index = ntohl(opaque_index);
7056 mp->advance = ntohl(advance);
7057 clib_memcpy (mp->match, match, vec_len(match));
7064 static int api_classify_set_interface_ip_table (vat_main_t * vam)
7066 unformat_input_t * i = vam->input;
7067 vl_api_classify_set_interface_ip_table_t *mp;
7070 int sw_if_index_set;
7071 u32 table_index = ~0;
7074 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
7075 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
7076 sw_if_index_set = 1;
7077 else if (unformat (i, "sw_if_index %d", &sw_if_index))
7078 sw_if_index_set = 1;
7079 else if (unformat (i, "table %d", &table_index))
7082 clib_warning ("parse error '%U'", format_unformat_error, i);
7087 if (sw_if_index_set == 0) {
7088 errmsg ("missing interface name or sw_if_index\n");
7093 M(CLASSIFY_SET_INTERFACE_IP_TABLE, classify_set_interface_ip_table);
7095 mp->sw_if_index = ntohl(sw_if_index);
7096 mp->table_index = ntohl(table_index);
7097 mp->is_ipv6 = is_ipv6;
7104 static int api_classify_set_interface_l2_tables (vat_main_t * vam)
7106 unformat_input_t * i = vam->input;
7107 vl_api_classify_set_interface_l2_tables_t *mp;
7110 int sw_if_index_set;
7111 u32 ip4_table_index = ~0;
7112 u32 ip6_table_index = ~0;
7113 u32 other_table_index = ~0;
7115 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
7116 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
7117 sw_if_index_set = 1;
7118 else if (unformat (i, "sw_if_index %d", &sw_if_index))
7119 sw_if_index_set = 1;
7120 else if (unformat (i, "ip4-table %d", &ip4_table_index))
7122 else if (unformat (i, "ip6-table %d", &ip6_table_index))
7124 else if (unformat (i, "other-table %d", &other_table_index))
7127 clib_warning ("parse error '%U'", format_unformat_error, i);
7132 if (sw_if_index_set == 0) {
7133 errmsg ("missing interface name or sw_if_index\n");
7138 M(CLASSIFY_SET_INTERFACE_L2_TABLES, classify_set_interface_l2_tables);
7140 mp->sw_if_index = ntohl(sw_if_index);
7141 mp->ip4_table_index = ntohl(ip4_table_index);
7142 mp->ip6_table_index = ntohl(ip6_table_index);
7143 mp->other_table_index = ntohl(other_table_index);
7151 static int api_get_node_index (vat_main_t * vam)
7153 unformat_input_t * i = vam->input;
7154 vl_api_get_node_index_t * mp;
7158 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
7159 if (unformat (i, "node %s", &name))
7165 errmsg ("node name required\n");
7168 if (vec_len (name) >= ARRAY_LEN(mp->node_name)) {
7169 errmsg ("node name too long, max %d\n", ARRAY_LEN(mp->node_name));
7173 M(GET_NODE_INDEX, get_node_index);
7174 clib_memcpy (mp->node_name, name, vec_len(name));
7182 static int api_add_node_next (vat_main_t * vam)
7184 unformat_input_t * i = vam->input;
7185 vl_api_add_node_next_t * mp;
7190 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
7191 if (unformat (i, "node %s", &name))
7193 else if (unformat (i, "next %s", &next))
7199 errmsg ("node name required\n");
7202 if (vec_len (name) >= ARRAY_LEN(mp->node_name)) {
7203 errmsg ("node name too long, max %d\n", ARRAY_LEN(mp->node_name));
7207 errmsg ("next node required\n");
7210 if (vec_len (next) >= ARRAY_LEN(mp->next_name)) {
7211 errmsg ("next name too long, max %d\n", ARRAY_LEN(mp->next_name));
7215 M(ADD_NODE_NEXT, add_node_next);
7216 clib_memcpy (mp->node_name, name, vec_len(name));
7217 clib_memcpy (mp->next_name, next, vec_len(next));
7226 static int api_l2tpv3_create_tunnel (vat_main_t * vam)
7228 unformat_input_t * i = vam->input;
7229 ip6_address_t client_address, our_address;
7230 int client_address_set = 0;
7231 int our_address_set = 0;
7232 u32 local_session_id = 0;
7233 u32 remote_session_id = 0;
7234 u64 local_cookie = 0;
7235 u64 remote_cookie = 0;
7236 u8 l2_sublayer_present = 0;
7237 vl_api_l2tpv3_create_tunnel_t * mp;
7240 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
7241 if (unformat (i, "client_address %U", unformat_ip6_address,
7243 client_address_set = 1;
7244 else if (unformat (i, "our_address %U", unformat_ip6_address,
7246 our_address_set = 1;
7247 else if (unformat (i, "local_session_id %d", &local_session_id))
7249 else if (unformat (i, "remote_session_id %d", &remote_session_id))
7251 else if (unformat (i, "local_cookie %lld", &local_cookie))
7253 else if (unformat (i, "remote_cookie %lld", &remote_cookie))
7255 else if (unformat (i, "l2-sublayer-present"))
7256 l2_sublayer_present = 1;
7261 if (client_address_set == 0) {
7262 errmsg ("client_address required\n");
7266 if (our_address_set == 0) {
7267 errmsg ("our_address required\n");
7271 M(L2TPV3_CREATE_TUNNEL, l2tpv3_create_tunnel);
7273 clib_memcpy (mp->client_address, client_address.as_u8,
7274 sizeof (mp->client_address));
7276 clib_memcpy (mp->our_address, our_address.as_u8,
7277 sizeof (mp->our_address));
7279 mp->local_session_id = ntohl (local_session_id);
7280 mp->remote_session_id = ntohl (remote_session_id);
7281 mp->local_cookie = clib_host_to_net_u64 (local_cookie);
7282 mp->remote_cookie = clib_host_to_net_u64 (remote_cookie);
7283 mp->l2_sublayer_present = l2_sublayer_present;
7291 static int api_l2tpv3_set_tunnel_cookies (vat_main_t * vam)
7293 unformat_input_t * i = vam->input;
7295 u8 sw_if_index_set = 0;
7296 u64 new_local_cookie = 0;
7297 u64 new_remote_cookie = 0;
7298 vl_api_l2tpv3_set_tunnel_cookies_t *mp;
7301 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
7302 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
7303 sw_if_index_set = 1;
7304 else if (unformat (i, "sw_if_index %d", &sw_if_index))
7305 sw_if_index_set = 1;
7306 else if (unformat (i, "new_local_cookie %lld", &new_local_cookie))
7308 else if (unformat (i, "new_remote_cookie %lld", &new_remote_cookie))
7314 if (sw_if_index_set == 0) {
7315 errmsg ("missing interface name or sw_if_index\n");
7319 M(L2TPV3_SET_TUNNEL_COOKIES, l2tpv3_set_tunnel_cookies);
7321 mp->sw_if_index = ntohl(sw_if_index);
7322 mp->new_local_cookie = clib_host_to_net_u64 (new_local_cookie);
7323 mp->new_remote_cookie = clib_host_to_net_u64 (new_remote_cookie);
7330 static int api_l2tpv3_interface_enable_disable (vat_main_t * vam)
7332 unformat_input_t * i = vam->input;
7333 vl_api_l2tpv3_interface_enable_disable_t *mp;
7336 u8 sw_if_index_set = 0;
7337 u8 enable_disable = 1;
7339 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
7340 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
7341 sw_if_index_set = 1;
7342 else if (unformat (i, "sw_if_index %d", &sw_if_index))
7343 sw_if_index_set = 1;
7344 else if (unformat (i, "enable"))
7346 else if (unformat (i, "disable"))
7352 if (sw_if_index_set == 0) {
7353 errmsg ("missing interface name or sw_if_index\n");
7357 M(L2TPV3_INTERFACE_ENABLE_DISABLE, l2tpv3_interface_enable_disable);
7359 mp->sw_if_index = ntohl(sw_if_index);
7360 mp->enable_disable = enable_disable;
7367 static int api_l2tpv3_set_lookup_key (vat_main_t * vam)
7369 unformat_input_t * i = vam->input;
7370 vl_api_l2tpv3_set_lookup_key_t * mp;
7374 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
7375 if (unformat (i, "lookup_v6_src"))
7376 key = L2T_LOOKUP_SRC_ADDRESS;
7377 else if (unformat (i, "lookup_v6_dst"))
7378 key = L2T_LOOKUP_DST_ADDRESS;
7379 else if (unformat (i, "lookup_session_id"))
7380 key = L2T_LOOKUP_SESSION_ID;
7385 if (key == (u8) ~0) {
7386 errmsg ("l2tp session lookup key unset\n");
7390 M(L2TPV3_SET_LOOKUP_KEY, l2tpv3_set_lookup_key);
7399 static void vl_api_sw_if_l2tpv3_tunnel_details_t_handler
7400 (vl_api_sw_if_l2tpv3_tunnel_details_t * mp)
7402 vat_main_t * vam = &vat_main;
7404 fformat(vam->ofp, "* %U (our) %U (client) (sw_if_index %d)\n",
7405 format_ip6_address, mp->our_address,
7406 format_ip6_address, mp->client_address,
7407 clib_net_to_host_u32(mp->sw_if_index));
7409 fformat (vam->ofp, " local cookies %016llx %016llx remote cookie %016llx\n",
7410 clib_net_to_host_u64 (mp->local_cookie[0]),
7411 clib_net_to_host_u64 (mp->local_cookie[1]),
7412 clib_net_to_host_u64 (mp->remote_cookie));
7414 fformat (vam->ofp, " local session-id %d remote session-id %d\n",
7415 clib_net_to_host_u32 (mp->local_session_id),
7416 clib_net_to_host_u32 (mp->remote_session_id));
7418 fformat (vam->ofp, " l2 specific sublayer %s\n\n",
7419 mp->l2_sublayer_present ? "preset" : "absent");
7423 static void vl_api_sw_if_l2tpv3_tunnel_details_t_handler_json
7424 (vl_api_sw_if_l2tpv3_tunnel_details_t * mp)
7426 vat_main_t * vam = &vat_main;
7427 vat_json_node_t *node = NULL;
7428 struct in6_addr addr;
7430 if (VAT_JSON_ARRAY != vam->json_tree.type) {
7431 ASSERT(VAT_JSON_NONE == vam->json_tree.type);
7432 vat_json_init_array(&vam->json_tree);
7434 node = vat_json_array_add(&vam->json_tree);
7436 vat_json_init_object(node);
7438 clib_memcpy(&addr, mp->our_address, sizeof(addr));
7439 vat_json_object_add_ip6(node, "our_address", addr);
7440 clib_memcpy(&addr, mp->client_address, sizeof(addr));
7441 vat_json_object_add_ip6(node, "client_address", addr);
7443 vat_json_node_t * lc = vat_json_object_add(node, "local_cookie");
7444 vat_json_init_array(lc);
7445 vat_json_array_add_uint(lc, clib_net_to_host_u64(mp->local_cookie[0]));
7446 vat_json_array_add_uint(lc, clib_net_to_host_u64(mp->local_cookie[1]));
7447 vat_json_object_add_uint(node, "remote_cookie", clib_net_to_host_u64(mp->remote_cookie));
7449 printf("local id: %u", clib_net_to_host_u32(mp->local_session_id));
7450 vat_json_object_add_uint(node, "local_session_id", clib_net_to_host_u32(mp->local_session_id));
7451 vat_json_object_add_uint(node, "remote_session_id", clib_net_to_host_u32(mp->remote_session_id));
7452 vat_json_object_add_string_copy(node, "l2_sublayer", mp->l2_sublayer_present ?
7453 (u8*)"present" : (u8*)"absent");
7456 static int api_sw_if_l2tpv3_tunnel_dump (vat_main_t * vam)
7458 vl_api_sw_if_l2tpv3_tunnel_dump_t *mp;
7461 /* Get list of l2tpv3-tunnel interfaces */
7462 M(SW_IF_L2TPV3_TUNNEL_DUMP, sw_if_l2tpv3_tunnel_dump);
7465 /* Use a control ping for synchronization */
7467 vl_api_control_ping_t * mp;
7468 M(CONTROL_PING, control_ping);
7475 static void vl_api_sw_interface_tap_details_t_handler
7476 (vl_api_sw_interface_tap_details_t * mp)
7478 vat_main_t * vam = &vat_main;
7480 fformat(vam->ofp, "%-16s %d\n",
7482 clib_net_to_host_u32(mp->sw_if_index));
7485 static void vl_api_sw_interface_tap_details_t_handler_json
7486 (vl_api_sw_interface_tap_details_t * mp)
7488 vat_main_t * vam = &vat_main;
7489 vat_json_node_t *node = NULL;
7491 if (VAT_JSON_ARRAY != vam->json_tree.type) {
7492 ASSERT(VAT_JSON_NONE == vam->json_tree.type);
7493 vat_json_init_array(&vam->json_tree);
7495 node = vat_json_array_add(&vam->json_tree);
7497 vat_json_init_object(node);
7498 vat_json_object_add_uint(node, "sw_if_index", ntohl(mp->sw_if_index));
7499 vat_json_object_add_string_copy(node, "dev_name", mp->dev_name);
7502 static int api_sw_interface_tap_dump (vat_main_t * vam)
7504 vl_api_sw_interface_tap_dump_t *mp;
7507 fformat(vam->ofp, "\n%-16s %s\n", "dev_name", "sw_if_index");
7508 /* Get list of tap interfaces */
7509 M(SW_INTERFACE_TAP_DUMP, sw_interface_tap_dump);
7512 /* Use a control ping for synchronization */
7514 vl_api_control_ping_t * mp;
7515 M(CONTROL_PING, control_ping);
7521 static uword unformat_vxlan_decap_next
7522 (unformat_input_t * input, va_list * args)
7524 u32 * result = va_arg (*args, u32 *);
7527 if (unformat (input, "drop"))
7528 *result = VXLAN_INPUT_NEXT_DROP;
7529 else if (unformat (input, "ip4"))
7530 *result = VXLAN_INPUT_NEXT_IP4_INPUT;
7531 else if (unformat (input, "ip6"))
7532 *result = VXLAN_INPUT_NEXT_IP6_INPUT;
7533 else if (unformat (input, "l2"))
7534 *result = VXLAN_INPUT_NEXT_L2_INPUT;
7535 else if (unformat (input, "%d", &tmp))
7542 static int api_vxlan_add_del_tunnel (vat_main_t * vam)
7544 unformat_input_t * line_input = vam->input;
7545 vl_api_vxlan_add_del_tunnel_t *mp;
7547 ip4_address_t src4, dst4;
7548 ip6_address_t src6, dst6;
7550 u8 ipv4_set = 0, ipv6_set = 0;
7553 u32 encap_vrf_id = 0;
7554 u32 decap_next_index = ~0;
7557 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) {
7558 if (unformat (line_input, "del"))
7560 else if (unformat (line_input, "src %U",
7561 unformat_ip4_address, &src4))
7566 else if (unformat (line_input, "dst %U",
7567 unformat_ip4_address, &dst4))
7572 else if (unformat (line_input, "src %U",
7573 unformat_ip6_address, &src6))
7578 else if (unformat (line_input, "dst %U",
7579 unformat_ip6_address, &dst6))
7584 else if (unformat (line_input, "encap-vrf-id %d", &encap_vrf_id))
7586 else if (unformat (line_input, "decap-next %U",
7587 unformat_vxlan_decap_next, &decap_next_index))
7589 else if (unformat (line_input, "vni %d", &vni))
7592 errmsg ("parse error '%U'\n", format_unformat_error, line_input);
7598 errmsg ("tunnel src address not specified\n");
7602 errmsg ("tunnel dst address not specified\n");
7606 if (ipv4_set && ipv6_set) {
7607 errmsg ("both IPv4 and IPv6 addresses specified");
7611 if ((vni == 0) || (vni>>24)) {
7612 errmsg ("vni not specified or out of range\n");
7616 M (VXLAN_ADD_DEL_TUNNEL, vxlan_add_del_tunnel);
7619 clib_memcpy(&mp->src_address, &src6, sizeof(src6));
7620 clib_memcpy(&mp->dst_address, &dst6, sizeof(dst6));
7622 clib_memcpy(&mp->src_address, &src4, sizeof(src4));
7623 clib_memcpy(&mp->dst_address, &dst4, sizeof(dst4));
7625 mp->encap_vrf_id = ntohl(encap_vrf_id);
7626 mp->decap_next_index = ntohl(decap_next_index);
7627 mp->vni = ntohl(vni);
7628 mp->is_add = is_add;
7629 mp->is_ipv6 = ipv6_set;
7636 static void vl_api_vxlan_tunnel_details_t_handler
7637 (vl_api_vxlan_tunnel_details_t * mp)
7639 vat_main_t * vam = &vat_main;
7641 fformat(vam->ofp, "%11d%24U%24U%14d%18d%13d\n",
7642 ntohl(mp->sw_if_index),
7643 format_ip46_address, &(mp->src_address[0]),
7645 format_ip46_address, &(mp->dst_address[0]),
7647 ntohl(mp->encap_vrf_id),
7648 ntohl(mp->decap_next_index),
7652 static void vl_api_vxlan_tunnel_details_t_handler_json
7653 (vl_api_vxlan_tunnel_details_t * mp)
7655 vat_main_t * vam = &vat_main;
7656 vat_json_node_t *node = NULL;
7658 struct in6_addr ip6;
7660 if (VAT_JSON_ARRAY != vam->json_tree.type) {
7661 ASSERT(VAT_JSON_NONE == vam->json_tree.type);
7662 vat_json_init_array(&vam->json_tree);
7664 node = vat_json_array_add(&vam->json_tree);
7666 vat_json_init_object(node);
7667 vat_json_object_add_uint(node, "sw_if_index", ntohl(mp->sw_if_index));
7669 clib_memcpy(&ip6, &(mp->src_address[0]), sizeof(ip6));
7670 vat_json_object_add_ip6(node, "src_address", ip6);
7671 clib_memcpy(&ip6, &(mp->dst_address[0]), sizeof(ip6));
7672 vat_json_object_add_ip6(node, "dst_address", ip6);
7674 clib_memcpy(&ip4, &(mp->src_address[0]), sizeof(ip4));
7675 vat_json_object_add_ip4(node, "src_address", ip4);
7676 clib_memcpy(&ip4, &(mp->dst_address[0]), sizeof(ip4));
7677 vat_json_object_add_ip4(node, "dst_address", ip4);
7679 vat_json_object_add_uint(node, "encap_vrf_id", ntohl(mp->encap_vrf_id));
7680 vat_json_object_add_uint(node, "decap_next_index", ntohl(mp->decap_next_index));
7681 vat_json_object_add_uint(node, "vni", ntohl(mp->vni));
7682 vat_json_object_add_uint(node, "is_ipv6", mp->is_ipv6 ? 1 : 0);
7685 static int api_vxlan_tunnel_dump (vat_main_t * vam)
7687 unformat_input_t * i = vam->input;
7688 vl_api_vxlan_tunnel_dump_t *mp;
7691 u8 sw_if_index_set = 0;
7693 /* Parse args required to build the message */
7694 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
7695 if (unformat (i, "sw_if_index %d", &sw_if_index))
7696 sw_if_index_set = 1;
7701 if (sw_if_index_set == 0) {
7705 if (!vam->json_output) {
7706 fformat(vam->ofp, "%11s%24s%24s%14s%18s%13s\n",
7707 "sw_if_index", "src_address", "dst_address",
7708 "encap_vrf_id", "decap_next_index", "vni");
7711 /* Get list of vxlan-tunnel interfaces */
7712 M(VXLAN_TUNNEL_DUMP, vxlan_tunnel_dump);
7714 mp->sw_if_index = htonl(sw_if_index);
7718 /* Use a control ping for synchronization */
7720 vl_api_control_ping_t * mp;
7721 M(CONTROL_PING, control_ping);
7727 static int api_gre_add_del_tunnel (vat_main_t * vam)
7729 unformat_input_t * line_input = vam->input;
7730 vl_api_gre_add_del_tunnel_t *mp;
7732 ip4_address_t src4, dst4;
7736 u32 outer_fib_id = 0;
7738 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) {
7739 if (unformat (line_input, "del"))
7741 else if (unformat (line_input, "src %U",
7742 unformat_ip4_address, &src4))
7744 else if (unformat (line_input, "dst %U",
7745 unformat_ip4_address, &dst4))
7747 else if (unformat (line_input, "outer-fib-id %d", &outer_fib_id))
7750 errmsg ("parse error '%U'\n", format_unformat_error, line_input);
7756 errmsg ("tunnel src address not specified\n");
7760 errmsg ("tunnel dst address not specified\n");
7765 M (GRE_ADD_DEL_TUNNEL, gre_add_del_tunnel);
7767 clib_memcpy(&mp->src_address, &src4, sizeof(src4));
7768 clib_memcpy(&mp->dst_address, &dst4, sizeof(dst4));
7769 mp->outer_table_id = ntohl(outer_fib_id);
7770 mp->is_add = is_add;
7777 static void vl_api_gre_tunnel_details_t_handler
7778 (vl_api_gre_tunnel_details_t * mp)
7780 vat_main_t * vam = &vat_main;
7782 fformat(vam->ofp, "%11d%15U%15U%14d\n",
7783 ntohl(mp->sw_if_index),
7784 format_ip4_address, &mp->src_address,
7785 format_ip4_address, &mp->dst_address,
7786 ntohl(mp->outer_table_id));
7789 static void vl_api_gre_tunnel_details_t_handler_json
7790 (vl_api_gre_tunnel_details_t * mp)
7792 vat_main_t * vam = &vat_main;
7793 vat_json_node_t *node = NULL;
7796 if (VAT_JSON_ARRAY != vam->json_tree.type) {
7797 ASSERT(VAT_JSON_NONE == vam->json_tree.type);
7798 vat_json_init_array(&vam->json_tree);
7800 node = vat_json_array_add(&vam->json_tree);
7802 vat_json_init_object(node);
7803 vat_json_object_add_uint(node, "sw_if_index", ntohl(mp->sw_if_index));
7804 clib_memcpy(&ip4, &mp->src_address, sizeof(ip4));
7805 vat_json_object_add_ip4(node, "src_address", ip4);
7806 clib_memcpy(&ip4, &mp->dst_address, sizeof(ip4));
7807 vat_json_object_add_ip4(node, "dst_address", ip4);
7808 vat_json_object_add_uint(node, "outer_fib_id", ntohl(mp->outer_table_id));
7811 static int api_gre_tunnel_dump (vat_main_t * vam)
7813 unformat_input_t * i = vam->input;
7814 vl_api_gre_tunnel_dump_t *mp;
7817 u8 sw_if_index_set = 0;
7819 /* Parse args required to build the message */
7820 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
7821 if (unformat (i, "sw_if_index %d", &sw_if_index))
7822 sw_if_index_set = 1;
7827 if (sw_if_index_set == 0) {
7831 if (!vam->json_output) {
7832 fformat(vam->ofp, "%11s%15s%15s%14s\n",
7833 "sw_if_index", "src_address", "dst_address",
7837 /* Get list of gre-tunnel interfaces */
7838 M(GRE_TUNNEL_DUMP, gre_tunnel_dump);
7840 mp->sw_if_index = htonl(sw_if_index);
7844 /* Use a control ping for synchronization */
7846 vl_api_control_ping_t * mp;
7847 M(CONTROL_PING, control_ping);
7853 static int api_l2_fib_clear_table (vat_main_t * vam)
7855 // unformat_input_t * i = vam->input;
7856 vl_api_l2_fib_clear_table_t *mp;
7859 M(L2_FIB_CLEAR_TABLE, l2_fib_clear_table);
7866 static int api_l2_interface_efp_filter (vat_main_t * vam)
7868 unformat_input_t * i = vam->input;
7869 vl_api_l2_interface_efp_filter_t *mp;
7873 u8 sw_if_index_set = 0;
7875 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
7876 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
7877 sw_if_index_set = 1;
7878 else if (unformat (i, "sw_if_index %d", &sw_if_index))
7879 sw_if_index_set = 1;
7880 else if (unformat (i, "enable"))
7882 else if (unformat (i, "disable"))
7885 clib_warning ("parse error '%U'", format_unformat_error, i);
7890 if (sw_if_index_set == 0) {
7891 errmsg ("missing sw_if_index\n");
7895 M(L2_INTERFACE_EFP_FILTER, l2_interface_efp_filter);
7897 mp->sw_if_index = ntohl(sw_if_index);
7898 mp->enable_disable = enable;
7905 #define foreach_vtr_op \
7906 _("disable", L2_VTR_DISABLED) \
7907 _("push-1", L2_VTR_PUSH_1) \
7908 _("push-2", L2_VTR_PUSH_2) \
7909 _("pop-1", L2_VTR_POP_1) \
7910 _("pop-2", L2_VTR_POP_2) \
7911 _("translate-1-1", L2_VTR_TRANSLATE_1_1) \
7912 _("translate-1-2", L2_VTR_TRANSLATE_1_2) \
7913 _("translate-2-1", L2_VTR_TRANSLATE_2_1) \
7914 _("translate-2-2", L2_VTR_TRANSLATE_2_2)
7916 static int api_l2_interface_vlan_tag_rewrite (vat_main_t * vam)
7918 unformat_input_t * i = vam->input;
7919 vl_api_l2_interface_vlan_tag_rewrite_t *mp;
7922 u8 sw_if_index_set = 0;
7929 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
7930 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
7931 sw_if_index_set = 1;
7932 else if (unformat (i, "sw_if_index %d", &sw_if_index))
7933 sw_if_index_set = 1;
7934 else if (unformat (i, "vtr_op %d", &vtr_op))
7936 #define _(n,v) else if (unformat(i, n)) {vtr_op = v; vtr_op_set = 1;}
7940 else if (unformat (i, "push_dot1q %d", &push_dot1q))
7942 else if (unformat (i, "tag1 %d", &tag1))
7944 else if (unformat (i, "tag2 %d", &tag2))
7947 clib_warning ("parse error '%U'", format_unformat_error, i);
7952 if ((sw_if_index_set == 0)||(vtr_op_set == 0)) {
7953 errmsg ("missing vtr operation or sw_if_index\n");
7957 M(L2_INTERFACE_VLAN_TAG_REWRITE, l2_interface_vlan_tag_rewrite)
7959 mp->sw_if_index = ntohl(sw_if_index);
7960 mp->vtr_op = ntohl(vtr_op);
7961 mp->push_dot1q = ntohl(push_dot1q);
7962 mp->tag1 = ntohl(tag1);
7963 mp->tag2 = ntohl(tag2);
7970 static int api_create_vhost_user_if (vat_main_t * vam)
7972 unformat_input_t * i = vam->input;
7973 vl_api_create_vhost_user_if_t *mp;
7977 u8 file_name_set = 0;
7978 u32 custom_dev_instance = ~0;
7980 u8 use_custom_mac = 0;
7982 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
7983 if (unformat (i, "socket %s", &file_name)) {
7986 else if (unformat (i, "renumber %"PRIu32, &custom_dev_instance))
7988 else if (unformat (i, "mac %U", unformat_ethernet_address, hwaddr))
7990 else if (unformat (i, "server"))
7996 if (file_name_set == 0) {
7997 errmsg ("missing socket file name\n");
8001 if (vec_len (file_name) > 255) {
8002 errmsg ("socket file name too long\n");
8005 vec_add1 (file_name, 0);
8007 M(CREATE_VHOST_USER_IF, create_vhost_user_if);
8009 mp->is_server = is_server;
8010 clib_memcpy(mp->sock_filename, file_name, vec_len(file_name));
8011 vec_free(file_name);
8012 if (custom_dev_instance != ~0) {
8014 mp->custom_dev_instance = ntohl(custom_dev_instance);
8016 mp->use_custom_mac = use_custom_mac;
8017 clib_memcpy(mp->mac_address, hwaddr, 6);
8024 static int api_modify_vhost_user_if (vat_main_t * vam)
8026 unformat_input_t * i = vam->input;
8027 vl_api_modify_vhost_user_if_t *mp;
8031 u8 file_name_set = 0;
8032 u32 custom_dev_instance = ~0;
8033 u8 sw_if_index_set = 0;
8034 u32 sw_if_index = (u32)~0;
8036 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
8037 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
8038 sw_if_index_set = 1;
8039 else if (unformat (i, "sw_if_index %d", &sw_if_index))
8040 sw_if_index_set = 1;
8041 else if (unformat (i, "socket %s", &file_name)) {
8044 else if (unformat (i, "renumber %"PRIu32, &custom_dev_instance))
8046 else if (unformat (i, "server"))
8052 if (sw_if_index_set == 0) {
8053 errmsg ("missing sw_if_index or interface name\n");
8057 if (file_name_set == 0) {
8058 errmsg ("missing socket file name\n");
8062 if (vec_len (file_name) > 255) {
8063 errmsg ("socket file name too long\n");
8066 vec_add1 (file_name, 0);
8068 M(MODIFY_VHOST_USER_IF, modify_vhost_user_if);
8070 mp->sw_if_index = ntohl(sw_if_index);
8071 mp->is_server = is_server;
8072 clib_memcpy(mp->sock_filename, file_name, vec_len(file_name));
8073 vec_free(file_name);
8074 if (custom_dev_instance != ~0) {
8076 mp->custom_dev_instance = ntohl(custom_dev_instance);
8084 static int api_delete_vhost_user_if (vat_main_t * vam)
8086 unformat_input_t * i = vam->input;
8087 vl_api_delete_vhost_user_if_t *mp;
8089 u32 sw_if_index = ~0;
8090 u8 sw_if_index_set = 0;
8092 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
8093 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
8094 sw_if_index_set = 1;
8095 else if (unformat (i, "sw_if_index %d", &sw_if_index))
8096 sw_if_index_set = 1;
8101 if (sw_if_index_set == 0) {
8102 errmsg ("missing sw_if_index or interface name\n");
8107 M(DELETE_VHOST_USER_IF, delete_vhost_user_if);
8109 mp->sw_if_index = ntohl(sw_if_index);
8116 static void vl_api_sw_interface_vhost_user_details_t_handler
8117 (vl_api_sw_interface_vhost_user_details_t * mp)
8119 vat_main_t * vam = &vat_main;
8121 fformat(vam->ofp, "%-25s %3" PRIu32 " %6" PRIu32 " %8x %6d %7d %s\n",
8122 (char *)mp->interface_name,
8123 ntohl(mp->sw_if_index), ntohl(mp->virtio_net_hdr_sz),
8124 clib_net_to_host_u64(mp->features), mp->is_server,
8125 ntohl(mp->num_regions), (char *)mp->sock_filename);
8126 fformat(vam->ofp, " Status: '%s'\n", strerror(ntohl(mp->sock_errno)));
8129 static void vl_api_sw_interface_vhost_user_details_t_handler_json
8130 (vl_api_sw_interface_vhost_user_details_t * mp)
8132 vat_main_t * vam = &vat_main;
8133 vat_json_node_t *node = NULL;
8135 if (VAT_JSON_ARRAY != vam->json_tree.type) {
8136 ASSERT(VAT_JSON_NONE == vam->json_tree.type);
8137 vat_json_init_array(&vam->json_tree);
8139 node = vat_json_array_add(&vam->json_tree);
8141 vat_json_init_object(node);
8142 vat_json_object_add_uint(node, "sw_if_index", ntohl(mp->sw_if_index));
8143 vat_json_object_add_string_copy(node, "interface_name", mp->interface_name);
8144 vat_json_object_add_uint(node, "virtio_net_hdr_sz", ntohl(mp->virtio_net_hdr_sz));
8145 vat_json_object_add_uint(node, "features", clib_net_to_host_u64(mp->features));
8146 vat_json_object_add_uint(node, "is_server", mp->is_server);
8147 vat_json_object_add_string_copy(node, "sock_filename", mp->sock_filename);
8148 vat_json_object_add_uint(node, "num_regions", ntohl(mp->num_regions));
8149 vat_json_object_add_uint(node, "sock_errno", ntohl(mp->sock_errno));
8152 static int api_sw_interface_vhost_user_dump (vat_main_t * vam)
8154 vl_api_sw_interface_vhost_user_dump_t *mp;
8156 fformat(vam->ofp, "Interface name idx hdr_sz features server regions filename\n");
8158 /* Get list of vhost-user interfaces */
8159 M(SW_INTERFACE_VHOST_USER_DUMP, sw_interface_vhost_user_dump);
8162 /* Use a control ping for synchronization */
8164 vl_api_control_ping_t * mp;
8165 M(CONTROL_PING, control_ping);
8171 static int api_show_version (vat_main_t * vam)
8173 vl_api_show_version_t *mp;
8176 M(SHOW_VERSION, show_version);
8184 static int api_vxlan_gpe_add_del_tunnel (vat_main_t * vam)
8186 unformat_input_t * line_input = vam->input;
8187 vl_api_vxlan_gpe_add_del_tunnel_t *mp;
8189 ip4_address_t local4, remote4;
8190 ip6_address_t local6, remote6;
8192 u8 ipv4_set = 0, ipv6_set = 0;
8195 u32 encap_vrf_id = 0;
8196 u32 decap_vrf_id = 0;
8201 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) {
8202 if (unformat (line_input, "del"))
8204 else if (unformat (line_input, "local %U",
8205 unformat_ip4_address, &local4))
8210 else if (unformat (line_input, "remote %U",
8211 unformat_ip4_address, &remote4))
8216 else if (unformat (line_input, "local %U",
8217 unformat_ip6_address, &local6))
8222 else if (unformat (line_input, "remote %U",
8223 unformat_ip6_address, &remote6))
8228 else if (unformat (line_input, "encap-vrf-id %d", &encap_vrf_id))
8230 else if (unformat (line_input, "decap-vrf-id %d", &decap_vrf_id))
8232 else if (unformat (line_input, "vni %d", &vni))
8234 else if (unformat(line_input, "next-ip4"))
8236 else if (unformat(line_input, "next-ip6"))
8238 else if (unformat(line_input, "next-ethernet"))
8240 else if (unformat(line_input, "next-nsh"))
8243 errmsg ("parse error '%U'\n", format_unformat_error, line_input);
8248 if (local_set == 0) {
8249 errmsg ("tunnel local address not specified\n");
8252 if (remote_set == 0) {
8253 errmsg ("tunnel remote address not specified\n");
8256 if (ipv4_set && ipv6_set) {
8257 errmsg ("both IPv4 and IPv6 addresses specified");
8262 errmsg ("vni not specified\n");
8266 M(VXLAN_GPE_ADD_DEL_TUNNEL, vxlan_gpe_add_del_tunnel);
8270 clib_memcpy(&mp->local, &local6, sizeof(local6));
8271 clib_memcpy(&mp->remote, &remote6, sizeof(remote6));
8273 clib_memcpy(&mp->local, &local4, sizeof(local4));
8274 clib_memcpy(&mp->remote, &remote4, sizeof(remote4));
8277 mp->encap_vrf_id = ntohl(encap_vrf_id);
8278 mp->decap_vrf_id = ntohl(decap_vrf_id);
8279 mp->protocol = ntohl(protocol);
8280 mp->vni = ntohl(vni);
8281 mp->is_add = is_add;
8282 mp->is_ipv6 = ipv6_set;
8289 static void vl_api_vxlan_gpe_tunnel_details_t_handler
8290 (vl_api_vxlan_gpe_tunnel_details_t * mp)
8292 vat_main_t * vam = &vat_main;
8294 fformat(vam->ofp, "%11d%24U%24U%13d%12d%14d%14d\n",
8295 ntohl(mp->sw_if_index),
8296 format_ip46_address, &(mp->local[0]),
8297 format_ip46_address, &(mp->remote[0]),
8299 ntohl(mp->protocol),
8300 ntohl(mp->encap_vrf_id),
8301 ntohl(mp->decap_vrf_id));
8304 static void vl_api_vxlan_gpe_tunnel_details_t_handler_json
8305 (vl_api_vxlan_gpe_tunnel_details_t * mp)
8307 vat_main_t * vam = &vat_main;
8308 vat_json_node_t *node = NULL;
8310 struct in6_addr ip6;
8312 if (VAT_JSON_ARRAY != vam->json_tree.type) {
8313 ASSERT(VAT_JSON_NONE == vam->json_tree.type);
8314 vat_json_init_array(&vam->json_tree);
8316 node = vat_json_array_add(&vam->json_tree);
8318 vat_json_init_object(node);
8319 vat_json_object_add_uint(node, "sw_if_index", ntohl(mp->sw_if_index));
8321 clib_memcpy(&ip6, &(mp->local[0]), sizeof(ip6));
8322 vat_json_object_add_ip6(node, "local", ip6);
8323 clib_memcpy(&ip6, &(mp->remote[0]), sizeof(ip6));
8324 vat_json_object_add_ip6(node, "remote", ip6);
8326 clib_memcpy(&ip4, &(mp->local[0]), sizeof(ip4));
8327 vat_json_object_add_ip4(node, "local", ip4);
8328 clib_memcpy(&ip4, &(mp->remote[0]), sizeof(ip4));
8329 vat_json_object_add_ip4(node, "remote", ip4);
8331 vat_json_object_add_uint(node, "vni", ntohl(mp->vni));
8332 vat_json_object_add_uint(node, "protocol", ntohl(mp->protocol));
8333 vat_json_object_add_uint(node, "encap_vrf_id", ntohl(mp->encap_vrf_id));
8334 vat_json_object_add_uint(node, "decap_vrf_id", ntohl(mp->decap_vrf_id));
8335 vat_json_object_add_uint(node, "is_ipv6", mp->is_ipv6 ? 1 : 0);
8338 static int api_vxlan_gpe_tunnel_dump (vat_main_t * vam)
8340 unformat_input_t * i = vam->input;
8341 vl_api_vxlan_gpe_tunnel_dump_t *mp;
8344 u8 sw_if_index_set = 0;
8346 /* Parse args required to build the message */
8347 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
8348 if (unformat (i, "sw_if_index %d", &sw_if_index))
8349 sw_if_index_set = 1;
8354 if (sw_if_index_set == 0) {
8358 if (!vam->json_output) {
8359 fformat(vam->ofp, "%11s%24s%24s%13s%15s%14s%14s\n",
8360 "sw_if_index", "local", "remote", "vni",
8361 "protocol","encap_vrf_id", "decap_vrf_id");
8364 /* Get list of vxlan-tunnel interfaces */
8365 M(VXLAN_GPE_TUNNEL_DUMP, vxlan_gpe_tunnel_dump);
8367 mp->sw_if_index = htonl(sw_if_index);
8371 /* Use a control ping for synchronization */
8373 vl_api_control_ping_t * mp;
8374 M(CONTROL_PING, control_ping);
8380 u8 * format_l2_fib_mac_address (u8 * s, va_list * args)
8382 u8 * a = va_arg (*args, u8 *);
8384 return format (s, "%02x:%02x:%02x:%02x:%02x:%02x",
8385 a[2], a[3], a[4], a[5], a[6], a[7]);
8388 static void vl_api_l2_fib_table_entry_t_handler
8389 (vl_api_l2_fib_table_entry_t * mp)
8391 vat_main_t * vam = &vat_main;
8393 fformat(vam->ofp, "%3" PRIu32 " %U %3" PRIu32
8395 ntohl(mp->bd_id), format_l2_fib_mac_address, &mp->mac,
8396 ntohl(mp->sw_if_index), mp->static_mac, mp->filter_mac,
8400 static void vl_api_l2_fib_table_entry_t_handler_json
8401 (vl_api_l2_fib_table_entry_t * mp)
8403 vat_main_t * vam = &vat_main;
8404 vat_json_node_t *node = NULL;
8406 if (VAT_JSON_ARRAY != vam->json_tree.type) {
8407 ASSERT(VAT_JSON_NONE == vam->json_tree.type);
8408 vat_json_init_array(&vam->json_tree);
8410 node = vat_json_array_add(&vam->json_tree);
8412 vat_json_init_object(node);
8413 vat_json_object_add_uint(node, "bd_id", ntohl(mp->bd_id));
8414 vat_json_object_add_uint(node, "mac", clib_net_to_host_u64(mp->mac));
8415 vat_json_object_add_uint(node, "sw_if_index", ntohl(mp->sw_if_index));
8416 vat_json_object_add_uint(node, "static_mac", mp->static_mac);
8417 vat_json_object_add_uint(node, "filter_mac", mp->filter_mac);
8418 vat_json_object_add_uint(node, "bvi_mac", mp->bvi_mac);
8421 static int api_l2_fib_table_dump (vat_main_t * vam)
8423 unformat_input_t * i = vam->input;
8424 vl_api_l2_fib_table_dump_t *mp;
8429 /* Parse args required to build the message */
8430 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
8431 if (unformat (i, "bd_id %d", &bd_id))
8437 if (bd_id_set == 0) {
8438 errmsg ("missing bridge domain\n");
8442 fformat(vam->ofp, "BD-ID Mac Address sw-ndx Static Filter BVI\n");
8444 /* Get list of l2 fib entries */
8445 M(L2_FIB_TABLE_DUMP, l2_fib_table_dump);
8447 mp->bd_id = ntohl(bd_id);
8450 /* Use a control ping for synchronization */
8452 vl_api_control_ping_t * mp;
8453 M(CONTROL_PING, control_ping);
8461 api_interface_name_renumber (vat_main_t * vam)
8463 unformat_input_t * line_input = vam->input;
8464 vl_api_interface_name_renumber_t *mp;
8465 u32 sw_if_index = ~0;
8467 u32 new_show_dev_instance = ~0;
8469 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) {
8470 if (unformat (line_input, "%U", unformat_sw_if_index, vam,
8473 else if (unformat (line_input, "sw_if_index %d", &sw_if_index))
8475 else if (unformat (line_input, "new_show_dev_instance %d",
8476 &new_show_dev_instance))
8482 if (sw_if_index == ~0) {
8483 errmsg ("missing interface name or sw_if_index\n");
8487 if (new_show_dev_instance == ~0) {
8488 errmsg ("missing new_show_dev_instance\n");
8492 M(INTERFACE_NAME_RENUMBER, interface_name_renumber);
8494 mp->sw_if_index = ntohl (sw_if_index);
8495 mp->new_show_dev_instance = ntohl (new_show_dev_instance);
8501 api_want_ip4_arp_events (vat_main_t * vam)
8503 unformat_input_t * line_input = vam->input;
8504 vl_api_want_ip4_arp_events_t * mp;
8506 ip4_address_t address;
8507 int address_set = 0;
8508 u32 enable_disable = 1;
8510 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) {
8511 if (unformat (line_input, "address %U",
8512 unformat_ip4_address, &address))
8514 else if (unformat (line_input, "del"))
8520 if (address_set == 0) {
8521 errmsg ("missing addresses\n");
8525 M(WANT_IP4_ARP_EVENTS, want_ip4_arp_events);
8526 mp->enable_disable = enable_disable;
8528 mp->address = address.as_u32;
8533 static int api_input_acl_set_interface (vat_main_t * vam)
8535 unformat_input_t * i = vam->input;
8536 vl_api_input_acl_set_interface_t *mp;
8539 int sw_if_index_set;
8540 u32 ip4_table_index = ~0;
8541 u32 ip6_table_index = ~0;
8542 u32 l2_table_index = ~0;
8545 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
8546 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
8547 sw_if_index_set = 1;
8548 else if (unformat (i, "sw_if_index %d", &sw_if_index))
8549 sw_if_index_set = 1;
8550 else if (unformat (i, "del"))
8552 else if (unformat (i, "ip4-table %d", &ip4_table_index))
8554 else if (unformat (i, "ip6-table %d", &ip6_table_index))
8556 else if (unformat (i, "l2-table %d", &l2_table_index))
8559 clib_warning ("parse error '%U'", format_unformat_error, i);
8564 if (sw_if_index_set == 0) {
8565 errmsg ("missing interface name or sw_if_index\n");
8569 M(INPUT_ACL_SET_INTERFACE, input_acl_set_interface);
8571 mp->sw_if_index = ntohl(sw_if_index);
8572 mp->ip4_table_index = ntohl(ip4_table_index);
8573 mp->ip6_table_index = ntohl(ip6_table_index);
8574 mp->l2_table_index = ntohl(l2_table_index);
8575 mp->is_add = is_add;
8583 api_ip_address_dump (vat_main_t * vam)
8585 unformat_input_t * i = vam->input;
8586 vl_api_ip_address_dump_t * mp;
8587 u32 sw_if_index = ~0;
8588 u8 sw_if_index_set = 0;
8593 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
8594 if (unformat (i, "sw_if_index %d", &sw_if_index))
8595 sw_if_index_set = 1;
8596 else if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
8597 sw_if_index_set = 1;
8598 else if (unformat (i, "ipv4"))
8600 else if (unformat (i, "ipv6"))
8606 if (ipv4_set && ipv6_set) {
8607 errmsg ("ipv4 and ipv6 flags cannot be both set\n");
8611 if ((!ipv4_set) && (!ipv6_set)) {
8612 errmsg ("no ipv4 nor ipv6 flag set\n");
8616 if (sw_if_index_set == 0) {
8617 errmsg ("missing interface name or sw_if_index\n");
8621 vam->current_sw_if_index = sw_if_index;
8622 vam->is_ipv6 = ipv6_set;
8624 M(IP_ADDRESS_DUMP, ip_address_dump);
8625 mp->sw_if_index = ntohl(sw_if_index);
8626 mp->is_ipv6 = ipv6_set;
8629 /* Use a control ping for synchronization */
8631 vl_api_control_ping_t * mp;
8632 M(CONTROL_PING, control_ping);
8639 api_ip_dump (vat_main_t * vam)
8641 vl_api_ip_dump_t * mp;
8642 unformat_input_t * in = vam->input;
8649 while (unformat_check_input (in) != UNFORMAT_END_OF_INPUT) {
8650 if (unformat (in, "ipv4"))
8652 else if (unformat (in, "ipv6"))
8658 if (ipv4_set && ipv6_set) {
8659 errmsg ("ipv4 and ipv6 flags cannot be both set\n");
8663 if ((!ipv4_set) && (!ipv6_set)) {
8664 errmsg ("no ipv4 nor ipv6 flag set\n");
8669 vam->is_ipv6 = is_ipv6;
8672 for (i = 0; i < vec_len(vam->ip_details_by_sw_if_index[is_ipv6]); i++) {
8673 vec_free(vam->ip_details_by_sw_if_index[is_ipv6][i].addr);
8675 vec_free(vam->ip_details_by_sw_if_index[is_ipv6]);
8677 M(IP_DUMP, ip_dump);
8678 mp->is_ipv6 = ipv6_set;
8681 /* Use a control ping for synchronization */
8683 vl_api_control_ping_t * mp;
8684 M(CONTROL_PING, control_ping);
8691 api_ipsec_spd_add_del (vat_main_t * vam)
8694 unformat_input_t * i = vam->input;
8695 vl_api_ipsec_spd_add_del_t *mp;
8700 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
8701 if (unformat (i, "spd_id %d", &spd_id))
8703 else if (unformat (i, "del"))
8706 clib_warning ("parse error '%U'", format_unformat_error, i);
8711 errmsg ("spd_id must be set\n");
8715 M(IPSEC_SPD_ADD_DEL, ipsec_spd_add_del);
8717 mp->spd_id = ntohl(spd_id);
8718 mp->is_add = is_add;
8724 clib_warning ("unsupported (no dpdk)");
8730 api_ipsec_interface_add_del_spd (vat_main_t * vam)
8733 unformat_input_t * i = vam->input;
8734 vl_api_ipsec_interface_add_del_spd_t *mp;
8737 u8 sw_if_index_set = 0;
8738 u32 spd_id = (u32) ~0;
8741 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
8742 if (unformat (i, "del"))
8744 else if (unformat (i, "spd_id %d", &spd_id))
8746 else if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
8747 sw_if_index_set = 1;
8748 else if (unformat (i, "sw_if_index %d", &sw_if_index))
8749 sw_if_index_set = 1;
8751 clib_warning ("parse error '%U'", format_unformat_error, i);
8757 if (spd_id == (u32) ~0) {
8758 errmsg ("spd_id must be set\n");
8762 if (sw_if_index_set == 0) {
8763 errmsg ("missing interface name or sw_if_index\n");
8767 M(IPSEC_INTERFACE_ADD_DEL_SPD, ipsec_interface_add_del_spd);
8769 mp->spd_id = ntohl(spd_id);
8770 mp->sw_if_index = ntohl (sw_if_index);
8771 mp->is_add = is_add;
8777 clib_warning ("unsupported (no dpdk)");
8783 api_ipsec_spd_add_del_entry (vat_main_t * vam)
8786 unformat_input_t * i = vam->input;
8787 vl_api_ipsec_spd_add_del_entry_t *mp;
8789 u8 is_add = 1, is_outbound = 0, is_ipv6 = 0, is_ip_any = 1;
8790 u32 spd_id, sa_id, protocol = 0, policy = 0;
8792 u32 rport_start = 0, rport_stop = (u32) ~0;
8793 u32 lport_start = 0, lport_stop = (u32) ~0;
8794 ip4_address_t laddr4_start, laddr4_stop, raddr4_start, raddr4_stop;
8795 ip6_address_t laddr6_start, laddr6_stop, raddr6_start, raddr6_stop;
8797 laddr4_start.as_u32 = raddr4_start.as_u32 = 0;
8798 laddr4_stop.as_u32 = raddr4_stop.as_u32 = (u32) ~0;
8799 laddr6_start.as_u64[0] = raddr6_start.as_u64[0] = 0;
8800 laddr6_start.as_u64[1] = raddr6_start.as_u64[1] = 0;
8801 laddr6_stop.as_u64[0] = raddr6_stop.as_u64[0] = (u64) ~0;
8802 laddr6_stop.as_u64[1] = raddr6_stop.as_u64[1] = (u64) ~0;
8804 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
8805 if (unformat (i, "del"))
8807 if (unformat (i, "outbound"))
8809 if (unformat (i, "inbound"))
8811 else if (unformat (i, "spd_id %d", &spd_id))
8813 else if (unformat (i, "sa_id %d", &sa_id))
8815 else if (unformat (i, "priority %d", &priority))
8817 else if (unformat (i, "protocol %d", &protocol))
8819 else if (unformat (i, "lport_start %d", &lport_start))
8821 else if (unformat (i, "lport_stop %d", &lport_stop))
8823 else if (unformat (i, "rport_start %d", &rport_start))
8825 else if (unformat (i, "rport_stop %d", &rport_stop))
8827 else if (unformat (i, "laddr_start %U", unformat_ip4_address, &laddr4_start))
8832 else if (unformat (i, "laddr_stop %U", unformat_ip4_address, &laddr4_stop))
8837 else if (unformat (i, "raddr_start %U", unformat_ip4_address, &raddr4_start))
8842 else if (unformat (i, "raddr_stop %U", unformat_ip4_address, &raddr4_stop))
8847 else if (unformat (i, "laddr_start %U", unformat_ip6_address, &laddr6_start))
8852 else if (unformat (i, "laddr_stop %U", unformat_ip6_address, &laddr6_stop))
8857 else if (unformat (i, "raddr_start %U", unformat_ip6_address, &raddr6_start))
8862 else if (unformat (i, "raddr_stop %U", unformat_ip6_address, &raddr6_stop))
8867 else if (unformat (i, "action %U", unformat_ipsec_policy_action, &policy))
8869 if (policy == IPSEC_POLICY_ACTION_RESOLVE) {
8870 clib_warning ("unsupported action: 'resolve'");
8875 clib_warning ("parse error '%U'", format_unformat_error, i);
8881 M(IPSEC_SPD_ADD_DEL_ENTRY, ipsec_spd_add_del_entry);
8883 mp->spd_id = ntohl(spd_id);
8884 mp->priority = ntohl(priority);
8885 mp->is_outbound = is_outbound;
8887 mp->is_ipv6 = is_ipv6;
8888 if (is_ipv6 || is_ip_any) {
8889 clib_memcpy (mp->remote_address_start, &raddr6_start, sizeof(ip6_address_t));
8890 clib_memcpy (mp->remote_address_stop, &raddr6_stop, sizeof(ip6_address_t));
8891 clib_memcpy (mp->local_address_start, &laddr6_start, sizeof(ip6_address_t));
8892 clib_memcpy (mp->local_address_stop, &laddr6_stop, sizeof(ip6_address_t));
8894 clib_memcpy (mp->remote_address_start, &raddr4_start, sizeof(ip4_address_t));
8895 clib_memcpy (mp->remote_address_stop, &raddr4_stop, sizeof(ip4_address_t));
8896 clib_memcpy (mp->local_address_start, &laddr4_start, sizeof(ip4_address_t));
8897 clib_memcpy (mp->local_address_stop, &laddr4_stop, sizeof(ip4_address_t));
8899 mp->protocol = (u8) protocol;
8900 mp->local_port_start = ntohs((u16) lport_start);
8901 mp->local_port_stop = ntohs((u16) lport_stop);
8902 mp->remote_port_start = ntohs((u16) rport_start);
8903 mp->remote_port_stop = ntohs((u16) rport_stop);
8904 mp->policy = (u8) policy;
8905 mp->sa_id = ntohl(sa_id);
8906 mp->is_add = is_add;
8907 mp->is_ip_any = is_ip_any;
8912 clib_warning ("unsupported (no dpdk)");
8918 api_ipsec_sad_add_del_entry (vat_main_t * vam)
8921 unformat_input_t * i = vam->input;
8922 vl_api_ipsec_sad_add_del_entry_t *mp;
8928 u8 protocol = IPSEC_PROTOCOL_AH;
8929 u8 is_tunnel = 0, is_tunnel_ipv6 = 0;
8930 u32 crypto_alg = 0, integ_alg = 0;
8931 ip4_address_t tun_src4;
8932 ip4_address_t tun_dst4;
8933 ip6_address_t tun_src6;
8934 ip6_address_t tun_dst6;
8936 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
8937 if (unformat (i, "del"))
8939 else if (unformat (i, "sad_id %d", &sad_id))
8941 else if (unformat (i, "spi %d", &spi))
8943 else if (unformat (i, "esp"))
8944 protocol = IPSEC_PROTOCOL_ESP;
8945 else if (unformat (i, "tunnel_src %U", unformat_ip4_address, &tun_src4)) {
8949 else if (unformat (i, "tunnel_dst %U", unformat_ip4_address, &tun_dst4)) {
8953 else if (unformat (i, "tunnel_src %U", unformat_ip6_address, &tun_src6)) {
8957 else if (unformat (i, "tunnel_dst %U", unformat_ip6_address, &tun_dst6)) {
8961 else if (unformat (i, "crypto_alg %U", unformat_ipsec_crypto_alg, &crypto_alg)) {
8962 if (crypto_alg < IPSEC_CRYPTO_ALG_AES_CBC_128 ||
8963 crypto_alg > IPSEC_INTEG_ALG_SHA_512_256) {
8964 clib_warning ("unsupported crypto-alg: '%U'",
8965 format_ipsec_crypto_alg, crypto_alg);
8969 else if (unformat (i, "crypto_key %U", unformat_hex_string, &ck))
8971 else if (unformat (i, "integ_alg %U", unformat_ipsec_integ_alg, &integ_alg)) {
8972 if (integ_alg < IPSEC_INTEG_ALG_SHA1_96 ||
8973 integ_alg > IPSEC_INTEG_ALG_SHA_512_256) {
8974 clib_warning ("unsupported integ-alg: '%U'",
8975 format_ipsec_integ_alg, integ_alg);
8979 else if (unformat (i, "integ_key %U", unformat_hex_string, &ik))
8982 clib_warning ("parse error '%U'", format_unformat_error, i);
8988 M(IPSEC_SAD_ADD_DEL_ENTRY, ipsec_sad_add_del_entry);
8990 mp->sad_id = ntohl(sad_id);
8991 mp->is_add = is_add;
8992 mp->protocol = protocol;
8993 mp->spi = ntohl(spi);
8994 mp->is_tunnel = is_tunnel;
8995 mp->is_tunnel_ipv6 = is_tunnel_ipv6;
8996 mp->crypto_algorithm = crypto_alg;
8997 mp->integrity_algorithm = integ_alg;
8998 mp->crypto_key_length = vec_len(ck);
8999 mp->integrity_key_length = vec_len(ik);
9001 if (mp->crypto_key_length > sizeof(mp->crypto_key))
9002 mp->crypto_key_length = sizeof(mp->crypto_key);
9004 if (mp->integrity_key_length > sizeof(mp->integrity_key))
9005 mp->integrity_key_length = sizeof(mp->integrity_key);
9007 clib_memcpy (mp->crypto_key, ck, mp->crypto_key_length);
9008 clib_memcpy (mp->integrity_key, ik, mp->integrity_key_length);
9011 if (is_tunnel_ipv6) {
9012 clib_memcpy (mp->tunnel_src_address, &tun_src6, sizeof(ip6_address_t));
9013 clib_memcpy (mp->tunnel_dst_address, &tun_dst6, sizeof(ip6_address_t));
9015 clib_memcpy (mp->tunnel_src_address, &tun_src4, sizeof(ip4_address_t));
9016 clib_memcpy (mp->tunnel_dst_address, &tun_dst4, sizeof(ip4_address_t));
9024 clib_warning ("unsupported (no dpdk)");
9030 api_ipsec_sa_set_key (vat_main_t * vam)
9033 unformat_input_t * i = vam->input;
9034 vl_api_ipsec_sa_set_key_t *mp;
9039 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
9040 if (unformat (i, "sa_id %d", &sa_id))
9042 else if (unformat (i, "crypto_key %U", unformat_hex_string, &ck))
9044 else if (unformat (i, "integ_key %U", unformat_hex_string, &ik))
9047 clib_warning ("parse error '%U'", format_unformat_error, i);
9052 M(IPSEC_SA_SET_KEY, ipsec_set_sa_key);
9054 mp->sa_id = ntohl(sa_id);
9055 mp->crypto_key_length = vec_len(ck);
9056 mp->integrity_key_length = vec_len(ik);
9058 if (mp->crypto_key_length > sizeof(mp->crypto_key))
9059 mp->crypto_key_length = sizeof(mp->crypto_key);
9061 if (mp->integrity_key_length > sizeof(mp->integrity_key))
9062 mp->integrity_key_length = sizeof(mp->integrity_key);
9064 clib_memcpy (mp->crypto_key, ck, mp->crypto_key_length);
9065 clib_memcpy (mp->integrity_key, ik, mp->integrity_key_length);
9071 clib_warning ("unsupported (no dpdk)");
9077 api_ikev2_profile_add_del (vat_main_t * vam)
9080 unformat_input_t * i = vam->input;
9081 vl_api_ikev2_profile_add_del_t * mp;
9086 const char * valid_chars = "a-zA-Z0-9_";
9088 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
9089 if (unformat (i, "del"))
9091 else if (unformat (i, "name %U", unformat_token, valid_chars, &name))
9094 errmsg ("parse error '%U'", format_unformat_error, i);
9099 if (!vec_len (name)) {
9100 errmsg ("profile name must be specified");
9104 if (vec_len (name) > 64) {
9105 errmsg ("profile name too long");
9109 M(IKEV2_PROFILE_ADD_DEL, ikev2_profile_add_del);
9111 clib_memcpy(mp->name, name, vec_len (name));
9112 mp->is_add = is_add;
9119 clib_warning ("unsupported (no dpdk)");
9125 api_ikev2_profile_set_auth (vat_main_t * vam)
9128 unformat_input_t * i = vam->input;
9129 vl_api_ikev2_profile_set_auth_t * mp;
9133 u32 auth_method = 0;
9136 const char * valid_chars = "a-zA-Z0-9_";
9138 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
9139 if (unformat (i, "name %U", unformat_token, valid_chars, &name))
9141 else if (unformat (i, "auth_method %U",
9142 unformat_ikev2_auth_method, &auth_method))
9144 else if (unformat (i, "auth_data 0x%U", unformat_hex_string, &data))
9146 else if (unformat (i, "auth_data %v", &data))
9149 errmsg ("parse error '%U'", format_unformat_error, i);
9154 if (!vec_len (name)) {
9155 errmsg ("profile name must be specified");
9159 if (vec_len (name) > 64) {
9160 errmsg ("profile name too long");
9164 if (!vec_len(data)) {
9165 errmsg ("auth_data must be specified");
9170 errmsg ("auth_method must be specified");
9174 M(IKEV2_PROFILE_SET_AUTH, ikev2_profile_set_auth);
9176 mp->is_hex = is_hex;
9177 mp->auth_method = (u8) auth_method;
9178 mp->data_len = vec_len (data);
9179 clib_memcpy (mp->name, name, vec_len (name));
9180 clib_memcpy (mp->data, data, vec_len (data));
9188 clib_warning ("unsupported (no dpdk)");
9194 api_ikev2_profile_set_id (vat_main_t * vam)
9197 unformat_input_t * i = vam->input;
9198 vl_api_ikev2_profile_set_id_t * mp;
9206 const char * valid_chars = "a-zA-Z0-9_";
9208 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
9209 if (unformat (i, "name %U", unformat_token, valid_chars, &name))
9211 else if (unformat (i, "id_type %U",
9212 unformat_ikev2_id_type, &id_type))
9214 else if (unformat (i, "id_data %U", unformat_ip4_address, &ip4))
9216 data = vec_new(u8, 4);
9217 clib_memcpy(data, ip4.as_u8, 4);
9219 else if (unformat (i, "id_data 0x%U", unformat_hex_string, &data))
9221 else if (unformat (i, "id_data %v", &data))
9223 else if (unformat (i, "local"))
9225 else if (unformat (i, "remote"))
9228 errmsg ("parse error '%U'", format_unformat_error, i);
9233 if (!vec_len (name)) {
9234 errmsg ("profile name must be specified");
9238 if (vec_len (name) > 64) {
9239 errmsg ("profile name too long");
9243 if (!vec_len(data)) {
9244 errmsg ("id_data must be specified");
9249 errmsg ("id_type must be specified");
9253 M(IKEV2_PROFILE_SET_ID, ikev2_profile_set_id);
9255 mp->is_local = is_local;
9256 mp->id_type = (u8) id_type;
9257 mp->data_len = vec_len (data);
9258 clib_memcpy (mp->name, name, vec_len (name));
9259 clib_memcpy (mp->data, data, vec_len (data));
9267 clib_warning ("unsupported (no dpdk)");
9273 api_ikev2_profile_set_ts (vat_main_t * vam)
9276 unformat_input_t * i = vam->input;
9277 vl_api_ikev2_profile_set_ts_t * mp;
9281 u32 proto = 0, start_port = 0, end_port = (u32) ~0;
9282 ip4_address_t start_addr, end_addr;
9284 const char * valid_chars = "a-zA-Z0-9_";
9286 start_addr.as_u32 = 0;
9287 end_addr.as_u32 = (u32) ~0;
9289 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
9290 if (unformat (i, "name %U", unformat_token, valid_chars, &name))
9292 else if (unformat (i, "protocol %d", &proto))
9294 else if (unformat (i, "start_port %d", &start_port))
9296 else if (unformat (i, "end_port %d", &end_port))
9298 else if (unformat (i, "start_addr %U", unformat_ip4_address, &start_addr))
9300 else if (unformat (i, "end_addr %U", unformat_ip4_address, &end_addr))
9302 else if (unformat (i, "local"))
9304 else if (unformat (i, "remote"))
9307 errmsg ("parse error '%U'", format_unformat_error, i);
9312 if (!vec_len (name)) {
9313 errmsg ("profile name must be specified");
9317 if (vec_len (name) > 64) {
9318 errmsg ("profile name too long");
9322 M(IKEV2_PROFILE_SET_TS, ikev2_profile_set_ts);
9324 mp->is_local = is_local;
9325 mp->proto = (u8) proto;
9326 mp->start_port = (u16) start_port;
9327 mp->end_port = (u16) end_port;
9328 mp->start_addr = start_addr.as_u32;
9329 mp->end_addr = end_addr.as_u32;
9330 clib_memcpy (mp->name, name, vec_len (name));
9337 clib_warning ("unsupported (no dpdk)");
9343 api_ikev2_set_local_key (vat_main_t * vam)
9346 unformat_input_t * i = vam->input;
9347 vl_api_ikev2_set_local_key_t * mp;
9351 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
9352 if (unformat (i, "file %v", &file))
9355 errmsg ("parse error '%U'", format_unformat_error, i);
9360 if (!vec_len (file)) {
9361 errmsg ("RSA key file must be specified");
9365 if (vec_len (file) > 256) {
9366 errmsg ("file name too long");
9370 M(IKEV2_SET_LOCAL_KEY, ikev2_set_local_key);
9372 clib_memcpy (mp->key_file, file, vec_len (file));
9379 clib_warning ("unsupported (no dpdk)");
9387 static int api_map_add_domain (vat_main_t * vam)
9389 unformat_input_t *i = vam->input;
9390 vl_api_map_add_domain_t *mp;
9393 ip4_address_t ip4_prefix;
9394 ip6_address_t ip6_prefix;
9395 ip6_address_t ip6_src;
9397 u32 ip6_prefix_len, ip4_prefix_len, ea_bits_len, psid_offset,
9399 u8 is_translation = 0;
9401 u8 ip6_src_len = 128;
9403 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
9404 if (unformat (i, "ip4-pfx %U/%d", unformat_ip4_address,
9405 &ip4_prefix, &ip4_prefix_len))
9407 else if (unformat (i, "ip6-pfx %U/%d", unformat_ip6_address,
9408 &ip6_prefix, &ip6_prefix_len))
9410 else if (unformat (i, "ip6-src %U/%d", unformat_ip6_address, &ip6_src, &ip6_src_len))
9412 else if (unformat (i, "ip6-src %U", unformat_ip6_address, &ip6_src))
9414 else if (unformat (i, "ea-bits-len %d", &ea_bits_len))
9416 else if (unformat (i, "psid-offset %d", &psid_offset))
9418 else if (unformat (i, "psid-len %d", &psid_length))
9420 else if (unformat (i, "mtu %d", &mtu))
9422 else if (unformat (i, "map-t"))
9425 clib_warning ("parse error '%U'", format_unformat_error, i);
9430 if (num_m_args != 6) {
9431 errmsg("mandatory argument(s) missing\n");
9435 /* Construct the API message */
9436 M(MAP_ADD_DOMAIN, map_add_domain);
9438 clib_memcpy(mp->ip4_prefix, &ip4_prefix, sizeof(ip4_prefix));
9439 mp->ip4_prefix_len = ip4_prefix_len;
9441 clib_memcpy(mp->ip6_prefix, &ip6_prefix, sizeof(ip6_prefix));
9442 mp->ip6_prefix_len = ip6_prefix_len;
9444 clib_memcpy(mp->ip6_src, &ip6_src, sizeof(ip6_src));
9445 mp->ip6_src_prefix_len = ip6_src_len;
9447 mp->ea_bits_len = ea_bits_len;
9448 mp->psid_offset = psid_offset;
9449 mp->psid_length = psid_length;
9450 mp->is_translation = is_translation;
9451 mp->mtu = htons(mtu);
9456 /* Wait for a reply, return good/bad news */
9460 static int api_map_del_domain (vat_main_t * vam)
9462 unformat_input_t *i = vam->input;
9463 vl_api_map_del_domain_t *mp;
9469 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
9470 if (unformat (i, "index %d", &index))
9473 clib_warning ("parse error '%U'", format_unformat_error, i);
9478 if (num_m_args != 1) {
9479 errmsg("mandatory argument(s) missing\n");
9483 /* Construct the API message */
9484 M(MAP_DEL_DOMAIN, map_del_domain);
9486 mp->index = ntohl(index);
9491 /* Wait for a reply, return good/bad news */
9495 static int api_map_add_del_rule (vat_main_t * vam)
9497 unformat_input_t *i = vam->input;
9498 vl_api_map_add_del_rule_t *mp;
9501 ip6_address_t ip6_dst;
9502 u32 num_m_args = 0, index, psid;
9504 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
9505 if (unformat (i, "index %d", &index))
9507 else if (unformat (i, "psid %d", &psid))
9509 else if (unformat (i, "dst %U", unformat_ip6_address, &ip6_dst))
9511 else if (unformat (i, "del")) {
9514 clib_warning ("parse error '%U'", format_unformat_error, i);
9519 /* Construct the API message */
9520 M(MAP_ADD_DEL_RULE, map_add_del_rule);
9522 mp->index = ntohl(index);
9523 mp->is_add = is_add;
9524 clib_memcpy(mp->ip6_dst, &ip6_dst, sizeof(ip6_dst));
9525 mp->psid = ntohs(psid);
9530 /* Wait for a reply, return good/bad news */
9534 static int api_map_domain_dump (vat_main_t * vam)
9536 vl_api_map_domain_dump_t *mp;
9539 /* Construct the API message */
9540 M(MAP_DOMAIN_DUMP, map_domain_dump);
9545 /* Use a control ping for synchronization */
9547 vl_api_control_ping_t * mp;
9548 M(CONTROL_PING, control_ping);
9554 static int api_map_rule_dump (vat_main_t * vam)
9556 unformat_input_t *i = vam->input;
9557 vl_api_map_rule_dump_t *mp;
9559 u32 domain_index = ~0;
9561 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
9562 if (unformat (i, "index %u", &domain_index))
9568 if (domain_index == ~0) {
9569 clib_warning("parse error: domain index expected");
9573 /* Construct the API message */
9574 M(MAP_RULE_DUMP, map_rule_dump);
9576 mp->domain_index = htonl(domain_index);
9581 /* Use a control ping for synchronization */
9583 vl_api_control_ping_t * mp;
9584 M(CONTROL_PING, control_ping);
9590 static void vl_api_map_add_domain_reply_t_handler
9591 (vl_api_map_add_domain_reply_t * mp)
9593 vat_main_t * vam = &vat_main;
9594 i32 retval = ntohl(mp->retval);
9596 if (vam->async_mode) {
9597 vam->async_errors += (retval < 0);
9599 vam->retval = retval;
9600 vam->result_ready = 1;
9604 static void vl_api_map_add_domain_reply_t_handler_json
9605 (vl_api_map_add_domain_reply_t * mp)
9607 vat_main_t * vam = &vat_main;
9608 vat_json_node_t node;
9610 vat_json_init_object(&node);
9611 vat_json_object_add_int(&node, "retval", ntohl(mp->retval));
9612 vat_json_object_add_uint(&node, "index", ntohl(mp->index));
9614 vat_json_print(vam->ofp, &node);
9615 vat_json_free(&node);
9617 vam->retval = ntohl(mp->retval);
9618 vam->result_ready = 1;
9622 api_get_first_msg_id (vat_main_t * vam)
9624 vl_api_get_first_msg_id_t * mp;
9626 unformat_input_t * i = vam->input;
9630 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
9631 if (unformat (i, "client %s", &name))
9637 if (name_set == 0) {
9638 errmsg ("missing client name\n");
9643 if (vec_len (name) > 63) {
9644 errmsg ("client name too long\n");
9648 M(GET_FIRST_MSG_ID, get_first_msg_id);
9649 clib_memcpy (mp->name, name, vec_len(name));
9655 static int api_cop_interface_enable_disable (vat_main_t * vam)
9657 unformat_input_t * line_input = vam->input;
9658 vl_api_cop_interface_enable_disable_t * mp;
9660 u32 sw_if_index = ~0;
9661 u8 enable_disable = 1;
9663 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) {
9664 if (unformat (line_input, "disable"))
9666 if (unformat (line_input, "enable"))
9668 else if (unformat (line_input, "%U", unformat_sw_if_index,
9671 else if (unformat (line_input, "sw_if_index %d", &sw_if_index))
9677 if (sw_if_index == ~0) {
9678 errmsg ("missing interface name or sw_if_index\n");
9682 /* Construct the API message */
9683 M(COP_INTERFACE_ENABLE_DISABLE, cop_interface_enable_disable);
9684 mp->sw_if_index = ntohl(sw_if_index);
9685 mp->enable_disable = enable_disable;
9689 /* Wait for the reply */
9693 static int api_cop_whitelist_enable_disable (vat_main_t * vam)
9695 unformat_input_t * line_input = vam->input;
9696 vl_api_cop_whitelist_enable_disable_t * mp;
9698 u32 sw_if_index = ~0;
9699 u8 ip4=0, ip6=0, default_cop=0;
9702 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) {
9703 if (unformat (line_input, "ip4"))
9705 else if (unformat (line_input, "ip6"))
9707 else if (unformat (line_input, "default"))
9709 else if (unformat (line_input, "%U", unformat_sw_if_index,
9712 else if (unformat (line_input, "sw_if_index %d", &sw_if_index))
9714 else if (unformat (line_input, "fib-id %d", &fib_id))
9720 if (sw_if_index == ~0) {
9721 errmsg ("missing interface name or sw_if_index\n");
9725 /* Construct the API message */
9726 M(COP_WHITELIST_ENABLE_DISABLE, cop_whitelist_enable_disable);
9727 mp->sw_if_index = ntohl(sw_if_index);
9728 mp->fib_id = ntohl(fib_id);
9731 mp->default_cop = default_cop;
9735 /* Wait for the reply */
9739 static int api_get_node_graph (vat_main_t * vam)
9741 vl_api_get_node_graph_t * mp;
9744 M(GET_NODE_GRAPH, get_node_graph);
9748 /* Wait for the reply */
9753 api_lisp_add_del_locator_set(vat_main_t * vam)
9755 unformat_input_t * input = vam->input;
9756 vl_api_lisp_add_del_locator_set_t *mp;
9759 u8 *locator_set_name = NULL;
9760 u8 locator_set_name_set = 0;
9762 /* Parse args required to build the message */
9763 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) {
9764 if (unformat(input, "del")) {
9766 } else if (unformat(input, "locator-set %s", &locator_set_name)) {
9767 locator_set_name_set = 1;
9772 if (locator_set_name_set == 0) {
9773 errmsg ("missing locator-set name");
9777 if (vec_len(locator_set_name) > 64) {
9778 errmsg ("locator-set name too long\n");
9779 vec_free(locator_set_name);
9782 vec_add1(locator_set_name, 0);
9784 /* Construct the API message */
9785 M(LISP_ADD_DEL_LOCATOR_SET, lisp_add_del_locator_set);
9787 mp->is_add = is_add;
9788 clib_memcpy(mp->locator_set_name, locator_set_name,
9789 vec_len(locator_set_name));
9790 vec_free(locator_set_name);
9795 /* Wait for a reply... */
9803 api_lisp_add_del_locator(vat_main_t * vam)
9805 unformat_input_t * input = vam->input;
9806 vl_api_lisp_add_del_locator_t *mp;
9808 u32 tmp_if_index = ~0;
9809 u32 sw_if_index = ~0;
9810 u8 sw_if_index_set = 0;
9811 u8 sw_if_index_if_name_set = 0;
9813 u8 priority_set = 0;
9817 u8 *locator_set_name = NULL;
9818 u8 locator_set_name_set = 0;
9820 /* Parse args required to build the message */
9821 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) {
9822 if (unformat(input, "del")) {
9824 } else if (unformat(input, "locator-set %s", &locator_set_name)) {
9825 locator_set_name_set = 1;
9826 } else if (unformat(input, "iface %U", unformat_sw_if_index, vam,
9828 sw_if_index_if_name_set = 1;
9829 sw_if_index = tmp_if_index;
9830 } else if (unformat(input,"sw_if_index %d", &tmp_if_index)) {
9831 sw_if_index_set = 1;
9832 sw_if_index = tmp_if_index;
9833 } else if (unformat(input, "p %d", &priority)) {
9835 } else if (unformat(input, "w %d", &weight)) {
9841 if (locator_set_name_set == 0) {
9842 errmsg ("missing locator-set name");
9846 if (sw_if_index_set == 0 && sw_if_index_if_name_set == 0) {
9847 errmsg ("missing sw_if_index");
9848 vec_free(locator_set_name);
9852 if (sw_if_index_set != 0 && sw_if_index_if_name_set != 0) {
9853 errmsg ("cannot use both params interface name and sw_if_index");
9854 vec_free(locator_set_name);
9858 if (priority_set == 0) {
9859 errmsg ("missing locator-set priority\n");
9860 vec_free(locator_set_name);
9864 if (weight_set == 0) {
9865 errmsg ("missing locator-set weight\n");
9866 vec_free(locator_set_name);
9870 if (vec_len(locator_set_name) > 64) {
9871 errmsg ("locator-set name too long\n");
9872 vec_free(locator_set_name);
9875 vec_add1(locator_set_name, 0);
9877 /* Construct the API message */
9878 M(LISP_ADD_DEL_LOCATOR, lisp_add_del_locator);
9880 mp->is_add = is_add;
9881 mp->sw_if_index = ntohl(sw_if_index);
9882 mp->priority = priority;
9883 mp->weight = weight;
9884 clib_memcpy(mp->locator_set_name, locator_set_name,
9885 vec_len(locator_set_name));
9886 vec_free(locator_set_name);
9891 /* Wait for a reply... */
9899 api_lisp_add_del_local_eid(vat_main_t * vam)
9901 unformat_input_t * input = vam->input;
9902 vl_api_lisp_add_del_local_eid_t *mp;
9907 ip4_address_t eidv4;
9908 ip6_address_t eidv6;
9909 u8 tmp_eid_lenght = ~0;
9911 u8 *locator_set_name = NULL;
9912 u8 locator_set_name_set = 0;
9914 /* Parse args required to build the message */
9915 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) {
9916 if (unformat(input, "del")) {
9918 } else if (unformat(input, "eid %U/%d", unformat_ip4_address,
9919 &eidv4, &tmp_eid_lenght)) {
9920 eid_lenght = tmp_eid_lenght;
9922 } else if (unformat(input, "eid %U/%d", unformat_ip6_address,
9923 &eidv6, &tmp_eid_lenght)) {
9924 eid_lenght = tmp_eid_lenght;
9926 } else if (unformat(input, "locator-set %s", &locator_set_name)) {
9927 locator_set_name_set = 1;
9932 if (locator_set_name_set == 0) {
9933 errmsg ("missing locator-set name\n");
9937 if (vec_len(locator_set_name) > 64) {
9938 errmsg ("locator-set name too long\n");
9939 vec_free(locator_set_name);
9942 vec_add1(locator_set_name, 0);
9944 if (eidv4_set && eidv6_set) {
9945 errmsg ("both eid v4 and v6 addresses set\n");
9946 vec_free(locator_set_name);
9950 if (!eidv4_set && !eidv6_set) {
9951 errmsg ("eid addresses not set\n");
9952 vec_free(locator_set_name);
9956 if (eidv4_set && eid_lenght > 32) {
9957 errmsg ("eid prefix to big\n");
9958 vec_free(locator_set_name);
9962 if (eidv6_set && eid_lenght > 128) {
9963 errmsg ("eid prefix to big\n");
9964 vec_free(locator_set_name);
9968 /* Construct the API message */
9969 M(LISP_ADD_DEL_LOCAL_EID, lisp_add_del_local_eid);
9971 mp->is_add = is_add;
9974 clib_memcpy(mp->ip_address, &eidv6, sizeof(eidv6));
9977 clib_memcpy(mp->ip_address, &eidv4, sizeof(eidv4));
9979 mp->prefix_len = eid_lenght;
9980 clib_memcpy(mp->locator_set_name, locator_set_name,
9981 vec_len(locator_set_name));
9982 vec_free(locator_set_name);
9987 /* Wait for a reply... */
9995 api_lisp_gpe_add_del_fwd_entry(vat_main_t * vam)
9997 unformat_input_t * input = vam->input;
9998 vl_api_lisp_gpe_add_del_fwd_entry_t *mp;
10001 u8 eidv4_set = 0, slocv4_set = 0, dlocv4_set = 0;
10002 u8 eidv6_set = 0, slocv6_set = 0, dlocv6_set = 0;
10003 ip4_address_t eidv4, slocv4, dlocv4;
10004 ip6_address_t eidv6, slocv6, dlocv6;
10005 u8 tmp_eid_lenght = ~0;
10006 u8 eid_lenght = ~0;
10008 /* Parse args required to build the message */
10009 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) {
10010 if (unformat(input, "del")) {
10012 } else if (unformat(input, "eid %U/%d", unformat_ip4_address,
10013 &eidv4, &tmp_eid_lenght)) {
10014 eid_lenght = tmp_eid_lenght;
10016 } else if (unformat(input, "eid %U/%d", unformat_ip6_address,
10017 &eidv6, &tmp_eid_lenght)) {
10018 eid_lenght = tmp_eid_lenght;
10020 } else if (unformat(input, "sloc %U", unformat_ip4_address, &slocv4)) {
10022 } else if (unformat(input, "sloc %U", unformat_ip6_address, &slocv6)) {
10024 } else if (unformat(input, "dloc %U", unformat_ip4_address, &dlocv4)) {
10026 } else if (unformat(input, "dloc %U", unformat_ip6_address, &dlocv6)) {
10032 if (eidv4_set && eidv6_set) {
10033 errmsg ("both eid v4 and v6 addresses set\n");
10037 if (!eidv4_set && !eidv6_set) {
10038 errmsg ("eid addresses not set\n");
10042 if (slocv4_set && slocv6_set) {
10043 errmsg ("both source v4 and v6 addresses set\n");
10047 if (!slocv4_set && !slocv6_set) {
10048 errmsg ("source addresses not set\n");
10052 if (dlocv4_set && dlocv6_set) {
10053 errmsg ("both destination v4 and v6 addresses set\n");
10057 if (dlocv4_set && dlocv6_set) {
10058 errmsg ("destination addresses not set\n");
10062 if (!(slocv4_set == dlocv4_set && slocv6_set == dlocv6_set)) {
10063 errmsg ("mixing type of source and destination address\n");
10067 /* Construct the API message */
10068 M(LISP_GPE_ADD_DEL_FWD_ENTRY, lisp_gpe_add_del_fwd_entry);
10070 mp->is_add = is_add;
10072 mp->eid_is_ipv6 = 1;
10073 clib_memcpy(mp->eid_ip_address, &eidv6, sizeof(eidv6));
10075 mp->eid_is_ipv6 = 0;
10076 clib_memcpy(mp->eid_ip_address, &eidv4, sizeof(eidv4));
10078 mp->eid_prefix_len = eid_lenght;
10080 mp->address_is_ipv6 = 1;
10081 clib_memcpy(mp->source_ip_address, &slocv6, sizeof(slocv6));
10082 clib_memcpy(mp->destination_ip_address, &dlocv6, sizeof(dlocv6));
10084 mp->address_is_ipv6 = 0;
10085 clib_memcpy(mp->source_ip_address, &slocv4, sizeof(slocv4));
10086 clib_memcpy(mp->destination_ip_address, &dlocv4, sizeof(dlocv4));
10092 /* Wait for a reply... */
10100 api_lisp_add_del_map_resolver(vat_main_t * vam)
10102 unformat_input_t * input = vam->input;
10103 vl_api_lisp_add_del_map_resolver_t *mp;
10108 ip4_address_t ipv4;
10109 ip6_address_t ipv6;
10111 /* Parse args required to build the message */
10112 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) {
10113 if (unformat(input, "del")) {
10115 } else if (unformat(input, "%U", unformat_ip4_address, &ipv4)) {
10117 } else if (unformat(input, "%U", unformat_ip6_address, &ipv6)) {
10123 if (ipv4_set && ipv6_set) {
10124 errmsg ("both eid v4 and v6 addresses set\n");
10128 if (!ipv4_set && !ipv6_set) {
10129 errmsg ("eid addresses not set\n");
10133 /* Construct the API message */
10134 M(LISP_ADD_DEL_MAP_RESOLVER, lisp_add_del_map_resolver);
10136 mp->is_add = is_add;
10139 clib_memcpy(mp->ip_address, &ipv6, sizeof(ipv6));
10142 clib_memcpy(mp->ip_address, &ipv4, sizeof(ipv4));
10148 /* Wait for a reply... */
10156 api_lisp_gpe_enable_disable (vat_main_t * vam)
10158 unformat_input_t * input = vam->input;
10159 vl_api_lisp_gpe_enable_disable_t *mp;
10164 /* Parse args required to build the message */
10165 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) {
10166 if (unformat(input, "enable")) {
10169 } else if (unformat(input, "disable")) {
10177 errmsg("Value not set\n");
10181 /* Construct the API message */
10182 M(LISP_GPE_ENABLE_DISABLE, lisp_gpe_enable_disable);
10189 /* Wait for a reply... */
10197 api_lisp_enable_disable (vat_main_t * vam)
10199 unformat_input_t * input = vam->input;
10200 vl_api_lisp_enable_disable_t *mp;
10205 /* Parse args required to build the message */
10206 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
10208 if (unformat (input, "enable"))
10213 else if (unformat (input, "disable"))
10223 errmsg ("Value not set\n");
10227 /* Construct the API message */
10228 M(LISP_ENABLE_DISABLE, lisp_enable_disable);
10235 /* Wait for a reply... */
10242 /** Used for transferring locators via VPP API */
10243 typedef CLIB_PACKED(struct
10245 u8 is_ip4; /**< is locator an IPv4 address? */
10246 u8 addr[16]; /**< IPv4/IPv6 address */
10250 * Enable/disable LISP proxy ITR.
10252 * @param vam vpp API test context
10253 * @return return code
10256 api_lisp_pitr_set_locator_set (vat_main_t * vam)
10259 u8 ls_name_set = 0;
10260 unformat_input_t * input = vam->input;
10261 vl_api_lisp_pitr_set_locator_set_t * mp;
10265 /* Parse args required to build the message */
10266 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
10268 if (unformat (input, "del"))
10270 else if (unformat (input, "locator-set %s", &ls_name))
10274 errmsg ("parse error '%U'", format_unformat_error, input);
10281 errmsg ("locator-set name not set!");
10285 M(LISP_PITR_SET_LOCATOR_SET, lisp_pitr_set_locator_set);
10287 mp->is_add = is_add;
10288 clib_memcpy (mp->ls_name, ls_name, vec_len (ls_name));
10289 vec_free (ls_name);
10294 /* wait for reply */
10302 * Add/del remote mapping from LISP control plane and updates
10303 * forwarding entries in data-plane accordingly.
10305 * @param vam vpp API test context
10306 * @return return code
10309 api_lisp_add_del_remote_mapping (vat_main_t * vam)
10311 unformat_input_t * input = vam->input;
10312 vl_api_lisp_add_del_remote_mapping_t *mp;
10315 u8 seid_set = 0, deid_set = 0;
10316 ip4_address_t seid4, deid4, rloc4;
10317 ip6_address_t seid6, deid6, rloc6;
10318 u32 seid_len = 0, deid_len = 0, len;
10319 u8 deid_is_ip4 = 0, seid_is_ip4 = 0;
10320 u8 is_add = 1, del_all = 0;
10322 rloc_t * rlocs = 0, rloc;
10324 /* Parse args required to build the message */
10325 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) {
10326 if (unformat(input, "del-all")) {
10328 } else if (unformat(input, "del")) {
10330 } else if (unformat(input, "add")) {
10332 } else if (unformat(input, "deid %U/%d", unformat_ip4_address,
10337 } else if (unformat(input, "deid %U/%d", unformat_ip6_address,
10342 } else if (unformat(input, "seid %U/%d", unformat_ip4_address,
10347 } else if (unformat(input, "seid %U/%d", unformat_ip6_address,
10352 } else if (unformat(input, "vni %d", &vni)) {
10354 } else if (unformat(input, "rloc %U", unformat_ip4_address, &rloc4)) {
10356 clib_memcpy (&rloc.addr, &rloc4, sizeof (rloc4));
10357 vec_add1 (rlocs, rloc);
10358 } else if (unformat(input, "rloc %U", unformat_ip6_address, &rloc6)) {
10360 clib_memcpy (&rloc.addr, &rloc6, sizeof (rloc6));
10361 vec_add1 (rlocs, rloc);
10362 } else if (unformat(input, "action %d", &action)) {
10365 clib_warning ("parse error '%U'", format_unformat_error, input);
10370 if (!seid_set || !deid_set) {
10371 errmsg ("missing params!");
10375 if (seid_is_ip4 != deid_is_ip4) {
10376 errmsg ("source and destination EIDs are not in " "same IP family!");
10380 if (is_add && (~0 == action)
10381 && 0 == vec_len (rlocs)) {
10382 errmsg ("no action set for negative map-reply!");
10386 M(LISP_ADD_DEL_REMOTE_MAPPING, lisp_add_del_remote_mapping);
10387 mp->is_add = is_add;
10388 mp->vni = htonl (vni);
10389 mp->seid_len = seid_len;
10390 mp->action = (u8) action;
10391 mp->deid_len = deid_len;
10392 mp->del_all = del_all;
10394 mp->eid_is_ip4 = 1;
10395 clib_memcpy (mp->seid, &seid4, sizeof (seid4));
10397 mp->eid_is_ip4 = 0;
10398 clib_memcpy (mp->seid, &seid6, sizeof (seid6));
10402 mp->eid_is_ip4 = 1;
10403 clib_memcpy (mp->deid, &deid4, sizeof (deid4));
10405 mp->eid_is_ip4 = 0;
10406 clib_memcpy (mp->deid, &deid6, sizeof (deid6));
10409 mp->rloc_num = vec_len (rlocs);
10410 clib_memcpy (mp->rlocs, rlocs, (sizeof (rloc_t) * vec_len (rlocs)));
10416 /* Wait for a reply... */
10424 api_lisp_gpe_add_del_iface(vat_main_t * vam)
10426 unformat_input_t * input = vam->input;
10427 vl_api_lisp_gpe_add_del_iface_t *mp;
10433 /* Parse args required to build the message */
10434 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) {
10435 if (unformat(input, "up")) {
10438 } else if (unformat(input, "down")) {
10441 } else if (unformat(input, "table_id %d", &table_id)) {
10443 } else if (unformat(input, "vni %d", &vni)) {
10450 errmsg("Value not set\n");
10454 /* Construct the API message */
10455 M(LISP_GPE_ADD_DEL_IFACE, lisp_gpe_add_del_iface);
10457 mp->is_add = is_add;
10458 mp->table_id = table_id;
10464 /* Wait for a reply... */
10472 * Add/del map request itr rlocs from LISP control plane and updates
10474 * @param vam vpp API test context
10475 * @return return code
10478 api_lisp_add_del_map_request_itr_rlocs(vat_main_t * vam)
10480 unformat_input_t * input = vam->input;
10481 vl_api_lisp_add_del_map_request_itr_rlocs_t *mp;
10483 u8 *locator_set_name = 0;
10484 u8 locator_set_name_set = 0;
10487 /* Parse args required to build the message */
10488 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) {
10489 if (unformat(input, "del")) {
10491 } else if (unformat(input, "%_%v%_", &locator_set_name)) {
10492 locator_set_name_set = 1;
10494 clib_warning ("parse error '%U'", format_unformat_error, input);
10499 if (is_add && !locator_set_name_set) {
10500 errmsg ("itr-rloc is not set!");
10504 if (is_add && vec_len(locator_set_name) > 64) {
10505 errmsg ("itr-rloc locator-set name too long\n");
10506 vec_free(locator_set_name);
10510 M(LISP_ADD_DEL_MAP_REQUEST_ITR_RLOCS, lisp_add_del_map_request_itr_rlocs);
10511 mp->is_add = is_add;
10513 clib_memcpy (mp->locator_set_name , locator_set_name,
10514 vec_len(locator_set_name));
10516 memset(mp->locator_set_name, 0, sizeof(mp->locator_set_name));
10518 vec_free (locator_set_name);
10523 /* Wait for a reply... */
10531 api_lisp_locator_set_dump(vat_main_t *vam)
10533 vl_api_lisp_locator_set_dump_t *mp;
10536 if (!vam->json_output) {
10537 fformat(vam->ofp, "%=20s%=16s%=16s%=16s\n",
10538 "Locator-set", "Locator", "Priority", "Weight");
10541 M(LISP_LOCATOR_SET_DUMP, lisp_locator_set_dump);
10545 /* Use a control ping for synchronization */
10547 vl_api_control_ping_t * mp;
10548 M(CONTROL_PING, control_ping);
10551 /* Wait for a reply... */
10559 api_lisp_local_eid_table_dump(vat_main_t *vam)
10561 vl_api_lisp_local_eid_table_dump_t *mp;
10564 if (!vam->json_output) {
10565 fformat(vam->ofp, "%=20s%=30s\n",
10566 "Locator-set", "Eid");
10569 M(LISP_LOCAL_EID_TABLE_DUMP, lisp_local_eid_table_dump);
10573 /* Use a control ping for synchronization */
10575 vl_api_control_ping_t * mp;
10576 M(CONTROL_PING, control_ping);
10579 /* Wait for a reply... */
10587 api_lisp_gpe_tunnel_dump(vat_main_t *vam)
10589 vl_api_lisp_gpe_tunnel_dump_t *mp;
10592 if (!vam->json_output) {
10593 fformat(vam->ofp, "%=20s%=30s%=16s%=16s%=16s%=16s"
10594 "%=16s%=16s%=16s%=16s%=16s\n",
10595 "Tunel", "Source", "Destination", "Fib encap", "Fib decap",
10596 "Decap next", "Lisp version", "Flags", "Next protocol",
10597 "ver_res", "res", "iid");
10600 M(LISP_GPE_TUNNEL_DUMP, lisp_gpe_tunnel_dump);
10604 /* Use a control ping for synchronization */
10606 vl_api_control_ping_t * mp;
10607 M(CONTROL_PING, control_ping);
10610 /* Wait for a reply... */
10618 api_lisp_map_resolver_dump(vat_main_t *vam)
10620 vl_api_lisp_map_resolver_dump_t *mp;
10623 if (!vam->json_output) {
10624 fformat(vam->ofp, "%=20s\n",
10628 M(LISP_MAP_RESOLVER_DUMP, lisp_map_resolver_dump);
10632 /* Use a control ping for synchronization */
10634 vl_api_control_ping_t * mp;
10635 M(CONTROL_PING, control_ping);
10638 /* Wait for a reply... */
10646 api_lisp_enable_disable_status_dump(vat_main_t *vam)
10648 vl_api_lisp_enable_disable_status_dump_t *mp;
10651 if (!vam->json_output) {
10652 fformat(vam->ofp, "%=20s\n",
10656 M(LISP_ENABLE_DISABLE_STATUS_DUMP,
10657 lisp_enable_disable_status_dump);
10661 /* Use a control ping for synchronization */
10663 vl_api_control_ping_t * mp;
10664 M(CONTROL_PING, control_ping);
10667 /* Wait for a reply... */
10675 api_lisp_get_map_request_itr_rlocs(vat_main_t *vam)
10677 vl_api_lisp_get_map_request_itr_rlocs_t *mp;
10680 if (!vam->json_output) {
10681 fformat(vam->ofp, "%=20s\n",
10685 M(LISP_GET_MAP_REQUEST_ITR_RLOCS, lisp_get_map_request_itr_rlocs);
10688 /* Wait for a reply... */
10696 api_af_packet_create (vat_main_t * vam)
10698 unformat_input_t * i = vam->input;
10699 vl_api_af_packet_create_t * mp;
10701 u8 * host_if_name = 0;
10703 u8 random_hw_addr = 1;
10705 memset (hw_addr, 0, sizeof (hw_addr));
10707 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
10708 if (unformat (i, "name %s", &host_if_name))
10709 vec_add1 (host_if_name, 0);
10710 else if (unformat (i, "hw_addr %U", unformat_ethernet_address, hw_addr))
10711 random_hw_addr = 0;
10716 if (!vec_len (host_if_name)) {
10717 errmsg ("host-interface name must be specified");
10721 if (vec_len (host_if_name) > 64) {
10722 errmsg ("host-interface name too long");
10726 M(AF_PACKET_CREATE, af_packet_create);
10728 clib_memcpy (mp->host_if_name, host_if_name, vec_len (host_if_name));
10729 clib_memcpy (mp->hw_addr, hw_addr, 6);
10730 mp->use_random_hw_addr = random_hw_addr;
10731 vec_free (host_if_name);
10733 S; W2(fprintf(vam->ofp," new sw_if_index = %d ", vam->sw_if_index));
10739 api_af_packet_delete (vat_main_t * vam)
10741 unformat_input_t * i = vam->input;
10742 vl_api_af_packet_delete_t * mp;
10744 u8 * host_if_name = 0;
10746 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
10747 if (unformat (i, "name %s", &host_if_name))
10748 vec_add1 (host_if_name, 0);
10753 if (!vec_len (host_if_name)) {
10754 errmsg ("host-interface name must be specified");
10758 if (vec_len (host_if_name) > 64) {
10759 errmsg ("host-interface name too long");
10763 M(AF_PACKET_DELETE, af_packet_delete);
10765 clib_memcpy (mp->host_if_name, host_if_name, vec_len (host_if_name));
10766 vec_free (host_if_name);
10774 api_policer_add_del (vat_main_t * vam)
10776 unformat_input_t * i = vam->input;
10777 vl_api_policer_add_del_t * mp;
10789 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
10790 if (unformat (i, "del"))
10792 else if (unformat (i, "name %s", &name))
10793 vec_add1 (name, 0);
10794 else if (unformat (i, "cir %u", &cir))
10796 else if (unformat (i, "eir %u", &eir))
10798 else if (unformat (i, "cb %u", &cb))
10800 else if (unformat (i, "eb %u", &eb))
10802 else if (unformat (i, "rate_type %U", unformat_policer_rate_type,
10805 else if (unformat (i, "round_type %U", unformat_policer_round_type,
10808 else if (unformat (i, "type %U", unformat_policer_type, &type))
10814 if (!vec_len (name)) {
10815 errmsg ("policer name must be specified");
10819 if (vec_len (name) > 64) {
10820 errmsg ("policer name too long");
10824 M(POLICER_ADD_DEL, policer_add_del);
10826 clib_memcpy (mp->name, name, vec_len (name));
10828 mp->is_add = is_add;
10833 mp->rate_type = rate_type;
10834 mp->round_type = round_type;
10843 api_policer_dump(vat_main_t *vam)
10845 unformat_input_t * i = vam->input;
10846 vl_api_policer_dump_t *mp;
10848 u8 *match_name = 0;
10849 u8 match_name_valid = 0;
10851 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
10852 if (unformat (i, "name %s", &match_name)) {
10853 vec_add1 (match_name, 0);
10854 match_name_valid = 1;
10859 M(POLICER_DUMP, policer_dump);
10860 mp->match_name_valid = match_name_valid;
10861 clib_memcpy (mp->match_name, match_name, vec_len (match_name));
10862 vec_free (match_name);
10866 /* Use a control ping for synchronization */
10868 vl_api_control_ping_t * mp;
10869 M(CONTROL_PING, control_ping);
10872 /* Wait for a reply... */
10880 api_netmap_create (vat_main_t * vam)
10882 unformat_input_t * i = vam->input;
10883 vl_api_netmap_create_t * mp;
10887 u8 random_hw_addr = 1;
10891 memset (hw_addr, 0, sizeof (hw_addr));
10893 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
10894 if (unformat (i, "name %s", &if_name))
10895 vec_add1 (if_name, 0);
10896 else if (unformat (i, "hw_addr %U", unformat_ethernet_address, hw_addr))
10897 random_hw_addr = 0;
10898 else if (unformat (i, "pipe"))
10900 else if (unformat (i, "master"))
10902 else if (unformat (i, "slave"))
10908 if (!vec_len (if_name)) {
10909 errmsg ("interface name must be specified");
10913 if (vec_len (if_name) > 64) {
10914 errmsg ("interface name too long");
10918 M(NETMAP_CREATE, netmap_create);
10920 clib_memcpy (mp->netmap_if_name, if_name, vec_len (if_name));
10921 clib_memcpy (mp->hw_addr, hw_addr, 6);
10922 mp->use_random_hw_addr = random_hw_addr;
10923 mp->is_pipe = is_pipe;
10924 mp->is_master = is_master;
10925 vec_free (if_name);
10933 api_netmap_delete (vat_main_t * vam)
10935 unformat_input_t * i = vam->input;
10936 vl_api_netmap_delete_t * mp;
10940 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
10941 if (unformat (i, "name %s", &if_name))
10942 vec_add1 (if_name, 0);
10947 if (!vec_len (if_name)) {
10948 errmsg ("interface name must be specified");
10952 if (vec_len (if_name) > 64) {
10953 errmsg ("interface name too long");
10957 M(NETMAP_DELETE, netmap_delete);
10959 clib_memcpy (mp->netmap_if_name, if_name, vec_len (if_name));
10960 vec_free (if_name);
10967 static int q_or_quit (vat_main_t * vam)
10969 longjmp (vam->jump_buf, 1);
10970 return 0; /* not so much */
10972 static int q (vat_main_t * vam) {return q_or_quit (vam);}
10973 static int quit (vat_main_t * vam) {return q_or_quit (vam);}
10975 static int comment (vat_main_t * vam)
10980 static int cmd_cmp (void * a1, void * a2)
10985 return strcmp ((char *)(c1[0]), (char *)(c2[0]));
10988 static int help (vat_main_t * vam)
10993 unformat_input_t * i = vam->input;
10996 if (unformat (i, "%s", &name)) {
11001 hs = hash_get_mem (vam->help_by_name, name);
11003 fformat (vam->ofp, "usage: %s %s\n", name, hs[0]);
11005 fformat (vam->ofp, "No such msg / command '%s'\n", name);
11010 fformat(vam->ofp, "Help is available for the following:\n");
11012 hash_foreach_pair (p, vam->function_by_name,
11014 vec_add1 (cmds, (u8 *)(p->key));
11017 vec_sort_with_function (cmds, cmd_cmp);
11019 for (j = 0; j < vec_len(cmds); j++)
11020 fformat (vam->ofp, "%s\n", cmds[j]);
11026 static int set (vat_main_t * vam)
11028 u8 * name = 0, * value = 0;
11029 unformat_input_t * i = vam->input;
11031 if (unformat (i, "%s", &name)) {
11032 /* The input buffer is a vector, not a string. */
11033 value = vec_dup (i->buffer);
11034 vec_delete (value, i->index, 0);
11035 /* Almost certainly has a trailing newline */
11036 if (value[vec_len(value)-1] == '\n')
11037 value[vec_len(value)-1] = 0;
11038 /* Make sure it's a proper string, one way or the other */
11039 vec_add1 (value, 0);
11040 (void) clib_macro_set_value (&vam->macro_main,
11041 (char *)name, (char *)value);
11044 errmsg ("usage: set <name> <value>\n");
11051 static int unset (vat_main_t * vam)
11055 if (unformat (vam->input, "%s", &name))
11056 if (clib_macro_unset (&vam->macro_main, (char *)name) == 1)
11057 errmsg ("unset: %s wasn't set\n", name);
11068 static int macro_sort_cmp (void * a1, void * a2)
11070 macro_sort_t * s1 = a1;
11071 macro_sort_t * s2 = a2;
11073 return strcmp ((char *)(s1->name), (char *)(s2->name));
11076 static int dump_macro_table (vat_main_t * vam)
11078 macro_sort_t * sort_me = 0, * sm;
11082 hash_foreach_pair (p, vam->macro_main.the_value_table_hash,
11084 vec_add2 (sort_me, sm, 1);
11085 sm->name = (u8 *)(p->key);
11086 sm->value = (u8 *) (p->value[0]);
11089 vec_sort_with_function (sort_me, macro_sort_cmp);
11091 if (vec_len(sort_me))
11092 fformat (vam->ofp, "%-15s%s\n", "Name", "Value");
11094 fformat (vam->ofp, "The macro table is empty...\n");
11096 for (i = 0; i < vec_len (sort_me); i++)
11097 fformat (vam->ofp, "%-15s%s\n", sort_me[i].name,
11102 static int dump_node_table (vat_main_t * vam)
11105 vlib_node_t * node, * next_node;
11107 if (vec_len (vam->graph_nodes) == 0) {
11108 fformat (vam->ofp, "Node table empty, issue get_node_graph...\n");
11112 for (i = 0; i < vec_len (vam->graph_nodes); i++) {
11113 node = vam->graph_nodes[i];
11114 fformat (vam->ofp, "[%d] %s\n", i, node->name);
11115 for (j = 0; j < vec_len (node->next_nodes); j++) {
11116 if (node->next_nodes[j] != ~0) {
11117 next_node = vam->graph_nodes[node->next_nodes[j]];
11118 fformat (vam->ofp, " [%d] %s\n", j, next_node->name);
11125 static int search_node_table (vat_main_t * vam)
11127 unformat_input_t * line_input = vam->input;
11130 vlib_node_t * node, * next_node;
11133 if (vam->graph_node_index_by_name == 0) {
11134 fformat (vam->ofp, "Node table empty, issue get_node_graph...\n");
11138 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) {
11139 if (unformat (line_input, "%s", &node_to_find)) {
11140 vec_add1 (node_to_find, 0);
11141 p = hash_get_mem (vam->graph_node_index_by_name, node_to_find);
11143 fformat (vam->ofp, "%s not found...\n", node_to_find);
11146 node = vam->graph_nodes[p[0]];
11147 fformat (vam->ofp, "[%d] %s\n", p[0], node->name);
11148 for (j = 0; j < vec_len (node->next_nodes); j++) {
11149 if (node->next_nodes[j] != ~0) {
11150 next_node = vam->graph_nodes[node->next_nodes[j]];
11151 fformat (vam->ofp, " [%d] %s\n", j, next_node->name);
11157 clib_warning ("parse error '%U'", format_unformat_error,
11163 vec_free(node_to_find);
11171 static int script (vat_main_t * vam)
11174 char * save_current_file;
11175 unformat_input_t save_input;
11176 jmp_buf save_jump_buf;
11177 u32 save_line_number;
11179 FILE * new_fp, * save_ifp;
11181 if (unformat (vam->input, "%s", &s)) {
11182 new_fp = fopen ((char *)s, "r");
11184 errmsg ("Couldn't open script file %s\n", s);
11189 errmsg ("Missing script name\n");
11193 clib_memcpy (&save_input, &vam->input, sizeof (save_input));
11194 clib_memcpy (&save_jump_buf, &vam->jump_buf, sizeof (save_jump_buf));
11195 save_ifp = vam->ifp;
11196 save_line_number = vam->input_line_number;
11197 save_current_file = (char *) vam->current_file;
11199 vam->input_line_number = 0;
11201 vam->current_file = s;
11204 clib_memcpy (&vam->input, &save_input, sizeof (vam->input));
11205 clib_memcpy (&vam->jump_buf, &save_jump_buf, sizeof (save_jump_buf));
11206 vam->ifp = save_ifp;
11207 vam->input_line_number = save_line_number;
11208 vam->current_file = (u8 *) save_current_file;
11214 static int echo (vat_main_t * vam)
11216 fformat (vam->ofp, "%v", vam->input->buffer);
11220 /* List of API message constructors, CLI names map to api_xxx */
11221 #define foreach_vpe_api_msg \
11222 _(create_loopback,"[mac <mac-addr>]") \
11223 _(sw_interface_dump,"") \
11224 _(sw_interface_set_flags, \
11225 "<intfc> | sw_if_index <id> admin-up | admin-down link-up | link down") \
11226 _(sw_interface_add_del_address, \
11227 "<intfc> | sw_if_index <id> <ip4-address> | <ip6-address> [del] [del-all] ") \
11228 _(sw_interface_set_table, \
11229 "<intfc> | sw_if_index <id> vrf <table-id> [ipv6]") \
11230 _(sw_interface_set_vpath, \
11231 "<intfc> | sw_if_index <id> enable | disable") \
11232 _(sw_interface_set_l2_xconnect, \
11233 "rx <intfc> | rx_sw_if_index <id> tx <intfc> | tx_sw_if_index <id>\n" \
11234 "enable | disable") \
11235 _(sw_interface_set_l2_bridge, \
11236 "rx <intfc> | rx_sw_if_index <id> bd_id <bridge-domain-id>\n" \
11237 "[shg <split-horizon-group>] [bvi]\n" \
11238 "enable | disable") \
11239 _(bridge_domain_add_del, \
11240 "bd_id <bridge-domain-id> [flood 1|0] [uu-flood 1|0] [forward 1|0] [learn 1|0] [arp-term 1|0] [del]\n")\
11241 _(bridge_domain_dump, "[bd_id <bridge-domain-id>]\n") \
11243 "mac <mac-addr> bd_id <bridge-domain-id> [del] | sw_if <intfc> | sw_if_index <id> [static] [filter] [bvi]\n") \
11245 "sw_if <intfc> | sw_if_index <id> [learn] [forward] [uu-flood] [flood]\n") \
11247 "bd_id <bridge-domain-id> [learn] [forward] [uu-flood] [flood] [arp-term] [disable]\n") \
11249 "tapname <name> mac <mac-addr> | random-mac") \
11251 "<vpp-if-name> | sw_if_index <id> tapname <name> mac <mac-addr> | random-mac") \
11253 "<vpp-if-name> | sw_if_index <id>") \
11254 _(sw_interface_tap_dump, "") \
11255 _(ip_add_del_route, \
11256 "<addr>/<mask> via <addr> [vrf <n>]\n" \
11257 "[<intfc> | sw_if_index <id>] [resolve-attempts <n>]\n" \
11258 "[weight <n>] [drop] [local] [classify <n>] [del]\n" \
11259 "[multipath] [count <n>]") \
11260 _(proxy_arp_add_del, \
11261 "<lo-ip4-addr> - <hi-ip4-addr> [vrf <n>] [del]") \
11262 _(proxy_arp_intfc_enable_disable, \
11263 "<intfc> | sw_if_index <id> enable | disable") \
11264 _(mpls_add_del_encap, \
11265 "label <n> dst <ip4-addr> [vrf <n>] [del]") \
11266 _(mpls_add_del_decap, \
11267 "label <n> [rx_vrf_id <n>] [tx_vrf_id] [s-bit-clear][del]") \
11268 _(mpls_gre_add_del_tunnel, \
11269 "inner_vrf_id <n> outer_vrf_id <n> src <ip4-address> dst <ip4-address>\n" \
11270 "adj <ip4-address>/<mask-width> [del]") \
11271 _(sw_interface_set_unnumbered, \
11272 "<intfc> | sw_if_index <id> unnum_if_index <id> [del]") \
11273 _(ip_neighbor_add_del, \
11274 "<intfc> | sw_if_index <id> dst <ip46-address> mac <mac-addr>") \
11275 _(reset_vrf, "vrf <id> [ipv6]") \
11276 _(create_vlan_subif, "<intfc> | sw_if_index <id> vlan <n>") \
11277 _(create_subif, "<intfc> | sw_if_index <id> sub_id <n>\n" \
11278 "[outer_vlan_id <n>][inner_vlan_id <n>]\n" \
11279 "[no_tags][one_tag][two_tags][dot1ad][exact_match][default_sub]\n" \
11280 "[outer_vlan_id_any][inner_vlan_id_any]") \
11281 _(oam_add_del, "src <ip4-address> dst <ip4-address> [vrf <n>] [del]") \
11282 _(reset_fib, "vrf <n> [ipv6]") \
11283 _(dhcp_proxy_config, \
11284 "svr <v46-address> src <v46-address>\n" \
11285 "insert-cid <n> [del]") \
11286 _(dhcp_proxy_config_2, \
11287 "svr <v46-address> src <v46-address>\n" \
11288 "rx_vrf_id <nn> server_vrf_id <nn> insert-cid <n> [del]") \
11289 _(dhcp_proxy_set_vss, \
11290 "tbl_id <n> fib_id <n> oui <n> [ipv6] [del]") \
11291 _(dhcp_client_config, \
11292 "<intfc> | sw_if_index <id> [hostname <name>] [disable_event] [del]") \
11293 _(set_ip_flow_hash, \
11294 "vrf <n> [src] [dst] [sport] [dport] [proto] [reverse] [ipv6]") \
11295 _(sw_interface_ip6_enable_disable, \
11296 "<intfc> | sw_if_index <id> enable | disable") \
11297 _(sw_interface_ip6_set_link_local_address, \
11298 "<intfc> | sw_if_index <id> <ip6-address>/<mask-width>") \
11299 _(sw_interface_ip6nd_ra_prefix, \
11300 "<intfc> | sw_if_index <id> <ip6-address>/<mask-width>\n" \
11301 "val_life <n> pref_life <n> [def] [noadv] [offl] [noauto]\n" \
11302 "[nolink] [isno]") \
11303 _(sw_interface_ip6nd_ra_config, \
11304 "<intfc> | sw_if_index <id> [maxint <n>] [minint <n>]\n" \
11305 "[life <n>] [count <n>] [interval <n>] [surpress]\n" \
11306 "[managed] [other] [ll] [send] [cease] [isno] [def]") \
11307 _(set_arp_neighbor_limit, "arp_nbr_limit <n> [ipv6]") \
11308 _(l2_patch_add_del, \
11309 "rx <intfc> | rx_sw_if_index <id> tx <intfc> | tx_sw_if_index <id>\n" \
11310 "enable | disable") \
11311 _(mpls_ethernet_add_del_tunnel, \
11312 "tx <intfc> | tx_sw_if_index <n> dst <mac-addr>\n" \
11313 "adj <ip4-addr>/<mw> dst <mac-addr> [del]") \
11314 _(mpls_ethernet_add_del_tunnel_2, \
11315 "inner_vrf_id <n> outer_vrf_id <n> next-hop <ip4-addr>\n" \
11316 "resolve-attempts <n> resolve-if-needed 0 | 1 [del]") \
11317 _(sr_tunnel_add_del, \
11318 "[name <name>] src <ip6-addr> dst <ip6-addr>/<mw> \n" \
11319 "(next <ip6-addr>)+ [tag <ip6-addr>]* [clean] [reroute] \n" \
11320 "[policy <policy_name>]") \
11321 _(sr_policy_add_del, \
11322 "name <name> tunnel <tunnel-name> [tunnel <tunnel-name>]* [del]") \
11323 _(sr_multicast_map_add_del, \
11324 "address [ip6 multicast address] sr-policy [policy name] [del]") \
11325 _(classify_add_del_table, \
11326 "buckets <nn> [skip <n>] [match <n>] [memory_size <nn-bytes>]\n" \
11327 "[del] mask <mask-value>\n" \
11328 " [l2-miss-next | miss-next | acl-miss-next] <name|nn>") \
11329 _(classify_add_del_session, \
11330 "[hit-next|l2-hit-next|acl-hit-next] <name|nn> table-index <nn>\n" \
11331 "skip_n <nn> match_n <nn> match [hex] [l2] [l3 [ip4|ip6]]") \
11332 _(classify_set_interface_ip_table, \
11333 "<intfc> | sw_if_index <nn> table <nn>") \
11334 _(classify_set_interface_l2_tables, \
11335 "<intfc> | sw_if_index <nn> [ip4-table <nn>] [ip6-table <nn>]\n" \
11336 " [other-table <nn>]") \
11337 _(get_node_index, "node <node-name") \
11338 _(add_node_next, "node <node-name> next <next-node-name>") \
11339 _(l2tpv3_create_tunnel, \
11340 "client_address <ip6-addr> our_address <ip6-addr>\n" \
11341 "[local_session_id <nn>][remote_session_id <nn>][local_cookie <nn>]\n"\
11342 "[remote_cookie <nn>]\n[l2-sublayer-preset]\n") \
11343 _(l2tpv3_set_tunnel_cookies, \
11344 "<intfc> | sw_if_index <nn> [new_local_cookie <nn>]\n" \
11345 "[new_remote_cookie <nn>]\n") \
11346 _(l2tpv3_interface_enable_disable, \
11347 "<intfc> | sw_if_index <nn> enable | disable") \
11348 _(l2tpv3_set_lookup_key, \
11349 "lookup_v6_src | lookup_v6_dst | lookup_session_id") \
11350 _(sw_if_l2tpv3_tunnel_dump, "") \
11351 _(vxlan_add_del_tunnel, \
11352 "src <ip-addr> dst <ip-addr> vni <vni> [encap-vrf-id <nn>]\n" \
11353 " [decap-next l2|ip4|ip6] [del]") \
11354 _(vxlan_tunnel_dump, "[<intfc> | sw_if_index <nn>]") \
11355 _(gre_add_del_tunnel, \
11356 "src <ip4-addr> dst <ip4-addr> [outer-fib-id <nn>] [del]\n") \
11357 _(gre_tunnel_dump, "[<intfc> | sw_if_index <nn>]") \
11358 _(l2_fib_clear_table, "") \
11359 _(l2_interface_efp_filter, "sw_if_index <nn> enable | disable") \
11360 _(l2_interface_vlan_tag_rewrite, \
11361 "<intfc> | sw_if_index <nn> \n" \
11362 "[disable][push-[1|2]][pop-[1|2]][translate-1-[1|2]] \n" \
11363 "[translate-2-[1|2]] [push_dot1q 0] tag1 <nn> tag2 <nn>") \
11364 _(create_vhost_user_if, \
11365 "socket <filename> [server] [renumber <dev_instance>] " \
11366 "[mac <mac_address>]") \
11367 _(modify_vhost_user_if, \
11368 "<intfc> | sw_if_index <nn> socket <filename>\n" \
11369 "[server] [renumber <dev_instance>]") \
11370 _(delete_vhost_user_if, "<intfc> | sw_if_index <nn>") \
11371 _(sw_interface_vhost_user_dump, "") \
11372 _(show_version, "") \
11373 _(vxlan_gpe_add_del_tunnel, \
11374 "local <addr> remote <addr> vni <nn>\n" \
11375 "[encap-vrf-id <nn>] [decap-vrf-id <nn>] [next-ip4][next-ip6]" \
11376 "[next-ethernet] [next-nsh]\n") \
11377 _(vxlan_gpe_tunnel_dump, "[<intfc> | sw_if_index <nn>]") \
11378 _(l2_fib_table_dump, "bd_id <bridge-domain-id>") \
11379 _(interface_name_renumber, \
11380 "<intfc> | sw_if_index <nn> new_show_dev_instance <nn>") \
11381 _(input_acl_set_interface, \
11382 "<intfc> | sw_if_index <nn> [ip4-table <nn>] [ip6-table <nn>]\n" \
11383 " [l2-table <nn>] [del]") \
11384 _(want_ip4_arp_events, "address <ip4-address> [del]") \
11385 _(ip_address_dump, "(ipv4 | ipv6) (<intfc> | sw_if_index <id>)") \
11386 _(ip_dump, "ipv4 | ipv6") \
11387 _(ipsec_spd_add_del, "spd_id <n> [del]") \
11388 _(ipsec_interface_add_del_spd, "(<intfc> | sw_if_index <id>)\n" \
11390 _(ipsec_sad_add_del_entry, "sad_id <n> spi <n> crypto_alg <alg>\n" \
11391 " crypto_key <hex> tunnel_src <ip4|ip6> tunnel_dst <ip4|ip6>\n" \
11392 " integ_alg <alg> integ_key <hex>") \
11393 _(ipsec_spd_add_del_entry, "spd_id <n> priority <n> action <action>\n" \
11394 " (inbound|outbound) [sa_id <n>] laddr_start <ip4|ip6>\n" \
11395 " laddr_stop <ip4|ip6> raddr_start <ip4|ip6> raddr_stop <ip4|ip6>\n" \
11396 " [lport_start <n> lport_stop <n>] [rport_start <n> rport_stop <n>]" )\
11397 _(ipsec_sa_set_key, "sa_id <n> crypto_key <hex> integ_key <hex>") \
11398 _(ikev2_profile_add_del, "name <profile_name> [del]") \
11399 _(ikev2_profile_set_auth, "name <profile_name> auth_method <method>\n" \
11400 "(auth_data 0x<data> | auth_data <data>)") \
11401 _(ikev2_profile_set_id, "name <profile_name> id_type <type>\n" \
11402 "(id_data 0x<data> | id_data <data>) (local|remote)") \
11403 _(ikev2_profile_set_ts, "name <profile_name> protocol <proto>\n" \
11404 "start_port <port> end_port <port> start_addr <ip4> end_addr <ip4>\n" \
11405 "(local|remote)") \
11406 _(ikev2_set_local_key, "file <absolute_file_path>") \
11407 _(delete_loopback,"sw_if_index <nn>") \
11408 _(bd_ip_mac_add_del, "bd_id <bridge-domain-id> <ip4/6-addr> <mac-addr> [del]") \
11409 _(map_add_domain, \
11410 "ip4-pfx <ip4pfx> ip6-pfx <ip6pfx> " \
11411 "ip6-src <ip6addr> " \
11412 "ea-bits-len <n> psid-offset <n> psid-len <n>") \
11413 _(map_del_domain, "index <n>") \
11414 _(map_add_del_rule, \
11415 "index <n> psid <n> dst <ip6addr> [del]") \
11416 _(map_domain_dump, "") \
11417 _(map_rule_dump, "index <map-domain>") \
11418 _(want_interface_events, "enable|disable") \
11419 _(want_stats,"enable|disable") \
11420 _(get_first_msg_id, "client <name>") \
11421 _(cop_interface_enable_disable, "<intfc> | sw_if_index <nn> [disable]") \
11422 _(cop_whitelist_enable_disable, "<intfc> | sw_if_index <nn>\n" \
11423 "fib-id <nn> [ip4][ip6][default]") \
11424 _(get_node_graph, " ") \
11425 _(sw_interface_clear_stats,"<intfc> | sw_if_index <nn>") \
11426 _(trace_profile_add, "id <nn> trace-type <0x1f|0x3|0x9|0x11|0x19> " \
11427 "trace-elts <nn> trace-tsp <0|1|2|3> node-id <node id in hex> " \
11428 "app-data <app_data in hex> [pow] [ppc <encap|decap>]") \
11429 _(trace_profile_apply, "id <nn> <ip6-address>/<width>" \
11430 " vrf_id <nn> add | pop | none") \
11431 _(trace_profile_del, "") \
11432 _(lisp_add_del_locator_set, "locator-set <locator_name> [del]") \
11433 _(lisp_add_del_locator, "locator-set <locator_name> " \
11434 "iface <intf> | sw_if_index <sw_if_index> " \
11435 "p <priority> w <weight> [del]") \
11436 _(lisp_add_del_local_eid, "<ipv4|ipv6>/<prefix> " \
11437 "locator-set <locator_name> [del]") \
11438 _(lisp_gpe_add_del_fwd_entry, "eid <ip4|6-addr>/<prefix> " \
11439 "sloc <ip4/6-addr> dloc <ip4|6-addr> [del]") \
11440 _(lisp_add_del_map_resolver, "<ip4|6-addr> [del]") \
11441 _(lisp_gpe_enable_disable, "enable|disable") \
11442 _(lisp_enable_disable, "enable|disable") \
11443 _(lisp_gpe_add_del_iface, "up|down") \
11444 _(lisp_add_del_remote_mapping, "add|del vni <vni> table-id <id> " \
11445 "deid <dest-eid> seid" \
11446 " <src-eid> rloc <locator> " \
11447 "[rloc <loc> ... ]") \
11448 _(lisp_pitr_set_locator_set, "locator-set <loc-set-name> | del") \
11449 _(lisp_add_del_map_request_itr_rlocs, "<loc-set-name> [del]") \
11450 _(lisp_locator_set_dump, "") \
11451 _(lisp_local_eid_table_dump, "") \
11452 _(lisp_gpe_tunnel_dump, "") \
11453 _(lisp_map_resolver_dump, "") \
11454 _(lisp_enable_disable_status_dump, "") \
11455 _(lisp_get_map_request_itr_rlocs, "") \
11456 _(af_packet_create, "name <host interface name> [hw_addr <mac>]") \
11457 _(af_packet_delete, "name <host interface name>") \
11458 _(policer_add_del, "name <policer name> <params> [del]") \
11459 _(policer_dump, "[name <policer name>]") \
11460 _(netmap_create, "name <interface name> [hw-addr <mac>] [pipe] " \
11461 "[master|slave]") \
11462 _(netmap_delete, "name <interface name>")
11464 /* List of command functions, CLI names map directly to functions */
11465 #define foreach_cli_function \
11466 _(comment, "usage: comment <ignore-rest-of-line>") \
11467 _(dump_interface_table, "usage: dump_interface_table") \
11468 _(dump_sub_interface_table, "usage: dump_sub_interface_table") \
11469 _(dump_ipv4_table, "usage: dump_ipv4_table") \
11470 _(dump_ipv6_table, "usage: dump_ipv6_table") \
11471 _(dump_stats_table, "usage: dump_stats_table") \
11472 _(dump_macro_table, "usage: dump_macro_table ") \
11473 _(dump_node_table, "usage: dump_node_table") \
11474 _(echo, "usage: echo <message>") \
11475 _(exec, "usage: exec <vpe-debug-CLI-command>") \
11476 _(help, "usage: help") \
11477 _(q, "usage: quit") \
11478 _(quit, "usage: quit") \
11479 _(search_node_table, "usage: search_node_table <name>...") \
11480 _(set, "usage: set <variable-name> <value>") \
11481 _(script, "usage: script <file-name>") \
11482 _(unset, "usage: unset <variable-name>")
11485 static void vl_api_##n##_t_handler_uni \
11486 (vl_api_##n##_t * mp) \
11488 vat_main_t * vam = &vat_main; \
11489 if (vam->json_output) { \
11490 vl_api_##n##_t_handler_json(mp); \
11492 vl_api_##n##_t_handler(mp); \
11495 foreach_vpe_api_reply_msg;
11498 void vat_api_hookup (vat_main_t *vam)
11501 vl_msg_api_set_handlers(VL_API_##N, #n, \
11502 vl_api_##n##_t_handler_uni, \
11504 vl_api_##n##_t_endian, \
11505 vl_api_##n##_t_print, \
11506 sizeof(vl_api_##n##_t), 1);
11507 foreach_vpe_api_reply_msg;
11510 vl_msg_api_set_first_available_msg_id (VL_MSG_FIRST_AVAILABLE);
11512 vam->sw_if_index_by_interface_name =
11513 hash_create_string (0, sizeof (uword));
11515 vam->function_by_name =
11516 hash_create_string (0, sizeof(uword));
11518 vam->help_by_name =
11519 hash_create_string (0, sizeof(uword));
11521 /* API messages we can send */
11522 #define _(n,h) hash_set_mem (vam->function_by_name, #n, api_##n);
11523 foreach_vpe_api_msg;
11527 #define _(n,h) hash_set_mem (vam->help_by_name, #n, h);
11528 foreach_vpe_api_msg;
11531 /* CLI functions */
11532 #define _(n,h) hash_set_mem (vam->function_by_name, #n, n);
11533 foreach_cli_function;
11537 #define _(n,h) hash_set_mem (vam->help_by_name, #n, h);
11538 foreach_cli_function;
11542 #undef vl_api_version
11543 #define vl_api_version(n,v) static u32 vpe_api_version = v;
11544 #include <api/vpe.api.h>
11545 #undef vl_api_version
11547 void vl_client_add_api_signatures (vl_api_memclnt_create_t *mp)
11550 * Send the main API signature in slot 0. This bit of code must
11551 * match the checks in ../vpe/api/api.c: vl_msg_api_version_check().
11553 mp->api_versions[0] = clib_host_to_net_u32 (vpe_api_version);