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->result_ready = 1;
537 vam->regenerate_interface_table = 1;
540 static void vl_api_create_loopback_reply_t_handler_json
541 (vl_api_create_loopback_reply_t * mp)
543 vat_main_t * vam = &vat_main;
544 vat_json_node_t node;
546 vat_json_init_object(&node);
547 vat_json_object_add_int(&node, "retval", ntohl(mp->retval));
548 vat_json_object_add_uint(&node, "sw_if_index", ntohl(mp->sw_if_index));
550 vat_json_print(vam->ofp, &node);
551 vat_json_free(&node);
553 vam->retval = ntohl(mp->retval);
554 vam->result_ready = 1;
557 static void vl_api_create_vlan_subif_reply_t_handler
558 (vl_api_create_vlan_subif_reply_t * mp)
560 vat_main_t * vam = &vat_main;
561 i32 retval = ntohl(mp->retval);
563 vam->retval = retval;
564 vam->result_ready = 1;
565 vam->regenerate_interface_table = 1;
568 static void vl_api_create_vlan_subif_reply_t_handler_json
569 (vl_api_create_vlan_subif_reply_t * mp)
571 vat_main_t * vam = &vat_main;
572 vat_json_node_t node;
574 vat_json_init_object(&node);
575 vat_json_object_add_int(&node, "retval", ntohl(mp->retval));
576 vat_json_object_add_uint(&node, "sw_if_index", ntohl(mp->sw_if_index));
578 vat_json_print(vam->ofp, &node);
579 vat_json_free(&node);
581 vam->retval = ntohl(mp->retval);
582 vam->result_ready = 1;
585 static void vl_api_create_subif_reply_t_handler
586 (vl_api_create_subif_reply_t * mp)
588 vat_main_t * vam = &vat_main;
589 i32 retval = ntohl(mp->retval);
591 vam->retval = retval;
592 vam->result_ready = 1;
593 vam->regenerate_interface_table = 1;
596 static void vl_api_create_subif_reply_t_handler_json
597 (vl_api_create_subif_reply_t * mp)
599 vat_main_t * vam = &vat_main;
600 vat_json_node_t node;
602 vat_json_init_object(&node);
603 vat_json_object_add_int(&node, "retval", ntohl(mp->retval));
604 vat_json_object_add_uint(&node, "sw_if_index", ntohl(mp->sw_if_index));
606 vat_json_print(vam->ofp, &node);
607 vat_json_free(&node);
609 vam->retval = ntohl(mp->retval);
610 vam->result_ready = 1;
613 static void vl_api_interface_name_renumber_reply_t_handler
614 (vl_api_interface_name_renumber_reply_t * mp)
616 vat_main_t * vam = &vat_main;
617 i32 retval = ntohl(mp->retval);
619 vam->retval = retval;
620 vam->result_ready = 1;
621 vam->regenerate_interface_table = 1;
624 static void vl_api_interface_name_renumber_reply_t_handler_json
625 (vl_api_interface_name_renumber_reply_t * mp)
627 vat_main_t * vam = &vat_main;
628 vat_json_node_t node;
630 vat_json_init_object(&node);
631 vat_json_object_add_int(&node, "retval", ntohl(mp->retval));
633 vat_json_print(vam->ofp, &node);
634 vat_json_free(&node);
636 vam->retval = ntohl(mp->retval);
637 vam->result_ready = 1;
641 * Special-case: build the interface table, maintain
642 * the next loopback sw_if_index vbl.
644 static void vl_api_sw_interface_details_t_handler
645 (vl_api_sw_interface_details_t * mp)
647 vat_main_t * vam = &vat_main;
648 u8 * s = format (0, "%s%c", mp->interface_name, 0);
650 hash_set_mem (vam->sw_if_index_by_interface_name, s,
651 ntohl(mp->sw_if_index));
653 /* In sub interface case, fill the sub interface table entry */
654 if (mp->sw_if_index != mp->sup_sw_if_index) {
655 sw_interface_subif_t * sub = NULL;
657 vec_add2(vam->sw_if_subif_table, sub, 1);
659 vec_validate(sub->interface_name, strlen((char *)s) + 1);
660 strncpy((char *)sub->interface_name, (char *)s,
661 vec_len(sub->interface_name));
662 sub->sw_if_index = ntohl(mp->sw_if_index);
663 sub->sub_id = ntohl(mp->sub_id);
665 sub->sub_dot1ad = mp->sub_dot1ad;
666 sub->sub_number_of_tags = mp->sub_number_of_tags;
667 sub->sub_outer_vlan_id = ntohs(mp->sub_outer_vlan_id);
668 sub->sub_inner_vlan_id = ntohs(mp->sub_inner_vlan_id);
669 sub->sub_exact_match = mp->sub_exact_match;
670 sub->sub_default = mp->sub_default;
671 sub->sub_outer_vlan_id_any = mp->sub_outer_vlan_id_any;
672 sub->sub_inner_vlan_id_any = mp->sub_inner_vlan_id_any;
674 /* vlan tag rewrite */
675 sub->vtr_op = ntohl(mp->vtr_op);
676 sub->vtr_push_dot1q = ntohl(mp->vtr_push_dot1q);
677 sub->vtr_tag1 = ntohl(mp->vtr_tag1);
678 sub->vtr_tag2 = ntohl(mp->vtr_tag2);
682 static void vl_api_sw_interface_details_t_handler_json
683 (vl_api_sw_interface_details_t * mp)
685 vat_main_t * vam = &vat_main;
686 vat_json_node_t *node = NULL;
688 if (VAT_JSON_ARRAY != vam->json_tree.type) {
689 ASSERT(VAT_JSON_NONE == vam->json_tree.type);
690 vat_json_init_array(&vam->json_tree);
692 node = vat_json_array_add(&vam->json_tree);
694 vat_json_init_object(node);
695 vat_json_object_add_uint(node, "sw_if_index", ntohl(mp->sw_if_index));
696 vat_json_object_add_uint(node, "sup_sw_if_index", ntohl(mp->sup_sw_if_index));
697 vat_json_object_add_uint(node, "l2_address_length", ntohl(mp->l2_address_length));
698 vat_json_object_add_bytes(node, "l2_address", mp->l2_address, sizeof(mp->l2_address));
699 vat_json_object_add_string_copy(node, "interface_name", mp->interface_name);
700 vat_json_object_add_uint(node, "admin_up_down", mp->admin_up_down);
701 vat_json_object_add_uint(node, "link_up_down", mp->link_up_down);
702 vat_json_object_add_uint(node, "link_duplex", mp->link_duplex);
703 vat_json_object_add_uint(node, "link_speed", mp->link_speed);
704 vat_json_object_add_uint(node, "mtu", ntohs(mp->link_mtu));
705 vat_json_object_add_uint(node, "sub_id", ntohl(mp->sub_id));
706 vat_json_object_add_uint(node, "sub_dot1ad", mp->sub_dot1ad);
707 vat_json_object_add_uint(node, "sub_number_of_tags", mp->sub_number_of_tags);
708 vat_json_object_add_uint(node, "sub_outer_vlan_id", ntohs(mp->sub_outer_vlan_id));
709 vat_json_object_add_uint(node, "sub_inner_vlan_id", ntohs(mp->sub_inner_vlan_id));
710 vat_json_object_add_uint(node, "sub_exact_match", mp->sub_exact_match);
711 vat_json_object_add_uint(node, "sub_default", mp->sub_default);
712 vat_json_object_add_uint(node, "sub_outer_vlan_id_any", mp->sub_outer_vlan_id_any);
713 vat_json_object_add_uint(node, "sub_inner_vlan_id_any", mp->sub_inner_vlan_id_any);
714 vat_json_object_add_uint(node, "vtr_op", ntohl(mp->vtr_op));
715 vat_json_object_add_uint(node, "vtr_push_dot1q", ntohl(mp->vtr_push_dot1q));
716 vat_json_object_add_uint(node, "vtr_tag1", ntohl(mp->vtr_tag1));
717 vat_json_object_add_uint(node, "vtr_tag2", ntohl(mp->vtr_tag2));
720 static void vl_api_sw_interface_set_flags_t_handler
721 (vl_api_sw_interface_set_flags_t * mp)
723 vat_main_t * vam = &vat_main;
724 if (vam->interface_event_display)
725 errmsg ("interface flags: sw_if_index %d %s %s\n",
726 ntohl(mp->sw_if_index),
727 mp->admin_up_down ? "admin-up" : "admin-down",
728 mp->link_up_down ? "link-up" : "link-down");
731 static void vl_api_sw_interface_set_flags_t_handler_json
732 (vl_api_sw_interface_set_flags_t * mp)
734 /* JSON output not supported */
737 static void vl_api_cli_reply_t_handler
738 (vl_api_cli_reply_t * mp)
740 vat_main_t * vam = &vat_main;
741 i32 retval = ntohl(mp->retval);
743 vam->retval = retval;
744 vam->shmem_result = (u8 *) mp->reply_in_shmem;
745 vam->result_ready = 1;
748 static void vl_api_cli_reply_t_handler_json
749 (vl_api_cli_reply_t * mp)
751 vat_main_t * vam = &vat_main;
752 vat_json_node_t node;
753 api_main_t * am = &api_main;
757 vat_json_init_object(&node);
758 vat_json_object_add_int(&node, "retval", ntohl(mp->retval));
759 vat_json_object_add_uint(&node, "reply_in_shmem",
760 ntohl(mp->reply_in_shmem));
761 /* Toss the shared-memory original... */
762 pthread_mutex_lock (&am->vlib_rp->mutex);
763 oldheap = svm_push_data_heap (am->vlib_rp);
765 reply = (u8 *)(mp->reply_in_shmem);
768 svm_pop_heap (oldheap);
769 pthread_mutex_unlock (&am->vlib_rp->mutex);
771 vat_json_print(vam->ofp, &node);
772 vat_json_free(&node);
774 vam->retval = ntohl(mp->retval);
775 vam->result_ready = 1;
778 static void vl_api_classify_add_del_table_reply_t_handler
779 (vl_api_classify_add_del_table_reply_t * mp)
781 vat_main_t * vam = &vat_main;
782 i32 retval = ntohl(mp->retval);
783 if (vam->async_mode) {
784 vam->async_errors += (retval < 0);
786 vam->retval = retval;
787 vam->result_ready = 1;
789 ((mp->new_table_index != 0xFFFFFFFF) ||
790 (mp->skip_n_vectors != 0xFFFFFFFF) ||
791 (mp->match_n_vectors != 0xFFFFFFFF)))
793 * Note: this is just barely thread-safe, depends on
794 * the main thread spinning waiting for an answer...
796 errmsg ("new index %d, skip_n_vectors %d, match_n_vectors %d\n",
797 ntohl(mp->new_table_index),
798 ntohl(mp->skip_n_vectors), ntohl(mp->match_n_vectors));
802 static void vl_api_classify_add_del_table_reply_t_handler_json
803 (vl_api_classify_add_del_table_reply_t * mp)
805 vat_main_t * vam = &vat_main;
806 vat_json_node_t node;
808 vat_json_init_object(&node);
809 vat_json_object_add_int(&node, "retval", ntohl(mp->retval));
810 vat_json_object_add_uint(&node, "new_table_index", ntohl(mp->new_table_index));
811 vat_json_object_add_uint(&node, "skip_n_vectors", ntohl(mp->skip_n_vectors));
812 vat_json_object_add_uint(&node, "match_n_vectors", ntohl(mp->match_n_vectors));
814 vat_json_print(vam->ofp, &node);
815 vat_json_free(&node);
817 vam->retval = ntohl(mp->retval);
818 vam->result_ready = 1;
821 static void vl_api_get_node_index_reply_t_handler
822 (vl_api_get_node_index_reply_t * mp)
824 vat_main_t * vam = &vat_main;
825 i32 retval = ntohl(mp->retval);
826 if (vam->async_mode) {
827 vam->async_errors += (retval < 0);
829 vam->retval = retval;
830 vam->result_ready = 1;
832 errmsg ("node index %d\n", ntohl(mp->node_index));
836 static void vl_api_get_node_index_reply_t_handler_json
837 (vl_api_get_node_index_reply_t * mp)
839 vat_main_t * vam = &vat_main;
840 vat_json_node_t node;
842 vat_json_init_object(&node);
843 vat_json_object_add_int(&node, "retval", ntohl(mp->retval));
844 vat_json_object_add_uint(&node, "node_index", ntohl(mp->node_index));
846 vat_json_print(vam->ofp, &node);
847 vat_json_free(&node);
849 vam->retval = ntohl(mp->retval);
850 vam->result_ready = 1;
853 static void vl_api_add_node_next_reply_t_handler
854 (vl_api_add_node_next_reply_t * mp)
856 vat_main_t * vam = &vat_main;
857 i32 retval = ntohl(mp->retval);
858 if (vam->async_mode) {
859 vam->async_errors += (retval < 0);
861 vam->retval = retval;
862 vam->result_ready = 1;
864 errmsg ("next index %d\n", ntohl(mp->next_index));
868 static void vl_api_add_node_next_reply_t_handler_json
869 (vl_api_add_node_next_reply_t * mp)
871 vat_main_t * vam = &vat_main;
872 vat_json_node_t node;
874 vat_json_init_object(&node);
875 vat_json_object_add_int(&node, "retval", ntohl(mp->retval));
876 vat_json_object_add_uint(&node, "next_index", ntohl(mp->next_index));
878 vat_json_print(vam->ofp, &node);
879 vat_json_free(&node);
881 vam->retval = ntohl(mp->retval);
882 vam->result_ready = 1;
885 static void vl_api_mpls_gre_add_del_tunnel_reply_t_handler
886 (vl_api_mpls_gre_add_del_tunnel_reply_t * mp)
888 vat_main_t * vam = &vat_main;
889 i32 retval = ntohl(mp->retval);
890 u32 sw_if_index = ntohl(mp->tunnel_sw_if_index);
892 if (retval >= 0 && sw_if_index != (u32)~0) {
893 errmsg ("tunnel_sw_if_index %d\n", sw_if_index);
895 vam->retval = retval;
896 vam->result_ready = 1;
899 static void vl_api_mpls_gre_add_del_tunnel_reply_t_handler_json
900 (vl_api_mpls_gre_add_del_tunnel_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, "tunnel_sw_if_index", ntohl(mp->tunnel_sw_if_index));
909 vat_json_print(vam->ofp, &node);
910 vat_json_free(&node);
912 vam->retval = ntohl(mp->retval);
913 vam->result_ready = 1;
917 static void vl_api_show_version_reply_t_handler
918 (vl_api_show_version_reply_t * mp)
920 vat_main_t * vam = &vat_main;
921 i32 retval = ntohl(mp->retval);
924 errmsg (" program: %s\n", mp->program);
925 errmsg (" version: %s\n", mp->version);
926 errmsg (" build date: %s\n", mp->build_date);
927 errmsg ("build directory: %s\n", mp->build_directory);
929 vam->retval = retval;
930 vam->result_ready = 1;
933 static void vl_api_show_version_reply_t_handler_json
934 (vl_api_show_version_reply_t * mp)
936 vat_main_t * vam = &vat_main;
937 vat_json_node_t node;
939 vat_json_init_object(&node);
940 vat_json_object_add_int(&node, "retval", ntohl(mp->retval));
941 vat_json_object_add_string_copy(&node, "program", mp->program);
942 vat_json_object_add_string_copy(&node, "version", mp->version);
943 vat_json_object_add_string_copy(&node, "build_date", mp->build_date);
944 vat_json_object_add_string_copy(&node, "build_directory", mp->build_directory);
946 vat_json_print(vam->ofp, &node);
947 vat_json_free(&node);
949 vam->retval = ntohl(mp->retval);
950 vam->result_ready = 1;
953 static void vl_api_ip4_arp_event_t_handler
954 (vl_api_ip4_arp_event_t * mp)
956 vat_main_t * vam = &vat_main;
957 errmsg ("arp event: address %U new mac %U sw_if_index %d\n",
958 format_ip4_address, &mp->address,
959 format_ethernet_address, mp->new_mac, mp->sw_if_index);
962 static void vl_api_ip4_arp_event_t_handler_json
963 (vl_api_ip4_arp_event_t * mp)
965 /* JSON output not supported */
969 * Special-case: build the bridge domain table, maintain
970 * the next bd id vbl.
972 static void vl_api_bridge_domain_details_t_handler
973 (vl_api_bridge_domain_details_t * mp)
975 vat_main_t * vam = &vat_main;
976 u32 n_sw_ifs = ntohl (mp->n_sw_ifs);
978 fformat (vam->ofp, "\n%-3s %-3s %-3s %-3s %-3s %-3s\n",
979 " ID", "LRN", "FWD", "FLD", "BVI", "#IF");
981 fformat (vam->ofp, "%3d %3d %3d %3d %3d %3d\n",
982 ntohl (mp->bd_id), mp->learn, mp->forward,
983 mp->flood, ntohl (mp->bvi_sw_if_index), n_sw_ifs);
986 fformat (vam->ofp, "\n\n%s %s %s\n", "sw_if_index", "SHG",
990 static void vl_api_bridge_domain_details_t_handler_json
991 (vl_api_bridge_domain_details_t * mp)
993 vat_main_t * vam = &vat_main;
994 vat_json_node_t *node, *array = NULL;
996 if (VAT_JSON_ARRAY != vam->json_tree.type) {
997 ASSERT(VAT_JSON_NONE == vam->json_tree.type);
998 vat_json_init_array(&vam->json_tree);
1000 node = vat_json_array_add(&vam->json_tree);
1002 vat_json_init_object(node);
1003 vat_json_object_add_uint(node, "bd_id", ntohl(mp->bd_id));
1004 vat_json_object_add_uint(node, "flood", mp->flood);
1005 vat_json_object_add_uint(node, "forward", mp->forward);
1006 vat_json_object_add_uint(node, "learn", mp->learn);
1007 vat_json_object_add_uint(node, "bvi_sw_if_index", ntohl(mp->bvi_sw_if_index));
1008 vat_json_object_add_uint(node, "n_sw_ifs", ntohl(mp->n_sw_ifs));
1009 array = vat_json_object_add(node, "sw_if");
1010 vat_json_init_array(array);
1014 * Special-case: build the bridge domain sw if table.
1016 static void vl_api_bridge_domain_sw_if_details_t_handler
1017 (vl_api_bridge_domain_sw_if_details_t * mp)
1019 vat_main_t * vam = &vat_main;
1021 u8 * sw_if_name = 0;
1024 sw_if_index = ntohl (mp->sw_if_index);
1025 hash_foreach_pair (p, vam->sw_if_index_by_interface_name,
1027 if ((u32) p->value[0] == sw_if_index) {
1028 sw_if_name = (u8 *)(p->key);
1033 fformat (vam->ofp, "%7d %3d %s", sw_if_index,
1034 mp->shg, sw_if_name ? (char *)sw_if_name :
1035 "sw_if_index not found!");
1038 static void vl_api_bridge_domain_sw_if_details_t_handler_json
1039 (vl_api_bridge_domain_sw_if_details_t * mp)
1041 vat_main_t * vam = &vat_main;
1042 vat_json_node_t *node = NULL;
1043 uword last_index = 0;
1045 ASSERT(VAT_JSON_ARRAY == vam->json_tree.type);
1046 ASSERT(vec_len(vam->json_tree.array) >= 1);
1047 last_index = vec_len(vam->json_tree.array) - 1;
1048 node = &vam->json_tree.array[last_index];
1049 node = vat_json_object_get_element(node, "sw_if");
1050 ASSERT(NULL != node);
1051 node = vat_json_array_add(node);
1053 vat_json_init_object(node);
1054 vat_json_object_add_uint(node, "bd_id", ntohl(mp->bd_id));
1055 vat_json_object_add_uint(node, "sw_if_index", ntohl(mp->sw_if_index));
1056 vat_json_object_add_uint(node, "shg", mp->shg);
1059 static void vl_api_control_ping_reply_t_handler
1060 (vl_api_control_ping_reply_t * mp)
1062 vat_main_t * vam = &vat_main;
1063 i32 retval = ntohl(mp->retval);
1064 if (vam->async_mode) {
1065 vam->async_errors += (retval < 0);
1067 vam->retval = retval;
1068 vam->result_ready = 1;
1072 static void vl_api_control_ping_reply_t_handler_json
1073 (vl_api_control_ping_reply_t * mp)
1075 vat_main_t * vam = &vat_main;
1076 i32 retval = ntohl(mp->retval);
1078 if (VAT_JSON_NONE != vam->json_tree.type) {
1079 vat_json_print(vam->ofp, &vam->json_tree);
1080 vat_json_free(&vam->json_tree);
1081 vam->json_tree.type = VAT_JSON_NONE;
1084 vat_json_init_array(&vam->json_tree);
1085 vat_json_print(vam->ofp, &vam->json_tree);
1086 vam->json_tree.type = VAT_JSON_NONE;
1089 vam->retval = retval;
1090 vam->result_ready = 1;
1093 static void vl_api_l2_flags_reply_t_handler
1094 (vl_api_l2_flags_reply_t * mp)
1096 vat_main_t * vam = &vat_main;
1097 i32 retval = ntohl(mp->retval);
1098 if (vam->async_mode) {
1099 vam->async_errors += (retval < 0);
1101 vam->retval = retval;
1102 vam->result_ready = 1;
1106 static void vl_api_l2_flags_reply_t_handler_json
1107 (vl_api_l2_flags_reply_t * mp)
1109 vat_main_t * vam = &vat_main;
1110 vat_json_node_t node;
1112 vat_json_init_object(&node);
1113 vat_json_object_add_int(&node, "retval", ntohl(mp->retval));
1114 vat_json_object_add_uint(&node, "resulting_feature_bitmap", ntohl(mp->resulting_feature_bitmap));
1116 vat_json_print(vam->ofp, &node);
1117 vat_json_free(&node);
1119 vam->retval = ntohl(mp->retval);
1120 vam->result_ready = 1;
1123 static void vl_api_bridge_flags_reply_t_handler
1124 (vl_api_bridge_flags_reply_t * mp)
1126 vat_main_t * vam = &vat_main;
1127 i32 retval = ntohl(mp->retval);
1128 if (vam->async_mode) {
1129 vam->async_errors += (retval < 0);
1131 vam->retval = retval;
1132 vam->result_ready = 1;
1136 static void vl_api_bridge_flags_reply_t_handler_json
1137 (vl_api_bridge_flags_reply_t * mp)
1139 vat_main_t * vam = &vat_main;
1140 vat_json_node_t node;
1142 vat_json_init_object(&node);
1143 vat_json_object_add_int(&node, "retval", ntohl(mp->retval));
1144 vat_json_object_add_uint(&node, "resulting_feature_bitmap", ntohl(mp->resulting_feature_bitmap));
1146 vat_json_print(vam->ofp, &node);
1147 vat_json_free(&node);
1149 vam->retval = ntohl(mp->retval);
1150 vam->result_ready = 1;
1153 static void vl_api_tap_connect_reply_t_handler
1154 (vl_api_tap_connect_reply_t * mp)
1156 vat_main_t * vam = &vat_main;
1157 i32 retval = ntohl(mp->retval);
1158 if (vam->async_mode) {
1159 vam->async_errors += (retval < 0);
1161 vam->retval = retval;
1162 vam->result_ready = 1;
1166 static void vl_api_tap_connect_reply_t_handler_json
1167 (vl_api_tap_connect_reply_t * mp)
1169 vat_main_t * vam = &vat_main;
1170 vat_json_node_t node;
1172 vat_json_init_object(&node);
1173 vat_json_object_add_int(&node, "retval", ntohl(mp->retval));
1174 vat_json_object_add_uint(&node, "sw_if_index", ntohl(mp->sw_if_index));
1176 vat_json_print(vam->ofp, &node);
1177 vat_json_free(&node);
1179 vam->retval = ntohl(mp->retval);
1180 vam->result_ready = 1;
1183 static void vl_api_tap_modify_reply_t_handler
1184 (vl_api_tap_modify_reply_t * mp)
1186 vat_main_t * vam = &vat_main;
1187 i32 retval = ntohl(mp->retval);
1188 if (vam->async_mode) {
1189 vam->async_errors += (retval < 0);
1191 vam->retval = retval;
1192 vam->result_ready = 1;
1196 static void vl_api_tap_modify_reply_t_handler_json
1197 (vl_api_tap_modify_reply_t * mp)
1199 vat_main_t * vam = &vat_main;
1200 vat_json_node_t node;
1202 vat_json_init_object(&node);
1203 vat_json_object_add_int(&node, "retval", ntohl(mp->retval));
1204 vat_json_object_add_uint(&node, "sw_if_index", ntohl(mp->sw_if_index));
1206 vat_json_print(vam->ofp, &node);
1207 vat_json_free(&node);
1209 vam->retval = ntohl(mp->retval);
1210 vam->result_ready = 1;
1213 static void vl_api_tap_delete_reply_t_handler
1214 (vl_api_tap_delete_reply_t * mp)
1216 vat_main_t * vam = &vat_main;
1217 i32 retval = ntohl(mp->retval);
1218 if (vam->async_mode) {
1219 vam->async_errors += (retval < 0);
1221 vam->retval = retval;
1222 vam->result_ready = 1;
1226 static void vl_api_tap_delete_reply_t_handler_json
1227 (vl_api_tap_delete_reply_t * mp)
1229 vat_main_t * vam = &vat_main;
1230 vat_json_node_t node;
1232 vat_json_init_object(&node);
1233 vat_json_object_add_int(&node, "retval", ntohl(mp->retval));
1235 vat_json_print(vam->ofp, &node);
1236 vat_json_free(&node);
1238 vam->retval = ntohl(mp->retval);
1239 vam->result_ready = 1;
1242 static void vl_api_mpls_ethernet_add_del_tunnel_reply_t_handler
1243 (vl_api_mpls_ethernet_add_del_tunnel_reply_t * mp)
1245 vat_main_t * vam = &vat_main;
1246 i32 retval = ntohl(mp->retval);
1247 if (vam->async_mode) {
1248 vam->async_errors += (retval < 0);
1250 vam->retval = retval;
1251 vam->result_ready = 1;
1255 static void vl_api_mpls_ethernet_add_del_tunnel_reply_t_handler_json
1256 (vl_api_mpls_ethernet_add_del_tunnel_reply_t * mp)
1258 vat_main_t * vam = &vat_main;
1259 vat_json_node_t node;
1261 vat_json_init_object(&node);
1262 vat_json_object_add_int(&node, "retval", ntohl(mp->retval));
1263 vat_json_object_add_uint(&node, "tunnel_sw_if_index", ntohl(mp->tunnel_sw_if_index));
1265 vat_json_print(vam->ofp, &node);
1266 vat_json_free(&node);
1268 vam->retval = ntohl(mp->retval);
1269 vam->result_ready = 1;
1272 static void vl_api_l2tpv3_create_tunnel_reply_t_handler
1273 (vl_api_l2tpv3_create_tunnel_reply_t * mp)
1275 vat_main_t * vam = &vat_main;
1276 i32 retval = ntohl(mp->retval);
1277 if (vam->async_mode) {
1278 vam->async_errors += (retval < 0);
1280 vam->retval = retval;
1281 vam->result_ready = 1;
1285 static void vl_api_l2tpv3_create_tunnel_reply_t_handler_json
1286 (vl_api_l2tpv3_create_tunnel_reply_t * mp)
1288 vat_main_t * vam = &vat_main;
1289 vat_json_node_t node;
1291 vat_json_init_object(&node);
1292 vat_json_object_add_int(&node, "retval", ntohl(mp->retval));
1293 vat_json_object_add_uint(&node, "sw_if_index", ntohl(mp->sw_if_index));
1295 vat_json_print(vam->ofp, &node);
1296 vat_json_free(&node);
1298 vam->retval = ntohl(mp->retval);
1299 vam->result_ready = 1;
1302 static void vl_api_vxlan_add_del_tunnel_reply_t_handler
1303 (vl_api_vxlan_add_del_tunnel_reply_t * mp)
1305 vat_main_t * vam = &vat_main;
1306 i32 retval = ntohl(mp->retval);
1307 if (vam->async_mode) {
1308 vam->async_errors += (retval < 0);
1310 vam->retval = retval;
1311 vam->result_ready = 1;
1315 static void vl_api_vxlan_add_del_tunnel_reply_t_handler_json
1316 (vl_api_vxlan_add_del_tunnel_reply_t * mp)
1318 vat_main_t * vam = &vat_main;
1319 vat_json_node_t node;
1321 vat_json_init_object(&node);
1322 vat_json_object_add_int(&node, "retval", ntohl(mp->retval));
1323 vat_json_object_add_uint(&node, "sw_if_index", ntohl(mp->sw_if_index));
1325 vat_json_print(vam->ofp, &node);
1326 vat_json_free(&node);
1328 vam->retval = ntohl(mp->retval);
1329 vam->result_ready = 1;
1332 static void vl_api_gre_add_del_tunnel_reply_t_handler
1333 (vl_api_gre_add_del_tunnel_reply_t * mp)
1335 vat_main_t * vam = &vat_main;
1336 i32 retval = ntohl(mp->retval);
1337 if (vam->async_mode) {
1338 vam->async_errors += (retval < 0);
1340 vam->retval = retval;
1341 vam->result_ready = 1;
1345 static void vl_api_gre_add_del_tunnel_reply_t_handler_json
1346 (vl_api_gre_add_del_tunnel_reply_t * mp)
1348 vat_main_t * vam = &vat_main;
1349 vat_json_node_t node;
1351 vat_json_init_object(&node);
1352 vat_json_object_add_int(&node, "retval", ntohl(mp->retval));
1353 vat_json_object_add_uint(&node, "sw_if_index", ntohl(mp->sw_if_index));
1355 vat_json_print(vam->ofp, &node);
1356 vat_json_free(&node);
1358 vam->retval = ntohl(mp->retval);
1359 vam->result_ready = 1;
1362 static void vl_api_create_vhost_user_if_reply_t_handler
1363 (vl_api_create_vhost_user_if_reply_t * mp)
1365 vat_main_t * vam = &vat_main;
1366 i32 retval = ntohl(mp->retval);
1367 if (vam->async_mode) {
1368 vam->async_errors += (retval < 0);
1370 vam->retval = retval;
1371 vam->result_ready = 1;
1375 static void vl_api_create_vhost_user_if_reply_t_handler_json
1376 (vl_api_create_vhost_user_if_reply_t * mp)
1378 vat_main_t * vam = &vat_main;
1379 vat_json_node_t node;
1381 vat_json_init_object(&node);
1382 vat_json_object_add_int(&node, "retval", ntohl(mp->retval));
1383 vat_json_object_add_uint(&node, "sw_if_index", ntohl(mp->sw_if_index));
1385 vat_json_print(vam->ofp, &node);
1386 vat_json_free(&node);
1388 vam->retval = ntohl(mp->retval);
1389 vam->result_ready = 1;
1392 static void vl_api_ip_address_details_t_handler
1393 (vl_api_ip_address_details_t * mp)
1395 vat_main_t * vam = &vat_main;
1396 static ip_address_details_t empty_ip_address_details = {{0}};
1397 ip_address_details_t * address = NULL;
1398 ip_details_t * current_ip_details = NULL;
1399 ip_details_t * details = NULL;
1401 details = vam->ip_details_by_sw_if_index[vam->is_ipv6];
1403 if (!details || vam->current_sw_if_index >= vec_len(details)
1404 || !details[vam->current_sw_if_index].present) {
1405 errmsg ("ip address details arrived but not stored\n");
1406 errmsg ("ip_dump should be called first\n");
1410 current_ip_details = vec_elt_at_index(details,
1411 vam->current_sw_if_index);
1413 #define addresses (current_ip_details->addr)
1415 vec_validate_init_empty(addresses, vec_len(addresses),
1416 empty_ip_address_details);
1418 address = vec_elt_at_index(addresses, vec_len(addresses) - 1);
1420 clib_memcpy(&address->ip, &mp->ip, sizeof(address->ip));
1421 address->prefix_length = mp->prefix_length;
1425 static void vl_api_ip_address_details_t_handler_json
1426 (vl_api_ip_address_details_t * mp)
1428 vat_main_t * vam = &vat_main;
1429 vat_json_node_t *node = NULL;
1430 struct in6_addr ip6;
1433 if (VAT_JSON_ARRAY != vam->json_tree.type) {
1434 ASSERT(VAT_JSON_NONE == vam->json_tree.type);
1435 vat_json_init_array(&vam->json_tree);
1437 node = vat_json_array_add(&vam->json_tree);
1439 vat_json_init_object(node);
1441 clib_memcpy(&ip6, mp->ip, sizeof(ip6));
1442 vat_json_object_add_ip6(node, "ip", ip6);
1444 clib_memcpy(&ip4, mp->ip, sizeof(ip4));
1445 vat_json_object_add_ip4(node, "ip", ip4);
1447 vat_json_object_add_uint(node, "prefix_length", mp->prefix_length);
1450 static void vl_api_ip_details_t_handler (vl_api_ip_details_t * mp)
1452 vat_main_t * vam = &vat_main;
1453 static ip_details_t empty_ip_details = {0};
1454 ip_details_t * ip = NULL;
1455 u32 sw_if_index = ~0;
1457 sw_if_index = ntohl(mp->sw_if_index);
1459 vec_validate_init_empty(vam->ip_details_by_sw_if_index[vam->is_ipv6],
1460 sw_if_index, empty_ip_details);
1462 ip = vec_elt_at_index(vam->ip_details_by_sw_if_index[vam->is_ipv6],
1468 static void vl_api_ip_details_t_handler_json (vl_api_ip_details_t * mp)
1470 vat_main_t * vam = &vat_main;
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 vat_json_array_add_uint(&vam->json_tree, clib_net_to_host_u32(mp->sw_if_index));
1479 static void vl_api_map_domain_details_t_handler_json
1480 (vl_api_map_domain_details_t * mp)
1482 vat_json_node_t * node = NULL;
1483 vat_main_t * vam = &vat_main;
1484 struct in6_addr ip6;
1487 if (VAT_JSON_ARRAY != vam->json_tree.type) {
1488 ASSERT(VAT_JSON_NONE == vam->json_tree.type);
1489 vat_json_init_array(&vam->json_tree);
1492 node = vat_json_array_add(&vam->json_tree);
1493 vat_json_init_object(node);
1495 vat_json_object_add_uint(node, "domain_index", clib_net_to_host_u32(mp->domain_index));
1496 clib_memcpy(&ip6, mp->ip6_prefix, sizeof(ip6));
1497 vat_json_object_add_ip6(node, "ip6_prefix", ip6);
1498 clib_memcpy(&ip4, mp->ip4_prefix, sizeof(ip4));
1499 vat_json_object_add_ip4(node, "ip4_prefix", ip4);
1500 clib_memcpy(&ip6, mp->ip6_src, sizeof(ip6));
1501 vat_json_object_add_ip6(node, "ip6_src", ip6);
1502 vat_json_object_add_int(node, "ip6_prefix_len", mp->ip6_prefix_len);
1503 vat_json_object_add_int(node, "ip4_prefix_len", mp->ip4_prefix_len);
1504 vat_json_object_add_int(node, "ip6_src_len", mp->ip6_src_len);
1505 vat_json_object_add_int(node, "ea_bits_len", mp->ea_bits_len);
1506 vat_json_object_add_int(node, "psid_offset", mp->psid_offset);
1507 vat_json_object_add_int(node, "psid_length", mp->psid_length);
1508 vat_json_object_add_uint(node, "flags", mp->flags);
1509 vat_json_object_add_uint(node, "mtu", clib_net_to_host_u16(mp->mtu));
1510 vat_json_object_add_int(node, "is_translation", mp->is_translation);
1513 static void vl_api_map_domain_details_t_handler
1514 (vl_api_map_domain_details_t * mp)
1516 vat_main_t * vam = &vat_main;
1518 if (mp->is_translation) {
1519 fformat(vam->ofp, "* %U/%d (ipv4-prefix) %U/%d (ipv6-prefix) %U/%d (ip6-src) index: %u\n",
1520 format_ip4_address, mp->ip4_prefix, mp->ip4_prefix_len,
1521 format_ip6_address, mp->ip6_prefix, mp->ip6_prefix_len,
1522 format_ip6_address, mp->ip6_src, mp->ip6_src_len, clib_net_to_host_u32(mp->domain_index));
1524 fformat(vam->ofp, "* %U/%d (ipv4-prefix) %U/%d (ipv6-prefix) %U (ip6-src) index: %u\n",
1525 format_ip4_address, mp->ip4_prefix, mp->ip4_prefix_len,
1526 format_ip6_address, mp->ip6_prefix, mp->ip6_prefix_len,
1527 format_ip6_address, mp->ip6_src, clib_net_to_host_u32(mp->domain_index));
1529 fformat(vam->ofp, " ea-len %d psid-offset %d psid-len %d mtu %d %s\n",
1530 mp->ea_bits_len, mp->psid_offset, mp->psid_length, mp->mtu, mp->is_translation? "map-t":"");
1533 static void vl_api_map_rule_details_t_handler_json
1534 (vl_api_map_rule_details_t * mp)
1536 struct in6_addr ip6;
1537 vat_json_node_t * node = NULL;
1538 vat_main_t * vam = &vat_main;
1540 if (VAT_JSON_ARRAY != vam->json_tree.type) {
1541 ASSERT(VAT_JSON_NONE == vam->json_tree.type);
1542 vat_json_init_array(&vam->json_tree);
1545 node = vat_json_array_add(&vam->json_tree);
1546 vat_json_init_object(node);
1548 vat_json_object_add_uint(node, "psid", clib_net_to_host_u16(mp->psid));
1549 clib_memcpy(&ip6, mp->ip6_dst, sizeof(ip6));
1550 vat_json_object_add_ip6(node, "ip6_dst", ip6);
1553 static void vl_api_map_rule_details_t_handler
1554 (vl_api_map_rule_details_t * mp)
1556 vat_main_t * vam = &vat_main;
1557 fformat(vam->ofp, " %d (psid) %U (ip6-dst)\n", clib_net_to_host_u16(mp->psid),
1558 format_ip6_address, mp->ip6_dst);
1561 static void vl_api_dhcp_compl_event_t_handler
1562 (vl_api_dhcp_compl_event_t * mp)
1564 vat_main_t * vam = &vat_main;
1565 errmsg ("DHCP compl event: pid %d %s hostname %s host_addr %U "
1566 "router_addr %U host_mac %U\n",
1567 mp->pid, mp->is_ipv6 ? "ipv6":"ipv4", mp->hostname,
1568 format_ip4_address, &mp->host_address,
1569 format_ip4_address, &mp->router_address,
1570 format_ethernet_address, mp->host_mac);
1573 static void vl_api_dhcp_compl_event_t_handler_json
1574 (vl_api_dhcp_compl_event_t * mp)
1576 /* JSON output not supported */
1579 static void set_simple_interface_counter (u8 vnet_counter_type, u32 sw_if_index,
1582 vat_main_t * vam = &vat_main;
1583 static u64 default_counter = 0;
1585 vec_validate_init_empty(vam->simple_interface_counters, vnet_counter_type, NULL);
1586 vec_validate_init_empty(vam->simple_interface_counters[vnet_counter_type],
1587 sw_if_index, default_counter);
1588 vam->simple_interface_counters[vnet_counter_type][sw_if_index] = counter;
1591 static void set_combined_interface_counter (u8 vnet_counter_type, u32 sw_if_index,
1592 interface_counter_t counter)
1594 vat_main_t * vam = &vat_main;
1595 static interface_counter_t default_counter = {0, };
1597 vec_validate_init_empty(vam->combined_interface_counters, vnet_counter_type, NULL);
1598 vec_validate_init_empty(vam->combined_interface_counters[vnet_counter_type],
1599 sw_if_index, default_counter);
1600 vam->combined_interface_counters[vnet_counter_type][sw_if_index] = counter;
1603 static void vl_api_vnet_interface_counters_t_handler
1604 (vl_api_vnet_interface_counters_t *mp)
1609 static void vl_api_vnet_interface_counters_t_handler_json
1610 (vl_api_vnet_interface_counters_t *mp)
1612 interface_counter_t counter;
1617 u32 first_sw_if_index;
1620 count = ntohl(mp->count);
1621 first_sw_if_index = ntohl(mp->first_sw_if_index);
1623 if (!mp->is_combined) {
1624 v_packets = (u64*)&mp->data;
1625 for (i = 0; i < count; i++) {
1626 packets = clib_net_to_host_u64(clib_mem_unaligned(v_packets, u64));
1627 set_simple_interface_counter(mp->vnet_counter_type,
1628 first_sw_if_index + i, packets);
1632 v = (vlib_counter_t*)&mp->data;
1633 for (i = 0; i < count; i++) {
1634 counter.packets = clib_net_to_host_u64(
1635 clib_mem_unaligned(&v->packets, u64));
1636 counter.bytes = clib_net_to_host_u64(
1637 clib_mem_unaligned(&v->bytes, u64));
1638 set_combined_interface_counter(mp->vnet_counter_type,
1639 first_sw_if_index + i, counter);
1645 static u32 ip4_fib_counters_get_vrf_index_by_vrf_id (u32 vrf_id)
1647 vat_main_t * vam = &vat_main;
1650 for (i = 0; i < vec_len(vam->ip4_fib_counters_vrf_id_by_index); i++) {
1651 if (vam->ip4_fib_counters_vrf_id_by_index[i] == vrf_id) {
1658 static u32 ip6_fib_counters_get_vrf_index_by_vrf_id (u32 vrf_id)
1660 vat_main_t * vam = &vat_main;
1663 for (i = 0; i < vec_len(vam->ip6_fib_counters_vrf_id_by_index); i++) {
1664 if (vam->ip6_fib_counters_vrf_id_by_index[i] == vrf_id) {
1671 static void vl_api_vnet_ip4_fib_counters_t_handler
1672 (vl_api_vnet_ip4_fib_counters_t *mp)
1677 static void vl_api_vnet_ip4_fib_counters_t_handler_json
1678 (vl_api_vnet_ip4_fib_counters_t *mp)
1680 vat_main_t * vam = &vat_main;
1681 vl_api_ip4_fib_counter_t *v;
1682 ip4_fib_counter_t *counter;
1689 vrf_id = ntohl(mp->vrf_id);
1690 vrf_index = ip4_fib_counters_get_vrf_index_by_vrf_id(vrf_id);
1691 if (~0 == vrf_index) {
1692 vrf_index = vec_len(vam->ip4_fib_counters_vrf_id_by_index);
1693 vec_validate(vam->ip4_fib_counters_vrf_id_by_index, vrf_index);
1694 vam->ip4_fib_counters_vrf_id_by_index[vrf_index] = vrf_id;
1695 vec_validate(vam->ip4_fib_counters, vrf_index);
1696 vam->ip4_fib_counters[vrf_index] = NULL;
1699 vec_free(vam->ip4_fib_counters[vrf_index]);
1700 v = (vl_api_ip4_fib_counter_t*)&mp->c;
1701 count = ntohl(mp->count);
1702 for (i = 0; i < count; i++) {
1703 vec_validate(vam->ip4_fib_counters[vrf_index], i);
1704 counter = &vam->ip4_fib_counters[vrf_index][i];
1705 clib_memcpy(&ip4, &v->address, sizeof(ip4));
1706 counter->address = ip4;
1707 counter->address_length = v->address_length;
1708 counter->packets = clib_net_to_host_u64(v->packets);
1709 counter->bytes = clib_net_to_host_u64(v->bytes);
1714 static void vl_api_vnet_ip6_fib_counters_t_handler
1715 (vl_api_vnet_ip6_fib_counters_t *mp)
1720 static void vl_api_vnet_ip6_fib_counters_t_handler_json
1721 (vl_api_vnet_ip6_fib_counters_t *mp)
1723 vat_main_t * vam = &vat_main;
1724 vl_api_ip6_fib_counter_t *v;
1725 ip6_fib_counter_t *counter;
1726 struct in6_addr ip6;
1732 vrf_id = ntohl(mp->vrf_id);
1733 vrf_index = ip6_fib_counters_get_vrf_index_by_vrf_id(vrf_id);
1734 if (~0 == vrf_index) {
1735 vrf_index = vec_len(vam->ip6_fib_counters_vrf_id_by_index);
1736 vec_validate(vam->ip6_fib_counters_vrf_id_by_index, vrf_index);
1737 vam->ip6_fib_counters_vrf_id_by_index[vrf_index] = vrf_id;
1738 vec_validate(vam->ip6_fib_counters, vrf_index);
1739 vam->ip6_fib_counters[vrf_index] = NULL;
1742 vec_free(vam->ip6_fib_counters[vrf_index]);
1743 v = (vl_api_ip6_fib_counter_t*)&mp->c;
1744 count = ntohl(mp->count);
1745 for (i = 0; i < count; i++) {
1746 vec_validate(vam->ip6_fib_counters[vrf_index], i);
1747 counter = &vam->ip6_fib_counters[vrf_index][i];
1748 clib_memcpy(&ip6, &v->address, sizeof(ip6));
1749 counter->address = ip6;
1750 counter->address_length = v->address_length;
1751 counter->packets = clib_net_to_host_u64(v->packets);
1752 counter->bytes = clib_net_to_host_u64(v->bytes);
1757 static void vl_api_get_first_msg_id_reply_t_handler
1758 (vl_api_get_first_msg_id_reply_t * mp)
1760 vat_main_t * vam = &vat_main;
1761 i32 retval = ntohl(mp->retval);
1763 if (vam->async_mode) {
1764 vam->async_errors += (retval < 0);
1766 vam->retval = retval;
1767 vam->result_ready = 1;
1770 errmsg ("first message id %d\n", ntohs(mp->first_msg_id));
1774 static void vl_api_get_first_msg_id_reply_t_handler_json
1775 (vl_api_get_first_msg_id_reply_t * mp)
1777 vat_main_t * vam = &vat_main;
1778 vat_json_node_t node;
1780 vat_json_init_object(&node);
1781 vat_json_object_add_int(&node, "retval", ntohl(mp->retval));
1782 vat_json_object_add_uint(&node, "first_msg_id",
1783 (uint) ntohs(mp->first_msg_id));
1785 vat_json_print(vam->ofp, &node);
1786 vat_json_free(&node);
1788 vam->retval = ntohl(mp->retval);
1789 vam->result_ready = 1;
1792 static void vl_api_get_node_graph_reply_t_handler
1793 (vl_api_get_node_graph_reply_t * mp)
1795 vat_main_t * vam = &vat_main;
1796 api_main_t * am = &api_main;
1797 i32 retval = ntohl(mp->retval);
1798 u8 * pvt_copy, * reply;
1803 if (vam->async_mode) {
1804 vam->async_errors += (retval < 0);
1806 vam->retval = retval;
1807 vam->result_ready = 1;
1810 /* "Should never happen..." */
1814 reply = (u8 *)(mp->reply_in_shmem);
1815 pvt_copy = vec_dup (reply);
1817 /* Toss the shared-memory original... */
1818 pthread_mutex_lock (&am->vlib_rp->mutex);
1819 oldheap = svm_push_data_heap (am->vlib_rp);
1823 svm_pop_heap (oldheap);
1824 pthread_mutex_unlock (&am->vlib_rp->mutex);
1826 if (vam->graph_nodes) {
1827 hash_free (vam->graph_node_index_by_name);
1829 for (i = 0; i < vec_len (vam->graph_nodes); i++) {
1830 node = vam->graph_nodes[i];
1831 vec_free (node->name);
1832 vec_free (node->next_nodes);
1835 vec_free(vam->graph_nodes);
1838 vam->graph_node_index_by_name = hash_create_string (0, sizeof(uword));
1839 vam->graph_nodes = vlib_node_unserialize (pvt_copy);
1840 vec_free (pvt_copy);
1842 for (i = 0; i < vec_len (vam->graph_nodes); i++) {
1843 node = vam->graph_nodes[i];
1844 hash_set_mem (vam->graph_node_index_by_name, node->name, i);
1848 static void vl_api_get_node_graph_reply_t_handler_json
1849 (vl_api_get_node_graph_reply_t * mp)
1851 vat_main_t * vam = &vat_main;
1852 api_main_t * am = &api_main;
1854 vat_json_node_t node;
1857 /* $$$$ make this real? */
1858 vat_json_init_object(&node);
1859 vat_json_object_add_int(&node, "retval", ntohl(mp->retval));
1860 vat_json_object_add_uint(&node, "reply_in_shmem", mp->reply_in_shmem);
1862 reply = (u8 *)(mp->reply_in_shmem);
1864 /* Toss the shared-memory original... */
1865 pthread_mutex_lock (&am->vlib_rp->mutex);
1866 oldheap = svm_push_data_heap (am->vlib_rp);
1870 svm_pop_heap (oldheap);
1871 pthread_mutex_unlock (&am->vlib_rp->mutex);
1873 vat_json_print(vam->ofp, &node);
1874 vat_json_free(&node);
1876 vam->retval = ntohl(mp->retval);
1877 vam->result_ready = 1;
1881 vl_api_lisp_locator_set_details_t_handler (
1882 vl_api_lisp_locator_set_details_t *mp)
1884 vat_main_t *vam = &vat_main;
1885 u8 * tmp_str = NULL;
1888 fformat(vam->ofp, "%=20s%=16d%=16d%=16d\n",
1889 mp->locator_set_name,
1890 ntohl(mp->sw_if_index),
1894 tmp_str = format(0,"%U/%d",
1895 mp->is_ipv6 ? format_ip6_address : format_ip4_address,
1899 fformat(vam->ofp, "%=20s%=16s%=16d%=16d\n",
1900 mp->locator_set_name,
1909 vl_api_lisp_locator_set_details_t_handler_json (
1910 vl_api_lisp_locator_set_details_t *mp)
1912 vat_main_t *vam = &vat_main;
1913 vat_json_node_t *node = NULL;
1914 struct in6_addr ip6;
1917 if (VAT_JSON_ARRAY != vam->json_tree.type) {
1918 ASSERT(VAT_JSON_NONE == vam->json_tree.type);
1919 vat_json_init_array(&vam->json_tree);
1921 node = vat_json_array_add(&vam->json_tree);
1923 vat_json_init_object(node);
1924 vat_json_object_add_string_copy(node, "locator-set", mp->locator_set_name);
1926 vat_json_object_add_uint(node, "locator", ntohl(mp->sw_if_index));
1929 clib_memcpy(&ip6, mp->ip_address, sizeof(ip6));
1930 vat_json_object_add_ip6(node, "locator", ip6);
1932 clib_memcpy(&ip4, mp->ip_address, sizeof(ip4));
1933 vat_json_object_add_ip4(node, "locator", ip4);
1935 vat_json_object_add_uint(node, "prefix-length", mp->prefix_len);
1937 vat_json_object_add_uint(node, "priority", mp->priority);
1938 vat_json_object_add_uint(node, "weight", mp->weight);
1942 vl_api_lisp_local_eid_table_details_t_handler (
1943 vl_api_lisp_local_eid_table_details_t *mp)
1945 vat_main_t *vam = &vat_main;
1948 prefix = format(0, "%U/%d",
1949 mp->eid_is_ipv6 ? format_ip6_address : format_ip4_address,
1951 mp->eid_prefix_len);
1953 fformat(vam->ofp, "%=20s%=30s\n",
1954 mp->locator_set_name, prefix);
1960 vl_api_lisp_local_eid_table_details_t_handler_json (
1961 vl_api_lisp_local_eid_table_details_t *mp)
1963 vat_main_t *vam = &vat_main;
1964 vat_json_node_t *node = NULL;
1965 struct in6_addr ip6;
1968 if (VAT_JSON_ARRAY != vam->json_tree.type) {
1969 ASSERT(VAT_JSON_NONE == vam->json_tree.type);
1970 vat_json_init_array(&vam->json_tree);
1972 node = vat_json_array_add(&vam->json_tree);
1974 vat_json_init_object(node);
1975 vat_json_object_add_string_copy(node, "locator-set", mp->locator_set_name);
1976 if (mp->eid_is_ipv6) {
1977 clib_memcpy(&ip6, mp->eid_ip_address, sizeof(ip6));
1978 vat_json_object_add_ip6(node, "eid address", ip6);
1980 clib_memcpy(&ip4, mp->eid_ip_address, sizeof(ip4));
1981 vat_json_object_add_ip4(node, "eid address", ip4);
1983 vat_json_object_add_uint(node, "eid prefix len", mp->eid_prefix_len);
1987 format_decap_next (u8 * s, va_list * args)
1989 u32 next_index = va_arg (*args, u32);
1993 case LISP_GPE_INPUT_NEXT_DROP:
1994 return format (s, "drop");
1995 case LISP_GPE_INPUT_NEXT_IP4_INPUT:
1996 return format (s, "ip4");
1997 case LISP_GPE_INPUT_NEXT_IP6_INPUT:
1998 return format (s, "ip6");
2000 return format (s, "unknown %d", next_index);
2006 vl_api_lisp_gpe_tunnel_details_t_handler (vl_api_lisp_gpe_tunnel_details_t *mp)
2008 vat_main_t *vam = &vat_main;
2010 u8 *flag_str = NULL;
2012 iid_str = format(0, "%d (0x%x)", ntohl(mp->iid), ntohl(mp->iid));
2014 #define _(n,v) if (mp->flags & v) flag_str = format (flag_str, "%s-bit ", #n);
2015 foreach_lisp_gpe_flag_bit;
2018 fformat(vam->ofp, "%=20d%=30U%=16U%=16d%=16d%=16U"
2019 "%=16d%=16d%=16sd=16d%=16s%=16s\n",
2021 mp->is_ipv6 ? format_ip6_address : format_ip4_address,
2023 mp->is_ipv6 ? format_ip6_address : format_ip4_address,
2025 ntohl(mp->encap_fib_id),
2026 ntohl(mp->decap_fib_id),
2027 format_decap_next, ntohl(mp->dcap_next),
2039 vl_api_lisp_gpe_tunnel_details_t_handler_json (
2040 vl_api_lisp_gpe_tunnel_details_t *mp)
2042 vat_main_t *vam = &vat_main;
2043 vat_json_node_t *node = NULL;
2044 struct in6_addr ip6;
2048 next_decap_str = format(0, "%U", format_decap_next, htonl(mp->dcap_next));
2050 if (VAT_JSON_ARRAY != vam->json_tree.type) {
2051 ASSERT(VAT_JSON_NONE == vam->json_tree.type);
2052 vat_json_init_array(&vam->json_tree);
2054 node = vat_json_array_add(&vam->json_tree);
2056 vat_json_init_object(node);
2057 vat_json_object_add_uint(node, "tunel", mp->tunnels);
2059 clib_memcpy(&ip6, mp->source_ip, sizeof(ip6));
2060 vat_json_object_add_ip6(node, "source address", ip6);
2061 clib_memcpy(&ip6, mp->destination_ip, sizeof(ip6));
2062 vat_json_object_add_ip6(node, "destination address", ip6);
2064 clib_memcpy(&ip4, mp->source_ip, sizeof(ip4));
2065 vat_json_object_add_ip4(node, "source address", ip4);
2066 clib_memcpy(&ip4, mp->destination_ip, sizeof(ip4));
2067 vat_json_object_add_ip4(node, "destination address", ip4);
2069 vat_json_object_add_uint(node, "fib encap", ntohl(mp->encap_fib_id));
2070 vat_json_object_add_uint(node, "fib decap", ntohl(mp->decap_fib_id));
2071 vat_json_object_add_string_copy(node, "decap next", next_decap_str);
2072 vat_json_object_add_uint(node, "lisp version", mp->ver_res >> 6);
2073 vat_json_object_add_uint(node, "flags", mp->flags);
2074 vat_json_object_add_uint(node, "next protocol", mp->next_protocol);
2075 vat_json_object_add_uint(node, "ver_res", mp->ver_res);
2076 vat_json_object_add_uint(node, "res", mp->res);
2077 vat_json_object_add_uint(node, "iid", ntohl(mp->iid));
2079 vec_free(next_decap_str);
2083 vl_api_lisp_map_resolver_details_t_handler (
2084 vl_api_lisp_map_resolver_details_t *mp)
2086 vat_main_t *vam = &vat_main;
2088 fformat(vam->ofp, "%=20U\n",
2089 mp->is_ipv6 ? format_ip6_address : format_ip4_address,
2094 vl_api_lisp_map_resolver_details_t_handler_json (
2095 vl_api_lisp_map_resolver_details_t *mp)
2097 vat_main_t *vam = &vat_main;
2098 vat_json_node_t *node = NULL;
2099 struct in6_addr ip6;
2102 if (VAT_JSON_ARRAY != vam->json_tree.type) {
2103 ASSERT(VAT_JSON_NONE == vam->json_tree.type);
2104 vat_json_init_array(&vam->json_tree);
2106 node = vat_json_array_add(&vam->json_tree);
2108 vat_json_init_object(node);
2110 clib_memcpy(&ip6, mp->ip_address, sizeof(ip6));
2111 vat_json_object_add_ip6(node, "map resolver", ip6);
2113 clib_memcpy(&ip4, mp->ip_address, sizeof(ip4));
2114 vat_json_object_add_ip4(node, "map resolver", ip4);
2119 vl_api_lisp_enable_disable_status_details_t_handler
2120 (vl_api_lisp_enable_disable_status_details_t *mp)
2122 vat_main_t *vam = &vat_main;
2124 fformat(vam->ofp, "feature: %s\ngpe: %s\n",
2125 mp->feature_status ? "enabled" : "disabled",
2126 mp->gpe_status ? "enabled" : "disabled");
2130 vl_api_lisp_enable_disable_status_details_t_handler_json
2131 (vl_api_lisp_enable_disable_status_details_t *mp)
2133 vat_main_t *vam = &vat_main;
2134 vat_json_node_t *node = NULL;
2135 u8 * gpe_status = NULL;
2136 u8 * feature_status = NULL;
2138 gpe_status = format (0, "%s", mp->gpe_status ? "enabled" : "disabled");
2139 feature_status = format (0, "%s",
2140 mp->feature_status ? "enabled" : "disabled");
2141 vec_add1 (gpe_status, 0);
2142 vec_add1 (feature_status, 0);
2144 if (VAT_JSON_ARRAY != vam->json_tree.type) {
2145 ASSERT(VAT_JSON_NONE == vam->json_tree.type);
2146 vat_json_init_array(&vam->json_tree);
2148 node = vat_json_array_add(&vam->json_tree);
2150 vat_json_init_object(node);
2151 vat_json_object_add_string_copy(node, "gpe_status", gpe_status);
2152 vat_json_object_add_string_copy(node, "feature_status", feature_status);
2154 vec_free (gpe_status);
2155 vec_free (feature_status);
2158 static u8 * format_policer_type (u8 * s, va_list * va)
2160 u32 i = va_arg (*va, u32);
2162 if (i == SSE2_QOS_POLICER_TYPE_1R2C)
2163 s = format (s, "1r2c");
2164 else if (i == SSE2_QOS_POLICER_TYPE_1R3C_RFC_2697)
2165 s = format (s, "1r3c");
2166 else if (i == SSE2_QOS_POLICER_TYPE_2R3C_RFC_2698)
2167 s = format (s, "2r3c-2698");
2168 else if (i == SSE2_QOS_POLICER_TYPE_2R3C_RFC_4115)
2169 s = format (s, "2r3c-4115");
2170 else if (i == SSE2_QOS_POLICER_TYPE_2R3C_RFC_MEF5CF1)
2171 s = format (s, "2r3c-mef5cf1");
2173 s = format (s, "ILLEGAL");
2177 static u8 * format_policer_rate_type (u8 * s, va_list * va)
2179 u32 i = va_arg (*va, u32);
2181 if (i == SSE2_QOS_RATE_KBPS)
2182 s = format (s, "kbps");
2183 else if (i == SSE2_QOS_RATE_PPS)
2184 s = format(s, "pps");
2186 s = format (s, "ILLEGAL");
2190 static u8 * format_policer_round_type (u8 * s, va_list * va)
2192 u32 i = va_arg (*va, u32);
2194 if (i == SSE2_QOS_ROUND_TO_CLOSEST)
2195 s = format(s, "closest");
2196 else if (i == SSE2_QOS_ROUND_TO_UP)
2197 s = format (s, "up");
2198 else if (i == SSE2_QOS_ROUND_TO_DOWN)
2199 s = format (s, "down");
2201 s = format (s, "ILLEGAL");
2205 static void vl_api_policer_details_t_handler
2206 (vl_api_policer_details_t * mp)
2208 vat_main_t * vam = &vat_main;
2210 fformat (vam->ofp, "Name \"%s\", type %U, cir %u, eir %u, cb %u, eb %u, "
2211 "rate type %U, round type %U, %s rate, %s color-aware, "
2212 "cir %u tok/period, pir %u tok/period, scale %u, cur lim %u, "
2213 "cur bkt %u, ext lim %u, ext bkt %u, last update %llu\n",
2215 format_policer_type, mp->type,
2220 format_policer_rate_type, mp->rate_type,
2221 format_policer_round_type, mp->round_type,
2222 mp->single_rate ? "single" : "dual",
2223 mp->color_aware ? "is" : "not",
2224 ntohl(mp->cir_tokens_per_period),
2225 ntohl(mp->pir_tokens_per_period),
2227 ntohl(mp->current_limit),
2228 ntohl(mp->current_bucket),
2229 ntohl(mp->extended_limit),
2230 ntohl(mp->extended_bucket),
2231 clib_net_to_host_u64(mp->last_update_time));
2234 static void vl_api_policer_details_t_handler_json
2235 (vl_api_policer_details_t * mp)
2237 vat_main_t * vam = &vat_main;
2238 vat_json_node_t *node;
2239 u8 *rate_type_str, *round_type_str, *type_str;
2241 rate_type_str = format(0, "%U", format_policer_rate_type, mp->rate_type);
2242 round_type_str = format(0, "%U", format_policer_round_type, mp->round_type);
2243 type_str = format(0, "%U", format_policer_type, mp->type);
2245 if (VAT_JSON_ARRAY != vam->json_tree.type) {
2246 ASSERT(VAT_JSON_NONE == vam->json_tree.type);
2247 vat_json_init_array(&vam->json_tree);
2249 node = vat_json_array_add(&vam->json_tree);
2251 vat_json_init_object(node);
2252 vat_json_object_add_string_copy(node, "name", mp->name);
2253 vat_json_object_add_uint(node, "cir", ntohl(mp->cir));
2254 vat_json_object_add_uint(node, "eir", ntohl(mp->eir));
2255 vat_json_object_add_uint(node, "cb", ntohl(mp->cb));
2256 vat_json_object_add_uint(node, "eb", ntohl(mp->eb));
2257 vat_json_object_add_string_copy(node, "rate_type", rate_type_str);
2258 vat_json_object_add_string_copy(node, "round_type", round_type_str);
2259 vat_json_object_add_string_copy(node, "type", type_str);
2260 vat_json_object_add_uint(node, "single_rate", mp->single_rate);
2261 vat_json_object_add_uint(node, "color_aware", mp->color_aware);
2262 vat_json_object_add_uint(node, "scale", ntohl(mp->scale));
2263 vat_json_object_add_uint(node, "cir_tokens_per_period",
2264 ntohl(mp->cir_tokens_per_period));
2265 vat_json_object_add_uint(node, "eir_tokens_per_period",
2266 ntohl(mp->pir_tokens_per_period));
2267 vat_json_object_add_uint(node, "current_limit", ntohl(mp->current_limit));
2268 vat_json_object_add_uint(node, "current_bucket", ntohl(mp->current_bucket));
2269 vat_json_object_add_uint(node, "extended_limit", ntohl(mp->extended_limit));
2270 vat_json_object_add_uint(node, "extended_bucket",
2271 ntohl(mp->extended_bucket));
2272 vat_json_object_add_uint(node, "last_update_time",
2273 ntohl(mp->last_update_time));
2275 vec_free(rate_type_str);
2276 vec_free(round_type_str);
2281 #define vl_api_vnet_ip4_fib_counters_t_endian vl_noop_handler
2282 #define vl_api_vnet_ip4_fib_counters_t_print vl_noop_handler
2283 #define vl_api_vnet_ip6_fib_counters_t_endian vl_noop_handler
2284 #define vl_api_vnet_ip6_fib_counters_t_print vl_noop_handler
2287 * Generate boilerplate reply handlers, which
2288 * dig the return value out of the xxx_reply_t API message,
2289 * stick it into vam->retval, and set vam->result_ready
2291 * Could also do this by pointing N message decode slots at
2292 * a single function, but that could break in subtle ways.
2295 #define foreach_standard_reply_retval_handler \
2296 _(sw_interface_set_flags_reply) \
2297 _(sw_interface_add_del_address_reply) \
2298 _(sw_interface_set_table_reply) \
2299 _(sw_interface_set_vpath_reply) \
2300 _(sw_interface_set_l2_bridge_reply) \
2301 _(bridge_domain_add_del_reply) \
2302 _(sw_interface_set_l2_xconnect_reply) \
2303 _(l2fib_add_del_reply) \
2304 _(ip_add_del_route_reply) \
2305 _(proxy_arp_add_del_reply) \
2306 _(proxy_arp_intfc_enable_disable_reply) \
2307 _(mpls_add_del_encap_reply) \
2308 _(mpls_add_del_decap_reply) \
2309 _(mpls_ethernet_add_del_tunnel_2_reply) \
2310 _(sw_interface_set_unnumbered_reply) \
2311 _(ip_neighbor_add_del_reply) \
2312 _(reset_vrf_reply) \
2313 _(oam_add_del_reply) \
2314 _(reset_fib_reply) \
2315 _(dhcp_proxy_config_reply) \
2316 _(dhcp_proxy_config_2_reply) \
2317 _(dhcp_proxy_set_vss_reply) \
2318 _(dhcp_client_config_reply) \
2319 _(set_ip_flow_hash_reply) \
2320 _(sw_interface_ip6_enable_disable_reply) \
2321 _(sw_interface_ip6_set_link_local_address_reply) \
2322 _(sw_interface_ip6nd_ra_prefix_reply) \
2323 _(sw_interface_ip6nd_ra_config_reply) \
2324 _(set_arp_neighbor_limit_reply) \
2325 _(l2_patch_add_del_reply) \
2326 _(sr_tunnel_add_del_reply) \
2327 _(sr_policy_add_del_reply) \
2328 _(sr_multicast_map_add_del_reply) \
2329 _(classify_add_del_session_reply) \
2330 _(classify_set_interface_ip_table_reply) \
2331 _(classify_set_interface_l2_tables_reply) \
2332 _(l2tpv3_set_tunnel_cookies_reply) \
2333 _(l2tpv3_interface_enable_disable_reply) \
2334 _(l2tpv3_set_lookup_key_reply) \
2335 _(l2_fib_clear_table_reply) \
2336 _(l2_interface_efp_filter_reply) \
2337 _(l2_interface_vlan_tag_rewrite_reply) \
2338 _(modify_vhost_user_if_reply) \
2339 _(delete_vhost_user_if_reply) \
2340 _(want_ip4_arp_events_reply) \
2341 _(input_acl_set_interface_reply) \
2342 _(ipsec_spd_add_del_reply) \
2343 _(ipsec_interface_add_del_spd_reply) \
2344 _(ipsec_spd_add_del_entry_reply) \
2345 _(ipsec_sad_add_del_entry_reply) \
2346 _(ipsec_sa_set_key_reply) \
2347 _(ikev2_profile_add_del_reply) \
2348 _(ikev2_profile_set_auth_reply) \
2349 _(ikev2_profile_set_id_reply) \
2350 _(ikev2_profile_set_ts_reply) \
2351 _(ikev2_set_local_key_reply) \
2352 _(delete_loopback_reply) \
2353 _(bd_ip_mac_add_del_reply) \
2354 _(map_del_domain_reply) \
2355 _(map_add_del_rule_reply) \
2356 _(want_interface_events_reply) \
2357 _(want_stats_reply) \
2358 _(cop_interface_enable_disable_reply) \
2359 _(cop_whitelist_enable_disable_reply) \
2360 _(sw_interface_clear_stats_reply) \
2361 _(trace_profile_add_reply) \
2362 _(trace_profile_apply_reply) \
2363 _(trace_profile_del_reply) \
2364 _(lisp_add_del_locator_set_reply) \
2365 _(lisp_add_del_locator_reply) \
2366 _(lisp_add_del_local_eid_reply) \
2367 _(lisp_gpe_add_del_fwd_entry_reply) \
2368 _(lisp_add_del_map_resolver_reply) \
2369 _(lisp_gpe_enable_disable_reply) \
2370 _(lisp_gpe_add_del_iface_reply) \
2371 _(lisp_enable_disable_reply) \
2372 _(lisp_pitr_set_locator_set_reply) \
2373 _(vxlan_gpe_add_del_tunnel_reply) \
2374 _(af_packet_create_reply) \
2375 _(af_packet_delete_reply) \
2376 _(policer_add_del_reply) \
2377 _(netmap_create_reply) \
2378 _(netmap_delete_reply)
2381 static void vl_api_##n##_t_handler \
2382 (vl_api_##n##_t * mp) \
2384 vat_main_t * vam = &vat_main; \
2385 i32 retval = ntohl(mp->retval); \
2386 if (vam->async_mode) { \
2387 vam->async_errors += (retval < 0); \
2389 vam->retval = retval; \
2390 vam->result_ready = 1; \
2393 foreach_standard_reply_retval_handler;
2397 static void vl_api_##n##_t_handler_json \
2398 (vl_api_##n##_t * mp) \
2400 vat_main_t * vam = &vat_main; \
2401 vat_json_node_t node; \
2402 vat_json_init_object(&node); \
2403 vat_json_object_add_int(&node, "retval", ntohl(mp->retval)); \
2404 vat_json_print(vam->ofp, &node); \
2405 vam->retval = ntohl(mp->retval); \
2406 vam->result_ready = 1; \
2408 foreach_standard_reply_retval_handler;
2412 * Table of message reply handlers, must include boilerplate handlers
2416 #define foreach_vpe_api_reply_msg \
2417 _(CREATE_LOOPBACK_REPLY, create_loopback_reply) \
2418 _(SW_INTERFACE_DETAILS, sw_interface_details) \
2419 _(SW_INTERFACE_SET_FLAGS, sw_interface_set_flags) \
2420 _(SW_INTERFACE_SET_FLAGS_REPLY, sw_interface_set_flags_reply) \
2421 _(CONTROL_PING_REPLY, control_ping_reply) \
2422 _(CLI_REPLY, cli_reply) \
2423 _(SW_INTERFACE_ADD_DEL_ADDRESS_REPLY, \
2424 sw_interface_add_del_address_reply) \
2425 _(SW_INTERFACE_SET_TABLE_REPLY, sw_interface_set_table_reply) \
2426 _(SW_INTERFACE_SET_VPATH_REPLY, sw_interface_set_vpath_reply) \
2427 _(SW_INTERFACE_SET_L2_XCONNECT_REPLY, \
2428 sw_interface_set_l2_xconnect_reply) \
2429 _(SW_INTERFACE_SET_L2_BRIDGE_REPLY, \
2430 sw_interface_set_l2_bridge_reply) \
2431 _(BRIDGE_DOMAIN_ADD_DEL_REPLY, bridge_domain_add_del_reply) \
2432 _(BRIDGE_DOMAIN_DETAILS, bridge_domain_details) \
2433 _(BRIDGE_DOMAIN_SW_IF_DETAILS, bridge_domain_sw_if_details) \
2434 _(L2FIB_ADD_DEL_REPLY, l2fib_add_del_reply) \
2435 _(L2_FLAGS_REPLY, l2_flags_reply) \
2436 _(BRIDGE_FLAGS_REPLY, bridge_flags_reply) \
2437 _(TAP_CONNECT_REPLY, tap_connect_reply) \
2438 _(TAP_MODIFY_REPLY, tap_modify_reply) \
2439 _(TAP_DELETE_REPLY, tap_delete_reply) \
2440 _(SW_INTERFACE_TAP_DETAILS, sw_interface_tap_details) \
2441 _(IP_ADD_DEL_ROUTE_REPLY, ip_add_del_route_reply) \
2442 _(PROXY_ARP_ADD_DEL_REPLY, proxy_arp_add_del_reply) \
2443 _(PROXY_ARP_INTFC_ENABLE_DISABLE_REPLY, \
2444 proxy_arp_intfc_enable_disable_reply) \
2445 _(MPLS_ADD_DEL_ENCAP_REPLY, mpls_add_del_encap_reply) \
2446 _(MPLS_ADD_DEL_DECAP_REPLY, mpls_add_del_decap_reply) \
2447 _(MPLS_GRE_ADD_DEL_TUNNEL_REPLY, mpls_gre_add_del_tunnel_reply) \
2448 _(MPLS_ETHERNET_ADD_DEL_TUNNEL_REPLY, \
2449 mpls_ethernet_add_del_tunnel_reply) \
2450 _(MPLS_ETHERNET_ADD_DEL_TUNNEL_2_REPLY, \
2451 mpls_ethernet_add_del_tunnel_2_reply) \
2452 _(SW_INTERFACE_SET_UNNUMBERED_REPLY, \
2453 sw_interface_set_unnumbered_reply) \
2454 _(IP_NEIGHBOR_ADD_DEL_REPLY, ip_neighbor_add_del_reply) \
2455 _(RESET_VRF_REPLY, reset_vrf_reply) \
2456 _(CREATE_VLAN_SUBIF_REPLY, create_vlan_subif_reply) \
2457 _(CREATE_SUBIF_REPLY, create_subif_reply) \
2458 _(OAM_ADD_DEL_REPLY, oam_add_del_reply) \
2459 _(RESET_FIB_REPLY, reset_fib_reply) \
2460 _(DHCP_PROXY_CONFIG_REPLY, dhcp_proxy_config_reply) \
2461 _(DHCP_PROXY_CONFIG_2_REPLY, dhcp_proxy_config_2_reply) \
2462 _(DHCP_PROXY_SET_VSS_REPLY, dhcp_proxy_set_vss_reply) \
2463 _(DHCP_CLIENT_CONFIG_REPLY, dhcp_client_config_reply) \
2464 _(SET_IP_FLOW_HASH_REPLY, set_ip_flow_hash_reply) \
2465 _(SW_INTERFACE_IP6_ENABLE_DISABLE_REPLY, \
2466 sw_interface_ip6_enable_disable_reply) \
2467 _(SW_INTERFACE_IP6_SET_LINK_LOCAL_ADDRESS_REPLY, \
2468 sw_interface_ip6_set_link_local_address_reply) \
2469 _(SW_INTERFACE_IP6ND_RA_PREFIX_REPLY, \
2470 sw_interface_ip6nd_ra_prefix_reply) \
2471 _(SW_INTERFACE_IP6ND_RA_CONFIG_REPLY, \
2472 sw_interface_ip6nd_ra_config_reply) \
2473 _(SET_ARP_NEIGHBOR_LIMIT_REPLY, set_arp_neighbor_limit_reply) \
2474 _(L2_PATCH_ADD_DEL_REPLY, l2_patch_add_del_reply) \
2475 _(SR_TUNNEL_ADD_DEL_REPLY, sr_tunnel_add_del_reply) \
2476 _(SR_POLICY_ADD_DEL_REPLY, sr_policy_add_del_reply) \
2477 _(SR_MULTICAST_MAP_ADD_DEL_REPLY, sr_multicast_map_add_del_reply) \
2478 _(CLASSIFY_ADD_DEL_TABLE_REPLY, classify_add_del_table_reply) \
2479 _(CLASSIFY_ADD_DEL_SESSION_REPLY, classify_add_del_session_reply) \
2480 _(CLASSIFY_SET_INTERFACE_IP_TABLE_REPLY, \
2481 classify_set_interface_ip_table_reply) \
2482 _(CLASSIFY_SET_INTERFACE_L2_TABLES_REPLY, \
2483 classify_set_interface_l2_tables_reply) \
2484 _(GET_NODE_INDEX_REPLY, get_node_index_reply) \
2485 _(ADD_NODE_NEXT_REPLY, add_node_next_reply) \
2486 _(L2TPV3_CREATE_TUNNEL_REPLY, l2tpv3_create_tunnel_reply) \
2487 _(L2TPV3_SET_TUNNEL_COOKIES_REPLY, l2tpv3_set_tunnel_cookies_reply) \
2488 _(L2TPV3_INTERFACE_ENABLE_DISABLE_REPLY, \
2489 l2tpv3_interface_enable_disable_reply) \
2490 _(L2TPV3_SET_LOOKUP_KEY_REPLY, l2tpv3_set_lookup_key_reply) \
2491 _(SW_IF_L2TPV3_TUNNEL_DETAILS, sw_if_l2tpv3_tunnel_details) \
2492 _(VXLAN_ADD_DEL_TUNNEL_REPLY, vxlan_add_del_tunnel_reply) \
2493 _(VXLAN_TUNNEL_DETAILS, vxlan_tunnel_details) \
2494 _(GRE_ADD_DEL_TUNNEL_REPLY, gre_add_del_tunnel_reply) \
2495 _(GRE_TUNNEL_DETAILS, gre_tunnel_details) \
2496 _(L2_FIB_CLEAR_TABLE_REPLY, l2_fib_clear_table_reply) \
2497 _(L2_INTERFACE_EFP_FILTER_REPLY, l2_interface_efp_filter_reply) \
2498 _(L2_INTERFACE_VLAN_TAG_REWRITE_REPLY, l2_interface_vlan_tag_rewrite_reply) \
2499 _(SW_INTERFACE_VHOST_USER_DETAILS, sw_interface_vhost_user_details) \
2500 _(CREATE_VHOST_USER_IF_REPLY, create_vhost_user_if_reply) \
2501 _(MODIFY_VHOST_USER_IF_REPLY, modify_vhost_user_if_reply) \
2502 _(DELETE_VHOST_USER_IF_REPLY, delete_vhost_user_if_reply) \
2503 _(SHOW_VERSION_REPLY, show_version_reply) \
2504 _(L2_FIB_TABLE_ENTRY, l2_fib_table_entry) \
2505 _(VXLAN_GPE_ADD_DEL_TUNNEL_REPLY, vxlan_gpe_add_del_tunnel_reply) \
2506 _(VXLAN_GPE_TUNNEL_DETAILS, vxlan_gpe_tunnel_details) \
2507 _(INTERFACE_NAME_RENUMBER_REPLY, interface_name_renumber_reply) \
2508 _(WANT_IP4_ARP_EVENTS_REPLY, want_ip4_arp_events_reply) \
2509 _(IP4_ARP_EVENT, ip4_arp_event) \
2510 _(INPUT_ACL_SET_INTERFACE_REPLY, input_acl_set_interface_reply) \
2511 _(IP_ADDRESS_DETAILS, ip_address_details) \
2512 _(IP_DETAILS, ip_details) \
2513 _(IPSEC_SPD_ADD_DEL_REPLY, ipsec_spd_add_del_reply) \
2514 _(IPSEC_INTERFACE_ADD_DEL_SPD_REPLY, ipsec_interface_add_del_spd_reply) \
2515 _(IPSEC_SPD_ADD_DEL_ENTRY_REPLY, ipsec_spd_add_del_entry_reply) \
2516 _(IPSEC_SAD_ADD_DEL_ENTRY_REPLY, ipsec_sad_add_del_entry_reply) \
2517 _(IPSEC_SA_SET_KEY_REPLY, ipsec_sa_set_key_reply) \
2518 _(IKEV2_PROFILE_ADD_DEL_REPLY, ikev2_profile_add_del_reply) \
2519 _(IKEV2_PROFILE_SET_AUTH_REPLY, ikev2_profile_set_auth_reply) \
2520 _(IKEV2_PROFILE_SET_ID_REPLY, ikev2_profile_set_id_reply) \
2521 _(IKEV2_PROFILE_SET_TS_REPLY, ikev2_profile_set_ts_reply) \
2522 _(IKEV2_SET_LOCAL_KEY_REPLY, ikev2_set_local_key_reply) \
2523 _(DELETE_LOOPBACK_REPLY, delete_loopback_reply) \
2524 _(BD_IP_MAC_ADD_DEL_REPLY, bd_ip_mac_add_del_reply) \
2525 _(DHCP_COMPL_EVENT, dhcp_compl_event) \
2526 _(VNET_INTERFACE_COUNTERS, vnet_interface_counters) \
2527 _(VNET_IP4_FIB_COUNTERS, vnet_ip4_fib_counters) \
2528 _(VNET_IP6_FIB_COUNTERS, vnet_ip6_fib_counters) \
2529 _(MAP_ADD_DOMAIN_REPLY, map_add_domain_reply) \
2530 _(MAP_DEL_DOMAIN_REPLY, map_del_domain_reply) \
2531 _(MAP_ADD_DEL_RULE_REPLY, map_add_del_rule_reply) \
2532 _(MAP_DOMAIN_DETAILS, map_domain_details) \
2533 _(MAP_RULE_DETAILS, map_rule_details) \
2534 _(WANT_INTERFACE_EVENTS_REPLY, want_interface_events_reply) \
2535 _(WANT_STATS_REPLY, want_stats_reply) \
2536 _(GET_FIRST_MSG_ID_REPLY, get_first_msg_id_reply) \
2537 _(COP_INTERFACE_ENABLE_DISABLE_REPLY, cop_interface_enable_disable_reply) \
2538 _(COP_WHITELIST_ENABLE_DISABLE_REPLY, cop_whitelist_enable_disable_reply) \
2539 _(GET_NODE_GRAPH_REPLY, get_node_graph_reply) \
2540 _(SW_INTERFACE_CLEAR_STATS_REPLY, sw_interface_clear_stats_reply) \
2541 _(TRACE_PROFILE_ADD_REPLY, trace_profile_add_reply) \
2542 _(TRACE_PROFILE_APPLY_REPLY, trace_profile_apply_reply) \
2543 _(TRACE_PROFILE_DEL_REPLY, trace_profile_del_reply) \
2544 _(LISP_ADD_DEL_LOCATOR_SET_REPLY, lisp_add_del_locator_set_reply) \
2545 _(LISP_ADD_DEL_LOCATOR_REPLY, lisp_add_del_locator_reply) \
2546 _(LISP_ADD_DEL_LOCAL_EID_REPLY, lisp_add_del_local_eid_reply) \
2547 _(LISP_GPE_ADD_DEL_FWD_ENTRY_REPLY, lisp_gpe_add_del_fwd_entry_reply) \
2548 _(LISP_ADD_DEL_MAP_RESOLVER_REPLY, lisp_add_del_map_resolver_reply) \
2549 _(LISP_GPE_ENABLE_DISABLE_REPLY, lisp_gpe_enable_disable_reply) \
2550 _(LISP_ENABLE_DISABLE_REPLY, lisp_enable_disable_reply) \
2551 _(LISP_PITR_SET_LOCATOR_SET_REPLY, lisp_pitr_set_locator_set_reply) \
2552 _(LISP_GPE_ADD_DEL_IFACE_REPLY, lisp_gpe_add_del_iface_reply) \
2553 _(LISP_LOCATOR_SET_DETAILS, lisp_locator_set_details) \
2554 _(LISP_LOCAL_EID_TABLE_DETAILS, lisp_local_eid_table_details) \
2555 _(LISP_GPE_TUNNEL_DETAILS, lisp_gpe_tunnel_details) \
2556 _(LISP_MAP_RESOLVER_DETAILS, lisp_map_resolver_details) \
2557 _(LISP_ENABLE_DISABLE_STATUS_DETAILS, \
2558 lisp_enable_disable_status_details) \
2559 _(AF_PACKET_CREATE_REPLY, af_packet_create_reply) \
2560 _(AF_PACKET_DELETE_REPLY, af_packet_delete_reply) \
2561 _(POLICER_ADD_DEL_REPLY, policer_add_del_reply) \
2562 _(POLICER_DETAILS, policer_details) \
2563 _(NETMAP_CREATE_REPLY, netmap_create_reply) \
2564 _(NETMAP_DELETE_REPLY, netmap_delete_reply)
2566 /* M: construct, but don't yet send a message */
2570 vam->result_ready = 0; \
2571 mp = vl_msg_api_alloc(sizeof(*mp)); \
2572 memset (mp, 0, sizeof (*mp)); \
2573 mp->_vl_msg_id = ntohs (VL_API_##T); \
2574 mp->client_index = vam->my_client_index; \
2579 vam->result_ready = 0; \
2580 mp = vl_msg_api_alloc(sizeof(*mp)+(n)); \
2581 memset (mp, 0, sizeof (*mp)); \
2582 mp->_vl_msg_id = ntohs (VL_API_##T); \
2583 mp->client_index = vam->my_client_index; \
2587 /* S: send a message */
2588 #define S (vl_msg_api_send_shmem (vam->vl_input_queue, (u8 *)&mp))
2590 /* W: wait for results, with timeout */
2593 timeout = vat_time_now (vam) + 1.0; \
2595 while (vat_time_now (vam) < timeout) { \
2596 if (vam->result_ready == 1) { \
2597 return (vam->retval); \
2609 #define STR_VTR_OP_CASE(op) \
2610 case L2_VTR_ ## op: \
2613 static const char *str_vtr_op(u32 vtr_op)
2616 STR_VTR_OP_CASE(DISABLED);
2617 STR_VTR_OP_CASE(PUSH_1);
2618 STR_VTR_OP_CASE(PUSH_2);
2619 STR_VTR_OP_CASE(POP_1);
2620 STR_VTR_OP_CASE(POP_2);
2621 STR_VTR_OP_CASE(TRANSLATE_1_1);
2622 STR_VTR_OP_CASE(TRANSLATE_1_2);
2623 STR_VTR_OP_CASE(TRANSLATE_2_1);
2624 STR_VTR_OP_CASE(TRANSLATE_2_2);
2630 static int dump_sub_interface_table (vat_main_t * vam)
2632 const sw_interface_subif_t * sub = NULL;
2634 if (vam->json_output) {
2635 clib_warning ("JSON output supported only for VPE API calls and dump_stats_table");
2640 "%-30s%-12s%-11s%-7s%-5s%-9s%-9s%-6s%-8s%-10s%-10s\n",
2641 "Interface", "sw_if_index",
2642 "sub id", "dot1ad", "tags", "outer id",
2643 "inner id", "exact", "default",
2644 "outer any", "inner any");
2646 vec_foreach (sub, vam->sw_if_subif_table) {
2648 "%-30s%-12d%-11d%-7s%-5d%-9d%-9d%-6d%-8d%-10d%-10d\n",
2649 sub->interface_name,
2651 sub->sub_id, sub->sub_dot1ad ? "dot1ad" : "dot1q",
2652 sub->sub_number_of_tags, sub->sub_outer_vlan_id,
2653 sub->sub_inner_vlan_id, sub->sub_exact_match, sub->sub_default,
2654 sub->sub_outer_vlan_id_any, sub->sub_inner_vlan_id_any);
2655 if (sub->vtr_op != L2_VTR_DISABLED) {
2657 " vlan-tag-rewrite - op: %-14s [ dot1q: %d "
2658 "tag1: %d tag2: %d ]\n",
2659 str_vtr_op(sub->vtr_op), sub->vtr_push_dot1q,
2660 sub->vtr_tag1, sub->vtr_tag2);
2667 static int name_sort_cmp (void * a1, void * a2)
2669 name_sort_t * n1 = a1;
2670 name_sort_t * n2 = a2;
2672 return strcmp ((char *)n1->name, (char *)n2->name);
2675 static int dump_interface_table (vat_main_t * vam)
2678 name_sort_t * nses = 0, * ns;
2680 if (vam->json_output) {
2681 clib_warning ("JSON output supported only for VPE API calls and dump_stats_table");
2685 hash_foreach_pair (p, vam->sw_if_index_by_interface_name,
2687 vec_add2 (nses, ns, 1);
2688 ns->name = (u8 *)(p->key);
2689 ns->value = (u32) p->value[0];
2692 vec_sort_with_function (nses, name_sort_cmp);
2694 fformat (vam->ofp, "%-25s%-15s\n", "Interface", "sw_if_index");
2695 vec_foreach (ns, nses) {
2696 fformat (vam->ofp, "%-25s%-15d\n", ns->name, ns->value);
2702 static int dump_ip_table (vat_main_t * vam, int is_ipv6)
2704 const ip_details_t * det = NULL;
2705 const ip_address_details_t * address = NULL;
2716 vec_foreach (det, vam->ip_details_by_sw_if_index[is_ipv6]) {
2718 if (!det->present) {
2726 "Address", "Prefix length");
2730 vec_foreach (address, det->addr) {
2733 is_ipv6 ? format_ip6_address : format_ip4_address,
2735 address->prefix_length);
2742 static int dump_ipv4_table (vat_main_t * vam)
2744 if (vam->json_output) {
2745 clib_warning ("JSON output supported only for VPE API calls and dump_stats_table");
2749 return dump_ip_table (vam, 0);
2752 static int dump_ipv6_table (vat_main_t * vam)
2754 if (vam->json_output) {
2755 clib_warning ("JSON output supported only for VPE API calls and dump_stats_table");
2759 return dump_ip_table (vam, 1);
2762 static char* counter_type_to_str (u8 counter_type, u8 is_combined)
2765 switch(counter_type) {
2766 case VNET_INTERFACE_COUNTER_DROP:
2768 case VNET_INTERFACE_COUNTER_PUNT:
2770 case VNET_INTERFACE_COUNTER_IP4:
2772 case VNET_INTERFACE_COUNTER_IP6:
2774 case VNET_INTERFACE_COUNTER_RX_NO_BUF:
2776 case VNET_INTERFACE_COUNTER_RX_MISS:
2778 case VNET_INTERFACE_COUNTER_RX_ERROR:
2780 case VNET_INTERFACE_COUNTER_TX_ERROR:
2783 return "INVALID-COUNTER-TYPE";
2786 switch(counter_type) {
2787 case VNET_INTERFACE_COUNTER_RX:
2789 case VNET_INTERFACE_COUNTER_TX:
2792 return "INVALID-COUNTER-TYPE";
2797 static int dump_stats_table (vat_main_t * vam)
2799 vat_json_node_t node;
2800 vat_json_node_t *msg_array;
2801 vat_json_node_t *msg;
2802 vat_json_node_t *counter_array;
2803 vat_json_node_t *counter;
2804 interface_counter_t c;
2806 ip4_fib_counter_t *c4;
2807 ip6_fib_counter_t *c6;
2810 if (!vam->json_output) {
2811 clib_warning ("dump_stats_table supported only in JSON format");
2815 vat_json_init_object(&node);
2817 /* interface counters */
2818 msg_array = vat_json_object_add(&node, "interface_counters");
2819 vat_json_init_array(msg_array);
2820 for (i = 0; i < vec_len(vam->simple_interface_counters); i++) {
2821 msg = vat_json_array_add(msg_array);
2822 vat_json_init_object(msg);
2823 vat_json_object_add_string_copy(msg, "vnet_counter_type",
2824 (u8*)counter_type_to_str(i, 0));
2825 vat_json_object_add_int(msg, "is_combined", 0);
2826 counter_array = vat_json_object_add(msg, "data");
2827 vat_json_init_array(counter_array);
2828 for (j = 0; j < vec_len(vam->simple_interface_counters[i]); j++) {
2829 packets = vam->simple_interface_counters[i][j];
2830 vat_json_array_add_uint(counter_array, packets);
2833 for (i = 0; i < vec_len(vam->combined_interface_counters); i++) {
2834 msg = vat_json_array_add(msg_array);
2835 vat_json_init_object(msg);
2836 vat_json_object_add_string_copy(msg, "vnet_counter_type",
2837 (u8*)counter_type_to_str(i, 1));
2838 vat_json_object_add_int(msg, "is_combined", 1);
2839 counter_array = vat_json_object_add(msg, "data");
2840 vat_json_init_array(counter_array);
2841 for (j = 0; j < vec_len(vam->combined_interface_counters[i]); j++) {
2842 c = vam->combined_interface_counters[i][j];
2843 counter = vat_json_array_add(counter_array);
2844 vat_json_init_object(counter);
2845 vat_json_object_add_uint(counter, "packets", c.packets);
2846 vat_json_object_add_uint(counter, "bytes", c.bytes);
2850 /* ip4 fib counters */
2851 msg_array = vat_json_object_add(&node, "ip4_fib_counters");
2852 vat_json_init_array(msg_array);
2853 for (i = 0; i < vec_len(vam->ip4_fib_counters); i++) {
2854 msg = vat_json_array_add(msg_array);
2855 vat_json_init_object(msg);
2856 vat_json_object_add_uint(msg, "vrf_id", vam->ip4_fib_counters_vrf_id_by_index[i]);
2857 counter_array = vat_json_object_add(msg, "c");
2858 vat_json_init_array(counter_array);
2859 for (j = 0; j < vec_len(vam->ip4_fib_counters[i]); j++) {
2860 counter = vat_json_array_add(counter_array);
2861 vat_json_init_object(counter);
2862 c4 = &vam->ip4_fib_counters[i][j];
2863 vat_json_object_add_ip4(counter, "address", c4->address);
2864 vat_json_object_add_uint(counter, "address_length", c4->address_length);
2865 vat_json_object_add_uint(counter, "packets", c4->packets);
2866 vat_json_object_add_uint(counter, "bytes", c4->bytes);
2870 /* ip6 fib counters */
2871 msg_array = vat_json_object_add(&node, "ip6_fib_counters");
2872 vat_json_init_array(msg_array);
2873 for (i = 0; i < vec_len(vam->ip6_fib_counters); i++) {
2874 msg = vat_json_array_add(msg_array);
2875 vat_json_init_object(msg);
2876 vat_json_object_add_uint(msg, "vrf_id", vam->ip6_fib_counters_vrf_id_by_index[i]);
2877 counter_array = vat_json_object_add(msg, "c");
2878 vat_json_init_array(counter_array);
2879 for (j = 0; j < vec_len(vam->ip6_fib_counters[i]); j++) {
2880 counter = vat_json_array_add(counter_array);
2881 vat_json_init_object(counter);
2882 c6 = &vam->ip6_fib_counters[i][j];
2883 vat_json_object_add_ip6(counter, "address", c6->address);
2884 vat_json_object_add_uint(counter, "address_length", c6->address_length);
2885 vat_json_object_add_uint(counter, "packets", c6->packets);
2886 vat_json_object_add_uint(counter, "bytes", c6->bytes);
2890 vat_json_print(vam->ofp, &node);
2891 vat_json_free(&node);
2896 int exec (vat_main_t * vam)
2898 api_main_t * am = &api_main;
2899 vl_api_cli_request_t *mp;
2903 unformat_input_t * i = vam->input;
2905 if (vec_len(i->buffer) == 0)
2908 if (vam->exec_mode == 0 && unformat (i, "mode")) {
2912 if (vam->exec_mode == 1 &&
2913 (unformat (i, "exit") || unformat (i, "quit"))) {
2919 M(CLI_REQUEST, cli_request);
2922 * Copy cmd into shared memory.
2923 * In order for the CLI command to work, it
2924 * must be a vector ending in \n, not a C-string ending
2927 pthread_mutex_lock (&am->vlib_rp->mutex);
2928 oldheap = svm_push_data_heap (am->vlib_rp);
2930 vec_validate (cmd, vec_len(vam->input->buffer)-1);
2931 clib_memcpy (cmd, vam->input->buffer, vec_len(vam->input->buffer));
2933 svm_pop_heap (oldheap);
2934 pthread_mutex_unlock (&am->vlib_rp->mutex);
2936 mp->cmd_in_shmem = (u64) cmd;
2938 timeout = vat_time_now (vam) + 10.0;
2940 while (vat_time_now (vam) < timeout) {
2941 if (vam->result_ready == 1) {
2943 if (vam->shmem_result != NULL)
2944 fformat (vam->ofp, "%s", vam->shmem_result);
2945 pthread_mutex_lock (&am->vlib_rp->mutex);
2946 oldheap = svm_push_data_heap (am->vlib_rp);
2948 free_me = (u8 *)vam->shmem_result;
2951 svm_pop_heap (oldheap);
2952 pthread_mutex_unlock (&am->vlib_rp->mutex);
2959 static int api_create_loopback (vat_main_t * vam)
2961 unformat_input_t * i = vam->input;
2962 vl_api_create_loopback_t *mp;
2967 memset (mac_address, 0, sizeof (mac_address));
2969 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
2971 if (unformat (i, "mac %U", unformat_ethernet_address, mac_address))
2977 /* Construct the API message */
2978 M(CREATE_LOOPBACK, create_loopback);
2980 clib_memcpy (mp->mac_address, mac_address, sizeof (mac_address));
2985 static int api_delete_loopback (vat_main_t * vam)
2987 unformat_input_t * i = vam->input;
2988 vl_api_delete_loopback_t *mp;
2990 u32 sw_if_index = ~0;
2992 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
2994 if (unformat (i, "sw_if_index %d", &sw_if_index))
3000 if (sw_if_index == ~0)
3002 errmsg ("missing sw_if_index\n");
3006 /* Construct the API message */
3007 M(DELETE_LOOPBACK, delete_loopback);
3008 mp->sw_if_index = ntohl (sw_if_index);
3013 static int api_want_stats (vat_main_t * vam)
3015 unformat_input_t * i = vam->input;
3016 vl_api_want_stats_t * mp;
3020 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
3022 if (unformat (i, "enable"))
3024 else if (unformat (i, "disable"))
3032 errmsg ("missing enable|disable\n");
3036 M(WANT_STATS, want_stats);
3037 mp->enable_disable = enable;
3042 static int api_want_interface_events (vat_main_t * vam)
3044 unformat_input_t * i = vam->input;
3045 vl_api_want_interface_events_t * mp;
3049 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
3051 if (unformat (i, "enable"))
3053 else if (unformat (i, "disable"))
3061 errmsg ("missing enable|disable\n");
3065 M(WANT_INTERFACE_EVENTS, want_interface_events);
3066 mp->enable_disable = enable;
3068 vam->interface_event_display = enable;
3074 /* Note: non-static, called once to set up the initial intfc table */
3075 int api_sw_interface_dump (vat_main_t * vam)
3077 vl_api_sw_interface_dump_t *mp;
3080 name_sort_t * nses = 0, * ns;
3081 sw_interface_subif_t * sub = NULL;
3083 /* Toss the old name table */
3084 hash_foreach_pair (p, vam->sw_if_index_by_interface_name,
3086 vec_add2 (nses, ns, 1);
3087 ns->name = (u8 *)(p->key);
3088 ns->value = (u32) p->value[0];
3091 hash_free (vam->sw_if_index_by_interface_name);
3093 vec_foreach (ns, nses)
3094 vec_free (ns->name);
3098 vec_foreach (sub, vam->sw_if_subif_table) {
3099 vec_free (sub->interface_name);
3101 vec_free (vam->sw_if_subif_table);
3103 /* recreate the interface name hash table */
3104 vam->sw_if_index_by_interface_name
3105 = hash_create_string (0, sizeof(uword));
3107 /* Get list of ethernets */
3108 M(SW_INTERFACE_DUMP, sw_interface_dump);
3109 mp->name_filter_valid = 1;
3110 strncpy ((char *) mp->name_filter, "Ether", sizeof(mp->name_filter)-1);
3113 /* and local / loopback interfaces */
3114 M(SW_INTERFACE_DUMP, sw_interface_dump);
3115 mp->name_filter_valid = 1;
3116 strncpy ((char *) mp->name_filter, "lo", sizeof(mp->name_filter)-1);
3119 /* and vxlan tunnel interfaces */
3120 M(SW_INTERFACE_DUMP, sw_interface_dump);
3121 mp->name_filter_valid = 1;
3122 strncpy ((char *) mp->name_filter, "vxlan", sizeof(mp->name_filter)-1);
3125 /* and host (af_packet) interfaces */
3126 M(SW_INTERFACE_DUMP, sw_interface_dump);
3127 mp->name_filter_valid = 1;
3128 strncpy ((char *) mp->name_filter, "host", sizeof(mp->name_filter)-1);
3131 /* and l2tpv3 tunnel interfaces */
3132 M(SW_INTERFACE_DUMP, sw_interface_dump);
3133 mp->name_filter_valid = 1;
3134 strncpy ((char *) mp->name_filter, "l2tpv3_tunnel", sizeof(mp->name_filter)-1);
3137 /* and GRE tunnel interfaces */
3138 M(SW_INTERFACE_DUMP, sw_interface_dump);
3139 mp->name_filter_valid = 1;
3140 strncpy ((char *) mp->name_filter, "gre", sizeof(mp->name_filter)-1);
3143 /* Use a control ping for synchronization */
3145 vl_api_control_ping_t * mp;
3146 M(CONTROL_PING, control_ping);
3152 static int api_sw_interface_set_flags (vat_main_t * vam)
3154 unformat_input_t * i = vam->input;
3155 vl_api_sw_interface_set_flags_t *mp;
3158 u8 sw_if_index_set = 0;
3159 u8 admin_up = 0, link_up = 0;
3161 /* Parse args required to build the message */
3162 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
3163 if (unformat (i, "admin-up"))
3165 else if (unformat (i, "admin-down"))
3167 else if (unformat (i, "link-up"))
3169 else if (unformat (i, "link-down"))
3171 else if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
3172 sw_if_index_set = 1;
3173 else if (unformat (i, "sw_if_index %d", &sw_if_index))
3174 sw_if_index_set = 1;
3179 if (sw_if_index_set == 0) {
3180 errmsg ("missing interface name or sw_if_index\n");
3184 /* Construct the API message */
3185 M(SW_INTERFACE_SET_FLAGS, sw_interface_set_flags);
3186 mp->sw_if_index = ntohl (sw_if_index);
3187 mp->admin_up_down = admin_up;
3188 mp->link_up_down = link_up;
3193 /* Wait for a reply, return the good/bad news... */
3197 static int api_sw_interface_clear_stats (vat_main_t * vam)
3199 unformat_input_t * i = vam->input;
3200 vl_api_sw_interface_clear_stats_t *mp;
3203 u8 sw_if_index_set = 0;
3205 /* Parse args required to build the message */
3206 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
3207 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
3208 sw_if_index_set = 1;
3209 else if (unformat (i, "sw_if_index %d", &sw_if_index))
3210 sw_if_index_set = 1;
3215 /* Construct the API message */
3216 M(SW_INTERFACE_CLEAR_STATS, sw_interface_clear_stats);
3218 if (sw_if_index_set == 1)
3219 mp->sw_if_index = ntohl (sw_if_index);
3221 mp->sw_if_index = ~0;
3226 /* Wait for a reply, return the good/bad news... */
3230 static int api_sw_interface_add_del_address (vat_main_t * vam)
3232 unformat_input_t * i = vam->input;
3233 vl_api_sw_interface_add_del_address_t *mp;
3236 u8 sw_if_index_set = 0;
3237 u8 is_add = 1, del_all = 0;
3238 u32 address_length = 0;
3239 u8 v4_address_set = 0;
3240 u8 v6_address_set = 0;
3241 ip4_address_t v4address;
3242 ip6_address_t v6address;
3244 /* Parse args required to build the message */
3245 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
3246 if (unformat (i, "del-all"))
3248 else if (unformat (i, "del"))
3250 else if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
3251 sw_if_index_set = 1;
3252 else if (unformat (i, "sw_if_index %d", &sw_if_index))
3253 sw_if_index_set = 1;
3254 else if (unformat (i, "%U/%d",
3255 unformat_ip4_address, &v4address,
3258 else if (unformat (i, "%U/%d",
3259 unformat_ip6_address, &v6address,
3266 if (sw_if_index_set == 0) {
3267 errmsg ("missing interface name or sw_if_index\n");
3270 if (v4_address_set && v6_address_set) {
3271 errmsg ("both v4 and v6 addresses set\n");
3274 if (!v4_address_set && !v6_address_set && !del_all) {
3275 errmsg ("no addresses set\n");
3279 /* Construct the API message */
3280 M(SW_INTERFACE_ADD_DEL_ADDRESS, sw_interface_add_del_address);
3282 mp->sw_if_index = ntohl (sw_if_index);
3283 mp->is_add = is_add;
3284 mp->del_all = del_all;
3285 if (v6_address_set) {
3287 clib_memcpy (mp->address, &v6address, sizeof (v6address));
3289 clib_memcpy (mp->address, &v4address, sizeof (v4address));
3291 mp->address_length = address_length;
3296 /* Wait for a reply, return good/bad news */
3300 static int api_sw_interface_set_table (vat_main_t * vam)
3302 unformat_input_t * i = vam->input;
3303 vl_api_sw_interface_set_table_t *mp;
3305 u32 sw_if_index, vrf_id = 0;
3306 u8 sw_if_index_set = 0;
3309 /* Parse args required to build the message */
3310 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
3311 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
3312 sw_if_index_set = 1;
3313 else if (unformat (i, "sw_if_index %d", &sw_if_index))
3314 sw_if_index_set = 1;
3315 else if (unformat (i, "vrf %d", &vrf_id))
3317 else if (unformat (i, "ipv6"))
3323 if (sw_if_index_set == 0) {
3324 errmsg ("missing interface name or sw_if_index\n");
3328 /* Construct the API message */
3329 M(SW_INTERFACE_SET_TABLE, sw_interface_set_table);
3331 mp->sw_if_index = ntohl (sw_if_index);
3332 mp->is_ipv6 = is_ipv6;
3333 mp->vrf_id = ntohl (vrf_id);
3338 /* Wait for a reply... */
3342 static int api_sw_interface_set_vpath (vat_main_t * vam)
3344 unformat_input_t * i = vam->input;
3345 vl_api_sw_interface_set_vpath_t *mp;
3347 u32 sw_if_index = 0;
3348 u8 sw_if_index_set = 0;
3351 /* Parse args required to build the message */
3352 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
3353 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, "enable"))
3359 else if (unformat (i, "disable"))
3365 if (sw_if_index_set == 0) {
3366 errmsg ("missing interface name or sw_if_index\n");
3370 /* Construct the API message */
3371 M(SW_INTERFACE_SET_VPATH, sw_interface_set_vpath);
3373 mp->sw_if_index = ntohl (sw_if_index);
3374 mp->enable = is_enable;
3379 /* Wait for a reply... */
3383 static int api_sw_interface_set_l2_xconnect (vat_main_t * vam)
3385 unformat_input_t * i = vam->input;
3386 vl_api_sw_interface_set_l2_xconnect_t *mp;
3389 u8 rx_sw_if_index_set = 0;
3391 u8 tx_sw_if_index_set = 0;
3394 /* Parse args required to build the message */
3395 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
3396 if (unformat (i, "rx_sw_if_index %d", &rx_sw_if_index))
3397 rx_sw_if_index_set = 1;
3398 else if (unformat (i, "tx_sw_if_index %d", &tx_sw_if_index))
3399 tx_sw_if_index_set = 1;
3400 else if (unformat (i, "rx")) {
3401 if (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
3402 if (unformat (i, "%U", unformat_sw_if_index, vam,
3404 rx_sw_if_index_set = 1;
3407 } else if (unformat (i, "tx")) {
3408 if (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
3409 if (unformat (i, "%U", unformat_sw_if_index, vam,
3411 tx_sw_if_index_set = 1;
3414 } else if (unformat (i, "enable"))
3416 else if (unformat (i, "disable"))
3422 if (rx_sw_if_index_set == 0) {
3423 errmsg ("missing rx interface name or rx_sw_if_index\n");
3427 if (enable && (tx_sw_if_index_set == 0)) {
3428 errmsg ("missing tx interface name or tx_sw_if_index\n");
3432 M(SW_INTERFACE_SET_L2_XCONNECT, sw_interface_set_l2_xconnect);
3434 mp->rx_sw_if_index = ntohl(rx_sw_if_index);
3435 mp->tx_sw_if_index = ntohl(tx_sw_if_index);
3436 mp->enable = enable;
3443 static int api_sw_interface_set_l2_bridge (vat_main_t * vam)
3445 unformat_input_t * i = vam->input;
3446 vl_api_sw_interface_set_l2_bridge_t *mp;
3449 u8 rx_sw_if_index_set = 0;
3456 /* Parse args required to build the message */
3457 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
3458 if (unformat (i, "sw_if_index %d", &rx_sw_if_index))
3459 rx_sw_if_index_set = 1;
3460 else if (unformat (i, "bd_id %d", &bd_id))
3462 else if (unformat (i, "%U", unformat_sw_if_index, vam,
3464 rx_sw_if_index_set = 1;
3465 else if (unformat (i, "shg %d", &shg))
3467 else if (unformat (i, "bvi"))
3469 else if (unformat (i, "enable"))
3471 else if (unformat (i, "disable"))
3477 if (rx_sw_if_index_set == 0) {
3478 errmsg ("missing rx interface name or sw_if_index\n");
3482 if (enable && (bd_id_set == 0)) {
3483 errmsg ("missing bridge domain\n");
3487 M(SW_INTERFACE_SET_L2_BRIDGE, sw_interface_set_l2_bridge);
3489 mp->rx_sw_if_index = ntohl(rx_sw_if_index);
3490 mp->bd_id = ntohl(bd_id);
3493 mp->enable = enable;
3500 static int api_bridge_domain_dump (vat_main_t * vam)
3502 unformat_input_t * i = vam->input;
3503 vl_api_bridge_domain_dump_t *mp;
3507 /* Parse args required to build the message */
3508 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
3509 if (unformat (i, "bd_id %d", &bd_id))
3515 M(BRIDGE_DOMAIN_DUMP, bridge_domain_dump);
3516 mp->bd_id = ntohl(bd_id);
3519 /* Use a control ping for synchronization */
3521 vl_api_control_ping_t * mp;
3522 M(CONTROL_PING, control_ping);
3531 static int api_bridge_domain_add_del (vat_main_t * vam)
3533 unformat_input_t * i = vam->input;
3534 vl_api_bridge_domain_add_del_t *mp;
3538 u32 flood = 1, forward = 1, learn = 1, uu_flood = 1, arp_term = 0;
3540 /* Parse args required to build the message */
3541 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
3542 if (unformat (i, "bd_id %d", &bd_id))
3544 else if (unformat (i, "flood %d", &flood))
3546 else if (unformat (i, "uu-flood %d", &uu_flood))
3548 else if (unformat (i, "forward %d", &forward))
3550 else if (unformat (i, "learn %d", &learn))
3552 else if (unformat (i, "arp-term %d", &arp_term))
3554 else if (unformat (i, "del")) {
3556 flood = uu_flood = forward = learn = 0;
3563 errmsg ("missing bridge domain\n");
3567 M(BRIDGE_DOMAIN_ADD_DEL, bridge_domain_add_del);
3569 mp->bd_id = ntohl(bd_id);
3571 mp->uu_flood = uu_flood;
3572 mp->forward = forward;
3574 mp->arp_term = arp_term;
3575 mp->is_add = is_add;
3582 static int api_l2fib_add_del (vat_main_t * vam)
3584 unformat_input_t * i = vam->input;
3585 vl_api_l2fib_add_del_t *mp;
3592 u8 sw_if_index_set = 0;
3597 /* Parse args required to build the message */
3598 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
3599 if (unformat (i, "mac %U", unformat_ethernet_address, &mac))
3601 else if (unformat (i, "bd_id %d", &bd_id))
3603 else if (unformat (i, "sw_if_index %d", &sw_if_index))
3604 sw_if_index_set = 1;
3605 else if (unformat (i, "sw_if")) {
3606 if (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
3607 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
3608 sw_if_index_set = 1;
3611 } else if (unformat (i, "static"))
3613 else if (unformat (i, "filter")) {
3616 } else if (unformat (i, "del"))
3623 errmsg ("missing mac address\n");
3627 if (bd_id_set == 0) {
3628 errmsg ("missing bridge domain\n");
3632 if (is_add && (sw_if_index_set == 0)) {
3633 errmsg ("missing interface name or sw_if_index\n");
3637 M(L2FIB_ADD_DEL, l2fib_add_del);
3640 mp->bd_id = ntohl(bd_id);
3641 mp->is_add = is_add;
3644 mp->sw_if_index = ntohl(sw_if_index);
3645 mp->static_mac = static_mac;
3646 mp->filter_mac = filter_mac;
3654 static int api_l2_flags (vat_main_t * vam)
3656 unformat_input_t * i = vam->input;
3657 vl_api_l2_flags_t *mp;
3660 u32 feature_bitmap = 0;
3661 u8 sw_if_index_set = 0;
3663 /* Parse args required to build the message */
3664 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
3665 if (unformat (i, "sw_if_index %d", &sw_if_index))
3666 sw_if_index_set = 1;
3667 else if (unformat (i, "sw_if")) {
3668 if (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
3669 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
3670 sw_if_index_set = 1;
3673 } else if (unformat (i, "learn"))
3674 feature_bitmap |= L2INPUT_FEAT_LEARN;
3675 else if (unformat (i, "forward"))
3676 feature_bitmap |= L2INPUT_FEAT_FWD;
3677 else if (unformat (i, "flood"))
3678 feature_bitmap |= L2INPUT_FEAT_FLOOD;
3679 else if (unformat (i, "uu-flood"))
3680 feature_bitmap |= L2INPUT_FEAT_UU_FLOOD;
3685 if (sw_if_index_set == 0) {
3686 errmsg ("missing interface name or sw_if_index\n");
3690 M(L2_FLAGS, l2_flags);
3692 mp->sw_if_index = ntohl(sw_if_index);
3693 mp->feature_bitmap = ntohl(feature_bitmap);
3700 static int api_bridge_flags (vat_main_t * vam)
3702 unformat_input_t * i = vam->input;
3703 vl_api_bridge_flags_t *mp;
3710 /* Parse args required to build the message */
3711 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
3712 if (unformat (i, "bd_id %d", &bd_id))
3714 else if (unformat (i, "learn"))
3716 else if (unformat (i, "forward"))
3718 else if (unformat (i, "flood"))
3720 else if (unformat (i, "uu-flood"))
3721 flags |= L2_UU_FLOOD;
3722 else if (unformat (i, "arp-term"))
3723 flags |= L2_ARP_TERM;
3724 else if (unformat (i, "off"))
3726 else if (unformat (i, "disable"))
3732 if (bd_id_set == 0) {
3733 errmsg ("missing bridge domain\n");
3737 M(BRIDGE_FLAGS, bridge_flags);
3739 mp->bd_id = ntohl(bd_id);
3740 mp->feature_bitmap = ntohl(flags);
3741 mp->is_set = is_set;
3748 static int api_bd_ip_mac_add_del (vat_main_t * vam)
3750 unformat_input_t * i = vam->input;
3751 vl_api_bd_ip_mac_add_del_t *mp;
3759 ip4_address_t v4addr;
3760 ip6_address_t v6addr;
3764 /* Parse args required to build the message */
3765 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
3766 if (unformat (i, "bd_id %d", &bd_id)) {
3768 } else if (unformat (i, "%U", unformat_ip4_address, &v4addr)) {
3770 } else if (unformat (i, "%U", unformat_ip6_address, &v6addr)) {
3773 } else if (unformat (i, "%U", unformat_ethernet_address, macaddr)) {
3775 } else if (unformat (i, "del"))
3781 if (bd_id_set == 0) {
3782 errmsg ("missing bridge domain\n");
3784 } else if (ip_set == 0) {
3785 errmsg ("missing IP address\n");
3787 } else if (mac_set == 0) {
3788 errmsg ("missing MAC address\n");
3792 M(BD_IP_MAC_ADD_DEL, bd_ip_mac_add_del);
3794 mp->bd_id = ntohl(bd_id);
3795 mp->is_ipv6 = is_ipv6;
3796 mp->is_add = is_add;
3798 clib_memcpy (mp->ip_address, &v6addr, sizeof (v6addr));
3799 else clib_memcpy (mp->ip_address, &v4addr, sizeof (v4addr));
3800 clib_memcpy (mp->mac_address, macaddr, 6);
3806 static int api_tap_connect (vat_main_t * vam)
3808 unformat_input_t * i = vam->input;
3809 vl_api_tap_connect_t *mp;
3816 memset (mac_address, 0, sizeof (mac_address));
3818 /* Parse args required to build the message */
3819 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
3820 if (unformat (i, "mac %U", unformat_ethernet_address, mac_address)) {
3823 else if (unformat (i, "random-mac"))
3825 else if (unformat (i, "tapname %s", &tap_name))
3831 if (name_set == 0) {
3832 errmsg ("missing tap name\n");
3835 if (vec_len (tap_name) > 63) {
3836 errmsg ("tap name too long\n");
3838 vec_add1 (tap_name, 0);
3840 /* Construct the API message */
3841 M(TAP_CONNECT, tap_connect);
3843 mp->use_random_mac = random_mac;
3844 clib_memcpy (mp->mac_address, mac_address, 6);
3845 clib_memcpy (mp->tap_name, tap_name, vec_len (tap_name));
3846 vec_free (tap_name);
3851 /* Wait for a reply... */
3855 static int api_tap_modify (vat_main_t * vam)
3857 unformat_input_t * i = vam->input;
3858 vl_api_tap_modify_t *mp;
3864 u32 sw_if_index = ~0;
3865 u8 sw_if_index_set = 0;
3867 memset (mac_address, 0, sizeof (mac_address));
3869 /* Parse args required to build the message */
3870 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
3871 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
3872 sw_if_index_set = 1;
3873 else if (unformat (i, "sw_if_index %d", &sw_if_index))
3874 sw_if_index_set = 1;
3875 else if (unformat (i, "mac %U", unformat_ethernet_address, mac_address)) {
3878 else if (unformat (i, "random-mac"))
3880 else if (unformat (i, "tapname %s", &tap_name))
3886 if (sw_if_index_set == 0) {
3887 errmsg ("missing vpp interface name");
3890 if (name_set == 0) {
3891 errmsg ("missing tap name\n");
3894 if (vec_len (tap_name) > 63) {
3895 errmsg ("tap name too long\n");
3897 vec_add1 (tap_name, 0);
3899 /* Construct the API message */
3900 M(TAP_MODIFY, tap_modify);
3902 mp->use_random_mac = random_mac;
3903 mp->sw_if_index = ntohl(sw_if_index);
3904 clib_memcpy (mp->mac_address, mac_address, 6);
3905 clib_memcpy (mp->tap_name, tap_name, vec_len (tap_name));
3906 vec_free (tap_name);
3911 /* Wait for a reply... */
3915 static int api_tap_delete (vat_main_t * vam)
3917 unformat_input_t * i = vam->input;
3918 vl_api_tap_delete_t *mp;
3920 u32 sw_if_index = ~0;
3921 u8 sw_if_index_set = 0;
3923 /* Parse args required to build the message */
3924 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
3925 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
3926 sw_if_index_set = 1;
3927 else if (unformat (i, "sw_if_index %d", &sw_if_index))
3928 sw_if_index_set = 1;
3933 if (sw_if_index_set == 0) {
3934 errmsg ("missing vpp interface name");
3938 /* Construct the API message */
3939 M(TAP_DELETE, tap_delete);
3941 mp->sw_if_index = ntohl(sw_if_index);
3946 /* Wait for a reply... */
3950 static int api_ip_add_del_route (vat_main_t * vam)
3952 unformat_input_t * i = vam->input;
3953 vl_api_ip_add_del_route_t *mp;
3955 u32 sw_if_index = 0, vrf_id = 0;
3956 u8 sw_if_index_set = 0;
3958 u8 is_local = 0, is_drop = 0;
3959 u8 create_vrf_if_needed = 0;
3961 u8 next_hop_weight = 1;
3963 u8 is_multipath = 0;
3965 u8 address_length_set = 0;
3966 u32 lookup_in_vrf = 0;
3967 u32 resolve_attempts = 0;
3968 u32 dst_address_length = 0;
3969 u8 next_hop_set = 0;
3970 ip4_address_t v4_dst_address, v4_next_hop_address;
3971 ip6_address_t v6_dst_address, v6_next_hop_address;
3975 u32 random_add_del = 0;
3976 u32 * random_vector = 0;
3977 uword * random_hash;
3978 u32 random_seed = 0xdeaddabe;
3979 u32 classify_table_index = ~0;
3982 /* Parse args required to build the message */
3983 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
3984 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
3985 sw_if_index_set = 1;
3986 else if (unformat (i, "sw_if_index %d", &sw_if_index))
3987 sw_if_index_set = 1;
3988 else if (unformat (i, "%U", unformat_ip4_address,
3993 else if (unformat (i, "%U", unformat_ip6_address, &v6_dst_address)) {
3997 else if (unformat (i, "/%d", &dst_address_length)) {
3998 address_length_set = 1;
4001 else if (is_ipv6 == 0 && unformat (i, "via %U", unformat_ip4_address,
4002 &v4_next_hop_address)) {
4005 else if (is_ipv6 == 1 && unformat (i, "via %U", unformat_ip6_address,
4006 &v6_next_hop_address)) {
4009 else if (unformat (i, "resolve-attempts %d", &resolve_attempts))
4011 else if (unformat (i, "weight %d", &next_hop_weight))
4013 else if (unformat (i, "drop")) {
4015 } else if (unformat (i, "local")) {
4017 } else if (unformat (i, "classify %d", &classify_table_index)) {
4019 } else if (unformat (i, "del"))
4021 else if (unformat (i, "add"))
4023 else if (unformat (i, "not-last"))
4025 else if (unformat (i, "multipath"))
4027 else if (unformat (i, "vrf %d", &vrf_id))
4029 else if (unformat (i, "create-vrf"))
4030 create_vrf_if_needed = 1;
4031 else if (unformat (i, "count %d", &count))
4033 else if (unformat (i, "lookup-in-vrf %d", &lookup_in_vrf))
4035 else if (unformat (i, "random"))
4037 else if (unformat (i, "seed %d", &random_seed))
4040 clib_warning ("parse error '%U'", format_unformat_error, i);
4045 if (resolve_attempts > 0 && sw_if_index_set == 0) {
4046 errmsg ("ARP resolution needs explicit interface or sw_if_index\n");
4050 if (!next_hop_set && !is_drop && !is_local && !is_classify) {
4051 errmsg ("next hop / local / drop / classify not set\n");
4055 if (address_set == 0) {
4056 errmsg ("missing addresses\n");
4060 if (address_length_set == 0) {
4061 errmsg ("missing address length\n");
4065 /* Generate a pile of unique, random routes */
4066 if (random_add_del) {
4067 u32 this_random_address;
4068 random_hash = hash_create (count, sizeof(uword));
4070 hash_set (random_hash, v4_next_hop_address.as_u32, 1);
4071 for (j = 0; j <= count; j++) {
4073 this_random_address = random_u32 (&random_seed);
4074 this_random_address =
4075 clib_host_to_net_u32 (this_random_address);
4076 } while (hash_get (random_hash, this_random_address));
4077 vec_add1 (random_vector, this_random_address);
4078 hash_set (random_hash, this_random_address, 1);
4080 hash_free (random_hash);
4081 v4_dst_address.as_u32 = random_vector[0];
4085 /* Turn on async mode */
4086 vam->async_mode = 1;
4087 vam->async_errors = 0;
4088 before = vat_time_now(vam);
4091 for (j = 0; j < count; j++) {
4092 /* Construct the API message */
4093 M(IP_ADD_DEL_ROUTE, ip_add_del_route);
4095 mp->next_hop_sw_if_index = ntohl (sw_if_index);
4096 mp->vrf_id = ntohl (vrf_id);
4097 if (resolve_attempts > 0) {
4098 mp->resolve_attempts = ntohl (resolve_attempts);
4099 mp->resolve_if_needed = 1;
4101 mp->create_vrf_if_needed = create_vrf_if_needed;
4103 mp->is_add = is_add;
4104 mp->is_drop = is_drop;
4105 mp->is_ipv6 = is_ipv6;
4106 mp->is_local = is_local;
4107 mp->is_classify = is_classify;
4108 mp->is_multipath = is_multipath;
4109 mp->not_last = not_last;
4110 mp->next_hop_weight = next_hop_weight;
4111 mp->dst_address_length = dst_address_length;
4112 mp->lookup_in_vrf = ntohl(lookup_in_vrf);
4113 mp->classify_table_index = ntohl(classify_table_index);
4116 clib_memcpy (mp->dst_address, &v6_dst_address, sizeof (v6_dst_address));
4118 clib_memcpy (mp->next_hop_address, &v6_next_hop_address,
4119 sizeof (v6_next_hop_address));
4120 increment_v6_address (&v6_dst_address);
4122 clib_memcpy (mp->dst_address, &v4_dst_address, sizeof (v4_dst_address));
4124 clib_memcpy (mp->next_hop_address, &v4_next_hop_address,
4125 sizeof (v4_next_hop_address));
4127 v4_dst_address.as_u32 = random_vector[j+1];
4129 increment_v4_address (&v4_dst_address);
4135 /* When testing multiple add/del ops, use a control-ping to sync */
4137 vl_api_control_ping_t * mp;
4140 /* Shut off async mode */
4141 vam->async_mode = 0;
4143 M(CONTROL_PING, control_ping);
4146 timeout = vat_time_now(vam) + 1.0;
4147 while (vat_time_now (vam) < timeout)
4148 if (vam->result_ready == 1)
4153 if (vam->retval == -99)
4154 errmsg ("timeout\n");
4156 if (vam->async_errors > 0) {
4157 errmsg ("%d asynchronous errors\n", vam->async_errors);
4160 vam->async_errors = 0;
4161 after = vat_time_now(vam);
4163 fformat(vam->ofp, "%d routes in %.6f secs, %.2f routes/sec\n",
4164 count, after - before, count / (after - before));
4166 /* Wait for a reply... */
4170 /* Return the good/bad news */
4171 return (vam->retval);
4174 static int api_proxy_arp_add_del (vat_main_t * vam)
4176 unformat_input_t * i = vam->input;
4177 vl_api_proxy_arp_add_del_t *mp;
4181 ip4_address_t lo, hi;
4184 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
4185 if (unformat (i, "vrf %d", &vrf_id))
4187 else if (unformat (i, "%U - %U", unformat_ip4_address, &lo,
4188 unformat_ip4_address, &hi))
4190 else if (unformat (i, "del"))
4193 clib_warning ("parse error '%U'", format_unformat_error, i);
4198 if (range_set == 0) {
4199 errmsg ("address range not set\n");
4203 M(PROXY_ARP_ADD_DEL, proxy_arp_add_del);
4205 mp->vrf_id = ntohl(vrf_id);
4206 mp->is_add = is_add;
4207 clib_memcpy(mp->low_address, &lo, sizeof (mp->low_address));
4208 clib_memcpy(mp->hi_address, &hi, sizeof (mp->hi_address));
4215 static int api_proxy_arp_intfc_enable_disable (vat_main_t * vam)
4217 unformat_input_t * i = vam->input;
4218 vl_api_proxy_arp_intfc_enable_disable_t *mp;
4222 u8 sw_if_index_set = 0;
4224 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
4225 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
4226 sw_if_index_set = 1;
4227 else if (unformat (i, "sw_if_index %d", &sw_if_index))
4228 sw_if_index_set = 1;
4229 else if (unformat (i, "enable"))
4231 else if (unformat (i, "disable"))
4234 clib_warning ("parse error '%U'", format_unformat_error, i);
4239 if (sw_if_index_set == 0) {
4240 errmsg ("missing interface name or sw_if_index\n");
4244 M(PROXY_ARP_INTFC_ENABLE_DISABLE, proxy_arp_intfc_enable_disable);
4246 mp->sw_if_index = ntohl(sw_if_index);
4247 mp->enable_disable = enable;
4254 static int api_mpls_add_del_decap (vat_main_t * vam)
4256 unformat_input_t * i = vam->input;
4257 vl_api_mpls_add_del_decap_t *mp;
4266 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
4267 if (unformat (i, "rx_vrf_id %d", &rx_vrf_id))
4269 else if (unformat (i, "tx_vrf_id %d", &tx_vrf_id))
4271 else if (unformat (i, "label %d", &label))
4273 else if (unformat (i, "next-index %d", &next_index))
4275 else if (unformat (i, "del"))
4277 else if (unformat (i, "s-bit-clear"))
4280 clib_warning ("parse error '%U'", format_unformat_error, i);
4285 M(MPLS_ADD_DEL_DECAP, mpls_add_del_decap);
4287 mp->rx_vrf_id = ntohl(rx_vrf_id);
4288 mp->tx_vrf_id = ntohl(tx_vrf_id);
4289 mp->label = ntohl(label);
4290 mp->next_index = ntohl(next_index);
4292 mp->is_add = is_add;
4299 static int api_mpls_add_del_encap (vat_main_t * vam)
4301 unformat_input_t * i = vam->input;
4302 vl_api_mpls_add_del_encap_t *mp;
4307 ip4_address_t dst_address;
4310 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
4311 if (unformat (i, "vrf %d", &vrf_id))
4313 else if (unformat (i, "label %d", &label))
4314 vec_add1 (labels, ntohl(label));
4315 else if (unformat (i, "dst %U", unformat_ip4_address, &dst_address))
4317 else if (unformat (i, "del"))
4320 clib_warning ("parse error '%U'", format_unformat_error, i);
4325 if (vec_len (labels) == 0) {
4326 errmsg ("missing encap label stack\n");
4330 M2(MPLS_ADD_DEL_ENCAP, mpls_add_del_encap,
4331 sizeof (u32) * vec_len (labels));
4333 mp->vrf_id = ntohl(vrf_id);
4334 clib_memcpy(mp->dst_address, &dst_address, sizeof (dst_address));
4335 mp->is_add = is_add;
4336 mp->nlabels = vec_len (labels);
4337 clib_memcpy(mp->labels, labels, sizeof(u32)*mp->nlabels);
4346 static int api_mpls_gre_add_del_tunnel (vat_main_t * vam)
4348 unformat_input_t * i = vam->input;
4349 vl_api_mpls_gre_add_del_tunnel_t *mp;
4351 u32 inner_vrf_id = 0;
4352 u32 outer_vrf_id = 0;
4353 ip4_address_t src_address;
4354 ip4_address_t dst_address;
4355 ip4_address_t intfc_address;
4357 u8 intfc_address_length = 0;
4361 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
4362 if (unformat (i, "inner_vrf_id %d", &inner_vrf_id))
4364 else if (unformat (i, "outer_vrf_id %d", &outer_vrf_id))
4366 else if (unformat (i, "src %U", unformat_ip4_address, &src_address))
4368 else if (unformat (i, "dst %U", unformat_ip4_address, &dst_address))
4370 else if (unformat (i, "adj %U/%d", unformat_ip4_address,
4371 &intfc_address, &tmp))
4372 intfc_address_length = tmp;
4373 else if (unformat (i, "l2-only"))
4375 else if (unformat (i, "del"))
4378 clib_warning ("parse error '%U'", format_unformat_error, i);
4383 M(MPLS_GRE_ADD_DEL_TUNNEL, mpls_gre_add_del_tunnel);
4385 mp->inner_vrf_id = ntohl(inner_vrf_id);
4386 mp->outer_vrf_id = ntohl(outer_vrf_id);
4387 clib_memcpy(mp->src_address, &src_address, sizeof (src_address));
4388 clib_memcpy(mp->dst_address, &dst_address, sizeof (dst_address));
4389 clib_memcpy(mp->intfc_address, &intfc_address, sizeof (intfc_address));
4390 mp->intfc_address_length = intfc_address_length;
4391 mp->l2_only = l2_only;
4392 mp->is_add = is_add;
4399 static int api_mpls_ethernet_add_del_tunnel (vat_main_t * vam)
4401 unformat_input_t * i = vam->input;
4402 vl_api_mpls_ethernet_add_del_tunnel_t *mp;
4404 u32 inner_vrf_id = 0;
4405 ip4_address_t intfc_address;
4406 u8 dst_mac_address[6];
4409 u8 intfc_address_length = 0;
4413 int tx_sw_if_index_set = 0;
4415 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
4416 if (unformat (i, "vrf %d", &inner_vrf_id))
4418 else if (unformat (i, "adj %U/%d", unformat_ip4_address,
4419 &intfc_address, &tmp))
4420 intfc_address_length = tmp;
4421 else if (unformat (i, "%U",
4422 unformat_sw_if_index, vam, &tx_sw_if_index))
4423 tx_sw_if_index_set = 1;
4424 else if (unformat (i, "tx_sw_if_index %d", &tx_sw_if_index))
4425 tx_sw_if_index_set = 1;
4426 else if (unformat (i, "dst %U", unformat_ethernet_address,
4429 else if (unformat (i, "l2-only"))
4431 else if (unformat (i, "del"))
4434 clib_warning ("parse error '%U'", format_unformat_error, i);
4440 errmsg ("dst (mac address) not set\n");
4443 if (!tx_sw_if_index_set) {
4444 errmsg ("tx-intfc not set\n");
4448 M(MPLS_ETHERNET_ADD_DEL_TUNNEL, mpls_ethernet_add_del_tunnel);
4450 mp->vrf_id = ntohl(inner_vrf_id);
4451 clib_memcpy (mp->adj_address, &intfc_address, sizeof (intfc_address));
4452 mp->adj_address_length = intfc_address_length;
4453 clib_memcpy (mp->dst_mac_address, dst_mac_address, sizeof (dst_mac_address));
4454 mp->tx_sw_if_index = ntohl(tx_sw_if_index);
4455 mp->l2_only = l2_only;
4456 mp->is_add = is_add;
4463 static int api_mpls_ethernet_add_del_tunnel_2 (vat_main_t * vam)
4465 unformat_input_t * i = vam->input;
4466 vl_api_mpls_ethernet_add_del_tunnel_2_t *mp;
4468 u32 inner_vrf_id = 0;
4469 u32 outer_vrf_id = 0;
4470 ip4_address_t adj_address;
4471 int adj_address_set = 0;
4472 ip4_address_t next_hop_address;
4473 int next_hop_address_set = 0;
4475 u8 adj_address_length = 0;
4478 u32 resolve_attempts = 5;
4479 u8 resolve_if_needed = 1;
4481 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
4482 if (unformat (i, "inner_vrf_id %d", &inner_vrf_id))
4484 else if (unformat (i, "outer_vrf_id %d", &outer_vrf_id))
4486 else if (unformat (i, "adj %U/%d", unformat_ip4_address,
4487 &adj_address, &tmp)) {
4488 adj_address_length = tmp;
4489 adj_address_set = 1;
4491 else if (unformat (i, "next-hop %U", unformat_ip4_address,
4493 next_hop_address_set = 1;
4494 else if (unformat (i, "resolve-attempts %d", &resolve_attempts))
4496 else if (unformat (i, "resolve-if-needed %d", &tmp))
4497 resolve_if_needed = tmp;
4498 else if (unformat (i, "l2-only"))
4500 else if (unformat (i, "del"))
4503 clib_warning ("parse error '%U'", format_unformat_error, i);
4508 if (!adj_address_set) {
4509 errmsg ("adjacency address/mask not set\n");
4512 if (!next_hop_address_set) {
4513 errmsg ("ip4 next hop address (in outer fib) not set\n");
4517 M(MPLS_ETHERNET_ADD_DEL_TUNNEL_2, mpls_ethernet_add_del_tunnel_2);
4519 mp->inner_vrf_id = ntohl(inner_vrf_id);
4520 mp->outer_vrf_id = ntohl(outer_vrf_id);
4521 mp->resolve_attempts = ntohl(resolve_attempts);
4522 mp->resolve_if_needed = resolve_if_needed;
4523 mp->is_add = is_add;
4524 mp->l2_only = l2_only;
4525 clib_memcpy (mp->adj_address, &adj_address, sizeof (adj_address));
4526 mp->adj_address_length = adj_address_length;
4527 clib_memcpy (mp->next_hop_ip4_address_in_outer_vrf, &next_hop_address,
4528 sizeof (next_hop_address));
4535 static int api_sw_interface_set_unnumbered (vat_main_t * vam)
4537 unformat_input_t * i = vam->input;
4538 vl_api_sw_interface_set_unnumbered_t *mp;
4543 u8 sw_if_index_set = 0;
4545 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
4546 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
4547 sw_if_index_set = 1;
4548 else if (unformat (i, "sw_if_index %d", &sw_if_index))
4549 sw_if_index_set = 1;
4550 else if (unformat (i, "unnum_if_index %d", &unnum_sw_index))
4552 else if (unformat (i, "del"))
4555 clib_warning ("parse error '%U'", format_unformat_error, i);
4560 if (sw_if_index_set == 0) {
4561 errmsg ("missing interface name or sw_if_index\n");
4565 M(SW_INTERFACE_SET_UNNUMBERED, sw_interface_set_unnumbered);
4567 mp->sw_if_index = ntohl(sw_if_index);
4568 mp->unnumbered_sw_if_index = ntohl(unnum_sw_index);
4569 mp->is_add = is_add;
4576 static int api_ip_neighbor_add_del (vat_main_t * vam)
4578 unformat_input_t * i = vam->input;
4579 vl_api_ip_neighbor_add_del_t *mp;
4582 u8 sw_if_index_set = 0;
4588 u8 v4_address_set = 0;
4589 u8 v6_address_set = 0;
4590 ip4_address_t v4address;
4591 ip6_address_t v6address;
4593 memset (mac_address, 0, sizeof (mac_address));
4595 /* Parse args required to build the message */
4596 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
4597 if (unformat (i, "mac %U", unformat_ethernet_address, mac_address)) {
4600 else if (unformat (i, "del"))
4602 else if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
4603 sw_if_index_set = 1;
4604 else if (unformat (i, "sw_if_index %d", &sw_if_index))
4605 sw_if_index_set = 1;
4606 else if (unformat (i, "is_static"))
4608 else if (unformat (i, "vrf %d", &vrf_id))
4610 else if (unformat (i, "dst %U",
4611 unformat_ip4_address, &v4address))
4613 else if (unformat (i, "dst %U",
4614 unformat_ip6_address, &v6address))
4617 clib_warning ("parse error '%U'", format_unformat_error, i);
4622 if (sw_if_index_set == 0) {
4623 errmsg ("missing interface name or sw_if_index\n");
4626 if (v4_address_set && v6_address_set) {
4627 errmsg ("both v4 and v6 addresses set\n");
4630 if (!v4_address_set && !v6_address_set) {
4631 errmsg ("no addresses set\n");
4635 /* Construct the API message */
4636 M(IP_NEIGHBOR_ADD_DEL, ip_neighbor_add_del);
4638 mp->sw_if_index = ntohl (sw_if_index);
4639 mp->is_add = is_add;
4640 mp->vrf_id = ntohl (vrf_id);
4641 mp->is_static = is_static;
4643 clib_memcpy (mp->mac_address, mac_address, 6);
4644 if (v6_address_set) {
4646 clib_memcpy (mp->dst_address, &v6address, sizeof (v6address));
4648 /* mp->is_ipv6 = 0; via memset in M macro above */
4649 clib_memcpy (mp->dst_address, &v4address, sizeof (v4address));
4655 /* Wait for a reply, return good/bad news */
4662 static int api_reset_vrf (vat_main_t * vam)
4664 unformat_input_t * i = vam->input;
4665 vl_api_reset_vrf_t *mp;
4671 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
4672 if (unformat (i, "vrf %d", &vrf_id))
4674 else if (unformat (i, "ipv6"))
4677 clib_warning ("parse error '%U'", format_unformat_error, i);
4682 if (vrf_id_set == 0) {
4683 errmsg ("missing vrf id\n");
4687 M(RESET_VRF, reset_vrf);
4689 mp->vrf_id = ntohl(vrf_id);
4690 mp->is_ipv6 = is_ipv6;
4697 static int api_create_vlan_subif (vat_main_t * vam)
4699 unformat_input_t * i = vam->input;
4700 vl_api_create_vlan_subif_t *mp;
4703 u8 sw_if_index_set = 0;
4707 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
4708 if (unformat (i, "sw_if_index %d", &sw_if_index))
4709 sw_if_index_set = 1;
4710 else if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
4711 sw_if_index_set = 1;
4712 else if (unformat (i, "vlan %d", &vlan_id))
4715 clib_warning ("parse error '%U'", format_unformat_error, i);
4720 if (sw_if_index_set == 0) {
4721 errmsg ("missing interface name or sw_if_index\n");
4725 if (vlan_id_set == 0) {
4726 errmsg ("missing vlan_id\n");
4729 M(CREATE_VLAN_SUBIF, create_vlan_subif);
4731 mp->sw_if_index = ntohl(sw_if_index);
4732 mp->vlan_id = ntohl(vlan_id);
4739 #define foreach_create_subif_bit \
4746 _(outer_vlan_id_any) \
4747 _(inner_vlan_id_any)
4749 static int api_create_subif (vat_main_t * vam)
4751 unformat_input_t * i = vam->input;
4752 vl_api_create_subif_t *mp;
4755 u8 sw_if_index_set = 0;
4762 u32 exact_match = 0;
4763 u32 default_sub = 0;
4764 u32 outer_vlan_id_any = 0;
4765 u32 inner_vlan_id_any = 0;
4767 u16 outer_vlan_id = 0;
4768 u16 inner_vlan_id = 0;
4770 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
4771 if (unformat (i, "sw_if_index %d", &sw_if_index))
4772 sw_if_index_set = 1;
4773 else if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
4774 sw_if_index_set = 1;
4775 else if (unformat (i, "sub_id %d", &sub_id))
4777 else if (unformat (i, "outer_vlan_id %d", &tmp))
4778 outer_vlan_id = tmp;
4779 else if (unformat (i, "inner_vlan_id %d", &tmp))
4780 inner_vlan_id = tmp;
4782 #define _(a) else if (unformat (i, #a)) a = 1 ;
4783 foreach_create_subif_bit
4787 clib_warning ("parse error '%U'", format_unformat_error, i);
4792 if (sw_if_index_set == 0) {
4793 errmsg ("missing interface name or sw_if_index\n");
4797 if (sub_id_set == 0) {
4798 errmsg ("missing sub_id\n");
4801 M(CREATE_SUBIF, create_subif);
4803 mp->sw_if_index = ntohl(sw_if_index);
4804 mp->sub_id = ntohl(sub_id);
4806 #define _(a) mp->a = a;
4807 foreach_create_subif_bit;
4810 mp->outer_vlan_id = ntohs (outer_vlan_id);
4811 mp->inner_vlan_id = ntohs (inner_vlan_id);
4818 static int api_oam_add_del (vat_main_t * vam)
4820 unformat_input_t * i = vam->input;
4821 vl_api_oam_add_del_t *mp;
4825 ip4_address_t src, dst;
4829 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
4830 if (unformat (i, "vrf %d", &vrf_id))
4832 else if (unformat (i, "src %U", unformat_ip4_address, &src))
4834 else if (unformat (i, "dst %U", unformat_ip4_address, &dst))
4836 else if (unformat (i, "del"))
4839 clib_warning ("parse error '%U'", format_unformat_error, i);
4845 errmsg ("missing src addr\n");
4850 errmsg ("missing dst addr\n");
4854 M(OAM_ADD_DEL, oam_add_del);
4856 mp->vrf_id = ntohl(vrf_id);
4857 mp->is_add = is_add;
4858 clib_memcpy(mp->src_address, &src, sizeof (mp->src_address));
4859 clib_memcpy(mp->dst_address, &dst, sizeof (mp->dst_address));
4866 static int api_reset_fib (vat_main_t * vam)
4868 unformat_input_t * i = vam->input;
4869 vl_api_reset_fib_t *mp;
4875 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
4876 if (unformat (i, "vrf %d", &vrf_id))
4878 else if (unformat (i, "ipv6"))
4881 clib_warning ("parse error '%U'", format_unformat_error, i);
4886 if (vrf_id_set == 0) {
4887 errmsg ("missing vrf id\n");
4891 M(RESET_FIB, reset_fib);
4893 mp->vrf_id = ntohl(vrf_id);
4894 mp->is_ipv6 = is_ipv6;
4901 static int api_dhcp_proxy_config (vat_main_t * vam)
4903 unformat_input_t * i = vam->input;
4904 vl_api_dhcp_proxy_config_t *mp;
4909 u8 v4_address_set = 0;
4910 u8 v6_address_set = 0;
4911 ip4_address_t v4address;
4912 ip6_address_t v6address;
4913 u8 v4_src_address_set = 0;
4914 u8 v6_src_address_set = 0;
4915 ip4_address_t v4srcaddress;
4916 ip6_address_t v6srcaddress;
4918 /* Parse args required to build the message */
4919 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
4920 if (unformat (i, "del"))
4922 else if (unformat (i, "vrf %d", &vrf_id))
4924 else if (unformat (i, "insert-cid %d", &insert_cid))
4926 else if (unformat (i, "svr %U",
4927 unformat_ip4_address, &v4address))
4929 else if (unformat (i, "svr %U",
4930 unformat_ip6_address, &v6address))
4932 else if (unformat (i, "src %U",
4933 unformat_ip4_address, &v4srcaddress))
4934 v4_src_address_set = 1;
4935 else if (unformat (i, "src %U",
4936 unformat_ip6_address, &v6srcaddress))
4937 v6_src_address_set = 1;
4942 if (v4_address_set && v6_address_set) {
4943 errmsg ("both v4 and v6 server addresses set\n");
4946 if (!v4_address_set && !v6_address_set) {
4947 errmsg ("no server addresses set\n");
4951 if (v4_src_address_set && v6_src_address_set) {
4952 errmsg ("both v4 and v6 src addresses set\n");
4955 if (!v4_src_address_set && !v6_src_address_set) {
4956 errmsg ("no src addresses set\n");
4960 if (!(v4_src_address_set && v4_address_set) &&
4961 !(v6_src_address_set && v6_address_set)) {
4962 errmsg ("no matching server and src addresses set\n");
4966 /* Construct the API message */
4967 M(DHCP_PROXY_CONFIG, dhcp_proxy_config);
4969 mp->insert_circuit_id = insert_cid;
4970 mp->is_add = is_add;
4971 mp->vrf_id = ntohl (vrf_id);
4972 if (v6_address_set) {
4974 clib_memcpy (mp->dhcp_server, &v6address, sizeof (v6address));
4975 clib_memcpy (mp->dhcp_src_address, &v6srcaddress, sizeof (v6address));
4977 clib_memcpy (mp->dhcp_server, &v4address, sizeof (v4address));
4978 clib_memcpy (mp->dhcp_src_address, &v4srcaddress, sizeof (v4address));
4984 /* Wait for a reply, return good/bad news */
4990 static int api_dhcp_proxy_config_2 (vat_main_t * vam)
4992 unformat_input_t * i = vam->input;
4993 vl_api_dhcp_proxy_config_2_t *mp;
4996 u32 server_vrf_id = 0;
4999 u8 v4_address_set = 0;
5000 u8 v6_address_set = 0;
5001 ip4_address_t v4address;
5002 ip6_address_t v6address;
5003 u8 v4_src_address_set = 0;
5004 u8 v6_src_address_set = 0;
5005 ip4_address_t v4srcaddress;
5006 ip6_address_t v6srcaddress;
5008 /* Parse args required to build the message */
5009 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
5010 if (unformat (i, "del"))
5012 else if (unformat (i, "rx_vrf_id %d", &rx_vrf_id))
5014 else if (unformat (i, "server_vrf_id %d", &server_vrf_id))
5016 else if (unformat (i, "insert-cid %d", &insert_cid))
5018 else if (unformat (i, "svr %U",
5019 unformat_ip4_address, &v4address))
5021 else if (unformat (i, "svr %U",
5022 unformat_ip6_address, &v6address))
5024 else if (unformat (i, "src %U",
5025 unformat_ip4_address, &v4srcaddress))
5026 v4_src_address_set = 1;
5027 else if (unformat (i, "src %U",
5028 unformat_ip6_address, &v6srcaddress))
5029 v6_src_address_set = 1;
5034 if (v4_address_set && v6_address_set) {
5035 errmsg ("both v4 and v6 server addresses set\n");
5038 if (!v4_address_set && !v6_address_set) {
5039 errmsg ("no server addresses set\n");
5043 if (v4_src_address_set && v6_src_address_set) {
5044 errmsg ("both v4 and v6 src addresses set\n");
5047 if (!v4_src_address_set && !v6_src_address_set) {
5048 errmsg ("no src addresses set\n");
5052 if (!(v4_src_address_set && v4_address_set) &&
5053 !(v6_src_address_set && v6_address_set)) {
5054 errmsg ("no matching server and src addresses set\n");
5058 /* Construct the API message */
5059 M(DHCP_PROXY_CONFIG_2, dhcp_proxy_config_2);
5061 mp->insert_circuit_id = insert_cid;
5062 mp->is_add = is_add;
5063 mp->rx_vrf_id = ntohl (rx_vrf_id);
5064 mp->server_vrf_id = ntohl (server_vrf_id);
5065 if (v6_address_set) {
5067 clib_memcpy (mp->dhcp_server, &v6address, sizeof (v6address));
5068 clib_memcpy (mp->dhcp_src_address, &v6srcaddress, sizeof (v6address));
5070 clib_memcpy (mp->dhcp_server, &v4address, sizeof (v4address));
5071 clib_memcpy (mp->dhcp_src_address, &v4srcaddress, sizeof (v4address));
5077 /* Wait for a reply, return good/bad news */
5083 static int api_dhcp_proxy_set_vss (vat_main_t * vam)
5085 unformat_input_t * i = vam->input;
5086 vl_api_dhcp_proxy_set_vss_t *mp;
5097 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
5098 if (unformat (i, "tbl_id %d", &tbl_id))
5100 if (unformat (i, "fib_id %d", &fib_id))
5102 if (unformat (i, "oui %d", &oui))
5104 else if (unformat (i, "ipv6"))
5106 else if (unformat (i, "del"))
5109 clib_warning ("parse error '%U'", format_unformat_error, i);
5114 if (tbl_id_set == 0) {
5115 errmsg ("missing tbl id\n");
5119 if (fib_id_set == 0) {
5120 errmsg ("missing fib id\n");
5124 errmsg ("missing oui\n");
5128 M(DHCP_PROXY_SET_VSS, dhcp_proxy_set_vss);
5129 mp->tbl_id = ntohl(tbl_id);
5130 mp->fib_id = ntohl(fib_id);
5131 mp->oui = ntohl(oui);
5132 mp->is_ipv6 = is_ipv6;
5133 mp->is_add = is_add;
5140 static int api_dhcp_client_config (vat_main_t * vam)
5142 unformat_input_t * i = vam->input;
5143 vl_api_dhcp_client_config_t *mp;
5146 u8 sw_if_index_set = 0;
5149 u8 disable_event = 0;
5151 /* Parse args required to build the message */
5152 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
5153 if (unformat (i, "del"))
5155 else if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
5156 sw_if_index_set = 1;
5157 else if (unformat (i, "sw_if_index %d", &sw_if_index))
5158 sw_if_index_set = 1;
5159 else if (unformat (i, "hostname %s", &hostname))
5161 else if (unformat (i, "disable_event"))
5167 if (sw_if_index_set == 0) {
5168 errmsg ("missing interface name or sw_if_index\n");
5172 if (vec_len (hostname) > 63) {
5173 errmsg ("hostname too long\n");
5175 vec_add1 (hostname, 0);
5177 /* Construct the API message */
5178 M(DHCP_CLIENT_CONFIG, dhcp_client_config);
5180 mp->sw_if_index = ntohl (sw_if_index);
5181 clib_memcpy (mp->hostname, hostname, vec_len (hostname));
5182 vec_free (hostname);
5183 mp->is_add = is_add;
5184 mp->want_dhcp_event = disable_event ? 0 : 1;
5190 /* Wait for a reply, return good/bad news */
5196 static int api_set_ip_flow_hash (vat_main_t * vam)
5198 unformat_input_t * i = vam->input;
5199 vl_api_set_ip_flow_hash_t *mp;
5211 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
5212 if (unformat (i, "vrf %d", &vrf_id))
5214 else if (unformat (i, "ipv6"))
5216 else if (unformat (i, "src"))
5218 else if (unformat (i, "dst"))
5220 else if (unformat (i, "sport"))
5222 else if (unformat (i, "dport"))
5224 else if (unformat (i, "proto"))
5226 else if (unformat (i, "reverse"))
5230 clib_warning ("parse error '%U'", format_unformat_error, i);
5235 if (vrf_id_set == 0) {
5236 errmsg ("missing vrf id\n");
5240 M(SET_IP_FLOW_HASH, set_ip_flow_hash);
5246 mp->reverse = reverse;
5247 mp->vrf_id = ntohl(vrf_id);
5248 mp->is_ipv6 = is_ipv6;
5255 static int api_sw_interface_ip6_enable_disable (vat_main_t * vam)
5257 unformat_input_t * i = vam->input;
5258 vl_api_sw_interface_ip6_enable_disable_t *mp;
5261 u8 sw_if_index_set = 0;
5264 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
5265 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
5266 sw_if_index_set = 1;
5267 else if (unformat (i, "sw_if_index %d", &sw_if_index))
5268 sw_if_index_set = 1;
5269 else if (unformat (i, "enable"))
5271 else if (unformat (i, "disable"))
5274 clib_warning ("parse error '%U'", format_unformat_error, i);
5279 if (sw_if_index_set == 0) {
5280 errmsg ("missing interface name or sw_if_index\n");
5284 M(SW_INTERFACE_IP6_ENABLE_DISABLE, sw_interface_ip6_enable_disable);
5286 mp->sw_if_index = ntohl(sw_if_index);
5287 mp->enable = enable;
5294 static int api_sw_interface_ip6_set_link_local_address (vat_main_t * vam)
5296 unformat_input_t * i = vam->input;
5297 vl_api_sw_interface_ip6_set_link_local_address_t *mp;
5300 u8 sw_if_index_set = 0;
5301 u32 address_length = 0;
5302 u8 v6_address_set = 0;
5303 ip6_address_t v6address;
5305 /* Parse args required to build the message */
5306 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
5307 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
5308 sw_if_index_set = 1;
5309 else if (unformat (i, "sw_if_index %d", &sw_if_index))
5310 sw_if_index_set = 1;
5311 else if (unformat (i, "%U/%d",
5312 unformat_ip6_address, &v6address,
5319 if (sw_if_index_set == 0) {
5320 errmsg ("missing interface name or sw_if_index\n");
5323 if (!v6_address_set) {
5324 errmsg ("no address set\n");
5328 /* Construct the API message */
5329 M(SW_INTERFACE_IP6_SET_LINK_LOCAL_ADDRESS, \
5330 sw_interface_ip6_set_link_local_address);
5332 mp->sw_if_index = ntohl (sw_if_index);
5333 clib_memcpy (mp->address, &v6address, sizeof (v6address));
5334 mp->address_length = address_length;
5339 /* Wait for a reply, return good/bad news */
5347 static int api_sw_interface_ip6nd_ra_prefix (vat_main_t * vam)
5349 unformat_input_t * i = vam->input;
5350 vl_api_sw_interface_ip6nd_ra_prefix_t *mp;
5353 u8 sw_if_index_set = 0;
5354 u32 address_length = 0;
5355 u8 v6_address_set = 0;
5356 ip6_address_t v6address;
5358 u8 no_advertise = 0;
5360 u8 no_autoconfig = 0;
5363 u32 val_lifetime = 0;
5364 u32 pref_lifetime = 0;
5366 /* Parse args required to build the message */
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, "%U/%d",
5373 unformat_ip6_address, &v6address,
5376 else if (unformat (i, "val_life %d", &val_lifetime))
5378 else if (unformat (i, "pref_life %d", &pref_lifetime))
5380 else if (unformat (i, "def"))
5382 else if (unformat (i, "noadv"))
5384 else if (unformat (i, "offl"))
5386 else if (unformat (i, "noauto"))
5388 else if (unformat (i, "nolink"))
5390 else if (unformat (i, "isno"))
5393 clib_warning ("parse error '%U'", format_unformat_error, i);
5398 if (sw_if_index_set == 0) {
5399 errmsg ("missing interface name or sw_if_index\n");
5402 if (!v6_address_set) {
5403 errmsg ("no address set\n");
5407 /* Construct the API message */
5408 M(SW_INTERFACE_IP6ND_RA_PREFIX, sw_interface_ip6nd_ra_prefix);
5410 mp->sw_if_index = ntohl (sw_if_index);
5411 clib_memcpy (mp->address, &v6address, sizeof (v6address));
5412 mp->address_length = address_length;
5413 mp->use_default = use_default;
5414 mp->no_advertise = no_advertise;
5415 mp->off_link = off_link;
5416 mp->no_autoconfig = no_autoconfig;
5417 mp->no_onlink = no_onlink;
5419 mp->val_lifetime = ntohl(val_lifetime);
5420 mp->pref_lifetime = ntohl(pref_lifetime);
5425 /* Wait for a reply, return good/bad news */
5432 static int api_sw_interface_ip6nd_ra_config (vat_main_t * vam)
5434 unformat_input_t * i = vam->input;
5435 vl_api_sw_interface_ip6nd_ra_config_t *mp;
5438 u8 sw_if_index_set = 0;
5443 u8 send_unicast = 0;
5446 u8 default_router = 0;
5447 u32 max_interval = 0;
5448 u32 min_interval = 0;
5450 u32 initial_count = 0;
5451 u32 initial_interval = 0;
5454 /* Parse args required to build the message */
5455 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
5456 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
5457 sw_if_index_set = 1;
5458 else if (unformat (i, "sw_if_index %d", &sw_if_index))
5459 sw_if_index_set = 1;
5460 else if (unformat (i, "maxint %d", &max_interval))
5462 else if (unformat (i, "minint %d", &min_interval))
5464 else if (unformat (i, "life %d", &lifetime))
5466 else if (unformat (i, "count %d", &initial_count))
5468 else if (unformat (i, "interval %d", &initial_interval))
5470 else if (unformat (i, "surpress"))
5472 else if (unformat (i, "managed"))
5474 else if (unformat (i, "other"))
5476 else if (unformat (i, "ll"))
5478 else if (unformat (i, "send"))
5480 else if (unformat (i, "cease"))
5482 else if (unformat (i, "isno"))
5484 else if (unformat (i, "def"))
5487 clib_warning ("parse error '%U'", format_unformat_error, i);
5492 if (sw_if_index_set == 0) {
5493 errmsg ("missing interface name or sw_if_index\n");
5497 /* Construct the API message */
5498 M(SW_INTERFACE_IP6ND_RA_CONFIG, sw_interface_ip6nd_ra_config);
5500 mp->sw_if_index = ntohl (sw_if_index);
5501 mp->max_interval = ntohl(max_interval);
5502 mp->min_interval = ntohl(min_interval);
5503 mp->lifetime = ntohl(lifetime);
5504 mp->initial_count = ntohl(initial_count);
5505 mp->initial_interval = ntohl(initial_interval);
5506 mp->surpress = surpress;
5507 mp->managed = managed;
5509 mp->ll_option = ll_option;
5510 mp->send_unicast = send_unicast;
5513 mp->default_router = default_router;
5518 /* Wait for a reply, return good/bad news */
5525 static int api_set_arp_neighbor_limit (vat_main_t * vam)
5527 unformat_input_t * i = vam->input;
5528 vl_api_set_arp_neighbor_limit_t *mp;
5534 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
5535 if (unformat (i, "arp_nbr_limit %d", &arp_nbr_limit))
5537 else if (unformat (i, "ipv6"))
5540 clib_warning ("parse error '%U'", format_unformat_error, i);
5545 if (limit_set == 0) {
5546 errmsg ("missing limit value\n");
5550 M(SET_ARP_NEIGHBOR_LIMIT, set_arp_neighbor_limit);
5552 mp->arp_neighbor_limit = ntohl(arp_nbr_limit);
5553 mp->is_ipv6 = is_ipv6;
5560 static int api_l2_patch_add_del (vat_main_t * vam)
5562 unformat_input_t * i = vam->input;
5563 vl_api_l2_patch_add_del_t *mp;
5566 u8 rx_sw_if_index_set = 0;
5568 u8 tx_sw_if_index_set = 0;
5571 /* Parse args required to build the message */
5572 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
5573 if (unformat (i, "rx_sw_if_index %d", &rx_sw_if_index))
5574 rx_sw_if_index_set = 1;
5575 else if (unformat (i, "tx_sw_if_index %d", &tx_sw_if_index))
5576 tx_sw_if_index_set = 1;
5577 else if (unformat (i, "rx")) {
5578 if (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
5579 if (unformat (i, "%U", unformat_sw_if_index, vam,
5581 rx_sw_if_index_set = 1;
5584 } else if (unformat (i, "tx")) {
5585 if (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
5586 if (unformat (i, "%U", unformat_sw_if_index, vam,
5588 tx_sw_if_index_set = 1;
5591 } else if (unformat (i, "del"))
5597 if (rx_sw_if_index_set == 0) {
5598 errmsg ("missing rx interface name or rx_sw_if_index\n");
5602 if (tx_sw_if_index_set == 0) {
5603 errmsg ("missing tx interface name or tx_sw_if_index\n");
5607 M(L2_PATCH_ADD_DEL, l2_patch_add_del);
5609 mp->rx_sw_if_index = ntohl(rx_sw_if_index);
5610 mp->tx_sw_if_index = ntohl(tx_sw_if_index);
5611 mp->is_add = is_add;
5617 static int api_trace_profile_add (vat_main_t *vam)
5619 unformat_input_t * input = vam->input;
5620 vl_api_trace_profile_add_t *mp;
5623 u32 trace_option_elts = 0;
5624 u32 trace_type = 0, node_id = 0, app_data = 0, trace_tsp = 2;
5625 int has_pow_option = 0;
5626 int has_ppc_option = 0;
5628 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
5630 if (unformat (input, "id %d trace-type 0x%x trace-elts %d "
5631 "trace-tsp %d node-id 0x%x app-data 0x%x",
5632 &id, &trace_type, &trace_option_elts, &trace_tsp,
5633 &node_id, &app_data))
5635 else if (unformat (input, "pow"))
5637 else if (unformat (input, "ppc encap"))
5638 has_ppc_option = PPC_ENCAP;
5639 else if (unformat (input, "ppc decap"))
5640 has_ppc_option = PPC_DECAP;
5641 else if (unformat (input, "ppc none"))
5642 has_ppc_option = PPC_NONE;
5646 M(TRACE_PROFILE_ADD, trace_profile_add);
5648 mp->trace_type = trace_type;
5649 mp->trace_num_elt = trace_option_elts;
5650 mp->trace_ppc = has_ppc_option;
5651 mp->trace_app_data = htonl(app_data);
5652 mp->pow_enable = has_pow_option;
5653 mp->trace_tsp = trace_tsp;
5654 mp->node_id = htonl(node_id);
5661 static int api_trace_profile_apply (vat_main_t *vam)
5663 unformat_input_t * input = vam->input;
5664 vl_api_trace_profile_apply_t *mp;
5667 u32 mask_width = ~0;
5674 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
5676 if (unformat (input, "%U/%d",
5677 unformat_ip6_address, &addr, &mask_width))
5679 else if (unformat (input, "id %d", &id))
5681 else if (unformat (input, "vrf-id %d", &vrf_id))
5683 else if (unformat (input, "add"))
5685 else if (unformat (input, "pop"))
5687 else if (unformat (input, "none"))
5693 if ((is_add + is_pop + is_none) != 1) {
5694 errmsg("One of (add, pop, none) required");
5697 if (mask_width == ~0) {
5698 errmsg("<address>/<mask-width> required");
5701 M(TRACE_PROFILE_APPLY, trace_profile_apply);
5702 clib_memcpy(mp->dest_ipv6, &addr, sizeof(mp->dest_ipv6));
5704 mp->prefix_length = htonl(mask_width);
5705 mp->vrf_id = htonl(vrf_id);
5707 mp->trace_op = IOAM_HBYH_ADD;
5709 mp->trace_op = IOAM_HBYH_POP;
5711 mp->trace_op = IOAM_HBYH_MOD;
5723 static int api_trace_profile_del (vat_main_t *vam)
5725 vl_api_trace_profile_del_t *mp;
5728 M(TRACE_PROFILE_DEL, trace_profile_del);
5733 static int api_sr_tunnel_add_del (vat_main_t * vam)
5735 unformat_input_t * i = vam->input;
5736 vl_api_sr_tunnel_add_del_t *mp;
5740 ip6_address_t src_address;
5741 int src_address_set = 0;
5742 ip6_address_t dst_address;
5744 int dst_address_set = 0;
5746 u32 rx_table_id = 0;
5747 u32 tx_table_id = 0;
5748 ip6_address_t * segments = 0;
5749 ip6_address_t * this_seg;
5750 ip6_address_t * tags = 0;
5751 ip6_address_t * this_tag;
5752 ip6_address_t next_address, tag;
5754 u8 * policy_name = 0;
5756 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
5758 if (unformat (i, "del"))
5760 else if (unformat (i, "name %s", &name))
5762 else if (unformat (i, "policy %s", &policy_name))
5764 else if (unformat (i, "rx_fib_id %d", &rx_table_id))
5766 else if (unformat (i, "tx_fib_id %d", &tx_table_id))
5768 else if (unformat (i, "src %U", unformat_ip6_address, &src_address))
5769 src_address_set = 1;
5770 else if (unformat (i, "dst %U/%d",
5771 unformat_ip6_address, &dst_address,
5773 dst_address_set = 1;
5774 else if (unformat (i, "next %U", unformat_ip6_address,
5777 vec_add2 (segments, this_seg, 1);
5778 clib_memcpy (this_seg->as_u8, next_address.as_u8, sizeof (*this_seg));
5780 else if (unformat (i, "tag %U", unformat_ip6_address,
5783 vec_add2 (tags, this_tag, 1);
5784 clib_memcpy (this_tag->as_u8, tag.as_u8, sizeof (*this_tag));
5786 else if (unformat (i, "clean"))
5787 flags |= IP6_SR_HEADER_FLAG_CLEANUP;
5788 else if (unformat (i, "protected"))
5789 flags |= IP6_SR_HEADER_FLAG_PROTECTED;
5790 else if (unformat (i, "InPE %d", &pl_index))
5792 if (pl_index <= 0 || pl_index > 4)
5794 pl_index_range_error:
5795 errmsg ("pl index %d out of range\n", pl_index);
5798 flags |= IP6_SR_HEADER_FLAG_PL_ELT_INGRESS_PE << (3*(pl_index - 1));
5800 else if (unformat (i, "EgPE %d", &pl_index))
5802 if (pl_index <= 0 || pl_index > 4)
5803 goto pl_index_range_error;
5804 flags |= IP6_SR_HEADER_FLAG_PL_ELT_EGRESS_PE << (3*(pl_index - 1));
5806 else if (unformat (i, "OrgSrc %d", &pl_index))
5808 if (pl_index <= 0 || pl_index > 4)
5809 goto pl_index_range_error;
5810 flags |= IP6_SR_HEADER_FLAG_PL_ELT_ORIG_SRC_ADDR << (3*(pl_index - 1));
5816 if (!src_address_set)
5818 errmsg ("src address required\n");
5822 if (!dst_address_set)
5824 errmsg ("dst address required\n");
5830 errmsg ("at least one sr segment required\n");
5834 M2(SR_TUNNEL_ADD_DEL, sr_tunnel_add_del,
5835 vec_len(segments) * sizeof (ip6_address_t)
5836 + vec_len(tags) * sizeof (ip6_address_t));
5838 clib_memcpy (mp->src_address, &src_address, sizeof (mp->src_address));
5839 clib_memcpy (mp->dst_address, &dst_address, sizeof (mp->dst_address));
5840 mp->dst_mask_width = dst_mask_width;
5841 mp->flags_net_byte_order = clib_host_to_net_u16 (flags);
5842 mp->n_segments = vec_len (segments);
5843 mp->n_tags = vec_len (tags);
5844 mp->is_add = is_del == 0;
5845 clib_memcpy (mp->segs_and_tags, segments,
5846 vec_len(segments)* sizeof (ip6_address_t));
5847 clib_memcpy (mp->segs_and_tags + vec_len(segments)*sizeof (ip6_address_t),
5848 tags, vec_len(tags)* sizeof (ip6_address_t));
5850 mp->outer_vrf_id = ntohl (rx_table_id);
5851 mp->inner_vrf_id = ntohl (tx_table_id);
5852 memcpy (mp->name, name, vec_len(name));
5853 memcpy (mp->policy_name, policy_name, vec_len(policy_name));
5855 vec_free (segments);
5862 static int api_sr_policy_add_del (vat_main_t * vam)
5864 unformat_input_t * input = vam->input;
5865 vl_api_sr_policy_add_del_t *mp;
5869 u8 * tunnel_name = 0;
5870 u8 ** tunnel_names = 0;
5875 int tunnel_names_length = 1; // Init to 1 to offset the #tunnel_names counter byte
5876 int tun_name_len = 0; // Different naming convention used as confusing these would be "bad" (TM)
5878 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
5880 if (unformat (input, "del"))
5882 else if (unformat (input, "name %s", &name))
5884 else if (unformat (input, "tunnel %s", &tunnel_name))
5888 vec_add1 (tunnel_names, tunnel_name);
5890 - length = #bytes to store in serial vector
5891 - +1 = byte to store that length
5893 tunnel_names_length += (vec_len (tunnel_name) + 1);
5904 errmsg ("policy name required\n");
5908 if ((!tunnel_set) && (!is_del))
5910 errmsg ("tunnel name required\n");
5914 M2(SR_POLICY_ADD_DEL, sr_policy_add_del, tunnel_names_length);
5918 mp->is_add = !is_del;
5920 memcpy (mp->name, name, vec_len(name));
5921 // Since mp->tunnel_names is of type u8[0] and not a u8 *, u8 ** needs to be serialized
5922 u8 * serial_orig = 0;
5923 vec_validate (serial_orig, tunnel_names_length);
5924 *serial_orig = vec_len(tunnel_names); // Store the number of tunnels as length in first byte of serialized vector
5925 serial_orig += 1; // Move along one byte to store the length of first tunnel_name
5927 for (j=0; j < vec_len(tunnel_names); j++)
5929 tun_name_len = vec_len (tunnel_names[j]);
5930 *serial_orig = tun_name_len; // Store length of tunnel name in first byte of Length/Value pair
5931 serial_orig += 1; // Move along one byte to store the actual tunnel name
5932 memcpy (serial_orig, tunnel_names[j], tun_name_len);
5933 serial_orig += tun_name_len; // Advance past the copy
5935 memcpy (mp->tunnel_names, serial_orig - tunnel_names_length, tunnel_names_length); // Regress serial_orig to head then copy fwd
5937 vec_free (tunnel_names);
5938 vec_free (tunnel_name);
5944 static int api_sr_multicast_map_add_del (vat_main_t * vam)
5946 unformat_input_t * input = vam->input;
5947 vl_api_sr_multicast_map_add_del_t *mp;
5950 ip6_address_t multicast_address;
5951 u8 * policy_name = 0;
5952 int multicast_address_set = 0;
5954 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
5956 if (unformat (input, "del"))
5958 else if (unformat (input, "address %U", unformat_ip6_address, &multicast_address))
5959 multicast_address_set = 1;
5960 else if (unformat (input, "sr-policy %s", &policy_name))
5966 if (!is_del && !policy_name)
5968 errmsg ("sr-policy name required\n");
5973 if (!multicast_address_set)
5975 errmsg ("address required\n");
5979 M(SR_MULTICAST_MAP_ADD_DEL, sr_multicast_map_add_del);
5981 mp->is_add = !is_del;
5982 memcpy (mp->policy_name, policy_name, vec_len(policy_name));
5983 clib_memcpy (mp->multicast_address, &multicast_address, sizeof (mp->multicast_address));
5986 vec_free (policy_name);
5993 #define foreach_ip4_proto_field \
6003 uword unformat_ip4_mask (unformat_input_t * input, va_list * args)
6005 u8 ** maskp = va_arg (*args, u8 **);
6007 u8 found_something = 0;
6010 #define _(a) u8 a=0;
6011 foreach_ip4_proto_field;
6017 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
6019 if (unformat (input, "version"))
6021 else if (unformat (input, "hdr_length"))
6023 else if (unformat (input, "src"))
6025 else if (unformat (input, "dst"))
6027 else if (unformat (input, "proto"))
6030 #define _(a) else if (unformat (input, #a)) a=1;
6031 foreach_ip4_proto_field
6037 #define _(a) found_something += a;
6038 foreach_ip4_proto_field;
6041 if (found_something == 0)
6044 vec_validate (mask, sizeof (*ip) - 1);
6046 ip = (ip4_header_t *) mask;
6048 #define _(a) if (a) memset (&ip->a, 0xff, sizeof (ip->a));
6049 foreach_ip4_proto_field;
6052 ip->ip_version_and_header_length = 0;
6055 ip->ip_version_and_header_length |= 0xF0;
6058 ip->ip_version_and_header_length |= 0x0F;
6064 #define foreach_ip6_proto_field \
6071 uword unformat_ip6_mask (unformat_input_t * input, va_list * args)
6073 u8 ** maskp = va_arg (*args, u8 **);
6075 u8 found_something = 0;
6077 u32 ip_version_traffic_class_and_flow_label;
6079 #define _(a) u8 a=0;
6080 foreach_ip6_proto_field;
6083 u8 traffic_class = 0;
6086 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
6088 if (unformat (input, "version"))
6090 else if (unformat (input, "traffic-class"))
6092 else if (unformat (input, "flow-label"))
6094 else if (unformat (input, "src"))
6096 else if (unformat (input, "dst"))
6098 else if (unformat (input, "proto"))
6101 #define _(a) else if (unformat (input, #a)) a=1;
6102 foreach_ip6_proto_field
6108 #define _(a) found_something += a;
6109 foreach_ip6_proto_field;
6112 if (found_something == 0)
6115 vec_validate (mask, sizeof (*ip) - 1);
6117 ip = (ip6_header_t *) mask;
6119 #define _(a) if (a) memset (&ip->a, 0xff, sizeof (ip->a));
6120 foreach_ip6_proto_field;
6123 ip_version_traffic_class_and_flow_label = 0;
6126 ip_version_traffic_class_and_flow_label |= 0xF0000000;
6129 ip_version_traffic_class_and_flow_label |= 0x0FF00000;
6132 ip_version_traffic_class_and_flow_label |= 0x000FFFFF;
6134 ip->ip_version_traffic_class_and_flow_label =
6135 clib_host_to_net_u32 (ip_version_traffic_class_and_flow_label);
6141 uword unformat_l3_mask (unformat_input_t * input, va_list * args)
6143 u8 ** maskp = va_arg (*args, u8 **);
6145 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) {
6146 if (unformat (input, "ip4 %U", unformat_ip4_mask, maskp))
6148 else if (unformat (input, "ip6 %U", unformat_ip6_mask, maskp))
6156 uword unformat_l2_mask (unformat_input_t * input, va_list * args)
6158 u8 ** maskp = va_arg (*args, u8 **);
6173 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) {
6174 if (unformat (input, "src"))
6176 else if (unformat (input, "dst"))
6178 else if (unformat (input, "proto"))
6180 else if (unformat (input, "tag1"))
6182 else if (unformat (input, "tag2"))
6184 else if (unformat (input, "ignore-tag1"))
6186 else if (unformat (input, "ignore-tag2"))
6188 else if (unformat (input, "cos1"))
6190 else if (unformat (input, "cos2"))
6192 else if (unformat (input, "dot1q"))
6194 else if (unformat (input, "dot1ad"))
6199 if ((src + dst + proto + tag1 + tag2 + dot1q + dot1ad +
6200 ignore_tag1 + ignore_tag2 + cos1 + cos2) == 0)
6203 if (tag1 || ignore_tag1 || cos1 || dot1q)
6205 if (tag2 || ignore_tag2 || cos2 || dot1ad)
6208 vec_validate (mask, len-1);
6211 memset (mask, 0xff, 6);
6214 memset (mask + 6, 0xff, 6);
6218 /* inner vlan tag */
6227 mask[21] = mask [20] = 0xff;
6248 mask[16] = mask [17] = 0xff;
6258 mask[12] = mask [13] = 0xff;
6264 uword unformat_classify_mask (unformat_input_t * input, va_list * args)
6266 u8 ** maskp = va_arg (*args, u8 **);
6267 u32 * skipp = va_arg (*args, u32 *);
6268 u32 * matchp = va_arg (*args, u32 *);
6275 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) {
6276 if (unformat (input, "hex %U", unformat_hex_string, &mask))
6278 else if (unformat (input, "l2 %U", unformat_l2_mask, &l2))
6280 else if (unformat (input, "l3 %U", unformat_l3_mask, &l3))
6286 if (mask || l2 || l3)
6290 /* "With a free Ethernet header in every package" */
6292 vec_validate (l2, 13);
6294 vec_append (mask, l3);
6298 /* Scan forward looking for the first significant mask octet */
6299 for (i = 0; i < vec_len (mask); i++)
6303 /* compute (skip, match) params */
6304 *skipp = i / sizeof(u32x4);
6305 vec_delete (mask, *skipp * sizeof(u32x4), 0);
6307 /* Pad mask to an even multiple of the vector size */
6308 while (vec_len (mask) % sizeof (u32x4))
6311 match = vec_len (mask) / sizeof (u32x4);
6313 for (i = match*sizeof(u32x4); i > 0; i-= sizeof(u32x4))
6315 u64 *tmp = (u64 *)(mask + (i-sizeof(u32x4)));
6316 if (*tmp || *(tmp+1))
6321 clib_warning ("BUG: match 0");
6323 _vec_len (mask) = match * sizeof(u32x4);
6334 #define foreach_l2_next \
6336 _(ethernet, ETHERNET_INPUT) \
6340 uword unformat_l2_next_index (unformat_input_t * input, va_list * args)
6342 u32 * miss_next_indexp = va_arg (*args, u32 *);
6347 if (unformat (input, #n)) { next_index = L2_CLASSIFY_NEXT_##N; goto out;}
6351 if (unformat (input, "%d", &tmp))
6360 *miss_next_indexp = next_index;
6364 #define foreach_ip_next \
6370 uword unformat_ip_next_index (unformat_input_t * input, va_list * args)
6372 u32 * miss_next_indexp = va_arg (*args, u32 *);
6377 if (unformat (input, #n)) { next_index = IP_LOOKUP_NEXT_##N; goto out;}
6381 if (unformat (input, "%d", &tmp))
6390 *miss_next_indexp = next_index;
6394 #define foreach_acl_next \
6397 uword unformat_acl_next_index (unformat_input_t * input, va_list * args)
6399 u32 * miss_next_indexp = va_arg (*args, u32 *);
6404 if (unformat (input, #n)) { next_index = ACL_NEXT_INDEX_##N; goto out;}
6408 if (unformat (input, "permit"))
6413 else if (unformat (input, "%d", &tmp))
6422 *miss_next_indexp = next_index;
6426 static int api_classify_add_del_table (vat_main_t * vam)
6428 unformat_input_t * i = vam->input;
6429 vl_api_classify_add_del_table_t *mp;
6435 u32 table_index = ~0;
6436 u32 next_table_index = ~0;
6437 u32 miss_next_index = ~0;
6438 u32 memory_size = 32<<20;
6442 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
6443 if (unformat (i, "del"))
6445 else if (unformat (i, "buckets %d", &nbuckets))
6447 else if (unformat (i, "memory_size %d", &memory_size))
6449 else if (unformat (i, "skip %d", &skip))
6451 else if (unformat (i, "match %d", &match))
6453 else if (unformat (i, "table %d", &table_index))
6455 else if (unformat (i, "mask %U", unformat_classify_mask,
6456 &mask, &skip, &match))
6458 else if (unformat (i, "next-table %d", &next_table_index))
6460 else if (unformat (i, "miss-next %U", unformat_ip_next_index,
6463 else if (unformat (i, "l2-miss-next %U", unformat_l2_next_index,
6466 else if (unformat (i, "acl-miss-next %U", unformat_acl_next_index,
6473 if (is_add && mask == 0) {
6474 errmsg ("Mask required\n");
6478 if (is_add && skip == ~0) {
6479 errmsg ("skip count required\n");
6483 if (is_add && match == ~0) {
6484 errmsg ("match count required\n");
6488 if (!is_add && table_index == ~0) {
6489 errmsg ("table index required for delete\n");
6493 M2 (CLASSIFY_ADD_DEL_TABLE, classify_add_del_table,
6496 mp->is_add = is_add;
6497 mp->table_index = ntohl(table_index);
6498 mp->nbuckets = ntohl(nbuckets);
6499 mp->memory_size = ntohl(memory_size);
6500 mp->skip_n_vectors = ntohl(skip);
6501 mp->match_n_vectors = ntohl(match);
6502 mp->next_table_index = ntohl(next_table_index);
6503 mp->miss_next_index = ntohl(miss_next_index);
6504 clib_memcpy (mp->mask, mask, vec_len(mask));
6512 uword unformat_ip4_match (unformat_input_t * input, va_list * args)
6514 u8 ** matchp = va_arg (*args, u8 **);
6521 int src = 0, dst = 0;
6522 ip4_address_t src_val, dst_val;
6529 int fragment_id = 0;
6530 u32 fragment_id_val;
6536 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
6538 if (unformat (input, "version %d", &version_val))
6540 else if (unformat (input, "hdr_length %d", &hdr_length_val))
6542 else if (unformat (input, "src %U", unformat_ip4_address, &src_val))
6544 else if (unformat (input, "dst %U", unformat_ip4_address, &dst_val))
6546 else if (unformat (input, "proto %d", &proto_val))
6548 else if (unformat (input, "tos %d", &tos_val))
6550 else if (unformat (input, "length %d", &length_val))
6552 else if (unformat (input, "fragment_id %d", &fragment_id_val))
6554 else if (unformat (input, "ttl %d", &ttl_val))
6556 else if (unformat (input, "checksum %d", &checksum_val))
6562 if (version + hdr_length + src + dst + proto + tos + length + fragment_id
6563 + ttl + checksum == 0)
6567 * Aligned because we use the real comparison functions
6569 vec_validate_aligned (match, sizeof (*ip) - 1, sizeof(u32x4));
6571 ip = (ip4_header_t *) match;
6573 /* These are realistically matched in practice */
6575 ip->src_address.as_u32 = src_val.as_u32;
6578 ip->dst_address.as_u32 = dst_val.as_u32;
6581 ip->protocol = proto_val;
6584 /* These are not, but they're included for completeness */
6586 ip->ip_version_and_header_length |= (version_val & 0xF)<<4;
6589 ip->ip_version_and_header_length |= (hdr_length_val & 0xF);
6595 ip->length = length_val;
6601 ip->checksum = checksum_val;
6607 uword unformat_ip6_match (unformat_input_t * input, va_list * args)
6609 u8 ** matchp = va_arg (*args, u8 **);
6615 u32 traffic_class_val;
6618 int src = 0, dst = 0;
6619 ip6_address_t src_val, dst_val;
6622 int payload_length = 0;
6623 u32 payload_length_val;
6626 u32 ip_version_traffic_class_and_flow_label;
6628 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
6630 if (unformat (input, "version %d", &version_val))
6632 else if (unformat (input, "traffic_class %d", &traffic_class_val))
6634 else if (unformat (input, "flow_label %d", &flow_label_val))
6636 else if (unformat (input, "src %U", unformat_ip6_address, &src_val))
6638 else if (unformat (input, "dst %U", unformat_ip6_address, &dst_val))
6640 else if (unformat (input, "proto %d", &proto_val))
6642 else if (unformat (input, "payload_length %d", &payload_length_val))
6644 else if (unformat (input, "hop_limit %d", &hop_limit_val))
6650 if (version + traffic_class + flow_label + src + dst + proto +
6651 payload_length + hop_limit == 0)
6655 * Aligned because we use the real comparison functions
6657 vec_validate_aligned (match, sizeof (*ip) - 1, sizeof(u32x4));
6659 ip = (ip6_header_t *) match;
6662 clib_memcpy (&ip->src_address, &src_val, sizeof (ip->src_address));
6665 clib_memcpy (&ip->dst_address, &dst_val, sizeof (ip->dst_address));
6668 ip->protocol = proto_val;
6670 ip_version_traffic_class_and_flow_label = 0;
6673 ip_version_traffic_class_and_flow_label |= (version_val & 0xF) << 28;
6676 ip_version_traffic_class_and_flow_label |= (traffic_class_val & 0xFF) << 20;
6679 ip_version_traffic_class_and_flow_label |= (flow_label_val & 0xFFFFF);
6681 ip->ip_version_traffic_class_and_flow_label =
6682 clib_host_to_net_u32 (ip_version_traffic_class_and_flow_label);
6685 ip->payload_length = clib_host_to_net_u16 (payload_length_val);
6688 ip->hop_limit = hop_limit_val;
6694 uword unformat_l3_match (unformat_input_t * input, va_list * args)
6696 u8 ** matchp = va_arg (*args, u8 **);
6698 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) {
6699 if (unformat (input, "ip4 %U", unformat_ip4_match, matchp))
6701 else if (unformat (input, "ip6 %U", unformat_ip6_match, matchp))
6709 uword unformat_vlan_tag (unformat_input_t * input, va_list * args)
6711 u8 * tagp = va_arg (*args, u8 *);
6714 if (unformat(input, "%d", &tag))
6716 tagp[0] = (tag>>8) & 0x0F;
6717 tagp[1] = tag & 0xFF;
6724 uword unformat_l2_match (unformat_input_t * input, va_list * args)
6726 u8 ** matchp = va_arg (*args, u8 **);
6746 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) {
6747 if (unformat (input, "src %U", unformat_ethernet_address, &src_val))
6749 else if (unformat (input, "dst %U", unformat_ethernet_address, &dst_val))
6751 else if (unformat (input, "proto %U",
6752 unformat_ethernet_type_host_byte_order, &proto_val))
6754 else if (unformat (input, "tag1 %U", unformat_vlan_tag, tag1_val))
6756 else if (unformat (input, "tag2 %U", unformat_vlan_tag, tag2_val))
6758 else if (unformat (input, "ignore-tag1"))
6760 else if (unformat (input, "ignore-tag2"))
6762 else if (unformat (input, "cos1 %d", &cos1_val))
6764 else if (unformat (input, "cos2 %d", &cos2_val))
6769 if ((src + dst + proto + tag1 + tag2 +
6770 ignore_tag1 + ignore_tag2 + cos1 + cos2) == 0)
6773 if (tag1 || ignore_tag1 || cos1)
6775 if (tag2 || ignore_tag2 || cos2)
6778 vec_validate_aligned (match, len-1, sizeof(u32x4));
6781 clib_memcpy (match, dst_val, 6);
6784 clib_memcpy (match + 6, src_val, 6);
6788 /* inner vlan tag */
6789 match[19] = tag2_val[1];
6790 match[18] = tag2_val[0];
6792 match [18] |= (cos2_val & 0x7) << 5;
6795 match[21] = proto_val & 0xff;
6796 match[20] = proto_val >> 8;
6800 match [15] = tag1_val[1];
6801 match [14] = tag1_val[0];
6804 match [14] |= (cos1_val & 0x7) << 5;
6810 match [15] = tag1_val[1];
6811 match [14] = tag1_val[0];
6814 match[17] = proto_val & 0xff;
6815 match[16] = proto_val >> 8;
6818 match [14] |= (cos1_val & 0x7) << 5;
6824 match [18] |= (cos2_val & 0x7) << 5;
6826 match [14] |= (cos1_val & 0x7) << 5;
6829 match[13] = proto_val & 0xff;
6830 match[12] = proto_val >> 8;
6838 uword unformat_classify_match (unformat_input_t * input, va_list * args)
6840 u8 ** matchp = va_arg (*args, u8 **);
6841 u32 skip_n_vectors = va_arg (*args, u32);
6842 u32 match_n_vectors = va_arg (*args, u32);
6848 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) {
6849 if (unformat (input, "hex %U", unformat_hex_string, &match))
6851 else if (unformat (input, "l2 %U", unformat_l2_match, &l2))
6853 else if (unformat (input, "l3 %U", unformat_l3_match, &l3))
6859 if (match || l2 || l3)
6863 /* "Win a free Ethernet header in every packet" */
6865 vec_validate_aligned (l2, 13, sizeof(u32x4));
6867 vec_append_aligned (match, l3, sizeof(u32x4));
6871 /* Make sure the vector is big enough even if key is all 0's */
6872 vec_validate_aligned
6873 (match, ((match_n_vectors + skip_n_vectors) * sizeof(u32x4)) - 1,
6876 /* Set size, include skipped vectors*/
6877 _vec_len (match) = (match_n_vectors+skip_n_vectors) * sizeof(u32x4);
6887 static int api_classify_add_del_session (vat_main_t * vam)
6889 unformat_input_t * i = vam->input;
6890 vl_api_classify_add_del_session_t *mp;
6892 u32 table_index = ~0;
6893 u32 hit_next_index = ~0;
6894 u32 opaque_index = ~0;
6898 u32 skip_n_vectors = 0;
6899 u32 match_n_vectors = 0;
6902 * Warning: you have to supply skip_n and match_n
6903 * because the API client cant simply look at the classify
6907 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
6908 if (unformat (i, "del"))
6910 else if (unformat (i, "hit-next %U", unformat_ip_next_index,
6913 else if (unformat (i, "l2-hit-next %U", unformat_l2_next_index,
6916 else if (unformat (i, "acl-hit-next %U", unformat_acl_next_index,
6919 else if (unformat (i, "opaque-index %d", &opaque_index))
6921 else if (unformat (i, "skip_n %d", &skip_n_vectors))
6923 else if (unformat (i, "match_n %d", &match_n_vectors))
6925 else if (unformat (i, "match %U", unformat_classify_match,
6926 &match, skip_n_vectors, match_n_vectors))
6928 else if (unformat (i, "advance %d", &advance))
6930 else if (unformat (i, "table-index %d", &table_index))
6936 if (table_index == ~0) {
6937 errmsg ("Table index required\n");
6941 if (is_add && match == 0) {
6942 errmsg ("Match value required\n");
6946 M2 (CLASSIFY_ADD_DEL_SESSION, classify_add_del_session,
6949 mp->is_add = is_add;
6950 mp->table_index = ntohl(table_index);
6951 mp->hit_next_index = ntohl(hit_next_index);
6952 mp->opaque_index = ntohl(opaque_index);
6953 mp->advance = ntohl(advance);
6954 clib_memcpy (mp->match, match, vec_len(match));
6961 static int api_classify_set_interface_ip_table (vat_main_t * vam)
6963 unformat_input_t * i = vam->input;
6964 vl_api_classify_set_interface_ip_table_t *mp;
6967 int sw_if_index_set;
6968 u32 table_index = ~0;
6971 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
6972 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
6973 sw_if_index_set = 1;
6974 else if (unformat (i, "sw_if_index %d", &sw_if_index))
6975 sw_if_index_set = 1;
6976 else if (unformat (i, "table %d", &table_index))
6979 clib_warning ("parse error '%U'", format_unformat_error, i);
6984 if (sw_if_index_set == 0) {
6985 errmsg ("missing interface name or sw_if_index\n");
6990 M(CLASSIFY_SET_INTERFACE_IP_TABLE, classify_set_interface_ip_table);
6992 mp->sw_if_index = ntohl(sw_if_index);
6993 mp->table_index = ntohl(table_index);
6994 mp->is_ipv6 = is_ipv6;
7001 static int api_classify_set_interface_l2_tables (vat_main_t * vam)
7003 unformat_input_t * i = vam->input;
7004 vl_api_classify_set_interface_l2_tables_t *mp;
7007 int sw_if_index_set;
7008 u32 ip4_table_index = ~0;
7009 u32 ip6_table_index = ~0;
7010 u32 other_table_index = ~0;
7012 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
7013 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
7014 sw_if_index_set = 1;
7015 else if (unformat (i, "sw_if_index %d", &sw_if_index))
7016 sw_if_index_set = 1;
7017 else if (unformat (i, "ip4-table %d", &ip4_table_index))
7019 else if (unformat (i, "ip6-table %d", &ip6_table_index))
7021 else if (unformat (i, "other-table %d", &other_table_index))
7024 clib_warning ("parse error '%U'", format_unformat_error, i);
7029 if (sw_if_index_set == 0) {
7030 errmsg ("missing interface name or sw_if_index\n");
7035 M(CLASSIFY_SET_INTERFACE_L2_TABLES, classify_set_interface_l2_tables);
7037 mp->sw_if_index = ntohl(sw_if_index);
7038 mp->ip4_table_index = ntohl(ip4_table_index);
7039 mp->ip6_table_index = ntohl(ip6_table_index);
7040 mp->other_table_index = ntohl(other_table_index);
7048 static int api_get_node_index (vat_main_t * vam)
7050 unformat_input_t * i = vam->input;
7051 vl_api_get_node_index_t * mp;
7055 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
7056 if (unformat (i, "node %s", &name))
7062 errmsg ("node name required\n");
7065 if (vec_len (name) >= ARRAY_LEN(mp->node_name)) {
7066 errmsg ("node name too long, max %d\n", ARRAY_LEN(mp->node_name));
7070 M(GET_NODE_INDEX, get_node_index);
7071 clib_memcpy (mp->node_name, name, vec_len(name));
7079 static int api_add_node_next (vat_main_t * vam)
7081 unformat_input_t * i = vam->input;
7082 vl_api_add_node_next_t * mp;
7087 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
7088 if (unformat (i, "node %s", &name))
7090 else if (unformat (i, "next %s", &next))
7096 errmsg ("node name required\n");
7099 if (vec_len (name) >= ARRAY_LEN(mp->node_name)) {
7100 errmsg ("node name too long, max %d\n", ARRAY_LEN(mp->node_name));
7104 errmsg ("next node required\n");
7107 if (vec_len (next) >= ARRAY_LEN(mp->next_name)) {
7108 errmsg ("next name too long, max %d\n", ARRAY_LEN(mp->next_name));
7112 M(ADD_NODE_NEXT, add_node_next);
7113 clib_memcpy (mp->node_name, name, vec_len(name));
7114 clib_memcpy (mp->next_name, next, vec_len(next));
7123 static int api_l2tpv3_create_tunnel (vat_main_t * vam)
7125 unformat_input_t * i = vam->input;
7126 ip6_address_t client_address, our_address;
7127 int client_address_set = 0;
7128 int our_address_set = 0;
7129 u32 local_session_id = 0;
7130 u32 remote_session_id = 0;
7131 u64 local_cookie = 0;
7132 u64 remote_cookie = 0;
7133 u8 l2_sublayer_present = 0;
7134 vl_api_l2tpv3_create_tunnel_t * mp;
7137 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
7138 if (unformat (i, "client_address %U", unformat_ip6_address,
7140 client_address_set = 1;
7141 else if (unformat (i, "our_address %U", unformat_ip6_address,
7143 our_address_set = 1;
7144 else if (unformat (i, "local_session_id %d", &local_session_id))
7146 else if (unformat (i, "remote_session_id %d", &remote_session_id))
7148 else if (unformat (i, "local_cookie %lld", &local_cookie))
7150 else if (unformat (i, "remote_cookie %lld", &remote_cookie))
7152 else if (unformat (i, "l2-sublayer-present"))
7153 l2_sublayer_present = 1;
7158 if (client_address_set == 0) {
7159 errmsg ("client_address required\n");
7163 if (our_address_set == 0) {
7164 errmsg ("our_address required\n");
7168 M(L2TPV3_CREATE_TUNNEL, l2tpv3_create_tunnel);
7170 clib_memcpy (mp->client_address, client_address.as_u8,
7171 sizeof (mp->client_address));
7173 clib_memcpy (mp->our_address, our_address.as_u8,
7174 sizeof (mp->our_address));
7176 mp->local_session_id = ntohl (local_session_id);
7177 mp->remote_session_id = ntohl (remote_session_id);
7178 mp->local_cookie = clib_host_to_net_u64 (local_cookie);
7179 mp->remote_cookie = clib_host_to_net_u64 (remote_cookie);
7180 mp->l2_sublayer_present = l2_sublayer_present;
7188 static int api_l2tpv3_set_tunnel_cookies (vat_main_t * vam)
7190 unformat_input_t * i = vam->input;
7192 u8 sw_if_index_set = 0;
7193 u64 new_local_cookie = 0;
7194 u64 new_remote_cookie = 0;
7195 vl_api_l2tpv3_set_tunnel_cookies_t *mp;
7198 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
7199 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
7200 sw_if_index_set = 1;
7201 else if (unformat (i, "sw_if_index %d", &sw_if_index))
7202 sw_if_index_set = 1;
7203 else if (unformat (i, "new_local_cookie %lld", &new_local_cookie))
7205 else if (unformat (i, "new_remote_cookie %lld", &new_remote_cookie))
7211 if (sw_if_index_set == 0) {
7212 errmsg ("missing interface name or sw_if_index\n");
7216 M(L2TPV3_SET_TUNNEL_COOKIES, l2tpv3_set_tunnel_cookies);
7218 mp->sw_if_index = ntohl(sw_if_index);
7219 mp->new_local_cookie = clib_host_to_net_u64 (new_local_cookie);
7220 mp->new_remote_cookie = clib_host_to_net_u64 (new_remote_cookie);
7227 static int api_l2tpv3_interface_enable_disable (vat_main_t * vam)
7229 unformat_input_t * i = vam->input;
7230 vl_api_l2tpv3_interface_enable_disable_t *mp;
7233 u8 sw_if_index_set = 0;
7234 u8 enable_disable = 1;
7236 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
7237 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
7238 sw_if_index_set = 1;
7239 else if (unformat (i, "sw_if_index %d", &sw_if_index))
7240 sw_if_index_set = 1;
7241 else if (unformat (i, "enable"))
7243 else if (unformat (i, "disable"))
7249 if (sw_if_index_set == 0) {
7250 errmsg ("missing interface name or sw_if_index\n");
7254 M(L2TPV3_INTERFACE_ENABLE_DISABLE, l2tpv3_interface_enable_disable);
7256 mp->sw_if_index = ntohl(sw_if_index);
7257 mp->enable_disable = enable_disable;
7264 static int api_l2tpv3_set_lookup_key (vat_main_t * vam)
7266 unformat_input_t * i = vam->input;
7267 vl_api_l2tpv3_set_lookup_key_t * mp;
7271 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
7272 if (unformat (i, "lookup_v6_src"))
7273 key = L2T_LOOKUP_SRC_ADDRESS;
7274 else if (unformat (i, "lookup_v6_dst"))
7275 key = L2T_LOOKUP_DST_ADDRESS;
7276 else if (unformat (i, "lookup_session_id"))
7277 key = L2T_LOOKUP_SESSION_ID;
7282 if (key == (u8) ~0) {
7283 errmsg ("l2tp session lookup key unset\n");
7287 M(L2TPV3_SET_LOOKUP_KEY, l2tpv3_set_lookup_key);
7296 static void vl_api_sw_if_l2tpv3_tunnel_details_t_handler
7297 (vl_api_sw_if_l2tpv3_tunnel_details_t * mp)
7299 vat_main_t * vam = &vat_main;
7301 fformat(vam->ofp, "* %U (our) %U (client) (sw_if_index %d)\n",
7302 format_ip6_address, mp->our_address,
7303 format_ip6_address, mp->client_address,
7304 clib_net_to_host_u32(mp->sw_if_index));
7306 fformat (vam->ofp, " local cookies %016llx %016llx remote cookie %016llx\n",
7307 clib_net_to_host_u64 (mp->local_cookie[0]),
7308 clib_net_to_host_u64 (mp->local_cookie[1]),
7309 clib_net_to_host_u64 (mp->remote_cookie));
7311 fformat (vam->ofp, " local session-id %d remote session-id %d\n",
7312 clib_net_to_host_u32 (mp->local_session_id),
7313 clib_net_to_host_u32 (mp->remote_session_id));
7315 fformat (vam->ofp, " l2 specific sublayer %s\n\n",
7316 mp->l2_sublayer_present ? "preset" : "absent");
7320 static void vl_api_sw_if_l2tpv3_tunnel_details_t_handler_json
7321 (vl_api_sw_if_l2tpv3_tunnel_details_t * mp)
7323 vat_main_t * vam = &vat_main;
7324 vat_json_node_t *node = NULL;
7325 struct in6_addr addr;
7327 if (VAT_JSON_ARRAY != vam->json_tree.type) {
7328 ASSERT(VAT_JSON_NONE == vam->json_tree.type);
7329 vat_json_init_array(&vam->json_tree);
7331 node = vat_json_array_add(&vam->json_tree);
7333 vat_json_init_object(node);
7335 clib_memcpy(&addr, mp->our_address, sizeof(addr));
7336 vat_json_object_add_ip6(node, "our_address", addr);
7337 clib_memcpy(&addr, mp->client_address, sizeof(addr));
7338 vat_json_object_add_ip6(node, "client_address", addr);
7340 vat_json_node_t * lc = vat_json_object_add(node, "local_cookie");
7341 vat_json_init_array(lc);
7342 vat_json_array_add_uint(lc, clib_net_to_host_u64(mp->local_cookie[0]));
7343 vat_json_array_add_uint(lc, clib_net_to_host_u64(mp->local_cookie[1]));
7344 vat_json_object_add_uint(node, "remote_cookie", clib_net_to_host_u64(mp->remote_cookie));
7346 printf("local id: %u", clib_net_to_host_u32(mp->local_session_id));
7347 vat_json_object_add_uint(node, "local_session_id", clib_net_to_host_u32(mp->local_session_id));
7348 vat_json_object_add_uint(node, "remote_session_id", clib_net_to_host_u32(mp->remote_session_id));
7349 vat_json_object_add_string_copy(node, "l2_sublayer", mp->l2_sublayer_present ?
7350 (u8*)"present" : (u8*)"absent");
7353 static int api_sw_if_l2tpv3_tunnel_dump (vat_main_t * vam)
7355 vl_api_sw_if_l2tpv3_tunnel_dump_t *mp;
7358 /* Get list of l2tpv3-tunnel interfaces */
7359 M(SW_IF_L2TPV3_TUNNEL_DUMP, sw_if_l2tpv3_tunnel_dump);
7362 /* Use a control ping for synchronization */
7364 vl_api_control_ping_t * mp;
7365 M(CONTROL_PING, control_ping);
7372 static void vl_api_sw_interface_tap_details_t_handler
7373 (vl_api_sw_interface_tap_details_t * mp)
7375 vat_main_t * vam = &vat_main;
7377 fformat(vam->ofp, "%-16s %d\n",
7379 clib_net_to_host_u32(mp->sw_if_index));
7382 static void vl_api_sw_interface_tap_details_t_handler_json
7383 (vl_api_sw_interface_tap_details_t * mp)
7385 vat_main_t * vam = &vat_main;
7386 vat_json_node_t *node = NULL;
7388 if (VAT_JSON_ARRAY != vam->json_tree.type) {
7389 ASSERT(VAT_JSON_NONE == vam->json_tree.type);
7390 vat_json_init_array(&vam->json_tree);
7392 node = vat_json_array_add(&vam->json_tree);
7394 vat_json_init_object(node);
7395 vat_json_object_add_uint(node, "sw_if_index", ntohl(mp->sw_if_index));
7396 vat_json_object_add_string_copy(node, "dev_name", mp->dev_name);
7399 static int api_sw_interface_tap_dump (vat_main_t * vam)
7401 vl_api_sw_interface_tap_dump_t *mp;
7404 fformat(vam->ofp, "\n%-16s %s\n", "dev_name", "sw_if_index");
7405 /* Get list of tap interfaces */
7406 M(SW_INTERFACE_TAP_DUMP, sw_interface_tap_dump);
7409 /* Use a control ping for synchronization */
7411 vl_api_control_ping_t * mp;
7412 M(CONTROL_PING, control_ping);
7418 static uword unformat_vxlan_decap_next
7419 (unformat_input_t * input, va_list * args)
7421 u32 * result = va_arg (*args, u32 *);
7424 if (unformat (input, "drop"))
7425 *result = VXLAN_INPUT_NEXT_DROP;
7426 else if (unformat (input, "ip4"))
7427 *result = VXLAN_INPUT_NEXT_IP4_INPUT;
7428 else if (unformat (input, "ip6"))
7429 *result = VXLAN_INPUT_NEXT_IP6_INPUT;
7430 else if (unformat (input, "l2"))
7431 *result = VXLAN_INPUT_NEXT_L2_INPUT;
7432 else if (unformat (input, "%d", &tmp))
7439 static int api_vxlan_add_del_tunnel (vat_main_t * vam)
7441 unformat_input_t * line_input = vam->input;
7442 vl_api_vxlan_add_del_tunnel_t *mp;
7444 ip4_address_t src4, dst4;
7445 ip6_address_t src6, dst6;
7447 u8 ipv4_set = 0, ipv6_set = 0;
7450 u32 encap_vrf_id = 0;
7451 u32 decap_next_index = ~0;
7454 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) {
7455 if (unformat (line_input, "del"))
7457 else if (unformat (line_input, "src %U",
7458 unformat_ip4_address, &src4))
7463 else if (unformat (line_input, "dst %U",
7464 unformat_ip4_address, &dst4))
7469 else if (unformat (line_input, "src %U",
7470 unformat_ip6_address, &src6))
7475 else if (unformat (line_input, "dst %U",
7476 unformat_ip6_address, &dst6))
7481 else if (unformat (line_input, "encap-vrf-id %d", &encap_vrf_id))
7483 else if (unformat (line_input, "decap-next %U",
7484 unformat_vxlan_decap_next, &decap_next_index))
7486 else if (unformat (line_input, "vni %d", &vni))
7489 errmsg ("parse error '%U'\n", format_unformat_error, line_input);
7495 errmsg ("tunnel src address not specified\n");
7499 errmsg ("tunnel dst address not specified\n");
7503 if (ipv4_set && ipv6_set) {
7504 errmsg ("both IPv4 and IPv6 addresses specified");
7508 if ((vni == 0) || (vni>>24)) {
7509 errmsg ("vni not specified or out of range\n");
7513 M (VXLAN_ADD_DEL_TUNNEL, vxlan_add_del_tunnel);
7516 clib_memcpy(&mp->src_address, &src6, sizeof(src6));
7517 clib_memcpy(&mp->dst_address, &dst6, sizeof(dst6));
7519 clib_memcpy(&mp->src_address, &src4, sizeof(src4));
7520 clib_memcpy(&mp->dst_address, &dst4, sizeof(dst4));
7522 mp->encap_vrf_id = ntohl(encap_vrf_id);
7523 mp->decap_next_index = ntohl(decap_next_index);
7524 mp->vni = ntohl(vni);
7525 mp->is_add = is_add;
7526 mp->is_ipv6 = ipv6_set;
7533 static void vl_api_vxlan_tunnel_details_t_handler
7534 (vl_api_vxlan_tunnel_details_t * mp)
7536 vat_main_t * vam = &vat_main;
7538 fformat(vam->ofp, "%11d%24U%24U%14d%18d%13d\n",
7539 ntohl(mp->sw_if_index),
7540 format_ip46_address, &(mp->src_address[0]),
7542 format_ip46_address, &(mp->dst_address[0]),
7544 ntohl(mp->encap_vrf_id),
7545 ntohl(mp->decap_next_index),
7549 static void vl_api_vxlan_tunnel_details_t_handler_json
7550 (vl_api_vxlan_tunnel_details_t * mp)
7552 vat_main_t * vam = &vat_main;
7553 vat_json_node_t *node = NULL;
7555 struct in6_addr ip6;
7557 if (VAT_JSON_ARRAY != vam->json_tree.type) {
7558 ASSERT(VAT_JSON_NONE == vam->json_tree.type);
7559 vat_json_init_array(&vam->json_tree);
7561 node = vat_json_array_add(&vam->json_tree);
7563 vat_json_init_object(node);
7564 vat_json_object_add_uint(node, "sw_if_index", ntohl(mp->sw_if_index));
7566 clib_memcpy(&ip6, &(mp->src_address[0]), sizeof(ip6));
7567 vat_json_object_add_ip6(node, "src_address", ip6);
7568 clib_memcpy(&ip6, &(mp->dst_address[0]), sizeof(ip6));
7569 vat_json_object_add_ip6(node, "dst_address", ip6);
7571 clib_memcpy(&ip4, &(mp->src_address[0]), sizeof(ip4));
7572 vat_json_object_add_ip4(node, "src_address", ip4);
7573 clib_memcpy(&ip4, &(mp->dst_address[0]), sizeof(ip4));
7574 vat_json_object_add_ip4(node, "dst_address", ip4);
7576 vat_json_object_add_uint(node, "encap_vrf_id", ntohl(mp->encap_vrf_id));
7577 vat_json_object_add_uint(node, "decap_next_index", ntohl(mp->decap_next_index));
7578 vat_json_object_add_uint(node, "vni", ntohl(mp->vni));
7579 vat_json_object_add_uint(node, "is_ipv6", mp->is_ipv6 ? 1 : 0);
7582 static int api_vxlan_tunnel_dump (vat_main_t * vam)
7584 unformat_input_t * i = vam->input;
7585 vl_api_vxlan_tunnel_dump_t *mp;
7588 u8 sw_if_index_set = 0;
7590 /* Parse args required to build the message */
7591 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
7592 if (unformat (i, "sw_if_index %d", &sw_if_index))
7593 sw_if_index_set = 1;
7598 if (sw_if_index_set == 0) {
7602 if (!vam->json_output) {
7603 fformat(vam->ofp, "%11s%24s%24s%14s%18s%13s\n",
7604 "sw_if_index", "src_address", "dst_address",
7605 "encap_vrf_id", "decap_next_index", "vni");
7608 /* Get list of vxlan-tunnel interfaces */
7609 M(VXLAN_TUNNEL_DUMP, vxlan_tunnel_dump);
7611 mp->sw_if_index = htonl(sw_if_index);
7615 /* Use a control ping for synchronization */
7617 vl_api_control_ping_t * mp;
7618 M(CONTROL_PING, control_ping);
7624 static int api_gre_add_del_tunnel (vat_main_t * vam)
7626 unformat_input_t * line_input = vam->input;
7627 vl_api_gre_add_del_tunnel_t *mp;
7629 ip4_address_t src4, dst4;
7633 u32 outer_fib_id = 0;
7635 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) {
7636 if (unformat (line_input, "del"))
7638 else if (unformat (line_input, "src %U",
7639 unformat_ip4_address, &src4))
7641 else if (unformat (line_input, "dst %U",
7642 unformat_ip4_address, &dst4))
7644 else if (unformat (line_input, "outer-fib-id %d", &outer_fib_id))
7647 errmsg ("parse error '%U'\n", format_unformat_error, line_input);
7653 errmsg ("tunnel src address not specified\n");
7657 errmsg ("tunnel dst address not specified\n");
7662 M (GRE_ADD_DEL_TUNNEL, gre_add_del_tunnel);
7664 clib_memcpy(&mp->src_address, &src4, sizeof(src4));
7665 clib_memcpy(&mp->dst_address, &dst4, sizeof(dst4));
7666 mp->outer_table_id = ntohl(outer_fib_id);
7667 mp->is_add = is_add;
7674 static void vl_api_gre_tunnel_details_t_handler
7675 (vl_api_gre_tunnel_details_t * mp)
7677 vat_main_t * vam = &vat_main;
7679 fformat(vam->ofp, "%11d%15U%15U%14d\n",
7680 ntohl(mp->sw_if_index),
7681 format_ip4_address, &mp->src_address,
7682 format_ip4_address, &mp->dst_address,
7683 ntohl(mp->outer_table_id));
7686 static void vl_api_gre_tunnel_details_t_handler_json
7687 (vl_api_gre_tunnel_details_t * mp)
7689 vat_main_t * vam = &vat_main;
7690 vat_json_node_t *node = NULL;
7693 if (VAT_JSON_ARRAY != vam->json_tree.type) {
7694 ASSERT(VAT_JSON_NONE == vam->json_tree.type);
7695 vat_json_init_array(&vam->json_tree);
7697 node = vat_json_array_add(&vam->json_tree);
7699 vat_json_init_object(node);
7700 vat_json_object_add_uint(node, "sw_if_index", ntohl(mp->sw_if_index));
7701 clib_memcpy(&ip4, &mp->src_address, sizeof(ip4));
7702 vat_json_object_add_ip4(node, "src_address", ip4);
7703 clib_memcpy(&ip4, &mp->dst_address, sizeof(ip4));
7704 vat_json_object_add_ip4(node, "dst_address", ip4);
7705 vat_json_object_add_uint(node, "outer_fib_id", ntohl(mp->outer_table_id));
7708 static int api_gre_tunnel_dump (vat_main_t * vam)
7710 unformat_input_t * i = vam->input;
7711 vl_api_gre_tunnel_dump_t *mp;
7714 u8 sw_if_index_set = 0;
7716 /* Parse args required to build the message */
7717 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
7718 if (unformat (i, "sw_if_index %d", &sw_if_index))
7719 sw_if_index_set = 1;
7724 if (sw_if_index_set == 0) {
7728 if (!vam->json_output) {
7729 fformat(vam->ofp, "%11s%15s%15s%14s\n",
7730 "sw_if_index", "src_address", "dst_address",
7734 /* Get list of gre-tunnel interfaces */
7735 M(GRE_TUNNEL_DUMP, gre_tunnel_dump);
7737 mp->sw_if_index = htonl(sw_if_index);
7741 /* Use a control ping for synchronization */
7743 vl_api_control_ping_t * mp;
7744 M(CONTROL_PING, control_ping);
7750 static int api_l2_fib_clear_table (vat_main_t * vam)
7752 // unformat_input_t * i = vam->input;
7753 vl_api_l2_fib_clear_table_t *mp;
7756 M(L2_FIB_CLEAR_TABLE, l2_fib_clear_table);
7763 static int api_l2_interface_efp_filter (vat_main_t * vam)
7765 unformat_input_t * i = vam->input;
7766 vl_api_l2_interface_efp_filter_t *mp;
7770 u8 sw_if_index_set = 0;
7772 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
7773 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
7774 sw_if_index_set = 1;
7775 else if (unformat (i, "sw_if_index %d", &sw_if_index))
7776 sw_if_index_set = 1;
7777 else if (unformat (i, "enable"))
7779 else if (unformat (i, "disable"))
7782 clib_warning ("parse error '%U'", format_unformat_error, i);
7787 if (sw_if_index_set == 0) {
7788 errmsg ("missing sw_if_index\n");
7792 M(L2_INTERFACE_EFP_FILTER, l2_interface_efp_filter);
7794 mp->sw_if_index = ntohl(sw_if_index);
7795 mp->enable_disable = enable;
7802 #define foreach_vtr_op \
7803 _("disable", L2_VTR_DISABLED) \
7804 _("push-1", L2_VTR_PUSH_1) \
7805 _("push-2", L2_VTR_PUSH_2) \
7806 _("pop-1", L2_VTR_POP_1) \
7807 _("pop-2", L2_VTR_POP_2) \
7808 _("translate-1-1", L2_VTR_TRANSLATE_1_1) \
7809 _("translate-1-2", L2_VTR_TRANSLATE_1_2) \
7810 _("translate-2-1", L2_VTR_TRANSLATE_2_1) \
7811 _("translate-2-2", L2_VTR_TRANSLATE_2_2)
7813 static int api_l2_interface_vlan_tag_rewrite (vat_main_t * vam)
7815 unformat_input_t * i = vam->input;
7816 vl_api_l2_interface_vlan_tag_rewrite_t *mp;
7819 u8 sw_if_index_set = 0;
7826 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
7827 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
7828 sw_if_index_set = 1;
7829 else if (unformat (i, "sw_if_index %d", &sw_if_index))
7830 sw_if_index_set = 1;
7831 else if (unformat (i, "vtr_op %d", &vtr_op))
7833 #define _(n,v) else if (unformat(i, n)) {vtr_op = v; vtr_op_set = 1;}
7837 else if (unformat (i, "push_dot1q %d", &push_dot1q))
7839 else if (unformat (i, "tag1 %d", &tag1))
7841 else if (unformat (i, "tag2 %d", &tag2))
7844 clib_warning ("parse error '%U'", format_unformat_error, i);
7849 if ((sw_if_index_set == 0)||(vtr_op_set == 0)) {
7850 errmsg ("missing vtr operation or sw_if_index\n");
7854 M(L2_INTERFACE_VLAN_TAG_REWRITE, l2_interface_vlan_tag_rewrite)
7856 mp->sw_if_index = ntohl(sw_if_index);
7857 mp->vtr_op = ntohl(vtr_op);
7858 mp->push_dot1q = ntohl(push_dot1q);
7859 mp->tag1 = ntohl(tag1);
7860 mp->tag2 = ntohl(tag2);
7867 static int api_create_vhost_user_if (vat_main_t * vam)
7869 unformat_input_t * i = vam->input;
7870 vl_api_create_vhost_user_if_t *mp;
7874 u8 file_name_set = 0;
7875 u32 custom_dev_instance = ~0;
7877 u8 use_custom_mac = 0;
7879 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
7880 if (unformat (i, "socket %s", &file_name)) {
7883 else if (unformat (i, "renumber %"PRIu32, &custom_dev_instance))
7885 else if (unformat (i, "mac %U", unformat_ethernet_address, hwaddr))
7887 else if (unformat (i, "server"))
7893 if (file_name_set == 0) {
7894 errmsg ("missing socket file name\n");
7898 if (vec_len (file_name) > 255) {
7899 errmsg ("socket file name too long\n");
7902 vec_add1 (file_name, 0);
7904 M(CREATE_VHOST_USER_IF, create_vhost_user_if);
7906 mp->is_server = is_server;
7907 clib_memcpy(mp->sock_filename, file_name, vec_len(file_name));
7908 vec_free(file_name);
7909 if (custom_dev_instance != ~0) {
7911 mp->custom_dev_instance = ntohl(custom_dev_instance);
7913 mp->use_custom_mac = use_custom_mac;
7914 clib_memcpy(mp->mac_address, hwaddr, 6);
7921 static int api_modify_vhost_user_if (vat_main_t * vam)
7923 unformat_input_t * i = vam->input;
7924 vl_api_modify_vhost_user_if_t *mp;
7928 u8 file_name_set = 0;
7929 u32 custom_dev_instance = ~0;
7930 u8 sw_if_index_set = 0;
7931 u32 sw_if_index = (u32)~0;
7933 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
7934 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
7935 sw_if_index_set = 1;
7936 else if (unformat (i, "sw_if_index %d", &sw_if_index))
7937 sw_if_index_set = 1;
7938 else if (unformat (i, "socket %s", &file_name)) {
7941 else if (unformat (i, "renumber %"PRIu32, &custom_dev_instance))
7943 else if (unformat (i, "server"))
7949 if (sw_if_index_set == 0) {
7950 errmsg ("missing sw_if_index or interface name\n");
7954 if (file_name_set == 0) {
7955 errmsg ("missing socket file name\n");
7959 if (vec_len (file_name) > 255) {
7960 errmsg ("socket file name too long\n");
7963 vec_add1 (file_name, 0);
7965 M(MODIFY_VHOST_USER_IF, modify_vhost_user_if);
7967 mp->sw_if_index = ntohl(sw_if_index);
7968 mp->is_server = is_server;
7969 clib_memcpy(mp->sock_filename, file_name, vec_len(file_name));
7970 vec_free(file_name);
7971 if (custom_dev_instance != ~0) {
7973 mp->custom_dev_instance = ntohl(custom_dev_instance);
7981 static int api_delete_vhost_user_if (vat_main_t * vam)
7983 unformat_input_t * i = vam->input;
7984 vl_api_delete_vhost_user_if_t *mp;
7986 u32 sw_if_index = ~0;
7987 u8 sw_if_index_set = 0;
7989 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
7990 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
7991 sw_if_index_set = 1;
7992 else if (unformat (i, "sw_if_index %d", &sw_if_index))
7993 sw_if_index_set = 1;
7998 if (sw_if_index_set == 0) {
7999 errmsg ("missing sw_if_index or interface name\n");
8004 M(DELETE_VHOST_USER_IF, delete_vhost_user_if);
8006 mp->sw_if_index = ntohl(sw_if_index);
8013 static void vl_api_sw_interface_vhost_user_details_t_handler
8014 (vl_api_sw_interface_vhost_user_details_t * mp)
8016 vat_main_t * vam = &vat_main;
8018 fformat(vam->ofp, "%-25s %3" PRIu32 " %6" PRIu32 " %8x %6d %7d %s\n",
8019 (char *)mp->interface_name,
8020 ntohl(mp->sw_if_index), ntohl(mp->virtio_net_hdr_sz),
8021 clib_net_to_host_u64(mp->features), mp->is_server,
8022 ntohl(mp->num_regions), (char *)mp->sock_filename);
8023 fformat(vam->ofp, " Status: '%s'\n", strerror(ntohl(mp->sock_errno)));
8026 static void vl_api_sw_interface_vhost_user_details_t_handler_json
8027 (vl_api_sw_interface_vhost_user_details_t * mp)
8029 vat_main_t * vam = &vat_main;
8030 vat_json_node_t *node = NULL;
8032 if (VAT_JSON_ARRAY != vam->json_tree.type) {
8033 ASSERT(VAT_JSON_NONE == vam->json_tree.type);
8034 vat_json_init_array(&vam->json_tree);
8036 node = vat_json_array_add(&vam->json_tree);
8038 vat_json_init_object(node);
8039 vat_json_object_add_uint(node, "sw_if_index", ntohl(mp->sw_if_index));
8040 vat_json_object_add_string_copy(node, "interface_name", mp->interface_name);
8041 vat_json_object_add_uint(node, "virtio_net_hdr_sz", ntohl(mp->virtio_net_hdr_sz));
8042 vat_json_object_add_uint(node, "features", clib_net_to_host_u64(mp->features));
8043 vat_json_object_add_uint(node, "is_server", mp->is_server);
8044 vat_json_object_add_string_copy(node, "sock_filename", mp->sock_filename);
8045 vat_json_object_add_uint(node, "num_regions", ntohl(mp->num_regions));
8046 vat_json_object_add_uint(node, "sock_errno", ntohl(mp->sock_errno));
8049 static int api_sw_interface_vhost_user_dump (vat_main_t * vam)
8051 vl_api_sw_interface_vhost_user_dump_t *mp;
8053 fformat(vam->ofp, "Interface name idx hdr_sz features server regions filename\n");
8055 /* Get list of vhost-user interfaces */
8056 M(SW_INTERFACE_VHOST_USER_DUMP, sw_interface_vhost_user_dump);
8059 /* Use a control ping for synchronization */
8061 vl_api_control_ping_t * mp;
8062 M(CONTROL_PING, control_ping);
8068 static int api_show_version (vat_main_t * vam)
8070 vl_api_show_version_t *mp;
8073 M(SHOW_VERSION, show_version);
8081 static int api_vxlan_gpe_add_del_tunnel (vat_main_t * vam)
8083 unformat_input_t * line_input = vam->input;
8084 vl_api_vxlan_gpe_add_del_tunnel_t *mp;
8086 ip4_address_t local4, remote4;
8087 ip6_address_t local6, remote6;
8089 u8 ipv4_set = 0, ipv6_set = 0;
8092 u32 encap_vrf_id = 0;
8093 u32 decap_vrf_id = 0;
8098 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) {
8099 if (unformat (line_input, "del"))
8101 else if (unformat (line_input, "local %U",
8102 unformat_ip4_address, &local4))
8107 else if (unformat (line_input, "remote %U",
8108 unformat_ip4_address, &remote4))
8113 else if (unformat (line_input, "local %U",
8114 unformat_ip6_address, &local6))
8119 else if (unformat (line_input, "remote %U",
8120 unformat_ip6_address, &remote6))
8125 else if (unformat (line_input, "encap-vrf-id %d", &encap_vrf_id))
8127 else if (unformat (line_input, "decap-vrf-id %d", &decap_vrf_id))
8129 else if (unformat (line_input, "vni %d", &vni))
8131 else if (unformat(line_input, "next-ip4"))
8133 else if (unformat(line_input, "next-ip6"))
8135 else if (unformat(line_input, "next-ethernet"))
8137 else if (unformat(line_input, "next-nsh"))
8140 errmsg ("parse error '%U'\n", format_unformat_error, line_input);
8145 if (local_set == 0) {
8146 errmsg ("tunnel local address not specified\n");
8149 if (remote_set == 0) {
8150 errmsg ("tunnel remote address not specified\n");
8153 if (ipv4_set && ipv6_set) {
8154 errmsg ("both IPv4 and IPv6 addresses specified");
8159 errmsg ("vni not specified\n");
8163 M(VXLAN_GPE_ADD_DEL_TUNNEL, vxlan_gpe_add_del_tunnel);
8167 clib_memcpy(&mp->local, &local6, sizeof(local6));
8168 clib_memcpy(&mp->remote, &remote6, sizeof(remote6));
8170 clib_memcpy(&mp->local, &local4, sizeof(local4));
8171 clib_memcpy(&mp->remote, &remote4, sizeof(remote4));
8174 mp->encap_vrf_id = ntohl(encap_vrf_id);
8175 mp->decap_vrf_id = ntohl(decap_vrf_id);
8176 mp->protocol = ntohl(protocol);
8177 mp->vni = ntohl(vni);
8178 mp->is_add = is_add;
8179 mp->is_ipv6 = ipv6_set;
8186 static void vl_api_vxlan_gpe_tunnel_details_t_handler
8187 (vl_api_vxlan_gpe_tunnel_details_t * mp)
8189 vat_main_t * vam = &vat_main;
8191 fformat(vam->ofp, "%11d%24U%24U%13d%12d%14d%14d\n",
8192 ntohl(mp->sw_if_index),
8193 format_ip46_address, &(mp->local[0]),
8194 format_ip46_address, &(mp->remote[0]),
8196 ntohl(mp->protocol),
8197 ntohl(mp->encap_vrf_id),
8198 ntohl(mp->decap_vrf_id));
8201 static void vl_api_vxlan_gpe_tunnel_details_t_handler_json
8202 (vl_api_vxlan_gpe_tunnel_details_t * mp)
8204 vat_main_t * vam = &vat_main;
8205 vat_json_node_t *node = NULL;
8207 struct in6_addr ip6;
8209 if (VAT_JSON_ARRAY != vam->json_tree.type) {
8210 ASSERT(VAT_JSON_NONE == vam->json_tree.type);
8211 vat_json_init_array(&vam->json_tree);
8213 node = vat_json_array_add(&vam->json_tree);
8215 vat_json_init_object(node);
8216 vat_json_object_add_uint(node, "sw_if_index", ntohl(mp->sw_if_index));
8218 clib_memcpy(&ip6, &(mp->local[0]), sizeof(ip6));
8219 vat_json_object_add_ip6(node, "local", ip6);
8220 clib_memcpy(&ip6, &(mp->remote[0]), sizeof(ip6));
8221 vat_json_object_add_ip6(node, "remote", ip6);
8223 clib_memcpy(&ip4, &(mp->local[0]), sizeof(ip4));
8224 vat_json_object_add_ip4(node, "local", ip4);
8225 clib_memcpy(&ip4, &(mp->remote[0]), sizeof(ip4));
8226 vat_json_object_add_ip4(node, "remote", ip4);
8228 vat_json_object_add_uint(node, "vni", ntohl(mp->vni));
8229 vat_json_object_add_uint(node, "protocol", ntohl(mp->protocol));
8230 vat_json_object_add_uint(node, "encap_vrf_id", ntohl(mp->encap_vrf_id));
8231 vat_json_object_add_uint(node, "decap_vrf_id", ntohl(mp->decap_vrf_id));
8232 vat_json_object_add_uint(node, "is_ipv6", mp->is_ipv6 ? 1 : 0);
8235 static int api_vxlan_gpe_tunnel_dump (vat_main_t * vam)
8237 unformat_input_t * i = vam->input;
8238 vl_api_vxlan_gpe_tunnel_dump_t *mp;
8241 u8 sw_if_index_set = 0;
8243 /* Parse args required to build the message */
8244 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
8245 if (unformat (i, "sw_if_index %d", &sw_if_index))
8246 sw_if_index_set = 1;
8251 if (sw_if_index_set == 0) {
8255 if (!vam->json_output) {
8256 fformat(vam->ofp, "%11s%24s%24s%13s%15s%14s%14s\n",
8257 "sw_if_index", "local", "remote", "vni",
8258 "protocol","encap_vrf_id", "decap_vrf_id");
8261 /* Get list of vxlan-tunnel interfaces */
8262 M(VXLAN_GPE_TUNNEL_DUMP, vxlan_gpe_tunnel_dump);
8264 mp->sw_if_index = htonl(sw_if_index);
8268 /* Use a control ping for synchronization */
8270 vl_api_control_ping_t * mp;
8271 M(CONTROL_PING, control_ping);
8277 u8 * format_l2_fib_mac_address (u8 * s, va_list * args)
8279 u8 * a = va_arg (*args, u8 *);
8281 return format (s, "%02x:%02x:%02x:%02x:%02x:%02x",
8282 a[2], a[3], a[4], a[5], a[6], a[7]);
8285 static void vl_api_l2_fib_table_entry_t_handler
8286 (vl_api_l2_fib_table_entry_t * mp)
8288 vat_main_t * vam = &vat_main;
8290 fformat(vam->ofp, "%3" PRIu32 " %U %3" PRIu32
8292 ntohl(mp->bd_id), format_l2_fib_mac_address, &mp->mac,
8293 ntohl(mp->sw_if_index), mp->static_mac, mp->filter_mac,
8297 static void vl_api_l2_fib_table_entry_t_handler_json
8298 (vl_api_l2_fib_table_entry_t * mp)
8300 vat_main_t * vam = &vat_main;
8301 vat_json_node_t *node = NULL;
8303 if (VAT_JSON_ARRAY != vam->json_tree.type) {
8304 ASSERT(VAT_JSON_NONE == vam->json_tree.type);
8305 vat_json_init_array(&vam->json_tree);
8307 node = vat_json_array_add(&vam->json_tree);
8309 vat_json_init_object(node);
8310 vat_json_object_add_uint(node, "bd_id", ntohl(mp->bd_id));
8311 vat_json_object_add_uint(node, "mac", clib_net_to_host_u64(mp->mac));
8312 vat_json_object_add_uint(node, "sw_if_index", ntohl(mp->sw_if_index));
8313 vat_json_object_add_uint(node, "static_mac", mp->static_mac);
8314 vat_json_object_add_uint(node, "filter_mac", mp->filter_mac);
8315 vat_json_object_add_uint(node, "bvi_mac", mp->bvi_mac);
8318 static int api_l2_fib_table_dump (vat_main_t * vam)
8320 unformat_input_t * i = vam->input;
8321 vl_api_l2_fib_table_dump_t *mp;
8326 /* Parse args required to build the message */
8327 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
8328 if (unformat (i, "bd_id %d", &bd_id))
8334 if (bd_id_set == 0) {
8335 errmsg ("missing bridge domain\n");
8339 fformat(vam->ofp, "BD-ID Mac Address sw-ndx Static Filter BVI\n");
8341 /* Get list of l2 fib entries */
8342 M(L2_FIB_TABLE_DUMP, l2_fib_table_dump);
8344 mp->bd_id = ntohl(bd_id);
8347 /* Use a control ping for synchronization */
8349 vl_api_control_ping_t * mp;
8350 M(CONTROL_PING, control_ping);
8358 api_interface_name_renumber (vat_main_t * vam)
8360 unformat_input_t * line_input = vam->input;
8361 vl_api_interface_name_renumber_t *mp;
8362 u32 sw_if_index = ~0;
8364 u32 new_show_dev_instance = ~0;
8366 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) {
8367 if (unformat (line_input, "%U", unformat_sw_if_index, vam,
8370 else if (unformat (line_input, "sw_if_index %d", &sw_if_index))
8372 else if (unformat (line_input, "new_show_dev_instance %d",
8373 &new_show_dev_instance))
8379 if (sw_if_index == ~0) {
8380 errmsg ("missing interface name or sw_if_index\n");
8384 if (new_show_dev_instance == ~0) {
8385 errmsg ("missing new_show_dev_instance\n");
8389 M(INTERFACE_NAME_RENUMBER, interface_name_renumber);
8391 mp->sw_if_index = ntohl (sw_if_index);
8392 mp->new_show_dev_instance = ntohl (new_show_dev_instance);
8398 api_want_ip4_arp_events (vat_main_t * vam)
8400 unformat_input_t * line_input = vam->input;
8401 vl_api_want_ip4_arp_events_t * mp;
8403 ip4_address_t address;
8404 int address_set = 0;
8405 u32 enable_disable = 1;
8407 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) {
8408 if (unformat (line_input, "address %U",
8409 unformat_ip4_address, &address))
8411 else if (unformat (line_input, "del"))
8417 if (address_set == 0) {
8418 errmsg ("missing addresses\n");
8422 M(WANT_IP4_ARP_EVENTS, want_ip4_arp_events);
8423 mp->enable_disable = enable_disable;
8425 mp->address = address.as_u32;
8430 static int api_input_acl_set_interface (vat_main_t * vam)
8432 unformat_input_t * i = vam->input;
8433 vl_api_input_acl_set_interface_t *mp;
8436 int sw_if_index_set;
8437 u32 ip4_table_index = ~0;
8438 u32 ip6_table_index = ~0;
8439 u32 l2_table_index = ~0;
8442 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
8443 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
8444 sw_if_index_set = 1;
8445 else if (unformat (i, "sw_if_index %d", &sw_if_index))
8446 sw_if_index_set = 1;
8447 else if (unformat (i, "del"))
8449 else if (unformat (i, "ip4-table %d", &ip4_table_index))
8451 else if (unformat (i, "ip6-table %d", &ip6_table_index))
8453 else if (unformat (i, "l2-table %d", &l2_table_index))
8456 clib_warning ("parse error '%U'", format_unformat_error, i);
8461 if (sw_if_index_set == 0) {
8462 errmsg ("missing interface name or sw_if_index\n");
8466 M(INPUT_ACL_SET_INTERFACE, input_acl_set_interface);
8468 mp->sw_if_index = ntohl(sw_if_index);
8469 mp->ip4_table_index = ntohl(ip4_table_index);
8470 mp->ip6_table_index = ntohl(ip6_table_index);
8471 mp->l2_table_index = ntohl(l2_table_index);
8472 mp->is_add = is_add;
8480 api_ip_address_dump (vat_main_t * vam)
8482 unformat_input_t * i = vam->input;
8483 vl_api_ip_address_dump_t * mp;
8484 u32 sw_if_index = ~0;
8485 u8 sw_if_index_set = 0;
8490 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
8491 if (unformat (i, "sw_if_index %d", &sw_if_index))
8492 sw_if_index_set = 1;
8493 else if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
8494 sw_if_index_set = 1;
8495 else if (unformat (i, "ipv4"))
8497 else if (unformat (i, "ipv6"))
8503 if (ipv4_set && ipv6_set) {
8504 errmsg ("ipv4 and ipv6 flags cannot be both set\n");
8508 if ((!ipv4_set) && (!ipv6_set)) {
8509 errmsg ("no ipv4 nor ipv6 flag set\n");
8513 if (sw_if_index_set == 0) {
8514 errmsg ("missing interface name or sw_if_index\n");
8518 vam->current_sw_if_index = sw_if_index;
8519 vam->is_ipv6 = ipv6_set;
8521 M(IP_ADDRESS_DUMP, ip_address_dump);
8522 mp->sw_if_index = ntohl(sw_if_index);
8523 mp->is_ipv6 = ipv6_set;
8526 /* Use a control ping for synchronization */
8528 vl_api_control_ping_t * mp;
8529 M(CONTROL_PING, control_ping);
8536 api_ip_dump (vat_main_t * vam)
8538 vl_api_ip_dump_t * mp;
8539 unformat_input_t * in = vam->input;
8546 while (unformat_check_input (in) != UNFORMAT_END_OF_INPUT) {
8547 if (unformat (in, "ipv4"))
8549 else if (unformat (in, "ipv6"))
8555 if (ipv4_set && ipv6_set) {
8556 errmsg ("ipv4 and ipv6 flags cannot be both set\n");
8560 if ((!ipv4_set) && (!ipv6_set)) {
8561 errmsg ("no ipv4 nor ipv6 flag set\n");
8566 vam->is_ipv6 = is_ipv6;
8569 for (i = 0; i < vec_len(vam->ip_details_by_sw_if_index[is_ipv6]); i++) {
8570 vec_free(vam->ip_details_by_sw_if_index[is_ipv6][i].addr);
8572 vec_free(vam->ip_details_by_sw_if_index[is_ipv6]);
8574 M(IP_DUMP, ip_dump);
8575 mp->is_ipv6 = ipv6_set;
8578 /* Use a control ping for synchronization */
8580 vl_api_control_ping_t * mp;
8581 M(CONTROL_PING, control_ping);
8588 api_ipsec_spd_add_del (vat_main_t * vam)
8591 unformat_input_t * i = vam->input;
8592 vl_api_ipsec_spd_add_del_t *mp;
8597 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
8598 if (unformat (i, "spd_id %d", &spd_id))
8600 else if (unformat (i, "del"))
8603 clib_warning ("parse error '%U'", format_unformat_error, i);
8608 errmsg ("spd_id must be set\n");
8612 M(IPSEC_SPD_ADD_DEL, ipsec_spd_add_del);
8614 mp->spd_id = ntohl(spd_id);
8615 mp->is_add = is_add;
8621 clib_warning ("unsupported (no dpdk)");
8627 api_ipsec_interface_add_del_spd (vat_main_t * vam)
8630 unformat_input_t * i = vam->input;
8631 vl_api_ipsec_interface_add_del_spd_t *mp;
8634 u8 sw_if_index_set = 0;
8635 u32 spd_id = (u32) ~0;
8638 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
8639 if (unformat (i, "del"))
8641 else if (unformat (i, "spd_id %d", &spd_id))
8643 else if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
8644 sw_if_index_set = 1;
8645 else if (unformat (i, "sw_if_index %d", &sw_if_index))
8646 sw_if_index_set = 1;
8648 clib_warning ("parse error '%U'", format_unformat_error, i);
8654 if (spd_id == (u32) ~0) {
8655 errmsg ("spd_id must be set\n");
8659 if (sw_if_index_set == 0) {
8660 errmsg ("missing interface name or sw_if_index\n");
8664 M(IPSEC_INTERFACE_ADD_DEL_SPD, ipsec_interface_add_del_spd);
8666 mp->spd_id = ntohl(spd_id);
8667 mp->sw_if_index = ntohl (sw_if_index);
8668 mp->is_add = is_add;
8674 clib_warning ("unsupported (no dpdk)");
8680 api_ipsec_spd_add_del_entry (vat_main_t * vam)
8683 unformat_input_t * i = vam->input;
8684 vl_api_ipsec_spd_add_del_entry_t *mp;
8686 u8 is_add = 1, is_outbound = 0, is_ipv6 = 0, is_ip_any = 1;
8687 u32 spd_id, sa_id, protocol = 0, policy = 0;
8689 u32 rport_start = 0, rport_stop = (u32) ~0;
8690 u32 lport_start = 0, lport_stop = (u32) ~0;
8691 ip4_address_t laddr4_start, laddr4_stop, raddr4_start, raddr4_stop;
8692 ip6_address_t laddr6_start, laddr6_stop, raddr6_start, raddr6_stop;
8694 laddr4_start.as_u32 = raddr4_start.as_u32 = 0;
8695 laddr4_stop.as_u32 = raddr4_stop.as_u32 = (u32) ~0;
8696 laddr6_start.as_u64[0] = raddr6_start.as_u64[0] = 0;
8697 laddr6_start.as_u64[1] = raddr6_start.as_u64[1] = 0;
8698 laddr6_stop.as_u64[0] = raddr6_stop.as_u64[0] = (u64) ~0;
8699 laddr6_stop.as_u64[1] = raddr6_stop.as_u64[1] = (u64) ~0;
8701 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
8702 if (unformat (i, "del"))
8704 if (unformat (i, "outbound"))
8706 if (unformat (i, "inbound"))
8708 else if (unformat (i, "spd_id %d", &spd_id))
8710 else if (unformat (i, "sa_id %d", &sa_id))
8712 else if (unformat (i, "priority %d", &priority))
8714 else if (unformat (i, "protocol %d", &protocol))
8716 else if (unformat (i, "lport_start %d", &lport_start))
8718 else if (unformat (i, "lport_stop %d", &lport_stop))
8720 else if (unformat (i, "rport_start %d", &rport_start))
8722 else if (unformat (i, "rport_stop %d", &rport_stop))
8724 else if (unformat (i, "laddr_start %U", unformat_ip4_address, &laddr4_start))
8729 else if (unformat (i, "laddr_stop %U", unformat_ip4_address, &laddr4_stop))
8734 else if (unformat (i, "raddr_start %U", unformat_ip4_address, &raddr4_start))
8739 else if (unformat (i, "raddr_stop %U", unformat_ip4_address, &raddr4_stop))
8744 else if (unformat (i, "laddr_start %U", unformat_ip6_address, &laddr6_start))
8749 else if (unformat (i, "laddr_stop %U", unformat_ip6_address, &laddr6_stop))
8754 else if (unformat (i, "raddr_start %U", unformat_ip6_address, &raddr6_start))
8759 else if (unformat (i, "raddr_stop %U", unformat_ip6_address, &raddr6_stop))
8764 else if (unformat (i, "action %U", unformat_ipsec_policy_action, &policy))
8766 if (policy == IPSEC_POLICY_ACTION_RESOLVE) {
8767 clib_warning ("unsupported action: 'resolve'");
8772 clib_warning ("parse error '%U'", format_unformat_error, i);
8778 M(IPSEC_SPD_ADD_DEL_ENTRY, ipsec_spd_add_del_entry);
8780 mp->spd_id = ntohl(spd_id);
8781 mp->priority = ntohl(priority);
8782 mp->is_outbound = is_outbound;
8784 mp->is_ipv6 = is_ipv6;
8785 if (is_ipv6 || is_ip_any) {
8786 clib_memcpy (mp->remote_address_start, &raddr6_start, sizeof(ip6_address_t));
8787 clib_memcpy (mp->remote_address_stop, &raddr6_stop, sizeof(ip6_address_t));
8788 clib_memcpy (mp->local_address_start, &laddr6_start, sizeof(ip6_address_t));
8789 clib_memcpy (mp->local_address_stop, &laddr6_stop, sizeof(ip6_address_t));
8791 clib_memcpy (mp->remote_address_start, &raddr4_start, sizeof(ip4_address_t));
8792 clib_memcpy (mp->remote_address_stop, &raddr4_stop, sizeof(ip4_address_t));
8793 clib_memcpy (mp->local_address_start, &laddr4_start, sizeof(ip4_address_t));
8794 clib_memcpy (mp->local_address_stop, &laddr4_stop, sizeof(ip4_address_t));
8796 mp->protocol = (u8) protocol;
8797 mp->local_port_start = ntohs((u16) lport_start);
8798 mp->local_port_stop = ntohs((u16) lport_stop);
8799 mp->remote_port_start = ntohs((u16) rport_start);
8800 mp->remote_port_stop = ntohs((u16) rport_stop);
8801 mp->policy = (u8) policy;
8802 mp->sa_id = ntohl(sa_id);
8803 mp->is_add = is_add;
8804 mp->is_ip_any = is_ip_any;
8809 clib_warning ("unsupported (no dpdk)");
8815 api_ipsec_sad_add_del_entry (vat_main_t * vam)
8818 unformat_input_t * i = vam->input;
8819 vl_api_ipsec_sad_add_del_entry_t *mp;
8825 u8 protocol = IPSEC_PROTOCOL_AH;
8826 u8 is_tunnel = 0, is_tunnel_ipv6 = 0;
8827 u32 crypto_alg = 0, integ_alg = 0;
8828 ip4_address_t tun_src4;
8829 ip4_address_t tun_dst4;
8830 ip6_address_t tun_src6;
8831 ip6_address_t tun_dst6;
8833 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
8834 if (unformat (i, "del"))
8836 else if (unformat (i, "sad_id %d", &sad_id))
8838 else if (unformat (i, "spi %d", &spi))
8840 else if (unformat (i, "esp"))
8841 protocol = IPSEC_PROTOCOL_ESP;
8842 else if (unformat (i, "tunnel_src %U", unformat_ip4_address, &tun_src4)) {
8846 else if (unformat (i, "tunnel_dst %U", unformat_ip4_address, &tun_dst4)) {
8850 else if (unformat (i, "tunnel_src %U", unformat_ip6_address, &tun_src6)) {
8854 else if (unformat (i, "tunnel_dst %U", unformat_ip6_address, &tun_dst6)) {
8858 else if (unformat (i, "crypto_alg %U", unformat_ipsec_crypto_alg, &crypto_alg)) {
8859 if (crypto_alg < IPSEC_CRYPTO_ALG_AES_CBC_128 ||
8860 crypto_alg > IPSEC_INTEG_ALG_SHA_512_256) {
8861 clib_warning ("unsupported crypto-alg: '%U'",
8862 format_ipsec_crypto_alg, crypto_alg);
8866 else if (unformat (i, "crypto_key %U", unformat_hex_string, &ck))
8868 else if (unformat (i, "integ_alg %U", unformat_ipsec_integ_alg, &integ_alg)) {
8869 if (integ_alg < IPSEC_INTEG_ALG_SHA1_96 ||
8870 integ_alg > IPSEC_INTEG_ALG_SHA_512_256) {
8871 clib_warning ("unsupported integ-alg: '%U'",
8872 format_ipsec_integ_alg, integ_alg);
8876 else if (unformat (i, "integ_key %U", unformat_hex_string, &ik))
8879 clib_warning ("parse error '%U'", format_unformat_error, i);
8885 M(IPSEC_SAD_ADD_DEL_ENTRY, ipsec_sad_add_del_entry);
8887 mp->sad_id = ntohl(sad_id);
8888 mp->is_add = is_add;
8889 mp->protocol = protocol;
8890 mp->spi = ntohl(spi);
8891 mp->is_tunnel = is_tunnel;
8892 mp->is_tunnel_ipv6 = is_tunnel_ipv6;
8893 mp->crypto_algorithm = crypto_alg;
8894 mp->integrity_algorithm = integ_alg;
8895 mp->crypto_key_length = vec_len(ck);
8896 mp->integrity_key_length = vec_len(ik);
8898 if (mp->crypto_key_length > sizeof(mp->crypto_key))
8899 mp->crypto_key_length = sizeof(mp->crypto_key);
8901 if (mp->integrity_key_length > sizeof(mp->integrity_key))
8902 mp->integrity_key_length = sizeof(mp->integrity_key);
8904 clib_memcpy (mp->crypto_key, ck, mp->crypto_key_length);
8905 clib_memcpy (mp->integrity_key, ik, mp->integrity_key_length);
8908 if (is_tunnel_ipv6) {
8909 clib_memcpy (mp->tunnel_src_address, &tun_src6, sizeof(ip6_address_t));
8910 clib_memcpy (mp->tunnel_dst_address, &tun_dst6, sizeof(ip6_address_t));
8912 clib_memcpy (mp->tunnel_src_address, &tun_src4, sizeof(ip4_address_t));
8913 clib_memcpy (mp->tunnel_dst_address, &tun_dst4, sizeof(ip4_address_t));
8921 clib_warning ("unsupported (no dpdk)");
8927 api_ipsec_sa_set_key (vat_main_t * vam)
8930 unformat_input_t * i = vam->input;
8931 vl_api_ipsec_sa_set_key_t *mp;
8936 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
8937 if (unformat (i, "sa_id %d", &sa_id))
8939 else if (unformat (i, "crypto_key %U", unformat_hex_string, &ck))
8941 else if (unformat (i, "integ_key %U", unformat_hex_string, &ik))
8944 clib_warning ("parse error '%U'", format_unformat_error, i);
8949 M(IPSEC_SA_SET_KEY, ipsec_set_sa_key);
8951 mp->sa_id = ntohl(sa_id);
8952 mp->crypto_key_length = vec_len(ck);
8953 mp->integrity_key_length = vec_len(ik);
8955 if (mp->crypto_key_length > sizeof(mp->crypto_key))
8956 mp->crypto_key_length = sizeof(mp->crypto_key);
8958 if (mp->integrity_key_length > sizeof(mp->integrity_key))
8959 mp->integrity_key_length = sizeof(mp->integrity_key);
8961 clib_memcpy (mp->crypto_key, ck, mp->crypto_key_length);
8962 clib_memcpy (mp->integrity_key, ik, mp->integrity_key_length);
8968 clib_warning ("unsupported (no dpdk)");
8974 api_ikev2_profile_add_del (vat_main_t * vam)
8977 unformat_input_t * i = vam->input;
8978 vl_api_ikev2_profile_add_del_t * mp;
8983 const char * valid_chars = "a-zA-Z0-9_";
8985 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
8986 if (unformat (i, "del"))
8988 else if (unformat (i, "name %U", unformat_token, valid_chars, &name))
8991 errmsg ("parse error '%U'", format_unformat_error, i);
8996 if (!vec_len (name)) {
8997 errmsg ("profile name must be specified");
9001 if (vec_len (name) > 64) {
9002 errmsg ("profile name too long");
9006 M(IKEV2_PROFILE_ADD_DEL, ikev2_profile_add_del);
9008 clib_memcpy(mp->name, name, vec_len (name));
9009 mp->is_add = is_add;
9016 clib_warning ("unsupported (no dpdk)");
9022 api_ikev2_profile_set_auth (vat_main_t * vam)
9025 unformat_input_t * i = vam->input;
9026 vl_api_ikev2_profile_set_auth_t * mp;
9030 u32 auth_method = 0;
9033 const char * valid_chars = "a-zA-Z0-9_";
9035 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
9036 if (unformat (i, "name %U", unformat_token, valid_chars, &name))
9038 else if (unformat (i, "auth_method %U",
9039 unformat_ikev2_auth_method, &auth_method))
9041 else if (unformat (i, "auth_data 0x%U", unformat_hex_string, &data))
9043 else if (unformat (i, "auth_data %v", &data))
9046 errmsg ("parse error '%U'", format_unformat_error, i);
9051 if (!vec_len (name)) {
9052 errmsg ("profile name must be specified");
9056 if (vec_len (name) > 64) {
9057 errmsg ("profile name too long");
9061 if (!vec_len(data)) {
9062 errmsg ("auth_data must be specified");
9067 errmsg ("auth_method must be specified");
9071 M(IKEV2_PROFILE_SET_AUTH, ikev2_profile_set_auth);
9073 mp->is_hex = is_hex;
9074 mp->auth_method = (u8) auth_method;
9075 mp->data_len = vec_len (data);
9076 clib_memcpy (mp->name, name, vec_len (name));
9077 clib_memcpy (mp->data, data, vec_len (data));
9085 clib_warning ("unsupported (no dpdk)");
9091 api_ikev2_profile_set_id (vat_main_t * vam)
9094 unformat_input_t * i = vam->input;
9095 vl_api_ikev2_profile_set_id_t * mp;
9103 const char * valid_chars = "a-zA-Z0-9_";
9105 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
9106 if (unformat (i, "name %U", unformat_token, valid_chars, &name))
9108 else if (unformat (i, "id_type %U",
9109 unformat_ikev2_id_type, &id_type))
9111 else if (unformat (i, "id_data %U", unformat_ip4_address, &ip4))
9113 data = vec_new(u8, 4);
9114 clib_memcpy(data, ip4.as_u8, 4);
9116 else if (unformat (i, "id_data 0x%U", unformat_hex_string, &data))
9118 else if (unformat (i, "id_data %v", &data))
9120 else if (unformat (i, "local"))
9122 else if (unformat (i, "remote"))
9125 errmsg ("parse error '%U'", format_unformat_error, i);
9130 if (!vec_len (name)) {
9131 errmsg ("profile name must be specified");
9135 if (vec_len (name) > 64) {
9136 errmsg ("profile name too long");
9140 if (!vec_len(data)) {
9141 errmsg ("id_data must be specified");
9146 errmsg ("id_type must be specified");
9150 M(IKEV2_PROFILE_SET_ID, ikev2_profile_set_id);
9152 mp->is_local = is_local;
9153 mp->id_type = (u8) id_type;
9154 mp->data_len = vec_len (data);
9155 clib_memcpy (mp->name, name, vec_len (name));
9156 clib_memcpy (mp->data, data, vec_len (data));
9164 clib_warning ("unsupported (no dpdk)");
9170 api_ikev2_profile_set_ts (vat_main_t * vam)
9173 unformat_input_t * i = vam->input;
9174 vl_api_ikev2_profile_set_ts_t * mp;
9178 u32 proto = 0, start_port = 0, end_port = (u32) ~0;
9179 ip4_address_t start_addr, end_addr;
9181 const char * valid_chars = "a-zA-Z0-9_";
9183 start_addr.as_u32 = 0;
9184 end_addr.as_u32 = (u32) ~0;
9186 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
9187 if (unformat (i, "name %U", unformat_token, valid_chars, &name))
9189 else if (unformat (i, "protocol %d", &proto))
9191 else if (unformat (i, "start_port %d", &start_port))
9193 else if (unformat (i, "end_port %d", &end_port))
9195 else if (unformat (i, "start_addr %U", unformat_ip4_address, &start_addr))
9197 else if (unformat (i, "end_addr %U", unformat_ip4_address, &end_addr))
9199 else if (unformat (i, "local"))
9201 else if (unformat (i, "remote"))
9204 errmsg ("parse error '%U'", format_unformat_error, i);
9209 if (!vec_len (name)) {
9210 errmsg ("profile name must be specified");
9214 if (vec_len (name) > 64) {
9215 errmsg ("profile name too long");
9219 M(IKEV2_PROFILE_SET_TS, ikev2_profile_set_ts);
9221 mp->is_local = is_local;
9222 mp->proto = (u8) proto;
9223 mp->start_port = (u16) start_port;
9224 mp->end_port = (u16) end_port;
9225 mp->start_addr = start_addr.as_u32;
9226 mp->end_addr = end_addr.as_u32;
9227 clib_memcpy (mp->name, name, vec_len (name));
9234 clib_warning ("unsupported (no dpdk)");
9240 api_ikev2_set_local_key (vat_main_t * vam)
9243 unformat_input_t * i = vam->input;
9244 vl_api_ikev2_set_local_key_t * mp;
9248 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
9249 if (unformat (i, "file %v", &file))
9252 errmsg ("parse error '%U'", format_unformat_error, i);
9257 if (!vec_len (file)) {
9258 errmsg ("RSA key file must be specified");
9262 if (vec_len (file) > 256) {
9263 errmsg ("file name too long");
9267 M(IKEV2_SET_LOCAL_KEY, ikev2_set_local_key);
9269 clib_memcpy (mp->key_file, file, vec_len (file));
9276 clib_warning ("unsupported (no dpdk)");
9284 static int api_map_add_domain (vat_main_t * vam)
9286 unformat_input_t *i = vam->input;
9287 vl_api_map_add_domain_t *mp;
9290 ip4_address_t ip4_prefix;
9291 ip6_address_t ip6_prefix;
9292 ip6_address_t ip6_src;
9294 u32 ip6_prefix_len, ip4_prefix_len, ea_bits_len, psid_offset,
9296 u8 is_translation = 0;
9298 u8 ip6_src_len = 128;
9300 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
9301 if (unformat (i, "ip4-pfx %U/%d", unformat_ip4_address,
9302 &ip4_prefix, &ip4_prefix_len))
9304 else if (unformat (i, "ip6-pfx %U/%d", unformat_ip6_address,
9305 &ip6_prefix, &ip6_prefix_len))
9307 else if (unformat (i, "ip6-src %U/%d", unformat_ip6_address, &ip6_src, &ip6_src_len))
9309 else if (unformat (i, "ip6-src %U", unformat_ip6_address, &ip6_src))
9311 else if (unformat (i, "ea-bits-len %d", &ea_bits_len))
9313 else if (unformat (i, "psid-offset %d", &psid_offset))
9315 else if (unformat (i, "psid-len %d", &psid_length))
9317 else if (unformat (i, "mtu %d", &mtu))
9319 else if (unformat (i, "map-t"))
9322 clib_warning ("parse error '%U'", format_unformat_error, i);
9327 if (num_m_args != 6) {
9328 errmsg("mandatory argument(s) missing\n");
9332 /* Construct the API message */
9333 M(MAP_ADD_DOMAIN, map_add_domain);
9335 clib_memcpy(mp->ip4_prefix, &ip4_prefix, sizeof(ip4_prefix));
9336 mp->ip4_prefix_len = ip4_prefix_len;
9338 clib_memcpy(mp->ip6_prefix, &ip6_prefix, sizeof(ip6_prefix));
9339 mp->ip6_prefix_len = ip6_prefix_len;
9341 clib_memcpy(mp->ip6_src, &ip6_src, sizeof(ip6_src));
9342 mp->ip6_src_prefix_len = ip6_src_len;
9344 mp->ea_bits_len = ea_bits_len;
9345 mp->psid_offset = psid_offset;
9346 mp->psid_length = psid_length;
9347 mp->is_translation = is_translation;
9348 mp->mtu = htons(mtu);
9353 /* Wait for a reply, return good/bad news */
9357 static int api_map_del_domain (vat_main_t * vam)
9359 unformat_input_t *i = vam->input;
9360 vl_api_map_del_domain_t *mp;
9366 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
9367 if (unformat (i, "index %d", &index))
9370 clib_warning ("parse error '%U'", format_unformat_error, i);
9375 if (num_m_args != 1) {
9376 errmsg("mandatory argument(s) missing\n");
9380 /* Construct the API message */
9381 M(MAP_DEL_DOMAIN, map_del_domain);
9383 mp->index = ntohl(index);
9388 /* Wait for a reply, return good/bad news */
9392 static int api_map_add_del_rule (vat_main_t * vam)
9394 unformat_input_t *i = vam->input;
9395 vl_api_map_add_del_rule_t *mp;
9398 ip6_address_t ip6_dst;
9399 u32 num_m_args = 0, index, psid;
9401 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
9402 if (unformat (i, "index %d", &index))
9404 else if (unformat (i, "psid %d", &psid))
9406 else if (unformat (i, "dst %U", unformat_ip6_address, &ip6_dst))
9408 else if (unformat (i, "del")) {
9411 clib_warning ("parse error '%U'", format_unformat_error, i);
9416 /* Construct the API message */
9417 M(MAP_ADD_DEL_RULE, map_add_del_rule);
9419 mp->index = ntohl(index);
9420 mp->is_add = is_add;
9421 clib_memcpy(mp->ip6_dst, &ip6_dst, sizeof(ip6_dst));
9422 mp->psid = ntohs(psid);
9427 /* Wait for a reply, return good/bad news */
9431 static int api_map_domain_dump (vat_main_t * vam)
9433 vl_api_map_domain_dump_t *mp;
9436 /* Construct the API message */
9437 M(MAP_DOMAIN_DUMP, map_domain_dump);
9442 /* Use a control ping for synchronization */
9444 vl_api_control_ping_t * mp;
9445 M(CONTROL_PING, control_ping);
9451 static int api_map_rule_dump (vat_main_t * vam)
9453 unformat_input_t *i = vam->input;
9454 vl_api_map_rule_dump_t *mp;
9456 u32 domain_index = ~0;
9458 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
9459 if (unformat (i, "index %u", &domain_index))
9465 if (domain_index == ~0) {
9466 clib_warning("parse error: domain index expected");
9470 /* Construct the API message */
9471 M(MAP_RULE_DUMP, map_rule_dump);
9473 mp->domain_index = htonl(domain_index);
9478 /* Use a control ping for synchronization */
9480 vl_api_control_ping_t * mp;
9481 M(CONTROL_PING, control_ping);
9487 static void vl_api_map_add_domain_reply_t_handler
9488 (vl_api_map_add_domain_reply_t * mp)
9490 vat_main_t * vam = &vat_main;
9491 i32 retval = ntohl(mp->retval);
9493 if (vam->async_mode) {
9494 vam->async_errors += (retval < 0);
9496 vam->retval = retval;
9497 vam->result_ready = 1;
9501 static void vl_api_map_add_domain_reply_t_handler_json
9502 (vl_api_map_add_domain_reply_t * mp)
9504 vat_main_t * vam = &vat_main;
9505 vat_json_node_t node;
9507 vat_json_init_object(&node);
9508 vat_json_object_add_int(&node, "retval", ntohl(mp->retval));
9509 vat_json_object_add_uint(&node, "index", ntohl(mp->index));
9511 vat_json_print(vam->ofp, &node);
9512 vat_json_free(&node);
9514 vam->retval = ntohl(mp->retval);
9515 vam->result_ready = 1;
9519 api_get_first_msg_id (vat_main_t * vam)
9521 vl_api_get_first_msg_id_t * mp;
9523 unformat_input_t * i = vam->input;
9527 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
9528 if (unformat (i, "client %s", &name))
9534 if (name_set == 0) {
9535 errmsg ("missing client name\n");
9540 if (vec_len (name) > 63) {
9541 errmsg ("client name too long\n");
9545 M(GET_FIRST_MSG_ID, get_first_msg_id);
9546 clib_memcpy (mp->name, name, vec_len(name));
9552 static int api_cop_interface_enable_disable (vat_main_t * vam)
9554 unformat_input_t * line_input = vam->input;
9555 vl_api_cop_interface_enable_disable_t * mp;
9557 u32 sw_if_index = ~0;
9558 u8 enable_disable = 1;
9560 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) {
9561 if (unformat (line_input, "disable"))
9563 if (unformat (line_input, "enable"))
9565 else if (unformat (line_input, "%U", unformat_sw_if_index,
9568 else if (unformat (line_input, "sw_if_index %d", &sw_if_index))
9574 if (sw_if_index == ~0) {
9575 errmsg ("missing interface name or sw_if_index\n");
9579 /* Construct the API message */
9580 M(COP_INTERFACE_ENABLE_DISABLE, cop_interface_enable_disable);
9581 mp->sw_if_index = ntohl(sw_if_index);
9582 mp->enable_disable = enable_disable;
9586 /* Wait for the reply */
9590 static int api_cop_whitelist_enable_disable (vat_main_t * vam)
9592 unformat_input_t * line_input = vam->input;
9593 vl_api_cop_whitelist_enable_disable_t * mp;
9595 u32 sw_if_index = ~0;
9596 u8 ip4=0, ip6=0, default_cop=0;
9599 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) {
9600 if (unformat (line_input, "ip4"))
9602 else if (unformat (line_input, "ip6"))
9604 else if (unformat (line_input, "default"))
9606 else if (unformat (line_input, "%U", unformat_sw_if_index,
9609 else if (unformat (line_input, "sw_if_index %d", &sw_if_index))
9611 else if (unformat (line_input, "fib-id %d", &fib_id))
9617 if (sw_if_index == ~0) {
9618 errmsg ("missing interface name or sw_if_index\n");
9622 /* Construct the API message */
9623 M(COP_WHITELIST_ENABLE_DISABLE, cop_whitelist_enable_disable);
9624 mp->sw_if_index = ntohl(sw_if_index);
9625 mp->fib_id = ntohl(fib_id);
9628 mp->default_cop = default_cop;
9632 /* Wait for the reply */
9636 static int api_get_node_graph (vat_main_t * vam)
9638 vl_api_get_node_graph_t * mp;
9641 M(GET_NODE_GRAPH, get_node_graph);
9645 /* Wait for the reply */
9650 api_lisp_add_del_locator_set(vat_main_t * vam)
9652 unformat_input_t * input = vam->input;
9653 vl_api_lisp_add_del_locator_set_t *mp;
9656 u8 *locator_set_name = NULL;
9657 u8 locator_set_name_set = 0;
9659 /* Parse args required to build the message */
9660 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) {
9661 if (unformat(input, "del")) {
9663 } else if (unformat(input, "locator-set %s", &locator_set_name)) {
9664 locator_set_name_set = 1;
9669 if (locator_set_name_set == 0) {
9670 errmsg ("missing locator-set name");
9674 if (vec_len(locator_set_name) > 64) {
9675 errmsg ("locator-set name too long\n");
9676 vec_free(locator_set_name);
9679 vec_add1(locator_set_name, 0);
9681 /* Construct the API message */
9682 M(LISP_ADD_DEL_LOCATOR_SET, lisp_add_del_locator_set);
9684 mp->is_add = is_add;
9685 clib_memcpy(mp->locator_set_name, locator_set_name,
9686 vec_len(locator_set_name));
9687 vec_free(locator_set_name);
9692 /* Wait for a reply... */
9700 api_lisp_add_del_locator(vat_main_t * vam)
9702 unformat_input_t * input = vam->input;
9703 vl_api_lisp_add_del_locator_t *mp;
9705 u32 tmp_if_index = ~0;
9706 u32 sw_if_index = ~0;
9707 u8 sw_if_index_set = 0;
9708 u8 sw_if_index_if_name_set = 0;
9710 u8 priority_set = 0;
9714 u8 *locator_set_name = NULL;
9715 u8 locator_set_name_set = 0;
9717 /* Parse args required to build the message */
9718 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) {
9719 if (unformat(input, "del")) {
9721 } else if (unformat(input, "locator-set %s", &locator_set_name)) {
9722 locator_set_name_set = 1;
9723 } else if (unformat(input, "iface %U", unformat_sw_if_index, vam,
9725 sw_if_index_if_name_set = 1;
9726 sw_if_index = tmp_if_index;
9727 } else if (unformat(input,"sw_if_index %d", &tmp_if_index)) {
9728 sw_if_index_set = 1;
9729 sw_if_index = tmp_if_index;
9730 } else if (unformat(input, "p %d", &priority)) {
9732 } else if (unformat(input, "w %d", &weight)) {
9738 if (locator_set_name_set == 0) {
9739 errmsg ("missing locator-set name");
9743 if (sw_if_index_set == 0 && sw_if_index_if_name_set == 0) {
9744 errmsg ("missing sw_if_index");
9745 vec_free(locator_set_name);
9749 if (sw_if_index_set != 0 && sw_if_index_if_name_set != 0) {
9750 errmsg ("cannot use both params interface name and sw_if_index");
9751 vec_free(locator_set_name);
9755 if (priority_set == 0) {
9756 errmsg ("missing locator-set priority\n");
9757 vec_free(locator_set_name);
9761 if (weight_set == 0) {
9762 errmsg ("missing locator-set weight\n");
9763 vec_free(locator_set_name);
9767 if (vec_len(locator_set_name) > 64) {
9768 errmsg ("locator-set name too long\n");
9769 vec_free(locator_set_name);
9772 vec_add1(locator_set_name, 0);
9774 /* Construct the API message */
9775 M(LISP_ADD_DEL_LOCATOR, lisp_add_del_locator);
9777 mp->is_add = is_add;
9778 mp->sw_if_index = ntohl(sw_if_index);
9779 mp->priority = priority;
9780 mp->weight = weight;
9781 clib_memcpy(mp->locator_set_name, locator_set_name,
9782 vec_len(locator_set_name));
9783 vec_free(locator_set_name);
9788 /* Wait for a reply... */
9796 api_lisp_add_del_local_eid(vat_main_t * vam)
9798 unformat_input_t * input = vam->input;
9799 vl_api_lisp_add_del_local_eid_t *mp;
9804 ip4_address_t eidv4;
9805 ip6_address_t eidv6;
9806 u8 tmp_eid_lenght = ~0;
9808 u8 *locator_set_name = NULL;
9809 u8 locator_set_name_set = 0;
9811 /* Parse args required to build the message */
9812 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) {
9813 if (unformat(input, "del")) {
9815 } else if (unformat(input, "eid %U/%d", unformat_ip4_address,
9816 &eidv4, &tmp_eid_lenght)) {
9817 eid_lenght = tmp_eid_lenght;
9819 } else if (unformat(input, "eid %U/%d", unformat_ip6_address,
9820 &eidv6, &tmp_eid_lenght)) {
9821 eid_lenght = tmp_eid_lenght;
9823 } else if (unformat(input, "locator-set %s", &locator_set_name)) {
9824 locator_set_name_set = 1;
9829 if (locator_set_name_set == 0) {
9830 errmsg ("missing locator-set name\n");
9834 if (vec_len(locator_set_name) > 64) {
9835 errmsg ("locator-set name too long\n");
9836 vec_free(locator_set_name);
9839 vec_add1(locator_set_name, 0);
9841 if (eidv4_set && eidv6_set) {
9842 errmsg ("both eid v4 and v6 addresses set\n");
9843 vec_free(locator_set_name);
9847 if (!eidv4_set && !eidv6_set) {
9848 errmsg ("eid addresses not set\n");
9849 vec_free(locator_set_name);
9853 if (eidv4_set && eid_lenght > 32) {
9854 errmsg ("eid prefix to big\n");
9855 vec_free(locator_set_name);
9859 if (eidv6_set && eid_lenght > 128) {
9860 errmsg ("eid prefix to big\n");
9861 vec_free(locator_set_name);
9865 /* Construct the API message */
9866 M(LISP_ADD_DEL_LOCAL_EID, lisp_add_del_local_eid);
9868 mp->is_add = is_add;
9871 clib_memcpy(mp->ip_address, &eidv6, sizeof(eidv6));
9874 clib_memcpy(mp->ip_address, &eidv4, sizeof(eidv4));
9876 mp->prefix_len = eid_lenght;
9877 clib_memcpy(mp->locator_set_name, locator_set_name,
9878 vec_len(locator_set_name));
9879 vec_free(locator_set_name);
9884 /* Wait for a reply... */
9892 api_lisp_gpe_add_del_fwd_entry(vat_main_t * vam)
9894 unformat_input_t * input = vam->input;
9895 vl_api_lisp_gpe_add_del_fwd_entry_t *mp;
9898 u8 eidv4_set = 0, slocv4_set = 0, dlocv4_set = 0;
9899 u8 eidv6_set = 0, slocv6_set = 0, dlocv6_set = 0;
9900 ip4_address_t eidv4, slocv4, dlocv4;
9901 ip6_address_t eidv6, slocv6, dlocv6;
9902 u8 tmp_eid_lenght = ~0;
9905 /* Parse args required to build the message */
9906 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) {
9907 if (unformat(input, "del")) {
9909 } else if (unformat(input, "eid %U/%d", unformat_ip4_address,
9910 &eidv4, &tmp_eid_lenght)) {
9911 eid_lenght = tmp_eid_lenght;
9913 } else if (unformat(input, "eid %U/%d", unformat_ip6_address,
9914 &eidv6, &tmp_eid_lenght)) {
9915 eid_lenght = tmp_eid_lenght;
9917 } else if (unformat(input, "sloc %U", unformat_ip4_address, &slocv4)) {
9919 } else if (unformat(input, "sloc %U", unformat_ip6_address, &slocv6)) {
9921 } else if (unformat(input, "dloc %U", unformat_ip4_address, &dlocv4)) {
9923 } else if (unformat(input, "dloc %U", unformat_ip6_address, &dlocv6)) {
9929 if (eidv4_set && eidv6_set) {
9930 errmsg ("both eid v4 and v6 addresses set\n");
9934 if (!eidv4_set && !eidv6_set) {
9935 errmsg ("eid addresses not set\n");
9939 if (slocv4_set && slocv6_set) {
9940 errmsg ("both source v4 and v6 addresses set\n");
9944 if (!slocv4_set && !slocv6_set) {
9945 errmsg ("source addresses not set\n");
9949 if (dlocv4_set && dlocv6_set) {
9950 errmsg ("both destination v4 and v6 addresses set\n");
9954 if (dlocv4_set && dlocv6_set) {
9955 errmsg ("destination addresses not set\n");
9959 if (!(slocv4_set == dlocv4_set && slocv6_set == dlocv6_set)) {
9960 errmsg ("mixing type of source and destination address\n");
9964 /* Construct the API message */
9965 M(LISP_GPE_ADD_DEL_FWD_ENTRY, lisp_gpe_add_del_fwd_entry);
9967 mp->is_add = is_add;
9969 mp->eid_is_ipv6 = 1;
9970 clib_memcpy(mp->eid_ip_address, &eidv6, sizeof(eidv6));
9972 mp->eid_is_ipv6 = 0;
9973 clib_memcpy(mp->eid_ip_address, &eidv4, sizeof(eidv4));
9975 mp->eid_prefix_len = eid_lenght;
9977 mp->address_is_ipv6 = 1;
9978 clib_memcpy(mp->source_ip_address, &slocv6, sizeof(slocv6));
9979 clib_memcpy(mp->destination_ip_address, &dlocv6, sizeof(dlocv6));
9981 mp->address_is_ipv6 = 0;
9982 clib_memcpy(mp->source_ip_address, &slocv4, sizeof(slocv4));
9983 clib_memcpy(mp->destination_ip_address, &dlocv4, sizeof(dlocv4));
9989 /* Wait for a reply... */
9997 api_lisp_add_del_map_resolver(vat_main_t * vam)
9999 unformat_input_t * input = vam->input;
10000 vl_api_lisp_add_del_map_resolver_t *mp;
10005 ip4_address_t ipv4;
10006 ip6_address_t ipv6;
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, "%U", unformat_ip4_address, &ipv4)) {
10014 } else if (unformat(input, "%U", unformat_ip6_address, &ipv6)) {
10020 if (ipv4_set && ipv6_set) {
10021 errmsg ("both eid v4 and v6 addresses set\n");
10025 if (!ipv4_set && !ipv6_set) {
10026 errmsg ("eid addresses not set\n");
10030 /* Construct the API message */
10031 M(LISP_ADD_DEL_MAP_RESOLVER, lisp_add_del_map_resolver);
10033 mp->is_add = is_add;
10036 clib_memcpy(mp->ip_address, &ipv6, sizeof(ipv6));
10039 clib_memcpy(mp->ip_address, &ipv4, sizeof(ipv4));
10045 /* Wait for a reply... */
10053 api_lisp_gpe_enable_disable (vat_main_t * vam)
10055 unformat_input_t * input = vam->input;
10056 vl_api_lisp_gpe_enable_disable_t *mp;
10061 /* Parse args required to build the message */
10062 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) {
10063 if (unformat(input, "enable")) {
10066 } else if (unformat(input, "disable")) {
10074 errmsg("Value not set\n");
10078 /* Construct the API message */
10079 M(LISP_GPE_ENABLE_DISABLE, lisp_gpe_enable_disable);
10086 /* Wait for a reply... */
10094 api_lisp_enable_disable (vat_main_t * vam)
10096 unformat_input_t * input = vam->input;
10097 vl_api_lisp_enable_disable_t *mp;
10102 /* Parse args required to build the message */
10103 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
10105 if (unformat (input, "enable"))
10110 else if (unformat (input, "disable"))
10120 errmsg ("Value not set\n");
10124 /* Construct the API message */
10125 M(LISP_ENABLE_DISABLE, lisp_enable_disable);
10132 /* Wait for a reply... */
10139 /** Used for transferring locators via VPP API */
10140 typedef CLIB_PACKED(struct
10142 u8 is_ip4; /**< is locator an IPv4 address? */
10143 u8 addr[16]; /**< IPv4/IPv6 address */
10147 * Enable/disable LISP proxy ITR.
10149 * @param vam vpp API test context
10150 * @return return code
10153 api_lisp_pitr_set_locator_set (vat_main_t * vam)
10156 u8 ls_name_set = 0;
10157 unformat_input_t * input = vam->input;
10158 vl_api_lisp_pitr_set_locator_set_t * mp;
10162 /* Parse args required to build the message */
10163 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
10165 if (unformat (input, "del"))
10167 else if (unformat (input, "locator-set %s", &ls_name))
10171 errmsg ("parse error '%U'", format_unformat_error, input);
10178 errmsg ("locator-set name not set!");
10182 M(LISP_PITR_SET_LOCATOR_SET, lisp_pitr_set_locator_set);
10184 mp->is_add = is_add;
10185 clib_memcpy (mp->ls_name, ls_name, vec_len (ls_name));
10186 vec_free (ls_name);
10191 /* wait for reply */
10199 * Add/del remote mapping from LISP control plane and updates
10200 * forwarding entries in data-plane accordingly.
10202 * @param vam vpp API test context
10203 * @return return code
10206 api_lisp_add_del_remote_mapping (vat_main_t * vam)
10208 unformat_input_t * input = vam->input;
10209 vl_api_lisp_add_del_remote_mapping_t *mp;
10212 u8 seid_set = 0, deid_set = 0;
10213 ip4_address_t seid4, deid4, rloc4;
10214 ip6_address_t seid6, deid6, rloc6;
10215 u32 seid_len = 0, deid_len = 0, len;
10216 u8 deid_is_ip4 = 0, seid_is_ip4 = 0;
10217 u8 is_add = 1, del_all = 0;
10219 rloc_t * rlocs = 0, rloc;
10221 /* Parse args required to build the message */
10222 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) {
10223 if (unformat(input, "del-all")) {
10225 } else if (unformat(input, "del")) {
10227 } else if (unformat(input, "add")) {
10229 } else if (unformat(input, "deid %U/%d", unformat_ip4_address,
10234 } else if (unformat(input, "deid %U/%d", unformat_ip6_address,
10239 } else if (unformat(input, "seid %U/%d", unformat_ip4_address,
10244 } else if (unformat(input, "seid %U/%d", unformat_ip6_address,
10249 } else if (unformat(input, "vni %d", &vni)) {
10251 } else if (unformat(input, "rloc %U", unformat_ip4_address, &rloc4)) {
10253 clib_memcpy (&rloc.addr, &rloc4, sizeof (rloc4));
10254 vec_add1 (rlocs, rloc);
10255 } else if (unformat(input, "rloc %U", unformat_ip6_address, &rloc6)) {
10257 clib_memcpy (&rloc.addr, &rloc6, sizeof (rloc6));
10258 vec_add1 (rlocs, rloc);
10259 } else if (unformat(input, "action %d", &action)) {
10262 clib_warning ("parse error '%U'", format_unformat_error, input);
10267 if (!seid_set || !deid_set) {
10268 errmsg ("missing params!");
10272 if (seid_is_ip4 != deid_is_ip4) {
10273 errmsg ("source and destination EIDs are not in " "same IP family!");
10277 if (is_add && (~0 == action)
10278 && 0 == vec_len (rlocs)) {
10279 errmsg ("no action set for negative map-reply!");
10283 M(LISP_ADD_DEL_REMOTE_MAPPING, lisp_add_del_remote_mapping);
10284 mp->is_add = is_add;
10285 mp->vni = htonl (vni);
10286 mp->seid_len = seid_len;
10287 mp->action = (u8) action;
10288 mp->deid_len = deid_len;
10289 mp->del_all = del_all;
10291 mp->eid_is_ip4 = 1;
10292 clib_memcpy (mp->seid, &seid4, sizeof (seid4));
10294 mp->eid_is_ip4 = 0;
10295 clib_memcpy (mp->seid, &seid6, sizeof (seid6));
10299 mp->eid_is_ip4 = 1;
10300 clib_memcpy (mp->deid, &deid4, sizeof (deid4));
10302 mp->eid_is_ip4 = 0;
10303 clib_memcpy (mp->deid, &deid6, sizeof (deid6));
10306 mp->rloc_num = vec_len (rlocs);
10307 clib_memcpy (mp->rlocs, rlocs, (sizeof (rloc_t) * vec_len (rlocs)));
10313 /* Wait for a reply... */
10321 api_lisp_gpe_add_del_iface(vat_main_t * vam)
10323 unformat_input_t * input = vam->input;
10324 vl_api_lisp_gpe_add_del_iface_t *mp;
10330 /* Parse args required to build the message */
10331 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) {
10332 if (unformat(input, "up")) {
10335 } else if (unformat(input, "down")) {
10338 } else if (unformat(input, "table_id %d", &table_id)) {
10340 } else if (unformat(input, "vni %d", &vni)) {
10347 errmsg("Value not set\n");
10351 /* Construct the API message */
10352 M(LISP_GPE_ADD_DEL_IFACE, lisp_gpe_add_del_iface);
10354 mp->is_add = is_add;
10355 mp->table_id = table_id;
10361 /* Wait for a reply... */
10369 api_lisp_locator_set_dump(vat_main_t *vam)
10371 vl_api_lisp_locator_set_dump_t *mp;
10374 if (!vam->json_output) {
10375 fformat(vam->ofp, "%=20s%=16s%=16s%=16s\n",
10376 "Locator-set", "Locator", "Priority", "Weight");
10379 M(LISP_LOCATOR_SET_DUMP, lisp_locator_set_dump);
10383 /* Use a control ping for synchronization */
10385 vl_api_control_ping_t * mp;
10386 M(CONTROL_PING, control_ping);
10389 /* Wait for a reply... */
10397 api_lisp_local_eid_table_dump(vat_main_t *vam)
10399 vl_api_lisp_local_eid_table_dump_t *mp;
10402 if (!vam->json_output) {
10403 fformat(vam->ofp, "%=20s%=30s\n",
10404 "Locator-set", "Eid");
10407 M(LISP_LOCAL_EID_TABLE_DUMP, lisp_local_eid_table_dump);
10411 /* Use a control ping for synchronization */
10413 vl_api_control_ping_t * mp;
10414 M(CONTROL_PING, control_ping);
10417 /* Wait for a reply... */
10425 api_lisp_gpe_tunnel_dump(vat_main_t *vam)
10427 vl_api_lisp_gpe_tunnel_dump_t *mp;
10430 if (!vam->json_output) {
10431 fformat(vam->ofp, "%=20s%=30s%=16s%=16s%=16s%=16s"
10432 "%=16s%=16s%=16s%=16s%=16s\n",
10433 "Tunel", "Source", "Destination", "Fib encap", "Fib decap",
10434 "Decap next", "Lisp version", "Flags", "Next protocol",
10435 "ver_res", "res", "iid");
10438 M(LISP_GPE_TUNNEL_DUMP, lisp_gpe_tunnel_dump);
10442 /* Use a control ping for synchronization */
10444 vl_api_control_ping_t * mp;
10445 M(CONTROL_PING, control_ping);
10448 /* Wait for a reply... */
10456 api_lisp_map_resolver_dump(vat_main_t *vam)
10458 vl_api_lisp_map_resolver_dump_t *mp;
10461 if (!vam->json_output) {
10462 fformat(vam->ofp, "%=20s\n",
10466 M(LISP_MAP_RESOLVER_DUMP, lisp_map_resolver_dump);
10470 /* Use a control ping for synchronization */
10472 vl_api_control_ping_t * mp;
10473 M(CONTROL_PING, control_ping);
10476 /* Wait for a reply... */
10484 api_lisp_enable_disable_status_dump(vat_main_t *vam)
10486 vl_api_lisp_enable_disable_status_dump_t *mp;
10489 if (!vam->json_output) {
10490 fformat(vam->ofp, "%=20s\n",
10494 M(LISP_ENABLE_DISABLE_STATUS_DUMP,
10495 lisp_enable_disable_status_dump);
10499 /* Use a control ping for synchronization */
10501 vl_api_control_ping_t * mp;
10502 M(CONTROL_PING, control_ping);
10505 /* Wait for a reply... */
10513 api_af_packet_create (vat_main_t * vam)
10515 unformat_input_t * i = vam->input;
10516 vl_api_af_packet_create_t * mp;
10518 u8 * host_if_name = 0;
10520 u8 random_hw_addr = 1;
10522 memset (hw_addr, 0, sizeof (hw_addr));
10524 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
10525 if (unformat (i, "name %s", &host_if_name))
10526 vec_add1 (host_if_name, 0);
10527 else if (unformat (i, "hw_addr %U", unformat_ethernet_address, hw_addr))
10528 random_hw_addr = 0;
10533 if (!vec_len (host_if_name)) {
10534 errmsg ("host-interface name must be specified");
10538 if (vec_len (host_if_name) > 64) {
10539 errmsg ("host-interface name too long");
10543 M(AF_PACKET_CREATE, af_packet_create);
10545 clib_memcpy (mp->host_if_name, host_if_name, vec_len (host_if_name));
10546 clib_memcpy (mp->hw_addr, hw_addr, 6);
10547 mp->use_random_hw_addr = random_hw_addr;
10548 vec_free (host_if_name);
10556 api_af_packet_delete (vat_main_t * vam)
10558 unformat_input_t * i = vam->input;
10559 vl_api_af_packet_delete_t * mp;
10561 u8 * host_if_name = 0;
10563 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
10564 if (unformat (i, "name %s", &host_if_name))
10565 vec_add1 (host_if_name, 0);
10570 if (!vec_len (host_if_name)) {
10571 errmsg ("host-interface name must be specified");
10575 if (vec_len (host_if_name) > 64) {
10576 errmsg ("host-interface name too long");
10580 M(AF_PACKET_DELETE, af_packet_delete);
10582 clib_memcpy (mp->host_if_name, host_if_name, vec_len (host_if_name));
10583 vec_free (host_if_name);
10591 api_policer_add_del (vat_main_t * vam)
10593 unformat_input_t * i = vam->input;
10594 vl_api_policer_add_del_t * mp;
10606 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
10607 if (unformat (i, "del"))
10609 else if (unformat (i, "name %s", &name))
10610 vec_add1 (name, 0);
10611 else if (unformat (i, "cir %u", &cir))
10613 else if (unformat (i, "eir %u", &eir))
10615 else if (unformat (i, "cb %u", &cb))
10617 else if (unformat (i, "eb %u", &eb))
10619 else if (unformat (i, "rate_type %U", unformat_policer_rate_type,
10622 else if (unformat (i, "round_type %U", unformat_policer_round_type,
10625 else if (unformat (i, "type %U", unformat_policer_type, &type))
10631 if (!vec_len (name)) {
10632 errmsg ("policer name must be specified");
10636 if (vec_len (name) > 64) {
10637 errmsg ("policer name too long");
10641 M(POLICER_ADD_DEL, policer_add_del);
10643 clib_memcpy (mp->name, name, vec_len (name));
10645 mp->is_add = is_add;
10650 mp->rate_type = rate_type;
10651 mp->round_type = round_type;
10660 api_policer_dump(vat_main_t *vam)
10662 unformat_input_t * i = vam->input;
10663 vl_api_policer_dump_t *mp;
10665 u8 *match_name = 0;
10666 u8 match_name_valid = 0;
10668 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
10669 if (unformat (i, "name %s", &match_name)) {
10670 vec_add1 (match_name, 0);
10671 match_name_valid = 1;
10676 M(POLICER_DUMP, policer_dump);
10677 mp->match_name_valid = match_name_valid;
10678 clib_memcpy (mp->match_name, match_name, vec_len (match_name));
10679 vec_free (match_name);
10683 /* Use a control ping for synchronization */
10685 vl_api_control_ping_t * mp;
10686 M(CONTROL_PING, control_ping);
10689 /* Wait for a reply... */
10697 api_netmap_create (vat_main_t * vam)
10699 unformat_input_t * i = vam->input;
10700 vl_api_netmap_create_t * mp;
10704 u8 random_hw_addr = 1;
10708 memset (hw_addr, 0, sizeof (hw_addr));
10710 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
10711 if (unformat (i, "name %s", &if_name))
10712 vec_add1 (if_name, 0);
10713 else if (unformat (i, "hw_addr %U", unformat_ethernet_address, hw_addr))
10714 random_hw_addr = 0;
10715 else if (unformat (i, "pipe"))
10717 else if (unformat (i, "master"))
10719 else if (unformat (i, "slave"))
10725 if (!vec_len (if_name)) {
10726 errmsg ("interface name must be specified");
10730 if (vec_len (if_name) > 64) {
10731 errmsg ("interface name too long");
10735 M(NETMAP_CREATE, netmap_create);
10737 clib_memcpy (mp->netmap_if_name, if_name, vec_len (if_name));
10738 clib_memcpy (mp->hw_addr, hw_addr, 6);
10739 mp->use_random_hw_addr = random_hw_addr;
10740 mp->is_pipe = is_pipe;
10741 mp->is_master = is_master;
10742 vec_free (if_name);
10750 api_netmap_delete (vat_main_t * vam)
10752 unformat_input_t * i = vam->input;
10753 vl_api_netmap_delete_t * mp;
10757 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
10758 if (unformat (i, "name %s", &if_name))
10759 vec_add1 (if_name, 0);
10764 if (!vec_len (if_name)) {
10765 errmsg ("interface name must be specified");
10769 if (vec_len (if_name) > 64) {
10770 errmsg ("interface name too long");
10774 M(NETMAP_DELETE, netmap_delete);
10776 clib_memcpy (mp->netmap_if_name, if_name, vec_len (if_name));
10777 vec_free (if_name);
10784 static int q_or_quit (vat_main_t * vam)
10786 longjmp (vam->jump_buf, 1);
10787 return 0; /* not so much */
10789 static int q (vat_main_t * vam) {return q_or_quit (vam);}
10790 static int quit (vat_main_t * vam) {return q_or_quit (vam);}
10792 static int comment (vat_main_t * vam)
10797 static int cmd_cmp (void * a1, void * a2)
10802 return strcmp ((char *)(c1[0]), (char *)(c2[0]));
10805 static int help (vat_main_t * vam)
10810 unformat_input_t * i = vam->input;
10813 if (unformat (i, "%s", &name)) {
10818 hs = hash_get_mem (vam->help_by_name, name);
10820 fformat (vam->ofp, "usage: %s %s\n", name, hs[0]);
10822 fformat (vam->ofp, "No such msg / command '%s'\n", name);
10827 fformat(vam->ofp, "Help is available for the following:\n");
10829 hash_foreach_pair (p, vam->function_by_name,
10831 vec_add1 (cmds, (u8 *)(p->key));
10834 vec_sort_with_function (cmds, cmd_cmp);
10836 for (j = 0; j < vec_len(cmds); j++)
10837 fformat (vam->ofp, "%s\n", cmds[j]);
10843 static int set (vat_main_t * vam)
10845 u8 * name = 0, * value = 0;
10846 unformat_input_t * i = vam->input;
10848 if (unformat (i, "%s", &name)) {
10849 /* The input buffer is a vector, not a string. */
10850 value = vec_dup (i->buffer);
10851 vec_delete (value, i->index, 0);
10852 /* Almost certainly has a trailing newline */
10853 if (value[vec_len(value)-1] == '\n')
10854 value[vec_len(value)-1] = 0;
10855 /* Make sure it's a proper string, one way or the other */
10856 vec_add1 (value, 0);
10857 (void) clib_macro_set_value (&vam->macro_main,
10858 (char *)name, (char *)value);
10861 errmsg ("usage: set <name> <value>\n");
10868 static int unset (vat_main_t * vam)
10872 if (unformat (vam->input, "%s", &name))
10873 if (clib_macro_unset (&vam->macro_main, (char *)name) == 1)
10874 errmsg ("unset: %s wasn't set\n", name);
10885 static int macro_sort_cmp (void * a1, void * a2)
10887 macro_sort_t * s1 = a1;
10888 macro_sort_t * s2 = a2;
10890 return strcmp ((char *)(s1->name), (char *)(s2->name));
10893 static int dump_macro_table (vat_main_t * vam)
10895 macro_sort_t * sort_me = 0, * sm;
10899 hash_foreach_pair (p, vam->macro_main.the_value_table_hash,
10901 vec_add2 (sort_me, sm, 1);
10902 sm->name = (u8 *)(p->key);
10903 sm->value = (u8 *) (p->value[0]);
10906 vec_sort_with_function (sort_me, macro_sort_cmp);
10908 if (vec_len(sort_me))
10909 fformat (vam->ofp, "%-15s%s\n", "Name", "Value");
10911 fformat (vam->ofp, "The macro table is empty...\n");
10913 for (i = 0; i < vec_len (sort_me); i++)
10914 fformat (vam->ofp, "%-15s%s\n", sort_me[i].name,
10919 static int dump_node_table (vat_main_t * vam)
10922 vlib_node_t * node, * next_node;
10924 if (vec_len (vam->graph_nodes) == 0) {
10925 fformat (vam->ofp, "Node table empty, issue get_node_graph...\n");
10929 for (i = 0; i < vec_len (vam->graph_nodes); i++) {
10930 node = vam->graph_nodes[i];
10931 fformat (vam->ofp, "[%d] %s\n", i, node->name);
10932 for (j = 0; j < vec_len (node->next_nodes); j++) {
10933 if (node->next_nodes[j] != ~0) {
10934 next_node = vam->graph_nodes[node->next_nodes[j]];
10935 fformat (vam->ofp, " [%d] %s\n", j, next_node->name);
10942 static int search_node_table (vat_main_t * vam)
10944 unformat_input_t * line_input = vam->input;
10947 vlib_node_t * node, * next_node;
10950 if (vam->graph_node_index_by_name == 0) {
10951 fformat (vam->ofp, "Node table empty, issue get_node_graph...\n");
10955 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) {
10956 if (unformat (line_input, "%s", &node_to_find)) {
10957 vec_add1 (node_to_find, 0);
10958 p = hash_get_mem (vam->graph_node_index_by_name, node_to_find);
10960 fformat (vam->ofp, "%s not found...\n", node_to_find);
10963 node = vam->graph_nodes[p[0]];
10964 fformat (vam->ofp, "[%d] %s\n", p[0], node->name);
10965 for (j = 0; j < vec_len (node->next_nodes); j++) {
10966 if (node->next_nodes[j] != ~0) {
10967 next_node = vam->graph_nodes[node->next_nodes[j]];
10968 fformat (vam->ofp, " [%d] %s\n", j, next_node->name);
10974 clib_warning ("parse error '%U'", format_unformat_error,
10980 vec_free(node_to_find);
10988 static int script (vat_main_t * vam)
10991 char * save_current_file;
10992 unformat_input_t save_input;
10993 jmp_buf save_jump_buf;
10994 u32 save_line_number;
10996 FILE * new_fp, * save_ifp;
10998 if (unformat (vam->input, "%s", &s)) {
10999 new_fp = fopen ((char *)s, "r");
11001 errmsg ("Couldn't open script file %s\n", s);
11006 errmsg ("Missing script name\n");
11010 clib_memcpy (&save_input, &vam->input, sizeof (save_input));
11011 clib_memcpy (&save_jump_buf, &vam->jump_buf, sizeof (save_jump_buf));
11012 save_ifp = vam->ifp;
11013 save_line_number = vam->input_line_number;
11014 save_current_file = (char *) vam->current_file;
11016 vam->input_line_number = 0;
11018 vam->current_file = s;
11021 clib_memcpy (&vam->input, &save_input, sizeof (vam->input));
11022 clib_memcpy (&vam->jump_buf, &save_jump_buf, sizeof (save_jump_buf));
11023 vam->ifp = save_ifp;
11024 vam->input_line_number = save_line_number;
11025 vam->current_file = (u8 *) save_current_file;
11031 static int echo (vat_main_t * vam)
11033 fformat (vam->ofp, "%v", vam->input->buffer);
11037 /* List of API message constructors, CLI names map to api_xxx */
11038 #define foreach_vpe_api_msg \
11039 _(create_loopback,"[mac <mac-addr>]") \
11040 _(sw_interface_dump,"") \
11041 _(sw_interface_set_flags, \
11042 "<intfc> | sw_if_index <id> admin-up | admin-down link-up | link down") \
11043 _(sw_interface_add_del_address, \
11044 "<intfc> | sw_if_index <id> <ip4-address> | <ip6-address> [del] [del-all] ") \
11045 _(sw_interface_set_table, \
11046 "<intfc> | sw_if_index <id> vrf <table-id> [ipv6]") \
11047 _(sw_interface_set_vpath, \
11048 "<intfc> | sw_if_index <id> enable | disable") \
11049 _(sw_interface_set_l2_xconnect, \
11050 "rx <intfc> | rx_sw_if_index <id> tx <intfc> | tx_sw_if_index <id>\n" \
11051 "enable | disable") \
11052 _(sw_interface_set_l2_bridge, \
11053 "rx <intfc> | rx_sw_if_index <id> bd_id <bridge-domain-id>\n" \
11054 "[shg <split-horizon-group>] [bvi]\n" \
11055 "enable | disable") \
11056 _(bridge_domain_add_del, \
11057 "bd_id <bridge-domain-id> [flood 1|0] [uu-flood 1|0] [forward 1|0] [learn 1|0] [arp-term 1|0] [del]\n")\
11058 _(bridge_domain_dump, "[bd_id <bridge-domain-id>]\n") \
11060 "mac <mac-addr> bd_id <bridge-domain-id> [del] | sw_if <intfc> | sw_if_index <id> [static] [filter] [bvi]\n") \
11062 "sw_if <intfc> | sw_if_index <id> [learn] [forward] [uu-flood] [flood]\n") \
11064 "bd_id <bridge-domain-id> [learn] [forward] [uu-flood] [flood] [arp-term] [disable]\n") \
11066 "tapname <name> mac <mac-addr> | random-mac") \
11068 "<vpp-if-name> | sw_if_index <id> tapname <name> mac <mac-addr> | random-mac") \
11070 "<vpp-if-name> | sw_if_index <id>") \
11071 _(sw_interface_tap_dump, "") \
11072 _(ip_add_del_route, \
11073 "<addr>/<mask> via <addr> [vrf <n>]\n" \
11074 "[<intfc> | sw_if_index <id>] [resolve-attempts <n>]\n" \
11075 "[weight <n>] [drop] [local] [classify <n>] [del]\n" \
11076 "[multipath] [count <n>]") \
11077 _(proxy_arp_add_del, \
11078 "<lo-ip4-addr> - <hi-ip4-addr> [vrf <n>] [del]") \
11079 _(proxy_arp_intfc_enable_disable, \
11080 "<intfc> | sw_if_index <id> enable | disable") \
11081 _(mpls_add_del_encap, \
11082 "label <n> dst <ip4-addr> [vrf <n>] [del]") \
11083 _(mpls_add_del_decap, \
11084 "label <n> [rx_vrf_id <n>] [tx_vrf_id] [s-bit-clear][del]") \
11085 _(mpls_gre_add_del_tunnel, \
11086 "inner_vrf_id <n> outer_vrf_id <n> src <ip4-address> dst <ip4-address>\n" \
11087 "adj <ip4-address>/<mask-width> [del]") \
11088 _(sw_interface_set_unnumbered, \
11089 "<intfc> | sw_if_index <id> unnum_if_index <id> [del]") \
11090 _(ip_neighbor_add_del, \
11091 "<intfc> | sw_if_index <id> dst <ip46-address> mac <mac-addr>") \
11092 _(reset_vrf, "vrf <id> [ipv6]") \
11093 _(create_vlan_subif, "<intfc> | sw_if_index <id> vlan <n>") \
11094 _(create_subif, "<intfc> | sw_if_index <id> sub_id <n>\n" \
11095 "[outer_vlan_id <n>][inner_vlan_id <n>]\n" \
11096 "[no_tags][one_tag][two_tags][dot1ad][exact_match][default_sub]\n" \
11097 "[outer_vlan_id_any][inner_vlan_id_any]") \
11098 _(oam_add_del, "src <ip4-address> dst <ip4-address> [vrf <n>] [del]") \
11099 _(reset_fib, "vrf <n> [ipv6]") \
11100 _(dhcp_proxy_config, \
11101 "svr <v46-address> src <v46-address>\n" \
11102 "insert-cid <n> [del]") \
11103 _(dhcp_proxy_config_2, \
11104 "svr <v46-address> src <v46-address>\n" \
11105 "rx_vrf_id <nn> server_vrf_id <nn> insert-cid <n> [del]") \
11106 _(dhcp_proxy_set_vss, \
11107 "tbl_id <n> fib_id <n> oui <n> [ipv6] [del]") \
11108 _(dhcp_client_config, \
11109 "<intfc> | sw_if_index <id> [hostname <name>] [disable_event] [del]") \
11110 _(set_ip_flow_hash, \
11111 "vrf <n> [src] [dst] [sport] [dport] [proto] [reverse] [ipv6]") \
11112 _(sw_interface_ip6_enable_disable, \
11113 "<intfc> | sw_if_index <id> enable | disable") \
11114 _(sw_interface_ip6_set_link_local_address, \
11115 "<intfc> | sw_if_index <id> <ip6-address>/<mask-width>") \
11116 _(sw_interface_ip6nd_ra_prefix, \
11117 "<intfc> | sw_if_index <id> <ip6-address>/<mask-width>\n" \
11118 "val_life <n> pref_life <n> [def] [noadv] [offl] [noauto]\n" \
11119 "[nolink] [isno]") \
11120 _(sw_interface_ip6nd_ra_config, \
11121 "<intfc> | sw_if_index <id> [maxint <n>] [minint <n>]\n" \
11122 "[life <n>] [count <n>] [interval <n>] [surpress]\n" \
11123 "[managed] [other] [ll] [send] [cease] [isno] [def]") \
11124 _(set_arp_neighbor_limit, "arp_nbr_limit <n> [ipv6]") \
11125 _(l2_patch_add_del, \
11126 "rx <intfc> | rx_sw_if_index <id> tx <intfc> | tx_sw_if_index <id>\n" \
11127 "enable | disable") \
11128 _(mpls_ethernet_add_del_tunnel, \
11129 "tx <intfc> | tx_sw_if_index <n> dst <mac-addr>\n" \
11130 "adj <ip4-addr>/<mw> dst <mac-addr> [del]") \
11131 _(mpls_ethernet_add_del_tunnel_2, \
11132 "inner_vrf_id <n> outer_vrf_id <n> next-hop <ip4-addr>\n" \
11133 "resolve-attempts <n> resolve-if-needed 0 | 1 [del]") \
11134 _(sr_tunnel_add_del, \
11135 "[name <name>] src <ip6-addr> dst <ip6-addr>/<mw> \n" \
11136 "(next <ip6-addr>)+ [tag <ip6-addr>]* [clean] [reroute] \n" \
11137 "[policy <policy_name>]") \
11138 _(sr_policy_add_del, \
11139 "name <name> tunnel <tunnel-name> [tunnel <tunnel-name>]* [del]") \
11140 _(sr_multicast_map_add_del, \
11141 "address [ip6 multicast address] sr-policy [policy name] [del]") \
11142 _(classify_add_del_table, \
11143 "buckets <nn> [skip <n>] [match <n>] [memory_size <nn-bytes>]\n" \
11144 "[del] mask <mask-value>\n" \
11145 " [l2-miss-next | miss-next | acl-miss-next] <name|nn>") \
11146 _(classify_add_del_session, \
11147 "[hit-next|l2-hit-next|acl-hit-next] <name|nn> table-index <nn>\n" \
11148 "skip_n <nn> match_n <nn> match [hex] [l2] [l3 [ip4|ip6]]") \
11149 _(classify_set_interface_ip_table, \
11150 "<intfc> | sw_if_index <nn> table <nn>") \
11151 _(classify_set_interface_l2_tables, \
11152 "<intfc> | sw_if_index <nn> [ip4-table <nn>] [ip6-table <nn>]\n" \
11153 " [other-table <nn>]") \
11154 _(get_node_index, "node <node-name") \
11155 _(add_node_next, "node <node-name> next <next-node-name>") \
11156 _(l2tpv3_create_tunnel, \
11157 "client_address <ip6-addr> our_address <ip6-addr>\n" \
11158 "[local_session_id <nn>][remote_session_id <nn>][local_cookie <nn>]\n"\
11159 "[remote_cookie <nn>]\n[l2-sublayer-preset]\n") \
11160 _(l2tpv3_set_tunnel_cookies, \
11161 "<intfc> | sw_if_index <nn> [new_local_cookie <nn>]\n" \
11162 "[new_remote_cookie <nn>]\n") \
11163 _(l2tpv3_interface_enable_disable, \
11164 "<intfc> | sw_if_index <nn> enable | disable") \
11165 _(l2tpv3_set_lookup_key, \
11166 "lookup_v6_src | lookup_v6_dst | lookup_session_id") \
11167 _(sw_if_l2tpv3_tunnel_dump, "") \
11168 _(vxlan_add_del_tunnel, \
11169 "src <ip-addr> dst <ip-addr> vni <vni> [encap-vrf-id <nn>]\n" \
11170 " [decap-next l2|ip4|ip6] [del]") \
11171 _(vxlan_tunnel_dump, "[<intfc> | sw_if_index <nn>]") \
11172 _(gre_add_del_tunnel, \
11173 "src <ip4-addr> dst <ip4-addr> [outer-fib-id <nn>] [del]\n") \
11174 _(gre_tunnel_dump, "[<intfc> | sw_if_index <nn>]") \
11175 _(l2_fib_clear_table, "") \
11176 _(l2_interface_efp_filter, "sw_if_index <nn> enable | disable") \
11177 _(l2_interface_vlan_tag_rewrite, \
11178 "<intfc> | sw_if_index <nn> \n" \
11179 "[disable][push-[1|2]][pop-[1|2]][translate-1-[1|2]] \n" \
11180 "[translate-2-[1|2]] [push_dot1q 0] tag1 <nn> tag2 <nn>") \
11181 _(create_vhost_user_if, \
11182 "socket <filename> [server] [renumber <dev_instance>] " \
11183 "[mac <mac_address>]") \
11184 _(modify_vhost_user_if, \
11185 "<intfc> | sw_if_index <nn> socket <filename>\n" \
11186 "[server] [renumber <dev_instance>]") \
11187 _(delete_vhost_user_if, "<intfc> | sw_if_index <nn>") \
11188 _(sw_interface_vhost_user_dump, "") \
11189 _(show_version, "") \
11190 _(vxlan_gpe_add_del_tunnel, \
11191 "local <addr> remote <addr> vni <nn>\n" \
11192 "[encap-vrf-id <nn>] [decap-vrf-id <nn>] [next-ip4][next-ip6]" \
11193 "[next-ethernet] [next-nsh]\n") \
11194 _(vxlan_gpe_tunnel_dump, "[<intfc> | sw_if_index <nn>]") \
11195 _(l2_fib_table_dump, "bd_id <bridge-domain-id>") \
11196 _(interface_name_renumber, \
11197 "<intfc> | sw_if_index <nn> new_show_dev_instance <nn>") \
11198 _(input_acl_set_interface, \
11199 "<intfc> | sw_if_index <nn> [ip4-table <nn>] [ip6-table <nn>]\n" \
11200 " [l2-table <nn>] [del]") \
11201 _(want_ip4_arp_events, "address <ip4-address> [del]") \
11202 _(ip_address_dump, "(ipv4 | ipv6) (<intfc> | sw_if_index <id>)") \
11203 _(ip_dump, "ipv4 | ipv6") \
11204 _(ipsec_spd_add_del, "spd_id <n> [del]") \
11205 _(ipsec_interface_add_del_spd, "(<intfc> | sw_if_index <id>)\n" \
11207 _(ipsec_sad_add_del_entry, "sad_id <n> spi <n> crypto_alg <alg>\n" \
11208 " crypto_key <hex> tunnel_src <ip4|ip6> tunnel_dst <ip4|ip6>\n" \
11209 " integ_alg <alg> integ_key <hex>") \
11210 _(ipsec_spd_add_del_entry, "spd_id <n> priority <n> action <action>\n" \
11211 " (inbound|outbound) [sa_id <n>] laddr_start <ip4|ip6>\n" \
11212 " laddr_stop <ip4|ip6> raddr_start <ip4|ip6> raddr_stop <ip4|ip6>\n" \
11213 " [lport_start <n> lport_stop <n>] [rport_start <n> rport_stop <n>]" )\
11214 _(ipsec_sa_set_key, "sa_id <n> crypto_key <hex> integ_key <hex>") \
11215 _(ikev2_profile_add_del, "name <profile_name> [del]") \
11216 _(ikev2_profile_set_auth, "name <profile_name> auth_method <method>\n" \
11217 "(auth_data 0x<data> | auth_data <data>)") \
11218 _(ikev2_profile_set_id, "name <profile_name> id_type <type>\n" \
11219 "(id_data 0x<data> | id_data <data>) (local|remote)") \
11220 _(ikev2_profile_set_ts, "name <profile_name> protocol <proto>\n" \
11221 "start_port <port> end_port <port> start_addr <ip4> end_addr <ip4>\n" \
11222 "(local|remote)") \
11223 _(ikev2_set_local_key, "file <absolute_file_path>") \
11224 _(delete_loopback,"sw_if_index <nn>") \
11225 _(bd_ip_mac_add_del, "bd_id <bridge-domain-id> <ip4/6-addr> <mac-addr> [del]") \
11226 _(map_add_domain, \
11227 "ip4-pfx <ip4pfx> ip6-pfx <ip6pfx> " \
11228 "ip6-src <ip6addr> " \
11229 "ea-bits-len <n> psid-offset <n> psid-len <n>") \
11230 _(map_del_domain, "index <n>") \
11231 _(map_add_del_rule, \
11232 "index <n> psid <n> dst <ip6addr> [del]") \
11233 _(map_domain_dump, "") \
11234 _(map_rule_dump, "index <map-domain>") \
11235 _(want_interface_events, "enable|disable") \
11236 _(want_stats,"enable|disable") \
11237 _(get_first_msg_id, "client <name>") \
11238 _(cop_interface_enable_disable, "<intfc> | sw_if_index <nn> [disable]") \
11239 _(cop_whitelist_enable_disable, "<intfc> | sw_if_index <nn>\n" \
11240 "fib-id <nn> [ip4][ip6][default]") \
11241 _(get_node_graph, " ") \
11242 _(sw_interface_clear_stats,"<intfc> | sw_if_index <nn>") \
11243 _(trace_profile_add, "id <nn> trace-type <0x1f|0x3|0x9|0x11|0x19> " \
11244 "trace-elts <nn> trace-tsp <0|1|2|3> node-id <node id in hex> " \
11245 "app-data <app_data in hex> [pow] [ppc <encap|decap>]") \
11246 _(trace_profile_apply, "id <nn> <ip6-address>/<width>" \
11247 " vrf_id <nn> add | pop | none") \
11248 _(trace_profile_del, "") \
11249 _(lisp_add_del_locator_set, "locator-set <locator_name> [del]") \
11250 _(lisp_add_del_locator, "locator-set <locator_name> " \
11251 "iface <intf> | sw_if_index <sw_if_index> " \
11252 "p <priority> w <weight> [del]") \
11253 _(lisp_add_del_local_eid, "<ipv4|ipv6>/<prefix> " \
11254 "locator-set <locator_name> [del]") \
11255 _(lisp_gpe_add_del_fwd_entry, "eid <ip4|6-addr>/<prefix> " \
11256 "sloc <ip4/6-addr> dloc <ip4|6-addr> [del]") \
11257 _(lisp_add_del_map_resolver, "<ip4|6-addr> [del]") \
11258 _(lisp_gpe_enable_disable, "enable|disable") \
11259 _(lisp_enable_disable, "enable|disable") \
11260 _(lisp_gpe_add_del_iface, "up|down") \
11261 _(lisp_add_del_remote_mapping, "add|del vni <vni> table-id <id> " \
11262 "deid <dest-eid> seid" \
11263 " <src-eid> rloc <locator> " \
11264 "[rloc <loc> ... ]") \
11265 _(lisp_pitr_set_locator_set, "locator-set <loc-set-name> | del") \
11266 _(lisp_locator_set_dump, "") \
11267 _(lisp_local_eid_table_dump, "") \
11268 _(lisp_gpe_tunnel_dump, "") \
11269 _(lisp_map_resolver_dump, "") \
11270 _(lisp_enable_disable_status_dump, "") \
11271 _(af_packet_create, "name <host interface name> [hw_addr <mac>]") \
11272 _(af_packet_delete, "name <host interface name>") \
11273 _(policer_add_del, "name <policer name> <params> [del]") \
11274 _(policer_dump, "[name <policer name>]") \
11275 _(netmap_create, "name <interface name> [hw-addr <mac>] [pipe] " \
11276 "[master|slave]") \
11277 _(netmap_delete, "name <interface name>")
11279 /* List of command functions, CLI names map directly to functions */
11280 #define foreach_cli_function \
11281 _(comment, "usage: comment <ignore-rest-of-line>") \
11282 _(dump_interface_table, "usage: dump_interface_table") \
11283 _(dump_sub_interface_table, "usage: dump_sub_interface_table") \
11284 _(dump_ipv4_table, "usage: dump_ipv4_table") \
11285 _(dump_ipv6_table, "usage: dump_ipv6_table") \
11286 _(dump_stats_table, "usage: dump_stats_table") \
11287 _(dump_macro_table, "usage: dump_macro_table ") \
11288 _(dump_node_table, "usage: dump_node_table") \
11289 _(echo, "usage: echo <message>") \
11290 _(exec, "usage: exec <vpe-debug-CLI-command>") \
11291 _(help, "usage: help") \
11292 _(q, "usage: quit") \
11293 _(quit, "usage: quit") \
11294 _(search_node_table, "usage: search_node_table <name>...") \
11295 _(set, "usage: set <variable-name> <value>") \
11296 _(script, "usage: script <file-name>") \
11297 _(unset, "usage: unset <variable-name>")
11300 static void vl_api_##n##_t_handler_uni \
11301 (vl_api_##n##_t * mp) \
11303 vat_main_t * vam = &vat_main; \
11304 if (vam->json_output) { \
11305 vl_api_##n##_t_handler_json(mp); \
11307 vl_api_##n##_t_handler(mp); \
11310 foreach_vpe_api_reply_msg;
11313 void vat_api_hookup (vat_main_t *vam)
11316 vl_msg_api_set_handlers(VL_API_##N, #n, \
11317 vl_api_##n##_t_handler_uni, \
11319 vl_api_##n##_t_endian, \
11320 vl_api_##n##_t_print, \
11321 sizeof(vl_api_##n##_t), 1);
11322 foreach_vpe_api_reply_msg;
11325 vl_msg_api_set_first_available_msg_id (VL_MSG_FIRST_AVAILABLE);
11327 vam->sw_if_index_by_interface_name =
11328 hash_create_string (0, sizeof (uword));
11330 vam->function_by_name =
11331 hash_create_string (0, sizeof(uword));
11333 vam->help_by_name =
11334 hash_create_string (0, sizeof(uword));
11336 /* API messages we can send */
11337 #define _(n,h) hash_set_mem (vam->function_by_name, #n, api_##n);
11338 foreach_vpe_api_msg;
11342 #define _(n,h) hash_set_mem (vam->help_by_name, #n, h);
11343 foreach_vpe_api_msg;
11346 /* CLI functions */
11347 #define _(n,h) hash_set_mem (vam->function_by_name, #n, n);
11348 foreach_cli_function;
11352 #define _(n,h) hash_set_mem (vam->help_by_name, #n, h);
11353 foreach_cli_function;
11357 #undef vl_api_version
11358 #define vl_api_version(n,v) static u32 vpe_api_version = v;
11359 #include <api/vpe.api.h>
11360 #undef vl_api_version
11362 void vl_client_add_api_signatures (vl_api_memclnt_create_t *mp)
11365 * Send the main API signature in slot 0. This bit of code must
11366 * match the checks in ../vpe/api/api.c: vl_msg_api_version_check().
11368 mp->api_versions[0] = clib_host_to_net_u32 (vpe_api_version);