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_enable_disable_status_details_t_handler
2087 (vl_api_lisp_enable_disable_status_details_t *mp)
2089 vat_main_t *vam = &vat_main;
2091 fformat(vam->ofp, "feature: %s\ngpe: %s\n",
2092 mp->feature_status ? "enabled" : "disabled",
2093 mp->gpe_status ? "enabled" : "disabled");
2097 vl_api_lisp_enable_disable_status_details_t_handler_json
2098 (vl_api_lisp_enable_disable_status_details_t *mp)
2100 vat_main_t *vam = &vat_main;
2101 vat_json_node_t *node = NULL;
2102 u8 * gpe_status = NULL;
2103 u8 * feature_status = NULL;
2105 gpe_status = format (0, "%s", mp->gpe_status ? "enabled" : "disabled");
2106 feature_status = format (0, "%s",
2107 mp->feature_status ? "enabled" : "disabled");
2109 if (VAT_JSON_ARRAY != vam->json_tree.type) {
2110 ASSERT(VAT_JSON_NONE == vam->json_tree.type);
2111 vat_json_init_array(&vam->json_tree);
2113 node = vat_json_array_add(&vam->json_tree);
2115 vat_json_init_object(node);
2116 vat_json_object_add_string_copy(node, "gpe_status", gpe_status);
2117 vat_json_object_add_string_copy(node, "feature_status", feature_status);
2119 vec_free (gpe_status);
2120 vec_free (feature_status);
2123 #define vl_api_vnet_ip4_fib_counters_t_endian vl_noop_handler
2124 #define vl_api_vnet_ip4_fib_counters_t_print vl_noop_handler
2125 #define vl_api_vnet_ip6_fib_counters_t_endian vl_noop_handler
2126 #define vl_api_vnet_ip6_fib_counters_t_print vl_noop_handler
2129 * Generate boilerplate reply handlers, which
2130 * dig the return value out of the xxx_reply_t API message,
2131 * stick it into vam->retval, and set vam->result_ready
2133 * Could also do this by pointing N message decode slots at
2134 * a single function, but that could break in subtle ways.
2137 #define foreach_standard_reply_retval_handler \
2138 _(sw_interface_set_flags_reply) \
2139 _(sw_interface_add_del_address_reply) \
2140 _(sw_interface_set_table_reply) \
2141 _(sw_interface_set_vpath_reply) \
2142 _(sw_interface_set_l2_bridge_reply) \
2143 _(bridge_domain_add_del_reply) \
2144 _(sw_interface_set_l2_xconnect_reply) \
2145 _(l2fib_add_del_reply) \
2146 _(ip_add_del_route_reply) \
2147 _(proxy_arp_add_del_reply) \
2148 _(proxy_arp_intfc_enable_disable_reply) \
2149 _(mpls_add_del_encap_reply) \
2150 _(mpls_add_del_decap_reply) \
2151 _(mpls_ethernet_add_del_tunnel_2_reply) \
2152 _(sw_interface_set_unnumbered_reply) \
2153 _(ip_neighbor_add_del_reply) \
2154 _(reset_vrf_reply) \
2155 _(oam_add_del_reply) \
2156 _(reset_fib_reply) \
2157 _(dhcp_proxy_config_reply) \
2158 _(dhcp_proxy_config_2_reply) \
2159 _(dhcp_proxy_set_vss_reply) \
2160 _(dhcp_client_config_reply) \
2161 _(set_ip_flow_hash_reply) \
2162 _(sw_interface_ip6_enable_disable_reply) \
2163 _(sw_interface_ip6_set_link_local_address_reply) \
2164 _(sw_interface_ip6nd_ra_prefix_reply) \
2165 _(sw_interface_ip6nd_ra_config_reply) \
2166 _(set_arp_neighbor_limit_reply) \
2167 _(l2_patch_add_del_reply) \
2168 _(sr_tunnel_add_del_reply) \
2169 _(sr_policy_add_del_reply) \
2170 _(sr_multicast_map_add_del_reply) \
2171 _(classify_add_del_session_reply) \
2172 _(classify_set_interface_ip_table_reply) \
2173 _(classify_set_interface_l2_tables_reply) \
2174 _(l2tpv3_set_tunnel_cookies_reply) \
2175 _(l2tpv3_interface_enable_disable_reply) \
2176 _(l2tpv3_set_lookup_key_reply) \
2177 _(l2_fib_clear_table_reply) \
2178 _(l2_interface_efp_filter_reply) \
2179 _(l2_interface_vlan_tag_rewrite_reply) \
2180 _(modify_vhost_user_if_reply) \
2181 _(delete_vhost_user_if_reply) \
2182 _(want_ip4_arp_events_reply) \
2183 _(input_acl_set_interface_reply) \
2184 _(ipsec_spd_add_del_reply) \
2185 _(ipsec_interface_add_del_spd_reply) \
2186 _(ipsec_spd_add_del_entry_reply) \
2187 _(ipsec_sad_add_del_entry_reply) \
2188 _(ipsec_sa_set_key_reply) \
2189 _(ikev2_profile_add_del_reply) \
2190 _(ikev2_profile_set_auth_reply) \
2191 _(ikev2_profile_set_id_reply) \
2192 _(ikev2_profile_set_ts_reply) \
2193 _(ikev2_set_local_key_reply) \
2194 _(delete_loopback_reply) \
2195 _(bd_ip_mac_add_del_reply) \
2196 _(map_del_domain_reply) \
2197 _(map_add_del_rule_reply) \
2198 _(want_interface_events_reply) \
2199 _(want_stats_reply) \
2200 _(cop_interface_enable_disable_reply) \
2201 _(cop_whitelist_enable_disable_reply) \
2202 _(sw_interface_clear_stats_reply) \
2203 _(trace_profile_add_reply) \
2204 _(trace_profile_apply_reply) \
2205 _(trace_profile_del_reply) \
2206 _(lisp_add_del_locator_set_reply) \
2207 _(lisp_add_del_locator_reply) \
2208 _(lisp_add_del_local_eid_reply) \
2209 _(lisp_gpe_add_del_fwd_entry_reply) \
2210 _(lisp_add_del_map_resolver_reply) \
2211 _(lisp_gpe_enable_disable_reply) \
2212 _(lisp_gpe_add_del_iface_reply) \
2213 _(lisp_enable_disable_reply) \
2214 _(af_packet_create_reply) \
2215 _(af_packet_delete_reply)
2218 static void vl_api_##n##_t_handler \
2219 (vl_api_##n##_t * mp) \
2221 vat_main_t * vam = &vat_main; \
2222 i32 retval = ntohl(mp->retval); \
2223 if (vam->async_mode) { \
2224 vam->async_errors += (retval < 0); \
2226 vam->retval = retval; \
2227 vam->result_ready = 1; \
2230 foreach_standard_reply_retval_handler;
2234 static void vl_api_##n##_t_handler_json \
2235 (vl_api_##n##_t * mp) \
2237 vat_main_t * vam = &vat_main; \
2238 vat_json_node_t node; \
2239 vat_json_init_object(&node); \
2240 vat_json_object_add_int(&node, "retval", ntohl(mp->retval)); \
2241 vat_json_print(vam->ofp, &node); \
2242 vam->retval = ntohl(mp->retval); \
2243 vam->result_ready = 1; \
2245 foreach_standard_reply_retval_handler;
2249 * Table of message reply handlers, must include boilerplate handlers
2253 #define foreach_vpe_api_reply_msg \
2254 _(CREATE_LOOPBACK_REPLY, create_loopback_reply) \
2255 _(SW_INTERFACE_DETAILS, sw_interface_details) \
2256 _(SW_INTERFACE_SET_FLAGS, sw_interface_set_flags) \
2257 _(SW_INTERFACE_SET_FLAGS_REPLY, sw_interface_set_flags_reply) \
2258 _(CONTROL_PING_REPLY, control_ping_reply) \
2259 _(CLI_REPLY, cli_reply) \
2260 _(SW_INTERFACE_ADD_DEL_ADDRESS_REPLY, \
2261 sw_interface_add_del_address_reply) \
2262 _(SW_INTERFACE_SET_TABLE_REPLY, sw_interface_set_table_reply) \
2263 _(SW_INTERFACE_SET_VPATH_REPLY, sw_interface_set_vpath_reply) \
2264 _(SW_INTERFACE_SET_L2_XCONNECT_REPLY, \
2265 sw_interface_set_l2_xconnect_reply) \
2266 _(SW_INTERFACE_SET_L2_BRIDGE_REPLY, \
2267 sw_interface_set_l2_bridge_reply) \
2268 _(BRIDGE_DOMAIN_ADD_DEL_REPLY, bridge_domain_add_del_reply) \
2269 _(BRIDGE_DOMAIN_DETAILS, bridge_domain_details) \
2270 _(BRIDGE_DOMAIN_SW_IF_DETAILS, bridge_domain_sw_if_details) \
2271 _(L2FIB_ADD_DEL_REPLY, l2fib_add_del_reply) \
2272 _(L2_FLAGS_REPLY, l2_flags_reply) \
2273 _(BRIDGE_FLAGS_REPLY, bridge_flags_reply) \
2274 _(TAP_CONNECT_REPLY, tap_connect_reply) \
2275 _(TAP_MODIFY_REPLY, tap_modify_reply) \
2276 _(TAP_DELETE_REPLY, tap_delete_reply) \
2277 _(SW_INTERFACE_TAP_DETAILS, sw_interface_tap_details) \
2278 _(IP_ADD_DEL_ROUTE_REPLY, ip_add_del_route_reply) \
2279 _(PROXY_ARP_ADD_DEL_REPLY, proxy_arp_add_del_reply) \
2280 _(PROXY_ARP_INTFC_ENABLE_DISABLE_REPLY, \
2281 proxy_arp_intfc_enable_disable_reply) \
2282 _(MPLS_ADD_DEL_ENCAP_REPLY, mpls_add_del_encap_reply) \
2283 _(MPLS_ADD_DEL_DECAP_REPLY, mpls_add_del_decap_reply) \
2284 _(MPLS_GRE_ADD_DEL_TUNNEL_REPLY, mpls_gre_add_del_tunnel_reply) \
2285 _(MPLS_ETHERNET_ADD_DEL_TUNNEL_REPLY, \
2286 mpls_ethernet_add_del_tunnel_reply) \
2287 _(MPLS_ETHERNET_ADD_DEL_TUNNEL_2_REPLY, \
2288 mpls_ethernet_add_del_tunnel_2_reply) \
2289 _(SW_INTERFACE_SET_UNNUMBERED_REPLY, \
2290 sw_interface_set_unnumbered_reply) \
2291 _(IP_NEIGHBOR_ADD_DEL_REPLY, ip_neighbor_add_del_reply) \
2292 _(RESET_VRF_REPLY, reset_vrf_reply) \
2293 _(CREATE_VLAN_SUBIF_REPLY, create_vlan_subif_reply) \
2294 _(CREATE_SUBIF_REPLY, create_subif_reply) \
2295 _(OAM_ADD_DEL_REPLY, oam_add_del_reply) \
2296 _(RESET_FIB_REPLY, reset_fib_reply) \
2297 _(DHCP_PROXY_CONFIG_REPLY, dhcp_proxy_config_reply) \
2298 _(DHCP_PROXY_CONFIG_2_REPLY, dhcp_proxy_config_2_reply) \
2299 _(DHCP_PROXY_SET_VSS_REPLY, dhcp_proxy_set_vss_reply) \
2300 _(DHCP_CLIENT_CONFIG_REPLY, dhcp_client_config_reply) \
2301 _(SET_IP_FLOW_HASH_REPLY, set_ip_flow_hash_reply) \
2302 _(SW_INTERFACE_IP6_ENABLE_DISABLE_REPLY, \
2303 sw_interface_ip6_enable_disable_reply) \
2304 _(SW_INTERFACE_IP6_SET_LINK_LOCAL_ADDRESS_REPLY, \
2305 sw_interface_ip6_set_link_local_address_reply) \
2306 _(SW_INTERFACE_IP6ND_RA_PREFIX_REPLY, \
2307 sw_interface_ip6nd_ra_prefix_reply) \
2308 _(SW_INTERFACE_IP6ND_RA_CONFIG_REPLY, \
2309 sw_interface_ip6nd_ra_config_reply) \
2310 _(SET_ARP_NEIGHBOR_LIMIT_REPLY, set_arp_neighbor_limit_reply) \
2311 _(L2_PATCH_ADD_DEL_REPLY, l2_patch_add_del_reply) \
2312 _(SR_TUNNEL_ADD_DEL_REPLY, sr_tunnel_add_del_reply) \
2313 _(SR_POLICY_ADD_DEL_REPLY, sr_policy_add_del_reply) \
2314 _(SR_MULTICAST_MAP_ADD_DEL_REPLY, sr_multicast_map_add_del_reply) \
2315 _(CLASSIFY_ADD_DEL_TABLE_REPLY, classify_add_del_table_reply) \
2316 _(CLASSIFY_ADD_DEL_SESSION_REPLY, classify_add_del_session_reply) \
2317 _(CLASSIFY_SET_INTERFACE_IP_TABLE_REPLY, \
2318 classify_set_interface_ip_table_reply) \
2319 _(CLASSIFY_SET_INTERFACE_L2_TABLES_REPLY, \
2320 classify_set_interface_l2_tables_reply) \
2321 _(GET_NODE_INDEX_REPLY, get_node_index_reply) \
2322 _(ADD_NODE_NEXT_REPLY, add_node_next_reply) \
2323 _(L2TPV3_CREATE_TUNNEL_REPLY, l2tpv3_create_tunnel_reply) \
2324 _(L2TPV3_SET_TUNNEL_COOKIES_REPLY, l2tpv3_set_tunnel_cookies_reply) \
2325 _(L2TPV3_INTERFACE_ENABLE_DISABLE_REPLY, \
2326 l2tpv3_interface_enable_disable_reply) \
2327 _(L2TPV3_SET_LOOKUP_KEY_REPLY, l2tpv3_set_lookup_key_reply) \
2328 _(SW_IF_L2TPV3_TUNNEL_DETAILS, sw_if_l2tpv3_tunnel_details) \
2329 _(VXLAN_ADD_DEL_TUNNEL_REPLY, vxlan_add_del_tunnel_reply) \
2330 _(VXLAN_TUNNEL_DETAILS, vxlan_tunnel_details) \
2331 _(GRE_ADD_DEL_TUNNEL_REPLY, gre_add_del_tunnel_reply) \
2332 _(GRE_TUNNEL_DETAILS, gre_tunnel_details) \
2333 _(L2_FIB_CLEAR_TABLE_REPLY, l2_fib_clear_table_reply) \
2334 _(L2_INTERFACE_EFP_FILTER_REPLY, l2_interface_efp_filter_reply) \
2335 _(L2_INTERFACE_VLAN_TAG_REWRITE_REPLY, l2_interface_vlan_tag_rewrite_reply) \
2336 _(SW_INTERFACE_VHOST_USER_DETAILS, sw_interface_vhost_user_details) \
2337 _(CREATE_VHOST_USER_IF_REPLY, create_vhost_user_if_reply) \
2338 _(MODIFY_VHOST_USER_IF_REPLY, modify_vhost_user_if_reply) \
2339 _(DELETE_VHOST_USER_IF_REPLY, delete_vhost_user_if_reply) \
2340 _(SHOW_VERSION_REPLY, show_version_reply) \
2341 _(NSH_GRE_ADD_DEL_TUNNEL_REPLY, nsh_gre_add_del_tunnel_reply) \
2342 _(L2_FIB_TABLE_ENTRY, l2_fib_table_entry) \
2343 _(NSH_VXLAN_GPE_ADD_DEL_TUNNEL_REPLY, nsh_vxlan_gpe_add_del_tunnel_reply) \
2344 _(INTERFACE_NAME_RENUMBER_REPLY, interface_name_renumber_reply) \
2345 _(WANT_IP4_ARP_EVENTS_REPLY, want_ip4_arp_events_reply) \
2346 _(IP4_ARP_EVENT, ip4_arp_event) \
2347 _(INPUT_ACL_SET_INTERFACE_REPLY, input_acl_set_interface_reply) \
2348 _(IP_ADDRESS_DETAILS, ip_address_details) \
2349 _(IP_DETAILS, ip_details) \
2350 _(IPSEC_SPD_ADD_DEL_REPLY, ipsec_spd_add_del_reply) \
2351 _(IPSEC_INTERFACE_ADD_DEL_SPD_REPLY, ipsec_interface_add_del_spd_reply) \
2352 _(IPSEC_SPD_ADD_DEL_ENTRY_REPLY, ipsec_spd_add_del_entry_reply) \
2353 _(IPSEC_SAD_ADD_DEL_ENTRY_REPLY, ipsec_sad_add_del_entry_reply) \
2354 _(IPSEC_SA_SET_KEY_REPLY, ipsec_sa_set_key_reply) \
2355 _(IKEV2_PROFILE_ADD_DEL_REPLY, ikev2_profile_add_del_reply) \
2356 _(IKEV2_PROFILE_SET_AUTH_REPLY, ikev2_profile_set_auth_reply) \
2357 _(IKEV2_PROFILE_SET_ID_REPLY, ikev2_profile_set_id_reply) \
2358 _(IKEV2_PROFILE_SET_TS_REPLY, ikev2_profile_set_ts_reply) \
2359 _(IKEV2_SET_LOCAL_KEY_REPLY, ikev2_set_local_key_reply) \
2360 _(DELETE_LOOPBACK_REPLY, delete_loopback_reply) \
2361 _(BD_IP_MAC_ADD_DEL_REPLY, bd_ip_mac_add_del_reply) \
2362 _(DHCP_COMPL_EVENT, dhcp_compl_event) \
2363 _(VNET_INTERFACE_COUNTERS, vnet_interface_counters) \
2364 _(VNET_IP4_FIB_COUNTERS, vnet_ip4_fib_counters) \
2365 _(VNET_IP6_FIB_COUNTERS, vnet_ip6_fib_counters) \
2366 _(MAP_ADD_DOMAIN_REPLY, map_add_domain_reply) \
2367 _(MAP_DEL_DOMAIN_REPLY, map_del_domain_reply) \
2368 _(MAP_ADD_DEL_RULE_REPLY, map_add_del_rule_reply) \
2369 _(MAP_DOMAIN_DETAILS, map_domain_details) \
2370 _(MAP_RULE_DETAILS, map_rule_details) \
2371 _(WANT_INTERFACE_EVENTS_REPLY, want_interface_events_reply) \
2372 _(WANT_STATS_REPLY, want_stats_reply) \
2373 _(GET_FIRST_MSG_ID_REPLY, get_first_msg_id_reply) \
2374 _(COP_INTERFACE_ENABLE_DISABLE_REPLY, cop_interface_enable_disable_reply) \
2375 _(COP_WHITELIST_ENABLE_DISABLE_REPLY, cop_whitelist_enable_disable_reply) \
2376 _(GET_NODE_GRAPH_REPLY, get_node_graph_reply) \
2377 _(SW_INTERFACE_CLEAR_STATS_REPLY, sw_interface_clear_stats_reply) \
2378 _(TRACE_PROFILE_ADD_REPLY, trace_profile_add_reply) \
2379 _(TRACE_PROFILE_APPLY_REPLY, trace_profile_apply_reply) \
2380 _(TRACE_PROFILE_DEL_REPLY, trace_profile_del_reply) \
2381 _(LISP_ADD_DEL_LOCATOR_SET_REPLY, lisp_add_del_locator_set_reply) \
2382 _(LISP_ADD_DEL_LOCATOR_REPLY, lisp_add_del_locator_reply) \
2383 _(LISP_ADD_DEL_LOCAL_EID_REPLY, lisp_add_del_local_eid_reply) \
2384 _(LISP_GPE_ADD_DEL_FWD_ENTRY_REPLY, lisp_gpe_add_del_fwd_entry_reply) \
2385 _(LISP_ADD_DEL_MAP_RESOLVER_REPLY, lisp_add_del_map_resolver_reply) \
2386 _(LISP_GPE_ENABLE_DISABLE_REPLY, lisp_gpe_enable_disable_reply) \
2387 _(LISP_ENABLE_DISABLE_REPLY, lisp_enable_disable_reply) \
2388 _(LISP_GPE_ADD_DEL_IFACE_REPLY, lisp_gpe_add_del_iface_reply) \
2389 _(LISP_LOCATOR_SET_DETAILS, lisp_locator_set_details) \
2390 _(LISP_LOCAL_EID_TABLE_DETAILS, lisp_local_eid_table_details) \
2391 _(LISP_GPE_TUNNEL_DETAILS, lisp_gpe_tunnel_details) \
2392 _(LISP_MAP_RESOLVER_DETAILS, lisp_map_resolver_details) \
2393 _(LISP_ENABLE_DISABLE_STATUS_DETAILS, \
2394 lisp_enable_disable_status_details) \
2395 _(AF_PACKET_CREATE_REPLY, af_packet_create_reply) \
2396 _(AF_PACKET_DELETE_REPLY, af_packet_delete_reply)
2398 /* M: construct, but don't yet send a message */
2402 vam->result_ready = 0; \
2403 mp = vl_msg_api_alloc(sizeof(*mp)); \
2404 memset (mp, 0, sizeof (*mp)); \
2405 mp->_vl_msg_id = ntohs (VL_API_##T); \
2406 mp->client_index = vam->my_client_index; \
2411 vam->result_ready = 0; \
2412 mp = vl_msg_api_alloc(sizeof(*mp)+(n)); \
2413 memset (mp, 0, sizeof (*mp)); \
2414 mp->_vl_msg_id = ntohs (VL_API_##T); \
2415 mp->client_index = vam->my_client_index; \
2419 /* S: send a message */
2420 #define S (vl_msg_api_send_shmem (vam->vl_input_queue, (u8 *)&mp))
2422 /* W: wait for results, with timeout */
2425 timeout = vat_time_now (vam) + 1.0; \
2427 while (vat_time_now (vam) < timeout) { \
2428 if (vam->result_ready == 1) { \
2429 return (vam->retval); \
2441 #define STR_VTR_OP_CASE(op) \
2442 case L2_VTR_ ## op: \
2445 static const char *str_vtr_op(u32 vtr_op)
2448 STR_VTR_OP_CASE(DISABLED);
2449 STR_VTR_OP_CASE(PUSH_1);
2450 STR_VTR_OP_CASE(PUSH_2);
2451 STR_VTR_OP_CASE(POP_1);
2452 STR_VTR_OP_CASE(POP_2);
2453 STR_VTR_OP_CASE(TRANSLATE_1_1);
2454 STR_VTR_OP_CASE(TRANSLATE_1_2);
2455 STR_VTR_OP_CASE(TRANSLATE_2_1);
2456 STR_VTR_OP_CASE(TRANSLATE_2_2);
2462 static int dump_sub_interface_table (vat_main_t * vam)
2464 const sw_interface_subif_t * sub = NULL;
2466 if (vam->json_output) {
2467 clib_warning ("JSON output supported only for VPE API calls and dump_stats_table");
2472 "%-30s%-12s%-11s%-7s%-5s%-9s%-9s%-6s%-8s%-10s%-10s\n",
2473 "Interface", "sw_if_index",
2474 "sub id", "dot1ad", "tags", "outer id",
2475 "inner id", "exact", "default",
2476 "outer any", "inner any");
2478 vec_foreach (sub, vam->sw_if_subif_table) {
2480 "%-30s%-12d%-11d%-7s%-5d%-9d%-9d%-6d%-8d%-10d%-10d\n",
2481 sub->interface_name,
2483 sub->sub_id, sub->sub_dot1ad ? "dot1ad" : "dot1q",
2484 sub->sub_number_of_tags, sub->sub_outer_vlan_id,
2485 sub->sub_inner_vlan_id, sub->sub_exact_match, sub->sub_default,
2486 sub->sub_outer_vlan_id_any, sub->sub_inner_vlan_id_any);
2487 if (sub->vtr_op != L2_VTR_DISABLED) {
2489 " vlan-tag-rewrite - op: %-14s [ dot1q: %d "
2490 "tag1: %d tag2: %d ]\n",
2491 str_vtr_op(sub->vtr_op), sub->vtr_push_dot1q,
2492 sub->vtr_tag1, sub->vtr_tag2);
2499 static int name_sort_cmp (void * a1, void * a2)
2501 name_sort_t * n1 = a1;
2502 name_sort_t * n2 = a2;
2504 return strcmp ((char *)n1->name, (char *)n2->name);
2507 static int dump_interface_table (vat_main_t * vam)
2510 name_sort_t * nses = 0, * ns;
2512 if (vam->json_output) {
2513 clib_warning ("JSON output supported only for VPE API calls and dump_stats_table");
2517 hash_foreach_pair (p, vam->sw_if_index_by_interface_name,
2519 vec_add2 (nses, ns, 1);
2520 ns->name = (u8 *)(p->key);
2521 ns->value = (u32) p->value[0];
2524 vec_sort_with_function (nses, name_sort_cmp);
2526 fformat (vam->ofp, "%-25s%-15s\n", "Interface", "sw_if_index");
2527 vec_foreach (ns, nses) {
2528 fformat (vam->ofp, "%-25s%-15d\n", ns->name, ns->value);
2534 static int dump_ip_table (vat_main_t * vam, int is_ipv6)
2536 const ip_details_t * det = NULL;
2537 const ip_address_details_t * address = NULL;
2548 vec_foreach (det, vam->ip_details_by_sw_if_index[is_ipv6]) {
2550 if (!det->present) {
2558 "Address", "Prefix length");
2562 vec_foreach (address, det->addr) {
2565 is_ipv6 ? format_ip6_address : format_ip4_address,
2567 address->prefix_length);
2574 static int dump_ipv4_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, 0);
2584 static int dump_ipv6_table (vat_main_t * vam)
2586 if (vam->json_output) {
2587 clib_warning ("JSON output supported only for VPE API calls and dump_stats_table");
2591 return dump_ip_table (vam, 1);
2594 static char* counter_type_to_str (u8 counter_type, u8 is_combined)
2597 switch(counter_type) {
2598 case VNET_INTERFACE_COUNTER_DROP:
2600 case VNET_INTERFACE_COUNTER_PUNT:
2602 case VNET_INTERFACE_COUNTER_IP4:
2604 case VNET_INTERFACE_COUNTER_IP6:
2606 case VNET_INTERFACE_COUNTER_RX_NO_BUF:
2608 case VNET_INTERFACE_COUNTER_RX_MISS:
2610 case VNET_INTERFACE_COUNTER_RX_ERROR:
2612 case VNET_INTERFACE_COUNTER_TX_ERROR:
2615 return "INVALID-COUNTER-TYPE";
2618 switch(counter_type) {
2619 case VNET_INTERFACE_COUNTER_RX:
2621 case VNET_INTERFACE_COUNTER_TX:
2624 return "INVALID-COUNTER-TYPE";
2629 static int dump_stats_table (vat_main_t * vam)
2631 vat_json_node_t node;
2632 vat_json_node_t *msg_array;
2633 vat_json_node_t *msg;
2634 vat_json_node_t *counter_array;
2635 vat_json_node_t *counter;
2636 interface_counter_t c;
2638 ip4_fib_counter_t *c4;
2639 ip6_fib_counter_t *c6;
2642 if (!vam->json_output) {
2643 clib_warning ("dump_stats_table supported only in JSON format");
2647 vat_json_init_object(&node);
2649 /* interface counters */
2650 msg_array = vat_json_object_add(&node, "interface_counters");
2651 vat_json_init_array(msg_array);
2652 for (i = 0; i < vec_len(vam->simple_interface_counters); i++) {
2653 msg = vat_json_array_add(msg_array);
2654 vat_json_init_object(msg);
2655 vat_json_object_add_string_copy(msg, "vnet_counter_type",
2656 (u8*)counter_type_to_str(i, 0));
2657 vat_json_object_add_int(msg, "is_combined", 0);
2658 counter_array = vat_json_object_add(msg, "data");
2659 vat_json_init_array(counter_array);
2660 for (j = 0; j < vec_len(vam->simple_interface_counters[i]); j++) {
2661 packets = vam->simple_interface_counters[i][j];
2662 vat_json_array_add_uint(counter_array, packets);
2665 for (i = 0; i < vec_len(vam->combined_interface_counters); i++) {
2666 msg = vat_json_array_add(msg_array);
2667 vat_json_init_object(msg);
2668 vat_json_object_add_string_copy(msg, "vnet_counter_type",
2669 (u8*)counter_type_to_str(i, 1));
2670 vat_json_object_add_int(msg, "is_combined", 1);
2671 counter_array = vat_json_object_add(msg, "data");
2672 vat_json_init_array(counter_array);
2673 for (j = 0; j < vec_len(vam->combined_interface_counters[i]); j++) {
2674 c = vam->combined_interface_counters[i][j];
2675 counter = vat_json_array_add(counter_array);
2676 vat_json_init_object(counter);
2677 vat_json_object_add_uint(counter, "packets", c.packets);
2678 vat_json_object_add_uint(counter, "bytes", c.bytes);
2682 /* ip4 fib counters */
2683 msg_array = vat_json_object_add(&node, "ip4_fib_counters");
2684 vat_json_init_array(msg_array);
2685 for (i = 0; i < vec_len(vam->ip4_fib_counters); i++) {
2686 msg = vat_json_array_add(msg_array);
2687 vat_json_init_object(msg);
2688 vat_json_object_add_uint(msg, "vrf_id", vam->ip4_fib_counters_vrf_id_by_index[i]);
2689 counter_array = vat_json_object_add(msg, "c");
2690 vat_json_init_array(counter_array);
2691 for (j = 0; j < vec_len(vam->ip4_fib_counters[i]); j++) {
2692 counter = vat_json_array_add(counter_array);
2693 vat_json_init_object(counter);
2694 c4 = &vam->ip4_fib_counters[i][j];
2695 vat_json_object_add_ip4(counter, "address", c4->address);
2696 vat_json_object_add_uint(counter, "address_length", c4->address_length);
2697 vat_json_object_add_uint(counter, "packets", c4->packets);
2698 vat_json_object_add_uint(counter, "bytes", c4->bytes);
2702 /* ip6 fib counters */
2703 msg_array = vat_json_object_add(&node, "ip6_fib_counters");
2704 vat_json_init_array(msg_array);
2705 for (i = 0; i < vec_len(vam->ip6_fib_counters); i++) {
2706 msg = vat_json_array_add(msg_array);
2707 vat_json_init_object(msg);
2708 vat_json_object_add_uint(msg, "vrf_id", vam->ip6_fib_counters_vrf_id_by_index[i]);
2709 counter_array = vat_json_object_add(msg, "c");
2710 vat_json_init_array(counter_array);
2711 for (j = 0; j < vec_len(vam->ip6_fib_counters[i]); j++) {
2712 counter = vat_json_array_add(counter_array);
2713 vat_json_init_object(counter);
2714 c6 = &vam->ip6_fib_counters[i][j];
2715 vat_json_object_add_ip6(counter, "address", c6->address);
2716 vat_json_object_add_uint(counter, "address_length", c6->address_length);
2717 vat_json_object_add_uint(counter, "packets", c6->packets);
2718 vat_json_object_add_uint(counter, "bytes", c6->bytes);
2722 vat_json_print(vam->ofp, &node);
2723 vat_json_free(&node);
2728 int exec (vat_main_t * vam)
2730 api_main_t * am = &api_main;
2731 vl_api_cli_request_t *mp;
2735 unformat_input_t * i = vam->input;
2737 if (vec_len(i->buffer) == 0)
2740 if (vam->exec_mode == 0 && unformat (i, "mode")) {
2744 if (vam->exec_mode == 1 &&
2745 (unformat (i, "exit") || unformat (i, "quit"))) {
2751 M(CLI_REQUEST, cli_request);
2754 * Copy cmd into shared memory.
2755 * In order for the CLI command to work, it
2756 * must be a vector ending in \n, not a C-string ending
2759 pthread_mutex_lock (&am->vlib_rp->mutex);
2760 oldheap = svm_push_data_heap (am->vlib_rp);
2762 vec_validate (cmd, vec_len(vam->input->buffer)-1);
2763 clib_memcpy (cmd, vam->input->buffer, vec_len(vam->input->buffer));
2765 svm_pop_heap (oldheap);
2766 pthread_mutex_unlock (&am->vlib_rp->mutex);
2768 mp->cmd_in_shmem = (u64) cmd;
2770 timeout = vat_time_now (vam) + 10.0;
2772 while (vat_time_now (vam) < timeout) {
2773 if (vam->result_ready == 1) {
2775 if (vam->shmem_result != NULL)
2776 fformat (vam->ofp, "%s", vam->shmem_result);
2777 pthread_mutex_lock (&am->vlib_rp->mutex);
2778 oldheap = svm_push_data_heap (am->vlib_rp);
2780 free_me = (u8 *)vam->shmem_result;
2783 svm_pop_heap (oldheap);
2784 pthread_mutex_unlock (&am->vlib_rp->mutex);
2791 static int api_create_loopback (vat_main_t * vam)
2793 unformat_input_t * i = vam->input;
2794 vl_api_create_loopback_t *mp;
2799 memset (mac_address, 0, sizeof (mac_address));
2801 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
2803 if (unformat (i, "mac %U", unformat_ethernet_address, mac_address))
2809 /* Construct the API message */
2810 M(CREATE_LOOPBACK, create_loopback);
2812 clib_memcpy (mp->mac_address, mac_address, sizeof (mac_address));
2817 static int api_delete_loopback (vat_main_t * vam)
2819 unformat_input_t * i = vam->input;
2820 vl_api_delete_loopback_t *mp;
2822 u32 sw_if_index = ~0;
2824 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
2826 if (unformat (i, "sw_if_index %d", &sw_if_index))
2832 if (sw_if_index == ~0)
2834 errmsg ("missing sw_if_index\n");
2838 /* Construct the API message */
2839 M(DELETE_LOOPBACK, delete_loopback);
2840 mp->sw_if_index = ntohl (sw_if_index);
2845 static int api_want_stats (vat_main_t * vam)
2847 unformat_input_t * i = vam->input;
2848 vl_api_want_stats_t * mp;
2852 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
2854 if (unformat (i, "enable"))
2856 else if (unformat (i, "disable"))
2864 errmsg ("missing enable|disable\n");
2868 M(WANT_STATS, want_stats);
2869 mp->enable_disable = enable;
2874 static int api_want_interface_events (vat_main_t * vam)
2876 unformat_input_t * i = vam->input;
2877 vl_api_want_interface_events_t * mp;
2881 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
2883 if (unformat (i, "enable"))
2885 else if (unformat (i, "disable"))
2893 errmsg ("missing enable|disable\n");
2897 M(WANT_INTERFACE_EVENTS, want_interface_events);
2898 mp->enable_disable = enable;
2900 vam->interface_event_display = enable;
2906 /* Note: non-static, called once to set up the initial intfc table */
2907 int api_sw_interface_dump (vat_main_t * vam)
2909 vl_api_sw_interface_dump_t *mp;
2912 name_sort_t * nses = 0, * ns;
2913 sw_interface_subif_t * sub = NULL;
2915 /* Toss the old name table */
2916 hash_foreach_pair (p, vam->sw_if_index_by_interface_name,
2918 vec_add2 (nses, ns, 1);
2919 ns->name = (u8 *)(p->key);
2920 ns->value = (u32) p->value[0];
2923 hash_free (vam->sw_if_index_by_interface_name);
2925 vec_foreach (ns, nses)
2926 vec_free (ns->name);
2930 vec_foreach (sub, vam->sw_if_subif_table) {
2931 vec_free (sub->interface_name);
2933 vec_free (vam->sw_if_subif_table);
2935 /* recreate the interface name hash table */
2936 vam->sw_if_index_by_interface_name
2937 = hash_create_string (0, sizeof(uword));
2939 /* Get list of ethernets */
2940 M(SW_INTERFACE_DUMP, sw_interface_dump);
2941 mp->name_filter_valid = 1;
2942 strncpy ((char *) mp->name_filter, "Ether", sizeof(mp->name_filter)-1);
2945 /* and local / loopback interfaces */
2946 M(SW_INTERFACE_DUMP, sw_interface_dump);
2947 mp->name_filter_valid = 1;
2948 strncpy ((char *) mp->name_filter, "lo", sizeof(mp->name_filter)-1);
2951 /* and vxlan tunnel interfaces */
2952 M(SW_INTERFACE_DUMP, sw_interface_dump);
2953 mp->name_filter_valid = 1;
2954 strncpy ((char *) mp->name_filter, "vxlan", sizeof(mp->name_filter)-1);
2957 /* and host (af_packet) interfaces */
2958 M(SW_INTERFACE_DUMP, sw_interface_dump);
2959 mp->name_filter_valid = 1;
2960 strncpy ((char *) mp->name_filter, "host", sizeof(mp->name_filter)-1);
2963 /* and l2tpv3 tunnel interfaces */
2964 M(SW_INTERFACE_DUMP, sw_interface_dump);
2965 mp->name_filter_valid = 1;
2966 strncpy ((char *) mp->name_filter, "l2tpv3_tunnel", sizeof(mp->name_filter)-1);
2969 /* and GRE tunnel interfaces */
2970 M(SW_INTERFACE_DUMP, sw_interface_dump);
2971 mp->name_filter_valid = 1;
2972 strncpy ((char *) mp->name_filter, "gre", sizeof(mp->name_filter)-1);
2975 /* Use a control ping for synchronization */
2977 vl_api_control_ping_t * mp;
2978 M(CONTROL_PING, control_ping);
2984 static int api_sw_interface_set_flags (vat_main_t * vam)
2986 unformat_input_t * i = vam->input;
2987 vl_api_sw_interface_set_flags_t *mp;
2990 u8 sw_if_index_set = 0;
2991 u8 admin_up = 0, link_up = 0;
2993 /* Parse args required to build the message */
2994 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
2995 if (unformat (i, "admin-up"))
2997 else if (unformat (i, "admin-down"))
2999 else if (unformat (i, "link-up"))
3001 else if (unformat (i, "link-down"))
3003 else if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
3004 sw_if_index_set = 1;
3005 else if (unformat (i, "sw_if_index %d", &sw_if_index))
3006 sw_if_index_set = 1;
3011 if (sw_if_index_set == 0) {
3012 errmsg ("missing interface name or sw_if_index\n");
3016 /* Construct the API message */
3017 M(SW_INTERFACE_SET_FLAGS, sw_interface_set_flags);
3018 mp->sw_if_index = ntohl (sw_if_index);
3019 mp->admin_up_down = admin_up;
3020 mp->link_up_down = link_up;
3025 /* Wait for a reply, return the good/bad news... */
3029 static int api_sw_interface_clear_stats (vat_main_t * vam)
3031 unformat_input_t * i = vam->input;
3032 vl_api_sw_interface_clear_stats_t *mp;
3035 u8 sw_if_index_set = 0;
3037 /* Parse args required to build the message */
3038 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
3039 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
3040 sw_if_index_set = 1;
3041 else if (unformat (i, "sw_if_index %d", &sw_if_index))
3042 sw_if_index_set = 1;
3047 /* Construct the API message */
3048 M(SW_INTERFACE_CLEAR_STATS, sw_interface_clear_stats);
3050 if (sw_if_index_set == 1)
3051 mp->sw_if_index = ntohl (sw_if_index);
3053 mp->sw_if_index = ~0;
3058 /* Wait for a reply, return the good/bad news... */
3062 static int api_sw_interface_add_del_address (vat_main_t * vam)
3064 unformat_input_t * i = vam->input;
3065 vl_api_sw_interface_add_del_address_t *mp;
3068 u8 sw_if_index_set = 0;
3069 u8 is_add = 1, del_all = 0;
3070 u32 address_length = 0;
3071 u8 v4_address_set = 0;
3072 u8 v6_address_set = 0;
3073 ip4_address_t v4address;
3074 ip6_address_t v6address;
3076 /* Parse args required to build the message */
3077 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
3078 if (unformat (i, "del-all"))
3080 else if (unformat (i, "del"))
3082 else if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
3083 sw_if_index_set = 1;
3084 else if (unformat (i, "sw_if_index %d", &sw_if_index))
3085 sw_if_index_set = 1;
3086 else if (unformat (i, "%U/%d",
3087 unformat_ip4_address, &v4address,
3090 else if (unformat (i, "%U/%d",
3091 unformat_ip6_address, &v6address,
3098 if (sw_if_index_set == 0) {
3099 errmsg ("missing interface name or sw_if_index\n");
3102 if (v4_address_set && v6_address_set) {
3103 errmsg ("both v4 and v6 addresses set\n");
3106 if (!v4_address_set && !v6_address_set && !del_all) {
3107 errmsg ("no addresses set\n");
3111 /* Construct the API message */
3112 M(SW_INTERFACE_ADD_DEL_ADDRESS, sw_interface_add_del_address);
3114 mp->sw_if_index = ntohl (sw_if_index);
3115 mp->is_add = is_add;
3116 mp->del_all = del_all;
3117 if (v6_address_set) {
3119 clib_memcpy (mp->address, &v6address, sizeof (v6address));
3121 clib_memcpy (mp->address, &v4address, sizeof (v4address));
3123 mp->address_length = address_length;
3128 /* Wait for a reply, return good/bad news */
3132 static int api_sw_interface_set_table (vat_main_t * vam)
3134 unformat_input_t * i = vam->input;
3135 vl_api_sw_interface_set_table_t *mp;
3137 u32 sw_if_index, vrf_id = 0;
3138 u8 sw_if_index_set = 0;
3141 /* Parse args required to build the message */
3142 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
3143 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
3144 sw_if_index_set = 1;
3145 else if (unformat (i, "sw_if_index %d", &sw_if_index))
3146 sw_if_index_set = 1;
3147 else if (unformat (i, "vrf %d", &vrf_id))
3149 else if (unformat (i, "ipv6"))
3155 if (sw_if_index_set == 0) {
3156 errmsg ("missing interface name or sw_if_index\n");
3160 /* Construct the API message */
3161 M(SW_INTERFACE_SET_TABLE, sw_interface_set_table);
3163 mp->sw_if_index = ntohl (sw_if_index);
3164 mp->is_ipv6 = is_ipv6;
3165 mp->vrf_id = ntohl (vrf_id);
3170 /* Wait for a reply... */
3174 static int api_sw_interface_set_vpath (vat_main_t * vam)
3176 unformat_input_t * i = vam->input;
3177 vl_api_sw_interface_set_vpath_t *mp;
3179 u32 sw_if_index = 0;
3180 u8 sw_if_index_set = 0;
3183 /* Parse args required to build the message */
3184 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
3185 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
3186 sw_if_index_set = 1;
3187 else if (unformat (i, "sw_if_index %d", &sw_if_index))
3188 sw_if_index_set = 1;
3189 else if (unformat (i, "enable"))
3191 else if (unformat (i, "disable"))
3197 if (sw_if_index_set == 0) {
3198 errmsg ("missing interface name or sw_if_index\n");
3202 /* Construct the API message */
3203 M(SW_INTERFACE_SET_VPATH, sw_interface_set_vpath);
3205 mp->sw_if_index = ntohl (sw_if_index);
3206 mp->enable = is_enable;
3211 /* Wait for a reply... */
3215 static int api_sw_interface_set_l2_xconnect (vat_main_t * vam)
3217 unformat_input_t * i = vam->input;
3218 vl_api_sw_interface_set_l2_xconnect_t *mp;
3221 u8 rx_sw_if_index_set = 0;
3223 u8 tx_sw_if_index_set = 0;
3226 /* Parse args required to build the message */
3227 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
3228 if (unformat (i, "rx_sw_if_index %d", &rx_sw_if_index))
3229 rx_sw_if_index_set = 1;
3230 else if (unformat (i, "tx_sw_if_index %d", &tx_sw_if_index))
3231 tx_sw_if_index_set = 1;
3232 else if (unformat (i, "rx")) {
3233 if (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
3234 if (unformat (i, "%U", unformat_sw_if_index, vam,
3236 rx_sw_if_index_set = 1;
3239 } else if (unformat (i, "tx")) {
3240 if (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
3241 if (unformat (i, "%U", unformat_sw_if_index, vam,
3243 tx_sw_if_index_set = 1;
3246 } else if (unformat (i, "enable"))
3248 else if (unformat (i, "disable"))
3254 if (rx_sw_if_index_set == 0) {
3255 errmsg ("missing rx interface name or rx_sw_if_index\n");
3259 if (enable && (tx_sw_if_index_set == 0)) {
3260 errmsg ("missing tx interface name or tx_sw_if_index\n");
3264 M(SW_INTERFACE_SET_L2_XCONNECT, sw_interface_set_l2_xconnect);
3266 mp->rx_sw_if_index = ntohl(rx_sw_if_index);
3267 mp->tx_sw_if_index = ntohl(tx_sw_if_index);
3268 mp->enable = enable;
3275 static int api_sw_interface_set_l2_bridge (vat_main_t * vam)
3277 unformat_input_t * i = vam->input;
3278 vl_api_sw_interface_set_l2_bridge_t *mp;
3281 u8 rx_sw_if_index_set = 0;
3288 /* Parse args required to build the message */
3289 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
3290 if (unformat (i, "sw_if_index %d", &rx_sw_if_index))
3291 rx_sw_if_index_set = 1;
3292 else if (unformat (i, "bd_id %d", &bd_id))
3294 else if (unformat (i, "%U", unformat_sw_if_index, vam,
3296 rx_sw_if_index_set = 1;
3297 else if (unformat (i, "shg %d", &shg))
3299 else if (unformat (i, "bvi"))
3301 else if (unformat (i, "enable"))
3303 else if (unformat (i, "disable"))
3309 if (rx_sw_if_index_set == 0) {
3310 errmsg ("missing rx interface name or sw_if_index\n");
3314 if (enable && (bd_id_set == 0)) {
3315 errmsg ("missing bridge domain\n");
3319 M(SW_INTERFACE_SET_L2_BRIDGE, sw_interface_set_l2_bridge);
3321 mp->rx_sw_if_index = ntohl(rx_sw_if_index);
3322 mp->bd_id = ntohl(bd_id);
3325 mp->enable = enable;
3332 static int api_bridge_domain_dump (vat_main_t * vam)
3334 unformat_input_t * i = vam->input;
3335 vl_api_bridge_domain_dump_t *mp;
3339 /* Parse args required to build the message */
3340 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
3341 if (unformat (i, "bd_id %d", &bd_id))
3347 M(BRIDGE_DOMAIN_DUMP, bridge_domain_dump);
3348 mp->bd_id = ntohl(bd_id);
3351 /* Use a control ping for synchronization */
3353 vl_api_control_ping_t * mp;
3354 M(CONTROL_PING, control_ping);
3363 static int api_bridge_domain_add_del (vat_main_t * vam)
3365 unformat_input_t * i = vam->input;
3366 vl_api_bridge_domain_add_del_t *mp;
3370 u32 flood = 1, forward = 1, learn = 1, uu_flood = 1, arp_term = 0;
3372 /* Parse args required to build the message */
3373 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
3374 if (unformat (i, "bd_id %d", &bd_id))
3376 else if (unformat (i, "flood %d", &flood))
3378 else if (unformat (i, "uu-flood %d", &uu_flood))
3380 else if (unformat (i, "forward %d", &forward))
3382 else if (unformat (i, "learn %d", &learn))
3384 else if (unformat (i, "arp-term %d", &arp_term))
3386 else if (unformat (i, "del")) {
3388 flood = uu_flood = forward = learn = 0;
3395 errmsg ("missing bridge domain\n");
3399 M(BRIDGE_DOMAIN_ADD_DEL, bridge_domain_add_del);
3401 mp->bd_id = ntohl(bd_id);
3403 mp->uu_flood = uu_flood;
3404 mp->forward = forward;
3406 mp->arp_term = arp_term;
3407 mp->is_add = is_add;
3414 static int api_l2fib_add_del (vat_main_t * vam)
3416 unformat_input_t * i = vam->input;
3417 vl_api_l2fib_add_del_t *mp;
3424 u8 sw_if_index_set = 0;
3429 /* Parse args required to build the message */
3430 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
3431 if (unformat (i, "mac %U", unformat_ethernet_address, &mac))
3433 else if (unformat (i, "bd_id %d", &bd_id))
3435 else if (unformat (i, "sw_if_index %d", &sw_if_index))
3436 sw_if_index_set = 1;
3437 else if (unformat (i, "sw_if")) {
3438 if (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
3439 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
3440 sw_if_index_set = 1;
3443 } else if (unformat (i, "static"))
3445 else if (unformat (i, "filter")) {
3448 } else if (unformat (i, "del"))
3455 errmsg ("missing mac address\n");
3459 if (bd_id_set == 0) {
3460 errmsg ("missing bridge domain\n");
3464 if (is_add && (sw_if_index_set == 0)) {
3465 errmsg ("missing interface name or sw_if_index\n");
3469 M(L2FIB_ADD_DEL, l2fib_add_del);
3472 mp->bd_id = ntohl(bd_id);
3473 mp->is_add = is_add;
3476 mp->sw_if_index = ntohl(sw_if_index);
3477 mp->static_mac = static_mac;
3478 mp->filter_mac = filter_mac;
3486 static int api_l2_flags (vat_main_t * vam)
3488 unformat_input_t * i = vam->input;
3489 vl_api_l2_flags_t *mp;
3492 u32 feature_bitmap = 0;
3493 u8 sw_if_index_set = 0;
3495 /* Parse args required to build the message */
3496 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
3497 if (unformat (i, "sw_if_index %d", &sw_if_index))
3498 sw_if_index_set = 1;
3499 else if (unformat (i, "sw_if")) {
3500 if (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
3501 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
3502 sw_if_index_set = 1;
3505 } else if (unformat (i, "learn"))
3506 feature_bitmap |= L2INPUT_FEAT_LEARN;
3507 else if (unformat (i, "forward"))
3508 feature_bitmap |= L2INPUT_FEAT_FWD;
3509 else if (unformat (i, "flood"))
3510 feature_bitmap |= L2INPUT_FEAT_FLOOD;
3511 else if (unformat (i, "uu-flood"))
3512 feature_bitmap |= L2INPUT_FEAT_UU_FLOOD;
3517 if (sw_if_index_set == 0) {
3518 errmsg ("missing interface name or sw_if_index\n");
3522 M(L2_FLAGS, l2_flags);
3524 mp->sw_if_index = ntohl(sw_if_index);
3525 mp->feature_bitmap = ntohl(feature_bitmap);
3532 static int api_bridge_flags (vat_main_t * vam)
3534 unformat_input_t * i = vam->input;
3535 vl_api_bridge_flags_t *mp;
3542 /* Parse args required to build the message */
3543 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
3544 if (unformat (i, "bd_id %d", &bd_id))
3546 else if (unformat (i, "learn"))
3548 else if (unformat (i, "forward"))
3550 else if (unformat (i, "flood"))
3552 else if (unformat (i, "uu-flood"))
3553 flags |= L2_UU_FLOOD;
3554 else if (unformat (i, "arp-term"))
3555 flags |= L2_ARP_TERM;
3556 else if (unformat (i, "off"))
3558 else if (unformat (i, "disable"))
3564 if (bd_id_set == 0) {
3565 errmsg ("missing bridge domain\n");
3569 M(BRIDGE_FLAGS, bridge_flags);
3571 mp->bd_id = ntohl(bd_id);
3572 mp->feature_bitmap = ntohl(flags);
3573 mp->is_set = is_set;
3580 static int api_bd_ip_mac_add_del (vat_main_t * vam)
3582 unformat_input_t * i = vam->input;
3583 vl_api_bd_ip_mac_add_del_t *mp;
3591 ip4_address_t v4addr;
3592 ip6_address_t v6addr;
3596 /* Parse args required to build the message */
3597 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
3598 if (unformat (i, "bd_id %d", &bd_id)) {
3600 } else if (unformat (i, "%U", unformat_ip4_address, &v4addr)) {
3602 } else if (unformat (i, "%U", unformat_ip6_address, &v6addr)) {
3605 } else if (unformat (i, "%U", unformat_ethernet_address, macaddr)) {
3607 } else if (unformat (i, "del"))
3613 if (bd_id_set == 0) {
3614 errmsg ("missing bridge domain\n");
3616 } else if (ip_set == 0) {
3617 errmsg ("missing IP address\n");
3619 } else if (mac_set == 0) {
3620 errmsg ("missing MAC address\n");
3624 M(BD_IP_MAC_ADD_DEL, bd_ip_mac_add_del);
3626 mp->bd_id = ntohl(bd_id);
3627 mp->is_ipv6 = is_ipv6;
3628 mp->is_add = is_add;
3630 clib_memcpy (mp->ip_address, &v6addr, sizeof (v6addr));
3631 else clib_memcpy (mp->ip_address, &v4addr, sizeof (v4addr));
3632 clib_memcpy (mp->mac_address, macaddr, 6);
3638 static int api_tap_connect (vat_main_t * vam)
3640 unformat_input_t * i = vam->input;
3641 vl_api_tap_connect_t *mp;
3648 memset (mac_address, 0, sizeof (mac_address));
3650 /* Parse args required to build the message */
3651 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
3652 if (unformat (i, "mac %U", unformat_ethernet_address, mac_address)) {
3655 else if (unformat (i, "random-mac"))
3657 else if (unformat (i, "tapname %s", &tap_name))
3663 if (name_set == 0) {
3664 errmsg ("missing tap name\n");
3667 if (vec_len (tap_name) > 63) {
3668 errmsg ("tap name too long\n");
3670 vec_add1 (tap_name, 0);
3672 /* Construct the API message */
3673 M(TAP_CONNECT, tap_connect);
3675 mp->use_random_mac = random_mac;
3676 clib_memcpy (mp->mac_address, mac_address, 6);
3677 clib_memcpy (mp->tap_name, tap_name, vec_len (tap_name));
3678 vec_free (tap_name);
3683 /* Wait for a reply... */
3687 static int api_tap_modify (vat_main_t * vam)
3689 unformat_input_t * i = vam->input;
3690 vl_api_tap_modify_t *mp;
3696 u32 sw_if_index = ~0;
3697 u8 sw_if_index_set = 0;
3699 memset (mac_address, 0, sizeof (mac_address));
3701 /* Parse args required to build the message */
3702 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
3703 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
3704 sw_if_index_set = 1;
3705 else if (unformat (i, "sw_if_index %d", &sw_if_index))
3706 sw_if_index_set = 1;
3707 else if (unformat (i, "mac %U", unformat_ethernet_address, mac_address)) {
3710 else if (unformat (i, "random-mac"))
3712 else if (unformat (i, "tapname %s", &tap_name))
3718 if (sw_if_index_set == 0) {
3719 errmsg ("missing vpp interface name");
3722 if (name_set == 0) {
3723 errmsg ("missing tap name\n");
3726 if (vec_len (tap_name) > 63) {
3727 errmsg ("tap name too long\n");
3729 vec_add1 (tap_name, 0);
3731 /* Construct the API message */
3732 M(TAP_MODIFY, tap_modify);
3734 mp->use_random_mac = random_mac;
3735 mp->sw_if_index = ntohl(sw_if_index);
3736 clib_memcpy (mp->mac_address, mac_address, 6);
3737 clib_memcpy (mp->tap_name, tap_name, vec_len (tap_name));
3738 vec_free (tap_name);
3743 /* Wait for a reply... */
3747 static int api_tap_delete (vat_main_t * vam)
3749 unformat_input_t * i = vam->input;
3750 vl_api_tap_delete_t *mp;
3752 u32 sw_if_index = ~0;
3753 u8 sw_if_index_set = 0;
3755 /* Parse args required to build the message */
3756 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
3757 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
3758 sw_if_index_set = 1;
3759 else if (unformat (i, "sw_if_index %d", &sw_if_index))
3760 sw_if_index_set = 1;
3765 if (sw_if_index_set == 0) {
3766 errmsg ("missing vpp interface name");
3770 /* Construct the API message */
3771 M(TAP_DELETE, tap_delete);
3773 mp->sw_if_index = ntohl(sw_if_index);
3778 /* Wait for a reply... */
3782 static int api_ip_add_del_route (vat_main_t * vam)
3784 unformat_input_t * i = vam->input;
3785 vl_api_ip_add_del_route_t *mp;
3787 u32 sw_if_index = 0, vrf_id = 0;
3788 u8 sw_if_index_set = 0;
3790 u8 is_local = 0, is_drop = 0;
3791 u8 create_vrf_if_needed = 0;
3793 u8 next_hop_weight = 1;
3795 u8 is_multipath = 0;
3797 u8 address_length_set = 0;
3798 u32 lookup_in_vrf = 0;
3799 u32 resolve_attempts = 0;
3800 u32 dst_address_length = 0;
3801 u8 next_hop_set = 0;
3802 ip4_address_t v4_dst_address, v4_next_hop_address;
3803 ip6_address_t v6_dst_address, v6_next_hop_address;
3807 u32 random_add_del = 0;
3808 u32 * random_vector = 0;
3809 uword * random_hash;
3810 u32 random_seed = 0xdeaddabe;
3811 u32 classify_table_index = ~0;
3814 /* Parse args required to build the message */
3815 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
3816 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
3817 sw_if_index_set = 1;
3818 else if (unformat (i, "sw_if_index %d", &sw_if_index))
3819 sw_if_index_set = 1;
3820 else if (unformat (i, "%U", unformat_ip4_address,
3825 else if (unformat (i, "%U", unformat_ip6_address, &v6_dst_address)) {
3829 else if (unformat (i, "/%d", &dst_address_length)) {
3830 address_length_set = 1;
3833 else if (is_ipv6 == 0 && unformat (i, "via %U", unformat_ip4_address,
3834 &v4_next_hop_address)) {
3837 else if (is_ipv6 == 1 && unformat (i, "via %U", unformat_ip6_address,
3838 &v6_next_hop_address)) {
3841 else if (unformat (i, "resolve-attempts %d", &resolve_attempts))
3843 else if (unformat (i, "weight %d", &next_hop_weight))
3845 else if (unformat (i, "drop")) {
3847 } else if (unformat (i, "local")) {
3849 } else if (unformat (i, "classify %d", &classify_table_index)) {
3851 } else if (unformat (i, "del"))
3853 else if (unformat (i, "add"))
3855 else if (unformat (i, "not-last"))
3857 else if (unformat (i, "multipath"))
3859 else if (unformat (i, "vrf %d", &vrf_id))
3861 else if (unformat (i, "create-vrf"))
3862 create_vrf_if_needed = 1;
3863 else if (unformat (i, "count %d", &count))
3865 else if (unformat (i, "lookup-in-vrf %d", &lookup_in_vrf))
3867 else if (unformat (i, "random"))
3869 else if (unformat (i, "seed %d", &random_seed))
3872 clib_warning ("parse error '%U'", format_unformat_error, i);
3877 if (resolve_attempts > 0 && sw_if_index_set == 0) {
3878 errmsg ("ARP resolution needs explicit interface or sw_if_index\n");
3882 if (!next_hop_set && !is_drop && !is_local && !is_classify) {
3883 errmsg ("next hop / local / drop / classify not set\n");
3887 if (address_set == 0) {
3888 errmsg ("missing addresses\n");
3892 if (address_length_set == 0) {
3893 errmsg ("missing address length\n");
3897 /* Generate a pile of unique, random routes */
3898 if (random_add_del) {
3899 u32 this_random_address;
3900 random_hash = hash_create (count, sizeof(uword));
3902 hash_set (random_hash, v4_next_hop_address.as_u32, 1);
3903 for (j = 0; j <= count; j++) {
3905 this_random_address = random_u32 (&random_seed);
3906 this_random_address =
3907 clib_host_to_net_u32 (this_random_address);
3908 } while (hash_get (random_hash, this_random_address));
3909 vec_add1 (random_vector, this_random_address);
3910 hash_set (random_hash, this_random_address, 1);
3912 hash_free (random_hash);
3913 v4_dst_address.as_u32 = random_vector[0];
3917 /* Turn on async mode */
3918 vam->async_mode = 1;
3919 vam->async_errors = 0;
3920 before = vat_time_now(vam);
3923 for (j = 0; j < count; j++) {
3924 /* Construct the API message */
3925 M(IP_ADD_DEL_ROUTE, ip_add_del_route);
3927 mp->next_hop_sw_if_index = ntohl (sw_if_index);
3928 mp->vrf_id = ntohl (vrf_id);
3929 if (resolve_attempts > 0) {
3930 mp->resolve_attempts = ntohl (resolve_attempts);
3931 mp->resolve_if_needed = 1;
3933 mp->create_vrf_if_needed = create_vrf_if_needed;
3935 mp->is_add = is_add;
3936 mp->is_drop = is_drop;
3937 mp->is_ipv6 = is_ipv6;
3938 mp->is_local = is_local;
3939 mp->is_classify = is_classify;
3940 mp->is_multipath = is_multipath;
3941 mp->not_last = not_last;
3942 mp->next_hop_weight = next_hop_weight;
3943 mp->dst_address_length = dst_address_length;
3944 mp->lookup_in_vrf = ntohl(lookup_in_vrf);
3945 mp->classify_table_index = ntohl(classify_table_index);
3948 clib_memcpy (mp->dst_address, &v6_dst_address, sizeof (v6_dst_address));
3950 clib_memcpy (mp->next_hop_address, &v6_next_hop_address,
3951 sizeof (v6_next_hop_address));
3952 increment_v6_address (&v6_dst_address);
3954 clib_memcpy (mp->dst_address, &v4_dst_address, sizeof (v4_dst_address));
3956 clib_memcpy (mp->next_hop_address, &v4_next_hop_address,
3957 sizeof (v4_next_hop_address));
3959 v4_dst_address.as_u32 = random_vector[j+1];
3961 increment_v4_address (&v4_dst_address);
3967 /* When testing multiple add/del ops, use a control-ping to sync */
3969 vl_api_control_ping_t * mp;
3972 /* Shut off async mode */
3973 vam->async_mode = 0;
3975 M(CONTROL_PING, control_ping);
3978 timeout = vat_time_now(vam) + 1.0;
3979 while (vat_time_now (vam) < timeout)
3980 if (vam->result_ready == 1)
3985 if (vam->retval == -99)
3986 errmsg ("timeout\n");
3988 if (vam->async_errors > 0) {
3989 errmsg ("%d asynchronous errors\n", vam->async_errors);
3992 vam->async_errors = 0;
3993 after = vat_time_now(vam);
3995 fformat(vam->ofp, "%d routes in %.6f secs, %.2f routes/sec\n",
3996 count, after - before, count / (after - before));
3998 /* Wait for a reply... */
4002 /* Return the good/bad news */
4003 return (vam->retval);
4006 static int api_proxy_arp_add_del (vat_main_t * vam)
4008 unformat_input_t * i = vam->input;
4009 vl_api_proxy_arp_add_del_t *mp;
4013 ip4_address_t lo, hi;
4016 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
4017 if (unformat (i, "vrf %d", &vrf_id))
4019 else if (unformat (i, "%U - %U", unformat_ip4_address, &lo,
4020 unformat_ip4_address, &hi))
4022 else if (unformat (i, "del"))
4025 clib_warning ("parse error '%U'", format_unformat_error, i);
4030 if (range_set == 0) {
4031 errmsg ("address range not set\n");
4035 M(PROXY_ARP_ADD_DEL, proxy_arp_add_del);
4037 mp->vrf_id = ntohl(vrf_id);
4038 mp->is_add = is_add;
4039 clib_memcpy(mp->low_address, &lo, sizeof (mp->low_address));
4040 clib_memcpy(mp->hi_address, &hi, sizeof (mp->hi_address));
4047 static int api_proxy_arp_intfc_enable_disable (vat_main_t * vam)
4049 unformat_input_t * i = vam->input;
4050 vl_api_proxy_arp_intfc_enable_disable_t *mp;
4054 u8 sw_if_index_set = 0;
4056 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
4057 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
4058 sw_if_index_set = 1;
4059 else if (unformat (i, "sw_if_index %d", &sw_if_index))
4060 sw_if_index_set = 1;
4061 else if (unformat (i, "enable"))
4063 else if (unformat (i, "disable"))
4066 clib_warning ("parse error '%U'", format_unformat_error, i);
4071 if (sw_if_index_set == 0) {
4072 errmsg ("missing interface name or sw_if_index\n");
4076 M(PROXY_ARP_INTFC_ENABLE_DISABLE, proxy_arp_intfc_enable_disable);
4078 mp->sw_if_index = ntohl(sw_if_index);
4079 mp->enable_disable = enable;
4086 static int api_mpls_add_del_decap (vat_main_t * vam)
4088 unformat_input_t * i = vam->input;
4089 vl_api_mpls_add_del_decap_t *mp;
4098 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
4099 if (unformat (i, "rx_vrf_id %d", &rx_vrf_id))
4101 else if (unformat (i, "tx_vrf_id %d", &tx_vrf_id))
4103 else if (unformat (i, "label %d", &label))
4105 else if (unformat (i, "next-index %d", &next_index))
4107 else if (unformat (i, "del"))
4109 else if (unformat (i, "s-bit-clear"))
4112 clib_warning ("parse error '%U'", format_unformat_error, i);
4117 M(MPLS_ADD_DEL_DECAP, mpls_add_del_decap);
4119 mp->rx_vrf_id = ntohl(rx_vrf_id);
4120 mp->tx_vrf_id = ntohl(tx_vrf_id);
4121 mp->label = ntohl(label);
4122 mp->next_index = ntohl(next_index);
4124 mp->is_add = is_add;
4131 static int api_mpls_add_del_encap (vat_main_t * vam)
4133 unformat_input_t * i = vam->input;
4134 vl_api_mpls_add_del_encap_t *mp;
4139 ip4_address_t dst_address;
4142 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
4143 if (unformat (i, "vrf %d", &vrf_id))
4145 else if (unformat (i, "label %d", &label))
4146 vec_add1 (labels, ntohl(label));
4147 else if (unformat (i, "dst %U", unformat_ip4_address, &dst_address))
4149 else if (unformat (i, "del"))
4152 clib_warning ("parse error '%U'", format_unformat_error, i);
4157 if (vec_len (labels) == 0) {
4158 errmsg ("missing encap label stack\n");
4162 M2(MPLS_ADD_DEL_ENCAP, mpls_add_del_encap,
4163 sizeof (u32) * vec_len (labels));
4165 mp->vrf_id = ntohl(vrf_id);
4166 clib_memcpy(mp->dst_address, &dst_address, sizeof (dst_address));
4167 mp->is_add = is_add;
4168 mp->nlabels = vec_len (labels);
4169 clib_memcpy(mp->labels, labels, sizeof(u32)*mp->nlabels);
4178 static int api_mpls_gre_add_del_tunnel (vat_main_t * vam)
4180 unformat_input_t * i = vam->input;
4181 vl_api_mpls_gre_add_del_tunnel_t *mp;
4183 u32 inner_vrf_id = 0;
4184 u32 outer_vrf_id = 0;
4185 ip4_address_t src_address;
4186 ip4_address_t dst_address;
4187 ip4_address_t intfc_address;
4189 u8 intfc_address_length = 0;
4193 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
4194 if (unformat (i, "inner_vrf_id %d", &inner_vrf_id))
4196 else if (unformat (i, "outer_vrf_id %d", &outer_vrf_id))
4198 else if (unformat (i, "src %U", unformat_ip4_address, &src_address))
4200 else if (unformat (i, "dst %U", unformat_ip4_address, &dst_address))
4202 else if (unformat (i, "adj %U/%d", unformat_ip4_address,
4203 &intfc_address, &tmp))
4204 intfc_address_length = tmp;
4205 else if (unformat (i, "l2-only"))
4207 else if (unformat (i, "del"))
4210 clib_warning ("parse error '%U'", format_unformat_error, i);
4215 M(MPLS_GRE_ADD_DEL_TUNNEL, mpls_gre_add_del_tunnel);
4217 mp->inner_vrf_id = ntohl(inner_vrf_id);
4218 mp->outer_vrf_id = ntohl(outer_vrf_id);
4219 clib_memcpy(mp->src_address, &src_address, sizeof (src_address));
4220 clib_memcpy(mp->dst_address, &dst_address, sizeof (dst_address));
4221 clib_memcpy(mp->intfc_address, &intfc_address, sizeof (intfc_address));
4222 mp->intfc_address_length = intfc_address_length;
4223 mp->l2_only = l2_only;
4224 mp->is_add = is_add;
4231 static int api_mpls_ethernet_add_del_tunnel (vat_main_t * vam)
4233 unformat_input_t * i = vam->input;
4234 vl_api_mpls_ethernet_add_del_tunnel_t *mp;
4236 u32 inner_vrf_id = 0;
4237 ip4_address_t intfc_address;
4238 u8 dst_mac_address[6];
4241 u8 intfc_address_length = 0;
4245 int tx_sw_if_index_set = 0;
4247 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
4248 if (unformat (i, "vrf %d", &inner_vrf_id))
4250 else if (unformat (i, "adj %U/%d", unformat_ip4_address,
4251 &intfc_address, &tmp))
4252 intfc_address_length = tmp;
4253 else if (unformat (i, "%U",
4254 unformat_sw_if_index, vam, &tx_sw_if_index))
4255 tx_sw_if_index_set = 1;
4256 else if (unformat (i, "tx_sw_if_index %d", &tx_sw_if_index))
4257 tx_sw_if_index_set = 1;
4258 else if (unformat (i, "dst %U", unformat_ethernet_address,
4261 else if (unformat (i, "l2-only"))
4263 else if (unformat (i, "del"))
4266 clib_warning ("parse error '%U'", format_unformat_error, i);
4272 errmsg ("dst (mac address) not set\n");
4275 if (!tx_sw_if_index_set) {
4276 errmsg ("tx-intfc not set\n");
4280 M(MPLS_ETHERNET_ADD_DEL_TUNNEL, mpls_ethernet_add_del_tunnel);
4282 mp->vrf_id = ntohl(inner_vrf_id);
4283 clib_memcpy (mp->adj_address, &intfc_address, sizeof (intfc_address));
4284 mp->adj_address_length = intfc_address_length;
4285 clib_memcpy (mp->dst_mac_address, dst_mac_address, sizeof (dst_mac_address));
4286 mp->tx_sw_if_index = ntohl(tx_sw_if_index);
4287 mp->l2_only = l2_only;
4288 mp->is_add = is_add;
4295 static int api_mpls_ethernet_add_del_tunnel_2 (vat_main_t * vam)
4297 unformat_input_t * i = vam->input;
4298 vl_api_mpls_ethernet_add_del_tunnel_2_t *mp;
4300 u32 inner_vrf_id = 0;
4301 u32 outer_vrf_id = 0;
4302 ip4_address_t adj_address;
4303 int adj_address_set = 0;
4304 ip4_address_t next_hop_address;
4305 int next_hop_address_set = 0;
4307 u8 adj_address_length = 0;
4310 u32 resolve_attempts = 5;
4311 u8 resolve_if_needed = 1;
4313 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
4314 if (unformat (i, "inner_vrf_id %d", &inner_vrf_id))
4316 else if (unformat (i, "outer_vrf_id %d", &outer_vrf_id))
4318 else if (unformat (i, "adj %U/%d", unformat_ip4_address,
4319 &adj_address, &tmp)) {
4320 adj_address_length = tmp;
4321 adj_address_set = 1;
4323 else if (unformat (i, "next-hop %U", unformat_ip4_address,
4325 next_hop_address_set = 1;
4326 else if (unformat (i, "resolve-attempts %d", &resolve_attempts))
4328 else if (unformat (i, "resolve-if-needed %d", &tmp))
4329 resolve_if_needed = tmp;
4330 else if (unformat (i, "l2-only"))
4332 else if (unformat (i, "del"))
4335 clib_warning ("parse error '%U'", format_unformat_error, i);
4340 if (!adj_address_set) {
4341 errmsg ("adjacency address/mask not set\n");
4344 if (!next_hop_address_set) {
4345 errmsg ("ip4 next hop address (in outer fib) not set\n");
4349 M(MPLS_ETHERNET_ADD_DEL_TUNNEL_2, mpls_ethernet_add_del_tunnel_2);
4351 mp->inner_vrf_id = ntohl(inner_vrf_id);
4352 mp->outer_vrf_id = ntohl(outer_vrf_id);
4353 mp->resolve_attempts = ntohl(resolve_attempts);
4354 mp->resolve_if_needed = resolve_if_needed;
4355 mp->is_add = is_add;
4356 mp->l2_only = l2_only;
4357 clib_memcpy (mp->adj_address, &adj_address, sizeof (adj_address));
4358 mp->adj_address_length = adj_address_length;
4359 clib_memcpy (mp->next_hop_ip4_address_in_outer_vrf, &next_hop_address,
4360 sizeof (next_hop_address));
4367 static int api_sw_interface_set_unnumbered (vat_main_t * vam)
4369 unformat_input_t * i = vam->input;
4370 vl_api_sw_interface_set_unnumbered_t *mp;
4375 u8 sw_if_index_set = 0;
4377 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
4378 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
4379 sw_if_index_set = 1;
4380 else if (unformat (i, "sw_if_index %d", &sw_if_index))
4381 sw_if_index_set = 1;
4382 else if (unformat (i, "unnum_if_index %d", &unnum_sw_index))
4384 else if (unformat (i, "del"))
4387 clib_warning ("parse error '%U'", format_unformat_error, i);
4392 if (sw_if_index_set == 0) {
4393 errmsg ("missing interface name or sw_if_index\n");
4397 M(SW_INTERFACE_SET_UNNUMBERED, sw_interface_set_unnumbered);
4399 mp->sw_if_index = ntohl(sw_if_index);
4400 mp->unnumbered_sw_if_index = ntohl(unnum_sw_index);
4401 mp->is_add = is_add;
4408 static int api_ip_neighbor_add_del (vat_main_t * vam)
4410 unformat_input_t * i = vam->input;
4411 vl_api_ip_neighbor_add_del_t *mp;
4414 u8 sw_if_index_set = 0;
4420 u8 v4_address_set = 0;
4421 u8 v6_address_set = 0;
4422 ip4_address_t v4address;
4423 ip6_address_t v6address;
4425 memset (mac_address, 0, sizeof (mac_address));
4427 /* Parse args required to build the message */
4428 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
4429 if (unformat (i, "mac %U", unformat_ethernet_address, mac_address)) {
4432 else if (unformat (i, "del"))
4434 else if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
4435 sw_if_index_set = 1;
4436 else if (unformat (i, "sw_if_index %d", &sw_if_index))
4437 sw_if_index_set = 1;
4438 else if (unformat (i, "is_static"))
4440 else if (unformat (i, "vrf %d", &vrf_id))
4442 else if (unformat (i, "dst %U",
4443 unformat_ip4_address, &v4address))
4445 else if (unformat (i, "dst %U",
4446 unformat_ip6_address, &v6address))
4449 clib_warning ("parse error '%U'", format_unformat_error, i);
4454 if (sw_if_index_set == 0) {
4455 errmsg ("missing interface name or sw_if_index\n");
4458 if (v4_address_set && v6_address_set) {
4459 errmsg ("both v4 and v6 addresses set\n");
4462 if (!v4_address_set && !v6_address_set) {
4463 errmsg ("no addresses set\n");
4467 /* Construct the API message */
4468 M(IP_NEIGHBOR_ADD_DEL, ip_neighbor_add_del);
4470 mp->sw_if_index = ntohl (sw_if_index);
4471 mp->is_add = is_add;
4472 mp->vrf_id = ntohl (vrf_id);
4473 mp->is_static = is_static;
4475 clib_memcpy (mp->mac_address, mac_address, 6);
4476 if (v6_address_set) {
4478 clib_memcpy (mp->dst_address, &v6address, sizeof (v6address));
4480 /* mp->is_ipv6 = 0; via memset in M macro above */
4481 clib_memcpy (mp->dst_address, &v4address, sizeof (v4address));
4487 /* Wait for a reply, return good/bad news */
4494 static int api_reset_vrf (vat_main_t * vam)
4496 unformat_input_t * i = vam->input;
4497 vl_api_reset_vrf_t *mp;
4503 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
4504 if (unformat (i, "vrf %d", &vrf_id))
4506 else if (unformat (i, "ipv6"))
4509 clib_warning ("parse error '%U'", format_unformat_error, i);
4514 if (vrf_id_set == 0) {
4515 errmsg ("missing vrf id\n");
4519 M(RESET_VRF, reset_vrf);
4521 mp->vrf_id = ntohl(vrf_id);
4522 mp->is_ipv6 = is_ipv6;
4529 static int api_create_vlan_subif (vat_main_t * vam)
4531 unformat_input_t * i = vam->input;
4532 vl_api_create_vlan_subif_t *mp;
4535 u8 sw_if_index_set = 0;
4539 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
4540 if (unformat (i, "sw_if_index %d", &sw_if_index))
4541 sw_if_index_set = 1;
4542 else if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
4543 sw_if_index_set = 1;
4544 else if (unformat (i, "vlan %d", &vlan_id))
4547 clib_warning ("parse error '%U'", format_unformat_error, i);
4552 if (sw_if_index_set == 0) {
4553 errmsg ("missing interface name or sw_if_index\n");
4557 if (vlan_id_set == 0) {
4558 errmsg ("missing vlan_id\n");
4561 M(CREATE_VLAN_SUBIF, create_vlan_subif);
4563 mp->sw_if_index = ntohl(sw_if_index);
4564 mp->vlan_id = ntohl(vlan_id);
4571 #define foreach_create_subif_bit \
4578 _(outer_vlan_id_any) \
4579 _(inner_vlan_id_any)
4581 static int api_create_subif (vat_main_t * vam)
4583 unformat_input_t * i = vam->input;
4584 vl_api_create_subif_t *mp;
4587 u8 sw_if_index_set = 0;
4594 u32 exact_match = 0;
4595 u32 default_sub = 0;
4596 u32 outer_vlan_id_any = 0;
4597 u32 inner_vlan_id_any = 0;
4599 u16 outer_vlan_id = 0;
4600 u16 inner_vlan_id = 0;
4602 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
4603 if (unformat (i, "sw_if_index %d", &sw_if_index))
4604 sw_if_index_set = 1;
4605 else if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
4606 sw_if_index_set = 1;
4607 else if (unformat (i, "sub_id %d", &sub_id))
4609 else if (unformat (i, "outer_vlan_id %d", &tmp))
4610 outer_vlan_id = tmp;
4611 else if (unformat (i, "inner_vlan_id %d", &tmp))
4612 inner_vlan_id = tmp;
4614 #define _(a) else if (unformat (i, #a)) a = 1 ;
4615 foreach_create_subif_bit
4619 clib_warning ("parse error '%U'", format_unformat_error, i);
4624 if (sw_if_index_set == 0) {
4625 errmsg ("missing interface name or sw_if_index\n");
4629 if (sub_id_set == 0) {
4630 errmsg ("missing sub_id\n");
4633 M(CREATE_SUBIF, create_subif);
4635 mp->sw_if_index = ntohl(sw_if_index);
4636 mp->sub_id = ntohl(sub_id);
4638 #define _(a) mp->a = a;
4639 foreach_create_subif_bit;
4642 mp->outer_vlan_id = ntohs (outer_vlan_id);
4643 mp->inner_vlan_id = ntohs (inner_vlan_id);
4650 static int api_oam_add_del (vat_main_t * vam)
4652 unformat_input_t * i = vam->input;
4653 vl_api_oam_add_del_t *mp;
4657 ip4_address_t src, dst;
4661 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
4662 if (unformat (i, "vrf %d", &vrf_id))
4664 else if (unformat (i, "src %U", unformat_ip4_address, &src))
4666 else if (unformat (i, "dst %U", unformat_ip4_address, &dst))
4668 else if (unformat (i, "del"))
4671 clib_warning ("parse error '%U'", format_unformat_error, i);
4677 errmsg ("missing src addr\n");
4682 errmsg ("missing dst addr\n");
4686 M(OAM_ADD_DEL, oam_add_del);
4688 mp->vrf_id = ntohl(vrf_id);
4689 mp->is_add = is_add;
4690 clib_memcpy(mp->src_address, &src, sizeof (mp->src_address));
4691 clib_memcpy(mp->dst_address, &dst, sizeof (mp->dst_address));
4698 static int api_reset_fib (vat_main_t * vam)
4700 unformat_input_t * i = vam->input;
4701 vl_api_reset_fib_t *mp;
4707 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
4708 if (unformat (i, "vrf %d", &vrf_id))
4710 else if (unformat (i, "ipv6"))
4713 clib_warning ("parse error '%U'", format_unformat_error, i);
4718 if (vrf_id_set == 0) {
4719 errmsg ("missing vrf id\n");
4723 M(RESET_FIB, reset_fib);
4725 mp->vrf_id = ntohl(vrf_id);
4726 mp->is_ipv6 = is_ipv6;
4733 static int api_dhcp_proxy_config (vat_main_t * vam)
4735 unformat_input_t * i = vam->input;
4736 vl_api_dhcp_proxy_config_t *mp;
4741 u8 v4_address_set = 0;
4742 u8 v6_address_set = 0;
4743 ip4_address_t v4address;
4744 ip6_address_t v6address;
4745 u8 v4_src_address_set = 0;
4746 u8 v6_src_address_set = 0;
4747 ip4_address_t v4srcaddress;
4748 ip6_address_t v6srcaddress;
4750 /* Parse args required to build the message */
4751 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
4752 if (unformat (i, "del"))
4754 else if (unformat (i, "vrf %d", &vrf_id))
4756 else if (unformat (i, "insert-cid %d", &insert_cid))
4758 else if (unformat (i, "svr %U",
4759 unformat_ip4_address, &v4address))
4761 else if (unformat (i, "svr %U",
4762 unformat_ip6_address, &v6address))
4764 else if (unformat (i, "src %U",
4765 unformat_ip4_address, &v4srcaddress))
4766 v4_src_address_set = 1;
4767 else if (unformat (i, "src %U",
4768 unformat_ip6_address, &v6srcaddress))
4769 v6_src_address_set = 1;
4774 if (v4_address_set && v6_address_set) {
4775 errmsg ("both v4 and v6 server addresses set\n");
4778 if (!v4_address_set && !v6_address_set) {
4779 errmsg ("no server addresses set\n");
4783 if (v4_src_address_set && v6_src_address_set) {
4784 errmsg ("both v4 and v6 src addresses set\n");
4787 if (!v4_src_address_set && !v6_src_address_set) {
4788 errmsg ("no src addresses set\n");
4792 if (!(v4_src_address_set && v4_address_set) &&
4793 !(v6_src_address_set && v6_address_set)) {
4794 errmsg ("no matching server and src addresses set\n");
4798 /* Construct the API message */
4799 M(DHCP_PROXY_CONFIG, dhcp_proxy_config);
4801 mp->insert_circuit_id = insert_cid;
4802 mp->is_add = is_add;
4803 mp->vrf_id = ntohl (vrf_id);
4804 if (v6_address_set) {
4806 clib_memcpy (mp->dhcp_server, &v6address, sizeof (v6address));
4807 clib_memcpy (mp->dhcp_src_address, &v6srcaddress, sizeof (v6address));
4809 clib_memcpy (mp->dhcp_server, &v4address, sizeof (v4address));
4810 clib_memcpy (mp->dhcp_src_address, &v4srcaddress, sizeof (v4address));
4816 /* Wait for a reply, return good/bad news */
4822 static int api_dhcp_proxy_config_2 (vat_main_t * vam)
4824 unformat_input_t * i = vam->input;
4825 vl_api_dhcp_proxy_config_2_t *mp;
4828 u32 server_vrf_id = 0;
4831 u8 v4_address_set = 0;
4832 u8 v6_address_set = 0;
4833 ip4_address_t v4address;
4834 ip6_address_t v6address;
4835 u8 v4_src_address_set = 0;
4836 u8 v6_src_address_set = 0;
4837 ip4_address_t v4srcaddress;
4838 ip6_address_t v6srcaddress;
4840 /* Parse args required to build the message */
4841 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
4842 if (unformat (i, "del"))
4844 else if (unformat (i, "rx_vrf_id %d", &rx_vrf_id))
4846 else if (unformat (i, "server_vrf_id %d", &server_vrf_id))
4848 else if (unformat (i, "insert-cid %d", &insert_cid))
4850 else if (unformat (i, "svr %U",
4851 unformat_ip4_address, &v4address))
4853 else if (unformat (i, "svr %U",
4854 unformat_ip6_address, &v6address))
4856 else if (unformat (i, "src %U",
4857 unformat_ip4_address, &v4srcaddress))
4858 v4_src_address_set = 1;
4859 else if (unformat (i, "src %U",
4860 unformat_ip6_address, &v6srcaddress))
4861 v6_src_address_set = 1;
4866 if (v4_address_set && v6_address_set) {
4867 errmsg ("both v4 and v6 server addresses set\n");
4870 if (!v4_address_set && !v6_address_set) {
4871 errmsg ("no server addresses set\n");
4875 if (v4_src_address_set && v6_src_address_set) {
4876 errmsg ("both v4 and v6 src addresses set\n");
4879 if (!v4_src_address_set && !v6_src_address_set) {
4880 errmsg ("no src addresses set\n");
4884 if (!(v4_src_address_set && v4_address_set) &&
4885 !(v6_src_address_set && v6_address_set)) {
4886 errmsg ("no matching server and src addresses set\n");
4890 /* Construct the API message */
4891 M(DHCP_PROXY_CONFIG_2, dhcp_proxy_config_2);
4893 mp->insert_circuit_id = insert_cid;
4894 mp->is_add = is_add;
4895 mp->rx_vrf_id = ntohl (rx_vrf_id);
4896 mp->server_vrf_id = ntohl (server_vrf_id);
4897 if (v6_address_set) {
4899 clib_memcpy (mp->dhcp_server, &v6address, sizeof (v6address));
4900 clib_memcpy (mp->dhcp_src_address, &v6srcaddress, sizeof (v6address));
4902 clib_memcpy (mp->dhcp_server, &v4address, sizeof (v4address));
4903 clib_memcpy (mp->dhcp_src_address, &v4srcaddress, sizeof (v4address));
4909 /* Wait for a reply, return good/bad news */
4915 static int api_dhcp_proxy_set_vss (vat_main_t * vam)
4917 unformat_input_t * i = vam->input;
4918 vl_api_dhcp_proxy_set_vss_t *mp;
4929 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
4930 if (unformat (i, "tbl_id %d", &tbl_id))
4932 if (unformat (i, "fib_id %d", &fib_id))
4934 if (unformat (i, "oui %d", &oui))
4936 else if (unformat (i, "ipv6"))
4938 else if (unformat (i, "del"))
4941 clib_warning ("parse error '%U'", format_unformat_error, i);
4946 if (tbl_id_set == 0) {
4947 errmsg ("missing tbl id\n");
4951 if (fib_id_set == 0) {
4952 errmsg ("missing fib id\n");
4956 errmsg ("missing oui\n");
4960 M(DHCP_PROXY_SET_VSS, dhcp_proxy_set_vss);
4961 mp->tbl_id = ntohl(tbl_id);
4962 mp->fib_id = ntohl(fib_id);
4963 mp->oui = ntohl(oui);
4964 mp->is_ipv6 = is_ipv6;
4965 mp->is_add = is_add;
4972 static int api_dhcp_client_config (vat_main_t * vam)
4974 unformat_input_t * i = vam->input;
4975 vl_api_dhcp_client_config_t *mp;
4978 u8 sw_if_index_set = 0;
4981 u8 disable_event = 0;
4983 /* Parse args required to build the message */
4984 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
4985 if (unformat (i, "del"))
4987 else if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
4988 sw_if_index_set = 1;
4989 else if (unformat (i, "sw_if_index %d", &sw_if_index))
4990 sw_if_index_set = 1;
4991 else if (unformat (i, "hostname %s", &hostname))
4993 else if (unformat (i, "disable_event"))
4999 if (sw_if_index_set == 0) {
5000 errmsg ("missing interface name or sw_if_index\n");
5004 if (vec_len (hostname) > 63) {
5005 errmsg ("hostname too long\n");
5007 vec_add1 (hostname, 0);
5009 /* Construct the API message */
5010 M(DHCP_CLIENT_CONFIG, dhcp_client_config);
5012 mp->sw_if_index = ntohl (sw_if_index);
5013 clib_memcpy (mp->hostname, hostname, vec_len (hostname));
5014 vec_free (hostname);
5015 mp->is_add = is_add;
5016 mp->want_dhcp_event = disable_event ? 0 : 1;
5022 /* Wait for a reply, return good/bad news */
5028 static int api_set_ip_flow_hash (vat_main_t * vam)
5030 unformat_input_t * i = vam->input;
5031 vl_api_set_ip_flow_hash_t *mp;
5043 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
5044 if (unformat (i, "vrf %d", &vrf_id))
5046 else if (unformat (i, "ipv6"))
5048 else if (unformat (i, "src"))
5050 else if (unformat (i, "dst"))
5052 else if (unformat (i, "sport"))
5054 else if (unformat (i, "dport"))
5056 else if (unformat (i, "proto"))
5058 else if (unformat (i, "reverse"))
5062 clib_warning ("parse error '%U'", format_unformat_error, i);
5067 if (vrf_id_set == 0) {
5068 errmsg ("missing vrf id\n");
5072 M(SET_IP_FLOW_HASH, set_ip_flow_hash);
5078 mp->reverse = reverse;
5079 mp->vrf_id = ntohl(vrf_id);
5080 mp->is_ipv6 = is_ipv6;
5087 static int api_sw_interface_ip6_enable_disable (vat_main_t * vam)
5089 unformat_input_t * i = vam->input;
5090 vl_api_sw_interface_ip6_enable_disable_t *mp;
5093 u8 sw_if_index_set = 0;
5096 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
5097 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
5098 sw_if_index_set = 1;
5099 else if (unformat (i, "sw_if_index %d", &sw_if_index))
5100 sw_if_index_set = 1;
5101 else if (unformat (i, "enable"))
5103 else if (unformat (i, "disable"))
5106 clib_warning ("parse error '%U'", format_unformat_error, i);
5111 if (sw_if_index_set == 0) {
5112 errmsg ("missing interface name or sw_if_index\n");
5116 M(SW_INTERFACE_IP6_ENABLE_DISABLE, sw_interface_ip6_enable_disable);
5118 mp->sw_if_index = ntohl(sw_if_index);
5119 mp->enable = enable;
5126 static int api_sw_interface_ip6_set_link_local_address (vat_main_t * vam)
5128 unformat_input_t * i = vam->input;
5129 vl_api_sw_interface_ip6_set_link_local_address_t *mp;
5132 u8 sw_if_index_set = 0;
5133 u32 address_length = 0;
5134 u8 v6_address_set = 0;
5135 ip6_address_t v6address;
5137 /* Parse args required to build the message */
5138 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
5139 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
5140 sw_if_index_set = 1;
5141 else if (unformat (i, "sw_if_index %d", &sw_if_index))
5142 sw_if_index_set = 1;
5143 else if (unformat (i, "%U/%d",
5144 unformat_ip6_address, &v6address,
5151 if (sw_if_index_set == 0) {
5152 errmsg ("missing interface name or sw_if_index\n");
5155 if (!v6_address_set) {
5156 errmsg ("no address set\n");
5160 /* Construct the API message */
5161 M(SW_INTERFACE_IP6_SET_LINK_LOCAL_ADDRESS, \
5162 sw_interface_ip6_set_link_local_address);
5164 mp->sw_if_index = ntohl (sw_if_index);
5165 clib_memcpy (mp->address, &v6address, sizeof (v6address));
5166 mp->address_length = address_length;
5171 /* Wait for a reply, return good/bad news */
5179 static int api_sw_interface_ip6nd_ra_prefix (vat_main_t * vam)
5181 unformat_input_t * i = vam->input;
5182 vl_api_sw_interface_ip6nd_ra_prefix_t *mp;
5185 u8 sw_if_index_set = 0;
5186 u32 address_length = 0;
5187 u8 v6_address_set = 0;
5188 ip6_address_t v6address;
5190 u8 no_advertise = 0;
5192 u8 no_autoconfig = 0;
5195 u32 val_lifetime = 0;
5196 u32 pref_lifetime = 0;
5198 /* Parse args required to build the message */
5199 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
5200 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
5201 sw_if_index_set = 1;
5202 else if (unformat (i, "sw_if_index %d", &sw_if_index))
5203 sw_if_index_set = 1;
5204 else if (unformat (i, "%U/%d",
5205 unformat_ip6_address, &v6address,
5208 else if (unformat (i, "val_life %d", &val_lifetime))
5210 else if (unformat (i, "pref_life %d", &pref_lifetime))
5212 else if (unformat (i, "def"))
5214 else if (unformat (i, "noadv"))
5216 else if (unformat (i, "offl"))
5218 else if (unformat (i, "noauto"))
5220 else if (unformat (i, "nolink"))
5222 else if (unformat (i, "isno"))
5225 clib_warning ("parse error '%U'", format_unformat_error, i);
5230 if (sw_if_index_set == 0) {
5231 errmsg ("missing interface name or sw_if_index\n");
5234 if (!v6_address_set) {
5235 errmsg ("no address set\n");
5239 /* Construct the API message */
5240 M(SW_INTERFACE_IP6ND_RA_PREFIX, sw_interface_ip6nd_ra_prefix);
5242 mp->sw_if_index = ntohl (sw_if_index);
5243 clib_memcpy (mp->address, &v6address, sizeof (v6address));
5244 mp->address_length = address_length;
5245 mp->use_default = use_default;
5246 mp->no_advertise = no_advertise;
5247 mp->off_link = off_link;
5248 mp->no_autoconfig = no_autoconfig;
5249 mp->no_onlink = no_onlink;
5251 mp->val_lifetime = ntohl(val_lifetime);
5252 mp->pref_lifetime = ntohl(pref_lifetime);
5257 /* Wait for a reply, return good/bad news */
5264 static int api_sw_interface_ip6nd_ra_config (vat_main_t * vam)
5266 unformat_input_t * i = vam->input;
5267 vl_api_sw_interface_ip6nd_ra_config_t *mp;
5270 u8 sw_if_index_set = 0;
5275 u8 send_unicast = 0;
5278 u8 default_router = 0;
5279 u32 max_interval = 0;
5280 u32 min_interval = 0;
5282 u32 initial_count = 0;
5283 u32 initial_interval = 0;
5286 /* Parse args required to build the message */
5287 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
5288 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
5289 sw_if_index_set = 1;
5290 else if (unformat (i, "sw_if_index %d", &sw_if_index))
5291 sw_if_index_set = 1;
5292 else if (unformat (i, "maxint %d", &max_interval))
5294 else if (unformat (i, "minint %d", &min_interval))
5296 else if (unformat (i, "life %d", &lifetime))
5298 else if (unformat (i, "count %d", &initial_count))
5300 else if (unformat (i, "interval %d", &initial_interval))
5302 else if (unformat (i, "surpress"))
5304 else if (unformat (i, "managed"))
5306 else if (unformat (i, "other"))
5308 else if (unformat (i, "ll"))
5310 else if (unformat (i, "send"))
5312 else if (unformat (i, "cease"))
5314 else if (unformat (i, "isno"))
5316 else if (unformat (i, "def"))
5319 clib_warning ("parse error '%U'", format_unformat_error, i);
5324 if (sw_if_index_set == 0) {
5325 errmsg ("missing interface name or sw_if_index\n");
5329 /* Construct the API message */
5330 M(SW_INTERFACE_IP6ND_RA_CONFIG, sw_interface_ip6nd_ra_config);
5332 mp->sw_if_index = ntohl (sw_if_index);
5333 mp->max_interval = ntohl(max_interval);
5334 mp->min_interval = ntohl(min_interval);
5335 mp->lifetime = ntohl(lifetime);
5336 mp->initial_count = ntohl(initial_count);
5337 mp->initial_interval = ntohl(initial_interval);
5338 mp->surpress = surpress;
5339 mp->managed = managed;
5341 mp->ll_option = ll_option;
5342 mp->send_unicast = send_unicast;
5345 mp->default_router = default_router;
5350 /* Wait for a reply, return good/bad news */
5357 static int api_set_arp_neighbor_limit (vat_main_t * vam)
5359 unformat_input_t * i = vam->input;
5360 vl_api_set_arp_neighbor_limit_t *mp;
5366 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
5367 if (unformat (i, "arp_nbr_limit %d", &arp_nbr_limit))
5369 else if (unformat (i, "ipv6"))
5372 clib_warning ("parse error '%U'", format_unformat_error, i);
5377 if (limit_set == 0) {
5378 errmsg ("missing limit value\n");
5382 M(SET_ARP_NEIGHBOR_LIMIT, set_arp_neighbor_limit);
5384 mp->arp_neighbor_limit = ntohl(arp_nbr_limit);
5385 mp->is_ipv6 = is_ipv6;
5392 static int api_l2_patch_add_del (vat_main_t * vam)
5394 unformat_input_t * i = vam->input;
5395 vl_api_l2_patch_add_del_t *mp;
5398 u8 rx_sw_if_index_set = 0;
5400 u8 tx_sw_if_index_set = 0;
5403 /* Parse args required to build the message */
5404 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
5405 if (unformat (i, "rx_sw_if_index %d", &rx_sw_if_index))
5406 rx_sw_if_index_set = 1;
5407 else if (unformat (i, "tx_sw_if_index %d", &tx_sw_if_index))
5408 tx_sw_if_index_set = 1;
5409 else if (unformat (i, "rx")) {
5410 if (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
5411 if (unformat (i, "%U", unformat_sw_if_index, vam,
5413 rx_sw_if_index_set = 1;
5416 } else if (unformat (i, "tx")) {
5417 if (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
5418 if (unformat (i, "%U", unformat_sw_if_index, vam,
5420 tx_sw_if_index_set = 1;
5423 } else if (unformat (i, "del"))
5429 if (rx_sw_if_index_set == 0) {
5430 errmsg ("missing rx interface name or rx_sw_if_index\n");
5434 if (tx_sw_if_index_set == 0) {
5435 errmsg ("missing tx interface name or tx_sw_if_index\n");
5439 M(L2_PATCH_ADD_DEL, l2_patch_add_del);
5441 mp->rx_sw_if_index = ntohl(rx_sw_if_index);
5442 mp->tx_sw_if_index = ntohl(tx_sw_if_index);
5443 mp->is_add = is_add;
5449 static int api_trace_profile_add (vat_main_t *vam)
5451 unformat_input_t * input = vam->input;
5452 vl_api_trace_profile_add_t *mp;
5455 u32 trace_option_elts = 0;
5456 u32 trace_type = 0, node_id = 0, app_data = 0, trace_tsp = 2;
5457 int has_pow_option = 0;
5458 int has_ppc_option = 0;
5460 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
5462 if (unformat (input, "id %d trace-type 0x%x trace-elts %d "
5463 "trace-tsp %d node-id 0x%x app-data 0x%x",
5464 &id, &trace_type, &trace_option_elts, &trace_tsp,
5465 &node_id, &app_data))
5467 else if (unformat (input, "pow"))
5469 else if (unformat (input, "ppc encap"))
5470 has_ppc_option = PPC_ENCAP;
5471 else if (unformat (input, "ppc decap"))
5472 has_ppc_option = PPC_DECAP;
5473 else if (unformat (input, "ppc none"))
5474 has_ppc_option = PPC_NONE;
5478 M(TRACE_PROFILE_ADD, trace_profile_add);
5480 mp->trace_type = trace_type;
5481 mp->trace_num_elt = trace_option_elts;
5482 mp->trace_ppc = has_ppc_option;
5483 mp->trace_app_data = htonl(app_data);
5484 mp->pow_enable = has_pow_option;
5485 mp->trace_tsp = trace_tsp;
5486 mp->node_id = htonl(node_id);
5493 static int api_trace_profile_apply (vat_main_t *vam)
5495 unformat_input_t * input = vam->input;
5496 vl_api_trace_profile_apply_t *mp;
5499 u32 mask_width = ~0;
5506 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
5508 if (unformat (input, "%U/%d",
5509 unformat_ip6_address, &addr, &mask_width))
5511 else if (unformat (input, "id %d", &id))
5513 else if (unformat (input, "vrf-id %d", &vrf_id))
5515 else if (unformat (input, "add"))
5517 else if (unformat (input, "pop"))
5519 else if (unformat (input, "none"))
5525 if ((is_add + is_pop + is_none) != 1) {
5526 errmsg("One of (add, pop, none) required");
5529 if (mask_width == ~0) {
5530 errmsg("<address>/<mask-width> required");
5533 M(TRACE_PROFILE_APPLY, trace_profile_apply);
5534 clib_memcpy(mp->dest_ipv6, &addr, sizeof(mp->dest_ipv6));
5536 mp->prefix_length = htonl(mask_width);
5537 mp->vrf_id = htonl(vrf_id);
5539 mp->trace_op = IOAM_HBYH_ADD;
5541 mp->trace_op = IOAM_HBYH_POP;
5543 mp->trace_op = IOAM_HBYH_MOD;
5555 static int api_trace_profile_del (vat_main_t *vam)
5557 vl_api_trace_profile_del_t *mp;
5560 M(TRACE_PROFILE_DEL, trace_profile_del);
5565 static int api_sr_tunnel_add_del (vat_main_t * vam)
5567 unformat_input_t * i = vam->input;
5568 vl_api_sr_tunnel_add_del_t *mp;
5572 ip6_address_t src_address;
5573 int src_address_set = 0;
5574 ip6_address_t dst_address;
5576 int dst_address_set = 0;
5578 u32 rx_table_id = 0;
5579 u32 tx_table_id = 0;
5580 ip6_address_t * segments = 0;
5581 ip6_address_t * this_seg;
5582 ip6_address_t * tags = 0;
5583 ip6_address_t * this_tag;
5584 ip6_address_t next_address, tag;
5586 u8 * policy_name = 0;
5588 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
5590 if (unformat (i, "del"))
5592 else if (unformat (i, "name %s", &name))
5594 else if (unformat (i, "policy %s", &policy_name))
5596 else if (unformat (i, "rx_fib_id %d", &rx_table_id))
5598 else if (unformat (i, "tx_fib_id %d", &tx_table_id))
5600 else if (unformat (i, "src %U", unformat_ip6_address, &src_address))
5601 src_address_set = 1;
5602 else if (unformat (i, "dst %U/%d",
5603 unformat_ip6_address, &dst_address,
5605 dst_address_set = 1;
5606 else if (unformat (i, "next %U", unformat_ip6_address,
5609 vec_add2 (segments, this_seg, 1);
5610 clib_memcpy (this_seg->as_u8, next_address.as_u8, sizeof (*this_seg));
5612 else if (unformat (i, "tag %U", unformat_ip6_address,
5615 vec_add2 (tags, this_tag, 1);
5616 clib_memcpy (this_tag->as_u8, tag.as_u8, sizeof (*this_tag));
5618 else if (unformat (i, "clean"))
5619 flags |= IP6_SR_HEADER_FLAG_CLEANUP;
5620 else if (unformat (i, "protected"))
5621 flags |= IP6_SR_HEADER_FLAG_PROTECTED;
5622 else if (unformat (i, "InPE %d", &pl_index))
5624 if (pl_index <= 0 || pl_index > 4)
5626 pl_index_range_error:
5627 errmsg ("pl index %d out of range\n", pl_index);
5630 flags |= IP6_SR_HEADER_FLAG_PL_ELT_INGRESS_PE << (3*(pl_index - 1));
5632 else if (unformat (i, "EgPE %d", &pl_index))
5634 if (pl_index <= 0 || pl_index > 4)
5635 goto pl_index_range_error;
5636 flags |= IP6_SR_HEADER_FLAG_PL_ELT_EGRESS_PE << (3*(pl_index - 1));
5638 else if (unformat (i, "OrgSrc %d", &pl_index))
5640 if (pl_index <= 0 || pl_index > 4)
5641 goto pl_index_range_error;
5642 flags |= IP6_SR_HEADER_FLAG_PL_ELT_ORIG_SRC_ADDR << (3*(pl_index - 1));
5648 if (!src_address_set)
5650 errmsg ("src address required\n");
5654 if (!dst_address_set)
5656 errmsg ("dst address required\n");
5662 errmsg ("at least one sr segment required\n");
5666 M2(SR_TUNNEL_ADD_DEL, sr_tunnel_add_del,
5667 vec_len(segments) * sizeof (ip6_address_t)
5668 + vec_len(tags) * sizeof (ip6_address_t));
5670 clib_memcpy (mp->src_address, &src_address, sizeof (mp->src_address));
5671 clib_memcpy (mp->dst_address, &dst_address, sizeof (mp->dst_address));
5672 mp->dst_mask_width = dst_mask_width;
5673 mp->flags_net_byte_order = clib_host_to_net_u16 (flags);
5674 mp->n_segments = vec_len (segments);
5675 mp->n_tags = vec_len (tags);
5676 mp->is_add = is_del == 0;
5677 clib_memcpy (mp->segs_and_tags, segments,
5678 vec_len(segments)* sizeof (ip6_address_t));
5679 clib_memcpy (mp->segs_and_tags + vec_len(segments)*sizeof (ip6_address_t),
5680 tags, vec_len(tags)* sizeof (ip6_address_t));
5682 mp->outer_vrf_id = ntohl (rx_table_id);
5683 mp->inner_vrf_id = ntohl (tx_table_id);
5684 memcpy (mp->name, name, vec_len(name));
5685 memcpy (mp->policy_name, policy_name, vec_len(policy_name));
5687 vec_free (segments);
5694 static int api_sr_policy_add_del (vat_main_t * vam)
5696 unformat_input_t * input = vam->input;
5697 vl_api_sr_policy_add_del_t *mp;
5701 u8 * tunnel_name = 0;
5702 u8 ** tunnel_names = 0;
5707 int tunnel_names_length = 1; // Init to 1 to offset the #tunnel_names counter byte
5708 int tun_name_len = 0; // Different naming convention used as confusing these would be "bad" (TM)
5710 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
5712 if (unformat (input, "del"))
5714 else if (unformat (input, "name %s", &name))
5716 else if (unformat (input, "tunnel %s", &tunnel_name))
5720 vec_add1 (tunnel_names, tunnel_name);
5722 - length = #bytes to store in serial vector
5723 - +1 = byte to store that length
5725 tunnel_names_length += (vec_len (tunnel_name) + 1);
5736 errmsg ("policy name required\n");
5740 if ((!tunnel_set) && (!is_del))
5742 errmsg ("tunnel name required\n");
5746 M2(SR_POLICY_ADD_DEL, sr_policy_add_del, tunnel_names_length);
5750 mp->is_add = !is_del;
5752 memcpy (mp->name, name, vec_len(name));
5753 // Since mp->tunnel_names is of type u8[0] and not a u8 *, u8 ** needs to be serialized
5754 u8 * serial_orig = 0;
5755 vec_validate (serial_orig, tunnel_names_length);
5756 *serial_orig = vec_len(tunnel_names); // Store the number of tunnels as length in first byte of serialized vector
5757 serial_orig += 1; // Move along one byte to store the length of first tunnel_name
5759 for (j=0; j < vec_len(tunnel_names); j++)
5761 tun_name_len = vec_len (tunnel_names[j]);
5762 *serial_orig = tun_name_len; // Store length of tunnel name in first byte of Length/Value pair
5763 serial_orig += 1; // Move along one byte to store the actual tunnel name
5764 memcpy (serial_orig, tunnel_names[j], tun_name_len);
5765 serial_orig += tun_name_len; // Advance past the copy
5767 memcpy (mp->tunnel_names, serial_orig - tunnel_names_length, tunnel_names_length); // Regress serial_orig to head then copy fwd
5769 vec_free (tunnel_names);
5770 vec_free (tunnel_name);
5776 static int api_sr_multicast_map_add_del (vat_main_t * vam)
5778 unformat_input_t * input = vam->input;
5779 vl_api_sr_multicast_map_add_del_t *mp;
5782 ip6_address_t multicast_address;
5783 u8 * policy_name = 0;
5784 int multicast_address_set = 0;
5786 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
5788 if (unformat (input, "del"))
5790 else if (unformat (input, "address %U", unformat_ip6_address, &multicast_address))
5791 multicast_address_set = 1;
5792 else if (unformat (input, "sr-policy %s", &policy_name))
5798 if (!is_del && !policy_name)
5800 errmsg ("sr-policy name required\n");
5805 if (!multicast_address_set)
5807 errmsg ("address required\n");
5811 M(SR_MULTICAST_MAP_ADD_DEL, sr_multicast_map_add_del);
5813 mp->is_add = !is_del;
5814 memcpy (mp->policy_name, policy_name, vec_len(policy_name));
5815 clib_memcpy (mp->multicast_address, &multicast_address, sizeof (mp->multicast_address));
5818 vec_free (policy_name);
5825 #define foreach_ip4_proto_field \
5835 uword unformat_ip4_mask (unformat_input_t * input, va_list * args)
5837 u8 ** maskp = va_arg (*args, u8 **);
5839 u8 found_something = 0;
5842 #define _(a) u8 a=0;
5843 foreach_ip4_proto_field;
5849 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
5851 if (unformat (input, "version"))
5853 else if (unformat (input, "hdr_length"))
5855 else if (unformat (input, "src"))
5857 else if (unformat (input, "dst"))
5859 else if (unformat (input, "proto"))
5862 #define _(a) else if (unformat (input, #a)) a=1;
5863 foreach_ip4_proto_field
5869 #define _(a) found_something += a;
5870 foreach_ip4_proto_field;
5873 if (found_something == 0)
5876 vec_validate (mask, sizeof (*ip) - 1);
5878 ip = (ip4_header_t *) mask;
5880 #define _(a) if (a) memset (&ip->a, 0xff, sizeof (ip->a));
5881 foreach_ip4_proto_field;
5884 ip->ip_version_and_header_length = 0;
5887 ip->ip_version_and_header_length |= 0xF0;
5890 ip->ip_version_and_header_length |= 0x0F;
5896 #define foreach_ip6_proto_field \
5903 uword unformat_ip6_mask (unformat_input_t * input, va_list * args)
5905 u8 ** maskp = va_arg (*args, u8 **);
5907 u8 found_something = 0;
5909 u32 ip_version_traffic_class_and_flow_label;
5911 #define _(a) u8 a=0;
5912 foreach_ip6_proto_field;
5915 u8 traffic_class = 0;
5918 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
5920 if (unformat (input, "version"))
5922 else if (unformat (input, "traffic-class"))
5924 else if (unformat (input, "flow-label"))
5926 else if (unformat (input, "src"))
5928 else if (unformat (input, "dst"))
5930 else if (unformat (input, "proto"))
5933 #define _(a) else if (unformat (input, #a)) a=1;
5934 foreach_ip6_proto_field
5940 #define _(a) found_something += a;
5941 foreach_ip6_proto_field;
5944 if (found_something == 0)
5947 vec_validate (mask, sizeof (*ip) - 1);
5949 ip = (ip6_header_t *) mask;
5951 #define _(a) if (a) memset (&ip->a, 0xff, sizeof (ip->a));
5952 foreach_ip6_proto_field;
5955 ip_version_traffic_class_and_flow_label = 0;
5958 ip_version_traffic_class_and_flow_label |= 0xF0000000;
5961 ip_version_traffic_class_and_flow_label |= 0x0FF00000;
5964 ip_version_traffic_class_and_flow_label |= 0x000FFFFF;
5966 ip->ip_version_traffic_class_and_flow_label =
5967 clib_host_to_net_u32 (ip_version_traffic_class_and_flow_label);
5973 uword unformat_l3_mask (unformat_input_t * input, va_list * args)
5975 u8 ** maskp = va_arg (*args, u8 **);
5977 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) {
5978 if (unformat (input, "ip4 %U", unformat_ip4_mask, maskp))
5980 else if (unformat (input, "ip6 %U", unformat_ip6_mask, maskp))
5988 uword unformat_l2_mask (unformat_input_t * input, va_list * args)
5990 u8 ** maskp = va_arg (*args, u8 **);
6005 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) {
6006 if (unformat (input, "src"))
6008 else if (unformat (input, "dst"))
6010 else if (unformat (input, "proto"))
6012 else if (unformat (input, "tag1"))
6014 else if (unformat (input, "tag2"))
6016 else if (unformat (input, "ignore-tag1"))
6018 else if (unformat (input, "ignore-tag2"))
6020 else if (unformat (input, "cos1"))
6022 else if (unformat (input, "cos2"))
6024 else if (unformat (input, "dot1q"))
6026 else if (unformat (input, "dot1ad"))
6031 if ((src + dst + proto + tag1 + tag2 + dot1q + dot1ad +
6032 ignore_tag1 + ignore_tag2 + cos1 + cos2) == 0)
6035 if (tag1 || ignore_tag1 || cos1 || dot1q)
6037 if (tag2 || ignore_tag2 || cos2 || dot1ad)
6040 vec_validate (mask, len-1);
6043 memset (mask, 0xff, 6);
6046 memset (mask + 6, 0xff, 6);
6050 /* inner vlan tag */
6059 mask[21] = mask [20] = 0xff;
6080 mask[16] = mask [17] = 0xff;
6090 mask[12] = mask [13] = 0xff;
6096 uword unformat_classify_mask (unformat_input_t * input, va_list * args)
6098 u8 ** maskp = va_arg (*args, u8 **);
6099 u32 * skipp = va_arg (*args, u32 *);
6100 u32 * matchp = va_arg (*args, u32 *);
6107 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) {
6108 if (unformat (input, "hex %U", unformat_hex_string, &mask))
6110 else if (unformat (input, "l2 %U", unformat_l2_mask, &l2))
6112 else if (unformat (input, "l3 %U", unformat_l3_mask, &l3))
6118 if (mask || l2 || l3)
6122 /* "With a free Ethernet header in every package" */
6124 vec_validate (l2, 13);
6126 vec_append (mask, l3);
6130 /* Scan forward looking for the first significant mask octet */
6131 for (i = 0; i < vec_len (mask); i++)
6135 /* compute (skip, match) params */
6136 *skipp = i / sizeof(u32x4);
6137 vec_delete (mask, *skipp * sizeof(u32x4), 0);
6139 /* Pad mask to an even multiple of the vector size */
6140 while (vec_len (mask) % sizeof (u32x4))
6143 match = vec_len (mask) / sizeof (u32x4);
6145 for (i = match*sizeof(u32x4); i > 0; i-= sizeof(u32x4))
6147 u64 *tmp = (u64 *)(mask + (i-sizeof(u32x4)));
6148 if (*tmp || *(tmp+1))
6153 clib_warning ("BUG: match 0");
6155 _vec_len (mask) = match * sizeof(u32x4);
6166 #define foreach_l2_next \
6168 _(ethernet, ETHERNET_INPUT) \
6172 uword unformat_l2_next_index (unformat_input_t * input, va_list * args)
6174 u32 * miss_next_indexp = va_arg (*args, u32 *);
6179 if (unformat (input, #n)) { next_index = L2_CLASSIFY_NEXT_##N; goto out;}
6183 if (unformat (input, "%d", &tmp))
6192 *miss_next_indexp = next_index;
6196 #define foreach_ip_next \
6202 uword unformat_ip_next_index (unformat_input_t * input, va_list * args)
6204 u32 * miss_next_indexp = va_arg (*args, u32 *);
6209 if (unformat (input, #n)) { next_index = IP_LOOKUP_NEXT_##N; goto out;}
6213 if (unformat (input, "%d", &tmp))
6222 *miss_next_indexp = next_index;
6226 #define foreach_acl_next \
6229 uword unformat_acl_next_index (unformat_input_t * input, va_list * args)
6231 u32 * miss_next_indexp = va_arg (*args, u32 *);
6236 if (unformat (input, #n)) { next_index = ACL_NEXT_INDEX_##N; goto out;}
6240 if (unformat (input, "permit"))
6245 else if (unformat (input, "%d", &tmp))
6254 *miss_next_indexp = next_index;
6258 static int api_classify_add_del_table (vat_main_t * vam)
6260 unformat_input_t * i = vam->input;
6261 vl_api_classify_add_del_table_t *mp;
6267 u32 table_index = ~0;
6268 u32 next_table_index = ~0;
6269 u32 miss_next_index = ~0;
6270 u32 memory_size = 32<<20;
6274 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
6275 if (unformat (i, "del"))
6277 else if (unformat (i, "buckets %d", &nbuckets))
6279 else if (unformat (i, "memory_size %d", &memory_size))
6281 else if (unformat (i, "skip %d", &skip))
6283 else if (unformat (i, "match %d", &match))
6285 else if (unformat (i, "table %d", &table_index))
6287 else if (unformat (i, "mask %U", unformat_classify_mask,
6288 &mask, &skip, &match))
6290 else if (unformat (i, "next-table %d", &next_table_index))
6292 else if (unformat (i, "miss-next %U", unformat_ip_next_index,
6295 else if (unformat (i, "l2-miss-next %U", unformat_l2_next_index,
6298 else if (unformat (i, "acl-miss-next %U", unformat_acl_next_index,
6305 if (is_add && mask == 0) {
6306 errmsg ("Mask required\n");
6310 if (is_add && skip == ~0) {
6311 errmsg ("skip count required\n");
6315 if (is_add && match == ~0) {
6316 errmsg ("match count required\n");
6320 if (!is_add && table_index == ~0) {
6321 errmsg ("table index required for delete\n");
6325 M2 (CLASSIFY_ADD_DEL_TABLE, classify_add_del_table,
6328 mp->is_add = is_add;
6329 mp->table_index = ntohl(table_index);
6330 mp->nbuckets = ntohl(nbuckets);
6331 mp->memory_size = ntohl(memory_size);
6332 mp->skip_n_vectors = ntohl(skip);
6333 mp->match_n_vectors = ntohl(match);
6334 mp->next_table_index = ntohl(next_table_index);
6335 mp->miss_next_index = ntohl(miss_next_index);
6336 clib_memcpy (mp->mask, mask, vec_len(mask));
6344 uword unformat_ip4_match (unformat_input_t * input, va_list * args)
6346 u8 ** matchp = va_arg (*args, u8 **);
6353 int src = 0, dst = 0;
6354 ip4_address_t src_val, dst_val;
6361 int fragment_id = 0;
6362 u32 fragment_id_val;
6368 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
6370 if (unformat (input, "version %d", &version_val))
6372 else if (unformat (input, "hdr_length %d", &hdr_length_val))
6374 else if (unformat (input, "src %U", unformat_ip4_address, &src_val))
6376 else if (unformat (input, "dst %U", unformat_ip4_address, &dst_val))
6378 else if (unformat (input, "proto %d", &proto_val))
6380 else if (unformat (input, "tos %d", &tos_val))
6382 else if (unformat (input, "length %d", &length_val))
6384 else if (unformat (input, "fragment_id %d", &fragment_id_val))
6386 else if (unformat (input, "ttl %d", &ttl_val))
6388 else if (unformat (input, "checksum %d", &checksum_val))
6394 if (version + hdr_length + src + dst + proto + tos + length + fragment_id
6395 + ttl + checksum == 0)
6399 * Aligned because we use the real comparison functions
6401 vec_validate_aligned (match, sizeof (*ip) - 1, sizeof(u32x4));
6403 ip = (ip4_header_t *) match;
6405 /* These are realistically matched in practice */
6407 ip->src_address.as_u32 = src_val.as_u32;
6410 ip->dst_address.as_u32 = dst_val.as_u32;
6413 ip->protocol = proto_val;
6416 /* These are not, but they're included for completeness */
6418 ip->ip_version_and_header_length |= (version_val & 0xF)<<4;
6421 ip->ip_version_and_header_length |= (hdr_length_val & 0xF);
6427 ip->length = length_val;
6433 ip->checksum = checksum_val;
6439 uword unformat_ip6_match (unformat_input_t * input, va_list * args)
6441 u8 ** matchp = va_arg (*args, u8 **);
6447 u32 traffic_class_val;
6450 int src = 0, dst = 0;
6451 ip6_address_t src_val, dst_val;
6454 int payload_length = 0;
6455 u32 payload_length_val;
6458 u32 ip_version_traffic_class_and_flow_label;
6460 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
6462 if (unformat (input, "version %d", &version_val))
6464 else if (unformat (input, "traffic_class %d", &traffic_class_val))
6466 else if (unformat (input, "flow_label %d", &flow_label_val))
6468 else if (unformat (input, "src %U", unformat_ip6_address, &src_val))
6470 else if (unformat (input, "dst %U", unformat_ip6_address, &dst_val))
6472 else if (unformat (input, "proto %d", &proto_val))
6474 else if (unformat (input, "payload_length %d", &payload_length_val))
6476 else if (unformat (input, "hop_limit %d", &hop_limit_val))
6482 if (version + traffic_class + flow_label + src + dst + proto +
6483 payload_length + hop_limit == 0)
6487 * Aligned because we use the real comparison functions
6489 vec_validate_aligned (match, sizeof (*ip) - 1, sizeof(u32x4));
6491 ip = (ip6_header_t *) match;
6494 clib_memcpy (&ip->src_address, &src_val, sizeof (ip->src_address));
6497 clib_memcpy (&ip->dst_address, &dst_val, sizeof (ip->dst_address));
6500 ip->protocol = proto_val;
6502 ip_version_traffic_class_and_flow_label = 0;
6505 ip_version_traffic_class_and_flow_label |= (version_val & 0xF) << 28;
6508 ip_version_traffic_class_and_flow_label |= (traffic_class_val & 0xFF) << 20;
6511 ip_version_traffic_class_and_flow_label |= (flow_label_val & 0xFFFFF);
6513 ip->ip_version_traffic_class_and_flow_label =
6514 clib_host_to_net_u32 (ip_version_traffic_class_and_flow_label);
6517 ip->payload_length = clib_host_to_net_u16 (payload_length_val);
6520 ip->hop_limit = hop_limit_val;
6526 uword unformat_l3_match (unformat_input_t * input, va_list * args)
6528 u8 ** matchp = va_arg (*args, u8 **);
6530 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) {
6531 if (unformat (input, "ip4 %U", unformat_ip4_match, matchp))
6533 else if (unformat (input, "ip6 %U", unformat_ip6_match, matchp))
6541 uword unformat_vlan_tag (unformat_input_t * input, va_list * args)
6543 u8 * tagp = va_arg (*args, u8 *);
6546 if (unformat(input, "%d", &tag))
6548 tagp[0] = (tag>>8) & 0x0F;
6549 tagp[1] = tag & 0xFF;
6556 uword unformat_l2_match (unformat_input_t * input, va_list * args)
6558 u8 ** matchp = va_arg (*args, u8 **);
6578 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) {
6579 if (unformat (input, "src %U", unformat_ethernet_address, &src_val))
6581 else if (unformat (input, "dst %U", unformat_ethernet_address, &dst_val))
6583 else if (unformat (input, "proto %U",
6584 unformat_ethernet_type_host_byte_order, &proto_val))
6586 else if (unformat (input, "tag1 %U", unformat_vlan_tag, tag1_val))
6588 else if (unformat (input, "tag2 %U", unformat_vlan_tag, tag2_val))
6590 else if (unformat (input, "ignore-tag1"))
6592 else if (unformat (input, "ignore-tag2"))
6594 else if (unformat (input, "cos1 %d", &cos1_val))
6596 else if (unformat (input, "cos2 %d", &cos2_val))
6601 if ((src + dst + proto + tag1 + tag2 +
6602 ignore_tag1 + ignore_tag2 + cos1 + cos2) == 0)
6605 if (tag1 || ignore_tag1 || cos1)
6607 if (tag2 || ignore_tag2 || cos2)
6610 vec_validate_aligned (match, len-1, sizeof(u32x4));
6613 clib_memcpy (match, dst_val, 6);
6616 clib_memcpy (match + 6, src_val, 6);
6620 /* inner vlan tag */
6621 match[19] = tag2_val[1];
6622 match[18] = tag2_val[0];
6624 match [18] |= (cos2_val & 0x7) << 5;
6627 match[21] = proto_val & 0xff;
6628 match[20] = proto_val >> 8;
6632 match [15] = tag1_val[1];
6633 match [14] = tag1_val[0];
6636 match [14] |= (cos1_val & 0x7) << 5;
6642 match [15] = tag1_val[1];
6643 match [14] = tag1_val[0];
6646 match[17] = proto_val & 0xff;
6647 match[16] = proto_val >> 8;
6650 match [14] |= (cos1_val & 0x7) << 5;
6656 match [18] |= (cos2_val & 0x7) << 5;
6658 match [14] |= (cos1_val & 0x7) << 5;
6661 match[13] = proto_val & 0xff;
6662 match[12] = proto_val >> 8;
6670 uword unformat_classify_match (unformat_input_t * input, va_list * args)
6672 u8 ** matchp = va_arg (*args, u8 **);
6673 u32 skip_n_vectors = va_arg (*args, u32);
6674 u32 match_n_vectors = va_arg (*args, u32);
6680 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) {
6681 if (unformat (input, "hex %U", unformat_hex_string, &match))
6683 else if (unformat (input, "l2 %U", unformat_l2_match, &l2))
6685 else if (unformat (input, "l3 %U", unformat_l3_match, &l3))
6691 if (match || l2 || l3)
6695 /* "Win a free Ethernet header in every packet" */
6697 vec_validate_aligned (l2, 13, sizeof(u32x4));
6699 vec_append_aligned (match, l3, sizeof(u32x4));
6703 /* Make sure the vector is big enough even if key is all 0's */
6704 vec_validate_aligned
6705 (match, ((match_n_vectors + skip_n_vectors) * sizeof(u32x4)) - 1,
6708 /* Set size, include skipped vectors*/
6709 _vec_len (match) = (match_n_vectors+skip_n_vectors) * sizeof(u32x4);
6719 static int api_classify_add_del_session (vat_main_t * vam)
6721 unformat_input_t * i = vam->input;
6722 vl_api_classify_add_del_session_t *mp;
6724 u32 table_index = ~0;
6725 u32 hit_next_index = ~0;
6726 u32 opaque_index = ~0;
6730 u32 skip_n_vectors = 0;
6731 u32 match_n_vectors = 0;
6734 * Warning: you have to supply skip_n and match_n
6735 * because the API client cant simply look at the classify
6739 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
6740 if (unformat (i, "del"))
6742 else if (unformat (i, "hit-next %U", unformat_ip_next_index,
6745 else if (unformat (i, "l2-hit-next %U", unformat_l2_next_index,
6748 else if (unformat (i, "acl-hit-next %U", unformat_acl_next_index,
6751 else if (unformat (i, "opaque-index %d", &opaque_index))
6753 else if (unformat (i, "skip_n %d", &skip_n_vectors))
6755 else if (unformat (i, "match_n %d", &match_n_vectors))
6757 else if (unformat (i, "match %U", unformat_classify_match,
6758 &match, skip_n_vectors, match_n_vectors))
6760 else if (unformat (i, "advance %d", &advance))
6762 else if (unformat (i, "table-index %d", &table_index))
6768 if (table_index == ~0) {
6769 errmsg ("Table index required\n");
6773 if (is_add && match == 0) {
6774 errmsg ("Match value required\n");
6778 M2 (CLASSIFY_ADD_DEL_SESSION, classify_add_del_session,
6781 mp->is_add = is_add;
6782 mp->table_index = ntohl(table_index);
6783 mp->hit_next_index = ntohl(hit_next_index);
6784 mp->opaque_index = ntohl(opaque_index);
6785 mp->advance = ntohl(advance);
6786 clib_memcpy (mp->match, match, vec_len(match));
6793 static int api_classify_set_interface_ip_table (vat_main_t * vam)
6795 unformat_input_t * i = vam->input;
6796 vl_api_classify_set_interface_ip_table_t *mp;
6799 int sw_if_index_set;
6800 u32 table_index = ~0;
6803 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
6804 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
6805 sw_if_index_set = 1;
6806 else if (unformat (i, "sw_if_index %d", &sw_if_index))
6807 sw_if_index_set = 1;
6808 else if (unformat (i, "table %d", &table_index))
6811 clib_warning ("parse error '%U'", format_unformat_error, i);
6816 if (sw_if_index_set == 0) {
6817 errmsg ("missing interface name or sw_if_index\n");
6822 M(CLASSIFY_SET_INTERFACE_IP_TABLE, classify_set_interface_ip_table);
6824 mp->sw_if_index = ntohl(sw_if_index);
6825 mp->table_index = ntohl(table_index);
6826 mp->is_ipv6 = is_ipv6;
6833 static int api_classify_set_interface_l2_tables (vat_main_t * vam)
6835 unformat_input_t * i = vam->input;
6836 vl_api_classify_set_interface_l2_tables_t *mp;
6839 int sw_if_index_set;
6840 u32 ip4_table_index = ~0;
6841 u32 ip6_table_index = ~0;
6842 u32 other_table_index = ~0;
6844 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
6845 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
6846 sw_if_index_set = 1;
6847 else if (unformat (i, "sw_if_index %d", &sw_if_index))
6848 sw_if_index_set = 1;
6849 else if (unformat (i, "ip4-table %d", &ip4_table_index))
6851 else if (unformat (i, "ip6-table %d", &ip6_table_index))
6853 else if (unformat (i, "other-table %d", &other_table_index))
6856 clib_warning ("parse error '%U'", format_unformat_error, i);
6861 if (sw_if_index_set == 0) {
6862 errmsg ("missing interface name or sw_if_index\n");
6867 M(CLASSIFY_SET_INTERFACE_L2_TABLES, classify_set_interface_l2_tables);
6869 mp->sw_if_index = ntohl(sw_if_index);
6870 mp->ip4_table_index = ntohl(ip4_table_index);
6871 mp->ip6_table_index = ntohl(ip6_table_index);
6872 mp->other_table_index = ntohl(other_table_index);
6880 static int api_get_node_index (vat_main_t * vam)
6882 unformat_input_t * i = vam->input;
6883 vl_api_get_node_index_t * mp;
6887 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
6888 if (unformat (i, "node %s", &name))
6894 errmsg ("node name required\n");
6897 if (vec_len (name) >= ARRAY_LEN(mp->node_name)) {
6898 errmsg ("node name too long, max %d\n", ARRAY_LEN(mp->node_name));
6902 M(GET_NODE_INDEX, get_node_index);
6903 clib_memcpy (mp->node_name, name, vec_len(name));
6911 static int api_add_node_next (vat_main_t * vam)
6913 unformat_input_t * i = vam->input;
6914 vl_api_add_node_next_t * mp;
6919 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
6920 if (unformat (i, "node %s", &name))
6922 else if (unformat (i, "next %s", &next))
6928 errmsg ("node name required\n");
6931 if (vec_len (name) >= ARRAY_LEN(mp->node_name)) {
6932 errmsg ("node name too long, max %d\n", ARRAY_LEN(mp->node_name));
6936 errmsg ("next node required\n");
6939 if (vec_len (next) >= ARRAY_LEN(mp->next_name)) {
6940 errmsg ("next name too long, max %d\n", ARRAY_LEN(mp->next_name));
6944 M(ADD_NODE_NEXT, add_node_next);
6945 clib_memcpy (mp->node_name, name, vec_len(name));
6946 clib_memcpy (mp->next_name, next, vec_len(next));
6955 static int api_l2tpv3_create_tunnel (vat_main_t * vam)
6957 unformat_input_t * i = vam->input;
6958 ip6_address_t client_address, our_address;
6959 int client_address_set = 0;
6960 int our_address_set = 0;
6961 u32 local_session_id = 0;
6962 u32 remote_session_id = 0;
6963 u64 local_cookie = 0;
6964 u64 remote_cookie = 0;
6965 u8 l2_sublayer_present = 0;
6966 vl_api_l2tpv3_create_tunnel_t * mp;
6969 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
6970 if (unformat (i, "client_address %U", unformat_ip6_address,
6972 client_address_set = 1;
6973 else if (unformat (i, "our_address %U", unformat_ip6_address,
6975 our_address_set = 1;
6976 else if (unformat (i, "local_session_id %d", &local_session_id))
6978 else if (unformat (i, "remote_session_id %d", &remote_session_id))
6980 else if (unformat (i, "local_cookie %lld", &local_cookie))
6982 else if (unformat (i, "remote_cookie %lld", &remote_cookie))
6984 else if (unformat (i, "l2-sublayer-present"))
6985 l2_sublayer_present = 1;
6990 if (client_address_set == 0) {
6991 errmsg ("client_address required\n");
6995 if (our_address_set == 0) {
6996 errmsg ("our_address required\n");
7000 M(L2TPV3_CREATE_TUNNEL, l2tpv3_create_tunnel);
7002 clib_memcpy (mp->client_address, client_address.as_u8,
7003 sizeof (mp->client_address));
7005 clib_memcpy (mp->our_address, our_address.as_u8,
7006 sizeof (mp->our_address));
7008 mp->local_session_id = ntohl (local_session_id);
7009 mp->remote_session_id = ntohl (remote_session_id);
7010 mp->local_cookie = clib_host_to_net_u64 (local_cookie);
7011 mp->remote_cookie = clib_host_to_net_u64 (remote_cookie);
7012 mp->l2_sublayer_present = l2_sublayer_present;
7020 static int api_l2tpv3_set_tunnel_cookies (vat_main_t * vam)
7022 unformat_input_t * i = vam->input;
7024 u8 sw_if_index_set = 0;
7025 u64 new_local_cookie = 0;
7026 u64 new_remote_cookie = 0;
7027 vl_api_l2tpv3_set_tunnel_cookies_t *mp;
7030 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
7031 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
7032 sw_if_index_set = 1;
7033 else if (unformat (i, "sw_if_index %d", &sw_if_index))
7034 sw_if_index_set = 1;
7035 else if (unformat (i, "new_local_cookie %lld", &new_local_cookie))
7037 else if (unformat (i, "new_remote_cookie %lld", &new_remote_cookie))
7043 if (sw_if_index_set == 0) {
7044 errmsg ("missing interface name or sw_if_index\n");
7048 M(L2TPV3_SET_TUNNEL_COOKIES, l2tpv3_set_tunnel_cookies);
7050 mp->sw_if_index = ntohl(sw_if_index);
7051 mp->new_local_cookie = clib_host_to_net_u64 (new_local_cookie);
7052 mp->new_remote_cookie = clib_host_to_net_u64 (new_remote_cookie);
7059 static int api_l2tpv3_interface_enable_disable (vat_main_t * vam)
7061 unformat_input_t * i = vam->input;
7062 vl_api_l2tpv3_interface_enable_disable_t *mp;
7065 u8 sw_if_index_set = 0;
7066 u8 enable_disable = 1;
7068 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
7069 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
7070 sw_if_index_set = 1;
7071 else if (unformat (i, "sw_if_index %d", &sw_if_index))
7072 sw_if_index_set = 1;
7073 else if (unformat (i, "enable"))
7075 else if (unformat (i, "disable"))
7081 if (sw_if_index_set == 0) {
7082 errmsg ("missing interface name or sw_if_index\n");
7086 M(L2TPV3_INTERFACE_ENABLE_DISABLE, l2tpv3_interface_enable_disable);
7088 mp->sw_if_index = ntohl(sw_if_index);
7089 mp->enable_disable = enable_disable;
7096 static int api_l2tpv3_set_lookup_key (vat_main_t * vam)
7098 unformat_input_t * i = vam->input;
7099 vl_api_l2tpv3_set_lookup_key_t * mp;
7103 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
7104 if (unformat (i, "lookup_v6_src"))
7105 key = L2T_LOOKUP_SRC_ADDRESS;
7106 else if (unformat (i, "lookup_v6_dst"))
7107 key = L2T_LOOKUP_DST_ADDRESS;
7108 else if (unformat (i, "lookup_session_id"))
7109 key = L2T_LOOKUP_SESSION_ID;
7114 if (key == (u8) ~0) {
7115 errmsg ("l2tp session lookup key unset\n");
7119 M(L2TPV3_SET_LOOKUP_KEY, l2tpv3_set_lookup_key);
7128 static void vl_api_sw_if_l2tpv3_tunnel_details_t_handler
7129 (vl_api_sw_if_l2tpv3_tunnel_details_t * mp)
7131 vat_main_t * vam = &vat_main;
7133 fformat(vam->ofp, "* %U (our) %U (client) (sw_if_index %d)\n",
7134 format_ip6_address, mp->our_address,
7135 format_ip6_address, mp->client_address,
7136 clib_net_to_host_u32(mp->sw_if_index));
7138 fformat (vam->ofp, " local cookies %016llx %016llx remote cookie %016llx\n",
7139 clib_net_to_host_u64 (mp->local_cookie[0]),
7140 clib_net_to_host_u64 (mp->local_cookie[1]),
7141 clib_net_to_host_u64 (mp->remote_cookie));
7143 fformat (vam->ofp, " local session-id %d remote session-id %d\n",
7144 clib_net_to_host_u32 (mp->local_session_id),
7145 clib_net_to_host_u32 (mp->remote_session_id));
7147 fformat (vam->ofp, " l2 specific sublayer %s\n\n",
7148 mp->l2_sublayer_present ? "preset" : "absent");
7152 static void vl_api_sw_if_l2tpv3_tunnel_details_t_handler_json
7153 (vl_api_sw_if_l2tpv3_tunnel_details_t * mp)
7155 vat_main_t * vam = &vat_main;
7156 vat_json_node_t *node = NULL;
7157 struct in6_addr addr;
7159 if (VAT_JSON_ARRAY != vam->json_tree.type) {
7160 ASSERT(VAT_JSON_NONE == vam->json_tree.type);
7161 vat_json_init_array(&vam->json_tree);
7163 node = vat_json_array_add(&vam->json_tree);
7165 vat_json_init_object(node);
7167 clib_memcpy(&addr, mp->our_address, sizeof(addr));
7168 vat_json_object_add_ip6(node, "our_address", addr);
7169 clib_memcpy(&addr, mp->client_address, sizeof(addr));
7170 vat_json_object_add_ip6(node, "client_address", addr);
7172 vat_json_node_t * lc = vat_json_object_add(node, "local_cookie");
7173 vat_json_init_array(lc);
7174 vat_json_array_add_uint(lc, clib_net_to_host_u64(mp->local_cookie[0]));
7175 vat_json_array_add_uint(lc, clib_net_to_host_u64(mp->local_cookie[1]));
7176 vat_json_object_add_uint(node, "remote_cookie", clib_net_to_host_u64(mp->remote_cookie));
7178 printf("local id: %u", clib_net_to_host_u32(mp->local_session_id));
7179 vat_json_object_add_uint(node, "local_session_id", clib_net_to_host_u32(mp->local_session_id));
7180 vat_json_object_add_uint(node, "remote_session_id", clib_net_to_host_u32(mp->remote_session_id));
7181 vat_json_object_add_string_copy(node, "l2_sublayer", mp->l2_sublayer_present ?
7182 (u8*)"present" : (u8*)"absent");
7185 static int api_sw_if_l2tpv3_tunnel_dump (vat_main_t * vam)
7187 vl_api_sw_if_l2tpv3_tunnel_dump_t *mp;
7190 /* Get list of l2tpv3-tunnel interfaces */
7191 M(SW_IF_L2TPV3_TUNNEL_DUMP, sw_if_l2tpv3_tunnel_dump);
7194 /* Use a control ping for synchronization */
7196 vl_api_control_ping_t * mp;
7197 M(CONTROL_PING, control_ping);
7204 static void vl_api_sw_interface_tap_details_t_handler
7205 (vl_api_sw_interface_tap_details_t * mp)
7207 vat_main_t * vam = &vat_main;
7209 fformat(vam->ofp, "%-16s %d\n",
7211 clib_net_to_host_u32(mp->sw_if_index));
7214 static void vl_api_sw_interface_tap_details_t_handler_json
7215 (vl_api_sw_interface_tap_details_t * mp)
7217 vat_main_t * vam = &vat_main;
7218 vat_json_node_t *node = NULL;
7220 if (VAT_JSON_ARRAY != vam->json_tree.type) {
7221 ASSERT(VAT_JSON_NONE == vam->json_tree.type);
7222 vat_json_init_array(&vam->json_tree);
7224 node = vat_json_array_add(&vam->json_tree);
7226 vat_json_init_object(node);
7227 vat_json_object_add_uint(node, "sw_if_index", ntohl(mp->sw_if_index));
7228 vat_json_object_add_string_copy(node, "dev_name", mp->dev_name);
7231 static int api_sw_interface_tap_dump (vat_main_t * vam)
7233 vl_api_sw_interface_tap_dump_t *mp;
7236 fformat(vam->ofp, "\n%-16s %s\n", "dev_name", "sw_if_index");
7237 /* Get list of tap interfaces */
7238 M(SW_INTERFACE_TAP_DUMP, sw_interface_tap_dump);
7241 /* Use a control ping for synchronization */
7243 vl_api_control_ping_t * mp;
7244 M(CONTROL_PING, control_ping);
7250 static uword unformat_vxlan_decap_next
7251 (unformat_input_t * input, va_list * args)
7253 u32 * result = va_arg (*args, u32 *);
7256 if (unformat (input, "drop"))
7257 *result = VXLAN_INPUT_NEXT_DROP;
7258 else if (unformat (input, "ip4"))
7259 *result = VXLAN_INPUT_NEXT_IP4_INPUT;
7260 else if (unformat (input, "ip6"))
7261 *result = VXLAN_INPUT_NEXT_IP6_INPUT;
7262 else if (unformat (input, "l2"))
7263 *result = VXLAN_INPUT_NEXT_L2_INPUT;
7264 else if (unformat (input, "%d", &tmp))
7271 static int api_vxlan_add_del_tunnel (vat_main_t * vam)
7273 unformat_input_t * line_input = vam->input;
7274 vl_api_vxlan_add_del_tunnel_t *mp;
7276 ip4_address_t src4, dst4;
7277 ip6_address_t src6, dst6;
7279 u8 ipv4_set = 0, ipv6_set = 0;
7282 u32 encap_vrf_id = 0;
7283 u32 decap_next_index = ~0;
7286 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) {
7287 if (unformat (line_input, "del"))
7289 else if (unformat (line_input, "src %U",
7290 unformat_ip4_address, &src4))
7295 else if (unformat (line_input, "dst %U",
7296 unformat_ip4_address, &dst4))
7301 else if (unformat (line_input, "src %U",
7302 unformat_ip6_address, &src6))
7307 else if (unformat (line_input, "dst %U",
7308 unformat_ip6_address, &dst6))
7313 else if (unformat (line_input, "encap-vrf-id %d", &encap_vrf_id))
7315 else if (unformat (line_input, "decap-next %U",
7316 unformat_vxlan_decap_next, &decap_next_index))
7318 else if (unformat (line_input, "vni %d", &vni))
7321 errmsg ("parse error '%U'\n", format_unformat_error, line_input);
7327 errmsg ("tunnel src address not specified\n");
7331 errmsg ("tunnel dst address not specified\n");
7335 if (ipv4_set && ipv6_set) {
7336 errmsg ("both IPv4 and IPv6 addresses specified");
7340 if ((vni == 0) || (vni>>24)) {
7341 errmsg ("vni not specified or out of range\n");
7345 M (VXLAN_ADD_DEL_TUNNEL, vxlan_add_del_tunnel);
7348 clib_memcpy(&mp->dst_address, &src6, sizeof(src6));
7349 clib_memcpy(&mp->dst_address, &src6, sizeof(dst6));
7351 clib_memcpy(&mp->src_address, &src4, sizeof(src4));
7352 clib_memcpy(&mp->dst_address, &dst4, sizeof(dst4));
7354 mp->encap_vrf_id = ntohl(encap_vrf_id);
7355 mp->decap_next_index = ntohl(decap_next_index);
7356 mp->vni = ntohl(vni);
7357 mp->is_add = is_add;
7358 mp->is_ipv6 = ipv6_set;
7365 static void vl_api_vxlan_tunnel_details_t_handler
7366 (vl_api_vxlan_tunnel_details_t * mp)
7368 vat_main_t * vam = &vat_main;
7370 fformat(vam->ofp, "%11d%24U%24U%14d%18d%13d\n",
7371 ntohl(mp->sw_if_index),
7372 format_ip46_address, &(mp->src_address[0]),
7373 format_ip46_address, &(mp->dst_address[0]),
7374 ntohl(mp->encap_vrf_id),
7375 ntohl(mp->decap_next_index),
7379 static void vl_api_vxlan_tunnel_details_t_handler_json
7380 (vl_api_vxlan_tunnel_details_t * mp)
7382 vat_main_t * vam = &vat_main;
7383 vat_json_node_t *node = NULL;
7385 struct in6_addr ip6;
7387 if (VAT_JSON_ARRAY != vam->json_tree.type) {
7388 ASSERT(VAT_JSON_NONE == vam->json_tree.type);
7389 vat_json_init_array(&vam->json_tree);
7391 node = vat_json_array_add(&vam->json_tree);
7393 vat_json_init_object(node);
7394 vat_json_object_add_uint(node, "sw_if_index", ntohl(mp->sw_if_index));
7396 clib_memcpy(&ip6, &(mp->src_address[0]), sizeof(ip6));
7397 vat_json_object_add_ip6(node, "src_address", ip6);
7398 clib_memcpy(&ip6, &(mp->dst_address[0]), sizeof(ip6));
7399 vat_json_object_add_ip6(node, "dst_address", ip6);
7401 clib_memcpy(&ip4, &(mp->src_address[0]), sizeof(ip4));
7402 vat_json_object_add_ip4(node, "src_address", ip4);
7403 clib_memcpy(&ip4, &(mp->dst_address[0]), sizeof(ip4));
7404 vat_json_object_add_ip4(node, "dst_address", ip4);
7406 vat_json_object_add_uint(node, "encap_vrf_id", ntohl(mp->encap_vrf_id));
7407 vat_json_object_add_uint(node, "decap_next_index", ntohl(mp->decap_next_index));
7408 vat_json_object_add_uint(node, "vni", ntohl(mp->vni));
7409 vat_json_object_add_uint(node, "is_ipv6", mp->is_ipv6 ? 1 : 0);
7412 static int api_vxlan_tunnel_dump (vat_main_t * vam)
7414 unformat_input_t * i = vam->input;
7415 vl_api_vxlan_tunnel_dump_t *mp;
7418 u8 sw_if_index_set = 0;
7420 /* Parse args required to build the message */
7421 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
7422 if (unformat (i, "sw_if_index %d", &sw_if_index))
7423 sw_if_index_set = 1;
7428 if (sw_if_index_set == 0) {
7432 if (!vam->json_output) {
7433 fformat(vam->ofp, "%11s%24s%24s%14s%18s%13s\n",
7434 "sw_if_index", "src_address", "dst_address",
7435 "encap_vrf_id", "decap_next_index", "vni");
7438 /* Get list of vxlan-tunnel interfaces */
7439 M(VXLAN_TUNNEL_DUMP, vxlan_tunnel_dump);
7441 mp->sw_if_index = htonl(sw_if_index);
7445 /* Use a control ping for synchronization */
7447 vl_api_control_ping_t * mp;
7448 M(CONTROL_PING, control_ping);
7454 static int api_gre_add_del_tunnel (vat_main_t * vam)
7456 unformat_input_t * line_input = vam->input;
7457 vl_api_gre_add_del_tunnel_t *mp;
7459 ip4_address_t src4, dst4;
7463 u32 outer_fib_id = 0;
7465 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) {
7466 if (unformat (line_input, "del"))
7468 else if (unformat (line_input, "src %U",
7469 unformat_ip4_address, &src4))
7471 else if (unformat (line_input, "dst %U",
7472 unformat_ip4_address, &dst4))
7474 else if (unformat (line_input, "outer-fib-id %d", &outer_fib_id))
7477 errmsg ("parse error '%U'\n", format_unformat_error, line_input);
7483 errmsg ("tunnel src address not specified\n");
7487 errmsg ("tunnel dst address not specified\n");
7492 M (GRE_ADD_DEL_TUNNEL, gre_add_del_tunnel);
7494 clib_memcpy(&mp->src_address, &src4, sizeof(src4));
7495 clib_memcpy(&mp->dst_address, &dst4, sizeof(dst4));
7496 mp->outer_table_id = ntohl(outer_fib_id);
7497 mp->is_add = is_add;
7504 static void vl_api_gre_tunnel_details_t_handler
7505 (vl_api_gre_tunnel_details_t * mp)
7507 vat_main_t * vam = &vat_main;
7509 fformat(vam->ofp, "%11d%15U%15U%14d\n",
7510 ntohl(mp->sw_if_index),
7511 format_ip4_address, &mp->src_address,
7512 format_ip4_address, &mp->dst_address,
7513 ntohl(mp->outer_table_id));
7516 static void vl_api_gre_tunnel_details_t_handler_json
7517 (vl_api_gre_tunnel_details_t * mp)
7519 vat_main_t * vam = &vat_main;
7520 vat_json_node_t *node = NULL;
7523 if (VAT_JSON_ARRAY != vam->json_tree.type) {
7524 ASSERT(VAT_JSON_NONE == vam->json_tree.type);
7525 vat_json_init_array(&vam->json_tree);
7527 node = vat_json_array_add(&vam->json_tree);
7529 vat_json_init_object(node);
7530 vat_json_object_add_uint(node, "sw_if_index", ntohl(mp->sw_if_index));
7531 clib_memcpy(&ip4, &mp->src_address, sizeof(ip4));
7532 vat_json_object_add_ip4(node, "src_address", ip4);
7533 clib_memcpy(&ip4, &mp->dst_address, sizeof(ip4));
7534 vat_json_object_add_ip4(node, "dst_address", ip4);
7535 vat_json_object_add_uint(node, "outer_fib_id", ntohl(mp->outer_table_id));
7538 static int api_gre_tunnel_dump (vat_main_t * vam)
7540 unformat_input_t * i = vam->input;
7541 vl_api_gre_tunnel_dump_t *mp;
7544 u8 sw_if_index_set = 0;
7546 /* Parse args required to build the message */
7547 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
7548 if (unformat (i, "sw_if_index %d", &sw_if_index))
7549 sw_if_index_set = 1;
7554 if (sw_if_index_set == 0) {
7558 if (!vam->json_output) {
7559 fformat(vam->ofp, "%11s%15s%15s%14s\n",
7560 "sw_if_index", "src_address", "dst_address",
7564 /* Get list of gre-tunnel interfaces */
7565 M(GRE_TUNNEL_DUMP, gre_tunnel_dump);
7567 mp->sw_if_index = htonl(sw_if_index);
7571 /* Use a control ping for synchronization */
7573 vl_api_control_ping_t * mp;
7574 M(CONTROL_PING, control_ping);
7580 static int api_l2_fib_clear_table (vat_main_t * vam)
7582 // unformat_input_t * i = vam->input;
7583 vl_api_l2_fib_clear_table_t *mp;
7586 M(L2_FIB_CLEAR_TABLE, l2_fib_clear_table);
7593 static int api_l2_interface_efp_filter (vat_main_t * vam)
7595 unformat_input_t * i = vam->input;
7596 vl_api_l2_interface_efp_filter_t *mp;
7600 u8 sw_if_index_set = 0;
7602 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
7603 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
7604 sw_if_index_set = 1;
7605 else if (unformat (i, "sw_if_index %d", &sw_if_index))
7606 sw_if_index_set = 1;
7607 else if (unformat (i, "enable"))
7609 else if (unformat (i, "disable"))
7612 clib_warning ("parse error '%U'", format_unformat_error, i);
7617 if (sw_if_index_set == 0) {
7618 errmsg ("missing sw_if_index\n");
7622 M(L2_INTERFACE_EFP_FILTER, l2_interface_efp_filter);
7624 mp->sw_if_index = ntohl(sw_if_index);
7625 mp->enable_disable = enable;
7632 #define foreach_vtr_op \
7633 _("disable", L2_VTR_DISABLED) \
7634 _("push-1", L2_VTR_PUSH_1) \
7635 _("push-2", L2_VTR_PUSH_2) \
7636 _("pop-1", L2_VTR_POP_1) \
7637 _("pop-2", L2_VTR_POP_2) \
7638 _("translate-1-1", L2_VTR_TRANSLATE_1_1) \
7639 _("translate-1-2", L2_VTR_TRANSLATE_1_2) \
7640 _("translate-2-1", L2_VTR_TRANSLATE_2_1) \
7641 _("translate-2-2", L2_VTR_TRANSLATE_2_2)
7643 static int api_l2_interface_vlan_tag_rewrite (vat_main_t * vam)
7645 unformat_input_t * i = vam->input;
7646 vl_api_l2_interface_vlan_tag_rewrite_t *mp;
7649 u8 sw_if_index_set = 0;
7656 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
7657 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
7658 sw_if_index_set = 1;
7659 else if (unformat (i, "sw_if_index %d", &sw_if_index))
7660 sw_if_index_set = 1;
7661 else if (unformat (i, "vtr_op %d", &vtr_op))
7663 #define _(n,v) else if (unformat(i, n)) {vtr_op = v; vtr_op_set = 1;}
7667 else if (unformat (i, "push_dot1q %d", &push_dot1q))
7669 else if (unformat (i, "tag1 %d", &tag1))
7671 else if (unformat (i, "tag2 %d", &tag2))
7674 clib_warning ("parse error '%U'", format_unformat_error, i);
7679 if ((sw_if_index_set == 0)||(vtr_op_set == 0)) {
7680 errmsg ("missing vtr operation or sw_if_index\n");
7684 M(L2_INTERFACE_VLAN_TAG_REWRITE, l2_interface_vlan_tag_rewrite)
7686 mp->sw_if_index = ntohl(sw_if_index);
7687 mp->vtr_op = ntohl(vtr_op);
7688 mp->push_dot1q = ntohl(push_dot1q);
7689 mp->tag1 = ntohl(tag1);
7690 mp->tag2 = ntohl(tag2);
7697 static int api_create_vhost_user_if (vat_main_t * vam)
7699 unformat_input_t * i = vam->input;
7700 vl_api_create_vhost_user_if_t *mp;
7704 u8 file_name_set = 0;
7705 u32 custom_dev_instance = ~0;
7707 u8 use_custom_mac = 0;
7709 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
7710 if (unformat (i, "socket %s", &file_name)) {
7713 else if (unformat (i, "renumber %"PRIu32, &custom_dev_instance))
7715 else if (unformat (i, "mac %U", unformat_ethernet_address, hwaddr))
7717 else if (unformat (i, "server"))
7723 if (file_name_set == 0) {
7724 errmsg ("missing socket file name\n");
7728 if (vec_len (file_name) > 255) {
7729 errmsg ("socket file name too long\n");
7732 vec_add1 (file_name, 0);
7734 M(CREATE_VHOST_USER_IF, create_vhost_user_if);
7736 mp->is_server = is_server;
7737 clib_memcpy(mp->sock_filename, file_name, vec_len(file_name));
7738 vec_free(file_name);
7739 if (custom_dev_instance != ~0) {
7741 mp->custom_dev_instance = ntohl(custom_dev_instance);
7743 mp->use_custom_mac = use_custom_mac;
7744 clib_memcpy(mp->mac_address, hwaddr, 6);
7751 static int api_modify_vhost_user_if (vat_main_t * vam)
7753 unformat_input_t * i = vam->input;
7754 vl_api_modify_vhost_user_if_t *mp;
7758 u8 file_name_set = 0;
7759 u32 custom_dev_instance = ~0;
7760 u8 sw_if_index_set = 0;
7761 u32 sw_if_index = (u32)~0;
7763 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
7764 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
7765 sw_if_index_set = 1;
7766 else if (unformat (i, "sw_if_index %d", &sw_if_index))
7767 sw_if_index_set = 1;
7768 else if (unformat (i, "socket %s", &file_name)) {
7771 else if (unformat (i, "renumber %"PRIu32, &custom_dev_instance))
7773 else if (unformat (i, "server"))
7779 if (sw_if_index_set == 0) {
7780 errmsg ("missing sw_if_index or interface name\n");
7784 if (file_name_set == 0) {
7785 errmsg ("missing socket file name\n");
7789 if (vec_len (file_name) > 255) {
7790 errmsg ("socket file name too long\n");
7793 vec_add1 (file_name, 0);
7795 M(MODIFY_VHOST_USER_IF, modify_vhost_user_if);
7797 mp->sw_if_index = ntohl(sw_if_index);
7798 mp->is_server = is_server;
7799 clib_memcpy(mp->sock_filename, file_name, vec_len(file_name));
7800 vec_free(file_name);
7801 if (custom_dev_instance != ~0) {
7803 mp->custom_dev_instance = ntohl(custom_dev_instance);
7811 static int api_delete_vhost_user_if (vat_main_t * vam)
7813 unformat_input_t * i = vam->input;
7814 vl_api_delete_vhost_user_if_t *mp;
7816 u32 sw_if_index = ~0;
7817 u8 sw_if_index_set = 0;
7819 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
7820 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
7821 sw_if_index_set = 1;
7822 else if (unformat (i, "sw_if_index %d", &sw_if_index))
7823 sw_if_index_set = 1;
7828 if (sw_if_index_set == 0) {
7829 errmsg ("missing sw_if_index or interface name\n");
7834 M(DELETE_VHOST_USER_IF, delete_vhost_user_if);
7836 mp->sw_if_index = ntohl(sw_if_index);
7843 static void vl_api_sw_interface_vhost_user_details_t_handler
7844 (vl_api_sw_interface_vhost_user_details_t * mp)
7846 vat_main_t * vam = &vat_main;
7848 fformat(vam->ofp, "%-25s %3" PRIu32 " %6" PRIu32 " %8x %6d %7d %s\n",
7849 (char *)mp->interface_name,
7850 ntohl(mp->sw_if_index), ntohl(mp->virtio_net_hdr_sz),
7851 clib_net_to_host_u64(mp->features), mp->is_server,
7852 ntohl(mp->num_regions), (char *)mp->sock_filename);
7853 fformat(vam->ofp, " Status: '%s'\n", strerror(ntohl(mp->sock_errno)));
7856 static void vl_api_sw_interface_vhost_user_details_t_handler_json
7857 (vl_api_sw_interface_vhost_user_details_t * mp)
7859 vat_main_t * vam = &vat_main;
7860 vat_json_node_t *node = NULL;
7862 if (VAT_JSON_ARRAY != vam->json_tree.type) {
7863 ASSERT(VAT_JSON_NONE == vam->json_tree.type);
7864 vat_json_init_array(&vam->json_tree);
7866 node = vat_json_array_add(&vam->json_tree);
7868 vat_json_init_object(node);
7869 vat_json_object_add_uint(node, "sw_if_index", ntohl(mp->sw_if_index));
7870 vat_json_object_add_string_copy(node, "interface_name", mp->interface_name);
7871 vat_json_object_add_uint(node, "virtio_net_hdr_sz", ntohl(mp->virtio_net_hdr_sz));
7872 vat_json_object_add_uint(node, "features", clib_net_to_host_u64(mp->features));
7873 vat_json_object_add_uint(node, "is_server", mp->is_server);
7874 vat_json_object_add_string_copy(node, "sock_filename", mp->sock_filename);
7875 vat_json_object_add_uint(node, "num_regions", ntohl(mp->num_regions));
7876 vat_json_object_add_uint(node, "sock_errno", ntohl(mp->sock_errno));
7879 static int api_sw_interface_vhost_user_dump (vat_main_t * vam)
7881 vl_api_sw_interface_vhost_user_dump_t *mp;
7883 fformat(vam->ofp, "Interface name idx hdr_sz features server regions filename\n");
7885 /* Get list of vhost-user interfaces */
7886 M(SW_INTERFACE_VHOST_USER_DUMP, sw_interface_vhost_user_dump);
7889 /* Use a control ping for synchronization */
7891 vl_api_control_ping_t * mp;
7892 M(CONTROL_PING, control_ping);
7898 static int api_show_version (vat_main_t * vam)
7900 vl_api_show_version_t *mp;
7903 M(SHOW_VERSION, show_version);
7910 static uword unformat_nsh_gre_decap_next
7911 (unformat_input_t * input, va_list * args)
7913 u32 * result = va_arg (*args, u32 *);
7916 if (unformat (input, "drop"))
7917 *result = NSH_GRE_INPUT_NEXT_DROP;
7918 else if (unformat (input, "ip4"))
7919 *result = NSH_GRE_INPUT_NEXT_IP4_INPUT;
7920 else if (unformat (input, "ip6"))
7921 *result = NSH_GRE_INPUT_NEXT_IP6_INPUT;
7922 else if (unformat (input, "ethernet"))
7923 *result = NSH_GRE_INPUT_NEXT_ETHERNET_INPUT;
7924 else if (unformat (input, "%d", &tmp))
7931 static int api_nsh_gre_add_del_tunnel (vat_main_t * vam)
7933 unformat_input_t * line_input = vam->input;
7934 vl_api_nsh_gre_add_del_tunnel_t *mp;
7936 ip4_address_t src, dst;
7940 u32 encap_vrf_id = 0;
7941 u32 decap_vrf_id = 0;
7944 u8 next_protocol = 1; /* ip4 */
7955 u32 decap_next_index = NSH_GRE_INPUT_NEXT_IP4_INPUT;
7959 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) {
7960 if (unformat (line_input, "del"))
7962 else if (unformat (line_input, "src %U",
7963 unformat_ip4_address, &src))
7965 else if (unformat (line_input, "dst %U",
7966 unformat_ip4_address, &dst))
7968 else if (unformat (line_input, "encap-vrf-id %d", &encap_vrf_id))
7970 else if (unformat (line_input, "decap-vrf-id %d", &decap_vrf_id))
7972 else if (unformat (line_input, "decap-next %U",
7973 unformat_nsh_gre_decap_next, &decap_next_index))
7975 else if (unformat (line_input, "version %d", &tmp))
7976 ver_o_c |= (tmp & 3) << 6;
7977 else if (unformat (line_input, "o-bit %d", &tmp))
7978 ver_o_c |= (tmp & 1) << 5;
7979 else if (unformat (line_input, "c-bit %d", &tmp))
7980 ver_o_c |= (tmp & 1) << 4;
7981 else if (unformat (line_input, "md-type %d", &tmp))
7983 else if (unformat(line_input, "next-ip4"))
7985 else if (unformat(line_input, "next-ip6"))
7987 else if (unformat(line_input, "next-ethernet"))
7989 else if (unformat (line_input, "c1 %d", &c1))
7991 else if (unformat (line_input, "c2 %d", &c2))
7993 else if (unformat (line_input, "c3 %d", &c3))
7995 else if (unformat (line_input, "c4 %d", &c4))
7997 else if (unformat (line_input, "spi %d", &spi))
7999 else if (unformat (line_input, "si %d", &si))
8001 else if (unformat (line_input, "tlv %x"))
8002 vec_add1 (tlvs, tmp);
8004 errmsg ("parse error '%U'\n", format_unformat_error, line_input);
8010 errmsg ("tunnel src address not specified\n");
8014 errmsg ("tunnel dst address not specified\n");
8019 errmsg ("spi not specified\n");
8024 errmsg ("si not specified\n");
8028 M2 (NSH_GRE_ADD_DEL_TUNNEL, nsh_gre_add_del_tunnel,
8029 sizeof(u32) * vec_len (tlvs));
8031 spi_si = (spi<<8) | si;
8033 mp->src = src.as_u32;
8034 mp->dst = dst.as_u32;
8035 mp->encap_vrf_id = ntohl(encap_vrf_id);
8036 mp->decap_vrf_id = ntohl(decap_vrf_id);
8037 mp->decap_next_index = ntohl(decap_next_index);
8038 mp->tlv_len_in_words = vec_len (tlvs);
8039 mp->is_add = is_add;
8040 mp->ver_o_c = ver_o_c;
8041 mp->length = 6 + vec_len(tlvs);
8042 mp->md_type = md_type;
8043 mp->next_protocol = next_protocol;
8044 mp->spi_si = ntohl(spi_si);
8050 for (i = 0; i < vec_len(tlvs); i++)
8051 mp->tlvs[i] = ntohl(tlvs[i]);
8060 static uword unformat_nsh_vxlan_gpe_decap_next
8061 (unformat_input_t * input, va_list * args)
8063 u32 * result = va_arg (*args, u32 *);
8066 if (unformat (input, "drop"))
8067 *result = NSH_VXLAN_GPE_INPUT_NEXT_DROP;
8068 else if (unformat (input, "ip4"))
8069 *result = NSH_VXLAN_GPE_INPUT_NEXT_IP4_INPUT;
8070 else if (unformat (input, "ip6"))
8071 *result = NSH_VXLAN_GPE_INPUT_NEXT_IP6_INPUT;
8072 else if (unformat (input, "ethernet"))
8073 *result = NSH_VXLAN_GPE_INPUT_NEXT_ETHERNET_INPUT;
8074 else if (unformat (input, "nsh-vxlan-gpe"))
8075 *result = NSH_VXLAN_GPE_INPUT_NEXT_ETHERNET_INPUT;
8076 else if (unformat (input, "%d", &tmp))
8083 static int api_nsh_vxlan_gpe_add_del_tunnel (vat_main_t * vam)
8085 unformat_input_t * line_input = vam->input;
8086 vl_api_nsh_vxlan_gpe_add_del_tunnel_t *mp;
8088 ip4_address_t src, dst;
8092 u32 encap_vrf_id = 0;
8093 u32 decap_vrf_id = 0;
8096 u8 next_protocol = 1; /* ip4 */
8107 u32 decap_next_index = NSH_GRE_INPUT_NEXT_IP4_INPUT;
8113 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) {
8114 if (unformat (line_input, "del"))
8116 else if (unformat (line_input, "src %U",
8117 unformat_ip4_address, &src))
8119 else if (unformat (line_input, "dst %U",
8120 unformat_ip4_address, &dst))
8122 else if (unformat (line_input, "encap-vrf-id %d", &encap_vrf_id))
8124 else if (unformat (line_input, "decap-vrf-id %d", &decap_vrf_id))
8126 else if (unformat (line_input, "decap-next %U",
8127 unformat_nsh_vxlan_gpe_decap_next,
8130 else if (unformat (line_input, "vni %d", &vni))
8132 else if (unformat (line_input, "version %d", &tmp))
8133 ver_o_c |= (tmp & 3) << 6;
8134 else if (unformat (line_input, "o-bit %d", &tmp))
8135 ver_o_c |= (tmp & 1) << 5;
8136 else if (unformat (line_input, "c-bit %d", &tmp))
8137 ver_o_c |= (tmp & 1) << 4;
8138 else if (unformat (line_input, "md-type %d", &tmp))
8140 else if (unformat(line_input, "next-ip4"))
8142 else if (unformat(line_input, "next-ip6"))
8144 else if (unformat(line_input, "next-ethernet"))
8146 else if (unformat (line_input, "c1 %d", &c1))
8148 else if (unformat (line_input, "c2 %d", &c2))
8150 else if (unformat (line_input, "c3 %d", &c3))
8152 else if (unformat (line_input, "c4 %d", &c4))
8154 else if (unformat (line_input, "spi %d", &spi))
8156 else if (unformat (line_input, "si %d", &si))
8158 else if (unformat (line_input, "tlv %x"))
8159 vec_add1 (tlvs, tmp);
8161 errmsg ("parse error '%U'\n", format_unformat_error, line_input);
8167 errmsg ("tunnel src address not specified\n");
8171 errmsg ("tunnel dst address not specified\n");
8176 errmsg ("spi not specified\n");
8181 errmsg ("si not specified\n");
8185 errmsg ("vni not specified\n");
8189 M2 (NSH_VXLAN_GPE_ADD_DEL_TUNNEL, nsh_vxlan_gpe_add_del_tunnel,
8190 sizeof(u32) * vec_len (tlvs));
8192 spi_si = (spi<<8) | si;
8194 mp->src = src.as_u32;
8195 mp->dst = dst.as_u32;
8196 mp->encap_vrf_id = ntohl(encap_vrf_id);
8197 mp->decap_vrf_id = ntohl(decap_vrf_id);
8198 mp->decap_next_index = ntohl(decap_next_index);
8199 mp->tlv_len_in_words = vec_len (tlvs);
8200 mp->vni = ntohl(vni);
8201 mp->is_add = is_add;
8202 mp->ver_o_c = ver_o_c;
8203 mp->length = 6 + vec_len(tlvs);
8204 mp->md_type = md_type;
8205 mp->next_protocol = next_protocol;
8206 mp->spi_si = ntohl(spi_si);
8212 for (i = 0; i < vec_len(tlvs); i++)
8213 mp->tlvs[i] = ntohl(tlvs[i]);
8222 u8 * format_l2_fib_mac_address (u8 * s, va_list * args)
8224 u8 * a = va_arg (*args, u8 *);
8226 return format (s, "%02x:%02x:%02x:%02x:%02x:%02x",
8227 a[2], a[3], a[4], a[5], a[6], a[7]);
8230 static void vl_api_l2_fib_table_entry_t_handler
8231 (vl_api_l2_fib_table_entry_t * mp)
8233 vat_main_t * vam = &vat_main;
8235 fformat(vam->ofp, "%3" PRIu32 " %U %3" PRIu32
8237 ntohl(mp->bd_id), format_l2_fib_mac_address, &mp->mac,
8238 ntohl(mp->sw_if_index), mp->static_mac, mp->filter_mac,
8242 static void vl_api_l2_fib_table_entry_t_handler_json
8243 (vl_api_l2_fib_table_entry_t * mp)
8245 vat_main_t * vam = &vat_main;
8246 vat_json_node_t *node = NULL;
8248 if (VAT_JSON_ARRAY != vam->json_tree.type) {
8249 ASSERT(VAT_JSON_NONE == vam->json_tree.type);
8250 vat_json_init_array(&vam->json_tree);
8252 node = vat_json_array_add(&vam->json_tree);
8254 vat_json_init_object(node);
8255 vat_json_object_add_uint(node, "bd_id", ntohl(mp->bd_id));
8256 vat_json_object_add_uint(node, "mac", clib_net_to_host_u64(mp->mac));
8257 vat_json_object_add_uint(node, "sw_if_index", ntohl(mp->sw_if_index));
8258 vat_json_object_add_uint(node, "static_mac", mp->static_mac);
8259 vat_json_object_add_uint(node, "filter_mac", mp->filter_mac);
8260 vat_json_object_add_uint(node, "bvi_mac", mp->bvi_mac);
8263 static int api_l2_fib_table_dump (vat_main_t * vam)
8265 unformat_input_t * i = vam->input;
8266 vl_api_l2_fib_table_dump_t *mp;
8271 /* Parse args required to build the message */
8272 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
8273 if (unformat (i, "bd_id %d", &bd_id))
8279 if (bd_id_set == 0) {
8280 errmsg ("missing bridge domain\n");
8284 fformat(vam->ofp, "BD-ID Mac Address sw-ndx Static Filter BVI\n");
8286 /* Get list of l2 fib entries */
8287 M(L2_FIB_TABLE_DUMP, l2_fib_table_dump);
8289 mp->bd_id = ntohl(bd_id);
8292 /* Use a control ping for synchronization */
8294 vl_api_control_ping_t * mp;
8295 M(CONTROL_PING, control_ping);
8303 api_interface_name_renumber (vat_main_t * vam)
8305 unformat_input_t * line_input = vam->input;
8306 vl_api_interface_name_renumber_t *mp;
8307 u32 sw_if_index = ~0;
8309 u32 new_show_dev_instance = ~0;
8311 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) {
8312 if (unformat (line_input, "%U", unformat_sw_if_index, vam,
8315 else if (unformat (line_input, "sw_if_index %d", &sw_if_index))
8317 else if (unformat (line_input, "new_show_dev_instance %d",
8318 &new_show_dev_instance))
8324 if (sw_if_index == ~0) {
8325 errmsg ("missing interface name or sw_if_index\n");
8329 if (new_show_dev_instance == ~0) {
8330 errmsg ("missing new_show_dev_instance\n");
8334 M(INTERFACE_NAME_RENUMBER, interface_name_renumber);
8336 mp->sw_if_index = ntohl (sw_if_index);
8337 mp->new_show_dev_instance = ntohl (new_show_dev_instance);
8343 api_want_ip4_arp_events (vat_main_t * vam)
8345 unformat_input_t * line_input = vam->input;
8346 vl_api_want_ip4_arp_events_t * mp;
8348 ip4_address_t address;
8349 int address_set = 0;
8350 u32 enable_disable = 1;
8352 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) {
8353 if (unformat (line_input, "address %U",
8354 unformat_ip4_address, &address))
8356 else if (unformat (line_input, "del"))
8362 if (address_set == 0) {
8363 errmsg ("missing addresses\n");
8367 M(WANT_IP4_ARP_EVENTS, want_ip4_arp_events);
8368 mp->enable_disable = enable_disable;
8370 mp->address = address.as_u32;
8375 static int api_input_acl_set_interface (vat_main_t * vam)
8377 unformat_input_t * i = vam->input;
8378 vl_api_input_acl_set_interface_t *mp;
8381 int sw_if_index_set;
8382 u32 ip4_table_index = ~0;
8383 u32 ip6_table_index = ~0;
8384 u32 l2_table_index = ~0;
8387 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
8388 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
8389 sw_if_index_set = 1;
8390 else if (unformat (i, "sw_if_index %d", &sw_if_index))
8391 sw_if_index_set = 1;
8392 else if (unformat (i, "del"))
8394 else if (unformat (i, "ip4-table %d", &ip4_table_index))
8396 else if (unformat (i, "ip6-table %d", &ip6_table_index))
8398 else if (unformat (i, "l2-table %d", &l2_table_index))
8401 clib_warning ("parse error '%U'", format_unformat_error, i);
8406 if (sw_if_index_set == 0) {
8407 errmsg ("missing interface name or sw_if_index\n");
8411 M(INPUT_ACL_SET_INTERFACE, input_acl_set_interface);
8413 mp->sw_if_index = ntohl(sw_if_index);
8414 mp->ip4_table_index = ntohl(ip4_table_index);
8415 mp->ip6_table_index = ntohl(ip6_table_index);
8416 mp->l2_table_index = ntohl(l2_table_index);
8417 mp->is_add = is_add;
8425 api_ip_address_dump (vat_main_t * vam)
8427 unformat_input_t * i = vam->input;
8428 vl_api_ip_address_dump_t * mp;
8429 u32 sw_if_index = ~0;
8430 u8 sw_if_index_set = 0;
8435 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
8436 if (unformat (i, "sw_if_index %d", &sw_if_index))
8437 sw_if_index_set = 1;
8438 else if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
8439 sw_if_index_set = 1;
8440 else if (unformat (i, "ipv4"))
8442 else if (unformat (i, "ipv6"))
8448 if (ipv4_set && ipv6_set) {
8449 errmsg ("ipv4 and ipv6 flags cannot be both set\n");
8453 if ((!ipv4_set) && (!ipv6_set)) {
8454 errmsg ("no ipv4 nor ipv6 flag set\n");
8458 if (sw_if_index_set == 0) {
8459 errmsg ("missing interface name or sw_if_index\n");
8463 vam->current_sw_if_index = sw_if_index;
8464 vam->is_ipv6 = ipv6_set;
8466 M(IP_ADDRESS_DUMP, ip_address_dump);
8467 mp->sw_if_index = ntohl(sw_if_index);
8468 mp->is_ipv6 = ipv6_set;
8471 /* Use a control ping for synchronization */
8473 vl_api_control_ping_t * mp;
8474 M(CONTROL_PING, control_ping);
8481 api_ip_dump (vat_main_t * vam)
8483 vl_api_ip_dump_t * mp;
8484 unformat_input_t * in = vam->input;
8491 while (unformat_check_input (in) != UNFORMAT_END_OF_INPUT) {
8492 if (unformat (in, "ipv4"))
8494 else if (unformat (in, "ipv6"))
8500 if (ipv4_set && ipv6_set) {
8501 errmsg ("ipv4 and ipv6 flags cannot be both set\n");
8505 if ((!ipv4_set) && (!ipv6_set)) {
8506 errmsg ("no ipv4 nor ipv6 flag set\n");
8511 vam->is_ipv6 = is_ipv6;
8514 for (i = 0; i < vec_len(vam->ip_details_by_sw_if_index[is_ipv6]); i++) {
8515 vec_free(vam->ip_details_by_sw_if_index[is_ipv6][i].addr);
8517 vec_free(vam->ip_details_by_sw_if_index[is_ipv6]);
8519 M(IP_DUMP, ip_dump);
8520 mp->is_ipv6 = ipv6_set;
8523 /* Use a control ping for synchronization */
8525 vl_api_control_ping_t * mp;
8526 M(CONTROL_PING, control_ping);
8533 api_ipsec_spd_add_del (vat_main_t * vam)
8536 unformat_input_t * i = vam->input;
8537 vl_api_ipsec_spd_add_del_t *mp;
8542 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
8543 if (unformat (i, "spd_id %d", &spd_id))
8545 else if (unformat (i, "del"))
8548 clib_warning ("parse error '%U'", format_unformat_error, i);
8553 errmsg ("spd_id must be set\n");
8557 M(IPSEC_SPD_ADD_DEL, ipsec_spd_add_del);
8559 mp->spd_id = ntohl(spd_id);
8560 mp->is_add = is_add;
8566 clib_warning ("unsupported (no dpdk)");
8572 api_ipsec_interface_add_del_spd (vat_main_t * vam)
8575 unformat_input_t * i = vam->input;
8576 vl_api_ipsec_interface_add_del_spd_t *mp;
8579 u8 sw_if_index_set = 0;
8580 u32 spd_id = (u32) ~0;
8583 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
8584 if (unformat (i, "del"))
8586 else if (unformat (i, "spd_id %d", &spd_id))
8588 else if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
8589 sw_if_index_set = 1;
8590 else if (unformat (i, "sw_if_index %d", &sw_if_index))
8591 sw_if_index_set = 1;
8593 clib_warning ("parse error '%U'", format_unformat_error, i);
8599 if (spd_id == (u32) ~0) {
8600 errmsg ("spd_id must be set\n");
8604 if (sw_if_index_set == 0) {
8605 errmsg ("missing interface name or sw_if_index\n");
8609 M(IPSEC_INTERFACE_ADD_DEL_SPD, ipsec_interface_add_del_spd);
8611 mp->spd_id = ntohl(spd_id);
8612 mp->sw_if_index = ntohl (sw_if_index);
8613 mp->is_add = is_add;
8619 clib_warning ("unsupported (no dpdk)");
8625 api_ipsec_spd_add_del_entry (vat_main_t * vam)
8628 unformat_input_t * i = vam->input;
8629 vl_api_ipsec_spd_add_del_entry_t *mp;
8631 u8 is_add = 1, is_outbound = 0, is_ipv6 = 0, is_ip_any = 1;
8632 u32 spd_id, sa_id, protocol = 0, policy = 0;
8634 u32 rport_start = 0, rport_stop = (u32) ~0;
8635 u32 lport_start = 0, lport_stop = (u32) ~0;
8636 ip4_address_t laddr4_start, laddr4_stop, raddr4_start, raddr4_stop;
8637 ip6_address_t laddr6_start, laddr6_stop, raddr6_start, raddr6_stop;
8639 laddr4_start.as_u32 = raddr4_start.as_u32 = 0;
8640 laddr4_stop.as_u32 = raddr4_stop.as_u32 = (u32) ~0;
8641 laddr6_start.as_u64[0] = raddr6_start.as_u64[0] = 0;
8642 laddr6_start.as_u64[1] = raddr6_start.as_u64[1] = 0;
8643 laddr6_stop.as_u64[0] = raddr6_stop.as_u64[0] = (u64) ~0;
8644 laddr6_stop.as_u64[1] = raddr6_stop.as_u64[1] = (u64) ~0;
8646 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
8647 if (unformat (i, "del"))
8649 if (unformat (i, "outbound"))
8651 if (unformat (i, "inbound"))
8653 else if (unformat (i, "spd_id %d", &spd_id))
8655 else if (unformat (i, "sa_id %d", &sa_id))
8657 else if (unformat (i, "priority %d", &priority))
8659 else if (unformat (i, "protocol %d", &protocol))
8661 else if (unformat (i, "lport_start %d", &lport_start))
8663 else if (unformat (i, "lport_stop %d", &lport_stop))
8665 else if (unformat (i, "rport_start %d", &rport_start))
8667 else if (unformat (i, "rport_stop %d", &rport_stop))
8669 else if (unformat (i, "laddr_start %U", unformat_ip4_address, &laddr4_start))
8674 else if (unformat (i, "laddr_stop %U", unformat_ip4_address, &laddr4_stop))
8679 else if (unformat (i, "raddr_start %U", unformat_ip4_address, &raddr4_start))
8684 else if (unformat (i, "raddr_stop %U", unformat_ip4_address, &raddr4_stop))
8689 else if (unformat (i, "laddr_start %U", unformat_ip6_address, &laddr6_start))
8694 else if (unformat (i, "laddr_stop %U", unformat_ip6_address, &laddr6_stop))
8699 else if (unformat (i, "raddr_start %U", unformat_ip6_address, &raddr6_start))
8704 else if (unformat (i, "raddr_stop %U", unformat_ip6_address, &raddr6_stop))
8709 else if (unformat (i, "action %U", unformat_ipsec_policy_action, &policy))
8711 if (policy == IPSEC_POLICY_ACTION_RESOLVE) {
8712 clib_warning ("unsupported action: 'resolve'");
8717 clib_warning ("parse error '%U'", format_unformat_error, i);
8723 M(IPSEC_SPD_ADD_DEL_ENTRY, ipsec_spd_add_del_entry);
8725 mp->spd_id = ntohl(spd_id);
8726 mp->priority = ntohl(priority);
8727 mp->is_outbound = is_outbound;
8729 mp->is_ipv6 = is_ipv6;
8730 if (is_ipv6 || is_ip_any) {
8731 clib_memcpy (mp->remote_address_start, &raddr6_start, sizeof(ip6_address_t));
8732 clib_memcpy (mp->remote_address_stop, &raddr6_stop, sizeof(ip6_address_t));
8733 clib_memcpy (mp->local_address_start, &laddr6_start, sizeof(ip6_address_t));
8734 clib_memcpy (mp->local_address_stop, &laddr6_stop, sizeof(ip6_address_t));
8736 clib_memcpy (mp->remote_address_start, &raddr4_start, sizeof(ip4_address_t));
8737 clib_memcpy (mp->remote_address_stop, &raddr4_stop, sizeof(ip4_address_t));
8738 clib_memcpy (mp->local_address_start, &laddr4_start, sizeof(ip4_address_t));
8739 clib_memcpy (mp->local_address_stop, &laddr4_stop, sizeof(ip4_address_t));
8741 mp->protocol = (u8) protocol;
8742 mp->local_port_start = ntohs((u16) lport_start);
8743 mp->local_port_stop = ntohs((u16) lport_stop);
8744 mp->remote_port_start = ntohs((u16) rport_start);
8745 mp->remote_port_stop = ntohs((u16) rport_stop);
8746 mp->policy = (u8) policy;
8747 mp->sa_id = ntohl(sa_id);
8748 mp->is_add = is_add;
8749 mp->is_ip_any = is_ip_any;
8754 clib_warning ("unsupported (no dpdk)");
8760 api_ipsec_sad_add_del_entry (vat_main_t * vam)
8763 unformat_input_t * i = vam->input;
8764 vl_api_ipsec_sad_add_del_entry_t *mp;
8770 u8 protocol = IPSEC_PROTOCOL_AH;
8771 u8 is_tunnel = 0, is_tunnel_ipv6 = 0;
8772 u32 crypto_alg = 0, integ_alg = 0;
8773 ip4_address_t tun_src4;
8774 ip4_address_t tun_dst4;
8775 ip6_address_t tun_src6;
8776 ip6_address_t tun_dst6;
8778 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
8779 if (unformat (i, "del"))
8781 else if (unformat (i, "sad_id %d", &sad_id))
8783 else if (unformat (i, "spi %d", &spi))
8785 else if (unformat (i, "esp"))
8786 protocol = IPSEC_PROTOCOL_ESP;
8787 else if (unformat (i, "tunnel_src %U", unformat_ip4_address, &tun_src4)) {
8791 else if (unformat (i, "tunnel_dst %U", unformat_ip4_address, &tun_dst4)) {
8795 else if (unformat (i, "tunnel_src %U", unformat_ip6_address, &tun_src6)) {
8799 else if (unformat (i, "tunnel_dst %U", unformat_ip6_address, &tun_dst6)) {
8803 else if (unformat (i, "crypto_alg %U", unformat_ipsec_crypto_alg, &crypto_alg)) {
8804 if (crypto_alg < IPSEC_CRYPTO_ALG_AES_CBC_128 ||
8805 crypto_alg > IPSEC_INTEG_ALG_SHA_512_256) {
8806 clib_warning ("unsupported crypto-alg: '%U'",
8807 format_ipsec_crypto_alg, crypto_alg);
8811 else if (unformat (i, "crypto_key %U", unformat_hex_string, &ck))
8813 else if (unformat (i, "integ_alg %U", unformat_ipsec_integ_alg, &integ_alg)) {
8814 if (integ_alg < IPSEC_INTEG_ALG_SHA1_96 ||
8815 integ_alg > IPSEC_INTEG_ALG_SHA_512_256) {
8816 clib_warning ("unsupported integ-alg: '%U'",
8817 format_ipsec_integ_alg, integ_alg);
8821 else if (unformat (i, "integ_key %U", unformat_hex_string, &ik))
8824 clib_warning ("parse error '%U'", format_unformat_error, i);
8830 M(IPSEC_SAD_ADD_DEL_ENTRY, ipsec_sad_add_del_entry);
8832 mp->sad_id = ntohl(sad_id);
8833 mp->is_add = is_add;
8834 mp->protocol = protocol;
8835 mp->spi = ntohl(spi);
8836 mp->is_tunnel = is_tunnel;
8837 mp->is_tunnel_ipv6 = is_tunnel_ipv6;
8838 mp->crypto_algorithm = crypto_alg;
8839 mp->integrity_algorithm = integ_alg;
8840 mp->crypto_key_length = vec_len(ck);
8841 mp->integrity_key_length = vec_len(ik);
8843 if (mp->crypto_key_length > sizeof(mp->crypto_key))
8844 mp->crypto_key_length = sizeof(mp->crypto_key);
8846 if (mp->integrity_key_length > sizeof(mp->integrity_key))
8847 mp->integrity_key_length = sizeof(mp->integrity_key);
8849 clib_memcpy (mp->crypto_key, ck, mp->crypto_key_length);
8850 clib_memcpy (mp->integrity_key, ik, mp->integrity_key_length);
8853 if (is_tunnel_ipv6) {
8854 clib_memcpy (mp->tunnel_src_address, &tun_src6, sizeof(ip6_address_t));
8855 clib_memcpy (mp->tunnel_dst_address, &tun_dst6, sizeof(ip6_address_t));
8857 clib_memcpy (mp->tunnel_src_address, &tun_src4, sizeof(ip4_address_t));
8858 clib_memcpy (mp->tunnel_dst_address, &tun_dst4, sizeof(ip4_address_t));
8866 clib_warning ("unsupported (no dpdk)");
8872 api_ipsec_sa_set_key (vat_main_t * vam)
8875 unformat_input_t * i = vam->input;
8876 vl_api_ipsec_sa_set_key_t *mp;
8881 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
8882 if (unformat (i, "sa_id %d", &sa_id))
8884 else if (unformat (i, "crypto_key %U", unformat_hex_string, &ck))
8886 else if (unformat (i, "integ_key %U", unformat_hex_string, &ik))
8889 clib_warning ("parse error '%U'", format_unformat_error, i);
8894 M(IPSEC_SA_SET_KEY, ipsec_set_sa_key);
8896 mp->sa_id = ntohl(sa_id);
8897 mp->crypto_key_length = vec_len(ck);
8898 mp->integrity_key_length = vec_len(ik);
8900 if (mp->crypto_key_length > sizeof(mp->crypto_key))
8901 mp->crypto_key_length = sizeof(mp->crypto_key);
8903 if (mp->integrity_key_length > sizeof(mp->integrity_key))
8904 mp->integrity_key_length = sizeof(mp->integrity_key);
8906 clib_memcpy (mp->crypto_key, ck, mp->crypto_key_length);
8907 clib_memcpy (mp->integrity_key, ik, mp->integrity_key_length);
8913 clib_warning ("unsupported (no dpdk)");
8919 api_ikev2_profile_add_del (vat_main_t * vam)
8922 unformat_input_t * i = vam->input;
8923 vl_api_ikev2_profile_add_del_t * mp;
8928 const char * valid_chars = "a-zA-Z0-9_";
8930 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
8931 if (unformat (i, "del"))
8933 else if (unformat (i, "name %U", unformat_token, valid_chars, &name))
8936 errmsg ("parse error '%U'", format_unformat_error, i);
8941 if (!vec_len (name)) {
8942 errmsg ("profile name must be specified");
8946 if (vec_len (name) > 64) {
8947 errmsg ("profile name too long");
8951 M(IKEV2_PROFILE_ADD_DEL, ikev2_profile_add_del);
8953 clib_memcpy(mp->name, name, vec_len (name));
8954 mp->is_add = is_add;
8961 clib_warning ("unsupported (no dpdk)");
8967 api_ikev2_profile_set_auth (vat_main_t * vam)
8970 unformat_input_t * i = vam->input;
8971 vl_api_ikev2_profile_set_auth_t * mp;
8975 u32 auth_method = 0;
8978 const char * valid_chars = "a-zA-Z0-9_";
8980 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
8981 if (unformat (i, "name %U", unformat_token, valid_chars, &name))
8983 else if (unformat (i, "auth_method %U",
8984 unformat_ikev2_auth_method, &auth_method))
8986 else if (unformat (i, "auth_data 0x%U", unformat_hex_string, &data))
8988 else if (unformat (i, "auth_data %v", &data))
8991 errmsg ("parse error '%U'", format_unformat_error, i);
8996 if (!vec_len (name)) {
8997 errmsg ("profile name must be specified");
9001 if (vec_len (name) > 64) {
9002 errmsg ("profile name too long");
9006 if (!vec_len(data)) {
9007 errmsg ("auth_data must be specified");
9012 errmsg ("auth_method must be specified");
9016 M(IKEV2_PROFILE_SET_AUTH, ikev2_profile_set_auth);
9018 mp->is_hex = is_hex;
9019 mp->auth_method = (u8) auth_method;
9020 mp->data_len = vec_len (data);
9021 clib_memcpy (mp->name, name, vec_len (name));
9022 clib_memcpy (mp->data, data, vec_len (data));
9030 clib_warning ("unsupported (no dpdk)");
9036 api_ikev2_profile_set_id (vat_main_t * vam)
9039 unformat_input_t * i = vam->input;
9040 vl_api_ikev2_profile_set_id_t * mp;
9048 const char * valid_chars = "a-zA-Z0-9_";
9050 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
9051 if (unformat (i, "name %U", unformat_token, valid_chars, &name))
9053 else if (unformat (i, "id_type %U",
9054 unformat_ikev2_id_type, &id_type))
9056 else if (unformat (i, "id_data %U", unformat_ip4_address, &ip4))
9058 data = vec_new(u8, 4);
9059 clib_memcpy(data, ip4.as_u8, 4);
9061 else if (unformat (i, "id_data 0x%U", unformat_hex_string, &data))
9063 else if (unformat (i, "id_data %v", &data))
9065 else if (unformat (i, "local"))
9067 else if (unformat (i, "remote"))
9070 errmsg ("parse error '%U'", format_unformat_error, i);
9075 if (!vec_len (name)) {
9076 errmsg ("profile name must be specified");
9080 if (vec_len (name) > 64) {
9081 errmsg ("profile name too long");
9085 if (!vec_len(data)) {
9086 errmsg ("id_data must be specified");
9091 errmsg ("id_type must be specified");
9095 M(IKEV2_PROFILE_SET_ID, ikev2_profile_set_id);
9097 mp->is_local = is_local;
9098 mp->id_type = (u8) id_type;
9099 mp->data_len = vec_len (data);
9100 clib_memcpy (mp->name, name, vec_len (name));
9101 clib_memcpy (mp->data, data, vec_len (data));
9109 clib_warning ("unsupported (no dpdk)");
9115 api_ikev2_profile_set_ts (vat_main_t * vam)
9118 unformat_input_t * i = vam->input;
9119 vl_api_ikev2_profile_set_ts_t * mp;
9123 u32 proto = 0, start_port = 0, end_port = (u32) ~0;
9124 ip4_address_t start_addr, end_addr;
9126 const char * valid_chars = "a-zA-Z0-9_";
9128 start_addr.as_u32 = 0;
9129 end_addr.as_u32 = (u32) ~0;
9131 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
9132 if (unformat (i, "name %U", unformat_token, valid_chars, &name))
9134 else if (unformat (i, "protocol %d", &proto))
9136 else if (unformat (i, "start_port %d", &start_port))
9138 else if (unformat (i, "end_port %d", &end_port))
9140 else if (unformat (i, "start_addr %U", unformat_ip4_address, &start_addr))
9142 else if (unformat (i, "end_addr %U", unformat_ip4_address, &end_addr))
9144 else if (unformat (i, "local"))
9146 else if (unformat (i, "remote"))
9149 errmsg ("parse error '%U'", format_unformat_error, i);
9154 if (!vec_len (name)) {
9155 errmsg ("profile name must be specified");
9159 if (vec_len (name) > 64) {
9160 errmsg ("profile name too long");
9164 M(IKEV2_PROFILE_SET_TS, ikev2_profile_set_ts);
9166 mp->is_local = is_local;
9167 mp->proto = (u8) proto;
9168 mp->start_port = (u16) start_port;
9169 mp->end_port = (u16) end_port;
9170 mp->start_addr = start_addr.as_u32;
9171 mp->end_addr = end_addr.as_u32;
9172 clib_memcpy (mp->name, name, vec_len (name));
9179 clib_warning ("unsupported (no dpdk)");
9185 api_ikev2_set_local_key (vat_main_t * vam)
9188 unformat_input_t * i = vam->input;
9189 vl_api_ikev2_set_local_key_t * mp;
9193 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
9194 if (unformat (i, "file %v", &file))
9197 errmsg ("parse error '%U'", format_unformat_error, i);
9202 if (!vec_len (file)) {
9203 errmsg ("RSA key file must be specified");
9207 if (vec_len (file) > 256) {
9208 errmsg ("file name too long");
9212 M(IKEV2_SET_LOCAL_KEY, ikev2_set_local_key);
9214 clib_memcpy (mp->key_file, file, vec_len (file));
9221 clib_warning ("unsupported (no dpdk)");
9229 static int api_map_add_domain (vat_main_t * vam)
9231 unformat_input_t *i = vam->input;
9232 vl_api_map_add_domain_t *mp;
9235 ip4_address_t ip4_prefix;
9236 ip6_address_t ip6_prefix;
9237 ip6_address_t ip6_src;
9239 u32 ip6_prefix_len, ip4_prefix_len, ea_bits_len, psid_offset,
9241 u8 is_translation = 0;
9243 u8 ip6_src_len = 128;
9245 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
9246 if (unformat (i, "ip4-pfx %U/%d", unformat_ip4_address,
9247 &ip4_prefix, &ip4_prefix_len))
9249 else if (unformat (i, "ip6-pfx %U/%d", unformat_ip6_address,
9250 &ip6_prefix, &ip6_prefix_len))
9252 else if (unformat (i, "ip6-src %U/%d", unformat_ip6_address, &ip6_src, &ip6_src_len))
9254 else if (unformat (i, "ip6-src %U", unformat_ip6_address, &ip6_src))
9256 else if (unformat (i, "ea-bits-len %d", &ea_bits_len))
9258 else if (unformat (i, "psid-offset %d", &psid_offset))
9260 else if (unformat (i, "psid-len %d", &psid_length))
9262 else if (unformat (i, "mtu %d", &mtu))
9264 else if (unformat (i, "map-t"))
9267 clib_warning ("parse error '%U'", format_unformat_error, i);
9272 if (num_m_args != 6) {
9273 errmsg("mandatory argument(s) missing\n");
9277 /* Construct the API message */
9278 M(MAP_ADD_DOMAIN, map_add_domain);
9280 clib_memcpy(mp->ip4_prefix, &ip4_prefix, sizeof(ip4_prefix));
9281 mp->ip4_prefix_len = ip4_prefix_len;
9283 clib_memcpy(mp->ip6_prefix, &ip6_prefix, sizeof(ip6_prefix));
9284 mp->ip6_prefix_len = ip6_prefix_len;
9286 clib_memcpy(mp->ip6_src, &ip6_src, sizeof(ip6_src));
9287 mp->ip6_src_prefix_len = ip6_src_len;
9289 mp->ea_bits_len = ea_bits_len;
9290 mp->psid_offset = psid_offset;
9291 mp->psid_length = psid_length;
9292 mp->is_translation = is_translation;
9293 mp->mtu = htons(mtu);
9298 /* Wait for a reply, return good/bad news */
9302 static int api_map_del_domain (vat_main_t * vam)
9304 unformat_input_t *i = vam->input;
9305 vl_api_map_del_domain_t *mp;
9311 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
9312 if (unformat (i, "index %d", &index))
9315 clib_warning ("parse error '%U'", format_unformat_error, i);
9320 if (num_m_args != 1) {
9321 errmsg("mandatory argument(s) missing\n");
9325 /* Construct the API message */
9326 M(MAP_DEL_DOMAIN, map_del_domain);
9328 mp->index = ntohl(index);
9333 /* Wait for a reply, return good/bad news */
9337 static int api_map_add_del_rule (vat_main_t * vam)
9339 unformat_input_t *i = vam->input;
9340 vl_api_map_add_del_rule_t *mp;
9343 ip6_address_t ip6_dst;
9344 u32 num_m_args = 0, index, psid;
9346 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
9347 if (unformat (i, "index %d", &index))
9349 else if (unformat (i, "psid %d", &psid))
9351 else if (unformat (i, "dst %U", unformat_ip6_address, &ip6_dst))
9353 else if (unformat (i, "del")) {
9356 clib_warning ("parse error '%U'", format_unformat_error, i);
9361 /* Construct the API message */
9362 M(MAP_ADD_DEL_RULE, map_add_del_rule);
9364 mp->index = ntohl(index);
9365 mp->is_add = is_add;
9366 clib_memcpy(mp->ip6_dst, &ip6_dst, sizeof(ip6_dst));
9367 mp->psid = ntohs(psid);
9372 /* Wait for a reply, return good/bad news */
9376 static int api_map_domain_dump (vat_main_t * vam)
9378 vl_api_map_domain_dump_t *mp;
9381 /* Construct the API message */
9382 M(MAP_DOMAIN_DUMP, map_domain_dump);
9387 /* Use a control ping for synchronization */
9389 vl_api_control_ping_t * mp;
9390 M(CONTROL_PING, control_ping);
9396 static int api_map_rule_dump (vat_main_t * vam)
9398 unformat_input_t *i = vam->input;
9399 vl_api_map_rule_dump_t *mp;
9401 u32 domain_index = ~0;
9403 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
9404 if (unformat (i, "index %u", &domain_index))
9410 if (domain_index == ~0) {
9411 clib_warning("parse error: domain index expected");
9415 /* Construct the API message */
9416 M(MAP_RULE_DUMP, map_rule_dump);
9418 mp->domain_index = htonl(domain_index);
9423 /* Use a control ping for synchronization */
9425 vl_api_control_ping_t * mp;
9426 M(CONTROL_PING, control_ping);
9432 static void vl_api_map_add_domain_reply_t_handler
9433 (vl_api_map_add_domain_reply_t * mp)
9435 vat_main_t * vam = &vat_main;
9436 i32 retval = ntohl(mp->retval);
9438 if (vam->async_mode) {
9439 vam->async_errors += (retval < 0);
9441 vam->retval = retval;
9442 vam->result_ready = 1;
9446 static void vl_api_map_add_domain_reply_t_handler_json
9447 (vl_api_map_add_domain_reply_t * mp)
9449 vat_main_t * vam = &vat_main;
9450 vat_json_node_t node;
9452 vat_json_init_object(&node);
9453 vat_json_object_add_int(&node, "retval", ntohl(mp->retval));
9454 vat_json_object_add_uint(&node, "index", ntohl(mp->index));
9456 vat_json_print(vam->ofp, &node);
9457 vat_json_free(&node);
9459 vam->retval = ntohl(mp->retval);
9460 vam->result_ready = 1;
9464 api_get_first_msg_id (vat_main_t * vam)
9466 vl_api_get_first_msg_id_t * mp;
9468 unformat_input_t * i = vam->input;
9472 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
9473 if (unformat (i, "client %s", &name))
9479 if (name_set == 0) {
9480 errmsg ("missing client name\n");
9485 if (vec_len (name) > 63) {
9486 errmsg ("client name too long\n");
9490 M(GET_FIRST_MSG_ID, get_first_msg_id);
9491 clib_memcpy (mp->name, name, vec_len(name));
9497 static int api_cop_interface_enable_disable (vat_main_t * vam)
9499 unformat_input_t * line_input = vam->input;
9500 vl_api_cop_interface_enable_disable_t * mp;
9502 u32 sw_if_index = ~0;
9503 u8 enable_disable = 1;
9505 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) {
9506 if (unformat (line_input, "disable"))
9508 if (unformat (line_input, "enable"))
9510 else if (unformat (line_input, "%U", unformat_sw_if_index,
9513 else if (unformat (line_input, "sw_if_index %d", &sw_if_index))
9519 if (sw_if_index == ~0) {
9520 errmsg ("missing interface name or sw_if_index\n");
9524 /* Construct the API message */
9525 M(COP_INTERFACE_ENABLE_DISABLE, cop_interface_enable_disable);
9526 mp->sw_if_index = ntohl(sw_if_index);
9527 mp->enable_disable = enable_disable;
9531 /* Wait for the reply */
9535 static int api_cop_whitelist_enable_disable (vat_main_t * vam)
9537 unformat_input_t * line_input = vam->input;
9538 vl_api_cop_whitelist_enable_disable_t * mp;
9540 u32 sw_if_index = ~0;
9541 u8 ip4=0, ip6=0, default_cop=0;
9544 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) {
9545 if (unformat (line_input, "ip4"))
9547 else if (unformat (line_input, "ip6"))
9549 else if (unformat (line_input, "default"))
9551 else if (unformat (line_input, "%U", unformat_sw_if_index,
9554 else if (unformat (line_input, "sw_if_index %d", &sw_if_index))
9556 else if (unformat (line_input, "fib-id %d", &fib_id))
9562 if (sw_if_index == ~0) {
9563 errmsg ("missing interface name or sw_if_index\n");
9567 /* Construct the API message */
9568 M(COP_WHITELIST_ENABLE_DISABLE, cop_whitelist_enable_disable);
9569 mp->sw_if_index = ntohl(sw_if_index);
9570 mp->fib_id = ntohl(fib_id);
9573 mp->default_cop = default_cop;
9577 /* Wait for the reply */
9581 static int api_get_node_graph (vat_main_t * vam)
9583 vl_api_get_node_graph_t * mp;
9586 M(GET_NODE_GRAPH, get_node_graph);
9590 /* Wait for the reply */
9595 api_lisp_add_del_locator_set(vat_main_t * vam)
9597 unformat_input_t * input = vam->input;
9598 vl_api_lisp_add_del_locator_set_t *mp;
9601 u8 *locator_set_name = NULL;
9602 u8 locator_set_name_set = 0;
9604 /* Parse args required to build the message */
9605 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) {
9606 if (unformat(input, "del")) {
9608 } else if (unformat(input, "locator-set %s", &locator_set_name)) {
9609 locator_set_name_set = 1;
9614 if (locator_set_name_set == 0) {
9615 errmsg ("missing locator-set name");
9619 if (vec_len(locator_set_name) > 64) {
9620 errmsg ("locator-set name too long\n");
9621 vec_free(locator_set_name);
9624 vec_add1(locator_set_name, 0);
9626 /* Construct the API message */
9627 M(LISP_ADD_DEL_LOCATOR_SET, lisp_add_del_locator_set);
9629 mp->is_add = is_add;
9630 clib_memcpy(mp->locator_set_name, locator_set_name,
9631 vec_len(locator_set_name));
9632 vec_free(locator_set_name);
9637 /* Wait for a reply... */
9645 api_lisp_add_del_locator(vat_main_t * vam)
9647 unformat_input_t * input = vam->input;
9648 vl_api_lisp_add_del_locator_t *mp;
9650 u32 tmp_if_index = ~0;
9651 u32 sw_if_index = ~0;
9652 u8 sw_if_index_set = 0;
9653 u8 sw_if_index_if_name_set = 0;
9655 u8 priority_set = 0;
9659 u8 *locator_set_name = NULL;
9660 u8 locator_set_name_set = 0;
9662 /* Parse args required to build the message */
9663 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) {
9664 if (unformat(input, "del")) {
9666 } else if (unformat(input, "locator-set %s", &locator_set_name)) {
9667 locator_set_name_set = 1;
9668 } else if (unformat(input, "iface %U", unformat_sw_if_index, vam,
9670 sw_if_index_if_name_set = 1;
9671 sw_if_index = tmp_if_index;
9672 } else if (unformat(input,"sw_if_index %d", &tmp_if_index)) {
9673 sw_if_index_set = 1;
9674 sw_if_index = tmp_if_index;
9675 } else if (unformat(input, "p %d", &priority)) {
9677 } else if (unformat(input, "w %d", &weight)) {
9683 if (locator_set_name_set == 0) {
9684 errmsg ("missing locator-set name");
9688 if (sw_if_index_set == 0 && sw_if_index_if_name_set == 0) {
9689 errmsg ("missing sw_if_index");
9690 vec_free(locator_set_name);
9694 if (sw_if_index_set != 0 && sw_if_index_if_name_set != 0) {
9695 errmsg ("cannot use both params interface name and sw_if_index");
9696 vec_free(locator_set_name);
9700 if (priority_set == 0) {
9701 errmsg ("missing locator-set priority\n");
9702 vec_free(locator_set_name);
9706 if (weight_set == 0) {
9707 errmsg ("missing locator-set weight\n");
9708 vec_free(locator_set_name);
9712 if (vec_len(locator_set_name) > 64) {
9713 errmsg ("locator-set name too long\n");
9714 vec_free(locator_set_name);
9717 vec_add1(locator_set_name, 0);
9719 /* Construct the API message */
9720 M(LISP_ADD_DEL_LOCATOR, lisp_add_del_locator);
9722 mp->is_add = is_add;
9723 mp->sw_if_index = ntohl(sw_if_index);
9724 mp->priority = priority;
9725 mp->weight = weight;
9726 clib_memcpy(mp->locator_set_name, locator_set_name,
9727 vec_len(locator_set_name));
9728 vec_free(locator_set_name);
9733 /* Wait for a reply... */
9741 api_lisp_add_del_local_eid(vat_main_t * vam)
9743 unformat_input_t * input = vam->input;
9744 vl_api_lisp_add_del_local_eid_t *mp;
9749 ip4_address_t eidv4;
9750 ip6_address_t eidv6;
9751 u8 tmp_eid_lenght = ~0;
9753 u8 *locator_set_name = NULL;
9754 u8 locator_set_name_set = 0;
9756 /* Parse args required to build the message */
9757 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) {
9758 if (unformat(input, "del")) {
9760 } else if (unformat(input, "eid %U/%d", unformat_ip4_address,
9761 &eidv4, &tmp_eid_lenght)) {
9762 eid_lenght = tmp_eid_lenght;
9764 } else if (unformat(input, "eid %U/%d", unformat_ip6_address,
9765 &eidv6, &tmp_eid_lenght)) {
9766 eid_lenght = tmp_eid_lenght;
9768 } else if (unformat(input, "locator-set %s", &locator_set_name)) {
9769 locator_set_name_set = 1;
9774 if (locator_set_name_set == 0) {
9775 errmsg ("missing locator-set name\n");
9779 if (vec_len(locator_set_name) > 64) {
9780 errmsg ("locator-set name too long\n");
9781 vec_free(locator_set_name);
9784 vec_add1(locator_set_name, 0);
9786 if (eidv4_set && eidv6_set) {
9787 errmsg ("both eid v4 and v6 addresses set\n");
9788 vec_free(locator_set_name);
9792 if (!eidv4_set && !eidv6_set) {
9793 errmsg ("eid addresses not set\n");
9794 vec_free(locator_set_name);
9798 /* Construct the API message */
9799 M(LISP_ADD_DEL_LOCAL_EID, lisp_add_del_local_eid);
9801 mp->is_add = is_add;
9804 clib_memcpy(mp->ip_address, &eidv6, sizeof(eidv6));
9807 clib_memcpy(mp->ip_address, &eidv4, sizeof(eidv4));
9809 mp->prefix_len = eid_lenght;
9810 clib_memcpy(mp->locator_set_name, locator_set_name,
9811 vec_len(locator_set_name));
9812 vec_free(locator_set_name);
9817 /* Wait for a reply... */
9825 api_lisp_gpe_add_del_fwd_entry(vat_main_t * vam)
9827 unformat_input_t * input = vam->input;
9828 vl_api_lisp_gpe_add_del_fwd_entry_t *mp;
9831 u8 eidv4_set = 0, slocv4_set = 0, dlocv4_set = 0;
9832 u8 eidv6_set = 0, slocv6_set = 0, dlocv6_set = 0;
9833 ip4_address_t eidv4, slocv4, dlocv4;
9834 ip6_address_t eidv6, slocv6, dlocv6;
9835 u8 tmp_eid_lenght = ~0;
9838 /* Parse args required to build the message */
9839 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) {
9840 if (unformat(input, "del")) {
9842 } else if (unformat(input, "eid %U/%d", unformat_ip4_address,
9843 &eidv4, &tmp_eid_lenght)) {
9844 eid_lenght = tmp_eid_lenght;
9846 } else if (unformat(input, "eid %U/%d", unformat_ip6_address,
9847 &eidv6, &tmp_eid_lenght)) {
9848 eid_lenght = tmp_eid_lenght;
9850 } else if (unformat(input, "sloc %U", unformat_ip4_address, &slocv4)) {
9852 } else if (unformat(input, "sloc %U", unformat_ip6_address, &slocv6)) {
9854 } else if (unformat(input, "dloc %U", unformat_ip4_address, &dlocv4)) {
9856 } else if (unformat(input, "dloc %U", unformat_ip6_address, &dlocv6)) {
9862 if (eidv4_set && eidv6_set) {
9863 errmsg ("both eid v4 and v6 addresses set\n");
9867 if (!eidv4_set && !eidv6_set) {
9868 errmsg ("eid addresses not set\n");
9872 if (slocv4_set && slocv6_set) {
9873 errmsg ("both source v4 and v6 addresses set\n");
9877 if (!slocv4_set && !slocv6_set) {
9878 errmsg ("source addresses not set\n");
9882 if (dlocv4_set && dlocv6_set) {
9883 errmsg ("both destination v4 and v6 addresses set\n");
9887 if (dlocv4_set && dlocv6_set) {
9888 errmsg ("destination addresses not set\n");
9892 if (!(slocv4_set == dlocv4_set && slocv6_set == dlocv6_set)) {
9893 errmsg ("mixing type of source and destination address\n");
9897 /* Construct the API message */
9898 M(LISP_GPE_ADD_DEL_FWD_ENTRY, lisp_gpe_add_del_fwd_entry);
9900 mp->is_add = is_add;
9902 mp->eid_is_ipv6 = 1;
9903 clib_memcpy(mp->eid_ip_address, &eidv6, sizeof(eidv6));
9905 mp->eid_is_ipv6 = 0;
9906 clib_memcpy(mp->eid_ip_address, &eidv4, sizeof(eidv4));
9908 mp->eid_prefix_len = eid_lenght;
9910 mp->address_is_ipv6 = 1;
9911 clib_memcpy(mp->source_ip_address, &slocv6, sizeof(slocv6));
9912 clib_memcpy(mp->destination_ip_address, &dlocv6, sizeof(dlocv6));
9914 mp->address_is_ipv6 = 0;
9915 clib_memcpy(mp->source_ip_address, &slocv4, sizeof(slocv4));
9916 clib_memcpy(mp->destination_ip_address, &dlocv4, sizeof(dlocv4));
9922 /* Wait for a reply... */
9930 api_lisp_add_del_map_resolver(vat_main_t * vam)
9932 unformat_input_t * input = vam->input;
9933 vl_api_lisp_add_del_map_resolver_t *mp;
9941 /* Parse args required to build the message */
9942 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) {
9943 if (unformat(input, "del")) {
9945 } else if (unformat(input, "%U", unformat_ip4_address, &ipv4)) {
9947 } else if (unformat(input, "%U", unformat_ip6_address, &ipv6)) {
9953 if (ipv4_set && ipv6_set) {
9954 errmsg ("both eid v4 and v6 addresses set\n");
9958 if (!ipv4_set && !ipv6_set) {
9959 errmsg ("eid addresses not set\n");
9963 /* Construct the API message */
9964 M(LISP_ADD_DEL_MAP_RESOLVER, lisp_add_del_map_resolver);
9966 mp->is_add = is_add;
9969 clib_memcpy(mp->ip_address, &ipv6, sizeof(ipv6));
9972 clib_memcpy(mp->ip_address, &ipv4, sizeof(ipv4));
9978 /* Wait for a reply... */
9986 api_lisp_gpe_enable_disable (vat_main_t * vam)
9988 unformat_input_t * input = vam->input;
9989 vl_api_lisp_gpe_enable_disable_t *mp;
9994 /* Parse args required to build the message */
9995 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) {
9996 if (unformat(input, "enable")) {
9999 } else if (unformat(input, "disable")) {
10007 errmsg("Value not set\n");
10011 /* Construct the API message */
10012 M(LISP_GPE_ENABLE_DISABLE, lisp_gpe_enable_disable);
10019 /* Wait for a reply... */
10027 api_lisp_enable_disable (vat_main_t * vam)
10029 unformat_input_t * input = vam->input;
10030 vl_api_lisp_enable_disable_t *mp;
10035 /* Parse args required to build the message */
10036 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
10038 if (unformat (input, "enable"))
10043 else if (unformat (input, "disable"))
10053 errmsg ("Value not set\n");
10057 /* Construct the API message */
10058 M(LISP_ENABLE_DISABLE, lisp_enable_disable);
10065 /* Wait for a reply... */
10073 api_lisp_gpe_add_del_iface(vat_main_t * vam)
10075 unformat_input_t * input = vam->input;
10076 vl_api_lisp_gpe_add_del_iface_t *mp;
10082 /* Parse args required to build the message */
10083 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) {
10084 if (unformat(input, "up")) {
10087 } else if (unformat(input, "down")) {
10090 } else if (unformat(input, "table_id %d", &table_id)) {
10092 } else if (unformat(input, "vni %d", &vni)) {
10099 errmsg("Value not set\n");
10103 /* Construct the API message */
10104 M(LISP_GPE_ADD_DEL_IFACE, lisp_gpe_add_del_iface);
10106 mp->is_add = is_add;
10107 mp->table_id = table_id;
10113 /* Wait for a reply... */
10121 api_lisp_locator_set_dump(vat_main_t *vam)
10123 vl_api_lisp_locator_set_dump_t *mp;
10126 if (!vam->json_output) {
10127 fformat(vam->ofp, "%=20s%=16s%=16s%=16s\n",
10128 "Locator-set", "Locator", "Priority", "Weight");
10131 M(LISP_LOCATOR_SET_DUMP, lisp_locator_set_dump);
10135 /* Use a control ping for synchronization */
10137 vl_api_control_ping_t * mp;
10138 M(CONTROL_PING, control_ping);
10141 /* Wait for a reply... */
10149 api_lisp_local_eid_table_dump(vat_main_t *vam)
10151 vl_api_lisp_local_eid_table_dump_t *mp;
10154 if (!vam->json_output) {
10155 fformat(vam->ofp, "%=20s%=30s\n",
10156 "Locator-set", "Eid");
10159 M(LISP_LOCAL_EID_TABLE_DUMP, lisp_local_eid_table_dump);
10163 /* Use a control ping for synchronization */
10165 vl_api_control_ping_t * mp;
10166 M(CONTROL_PING, control_ping);
10169 /* Wait for a reply... */
10177 api_lisp_gpe_tunnel_dump(vat_main_t *vam)
10179 vl_api_lisp_gpe_tunnel_dump_t *mp;
10182 if (!vam->json_output) {
10183 fformat(vam->ofp, "%=20s%=30s%=16s%=16s%=16s%=16s"
10184 "%=16s%=16s%=16s%=16s%=16s\n",
10185 "Tunel", "Source", "Destination", "Fib encap", "Fib decap",
10186 "Decap next", "Lisp version", "Flags", "Next protocol",
10187 "ver_res", "res", "iid");
10190 M(LISP_GPE_TUNNEL_DUMP, lisp_gpe_tunnel_dump);
10194 /* Use a control ping for synchronization */
10196 vl_api_control_ping_t * mp;
10197 M(CONTROL_PING, control_ping);
10200 /* Wait for a reply... */
10208 api_lisp_map_resolver_dump(vat_main_t *vam)
10210 vl_api_lisp_map_resolver_dump_t *mp;
10213 if (!vam->json_output) {
10214 fformat(vam->ofp, "%=20s\n",
10218 M(LISP_MAP_RESOLVER_DUMP, lisp_map_resolver_dump);
10222 /* Use a control ping for synchronization */
10224 vl_api_control_ping_t * mp;
10225 M(CONTROL_PING, control_ping);
10228 /* Wait for a reply... */
10236 api_lisp_enable_disable_status_dump(vat_main_t *vam)
10238 vl_api_lisp_enable_disable_status_dump_t *mp;
10241 if (!vam->json_output) {
10242 fformat(vam->ofp, "%=20s\n",
10246 M(LISP_ENABLE_DISABLE_STATUS_DUMP,
10247 lisp_enable_disable_status_dump);
10251 /* Use a control ping for synchronization */
10253 vl_api_control_ping_t * mp;
10254 M(CONTROL_PING, control_ping);
10257 /* Wait for a reply... */
10265 api_af_packet_create (vat_main_t * vam)
10267 unformat_input_t * i = vam->input;
10268 vl_api_af_packet_create_t * mp;
10270 u8 * host_if_name = 0;
10272 u8 random_hw_addr = 1;
10274 memset (hw_addr, 0, sizeof (hw_addr));
10276 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
10277 if (unformat (i, "name %s", &host_if_name))
10278 vec_add1 (host_if_name, 0);
10279 else if (unformat (i, "hw_addr %U", unformat_ethernet_address, hw_addr))
10280 random_hw_addr = 0;
10285 if (!vec_len (host_if_name)) {
10286 errmsg ("host-interface name must be specified");
10290 if (vec_len (host_if_name) > 64) {
10291 errmsg ("host-interface name too long");
10295 M(AF_PACKET_CREATE, af_packet_create);
10297 clib_memcpy (mp->host_if_name, host_if_name, vec_len (host_if_name));
10298 clib_memcpy (mp->hw_addr, hw_addr, 6);
10299 mp->use_random_hw_addr = random_hw_addr;
10300 vec_free (host_if_name);
10308 api_af_packet_delete (vat_main_t * vam)
10310 unformat_input_t * i = vam->input;
10311 vl_api_af_packet_delete_t * mp;
10313 u8 * host_if_name = 0;
10315 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
10316 if (unformat (i, "name %s", &host_if_name))
10317 vec_add1 (host_if_name, 0);
10322 if (!vec_len (host_if_name)) {
10323 errmsg ("host-interface name must be specified");
10327 if (vec_len (host_if_name) > 64) {
10328 errmsg ("host-interface name too long");
10332 M(AF_PACKET_DELETE, af_packet_delete);
10334 clib_memcpy (mp->host_if_name, host_if_name, vec_len (host_if_name));
10335 vec_free (host_if_name);
10342 static int q_or_quit (vat_main_t * vam)
10344 longjmp (vam->jump_buf, 1);
10345 return 0; /* not so much */
10347 static int q (vat_main_t * vam) {return q_or_quit (vam);}
10348 static int quit (vat_main_t * vam) {return q_or_quit (vam);}
10350 static int comment (vat_main_t * vam)
10355 static int cmd_cmp (void * a1, void * a2)
10360 return strcmp ((char *)(c1[0]), (char *)(c2[0]));
10363 static int help (vat_main_t * vam)
10368 unformat_input_t * i = vam->input;
10371 if (unformat (i, "%s", &name)) {
10376 hs = hash_get_mem (vam->help_by_name, name);
10378 fformat (vam->ofp, "usage: %s %s\n", name, hs[0]);
10380 fformat (vam->ofp, "No such msg / command '%s'\n", name);
10385 fformat(vam->ofp, "Help is available for the following:\n");
10387 hash_foreach_pair (p, vam->function_by_name,
10389 vec_add1 (cmds, (u8 *)(p->key));
10392 vec_sort_with_function (cmds, cmd_cmp);
10394 for (j = 0; j < vec_len(cmds); j++)
10395 fformat (vam->ofp, "%s\n", cmds[j]);
10401 static int set (vat_main_t * vam)
10403 u8 * name = 0, * value = 0;
10404 unformat_input_t * i = vam->input;
10406 if (unformat (i, "%s", &name)) {
10407 /* The input buffer is a vector, not a string. */
10408 value = vec_dup (i->buffer);
10409 vec_delete (value, i->index, 0);
10410 /* Almost certainly has a trailing newline */
10411 if (value[vec_len(value)-1] == '\n')
10412 value[vec_len(value)-1] = 0;
10413 /* Make sure it's a proper string, one way or the other */
10414 vec_add1 (value, 0);
10415 (void) clib_macro_set_value (&vam->macro_main,
10416 (char *)name, (char *)value);
10419 errmsg ("usage: set <name> <value>\n");
10426 static int unset (vat_main_t * vam)
10430 if (unformat (vam->input, "%s", &name))
10431 if (clib_macro_unset (&vam->macro_main, (char *)name) == 1)
10432 errmsg ("unset: %s wasn't set\n", name);
10443 static int macro_sort_cmp (void * a1, void * a2)
10445 macro_sort_t * s1 = a1;
10446 macro_sort_t * s2 = a2;
10448 return strcmp ((char *)(s1->name), (char *)(s2->name));
10451 static int dump_macro_table (vat_main_t * vam)
10453 macro_sort_t * sort_me = 0, * sm;
10457 hash_foreach_pair (p, vam->macro_main.the_value_table_hash,
10459 vec_add2 (sort_me, sm, 1);
10460 sm->name = (u8 *)(p->key);
10461 sm->value = (u8 *) (p->value[0]);
10464 vec_sort_with_function (sort_me, macro_sort_cmp);
10466 if (vec_len(sort_me))
10467 fformat (vam->ofp, "%-15s%s\n", "Name", "Value");
10469 fformat (vam->ofp, "The macro table is empty...\n");
10471 for (i = 0; i < vec_len (sort_me); i++)
10472 fformat (vam->ofp, "%-15s%s\n", sort_me[i].name,
10477 static int dump_node_table (vat_main_t * vam)
10480 vlib_node_t * node, * next_node;
10482 if (vec_len (vam->graph_nodes) == 0) {
10483 fformat (vam->ofp, "Node table empty, issue get_node_graph...\n");
10487 for (i = 0; i < vec_len (vam->graph_nodes); i++) {
10488 node = vam->graph_nodes[i];
10489 fformat (vam->ofp, "[%d] %s\n", i, node->name);
10490 for (j = 0; j < vec_len (node->next_nodes); j++) {
10491 if (node->next_nodes[j] != ~0) {
10492 next_node = vam->graph_nodes[node->next_nodes[j]];
10493 fformat (vam->ofp, " [%d] %s\n", j, next_node->name);
10500 static int search_node_table (vat_main_t * vam)
10502 unformat_input_t * line_input = vam->input;
10505 vlib_node_t * node, * next_node;
10508 if (vam->graph_node_index_by_name == 0) {
10509 fformat (vam->ofp, "Node table empty, issue get_node_graph...\n");
10513 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) {
10514 if (unformat (line_input, "%s", &node_to_find)) {
10515 vec_add1 (node_to_find, 0);
10516 p = hash_get_mem (vam->graph_node_index_by_name, node_to_find);
10518 fformat (vam->ofp, "%s not found...\n", node_to_find);
10521 node = vam->graph_nodes[p[0]];
10522 fformat (vam->ofp, "[%d] %s\n", p[0], node->name);
10523 for (j = 0; j < vec_len (node->next_nodes); j++) {
10524 if (node->next_nodes[j] != ~0) {
10525 next_node = vam->graph_nodes[node->next_nodes[j]];
10526 fformat (vam->ofp, " [%d] %s\n", j, next_node->name);
10532 clib_warning ("parse error '%U'", format_unformat_error,
10538 vec_free(node_to_find);
10546 static int script (vat_main_t * vam)
10549 char * save_current_file;
10550 unformat_input_t save_input;
10551 jmp_buf save_jump_buf;
10552 u32 save_line_number;
10554 FILE * new_fp, * save_ifp;
10556 if (unformat (vam->input, "%s", &s)) {
10557 new_fp = fopen ((char *)s, "r");
10559 errmsg ("Couldn't open script file %s\n", s);
10564 errmsg ("Missing script name\n");
10568 clib_memcpy (&save_input, &vam->input, sizeof (save_input));
10569 clib_memcpy (&save_jump_buf, &vam->jump_buf, sizeof (save_jump_buf));
10570 save_ifp = vam->ifp;
10571 save_line_number = vam->input_line_number;
10572 save_current_file = (char *) vam->current_file;
10574 vam->input_line_number = 0;
10576 vam->current_file = s;
10579 clib_memcpy (&vam->input, &save_input, sizeof (vam->input));
10580 clib_memcpy (&vam->jump_buf, &save_jump_buf, sizeof (save_jump_buf));
10581 vam->ifp = save_ifp;
10582 vam->input_line_number = save_line_number;
10583 vam->current_file = (u8 *) save_current_file;
10589 static int echo (vat_main_t * vam)
10591 fformat (vam->ofp, "%v", vam->input->buffer);
10595 /* List of API message constructors, CLI names map to api_xxx */
10596 #define foreach_vpe_api_msg \
10597 _(create_loopback,"[mac <mac-addr>]") \
10598 _(sw_interface_dump,"") \
10599 _(sw_interface_set_flags, \
10600 "<intfc> | sw_if_index <id> admin-up | admin-down link-up | link down") \
10601 _(sw_interface_add_del_address, \
10602 "<intfc> | sw_if_index <id> <ip4-address> | <ip6-address> [del] [del-all] ") \
10603 _(sw_interface_set_table, \
10604 "<intfc> | sw_if_index <id> vrf <table-id> [ipv6]") \
10605 _(sw_interface_set_vpath, \
10606 "<intfc> | sw_if_index <id> enable | disable") \
10607 _(sw_interface_set_l2_xconnect, \
10608 "rx <intfc> | rx_sw_if_index <id> tx <intfc> | tx_sw_if_index <id>\n" \
10609 "enable | disable") \
10610 _(sw_interface_set_l2_bridge, \
10611 "rx <intfc> | rx_sw_if_index <id> bd_id <bridge-domain-id>\n" \
10612 "[shg <split-horizon-group>] [bvi]\n" \
10613 "enable | disable") \
10614 _(bridge_domain_add_del, \
10615 "bd_id <bridge-domain-id> [flood 1|0] [uu-flood 1|0] [forward 1|0] [learn 1|0] [arp-term 1|0] [del]\n")\
10616 _(bridge_domain_dump, "[bd_id <bridge-domain-id>]\n") \
10618 "mac <mac-addr> bd_id <bridge-domain-id> [del] | sw_if <intfc> | sw_if_index <id> [static] [filter] [bvi]\n") \
10620 "sw_if <intfc> | sw_if_index <id> [learn] [forward] [uu-flood] [flood]\n") \
10622 "bd_id <bridge-domain-id> [learn] [forward] [uu-flood] [flood] [arp-term] [disable]\n") \
10624 "tapname <name> mac <mac-addr> | random-mac") \
10626 "<vpp-if-name> | sw_if_index <id> tapname <name> mac <mac-addr> | random-mac") \
10628 "<vpp-if-name> | sw_if_index <id>") \
10629 _(sw_interface_tap_dump, "") \
10630 _(ip_add_del_route, \
10631 "<addr>/<mask> via <addr> [vrf <n>]\n" \
10632 "[<intfc> | sw_if_index <id>] [resolve-attempts <n>]\n" \
10633 "[weight <n>] [drop] [local] [classify <n>] [del]\n" \
10634 "[multipath] [count <n>]") \
10635 _(proxy_arp_add_del, \
10636 "<lo-ip4-addr> - <hi-ip4-addr> [vrf <n>] [del]") \
10637 _(proxy_arp_intfc_enable_disable, \
10638 "<intfc> | sw_if_index <id> enable | disable") \
10639 _(mpls_add_del_encap, \
10640 "label <n> dst <ip4-addr> [vrf <n>] [del]") \
10641 _(mpls_add_del_decap, \
10642 "label <n> [rx_vrf_id <n>] [tx_vrf_id] [s-bit-clear][del]") \
10643 _(mpls_gre_add_del_tunnel, \
10644 "inner_vrf_id <n> outer_vrf_id <n> src <ip4-address> dst <ip4-address>\n" \
10645 "adj <ip4-address>/<mask-width> [del]") \
10646 _(sw_interface_set_unnumbered, \
10647 "<intfc> | sw_if_index <id> unnum_if_index <id> [del]") \
10648 _(ip_neighbor_add_del, \
10649 "<intfc> | sw_if_index <id> dst <ip46-address> mac <mac-addr>") \
10650 _(reset_vrf, "vrf <id> [ipv6]") \
10651 _(create_vlan_subif, "<intfc> | sw_if_index <id> vlan <n>") \
10652 _(create_subif, "<intfc> | sw_if_index <id> sub_id <n>\n" \
10653 "[outer_vlan_id <n>][inner_vlan_id <n>]\n" \
10654 "[no_tags][one_tag][two_tags][dot1ad][exact_match][default_sub]\n" \
10655 "[outer_vlan_id_any][inner_vlan_id_any]") \
10656 _(oam_add_del, "src <ip4-address> dst <ip4-address> [vrf <n>] [del]") \
10657 _(reset_fib, "vrf <n> [ipv6]") \
10658 _(dhcp_proxy_config, \
10659 "svr <v46-address> src <v46-address>\n" \
10660 "insert-cid <n> [del]") \
10661 _(dhcp_proxy_config_2, \
10662 "svr <v46-address> src <v46-address>\n" \
10663 "rx_vrf_id <nn> server_vrf_id <nn> insert-cid <n> [del]") \
10664 _(dhcp_proxy_set_vss, \
10665 "tbl_id <n> fib_id <n> oui <n> [ipv6] [del]") \
10666 _(dhcp_client_config, \
10667 "<intfc> | sw_if_index <id> [hostname <name>] [disable_event] [del]") \
10668 _(set_ip_flow_hash, \
10669 "vrf <n> [src] [dst] [sport] [dport] [proto] [reverse] [ipv6]") \
10670 _(sw_interface_ip6_enable_disable, \
10671 "<intfc> | sw_if_index <id> enable | disable") \
10672 _(sw_interface_ip6_set_link_local_address, \
10673 "<intfc> | sw_if_index <id> <ip6-address>/<mask-width>") \
10674 _(sw_interface_ip6nd_ra_prefix, \
10675 "<intfc> | sw_if_index <id> <ip6-address>/<mask-width>\n" \
10676 "val_life <n> pref_life <n> [def] [noadv] [offl] [noauto]\n" \
10677 "[nolink] [isno]") \
10678 _(sw_interface_ip6nd_ra_config, \
10679 "<intfc> | sw_if_index <id> [maxint <n>] [minint <n>]\n" \
10680 "[life <n>] [count <n>] [interval <n>] [surpress]\n" \
10681 "[managed] [other] [ll] [send] [cease] [isno] [def]") \
10682 _(set_arp_neighbor_limit, "arp_nbr_limit <n> [ipv6]") \
10683 _(l2_patch_add_del, \
10684 "rx <intfc> | rx_sw_if_index <id> tx <intfc> | tx_sw_if_index <id>\n" \
10685 "enable | disable") \
10686 _(mpls_ethernet_add_del_tunnel, \
10687 "tx <intfc> | tx_sw_if_index <n> dst <mac-addr>\n" \
10688 "adj <ip4-addr>/<mw> dst <mac-addr> [del]") \
10689 _(mpls_ethernet_add_del_tunnel_2, \
10690 "inner_vrf_id <n> outer_vrf_id <n> next-hop <ip4-addr>\n" \
10691 "resolve-attempts <n> resolve-if-needed 0 | 1 [del]") \
10692 _(sr_tunnel_add_del, \
10693 "[name <name>] src <ip6-addr> dst <ip6-addr>/<mw> \n" \
10694 "(next <ip6-addr>)+ [tag <ip6-addr>]* [clean] [reroute] \n" \
10695 "[policy <policy_name>]") \
10696 _(sr_policy_add_del, \
10697 "name <name> tunnel <tunnel-name> [tunnel <tunnel-name>]* [del]") \
10698 _(sr_multicast_map_add_del, \
10699 "address [ip6 multicast address] sr-policy [policy name] [del]") \
10700 _(classify_add_del_table, \
10701 "buckets <nn> [skip <n>] [match <n>] [memory_size <nn-bytes>]\n" \
10702 "[del] mask <mask-value>\n" \
10703 " [l2-miss-next | miss-next | acl-miss-next] <name|nn>") \
10704 _(classify_add_del_session, \
10705 "[hit-next|l2-hit-next|acl-hit-next] <name|nn> table-index <nn>\n" \
10706 "skip_n <nn> match_n <nn> match [hex] [l2] [l3 [ip4|ip6]]") \
10707 _(classify_set_interface_ip_table, \
10708 "<intfc> | sw_if_index <nn> table <nn>") \
10709 _(classify_set_interface_l2_tables, \
10710 "<intfc> | sw_if_index <nn> [ip4-table <nn>] [ip6-table <nn>]\n" \
10711 " [other-table <nn>]") \
10712 _(get_node_index, "node <node-name") \
10713 _(add_node_next, "node <node-name> next <next-node-name>") \
10714 _(l2tpv3_create_tunnel, \
10715 "client_address <ip6-addr> our_address <ip6-addr>\n" \
10716 "[local_session_id <nn>][remote_session_id <nn>][local_cookie <nn>]\n"\
10717 "[remote_cookie <nn>]\n[l2-sublayer-preset]\n") \
10718 _(l2tpv3_set_tunnel_cookies, \
10719 "<intfc> | sw_if_index <nn> [new_local_cookie <nn>]\n" \
10720 "[new_remote_cookie <nn>]\n") \
10721 _(l2tpv3_interface_enable_disable, \
10722 "<intfc> | sw_if_index <nn> enable | disable") \
10723 _(l2tpv3_set_lookup_key, \
10724 "lookup_v6_src | lookup_v6_dst | lookup_session_id") \
10725 _(sw_if_l2tpv3_tunnel_dump, "") \
10726 _(vxlan_add_del_tunnel, \
10727 "src <ip4-addr> dst <ip4-addr> vni <vni> [encap-vrf-id <nn>]\n" \
10728 " [decap-next l2|ip4|ip6] [del]") \
10729 _(vxlan_tunnel_dump, "[<intfc> | sw_if_index <nn>]") \
10730 _(gre_add_del_tunnel, \
10731 "src <ip4-addr> dst <ip4-addr> [outer-fib-id <nn>] [del]\n") \
10732 _(gre_tunnel_dump, "[<intfc> | sw_if_index <nn>]") \
10733 _(l2_fib_clear_table, "") \
10734 _(l2_interface_efp_filter, "sw_if_index <nn> enable | disable") \
10735 _(l2_interface_vlan_tag_rewrite, \
10736 "<intfc> | sw_if_index <nn> \n" \
10737 "[disable][push-[1|2]][pop-[1|2]][translate-1-[1|2]] \n" \
10738 "[translate-2-[1|2]] [push_dot1q 0] tag1 <nn> tag2 <nn>") \
10739 _(create_vhost_user_if, \
10740 "socket <filename> [server] [renumber <dev_instance>] " \
10741 "[mac <mac_address>]") \
10742 _(modify_vhost_user_if, \
10743 "<intfc> | sw_if_index <nn> socket <filename>\n" \
10744 "[server] [renumber <dev_instance>]") \
10745 _(delete_vhost_user_if, "<intfc> | sw_if_index <nn>") \
10746 _(sw_interface_vhost_user_dump, "") \
10747 _(show_version, "") \
10748 _(nsh_gre_add_del_tunnel, \
10749 "src <ip4-addr> dst <ip4-addr>" \
10750 "c1 <nn> c2 <nn> c3 <nn> c4 <nn> spi <nn> si <nn>\n" \
10751 "[encap-fib-id <nn>] [decap-fib-id <nn>] [o-bit <1|0>]\n" \
10752 "[c-bit <1|0>] [md-type <nn>][next-ip4][next-ip6][next-ethernet]\n" \
10753 "[tlv <xx>][del]") \
10754 _(nsh_vxlan_gpe_add_del_tunnel, \
10755 "src <ip4-addr> dst <ip4-addr> vni <nn>\n" \
10756 "c1 <nn> c2 <nn> c3 <nn> c4 <nn> spi <nn> si <nn>\n" \
10757 "[encap-vrf-id <nn>] [decap-vrf-id <nn>] [o-bit <1|0>]\n" \
10758 "[c-bit <1|0>] [md-type <nn>][next-ip4][next-ip6][next-ethernet]\n" \
10759 "[tlv <xx>][del]") \
10760 _(l2_fib_table_dump, "bd_id <bridge-domain-id>") \
10761 _(interface_name_renumber, \
10762 "<intfc> | sw_if_index <nn> new_show_dev_instance <nn>") \
10763 _(input_acl_set_interface, \
10764 "<intfc> | sw_if_index <nn> [ip4-table <nn>] [ip6-table <nn>]\n" \
10765 " [l2-table <nn>] [del]") \
10766 _(want_ip4_arp_events, "address <ip4-address> [del]") \
10767 _(ip_address_dump, "(ipv4 | ipv6) (<intfc> | sw_if_index <id>)") \
10768 _(ip_dump, "ipv4 | ipv6") \
10769 _(ipsec_spd_add_del, "spd_id <n> [del]") \
10770 _(ipsec_interface_add_del_spd, "(<intfc> | sw_if_index <id>)\n" \
10772 _(ipsec_sad_add_del_entry, "sad_id <n> spi <n> crypto_alg <alg>\n" \
10773 " crypto_key <hex> tunnel_src <ip4|ip6> tunnel_dst <ip4|ip6>\n" \
10774 " integ_alg <alg> integ_key <hex>") \
10775 _(ipsec_spd_add_del_entry, "spd_id <n> priority <n> action <action>\n" \
10776 " (inbound|outbound) [sa_id <n>] laddr_start <ip4|ip6>\n" \
10777 " laddr_stop <ip4|ip6> raddr_start <ip4|ip6> raddr_stop <ip4|ip6>\n" \
10778 " [lport_start <n> lport_stop <n>] [rport_start <n> rport_stop <n>]" )\
10779 _(ipsec_sa_set_key, "sa_id <n> crypto_key <hex> integ_key <hex>") \
10780 _(ikev2_profile_add_del, "name <profile_name> [del]") \
10781 _(ikev2_profile_set_auth, "name <profile_name> auth_method <method>\n" \
10782 "(auth_data 0x<data> | auth_data <data>)") \
10783 _(ikev2_profile_set_id, "name <profile_name> id_type <type>\n" \
10784 "(id_data 0x<data> | id_data <data>) (local|remote)") \
10785 _(ikev2_profile_set_ts, "name <profile_name> protocol <proto>\n" \
10786 "start_port <port> end_port <port> start_addr <ip4> end_addr <ip4>\n" \
10787 "(local|remote)") \
10788 _(ikev2_set_local_key, "file <absolute_file_path>") \
10789 _(delete_loopback,"sw_if_index <nn>") \
10790 _(bd_ip_mac_add_del, "bd_id <bridge-domain-id> <ip4/6-addr> <mac-addr> [del]") \
10791 _(map_add_domain, \
10792 "ip4-pfx <ip4pfx> ip6-pfx <ip6pfx> " \
10793 "ip6-src <ip6addr> " \
10794 "ea-bits-len <n> psid-offset <n> psid-len <n>") \
10795 _(map_del_domain, "index <n>") \
10796 _(map_add_del_rule, \
10797 "index <n> psid <n> dst <ip6addr> [del]") \
10798 _(map_domain_dump, "") \
10799 _(map_rule_dump, "index <map-domain>") \
10800 _(want_interface_events, "enable|disable") \
10801 _(want_stats,"enable|disable") \
10802 _(get_first_msg_id, "client <name>") \
10803 _(cop_interface_enable_disable, "<intfc> | sw_if_index <nn> [disable]") \
10804 _(cop_whitelist_enable_disable, "<intfc> | sw_if_index <nn>\n" \
10805 "fib-id <nn> [ip4][ip6][default]") \
10806 _(get_node_graph, " ") \
10807 _(sw_interface_clear_stats,"<intfc> | sw_if_index <nn>") \
10808 _(trace_profile_add, "id <nn> trace-type <0x1f|0x3|0x9|0x11|0x19> " \
10809 "trace-elts <nn> trace-tsp <0|1|2|3> node-id <node id in hex> " \
10810 "app-data <app_data in hex> [pow] [ppc <encap|decap>]") \
10811 _(trace_profile_apply, "id <nn> <ip6-address>/<width>" \
10812 " vrf_id <nn> add | pop | none") \
10813 _(trace_profile_del, "") \
10814 _(lisp_add_del_locator_set, "locator-set <locator_name> [del]") \
10815 _(lisp_add_del_locator, "locator-set <locator_name> " \
10816 "iface <intf> | sw_if_index <sw_if_index> " \
10817 "p <priority> w <weight> [del]") \
10818 _(lisp_add_del_local_eid, "<ipv4|ipv6>/<prefix> " \
10819 "locator-set <locator_name> [del]") \
10820 _(lisp_gpe_add_del_fwd_entry, "eid <ip4|6-addr>/<prefix> " \
10821 "sloc <ip4/6-addr> dloc <ip4|6-addr> [del]") \
10822 _(lisp_add_del_map_resolver, "<ip4|6-addr> [del]") \
10823 _(lisp_gpe_enable_disable, "enable|disable") \
10824 _(lisp_enable_disable, "enable|disable") \
10825 _(lisp_gpe_add_del_iface, "up|down") \
10826 _(lisp_locator_set_dump, "") \
10827 _(lisp_local_eid_table_dump, "") \
10828 _(lisp_gpe_tunnel_dump, "") \
10829 _(lisp_map_resolver_dump, "") \
10830 _(lisp_enable_disable_status_dump, "") \
10831 _(af_packet_create, "name <host interface name> [hw_addr <mac>]") \
10832 _(af_packet_delete, "name <host interface name>")
10834 /* List of command functions, CLI names map directly to functions */
10835 #define foreach_cli_function \
10836 _(comment, "usage: comment <ignore-rest-of-line>") \
10837 _(dump_interface_table, "usage: dump_interface_table") \
10838 _(dump_sub_interface_table, "usage: dump_sub_interface_table") \
10839 _(dump_ipv4_table, "usage: dump_ipv4_table") \
10840 _(dump_ipv6_table, "usage: dump_ipv6_table") \
10841 _(dump_stats_table, "usage: dump_stats_table") \
10842 _(dump_macro_table, "usage: dump_macro_table ") \
10843 _(dump_node_table, "usage: dump_node_table") \
10844 _(echo, "usage: echo <message>") \
10845 _(exec, "usage: exec <vpe-debug-CLI-command>") \
10846 _(help, "usage: help") \
10847 _(q, "usage: quit") \
10848 _(quit, "usage: quit") \
10849 _(search_node_table, "usage: search_node_table <name>...") \
10850 _(set, "usage: set <variable-name> <value>") \
10851 _(script, "usage: script <file-name>") \
10852 _(unset, "usage: unset <variable-name>")
10855 static void vl_api_##n##_t_handler_uni \
10856 (vl_api_##n##_t * mp) \
10858 vat_main_t * vam = &vat_main; \
10859 if (vam->json_output) { \
10860 vl_api_##n##_t_handler_json(mp); \
10862 vl_api_##n##_t_handler(mp); \
10865 foreach_vpe_api_reply_msg;
10868 void vat_api_hookup (vat_main_t *vam)
10871 vl_msg_api_set_handlers(VL_API_##N, #n, \
10872 vl_api_##n##_t_handler_uni, \
10874 vl_api_##n##_t_endian, \
10875 vl_api_##n##_t_print, \
10876 sizeof(vl_api_##n##_t), 1);
10877 foreach_vpe_api_reply_msg;
10880 vl_msg_api_set_first_available_msg_id (VL_MSG_FIRST_AVAILABLE);
10882 vam->sw_if_index_by_interface_name =
10883 hash_create_string (0, sizeof (uword));
10885 vam->function_by_name =
10886 hash_create_string (0, sizeof(uword));
10888 vam->help_by_name =
10889 hash_create_string (0, sizeof(uword));
10891 /* API messages we can send */
10892 #define _(n,h) hash_set_mem (vam->function_by_name, #n, api_##n);
10893 foreach_vpe_api_msg;
10897 #define _(n,h) hash_set_mem (vam->help_by_name, #n, h);
10898 foreach_vpe_api_msg;
10901 /* CLI functions */
10902 #define _(n,h) hash_set_mem (vam->function_by_name, #n, n);
10903 foreach_cli_function;
10907 #define _(n,h) hash_set_mem (vam->help_by_name, #n, h);
10908 foreach_cli_function;
10912 #undef vl_api_version
10913 #define vl_api_version(n,v) static u32 vpe_api_version = v;
10914 #include <api/vpe.api.h>
10915 #undef vl_api_version
10917 void vl_client_add_api_signatures (vl_api_memclnt_create_t *mp)
10920 * Send the main API signature in slot 0. This bit of code must
10921 * match the checks in ../vpe/api/api.c: vl_msg_api_version_check().
10923 mp->api_versions[0] = clib_host_to_net_u32 (vpe_api_version);