2 *------------------------------------------------------------------
5 * Copyright (c) 2014 Cisco and/or its affiliates.
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at:
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 *------------------------------------------------------------------
21 #include <vlibapi/api.h>
22 #include <vlibmemory/api.h>
23 #include <vlibsocket/api.h>
24 #include <vnet/ip/ip.h>
25 #include <vnet/sr/sr_packet.h>
26 #include <vnet/l2/l2_input.h>
27 #include <vnet/l2tp/l2tp.h>
28 #include <vnet/vxlan/vxlan.h>
29 #include <vnet/gre/gre.h>
30 #include <vnet/nsh-gre/nsh_gre.h>
31 #include <vnet/nsh-vxlan-gpe/nsh_vxlan_gpe.h>
32 #include <vnet/lisp-gpe/lisp_gpe.h>
34 #include <api/vpe_msg_enum.h>
35 #include <vnet/l2/l2_classify.h>
36 #include <vnet/l2/l2_vtr.h>
37 #include <vnet/classify/input_acl.h>
39 #include <vnet/ipsec/ipsec.h>
40 #include <vnet/ipsec/ikev2.h>
44 #include <vnet/map/map.h>
45 #include <vnet/cop/cop.h>
46 #include <vnet/ip/ip6_hop_by_hop.h>
48 #include "vat/json_format.h"
50 #define vl_typedefs /* define message structures */
51 #include <api/vpe_all_api_h.h>
54 /* declare message handlers for each api */
56 #define vl_endianfun /* define message structures */
57 #include <api/vpe_all_api_h.h>
60 /* instantiate all the print functions we know about */
61 #define vl_print(handle, ...)
63 #include <api/vpe_all_api_h.h>
66 uword unformat_sw_if_index (unformat_input_t * input, va_list * args)
68 vat_main_t * vam = va_arg (*args, vat_main_t *);
69 u32 * result = va_arg (*args, u32 *);
73 if (!unformat (input, "%s", &if_name))
76 p = hash_get_mem (vam->sw_if_index_by_interface_name, if_name);
83 /* Parse an IP4 address %d.%d.%d.%d. */
84 uword unformat_ip4_address (unformat_input_t * input, va_list * args)
86 u8 * result = va_arg (*args, u8 *);
89 if (! unformat (input, "%d.%d.%d.%d", &a[0], &a[1], &a[2], &a[3]))
92 if (a[0] >= 256 || a[1] >= 256 || a[2] >= 256 || a[3] >= 256)
105 unformat_ethernet_address (unformat_input_t * input, va_list * args)
107 u8 * result = va_arg (*args, u8 *);
110 if (! unformat (input, "%_%x:%x:%x:%x:%x:%x%_",
111 &a[0], &a[1], &a[2], &a[3], &a[4], &a[5]))
115 for (i = 0; i < 6; i++)
116 if (a[i] >= (1 << 8))
119 for (i = 0; i < 6; i++)
125 /* Returns ethernet type as an int in host byte order. */
127 unformat_ethernet_type_host_byte_order (unformat_input_t * input,
130 u16 * result = va_arg (*args, u16 *);
134 if (unformat (input, "0x%x", &type)
135 || unformat (input, "%d", &type))
137 if (type >= (1 << 16))
145 /* Parse an IP6 address. */
146 uword unformat_ip6_address (unformat_input_t * input, va_list * args)
148 ip6_address_t * result = va_arg (*args, ip6_address_t *);
150 uword hex_quad, n_hex_quads, hex_digit, n_hex_digits;
151 uword c, n_colon, double_colon_index;
153 n_hex_quads = hex_quad = n_hex_digits = n_colon = 0;
154 double_colon_index = ARRAY_LEN (hex_quads);
155 while ((c = unformat_get_input (input)) != UNFORMAT_END_OF_INPUT)
158 if (c >= '0' && c <= '9')
160 else if (c >= 'a' && c <= 'f')
161 hex_digit = c + 10 - 'a';
162 else if (c >= 'A' && c <= 'F')
163 hex_digit = c + 10 - 'A';
164 else if (c == ':' && n_colon < 2)
168 unformat_put_input (input);
172 /* Too many hex quads. */
173 if (n_hex_quads >= ARRAY_LEN (hex_quads))
178 hex_quad = (hex_quad << 4) | hex_digit;
180 /* Hex quad must fit in 16 bits. */
181 if (n_hex_digits >= 4)
188 /* Save position of :: */
191 /* More than one :: ? */
192 if (double_colon_index < ARRAY_LEN (hex_quads))
194 double_colon_index = n_hex_quads;
197 if (n_colon > 0 && n_hex_digits > 0)
199 hex_quads[n_hex_quads++] = hex_quad;
205 if (n_hex_digits > 0)
206 hex_quads[n_hex_quads++] = hex_quad;
211 /* Expand :: to appropriate number of zero hex quads. */
212 if (double_colon_index < ARRAY_LEN (hex_quads))
214 word n_zero = ARRAY_LEN (hex_quads) - n_hex_quads;
216 for (i = n_hex_quads - 1; i >= (signed) double_colon_index; i--)
217 hex_quads[n_zero + i] = hex_quads[i];
219 for (i = 0; i < n_zero; i++)
220 hex_quads[double_colon_index + i] = 0;
222 n_hex_quads = ARRAY_LEN (hex_quads);
225 /* Too few hex quads given. */
226 if (n_hex_quads < ARRAY_LEN (hex_quads))
229 for (i = 0; i < ARRAY_LEN (hex_quads); i++)
230 result->as_u16[i] = clib_host_to_net_u16 (hex_quads[i]);
237 unformat_ipsec_policy_action (unformat_input_t * input, va_list * args)
240 u32 * r = va_arg (*args, u32 *);
243 #define _(v,f,s) else if (unformat (input, s)) *r = IPSEC_POLICY_ACTION_##f;
244 foreach_ipsec_policy_action
255 unformat_ipsec_crypto_alg (unformat_input_t * input, va_list * args)
258 u32 * r = va_arg (*args, u32 *);
261 #define _(v,f,s) else if (unformat (input, s)) *r = IPSEC_CRYPTO_ALG_##f;
262 foreach_ipsec_crypto_alg
273 format_ipsec_crypto_alg (u8 * s, va_list * args)
276 u32 i = va_arg (*args, u32);
281 #define _(v,f,str) case IPSEC_CRYPTO_ALG_##f: t = (u8 *) str; break;
282 foreach_ipsec_crypto_alg
285 return format (s, "unknown");
287 return format (s, "%s", t);
289 return format (s, "Unimplemented");
294 unformat_ipsec_integ_alg (unformat_input_t * input, va_list * args)
297 u32 * r = va_arg (*args, u32 *);
300 #define _(v,f,s) else if (unformat (input, s)) *r = IPSEC_INTEG_ALG_##f;
301 foreach_ipsec_integ_alg
312 format_ipsec_integ_alg (u8 * s, va_list * args)
315 u32 i = va_arg (*args, u32);
320 #define _(v,f,str) case IPSEC_INTEG_ALG_##f: t = (u8 *) str; break;
321 foreach_ipsec_integ_alg
324 return format (s, "unknown");
326 return format (s, "%s", t);
328 return format (s, "Unsupported");
333 unformat_ikev2_auth_method (unformat_input_t * input, va_list * args)
336 u32 * r = va_arg (*args, u32 *);
339 #define _(v,f,s) else if (unformat (input, s)) *r = IKEV2_AUTH_METHOD_##f;
340 foreach_ikev2_auth_method
351 unformat_ikev2_id_type (unformat_input_t * input, va_list * args)
354 u32 * r = va_arg (*args, u32 *);
357 #define _(v,f,s) else if (unformat (input, s)) *r = IKEV2_ID_TYPE_##f;
358 foreach_ikev2_id_type
368 u8 * format_ip4_address (u8 * s, va_list * args)
370 u8 * a = va_arg (*args, u8 *);
371 return format (s, "%d.%d.%d.%d", a[0], a[1], a[2], a[3]);
374 u8 * format_ip6_address (u8 * s, va_list * args)
376 ip6_address_t * a = va_arg (*args, ip6_address_t *);
377 u32 i, i_max_n_zero, max_n_zeros, i_first_zero, n_zeros, last_double_colon;
379 i_max_n_zero = ARRAY_LEN (a->as_u16);
381 i_first_zero = i_max_n_zero;
383 for (i = 0; i < ARRAY_LEN (a->as_u16); i++)
385 u32 is_zero = a->as_u16[i] == 0;
386 if (is_zero && i_first_zero >= ARRAY_LEN (a->as_u16))
392 if ((! is_zero && n_zeros > max_n_zeros)
393 || (i + 1 >= ARRAY_LEN (a->as_u16) && n_zeros > max_n_zeros))
395 i_max_n_zero = i_first_zero;
396 max_n_zeros = n_zeros;
397 i_first_zero = ARRAY_LEN (a->as_u16);
402 last_double_colon = 0;
403 for (i = 0; i < ARRAY_LEN (a->as_u16); i++)
405 if (i == i_max_n_zero && max_n_zeros > 1)
407 s = format (s, "::");
408 i += max_n_zeros - 1;
409 last_double_colon = 1;
413 s = format (s, "%s%x",
414 (last_double_colon || i == 0) ? "" : ":",
415 clib_net_to_host_u16 (a->as_u16[i]));
416 last_double_colon = 0;
423 /* Format an IP46 address. */
424 u8 * format_ip46_address (u8 * s, va_list * args)
426 ip46_address_t *ip46 = va_arg (*args, ip46_address_t *);
427 return ip46_address_is_ip4(ip46)?
428 format(s, "%U", format_ip4_address, &ip46->ip4):
429 format(s, "%U", format_ip6_address, &ip46->ip6);
432 u8 * format_ethernet_address (u8 * s, va_list * args)
434 u8 * a = va_arg (*args, u8 *);
436 return format (s, "%02x:%02x:%02x:%02x:%02x:%02x",
437 a[0], a[1], a[2], a[3], a[4], a[5]);
440 void increment_v4_address (ip4_address_t * a)
444 v = ntohl(a->as_u32) + 1;
445 a->as_u32 = ntohl(v);
448 void increment_v6_address (ip6_address_t * a)
452 v0 = clib_net_to_host_u64 (a->as_u64[0]);
453 v1 = clib_net_to_host_u64 (a->as_u64[1]);
458 a->as_u64[0] = clib_net_to_host_u64 (v0);
459 a->as_u64[1] = clib_net_to_host_u64 (v1);
463 static void vl_api_create_loopback_reply_t_handler
464 (vl_api_create_loopback_reply_t * mp)
466 vat_main_t * vam = &vat_main;
467 i32 retval = ntohl(mp->retval);
469 vam->retval = retval;
470 vam->result_ready = 1;
471 vam->regenerate_interface_table = 1;
474 static void vl_api_create_loopback_reply_t_handler_json
475 (vl_api_create_loopback_reply_t * mp)
477 vat_main_t * vam = &vat_main;
478 vat_json_node_t node;
480 vat_json_init_object(&node);
481 vat_json_object_add_int(&node, "retval", ntohl(mp->retval));
482 vat_json_object_add_uint(&node, "sw_if_index", ntohl(mp->sw_if_index));
484 vat_json_print(vam->ofp, &node);
485 vat_json_free(&node);
487 vam->retval = ntohl(mp->retval);
488 vam->result_ready = 1;
491 static void vl_api_create_vlan_subif_reply_t_handler
492 (vl_api_create_vlan_subif_reply_t * mp)
494 vat_main_t * vam = &vat_main;
495 i32 retval = ntohl(mp->retval);
497 vam->retval = retval;
498 vam->result_ready = 1;
499 vam->regenerate_interface_table = 1;
502 static void vl_api_create_vlan_subif_reply_t_handler_json
503 (vl_api_create_vlan_subif_reply_t * mp)
505 vat_main_t * vam = &vat_main;
506 vat_json_node_t node;
508 vat_json_init_object(&node);
509 vat_json_object_add_int(&node, "retval", ntohl(mp->retval));
510 vat_json_object_add_uint(&node, "sw_if_index", ntohl(mp->sw_if_index));
512 vat_json_print(vam->ofp, &node);
513 vat_json_free(&node);
515 vam->retval = ntohl(mp->retval);
516 vam->result_ready = 1;
519 static void vl_api_create_subif_reply_t_handler
520 (vl_api_create_subif_reply_t * mp)
522 vat_main_t * vam = &vat_main;
523 i32 retval = ntohl(mp->retval);
525 vam->retval = retval;
526 vam->result_ready = 1;
527 vam->regenerate_interface_table = 1;
530 static void vl_api_create_subif_reply_t_handler_json
531 (vl_api_create_subif_reply_t * mp)
533 vat_main_t * vam = &vat_main;
534 vat_json_node_t node;
536 vat_json_init_object(&node);
537 vat_json_object_add_int(&node, "retval", ntohl(mp->retval));
538 vat_json_object_add_uint(&node, "sw_if_index", ntohl(mp->sw_if_index));
540 vat_json_print(vam->ofp, &node);
541 vat_json_free(&node);
543 vam->retval = ntohl(mp->retval);
544 vam->result_ready = 1;
547 static void vl_api_interface_name_renumber_reply_t_handler
548 (vl_api_interface_name_renumber_reply_t * mp)
550 vat_main_t * vam = &vat_main;
551 i32 retval = ntohl(mp->retval);
553 vam->retval = retval;
554 vam->result_ready = 1;
555 vam->regenerate_interface_table = 1;
558 static void vl_api_interface_name_renumber_reply_t_handler_json
559 (vl_api_interface_name_renumber_reply_t * mp)
561 vat_main_t * vam = &vat_main;
562 vat_json_node_t node;
564 vat_json_init_object(&node);
565 vat_json_object_add_int(&node, "retval", ntohl(mp->retval));
567 vat_json_print(vam->ofp, &node);
568 vat_json_free(&node);
570 vam->retval = ntohl(mp->retval);
571 vam->result_ready = 1;
575 * Special-case: build the interface table, maintain
576 * the next loopback sw_if_index vbl.
578 static void vl_api_sw_interface_details_t_handler
579 (vl_api_sw_interface_details_t * mp)
581 vat_main_t * vam = &vat_main;
582 u8 * s = format (0, "%s%c", mp->interface_name, 0);
584 hash_set_mem (vam->sw_if_index_by_interface_name, s,
585 ntohl(mp->sw_if_index));
587 /* In sub interface case, fill the sub interface table entry */
588 if (mp->sw_if_index != mp->sup_sw_if_index) {
589 sw_interface_subif_t * sub = NULL;
591 vec_add2(vam->sw_if_subif_table, sub, 1);
593 vec_validate(sub->interface_name, strlen((char *)s) + 1);
594 strncpy((char *)sub->interface_name, (char *)s,
595 vec_len(sub->interface_name));
596 sub->sw_if_index = ntohl(mp->sw_if_index);
597 sub->sub_id = ntohl(mp->sub_id);
599 sub->sub_dot1ad = mp->sub_dot1ad;
600 sub->sub_number_of_tags = mp->sub_number_of_tags;
601 sub->sub_outer_vlan_id = ntohs(mp->sub_outer_vlan_id);
602 sub->sub_inner_vlan_id = ntohs(mp->sub_inner_vlan_id);
603 sub->sub_exact_match = mp->sub_exact_match;
604 sub->sub_default = mp->sub_default;
605 sub->sub_outer_vlan_id_any = mp->sub_outer_vlan_id_any;
606 sub->sub_inner_vlan_id_any = mp->sub_inner_vlan_id_any;
608 /* vlan tag rewrite */
609 sub->vtr_op = ntohl(mp->vtr_op);
610 sub->vtr_push_dot1q = ntohl(mp->vtr_push_dot1q);
611 sub->vtr_tag1 = ntohl(mp->vtr_tag1);
612 sub->vtr_tag2 = ntohl(mp->vtr_tag2);
616 static void vl_api_sw_interface_details_t_handler_json
617 (vl_api_sw_interface_details_t * mp)
619 vat_main_t * vam = &vat_main;
620 vat_json_node_t *node = NULL;
622 if (VAT_JSON_ARRAY != vam->json_tree.type) {
623 ASSERT(VAT_JSON_NONE == vam->json_tree.type);
624 vat_json_init_array(&vam->json_tree);
626 node = vat_json_array_add(&vam->json_tree);
628 vat_json_init_object(node);
629 vat_json_object_add_uint(node, "sw_if_index", ntohl(mp->sw_if_index));
630 vat_json_object_add_uint(node, "sup_sw_if_index", ntohl(mp->sup_sw_if_index));
631 vat_json_object_add_uint(node, "l2_address_length", ntohl(mp->l2_address_length));
632 vat_json_object_add_bytes(node, "l2_address", mp->l2_address, sizeof(mp->l2_address));
633 vat_json_object_add_string_copy(node, "interface_name", mp->interface_name);
634 vat_json_object_add_uint(node, "admin_up_down", mp->admin_up_down);
635 vat_json_object_add_uint(node, "link_up_down", mp->link_up_down);
636 vat_json_object_add_uint(node, "link_duplex", mp->link_duplex);
637 vat_json_object_add_uint(node, "link_speed", mp->link_speed);
638 vat_json_object_add_uint(node, "mtu", ntohs(mp->link_mtu));
639 vat_json_object_add_uint(node, "sub_id", ntohl(mp->sub_id));
640 vat_json_object_add_uint(node, "sub_dot1ad", mp->sub_dot1ad);
641 vat_json_object_add_uint(node, "sub_number_of_tags", mp->sub_number_of_tags);
642 vat_json_object_add_uint(node, "sub_outer_vlan_id", ntohs(mp->sub_outer_vlan_id));
643 vat_json_object_add_uint(node, "sub_inner_vlan_id", ntohs(mp->sub_inner_vlan_id));
644 vat_json_object_add_uint(node, "sub_exact_match", mp->sub_exact_match);
645 vat_json_object_add_uint(node, "sub_default", mp->sub_default);
646 vat_json_object_add_uint(node, "sub_outer_vlan_id_any", mp->sub_outer_vlan_id_any);
647 vat_json_object_add_uint(node, "sub_inner_vlan_id_any", mp->sub_inner_vlan_id_any);
648 vat_json_object_add_uint(node, "vtr_op", ntohl(mp->vtr_op));
649 vat_json_object_add_uint(node, "vtr_push_dot1q", ntohl(mp->vtr_push_dot1q));
650 vat_json_object_add_uint(node, "vtr_tag1", ntohl(mp->vtr_tag1));
651 vat_json_object_add_uint(node, "vtr_tag2", ntohl(mp->vtr_tag2));
654 static void vl_api_sw_interface_set_flags_t_handler
655 (vl_api_sw_interface_set_flags_t * mp)
657 vat_main_t * vam = &vat_main;
658 if (vam->interface_event_display)
659 errmsg ("interface flags: sw_if_index %d %s %s\n",
660 ntohl(mp->sw_if_index),
661 mp->admin_up_down ? "admin-up" : "admin-down",
662 mp->link_up_down ? "link-up" : "link-down");
665 static void vl_api_sw_interface_set_flags_t_handler_json
666 (vl_api_sw_interface_set_flags_t * mp)
668 /* JSON output not supported */
671 static void vl_api_cli_reply_t_handler
672 (vl_api_cli_reply_t * mp)
674 vat_main_t * vam = &vat_main;
675 i32 retval = ntohl(mp->retval);
677 vam->retval = retval;
678 vam->shmem_result = (u8 *) mp->reply_in_shmem;
679 vam->result_ready = 1;
682 static void vl_api_cli_reply_t_handler_json
683 (vl_api_cli_reply_t * mp)
685 vat_main_t * vam = &vat_main;
686 vat_json_node_t node;
687 api_main_t * am = &api_main;
691 vat_json_init_object(&node);
692 vat_json_object_add_int(&node, "retval", ntohl(mp->retval));
693 vat_json_object_add_uint(&node, "reply_in_shmem",
694 ntohl(mp->reply_in_shmem));
695 /* Toss the shared-memory original... */
696 pthread_mutex_lock (&am->vlib_rp->mutex);
697 oldheap = svm_push_data_heap (am->vlib_rp);
699 reply = (u8 *)(mp->reply_in_shmem);
702 svm_pop_heap (oldheap);
703 pthread_mutex_unlock (&am->vlib_rp->mutex);
705 vat_json_print(vam->ofp, &node);
706 vat_json_free(&node);
708 vam->retval = ntohl(mp->retval);
709 vam->result_ready = 1;
712 static void vl_api_classify_add_del_table_reply_t_handler
713 (vl_api_classify_add_del_table_reply_t * mp)
715 vat_main_t * vam = &vat_main;
716 i32 retval = ntohl(mp->retval);
717 if (vam->async_mode) {
718 vam->async_errors += (retval < 0);
720 vam->retval = retval;
721 vam->result_ready = 1;
723 ((mp->new_table_index != 0xFFFFFFFF) ||
724 (mp->skip_n_vectors != 0xFFFFFFFF) ||
725 (mp->match_n_vectors != 0xFFFFFFFF)))
727 * Note: this is just barely thread-safe, depends on
728 * the main thread spinning waiting for an answer...
730 errmsg ("new index %d, skip_n_vectors %d, match_n_vectors %d\n",
731 ntohl(mp->new_table_index),
732 ntohl(mp->skip_n_vectors), ntohl(mp->match_n_vectors));
736 static void vl_api_classify_add_del_table_reply_t_handler_json
737 (vl_api_classify_add_del_table_reply_t * mp)
739 vat_main_t * vam = &vat_main;
740 vat_json_node_t node;
742 vat_json_init_object(&node);
743 vat_json_object_add_int(&node, "retval", ntohl(mp->retval));
744 vat_json_object_add_uint(&node, "new_table_index", ntohl(mp->new_table_index));
745 vat_json_object_add_uint(&node, "skip_n_vectors", ntohl(mp->skip_n_vectors));
746 vat_json_object_add_uint(&node, "match_n_vectors", ntohl(mp->match_n_vectors));
748 vat_json_print(vam->ofp, &node);
749 vat_json_free(&node);
751 vam->retval = ntohl(mp->retval);
752 vam->result_ready = 1;
755 static void vl_api_get_node_index_reply_t_handler
756 (vl_api_get_node_index_reply_t * mp)
758 vat_main_t * vam = &vat_main;
759 i32 retval = ntohl(mp->retval);
760 if (vam->async_mode) {
761 vam->async_errors += (retval < 0);
763 vam->retval = retval;
764 vam->result_ready = 1;
766 errmsg ("node index %d\n", ntohl(mp->node_index));
770 static void vl_api_get_node_index_reply_t_handler_json
771 (vl_api_get_node_index_reply_t * mp)
773 vat_main_t * vam = &vat_main;
774 vat_json_node_t node;
776 vat_json_init_object(&node);
777 vat_json_object_add_int(&node, "retval", ntohl(mp->retval));
778 vat_json_object_add_uint(&node, "node_index", ntohl(mp->node_index));
780 vat_json_print(vam->ofp, &node);
781 vat_json_free(&node);
783 vam->retval = ntohl(mp->retval);
784 vam->result_ready = 1;
787 static void vl_api_add_node_next_reply_t_handler
788 (vl_api_add_node_next_reply_t * mp)
790 vat_main_t * vam = &vat_main;
791 i32 retval = ntohl(mp->retval);
792 if (vam->async_mode) {
793 vam->async_errors += (retval < 0);
795 vam->retval = retval;
796 vam->result_ready = 1;
798 errmsg ("next index %d\n", ntohl(mp->next_index));
802 static void vl_api_add_node_next_reply_t_handler_json
803 (vl_api_add_node_next_reply_t * mp)
805 vat_main_t * vam = &vat_main;
806 vat_json_node_t node;
808 vat_json_init_object(&node);
809 vat_json_object_add_int(&node, "retval", ntohl(mp->retval));
810 vat_json_object_add_uint(&node, "next_index", ntohl(mp->next_index));
812 vat_json_print(vam->ofp, &node);
813 vat_json_free(&node);
815 vam->retval = ntohl(mp->retval);
816 vam->result_ready = 1;
819 static void vl_api_mpls_gre_add_del_tunnel_reply_t_handler
820 (vl_api_mpls_gre_add_del_tunnel_reply_t * mp)
822 vat_main_t * vam = &vat_main;
823 i32 retval = ntohl(mp->retval);
824 u32 sw_if_index = ntohl(mp->tunnel_sw_if_index);
826 if (retval >= 0 && sw_if_index != (u32)~0) {
827 errmsg ("tunnel_sw_if_index %d\n", sw_if_index);
829 vam->retval = retval;
830 vam->result_ready = 1;
833 static void vl_api_mpls_gre_add_del_tunnel_reply_t_handler_json
834 (vl_api_mpls_gre_add_del_tunnel_reply_t * mp)
836 vat_main_t * vam = &vat_main;
837 vat_json_node_t node;
839 vat_json_init_object(&node);
840 vat_json_object_add_int(&node, "retval", ntohl(mp->retval));
841 vat_json_object_add_uint(&node, "tunnel_sw_if_index", ntohl(mp->tunnel_sw_if_index));
843 vat_json_print(vam->ofp, &node);
844 vat_json_free(&node);
846 vam->retval = ntohl(mp->retval);
847 vam->result_ready = 1;
850 static void vl_api_nsh_gre_add_del_tunnel_reply_t_handler
851 (vl_api_nsh_gre_add_del_tunnel_reply_t * mp)
853 vat_main_t * vam = &vat_main;
854 i32 retval = ntohl(mp->retval);
855 u32 sw_if_index = ntohl(mp->sw_if_index);
857 if (retval >= 0 && sw_if_index != (u32)~0) {
858 errmsg ("sw_if_index %d\n", ntohl(mp->sw_if_index));
860 vam->retval = retval;
861 vam->result_ready = 1;
864 static void vl_api_nsh_gre_add_del_tunnel_reply_t_handler_json
865 (vl_api_nsh_gre_add_del_tunnel_reply_t * mp)
867 vat_main_t * vam = &vat_main;
868 vat_json_node_t node;
870 vat_json_init_object(&node);
871 vat_json_object_add_int(&node, "retval", ntohl(mp->retval));
872 vat_json_object_add_uint(&node, "sw_if_index", ntohl(mp->sw_if_index));
874 vat_json_print(vam->ofp, &node);
875 vat_json_free(&node);
877 vam->retval = ntohl(mp->retval);
878 vam->result_ready = 1;
881 static void vl_api_nsh_vxlan_gpe_add_del_tunnel_reply_t_handler
882 (vl_api_nsh_vxlan_gpe_add_del_tunnel_reply_t * mp)
884 vat_main_t * vam = &vat_main;
885 i32 retval = ntohl(mp->retval);
886 u32 sw_if_index = ntohl(mp->sw_if_index);
888 if (retval >= 0 && sw_if_index != (u32)~0) {
889 errmsg ("sw_if_index %d\n", ntohl(mp->sw_if_index));
891 vam->retval = retval;
892 vam->result_ready = 1;
895 static void vl_api_nsh_vxlan_gpe_add_del_tunnel_reply_t_handler_json
896 (vl_api_nsh_vxlan_gpe_add_del_tunnel_reply_t * mp)
898 vat_main_t * vam = &vat_main;
899 vat_json_node_t node;
901 vat_json_init_object(&node);
902 vat_json_object_add_int(&node, "retval", ntohl(mp->retval));
903 vat_json_object_add_uint(&node, "sw_if_index", ntohl(mp->sw_if_index));
905 vat_json_print(vam->ofp, &node);
906 vat_json_free(&node);
908 vam->retval = ntohl(mp->retval);
909 vam->result_ready = 1;
912 static void vl_api_show_version_reply_t_handler
913 (vl_api_show_version_reply_t * mp)
915 vat_main_t * vam = &vat_main;
916 i32 retval = ntohl(mp->retval);
919 errmsg (" program: %s\n", mp->program);
920 errmsg (" version: %s\n", mp->version);
921 errmsg (" build date: %s\n", mp->build_date);
922 errmsg ("build directory: %s\n", mp->build_directory);
924 vam->retval = retval;
925 vam->result_ready = 1;
928 static void vl_api_show_version_reply_t_handler_json
929 (vl_api_show_version_reply_t * mp)
931 vat_main_t * vam = &vat_main;
932 vat_json_node_t node;
934 vat_json_init_object(&node);
935 vat_json_object_add_int(&node, "retval", ntohl(mp->retval));
936 vat_json_object_add_string_copy(&node, "program", mp->program);
937 vat_json_object_add_string_copy(&node, "version", mp->version);
938 vat_json_object_add_string_copy(&node, "build_date", mp->build_date);
939 vat_json_object_add_string_copy(&node, "build_directory", mp->build_directory);
941 vat_json_print(vam->ofp, &node);
942 vat_json_free(&node);
944 vam->retval = ntohl(mp->retval);
945 vam->result_ready = 1;
948 static void vl_api_ip4_arp_event_t_handler
949 (vl_api_ip4_arp_event_t * mp)
951 vat_main_t * vam = &vat_main;
952 errmsg ("arp event: address %U new mac %U sw_if_index %d\n",
953 format_ip4_address, &mp->address,
954 format_ethernet_address, mp->new_mac, mp->sw_if_index);
957 static void vl_api_ip4_arp_event_t_handler_json
958 (vl_api_ip4_arp_event_t * mp)
960 /* JSON output not supported */
964 * Special-case: build the bridge domain table, maintain
965 * the next bd id vbl.
967 static void vl_api_bridge_domain_details_t_handler
968 (vl_api_bridge_domain_details_t * mp)
970 vat_main_t * vam = &vat_main;
971 u32 n_sw_ifs = ntohl (mp->n_sw_ifs);
973 fformat (vam->ofp, "\n%-3s %-3s %-3s %-3s %-3s %-3s\n",
974 " ID", "LRN", "FWD", "FLD", "BVI", "#IF");
976 fformat (vam->ofp, "%3d %3d %3d %3d %3d %3d\n",
977 ntohl (mp->bd_id), mp->learn, mp->forward,
978 mp->flood, ntohl (mp->bvi_sw_if_index), n_sw_ifs);
981 fformat (vam->ofp, "\n\n%s %s %s\n", "sw_if_index", "SHG",
985 static void vl_api_bridge_domain_details_t_handler_json
986 (vl_api_bridge_domain_details_t * mp)
988 vat_main_t * vam = &vat_main;
989 vat_json_node_t *node, *array = NULL;
991 if (VAT_JSON_ARRAY != vam->json_tree.type) {
992 ASSERT(VAT_JSON_NONE == vam->json_tree.type);
993 vat_json_init_array(&vam->json_tree);
995 node = vat_json_array_add(&vam->json_tree);
997 vat_json_init_object(node);
998 vat_json_object_add_uint(node, "bd_id", ntohl(mp->bd_id));
999 vat_json_object_add_uint(node, "flood", mp->flood);
1000 vat_json_object_add_uint(node, "forward", mp->forward);
1001 vat_json_object_add_uint(node, "learn", mp->learn);
1002 vat_json_object_add_uint(node, "bvi_sw_if_index", ntohl(mp->bvi_sw_if_index));
1003 vat_json_object_add_uint(node, "n_sw_ifs", ntohl(mp->n_sw_ifs));
1004 array = vat_json_object_add(node, "sw_if");
1005 vat_json_init_array(array);
1009 * Special-case: build the bridge domain sw if table.
1011 static void vl_api_bridge_domain_sw_if_details_t_handler
1012 (vl_api_bridge_domain_sw_if_details_t * mp)
1014 vat_main_t * vam = &vat_main;
1016 u8 * sw_if_name = 0;
1019 sw_if_index = ntohl (mp->sw_if_index);
1020 hash_foreach_pair (p, vam->sw_if_index_by_interface_name,
1022 if ((u32) p->value[0] == sw_if_index) {
1023 sw_if_name = (u8 *)(p->key);
1028 fformat (vam->ofp, "%7d %3d %s", sw_if_index,
1029 mp->shg, sw_if_name ? (char *)sw_if_name :
1030 "sw_if_index not found!");
1033 static void vl_api_bridge_domain_sw_if_details_t_handler_json
1034 (vl_api_bridge_domain_sw_if_details_t * mp)
1036 vat_main_t * vam = &vat_main;
1037 vat_json_node_t *node = NULL;
1038 uword last_index = 0;
1040 ASSERT(VAT_JSON_ARRAY == vam->json_tree.type);
1041 ASSERT(vec_len(vam->json_tree.array) >= 1);
1042 last_index = vec_len(vam->json_tree.array) - 1;
1043 node = &vam->json_tree.array[last_index];
1044 node = vat_json_object_get_element(node, "sw_if");
1045 ASSERT(NULL != node);
1046 node = vat_json_array_add(node);
1048 vat_json_init_object(node);
1049 vat_json_object_add_uint(node, "bd_id", ntohl(mp->bd_id));
1050 vat_json_object_add_uint(node, "sw_if_index", ntohl(mp->sw_if_index));
1051 vat_json_object_add_uint(node, "shg", mp->shg);
1054 static void vl_api_control_ping_reply_t_handler
1055 (vl_api_control_ping_reply_t * mp)
1057 vat_main_t * vam = &vat_main;
1058 i32 retval = ntohl(mp->retval);
1059 if (vam->async_mode) {
1060 vam->async_errors += (retval < 0);
1062 vam->retval = retval;
1063 vam->result_ready = 1;
1067 static void vl_api_control_ping_reply_t_handler_json
1068 (vl_api_control_ping_reply_t * mp)
1070 vat_main_t * vam = &vat_main;
1071 i32 retval = ntohl(mp->retval);
1073 if (VAT_JSON_NONE != vam->json_tree.type) {
1074 vat_json_print(vam->ofp, &vam->json_tree);
1075 vat_json_free(&vam->json_tree);
1076 vam->json_tree.type = VAT_JSON_NONE;
1079 vat_json_init_array(&vam->json_tree);
1080 vat_json_print(vam->ofp, &vam->json_tree);
1081 vam->json_tree.type = VAT_JSON_NONE;
1084 vam->retval = retval;
1085 vam->result_ready = 1;
1088 static void vl_api_l2_flags_reply_t_handler
1089 (vl_api_l2_flags_reply_t * mp)
1091 vat_main_t * vam = &vat_main;
1092 i32 retval = ntohl(mp->retval);
1093 if (vam->async_mode) {
1094 vam->async_errors += (retval < 0);
1096 vam->retval = retval;
1097 vam->result_ready = 1;
1101 static void vl_api_l2_flags_reply_t_handler_json
1102 (vl_api_l2_flags_reply_t * mp)
1104 vat_main_t * vam = &vat_main;
1105 vat_json_node_t node;
1107 vat_json_init_object(&node);
1108 vat_json_object_add_int(&node, "retval", ntohl(mp->retval));
1109 vat_json_object_add_uint(&node, "resulting_feature_bitmap", ntohl(mp->resulting_feature_bitmap));
1111 vat_json_print(vam->ofp, &node);
1112 vat_json_free(&node);
1114 vam->retval = ntohl(mp->retval);
1115 vam->result_ready = 1;
1118 static void vl_api_bridge_flags_reply_t_handler
1119 (vl_api_bridge_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_bridge_flags_reply_t_handler_json
1132 (vl_api_bridge_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_tap_connect_reply_t_handler
1149 (vl_api_tap_connect_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_tap_connect_reply_t_handler_json
1162 (vl_api_tap_connect_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, "sw_if_index", ntohl(mp->sw_if_index));
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_modify_reply_t_handler
1179 (vl_api_tap_modify_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_modify_reply_t_handler_json
1192 (vl_api_tap_modify_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_delete_reply_t_handler
1209 (vl_api_tap_delete_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_delete_reply_t_handler_json
1222 (vl_api_tap_delete_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));
1230 vat_json_print(vam->ofp, &node);
1231 vat_json_free(&node);
1233 vam->retval = ntohl(mp->retval);
1234 vam->result_ready = 1;
1237 static void vl_api_mpls_ethernet_add_del_tunnel_reply_t_handler
1238 (vl_api_mpls_ethernet_add_del_tunnel_reply_t * mp)
1240 vat_main_t * vam = &vat_main;
1241 i32 retval = ntohl(mp->retval);
1242 if (vam->async_mode) {
1243 vam->async_errors += (retval < 0);
1245 vam->retval = retval;
1246 vam->result_ready = 1;
1250 static void vl_api_mpls_ethernet_add_del_tunnel_reply_t_handler_json
1251 (vl_api_mpls_ethernet_add_del_tunnel_reply_t * mp)
1253 vat_main_t * vam = &vat_main;
1254 vat_json_node_t node;
1256 vat_json_init_object(&node);
1257 vat_json_object_add_int(&node, "retval", ntohl(mp->retval));
1258 vat_json_object_add_uint(&node, "tunnel_sw_if_index", ntohl(mp->tunnel_sw_if_index));
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_l2tpv3_create_tunnel_reply_t_handler
1268 (vl_api_l2tpv3_create_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_l2tpv3_create_tunnel_reply_t_handler_json
1281 (vl_api_l2tpv3_create_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, "sw_if_index", ntohl(mp->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_vxlan_add_del_tunnel_reply_t_handler
1298 (vl_api_vxlan_add_del_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_vxlan_add_del_tunnel_reply_t_handler_json
1311 (vl_api_vxlan_add_del_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_gre_add_del_tunnel_reply_t_handler
1328 (vl_api_gre_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_gre_add_del_tunnel_reply_t_handler_json
1341 (vl_api_gre_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);
2086 vl_api_lisp_gpe_enable_disable_status_details_t_handler
2087 (vl_api_lisp_gpe_enable_disable_status_details_t *mp)
2089 vat_main_t *vam = &vat_main;
2091 fformat(vam->ofp, "%=20s\n",
2092 mp->is_en ? "enable" : "disable");
2096 vl_api_lisp_gpe_enable_disable_status_details_t_handler_json
2097 (vl_api_lisp_gpe_enable_disable_status_details_t *mp)
2099 vat_main_t *vam = &vat_main;
2100 vat_json_node_t *node = NULL;
2103 str = format(0, "%s", mp->is_en ? "enable" : "disable");
2105 if (VAT_JSON_ARRAY != vam->json_tree.type) {
2106 ASSERT(VAT_JSON_NONE == vam->json_tree.type);
2107 vat_json_init_array(&vam->json_tree);
2109 node = vat_json_array_add(&vam->json_tree);
2111 vat_json_init_object(node);
2112 vat_json_object_add_string_copy(node, "lisp_gpe", str);
2115 #define vl_api_vnet_ip4_fib_counters_t_endian vl_noop_handler
2116 #define vl_api_vnet_ip4_fib_counters_t_print vl_noop_handler
2117 #define vl_api_vnet_ip6_fib_counters_t_endian vl_noop_handler
2118 #define vl_api_vnet_ip6_fib_counters_t_print vl_noop_handler
2121 * Generate boilerplate reply handlers, which
2122 * dig the return value out of the xxx_reply_t API message,
2123 * stick it into vam->retval, and set vam->result_ready
2125 * Could also do this by pointing N message decode slots at
2126 * a single function, but that could break in subtle ways.
2129 #define foreach_standard_reply_retval_handler \
2130 _(sw_interface_set_flags_reply) \
2131 _(sw_interface_add_del_address_reply) \
2132 _(sw_interface_set_table_reply) \
2133 _(sw_interface_set_vpath_reply) \
2134 _(sw_interface_set_l2_bridge_reply) \
2135 _(bridge_domain_add_del_reply) \
2136 _(sw_interface_set_l2_xconnect_reply) \
2137 _(l2fib_add_del_reply) \
2138 _(ip_add_del_route_reply) \
2139 _(proxy_arp_add_del_reply) \
2140 _(proxy_arp_intfc_enable_disable_reply) \
2141 _(mpls_add_del_encap_reply) \
2142 _(mpls_add_del_decap_reply) \
2143 _(mpls_ethernet_add_del_tunnel_2_reply) \
2144 _(sw_interface_set_unnumbered_reply) \
2145 _(ip_neighbor_add_del_reply) \
2146 _(reset_vrf_reply) \
2147 _(oam_add_del_reply) \
2148 _(reset_fib_reply) \
2149 _(dhcp_proxy_config_reply) \
2150 _(dhcp_proxy_config_2_reply) \
2151 _(dhcp_proxy_set_vss_reply) \
2152 _(dhcp_client_config_reply) \
2153 _(set_ip_flow_hash_reply) \
2154 _(sw_interface_ip6_enable_disable_reply) \
2155 _(sw_interface_ip6_set_link_local_address_reply) \
2156 _(sw_interface_ip6nd_ra_prefix_reply) \
2157 _(sw_interface_ip6nd_ra_config_reply) \
2158 _(set_arp_neighbor_limit_reply) \
2159 _(l2_patch_add_del_reply) \
2160 _(sr_tunnel_add_del_reply) \
2161 _(sr_policy_add_del_reply) \
2162 _(sr_multicast_map_add_del_reply) \
2163 _(classify_add_del_session_reply) \
2164 _(classify_set_interface_ip_table_reply) \
2165 _(classify_set_interface_l2_tables_reply) \
2166 _(l2tpv3_set_tunnel_cookies_reply) \
2167 _(l2tpv3_interface_enable_disable_reply) \
2168 _(l2tpv3_set_lookup_key_reply) \
2169 _(l2_fib_clear_table_reply) \
2170 _(l2_interface_efp_filter_reply) \
2171 _(l2_interface_vlan_tag_rewrite_reply) \
2172 _(modify_vhost_user_if_reply) \
2173 _(delete_vhost_user_if_reply) \
2174 _(want_ip4_arp_events_reply) \
2175 _(input_acl_set_interface_reply) \
2176 _(ipsec_spd_add_del_reply) \
2177 _(ipsec_interface_add_del_spd_reply) \
2178 _(ipsec_spd_add_del_entry_reply) \
2179 _(ipsec_sad_add_del_entry_reply) \
2180 _(ipsec_sa_set_key_reply) \
2181 _(ikev2_profile_add_del_reply) \
2182 _(ikev2_profile_set_auth_reply) \
2183 _(ikev2_profile_set_id_reply) \
2184 _(ikev2_profile_set_ts_reply) \
2185 _(ikev2_set_local_key_reply) \
2186 _(delete_loopback_reply) \
2187 _(bd_ip_mac_add_del_reply) \
2188 _(map_del_domain_reply) \
2189 _(map_add_del_rule_reply) \
2190 _(want_interface_events_reply) \
2191 _(want_stats_reply) \
2192 _(cop_interface_enable_disable_reply) \
2193 _(cop_whitelist_enable_disable_reply) \
2194 _(sw_interface_clear_stats_reply) \
2195 _(trace_profile_add_reply) \
2196 _(trace_profile_apply_reply) \
2197 _(trace_profile_del_reply) \
2198 _(lisp_add_del_locator_set_reply) \
2199 _(lisp_add_del_locator_reply) \
2200 _(lisp_add_del_local_eid_reply) \
2201 _(lisp_gpe_add_del_fwd_entry_reply) \
2202 _(lisp_add_del_map_resolver_reply) \
2203 _(lisp_gpe_enable_disable_reply) \
2204 _(lisp_gpe_add_del_iface_reply) \
2205 _(af_packet_create_reply) \
2206 _(af_packet_delete_reply)
2209 static void vl_api_##n##_t_handler \
2210 (vl_api_##n##_t * mp) \
2212 vat_main_t * vam = &vat_main; \
2213 i32 retval = ntohl(mp->retval); \
2214 if (vam->async_mode) { \
2215 vam->async_errors += (retval < 0); \
2217 vam->retval = retval; \
2218 vam->result_ready = 1; \
2221 foreach_standard_reply_retval_handler;
2225 static void vl_api_##n##_t_handler_json \
2226 (vl_api_##n##_t * mp) \
2228 vat_main_t * vam = &vat_main; \
2229 vat_json_node_t node; \
2230 vat_json_init_object(&node); \
2231 vat_json_object_add_int(&node, "retval", ntohl(mp->retval)); \
2232 vat_json_print(vam->ofp, &node); \
2233 vam->retval = ntohl(mp->retval); \
2234 vam->result_ready = 1; \
2236 foreach_standard_reply_retval_handler;
2240 * Table of message reply handlers, must include boilerplate handlers
2244 #define foreach_vpe_api_reply_msg \
2245 _(CREATE_LOOPBACK_REPLY, create_loopback_reply) \
2246 _(SW_INTERFACE_DETAILS, sw_interface_details) \
2247 _(SW_INTERFACE_SET_FLAGS, sw_interface_set_flags) \
2248 _(SW_INTERFACE_SET_FLAGS_REPLY, sw_interface_set_flags_reply) \
2249 _(CONTROL_PING_REPLY, control_ping_reply) \
2250 _(CLI_REPLY, cli_reply) \
2251 _(SW_INTERFACE_ADD_DEL_ADDRESS_REPLY, \
2252 sw_interface_add_del_address_reply) \
2253 _(SW_INTERFACE_SET_TABLE_REPLY, sw_interface_set_table_reply) \
2254 _(SW_INTERFACE_SET_VPATH_REPLY, sw_interface_set_vpath_reply) \
2255 _(SW_INTERFACE_SET_L2_XCONNECT_REPLY, \
2256 sw_interface_set_l2_xconnect_reply) \
2257 _(SW_INTERFACE_SET_L2_BRIDGE_REPLY, \
2258 sw_interface_set_l2_bridge_reply) \
2259 _(BRIDGE_DOMAIN_ADD_DEL_REPLY, bridge_domain_add_del_reply) \
2260 _(BRIDGE_DOMAIN_DETAILS, bridge_domain_details) \
2261 _(BRIDGE_DOMAIN_SW_IF_DETAILS, bridge_domain_sw_if_details) \
2262 _(L2FIB_ADD_DEL_REPLY, l2fib_add_del_reply) \
2263 _(L2_FLAGS_REPLY, l2_flags_reply) \
2264 _(BRIDGE_FLAGS_REPLY, bridge_flags_reply) \
2265 _(TAP_CONNECT_REPLY, tap_connect_reply) \
2266 _(TAP_MODIFY_REPLY, tap_modify_reply) \
2267 _(TAP_DELETE_REPLY, tap_delete_reply) \
2268 _(SW_INTERFACE_TAP_DETAILS, sw_interface_tap_details) \
2269 _(IP_ADD_DEL_ROUTE_REPLY, ip_add_del_route_reply) \
2270 _(PROXY_ARP_ADD_DEL_REPLY, proxy_arp_add_del_reply) \
2271 _(PROXY_ARP_INTFC_ENABLE_DISABLE_REPLY, \
2272 proxy_arp_intfc_enable_disable_reply) \
2273 _(MPLS_ADD_DEL_ENCAP_REPLY, mpls_add_del_encap_reply) \
2274 _(MPLS_ADD_DEL_DECAP_REPLY, mpls_add_del_decap_reply) \
2275 _(MPLS_GRE_ADD_DEL_TUNNEL_REPLY, mpls_gre_add_del_tunnel_reply) \
2276 _(MPLS_ETHERNET_ADD_DEL_TUNNEL_REPLY, \
2277 mpls_ethernet_add_del_tunnel_reply) \
2278 _(MPLS_ETHERNET_ADD_DEL_TUNNEL_2_REPLY, \
2279 mpls_ethernet_add_del_tunnel_2_reply) \
2280 _(SW_INTERFACE_SET_UNNUMBERED_REPLY, \
2281 sw_interface_set_unnumbered_reply) \
2282 _(IP_NEIGHBOR_ADD_DEL_REPLY, ip_neighbor_add_del_reply) \
2283 _(RESET_VRF_REPLY, reset_vrf_reply) \
2284 _(CREATE_VLAN_SUBIF_REPLY, create_vlan_subif_reply) \
2285 _(CREATE_SUBIF_REPLY, create_subif_reply) \
2286 _(OAM_ADD_DEL_REPLY, oam_add_del_reply) \
2287 _(RESET_FIB_REPLY, reset_fib_reply) \
2288 _(DHCP_PROXY_CONFIG_REPLY, dhcp_proxy_config_reply) \
2289 _(DHCP_PROXY_CONFIG_2_REPLY, dhcp_proxy_config_2_reply) \
2290 _(DHCP_PROXY_SET_VSS_REPLY, dhcp_proxy_set_vss_reply) \
2291 _(DHCP_CLIENT_CONFIG_REPLY, dhcp_client_config_reply) \
2292 _(SET_IP_FLOW_HASH_REPLY, set_ip_flow_hash_reply) \
2293 _(SW_INTERFACE_IP6_ENABLE_DISABLE_REPLY, \
2294 sw_interface_ip6_enable_disable_reply) \
2295 _(SW_INTERFACE_IP6_SET_LINK_LOCAL_ADDRESS_REPLY, \
2296 sw_interface_ip6_set_link_local_address_reply) \
2297 _(SW_INTERFACE_IP6ND_RA_PREFIX_REPLY, \
2298 sw_interface_ip6nd_ra_prefix_reply) \
2299 _(SW_INTERFACE_IP6ND_RA_CONFIG_REPLY, \
2300 sw_interface_ip6nd_ra_config_reply) \
2301 _(SET_ARP_NEIGHBOR_LIMIT_REPLY, set_arp_neighbor_limit_reply) \
2302 _(L2_PATCH_ADD_DEL_REPLY, l2_patch_add_del_reply) \
2303 _(SR_TUNNEL_ADD_DEL_REPLY, sr_tunnel_add_del_reply) \
2304 _(SR_POLICY_ADD_DEL_REPLY, sr_policy_add_del_reply) \
2305 _(SR_MULTICAST_MAP_ADD_DEL_REPLY, sr_multicast_map_add_del_reply) \
2306 _(CLASSIFY_ADD_DEL_TABLE_REPLY, classify_add_del_table_reply) \
2307 _(CLASSIFY_ADD_DEL_SESSION_REPLY, classify_add_del_session_reply) \
2308 _(CLASSIFY_SET_INTERFACE_IP_TABLE_REPLY, \
2309 classify_set_interface_ip_table_reply) \
2310 _(CLASSIFY_SET_INTERFACE_L2_TABLES_REPLY, \
2311 classify_set_interface_l2_tables_reply) \
2312 _(GET_NODE_INDEX_REPLY, get_node_index_reply) \
2313 _(ADD_NODE_NEXT_REPLY, add_node_next_reply) \
2314 _(L2TPV3_CREATE_TUNNEL_REPLY, l2tpv3_create_tunnel_reply) \
2315 _(L2TPV3_SET_TUNNEL_COOKIES_REPLY, l2tpv3_set_tunnel_cookies_reply) \
2316 _(L2TPV3_INTERFACE_ENABLE_DISABLE_REPLY, \
2317 l2tpv3_interface_enable_disable_reply) \
2318 _(L2TPV3_SET_LOOKUP_KEY_REPLY, l2tpv3_set_lookup_key_reply) \
2319 _(SW_IF_L2TPV3_TUNNEL_DETAILS, sw_if_l2tpv3_tunnel_details) \
2320 _(VXLAN_ADD_DEL_TUNNEL_REPLY, vxlan_add_del_tunnel_reply) \
2321 _(VXLAN_TUNNEL_DETAILS, vxlan_tunnel_details) \
2322 _(GRE_ADD_DEL_TUNNEL_REPLY, gre_add_del_tunnel_reply) \
2323 _(GRE_TUNNEL_DETAILS, gre_tunnel_details) \
2324 _(L2_FIB_CLEAR_TABLE_REPLY, l2_fib_clear_table_reply) \
2325 _(L2_INTERFACE_EFP_FILTER_REPLY, l2_interface_efp_filter_reply) \
2326 _(L2_INTERFACE_VLAN_TAG_REWRITE_REPLY, l2_interface_vlan_tag_rewrite_reply) \
2327 _(SW_INTERFACE_VHOST_USER_DETAILS, sw_interface_vhost_user_details) \
2328 _(CREATE_VHOST_USER_IF_REPLY, create_vhost_user_if_reply) \
2329 _(MODIFY_VHOST_USER_IF_REPLY, modify_vhost_user_if_reply) \
2330 _(DELETE_VHOST_USER_IF_REPLY, delete_vhost_user_if_reply) \
2331 _(SHOW_VERSION_REPLY, show_version_reply) \
2332 _(NSH_GRE_ADD_DEL_TUNNEL_REPLY, nsh_gre_add_del_tunnel_reply) \
2333 _(L2_FIB_TABLE_ENTRY, l2_fib_table_entry) \
2334 _(NSH_VXLAN_GPE_ADD_DEL_TUNNEL_REPLY, nsh_vxlan_gpe_add_del_tunnel_reply) \
2335 _(INTERFACE_NAME_RENUMBER_REPLY, interface_name_renumber_reply) \
2336 _(WANT_IP4_ARP_EVENTS_REPLY, want_ip4_arp_events_reply) \
2337 _(IP4_ARP_EVENT, ip4_arp_event) \
2338 _(INPUT_ACL_SET_INTERFACE_REPLY, input_acl_set_interface_reply) \
2339 _(IP_ADDRESS_DETAILS, ip_address_details) \
2340 _(IP_DETAILS, ip_details) \
2341 _(IPSEC_SPD_ADD_DEL_REPLY, ipsec_spd_add_del_reply) \
2342 _(IPSEC_INTERFACE_ADD_DEL_SPD_REPLY, ipsec_interface_add_del_spd_reply) \
2343 _(IPSEC_SPD_ADD_DEL_ENTRY_REPLY, ipsec_spd_add_del_entry_reply) \
2344 _(IPSEC_SAD_ADD_DEL_ENTRY_REPLY, ipsec_sad_add_del_entry_reply) \
2345 _(IPSEC_SA_SET_KEY_REPLY, ipsec_sa_set_key_reply) \
2346 _(IKEV2_PROFILE_ADD_DEL_REPLY, ikev2_profile_add_del_reply) \
2347 _(IKEV2_PROFILE_SET_AUTH_REPLY, ikev2_profile_set_auth_reply) \
2348 _(IKEV2_PROFILE_SET_ID_REPLY, ikev2_profile_set_id_reply) \
2349 _(IKEV2_PROFILE_SET_TS_REPLY, ikev2_profile_set_ts_reply) \
2350 _(IKEV2_SET_LOCAL_KEY_REPLY, ikev2_set_local_key_reply) \
2351 _(DELETE_LOOPBACK_REPLY, delete_loopback_reply) \
2352 _(BD_IP_MAC_ADD_DEL_REPLY, bd_ip_mac_add_del_reply) \
2353 _(DHCP_COMPL_EVENT, dhcp_compl_event) \
2354 _(VNET_INTERFACE_COUNTERS, vnet_interface_counters) \
2355 _(VNET_IP4_FIB_COUNTERS, vnet_ip4_fib_counters) \
2356 _(VNET_IP6_FIB_COUNTERS, vnet_ip6_fib_counters) \
2357 _(MAP_ADD_DOMAIN_REPLY, map_add_domain_reply) \
2358 _(MAP_DEL_DOMAIN_REPLY, map_del_domain_reply) \
2359 _(MAP_ADD_DEL_RULE_REPLY, map_add_del_rule_reply) \
2360 _(MAP_DOMAIN_DETAILS, map_domain_details) \
2361 _(MAP_RULE_DETAILS, map_rule_details) \
2362 _(WANT_INTERFACE_EVENTS_REPLY, want_interface_events_reply) \
2363 _(WANT_STATS_REPLY, want_stats_reply) \
2364 _(GET_FIRST_MSG_ID_REPLY, get_first_msg_id_reply) \
2365 _(COP_INTERFACE_ENABLE_DISABLE_REPLY, cop_interface_enable_disable_reply) \
2366 _(COP_WHITELIST_ENABLE_DISABLE_REPLY, cop_whitelist_enable_disable_reply) \
2367 _(GET_NODE_GRAPH_REPLY, get_node_graph_reply) \
2368 _(SW_INTERFACE_CLEAR_STATS_REPLY, sw_interface_clear_stats_reply) \
2369 _(TRACE_PROFILE_ADD_REPLY, trace_profile_add_reply) \
2370 _(TRACE_PROFILE_APPLY_REPLY, trace_profile_apply_reply) \
2371 _(TRACE_PROFILE_DEL_REPLY, trace_profile_del_reply) \
2372 _(LISP_ADD_DEL_LOCATOR_SET_REPLY, lisp_add_del_locator_set_reply) \
2373 _(LISP_ADD_DEL_LOCATOR_REPLY, lisp_add_del_locator_reply) \
2374 _(LISP_ADD_DEL_LOCAL_EID_REPLY, lisp_add_del_local_eid_reply) \
2375 _(LISP_GPE_ADD_DEL_FWD_ENTRY_REPLY, lisp_gpe_add_del_fwd_entry_reply) \
2376 _(LISP_ADD_DEL_MAP_RESOLVER_REPLY, lisp_add_del_map_resolver_reply) \
2377 _(LISP_GPE_ENABLE_DISABLE_REPLY, lisp_gpe_enable_disable_reply) \
2378 _(LISP_GPE_ADD_DEL_IFACE_REPLY, lisp_gpe_add_del_iface_reply) \
2379 _(LISP_LOCATOR_SET_DETAILS, lisp_locator_set_details) \
2380 _(LISP_LOCAL_EID_TABLE_DETAILS, lisp_local_eid_table_details) \
2381 _(LISP_GPE_TUNNEL_DETAILS, lisp_gpe_tunnel_details) \
2382 _(LISP_MAP_RESOLVER_DETAILS, lisp_map_resolver_details) \
2383 _(LISP_GPE_ENABLE_DISABLE_STATUS_DETAILS, \
2384 lisp_gpe_enable_disable_status_details) \
2385 _(AF_PACKET_CREATE_REPLY, af_packet_create_reply) \
2386 _(AF_PACKET_DELETE_REPLY, af_packet_delete_reply)
2388 /* M: construct, but don't yet send a message */
2392 vam->result_ready = 0; \
2393 mp = vl_msg_api_alloc(sizeof(*mp)); \
2394 memset (mp, 0, sizeof (*mp)); \
2395 mp->_vl_msg_id = ntohs (VL_API_##T); \
2396 mp->client_index = vam->my_client_index; \
2401 vam->result_ready = 0; \
2402 mp = vl_msg_api_alloc(sizeof(*mp)+(n)); \
2403 memset (mp, 0, sizeof (*mp)); \
2404 mp->_vl_msg_id = ntohs (VL_API_##T); \
2405 mp->client_index = vam->my_client_index; \
2409 /* S: send a message */
2410 #define S (vl_msg_api_send_shmem (vam->vl_input_queue, (u8 *)&mp))
2412 /* W: wait for results, with timeout */
2415 timeout = vat_time_now (vam) + 1.0; \
2417 while (vat_time_now (vam) < timeout) { \
2418 if (vam->result_ready == 1) { \
2419 return (vam->retval); \
2431 #define STR_VTR_OP_CASE(op) \
2432 case L2_VTR_ ## op: \
2435 static const char *str_vtr_op(u32 vtr_op)
2438 STR_VTR_OP_CASE(DISABLED);
2439 STR_VTR_OP_CASE(PUSH_1);
2440 STR_VTR_OP_CASE(PUSH_2);
2441 STR_VTR_OP_CASE(POP_1);
2442 STR_VTR_OP_CASE(POP_2);
2443 STR_VTR_OP_CASE(TRANSLATE_1_1);
2444 STR_VTR_OP_CASE(TRANSLATE_1_2);
2445 STR_VTR_OP_CASE(TRANSLATE_2_1);
2446 STR_VTR_OP_CASE(TRANSLATE_2_2);
2452 static int dump_sub_interface_table (vat_main_t * vam)
2454 const sw_interface_subif_t * sub = NULL;
2456 if (vam->json_output) {
2457 clib_warning ("JSON output supported only for VPE API calls and dump_stats_table");
2462 "%-30s%-12s%-11s%-7s%-5s%-9s%-9s%-6s%-8s%-10s%-10s\n",
2463 "Interface", "sw_if_index",
2464 "sub id", "dot1ad", "tags", "outer id",
2465 "inner id", "exact", "default",
2466 "outer any", "inner any");
2468 vec_foreach (sub, vam->sw_if_subif_table) {
2470 "%-30s%-12d%-11d%-7s%-5d%-9d%-9d%-6d%-8d%-10d%-10d\n",
2471 sub->interface_name,
2473 sub->sub_id, sub->sub_dot1ad ? "dot1ad" : "dot1q",
2474 sub->sub_number_of_tags, sub->sub_outer_vlan_id,
2475 sub->sub_inner_vlan_id, sub->sub_exact_match, sub->sub_default,
2476 sub->sub_outer_vlan_id_any, sub->sub_inner_vlan_id_any);
2477 if (sub->vtr_op != L2_VTR_DISABLED) {
2479 " vlan-tag-rewrite - op: %-14s [ dot1q: %d "
2480 "tag1: %d tag2: %d ]\n",
2481 str_vtr_op(sub->vtr_op), sub->vtr_push_dot1q,
2482 sub->vtr_tag1, sub->vtr_tag2);
2489 static int name_sort_cmp (void * a1, void * a2)
2491 name_sort_t * n1 = a1;
2492 name_sort_t * n2 = a2;
2494 return strcmp ((char *)n1->name, (char *)n2->name);
2497 static int dump_interface_table (vat_main_t * vam)
2500 name_sort_t * nses = 0, * ns;
2502 if (vam->json_output) {
2503 clib_warning ("JSON output supported only for VPE API calls and dump_stats_table");
2507 hash_foreach_pair (p, vam->sw_if_index_by_interface_name,
2509 vec_add2 (nses, ns, 1);
2510 ns->name = (u8 *)(p->key);
2511 ns->value = (u32) p->value[0];
2514 vec_sort_with_function (nses, name_sort_cmp);
2516 fformat (vam->ofp, "%-25s%-15s\n", "Interface", "sw_if_index");
2517 vec_foreach (ns, nses) {
2518 fformat (vam->ofp, "%-25s%-15d\n", ns->name, ns->value);
2524 static int dump_ip_table (vat_main_t * vam, int is_ipv6)
2526 const ip_details_t * det = NULL;
2527 const ip_address_details_t * address = NULL;
2538 vec_foreach (det, vam->ip_details_by_sw_if_index[is_ipv6]) {
2540 if (!det->present) {
2548 "Address", "Prefix length");
2552 vec_foreach (address, det->addr) {
2555 is_ipv6 ? format_ip6_address : format_ip4_address,
2557 address->prefix_length);
2564 static int dump_ipv4_table (vat_main_t * vam)
2566 if (vam->json_output) {
2567 clib_warning ("JSON output supported only for VPE API calls and dump_stats_table");
2571 return dump_ip_table (vam, 0);
2574 static int dump_ipv6_table (vat_main_t * vam)
2576 if (vam->json_output) {
2577 clib_warning ("JSON output supported only for VPE API calls and dump_stats_table");
2581 return dump_ip_table (vam, 1);
2584 static char* counter_type_to_str (u8 counter_type, u8 is_combined)
2587 switch(counter_type) {
2588 case VNET_INTERFACE_COUNTER_DROP:
2590 case VNET_INTERFACE_COUNTER_PUNT:
2592 case VNET_INTERFACE_COUNTER_IP4:
2594 case VNET_INTERFACE_COUNTER_IP6:
2596 case VNET_INTERFACE_COUNTER_RX_NO_BUF:
2598 case VNET_INTERFACE_COUNTER_RX_MISS:
2600 case VNET_INTERFACE_COUNTER_RX_ERROR:
2602 case VNET_INTERFACE_COUNTER_TX_ERROR:
2605 return "INVALID-COUNTER-TYPE";
2608 switch(counter_type) {
2609 case VNET_INTERFACE_COUNTER_RX:
2611 case VNET_INTERFACE_COUNTER_TX:
2614 return "INVALID-COUNTER-TYPE";
2619 static int dump_stats_table (vat_main_t * vam)
2621 vat_json_node_t node;
2622 vat_json_node_t *msg_array;
2623 vat_json_node_t *msg;
2624 vat_json_node_t *counter_array;
2625 vat_json_node_t *counter;
2626 interface_counter_t c;
2628 ip4_fib_counter_t *c4;
2629 ip6_fib_counter_t *c6;
2632 if (!vam->json_output) {
2633 clib_warning ("dump_stats_table supported only in JSON format");
2637 vat_json_init_object(&node);
2639 /* interface counters */
2640 msg_array = vat_json_object_add(&node, "interface_counters");
2641 vat_json_init_array(msg_array);
2642 for (i = 0; i < vec_len(vam->simple_interface_counters); i++) {
2643 msg = vat_json_array_add(msg_array);
2644 vat_json_init_object(msg);
2645 vat_json_object_add_string_copy(msg, "vnet_counter_type",
2646 (u8*)counter_type_to_str(i, 0));
2647 vat_json_object_add_int(msg, "is_combined", 0);
2648 counter_array = vat_json_object_add(msg, "data");
2649 vat_json_init_array(counter_array);
2650 for (j = 0; j < vec_len(vam->simple_interface_counters[i]); j++) {
2651 packets = vam->simple_interface_counters[i][j];
2652 vat_json_array_add_uint(counter_array, packets);
2655 for (i = 0; i < vec_len(vam->combined_interface_counters); i++) {
2656 msg = vat_json_array_add(msg_array);
2657 vat_json_init_object(msg);
2658 vat_json_object_add_string_copy(msg, "vnet_counter_type",
2659 (u8*)counter_type_to_str(i, 1));
2660 vat_json_object_add_int(msg, "is_combined", 1);
2661 counter_array = vat_json_object_add(msg, "data");
2662 vat_json_init_array(counter_array);
2663 for (j = 0; j < vec_len(vam->combined_interface_counters[i]); j++) {
2664 c = vam->combined_interface_counters[i][j];
2665 counter = vat_json_array_add(counter_array);
2666 vat_json_init_object(counter);
2667 vat_json_object_add_uint(counter, "packets", c.packets);
2668 vat_json_object_add_uint(counter, "bytes", c.bytes);
2672 /* ip4 fib counters */
2673 msg_array = vat_json_object_add(&node, "ip4_fib_counters");
2674 vat_json_init_array(msg_array);
2675 for (i = 0; i < vec_len(vam->ip4_fib_counters); i++) {
2676 msg = vat_json_array_add(msg_array);
2677 vat_json_init_object(msg);
2678 vat_json_object_add_uint(msg, "vrf_id", vam->ip4_fib_counters_vrf_id_by_index[i]);
2679 counter_array = vat_json_object_add(msg, "c");
2680 vat_json_init_array(counter_array);
2681 for (j = 0; j < vec_len(vam->ip4_fib_counters[i]); j++) {
2682 counter = vat_json_array_add(counter_array);
2683 vat_json_init_object(counter);
2684 c4 = &vam->ip4_fib_counters[i][j];
2685 vat_json_object_add_ip4(counter, "address", c4->address);
2686 vat_json_object_add_uint(counter, "address_length", c4->address_length);
2687 vat_json_object_add_uint(counter, "packets", c4->packets);
2688 vat_json_object_add_uint(counter, "bytes", c4->bytes);
2692 /* ip6 fib counters */
2693 msg_array = vat_json_object_add(&node, "ip6_fib_counters");
2694 vat_json_init_array(msg_array);
2695 for (i = 0; i < vec_len(vam->ip6_fib_counters); i++) {
2696 msg = vat_json_array_add(msg_array);
2697 vat_json_init_object(msg);
2698 vat_json_object_add_uint(msg, "vrf_id", vam->ip6_fib_counters_vrf_id_by_index[i]);
2699 counter_array = vat_json_object_add(msg, "c");
2700 vat_json_init_array(counter_array);
2701 for (j = 0; j < vec_len(vam->ip6_fib_counters[i]); j++) {
2702 counter = vat_json_array_add(counter_array);
2703 vat_json_init_object(counter);
2704 c6 = &vam->ip6_fib_counters[i][j];
2705 vat_json_object_add_ip6(counter, "address", c6->address);
2706 vat_json_object_add_uint(counter, "address_length", c6->address_length);
2707 vat_json_object_add_uint(counter, "packets", c6->packets);
2708 vat_json_object_add_uint(counter, "bytes", c6->bytes);
2712 vat_json_print(vam->ofp, &node);
2713 vat_json_free(&node);
2718 int exec (vat_main_t * vam)
2720 api_main_t * am = &api_main;
2721 vl_api_cli_request_t *mp;
2725 unformat_input_t * i = vam->input;
2727 if (vec_len(i->buffer) == 0)
2730 if (vam->exec_mode == 0 && unformat (i, "mode")) {
2734 if (vam->exec_mode == 1 &&
2735 (unformat (i, "exit") || unformat (i, "quit"))) {
2741 M(CLI_REQUEST, cli_request);
2744 * Copy cmd into shared memory.
2745 * In order for the CLI command to work, it
2746 * must be a vector ending in \n, not a C-string ending
2749 pthread_mutex_lock (&am->vlib_rp->mutex);
2750 oldheap = svm_push_data_heap (am->vlib_rp);
2752 vec_validate (cmd, vec_len(vam->input->buffer)-1);
2753 clib_memcpy (cmd, vam->input->buffer, vec_len(vam->input->buffer));
2755 svm_pop_heap (oldheap);
2756 pthread_mutex_unlock (&am->vlib_rp->mutex);
2758 mp->cmd_in_shmem = (u64) cmd;
2760 timeout = vat_time_now (vam) + 10.0;
2762 while (vat_time_now (vam) < timeout) {
2763 if (vam->result_ready == 1) {
2765 if (vam->shmem_result != NULL)
2766 fformat (vam->ofp, "%s", vam->shmem_result);
2767 pthread_mutex_lock (&am->vlib_rp->mutex);
2768 oldheap = svm_push_data_heap (am->vlib_rp);
2770 free_me = (u8 *)vam->shmem_result;
2773 svm_pop_heap (oldheap);
2774 pthread_mutex_unlock (&am->vlib_rp->mutex);
2781 static int api_create_loopback (vat_main_t * vam)
2783 unformat_input_t * i = vam->input;
2784 vl_api_create_loopback_t *mp;
2789 memset (mac_address, 0, sizeof (mac_address));
2791 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
2793 if (unformat (i, "mac %U", unformat_ethernet_address, mac_address))
2799 /* Construct the API message */
2800 M(CREATE_LOOPBACK, create_loopback);
2802 clib_memcpy (mp->mac_address, mac_address, sizeof (mac_address));
2807 static int api_delete_loopback (vat_main_t * vam)
2809 unformat_input_t * i = vam->input;
2810 vl_api_delete_loopback_t *mp;
2812 u32 sw_if_index = ~0;
2814 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
2816 if (unformat (i, "sw_if_index %d", &sw_if_index))
2822 if (sw_if_index == ~0)
2824 errmsg ("missing sw_if_index\n");
2828 /* Construct the API message */
2829 M(DELETE_LOOPBACK, delete_loopback);
2830 mp->sw_if_index = ntohl (sw_if_index);
2835 static int api_want_stats (vat_main_t * vam)
2837 unformat_input_t * i = vam->input;
2838 vl_api_want_stats_t * mp;
2842 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
2844 if (unformat (i, "enable"))
2846 else if (unformat (i, "disable"))
2854 errmsg ("missing enable|disable\n");
2858 M(WANT_STATS, want_stats);
2859 mp->enable_disable = enable;
2864 static int api_want_interface_events (vat_main_t * vam)
2866 unformat_input_t * i = vam->input;
2867 vl_api_want_interface_events_t * mp;
2871 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
2873 if (unformat (i, "enable"))
2875 else if (unformat (i, "disable"))
2883 errmsg ("missing enable|disable\n");
2887 M(WANT_INTERFACE_EVENTS, want_interface_events);
2888 mp->enable_disable = enable;
2890 vam->interface_event_display = enable;
2896 /* Note: non-static, called once to set up the initial intfc table */
2897 int api_sw_interface_dump (vat_main_t * vam)
2899 vl_api_sw_interface_dump_t *mp;
2902 name_sort_t * nses = 0, * ns;
2903 sw_interface_subif_t * sub = NULL;
2905 /* Toss the old name table */
2906 hash_foreach_pair (p, vam->sw_if_index_by_interface_name,
2908 vec_add2 (nses, ns, 1);
2909 ns->name = (u8 *)(p->key);
2910 ns->value = (u32) p->value[0];
2913 hash_free (vam->sw_if_index_by_interface_name);
2915 vec_foreach (ns, nses)
2916 vec_free (ns->name);
2920 vec_foreach (sub, vam->sw_if_subif_table) {
2921 vec_free (sub->interface_name);
2923 vec_free (vam->sw_if_subif_table);
2925 /* recreate the interface name hash table */
2926 vam->sw_if_index_by_interface_name
2927 = hash_create_string (0, sizeof(uword));
2929 /* Get list of ethernets */
2930 M(SW_INTERFACE_DUMP, sw_interface_dump);
2931 mp->name_filter_valid = 1;
2932 strncpy ((char *) mp->name_filter, "Ether", sizeof(mp->name_filter)-1);
2935 /* and local / loopback interfaces */
2936 M(SW_INTERFACE_DUMP, sw_interface_dump);
2937 mp->name_filter_valid = 1;
2938 strncpy ((char *) mp->name_filter, "lo", sizeof(mp->name_filter)-1);
2941 /* and vxlan tunnel interfaces */
2942 M(SW_INTERFACE_DUMP, sw_interface_dump);
2943 mp->name_filter_valid = 1;
2944 strncpy ((char *) mp->name_filter, "vxlan", sizeof(mp->name_filter)-1);
2947 /* and host (af_packet) interfaces */
2948 M(SW_INTERFACE_DUMP, sw_interface_dump);
2949 mp->name_filter_valid = 1;
2950 strncpy ((char *) mp->name_filter, "host", sizeof(mp->name_filter)-1);
2953 /* and l2tpv3 tunnel interfaces */
2954 M(SW_INTERFACE_DUMP, sw_interface_dump);
2955 mp->name_filter_valid = 1;
2956 strncpy ((char *) mp->name_filter, "l2tpv3_tunnel", sizeof(mp->name_filter)-1);
2959 /* and GRE tunnel interfaces */
2960 M(SW_INTERFACE_DUMP, sw_interface_dump);
2961 mp->name_filter_valid = 1;
2962 strncpy ((char *) mp->name_filter, "gre", sizeof(mp->name_filter)-1);
2965 /* Use a control ping for synchronization */
2967 vl_api_control_ping_t * mp;
2968 M(CONTROL_PING, control_ping);
2974 static int api_sw_interface_set_flags (vat_main_t * vam)
2976 unformat_input_t * i = vam->input;
2977 vl_api_sw_interface_set_flags_t *mp;
2980 u8 sw_if_index_set = 0;
2981 u8 admin_up = 0, link_up = 0;
2983 /* Parse args required to build the message */
2984 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
2985 if (unformat (i, "admin-up"))
2987 else if (unformat (i, "admin-down"))
2989 else if (unformat (i, "link-up"))
2991 else if (unformat (i, "link-down"))
2993 else if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
2994 sw_if_index_set = 1;
2995 else if (unformat (i, "sw_if_index %d", &sw_if_index))
2996 sw_if_index_set = 1;
3001 if (sw_if_index_set == 0) {
3002 errmsg ("missing interface name or sw_if_index\n");
3006 /* Construct the API message */
3007 M(SW_INTERFACE_SET_FLAGS, sw_interface_set_flags);
3008 mp->sw_if_index = ntohl (sw_if_index);
3009 mp->admin_up_down = admin_up;
3010 mp->link_up_down = link_up;
3015 /* Wait for a reply, return the good/bad news... */
3019 static int api_sw_interface_clear_stats (vat_main_t * vam)
3021 unformat_input_t * i = vam->input;
3022 vl_api_sw_interface_clear_stats_t *mp;
3025 u8 sw_if_index_set = 0;
3027 /* Parse args required to build the message */
3028 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
3029 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
3030 sw_if_index_set = 1;
3031 else if (unformat (i, "sw_if_index %d", &sw_if_index))
3032 sw_if_index_set = 1;
3037 /* Construct the API message */
3038 M(SW_INTERFACE_CLEAR_STATS, sw_interface_clear_stats);
3040 if (sw_if_index_set == 1)
3041 mp->sw_if_index = ntohl (sw_if_index);
3043 mp->sw_if_index = ~0;
3048 /* Wait for a reply, return the good/bad news... */
3052 static int api_sw_interface_add_del_address (vat_main_t * vam)
3054 unformat_input_t * i = vam->input;
3055 vl_api_sw_interface_add_del_address_t *mp;
3058 u8 sw_if_index_set = 0;
3059 u8 is_add = 1, del_all = 0;
3060 u32 address_length = 0;
3061 u8 v4_address_set = 0;
3062 u8 v6_address_set = 0;
3063 ip4_address_t v4address;
3064 ip6_address_t v6address;
3066 /* Parse args required to build the message */
3067 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
3068 if (unformat (i, "del-all"))
3070 else if (unformat (i, "del"))
3072 else if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
3073 sw_if_index_set = 1;
3074 else if (unformat (i, "sw_if_index %d", &sw_if_index))
3075 sw_if_index_set = 1;
3076 else if (unformat (i, "%U/%d",
3077 unformat_ip4_address, &v4address,
3080 else if (unformat (i, "%U/%d",
3081 unformat_ip6_address, &v6address,
3088 if (sw_if_index_set == 0) {
3089 errmsg ("missing interface name or sw_if_index\n");
3092 if (v4_address_set && v6_address_set) {
3093 errmsg ("both v4 and v6 addresses set\n");
3096 if (!v4_address_set && !v6_address_set && !del_all) {
3097 errmsg ("no addresses set\n");
3101 /* Construct the API message */
3102 M(SW_INTERFACE_ADD_DEL_ADDRESS, sw_interface_add_del_address);
3104 mp->sw_if_index = ntohl (sw_if_index);
3105 mp->is_add = is_add;
3106 mp->del_all = del_all;
3107 if (v6_address_set) {
3109 clib_memcpy (mp->address, &v6address, sizeof (v6address));
3111 clib_memcpy (mp->address, &v4address, sizeof (v4address));
3113 mp->address_length = address_length;
3118 /* Wait for a reply, return good/bad news */
3122 static int api_sw_interface_set_table (vat_main_t * vam)
3124 unformat_input_t * i = vam->input;
3125 vl_api_sw_interface_set_table_t *mp;
3127 u32 sw_if_index, vrf_id = 0;
3128 u8 sw_if_index_set = 0;
3131 /* Parse args required to build the message */
3132 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
3133 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
3134 sw_if_index_set = 1;
3135 else if (unformat (i, "sw_if_index %d", &sw_if_index))
3136 sw_if_index_set = 1;
3137 else if (unformat (i, "vrf %d", &vrf_id))
3139 else if (unformat (i, "ipv6"))
3145 if (sw_if_index_set == 0) {
3146 errmsg ("missing interface name or sw_if_index\n");
3150 /* Construct the API message */
3151 M(SW_INTERFACE_SET_TABLE, sw_interface_set_table);
3153 mp->sw_if_index = ntohl (sw_if_index);
3154 mp->is_ipv6 = is_ipv6;
3155 mp->vrf_id = ntohl (vrf_id);
3160 /* Wait for a reply... */
3164 static int api_sw_interface_set_vpath (vat_main_t * vam)
3166 unformat_input_t * i = vam->input;
3167 vl_api_sw_interface_set_vpath_t *mp;
3169 u32 sw_if_index = 0;
3170 u8 sw_if_index_set = 0;
3173 /* Parse args required to build the message */
3174 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
3175 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
3176 sw_if_index_set = 1;
3177 else if (unformat (i, "sw_if_index %d", &sw_if_index))
3178 sw_if_index_set = 1;
3179 else if (unformat (i, "enable"))
3181 else if (unformat (i, "disable"))
3187 if (sw_if_index_set == 0) {
3188 errmsg ("missing interface name or sw_if_index\n");
3192 /* Construct the API message */
3193 M(SW_INTERFACE_SET_VPATH, sw_interface_set_vpath);
3195 mp->sw_if_index = ntohl (sw_if_index);
3196 mp->enable = is_enable;
3201 /* Wait for a reply... */
3205 static int api_sw_interface_set_l2_xconnect (vat_main_t * vam)
3207 unformat_input_t * i = vam->input;
3208 vl_api_sw_interface_set_l2_xconnect_t *mp;
3211 u8 rx_sw_if_index_set = 0;
3213 u8 tx_sw_if_index_set = 0;
3216 /* Parse args required to build the message */
3217 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
3218 if (unformat (i, "rx_sw_if_index %d", &rx_sw_if_index))
3219 rx_sw_if_index_set = 1;
3220 else if (unformat (i, "tx_sw_if_index %d", &tx_sw_if_index))
3221 tx_sw_if_index_set = 1;
3222 else if (unformat (i, "rx")) {
3223 if (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
3224 if (unformat (i, "%U", unformat_sw_if_index, vam,
3226 rx_sw_if_index_set = 1;
3229 } else if (unformat (i, "tx")) {
3230 if (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
3231 if (unformat (i, "%U", unformat_sw_if_index, vam,
3233 tx_sw_if_index_set = 1;
3236 } else if (unformat (i, "enable"))
3238 else if (unformat (i, "disable"))
3244 if (rx_sw_if_index_set == 0) {
3245 errmsg ("missing rx interface name or rx_sw_if_index\n");
3249 if (enable && (tx_sw_if_index_set == 0)) {
3250 errmsg ("missing tx interface name or tx_sw_if_index\n");
3254 M(SW_INTERFACE_SET_L2_XCONNECT, sw_interface_set_l2_xconnect);
3256 mp->rx_sw_if_index = ntohl(rx_sw_if_index);
3257 mp->tx_sw_if_index = ntohl(tx_sw_if_index);
3258 mp->enable = enable;
3265 static int api_sw_interface_set_l2_bridge (vat_main_t * vam)
3267 unformat_input_t * i = vam->input;
3268 vl_api_sw_interface_set_l2_bridge_t *mp;
3271 u8 rx_sw_if_index_set = 0;
3278 /* Parse args required to build the message */
3279 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
3280 if (unformat (i, "sw_if_index %d", &rx_sw_if_index))
3281 rx_sw_if_index_set = 1;
3282 else if (unformat (i, "bd_id %d", &bd_id))
3284 else if (unformat (i, "%U", unformat_sw_if_index, vam,
3286 rx_sw_if_index_set = 1;
3287 else if (unformat (i, "shg %d", &shg))
3289 else if (unformat (i, "bvi"))
3291 else if (unformat (i, "enable"))
3293 else if (unformat (i, "disable"))
3299 if (rx_sw_if_index_set == 0) {
3300 errmsg ("missing rx interface name or sw_if_index\n");
3304 if (enable && (bd_id_set == 0)) {
3305 errmsg ("missing bridge domain\n");
3309 M(SW_INTERFACE_SET_L2_BRIDGE, sw_interface_set_l2_bridge);
3311 mp->rx_sw_if_index = ntohl(rx_sw_if_index);
3312 mp->bd_id = ntohl(bd_id);
3315 mp->enable = enable;
3322 static int api_bridge_domain_dump (vat_main_t * vam)
3324 unformat_input_t * i = vam->input;
3325 vl_api_bridge_domain_dump_t *mp;
3329 /* Parse args required to build the message */
3330 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
3331 if (unformat (i, "bd_id %d", &bd_id))
3337 M(BRIDGE_DOMAIN_DUMP, bridge_domain_dump);
3338 mp->bd_id = ntohl(bd_id);
3341 /* Use a control ping for synchronization */
3343 vl_api_control_ping_t * mp;
3344 M(CONTROL_PING, control_ping);
3353 static int api_bridge_domain_add_del (vat_main_t * vam)
3355 unformat_input_t * i = vam->input;
3356 vl_api_bridge_domain_add_del_t *mp;
3360 u32 flood = 1, forward = 1, learn = 1, uu_flood = 1, arp_term = 0;
3362 /* Parse args required to build the message */
3363 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
3364 if (unformat (i, "bd_id %d", &bd_id))
3366 else if (unformat (i, "flood %d", &flood))
3368 else if (unformat (i, "uu-flood %d", &uu_flood))
3370 else if (unformat (i, "forward %d", &forward))
3372 else if (unformat (i, "learn %d", &learn))
3374 else if (unformat (i, "arp-term %d", &arp_term))
3376 else if (unformat (i, "del")) {
3378 flood = uu_flood = forward = learn = 0;
3385 errmsg ("missing bridge domain\n");
3389 M(BRIDGE_DOMAIN_ADD_DEL, bridge_domain_add_del);
3391 mp->bd_id = ntohl(bd_id);
3393 mp->uu_flood = uu_flood;
3394 mp->forward = forward;
3396 mp->arp_term = arp_term;
3397 mp->is_add = is_add;
3404 static int api_l2fib_add_del (vat_main_t * vam)
3406 unformat_input_t * i = vam->input;
3407 vl_api_l2fib_add_del_t *mp;
3414 u8 sw_if_index_set = 0;
3419 /* Parse args required to build the message */
3420 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
3421 if (unformat (i, "mac %U", unformat_ethernet_address, &mac))
3423 else if (unformat (i, "bd_id %d", &bd_id))
3425 else if (unformat (i, "sw_if_index %d", &sw_if_index))
3426 sw_if_index_set = 1;
3427 else if (unformat (i, "sw_if")) {
3428 if (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
3429 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
3430 sw_if_index_set = 1;
3433 } else if (unformat (i, "static"))
3435 else if (unformat (i, "filter")) {
3438 } else if (unformat (i, "del"))
3445 errmsg ("missing mac address\n");
3449 if (bd_id_set == 0) {
3450 errmsg ("missing bridge domain\n");
3454 if (is_add && (sw_if_index_set == 0)) {
3455 errmsg ("missing interface name or sw_if_index\n");
3459 M(L2FIB_ADD_DEL, l2fib_add_del);
3462 mp->bd_id = ntohl(bd_id);
3463 mp->is_add = is_add;
3466 mp->sw_if_index = ntohl(sw_if_index);
3467 mp->static_mac = static_mac;
3468 mp->filter_mac = filter_mac;
3476 static int api_l2_flags (vat_main_t * vam)
3478 unformat_input_t * i = vam->input;
3479 vl_api_l2_flags_t *mp;
3482 u32 feature_bitmap = 0;
3483 u8 sw_if_index_set = 0;
3485 /* Parse args required to build the message */
3486 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
3487 if (unformat (i, "sw_if_index %d", &sw_if_index))
3488 sw_if_index_set = 1;
3489 else if (unformat (i, "sw_if")) {
3490 if (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
3491 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
3492 sw_if_index_set = 1;
3495 } else if (unformat (i, "learn"))
3496 feature_bitmap |= L2INPUT_FEAT_LEARN;
3497 else if (unformat (i, "forward"))
3498 feature_bitmap |= L2INPUT_FEAT_FWD;
3499 else if (unformat (i, "flood"))
3500 feature_bitmap |= L2INPUT_FEAT_FLOOD;
3501 else if (unformat (i, "uu-flood"))
3502 feature_bitmap |= L2INPUT_FEAT_UU_FLOOD;
3507 if (sw_if_index_set == 0) {
3508 errmsg ("missing interface name or sw_if_index\n");
3512 M(L2_FLAGS, l2_flags);
3514 mp->sw_if_index = ntohl(sw_if_index);
3515 mp->feature_bitmap = ntohl(feature_bitmap);
3522 static int api_bridge_flags (vat_main_t * vam)
3524 unformat_input_t * i = vam->input;
3525 vl_api_bridge_flags_t *mp;
3532 /* Parse args required to build the message */
3533 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
3534 if (unformat (i, "bd_id %d", &bd_id))
3536 else if (unformat (i, "learn"))
3538 else if (unformat (i, "forward"))
3540 else if (unformat (i, "flood"))
3542 else if (unformat (i, "uu-flood"))
3543 flags |= L2_UU_FLOOD;
3544 else if (unformat (i, "arp-term"))
3545 flags |= L2_ARP_TERM;
3546 else if (unformat (i, "off"))
3548 else if (unformat (i, "disable"))
3554 if (bd_id_set == 0) {
3555 errmsg ("missing bridge domain\n");
3559 M(BRIDGE_FLAGS, bridge_flags);
3561 mp->bd_id = ntohl(bd_id);
3562 mp->feature_bitmap = ntohl(flags);
3563 mp->is_set = is_set;
3570 static int api_bd_ip_mac_add_del (vat_main_t * vam)
3572 unformat_input_t * i = vam->input;
3573 vl_api_bd_ip_mac_add_del_t *mp;
3581 ip4_address_t v4addr;
3582 ip6_address_t v6addr;
3586 /* Parse args required to build the message */
3587 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
3588 if (unformat (i, "bd_id %d", &bd_id)) {
3590 } else if (unformat (i, "%U", unformat_ip4_address, &v4addr)) {
3592 } else if (unformat (i, "%U", unformat_ip6_address, &v6addr)) {
3595 } else if (unformat (i, "%U", unformat_ethernet_address, macaddr)) {
3597 } else if (unformat (i, "del"))
3603 if (bd_id_set == 0) {
3604 errmsg ("missing bridge domain\n");
3606 } else if (ip_set == 0) {
3607 errmsg ("missing IP address\n");
3609 } else if (mac_set == 0) {
3610 errmsg ("missing MAC address\n");
3614 M(BD_IP_MAC_ADD_DEL, bd_ip_mac_add_del);
3616 mp->bd_id = ntohl(bd_id);
3617 mp->is_ipv6 = is_ipv6;
3618 mp->is_add = is_add;
3620 clib_memcpy (mp->ip_address, &v6addr, sizeof (v6addr));
3621 else clib_memcpy (mp->ip_address, &v4addr, sizeof (v4addr));
3622 clib_memcpy (mp->mac_address, macaddr, 6);
3628 static int api_tap_connect (vat_main_t * vam)
3630 unformat_input_t * i = vam->input;
3631 vl_api_tap_connect_t *mp;
3638 memset (mac_address, 0, sizeof (mac_address));
3640 /* Parse args required to build the message */
3641 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
3642 if (unformat (i, "mac %U", unformat_ethernet_address, mac_address)) {
3645 else if (unformat (i, "random-mac"))
3647 else if (unformat (i, "tapname %s", &tap_name))
3653 if (name_set == 0) {
3654 errmsg ("missing tap name\n");
3657 if (vec_len (tap_name) > 63) {
3658 errmsg ("tap name too long\n");
3660 vec_add1 (tap_name, 0);
3662 /* Construct the API message */
3663 M(TAP_CONNECT, tap_connect);
3665 mp->use_random_mac = random_mac;
3666 clib_memcpy (mp->mac_address, mac_address, 6);
3667 clib_memcpy (mp->tap_name, tap_name, vec_len (tap_name));
3668 vec_free (tap_name);
3673 /* Wait for a reply... */
3677 static int api_tap_modify (vat_main_t * vam)
3679 unformat_input_t * i = vam->input;
3680 vl_api_tap_modify_t *mp;
3686 u32 sw_if_index = ~0;
3687 u8 sw_if_index_set = 0;
3689 memset (mac_address, 0, sizeof (mac_address));
3691 /* Parse args required to build the message */
3692 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
3693 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
3694 sw_if_index_set = 1;
3695 else if (unformat (i, "sw_if_index %d", &sw_if_index))
3696 sw_if_index_set = 1;
3697 else if (unformat (i, "mac %U", unformat_ethernet_address, mac_address)) {
3700 else if (unformat (i, "random-mac"))
3702 else if (unformat (i, "tapname %s", &tap_name))
3708 if (sw_if_index_set == 0) {
3709 errmsg ("missing vpp interface name");
3712 if (name_set == 0) {
3713 errmsg ("missing tap name\n");
3716 if (vec_len (tap_name) > 63) {
3717 errmsg ("tap name too long\n");
3719 vec_add1 (tap_name, 0);
3721 /* Construct the API message */
3722 M(TAP_MODIFY, tap_modify);
3724 mp->use_random_mac = random_mac;
3725 mp->sw_if_index = ntohl(sw_if_index);
3726 clib_memcpy (mp->mac_address, mac_address, 6);
3727 clib_memcpy (mp->tap_name, tap_name, vec_len (tap_name));
3728 vec_free (tap_name);
3733 /* Wait for a reply... */
3737 static int api_tap_delete (vat_main_t * vam)
3739 unformat_input_t * i = vam->input;
3740 vl_api_tap_delete_t *mp;
3742 u32 sw_if_index = ~0;
3743 u8 sw_if_index_set = 0;
3745 /* Parse args required to build the message */
3746 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
3747 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
3748 sw_if_index_set = 1;
3749 else if (unformat (i, "sw_if_index %d", &sw_if_index))
3750 sw_if_index_set = 1;
3755 if (sw_if_index_set == 0) {
3756 errmsg ("missing vpp interface name");
3760 /* Construct the API message */
3761 M(TAP_DELETE, tap_delete);
3763 mp->sw_if_index = ntohl(sw_if_index);
3768 /* Wait for a reply... */
3772 static int api_ip_add_del_route (vat_main_t * vam)
3774 unformat_input_t * i = vam->input;
3775 vl_api_ip_add_del_route_t *mp;
3777 u32 sw_if_index = 0, vrf_id = 0;
3778 u8 sw_if_index_set = 0;
3780 u8 is_local = 0, is_drop = 0;
3781 u8 create_vrf_if_needed = 0;
3783 u8 next_hop_weight = 1;
3785 u8 is_multipath = 0;
3787 u8 address_length_set = 0;
3788 u32 lookup_in_vrf = 0;
3789 u32 resolve_attempts = 0;
3790 u32 dst_address_length = 0;
3791 u8 next_hop_set = 0;
3792 ip4_address_t v4_dst_address, v4_next_hop_address;
3793 ip6_address_t v6_dst_address, v6_next_hop_address;
3797 u32 random_add_del = 0;
3798 u32 * random_vector = 0;
3799 uword * random_hash;
3800 u32 random_seed = 0xdeaddabe;
3801 u32 classify_table_index = ~0;
3804 /* Parse args required to build the message */
3805 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
3806 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
3807 sw_if_index_set = 1;
3808 else if (unformat (i, "sw_if_index %d", &sw_if_index))
3809 sw_if_index_set = 1;
3810 else if (unformat (i, "%U", unformat_ip4_address,
3815 else if (unformat (i, "%U", unformat_ip6_address, &v6_dst_address)) {
3819 else if (unformat (i, "/%d", &dst_address_length)) {
3820 address_length_set = 1;
3823 else if (is_ipv6 == 0 && unformat (i, "via %U", unformat_ip4_address,
3824 &v4_next_hop_address)) {
3827 else if (is_ipv6 == 1 && unformat (i, "via %U", unformat_ip6_address,
3828 &v6_next_hop_address)) {
3831 else if (unformat (i, "resolve-attempts %d", &resolve_attempts))
3833 else if (unformat (i, "weight %d", &next_hop_weight))
3835 else if (unformat (i, "drop")) {
3837 } else if (unformat (i, "local")) {
3839 } else if (unformat (i, "classify %d", &classify_table_index)) {
3841 } else if (unformat (i, "del"))
3843 else if (unformat (i, "add"))
3845 else if (unformat (i, "not-last"))
3847 else if (unformat (i, "multipath"))
3849 else if (unformat (i, "vrf %d", &vrf_id))
3851 else if (unformat (i, "create-vrf"))
3852 create_vrf_if_needed = 1;
3853 else if (unformat (i, "count %d", &count))
3855 else if (unformat (i, "lookup-in-vrf %d", &lookup_in_vrf))
3857 else if (unformat (i, "random"))
3859 else if (unformat (i, "seed %d", &random_seed))
3862 clib_warning ("parse error '%U'", format_unformat_error, i);
3867 if (resolve_attempts > 0 && sw_if_index_set == 0) {
3868 errmsg ("ARP resolution needs explicit interface or sw_if_index\n");
3872 if (!next_hop_set && !is_drop && !is_local && !is_classify) {
3873 errmsg ("next hop / local / drop / classify not set\n");
3877 if (address_set == 0) {
3878 errmsg ("missing addresses\n");
3882 if (address_length_set == 0) {
3883 errmsg ("missing address length\n");
3887 /* Generate a pile of unique, random routes */
3888 if (random_add_del) {
3889 u32 this_random_address;
3890 random_hash = hash_create (count, sizeof(uword));
3892 hash_set (random_hash, v4_next_hop_address.as_u32, 1);
3893 for (j = 0; j <= count; j++) {
3895 this_random_address = random_u32 (&random_seed);
3896 this_random_address =
3897 clib_host_to_net_u32 (this_random_address);
3898 } while (hash_get (random_hash, this_random_address));
3899 vec_add1 (random_vector, this_random_address);
3900 hash_set (random_hash, this_random_address, 1);
3902 hash_free (random_hash);
3903 v4_dst_address.as_u32 = random_vector[0];
3907 /* Turn on async mode */
3908 vam->async_mode = 1;
3909 vam->async_errors = 0;
3910 before = vat_time_now(vam);
3913 for (j = 0; j < count; j++) {
3914 /* Construct the API message */
3915 M(IP_ADD_DEL_ROUTE, ip_add_del_route);
3917 mp->next_hop_sw_if_index = ntohl (sw_if_index);
3918 mp->vrf_id = ntohl (vrf_id);
3919 if (resolve_attempts > 0) {
3920 mp->resolve_attempts = ntohl (resolve_attempts);
3921 mp->resolve_if_needed = 1;
3923 mp->create_vrf_if_needed = create_vrf_if_needed;
3925 mp->is_add = is_add;
3926 mp->is_drop = is_drop;
3927 mp->is_ipv6 = is_ipv6;
3928 mp->is_local = is_local;
3929 mp->is_classify = is_classify;
3930 mp->is_multipath = is_multipath;
3931 mp->not_last = not_last;
3932 mp->next_hop_weight = next_hop_weight;
3933 mp->dst_address_length = dst_address_length;
3934 mp->lookup_in_vrf = ntohl(lookup_in_vrf);
3935 mp->classify_table_index = ntohl(classify_table_index);
3938 clib_memcpy (mp->dst_address, &v6_dst_address, sizeof (v6_dst_address));
3940 clib_memcpy (mp->next_hop_address, &v6_next_hop_address,
3941 sizeof (v6_next_hop_address));
3942 increment_v6_address (&v6_dst_address);
3944 clib_memcpy (mp->dst_address, &v4_dst_address, sizeof (v4_dst_address));
3946 clib_memcpy (mp->next_hop_address, &v4_next_hop_address,
3947 sizeof (v4_next_hop_address));
3949 v4_dst_address.as_u32 = random_vector[j+1];
3951 increment_v4_address (&v4_dst_address);
3957 /* When testing multiple add/del ops, use a control-ping to sync */
3959 vl_api_control_ping_t * mp;
3962 /* Shut off async mode */
3963 vam->async_mode = 0;
3965 M(CONTROL_PING, control_ping);
3968 timeout = vat_time_now(vam) + 1.0;
3969 while (vat_time_now (vam) < timeout)
3970 if (vam->result_ready == 1)
3975 if (vam->retval == -99)
3976 errmsg ("timeout\n");
3978 if (vam->async_errors > 0) {
3979 errmsg ("%d asynchronous errors\n", vam->async_errors);
3982 vam->async_errors = 0;
3983 after = vat_time_now(vam);
3985 fformat(vam->ofp, "%d routes in %.6f secs, %.2f routes/sec\n",
3986 count, after - before, count / (after - before));
3988 /* Wait for a reply... */
3992 /* Return the good/bad news */
3993 return (vam->retval);
3996 static int api_proxy_arp_add_del (vat_main_t * vam)
3998 unformat_input_t * i = vam->input;
3999 vl_api_proxy_arp_add_del_t *mp;
4003 ip4_address_t lo, hi;
4006 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
4007 if (unformat (i, "vrf %d", &vrf_id))
4009 else if (unformat (i, "%U - %U", unformat_ip4_address, &lo,
4010 unformat_ip4_address, &hi))
4012 else if (unformat (i, "del"))
4015 clib_warning ("parse error '%U'", format_unformat_error, i);
4020 if (range_set == 0) {
4021 errmsg ("address range not set\n");
4025 M(PROXY_ARP_ADD_DEL, proxy_arp_add_del);
4027 mp->vrf_id = ntohl(vrf_id);
4028 mp->is_add = is_add;
4029 clib_memcpy(mp->low_address, &lo, sizeof (mp->low_address));
4030 clib_memcpy(mp->hi_address, &hi, sizeof (mp->hi_address));
4037 static int api_proxy_arp_intfc_enable_disable (vat_main_t * vam)
4039 unformat_input_t * i = vam->input;
4040 vl_api_proxy_arp_intfc_enable_disable_t *mp;
4044 u8 sw_if_index_set = 0;
4046 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
4047 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
4048 sw_if_index_set = 1;
4049 else if (unformat (i, "sw_if_index %d", &sw_if_index))
4050 sw_if_index_set = 1;
4051 else if (unformat (i, "enable"))
4053 else if (unformat (i, "disable"))
4056 clib_warning ("parse error '%U'", format_unformat_error, i);
4061 if (sw_if_index_set == 0) {
4062 errmsg ("missing interface name or sw_if_index\n");
4066 M(PROXY_ARP_INTFC_ENABLE_DISABLE, proxy_arp_intfc_enable_disable);
4068 mp->sw_if_index = ntohl(sw_if_index);
4069 mp->enable_disable = enable;
4076 static int api_mpls_add_del_decap (vat_main_t * vam)
4078 unformat_input_t * i = vam->input;
4079 vl_api_mpls_add_del_decap_t *mp;
4088 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
4089 if (unformat (i, "rx_vrf_id %d", &rx_vrf_id))
4091 else if (unformat (i, "tx_vrf_id %d", &tx_vrf_id))
4093 else if (unformat (i, "label %d", &label))
4095 else if (unformat (i, "next-index %d", &next_index))
4097 else if (unformat (i, "del"))
4099 else if (unformat (i, "s-bit-clear"))
4102 clib_warning ("parse error '%U'", format_unformat_error, i);
4107 M(MPLS_ADD_DEL_DECAP, mpls_add_del_decap);
4109 mp->rx_vrf_id = ntohl(rx_vrf_id);
4110 mp->tx_vrf_id = ntohl(tx_vrf_id);
4111 mp->label = ntohl(label);
4112 mp->next_index = ntohl(next_index);
4114 mp->is_add = is_add;
4121 static int api_mpls_add_del_encap (vat_main_t * vam)
4123 unformat_input_t * i = vam->input;
4124 vl_api_mpls_add_del_encap_t *mp;
4129 ip4_address_t dst_address;
4132 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
4133 if (unformat (i, "vrf %d", &vrf_id))
4135 else if (unformat (i, "label %d", &label))
4136 vec_add1 (labels, ntohl(label));
4137 else if (unformat (i, "dst %U", unformat_ip4_address, &dst_address))
4139 else if (unformat (i, "del"))
4142 clib_warning ("parse error '%U'", format_unformat_error, i);
4147 if (vec_len (labels) == 0) {
4148 errmsg ("missing encap label stack\n");
4152 M2(MPLS_ADD_DEL_ENCAP, mpls_add_del_encap,
4153 sizeof (u32) * vec_len (labels));
4155 mp->vrf_id = ntohl(vrf_id);
4156 clib_memcpy(mp->dst_address, &dst_address, sizeof (dst_address));
4157 mp->is_add = is_add;
4158 mp->nlabels = vec_len (labels);
4159 clib_memcpy(mp->labels, labels, sizeof(u32)*mp->nlabels);
4168 static int api_mpls_gre_add_del_tunnel (vat_main_t * vam)
4170 unformat_input_t * i = vam->input;
4171 vl_api_mpls_gre_add_del_tunnel_t *mp;
4173 u32 inner_vrf_id = 0;
4174 u32 outer_vrf_id = 0;
4175 ip4_address_t src_address;
4176 ip4_address_t dst_address;
4177 ip4_address_t intfc_address;
4179 u8 intfc_address_length = 0;
4183 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
4184 if (unformat (i, "inner_vrf_id %d", &inner_vrf_id))
4186 else if (unformat (i, "outer_vrf_id %d", &outer_vrf_id))
4188 else if (unformat (i, "src %U", unformat_ip4_address, &src_address))
4190 else if (unformat (i, "dst %U", unformat_ip4_address, &dst_address))
4192 else if (unformat (i, "adj %U/%d", unformat_ip4_address,
4193 &intfc_address, &tmp))
4194 intfc_address_length = tmp;
4195 else if (unformat (i, "l2-only"))
4197 else if (unformat (i, "del"))
4200 clib_warning ("parse error '%U'", format_unformat_error, i);
4205 M(MPLS_GRE_ADD_DEL_TUNNEL, mpls_gre_add_del_tunnel);
4207 mp->inner_vrf_id = ntohl(inner_vrf_id);
4208 mp->outer_vrf_id = ntohl(outer_vrf_id);
4209 clib_memcpy(mp->src_address, &src_address, sizeof (src_address));
4210 clib_memcpy(mp->dst_address, &dst_address, sizeof (dst_address));
4211 clib_memcpy(mp->intfc_address, &intfc_address, sizeof (intfc_address));
4212 mp->intfc_address_length = intfc_address_length;
4213 mp->l2_only = l2_only;
4214 mp->is_add = is_add;
4221 static int api_mpls_ethernet_add_del_tunnel (vat_main_t * vam)
4223 unformat_input_t * i = vam->input;
4224 vl_api_mpls_ethernet_add_del_tunnel_t *mp;
4226 u32 inner_vrf_id = 0;
4227 ip4_address_t intfc_address;
4228 u8 dst_mac_address[6];
4231 u8 intfc_address_length = 0;
4235 int tx_sw_if_index_set = 0;
4237 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
4238 if (unformat (i, "vrf %d", &inner_vrf_id))
4240 else if (unformat (i, "adj %U/%d", unformat_ip4_address,
4241 &intfc_address, &tmp))
4242 intfc_address_length = tmp;
4243 else if (unformat (i, "%U",
4244 unformat_sw_if_index, vam, &tx_sw_if_index))
4245 tx_sw_if_index_set = 1;
4246 else if (unformat (i, "tx_sw_if_index %d", &tx_sw_if_index))
4247 tx_sw_if_index_set = 1;
4248 else if (unformat (i, "dst %U", unformat_ethernet_address,
4251 else if (unformat (i, "l2-only"))
4253 else if (unformat (i, "del"))
4256 clib_warning ("parse error '%U'", format_unformat_error, i);
4262 errmsg ("dst (mac address) not set\n");
4265 if (!tx_sw_if_index_set) {
4266 errmsg ("tx-intfc not set\n");
4270 M(MPLS_ETHERNET_ADD_DEL_TUNNEL, mpls_ethernet_add_del_tunnel);
4272 mp->vrf_id = ntohl(inner_vrf_id);
4273 clib_memcpy (mp->adj_address, &intfc_address, sizeof (intfc_address));
4274 mp->adj_address_length = intfc_address_length;
4275 clib_memcpy (mp->dst_mac_address, dst_mac_address, sizeof (dst_mac_address));
4276 mp->tx_sw_if_index = ntohl(tx_sw_if_index);
4277 mp->l2_only = l2_only;
4278 mp->is_add = is_add;
4285 static int api_mpls_ethernet_add_del_tunnel_2 (vat_main_t * vam)
4287 unformat_input_t * i = vam->input;
4288 vl_api_mpls_ethernet_add_del_tunnel_2_t *mp;
4290 u32 inner_vrf_id = 0;
4291 u32 outer_vrf_id = 0;
4292 ip4_address_t adj_address;
4293 int adj_address_set = 0;
4294 ip4_address_t next_hop_address;
4295 int next_hop_address_set = 0;
4297 u8 adj_address_length = 0;
4300 u32 resolve_attempts = 5;
4301 u8 resolve_if_needed = 1;
4303 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
4304 if (unformat (i, "inner_vrf_id %d", &inner_vrf_id))
4306 else if (unformat (i, "outer_vrf_id %d", &outer_vrf_id))
4308 else if (unformat (i, "adj %U/%d", unformat_ip4_address,
4309 &adj_address, &tmp)) {
4310 adj_address_length = tmp;
4311 adj_address_set = 1;
4313 else if (unformat (i, "next-hop %U", unformat_ip4_address,
4315 next_hop_address_set = 1;
4316 else if (unformat (i, "resolve-attempts %d", &resolve_attempts))
4318 else if (unformat (i, "resolve-if-needed %d", &tmp))
4319 resolve_if_needed = tmp;
4320 else if (unformat (i, "l2-only"))
4322 else if (unformat (i, "del"))
4325 clib_warning ("parse error '%U'", format_unformat_error, i);
4330 if (!adj_address_set) {
4331 errmsg ("adjacency address/mask not set\n");
4334 if (!next_hop_address_set) {
4335 errmsg ("ip4 next hop address (in outer fib) not set\n");
4339 M(MPLS_ETHERNET_ADD_DEL_TUNNEL_2, mpls_ethernet_add_del_tunnel_2);
4341 mp->inner_vrf_id = ntohl(inner_vrf_id);
4342 mp->outer_vrf_id = ntohl(outer_vrf_id);
4343 mp->resolve_attempts = ntohl(resolve_attempts);
4344 mp->resolve_if_needed = resolve_if_needed;
4345 mp->is_add = is_add;
4346 mp->l2_only = l2_only;
4347 clib_memcpy (mp->adj_address, &adj_address, sizeof (adj_address));
4348 mp->adj_address_length = adj_address_length;
4349 clib_memcpy (mp->next_hop_ip4_address_in_outer_vrf, &next_hop_address,
4350 sizeof (next_hop_address));
4357 static int api_sw_interface_set_unnumbered (vat_main_t * vam)
4359 unformat_input_t * i = vam->input;
4360 vl_api_sw_interface_set_unnumbered_t *mp;
4365 u8 sw_if_index_set = 0;
4367 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
4368 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
4369 sw_if_index_set = 1;
4370 else if (unformat (i, "sw_if_index %d", &sw_if_index))
4371 sw_if_index_set = 1;
4372 else if (unformat (i, "unnum_if_index %d", &unnum_sw_index))
4374 else if (unformat (i, "del"))
4377 clib_warning ("parse error '%U'", format_unformat_error, i);
4382 if (sw_if_index_set == 0) {
4383 errmsg ("missing interface name or sw_if_index\n");
4387 M(SW_INTERFACE_SET_UNNUMBERED, sw_interface_set_unnumbered);
4389 mp->sw_if_index = ntohl(sw_if_index);
4390 mp->unnumbered_sw_if_index = ntohl(unnum_sw_index);
4391 mp->is_add = is_add;
4398 static int api_ip_neighbor_add_del (vat_main_t * vam)
4400 unformat_input_t * i = vam->input;
4401 vl_api_ip_neighbor_add_del_t *mp;
4404 u8 sw_if_index_set = 0;
4410 u8 v4_address_set = 0;
4411 u8 v6_address_set = 0;
4412 ip4_address_t v4address;
4413 ip6_address_t v6address;
4415 memset (mac_address, 0, sizeof (mac_address));
4417 /* Parse args required to build the message */
4418 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
4419 if (unformat (i, "mac %U", unformat_ethernet_address, mac_address)) {
4422 else if (unformat (i, "del"))
4424 else if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
4425 sw_if_index_set = 1;
4426 else if (unformat (i, "sw_if_index %d", &sw_if_index))
4427 sw_if_index_set = 1;
4428 else if (unformat (i, "is_static"))
4430 else if (unformat (i, "vrf %d", &vrf_id))
4432 else if (unformat (i, "dst %U",
4433 unformat_ip4_address, &v4address))
4435 else if (unformat (i, "dst %U",
4436 unformat_ip6_address, &v6address))
4439 clib_warning ("parse error '%U'", format_unformat_error, i);
4444 if (sw_if_index_set == 0) {
4445 errmsg ("missing interface name or sw_if_index\n");
4448 if (v4_address_set && v6_address_set) {
4449 errmsg ("both v4 and v6 addresses set\n");
4452 if (!v4_address_set && !v6_address_set) {
4453 errmsg ("no addresses set\n");
4457 /* Construct the API message */
4458 M(IP_NEIGHBOR_ADD_DEL, ip_neighbor_add_del);
4460 mp->sw_if_index = ntohl (sw_if_index);
4461 mp->is_add = is_add;
4462 mp->vrf_id = ntohl (vrf_id);
4463 mp->is_static = is_static;
4465 clib_memcpy (mp->mac_address, mac_address, 6);
4466 if (v6_address_set) {
4468 clib_memcpy (mp->dst_address, &v6address, sizeof (v6address));
4470 /* mp->is_ipv6 = 0; via memset in M macro above */
4471 clib_memcpy (mp->dst_address, &v4address, sizeof (v4address));
4477 /* Wait for a reply, return good/bad news */
4484 static int api_reset_vrf (vat_main_t * vam)
4486 unformat_input_t * i = vam->input;
4487 vl_api_reset_vrf_t *mp;
4493 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
4494 if (unformat (i, "vrf %d", &vrf_id))
4496 else if (unformat (i, "ipv6"))
4499 clib_warning ("parse error '%U'", format_unformat_error, i);
4504 if (vrf_id_set == 0) {
4505 errmsg ("missing vrf id\n");
4509 M(RESET_VRF, reset_vrf);
4511 mp->vrf_id = ntohl(vrf_id);
4512 mp->is_ipv6 = is_ipv6;
4519 static int api_create_vlan_subif (vat_main_t * vam)
4521 unformat_input_t * i = vam->input;
4522 vl_api_create_vlan_subif_t *mp;
4525 u8 sw_if_index_set = 0;
4529 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
4530 if (unformat (i, "sw_if_index %d", &sw_if_index))
4531 sw_if_index_set = 1;
4532 else if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
4533 sw_if_index_set = 1;
4534 else if (unformat (i, "vlan %d", &vlan_id))
4537 clib_warning ("parse error '%U'", format_unformat_error, i);
4542 if (sw_if_index_set == 0) {
4543 errmsg ("missing interface name or sw_if_index\n");
4547 if (vlan_id_set == 0) {
4548 errmsg ("missing vlan_id\n");
4551 M(CREATE_VLAN_SUBIF, create_vlan_subif);
4553 mp->sw_if_index = ntohl(sw_if_index);
4554 mp->vlan_id = ntohl(vlan_id);
4561 #define foreach_create_subif_bit \
4568 _(outer_vlan_id_any) \
4569 _(inner_vlan_id_any)
4571 static int api_create_subif (vat_main_t * vam)
4573 unformat_input_t * i = vam->input;
4574 vl_api_create_subif_t *mp;
4577 u8 sw_if_index_set = 0;
4584 u32 exact_match = 0;
4585 u32 default_sub = 0;
4586 u32 outer_vlan_id_any = 0;
4587 u32 inner_vlan_id_any = 0;
4589 u16 outer_vlan_id = 0;
4590 u16 inner_vlan_id = 0;
4592 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
4593 if (unformat (i, "sw_if_index %d", &sw_if_index))
4594 sw_if_index_set = 1;
4595 else if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
4596 sw_if_index_set = 1;
4597 else if (unformat (i, "sub_id %d", &sub_id))
4599 else if (unformat (i, "outer_vlan_id %d", &tmp))
4600 outer_vlan_id = tmp;
4601 else if (unformat (i, "inner_vlan_id %d", &tmp))
4602 inner_vlan_id = tmp;
4604 #define _(a) else if (unformat (i, #a)) a = 1 ;
4605 foreach_create_subif_bit
4609 clib_warning ("parse error '%U'", format_unformat_error, i);
4614 if (sw_if_index_set == 0) {
4615 errmsg ("missing interface name or sw_if_index\n");
4619 if (sub_id_set == 0) {
4620 errmsg ("missing sub_id\n");
4623 M(CREATE_SUBIF, create_subif);
4625 mp->sw_if_index = ntohl(sw_if_index);
4626 mp->sub_id = ntohl(sub_id);
4628 #define _(a) mp->a = a;
4629 foreach_create_subif_bit;
4632 mp->outer_vlan_id = ntohs (outer_vlan_id);
4633 mp->inner_vlan_id = ntohs (inner_vlan_id);
4640 static int api_oam_add_del (vat_main_t * vam)
4642 unformat_input_t * i = vam->input;
4643 vl_api_oam_add_del_t *mp;
4647 ip4_address_t src, dst;
4651 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
4652 if (unformat (i, "vrf %d", &vrf_id))
4654 else if (unformat (i, "src %U", unformat_ip4_address, &src))
4656 else if (unformat (i, "dst %U", unformat_ip4_address, &dst))
4658 else if (unformat (i, "del"))
4661 clib_warning ("parse error '%U'", format_unformat_error, i);
4667 errmsg ("missing src addr\n");
4672 errmsg ("missing dst addr\n");
4676 M(OAM_ADD_DEL, oam_add_del);
4678 mp->vrf_id = ntohl(vrf_id);
4679 mp->is_add = is_add;
4680 clib_memcpy(mp->src_address, &src, sizeof (mp->src_address));
4681 clib_memcpy(mp->dst_address, &dst, sizeof (mp->dst_address));
4688 static int api_reset_fib (vat_main_t * vam)
4690 unformat_input_t * i = vam->input;
4691 vl_api_reset_fib_t *mp;
4697 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
4698 if (unformat (i, "vrf %d", &vrf_id))
4700 else if (unformat (i, "ipv6"))
4703 clib_warning ("parse error '%U'", format_unformat_error, i);
4708 if (vrf_id_set == 0) {
4709 errmsg ("missing vrf id\n");
4713 M(RESET_FIB, reset_fib);
4715 mp->vrf_id = ntohl(vrf_id);
4716 mp->is_ipv6 = is_ipv6;
4723 static int api_dhcp_proxy_config (vat_main_t * vam)
4725 unformat_input_t * i = vam->input;
4726 vl_api_dhcp_proxy_config_t *mp;
4731 u8 v4_address_set = 0;
4732 u8 v6_address_set = 0;
4733 ip4_address_t v4address;
4734 ip6_address_t v6address;
4735 u8 v4_src_address_set = 0;
4736 u8 v6_src_address_set = 0;
4737 ip4_address_t v4srcaddress;
4738 ip6_address_t v6srcaddress;
4740 /* Parse args required to build the message */
4741 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
4742 if (unformat (i, "del"))
4744 else if (unformat (i, "vrf %d", &vrf_id))
4746 else if (unformat (i, "insert-cid %d", &insert_cid))
4748 else if (unformat (i, "svr %U",
4749 unformat_ip4_address, &v4address))
4751 else if (unformat (i, "svr %U",
4752 unformat_ip6_address, &v6address))
4754 else if (unformat (i, "src %U",
4755 unformat_ip4_address, &v4srcaddress))
4756 v4_src_address_set = 1;
4757 else if (unformat (i, "src %U",
4758 unformat_ip6_address, &v6srcaddress))
4759 v6_src_address_set = 1;
4764 if (v4_address_set && v6_address_set) {
4765 errmsg ("both v4 and v6 server addresses set\n");
4768 if (!v4_address_set && !v6_address_set) {
4769 errmsg ("no server addresses set\n");
4773 if (v4_src_address_set && v6_src_address_set) {
4774 errmsg ("both v4 and v6 src addresses set\n");
4777 if (!v4_src_address_set && !v6_src_address_set) {
4778 errmsg ("no src addresses set\n");
4782 if (!(v4_src_address_set && v4_address_set) &&
4783 !(v6_src_address_set && v6_address_set)) {
4784 errmsg ("no matching server and src addresses set\n");
4788 /* Construct the API message */
4789 M(DHCP_PROXY_CONFIG, dhcp_proxy_config);
4791 mp->insert_circuit_id = insert_cid;
4792 mp->is_add = is_add;
4793 mp->vrf_id = ntohl (vrf_id);
4794 if (v6_address_set) {
4796 clib_memcpy (mp->dhcp_server, &v6address, sizeof (v6address));
4797 clib_memcpy (mp->dhcp_src_address, &v6srcaddress, sizeof (v6address));
4799 clib_memcpy (mp->dhcp_server, &v4address, sizeof (v4address));
4800 clib_memcpy (mp->dhcp_src_address, &v4srcaddress, sizeof (v4address));
4806 /* Wait for a reply, return good/bad news */
4812 static int api_dhcp_proxy_config_2 (vat_main_t * vam)
4814 unformat_input_t * i = vam->input;
4815 vl_api_dhcp_proxy_config_2_t *mp;
4818 u32 server_vrf_id = 0;
4821 u8 v4_address_set = 0;
4822 u8 v6_address_set = 0;
4823 ip4_address_t v4address;
4824 ip6_address_t v6address;
4825 u8 v4_src_address_set = 0;
4826 u8 v6_src_address_set = 0;
4827 ip4_address_t v4srcaddress;
4828 ip6_address_t v6srcaddress;
4830 /* Parse args required to build the message */
4831 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
4832 if (unformat (i, "del"))
4834 else if (unformat (i, "rx_vrf_id %d", &rx_vrf_id))
4836 else if (unformat (i, "server_vrf_id %d", &server_vrf_id))
4838 else if (unformat (i, "insert-cid %d", &insert_cid))
4840 else if (unformat (i, "svr %U",
4841 unformat_ip4_address, &v4address))
4843 else if (unformat (i, "svr %U",
4844 unformat_ip6_address, &v6address))
4846 else if (unformat (i, "src %U",
4847 unformat_ip4_address, &v4srcaddress))
4848 v4_src_address_set = 1;
4849 else if (unformat (i, "src %U",
4850 unformat_ip6_address, &v6srcaddress))
4851 v6_src_address_set = 1;
4856 if (v4_address_set && v6_address_set) {
4857 errmsg ("both v4 and v6 server addresses set\n");
4860 if (!v4_address_set && !v6_address_set) {
4861 errmsg ("no server addresses set\n");
4865 if (v4_src_address_set && v6_src_address_set) {
4866 errmsg ("both v4 and v6 src addresses set\n");
4869 if (!v4_src_address_set && !v6_src_address_set) {
4870 errmsg ("no src addresses set\n");
4874 if (!(v4_src_address_set && v4_address_set) &&
4875 !(v6_src_address_set && v6_address_set)) {
4876 errmsg ("no matching server and src addresses set\n");
4880 /* Construct the API message */
4881 M(DHCP_PROXY_CONFIG_2, dhcp_proxy_config_2);
4883 mp->insert_circuit_id = insert_cid;
4884 mp->is_add = is_add;
4885 mp->rx_vrf_id = ntohl (rx_vrf_id);
4886 mp->server_vrf_id = ntohl (server_vrf_id);
4887 if (v6_address_set) {
4889 clib_memcpy (mp->dhcp_server, &v6address, sizeof (v6address));
4890 clib_memcpy (mp->dhcp_src_address, &v6srcaddress, sizeof (v6address));
4892 clib_memcpy (mp->dhcp_server, &v4address, sizeof (v4address));
4893 clib_memcpy (mp->dhcp_src_address, &v4srcaddress, sizeof (v4address));
4899 /* Wait for a reply, return good/bad news */
4905 static int api_dhcp_proxy_set_vss (vat_main_t * vam)
4907 unformat_input_t * i = vam->input;
4908 vl_api_dhcp_proxy_set_vss_t *mp;
4919 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
4920 if (unformat (i, "tbl_id %d", &tbl_id))
4922 if (unformat (i, "fib_id %d", &fib_id))
4924 if (unformat (i, "oui %d", &oui))
4926 else if (unformat (i, "ipv6"))
4928 else if (unformat (i, "del"))
4931 clib_warning ("parse error '%U'", format_unformat_error, i);
4936 if (tbl_id_set == 0) {
4937 errmsg ("missing tbl id\n");
4941 if (fib_id_set == 0) {
4942 errmsg ("missing fib id\n");
4946 errmsg ("missing oui\n");
4950 M(DHCP_PROXY_SET_VSS, dhcp_proxy_set_vss);
4951 mp->tbl_id = ntohl(tbl_id);
4952 mp->fib_id = ntohl(fib_id);
4953 mp->oui = ntohl(oui);
4954 mp->is_ipv6 = is_ipv6;
4955 mp->is_add = is_add;
4962 static int api_dhcp_client_config (vat_main_t * vam)
4964 unformat_input_t * i = vam->input;
4965 vl_api_dhcp_client_config_t *mp;
4968 u8 sw_if_index_set = 0;
4971 u8 disable_event = 0;
4973 /* Parse args required to build the message */
4974 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
4975 if (unformat (i, "del"))
4977 else if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
4978 sw_if_index_set = 1;
4979 else if (unformat (i, "sw_if_index %d", &sw_if_index))
4980 sw_if_index_set = 1;
4981 else if (unformat (i, "hostname %s", &hostname))
4983 else if (unformat (i, "disable_event"))
4989 if (sw_if_index_set == 0) {
4990 errmsg ("missing interface name or sw_if_index\n");
4994 if (vec_len (hostname) > 63) {
4995 errmsg ("hostname too long\n");
4997 vec_add1 (hostname, 0);
4999 /* Construct the API message */
5000 M(DHCP_CLIENT_CONFIG, dhcp_client_config);
5002 mp->sw_if_index = ntohl (sw_if_index);
5003 clib_memcpy (mp->hostname, hostname, vec_len (hostname));
5004 vec_free (hostname);
5005 mp->is_add = is_add;
5006 mp->want_dhcp_event = disable_event ? 0 : 1;
5012 /* Wait for a reply, return good/bad news */
5018 static int api_set_ip_flow_hash (vat_main_t * vam)
5020 unformat_input_t * i = vam->input;
5021 vl_api_set_ip_flow_hash_t *mp;
5033 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
5034 if (unformat (i, "vrf %d", &vrf_id))
5036 else if (unformat (i, "ipv6"))
5038 else if (unformat (i, "src"))
5040 else if (unformat (i, "dst"))
5042 else if (unformat (i, "sport"))
5044 else if (unformat (i, "dport"))
5046 else if (unformat (i, "proto"))
5048 else if (unformat (i, "reverse"))
5052 clib_warning ("parse error '%U'", format_unformat_error, i);
5057 if (vrf_id_set == 0) {
5058 errmsg ("missing vrf id\n");
5062 M(SET_IP_FLOW_HASH, set_ip_flow_hash);
5068 mp->reverse = reverse;
5069 mp->vrf_id = ntohl(vrf_id);
5070 mp->is_ipv6 = is_ipv6;
5077 static int api_sw_interface_ip6_enable_disable (vat_main_t * vam)
5079 unformat_input_t * i = vam->input;
5080 vl_api_sw_interface_ip6_enable_disable_t *mp;
5083 u8 sw_if_index_set = 0;
5086 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
5087 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
5088 sw_if_index_set = 1;
5089 else if (unformat (i, "sw_if_index %d", &sw_if_index))
5090 sw_if_index_set = 1;
5091 else if (unformat (i, "enable"))
5093 else if (unformat (i, "disable"))
5096 clib_warning ("parse error '%U'", format_unformat_error, i);
5101 if (sw_if_index_set == 0) {
5102 errmsg ("missing interface name or sw_if_index\n");
5106 M(SW_INTERFACE_IP6_ENABLE_DISABLE, sw_interface_ip6_enable_disable);
5108 mp->sw_if_index = ntohl(sw_if_index);
5109 mp->enable = enable;
5116 static int api_sw_interface_ip6_set_link_local_address (vat_main_t * vam)
5118 unformat_input_t * i = vam->input;
5119 vl_api_sw_interface_ip6_set_link_local_address_t *mp;
5122 u8 sw_if_index_set = 0;
5123 u32 address_length = 0;
5124 u8 v6_address_set = 0;
5125 ip6_address_t v6address;
5127 /* Parse args required to build the message */
5128 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
5129 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
5130 sw_if_index_set = 1;
5131 else if (unformat (i, "sw_if_index %d", &sw_if_index))
5132 sw_if_index_set = 1;
5133 else if (unformat (i, "%U/%d",
5134 unformat_ip6_address, &v6address,
5141 if (sw_if_index_set == 0) {
5142 errmsg ("missing interface name or sw_if_index\n");
5145 if (!v6_address_set) {
5146 errmsg ("no address set\n");
5150 /* Construct the API message */
5151 M(SW_INTERFACE_IP6_SET_LINK_LOCAL_ADDRESS, \
5152 sw_interface_ip6_set_link_local_address);
5154 mp->sw_if_index = ntohl (sw_if_index);
5155 clib_memcpy (mp->address, &v6address, sizeof (v6address));
5156 mp->address_length = address_length;
5161 /* Wait for a reply, return good/bad news */
5169 static int api_sw_interface_ip6nd_ra_prefix (vat_main_t * vam)
5171 unformat_input_t * i = vam->input;
5172 vl_api_sw_interface_ip6nd_ra_prefix_t *mp;
5175 u8 sw_if_index_set = 0;
5176 u32 address_length = 0;
5177 u8 v6_address_set = 0;
5178 ip6_address_t v6address;
5180 u8 no_advertise = 0;
5182 u8 no_autoconfig = 0;
5185 u32 val_lifetime = 0;
5186 u32 pref_lifetime = 0;
5188 /* Parse args required to build the message */
5189 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
5190 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
5191 sw_if_index_set = 1;
5192 else if (unformat (i, "sw_if_index %d", &sw_if_index))
5193 sw_if_index_set = 1;
5194 else if (unformat (i, "%U/%d",
5195 unformat_ip6_address, &v6address,
5198 else if (unformat (i, "val_life %d", &val_lifetime))
5200 else if (unformat (i, "pref_life %d", &pref_lifetime))
5202 else if (unformat (i, "def"))
5204 else if (unformat (i, "noadv"))
5206 else if (unformat (i, "offl"))
5208 else if (unformat (i, "noauto"))
5210 else if (unformat (i, "nolink"))
5212 else if (unformat (i, "isno"))
5215 clib_warning ("parse error '%U'", format_unformat_error, i);
5220 if (sw_if_index_set == 0) {
5221 errmsg ("missing interface name or sw_if_index\n");
5224 if (!v6_address_set) {
5225 errmsg ("no address set\n");
5229 /* Construct the API message */
5230 M(SW_INTERFACE_IP6ND_RA_PREFIX, sw_interface_ip6nd_ra_prefix);
5232 mp->sw_if_index = ntohl (sw_if_index);
5233 clib_memcpy (mp->address, &v6address, sizeof (v6address));
5234 mp->address_length = address_length;
5235 mp->use_default = use_default;
5236 mp->no_advertise = no_advertise;
5237 mp->off_link = off_link;
5238 mp->no_autoconfig = no_autoconfig;
5239 mp->no_onlink = no_onlink;
5241 mp->val_lifetime = ntohl(val_lifetime);
5242 mp->pref_lifetime = ntohl(pref_lifetime);
5247 /* Wait for a reply, return good/bad news */
5254 static int api_sw_interface_ip6nd_ra_config (vat_main_t * vam)
5256 unformat_input_t * i = vam->input;
5257 vl_api_sw_interface_ip6nd_ra_config_t *mp;
5260 u8 sw_if_index_set = 0;
5265 u8 send_unicast = 0;
5268 u8 default_router = 0;
5269 u32 max_interval = 0;
5270 u32 min_interval = 0;
5272 u32 initial_count = 0;
5273 u32 initial_interval = 0;
5276 /* Parse args required to build the message */
5277 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
5278 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
5279 sw_if_index_set = 1;
5280 else if (unformat (i, "sw_if_index %d", &sw_if_index))
5281 sw_if_index_set = 1;
5282 else if (unformat (i, "maxint %d", &max_interval))
5284 else if (unformat (i, "minint %d", &min_interval))
5286 else if (unformat (i, "life %d", &lifetime))
5288 else if (unformat (i, "count %d", &initial_count))
5290 else if (unformat (i, "interval %d", &initial_interval))
5292 else if (unformat (i, "surpress"))
5294 else if (unformat (i, "managed"))
5296 else if (unformat (i, "other"))
5298 else if (unformat (i, "ll"))
5300 else if (unformat (i, "send"))
5302 else if (unformat (i, "cease"))
5304 else if (unformat (i, "isno"))
5306 else if (unformat (i, "def"))
5309 clib_warning ("parse error '%U'", format_unformat_error, i);
5314 if (sw_if_index_set == 0) {
5315 errmsg ("missing interface name or sw_if_index\n");
5319 /* Construct the API message */
5320 M(SW_INTERFACE_IP6ND_RA_CONFIG, sw_interface_ip6nd_ra_config);
5322 mp->sw_if_index = ntohl (sw_if_index);
5323 mp->max_interval = ntohl(max_interval);
5324 mp->min_interval = ntohl(min_interval);
5325 mp->lifetime = ntohl(lifetime);
5326 mp->initial_count = ntohl(initial_count);
5327 mp->initial_interval = ntohl(initial_interval);
5328 mp->surpress = surpress;
5329 mp->managed = managed;
5331 mp->ll_option = ll_option;
5332 mp->send_unicast = send_unicast;
5335 mp->default_router = default_router;
5340 /* Wait for a reply, return good/bad news */
5347 static int api_set_arp_neighbor_limit (vat_main_t * vam)
5349 unformat_input_t * i = vam->input;
5350 vl_api_set_arp_neighbor_limit_t *mp;
5356 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
5357 if (unformat (i, "arp_nbr_limit %d", &arp_nbr_limit))
5359 else if (unformat (i, "ipv6"))
5362 clib_warning ("parse error '%U'", format_unformat_error, i);
5367 if (limit_set == 0) {
5368 errmsg ("missing limit value\n");
5372 M(SET_ARP_NEIGHBOR_LIMIT, set_arp_neighbor_limit);
5374 mp->arp_neighbor_limit = ntohl(arp_nbr_limit);
5375 mp->is_ipv6 = is_ipv6;
5382 static int api_l2_patch_add_del (vat_main_t * vam)
5384 unformat_input_t * i = vam->input;
5385 vl_api_l2_patch_add_del_t *mp;
5388 u8 rx_sw_if_index_set = 0;
5390 u8 tx_sw_if_index_set = 0;
5393 /* Parse args required to build the message */
5394 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
5395 if (unformat (i, "rx_sw_if_index %d", &rx_sw_if_index))
5396 rx_sw_if_index_set = 1;
5397 else if (unformat (i, "tx_sw_if_index %d", &tx_sw_if_index))
5398 tx_sw_if_index_set = 1;
5399 else if (unformat (i, "rx")) {
5400 if (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
5401 if (unformat (i, "%U", unformat_sw_if_index, vam,
5403 rx_sw_if_index_set = 1;
5406 } else if (unformat (i, "tx")) {
5407 if (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
5408 if (unformat (i, "%U", unformat_sw_if_index, vam,
5410 tx_sw_if_index_set = 1;
5413 } else if (unformat (i, "del"))
5419 if (rx_sw_if_index_set == 0) {
5420 errmsg ("missing rx interface name or rx_sw_if_index\n");
5424 if (tx_sw_if_index_set == 0) {
5425 errmsg ("missing tx interface name or tx_sw_if_index\n");
5429 M(L2_PATCH_ADD_DEL, l2_patch_add_del);
5431 mp->rx_sw_if_index = ntohl(rx_sw_if_index);
5432 mp->tx_sw_if_index = ntohl(tx_sw_if_index);
5433 mp->is_add = is_add;
5439 static int api_trace_profile_add (vat_main_t *vam)
5441 unformat_input_t * input = vam->input;
5442 vl_api_trace_profile_add_t *mp;
5445 u32 trace_option_elts = 0;
5446 u32 trace_type = 0, node_id = 0, app_data = 0, trace_tsp = 2;
5447 int has_pow_option = 0;
5448 int has_ppc_option = 0;
5450 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
5452 if (unformat (input, "id %d trace-type 0x%x trace-elts %d "
5453 "trace-tsp %d node-id 0x%x app-data 0x%x",
5454 &id, &trace_type, &trace_option_elts, &trace_tsp,
5455 &node_id, &app_data))
5457 else if (unformat (input, "pow"))
5459 else if (unformat (input, "ppc encap"))
5460 has_ppc_option = PPC_ENCAP;
5461 else if (unformat (input, "ppc decap"))
5462 has_ppc_option = PPC_DECAP;
5463 else if (unformat (input, "ppc none"))
5464 has_ppc_option = PPC_NONE;
5468 M(TRACE_PROFILE_ADD, trace_profile_add);
5470 mp->trace_type = trace_type;
5471 mp->trace_num_elt = trace_option_elts;
5472 mp->trace_ppc = has_ppc_option;
5473 mp->trace_app_data = htonl(app_data);
5474 mp->pow_enable = has_pow_option;
5475 mp->trace_tsp = trace_tsp;
5476 mp->node_id = htonl(node_id);
5483 static int api_trace_profile_apply (vat_main_t *vam)
5485 unformat_input_t * input = vam->input;
5486 vl_api_trace_profile_apply_t *mp;
5489 u32 mask_width = ~0;
5496 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
5498 if (unformat (input, "%U/%d",
5499 unformat_ip6_address, &addr, &mask_width))
5501 else if (unformat (input, "id %d", &id))
5503 else if (unformat (input, "vrf-id %d", &vrf_id))
5505 else if (unformat (input, "add"))
5507 else if (unformat (input, "pop"))
5509 else if (unformat (input, "none"))
5515 if ((is_add + is_pop + is_none) != 1) {
5516 errmsg("One of (add, pop, none) required");
5519 if (mask_width == ~0) {
5520 errmsg("<address>/<mask-width> required");
5523 M(TRACE_PROFILE_APPLY, trace_profile_apply);
5524 clib_memcpy(mp->dest_ipv6, &addr, sizeof(mp->dest_ipv6));
5526 mp->prefix_length = htonl(mask_width);
5527 mp->vrf_id = htonl(vrf_id);
5529 mp->trace_op = IOAM_HBYH_ADD;
5531 mp->trace_op = IOAM_HBYH_POP;
5533 mp->trace_op = IOAM_HBYH_MOD;
5545 static int api_trace_profile_del (vat_main_t *vam)
5547 vl_api_trace_profile_del_t *mp;
5550 M(TRACE_PROFILE_DEL, trace_profile_del);
5555 static int api_sr_tunnel_add_del (vat_main_t * vam)
5557 unformat_input_t * i = vam->input;
5558 vl_api_sr_tunnel_add_del_t *mp;
5562 ip6_address_t src_address;
5563 int src_address_set = 0;
5564 ip6_address_t dst_address;
5566 int dst_address_set = 0;
5568 u32 rx_table_id = 0;
5569 u32 tx_table_id = 0;
5570 ip6_address_t * segments = 0;
5571 ip6_address_t * this_seg;
5572 ip6_address_t * tags = 0;
5573 ip6_address_t * this_tag;
5574 ip6_address_t next_address, tag;
5576 u8 * policy_name = 0;
5578 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
5580 if (unformat (i, "del"))
5582 else if (unformat (i, "name %s", &name))
5584 else if (unformat (i, "policy %s", &policy_name))
5586 else if (unformat (i, "rx_fib_id %d", &rx_table_id))
5588 else if (unformat (i, "tx_fib_id %d", &tx_table_id))
5590 else if (unformat (i, "src %U", unformat_ip6_address, &src_address))
5591 src_address_set = 1;
5592 else if (unformat (i, "dst %U/%d",
5593 unformat_ip6_address, &dst_address,
5595 dst_address_set = 1;
5596 else if (unformat (i, "next %U", unformat_ip6_address,
5599 vec_add2 (segments, this_seg, 1);
5600 clib_memcpy (this_seg->as_u8, next_address.as_u8, sizeof (*this_seg));
5602 else if (unformat (i, "tag %U", unformat_ip6_address,
5605 vec_add2 (tags, this_tag, 1);
5606 clib_memcpy (this_tag->as_u8, tag.as_u8, sizeof (*this_tag));
5608 else if (unformat (i, "clean"))
5609 flags |= IP6_SR_HEADER_FLAG_CLEANUP;
5610 else if (unformat (i, "protected"))
5611 flags |= IP6_SR_HEADER_FLAG_PROTECTED;
5612 else if (unformat (i, "InPE %d", &pl_index))
5614 if (pl_index <= 0 || pl_index > 4)
5616 pl_index_range_error:
5617 errmsg ("pl index %d out of range\n", pl_index);
5620 flags |= IP6_SR_HEADER_FLAG_PL_ELT_INGRESS_PE << (3*(pl_index - 1));
5622 else if (unformat (i, "EgPE %d", &pl_index))
5624 if (pl_index <= 0 || pl_index > 4)
5625 goto pl_index_range_error;
5626 flags |= IP6_SR_HEADER_FLAG_PL_ELT_EGRESS_PE << (3*(pl_index - 1));
5628 else if (unformat (i, "OrgSrc %d", &pl_index))
5630 if (pl_index <= 0 || pl_index > 4)
5631 goto pl_index_range_error;
5632 flags |= IP6_SR_HEADER_FLAG_PL_ELT_ORIG_SRC_ADDR << (3*(pl_index - 1));
5638 if (!src_address_set)
5640 errmsg ("src address required\n");
5644 if (!dst_address_set)
5646 errmsg ("dst address required\n");
5652 errmsg ("at least one sr segment required\n");
5656 M2(SR_TUNNEL_ADD_DEL, sr_tunnel_add_del,
5657 vec_len(segments) * sizeof (ip6_address_t)
5658 + vec_len(tags) * sizeof (ip6_address_t));
5660 clib_memcpy (mp->src_address, &src_address, sizeof (mp->src_address));
5661 clib_memcpy (mp->dst_address, &dst_address, sizeof (mp->dst_address));
5662 mp->dst_mask_width = dst_mask_width;
5663 mp->flags_net_byte_order = clib_host_to_net_u16 (flags);
5664 mp->n_segments = vec_len (segments);
5665 mp->n_tags = vec_len (tags);
5666 mp->is_add = is_del == 0;
5667 clib_memcpy (mp->segs_and_tags, segments,
5668 vec_len(segments)* sizeof (ip6_address_t));
5669 clib_memcpy (mp->segs_and_tags + vec_len(segments)*sizeof (ip6_address_t),
5670 tags, vec_len(tags)* sizeof (ip6_address_t));
5672 mp->outer_vrf_id = ntohl (rx_table_id);
5673 mp->inner_vrf_id = ntohl (tx_table_id);
5674 memcpy (mp->name, name, vec_len(name));
5675 memcpy (mp->policy_name, policy_name, vec_len(policy_name));
5677 vec_free (segments);
5684 static int api_sr_policy_add_del (vat_main_t * vam)
5686 unformat_input_t * input = vam->input;
5687 vl_api_sr_policy_add_del_t *mp;
5691 u8 * tunnel_name = 0;
5692 u8 ** tunnel_names = 0;
5697 int tunnel_names_length = 1; // Init to 1 to offset the #tunnel_names counter byte
5698 int tun_name_len = 0; // Different naming convention used as confusing these would be "bad" (TM)
5700 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
5702 if (unformat (input, "del"))
5704 else if (unformat (input, "name %s", &name))
5706 else if (unformat (input, "tunnel %s", &tunnel_name))
5710 vec_add1 (tunnel_names, tunnel_name);
5712 - length = #bytes to store in serial vector
5713 - +1 = byte to store that length
5715 tunnel_names_length += (vec_len (tunnel_name) + 1);
5726 errmsg ("policy name required\n");
5730 if ((!tunnel_set) && (!is_del))
5732 errmsg ("tunnel name required\n");
5736 M2(SR_POLICY_ADD_DEL, sr_policy_add_del, tunnel_names_length);
5740 mp->is_add = !is_del;
5742 memcpy (mp->name, name, vec_len(name));
5743 // Since mp->tunnel_names is of type u8[0] and not a u8 *, u8 ** needs to be serialized
5744 u8 * serial_orig = 0;
5745 vec_validate (serial_orig, tunnel_names_length);
5746 *serial_orig = vec_len(tunnel_names); // Store the number of tunnels as length in first byte of serialized vector
5747 serial_orig += 1; // Move along one byte to store the length of first tunnel_name
5749 for (j=0; j < vec_len(tunnel_names); j++)
5751 tun_name_len = vec_len (tunnel_names[j]);
5752 *serial_orig = tun_name_len; // Store length of tunnel name in first byte of Length/Value pair
5753 serial_orig += 1; // Move along one byte to store the actual tunnel name
5754 memcpy (serial_orig, tunnel_names[j], tun_name_len);
5755 serial_orig += tun_name_len; // Advance past the copy
5757 memcpy (mp->tunnel_names, serial_orig - tunnel_names_length, tunnel_names_length); // Regress serial_orig to head then copy fwd
5759 vec_free (tunnel_names);
5760 vec_free (tunnel_name);
5766 static int api_sr_multicast_map_add_del (vat_main_t * vam)
5768 unformat_input_t * input = vam->input;
5769 vl_api_sr_multicast_map_add_del_t *mp;
5772 ip6_address_t multicast_address;
5773 u8 * policy_name = 0;
5774 int multicast_address_set = 0;
5776 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
5778 if (unformat (input, "del"))
5780 else if (unformat (input, "address %U", unformat_ip6_address, &multicast_address))
5781 multicast_address_set = 1;
5782 else if (unformat (input, "sr-policy %s", &policy_name))
5788 if (!is_del && !policy_name)
5790 errmsg ("sr-policy name required\n");
5795 if (!multicast_address_set)
5797 errmsg ("address required\n");
5801 M(SR_MULTICAST_MAP_ADD_DEL, sr_multicast_map_add_del);
5803 mp->is_add = !is_del;
5804 memcpy (mp->policy_name, policy_name, vec_len(policy_name));
5805 clib_memcpy (mp->multicast_address, &multicast_address, sizeof (mp->multicast_address));
5808 vec_free (policy_name);
5815 #define foreach_ip4_proto_field \
5825 uword unformat_ip4_mask (unformat_input_t * input, va_list * args)
5827 u8 ** maskp = va_arg (*args, u8 **);
5829 u8 found_something = 0;
5832 #define _(a) u8 a=0;
5833 foreach_ip4_proto_field;
5839 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
5841 if (unformat (input, "version"))
5843 else if (unformat (input, "hdr_length"))
5845 else if (unformat (input, "src"))
5847 else if (unformat (input, "dst"))
5849 else if (unformat (input, "proto"))
5852 #define _(a) else if (unformat (input, #a)) a=1;
5853 foreach_ip4_proto_field
5859 #define _(a) found_something += a;
5860 foreach_ip4_proto_field;
5863 if (found_something == 0)
5866 vec_validate (mask, sizeof (*ip) - 1);
5868 ip = (ip4_header_t *) mask;
5870 #define _(a) if (a) memset (&ip->a, 0xff, sizeof (ip->a));
5871 foreach_ip4_proto_field;
5874 ip->ip_version_and_header_length = 0;
5877 ip->ip_version_and_header_length |= 0xF0;
5880 ip->ip_version_and_header_length |= 0x0F;
5886 #define foreach_ip6_proto_field \
5893 uword unformat_ip6_mask (unformat_input_t * input, va_list * args)
5895 u8 ** maskp = va_arg (*args, u8 **);
5897 u8 found_something = 0;
5899 u32 ip_version_traffic_class_and_flow_label;
5901 #define _(a) u8 a=0;
5902 foreach_ip6_proto_field;
5905 u8 traffic_class = 0;
5908 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
5910 if (unformat (input, "version"))
5912 else if (unformat (input, "traffic-class"))
5914 else if (unformat (input, "flow-label"))
5916 else if (unformat (input, "src"))
5918 else if (unformat (input, "dst"))
5920 else if (unformat (input, "proto"))
5923 #define _(a) else if (unformat (input, #a)) a=1;
5924 foreach_ip6_proto_field
5930 #define _(a) found_something += a;
5931 foreach_ip6_proto_field;
5934 if (found_something == 0)
5937 vec_validate (mask, sizeof (*ip) - 1);
5939 ip = (ip6_header_t *) mask;
5941 #define _(a) if (a) memset (&ip->a, 0xff, sizeof (ip->a));
5942 foreach_ip6_proto_field;
5945 ip_version_traffic_class_and_flow_label = 0;
5948 ip_version_traffic_class_and_flow_label |= 0xF0000000;
5951 ip_version_traffic_class_and_flow_label |= 0x0FF00000;
5954 ip_version_traffic_class_and_flow_label |= 0x000FFFFF;
5956 ip->ip_version_traffic_class_and_flow_label =
5957 clib_host_to_net_u32 (ip_version_traffic_class_and_flow_label);
5963 uword unformat_l3_mask (unformat_input_t * input, va_list * args)
5965 u8 ** maskp = va_arg (*args, u8 **);
5967 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) {
5968 if (unformat (input, "ip4 %U", unformat_ip4_mask, maskp))
5970 else if (unformat (input, "ip6 %U", unformat_ip6_mask, maskp))
5978 uword unformat_l2_mask (unformat_input_t * input, va_list * args)
5980 u8 ** maskp = va_arg (*args, u8 **);
5995 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) {
5996 if (unformat (input, "src"))
5998 else if (unformat (input, "dst"))
6000 else if (unformat (input, "proto"))
6002 else if (unformat (input, "tag1"))
6004 else if (unformat (input, "tag2"))
6006 else if (unformat (input, "ignore-tag1"))
6008 else if (unformat (input, "ignore-tag2"))
6010 else if (unformat (input, "cos1"))
6012 else if (unformat (input, "cos2"))
6014 else if (unformat (input, "dot1q"))
6016 else if (unformat (input, "dot1ad"))
6021 if ((src + dst + proto + tag1 + tag2 + dot1q + dot1ad +
6022 ignore_tag1 + ignore_tag2 + cos1 + cos2) == 0)
6025 if (tag1 || ignore_tag1 || cos1 || dot1q)
6027 if (tag2 || ignore_tag2 || cos2 || dot1ad)
6030 vec_validate (mask, len-1);
6033 memset (mask, 0xff, 6);
6036 memset (mask + 6, 0xff, 6);
6040 /* inner vlan tag */
6049 mask[21] = mask [20] = 0xff;
6070 mask[16] = mask [17] = 0xff;
6080 mask[12] = mask [13] = 0xff;
6086 uword unformat_classify_mask (unformat_input_t * input, va_list * args)
6088 u8 ** maskp = va_arg (*args, u8 **);
6089 u32 * skipp = va_arg (*args, u32 *);
6090 u32 * matchp = va_arg (*args, u32 *);
6097 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) {
6098 if (unformat (input, "hex %U", unformat_hex_string, &mask))
6100 else if (unformat (input, "l2 %U", unformat_l2_mask, &l2))
6102 else if (unformat (input, "l3 %U", unformat_l3_mask, &l3))
6108 if (mask || l2 || l3)
6112 /* "With a free Ethernet header in every package" */
6114 vec_validate (l2, 13);
6116 vec_append (mask, l3);
6120 /* Scan forward looking for the first significant mask octet */
6121 for (i = 0; i < vec_len (mask); i++)
6125 /* compute (skip, match) params */
6126 *skipp = i / sizeof(u32x4);
6127 vec_delete (mask, *skipp * sizeof(u32x4), 0);
6129 /* Pad mask to an even multiple of the vector size */
6130 while (vec_len (mask) % sizeof (u32x4))
6133 match = vec_len (mask) / sizeof (u32x4);
6135 for (i = match*sizeof(u32x4); i > 0; i-= sizeof(u32x4))
6137 u64 *tmp = (u64 *)(mask + (i-sizeof(u32x4)));
6138 if (*tmp || *(tmp+1))
6143 clib_warning ("BUG: match 0");
6145 _vec_len (mask) = match * sizeof(u32x4);
6156 #define foreach_l2_next \
6158 _(ethernet, ETHERNET_INPUT) \
6162 uword unformat_l2_next_index (unformat_input_t * input, va_list * args)
6164 u32 * miss_next_indexp = va_arg (*args, u32 *);
6169 if (unformat (input, #n)) { next_index = L2_CLASSIFY_NEXT_##N; goto out;}
6173 if (unformat (input, "%d", &tmp))
6182 *miss_next_indexp = next_index;
6186 #define foreach_ip_next \
6192 uword unformat_ip_next_index (unformat_input_t * input, va_list * args)
6194 u32 * miss_next_indexp = va_arg (*args, u32 *);
6199 if (unformat (input, #n)) { next_index = IP_LOOKUP_NEXT_##N; goto out;}
6203 if (unformat (input, "%d", &tmp))
6212 *miss_next_indexp = next_index;
6216 #define foreach_acl_next \
6219 uword unformat_acl_next_index (unformat_input_t * input, va_list * args)
6221 u32 * miss_next_indexp = va_arg (*args, u32 *);
6226 if (unformat (input, #n)) { next_index = ACL_NEXT_INDEX_##N; goto out;}
6230 if (unformat (input, "permit"))
6235 else if (unformat (input, "%d", &tmp))
6244 *miss_next_indexp = next_index;
6248 static int api_classify_add_del_table (vat_main_t * vam)
6250 unformat_input_t * i = vam->input;
6251 vl_api_classify_add_del_table_t *mp;
6257 u32 table_index = ~0;
6258 u32 next_table_index = ~0;
6259 u32 miss_next_index = ~0;
6260 u32 memory_size = 32<<20;
6264 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
6265 if (unformat (i, "del"))
6267 else if (unformat (i, "buckets %d", &nbuckets))
6269 else if (unformat (i, "memory_size %d", &memory_size))
6271 else if (unformat (i, "skip %d", &skip))
6273 else if (unformat (i, "match %d", &match))
6275 else if (unformat (i, "table %d", &table_index))
6277 else if (unformat (i, "mask %U", unformat_classify_mask,
6278 &mask, &skip, &match))
6280 else if (unformat (i, "next-table %d", &next_table_index))
6282 else if (unformat (i, "miss-next %U", unformat_ip_next_index,
6285 else if (unformat (i, "l2-miss-next %U", unformat_l2_next_index,
6288 else if (unformat (i, "acl-miss-next %U", unformat_acl_next_index,
6295 if (is_add && mask == 0) {
6296 errmsg ("Mask required\n");
6300 if (is_add && skip == ~0) {
6301 errmsg ("skip count required\n");
6305 if (is_add && match == ~0) {
6306 errmsg ("match count required\n");
6310 if (!is_add && table_index == ~0) {
6311 errmsg ("table index required for delete\n");
6315 M2 (CLASSIFY_ADD_DEL_TABLE, classify_add_del_table,
6318 mp->is_add = is_add;
6319 mp->table_index = ntohl(table_index);
6320 mp->nbuckets = ntohl(nbuckets);
6321 mp->memory_size = ntohl(memory_size);
6322 mp->skip_n_vectors = ntohl(skip);
6323 mp->match_n_vectors = ntohl(match);
6324 mp->next_table_index = ntohl(next_table_index);
6325 mp->miss_next_index = ntohl(miss_next_index);
6326 clib_memcpy (mp->mask, mask, vec_len(mask));
6334 uword unformat_ip4_match (unformat_input_t * input, va_list * args)
6336 u8 ** matchp = va_arg (*args, u8 **);
6343 int src = 0, dst = 0;
6344 ip4_address_t src_val, dst_val;
6351 int fragment_id = 0;
6352 u32 fragment_id_val;
6358 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
6360 if (unformat (input, "version %d", &version_val))
6362 else if (unformat (input, "hdr_length %d", &hdr_length_val))
6364 else if (unformat (input, "src %U", unformat_ip4_address, &src_val))
6366 else if (unformat (input, "dst %U", unformat_ip4_address, &dst_val))
6368 else if (unformat (input, "proto %d", &proto_val))
6370 else if (unformat (input, "tos %d", &tos_val))
6372 else if (unformat (input, "length %d", &length_val))
6374 else if (unformat (input, "fragment_id %d", &fragment_id_val))
6376 else if (unformat (input, "ttl %d", &ttl_val))
6378 else if (unformat (input, "checksum %d", &checksum_val))
6384 if (version + hdr_length + src + dst + proto + tos + length + fragment_id
6385 + ttl + checksum == 0)
6389 * Aligned because we use the real comparison functions
6391 vec_validate_aligned (match, sizeof (*ip) - 1, sizeof(u32x4));
6393 ip = (ip4_header_t *) match;
6395 /* These are realistically matched in practice */
6397 ip->src_address.as_u32 = src_val.as_u32;
6400 ip->dst_address.as_u32 = dst_val.as_u32;
6403 ip->protocol = proto_val;
6406 /* These are not, but they're included for completeness */
6408 ip->ip_version_and_header_length |= (version_val & 0xF)<<4;
6411 ip->ip_version_and_header_length |= (hdr_length_val & 0xF);
6417 ip->length = length_val;
6423 ip->checksum = checksum_val;
6429 uword unformat_ip6_match (unformat_input_t * input, va_list * args)
6431 u8 ** matchp = va_arg (*args, u8 **);
6437 u32 traffic_class_val;
6440 int src = 0, dst = 0;
6441 ip6_address_t src_val, dst_val;
6444 int payload_length = 0;
6445 u32 payload_length_val;
6448 u32 ip_version_traffic_class_and_flow_label;
6450 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
6452 if (unformat (input, "version %d", &version_val))
6454 else if (unformat (input, "traffic_class %d", &traffic_class_val))
6456 else if (unformat (input, "flow_label %d", &flow_label_val))
6458 else if (unformat (input, "src %U", unformat_ip6_address, &src_val))
6460 else if (unformat (input, "dst %U", unformat_ip6_address, &dst_val))
6462 else if (unformat (input, "proto %d", &proto_val))
6464 else if (unformat (input, "payload_length %d", &payload_length_val))
6466 else if (unformat (input, "hop_limit %d", &hop_limit_val))
6472 if (version + traffic_class + flow_label + src + dst + proto +
6473 payload_length + hop_limit == 0)
6477 * Aligned because we use the real comparison functions
6479 vec_validate_aligned (match, sizeof (*ip) - 1, sizeof(u32x4));
6481 ip = (ip6_header_t *) match;
6484 clib_memcpy (&ip->src_address, &src_val, sizeof (ip->src_address));
6487 clib_memcpy (&ip->dst_address, &dst_val, sizeof (ip->dst_address));
6490 ip->protocol = proto_val;
6492 ip_version_traffic_class_and_flow_label = 0;
6495 ip_version_traffic_class_and_flow_label |= (version_val & 0xF) << 28;
6498 ip_version_traffic_class_and_flow_label |= (traffic_class_val & 0xFF) << 20;
6501 ip_version_traffic_class_and_flow_label |= (flow_label_val & 0xFFFFF);
6503 ip->ip_version_traffic_class_and_flow_label =
6504 clib_host_to_net_u32 (ip_version_traffic_class_and_flow_label);
6507 ip->payload_length = clib_host_to_net_u16 (payload_length_val);
6510 ip->hop_limit = hop_limit_val;
6516 uword unformat_l3_match (unformat_input_t * input, va_list * args)
6518 u8 ** matchp = va_arg (*args, u8 **);
6520 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) {
6521 if (unformat (input, "ip4 %U", unformat_ip4_match, matchp))
6523 else if (unformat (input, "ip6 %U", unformat_ip6_match, matchp))
6531 uword unformat_vlan_tag (unformat_input_t * input, va_list * args)
6533 u8 * tagp = va_arg (*args, u8 *);
6536 if (unformat(input, "%d", &tag))
6538 tagp[0] = (tag>>8) & 0x0F;
6539 tagp[1] = tag & 0xFF;
6546 uword unformat_l2_match (unformat_input_t * input, va_list * args)
6548 u8 ** matchp = va_arg (*args, u8 **);
6568 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) {
6569 if (unformat (input, "src %U", unformat_ethernet_address, &src_val))
6571 else if (unformat (input, "dst %U", unformat_ethernet_address, &dst_val))
6573 else if (unformat (input, "proto %U",
6574 unformat_ethernet_type_host_byte_order, &proto_val))
6576 else if (unformat (input, "tag1 %U", unformat_vlan_tag, tag1_val))
6578 else if (unformat (input, "tag2 %U", unformat_vlan_tag, tag2_val))
6580 else if (unformat (input, "ignore-tag1"))
6582 else if (unformat (input, "ignore-tag2"))
6584 else if (unformat (input, "cos1 %d", &cos1_val))
6586 else if (unformat (input, "cos2 %d", &cos2_val))
6591 if ((src + dst + proto + tag1 + tag2 +
6592 ignore_tag1 + ignore_tag2 + cos1 + cos2) == 0)
6595 if (tag1 || ignore_tag1 || cos1)
6597 if (tag2 || ignore_tag2 || cos2)
6600 vec_validate_aligned (match, len-1, sizeof(u32x4));
6603 clib_memcpy (match, dst_val, 6);
6606 clib_memcpy (match + 6, src_val, 6);
6610 /* inner vlan tag */
6611 match[19] = tag2_val[1];
6612 match[18] = tag2_val[0];
6614 match [18] |= (cos2_val & 0x7) << 5;
6617 match[21] = proto_val & 0xff;
6618 match[20] = proto_val >> 8;
6622 match [15] = tag1_val[1];
6623 match [14] = tag1_val[0];
6626 match [14] |= (cos1_val & 0x7) << 5;
6632 match [15] = tag1_val[1];
6633 match [14] = tag1_val[0];
6636 match[17] = proto_val & 0xff;
6637 match[16] = proto_val >> 8;
6640 match [14] |= (cos1_val & 0x7) << 5;
6646 match [18] |= (cos2_val & 0x7) << 5;
6648 match [14] |= (cos1_val & 0x7) << 5;
6651 match[13] = proto_val & 0xff;
6652 match[12] = proto_val >> 8;
6660 uword unformat_classify_match (unformat_input_t * input, va_list * args)
6662 u8 ** matchp = va_arg (*args, u8 **);
6663 u32 skip_n_vectors = va_arg (*args, u32);
6664 u32 match_n_vectors = va_arg (*args, u32);
6670 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) {
6671 if (unformat (input, "hex %U", unformat_hex_string, &match))
6673 else if (unformat (input, "l2 %U", unformat_l2_match, &l2))
6675 else if (unformat (input, "l3 %U", unformat_l3_match, &l3))
6681 if (match || l2 || l3)
6685 /* "Win a free Ethernet header in every packet" */
6687 vec_validate_aligned (l2, 13, sizeof(u32x4));
6689 vec_append_aligned (match, l3, sizeof(u32x4));
6693 /* Make sure the vector is big enough even if key is all 0's */
6694 vec_validate_aligned
6695 (match, ((match_n_vectors + skip_n_vectors) * sizeof(u32x4)) - 1,
6698 /* Set size, include skipped vectors*/
6699 _vec_len (match) = (match_n_vectors+skip_n_vectors) * sizeof(u32x4);
6709 static int api_classify_add_del_session (vat_main_t * vam)
6711 unformat_input_t * i = vam->input;
6712 vl_api_classify_add_del_session_t *mp;
6714 u32 table_index = ~0;
6715 u32 hit_next_index = ~0;
6716 u32 opaque_index = ~0;
6720 u32 skip_n_vectors = 0;
6721 u32 match_n_vectors = 0;
6724 * Warning: you have to supply skip_n and match_n
6725 * because the API client cant simply look at the classify
6729 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
6730 if (unformat (i, "del"))
6732 else if (unformat (i, "hit-next %U", unformat_ip_next_index,
6735 else if (unformat (i, "l2-hit-next %U", unformat_l2_next_index,
6738 else if (unformat (i, "acl-hit-next %U", unformat_acl_next_index,
6741 else if (unformat (i, "opaque-index %d", &opaque_index))
6743 else if (unformat (i, "skip_n %d", &skip_n_vectors))
6745 else if (unformat (i, "match_n %d", &match_n_vectors))
6747 else if (unformat (i, "match %U", unformat_classify_match,
6748 &match, skip_n_vectors, match_n_vectors))
6750 else if (unformat (i, "advance %d", &advance))
6752 else if (unformat (i, "table-index %d", &table_index))
6758 if (table_index == ~0) {
6759 errmsg ("Table index required\n");
6763 if (is_add && match == 0) {
6764 errmsg ("Match value required\n");
6768 M2 (CLASSIFY_ADD_DEL_SESSION, classify_add_del_session,
6771 mp->is_add = is_add;
6772 mp->table_index = ntohl(table_index);
6773 mp->hit_next_index = ntohl(hit_next_index);
6774 mp->opaque_index = ntohl(opaque_index);
6775 mp->advance = ntohl(advance);
6776 clib_memcpy (mp->match, match, vec_len(match));
6783 static int api_classify_set_interface_ip_table (vat_main_t * vam)
6785 unformat_input_t * i = vam->input;
6786 vl_api_classify_set_interface_ip_table_t *mp;
6789 int sw_if_index_set;
6790 u32 table_index = ~0;
6793 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
6794 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
6795 sw_if_index_set = 1;
6796 else if (unformat (i, "sw_if_index %d", &sw_if_index))
6797 sw_if_index_set = 1;
6798 else if (unformat (i, "table %d", &table_index))
6801 clib_warning ("parse error '%U'", format_unformat_error, i);
6806 if (sw_if_index_set == 0) {
6807 errmsg ("missing interface name or sw_if_index\n");
6812 M(CLASSIFY_SET_INTERFACE_IP_TABLE, classify_set_interface_ip_table);
6814 mp->sw_if_index = ntohl(sw_if_index);
6815 mp->table_index = ntohl(table_index);
6816 mp->is_ipv6 = is_ipv6;
6823 static int api_classify_set_interface_l2_tables (vat_main_t * vam)
6825 unformat_input_t * i = vam->input;
6826 vl_api_classify_set_interface_l2_tables_t *mp;
6829 int sw_if_index_set;
6830 u32 ip4_table_index = ~0;
6831 u32 ip6_table_index = ~0;
6832 u32 other_table_index = ~0;
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, "ip4-table %d", &ip4_table_index))
6841 else if (unformat (i, "ip6-table %d", &ip6_table_index))
6843 else if (unformat (i, "other-table %d", &other_table_index))
6846 clib_warning ("parse error '%U'", format_unformat_error, i);
6851 if (sw_if_index_set == 0) {
6852 errmsg ("missing interface name or sw_if_index\n");
6857 M(CLASSIFY_SET_INTERFACE_L2_TABLES, classify_set_interface_l2_tables);
6859 mp->sw_if_index = ntohl(sw_if_index);
6860 mp->ip4_table_index = ntohl(ip4_table_index);
6861 mp->ip6_table_index = ntohl(ip6_table_index);
6862 mp->other_table_index = ntohl(other_table_index);
6870 static int api_get_node_index (vat_main_t * vam)
6872 unformat_input_t * i = vam->input;
6873 vl_api_get_node_index_t * mp;
6877 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
6878 if (unformat (i, "node %s", &name))
6884 errmsg ("node name required\n");
6887 if (vec_len (name) >= ARRAY_LEN(mp->node_name)) {
6888 errmsg ("node name too long, max %d\n", ARRAY_LEN(mp->node_name));
6892 M(GET_NODE_INDEX, get_node_index);
6893 clib_memcpy (mp->node_name, name, vec_len(name));
6901 static int api_add_node_next (vat_main_t * vam)
6903 unformat_input_t * i = vam->input;
6904 vl_api_add_node_next_t * mp;
6909 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
6910 if (unformat (i, "node %s", &name))
6912 else if (unformat (i, "next %s", &next))
6918 errmsg ("node name required\n");
6921 if (vec_len (name) >= ARRAY_LEN(mp->node_name)) {
6922 errmsg ("node name too long, max %d\n", ARRAY_LEN(mp->node_name));
6926 errmsg ("next node required\n");
6929 if (vec_len (next) >= ARRAY_LEN(mp->next_name)) {
6930 errmsg ("next name too long, max %d\n", ARRAY_LEN(mp->next_name));
6934 M(ADD_NODE_NEXT, add_node_next);
6935 clib_memcpy (mp->node_name, name, vec_len(name));
6936 clib_memcpy (mp->next_name, next, vec_len(next));
6945 static int api_l2tpv3_create_tunnel (vat_main_t * vam)
6947 unformat_input_t * i = vam->input;
6948 ip6_address_t client_address, our_address;
6949 int client_address_set = 0;
6950 int our_address_set = 0;
6951 u32 local_session_id = 0;
6952 u32 remote_session_id = 0;
6953 u64 local_cookie = 0;
6954 u64 remote_cookie = 0;
6955 u8 l2_sublayer_present = 0;
6956 vl_api_l2tpv3_create_tunnel_t * mp;
6959 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
6960 if (unformat (i, "client_address %U", unformat_ip6_address,
6962 client_address_set = 1;
6963 else if (unformat (i, "our_address %U", unformat_ip6_address,
6965 our_address_set = 1;
6966 else if (unformat (i, "local_session_id %d", &local_session_id))
6968 else if (unformat (i, "remote_session_id %d", &remote_session_id))
6970 else if (unformat (i, "local_cookie %lld", &local_cookie))
6972 else if (unformat (i, "remote_cookie %lld", &remote_cookie))
6974 else if (unformat (i, "l2-sublayer-present"))
6975 l2_sublayer_present = 1;
6980 if (client_address_set == 0) {
6981 errmsg ("client_address required\n");
6985 if (our_address_set == 0) {
6986 errmsg ("our_address required\n");
6990 M(L2TPV3_CREATE_TUNNEL, l2tpv3_create_tunnel);
6992 clib_memcpy (mp->client_address, client_address.as_u8,
6993 sizeof (mp->client_address));
6995 clib_memcpy (mp->our_address, our_address.as_u8,
6996 sizeof (mp->our_address));
6998 mp->local_session_id = ntohl (local_session_id);
6999 mp->remote_session_id = ntohl (remote_session_id);
7000 mp->local_cookie = clib_host_to_net_u64 (local_cookie);
7001 mp->remote_cookie = clib_host_to_net_u64 (remote_cookie);
7002 mp->l2_sublayer_present = l2_sublayer_present;
7010 static int api_l2tpv3_set_tunnel_cookies (vat_main_t * vam)
7012 unformat_input_t * i = vam->input;
7014 u8 sw_if_index_set = 0;
7015 u64 new_local_cookie = 0;
7016 u64 new_remote_cookie = 0;
7017 vl_api_l2tpv3_set_tunnel_cookies_t *mp;
7020 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
7021 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
7022 sw_if_index_set = 1;
7023 else if (unformat (i, "sw_if_index %d", &sw_if_index))
7024 sw_if_index_set = 1;
7025 else if (unformat (i, "new_local_cookie %lld", &new_local_cookie))
7027 else if (unformat (i, "new_remote_cookie %lld", &new_remote_cookie))
7033 if (sw_if_index_set == 0) {
7034 errmsg ("missing interface name or sw_if_index\n");
7038 M(L2TPV3_SET_TUNNEL_COOKIES, l2tpv3_set_tunnel_cookies);
7040 mp->sw_if_index = ntohl(sw_if_index);
7041 mp->new_local_cookie = clib_host_to_net_u64 (new_local_cookie);
7042 mp->new_remote_cookie = clib_host_to_net_u64 (new_remote_cookie);
7049 static int api_l2tpv3_interface_enable_disable (vat_main_t * vam)
7051 unformat_input_t * i = vam->input;
7052 vl_api_l2tpv3_interface_enable_disable_t *mp;
7055 u8 sw_if_index_set = 0;
7056 u8 enable_disable = 1;
7058 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
7059 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
7060 sw_if_index_set = 1;
7061 else if (unformat (i, "sw_if_index %d", &sw_if_index))
7062 sw_if_index_set = 1;
7063 else if (unformat (i, "enable"))
7065 else if (unformat (i, "disable"))
7071 if (sw_if_index_set == 0) {
7072 errmsg ("missing interface name or sw_if_index\n");
7076 M(L2TPV3_INTERFACE_ENABLE_DISABLE, l2tpv3_interface_enable_disable);
7078 mp->sw_if_index = ntohl(sw_if_index);
7079 mp->enable_disable = enable_disable;
7086 static int api_l2tpv3_set_lookup_key (vat_main_t * vam)
7088 unformat_input_t * i = vam->input;
7089 vl_api_l2tpv3_set_lookup_key_t * mp;
7093 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
7094 if (unformat (i, "lookup_v6_src"))
7095 key = L2T_LOOKUP_SRC_ADDRESS;
7096 else if (unformat (i, "lookup_v6_dst"))
7097 key = L2T_LOOKUP_DST_ADDRESS;
7098 else if (unformat (i, "lookup_session_id"))
7099 key = L2T_LOOKUP_SESSION_ID;
7104 if (key == (u8) ~0) {
7105 errmsg ("l2tp session lookup key unset\n");
7109 M(L2TPV3_SET_LOOKUP_KEY, l2tpv3_set_lookup_key);
7118 static void vl_api_sw_if_l2tpv3_tunnel_details_t_handler
7119 (vl_api_sw_if_l2tpv3_tunnel_details_t * mp)
7121 vat_main_t * vam = &vat_main;
7123 fformat(vam->ofp, "* %U (our) %U (client) (sw_if_index %d)\n",
7124 format_ip6_address, mp->our_address,
7125 format_ip6_address, mp->client_address,
7126 clib_net_to_host_u32(mp->sw_if_index));
7128 fformat (vam->ofp, " local cookies %016llx %016llx remote cookie %016llx\n",
7129 clib_net_to_host_u64 (mp->local_cookie[0]),
7130 clib_net_to_host_u64 (mp->local_cookie[1]),
7131 clib_net_to_host_u64 (mp->remote_cookie));
7133 fformat (vam->ofp, " local session-id %d remote session-id %d\n",
7134 clib_net_to_host_u32 (mp->local_session_id),
7135 clib_net_to_host_u32 (mp->remote_session_id));
7137 fformat (vam->ofp, " l2 specific sublayer %s\n\n",
7138 mp->l2_sublayer_present ? "preset" : "absent");
7142 static void vl_api_sw_if_l2tpv3_tunnel_details_t_handler_json
7143 (vl_api_sw_if_l2tpv3_tunnel_details_t * mp)
7145 vat_main_t * vam = &vat_main;
7146 vat_json_node_t *node = NULL;
7147 struct in6_addr addr;
7149 if (VAT_JSON_ARRAY != vam->json_tree.type) {
7150 ASSERT(VAT_JSON_NONE == vam->json_tree.type);
7151 vat_json_init_array(&vam->json_tree);
7153 node = vat_json_array_add(&vam->json_tree);
7155 vat_json_init_object(node);
7157 clib_memcpy(&addr, mp->our_address, sizeof(addr));
7158 vat_json_object_add_ip6(node, "our_address", addr);
7159 clib_memcpy(&addr, mp->client_address, sizeof(addr));
7160 vat_json_object_add_ip6(node, "client_address", addr);
7162 vat_json_node_t * lc = vat_json_object_add(node, "local_cookie");
7163 vat_json_init_array(lc);
7164 vat_json_array_add_uint(lc, clib_net_to_host_u64(mp->local_cookie[0]));
7165 vat_json_array_add_uint(lc, clib_net_to_host_u64(mp->local_cookie[1]));
7166 vat_json_object_add_uint(node, "remote_cookie", clib_net_to_host_u64(mp->remote_cookie));
7168 printf("local id: %u", clib_net_to_host_u32(mp->local_session_id));
7169 vat_json_object_add_uint(node, "local_session_id", clib_net_to_host_u32(mp->local_session_id));
7170 vat_json_object_add_uint(node, "remote_session_id", clib_net_to_host_u32(mp->remote_session_id));
7171 vat_json_object_add_string_copy(node, "l2_sublayer", mp->l2_sublayer_present ?
7172 (u8*)"present" : (u8*)"absent");
7175 static int api_sw_if_l2tpv3_tunnel_dump (vat_main_t * vam)
7177 vl_api_sw_if_l2tpv3_tunnel_dump_t *mp;
7180 /* Get list of l2tpv3-tunnel interfaces */
7181 M(SW_IF_L2TPV3_TUNNEL_DUMP, sw_if_l2tpv3_tunnel_dump);
7184 /* Use a control ping for synchronization */
7186 vl_api_control_ping_t * mp;
7187 M(CONTROL_PING, control_ping);
7194 static void vl_api_sw_interface_tap_details_t_handler
7195 (vl_api_sw_interface_tap_details_t * mp)
7197 vat_main_t * vam = &vat_main;
7199 fformat(vam->ofp, "%-16s %d\n",
7201 clib_net_to_host_u32(mp->sw_if_index));
7204 static void vl_api_sw_interface_tap_details_t_handler_json
7205 (vl_api_sw_interface_tap_details_t * mp)
7207 vat_main_t * vam = &vat_main;
7208 vat_json_node_t *node = NULL;
7210 if (VAT_JSON_ARRAY != vam->json_tree.type) {
7211 ASSERT(VAT_JSON_NONE == vam->json_tree.type);
7212 vat_json_init_array(&vam->json_tree);
7214 node = vat_json_array_add(&vam->json_tree);
7216 vat_json_init_object(node);
7217 vat_json_object_add_uint(node, "sw_if_index", ntohl(mp->sw_if_index));
7218 vat_json_object_add_string_copy(node, "dev_name", mp->dev_name);
7221 static int api_sw_interface_tap_dump (vat_main_t * vam)
7223 vl_api_sw_interface_tap_dump_t *mp;
7226 fformat(vam->ofp, "\n%-16s %s\n", "dev_name", "sw_if_index");
7227 /* Get list of tap interfaces */
7228 M(SW_INTERFACE_TAP_DUMP, sw_interface_tap_dump);
7231 /* Use a control ping for synchronization */
7233 vl_api_control_ping_t * mp;
7234 M(CONTROL_PING, control_ping);
7240 static uword unformat_vxlan_decap_next
7241 (unformat_input_t * input, va_list * args)
7243 u32 * result = va_arg (*args, u32 *);
7246 if (unformat (input, "drop"))
7247 *result = VXLAN_INPUT_NEXT_DROP;
7248 else if (unformat (input, "ip4"))
7249 *result = VXLAN_INPUT_NEXT_IP4_INPUT;
7250 else if (unformat (input, "ip6"))
7251 *result = VXLAN_INPUT_NEXT_IP6_INPUT;
7252 else if (unformat (input, "l2"))
7253 *result = VXLAN_INPUT_NEXT_L2_INPUT;
7254 else if (unformat (input, "%d", &tmp))
7261 static int api_vxlan_add_del_tunnel (vat_main_t * vam)
7263 unformat_input_t * line_input = vam->input;
7264 vl_api_vxlan_add_del_tunnel_t *mp;
7266 ip4_address_t src4, dst4;
7267 ip6_address_t src6, dst6;
7269 u8 ipv4_set = 0, ipv6_set = 0;
7272 u32 encap_vrf_id = 0;
7273 u32 decap_next_index = ~0;
7276 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) {
7277 if (unformat (line_input, "del"))
7279 else if (unformat (line_input, "src %U",
7280 unformat_ip4_address, &src4))
7285 else if (unformat (line_input, "dst %U",
7286 unformat_ip4_address, &dst4))
7291 else if (unformat (line_input, "src %U",
7292 unformat_ip6_address, &src6))
7297 else if (unformat (line_input, "dst %U",
7298 unformat_ip6_address, &dst6))
7303 else if (unformat (line_input, "encap-vrf-id %d", &encap_vrf_id))
7305 else if (unformat (line_input, "decap-next %U",
7306 unformat_vxlan_decap_next, &decap_next_index))
7308 else if (unformat (line_input, "vni %d", &vni))
7311 errmsg ("parse error '%U'\n", format_unformat_error, line_input);
7317 errmsg ("tunnel src address not specified\n");
7321 errmsg ("tunnel dst address not specified\n");
7325 if (ipv4_set && ipv6_set) {
7326 errmsg ("both IPv4 and IPv6 addresses specified");
7330 if ((vni == 0) || (vni>>24)) {
7331 errmsg ("vni not specified or out of range\n");
7335 M (VXLAN_ADD_DEL_TUNNEL, vxlan_add_del_tunnel);
7338 clib_memcpy(&mp->dst_address, &src6, sizeof(src6));
7339 clib_memcpy(&mp->dst_address, &src6, sizeof(dst6));
7341 clib_memcpy(&mp->src_address, &src4, sizeof(src4));
7342 clib_memcpy(&mp->dst_address, &dst4, sizeof(dst4));
7344 mp->encap_vrf_id = ntohl(encap_vrf_id);
7345 mp->decap_next_index = ntohl(decap_next_index);
7346 mp->vni = ntohl(vni);
7347 mp->is_add = is_add;
7348 mp->is_ipv6 = ipv6_set;
7355 static void vl_api_vxlan_tunnel_details_t_handler
7356 (vl_api_vxlan_tunnel_details_t * mp)
7358 vat_main_t * vam = &vat_main;
7360 fformat(vam->ofp, "%11d%24U%24U%14d%18d%13d\n",
7361 ntohl(mp->sw_if_index),
7362 format_ip46_address, &(mp->src_address[0]),
7363 format_ip46_address, &(mp->dst_address[0]),
7364 ntohl(mp->encap_vrf_id),
7365 ntohl(mp->decap_next_index),
7369 static void vl_api_vxlan_tunnel_details_t_handler_json
7370 (vl_api_vxlan_tunnel_details_t * mp)
7372 vat_main_t * vam = &vat_main;
7373 vat_json_node_t *node = NULL;
7375 struct in6_addr ip6;
7377 if (VAT_JSON_ARRAY != vam->json_tree.type) {
7378 ASSERT(VAT_JSON_NONE == vam->json_tree.type);
7379 vat_json_init_array(&vam->json_tree);
7381 node = vat_json_array_add(&vam->json_tree);
7383 vat_json_init_object(node);
7384 vat_json_object_add_uint(node, "sw_if_index", ntohl(mp->sw_if_index));
7386 clib_memcpy(&ip6, &(mp->src_address[0]), sizeof(ip6));
7387 vat_json_object_add_ip6(node, "src_address", ip6);
7388 clib_memcpy(&ip6, &(mp->dst_address[0]), sizeof(ip6));
7389 vat_json_object_add_ip6(node, "dst_address", ip6);
7391 clib_memcpy(&ip4, &(mp->src_address[0]), sizeof(ip4));
7392 vat_json_object_add_ip4(node, "src_address", ip4);
7393 clib_memcpy(&ip4, &(mp->dst_address[0]), sizeof(ip4));
7394 vat_json_object_add_ip4(node, "dst_address", ip4);
7396 vat_json_object_add_uint(node, "encap_vrf_id", ntohl(mp->encap_vrf_id));
7397 vat_json_object_add_uint(node, "decap_next_index", ntohl(mp->decap_next_index));
7398 vat_json_object_add_uint(node, "vni", ntohl(mp->vni));
7399 vat_json_object_add_uint(node, "is_ipv6", mp->is_ipv6 ? 1 : 0);
7402 static int api_vxlan_tunnel_dump (vat_main_t * vam)
7404 unformat_input_t * i = vam->input;
7405 vl_api_vxlan_tunnel_dump_t *mp;
7408 u8 sw_if_index_set = 0;
7410 /* Parse args required to build the message */
7411 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
7412 if (unformat (i, "sw_if_index %d", &sw_if_index))
7413 sw_if_index_set = 1;
7418 if (sw_if_index_set == 0) {
7422 if (!vam->json_output) {
7423 fformat(vam->ofp, "%11s%24s%24s%14s%18s%13s\n",
7424 "sw_if_index", "src_address", "dst_address",
7425 "encap_vrf_id", "decap_next_index", "vni");
7428 /* Get list of vxlan-tunnel interfaces */
7429 M(VXLAN_TUNNEL_DUMP, vxlan_tunnel_dump);
7431 mp->sw_if_index = htonl(sw_if_index);
7435 /* Use a control ping for synchronization */
7437 vl_api_control_ping_t * mp;
7438 M(CONTROL_PING, control_ping);
7444 static int api_gre_add_del_tunnel (vat_main_t * vam)
7446 unformat_input_t * line_input = vam->input;
7447 vl_api_gre_add_del_tunnel_t *mp;
7449 ip4_address_t src4, dst4;
7453 u32 outer_fib_id = 0;
7455 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) {
7456 if (unformat (line_input, "del"))
7458 else if (unformat (line_input, "src %U",
7459 unformat_ip4_address, &src4))
7461 else if (unformat (line_input, "dst %U",
7462 unformat_ip4_address, &dst4))
7464 else if (unformat (line_input, "outer-fib-id %d", &outer_fib_id))
7467 errmsg ("parse error '%U'\n", format_unformat_error, line_input);
7473 errmsg ("tunnel src address not specified\n");
7477 errmsg ("tunnel dst address not specified\n");
7482 M (GRE_ADD_DEL_TUNNEL, gre_add_del_tunnel);
7484 clib_memcpy(&mp->src_address, &src4, sizeof(src4));
7485 clib_memcpy(&mp->dst_address, &dst4, sizeof(dst4));
7486 mp->outer_table_id = ntohl(outer_fib_id);
7487 mp->is_add = is_add;
7494 static void vl_api_gre_tunnel_details_t_handler
7495 (vl_api_gre_tunnel_details_t * mp)
7497 vat_main_t * vam = &vat_main;
7499 fformat(vam->ofp, "%11d%15U%15U%14d\n",
7500 ntohl(mp->sw_if_index),
7501 format_ip4_address, &mp->src_address,
7502 format_ip4_address, &mp->dst_address,
7503 ntohl(mp->outer_table_id));
7506 static void vl_api_gre_tunnel_details_t_handler_json
7507 (vl_api_gre_tunnel_details_t * mp)
7509 vat_main_t * vam = &vat_main;
7510 vat_json_node_t *node = NULL;
7513 if (VAT_JSON_ARRAY != vam->json_tree.type) {
7514 ASSERT(VAT_JSON_NONE == vam->json_tree.type);
7515 vat_json_init_array(&vam->json_tree);
7517 node = vat_json_array_add(&vam->json_tree);
7519 vat_json_init_object(node);
7520 vat_json_object_add_uint(node, "sw_if_index", ntohl(mp->sw_if_index));
7521 clib_memcpy(&ip4, &mp->src_address, sizeof(ip4));
7522 vat_json_object_add_ip4(node, "src_address", ip4);
7523 clib_memcpy(&ip4, &mp->dst_address, sizeof(ip4));
7524 vat_json_object_add_ip4(node, "dst_address", ip4);
7525 vat_json_object_add_uint(node, "outer_fib_id", ntohl(mp->outer_table_id));
7528 static int api_gre_tunnel_dump (vat_main_t * vam)
7530 unformat_input_t * i = vam->input;
7531 vl_api_gre_tunnel_dump_t *mp;
7534 u8 sw_if_index_set = 0;
7536 /* Parse args required to build the message */
7537 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
7538 if (unformat (i, "sw_if_index %d", &sw_if_index))
7539 sw_if_index_set = 1;
7544 if (sw_if_index_set == 0) {
7548 if (!vam->json_output) {
7549 fformat(vam->ofp, "%11s%15s%15s%14s\n",
7550 "sw_if_index", "src_address", "dst_address",
7554 /* Get list of gre-tunnel interfaces */
7555 M(GRE_TUNNEL_DUMP, gre_tunnel_dump);
7557 mp->sw_if_index = htonl(sw_if_index);
7561 /* Use a control ping for synchronization */
7563 vl_api_control_ping_t * mp;
7564 M(CONTROL_PING, control_ping);
7570 static int api_l2_fib_clear_table (vat_main_t * vam)
7572 // unformat_input_t * i = vam->input;
7573 vl_api_l2_fib_clear_table_t *mp;
7576 M(L2_FIB_CLEAR_TABLE, l2_fib_clear_table);
7583 static int api_l2_interface_efp_filter (vat_main_t * vam)
7585 unformat_input_t * i = vam->input;
7586 vl_api_l2_interface_efp_filter_t *mp;
7590 u8 sw_if_index_set = 0;
7592 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
7593 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
7594 sw_if_index_set = 1;
7595 else if (unformat (i, "sw_if_index %d", &sw_if_index))
7596 sw_if_index_set = 1;
7597 else if (unformat (i, "enable"))
7599 else if (unformat (i, "disable"))
7602 clib_warning ("parse error '%U'", format_unformat_error, i);
7607 if (sw_if_index_set == 0) {
7608 errmsg ("missing sw_if_index\n");
7612 M(L2_INTERFACE_EFP_FILTER, l2_interface_efp_filter);
7614 mp->sw_if_index = ntohl(sw_if_index);
7615 mp->enable_disable = enable;
7622 #define foreach_vtr_op \
7623 _("disable", L2_VTR_DISABLED) \
7624 _("push-1", L2_VTR_PUSH_1) \
7625 _("push-2", L2_VTR_PUSH_2) \
7626 _("pop-1", L2_VTR_POP_1) \
7627 _("pop-2", L2_VTR_POP_2) \
7628 _("translate-1-1", L2_VTR_TRANSLATE_1_1) \
7629 _("translate-1-2", L2_VTR_TRANSLATE_1_2) \
7630 _("translate-2-1", L2_VTR_TRANSLATE_2_1) \
7631 _("translate-2-2", L2_VTR_TRANSLATE_2_2)
7633 static int api_l2_interface_vlan_tag_rewrite (vat_main_t * vam)
7635 unformat_input_t * i = vam->input;
7636 vl_api_l2_interface_vlan_tag_rewrite_t *mp;
7639 u8 sw_if_index_set = 0;
7646 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
7647 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
7648 sw_if_index_set = 1;
7649 else if (unformat (i, "sw_if_index %d", &sw_if_index))
7650 sw_if_index_set = 1;
7651 else if (unformat (i, "vtr_op %d", &vtr_op))
7653 #define _(n,v) else if (unformat(i, n)) {vtr_op = v; vtr_op_set = 1;}
7657 else if (unformat (i, "push_dot1q %d", &push_dot1q))
7659 else if (unformat (i, "tag1 %d", &tag1))
7661 else if (unformat (i, "tag2 %d", &tag2))
7664 clib_warning ("parse error '%U'", format_unformat_error, i);
7669 if ((sw_if_index_set == 0)||(vtr_op_set == 0)) {
7670 errmsg ("missing vtr operation or sw_if_index\n");
7674 M(L2_INTERFACE_VLAN_TAG_REWRITE, l2_interface_vlan_tag_rewrite)
7676 mp->sw_if_index = ntohl(sw_if_index);
7677 mp->vtr_op = ntohl(vtr_op);
7678 mp->push_dot1q = ntohl(push_dot1q);
7679 mp->tag1 = ntohl(tag1);
7680 mp->tag2 = ntohl(tag2);
7687 static int api_create_vhost_user_if (vat_main_t * vam)
7689 unformat_input_t * i = vam->input;
7690 vl_api_create_vhost_user_if_t *mp;
7694 u8 file_name_set = 0;
7695 u32 custom_dev_instance = ~0;
7697 u8 use_custom_mac = 0;
7699 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
7700 if (unformat (i, "socket %s", &file_name)) {
7703 else if (unformat (i, "renumber %"PRIu32, &custom_dev_instance))
7705 else if (unformat (i, "mac %U", unformat_ethernet_address, hwaddr))
7707 else if (unformat (i, "server"))
7713 if (file_name_set == 0) {
7714 errmsg ("missing socket file name\n");
7718 if (vec_len (file_name) > 255) {
7719 errmsg ("socket file name too long\n");
7722 vec_add1 (file_name, 0);
7724 M(CREATE_VHOST_USER_IF, create_vhost_user_if);
7726 mp->is_server = is_server;
7727 clib_memcpy(mp->sock_filename, file_name, vec_len(file_name));
7728 vec_free(file_name);
7729 if (custom_dev_instance != ~0) {
7731 mp->custom_dev_instance = ntohl(custom_dev_instance);
7733 mp->use_custom_mac = use_custom_mac;
7734 clib_memcpy(mp->mac_address, hwaddr, 6);
7741 static int api_modify_vhost_user_if (vat_main_t * vam)
7743 unformat_input_t * i = vam->input;
7744 vl_api_modify_vhost_user_if_t *mp;
7748 u8 file_name_set = 0;
7749 u32 custom_dev_instance = ~0;
7750 u8 sw_if_index_set = 0;
7751 u32 sw_if_index = (u32)~0;
7753 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
7754 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
7755 sw_if_index_set = 1;
7756 else if (unformat (i, "sw_if_index %d", &sw_if_index))
7757 sw_if_index_set = 1;
7758 else if (unformat (i, "socket %s", &file_name)) {
7761 else if (unformat (i, "renumber %"PRIu32, &custom_dev_instance))
7763 else if (unformat (i, "server"))
7769 if (sw_if_index_set == 0) {
7770 errmsg ("missing sw_if_index or interface name\n");
7774 if (file_name_set == 0) {
7775 errmsg ("missing socket file name\n");
7779 if (vec_len (file_name) > 255) {
7780 errmsg ("socket file name too long\n");
7783 vec_add1 (file_name, 0);
7785 M(MODIFY_VHOST_USER_IF, modify_vhost_user_if);
7787 mp->sw_if_index = ntohl(sw_if_index);
7788 mp->is_server = is_server;
7789 clib_memcpy(mp->sock_filename, file_name, vec_len(file_name));
7790 vec_free(file_name);
7791 if (custom_dev_instance != ~0) {
7793 mp->custom_dev_instance = ntohl(custom_dev_instance);
7801 static int api_delete_vhost_user_if (vat_main_t * vam)
7803 unformat_input_t * i = vam->input;
7804 vl_api_delete_vhost_user_if_t *mp;
7806 u32 sw_if_index = ~0;
7807 u8 sw_if_index_set = 0;
7809 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
7810 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
7811 sw_if_index_set = 1;
7812 else if (unformat (i, "sw_if_index %d", &sw_if_index))
7813 sw_if_index_set = 1;
7818 if (sw_if_index_set == 0) {
7819 errmsg ("missing sw_if_index or interface name\n");
7824 M(DELETE_VHOST_USER_IF, delete_vhost_user_if);
7826 mp->sw_if_index = ntohl(sw_if_index);
7833 static void vl_api_sw_interface_vhost_user_details_t_handler
7834 (vl_api_sw_interface_vhost_user_details_t * mp)
7836 vat_main_t * vam = &vat_main;
7838 fformat(vam->ofp, "%-25s %3" PRIu32 " %6" PRIu32 " %8x %6d %7d %s\n",
7839 (char *)mp->interface_name,
7840 ntohl(mp->sw_if_index), ntohl(mp->virtio_net_hdr_sz),
7841 clib_net_to_host_u64(mp->features), mp->is_server,
7842 ntohl(mp->num_regions), (char *)mp->sock_filename);
7843 fformat(vam->ofp, " Status: '%s'\n", strerror(ntohl(mp->sock_errno)));
7846 static void vl_api_sw_interface_vhost_user_details_t_handler_json
7847 (vl_api_sw_interface_vhost_user_details_t * mp)
7849 vat_main_t * vam = &vat_main;
7850 vat_json_node_t *node = NULL;
7852 if (VAT_JSON_ARRAY != vam->json_tree.type) {
7853 ASSERT(VAT_JSON_NONE == vam->json_tree.type);
7854 vat_json_init_array(&vam->json_tree);
7856 node = vat_json_array_add(&vam->json_tree);
7858 vat_json_init_object(node);
7859 vat_json_object_add_uint(node, "sw_if_index", ntohl(mp->sw_if_index));
7860 vat_json_object_add_string_copy(node, "interface_name", mp->interface_name);
7861 vat_json_object_add_uint(node, "virtio_net_hdr_sz", ntohl(mp->virtio_net_hdr_sz));
7862 vat_json_object_add_uint(node, "features", clib_net_to_host_u64(mp->features));
7863 vat_json_object_add_uint(node, "is_server", mp->is_server);
7864 vat_json_object_add_string_copy(node, "sock_filename", mp->sock_filename);
7865 vat_json_object_add_uint(node, "num_regions", ntohl(mp->num_regions));
7866 vat_json_object_add_uint(node, "sock_errno", ntohl(mp->sock_errno));
7869 static int api_sw_interface_vhost_user_dump (vat_main_t * vam)
7871 vl_api_sw_interface_vhost_user_dump_t *mp;
7873 fformat(vam->ofp, "Interface name idx hdr_sz features server regions filename\n");
7875 /* Get list of vhost-user interfaces */
7876 M(SW_INTERFACE_VHOST_USER_DUMP, sw_interface_vhost_user_dump);
7879 /* Use a control ping for synchronization */
7881 vl_api_control_ping_t * mp;
7882 M(CONTROL_PING, control_ping);
7888 static int api_show_version (vat_main_t * vam)
7890 vl_api_show_version_t *mp;
7893 M(SHOW_VERSION, show_version);
7900 static uword unformat_nsh_gre_decap_next
7901 (unformat_input_t * input, va_list * args)
7903 u32 * result = va_arg (*args, u32 *);
7906 if (unformat (input, "drop"))
7907 *result = NSH_GRE_INPUT_NEXT_DROP;
7908 else if (unformat (input, "ip4"))
7909 *result = NSH_GRE_INPUT_NEXT_IP4_INPUT;
7910 else if (unformat (input, "ip6"))
7911 *result = NSH_GRE_INPUT_NEXT_IP6_INPUT;
7912 else if (unformat (input, "ethernet"))
7913 *result = NSH_GRE_INPUT_NEXT_ETHERNET_INPUT;
7914 else if (unformat (input, "%d", &tmp))
7921 static int api_nsh_gre_add_del_tunnel (vat_main_t * vam)
7923 unformat_input_t * line_input = vam->input;
7924 vl_api_nsh_gre_add_del_tunnel_t *mp;
7926 ip4_address_t src, dst;
7930 u32 encap_vrf_id = 0;
7931 u32 decap_vrf_id = 0;
7934 u8 next_protocol = 1; /* ip4 */
7945 u32 decap_next_index = NSH_GRE_INPUT_NEXT_IP4_INPUT;
7949 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) {
7950 if (unformat (line_input, "del"))
7952 else if (unformat (line_input, "src %U",
7953 unformat_ip4_address, &src))
7955 else if (unformat (line_input, "dst %U",
7956 unformat_ip4_address, &dst))
7958 else if (unformat (line_input, "encap-vrf-id %d", &encap_vrf_id))
7960 else if (unformat (line_input, "decap-vrf-id %d", &decap_vrf_id))
7962 else if (unformat (line_input, "decap-next %U",
7963 unformat_nsh_gre_decap_next, &decap_next_index))
7965 else if (unformat (line_input, "version %d", &tmp))
7966 ver_o_c |= (tmp & 3) << 6;
7967 else if (unformat (line_input, "o-bit %d", &tmp))
7968 ver_o_c |= (tmp & 1) << 5;
7969 else if (unformat (line_input, "c-bit %d", &tmp))
7970 ver_o_c |= (tmp & 1) << 4;
7971 else if (unformat (line_input, "md-type %d", &tmp))
7973 else if (unformat(line_input, "next-ip4"))
7975 else if (unformat(line_input, "next-ip6"))
7977 else if (unformat(line_input, "next-ethernet"))
7979 else if (unformat (line_input, "c1 %d", &c1))
7981 else if (unformat (line_input, "c2 %d", &c2))
7983 else if (unformat (line_input, "c3 %d", &c3))
7985 else if (unformat (line_input, "c4 %d", &c4))
7987 else if (unformat (line_input, "spi %d", &spi))
7989 else if (unformat (line_input, "si %d", &si))
7991 else if (unformat (line_input, "tlv %x"))
7992 vec_add1 (tlvs, tmp);
7994 errmsg ("parse error '%U'\n", format_unformat_error, line_input);
8000 errmsg ("tunnel src address not specified\n");
8004 errmsg ("tunnel dst address not specified\n");
8009 errmsg ("spi not specified\n");
8014 errmsg ("si not specified\n");
8018 M2 (NSH_GRE_ADD_DEL_TUNNEL, nsh_gre_add_del_tunnel,
8019 sizeof(u32) * vec_len (tlvs));
8021 spi_si = (spi<<8) | si;
8023 mp->src = src.as_u32;
8024 mp->dst = dst.as_u32;
8025 mp->encap_vrf_id = ntohl(encap_vrf_id);
8026 mp->decap_vrf_id = ntohl(decap_vrf_id);
8027 mp->decap_next_index = ntohl(decap_next_index);
8028 mp->tlv_len_in_words = vec_len (tlvs);
8029 mp->is_add = is_add;
8030 mp->ver_o_c = ver_o_c;
8031 mp->length = 6 + vec_len(tlvs);
8032 mp->md_type = md_type;
8033 mp->next_protocol = next_protocol;
8034 mp->spi_si = ntohl(spi_si);
8040 for (i = 0; i < vec_len(tlvs); i++)
8041 mp->tlvs[i] = ntohl(tlvs[i]);
8050 static uword unformat_nsh_vxlan_gpe_decap_next
8051 (unformat_input_t * input, va_list * args)
8053 u32 * result = va_arg (*args, u32 *);
8056 if (unformat (input, "drop"))
8057 *result = NSH_VXLAN_GPE_INPUT_NEXT_DROP;
8058 else if (unformat (input, "ip4"))
8059 *result = NSH_VXLAN_GPE_INPUT_NEXT_IP4_INPUT;
8060 else if (unformat (input, "ip6"))
8061 *result = NSH_VXLAN_GPE_INPUT_NEXT_IP6_INPUT;
8062 else if (unformat (input, "ethernet"))
8063 *result = NSH_VXLAN_GPE_INPUT_NEXT_ETHERNET_INPUT;
8064 else if (unformat (input, "nsh-vxlan-gpe"))
8065 *result = NSH_VXLAN_GPE_INPUT_NEXT_ETHERNET_INPUT;
8066 else if (unformat (input, "%d", &tmp))
8073 static int api_nsh_vxlan_gpe_add_del_tunnel (vat_main_t * vam)
8075 unformat_input_t * line_input = vam->input;
8076 vl_api_nsh_vxlan_gpe_add_del_tunnel_t *mp;
8078 ip4_address_t src, dst;
8082 u32 encap_vrf_id = 0;
8083 u32 decap_vrf_id = 0;
8086 u8 next_protocol = 1; /* ip4 */
8097 u32 decap_next_index = NSH_GRE_INPUT_NEXT_IP4_INPUT;
8103 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) {
8104 if (unformat (line_input, "del"))
8106 else if (unformat (line_input, "src %U",
8107 unformat_ip4_address, &src))
8109 else if (unformat (line_input, "dst %U",
8110 unformat_ip4_address, &dst))
8112 else if (unformat (line_input, "encap-vrf-id %d", &encap_vrf_id))
8114 else if (unformat (line_input, "decap-vrf-id %d", &decap_vrf_id))
8116 else if (unformat (line_input, "decap-next %U",
8117 unformat_nsh_vxlan_gpe_decap_next,
8120 else if (unformat (line_input, "vni %d", &vni))
8122 else if (unformat (line_input, "version %d", &tmp))
8123 ver_o_c |= (tmp & 3) << 6;
8124 else if (unformat (line_input, "o-bit %d", &tmp))
8125 ver_o_c |= (tmp & 1) << 5;
8126 else if (unformat (line_input, "c-bit %d", &tmp))
8127 ver_o_c |= (tmp & 1) << 4;
8128 else if (unformat (line_input, "md-type %d", &tmp))
8130 else if (unformat(line_input, "next-ip4"))
8132 else if (unformat(line_input, "next-ip6"))
8134 else if (unformat(line_input, "next-ethernet"))
8136 else if (unformat (line_input, "c1 %d", &c1))
8138 else if (unformat (line_input, "c2 %d", &c2))
8140 else if (unformat (line_input, "c3 %d", &c3))
8142 else if (unformat (line_input, "c4 %d", &c4))
8144 else if (unformat (line_input, "spi %d", &spi))
8146 else if (unformat (line_input, "si %d", &si))
8148 else if (unformat (line_input, "tlv %x"))
8149 vec_add1 (tlvs, tmp);
8151 errmsg ("parse error '%U'\n", format_unformat_error, line_input);
8157 errmsg ("tunnel src address not specified\n");
8161 errmsg ("tunnel dst address not specified\n");
8166 errmsg ("spi not specified\n");
8171 errmsg ("si not specified\n");
8175 errmsg ("vni not specified\n");
8179 M2 (NSH_VXLAN_GPE_ADD_DEL_TUNNEL, nsh_vxlan_gpe_add_del_tunnel,
8180 sizeof(u32) * vec_len (tlvs));
8182 spi_si = (spi<<8) | si;
8184 mp->src = src.as_u32;
8185 mp->dst = dst.as_u32;
8186 mp->encap_vrf_id = ntohl(encap_vrf_id);
8187 mp->decap_vrf_id = ntohl(decap_vrf_id);
8188 mp->decap_next_index = ntohl(decap_next_index);
8189 mp->tlv_len_in_words = vec_len (tlvs);
8190 mp->vni = ntohl(vni);
8191 mp->is_add = is_add;
8192 mp->ver_o_c = ver_o_c;
8193 mp->length = 6 + vec_len(tlvs);
8194 mp->md_type = md_type;
8195 mp->next_protocol = next_protocol;
8196 mp->spi_si = ntohl(spi_si);
8202 for (i = 0; i < vec_len(tlvs); i++)
8203 mp->tlvs[i] = ntohl(tlvs[i]);
8212 u8 * format_l2_fib_mac_address (u8 * s, va_list * args)
8214 u8 * a = va_arg (*args, u8 *);
8216 return format (s, "%02x:%02x:%02x:%02x:%02x:%02x",
8217 a[2], a[3], a[4], a[5], a[6], a[7]);
8220 static void vl_api_l2_fib_table_entry_t_handler
8221 (vl_api_l2_fib_table_entry_t * mp)
8223 vat_main_t * vam = &vat_main;
8225 fformat(vam->ofp, "%3" PRIu32 " %U %3" PRIu32
8227 ntohl(mp->bd_id), format_l2_fib_mac_address, &mp->mac,
8228 ntohl(mp->sw_if_index), mp->static_mac, mp->filter_mac,
8232 static void vl_api_l2_fib_table_entry_t_handler_json
8233 (vl_api_l2_fib_table_entry_t * mp)
8235 vat_main_t * vam = &vat_main;
8236 vat_json_node_t *node = NULL;
8238 if (VAT_JSON_ARRAY != vam->json_tree.type) {
8239 ASSERT(VAT_JSON_NONE == vam->json_tree.type);
8240 vat_json_init_array(&vam->json_tree);
8242 node = vat_json_array_add(&vam->json_tree);
8244 vat_json_init_object(node);
8245 vat_json_object_add_uint(node, "bd_id", ntohl(mp->bd_id));
8246 vat_json_object_add_uint(node, "mac", clib_net_to_host_u64(mp->mac));
8247 vat_json_object_add_uint(node, "sw_if_index", ntohl(mp->sw_if_index));
8248 vat_json_object_add_uint(node, "static_mac", mp->static_mac);
8249 vat_json_object_add_uint(node, "filter_mac", mp->filter_mac);
8250 vat_json_object_add_uint(node, "bvi_mac", mp->bvi_mac);
8253 static int api_l2_fib_table_dump (vat_main_t * vam)
8255 unformat_input_t * i = vam->input;
8256 vl_api_l2_fib_table_dump_t *mp;
8261 /* Parse args required to build the message */
8262 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
8263 if (unformat (i, "bd_id %d", &bd_id))
8269 if (bd_id_set == 0) {
8270 errmsg ("missing bridge domain\n");
8274 fformat(vam->ofp, "BD-ID Mac Address sw-ndx Static Filter BVI\n");
8276 /* Get list of l2 fib entries */
8277 M(L2_FIB_TABLE_DUMP, l2_fib_table_dump);
8279 mp->bd_id = ntohl(bd_id);
8282 /* Use a control ping for synchronization */
8284 vl_api_control_ping_t * mp;
8285 M(CONTROL_PING, control_ping);
8293 api_interface_name_renumber (vat_main_t * vam)
8295 unformat_input_t * line_input = vam->input;
8296 vl_api_interface_name_renumber_t *mp;
8297 u32 sw_if_index = ~0;
8299 u32 new_show_dev_instance = ~0;
8301 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) {
8302 if (unformat (line_input, "%U", unformat_sw_if_index, vam,
8305 else if (unformat (line_input, "sw_if_index %d", &sw_if_index))
8307 else if (unformat (line_input, "new_show_dev_instance %d",
8308 &new_show_dev_instance))
8314 if (sw_if_index == ~0) {
8315 errmsg ("missing interface name or sw_if_index\n");
8319 if (new_show_dev_instance == ~0) {
8320 errmsg ("missing new_show_dev_instance\n");
8324 M(INTERFACE_NAME_RENUMBER, interface_name_renumber);
8326 mp->sw_if_index = ntohl (sw_if_index);
8327 mp->new_show_dev_instance = ntohl (new_show_dev_instance);
8333 api_want_ip4_arp_events (vat_main_t * vam)
8335 unformat_input_t * line_input = vam->input;
8336 vl_api_want_ip4_arp_events_t * mp;
8338 ip4_address_t address;
8339 int address_set = 0;
8340 u32 enable_disable = 1;
8342 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) {
8343 if (unformat (line_input, "address %U",
8344 unformat_ip4_address, &address))
8346 else if (unformat (line_input, "del"))
8352 if (address_set == 0) {
8353 errmsg ("missing addresses\n");
8357 M(WANT_IP4_ARP_EVENTS, want_ip4_arp_events);
8358 mp->enable_disable = enable_disable;
8360 mp->address = address.as_u32;
8365 static int api_input_acl_set_interface (vat_main_t * vam)
8367 unformat_input_t * i = vam->input;
8368 vl_api_input_acl_set_interface_t *mp;
8371 int sw_if_index_set;
8372 u32 ip4_table_index = ~0;
8373 u32 ip6_table_index = ~0;
8374 u32 l2_table_index = ~0;
8377 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
8378 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
8379 sw_if_index_set = 1;
8380 else if (unformat (i, "sw_if_index %d", &sw_if_index))
8381 sw_if_index_set = 1;
8382 else if (unformat (i, "del"))
8384 else if (unformat (i, "ip4-table %d", &ip4_table_index))
8386 else if (unformat (i, "ip6-table %d", &ip6_table_index))
8388 else if (unformat (i, "l2-table %d", &l2_table_index))
8391 clib_warning ("parse error '%U'", format_unformat_error, i);
8396 if (sw_if_index_set == 0) {
8397 errmsg ("missing interface name or sw_if_index\n");
8401 M(INPUT_ACL_SET_INTERFACE, input_acl_set_interface);
8403 mp->sw_if_index = ntohl(sw_if_index);
8404 mp->ip4_table_index = ntohl(ip4_table_index);
8405 mp->ip6_table_index = ntohl(ip6_table_index);
8406 mp->l2_table_index = ntohl(l2_table_index);
8407 mp->is_add = is_add;
8415 api_ip_address_dump (vat_main_t * vam)
8417 unformat_input_t * i = vam->input;
8418 vl_api_ip_address_dump_t * mp;
8419 u32 sw_if_index = ~0;
8420 u8 sw_if_index_set = 0;
8425 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
8426 if (unformat (i, "sw_if_index %d", &sw_if_index))
8427 sw_if_index_set = 1;
8428 else if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
8429 sw_if_index_set = 1;
8430 else if (unformat (i, "ipv4"))
8432 else if (unformat (i, "ipv6"))
8438 if (ipv4_set && ipv6_set) {
8439 errmsg ("ipv4 and ipv6 flags cannot be both set\n");
8443 if ((!ipv4_set) && (!ipv6_set)) {
8444 errmsg ("no ipv4 nor ipv6 flag set\n");
8448 if (sw_if_index_set == 0) {
8449 errmsg ("missing interface name or sw_if_index\n");
8453 vam->current_sw_if_index = sw_if_index;
8454 vam->is_ipv6 = ipv6_set;
8456 M(IP_ADDRESS_DUMP, ip_address_dump);
8457 mp->sw_if_index = ntohl(sw_if_index);
8458 mp->is_ipv6 = ipv6_set;
8461 /* Use a control ping for synchronization */
8463 vl_api_control_ping_t * mp;
8464 M(CONTROL_PING, control_ping);
8471 api_ip_dump (vat_main_t * vam)
8473 vl_api_ip_dump_t * mp;
8474 unformat_input_t * in = vam->input;
8481 while (unformat_check_input (in) != UNFORMAT_END_OF_INPUT) {
8482 if (unformat (in, "ipv4"))
8484 else if (unformat (in, "ipv6"))
8490 if (ipv4_set && ipv6_set) {
8491 errmsg ("ipv4 and ipv6 flags cannot be both set\n");
8495 if ((!ipv4_set) && (!ipv6_set)) {
8496 errmsg ("no ipv4 nor ipv6 flag set\n");
8501 vam->is_ipv6 = is_ipv6;
8504 for (i = 0; i < vec_len(vam->ip_details_by_sw_if_index[is_ipv6]); i++) {
8505 vec_free(vam->ip_details_by_sw_if_index[is_ipv6][i].addr);
8507 vec_free(vam->ip_details_by_sw_if_index[is_ipv6]);
8509 M(IP_DUMP, ip_dump);
8510 mp->is_ipv6 = ipv6_set;
8513 /* Use a control ping for synchronization */
8515 vl_api_control_ping_t * mp;
8516 M(CONTROL_PING, control_ping);
8523 api_ipsec_spd_add_del (vat_main_t * vam)
8526 unformat_input_t * i = vam->input;
8527 vl_api_ipsec_spd_add_del_t *mp;
8532 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
8533 if (unformat (i, "spd_id %d", &spd_id))
8535 else if (unformat (i, "del"))
8538 clib_warning ("parse error '%U'", format_unformat_error, i);
8543 errmsg ("spd_id must be set\n");
8547 M(IPSEC_SPD_ADD_DEL, ipsec_spd_add_del);
8549 mp->spd_id = ntohl(spd_id);
8550 mp->is_add = is_add;
8556 clib_warning ("unsupported (no dpdk)");
8562 api_ipsec_interface_add_del_spd (vat_main_t * vam)
8565 unformat_input_t * i = vam->input;
8566 vl_api_ipsec_interface_add_del_spd_t *mp;
8569 u8 sw_if_index_set = 0;
8570 u32 spd_id = (u32) ~0;
8573 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
8574 if (unformat (i, "del"))
8576 else if (unformat (i, "spd_id %d", &spd_id))
8578 else if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
8579 sw_if_index_set = 1;
8580 else if (unformat (i, "sw_if_index %d", &sw_if_index))
8581 sw_if_index_set = 1;
8583 clib_warning ("parse error '%U'", format_unformat_error, i);
8589 if (spd_id == (u32) ~0) {
8590 errmsg ("spd_id must be set\n");
8594 if (sw_if_index_set == 0) {
8595 errmsg ("missing interface name or sw_if_index\n");
8599 M(IPSEC_INTERFACE_ADD_DEL_SPD, ipsec_interface_add_del_spd);
8601 mp->spd_id = ntohl(spd_id);
8602 mp->sw_if_index = ntohl (sw_if_index);
8603 mp->is_add = is_add;
8609 clib_warning ("unsupported (no dpdk)");
8615 api_ipsec_spd_add_del_entry (vat_main_t * vam)
8618 unformat_input_t * i = vam->input;
8619 vl_api_ipsec_spd_add_del_entry_t *mp;
8621 u8 is_add = 1, is_outbound = 0, is_ipv6 = 0, is_ip_any = 1;
8622 u32 spd_id, sa_id, protocol = 0, policy = 0;
8624 u32 rport_start = 0, rport_stop = (u32) ~0;
8625 u32 lport_start = 0, lport_stop = (u32) ~0;
8626 ip4_address_t laddr4_start, laddr4_stop, raddr4_start, raddr4_stop;
8627 ip6_address_t laddr6_start, laddr6_stop, raddr6_start, raddr6_stop;
8629 laddr4_start.as_u32 = raddr4_start.as_u32 = 0;
8630 laddr4_stop.as_u32 = raddr4_stop.as_u32 = (u32) ~0;
8631 laddr6_start.as_u64[0] = raddr6_start.as_u64[0] = 0;
8632 laddr6_start.as_u64[1] = raddr6_start.as_u64[1] = 0;
8633 laddr6_stop.as_u64[0] = raddr6_stop.as_u64[0] = (u64) ~0;
8634 laddr6_stop.as_u64[1] = raddr6_stop.as_u64[1] = (u64) ~0;
8636 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
8637 if (unformat (i, "del"))
8639 if (unformat (i, "outbound"))
8641 if (unformat (i, "inbound"))
8643 else if (unformat (i, "spd_id %d", &spd_id))
8645 else if (unformat (i, "sa_id %d", &sa_id))
8647 else if (unformat (i, "priority %d", &priority))
8649 else if (unformat (i, "protocol %d", &protocol))
8651 else if (unformat (i, "lport_start %d", &lport_start))
8653 else if (unformat (i, "lport_stop %d", &lport_stop))
8655 else if (unformat (i, "rport_start %d", &rport_start))
8657 else if (unformat (i, "rport_stop %d", &rport_stop))
8659 else if (unformat (i, "laddr_start %U", unformat_ip4_address, &laddr4_start))
8664 else if (unformat (i, "laddr_stop %U", unformat_ip4_address, &laddr4_stop))
8669 else if (unformat (i, "raddr_start %U", unformat_ip4_address, &raddr4_start))
8674 else if (unformat (i, "raddr_stop %U", unformat_ip4_address, &raddr4_stop))
8679 else if (unformat (i, "laddr_start %U", unformat_ip6_address, &laddr6_start))
8684 else if (unformat (i, "laddr_stop %U", unformat_ip6_address, &laddr6_stop))
8689 else if (unformat (i, "raddr_start %U", unformat_ip6_address, &raddr6_start))
8694 else if (unformat (i, "raddr_stop %U", unformat_ip6_address, &raddr6_stop))
8699 else if (unformat (i, "action %U", unformat_ipsec_policy_action, &policy))
8701 if (policy == IPSEC_POLICY_ACTION_RESOLVE) {
8702 clib_warning ("unsupported action: 'resolve'");
8707 clib_warning ("parse error '%U'", format_unformat_error, i);
8713 M(IPSEC_SPD_ADD_DEL_ENTRY, ipsec_spd_add_del_entry);
8715 mp->spd_id = ntohl(spd_id);
8716 mp->priority = ntohl(priority);
8717 mp->is_outbound = is_outbound;
8719 mp->is_ipv6 = is_ipv6;
8720 if (is_ipv6 || is_ip_any) {
8721 clib_memcpy (mp->remote_address_start, &raddr6_start, sizeof(ip6_address_t));
8722 clib_memcpy (mp->remote_address_stop, &raddr6_stop, sizeof(ip6_address_t));
8723 clib_memcpy (mp->local_address_start, &laddr6_start, sizeof(ip6_address_t));
8724 clib_memcpy (mp->local_address_stop, &laddr6_stop, sizeof(ip6_address_t));
8726 clib_memcpy (mp->remote_address_start, &raddr4_start, sizeof(ip4_address_t));
8727 clib_memcpy (mp->remote_address_stop, &raddr4_stop, sizeof(ip4_address_t));
8728 clib_memcpy (mp->local_address_start, &laddr4_start, sizeof(ip4_address_t));
8729 clib_memcpy (mp->local_address_stop, &laddr4_stop, sizeof(ip4_address_t));
8731 mp->protocol = (u8) protocol;
8732 mp->local_port_start = ntohs((u16) lport_start);
8733 mp->local_port_stop = ntohs((u16) lport_stop);
8734 mp->remote_port_start = ntohs((u16) rport_start);
8735 mp->remote_port_stop = ntohs((u16) rport_stop);
8736 mp->policy = (u8) policy;
8737 mp->sa_id = ntohl(sa_id);
8738 mp->is_add = is_add;
8739 mp->is_ip_any = is_ip_any;
8744 clib_warning ("unsupported (no dpdk)");
8750 api_ipsec_sad_add_del_entry (vat_main_t * vam)
8753 unformat_input_t * i = vam->input;
8754 vl_api_ipsec_sad_add_del_entry_t *mp;
8760 u8 protocol = IPSEC_PROTOCOL_AH;
8761 u8 is_tunnel = 0, is_tunnel_ipv6 = 0;
8762 u32 crypto_alg = 0, integ_alg = 0;
8763 ip4_address_t tun_src4;
8764 ip4_address_t tun_dst4;
8765 ip6_address_t tun_src6;
8766 ip6_address_t tun_dst6;
8768 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
8769 if (unformat (i, "del"))
8771 else if (unformat (i, "sad_id %d", &sad_id))
8773 else if (unformat (i, "spi %d", &spi))
8775 else if (unformat (i, "esp"))
8776 protocol = IPSEC_PROTOCOL_ESP;
8777 else if (unformat (i, "tunnel_src %U", unformat_ip4_address, &tun_src4)) {
8781 else if (unformat (i, "tunnel_dst %U", unformat_ip4_address, &tun_dst4)) {
8785 else if (unformat (i, "tunnel_src %U", unformat_ip6_address, &tun_src6)) {
8789 else if (unformat (i, "tunnel_dst %U", unformat_ip6_address, &tun_dst6)) {
8793 else if (unformat (i, "crypto_alg %U", unformat_ipsec_crypto_alg, &crypto_alg)) {
8794 if (crypto_alg < IPSEC_CRYPTO_ALG_AES_CBC_128 ||
8795 crypto_alg > IPSEC_INTEG_ALG_SHA_512_256) {
8796 clib_warning ("unsupported crypto-alg: '%U'",
8797 format_ipsec_crypto_alg, crypto_alg);
8801 else if (unformat (i, "crypto_key %U", unformat_hex_string, &ck))
8803 else if (unformat (i, "integ_alg %U", unformat_ipsec_integ_alg, &integ_alg)) {
8804 if (integ_alg < IPSEC_INTEG_ALG_SHA1_96 ||
8805 integ_alg > IPSEC_INTEG_ALG_SHA_512_256) {
8806 clib_warning ("unsupported integ-alg: '%U'",
8807 format_ipsec_integ_alg, integ_alg);
8811 else if (unformat (i, "integ_key %U", unformat_hex_string, &ik))
8814 clib_warning ("parse error '%U'", format_unformat_error, i);
8820 M(IPSEC_SAD_ADD_DEL_ENTRY, ipsec_sad_add_del_entry);
8822 mp->sad_id = ntohl(sad_id);
8823 mp->is_add = is_add;
8824 mp->protocol = protocol;
8825 mp->spi = ntohl(spi);
8826 mp->is_tunnel = is_tunnel;
8827 mp->is_tunnel_ipv6 = is_tunnel_ipv6;
8828 mp->crypto_algorithm = crypto_alg;
8829 mp->integrity_algorithm = integ_alg;
8830 mp->crypto_key_length = vec_len(ck);
8831 mp->integrity_key_length = vec_len(ik);
8833 if (mp->crypto_key_length > sizeof(mp->crypto_key))
8834 mp->crypto_key_length = sizeof(mp->crypto_key);
8836 if (mp->integrity_key_length > sizeof(mp->integrity_key))
8837 mp->integrity_key_length = sizeof(mp->integrity_key);
8839 clib_memcpy (mp->crypto_key, ck, mp->crypto_key_length);
8840 clib_memcpy (mp->integrity_key, ik, mp->integrity_key_length);
8843 if (is_tunnel_ipv6) {
8844 clib_memcpy (mp->tunnel_src_address, &tun_src6, sizeof(ip6_address_t));
8845 clib_memcpy (mp->tunnel_dst_address, &tun_dst6, sizeof(ip6_address_t));
8847 clib_memcpy (mp->tunnel_src_address, &tun_src4, sizeof(ip4_address_t));
8848 clib_memcpy (mp->tunnel_dst_address, &tun_dst4, sizeof(ip4_address_t));
8856 clib_warning ("unsupported (no dpdk)");
8862 api_ipsec_sa_set_key (vat_main_t * vam)
8865 unformat_input_t * i = vam->input;
8866 vl_api_ipsec_sa_set_key_t *mp;
8871 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
8872 if (unformat (i, "sa_id %d", &sa_id))
8874 else if (unformat (i, "crypto_key %U", unformat_hex_string, &ck))
8876 else if (unformat (i, "integ_key %U", unformat_hex_string, &ik))
8879 clib_warning ("parse error '%U'", format_unformat_error, i);
8884 M(IPSEC_SA_SET_KEY, ipsec_set_sa_key);
8886 mp->sa_id = ntohl(sa_id);
8887 mp->crypto_key_length = vec_len(ck);
8888 mp->integrity_key_length = vec_len(ik);
8890 if (mp->crypto_key_length > sizeof(mp->crypto_key))
8891 mp->crypto_key_length = sizeof(mp->crypto_key);
8893 if (mp->integrity_key_length > sizeof(mp->integrity_key))
8894 mp->integrity_key_length = sizeof(mp->integrity_key);
8896 clib_memcpy (mp->crypto_key, ck, mp->crypto_key_length);
8897 clib_memcpy (mp->integrity_key, ik, mp->integrity_key_length);
8903 clib_warning ("unsupported (no dpdk)");
8909 api_ikev2_profile_add_del (vat_main_t * vam)
8912 unformat_input_t * i = vam->input;
8913 vl_api_ikev2_profile_add_del_t * mp;
8918 const char * valid_chars = "a-zA-Z0-9_";
8920 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
8921 if (unformat (i, "del"))
8923 else if (unformat (i, "name %U", unformat_token, valid_chars, &name))
8926 errmsg ("parse error '%U'", format_unformat_error, i);
8931 if (!vec_len (name)) {
8932 errmsg ("profile name must be specified");
8936 if (vec_len (name) > 64) {
8937 errmsg ("profile name too long");
8941 M(IKEV2_PROFILE_ADD_DEL, ikev2_profile_add_del);
8943 clib_memcpy(mp->name, name, vec_len (name));
8944 mp->is_add = is_add;
8951 clib_warning ("unsupported (no dpdk)");
8957 api_ikev2_profile_set_auth (vat_main_t * vam)
8960 unformat_input_t * i = vam->input;
8961 vl_api_ikev2_profile_set_auth_t * mp;
8965 u32 auth_method = 0;
8968 const char * valid_chars = "a-zA-Z0-9_";
8970 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
8971 if (unformat (i, "name %U", unformat_token, valid_chars, &name))
8973 else if (unformat (i, "auth_method %U",
8974 unformat_ikev2_auth_method, &auth_method))
8976 else if (unformat (i, "auth_data 0x%U", unformat_hex_string, &data))
8978 else if (unformat (i, "auth_data %v", &data))
8981 errmsg ("parse error '%U'", format_unformat_error, i);
8986 if (!vec_len (name)) {
8987 errmsg ("profile name must be specified");
8991 if (vec_len (name) > 64) {
8992 errmsg ("profile name too long");
8996 if (!vec_len(data)) {
8997 errmsg ("auth_data must be specified");
9002 errmsg ("auth_method must be specified");
9006 M(IKEV2_PROFILE_SET_AUTH, ikev2_profile_set_auth);
9008 mp->is_hex = is_hex;
9009 mp->auth_method = (u8) auth_method;
9010 mp->data_len = vec_len (data);
9011 clib_memcpy (mp->name, name, vec_len (name));
9012 clib_memcpy (mp->data, data, vec_len (data));
9020 clib_warning ("unsupported (no dpdk)");
9026 api_ikev2_profile_set_id (vat_main_t * vam)
9029 unformat_input_t * i = vam->input;
9030 vl_api_ikev2_profile_set_id_t * mp;
9038 const char * valid_chars = "a-zA-Z0-9_";
9040 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
9041 if (unformat (i, "name %U", unformat_token, valid_chars, &name))
9043 else if (unformat (i, "id_type %U",
9044 unformat_ikev2_id_type, &id_type))
9046 else if (unformat (i, "id_data %U", unformat_ip4_address, &ip4))
9048 data = vec_new(u8, 4);
9049 clib_memcpy(data, ip4.as_u8, 4);
9051 else if (unformat (i, "id_data 0x%U", unformat_hex_string, &data))
9053 else if (unformat (i, "id_data %v", &data))
9055 else if (unformat (i, "local"))
9057 else if (unformat (i, "remote"))
9060 errmsg ("parse error '%U'", format_unformat_error, i);
9065 if (!vec_len (name)) {
9066 errmsg ("profile name must be specified");
9070 if (vec_len (name) > 64) {
9071 errmsg ("profile name too long");
9075 if (!vec_len(data)) {
9076 errmsg ("id_data must be specified");
9081 errmsg ("id_type must be specified");
9085 M(IKEV2_PROFILE_SET_ID, ikev2_profile_set_id);
9087 mp->is_local = is_local;
9088 mp->id_type = (u8) id_type;
9089 mp->data_len = vec_len (data);
9090 clib_memcpy (mp->name, name, vec_len (name));
9091 clib_memcpy (mp->data, data, vec_len (data));
9099 clib_warning ("unsupported (no dpdk)");
9105 api_ikev2_profile_set_ts (vat_main_t * vam)
9108 unformat_input_t * i = vam->input;
9109 vl_api_ikev2_profile_set_ts_t * mp;
9113 u32 proto = 0, start_port = 0, end_port = (u32) ~0;
9114 ip4_address_t start_addr, end_addr;
9116 const char * valid_chars = "a-zA-Z0-9_";
9118 start_addr.as_u32 = 0;
9119 end_addr.as_u32 = (u32) ~0;
9121 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
9122 if (unformat (i, "name %U", unformat_token, valid_chars, &name))
9124 else if (unformat (i, "protocol %d", &proto))
9126 else if (unformat (i, "start_port %d", &start_port))
9128 else if (unformat (i, "end_port %d", &end_port))
9130 else if (unformat (i, "start_addr %U", unformat_ip4_address, &start_addr))
9132 else if (unformat (i, "end_addr %U", unformat_ip4_address, &end_addr))
9134 else if (unformat (i, "local"))
9136 else if (unformat (i, "remote"))
9139 errmsg ("parse error '%U'", format_unformat_error, i);
9144 if (!vec_len (name)) {
9145 errmsg ("profile name must be specified");
9149 if (vec_len (name) > 64) {
9150 errmsg ("profile name too long");
9154 M(IKEV2_PROFILE_SET_TS, ikev2_profile_set_ts);
9156 mp->is_local = is_local;
9157 mp->proto = (u8) proto;
9158 mp->start_port = (u16) start_port;
9159 mp->end_port = (u16) end_port;
9160 mp->start_addr = start_addr.as_u32;
9161 mp->end_addr = end_addr.as_u32;
9162 clib_memcpy (mp->name, name, vec_len (name));
9169 clib_warning ("unsupported (no dpdk)");
9175 api_ikev2_set_local_key (vat_main_t * vam)
9178 unformat_input_t * i = vam->input;
9179 vl_api_ikev2_set_local_key_t * mp;
9183 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
9184 if (unformat (i, "file %v", &file))
9187 errmsg ("parse error '%U'", format_unformat_error, i);
9192 if (!vec_len (file)) {
9193 errmsg ("RSA key file must be specified");
9197 if (vec_len (file) > 256) {
9198 errmsg ("file name too long");
9202 M(IKEV2_SET_LOCAL_KEY, ikev2_set_local_key);
9204 clib_memcpy (mp->key_file, file, vec_len (file));
9211 clib_warning ("unsupported (no dpdk)");
9219 static int api_map_add_domain (vat_main_t * vam)
9221 unformat_input_t *i = vam->input;
9222 vl_api_map_add_domain_t *mp;
9225 ip4_address_t ip4_prefix;
9226 ip6_address_t ip6_prefix;
9227 ip6_address_t ip6_src;
9229 u32 ip6_prefix_len, ip4_prefix_len, ea_bits_len, psid_offset,
9231 u8 is_translation = 0;
9233 u8 ip6_src_len = 128;
9235 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
9236 if (unformat (i, "ip4-pfx %U/%d", unformat_ip4_address,
9237 &ip4_prefix, &ip4_prefix_len))
9239 else if (unformat (i, "ip6-pfx %U/%d", unformat_ip6_address,
9240 &ip6_prefix, &ip6_prefix_len))
9242 else if (unformat (i, "ip6-src %U/%d", unformat_ip6_address, &ip6_src, &ip6_src_len))
9244 else if (unformat (i, "ip6-src %U", unformat_ip6_address, &ip6_src))
9246 else if (unformat (i, "ea-bits-len %d", &ea_bits_len))
9248 else if (unformat (i, "psid-offset %d", &psid_offset))
9250 else if (unformat (i, "psid-len %d", &psid_length))
9252 else if (unformat (i, "mtu %d", &mtu))
9254 else if (unformat (i, "map-t"))
9257 clib_warning ("parse error '%U'", format_unformat_error, i);
9262 if (num_m_args != 6) {
9263 errmsg("mandatory argument(s) missing\n");
9267 /* Construct the API message */
9268 M(MAP_ADD_DOMAIN, map_add_domain);
9270 clib_memcpy(mp->ip4_prefix, &ip4_prefix, sizeof(ip4_prefix));
9271 mp->ip4_prefix_len = ip4_prefix_len;
9273 clib_memcpy(mp->ip6_prefix, &ip6_prefix, sizeof(ip6_prefix));
9274 mp->ip6_prefix_len = ip6_prefix_len;
9276 clib_memcpy(mp->ip6_src, &ip6_src, sizeof(ip6_src));
9277 mp->ip6_src_prefix_len = ip6_src_len;
9279 mp->ea_bits_len = ea_bits_len;
9280 mp->psid_offset = psid_offset;
9281 mp->psid_length = psid_length;
9282 mp->is_translation = is_translation;
9283 mp->mtu = htons(mtu);
9288 /* Wait for a reply, return good/bad news */
9292 static int api_map_del_domain (vat_main_t * vam)
9294 unformat_input_t *i = vam->input;
9295 vl_api_map_del_domain_t *mp;
9301 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
9302 if (unformat (i, "index %d", &index))
9305 clib_warning ("parse error '%U'", format_unformat_error, i);
9310 if (num_m_args != 1) {
9311 errmsg("mandatory argument(s) missing\n");
9315 /* Construct the API message */
9316 M(MAP_DEL_DOMAIN, map_del_domain);
9318 mp->index = ntohl(index);
9323 /* Wait for a reply, return good/bad news */
9327 static int api_map_add_del_rule (vat_main_t * vam)
9329 unformat_input_t *i = vam->input;
9330 vl_api_map_add_del_rule_t *mp;
9333 ip6_address_t ip6_dst;
9334 u32 num_m_args = 0, index, psid;
9336 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
9337 if (unformat (i, "index %d", &index))
9339 else if (unformat (i, "psid %d", &psid))
9341 else if (unformat (i, "dst %U", unformat_ip6_address, &ip6_dst))
9343 else if (unformat (i, "del")) {
9346 clib_warning ("parse error '%U'", format_unformat_error, i);
9351 /* Construct the API message */
9352 M(MAP_ADD_DEL_RULE, map_add_del_rule);
9354 mp->index = ntohl(index);
9355 mp->is_add = is_add;
9356 clib_memcpy(mp->ip6_dst, &ip6_dst, sizeof(ip6_dst));
9357 mp->psid = ntohs(psid);
9362 /* Wait for a reply, return good/bad news */
9366 static int api_map_domain_dump (vat_main_t * vam)
9368 vl_api_map_domain_dump_t *mp;
9371 /* Construct the API message */
9372 M(MAP_DOMAIN_DUMP, map_domain_dump);
9377 /* Use a control ping for synchronization */
9379 vl_api_control_ping_t * mp;
9380 M(CONTROL_PING, control_ping);
9386 static int api_map_rule_dump (vat_main_t * vam)
9388 unformat_input_t *i = vam->input;
9389 vl_api_map_rule_dump_t *mp;
9391 u32 domain_index = ~0;
9393 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
9394 if (unformat (i, "index %u", &domain_index))
9400 if (domain_index == ~0) {
9401 clib_warning("parse error: domain index expected");
9405 /* Construct the API message */
9406 M(MAP_RULE_DUMP, map_rule_dump);
9408 mp->domain_index = htonl(domain_index);
9413 /* Use a control ping for synchronization */
9415 vl_api_control_ping_t * mp;
9416 M(CONTROL_PING, control_ping);
9422 static void vl_api_map_add_domain_reply_t_handler
9423 (vl_api_map_add_domain_reply_t * mp)
9425 vat_main_t * vam = &vat_main;
9426 i32 retval = ntohl(mp->retval);
9428 if (vam->async_mode) {
9429 vam->async_errors += (retval < 0);
9431 vam->retval = retval;
9432 vam->result_ready = 1;
9436 static void vl_api_map_add_domain_reply_t_handler_json
9437 (vl_api_map_add_domain_reply_t * mp)
9439 vat_main_t * vam = &vat_main;
9440 vat_json_node_t node;
9442 vat_json_init_object(&node);
9443 vat_json_object_add_int(&node, "retval", ntohl(mp->retval));
9444 vat_json_object_add_uint(&node, "index", ntohl(mp->index));
9446 vat_json_print(vam->ofp, &node);
9447 vat_json_free(&node);
9449 vam->retval = ntohl(mp->retval);
9450 vam->result_ready = 1;
9454 api_get_first_msg_id (vat_main_t * vam)
9456 vl_api_get_first_msg_id_t * mp;
9458 unformat_input_t * i = vam->input;
9462 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
9463 if (unformat (i, "client %s", &name))
9469 if (name_set == 0) {
9470 errmsg ("missing client name\n");
9475 if (vec_len (name) > 63) {
9476 errmsg ("client name too long\n");
9480 M(GET_FIRST_MSG_ID, get_first_msg_id);
9481 clib_memcpy (mp->name, name, vec_len(name));
9487 static int api_cop_interface_enable_disable (vat_main_t * vam)
9489 unformat_input_t * line_input = vam->input;
9490 vl_api_cop_interface_enable_disable_t * mp;
9492 u32 sw_if_index = ~0;
9493 u8 enable_disable = 1;
9495 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) {
9496 if (unformat (line_input, "disable"))
9498 if (unformat (line_input, "enable"))
9500 else if (unformat (line_input, "%U", unformat_sw_if_index,
9503 else if (unformat (line_input, "sw_if_index %d", &sw_if_index))
9509 if (sw_if_index == ~0) {
9510 errmsg ("missing interface name or sw_if_index\n");
9514 /* Construct the API message */
9515 M(COP_INTERFACE_ENABLE_DISABLE, cop_interface_enable_disable);
9516 mp->sw_if_index = ntohl(sw_if_index);
9517 mp->enable_disable = enable_disable;
9521 /* Wait for the reply */
9525 static int api_cop_whitelist_enable_disable (vat_main_t * vam)
9527 unformat_input_t * line_input = vam->input;
9528 vl_api_cop_whitelist_enable_disable_t * mp;
9530 u32 sw_if_index = ~0;
9531 u8 ip4=0, ip6=0, default_cop=0;
9534 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) {
9535 if (unformat (line_input, "ip4"))
9537 else if (unformat (line_input, "ip6"))
9539 else if (unformat (line_input, "default"))
9541 else if (unformat (line_input, "%U", unformat_sw_if_index,
9544 else if (unformat (line_input, "sw_if_index %d", &sw_if_index))
9546 else if (unformat (line_input, "fib-id %d", &fib_id))
9552 if (sw_if_index == ~0) {
9553 errmsg ("missing interface name or sw_if_index\n");
9557 /* Construct the API message */
9558 M(COP_WHITELIST_ENABLE_DISABLE, cop_whitelist_enable_disable);
9559 mp->sw_if_index = ntohl(sw_if_index);
9560 mp->fib_id = ntohl(fib_id);
9563 mp->default_cop = default_cop;
9567 /* Wait for the reply */
9571 static int api_get_node_graph (vat_main_t * vam)
9573 vl_api_get_node_graph_t * mp;
9576 M(GET_NODE_GRAPH, get_node_graph);
9580 /* Wait for the reply */
9585 api_lisp_add_del_locator_set(vat_main_t * vam)
9587 unformat_input_t * input = vam->input;
9588 vl_api_lisp_add_del_locator_set_t *mp;
9591 u8 *locator_set_name = NULL;
9592 u8 locator_set_name_set = 0;
9594 /* Parse args required to build the message */
9595 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) {
9596 if (unformat(input, "del")) {
9598 } else if (unformat(input, "locator-set %s", &locator_set_name)) {
9599 locator_set_name_set = 1;
9604 if (locator_set_name_set == 0) {
9605 errmsg ("missing locator-set name");
9609 if (vec_len(locator_set_name) > 64) {
9610 errmsg ("locator-set name too long\n");
9611 vec_free(locator_set_name);
9614 vec_add1(locator_set_name, 0);
9616 /* Construct the API message */
9617 M(LISP_ADD_DEL_LOCATOR_SET, lisp_add_del_locator_set);
9619 mp->is_add = is_add;
9620 clib_memcpy(mp->locator_set_name, locator_set_name,
9621 vec_len(locator_set_name));
9622 vec_free(locator_set_name);
9627 /* Wait for a reply... */
9635 api_lisp_add_del_locator(vat_main_t * vam)
9637 unformat_input_t * input = vam->input;
9638 vl_api_lisp_add_del_locator_t *mp;
9640 u32 tmp_if_index = ~0;
9641 u32 sw_if_index = ~0;
9642 u8 sw_if_index_set = 0;
9643 u8 sw_if_index_if_name_set = 0;
9645 u8 priority_set = 0;
9649 u8 *locator_set_name = NULL;
9650 u8 locator_set_name_set = 0;
9652 /* Parse args required to build the message */
9653 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) {
9654 if (unformat(input, "del")) {
9656 } else if (unformat(input, "locator-set %s", &locator_set_name)) {
9657 locator_set_name_set = 1;
9658 } else if (unformat(input, "iface %U", unformat_sw_if_index, vam,
9660 sw_if_index_if_name_set = 1;
9661 sw_if_index = tmp_if_index;
9662 } else if (unformat(input,"sw_if_index %d", &tmp_if_index)) {
9663 sw_if_index_set = 1;
9664 sw_if_index = tmp_if_index;
9665 } else if (unformat(input, "p %d", &priority)) {
9667 } else if (unformat(input, "w %d", &weight)) {
9673 if (locator_set_name_set == 0) {
9674 errmsg ("missing locator-set name");
9678 if (sw_if_index_set == 0 && sw_if_index_if_name_set == 0) {
9679 errmsg ("missing sw_if_index");
9680 vec_free(locator_set_name);
9684 if (sw_if_index_set != 0 && sw_if_index_if_name_set != 0) {
9685 errmsg ("cannot use both params interface name and sw_if_index");
9686 vec_free(locator_set_name);
9690 if (priority_set == 0) {
9691 errmsg ("missing locator-set priority\n");
9692 vec_free(locator_set_name);
9696 if (weight_set == 0) {
9697 errmsg ("missing locator-set weight\n");
9698 vec_free(locator_set_name);
9702 if (vec_len(locator_set_name) > 64) {
9703 errmsg ("locator-set name too long\n");
9704 vec_free(locator_set_name);
9707 vec_add1(locator_set_name, 0);
9709 /* Construct the API message */
9710 M(LISP_ADD_DEL_LOCATOR, lisp_add_del_locator);
9712 mp->is_add = is_add;
9713 mp->sw_if_index = ntohl(sw_if_index);
9714 mp->priority = priority;
9715 mp->weight = weight;
9716 clib_memcpy(mp->locator_set_name, locator_set_name,
9717 vec_len(locator_set_name));
9718 vec_free(locator_set_name);
9723 /* Wait for a reply... */
9731 api_lisp_add_del_local_eid(vat_main_t * vam)
9733 unformat_input_t * input = vam->input;
9734 vl_api_lisp_add_del_local_eid_t *mp;
9739 ip4_address_t eidv4;
9740 ip6_address_t eidv6;
9741 u8 tmp_eid_lenght = ~0;
9743 u8 *locator_set_name = NULL;
9744 u8 locator_set_name_set = 0;
9746 /* Parse args required to build the message */
9747 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) {
9748 if (unformat(input, "del")) {
9750 } else if (unformat(input, "eid %U/%d", unformat_ip4_address,
9751 &eidv4, &tmp_eid_lenght)) {
9752 eid_lenght = tmp_eid_lenght;
9754 } else if (unformat(input, "eid %U/%d", unformat_ip6_address,
9755 &eidv6, &tmp_eid_lenght)) {
9756 eid_lenght = tmp_eid_lenght;
9758 } else if (unformat(input, "locator-set %s", &locator_set_name)) {
9759 locator_set_name_set = 1;
9764 if (locator_set_name_set == 0) {
9765 errmsg ("missing locator-set name\n");
9769 if (vec_len(locator_set_name) > 64) {
9770 errmsg ("locator-set name too long\n");
9771 vec_free(locator_set_name);
9774 vec_add1(locator_set_name, 0);
9776 if (eidv4_set && eidv6_set) {
9777 errmsg ("both eid v4 and v6 addresses set\n");
9778 vec_free(locator_set_name);
9782 if (!eidv4_set && !eidv6_set) {
9783 errmsg ("eid addresses not set\n");
9784 vec_free(locator_set_name);
9788 /* Construct the API message */
9789 M(LISP_ADD_DEL_LOCAL_EID, lisp_add_del_local_eid);
9791 mp->is_add = is_add;
9794 clib_memcpy(mp->ip_address, &eidv6, sizeof(eidv6));
9797 clib_memcpy(mp->ip_address, &eidv4, sizeof(eidv4));
9799 mp->prefix_len = eid_lenght;
9800 clib_memcpy(mp->locator_set_name, locator_set_name,
9801 vec_len(locator_set_name));
9802 vec_free(locator_set_name);
9807 /* Wait for a reply... */
9815 api_lisp_gpe_add_del_fwd_entry(vat_main_t * vam)
9817 unformat_input_t * input = vam->input;
9818 vl_api_lisp_gpe_add_del_fwd_entry_t *mp;
9821 u8 eidv4_set = 0, slocv4_set = 0, dlocv4_set = 0;
9822 u8 eidv6_set = 0, slocv6_set = 0, dlocv6_set = 0;
9823 ip4_address_t eidv4, slocv4, dlocv4;
9824 ip6_address_t eidv6, slocv6, dlocv6;
9825 u8 tmp_eid_lenght = ~0;
9828 /* Parse args required to build the message */
9829 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) {
9830 if (unformat(input, "del")) {
9832 } else if (unformat(input, "eid %U/%d", unformat_ip4_address,
9833 &eidv4, &tmp_eid_lenght)) {
9834 eid_lenght = tmp_eid_lenght;
9836 } else if (unformat(input, "eid %U/%d", unformat_ip6_address,
9837 &eidv6, &tmp_eid_lenght)) {
9838 eid_lenght = tmp_eid_lenght;
9840 } else if (unformat(input, "sloc %U", unformat_ip4_address, &slocv4)) {
9842 } else if (unformat(input, "sloc %U", unformat_ip6_address, &slocv6)) {
9844 } else if (unformat(input, "dloc %U", unformat_ip4_address, &dlocv4)) {
9846 } else if (unformat(input, "dloc %U", unformat_ip6_address, &dlocv6)) {
9852 if (eidv4_set && eidv6_set) {
9853 errmsg ("both eid v4 and v6 addresses set\n");
9857 if (!eidv4_set && !eidv6_set) {
9858 errmsg ("eid addresses not set\n");
9862 if (slocv4_set && slocv6_set) {
9863 errmsg ("both source v4 and v6 addresses set\n");
9867 if (!slocv4_set && !slocv6_set) {
9868 errmsg ("source addresses not set\n");
9872 if (dlocv4_set && dlocv6_set) {
9873 errmsg ("both destination v4 and v6 addresses set\n");
9877 if (dlocv4_set && dlocv6_set) {
9878 errmsg ("destination addresses not set\n");
9882 if (!(slocv4_set == dlocv4_set && slocv6_set == dlocv6_set)) {
9883 errmsg ("mixing type of source and destination address\n");
9887 /* Construct the API message */
9888 M(LISP_GPE_ADD_DEL_FWD_ENTRY, lisp_gpe_add_del_fwd_entry);
9890 mp->is_add = is_add;
9892 mp->eid_is_ipv6 = 1;
9893 clib_memcpy(mp->eid_ip_address, &eidv6, sizeof(eidv6));
9895 mp->eid_is_ipv6 = 0;
9896 clib_memcpy(mp->eid_ip_address, &eidv4, sizeof(eidv4));
9898 mp->eid_prefix_len = eid_lenght;
9900 mp->address_is_ipv6 = 1;
9901 clib_memcpy(mp->source_ip_address, &slocv6, sizeof(slocv6));
9902 clib_memcpy(mp->destination_ip_address, &dlocv6, sizeof(dlocv6));
9904 mp->address_is_ipv6 = 0;
9905 clib_memcpy(mp->source_ip_address, &slocv4, sizeof(slocv4));
9906 clib_memcpy(mp->destination_ip_address, &dlocv4, sizeof(dlocv4));
9912 /* Wait for a reply... */
9920 api_lisp_add_del_map_resolver(vat_main_t * vam)
9922 unformat_input_t * input = vam->input;
9923 vl_api_lisp_add_del_map_resolver_t *mp;
9931 /* Parse args required to build the message */
9932 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) {
9933 if (unformat(input, "del")) {
9935 } else if (unformat(input, "%U", unformat_ip4_address, &ipv4)) {
9937 } else if (unformat(input, "%U", unformat_ip6_address, &ipv6)) {
9943 if (ipv4_set && ipv6_set) {
9944 errmsg ("both eid v4 and v6 addresses set\n");
9948 if (!ipv4_set && !ipv6_set) {
9949 errmsg ("eid addresses not set\n");
9953 /* Construct the API message */
9954 M(LISP_ADD_DEL_MAP_RESOLVER, lisp_add_del_map_resolver);
9956 mp->is_add = is_add;
9959 clib_memcpy(mp->ip_address, &ipv6, sizeof(ipv6));
9962 clib_memcpy(mp->ip_address, &ipv4, sizeof(ipv4));
9968 /* Wait for a reply... */
9976 api_lisp_gpe_enable_disable (vat_main_t * vam)
9978 unformat_input_t * input = vam->input;
9979 vl_api_lisp_gpe_enable_disable_t *mp;
9984 /* Parse args required to build the message */
9985 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) {
9986 if (unformat(input, "enable")) {
9989 } else if (unformat(input, "disable")) {
9997 errmsg("Value not set\n");
10001 /* Construct the API message */
10002 M(LISP_GPE_ENABLE_DISABLE, lisp_gpe_enable_disable);
10009 /* Wait for a reply... */
10017 api_lisp_gpe_add_del_iface(vat_main_t * vam)
10019 unformat_input_t * input = vam->input;
10020 vl_api_lisp_gpe_add_del_iface_t *mp;
10026 /* Parse args required to build the message */
10027 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) {
10028 if (unformat(input, "up")) {
10031 } else if (unformat(input, "down")) {
10034 } else if (unformat(input, "table_id %d", &table_id)) {
10036 } else if (unformat(input, "vni %d", &vni)) {
10043 errmsg("Value not set\n");
10047 /* Construct the API message */
10048 M(LISP_GPE_ADD_DEL_IFACE, lisp_gpe_add_del_iface);
10050 mp->is_add = is_add;
10051 mp->table_id = table_id;
10057 /* Wait for a reply... */
10065 api_lisp_locator_set_dump(vat_main_t *vam)
10067 vl_api_lisp_locator_set_dump_t *mp;
10070 if (!vam->json_output) {
10071 fformat(vam->ofp, "%=20s%=16s%=16s%=16s\n",
10072 "Locator-set", "Locator", "Priority", "Weight");
10075 M(LISP_LOCATOR_SET_DUMP, lisp_locator_set_dump);
10079 /* Use a control ping for synchronization */
10081 vl_api_control_ping_t * mp;
10082 M(CONTROL_PING, control_ping);
10085 /* Wait for a reply... */
10093 api_lisp_local_eid_table_dump(vat_main_t *vam)
10095 vl_api_lisp_local_eid_table_dump_t *mp;
10098 if (!vam->json_output) {
10099 fformat(vam->ofp, "%=20s%=30s\n",
10100 "Locator-set", "Eid");
10103 M(LISP_LOCAL_EID_TABLE_DUMP, lisp_local_eid_table_dump);
10107 /* Use a control ping for synchronization */
10109 vl_api_control_ping_t * mp;
10110 M(CONTROL_PING, control_ping);
10113 /* Wait for a reply... */
10121 api_lisp_gpe_tunnel_dump(vat_main_t *vam)
10123 vl_api_lisp_gpe_tunnel_dump_t *mp;
10126 if (!vam->json_output) {
10127 fformat(vam->ofp, "%=20s%=30s%=16s%=16s%=16s%=16s"
10128 "%=16s%=16s%=16s%=16s%=16s\n",
10129 "Tunel", "Source", "Destination", "Fib encap", "Fib decap",
10130 "Decap next", "Lisp version", "Flags", "Next protocol",
10131 "ver_res", "res", "iid");
10134 M(LISP_GPE_TUNNEL_DUMP, lisp_gpe_tunnel_dump);
10138 /* Use a control ping for synchronization */
10140 vl_api_control_ping_t * mp;
10141 M(CONTROL_PING, control_ping);
10144 /* Wait for a reply... */
10152 api_lisp_map_resolver_dump(vat_main_t *vam)
10154 vl_api_lisp_map_resolver_dump_t *mp;
10157 if (!vam->json_output) {
10158 fformat(vam->ofp, "%=20s\n",
10162 M(LISP_MAP_RESOLVER_DUMP, lisp_map_resolver_dump);
10166 /* Use a control ping for synchronization */
10168 vl_api_control_ping_t * mp;
10169 M(CONTROL_PING, control_ping);
10172 /* Wait for a reply... */
10180 api_lisp_gpe_enable_disable_status_dump(vat_main_t *vam)
10182 vl_api_lisp_gpe_enable_disable_status_dump_t *mp;
10185 if (!vam->json_output) {
10186 fformat(vam->ofp, "%=20s\n",
10190 M(LISP_GPE_ENABLE_DISABLE_STATUS_DUMP,
10191 lisp_gpe_enable_disable_status_dump);
10195 /* Use a control ping for synchronization */
10197 vl_api_control_ping_t * mp;
10198 M(CONTROL_PING, control_ping);
10201 /* Wait for a reply... */
10209 api_af_packet_create (vat_main_t * vam)
10211 unformat_input_t * i = vam->input;
10212 vl_api_af_packet_create_t * mp;
10214 u8 * host_if_name = 0;
10216 u8 random_hw_addr = 1;
10218 memset (hw_addr, 0, sizeof (hw_addr));
10220 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
10221 if (unformat (i, "name %s", &host_if_name))
10222 vec_add1 (host_if_name, 0);
10223 else if (unformat (i, "hw_addr %U", unformat_ethernet_address, hw_addr))
10224 random_hw_addr = 0;
10229 if (!vec_len (host_if_name)) {
10230 errmsg ("host-interface name must be specified");
10234 if (vec_len (host_if_name) > 64) {
10235 errmsg ("host-interface name too long");
10239 M(AF_PACKET_CREATE, af_packet_create);
10241 clib_memcpy (mp->host_if_name, host_if_name, vec_len (host_if_name));
10242 clib_memcpy (mp->hw_addr, hw_addr, 6);
10243 mp->use_random_hw_addr = random_hw_addr;
10244 vec_free (host_if_name);
10252 api_af_packet_delete (vat_main_t * vam)
10254 unformat_input_t * i = vam->input;
10255 vl_api_af_packet_delete_t * mp;
10257 u8 * host_if_name = 0;
10259 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
10260 if (unformat (i, "name %s", &host_if_name))
10261 vec_add1 (host_if_name, 0);
10266 if (!vec_len (host_if_name)) {
10267 errmsg ("host-interface name must be specified");
10271 if (vec_len (host_if_name) > 64) {
10272 errmsg ("host-interface name too long");
10276 M(AF_PACKET_DELETE, af_packet_delete);
10278 clib_memcpy (mp->host_if_name, host_if_name, vec_len (host_if_name));
10279 vec_free (host_if_name);
10286 static int q_or_quit (vat_main_t * vam)
10288 longjmp (vam->jump_buf, 1);
10289 return 0; /* not so much */
10291 static int q (vat_main_t * vam) {return q_or_quit (vam);}
10292 static int quit (vat_main_t * vam) {return q_or_quit (vam);}
10294 static int comment (vat_main_t * vam)
10299 static int cmd_cmp (void * a1, void * a2)
10304 return strcmp ((char *)(c1[0]), (char *)(c2[0]));
10307 static int help (vat_main_t * vam)
10312 unformat_input_t * i = vam->input;
10315 if (unformat (i, "%s", &name)) {
10320 hs = hash_get_mem (vam->help_by_name, name);
10322 fformat (vam->ofp, "usage: %s %s\n", name, hs[0]);
10324 fformat (vam->ofp, "No such msg / command '%s'\n", name);
10329 fformat(vam->ofp, "Help is available for the following:\n");
10331 hash_foreach_pair (p, vam->function_by_name,
10333 vec_add1 (cmds, (u8 *)(p->key));
10336 vec_sort_with_function (cmds, cmd_cmp);
10338 for (j = 0; j < vec_len(cmds); j++)
10339 fformat (vam->ofp, "%s\n", cmds[j]);
10345 static int set (vat_main_t * vam)
10347 u8 * name = 0, * value = 0;
10348 unformat_input_t * i = vam->input;
10350 if (unformat (i, "%s", &name)) {
10351 /* The input buffer is a vector, not a string. */
10352 value = vec_dup (i->buffer);
10353 vec_delete (value, i->index, 0);
10354 /* Almost certainly has a trailing newline */
10355 if (value[vec_len(value)-1] == '\n')
10356 value[vec_len(value)-1] = 0;
10357 /* Make sure it's a proper string, one way or the other */
10358 vec_add1 (value, 0);
10359 (void) clib_macro_set_value (&vam->macro_main,
10360 (char *)name, (char *)value);
10363 errmsg ("usage: set <name> <value>\n");
10370 static int unset (vat_main_t * vam)
10374 if (unformat (vam->input, "%s", &name))
10375 if (clib_macro_unset (&vam->macro_main, (char *)name) == 1)
10376 errmsg ("unset: %s wasn't set\n", name);
10387 static int macro_sort_cmp (void * a1, void * a2)
10389 macro_sort_t * s1 = a1;
10390 macro_sort_t * s2 = a2;
10392 return strcmp ((char *)(s1->name), (char *)(s2->name));
10395 static int dump_macro_table (vat_main_t * vam)
10397 macro_sort_t * sort_me = 0, * sm;
10401 hash_foreach_pair (p, vam->macro_main.the_value_table_hash,
10403 vec_add2 (sort_me, sm, 1);
10404 sm->name = (u8 *)(p->key);
10405 sm->value = (u8 *) (p->value[0]);
10408 vec_sort_with_function (sort_me, macro_sort_cmp);
10410 if (vec_len(sort_me))
10411 fformat (vam->ofp, "%-15s%s\n", "Name", "Value");
10413 fformat (vam->ofp, "The macro table is empty...\n");
10415 for (i = 0; i < vec_len (sort_me); i++)
10416 fformat (vam->ofp, "%-15s%s\n", sort_me[i].name,
10421 static int dump_node_table (vat_main_t * vam)
10424 vlib_node_t * node, * next_node;
10426 if (vec_len (vam->graph_nodes) == 0) {
10427 fformat (vam->ofp, "Node table empty, issue get_node_graph...\n");
10431 for (i = 0; i < vec_len (vam->graph_nodes); i++) {
10432 node = vam->graph_nodes[i];
10433 fformat (vam->ofp, "[%d] %s\n", i, node->name);
10434 for (j = 0; j < vec_len (node->next_nodes); j++) {
10435 if (node->next_nodes[j] != ~0) {
10436 next_node = vam->graph_nodes[node->next_nodes[j]];
10437 fformat (vam->ofp, " [%d] %s\n", j, next_node->name);
10444 static int search_node_table (vat_main_t * vam)
10446 unformat_input_t * line_input = vam->input;
10449 vlib_node_t * node, * next_node;
10452 if (vam->graph_node_index_by_name == 0) {
10453 fformat (vam->ofp, "Node table empty, issue get_node_graph...\n");
10457 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) {
10458 if (unformat (line_input, "%s", &node_to_find)) {
10459 vec_add1 (node_to_find, 0);
10460 p = hash_get_mem (vam->graph_node_index_by_name, node_to_find);
10462 fformat (vam->ofp, "%s not found...\n", node_to_find);
10465 node = vam->graph_nodes[p[0]];
10466 fformat (vam->ofp, "[%d] %s\n", p[0], node->name);
10467 for (j = 0; j < vec_len (node->next_nodes); j++) {
10468 if (node->next_nodes[j] != ~0) {
10469 next_node = vam->graph_nodes[node->next_nodes[j]];
10470 fformat (vam->ofp, " [%d] %s\n", j, next_node->name);
10476 clib_warning ("parse error '%U'", format_unformat_error,
10482 vec_free(node_to_find);
10490 static int script (vat_main_t * vam)
10493 char * save_current_file;
10494 unformat_input_t save_input;
10495 jmp_buf save_jump_buf;
10496 u32 save_line_number;
10498 FILE * new_fp, * save_ifp;
10500 if (unformat (vam->input, "%s", &s)) {
10501 new_fp = fopen ((char *)s, "r");
10503 errmsg ("Couldn't open script file %s\n", s);
10508 errmsg ("Missing script name\n");
10512 clib_memcpy (&save_input, &vam->input, sizeof (save_input));
10513 clib_memcpy (&save_jump_buf, &vam->jump_buf, sizeof (save_jump_buf));
10514 save_ifp = vam->ifp;
10515 save_line_number = vam->input_line_number;
10516 save_current_file = (char *) vam->current_file;
10518 vam->input_line_number = 0;
10520 vam->current_file = s;
10523 clib_memcpy (&vam->input, &save_input, sizeof (vam->input));
10524 clib_memcpy (&vam->jump_buf, &save_jump_buf, sizeof (save_jump_buf));
10525 vam->ifp = save_ifp;
10526 vam->input_line_number = save_line_number;
10527 vam->current_file = (u8 *) save_current_file;
10533 static int echo (vat_main_t * vam)
10535 fformat (vam->ofp, "%v", vam->input->buffer);
10539 /* List of API message constructors, CLI names map to api_xxx */
10540 #define foreach_vpe_api_msg \
10541 _(create_loopback,"[mac <mac-addr>]") \
10542 _(sw_interface_dump,"") \
10543 _(sw_interface_set_flags, \
10544 "<intfc> | sw_if_index <id> admin-up | admin-down link-up | link down") \
10545 _(sw_interface_add_del_address, \
10546 "<intfc> | sw_if_index <id> <ip4-address> | <ip6-address> [del] [del-all] ") \
10547 _(sw_interface_set_table, \
10548 "<intfc> | sw_if_index <id> vrf <table-id> [ipv6]") \
10549 _(sw_interface_set_vpath, \
10550 "<intfc> | sw_if_index <id> enable | disable") \
10551 _(sw_interface_set_l2_xconnect, \
10552 "rx <intfc> | rx_sw_if_index <id> tx <intfc> | tx_sw_if_index <id>\n" \
10553 "enable | disable") \
10554 _(sw_interface_set_l2_bridge, \
10555 "rx <intfc> | rx_sw_if_index <id> bd_id <bridge-domain-id>\n" \
10556 "[shg <split-horizon-group>] [bvi]\n" \
10557 "enable | disable") \
10558 _(bridge_domain_add_del, \
10559 "bd_id <bridge-domain-id> [flood 1|0] [uu-flood 1|0] [forward 1|0] [learn 1|0] [arp-term 1|0] [del]\n")\
10560 _(bridge_domain_dump, "[bd_id <bridge-domain-id>]\n") \
10562 "mac <mac-addr> bd_id <bridge-domain-id> [del] | sw_if <intfc> | sw_if_index <id> [static] [filter] [bvi]\n") \
10564 "sw_if <intfc> | sw_if_index <id> [learn] [forward] [uu-flood] [flood]\n") \
10566 "bd_id <bridge-domain-id> [learn] [forward] [uu-flood] [flood] [arp-term] [disable]\n") \
10568 "tapname <name> mac <mac-addr> | random-mac") \
10570 "<vpp-if-name> | sw_if_index <id> tapname <name> mac <mac-addr> | random-mac") \
10572 "<vpp-if-name> | sw_if_index <id>") \
10573 _(sw_interface_tap_dump, "") \
10574 _(ip_add_del_route, \
10575 "<addr>/<mask> via <addr> [vrf <n>]\n" \
10576 "[<intfc> | sw_if_index <id>] [resolve-attempts <n>]\n" \
10577 "[weight <n>] [drop] [local] [classify <n>] [del]\n" \
10578 "[multipath] [count <n>]") \
10579 _(proxy_arp_add_del, \
10580 "<lo-ip4-addr> - <hi-ip4-addr> [vrf <n>] [del]") \
10581 _(proxy_arp_intfc_enable_disable, \
10582 "<intfc> | sw_if_index <id> enable | disable") \
10583 _(mpls_add_del_encap, \
10584 "label <n> dst <ip4-addr> [vrf <n>] [del]") \
10585 _(mpls_add_del_decap, \
10586 "label <n> [rx_vrf_id <n>] [tx_vrf_id] [s-bit-clear][del]") \
10587 _(mpls_gre_add_del_tunnel, \
10588 "inner_vrf_id <n> outer_vrf_id <n> src <ip4-address> dst <ip4-address>\n" \
10589 "adj <ip4-address>/<mask-width> [del]") \
10590 _(sw_interface_set_unnumbered, \
10591 "<intfc> | sw_if_index <id> unnum_if_index <id> [del]") \
10592 _(ip_neighbor_add_del, \
10593 "<intfc> | sw_if_index <id> dst <ip46-address> mac <mac-addr>") \
10594 _(reset_vrf, "vrf <id> [ipv6]") \
10595 _(create_vlan_subif, "<intfc> | sw_if_index <id> vlan <n>") \
10596 _(create_subif, "<intfc> | sw_if_index <id> sub_id <n>\n" \
10597 "[outer_vlan_id <n>][inner_vlan_id <n>]\n" \
10598 "[no_tags][one_tag][two_tags][dot1ad][exact_match][default_sub]\n" \
10599 "[outer_vlan_id_any][inner_vlan_id_any]") \
10600 _(oam_add_del, "src <ip4-address> dst <ip4-address> [vrf <n>] [del]") \
10601 _(reset_fib, "vrf <n> [ipv6]") \
10602 _(dhcp_proxy_config, \
10603 "svr <v46-address> src <v46-address>\n" \
10604 "insert-cid <n> [del]") \
10605 _(dhcp_proxy_config_2, \
10606 "svr <v46-address> src <v46-address>\n" \
10607 "rx_vrf_id <nn> server_vrf_id <nn> insert-cid <n> [del]") \
10608 _(dhcp_proxy_set_vss, \
10609 "tbl_id <n> fib_id <n> oui <n> [ipv6] [del]") \
10610 _(dhcp_client_config, \
10611 "<intfc> | sw_if_index <id> [hostname <name>] [disable_event] [del]") \
10612 _(set_ip_flow_hash, \
10613 "vrf <n> [src] [dst] [sport] [dport] [proto] [reverse] [ipv6]") \
10614 _(sw_interface_ip6_enable_disable, \
10615 "<intfc> | sw_if_index <id> enable | disable") \
10616 _(sw_interface_ip6_set_link_local_address, \
10617 "<intfc> | sw_if_index <id> <ip6-address>/<mask-width>") \
10618 _(sw_interface_ip6nd_ra_prefix, \
10619 "<intfc> | sw_if_index <id> <ip6-address>/<mask-width>\n" \
10620 "val_life <n> pref_life <n> [def] [noadv] [offl] [noauto]\n" \
10621 "[nolink] [isno]") \
10622 _(sw_interface_ip6nd_ra_config, \
10623 "<intfc> | sw_if_index <id> [maxint <n>] [minint <n>]\n" \
10624 "[life <n>] [count <n>] [interval <n>] [surpress]\n" \
10625 "[managed] [other] [ll] [send] [cease] [isno] [def]") \
10626 _(set_arp_neighbor_limit, "arp_nbr_limit <n> [ipv6]") \
10627 _(l2_patch_add_del, \
10628 "rx <intfc> | rx_sw_if_index <id> tx <intfc> | tx_sw_if_index <id>\n" \
10629 "enable | disable") \
10630 _(mpls_ethernet_add_del_tunnel, \
10631 "tx <intfc> | tx_sw_if_index <n> dst <mac-addr>\n" \
10632 "adj <ip4-addr>/<mw> dst <mac-addr> [del]") \
10633 _(mpls_ethernet_add_del_tunnel_2, \
10634 "inner_vrf_id <n> outer_vrf_id <n> next-hop <ip4-addr>\n" \
10635 "resolve-attempts <n> resolve-if-needed 0 | 1 [del]") \
10636 _(sr_tunnel_add_del, \
10637 "[name <name>] src <ip6-addr> dst <ip6-addr>/<mw> \n" \
10638 "(next <ip6-addr>)+ [tag <ip6-addr>]* [clean] [reroute] \n" \
10639 "[policy <policy_name>]") \
10640 _(sr_policy_add_del, \
10641 "name <name> tunnel <tunnel-name> [tunnel <tunnel-name>]* [del]") \
10642 _(sr_multicast_map_add_del, \
10643 "address [ip6 multicast address] sr-policy [policy name] [del]") \
10644 _(classify_add_del_table, \
10645 "buckets <nn> [skip <n>] [match <n>] [memory_size <nn-bytes>]\n" \
10646 "[del] mask <mask-value>\n" \
10647 " [l2-miss-next | miss-next | acl-miss-next] <name|nn>") \
10648 _(classify_add_del_session, \
10649 "[hit-next|l2-hit-next|acl-hit-next] <name|nn> table-index <nn>\n" \
10650 "skip_n <nn> match_n <nn> match [hex] [l2] [l3 [ip4|ip6]]") \
10651 _(classify_set_interface_ip_table, \
10652 "<intfc> | sw_if_index <nn> table <nn>") \
10653 _(classify_set_interface_l2_tables, \
10654 "<intfc> | sw_if_index <nn> [ip4-table <nn>] [ip6-table <nn>]\n" \
10655 " [other-table <nn>]") \
10656 _(get_node_index, "node <node-name") \
10657 _(add_node_next, "node <node-name> next <next-node-name>") \
10658 _(l2tpv3_create_tunnel, \
10659 "client_address <ip6-addr> our_address <ip6-addr>\n" \
10660 "[local_session_id <nn>][remote_session_id <nn>][local_cookie <nn>]\n"\
10661 "[remote_cookie <nn>]\n[l2-sublayer-preset]\n") \
10662 _(l2tpv3_set_tunnel_cookies, \
10663 "<intfc> | sw_if_index <nn> [new_local_cookie <nn>]\n" \
10664 "[new_remote_cookie <nn>]\n") \
10665 _(l2tpv3_interface_enable_disable, \
10666 "<intfc> | sw_if_index <nn> enable | disable") \
10667 _(l2tpv3_set_lookup_key, \
10668 "lookup_v6_src | lookup_v6_dst | lookup_session_id") \
10669 _(sw_if_l2tpv3_tunnel_dump, "") \
10670 _(vxlan_add_del_tunnel, \
10671 "src <ip4-addr> dst <ip4-addr> vni <vni> [encap-vrf-id <nn>]\n" \
10672 " [decap-next l2|ip4|ip6] [del]") \
10673 _(vxlan_tunnel_dump, "[<intfc> | sw_if_index <nn>]") \
10674 _(gre_add_del_tunnel, \
10675 "src <ip4-addr> dst <ip4-addr> [outer-fib-id <nn>] [del]\n") \
10676 _(gre_tunnel_dump, "[<intfc> | sw_if_index <nn>]") \
10677 _(l2_fib_clear_table, "") \
10678 _(l2_interface_efp_filter, "sw_if_index <nn> enable | disable") \
10679 _(l2_interface_vlan_tag_rewrite, \
10680 "<intfc> | sw_if_index <nn> \n" \
10681 "[disable][push-[1|2]][pop-[1|2]][translate-1-[1|2]] \n" \
10682 "[translate-2-[1|2]] [push_dot1q 0] tag1 <nn> tag2 <nn>") \
10683 _(create_vhost_user_if, \
10684 "socket <filename> [server] [renumber <dev_instance>] " \
10685 "[mac <mac_address>]") \
10686 _(modify_vhost_user_if, \
10687 "<intfc> | sw_if_index <nn> socket <filename>\n" \
10688 "[server] [renumber <dev_instance>]") \
10689 _(delete_vhost_user_if, "<intfc> | sw_if_index <nn>") \
10690 _(sw_interface_vhost_user_dump, "") \
10691 _(show_version, "") \
10692 _(nsh_gre_add_del_tunnel, \
10693 "src <ip4-addr> dst <ip4-addr>" \
10694 "c1 <nn> c2 <nn> c3 <nn> c4 <nn> spi <nn> si <nn>\n" \
10695 "[encap-fib-id <nn>] [decap-fib-id <nn>] [o-bit <1|0>]\n" \
10696 "[c-bit <1|0>] [md-type <nn>][next-ip4][next-ip6][next-ethernet]\n" \
10697 "[tlv <xx>][del]") \
10698 _(nsh_vxlan_gpe_add_del_tunnel, \
10699 "src <ip4-addr> dst <ip4-addr> vni <nn>\n" \
10700 "c1 <nn> c2 <nn> c3 <nn> c4 <nn> spi <nn> si <nn>\n" \
10701 "[encap-vrf-id <nn>] [decap-vrf-id <nn>] [o-bit <1|0>]\n" \
10702 "[c-bit <1|0>] [md-type <nn>][next-ip4][next-ip6][next-ethernet]\n" \
10703 "[tlv <xx>][del]") \
10704 _(l2_fib_table_dump, "bd_id <bridge-domain-id>") \
10705 _(interface_name_renumber, \
10706 "<intfc> | sw_if_index <nn> new_show_dev_instance <nn>") \
10707 _(input_acl_set_interface, \
10708 "<intfc> | sw_if_index <nn> [ip4-table <nn>] [ip6-table <nn>]\n" \
10709 " [l2-table <nn>] [del]") \
10710 _(want_ip4_arp_events, "address <ip4-address> [del]") \
10711 _(ip_address_dump, "(ipv4 | ipv6) (<intfc> | sw_if_index <id>)") \
10712 _(ip_dump, "ipv4 | ipv6") \
10713 _(ipsec_spd_add_del, "spd_id <n> [del]") \
10714 _(ipsec_interface_add_del_spd, "(<intfc> | sw_if_index <id>)\n" \
10716 _(ipsec_sad_add_del_entry, "sad_id <n> spi <n> crypto_alg <alg>\n" \
10717 " crypto_key <hex> tunnel_src <ip4|ip6> tunnel_dst <ip4|ip6>\n" \
10718 " integ_alg <alg> integ_key <hex>") \
10719 _(ipsec_spd_add_del_entry, "spd_id <n> priority <n> action <action>\n" \
10720 " (inbound|outbound) [sa_id <n>] laddr_start <ip4|ip6>\n" \
10721 " laddr_stop <ip4|ip6> raddr_start <ip4|ip6> raddr_stop <ip4|ip6>\n" \
10722 " [lport_start <n> lport_stop <n>] [rport_start <n> rport_stop <n>]" )\
10723 _(ipsec_sa_set_key, "sa_id <n> crypto_key <hex> integ_key <hex>") \
10724 _(ikev2_profile_add_del, "name <profile_name> [del]") \
10725 _(ikev2_profile_set_auth, "name <profile_name> auth_method <method>\n" \
10726 "(auth_data 0x<data> | auth_data <data>)") \
10727 _(ikev2_profile_set_id, "name <profile_name> id_type <type>\n" \
10728 "(id_data 0x<data> | id_data <data>) (local|remote)") \
10729 _(ikev2_profile_set_ts, "name <profile_name> protocol <proto>\n" \
10730 "start_port <port> end_port <port> start_addr <ip4> end_addr <ip4>\n" \
10731 "(local|remote)") \
10732 _(ikev2_set_local_key, "file <absolute_file_path>") \
10733 _(delete_loopback,"sw_if_index <nn>") \
10734 _(bd_ip_mac_add_del, "bd_id <bridge-domain-id> <ip4/6-addr> <mac-addr> [del]") \
10735 _(map_add_domain, \
10736 "ip4-pfx <ip4pfx> ip6-pfx <ip6pfx> " \
10737 "ip6-src <ip6addr> " \
10738 "ea-bits-len <n> psid-offset <n> psid-len <n>") \
10739 _(map_del_domain, "index <n>") \
10740 _(map_add_del_rule, \
10741 "index <n> psid <n> dst <ip6addr> [del]") \
10742 _(map_domain_dump, "") \
10743 _(map_rule_dump, "index <map-domain>") \
10744 _(want_interface_events, "enable|disable") \
10745 _(want_stats,"enable|disable") \
10746 _(get_first_msg_id, "client <name>") \
10747 _(cop_interface_enable_disable, "<intfc> | sw_if_index <nn> [disable]") \
10748 _(cop_whitelist_enable_disable, "<intfc> | sw_if_index <nn>\n" \
10749 "fib-id <nn> [ip4][ip6][default]") \
10750 _(get_node_graph, " ") \
10751 _(sw_interface_clear_stats,"<intfc> | sw_if_index <nn>") \
10752 _(trace_profile_add, "id <nn> trace-type <0x1f|0x3|0x9|0x11|0x19> " \
10753 "trace-elts <nn> trace-tsp <0|1|2|3> node-id <node id in hex> " \
10754 "app-data <app_data in hex> [pow] [ppc <encap|decap>]") \
10755 _(trace_profile_apply, "id <nn> <ip6-address>/<width>" \
10756 " vrf_id <nn> add | pop | none") \
10757 _(trace_profile_del, "") \
10758 _(lisp_add_del_locator_set, "locator-set <locator_name> [del]") \
10759 _(lisp_add_del_locator, "locator-set <locator_name> " \
10760 "iface <intf> | sw_if_index <sw_if_index> " \
10761 "p <priority> w <weight> [del]") \
10762 _(lisp_add_del_local_eid, "<ipv4|ipv6>/<prefix> " \
10763 "locator-set <locator_name> [del]") \
10764 _(lisp_gpe_add_del_fwd_entry, "eid <ip4|6-addr>/<prefix> " \
10765 "sloc <ip4/6-addr> dloc <ip4|6-addr> [del]") \
10766 _(lisp_add_del_map_resolver, "<ip4|6-addr> [del]") \
10767 _(lisp_gpe_enable_disable, "enable|disable") \
10768 _(lisp_gpe_add_del_iface, "up|down") \
10769 _(lisp_locator_set_dump, "") \
10770 _(lisp_local_eid_table_dump, "") \
10771 _(lisp_gpe_tunnel_dump, "") \
10772 _(lisp_map_resolver_dump, "") \
10773 _(lisp_gpe_enable_disable_status_dump, "") \
10774 _(af_packet_create, "name <host interface name> [hw_addr <mac>]") \
10775 _(af_packet_delete, "name <host interface name>")
10777 /* List of command functions, CLI names map directly to functions */
10778 #define foreach_cli_function \
10779 _(comment, "usage: comment <ignore-rest-of-line>") \
10780 _(dump_interface_table, "usage: dump_interface_table") \
10781 _(dump_sub_interface_table, "usage: dump_sub_interface_table") \
10782 _(dump_ipv4_table, "usage: dump_ipv4_table") \
10783 _(dump_ipv6_table, "usage: dump_ipv6_table") \
10784 _(dump_stats_table, "usage: dump_stats_table") \
10785 _(dump_macro_table, "usage: dump_macro_table ") \
10786 _(dump_node_table, "usage: dump_node_table") \
10787 _(echo, "usage: echo <message>") \
10788 _(exec, "usage: exec <vpe-debug-CLI-command>") \
10789 _(help, "usage: help") \
10790 _(q, "usage: quit") \
10791 _(quit, "usage: quit") \
10792 _(search_node_table, "usage: search_node_table <name>...") \
10793 _(set, "usage: set <variable-name> <value>") \
10794 _(script, "usage: script <file-name>") \
10795 _(unset, "usage: unset <variable-name>")
10798 static void vl_api_##n##_t_handler_uni \
10799 (vl_api_##n##_t * mp) \
10801 vat_main_t * vam = &vat_main; \
10802 if (vam->json_output) { \
10803 vl_api_##n##_t_handler_json(mp); \
10805 vl_api_##n##_t_handler(mp); \
10808 foreach_vpe_api_reply_msg;
10811 void vat_api_hookup (vat_main_t *vam)
10814 vl_msg_api_set_handlers(VL_API_##N, #n, \
10815 vl_api_##n##_t_handler_uni, \
10817 vl_api_##n##_t_endian, \
10818 vl_api_##n##_t_print, \
10819 sizeof(vl_api_##n##_t), 1);
10820 foreach_vpe_api_reply_msg;
10823 vl_msg_api_set_first_available_msg_id (VL_MSG_FIRST_AVAILABLE);
10825 vam->sw_if_index_by_interface_name =
10826 hash_create_string (0, sizeof (uword));
10828 vam->function_by_name =
10829 hash_create_string (0, sizeof(uword));
10831 vam->help_by_name =
10832 hash_create_string (0, sizeof(uword));
10834 /* API messages we can send */
10835 #define _(n,h) hash_set_mem (vam->function_by_name, #n, api_##n);
10836 foreach_vpe_api_msg;
10840 #define _(n,h) hash_set_mem (vam->help_by_name, #n, h);
10841 foreach_vpe_api_msg;
10844 /* CLI functions */
10845 #define _(n,h) hash_set_mem (vam->function_by_name, #n, n);
10846 foreach_cli_function;
10850 #define _(n,h) hash_set_mem (vam->help_by_name, #n, h);
10851 foreach_cli_function;
10855 #undef vl_api_version
10856 #define vl_api_version(n,v) static u32 vpe_api_version = v;
10857 #include <api/vpe.api.h>
10858 #undef vl_api_version
10860 void vl_client_add_api_signatures (vl_api_memclnt_create_t *mp)
10863 * Send the main API signature in slot 0. This bit of code must
10864 * match the checks in ../vpe/api/api.c: vl_msg_api_version_check().
10866 mp->api_versions[0] = clib_host_to_net_u32 (vpe_api_version);