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>
47 #include "vat/json_format.h"
49 #define vl_typedefs /* define message structures */
50 #include <api/vpe_all_api_h.h>
53 /* declare message handlers for each api */
55 #define vl_endianfun /* define message structures */
56 #include <api/vpe_all_api_h.h>
59 /* instantiate all the print functions we know about */
60 #define vl_print(handle, ...)
62 #include <api/vpe_all_api_h.h>
65 uword unformat_sw_if_index (unformat_input_t * input, va_list * args)
67 vat_main_t * vam = va_arg (*args, vat_main_t *);
68 u32 * result = va_arg (*args, u32 *);
72 if (!unformat (input, "%s", &if_name))
75 p = hash_get_mem (vam->sw_if_index_by_interface_name, if_name);
82 /* Parse an IP4 address %d.%d.%d.%d. */
83 uword unformat_ip4_address (unformat_input_t * input, va_list * args)
85 u8 * result = va_arg (*args, u8 *);
88 if (! unformat (input, "%d.%d.%d.%d", &a[0], &a[1], &a[2], &a[3]))
91 if (a[0] >= 256 || a[1] >= 256 || a[2] >= 256 || a[3] >= 256)
104 unformat_ethernet_address (unformat_input_t * input, va_list * args)
106 u8 * result = va_arg (*args, u8 *);
109 if (! unformat (input, "%_%x:%x:%x:%x:%x:%x%_",
110 &a[0], &a[1], &a[2], &a[3], &a[4], &a[5]))
114 for (i = 0; i < 6; i++)
115 if (a[i] >= (1 << 8))
118 for (i = 0; i < 6; i++)
124 /* Returns ethernet type as an int in host byte order. */
126 unformat_ethernet_type_host_byte_order (unformat_input_t * input,
129 u16 * result = va_arg (*args, u16 *);
133 if (unformat (input, "0x%x", &type)
134 || unformat (input, "%d", &type))
136 if (type >= (1 << 16))
144 /* Parse an IP6 address. */
145 uword unformat_ip6_address (unformat_input_t * input, va_list * args)
147 ip6_address_t * result = va_arg (*args, ip6_address_t *);
149 uword hex_quad, n_hex_quads, hex_digit, n_hex_digits;
150 uword c, n_colon, double_colon_index;
152 n_hex_quads = hex_quad = n_hex_digits = n_colon = 0;
153 double_colon_index = ARRAY_LEN (hex_quads);
154 while ((c = unformat_get_input (input)) != UNFORMAT_END_OF_INPUT)
157 if (c >= '0' && c <= '9')
159 else if (c >= 'a' && c <= 'f')
160 hex_digit = c + 10 - 'a';
161 else if (c >= 'A' && c <= 'F')
162 hex_digit = c + 10 - 'A';
163 else if (c == ':' && n_colon < 2)
167 unformat_put_input (input);
171 /* Too many hex quads. */
172 if (n_hex_quads >= ARRAY_LEN (hex_quads))
177 hex_quad = (hex_quad << 4) | hex_digit;
179 /* Hex quad must fit in 16 bits. */
180 if (n_hex_digits >= 4)
187 /* Save position of :: */
190 /* More than one :: ? */
191 if (double_colon_index < ARRAY_LEN (hex_quads))
193 double_colon_index = n_hex_quads;
196 if (n_colon > 0 && n_hex_digits > 0)
198 hex_quads[n_hex_quads++] = hex_quad;
204 if (n_hex_digits > 0)
205 hex_quads[n_hex_quads++] = hex_quad;
210 /* Expand :: to appropriate number of zero hex quads. */
211 if (double_colon_index < ARRAY_LEN (hex_quads))
213 word n_zero = ARRAY_LEN (hex_quads) - n_hex_quads;
215 for (i = n_hex_quads - 1; i >= (signed) double_colon_index; i--)
216 hex_quads[n_zero + i] = hex_quads[i];
218 for (i = 0; i < n_zero; i++)
219 hex_quads[double_colon_index + i] = 0;
221 n_hex_quads = ARRAY_LEN (hex_quads);
224 /* Too few hex quads given. */
225 if (n_hex_quads < ARRAY_LEN (hex_quads))
228 for (i = 0; i < ARRAY_LEN (hex_quads); i++)
229 result->as_u16[i] = clib_host_to_net_u16 (hex_quads[i]);
236 unformat_ipsec_policy_action (unformat_input_t * input, va_list * args)
239 u32 * r = va_arg (*args, u32 *);
242 #define _(v,f,s) else if (unformat (input, s)) *r = IPSEC_POLICY_ACTION_##f;
243 foreach_ipsec_policy_action
254 unformat_ipsec_crypto_alg (unformat_input_t * input, va_list * args)
257 u32 * r = va_arg (*args, u32 *);
260 #define _(v,f,s) else if (unformat (input, s)) *r = IPSEC_CRYPTO_ALG_##f;
261 foreach_ipsec_crypto_alg
272 format_ipsec_crypto_alg (u8 * s, va_list * args)
275 u32 i = va_arg (*args, u32);
280 #define _(v,f,str) case IPSEC_CRYPTO_ALG_##f: t = (u8 *) str; break;
281 foreach_ipsec_crypto_alg
284 return format (s, "unknown");
286 return format (s, "%s", t);
288 return format (s, "Unimplemented");
293 unformat_ipsec_integ_alg (unformat_input_t * input, va_list * args)
296 u32 * r = va_arg (*args, u32 *);
299 #define _(v,f,s) else if (unformat (input, s)) *r = IPSEC_INTEG_ALG_##f;
300 foreach_ipsec_integ_alg
311 format_ipsec_integ_alg (u8 * s, va_list * args)
314 u32 i = va_arg (*args, u32);
319 #define _(v,f,str) case IPSEC_INTEG_ALG_##f: t = (u8 *) str; break;
320 foreach_ipsec_integ_alg
323 return format (s, "unknown");
325 return format (s, "%s", t);
327 return format (s, "Unsupported");
332 unformat_ikev2_auth_method (unformat_input_t * input, va_list * args)
335 u32 * r = va_arg (*args, u32 *);
338 #define _(v,f,s) else if (unformat (input, s)) *r = IKEV2_AUTH_METHOD_##f;
339 foreach_ikev2_auth_method
350 unformat_ikev2_id_type (unformat_input_t * input, va_list * args)
353 u32 * r = va_arg (*args, u32 *);
356 #define _(v,f,s) else if (unformat (input, s)) *r = IKEV2_ID_TYPE_##f;
357 foreach_ikev2_id_type
367 u8 * format_ip4_address (u8 * s, va_list * args)
369 u8 * a = va_arg (*args, u8 *);
370 return format (s, "%d.%d.%d.%d", a[0], a[1], a[2], a[3]);
373 u8 * format_ip6_address (u8 * s, va_list * args)
375 ip6_address_t * a = va_arg (*args, ip6_address_t *);
376 u32 i, i_max_n_zero, max_n_zeros, i_first_zero, n_zeros, last_double_colon;
378 i_max_n_zero = ARRAY_LEN (a->as_u16);
380 i_first_zero = i_max_n_zero;
382 for (i = 0; i < ARRAY_LEN (a->as_u16); i++)
384 u32 is_zero = a->as_u16[i] == 0;
385 if (is_zero && i_first_zero >= ARRAY_LEN (a->as_u16))
391 if ((! is_zero && n_zeros > max_n_zeros)
392 || (i + 1 >= ARRAY_LEN (a->as_u16) && n_zeros > max_n_zeros))
394 i_max_n_zero = i_first_zero;
395 max_n_zeros = n_zeros;
396 i_first_zero = ARRAY_LEN (a->as_u16);
401 last_double_colon = 0;
402 for (i = 0; i < ARRAY_LEN (a->as_u16); i++)
404 if (i == i_max_n_zero && max_n_zeros > 1)
406 s = format (s, "::");
407 i += max_n_zeros - 1;
408 last_double_colon = 1;
412 s = format (s, "%s%x",
413 (last_double_colon || i == 0) ? "" : ":",
414 clib_net_to_host_u16 (a->as_u16[i]));
415 last_double_colon = 0;
422 /* Format an IP46 address. */
423 u8 * format_ip46_address (u8 * s, va_list * args)
425 ip46_address_t *ip46 = va_arg (*args, ip46_address_t *);
426 return ip46_address_is_ip4(ip46)?
427 format(s, "%U", format_ip4_address, &ip46->ip4):
428 format(s, "%U", format_ip6_address, &ip46->ip6);
431 u8 * format_ethernet_address (u8 * s, va_list * args)
433 u8 * a = va_arg (*args, u8 *);
435 return format (s, "%02x:%02x:%02x:%02x:%02x:%02x",
436 a[0], a[1], a[2], a[3], a[4], a[5]);
439 void increment_v4_address (ip4_address_t * a)
443 v = ntohl(a->as_u32) + 1;
444 a->as_u32 = ntohl(v);
447 void increment_v6_address (ip6_address_t * a)
451 v0 = clib_net_to_host_u64 (a->as_u64[0]);
452 v1 = clib_net_to_host_u64 (a->as_u64[1]);
457 a->as_u64[0] = clib_net_to_host_u64 (v0);
458 a->as_u64[1] = clib_net_to_host_u64 (v1);
462 static void vl_api_create_loopback_reply_t_handler
463 (vl_api_create_loopback_reply_t * mp)
465 vat_main_t * vam = &vat_main;
466 i32 retval = ntohl(mp->retval);
468 vam->retval = retval;
469 vam->result_ready = 1;
470 vam->regenerate_interface_table = 1;
473 static void vl_api_create_loopback_reply_t_handler_json
474 (vl_api_create_loopback_reply_t * mp)
476 vat_main_t * vam = &vat_main;
477 vat_json_node_t node;
479 vat_json_init_object(&node);
480 vat_json_object_add_int(&node, "retval", ntohl(mp->retval));
481 vat_json_object_add_uint(&node, "sw_if_index", ntohl(mp->sw_if_index));
483 vat_json_print(vam->ofp, &node);
484 vat_json_free(&node);
486 vam->retval = ntohl(mp->retval);
487 vam->result_ready = 1;
490 static void vl_api_create_vlan_subif_reply_t_handler
491 (vl_api_create_vlan_subif_reply_t * mp)
493 vat_main_t * vam = &vat_main;
494 i32 retval = ntohl(mp->retval);
496 vam->retval = retval;
497 vam->result_ready = 1;
498 vam->regenerate_interface_table = 1;
501 static void vl_api_create_vlan_subif_reply_t_handler_json
502 (vl_api_create_vlan_subif_reply_t * mp)
504 vat_main_t * vam = &vat_main;
505 vat_json_node_t node;
507 vat_json_init_object(&node);
508 vat_json_object_add_int(&node, "retval", ntohl(mp->retval));
509 vat_json_object_add_uint(&node, "sw_if_index", ntohl(mp->sw_if_index));
511 vat_json_print(vam->ofp, &node);
512 vat_json_free(&node);
514 vam->retval = ntohl(mp->retval);
515 vam->result_ready = 1;
518 static void vl_api_create_subif_reply_t_handler
519 (vl_api_create_subif_reply_t * mp)
521 vat_main_t * vam = &vat_main;
522 i32 retval = ntohl(mp->retval);
524 vam->retval = retval;
525 vam->result_ready = 1;
526 vam->regenerate_interface_table = 1;
529 static void vl_api_create_subif_reply_t_handler_json
530 (vl_api_create_subif_reply_t * mp)
532 vat_main_t * vam = &vat_main;
533 vat_json_node_t node;
535 vat_json_init_object(&node);
536 vat_json_object_add_int(&node, "retval", ntohl(mp->retval));
537 vat_json_object_add_uint(&node, "sw_if_index", ntohl(mp->sw_if_index));
539 vat_json_print(vam->ofp, &node);
540 vat_json_free(&node);
542 vam->retval = ntohl(mp->retval);
543 vam->result_ready = 1;
546 static void vl_api_interface_name_renumber_reply_t_handler
547 (vl_api_interface_name_renumber_reply_t * mp)
549 vat_main_t * vam = &vat_main;
550 i32 retval = ntohl(mp->retval);
552 vam->retval = retval;
553 vam->result_ready = 1;
554 vam->regenerate_interface_table = 1;
557 static void vl_api_interface_name_renumber_reply_t_handler_json
558 (vl_api_interface_name_renumber_reply_t * mp)
560 vat_main_t * vam = &vat_main;
561 vat_json_node_t node;
563 vat_json_init_object(&node);
564 vat_json_object_add_int(&node, "retval", ntohl(mp->retval));
566 vat_json_print(vam->ofp, &node);
567 vat_json_free(&node);
569 vam->retval = ntohl(mp->retval);
570 vam->result_ready = 1;
574 * Special-case: build the interface table, maintain
575 * the next loopback sw_if_index vbl.
577 static void vl_api_sw_interface_details_t_handler
578 (vl_api_sw_interface_details_t * mp)
580 vat_main_t * vam = &vat_main;
581 u8 * s = format (0, "%s%c", mp->interface_name, 0);
583 hash_set_mem (vam->sw_if_index_by_interface_name, s,
584 ntohl(mp->sw_if_index));
586 /* In sub interface case, fill the sub interface table entry */
587 if (mp->sw_if_index != mp->sup_sw_if_index) {
588 sw_interface_subif_t * sub = NULL;
590 vec_add2(vam->sw_if_subif_table, sub, 1);
592 vec_validate(sub->interface_name, strlen((char *)s) + 1);
593 strncpy((char *)sub->interface_name, (char *)s,
594 vec_len(sub->interface_name));
595 sub->sw_if_index = ntohl(mp->sw_if_index);
596 sub->sub_id = ntohl(mp->sub_id);
598 sub->sub_dot1ad = mp->sub_dot1ad;
599 sub->sub_number_of_tags = mp->sub_number_of_tags;
600 sub->sub_outer_vlan_id = ntohs(mp->sub_outer_vlan_id);
601 sub->sub_inner_vlan_id = ntohs(mp->sub_inner_vlan_id);
602 sub->sub_exact_match = mp->sub_exact_match;
603 sub->sub_default = mp->sub_default;
604 sub->sub_outer_vlan_id_any = mp->sub_outer_vlan_id_any;
605 sub->sub_inner_vlan_id_any = mp->sub_inner_vlan_id_any;
607 /* vlan tag rewrite */
608 sub->vtr_op = ntohl(mp->vtr_op);
609 sub->vtr_push_dot1q = ntohl(mp->vtr_push_dot1q);
610 sub->vtr_tag1 = ntohl(mp->vtr_tag1);
611 sub->vtr_tag2 = ntohl(mp->vtr_tag2);
615 static void vl_api_sw_interface_details_t_handler_json
616 (vl_api_sw_interface_details_t * mp)
618 vat_main_t * vam = &vat_main;
619 vat_json_node_t *node = NULL;
621 if (VAT_JSON_ARRAY != vam->json_tree.type) {
622 ASSERT(VAT_JSON_NONE == vam->json_tree.type);
623 vat_json_init_array(&vam->json_tree);
625 node = vat_json_array_add(&vam->json_tree);
627 vat_json_init_object(node);
628 vat_json_object_add_uint(node, "sw_if_index", ntohl(mp->sw_if_index));
629 vat_json_object_add_uint(node, "sup_sw_if_index", ntohl(mp->sup_sw_if_index));
630 vat_json_object_add_uint(node, "l2_address_length", ntohl(mp->l2_address_length));
631 vat_json_object_add_bytes(node, "l2_address", mp->l2_address, sizeof(mp->l2_address));
632 vat_json_object_add_string_copy(node, "interface_name", mp->interface_name);
633 vat_json_object_add_uint(node, "admin_up_down", mp->admin_up_down);
634 vat_json_object_add_uint(node, "link_up_down", mp->link_up_down);
635 vat_json_object_add_uint(node, "link_duplex", mp->link_duplex);
636 vat_json_object_add_uint(node, "link_speed", mp->link_speed);
637 vat_json_object_add_uint(node, "mtu", ntohs(mp->link_mtu));
638 vat_json_object_add_uint(node, "sub_id", ntohl(mp->sub_id));
639 vat_json_object_add_uint(node, "sub_dot1ad", mp->sub_dot1ad);
640 vat_json_object_add_uint(node, "sub_number_of_tags", mp->sub_number_of_tags);
641 vat_json_object_add_uint(node, "sub_outer_vlan_id", ntohs(mp->sub_outer_vlan_id));
642 vat_json_object_add_uint(node, "sub_inner_vlan_id", ntohs(mp->sub_inner_vlan_id));
643 vat_json_object_add_uint(node, "sub_exact_match", mp->sub_exact_match);
644 vat_json_object_add_uint(node, "sub_default", mp->sub_default);
645 vat_json_object_add_uint(node, "sub_outer_vlan_id_any", mp->sub_outer_vlan_id_any);
646 vat_json_object_add_uint(node, "sub_inner_vlan_id_any", mp->sub_inner_vlan_id_any);
647 vat_json_object_add_uint(node, "vtr_op", ntohl(mp->vtr_op));
648 vat_json_object_add_uint(node, "vtr_push_dot1q", ntohl(mp->vtr_push_dot1q));
649 vat_json_object_add_uint(node, "vtr_tag1", ntohl(mp->vtr_tag1));
650 vat_json_object_add_uint(node, "vtr_tag2", ntohl(mp->vtr_tag2));
653 static void vl_api_sw_interface_set_flags_t_handler
654 (vl_api_sw_interface_set_flags_t * mp)
656 vat_main_t * vam = &vat_main;
657 if (vam->interface_event_display)
658 errmsg ("interface flags: sw_if_index %d %s %s\n",
659 ntohl(mp->sw_if_index),
660 mp->admin_up_down ? "admin-up" : "admin-down",
661 mp->link_up_down ? "link-up" : "link-down");
664 static void vl_api_sw_interface_set_flags_t_handler_json
665 (vl_api_sw_interface_set_flags_t * mp)
667 /* JSON output not supported */
670 static void vl_api_cli_reply_t_handler
671 (vl_api_cli_reply_t * mp)
673 vat_main_t * vam = &vat_main;
674 i32 retval = ntohl(mp->retval);
676 vam->retval = retval;
677 vam->shmem_result = (u8 *) mp->reply_in_shmem;
678 vam->result_ready = 1;
681 static void vl_api_cli_reply_t_handler_json
682 (vl_api_cli_reply_t * mp)
684 vat_main_t * vam = &vat_main;
685 vat_json_node_t node;
686 api_main_t * am = &api_main;
690 vat_json_init_object(&node);
691 vat_json_object_add_int(&node, "retval", ntohl(mp->retval));
692 vat_json_object_add_uint(&node, "reply_in_shmem",
693 ntohl(mp->reply_in_shmem));
694 /* Toss the shared-memory original... */
695 pthread_mutex_lock (&am->vlib_rp->mutex);
696 oldheap = svm_push_data_heap (am->vlib_rp);
698 reply = (u8 *)(mp->reply_in_shmem);
701 svm_pop_heap (oldheap);
702 pthread_mutex_unlock (&am->vlib_rp->mutex);
704 vat_json_print(vam->ofp, &node);
705 vat_json_free(&node);
707 vam->retval = ntohl(mp->retval);
708 vam->result_ready = 1;
711 static void vl_api_classify_add_del_table_reply_t_handler
712 (vl_api_classify_add_del_table_reply_t * mp)
714 vat_main_t * vam = &vat_main;
715 i32 retval = ntohl(mp->retval);
716 if (vam->async_mode) {
717 vam->async_errors += (retval < 0);
719 vam->retval = retval;
720 vam->result_ready = 1;
722 ((mp->new_table_index != 0xFFFFFFFF) ||
723 (mp->skip_n_vectors != 0xFFFFFFFF) ||
724 (mp->match_n_vectors != 0xFFFFFFFF)))
726 * Note: this is just barely thread-safe, depends on
727 * the main thread spinning waiting for an answer...
729 errmsg ("new index %d, skip_n_vectors %d, match_n_vectors %d\n",
730 ntohl(mp->new_table_index),
731 ntohl(mp->skip_n_vectors), ntohl(mp->match_n_vectors));
735 static void vl_api_classify_add_del_table_reply_t_handler_json
736 (vl_api_classify_add_del_table_reply_t * mp)
738 vat_main_t * vam = &vat_main;
739 vat_json_node_t node;
741 vat_json_init_object(&node);
742 vat_json_object_add_int(&node, "retval", ntohl(mp->retval));
743 vat_json_object_add_uint(&node, "new_table_index", ntohl(mp->new_table_index));
744 vat_json_object_add_uint(&node, "skip_n_vectors", ntohl(mp->skip_n_vectors));
745 vat_json_object_add_uint(&node, "match_n_vectors", ntohl(mp->match_n_vectors));
747 vat_json_print(vam->ofp, &node);
748 vat_json_free(&node);
750 vam->retval = ntohl(mp->retval);
751 vam->result_ready = 1;
754 static void vl_api_get_node_index_reply_t_handler
755 (vl_api_get_node_index_reply_t * mp)
757 vat_main_t * vam = &vat_main;
758 i32 retval = ntohl(mp->retval);
759 if (vam->async_mode) {
760 vam->async_errors += (retval < 0);
762 vam->retval = retval;
763 vam->result_ready = 1;
765 errmsg ("node index %d\n", ntohl(mp->node_index));
769 static void vl_api_get_node_index_reply_t_handler_json
770 (vl_api_get_node_index_reply_t * mp)
772 vat_main_t * vam = &vat_main;
773 vat_json_node_t node;
775 vat_json_init_object(&node);
776 vat_json_object_add_int(&node, "retval", ntohl(mp->retval));
777 vat_json_object_add_uint(&node, "node_index", ntohl(mp->node_index));
779 vat_json_print(vam->ofp, &node);
780 vat_json_free(&node);
782 vam->retval = ntohl(mp->retval);
783 vam->result_ready = 1;
786 static void vl_api_add_node_next_reply_t_handler
787 (vl_api_add_node_next_reply_t * mp)
789 vat_main_t * vam = &vat_main;
790 i32 retval = ntohl(mp->retval);
791 if (vam->async_mode) {
792 vam->async_errors += (retval < 0);
794 vam->retval = retval;
795 vam->result_ready = 1;
797 errmsg ("next index %d\n", ntohl(mp->next_index));
801 static void vl_api_add_node_next_reply_t_handler_json
802 (vl_api_add_node_next_reply_t * mp)
804 vat_main_t * vam = &vat_main;
805 vat_json_node_t node;
807 vat_json_init_object(&node);
808 vat_json_object_add_int(&node, "retval", ntohl(mp->retval));
809 vat_json_object_add_uint(&node, "next_index", ntohl(mp->next_index));
811 vat_json_print(vam->ofp, &node);
812 vat_json_free(&node);
814 vam->retval = ntohl(mp->retval);
815 vam->result_ready = 1;
818 static void vl_api_mpls_gre_add_del_tunnel_reply_t_handler
819 (vl_api_mpls_gre_add_del_tunnel_reply_t * mp)
821 vat_main_t * vam = &vat_main;
822 i32 retval = ntohl(mp->retval);
823 u32 sw_if_index = ntohl(mp->tunnel_sw_if_index);
825 if (retval >= 0 && sw_if_index != (u32)~0) {
826 errmsg ("tunnel_sw_if_index %d\n", sw_if_index);
828 vam->retval = retval;
829 vam->result_ready = 1;
832 static void vl_api_mpls_gre_add_del_tunnel_reply_t_handler_json
833 (vl_api_mpls_gre_add_del_tunnel_reply_t * mp)
835 vat_main_t * vam = &vat_main;
836 vat_json_node_t node;
838 vat_json_init_object(&node);
839 vat_json_object_add_int(&node, "retval", ntohl(mp->retval));
840 vat_json_object_add_uint(&node, "tunnel_sw_if_index", ntohl(mp->tunnel_sw_if_index));
842 vat_json_print(vam->ofp, &node);
843 vat_json_free(&node);
845 vam->retval = ntohl(mp->retval);
846 vam->result_ready = 1;
850 static void vl_api_show_version_reply_t_handler
851 (vl_api_show_version_reply_t * mp)
853 vat_main_t * vam = &vat_main;
854 i32 retval = ntohl(mp->retval);
857 errmsg (" program: %s\n", mp->program);
858 errmsg (" version: %s\n", mp->version);
859 errmsg (" build date: %s\n", mp->build_date);
860 errmsg ("build directory: %s\n", mp->build_directory);
862 vam->retval = retval;
863 vam->result_ready = 1;
866 static void vl_api_show_version_reply_t_handler_json
867 (vl_api_show_version_reply_t * mp)
869 vat_main_t * vam = &vat_main;
870 vat_json_node_t node;
872 vat_json_init_object(&node);
873 vat_json_object_add_int(&node, "retval", ntohl(mp->retval));
874 vat_json_object_add_string_copy(&node, "program", mp->program);
875 vat_json_object_add_string_copy(&node, "version", mp->version);
876 vat_json_object_add_string_copy(&node, "build_date", mp->build_date);
877 vat_json_object_add_string_copy(&node, "build_directory", mp->build_directory);
879 vat_json_print(vam->ofp, &node);
880 vat_json_free(&node);
882 vam->retval = ntohl(mp->retval);
883 vam->result_ready = 1;
886 static void vl_api_ip4_arp_event_t_handler
887 (vl_api_ip4_arp_event_t * mp)
889 vat_main_t * vam = &vat_main;
890 errmsg ("arp event: address %U new mac %U sw_if_index %d\n",
891 format_ip4_address, &mp->address,
892 format_ethernet_address, mp->new_mac, mp->sw_if_index);
895 static void vl_api_ip4_arp_event_t_handler_json
896 (vl_api_ip4_arp_event_t * mp)
898 /* JSON output not supported */
902 * Special-case: build the bridge domain table, maintain
903 * the next bd id vbl.
905 static void vl_api_bridge_domain_details_t_handler
906 (vl_api_bridge_domain_details_t * mp)
908 vat_main_t * vam = &vat_main;
909 u32 n_sw_ifs = ntohl (mp->n_sw_ifs);
911 fformat (vam->ofp, "\n%-3s %-3s %-3s %-3s %-3s %-3s\n",
912 " ID", "LRN", "FWD", "FLD", "BVI", "#IF");
914 fformat (vam->ofp, "%3d %3d %3d %3d %3d %3d\n",
915 ntohl (mp->bd_id), mp->learn, mp->forward,
916 mp->flood, ntohl (mp->bvi_sw_if_index), n_sw_ifs);
919 fformat (vam->ofp, "\n\n%s %s %s\n", "sw_if_index", "SHG",
923 static void vl_api_bridge_domain_details_t_handler_json
924 (vl_api_bridge_domain_details_t * mp)
926 vat_main_t * vam = &vat_main;
927 vat_json_node_t *node, *array = NULL;
929 if (VAT_JSON_ARRAY != vam->json_tree.type) {
930 ASSERT(VAT_JSON_NONE == vam->json_tree.type);
931 vat_json_init_array(&vam->json_tree);
933 node = vat_json_array_add(&vam->json_tree);
935 vat_json_init_object(node);
936 vat_json_object_add_uint(node, "bd_id", ntohl(mp->bd_id));
937 vat_json_object_add_uint(node, "flood", mp->flood);
938 vat_json_object_add_uint(node, "forward", mp->forward);
939 vat_json_object_add_uint(node, "learn", mp->learn);
940 vat_json_object_add_uint(node, "bvi_sw_if_index", ntohl(mp->bvi_sw_if_index));
941 vat_json_object_add_uint(node, "n_sw_ifs", ntohl(mp->n_sw_ifs));
942 array = vat_json_object_add(node, "sw_if");
943 vat_json_init_array(array);
947 * Special-case: build the bridge domain sw if table.
949 static void vl_api_bridge_domain_sw_if_details_t_handler
950 (vl_api_bridge_domain_sw_if_details_t * mp)
952 vat_main_t * vam = &vat_main;
957 sw_if_index = ntohl (mp->sw_if_index);
958 hash_foreach_pair (p, vam->sw_if_index_by_interface_name,
960 if ((u32) p->value[0] == sw_if_index) {
961 sw_if_name = (u8 *)(p->key);
966 fformat (vam->ofp, "%7d %3d %s", sw_if_index,
967 mp->shg, sw_if_name ? (char *)sw_if_name :
968 "sw_if_index not found!");
971 static void vl_api_bridge_domain_sw_if_details_t_handler_json
972 (vl_api_bridge_domain_sw_if_details_t * mp)
974 vat_main_t * vam = &vat_main;
975 vat_json_node_t *node = NULL;
976 uword last_index = 0;
978 ASSERT(VAT_JSON_ARRAY == vam->json_tree.type);
979 ASSERT(vec_len(vam->json_tree.array) >= 1);
980 last_index = vec_len(vam->json_tree.array) - 1;
981 node = &vam->json_tree.array[last_index];
982 node = vat_json_object_get_element(node, "sw_if");
983 ASSERT(NULL != node);
984 node = vat_json_array_add(node);
986 vat_json_init_object(node);
987 vat_json_object_add_uint(node, "bd_id", ntohl(mp->bd_id));
988 vat_json_object_add_uint(node, "sw_if_index", ntohl(mp->sw_if_index));
989 vat_json_object_add_uint(node, "shg", mp->shg);
992 static void vl_api_control_ping_reply_t_handler
993 (vl_api_control_ping_reply_t * mp)
995 vat_main_t * vam = &vat_main;
996 i32 retval = ntohl(mp->retval);
997 if (vam->async_mode) {
998 vam->async_errors += (retval < 0);
1000 vam->retval = retval;
1001 vam->result_ready = 1;
1005 static void vl_api_control_ping_reply_t_handler_json
1006 (vl_api_control_ping_reply_t * mp)
1008 vat_main_t * vam = &vat_main;
1009 i32 retval = ntohl(mp->retval);
1011 if (VAT_JSON_NONE != vam->json_tree.type) {
1012 vat_json_print(vam->ofp, &vam->json_tree);
1013 vat_json_free(&vam->json_tree);
1014 vam->json_tree.type = VAT_JSON_NONE;
1017 vat_json_init_array(&vam->json_tree);
1018 vat_json_print(vam->ofp, &vam->json_tree);
1019 vam->json_tree.type = VAT_JSON_NONE;
1022 vam->retval = retval;
1023 vam->result_ready = 1;
1026 static void vl_api_l2_flags_reply_t_handler
1027 (vl_api_l2_flags_reply_t * mp)
1029 vat_main_t * vam = &vat_main;
1030 i32 retval = ntohl(mp->retval);
1031 if (vam->async_mode) {
1032 vam->async_errors += (retval < 0);
1034 vam->retval = retval;
1035 vam->result_ready = 1;
1039 static void vl_api_l2_flags_reply_t_handler_json
1040 (vl_api_l2_flags_reply_t * mp)
1042 vat_main_t * vam = &vat_main;
1043 vat_json_node_t node;
1045 vat_json_init_object(&node);
1046 vat_json_object_add_int(&node, "retval", ntohl(mp->retval));
1047 vat_json_object_add_uint(&node, "resulting_feature_bitmap", ntohl(mp->resulting_feature_bitmap));
1049 vat_json_print(vam->ofp, &node);
1050 vat_json_free(&node);
1052 vam->retval = ntohl(mp->retval);
1053 vam->result_ready = 1;
1056 static void vl_api_bridge_flags_reply_t_handler
1057 (vl_api_bridge_flags_reply_t * mp)
1059 vat_main_t * vam = &vat_main;
1060 i32 retval = ntohl(mp->retval);
1061 if (vam->async_mode) {
1062 vam->async_errors += (retval < 0);
1064 vam->retval = retval;
1065 vam->result_ready = 1;
1069 static void vl_api_bridge_flags_reply_t_handler_json
1070 (vl_api_bridge_flags_reply_t * mp)
1072 vat_main_t * vam = &vat_main;
1073 vat_json_node_t node;
1075 vat_json_init_object(&node);
1076 vat_json_object_add_int(&node, "retval", ntohl(mp->retval));
1077 vat_json_object_add_uint(&node, "resulting_feature_bitmap", ntohl(mp->resulting_feature_bitmap));
1079 vat_json_print(vam->ofp, &node);
1080 vat_json_free(&node);
1082 vam->retval = ntohl(mp->retval);
1083 vam->result_ready = 1;
1086 static void vl_api_tap_connect_reply_t_handler
1087 (vl_api_tap_connect_reply_t * mp)
1089 vat_main_t * vam = &vat_main;
1090 i32 retval = ntohl(mp->retval);
1091 if (vam->async_mode) {
1092 vam->async_errors += (retval < 0);
1094 vam->retval = retval;
1095 vam->result_ready = 1;
1099 static void vl_api_tap_connect_reply_t_handler_json
1100 (vl_api_tap_connect_reply_t * mp)
1102 vat_main_t * vam = &vat_main;
1103 vat_json_node_t node;
1105 vat_json_init_object(&node);
1106 vat_json_object_add_int(&node, "retval", ntohl(mp->retval));
1107 vat_json_object_add_uint(&node, "sw_if_index", ntohl(mp->sw_if_index));
1109 vat_json_print(vam->ofp, &node);
1110 vat_json_free(&node);
1112 vam->retval = ntohl(mp->retval);
1113 vam->result_ready = 1;
1116 static void vl_api_tap_modify_reply_t_handler
1117 (vl_api_tap_modify_reply_t * mp)
1119 vat_main_t * vam = &vat_main;
1120 i32 retval = ntohl(mp->retval);
1121 if (vam->async_mode) {
1122 vam->async_errors += (retval < 0);
1124 vam->retval = retval;
1125 vam->result_ready = 1;
1129 static void vl_api_tap_modify_reply_t_handler_json
1130 (vl_api_tap_modify_reply_t * mp)
1132 vat_main_t * vam = &vat_main;
1133 vat_json_node_t node;
1135 vat_json_init_object(&node);
1136 vat_json_object_add_int(&node, "retval", ntohl(mp->retval));
1137 vat_json_object_add_uint(&node, "sw_if_index", ntohl(mp->sw_if_index));
1139 vat_json_print(vam->ofp, &node);
1140 vat_json_free(&node);
1142 vam->retval = ntohl(mp->retval);
1143 vam->result_ready = 1;
1146 static void vl_api_tap_delete_reply_t_handler
1147 (vl_api_tap_delete_reply_t * mp)
1149 vat_main_t * vam = &vat_main;
1150 i32 retval = ntohl(mp->retval);
1151 if (vam->async_mode) {
1152 vam->async_errors += (retval < 0);
1154 vam->retval = retval;
1155 vam->result_ready = 1;
1159 static void vl_api_tap_delete_reply_t_handler_json
1160 (vl_api_tap_delete_reply_t * mp)
1162 vat_main_t * vam = &vat_main;
1163 vat_json_node_t node;
1165 vat_json_init_object(&node);
1166 vat_json_object_add_int(&node, "retval", ntohl(mp->retval));
1168 vat_json_print(vam->ofp, &node);
1169 vat_json_free(&node);
1171 vam->retval = ntohl(mp->retval);
1172 vam->result_ready = 1;
1175 static void vl_api_mpls_ethernet_add_del_tunnel_reply_t_handler
1176 (vl_api_mpls_ethernet_add_del_tunnel_reply_t * mp)
1178 vat_main_t * vam = &vat_main;
1179 i32 retval = ntohl(mp->retval);
1180 if (vam->async_mode) {
1181 vam->async_errors += (retval < 0);
1183 vam->retval = retval;
1184 vam->result_ready = 1;
1188 static void vl_api_mpls_ethernet_add_del_tunnel_reply_t_handler_json
1189 (vl_api_mpls_ethernet_add_del_tunnel_reply_t * mp)
1191 vat_main_t * vam = &vat_main;
1192 vat_json_node_t node;
1194 vat_json_init_object(&node);
1195 vat_json_object_add_int(&node, "retval", ntohl(mp->retval));
1196 vat_json_object_add_uint(&node, "tunnel_sw_if_index", ntohl(mp->tunnel_sw_if_index));
1198 vat_json_print(vam->ofp, &node);
1199 vat_json_free(&node);
1201 vam->retval = ntohl(mp->retval);
1202 vam->result_ready = 1;
1205 static void vl_api_l2tpv3_create_tunnel_reply_t_handler
1206 (vl_api_l2tpv3_create_tunnel_reply_t * mp)
1208 vat_main_t * vam = &vat_main;
1209 i32 retval = ntohl(mp->retval);
1210 if (vam->async_mode) {
1211 vam->async_errors += (retval < 0);
1213 vam->retval = retval;
1214 vam->result_ready = 1;
1218 static void vl_api_l2tpv3_create_tunnel_reply_t_handler_json
1219 (vl_api_l2tpv3_create_tunnel_reply_t * mp)
1221 vat_main_t * vam = &vat_main;
1222 vat_json_node_t node;
1224 vat_json_init_object(&node);
1225 vat_json_object_add_int(&node, "retval", ntohl(mp->retval));
1226 vat_json_object_add_uint(&node, "sw_if_index", ntohl(mp->sw_if_index));
1228 vat_json_print(vam->ofp, &node);
1229 vat_json_free(&node);
1231 vam->retval = ntohl(mp->retval);
1232 vam->result_ready = 1;
1235 static void vl_api_vxlan_add_del_tunnel_reply_t_handler
1236 (vl_api_vxlan_add_del_tunnel_reply_t * mp)
1238 vat_main_t * vam = &vat_main;
1239 i32 retval = ntohl(mp->retval);
1240 if (vam->async_mode) {
1241 vam->async_errors += (retval < 0);
1243 vam->retval = retval;
1244 vam->result_ready = 1;
1248 static void vl_api_vxlan_add_del_tunnel_reply_t_handler_json
1249 (vl_api_vxlan_add_del_tunnel_reply_t * mp)
1251 vat_main_t * vam = &vat_main;
1252 vat_json_node_t node;
1254 vat_json_init_object(&node);
1255 vat_json_object_add_int(&node, "retval", ntohl(mp->retval));
1256 vat_json_object_add_uint(&node, "sw_if_index", ntohl(mp->sw_if_index));
1258 vat_json_print(vam->ofp, &node);
1259 vat_json_free(&node);
1261 vam->retval = ntohl(mp->retval);
1262 vam->result_ready = 1;
1265 static void vl_api_gre_add_del_tunnel_reply_t_handler
1266 (vl_api_gre_add_del_tunnel_reply_t * mp)
1268 vat_main_t * vam = &vat_main;
1269 i32 retval = ntohl(mp->retval);
1270 if (vam->async_mode) {
1271 vam->async_errors += (retval < 0);
1273 vam->retval = retval;
1274 vam->result_ready = 1;
1278 static void vl_api_gre_add_del_tunnel_reply_t_handler_json
1279 (vl_api_gre_add_del_tunnel_reply_t * mp)
1281 vat_main_t * vam = &vat_main;
1282 vat_json_node_t node;
1284 vat_json_init_object(&node);
1285 vat_json_object_add_int(&node, "retval", ntohl(mp->retval));
1286 vat_json_object_add_uint(&node, "sw_if_index", ntohl(mp->sw_if_index));
1288 vat_json_print(vam->ofp, &node);
1289 vat_json_free(&node);
1291 vam->retval = ntohl(mp->retval);
1292 vam->result_ready = 1;
1295 static void vl_api_create_vhost_user_if_reply_t_handler
1296 (vl_api_create_vhost_user_if_reply_t * mp)
1298 vat_main_t * vam = &vat_main;
1299 i32 retval = ntohl(mp->retval);
1300 if (vam->async_mode) {
1301 vam->async_errors += (retval < 0);
1303 vam->retval = retval;
1304 vam->result_ready = 1;
1308 static void vl_api_create_vhost_user_if_reply_t_handler_json
1309 (vl_api_create_vhost_user_if_reply_t * mp)
1311 vat_main_t * vam = &vat_main;
1312 vat_json_node_t node;
1314 vat_json_init_object(&node);
1315 vat_json_object_add_int(&node, "retval", ntohl(mp->retval));
1316 vat_json_object_add_uint(&node, "sw_if_index", ntohl(mp->sw_if_index));
1318 vat_json_print(vam->ofp, &node);
1319 vat_json_free(&node);
1321 vam->retval = ntohl(mp->retval);
1322 vam->result_ready = 1;
1325 static void vl_api_ip_address_details_t_handler
1326 (vl_api_ip_address_details_t * mp)
1328 vat_main_t * vam = &vat_main;
1329 static ip_address_details_t empty_ip_address_details = {{0}};
1330 ip_address_details_t * address = NULL;
1331 ip_details_t * current_ip_details = NULL;
1332 ip_details_t * details = NULL;
1334 details = vam->ip_details_by_sw_if_index[vam->is_ipv6];
1336 if (!details || vam->current_sw_if_index >= vec_len(details)
1337 || !details[vam->current_sw_if_index].present) {
1338 errmsg ("ip address details arrived but not stored\n");
1339 errmsg ("ip_dump should be called first\n");
1343 current_ip_details = vec_elt_at_index(details,
1344 vam->current_sw_if_index);
1346 #define addresses (current_ip_details->addr)
1348 vec_validate_init_empty(addresses, vec_len(addresses),
1349 empty_ip_address_details);
1351 address = vec_elt_at_index(addresses, vec_len(addresses) - 1);
1353 clib_memcpy(&address->ip, &mp->ip, sizeof(address->ip));
1354 address->prefix_length = mp->prefix_length;
1358 static void vl_api_ip_address_details_t_handler_json
1359 (vl_api_ip_address_details_t * mp)
1361 vat_main_t * vam = &vat_main;
1362 vat_json_node_t *node = NULL;
1363 struct in6_addr ip6;
1366 if (VAT_JSON_ARRAY != vam->json_tree.type) {
1367 ASSERT(VAT_JSON_NONE == vam->json_tree.type);
1368 vat_json_init_array(&vam->json_tree);
1370 node = vat_json_array_add(&vam->json_tree);
1372 vat_json_init_object(node);
1374 clib_memcpy(&ip6, mp->ip, sizeof(ip6));
1375 vat_json_object_add_ip6(node, "ip", ip6);
1377 clib_memcpy(&ip4, mp->ip, sizeof(ip4));
1378 vat_json_object_add_ip4(node, "ip", ip4);
1380 vat_json_object_add_uint(node, "prefix_length", mp->prefix_length);
1383 static void vl_api_ip_details_t_handler (vl_api_ip_details_t * mp)
1385 vat_main_t * vam = &vat_main;
1386 static ip_details_t empty_ip_details = {0};
1387 ip_details_t * ip = NULL;
1388 u32 sw_if_index = ~0;
1390 sw_if_index = ntohl(mp->sw_if_index);
1392 vec_validate_init_empty(vam->ip_details_by_sw_if_index[vam->is_ipv6],
1393 sw_if_index, empty_ip_details);
1395 ip = vec_elt_at_index(vam->ip_details_by_sw_if_index[vam->is_ipv6],
1401 static void vl_api_ip_details_t_handler_json (vl_api_ip_details_t * mp)
1403 vat_main_t * vam = &vat_main;
1405 if (VAT_JSON_ARRAY != vam->json_tree.type) {
1406 ASSERT(VAT_JSON_NONE == vam->json_tree.type);
1407 vat_json_init_array(&vam->json_tree);
1409 vat_json_array_add_uint(&vam->json_tree, clib_net_to_host_u32(mp->sw_if_index));
1412 static void vl_api_map_domain_details_t_handler_json
1413 (vl_api_map_domain_details_t * mp)
1415 vat_json_node_t * node = NULL;
1416 vat_main_t * vam = &vat_main;
1417 struct in6_addr ip6;
1420 if (VAT_JSON_ARRAY != vam->json_tree.type) {
1421 ASSERT(VAT_JSON_NONE == vam->json_tree.type);
1422 vat_json_init_array(&vam->json_tree);
1425 node = vat_json_array_add(&vam->json_tree);
1426 vat_json_init_object(node);
1428 vat_json_object_add_uint(node, "domain_index", clib_net_to_host_u32(mp->domain_index));
1429 clib_memcpy(&ip6, mp->ip6_prefix, sizeof(ip6));
1430 vat_json_object_add_ip6(node, "ip6_prefix", ip6);
1431 clib_memcpy(&ip4, mp->ip4_prefix, sizeof(ip4));
1432 vat_json_object_add_ip4(node, "ip4_prefix", ip4);
1433 clib_memcpy(&ip6, mp->ip6_src, sizeof(ip6));
1434 vat_json_object_add_ip6(node, "ip6_src", ip6);
1435 vat_json_object_add_int(node, "ip6_prefix_len", mp->ip6_prefix_len);
1436 vat_json_object_add_int(node, "ip4_prefix_len", mp->ip4_prefix_len);
1437 vat_json_object_add_int(node, "ip6_src_len", mp->ip6_src_len);
1438 vat_json_object_add_int(node, "ea_bits_len", mp->ea_bits_len);
1439 vat_json_object_add_int(node, "psid_offset", mp->psid_offset);
1440 vat_json_object_add_int(node, "psid_length", mp->psid_length);
1441 vat_json_object_add_uint(node, "flags", mp->flags);
1442 vat_json_object_add_uint(node, "mtu", clib_net_to_host_u16(mp->mtu));
1443 vat_json_object_add_int(node, "is_translation", mp->is_translation);
1446 static void vl_api_map_domain_details_t_handler
1447 (vl_api_map_domain_details_t * mp)
1449 vat_main_t * vam = &vat_main;
1451 if (mp->is_translation) {
1452 fformat(vam->ofp, "* %U/%d (ipv4-prefix) %U/%d (ipv6-prefix) %U/%d (ip6-src) index: %u\n",
1453 format_ip4_address, mp->ip4_prefix, mp->ip4_prefix_len,
1454 format_ip6_address, mp->ip6_prefix, mp->ip6_prefix_len,
1455 format_ip6_address, mp->ip6_src, mp->ip6_src_len, clib_net_to_host_u32(mp->domain_index));
1457 fformat(vam->ofp, "* %U/%d (ipv4-prefix) %U/%d (ipv6-prefix) %U (ip6-src) index: %u\n",
1458 format_ip4_address, mp->ip4_prefix, mp->ip4_prefix_len,
1459 format_ip6_address, mp->ip6_prefix, mp->ip6_prefix_len,
1460 format_ip6_address, mp->ip6_src, clib_net_to_host_u32(mp->domain_index));
1462 fformat(vam->ofp, " ea-len %d psid-offset %d psid-len %d mtu %d %s\n",
1463 mp->ea_bits_len, mp->psid_offset, mp->psid_length, mp->mtu, mp->is_translation? "map-t":"");
1466 static void vl_api_map_rule_details_t_handler_json
1467 (vl_api_map_rule_details_t * mp)
1469 struct in6_addr ip6;
1470 vat_json_node_t * node = NULL;
1471 vat_main_t * vam = &vat_main;
1473 if (VAT_JSON_ARRAY != vam->json_tree.type) {
1474 ASSERT(VAT_JSON_NONE == vam->json_tree.type);
1475 vat_json_init_array(&vam->json_tree);
1478 node = vat_json_array_add(&vam->json_tree);
1479 vat_json_init_object(node);
1481 vat_json_object_add_uint(node, "psid", clib_net_to_host_u16(mp->psid));
1482 clib_memcpy(&ip6, mp->ip6_dst, sizeof(ip6));
1483 vat_json_object_add_ip6(node, "ip6_dst", ip6);
1486 static void vl_api_map_rule_details_t_handler
1487 (vl_api_map_rule_details_t * mp)
1489 vat_main_t * vam = &vat_main;
1490 fformat(vam->ofp, " %d (psid) %U (ip6-dst)\n", clib_net_to_host_u16(mp->psid),
1491 format_ip6_address, mp->ip6_dst);
1494 static void vl_api_dhcp_compl_event_t_handler
1495 (vl_api_dhcp_compl_event_t * mp)
1497 vat_main_t * vam = &vat_main;
1498 errmsg ("DHCP compl event: pid %d %s hostname %s host_addr %U "
1499 "router_addr %U host_mac %U\n",
1500 mp->pid, mp->is_ipv6 ? "ipv6":"ipv4", mp->hostname,
1501 format_ip4_address, &mp->host_address,
1502 format_ip4_address, &mp->router_address,
1503 format_ethernet_address, mp->host_mac);
1506 static void vl_api_dhcp_compl_event_t_handler_json
1507 (vl_api_dhcp_compl_event_t * mp)
1509 /* JSON output not supported */
1512 static void set_simple_interface_counter (u8 vnet_counter_type, u32 sw_if_index,
1515 vat_main_t * vam = &vat_main;
1516 static u64 default_counter = 0;
1518 vec_validate_init_empty(vam->simple_interface_counters, vnet_counter_type, NULL);
1519 vec_validate_init_empty(vam->simple_interface_counters[vnet_counter_type],
1520 sw_if_index, default_counter);
1521 vam->simple_interface_counters[vnet_counter_type][sw_if_index] = counter;
1524 static void set_combined_interface_counter (u8 vnet_counter_type, u32 sw_if_index,
1525 interface_counter_t counter)
1527 vat_main_t * vam = &vat_main;
1528 static interface_counter_t default_counter = {0, };
1530 vec_validate_init_empty(vam->combined_interface_counters, vnet_counter_type, NULL);
1531 vec_validate_init_empty(vam->combined_interface_counters[vnet_counter_type],
1532 sw_if_index, default_counter);
1533 vam->combined_interface_counters[vnet_counter_type][sw_if_index] = counter;
1536 static void vl_api_vnet_interface_counters_t_handler
1537 (vl_api_vnet_interface_counters_t *mp)
1542 static void vl_api_vnet_interface_counters_t_handler_json
1543 (vl_api_vnet_interface_counters_t *mp)
1545 interface_counter_t counter;
1550 u32 first_sw_if_index;
1553 count = ntohl(mp->count);
1554 first_sw_if_index = ntohl(mp->first_sw_if_index);
1556 if (!mp->is_combined) {
1557 v_packets = (u64*)&mp->data;
1558 for (i = 0; i < count; i++) {
1559 packets = clib_net_to_host_u64(clib_mem_unaligned(v_packets, u64));
1560 set_simple_interface_counter(mp->vnet_counter_type,
1561 first_sw_if_index + i, packets);
1565 v = (vlib_counter_t*)&mp->data;
1566 for (i = 0; i < count; i++) {
1567 counter.packets = clib_net_to_host_u64(
1568 clib_mem_unaligned(&v->packets, u64));
1569 counter.bytes = clib_net_to_host_u64(
1570 clib_mem_unaligned(&v->bytes, u64));
1571 set_combined_interface_counter(mp->vnet_counter_type,
1572 first_sw_if_index + i, counter);
1578 static u32 ip4_fib_counters_get_vrf_index_by_vrf_id (u32 vrf_id)
1580 vat_main_t * vam = &vat_main;
1583 for (i = 0; i < vec_len(vam->ip4_fib_counters_vrf_id_by_index); i++) {
1584 if (vam->ip4_fib_counters_vrf_id_by_index[i] == vrf_id) {
1591 static u32 ip6_fib_counters_get_vrf_index_by_vrf_id (u32 vrf_id)
1593 vat_main_t * vam = &vat_main;
1596 for (i = 0; i < vec_len(vam->ip6_fib_counters_vrf_id_by_index); i++) {
1597 if (vam->ip6_fib_counters_vrf_id_by_index[i] == vrf_id) {
1604 static void vl_api_vnet_ip4_fib_counters_t_handler
1605 (vl_api_vnet_ip4_fib_counters_t *mp)
1610 static void vl_api_vnet_ip4_fib_counters_t_handler_json
1611 (vl_api_vnet_ip4_fib_counters_t *mp)
1613 vat_main_t * vam = &vat_main;
1614 vl_api_ip4_fib_counter_t *v;
1615 ip4_fib_counter_t *counter;
1622 vrf_id = ntohl(mp->vrf_id);
1623 vrf_index = ip4_fib_counters_get_vrf_index_by_vrf_id(vrf_id);
1624 if (~0 == vrf_index) {
1625 vrf_index = vec_len(vam->ip4_fib_counters_vrf_id_by_index);
1626 vec_validate(vam->ip4_fib_counters_vrf_id_by_index, vrf_index);
1627 vam->ip4_fib_counters_vrf_id_by_index[vrf_index] = vrf_id;
1628 vec_validate(vam->ip4_fib_counters, vrf_index);
1629 vam->ip4_fib_counters[vrf_index] = NULL;
1632 vec_free(vam->ip4_fib_counters[vrf_index]);
1633 v = (vl_api_ip4_fib_counter_t*)&mp->c;
1634 count = ntohl(mp->count);
1635 for (i = 0; i < count; i++) {
1636 vec_validate(vam->ip4_fib_counters[vrf_index], i);
1637 counter = &vam->ip4_fib_counters[vrf_index][i];
1638 clib_memcpy(&ip4, &v->address, sizeof(ip4));
1639 counter->address = ip4;
1640 counter->address_length = v->address_length;
1641 counter->packets = clib_net_to_host_u64(v->packets);
1642 counter->bytes = clib_net_to_host_u64(v->bytes);
1647 static void vl_api_vnet_ip6_fib_counters_t_handler
1648 (vl_api_vnet_ip6_fib_counters_t *mp)
1653 static void vl_api_vnet_ip6_fib_counters_t_handler_json
1654 (vl_api_vnet_ip6_fib_counters_t *mp)
1656 vat_main_t * vam = &vat_main;
1657 vl_api_ip6_fib_counter_t *v;
1658 ip6_fib_counter_t *counter;
1659 struct in6_addr ip6;
1665 vrf_id = ntohl(mp->vrf_id);
1666 vrf_index = ip6_fib_counters_get_vrf_index_by_vrf_id(vrf_id);
1667 if (~0 == vrf_index) {
1668 vrf_index = vec_len(vam->ip6_fib_counters_vrf_id_by_index);
1669 vec_validate(vam->ip6_fib_counters_vrf_id_by_index, vrf_index);
1670 vam->ip6_fib_counters_vrf_id_by_index[vrf_index] = vrf_id;
1671 vec_validate(vam->ip6_fib_counters, vrf_index);
1672 vam->ip6_fib_counters[vrf_index] = NULL;
1675 vec_free(vam->ip6_fib_counters[vrf_index]);
1676 v = (vl_api_ip6_fib_counter_t*)&mp->c;
1677 count = ntohl(mp->count);
1678 for (i = 0; i < count; i++) {
1679 vec_validate(vam->ip6_fib_counters[vrf_index], i);
1680 counter = &vam->ip6_fib_counters[vrf_index][i];
1681 clib_memcpy(&ip6, &v->address, sizeof(ip6));
1682 counter->address = ip6;
1683 counter->address_length = v->address_length;
1684 counter->packets = clib_net_to_host_u64(v->packets);
1685 counter->bytes = clib_net_to_host_u64(v->bytes);
1690 static void vl_api_get_first_msg_id_reply_t_handler
1691 (vl_api_get_first_msg_id_reply_t * mp)
1693 vat_main_t * vam = &vat_main;
1694 i32 retval = ntohl(mp->retval);
1696 if (vam->async_mode) {
1697 vam->async_errors += (retval < 0);
1699 vam->retval = retval;
1700 vam->result_ready = 1;
1703 errmsg ("first message id %d\n", ntohs(mp->first_msg_id));
1707 static void vl_api_get_first_msg_id_reply_t_handler_json
1708 (vl_api_get_first_msg_id_reply_t * mp)
1710 vat_main_t * vam = &vat_main;
1711 vat_json_node_t node;
1713 vat_json_init_object(&node);
1714 vat_json_object_add_int(&node, "retval", ntohl(mp->retval));
1715 vat_json_object_add_uint(&node, "first_msg_id",
1716 (uint) ntohs(mp->first_msg_id));
1718 vat_json_print(vam->ofp, &node);
1719 vat_json_free(&node);
1721 vam->retval = ntohl(mp->retval);
1722 vam->result_ready = 1;
1725 static void vl_api_get_node_graph_reply_t_handler
1726 (vl_api_get_node_graph_reply_t * mp)
1728 vat_main_t * vam = &vat_main;
1729 api_main_t * am = &api_main;
1730 i32 retval = ntohl(mp->retval);
1731 u8 * pvt_copy, * reply;
1736 if (vam->async_mode) {
1737 vam->async_errors += (retval < 0);
1739 vam->retval = retval;
1740 vam->result_ready = 1;
1743 /* "Should never happen..." */
1747 reply = (u8 *)(mp->reply_in_shmem);
1748 pvt_copy = vec_dup (reply);
1750 /* Toss the shared-memory original... */
1751 pthread_mutex_lock (&am->vlib_rp->mutex);
1752 oldheap = svm_push_data_heap (am->vlib_rp);
1756 svm_pop_heap (oldheap);
1757 pthread_mutex_unlock (&am->vlib_rp->mutex);
1759 if (vam->graph_nodes) {
1760 hash_free (vam->graph_node_index_by_name);
1762 for (i = 0; i < vec_len (vam->graph_nodes); i++) {
1763 node = vam->graph_nodes[i];
1764 vec_free (node->name);
1765 vec_free (node->next_nodes);
1768 vec_free(vam->graph_nodes);
1771 vam->graph_node_index_by_name = hash_create_string (0, sizeof(uword));
1772 vam->graph_nodes = vlib_node_unserialize (pvt_copy);
1773 vec_free (pvt_copy);
1775 for (i = 0; i < vec_len (vam->graph_nodes); i++) {
1776 node = vam->graph_nodes[i];
1777 hash_set_mem (vam->graph_node_index_by_name, node->name, i);
1781 static void vl_api_get_node_graph_reply_t_handler_json
1782 (vl_api_get_node_graph_reply_t * mp)
1784 vat_main_t * vam = &vat_main;
1785 api_main_t * am = &api_main;
1787 vat_json_node_t node;
1790 /* $$$$ make this real? */
1791 vat_json_init_object(&node);
1792 vat_json_object_add_int(&node, "retval", ntohl(mp->retval));
1793 vat_json_object_add_uint(&node, "reply_in_shmem", mp->reply_in_shmem);
1795 reply = (u8 *)(mp->reply_in_shmem);
1797 /* Toss the shared-memory original... */
1798 pthread_mutex_lock (&am->vlib_rp->mutex);
1799 oldheap = svm_push_data_heap (am->vlib_rp);
1803 svm_pop_heap (oldheap);
1804 pthread_mutex_unlock (&am->vlib_rp->mutex);
1806 vat_json_print(vam->ofp, &node);
1807 vat_json_free(&node);
1809 vam->retval = ntohl(mp->retval);
1810 vam->result_ready = 1;
1814 vl_api_lisp_locator_set_details_t_handler (
1815 vl_api_lisp_locator_set_details_t *mp)
1817 vat_main_t *vam = &vat_main;
1818 u8 * tmp_str = NULL;
1821 fformat(vam->ofp, "%=20s%=16d%=16d%=16d\n",
1822 mp->locator_set_name,
1823 ntohl(mp->sw_if_index),
1827 tmp_str = format(0,"%U/%d",
1828 mp->is_ipv6 ? format_ip6_address : format_ip4_address,
1832 fformat(vam->ofp, "%=20s%=16s%=16d%=16d\n",
1833 mp->locator_set_name,
1842 vl_api_lisp_locator_set_details_t_handler_json (
1843 vl_api_lisp_locator_set_details_t *mp)
1845 vat_main_t *vam = &vat_main;
1846 vat_json_node_t *node = NULL;
1847 struct in6_addr ip6;
1850 if (VAT_JSON_ARRAY != vam->json_tree.type) {
1851 ASSERT(VAT_JSON_NONE == vam->json_tree.type);
1852 vat_json_init_array(&vam->json_tree);
1854 node = vat_json_array_add(&vam->json_tree);
1856 vat_json_init_object(node);
1857 vat_json_object_add_string_copy(node, "locator-set", mp->locator_set_name);
1859 vat_json_object_add_uint(node, "locator", ntohl(mp->sw_if_index));
1862 clib_memcpy(&ip6, mp->ip_address, sizeof(ip6));
1863 vat_json_object_add_ip6(node, "locator", ip6);
1865 clib_memcpy(&ip4, mp->ip_address, sizeof(ip4));
1866 vat_json_object_add_ip4(node, "locator", ip4);
1868 vat_json_object_add_uint(node, "prefix-length", mp->prefix_len);
1870 vat_json_object_add_uint(node, "priority", mp->priority);
1871 vat_json_object_add_uint(node, "weight", mp->weight);
1875 vl_api_lisp_local_eid_table_details_t_handler (
1876 vl_api_lisp_local_eid_table_details_t *mp)
1878 vat_main_t *vam = &vat_main;
1881 prefix = format(0, "%U/%d",
1882 mp->eid_is_ipv6 ? format_ip6_address : format_ip4_address,
1884 mp->eid_prefix_len);
1886 fformat(vam->ofp, "%=20s%=30s\n",
1887 mp->locator_set_name, prefix);
1893 vl_api_lisp_local_eid_table_details_t_handler_json (
1894 vl_api_lisp_local_eid_table_details_t *mp)
1896 vat_main_t *vam = &vat_main;
1897 vat_json_node_t *node = NULL;
1898 struct in6_addr ip6;
1901 if (VAT_JSON_ARRAY != vam->json_tree.type) {
1902 ASSERT(VAT_JSON_NONE == vam->json_tree.type);
1903 vat_json_init_array(&vam->json_tree);
1905 node = vat_json_array_add(&vam->json_tree);
1907 vat_json_init_object(node);
1908 vat_json_object_add_string_copy(node, "locator-set", mp->locator_set_name);
1909 if (mp->eid_is_ipv6) {
1910 clib_memcpy(&ip6, mp->eid_ip_address, sizeof(ip6));
1911 vat_json_object_add_ip6(node, "eid address", ip6);
1913 clib_memcpy(&ip4, mp->eid_ip_address, sizeof(ip4));
1914 vat_json_object_add_ip4(node, "eid address", ip4);
1916 vat_json_object_add_uint(node, "eid prefix len", mp->eid_prefix_len);
1920 format_decap_next (u8 * s, va_list * args)
1922 u32 next_index = va_arg (*args, u32);
1926 case LISP_GPE_INPUT_NEXT_DROP:
1927 return format (s, "drop");
1928 case LISP_GPE_INPUT_NEXT_IP4_INPUT:
1929 return format (s, "ip4");
1930 case LISP_GPE_INPUT_NEXT_IP6_INPUT:
1931 return format (s, "ip6");
1933 return format (s, "unknown %d", next_index);
1939 vl_api_lisp_gpe_tunnel_details_t_handler (vl_api_lisp_gpe_tunnel_details_t *mp)
1941 vat_main_t *vam = &vat_main;
1943 u8 *flag_str = NULL;
1945 iid_str = format(0, "%d (0x%x)", ntohl(mp->iid), ntohl(mp->iid));
1947 #define _(n,v) if (mp->flags & v) flag_str = format (flag_str, "%s-bit ", #n);
1948 foreach_lisp_gpe_flag_bit;
1951 fformat(vam->ofp, "%=20d%=30U%=16U%=16d%=16d%=16U"
1952 "%=16d%=16d%=16sd=16d%=16s%=16s\n",
1954 mp->is_ipv6 ? format_ip6_address : format_ip4_address,
1956 mp->is_ipv6 ? format_ip6_address : format_ip4_address,
1958 ntohl(mp->encap_fib_id),
1959 ntohl(mp->decap_fib_id),
1960 format_decap_next, ntohl(mp->dcap_next),
1972 vl_api_lisp_gpe_tunnel_details_t_handler_json (
1973 vl_api_lisp_gpe_tunnel_details_t *mp)
1975 vat_main_t *vam = &vat_main;
1976 vat_json_node_t *node = NULL;
1977 struct in6_addr ip6;
1981 next_decap_str = format(0, "%U", format_decap_next, htonl(mp->dcap_next));
1983 if (VAT_JSON_ARRAY != vam->json_tree.type) {
1984 ASSERT(VAT_JSON_NONE == vam->json_tree.type);
1985 vat_json_init_array(&vam->json_tree);
1987 node = vat_json_array_add(&vam->json_tree);
1989 vat_json_init_object(node);
1990 vat_json_object_add_uint(node, "tunel", mp->tunnels);
1992 clib_memcpy(&ip6, mp->source_ip, sizeof(ip6));
1993 vat_json_object_add_ip6(node, "source address", ip6);
1994 clib_memcpy(&ip6, mp->destination_ip, sizeof(ip6));
1995 vat_json_object_add_ip6(node, "destination address", ip6);
1997 clib_memcpy(&ip4, mp->source_ip, sizeof(ip4));
1998 vat_json_object_add_ip4(node, "source address", ip4);
1999 clib_memcpy(&ip4, mp->destination_ip, sizeof(ip4));
2000 vat_json_object_add_ip4(node, "destination address", ip4);
2002 vat_json_object_add_uint(node, "fib encap", ntohl(mp->encap_fib_id));
2003 vat_json_object_add_uint(node, "fib decap", ntohl(mp->decap_fib_id));
2004 vat_json_object_add_string_copy(node, "decap next", next_decap_str);
2005 vat_json_object_add_uint(node, "lisp version", mp->ver_res >> 6);
2006 vat_json_object_add_uint(node, "flags", mp->flags);
2007 vat_json_object_add_uint(node, "next protocol", mp->next_protocol);
2008 vat_json_object_add_uint(node, "ver_res", mp->ver_res);
2009 vat_json_object_add_uint(node, "res", mp->res);
2010 vat_json_object_add_uint(node, "iid", ntohl(mp->iid));
2012 vec_free(next_decap_str);
2016 vl_api_lisp_map_resolver_details_t_handler (
2017 vl_api_lisp_map_resolver_details_t *mp)
2019 vat_main_t *vam = &vat_main;
2021 fformat(vam->ofp, "%=20U\n",
2022 mp->is_ipv6 ? format_ip6_address : format_ip4_address,
2027 vl_api_lisp_map_resolver_details_t_handler_json (
2028 vl_api_lisp_map_resolver_details_t *mp)
2030 vat_main_t *vam = &vat_main;
2031 vat_json_node_t *node = NULL;
2032 struct in6_addr ip6;
2035 if (VAT_JSON_ARRAY != vam->json_tree.type) {
2036 ASSERT(VAT_JSON_NONE == vam->json_tree.type);
2037 vat_json_init_array(&vam->json_tree);
2039 node = vat_json_array_add(&vam->json_tree);
2041 vat_json_init_object(node);
2043 clib_memcpy(&ip6, mp->ip_address, sizeof(ip6));
2044 vat_json_object_add_ip6(node, "map resolver", ip6);
2046 clib_memcpy(&ip4, mp->ip_address, sizeof(ip4));
2047 vat_json_object_add_ip4(node, "map resolver", ip4);
2052 vl_api_lisp_enable_disable_status_details_t_handler
2053 (vl_api_lisp_enable_disable_status_details_t *mp)
2055 vat_main_t *vam = &vat_main;
2057 fformat(vam->ofp, "feature: %s\ngpe: %s\n",
2058 mp->feature_status ? "enabled" : "disabled",
2059 mp->gpe_status ? "enabled" : "disabled");
2063 vl_api_lisp_enable_disable_status_details_t_handler_json
2064 (vl_api_lisp_enable_disable_status_details_t *mp)
2066 vat_main_t *vam = &vat_main;
2067 vat_json_node_t *node = NULL;
2068 u8 * gpe_status = NULL;
2069 u8 * feature_status = NULL;
2071 gpe_status = format (0, "%s", mp->gpe_status ? "enabled" : "disabled");
2072 feature_status = format (0, "%s",
2073 mp->feature_status ? "enabled" : "disabled");
2075 if (VAT_JSON_ARRAY != vam->json_tree.type) {
2076 ASSERT(VAT_JSON_NONE == vam->json_tree.type);
2077 vat_json_init_array(&vam->json_tree);
2079 node = vat_json_array_add(&vam->json_tree);
2081 vat_json_init_object(node);
2082 vat_json_object_add_string_copy(node, "gpe_status", gpe_status);
2083 vat_json_object_add_string_copy(node, "feature_status", feature_status);
2085 vec_free (gpe_status);
2086 vec_free (feature_status);
2089 #define vl_api_vnet_ip4_fib_counters_t_endian vl_noop_handler
2090 #define vl_api_vnet_ip4_fib_counters_t_print vl_noop_handler
2091 #define vl_api_vnet_ip6_fib_counters_t_endian vl_noop_handler
2092 #define vl_api_vnet_ip6_fib_counters_t_print vl_noop_handler
2095 * Generate boilerplate reply handlers, which
2096 * dig the return value out of the xxx_reply_t API message,
2097 * stick it into vam->retval, and set vam->result_ready
2099 * Could also do this by pointing N message decode slots at
2100 * a single function, but that could break in subtle ways.
2103 #define foreach_standard_reply_retval_handler \
2104 _(sw_interface_set_flags_reply) \
2105 _(sw_interface_add_del_address_reply) \
2106 _(sw_interface_set_table_reply) \
2107 _(sw_interface_set_vpath_reply) \
2108 _(sw_interface_set_l2_bridge_reply) \
2109 _(bridge_domain_add_del_reply) \
2110 _(sw_interface_set_l2_xconnect_reply) \
2111 _(l2fib_add_del_reply) \
2112 _(ip_add_del_route_reply) \
2113 _(proxy_arp_add_del_reply) \
2114 _(proxy_arp_intfc_enable_disable_reply) \
2115 _(mpls_add_del_encap_reply) \
2116 _(mpls_add_del_decap_reply) \
2117 _(mpls_ethernet_add_del_tunnel_2_reply) \
2118 _(sw_interface_set_unnumbered_reply) \
2119 _(ip_neighbor_add_del_reply) \
2120 _(reset_vrf_reply) \
2121 _(oam_add_del_reply) \
2122 _(reset_fib_reply) \
2123 _(dhcp_proxy_config_reply) \
2124 _(dhcp_proxy_config_2_reply) \
2125 _(dhcp_proxy_set_vss_reply) \
2126 _(dhcp_client_config_reply) \
2127 _(set_ip_flow_hash_reply) \
2128 _(sw_interface_ip6_enable_disable_reply) \
2129 _(sw_interface_ip6_set_link_local_address_reply) \
2130 _(sw_interface_ip6nd_ra_prefix_reply) \
2131 _(sw_interface_ip6nd_ra_config_reply) \
2132 _(set_arp_neighbor_limit_reply) \
2133 _(l2_patch_add_del_reply) \
2134 _(sr_tunnel_add_del_reply) \
2135 _(sr_policy_add_del_reply) \
2136 _(sr_multicast_map_add_del_reply) \
2137 _(classify_add_del_session_reply) \
2138 _(classify_set_interface_ip_table_reply) \
2139 _(classify_set_interface_l2_tables_reply) \
2140 _(l2tpv3_set_tunnel_cookies_reply) \
2141 _(l2tpv3_interface_enable_disable_reply) \
2142 _(l2tpv3_set_lookup_key_reply) \
2143 _(l2_fib_clear_table_reply) \
2144 _(l2_interface_efp_filter_reply) \
2145 _(l2_interface_vlan_tag_rewrite_reply) \
2146 _(modify_vhost_user_if_reply) \
2147 _(delete_vhost_user_if_reply) \
2148 _(want_ip4_arp_events_reply) \
2149 _(input_acl_set_interface_reply) \
2150 _(ipsec_spd_add_del_reply) \
2151 _(ipsec_interface_add_del_spd_reply) \
2152 _(ipsec_spd_add_del_entry_reply) \
2153 _(ipsec_sad_add_del_entry_reply) \
2154 _(ipsec_sa_set_key_reply) \
2155 _(ikev2_profile_add_del_reply) \
2156 _(ikev2_profile_set_auth_reply) \
2157 _(ikev2_profile_set_id_reply) \
2158 _(ikev2_profile_set_ts_reply) \
2159 _(ikev2_set_local_key_reply) \
2160 _(delete_loopback_reply) \
2161 _(bd_ip_mac_add_del_reply) \
2162 _(map_del_domain_reply) \
2163 _(map_add_del_rule_reply) \
2164 _(want_interface_events_reply) \
2165 _(want_stats_reply) \
2166 _(cop_interface_enable_disable_reply) \
2167 _(cop_whitelist_enable_disable_reply) \
2168 _(sw_interface_clear_stats_reply) \
2169 _(trace_profile_add_reply) \
2170 _(trace_profile_apply_reply) \
2171 _(trace_profile_del_reply) \
2172 _(lisp_add_del_locator_set_reply) \
2173 _(lisp_add_del_locator_reply) \
2174 _(lisp_add_del_local_eid_reply) \
2175 _(lisp_gpe_add_del_fwd_entry_reply) \
2176 _(lisp_add_del_map_resolver_reply) \
2177 _(lisp_gpe_enable_disable_reply) \
2178 _(lisp_gpe_add_del_iface_reply) \
2179 _(lisp_enable_disable_reply) \
2180 _(vxlan_gpe_add_del_tunnel_reply) \
2181 _(af_packet_create_reply) \
2182 _(af_packet_delete_reply)
2185 static void vl_api_##n##_t_handler \
2186 (vl_api_##n##_t * mp) \
2188 vat_main_t * vam = &vat_main; \
2189 i32 retval = ntohl(mp->retval); \
2190 if (vam->async_mode) { \
2191 vam->async_errors += (retval < 0); \
2193 vam->retval = retval; \
2194 vam->result_ready = 1; \
2197 foreach_standard_reply_retval_handler;
2201 static void vl_api_##n##_t_handler_json \
2202 (vl_api_##n##_t * mp) \
2204 vat_main_t * vam = &vat_main; \
2205 vat_json_node_t node; \
2206 vat_json_init_object(&node); \
2207 vat_json_object_add_int(&node, "retval", ntohl(mp->retval)); \
2208 vat_json_print(vam->ofp, &node); \
2209 vam->retval = ntohl(mp->retval); \
2210 vam->result_ready = 1; \
2212 foreach_standard_reply_retval_handler;
2216 * Table of message reply handlers, must include boilerplate handlers
2220 #define foreach_vpe_api_reply_msg \
2221 _(CREATE_LOOPBACK_REPLY, create_loopback_reply) \
2222 _(SW_INTERFACE_DETAILS, sw_interface_details) \
2223 _(SW_INTERFACE_SET_FLAGS, sw_interface_set_flags) \
2224 _(SW_INTERFACE_SET_FLAGS_REPLY, sw_interface_set_flags_reply) \
2225 _(CONTROL_PING_REPLY, control_ping_reply) \
2226 _(CLI_REPLY, cli_reply) \
2227 _(SW_INTERFACE_ADD_DEL_ADDRESS_REPLY, \
2228 sw_interface_add_del_address_reply) \
2229 _(SW_INTERFACE_SET_TABLE_REPLY, sw_interface_set_table_reply) \
2230 _(SW_INTERFACE_SET_VPATH_REPLY, sw_interface_set_vpath_reply) \
2231 _(SW_INTERFACE_SET_L2_XCONNECT_REPLY, \
2232 sw_interface_set_l2_xconnect_reply) \
2233 _(SW_INTERFACE_SET_L2_BRIDGE_REPLY, \
2234 sw_interface_set_l2_bridge_reply) \
2235 _(BRIDGE_DOMAIN_ADD_DEL_REPLY, bridge_domain_add_del_reply) \
2236 _(BRIDGE_DOMAIN_DETAILS, bridge_domain_details) \
2237 _(BRIDGE_DOMAIN_SW_IF_DETAILS, bridge_domain_sw_if_details) \
2238 _(L2FIB_ADD_DEL_REPLY, l2fib_add_del_reply) \
2239 _(L2_FLAGS_REPLY, l2_flags_reply) \
2240 _(BRIDGE_FLAGS_REPLY, bridge_flags_reply) \
2241 _(TAP_CONNECT_REPLY, tap_connect_reply) \
2242 _(TAP_MODIFY_REPLY, tap_modify_reply) \
2243 _(TAP_DELETE_REPLY, tap_delete_reply) \
2244 _(SW_INTERFACE_TAP_DETAILS, sw_interface_tap_details) \
2245 _(IP_ADD_DEL_ROUTE_REPLY, ip_add_del_route_reply) \
2246 _(PROXY_ARP_ADD_DEL_REPLY, proxy_arp_add_del_reply) \
2247 _(PROXY_ARP_INTFC_ENABLE_DISABLE_REPLY, \
2248 proxy_arp_intfc_enable_disable_reply) \
2249 _(MPLS_ADD_DEL_ENCAP_REPLY, mpls_add_del_encap_reply) \
2250 _(MPLS_ADD_DEL_DECAP_REPLY, mpls_add_del_decap_reply) \
2251 _(MPLS_GRE_ADD_DEL_TUNNEL_REPLY, mpls_gre_add_del_tunnel_reply) \
2252 _(MPLS_ETHERNET_ADD_DEL_TUNNEL_REPLY, \
2253 mpls_ethernet_add_del_tunnel_reply) \
2254 _(MPLS_ETHERNET_ADD_DEL_TUNNEL_2_REPLY, \
2255 mpls_ethernet_add_del_tunnel_2_reply) \
2256 _(SW_INTERFACE_SET_UNNUMBERED_REPLY, \
2257 sw_interface_set_unnumbered_reply) \
2258 _(IP_NEIGHBOR_ADD_DEL_REPLY, ip_neighbor_add_del_reply) \
2259 _(RESET_VRF_REPLY, reset_vrf_reply) \
2260 _(CREATE_VLAN_SUBIF_REPLY, create_vlan_subif_reply) \
2261 _(CREATE_SUBIF_REPLY, create_subif_reply) \
2262 _(OAM_ADD_DEL_REPLY, oam_add_del_reply) \
2263 _(RESET_FIB_REPLY, reset_fib_reply) \
2264 _(DHCP_PROXY_CONFIG_REPLY, dhcp_proxy_config_reply) \
2265 _(DHCP_PROXY_CONFIG_2_REPLY, dhcp_proxy_config_2_reply) \
2266 _(DHCP_PROXY_SET_VSS_REPLY, dhcp_proxy_set_vss_reply) \
2267 _(DHCP_CLIENT_CONFIG_REPLY, dhcp_client_config_reply) \
2268 _(SET_IP_FLOW_HASH_REPLY, set_ip_flow_hash_reply) \
2269 _(SW_INTERFACE_IP6_ENABLE_DISABLE_REPLY, \
2270 sw_interface_ip6_enable_disable_reply) \
2271 _(SW_INTERFACE_IP6_SET_LINK_LOCAL_ADDRESS_REPLY, \
2272 sw_interface_ip6_set_link_local_address_reply) \
2273 _(SW_INTERFACE_IP6ND_RA_PREFIX_REPLY, \
2274 sw_interface_ip6nd_ra_prefix_reply) \
2275 _(SW_INTERFACE_IP6ND_RA_CONFIG_REPLY, \
2276 sw_interface_ip6nd_ra_config_reply) \
2277 _(SET_ARP_NEIGHBOR_LIMIT_REPLY, set_arp_neighbor_limit_reply) \
2278 _(L2_PATCH_ADD_DEL_REPLY, l2_patch_add_del_reply) \
2279 _(SR_TUNNEL_ADD_DEL_REPLY, sr_tunnel_add_del_reply) \
2280 _(SR_POLICY_ADD_DEL_REPLY, sr_policy_add_del_reply) \
2281 _(SR_MULTICAST_MAP_ADD_DEL_REPLY, sr_multicast_map_add_del_reply) \
2282 _(CLASSIFY_ADD_DEL_TABLE_REPLY, classify_add_del_table_reply) \
2283 _(CLASSIFY_ADD_DEL_SESSION_REPLY, classify_add_del_session_reply) \
2284 _(CLASSIFY_SET_INTERFACE_IP_TABLE_REPLY, \
2285 classify_set_interface_ip_table_reply) \
2286 _(CLASSIFY_SET_INTERFACE_L2_TABLES_REPLY, \
2287 classify_set_interface_l2_tables_reply) \
2288 _(GET_NODE_INDEX_REPLY, get_node_index_reply) \
2289 _(ADD_NODE_NEXT_REPLY, add_node_next_reply) \
2290 _(L2TPV3_CREATE_TUNNEL_REPLY, l2tpv3_create_tunnel_reply) \
2291 _(L2TPV3_SET_TUNNEL_COOKIES_REPLY, l2tpv3_set_tunnel_cookies_reply) \
2292 _(L2TPV3_INTERFACE_ENABLE_DISABLE_REPLY, \
2293 l2tpv3_interface_enable_disable_reply) \
2294 _(L2TPV3_SET_LOOKUP_KEY_REPLY, l2tpv3_set_lookup_key_reply) \
2295 _(SW_IF_L2TPV3_TUNNEL_DETAILS, sw_if_l2tpv3_tunnel_details) \
2296 _(VXLAN_ADD_DEL_TUNNEL_REPLY, vxlan_add_del_tunnel_reply) \
2297 _(VXLAN_TUNNEL_DETAILS, vxlan_tunnel_details) \
2298 _(GRE_ADD_DEL_TUNNEL_REPLY, gre_add_del_tunnel_reply) \
2299 _(GRE_TUNNEL_DETAILS, gre_tunnel_details) \
2300 _(L2_FIB_CLEAR_TABLE_REPLY, l2_fib_clear_table_reply) \
2301 _(L2_INTERFACE_EFP_FILTER_REPLY, l2_interface_efp_filter_reply) \
2302 _(L2_INTERFACE_VLAN_TAG_REWRITE_REPLY, l2_interface_vlan_tag_rewrite_reply) \
2303 _(SW_INTERFACE_VHOST_USER_DETAILS, sw_interface_vhost_user_details) \
2304 _(CREATE_VHOST_USER_IF_REPLY, create_vhost_user_if_reply) \
2305 _(MODIFY_VHOST_USER_IF_REPLY, modify_vhost_user_if_reply) \
2306 _(DELETE_VHOST_USER_IF_REPLY, delete_vhost_user_if_reply) \
2307 _(SHOW_VERSION_REPLY, show_version_reply) \
2308 _(L2_FIB_TABLE_ENTRY, l2_fib_table_entry) \
2309 _(VXLAN_GPE_ADD_DEL_TUNNEL_REPLY, vxlan_gpe_add_del_tunnel_reply) \
2310 _(INTERFACE_NAME_RENUMBER_REPLY, interface_name_renumber_reply) \
2311 _(WANT_IP4_ARP_EVENTS_REPLY, want_ip4_arp_events_reply) \
2312 _(IP4_ARP_EVENT, ip4_arp_event) \
2313 _(INPUT_ACL_SET_INTERFACE_REPLY, input_acl_set_interface_reply) \
2314 _(IP_ADDRESS_DETAILS, ip_address_details) \
2315 _(IP_DETAILS, ip_details) \
2316 _(IPSEC_SPD_ADD_DEL_REPLY, ipsec_spd_add_del_reply) \
2317 _(IPSEC_INTERFACE_ADD_DEL_SPD_REPLY, ipsec_interface_add_del_spd_reply) \
2318 _(IPSEC_SPD_ADD_DEL_ENTRY_REPLY, ipsec_spd_add_del_entry_reply) \
2319 _(IPSEC_SAD_ADD_DEL_ENTRY_REPLY, ipsec_sad_add_del_entry_reply) \
2320 _(IPSEC_SA_SET_KEY_REPLY, ipsec_sa_set_key_reply) \
2321 _(IKEV2_PROFILE_ADD_DEL_REPLY, ikev2_profile_add_del_reply) \
2322 _(IKEV2_PROFILE_SET_AUTH_REPLY, ikev2_profile_set_auth_reply) \
2323 _(IKEV2_PROFILE_SET_ID_REPLY, ikev2_profile_set_id_reply) \
2324 _(IKEV2_PROFILE_SET_TS_REPLY, ikev2_profile_set_ts_reply) \
2325 _(IKEV2_SET_LOCAL_KEY_REPLY, ikev2_set_local_key_reply) \
2326 _(DELETE_LOOPBACK_REPLY, delete_loopback_reply) \
2327 _(BD_IP_MAC_ADD_DEL_REPLY, bd_ip_mac_add_del_reply) \
2328 _(DHCP_COMPL_EVENT, dhcp_compl_event) \
2329 _(VNET_INTERFACE_COUNTERS, vnet_interface_counters) \
2330 _(VNET_IP4_FIB_COUNTERS, vnet_ip4_fib_counters) \
2331 _(VNET_IP6_FIB_COUNTERS, vnet_ip6_fib_counters) \
2332 _(MAP_ADD_DOMAIN_REPLY, map_add_domain_reply) \
2333 _(MAP_DEL_DOMAIN_REPLY, map_del_domain_reply) \
2334 _(MAP_ADD_DEL_RULE_REPLY, map_add_del_rule_reply) \
2335 _(MAP_DOMAIN_DETAILS, map_domain_details) \
2336 _(MAP_RULE_DETAILS, map_rule_details) \
2337 _(WANT_INTERFACE_EVENTS_REPLY, want_interface_events_reply) \
2338 _(WANT_STATS_REPLY, want_stats_reply) \
2339 _(GET_FIRST_MSG_ID_REPLY, get_first_msg_id_reply) \
2340 _(COP_INTERFACE_ENABLE_DISABLE_REPLY, cop_interface_enable_disable_reply) \
2341 _(COP_WHITELIST_ENABLE_DISABLE_REPLY, cop_whitelist_enable_disable_reply) \
2342 _(GET_NODE_GRAPH_REPLY, get_node_graph_reply) \
2343 _(SW_INTERFACE_CLEAR_STATS_REPLY, sw_interface_clear_stats_reply) \
2344 _(TRACE_PROFILE_ADD_REPLY, trace_profile_add_reply) \
2345 _(TRACE_PROFILE_APPLY_REPLY, trace_profile_apply_reply) \
2346 _(TRACE_PROFILE_DEL_REPLY, trace_profile_del_reply) \
2347 _(LISP_ADD_DEL_LOCATOR_SET_REPLY, lisp_add_del_locator_set_reply) \
2348 _(LISP_ADD_DEL_LOCATOR_REPLY, lisp_add_del_locator_reply) \
2349 _(LISP_ADD_DEL_LOCAL_EID_REPLY, lisp_add_del_local_eid_reply) \
2350 _(LISP_GPE_ADD_DEL_FWD_ENTRY_REPLY, lisp_gpe_add_del_fwd_entry_reply) \
2351 _(LISP_ADD_DEL_MAP_RESOLVER_REPLY, lisp_add_del_map_resolver_reply) \
2352 _(LISP_GPE_ENABLE_DISABLE_REPLY, lisp_gpe_enable_disable_reply) \
2353 _(LISP_ENABLE_DISABLE_REPLY, lisp_enable_disable_reply) \
2354 _(LISP_GPE_ADD_DEL_IFACE_REPLY, lisp_gpe_add_del_iface_reply) \
2355 _(LISP_LOCATOR_SET_DETAILS, lisp_locator_set_details) \
2356 _(LISP_LOCAL_EID_TABLE_DETAILS, lisp_local_eid_table_details) \
2357 _(LISP_GPE_TUNNEL_DETAILS, lisp_gpe_tunnel_details) \
2358 _(LISP_MAP_RESOLVER_DETAILS, lisp_map_resolver_details) \
2359 _(LISP_ENABLE_DISABLE_STATUS_DETAILS, \
2360 lisp_enable_disable_status_details) \
2361 _(AF_PACKET_CREATE_REPLY, af_packet_create_reply) \
2362 _(AF_PACKET_DELETE_REPLY, af_packet_delete_reply)
2364 /* M: construct, but don't yet send a message */
2368 vam->result_ready = 0; \
2369 mp = vl_msg_api_alloc(sizeof(*mp)); \
2370 memset (mp, 0, sizeof (*mp)); \
2371 mp->_vl_msg_id = ntohs (VL_API_##T); \
2372 mp->client_index = vam->my_client_index; \
2377 vam->result_ready = 0; \
2378 mp = vl_msg_api_alloc(sizeof(*mp)+(n)); \
2379 memset (mp, 0, sizeof (*mp)); \
2380 mp->_vl_msg_id = ntohs (VL_API_##T); \
2381 mp->client_index = vam->my_client_index; \
2385 /* S: send a message */
2386 #define S (vl_msg_api_send_shmem (vam->vl_input_queue, (u8 *)&mp))
2388 /* W: wait for results, with timeout */
2391 timeout = vat_time_now (vam) + 1.0; \
2393 while (vat_time_now (vam) < timeout) { \
2394 if (vam->result_ready == 1) { \
2395 return (vam->retval); \
2407 #define STR_VTR_OP_CASE(op) \
2408 case L2_VTR_ ## op: \
2411 static const char *str_vtr_op(u32 vtr_op)
2414 STR_VTR_OP_CASE(DISABLED);
2415 STR_VTR_OP_CASE(PUSH_1);
2416 STR_VTR_OP_CASE(PUSH_2);
2417 STR_VTR_OP_CASE(POP_1);
2418 STR_VTR_OP_CASE(POP_2);
2419 STR_VTR_OP_CASE(TRANSLATE_1_1);
2420 STR_VTR_OP_CASE(TRANSLATE_1_2);
2421 STR_VTR_OP_CASE(TRANSLATE_2_1);
2422 STR_VTR_OP_CASE(TRANSLATE_2_2);
2428 static int dump_sub_interface_table (vat_main_t * vam)
2430 const sw_interface_subif_t * sub = NULL;
2432 if (vam->json_output) {
2433 clib_warning ("JSON output supported only for VPE API calls and dump_stats_table");
2438 "%-30s%-12s%-11s%-7s%-5s%-9s%-9s%-6s%-8s%-10s%-10s\n",
2439 "Interface", "sw_if_index",
2440 "sub id", "dot1ad", "tags", "outer id",
2441 "inner id", "exact", "default",
2442 "outer any", "inner any");
2444 vec_foreach (sub, vam->sw_if_subif_table) {
2446 "%-30s%-12d%-11d%-7s%-5d%-9d%-9d%-6d%-8d%-10d%-10d\n",
2447 sub->interface_name,
2449 sub->sub_id, sub->sub_dot1ad ? "dot1ad" : "dot1q",
2450 sub->sub_number_of_tags, sub->sub_outer_vlan_id,
2451 sub->sub_inner_vlan_id, sub->sub_exact_match, sub->sub_default,
2452 sub->sub_outer_vlan_id_any, sub->sub_inner_vlan_id_any);
2453 if (sub->vtr_op != L2_VTR_DISABLED) {
2455 " vlan-tag-rewrite - op: %-14s [ dot1q: %d "
2456 "tag1: %d tag2: %d ]\n",
2457 str_vtr_op(sub->vtr_op), sub->vtr_push_dot1q,
2458 sub->vtr_tag1, sub->vtr_tag2);
2465 static int name_sort_cmp (void * a1, void * a2)
2467 name_sort_t * n1 = a1;
2468 name_sort_t * n2 = a2;
2470 return strcmp ((char *)n1->name, (char *)n2->name);
2473 static int dump_interface_table (vat_main_t * vam)
2476 name_sort_t * nses = 0, * ns;
2478 if (vam->json_output) {
2479 clib_warning ("JSON output supported only for VPE API calls and dump_stats_table");
2483 hash_foreach_pair (p, vam->sw_if_index_by_interface_name,
2485 vec_add2 (nses, ns, 1);
2486 ns->name = (u8 *)(p->key);
2487 ns->value = (u32) p->value[0];
2490 vec_sort_with_function (nses, name_sort_cmp);
2492 fformat (vam->ofp, "%-25s%-15s\n", "Interface", "sw_if_index");
2493 vec_foreach (ns, nses) {
2494 fformat (vam->ofp, "%-25s%-15d\n", ns->name, ns->value);
2500 static int dump_ip_table (vat_main_t * vam, int is_ipv6)
2502 const ip_details_t * det = NULL;
2503 const ip_address_details_t * address = NULL;
2514 vec_foreach (det, vam->ip_details_by_sw_if_index[is_ipv6]) {
2516 if (!det->present) {
2524 "Address", "Prefix length");
2528 vec_foreach (address, det->addr) {
2531 is_ipv6 ? format_ip6_address : format_ip4_address,
2533 address->prefix_length);
2540 static int dump_ipv4_table (vat_main_t * vam)
2542 if (vam->json_output) {
2543 clib_warning ("JSON output supported only for VPE API calls and dump_stats_table");
2547 return dump_ip_table (vam, 0);
2550 static int dump_ipv6_table (vat_main_t * vam)
2552 if (vam->json_output) {
2553 clib_warning ("JSON output supported only for VPE API calls and dump_stats_table");
2557 return dump_ip_table (vam, 1);
2560 static char* counter_type_to_str (u8 counter_type, u8 is_combined)
2563 switch(counter_type) {
2564 case VNET_INTERFACE_COUNTER_DROP:
2566 case VNET_INTERFACE_COUNTER_PUNT:
2568 case VNET_INTERFACE_COUNTER_IP4:
2570 case VNET_INTERFACE_COUNTER_IP6:
2572 case VNET_INTERFACE_COUNTER_RX_NO_BUF:
2574 case VNET_INTERFACE_COUNTER_RX_MISS:
2576 case VNET_INTERFACE_COUNTER_RX_ERROR:
2578 case VNET_INTERFACE_COUNTER_TX_ERROR:
2581 return "INVALID-COUNTER-TYPE";
2584 switch(counter_type) {
2585 case VNET_INTERFACE_COUNTER_RX:
2587 case VNET_INTERFACE_COUNTER_TX:
2590 return "INVALID-COUNTER-TYPE";
2595 static int dump_stats_table (vat_main_t * vam)
2597 vat_json_node_t node;
2598 vat_json_node_t *msg_array;
2599 vat_json_node_t *msg;
2600 vat_json_node_t *counter_array;
2601 vat_json_node_t *counter;
2602 interface_counter_t c;
2604 ip4_fib_counter_t *c4;
2605 ip6_fib_counter_t *c6;
2608 if (!vam->json_output) {
2609 clib_warning ("dump_stats_table supported only in JSON format");
2613 vat_json_init_object(&node);
2615 /* interface counters */
2616 msg_array = vat_json_object_add(&node, "interface_counters");
2617 vat_json_init_array(msg_array);
2618 for (i = 0; i < vec_len(vam->simple_interface_counters); i++) {
2619 msg = vat_json_array_add(msg_array);
2620 vat_json_init_object(msg);
2621 vat_json_object_add_string_copy(msg, "vnet_counter_type",
2622 (u8*)counter_type_to_str(i, 0));
2623 vat_json_object_add_int(msg, "is_combined", 0);
2624 counter_array = vat_json_object_add(msg, "data");
2625 vat_json_init_array(counter_array);
2626 for (j = 0; j < vec_len(vam->simple_interface_counters[i]); j++) {
2627 packets = vam->simple_interface_counters[i][j];
2628 vat_json_array_add_uint(counter_array, packets);
2631 for (i = 0; i < vec_len(vam->combined_interface_counters); i++) {
2632 msg = vat_json_array_add(msg_array);
2633 vat_json_init_object(msg);
2634 vat_json_object_add_string_copy(msg, "vnet_counter_type",
2635 (u8*)counter_type_to_str(i, 1));
2636 vat_json_object_add_int(msg, "is_combined", 1);
2637 counter_array = vat_json_object_add(msg, "data");
2638 vat_json_init_array(counter_array);
2639 for (j = 0; j < vec_len(vam->combined_interface_counters[i]); j++) {
2640 c = vam->combined_interface_counters[i][j];
2641 counter = vat_json_array_add(counter_array);
2642 vat_json_init_object(counter);
2643 vat_json_object_add_uint(counter, "packets", c.packets);
2644 vat_json_object_add_uint(counter, "bytes", c.bytes);
2648 /* ip4 fib counters */
2649 msg_array = vat_json_object_add(&node, "ip4_fib_counters");
2650 vat_json_init_array(msg_array);
2651 for (i = 0; i < vec_len(vam->ip4_fib_counters); i++) {
2652 msg = vat_json_array_add(msg_array);
2653 vat_json_init_object(msg);
2654 vat_json_object_add_uint(msg, "vrf_id", vam->ip4_fib_counters_vrf_id_by_index[i]);
2655 counter_array = vat_json_object_add(msg, "c");
2656 vat_json_init_array(counter_array);
2657 for (j = 0; j < vec_len(vam->ip4_fib_counters[i]); j++) {
2658 counter = vat_json_array_add(counter_array);
2659 vat_json_init_object(counter);
2660 c4 = &vam->ip4_fib_counters[i][j];
2661 vat_json_object_add_ip4(counter, "address", c4->address);
2662 vat_json_object_add_uint(counter, "address_length", c4->address_length);
2663 vat_json_object_add_uint(counter, "packets", c4->packets);
2664 vat_json_object_add_uint(counter, "bytes", c4->bytes);
2668 /* ip6 fib counters */
2669 msg_array = vat_json_object_add(&node, "ip6_fib_counters");
2670 vat_json_init_array(msg_array);
2671 for (i = 0; i < vec_len(vam->ip6_fib_counters); i++) {
2672 msg = vat_json_array_add(msg_array);
2673 vat_json_init_object(msg);
2674 vat_json_object_add_uint(msg, "vrf_id", vam->ip6_fib_counters_vrf_id_by_index[i]);
2675 counter_array = vat_json_object_add(msg, "c");
2676 vat_json_init_array(counter_array);
2677 for (j = 0; j < vec_len(vam->ip6_fib_counters[i]); j++) {
2678 counter = vat_json_array_add(counter_array);
2679 vat_json_init_object(counter);
2680 c6 = &vam->ip6_fib_counters[i][j];
2681 vat_json_object_add_ip6(counter, "address", c6->address);
2682 vat_json_object_add_uint(counter, "address_length", c6->address_length);
2683 vat_json_object_add_uint(counter, "packets", c6->packets);
2684 vat_json_object_add_uint(counter, "bytes", c6->bytes);
2688 vat_json_print(vam->ofp, &node);
2689 vat_json_free(&node);
2694 int exec (vat_main_t * vam)
2696 api_main_t * am = &api_main;
2697 vl_api_cli_request_t *mp;
2701 unformat_input_t * i = vam->input;
2703 if (vec_len(i->buffer) == 0)
2706 if (vam->exec_mode == 0 && unformat (i, "mode")) {
2710 if (vam->exec_mode == 1 &&
2711 (unformat (i, "exit") || unformat (i, "quit"))) {
2717 M(CLI_REQUEST, cli_request);
2720 * Copy cmd into shared memory.
2721 * In order for the CLI command to work, it
2722 * must be a vector ending in \n, not a C-string ending
2725 pthread_mutex_lock (&am->vlib_rp->mutex);
2726 oldheap = svm_push_data_heap (am->vlib_rp);
2728 vec_validate (cmd, vec_len(vam->input->buffer)-1);
2729 clib_memcpy (cmd, vam->input->buffer, vec_len(vam->input->buffer));
2731 svm_pop_heap (oldheap);
2732 pthread_mutex_unlock (&am->vlib_rp->mutex);
2734 mp->cmd_in_shmem = (u64) cmd;
2736 timeout = vat_time_now (vam) + 10.0;
2738 while (vat_time_now (vam) < timeout) {
2739 if (vam->result_ready == 1) {
2741 if (vam->shmem_result != NULL)
2742 fformat (vam->ofp, "%s", vam->shmem_result);
2743 pthread_mutex_lock (&am->vlib_rp->mutex);
2744 oldheap = svm_push_data_heap (am->vlib_rp);
2746 free_me = (u8 *)vam->shmem_result;
2749 svm_pop_heap (oldheap);
2750 pthread_mutex_unlock (&am->vlib_rp->mutex);
2757 static int api_create_loopback (vat_main_t * vam)
2759 unformat_input_t * i = vam->input;
2760 vl_api_create_loopback_t *mp;
2765 memset (mac_address, 0, sizeof (mac_address));
2767 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
2769 if (unformat (i, "mac %U", unformat_ethernet_address, mac_address))
2775 /* Construct the API message */
2776 M(CREATE_LOOPBACK, create_loopback);
2778 clib_memcpy (mp->mac_address, mac_address, sizeof (mac_address));
2783 static int api_delete_loopback (vat_main_t * vam)
2785 unformat_input_t * i = vam->input;
2786 vl_api_delete_loopback_t *mp;
2788 u32 sw_if_index = ~0;
2790 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
2792 if (unformat (i, "sw_if_index %d", &sw_if_index))
2798 if (sw_if_index == ~0)
2800 errmsg ("missing sw_if_index\n");
2804 /* Construct the API message */
2805 M(DELETE_LOOPBACK, delete_loopback);
2806 mp->sw_if_index = ntohl (sw_if_index);
2811 static int api_want_stats (vat_main_t * vam)
2813 unformat_input_t * i = vam->input;
2814 vl_api_want_stats_t * mp;
2818 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
2820 if (unformat (i, "enable"))
2822 else if (unformat (i, "disable"))
2830 errmsg ("missing enable|disable\n");
2834 M(WANT_STATS, want_stats);
2835 mp->enable_disable = enable;
2840 static int api_want_interface_events (vat_main_t * vam)
2842 unformat_input_t * i = vam->input;
2843 vl_api_want_interface_events_t * mp;
2847 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
2849 if (unformat (i, "enable"))
2851 else if (unformat (i, "disable"))
2859 errmsg ("missing enable|disable\n");
2863 M(WANT_INTERFACE_EVENTS, want_interface_events);
2864 mp->enable_disable = enable;
2866 vam->interface_event_display = enable;
2872 /* Note: non-static, called once to set up the initial intfc table */
2873 int api_sw_interface_dump (vat_main_t * vam)
2875 vl_api_sw_interface_dump_t *mp;
2878 name_sort_t * nses = 0, * ns;
2879 sw_interface_subif_t * sub = NULL;
2881 /* Toss the old name table */
2882 hash_foreach_pair (p, vam->sw_if_index_by_interface_name,
2884 vec_add2 (nses, ns, 1);
2885 ns->name = (u8 *)(p->key);
2886 ns->value = (u32) p->value[0];
2889 hash_free (vam->sw_if_index_by_interface_name);
2891 vec_foreach (ns, nses)
2892 vec_free (ns->name);
2896 vec_foreach (sub, vam->sw_if_subif_table) {
2897 vec_free (sub->interface_name);
2899 vec_free (vam->sw_if_subif_table);
2901 /* recreate the interface name hash table */
2902 vam->sw_if_index_by_interface_name
2903 = hash_create_string (0, sizeof(uword));
2905 /* Get list of ethernets */
2906 M(SW_INTERFACE_DUMP, sw_interface_dump);
2907 mp->name_filter_valid = 1;
2908 strncpy ((char *) mp->name_filter, "Ether", sizeof(mp->name_filter)-1);
2911 /* and local / loopback interfaces */
2912 M(SW_INTERFACE_DUMP, sw_interface_dump);
2913 mp->name_filter_valid = 1;
2914 strncpy ((char *) mp->name_filter, "lo", sizeof(mp->name_filter)-1);
2917 /* and vxlan tunnel interfaces */
2918 M(SW_INTERFACE_DUMP, sw_interface_dump);
2919 mp->name_filter_valid = 1;
2920 strncpy ((char *) mp->name_filter, "vxlan", sizeof(mp->name_filter)-1);
2923 /* and host (af_packet) interfaces */
2924 M(SW_INTERFACE_DUMP, sw_interface_dump);
2925 mp->name_filter_valid = 1;
2926 strncpy ((char *) mp->name_filter, "host", sizeof(mp->name_filter)-1);
2929 /* and l2tpv3 tunnel interfaces */
2930 M(SW_INTERFACE_DUMP, sw_interface_dump);
2931 mp->name_filter_valid = 1;
2932 strncpy ((char *) mp->name_filter, "l2tpv3_tunnel", sizeof(mp->name_filter)-1);
2935 /* and GRE tunnel interfaces */
2936 M(SW_INTERFACE_DUMP, sw_interface_dump);
2937 mp->name_filter_valid = 1;
2938 strncpy ((char *) mp->name_filter, "gre", sizeof(mp->name_filter)-1);
2941 /* Use a control ping for synchronization */
2943 vl_api_control_ping_t * mp;
2944 M(CONTROL_PING, control_ping);
2950 static int api_sw_interface_set_flags (vat_main_t * vam)
2952 unformat_input_t * i = vam->input;
2953 vl_api_sw_interface_set_flags_t *mp;
2956 u8 sw_if_index_set = 0;
2957 u8 admin_up = 0, link_up = 0;
2959 /* Parse args required to build the message */
2960 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
2961 if (unformat (i, "admin-up"))
2963 else if (unformat (i, "admin-down"))
2965 else if (unformat (i, "link-up"))
2967 else if (unformat (i, "link-down"))
2969 else if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
2970 sw_if_index_set = 1;
2971 else if (unformat (i, "sw_if_index %d", &sw_if_index))
2972 sw_if_index_set = 1;
2977 if (sw_if_index_set == 0) {
2978 errmsg ("missing interface name or sw_if_index\n");
2982 /* Construct the API message */
2983 M(SW_INTERFACE_SET_FLAGS, sw_interface_set_flags);
2984 mp->sw_if_index = ntohl (sw_if_index);
2985 mp->admin_up_down = admin_up;
2986 mp->link_up_down = link_up;
2991 /* Wait for a reply, return the good/bad news... */
2995 static int api_sw_interface_clear_stats (vat_main_t * vam)
2997 unformat_input_t * i = vam->input;
2998 vl_api_sw_interface_clear_stats_t *mp;
3001 u8 sw_if_index_set = 0;
3003 /* Parse args required to build the message */
3004 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
3005 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
3006 sw_if_index_set = 1;
3007 else if (unformat (i, "sw_if_index %d", &sw_if_index))
3008 sw_if_index_set = 1;
3013 /* Construct the API message */
3014 M(SW_INTERFACE_CLEAR_STATS, sw_interface_clear_stats);
3016 if (sw_if_index_set == 1)
3017 mp->sw_if_index = ntohl (sw_if_index);
3019 mp->sw_if_index = ~0;
3024 /* Wait for a reply, return the good/bad news... */
3028 static int api_sw_interface_add_del_address (vat_main_t * vam)
3030 unformat_input_t * i = vam->input;
3031 vl_api_sw_interface_add_del_address_t *mp;
3034 u8 sw_if_index_set = 0;
3035 u8 is_add = 1, del_all = 0;
3036 u32 address_length = 0;
3037 u8 v4_address_set = 0;
3038 u8 v6_address_set = 0;
3039 ip4_address_t v4address;
3040 ip6_address_t v6address;
3042 /* Parse args required to build the message */
3043 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
3044 if (unformat (i, "del-all"))
3046 else if (unformat (i, "del"))
3048 else if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
3049 sw_if_index_set = 1;
3050 else if (unformat (i, "sw_if_index %d", &sw_if_index))
3051 sw_if_index_set = 1;
3052 else if (unformat (i, "%U/%d",
3053 unformat_ip4_address, &v4address,
3056 else if (unformat (i, "%U/%d",
3057 unformat_ip6_address, &v6address,
3064 if (sw_if_index_set == 0) {
3065 errmsg ("missing interface name or sw_if_index\n");
3068 if (v4_address_set && v6_address_set) {
3069 errmsg ("both v4 and v6 addresses set\n");
3072 if (!v4_address_set && !v6_address_set && !del_all) {
3073 errmsg ("no addresses set\n");
3077 /* Construct the API message */
3078 M(SW_INTERFACE_ADD_DEL_ADDRESS, sw_interface_add_del_address);
3080 mp->sw_if_index = ntohl (sw_if_index);
3081 mp->is_add = is_add;
3082 mp->del_all = del_all;
3083 if (v6_address_set) {
3085 clib_memcpy (mp->address, &v6address, sizeof (v6address));
3087 clib_memcpy (mp->address, &v4address, sizeof (v4address));
3089 mp->address_length = address_length;
3094 /* Wait for a reply, return good/bad news */
3098 static int api_sw_interface_set_table (vat_main_t * vam)
3100 unformat_input_t * i = vam->input;
3101 vl_api_sw_interface_set_table_t *mp;
3103 u32 sw_if_index, vrf_id = 0;
3104 u8 sw_if_index_set = 0;
3107 /* Parse args required to build the message */
3108 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
3109 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
3110 sw_if_index_set = 1;
3111 else if (unformat (i, "sw_if_index %d", &sw_if_index))
3112 sw_if_index_set = 1;
3113 else if (unformat (i, "vrf %d", &vrf_id))
3115 else if (unformat (i, "ipv6"))
3121 if (sw_if_index_set == 0) {
3122 errmsg ("missing interface name or sw_if_index\n");
3126 /* Construct the API message */
3127 M(SW_INTERFACE_SET_TABLE, sw_interface_set_table);
3129 mp->sw_if_index = ntohl (sw_if_index);
3130 mp->is_ipv6 = is_ipv6;
3131 mp->vrf_id = ntohl (vrf_id);
3136 /* Wait for a reply... */
3140 static int api_sw_interface_set_vpath (vat_main_t * vam)
3142 unformat_input_t * i = vam->input;
3143 vl_api_sw_interface_set_vpath_t *mp;
3145 u32 sw_if_index = 0;
3146 u8 sw_if_index_set = 0;
3149 /* Parse args required to build the message */
3150 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
3151 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
3152 sw_if_index_set = 1;
3153 else if (unformat (i, "sw_if_index %d", &sw_if_index))
3154 sw_if_index_set = 1;
3155 else if (unformat (i, "enable"))
3157 else if (unformat (i, "disable"))
3163 if (sw_if_index_set == 0) {
3164 errmsg ("missing interface name or sw_if_index\n");
3168 /* Construct the API message */
3169 M(SW_INTERFACE_SET_VPATH, sw_interface_set_vpath);
3171 mp->sw_if_index = ntohl (sw_if_index);
3172 mp->enable = is_enable;
3177 /* Wait for a reply... */
3181 static int api_sw_interface_set_l2_xconnect (vat_main_t * vam)
3183 unformat_input_t * i = vam->input;
3184 vl_api_sw_interface_set_l2_xconnect_t *mp;
3187 u8 rx_sw_if_index_set = 0;
3189 u8 tx_sw_if_index_set = 0;
3192 /* Parse args required to build the message */
3193 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
3194 if (unformat (i, "rx_sw_if_index %d", &rx_sw_if_index))
3195 rx_sw_if_index_set = 1;
3196 else if (unformat (i, "tx_sw_if_index %d", &tx_sw_if_index))
3197 tx_sw_if_index_set = 1;
3198 else if (unformat (i, "rx")) {
3199 if (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
3200 if (unformat (i, "%U", unformat_sw_if_index, vam,
3202 rx_sw_if_index_set = 1;
3205 } else if (unformat (i, "tx")) {
3206 if (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
3207 if (unformat (i, "%U", unformat_sw_if_index, vam,
3209 tx_sw_if_index_set = 1;
3212 } else if (unformat (i, "enable"))
3214 else if (unformat (i, "disable"))
3220 if (rx_sw_if_index_set == 0) {
3221 errmsg ("missing rx interface name or rx_sw_if_index\n");
3225 if (enable && (tx_sw_if_index_set == 0)) {
3226 errmsg ("missing tx interface name or tx_sw_if_index\n");
3230 M(SW_INTERFACE_SET_L2_XCONNECT, sw_interface_set_l2_xconnect);
3232 mp->rx_sw_if_index = ntohl(rx_sw_if_index);
3233 mp->tx_sw_if_index = ntohl(tx_sw_if_index);
3234 mp->enable = enable;
3241 static int api_sw_interface_set_l2_bridge (vat_main_t * vam)
3243 unformat_input_t * i = vam->input;
3244 vl_api_sw_interface_set_l2_bridge_t *mp;
3247 u8 rx_sw_if_index_set = 0;
3254 /* Parse args required to build the message */
3255 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
3256 if (unformat (i, "sw_if_index %d", &rx_sw_if_index))
3257 rx_sw_if_index_set = 1;
3258 else if (unformat (i, "bd_id %d", &bd_id))
3260 else if (unformat (i, "%U", unformat_sw_if_index, vam,
3262 rx_sw_if_index_set = 1;
3263 else if (unformat (i, "shg %d", &shg))
3265 else if (unformat (i, "bvi"))
3267 else if (unformat (i, "enable"))
3269 else if (unformat (i, "disable"))
3275 if (rx_sw_if_index_set == 0) {
3276 errmsg ("missing rx interface name or sw_if_index\n");
3280 if (enable && (bd_id_set == 0)) {
3281 errmsg ("missing bridge domain\n");
3285 M(SW_INTERFACE_SET_L2_BRIDGE, sw_interface_set_l2_bridge);
3287 mp->rx_sw_if_index = ntohl(rx_sw_if_index);
3288 mp->bd_id = ntohl(bd_id);
3291 mp->enable = enable;
3298 static int api_bridge_domain_dump (vat_main_t * vam)
3300 unformat_input_t * i = vam->input;
3301 vl_api_bridge_domain_dump_t *mp;
3305 /* Parse args required to build the message */
3306 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
3307 if (unformat (i, "bd_id %d", &bd_id))
3313 M(BRIDGE_DOMAIN_DUMP, bridge_domain_dump);
3314 mp->bd_id = ntohl(bd_id);
3317 /* Use a control ping for synchronization */
3319 vl_api_control_ping_t * mp;
3320 M(CONTROL_PING, control_ping);
3329 static int api_bridge_domain_add_del (vat_main_t * vam)
3331 unformat_input_t * i = vam->input;
3332 vl_api_bridge_domain_add_del_t *mp;
3336 u32 flood = 1, forward = 1, learn = 1, uu_flood = 1, arp_term = 0;
3338 /* Parse args required to build the message */
3339 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
3340 if (unformat (i, "bd_id %d", &bd_id))
3342 else if (unformat (i, "flood %d", &flood))
3344 else if (unformat (i, "uu-flood %d", &uu_flood))
3346 else if (unformat (i, "forward %d", &forward))
3348 else if (unformat (i, "learn %d", &learn))
3350 else if (unformat (i, "arp-term %d", &arp_term))
3352 else if (unformat (i, "del")) {
3354 flood = uu_flood = forward = learn = 0;
3361 errmsg ("missing bridge domain\n");
3365 M(BRIDGE_DOMAIN_ADD_DEL, bridge_domain_add_del);
3367 mp->bd_id = ntohl(bd_id);
3369 mp->uu_flood = uu_flood;
3370 mp->forward = forward;
3372 mp->arp_term = arp_term;
3373 mp->is_add = is_add;
3380 static int api_l2fib_add_del (vat_main_t * vam)
3382 unformat_input_t * i = vam->input;
3383 vl_api_l2fib_add_del_t *mp;
3390 u8 sw_if_index_set = 0;
3395 /* Parse args required to build the message */
3396 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
3397 if (unformat (i, "mac %U", unformat_ethernet_address, &mac))
3399 else if (unformat (i, "bd_id %d", &bd_id))
3401 else if (unformat (i, "sw_if_index %d", &sw_if_index))
3402 sw_if_index_set = 1;
3403 else if (unformat (i, "sw_if")) {
3404 if (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
3405 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
3406 sw_if_index_set = 1;
3409 } else if (unformat (i, "static"))
3411 else if (unformat (i, "filter")) {
3414 } else if (unformat (i, "del"))
3421 errmsg ("missing mac address\n");
3425 if (bd_id_set == 0) {
3426 errmsg ("missing bridge domain\n");
3430 if (is_add && (sw_if_index_set == 0)) {
3431 errmsg ("missing interface name or sw_if_index\n");
3435 M(L2FIB_ADD_DEL, l2fib_add_del);
3438 mp->bd_id = ntohl(bd_id);
3439 mp->is_add = is_add;
3442 mp->sw_if_index = ntohl(sw_if_index);
3443 mp->static_mac = static_mac;
3444 mp->filter_mac = filter_mac;
3452 static int api_l2_flags (vat_main_t * vam)
3454 unformat_input_t * i = vam->input;
3455 vl_api_l2_flags_t *mp;
3458 u32 feature_bitmap = 0;
3459 u8 sw_if_index_set = 0;
3461 /* Parse args required to build the message */
3462 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
3463 if (unformat (i, "sw_if_index %d", &sw_if_index))
3464 sw_if_index_set = 1;
3465 else if (unformat (i, "sw_if")) {
3466 if (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
3467 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
3468 sw_if_index_set = 1;
3471 } else if (unformat (i, "learn"))
3472 feature_bitmap |= L2INPUT_FEAT_LEARN;
3473 else if (unformat (i, "forward"))
3474 feature_bitmap |= L2INPUT_FEAT_FWD;
3475 else if (unformat (i, "flood"))
3476 feature_bitmap |= L2INPUT_FEAT_FLOOD;
3477 else if (unformat (i, "uu-flood"))
3478 feature_bitmap |= L2INPUT_FEAT_UU_FLOOD;
3483 if (sw_if_index_set == 0) {
3484 errmsg ("missing interface name or sw_if_index\n");
3488 M(L2_FLAGS, l2_flags);
3490 mp->sw_if_index = ntohl(sw_if_index);
3491 mp->feature_bitmap = ntohl(feature_bitmap);
3498 static int api_bridge_flags (vat_main_t * vam)
3500 unformat_input_t * i = vam->input;
3501 vl_api_bridge_flags_t *mp;
3508 /* Parse args required to build the message */
3509 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
3510 if (unformat (i, "bd_id %d", &bd_id))
3512 else if (unformat (i, "learn"))
3514 else if (unformat (i, "forward"))
3516 else if (unformat (i, "flood"))
3518 else if (unformat (i, "uu-flood"))
3519 flags |= L2_UU_FLOOD;
3520 else if (unformat (i, "arp-term"))
3521 flags |= L2_ARP_TERM;
3522 else if (unformat (i, "off"))
3524 else if (unformat (i, "disable"))
3530 if (bd_id_set == 0) {
3531 errmsg ("missing bridge domain\n");
3535 M(BRIDGE_FLAGS, bridge_flags);
3537 mp->bd_id = ntohl(bd_id);
3538 mp->feature_bitmap = ntohl(flags);
3539 mp->is_set = is_set;
3546 static int api_bd_ip_mac_add_del (vat_main_t * vam)
3548 unformat_input_t * i = vam->input;
3549 vl_api_bd_ip_mac_add_del_t *mp;
3557 ip4_address_t v4addr;
3558 ip6_address_t v6addr;
3562 /* Parse args required to build the message */
3563 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
3564 if (unformat (i, "bd_id %d", &bd_id)) {
3566 } else if (unformat (i, "%U", unformat_ip4_address, &v4addr)) {
3568 } else if (unformat (i, "%U", unformat_ip6_address, &v6addr)) {
3571 } else if (unformat (i, "%U", unformat_ethernet_address, macaddr)) {
3573 } else if (unformat (i, "del"))
3579 if (bd_id_set == 0) {
3580 errmsg ("missing bridge domain\n");
3582 } else if (ip_set == 0) {
3583 errmsg ("missing IP address\n");
3585 } else if (mac_set == 0) {
3586 errmsg ("missing MAC address\n");
3590 M(BD_IP_MAC_ADD_DEL, bd_ip_mac_add_del);
3592 mp->bd_id = ntohl(bd_id);
3593 mp->is_ipv6 = is_ipv6;
3594 mp->is_add = is_add;
3596 clib_memcpy (mp->ip_address, &v6addr, sizeof (v6addr));
3597 else clib_memcpy (mp->ip_address, &v4addr, sizeof (v4addr));
3598 clib_memcpy (mp->mac_address, macaddr, 6);
3604 static int api_tap_connect (vat_main_t * vam)
3606 unformat_input_t * i = vam->input;
3607 vl_api_tap_connect_t *mp;
3614 memset (mac_address, 0, sizeof (mac_address));
3616 /* Parse args required to build the message */
3617 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
3618 if (unformat (i, "mac %U", unformat_ethernet_address, mac_address)) {
3621 else if (unformat (i, "random-mac"))
3623 else if (unformat (i, "tapname %s", &tap_name))
3629 if (name_set == 0) {
3630 errmsg ("missing tap name\n");
3633 if (vec_len (tap_name) > 63) {
3634 errmsg ("tap name too long\n");
3636 vec_add1 (tap_name, 0);
3638 /* Construct the API message */
3639 M(TAP_CONNECT, tap_connect);
3641 mp->use_random_mac = random_mac;
3642 clib_memcpy (mp->mac_address, mac_address, 6);
3643 clib_memcpy (mp->tap_name, tap_name, vec_len (tap_name));
3644 vec_free (tap_name);
3649 /* Wait for a reply... */
3653 static int api_tap_modify (vat_main_t * vam)
3655 unformat_input_t * i = vam->input;
3656 vl_api_tap_modify_t *mp;
3662 u32 sw_if_index = ~0;
3663 u8 sw_if_index_set = 0;
3665 memset (mac_address, 0, sizeof (mac_address));
3667 /* Parse args required to build the message */
3668 while (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;
3671 else if (unformat (i, "sw_if_index %d", &sw_if_index))
3672 sw_if_index_set = 1;
3673 else if (unformat (i, "mac %U", unformat_ethernet_address, mac_address)) {
3676 else if (unformat (i, "random-mac"))
3678 else if (unformat (i, "tapname %s", &tap_name))
3684 if (sw_if_index_set == 0) {
3685 errmsg ("missing vpp interface name");
3688 if (name_set == 0) {
3689 errmsg ("missing tap name\n");
3692 if (vec_len (tap_name) > 63) {
3693 errmsg ("tap name too long\n");
3695 vec_add1 (tap_name, 0);
3697 /* Construct the API message */
3698 M(TAP_MODIFY, tap_modify);
3700 mp->use_random_mac = random_mac;
3701 mp->sw_if_index = ntohl(sw_if_index);
3702 clib_memcpy (mp->mac_address, mac_address, 6);
3703 clib_memcpy (mp->tap_name, tap_name, vec_len (tap_name));
3704 vec_free (tap_name);
3709 /* Wait for a reply... */
3713 static int api_tap_delete (vat_main_t * vam)
3715 unformat_input_t * i = vam->input;
3716 vl_api_tap_delete_t *mp;
3718 u32 sw_if_index = ~0;
3719 u8 sw_if_index_set = 0;
3721 /* Parse args required to build the message */
3722 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
3723 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
3724 sw_if_index_set = 1;
3725 else if (unformat (i, "sw_if_index %d", &sw_if_index))
3726 sw_if_index_set = 1;
3731 if (sw_if_index_set == 0) {
3732 errmsg ("missing vpp interface name");
3736 /* Construct the API message */
3737 M(TAP_DELETE, tap_delete);
3739 mp->sw_if_index = ntohl(sw_if_index);
3744 /* Wait for a reply... */
3748 static int api_ip_add_del_route (vat_main_t * vam)
3750 unformat_input_t * i = vam->input;
3751 vl_api_ip_add_del_route_t *mp;
3753 u32 sw_if_index = 0, vrf_id = 0;
3754 u8 sw_if_index_set = 0;
3756 u8 is_local = 0, is_drop = 0;
3757 u8 create_vrf_if_needed = 0;
3759 u8 next_hop_weight = 1;
3761 u8 is_multipath = 0;
3763 u8 address_length_set = 0;
3764 u32 lookup_in_vrf = 0;
3765 u32 resolve_attempts = 0;
3766 u32 dst_address_length = 0;
3767 u8 next_hop_set = 0;
3768 ip4_address_t v4_dst_address, v4_next_hop_address;
3769 ip6_address_t v6_dst_address, v6_next_hop_address;
3773 u32 random_add_del = 0;
3774 u32 * random_vector = 0;
3775 uword * random_hash;
3776 u32 random_seed = 0xdeaddabe;
3777 u32 classify_table_index = ~0;
3780 /* Parse args required to build the message */
3781 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
3782 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
3783 sw_if_index_set = 1;
3784 else if (unformat (i, "sw_if_index %d", &sw_if_index))
3785 sw_if_index_set = 1;
3786 else if (unformat (i, "%U", unformat_ip4_address,
3791 else if (unformat (i, "%U", unformat_ip6_address, &v6_dst_address)) {
3795 else if (unformat (i, "/%d", &dst_address_length)) {
3796 address_length_set = 1;
3799 else if (is_ipv6 == 0 && unformat (i, "via %U", unformat_ip4_address,
3800 &v4_next_hop_address)) {
3803 else if (is_ipv6 == 1 && unformat (i, "via %U", unformat_ip6_address,
3804 &v6_next_hop_address)) {
3807 else if (unformat (i, "resolve-attempts %d", &resolve_attempts))
3809 else if (unformat (i, "weight %d", &next_hop_weight))
3811 else if (unformat (i, "drop")) {
3813 } else if (unformat (i, "local")) {
3815 } else if (unformat (i, "classify %d", &classify_table_index)) {
3817 } else if (unformat (i, "del"))
3819 else if (unformat (i, "add"))
3821 else if (unformat (i, "not-last"))
3823 else if (unformat (i, "multipath"))
3825 else if (unformat (i, "vrf %d", &vrf_id))
3827 else if (unformat (i, "create-vrf"))
3828 create_vrf_if_needed = 1;
3829 else if (unformat (i, "count %d", &count))
3831 else if (unformat (i, "lookup-in-vrf %d", &lookup_in_vrf))
3833 else if (unformat (i, "random"))
3835 else if (unformat (i, "seed %d", &random_seed))
3838 clib_warning ("parse error '%U'", format_unformat_error, i);
3843 if (resolve_attempts > 0 && sw_if_index_set == 0) {
3844 errmsg ("ARP resolution needs explicit interface or sw_if_index\n");
3848 if (!next_hop_set && !is_drop && !is_local && !is_classify) {
3849 errmsg ("next hop / local / drop / classify not set\n");
3853 if (address_set == 0) {
3854 errmsg ("missing addresses\n");
3858 if (address_length_set == 0) {
3859 errmsg ("missing address length\n");
3863 /* Generate a pile of unique, random routes */
3864 if (random_add_del) {
3865 u32 this_random_address;
3866 random_hash = hash_create (count, sizeof(uword));
3868 hash_set (random_hash, v4_next_hop_address.as_u32, 1);
3869 for (j = 0; j <= count; j++) {
3871 this_random_address = random_u32 (&random_seed);
3872 this_random_address =
3873 clib_host_to_net_u32 (this_random_address);
3874 } while (hash_get (random_hash, this_random_address));
3875 vec_add1 (random_vector, this_random_address);
3876 hash_set (random_hash, this_random_address, 1);
3878 hash_free (random_hash);
3879 v4_dst_address.as_u32 = random_vector[0];
3883 /* Turn on async mode */
3884 vam->async_mode = 1;
3885 vam->async_errors = 0;
3886 before = vat_time_now(vam);
3889 for (j = 0; j < count; j++) {
3890 /* Construct the API message */
3891 M(IP_ADD_DEL_ROUTE, ip_add_del_route);
3893 mp->next_hop_sw_if_index = ntohl (sw_if_index);
3894 mp->vrf_id = ntohl (vrf_id);
3895 if (resolve_attempts > 0) {
3896 mp->resolve_attempts = ntohl (resolve_attempts);
3897 mp->resolve_if_needed = 1;
3899 mp->create_vrf_if_needed = create_vrf_if_needed;
3901 mp->is_add = is_add;
3902 mp->is_drop = is_drop;
3903 mp->is_ipv6 = is_ipv6;
3904 mp->is_local = is_local;
3905 mp->is_classify = is_classify;
3906 mp->is_multipath = is_multipath;
3907 mp->not_last = not_last;
3908 mp->next_hop_weight = next_hop_weight;
3909 mp->dst_address_length = dst_address_length;
3910 mp->lookup_in_vrf = ntohl(lookup_in_vrf);
3911 mp->classify_table_index = ntohl(classify_table_index);
3914 clib_memcpy (mp->dst_address, &v6_dst_address, sizeof (v6_dst_address));
3916 clib_memcpy (mp->next_hop_address, &v6_next_hop_address,
3917 sizeof (v6_next_hop_address));
3918 increment_v6_address (&v6_dst_address);
3920 clib_memcpy (mp->dst_address, &v4_dst_address, sizeof (v4_dst_address));
3922 clib_memcpy (mp->next_hop_address, &v4_next_hop_address,
3923 sizeof (v4_next_hop_address));
3925 v4_dst_address.as_u32 = random_vector[j+1];
3927 increment_v4_address (&v4_dst_address);
3933 /* When testing multiple add/del ops, use a control-ping to sync */
3935 vl_api_control_ping_t * mp;
3938 /* Shut off async mode */
3939 vam->async_mode = 0;
3941 M(CONTROL_PING, control_ping);
3944 timeout = vat_time_now(vam) + 1.0;
3945 while (vat_time_now (vam) < timeout)
3946 if (vam->result_ready == 1)
3951 if (vam->retval == -99)
3952 errmsg ("timeout\n");
3954 if (vam->async_errors > 0) {
3955 errmsg ("%d asynchronous errors\n", vam->async_errors);
3958 vam->async_errors = 0;
3959 after = vat_time_now(vam);
3961 fformat(vam->ofp, "%d routes in %.6f secs, %.2f routes/sec\n",
3962 count, after - before, count / (after - before));
3964 /* Wait for a reply... */
3968 /* Return the good/bad news */
3969 return (vam->retval);
3972 static int api_proxy_arp_add_del (vat_main_t * vam)
3974 unformat_input_t * i = vam->input;
3975 vl_api_proxy_arp_add_del_t *mp;
3979 ip4_address_t lo, hi;
3982 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
3983 if (unformat (i, "vrf %d", &vrf_id))
3985 else if (unformat (i, "%U - %U", unformat_ip4_address, &lo,
3986 unformat_ip4_address, &hi))
3988 else if (unformat (i, "del"))
3991 clib_warning ("parse error '%U'", format_unformat_error, i);
3996 if (range_set == 0) {
3997 errmsg ("address range not set\n");
4001 M(PROXY_ARP_ADD_DEL, proxy_arp_add_del);
4003 mp->vrf_id = ntohl(vrf_id);
4004 mp->is_add = is_add;
4005 clib_memcpy(mp->low_address, &lo, sizeof (mp->low_address));
4006 clib_memcpy(mp->hi_address, &hi, sizeof (mp->hi_address));
4013 static int api_proxy_arp_intfc_enable_disable (vat_main_t * vam)
4015 unformat_input_t * i = vam->input;
4016 vl_api_proxy_arp_intfc_enable_disable_t *mp;
4020 u8 sw_if_index_set = 0;
4022 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
4023 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
4024 sw_if_index_set = 1;
4025 else if (unformat (i, "sw_if_index %d", &sw_if_index))
4026 sw_if_index_set = 1;
4027 else if (unformat (i, "enable"))
4029 else if (unformat (i, "disable"))
4032 clib_warning ("parse error '%U'", format_unformat_error, i);
4037 if (sw_if_index_set == 0) {
4038 errmsg ("missing interface name or sw_if_index\n");
4042 M(PROXY_ARP_INTFC_ENABLE_DISABLE, proxy_arp_intfc_enable_disable);
4044 mp->sw_if_index = ntohl(sw_if_index);
4045 mp->enable_disable = enable;
4052 static int api_mpls_add_del_decap (vat_main_t * vam)
4054 unformat_input_t * i = vam->input;
4055 vl_api_mpls_add_del_decap_t *mp;
4064 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
4065 if (unformat (i, "rx_vrf_id %d", &rx_vrf_id))
4067 else if (unformat (i, "tx_vrf_id %d", &tx_vrf_id))
4069 else if (unformat (i, "label %d", &label))
4071 else if (unformat (i, "next-index %d", &next_index))
4073 else if (unformat (i, "del"))
4075 else if (unformat (i, "s-bit-clear"))
4078 clib_warning ("parse error '%U'", format_unformat_error, i);
4083 M(MPLS_ADD_DEL_DECAP, mpls_add_del_decap);
4085 mp->rx_vrf_id = ntohl(rx_vrf_id);
4086 mp->tx_vrf_id = ntohl(tx_vrf_id);
4087 mp->label = ntohl(label);
4088 mp->next_index = ntohl(next_index);
4090 mp->is_add = is_add;
4097 static int api_mpls_add_del_encap (vat_main_t * vam)
4099 unformat_input_t * i = vam->input;
4100 vl_api_mpls_add_del_encap_t *mp;
4105 ip4_address_t dst_address;
4108 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
4109 if (unformat (i, "vrf %d", &vrf_id))
4111 else if (unformat (i, "label %d", &label))
4112 vec_add1 (labels, ntohl(label));
4113 else if (unformat (i, "dst %U", unformat_ip4_address, &dst_address))
4115 else if (unformat (i, "del"))
4118 clib_warning ("parse error '%U'", format_unformat_error, i);
4123 if (vec_len (labels) == 0) {
4124 errmsg ("missing encap label stack\n");
4128 M2(MPLS_ADD_DEL_ENCAP, mpls_add_del_encap,
4129 sizeof (u32) * vec_len (labels));
4131 mp->vrf_id = ntohl(vrf_id);
4132 clib_memcpy(mp->dst_address, &dst_address, sizeof (dst_address));
4133 mp->is_add = is_add;
4134 mp->nlabels = vec_len (labels);
4135 clib_memcpy(mp->labels, labels, sizeof(u32)*mp->nlabels);
4144 static int api_mpls_gre_add_del_tunnel (vat_main_t * vam)
4146 unformat_input_t * i = vam->input;
4147 vl_api_mpls_gre_add_del_tunnel_t *mp;
4149 u32 inner_vrf_id = 0;
4150 u32 outer_vrf_id = 0;
4151 ip4_address_t src_address;
4152 ip4_address_t dst_address;
4153 ip4_address_t intfc_address;
4155 u8 intfc_address_length = 0;
4159 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
4160 if (unformat (i, "inner_vrf_id %d", &inner_vrf_id))
4162 else if (unformat (i, "outer_vrf_id %d", &outer_vrf_id))
4164 else if (unformat (i, "src %U", unformat_ip4_address, &src_address))
4166 else if (unformat (i, "dst %U", unformat_ip4_address, &dst_address))
4168 else if (unformat (i, "adj %U/%d", unformat_ip4_address,
4169 &intfc_address, &tmp))
4170 intfc_address_length = tmp;
4171 else if (unformat (i, "l2-only"))
4173 else if (unformat (i, "del"))
4176 clib_warning ("parse error '%U'", format_unformat_error, i);
4181 M(MPLS_GRE_ADD_DEL_TUNNEL, mpls_gre_add_del_tunnel);
4183 mp->inner_vrf_id = ntohl(inner_vrf_id);
4184 mp->outer_vrf_id = ntohl(outer_vrf_id);
4185 clib_memcpy(mp->src_address, &src_address, sizeof (src_address));
4186 clib_memcpy(mp->dst_address, &dst_address, sizeof (dst_address));
4187 clib_memcpy(mp->intfc_address, &intfc_address, sizeof (intfc_address));
4188 mp->intfc_address_length = intfc_address_length;
4189 mp->l2_only = l2_only;
4190 mp->is_add = is_add;
4197 static int api_mpls_ethernet_add_del_tunnel (vat_main_t * vam)
4199 unformat_input_t * i = vam->input;
4200 vl_api_mpls_ethernet_add_del_tunnel_t *mp;
4202 u32 inner_vrf_id = 0;
4203 ip4_address_t intfc_address;
4204 u8 dst_mac_address[6];
4207 u8 intfc_address_length = 0;
4211 int tx_sw_if_index_set = 0;
4213 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
4214 if (unformat (i, "vrf %d", &inner_vrf_id))
4216 else if (unformat (i, "adj %U/%d", unformat_ip4_address,
4217 &intfc_address, &tmp))
4218 intfc_address_length = tmp;
4219 else if (unformat (i, "%U",
4220 unformat_sw_if_index, vam, &tx_sw_if_index))
4221 tx_sw_if_index_set = 1;
4222 else if (unformat (i, "tx_sw_if_index %d", &tx_sw_if_index))
4223 tx_sw_if_index_set = 1;
4224 else if (unformat (i, "dst %U", unformat_ethernet_address,
4227 else if (unformat (i, "l2-only"))
4229 else if (unformat (i, "del"))
4232 clib_warning ("parse error '%U'", format_unformat_error, i);
4238 errmsg ("dst (mac address) not set\n");
4241 if (!tx_sw_if_index_set) {
4242 errmsg ("tx-intfc not set\n");
4246 M(MPLS_ETHERNET_ADD_DEL_TUNNEL, mpls_ethernet_add_del_tunnel);
4248 mp->vrf_id = ntohl(inner_vrf_id);
4249 clib_memcpy (mp->adj_address, &intfc_address, sizeof (intfc_address));
4250 mp->adj_address_length = intfc_address_length;
4251 clib_memcpy (mp->dst_mac_address, dst_mac_address, sizeof (dst_mac_address));
4252 mp->tx_sw_if_index = ntohl(tx_sw_if_index);
4253 mp->l2_only = l2_only;
4254 mp->is_add = is_add;
4261 static int api_mpls_ethernet_add_del_tunnel_2 (vat_main_t * vam)
4263 unformat_input_t * i = vam->input;
4264 vl_api_mpls_ethernet_add_del_tunnel_2_t *mp;
4266 u32 inner_vrf_id = 0;
4267 u32 outer_vrf_id = 0;
4268 ip4_address_t adj_address;
4269 int adj_address_set = 0;
4270 ip4_address_t next_hop_address;
4271 int next_hop_address_set = 0;
4273 u8 adj_address_length = 0;
4276 u32 resolve_attempts = 5;
4277 u8 resolve_if_needed = 1;
4279 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
4280 if (unformat (i, "inner_vrf_id %d", &inner_vrf_id))
4282 else if (unformat (i, "outer_vrf_id %d", &outer_vrf_id))
4284 else if (unformat (i, "adj %U/%d", unformat_ip4_address,
4285 &adj_address, &tmp)) {
4286 adj_address_length = tmp;
4287 adj_address_set = 1;
4289 else if (unformat (i, "next-hop %U", unformat_ip4_address,
4291 next_hop_address_set = 1;
4292 else if (unformat (i, "resolve-attempts %d", &resolve_attempts))
4294 else if (unformat (i, "resolve-if-needed %d", &tmp))
4295 resolve_if_needed = tmp;
4296 else if (unformat (i, "l2-only"))
4298 else if (unformat (i, "del"))
4301 clib_warning ("parse error '%U'", format_unformat_error, i);
4306 if (!adj_address_set) {
4307 errmsg ("adjacency address/mask not set\n");
4310 if (!next_hop_address_set) {
4311 errmsg ("ip4 next hop address (in outer fib) not set\n");
4315 M(MPLS_ETHERNET_ADD_DEL_TUNNEL_2, mpls_ethernet_add_del_tunnel_2);
4317 mp->inner_vrf_id = ntohl(inner_vrf_id);
4318 mp->outer_vrf_id = ntohl(outer_vrf_id);
4319 mp->resolve_attempts = ntohl(resolve_attempts);
4320 mp->resolve_if_needed = resolve_if_needed;
4321 mp->is_add = is_add;
4322 mp->l2_only = l2_only;
4323 clib_memcpy (mp->adj_address, &adj_address, sizeof (adj_address));
4324 mp->adj_address_length = adj_address_length;
4325 clib_memcpy (mp->next_hop_ip4_address_in_outer_vrf, &next_hop_address,
4326 sizeof (next_hop_address));
4333 static int api_sw_interface_set_unnumbered (vat_main_t * vam)
4335 unformat_input_t * i = vam->input;
4336 vl_api_sw_interface_set_unnumbered_t *mp;
4341 u8 sw_if_index_set = 0;
4343 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
4344 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
4345 sw_if_index_set = 1;
4346 else if (unformat (i, "sw_if_index %d", &sw_if_index))
4347 sw_if_index_set = 1;
4348 else if (unformat (i, "unnum_if_index %d", &unnum_sw_index))
4350 else if (unformat (i, "del"))
4353 clib_warning ("parse error '%U'", format_unformat_error, i);
4358 if (sw_if_index_set == 0) {
4359 errmsg ("missing interface name or sw_if_index\n");
4363 M(SW_INTERFACE_SET_UNNUMBERED, sw_interface_set_unnumbered);
4365 mp->sw_if_index = ntohl(sw_if_index);
4366 mp->unnumbered_sw_if_index = ntohl(unnum_sw_index);
4367 mp->is_add = is_add;
4374 static int api_ip_neighbor_add_del (vat_main_t * vam)
4376 unformat_input_t * i = vam->input;
4377 vl_api_ip_neighbor_add_del_t *mp;
4380 u8 sw_if_index_set = 0;
4386 u8 v4_address_set = 0;
4387 u8 v6_address_set = 0;
4388 ip4_address_t v4address;
4389 ip6_address_t v6address;
4391 memset (mac_address, 0, sizeof (mac_address));
4393 /* Parse args required to build the message */
4394 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
4395 if (unformat (i, "mac %U", unformat_ethernet_address, mac_address)) {
4398 else if (unformat (i, "del"))
4400 else if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
4401 sw_if_index_set = 1;
4402 else if (unformat (i, "sw_if_index %d", &sw_if_index))
4403 sw_if_index_set = 1;
4404 else if (unformat (i, "is_static"))
4406 else if (unformat (i, "vrf %d", &vrf_id))
4408 else if (unformat (i, "dst %U",
4409 unformat_ip4_address, &v4address))
4411 else if (unformat (i, "dst %U",
4412 unformat_ip6_address, &v6address))
4415 clib_warning ("parse error '%U'", format_unformat_error, i);
4420 if (sw_if_index_set == 0) {
4421 errmsg ("missing interface name or sw_if_index\n");
4424 if (v4_address_set && v6_address_set) {
4425 errmsg ("both v4 and v6 addresses set\n");
4428 if (!v4_address_set && !v6_address_set) {
4429 errmsg ("no addresses set\n");
4433 /* Construct the API message */
4434 M(IP_NEIGHBOR_ADD_DEL, ip_neighbor_add_del);
4436 mp->sw_if_index = ntohl (sw_if_index);
4437 mp->is_add = is_add;
4438 mp->vrf_id = ntohl (vrf_id);
4439 mp->is_static = is_static;
4441 clib_memcpy (mp->mac_address, mac_address, 6);
4442 if (v6_address_set) {
4444 clib_memcpy (mp->dst_address, &v6address, sizeof (v6address));
4446 /* mp->is_ipv6 = 0; via memset in M macro above */
4447 clib_memcpy (mp->dst_address, &v4address, sizeof (v4address));
4453 /* Wait for a reply, return good/bad news */
4460 static int api_reset_vrf (vat_main_t * vam)
4462 unformat_input_t * i = vam->input;
4463 vl_api_reset_vrf_t *mp;
4469 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
4470 if (unformat (i, "vrf %d", &vrf_id))
4472 else if (unformat (i, "ipv6"))
4475 clib_warning ("parse error '%U'", format_unformat_error, i);
4480 if (vrf_id_set == 0) {
4481 errmsg ("missing vrf id\n");
4485 M(RESET_VRF, reset_vrf);
4487 mp->vrf_id = ntohl(vrf_id);
4488 mp->is_ipv6 = is_ipv6;
4495 static int api_create_vlan_subif (vat_main_t * vam)
4497 unformat_input_t * i = vam->input;
4498 vl_api_create_vlan_subif_t *mp;
4501 u8 sw_if_index_set = 0;
4505 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
4506 if (unformat (i, "sw_if_index %d", &sw_if_index))
4507 sw_if_index_set = 1;
4508 else if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
4509 sw_if_index_set = 1;
4510 else if (unformat (i, "vlan %d", &vlan_id))
4513 clib_warning ("parse error '%U'", format_unformat_error, i);
4518 if (sw_if_index_set == 0) {
4519 errmsg ("missing interface name or sw_if_index\n");
4523 if (vlan_id_set == 0) {
4524 errmsg ("missing vlan_id\n");
4527 M(CREATE_VLAN_SUBIF, create_vlan_subif);
4529 mp->sw_if_index = ntohl(sw_if_index);
4530 mp->vlan_id = ntohl(vlan_id);
4537 #define foreach_create_subif_bit \
4544 _(outer_vlan_id_any) \
4545 _(inner_vlan_id_any)
4547 static int api_create_subif (vat_main_t * vam)
4549 unformat_input_t * i = vam->input;
4550 vl_api_create_subif_t *mp;
4553 u8 sw_if_index_set = 0;
4560 u32 exact_match = 0;
4561 u32 default_sub = 0;
4562 u32 outer_vlan_id_any = 0;
4563 u32 inner_vlan_id_any = 0;
4565 u16 outer_vlan_id = 0;
4566 u16 inner_vlan_id = 0;
4568 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
4569 if (unformat (i, "sw_if_index %d", &sw_if_index))
4570 sw_if_index_set = 1;
4571 else if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
4572 sw_if_index_set = 1;
4573 else if (unformat (i, "sub_id %d", &sub_id))
4575 else if (unformat (i, "outer_vlan_id %d", &tmp))
4576 outer_vlan_id = tmp;
4577 else if (unformat (i, "inner_vlan_id %d", &tmp))
4578 inner_vlan_id = tmp;
4580 #define _(a) else if (unformat (i, #a)) a = 1 ;
4581 foreach_create_subif_bit
4585 clib_warning ("parse error '%U'", format_unformat_error, i);
4590 if (sw_if_index_set == 0) {
4591 errmsg ("missing interface name or sw_if_index\n");
4595 if (sub_id_set == 0) {
4596 errmsg ("missing sub_id\n");
4599 M(CREATE_SUBIF, create_subif);
4601 mp->sw_if_index = ntohl(sw_if_index);
4602 mp->sub_id = ntohl(sub_id);
4604 #define _(a) mp->a = a;
4605 foreach_create_subif_bit;
4608 mp->outer_vlan_id = ntohs (outer_vlan_id);
4609 mp->inner_vlan_id = ntohs (inner_vlan_id);
4616 static int api_oam_add_del (vat_main_t * vam)
4618 unformat_input_t * i = vam->input;
4619 vl_api_oam_add_del_t *mp;
4623 ip4_address_t src, dst;
4627 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
4628 if (unformat (i, "vrf %d", &vrf_id))
4630 else if (unformat (i, "src %U", unformat_ip4_address, &src))
4632 else if (unformat (i, "dst %U", unformat_ip4_address, &dst))
4634 else if (unformat (i, "del"))
4637 clib_warning ("parse error '%U'", format_unformat_error, i);
4643 errmsg ("missing src addr\n");
4648 errmsg ("missing dst addr\n");
4652 M(OAM_ADD_DEL, oam_add_del);
4654 mp->vrf_id = ntohl(vrf_id);
4655 mp->is_add = is_add;
4656 clib_memcpy(mp->src_address, &src, sizeof (mp->src_address));
4657 clib_memcpy(mp->dst_address, &dst, sizeof (mp->dst_address));
4664 static int api_reset_fib (vat_main_t * vam)
4666 unformat_input_t * i = vam->input;
4667 vl_api_reset_fib_t *mp;
4673 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
4674 if (unformat (i, "vrf %d", &vrf_id))
4676 else if (unformat (i, "ipv6"))
4679 clib_warning ("parse error '%U'", format_unformat_error, i);
4684 if (vrf_id_set == 0) {
4685 errmsg ("missing vrf id\n");
4689 M(RESET_FIB, reset_fib);
4691 mp->vrf_id = ntohl(vrf_id);
4692 mp->is_ipv6 = is_ipv6;
4699 static int api_dhcp_proxy_config (vat_main_t * vam)
4701 unformat_input_t * i = vam->input;
4702 vl_api_dhcp_proxy_config_t *mp;
4707 u8 v4_address_set = 0;
4708 u8 v6_address_set = 0;
4709 ip4_address_t v4address;
4710 ip6_address_t v6address;
4711 u8 v4_src_address_set = 0;
4712 u8 v6_src_address_set = 0;
4713 ip4_address_t v4srcaddress;
4714 ip6_address_t v6srcaddress;
4716 /* Parse args required to build the message */
4717 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
4718 if (unformat (i, "del"))
4720 else if (unformat (i, "vrf %d", &vrf_id))
4722 else if (unformat (i, "insert-cid %d", &insert_cid))
4724 else if (unformat (i, "svr %U",
4725 unformat_ip4_address, &v4address))
4727 else if (unformat (i, "svr %U",
4728 unformat_ip6_address, &v6address))
4730 else if (unformat (i, "src %U",
4731 unformat_ip4_address, &v4srcaddress))
4732 v4_src_address_set = 1;
4733 else if (unformat (i, "src %U",
4734 unformat_ip6_address, &v6srcaddress))
4735 v6_src_address_set = 1;
4740 if (v4_address_set && v6_address_set) {
4741 errmsg ("both v4 and v6 server addresses set\n");
4744 if (!v4_address_set && !v6_address_set) {
4745 errmsg ("no server addresses set\n");
4749 if (v4_src_address_set && v6_src_address_set) {
4750 errmsg ("both v4 and v6 src addresses set\n");
4753 if (!v4_src_address_set && !v6_src_address_set) {
4754 errmsg ("no src addresses set\n");
4758 if (!(v4_src_address_set && v4_address_set) &&
4759 !(v6_src_address_set && v6_address_set)) {
4760 errmsg ("no matching server and src addresses set\n");
4764 /* Construct the API message */
4765 M(DHCP_PROXY_CONFIG, dhcp_proxy_config);
4767 mp->insert_circuit_id = insert_cid;
4768 mp->is_add = is_add;
4769 mp->vrf_id = ntohl (vrf_id);
4770 if (v6_address_set) {
4772 clib_memcpy (mp->dhcp_server, &v6address, sizeof (v6address));
4773 clib_memcpy (mp->dhcp_src_address, &v6srcaddress, sizeof (v6address));
4775 clib_memcpy (mp->dhcp_server, &v4address, sizeof (v4address));
4776 clib_memcpy (mp->dhcp_src_address, &v4srcaddress, sizeof (v4address));
4782 /* Wait for a reply, return good/bad news */
4788 static int api_dhcp_proxy_config_2 (vat_main_t * vam)
4790 unformat_input_t * i = vam->input;
4791 vl_api_dhcp_proxy_config_2_t *mp;
4794 u32 server_vrf_id = 0;
4797 u8 v4_address_set = 0;
4798 u8 v6_address_set = 0;
4799 ip4_address_t v4address;
4800 ip6_address_t v6address;
4801 u8 v4_src_address_set = 0;
4802 u8 v6_src_address_set = 0;
4803 ip4_address_t v4srcaddress;
4804 ip6_address_t v6srcaddress;
4806 /* Parse args required to build the message */
4807 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
4808 if (unformat (i, "del"))
4810 else if (unformat (i, "rx_vrf_id %d", &rx_vrf_id))
4812 else if (unformat (i, "server_vrf_id %d", &server_vrf_id))
4814 else if (unformat (i, "insert-cid %d", &insert_cid))
4816 else if (unformat (i, "svr %U",
4817 unformat_ip4_address, &v4address))
4819 else if (unformat (i, "svr %U",
4820 unformat_ip6_address, &v6address))
4822 else if (unformat (i, "src %U",
4823 unformat_ip4_address, &v4srcaddress))
4824 v4_src_address_set = 1;
4825 else if (unformat (i, "src %U",
4826 unformat_ip6_address, &v6srcaddress))
4827 v6_src_address_set = 1;
4832 if (v4_address_set && v6_address_set) {
4833 errmsg ("both v4 and v6 server addresses set\n");
4836 if (!v4_address_set && !v6_address_set) {
4837 errmsg ("no server addresses set\n");
4841 if (v4_src_address_set && v6_src_address_set) {
4842 errmsg ("both v4 and v6 src addresses set\n");
4845 if (!v4_src_address_set && !v6_src_address_set) {
4846 errmsg ("no src addresses set\n");
4850 if (!(v4_src_address_set && v4_address_set) &&
4851 !(v6_src_address_set && v6_address_set)) {
4852 errmsg ("no matching server and src addresses set\n");
4856 /* Construct the API message */
4857 M(DHCP_PROXY_CONFIG_2, dhcp_proxy_config_2);
4859 mp->insert_circuit_id = insert_cid;
4860 mp->is_add = is_add;
4861 mp->rx_vrf_id = ntohl (rx_vrf_id);
4862 mp->server_vrf_id = ntohl (server_vrf_id);
4863 if (v6_address_set) {
4865 clib_memcpy (mp->dhcp_server, &v6address, sizeof (v6address));
4866 clib_memcpy (mp->dhcp_src_address, &v6srcaddress, sizeof (v6address));
4868 clib_memcpy (mp->dhcp_server, &v4address, sizeof (v4address));
4869 clib_memcpy (mp->dhcp_src_address, &v4srcaddress, sizeof (v4address));
4875 /* Wait for a reply, return good/bad news */
4881 static int api_dhcp_proxy_set_vss (vat_main_t * vam)
4883 unformat_input_t * i = vam->input;
4884 vl_api_dhcp_proxy_set_vss_t *mp;
4895 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
4896 if (unformat (i, "tbl_id %d", &tbl_id))
4898 if (unformat (i, "fib_id %d", &fib_id))
4900 if (unformat (i, "oui %d", &oui))
4902 else if (unformat (i, "ipv6"))
4904 else if (unformat (i, "del"))
4907 clib_warning ("parse error '%U'", format_unformat_error, i);
4912 if (tbl_id_set == 0) {
4913 errmsg ("missing tbl id\n");
4917 if (fib_id_set == 0) {
4918 errmsg ("missing fib id\n");
4922 errmsg ("missing oui\n");
4926 M(DHCP_PROXY_SET_VSS, dhcp_proxy_set_vss);
4927 mp->tbl_id = ntohl(tbl_id);
4928 mp->fib_id = ntohl(fib_id);
4929 mp->oui = ntohl(oui);
4930 mp->is_ipv6 = is_ipv6;
4931 mp->is_add = is_add;
4938 static int api_dhcp_client_config (vat_main_t * vam)
4940 unformat_input_t * i = vam->input;
4941 vl_api_dhcp_client_config_t *mp;
4944 u8 sw_if_index_set = 0;
4947 u8 disable_event = 0;
4949 /* Parse args required to build the message */
4950 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
4951 if (unformat (i, "del"))
4953 else if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
4954 sw_if_index_set = 1;
4955 else if (unformat (i, "sw_if_index %d", &sw_if_index))
4956 sw_if_index_set = 1;
4957 else if (unformat (i, "hostname %s", &hostname))
4959 else if (unformat (i, "disable_event"))
4965 if (sw_if_index_set == 0) {
4966 errmsg ("missing interface name or sw_if_index\n");
4970 if (vec_len (hostname) > 63) {
4971 errmsg ("hostname too long\n");
4973 vec_add1 (hostname, 0);
4975 /* Construct the API message */
4976 M(DHCP_CLIENT_CONFIG, dhcp_client_config);
4978 mp->sw_if_index = ntohl (sw_if_index);
4979 clib_memcpy (mp->hostname, hostname, vec_len (hostname));
4980 vec_free (hostname);
4981 mp->is_add = is_add;
4982 mp->want_dhcp_event = disable_event ? 0 : 1;
4988 /* Wait for a reply, return good/bad news */
4994 static int api_set_ip_flow_hash (vat_main_t * vam)
4996 unformat_input_t * i = vam->input;
4997 vl_api_set_ip_flow_hash_t *mp;
5009 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
5010 if (unformat (i, "vrf %d", &vrf_id))
5012 else if (unformat (i, "ipv6"))
5014 else if (unformat (i, "src"))
5016 else if (unformat (i, "dst"))
5018 else if (unformat (i, "sport"))
5020 else if (unformat (i, "dport"))
5022 else if (unformat (i, "proto"))
5024 else if (unformat (i, "reverse"))
5028 clib_warning ("parse error '%U'", format_unformat_error, i);
5033 if (vrf_id_set == 0) {
5034 errmsg ("missing vrf id\n");
5038 M(SET_IP_FLOW_HASH, set_ip_flow_hash);
5044 mp->reverse = reverse;
5045 mp->vrf_id = ntohl(vrf_id);
5046 mp->is_ipv6 = is_ipv6;
5053 static int api_sw_interface_ip6_enable_disable (vat_main_t * vam)
5055 unformat_input_t * i = vam->input;
5056 vl_api_sw_interface_ip6_enable_disable_t *mp;
5059 u8 sw_if_index_set = 0;
5062 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
5063 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
5064 sw_if_index_set = 1;
5065 else if (unformat (i, "sw_if_index %d", &sw_if_index))
5066 sw_if_index_set = 1;
5067 else if (unformat (i, "enable"))
5069 else if (unformat (i, "disable"))
5072 clib_warning ("parse error '%U'", format_unformat_error, i);
5077 if (sw_if_index_set == 0) {
5078 errmsg ("missing interface name or sw_if_index\n");
5082 M(SW_INTERFACE_IP6_ENABLE_DISABLE, sw_interface_ip6_enable_disable);
5084 mp->sw_if_index = ntohl(sw_if_index);
5085 mp->enable = enable;
5092 static int api_sw_interface_ip6_set_link_local_address (vat_main_t * vam)
5094 unformat_input_t * i = vam->input;
5095 vl_api_sw_interface_ip6_set_link_local_address_t *mp;
5098 u8 sw_if_index_set = 0;
5099 u32 address_length = 0;
5100 u8 v6_address_set = 0;
5101 ip6_address_t v6address;
5103 /* Parse args required to build the message */
5104 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
5105 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
5106 sw_if_index_set = 1;
5107 else if (unformat (i, "sw_if_index %d", &sw_if_index))
5108 sw_if_index_set = 1;
5109 else if (unformat (i, "%U/%d",
5110 unformat_ip6_address, &v6address,
5117 if (sw_if_index_set == 0) {
5118 errmsg ("missing interface name or sw_if_index\n");
5121 if (!v6_address_set) {
5122 errmsg ("no address set\n");
5126 /* Construct the API message */
5127 M(SW_INTERFACE_IP6_SET_LINK_LOCAL_ADDRESS, \
5128 sw_interface_ip6_set_link_local_address);
5130 mp->sw_if_index = ntohl (sw_if_index);
5131 clib_memcpy (mp->address, &v6address, sizeof (v6address));
5132 mp->address_length = address_length;
5137 /* Wait for a reply, return good/bad news */
5145 static int api_sw_interface_ip6nd_ra_prefix (vat_main_t * vam)
5147 unformat_input_t * i = vam->input;
5148 vl_api_sw_interface_ip6nd_ra_prefix_t *mp;
5151 u8 sw_if_index_set = 0;
5152 u32 address_length = 0;
5153 u8 v6_address_set = 0;
5154 ip6_address_t v6address;
5156 u8 no_advertise = 0;
5158 u8 no_autoconfig = 0;
5161 u32 val_lifetime = 0;
5162 u32 pref_lifetime = 0;
5164 /* Parse args required to build the message */
5165 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
5166 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
5167 sw_if_index_set = 1;
5168 else if (unformat (i, "sw_if_index %d", &sw_if_index))
5169 sw_if_index_set = 1;
5170 else if (unformat (i, "%U/%d",
5171 unformat_ip6_address, &v6address,
5174 else if (unformat (i, "val_life %d", &val_lifetime))
5176 else if (unformat (i, "pref_life %d", &pref_lifetime))
5178 else if (unformat (i, "def"))
5180 else if (unformat (i, "noadv"))
5182 else if (unformat (i, "offl"))
5184 else if (unformat (i, "noauto"))
5186 else if (unformat (i, "nolink"))
5188 else if (unformat (i, "isno"))
5191 clib_warning ("parse error '%U'", format_unformat_error, i);
5196 if (sw_if_index_set == 0) {
5197 errmsg ("missing interface name or sw_if_index\n");
5200 if (!v6_address_set) {
5201 errmsg ("no address set\n");
5205 /* Construct the API message */
5206 M(SW_INTERFACE_IP6ND_RA_PREFIX, sw_interface_ip6nd_ra_prefix);
5208 mp->sw_if_index = ntohl (sw_if_index);
5209 clib_memcpy (mp->address, &v6address, sizeof (v6address));
5210 mp->address_length = address_length;
5211 mp->use_default = use_default;
5212 mp->no_advertise = no_advertise;
5213 mp->off_link = off_link;
5214 mp->no_autoconfig = no_autoconfig;
5215 mp->no_onlink = no_onlink;
5217 mp->val_lifetime = ntohl(val_lifetime);
5218 mp->pref_lifetime = ntohl(pref_lifetime);
5223 /* Wait for a reply, return good/bad news */
5230 static int api_sw_interface_ip6nd_ra_config (vat_main_t * vam)
5232 unformat_input_t * i = vam->input;
5233 vl_api_sw_interface_ip6nd_ra_config_t *mp;
5236 u8 sw_if_index_set = 0;
5241 u8 send_unicast = 0;
5244 u8 default_router = 0;
5245 u32 max_interval = 0;
5246 u32 min_interval = 0;
5248 u32 initial_count = 0;
5249 u32 initial_interval = 0;
5252 /* Parse args required to build the message */
5253 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
5254 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
5255 sw_if_index_set = 1;
5256 else if (unformat (i, "sw_if_index %d", &sw_if_index))
5257 sw_if_index_set = 1;
5258 else if (unformat (i, "maxint %d", &max_interval))
5260 else if (unformat (i, "minint %d", &min_interval))
5262 else if (unformat (i, "life %d", &lifetime))
5264 else if (unformat (i, "count %d", &initial_count))
5266 else if (unformat (i, "interval %d", &initial_interval))
5268 else if (unformat (i, "surpress"))
5270 else if (unformat (i, "managed"))
5272 else if (unformat (i, "other"))
5274 else if (unformat (i, "ll"))
5276 else if (unformat (i, "send"))
5278 else if (unformat (i, "cease"))
5280 else if (unformat (i, "isno"))
5282 else if (unformat (i, "def"))
5285 clib_warning ("parse error '%U'", format_unformat_error, i);
5290 if (sw_if_index_set == 0) {
5291 errmsg ("missing interface name or sw_if_index\n");
5295 /* Construct the API message */
5296 M(SW_INTERFACE_IP6ND_RA_CONFIG, sw_interface_ip6nd_ra_config);
5298 mp->sw_if_index = ntohl (sw_if_index);
5299 mp->max_interval = ntohl(max_interval);
5300 mp->min_interval = ntohl(min_interval);
5301 mp->lifetime = ntohl(lifetime);
5302 mp->initial_count = ntohl(initial_count);
5303 mp->initial_interval = ntohl(initial_interval);
5304 mp->surpress = surpress;
5305 mp->managed = managed;
5307 mp->ll_option = ll_option;
5308 mp->send_unicast = send_unicast;
5311 mp->default_router = default_router;
5316 /* Wait for a reply, return good/bad news */
5323 static int api_set_arp_neighbor_limit (vat_main_t * vam)
5325 unformat_input_t * i = vam->input;
5326 vl_api_set_arp_neighbor_limit_t *mp;
5332 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
5333 if (unformat (i, "arp_nbr_limit %d", &arp_nbr_limit))
5335 else if (unformat (i, "ipv6"))
5338 clib_warning ("parse error '%U'", format_unformat_error, i);
5343 if (limit_set == 0) {
5344 errmsg ("missing limit value\n");
5348 M(SET_ARP_NEIGHBOR_LIMIT, set_arp_neighbor_limit);
5350 mp->arp_neighbor_limit = ntohl(arp_nbr_limit);
5351 mp->is_ipv6 = is_ipv6;
5358 static int api_l2_patch_add_del (vat_main_t * vam)
5360 unformat_input_t * i = vam->input;
5361 vl_api_l2_patch_add_del_t *mp;
5364 u8 rx_sw_if_index_set = 0;
5366 u8 tx_sw_if_index_set = 0;
5369 /* Parse args required to build the message */
5370 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
5371 if (unformat (i, "rx_sw_if_index %d", &rx_sw_if_index))
5372 rx_sw_if_index_set = 1;
5373 else if (unformat (i, "tx_sw_if_index %d", &tx_sw_if_index))
5374 tx_sw_if_index_set = 1;
5375 else if (unformat (i, "rx")) {
5376 if (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
5377 if (unformat (i, "%U", unformat_sw_if_index, vam,
5379 rx_sw_if_index_set = 1;
5382 } else if (unformat (i, "tx")) {
5383 if (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
5384 if (unformat (i, "%U", unformat_sw_if_index, vam,
5386 tx_sw_if_index_set = 1;
5389 } else if (unformat (i, "del"))
5395 if (rx_sw_if_index_set == 0) {
5396 errmsg ("missing rx interface name or rx_sw_if_index\n");
5400 if (tx_sw_if_index_set == 0) {
5401 errmsg ("missing tx interface name or tx_sw_if_index\n");
5405 M(L2_PATCH_ADD_DEL, l2_patch_add_del);
5407 mp->rx_sw_if_index = ntohl(rx_sw_if_index);
5408 mp->tx_sw_if_index = ntohl(tx_sw_if_index);
5409 mp->is_add = is_add;
5415 static int api_trace_profile_add (vat_main_t *vam)
5417 unformat_input_t * input = vam->input;
5418 vl_api_trace_profile_add_t *mp;
5421 u32 trace_option_elts = 0;
5422 u32 trace_type = 0, node_id = 0, app_data = 0, trace_tsp = 2;
5423 int has_pow_option = 0;
5424 int has_ppc_option = 0;
5426 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
5428 if (unformat (input, "id %d trace-type 0x%x trace-elts %d "
5429 "trace-tsp %d node-id 0x%x app-data 0x%x",
5430 &id, &trace_type, &trace_option_elts, &trace_tsp,
5431 &node_id, &app_data))
5433 else if (unformat (input, "pow"))
5435 else if (unformat (input, "ppc encap"))
5436 has_ppc_option = PPC_ENCAP;
5437 else if (unformat (input, "ppc decap"))
5438 has_ppc_option = PPC_DECAP;
5439 else if (unformat (input, "ppc none"))
5440 has_ppc_option = PPC_NONE;
5444 M(TRACE_PROFILE_ADD, trace_profile_add);
5446 mp->trace_type = trace_type;
5447 mp->trace_num_elt = trace_option_elts;
5448 mp->trace_ppc = has_ppc_option;
5449 mp->trace_app_data = htonl(app_data);
5450 mp->pow_enable = has_pow_option;
5451 mp->trace_tsp = trace_tsp;
5452 mp->node_id = htonl(node_id);
5459 static int api_trace_profile_apply (vat_main_t *vam)
5461 unformat_input_t * input = vam->input;
5462 vl_api_trace_profile_apply_t *mp;
5465 u32 mask_width = ~0;
5472 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
5474 if (unformat (input, "%U/%d",
5475 unformat_ip6_address, &addr, &mask_width))
5477 else if (unformat (input, "id %d", &id))
5479 else if (unformat (input, "vrf-id %d", &vrf_id))
5481 else if (unformat (input, "add"))
5483 else if (unformat (input, "pop"))
5485 else if (unformat (input, "none"))
5491 if ((is_add + is_pop + is_none) != 1) {
5492 errmsg("One of (add, pop, none) required");
5495 if (mask_width == ~0) {
5496 errmsg("<address>/<mask-width> required");
5499 M(TRACE_PROFILE_APPLY, trace_profile_apply);
5500 clib_memcpy(mp->dest_ipv6, &addr, sizeof(mp->dest_ipv6));
5502 mp->prefix_length = htonl(mask_width);
5503 mp->vrf_id = htonl(vrf_id);
5505 mp->trace_op = IOAM_HBYH_ADD;
5507 mp->trace_op = IOAM_HBYH_POP;
5509 mp->trace_op = IOAM_HBYH_MOD;
5521 static int api_trace_profile_del (vat_main_t *vam)
5523 vl_api_trace_profile_del_t *mp;
5526 M(TRACE_PROFILE_DEL, trace_profile_del);
5531 static int api_sr_tunnel_add_del (vat_main_t * vam)
5533 unformat_input_t * i = vam->input;
5534 vl_api_sr_tunnel_add_del_t *mp;
5538 ip6_address_t src_address;
5539 int src_address_set = 0;
5540 ip6_address_t dst_address;
5542 int dst_address_set = 0;
5544 u32 rx_table_id = 0;
5545 u32 tx_table_id = 0;
5546 ip6_address_t * segments = 0;
5547 ip6_address_t * this_seg;
5548 ip6_address_t * tags = 0;
5549 ip6_address_t * this_tag;
5550 ip6_address_t next_address, tag;
5552 u8 * policy_name = 0;
5554 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
5556 if (unformat (i, "del"))
5558 else if (unformat (i, "name %s", &name))
5560 else if (unformat (i, "policy %s", &policy_name))
5562 else if (unformat (i, "rx_fib_id %d", &rx_table_id))
5564 else if (unformat (i, "tx_fib_id %d", &tx_table_id))
5566 else if (unformat (i, "src %U", unformat_ip6_address, &src_address))
5567 src_address_set = 1;
5568 else if (unformat (i, "dst %U/%d",
5569 unformat_ip6_address, &dst_address,
5571 dst_address_set = 1;
5572 else if (unformat (i, "next %U", unformat_ip6_address,
5575 vec_add2 (segments, this_seg, 1);
5576 clib_memcpy (this_seg->as_u8, next_address.as_u8, sizeof (*this_seg));
5578 else if (unformat (i, "tag %U", unformat_ip6_address,
5581 vec_add2 (tags, this_tag, 1);
5582 clib_memcpy (this_tag->as_u8, tag.as_u8, sizeof (*this_tag));
5584 else if (unformat (i, "clean"))
5585 flags |= IP6_SR_HEADER_FLAG_CLEANUP;
5586 else if (unformat (i, "protected"))
5587 flags |= IP6_SR_HEADER_FLAG_PROTECTED;
5588 else if (unformat (i, "InPE %d", &pl_index))
5590 if (pl_index <= 0 || pl_index > 4)
5592 pl_index_range_error:
5593 errmsg ("pl index %d out of range\n", pl_index);
5596 flags |= IP6_SR_HEADER_FLAG_PL_ELT_INGRESS_PE << (3*(pl_index - 1));
5598 else if (unformat (i, "EgPE %d", &pl_index))
5600 if (pl_index <= 0 || pl_index > 4)
5601 goto pl_index_range_error;
5602 flags |= IP6_SR_HEADER_FLAG_PL_ELT_EGRESS_PE << (3*(pl_index - 1));
5604 else if (unformat (i, "OrgSrc %d", &pl_index))
5606 if (pl_index <= 0 || pl_index > 4)
5607 goto pl_index_range_error;
5608 flags |= IP6_SR_HEADER_FLAG_PL_ELT_ORIG_SRC_ADDR << (3*(pl_index - 1));
5614 if (!src_address_set)
5616 errmsg ("src address required\n");
5620 if (!dst_address_set)
5622 errmsg ("dst address required\n");
5628 errmsg ("at least one sr segment required\n");
5632 M2(SR_TUNNEL_ADD_DEL, sr_tunnel_add_del,
5633 vec_len(segments) * sizeof (ip6_address_t)
5634 + vec_len(tags) * sizeof (ip6_address_t));
5636 clib_memcpy (mp->src_address, &src_address, sizeof (mp->src_address));
5637 clib_memcpy (mp->dst_address, &dst_address, sizeof (mp->dst_address));
5638 mp->dst_mask_width = dst_mask_width;
5639 mp->flags_net_byte_order = clib_host_to_net_u16 (flags);
5640 mp->n_segments = vec_len (segments);
5641 mp->n_tags = vec_len (tags);
5642 mp->is_add = is_del == 0;
5643 clib_memcpy (mp->segs_and_tags, segments,
5644 vec_len(segments)* sizeof (ip6_address_t));
5645 clib_memcpy (mp->segs_and_tags + vec_len(segments)*sizeof (ip6_address_t),
5646 tags, vec_len(tags)* sizeof (ip6_address_t));
5648 mp->outer_vrf_id = ntohl (rx_table_id);
5649 mp->inner_vrf_id = ntohl (tx_table_id);
5650 memcpy (mp->name, name, vec_len(name));
5651 memcpy (mp->policy_name, policy_name, vec_len(policy_name));
5653 vec_free (segments);
5660 static int api_sr_policy_add_del (vat_main_t * vam)
5662 unformat_input_t * input = vam->input;
5663 vl_api_sr_policy_add_del_t *mp;
5667 u8 * tunnel_name = 0;
5668 u8 ** tunnel_names = 0;
5673 int tunnel_names_length = 1; // Init to 1 to offset the #tunnel_names counter byte
5674 int tun_name_len = 0; // Different naming convention used as confusing these would be "bad" (TM)
5676 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
5678 if (unformat (input, "del"))
5680 else if (unformat (input, "name %s", &name))
5682 else if (unformat (input, "tunnel %s", &tunnel_name))
5686 vec_add1 (tunnel_names, tunnel_name);
5688 - length = #bytes to store in serial vector
5689 - +1 = byte to store that length
5691 tunnel_names_length += (vec_len (tunnel_name) + 1);
5702 errmsg ("policy name required\n");
5706 if ((!tunnel_set) && (!is_del))
5708 errmsg ("tunnel name required\n");
5712 M2(SR_POLICY_ADD_DEL, sr_policy_add_del, tunnel_names_length);
5716 mp->is_add = !is_del;
5718 memcpy (mp->name, name, vec_len(name));
5719 // Since mp->tunnel_names is of type u8[0] and not a u8 *, u8 ** needs to be serialized
5720 u8 * serial_orig = 0;
5721 vec_validate (serial_orig, tunnel_names_length);
5722 *serial_orig = vec_len(tunnel_names); // Store the number of tunnels as length in first byte of serialized vector
5723 serial_orig += 1; // Move along one byte to store the length of first tunnel_name
5725 for (j=0; j < vec_len(tunnel_names); j++)
5727 tun_name_len = vec_len (tunnel_names[j]);
5728 *serial_orig = tun_name_len; // Store length of tunnel name in first byte of Length/Value pair
5729 serial_orig += 1; // Move along one byte to store the actual tunnel name
5730 memcpy (serial_orig, tunnel_names[j], tun_name_len);
5731 serial_orig += tun_name_len; // Advance past the copy
5733 memcpy (mp->tunnel_names, serial_orig - tunnel_names_length, tunnel_names_length); // Regress serial_orig to head then copy fwd
5735 vec_free (tunnel_names);
5736 vec_free (tunnel_name);
5742 static int api_sr_multicast_map_add_del (vat_main_t * vam)
5744 unformat_input_t * input = vam->input;
5745 vl_api_sr_multicast_map_add_del_t *mp;
5748 ip6_address_t multicast_address;
5749 u8 * policy_name = 0;
5750 int multicast_address_set = 0;
5752 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
5754 if (unformat (input, "del"))
5756 else if (unformat (input, "address %U", unformat_ip6_address, &multicast_address))
5757 multicast_address_set = 1;
5758 else if (unformat (input, "sr-policy %s", &policy_name))
5764 if (!is_del && !policy_name)
5766 errmsg ("sr-policy name required\n");
5771 if (!multicast_address_set)
5773 errmsg ("address required\n");
5777 M(SR_MULTICAST_MAP_ADD_DEL, sr_multicast_map_add_del);
5779 mp->is_add = !is_del;
5780 memcpy (mp->policy_name, policy_name, vec_len(policy_name));
5781 clib_memcpy (mp->multicast_address, &multicast_address, sizeof (mp->multicast_address));
5784 vec_free (policy_name);
5791 #define foreach_ip4_proto_field \
5801 uword unformat_ip4_mask (unformat_input_t * input, va_list * args)
5803 u8 ** maskp = va_arg (*args, u8 **);
5805 u8 found_something = 0;
5808 #define _(a) u8 a=0;
5809 foreach_ip4_proto_field;
5815 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
5817 if (unformat (input, "version"))
5819 else if (unformat (input, "hdr_length"))
5821 else if (unformat (input, "src"))
5823 else if (unformat (input, "dst"))
5825 else if (unformat (input, "proto"))
5828 #define _(a) else if (unformat (input, #a)) a=1;
5829 foreach_ip4_proto_field
5835 #define _(a) found_something += a;
5836 foreach_ip4_proto_field;
5839 if (found_something == 0)
5842 vec_validate (mask, sizeof (*ip) - 1);
5844 ip = (ip4_header_t *) mask;
5846 #define _(a) if (a) memset (&ip->a, 0xff, sizeof (ip->a));
5847 foreach_ip4_proto_field;
5850 ip->ip_version_and_header_length = 0;
5853 ip->ip_version_and_header_length |= 0xF0;
5856 ip->ip_version_and_header_length |= 0x0F;
5862 #define foreach_ip6_proto_field \
5869 uword unformat_ip6_mask (unformat_input_t * input, va_list * args)
5871 u8 ** maskp = va_arg (*args, u8 **);
5873 u8 found_something = 0;
5875 u32 ip_version_traffic_class_and_flow_label;
5877 #define _(a) u8 a=0;
5878 foreach_ip6_proto_field;
5881 u8 traffic_class = 0;
5884 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
5886 if (unformat (input, "version"))
5888 else if (unformat (input, "traffic-class"))
5890 else if (unformat (input, "flow-label"))
5892 else if (unformat (input, "src"))
5894 else if (unformat (input, "dst"))
5896 else if (unformat (input, "proto"))
5899 #define _(a) else if (unformat (input, #a)) a=1;
5900 foreach_ip6_proto_field
5906 #define _(a) found_something += a;
5907 foreach_ip6_proto_field;
5910 if (found_something == 0)
5913 vec_validate (mask, sizeof (*ip) - 1);
5915 ip = (ip6_header_t *) mask;
5917 #define _(a) if (a) memset (&ip->a, 0xff, sizeof (ip->a));
5918 foreach_ip6_proto_field;
5921 ip_version_traffic_class_and_flow_label = 0;
5924 ip_version_traffic_class_and_flow_label |= 0xF0000000;
5927 ip_version_traffic_class_and_flow_label |= 0x0FF00000;
5930 ip_version_traffic_class_and_flow_label |= 0x000FFFFF;
5932 ip->ip_version_traffic_class_and_flow_label =
5933 clib_host_to_net_u32 (ip_version_traffic_class_and_flow_label);
5939 uword unformat_l3_mask (unformat_input_t * input, va_list * args)
5941 u8 ** maskp = va_arg (*args, u8 **);
5943 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) {
5944 if (unformat (input, "ip4 %U", unformat_ip4_mask, maskp))
5946 else if (unformat (input, "ip6 %U", unformat_ip6_mask, maskp))
5954 uword unformat_l2_mask (unformat_input_t * input, va_list * args)
5956 u8 ** maskp = va_arg (*args, u8 **);
5971 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) {
5972 if (unformat (input, "src"))
5974 else if (unformat (input, "dst"))
5976 else if (unformat (input, "proto"))
5978 else if (unformat (input, "tag1"))
5980 else if (unformat (input, "tag2"))
5982 else if (unformat (input, "ignore-tag1"))
5984 else if (unformat (input, "ignore-tag2"))
5986 else if (unformat (input, "cos1"))
5988 else if (unformat (input, "cos2"))
5990 else if (unformat (input, "dot1q"))
5992 else if (unformat (input, "dot1ad"))
5997 if ((src + dst + proto + tag1 + tag2 + dot1q + dot1ad +
5998 ignore_tag1 + ignore_tag2 + cos1 + cos2) == 0)
6001 if (tag1 || ignore_tag1 || cos1 || dot1q)
6003 if (tag2 || ignore_tag2 || cos2 || dot1ad)
6006 vec_validate (mask, len-1);
6009 memset (mask, 0xff, 6);
6012 memset (mask + 6, 0xff, 6);
6016 /* inner vlan tag */
6025 mask[21] = mask [20] = 0xff;
6046 mask[16] = mask [17] = 0xff;
6056 mask[12] = mask [13] = 0xff;
6062 uword unformat_classify_mask (unformat_input_t * input, va_list * args)
6064 u8 ** maskp = va_arg (*args, u8 **);
6065 u32 * skipp = va_arg (*args, u32 *);
6066 u32 * matchp = va_arg (*args, u32 *);
6073 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) {
6074 if (unformat (input, "hex %U", unformat_hex_string, &mask))
6076 else if (unformat (input, "l2 %U", unformat_l2_mask, &l2))
6078 else if (unformat (input, "l3 %U", unformat_l3_mask, &l3))
6084 if (mask || l2 || l3)
6088 /* "With a free Ethernet header in every package" */
6090 vec_validate (l2, 13);
6092 vec_append (mask, l3);
6096 /* Scan forward looking for the first significant mask octet */
6097 for (i = 0; i < vec_len (mask); i++)
6101 /* compute (skip, match) params */
6102 *skipp = i / sizeof(u32x4);
6103 vec_delete (mask, *skipp * sizeof(u32x4), 0);
6105 /* Pad mask to an even multiple of the vector size */
6106 while (vec_len (mask) % sizeof (u32x4))
6109 match = vec_len (mask) / sizeof (u32x4);
6111 for (i = match*sizeof(u32x4); i > 0; i-= sizeof(u32x4))
6113 u64 *tmp = (u64 *)(mask + (i-sizeof(u32x4)));
6114 if (*tmp || *(tmp+1))
6119 clib_warning ("BUG: match 0");
6121 _vec_len (mask) = match * sizeof(u32x4);
6132 #define foreach_l2_next \
6134 _(ethernet, ETHERNET_INPUT) \
6138 uword unformat_l2_next_index (unformat_input_t * input, va_list * args)
6140 u32 * miss_next_indexp = va_arg (*args, u32 *);
6145 if (unformat (input, #n)) { next_index = L2_CLASSIFY_NEXT_##N; goto out;}
6149 if (unformat (input, "%d", &tmp))
6158 *miss_next_indexp = next_index;
6162 #define foreach_ip_next \
6168 uword unformat_ip_next_index (unformat_input_t * input, va_list * args)
6170 u32 * miss_next_indexp = va_arg (*args, u32 *);
6175 if (unformat (input, #n)) { next_index = IP_LOOKUP_NEXT_##N; goto out;}
6179 if (unformat (input, "%d", &tmp))
6188 *miss_next_indexp = next_index;
6192 #define foreach_acl_next \
6195 uword unformat_acl_next_index (unformat_input_t * input, va_list * args)
6197 u32 * miss_next_indexp = va_arg (*args, u32 *);
6202 if (unformat (input, #n)) { next_index = ACL_NEXT_INDEX_##N; goto out;}
6206 if (unformat (input, "permit"))
6211 else if (unformat (input, "%d", &tmp))
6220 *miss_next_indexp = next_index;
6224 static int api_classify_add_del_table (vat_main_t * vam)
6226 unformat_input_t * i = vam->input;
6227 vl_api_classify_add_del_table_t *mp;
6233 u32 table_index = ~0;
6234 u32 next_table_index = ~0;
6235 u32 miss_next_index = ~0;
6236 u32 memory_size = 32<<20;
6240 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
6241 if (unformat (i, "del"))
6243 else if (unformat (i, "buckets %d", &nbuckets))
6245 else if (unformat (i, "memory_size %d", &memory_size))
6247 else if (unformat (i, "skip %d", &skip))
6249 else if (unformat (i, "match %d", &match))
6251 else if (unformat (i, "table %d", &table_index))
6253 else if (unformat (i, "mask %U", unformat_classify_mask,
6254 &mask, &skip, &match))
6256 else if (unformat (i, "next-table %d", &next_table_index))
6258 else if (unformat (i, "miss-next %U", unformat_ip_next_index,
6261 else if (unformat (i, "l2-miss-next %U", unformat_l2_next_index,
6264 else if (unformat (i, "acl-miss-next %U", unformat_acl_next_index,
6271 if (is_add && mask == 0) {
6272 errmsg ("Mask required\n");
6276 if (is_add && skip == ~0) {
6277 errmsg ("skip count required\n");
6281 if (is_add && match == ~0) {
6282 errmsg ("match count required\n");
6286 if (!is_add && table_index == ~0) {
6287 errmsg ("table index required for delete\n");
6291 M2 (CLASSIFY_ADD_DEL_TABLE, classify_add_del_table,
6294 mp->is_add = is_add;
6295 mp->table_index = ntohl(table_index);
6296 mp->nbuckets = ntohl(nbuckets);
6297 mp->memory_size = ntohl(memory_size);
6298 mp->skip_n_vectors = ntohl(skip);
6299 mp->match_n_vectors = ntohl(match);
6300 mp->next_table_index = ntohl(next_table_index);
6301 mp->miss_next_index = ntohl(miss_next_index);
6302 clib_memcpy (mp->mask, mask, vec_len(mask));
6310 uword unformat_ip4_match (unformat_input_t * input, va_list * args)
6312 u8 ** matchp = va_arg (*args, u8 **);
6319 int src = 0, dst = 0;
6320 ip4_address_t src_val, dst_val;
6327 int fragment_id = 0;
6328 u32 fragment_id_val;
6334 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
6336 if (unformat (input, "version %d", &version_val))
6338 else if (unformat (input, "hdr_length %d", &hdr_length_val))
6340 else if (unformat (input, "src %U", unformat_ip4_address, &src_val))
6342 else if (unformat (input, "dst %U", unformat_ip4_address, &dst_val))
6344 else if (unformat (input, "proto %d", &proto_val))
6346 else if (unformat (input, "tos %d", &tos_val))
6348 else if (unformat (input, "length %d", &length_val))
6350 else if (unformat (input, "fragment_id %d", &fragment_id_val))
6352 else if (unformat (input, "ttl %d", &ttl_val))
6354 else if (unformat (input, "checksum %d", &checksum_val))
6360 if (version + hdr_length + src + dst + proto + tos + length + fragment_id
6361 + ttl + checksum == 0)
6365 * Aligned because we use the real comparison functions
6367 vec_validate_aligned (match, sizeof (*ip) - 1, sizeof(u32x4));
6369 ip = (ip4_header_t *) match;
6371 /* These are realistically matched in practice */
6373 ip->src_address.as_u32 = src_val.as_u32;
6376 ip->dst_address.as_u32 = dst_val.as_u32;
6379 ip->protocol = proto_val;
6382 /* These are not, but they're included for completeness */
6384 ip->ip_version_and_header_length |= (version_val & 0xF)<<4;
6387 ip->ip_version_and_header_length |= (hdr_length_val & 0xF);
6393 ip->length = length_val;
6399 ip->checksum = checksum_val;
6405 uword unformat_ip6_match (unformat_input_t * input, va_list * args)
6407 u8 ** matchp = va_arg (*args, u8 **);
6413 u32 traffic_class_val;
6416 int src = 0, dst = 0;
6417 ip6_address_t src_val, dst_val;
6420 int payload_length = 0;
6421 u32 payload_length_val;
6424 u32 ip_version_traffic_class_and_flow_label;
6426 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
6428 if (unformat (input, "version %d", &version_val))
6430 else if (unformat (input, "traffic_class %d", &traffic_class_val))
6432 else if (unformat (input, "flow_label %d", &flow_label_val))
6434 else if (unformat (input, "src %U", unformat_ip6_address, &src_val))
6436 else if (unformat (input, "dst %U", unformat_ip6_address, &dst_val))
6438 else if (unformat (input, "proto %d", &proto_val))
6440 else if (unformat (input, "payload_length %d", &payload_length_val))
6442 else if (unformat (input, "hop_limit %d", &hop_limit_val))
6448 if (version + traffic_class + flow_label + src + dst + proto +
6449 payload_length + hop_limit == 0)
6453 * Aligned because we use the real comparison functions
6455 vec_validate_aligned (match, sizeof (*ip) - 1, sizeof(u32x4));
6457 ip = (ip6_header_t *) match;
6460 clib_memcpy (&ip->src_address, &src_val, sizeof (ip->src_address));
6463 clib_memcpy (&ip->dst_address, &dst_val, sizeof (ip->dst_address));
6466 ip->protocol = proto_val;
6468 ip_version_traffic_class_and_flow_label = 0;
6471 ip_version_traffic_class_and_flow_label |= (version_val & 0xF) << 28;
6474 ip_version_traffic_class_and_flow_label |= (traffic_class_val & 0xFF) << 20;
6477 ip_version_traffic_class_and_flow_label |= (flow_label_val & 0xFFFFF);
6479 ip->ip_version_traffic_class_and_flow_label =
6480 clib_host_to_net_u32 (ip_version_traffic_class_and_flow_label);
6483 ip->payload_length = clib_host_to_net_u16 (payload_length_val);
6486 ip->hop_limit = hop_limit_val;
6492 uword unformat_l3_match (unformat_input_t * input, va_list * args)
6494 u8 ** matchp = va_arg (*args, u8 **);
6496 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) {
6497 if (unformat (input, "ip4 %U", unformat_ip4_match, matchp))
6499 else if (unformat (input, "ip6 %U", unformat_ip6_match, matchp))
6507 uword unformat_vlan_tag (unformat_input_t * input, va_list * args)
6509 u8 * tagp = va_arg (*args, u8 *);
6512 if (unformat(input, "%d", &tag))
6514 tagp[0] = (tag>>8) & 0x0F;
6515 tagp[1] = tag & 0xFF;
6522 uword unformat_l2_match (unformat_input_t * input, va_list * args)
6524 u8 ** matchp = va_arg (*args, u8 **);
6544 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) {
6545 if (unformat (input, "src %U", unformat_ethernet_address, &src_val))
6547 else if (unformat (input, "dst %U", unformat_ethernet_address, &dst_val))
6549 else if (unformat (input, "proto %U",
6550 unformat_ethernet_type_host_byte_order, &proto_val))
6552 else if (unformat (input, "tag1 %U", unformat_vlan_tag, tag1_val))
6554 else if (unformat (input, "tag2 %U", unformat_vlan_tag, tag2_val))
6556 else if (unformat (input, "ignore-tag1"))
6558 else if (unformat (input, "ignore-tag2"))
6560 else if (unformat (input, "cos1 %d", &cos1_val))
6562 else if (unformat (input, "cos2 %d", &cos2_val))
6567 if ((src + dst + proto + tag1 + tag2 +
6568 ignore_tag1 + ignore_tag2 + cos1 + cos2) == 0)
6571 if (tag1 || ignore_tag1 || cos1)
6573 if (tag2 || ignore_tag2 || cos2)
6576 vec_validate_aligned (match, len-1, sizeof(u32x4));
6579 clib_memcpy (match, dst_val, 6);
6582 clib_memcpy (match + 6, src_val, 6);
6586 /* inner vlan tag */
6587 match[19] = tag2_val[1];
6588 match[18] = tag2_val[0];
6590 match [18] |= (cos2_val & 0x7) << 5;
6593 match[21] = proto_val & 0xff;
6594 match[20] = proto_val >> 8;
6598 match [15] = tag1_val[1];
6599 match [14] = tag1_val[0];
6602 match [14] |= (cos1_val & 0x7) << 5;
6608 match [15] = tag1_val[1];
6609 match [14] = tag1_val[0];
6612 match[17] = proto_val & 0xff;
6613 match[16] = proto_val >> 8;
6616 match [14] |= (cos1_val & 0x7) << 5;
6622 match [18] |= (cos2_val & 0x7) << 5;
6624 match [14] |= (cos1_val & 0x7) << 5;
6627 match[13] = proto_val & 0xff;
6628 match[12] = proto_val >> 8;
6636 uword unformat_classify_match (unformat_input_t * input, va_list * args)
6638 u8 ** matchp = va_arg (*args, u8 **);
6639 u32 skip_n_vectors = va_arg (*args, u32);
6640 u32 match_n_vectors = va_arg (*args, u32);
6646 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) {
6647 if (unformat (input, "hex %U", unformat_hex_string, &match))
6649 else if (unformat (input, "l2 %U", unformat_l2_match, &l2))
6651 else if (unformat (input, "l3 %U", unformat_l3_match, &l3))
6657 if (match || l2 || l3)
6661 /* "Win a free Ethernet header in every packet" */
6663 vec_validate_aligned (l2, 13, sizeof(u32x4));
6665 vec_append_aligned (match, l3, sizeof(u32x4));
6669 /* Make sure the vector is big enough even if key is all 0's */
6670 vec_validate_aligned
6671 (match, ((match_n_vectors + skip_n_vectors) * sizeof(u32x4)) - 1,
6674 /* Set size, include skipped vectors*/
6675 _vec_len (match) = (match_n_vectors+skip_n_vectors) * sizeof(u32x4);
6685 static int api_classify_add_del_session (vat_main_t * vam)
6687 unformat_input_t * i = vam->input;
6688 vl_api_classify_add_del_session_t *mp;
6690 u32 table_index = ~0;
6691 u32 hit_next_index = ~0;
6692 u32 opaque_index = ~0;
6696 u32 skip_n_vectors = 0;
6697 u32 match_n_vectors = 0;
6700 * Warning: you have to supply skip_n and match_n
6701 * because the API client cant simply look at the classify
6705 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
6706 if (unformat (i, "del"))
6708 else if (unformat (i, "hit-next %U", unformat_ip_next_index,
6711 else if (unformat (i, "l2-hit-next %U", unformat_l2_next_index,
6714 else if (unformat (i, "acl-hit-next %U", unformat_acl_next_index,
6717 else if (unformat (i, "opaque-index %d", &opaque_index))
6719 else if (unformat (i, "skip_n %d", &skip_n_vectors))
6721 else if (unformat (i, "match_n %d", &match_n_vectors))
6723 else if (unformat (i, "match %U", unformat_classify_match,
6724 &match, skip_n_vectors, match_n_vectors))
6726 else if (unformat (i, "advance %d", &advance))
6728 else if (unformat (i, "table-index %d", &table_index))
6734 if (table_index == ~0) {
6735 errmsg ("Table index required\n");
6739 if (is_add && match == 0) {
6740 errmsg ("Match value required\n");
6744 M2 (CLASSIFY_ADD_DEL_SESSION, classify_add_del_session,
6747 mp->is_add = is_add;
6748 mp->table_index = ntohl(table_index);
6749 mp->hit_next_index = ntohl(hit_next_index);
6750 mp->opaque_index = ntohl(opaque_index);
6751 mp->advance = ntohl(advance);
6752 clib_memcpy (mp->match, match, vec_len(match));
6759 static int api_classify_set_interface_ip_table (vat_main_t * vam)
6761 unformat_input_t * i = vam->input;
6762 vl_api_classify_set_interface_ip_table_t *mp;
6765 int sw_if_index_set;
6766 u32 table_index = ~0;
6769 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
6770 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
6771 sw_if_index_set = 1;
6772 else if (unformat (i, "sw_if_index %d", &sw_if_index))
6773 sw_if_index_set = 1;
6774 else if (unformat (i, "table %d", &table_index))
6777 clib_warning ("parse error '%U'", format_unformat_error, i);
6782 if (sw_if_index_set == 0) {
6783 errmsg ("missing interface name or sw_if_index\n");
6788 M(CLASSIFY_SET_INTERFACE_IP_TABLE, classify_set_interface_ip_table);
6790 mp->sw_if_index = ntohl(sw_if_index);
6791 mp->table_index = ntohl(table_index);
6792 mp->is_ipv6 = is_ipv6;
6799 static int api_classify_set_interface_l2_tables (vat_main_t * vam)
6801 unformat_input_t * i = vam->input;
6802 vl_api_classify_set_interface_l2_tables_t *mp;
6805 int sw_if_index_set;
6806 u32 ip4_table_index = ~0;
6807 u32 ip6_table_index = ~0;
6808 u32 other_table_index = ~0;
6810 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
6811 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
6812 sw_if_index_set = 1;
6813 else if (unformat (i, "sw_if_index %d", &sw_if_index))
6814 sw_if_index_set = 1;
6815 else if (unformat (i, "ip4-table %d", &ip4_table_index))
6817 else if (unformat (i, "ip6-table %d", &ip6_table_index))
6819 else if (unformat (i, "other-table %d", &other_table_index))
6822 clib_warning ("parse error '%U'", format_unformat_error, i);
6827 if (sw_if_index_set == 0) {
6828 errmsg ("missing interface name or sw_if_index\n");
6833 M(CLASSIFY_SET_INTERFACE_L2_TABLES, classify_set_interface_l2_tables);
6835 mp->sw_if_index = ntohl(sw_if_index);
6836 mp->ip4_table_index = ntohl(ip4_table_index);
6837 mp->ip6_table_index = ntohl(ip6_table_index);
6838 mp->other_table_index = ntohl(other_table_index);
6846 static int api_get_node_index (vat_main_t * vam)
6848 unformat_input_t * i = vam->input;
6849 vl_api_get_node_index_t * mp;
6853 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
6854 if (unformat (i, "node %s", &name))
6860 errmsg ("node name required\n");
6863 if (vec_len (name) >= ARRAY_LEN(mp->node_name)) {
6864 errmsg ("node name too long, max %d\n", ARRAY_LEN(mp->node_name));
6868 M(GET_NODE_INDEX, get_node_index);
6869 clib_memcpy (mp->node_name, name, vec_len(name));
6877 static int api_add_node_next (vat_main_t * vam)
6879 unformat_input_t * i = vam->input;
6880 vl_api_add_node_next_t * mp;
6885 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
6886 if (unformat (i, "node %s", &name))
6888 else if (unformat (i, "next %s", &next))
6894 errmsg ("node name required\n");
6897 if (vec_len (name) >= ARRAY_LEN(mp->node_name)) {
6898 errmsg ("node name too long, max %d\n", ARRAY_LEN(mp->node_name));
6902 errmsg ("next node required\n");
6905 if (vec_len (next) >= ARRAY_LEN(mp->next_name)) {
6906 errmsg ("next name too long, max %d\n", ARRAY_LEN(mp->next_name));
6910 M(ADD_NODE_NEXT, add_node_next);
6911 clib_memcpy (mp->node_name, name, vec_len(name));
6912 clib_memcpy (mp->next_name, next, vec_len(next));
6921 static int api_l2tpv3_create_tunnel (vat_main_t * vam)
6923 unformat_input_t * i = vam->input;
6924 ip6_address_t client_address, our_address;
6925 int client_address_set = 0;
6926 int our_address_set = 0;
6927 u32 local_session_id = 0;
6928 u32 remote_session_id = 0;
6929 u64 local_cookie = 0;
6930 u64 remote_cookie = 0;
6931 u8 l2_sublayer_present = 0;
6932 vl_api_l2tpv3_create_tunnel_t * mp;
6935 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
6936 if (unformat (i, "client_address %U", unformat_ip6_address,
6938 client_address_set = 1;
6939 else if (unformat (i, "our_address %U", unformat_ip6_address,
6941 our_address_set = 1;
6942 else if (unformat (i, "local_session_id %d", &local_session_id))
6944 else if (unformat (i, "remote_session_id %d", &remote_session_id))
6946 else if (unformat (i, "local_cookie %lld", &local_cookie))
6948 else if (unformat (i, "remote_cookie %lld", &remote_cookie))
6950 else if (unformat (i, "l2-sublayer-present"))
6951 l2_sublayer_present = 1;
6956 if (client_address_set == 0) {
6957 errmsg ("client_address required\n");
6961 if (our_address_set == 0) {
6962 errmsg ("our_address required\n");
6966 M(L2TPV3_CREATE_TUNNEL, l2tpv3_create_tunnel);
6968 clib_memcpy (mp->client_address, client_address.as_u8,
6969 sizeof (mp->client_address));
6971 clib_memcpy (mp->our_address, our_address.as_u8,
6972 sizeof (mp->our_address));
6974 mp->local_session_id = ntohl (local_session_id);
6975 mp->remote_session_id = ntohl (remote_session_id);
6976 mp->local_cookie = clib_host_to_net_u64 (local_cookie);
6977 mp->remote_cookie = clib_host_to_net_u64 (remote_cookie);
6978 mp->l2_sublayer_present = l2_sublayer_present;
6986 static int api_l2tpv3_set_tunnel_cookies (vat_main_t * vam)
6988 unformat_input_t * i = vam->input;
6990 u8 sw_if_index_set = 0;
6991 u64 new_local_cookie = 0;
6992 u64 new_remote_cookie = 0;
6993 vl_api_l2tpv3_set_tunnel_cookies_t *mp;
6996 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
6997 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
6998 sw_if_index_set = 1;
6999 else if (unformat (i, "sw_if_index %d", &sw_if_index))
7000 sw_if_index_set = 1;
7001 else if (unformat (i, "new_local_cookie %lld", &new_local_cookie))
7003 else if (unformat (i, "new_remote_cookie %lld", &new_remote_cookie))
7009 if (sw_if_index_set == 0) {
7010 errmsg ("missing interface name or sw_if_index\n");
7014 M(L2TPV3_SET_TUNNEL_COOKIES, l2tpv3_set_tunnel_cookies);
7016 mp->sw_if_index = ntohl(sw_if_index);
7017 mp->new_local_cookie = clib_host_to_net_u64 (new_local_cookie);
7018 mp->new_remote_cookie = clib_host_to_net_u64 (new_remote_cookie);
7025 static int api_l2tpv3_interface_enable_disable (vat_main_t * vam)
7027 unformat_input_t * i = vam->input;
7028 vl_api_l2tpv3_interface_enable_disable_t *mp;
7031 u8 sw_if_index_set = 0;
7032 u8 enable_disable = 1;
7034 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
7035 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
7036 sw_if_index_set = 1;
7037 else if (unformat (i, "sw_if_index %d", &sw_if_index))
7038 sw_if_index_set = 1;
7039 else if (unformat (i, "enable"))
7041 else if (unformat (i, "disable"))
7047 if (sw_if_index_set == 0) {
7048 errmsg ("missing interface name or sw_if_index\n");
7052 M(L2TPV3_INTERFACE_ENABLE_DISABLE, l2tpv3_interface_enable_disable);
7054 mp->sw_if_index = ntohl(sw_if_index);
7055 mp->enable_disable = enable_disable;
7062 static int api_l2tpv3_set_lookup_key (vat_main_t * vam)
7064 unformat_input_t * i = vam->input;
7065 vl_api_l2tpv3_set_lookup_key_t * mp;
7069 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
7070 if (unformat (i, "lookup_v6_src"))
7071 key = L2T_LOOKUP_SRC_ADDRESS;
7072 else if (unformat (i, "lookup_v6_dst"))
7073 key = L2T_LOOKUP_DST_ADDRESS;
7074 else if (unformat (i, "lookup_session_id"))
7075 key = L2T_LOOKUP_SESSION_ID;
7080 if (key == (u8) ~0) {
7081 errmsg ("l2tp session lookup key unset\n");
7085 M(L2TPV3_SET_LOOKUP_KEY, l2tpv3_set_lookup_key);
7094 static void vl_api_sw_if_l2tpv3_tunnel_details_t_handler
7095 (vl_api_sw_if_l2tpv3_tunnel_details_t * mp)
7097 vat_main_t * vam = &vat_main;
7099 fformat(vam->ofp, "* %U (our) %U (client) (sw_if_index %d)\n",
7100 format_ip6_address, mp->our_address,
7101 format_ip6_address, mp->client_address,
7102 clib_net_to_host_u32(mp->sw_if_index));
7104 fformat (vam->ofp, " local cookies %016llx %016llx remote cookie %016llx\n",
7105 clib_net_to_host_u64 (mp->local_cookie[0]),
7106 clib_net_to_host_u64 (mp->local_cookie[1]),
7107 clib_net_to_host_u64 (mp->remote_cookie));
7109 fformat (vam->ofp, " local session-id %d remote session-id %d\n",
7110 clib_net_to_host_u32 (mp->local_session_id),
7111 clib_net_to_host_u32 (mp->remote_session_id));
7113 fformat (vam->ofp, " l2 specific sublayer %s\n\n",
7114 mp->l2_sublayer_present ? "preset" : "absent");
7118 static void vl_api_sw_if_l2tpv3_tunnel_details_t_handler_json
7119 (vl_api_sw_if_l2tpv3_tunnel_details_t * mp)
7121 vat_main_t * vam = &vat_main;
7122 vat_json_node_t *node = NULL;
7123 struct in6_addr addr;
7125 if (VAT_JSON_ARRAY != vam->json_tree.type) {
7126 ASSERT(VAT_JSON_NONE == vam->json_tree.type);
7127 vat_json_init_array(&vam->json_tree);
7129 node = vat_json_array_add(&vam->json_tree);
7131 vat_json_init_object(node);
7133 clib_memcpy(&addr, mp->our_address, sizeof(addr));
7134 vat_json_object_add_ip6(node, "our_address", addr);
7135 clib_memcpy(&addr, mp->client_address, sizeof(addr));
7136 vat_json_object_add_ip6(node, "client_address", addr);
7138 vat_json_node_t * lc = vat_json_object_add(node, "local_cookie");
7139 vat_json_init_array(lc);
7140 vat_json_array_add_uint(lc, clib_net_to_host_u64(mp->local_cookie[0]));
7141 vat_json_array_add_uint(lc, clib_net_to_host_u64(mp->local_cookie[1]));
7142 vat_json_object_add_uint(node, "remote_cookie", clib_net_to_host_u64(mp->remote_cookie));
7144 printf("local id: %u", clib_net_to_host_u32(mp->local_session_id));
7145 vat_json_object_add_uint(node, "local_session_id", clib_net_to_host_u32(mp->local_session_id));
7146 vat_json_object_add_uint(node, "remote_session_id", clib_net_to_host_u32(mp->remote_session_id));
7147 vat_json_object_add_string_copy(node, "l2_sublayer", mp->l2_sublayer_present ?
7148 (u8*)"present" : (u8*)"absent");
7151 static int api_sw_if_l2tpv3_tunnel_dump (vat_main_t * vam)
7153 vl_api_sw_if_l2tpv3_tunnel_dump_t *mp;
7156 /* Get list of l2tpv3-tunnel interfaces */
7157 M(SW_IF_L2TPV3_TUNNEL_DUMP, sw_if_l2tpv3_tunnel_dump);
7160 /* Use a control ping for synchronization */
7162 vl_api_control_ping_t * mp;
7163 M(CONTROL_PING, control_ping);
7170 static void vl_api_sw_interface_tap_details_t_handler
7171 (vl_api_sw_interface_tap_details_t * mp)
7173 vat_main_t * vam = &vat_main;
7175 fformat(vam->ofp, "%-16s %d\n",
7177 clib_net_to_host_u32(mp->sw_if_index));
7180 static void vl_api_sw_interface_tap_details_t_handler_json
7181 (vl_api_sw_interface_tap_details_t * mp)
7183 vat_main_t * vam = &vat_main;
7184 vat_json_node_t *node = NULL;
7186 if (VAT_JSON_ARRAY != vam->json_tree.type) {
7187 ASSERT(VAT_JSON_NONE == vam->json_tree.type);
7188 vat_json_init_array(&vam->json_tree);
7190 node = vat_json_array_add(&vam->json_tree);
7192 vat_json_init_object(node);
7193 vat_json_object_add_uint(node, "sw_if_index", ntohl(mp->sw_if_index));
7194 vat_json_object_add_string_copy(node, "dev_name", mp->dev_name);
7197 static int api_sw_interface_tap_dump (vat_main_t * vam)
7199 vl_api_sw_interface_tap_dump_t *mp;
7202 fformat(vam->ofp, "\n%-16s %s\n", "dev_name", "sw_if_index");
7203 /* Get list of tap interfaces */
7204 M(SW_INTERFACE_TAP_DUMP, sw_interface_tap_dump);
7207 /* Use a control ping for synchronization */
7209 vl_api_control_ping_t * mp;
7210 M(CONTROL_PING, control_ping);
7216 static uword unformat_vxlan_decap_next
7217 (unformat_input_t * input, va_list * args)
7219 u32 * result = va_arg (*args, u32 *);
7222 if (unformat (input, "drop"))
7223 *result = VXLAN_INPUT_NEXT_DROP;
7224 else if (unformat (input, "ip4"))
7225 *result = VXLAN_INPUT_NEXT_IP4_INPUT;
7226 else if (unformat (input, "ip6"))
7227 *result = VXLAN_INPUT_NEXT_IP6_INPUT;
7228 else if (unformat (input, "l2"))
7229 *result = VXLAN_INPUT_NEXT_L2_INPUT;
7230 else if (unformat (input, "%d", &tmp))
7237 static int api_vxlan_add_del_tunnel (vat_main_t * vam)
7239 unformat_input_t * line_input = vam->input;
7240 vl_api_vxlan_add_del_tunnel_t *mp;
7242 ip4_address_t src4, dst4;
7243 ip6_address_t src6, dst6;
7245 u8 ipv4_set = 0, ipv6_set = 0;
7248 u32 encap_vrf_id = 0;
7249 u32 decap_next_index = ~0;
7252 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) {
7253 if (unformat (line_input, "del"))
7255 else if (unformat (line_input, "src %U",
7256 unformat_ip4_address, &src4))
7261 else if (unformat (line_input, "dst %U",
7262 unformat_ip4_address, &dst4))
7267 else if (unformat (line_input, "src %U",
7268 unformat_ip6_address, &src6))
7273 else if (unformat (line_input, "dst %U",
7274 unformat_ip6_address, &dst6))
7279 else if (unformat (line_input, "encap-vrf-id %d", &encap_vrf_id))
7281 else if (unformat (line_input, "decap-next %U",
7282 unformat_vxlan_decap_next, &decap_next_index))
7284 else if (unformat (line_input, "vni %d", &vni))
7287 errmsg ("parse error '%U'\n", format_unformat_error, line_input);
7293 errmsg ("tunnel src address not specified\n");
7297 errmsg ("tunnel dst address not specified\n");
7301 if (ipv4_set && ipv6_set) {
7302 errmsg ("both IPv4 and IPv6 addresses specified");
7306 if ((vni == 0) || (vni>>24)) {
7307 errmsg ("vni not specified or out of range\n");
7311 M (VXLAN_ADD_DEL_TUNNEL, vxlan_add_del_tunnel);
7314 clib_memcpy(&mp->dst_address, &src6, sizeof(src6));
7315 clib_memcpy(&mp->dst_address, &src6, sizeof(dst6));
7317 clib_memcpy(&mp->src_address, &src4, sizeof(src4));
7318 clib_memcpy(&mp->dst_address, &dst4, sizeof(dst4));
7320 mp->encap_vrf_id = ntohl(encap_vrf_id);
7321 mp->decap_next_index = ntohl(decap_next_index);
7322 mp->vni = ntohl(vni);
7323 mp->is_add = is_add;
7324 mp->is_ipv6 = ipv6_set;
7331 static void vl_api_vxlan_tunnel_details_t_handler
7332 (vl_api_vxlan_tunnel_details_t * mp)
7334 vat_main_t * vam = &vat_main;
7336 fformat(vam->ofp, "%11d%24U%24U%14d%18d%13d\n",
7337 ntohl(mp->sw_if_index),
7338 format_ip46_address, &(mp->src_address[0]),
7339 format_ip46_address, &(mp->dst_address[0]),
7340 ntohl(mp->encap_vrf_id),
7341 ntohl(mp->decap_next_index),
7345 static void vl_api_vxlan_tunnel_details_t_handler_json
7346 (vl_api_vxlan_tunnel_details_t * mp)
7348 vat_main_t * vam = &vat_main;
7349 vat_json_node_t *node = NULL;
7351 struct in6_addr ip6;
7353 if (VAT_JSON_ARRAY != vam->json_tree.type) {
7354 ASSERT(VAT_JSON_NONE == vam->json_tree.type);
7355 vat_json_init_array(&vam->json_tree);
7357 node = vat_json_array_add(&vam->json_tree);
7359 vat_json_init_object(node);
7360 vat_json_object_add_uint(node, "sw_if_index", ntohl(mp->sw_if_index));
7362 clib_memcpy(&ip6, &(mp->src_address[0]), sizeof(ip6));
7363 vat_json_object_add_ip6(node, "src_address", ip6);
7364 clib_memcpy(&ip6, &(mp->dst_address[0]), sizeof(ip6));
7365 vat_json_object_add_ip6(node, "dst_address", ip6);
7367 clib_memcpy(&ip4, &(mp->src_address[0]), sizeof(ip4));
7368 vat_json_object_add_ip4(node, "src_address", ip4);
7369 clib_memcpy(&ip4, &(mp->dst_address[0]), sizeof(ip4));
7370 vat_json_object_add_ip4(node, "dst_address", ip4);
7372 vat_json_object_add_uint(node, "encap_vrf_id", ntohl(mp->encap_vrf_id));
7373 vat_json_object_add_uint(node, "decap_next_index", ntohl(mp->decap_next_index));
7374 vat_json_object_add_uint(node, "vni", ntohl(mp->vni));
7375 vat_json_object_add_uint(node, "is_ipv6", mp->is_ipv6 ? 1 : 0);
7378 static int api_vxlan_tunnel_dump (vat_main_t * vam)
7380 unformat_input_t * i = vam->input;
7381 vl_api_vxlan_tunnel_dump_t *mp;
7384 u8 sw_if_index_set = 0;
7386 /* Parse args required to build the message */
7387 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
7388 if (unformat (i, "sw_if_index %d", &sw_if_index))
7389 sw_if_index_set = 1;
7394 if (sw_if_index_set == 0) {
7398 if (!vam->json_output) {
7399 fformat(vam->ofp, "%11s%24s%24s%14s%18s%13s\n",
7400 "sw_if_index", "src_address", "dst_address",
7401 "encap_vrf_id", "decap_next_index", "vni");
7404 /* Get list of vxlan-tunnel interfaces */
7405 M(VXLAN_TUNNEL_DUMP, vxlan_tunnel_dump);
7407 mp->sw_if_index = htonl(sw_if_index);
7411 /* Use a control ping for synchronization */
7413 vl_api_control_ping_t * mp;
7414 M(CONTROL_PING, control_ping);
7420 static int api_gre_add_del_tunnel (vat_main_t * vam)
7422 unformat_input_t * line_input = vam->input;
7423 vl_api_gre_add_del_tunnel_t *mp;
7425 ip4_address_t src4, dst4;
7429 u32 outer_fib_id = 0;
7431 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) {
7432 if (unformat (line_input, "del"))
7434 else if (unformat (line_input, "src %U",
7435 unformat_ip4_address, &src4))
7437 else if (unformat (line_input, "dst %U",
7438 unformat_ip4_address, &dst4))
7440 else if (unformat (line_input, "outer-fib-id %d", &outer_fib_id))
7443 errmsg ("parse error '%U'\n", format_unformat_error, line_input);
7449 errmsg ("tunnel src address not specified\n");
7453 errmsg ("tunnel dst address not specified\n");
7458 M (GRE_ADD_DEL_TUNNEL, gre_add_del_tunnel);
7460 clib_memcpy(&mp->src_address, &src4, sizeof(src4));
7461 clib_memcpy(&mp->dst_address, &dst4, sizeof(dst4));
7462 mp->outer_table_id = ntohl(outer_fib_id);
7463 mp->is_add = is_add;
7470 static void vl_api_gre_tunnel_details_t_handler
7471 (vl_api_gre_tunnel_details_t * mp)
7473 vat_main_t * vam = &vat_main;
7475 fformat(vam->ofp, "%11d%15U%15U%14d\n",
7476 ntohl(mp->sw_if_index),
7477 format_ip4_address, &mp->src_address,
7478 format_ip4_address, &mp->dst_address,
7479 ntohl(mp->outer_table_id));
7482 static void vl_api_gre_tunnel_details_t_handler_json
7483 (vl_api_gre_tunnel_details_t * mp)
7485 vat_main_t * vam = &vat_main;
7486 vat_json_node_t *node = NULL;
7489 if (VAT_JSON_ARRAY != vam->json_tree.type) {
7490 ASSERT(VAT_JSON_NONE == vam->json_tree.type);
7491 vat_json_init_array(&vam->json_tree);
7493 node = vat_json_array_add(&vam->json_tree);
7495 vat_json_init_object(node);
7496 vat_json_object_add_uint(node, "sw_if_index", ntohl(mp->sw_if_index));
7497 clib_memcpy(&ip4, &mp->src_address, sizeof(ip4));
7498 vat_json_object_add_ip4(node, "src_address", ip4);
7499 clib_memcpy(&ip4, &mp->dst_address, sizeof(ip4));
7500 vat_json_object_add_ip4(node, "dst_address", ip4);
7501 vat_json_object_add_uint(node, "outer_fib_id", ntohl(mp->outer_table_id));
7504 static int api_gre_tunnel_dump (vat_main_t * vam)
7506 unformat_input_t * i = vam->input;
7507 vl_api_gre_tunnel_dump_t *mp;
7510 u8 sw_if_index_set = 0;
7512 /* Parse args required to build the message */
7513 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
7514 if (unformat (i, "sw_if_index %d", &sw_if_index))
7515 sw_if_index_set = 1;
7520 if (sw_if_index_set == 0) {
7524 if (!vam->json_output) {
7525 fformat(vam->ofp, "%11s%15s%15s%14s\n",
7526 "sw_if_index", "src_address", "dst_address",
7530 /* Get list of gre-tunnel interfaces */
7531 M(GRE_TUNNEL_DUMP, gre_tunnel_dump);
7533 mp->sw_if_index = htonl(sw_if_index);
7537 /* Use a control ping for synchronization */
7539 vl_api_control_ping_t * mp;
7540 M(CONTROL_PING, control_ping);
7546 static int api_l2_fib_clear_table (vat_main_t * vam)
7548 // unformat_input_t * i = vam->input;
7549 vl_api_l2_fib_clear_table_t *mp;
7552 M(L2_FIB_CLEAR_TABLE, l2_fib_clear_table);
7559 static int api_l2_interface_efp_filter (vat_main_t * vam)
7561 unformat_input_t * i = vam->input;
7562 vl_api_l2_interface_efp_filter_t *mp;
7566 u8 sw_if_index_set = 0;
7568 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
7569 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
7570 sw_if_index_set = 1;
7571 else if (unformat (i, "sw_if_index %d", &sw_if_index))
7572 sw_if_index_set = 1;
7573 else if (unformat (i, "enable"))
7575 else if (unformat (i, "disable"))
7578 clib_warning ("parse error '%U'", format_unformat_error, i);
7583 if (sw_if_index_set == 0) {
7584 errmsg ("missing sw_if_index\n");
7588 M(L2_INTERFACE_EFP_FILTER, l2_interface_efp_filter);
7590 mp->sw_if_index = ntohl(sw_if_index);
7591 mp->enable_disable = enable;
7598 #define foreach_vtr_op \
7599 _("disable", L2_VTR_DISABLED) \
7600 _("push-1", L2_VTR_PUSH_1) \
7601 _("push-2", L2_VTR_PUSH_2) \
7602 _("pop-1", L2_VTR_POP_1) \
7603 _("pop-2", L2_VTR_POP_2) \
7604 _("translate-1-1", L2_VTR_TRANSLATE_1_1) \
7605 _("translate-1-2", L2_VTR_TRANSLATE_1_2) \
7606 _("translate-2-1", L2_VTR_TRANSLATE_2_1) \
7607 _("translate-2-2", L2_VTR_TRANSLATE_2_2)
7609 static int api_l2_interface_vlan_tag_rewrite (vat_main_t * vam)
7611 unformat_input_t * i = vam->input;
7612 vl_api_l2_interface_vlan_tag_rewrite_t *mp;
7615 u8 sw_if_index_set = 0;
7622 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
7623 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
7624 sw_if_index_set = 1;
7625 else if (unformat (i, "sw_if_index %d", &sw_if_index))
7626 sw_if_index_set = 1;
7627 else if (unformat (i, "vtr_op %d", &vtr_op))
7629 #define _(n,v) else if (unformat(i, n)) {vtr_op = v; vtr_op_set = 1;}
7633 else if (unformat (i, "push_dot1q %d", &push_dot1q))
7635 else if (unformat (i, "tag1 %d", &tag1))
7637 else if (unformat (i, "tag2 %d", &tag2))
7640 clib_warning ("parse error '%U'", format_unformat_error, i);
7645 if ((sw_if_index_set == 0)||(vtr_op_set == 0)) {
7646 errmsg ("missing vtr operation or sw_if_index\n");
7650 M(L2_INTERFACE_VLAN_TAG_REWRITE, l2_interface_vlan_tag_rewrite)
7652 mp->sw_if_index = ntohl(sw_if_index);
7653 mp->vtr_op = ntohl(vtr_op);
7654 mp->push_dot1q = ntohl(push_dot1q);
7655 mp->tag1 = ntohl(tag1);
7656 mp->tag2 = ntohl(tag2);
7663 static int api_create_vhost_user_if (vat_main_t * vam)
7665 unformat_input_t * i = vam->input;
7666 vl_api_create_vhost_user_if_t *mp;
7670 u8 file_name_set = 0;
7671 u32 custom_dev_instance = ~0;
7673 u8 use_custom_mac = 0;
7675 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
7676 if (unformat (i, "socket %s", &file_name)) {
7679 else if (unformat (i, "renumber %"PRIu32, &custom_dev_instance))
7681 else if (unformat (i, "mac %U", unformat_ethernet_address, hwaddr))
7683 else if (unformat (i, "server"))
7689 if (file_name_set == 0) {
7690 errmsg ("missing socket file name\n");
7694 if (vec_len (file_name) > 255) {
7695 errmsg ("socket file name too long\n");
7698 vec_add1 (file_name, 0);
7700 M(CREATE_VHOST_USER_IF, create_vhost_user_if);
7702 mp->is_server = is_server;
7703 clib_memcpy(mp->sock_filename, file_name, vec_len(file_name));
7704 vec_free(file_name);
7705 if (custom_dev_instance != ~0) {
7707 mp->custom_dev_instance = ntohl(custom_dev_instance);
7709 mp->use_custom_mac = use_custom_mac;
7710 clib_memcpy(mp->mac_address, hwaddr, 6);
7717 static int api_modify_vhost_user_if (vat_main_t * vam)
7719 unformat_input_t * i = vam->input;
7720 vl_api_modify_vhost_user_if_t *mp;
7724 u8 file_name_set = 0;
7725 u32 custom_dev_instance = ~0;
7726 u8 sw_if_index_set = 0;
7727 u32 sw_if_index = (u32)~0;
7729 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
7730 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
7731 sw_if_index_set = 1;
7732 else if (unformat (i, "sw_if_index %d", &sw_if_index))
7733 sw_if_index_set = 1;
7734 else if (unformat (i, "socket %s", &file_name)) {
7737 else if (unformat (i, "renumber %"PRIu32, &custom_dev_instance))
7739 else if (unformat (i, "server"))
7745 if (sw_if_index_set == 0) {
7746 errmsg ("missing sw_if_index or interface name\n");
7750 if (file_name_set == 0) {
7751 errmsg ("missing socket file name\n");
7755 if (vec_len (file_name) > 255) {
7756 errmsg ("socket file name too long\n");
7759 vec_add1 (file_name, 0);
7761 M(MODIFY_VHOST_USER_IF, modify_vhost_user_if);
7763 mp->sw_if_index = ntohl(sw_if_index);
7764 mp->is_server = is_server;
7765 clib_memcpy(mp->sock_filename, file_name, vec_len(file_name));
7766 vec_free(file_name);
7767 if (custom_dev_instance != ~0) {
7769 mp->custom_dev_instance = ntohl(custom_dev_instance);
7777 static int api_delete_vhost_user_if (vat_main_t * vam)
7779 unformat_input_t * i = vam->input;
7780 vl_api_delete_vhost_user_if_t *mp;
7782 u32 sw_if_index = ~0;
7783 u8 sw_if_index_set = 0;
7785 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
7786 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
7787 sw_if_index_set = 1;
7788 else if (unformat (i, "sw_if_index %d", &sw_if_index))
7789 sw_if_index_set = 1;
7794 if (sw_if_index_set == 0) {
7795 errmsg ("missing sw_if_index or interface name\n");
7800 M(DELETE_VHOST_USER_IF, delete_vhost_user_if);
7802 mp->sw_if_index = ntohl(sw_if_index);
7809 static void vl_api_sw_interface_vhost_user_details_t_handler
7810 (vl_api_sw_interface_vhost_user_details_t * mp)
7812 vat_main_t * vam = &vat_main;
7814 fformat(vam->ofp, "%-25s %3" PRIu32 " %6" PRIu32 " %8x %6d %7d %s\n",
7815 (char *)mp->interface_name,
7816 ntohl(mp->sw_if_index), ntohl(mp->virtio_net_hdr_sz),
7817 clib_net_to_host_u64(mp->features), mp->is_server,
7818 ntohl(mp->num_regions), (char *)mp->sock_filename);
7819 fformat(vam->ofp, " Status: '%s'\n", strerror(ntohl(mp->sock_errno)));
7822 static void vl_api_sw_interface_vhost_user_details_t_handler_json
7823 (vl_api_sw_interface_vhost_user_details_t * mp)
7825 vat_main_t * vam = &vat_main;
7826 vat_json_node_t *node = NULL;
7828 if (VAT_JSON_ARRAY != vam->json_tree.type) {
7829 ASSERT(VAT_JSON_NONE == vam->json_tree.type);
7830 vat_json_init_array(&vam->json_tree);
7832 node = vat_json_array_add(&vam->json_tree);
7834 vat_json_init_object(node);
7835 vat_json_object_add_uint(node, "sw_if_index", ntohl(mp->sw_if_index));
7836 vat_json_object_add_string_copy(node, "interface_name", mp->interface_name);
7837 vat_json_object_add_uint(node, "virtio_net_hdr_sz", ntohl(mp->virtio_net_hdr_sz));
7838 vat_json_object_add_uint(node, "features", clib_net_to_host_u64(mp->features));
7839 vat_json_object_add_uint(node, "is_server", mp->is_server);
7840 vat_json_object_add_string_copy(node, "sock_filename", mp->sock_filename);
7841 vat_json_object_add_uint(node, "num_regions", ntohl(mp->num_regions));
7842 vat_json_object_add_uint(node, "sock_errno", ntohl(mp->sock_errno));
7845 static int api_sw_interface_vhost_user_dump (vat_main_t * vam)
7847 vl_api_sw_interface_vhost_user_dump_t *mp;
7849 fformat(vam->ofp, "Interface name idx hdr_sz features server regions filename\n");
7851 /* Get list of vhost-user interfaces */
7852 M(SW_INTERFACE_VHOST_USER_DUMP, sw_interface_vhost_user_dump);
7855 /* Use a control ping for synchronization */
7857 vl_api_control_ping_t * mp;
7858 M(CONTROL_PING, control_ping);
7864 static int api_show_version (vat_main_t * vam)
7866 vl_api_show_version_t *mp;
7869 M(SHOW_VERSION, show_version);
7877 static int api_vxlan_gpe_add_del_tunnel (vat_main_t * vam)
7879 unformat_input_t * line_input = vam->input;
7880 vl_api_vxlan_gpe_add_del_tunnel_t *mp;
7882 ip4_address_t local, remote;
7886 u32 encap_vrf_id = 0;
7887 u32 decap_vrf_id = 0;
7892 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) {
7893 if (unformat (line_input, "del"))
7895 else if (unformat (line_input, "local %U",
7896 unformat_ip4_address, &local))
7898 else if (unformat (line_input, "remote %U",
7899 unformat_ip4_address, &remote))
7901 else if (unformat (line_input, "encap-vrf-id %d", &encap_vrf_id))
7903 else if (unformat (line_input, "decap-vrf-id %d", &decap_vrf_id))
7905 else if (unformat (line_input, "vni %d", &vni))
7907 else if (unformat(line_input, "next-ip4"))
7909 else if (unformat(line_input, "next-ip6"))
7911 else if (unformat(line_input, "next-ethernet"))
7913 else if (unformat(line_input, "next-nsh"))
7916 errmsg ("parse error '%U'\n", format_unformat_error, line_input);
7921 if (local_set == 0) {
7922 errmsg ("tunnel local address not specified\n");
7925 if (remote_set == 0) {
7926 errmsg ("tunnel remote address not specified\n");
7931 errmsg ("vni not specified\n");
7935 M(VXLAN_GPE_ADD_DEL_TUNNEL, vxlan_gpe_add_del_tunnel);
7937 mp->local = local.as_u32;
7938 mp->remote = remote.as_u32;
7939 mp->encap_vrf_id = ntohl(encap_vrf_id);
7940 mp->decap_vrf_id = ntohl(decap_vrf_id);
7941 mp->protocol = ntohl(protocol);
7942 mp->vni = ntohl(vni);
7943 mp->is_add = is_add;
7951 u8 * format_l2_fib_mac_address (u8 * s, va_list * args)
7953 u8 * a = va_arg (*args, u8 *);
7955 return format (s, "%02x:%02x:%02x:%02x:%02x:%02x",
7956 a[2], a[3], a[4], a[5], a[6], a[7]);
7959 static void vl_api_l2_fib_table_entry_t_handler
7960 (vl_api_l2_fib_table_entry_t * mp)
7962 vat_main_t * vam = &vat_main;
7964 fformat(vam->ofp, "%3" PRIu32 " %U %3" PRIu32
7966 ntohl(mp->bd_id), format_l2_fib_mac_address, &mp->mac,
7967 ntohl(mp->sw_if_index), mp->static_mac, mp->filter_mac,
7971 static void vl_api_l2_fib_table_entry_t_handler_json
7972 (vl_api_l2_fib_table_entry_t * mp)
7974 vat_main_t * vam = &vat_main;
7975 vat_json_node_t *node = NULL;
7977 if (VAT_JSON_ARRAY != vam->json_tree.type) {
7978 ASSERT(VAT_JSON_NONE == vam->json_tree.type);
7979 vat_json_init_array(&vam->json_tree);
7981 node = vat_json_array_add(&vam->json_tree);
7983 vat_json_init_object(node);
7984 vat_json_object_add_uint(node, "bd_id", ntohl(mp->bd_id));
7985 vat_json_object_add_uint(node, "mac", clib_net_to_host_u64(mp->mac));
7986 vat_json_object_add_uint(node, "sw_if_index", ntohl(mp->sw_if_index));
7987 vat_json_object_add_uint(node, "static_mac", mp->static_mac);
7988 vat_json_object_add_uint(node, "filter_mac", mp->filter_mac);
7989 vat_json_object_add_uint(node, "bvi_mac", mp->bvi_mac);
7992 static int api_l2_fib_table_dump (vat_main_t * vam)
7994 unformat_input_t * i = vam->input;
7995 vl_api_l2_fib_table_dump_t *mp;
8000 /* Parse args required to build the message */
8001 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
8002 if (unformat (i, "bd_id %d", &bd_id))
8008 if (bd_id_set == 0) {
8009 errmsg ("missing bridge domain\n");
8013 fformat(vam->ofp, "BD-ID Mac Address sw-ndx Static Filter BVI\n");
8015 /* Get list of l2 fib entries */
8016 M(L2_FIB_TABLE_DUMP, l2_fib_table_dump);
8018 mp->bd_id = ntohl(bd_id);
8021 /* Use a control ping for synchronization */
8023 vl_api_control_ping_t * mp;
8024 M(CONTROL_PING, control_ping);
8032 api_interface_name_renumber (vat_main_t * vam)
8034 unformat_input_t * line_input = vam->input;
8035 vl_api_interface_name_renumber_t *mp;
8036 u32 sw_if_index = ~0;
8038 u32 new_show_dev_instance = ~0;
8040 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) {
8041 if (unformat (line_input, "%U", unformat_sw_if_index, vam,
8044 else if (unformat (line_input, "sw_if_index %d", &sw_if_index))
8046 else if (unformat (line_input, "new_show_dev_instance %d",
8047 &new_show_dev_instance))
8053 if (sw_if_index == ~0) {
8054 errmsg ("missing interface name or sw_if_index\n");
8058 if (new_show_dev_instance == ~0) {
8059 errmsg ("missing new_show_dev_instance\n");
8063 M(INTERFACE_NAME_RENUMBER, interface_name_renumber);
8065 mp->sw_if_index = ntohl (sw_if_index);
8066 mp->new_show_dev_instance = ntohl (new_show_dev_instance);
8072 api_want_ip4_arp_events (vat_main_t * vam)
8074 unformat_input_t * line_input = vam->input;
8075 vl_api_want_ip4_arp_events_t * mp;
8077 ip4_address_t address;
8078 int address_set = 0;
8079 u32 enable_disable = 1;
8081 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) {
8082 if (unformat (line_input, "address %U",
8083 unformat_ip4_address, &address))
8085 else if (unformat (line_input, "del"))
8091 if (address_set == 0) {
8092 errmsg ("missing addresses\n");
8096 M(WANT_IP4_ARP_EVENTS, want_ip4_arp_events);
8097 mp->enable_disable = enable_disable;
8099 mp->address = address.as_u32;
8104 static int api_input_acl_set_interface (vat_main_t * vam)
8106 unformat_input_t * i = vam->input;
8107 vl_api_input_acl_set_interface_t *mp;
8110 int sw_if_index_set;
8111 u32 ip4_table_index = ~0;
8112 u32 ip6_table_index = ~0;
8113 u32 l2_table_index = ~0;
8116 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
8117 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
8118 sw_if_index_set = 1;
8119 else if (unformat (i, "sw_if_index %d", &sw_if_index))
8120 sw_if_index_set = 1;
8121 else if (unformat (i, "del"))
8123 else if (unformat (i, "ip4-table %d", &ip4_table_index))
8125 else if (unformat (i, "ip6-table %d", &ip6_table_index))
8127 else if (unformat (i, "l2-table %d", &l2_table_index))
8130 clib_warning ("parse error '%U'", format_unformat_error, i);
8135 if (sw_if_index_set == 0) {
8136 errmsg ("missing interface name or sw_if_index\n");
8140 M(INPUT_ACL_SET_INTERFACE, input_acl_set_interface);
8142 mp->sw_if_index = ntohl(sw_if_index);
8143 mp->ip4_table_index = ntohl(ip4_table_index);
8144 mp->ip6_table_index = ntohl(ip6_table_index);
8145 mp->l2_table_index = ntohl(l2_table_index);
8146 mp->is_add = is_add;
8154 api_ip_address_dump (vat_main_t * vam)
8156 unformat_input_t * i = vam->input;
8157 vl_api_ip_address_dump_t * mp;
8158 u32 sw_if_index = ~0;
8159 u8 sw_if_index_set = 0;
8164 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
8165 if (unformat (i, "sw_if_index %d", &sw_if_index))
8166 sw_if_index_set = 1;
8167 else if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
8168 sw_if_index_set = 1;
8169 else if (unformat (i, "ipv4"))
8171 else if (unformat (i, "ipv6"))
8177 if (ipv4_set && ipv6_set) {
8178 errmsg ("ipv4 and ipv6 flags cannot be both set\n");
8182 if ((!ipv4_set) && (!ipv6_set)) {
8183 errmsg ("no ipv4 nor ipv6 flag set\n");
8187 if (sw_if_index_set == 0) {
8188 errmsg ("missing interface name or sw_if_index\n");
8192 vam->current_sw_if_index = sw_if_index;
8193 vam->is_ipv6 = ipv6_set;
8195 M(IP_ADDRESS_DUMP, ip_address_dump);
8196 mp->sw_if_index = ntohl(sw_if_index);
8197 mp->is_ipv6 = ipv6_set;
8200 /* Use a control ping for synchronization */
8202 vl_api_control_ping_t * mp;
8203 M(CONTROL_PING, control_ping);
8210 api_ip_dump (vat_main_t * vam)
8212 vl_api_ip_dump_t * mp;
8213 unformat_input_t * in = vam->input;
8220 while (unformat_check_input (in) != UNFORMAT_END_OF_INPUT) {
8221 if (unformat (in, "ipv4"))
8223 else if (unformat (in, "ipv6"))
8229 if (ipv4_set && ipv6_set) {
8230 errmsg ("ipv4 and ipv6 flags cannot be both set\n");
8234 if ((!ipv4_set) && (!ipv6_set)) {
8235 errmsg ("no ipv4 nor ipv6 flag set\n");
8240 vam->is_ipv6 = is_ipv6;
8243 for (i = 0; i < vec_len(vam->ip_details_by_sw_if_index[is_ipv6]); i++) {
8244 vec_free(vam->ip_details_by_sw_if_index[is_ipv6][i].addr);
8246 vec_free(vam->ip_details_by_sw_if_index[is_ipv6]);
8248 M(IP_DUMP, ip_dump);
8249 mp->is_ipv6 = ipv6_set;
8252 /* Use a control ping for synchronization */
8254 vl_api_control_ping_t * mp;
8255 M(CONTROL_PING, control_ping);
8262 api_ipsec_spd_add_del (vat_main_t * vam)
8265 unformat_input_t * i = vam->input;
8266 vl_api_ipsec_spd_add_del_t *mp;
8271 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
8272 if (unformat (i, "spd_id %d", &spd_id))
8274 else if (unformat (i, "del"))
8277 clib_warning ("parse error '%U'", format_unformat_error, i);
8282 errmsg ("spd_id must be set\n");
8286 M(IPSEC_SPD_ADD_DEL, ipsec_spd_add_del);
8288 mp->spd_id = ntohl(spd_id);
8289 mp->is_add = is_add;
8295 clib_warning ("unsupported (no dpdk)");
8301 api_ipsec_interface_add_del_spd (vat_main_t * vam)
8304 unformat_input_t * i = vam->input;
8305 vl_api_ipsec_interface_add_del_spd_t *mp;
8308 u8 sw_if_index_set = 0;
8309 u32 spd_id = (u32) ~0;
8312 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
8313 if (unformat (i, "del"))
8315 else if (unformat (i, "spd_id %d", &spd_id))
8317 else if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
8318 sw_if_index_set = 1;
8319 else if (unformat (i, "sw_if_index %d", &sw_if_index))
8320 sw_if_index_set = 1;
8322 clib_warning ("parse error '%U'", format_unformat_error, i);
8328 if (spd_id == (u32) ~0) {
8329 errmsg ("spd_id must be set\n");
8333 if (sw_if_index_set == 0) {
8334 errmsg ("missing interface name or sw_if_index\n");
8338 M(IPSEC_INTERFACE_ADD_DEL_SPD, ipsec_interface_add_del_spd);
8340 mp->spd_id = ntohl(spd_id);
8341 mp->sw_if_index = ntohl (sw_if_index);
8342 mp->is_add = is_add;
8348 clib_warning ("unsupported (no dpdk)");
8354 api_ipsec_spd_add_del_entry (vat_main_t * vam)
8357 unformat_input_t * i = vam->input;
8358 vl_api_ipsec_spd_add_del_entry_t *mp;
8360 u8 is_add = 1, is_outbound = 0, is_ipv6 = 0, is_ip_any = 1;
8361 u32 spd_id, sa_id, protocol = 0, policy = 0;
8363 u32 rport_start = 0, rport_stop = (u32) ~0;
8364 u32 lport_start = 0, lport_stop = (u32) ~0;
8365 ip4_address_t laddr4_start, laddr4_stop, raddr4_start, raddr4_stop;
8366 ip6_address_t laddr6_start, laddr6_stop, raddr6_start, raddr6_stop;
8368 laddr4_start.as_u32 = raddr4_start.as_u32 = 0;
8369 laddr4_stop.as_u32 = raddr4_stop.as_u32 = (u32) ~0;
8370 laddr6_start.as_u64[0] = raddr6_start.as_u64[0] = 0;
8371 laddr6_start.as_u64[1] = raddr6_start.as_u64[1] = 0;
8372 laddr6_stop.as_u64[0] = raddr6_stop.as_u64[0] = (u64) ~0;
8373 laddr6_stop.as_u64[1] = raddr6_stop.as_u64[1] = (u64) ~0;
8375 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
8376 if (unformat (i, "del"))
8378 if (unformat (i, "outbound"))
8380 if (unformat (i, "inbound"))
8382 else if (unformat (i, "spd_id %d", &spd_id))
8384 else if (unformat (i, "sa_id %d", &sa_id))
8386 else if (unformat (i, "priority %d", &priority))
8388 else if (unformat (i, "protocol %d", &protocol))
8390 else if (unformat (i, "lport_start %d", &lport_start))
8392 else if (unformat (i, "lport_stop %d", &lport_stop))
8394 else if (unformat (i, "rport_start %d", &rport_start))
8396 else if (unformat (i, "rport_stop %d", &rport_stop))
8398 else if (unformat (i, "laddr_start %U", unformat_ip4_address, &laddr4_start))
8403 else if (unformat (i, "laddr_stop %U", unformat_ip4_address, &laddr4_stop))
8408 else if (unformat (i, "raddr_start %U", unformat_ip4_address, &raddr4_start))
8413 else if (unformat (i, "raddr_stop %U", unformat_ip4_address, &raddr4_stop))
8418 else if (unformat (i, "laddr_start %U", unformat_ip6_address, &laddr6_start))
8423 else if (unformat (i, "laddr_stop %U", unformat_ip6_address, &laddr6_stop))
8428 else if (unformat (i, "raddr_start %U", unformat_ip6_address, &raddr6_start))
8433 else if (unformat (i, "raddr_stop %U", unformat_ip6_address, &raddr6_stop))
8438 else if (unformat (i, "action %U", unformat_ipsec_policy_action, &policy))
8440 if (policy == IPSEC_POLICY_ACTION_RESOLVE) {
8441 clib_warning ("unsupported action: 'resolve'");
8446 clib_warning ("parse error '%U'", format_unformat_error, i);
8452 M(IPSEC_SPD_ADD_DEL_ENTRY, ipsec_spd_add_del_entry);
8454 mp->spd_id = ntohl(spd_id);
8455 mp->priority = ntohl(priority);
8456 mp->is_outbound = is_outbound;
8458 mp->is_ipv6 = is_ipv6;
8459 if (is_ipv6 || is_ip_any) {
8460 clib_memcpy (mp->remote_address_start, &raddr6_start, sizeof(ip6_address_t));
8461 clib_memcpy (mp->remote_address_stop, &raddr6_stop, sizeof(ip6_address_t));
8462 clib_memcpy (mp->local_address_start, &laddr6_start, sizeof(ip6_address_t));
8463 clib_memcpy (mp->local_address_stop, &laddr6_stop, sizeof(ip6_address_t));
8465 clib_memcpy (mp->remote_address_start, &raddr4_start, sizeof(ip4_address_t));
8466 clib_memcpy (mp->remote_address_stop, &raddr4_stop, sizeof(ip4_address_t));
8467 clib_memcpy (mp->local_address_start, &laddr4_start, sizeof(ip4_address_t));
8468 clib_memcpy (mp->local_address_stop, &laddr4_stop, sizeof(ip4_address_t));
8470 mp->protocol = (u8) protocol;
8471 mp->local_port_start = ntohs((u16) lport_start);
8472 mp->local_port_stop = ntohs((u16) lport_stop);
8473 mp->remote_port_start = ntohs((u16) rport_start);
8474 mp->remote_port_stop = ntohs((u16) rport_stop);
8475 mp->policy = (u8) policy;
8476 mp->sa_id = ntohl(sa_id);
8477 mp->is_add = is_add;
8478 mp->is_ip_any = is_ip_any;
8483 clib_warning ("unsupported (no dpdk)");
8489 api_ipsec_sad_add_del_entry (vat_main_t * vam)
8492 unformat_input_t * i = vam->input;
8493 vl_api_ipsec_sad_add_del_entry_t *mp;
8499 u8 protocol = IPSEC_PROTOCOL_AH;
8500 u8 is_tunnel = 0, is_tunnel_ipv6 = 0;
8501 u32 crypto_alg = 0, integ_alg = 0;
8502 ip4_address_t tun_src4;
8503 ip4_address_t tun_dst4;
8504 ip6_address_t tun_src6;
8505 ip6_address_t tun_dst6;
8507 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
8508 if (unformat (i, "del"))
8510 else if (unformat (i, "sad_id %d", &sad_id))
8512 else if (unformat (i, "spi %d", &spi))
8514 else if (unformat (i, "esp"))
8515 protocol = IPSEC_PROTOCOL_ESP;
8516 else if (unformat (i, "tunnel_src %U", unformat_ip4_address, &tun_src4)) {
8520 else if (unformat (i, "tunnel_dst %U", unformat_ip4_address, &tun_dst4)) {
8524 else if (unformat (i, "tunnel_src %U", unformat_ip6_address, &tun_src6)) {
8528 else if (unformat (i, "tunnel_dst %U", unformat_ip6_address, &tun_dst6)) {
8532 else if (unformat (i, "crypto_alg %U", unformat_ipsec_crypto_alg, &crypto_alg)) {
8533 if (crypto_alg < IPSEC_CRYPTO_ALG_AES_CBC_128 ||
8534 crypto_alg > IPSEC_INTEG_ALG_SHA_512_256) {
8535 clib_warning ("unsupported crypto-alg: '%U'",
8536 format_ipsec_crypto_alg, crypto_alg);
8540 else if (unformat (i, "crypto_key %U", unformat_hex_string, &ck))
8542 else if (unformat (i, "integ_alg %U", unformat_ipsec_integ_alg, &integ_alg)) {
8543 if (integ_alg < IPSEC_INTEG_ALG_SHA1_96 ||
8544 integ_alg > IPSEC_INTEG_ALG_SHA_512_256) {
8545 clib_warning ("unsupported integ-alg: '%U'",
8546 format_ipsec_integ_alg, integ_alg);
8550 else if (unformat (i, "integ_key %U", unformat_hex_string, &ik))
8553 clib_warning ("parse error '%U'", format_unformat_error, i);
8559 M(IPSEC_SAD_ADD_DEL_ENTRY, ipsec_sad_add_del_entry);
8561 mp->sad_id = ntohl(sad_id);
8562 mp->is_add = is_add;
8563 mp->protocol = protocol;
8564 mp->spi = ntohl(spi);
8565 mp->is_tunnel = is_tunnel;
8566 mp->is_tunnel_ipv6 = is_tunnel_ipv6;
8567 mp->crypto_algorithm = crypto_alg;
8568 mp->integrity_algorithm = integ_alg;
8569 mp->crypto_key_length = vec_len(ck);
8570 mp->integrity_key_length = vec_len(ik);
8572 if (mp->crypto_key_length > sizeof(mp->crypto_key))
8573 mp->crypto_key_length = sizeof(mp->crypto_key);
8575 if (mp->integrity_key_length > sizeof(mp->integrity_key))
8576 mp->integrity_key_length = sizeof(mp->integrity_key);
8578 clib_memcpy (mp->crypto_key, ck, mp->crypto_key_length);
8579 clib_memcpy (mp->integrity_key, ik, mp->integrity_key_length);
8582 if (is_tunnel_ipv6) {
8583 clib_memcpy (mp->tunnel_src_address, &tun_src6, sizeof(ip6_address_t));
8584 clib_memcpy (mp->tunnel_dst_address, &tun_dst6, sizeof(ip6_address_t));
8586 clib_memcpy (mp->tunnel_src_address, &tun_src4, sizeof(ip4_address_t));
8587 clib_memcpy (mp->tunnel_dst_address, &tun_dst4, sizeof(ip4_address_t));
8595 clib_warning ("unsupported (no dpdk)");
8601 api_ipsec_sa_set_key (vat_main_t * vam)
8604 unformat_input_t * i = vam->input;
8605 vl_api_ipsec_sa_set_key_t *mp;
8610 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
8611 if (unformat (i, "sa_id %d", &sa_id))
8613 else if (unformat (i, "crypto_key %U", unformat_hex_string, &ck))
8615 else if (unformat (i, "integ_key %U", unformat_hex_string, &ik))
8618 clib_warning ("parse error '%U'", format_unformat_error, i);
8623 M(IPSEC_SA_SET_KEY, ipsec_set_sa_key);
8625 mp->sa_id = ntohl(sa_id);
8626 mp->crypto_key_length = vec_len(ck);
8627 mp->integrity_key_length = vec_len(ik);
8629 if (mp->crypto_key_length > sizeof(mp->crypto_key))
8630 mp->crypto_key_length = sizeof(mp->crypto_key);
8632 if (mp->integrity_key_length > sizeof(mp->integrity_key))
8633 mp->integrity_key_length = sizeof(mp->integrity_key);
8635 clib_memcpy (mp->crypto_key, ck, mp->crypto_key_length);
8636 clib_memcpy (mp->integrity_key, ik, mp->integrity_key_length);
8642 clib_warning ("unsupported (no dpdk)");
8648 api_ikev2_profile_add_del (vat_main_t * vam)
8651 unformat_input_t * i = vam->input;
8652 vl_api_ikev2_profile_add_del_t * mp;
8657 const char * valid_chars = "a-zA-Z0-9_";
8659 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
8660 if (unformat (i, "del"))
8662 else if (unformat (i, "name %U", unformat_token, valid_chars, &name))
8665 errmsg ("parse error '%U'", format_unformat_error, i);
8670 if (!vec_len (name)) {
8671 errmsg ("profile name must be specified");
8675 if (vec_len (name) > 64) {
8676 errmsg ("profile name too long");
8680 M(IKEV2_PROFILE_ADD_DEL, ikev2_profile_add_del);
8682 clib_memcpy(mp->name, name, vec_len (name));
8683 mp->is_add = is_add;
8690 clib_warning ("unsupported (no dpdk)");
8696 api_ikev2_profile_set_auth (vat_main_t * vam)
8699 unformat_input_t * i = vam->input;
8700 vl_api_ikev2_profile_set_auth_t * mp;
8704 u32 auth_method = 0;
8707 const char * valid_chars = "a-zA-Z0-9_";
8709 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
8710 if (unformat (i, "name %U", unformat_token, valid_chars, &name))
8712 else if (unformat (i, "auth_method %U",
8713 unformat_ikev2_auth_method, &auth_method))
8715 else if (unformat (i, "auth_data 0x%U", unformat_hex_string, &data))
8717 else if (unformat (i, "auth_data %v", &data))
8720 errmsg ("parse error '%U'", format_unformat_error, i);
8725 if (!vec_len (name)) {
8726 errmsg ("profile name must be specified");
8730 if (vec_len (name) > 64) {
8731 errmsg ("profile name too long");
8735 if (!vec_len(data)) {
8736 errmsg ("auth_data must be specified");
8741 errmsg ("auth_method must be specified");
8745 M(IKEV2_PROFILE_SET_AUTH, ikev2_profile_set_auth);
8747 mp->is_hex = is_hex;
8748 mp->auth_method = (u8) auth_method;
8749 mp->data_len = vec_len (data);
8750 clib_memcpy (mp->name, name, vec_len (name));
8751 clib_memcpy (mp->data, data, vec_len (data));
8759 clib_warning ("unsupported (no dpdk)");
8765 api_ikev2_profile_set_id (vat_main_t * vam)
8768 unformat_input_t * i = vam->input;
8769 vl_api_ikev2_profile_set_id_t * mp;
8777 const char * valid_chars = "a-zA-Z0-9_";
8779 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
8780 if (unformat (i, "name %U", unformat_token, valid_chars, &name))
8782 else if (unformat (i, "id_type %U",
8783 unformat_ikev2_id_type, &id_type))
8785 else if (unformat (i, "id_data %U", unformat_ip4_address, &ip4))
8787 data = vec_new(u8, 4);
8788 clib_memcpy(data, ip4.as_u8, 4);
8790 else if (unformat (i, "id_data 0x%U", unformat_hex_string, &data))
8792 else if (unformat (i, "id_data %v", &data))
8794 else if (unformat (i, "local"))
8796 else if (unformat (i, "remote"))
8799 errmsg ("parse error '%U'", format_unformat_error, i);
8804 if (!vec_len (name)) {
8805 errmsg ("profile name must be specified");
8809 if (vec_len (name) > 64) {
8810 errmsg ("profile name too long");
8814 if (!vec_len(data)) {
8815 errmsg ("id_data must be specified");
8820 errmsg ("id_type must be specified");
8824 M(IKEV2_PROFILE_SET_ID, ikev2_profile_set_id);
8826 mp->is_local = is_local;
8827 mp->id_type = (u8) id_type;
8828 mp->data_len = vec_len (data);
8829 clib_memcpy (mp->name, name, vec_len (name));
8830 clib_memcpy (mp->data, data, vec_len (data));
8838 clib_warning ("unsupported (no dpdk)");
8844 api_ikev2_profile_set_ts (vat_main_t * vam)
8847 unformat_input_t * i = vam->input;
8848 vl_api_ikev2_profile_set_ts_t * mp;
8852 u32 proto = 0, start_port = 0, end_port = (u32) ~0;
8853 ip4_address_t start_addr, end_addr;
8855 const char * valid_chars = "a-zA-Z0-9_";
8857 start_addr.as_u32 = 0;
8858 end_addr.as_u32 = (u32) ~0;
8860 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
8861 if (unformat (i, "name %U", unformat_token, valid_chars, &name))
8863 else if (unformat (i, "protocol %d", &proto))
8865 else if (unformat (i, "start_port %d", &start_port))
8867 else if (unformat (i, "end_port %d", &end_port))
8869 else if (unformat (i, "start_addr %U", unformat_ip4_address, &start_addr))
8871 else if (unformat (i, "end_addr %U", unformat_ip4_address, &end_addr))
8873 else if (unformat (i, "local"))
8875 else if (unformat (i, "remote"))
8878 errmsg ("parse error '%U'", format_unformat_error, i);
8883 if (!vec_len (name)) {
8884 errmsg ("profile name must be specified");
8888 if (vec_len (name) > 64) {
8889 errmsg ("profile name too long");
8893 M(IKEV2_PROFILE_SET_TS, ikev2_profile_set_ts);
8895 mp->is_local = is_local;
8896 mp->proto = (u8) proto;
8897 mp->start_port = (u16) start_port;
8898 mp->end_port = (u16) end_port;
8899 mp->start_addr = start_addr.as_u32;
8900 mp->end_addr = end_addr.as_u32;
8901 clib_memcpy (mp->name, name, vec_len (name));
8908 clib_warning ("unsupported (no dpdk)");
8914 api_ikev2_set_local_key (vat_main_t * vam)
8917 unformat_input_t * i = vam->input;
8918 vl_api_ikev2_set_local_key_t * mp;
8922 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
8923 if (unformat (i, "file %v", &file))
8926 errmsg ("parse error '%U'", format_unformat_error, i);
8931 if (!vec_len (file)) {
8932 errmsg ("RSA key file must be specified");
8936 if (vec_len (file) > 256) {
8937 errmsg ("file name too long");
8941 M(IKEV2_SET_LOCAL_KEY, ikev2_set_local_key);
8943 clib_memcpy (mp->key_file, file, vec_len (file));
8950 clib_warning ("unsupported (no dpdk)");
8958 static int api_map_add_domain (vat_main_t * vam)
8960 unformat_input_t *i = vam->input;
8961 vl_api_map_add_domain_t *mp;
8964 ip4_address_t ip4_prefix;
8965 ip6_address_t ip6_prefix;
8966 ip6_address_t ip6_src;
8968 u32 ip6_prefix_len, ip4_prefix_len, ea_bits_len, psid_offset,
8970 u8 is_translation = 0;
8972 u8 ip6_src_len = 128;
8974 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
8975 if (unformat (i, "ip4-pfx %U/%d", unformat_ip4_address,
8976 &ip4_prefix, &ip4_prefix_len))
8978 else if (unformat (i, "ip6-pfx %U/%d", unformat_ip6_address,
8979 &ip6_prefix, &ip6_prefix_len))
8981 else if (unformat (i, "ip6-src %U/%d", unformat_ip6_address, &ip6_src, &ip6_src_len))
8983 else if (unformat (i, "ip6-src %U", unformat_ip6_address, &ip6_src))
8985 else if (unformat (i, "ea-bits-len %d", &ea_bits_len))
8987 else if (unformat (i, "psid-offset %d", &psid_offset))
8989 else if (unformat (i, "psid-len %d", &psid_length))
8991 else if (unformat (i, "mtu %d", &mtu))
8993 else if (unformat (i, "map-t"))
8996 clib_warning ("parse error '%U'", format_unformat_error, i);
9001 if (num_m_args != 6) {
9002 errmsg("mandatory argument(s) missing\n");
9006 /* Construct the API message */
9007 M(MAP_ADD_DOMAIN, map_add_domain);
9009 clib_memcpy(mp->ip4_prefix, &ip4_prefix, sizeof(ip4_prefix));
9010 mp->ip4_prefix_len = ip4_prefix_len;
9012 clib_memcpy(mp->ip6_prefix, &ip6_prefix, sizeof(ip6_prefix));
9013 mp->ip6_prefix_len = ip6_prefix_len;
9015 clib_memcpy(mp->ip6_src, &ip6_src, sizeof(ip6_src));
9016 mp->ip6_src_prefix_len = ip6_src_len;
9018 mp->ea_bits_len = ea_bits_len;
9019 mp->psid_offset = psid_offset;
9020 mp->psid_length = psid_length;
9021 mp->is_translation = is_translation;
9022 mp->mtu = htons(mtu);
9027 /* Wait for a reply, return good/bad news */
9031 static int api_map_del_domain (vat_main_t * vam)
9033 unformat_input_t *i = vam->input;
9034 vl_api_map_del_domain_t *mp;
9040 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
9041 if (unformat (i, "index %d", &index))
9044 clib_warning ("parse error '%U'", format_unformat_error, i);
9049 if (num_m_args != 1) {
9050 errmsg("mandatory argument(s) missing\n");
9054 /* Construct the API message */
9055 M(MAP_DEL_DOMAIN, map_del_domain);
9057 mp->index = ntohl(index);
9062 /* Wait for a reply, return good/bad news */
9066 static int api_map_add_del_rule (vat_main_t * vam)
9068 unformat_input_t *i = vam->input;
9069 vl_api_map_add_del_rule_t *mp;
9072 ip6_address_t ip6_dst;
9073 u32 num_m_args = 0, index, psid;
9075 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
9076 if (unformat (i, "index %d", &index))
9078 else if (unformat (i, "psid %d", &psid))
9080 else if (unformat (i, "dst %U", unformat_ip6_address, &ip6_dst))
9082 else if (unformat (i, "del")) {
9085 clib_warning ("parse error '%U'", format_unformat_error, i);
9090 /* Construct the API message */
9091 M(MAP_ADD_DEL_RULE, map_add_del_rule);
9093 mp->index = ntohl(index);
9094 mp->is_add = is_add;
9095 clib_memcpy(mp->ip6_dst, &ip6_dst, sizeof(ip6_dst));
9096 mp->psid = ntohs(psid);
9101 /* Wait for a reply, return good/bad news */
9105 static int api_map_domain_dump (vat_main_t * vam)
9107 vl_api_map_domain_dump_t *mp;
9110 /* Construct the API message */
9111 M(MAP_DOMAIN_DUMP, map_domain_dump);
9116 /* Use a control ping for synchronization */
9118 vl_api_control_ping_t * mp;
9119 M(CONTROL_PING, control_ping);
9125 static int api_map_rule_dump (vat_main_t * vam)
9127 unformat_input_t *i = vam->input;
9128 vl_api_map_rule_dump_t *mp;
9130 u32 domain_index = ~0;
9132 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
9133 if (unformat (i, "index %u", &domain_index))
9139 if (domain_index == ~0) {
9140 clib_warning("parse error: domain index expected");
9144 /* Construct the API message */
9145 M(MAP_RULE_DUMP, map_rule_dump);
9147 mp->domain_index = htonl(domain_index);
9152 /* Use a control ping for synchronization */
9154 vl_api_control_ping_t * mp;
9155 M(CONTROL_PING, control_ping);
9161 static void vl_api_map_add_domain_reply_t_handler
9162 (vl_api_map_add_domain_reply_t * mp)
9164 vat_main_t * vam = &vat_main;
9165 i32 retval = ntohl(mp->retval);
9167 if (vam->async_mode) {
9168 vam->async_errors += (retval < 0);
9170 vam->retval = retval;
9171 vam->result_ready = 1;
9175 static void vl_api_map_add_domain_reply_t_handler_json
9176 (vl_api_map_add_domain_reply_t * mp)
9178 vat_main_t * vam = &vat_main;
9179 vat_json_node_t node;
9181 vat_json_init_object(&node);
9182 vat_json_object_add_int(&node, "retval", ntohl(mp->retval));
9183 vat_json_object_add_uint(&node, "index", ntohl(mp->index));
9185 vat_json_print(vam->ofp, &node);
9186 vat_json_free(&node);
9188 vam->retval = ntohl(mp->retval);
9189 vam->result_ready = 1;
9193 api_get_first_msg_id (vat_main_t * vam)
9195 vl_api_get_first_msg_id_t * mp;
9197 unformat_input_t * i = vam->input;
9201 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
9202 if (unformat (i, "client %s", &name))
9208 if (name_set == 0) {
9209 errmsg ("missing client name\n");
9214 if (vec_len (name) > 63) {
9215 errmsg ("client name too long\n");
9219 M(GET_FIRST_MSG_ID, get_first_msg_id);
9220 clib_memcpy (mp->name, name, vec_len(name));
9226 static int api_cop_interface_enable_disable (vat_main_t * vam)
9228 unformat_input_t * line_input = vam->input;
9229 vl_api_cop_interface_enable_disable_t * mp;
9231 u32 sw_if_index = ~0;
9232 u8 enable_disable = 1;
9234 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) {
9235 if (unformat (line_input, "disable"))
9237 if (unformat (line_input, "enable"))
9239 else if (unformat (line_input, "%U", unformat_sw_if_index,
9242 else if (unformat (line_input, "sw_if_index %d", &sw_if_index))
9248 if (sw_if_index == ~0) {
9249 errmsg ("missing interface name or sw_if_index\n");
9253 /* Construct the API message */
9254 M(COP_INTERFACE_ENABLE_DISABLE, cop_interface_enable_disable);
9255 mp->sw_if_index = ntohl(sw_if_index);
9256 mp->enable_disable = enable_disable;
9260 /* Wait for the reply */
9264 static int api_cop_whitelist_enable_disable (vat_main_t * vam)
9266 unformat_input_t * line_input = vam->input;
9267 vl_api_cop_whitelist_enable_disable_t * mp;
9269 u32 sw_if_index = ~0;
9270 u8 ip4=0, ip6=0, default_cop=0;
9273 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) {
9274 if (unformat (line_input, "ip4"))
9276 else if (unformat (line_input, "ip6"))
9278 else if (unformat (line_input, "default"))
9280 else if (unformat (line_input, "%U", unformat_sw_if_index,
9283 else if (unformat (line_input, "sw_if_index %d", &sw_if_index))
9285 else if (unformat (line_input, "fib-id %d", &fib_id))
9291 if (sw_if_index == ~0) {
9292 errmsg ("missing interface name or sw_if_index\n");
9296 /* Construct the API message */
9297 M(COP_WHITELIST_ENABLE_DISABLE, cop_whitelist_enable_disable);
9298 mp->sw_if_index = ntohl(sw_if_index);
9299 mp->fib_id = ntohl(fib_id);
9302 mp->default_cop = default_cop;
9306 /* Wait for the reply */
9310 static int api_get_node_graph (vat_main_t * vam)
9312 vl_api_get_node_graph_t * mp;
9315 M(GET_NODE_GRAPH, get_node_graph);
9319 /* Wait for the reply */
9324 api_lisp_add_del_locator_set(vat_main_t * vam)
9326 unformat_input_t * input = vam->input;
9327 vl_api_lisp_add_del_locator_set_t *mp;
9330 u8 *locator_set_name = NULL;
9331 u8 locator_set_name_set = 0;
9333 /* Parse args required to build the message */
9334 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) {
9335 if (unformat(input, "del")) {
9337 } else if (unformat(input, "locator-set %s", &locator_set_name)) {
9338 locator_set_name_set = 1;
9343 if (locator_set_name_set == 0) {
9344 errmsg ("missing locator-set name");
9348 if (vec_len(locator_set_name) > 64) {
9349 errmsg ("locator-set name too long\n");
9350 vec_free(locator_set_name);
9353 vec_add1(locator_set_name, 0);
9355 /* Construct the API message */
9356 M(LISP_ADD_DEL_LOCATOR_SET, lisp_add_del_locator_set);
9358 mp->is_add = is_add;
9359 clib_memcpy(mp->locator_set_name, locator_set_name,
9360 vec_len(locator_set_name));
9361 vec_free(locator_set_name);
9366 /* Wait for a reply... */
9374 api_lisp_add_del_locator(vat_main_t * vam)
9376 unformat_input_t * input = vam->input;
9377 vl_api_lisp_add_del_locator_t *mp;
9379 u32 tmp_if_index = ~0;
9380 u32 sw_if_index = ~0;
9381 u8 sw_if_index_set = 0;
9382 u8 sw_if_index_if_name_set = 0;
9384 u8 priority_set = 0;
9388 u8 *locator_set_name = NULL;
9389 u8 locator_set_name_set = 0;
9391 /* Parse args required to build the message */
9392 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) {
9393 if (unformat(input, "del")) {
9395 } else if (unformat(input, "locator-set %s", &locator_set_name)) {
9396 locator_set_name_set = 1;
9397 } else if (unformat(input, "iface %U", unformat_sw_if_index, vam,
9399 sw_if_index_if_name_set = 1;
9400 sw_if_index = tmp_if_index;
9401 } else if (unformat(input,"sw_if_index %d", &tmp_if_index)) {
9402 sw_if_index_set = 1;
9403 sw_if_index = tmp_if_index;
9404 } else if (unformat(input, "p %d", &priority)) {
9406 } else if (unformat(input, "w %d", &weight)) {
9412 if (locator_set_name_set == 0) {
9413 errmsg ("missing locator-set name");
9417 if (sw_if_index_set == 0 && sw_if_index_if_name_set == 0) {
9418 errmsg ("missing sw_if_index");
9419 vec_free(locator_set_name);
9423 if (sw_if_index_set != 0 && sw_if_index_if_name_set != 0) {
9424 errmsg ("cannot use both params interface name and sw_if_index");
9425 vec_free(locator_set_name);
9429 if (priority_set == 0) {
9430 errmsg ("missing locator-set priority\n");
9431 vec_free(locator_set_name);
9435 if (weight_set == 0) {
9436 errmsg ("missing locator-set weight\n");
9437 vec_free(locator_set_name);
9441 if (vec_len(locator_set_name) > 64) {
9442 errmsg ("locator-set name too long\n");
9443 vec_free(locator_set_name);
9446 vec_add1(locator_set_name, 0);
9448 /* Construct the API message */
9449 M(LISP_ADD_DEL_LOCATOR, lisp_add_del_locator);
9451 mp->is_add = is_add;
9452 mp->sw_if_index = ntohl(sw_if_index);
9453 mp->priority = priority;
9454 mp->weight = weight;
9455 clib_memcpy(mp->locator_set_name, locator_set_name,
9456 vec_len(locator_set_name));
9457 vec_free(locator_set_name);
9462 /* Wait for a reply... */
9470 api_lisp_add_del_local_eid(vat_main_t * vam)
9472 unformat_input_t * input = vam->input;
9473 vl_api_lisp_add_del_local_eid_t *mp;
9478 ip4_address_t eidv4;
9479 ip6_address_t eidv6;
9480 u8 tmp_eid_lenght = ~0;
9482 u8 *locator_set_name = NULL;
9483 u8 locator_set_name_set = 0;
9485 /* Parse args required to build the message */
9486 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) {
9487 if (unformat(input, "del")) {
9489 } else if (unformat(input, "eid %U/%d", unformat_ip4_address,
9490 &eidv4, &tmp_eid_lenght)) {
9491 eid_lenght = tmp_eid_lenght;
9493 } else if (unformat(input, "eid %U/%d", unformat_ip6_address,
9494 &eidv6, &tmp_eid_lenght)) {
9495 eid_lenght = tmp_eid_lenght;
9497 } else if (unformat(input, "locator-set %s", &locator_set_name)) {
9498 locator_set_name_set = 1;
9503 if (locator_set_name_set == 0) {
9504 errmsg ("missing locator-set name\n");
9508 if (vec_len(locator_set_name) > 64) {
9509 errmsg ("locator-set name too long\n");
9510 vec_free(locator_set_name);
9513 vec_add1(locator_set_name, 0);
9515 if (eidv4_set && eidv6_set) {
9516 errmsg ("both eid v4 and v6 addresses set\n");
9517 vec_free(locator_set_name);
9521 if (!eidv4_set && !eidv6_set) {
9522 errmsg ("eid addresses not set\n");
9523 vec_free(locator_set_name);
9527 if (eidv4_set && eid_lenght > 32) {
9528 errmsg ("eid prefix to big\n");
9529 vec_free(locator_set_name);
9533 if (eidv6_set && eid_lenght > 128) {
9534 errmsg ("eid prefix to big\n");
9535 vec_free(locator_set_name);
9539 /* Construct the API message */
9540 M(LISP_ADD_DEL_LOCAL_EID, lisp_add_del_local_eid);
9542 mp->is_add = is_add;
9545 clib_memcpy(mp->ip_address, &eidv6, sizeof(eidv6));
9548 clib_memcpy(mp->ip_address, &eidv4, sizeof(eidv4));
9550 mp->prefix_len = eid_lenght;
9551 clib_memcpy(mp->locator_set_name, locator_set_name,
9552 vec_len(locator_set_name));
9553 vec_free(locator_set_name);
9558 /* Wait for a reply... */
9566 api_lisp_gpe_add_del_fwd_entry(vat_main_t * vam)
9568 unformat_input_t * input = vam->input;
9569 vl_api_lisp_gpe_add_del_fwd_entry_t *mp;
9572 u8 eidv4_set = 0, slocv4_set = 0, dlocv4_set = 0;
9573 u8 eidv6_set = 0, slocv6_set = 0, dlocv6_set = 0;
9574 ip4_address_t eidv4, slocv4, dlocv4;
9575 ip6_address_t eidv6, slocv6, dlocv6;
9576 u8 tmp_eid_lenght = ~0;
9579 /* Parse args required to build the message */
9580 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) {
9581 if (unformat(input, "del")) {
9583 } else if (unformat(input, "eid %U/%d", unformat_ip4_address,
9584 &eidv4, &tmp_eid_lenght)) {
9585 eid_lenght = tmp_eid_lenght;
9587 } else if (unformat(input, "eid %U/%d", unformat_ip6_address,
9588 &eidv6, &tmp_eid_lenght)) {
9589 eid_lenght = tmp_eid_lenght;
9591 } else if (unformat(input, "sloc %U", unformat_ip4_address, &slocv4)) {
9593 } else if (unformat(input, "sloc %U", unformat_ip6_address, &slocv6)) {
9595 } else if (unformat(input, "dloc %U", unformat_ip4_address, &dlocv4)) {
9597 } else if (unformat(input, "dloc %U", unformat_ip6_address, &dlocv6)) {
9603 if (eidv4_set && eidv6_set) {
9604 errmsg ("both eid v4 and v6 addresses set\n");
9608 if (!eidv4_set && !eidv6_set) {
9609 errmsg ("eid addresses not set\n");
9613 if (slocv4_set && slocv6_set) {
9614 errmsg ("both source v4 and v6 addresses set\n");
9618 if (!slocv4_set && !slocv6_set) {
9619 errmsg ("source addresses not set\n");
9623 if (dlocv4_set && dlocv6_set) {
9624 errmsg ("both destination v4 and v6 addresses set\n");
9628 if (dlocv4_set && dlocv6_set) {
9629 errmsg ("destination addresses not set\n");
9633 if (!(slocv4_set == dlocv4_set && slocv6_set == dlocv6_set)) {
9634 errmsg ("mixing type of source and destination address\n");
9638 /* Construct the API message */
9639 M(LISP_GPE_ADD_DEL_FWD_ENTRY, lisp_gpe_add_del_fwd_entry);
9641 mp->is_add = is_add;
9643 mp->eid_is_ipv6 = 1;
9644 clib_memcpy(mp->eid_ip_address, &eidv6, sizeof(eidv6));
9646 mp->eid_is_ipv6 = 0;
9647 clib_memcpy(mp->eid_ip_address, &eidv4, sizeof(eidv4));
9649 mp->eid_prefix_len = eid_lenght;
9651 mp->address_is_ipv6 = 1;
9652 clib_memcpy(mp->source_ip_address, &slocv6, sizeof(slocv6));
9653 clib_memcpy(mp->destination_ip_address, &dlocv6, sizeof(dlocv6));
9655 mp->address_is_ipv6 = 0;
9656 clib_memcpy(mp->source_ip_address, &slocv4, sizeof(slocv4));
9657 clib_memcpy(mp->destination_ip_address, &dlocv4, sizeof(dlocv4));
9663 /* Wait for a reply... */
9671 api_lisp_add_del_map_resolver(vat_main_t * vam)
9673 unformat_input_t * input = vam->input;
9674 vl_api_lisp_add_del_map_resolver_t *mp;
9682 /* Parse args required to build the message */
9683 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) {
9684 if (unformat(input, "del")) {
9686 } else if (unformat(input, "%U", unformat_ip4_address, &ipv4)) {
9688 } else if (unformat(input, "%U", unformat_ip6_address, &ipv6)) {
9694 if (ipv4_set && ipv6_set) {
9695 errmsg ("both eid v4 and v6 addresses set\n");
9699 if (!ipv4_set && !ipv6_set) {
9700 errmsg ("eid addresses not set\n");
9704 /* Construct the API message */
9705 M(LISP_ADD_DEL_MAP_RESOLVER, lisp_add_del_map_resolver);
9707 mp->is_add = is_add;
9710 clib_memcpy(mp->ip_address, &ipv6, sizeof(ipv6));
9713 clib_memcpy(mp->ip_address, &ipv4, sizeof(ipv4));
9719 /* Wait for a reply... */
9727 api_lisp_gpe_enable_disable (vat_main_t * vam)
9729 unformat_input_t * input = vam->input;
9730 vl_api_lisp_gpe_enable_disable_t *mp;
9735 /* Parse args required to build the message */
9736 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) {
9737 if (unformat(input, "enable")) {
9740 } else if (unformat(input, "disable")) {
9748 errmsg("Value not set\n");
9752 /* Construct the API message */
9753 M(LISP_GPE_ENABLE_DISABLE, lisp_gpe_enable_disable);
9760 /* Wait for a reply... */
9768 api_lisp_enable_disable (vat_main_t * vam)
9770 unformat_input_t * input = vam->input;
9771 vl_api_lisp_enable_disable_t *mp;
9776 /* Parse args required to build the message */
9777 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
9779 if (unformat (input, "enable"))
9784 else if (unformat (input, "disable"))
9794 errmsg ("Value not set\n");
9798 /* Construct the API message */
9799 M(LISP_ENABLE_DISABLE, lisp_enable_disable);
9806 /* Wait for a reply... */
9813 /** Used for transferring locators via VPP API */
9814 typedef CLIB_PACKED(struct
9816 u8 is_ip4; /**< is locator an IPv4 address? */
9817 u8 addr[16]; /**< IPv4/IPv6 address */
9821 * Add/del remote mapping from LISP control plane and updates
9822 * forwarding entries in data-plane accordingly.
9824 * @param vam vpp API test context
9825 * @return return code
9828 api_lisp_add_del_remote_mapping (vat_main_t * vam)
9830 unformat_input_t * input = vam->input;
9831 vl_api_lisp_add_del_remote_mapping_t *mp;
9834 u8 seid_set = 0, deid_set = 0;
9835 ip4_address_t seid4, deid4, rloc4;
9836 ip6_address_t seid6, deid6, rloc6;
9837 u32 seid_len = 0, deid_len = 0, len;
9838 u8 deid_is_ip4 = 0, seid_is_ip4 = 0;
9841 rloc_t * rlocs = 0, rloc;
9843 /* Parse args required to build the message */
9844 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) {
9845 if (unformat(input, "del")) {
9847 } else if (unformat(input, "add")) {
9849 } else if (unformat(input, "deid %U/%d", unformat_ip4_address,
9854 } else if (unformat(input, "deid %U/%d", unformat_ip6_address,
9859 } else if (unformat(input, "seid %U/%d", unformat_ip4_address,
9864 } else if (unformat(input, "seid %U/%d", unformat_ip6_address,
9869 } else if (unformat(input, "vni %d", &vni)) {
9871 } else if (unformat(input, "rloc %U", unformat_ip4_address, &rloc4)) {
9873 clib_memcpy (&rloc.addr, &rloc4, sizeof (rloc4));
9874 vec_add1 (rlocs, rloc);
9875 } else if (unformat(input, "rloc %U", unformat_ip6_address, &rloc6)) {
9877 clib_memcpy (&rloc.addr, &rloc6, sizeof (rloc6));
9878 vec_add1 (rlocs, rloc);
9879 } else if (unformat(input, "action %d", &action)) {
9882 clib_warning ("parse error '%U'", format_unformat_error, input);
9887 if (!seid_set || !deid_set) {
9888 errmsg ("missing params!");
9892 if (seid_is_ip4 != deid_is_ip4) {
9893 errmsg ("source and destination EIDs are not in " "same IP family!");
9897 if (is_add && (~0 == action)
9898 && 0 == vec_len (rlocs)) {
9899 errmsg ("no action set for negative map-reply!");
9903 M(LISP_ADD_DEL_REMOTE_MAPPING, lisp_add_del_remote_mapping);
9904 mp->is_add = is_add;
9905 mp->vni = htonl (vni);
9906 mp->seid_len = seid_len;
9907 mp->action = (u8) action;
9908 mp->deid_len = deid_len;
9911 clib_memcpy (mp->seid, &seid4, sizeof (seid4));
9914 clib_memcpy (mp->seid, &seid6, sizeof (seid6));
9919 clib_memcpy (mp->deid, &deid4, sizeof (deid4));
9922 clib_memcpy (mp->deid, &deid6, sizeof (deid6));
9925 mp->rloc_num = vec_len (rlocs);
9926 clib_memcpy (mp->rlocs, rlocs, (sizeof (rloc_t) * vec_len (rlocs)));
9932 /* Wait for a reply... */
9940 api_lisp_gpe_add_del_iface(vat_main_t * vam)
9942 unformat_input_t * input = vam->input;
9943 vl_api_lisp_gpe_add_del_iface_t *mp;
9949 /* Parse args required to build the message */
9950 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) {
9951 if (unformat(input, "up")) {
9954 } else if (unformat(input, "down")) {
9957 } else if (unformat(input, "table_id %d", &table_id)) {
9959 } else if (unformat(input, "vni %d", &vni)) {
9966 errmsg("Value not set\n");
9970 /* Construct the API message */
9971 M(LISP_GPE_ADD_DEL_IFACE, lisp_gpe_add_del_iface);
9973 mp->is_add = is_add;
9974 mp->table_id = table_id;
9980 /* Wait for a reply... */
9988 api_lisp_locator_set_dump(vat_main_t *vam)
9990 vl_api_lisp_locator_set_dump_t *mp;
9993 if (!vam->json_output) {
9994 fformat(vam->ofp, "%=20s%=16s%=16s%=16s\n",
9995 "Locator-set", "Locator", "Priority", "Weight");
9998 M(LISP_LOCATOR_SET_DUMP, lisp_locator_set_dump);
10002 /* Use a control ping for synchronization */
10004 vl_api_control_ping_t * mp;
10005 M(CONTROL_PING, control_ping);
10008 /* Wait for a reply... */
10016 api_lisp_local_eid_table_dump(vat_main_t *vam)
10018 vl_api_lisp_local_eid_table_dump_t *mp;
10021 if (!vam->json_output) {
10022 fformat(vam->ofp, "%=20s%=30s\n",
10023 "Locator-set", "Eid");
10026 M(LISP_LOCAL_EID_TABLE_DUMP, lisp_local_eid_table_dump);
10030 /* Use a control ping for synchronization */
10032 vl_api_control_ping_t * mp;
10033 M(CONTROL_PING, control_ping);
10036 /* Wait for a reply... */
10044 api_lisp_gpe_tunnel_dump(vat_main_t *vam)
10046 vl_api_lisp_gpe_tunnel_dump_t *mp;
10049 if (!vam->json_output) {
10050 fformat(vam->ofp, "%=20s%=30s%=16s%=16s%=16s%=16s"
10051 "%=16s%=16s%=16s%=16s%=16s\n",
10052 "Tunel", "Source", "Destination", "Fib encap", "Fib decap",
10053 "Decap next", "Lisp version", "Flags", "Next protocol",
10054 "ver_res", "res", "iid");
10057 M(LISP_GPE_TUNNEL_DUMP, lisp_gpe_tunnel_dump);
10061 /* Use a control ping for synchronization */
10063 vl_api_control_ping_t * mp;
10064 M(CONTROL_PING, control_ping);
10067 /* Wait for a reply... */
10075 api_lisp_map_resolver_dump(vat_main_t *vam)
10077 vl_api_lisp_map_resolver_dump_t *mp;
10080 if (!vam->json_output) {
10081 fformat(vam->ofp, "%=20s\n",
10085 M(LISP_MAP_RESOLVER_DUMP, lisp_map_resolver_dump);
10089 /* Use a control ping for synchronization */
10091 vl_api_control_ping_t * mp;
10092 M(CONTROL_PING, control_ping);
10095 /* Wait for a reply... */
10103 api_lisp_enable_disable_status_dump(vat_main_t *vam)
10105 vl_api_lisp_enable_disable_status_dump_t *mp;
10108 if (!vam->json_output) {
10109 fformat(vam->ofp, "%=20s\n",
10113 M(LISP_ENABLE_DISABLE_STATUS_DUMP,
10114 lisp_enable_disable_status_dump);
10118 /* Use a control ping for synchronization */
10120 vl_api_control_ping_t * mp;
10121 M(CONTROL_PING, control_ping);
10124 /* Wait for a reply... */
10132 api_af_packet_create (vat_main_t * vam)
10134 unformat_input_t * i = vam->input;
10135 vl_api_af_packet_create_t * mp;
10137 u8 * host_if_name = 0;
10139 u8 random_hw_addr = 1;
10141 memset (hw_addr, 0, sizeof (hw_addr));
10143 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
10144 if (unformat (i, "name %s", &host_if_name))
10145 vec_add1 (host_if_name, 0);
10146 else if (unformat (i, "hw_addr %U", unformat_ethernet_address, hw_addr))
10147 random_hw_addr = 0;
10152 if (!vec_len (host_if_name)) {
10153 errmsg ("host-interface name must be specified");
10157 if (vec_len (host_if_name) > 64) {
10158 errmsg ("host-interface name too long");
10162 M(AF_PACKET_CREATE, af_packet_create);
10164 clib_memcpy (mp->host_if_name, host_if_name, vec_len (host_if_name));
10165 clib_memcpy (mp->hw_addr, hw_addr, 6);
10166 mp->use_random_hw_addr = random_hw_addr;
10167 vec_free (host_if_name);
10175 api_af_packet_delete (vat_main_t * vam)
10177 unformat_input_t * i = vam->input;
10178 vl_api_af_packet_delete_t * mp;
10180 u8 * host_if_name = 0;
10182 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
10183 if (unformat (i, "name %s", &host_if_name))
10184 vec_add1 (host_if_name, 0);
10189 if (!vec_len (host_if_name)) {
10190 errmsg ("host-interface name must be specified");
10194 if (vec_len (host_if_name) > 64) {
10195 errmsg ("host-interface name too long");
10199 M(AF_PACKET_DELETE, af_packet_delete);
10201 clib_memcpy (mp->host_if_name, host_if_name, vec_len (host_if_name));
10202 vec_free (host_if_name);
10209 static int q_or_quit (vat_main_t * vam)
10211 longjmp (vam->jump_buf, 1);
10212 return 0; /* not so much */
10214 static int q (vat_main_t * vam) {return q_or_quit (vam);}
10215 static int quit (vat_main_t * vam) {return q_or_quit (vam);}
10217 static int comment (vat_main_t * vam)
10222 static int cmd_cmp (void * a1, void * a2)
10227 return strcmp ((char *)(c1[0]), (char *)(c2[0]));
10230 static int help (vat_main_t * vam)
10235 unformat_input_t * i = vam->input;
10238 if (unformat (i, "%s", &name)) {
10243 hs = hash_get_mem (vam->help_by_name, name);
10245 fformat (vam->ofp, "usage: %s %s\n", name, hs[0]);
10247 fformat (vam->ofp, "No such msg / command '%s'\n", name);
10252 fformat(vam->ofp, "Help is available for the following:\n");
10254 hash_foreach_pair (p, vam->function_by_name,
10256 vec_add1 (cmds, (u8 *)(p->key));
10259 vec_sort_with_function (cmds, cmd_cmp);
10261 for (j = 0; j < vec_len(cmds); j++)
10262 fformat (vam->ofp, "%s\n", cmds[j]);
10268 static int set (vat_main_t * vam)
10270 u8 * name = 0, * value = 0;
10271 unformat_input_t * i = vam->input;
10273 if (unformat (i, "%s", &name)) {
10274 /* The input buffer is a vector, not a string. */
10275 value = vec_dup (i->buffer);
10276 vec_delete (value, i->index, 0);
10277 /* Almost certainly has a trailing newline */
10278 if (value[vec_len(value)-1] == '\n')
10279 value[vec_len(value)-1] = 0;
10280 /* Make sure it's a proper string, one way or the other */
10281 vec_add1 (value, 0);
10282 (void) clib_macro_set_value (&vam->macro_main,
10283 (char *)name, (char *)value);
10286 errmsg ("usage: set <name> <value>\n");
10293 static int unset (vat_main_t * vam)
10297 if (unformat (vam->input, "%s", &name))
10298 if (clib_macro_unset (&vam->macro_main, (char *)name) == 1)
10299 errmsg ("unset: %s wasn't set\n", name);
10310 static int macro_sort_cmp (void * a1, void * a2)
10312 macro_sort_t * s1 = a1;
10313 macro_sort_t * s2 = a2;
10315 return strcmp ((char *)(s1->name), (char *)(s2->name));
10318 static int dump_macro_table (vat_main_t * vam)
10320 macro_sort_t * sort_me = 0, * sm;
10324 hash_foreach_pair (p, vam->macro_main.the_value_table_hash,
10326 vec_add2 (sort_me, sm, 1);
10327 sm->name = (u8 *)(p->key);
10328 sm->value = (u8 *) (p->value[0]);
10331 vec_sort_with_function (sort_me, macro_sort_cmp);
10333 if (vec_len(sort_me))
10334 fformat (vam->ofp, "%-15s%s\n", "Name", "Value");
10336 fformat (vam->ofp, "The macro table is empty...\n");
10338 for (i = 0; i < vec_len (sort_me); i++)
10339 fformat (vam->ofp, "%-15s%s\n", sort_me[i].name,
10344 static int dump_node_table (vat_main_t * vam)
10347 vlib_node_t * node, * next_node;
10349 if (vec_len (vam->graph_nodes) == 0) {
10350 fformat (vam->ofp, "Node table empty, issue get_node_graph...\n");
10354 for (i = 0; i < vec_len (vam->graph_nodes); i++) {
10355 node = vam->graph_nodes[i];
10356 fformat (vam->ofp, "[%d] %s\n", i, node->name);
10357 for (j = 0; j < vec_len (node->next_nodes); j++) {
10358 if (node->next_nodes[j] != ~0) {
10359 next_node = vam->graph_nodes[node->next_nodes[j]];
10360 fformat (vam->ofp, " [%d] %s\n", j, next_node->name);
10367 static int search_node_table (vat_main_t * vam)
10369 unformat_input_t * line_input = vam->input;
10372 vlib_node_t * node, * next_node;
10375 if (vam->graph_node_index_by_name == 0) {
10376 fformat (vam->ofp, "Node table empty, issue get_node_graph...\n");
10380 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) {
10381 if (unformat (line_input, "%s", &node_to_find)) {
10382 vec_add1 (node_to_find, 0);
10383 p = hash_get_mem (vam->graph_node_index_by_name, node_to_find);
10385 fformat (vam->ofp, "%s not found...\n", node_to_find);
10388 node = vam->graph_nodes[p[0]];
10389 fformat (vam->ofp, "[%d] %s\n", p[0], node->name);
10390 for (j = 0; j < vec_len (node->next_nodes); j++) {
10391 if (node->next_nodes[j] != ~0) {
10392 next_node = vam->graph_nodes[node->next_nodes[j]];
10393 fformat (vam->ofp, " [%d] %s\n", j, next_node->name);
10399 clib_warning ("parse error '%U'", format_unformat_error,
10405 vec_free(node_to_find);
10413 static int script (vat_main_t * vam)
10416 char * save_current_file;
10417 unformat_input_t save_input;
10418 jmp_buf save_jump_buf;
10419 u32 save_line_number;
10421 FILE * new_fp, * save_ifp;
10423 if (unformat (vam->input, "%s", &s)) {
10424 new_fp = fopen ((char *)s, "r");
10426 errmsg ("Couldn't open script file %s\n", s);
10431 errmsg ("Missing script name\n");
10435 clib_memcpy (&save_input, &vam->input, sizeof (save_input));
10436 clib_memcpy (&save_jump_buf, &vam->jump_buf, sizeof (save_jump_buf));
10437 save_ifp = vam->ifp;
10438 save_line_number = vam->input_line_number;
10439 save_current_file = (char *) vam->current_file;
10441 vam->input_line_number = 0;
10443 vam->current_file = s;
10446 clib_memcpy (&vam->input, &save_input, sizeof (vam->input));
10447 clib_memcpy (&vam->jump_buf, &save_jump_buf, sizeof (save_jump_buf));
10448 vam->ifp = save_ifp;
10449 vam->input_line_number = save_line_number;
10450 vam->current_file = (u8 *) save_current_file;
10456 static int echo (vat_main_t * vam)
10458 fformat (vam->ofp, "%v", vam->input->buffer);
10462 /* List of API message constructors, CLI names map to api_xxx */
10463 #define foreach_vpe_api_msg \
10464 _(create_loopback,"[mac <mac-addr>]") \
10465 _(sw_interface_dump,"") \
10466 _(sw_interface_set_flags, \
10467 "<intfc> | sw_if_index <id> admin-up | admin-down link-up | link down") \
10468 _(sw_interface_add_del_address, \
10469 "<intfc> | sw_if_index <id> <ip4-address> | <ip6-address> [del] [del-all] ") \
10470 _(sw_interface_set_table, \
10471 "<intfc> | sw_if_index <id> vrf <table-id> [ipv6]") \
10472 _(sw_interface_set_vpath, \
10473 "<intfc> | sw_if_index <id> enable | disable") \
10474 _(sw_interface_set_l2_xconnect, \
10475 "rx <intfc> | rx_sw_if_index <id> tx <intfc> | tx_sw_if_index <id>\n" \
10476 "enable | disable") \
10477 _(sw_interface_set_l2_bridge, \
10478 "rx <intfc> | rx_sw_if_index <id> bd_id <bridge-domain-id>\n" \
10479 "[shg <split-horizon-group>] [bvi]\n" \
10480 "enable | disable") \
10481 _(bridge_domain_add_del, \
10482 "bd_id <bridge-domain-id> [flood 1|0] [uu-flood 1|0] [forward 1|0] [learn 1|0] [arp-term 1|0] [del]\n")\
10483 _(bridge_domain_dump, "[bd_id <bridge-domain-id>]\n") \
10485 "mac <mac-addr> bd_id <bridge-domain-id> [del] | sw_if <intfc> | sw_if_index <id> [static] [filter] [bvi]\n") \
10487 "sw_if <intfc> | sw_if_index <id> [learn] [forward] [uu-flood] [flood]\n") \
10489 "bd_id <bridge-domain-id> [learn] [forward] [uu-flood] [flood] [arp-term] [disable]\n") \
10491 "tapname <name> mac <mac-addr> | random-mac") \
10493 "<vpp-if-name> | sw_if_index <id> tapname <name> mac <mac-addr> | random-mac") \
10495 "<vpp-if-name> | sw_if_index <id>") \
10496 _(sw_interface_tap_dump, "") \
10497 _(ip_add_del_route, \
10498 "<addr>/<mask> via <addr> [vrf <n>]\n" \
10499 "[<intfc> | sw_if_index <id>] [resolve-attempts <n>]\n" \
10500 "[weight <n>] [drop] [local] [classify <n>] [del]\n" \
10501 "[multipath] [count <n>]") \
10502 _(proxy_arp_add_del, \
10503 "<lo-ip4-addr> - <hi-ip4-addr> [vrf <n>] [del]") \
10504 _(proxy_arp_intfc_enable_disable, \
10505 "<intfc> | sw_if_index <id> enable | disable") \
10506 _(mpls_add_del_encap, \
10507 "label <n> dst <ip4-addr> [vrf <n>] [del]") \
10508 _(mpls_add_del_decap, \
10509 "label <n> [rx_vrf_id <n>] [tx_vrf_id] [s-bit-clear][del]") \
10510 _(mpls_gre_add_del_tunnel, \
10511 "inner_vrf_id <n> outer_vrf_id <n> src <ip4-address> dst <ip4-address>\n" \
10512 "adj <ip4-address>/<mask-width> [del]") \
10513 _(sw_interface_set_unnumbered, \
10514 "<intfc> | sw_if_index <id> unnum_if_index <id> [del]") \
10515 _(ip_neighbor_add_del, \
10516 "<intfc> | sw_if_index <id> dst <ip46-address> mac <mac-addr>") \
10517 _(reset_vrf, "vrf <id> [ipv6]") \
10518 _(create_vlan_subif, "<intfc> | sw_if_index <id> vlan <n>") \
10519 _(create_subif, "<intfc> | sw_if_index <id> sub_id <n>\n" \
10520 "[outer_vlan_id <n>][inner_vlan_id <n>]\n" \
10521 "[no_tags][one_tag][two_tags][dot1ad][exact_match][default_sub]\n" \
10522 "[outer_vlan_id_any][inner_vlan_id_any]") \
10523 _(oam_add_del, "src <ip4-address> dst <ip4-address> [vrf <n>] [del]") \
10524 _(reset_fib, "vrf <n> [ipv6]") \
10525 _(dhcp_proxy_config, \
10526 "svr <v46-address> src <v46-address>\n" \
10527 "insert-cid <n> [del]") \
10528 _(dhcp_proxy_config_2, \
10529 "svr <v46-address> src <v46-address>\n" \
10530 "rx_vrf_id <nn> server_vrf_id <nn> insert-cid <n> [del]") \
10531 _(dhcp_proxy_set_vss, \
10532 "tbl_id <n> fib_id <n> oui <n> [ipv6] [del]") \
10533 _(dhcp_client_config, \
10534 "<intfc> | sw_if_index <id> [hostname <name>] [disable_event] [del]") \
10535 _(set_ip_flow_hash, \
10536 "vrf <n> [src] [dst] [sport] [dport] [proto] [reverse] [ipv6]") \
10537 _(sw_interface_ip6_enable_disable, \
10538 "<intfc> | sw_if_index <id> enable | disable") \
10539 _(sw_interface_ip6_set_link_local_address, \
10540 "<intfc> | sw_if_index <id> <ip6-address>/<mask-width>") \
10541 _(sw_interface_ip6nd_ra_prefix, \
10542 "<intfc> | sw_if_index <id> <ip6-address>/<mask-width>\n" \
10543 "val_life <n> pref_life <n> [def] [noadv] [offl] [noauto]\n" \
10544 "[nolink] [isno]") \
10545 _(sw_interface_ip6nd_ra_config, \
10546 "<intfc> | sw_if_index <id> [maxint <n>] [minint <n>]\n" \
10547 "[life <n>] [count <n>] [interval <n>] [surpress]\n" \
10548 "[managed] [other] [ll] [send] [cease] [isno] [def]") \
10549 _(set_arp_neighbor_limit, "arp_nbr_limit <n> [ipv6]") \
10550 _(l2_patch_add_del, \
10551 "rx <intfc> | rx_sw_if_index <id> tx <intfc> | tx_sw_if_index <id>\n" \
10552 "enable | disable") \
10553 _(mpls_ethernet_add_del_tunnel, \
10554 "tx <intfc> | tx_sw_if_index <n> dst <mac-addr>\n" \
10555 "adj <ip4-addr>/<mw> dst <mac-addr> [del]") \
10556 _(mpls_ethernet_add_del_tunnel_2, \
10557 "inner_vrf_id <n> outer_vrf_id <n> next-hop <ip4-addr>\n" \
10558 "resolve-attempts <n> resolve-if-needed 0 | 1 [del]") \
10559 _(sr_tunnel_add_del, \
10560 "[name <name>] src <ip6-addr> dst <ip6-addr>/<mw> \n" \
10561 "(next <ip6-addr>)+ [tag <ip6-addr>]* [clean] [reroute] \n" \
10562 "[policy <policy_name>]") \
10563 _(sr_policy_add_del, \
10564 "name <name> tunnel <tunnel-name> [tunnel <tunnel-name>]* [del]") \
10565 _(sr_multicast_map_add_del, \
10566 "address [ip6 multicast address] sr-policy [policy name] [del]") \
10567 _(classify_add_del_table, \
10568 "buckets <nn> [skip <n>] [match <n>] [memory_size <nn-bytes>]\n" \
10569 "[del] mask <mask-value>\n" \
10570 " [l2-miss-next | miss-next | acl-miss-next] <name|nn>") \
10571 _(classify_add_del_session, \
10572 "[hit-next|l2-hit-next|acl-hit-next] <name|nn> table-index <nn>\n" \
10573 "skip_n <nn> match_n <nn> match [hex] [l2] [l3 [ip4|ip6]]") \
10574 _(classify_set_interface_ip_table, \
10575 "<intfc> | sw_if_index <nn> table <nn>") \
10576 _(classify_set_interface_l2_tables, \
10577 "<intfc> | sw_if_index <nn> [ip4-table <nn>] [ip6-table <nn>]\n" \
10578 " [other-table <nn>]") \
10579 _(get_node_index, "node <node-name") \
10580 _(add_node_next, "node <node-name> next <next-node-name>") \
10581 _(l2tpv3_create_tunnel, \
10582 "client_address <ip6-addr> our_address <ip6-addr>\n" \
10583 "[local_session_id <nn>][remote_session_id <nn>][local_cookie <nn>]\n"\
10584 "[remote_cookie <nn>]\n[l2-sublayer-preset]\n") \
10585 _(l2tpv3_set_tunnel_cookies, \
10586 "<intfc> | sw_if_index <nn> [new_local_cookie <nn>]\n" \
10587 "[new_remote_cookie <nn>]\n") \
10588 _(l2tpv3_interface_enable_disable, \
10589 "<intfc> | sw_if_index <nn> enable | disable") \
10590 _(l2tpv3_set_lookup_key, \
10591 "lookup_v6_src | lookup_v6_dst | lookup_session_id") \
10592 _(sw_if_l2tpv3_tunnel_dump, "") \
10593 _(vxlan_add_del_tunnel, \
10594 "src <ip4-addr> dst <ip4-addr> vni <vni> [encap-vrf-id <nn>]\n" \
10595 " [decap-next l2|ip4|ip6] [del]") \
10596 _(vxlan_tunnel_dump, "[<intfc> | sw_if_index <nn>]") \
10597 _(gre_add_del_tunnel, \
10598 "src <ip4-addr> dst <ip4-addr> [outer-fib-id <nn>] [del]\n") \
10599 _(gre_tunnel_dump, "[<intfc> | sw_if_index <nn>]") \
10600 _(l2_fib_clear_table, "") \
10601 _(l2_interface_efp_filter, "sw_if_index <nn> enable | disable") \
10602 _(l2_interface_vlan_tag_rewrite, \
10603 "<intfc> | sw_if_index <nn> \n" \
10604 "[disable][push-[1|2]][pop-[1|2]][translate-1-[1|2]] \n" \
10605 "[translate-2-[1|2]] [push_dot1q 0] tag1 <nn> tag2 <nn>") \
10606 _(create_vhost_user_if, \
10607 "socket <filename> [server] [renumber <dev_instance>] " \
10608 "[mac <mac_address>]") \
10609 _(modify_vhost_user_if, \
10610 "<intfc> | sw_if_index <nn> socket <filename>\n" \
10611 "[server] [renumber <dev_instance>]") \
10612 _(delete_vhost_user_if, "<intfc> | sw_if_index <nn>") \
10613 _(sw_interface_vhost_user_dump, "") \
10614 _(show_version, "") \
10615 _(vxlan_gpe_add_del_tunnel, \
10616 "local <ip4-addr> remote <ip4-addr> vni <nn>\n" \
10617 "[encap-vrf-id <nn>] [decap-vrf-id <nn>] [next-ip4][next-ip6]" \
10618 "[next-ethernet] [next-nsh]\n") \
10619 _(l2_fib_table_dump, "bd_id <bridge-domain-id>") \
10620 _(interface_name_renumber, \
10621 "<intfc> | sw_if_index <nn> new_show_dev_instance <nn>") \
10622 _(input_acl_set_interface, \
10623 "<intfc> | sw_if_index <nn> [ip4-table <nn>] [ip6-table <nn>]\n" \
10624 " [l2-table <nn>] [del]") \
10625 _(want_ip4_arp_events, "address <ip4-address> [del]") \
10626 _(ip_address_dump, "(ipv4 | ipv6) (<intfc> | sw_if_index <id>)") \
10627 _(ip_dump, "ipv4 | ipv6") \
10628 _(ipsec_spd_add_del, "spd_id <n> [del]") \
10629 _(ipsec_interface_add_del_spd, "(<intfc> | sw_if_index <id>)\n" \
10631 _(ipsec_sad_add_del_entry, "sad_id <n> spi <n> crypto_alg <alg>\n" \
10632 " crypto_key <hex> tunnel_src <ip4|ip6> tunnel_dst <ip4|ip6>\n" \
10633 " integ_alg <alg> integ_key <hex>") \
10634 _(ipsec_spd_add_del_entry, "spd_id <n> priority <n> action <action>\n" \
10635 " (inbound|outbound) [sa_id <n>] laddr_start <ip4|ip6>\n" \
10636 " laddr_stop <ip4|ip6> raddr_start <ip4|ip6> raddr_stop <ip4|ip6>\n" \
10637 " [lport_start <n> lport_stop <n>] [rport_start <n> rport_stop <n>]" )\
10638 _(ipsec_sa_set_key, "sa_id <n> crypto_key <hex> integ_key <hex>") \
10639 _(ikev2_profile_add_del, "name <profile_name> [del]") \
10640 _(ikev2_profile_set_auth, "name <profile_name> auth_method <method>\n" \
10641 "(auth_data 0x<data> | auth_data <data>)") \
10642 _(ikev2_profile_set_id, "name <profile_name> id_type <type>\n" \
10643 "(id_data 0x<data> | id_data <data>) (local|remote)") \
10644 _(ikev2_profile_set_ts, "name <profile_name> protocol <proto>\n" \
10645 "start_port <port> end_port <port> start_addr <ip4> end_addr <ip4>\n" \
10646 "(local|remote)") \
10647 _(ikev2_set_local_key, "file <absolute_file_path>") \
10648 _(delete_loopback,"sw_if_index <nn>") \
10649 _(bd_ip_mac_add_del, "bd_id <bridge-domain-id> <ip4/6-addr> <mac-addr> [del]") \
10650 _(map_add_domain, \
10651 "ip4-pfx <ip4pfx> ip6-pfx <ip6pfx> " \
10652 "ip6-src <ip6addr> " \
10653 "ea-bits-len <n> psid-offset <n> psid-len <n>") \
10654 _(map_del_domain, "index <n>") \
10655 _(map_add_del_rule, \
10656 "index <n> psid <n> dst <ip6addr> [del]") \
10657 _(map_domain_dump, "") \
10658 _(map_rule_dump, "index <map-domain>") \
10659 _(want_interface_events, "enable|disable") \
10660 _(want_stats,"enable|disable") \
10661 _(get_first_msg_id, "client <name>") \
10662 _(cop_interface_enable_disable, "<intfc> | sw_if_index <nn> [disable]") \
10663 _(cop_whitelist_enable_disable, "<intfc> | sw_if_index <nn>\n" \
10664 "fib-id <nn> [ip4][ip6][default]") \
10665 _(get_node_graph, " ") \
10666 _(sw_interface_clear_stats,"<intfc> | sw_if_index <nn>") \
10667 _(trace_profile_add, "id <nn> trace-type <0x1f|0x3|0x9|0x11|0x19> " \
10668 "trace-elts <nn> trace-tsp <0|1|2|3> node-id <node id in hex> " \
10669 "app-data <app_data in hex> [pow] [ppc <encap|decap>]") \
10670 _(trace_profile_apply, "id <nn> <ip6-address>/<width>" \
10671 " vrf_id <nn> add | pop | none") \
10672 _(trace_profile_del, "") \
10673 _(lisp_add_del_locator_set, "locator-set <locator_name> [del]") \
10674 _(lisp_add_del_locator, "locator-set <locator_name> " \
10675 "iface <intf> | sw_if_index <sw_if_index> " \
10676 "p <priority> w <weight> [del]") \
10677 _(lisp_add_del_local_eid, "<ipv4|ipv6>/<prefix> " \
10678 "locator-set <locator_name> [del]") \
10679 _(lisp_gpe_add_del_fwd_entry, "eid <ip4|6-addr>/<prefix> " \
10680 "sloc <ip4/6-addr> dloc <ip4|6-addr> [del]") \
10681 _(lisp_add_del_map_resolver, "<ip4|6-addr> [del]") \
10682 _(lisp_gpe_enable_disable, "enable|disable") \
10683 _(lisp_enable_disable, "enable|disable") \
10684 _(lisp_gpe_add_del_iface, "up|down") \
10685 _(lisp_add_del_remote_mapping, "add|del vni <vni> deid <dest-eid> seid" \
10686 " <src-eid> rloc <locator> " \
10687 "[rloc <loc> ... ]") \
10688 _(lisp_locator_set_dump, "") \
10689 _(lisp_local_eid_table_dump, "") \
10690 _(lisp_gpe_tunnel_dump, "") \
10691 _(lisp_map_resolver_dump, "") \
10692 _(lisp_enable_disable_status_dump, "") \
10693 _(af_packet_create, "name <host interface name> [hw_addr <mac>]") \
10694 _(af_packet_delete, "name <host interface name>")
10696 /* List of command functions, CLI names map directly to functions */
10697 #define foreach_cli_function \
10698 _(comment, "usage: comment <ignore-rest-of-line>") \
10699 _(dump_interface_table, "usage: dump_interface_table") \
10700 _(dump_sub_interface_table, "usage: dump_sub_interface_table") \
10701 _(dump_ipv4_table, "usage: dump_ipv4_table") \
10702 _(dump_ipv6_table, "usage: dump_ipv6_table") \
10703 _(dump_stats_table, "usage: dump_stats_table") \
10704 _(dump_macro_table, "usage: dump_macro_table ") \
10705 _(dump_node_table, "usage: dump_node_table") \
10706 _(echo, "usage: echo <message>") \
10707 _(exec, "usage: exec <vpe-debug-CLI-command>") \
10708 _(help, "usage: help") \
10709 _(q, "usage: quit") \
10710 _(quit, "usage: quit") \
10711 _(search_node_table, "usage: search_node_table <name>...") \
10712 _(set, "usage: set <variable-name> <value>") \
10713 _(script, "usage: script <file-name>") \
10714 _(unset, "usage: unset <variable-name>")
10717 static void vl_api_##n##_t_handler_uni \
10718 (vl_api_##n##_t * mp) \
10720 vat_main_t * vam = &vat_main; \
10721 if (vam->json_output) { \
10722 vl_api_##n##_t_handler_json(mp); \
10724 vl_api_##n##_t_handler(mp); \
10727 foreach_vpe_api_reply_msg;
10730 void vat_api_hookup (vat_main_t *vam)
10733 vl_msg_api_set_handlers(VL_API_##N, #n, \
10734 vl_api_##n##_t_handler_uni, \
10736 vl_api_##n##_t_endian, \
10737 vl_api_##n##_t_print, \
10738 sizeof(vl_api_##n##_t), 1);
10739 foreach_vpe_api_reply_msg;
10742 vl_msg_api_set_first_available_msg_id (VL_MSG_FIRST_AVAILABLE);
10744 vam->sw_if_index_by_interface_name =
10745 hash_create_string (0, sizeof (uword));
10747 vam->function_by_name =
10748 hash_create_string (0, sizeof(uword));
10750 vam->help_by_name =
10751 hash_create_string (0, sizeof(uword));
10753 /* API messages we can send */
10754 #define _(n,h) hash_set_mem (vam->function_by_name, #n, api_##n);
10755 foreach_vpe_api_msg;
10759 #define _(n,h) hash_set_mem (vam->help_by_name, #n, h);
10760 foreach_vpe_api_msg;
10763 /* CLI functions */
10764 #define _(n,h) hash_set_mem (vam->function_by_name, #n, n);
10765 foreach_cli_function;
10769 #define _(n,h) hash_set_mem (vam->help_by_name, #n, h);
10770 foreach_cli_function;
10774 #undef vl_api_version
10775 #define vl_api_version(n,v) static u32 vpe_api_version = v;
10776 #include <api/vpe.api.h>
10777 #undef vl_api_version
10779 void vl_client_add_api_signatures (vl_api_memclnt_create_t *mp)
10782 * Send the main API signature in slot 0. This bit of code must
10783 * match the checks in ../vpe/api/api.c: vl_msg_api_version_check().
10785 mp->api_versions[0] = clib_host_to_net_u32 (vpe_api_version);