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/nsh-gre/nsh_gre.h>
30 #include <vnet/nsh-vxlan-gpe/nsh_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;
849 static void vl_api_nsh_gre_add_del_tunnel_reply_t_handler
850 (vl_api_nsh_gre_add_del_tunnel_reply_t * mp)
852 vat_main_t * vam = &vat_main;
853 i32 retval = ntohl(mp->retval);
854 u32 sw_if_index = ntohl(mp->sw_if_index);
856 if (retval >= 0 && sw_if_index != (u32)~0) {
857 errmsg ("sw_if_index %d\n", ntohl(mp->sw_if_index));
859 vam->retval = retval;
860 vam->result_ready = 1;
863 static void vl_api_nsh_gre_add_del_tunnel_reply_t_handler_json
864 (vl_api_nsh_gre_add_del_tunnel_reply_t * mp)
866 vat_main_t * vam = &vat_main;
867 vat_json_node_t node;
869 vat_json_init_object(&node);
870 vat_json_object_add_int(&node, "retval", ntohl(mp->retval));
871 vat_json_object_add_uint(&node, "sw_if_index", ntohl(mp->sw_if_index));
873 vat_json_print(vam->ofp, &node);
874 vat_json_free(&node);
876 vam->retval = ntohl(mp->retval);
877 vam->result_ready = 1;
880 static void vl_api_nsh_vxlan_gpe_add_del_tunnel_reply_t_handler
881 (vl_api_nsh_vxlan_gpe_add_del_tunnel_reply_t * mp)
883 vat_main_t * vam = &vat_main;
884 i32 retval = ntohl(mp->retval);
885 u32 sw_if_index = ntohl(mp->sw_if_index);
887 if (retval >= 0 && sw_if_index != (u32)~0) {
888 errmsg ("sw_if_index %d\n", ntohl(mp->sw_if_index));
890 vam->retval = retval;
891 vam->result_ready = 1;
894 static void vl_api_nsh_vxlan_gpe_add_del_tunnel_reply_t_handler_json
895 (vl_api_nsh_vxlan_gpe_add_del_tunnel_reply_t * mp)
897 vat_main_t * vam = &vat_main;
898 vat_json_node_t node;
900 vat_json_init_object(&node);
901 vat_json_object_add_int(&node, "retval", ntohl(mp->retval));
902 vat_json_object_add_uint(&node, "sw_if_index", ntohl(mp->sw_if_index));
904 vat_json_print(vam->ofp, &node);
905 vat_json_free(&node);
907 vam->retval = ntohl(mp->retval);
908 vam->result_ready = 1;
911 static void vl_api_lisp_gpe_add_del_tunnel_reply_t_handler
912 (vl_api_lisp_gpe_add_del_tunnel_reply_t * mp)
914 vat_main_t * vam = &vat_main;
915 i32 retval = ntohl(mp->retval);
916 u32 sw_if_index = ntohl(mp->sw_if_index);
918 if (retval >= 0 && sw_if_index != (u32)~0) {
919 errmsg ("sw_if_index %d\n", ntohl(mp->sw_if_index));
921 vam->retval = retval;
922 vam->result_ready = 1;
925 static void vl_api_lisp_gpe_add_del_tunnel_reply_t_handler_json
926 (vl_api_lisp_gpe_add_del_tunnel_reply_t * mp)
928 vat_main_t * vam = &vat_main;
929 vat_json_node_t node;
931 vat_json_init_object(&node);
932 vat_json_object_add_int(&node, "retval", ntohl(mp->retval));
933 vat_json_object_add_uint(&node, "sw_if_index", ntohl(mp->sw_if_index));
935 vat_json_print(vam->ofp, &node);
936 vat_json_free(&node);
938 vam->retval = ntohl(mp->retval);
939 vam->result_ready = 1;
942 static void vl_api_show_version_reply_t_handler
943 (vl_api_show_version_reply_t * mp)
945 vat_main_t * vam = &vat_main;
946 i32 retval = ntohl(mp->retval);
949 errmsg (" program: %s\n", mp->program);
950 errmsg (" version: %s\n", mp->version);
951 errmsg (" build date: %s\n", mp->build_date);
952 errmsg ("build directory: %s\n", mp->build_directory);
954 vam->retval = retval;
955 vam->result_ready = 1;
958 static void vl_api_show_version_reply_t_handler_json
959 (vl_api_show_version_reply_t * mp)
961 vat_main_t * vam = &vat_main;
962 vat_json_node_t node;
964 vat_json_init_object(&node);
965 vat_json_object_add_int(&node, "retval", ntohl(mp->retval));
966 vat_json_object_add_string_copy(&node, "program", mp->program);
967 vat_json_object_add_string_copy(&node, "version", mp->version);
968 vat_json_object_add_string_copy(&node, "build_date", mp->build_date);
969 vat_json_object_add_string_copy(&node, "build_directory", mp->build_directory);
971 vat_json_print(vam->ofp, &node);
972 vat_json_free(&node);
974 vam->retval = ntohl(mp->retval);
975 vam->result_ready = 1;
978 static void vl_api_ip4_arp_event_t_handler
979 (vl_api_ip4_arp_event_t * mp)
981 vat_main_t * vam = &vat_main;
982 errmsg ("arp event: address %U new mac %U sw_if_index %d\n",
983 format_ip4_address, &mp->address,
984 format_ethernet_address, mp->new_mac, mp->sw_if_index);
987 static void vl_api_ip4_arp_event_t_handler_json
988 (vl_api_ip4_arp_event_t * mp)
990 /* JSON output not supported */
994 * Special-case: build the bridge domain table, maintain
995 * the next bd id vbl.
997 static void vl_api_bridge_domain_details_t_handler
998 (vl_api_bridge_domain_details_t * mp)
1000 vat_main_t * vam = &vat_main;
1001 u32 n_sw_ifs = ntohl (mp->n_sw_ifs);
1003 fformat (vam->ofp, "\n%-3s %-3s %-3s %-3s %-3s %-3s\n",
1004 " ID", "LRN", "FWD", "FLD", "BVI", "#IF");
1006 fformat (vam->ofp, "%3d %3d %3d %3d %3d %3d\n",
1007 ntohl (mp->bd_id), mp->learn, mp->forward,
1008 mp->flood, ntohl (mp->bvi_sw_if_index), n_sw_ifs);
1011 fformat (vam->ofp, "\n\n%s %s %s\n", "sw_if_index", "SHG",
1015 static void vl_api_bridge_domain_details_t_handler_json
1016 (vl_api_bridge_domain_details_t * mp)
1018 vat_main_t * vam = &vat_main;
1019 vat_json_node_t *node, *array = NULL;
1021 if (VAT_JSON_ARRAY != vam->json_tree.type) {
1022 ASSERT(VAT_JSON_NONE == vam->json_tree.type);
1023 vat_json_init_array(&vam->json_tree);
1025 node = vat_json_array_add(&vam->json_tree);
1027 vat_json_init_object(node);
1028 vat_json_object_add_uint(node, "bd_id", ntohl(mp->bd_id));
1029 vat_json_object_add_uint(node, "flood", mp->flood);
1030 vat_json_object_add_uint(node, "forward", mp->forward);
1031 vat_json_object_add_uint(node, "learn", mp->learn);
1032 vat_json_object_add_uint(node, "bvi_sw_if_index", ntohl(mp->bvi_sw_if_index));
1033 vat_json_object_add_uint(node, "n_sw_ifs", ntohl(mp->n_sw_ifs));
1034 array = vat_json_object_add(node, "sw_if");
1035 vat_json_init_array(array);
1039 * Special-case: build the bridge domain sw if table.
1041 static void vl_api_bridge_domain_sw_if_details_t_handler
1042 (vl_api_bridge_domain_sw_if_details_t * mp)
1044 vat_main_t * vam = &vat_main;
1046 u8 * sw_if_name = 0;
1049 sw_if_index = ntohl (mp->sw_if_index);
1050 hash_foreach_pair (p, vam->sw_if_index_by_interface_name,
1052 if ((u32) p->value[0] == sw_if_index) {
1053 sw_if_name = (u8 *)(p->key);
1058 fformat (vam->ofp, "%7d %3d %s", sw_if_index,
1059 mp->shg, sw_if_name ? (char *)sw_if_name :
1060 "sw_if_index not found!");
1063 static void vl_api_bridge_domain_sw_if_details_t_handler_json
1064 (vl_api_bridge_domain_sw_if_details_t * mp)
1066 vat_main_t * vam = &vat_main;
1067 vat_json_node_t *node = NULL;
1068 uword last_index = 0;
1070 ASSERT(VAT_JSON_ARRAY == vam->json_tree.type);
1071 ASSERT(vec_len(vam->json_tree.array) >= 1);
1072 last_index = vec_len(vam->json_tree.array) - 1;
1073 node = &vam->json_tree.array[last_index];
1074 node = vat_json_object_get_element(node, "sw_if");
1075 ASSERT(NULL != node);
1076 node = vat_json_array_add(node);
1078 vat_json_init_object(node);
1079 vat_json_object_add_uint(node, "bd_id", ntohl(mp->bd_id));
1080 vat_json_object_add_uint(node, "sw_if_index", ntohl(mp->sw_if_index));
1081 vat_json_object_add_uint(node, "shg", mp->shg);
1084 static void vl_api_control_ping_reply_t_handler
1085 (vl_api_control_ping_reply_t * mp)
1087 vat_main_t * vam = &vat_main;
1088 i32 retval = ntohl(mp->retval);
1089 if (vam->async_mode) {
1090 vam->async_errors += (retval < 0);
1092 vam->retval = retval;
1093 vam->result_ready = 1;
1097 static void vl_api_control_ping_reply_t_handler_json
1098 (vl_api_control_ping_reply_t * mp)
1100 vat_main_t * vam = &vat_main;
1101 i32 retval = ntohl(mp->retval);
1103 if (VAT_JSON_NONE != vam->json_tree.type) {
1104 vat_json_print(vam->ofp, &vam->json_tree);
1105 vat_json_free(&vam->json_tree);
1106 vam->json_tree.type = VAT_JSON_NONE;
1109 vat_json_init_array(&vam->json_tree);
1110 vat_json_print(vam->ofp, &vam->json_tree);
1111 vam->json_tree.type = VAT_JSON_NONE;
1114 vam->retval = retval;
1115 vam->result_ready = 1;
1118 static void vl_api_l2_flags_reply_t_handler
1119 (vl_api_l2_flags_reply_t * mp)
1121 vat_main_t * vam = &vat_main;
1122 i32 retval = ntohl(mp->retval);
1123 if (vam->async_mode) {
1124 vam->async_errors += (retval < 0);
1126 vam->retval = retval;
1127 vam->result_ready = 1;
1131 static void vl_api_l2_flags_reply_t_handler_json
1132 (vl_api_l2_flags_reply_t * mp)
1134 vat_main_t * vam = &vat_main;
1135 vat_json_node_t node;
1137 vat_json_init_object(&node);
1138 vat_json_object_add_int(&node, "retval", ntohl(mp->retval));
1139 vat_json_object_add_uint(&node, "resulting_feature_bitmap", ntohl(mp->resulting_feature_bitmap));
1141 vat_json_print(vam->ofp, &node);
1142 vat_json_free(&node);
1144 vam->retval = ntohl(mp->retval);
1145 vam->result_ready = 1;
1148 static void vl_api_bridge_flags_reply_t_handler
1149 (vl_api_bridge_flags_reply_t * mp)
1151 vat_main_t * vam = &vat_main;
1152 i32 retval = ntohl(mp->retval);
1153 if (vam->async_mode) {
1154 vam->async_errors += (retval < 0);
1156 vam->retval = retval;
1157 vam->result_ready = 1;
1161 static void vl_api_bridge_flags_reply_t_handler_json
1162 (vl_api_bridge_flags_reply_t * mp)
1164 vat_main_t * vam = &vat_main;
1165 vat_json_node_t node;
1167 vat_json_init_object(&node);
1168 vat_json_object_add_int(&node, "retval", ntohl(mp->retval));
1169 vat_json_object_add_uint(&node, "resulting_feature_bitmap", ntohl(mp->resulting_feature_bitmap));
1171 vat_json_print(vam->ofp, &node);
1172 vat_json_free(&node);
1174 vam->retval = ntohl(mp->retval);
1175 vam->result_ready = 1;
1178 static void vl_api_tap_connect_reply_t_handler
1179 (vl_api_tap_connect_reply_t * mp)
1181 vat_main_t * vam = &vat_main;
1182 i32 retval = ntohl(mp->retval);
1183 if (vam->async_mode) {
1184 vam->async_errors += (retval < 0);
1186 vam->retval = retval;
1187 vam->result_ready = 1;
1191 static void vl_api_tap_connect_reply_t_handler_json
1192 (vl_api_tap_connect_reply_t * mp)
1194 vat_main_t * vam = &vat_main;
1195 vat_json_node_t node;
1197 vat_json_init_object(&node);
1198 vat_json_object_add_int(&node, "retval", ntohl(mp->retval));
1199 vat_json_object_add_uint(&node, "sw_if_index", ntohl(mp->sw_if_index));
1201 vat_json_print(vam->ofp, &node);
1202 vat_json_free(&node);
1204 vam->retval = ntohl(mp->retval);
1205 vam->result_ready = 1;
1208 static void vl_api_tap_modify_reply_t_handler
1209 (vl_api_tap_modify_reply_t * mp)
1211 vat_main_t * vam = &vat_main;
1212 i32 retval = ntohl(mp->retval);
1213 if (vam->async_mode) {
1214 vam->async_errors += (retval < 0);
1216 vam->retval = retval;
1217 vam->result_ready = 1;
1221 static void vl_api_tap_modify_reply_t_handler_json
1222 (vl_api_tap_modify_reply_t * mp)
1224 vat_main_t * vam = &vat_main;
1225 vat_json_node_t node;
1227 vat_json_init_object(&node);
1228 vat_json_object_add_int(&node, "retval", ntohl(mp->retval));
1229 vat_json_object_add_uint(&node, "sw_if_index", ntohl(mp->sw_if_index));
1231 vat_json_print(vam->ofp, &node);
1232 vat_json_free(&node);
1234 vam->retval = ntohl(mp->retval);
1235 vam->result_ready = 1;
1238 static void vl_api_tap_delete_reply_t_handler
1239 (vl_api_tap_delete_reply_t * mp)
1241 vat_main_t * vam = &vat_main;
1242 i32 retval = ntohl(mp->retval);
1243 if (vam->async_mode) {
1244 vam->async_errors += (retval < 0);
1246 vam->retval = retval;
1247 vam->result_ready = 1;
1251 static void vl_api_tap_delete_reply_t_handler_json
1252 (vl_api_tap_delete_reply_t * mp)
1254 vat_main_t * vam = &vat_main;
1255 vat_json_node_t node;
1257 vat_json_init_object(&node);
1258 vat_json_object_add_int(&node, "retval", ntohl(mp->retval));
1260 vat_json_print(vam->ofp, &node);
1261 vat_json_free(&node);
1263 vam->retval = ntohl(mp->retval);
1264 vam->result_ready = 1;
1267 static void vl_api_mpls_ethernet_add_del_tunnel_reply_t_handler
1268 (vl_api_mpls_ethernet_add_del_tunnel_reply_t * mp)
1270 vat_main_t * vam = &vat_main;
1271 i32 retval = ntohl(mp->retval);
1272 if (vam->async_mode) {
1273 vam->async_errors += (retval < 0);
1275 vam->retval = retval;
1276 vam->result_ready = 1;
1280 static void vl_api_mpls_ethernet_add_del_tunnel_reply_t_handler_json
1281 (vl_api_mpls_ethernet_add_del_tunnel_reply_t * mp)
1283 vat_main_t * vam = &vat_main;
1284 vat_json_node_t node;
1286 vat_json_init_object(&node);
1287 vat_json_object_add_int(&node, "retval", ntohl(mp->retval));
1288 vat_json_object_add_uint(&node, "tunnel_sw_if_index", ntohl(mp->tunnel_sw_if_index));
1290 vat_json_print(vam->ofp, &node);
1291 vat_json_free(&node);
1293 vam->retval = ntohl(mp->retval);
1294 vam->result_ready = 1;
1297 static void vl_api_l2tpv3_create_tunnel_reply_t_handler
1298 (vl_api_l2tpv3_create_tunnel_reply_t * mp)
1300 vat_main_t * vam = &vat_main;
1301 i32 retval = ntohl(mp->retval);
1302 if (vam->async_mode) {
1303 vam->async_errors += (retval < 0);
1305 vam->retval = retval;
1306 vam->result_ready = 1;
1310 static void vl_api_l2tpv3_create_tunnel_reply_t_handler_json
1311 (vl_api_l2tpv3_create_tunnel_reply_t * mp)
1313 vat_main_t * vam = &vat_main;
1314 vat_json_node_t node;
1316 vat_json_init_object(&node);
1317 vat_json_object_add_int(&node, "retval", ntohl(mp->retval));
1318 vat_json_object_add_uint(&node, "sw_if_index", ntohl(mp->sw_if_index));
1320 vat_json_print(vam->ofp, &node);
1321 vat_json_free(&node);
1323 vam->retval = ntohl(mp->retval);
1324 vam->result_ready = 1;
1327 static void vl_api_vxlan_add_del_tunnel_reply_t_handler
1328 (vl_api_vxlan_add_del_tunnel_reply_t * mp)
1330 vat_main_t * vam = &vat_main;
1331 i32 retval = ntohl(mp->retval);
1332 if (vam->async_mode) {
1333 vam->async_errors += (retval < 0);
1335 vam->retval = retval;
1336 vam->result_ready = 1;
1340 static void vl_api_vxlan_add_del_tunnel_reply_t_handler_json
1341 (vl_api_vxlan_add_del_tunnel_reply_t * mp)
1343 vat_main_t * vam = &vat_main;
1344 vat_json_node_t node;
1346 vat_json_init_object(&node);
1347 vat_json_object_add_int(&node, "retval", ntohl(mp->retval));
1348 vat_json_object_add_uint(&node, "sw_if_index", ntohl(mp->sw_if_index));
1350 vat_json_print(vam->ofp, &node);
1351 vat_json_free(&node);
1353 vam->retval = ntohl(mp->retval);
1354 vam->result_ready = 1;
1357 static void vl_api_create_vhost_user_if_reply_t_handler
1358 (vl_api_create_vhost_user_if_reply_t * mp)
1360 vat_main_t * vam = &vat_main;
1361 i32 retval = ntohl(mp->retval);
1362 if (vam->async_mode) {
1363 vam->async_errors += (retval < 0);
1365 vam->retval = retval;
1366 vam->result_ready = 1;
1370 static void vl_api_create_vhost_user_if_reply_t_handler_json
1371 (vl_api_create_vhost_user_if_reply_t * mp)
1373 vat_main_t * vam = &vat_main;
1374 vat_json_node_t node;
1376 vat_json_init_object(&node);
1377 vat_json_object_add_int(&node, "retval", ntohl(mp->retval));
1378 vat_json_object_add_uint(&node, "sw_if_index", ntohl(mp->sw_if_index));
1380 vat_json_print(vam->ofp, &node);
1381 vat_json_free(&node);
1383 vam->retval = ntohl(mp->retval);
1384 vam->result_ready = 1;
1387 static void vl_api_ip_address_details_t_handler
1388 (vl_api_ip_address_details_t * mp)
1390 vat_main_t * vam = &vat_main;
1391 static ip_address_details_t empty_ip_address_details = {{0}};
1392 ip_address_details_t * address = NULL;
1393 ip_details_t * current_ip_details = NULL;
1394 ip_details_t * details = NULL;
1396 details = vam->ip_details_by_sw_if_index[vam->is_ipv6];
1398 if (!details || vam->current_sw_if_index >= vec_len(details)
1399 || !details[vam->current_sw_if_index].present) {
1400 errmsg ("ip address details arrived but not stored\n");
1401 errmsg ("ip_dump should be called first\n");
1405 current_ip_details = vec_elt_at_index(details,
1406 vam->current_sw_if_index);
1408 #define addresses (current_ip_details->addr)
1410 vec_validate_init_empty(addresses, vec_len(addresses),
1411 empty_ip_address_details);
1413 address = vec_elt_at_index(addresses, vec_len(addresses) - 1);
1415 clib_memcpy(&address->ip, &mp->ip, sizeof(address->ip));
1416 address->prefix_length = mp->prefix_length;
1420 static void vl_api_ip_address_details_t_handler_json
1421 (vl_api_ip_address_details_t * mp)
1423 vat_main_t * vam = &vat_main;
1424 vat_json_node_t *node = NULL;
1425 struct in6_addr ip6;
1428 if (VAT_JSON_ARRAY != vam->json_tree.type) {
1429 ASSERT(VAT_JSON_NONE == vam->json_tree.type);
1430 vat_json_init_array(&vam->json_tree);
1432 node = vat_json_array_add(&vam->json_tree);
1434 vat_json_init_object(node);
1436 clib_memcpy(&ip6, mp->ip, sizeof(ip6));
1437 vat_json_object_add_ip6(node, "ip", ip6);
1439 clib_memcpy(&ip4, mp->ip, sizeof(ip4));
1440 vat_json_object_add_ip4(node, "ip", ip4);
1442 vat_json_object_add_uint(node, "prefix_length", mp->prefix_length);
1445 static void vl_api_ip_details_t_handler (vl_api_ip_details_t * mp)
1447 vat_main_t * vam = &vat_main;
1448 static ip_details_t empty_ip_details = {0};
1449 ip_details_t * ip = NULL;
1450 u32 sw_if_index = ~0;
1452 sw_if_index = ntohl(mp->sw_if_index);
1454 vec_validate_init_empty(vam->ip_details_by_sw_if_index[vam->is_ipv6],
1455 sw_if_index, empty_ip_details);
1457 ip = vec_elt_at_index(vam->ip_details_by_sw_if_index[vam->is_ipv6],
1463 static void vl_api_ip_details_t_handler_json (vl_api_ip_details_t * mp)
1465 vat_main_t * vam = &vat_main;
1467 if (VAT_JSON_ARRAY != vam->json_tree.type) {
1468 ASSERT(VAT_JSON_NONE == vam->json_tree.type);
1469 vat_json_init_array(&vam->json_tree);
1471 vat_json_array_add_uint(&vam->json_tree, clib_net_to_host_u32(mp->sw_if_index));
1474 static void vl_api_map_domain_details_t_handler_json
1475 (vl_api_map_domain_details_t * mp)
1477 vat_json_node_t * node = NULL;
1478 vat_main_t * vam = &vat_main;
1479 struct in6_addr ip6;
1482 if (VAT_JSON_ARRAY != vam->json_tree.type) {
1483 ASSERT(VAT_JSON_NONE == vam->json_tree.type);
1484 vat_json_init_array(&vam->json_tree);
1487 node = vat_json_array_add(&vam->json_tree);
1488 vat_json_init_object(node);
1490 vat_json_object_add_uint(node, "domain_index", clib_net_to_host_u32(mp->domain_index));
1491 clib_memcpy(&ip6, mp->ip6_prefix, sizeof(ip6));
1492 vat_json_object_add_ip6(node, "ip6_prefix", ip6);
1493 clib_memcpy(&ip4, mp->ip4_prefix, sizeof(ip4));
1494 vat_json_object_add_ip4(node, "ip4_prefix", ip4);
1495 clib_memcpy(&ip6, mp->ip6_src, sizeof(ip6));
1496 vat_json_object_add_ip6(node, "ip6_src", ip6);
1497 vat_json_object_add_int(node, "ip6_prefix_len", mp->ip6_prefix_len);
1498 vat_json_object_add_int(node, "ip4_prefix_len", mp->ip4_prefix_len);
1499 vat_json_object_add_int(node, "ip6_src_len", mp->ip6_src_len);
1500 vat_json_object_add_int(node, "ea_bits_len", mp->ea_bits_len);
1501 vat_json_object_add_int(node, "psid_offset", mp->psid_offset);
1502 vat_json_object_add_int(node, "psid_length", mp->psid_length);
1503 vat_json_object_add_uint(node, "flags", mp->flags);
1504 vat_json_object_add_uint(node, "mtu", clib_net_to_host_u16(mp->mtu));
1505 vat_json_object_add_int(node, "is_translation", mp->is_translation);
1508 static void vl_api_map_domain_details_t_handler
1509 (vl_api_map_domain_details_t * mp)
1511 vat_main_t * vam = &vat_main;
1513 if (mp->is_translation) {
1514 fformat(vam->ofp, "* %U/%d (ipv4-prefix) %U/%d (ipv6-prefix) %U/%d (ip6-src) index: %u\n",
1515 format_ip4_address, mp->ip4_prefix, mp->ip4_prefix_len,
1516 format_ip6_address, mp->ip6_prefix, mp->ip6_prefix_len,
1517 format_ip6_address, mp->ip6_src, mp->ip6_src_len, clib_net_to_host_u32(mp->domain_index));
1519 fformat(vam->ofp, "* %U/%d (ipv4-prefix) %U/%d (ipv6-prefix) %U (ip6-src) index: %u\n",
1520 format_ip4_address, mp->ip4_prefix, mp->ip4_prefix_len,
1521 format_ip6_address, mp->ip6_prefix, mp->ip6_prefix_len,
1522 format_ip6_address, mp->ip6_src, clib_net_to_host_u32(mp->domain_index));
1524 fformat(vam->ofp, " ea-len %d psid-offset %d psid-len %d mtu %d %s\n",
1525 mp->ea_bits_len, mp->psid_offset, mp->psid_length, mp->mtu, mp->is_translation? "map-t":"");
1528 static void vl_api_map_rule_details_t_handler_json
1529 (vl_api_map_rule_details_t * mp)
1531 struct in6_addr ip6;
1532 vat_json_node_t * node = NULL;
1533 vat_main_t * vam = &vat_main;
1535 if (VAT_JSON_ARRAY != vam->json_tree.type) {
1536 ASSERT(VAT_JSON_NONE == vam->json_tree.type);
1537 vat_json_init_array(&vam->json_tree);
1540 node = vat_json_array_add(&vam->json_tree);
1541 vat_json_init_object(node);
1543 vat_json_object_add_uint(node, "psid", clib_net_to_host_u16(mp->psid));
1544 clib_memcpy(&ip6, mp->ip6_dst, sizeof(ip6));
1545 vat_json_object_add_ip6(node, "ip6_dst", ip6);
1548 static void vl_api_map_rule_details_t_handler
1549 (vl_api_map_rule_details_t * mp)
1551 vat_main_t * vam = &vat_main;
1552 fformat(vam->ofp, " %d (psid) %U (ip6-dst)\n", clib_net_to_host_u16(mp->psid),
1553 format_ip6_address, mp->ip6_dst);
1556 static void vl_api_dhcp_compl_event_t_handler
1557 (vl_api_dhcp_compl_event_t * mp)
1559 vat_main_t * vam = &vat_main;
1560 errmsg ("DHCP compl event: pid %d %s hostname %s host_addr %U "
1561 "router_addr %U host_mac %U\n",
1562 mp->pid, mp->is_ipv6 ? "ipv6":"ipv4", mp->hostname,
1563 format_ip4_address, &mp->host_address,
1564 format_ip4_address, &mp->router_address,
1565 format_ethernet_address, mp->host_mac);
1568 static void vl_api_dhcp_compl_event_t_handler_json
1569 (vl_api_dhcp_compl_event_t * mp)
1571 /* JSON output not supported */
1574 static void set_simple_interface_counter (u8 vnet_counter_type, u32 sw_if_index,
1577 vat_main_t * vam = &vat_main;
1578 static u64 default_counter = 0;
1580 vec_validate_init_empty(vam->simple_interface_counters, vnet_counter_type, NULL);
1581 vec_validate_init_empty(vam->simple_interface_counters[vnet_counter_type],
1582 sw_if_index, default_counter);
1583 vam->simple_interface_counters[vnet_counter_type][sw_if_index] = counter;
1586 static void set_combined_interface_counter (u8 vnet_counter_type, u32 sw_if_index,
1587 interface_counter_t counter)
1589 vat_main_t * vam = &vat_main;
1590 static interface_counter_t default_counter = {0, };
1592 vec_validate_init_empty(vam->combined_interface_counters, vnet_counter_type, NULL);
1593 vec_validate_init_empty(vam->combined_interface_counters[vnet_counter_type],
1594 sw_if_index, default_counter);
1595 vam->combined_interface_counters[vnet_counter_type][sw_if_index] = counter;
1598 static void vl_api_vnet_interface_counters_t_handler
1599 (vl_api_vnet_interface_counters_t *mp)
1604 static void vl_api_vnet_interface_counters_t_handler_json
1605 (vl_api_vnet_interface_counters_t *mp)
1607 interface_counter_t counter;
1612 u32 first_sw_if_index;
1615 count = ntohl(mp->count);
1616 first_sw_if_index = ntohl(mp->first_sw_if_index);
1618 if (!mp->is_combined) {
1619 v_packets = (u64*)&mp->data;
1620 for (i = 0; i < count; i++) {
1621 packets = clib_net_to_host_u64(clib_mem_unaligned(v_packets, u64));
1622 set_simple_interface_counter(mp->vnet_counter_type,
1623 first_sw_if_index + i, packets);
1627 v = (vlib_counter_t*)&mp->data;
1628 for (i = 0; i < count; i++) {
1629 counter.packets = clib_net_to_host_u64(
1630 clib_mem_unaligned(&v->packets, u64));
1631 counter.bytes = clib_net_to_host_u64(
1632 clib_mem_unaligned(&v->bytes, u64));
1633 set_combined_interface_counter(mp->vnet_counter_type,
1634 first_sw_if_index + i, counter);
1640 static u32 ip4_fib_counters_get_vrf_index_by_vrf_id (u32 vrf_id)
1642 vat_main_t * vam = &vat_main;
1645 for (i = 0; i < vec_len(vam->ip4_fib_counters_vrf_id_by_index); i++) {
1646 if (vam->ip4_fib_counters_vrf_id_by_index[i] == vrf_id) {
1653 static u32 ip6_fib_counters_get_vrf_index_by_vrf_id (u32 vrf_id)
1655 vat_main_t * vam = &vat_main;
1658 for (i = 0; i < vec_len(vam->ip6_fib_counters_vrf_id_by_index); i++) {
1659 if (vam->ip6_fib_counters_vrf_id_by_index[i] == vrf_id) {
1666 static void vl_api_vnet_ip4_fib_counters_t_handler
1667 (vl_api_vnet_ip4_fib_counters_t *mp)
1672 static void vl_api_vnet_ip4_fib_counters_t_handler_json
1673 (vl_api_vnet_ip4_fib_counters_t *mp)
1675 vat_main_t * vam = &vat_main;
1676 vl_api_ip4_fib_counter_t *v;
1677 ip4_fib_counter_t *counter;
1684 vrf_id = ntohl(mp->vrf_id);
1685 vrf_index = ip4_fib_counters_get_vrf_index_by_vrf_id(vrf_id);
1686 if (~0 == vrf_index) {
1687 vrf_index = vec_len(vam->ip4_fib_counters_vrf_id_by_index);
1688 vec_validate(vam->ip4_fib_counters_vrf_id_by_index, vrf_index);
1689 vam->ip4_fib_counters_vrf_id_by_index[vrf_index] = vrf_id;
1690 vec_validate(vam->ip4_fib_counters, vrf_index);
1691 vam->ip4_fib_counters[vrf_index] = NULL;
1694 vec_free(vam->ip4_fib_counters[vrf_index]);
1695 v = (vl_api_ip4_fib_counter_t*)&mp->c;
1696 count = ntohl(mp->count);
1697 for (i = 0; i < count; i++) {
1698 vec_validate(vam->ip4_fib_counters[vrf_index], i);
1699 counter = &vam->ip4_fib_counters[vrf_index][i];
1700 clib_memcpy(&ip4, &v->address, sizeof(ip4));
1701 counter->address = ip4;
1702 counter->address_length = v->address_length;
1703 counter->packets = clib_net_to_host_u64(v->packets);
1704 counter->bytes = clib_net_to_host_u64(v->bytes);
1709 static void vl_api_vnet_ip6_fib_counters_t_handler
1710 (vl_api_vnet_ip6_fib_counters_t *mp)
1715 static void vl_api_vnet_ip6_fib_counters_t_handler_json
1716 (vl_api_vnet_ip6_fib_counters_t *mp)
1718 vat_main_t * vam = &vat_main;
1719 vl_api_ip6_fib_counter_t *v;
1720 ip6_fib_counter_t *counter;
1721 struct in6_addr ip6;
1727 vrf_id = ntohl(mp->vrf_id);
1728 vrf_index = ip6_fib_counters_get_vrf_index_by_vrf_id(vrf_id);
1729 if (~0 == vrf_index) {
1730 vrf_index = vec_len(vam->ip6_fib_counters_vrf_id_by_index);
1731 vec_validate(vam->ip6_fib_counters_vrf_id_by_index, vrf_index);
1732 vam->ip6_fib_counters_vrf_id_by_index[vrf_index] = vrf_id;
1733 vec_validate(vam->ip6_fib_counters, vrf_index);
1734 vam->ip6_fib_counters[vrf_index] = NULL;
1737 vec_free(vam->ip6_fib_counters[vrf_index]);
1738 v = (vl_api_ip6_fib_counter_t*)&mp->c;
1739 count = ntohl(mp->count);
1740 for (i = 0; i < count; i++) {
1741 vec_validate(vam->ip6_fib_counters[vrf_index], i);
1742 counter = &vam->ip6_fib_counters[vrf_index][i];
1743 clib_memcpy(&ip6, &v->address, sizeof(ip6));
1744 counter->address = ip6;
1745 counter->address_length = v->address_length;
1746 counter->packets = clib_net_to_host_u64(v->packets);
1747 counter->bytes = clib_net_to_host_u64(v->bytes);
1752 static void vl_api_get_first_msg_id_reply_t_handler
1753 (vl_api_get_first_msg_id_reply_t * mp)
1755 vat_main_t * vam = &vat_main;
1756 i32 retval = ntohl(mp->retval);
1758 if (vam->async_mode) {
1759 vam->async_errors += (retval < 0);
1761 vam->retval = retval;
1762 vam->result_ready = 1;
1765 errmsg ("first message id %d\n", ntohs(mp->first_msg_id));
1769 static void vl_api_get_first_msg_id_reply_t_handler_json
1770 (vl_api_get_first_msg_id_reply_t * mp)
1772 vat_main_t * vam = &vat_main;
1773 vat_json_node_t node;
1775 vat_json_init_object(&node);
1776 vat_json_object_add_int(&node, "retval", ntohl(mp->retval));
1777 vat_json_object_add_uint(&node, "first_msg_id",
1778 (uint) ntohs(mp->first_msg_id));
1780 vat_json_print(vam->ofp, &node);
1781 vat_json_free(&node);
1783 vam->retval = ntohl(mp->retval);
1784 vam->result_ready = 1;
1787 static void vl_api_get_node_graph_reply_t_handler
1788 (vl_api_get_node_graph_reply_t * mp)
1790 vat_main_t * vam = &vat_main;
1791 api_main_t * am = &api_main;
1792 i32 retval = ntohl(mp->retval);
1793 u8 * pvt_copy, * reply;
1798 if (vam->async_mode) {
1799 vam->async_errors += (retval < 0);
1801 vam->retval = retval;
1802 vam->result_ready = 1;
1805 /* "Should never happen..." */
1809 reply = (u8 *)(mp->reply_in_shmem);
1810 pvt_copy = vec_dup (reply);
1812 /* Toss the shared-memory original... */
1813 pthread_mutex_lock (&am->vlib_rp->mutex);
1814 oldheap = svm_push_data_heap (am->vlib_rp);
1818 svm_pop_heap (oldheap);
1819 pthread_mutex_unlock (&am->vlib_rp->mutex);
1821 if (vam->graph_nodes) {
1822 hash_free (vam->graph_node_index_by_name);
1824 for (i = 0; i < vec_len (vam->graph_nodes); i++) {
1825 node = vam->graph_nodes[i];
1826 vec_free (node->name);
1827 vec_free (node->next_nodes);
1830 vec_free(vam->graph_nodes);
1833 vam->graph_node_index_by_name = hash_create_string (0, sizeof(uword));
1834 vam->graph_nodes = vlib_node_unserialize (pvt_copy);
1835 vec_free (pvt_copy);
1837 for (i = 0; i < vec_len (vam->graph_nodes); i++) {
1838 node = vam->graph_nodes[i];
1839 hash_set_mem (vam->graph_node_index_by_name, node->name, i);
1843 static void vl_api_get_node_graph_reply_t_handler_json
1844 (vl_api_get_node_graph_reply_t * mp)
1846 vat_main_t * vam = &vat_main;
1847 api_main_t * am = &api_main;
1849 vat_json_node_t node;
1852 /* $$$$ make this real? */
1853 vat_json_init_object(&node);
1854 vat_json_object_add_int(&node, "retval", ntohl(mp->retval));
1855 vat_json_object_add_uint(&node, "reply_in_shmem", mp->reply_in_shmem);
1857 reply = (u8 *)(mp->reply_in_shmem);
1859 /* Toss the shared-memory original... */
1860 pthread_mutex_lock (&am->vlib_rp->mutex);
1861 oldheap = svm_push_data_heap (am->vlib_rp);
1865 svm_pop_heap (oldheap);
1866 pthread_mutex_unlock (&am->vlib_rp->mutex);
1868 vat_json_print(vam->ofp, &node);
1869 vat_json_free(&node);
1871 vam->retval = ntohl(mp->retval);
1872 vam->result_ready = 1;
1876 vl_api_lisp_locator_set_details_t_handler (
1877 vl_api_lisp_locator_set_details_t *mp)
1879 vat_main_t *vam = &vat_main;
1881 fformat(vam->ofp, "%=20s%=16d%=16d%=16d\n",
1882 mp->locator_set_name,
1883 ntohl(mp->sw_if_index),
1889 vl_api_lisp_locator_set_details_t_handler_json (
1890 vl_api_lisp_locator_set_details_t *mp)
1892 vat_main_t *vam = &vat_main;
1893 vat_json_node_t *node = NULL;
1895 if (VAT_JSON_ARRAY != vam->json_tree.type) {
1896 ASSERT(VAT_JSON_NONE == vam->json_tree.type);
1897 vat_json_init_array(&vam->json_tree);
1899 node = vat_json_array_add(&vam->json_tree);
1901 vat_json_init_object(node);
1902 vat_json_object_add_string_copy(node, "locator-set", mp->locator_set_name);
1903 vat_json_object_add_uint(node, "locator", ntohl(mp->sw_if_index));
1904 vat_json_object_add_uint(node, "priority", mp->priority);
1905 vat_json_object_add_uint(node, "weight", mp->weight);
1909 vl_api_lisp_local_eid_table_details_t_handler (
1910 vl_api_lisp_local_eid_table_details_t *mp)
1912 vat_main_t *vam = &vat_main;
1915 prefix = format(0, "%U/%d",
1916 mp->eid_is_ipv6 ? format_ip6_address : format_ip4_address,
1918 mp->eid_prefix_len);
1920 fformat(vam->ofp, "%=20s%=30s\n",
1921 mp->locator_set_name, prefix);
1927 vl_api_lisp_local_eid_table_details_t_handler_json (
1928 vl_api_lisp_local_eid_table_details_t *mp)
1930 vat_main_t *vam = &vat_main;
1931 vat_json_node_t *node = NULL;
1932 struct in6_addr ip6;
1935 if (VAT_JSON_ARRAY != vam->json_tree.type) {
1936 ASSERT(VAT_JSON_NONE == vam->json_tree.type);
1937 vat_json_init_array(&vam->json_tree);
1939 node = vat_json_array_add(&vam->json_tree);
1941 vat_json_init_object(node);
1942 vat_json_object_add_string_copy(node, "locator-set", mp->locator_set_name);
1943 if (mp->eid_is_ipv6) {
1944 clib_memcpy(&ip6, mp->eid_ip_address, sizeof(ip6));
1945 vat_json_object_add_ip6(node, "eid address", ip6);
1947 clib_memcpy(&ip4, mp->eid_ip_address, sizeof(ip4));
1948 vat_json_object_add_ip4(node, "eid address", ip4);
1950 vat_json_object_add_uint(node, "eid prefix len", mp->eid_prefix_len);
1954 format_decap_next (u8 * s, va_list * args)
1956 u32 next_index = va_arg (*args, u32);
1960 case LISP_GPE_INPUT_NEXT_DROP:
1961 return format (s, "drop");
1962 case LISP_GPE_INPUT_NEXT_IP4_INPUT:
1963 return format (s, "ip4");
1964 case LISP_GPE_INPUT_NEXT_IP6_INPUT:
1965 return format (s, "ip6");
1967 return format (s, "unknown %d", next_index);
1973 vl_api_lisp_gpe_tunnel_details_t_handler (vl_api_lisp_gpe_tunnel_details_t *mp)
1975 vat_main_t *vam = &vat_main;
1977 u8 *flag_str = NULL;
1979 iid_str = format(0, "%d (0x%x)", ntohl(mp->iid), ntohl(mp->iid));
1981 #define _(n,v) if (mp->flags & v) flag_str = format (flag_str, "%s-bit ", #n);
1982 foreach_lisp_gpe_flag_bit;
1985 fformat(vam->ofp, "%=20d%=30U%=16U%=16d%=16d%=16U"
1986 "%=16d%=16d%=16sd=16d%=16s%=16s\n",
1988 mp->is_ipv6 ? format_ip6_address : format_ip4_address,
1990 mp->is_ipv6 ? format_ip6_address : format_ip4_address,
1992 ntohl(mp->encap_fib_id),
1993 ntohl(mp->decap_fib_id),
1994 format_decap_next, ntohl(mp->dcap_next),
2006 vl_api_lisp_gpe_tunnel_details_t_handler_json (
2007 vl_api_lisp_gpe_tunnel_details_t *mp)
2009 vat_main_t *vam = &vat_main;
2010 vat_json_node_t *node = NULL;
2011 struct in6_addr ip6;
2015 next_decap_str = format(0, "%U", format_decap_next, htonl(mp->dcap_next));
2017 if (VAT_JSON_ARRAY != vam->json_tree.type) {
2018 ASSERT(VAT_JSON_NONE == vam->json_tree.type);
2019 vat_json_init_array(&vam->json_tree);
2021 node = vat_json_array_add(&vam->json_tree);
2023 vat_json_init_object(node);
2024 vat_json_object_add_uint(node, "tunel", mp->tunnels);
2026 clib_memcpy(&ip6, mp->source_ip, sizeof(ip6));
2027 vat_json_object_add_ip6(node, "source address", ip6);
2028 clib_memcpy(&ip6, mp->destination_ip, sizeof(ip6));
2029 vat_json_object_add_ip6(node, "destination address", ip6);
2031 clib_memcpy(&ip4, mp->source_ip, sizeof(ip4));
2032 vat_json_object_add_ip4(node, "source address", ip4);
2033 clib_memcpy(&ip4, mp->destination_ip, sizeof(ip4));
2034 vat_json_object_add_ip4(node, "destination address", ip4);
2036 vat_json_object_add_uint(node, "fib encap", ntohl(mp->encap_fib_id));
2037 vat_json_object_add_uint(node, "fib decap", ntohl(mp->decap_fib_id));
2038 vat_json_object_add_string_copy(node, "decap next", next_decap_str);
2039 vat_json_object_add_uint(node, "lisp version", mp->ver_res >> 6);
2040 vat_json_object_add_uint(node, "flags", mp->flags);
2041 vat_json_object_add_uint(node, "next protocol", mp->next_protocol);
2042 vat_json_object_add_uint(node, "ver_res", mp->ver_res);
2043 vat_json_object_add_uint(node, "res", mp->res);
2044 vat_json_object_add_uint(node, "iid", ntohl(mp->iid));
2046 vec_free(next_decap_str);
2050 vl_api_lisp_map_resolver_details_t_handler (
2051 vl_api_lisp_map_resolver_details_t *mp)
2053 vat_main_t *vam = &vat_main;
2055 fformat(vam->ofp, "%=20U\n",
2056 mp->is_ipv6 ? format_ip6_address : format_ip4_address,
2061 vl_api_lisp_map_resolver_details_t_handler_json (
2062 vl_api_lisp_map_resolver_details_t *mp)
2064 vat_main_t *vam = &vat_main;
2065 vat_json_node_t *node = NULL;
2066 struct in6_addr ip6;
2069 if (VAT_JSON_ARRAY != vam->json_tree.type) {
2070 ASSERT(VAT_JSON_NONE == vam->json_tree.type);
2071 vat_json_init_array(&vam->json_tree);
2073 node = vat_json_array_add(&vam->json_tree);
2075 vat_json_init_object(node);
2077 clib_memcpy(&ip6, mp->ip_address, sizeof(ip6));
2078 vat_json_object_add_ip6(node, "map resolver", ip6);
2080 clib_memcpy(&ip4, mp->ip_address, sizeof(ip4));
2081 vat_json_object_add_ip4(node, "map resolver", ip4);
2085 #define vl_api_vnet_ip4_fib_counters_t_endian vl_noop_handler
2086 #define vl_api_vnet_ip4_fib_counters_t_print vl_noop_handler
2087 #define vl_api_vnet_ip6_fib_counters_t_endian vl_noop_handler
2088 #define vl_api_vnet_ip6_fib_counters_t_print vl_noop_handler
2091 * Generate boilerplate reply handlers, which
2092 * dig the return value out of the xxx_reply_t API message,
2093 * stick it into vam->retval, and set vam->result_ready
2095 * Could also do this by pointing N message decode slots at
2096 * a single function, but that could break in subtle ways.
2099 #define foreach_standard_reply_retval_handler \
2100 _(sw_interface_set_flags_reply) \
2101 _(sw_interface_add_del_address_reply) \
2102 _(sw_interface_set_table_reply) \
2103 _(sw_interface_set_vpath_reply) \
2104 _(sw_interface_set_l2_bridge_reply) \
2105 _(bridge_domain_add_del_reply) \
2106 _(sw_interface_set_l2_xconnect_reply) \
2107 _(l2fib_add_del_reply) \
2108 _(ip_add_del_route_reply) \
2109 _(proxy_arp_add_del_reply) \
2110 _(proxy_arp_intfc_enable_disable_reply) \
2111 _(mpls_add_del_encap_reply) \
2112 _(mpls_add_del_decap_reply) \
2113 _(mpls_ethernet_add_del_tunnel_2_reply) \
2114 _(sw_interface_set_unnumbered_reply) \
2115 _(ip_neighbor_add_del_reply) \
2116 _(reset_vrf_reply) \
2117 _(oam_add_del_reply) \
2118 _(reset_fib_reply) \
2119 _(dhcp_proxy_config_reply) \
2120 _(dhcp_proxy_config_2_reply) \
2121 _(dhcp_proxy_set_vss_reply) \
2122 _(dhcp_client_config_reply) \
2123 _(set_ip_flow_hash_reply) \
2124 _(sw_interface_ip6_enable_disable_reply) \
2125 _(sw_interface_ip6_set_link_local_address_reply) \
2126 _(sw_interface_ip6nd_ra_prefix_reply) \
2127 _(sw_interface_ip6nd_ra_config_reply) \
2128 _(set_arp_neighbor_limit_reply) \
2129 _(l2_patch_add_del_reply) \
2130 _(sr_tunnel_add_del_reply) \
2131 _(classify_add_del_session_reply) \
2132 _(classify_set_interface_ip_table_reply) \
2133 _(classify_set_interface_l2_tables_reply) \
2134 _(l2tpv3_set_tunnel_cookies_reply) \
2135 _(l2tpv3_interface_enable_disable_reply) \
2136 _(l2tpv3_set_lookup_key_reply) \
2137 _(l2_fib_clear_table_reply) \
2138 _(l2_interface_efp_filter_reply) \
2139 _(l2_interface_vlan_tag_rewrite_reply) \
2140 _(modify_vhost_user_if_reply) \
2141 _(delete_vhost_user_if_reply) \
2142 _(want_ip4_arp_events_reply) \
2143 _(input_acl_set_interface_reply) \
2144 _(ipsec_spd_add_del_reply) \
2145 _(ipsec_interface_add_del_spd_reply) \
2146 _(ipsec_spd_add_del_entry_reply) \
2147 _(ipsec_sad_add_del_entry_reply) \
2148 _(ipsec_sa_set_key_reply) \
2149 _(ikev2_profile_add_del_reply) \
2150 _(ikev2_profile_set_auth_reply) \
2151 _(ikev2_profile_set_id_reply) \
2152 _(ikev2_profile_set_ts_reply) \
2153 _(ikev2_set_local_key_reply) \
2154 _(delete_loopback_reply) \
2155 _(bd_ip_mac_add_del_reply) \
2156 _(map_del_domain_reply) \
2157 _(map_add_del_rule_reply) \
2158 _(want_interface_events_reply) \
2159 _(want_stats_reply) \
2160 _(cop_interface_enable_disable_reply) \
2161 _(cop_whitelist_enable_disable_reply) \
2162 _(sw_interface_clear_stats_reply) \
2163 _(trace_profile_add_reply) \
2164 _(trace_profile_apply_reply) \
2165 _(trace_profile_del_reply) \
2166 _(lisp_add_del_locator_set_reply) \
2167 _(lisp_add_del_locator_reply) \
2168 _(lisp_add_del_local_eid_reply) \
2169 _(lisp_gpe_add_del_fwd_entry_reply) \
2170 _(lisp_add_del_map_resolver_reply) \
2171 _(lisp_gpe_enable_disable_reply) \
2172 _(lisp_gpe_add_del_iface_reply)
2175 static void vl_api_##n##_t_handler \
2176 (vl_api_##n##_t * mp) \
2178 vat_main_t * vam = &vat_main; \
2179 i32 retval = ntohl(mp->retval); \
2180 if (vam->async_mode) { \
2181 vam->async_errors += (retval < 0); \
2183 vam->retval = retval; \
2184 vam->result_ready = 1; \
2187 foreach_standard_reply_retval_handler;
2191 static void vl_api_##n##_t_handler_json \
2192 (vl_api_##n##_t * mp) \
2194 vat_main_t * vam = &vat_main; \
2195 vat_json_node_t node; \
2196 vat_json_init_object(&node); \
2197 vat_json_object_add_int(&node, "retval", ntohl(mp->retval)); \
2198 vat_json_print(vam->ofp, &node); \
2199 vam->retval = ntohl(mp->retval); \
2200 vam->result_ready = 1; \
2202 foreach_standard_reply_retval_handler;
2206 * Table of message reply handlers, must include boilerplate handlers
2210 #define foreach_vpe_api_reply_msg \
2211 _(CREATE_LOOPBACK_REPLY, create_loopback_reply) \
2212 _(SW_INTERFACE_DETAILS, sw_interface_details) \
2213 _(SW_INTERFACE_SET_FLAGS, sw_interface_set_flags) \
2214 _(SW_INTERFACE_SET_FLAGS_REPLY, sw_interface_set_flags_reply) \
2215 _(CONTROL_PING_REPLY, control_ping_reply) \
2216 _(CLI_REPLY, cli_reply) \
2217 _(SW_INTERFACE_ADD_DEL_ADDRESS_REPLY, \
2218 sw_interface_add_del_address_reply) \
2219 _(SW_INTERFACE_SET_TABLE_REPLY, sw_interface_set_table_reply) \
2220 _(SW_INTERFACE_SET_VPATH_REPLY, sw_interface_set_vpath_reply) \
2221 _(SW_INTERFACE_SET_L2_XCONNECT_REPLY, \
2222 sw_interface_set_l2_xconnect_reply) \
2223 _(SW_INTERFACE_SET_L2_BRIDGE_REPLY, \
2224 sw_interface_set_l2_bridge_reply) \
2225 _(BRIDGE_DOMAIN_ADD_DEL_REPLY, bridge_domain_add_del_reply) \
2226 _(BRIDGE_DOMAIN_DETAILS, bridge_domain_details) \
2227 _(BRIDGE_DOMAIN_SW_IF_DETAILS, bridge_domain_sw_if_details) \
2228 _(L2FIB_ADD_DEL_REPLY, l2fib_add_del_reply) \
2229 _(L2_FLAGS_REPLY, l2_flags_reply) \
2230 _(BRIDGE_FLAGS_REPLY, bridge_flags_reply) \
2231 _(TAP_CONNECT_REPLY, tap_connect_reply) \
2232 _(TAP_MODIFY_REPLY, tap_modify_reply) \
2233 _(TAP_DELETE_REPLY, tap_delete_reply) \
2234 _(SW_INTERFACE_TAP_DETAILS, sw_interface_tap_details) \
2235 _(IP_ADD_DEL_ROUTE_REPLY, ip_add_del_route_reply) \
2236 _(PROXY_ARP_ADD_DEL_REPLY, proxy_arp_add_del_reply) \
2237 _(PROXY_ARP_INTFC_ENABLE_DISABLE_REPLY, \
2238 proxy_arp_intfc_enable_disable_reply) \
2239 _(MPLS_ADD_DEL_ENCAP_REPLY, mpls_add_del_encap_reply) \
2240 _(MPLS_ADD_DEL_DECAP_REPLY, mpls_add_del_decap_reply) \
2241 _(MPLS_GRE_ADD_DEL_TUNNEL_REPLY, mpls_gre_add_del_tunnel_reply) \
2242 _(MPLS_ETHERNET_ADD_DEL_TUNNEL_REPLY, \
2243 mpls_ethernet_add_del_tunnel_reply) \
2244 _(MPLS_ETHERNET_ADD_DEL_TUNNEL_2_REPLY, \
2245 mpls_ethernet_add_del_tunnel_2_reply) \
2246 _(SW_INTERFACE_SET_UNNUMBERED_REPLY, \
2247 sw_interface_set_unnumbered_reply) \
2248 _(IP_NEIGHBOR_ADD_DEL_REPLY, ip_neighbor_add_del_reply) \
2249 _(RESET_VRF_REPLY, reset_vrf_reply) \
2250 _(CREATE_VLAN_SUBIF_REPLY, create_vlan_subif_reply) \
2251 _(CREATE_SUBIF_REPLY, create_subif_reply) \
2252 _(OAM_ADD_DEL_REPLY, oam_add_del_reply) \
2253 _(RESET_FIB_REPLY, reset_fib_reply) \
2254 _(DHCP_PROXY_CONFIG_REPLY, dhcp_proxy_config_reply) \
2255 _(DHCP_PROXY_CONFIG_2_REPLY, dhcp_proxy_config_2_reply) \
2256 _(DHCP_PROXY_SET_VSS_REPLY, dhcp_proxy_set_vss_reply) \
2257 _(DHCP_CLIENT_CONFIG_REPLY, dhcp_client_config_reply) \
2258 _(SET_IP_FLOW_HASH_REPLY, set_ip_flow_hash_reply) \
2259 _(SW_INTERFACE_IP6_ENABLE_DISABLE_REPLY, \
2260 sw_interface_ip6_enable_disable_reply) \
2261 _(SW_INTERFACE_IP6_SET_LINK_LOCAL_ADDRESS_REPLY, \
2262 sw_interface_ip6_set_link_local_address_reply) \
2263 _(SW_INTERFACE_IP6ND_RA_PREFIX_REPLY, \
2264 sw_interface_ip6nd_ra_prefix_reply) \
2265 _(SW_INTERFACE_IP6ND_RA_CONFIG_REPLY, \
2266 sw_interface_ip6nd_ra_config_reply) \
2267 _(SET_ARP_NEIGHBOR_LIMIT_REPLY, set_arp_neighbor_limit_reply) \
2268 _(L2_PATCH_ADD_DEL_REPLY, l2_patch_add_del_reply) \
2269 _(SR_TUNNEL_ADD_DEL_REPLY, sr_tunnel_add_del_reply) \
2270 _(CLASSIFY_ADD_DEL_TABLE_REPLY, classify_add_del_table_reply) \
2271 _(CLASSIFY_ADD_DEL_SESSION_REPLY, classify_add_del_session_reply) \
2272 _(CLASSIFY_SET_INTERFACE_IP_TABLE_REPLY, \
2273 classify_set_interface_ip_table_reply) \
2274 _(CLASSIFY_SET_INTERFACE_L2_TABLES_REPLY, \
2275 classify_set_interface_l2_tables_reply) \
2276 _(GET_NODE_INDEX_REPLY, get_node_index_reply) \
2277 _(ADD_NODE_NEXT_REPLY, add_node_next_reply) \
2278 _(L2TPV3_CREATE_TUNNEL_REPLY, l2tpv3_create_tunnel_reply) \
2279 _(L2TPV3_SET_TUNNEL_COOKIES_REPLY, l2tpv3_set_tunnel_cookies_reply) \
2280 _(L2TPV3_INTERFACE_ENABLE_DISABLE_REPLY, \
2281 l2tpv3_interface_enable_disable_reply) \
2282 _(L2TPV3_SET_LOOKUP_KEY_REPLY, l2tpv3_set_lookup_key_reply) \
2283 _(SW_IF_L2TPV3_TUNNEL_DETAILS, sw_if_l2tpv3_tunnel_details) \
2284 _(VXLAN_ADD_DEL_TUNNEL_REPLY, vxlan_add_del_tunnel_reply) \
2285 _(VXLAN_TUNNEL_DETAILS, vxlan_tunnel_details) \
2286 _(L2_FIB_CLEAR_TABLE_REPLY, l2_fib_clear_table_reply) \
2287 _(L2_INTERFACE_EFP_FILTER_REPLY, l2_interface_efp_filter_reply) \
2288 _(L2_INTERFACE_VLAN_TAG_REWRITE_REPLY, l2_interface_vlan_tag_rewrite_reply) \
2289 _(SW_INTERFACE_VHOST_USER_DETAILS, sw_interface_vhost_user_details) \
2290 _(CREATE_VHOST_USER_IF_REPLY, create_vhost_user_if_reply) \
2291 _(MODIFY_VHOST_USER_IF_REPLY, modify_vhost_user_if_reply) \
2292 _(DELETE_VHOST_USER_IF_REPLY, delete_vhost_user_if_reply) \
2293 _(SHOW_VERSION_REPLY, show_version_reply) \
2294 _(NSH_GRE_ADD_DEL_TUNNEL_REPLY, nsh_gre_add_del_tunnel_reply) \
2295 _(L2_FIB_TABLE_ENTRY, l2_fib_table_entry) \
2296 _(NSH_VXLAN_GPE_ADD_DEL_TUNNEL_REPLY, nsh_vxlan_gpe_add_del_tunnel_reply) \
2297 _(LISP_GPE_ADD_DEL_TUNNEL_REPLY, lisp_gpe_add_del_tunnel_reply) \
2298 _(INTERFACE_NAME_RENUMBER_REPLY, interface_name_renumber_reply) \
2299 _(WANT_IP4_ARP_EVENTS_REPLY, want_ip4_arp_events_reply) \
2300 _(IP4_ARP_EVENT, ip4_arp_event) \
2301 _(INPUT_ACL_SET_INTERFACE_REPLY, input_acl_set_interface_reply) \
2302 _(IP_ADDRESS_DETAILS, ip_address_details) \
2303 _(IP_DETAILS, ip_details) \
2304 _(IPSEC_SPD_ADD_DEL_REPLY, ipsec_spd_add_del_reply) \
2305 _(IPSEC_INTERFACE_ADD_DEL_SPD_REPLY, ipsec_interface_add_del_spd_reply) \
2306 _(IPSEC_SPD_ADD_DEL_ENTRY_REPLY, ipsec_spd_add_del_entry_reply) \
2307 _(IPSEC_SAD_ADD_DEL_ENTRY_REPLY, ipsec_sad_add_del_entry_reply) \
2308 _(IPSEC_SA_SET_KEY_REPLY, ipsec_sa_set_key_reply) \
2309 _(IKEV2_PROFILE_ADD_DEL_REPLY, ikev2_profile_add_del_reply) \
2310 _(IKEV2_PROFILE_SET_AUTH_REPLY, ikev2_profile_set_auth_reply) \
2311 _(IKEV2_PROFILE_SET_ID_REPLY, ikev2_profile_set_id_reply) \
2312 _(IKEV2_PROFILE_SET_TS_REPLY, ikev2_profile_set_ts_reply) \
2313 _(IKEV2_SET_LOCAL_KEY_REPLY, ikev2_set_local_key_reply) \
2314 _(DELETE_LOOPBACK_REPLY, delete_loopback_reply) \
2315 _(BD_IP_MAC_ADD_DEL_REPLY, bd_ip_mac_add_del_reply) \
2316 _(DHCP_COMPL_EVENT, dhcp_compl_event) \
2317 _(VNET_INTERFACE_COUNTERS, vnet_interface_counters) \
2318 _(VNET_IP4_FIB_COUNTERS, vnet_ip4_fib_counters) \
2319 _(VNET_IP6_FIB_COUNTERS, vnet_ip6_fib_counters) \
2320 _(MAP_ADD_DOMAIN_REPLY, map_add_domain_reply) \
2321 _(MAP_DEL_DOMAIN_REPLY, map_del_domain_reply) \
2322 _(MAP_ADD_DEL_RULE_REPLY, map_add_del_rule_reply) \
2323 _(MAP_DOMAIN_DETAILS, map_domain_details) \
2324 _(MAP_RULE_DETAILS, map_rule_details) \
2325 _(WANT_INTERFACE_EVENTS_REPLY, want_interface_events_reply) \
2326 _(WANT_STATS_REPLY, want_stats_reply) \
2327 _(GET_FIRST_MSG_ID_REPLY, get_first_msg_id_reply) \
2328 _(COP_INTERFACE_ENABLE_DISABLE_REPLY, cop_interface_enable_disable_reply) \
2329 _(COP_WHITELIST_ENABLE_DISABLE_REPLY, cop_whitelist_enable_disable_reply) \
2330 _(GET_NODE_GRAPH_REPLY, get_node_graph_reply) \
2331 _(SW_INTERFACE_CLEAR_STATS_REPLY, sw_interface_clear_stats_reply) \
2332 _(TRACE_PROFILE_ADD_REPLY, trace_profile_add_reply) \
2333 _(TRACE_PROFILE_APPLY_REPLY, trace_profile_apply_reply) \
2334 _(TRACE_PROFILE_DEL_REPLY, trace_profile_del_reply) \
2335 _(LISP_ADD_DEL_LOCATOR_SET_REPLY, lisp_add_del_locator_set_reply) \
2336 _(LISP_ADD_DEL_LOCATOR_REPLY, lisp_add_del_locator_reply) \
2337 _(LISP_ADD_DEL_LOCAL_EID_REPLY, lisp_add_del_local_eid_reply) \
2338 _(LISP_GPE_ADD_DEL_FWD_ENTRY_REPLY, lisp_gpe_add_del_fwd_entry_reply) \
2339 _(LISP_ADD_DEL_MAP_RESOLVER_REPLY, lisp_add_del_map_resolver_reply) \
2340 _(LISP_GPE_ENABLE_DISABLE_REPLY, lisp_gpe_enable_disable_reply) \
2341 _(LISP_GPE_ADD_DEL_IFACE_REPLY, lisp_gpe_add_del_iface_reply) \
2342 _(LISP_LOCATOR_SET_DETAILS, lisp_locator_set_details) \
2343 _(LISP_LOCAL_EID_TABLE_DETAILS, lisp_local_eid_table_details) \
2344 _(LISP_GPE_TUNNEL_DETAILS, lisp_gpe_tunnel_details) \
2345 _(LISP_MAP_RESOLVER_DETAILS, lisp_map_resolver_details)
2347 /* M: construct, but don't yet send a message */
2351 vam->result_ready = 0; \
2352 mp = vl_msg_api_alloc(sizeof(*mp)); \
2353 memset (mp, 0, sizeof (*mp)); \
2354 mp->_vl_msg_id = ntohs (VL_API_##T); \
2355 mp->client_index = vam->my_client_index; \
2360 vam->result_ready = 0; \
2361 mp = vl_msg_api_alloc(sizeof(*mp)+(n)); \
2362 memset (mp, 0, sizeof (*mp)); \
2363 mp->_vl_msg_id = ntohs (VL_API_##T); \
2364 mp->client_index = vam->my_client_index; \
2368 /* S: send a message */
2369 #define S (vl_msg_api_send_shmem (vam->vl_input_queue, (u8 *)&mp))
2371 /* W: wait for results, with timeout */
2374 timeout = vat_time_now (vam) + 1.0; \
2376 while (vat_time_now (vam) < timeout) { \
2377 if (vam->result_ready == 1) { \
2378 return (vam->retval); \
2390 #define STR_VTR_OP_CASE(op) \
2391 case L2_VTR_ ## op: \
2394 static const char *str_vtr_op(u32 vtr_op)
2397 STR_VTR_OP_CASE(DISABLED);
2398 STR_VTR_OP_CASE(PUSH_1);
2399 STR_VTR_OP_CASE(PUSH_2);
2400 STR_VTR_OP_CASE(POP_1);
2401 STR_VTR_OP_CASE(POP_2);
2402 STR_VTR_OP_CASE(TRANSLATE_1_1);
2403 STR_VTR_OP_CASE(TRANSLATE_1_2);
2404 STR_VTR_OP_CASE(TRANSLATE_2_1);
2405 STR_VTR_OP_CASE(TRANSLATE_2_2);
2411 static int dump_sub_interface_table (vat_main_t * vam)
2413 const sw_interface_subif_t * sub = NULL;
2415 if (vam->json_output) {
2416 clib_warning ("JSON output supported only for VPE API calls and dump_stats_table");
2421 "%-30s%-12s%-11s%-7s%-5s%-9s%-9s%-6s%-8s%-10s%-10s\n",
2422 "Interface", "sw_if_index",
2423 "sub id", "dot1ad", "tags", "outer id",
2424 "inner id", "exact", "default",
2425 "outer any", "inner any");
2427 vec_foreach (sub, vam->sw_if_subif_table) {
2429 "%-30s%-12d%-11d%-7s%-5d%-9d%-9d%-6d%-8d%-10d%-10d\n",
2430 sub->interface_name,
2432 sub->sub_id, sub->sub_dot1ad ? "dot1ad" : "dot1q",
2433 sub->sub_number_of_tags, sub->sub_outer_vlan_id,
2434 sub->sub_inner_vlan_id, sub->sub_exact_match, sub->sub_default,
2435 sub->sub_outer_vlan_id_any, sub->sub_inner_vlan_id_any);
2436 if (sub->vtr_op != L2_VTR_DISABLED) {
2438 " vlan-tag-rewrite - op: %-14s [ dot1q: %d "
2439 "tag1: %d tag2: %d ]\n",
2440 str_vtr_op(sub->vtr_op), sub->vtr_push_dot1q,
2441 sub->vtr_tag1, sub->vtr_tag2);
2448 static int name_sort_cmp (void * a1, void * a2)
2450 name_sort_t * n1 = a1;
2451 name_sort_t * n2 = a2;
2453 return strcmp ((char *)n1->name, (char *)n2->name);
2456 static int dump_interface_table (vat_main_t * vam)
2459 name_sort_t * nses = 0, * ns;
2461 if (vam->json_output) {
2462 clib_warning ("JSON output supported only for VPE API calls and dump_stats_table");
2466 hash_foreach_pair (p, vam->sw_if_index_by_interface_name,
2468 vec_add2 (nses, ns, 1);
2469 ns->name = (u8 *)(p->key);
2470 ns->value = (u32) p->value[0];
2473 vec_sort_with_function (nses, name_sort_cmp);
2475 fformat (vam->ofp, "%-25s%-15s\n", "Interface", "sw_if_index");
2476 vec_foreach (ns, nses) {
2477 fformat (vam->ofp, "%-25s%-15d\n", ns->name, ns->value);
2483 static int dump_ip_table (vat_main_t * vam, int is_ipv6)
2485 const ip_details_t * det = NULL;
2486 const ip_address_details_t * address = NULL;
2497 vec_foreach (det, vam->ip_details_by_sw_if_index[is_ipv6]) {
2499 if (!det->present) {
2507 "Address", "Prefix length");
2511 vec_foreach (address, det->addr) {
2514 is_ipv6 ? format_ip6_address : format_ip4_address,
2516 address->prefix_length);
2523 static int dump_ipv4_table (vat_main_t * vam)
2525 if (vam->json_output) {
2526 clib_warning ("JSON output supported only for VPE API calls and dump_stats_table");
2530 return dump_ip_table (vam, 0);
2533 static int dump_ipv6_table (vat_main_t * vam)
2535 if (vam->json_output) {
2536 clib_warning ("JSON output supported only for VPE API calls and dump_stats_table");
2540 return dump_ip_table (vam, 1);
2543 static char* counter_type_to_str (u8 counter_type, u8 is_combined)
2546 switch(counter_type) {
2547 case VNET_INTERFACE_COUNTER_DROP:
2549 case VNET_INTERFACE_COUNTER_PUNT:
2551 case VNET_INTERFACE_COUNTER_IP4:
2553 case VNET_INTERFACE_COUNTER_IP6:
2555 case VNET_INTERFACE_COUNTER_RX_NO_BUF:
2557 case VNET_INTERFACE_COUNTER_RX_MISS:
2559 case VNET_INTERFACE_COUNTER_RX_ERROR:
2561 case VNET_INTERFACE_COUNTER_TX_ERROR:
2564 return "INVALID-COUNTER-TYPE";
2567 switch(counter_type) {
2568 case VNET_INTERFACE_COUNTER_RX:
2570 case VNET_INTERFACE_COUNTER_TX:
2573 return "INVALID-COUNTER-TYPE";
2578 static int dump_stats_table (vat_main_t * vam)
2580 vat_json_node_t node;
2581 vat_json_node_t *msg_array;
2582 vat_json_node_t *msg;
2583 vat_json_node_t *counter_array;
2584 vat_json_node_t *counter;
2585 interface_counter_t c;
2587 ip4_fib_counter_t *c4;
2588 ip6_fib_counter_t *c6;
2591 if (!vam->json_output) {
2592 clib_warning ("dump_stats_table supported only in JSON format");
2596 vat_json_init_object(&node);
2598 /* interface counters */
2599 msg_array = vat_json_object_add(&node, "interface_counters");
2600 vat_json_init_array(msg_array);
2601 for (i = 0; i < vec_len(vam->simple_interface_counters); i++) {
2602 msg = vat_json_array_add(msg_array);
2603 vat_json_init_object(msg);
2604 vat_json_object_add_string_copy(msg, "vnet_counter_type",
2605 (u8*)counter_type_to_str(i, 0));
2606 vat_json_object_add_int(msg, "is_combined", 0);
2607 counter_array = vat_json_object_add(msg, "data");
2608 vat_json_init_array(counter_array);
2609 for (j = 0; j < vec_len(vam->simple_interface_counters[i]); j++) {
2610 packets = vam->simple_interface_counters[i][j];
2611 vat_json_array_add_uint(counter_array, packets);
2614 for (i = 0; i < vec_len(vam->combined_interface_counters); i++) {
2615 msg = vat_json_array_add(msg_array);
2616 vat_json_init_object(msg);
2617 vat_json_object_add_string_copy(msg, "vnet_counter_type",
2618 (u8*)counter_type_to_str(i, 1));
2619 vat_json_object_add_int(msg, "is_combined", 1);
2620 counter_array = vat_json_object_add(msg, "data");
2621 vat_json_init_array(counter_array);
2622 for (j = 0; j < vec_len(vam->combined_interface_counters[i]); j++) {
2623 c = vam->combined_interface_counters[i][j];
2624 counter = vat_json_array_add(counter_array);
2625 vat_json_init_object(counter);
2626 vat_json_object_add_uint(counter, "packets", c.packets);
2627 vat_json_object_add_uint(counter, "bytes", c.bytes);
2631 /* ip4 fib counters */
2632 msg_array = vat_json_object_add(&node, "ip4_fib_counters");
2633 vat_json_init_array(msg_array);
2634 for (i = 0; i < vec_len(vam->ip4_fib_counters); i++) {
2635 msg = vat_json_array_add(msg_array);
2636 vat_json_init_object(msg);
2637 vat_json_object_add_uint(msg, "vrf_id", vam->ip4_fib_counters_vrf_id_by_index[i]);
2638 counter_array = vat_json_object_add(msg, "c");
2639 vat_json_init_array(counter_array);
2640 for (j = 0; j < vec_len(vam->ip4_fib_counters[i]); j++) {
2641 counter = vat_json_array_add(counter_array);
2642 vat_json_init_object(counter);
2643 c4 = &vam->ip4_fib_counters[i][j];
2644 vat_json_object_add_ip4(counter, "address", c4->address);
2645 vat_json_object_add_uint(counter, "address_length", c4->address_length);
2646 vat_json_object_add_uint(counter, "packets", c4->packets);
2647 vat_json_object_add_uint(counter, "bytes", c4->bytes);
2651 /* ip6 fib counters */
2652 msg_array = vat_json_object_add(&node, "ip6_fib_counters");
2653 vat_json_init_array(msg_array);
2654 for (i = 0; i < vec_len(vam->ip6_fib_counters); i++) {
2655 msg = vat_json_array_add(msg_array);
2656 vat_json_init_object(msg);
2657 vat_json_object_add_uint(msg, "vrf_id", vam->ip6_fib_counters_vrf_id_by_index[i]);
2658 counter_array = vat_json_object_add(msg, "c");
2659 vat_json_init_array(counter_array);
2660 for (j = 0; j < vec_len(vam->ip6_fib_counters[i]); j++) {
2661 counter = vat_json_array_add(counter_array);
2662 vat_json_init_object(counter);
2663 c6 = &vam->ip6_fib_counters[i][j];
2664 vat_json_object_add_ip6(counter, "address", c6->address);
2665 vat_json_object_add_uint(counter, "address_length", c6->address_length);
2666 vat_json_object_add_uint(counter, "packets", c6->packets);
2667 vat_json_object_add_uint(counter, "bytes", c6->bytes);
2671 vat_json_print(vam->ofp, &node);
2672 vat_json_free(&node);
2677 int exec (vat_main_t * vam)
2679 api_main_t * am = &api_main;
2680 vl_api_cli_request_t *mp;
2684 unformat_input_t * i = vam->input;
2686 if (vec_len(i->buffer) == 0)
2689 if (vam->exec_mode == 0 && unformat (i, "mode")) {
2693 if (vam->exec_mode == 1 &&
2694 (unformat (i, "exit") || unformat (i, "quit"))) {
2700 M(CLI_REQUEST, cli_request);
2703 * Copy cmd into shared memory.
2704 * In order for the CLI command to work, it
2705 * must be a vector ending in \n, not a C-string ending
2708 pthread_mutex_lock (&am->vlib_rp->mutex);
2709 oldheap = svm_push_data_heap (am->vlib_rp);
2711 vec_validate (cmd, vec_len(vam->input->buffer)-1);
2712 clib_memcpy (cmd, vam->input->buffer, vec_len(vam->input->buffer));
2714 svm_pop_heap (oldheap);
2715 pthread_mutex_unlock (&am->vlib_rp->mutex);
2717 mp->cmd_in_shmem = (u64) cmd;
2719 timeout = vat_time_now (vam) + 10.0;
2721 while (vat_time_now (vam) < timeout) {
2722 if (vam->result_ready == 1) {
2724 if (vam->shmem_result != NULL)
2725 fformat (vam->ofp, "%s", vam->shmem_result);
2726 pthread_mutex_lock (&am->vlib_rp->mutex);
2727 oldheap = svm_push_data_heap (am->vlib_rp);
2729 free_me = (u8 *)vam->shmem_result;
2732 svm_pop_heap (oldheap);
2733 pthread_mutex_unlock (&am->vlib_rp->mutex);
2740 static int api_create_loopback (vat_main_t * vam)
2742 unformat_input_t * i = vam->input;
2743 vl_api_create_loopback_t *mp;
2748 memset (mac_address, 0, sizeof (mac_address));
2750 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
2752 if (unformat (i, "mac %U", unformat_ethernet_address, mac_address))
2758 /* Construct the API message */
2759 M(CREATE_LOOPBACK, create_loopback);
2761 clib_memcpy (mp->mac_address, mac_address, sizeof (mac_address));
2766 static int api_delete_loopback (vat_main_t * vam)
2768 unformat_input_t * i = vam->input;
2769 vl_api_delete_loopback_t *mp;
2771 u32 sw_if_index = ~0;
2773 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
2775 if (unformat (i, "sw_if_index %d", &sw_if_index))
2781 if (sw_if_index == ~0)
2783 errmsg ("missing sw_if_index\n");
2787 /* Construct the API message */
2788 M(DELETE_LOOPBACK, delete_loopback);
2789 mp->sw_if_index = ntohl (sw_if_index);
2794 static int api_want_stats (vat_main_t * vam)
2796 unformat_input_t * i = vam->input;
2797 vl_api_want_stats_t * mp;
2801 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
2803 if (unformat (i, "enable"))
2805 else if (unformat (i, "disable"))
2813 errmsg ("missing enable|disable\n");
2817 M(WANT_STATS, want_stats);
2818 mp->enable_disable = enable;
2823 static int api_want_interface_events (vat_main_t * vam)
2825 unformat_input_t * i = vam->input;
2826 vl_api_want_interface_events_t * mp;
2830 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
2832 if (unformat (i, "enable"))
2834 else if (unformat (i, "disable"))
2842 errmsg ("missing enable|disable\n");
2846 M(WANT_INTERFACE_EVENTS, want_interface_events);
2847 mp->enable_disable = enable;
2849 vam->interface_event_display = enable;
2855 /* Note: non-static, called once to set up the initial intfc table */
2856 int api_sw_interface_dump (vat_main_t * vam)
2858 vl_api_sw_interface_dump_t *mp;
2861 name_sort_t * nses = 0, * ns;
2862 sw_interface_subif_t * sub = NULL;
2864 /* Toss the old name table */
2865 hash_foreach_pair (p, vam->sw_if_index_by_interface_name,
2867 vec_add2 (nses, ns, 1);
2868 ns->name = (u8 *)(p->key);
2869 ns->value = (u32) p->value[0];
2872 hash_free (vam->sw_if_index_by_interface_name);
2874 vec_foreach (ns, nses)
2875 vec_free (ns->name);
2879 vec_foreach (sub, vam->sw_if_subif_table) {
2880 vec_free (sub->interface_name);
2882 vec_free (vam->sw_if_subif_table);
2884 /* recreate the interface name hash table */
2885 vam->sw_if_index_by_interface_name
2886 = hash_create_string (0, sizeof(uword));
2888 /* Get list of ethernets */
2889 M(SW_INTERFACE_DUMP, sw_interface_dump);
2890 mp->name_filter_valid = 1;
2891 strncpy ((char *) mp->name_filter, "Ether", sizeof(mp->name_filter)-1);
2894 /* and local / loopback interfaces */
2895 M(SW_INTERFACE_DUMP, sw_interface_dump);
2896 mp->name_filter_valid = 1;
2897 strncpy ((char *) mp->name_filter, "lo", sizeof(mp->name_filter)-1);
2900 /* and vxlan tunnel interfaces */
2901 M(SW_INTERFACE_DUMP, sw_interface_dump);
2902 mp->name_filter_valid = 1;
2903 strncpy ((char *) mp->name_filter, "vxlan", sizeof(mp->name_filter)-1);
2906 /* and host (af_packet) interfaces */
2907 M(SW_INTERFACE_DUMP, sw_interface_dump);
2908 mp->name_filter_valid = 1;
2909 strncpy ((char *) mp->name_filter, "host", sizeof(mp->name_filter)-1);
2912 /* and l2tpv3 tunnel interfaces */
2913 M(SW_INTERFACE_DUMP, sw_interface_dump);
2914 mp->name_filter_valid = 1;
2915 strncpy ((char *) mp->name_filter, "l2tpv3_tunnel", sizeof(mp->name_filter)-1);
2918 /* Use a control ping for synchronization */
2920 vl_api_control_ping_t * mp;
2921 M(CONTROL_PING, control_ping);
2927 static int api_sw_interface_set_flags (vat_main_t * vam)
2929 unformat_input_t * i = vam->input;
2930 vl_api_sw_interface_set_flags_t *mp;
2933 u8 sw_if_index_set = 0;
2934 u8 admin_up = 0, link_up = 0;
2936 /* Parse args required to build the message */
2937 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
2938 if (unformat (i, "admin-up"))
2940 else if (unformat (i, "admin-down"))
2942 else if (unformat (i, "link-up"))
2944 else if (unformat (i, "link-down"))
2946 else if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
2947 sw_if_index_set = 1;
2948 else if (unformat (i, "sw_if_index %d", &sw_if_index))
2949 sw_if_index_set = 1;
2954 if (sw_if_index_set == 0) {
2955 errmsg ("missing interface name or sw_if_index\n");
2959 /* Construct the API message */
2960 M(SW_INTERFACE_SET_FLAGS, sw_interface_set_flags);
2961 mp->sw_if_index = ntohl (sw_if_index);
2962 mp->admin_up_down = admin_up;
2963 mp->link_up_down = link_up;
2968 /* Wait for a reply, return the good/bad news... */
2972 static int api_sw_interface_clear_stats (vat_main_t * vam)
2974 unformat_input_t * i = vam->input;
2975 vl_api_sw_interface_clear_stats_t *mp;
2978 u8 sw_if_index_set = 0;
2980 /* Parse args required to build the message */
2981 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
2982 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
2983 sw_if_index_set = 1;
2984 else if (unformat (i, "sw_if_index %d", &sw_if_index))
2985 sw_if_index_set = 1;
2990 /* Construct the API message */
2991 M(SW_INTERFACE_CLEAR_STATS, sw_interface_clear_stats);
2993 if (sw_if_index_set == 1)
2994 mp->sw_if_index = ntohl (sw_if_index);
2996 mp->sw_if_index = ~0;
3001 /* Wait for a reply, return the good/bad news... */
3005 static int api_sw_interface_add_del_address (vat_main_t * vam)
3007 unformat_input_t * i = vam->input;
3008 vl_api_sw_interface_add_del_address_t *mp;
3011 u8 sw_if_index_set = 0;
3012 u8 is_add = 1, del_all = 0;
3013 u32 address_length = 0;
3014 u8 v4_address_set = 0;
3015 u8 v6_address_set = 0;
3016 ip4_address_t v4address;
3017 ip6_address_t v6address;
3019 /* Parse args required to build the message */
3020 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
3021 if (unformat (i, "del-all"))
3023 else if (unformat (i, "del"))
3025 else if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
3026 sw_if_index_set = 1;
3027 else if (unformat (i, "sw_if_index %d", &sw_if_index))
3028 sw_if_index_set = 1;
3029 else if (unformat (i, "%U/%d",
3030 unformat_ip4_address, &v4address,
3033 else if (unformat (i, "%U/%d",
3034 unformat_ip6_address, &v6address,
3041 if (sw_if_index_set == 0) {
3042 errmsg ("missing interface name or sw_if_index\n");
3045 if (v4_address_set && v6_address_set) {
3046 errmsg ("both v4 and v6 addresses set\n");
3049 if (!v4_address_set && !v6_address_set && !del_all) {
3050 errmsg ("no addresses set\n");
3054 /* Construct the API message */
3055 M(SW_INTERFACE_ADD_DEL_ADDRESS, sw_interface_add_del_address);
3057 mp->sw_if_index = ntohl (sw_if_index);
3058 mp->is_add = is_add;
3059 mp->del_all = del_all;
3060 if (v6_address_set) {
3062 clib_memcpy (mp->address, &v6address, sizeof (v6address));
3064 clib_memcpy (mp->address, &v4address, sizeof (v4address));
3066 mp->address_length = address_length;
3071 /* Wait for a reply, return good/bad news */
3075 static int api_sw_interface_set_table (vat_main_t * vam)
3077 unformat_input_t * i = vam->input;
3078 vl_api_sw_interface_set_table_t *mp;
3080 u32 sw_if_index, vrf_id = 0;
3081 u8 sw_if_index_set = 0;
3084 /* Parse args required to build the message */
3085 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
3086 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
3087 sw_if_index_set = 1;
3088 else if (unformat (i, "sw_if_index %d", &sw_if_index))
3089 sw_if_index_set = 1;
3090 else if (unformat (i, "vrf %d", &vrf_id))
3092 else if (unformat (i, "ipv6"))
3098 if (sw_if_index_set == 0) {
3099 errmsg ("missing interface name or sw_if_index\n");
3103 /* Construct the API message */
3104 M(SW_INTERFACE_SET_TABLE, sw_interface_set_table);
3106 mp->sw_if_index = ntohl (sw_if_index);
3107 mp->is_ipv6 = is_ipv6;
3108 mp->vrf_id = ntohl (vrf_id);
3113 /* Wait for a reply... */
3117 static int api_sw_interface_set_vpath (vat_main_t * vam)
3119 unformat_input_t * i = vam->input;
3120 vl_api_sw_interface_set_vpath_t *mp;
3122 u32 sw_if_index = 0;
3123 u8 sw_if_index_set = 0;
3126 /* Parse args required to build the message */
3127 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
3128 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
3129 sw_if_index_set = 1;
3130 else if (unformat (i, "sw_if_index %d", &sw_if_index))
3131 sw_if_index_set = 1;
3132 else if (unformat (i, "enable"))
3134 else if (unformat (i, "disable"))
3140 if (sw_if_index_set == 0) {
3141 errmsg ("missing interface name or sw_if_index\n");
3145 /* Construct the API message */
3146 M(SW_INTERFACE_SET_VPATH, sw_interface_set_vpath);
3148 mp->sw_if_index = ntohl (sw_if_index);
3149 mp->enable = is_enable;
3154 /* Wait for a reply... */
3158 static int api_sw_interface_set_l2_xconnect (vat_main_t * vam)
3160 unformat_input_t * i = vam->input;
3161 vl_api_sw_interface_set_l2_xconnect_t *mp;
3164 u8 rx_sw_if_index_set = 0;
3166 u8 tx_sw_if_index_set = 0;
3169 /* Parse args required to build the message */
3170 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
3171 if (unformat (i, "rx_sw_if_index %d", &rx_sw_if_index))
3172 rx_sw_if_index_set = 1;
3173 else if (unformat (i, "tx_sw_if_index %d", &tx_sw_if_index))
3174 tx_sw_if_index_set = 1;
3175 else if (unformat (i, "rx")) {
3176 if (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
3177 if (unformat (i, "%U", unformat_sw_if_index, vam,
3179 rx_sw_if_index_set = 1;
3182 } else if (unformat (i, "tx")) {
3183 if (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
3184 if (unformat (i, "%U", unformat_sw_if_index, vam,
3186 tx_sw_if_index_set = 1;
3189 } else if (unformat (i, "enable"))
3191 else if (unformat (i, "disable"))
3197 if (rx_sw_if_index_set == 0) {
3198 errmsg ("missing rx interface name or rx_sw_if_index\n");
3202 if (enable && (tx_sw_if_index_set == 0)) {
3203 errmsg ("missing tx interface name or tx_sw_if_index\n");
3207 M(SW_INTERFACE_SET_L2_XCONNECT, sw_interface_set_l2_xconnect);
3209 mp->rx_sw_if_index = ntohl(rx_sw_if_index);
3210 mp->tx_sw_if_index = ntohl(tx_sw_if_index);
3211 mp->enable = enable;
3218 static int api_sw_interface_set_l2_bridge (vat_main_t * vam)
3220 unformat_input_t * i = vam->input;
3221 vl_api_sw_interface_set_l2_bridge_t *mp;
3224 u8 rx_sw_if_index_set = 0;
3231 /* Parse args required to build the message */
3232 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
3233 if (unformat (i, "sw_if_index %d", &rx_sw_if_index))
3234 rx_sw_if_index_set = 1;
3235 else if (unformat (i, "bd_id %d", &bd_id))
3237 else if (unformat (i, "%U", unformat_sw_if_index, vam,
3239 rx_sw_if_index_set = 1;
3240 else if (unformat (i, "shg %d", &shg))
3242 else if (unformat (i, "bvi"))
3244 else if (unformat (i, "enable"))
3246 else if (unformat (i, "disable"))
3252 if (rx_sw_if_index_set == 0) {
3253 errmsg ("missing rx interface name or sw_if_index\n");
3257 if (enable && (bd_id_set == 0)) {
3258 errmsg ("missing bridge domain\n");
3262 M(SW_INTERFACE_SET_L2_BRIDGE, sw_interface_set_l2_bridge);
3264 mp->rx_sw_if_index = ntohl(rx_sw_if_index);
3265 mp->bd_id = ntohl(bd_id);
3268 mp->enable = enable;
3275 static int api_bridge_domain_dump (vat_main_t * vam)
3277 unformat_input_t * i = vam->input;
3278 vl_api_bridge_domain_dump_t *mp;
3282 /* Parse args required to build the message */
3283 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
3284 if (unformat (i, "bd_id %d", &bd_id))
3290 M(BRIDGE_DOMAIN_DUMP, bridge_domain_dump);
3291 mp->bd_id = ntohl(bd_id);
3294 /* Use a control ping for synchronization */
3296 vl_api_control_ping_t * mp;
3297 M(CONTROL_PING, control_ping);
3306 static int api_bridge_domain_add_del (vat_main_t * vam)
3308 unformat_input_t * i = vam->input;
3309 vl_api_bridge_domain_add_del_t *mp;
3313 u32 flood = 1, forward = 1, learn = 1, uu_flood = 1, arp_term = 0;
3315 /* Parse args required to build the message */
3316 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
3317 if (unformat (i, "bd_id %d", &bd_id))
3319 else if (unformat (i, "flood %d", &flood))
3321 else if (unformat (i, "uu-flood %d", &uu_flood))
3323 else if (unformat (i, "forward %d", &forward))
3325 else if (unformat (i, "learn %d", &learn))
3327 else if (unformat (i, "arp-term %d", &arp_term))
3329 else if (unformat (i, "del")) {
3331 flood = uu_flood = forward = learn = 0;
3338 errmsg ("missing bridge domain\n");
3342 M(BRIDGE_DOMAIN_ADD_DEL, bridge_domain_add_del);
3344 mp->bd_id = ntohl(bd_id);
3346 mp->uu_flood = uu_flood;
3347 mp->forward = forward;
3349 mp->arp_term = arp_term;
3350 mp->is_add = is_add;
3357 static int api_l2fib_add_del (vat_main_t * vam)
3359 unformat_input_t * i = vam->input;
3360 vl_api_l2fib_add_del_t *mp;
3367 u8 sw_if_index_set = 0;
3372 /* Parse args required to build the message */
3373 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
3374 if (unformat (i, "mac %U", unformat_ethernet_address, &mac))
3376 else if (unformat (i, "bd_id %d", &bd_id))
3378 else if (unformat (i, "sw_if_index %d", &sw_if_index))
3379 sw_if_index_set = 1;
3380 else if (unformat (i, "sw_if")) {
3381 if (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
3382 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
3383 sw_if_index_set = 1;
3386 } else if (unformat (i, "static"))
3388 else if (unformat (i, "filter")) {
3391 } else if (unformat (i, "del"))
3398 errmsg ("missing mac address\n");
3402 if (bd_id_set == 0) {
3403 errmsg ("missing bridge domain\n");
3407 if (is_add && (sw_if_index_set == 0)) {
3408 errmsg ("missing interface name or sw_if_index\n");
3412 M(L2FIB_ADD_DEL, l2fib_add_del);
3415 mp->bd_id = ntohl(bd_id);
3416 mp->is_add = is_add;
3419 mp->sw_if_index = ntohl(sw_if_index);
3420 mp->static_mac = static_mac;
3421 mp->filter_mac = filter_mac;
3429 static int api_l2_flags (vat_main_t * vam)
3431 unformat_input_t * i = vam->input;
3432 vl_api_l2_flags_t *mp;
3435 u32 feature_bitmap = 0;
3436 u8 sw_if_index_set = 0;
3438 /* Parse args required to build the message */
3439 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
3440 if (unformat (i, "sw_if_index %d", &sw_if_index))
3441 sw_if_index_set = 1;
3442 else if (unformat (i, "sw_if")) {
3443 if (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
3444 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
3445 sw_if_index_set = 1;
3448 } else if (unformat (i, "learn"))
3449 feature_bitmap |= L2INPUT_FEAT_LEARN;
3450 else if (unformat (i, "forward"))
3451 feature_bitmap |= L2INPUT_FEAT_FWD;
3452 else if (unformat (i, "flood"))
3453 feature_bitmap |= L2INPUT_FEAT_FLOOD;
3454 else if (unformat (i, "uu-flood"))
3455 feature_bitmap |= L2INPUT_FEAT_UU_FLOOD;
3460 if (sw_if_index_set == 0) {
3461 errmsg ("missing interface name or sw_if_index\n");
3465 M(L2_FLAGS, l2_flags);
3467 mp->sw_if_index = ntohl(sw_if_index);
3468 mp->feature_bitmap = ntohl(feature_bitmap);
3475 static int api_bridge_flags (vat_main_t * vam)
3477 unformat_input_t * i = vam->input;
3478 vl_api_bridge_flags_t *mp;
3485 /* Parse args required to build the message */
3486 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
3487 if (unformat (i, "bd_id %d", &bd_id))
3489 else if (unformat (i, "learn"))
3491 else if (unformat (i, "forward"))
3493 else if (unformat (i, "flood"))
3495 else if (unformat (i, "uu-flood"))
3496 flags |= L2_UU_FLOOD;
3497 else if (unformat (i, "arp-term"))
3498 flags |= L2_ARP_TERM;
3499 else if (unformat (i, "off"))
3501 else if (unformat (i, "disable"))
3507 if (bd_id_set == 0) {
3508 errmsg ("missing bridge domain\n");
3512 M(BRIDGE_FLAGS, bridge_flags);
3514 mp->bd_id = ntohl(bd_id);
3515 mp->feature_bitmap = ntohl(flags);
3516 mp->is_set = is_set;
3523 static int api_bd_ip_mac_add_del (vat_main_t * vam)
3525 unformat_input_t * i = vam->input;
3526 vl_api_bd_ip_mac_add_del_t *mp;
3534 ip4_address_t v4addr;
3535 ip6_address_t v6addr;
3539 /* Parse args required to build the message */
3540 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
3541 if (unformat (i, "bd_id %d", &bd_id)) {
3543 } else if (unformat (i, "%U", unformat_ip4_address, &v4addr)) {
3545 } else if (unformat (i, "%U", unformat_ip6_address, &v6addr)) {
3548 } else if (unformat (i, "%U", unformat_ethernet_address, macaddr)) {
3550 } else if (unformat (i, "del"))
3556 if (bd_id_set == 0) {
3557 errmsg ("missing bridge domain\n");
3559 } else if (ip_set == 0) {
3560 errmsg ("missing IP address\n");
3562 } else if (mac_set == 0) {
3563 errmsg ("missing MAC address\n");
3567 M(BD_IP_MAC_ADD_DEL, bd_ip_mac_add_del);
3569 mp->bd_id = ntohl(bd_id);
3570 mp->is_ipv6 = is_ipv6;
3571 mp->is_add = is_add;
3573 clib_memcpy (mp->ip_address, &v6addr, sizeof (v6addr));
3574 else clib_memcpy (mp->ip_address, &v4addr, sizeof (v4addr));
3575 clib_memcpy (mp->mac_address, macaddr, 6);
3581 static int api_tap_connect (vat_main_t * vam)
3583 unformat_input_t * i = vam->input;
3584 vl_api_tap_connect_t *mp;
3591 memset (mac_address, 0, sizeof (mac_address));
3593 /* Parse args required to build the message */
3594 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
3595 if (unformat (i, "mac %U", unformat_ethernet_address, mac_address)) {
3598 else if (unformat (i, "random-mac"))
3600 else if (unformat (i, "tapname %s", &tap_name))
3606 if (name_set == 0) {
3607 errmsg ("missing tap name\n");
3610 if (vec_len (tap_name) > 63) {
3611 errmsg ("tap name too long\n");
3613 vec_add1 (tap_name, 0);
3615 /* Construct the API message */
3616 M(TAP_CONNECT, tap_connect);
3618 mp->use_random_mac = random_mac;
3619 clib_memcpy (mp->mac_address, mac_address, 6);
3620 clib_memcpy (mp->tap_name, tap_name, vec_len (tap_name));
3621 vec_free (tap_name);
3626 /* Wait for a reply... */
3630 static int api_tap_modify (vat_main_t * vam)
3632 unformat_input_t * i = vam->input;
3633 vl_api_tap_modify_t *mp;
3639 u32 sw_if_index = ~0;
3640 u8 sw_if_index_set = 0;
3642 memset (mac_address, 0, sizeof (mac_address));
3644 /* Parse args required to build the message */
3645 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
3646 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
3647 sw_if_index_set = 1;
3648 else if (unformat (i, "sw_if_index %d", &sw_if_index))
3649 sw_if_index_set = 1;
3650 else if (unformat (i, "mac %U", unformat_ethernet_address, mac_address)) {
3653 else if (unformat (i, "random-mac"))
3655 else if (unformat (i, "tapname %s", &tap_name))
3661 if (sw_if_index_set == 0) {
3662 errmsg ("missing vpp interface name");
3665 if (name_set == 0) {
3666 errmsg ("missing tap name\n");
3669 if (vec_len (tap_name) > 63) {
3670 errmsg ("tap name too long\n");
3672 vec_add1 (tap_name, 0);
3674 /* Construct the API message */
3675 M(TAP_MODIFY, tap_modify);
3677 mp->use_random_mac = random_mac;
3678 mp->sw_if_index = ntohl(sw_if_index);
3679 clib_memcpy (mp->mac_address, mac_address, 6);
3680 clib_memcpy (mp->tap_name, tap_name, vec_len (tap_name));
3681 vec_free (tap_name);
3686 /* Wait for a reply... */
3690 static int api_tap_delete (vat_main_t * vam)
3692 unformat_input_t * i = vam->input;
3693 vl_api_tap_delete_t *mp;
3695 u32 sw_if_index = ~0;
3696 u8 sw_if_index_set = 0;
3698 /* Parse args required to build the message */
3699 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
3700 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
3701 sw_if_index_set = 1;
3702 else if (unformat (i, "sw_if_index %d", &sw_if_index))
3703 sw_if_index_set = 1;
3708 if (sw_if_index_set == 0) {
3709 errmsg ("missing vpp interface name");
3713 /* Construct the API message */
3714 M(TAP_DELETE, tap_delete);
3716 mp->sw_if_index = ntohl(sw_if_index);
3721 /* Wait for a reply... */
3725 static int api_ip_add_del_route (vat_main_t * vam)
3727 unformat_input_t * i = vam->input;
3728 vl_api_ip_add_del_route_t *mp;
3730 u32 sw_if_index = 0, vrf_id = 0;
3731 u8 sw_if_index_set = 0;
3733 u8 is_local = 0, is_drop = 0;
3734 u8 create_vrf_if_needed = 0;
3736 u8 next_hop_weight = 1;
3738 u8 is_multipath = 0;
3740 u8 address_length_set = 0;
3741 u32 lookup_in_vrf = 0;
3742 u32 resolve_attempts = 0;
3743 u32 dst_address_length = 0;
3744 u8 next_hop_set = 0;
3745 ip4_address_t v4_dst_address, v4_next_hop_address;
3746 ip6_address_t v6_dst_address, v6_next_hop_address;
3750 u32 random_add_del = 0;
3751 u32 * random_vector = 0;
3752 uword * random_hash;
3753 u32 random_seed = 0xdeaddabe;
3754 u32 classify_table_index = ~0;
3757 /* Parse args required to build the message */
3758 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
3759 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
3760 sw_if_index_set = 1;
3761 else if (unformat (i, "sw_if_index %d", &sw_if_index))
3762 sw_if_index_set = 1;
3763 else if (unformat (i, "%U", unformat_ip4_address,
3768 else if (unformat (i, "%U", unformat_ip6_address, &v6_dst_address)) {
3772 else if (unformat (i, "/%d", &dst_address_length)) {
3773 address_length_set = 1;
3776 else if (is_ipv6 == 0 && unformat (i, "via %U", unformat_ip4_address,
3777 &v4_next_hop_address)) {
3780 else if (is_ipv6 == 1 && unformat (i, "via %U", unformat_ip6_address,
3781 &v6_next_hop_address)) {
3784 else if (unformat (i, "resolve-attempts %d", &resolve_attempts))
3786 else if (unformat (i, "weight %d", &next_hop_weight))
3788 else if (unformat (i, "drop")) {
3790 } else if (unformat (i, "local")) {
3792 } else if (unformat (i, "classify %d", &classify_table_index)) {
3794 } else if (unformat (i, "del"))
3796 else if (unformat (i, "add"))
3798 else if (unformat (i, "not-last"))
3800 else if (unformat (i, "multipath"))
3802 else if (unformat (i, "vrf %d", &vrf_id))
3804 else if (unformat (i, "create-vrf"))
3805 create_vrf_if_needed = 1;
3806 else if (unformat (i, "count %d", &count))
3808 else if (unformat (i, "lookup-in-vrf %d", &lookup_in_vrf))
3810 else if (unformat (i, "random"))
3812 else if (unformat (i, "seed %d", &random_seed))
3815 clib_warning ("parse error '%U'", format_unformat_error, i);
3820 if (resolve_attempts > 0 && sw_if_index_set == 0) {
3821 errmsg ("ARP resolution needs explicit interface or sw_if_index\n");
3825 if (!next_hop_set && !is_drop && !is_local && !is_classify) {
3826 errmsg ("next hop / local / drop / classify not set\n");
3830 if (address_set == 0) {
3831 errmsg ("missing addresses\n");
3835 if (address_length_set == 0) {
3836 errmsg ("missing address length\n");
3840 /* Generate a pile of unique, random routes */
3841 if (random_add_del) {
3842 u32 this_random_address;
3843 random_hash = hash_create (count, sizeof(uword));
3845 hash_set (random_hash, v4_next_hop_address.as_u32, 1);
3846 for (j = 0; j <= count; j++) {
3848 this_random_address = random_u32 (&random_seed);
3849 this_random_address =
3850 clib_host_to_net_u32 (this_random_address);
3851 } while (hash_get (random_hash, this_random_address));
3852 vec_add1 (random_vector, this_random_address);
3853 hash_set (random_hash, this_random_address, 1);
3855 hash_free (random_hash);
3856 v4_dst_address.as_u32 = random_vector[0];
3860 /* Turn on async mode */
3861 vam->async_mode = 1;
3862 vam->async_errors = 0;
3863 before = vat_time_now(vam);
3866 for (j = 0; j < count; j++) {
3867 /* Construct the API message */
3868 M(IP_ADD_DEL_ROUTE, ip_add_del_route);
3870 mp->next_hop_sw_if_index = ntohl (sw_if_index);
3871 mp->vrf_id = ntohl (vrf_id);
3872 if (resolve_attempts > 0) {
3873 mp->resolve_attempts = ntohl (resolve_attempts);
3874 mp->resolve_if_needed = 1;
3876 mp->create_vrf_if_needed = create_vrf_if_needed;
3878 mp->is_add = is_add;
3879 mp->is_drop = is_drop;
3880 mp->is_ipv6 = is_ipv6;
3881 mp->is_local = is_local;
3882 mp->is_classify = is_classify;
3883 mp->is_multipath = is_multipath;
3884 mp->not_last = not_last;
3885 mp->next_hop_weight = next_hop_weight;
3886 mp->dst_address_length = dst_address_length;
3887 mp->lookup_in_vrf = ntohl(lookup_in_vrf);
3888 mp->classify_table_index = ntohl(classify_table_index);
3891 clib_memcpy (mp->dst_address, &v6_dst_address, sizeof (v6_dst_address));
3893 clib_memcpy (mp->next_hop_address, &v6_next_hop_address,
3894 sizeof (v6_next_hop_address));
3895 increment_v6_address (&v6_dst_address);
3897 clib_memcpy (mp->dst_address, &v4_dst_address, sizeof (v4_dst_address));
3899 clib_memcpy (mp->next_hop_address, &v4_next_hop_address,
3900 sizeof (v4_next_hop_address));
3902 v4_dst_address.as_u32 = random_vector[j+1];
3904 increment_v4_address (&v4_dst_address);
3910 /* When testing multiple add/del ops, use a control-ping to sync */
3912 vl_api_control_ping_t * mp;
3915 /* Shut off async mode */
3916 vam->async_mode = 0;
3918 M(CONTROL_PING, control_ping);
3921 timeout = vat_time_now(vam) + 1.0;
3922 while (vat_time_now (vam) < timeout)
3923 if (vam->result_ready == 1)
3928 if (vam->retval == -99)
3929 errmsg ("timeout\n");
3931 if (vam->async_errors > 0) {
3932 errmsg ("%d asynchronous errors\n", vam->async_errors);
3935 vam->async_errors = 0;
3936 after = vat_time_now(vam);
3938 fformat(vam->ofp, "%d routes in %.6f secs, %.2f routes/sec\n",
3939 count, after - before, count / (after - before));
3941 /* Wait for a reply... */
3945 /* Return the good/bad news */
3946 return (vam->retval);
3949 static int api_proxy_arp_add_del (vat_main_t * vam)
3951 unformat_input_t * i = vam->input;
3952 vl_api_proxy_arp_add_del_t *mp;
3956 ip4_address_t lo, hi;
3959 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
3960 if (unformat (i, "vrf %d", &vrf_id))
3962 else if (unformat (i, "%U - %U", unformat_ip4_address, &lo,
3963 unformat_ip4_address, &hi))
3965 else if (unformat (i, "del"))
3968 clib_warning ("parse error '%U'", format_unformat_error, i);
3973 if (range_set == 0) {
3974 errmsg ("address range not set\n");
3978 M(PROXY_ARP_ADD_DEL, proxy_arp_add_del);
3980 mp->vrf_id = ntohl(vrf_id);
3981 mp->is_add = is_add;
3982 clib_memcpy(mp->low_address, &lo, sizeof (mp->low_address));
3983 clib_memcpy(mp->hi_address, &hi, sizeof (mp->hi_address));
3990 static int api_proxy_arp_intfc_enable_disable (vat_main_t * vam)
3992 unformat_input_t * i = vam->input;
3993 vl_api_proxy_arp_intfc_enable_disable_t *mp;
3997 u8 sw_if_index_set = 0;
3999 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
4000 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
4001 sw_if_index_set = 1;
4002 else if (unformat (i, "sw_if_index %d", &sw_if_index))
4003 sw_if_index_set = 1;
4004 else if (unformat (i, "enable"))
4006 else if (unformat (i, "disable"))
4009 clib_warning ("parse error '%U'", format_unformat_error, i);
4014 if (sw_if_index_set == 0) {
4015 errmsg ("missing interface name or sw_if_index\n");
4019 M(PROXY_ARP_INTFC_ENABLE_DISABLE, proxy_arp_intfc_enable_disable);
4021 mp->sw_if_index = ntohl(sw_if_index);
4022 mp->enable_disable = enable;
4029 static int api_mpls_add_del_decap (vat_main_t * vam)
4031 unformat_input_t * i = vam->input;
4032 vl_api_mpls_add_del_decap_t *mp;
4041 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
4042 if (unformat (i, "rx_vrf_id %d", &rx_vrf_id))
4044 else if (unformat (i, "tx_vrf_id %d", &tx_vrf_id))
4046 else if (unformat (i, "label %d", &label))
4048 else if (unformat (i, "next-index %d", &next_index))
4050 else if (unformat (i, "del"))
4052 else if (unformat (i, "s-bit-clear"))
4055 clib_warning ("parse error '%U'", format_unformat_error, i);
4060 M(MPLS_ADD_DEL_DECAP, mpls_add_del_decap);
4062 mp->rx_vrf_id = ntohl(rx_vrf_id);
4063 mp->tx_vrf_id = ntohl(tx_vrf_id);
4064 mp->label = ntohl(label);
4065 mp->next_index = ntohl(next_index);
4067 mp->is_add = is_add;
4074 static int api_mpls_add_del_encap (vat_main_t * vam)
4076 unformat_input_t * i = vam->input;
4077 vl_api_mpls_add_del_encap_t *mp;
4082 ip4_address_t dst_address;
4085 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
4086 if (unformat (i, "vrf %d", &vrf_id))
4088 else if (unformat (i, "label %d", &label))
4089 vec_add1 (labels, ntohl(label));
4090 else if (unformat (i, "dst %U", unformat_ip4_address, &dst_address))
4092 else if (unformat (i, "del"))
4095 clib_warning ("parse error '%U'", format_unformat_error, i);
4100 if (vec_len (labels) == 0) {
4101 errmsg ("missing encap label stack\n");
4105 M2(MPLS_ADD_DEL_ENCAP, mpls_add_del_encap,
4106 sizeof (u32) * vec_len (labels));
4108 mp->vrf_id = ntohl(vrf_id);
4109 clib_memcpy(mp->dst_address, &dst_address, sizeof (dst_address));
4110 mp->is_add = is_add;
4111 mp->nlabels = vec_len (labels);
4112 clib_memcpy(mp->labels, labels, sizeof(u32)*mp->nlabels);
4121 static int api_mpls_gre_add_del_tunnel (vat_main_t * vam)
4123 unformat_input_t * i = vam->input;
4124 vl_api_mpls_gre_add_del_tunnel_t *mp;
4126 u32 inner_vrf_id = 0;
4127 u32 outer_vrf_id = 0;
4128 ip4_address_t src_address;
4129 ip4_address_t dst_address;
4130 ip4_address_t intfc_address;
4132 u8 intfc_address_length = 0;
4136 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
4137 if (unformat (i, "inner_vrf_id %d", &inner_vrf_id))
4139 else if (unformat (i, "outer_vrf_id %d", &outer_vrf_id))
4141 else if (unformat (i, "src %U", unformat_ip4_address, &src_address))
4143 else if (unformat (i, "dst %U", unformat_ip4_address, &dst_address))
4145 else if (unformat (i, "adj %U/%d", unformat_ip4_address,
4146 &intfc_address, &tmp))
4147 intfc_address_length = tmp;
4148 else if (unformat (i, "l2-only"))
4150 else if (unformat (i, "del"))
4153 clib_warning ("parse error '%U'", format_unformat_error, i);
4158 M(MPLS_GRE_ADD_DEL_TUNNEL, mpls_gre_add_del_tunnel);
4160 mp->inner_vrf_id = ntohl(inner_vrf_id);
4161 mp->outer_vrf_id = ntohl(outer_vrf_id);
4162 clib_memcpy(mp->src_address, &src_address, sizeof (src_address));
4163 clib_memcpy(mp->dst_address, &dst_address, sizeof (dst_address));
4164 clib_memcpy(mp->intfc_address, &intfc_address, sizeof (intfc_address));
4165 mp->intfc_address_length = intfc_address_length;
4166 mp->l2_only = l2_only;
4167 mp->is_add = is_add;
4174 static int api_mpls_ethernet_add_del_tunnel (vat_main_t * vam)
4176 unformat_input_t * i = vam->input;
4177 vl_api_mpls_ethernet_add_del_tunnel_t *mp;
4179 u32 inner_vrf_id = 0;
4180 ip4_address_t intfc_address;
4181 u8 dst_mac_address[6];
4184 u8 intfc_address_length = 0;
4188 int tx_sw_if_index_set = 0;
4190 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
4191 if (unformat (i, "vrf %d", &inner_vrf_id))
4193 else if (unformat (i, "adj %U/%d", unformat_ip4_address,
4194 &intfc_address, &tmp))
4195 intfc_address_length = tmp;
4196 else if (unformat (i, "%U",
4197 unformat_sw_if_index, vam, &tx_sw_if_index))
4198 tx_sw_if_index_set = 1;
4199 else if (unformat (i, "tx_sw_if_index %d", &tx_sw_if_index))
4200 tx_sw_if_index_set = 1;
4201 else if (unformat (i, "dst %U", unformat_ethernet_address,
4204 else if (unformat (i, "l2-only"))
4206 else if (unformat (i, "del"))
4209 clib_warning ("parse error '%U'", format_unformat_error, i);
4215 errmsg ("dst (mac address) not set\n");
4218 if (!tx_sw_if_index_set) {
4219 errmsg ("tx-intfc not set\n");
4223 M(MPLS_ETHERNET_ADD_DEL_TUNNEL, mpls_ethernet_add_del_tunnel);
4225 mp->vrf_id = ntohl(inner_vrf_id);
4226 clib_memcpy (mp->adj_address, &intfc_address, sizeof (intfc_address));
4227 mp->adj_address_length = intfc_address_length;
4228 clib_memcpy (mp->dst_mac_address, dst_mac_address, sizeof (dst_mac_address));
4229 mp->tx_sw_if_index = ntohl(tx_sw_if_index);
4230 mp->l2_only = l2_only;
4231 mp->is_add = is_add;
4238 static int api_mpls_ethernet_add_del_tunnel_2 (vat_main_t * vam)
4240 unformat_input_t * i = vam->input;
4241 vl_api_mpls_ethernet_add_del_tunnel_2_t *mp;
4243 u32 inner_vrf_id = 0;
4244 u32 outer_vrf_id = 0;
4245 ip4_address_t adj_address;
4246 int adj_address_set = 0;
4247 ip4_address_t next_hop_address;
4248 int next_hop_address_set = 0;
4250 u8 adj_address_length = 0;
4253 u32 resolve_attempts = 5;
4254 u8 resolve_if_needed = 1;
4256 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
4257 if (unformat (i, "inner_vrf_id %d", &inner_vrf_id))
4259 else if (unformat (i, "outer_vrf_id %d", &outer_vrf_id))
4261 else if (unformat (i, "adj %U/%d", unformat_ip4_address,
4262 &adj_address, &tmp)) {
4263 adj_address_length = tmp;
4264 adj_address_set = 1;
4266 else if (unformat (i, "next-hop %U", unformat_ip4_address,
4268 next_hop_address_set = 1;
4269 else if (unformat (i, "resolve-attempts %d", &resolve_attempts))
4271 else if (unformat (i, "resolve-if-needed %d", &tmp))
4272 resolve_if_needed = tmp;
4273 else if (unformat (i, "l2-only"))
4275 else if (unformat (i, "del"))
4278 clib_warning ("parse error '%U'", format_unformat_error, i);
4283 if (!adj_address_set) {
4284 errmsg ("adjacency address/mask not set\n");
4287 if (!next_hop_address_set) {
4288 errmsg ("ip4 next hop address (in outer fib) not set\n");
4292 M(MPLS_ETHERNET_ADD_DEL_TUNNEL_2, mpls_ethernet_add_del_tunnel_2);
4294 mp->inner_vrf_id = ntohl(inner_vrf_id);
4295 mp->outer_vrf_id = ntohl(outer_vrf_id);
4296 mp->resolve_attempts = ntohl(resolve_attempts);
4297 mp->resolve_if_needed = resolve_if_needed;
4298 mp->is_add = is_add;
4299 mp->l2_only = l2_only;
4300 clib_memcpy (mp->adj_address, &adj_address, sizeof (adj_address));
4301 mp->adj_address_length = adj_address_length;
4302 clib_memcpy (mp->next_hop_ip4_address_in_outer_vrf, &next_hop_address,
4303 sizeof (next_hop_address));
4310 static int api_sw_interface_set_unnumbered (vat_main_t * vam)
4312 unformat_input_t * i = vam->input;
4313 vl_api_sw_interface_set_unnumbered_t *mp;
4318 u8 sw_if_index_set = 0;
4320 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
4321 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
4322 sw_if_index_set = 1;
4323 else if (unformat (i, "sw_if_index %d", &sw_if_index))
4324 sw_if_index_set = 1;
4325 else if (unformat (i, "unnum_if_index %d", &unnum_sw_index))
4327 else if (unformat (i, "del"))
4330 clib_warning ("parse error '%U'", format_unformat_error, i);
4335 if (sw_if_index_set == 0) {
4336 errmsg ("missing interface name or sw_if_index\n");
4340 M(SW_INTERFACE_SET_UNNUMBERED, sw_interface_set_unnumbered);
4342 mp->sw_if_index = ntohl(sw_if_index);
4343 mp->unnumbered_sw_if_index = ntohl(unnum_sw_index);
4344 mp->is_add = is_add;
4351 static int api_ip_neighbor_add_del (vat_main_t * vam)
4353 unformat_input_t * i = vam->input;
4354 vl_api_ip_neighbor_add_del_t *mp;
4357 u8 sw_if_index_set = 0;
4363 u8 v4_address_set = 0;
4364 u8 v6_address_set = 0;
4365 ip4_address_t v4address;
4366 ip6_address_t v6address;
4368 memset (mac_address, 0, sizeof (mac_address));
4370 /* Parse args required to build the message */
4371 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
4372 if (unformat (i, "mac %U", unformat_ethernet_address, mac_address)) {
4375 else if (unformat (i, "del"))
4377 else if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
4378 sw_if_index_set = 1;
4379 else if (unformat (i, "sw_if_index %d", &sw_if_index))
4380 sw_if_index_set = 1;
4381 else if (unformat (i, "is_static"))
4383 else if (unformat (i, "vrf %d", &vrf_id))
4385 else if (unformat (i, "dst %U",
4386 unformat_ip4_address, &v4address))
4388 else if (unformat (i, "dst %U",
4389 unformat_ip6_address, &v6address))
4392 clib_warning ("parse error '%U'", format_unformat_error, i);
4397 if (sw_if_index_set == 0) {
4398 errmsg ("missing interface name or sw_if_index\n");
4401 if (v4_address_set && v6_address_set) {
4402 errmsg ("both v4 and v6 addresses set\n");
4405 if (!v4_address_set && !v6_address_set) {
4406 errmsg ("no addresses set\n");
4410 /* Construct the API message */
4411 M(IP_NEIGHBOR_ADD_DEL, ip_neighbor_add_del);
4413 mp->sw_if_index = ntohl (sw_if_index);
4414 mp->is_add = is_add;
4415 mp->vrf_id = ntohl (vrf_id);
4416 mp->is_static = is_static;
4418 clib_memcpy (mp->mac_address, mac_address, 6);
4419 if (v6_address_set) {
4421 clib_memcpy (mp->dst_address, &v6address, sizeof (v6address));
4423 /* mp->is_ipv6 = 0; via memset in M macro above */
4424 clib_memcpy (mp->dst_address, &v4address, sizeof (v4address));
4430 /* Wait for a reply, return good/bad news */
4437 static int api_reset_vrf (vat_main_t * vam)
4439 unformat_input_t * i = vam->input;
4440 vl_api_reset_vrf_t *mp;
4446 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
4447 if (unformat (i, "vrf %d", &vrf_id))
4449 else if (unformat (i, "ipv6"))
4452 clib_warning ("parse error '%U'", format_unformat_error, i);
4457 if (vrf_id_set == 0) {
4458 errmsg ("missing vrf id\n");
4462 M(RESET_VRF, reset_vrf);
4464 mp->vrf_id = ntohl(vrf_id);
4465 mp->is_ipv6 = is_ipv6;
4472 static int api_create_vlan_subif (vat_main_t * vam)
4474 unformat_input_t * i = vam->input;
4475 vl_api_create_vlan_subif_t *mp;
4478 u8 sw_if_index_set = 0;
4482 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
4483 if (unformat (i, "sw_if_index %d", &sw_if_index))
4484 sw_if_index_set = 1;
4485 else if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
4486 sw_if_index_set = 1;
4487 else if (unformat (i, "vlan %d", &vlan_id))
4490 clib_warning ("parse error '%U'", format_unformat_error, i);
4495 if (sw_if_index_set == 0) {
4496 errmsg ("missing interface name or sw_if_index\n");
4500 if (vlan_id_set == 0) {
4501 errmsg ("missing vlan_id\n");
4504 M(CREATE_VLAN_SUBIF, create_vlan_subif);
4506 mp->sw_if_index = ntohl(sw_if_index);
4507 mp->vlan_id = ntohl(vlan_id);
4514 #define foreach_create_subif_bit \
4521 _(outer_vlan_id_any) \
4522 _(inner_vlan_id_any)
4524 static int api_create_subif (vat_main_t * vam)
4526 unformat_input_t * i = vam->input;
4527 vl_api_create_subif_t *mp;
4530 u8 sw_if_index_set = 0;
4537 u32 exact_match = 0;
4538 u32 default_sub = 0;
4539 u32 outer_vlan_id_any = 0;
4540 u32 inner_vlan_id_any = 0;
4542 u16 outer_vlan_id = 0;
4543 u16 inner_vlan_id = 0;
4545 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
4546 if (unformat (i, "sw_if_index %d", &sw_if_index))
4547 sw_if_index_set = 1;
4548 else if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
4549 sw_if_index_set = 1;
4550 else if (unformat (i, "sub_id %d", &sub_id))
4552 else if (unformat (i, "outer_vlan_id %d", &tmp))
4553 outer_vlan_id = tmp;
4554 else if (unformat (i, "inner_vlan_id %d", &tmp))
4555 inner_vlan_id = tmp;
4557 #define _(a) else if (unformat (i, #a)) a = 1 ;
4558 foreach_create_subif_bit
4562 clib_warning ("parse error '%U'", format_unformat_error, i);
4567 if (sw_if_index_set == 0) {
4568 errmsg ("missing interface name or sw_if_index\n");
4572 if (sub_id_set == 0) {
4573 errmsg ("missing sub_id\n");
4576 M(CREATE_SUBIF, create_subif);
4578 mp->sw_if_index = ntohl(sw_if_index);
4579 mp->sub_id = ntohl(sub_id);
4581 #define _(a) mp->a = a;
4582 foreach_create_subif_bit;
4585 mp->outer_vlan_id = ntohs (outer_vlan_id);
4586 mp->inner_vlan_id = ntohs (inner_vlan_id);
4593 static int api_oam_add_del (vat_main_t * vam)
4595 unformat_input_t * i = vam->input;
4596 vl_api_oam_add_del_t *mp;
4600 ip4_address_t src, dst;
4604 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
4605 if (unformat (i, "vrf %d", &vrf_id))
4607 else if (unformat (i, "src %U", unformat_ip4_address, &src))
4609 else if (unformat (i, "dst %U", unformat_ip4_address, &dst))
4611 else if (unformat (i, "del"))
4614 clib_warning ("parse error '%U'", format_unformat_error, i);
4620 errmsg ("missing src addr\n");
4625 errmsg ("missing dst addr\n");
4629 M(OAM_ADD_DEL, oam_add_del);
4631 mp->vrf_id = ntohl(vrf_id);
4632 mp->is_add = is_add;
4633 clib_memcpy(mp->src_address, &src, sizeof (mp->src_address));
4634 clib_memcpy(mp->dst_address, &dst, sizeof (mp->dst_address));
4641 static int api_reset_fib (vat_main_t * vam)
4643 unformat_input_t * i = vam->input;
4644 vl_api_reset_fib_t *mp;
4650 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
4651 if (unformat (i, "vrf %d", &vrf_id))
4653 else if (unformat (i, "ipv6"))
4656 clib_warning ("parse error '%U'", format_unformat_error, i);
4661 if (vrf_id_set == 0) {
4662 errmsg ("missing vrf id\n");
4666 M(RESET_FIB, reset_fib);
4668 mp->vrf_id = ntohl(vrf_id);
4669 mp->is_ipv6 = is_ipv6;
4676 static int api_dhcp_proxy_config (vat_main_t * vam)
4678 unformat_input_t * i = vam->input;
4679 vl_api_dhcp_proxy_config_t *mp;
4684 u8 v4_address_set = 0;
4685 u8 v6_address_set = 0;
4686 ip4_address_t v4address;
4687 ip6_address_t v6address;
4688 u8 v4_src_address_set = 0;
4689 u8 v6_src_address_set = 0;
4690 ip4_address_t v4srcaddress;
4691 ip6_address_t v6srcaddress;
4693 /* Parse args required to build the message */
4694 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
4695 if (unformat (i, "del"))
4697 else if (unformat (i, "vrf %d", &vrf_id))
4699 else if (unformat (i, "insert-cid %d", &insert_cid))
4701 else if (unformat (i, "svr %U",
4702 unformat_ip4_address, &v4address))
4704 else if (unformat (i, "svr %U",
4705 unformat_ip6_address, &v6address))
4707 else if (unformat (i, "src %U",
4708 unformat_ip4_address, &v4srcaddress))
4709 v4_src_address_set = 1;
4710 else if (unformat (i, "src %U",
4711 unformat_ip6_address, &v6srcaddress))
4712 v6_src_address_set = 1;
4717 if (v4_address_set && v6_address_set) {
4718 errmsg ("both v4 and v6 server addresses set\n");
4721 if (!v4_address_set && !v6_address_set) {
4722 errmsg ("no server addresses set\n");
4726 if (v4_src_address_set && v6_src_address_set) {
4727 errmsg ("both v4 and v6 src addresses set\n");
4730 if (!v4_src_address_set && !v6_src_address_set) {
4731 errmsg ("no src addresses set\n");
4735 if (!(v4_src_address_set && v4_address_set) &&
4736 !(v6_src_address_set && v6_address_set)) {
4737 errmsg ("no matching server and src addresses set\n");
4741 /* Construct the API message */
4742 M(DHCP_PROXY_CONFIG, dhcp_proxy_config);
4744 mp->insert_circuit_id = insert_cid;
4745 mp->is_add = is_add;
4746 mp->vrf_id = ntohl (vrf_id);
4747 if (v6_address_set) {
4749 clib_memcpy (mp->dhcp_server, &v6address, sizeof (v6address));
4750 clib_memcpy (mp->dhcp_src_address, &v6srcaddress, sizeof (v6address));
4752 clib_memcpy (mp->dhcp_server, &v4address, sizeof (v4address));
4753 clib_memcpy (mp->dhcp_src_address, &v4srcaddress, sizeof (v4address));
4759 /* Wait for a reply, return good/bad news */
4765 static int api_dhcp_proxy_config_2 (vat_main_t * vam)
4767 unformat_input_t * i = vam->input;
4768 vl_api_dhcp_proxy_config_2_t *mp;
4771 u32 server_vrf_id = 0;
4774 u8 v4_address_set = 0;
4775 u8 v6_address_set = 0;
4776 ip4_address_t v4address;
4777 ip6_address_t v6address;
4778 u8 v4_src_address_set = 0;
4779 u8 v6_src_address_set = 0;
4780 ip4_address_t v4srcaddress;
4781 ip6_address_t v6srcaddress;
4783 /* Parse args required to build the message */
4784 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
4785 if (unformat (i, "del"))
4787 else if (unformat (i, "rx_vrf_id %d", &rx_vrf_id))
4789 else if (unformat (i, "server_vrf_id %d", &server_vrf_id))
4791 else if (unformat (i, "insert-cid %d", &insert_cid))
4793 else if (unformat (i, "svr %U",
4794 unformat_ip4_address, &v4address))
4796 else if (unformat (i, "svr %U",
4797 unformat_ip6_address, &v6address))
4799 else if (unformat (i, "src %U",
4800 unformat_ip4_address, &v4srcaddress))
4801 v4_src_address_set = 1;
4802 else if (unformat (i, "src %U",
4803 unformat_ip6_address, &v6srcaddress))
4804 v6_src_address_set = 1;
4809 if (v4_address_set && v6_address_set) {
4810 errmsg ("both v4 and v6 server addresses set\n");
4813 if (!v4_address_set && !v6_address_set) {
4814 errmsg ("no server addresses set\n");
4818 if (v4_src_address_set && v6_src_address_set) {
4819 errmsg ("both v4 and v6 src addresses set\n");
4822 if (!v4_src_address_set && !v6_src_address_set) {
4823 errmsg ("no src addresses set\n");
4827 if (!(v4_src_address_set && v4_address_set) &&
4828 !(v6_src_address_set && v6_address_set)) {
4829 errmsg ("no matching server and src addresses set\n");
4833 /* Construct the API message */
4834 M(DHCP_PROXY_CONFIG_2, dhcp_proxy_config_2);
4836 mp->insert_circuit_id = insert_cid;
4837 mp->is_add = is_add;
4838 mp->rx_vrf_id = ntohl (rx_vrf_id);
4839 mp->server_vrf_id = ntohl (server_vrf_id);
4840 if (v6_address_set) {
4842 clib_memcpy (mp->dhcp_server, &v6address, sizeof (v6address));
4843 clib_memcpy (mp->dhcp_src_address, &v6srcaddress, sizeof (v6address));
4845 clib_memcpy (mp->dhcp_server, &v4address, sizeof (v4address));
4846 clib_memcpy (mp->dhcp_src_address, &v4srcaddress, sizeof (v4address));
4852 /* Wait for a reply, return good/bad news */
4858 static int api_dhcp_proxy_set_vss (vat_main_t * vam)
4860 unformat_input_t * i = vam->input;
4861 vl_api_dhcp_proxy_set_vss_t *mp;
4872 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
4873 if (unformat (i, "tbl_id %d", &tbl_id))
4875 if (unformat (i, "fib_id %d", &fib_id))
4877 if (unformat (i, "oui %d", &oui))
4879 else if (unformat (i, "ipv6"))
4881 else if (unformat (i, "del"))
4884 clib_warning ("parse error '%U'", format_unformat_error, i);
4889 if (tbl_id_set == 0) {
4890 errmsg ("missing tbl id\n");
4894 if (fib_id_set == 0) {
4895 errmsg ("missing fib id\n");
4899 errmsg ("missing oui\n");
4903 M(DHCP_PROXY_SET_VSS, dhcp_proxy_set_vss);
4904 mp->tbl_id = ntohl(tbl_id);
4905 mp->fib_id = ntohl(fib_id);
4906 mp->oui = ntohl(oui);
4907 mp->is_ipv6 = is_ipv6;
4908 mp->is_add = is_add;
4915 static int api_dhcp_client_config (vat_main_t * vam)
4917 unformat_input_t * i = vam->input;
4918 vl_api_dhcp_client_config_t *mp;
4921 u8 sw_if_index_set = 0;
4924 u8 disable_event = 0;
4926 /* Parse args required to build the message */
4927 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
4928 if (unformat (i, "del"))
4930 else if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
4931 sw_if_index_set = 1;
4932 else if (unformat (i, "sw_if_index %d", &sw_if_index))
4933 sw_if_index_set = 1;
4934 else if (unformat (i, "hostname %s", &hostname))
4936 else if (unformat (i, "disable_event"))
4942 if (sw_if_index_set == 0) {
4943 errmsg ("missing interface name or sw_if_index\n");
4947 if (vec_len (hostname) > 63) {
4948 errmsg ("hostname too long\n");
4950 vec_add1 (hostname, 0);
4952 /* Construct the API message */
4953 M(DHCP_CLIENT_CONFIG, dhcp_client_config);
4955 mp->sw_if_index = ntohl (sw_if_index);
4956 clib_memcpy (mp->hostname, hostname, vec_len (hostname));
4957 vec_free (hostname);
4958 mp->is_add = is_add;
4959 mp->want_dhcp_event = disable_event ? 0 : 1;
4965 /* Wait for a reply, return good/bad news */
4971 static int api_set_ip_flow_hash (vat_main_t * vam)
4973 unformat_input_t * i = vam->input;
4974 vl_api_set_ip_flow_hash_t *mp;
4986 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
4987 if (unformat (i, "vrf %d", &vrf_id))
4989 else if (unformat (i, "ipv6"))
4991 else if (unformat (i, "src"))
4993 else if (unformat (i, "dst"))
4995 else if (unformat (i, "sport"))
4997 else if (unformat (i, "dport"))
4999 else if (unformat (i, "proto"))
5001 else if (unformat (i, "reverse"))
5005 clib_warning ("parse error '%U'", format_unformat_error, i);
5010 if (vrf_id_set == 0) {
5011 errmsg ("missing vrf id\n");
5015 M(SET_IP_FLOW_HASH, set_ip_flow_hash);
5021 mp->reverse = reverse;
5022 mp->vrf_id = ntohl(vrf_id);
5023 mp->is_ipv6 = is_ipv6;
5030 static int api_sw_interface_ip6_enable_disable (vat_main_t * vam)
5032 unformat_input_t * i = vam->input;
5033 vl_api_sw_interface_ip6_enable_disable_t *mp;
5036 u8 sw_if_index_set = 0;
5039 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
5040 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
5041 sw_if_index_set = 1;
5042 else if (unformat (i, "sw_if_index %d", &sw_if_index))
5043 sw_if_index_set = 1;
5044 else if (unformat (i, "enable"))
5046 else if (unformat (i, "disable"))
5049 clib_warning ("parse error '%U'", format_unformat_error, i);
5054 if (sw_if_index_set == 0) {
5055 errmsg ("missing interface name or sw_if_index\n");
5059 M(SW_INTERFACE_IP6_ENABLE_DISABLE, sw_interface_ip6_enable_disable);
5061 mp->sw_if_index = ntohl(sw_if_index);
5062 mp->enable = enable;
5069 static int api_sw_interface_ip6_set_link_local_address (vat_main_t * vam)
5071 unformat_input_t * i = vam->input;
5072 vl_api_sw_interface_ip6_set_link_local_address_t *mp;
5075 u8 sw_if_index_set = 0;
5076 u32 address_length = 0;
5077 u8 v6_address_set = 0;
5078 ip6_address_t v6address;
5080 /* Parse args required to build the message */
5081 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
5082 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
5083 sw_if_index_set = 1;
5084 else if (unformat (i, "sw_if_index %d", &sw_if_index))
5085 sw_if_index_set = 1;
5086 else if (unformat (i, "%U/%d",
5087 unformat_ip6_address, &v6address,
5094 if (sw_if_index_set == 0) {
5095 errmsg ("missing interface name or sw_if_index\n");
5098 if (!v6_address_set) {
5099 errmsg ("no address set\n");
5103 /* Construct the API message */
5104 M(SW_INTERFACE_IP6_SET_LINK_LOCAL_ADDRESS, \
5105 sw_interface_ip6_set_link_local_address);
5107 mp->sw_if_index = ntohl (sw_if_index);
5108 clib_memcpy (mp->address, &v6address, sizeof (v6address));
5109 mp->address_length = address_length;
5114 /* Wait for a reply, return good/bad news */
5122 static int api_sw_interface_ip6nd_ra_prefix (vat_main_t * vam)
5124 unformat_input_t * i = vam->input;
5125 vl_api_sw_interface_ip6nd_ra_prefix_t *mp;
5128 u8 sw_if_index_set = 0;
5129 u32 address_length = 0;
5130 u8 v6_address_set = 0;
5131 ip6_address_t v6address;
5133 u8 no_advertise = 0;
5135 u8 no_autoconfig = 0;
5138 u32 val_lifetime = 0;
5139 u32 pref_lifetime = 0;
5141 /* Parse args required to build the message */
5142 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
5143 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
5144 sw_if_index_set = 1;
5145 else if (unformat (i, "sw_if_index %d", &sw_if_index))
5146 sw_if_index_set = 1;
5147 else if (unformat (i, "%U/%d",
5148 unformat_ip6_address, &v6address,
5151 else if (unformat (i, "val_life %d", &val_lifetime))
5153 else if (unformat (i, "pref_life %d", &pref_lifetime))
5155 else if (unformat (i, "def"))
5157 else if (unformat (i, "noadv"))
5159 else if (unformat (i, "offl"))
5161 else if (unformat (i, "noauto"))
5163 else if (unformat (i, "nolink"))
5165 else if (unformat (i, "isno"))
5168 clib_warning ("parse error '%U'", format_unformat_error, i);
5173 if (sw_if_index_set == 0) {
5174 errmsg ("missing interface name or sw_if_index\n");
5177 if (!v6_address_set) {
5178 errmsg ("no address set\n");
5182 /* Construct the API message */
5183 M(SW_INTERFACE_IP6ND_RA_PREFIX, sw_interface_ip6nd_ra_prefix);
5185 mp->sw_if_index = ntohl (sw_if_index);
5186 clib_memcpy (mp->address, &v6address, sizeof (v6address));
5187 mp->address_length = address_length;
5188 mp->use_default = use_default;
5189 mp->no_advertise = no_advertise;
5190 mp->off_link = off_link;
5191 mp->no_autoconfig = no_autoconfig;
5192 mp->no_onlink = no_onlink;
5194 mp->val_lifetime = ntohl(val_lifetime);
5195 mp->pref_lifetime = ntohl(pref_lifetime);
5200 /* Wait for a reply, return good/bad news */
5207 static int api_sw_interface_ip6nd_ra_config (vat_main_t * vam)
5209 unformat_input_t * i = vam->input;
5210 vl_api_sw_interface_ip6nd_ra_config_t *mp;
5213 u8 sw_if_index_set = 0;
5218 u8 send_unicast = 0;
5221 u8 default_router = 0;
5222 u32 max_interval = 0;
5223 u32 min_interval = 0;
5225 u32 initial_count = 0;
5226 u32 initial_interval = 0;
5229 /* Parse args required to build the message */
5230 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
5231 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
5232 sw_if_index_set = 1;
5233 else if (unformat (i, "sw_if_index %d", &sw_if_index))
5234 sw_if_index_set = 1;
5235 else if (unformat (i, "maxint %d", &max_interval))
5237 else if (unformat (i, "minint %d", &min_interval))
5239 else if (unformat (i, "life %d", &lifetime))
5241 else if (unformat (i, "count %d", &initial_count))
5243 else if (unformat (i, "interval %d", &initial_interval))
5245 else if (unformat (i, "surpress"))
5247 else if (unformat (i, "managed"))
5249 else if (unformat (i, "other"))
5251 else if (unformat (i, "ll"))
5253 else if (unformat (i, "send"))
5255 else if (unformat (i, "cease"))
5257 else if (unformat (i, "isno"))
5259 else if (unformat (i, "def"))
5262 clib_warning ("parse error '%U'", format_unformat_error, i);
5267 if (sw_if_index_set == 0) {
5268 errmsg ("missing interface name or sw_if_index\n");
5272 /* Construct the API message */
5273 M(SW_INTERFACE_IP6ND_RA_CONFIG, sw_interface_ip6nd_ra_config);
5275 mp->sw_if_index = ntohl (sw_if_index);
5276 mp->max_interval = ntohl(max_interval);
5277 mp->min_interval = ntohl(min_interval);
5278 mp->lifetime = ntohl(lifetime);
5279 mp->initial_count = ntohl(initial_count);
5280 mp->initial_interval = ntohl(initial_interval);
5281 mp->surpress = surpress;
5282 mp->managed = managed;
5284 mp->ll_option = ll_option;
5285 mp->send_unicast = send_unicast;
5288 mp->default_router = default_router;
5293 /* Wait for a reply, return good/bad news */
5300 static int api_set_arp_neighbor_limit (vat_main_t * vam)
5302 unformat_input_t * i = vam->input;
5303 vl_api_set_arp_neighbor_limit_t *mp;
5309 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
5310 if (unformat (i, "arp_nbr_limit %d", &arp_nbr_limit))
5312 else if (unformat (i, "ipv6"))
5315 clib_warning ("parse error '%U'", format_unformat_error, i);
5320 if (limit_set == 0) {
5321 errmsg ("missing limit value\n");
5325 M(SET_ARP_NEIGHBOR_LIMIT, set_arp_neighbor_limit);
5327 mp->arp_neighbor_limit = ntohl(arp_nbr_limit);
5328 mp->is_ipv6 = is_ipv6;
5335 static int api_l2_patch_add_del (vat_main_t * vam)
5337 unformat_input_t * i = vam->input;
5338 vl_api_l2_patch_add_del_t *mp;
5341 u8 rx_sw_if_index_set = 0;
5343 u8 tx_sw_if_index_set = 0;
5346 /* Parse args required to build the message */
5347 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
5348 if (unformat (i, "rx_sw_if_index %d", &rx_sw_if_index))
5349 rx_sw_if_index_set = 1;
5350 else if (unformat (i, "tx_sw_if_index %d", &tx_sw_if_index))
5351 tx_sw_if_index_set = 1;
5352 else if (unformat (i, "rx")) {
5353 if (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
5354 if (unformat (i, "%U", unformat_sw_if_index, vam,
5356 rx_sw_if_index_set = 1;
5359 } else if (unformat (i, "tx")) {
5360 if (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
5361 if (unformat (i, "%U", unformat_sw_if_index, vam,
5363 tx_sw_if_index_set = 1;
5366 } else if (unformat (i, "del"))
5372 if (rx_sw_if_index_set == 0) {
5373 errmsg ("missing rx interface name or rx_sw_if_index\n");
5377 if (tx_sw_if_index_set == 0) {
5378 errmsg ("missing tx interface name or tx_sw_if_index\n");
5382 M(L2_PATCH_ADD_DEL, l2_patch_add_del);
5384 mp->rx_sw_if_index = ntohl(rx_sw_if_index);
5385 mp->tx_sw_if_index = ntohl(tx_sw_if_index);
5386 mp->is_add = is_add;
5392 static int api_trace_profile_add (vat_main_t *vam)
5394 unformat_input_t * input = vam->input;
5395 vl_api_trace_profile_add_t *mp;
5398 u32 trace_option_elts = 0;
5399 u32 trace_type = 0, node_id = 0, app_data = 0, trace_tsp = 2;
5400 int has_pow_option = 0;
5401 int has_ppc_option = 0;
5403 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
5405 if (unformat (input, "id %d trace-type 0x%x trace-elts %d "
5406 "trace-tsp %d node-id 0x%x app-data 0x%x",
5407 &id, &trace_type, &trace_option_elts, &trace_tsp,
5408 &node_id, &app_data))
5410 else if (unformat (input, "pow"))
5412 else if (unformat (input, "ppc encap"))
5413 has_ppc_option = PPC_ENCAP;
5414 else if (unformat (input, "ppc decap"))
5415 has_ppc_option = PPC_DECAP;
5416 else if (unformat (input, "ppc none"))
5417 has_ppc_option = PPC_NONE;
5421 M(TRACE_PROFILE_ADD, trace_profile_add);
5423 mp->trace_type = trace_type;
5424 mp->trace_num_elt = trace_option_elts;
5425 mp->trace_ppc = has_ppc_option;
5426 mp->trace_app_data = htonl(app_data);
5427 mp->pow_enable = has_pow_option;
5428 mp->trace_tsp = trace_tsp;
5429 mp->node_id = htonl(node_id);
5436 static int api_trace_profile_apply (vat_main_t *vam)
5438 unformat_input_t * input = vam->input;
5439 vl_api_trace_profile_apply_t *mp;
5442 u32 mask_width = ~0;
5449 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
5451 if (unformat (input, "%U/%d",
5452 unformat_ip6_address, &addr, &mask_width))
5454 else if (unformat (input, "id %d", &id))
5456 else if (unformat (input, "vrf-id %d", &vrf_id))
5458 else if (unformat (input, "add"))
5460 else if (unformat (input, "pop"))
5462 else if (unformat (input, "none"))
5468 if ((is_add + is_pop + is_none) != 1) {
5469 errmsg("One of (add, pop, none) required");
5472 if (mask_width == ~0) {
5473 errmsg("<address>/<mask-width> required");
5476 M(TRACE_PROFILE_APPLY, trace_profile_apply);
5477 clib_memcpy(mp->dest_ipv6, &addr, sizeof(mp->dest_ipv6));
5479 mp->prefix_length = htonl(mask_width);
5480 mp->vrf_id = htonl(vrf_id);
5482 mp->trace_op = IOAM_HBYH_ADD;
5484 mp->trace_op = IOAM_HBYH_POP;
5486 mp->trace_op = IOAM_HBYH_MOD;
5498 static int api_trace_profile_del (vat_main_t *vam)
5500 vl_api_trace_profile_del_t *mp;
5503 M(TRACE_PROFILE_DEL, trace_profile_del);
5507 static int api_sr_tunnel_add_del (vat_main_t * vam)
5509 unformat_input_t * i = vam->input;
5510 vl_api_sr_tunnel_add_del_t *mp;
5514 ip6_address_t src_address;
5515 int src_address_set = 0;
5516 ip6_address_t dst_address;
5518 int dst_address_set = 0;
5520 u32 rx_table_id = 0;
5521 u32 tx_table_id = 0;
5522 ip6_address_t * segments = 0;
5523 ip6_address_t * this_seg;
5524 ip6_address_t * tags = 0;
5525 ip6_address_t * this_tag;
5526 ip6_address_t next_address, tag;
5528 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
5530 if (unformat (i, "del"))
5532 else if (unformat (i, "rx_fib_id %d", &rx_table_id))
5534 else if (unformat (i, "tx_fib_id %d", &tx_table_id))
5536 else if (unformat (i, "src %U", unformat_ip6_address, &src_address))
5537 src_address_set = 1;
5538 else if (unformat (i, "dst %U/%d",
5539 unformat_ip6_address, &dst_address,
5541 dst_address_set = 1;
5542 else if (unformat (i, "next %U", unformat_ip6_address,
5545 vec_add2 (segments, this_seg, 1);
5546 clib_memcpy (this_seg->as_u8, next_address.as_u8, sizeof (*this_seg));
5548 else if (unformat (i, "tag %U", unformat_ip6_address,
5551 vec_add2 (tags, this_tag, 1);
5552 clib_memcpy (this_tag->as_u8, tag.as_u8, sizeof (*this_tag));
5554 else if (unformat (i, "clean"))
5555 flags |= IP6_SR_HEADER_FLAG_CLEANUP;
5556 else if (unformat (i, "protected"))
5557 flags |= IP6_SR_HEADER_FLAG_PROTECTED;
5558 else if (unformat (i, "InPE %d", &pl_index))
5560 if (pl_index <= 0 || pl_index > 4)
5562 pl_index_range_error:
5563 errmsg ("pl index %d out of range\n", pl_index);
5566 flags |= IP6_SR_HEADER_FLAG_PL_ELT_INGRESS_PE << (3*(pl_index - 1));
5568 else if (unformat (i, "EgPE %d", &pl_index))
5570 if (pl_index <= 0 || pl_index > 4)
5571 goto pl_index_range_error;
5572 flags |= IP6_SR_HEADER_FLAG_PL_ELT_EGRESS_PE << (3*(pl_index - 1));
5574 else if (unformat (i, "OrgSrc %d", &pl_index))
5576 if (pl_index <= 0 || pl_index > 4)
5577 goto pl_index_range_error;
5578 flags |= IP6_SR_HEADER_FLAG_PL_ELT_ORIG_SRC_ADDR << (3*(pl_index - 1));
5584 if (!src_address_set)
5586 errmsg ("src address required\n");
5590 if (!dst_address_set)
5592 errmsg ("dst address required\n");
5598 errmsg ("at least one sr segment required\n");
5602 M2(SR_TUNNEL_ADD_DEL, sr_tunnel_add_del,
5603 vec_len(segments) * sizeof (ip6_address_t)
5604 + vec_len(tags) * sizeof (ip6_address_t));
5606 clib_memcpy (mp->src_address, &src_address, sizeof (mp->src_address));
5607 clib_memcpy (mp->dst_address, &dst_address, sizeof (mp->dst_address));
5608 mp->dst_mask_width = dst_mask_width;
5609 mp->flags_net_byte_order = clib_host_to_net_u16 (flags);
5610 mp->n_segments = vec_len (segments);
5611 mp->n_tags = vec_len (tags);
5612 mp->is_add = is_del == 0;
5613 clib_memcpy (mp->segs_and_tags, segments,
5614 vec_len(segments)* sizeof (ip6_address_t));
5615 clib_memcpy (mp->segs_and_tags + vec_len(segments)*sizeof (ip6_address_t),
5616 tags, vec_len(tags)* sizeof (ip6_address_t));
5618 mp->outer_vrf_id = ntohl (rx_table_id);
5619 mp->inner_vrf_id = ntohl (tx_table_id);
5621 vec_free (segments);
5629 #define foreach_ip4_proto_field \
5639 uword unformat_ip4_mask (unformat_input_t * input, va_list * args)
5641 u8 ** maskp = va_arg (*args, u8 **);
5643 u8 found_something = 0;
5646 #define _(a) u8 a=0;
5647 foreach_ip4_proto_field;
5653 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
5655 if (unformat (input, "version"))
5657 else if (unformat (input, "hdr_length"))
5659 else if (unformat (input, "src"))
5661 else if (unformat (input, "dst"))
5663 else if (unformat (input, "proto"))
5666 #define _(a) else if (unformat (input, #a)) a=1;
5667 foreach_ip4_proto_field
5673 #define _(a) found_something += a;
5674 foreach_ip4_proto_field;
5677 if (found_something == 0)
5680 vec_validate (mask, sizeof (*ip) - 1);
5682 ip = (ip4_header_t *) mask;
5684 #define _(a) if (a) memset (&ip->a, 0xff, sizeof (ip->a));
5685 foreach_ip4_proto_field;
5688 ip->ip_version_and_header_length = 0;
5691 ip->ip_version_and_header_length |= 0xF0;
5694 ip->ip_version_and_header_length |= 0x0F;
5700 #define foreach_ip6_proto_field \
5707 uword unformat_ip6_mask (unformat_input_t * input, va_list * args)
5709 u8 ** maskp = va_arg (*args, u8 **);
5711 u8 found_something = 0;
5713 u32 ip_version_traffic_class_and_flow_label;
5715 #define _(a) u8 a=0;
5716 foreach_ip6_proto_field;
5719 u8 traffic_class = 0;
5722 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
5724 if (unformat (input, "version"))
5726 else if (unformat (input, "traffic-class"))
5728 else if (unformat (input, "flow-label"))
5730 else if (unformat (input, "src"))
5732 else if (unformat (input, "dst"))
5734 else if (unformat (input, "proto"))
5737 #define _(a) else if (unformat (input, #a)) a=1;
5738 foreach_ip6_proto_field
5744 #define _(a) found_something += a;
5745 foreach_ip6_proto_field;
5748 if (found_something == 0)
5751 vec_validate (mask, sizeof (*ip) - 1);
5753 ip = (ip6_header_t *) mask;
5755 #define _(a) if (a) memset (&ip->a, 0xff, sizeof (ip->a));
5756 foreach_ip6_proto_field;
5759 ip_version_traffic_class_and_flow_label = 0;
5762 ip_version_traffic_class_and_flow_label |= 0xF0000000;
5765 ip_version_traffic_class_and_flow_label |= 0x0FF00000;
5768 ip_version_traffic_class_and_flow_label |= 0x000FFFFF;
5770 ip->ip_version_traffic_class_and_flow_label =
5771 clib_host_to_net_u32 (ip_version_traffic_class_and_flow_label);
5777 uword unformat_l3_mask (unformat_input_t * input, va_list * args)
5779 u8 ** maskp = va_arg (*args, u8 **);
5781 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) {
5782 if (unformat (input, "ip4 %U", unformat_ip4_mask, maskp))
5784 else if (unformat (input, "ip6 %U", unformat_ip6_mask, maskp))
5792 uword unformat_l2_mask (unformat_input_t * input, va_list * args)
5794 u8 ** maskp = va_arg (*args, u8 **);
5809 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) {
5810 if (unformat (input, "src"))
5812 else if (unformat (input, "dst"))
5814 else if (unformat (input, "proto"))
5816 else if (unformat (input, "tag1"))
5818 else if (unformat (input, "tag2"))
5820 else if (unformat (input, "ignore-tag1"))
5822 else if (unformat (input, "ignore-tag2"))
5824 else if (unformat (input, "cos1"))
5826 else if (unformat (input, "cos2"))
5828 else if (unformat (input, "dot1q"))
5830 else if (unformat (input, "dot1ad"))
5835 if ((src + dst + proto + tag1 + tag2 + dot1q + dot1ad +
5836 ignore_tag1 + ignore_tag2 + cos1 + cos2) == 0)
5839 if (tag1 || ignore_tag1 || cos1 || dot1q)
5841 if (tag2 || ignore_tag2 || cos2 || dot1ad)
5844 vec_validate (mask, len-1);
5847 memset (mask, 0xff, 6);
5850 memset (mask + 6, 0xff, 6);
5854 /* inner vlan tag */
5863 mask[21] = mask [20] = 0xff;
5884 mask[16] = mask [17] = 0xff;
5894 mask[12] = mask [13] = 0xff;
5900 uword unformat_classify_mask (unformat_input_t * input, va_list * args)
5902 u8 ** maskp = va_arg (*args, u8 **);
5903 u32 * skipp = va_arg (*args, u32 *);
5904 u32 * matchp = va_arg (*args, u32 *);
5911 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) {
5912 if (unformat (input, "hex %U", unformat_hex_string, &mask))
5914 else if (unformat (input, "l2 %U", unformat_l2_mask, &l2))
5916 else if (unformat (input, "l3 %U", unformat_l3_mask, &l3))
5922 if (mask || l2 || l3)
5926 /* "With a free Ethernet header in every package" */
5928 vec_validate (l2, 13);
5930 vec_append (mask, l3);
5934 /* Scan forward looking for the first significant mask octet */
5935 for (i = 0; i < vec_len (mask); i++)
5939 /* compute (skip, match) params */
5940 *skipp = i / sizeof(u32x4);
5941 vec_delete (mask, *skipp * sizeof(u32x4), 0);
5943 /* Pad mask to an even multiple of the vector size */
5944 while (vec_len (mask) % sizeof (u32x4))
5947 match = vec_len (mask) / sizeof (u32x4);
5949 for (i = match*sizeof(u32x4); i > 0; i-= sizeof(u32x4))
5951 u64 *tmp = (u64 *)(mask + (i-sizeof(u32x4)));
5952 if (*tmp || *(tmp+1))
5957 clib_warning ("BUG: match 0");
5959 _vec_len (mask) = match * sizeof(u32x4);
5970 #define foreach_l2_next \
5972 _(ethernet, ETHERNET_INPUT) \
5976 uword unformat_l2_next_index (unformat_input_t * input, va_list * args)
5978 u32 * miss_next_indexp = va_arg (*args, u32 *);
5983 if (unformat (input, #n)) { next_index = L2_CLASSIFY_NEXT_##N; goto out;}
5987 if (unformat (input, "%d", &tmp))
5996 *miss_next_indexp = next_index;
6000 #define foreach_ip_next \
6006 uword unformat_ip_next_index (unformat_input_t * input, va_list * args)
6008 u32 * miss_next_indexp = va_arg (*args, u32 *);
6013 if (unformat (input, #n)) { next_index = IP_LOOKUP_NEXT_##N; goto out;}
6017 if (unformat (input, "%d", &tmp))
6026 *miss_next_indexp = next_index;
6030 #define foreach_acl_next \
6033 uword unformat_acl_next_index (unformat_input_t * input, va_list * args)
6035 u32 * miss_next_indexp = va_arg (*args, u32 *);
6040 if (unformat (input, #n)) { next_index = ACL_NEXT_INDEX_##N; goto out;}
6044 if (unformat (input, "permit"))
6049 else if (unformat (input, "%d", &tmp))
6058 *miss_next_indexp = next_index;
6062 static int api_classify_add_del_table (vat_main_t * vam)
6064 unformat_input_t * i = vam->input;
6065 vl_api_classify_add_del_table_t *mp;
6071 u32 table_index = ~0;
6072 u32 next_table_index = ~0;
6073 u32 miss_next_index = ~0;
6074 u32 memory_size = 32<<20;
6078 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
6079 if (unformat (i, "del"))
6081 else if (unformat (i, "buckets %d", &nbuckets))
6083 else if (unformat (i, "memory_size %d", &memory_size))
6085 else if (unformat (i, "skip %d", &skip))
6087 else if (unformat (i, "match %d", &match))
6089 else if (unformat (i, "table %d", &table_index))
6091 else if (unformat (i, "mask %U", unformat_classify_mask,
6092 &mask, &skip, &match))
6094 else if (unformat (i, "next-table %d", &next_table_index))
6096 else if (unformat (i, "miss-next %U", unformat_ip_next_index,
6099 else if (unformat (i, "l2-miss-next %U", unformat_l2_next_index,
6102 else if (unformat (i, "acl-miss-next %U", unformat_acl_next_index,
6109 if (is_add && mask == 0) {
6110 errmsg ("Mask required\n");
6114 if (is_add && skip == ~0) {
6115 errmsg ("skip count required\n");
6119 if (is_add && match == ~0) {
6120 errmsg ("match count required\n");
6124 if (!is_add && table_index == ~0) {
6125 errmsg ("table index required for delete\n");
6129 M2 (CLASSIFY_ADD_DEL_TABLE, classify_add_del_table,
6132 mp->is_add = is_add;
6133 mp->table_index = ntohl(table_index);
6134 mp->nbuckets = ntohl(nbuckets);
6135 mp->memory_size = ntohl(memory_size);
6136 mp->skip_n_vectors = ntohl(skip);
6137 mp->match_n_vectors = ntohl(match);
6138 mp->next_table_index = ntohl(next_table_index);
6139 mp->miss_next_index = ntohl(miss_next_index);
6140 clib_memcpy (mp->mask, mask, vec_len(mask));
6148 uword unformat_ip4_match (unformat_input_t * input, va_list * args)
6150 u8 ** matchp = va_arg (*args, u8 **);
6157 int src = 0, dst = 0;
6158 ip4_address_t src_val, dst_val;
6165 int fragment_id = 0;
6166 u32 fragment_id_val;
6172 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
6174 if (unformat (input, "version %d", &version_val))
6176 else if (unformat (input, "hdr_length %d", &hdr_length_val))
6178 else if (unformat (input, "src %U", unformat_ip4_address, &src_val))
6180 else if (unformat (input, "dst %U", unformat_ip4_address, &dst_val))
6182 else if (unformat (input, "proto %d", &proto_val))
6184 else if (unformat (input, "tos %d", &tos_val))
6186 else if (unformat (input, "length %d", &length_val))
6188 else if (unformat (input, "fragment_id %d", &fragment_id_val))
6190 else if (unformat (input, "ttl %d", &ttl_val))
6192 else if (unformat (input, "checksum %d", &checksum_val))
6198 if (version + hdr_length + src + dst + proto + tos + length + fragment_id
6199 + ttl + checksum == 0)
6203 * Aligned because we use the real comparison functions
6205 vec_validate_aligned (match, sizeof (*ip) - 1, sizeof(u32x4));
6207 ip = (ip4_header_t *) match;
6209 /* These are realistically matched in practice */
6211 ip->src_address.as_u32 = src_val.as_u32;
6214 ip->dst_address.as_u32 = dst_val.as_u32;
6217 ip->protocol = proto_val;
6220 /* These are not, but they're included for completeness */
6222 ip->ip_version_and_header_length |= (version_val & 0xF)<<4;
6225 ip->ip_version_and_header_length |= (hdr_length_val & 0xF);
6231 ip->length = length_val;
6237 ip->checksum = checksum_val;
6243 uword unformat_ip6_match (unformat_input_t * input, va_list * args)
6245 u8 ** matchp = va_arg (*args, u8 **);
6251 u32 traffic_class_val;
6254 int src = 0, dst = 0;
6255 ip6_address_t src_val, dst_val;
6258 int payload_length = 0;
6259 u32 payload_length_val;
6262 u32 ip_version_traffic_class_and_flow_label;
6264 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
6266 if (unformat (input, "version %d", &version_val))
6268 else if (unformat (input, "traffic_class %d", &traffic_class_val))
6270 else if (unformat (input, "flow_label %d", &flow_label_val))
6272 else if (unformat (input, "src %U", unformat_ip6_address, &src_val))
6274 else if (unformat (input, "dst %U", unformat_ip6_address, &dst_val))
6276 else if (unformat (input, "proto %d", &proto_val))
6278 else if (unformat (input, "payload_length %d", &payload_length_val))
6280 else if (unformat (input, "hop_limit %d", &hop_limit_val))
6286 if (version + traffic_class + flow_label + src + dst + proto +
6287 payload_length + hop_limit == 0)
6291 * Aligned because we use the real comparison functions
6293 vec_validate_aligned (match, sizeof (*ip) - 1, sizeof(u32x4));
6295 ip = (ip6_header_t *) match;
6298 clib_memcpy (&ip->src_address, &src_val, sizeof (ip->src_address));
6301 clib_memcpy (&ip->dst_address, &dst_val, sizeof (ip->dst_address));
6304 ip->protocol = proto_val;
6306 ip_version_traffic_class_and_flow_label = 0;
6309 ip_version_traffic_class_and_flow_label |= (version_val & 0xF) << 28;
6312 ip_version_traffic_class_and_flow_label |= (traffic_class_val & 0xFF) << 20;
6315 ip_version_traffic_class_and_flow_label |= (flow_label_val & 0xFFFFF);
6317 ip->ip_version_traffic_class_and_flow_label =
6318 clib_host_to_net_u32 (ip_version_traffic_class_and_flow_label);
6321 ip->payload_length = clib_host_to_net_u16 (payload_length_val);
6324 ip->hop_limit = hop_limit_val;
6330 uword unformat_l3_match (unformat_input_t * input, va_list * args)
6332 u8 ** matchp = va_arg (*args, u8 **);
6334 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) {
6335 if (unformat (input, "ip4 %U", unformat_ip4_match, matchp))
6337 else if (unformat (input, "ip6 %U", unformat_ip6_match, matchp))
6345 uword unformat_vlan_tag (unformat_input_t * input, va_list * args)
6347 u8 * tagp = va_arg (*args, u8 *);
6350 if (unformat(input, "%d", &tag))
6352 tagp[0] = (tag>>8) & 0x0F;
6353 tagp[1] = tag & 0xFF;
6360 uword unformat_l2_match (unformat_input_t * input, va_list * args)
6362 u8 ** matchp = va_arg (*args, u8 **);
6382 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) {
6383 if (unformat (input, "src %U", unformat_ethernet_address, &src_val))
6385 else if (unformat (input, "dst %U", unformat_ethernet_address, &dst_val))
6387 else if (unformat (input, "proto %U",
6388 unformat_ethernet_type_host_byte_order, &proto_val))
6390 else if (unformat (input, "tag1 %U", unformat_vlan_tag, tag1_val))
6392 else if (unformat (input, "tag2 %U", unformat_vlan_tag, tag2_val))
6394 else if (unformat (input, "ignore-tag1"))
6396 else if (unformat (input, "ignore-tag2"))
6398 else if (unformat (input, "cos1 %d", &cos1_val))
6400 else if (unformat (input, "cos2 %d", &cos2_val))
6405 if ((src + dst + proto + tag1 + tag2 +
6406 ignore_tag1 + ignore_tag2 + cos1 + cos2) == 0)
6409 if (tag1 || ignore_tag1 || cos1)
6411 if (tag2 || ignore_tag2 || cos2)
6414 vec_validate_aligned (match, len-1, sizeof(u32x4));
6417 clib_memcpy (match, dst_val, 6);
6420 clib_memcpy (match + 6, src_val, 6);
6424 /* inner vlan tag */
6425 match[19] = tag2_val[1];
6426 match[18] = tag2_val[0];
6428 match [18] |= (cos2_val & 0x7) << 5;
6431 match[21] = proto_val & 0xff;
6432 match[20] = proto_val >> 8;
6436 match [15] = tag1_val[1];
6437 match [14] = tag1_val[0];
6440 match [14] |= (cos1_val & 0x7) << 5;
6446 match [15] = tag1_val[1];
6447 match [14] = tag1_val[0];
6450 match[17] = proto_val & 0xff;
6451 match[16] = proto_val >> 8;
6454 match [14] |= (cos1_val & 0x7) << 5;
6460 match [18] |= (cos2_val & 0x7) << 5;
6462 match [14] |= (cos1_val & 0x7) << 5;
6465 match[13] = proto_val & 0xff;
6466 match[12] = proto_val >> 8;
6474 uword unformat_classify_match (unformat_input_t * input, va_list * args)
6476 u8 ** matchp = va_arg (*args, u8 **);
6477 u32 skip_n_vectors = va_arg (*args, u32);
6478 u32 match_n_vectors = va_arg (*args, u32);
6484 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) {
6485 if (unformat (input, "hex %U", unformat_hex_string, &match))
6487 else if (unformat (input, "l2 %U", unformat_l2_match, &l2))
6489 else if (unformat (input, "l3 %U", unformat_l3_match, &l3))
6495 if (match || l2 || l3)
6499 /* "Win a free Ethernet header in every packet" */
6501 vec_validate_aligned (l2, 13, sizeof(u32x4));
6503 vec_append_aligned (match, l3, sizeof(u32x4));
6507 /* Make sure the vector is big enough even if key is all 0's */
6508 vec_validate_aligned
6509 (match, ((match_n_vectors + skip_n_vectors) * sizeof(u32x4)) - 1,
6512 /* Set size, include skipped vectors*/
6513 _vec_len (match) = (match_n_vectors+skip_n_vectors) * sizeof(u32x4);
6523 static int api_classify_add_del_session (vat_main_t * vam)
6525 unformat_input_t * i = vam->input;
6526 vl_api_classify_add_del_session_t *mp;
6528 u32 table_index = ~0;
6529 u32 hit_next_index = ~0;
6530 u32 opaque_index = ~0;
6534 u32 skip_n_vectors = 0;
6535 u32 match_n_vectors = 0;
6538 * Warning: you have to supply skip_n and match_n
6539 * because the API client cant simply look at the classify
6543 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
6544 if (unformat (i, "del"))
6546 else if (unformat (i, "hit-next %U", unformat_ip_next_index,
6549 else if (unformat (i, "l2-hit-next %U", unformat_l2_next_index,
6552 else if (unformat (i, "acl-hit-next %U", unformat_acl_next_index,
6555 else if (unformat (i, "opaque-index %d", &opaque_index))
6557 else if (unformat (i, "skip_n %d", &skip_n_vectors))
6559 else if (unformat (i, "match_n %d", &match_n_vectors))
6561 else if (unformat (i, "match %U", unformat_classify_match,
6562 &match, skip_n_vectors, match_n_vectors))
6564 else if (unformat (i, "advance %d", &advance))
6566 else if (unformat (i, "table-index %d", &table_index))
6572 if (table_index == ~0) {
6573 errmsg ("Table index required\n");
6577 if (is_add && match == 0) {
6578 errmsg ("Match value required\n");
6582 M2 (CLASSIFY_ADD_DEL_SESSION, classify_add_del_session,
6585 mp->is_add = is_add;
6586 mp->table_index = ntohl(table_index);
6587 mp->hit_next_index = ntohl(hit_next_index);
6588 mp->opaque_index = ntohl(opaque_index);
6589 mp->advance = ntohl(advance);
6590 clib_memcpy (mp->match, match, vec_len(match));
6597 static int api_classify_set_interface_ip_table (vat_main_t * vam)
6599 unformat_input_t * i = vam->input;
6600 vl_api_classify_set_interface_ip_table_t *mp;
6603 int sw_if_index_set;
6604 u32 table_index = ~0;
6607 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
6608 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
6609 sw_if_index_set = 1;
6610 else if (unformat (i, "sw_if_index %d", &sw_if_index))
6611 sw_if_index_set = 1;
6612 else if (unformat (i, "table %d", &table_index))
6615 clib_warning ("parse error '%U'", format_unformat_error, i);
6620 if (sw_if_index_set == 0) {
6621 errmsg ("missing interface name or sw_if_index\n");
6626 M(CLASSIFY_SET_INTERFACE_IP_TABLE, classify_set_interface_ip_table);
6628 mp->sw_if_index = ntohl(sw_if_index);
6629 mp->table_index = ntohl(table_index);
6630 mp->is_ipv6 = is_ipv6;
6637 static int api_classify_set_interface_l2_tables (vat_main_t * vam)
6639 unformat_input_t * i = vam->input;
6640 vl_api_classify_set_interface_l2_tables_t *mp;
6643 int sw_if_index_set;
6644 u32 ip4_table_index = ~0;
6645 u32 ip6_table_index = ~0;
6646 u32 other_table_index = ~0;
6648 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
6649 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
6650 sw_if_index_set = 1;
6651 else if (unformat (i, "sw_if_index %d", &sw_if_index))
6652 sw_if_index_set = 1;
6653 else if (unformat (i, "ip4-table %d", &ip4_table_index))
6655 else if (unformat (i, "ip6-table %d", &ip6_table_index))
6657 else if (unformat (i, "other-table %d", &other_table_index))
6660 clib_warning ("parse error '%U'", format_unformat_error, i);
6665 if (sw_if_index_set == 0) {
6666 errmsg ("missing interface name or sw_if_index\n");
6671 M(CLASSIFY_SET_INTERFACE_L2_TABLES, classify_set_interface_l2_tables);
6673 mp->sw_if_index = ntohl(sw_if_index);
6674 mp->ip4_table_index = ntohl(ip4_table_index);
6675 mp->ip6_table_index = ntohl(ip6_table_index);
6676 mp->other_table_index = ntohl(other_table_index);
6684 static int api_get_node_index (vat_main_t * vam)
6686 unformat_input_t * i = vam->input;
6687 vl_api_get_node_index_t * mp;
6691 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
6692 if (unformat (i, "node %s", &name))
6698 errmsg ("node name required\n");
6701 if (vec_len (name) >= ARRAY_LEN(mp->node_name)) {
6702 errmsg ("node name too long, max %d\n", ARRAY_LEN(mp->node_name));
6706 M(GET_NODE_INDEX, get_node_index);
6707 clib_memcpy (mp->node_name, name, vec_len(name));
6715 static int api_add_node_next (vat_main_t * vam)
6717 unformat_input_t * i = vam->input;
6718 vl_api_add_node_next_t * mp;
6723 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
6724 if (unformat (i, "node %s", &name))
6726 else if (unformat (i, "next %s", &next))
6732 errmsg ("node name required\n");
6735 if (vec_len (name) >= ARRAY_LEN(mp->node_name)) {
6736 errmsg ("node name too long, max %d\n", ARRAY_LEN(mp->node_name));
6740 errmsg ("next node required\n");
6743 if (vec_len (next) >= ARRAY_LEN(mp->next_name)) {
6744 errmsg ("next name too long, max %d\n", ARRAY_LEN(mp->next_name));
6748 M(ADD_NODE_NEXT, add_node_next);
6749 clib_memcpy (mp->node_name, name, vec_len(name));
6750 clib_memcpy (mp->next_name, next, vec_len(next));
6759 static int api_l2tpv3_create_tunnel (vat_main_t * vam)
6761 unformat_input_t * i = vam->input;
6762 ip6_address_t client_address, our_address;
6763 int client_address_set = 0;
6764 int our_address_set = 0;
6765 u32 local_session_id = 0;
6766 u32 remote_session_id = 0;
6767 u64 local_cookie = 0;
6768 u64 remote_cookie = 0;
6769 u8 l2_sublayer_present = 0;
6770 vl_api_l2tpv3_create_tunnel_t * mp;
6773 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
6774 if (unformat (i, "client_address %U", unformat_ip6_address,
6776 client_address_set = 1;
6777 else if (unformat (i, "our_address %U", unformat_ip6_address,
6779 our_address_set = 1;
6780 else if (unformat (i, "local_session_id %d", &local_session_id))
6782 else if (unformat (i, "remote_session_id %d", &remote_session_id))
6784 else if (unformat (i, "local_cookie %lld", &local_cookie))
6786 else if (unformat (i, "remote_cookie %lld", &remote_cookie))
6788 else if (unformat (i, "l2-sublayer-present"))
6789 l2_sublayer_present = 1;
6794 if (client_address_set == 0) {
6795 errmsg ("client_address required\n");
6799 if (our_address_set == 0) {
6800 errmsg ("our_address required\n");
6804 M(L2TPV3_CREATE_TUNNEL, l2tpv3_create_tunnel);
6806 clib_memcpy (mp->client_address, client_address.as_u8,
6807 sizeof (mp->client_address));
6809 clib_memcpy (mp->our_address, our_address.as_u8,
6810 sizeof (mp->our_address));
6812 mp->local_session_id = ntohl (local_session_id);
6813 mp->remote_session_id = ntohl (remote_session_id);
6814 mp->local_cookie = clib_host_to_net_u64 (local_cookie);
6815 mp->remote_cookie = clib_host_to_net_u64 (remote_cookie);
6816 mp->l2_sublayer_present = l2_sublayer_present;
6824 static int api_l2tpv3_set_tunnel_cookies (vat_main_t * vam)
6826 unformat_input_t * i = vam->input;
6828 u8 sw_if_index_set = 0;
6829 u64 new_local_cookie = 0;
6830 u64 new_remote_cookie = 0;
6831 vl_api_l2tpv3_set_tunnel_cookies_t *mp;
6834 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
6835 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
6836 sw_if_index_set = 1;
6837 else if (unformat (i, "sw_if_index %d", &sw_if_index))
6838 sw_if_index_set = 1;
6839 else if (unformat (i, "new_local_cookie %lld", &new_local_cookie))
6841 else if (unformat (i, "new_remote_cookie %lld", &new_remote_cookie))
6847 if (sw_if_index_set == 0) {
6848 errmsg ("missing interface name or sw_if_index\n");
6852 M(L2TPV3_SET_TUNNEL_COOKIES, l2tpv3_set_tunnel_cookies);
6854 mp->sw_if_index = ntohl(sw_if_index);
6855 mp->new_local_cookie = clib_host_to_net_u64 (new_local_cookie);
6856 mp->new_remote_cookie = clib_host_to_net_u64 (new_remote_cookie);
6863 static int api_l2tpv3_interface_enable_disable (vat_main_t * vam)
6865 unformat_input_t * i = vam->input;
6866 vl_api_l2tpv3_interface_enable_disable_t *mp;
6869 u8 sw_if_index_set = 0;
6870 u8 enable_disable = 1;
6872 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
6873 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
6874 sw_if_index_set = 1;
6875 else if (unformat (i, "sw_if_index %d", &sw_if_index))
6876 sw_if_index_set = 1;
6877 else if (unformat (i, "enable"))
6879 else if (unformat (i, "disable"))
6885 if (sw_if_index_set == 0) {
6886 errmsg ("missing interface name or sw_if_index\n");
6890 M(L2TPV3_INTERFACE_ENABLE_DISABLE, l2tpv3_interface_enable_disable);
6892 mp->sw_if_index = ntohl(sw_if_index);
6893 mp->enable_disable = enable_disable;
6900 static int api_l2tpv3_set_lookup_key (vat_main_t * vam)
6902 unformat_input_t * i = vam->input;
6903 vl_api_l2tpv3_set_lookup_key_t * mp;
6907 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
6908 if (unformat (i, "lookup_v6_src"))
6909 key = L2T_LOOKUP_SRC_ADDRESS;
6910 else if (unformat (i, "lookup_v6_dst"))
6911 key = L2T_LOOKUP_DST_ADDRESS;
6912 else if (unformat (i, "lookup_session_id"))
6913 key = L2T_LOOKUP_SESSION_ID;
6918 if (key == (u8) ~0) {
6919 errmsg ("l2tp session lookup key unset\n");
6923 M(L2TPV3_SET_LOOKUP_KEY, l2tpv3_set_lookup_key);
6932 static void vl_api_sw_if_l2tpv3_tunnel_details_t_handler
6933 (vl_api_sw_if_l2tpv3_tunnel_details_t * mp)
6935 vat_main_t * vam = &vat_main;
6937 fformat(vam->ofp, "* %U (our) %U (client) (sw_if_index %d)\n",
6938 format_ip6_address, mp->our_address,
6939 format_ip6_address, mp->client_address,
6940 clib_net_to_host_u32(mp->sw_if_index));
6942 fformat (vam->ofp, " local cookies %016llx %016llx remote cookie %016llx\n",
6943 clib_net_to_host_u64 (mp->local_cookie[0]),
6944 clib_net_to_host_u64 (mp->local_cookie[1]),
6945 clib_net_to_host_u64 (mp->remote_cookie));
6947 fformat (vam->ofp, " local session-id %d remote session-id %d\n",
6948 clib_net_to_host_u32 (mp->local_session_id),
6949 clib_net_to_host_u32 (mp->remote_session_id));
6951 fformat (vam->ofp, " l2 specific sublayer %s\n\n",
6952 mp->l2_sublayer_present ? "preset" : "absent");
6956 static void vl_api_sw_if_l2tpv3_tunnel_details_t_handler_json
6957 (vl_api_sw_if_l2tpv3_tunnel_details_t * mp)
6959 vat_main_t * vam = &vat_main;
6960 vat_json_node_t *node = NULL;
6961 struct in6_addr addr;
6963 if (VAT_JSON_ARRAY != vam->json_tree.type) {
6964 ASSERT(VAT_JSON_NONE == vam->json_tree.type);
6965 vat_json_init_array(&vam->json_tree);
6967 node = vat_json_array_add(&vam->json_tree);
6969 vat_json_init_object(node);
6971 clib_memcpy(&addr, mp->our_address, sizeof(addr));
6972 vat_json_object_add_ip6(node, "our_address", addr);
6973 clib_memcpy(&addr, mp->client_address, sizeof(addr));
6974 vat_json_object_add_ip6(node, "client_address", addr);
6976 vat_json_node_t * lc = vat_json_object_add(node, "local_cookie");
6977 vat_json_init_array(lc);
6978 vat_json_array_add_uint(lc, clib_net_to_host_u64(mp->local_cookie[0]));
6979 vat_json_array_add_uint(lc, clib_net_to_host_u64(mp->local_cookie[1]));
6980 vat_json_object_add_uint(node, "remote_cookie", clib_net_to_host_u64(mp->remote_cookie));
6982 printf("local id: %u", clib_net_to_host_u32(mp->local_session_id));
6983 vat_json_object_add_uint(node, "local_session_id", clib_net_to_host_u32(mp->local_session_id));
6984 vat_json_object_add_uint(node, "remote_session_id", clib_net_to_host_u32(mp->remote_session_id));
6985 vat_json_object_add_string_copy(node, "l2_sublayer", mp->l2_sublayer_present ?
6986 (u8*)"present" : (u8*)"absent");
6989 static int api_sw_if_l2tpv3_tunnel_dump (vat_main_t * vam)
6991 vl_api_sw_if_l2tpv3_tunnel_dump_t *mp;
6994 /* Get list of l2tpv3-tunnel interfaces */
6995 M(SW_IF_L2TPV3_TUNNEL_DUMP, sw_if_l2tpv3_tunnel_dump);
6998 /* Use a control ping for synchronization */
7000 vl_api_control_ping_t * mp;
7001 M(CONTROL_PING, control_ping);
7008 static void vl_api_sw_interface_tap_details_t_handler
7009 (vl_api_sw_interface_tap_details_t * mp)
7011 vat_main_t * vam = &vat_main;
7013 fformat(vam->ofp, "%-16s %d\n",
7015 clib_net_to_host_u32(mp->sw_if_index));
7018 static void vl_api_sw_interface_tap_details_t_handler_json
7019 (vl_api_sw_interface_tap_details_t * mp)
7021 vat_main_t * vam = &vat_main;
7022 vat_json_node_t *node = NULL;
7024 if (VAT_JSON_ARRAY != vam->json_tree.type) {
7025 ASSERT(VAT_JSON_NONE == vam->json_tree.type);
7026 vat_json_init_array(&vam->json_tree);
7028 node = vat_json_array_add(&vam->json_tree);
7030 vat_json_init_object(node);
7031 vat_json_object_add_uint(node, "sw_if_index", ntohl(mp->sw_if_index));
7032 vat_json_object_add_string_copy(node, "dev_name", mp->dev_name);
7035 static int api_sw_interface_tap_dump (vat_main_t * vam)
7037 vl_api_sw_interface_tap_dump_t *mp;
7040 fformat(vam->ofp, "\n%-16s %s\n", "dev_name", "sw_if_index");
7041 /* Get list of tap interfaces */
7042 M(SW_INTERFACE_TAP_DUMP, sw_interface_tap_dump);
7045 /* Use a control ping for synchronization */
7047 vl_api_control_ping_t * mp;
7048 M(CONTROL_PING, control_ping);
7054 static uword unformat_vxlan_decap_next
7055 (unformat_input_t * input, va_list * args)
7057 u32 * result = va_arg (*args, u32 *);
7060 if (unformat (input, "drop"))
7061 *result = VXLAN_INPUT_NEXT_DROP;
7062 else if (unformat (input, "ip4"))
7063 *result = VXLAN_INPUT_NEXT_IP4_INPUT;
7064 else if (unformat (input, "ip6"))
7065 *result = VXLAN_INPUT_NEXT_IP6_INPUT;
7066 else if (unformat (input, "l2"))
7067 *result = VXLAN_INPUT_NEXT_L2_INPUT;
7068 else if (unformat (input, "%d", &tmp))
7075 static int api_vxlan_add_del_tunnel (vat_main_t * vam)
7077 unformat_input_t * line_input = vam->input;
7078 vl_api_vxlan_add_del_tunnel_t *mp;
7080 ip4_address_t src4, dst4;
7081 ip6_address_t src6, dst6;
7083 u8 ipv4_set = 0, ipv6_set = 0;
7086 u32 encap_vrf_id = 0;
7087 u32 decap_next_index = ~0;
7090 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) {
7091 if (unformat (line_input, "del"))
7093 else if (unformat (line_input, "src %U",
7094 unformat_ip4_address, &src4))
7099 else if (unformat (line_input, "dst %U",
7100 unformat_ip4_address, &dst4))
7105 else if (unformat (line_input, "src %U",
7106 unformat_ip6_address, &src6))
7111 else if (unformat (line_input, "dst %U",
7112 unformat_ip6_address, &dst6))
7117 else if (unformat (line_input, "encap-vrf-id %d", &encap_vrf_id))
7119 else if (unformat (line_input, "decap-next %U",
7120 unformat_vxlan_decap_next, &decap_next_index))
7122 else if (unformat (line_input, "vni %d", &vni))
7125 errmsg ("parse error '%U'\n", format_unformat_error, line_input);
7131 errmsg ("tunnel src address not specified\n");
7135 errmsg ("tunnel dst address not specified\n");
7139 if (ipv4_set && ipv6_set) {
7140 errmsg ("both IPv4 and IPv6 addresses specified");
7144 if ((vni == 0) || (vni>>24)) {
7145 errmsg ("vni not specified or out of range\n");
7149 M (VXLAN_ADD_DEL_TUNNEL, vxlan_add_del_tunnel);
7152 clib_memcpy(&mp->dst_address, &src6, sizeof(src6));
7153 clib_memcpy(&mp->dst_address, &src6, sizeof(dst6));
7155 clib_memcpy(&mp->src_address, &src4, sizeof(src4));
7156 clib_memcpy(&mp->dst_address, &dst4, sizeof(dst4));
7158 mp->encap_vrf_id = ntohl(encap_vrf_id);
7159 mp->decap_next_index = ntohl(decap_next_index);
7160 mp->vni = ntohl(vni);
7161 mp->is_add = is_add;
7162 mp->is_ipv6 = ipv6_set;
7169 static void vl_api_vxlan_tunnel_details_t_handler
7170 (vl_api_vxlan_tunnel_details_t * mp)
7172 vat_main_t * vam = &vat_main;
7174 fformat(vam->ofp, "%11d%24U%24U%14d%18d%13d\n",
7175 ntohl(mp->sw_if_index),
7176 format_ip46_address, &(mp->src_address[0]),
7177 format_ip46_address, &(mp->dst_address[0]),
7178 ntohl(mp->encap_vrf_id),
7179 ntohl(mp->decap_next_index),
7183 static void vl_api_vxlan_tunnel_details_t_handler_json
7184 (vl_api_vxlan_tunnel_details_t * mp)
7186 vat_main_t * vam = &vat_main;
7187 vat_json_node_t *node = NULL;
7189 struct in6_addr ip6;
7191 if (VAT_JSON_ARRAY != vam->json_tree.type) {
7192 ASSERT(VAT_JSON_NONE == vam->json_tree.type);
7193 vat_json_init_array(&vam->json_tree);
7195 node = vat_json_array_add(&vam->json_tree);
7197 vat_json_init_object(node);
7198 vat_json_object_add_uint(node, "sw_if_index", ntohl(mp->sw_if_index));
7200 clib_memcpy(&ip6, &(mp->src_address[0]), sizeof(ip6));
7201 vat_json_object_add_ip6(node, "src_address", ip6);
7202 clib_memcpy(&ip6, &(mp->dst_address[0]), sizeof(ip6));
7203 vat_json_object_add_ip6(node, "dst_address", ip6);
7205 clib_memcpy(&ip4, &(mp->src_address[0]), sizeof(ip4));
7206 vat_json_object_add_ip4(node, "src_address", ip4);
7207 clib_memcpy(&ip4, &(mp->dst_address[0]), sizeof(ip4));
7208 vat_json_object_add_ip4(node, "dst_address", ip4);
7210 vat_json_object_add_uint(node, "encap_vrf_id", ntohl(mp->encap_vrf_id));
7211 vat_json_object_add_uint(node, "decap_next_index", ntohl(mp->decap_next_index));
7212 vat_json_object_add_uint(node, "vni", ntohl(mp->vni));
7213 vat_json_object_add_uint(node, "is_ipv6", mp->is_ipv6 ? 1 : 0);
7216 static int api_vxlan_tunnel_dump (vat_main_t * vam)
7218 unformat_input_t * i = vam->input;
7219 vl_api_vxlan_tunnel_dump_t *mp;
7222 u8 sw_if_index_set = 0;
7224 /* Parse args required to build the message */
7225 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
7226 if (unformat (i, "sw_if_index %d", &sw_if_index))
7227 sw_if_index_set = 1;
7232 if (sw_if_index_set == 0) {
7236 if (!vam->json_output) {
7237 fformat(vam->ofp, "%11s%24s%24s%14s%18s%13s\n",
7238 "sw_if_index", "src_address", "dst_address",
7239 "encap_vrf_id", "decap_next_index", "vni");
7242 /* Get list of vxlan-tunnel interfaces */
7243 M(VXLAN_TUNNEL_DUMP, vxlan_tunnel_dump);
7245 mp->sw_if_index = htonl(sw_if_index);
7249 /* Use a control ping for synchronization */
7251 vl_api_control_ping_t * mp;
7252 M(CONTROL_PING, control_ping);
7258 static int api_l2_fib_clear_table (vat_main_t * vam)
7260 // unformat_input_t * i = vam->input;
7261 vl_api_l2_fib_clear_table_t *mp;
7264 M(L2_FIB_CLEAR_TABLE, l2_fib_clear_table);
7271 static int api_l2_interface_efp_filter (vat_main_t * vam)
7273 unformat_input_t * i = vam->input;
7274 vl_api_l2_interface_efp_filter_t *mp;
7278 u8 sw_if_index_set = 0;
7280 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
7281 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
7282 sw_if_index_set = 1;
7283 else if (unformat (i, "sw_if_index %d", &sw_if_index))
7284 sw_if_index_set = 1;
7285 else if (unformat (i, "enable"))
7287 else if (unformat (i, "disable"))
7290 clib_warning ("parse error '%U'", format_unformat_error, i);
7295 if (sw_if_index_set == 0) {
7296 errmsg ("missing sw_if_index\n");
7300 M(L2_INTERFACE_EFP_FILTER, l2_interface_efp_filter);
7302 mp->sw_if_index = ntohl(sw_if_index);
7303 mp->enable_disable = enable;
7310 #define foreach_vtr_op \
7311 _("disable", L2_VTR_DISABLED) \
7312 _("push-1", L2_VTR_PUSH_1) \
7313 _("push-2", L2_VTR_PUSH_2) \
7314 _("pop-1", L2_VTR_POP_1) \
7315 _("pop-2", L2_VTR_POP_2) \
7316 _("translate-1-1", L2_VTR_TRANSLATE_1_1) \
7317 _("translate-1-2", L2_VTR_TRANSLATE_1_2) \
7318 _("translate-2-1", L2_VTR_TRANSLATE_2_1) \
7319 _("translate-2-2", L2_VTR_TRANSLATE_2_2)
7321 static int api_l2_interface_vlan_tag_rewrite (vat_main_t * vam)
7323 unformat_input_t * i = vam->input;
7324 vl_api_l2_interface_vlan_tag_rewrite_t *mp;
7327 u8 sw_if_index_set = 0;
7334 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
7335 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
7336 sw_if_index_set = 1;
7337 else if (unformat (i, "sw_if_index %d", &sw_if_index))
7338 sw_if_index_set = 1;
7339 else if (unformat (i, "vtr_op %d", &vtr_op))
7341 #define _(n,v) else if (unformat(i, n)) {vtr_op = v; vtr_op_set = 1;}
7345 else if (unformat (i, "push_dot1q %d", &push_dot1q))
7347 else if (unformat (i, "tag1 %d", &tag1))
7349 else if (unformat (i, "tag2 %d", &tag2))
7352 clib_warning ("parse error '%U'", format_unformat_error, i);
7357 if ((sw_if_index_set == 0)||(vtr_op_set == 0)) {
7358 errmsg ("missing vtr operation or sw_if_index\n");
7362 M(L2_INTERFACE_VLAN_TAG_REWRITE, l2_interface_vlan_tag_rewrite)
7364 mp->sw_if_index = ntohl(sw_if_index);
7365 mp->vtr_op = ntohl(vtr_op);
7366 mp->push_dot1q = ntohl(push_dot1q);
7367 mp->tag1 = ntohl(tag1);
7368 mp->tag2 = ntohl(tag2);
7375 static int api_create_vhost_user_if (vat_main_t * vam)
7377 unformat_input_t * i = vam->input;
7378 vl_api_create_vhost_user_if_t *mp;
7382 u8 file_name_set = 0;
7383 u32 custom_dev_instance = ~0;
7385 u8 use_custom_mac = 0;
7387 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
7388 if (unformat (i, "socket %s", &file_name)) {
7391 else if (unformat (i, "renumber %"PRIu32, &custom_dev_instance))
7393 else if (unformat (i, "mac %U", unformat_ethernet_address, hwaddr))
7395 else if (unformat (i, "server"))
7401 if (file_name_set == 0) {
7402 errmsg ("missing socket file name\n");
7406 if (vec_len (file_name) > 255) {
7407 errmsg ("socket file name too long\n");
7410 vec_add1 (file_name, 0);
7412 M(CREATE_VHOST_USER_IF, create_vhost_user_if);
7414 mp->is_server = is_server;
7415 clib_memcpy(mp->sock_filename, file_name, vec_len(file_name));
7416 vec_free(file_name);
7417 if (custom_dev_instance != ~0) {
7419 mp->custom_dev_instance = ntohl(custom_dev_instance);
7421 mp->use_custom_mac = use_custom_mac;
7422 clib_memcpy(mp->mac_address, hwaddr, 6);
7429 static int api_modify_vhost_user_if (vat_main_t * vam)
7431 unformat_input_t * i = vam->input;
7432 vl_api_modify_vhost_user_if_t *mp;
7436 u8 file_name_set = 0;
7437 u32 custom_dev_instance = ~0;
7438 u8 sw_if_index_set = 0;
7439 u32 sw_if_index = (u32)~0;
7441 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
7442 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
7443 sw_if_index_set = 1;
7444 else if (unformat (i, "sw_if_index %d", &sw_if_index))
7445 sw_if_index_set = 1;
7446 else if (unformat (i, "socket %s", &file_name)) {
7449 else if (unformat (i, "renumber %"PRIu32, &custom_dev_instance))
7451 else if (unformat (i, "server"))
7457 if (sw_if_index_set == 0) {
7458 errmsg ("missing sw_if_index or interface name\n");
7462 if (file_name_set == 0) {
7463 errmsg ("missing socket file name\n");
7467 if (vec_len (file_name) > 255) {
7468 errmsg ("socket file name too long\n");
7471 vec_add1 (file_name, 0);
7473 M(MODIFY_VHOST_USER_IF, modify_vhost_user_if);
7475 mp->sw_if_index = ntohl(sw_if_index);
7476 mp->is_server = is_server;
7477 clib_memcpy(mp->sock_filename, file_name, vec_len(file_name));
7478 vec_free(file_name);
7479 if (custom_dev_instance != ~0) {
7481 mp->custom_dev_instance = ntohl(custom_dev_instance);
7489 static int api_delete_vhost_user_if (vat_main_t * vam)
7491 unformat_input_t * i = vam->input;
7492 vl_api_delete_vhost_user_if_t *mp;
7494 u32 sw_if_index = ~0;
7495 u8 sw_if_index_set = 0;
7497 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
7498 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
7499 sw_if_index_set = 1;
7500 else if (unformat (i, "sw_if_index %d", &sw_if_index))
7501 sw_if_index_set = 1;
7506 if (sw_if_index_set == 0) {
7507 errmsg ("missing sw_if_index or interface name\n");
7512 M(DELETE_VHOST_USER_IF, delete_vhost_user_if);
7514 mp->sw_if_index = ntohl(sw_if_index);
7521 static void vl_api_sw_interface_vhost_user_details_t_handler
7522 (vl_api_sw_interface_vhost_user_details_t * mp)
7524 vat_main_t * vam = &vat_main;
7526 fformat(vam->ofp, "%-25s %3" PRIu32 " %6" PRIu32 " %8x %6d %7d %s\n",
7527 (char *)mp->interface_name,
7528 ntohl(mp->sw_if_index), ntohl(mp->virtio_net_hdr_sz),
7529 clib_net_to_host_u64(mp->features), mp->is_server,
7530 ntohl(mp->num_regions), (char *)mp->sock_filename);
7531 fformat(vam->ofp, " Status: '%s'\n", strerror(ntohl(mp->sock_errno)));
7534 static void vl_api_sw_interface_vhost_user_details_t_handler_json
7535 (vl_api_sw_interface_vhost_user_details_t * mp)
7537 vat_main_t * vam = &vat_main;
7538 vat_json_node_t *node = NULL;
7540 if (VAT_JSON_ARRAY != vam->json_tree.type) {
7541 ASSERT(VAT_JSON_NONE == vam->json_tree.type);
7542 vat_json_init_array(&vam->json_tree);
7544 node = vat_json_array_add(&vam->json_tree);
7546 vat_json_init_object(node);
7547 vat_json_object_add_uint(node, "sw_if_index", ntohl(mp->sw_if_index));
7548 vat_json_object_add_string_copy(node, "interface_name", mp->interface_name);
7549 vat_json_object_add_uint(node, "virtio_net_hdr_sz", ntohl(mp->virtio_net_hdr_sz));
7550 vat_json_object_add_uint(node, "features", clib_net_to_host_u64(mp->features));
7551 vat_json_object_add_uint(node, "is_server", mp->is_server);
7552 vat_json_object_add_string_copy(node, "sock_filename", mp->sock_filename);
7553 vat_json_object_add_uint(node, "num_regions", ntohl(mp->num_regions));
7554 vat_json_object_add_uint(node, "sock_errno", ntohl(mp->sock_errno));
7557 static int api_sw_interface_vhost_user_dump (vat_main_t * vam)
7559 vl_api_sw_interface_vhost_user_dump_t *mp;
7561 fformat(vam->ofp, "Interface name idx hdr_sz features server regions filename\n");
7563 /* Get list of vhost-user interfaces */
7564 M(SW_INTERFACE_VHOST_USER_DUMP, sw_interface_vhost_user_dump);
7567 /* Use a control ping for synchronization */
7569 vl_api_control_ping_t * mp;
7570 M(CONTROL_PING, control_ping);
7576 static int api_show_version (vat_main_t * vam)
7578 vl_api_show_version_t *mp;
7581 M(SHOW_VERSION, show_version);
7588 static uword unformat_nsh_gre_decap_next
7589 (unformat_input_t * input, va_list * args)
7591 u32 * result = va_arg (*args, u32 *);
7594 if (unformat (input, "drop"))
7595 *result = NSH_INPUT_NEXT_DROP;
7596 else if (unformat (input, "ip4"))
7597 *result = NSH_INPUT_NEXT_IP4_INPUT;
7598 else if (unformat (input, "ip6"))
7599 *result = NSH_INPUT_NEXT_IP6_INPUT;
7600 else if (unformat (input, "ethernet"))
7601 *result = NSH_INPUT_NEXT_ETHERNET_INPUT;
7602 else if (unformat (input, "%d", &tmp))
7609 static int api_nsh_gre_add_del_tunnel (vat_main_t * vam)
7611 unformat_input_t * line_input = vam->input;
7612 vl_api_nsh_gre_add_del_tunnel_t *mp;
7614 ip4_address_t src, dst;
7618 u32 encap_vrf_id = 0;
7619 u32 decap_vrf_id = 0;
7622 u8 next_protocol = 1; /* ip4 */
7633 u32 decap_next_index = NSH_INPUT_NEXT_IP4_INPUT;
7637 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) {
7638 if (unformat (line_input, "del"))
7640 else if (unformat (line_input, "src %U",
7641 unformat_ip4_address, &src))
7643 else if (unformat (line_input, "dst %U",
7644 unformat_ip4_address, &dst))
7646 else if (unformat (line_input, "encap-vrf-id %d", &encap_vrf_id))
7648 else if (unformat (line_input, "decap-vrf-id %d", &decap_vrf_id))
7650 else if (unformat (line_input, "decap-next %U",
7651 unformat_nsh_gre_decap_next, &decap_next_index))
7653 else if (unformat (line_input, "version %d", &tmp))
7654 ver_o_c |= (tmp & 3) << 6;
7655 else if (unformat (line_input, "o-bit %d", &tmp))
7656 ver_o_c |= (tmp & 1) << 5;
7657 else if (unformat (line_input, "c-bit %d", &tmp))
7658 ver_o_c |= (tmp & 1) << 4;
7659 else if (unformat (line_input, "md-type %d", &tmp))
7661 else if (unformat(line_input, "next-ip4"))
7663 else if (unformat(line_input, "next-ip6"))
7665 else if (unformat(line_input, "next-ethernet"))
7667 else if (unformat (line_input, "c1 %d", &c1))
7669 else if (unformat (line_input, "c2 %d", &c2))
7671 else if (unformat (line_input, "c3 %d", &c3))
7673 else if (unformat (line_input, "c4 %d", &c4))
7675 else if (unformat (line_input, "spi %d", &spi))
7677 else if (unformat (line_input, "si %d", &si))
7679 else if (unformat (line_input, "tlv %x"))
7680 vec_add1 (tlvs, tmp);
7682 errmsg ("parse error '%U'\n", format_unformat_error, line_input);
7688 errmsg ("tunnel src address not specified\n");
7692 errmsg ("tunnel dst address not specified\n");
7697 errmsg ("spi not specified\n");
7702 errmsg ("si not specified\n");
7706 M2 (NSH_GRE_ADD_DEL_TUNNEL, nsh_gre_add_del_tunnel,
7707 sizeof(u32) * vec_len (tlvs));
7709 spi_si = (spi<<8) | si;
7711 mp->src = src.as_u32;
7712 mp->dst = dst.as_u32;
7713 mp->encap_vrf_id = ntohl(encap_vrf_id);
7714 mp->decap_vrf_id = ntohl(decap_vrf_id);
7715 mp->decap_next_index = ntohl(decap_next_index);
7716 mp->tlv_len_in_words = vec_len (tlvs);
7717 mp->is_add = is_add;
7718 mp->ver_o_c = ver_o_c;
7719 mp->length = 6 + vec_len(tlvs);
7720 mp->md_type = md_type;
7721 mp->next_protocol = next_protocol;
7722 mp->spi_si = ntohl(spi_si);
7728 for (i = 0; i < vec_len(tlvs); i++)
7729 mp->tlvs[i] = ntohl(tlvs[i]);
7738 static uword unformat_nsh_vxlan_gpe_decap_next
7739 (unformat_input_t * input, va_list * args)
7741 u32 * result = va_arg (*args, u32 *);
7744 if (unformat (input, "drop"))
7745 *result = NSH_VXLAN_GPE_INPUT_NEXT_DROP;
7746 else if (unformat (input, "ip4"))
7747 *result = NSH_VXLAN_GPE_INPUT_NEXT_IP4_INPUT;
7748 else if (unformat (input, "ip6"))
7749 *result = NSH_VXLAN_GPE_INPUT_NEXT_IP6_INPUT;
7750 else if (unformat (input, "ethernet"))
7751 *result = NSH_VXLAN_GPE_INPUT_NEXT_ETHERNET_INPUT;
7752 else if (unformat (input, "nsh-vxlan-gpe"))
7753 *result = NSH_VXLAN_GPE_INPUT_NEXT_ETHERNET_INPUT;
7754 else if (unformat (input, "%d", &tmp))
7761 static int api_nsh_vxlan_gpe_add_del_tunnel (vat_main_t * vam)
7763 unformat_input_t * line_input = vam->input;
7764 vl_api_nsh_vxlan_gpe_add_del_tunnel_t *mp;
7766 ip4_address_t src, dst;
7770 u32 encap_vrf_id = 0;
7771 u32 decap_vrf_id = 0;
7774 u8 next_protocol = 1; /* ip4 */
7785 u32 decap_next_index = NSH_INPUT_NEXT_IP4_INPUT;
7791 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) {
7792 if (unformat (line_input, "del"))
7794 else if (unformat (line_input, "src %U",
7795 unformat_ip4_address, &src))
7797 else if (unformat (line_input, "dst %U",
7798 unformat_ip4_address, &dst))
7800 else if (unformat (line_input, "encap-vrf-id %d", &encap_vrf_id))
7802 else if (unformat (line_input, "decap-vrf-id %d", &decap_vrf_id))
7804 else if (unformat (line_input, "decap-next %U",
7805 unformat_nsh_vxlan_gpe_decap_next,
7808 else if (unformat (line_input, "vni %d", &vni))
7810 else if (unformat (line_input, "version %d", &tmp))
7811 ver_o_c |= (tmp & 3) << 6;
7812 else if (unformat (line_input, "o-bit %d", &tmp))
7813 ver_o_c |= (tmp & 1) << 5;
7814 else if (unformat (line_input, "c-bit %d", &tmp))
7815 ver_o_c |= (tmp & 1) << 4;
7816 else if (unformat (line_input, "md-type %d", &tmp))
7818 else if (unformat(line_input, "next-ip4"))
7820 else if (unformat(line_input, "next-ip6"))
7822 else if (unformat(line_input, "next-ethernet"))
7824 else if (unformat (line_input, "c1 %d", &c1))
7826 else if (unformat (line_input, "c2 %d", &c2))
7828 else if (unformat (line_input, "c3 %d", &c3))
7830 else if (unformat (line_input, "c4 %d", &c4))
7832 else if (unformat (line_input, "spi %d", &spi))
7834 else if (unformat (line_input, "si %d", &si))
7836 else if (unformat (line_input, "tlv %x"))
7837 vec_add1 (tlvs, tmp);
7839 errmsg ("parse error '%U'\n", format_unformat_error, line_input);
7845 errmsg ("tunnel src address not specified\n");
7849 errmsg ("tunnel dst address not specified\n");
7854 errmsg ("spi not specified\n");
7859 errmsg ("si not specified\n");
7863 errmsg ("vni not specified\n");
7867 M2 (NSH_VXLAN_GPE_ADD_DEL_TUNNEL, nsh_vxlan_gpe_add_del_tunnel,
7868 sizeof(u32) * vec_len (tlvs));
7870 spi_si = (spi<<8) | si;
7872 mp->src = src.as_u32;
7873 mp->dst = dst.as_u32;
7874 mp->encap_vrf_id = ntohl(encap_vrf_id);
7875 mp->decap_vrf_id = ntohl(decap_vrf_id);
7876 mp->decap_next_index = ntohl(decap_next_index);
7877 mp->tlv_len_in_words = vec_len (tlvs);
7878 mp->vni = ntohl(vni);
7879 mp->is_add = is_add;
7880 mp->ver_o_c = ver_o_c;
7881 mp->length = 6 + vec_len(tlvs);
7882 mp->md_type = md_type;
7883 mp->next_protocol = next_protocol;
7884 mp->spi_si = ntohl(spi_si);
7890 for (i = 0; i < vec_len(tlvs); i++)
7891 mp->tlvs[i] = ntohl(tlvs[i]);
7900 static uword unformat_lisp_gpe_decap_next (unformat_input_t * input,
7903 u32 * result = va_arg (*args, u32 *);
7906 if (unformat (input, "drop"))
7907 *result = LISP_GPE_INPUT_NEXT_DROP;
7908 else if (unformat (input, "ip4"))
7909 *result = LISP_GPE_INPUT_NEXT_IP4_INPUT;
7910 else if (unformat (input, "ip6"))
7911 *result = LISP_GPE_INPUT_NEXT_IP6_INPUT;
7912 else if (unformat (input, "ethernet"))
7913 *result = LISP_GPE_INPUT_NEXT_IP6_INPUT;
7914 else if (unformat (input, "%d", &tmp))
7922 api_lisp_gpe_add_del_tunnel (vat_main_t * vam)
7924 unformat_input_t * line_input = vam->input;
7925 vl_api_lisp_gpe_add_del_tunnel_t *mp;
7927 ip4_address_t src, dst;
7931 u32 encap_vrf_id = 0;
7932 u32 decap_vrf_id = 0;
7933 u8 next_protocol = LISP_GPE_NEXT_PROTOCOL_IP4;
7934 u32 decap_next_index = LISP_GPE_INPUT_NEXT_IP4_INPUT;
7935 u8 flags = LISP_GPE_FLAGS_P;
7942 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) {
7943 if (unformat (line_input, "del"))
7945 else if (unformat (line_input, "src %U",
7946 unformat_ip4_address, &src))
7948 else if (unformat (line_input, "dst %U",
7949 unformat_ip4_address, &dst))
7951 else if (unformat (line_input, "encap-vrf-id %d", &encap_vrf_id))
7953 else if (unformat (line_input, "decap-vrf-id %d", &decap_vrf_id))
7955 else if (unformat (line_input, "decap-next %U",
7956 unformat_lisp_gpe_decap_next,
7959 else if (unformat(line_input, "next-ip4"))
7961 else if (unformat(line_input, "next-ip6"))
7963 else if (unformat(line_input, "next-ethernet"))
7965 else if (unformat(line_input, "next-nsh"))
7967 /* Allow the user to specify anything they want in the LISP hdr */
7968 else if (unformat (line_input, "ver_res %x", &tmp))
7970 else if (unformat (line_input, "res %x", &tmp))
7972 else if (unformat (line_input, "flags %x", &tmp))
7974 else if (unformat (line_input, "n-bit"))
7975 flags |= LISP_GPE_FLAGS_N;
7976 else if (unformat (line_input, "l-bit"))
7977 flags |= LISP_GPE_FLAGS_L;
7978 else if (unformat (line_input, "e-bit"))
7979 flags |= LISP_GPE_FLAGS_E;
7980 else if (unformat (line_input, "v-bit"))
7981 flags |= LISP_GPE_FLAGS_V;
7982 else if (unformat (line_input, "i-bit"))
7983 flags |= LISP_GPE_FLAGS_V;
7984 else if (unformat (line_input, "not-p-bit"))
7985 flags &= !LISP_GPE_FLAGS_P;
7986 else if (unformat (line_input, "p-bit"))
7987 flags |= LISP_GPE_FLAGS_P;
7988 else if (unformat (line_input, "o-bit"))
7989 flags |= LISP_GPE_FLAGS_O;
7990 else if (unformat (line_input, "iidx %x", &iid))
7992 else if (unformat (line_input, "iid %d", &iid))
7995 errmsg ("parse error '%U'\n", format_unformat_error, line_input);
8001 errmsg ("tunnel src address not specified\n");
8005 errmsg ("tunnel dst address not specified\n");
8009 errmsg ("iid not specified\n");
8013 M(LISP_GPE_ADD_DEL_TUNNEL, lisp_gpe_add_del_tunnel);
8015 mp->src = src.as_u32;
8016 mp->dst = dst.as_u32;
8017 mp->encap_vrf_id = ntohl(encap_vrf_id);
8018 mp->decap_vrf_id = ntohl(decap_vrf_id);
8019 mp->decap_next_index = ntohl(decap_next_index);
8020 mp->is_add = is_add;
8022 mp->ver_res = ver_res;
8024 mp->next_protocol = next_protocol;
8025 mp->iid = ntohl(iid);
8034 u8 * format_l2_fib_mac_address (u8 * s, va_list * args)
8036 u8 * a = va_arg (*args, u8 *);
8038 return format (s, "%02x:%02x:%02x:%02x:%02x:%02x",
8039 a[2], a[3], a[4], a[5], a[6], a[7]);
8042 static void vl_api_l2_fib_table_entry_t_handler
8043 (vl_api_l2_fib_table_entry_t * mp)
8045 vat_main_t * vam = &vat_main;
8047 fformat(vam->ofp, "%3" PRIu32 " %U %3" PRIu32
8049 ntohl(mp->bd_id), format_l2_fib_mac_address, &mp->mac,
8050 ntohl(mp->sw_if_index), mp->static_mac, mp->filter_mac,
8054 static void vl_api_l2_fib_table_entry_t_handler_json
8055 (vl_api_l2_fib_table_entry_t * mp)
8057 vat_main_t * vam = &vat_main;
8058 vat_json_node_t *node = NULL;
8060 if (VAT_JSON_ARRAY != vam->json_tree.type) {
8061 ASSERT(VAT_JSON_NONE == vam->json_tree.type);
8062 vat_json_init_array(&vam->json_tree);
8064 node = vat_json_array_add(&vam->json_tree);
8066 vat_json_init_object(node);
8067 vat_json_object_add_uint(node, "bd_id", ntohl(mp->bd_id));
8068 vat_json_object_add_uint(node, "mac", clib_net_to_host_u64(mp->mac));
8069 vat_json_object_add_uint(node, "sw_if_index", ntohl(mp->sw_if_index));
8070 vat_json_object_add_uint(node, "static_mac", mp->static_mac);
8071 vat_json_object_add_uint(node, "filter_mac", mp->filter_mac);
8072 vat_json_object_add_uint(node, "bvi_mac", mp->bvi_mac);
8075 static int api_l2_fib_table_dump (vat_main_t * vam)
8077 unformat_input_t * i = vam->input;
8078 vl_api_l2_fib_table_dump_t *mp;
8083 /* Parse args required to build the message */
8084 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
8085 if (unformat (i, "bd_id %d", &bd_id))
8091 if (bd_id_set == 0) {
8092 errmsg ("missing bridge domain\n");
8096 fformat(vam->ofp, "BD-ID Mac Address sw-ndx Static Filter BVI\n");
8098 /* Get list of l2 fib entries */
8099 M(L2_FIB_TABLE_DUMP, l2_fib_table_dump);
8101 mp->bd_id = ntohl(bd_id);
8104 /* Use a control ping for synchronization */
8106 vl_api_control_ping_t * mp;
8107 M(CONTROL_PING, control_ping);
8115 api_interface_name_renumber (vat_main_t * vam)
8117 unformat_input_t * line_input = vam->input;
8118 vl_api_interface_name_renumber_t *mp;
8119 u32 sw_if_index = ~0;
8121 u32 new_show_dev_instance = ~0;
8123 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) {
8124 if (unformat (line_input, "%U", unformat_sw_if_index, vam,
8127 else if (unformat (line_input, "sw_if_index %d", &sw_if_index))
8129 else if (unformat (line_input, "new_show_dev_instance %d",
8130 &new_show_dev_instance))
8136 if (sw_if_index == ~0) {
8137 errmsg ("missing interface name or sw_if_index\n");
8141 if (new_show_dev_instance == ~0) {
8142 errmsg ("missing new_show_dev_instance\n");
8146 M(INTERFACE_NAME_RENUMBER, interface_name_renumber);
8148 mp->sw_if_index = ntohl (sw_if_index);
8149 mp->new_show_dev_instance = ntohl (new_show_dev_instance);
8155 api_want_ip4_arp_events (vat_main_t * vam)
8157 unformat_input_t * line_input = vam->input;
8158 vl_api_want_ip4_arp_events_t * mp;
8160 ip4_address_t address;
8161 int address_set = 0;
8162 u32 enable_disable = 1;
8164 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) {
8165 if (unformat (line_input, "address %U",
8166 unformat_ip4_address, &address))
8168 else if (unformat (line_input, "del"))
8174 if (address_set == 0) {
8175 errmsg ("missing addresses\n");
8179 M(WANT_IP4_ARP_EVENTS, want_ip4_arp_events);
8180 mp->enable_disable = enable_disable;
8182 mp->address = address.as_u32;
8187 static int api_input_acl_set_interface (vat_main_t * vam)
8189 unformat_input_t * i = vam->input;
8190 vl_api_input_acl_set_interface_t *mp;
8193 int sw_if_index_set;
8194 u32 ip4_table_index = ~0;
8195 u32 ip6_table_index = ~0;
8196 u32 l2_table_index = ~0;
8199 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
8200 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
8201 sw_if_index_set = 1;
8202 else if (unformat (i, "sw_if_index %d", &sw_if_index))
8203 sw_if_index_set = 1;
8204 else if (unformat (i, "del"))
8206 else if (unformat (i, "ip4-table %d", &ip4_table_index))
8208 else if (unformat (i, "ip6-table %d", &ip6_table_index))
8210 else if (unformat (i, "l2-table %d", &l2_table_index))
8213 clib_warning ("parse error '%U'", format_unformat_error, i);
8218 if (sw_if_index_set == 0) {
8219 errmsg ("missing interface name or sw_if_index\n");
8223 M(INPUT_ACL_SET_INTERFACE, input_acl_set_interface);
8225 mp->sw_if_index = ntohl(sw_if_index);
8226 mp->ip4_table_index = ntohl(ip4_table_index);
8227 mp->ip6_table_index = ntohl(ip6_table_index);
8228 mp->l2_table_index = ntohl(l2_table_index);
8229 mp->is_add = is_add;
8237 api_ip_address_dump (vat_main_t * vam)
8239 unformat_input_t * i = vam->input;
8240 vl_api_ip_address_dump_t * mp;
8241 u32 sw_if_index = ~0;
8242 u8 sw_if_index_set = 0;
8247 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
8248 if (unformat (i, "sw_if_index %d", &sw_if_index))
8249 sw_if_index_set = 1;
8250 else if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
8251 sw_if_index_set = 1;
8252 else if (unformat (i, "ipv4"))
8254 else if (unformat (i, "ipv6"))
8260 if (ipv4_set && ipv6_set) {
8261 errmsg ("ipv4 and ipv6 flags cannot be both set\n");
8265 if ((!ipv4_set) && (!ipv6_set)) {
8266 errmsg ("no ipv4 nor ipv6 flag set\n");
8270 if (sw_if_index_set == 0) {
8271 errmsg ("missing interface name or sw_if_index\n");
8275 vam->current_sw_if_index = sw_if_index;
8276 vam->is_ipv6 = ipv6_set;
8278 M(IP_ADDRESS_DUMP, ip_address_dump);
8279 mp->sw_if_index = ntohl(sw_if_index);
8280 mp->is_ipv6 = ipv6_set;
8283 /* Use a control ping for synchronization */
8285 vl_api_control_ping_t * mp;
8286 M(CONTROL_PING, control_ping);
8293 api_ip_dump (vat_main_t * vam)
8295 vl_api_ip_dump_t * mp;
8296 unformat_input_t * in = vam->input;
8303 while (unformat_check_input (in) != UNFORMAT_END_OF_INPUT) {
8304 if (unformat (in, "ipv4"))
8306 else if (unformat (in, "ipv6"))
8312 if (ipv4_set && ipv6_set) {
8313 errmsg ("ipv4 and ipv6 flags cannot be both set\n");
8317 if ((!ipv4_set) && (!ipv6_set)) {
8318 errmsg ("no ipv4 nor ipv6 flag set\n");
8323 vam->is_ipv6 = is_ipv6;
8326 for (i = 0; i < vec_len(vam->ip_details_by_sw_if_index[is_ipv6]); i++) {
8327 vec_free(vam->ip_details_by_sw_if_index[is_ipv6][i].addr);
8329 vec_free(vam->ip_details_by_sw_if_index[is_ipv6]);
8331 M(IP_DUMP, ip_dump);
8332 mp->is_ipv6 = ipv6_set;
8335 /* Use a control ping for synchronization */
8337 vl_api_control_ping_t * mp;
8338 M(CONTROL_PING, control_ping);
8345 api_ipsec_spd_add_del (vat_main_t * vam)
8348 unformat_input_t * i = vam->input;
8349 vl_api_ipsec_spd_add_del_t *mp;
8354 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
8355 if (unformat (i, "spd_id %d", &spd_id))
8357 else if (unformat (i, "del"))
8360 clib_warning ("parse error '%U'", format_unformat_error, i);
8365 errmsg ("spd_id must be set\n");
8369 M(IPSEC_SPD_ADD_DEL, ipsec_spd_add_del);
8371 mp->spd_id = ntohl(spd_id);
8372 mp->is_add = is_add;
8378 clib_warning ("unsupported (no dpdk)");
8384 api_ipsec_interface_add_del_spd (vat_main_t * vam)
8387 unformat_input_t * i = vam->input;
8388 vl_api_ipsec_interface_add_del_spd_t *mp;
8391 u8 sw_if_index_set = 0;
8392 u32 spd_id = (u32) ~0;
8395 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
8396 if (unformat (i, "del"))
8398 else if (unformat (i, "spd_id %d", &spd_id))
8400 else if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
8401 sw_if_index_set = 1;
8402 else if (unformat (i, "sw_if_index %d", &sw_if_index))
8403 sw_if_index_set = 1;
8405 clib_warning ("parse error '%U'", format_unformat_error, i);
8411 if (spd_id == (u32) ~0) {
8412 errmsg ("spd_id must be set\n");
8416 if (sw_if_index_set == 0) {
8417 errmsg ("missing interface name or sw_if_index\n");
8421 M(IPSEC_INTERFACE_ADD_DEL_SPD, ipsec_interface_add_del_spd);
8423 mp->spd_id = ntohl(spd_id);
8424 mp->sw_if_index = ntohl (sw_if_index);
8425 mp->is_add = is_add;
8431 clib_warning ("unsupported (no dpdk)");
8437 api_ipsec_spd_add_del_entry (vat_main_t * vam)
8440 unformat_input_t * i = vam->input;
8441 vl_api_ipsec_spd_add_del_entry_t *mp;
8443 u8 is_add = 1, is_outbound = 0, is_ipv6 = 0, is_ip_any = 1;
8444 u32 spd_id, sa_id, protocol = 0, policy = 0;
8446 u32 rport_start = 0, rport_stop = (u32) ~0;
8447 u32 lport_start = 0, lport_stop = (u32) ~0;
8448 ip4_address_t laddr4_start, laddr4_stop, raddr4_start, raddr4_stop;
8449 ip6_address_t laddr6_start, laddr6_stop, raddr6_start, raddr6_stop;
8451 laddr4_start.as_u32 = raddr4_start.as_u32 = 0;
8452 laddr4_stop.as_u32 = raddr4_stop.as_u32 = (u32) ~0;
8453 laddr6_start.as_u64[0] = raddr6_start.as_u64[0] = 0;
8454 laddr6_start.as_u64[1] = raddr6_start.as_u64[1] = 0;
8455 laddr6_stop.as_u64[0] = raddr6_stop.as_u64[0] = (u64) ~0;
8456 laddr6_stop.as_u64[1] = raddr6_stop.as_u64[1] = (u64) ~0;
8458 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
8459 if (unformat (i, "del"))
8461 if (unformat (i, "outbound"))
8463 if (unformat (i, "inbound"))
8465 else if (unformat (i, "spd_id %d", &spd_id))
8467 else if (unformat (i, "sa_id %d", &sa_id))
8469 else if (unformat (i, "priority %d", &priority))
8471 else if (unformat (i, "protocol %d", &protocol))
8473 else if (unformat (i, "lport_start %d", &lport_start))
8475 else if (unformat (i, "lport_stop %d", &lport_stop))
8477 else if (unformat (i, "rport_start %d", &rport_start))
8479 else if (unformat (i, "rport_stop %d", &rport_stop))
8481 else if (unformat (i, "laddr_start %U", unformat_ip4_address, &laddr4_start))
8486 else if (unformat (i, "laddr_stop %U", unformat_ip4_address, &laddr4_stop))
8491 else if (unformat (i, "raddr_start %U", unformat_ip4_address, &raddr4_start))
8496 else if (unformat (i, "raddr_stop %U", unformat_ip4_address, &raddr4_stop))
8501 else if (unformat (i, "laddr_start %U", unformat_ip6_address, &laddr6_start))
8506 else if (unformat (i, "laddr_stop %U", unformat_ip6_address, &laddr6_stop))
8511 else if (unformat (i, "raddr_start %U", unformat_ip6_address, &raddr6_start))
8516 else if (unformat (i, "raddr_stop %U", unformat_ip6_address, &raddr6_stop))
8521 else if (unformat (i, "action %U", unformat_ipsec_policy_action, &policy))
8523 if (policy == IPSEC_POLICY_ACTION_RESOLVE) {
8524 clib_warning ("unsupported action: 'resolve'");
8529 clib_warning ("parse error '%U'", format_unformat_error, i);
8535 M(IPSEC_SPD_ADD_DEL_ENTRY, ipsec_spd_add_del_entry);
8537 mp->spd_id = ntohl(spd_id);
8538 mp->priority = ntohl(priority);
8539 mp->is_outbound = is_outbound;
8541 mp->is_ipv6 = is_ipv6;
8542 if (is_ipv6 || is_ip_any) {
8543 clib_memcpy (mp->remote_address_start, &raddr6_start, sizeof(ip6_address_t));
8544 clib_memcpy (mp->remote_address_stop, &raddr6_stop, sizeof(ip6_address_t));
8545 clib_memcpy (mp->local_address_start, &laddr6_start, sizeof(ip6_address_t));
8546 clib_memcpy (mp->local_address_stop, &laddr6_stop, sizeof(ip6_address_t));
8548 clib_memcpy (mp->remote_address_start, &raddr4_start, sizeof(ip4_address_t));
8549 clib_memcpy (mp->remote_address_stop, &raddr4_stop, sizeof(ip4_address_t));
8550 clib_memcpy (mp->local_address_start, &laddr4_start, sizeof(ip4_address_t));
8551 clib_memcpy (mp->local_address_stop, &laddr4_stop, sizeof(ip4_address_t));
8553 mp->protocol = (u8) protocol;
8554 mp->local_port_start = ntohs((u16) lport_start);
8555 mp->local_port_stop = ntohs((u16) lport_stop);
8556 mp->remote_port_start = ntohs((u16) rport_start);
8557 mp->remote_port_stop = ntohs((u16) rport_stop);
8558 mp->policy = (u8) policy;
8559 mp->sa_id = ntohl(sa_id);
8560 mp->is_add = is_add;
8561 mp->is_ip_any = is_ip_any;
8566 clib_warning ("unsupported (no dpdk)");
8572 api_ipsec_sad_add_del_entry (vat_main_t * vam)
8575 unformat_input_t * i = vam->input;
8576 vl_api_ipsec_sad_add_del_entry_t *mp;
8582 u8 protocol = IPSEC_PROTOCOL_AH;
8583 u8 is_tunnel = 0, is_tunnel_ipv6 = 0;
8584 u32 crypto_alg = 0, integ_alg = 0;
8585 ip4_address_t tun_src4;
8586 ip4_address_t tun_dst4;
8587 ip6_address_t tun_src6;
8588 ip6_address_t tun_dst6;
8590 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
8591 if (unformat (i, "del"))
8593 else if (unformat (i, "sad_id %d", &sad_id))
8595 else if (unformat (i, "spi %d", &spi))
8597 else if (unformat (i, "esp"))
8598 protocol = IPSEC_PROTOCOL_ESP;
8599 else if (unformat (i, "tunnel_src %U", unformat_ip4_address, &tun_src4)) {
8603 else if (unformat (i, "tunnel_dst %U", unformat_ip4_address, &tun_dst4)) {
8607 else if (unformat (i, "tunnel_src %U", unformat_ip6_address, &tun_src6)) {
8611 else if (unformat (i, "tunnel_dst %U", unformat_ip6_address, &tun_dst6)) {
8615 else if (unformat (i, "crypto_alg %U", unformat_ipsec_crypto_alg, &crypto_alg)) {
8616 if (crypto_alg < IPSEC_CRYPTO_ALG_AES_CBC_128 ||
8617 crypto_alg > IPSEC_INTEG_ALG_SHA_512_256) {
8618 clib_warning ("unsupported crypto-alg: '%U'",
8619 format_ipsec_crypto_alg, crypto_alg);
8623 else if (unformat (i, "crypto_key %U", unformat_hex_string, &ck))
8625 else if (unformat (i, "integ_alg %U", unformat_ipsec_integ_alg, &integ_alg)) {
8626 if (integ_alg < IPSEC_INTEG_ALG_SHA1_96 ||
8627 integ_alg > IPSEC_INTEG_ALG_SHA_512_256) {
8628 clib_warning ("unsupported integ-alg: '%U'",
8629 format_ipsec_integ_alg, integ_alg);
8633 else if (unformat (i, "integ_key %U", unformat_hex_string, &ik))
8636 clib_warning ("parse error '%U'", format_unformat_error, i);
8642 M(IPSEC_SAD_ADD_DEL_ENTRY, ipsec_sad_add_del_entry);
8644 mp->sad_id = ntohl(sad_id);
8645 mp->is_add = is_add;
8646 mp->protocol = protocol;
8647 mp->spi = ntohl(spi);
8648 mp->is_tunnel = is_tunnel;
8649 mp->is_tunnel_ipv6 = is_tunnel_ipv6;
8650 mp->crypto_algorithm = crypto_alg;
8651 mp->integrity_algorithm = integ_alg;
8652 mp->crypto_key_length = vec_len(ck);
8653 mp->integrity_key_length = vec_len(ik);
8655 if (mp->crypto_key_length > sizeof(mp->crypto_key))
8656 mp->crypto_key_length = sizeof(mp->crypto_key);
8658 if (mp->integrity_key_length > sizeof(mp->integrity_key))
8659 mp->integrity_key_length = sizeof(mp->integrity_key);
8661 clib_memcpy (mp->crypto_key, ck, mp->crypto_key_length);
8662 clib_memcpy (mp->integrity_key, ik, mp->integrity_key_length);
8665 if (is_tunnel_ipv6) {
8666 clib_memcpy (mp->tunnel_src_address, &tun_src6, sizeof(ip6_address_t));
8667 clib_memcpy (mp->tunnel_dst_address, &tun_dst6, sizeof(ip6_address_t));
8669 clib_memcpy (mp->tunnel_src_address, &tun_src4, sizeof(ip4_address_t));
8670 clib_memcpy (mp->tunnel_dst_address, &tun_dst4, sizeof(ip4_address_t));
8678 clib_warning ("unsupported (no dpdk)");
8684 api_ipsec_sa_set_key (vat_main_t * vam)
8687 unformat_input_t * i = vam->input;
8688 vl_api_ipsec_sa_set_key_t *mp;
8693 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
8694 if (unformat (i, "sa_id %d", &sa_id))
8696 else if (unformat (i, "crypto_key %U", unformat_hex_string, &ck))
8698 else if (unformat (i, "integ_key %U", unformat_hex_string, &ik))
8701 clib_warning ("parse error '%U'", format_unformat_error, i);
8706 M(IPSEC_SA_SET_KEY, ipsec_set_sa_key);
8708 mp->sa_id = ntohl(sa_id);
8709 mp->crypto_key_length = vec_len(ck);
8710 mp->integrity_key_length = vec_len(ik);
8712 if (mp->crypto_key_length > sizeof(mp->crypto_key))
8713 mp->crypto_key_length = sizeof(mp->crypto_key);
8715 if (mp->integrity_key_length > sizeof(mp->integrity_key))
8716 mp->integrity_key_length = sizeof(mp->integrity_key);
8718 clib_memcpy (mp->crypto_key, ck, mp->crypto_key_length);
8719 clib_memcpy (mp->integrity_key, ik, mp->integrity_key_length);
8725 clib_warning ("unsupported (no dpdk)");
8731 api_ikev2_profile_add_del (vat_main_t * vam)
8734 unformat_input_t * i = vam->input;
8735 vl_api_ikev2_profile_add_del_t * mp;
8740 const char * valid_chars = "a-zA-Z0-9_";
8742 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
8743 if (unformat (i, "del"))
8745 else if (unformat (i, "name %U", unformat_token, valid_chars, &name))
8748 errmsg ("parse error '%U'", format_unformat_error, i);
8753 if (!vec_len (name)) {
8754 errmsg ("profile name must be specified");
8758 if (vec_len (name) > 64) {
8759 errmsg ("profile name too long");
8763 M(IKEV2_PROFILE_ADD_DEL, ikev2_profile_add_del);
8765 clib_memcpy(mp->name, name, vec_len (name));
8766 mp->is_add = is_add;
8773 clib_warning ("unsupported (no dpdk)");
8779 api_ikev2_profile_set_auth (vat_main_t * vam)
8782 unformat_input_t * i = vam->input;
8783 vl_api_ikev2_profile_set_auth_t * mp;
8787 u32 auth_method = 0;
8790 const char * valid_chars = "a-zA-Z0-9_";
8792 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
8793 if (unformat (i, "name %U", unformat_token, valid_chars, &name))
8795 else if (unformat (i, "auth_method %U",
8796 unformat_ikev2_auth_method, &auth_method))
8798 else if (unformat (i, "auth_data 0x%U", unformat_hex_string, &data))
8800 else if (unformat (i, "auth_data %v", &data))
8803 errmsg ("parse error '%U'", format_unformat_error, i);
8808 if (!vec_len (name)) {
8809 errmsg ("profile name must be specified");
8813 if (vec_len (name) > 64) {
8814 errmsg ("profile name too long");
8818 if (!vec_len(data)) {
8819 errmsg ("auth_data must be specified");
8824 errmsg ("auth_method must be specified");
8828 M(IKEV2_PROFILE_SET_AUTH, ikev2_profile_set_auth);
8830 mp->is_hex = is_hex;
8831 mp->auth_method = (u8) auth_method;
8832 mp->data_len = vec_len (data);
8833 clib_memcpy (mp->name, name, vec_len (name));
8834 clib_memcpy (mp->data, data, vec_len (data));
8842 clib_warning ("unsupported (no dpdk)");
8848 api_ikev2_profile_set_id (vat_main_t * vam)
8851 unformat_input_t * i = vam->input;
8852 vl_api_ikev2_profile_set_id_t * mp;
8860 const char * valid_chars = "a-zA-Z0-9_";
8862 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
8863 if (unformat (i, "name %U", unformat_token, valid_chars, &name))
8865 else if (unformat (i, "id_type %U",
8866 unformat_ikev2_id_type, &id_type))
8868 else if (unformat (i, "id_data %U", unformat_ip4_address, &ip4))
8870 data = vec_new(u8, 4);
8871 clib_memcpy(data, ip4.as_u8, 4);
8873 else if (unformat (i, "id_data 0x%U", unformat_hex_string, &data))
8875 else if (unformat (i, "id_data %v", &data))
8877 else if (unformat (i, "local"))
8879 else if (unformat (i, "remote"))
8882 errmsg ("parse error '%U'", format_unformat_error, i);
8887 if (!vec_len (name)) {
8888 errmsg ("profile name must be specified");
8892 if (vec_len (name) > 64) {
8893 errmsg ("profile name too long");
8897 if (!vec_len(data)) {
8898 errmsg ("id_data must be specified");
8903 errmsg ("id_type must be specified");
8907 M(IKEV2_PROFILE_SET_ID, ikev2_profile_set_id);
8909 mp->is_local = is_local;
8910 mp->id_type = (u8) id_type;
8911 mp->data_len = vec_len (data);
8912 clib_memcpy (mp->name, name, vec_len (name));
8913 clib_memcpy (mp->data, data, vec_len (data));
8921 clib_warning ("unsupported (no dpdk)");
8927 api_ikev2_profile_set_ts (vat_main_t * vam)
8930 unformat_input_t * i = vam->input;
8931 vl_api_ikev2_profile_set_ts_t * mp;
8935 u32 proto = 0, start_port = 0, end_port = (u32) ~0;
8936 ip4_address_t start_addr, end_addr;
8938 const char * valid_chars = "a-zA-Z0-9_";
8940 start_addr.as_u32 = 0;
8941 end_addr.as_u32 = (u32) ~0;
8943 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
8944 if (unformat (i, "name %U", unformat_token, valid_chars, &name))
8946 else if (unformat (i, "protocol %d", &proto))
8948 else if (unformat (i, "start_port %d", &start_port))
8950 else if (unformat (i, "end_port %d", &end_port))
8952 else if (unformat (i, "start_addr %U", unformat_ip4_address, &start_addr))
8954 else if (unformat (i, "end_addr %U", unformat_ip4_address, &end_addr))
8956 else if (unformat (i, "local"))
8958 else if (unformat (i, "remote"))
8961 errmsg ("parse error '%U'", format_unformat_error, i);
8966 if (!vec_len (name)) {
8967 errmsg ("profile name must be specified");
8971 if (vec_len (name) > 64) {
8972 errmsg ("profile name too long");
8976 M(IKEV2_PROFILE_SET_TS, ikev2_profile_set_ts);
8978 mp->is_local = is_local;
8979 mp->proto = (u8) proto;
8980 mp->start_port = (u16) start_port;
8981 mp->end_port = (u16) end_port;
8982 mp->start_addr = start_addr.as_u32;
8983 mp->end_addr = end_addr.as_u32;
8984 clib_memcpy (mp->name, name, vec_len (name));
8991 clib_warning ("unsupported (no dpdk)");
8997 api_ikev2_set_local_key (vat_main_t * vam)
9000 unformat_input_t * i = vam->input;
9001 vl_api_ikev2_set_local_key_t * mp;
9005 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
9006 if (unformat (i, "file %v", &file))
9009 errmsg ("parse error '%U'", format_unformat_error, i);
9014 if (!vec_len (file)) {
9015 errmsg ("RSA key file must be specified");
9019 if (vec_len (file) > 256) {
9020 errmsg ("file name too long");
9024 M(IKEV2_SET_LOCAL_KEY, ikev2_set_local_key);
9026 clib_memcpy (mp->key_file, file, vec_len (file));
9033 clib_warning ("unsupported (no dpdk)");
9041 static int api_map_add_domain (vat_main_t * vam)
9043 unformat_input_t *i = vam->input;
9044 vl_api_map_add_domain_t *mp;
9047 ip4_address_t ip4_prefix;
9048 ip6_address_t ip6_prefix;
9049 ip6_address_t ip6_src;
9051 u32 ip6_prefix_len, ip4_prefix_len, ea_bits_len, psid_offset,
9053 u8 is_translation = 0;
9055 u8 ip6_src_len = 128;
9057 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
9058 if (unformat (i, "ip4-pfx %U/%d", unformat_ip4_address,
9059 &ip4_prefix, &ip4_prefix_len))
9061 else if (unformat (i, "ip6-pfx %U/%d", unformat_ip6_address,
9062 &ip6_prefix, &ip6_prefix_len))
9064 else if (unformat (i, "ip6-src %U/%d", unformat_ip6_address, &ip6_src, &ip6_src_len))
9066 else if (unformat (i, "ip6-src %U", unformat_ip6_address, &ip6_src))
9068 else if (unformat (i, "ea-bits-len %d", &ea_bits_len))
9070 else if (unformat (i, "psid-offset %d", &psid_offset))
9072 else if (unformat (i, "psid-len %d", &psid_length))
9074 else if (unformat (i, "mtu %d", &mtu))
9076 else if (unformat (i, "map-t"))
9079 clib_warning ("parse error '%U'", format_unformat_error, i);
9084 if (num_m_args != 6) {
9085 errmsg("mandatory argument(s) missing\n");
9089 /* Construct the API message */
9090 M(MAP_ADD_DOMAIN, map_add_domain);
9092 clib_memcpy(mp->ip4_prefix, &ip4_prefix, sizeof(ip4_prefix));
9093 mp->ip4_prefix_len = ip4_prefix_len;
9095 clib_memcpy(mp->ip6_prefix, &ip6_prefix, sizeof(ip6_prefix));
9096 mp->ip6_prefix_len = ip6_prefix_len;
9098 clib_memcpy(mp->ip6_src, &ip6_src, sizeof(ip6_src));
9099 mp->ip6_src_prefix_len = ip6_src_len;
9101 mp->ea_bits_len = ea_bits_len;
9102 mp->psid_offset = psid_offset;
9103 mp->psid_length = psid_length;
9104 mp->is_translation = is_translation;
9105 mp->mtu = htons(mtu);
9110 /* Wait for a reply, return good/bad news */
9114 static int api_map_del_domain (vat_main_t * vam)
9116 unformat_input_t *i = vam->input;
9117 vl_api_map_del_domain_t *mp;
9123 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
9124 if (unformat (i, "index %d", &index))
9127 clib_warning ("parse error '%U'", format_unformat_error, i);
9132 if (num_m_args != 1) {
9133 errmsg("mandatory argument(s) missing\n");
9137 /* Construct the API message */
9138 M(MAP_DEL_DOMAIN, map_del_domain);
9140 mp->index = ntohl(index);
9145 /* Wait for a reply, return good/bad news */
9149 static int api_map_add_del_rule (vat_main_t * vam)
9151 unformat_input_t *i = vam->input;
9152 vl_api_map_add_del_rule_t *mp;
9155 ip6_address_t ip6_dst;
9156 u32 num_m_args = 0, index, psid;
9158 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
9159 if (unformat (i, "index %d", &index))
9161 else if (unformat (i, "psid %d", &psid))
9163 else if (unformat (i, "dst %U", unformat_ip6_address, &ip6_dst))
9165 else if (unformat (i, "del")) {
9168 clib_warning ("parse error '%U'", format_unformat_error, i);
9173 /* Construct the API message */
9174 M(MAP_ADD_DEL_RULE, map_add_del_rule);
9176 mp->index = ntohl(index);
9177 mp->is_add = is_add;
9178 clib_memcpy(mp->ip6_dst, &ip6_dst, sizeof(ip6_dst));
9179 mp->psid = ntohs(psid);
9184 /* Wait for a reply, return good/bad news */
9188 static int api_map_domain_dump (vat_main_t * vam)
9190 vl_api_map_domain_dump_t *mp;
9193 /* Construct the API message */
9194 M(MAP_DOMAIN_DUMP, map_domain_dump);
9199 /* Use a control ping for synchronization */
9201 vl_api_control_ping_t * mp;
9202 M(CONTROL_PING, control_ping);
9208 static int api_map_rule_dump (vat_main_t * vam)
9210 unformat_input_t *i = vam->input;
9211 vl_api_map_rule_dump_t *mp;
9213 u32 domain_index = ~0;
9215 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
9216 if (unformat (i, "index %u", &domain_index))
9222 if (domain_index == ~0) {
9223 clib_warning("parse error: domain index expected");
9227 /* Construct the API message */
9228 M(MAP_RULE_DUMP, map_rule_dump);
9230 mp->domain_index = htonl(domain_index);
9235 /* Use a control ping for synchronization */
9237 vl_api_control_ping_t * mp;
9238 M(CONTROL_PING, control_ping);
9244 static void vl_api_map_add_domain_reply_t_handler
9245 (vl_api_map_add_domain_reply_t * mp)
9247 vat_main_t * vam = &vat_main;
9248 i32 retval = ntohl(mp->retval);
9250 if (vam->async_mode) {
9251 vam->async_errors += (retval < 0);
9253 vam->retval = retval;
9254 vam->result_ready = 1;
9258 static void vl_api_map_add_domain_reply_t_handler_json
9259 (vl_api_map_add_domain_reply_t * mp)
9261 vat_main_t * vam = &vat_main;
9262 vat_json_node_t node;
9264 vat_json_init_object(&node);
9265 vat_json_object_add_int(&node, "retval", ntohl(mp->retval));
9266 vat_json_object_add_uint(&node, "index", ntohl(mp->index));
9268 vat_json_print(vam->ofp, &node);
9269 vat_json_free(&node);
9271 vam->retval = ntohl(mp->retval);
9272 vam->result_ready = 1;
9276 api_get_first_msg_id (vat_main_t * vam)
9278 vl_api_get_first_msg_id_t * mp;
9280 unformat_input_t * i = vam->input;
9284 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
9285 if (unformat (i, "client %s", &name))
9291 if (name_set == 0) {
9292 errmsg ("missing client name\n");
9297 if (vec_len (name) > 63) {
9298 errmsg ("client name too long\n");
9302 M(GET_FIRST_MSG_ID, get_first_msg_id);
9303 clib_memcpy (mp->name, name, vec_len(name));
9309 static int api_cop_interface_enable_disable (vat_main_t * vam)
9311 unformat_input_t * line_input = vam->input;
9312 vl_api_cop_interface_enable_disable_t * mp;
9314 u32 sw_if_index = ~0;
9315 u8 enable_disable = 1;
9317 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) {
9318 if (unformat (line_input, "disable"))
9320 if (unformat (line_input, "enable"))
9322 else if (unformat (line_input, "%U", unformat_sw_if_index,
9325 else if (unformat (line_input, "sw_if_index %d", &sw_if_index))
9331 if (sw_if_index == ~0) {
9332 errmsg ("missing interface name or sw_if_index\n");
9336 /* Construct the API message */
9337 M(COP_INTERFACE_ENABLE_DISABLE, cop_interface_enable_disable);
9338 mp->sw_if_index = ntohl(sw_if_index);
9339 mp->enable_disable = enable_disable;
9343 /* Wait for the reply */
9347 static int api_cop_whitelist_enable_disable (vat_main_t * vam)
9349 unformat_input_t * line_input = vam->input;
9350 vl_api_cop_whitelist_enable_disable_t * mp;
9352 u32 sw_if_index = ~0;
9353 u8 ip4=0, ip6=0, default_cop=0;
9356 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) {
9357 if (unformat (line_input, "ip4"))
9359 else if (unformat (line_input, "ip6"))
9361 else if (unformat (line_input, "default"))
9363 else if (unformat (line_input, "%U", unformat_sw_if_index,
9366 else if (unformat (line_input, "sw_if_index %d", &sw_if_index))
9368 else if (unformat (line_input, "fib-id %d", &fib_id))
9374 if (sw_if_index == ~0) {
9375 errmsg ("missing interface name or sw_if_index\n");
9379 /* Construct the API message */
9380 M(COP_WHITELIST_ENABLE_DISABLE, cop_whitelist_enable_disable);
9381 mp->sw_if_index = ntohl(sw_if_index);
9382 mp->fib_id = ntohl(fib_id);
9385 mp->default_cop = default_cop;
9389 /* Wait for the reply */
9393 static int api_get_node_graph (vat_main_t * vam)
9395 vl_api_get_node_graph_t * mp;
9398 M(GET_NODE_GRAPH, get_node_graph);
9402 /* Wait for the reply */
9407 api_lisp_add_del_locator_set(vat_main_t * vam)
9409 unformat_input_t * input = vam->input;
9410 vl_api_lisp_add_del_locator_set_t *mp;
9413 u8 *locator_set_name = NULL;
9414 u8 locator_set_name_set = 0;
9416 /* Parse args required to build the message */
9417 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) {
9418 if (unformat(input, "del")) {
9420 } else if (unformat(input, "locator-set %s", &locator_set_name)) {
9421 locator_set_name_set = 1;
9426 if (locator_set_name_set == 0) {
9427 errmsg ("missing locator-set name");
9431 if (vec_len(locator_set_name) > 64) {
9432 errmsg ("locator-set name too long\n");
9433 vec_free(locator_set_name);
9436 vec_add1(locator_set_name, 0);
9438 /* Construct the API message */
9439 M(LISP_ADD_DEL_LOCATOR_SET, lisp_add_del_locator_set);
9441 mp->is_add = is_add;
9442 clib_memcpy(mp->locator_set_name, locator_set_name,
9443 vec_len(locator_set_name));
9444 vec_free(locator_set_name);
9449 /* Wait for a reply... */
9457 api_lisp_add_del_locator(vat_main_t * vam)
9459 unformat_input_t * input = vam->input;
9460 vl_api_lisp_add_del_locator_t *mp;
9462 u32 tmp_if_index = ~0;
9463 u32 sw_if_index = ~0;
9464 u8 sw_if_index_set = 0;
9465 u8 sw_if_index_if_name_set = 0;
9467 u8 priority_set = 0;
9471 u8 *locator_set_name = NULL;
9472 u8 locator_set_name_set = 0;
9474 /* Parse args required to build the message */
9475 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) {
9476 if (unformat(input, "del")) {
9478 } else if (unformat(input, "locator-set %s", &locator_set_name)) {
9479 locator_set_name_set = 1;
9480 } else if (unformat(input, "iface %U", unformat_sw_if_index, vam,
9482 sw_if_index_if_name_set = 1;
9483 sw_if_index = tmp_if_index;
9484 } else if (unformat(input,"sw_if_index %d", &tmp_if_index)) {
9485 sw_if_index_set = 1;
9486 sw_if_index = tmp_if_index;
9487 } else if (unformat(input, "p %d", &priority)) {
9489 } else if (unformat(input, "w %d", &weight)) {
9495 if (locator_set_name_set == 0) {
9496 errmsg ("missing locator-set name");
9500 if (sw_if_index_set == 0 && sw_if_index_if_name_set == 0) {
9501 errmsg ("missing sw_if_index");
9502 vec_free(locator_set_name);
9506 if (sw_if_index_set != 0 && sw_if_index_if_name_set != 0) {
9507 errmsg ("cannot use both params interface name and sw_if_index");
9508 vec_free(locator_set_name);
9512 if (priority_set == 0) {
9513 errmsg ("missing locator-set priority\n");
9514 vec_free(locator_set_name);
9518 if (weight_set == 0) {
9519 errmsg ("missing locator-set weight\n");
9520 vec_free(locator_set_name);
9524 if (vec_len(locator_set_name) > 64) {
9525 errmsg ("locator-set name too long\n");
9526 vec_free(locator_set_name);
9529 vec_add1(locator_set_name, 0);
9531 /* Construct the API message */
9532 M(LISP_ADD_DEL_LOCATOR, lisp_add_del_locator);
9534 mp->is_add = is_add;
9535 mp->sw_if_index = ntohl(sw_if_index);
9536 mp->priority = priority;
9537 mp->weight = weight;
9538 clib_memcpy(mp->locator_set_name, locator_set_name,
9539 vec_len(locator_set_name));
9540 vec_free(locator_set_name);
9545 /* Wait for a reply... */
9553 api_lisp_add_del_local_eid(vat_main_t * vam)
9555 unformat_input_t * input = vam->input;
9556 vl_api_lisp_add_del_local_eid_t *mp;
9561 ip4_address_t eidv4;
9562 ip6_address_t eidv6;
9563 u8 tmp_eid_lenght = ~0;
9565 u8 *locator_set_name = NULL;
9566 u8 locator_set_name_set = 0;
9568 /* Parse args required to build the message */
9569 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) {
9570 if (unformat(input, "del")) {
9572 } else if (unformat(input, "eid %U/%d", unformat_ip4_address,
9573 &eidv4, &tmp_eid_lenght)) {
9574 eid_lenght = tmp_eid_lenght;
9576 } else if (unformat(input, "eid %U/%d", unformat_ip6_address,
9577 &eidv6, &tmp_eid_lenght)) {
9578 eid_lenght = tmp_eid_lenght;
9580 } else if (unformat(input, "locator-set %s", &locator_set_name)) {
9581 locator_set_name_set = 1;
9586 if (locator_set_name_set == 0) {
9587 errmsg ("missing locator-set name\n");
9591 if (vec_len(locator_set_name) > 64) {
9592 errmsg ("locator-set name too long\n");
9593 vec_free(locator_set_name);
9596 vec_add1(locator_set_name, 0);
9598 if (eidv4_set && eidv6_set) {
9599 errmsg ("both eid v4 and v6 addresses set\n");
9600 vec_free(locator_set_name);
9604 if (!eidv4_set && !eidv6_set) {
9605 errmsg ("eid addresses not set\n");
9606 vec_free(locator_set_name);
9610 /* Construct the API message */
9611 M(LISP_ADD_DEL_LOCAL_EID, lisp_add_del_local_eid);
9613 mp->is_add = is_add;
9616 clib_memcpy(mp->ip_address, &eidv6, sizeof(eidv6));
9619 clib_memcpy(mp->ip_address, &eidv4, sizeof(eidv4));
9621 mp->prefix_len = eid_lenght;
9622 clib_memcpy(mp->locator_set_name, locator_set_name,
9623 vec_len(locator_set_name));
9624 vec_free(locator_set_name);
9629 /* Wait for a reply... */
9637 api_lisp_gpe_add_del_fwd_entry(vat_main_t * vam)
9639 unformat_input_t * input = vam->input;
9640 vl_api_lisp_gpe_add_del_fwd_entry_t *mp;
9643 u8 eidv4_set = 0, slocv4_set = 0, dlocv4_set = 0;
9644 u8 eidv6_set = 0, slocv6_set = 0, dlocv6_set = 0;
9645 ip4_address_t eidv4, slocv4, dlocv4;
9646 ip6_address_t eidv6, slocv6, dlocv6;
9647 u8 tmp_eid_lenght = ~0;
9650 /* Parse args required to build the message */
9651 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) {
9652 if (unformat(input, "del")) {
9654 } else if (unformat(input, "eid %U/%d", unformat_ip4_address,
9655 &eidv4, &tmp_eid_lenght)) {
9656 eid_lenght = tmp_eid_lenght;
9658 } else if (unformat(input, "eid %U/%d", unformat_ip6_address,
9659 &eidv6, &tmp_eid_lenght)) {
9660 eid_lenght = tmp_eid_lenght;
9662 } else if (unformat(input, "sloc %U", unformat_ip4_address, &slocv4)) {
9664 } else if (unformat(input, "sloc %U", unformat_ip6_address, &slocv6)) {
9666 } else if (unformat(input, "dloc %U", unformat_ip4_address, &dlocv4)) {
9668 } else if (unformat(input, "dloc %U", unformat_ip6_address, &dlocv6)) {
9674 if (eidv4_set && eidv6_set) {
9675 errmsg ("both eid v4 and v6 addresses set\n");
9679 if (!eidv4_set && !eidv6_set) {
9680 errmsg ("eid addresses not set\n");
9684 if (slocv4_set && slocv6_set) {
9685 errmsg ("both source v4 and v6 addresses set\n");
9689 if (!slocv4_set && !slocv6_set) {
9690 errmsg ("source addresses not set\n");
9694 if (dlocv4_set && dlocv6_set) {
9695 errmsg ("both destination v4 and v6 addresses set\n");
9699 if (dlocv4_set && dlocv6_set) {
9700 errmsg ("destination addresses not set\n");
9704 if (!(slocv4_set == dlocv4_set && slocv6_set == dlocv6_set)) {
9705 errmsg ("mixing type of source and destination address\n");
9709 /* Construct the API message */
9710 M(LISP_GPE_ADD_DEL_FWD_ENTRY, lisp_gpe_add_del_fwd_entry);
9712 mp->is_add = is_add;
9714 mp->eid_is_ipv6 = 1;
9715 clib_memcpy(mp->eid_ip_address, &eidv6, sizeof(eidv6));
9717 mp->eid_is_ipv6 = 0;
9718 clib_memcpy(mp->eid_ip_address, &eidv4, sizeof(eidv4));
9720 mp->eid_prefix_len = eid_lenght;
9722 mp->address_is_ipv6 = 1;
9723 clib_memcpy(mp->source_ip_address, &slocv6, sizeof(slocv6));
9724 clib_memcpy(mp->destination_ip_address, &dlocv6, sizeof(dlocv6));
9726 mp->address_is_ipv6 = 0;
9727 clib_memcpy(mp->source_ip_address, &slocv4, sizeof(slocv4));
9728 clib_memcpy(mp->destination_ip_address, &dlocv4, sizeof(dlocv4));
9734 /* Wait for a reply... */
9742 api_lisp_add_del_map_resolver(vat_main_t * vam)
9744 unformat_input_t * input = vam->input;
9745 vl_api_lisp_add_del_map_resolver_t *mp;
9753 /* Parse args required to build the message */
9754 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) {
9755 if (unformat(input, "del")) {
9757 } else if (unformat(input, "%U", unformat_ip4_address, &ipv4)) {
9759 } else if (unformat(input, "%U", unformat_ip6_address, &ipv6)) {
9765 if (ipv4_set && ipv6_set) {
9766 errmsg ("both eid v4 and v6 addresses set\n");
9770 if (!ipv4_set && !ipv6_set) {
9771 errmsg ("eid addresses not set\n");
9775 /* Construct the API message */
9776 M(LISP_ADD_DEL_MAP_RESOLVER, lisp_add_del_map_resolver);
9778 mp->is_add = is_add;
9781 clib_memcpy(mp->ip_address, &ipv6, sizeof(ipv6));
9784 clib_memcpy(mp->ip_address, &ipv4, sizeof(ipv4));
9790 /* Wait for a reply... */
9798 api_lisp_gpe_enable_disable (vat_main_t * vam)
9800 unformat_input_t * input = vam->input;
9801 vl_api_lisp_gpe_enable_disable_t *mp;
9806 /* Parse args required to build the message */
9807 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) {
9808 if (unformat(input, "enable")) {
9811 } else if (unformat(input, "disable")) {
9819 errmsg("Value not set\n");
9823 /* Construct the API message */
9824 M(LISP_GPE_ENABLE_DISABLE, lisp_gpe_enable_disable);
9831 /* Wait for a reply... */
9839 api_lisp_gpe_add_del_iface(vat_main_t * vam)
9841 unformat_input_t * input = vam->input;
9842 vl_api_lisp_gpe_add_del_iface_t *mp;
9848 /* Parse args required to build the message */
9849 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) {
9850 if (unformat(input, "up")) {
9853 } else if (unformat(input, "down")) {
9856 } else if (unformat(input, "table_id %d", &table_id)) {
9858 } else if (unformat(input, "vni %d", &vni)) {
9865 errmsg("Value not set\n");
9869 /* Construct the API message */
9870 M(LISP_GPE_ADD_DEL_IFACE, lisp_gpe_add_del_iface);
9872 mp->is_add = is_add;
9873 mp->table_id = table_id;
9879 /* Wait for a reply... */
9887 api_lisp_locator_set_dump(vat_main_t *vam)
9889 vl_api_lisp_locator_set_dump_t *mp;
9892 if (!vam->json_output) {
9893 fformat(vam->ofp, "%=20s%=16s%=16s%=16s\n",
9894 "Locator-set", "Locator", "Priority", "Weight");
9897 M(LISP_LOCATOR_SET_DUMP, lisp_locator_set_dump);
9901 /* Use a control ping for synchronization */
9903 vl_api_control_ping_t * mp;
9904 M(CONTROL_PING, control_ping);
9907 /* Wait for a reply... */
9915 api_lisp_local_eid_table_dump(vat_main_t *vam)
9917 vl_api_lisp_local_eid_table_dump_t *mp;
9920 if (!vam->json_output) {
9921 fformat(vam->ofp, "%=20s%=30s\n",
9922 "Locator-set", "Eid");
9925 M(LISP_LOCAL_EID_TABLE_DUMP, lisp_local_eid_table_dump);
9929 /* Use a control ping for synchronization */
9931 vl_api_control_ping_t * mp;
9932 M(CONTROL_PING, control_ping);
9935 /* Wait for a reply... */
9943 api_lisp_gpe_tunnel_dump(vat_main_t *vam)
9945 vl_api_lisp_gpe_tunnel_dump_t *mp;
9948 if (!vam->json_output) {
9949 fformat(vam->ofp, "%=20s%=30s%=16s%=16s%=16s%=16s"
9950 "%=16s%=16s%=16s%=16s%=16s\n",
9951 "Tunel", "Source", "Destination", "Fib encap", "Fib decap",
9952 "Decap next", "Lisp version", "Flags", "Next protocol",
9953 "ver_res", "res", "iid");
9956 M(LISP_GPE_TUNNEL_DUMP, lisp_gpe_tunnel_dump);
9960 /* Use a control ping for synchronization */
9962 vl_api_control_ping_t * mp;
9963 M(CONTROL_PING, control_ping);
9966 /* Wait for a reply... */
9974 api_lisp_map_resolver_dump(vat_main_t *vam)
9976 vl_api_lisp_map_resolver_dump_t *mp;
9979 if (!vam->json_output) {
9980 fformat(vam->ofp, "%=20s\n",
9984 M(LISP_MAP_RESOLVER_DUMP, lisp_map_resolver_dump);
9988 /* Use a control ping for synchronization */
9990 vl_api_control_ping_t * mp;
9991 M(CONTROL_PING, control_ping);
9994 /* Wait for a reply... */
10001 static int q_or_quit (vat_main_t * vam)
10003 longjmp (vam->jump_buf, 1);
10004 return 0; /* not so much */
10006 static int q (vat_main_t * vam) {return q_or_quit (vam);}
10007 static int quit (vat_main_t * vam) {return q_or_quit (vam);}
10009 static int comment (vat_main_t * vam)
10014 static int cmd_cmp (void * a1, void * a2)
10019 return strcmp ((char *)(c1[0]), (char *)(c2[0]));
10022 static int help (vat_main_t * vam)
10027 unformat_input_t * i = vam->input;
10030 if (unformat (i, "%s", &name)) {
10035 hs = hash_get_mem (vam->help_by_name, name);
10037 fformat (vam->ofp, "usage: %s %s\n", name, hs[0]);
10039 fformat (vam->ofp, "No such msg / command '%s'\n", name);
10044 fformat(vam->ofp, "Help is available for the following:\n");
10046 hash_foreach_pair (p, vam->function_by_name,
10048 vec_add1 (cmds, (u8 *)(p->key));
10051 vec_sort_with_function (cmds, cmd_cmp);
10053 for (j = 0; j < vec_len(cmds); j++)
10054 fformat (vam->ofp, "%s\n", cmds[j]);
10060 static int set (vat_main_t * vam)
10062 u8 * name = 0, * value = 0;
10063 unformat_input_t * i = vam->input;
10065 if (unformat (i, "%s", &name)) {
10066 /* The input buffer is a vector, not a string. */
10067 value = vec_dup (i->buffer);
10068 vec_delete (value, i->index, 0);
10069 /* Almost certainly has a trailing newline */
10070 if (value[vec_len(value)-1] == '\n')
10071 value[vec_len(value)-1] = 0;
10072 /* Make sure it's a proper string, one way or the other */
10073 vec_add1 (value, 0);
10074 (void) clib_macro_set_value (&vam->macro_main,
10075 (char *)name, (char *)value);
10078 errmsg ("usage: set <name> <value>\n");
10085 static int unset (vat_main_t * vam)
10089 if (unformat (vam->input, "%s", &name))
10090 if (clib_macro_unset (&vam->macro_main, (char *)name) == 1)
10091 errmsg ("unset: %s wasn't set\n", name);
10102 static int macro_sort_cmp (void * a1, void * a2)
10104 macro_sort_t * s1 = a1;
10105 macro_sort_t * s2 = a2;
10107 return strcmp ((char *)(s1->name), (char *)(s2->name));
10110 static int dump_macro_table (vat_main_t * vam)
10112 macro_sort_t * sort_me = 0, * sm;
10116 hash_foreach_pair (p, vam->macro_main.the_value_table_hash,
10118 vec_add2 (sort_me, sm, 1);
10119 sm->name = (u8 *)(p->key);
10120 sm->value = (u8 *) (p->value[0]);
10123 vec_sort_with_function (sort_me, macro_sort_cmp);
10125 if (vec_len(sort_me))
10126 fformat (vam->ofp, "%-15s%s\n", "Name", "Value");
10128 fformat (vam->ofp, "The macro table is empty...\n");
10130 for (i = 0; i < vec_len (sort_me); i++)
10131 fformat (vam->ofp, "%-15s%s\n", sort_me[i].name,
10136 static int dump_node_table (vat_main_t * vam)
10139 vlib_node_t * node, * next_node;
10141 if (vec_len (vam->graph_nodes) == 0) {
10142 fformat (vam->ofp, "Node table empty, issue get_node_graph...\n");
10146 for (i = 0; i < vec_len (vam->graph_nodes); i++) {
10147 node = vam->graph_nodes[i];
10148 fformat (vam->ofp, "[%d] %s\n", i, node->name);
10149 for (j = 0; j < vec_len (node->next_nodes); j++) {
10150 if (node->next_nodes[j] != ~0) {
10151 next_node = vam->graph_nodes[node->next_nodes[j]];
10152 fformat (vam->ofp, " [%d] %s\n", j, next_node->name);
10159 static int search_node_table (vat_main_t * vam)
10161 unformat_input_t * line_input = vam->input;
10164 vlib_node_t * node, * next_node;
10167 if (vam->graph_node_index_by_name == 0) {
10168 fformat (vam->ofp, "Node table empty, issue get_node_graph...\n");
10172 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) {
10173 if (unformat (line_input, "%s", &node_to_find)) {
10174 vec_add1 (node_to_find, 0);
10175 p = hash_get_mem (vam->graph_node_index_by_name, node_to_find);
10177 fformat (vam->ofp, "%s not found...\n", node_to_find);
10180 node = vam->graph_nodes[p[0]];
10181 fformat (vam->ofp, "[%d] %s\n", p[0], node->name);
10182 for (j = 0; j < vec_len (node->next_nodes); j++) {
10183 if (node->next_nodes[j] != ~0) {
10184 next_node = vam->graph_nodes[node->next_nodes[j]];
10185 fformat (vam->ofp, " [%d] %s\n", j, next_node->name);
10191 clib_warning ("parse error '%U'", format_unformat_error,
10197 vec_free(node_to_find);
10205 static int script (vat_main_t * vam)
10208 char * save_current_file;
10209 unformat_input_t save_input;
10210 jmp_buf save_jump_buf;
10211 u32 save_line_number;
10213 FILE * new_fp, * save_ifp;
10215 if (unformat (vam->input, "%s", &s)) {
10216 new_fp = fopen ((char *)s, "r");
10218 errmsg ("Couldn't open script file %s\n", s);
10223 errmsg ("Missing script name\n");
10227 clib_memcpy (&save_input, &vam->input, sizeof (save_input));
10228 clib_memcpy (&save_jump_buf, &vam->jump_buf, sizeof (save_jump_buf));
10229 save_ifp = vam->ifp;
10230 save_line_number = vam->input_line_number;
10231 save_current_file = (char *) vam->current_file;
10233 vam->input_line_number = 0;
10235 vam->current_file = s;
10238 clib_memcpy (&vam->input, &save_input, sizeof (vam->input));
10239 clib_memcpy (&vam->jump_buf, &save_jump_buf, sizeof (save_jump_buf));
10240 vam->ifp = save_ifp;
10241 vam->input_line_number = save_line_number;
10242 vam->current_file = (u8 *) save_current_file;
10248 static int echo (vat_main_t * vam)
10250 fformat (vam->ofp, "%v", vam->input->buffer);
10254 /* List of API message constructors, CLI names map to api_xxx */
10255 #define foreach_vpe_api_msg \
10256 _(create_loopback,"[mac <mac-addr>]") \
10257 _(sw_interface_dump,"") \
10258 _(sw_interface_set_flags, \
10259 "<intfc> | sw_if_index <id> admin-up | admin-down link-up | link down") \
10260 _(sw_interface_add_del_address, \
10261 "<intfc> | sw_if_index <id> <ip4-address> | <ip6-address> [del] [del-all] ") \
10262 _(sw_interface_set_table, \
10263 "<intfc> | sw_if_index <id> vrf <table-id> [ipv6]") \
10264 _(sw_interface_set_vpath, \
10265 "<intfc> | sw_if_index <id> enable | disable") \
10266 _(sw_interface_set_l2_xconnect, \
10267 "rx <intfc> | rx_sw_if_index <id> tx <intfc> | tx_sw_if_index <id>\n" \
10268 "enable | disable") \
10269 _(sw_interface_set_l2_bridge, \
10270 "rx <intfc> | rx_sw_if_index <id> bd_id <bridge-domain-id>\n" \
10271 "[shg <split-horizon-group>] [bvi]\n" \
10272 "enable | disable") \
10273 _(bridge_domain_add_del, \
10274 "bd_id <bridge-domain-id> [flood 1|0] [uu-flood 1|0] [forward 1|0] [learn 1|0] [arp-term 1|0] [del]\n")\
10275 _(bridge_domain_dump, "[bd_id <bridge-domain-id>]\n") \
10277 "mac <mac-addr> bd_id <bridge-domain-id> [del] | sw_if <intfc> | sw_if_index <id> [static] [filter] [bvi]\n") \
10279 "sw_if <intfc> | sw_if_index <id> [learn] [forward] [uu-flood] [flood]\n") \
10281 "bd_id <bridge-domain-id> [learn] [forward] [uu-flood] [flood] [arp-term] [disable]\n") \
10283 "tapname <name> mac <mac-addr> | random-mac") \
10285 "<vpp-if-name> | sw_if_index <id> tapname <name> mac <mac-addr> | random-mac") \
10287 "<vpp-if-name> | sw_if_index <id>") \
10288 _(sw_interface_tap_dump, "") \
10289 _(ip_add_del_route, \
10290 "<addr>/<mask> via <addr> [vrf <n>]\n" \
10291 "[<intfc> | sw_if_index <id>] [resolve-attempts <n>]\n" \
10292 "[weight <n>] [drop] [local] [classify <n>] [del]\n" \
10293 "[multipath] [count <n>]") \
10294 _(proxy_arp_add_del, \
10295 "<lo-ip4-addr> - <hi-ip4-addr> [vrf <n>] [del]") \
10296 _(proxy_arp_intfc_enable_disable, \
10297 "<intfc> | sw_if_index <id> enable | disable") \
10298 _(mpls_add_del_encap, \
10299 "label <n> dst <ip4-addr> [vrf <n>] [del]") \
10300 _(mpls_add_del_decap, \
10301 "label <n> [rx_vrf_id <n>] [tx_vrf_id] [s-bit-clear][del]") \
10302 _(mpls_gre_add_del_tunnel, \
10303 "inner_vrf_id <n> outer_vrf_id <n> src <ip4-address> dst <ip4-address>\n" \
10304 "adj <ip4-address>/<mask-width> [del]") \
10305 _(sw_interface_set_unnumbered, \
10306 "<intfc> | sw_if_index <id> unnum_if_index <id> [del]") \
10307 _(ip_neighbor_add_del, \
10308 "<intfc> | sw_if_index <id> dst <ip46-address> mac <mac-addr>") \
10309 _(reset_vrf, "vrf <id> [ipv6]") \
10310 _(create_vlan_subif, "<intfc> | sw_if_index <id> vlan <n>") \
10311 _(create_subif, "<intfc> | sw_if_index <id> sub_id <n>\n" \
10312 "[outer_vlan_id <n>][inner_vlan_id <n>]\n" \
10313 "[no_tags][one_tag][two_tags][dot1ad][exact_match][default_sub]\n" \
10314 "[outer_vlan_id_any][inner_vlan_id_any]") \
10315 _(oam_add_del, "src <ip4-address> dst <ip4-address> [vrf <n>] [del]") \
10316 _(reset_fib, "vrf <n> [ipv6]") \
10317 _(dhcp_proxy_config, \
10318 "svr <v46-address> src <v46-address>\n" \
10319 "insert-cid <n> [del]") \
10320 _(dhcp_proxy_config_2, \
10321 "svr <v46-address> src <v46-address>\n" \
10322 "rx_vrf_id <nn> server_vrf_id <nn> insert-cid <n> [del]") \
10323 _(dhcp_proxy_set_vss, \
10324 "tbl_id <n> fib_id <n> oui <n> [ipv6] [del]") \
10325 _(dhcp_client_config, \
10326 "<intfc> | sw_if_index <id> [hostname <name>] [disable_event] [del]") \
10327 _(set_ip_flow_hash, \
10328 "vrf <n> [src] [dst] [sport] [dport] [proto] [reverse] [ipv6]") \
10329 _(sw_interface_ip6_enable_disable, \
10330 "<intfc> | sw_if_index <id> enable | disable") \
10331 _(sw_interface_ip6_set_link_local_address, \
10332 "<intfc> | sw_if_index <id> <ip6-address>/<mask-width>") \
10333 _(sw_interface_ip6nd_ra_prefix, \
10334 "<intfc> | sw_if_index <id> <ip6-address>/<mask-width>\n" \
10335 "val_life <n> pref_life <n> [def] [noadv] [offl] [noauto]\n" \
10336 "[nolink] [isno]") \
10337 _(sw_interface_ip6nd_ra_config, \
10338 "<intfc> | sw_if_index <id> [maxint <n>] [minint <n>]\n" \
10339 "[life <n>] [count <n>] [interval <n>] [surpress]\n" \
10340 "[managed] [other] [ll] [send] [cease] [isno] [def]") \
10341 _(set_arp_neighbor_limit, "arp_nbr_limit <n> [ipv6]") \
10342 _(l2_patch_add_del, \
10343 "rx <intfc> | rx_sw_if_index <id> tx <intfc> | tx_sw_if_index <id>\n" \
10344 "enable | disable") \
10345 _(mpls_ethernet_add_del_tunnel, \
10346 "tx <intfc> | tx_sw_if_index <n> dst <mac-addr>\n" \
10347 "adj <ip4-addr>/<mw> dst <mac-addr> [del]") \
10348 _(mpls_ethernet_add_del_tunnel_2, \
10349 "inner_vrf_id <n> outer_vrf_id <n> next-hop <ip4-addr>\n" \
10350 "resolve-attempts <n> resolve-if-needed 0 | 1 [del]") \
10351 _(sr_tunnel_add_del, \
10352 "src <ip6-addr> dst <ip6-addr>/<mw> (next <ip6-addr>)+\n" \
10353 " [tag <ip6-addr>]* [clean] [reroute]") \
10354 _(classify_add_del_table, \
10355 "buckets <nn> [skip <n>] [match <n>] [memory_size <nn-bytes>]\n" \
10356 "[del] mask <mask-value>\n" \
10357 " [l2-miss-next | miss-next | acl-miss-next] <name|nn>") \
10358 _(classify_add_del_session, \
10359 "[hit-next|l2-hit-next|acl-hit-next] <name|nn> table-index <nn>\n" \
10360 "skip_n <nn> match_n <nn> match [hex] [l2] [l3 [ip4|ip6]]") \
10361 _(classify_set_interface_ip_table, \
10362 "<intfc> | sw_if_index <nn> table <nn>") \
10363 _(classify_set_interface_l2_tables, \
10364 "<intfc> | sw_if_index <nn> [ip4-table <nn>] [ip6-table <nn>]\n" \
10365 " [other-table <nn>]") \
10366 _(get_node_index, "node <node-name") \
10367 _(add_node_next, "node <node-name> next <next-node-name>") \
10368 _(l2tpv3_create_tunnel, \
10369 "client_address <ip6-addr> our_address <ip6-addr>\n" \
10370 "[local_session_id <nn>][remote_session_id <nn>][local_cookie <nn>]\n"\
10371 "[remote_cookie <nn>]\n[l2-sublayer-preset]\n") \
10372 _(l2tpv3_set_tunnel_cookies, \
10373 "<intfc> | sw_if_index <nn> [new_local_cookie <nn>]\n" \
10374 "[new_remote_cookie <nn>]\n") \
10375 _(l2tpv3_interface_enable_disable, \
10376 "<intfc> | sw_if_index <nn> enable | disable") \
10377 _(l2tpv3_set_lookup_key, \
10378 "lookup_v6_src | lookup_v6_dst | lookup_session_id") \
10379 _(sw_if_l2tpv3_tunnel_dump, "") \
10380 _(vxlan_add_del_tunnel, \
10381 "src <ip4-addr> dst <ip4-addr> vni [encap-vrf-id <nn>]\n" \
10382 " [decap-next l2|ip4|ip6] [del]") \
10383 _(vxlan_tunnel_dump, "[<intfc> | sw_if_index <nn>]") \
10384 _(l2_fib_clear_table, "") \
10385 _(l2_interface_efp_filter, "sw_if_index <nn> enable | disable") \
10386 _(l2_interface_vlan_tag_rewrite, \
10387 "<intfc> | sw_if_index <nn> \n" \
10388 "[disable][push-[1|2]][pop-[1|2]][translate-1-[1|2]] \n" \
10389 "[translate-2-[1|2]] [push_dot1q 0] tag1 <nn> tag2 <nn>") \
10390 _(create_vhost_user_if, \
10391 "socket <filename> [server] [renumber <dev_instance>] " \
10392 "[mac <mac_address>]") \
10393 _(modify_vhost_user_if, \
10394 "<intfc> | sw_if_index <nn> socket <filename>\n" \
10395 "[server] [renumber <dev_instance>]") \
10396 _(delete_vhost_user_if, "<intfc> | sw_if_index <nn>") \
10397 _(sw_interface_vhost_user_dump, "") \
10398 _(show_version, "") \
10399 _(nsh_gre_add_del_tunnel, \
10400 "src <ip4-addr> dst <ip4-addr>" \
10401 "c1 <nn> c2 <nn> c3 <nn> c4 <nn> spi <nn> si <nn>\n" \
10402 "[encap-fib-id <nn>] [decap-fib-id <nn>] [o-bit <1|0>]\n" \
10403 "[c-bit <1|0>] [md-type <nn>][next-ip4][next-ip6][next-ethernet]\n" \
10404 "[tlv <xx>][del]") \
10405 _(nsh_vxlan_gpe_add_del_tunnel, \
10406 "src <ip4-addr> dst <ip4-addr> vni <nn>\n" \
10407 "c1 <nn> c2 <nn> c3 <nn> c4 <nn> spi <nn> si <nn>\n" \
10408 "[encap-vrf-id <nn>] [decap-vrf-id <nn>] [o-bit <1|0>]\n" \
10409 "[c-bit <1|0>] [md-type <nn>][next-ip4][next-ip6][next-ethernet]\n" \
10410 "[tlv <xx>][del]") \
10411 _(l2_fib_table_dump, "bd_id <bridge-domain-id>") \
10412 _(lisp_gpe_add_del_tunnel, \
10413 "src <ip4-addr> dst <ip4-addr> iid <nn>|iidx <0xnn>\n" \
10414 "[encap-vrf-id <nn>] [decap-vrf-id <nn>]\n" \
10415 "[n-bit][l-bit][e-bit][v-bit][i-bit][p-bit][not-p-bit][o-bit]\n" \
10416 "[next-ip4][next-ip6][next-ethernet][next-nsh]\n" \
10417 "[decap-next [ip4|ip6|ethernet|nsh-encap|<nn>]][del]") \
10418 _(interface_name_renumber, \
10419 "<intfc> | sw_if_index <nn> new_show_dev_instance <nn>") \
10420 _(input_acl_set_interface, \
10421 "<intfc> | sw_if_index <nn> [ip4-table <nn>] [ip6-table <nn>]\n" \
10422 " [l2-table <nn>] [del]") \
10423 _(want_ip4_arp_events, "address <ip4-address> [del]") \
10424 _(ip_address_dump, "(ipv4 | ipv6) (<intfc> | sw_if_index <id>)") \
10425 _(ip_dump, "ipv4 | ipv6") \
10426 _(ipsec_spd_add_del, "spd_id <n> [del]") \
10427 _(ipsec_interface_add_del_spd, "(<intfc> | sw_if_index <id>)\n" \
10429 _(ipsec_sad_add_del_entry, "sad_id <n> spi <n> crypto_alg <alg>\n" \
10430 " crypto_key <hex> tunnel_src <ip4|ip6> tunnel_dst <ip4|ip6>\n" \
10431 " integ_alg <alg> integ_key <hex>") \
10432 _(ipsec_spd_add_del_entry, "spd_id <n> priority <n> action <action>\n" \
10433 " (inbound|outbound) [sa_id <n>] laddr_start <ip4|ip6>\n" \
10434 " laddr_stop <ip4|ip6> raddr_start <ip4|ip6> raddr_stop <ip4|ip6>\n" \
10435 " [lport_start <n> lport_stop <n>] [rport_start <n> rport_stop <n>]" )\
10436 _(ipsec_sa_set_key, "sa_id <n> crypto_key <hex> integ_key <hex>") \
10437 _(ikev2_profile_add_del, "name <profile_name> [del]") \
10438 _(ikev2_profile_set_auth, "name <profile_name> auth_method <method>\n" \
10439 "(auth_data 0x<data> | auth_data <data>)") \
10440 _(ikev2_profile_set_id, "name <profile_name> id_type <type>\n" \
10441 "(id_data 0x<data> | id_data <data>) (local|remote)") \
10442 _(ikev2_profile_set_ts, "name <profile_name> protocol <proto>\n" \
10443 "start_port <port> end_port <port> start_addr <ip4> end_addr <ip4>\n" \
10444 "(local|remote)") \
10445 _(ikev2_set_local_key, "file <absolute_file_path>") \
10446 _(delete_loopback,"sw_if_index <nn>") \
10447 _(bd_ip_mac_add_del, "bd_id <bridge-domain-id> <ip4/6-addr> <mac-addr> [del]") \
10448 _(map_add_domain, \
10449 "ip4-pfx <ip4pfx> ip6-pfx <ip6pfx> " \
10450 "ip6-src <ip6addr> " \
10451 "ea-bits-len <n> psid-offset <n> psid-len <n>") \
10452 _(map_del_domain, "index <n>") \
10453 _(map_add_del_rule, \
10454 "index <n> psid <n> dst <ip6addr> [del]") \
10455 _(map_domain_dump, "") \
10456 _(map_rule_dump, "index <map-domain>") \
10457 _(want_interface_events, "enable|disable") \
10458 _(want_stats,"enable|disable") \
10459 _(get_first_msg_id, "client <name>") \
10460 _(cop_interface_enable_disable, "<intfc> | sw_if_index <nn> [disable]") \
10461 _(cop_whitelist_enable_disable, "<intfc> | sw_if_index <nn>\n" \
10462 "fib-id <nn> [ip4][ip6][default]") \
10463 _(get_node_graph, " ") \
10464 _(sw_interface_clear_stats,"<intfc> | sw_if_index <nn>") \
10465 _(trace_profile_add, "id <nn> trace-type <0x1f|0x3|0x9|0x11|0x19> " \
10466 "trace-elts <nn> trace-tsp <0|1|2|3> node-id <node id in hex> " \
10467 "app-data <app_data in hex> [pow] [ppc <encap|decap>]") \
10468 _(trace_profile_apply, "id <nn> <ip6-address>/<width>" \
10469 " vrf_id <nn> add | pop | none") \
10470 _(trace_profile_del, "") \
10471 _(lisp_add_del_locator_set, "locator-set <locator_name> [del]") \
10472 _(lisp_add_del_locator, "locator-set <locator_name> " \
10473 "iface <intf> | sw_if_index <sw_if_index> " \
10474 "p <priority> w <weight> [del]") \
10475 _(lisp_add_del_local_eid, "<ipv4|ipv6>/<prefix> " \
10476 "locator-set <locator_name> [del]") \
10477 _(lisp_gpe_add_del_fwd_entry, "eid <ip4|6-addr>/<prefix> " \
10478 "sloc <ip4/6-addr> dloc <ip4|6-addr> [del]") \
10479 _(lisp_add_del_map_resolver, "<ip4|6-addr> [del]") \
10480 _(lisp_gpe_enable_disable, "enable|disable") \
10481 _(lisp_gpe_add_del_iface, "up|down") \
10482 _(lisp_locator_set_dump, "") \
10483 _(lisp_local_eid_table_dump, "") \
10484 _(lisp_gpe_tunnel_dump, "") \
10485 _(lisp_map_resolver_dump, "")
10487 /* List of command functions, CLI names map directly to functions */
10488 #define foreach_cli_function \
10489 _(comment, "usage: comment <ignore-rest-of-line>") \
10490 _(dump_interface_table, "usage: dump_interface_table") \
10491 _(dump_sub_interface_table, "usage: dump_sub_interface_table") \
10492 _(dump_ipv4_table, "usage: dump_ipv4_table") \
10493 _(dump_ipv6_table, "usage: dump_ipv6_table") \
10494 _(dump_stats_table, "usage: dump_stats_table") \
10495 _(dump_macro_table, "usage: dump_macro_table ") \
10496 _(dump_node_table, "usage: dump_node_table") \
10497 _(echo, "usage: echo <message>") \
10498 _(exec, "usage: exec <vpe-debug-CLI-command>") \
10499 _(help, "usage: help") \
10500 _(q, "usage: quit") \
10501 _(quit, "usage: quit") \
10502 _(search_node_table, "usage: search_node_table <name>...") \
10503 _(set, "usage: set <variable-name> <value>") \
10504 _(script, "usage: script <file-name>") \
10505 _(unset, "usage: unset <variable-name>")
10508 static void vl_api_##n##_t_handler_uni \
10509 (vl_api_##n##_t * mp) \
10511 vat_main_t * vam = &vat_main; \
10512 if (vam->json_output) { \
10513 vl_api_##n##_t_handler_json(mp); \
10515 vl_api_##n##_t_handler(mp); \
10518 foreach_vpe_api_reply_msg;
10521 void vat_api_hookup (vat_main_t *vam)
10524 vl_msg_api_set_handlers(VL_API_##N, #n, \
10525 vl_api_##n##_t_handler_uni, \
10527 vl_api_##n##_t_endian, \
10528 vl_api_##n##_t_print, \
10529 sizeof(vl_api_##n##_t), 1);
10530 foreach_vpe_api_reply_msg;
10533 vl_msg_api_set_first_available_msg_id (VL_MSG_FIRST_AVAILABLE);
10535 vam->sw_if_index_by_interface_name =
10536 hash_create_string (0, sizeof (uword));
10538 vam->function_by_name =
10539 hash_create_string (0, sizeof(uword));
10541 vam->help_by_name =
10542 hash_create_string (0, sizeof(uword));
10544 /* API messages we can send */
10545 #define _(n,h) hash_set_mem (vam->function_by_name, #n, api_##n);
10546 foreach_vpe_api_msg;
10550 #define _(n,h) hash_set_mem (vam->help_by_name, #n, h);
10551 foreach_vpe_api_msg;
10554 /* CLI functions */
10555 #define _(n,h) hash_set_mem (vam->function_by_name, #n, n);
10556 foreach_cli_function;
10560 #define _(n,h) hash_set_mem (vam->help_by_name, #n, h);
10561 foreach_cli_function;
10565 #undef vl_api_version
10566 #define vl_api_version(n,v) static u32 vpe_api_version = v;
10567 #include <api/vpe.api.h>
10568 #undef vl_api_version
10570 void vl_client_add_api_signatures (vl_api_memclnt_create_t *mp)
10573 * Send the main API signature in slot 0. This bit of code must
10574 * match the checks in ../vpe/api/api.c: vl_msg_api_version_check().
10576 mp->api_versions[0] = clib_host_to_net_u32 (vpe_api_version);