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_lisp_gpe_add_del_tunnel_reply_t_handler
913 (vl_api_lisp_gpe_add_del_tunnel_reply_t * mp)
915 vat_main_t * vam = &vat_main;
916 i32 retval = ntohl(mp->retval);
917 u32 sw_if_index = ntohl(mp->sw_if_index);
919 if (retval >= 0 && sw_if_index != (u32)~0) {
920 errmsg ("sw_if_index %d\n", ntohl(mp->sw_if_index));
922 vam->retval = retval;
923 vam->result_ready = 1;
926 static void vl_api_lisp_gpe_add_del_tunnel_reply_t_handler_json
927 (vl_api_lisp_gpe_add_del_tunnel_reply_t * mp)
929 vat_main_t * vam = &vat_main;
930 vat_json_node_t node;
932 vat_json_init_object(&node);
933 vat_json_object_add_int(&node, "retval", ntohl(mp->retval));
934 vat_json_object_add_uint(&node, "sw_if_index", ntohl(mp->sw_if_index));
936 vat_json_print(vam->ofp, &node);
937 vat_json_free(&node);
939 vam->retval = ntohl(mp->retval);
940 vam->result_ready = 1;
943 static void vl_api_show_version_reply_t_handler
944 (vl_api_show_version_reply_t * mp)
946 vat_main_t * vam = &vat_main;
947 i32 retval = ntohl(mp->retval);
950 errmsg (" program: %s\n", mp->program);
951 errmsg (" version: %s\n", mp->version);
952 errmsg (" build date: %s\n", mp->build_date);
953 errmsg ("build directory: %s\n", mp->build_directory);
955 vam->retval = retval;
956 vam->result_ready = 1;
959 static void vl_api_show_version_reply_t_handler_json
960 (vl_api_show_version_reply_t * mp)
962 vat_main_t * vam = &vat_main;
963 vat_json_node_t node;
965 vat_json_init_object(&node);
966 vat_json_object_add_int(&node, "retval", ntohl(mp->retval));
967 vat_json_object_add_string_copy(&node, "program", mp->program);
968 vat_json_object_add_string_copy(&node, "version", mp->version);
969 vat_json_object_add_string_copy(&node, "build_date", mp->build_date);
970 vat_json_object_add_string_copy(&node, "build_directory", mp->build_directory);
972 vat_json_print(vam->ofp, &node);
973 vat_json_free(&node);
975 vam->retval = ntohl(mp->retval);
976 vam->result_ready = 1;
979 static void vl_api_ip4_arp_event_t_handler
980 (vl_api_ip4_arp_event_t * mp)
982 vat_main_t * vam = &vat_main;
983 errmsg ("arp event: address %U new mac %U sw_if_index %d\n",
984 format_ip4_address, &mp->address,
985 format_ethernet_address, mp->new_mac, mp->sw_if_index);
988 static void vl_api_ip4_arp_event_t_handler_json
989 (vl_api_ip4_arp_event_t * mp)
991 /* JSON output not supported */
995 * Special-case: build the bridge domain table, maintain
996 * the next bd id vbl.
998 static void vl_api_bridge_domain_details_t_handler
999 (vl_api_bridge_domain_details_t * mp)
1001 vat_main_t * vam = &vat_main;
1002 u32 n_sw_ifs = ntohl (mp->n_sw_ifs);
1004 fformat (vam->ofp, "\n%-3s %-3s %-3s %-3s %-3s %-3s\n",
1005 " ID", "LRN", "FWD", "FLD", "BVI", "#IF");
1007 fformat (vam->ofp, "%3d %3d %3d %3d %3d %3d\n",
1008 ntohl (mp->bd_id), mp->learn, mp->forward,
1009 mp->flood, ntohl (mp->bvi_sw_if_index), n_sw_ifs);
1012 fformat (vam->ofp, "\n\n%s %s %s\n", "sw_if_index", "SHG",
1016 static void vl_api_bridge_domain_details_t_handler_json
1017 (vl_api_bridge_domain_details_t * mp)
1019 vat_main_t * vam = &vat_main;
1020 vat_json_node_t *node, *array = NULL;
1022 if (VAT_JSON_ARRAY != vam->json_tree.type) {
1023 ASSERT(VAT_JSON_NONE == vam->json_tree.type);
1024 vat_json_init_array(&vam->json_tree);
1026 node = vat_json_array_add(&vam->json_tree);
1028 vat_json_init_object(node);
1029 vat_json_object_add_uint(node, "bd_id", ntohl(mp->bd_id));
1030 vat_json_object_add_uint(node, "flood", mp->flood);
1031 vat_json_object_add_uint(node, "forward", mp->forward);
1032 vat_json_object_add_uint(node, "learn", mp->learn);
1033 vat_json_object_add_uint(node, "bvi_sw_if_index", ntohl(mp->bvi_sw_if_index));
1034 vat_json_object_add_uint(node, "n_sw_ifs", ntohl(mp->n_sw_ifs));
1035 array = vat_json_object_add(node, "sw_if");
1036 vat_json_init_array(array);
1040 * Special-case: build the bridge domain sw if table.
1042 static void vl_api_bridge_domain_sw_if_details_t_handler
1043 (vl_api_bridge_domain_sw_if_details_t * mp)
1045 vat_main_t * vam = &vat_main;
1047 u8 * sw_if_name = 0;
1050 sw_if_index = ntohl (mp->sw_if_index);
1051 hash_foreach_pair (p, vam->sw_if_index_by_interface_name,
1053 if ((u32) p->value[0] == sw_if_index) {
1054 sw_if_name = (u8 *)(p->key);
1059 fformat (vam->ofp, "%7d %3d %s", sw_if_index,
1060 mp->shg, sw_if_name ? (char *)sw_if_name :
1061 "sw_if_index not found!");
1064 static void vl_api_bridge_domain_sw_if_details_t_handler_json
1065 (vl_api_bridge_domain_sw_if_details_t * mp)
1067 vat_main_t * vam = &vat_main;
1068 vat_json_node_t *node = NULL;
1069 uword last_index = 0;
1071 ASSERT(VAT_JSON_ARRAY == vam->json_tree.type);
1072 ASSERT(vec_len(vam->json_tree.array) >= 1);
1073 last_index = vec_len(vam->json_tree.array) - 1;
1074 node = &vam->json_tree.array[last_index];
1075 node = vat_json_object_get_element(node, "sw_if");
1076 ASSERT(NULL != node);
1077 node = vat_json_array_add(node);
1079 vat_json_init_object(node);
1080 vat_json_object_add_uint(node, "bd_id", ntohl(mp->bd_id));
1081 vat_json_object_add_uint(node, "sw_if_index", ntohl(mp->sw_if_index));
1082 vat_json_object_add_uint(node, "shg", mp->shg);
1085 static void vl_api_control_ping_reply_t_handler
1086 (vl_api_control_ping_reply_t * mp)
1088 vat_main_t * vam = &vat_main;
1089 i32 retval = ntohl(mp->retval);
1090 if (vam->async_mode) {
1091 vam->async_errors += (retval < 0);
1093 vam->retval = retval;
1094 vam->result_ready = 1;
1098 static void vl_api_control_ping_reply_t_handler_json
1099 (vl_api_control_ping_reply_t * mp)
1101 vat_main_t * vam = &vat_main;
1102 i32 retval = ntohl(mp->retval);
1104 if (VAT_JSON_NONE != vam->json_tree.type) {
1105 vat_json_print(vam->ofp, &vam->json_tree);
1106 vat_json_free(&vam->json_tree);
1107 vam->json_tree.type = VAT_JSON_NONE;
1110 vat_json_init_array(&vam->json_tree);
1111 vat_json_print(vam->ofp, &vam->json_tree);
1112 vam->json_tree.type = VAT_JSON_NONE;
1115 vam->retval = retval;
1116 vam->result_ready = 1;
1119 static void vl_api_l2_flags_reply_t_handler
1120 (vl_api_l2_flags_reply_t * mp)
1122 vat_main_t * vam = &vat_main;
1123 i32 retval = ntohl(mp->retval);
1124 if (vam->async_mode) {
1125 vam->async_errors += (retval < 0);
1127 vam->retval = retval;
1128 vam->result_ready = 1;
1132 static void vl_api_l2_flags_reply_t_handler_json
1133 (vl_api_l2_flags_reply_t * mp)
1135 vat_main_t * vam = &vat_main;
1136 vat_json_node_t node;
1138 vat_json_init_object(&node);
1139 vat_json_object_add_int(&node, "retval", ntohl(mp->retval));
1140 vat_json_object_add_uint(&node, "resulting_feature_bitmap", ntohl(mp->resulting_feature_bitmap));
1142 vat_json_print(vam->ofp, &node);
1143 vat_json_free(&node);
1145 vam->retval = ntohl(mp->retval);
1146 vam->result_ready = 1;
1149 static void vl_api_bridge_flags_reply_t_handler
1150 (vl_api_bridge_flags_reply_t * mp)
1152 vat_main_t * vam = &vat_main;
1153 i32 retval = ntohl(mp->retval);
1154 if (vam->async_mode) {
1155 vam->async_errors += (retval < 0);
1157 vam->retval = retval;
1158 vam->result_ready = 1;
1162 static void vl_api_bridge_flags_reply_t_handler_json
1163 (vl_api_bridge_flags_reply_t * mp)
1165 vat_main_t * vam = &vat_main;
1166 vat_json_node_t node;
1168 vat_json_init_object(&node);
1169 vat_json_object_add_int(&node, "retval", ntohl(mp->retval));
1170 vat_json_object_add_uint(&node, "resulting_feature_bitmap", ntohl(mp->resulting_feature_bitmap));
1172 vat_json_print(vam->ofp, &node);
1173 vat_json_free(&node);
1175 vam->retval = ntohl(mp->retval);
1176 vam->result_ready = 1;
1179 static void vl_api_tap_connect_reply_t_handler
1180 (vl_api_tap_connect_reply_t * mp)
1182 vat_main_t * vam = &vat_main;
1183 i32 retval = ntohl(mp->retval);
1184 if (vam->async_mode) {
1185 vam->async_errors += (retval < 0);
1187 vam->retval = retval;
1188 vam->result_ready = 1;
1192 static void vl_api_tap_connect_reply_t_handler_json
1193 (vl_api_tap_connect_reply_t * mp)
1195 vat_main_t * vam = &vat_main;
1196 vat_json_node_t node;
1198 vat_json_init_object(&node);
1199 vat_json_object_add_int(&node, "retval", ntohl(mp->retval));
1200 vat_json_object_add_uint(&node, "sw_if_index", ntohl(mp->sw_if_index));
1202 vat_json_print(vam->ofp, &node);
1203 vat_json_free(&node);
1205 vam->retval = ntohl(mp->retval);
1206 vam->result_ready = 1;
1209 static void vl_api_tap_modify_reply_t_handler
1210 (vl_api_tap_modify_reply_t * mp)
1212 vat_main_t * vam = &vat_main;
1213 i32 retval = ntohl(mp->retval);
1214 if (vam->async_mode) {
1215 vam->async_errors += (retval < 0);
1217 vam->retval = retval;
1218 vam->result_ready = 1;
1222 static void vl_api_tap_modify_reply_t_handler_json
1223 (vl_api_tap_modify_reply_t * mp)
1225 vat_main_t * vam = &vat_main;
1226 vat_json_node_t node;
1228 vat_json_init_object(&node);
1229 vat_json_object_add_int(&node, "retval", ntohl(mp->retval));
1230 vat_json_object_add_uint(&node, "sw_if_index", ntohl(mp->sw_if_index));
1232 vat_json_print(vam->ofp, &node);
1233 vat_json_free(&node);
1235 vam->retval = ntohl(mp->retval);
1236 vam->result_ready = 1;
1239 static void vl_api_tap_delete_reply_t_handler
1240 (vl_api_tap_delete_reply_t * mp)
1242 vat_main_t * vam = &vat_main;
1243 i32 retval = ntohl(mp->retval);
1244 if (vam->async_mode) {
1245 vam->async_errors += (retval < 0);
1247 vam->retval = retval;
1248 vam->result_ready = 1;
1252 static void vl_api_tap_delete_reply_t_handler_json
1253 (vl_api_tap_delete_reply_t * mp)
1255 vat_main_t * vam = &vat_main;
1256 vat_json_node_t node;
1258 vat_json_init_object(&node);
1259 vat_json_object_add_int(&node, "retval", ntohl(mp->retval));
1261 vat_json_print(vam->ofp, &node);
1262 vat_json_free(&node);
1264 vam->retval = ntohl(mp->retval);
1265 vam->result_ready = 1;
1268 static void vl_api_mpls_ethernet_add_del_tunnel_reply_t_handler
1269 (vl_api_mpls_ethernet_add_del_tunnel_reply_t * mp)
1271 vat_main_t * vam = &vat_main;
1272 i32 retval = ntohl(mp->retval);
1273 if (vam->async_mode) {
1274 vam->async_errors += (retval < 0);
1276 vam->retval = retval;
1277 vam->result_ready = 1;
1281 static void vl_api_mpls_ethernet_add_del_tunnel_reply_t_handler_json
1282 (vl_api_mpls_ethernet_add_del_tunnel_reply_t * mp)
1284 vat_main_t * vam = &vat_main;
1285 vat_json_node_t node;
1287 vat_json_init_object(&node);
1288 vat_json_object_add_int(&node, "retval", ntohl(mp->retval));
1289 vat_json_object_add_uint(&node, "tunnel_sw_if_index", ntohl(mp->tunnel_sw_if_index));
1291 vat_json_print(vam->ofp, &node);
1292 vat_json_free(&node);
1294 vam->retval = ntohl(mp->retval);
1295 vam->result_ready = 1;
1298 static void vl_api_l2tpv3_create_tunnel_reply_t_handler
1299 (vl_api_l2tpv3_create_tunnel_reply_t * mp)
1301 vat_main_t * vam = &vat_main;
1302 i32 retval = ntohl(mp->retval);
1303 if (vam->async_mode) {
1304 vam->async_errors += (retval < 0);
1306 vam->retval = retval;
1307 vam->result_ready = 1;
1311 static void vl_api_l2tpv3_create_tunnel_reply_t_handler_json
1312 (vl_api_l2tpv3_create_tunnel_reply_t * mp)
1314 vat_main_t * vam = &vat_main;
1315 vat_json_node_t node;
1317 vat_json_init_object(&node);
1318 vat_json_object_add_int(&node, "retval", ntohl(mp->retval));
1319 vat_json_object_add_uint(&node, "sw_if_index", ntohl(mp->sw_if_index));
1321 vat_json_print(vam->ofp, &node);
1322 vat_json_free(&node);
1324 vam->retval = ntohl(mp->retval);
1325 vam->result_ready = 1;
1328 static void vl_api_vxlan_add_del_tunnel_reply_t_handler
1329 (vl_api_vxlan_add_del_tunnel_reply_t * mp)
1331 vat_main_t * vam = &vat_main;
1332 i32 retval = ntohl(mp->retval);
1333 if (vam->async_mode) {
1334 vam->async_errors += (retval < 0);
1336 vam->retval = retval;
1337 vam->result_ready = 1;
1341 static void vl_api_vxlan_add_del_tunnel_reply_t_handler_json
1342 (vl_api_vxlan_add_del_tunnel_reply_t * mp)
1344 vat_main_t * vam = &vat_main;
1345 vat_json_node_t node;
1347 vat_json_init_object(&node);
1348 vat_json_object_add_int(&node, "retval", ntohl(mp->retval));
1349 vat_json_object_add_uint(&node, "sw_if_index", ntohl(mp->sw_if_index));
1351 vat_json_print(vam->ofp, &node);
1352 vat_json_free(&node);
1354 vam->retval = ntohl(mp->retval);
1355 vam->result_ready = 1;
1358 static void vl_api_gre_add_del_tunnel_reply_t_handler
1359 (vl_api_gre_add_del_tunnel_reply_t * mp)
1361 vat_main_t * vam = &vat_main;
1362 i32 retval = ntohl(mp->retval);
1363 if (vam->async_mode) {
1364 vam->async_errors += (retval < 0);
1366 vam->retval = retval;
1367 vam->result_ready = 1;
1371 static void vl_api_gre_add_del_tunnel_reply_t_handler_json
1372 (vl_api_gre_add_del_tunnel_reply_t * mp)
1374 vat_main_t * vam = &vat_main;
1375 vat_json_node_t node;
1377 vat_json_init_object(&node);
1378 vat_json_object_add_int(&node, "retval", ntohl(mp->retval));
1379 vat_json_object_add_uint(&node, "sw_if_index", ntohl(mp->sw_if_index));
1381 vat_json_print(vam->ofp, &node);
1382 vat_json_free(&node);
1384 vam->retval = ntohl(mp->retval);
1385 vam->result_ready = 1;
1388 static void vl_api_create_vhost_user_if_reply_t_handler
1389 (vl_api_create_vhost_user_if_reply_t * mp)
1391 vat_main_t * vam = &vat_main;
1392 i32 retval = ntohl(mp->retval);
1393 if (vam->async_mode) {
1394 vam->async_errors += (retval < 0);
1396 vam->retval = retval;
1397 vam->result_ready = 1;
1401 static void vl_api_create_vhost_user_if_reply_t_handler_json
1402 (vl_api_create_vhost_user_if_reply_t * mp)
1404 vat_main_t * vam = &vat_main;
1405 vat_json_node_t node;
1407 vat_json_init_object(&node);
1408 vat_json_object_add_int(&node, "retval", ntohl(mp->retval));
1409 vat_json_object_add_uint(&node, "sw_if_index", ntohl(mp->sw_if_index));
1411 vat_json_print(vam->ofp, &node);
1412 vat_json_free(&node);
1414 vam->retval = ntohl(mp->retval);
1415 vam->result_ready = 1;
1418 static void vl_api_ip_address_details_t_handler
1419 (vl_api_ip_address_details_t * mp)
1421 vat_main_t * vam = &vat_main;
1422 static ip_address_details_t empty_ip_address_details = {{0}};
1423 ip_address_details_t * address = NULL;
1424 ip_details_t * current_ip_details = NULL;
1425 ip_details_t * details = NULL;
1427 details = vam->ip_details_by_sw_if_index[vam->is_ipv6];
1429 if (!details || vam->current_sw_if_index >= vec_len(details)
1430 || !details[vam->current_sw_if_index].present) {
1431 errmsg ("ip address details arrived but not stored\n");
1432 errmsg ("ip_dump should be called first\n");
1436 current_ip_details = vec_elt_at_index(details,
1437 vam->current_sw_if_index);
1439 #define addresses (current_ip_details->addr)
1441 vec_validate_init_empty(addresses, vec_len(addresses),
1442 empty_ip_address_details);
1444 address = vec_elt_at_index(addresses, vec_len(addresses) - 1);
1446 clib_memcpy(&address->ip, &mp->ip, sizeof(address->ip));
1447 address->prefix_length = mp->prefix_length;
1451 static void vl_api_ip_address_details_t_handler_json
1452 (vl_api_ip_address_details_t * mp)
1454 vat_main_t * vam = &vat_main;
1455 vat_json_node_t *node = NULL;
1456 struct in6_addr ip6;
1459 if (VAT_JSON_ARRAY != vam->json_tree.type) {
1460 ASSERT(VAT_JSON_NONE == vam->json_tree.type);
1461 vat_json_init_array(&vam->json_tree);
1463 node = vat_json_array_add(&vam->json_tree);
1465 vat_json_init_object(node);
1467 clib_memcpy(&ip6, mp->ip, sizeof(ip6));
1468 vat_json_object_add_ip6(node, "ip", ip6);
1470 clib_memcpy(&ip4, mp->ip, sizeof(ip4));
1471 vat_json_object_add_ip4(node, "ip", ip4);
1473 vat_json_object_add_uint(node, "prefix_length", mp->prefix_length);
1476 static void vl_api_ip_details_t_handler (vl_api_ip_details_t * mp)
1478 vat_main_t * vam = &vat_main;
1479 static ip_details_t empty_ip_details = {0};
1480 ip_details_t * ip = NULL;
1481 u32 sw_if_index = ~0;
1483 sw_if_index = ntohl(mp->sw_if_index);
1485 vec_validate_init_empty(vam->ip_details_by_sw_if_index[vam->is_ipv6],
1486 sw_if_index, empty_ip_details);
1488 ip = vec_elt_at_index(vam->ip_details_by_sw_if_index[vam->is_ipv6],
1494 static void vl_api_ip_details_t_handler_json (vl_api_ip_details_t * mp)
1496 vat_main_t * vam = &vat_main;
1498 if (VAT_JSON_ARRAY != vam->json_tree.type) {
1499 ASSERT(VAT_JSON_NONE == vam->json_tree.type);
1500 vat_json_init_array(&vam->json_tree);
1502 vat_json_array_add_uint(&vam->json_tree, clib_net_to_host_u32(mp->sw_if_index));
1505 static void vl_api_map_domain_details_t_handler_json
1506 (vl_api_map_domain_details_t * mp)
1508 vat_json_node_t * node = NULL;
1509 vat_main_t * vam = &vat_main;
1510 struct in6_addr ip6;
1513 if (VAT_JSON_ARRAY != vam->json_tree.type) {
1514 ASSERT(VAT_JSON_NONE == vam->json_tree.type);
1515 vat_json_init_array(&vam->json_tree);
1518 node = vat_json_array_add(&vam->json_tree);
1519 vat_json_init_object(node);
1521 vat_json_object_add_uint(node, "domain_index", clib_net_to_host_u32(mp->domain_index));
1522 clib_memcpy(&ip6, mp->ip6_prefix, sizeof(ip6));
1523 vat_json_object_add_ip6(node, "ip6_prefix", ip6);
1524 clib_memcpy(&ip4, mp->ip4_prefix, sizeof(ip4));
1525 vat_json_object_add_ip4(node, "ip4_prefix", ip4);
1526 clib_memcpy(&ip6, mp->ip6_src, sizeof(ip6));
1527 vat_json_object_add_ip6(node, "ip6_src", ip6);
1528 vat_json_object_add_int(node, "ip6_prefix_len", mp->ip6_prefix_len);
1529 vat_json_object_add_int(node, "ip4_prefix_len", mp->ip4_prefix_len);
1530 vat_json_object_add_int(node, "ip6_src_len", mp->ip6_src_len);
1531 vat_json_object_add_int(node, "ea_bits_len", mp->ea_bits_len);
1532 vat_json_object_add_int(node, "psid_offset", mp->psid_offset);
1533 vat_json_object_add_int(node, "psid_length", mp->psid_length);
1534 vat_json_object_add_uint(node, "flags", mp->flags);
1535 vat_json_object_add_uint(node, "mtu", clib_net_to_host_u16(mp->mtu));
1536 vat_json_object_add_int(node, "is_translation", mp->is_translation);
1539 static void vl_api_map_domain_details_t_handler
1540 (vl_api_map_domain_details_t * mp)
1542 vat_main_t * vam = &vat_main;
1544 if (mp->is_translation) {
1545 fformat(vam->ofp, "* %U/%d (ipv4-prefix) %U/%d (ipv6-prefix) %U/%d (ip6-src) index: %u\n",
1546 format_ip4_address, mp->ip4_prefix, mp->ip4_prefix_len,
1547 format_ip6_address, mp->ip6_prefix, mp->ip6_prefix_len,
1548 format_ip6_address, mp->ip6_src, mp->ip6_src_len, clib_net_to_host_u32(mp->domain_index));
1550 fformat(vam->ofp, "* %U/%d (ipv4-prefix) %U/%d (ipv6-prefix) %U (ip6-src) index: %u\n",
1551 format_ip4_address, mp->ip4_prefix, mp->ip4_prefix_len,
1552 format_ip6_address, mp->ip6_prefix, mp->ip6_prefix_len,
1553 format_ip6_address, mp->ip6_src, clib_net_to_host_u32(mp->domain_index));
1555 fformat(vam->ofp, " ea-len %d psid-offset %d psid-len %d mtu %d %s\n",
1556 mp->ea_bits_len, mp->psid_offset, mp->psid_length, mp->mtu, mp->is_translation? "map-t":"");
1559 static void vl_api_map_rule_details_t_handler_json
1560 (vl_api_map_rule_details_t * mp)
1562 struct in6_addr ip6;
1563 vat_json_node_t * node = NULL;
1564 vat_main_t * vam = &vat_main;
1566 if (VAT_JSON_ARRAY != vam->json_tree.type) {
1567 ASSERT(VAT_JSON_NONE == vam->json_tree.type);
1568 vat_json_init_array(&vam->json_tree);
1571 node = vat_json_array_add(&vam->json_tree);
1572 vat_json_init_object(node);
1574 vat_json_object_add_uint(node, "psid", clib_net_to_host_u16(mp->psid));
1575 clib_memcpy(&ip6, mp->ip6_dst, sizeof(ip6));
1576 vat_json_object_add_ip6(node, "ip6_dst", ip6);
1579 static void vl_api_map_rule_details_t_handler
1580 (vl_api_map_rule_details_t * mp)
1582 vat_main_t * vam = &vat_main;
1583 fformat(vam->ofp, " %d (psid) %U (ip6-dst)\n", clib_net_to_host_u16(mp->psid),
1584 format_ip6_address, mp->ip6_dst);
1587 static void vl_api_dhcp_compl_event_t_handler
1588 (vl_api_dhcp_compl_event_t * mp)
1590 vat_main_t * vam = &vat_main;
1591 errmsg ("DHCP compl event: pid %d %s hostname %s host_addr %U "
1592 "router_addr %U host_mac %U\n",
1593 mp->pid, mp->is_ipv6 ? "ipv6":"ipv4", mp->hostname,
1594 format_ip4_address, &mp->host_address,
1595 format_ip4_address, &mp->router_address,
1596 format_ethernet_address, mp->host_mac);
1599 static void vl_api_dhcp_compl_event_t_handler_json
1600 (vl_api_dhcp_compl_event_t * mp)
1602 /* JSON output not supported */
1605 static void set_simple_interface_counter (u8 vnet_counter_type, u32 sw_if_index,
1608 vat_main_t * vam = &vat_main;
1609 static u64 default_counter = 0;
1611 vec_validate_init_empty(vam->simple_interface_counters, vnet_counter_type, NULL);
1612 vec_validate_init_empty(vam->simple_interface_counters[vnet_counter_type],
1613 sw_if_index, default_counter);
1614 vam->simple_interface_counters[vnet_counter_type][sw_if_index] = counter;
1617 static void set_combined_interface_counter (u8 vnet_counter_type, u32 sw_if_index,
1618 interface_counter_t counter)
1620 vat_main_t * vam = &vat_main;
1621 static interface_counter_t default_counter = {0, };
1623 vec_validate_init_empty(vam->combined_interface_counters, vnet_counter_type, NULL);
1624 vec_validate_init_empty(vam->combined_interface_counters[vnet_counter_type],
1625 sw_if_index, default_counter);
1626 vam->combined_interface_counters[vnet_counter_type][sw_if_index] = counter;
1629 static void vl_api_vnet_interface_counters_t_handler
1630 (vl_api_vnet_interface_counters_t *mp)
1635 static void vl_api_vnet_interface_counters_t_handler_json
1636 (vl_api_vnet_interface_counters_t *mp)
1638 interface_counter_t counter;
1643 u32 first_sw_if_index;
1646 count = ntohl(mp->count);
1647 first_sw_if_index = ntohl(mp->first_sw_if_index);
1649 if (!mp->is_combined) {
1650 v_packets = (u64*)&mp->data;
1651 for (i = 0; i < count; i++) {
1652 packets = clib_net_to_host_u64(clib_mem_unaligned(v_packets, u64));
1653 set_simple_interface_counter(mp->vnet_counter_type,
1654 first_sw_if_index + i, packets);
1658 v = (vlib_counter_t*)&mp->data;
1659 for (i = 0; i < count; i++) {
1660 counter.packets = clib_net_to_host_u64(
1661 clib_mem_unaligned(&v->packets, u64));
1662 counter.bytes = clib_net_to_host_u64(
1663 clib_mem_unaligned(&v->bytes, u64));
1664 set_combined_interface_counter(mp->vnet_counter_type,
1665 first_sw_if_index + i, counter);
1671 static u32 ip4_fib_counters_get_vrf_index_by_vrf_id (u32 vrf_id)
1673 vat_main_t * vam = &vat_main;
1676 for (i = 0; i < vec_len(vam->ip4_fib_counters_vrf_id_by_index); i++) {
1677 if (vam->ip4_fib_counters_vrf_id_by_index[i] == vrf_id) {
1684 static u32 ip6_fib_counters_get_vrf_index_by_vrf_id (u32 vrf_id)
1686 vat_main_t * vam = &vat_main;
1689 for (i = 0; i < vec_len(vam->ip6_fib_counters_vrf_id_by_index); i++) {
1690 if (vam->ip6_fib_counters_vrf_id_by_index[i] == vrf_id) {
1697 static void vl_api_vnet_ip4_fib_counters_t_handler
1698 (vl_api_vnet_ip4_fib_counters_t *mp)
1703 static void vl_api_vnet_ip4_fib_counters_t_handler_json
1704 (vl_api_vnet_ip4_fib_counters_t *mp)
1706 vat_main_t * vam = &vat_main;
1707 vl_api_ip4_fib_counter_t *v;
1708 ip4_fib_counter_t *counter;
1715 vrf_id = ntohl(mp->vrf_id);
1716 vrf_index = ip4_fib_counters_get_vrf_index_by_vrf_id(vrf_id);
1717 if (~0 == vrf_index) {
1718 vrf_index = vec_len(vam->ip4_fib_counters_vrf_id_by_index);
1719 vec_validate(vam->ip4_fib_counters_vrf_id_by_index, vrf_index);
1720 vam->ip4_fib_counters_vrf_id_by_index[vrf_index] = vrf_id;
1721 vec_validate(vam->ip4_fib_counters, vrf_index);
1722 vam->ip4_fib_counters[vrf_index] = NULL;
1725 vec_free(vam->ip4_fib_counters[vrf_index]);
1726 v = (vl_api_ip4_fib_counter_t*)&mp->c;
1727 count = ntohl(mp->count);
1728 for (i = 0; i < count; i++) {
1729 vec_validate(vam->ip4_fib_counters[vrf_index], i);
1730 counter = &vam->ip4_fib_counters[vrf_index][i];
1731 clib_memcpy(&ip4, &v->address, sizeof(ip4));
1732 counter->address = ip4;
1733 counter->address_length = v->address_length;
1734 counter->packets = clib_net_to_host_u64(v->packets);
1735 counter->bytes = clib_net_to_host_u64(v->bytes);
1740 static void vl_api_vnet_ip6_fib_counters_t_handler
1741 (vl_api_vnet_ip6_fib_counters_t *mp)
1746 static void vl_api_vnet_ip6_fib_counters_t_handler_json
1747 (vl_api_vnet_ip6_fib_counters_t *mp)
1749 vat_main_t * vam = &vat_main;
1750 vl_api_ip6_fib_counter_t *v;
1751 ip6_fib_counter_t *counter;
1752 struct in6_addr ip6;
1758 vrf_id = ntohl(mp->vrf_id);
1759 vrf_index = ip6_fib_counters_get_vrf_index_by_vrf_id(vrf_id);
1760 if (~0 == vrf_index) {
1761 vrf_index = vec_len(vam->ip6_fib_counters_vrf_id_by_index);
1762 vec_validate(vam->ip6_fib_counters_vrf_id_by_index, vrf_index);
1763 vam->ip6_fib_counters_vrf_id_by_index[vrf_index] = vrf_id;
1764 vec_validate(vam->ip6_fib_counters, vrf_index);
1765 vam->ip6_fib_counters[vrf_index] = NULL;
1768 vec_free(vam->ip6_fib_counters[vrf_index]);
1769 v = (vl_api_ip6_fib_counter_t*)&mp->c;
1770 count = ntohl(mp->count);
1771 for (i = 0; i < count; i++) {
1772 vec_validate(vam->ip6_fib_counters[vrf_index], i);
1773 counter = &vam->ip6_fib_counters[vrf_index][i];
1774 clib_memcpy(&ip6, &v->address, sizeof(ip6));
1775 counter->address = ip6;
1776 counter->address_length = v->address_length;
1777 counter->packets = clib_net_to_host_u64(v->packets);
1778 counter->bytes = clib_net_to_host_u64(v->bytes);
1783 static void vl_api_get_first_msg_id_reply_t_handler
1784 (vl_api_get_first_msg_id_reply_t * mp)
1786 vat_main_t * vam = &vat_main;
1787 i32 retval = ntohl(mp->retval);
1789 if (vam->async_mode) {
1790 vam->async_errors += (retval < 0);
1792 vam->retval = retval;
1793 vam->result_ready = 1;
1796 errmsg ("first message id %d\n", ntohs(mp->first_msg_id));
1800 static void vl_api_get_first_msg_id_reply_t_handler_json
1801 (vl_api_get_first_msg_id_reply_t * mp)
1803 vat_main_t * vam = &vat_main;
1804 vat_json_node_t node;
1806 vat_json_init_object(&node);
1807 vat_json_object_add_int(&node, "retval", ntohl(mp->retval));
1808 vat_json_object_add_uint(&node, "first_msg_id",
1809 (uint) ntohs(mp->first_msg_id));
1811 vat_json_print(vam->ofp, &node);
1812 vat_json_free(&node);
1814 vam->retval = ntohl(mp->retval);
1815 vam->result_ready = 1;
1818 static void vl_api_get_node_graph_reply_t_handler
1819 (vl_api_get_node_graph_reply_t * mp)
1821 vat_main_t * vam = &vat_main;
1822 api_main_t * am = &api_main;
1823 i32 retval = ntohl(mp->retval);
1824 u8 * pvt_copy, * reply;
1829 if (vam->async_mode) {
1830 vam->async_errors += (retval < 0);
1832 vam->retval = retval;
1833 vam->result_ready = 1;
1836 /* "Should never happen..." */
1840 reply = (u8 *)(mp->reply_in_shmem);
1841 pvt_copy = vec_dup (reply);
1843 /* Toss the shared-memory original... */
1844 pthread_mutex_lock (&am->vlib_rp->mutex);
1845 oldheap = svm_push_data_heap (am->vlib_rp);
1849 svm_pop_heap (oldheap);
1850 pthread_mutex_unlock (&am->vlib_rp->mutex);
1852 if (vam->graph_nodes) {
1853 hash_free (vam->graph_node_index_by_name);
1855 for (i = 0; i < vec_len (vam->graph_nodes); i++) {
1856 node = vam->graph_nodes[i];
1857 vec_free (node->name);
1858 vec_free (node->next_nodes);
1861 vec_free(vam->graph_nodes);
1864 vam->graph_node_index_by_name = hash_create_string (0, sizeof(uword));
1865 vam->graph_nodes = vlib_node_unserialize (pvt_copy);
1866 vec_free (pvt_copy);
1868 for (i = 0; i < vec_len (vam->graph_nodes); i++) {
1869 node = vam->graph_nodes[i];
1870 hash_set_mem (vam->graph_node_index_by_name, node->name, i);
1874 static void vl_api_get_node_graph_reply_t_handler_json
1875 (vl_api_get_node_graph_reply_t * mp)
1877 vat_main_t * vam = &vat_main;
1878 api_main_t * am = &api_main;
1880 vat_json_node_t node;
1883 /* $$$$ make this real? */
1884 vat_json_init_object(&node);
1885 vat_json_object_add_int(&node, "retval", ntohl(mp->retval));
1886 vat_json_object_add_uint(&node, "reply_in_shmem", mp->reply_in_shmem);
1888 reply = (u8 *)(mp->reply_in_shmem);
1890 /* Toss the shared-memory original... */
1891 pthread_mutex_lock (&am->vlib_rp->mutex);
1892 oldheap = svm_push_data_heap (am->vlib_rp);
1896 svm_pop_heap (oldheap);
1897 pthread_mutex_unlock (&am->vlib_rp->mutex);
1899 vat_json_print(vam->ofp, &node);
1900 vat_json_free(&node);
1902 vam->retval = ntohl(mp->retval);
1903 vam->result_ready = 1;
1907 vl_api_lisp_locator_set_details_t_handler (
1908 vl_api_lisp_locator_set_details_t *mp)
1910 vat_main_t *vam = &vat_main;
1912 fformat(vam->ofp, "%=20s%=16d%=16d%=16d\n",
1913 mp->locator_set_name,
1914 ntohl(mp->sw_if_index),
1920 vl_api_lisp_locator_set_details_t_handler_json (
1921 vl_api_lisp_locator_set_details_t *mp)
1923 vat_main_t *vam = &vat_main;
1924 vat_json_node_t *node = NULL;
1926 if (VAT_JSON_ARRAY != vam->json_tree.type) {
1927 ASSERT(VAT_JSON_NONE == vam->json_tree.type);
1928 vat_json_init_array(&vam->json_tree);
1930 node = vat_json_array_add(&vam->json_tree);
1932 vat_json_init_object(node);
1933 vat_json_object_add_string_copy(node, "locator-set", mp->locator_set_name);
1934 vat_json_object_add_uint(node, "locator", ntohl(mp->sw_if_index));
1935 vat_json_object_add_uint(node, "priority", mp->priority);
1936 vat_json_object_add_uint(node, "weight", mp->weight);
1940 vl_api_lisp_local_eid_table_details_t_handler (
1941 vl_api_lisp_local_eid_table_details_t *mp)
1943 vat_main_t *vam = &vat_main;
1946 prefix = format(0, "%U/%d",
1947 mp->eid_is_ipv6 ? format_ip6_address : format_ip4_address,
1949 mp->eid_prefix_len);
1951 fformat(vam->ofp, "%=20s%=30s\n",
1952 mp->locator_set_name, prefix);
1958 vl_api_lisp_local_eid_table_details_t_handler_json (
1959 vl_api_lisp_local_eid_table_details_t *mp)
1961 vat_main_t *vam = &vat_main;
1962 vat_json_node_t *node = NULL;
1963 struct in6_addr ip6;
1966 if (VAT_JSON_ARRAY != vam->json_tree.type) {
1967 ASSERT(VAT_JSON_NONE == vam->json_tree.type);
1968 vat_json_init_array(&vam->json_tree);
1970 node = vat_json_array_add(&vam->json_tree);
1972 vat_json_init_object(node);
1973 vat_json_object_add_string_copy(node, "locator-set", mp->locator_set_name);
1974 if (mp->eid_is_ipv6) {
1975 clib_memcpy(&ip6, mp->eid_ip_address, sizeof(ip6));
1976 vat_json_object_add_ip6(node, "eid address", ip6);
1978 clib_memcpy(&ip4, mp->eid_ip_address, sizeof(ip4));
1979 vat_json_object_add_ip4(node, "eid address", ip4);
1981 vat_json_object_add_uint(node, "eid prefix len", mp->eid_prefix_len);
1985 format_decap_next (u8 * s, va_list * args)
1987 u32 next_index = va_arg (*args, u32);
1991 case LISP_GPE_INPUT_NEXT_DROP:
1992 return format (s, "drop");
1993 case LISP_GPE_INPUT_NEXT_IP4_INPUT:
1994 return format (s, "ip4");
1995 case LISP_GPE_INPUT_NEXT_IP6_INPUT:
1996 return format (s, "ip6");
1998 return format (s, "unknown %d", next_index);
2004 vl_api_lisp_gpe_tunnel_details_t_handler (vl_api_lisp_gpe_tunnel_details_t *mp)
2006 vat_main_t *vam = &vat_main;
2008 u8 *flag_str = NULL;
2010 iid_str = format(0, "%d (0x%x)", ntohl(mp->iid), ntohl(mp->iid));
2012 #define _(n,v) if (mp->flags & v) flag_str = format (flag_str, "%s-bit ", #n);
2013 foreach_lisp_gpe_flag_bit;
2016 fformat(vam->ofp, "%=20d%=30U%=16U%=16d%=16d%=16U"
2017 "%=16d%=16d%=16sd=16d%=16s%=16s\n",
2019 mp->is_ipv6 ? format_ip6_address : format_ip4_address,
2021 mp->is_ipv6 ? format_ip6_address : format_ip4_address,
2023 ntohl(mp->encap_fib_id),
2024 ntohl(mp->decap_fib_id),
2025 format_decap_next, ntohl(mp->dcap_next),
2037 vl_api_lisp_gpe_tunnel_details_t_handler_json (
2038 vl_api_lisp_gpe_tunnel_details_t *mp)
2040 vat_main_t *vam = &vat_main;
2041 vat_json_node_t *node = NULL;
2042 struct in6_addr ip6;
2046 next_decap_str = format(0, "%U", format_decap_next, htonl(mp->dcap_next));
2048 if (VAT_JSON_ARRAY != vam->json_tree.type) {
2049 ASSERT(VAT_JSON_NONE == vam->json_tree.type);
2050 vat_json_init_array(&vam->json_tree);
2052 node = vat_json_array_add(&vam->json_tree);
2054 vat_json_init_object(node);
2055 vat_json_object_add_uint(node, "tunel", mp->tunnels);
2057 clib_memcpy(&ip6, mp->source_ip, sizeof(ip6));
2058 vat_json_object_add_ip6(node, "source address", ip6);
2059 clib_memcpy(&ip6, mp->destination_ip, sizeof(ip6));
2060 vat_json_object_add_ip6(node, "destination address", ip6);
2062 clib_memcpy(&ip4, mp->source_ip, sizeof(ip4));
2063 vat_json_object_add_ip4(node, "source address", ip4);
2064 clib_memcpy(&ip4, mp->destination_ip, sizeof(ip4));
2065 vat_json_object_add_ip4(node, "destination address", ip4);
2067 vat_json_object_add_uint(node, "fib encap", ntohl(mp->encap_fib_id));
2068 vat_json_object_add_uint(node, "fib decap", ntohl(mp->decap_fib_id));
2069 vat_json_object_add_string_copy(node, "decap next", next_decap_str);
2070 vat_json_object_add_uint(node, "lisp version", mp->ver_res >> 6);
2071 vat_json_object_add_uint(node, "flags", mp->flags);
2072 vat_json_object_add_uint(node, "next protocol", mp->next_protocol);
2073 vat_json_object_add_uint(node, "ver_res", mp->ver_res);
2074 vat_json_object_add_uint(node, "res", mp->res);
2075 vat_json_object_add_uint(node, "iid", ntohl(mp->iid));
2077 vec_free(next_decap_str);
2081 vl_api_lisp_map_resolver_details_t_handler (
2082 vl_api_lisp_map_resolver_details_t *mp)
2084 vat_main_t *vam = &vat_main;
2086 fformat(vam->ofp, "%=20U\n",
2087 mp->is_ipv6 ? format_ip6_address : format_ip4_address,
2092 vl_api_lisp_map_resolver_details_t_handler_json (
2093 vl_api_lisp_map_resolver_details_t *mp)
2095 vat_main_t *vam = &vat_main;
2096 vat_json_node_t *node = NULL;
2097 struct in6_addr ip6;
2100 if (VAT_JSON_ARRAY != vam->json_tree.type) {
2101 ASSERT(VAT_JSON_NONE == vam->json_tree.type);
2102 vat_json_init_array(&vam->json_tree);
2104 node = vat_json_array_add(&vam->json_tree);
2106 vat_json_init_object(node);
2108 clib_memcpy(&ip6, mp->ip_address, sizeof(ip6));
2109 vat_json_object_add_ip6(node, "map resolver", ip6);
2111 clib_memcpy(&ip4, mp->ip_address, sizeof(ip4));
2112 vat_json_object_add_ip4(node, "map resolver", ip4);
2116 #define vl_api_vnet_ip4_fib_counters_t_endian vl_noop_handler
2117 #define vl_api_vnet_ip4_fib_counters_t_print vl_noop_handler
2118 #define vl_api_vnet_ip6_fib_counters_t_endian vl_noop_handler
2119 #define vl_api_vnet_ip6_fib_counters_t_print vl_noop_handler
2122 * Generate boilerplate reply handlers, which
2123 * dig the return value out of the xxx_reply_t API message,
2124 * stick it into vam->retval, and set vam->result_ready
2126 * Could also do this by pointing N message decode slots at
2127 * a single function, but that could break in subtle ways.
2130 #define foreach_standard_reply_retval_handler \
2131 _(sw_interface_set_flags_reply) \
2132 _(sw_interface_add_del_address_reply) \
2133 _(sw_interface_set_table_reply) \
2134 _(sw_interface_set_vpath_reply) \
2135 _(sw_interface_set_l2_bridge_reply) \
2136 _(bridge_domain_add_del_reply) \
2137 _(sw_interface_set_l2_xconnect_reply) \
2138 _(l2fib_add_del_reply) \
2139 _(ip_add_del_route_reply) \
2140 _(proxy_arp_add_del_reply) \
2141 _(proxy_arp_intfc_enable_disable_reply) \
2142 _(mpls_add_del_encap_reply) \
2143 _(mpls_add_del_decap_reply) \
2144 _(mpls_ethernet_add_del_tunnel_2_reply) \
2145 _(sw_interface_set_unnumbered_reply) \
2146 _(ip_neighbor_add_del_reply) \
2147 _(reset_vrf_reply) \
2148 _(oam_add_del_reply) \
2149 _(reset_fib_reply) \
2150 _(dhcp_proxy_config_reply) \
2151 _(dhcp_proxy_config_2_reply) \
2152 _(dhcp_proxy_set_vss_reply) \
2153 _(dhcp_client_config_reply) \
2154 _(set_ip_flow_hash_reply) \
2155 _(sw_interface_ip6_enable_disable_reply) \
2156 _(sw_interface_ip6_set_link_local_address_reply) \
2157 _(sw_interface_ip6nd_ra_prefix_reply) \
2158 _(sw_interface_ip6nd_ra_config_reply) \
2159 _(set_arp_neighbor_limit_reply) \
2160 _(l2_patch_add_del_reply) \
2161 _(sr_tunnel_add_del_reply) \
2162 _(sr_policy_add_del_reply) \
2163 _(sr_multicast_map_add_del_reply) \
2164 _(classify_add_del_session_reply) \
2165 _(classify_set_interface_ip_table_reply) \
2166 _(classify_set_interface_l2_tables_reply) \
2167 _(l2tpv3_set_tunnel_cookies_reply) \
2168 _(l2tpv3_interface_enable_disable_reply) \
2169 _(l2tpv3_set_lookup_key_reply) \
2170 _(l2_fib_clear_table_reply) \
2171 _(l2_interface_efp_filter_reply) \
2172 _(l2_interface_vlan_tag_rewrite_reply) \
2173 _(modify_vhost_user_if_reply) \
2174 _(delete_vhost_user_if_reply) \
2175 _(want_ip4_arp_events_reply) \
2176 _(input_acl_set_interface_reply) \
2177 _(ipsec_spd_add_del_reply) \
2178 _(ipsec_interface_add_del_spd_reply) \
2179 _(ipsec_spd_add_del_entry_reply) \
2180 _(ipsec_sad_add_del_entry_reply) \
2181 _(ipsec_sa_set_key_reply) \
2182 _(ikev2_profile_add_del_reply) \
2183 _(ikev2_profile_set_auth_reply) \
2184 _(ikev2_profile_set_id_reply) \
2185 _(ikev2_profile_set_ts_reply) \
2186 _(ikev2_set_local_key_reply) \
2187 _(delete_loopback_reply) \
2188 _(bd_ip_mac_add_del_reply) \
2189 _(map_del_domain_reply) \
2190 _(map_add_del_rule_reply) \
2191 _(want_interface_events_reply) \
2192 _(want_stats_reply) \
2193 _(cop_interface_enable_disable_reply) \
2194 _(cop_whitelist_enable_disable_reply) \
2195 _(sw_interface_clear_stats_reply) \
2196 _(trace_profile_add_reply) \
2197 _(trace_profile_apply_reply) \
2198 _(trace_profile_del_reply) \
2199 _(lisp_add_del_locator_set_reply) \
2200 _(lisp_add_del_locator_reply) \
2201 _(lisp_add_del_local_eid_reply) \
2202 _(lisp_gpe_add_del_fwd_entry_reply) \
2203 _(lisp_add_del_map_resolver_reply) \
2204 _(lisp_gpe_enable_disable_reply) \
2205 _(lisp_gpe_add_del_iface_reply)
2208 static void vl_api_##n##_t_handler \
2209 (vl_api_##n##_t * mp) \
2211 vat_main_t * vam = &vat_main; \
2212 i32 retval = ntohl(mp->retval); \
2213 if (vam->async_mode) { \
2214 vam->async_errors += (retval < 0); \
2216 vam->retval = retval; \
2217 vam->result_ready = 1; \
2220 foreach_standard_reply_retval_handler;
2224 static void vl_api_##n##_t_handler_json \
2225 (vl_api_##n##_t * mp) \
2227 vat_main_t * vam = &vat_main; \
2228 vat_json_node_t node; \
2229 vat_json_init_object(&node); \
2230 vat_json_object_add_int(&node, "retval", ntohl(mp->retval)); \
2231 vat_json_print(vam->ofp, &node); \
2232 vam->retval = ntohl(mp->retval); \
2233 vam->result_ready = 1; \
2235 foreach_standard_reply_retval_handler;
2239 * Table of message reply handlers, must include boilerplate handlers
2243 #define foreach_vpe_api_reply_msg \
2244 _(CREATE_LOOPBACK_REPLY, create_loopback_reply) \
2245 _(SW_INTERFACE_DETAILS, sw_interface_details) \
2246 _(SW_INTERFACE_SET_FLAGS, sw_interface_set_flags) \
2247 _(SW_INTERFACE_SET_FLAGS_REPLY, sw_interface_set_flags_reply) \
2248 _(CONTROL_PING_REPLY, control_ping_reply) \
2249 _(CLI_REPLY, cli_reply) \
2250 _(SW_INTERFACE_ADD_DEL_ADDRESS_REPLY, \
2251 sw_interface_add_del_address_reply) \
2252 _(SW_INTERFACE_SET_TABLE_REPLY, sw_interface_set_table_reply) \
2253 _(SW_INTERFACE_SET_VPATH_REPLY, sw_interface_set_vpath_reply) \
2254 _(SW_INTERFACE_SET_L2_XCONNECT_REPLY, \
2255 sw_interface_set_l2_xconnect_reply) \
2256 _(SW_INTERFACE_SET_L2_BRIDGE_REPLY, \
2257 sw_interface_set_l2_bridge_reply) \
2258 _(BRIDGE_DOMAIN_ADD_DEL_REPLY, bridge_domain_add_del_reply) \
2259 _(BRIDGE_DOMAIN_DETAILS, bridge_domain_details) \
2260 _(BRIDGE_DOMAIN_SW_IF_DETAILS, bridge_domain_sw_if_details) \
2261 _(L2FIB_ADD_DEL_REPLY, l2fib_add_del_reply) \
2262 _(L2_FLAGS_REPLY, l2_flags_reply) \
2263 _(BRIDGE_FLAGS_REPLY, bridge_flags_reply) \
2264 _(TAP_CONNECT_REPLY, tap_connect_reply) \
2265 _(TAP_MODIFY_REPLY, tap_modify_reply) \
2266 _(TAP_DELETE_REPLY, tap_delete_reply) \
2267 _(SW_INTERFACE_TAP_DETAILS, sw_interface_tap_details) \
2268 _(IP_ADD_DEL_ROUTE_REPLY, ip_add_del_route_reply) \
2269 _(PROXY_ARP_ADD_DEL_REPLY, proxy_arp_add_del_reply) \
2270 _(PROXY_ARP_INTFC_ENABLE_DISABLE_REPLY, \
2271 proxy_arp_intfc_enable_disable_reply) \
2272 _(MPLS_ADD_DEL_ENCAP_REPLY, mpls_add_del_encap_reply) \
2273 _(MPLS_ADD_DEL_DECAP_REPLY, mpls_add_del_decap_reply) \
2274 _(MPLS_GRE_ADD_DEL_TUNNEL_REPLY, mpls_gre_add_del_tunnel_reply) \
2275 _(MPLS_ETHERNET_ADD_DEL_TUNNEL_REPLY, \
2276 mpls_ethernet_add_del_tunnel_reply) \
2277 _(MPLS_ETHERNET_ADD_DEL_TUNNEL_2_REPLY, \
2278 mpls_ethernet_add_del_tunnel_2_reply) \
2279 _(SW_INTERFACE_SET_UNNUMBERED_REPLY, \
2280 sw_interface_set_unnumbered_reply) \
2281 _(IP_NEIGHBOR_ADD_DEL_REPLY, ip_neighbor_add_del_reply) \
2282 _(RESET_VRF_REPLY, reset_vrf_reply) \
2283 _(CREATE_VLAN_SUBIF_REPLY, create_vlan_subif_reply) \
2284 _(CREATE_SUBIF_REPLY, create_subif_reply) \
2285 _(OAM_ADD_DEL_REPLY, oam_add_del_reply) \
2286 _(RESET_FIB_REPLY, reset_fib_reply) \
2287 _(DHCP_PROXY_CONFIG_REPLY, dhcp_proxy_config_reply) \
2288 _(DHCP_PROXY_CONFIG_2_REPLY, dhcp_proxy_config_2_reply) \
2289 _(DHCP_PROXY_SET_VSS_REPLY, dhcp_proxy_set_vss_reply) \
2290 _(DHCP_CLIENT_CONFIG_REPLY, dhcp_client_config_reply) \
2291 _(SET_IP_FLOW_HASH_REPLY, set_ip_flow_hash_reply) \
2292 _(SW_INTERFACE_IP6_ENABLE_DISABLE_REPLY, \
2293 sw_interface_ip6_enable_disable_reply) \
2294 _(SW_INTERFACE_IP6_SET_LINK_LOCAL_ADDRESS_REPLY, \
2295 sw_interface_ip6_set_link_local_address_reply) \
2296 _(SW_INTERFACE_IP6ND_RA_PREFIX_REPLY, \
2297 sw_interface_ip6nd_ra_prefix_reply) \
2298 _(SW_INTERFACE_IP6ND_RA_CONFIG_REPLY, \
2299 sw_interface_ip6nd_ra_config_reply) \
2300 _(SET_ARP_NEIGHBOR_LIMIT_REPLY, set_arp_neighbor_limit_reply) \
2301 _(L2_PATCH_ADD_DEL_REPLY, l2_patch_add_del_reply) \
2302 _(SR_TUNNEL_ADD_DEL_REPLY, sr_tunnel_add_del_reply) \
2303 _(SR_POLICY_ADD_DEL_REPLY, sr_policy_add_del_reply) \
2304 _(SR_MULTICAST_MAP_ADD_DEL_REPLY, sr_multicast_map_add_del_reply) \
2305 _(CLASSIFY_ADD_DEL_TABLE_REPLY, classify_add_del_table_reply) \
2306 _(CLASSIFY_ADD_DEL_SESSION_REPLY, classify_add_del_session_reply) \
2307 _(CLASSIFY_SET_INTERFACE_IP_TABLE_REPLY, \
2308 classify_set_interface_ip_table_reply) \
2309 _(CLASSIFY_SET_INTERFACE_L2_TABLES_REPLY, \
2310 classify_set_interface_l2_tables_reply) \
2311 _(GET_NODE_INDEX_REPLY, get_node_index_reply) \
2312 _(ADD_NODE_NEXT_REPLY, add_node_next_reply) \
2313 _(L2TPV3_CREATE_TUNNEL_REPLY, l2tpv3_create_tunnel_reply) \
2314 _(L2TPV3_SET_TUNNEL_COOKIES_REPLY, l2tpv3_set_tunnel_cookies_reply) \
2315 _(L2TPV3_INTERFACE_ENABLE_DISABLE_REPLY, \
2316 l2tpv3_interface_enable_disable_reply) \
2317 _(L2TPV3_SET_LOOKUP_KEY_REPLY, l2tpv3_set_lookup_key_reply) \
2318 _(SW_IF_L2TPV3_TUNNEL_DETAILS, sw_if_l2tpv3_tunnel_details) \
2319 _(VXLAN_ADD_DEL_TUNNEL_REPLY, vxlan_add_del_tunnel_reply) \
2320 _(VXLAN_TUNNEL_DETAILS, vxlan_tunnel_details) \
2321 _(GRE_ADD_DEL_TUNNEL_REPLY, gre_add_del_tunnel_reply) \
2322 _(GRE_TUNNEL_DETAILS, gre_tunnel_details) \
2323 _(L2_FIB_CLEAR_TABLE_REPLY, l2_fib_clear_table_reply) \
2324 _(L2_INTERFACE_EFP_FILTER_REPLY, l2_interface_efp_filter_reply) \
2325 _(L2_INTERFACE_VLAN_TAG_REWRITE_REPLY, l2_interface_vlan_tag_rewrite_reply) \
2326 _(SW_INTERFACE_VHOST_USER_DETAILS, sw_interface_vhost_user_details) \
2327 _(CREATE_VHOST_USER_IF_REPLY, create_vhost_user_if_reply) \
2328 _(MODIFY_VHOST_USER_IF_REPLY, modify_vhost_user_if_reply) \
2329 _(DELETE_VHOST_USER_IF_REPLY, delete_vhost_user_if_reply) \
2330 _(SHOW_VERSION_REPLY, show_version_reply) \
2331 _(NSH_GRE_ADD_DEL_TUNNEL_REPLY, nsh_gre_add_del_tunnel_reply) \
2332 _(L2_FIB_TABLE_ENTRY, l2_fib_table_entry) \
2333 _(NSH_VXLAN_GPE_ADD_DEL_TUNNEL_REPLY, nsh_vxlan_gpe_add_del_tunnel_reply) \
2334 _(LISP_GPE_ADD_DEL_TUNNEL_REPLY, lisp_gpe_add_del_tunnel_reply) \
2335 _(INTERFACE_NAME_RENUMBER_REPLY, interface_name_renumber_reply) \
2336 _(WANT_IP4_ARP_EVENTS_REPLY, want_ip4_arp_events_reply) \
2337 _(IP4_ARP_EVENT, ip4_arp_event) \
2338 _(INPUT_ACL_SET_INTERFACE_REPLY, input_acl_set_interface_reply) \
2339 _(IP_ADDRESS_DETAILS, ip_address_details) \
2340 _(IP_DETAILS, ip_details) \
2341 _(IPSEC_SPD_ADD_DEL_REPLY, ipsec_spd_add_del_reply) \
2342 _(IPSEC_INTERFACE_ADD_DEL_SPD_REPLY, ipsec_interface_add_del_spd_reply) \
2343 _(IPSEC_SPD_ADD_DEL_ENTRY_REPLY, ipsec_spd_add_del_entry_reply) \
2344 _(IPSEC_SAD_ADD_DEL_ENTRY_REPLY, ipsec_sad_add_del_entry_reply) \
2345 _(IPSEC_SA_SET_KEY_REPLY, ipsec_sa_set_key_reply) \
2346 _(IKEV2_PROFILE_ADD_DEL_REPLY, ikev2_profile_add_del_reply) \
2347 _(IKEV2_PROFILE_SET_AUTH_REPLY, ikev2_profile_set_auth_reply) \
2348 _(IKEV2_PROFILE_SET_ID_REPLY, ikev2_profile_set_id_reply) \
2349 _(IKEV2_PROFILE_SET_TS_REPLY, ikev2_profile_set_ts_reply) \
2350 _(IKEV2_SET_LOCAL_KEY_REPLY, ikev2_set_local_key_reply) \
2351 _(DELETE_LOOPBACK_REPLY, delete_loopback_reply) \
2352 _(BD_IP_MAC_ADD_DEL_REPLY, bd_ip_mac_add_del_reply) \
2353 _(DHCP_COMPL_EVENT, dhcp_compl_event) \
2354 _(VNET_INTERFACE_COUNTERS, vnet_interface_counters) \
2355 _(VNET_IP4_FIB_COUNTERS, vnet_ip4_fib_counters) \
2356 _(VNET_IP6_FIB_COUNTERS, vnet_ip6_fib_counters) \
2357 _(MAP_ADD_DOMAIN_REPLY, map_add_domain_reply) \
2358 _(MAP_DEL_DOMAIN_REPLY, map_del_domain_reply) \
2359 _(MAP_ADD_DEL_RULE_REPLY, map_add_del_rule_reply) \
2360 _(MAP_DOMAIN_DETAILS, map_domain_details) \
2361 _(MAP_RULE_DETAILS, map_rule_details) \
2362 _(WANT_INTERFACE_EVENTS_REPLY, want_interface_events_reply) \
2363 _(WANT_STATS_REPLY, want_stats_reply) \
2364 _(GET_FIRST_MSG_ID_REPLY, get_first_msg_id_reply) \
2365 _(COP_INTERFACE_ENABLE_DISABLE_REPLY, cop_interface_enable_disable_reply) \
2366 _(COP_WHITELIST_ENABLE_DISABLE_REPLY, cop_whitelist_enable_disable_reply) \
2367 _(GET_NODE_GRAPH_REPLY, get_node_graph_reply) \
2368 _(SW_INTERFACE_CLEAR_STATS_REPLY, sw_interface_clear_stats_reply) \
2369 _(TRACE_PROFILE_ADD_REPLY, trace_profile_add_reply) \
2370 _(TRACE_PROFILE_APPLY_REPLY, trace_profile_apply_reply) \
2371 _(TRACE_PROFILE_DEL_REPLY, trace_profile_del_reply) \
2372 _(LISP_ADD_DEL_LOCATOR_SET_REPLY, lisp_add_del_locator_set_reply) \
2373 _(LISP_ADD_DEL_LOCATOR_REPLY, lisp_add_del_locator_reply) \
2374 _(LISP_ADD_DEL_LOCAL_EID_REPLY, lisp_add_del_local_eid_reply) \
2375 _(LISP_GPE_ADD_DEL_FWD_ENTRY_REPLY, lisp_gpe_add_del_fwd_entry_reply) \
2376 _(LISP_ADD_DEL_MAP_RESOLVER_REPLY, lisp_add_del_map_resolver_reply) \
2377 _(LISP_GPE_ENABLE_DISABLE_REPLY, lisp_gpe_enable_disable_reply) \
2378 _(LISP_GPE_ADD_DEL_IFACE_REPLY, lisp_gpe_add_del_iface_reply) \
2379 _(LISP_LOCATOR_SET_DETAILS, lisp_locator_set_details) \
2380 _(LISP_LOCAL_EID_TABLE_DETAILS, lisp_local_eid_table_details) \
2381 _(LISP_GPE_TUNNEL_DETAILS, lisp_gpe_tunnel_details) \
2382 _(LISP_MAP_RESOLVER_DETAILS, lisp_map_resolver_details)
2384 /* M: construct, but don't yet send a message */
2388 vam->result_ready = 0; \
2389 mp = vl_msg_api_alloc(sizeof(*mp)); \
2390 memset (mp, 0, sizeof (*mp)); \
2391 mp->_vl_msg_id = ntohs (VL_API_##T); \
2392 mp->client_index = vam->my_client_index; \
2397 vam->result_ready = 0; \
2398 mp = vl_msg_api_alloc(sizeof(*mp)+(n)); \
2399 memset (mp, 0, sizeof (*mp)); \
2400 mp->_vl_msg_id = ntohs (VL_API_##T); \
2401 mp->client_index = vam->my_client_index; \
2405 /* S: send a message */
2406 #define S (vl_msg_api_send_shmem (vam->vl_input_queue, (u8 *)&mp))
2408 /* W: wait for results, with timeout */
2411 timeout = vat_time_now (vam) + 1.0; \
2413 while (vat_time_now (vam) < timeout) { \
2414 if (vam->result_ready == 1) { \
2415 return (vam->retval); \
2427 #define STR_VTR_OP_CASE(op) \
2428 case L2_VTR_ ## op: \
2431 static const char *str_vtr_op(u32 vtr_op)
2434 STR_VTR_OP_CASE(DISABLED);
2435 STR_VTR_OP_CASE(PUSH_1);
2436 STR_VTR_OP_CASE(PUSH_2);
2437 STR_VTR_OP_CASE(POP_1);
2438 STR_VTR_OP_CASE(POP_2);
2439 STR_VTR_OP_CASE(TRANSLATE_1_1);
2440 STR_VTR_OP_CASE(TRANSLATE_1_2);
2441 STR_VTR_OP_CASE(TRANSLATE_2_1);
2442 STR_VTR_OP_CASE(TRANSLATE_2_2);
2448 static int dump_sub_interface_table (vat_main_t * vam)
2450 const sw_interface_subif_t * sub = NULL;
2452 if (vam->json_output) {
2453 clib_warning ("JSON output supported only for VPE API calls and dump_stats_table");
2458 "%-30s%-12s%-11s%-7s%-5s%-9s%-9s%-6s%-8s%-10s%-10s\n",
2459 "Interface", "sw_if_index",
2460 "sub id", "dot1ad", "tags", "outer id",
2461 "inner id", "exact", "default",
2462 "outer any", "inner any");
2464 vec_foreach (sub, vam->sw_if_subif_table) {
2466 "%-30s%-12d%-11d%-7s%-5d%-9d%-9d%-6d%-8d%-10d%-10d\n",
2467 sub->interface_name,
2469 sub->sub_id, sub->sub_dot1ad ? "dot1ad" : "dot1q",
2470 sub->sub_number_of_tags, sub->sub_outer_vlan_id,
2471 sub->sub_inner_vlan_id, sub->sub_exact_match, sub->sub_default,
2472 sub->sub_outer_vlan_id_any, sub->sub_inner_vlan_id_any);
2473 if (sub->vtr_op != L2_VTR_DISABLED) {
2475 " vlan-tag-rewrite - op: %-14s [ dot1q: %d "
2476 "tag1: %d tag2: %d ]\n",
2477 str_vtr_op(sub->vtr_op), sub->vtr_push_dot1q,
2478 sub->vtr_tag1, sub->vtr_tag2);
2485 static int name_sort_cmp (void * a1, void * a2)
2487 name_sort_t * n1 = a1;
2488 name_sort_t * n2 = a2;
2490 return strcmp ((char *)n1->name, (char *)n2->name);
2493 static int dump_interface_table (vat_main_t * vam)
2496 name_sort_t * nses = 0, * ns;
2498 if (vam->json_output) {
2499 clib_warning ("JSON output supported only for VPE API calls and dump_stats_table");
2503 hash_foreach_pair (p, vam->sw_if_index_by_interface_name,
2505 vec_add2 (nses, ns, 1);
2506 ns->name = (u8 *)(p->key);
2507 ns->value = (u32) p->value[0];
2510 vec_sort_with_function (nses, name_sort_cmp);
2512 fformat (vam->ofp, "%-25s%-15s\n", "Interface", "sw_if_index");
2513 vec_foreach (ns, nses) {
2514 fformat (vam->ofp, "%-25s%-15d\n", ns->name, ns->value);
2520 static int dump_ip_table (vat_main_t * vam, int is_ipv6)
2522 const ip_details_t * det = NULL;
2523 const ip_address_details_t * address = NULL;
2534 vec_foreach (det, vam->ip_details_by_sw_if_index[is_ipv6]) {
2536 if (!det->present) {
2544 "Address", "Prefix length");
2548 vec_foreach (address, det->addr) {
2551 is_ipv6 ? format_ip6_address : format_ip4_address,
2553 address->prefix_length);
2560 static int dump_ipv4_table (vat_main_t * vam)
2562 if (vam->json_output) {
2563 clib_warning ("JSON output supported only for VPE API calls and dump_stats_table");
2567 return dump_ip_table (vam, 0);
2570 static int dump_ipv6_table (vat_main_t * vam)
2572 if (vam->json_output) {
2573 clib_warning ("JSON output supported only for VPE API calls and dump_stats_table");
2577 return dump_ip_table (vam, 1);
2580 static char* counter_type_to_str (u8 counter_type, u8 is_combined)
2583 switch(counter_type) {
2584 case VNET_INTERFACE_COUNTER_DROP:
2586 case VNET_INTERFACE_COUNTER_PUNT:
2588 case VNET_INTERFACE_COUNTER_IP4:
2590 case VNET_INTERFACE_COUNTER_IP6:
2592 case VNET_INTERFACE_COUNTER_RX_NO_BUF:
2594 case VNET_INTERFACE_COUNTER_RX_MISS:
2596 case VNET_INTERFACE_COUNTER_RX_ERROR:
2598 case VNET_INTERFACE_COUNTER_TX_ERROR:
2601 return "INVALID-COUNTER-TYPE";
2604 switch(counter_type) {
2605 case VNET_INTERFACE_COUNTER_RX:
2607 case VNET_INTERFACE_COUNTER_TX:
2610 return "INVALID-COUNTER-TYPE";
2615 static int dump_stats_table (vat_main_t * vam)
2617 vat_json_node_t node;
2618 vat_json_node_t *msg_array;
2619 vat_json_node_t *msg;
2620 vat_json_node_t *counter_array;
2621 vat_json_node_t *counter;
2622 interface_counter_t c;
2624 ip4_fib_counter_t *c4;
2625 ip6_fib_counter_t *c6;
2628 if (!vam->json_output) {
2629 clib_warning ("dump_stats_table supported only in JSON format");
2633 vat_json_init_object(&node);
2635 /* interface counters */
2636 msg_array = vat_json_object_add(&node, "interface_counters");
2637 vat_json_init_array(msg_array);
2638 for (i = 0; i < vec_len(vam->simple_interface_counters); i++) {
2639 msg = vat_json_array_add(msg_array);
2640 vat_json_init_object(msg);
2641 vat_json_object_add_string_copy(msg, "vnet_counter_type",
2642 (u8*)counter_type_to_str(i, 0));
2643 vat_json_object_add_int(msg, "is_combined", 0);
2644 counter_array = vat_json_object_add(msg, "data");
2645 vat_json_init_array(counter_array);
2646 for (j = 0; j < vec_len(vam->simple_interface_counters[i]); j++) {
2647 packets = vam->simple_interface_counters[i][j];
2648 vat_json_array_add_uint(counter_array, packets);
2651 for (i = 0; i < vec_len(vam->combined_interface_counters); i++) {
2652 msg = vat_json_array_add(msg_array);
2653 vat_json_init_object(msg);
2654 vat_json_object_add_string_copy(msg, "vnet_counter_type",
2655 (u8*)counter_type_to_str(i, 1));
2656 vat_json_object_add_int(msg, "is_combined", 1);
2657 counter_array = vat_json_object_add(msg, "data");
2658 vat_json_init_array(counter_array);
2659 for (j = 0; j < vec_len(vam->combined_interface_counters[i]); j++) {
2660 c = vam->combined_interface_counters[i][j];
2661 counter = vat_json_array_add(counter_array);
2662 vat_json_init_object(counter);
2663 vat_json_object_add_uint(counter, "packets", c.packets);
2664 vat_json_object_add_uint(counter, "bytes", c.bytes);
2668 /* ip4 fib counters */
2669 msg_array = vat_json_object_add(&node, "ip4_fib_counters");
2670 vat_json_init_array(msg_array);
2671 for (i = 0; i < vec_len(vam->ip4_fib_counters); i++) {
2672 msg = vat_json_array_add(msg_array);
2673 vat_json_init_object(msg);
2674 vat_json_object_add_uint(msg, "vrf_id", vam->ip4_fib_counters_vrf_id_by_index[i]);
2675 counter_array = vat_json_object_add(msg, "c");
2676 vat_json_init_array(counter_array);
2677 for (j = 0; j < vec_len(vam->ip4_fib_counters[i]); j++) {
2678 counter = vat_json_array_add(counter_array);
2679 vat_json_init_object(counter);
2680 c4 = &vam->ip4_fib_counters[i][j];
2681 vat_json_object_add_ip4(counter, "address", c4->address);
2682 vat_json_object_add_uint(counter, "address_length", c4->address_length);
2683 vat_json_object_add_uint(counter, "packets", c4->packets);
2684 vat_json_object_add_uint(counter, "bytes", c4->bytes);
2688 /* ip6 fib counters */
2689 msg_array = vat_json_object_add(&node, "ip6_fib_counters");
2690 vat_json_init_array(msg_array);
2691 for (i = 0; i < vec_len(vam->ip6_fib_counters); i++) {
2692 msg = vat_json_array_add(msg_array);
2693 vat_json_init_object(msg);
2694 vat_json_object_add_uint(msg, "vrf_id", vam->ip6_fib_counters_vrf_id_by_index[i]);
2695 counter_array = vat_json_object_add(msg, "c");
2696 vat_json_init_array(counter_array);
2697 for (j = 0; j < vec_len(vam->ip6_fib_counters[i]); j++) {
2698 counter = vat_json_array_add(counter_array);
2699 vat_json_init_object(counter);
2700 c6 = &vam->ip6_fib_counters[i][j];
2701 vat_json_object_add_ip6(counter, "address", c6->address);
2702 vat_json_object_add_uint(counter, "address_length", c6->address_length);
2703 vat_json_object_add_uint(counter, "packets", c6->packets);
2704 vat_json_object_add_uint(counter, "bytes", c6->bytes);
2708 vat_json_print(vam->ofp, &node);
2709 vat_json_free(&node);
2714 int exec (vat_main_t * vam)
2716 api_main_t * am = &api_main;
2717 vl_api_cli_request_t *mp;
2721 unformat_input_t * i = vam->input;
2723 if (vec_len(i->buffer) == 0)
2726 if (vam->exec_mode == 0 && unformat (i, "mode")) {
2730 if (vam->exec_mode == 1 &&
2731 (unformat (i, "exit") || unformat (i, "quit"))) {
2737 M(CLI_REQUEST, cli_request);
2740 * Copy cmd into shared memory.
2741 * In order for the CLI command to work, it
2742 * must be a vector ending in \n, not a C-string ending
2745 pthread_mutex_lock (&am->vlib_rp->mutex);
2746 oldheap = svm_push_data_heap (am->vlib_rp);
2748 vec_validate (cmd, vec_len(vam->input->buffer)-1);
2749 clib_memcpy (cmd, vam->input->buffer, vec_len(vam->input->buffer));
2751 svm_pop_heap (oldheap);
2752 pthread_mutex_unlock (&am->vlib_rp->mutex);
2754 mp->cmd_in_shmem = (u64) cmd;
2756 timeout = vat_time_now (vam) + 10.0;
2758 while (vat_time_now (vam) < timeout) {
2759 if (vam->result_ready == 1) {
2761 if (vam->shmem_result != NULL)
2762 fformat (vam->ofp, "%s", vam->shmem_result);
2763 pthread_mutex_lock (&am->vlib_rp->mutex);
2764 oldheap = svm_push_data_heap (am->vlib_rp);
2766 free_me = (u8 *)vam->shmem_result;
2769 svm_pop_heap (oldheap);
2770 pthread_mutex_unlock (&am->vlib_rp->mutex);
2777 static int api_create_loopback (vat_main_t * vam)
2779 unformat_input_t * i = vam->input;
2780 vl_api_create_loopback_t *mp;
2785 memset (mac_address, 0, sizeof (mac_address));
2787 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
2789 if (unformat (i, "mac %U", unformat_ethernet_address, mac_address))
2795 /* Construct the API message */
2796 M(CREATE_LOOPBACK, create_loopback);
2798 clib_memcpy (mp->mac_address, mac_address, sizeof (mac_address));
2803 static int api_delete_loopback (vat_main_t * vam)
2805 unformat_input_t * i = vam->input;
2806 vl_api_delete_loopback_t *mp;
2808 u32 sw_if_index = ~0;
2810 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
2812 if (unformat (i, "sw_if_index %d", &sw_if_index))
2818 if (sw_if_index == ~0)
2820 errmsg ("missing sw_if_index\n");
2824 /* Construct the API message */
2825 M(DELETE_LOOPBACK, delete_loopback);
2826 mp->sw_if_index = ntohl (sw_if_index);
2831 static int api_want_stats (vat_main_t * vam)
2833 unformat_input_t * i = vam->input;
2834 vl_api_want_stats_t * mp;
2838 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
2840 if (unformat (i, "enable"))
2842 else if (unformat (i, "disable"))
2850 errmsg ("missing enable|disable\n");
2854 M(WANT_STATS, want_stats);
2855 mp->enable_disable = enable;
2860 static int api_want_interface_events (vat_main_t * vam)
2862 unformat_input_t * i = vam->input;
2863 vl_api_want_interface_events_t * mp;
2867 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
2869 if (unformat (i, "enable"))
2871 else if (unformat (i, "disable"))
2879 errmsg ("missing enable|disable\n");
2883 M(WANT_INTERFACE_EVENTS, want_interface_events);
2884 mp->enable_disable = enable;
2886 vam->interface_event_display = enable;
2892 /* Note: non-static, called once to set up the initial intfc table */
2893 int api_sw_interface_dump (vat_main_t * vam)
2895 vl_api_sw_interface_dump_t *mp;
2898 name_sort_t * nses = 0, * ns;
2899 sw_interface_subif_t * sub = NULL;
2901 /* Toss the old name table */
2902 hash_foreach_pair (p, vam->sw_if_index_by_interface_name,
2904 vec_add2 (nses, ns, 1);
2905 ns->name = (u8 *)(p->key);
2906 ns->value = (u32) p->value[0];
2909 hash_free (vam->sw_if_index_by_interface_name);
2911 vec_foreach (ns, nses)
2912 vec_free (ns->name);
2916 vec_foreach (sub, vam->sw_if_subif_table) {
2917 vec_free (sub->interface_name);
2919 vec_free (vam->sw_if_subif_table);
2921 /* recreate the interface name hash table */
2922 vam->sw_if_index_by_interface_name
2923 = hash_create_string (0, sizeof(uword));
2925 /* Get list of ethernets */
2926 M(SW_INTERFACE_DUMP, sw_interface_dump);
2927 mp->name_filter_valid = 1;
2928 strncpy ((char *) mp->name_filter, "Ether", sizeof(mp->name_filter)-1);
2931 /* and local / loopback interfaces */
2932 M(SW_INTERFACE_DUMP, sw_interface_dump);
2933 mp->name_filter_valid = 1;
2934 strncpy ((char *) mp->name_filter, "lo", sizeof(mp->name_filter)-1);
2937 /* and vxlan tunnel interfaces */
2938 M(SW_INTERFACE_DUMP, sw_interface_dump);
2939 mp->name_filter_valid = 1;
2940 strncpy ((char *) mp->name_filter, "vxlan", sizeof(mp->name_filter)-1);
2943 /* and host (af_packet) interfaces */
2944 M(SW_INTERFACE_DUMP, sw_interface_dump);
2945 mp->name_filter_valid = 1;
2946 strncpy ((char *) mp->name_filter, "host", sizeof(mp->name_filter)-1);
2949 /* and l2tpv3 tunnel interfaces */
2950 M(SW_INTERFACE_DUMP, sw_interface_dump);
2951 mp->name_filter_valid = 1;
2952 strncpy ((char *) mp->name_filter, "l2tpv3_tunnel", sizeof(mp->name_filter)-1);
2955 /* Use a control ping for synchronization */
2957 vl_api_control_ping_t * mp;
2958 M(CONTROL_PING, control_ping);
2964 static int api_sw_interface_set_flags (vat_main_t * vam)
2966 unformat_input_t * i = vam->input;
2967 vl_api_sw_interface_set_flags_t *mp;
2970 u8 sw_if_index_set = 0;
2971 u8 admin_up = 0, link_up = 0;
2973 /* Parse args required to build the message */
2974 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
2975 if (unformat (i, "admin-up"))
2977 else if (unformat (i, "admin-down"))
2979 else if (unformat (i, "link-up"))
2981 else if (unformat (i, "link-down"))
2983 else if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
2984 sw_if_index_set = 1;
2985 else if (unformat (i, "sw_if_index %d", &sw_if_index))
2986 sw_if_index_set = 1;
2991 if (sw_if_index_set == 0) {
2992 errmsg ("missing interface name or sw_if_index\n");
2996 /* Construct the API message */
2997 M(SW_INTERFACE_SET_FLAGS, sw_interface_set_flags);
2998 mp->sw_if_index = ntohl (sw_if_index);
2999 mp->admin_up_down = admin_up;
3000 mp->link_up_down = link_up;
3005 /* Wait for a reply, return the good/bad news... */
3009 static int api_sw_interface_clear_stats (vat_main_t * vam)
3011 unformat_input_t * i = vam->input;
3012 vl_api_sw_interface_clear_stats_t *mp;
3015 u8 sw_if_index_set = 0;
3017 /* Parse args required to build the message */
3018 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
3019 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
3020 sw_if_index_set = 1;
3021 else if (unformat (i, "sw_if_index %d", &sw_if_index))
3022 sw_if_index_set = 1;
3027 /* Construct the API message */
3028 M(SW_INTERFACE_CLEAR_STATS, sw_interface_clear_stats);
3030 if (sw_if_index_set == 1)
3031 mp->sw_if_index = ntohl (sw_if_index);
3033 mp->sw_if_index = ~0;
3038 /* Wait for a reply, return the good/bad news... */
3042 static int api_sw_interface_add_del_address (vat_main_t * vam)
3044 unformat_input_t * i = vam->input;
3045 vl_api_sw_interface_add_del_address_t *mp;
3048 u8 sw_if_index_set = 0;
3049 u8 is_add = 1, del_all = 0;
3050 u32 address_length = 0;
3051 u8 v4_address_set = 0;
3052 u8 v6_address_set = 0;
3053 ip4_address_t v4address;
3054 ip6_address_t v6address;
3056 /* Parse args required to build the message */
3057 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
3058 if (unformat (i, "del-all"))
3060 else if (unformat (i, "del"))
3062 else if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
3063 sw_if_index_set = 1;
3064 else if (unformat (i, "sw_if_index %d", &sw_if_index))
3065 sw_if_index_set = 1;
3066 else if (unformat (i, "%U/%d",
3067 unformat_ip4_address, &v4address,
3070 else if (unformat (i, "%U/%d",
3071 unformat_ip6_address, &v6address,
3078 if (sw_if_index_set == 0) {
3079 errmsg ("missing interface name or sw_if_index\n");
3082 if (v4_address_set && v6_address_set) {
3083 errmsg ("both v4 and v6 addresses set\n");
3086 if (!v4_address_set && !v6_address_set && !del_all) {
3087 errmsg ("no addresses set\n");
3091 /* Construct the API message */
3092 M(SW_INTERFACE_ADD_DEL_ADDRESS, sw_interface_add_del_address);
3094 mp->sw_if_index = ntohl (sw_if_index);
3095 mp->is_add = is_add;
3096 mp->del_all = del_all;
3097 if (v6_address_set) {
3099 clib_memcpy (mp->address, &v6address, sizeof (v6address));
3101 clib_memcpy (mp->address, &v4address, sizeof (v4address));
3103 mp->address_length = address_length;
3108 /* Wait for a reply, return good/bad news */
3112 static int api_sw_interface_set_table (vat_main_t * vam)
3114 unformat_input_t * i = vam->input;
3115 vl_api_sw_interface_set_table_t *mp;
3117 u32 sw_if_index, vrf_id = 0;
3118 u8 sw_if_index_set = 0;
3121 /* Parse args required to build the message */
3122 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
3123 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
3124 sw_if_index_set = 1;
3125 else if (unformat (i, "sw_if_index %d", &sw_if_index))
3126 sw_if_index_set = 1;
3127 else if (unformat (i, "vrf %d", &vrf_id))
3129 else if (unformat (i, "ipv6"))
3135 if (sw_if_index_set == 0) {
3136 errmsg ("missing interface name or sw_if_index\n");
3140 /* Construct the API message */
3141 M(SW_INTERFACE_SET_TABLE, sw_interface_set_table);
3143 mp->sw_if_index = ntohl (sw_if_index);
3144 mp->is_ipv6 = is_ipv6;
3145 mp->vrf_id = ntohl (vrf_id);
3150 /* Wait for a reply... */
3154 static int api_sw_interface_set_vpath (vat_main_t * vam)
3156 unformat_input_t * i = vam->input;
3157 vl_api_sw_interface_set_vpath_t *mp;
3159 u32 sw_if_index = 0;
3160 u8 sw_if_index_set = 0;
3163 /* Parse args required to build the message */
3164 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
3165 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
3166 sw_if_index_set = 1;
3167 else if (unformat (i, "sw_if_index %d", &sw_if_index))
3168 sw_if_index_set = 1;
3169 else if (unformat (i, "enable"))
3171 else if (unformat (i, "disable"))
3177 if (sw_if_index_set == 0) {
3178 errmsg ("missing interface name or sw_if_index\n");
3182 /* Construct the API message */
3183 M(SW_INTERFACE_SET_VPATH, sw_interface_set_vpath);
3185 mp->sw_if_index = ntohl (sw_if_index);
3186 mp->enable = is_enable;
3191 /* Wait for a reply... */
3195 static int api_sw_interface_set_l2_xconnect (vat_main_t * vam)
3197 unformat_input_t * i = vam->input;
3198 vl_api_sw_interface_set_l2_xconnect_t *mp;
3201 u8 rx_sw_if_index_set = 0;
3203 u8 tx_sw_if_index_set = 0;
3206 /* Parse args required to build the message */
3207 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
3208 if (unformat (i, "rx_sw_if_index %d", &rx_sw_if_index))
3209 rx_sw_if_index_set = 1;
3210 else if (unformat (i, "tx_sw_if_index %d", &tx_sw_if_index))
3211 tx_sw_if_index_set = 1;
3212 else if (unformat (i, "rx")) {
3213 if (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
3214 if (unformat (i, "%U", unformat_sw_if_index, vam,
3216 rx_sw_if_index_set = 1;
3219 } else if (unformat (i, "tx")) {
3220 if (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
3221 if (unformat (i, "%U", unformat_sw_if_index, vam,
3223 tx_sw_if_index_set = 1;
3226 } else if (unformat (i, "enable"))
3228 else if (unformat (i, "disable"))
3234 if (rx_sw_if_index_set == 0) {
3235 errmsg ("missing rx interface name or rx_sw_if_index\n");
3239 if (enable && (tx_sw_if_index_set == 0)) {
3240 errmsg ("missing tx interface name or tx_sw_if_index\n");
3244 M(SW_INTERFACE_SET_L2_XCONNECT, sw_interface_set_l2_xconnect);
3246 mp->rx_sw_if_index = ntohl(rx_sw_if_index);
3247 mp->tx_sw_if_index = ntohl(tx_sw_if_index);
3248 mp->enable = enable;
3255 static int api_sw_interface_set_l2_bridge (vat_main_t * vam)
3257 unformat_input_t * i = vam->input;
3258 vl_api_sw_interface_set_l2_bridge_t *mp;
3261 u8 rx_sw_if_index_set = 0;
3268 /* Parse args required to build the message */
3269 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
3270 if (unformat (i, "sw_if_index %d", &rx_sw_if_index))
3271 rx_sw_if_index_set = 1;
3272 else if (unformat (i, "bd_id %d", &bd_id))
3274 else if (unformat (i, "%U", unformat_sw_if_index, vam,
3276 rx_sw_if_index_set = 1;
3277 else if (unformat (i, "shg %d", &shg))
3279 else if (unformat (i, "bvi"))
3281 else if (unformat (i, "enable"))
3283 else if (unformat (i, "disable"))
3289 if (rx_sw_if_index_set == 0) {
3290 errmsg ("missing rx interface name or sw_if_index\n");
3294 if (enable && (bd_id_set == 0)) {
3295 errmsg ("missing bridge domain\n");
3299 M(SW_INTERFACE_SET_L2_BRIDGE, sw_interface_set_l2_bridge);
3301 mp->rx_sw_if_index = ntohl(rx_sw_if_index);
3302 mp->bd_id = ntohl(bd_id);
3305 mp->enable = enable;
3312 static int api_bridge_domain_dump (vat_main_t * vam)
3314 unformat_input_t * i = vam->input;
3315 vl_api_bridge_domain_dump_t *mp;
3319 /* Parse args required to build the message */
3320 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
3321 if (unformat (i, "bd_id %d", &bd_id))
3327 M(BRIDGE_DOMAIN_DUMP, bridge_domain_dump);
3328 mp->bd_id = ntohl(bd_id);
3331 /* Use a control ping for synchronization */
3333 vl_api_control_ping_t * mp;
3334 M(CONTROL_PING, control_ping);
3343 static int api_bridge_domain_add_del (vat_main_t * vam)
3345 unformat_input_t * i = vam->input;
3346 vl_api_bridge_domain_add_del_t *mp;
3350 u32 flood = 1, forward = 1, learn = 1, uu_flood = 1, arp_term = 0;
3352 /* Parse args required to build the message */
3353 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
3354 if (unformat (i, "bd_id %d", &bd_id))
3356 else if (unformat (i, "flood %d", &flood))
3358 else if (unformat (i, "uu-flood %d", &uu_flood))
3360 else if (unformat (i, "forward %d", &forward))
3362 else if (unformat (i, "learn %d", &learn))
3364 else if (unformat (i, "arp-term %d", &arp_term))
3366 else if (unformat (i, "del")) {
3368 flood = uu_flood = forward = learn = 0;
3375 errmsg ("missing bridge domain\n");
3379 M(BRIDGE_DOMAIN_ADD_DEL, bridge_domain_add_del);
3381 mp->bd_id = ntohl(bd_id);
3383 mp->uu_flood = uu_flood;
3384 mp->forward = forward;
3386 mp->arp_term = arp_term;
3387 mp->is_add = is_add;
3394 static int api_l2fib_add_del (vat_main_t * vam)
3396 unformat_input_t * i = vam->input;
3397 vl_api_l2fib_add_del_t *mp;
3404 u8 sw_if_index_set = 0;
3409 /* Parse args required to build the message */
3410 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
3411 if (unformat (i, "mac %U", unformat_ethernet_address, &mac))
3413 else if (unformat (i, "bd_id %d", &bd_id))
3415 else if (unformat (i, "sw_if_index %d", &sw_if_index))
3416 sw_if_index_set = 1;
3417 else if (unformat (i, "sw_if")) {
3418 if (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
3419 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
3420 sw_if_index_set = 1;
3423 } else if (unformat (i, "static"))
3425 else if (unformat (i, "filter")) {
3428 } else if (unformat (i, "del"))
3435 errmsg ("missing mac address\n");
3439 if (bd_id_set == 0) {
3440 errmsg ("missing bridge domain\n");
3444 if (is_add && (sw_if_index_set == 0)) {
3445 errmsg ("missing interface name or sw_if_index\n");
3449 M(L2FIB_ADD_DEL, l2fib_add_del);
3452 mp->bd_id = ntohl(bd_id);
3453 mp->is_add = is_add;
3456 mp->sw_if_index = ntohl(sw_if_index);
3457 mp->static_mac = static_mac;
3458 mp->filter_mac = filter_mac;
3466 static int api_l2_flags (vat_main_t * vam)
3468 unformat_input_t * i = vam->input;
3469 vl_api_l2_flags_t *mp;
3472 u32 feature_bitmap = 0;
3473 u8 sw_if_index_set = 0;
3475 /* Parse args required to build the message */
3476 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
3477 if (unformat (i, "sw_if_index %d", &sw_if_index))
3478 sw_if_index_set = 1;
3479 else if (unformat (i, "sw_if")) {
3480 if (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
3481 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
3482 sw_if_index_set = 1;
3485 } else if (unformat (i, "learn"))
3486 feature_bitmap |= L2INPUT_FEAT_LEARN;
3487 else if (unformat (i, "forward"))
3488 feature_bitmap |= L2INPUT_FEAT_FWD;
3489 else if (unformat (i, "flood"))
3490 feature_bitmap |= L2INPUT_FEAT_FLOOD;
3491 else if (unformat (i, "uu-flood"))
3492 feature_bitmap |= L2INPUT_FEAT_UU_FLOOD;
3497 if (sw_if_index_set == 0) {
3498 errmsg ("missing interface name or sw_if_index\n");
3502 M(L2_FLAGS, l2_flags);
3504 mp->sw_if_index = ntohl(sw_if_index);
3505 mp->feature_bitmap = ntohl(feature_bitmap);
3512 static int api_bridge_flags (vat_main_t * vam)
3514 unformat_input_t * i = vam->input;
3515 vl_api_bridge_flags_t *mp;
3522 /* Parse args required to build the message */
3523 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
3524 if (unformat (i, "bd_id %d", &bd_id))
3526 else if (unformat (i, "learn"))
3528 else if (unformat (i, "forward"))
3530 else if (unformat (i, "flood"))
3532 else if (unformat (i, "uu-flood"))
3533 flags |= L2_UU_FLOOD;
3534 else if (unformat (i, "arp-term"))
3535 flags |= L2_ARP_TERM;
3536 else if (unformat (i, "off"))
3538 else if (unformat (i, "disable"))
3544 if (bd_id_set == 0) {
3545 errmsg ("missing bridge domain\n");
3549 M(BRIDGE_FLAGS, bridge_flags);
3551 mp->bd_id = ntohl(bd_id);
3552 mp->feature_bitmap = ntohl(flags);
3553 mp->is_set = is_set;
3560 static int api_bd_ip_mac_add_del (vat_main_t * vam)
3562 unformat_input_t * i = vam->input;
3563 vl_api_bd_ip_mac_add_del_t *mp;
3571 ip4_address_t v4addr;
3572 ip6_address_t v6addr;
3576 /* Parse args required to build the message */
3577 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
3578 if (unformat (i, "bd_id %d", &bd_id)) {
3580 } else if (unformat (i, "%U", unformat_ip4_address, &v4addr)) {
3582 } else if (unformat (i, "%U", unformat_ip6_address, &v6addr)) {
3585 } else if (unformat (i, "%U", unformat_ethernet_address, macaddr)) {
3587 } else if (unformat (i, "del"))
3593 if (bd_id_set == 0) {
3594 errmsg ("missing bridge domain\n");
3596 } else if (ip_set == 0) {
3597 errmsg ("missing IP address\n");
3599 } else if (mac_set == 0) {
3600 errmsg ("missing MAC address\n");
3604 M(BD_IP_MAC_ADD_DEL, bd_ip_mac_add_del);
3606 mp->bd_id = ntohl(bd_id);
3607 mp->is_ipv6 = is_ipv6;
3608 mp->is_add = is_add;
3610 clib_memcpy (mp->ip_address, &v6addr, sizeof (v6addr));
3611 else clib_memcpy (mp->ip_address, &v4addr, sizeof (v4addr));
3612 clib_memcpy (mp->mac_address, macaddr, 6);
3618 static int api_tap_connect (vat_main_t * vam)
3620 unformat_input_t * i = vam->input;
3621 vl_api_tap_connect_t *mp;
3628 memset (mac_address, 0, sizeof (mac_address));
3630 /* Parse args required to build the message */
3631 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
3632 if (unformat (i, "mac %U", unformat_ethernet_address, mac_address)) {
3635 else if (unformat (i, "random-mac"))
3637 else if (unformat (i, "tapname %s", &tap_name))
3643 if (name_set == 0) {
3644 errmsg ("missing tap name\n");
3647 if (vec_len (tap_name) > 63) {
3648 errmsg ("tap name too long\n");
3650 vec_add1 (tap_name, 0);
3652 /* Construct the API message */
3653 M(TAP_CONNECT, tap_connect);
3655 mp->use_random_mac = random_mac;
3656 clib_memcpy (mp->mac_address, mac_address, 6);
3657 clib_memcpy (mp->tap_name, tap_name, vec_len (tap_name));
3658 vec_free (tap_name);
3663 /* Wait for a reply... */
3667 static int api_tap_modify (vat_main_t * vam)
3669 unformat_input_t * i = vam->input;
3670 vl_api_tap_modify_t *mp;
3676 u32 sw_if_index = ~0;
3677 u8 sw_if_index_set = 0;
3679 memset (mac_address, 0, sizeof (mac_address));
3681 /* Parse args required to build the message */
3682 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
3683 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
3684 sw_if_index_set = 1;
3685 else if (unformat (i, "sw_if_index %d", &sw_if_index))
3686 sw_if_index_set = 1;
3687 else if (unformat (i, "mac %U", unformat_ethernet_address, mac_address)) {
3690 else if (unformat (i, "random-mac"))
3692 else if (unformat (i, "tapname %s", &tap_name))
3698 if (sw_if_index_set == 0) {
3699 errmsg ("missing vpp interface name");
3702 if (name_set == 0) {
3703 errmsg ("missing tap name\n");
3706 if (vec_len (tap_name) > 63) {
3707 errmsg ("tap name too long\n");
3709 vec_add1 (tap_name, 0);
3711 /* Construct the API message */
3712 M(TAP_MODIFY, tap_modify);
3714 mp->use_random_mac = random_mac;
3715 mp->sw_if_index = ntohl(sw_if_index);
3716 clib_memcpy (mp->mac_address, mac_address, 6);
3717 clib_memcpy (mp->tap_name, tap_name, vec_len (tap_name));
3718 vec_free (tap_name);
3723 /* Wait for a reply... */
3727 static int api_tap_delete (vat_main_t * vam)
3729 unformat_input_t * i = vam->input;
3730 vl_api_tap_delete_t *mp;
3732 u32 sw_if_index = ~0;
3733 u8 sw_if_index_set = 0;
3735 /* Parse args required to build the message */
3736 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
3737 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
3738 sw_if_index_set = 1;
3739 else if (unformat (i, "sw_if_index %d", &sw_if_index))
3740 sw_if_index_set = 1;
3745 if (sw_if_index_set == 0) {
3746 errmsg ("missing vpp interface name");
3750 /* Construct the API message */
3751 M(TAP_DELETE, tap_delete);
3753 mp->sw_if_index = ntohl(sw_if_index);
3758 /* Wait for a reply... */
3762 static int api_ip_add_del_route (vat_main_t * vam)
3764 unformat_input_t * i = vam->input;
3765 vl_api_ip_add_del_route_t *mp;
3767 u32 sw_if_index = 0, vrf_id = 0;
3768 u8 sw_if_index_set = 0;
3770 u8 is_local = 0, is_drop = 0;
3771 u8 create_vrf_if_needed = 0;
3773 u8 next_hop_weight = 1;
3775 u8 is_multipath = 0;
3777 u8 address_length_set = 0;
3778 u32 lookup_in_vrf = 0;
3779 u32 resolve_attempts = 0;
3780 u32 dst_address_length = 0;
3781 u8 next_hop_set = 0;
3782 ip4_address_t v4_dst_address, v4_next_hop_address;
3783 ip6_address_t v6_dst_address, v6_next_hop_address;
3787 u32 random_add_del = 0;
3788 u32 * random_vector = 0;
3789 uword * random_hash;
3790 u32 random_seed = 0xdeaddabe;
3791 u32 classify_table_index = ~0;
3794 /* Parse args required to build the message */
3795 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
3796 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
3797 sw_if_index_set = 1;
3798 else if (unformat (i, "sw_if_index %d", &sw_if_index))
3799 sw_if_index_set = 1;
3800 else if (unformat (i, "%U", unformat_ip4_address,
3805 else if (unformat (i, "%U", unformat_ip6_address, &v6_dst_address)) {
3809 else if (unformat (i, "/%d", &dst_address_length)) {
3810 address_length_set = 1;
3813 else if (is_ipv6 == 0 && unformat (i, "via %U", unformat_ip4_address,
3814 &v4_next_hop_address)) {
3817 else if (is_ipv6 == 1 && unformat (i, "via %U", unformat_ip6_address,
3818 &v6_next_hop_address)) {
3821 else if (unformat (i, "resolve-attempts %d", &resolve_attempts))
3823 else if (unformat (i, "weight %d", &next_hop_weight))
3825 else if (unformat (i, "drop")) {
3827 } else if (unformat (i, "local")) {
3829 } else if (unformat (i, "classify %d", &classify_table_index)) {
3831 } else if (unformat (i, "del"))
3833 else if (unformat (i, "add"))
3835 else if (unformat (i, "not-last"))
3837 else if (unformat (i, "multipath"))
3839 else if (unformat (i, "vrf %d", &vrf_id))
3841 else if (unformat (i, "create-vrf"))
3842 create_vrf_if_needed = 1;
3843 else if (unformat (i, "count %d", &count))
3845 else if (unformat (i, "lookup-in-vrf %d", &lookup_in_vrf))
3847 else if (unformat (i, "random"))
3849 else if (unformat (i, "seed %d", &random_seed))
3852 clib_warning ("parse error '%U'", format_unformat_error, i);
3857 if (resolve_attempts > 0 && sw_if_index_set == 0) {
3858 errmsg ("ARP resolution needs explicit interface or sw_if_index\n");
3862 if (!next_hop_set && !is_drop && !is_local && !is_classify) {
3863 errmsg ("next hop / local / drop / classify not set\n");
3867 if (address_set == 0) {
3868 errmsg ("missing addresses\n");
3872 if (address_length_set == 0) {
3873 errmsg ("missing address length\n");
3877 /* Generate a pile of unique, random routes */
3878 if (random_add_del) {
3879 u32 this_random_address;
3880 random_hash = hash_create (count, sizeof(uword));
3882 hash_set (random_hash, v4_next_hop_address.as_u32, 1);
3883 for (j = 0; j <= count; j++) {
3885 this_random_address = random_u32 (&random_seed);
3886 this_random_address =
3887 clib_host_to_net_u32 (this_random_address);
3888 } while (hash_get (random_hash, this_random_address));
3889 vec_add1 (random_vector, this_random_address);
3890 hash_set (random_hash, this_random_address, 1);
3892 hash_free (random_hash);
3893 v4_dst_address.as_u32 = random_vector[0];
3897 /* Turn on async mode */
3898 vam->async_mode = 1;
3899 vam->async_errors = 0;
3900 before = vat_time_now(vam);
3903 for (j = 0; j < count; j++) {
3904 /* Construct the API message */
3905 M(IP_ADD_DEL_ROUTE, ip_add_del_route);
3907 mp->next_hop_sw_if_index = ntohl (sw_if_index);
3908 mp->vrf_id = ntohl (vrf_id);
3909 if (resolve_attempts > 0) {
3910 mp->resolve_attempts = ntohl (resolve_attempts);
3911 mp->resolve_if_needed = 1;
3913 mp->create_vrf_if_needed = create_vrf_if_needed;
3915 mp->is_add = is_add;
3916 mp->is_drop = is_drop;
3917 mp->is_ipv6 = is_ipv6;
3918 mp->is_local = is_local;
3919 mp->is_classify = is_classify;
3920 mp->is_multipath = is_multipath;
3921 mp->not_last = not_last;
3922 mp->next_hop_weight = next_hop_weight;
3923 mp->dst_address_length = dst_address_length;
3924 mp->lookup_in_vrf = ntohl(lookup_in_vrf);
3925 mp->classify_table_index = ntohl(classify_table_index);
3928 clib_memcpy (mp->dst_address, &v6_dst_address, sizeof (v6_dst_address));
3930 clib_memcpy (mp->next_hop_address, &v6_next_hop_address,
3931 sizeof (v6_next_hop_address));
3932 increment_v6_address (&v6_dst_address);
3934 clib_memcpy (mp->dst_address, &v4_dst_address, sizeof (v4_dst_address));
3936 clib_memcpy (mp->next_hop_address, &v4_next_hop_address,
3937 sizeof (v4_next_hop_address));
3939 v4_dst_address.as_u32 = random_vector[j+1];
3941 increment_v4_address (&v4_dst_address);
3947 /* When testing multiple add/del ops, use a control-ping to sync */
3949 vl_api_control_ping_t * mp;
3952 /* Shut off async mode */
3953 vam->async_mode = 0;
3955 M(CONTROL_PING, control_ping);
3958 timeout = vat_time_now(vam) + 1.0;
3959 while (vat_time_now (vam) < timeout)
3960 if (vam->result_ready == 1)
3965 if (vam->retval == -99)
3966 errmsg ("timeout\n");
3968 if (vam->async_errors > 0) {
3969 errmsg ("%d asynchronous errors\n", vam->async_errors);
3972 vam->async_errors = 0;
3973 after = vat_time_now(vam);
3975 fformat(vam->ofp, "%d routes in %.6f secs, %.2f routes/sec\n",
3976 count, after - before, count / (after - before));
3978 /* Wait for a reply... */
3982 /* Return the good/bad news */
3983 return (vam->retval);
3986 static int api_proxy_arp_add_del (vat_main_t * vam)
3988 unformat_input_t * i = vam->input;
3989 vl_api_proxy_arp_add_del_t *mp;
3993 ip4_address_t lo, hi;
3996 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
3997 if (unformat (i, "vrf %d", &vrf_id))
3999 else if (unformat (i, "%U - %U", unformat_ip4_address, &lo,
4000 unformat_ip4_address, &hi))
4002 else if (unformat (i, "del"))
4005 clib_warning ("parse error '%U'", format_unformat_error, i);
4010 if (range_set == 0) {
4011 errmsg ("address range not set\n");
4015 M(PROXY_ARP_ADD_DEL, proxy_arp_add_del);
4017 mp->vrf_id = ntohl(vrf_id);
4018 mp->is_add = is_add;
4019 clib_memcpy(mp->low_address, &lo, sizeof (mp->low_address));
4020 clib_memcpy(mp->hi_address, &hi, sizeof (mp->hi_address));
4027 static int api_proxy_arp_intfc_enable_disable (vat_main_t * vam)
4029 unformat_input_t * i = vam->input;
4030 vl_api_proxy_arp_intfc_enable_disable_t *mp;
4034 u8 sw_if_index_set = 0;
4036 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
4037 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
4038 sw_if_index_set = 1;
4039 else if (unformat (i, "sw_if_index %d", &sw_if_index))
4040 sw_if_index_set = 1;
4041 else if (unformat (i, "enable"))
4043 else if (unformat (i, "disable"))
4046 clib_warning ("parse error '%U'", format_unformat_error, i);
4051 if (sw_if_index_set == 0) {
4052 errmsg ("missing interface name or sw_if_index\n");
4056 M(PROXY_ARP_INTFC_ENABLE_DISABLE, proxy_arp_intfc_enable_disable);
4058 mp->sw_if_index = ntohl(sw_if_index);
4059 mp->enable_disable = enable;
4066 static int api_mpls_add_del_decap (vat_main_t * vam)
4068 unformat_input_t * i = vam->input;
4069 vl_api_mpls_add_del_decap_t *mp;
4078 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
4079 if (unformat (i, "rx_vrf_id %d", &rx_vrf_id))
4081 else if (unformat (i, "tx_vrf_id %d", &tx_vrf_id))
4083 else if (unformat (i, "label %d", &label))
4085 else if (unformat (i, "next-index %d", &next_index))
4087 else if (unformat (i, "del"))
4089 else if (unformat (i, "s-bit-clear"))
4092 clib_warning ("parse error '%U'", format_unformat_error, i);
4097 M(MPLS_ADD_DEL_DECAP, mpls_add_del_decap);
4099 mp->rx_vrf_id = ntohl(rx_vrf_id);
4100 mp->tx_vrf_id = ntohl(tx_vrf_id);
4101 mp->label = ntohl(label);
4102 mp->next_index = ntohl(next_index);
4104 mp->is_add = is_add;
4111 static int api_mpls_add_del_encap (vat_main_t * vam)
4113 unformat_input_t * i = vam->input;
4114 vl_api_mpls_add_del_encap_t *mp;
4119 ip4_address_t dst_address;
4122 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
4123 if (unformat (i, "vrf %d", &vrf_id))
4125 else if (unformat (i, "label %d", &label))
4126 vec_add1 (labels, ntohl(label));
4127 else if (unformat (i, "dst %U", unformat_ip4_address, &dst_address))
4129 else if (unformat (i, "del"))
4132 clib_warning ("parse error '%U'", format_unformat_error, i);
4137 if (vec_len (labels) == 0) {
4138 errmsg ("missing encap label stack\n");
4142 M2(MPLS_ADD_DEL_ENCAP, mpls_add_del_encap,
4143 sizeof (u32) * vec_len (labels));
4145 mp->vrf_id = ntohl(vrf_id);
4146 clib_memcpy(mp->dst_address, &dst_address, sizeof (dst_address));
4147 mp->is_add = is_add;
4148 mp->nlabels = vec_len (labels);
4149 clib_memcpy(mp->labels, labels, sizeof(u32)*mp->nlabels);
4158 static int api_mpls_gre_add_del_tunnel (vat_main_t * vam)
4160 unformat_input_t * i = vam->input;
4161 vl_api_mpls_gre_add_del_tunnel_t *mp;
4163 u32 inner_vrf_id = 0;
4164 u32 outer_vrf_id = 0;
4165 ip4_address_t src_address;
4166 ip4_address_t dst_address;
4167 ip4_address_t intfc_address;
4169 u8 intfc_address_length = 0;
4173 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
4174 if (unformat (i, "inner_vrf_id %d", &inner_vrf_id))
4176 else if (unformat (i, "outer_vrf_id %d", &outer_vrf_id))
4178 else if (unformat (i, "src %U", unformat_ip4_address, &src_address))
4180 else if (unformat (i, "dst %U", unformat_ip4_address, &dst_address))
4182 else if (unformat (i, "adj %U/%d", unformat_ip4_address,
4183 &intfc_address, &tmp))
4184 intfc_address_length = tmp;
4185 else if (unformat (i, "l2-only"))
4187 else if (unformat (i, "del"))
4190 clib_warning ("parse error '%U'", format_unformat_error, i);
4195 M(MPLS_GRE_ADD_DEL_TUNNEL, mpls_gre_add_del_tunnel);
4197 mp->inner_vrf_id = ntohl(inner_vrf_id);
4198 mp->outer_vrf_id = ntohl(outer_vrf_id);
4199 clib_memcpy(mp->src_address, &src_address, sizeof (src_address));
4200 clib_memcpy(mp->dst_address, &dst_address, sizeof (dst_address));
4201 clib_memcpy(mp->intfc_address, &intfc_address, sizeof (intfc_address));
4202 mp->intfc_address_length = intfc_address_length;
4203 mp->l2_only = l2_only;
4204 mp->is_add = is_add;
4211 static int api_mpls_ethernet_add_del_tunnel (vat_main_t * vam)
4213 unformat_input_t * i = vam->input;
4214 vl_api_mpls_ethernet_add_del_tunnel_t *mp;
4216 u32 inner_vrf_id = 0;
4217 ip4_address_t intfc_address;
4218 u8 dst_mac_address[6];
4221 u8 intfc_address_length = 0;
4225 int tx_sw_if_index_set = 0;
4227 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
4228 if (unformat (i, "vrf %d", &inner_vrf_id))
4230 else if (unformat (i, "adj %U/%d", unformat_ip4_address,
4231 &intfc_address, &tmp))
4232 intfc_address_length = tmp;
4233 else if (unformat (i, "%U",
4234 unformat_sw_if_index, vam, &tx_sw_if_index))
4235 tx_sw_if_index_set = 1;
4236 else if (unformat (i, "tx_sw_if_index %d", &tx_sw_if_index))
4237 tx_sw_if_index_set = 1;
4238 else if (unformat (i, "dst %U", unformat_ethernet_address,
4241 else if (unformat (i, "l2-only"))
4243 else if (unformat (i, "del"))
4246 clib_warning ("parse error '%U'", format_unformat_error, i);
4252 errmsg ("dst (mac address) not set\n");
4255 if (!tx_sw_if_index_set) {
4256 errmsg ("tx-intfc not set\n");
4260 M(MPLS_ETHERNET_ADD_DEL_TUNNEL, mpls_ethernet_add_del_tunnel);
4262 mp->vrf_id = ntohl(inner_vrf_id);
4263 clib_memcpy (mp->adj_address, &intfc_address, sizeof (intfc_address));
4264 mp->adj_address_length = intfc_address_length;
4265 clib_memcpy (mp->dst_mac_address, dst_mac_address, sizeof (dst_mac_address));
4266 mp->tx_sw_if_index = ntohl(tx_sw_if_index);
4267 mp->l2_only = l2_only;
4268 mp->is_add = is_add;
4275 static int api_mpls_ethernet_add_del_tunnel_2 (vat_main_t * vam)
4277 unformat_input_t * i = vam->input;
4278 vl_api_mpls_ethernet_add_del_tunnel_2_t *mp;
4280 u32 inner_vrf_id = 0;
4281 u32 outer_vrf_id = 0;
4282 ip4_address_t adj_address;
4283 int adj_address_set = 0;
4284 ip4_address_t next_hop_address;
4285 int next_hop_address_set = 0;
4287 u8 adj_address_length = 0;
4290 u32 resolve_attempts = 5;
4291 u8 resolve_if_needed = 1;
4293 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
4294 if (unformat (i, "inner_vrf_id %d", &inner_vrf_id))
4296 else if (unformat (i, "outer_vrf_id %d", &outer_vrf_id))
4298 else if (unformat (i, "adj %U/%d", unformat_ip4_address,
4299 &adj_address, &tmp)) {
4300 adj_address_length = tmp;
4301 adj_address_set = 1;
4303 else if (unformat (i, "next-hop %U", unformat_ip4_address,
4305 next_hop_address_set = 1;
4306 else if (unformat (i, "resolve-attempts %d", &resolve_attempts))
4308 else if (unformat (i, "resolve-if-needed %d", &tmp))
4309 resolve_if_needed = tmp;
4310 else if (unformat (i, "l2-only"))
4312 else if (unformat (i, "del"))
4315 clib_warning ("parse error '%U'", format_unformat_error, i);
4320 if (!adj_address_set) {
4321 errmsg ("adjacency address/mask not set\n");
4324 if (!next_hop_address_set) {
4325 errmsg ("ip4 next hop address (in outer fib) not set\n");
4329 M(MPLS_ETHERNET_ADD_DEL_TUNNEL_2, mpls_ethernet_add_del_tunnel_2);
4331 mp->inner_vrf_id = ntohl(inner_vrf_id);
4332 mp->outer_vrf_id = ntohl(outer_vrf_id);
4333 mp->resolve_attempts = ntohl(resolve_attempts);
4334 mp->resolve_if_needed = resolve_if_needed;
4335 mp->is_add = is_add;
4336 mp->l2_only = l2_only;
4337 clib_memcpy (mp->adj_address, &adj_address, sizeof (adj_address));
4338 mp->adj_address_length = adj_address_length;
4339 clib_memcpy (mp->next_hop_ip4_address_in_outer_vrf, &next_hop_address,
4340 sizeof (next_hop_address));
4347 static int api_sw_interface_set_unnumbered (vat_main_t * vam)
4349 unformat_input_t * i = vam->input;
4350 vl_api_sw_interface_set_unnumbered_t *mp;
4355 u8 sw_if_index_set = 0;
4357 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
4358 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
4359 sw_if_index_set = 1;
4360 else if (unformat (i, "sw_if_index %d", &sw_if_index))
4361 sw_if_index_set = 1;
4362 else if (unformat (i, "unnum_if_index %d", &unnum_sw_index))
4364 else if (unformat (i, "del"))
4367 clib_warning ("parse error '%U'", format_unformat_error, i);
4372 if (sw_if_index_set == 0) {
4373 errmsg ("missing interface name or sw_if_index\n");
4377 M(SW_INTERFACE_SET_UNNUMBERED, sw_interface_set_unnumbered);
4379 mp->sw_if_index = ntohl(sw_if_index);
4380 mp->unnumbered_sw_if_index = ntohl(unnum_sw_index);
4381 mp->is_add = is_add;
4388 static int api_ip_neighbor_add_del (vat_main_t * vam)
4390 unformat_input_t * i = vam->input;
4391 vl_api_ip_neighbor_add_del_t *mp;
4394 u8 sw_if_index_set = 0;
4400 u8 v4_address_set = 0;
4401 u8 v6_address_set = 0;
4402 ip4_address_t v4address;
4403 ip6_address_t v6address;
4405 memset (mac_address, 0, sizeof (mac_address));
4407 /* Parse args required to build the message */
4408 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
4409 if (unformat (i, "mac %U", unformat_ethernet_address, mac_address)) {
4412 else if (unformat (i, "del"))
4414 else if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
4415 sw_if_index_set = 1;
4416 else if (unformat (i, "sw_if_index %d", &sw_if_index))
4417 sw_if_index_set = 1;
4418 else if (unformat (i, "is_static"))
4420 else if (unformat (i, "vrf %d", &vrf_id))
4422 else if (unformat (i, "dst %U",
4423 unformat_ip4_address, &v4address))
4425 else if (unformat (i, "dst %U",
4426 unformat_ip6_address, &v6address))
4429 clib_warning ("parse error '%U'", format_unformat_error, i);
4434 if (sw_if_index_set == 0) {
4435 errmsg ("missing interface name or sw_if_index\n");
4438 if (v4_address_set && v6_address_set) {
4439 errmsg ("both v4 and v6 addresses set\n");
4442 if (!v4_address_set && !v6_address_set) {
4443 errmsg ("no addresses set\n");
4447 /* Construct the API message */
4448 M(IP_NEIGHBOR_ADD_DEL, ip_neighbor_add_del);
4450 mp->sw_if_index = ntohl (sw_if_index);
4451 mp->is_add = is_add;
4452 mp->vrf_id = ntohl (vrf_id);
4453 mp->is_static = is_static;
4455 clib_memcpy (mp->mac_address, mac_address, 6);
4456 if (v6_address_set) {
4458 clib_memcpy (mp->dst_address, &v6address, sizeof (v6address));
4460 /* mp->is_ipv6 = 0; via memset in M macro above */
4461 clib_memcpy (mp->dst_address, &v4address, sizeof (v4address));
4467 /* Wait for a reply, return good/bad news */
4474 static int api_reset_vrf (vat_main_t * vam)
4476 unformat_input_t * i = vam->input;
4477 vl_api_reset_vrf_t *mp;
4483 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
4484 if (unformat (i, "vrf %d", &vrf_id))
4486 else if (unformat (i, "ipv6"))
4489 clib_warning ("parse error '%U'", format_unformat_error, i);
4494 if (vrf_id_set == 0) {
4495 errmsg ("missing vrf id\n");
4499 M(RESET_VRF, reset_vrf);
4501 mp->vrf_id = ntohl(vrf_id);
4502 mp->is_ipv6 = is_ipv6;
4509 static int api_create_vlan_subif (vat_main_t * vam)
4511 unformat_input_t * i = vam->input;
4512 vl_api_create_vlan_subif_t *mp;
4515 u8 sw_if_index_set = 0;
4519 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
4520 if (unformat (i, "sw_if_index %d", &sw_if_index))
4521 sw_if_index_set = 1;
4522 else if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
4523 sw_if_index_set = 1;
4524 else if (unformat (i, "vlan %d", &vlan_id))
4527 clib_warning ("parse error '%U'", format_unformat_error, i);
4532 if (sw_if_index_set == 0) {
4533 errmsg ("missing interface name or sw_if_index\n");
4537 if (vlan_id_set == 0) {
4538 errmsg ("missing vlan_id\n");
4541 M(CREATE_VLAN_SUBIF, create_vlan_subif);
4543 mp->sw_if_index = ntohl(sw_if_index);
4544 mp->vlan_id = ntohl(vlan_id);
4551 #define foreach_create_subif_bit \
4558 _(outer_vlan_id_any) \
4559 _(inner_vlan_id_any)
4561 static int api_create_subif (vat_main_t * vam)
4563 unformat_input_t * i = vam->input;
4564 vl_api_create_subif_t *mp;
4567 u8 sw_if_index_set = 0;
4574 u32 exact_match = 0;
4575 u32 default_sub = 0;
4576 u32 outer_vlan_id_any = 0;
4577 u32 inner_vlan_id_any = 0;
4579 u16 outer_vlan_id = 0;
4580 u16 inner_vlan_id = 0;
4582 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
4583 if (unformat (i, "sw_if_index %d", &sw_if_index))
4584 sw_if_index_set = 1;
4585 else if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
4586 sw_if_index_set = 1;
4587 else if (unformat (i, "sub_id %d", &sub_id))
4589 else if (unformat (i, "outer_vlan_id %d", &tmp))
4590 outer_vlan_id = tmp;
4591 else if (unformat (i, "inner_vlan_id %d", &tmp))
4592 inner_vlan_id = tmp;
4594 #define _(a) else if (unformat (i, #a)) a = 1 ;
4595 foreach_create_subif_bit
4599 clib_warning ("parse error '%U'", format_unformat_error, i);
4604 if (sw_if_index_set == 0) {
4605 errmsg ("missing interface name or sw_if_index\n");
4609 if (sub_id_set == 0) {
4610 errmsg ("missing sub_id\n");
4613 M(CREATE_SUBIF, create_subif);
4615 mp->sw_if_index = ntohl(sw_if_index);
4616 mp->sub_id = ntohl(sub_id);
4618 #define _(a) mp->a = a;
4619 foreach_create_subif_bit;
4622 mp->outer_vlan_id = ntohs (outer_vlan_id);
4623 mp->inner_vlan_id = ntohs (inner_vlan_id);
4630 static int api_oam_add_del (vat_main_t * vam)
4632 unformat_input_t * i = vam->input;
4633 vl_api_oam_add_del_t *mp;
4637 ip4_address_t src, dst;
4641 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
4642 if (unformat (i, "vrf %d", &vrf_id))
4644 else if (unformat (i, "src %U", unformat_ip4_address, &src))
4646 else if (unformat (i, "dst %U", unformat_ip4_address, &dst))
4648 else if (unformat (i, "del"))
4651 clib_warning ("parse error '%U'", format_unformat_error, i);
4657 errmsg ("missing src addr\n");
4662 errmsg ("missing dst addr\n");
4666 M(OAM_ADD_DEL, oam_add_del);
4668 mp->vrf_id = ntohl(vrf_id);
4669 mp->is_add = is_add;
4670 clib_memcpy(mp->src_address, &src, sizeof (mp->src_address));
4671 clib_memcpy(mp->dst_address, &dst, sizeof (mp->dst_address));
4678 static int api_reset_fib (vat_main_t * vam)
4680 unformat_input_t * i = vam->input;
4681 vl_api_reset_fib_t *mp;
4687 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
4688 if (unformat (i, "vrf %d", &vrf_id))
4690 else if (unformat (i, "ipv6"))
4693 clib_warning ("parse error '%U'", format_unformat_error, i);
4698 if (vrf_id_set == 0) {
4699 errmsg ("missing vrf id\n");
4703 M(RESET_FIB, reset_fib);
4705 mp->vrf_id = ntohl(vrf_id);
4706 mp->is_ipv6 = is_ipv6;
4713 static int api_dhcp_proxy_config (vat_main_t * vam)
4715 unformat_input_t * i = vam->input;
4716 vl_api_dhcp_proxy_config_t *mp;
4721 u8 v4_address_set = 0;
4722 u8 v6_address_set = 0;
4723 ip4_address_t v4address;
4724 ip6_address_t v6address;
4725 u8 v4_src_address_set = 0;
4726 u8 v6_src_address_set = 0;
4727 ip4_address_t v4srcaddress;
4728 ip6_address_t v6srcaddress;
4730 /* Parse args required to build the message */
4731 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
4732 if (unformat (i, "del"))
4734 else if (unformat (i, "vrf %d", &vrf_id))
4736 else if (unformat (i, "insert-cid %d", &insert_cid))
4738 else if (unformat (i, "svr %U",
4739 unformat_ip4_address, &v4address))
4741 else if (unformat (i, "svr %U",
4742 unformat_ip6_address, &v6address))
4744 else if (unformat (i, "src %U",
4745 unformat_ip4_address, &v4srcaddress))
4746 v4_src_address_set = 1;
4747 else if (unformat (i, "src %U",
4748 unformat_ip6_address, &v6srcaddress))
4749 v6_src_address_set = 1;
4754 if (v4_address_set && v6_address_set) {
4755 errmsg ("both v4 and v6 server addresses set\n");
4758 if (!v4_address_set && !v6_address_set) {
4759 errmsg ("no server addresses set\n");
4763 if (v4_src_address_set && v6_src_address_set) {
4764 errmsg ("both v4 and v6 src addresses set\n");
4767 if (!v4_src_address_set && !v6_src_address_set) {
4768 errmsg ("no src addresses set\n");
4772 if (!(v4_src_address_set && v4_address_set) &&
4773 !(v6_src_address_set && v6_address_set)) {
4774 errmsg ("no matching server and src addresses set\n");
4778 /* Construct the API message */
4779 M(DHCP_PROXY_CONFIG, dhcp_proxy_config);
4781 mp->insert_circuit_id = insert_cid;
4782 mp->is_add = is_add;
4783 mp->vrf_id = ntohl (vrf_id);
4784 if (v6_address_set) {
4786 clib_memcpy (mp->dhcp_server, &v6address, sizeof (v6address));
4787 clib_memcpy (mp->dhcp_src_address, &v6srcaddress, sizeof (v6address));
4789 clib_memcpy (mp->dhcp_server, &v4address, sizeof (v4address));
4790 clib_memcpy (mp->dhcp_src_address, &v4srcaddress, sizeof (v4address));
4796 /* Wait for a reply, return good/bad news */
4802 static int api_dhcp_proxy_config_2 (vat_main_t * vam)
4804 unformat_input_t * i = vam->input;
4805 vl_api_dhcp_proxy_config_2_t *mp;
4808 u32 server_vrf_id = 0;
4811 u8 v4_address_set = 0;
4812 u8 v6_address_set = 0;
4813 ip4_address_t v4address;
4814 ip6_address_t v6address;
4815 u8 v4_src_address_set = 0;
4816 u8 v6_src_address_set = 0;
4817 ip4_address_t v4srcaddress;
4818 ip6_address_t v6srcaddress;
4820 /* Parse args required to build the message */
4821 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
4822 if (unformat (i, "del"))
4824 else if (unformat (i, "rx_vrf_id %d", &rx_vrf_id))
4826 else if (unformat (i, "server_vrf_id %d", &server_vrf_id))
4828 else if (unformat (i, "insert-cid %d", &insert_cid))
4830 else if (unformat (i, "svr %U",
4831 unformat_ip4_address, &v4address))
4833 else if (unformat (i, "svr %U",
4834 unformat_ip6_address, &v6address))
4836 else if (unformat (i, "src %U",
4837 unformat_ip4_address, &v4srcaddress))
4838 v4_src_address_set = 1;
4839 else if (unformat (i, "src %U",
4840 unformat_ip6_address, &v6srcaddress))
4841 v6_src_address_set = 1;
4846 if (v4_address_set && v6_address_set) {
4847 errmsg ("both v4 and v6 server addresses set\n");
4850 if (!v4_address_set && !v6_address_set) {
4851 errmsg ("no server addresses set\n");
4855 if (v4_src_address_set && v6_src_address_set) {
4856 errmsg ("both v4 and v6 src addresses set\n");
4859 if (!v4_src_address_set && !v6_src_address_set) {
4860 errmsg ("no src addresses set\n");
4864 if (!(v4_src_address_set && v4_address_set) &&
4865 !(v6_src_address_set && v6_address_set)) {
4866 errmsg ("no matching server and src addresses set\n");
4870 /* Construct the API message */
4871 M(DHCP_PROXY_CONFIG_2, dhcp_proxy_config_2);
4873 mp->insert_circuit_id = insert_cid;
4874 mp->is_add = is_add;
4875 mp->rx_vrf_id = ntohl (rx_vrf_id);
4876 mp->server_vrf_id = ntohl (server_vrf_id);
4877 if (v6_address_set) {
4879 clib_memcpy (mp->dhcp_server, &v6address, sizeof (v6address));
4880 clib_memcpy (mp->dhcp_src_address, &v6srcaddress, sizeof (v6address));
4882 clib_memcpy (mp->dhcp_server, &v4address, sizeof (v4address));
4883 clib_memcpy (mp->dhcp_src_address, &v4srcaddress, sizeof (v4address));
4889 /* Wait for a reply, return good/bad news */
4895 static int api_dhcp_proxy_set_vss (vat_main_t * vam)
4897 unformat_input_t * i = vam->input;
4898 vl_api_dhcp_proxy_set_vss_t *mp;
4909 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
4910 if (unformat (i, "tbl_id %d", &tbl_id))
4912 if (unformat (i, "fib_id %d", &fib_id))
4914 if (unformat (i, "oui %d", &oui))
4916 else if (unformat (i, "ipv6"))
4918 else if (unformat (i, "del"))
4921 clib_warning ("parse error '%U'", format_unformat_error, i);
4926 if (tbl_id_set == 0) {
4927 errmsg ("missing tbl id\n");
4931 if (fib_id_set == 0) {
4932 errmsg ("missing fib id\n");
4936 errmsg ("missing oui\n");
4940 M(DHCP_PROXY_SET_VSS, dhcp_proxy_set_vss);
4941 mp->tbl_id = ntohl(tbl_id);
4942 mp->fib_id = ntohl(fib_id);
4943 mp->oui = ntohl(oui);
4944 mp->is_ipv6 = is_ipv6;
4945 mp->is_add = is_add;
4952 static int api_dhcp_client_config (vat_main_t * vam)
4954 unformat_input_t * i = vam->input;
4955 vl_api_dhcp_client_config_t *mp;
4958 u8 sw_if_index_set = 0;
4961 u8 disable_event = 0;
4963 /* Parse args required to build the message */
4964 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
4965 if (unformat (i, "del"))
4967 else if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
4968 sw_if_index_set = 1;
4969 else if (unformat (i, "sw_if_index %d", &sw_if_index))
4970 sw_if_index_set = 1;
4971 else if (unformat (i, "hostname %s", &hostname))
4973 else if (unformat (i, "disable_event"))
4979 if (sw_if_index_set == 0) {
4980 errmsg ("missing interface name or sw_if_index\n");
4984 if (vec_len (hostname) > 63) {
4985 errmsg ("hostname too long\n");
4987 vec_add1 (hostname, 0);
4989 /* Construct the API message */
4990 M(DHCP_CLIENT_CONFIG, dhcp_client_config);
4992 mp->sw_if_index = ntohl (sw_if_index);
4993 clib_memcpy (mp->hostname, hostname, vec_len (hostname));
4994 vec_free (hostname);
4995 mp->is_add = is_add;
4996 mp->want_dhcp_event = disable_event ? 0 : 1;
5002 /* Wait for a reply, return good/bad news */
5008 static int api_set_ip_flow_hash (vat_main_t * vam)
5010 unformat_input_t * i = vam->input;
5011 vl_api_set_ip_flow_hash_t *mp;
5023 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
5024 if (unformat (i, "vrf %d", &vrf_id))
5026 else if (unformat (i, "ipv6"))
5028 else if (unformat (i, "src"))
5030 else if (unformat (i, "dst"))
5032 else if (unformat (i, "sport"))
5034 else if (unformat (i, "dport"))
5036 else if (unformat (i, "proto"))
5038 else if (unformat (i, "reverse"))
5042 clib_warning ("parse error '%U'", format_unformat_error, i);
5047 if (vrf_id_set == 0) {
5048 errmsg ("missing vrf id\n");
5052 M(SET_IP_FLOW_HASH, set_ip_flow_hash);
5058 mp->reverse = reverse;
5059 mp->vrf_id = ntohl(vrf_id);
5060 mp->is_ipv6 = is_ipv6;
5067 static int api_sw_interface_ip6_enable_disable (vat_main_t * vam)
5069 unformat_input_t * i = vam->input;
5070 vl_api_sw_interface_ip6_enable_disable_t *mp;
5073 u8 sw_if_index_set = 0;
5076 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
5077 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
5078 sw_if_index_set = 1;
5079 else if (unformat (i, "sw_if_index %d", &sw_if_index))
5080 sw_if_index_set = 1;
5081 else if (unformat (i, "enable"))
5083 else if (unformat (i, "disable"))
5086 clib_warning ("parse error '%U'", format_unformat_error, i);
5091 if (sw_if_index_set == 0) {
5092 errmsg ("missing interface name or sw_if_index\n");
5096 M(SW_INTERFACE_IP6_ENABLE_DISABLE, sw_interface_ip6_enable_disable);
5098 mp->sw_if_index = ntohl(sw_if_index);
5099 mp->enable = enable;
5106 static int api_sw_interface_ip6_set_link_local_address (vat_main_t * vam)
5108 unformat_input_t * i = vam->input;
5109 vl_api_sw_interface_ip6_set_link_local_address_t *mp;
5112 u8 sw_if_index_set = 0;
5113 u32 address_length = 0;
5114 u8 v6_address_set = 0;
5115 ip6_address_t v6address;
5117 /* Parse args required to build the message */
5118 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
5119 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
5120 sw_if_index_set = 1;
5121 else if (unformat (i, "sw_if_index %d", &sw_if_index))
5122 sw_if_index_set = 1;
5123 else if (unformat (i, "%U/%d",
5124 unformat_ip6_address, &v6address,
5131 if (sw_if_index_set == 0) {
5132 errmsg ("missing interface name or sw_if_index\n");
5135 if (!v6_address_set) {
5136 errmsg ("no address set\n");
5140 /* Construct the API message */
5141 M(SW_INTERFACE_IP6_SET_LINK_LOCAL_ADDRESS, \
5142 sw_interface_ip6_set_link_local_address);
5144 mp->sw_if_index = ntohl (sw_if_index);
5145 clib_memcpy (mp->address, &v6address, sizeof (v6address));
5146 mp->address_length = address_length;
5151 /* Wait for a reply, return good/bad news */
5159 static int api_sw_interface_ip6nd_ra_prefix (vat_main_t * vam)
5161 unformat_input_t * i = vam->input;
5162 vl_api_sw_interface_ip6nd_ra_prefix_t *mp;
5165 u8 sw_if_index_set = 0;
5166 u32 address_length = 0;
5167 u8 v6_address_set = 0;
5168 ip6_address_t v6address;
5170 u8 no_advertise = 0;
5172 u8 no_autoconfig = 0;
5175 u32 val_lifetime = 0;
5176 u32 pref_lifetime = 0;
5178 /* Parse args required to build the message */
5179 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
5180 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
5181 sw_if_index_set = 1;
5182 else if (unformat (i, "sw_if_index %d", &sw_if_index))
5183 sw_if_index_set = 1;
5184 else if (unformat (i, "%U/%d",
5185 unformat_ip6_address, &v6address,
5188 else if (unformat (i, "val_life %d", &val_lifetime))
5190 else if (unformat (i, "pref_life %d", &pref_lifetime))
5192 else if (unformat (i, "def"))
5194 else if (unformat (i, "noadv"))
5196 else if (unformat (i, "offl"))
5198 else if (unformat (i, "noauto"))
5200 else if (unformat (i, "nolink"))
5202 else if (unformat (i, "isno"))
5205 clib_warning ("parse error '%U'", format_unformat_error, i);
5210 if (sw_if_index_set == 0) {
5211 errmsg ("missing interface name or sw_if_index\n");
5214 if (!v6_address_set) {
5215 errmsg ("no address set\n");
5219 /* Construct the API message */
5220 M(SW_INTERFACE_IP6ND_RA_PREFIX, sw_interface_ip6nd_ra_prefix);
5222 mp->sw_if_index = ntohl (sw_if_index);
5223 clib_memcpy (mp->address, &v6address, sizeof (v6address));
5224 mp->address_length = address_length;
5225 mp->use_default = use_default;
5226 mp->no_advertise = no_advertise;
5227 mp->off_link = off_link;
5228 mp->no_autoconfig = no_autoconfig;
5229 mp->no_onlink = no_onlink;
5231 mp->val_lifetime = ntohl(val_lifetime);
5232 mp->pref_lifetime = ntohl(pref_lifetime);
5237 /* Wait for a reply, return good/bad news */
5244 static int api_sw_interface_ip6nd_ra_config (vat_main_t * vam)
5246 unformat_input_t * i = vam->input;
5247 vl_api_sw_interface_ip6nd_ra_config_t *mp;
5250 u8 sw_if_index_set = 0;
5255 u8 send_unicast = 0;
5258 u8 default_router = 0;
5259 u32 max_interval = 0;
5260 u32 min_interval = 0;
5262 u32 initial_count = 0;
5263 u32 initial_interval = 0;
5266 /* Parse args required to build the message */
5267 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
5268 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
5269 sw_if_index_set = 1;
5270 else if (unformat (i, "sw_if_index %d", &sw_if_index))
5271 sw_if_index_set = 1;
5272 else if (unformat (i, "maxint %d", &max_interval))
5274 else if (unformat (i, "minint %d", &min_interval))
5276 else if (unformat (i, "life %d", &lifetime))
5278 else if (unformat (i, "count %d", &initial_count))
5280 else if (unformat (i, "interval %d", &initial_interval))
5282 else if (unformat (i, "surpress"))
5284 else if (unformat (i, "managed"))
5286 else if (unformat (i, "other"))
5288 else if (unformat (i, "ll"))
5290 else if (unformat (i, "send"))
5292 else if (unformat (i, "cease"))
5294 else if (unformat (i, "isno"))
5296 else if (unformat (i, "def"))
5299 clib_warning ("parse error '%U'", format_unformat_error, i);
5304 if (sw_if_index_set == 0) {
5305 errmsg ("missing interface name or sw_if_index\n");
5309 /* Construct the API message */
5310 M(SW_INTERFACE_IP6ND_RA_CONFIG, sw_interface_ip6nd_ra_config);
5312 mp->sw_if_index = ntohl (sw_if_index);
5313 mp->max_interval = ntohl(max_interval);
5314 mp->min_interval = ntohl(min_interval);
5315 mp->lifetime = ntohl(lifetime);
5316 mp->initial_count = ntohl(initial_count);
5317 mp->initial_interval = ntohl(initial_interval);
5318 mp->surpress = surpress;
5319 mp->managed = managed;
5321 mp->ll_option = ll_option;
5322 mp->send_unicast = send_unicast;
5325 mp->default_router = default_router;
5330 /* Wait for a reply, return good/bad news */
5337 static int api_set_arp_neighbor_limit (vat_main_t * vam)
5339 unformat_input_t * i = vam->input;
5340 vl_api_set_arp_neighbor_limit_t *mp;
5346 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
5347 if (unformat (i, "arp_nbr_limit %d", &arp_nbr_limit))
5349 else if (unformat (i, "ipv6"))
5352 clib_warning ("parse error '%U'", format_unformat_error, i);
5357 if (limit_set == 0) {
5358 errmsg ("missing limit value\n");
5362 M(SET_ARP_NEIGHBOR_LIMIT, set_arp_neighbor_limit);
5364 mp->arp_neighbor_limit = ntohl(arp_nbr_limit);
5365 mp->is_ipv6 = is_ipv6;
5372 static int api_l2_patch_add_del (vat_main_t * vam)
5374 unformat_input_t * i = vam->input;
5375 vl_api_l2_patch_add_del_t *mp;
5378 u8 rx_sw_if_index_set = 0;
5380 u8 tx_sw_if_index_set = 0;
5383 /* Parse args required to build the message */
5384 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
5385 if (unformat (i, "rx_sw_if_index %d", &rx_sw_if_index))
5386 rx_sw_if_index_set = 1;
5387 else if (unformat (i, "tx_sw_if_index %d", &tx_sw_if_index))
5388 tx_sw_if_index_set = 1;
5389 else if (unformat (i, "rx")) {
5390 if (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
5391 if (unformat (i, "%U", unformat_sw_if_index, vam,
5393 rx_sw_if_index_set = 1;
5396 } else if (unformat (i, "tx")) {
5397 if (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
5398 if (unformat (i, "%U", unformat_sw_if_index, vam,
5400 tx_sw_if_index_set = 1;
5403 } else if (unformat (i, "del"))
5409 if (rx_sw_if_index_set == 0) {
5410 errmsg ("missing rx interface name or rx_sw_if_index\n");
5414 if (tx_sw_if_index_set == 0) {
5415 errmsg ("missing tx interface name or tx_sw_if_index\n");
5419 M(L2_PATCH_ADD_DEL, l2_patch_add_del);
5421 mp->rx_sw_if_index = ntohl(rx_sw_if_index);
5422 mp->tx_sw_if_index = ntohl(tx_sw_if_index);
5423 mp->is_add = is_add;
5429 static int api_trace_profile_add (vat_main_t *vam)
5431 unformat_input_t * input = vam->input;
5432 vl_api_trace_profile_add_t *mp;
5435 u32 trace_option_elts = 0;
5436 u32 trace_type = 0, node_id = 0, app_data = 0, trace_tsp = 2;
5437 int has_pow_option = 0;
5438 int has_ppc_option = 0;
5440 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
5442 if (unformat (input, "id %d trace-type 0x%x trace-elts %d "
5443 "trace-tsp %d node-id 0x%x app-data 0x%x",
5444 &id, &trace_type, &trace_option_elts, &trace_tsp,
5445 &node_id, &app_data))
5447 else if (unformat (input, "pow"))
5449 else if (unformat (input, "ppc encap"))
5450 has_ppc_option = PPC_ENCAP;
5451 else if (unformat (input, "ppc decap"))
5452 has_ppc_option = PPC_DECAP;
5453 else if (unformat (input, "ppc none"))
5454 has_ppc_option = PPC_NONE;
5458 M(TRACE_PROFILE_ADD, trace_profile_add);
5460 mp->trace_type = trace_type;
5461 mp->trace_num_elt = trace_option_elts;
5462 mp->trace_ppc = has_ppc_option;
5463 mp->trace_app_data = htonl(app_data);
5464 mp->pow_enable = has_pow_option;
5465 mp->trace_tsp = trace_tsp;
5466 mp->node_id = htonl(node_id);
5473 static int api_trace_profile_apply (vat_main_t *vam)
5475 unformat_input_t * input = vam->input;
5476 vl_api_trace_profile_apply_t *mp;
5479 u32 mask_width = ~0;
5486 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
5488 if (unformat (input, "%U/%d",
5489 unformat_ip6_address, &addr, &mask_width))
5491 else if (unformat (input, "id %d", &id))
5493 else if (unformat (input, "vrf-id %d", &vrf_id))
5495 else if (unformat (input, "add"))
5497 else if (unformat (input, "pop"))
5499 else if (unformat (input, "none"))
5505 if ((is_add + is_pop + is_none) != 1) {
5506 errmsg("One of (add, pop, none) required");
5509 if (mask_width == ~0) {
5510 errmsg("<address>/<mask-width> required");
5513 M(TRACE_PROFILE_APPLY, trace_profile_apply);
5514 clib_memcpy(mp->dest_ipv6, &addr, sizeof(mp->dest_ipv6));
5516 mp->prefix_length = htonl(mask_width);
5517 mp->vrf_id = htonl(vrf_id);
5519 mp->trace_op = IOAM_HBYH_ADD;
5521 mp->trace_op = IOAM_HBYH_POP;
5523 mp->trace_op = IOAM_HBYH_MOD;
5535 static int api_trace_profile_del (vat_main_t *vam)
5537 vl_api_trace_profile_del_t *mp;
5540 M(TRACE_PROFILE_DEL, trace_profile_del);
5545 static int api_sr_tunnel_add_del (vat_main_t * vam)
5547 unformat_input_t * i = vam->input;
5548 vl_api_sr_tunnel_add_del_t *mp;
5552 ip6_address_t src_address;
5553 int src_address_set = 0;
5554 ip6_address_t dst_address;
5556 int dst_address_set = 0;
5558 u32 rx_table_id = 0;
5559 u32 tx_table_id = 0;
5560 ip6_address_t * segments = 0;
5561 ip6_address_t * this_seg;
5562 ip6_address_t * tags = 0;
5563 ip6_address_t * this_tag;
5564 ip6_address_t next_address, tag;
5566 u8 * policy_name = 0;
5568 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
5570 if (unformat (i, "del"))
5572 else if (unformat (i, "name %s", &name))
5574 else if (unformat (i, "policy %s", &policy_name))
5576 else if (unformat (i, "rx_fib_id %d", &rx_table_id))
5578 else if (unformat (i, "tx_fib_id %d", &tx_table_id))
5580 else if (unformat (i, "src %U", unformat_ip6_address, &src_address))
5581 src_address_set = 1;
5582 else if (unformat (i, "dst %U/%d",
5583 unformat_ip6_address, &dst_address,
5585 dst_address_set = 1;
5586 else if (unformat (i, "next %U", unformat_ip6_address,
5589 vec_add2 (segments, this_seg, 1);
5590 clib_memcpy (this_seg->as_u8, next_address.as_u8, sizeof (*this_seg));
5592 else if (unformat (i, "tag %U", unformat_ip6_address,
5595 vec_add2 (tags, this_tag, 1);
5596 clib_memcpy (this_tag->as_u8, tag.as_u8, sizeof (*this_tag));
5598 else if (unformat (i, "clean"))
5599 flags |= IP6_SR_HEADER_FLAG_CLEANUP;
5600 else if (unformat (i, "protected"))
5601 flags |= IP6_SR_HEADER_FLAG_PROTECTED;
5602 else if (unformat (i, "InPE %d", &pl_index))
5604 if (pl_index <= 0 || pl_index > 4)
5606 pl_index_range_error:
5607 errmsg ("pl index %d out of range\n", pl_index);
5610 flags |= IP6_SR_HEADER_FLAG_PL_ELT_INGRESS_PE << (3*(pl_index - 1));
5612 else if (unformat (i, "EgPE %d", &pl_index))
5614 if (pl_index <= 0 || pl_index > 4)
5615 goto pl_index_range_error;
5616 flags |= IP6_SR_HEADER_FLAG_PL_ELT_EGRESS_PE << (3*(pl_index - 1));
5618 else if (unformat (i, "OrgSrc %d", &pl_index))
5620 if (pl_index <= 0 || pl_index > 4)
5621 goto pl_index_range_error;
5622 flags |= IP6_SR_HEADER_FLAG_PL_ELT_ORIG_SRC_ADDR << (3*(pl_index - 1));
5628 if (!src_address_set)
5630 errmsg ("src address required\n");
5634 if (!dst_address_set)
5636 errmsg ("dst address required\n");
5642 errmsg ("at least one sr segment required\n");
5646 M2(SR_TUNNEL_ADD_DEL, sr_tunnel_add_del,
5647 vec_len(segments) * sizeof (ip6_address_t)
5648 + vec_len(tags) * sizeof (ip6_address_t));
5650 clib_memcpy (mp->src_address, &src_address, sizeof (mp->src_address));
5651 clib_memcpy (mp->dst_address, &dst_address, sizeof (mp->dst_address));
5652 mp->dst_mask_width = dst_mask_width;
5653 mp->flags_net_byte_order = clib_host_to_net_u16 (flags);
5654 mp->n_segments = vec_len (segments);
5655 mp->n_tags = vec_len (tags);
5656 mp->is_add = is_del == 0;
5657 clib_memcpy (mp->segs_and_tags, segments,
5658 vec_len(segments)* sizeof (ip6_address_t));
5659 clib_memcpy (mp->segs_and_tags + vec_len(segments)*sizeof (ip6_address_t),
5660 tags, vec_len(tags)* sizeof (ip6_address_t));
5662 mp->outer_vrf_id = ntohl (rx_table_id);
5663 mp->inner_vrf_id = ntohl (tx_table_id);
5664 memcpy (mp->name, name, vec_len(name));
5665 memcpy (mp->policy_name, policy_name, vec_len(policy_name));
5667 vec_free (segments);
5674 static int api_sr_policy_add_del (vat_main_t * vam)
5676 unformat_input_t * input = vam->input;
5677 vl_api_sr_policy_add_del_t *mp;
5681 u8 * tunnel_name = 0;
5682 u8 ** tunnel_names = 0;
5687 int tunnel_names_length = 1; // Init to 1 to offset the #tunnel_names counter byte
5688 int tun_name_len = 0; // Different naming convention used as confusing these would be "bad" (TM)
5690 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
5692 if (unformat (input, "del"))
5694 else if (unformat (input, "name %s", &name))
5696 else if (unformat (input, "tunnel %s", &tunnel_name))
5700 vec_add1 (tunnel_names, tunnel_name);
5702 - length = #bytes to store in serial vector
5703 - +1 = byte to store that length
5705 tunnel_names_length += (vec_len (tunnel_name) + 1);
5716 errmsg ("policy name required\n");
5720 if ((!tunnel_set) && (!is_del))
5722 errmsg ("tunnel name required\n");
5726 M2(SR_POLICY_ADD_DEL, sr_policy_add_del, tunnel_names_length);
5730 mp->is_add = !is_del;
5732 memcpy (mp->name, name, vec_len(name));
5733 // Since mp->tunnel_names is of type u8[0] and not a u8 *, u8 ** needs to be serialized
5734 u8 * serial_orig = 0;
5735 vec_validate (serial_orig, tunnel_names_length);
5736 *serial_orig = vec_len(tunnel_names); // Store the number of tunnels as length in first byte of serialized vector
5737 serial_orig += 1; // Move along one byte to store the length of first tunnel_name
5739 for (j=0; j < vec_len(tunnel_names); j++)
5741 tun_name_len = vec_len (tunnel_names[j]);
5742 *serial_orig = tun_name_len; // Store length of tunnel name in first byte of Length/Value pair
5743 serial_orig += 1; // Move along one byte to store the actual tunnel name
5744 memcpy (serial_orig, tunnel_names[j], tun_name_len);
5745 serial_orig += tun_name_len; // Advance past the copy
5747 memcpy (mp->tunnel_names, serial_orig - tunnel_names_length, tunnel_names_length); // Regress serial_orig to head then copy fwd
5749 vec_free (tunnel_names);
5750 vec_free (tunnel_name);
5756 static int api_sr_multicast_map_add_del (vat_main_t * vam)
5758 unformat_input_t * input = vam->input;
5759 vl_api_sr_multicast_map_add_del_t *mp;
5762 ip6_address_t multicast_address;
5763 u8 * policy_name = 0;
5764 int multicast_address_set = 0;
5766 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
5768 if (unformat (input, "del"))
5770 else if (unformat (input, "address %U", unformat_ip6_address, &multicast_address))
5771 multicast_address_set = 1;
5772 else if (unformat (input, "sr-policy %s", &policy_name))
5778 if (!is_del && !policy_name)
5780 errmsg ("sr-policy name required\n");
5785 if (!multicast_address_set)
5787 errmsg ("address required\n");
5791 M(SR_MULTICAST_MAP_ADD_DEL, sr_multicast_map_add_del);
5793 mp->is_add = !is_del;
5794 memcpy (mp->policy_name, policy_name, vec_len(policy_name));
5795 clib_memcpy (mp->multicast_address, &multicast_address, sizeof (mp->multicast_address));
5798 vec_free (policy_name);
5805 #define foreach_ip4_proto_field \
5815 uword unformat_ip4_mask (unformat_input_t * input, va_list * args)
5817 u8 ** maskp = va_arg (*args, u8 **);
5819 u8 found_something = 0;
5822 #define _(a) u8 a=0;
5823 foreach_ip4_proto_field;
5829 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
5831 if (unformat (input, "version"))
5833 else if (unformat (input, "hdr_length"))
5835 else if (unformat (input, "src"))
5837 else if (unformat (input, "dst"))
5839 else if (unformat (input, "proto"))
5842 #define _(a) else if (unformat (input, #a)) a=1;
5843 foreach_ip4_proto_field
5849 #define _(a) found_something += a;
5850 foreach_ip4_proto_field;
5853 if (found_something == 0)
5856 vec_validate (mask, sizeof (*ip) - 1);
5858 ip = (ip4_header_t *) mask;
5860 #define _(a) if (a) memset (&ip->a, 0xff, sizeof (ip->a));
5861 foreach_ip4_proto_field;
5864 ip->ip_version_and_header_length = 0;
5867 ip->ip_version_and_header_length |= 0xF0;
5870 ip->ip_version_and_header_length |= 0x0F;
5876 #define foreach_ip6_proto_field \
5883 uword unformat_ip6_mask (unformat_input_t * input, va_list * args)
5885 u8 ** maskp = va_arg (*args, u8 **);
5887 u8 found_something = 0;
5889 u32 ip_version_traffic_class_and_flow_label;
5891 #define _(a) u8 a=0;
5892 foreach_ip6_proto_field;
5895 u8 traffic_class = 0;
5898 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
5900 if (unformat (input, "version"))
5902 else if (unformat (input, "traffic-class"))
5904 else if (unformat (input, "flow-label"))
5906 else if (unformat (input, "src"))
5908 else if (unformat (input, "dst"))
5910 else if (unformat (input, "proto"))
5913 #define _(a) else if (unformat (input, #a)) a=1;
5914 foreach_ip6_proto_field
5920 #define _(a) found_something += a;
5921 foreach_ip6_proto_field;
5924 if (found_something == 0)
5927 vec_validate (mask, sizeof (*ip) - 1);
5929 ip = (ip6_header_t *) mask;
5931 #define _(a) if (a) memset (&ip->a, 0xff, sizeof (ip->a));
5932 foreach_ip6_proto_field;
5935 ip_version_traffic_class_and_flow_label = 0;
5938 ip_version_traffic_class_and_flow_label |= 0xF0000000;
5941 ip_version_traffic_class_and_flow_label |= 0x0FF00000;
5944 ip_version_traffic_class_and_flow_label |= 0x000FFFFF;
5946 ip->ip_version_traffic_class_and_flow_label =
5947 clib_host_to_net_u32 (ip_version_traffic_class_and_flow_label);
5953 uword unformat_l3_mask (unformat_input_t * input, va_list * args)
5955 u8 ** maskp = va_arg (*args, u8 **);
5957 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) {
5958 if (unformat (input, "ip4 %U", unformat_ip4_mask, maskp))
5960 else if (unformat (input, "ip6 %U", unformat_ip6_mask, maskp))
5968 uword unformat_l2_mask (unformat_input_t * input, va_list * args)
5970 u8 ** maskp = va_arg (*args, u8 **);
5985 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) {
5986 if (unformat (input, "src"))
5988 else if (unformat (input, "dst"))
5990 else if (unformat (input, "proto"))
5992 else if (unformat (input, "tag1"))
5994 else if (unformat (input, "tag2"))
5996 else if (unformat (input, "ignore-tag1"))
5998 else if (unformat (input, "ignore-tag2"))
6000 else if (unformat (input, "cos1"))
6002 else if (unformat (input, "cos2"))
6004 else if (unformat (input, "dot1q"))
6006 else if (unformat (input, "dot1ad"))
6011 if ((src + dst + proto + tag1 + tag2 + dot1q + dot1ad +
6012 ignore_tag1 + ignore_tag2 + cos1 + cos2) == 0)
6015 if (tag1 || ignore_tag1 || cos1 || dot1q)
6017 if (tag2 || ignore_tag2 || cos2 || dot1ad)
6020 vec_validate (mask, len-1);
6023 memset (mask, 0xff, 6);
6026 memset (mask + 6, 0xff, 6);
6030 /* inner vlan tag */
6039 mask[21] = mask [20] = 0xff;
6060 mask[16] = mask [17] = 0xff;
6070 mask[12] = mask [13] = 0xff;
6076 uword unformat_classify_mask (unformat_input_t * input, va_list * args)
6078 u8 ** maskp = va_arg (*args, u8 **);
6079 u32 * skipp = va_arg (*args, u32 *);
6080 u32 * matchp = va_arg (*args, u32 *);
6087 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) {
6088 if (unformat (input, "hex %U", unformat_hex_string, &mask))
6090 else if (unformat (input, "l2 %U", unformat_l2_mask, &l2))
6092 else if (unformat (input, "l3 %U", unformat_l3_mask, &l3))
6098 if (mask || l2 || l3)
6102 /* "With a free Ethernet header in every package" */
6104 vec_validate (l2, 13);
6106 vec_append (mask, l3);
6110 /* Scan forward looking for the first significant mask octet */
6111 for (i = 0; i < vec_len (mask); i++)
6115 /* compute (skip, match) params */
6116 *skipp = i / sizeof(u32x4);
6117 vec_delete (mask, *skipp * sizeof(u32x4), 0);
6119 /* Pad mask to an even multiple of the vector size */
6120 while (vec_len (mask) % sizeof (u32x4))
6123 match = vec_len (mask) / sizeof (u32x4);
6125 for (i = match*sizeof(u32x4); i > 0; i-= sizeof(u32x4))
6127 u64 *tmp = (u64 *)(mask + (i-sizeof(u32x4)));
6128 if (*tmp || *(tmp+1))
6133 clib_warning ("BUG: match 0");
6135 _vec_len (mask) = match * sizeof(u32x4);
6146 #define foreach_l2_next \
6148 _(ethernet, ETHERNET_INPUT) \
6152 uword unformat_l2_next_index (unformat_input_t * input, va_list * args)
6154 u32 * miss_next_indexp = va_arg (*args, u32 *);
6159 if (unformat (input, #n)) { next_index = L2_CLASSIFY_NEXT_##N; goto out;}
6163 if (unformat (input, "%d", &tmp))
6172 *miss_next_indexp = next_index;
6176 #define foreach_ip_next \
6182 uword unformat_ip_next_index (unformat_input_t * input, va_list * args)
6184 u32 * miss_next_indexp = va_arg (*args, u32 *);
6189 if (unformat (input, #n)) { next_index = IP_LOOKUP_NEXT_##N; goto out;}
6193 if (unformat (input, "%d", &tmp))
6202 *miss_next_indexp = next_index;
6206 #define foreach_acl_next \
6209 uword unformat_acl_next_index (unformat_input_t * input, va_list * args)
6211 u32 * miss_next_indexp = va_arg (*args, u32 *);
6216 if (unformat (input, #n)) { next_index = ACL_NEXT_INDEX_##N; goto out;}
6220 if (unformat (input, "permit"))
6225 else if (unformat (input, "%d", &tmp))
6234 *miss_next_indexp = next_index;
6238 static int api_classify_add_del_table (vat_main_t * vam)
6240 unformat_input_t * i = vam->input;
6241 vl_api_classify_add_del_table_t *mp;
6247 u32 table_index = ~0;
6248 u32 next_table_index = ~0;
6249 u32 miss_next_index = ~0;
6250 u32 memory_size = 32<<20;
6254 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
6255 if (unformat (i, "del"))
6257 else if (unformat (i, "buckets %d", &nbuckets))
6259 else if (unformat (i, "memory_size %d", &memory_size))
6261 else if (unformat (i, "skip %d", &skip))
6263 else if (unformat (i, "match %d", &match))
6265 else if (unformat (i, "table %d", &table_index))
6267 else if (unformat (i, "mask %U", unformat_classify_mask,
6268 &mask, &skip, &match))
6270 else if (unformat (i, "next-table %d", &next_table_index))
6272 else if (unformat (i, "miss-next %U", unformat_ip_next_index,
6275 else if (unformat (i, "l2-miss-next %U", unformat_l2_next_index,
6278 else if (unformat (i, "acl-miss-next %U", unformat_acl_next_index,
6285 if (is_add && mask == 0) {
6286 errmsg ("Mask required\n");
6290 if (is_add && skip == ~0) {
6291 errmsg ("skip count required\n");
6295 if (is_add && match == ~0) {
6296 errmsg ("match count required\n");
6300 if (!is_add && table_index == ~0) {
6301 errmsg ("table index required for delete\n");
6305 M2 (CLASSIFY_ADD_DEL_TABLE, classify_add_del_table,
6308 mp->is_add = is_add;
6309 mp->table_index = ntohl(table_index);
6310 mp->nbuckets = ntohl(nbuckets);
6311 mp->memory_size = ntohl(memory_size);
6312 mp->skip_n_vectors = ntohl(skip);
6313 mp->match_n_vectors = ntohl(match);
6314 mp->next_table_index = ntohl(next_table_index);
6315 mp->miss_next_index = ntohl(miss_next_index);
6316 clib_memcpy (mp->mask, mask, vec_len(mask));
6324 uword unformat_ip4_match (unformat_input_t * input, va_list * args)
6326 u8 ** matchp = va_arg (*args, u8 **);
6333 int src = 0, dst = 0;
6334 ip4_address_t src_val, dst_val;
6341 int fragment_id = 0;
6342 u32 fragment_id_val;
6348 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
6350 if (unformat (input, "version %d", &version_val))
6352 else if (unformat (input, "hdr_length %d", &hdr_length_val))
6354 else if (unformat (input, "src %U", unformat_ip4_address, &src_val))
6356 else if (unformat (input, "dst %U", unformat_ip4_address, &dst_val))
6358 else if (unformat (input, "proto %d", &proto_val))
6360 else if (unformat (input, "tos %d", &tos_val))
6362 else if (unformat (input, "length %d", &length_val))
6364 else if (unformat (input, "fragment_id %d", &fragment_id_val))
6366 else if (unformat (input, "ttl %d", &ttl_val))
6368 else if (unformat (input, "checksum %d", &checksum_val))
6374 if (version + hdr_length + src + dst + proto + tos + length + fragment_id
6375 + ttl + checksum == 0)
6379 * Aligned because we use the real comparison functions
6381 vec_validate_aligned (match, sizeof (*ip) - 1, sizeof(u32x4));
6383 ip = (ip4_header_t *) match;
6385 /* These are realistically matched in practice */
6387 ip->src_address.as_u32 = src_val.as_u32;
6390 ip->dst_address.as_u32 = dst_val.as_u32;
6393 ip->protocol = proto_val;
6396 /* These are not, but they're included for completeness */
6398 ip->ip_version_and_header_length |= (version_val & 0xF)<<4;
6401 ip->ip_version_and_header_length |= (hdr_length_val & 0xF);
6407 ip->length = length_val;
6413 ip->checksum = checksum_val;
6419 uword unformat_ip6_match (unformat_input_t * input, va_list * args)
6421 u8 ** matchp = va_arg (*args, u8 **);
6427 u32 traffic_class_val;
6430 int src = 0, dst = 0;
6431 ip6_address_t src_val, dst_val;
6434 int payload_length = 0;
6435 u32 payload_length_val;
6438 u32 ip_version_traffic_class_and_flow_label;
6440 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
6442 if (unformat (input, "version %d", &version_val))
6444 else if (unformat (input, "traffic_class %d", &traffic_class_val))
6446 else if (unformat (input, "flow_label %d", &flow_label_val))
6448 else if (unformat (input, "src %U", unformat_ip6_address, &src_val))
6450 else if (unformat (input, "dst %U", unformat_ip6_address, &dst_val))
6452 else if (unformat (input, "proto %d", &proto_val))
6454 else if (unformat (input, "payload_length %d", &payload_length_val))
6456 else if (unformat (input, "hop_limit %d", &hop_limit_val))
6462 if (version + traffic_class + flow_label + src + dst + proto +
6463 payload_length + hop_limit == 0)
6467 * Aligned because we use the real comparison functions
6469 vec_validate_aligned (match, sizeof (*ip) - 1, sizeof(u32x4));
6471 ip = (ip6_header_t *) match;
6474 clib_memcpy (&ip->src_address, &src_val, sizeof (ip->src_address));
6477 clib_memcpy (&ip->dst_address, &dst_val, sizeof (ip->dst_address));
6480 ip->protocol = proto_val;
6482 ip_version_traffic_class_and_flow_label = 0;
6485 ip_version_traffic_class_and_flow_label |= (version_val & 0xF) << 28;
6488 ip_version_traffic_class_and_flow_label |= (traffic_class_val & 0xFF) << 20;
6491 ip_version_traffic_class_and_flow_label |= (flow_label_val & 0xFFFFF);
6493 ip->ip_version_traffic_class_and_flow_label =
6494 clib_host_to_net_u32 (ip_version_traffic_class_and_flow_label);
6497 ip->payload_length = clib_host_to_net_u16 (payload_length_val);
6500 ip->hop_limit = hop_limit_val;
6506 uword unformat_l3_match (unformat_input_t * input, va_list * args)
6508 u8 ** matchp = va_arg (*args, u8 **);
6510 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) {
6511 if (unformat (input, "ip4 %U", unformat_ip4_match, matchp))
6513 else if (unformat (input, "ip6 %U", unformat_ip6_match, matchp))
6521 uword unformat_vlan_tag (unformat_input_t * input, va_list * args)
6523 u8 * tagp = va_arg (*args, u8 *);
6526 if (unformat(input, "%d", &tag))
6528 tagp[0] = (tag>>8) & 0x0F;
6529 tagp[1] = tag & 0xFF;
6536 uword unformat_l2_match (unformat_input_t * input, va_list * args)
6538 u8 ** matchp = va_arg (*args, u8 **);
6558 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) {
6559 if (unformat (input, "src %U", unformat_ethernet_address, &src_val))
6561 else if (unformat (input, "dst %U", unformat_ethernet_address, &dst_val))
6563 else if (unformat (input, "proto %U",
6564 unformat_ethernet_type_host_byte_order, &proto_val))
6566 else if (unformat (input, "tag1 %U", unformat_vlan_tag, tag1_val))
6568 else if (unformat (input, "tag2 %U", unformat_vlan_tag, tag2_val))
6570 else if (unformat (input, "ignore-tag1"))
6572 else if (unformat (input, "ignore-tag2"))
6574 else if (unformat (input, "cos1 %d", &cos1_val))
6576 else if (unformat (input, "cos2 %d", &cos2_val))
6581 if ((src + dst + proto + tag1 + tag2 +
6582 ignore_tag1 + ignore_tag2 + cos1 + cos2) == 0)
6585 if (tag1 || ignore_tag1 || cos1)
6587 if (tag2 || ignore_tag2 || cos2)
6590 vec_validate_aligned (match, len-1, sizeof(u32x4));
6593 clib_memcpy (match, dst_val, 6);
6596 clib_memcpy (match + 6, src_val, 6);
6600 /* inner vlan tag */
6601 match[19] = tag2_val[1];
6602 match[18] = tag2_val[0];
6604 match [18] |= (cos2_val & 0x7) << 5;
6607 match[21] = proto_val & 0xff;
6608 match[20] = proto_val >> 8;
6612 match [15] = tag1_val[1];
6613 match [14] = tag1_val[0];
6616 match [14] |= (cos1_val & 0x7) << 5;
6622 match [15] = tag1_val[1];
6623 match [14] = tag1_val[0];
6626 match[17] = proto_val & 0xff;
6627 match[16] = proto_val >> 8;
6630 match [14] |= (cos1_val & 0x7) << 5;
6636 match [18] |= (cos2_val & 0x7) << 5;
6638 match [14] |= (cos1_val & 0x7) << 5;
6641 match[13] = proto_val & 0xff;
6642 match[12] = proto_val >> 8;
6650 uword unformat_classify_match (unformat_input_t * input, va_list * args)
6652 u8 ** matchp = va_arg (*args, u8 **);
6653 u32 skip_n_vectors = va_arg (*args, u32);
6654 u32 match_n_vectors = va_arg (*args, u32);
6660 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) {
6661 if (unformat (input, "hex %U", unformat_hex_string, &match))
6663 else if (unformat (input, "l2 %U", unformat_l2_match, &l2))
6665 else if (unformat (input, "l3 %U", unformat_l3_match, &l3))
6671 if (match || l2 || l3)
6675 /* "Win a free Ethernet header in every packet" */
6677 vec_validate_aligned (l2, 13, sizeof(u32x4));
6679 vec_append_aligned (match, l3, sizeof(u32x4));
6683 /* Make sure the vector is big enough even if key is all 0's */
6684 vec_validate_aligned
6685 (match, ((match_n_vectors + skip_n_vectors) * sizeof(u32x4)) - 1,
6688 /* Set size, include skipped vectors*/
6689 _vec_len (match) = (match_n_vectors+skip_n_vectors) * sizeof(u32x4);
6699 static int api_classify_add_del_session (vat_main_t * vam)
6701 unformat_input_t * i = vam->input;
6702 vl_api_classify_add_del_session_t *mp;
6704 u32 table_index = ~0;
6705 u32 hit_next_index = ~0;
6706 u32 opaque_index = ~0;
6710 u32 skip_n_vectors = 0;
6711 u32 match_n_vectors = 0;
6714 * Warning: you have to supply skip_n and match_n
6715 * because the API client cant simply look at the classify
6719 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
6720 if (unformat (i, "del"))
6722 else if (unformat (i, "hit-next %U", unformat_ip_next_index,
6725 else if (unformat (i, "l2-hit-next %U", unformat_l2_next_index,
6728 else if (unformat (i, "acl-hit-next %U", unformat_acl_next_index,
6731 else if (unformat (i, "opaque-index %d", &opaque_index))
6733 else if (unformat (i, "skip_n %d", &skip_n_vectors))
6735 else if (unformat (i, "match_n %d", &match_n_vectors))
6737 else if (unformat (i, "match %U", unformat_classify_match,
6738 &match, skip_n_vectors, match_n_vectors))
6740 else if (unformat (i, "advance %d", &advance))
6742 else if (unformat (i, "table-index %d", &table_index))
6748 if (table_index == ~0) {
6749 errmsg ("Table index required\n");
6753 if (is_add && match == 0) {
6754 errmsg ("Match value required\n");
6758 M2 (CLASSIFY_ADD_DEL_SESSION, classify_add_del_session,
6761 mp->is_add = is_add;
6762 mp->table_index = ntohl(table_index);
6763 mp->hit_next_index = ntohl(hit_next_index);
6764 mp->opaque_index = ntohl(opaque_index);
6765 mp->advance = ntohl(advance);
6766 clib_memcpy (mp->match, match, vec_len(match));
6773 static int api_classify_set_interface_ip_table (vat_main_t * vam)
6775 unformat_input_t * i = vam->input;
6776 vl_api_classify_set_interface_ip_table_t *mp;
6779 int sw_if_index_set;
6780 u32 table_index = ~0;
6783 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
6784 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
6785 sw_if_index_set = 1;
6786 else if (unformat (i, "sw_if_index %d", &sw_if_index))
6787 sw_if_index_set = 1;
6788 else if (unformat (i, "table %d", &table_index))
6791 clib_warning ("parse error '%U'", format_unformat_error, i);
6796 if (sw_if_index_set == 0) {
6797 errmsg ("missing interface name or sw_if_index\n");
6802 M(CLASSIFY_SET_INTERFACE_IP_TABLE, classify_set_interface_ip_table);
6804 mp->sw_if_index = ntohl(sw_if_index);
6805 mp->table_index = ntohl(table_index);
6806 mp->is_ipv6 = is_ipv6;
6813 static int api_classify_set_interface_l2_tables (vat_main_t * vam)
6815 unformat_input_t * i = vam->input;
6816 vl_api_classify_set_interface_l2_tables_t *mp;
6819 int sw_if_index_set;
6820 u32 ip4_table_index = ~0;
6821 u32 ip6_table_index = ~0;
6822 u32 other_table_index = ~0;
6824 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
6825 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
6826 sw_if_index_set = 1;
6827 else if (unformat (i, "sw_if_index %d", &sw_if_index))
6828 sw_if_index_set = 1;
6829 else if (unformat (i, "ip4-table %d", &ip4_table_index))
6831 else if (unformat (i, "ip6-table %d", &ip6_table_index))
6833 else if (unformat (i, "other-table %d", &other_table_index))
6836 clib_warning ("parse error '%U'", format_unformat_error, i);
6841 if (sw_if_index_set == 0) {
6842 errmsg ("missing interface name or sw_if_index\n");
6847 M(CLASSIFY_SET_INTERFACE_L2_TABLES, classify_set_interface_l2_tables);
6849 mp->sw_if_index = ntohl(sw_if_index);
6850 mp->ip4_table_index = ntohl(ip4_table_index);
6851 mp->ip6_table_index = ntohl(ip6_table_index);
6852 mp->other_table_index = ntohl(other_table_index);
6860 static int api_get_node_index (vat_main_t * vam)
6862 unformat_input_t * i = vam->input;
6863 vl_api_get_node_index_t * mp;
6867 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
6868 if (unformat (i, "node %s", &name))
6874 errmsg ("node name required\n");
6877 if (vec_len (name) >= ARRAY_LEN(mp->node_name)) {
6878 errmsg ("node name too long, max %d\n", ARRAY_LEN(mp->node_name));
6882 M(GET_NODE_INDEX, get_node_index);
6883 clib_memcpy (mp->node_name, name, vec_len(name));
6891 static int api_add_node_next (vat_main_t * vam)
6893 unformat_input_t * i = vam->input;
6894 vl_api_add_node_next_t * mp;
6899 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
6900 if (unformat (i, "node %s", &name))
6902 else if (unformat (i, "next %s", &next))
6908 errmsg ("node name required\n");
6911 if (vec_len (name) >= ARRAY_LEN(mp->node_name)) {
6912 errmsg ("node name too long, max %d\n", ARRAY_LEN(mp->node_name));
6916 errmsg ("next node required\n");
6919 if (vec_len (next) >= ARRAY_LEN(mp->next_name)) {
6920 errmsg ("next name too long, max %d\n", ARRAY_LEN(mp->next_name));
6924 M(ADD_NODE_NEXT, add_node_next);
6925 clib_memcpy (mp->node_name, name, vec_len(name));
6926 clib_memcpy (mp->next_name, next, vec_len(next));
6935 static int api_l2tpv3_create_tunnel (vat_main_t * vam)
6937 unformat_input_t * i = vam->input;
6938 ip6_address_t client_address, our_address;
6939 int client_address_set = 0;
6940 int our_address_set = 0;
6941 u32 local_session_id = 0;
6942 u32 remote_session_id = 0;
6943 u64 local_cookie = 0;
6944 u64 remote_cookie = 0;
6945 u8 l2_sublayer_present = 0;
6946 vl_api_l2tpv3_create_tunnel_t * mp;
6949 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
6950 if (unformat (i, "client_address %U", unformat_ip6_address,
6952 client_address_set = 1;
6953 else if (unformat (i, "our_address %U", unformat_ip6_address,
6955 our_address_set = 1;
6956 else if (unformat (i, "local_session_id %d", &local_session_id))
6958 else if (unformat (i, "remote_session_id %d", &remote_session_id))
6960 else if (unformat (i, "local_cookie %lld", &local_cookie))
6962 else if (unformat (i, "remote_cookie %lld", &remote_cookie))
6964 else if (unformat (i, "l2-sublayer-present"))
6965 l2_sublayer_present = 1;
6970 if (client_address_set == 0) {
6971 errmsg ("client_address required\n");
6975 if (our_address_set == 0) {
6976 errmsg ("our_address required\n");
6980 M(L2TPV3_CREATE_TUNNEL, l2tpv3_create_tunnel);
6982 clib_memcpy (mp->client_address, client_address.as_u8,
6983 sizeof (mp->client_address));
6985 clib_memcpy (mp->our_address, our_address.as_u8,
6986 sizeof (mp->our_address));
6988 mp->local_session_id = ntohl (local_session_id);
6989 mp->remote_session_id = ntohl (remote_session_id);
6990 mp->local_cookie = clib_host_to_net_u64 (local_cookie);
6991 mp->remote_cookie = clib_host_to_net_u64 (remote_cookie);
6992 mp->l2_sublayer_present = l2_sublayer_present;
7000 static int api_l2tpv3_set_tunnel_cookies (vat_main_t * vam)
7002 unformat_input_t * i = vam->input;
7004 u8 sw_if_index_set = 0;
7005 u64 new_local_cookie = 0;
7006 u64 new_remote_cookie = 0;
7007 vl_api_l2tpv3_set_tunnel_cookies_t *mp;
7010 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
7011 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
7012 sw_if_index_set = 1;
7013 else if (unformat (i, "sw_if_index %d", &sw_if_index))
7014 sw_if_index_set = 1;
7015 else if (unformat (i, "new_local_cookie %lld", &new_local_cookie))
7017 else if (unformat (i, "new_remote_cookie %lld", &new_remote_cookie))
7023 if (sw_if_index_set == 0) {
7024 errmsg ("missing interface name or sw_if_index\n");
7028 M(L2TPV3_SET_TUNNEL_COOKIES, l2tpv3_set_tunnel_cookies);
7030 mp->sw_if_index = ntohl(sw_if_index);
7031 mp->new_local_cookie = clib_host_to_net_u64 (new_local_cookie);
7032 mp->new_remote_cookie = clib_host_to_net_u64 (new_remote_cookie);
7039 static int api_l2tpv3_interface_enable_disable (vat_main_t * vam)
7041 unformat_input_t * i = vam->input;
7042 vl_api_l2tpv3_interface_enable_disable_t *mp;
7045 u8 sw_if_index_set = 0;
7046 u8 enable_disable = 1;
7048 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
7049 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
7050 sw_if_index_set = 1;
7051 else if (unformat (i, "sw_if_index %d", &sw_if_index))
7052 sw_if_index_set = 1;
7053 else if (unformat (i, "enable"))
7055 else if (unformat (i, "disable"))
7061 if (sw_if_index_set == 0) {
7062 errmsg ("missing interface name or sw_if_index\n");
7066 M(L2TPV3_INTERFACE_ENABLE_DISABLE, l2tpv3_interface_enable_disable);
7068 mp->sw_if_index = ntohl(sw_if_index);
7069 mp->enable_disable = enable_disable;
7076 static int api_l2tpv3_set_lookup_key (vat_main_t * vam)
7078 unformat_input_t * i = vam->input;
7079 vl_api_l2tpv3_set_lookup_key_t * mp;
7083 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
7084 if (unformat (i, "lookup_v6_src"))
7085 key = L2T_LOOKUP_SRC_ADDRESS;
7086 else if (unformat (i, "lookup_v6_dst"))
7087 key = L2T_LOOKUP_DST_ADDRESS;
7088 else if (unformat (i, "lookup_session_id"))
7089 key = L2T_LOOKUP_SESSION_ID;
7094 if (key == (u8) ~0) {
7095 errmsg ("l2tp session lookup key unset\n");
7099 M(L2TPV3_SET_LOOKUP_KEY, l2tpv3_set_lookup_key);
7108 static void vl_api_sw_if_l2tpv3_tunnel_details_t_handler
7109 (vl_api_sw_if_l2tpv3_tunnel_details_t * mp)
7111 vat_main_t * vam = &vat_main;
7113 fformat(vam->ofp, "* %U (our) %U (client) (sw_if_index %d)\n",
7114 format_ip6_address, mp->our_address,
7115 format_ip6_address, mp->client_address,
7116 clib_net_to_host_u32(mp->sw_if_index));
7118 fformat (vam->ofp, " local cookies %016llx %016llx remote cookie %016llx\n",
7119 clib_net_to_host_u64 (mp->local_cookie[0]),
7120 clib_net_to_host_u64 (mp->local_cookie[1]),
7121 clib_net_to_host_u64 (mp->remote_cookie));
7123 fformat (vam->ofp, " local session-id %d remote session-id %d\n",
7124 clib_net_to_host_u32 (mp->local_session_id),
7125 clib_net_to_host_u32 (mp->remote_session_id));
7127 fformat (vam->ofp, " l2 specific sublayer %s\n\n",
7128 mp->l2_sublayer_present ? "preset" : "absent");
7132 static void vl_api_sw_if_l2tpv3_tunnel_details_t_handler_json
7133 (vl_api_sw_if_l2tpv3_tunnel_details_t * mp)
7135 vat_main_t * vam = &vat_main;
7136 vat_json_node_t *node = NULL;
7137 struct in6_addr addr;
7139 if (VAT_JSON_ARRAY != vam->json_tree.type) {
7140 ASSERT(VAT_JSON_NONE == vam->json_tree.type);
7141 vat_json_init_array(&vam->json_tree);
7143 node = vat_json_array_add(&vam->json_tree);
7145 vat_json_init_object(node);
7147 clib_memcpy(&addr, mp->our_address, sizeof(addr));
7148 vat_json_object_add_ip6(node, "our_address", addr);
7149 clib_memcpy(&addr, mp->client_address, sizeof(addr));
7150 vat_json_object_add_ip6(node, "client_address", addr);
7152 vat_json_node_t * lc = vat_json_object_add(node, "local_cookie");
7153 vat_json_init_array(lc);
7154 vat_json_array_add_uint(lc, clib_net_to_host_u64(mp->local_cookie[0]));
7155 vat_json_array_add_uint(lc, clib_net_to_host_u64(mp->local_cookie[1]));
7156 vat_json_object_add_uint(node, "remote_cookie", clib_net_to_host_u64(mp->remote_cookie));
7158 printf("local id: %u", clib_net_to_host_u32(mp->local_session_id));
7159 vat_json_object_add_uint(node, "local_session_id", clib_net_to_host_u32(mp->local_session_id));
7160 vat_json_object_add_uint(node, "remote_session_id", clib_net_to_host_u32(mp->remote_session_id));
7161 vat_json_object_add_string_copy(node, "l2_sublayer", mp->l2_sublayer_present ?
7162 (u8*)"present" : (u8*)"absent");
7165 static int api_sw_if_l2tpv3_tunnel_dump (vat_main_t * vam)
7167 vl_api_sw_if_l2tpv3_tunnel_dump_t *mp;
7170 /* Get list of l2tpv3-tunnel interfaces */
7171 M(SW_IF_L2TPV3_TUNNEL_DUMP, sw_if_l2tpv3_tunnel_dump);
7174 /* Use a control ping for synchronization */
7176 vl_api_control_ping_t * mp;
7177 M(CONTROL_PING, control_ping);
7184 static void vl_api_sw_interface_tap_details_t_handler
7185 (vl_api_sw_interface_tap_details_t * mp)
7187 vat_main_t * vam = &vat_main;
7189 fformat(vam->ofp, "%-16s %d\n",
7191 clib_net_to_host_u32(mp->sw_if_index));
7194 static void vl_api_sw_interface_tap_details_t_handler_json
7195 (vl_api_sw_interface_tap_details_t * mp)
7197 vat_main_t * vam = &vat_main;
7198 vat_json_node_t *node = NULL;
7200 if (VAT_JSON_ARRAY != vam->json_tree.type) {
7201 ASSERT(VAT_JSON_NONE == vam->json_tree.type);
7202 vat_json_init_array(&vam->json_tree);
7204 node = vat_json_array_add(&vam->json_tree);
7206 vat_json_init_object(node);
7207 vat_json_object_add_uint(node, "sw_if_index", ntohl(mp->sw_if_index));
7208 vat_json_object_add_string_copy(node, "dev_name", mp->dev_name);
7211 static int api_sw_interface_tap_dump (vat_main_t * vam)
7213 vl_api_sw_interface_tap_dump_t *mp;
7216 fformat(vam->ofp, "\n%-16s %s\n", "dev_name", "sw_if_index");
7217 /* Get list of tap interfaces */
7218 M(SW_INTERFACE_TAP_DUMP, sw_interface_tap_dump);
7221 /* Use a control ping for synchronization */
7223 vl_api_control_ping_t * mp;
7224 M(CONTROL_PING, control_ping);
7230 static uword unformat_vxlan_decap_next
7231 (unformat_input_t * input, va_list * args)
7233 u32 * result = va_arg (*args, u32 *);
7236 if (unformat (input, "drop"))
7237 *result = VXLAN_INPUT_NEXT_DROP;
7238 else if (unformat (input, "ip4"))
7239 *result = VXLAN_INPUT_NEXT_IP4_INPUT;
7240 else if (unformat (input, "ip6"))
7241 *result = VXLAN_INPUT_NEXT_IP6_INPUT;
7242 else if (unformat (input, "l2"))
7243 *result = VXLAN_INPUT_NEXT_L2_INPUT;
7244 else if (unformat (input, "%d", &tmp))
7251 static int api_vxlan_add_del_tunnel (vat_main_t * vam)
7253 unformat_input_t * line_input = vam->input;
7254 vl_api_vxlan_add_del_tunnel_t *mp;
7256 ip4_address_t src4, dst4;
7257 ip6_address_t src6, dst6;
7259 u8 ipv4_set = 0, ipv6_set = 0;
7262 u32 encap_vrf_id = 0;
7263 u32 decap_next_index = ~0;
7266 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) {
7267 if (unformat (line_input, "del"))
7269 else if (unformat (line_input, "src %U",
7270 unformat_ip4_address, &src4))
7275 else if (unformat (line_input, "dst %U",
7276 unformat_ip4_address, &dst4))
7281 else if (unformat (line_input, "src %U",
7282 unformat_ip6_address, &src6))
7287 else if (unformat (line_input, "dst %U",
7288 unformat_ip6_address, &dst6))
7293 else if (unformat (line_input, "encap-vrf-id %d", &encap_vrf_id))
7295 else if (unformat (line_input, "decap-next %U",
7296 unformat_vxlan_decap_next, &decap_next_index))
7298 else if (unformat (line_input, "vni %d", &vni))
7301 errmsg ("parse error '%U'\n", format_unformat_error, line_input);
7307 errmsg ("tunnel src address not specified\n");
7311 errmsg ("tunnel dst address not specified\n");
7315 if (ipv4_set && ipv6_set) {
7316 errmsg ("both IPv4 and IPv6 addresses specified");
7320 if ((vni == 0) || (vni>>24)) {
7321 errmsg ("vni not specified or out of range\n");
7325 M (VXLAN_ADD_DEL_TUNNEL, vxlan_add_del_tunnel);
7328 clib_memcpy(&mp->dst_address, &src6, sizeof(src6));
7329 clib_memcpy(&mp->dst_address, &src6, sizeof(dst6));
7331 clib_memcpy(&mp->src_address, &src4, sizeof(src4));
7332 clib_memcpy(&mp->dst_address, &dst4, sizeof(dst4));
7334 mp->encap_vrf_id = ntohl(encap_vrf_id);
7335 mp->decap_next_index = ntohl(decap_next_index);
7336 mp->vni = ntohl(vni);
7337 mp->is_add = is_add;
7338 mp->is_ipv6 = ipv6_set;
7345 static void vl_api_vxlan_tunnel_details_t_handler
7346 (vl_api_vxlan_tunnel_details_t * mp)
7348 vat_main_t * vam = &vat_main;
7350 fformat(vam->ofp, "%11d%24U%24U%14d%18d%13d\n",
7351 ntohl(mp->sw_if_index),
7352 format_ip46_address, &(mp->src_address[0]),
7353 format_ip46_address, &(mp->dst_address[0]),
7354 ntohl(mp->encap_vrf_id),
7355 ntohl(mp->decap_next_index),
7359 static void vl_api_vxlan_tunnel_details_t_handler_json
7360 (vl_api_vxlan_tunnel_details_t * mp)
7362 vat_main_t * vam = &vat_main;
7363 vat_json_node_t *node = NULL;
7365 struct in6_addr ip6;
7367 if (VAT_JSON_ARRAY != vam->json_tree.type) {
7368 ASSERT(VAT_JSON_NONE == vam->json_tree.type);
7369 vat_json_init_array(&vam->json_tree);
7371 node = vat_json_array_add(&vam->json_tree);
7373 vat_json_init_object(node);
7374 vat_json_object_add_uint(node, "sw_if_index", ntohl(mp->sw_if_index));
7376 clib_memcpy(&ip6, &(mp->src_address[0]), sizeof(ip6));
7377 vat_json_object_add_ip6(node, "src_address", ip6);
7378 clib_memcpy(&ip6, &(mp->dst_address[0]), sizeof(ip6));
7379 vat_json_object_add_ip6(node, "dst_address", ip6);
7381 clib_memcpy(&ip4, &(mp->src_address[0]), sizeof(ip4));
7382 vat_json_object_add_ip4(node, "src_address", ip4);
7383 clib_memcpy(&ip4, &(mp->dst_address[0]), sizeof(ip4));
7384 vat_json_object_add_ip4(node, "dst_address", ip4);
7386 vat_json_object_add_uint(node, "encap_vrf_id", ntohl(mp->encap_vrf_id));
7387 vat_json_object_add_uint(node, "decap_next_index", ntohl(mp->decap_next_index));
7388 vat_json_object_add_uint(node, "vni", ntohl(mp->vni));
7389 vat_json_object_add_uint(node, "is_ipv6", mp->is_ipv6 ? 1 : 0);
7392 static int api_vxlan_tunnel_dump (vat_main_t * vam)
7394 unformat_input_t * i = vam->input;
7395 vl_api_vxlan_tunnel_dump_t *mp;
7398 u8 sw_if_index_set = 0;
7400 /* Parse args required to build the message */
7401 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
7402 if (unformat (i, "sw_if_index %d", &sw_if_index))
7403 sw_if_index_set = 1;
7408 if (sw_if_index_set == 0) {
7412 if (!vam->json_output) {
7413 fformat(vam->ofp, "%11s%24s%24s%14s%18s%13s\n",
7414 "sw_if_index", "src_address", "dst_address",
7415 "encap_vrf_id", "decap_next_index", "vni");
7418 /* Get list of vxlan-tunnel interfaces */
7419 M(VXLAN_TUNNEL_DUMP, vxlan_tunnel_dump);
7421 mp->sw_if_index = htonl(sw_if_index);
7425 /* Use a control ping for synchronization */
7427 vl_api_control_ping_t * mp;
7428 M(CONTROL_PING, control_ping);
7434 static int api_gre_add_del_tunnel (vat_main_t * vam)
7436 unformat_input_t * line_input = vam->input;
7437 vl_api_gre_add_del_tunnel_t *mp;
7439 ip4_address_t src4, dst4;
7443 u32 outer_fib_id = 0;
7445 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) {
7446 if (unformat (line_input, "del"))
7448 else if (unformat (line_input, "src %U",
7449 unformat_ip4_address, &src4))
7451 else if (unformat (line_input, "dst %U",
7452 unformat_ip4_address, &dst4))
7454 else if (unformat (line_input, "outer-fib-id %d", &outer_fib_id))
7457 errmsg ("parse error '%U'\n", format_unformat_error, line_input);
7463 errmsg ("tunnel src address not specified\n");
7467 errmsg ("tunnel dst address not specified\n");
7472 M (GRE_ADD_DEL_TUNNEL, gre_add_del_tunnel);
7474 clib_memcpy(&mp->src_address, &src4, sizeof(src4));
7475 clib_memcpy(&mp->dst_address, &dst4, sizeof(dst4));
7476 mp->outer_table_id = ntohl(outer_fib_id);
7477 mp->is_add = is_add;
7484 static void vl_api_gre_tunnel_details_t_handler
7485 (vl_api_gre_tunnel_details_t * mp)
7487 vat_main_t * vam = &vat_main;
7489 fformat(vam->ofp, "%11d%15U%15U%14d\n",
7490 ntohl(mp->sw_if_index),
7491 format_ip4_address, &mp->src_address,
7492 format_ip4_address, &mp->dst_address,
7493 ntohl(mp->outer_table_id));
7496 static void vl_api_gre_tunnel_details_t_handler_json
7497 (vl_api_gre_tunnel_details_t * mp)
7499 vat_main_t * vam = &vat_main;
7500 vat_json_node_t *node = NULL;
7503 if (VAT_JSON_ARRAY != vam->json_tree.type) {
7504 ASSERT(VAT_JSON_NONE == vam->json_tree.type);
7505 vat_json_init_array(&vam->json_tree);
7507 node = vat_json_array_add(&vam->json_tree);
7509 vat_json_init_object(node);
7510 vat_json_object_add_uint(node, "sw_if_index", ntohl(mp->sw_if_index));
7511 clib_memcpy(&ip4, &mp->src_address, sizeof(ip4));
7512 vat_json_object_add_ip4(node, "src_address", ip4);
7513 clib_memcpy(&ip4, &mp->dst_address, sizeof(ip4));
7514 vat_json_object_add_ip4(node, "dst_address", ip4);
7515 vat_json_object_add_uint(node, "outer_fib_id", ntohl(mp->outer_table_id));
7518 static int api_gre_tunnel_dump (vat_main_t * vam)
7520 unformat_input_t * i = vam->input;
7521 vl_api_gre_tunnel_dump_t *mp;
7524 u8 sw_if_index_set = 0;
7526 /* Parse args required to build the message */
7527 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
7528 if (unformat (i, "sw_if_index %d", &sw_if_index))
7529 sw_if_index_set = 1;
7534 if (sw_if_index_set == 0) {
7538 if (!vam->json_output) {
7539 fformat(vam->ofp, "%11s%15s%15s%14s\n",
7540 "sw_if_index", "src_address", "dst_address",
7544 /* Get list of gre-tunnel interfaces */
7545 M(GRE_TUNNEL_DUMP, gre_tunnel_dump);
7547 mp->sw_if_index = htonl(sw_if_index);
7551 /* Use a control ping for synchronization */
7553 vl_api_control_ping_t * mp;
7554 M(CONTROL_PING, control_ping);
7560 static int api_l2_fib_clear_table (vat_main_t * vam)
7562 // unformat_input_t * i = vam->input;
7563 vl_api_l2_fib_clear_table_t *mp;
7566 M(L2_FIB_CLEAR_TABLE, l2_fib_clear_table);
7573 static int api_l2_interface_efp_filter (vat_main_t * vam)
7575 unformat_input_t * i = vam->input;
7576 vl_api_l2_interface_efp_filter_t *mp;
7580 u8 sw_if_index_set = 0;
7582 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
7583 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
7584 sw_if_index_set = 1;
7585 else if (unformat (i, "sw_if_index %d", &sw_if_index))
7586 sw_if_index_set = 1;
7587 else if (unformat (i, "enable"))
7589 else if (unformat (i, "disable"))
7592 clib_warning ("parse error '%U'", format_unformat_error, i);
7597 if (sw_if_index_set == 0) {
7598 errmsg ("missing sw_if_index\n");
7602 M(L2_INTERFACE_EFP_FILTER, l2_interface_efp_filter);
7604 mp->sw_if_index = ntohl(sw_if_index);
7605 mp->enable_disable = enable;
7612 #define foreach_vtr_op \
7613 _("disable", L2_VTR_DISABLED) \
7614 _("push-1", L2_VTR_PUSH_1) \
7615 _("push-2", L2_VTR_PUSH_2) \
7616 _("pop-1", L2_VTR_POP_1) \
7617 _("pop-2", L2_VTR_POP_2) \
7618 _("translate-1-1", L2_VTR_TRANSLATE_1_1) \
7619 _("translate-1-2", L2_VTR_TRANSLATE_1_2) \
7620 _("translate-2-1", L2_VTR_TRANSLATE_2_1) \
7621 _("translate-2-2", L2_VTR_TRANSLATE_2_2)
7623 static int api_l2_interface_vlan_tag_rewrite (vat_main_t * vam)
7625 unformat_input_t * i = vam->input;
7626 vl_api_l2_interface_vlan_tag_rewrite_t *mp;
7629 u8 sw_if_index_set = 0;
7636 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
7637 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
7638 sw_if_index_set = 1;
7639 else if (unformat (i, "sw_if_index %d", &sw_if_index))
7640 sw_if_index_set = 1;
7641 else if (unformat (i, "vtr_op %d", &vtr_op))
7643 #define _(n,v) else if (unformat(i, n)) {vtr_op = v; vtr_op_set = 1;}
7647 else if (unformat (i, "push_dot1q %d", &push_dot1q))
7649 else if (unformat (i, "tag1 %d", &tag1))
7651 else if (unformat (i, "tag2 %d", &tag2))
7654 clib_warning ("parse error '%U'", format_unformat_error, i);
7659 if ((sw_if_index_set == 0)||(vtr_op_set == 0)) {
7660 errmsg ("missing vtr operation or sw_if_index\n");
7664 M(L2_INTERFACE_VLAN_TAG_REWRITE, l2_interface_vlan_tag_rewrite)
7666 mp->sw_if_index = ntohl(sw_if_index);
7667 mp->vtr_op = ntohl(vtr_op);
7668 mp->push_dot1q = ntohl(push_dot1q);
7669 mp->tag1 = ntohl(tag1);
7670 mp->tag2 = ntohl(tag2);
7677 static int api_create_vhost_user_if (vat_main_t * vam)
7679 unformat_input_t * i = vam->input;
7680 vl_api_create_vhost_user_if_t *mp;
7684 u8 file_name_set = 0;
7685 u32 custom_dev_instance = ~0;
7687 u8 use_custom_mac = 0;
7689 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
7690 if (unformat (i, "socket %s", &file_name)) {
7693 else if (unformat (i, "renumber %"PRIu32, &custom_dev_instance))
7695 else if (unformat (i, "mac %U", unformat_ethernet_address, hwaddr))
7697 else if (unformat (i, "server"))
7703 if (file_name_set == 0) {
7704 errmsg ("missing socket file name\n");
7708 if (vec_len (file_name) > 255) {
7709 errmsg ("socket file name too long\n");
7712 vec_add1 (file_name, 0);
7714 M(CREATE_VHOST_USER_IF, create_vhost_user_if);
7716 mp->is_server = is_server;
7717 clib_memcpy(mp->sock_filename, file_name, vec_len(file_name));
7718 vec_free(file_name);
7719 if (custom_dev_instance != ~0) {
7721 mp->custom_dev_instance = ntohl(custom_dev_instance);
7723 mp->use_custom_mac = use_custom_mac;
7724 clib_memcpy(mp->mac_address, hwaddr, 6);
7731 static int api_modify_vhost_user_if (vat_main_t * vam)
7733 unformat_input_t * i = vam->input;
7734 vl_api_modify_vhost_user_if_t *mp;
7738 u8 file_name_set = 0;
7739 u32 custom_dev_instance = ~0;
7740 u8 sw_if_index_set = 0;
7741 u32 sw_if_index = (u32)~0;
7743 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
7744 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
7745 sw_if_index_set = 1;
7746 else if (unformat (i, "sw_if_index %d", &sw_if_index))
7747 sw_if_index_set = 1;
7748 else if (unformat (i, "socket %s", &file_name)) {
7751 else if (unformat (i, "renumber %"PRIu32, &custom_dev_instance))
7753 else if (unformat (i, "server"))
7759 if (sw_if_index_set == 0) {
7760 errmsg ("missing sw_if_index or interface name\n");
7764 if (file_name_set == 0) {
7765 errmsg ("missing socket file name\n");
7769 if (vec_len (file_name) > 255) {
7770 errmsg ("socket file name too long\n");
7773 vec_add1 (file_name, 0);
7775 M(MODIFY_VHOST_USER_IF, modify_vhost_user_if);
7777 mp->sw_if_index = ntohl(sw_if_index);
7778 mp->is_server = is_server;
7779 clib_memcpy(mp->sock_filename, file_name, vec_len(file_name));
7780 vec_free(file_name);
7781 if (custom_dev_instance != ~0) {
7783 mp->custom_dev_instance = ntohl(custom_dev_instance);
7791 static int api_delete_vhost_user_if (vat_main_t * vam)
7793 unformat_input_t * i = vam->input;
7794 vl_api_delete_vhost_user_if_t *mp;
7796 u32 sw_if_index = ~0;
7797 u8 sw_if_index_set = 0;
7799 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
7800 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
7801 sw_if_index_set = 1;
7802 else if (unformat (i, "sw_if_index %d", &sw_if_index))
7803 sw_if_index_set = 1;
7808 if (sw_if_index_set == 0) {
7809 errmsg ("missing sw_if_index or interface name\n");
7814 M(DELETE_VHOST_USER_IF, delete_vhost_user_if);
7816 mp->sw_if_index = ntohl(sw_if_index);
7823 static void vl_api_sw_interface_vhost_user_details_t_handler
7824 (vl_api_sw_interface_vhost_user_details_t * mp)
7826 vat_main_t * vam = &vat_main;
7828 fformat(vam->ofp, "%-25s %3" PRIu32 " %6" PRIu32 " %8x %6d %7d %s\n",
7829 (char *)mp->interface_name,
7830 ntohl(mp->sw_if_index), ntohl(mp->virtio_net_hdr_sz),
7831 clib_net_to_host_u64(mp->features), mp->is_server,
7832 ntohl(mp->num_regions), (char *)mp->sock_filename);
7833 fformat(vam->ofp, " Status: '%s'\n", strerror(ntohl(mp->sock_errno)));
7836 static void vl_api_sw_interface_vhost_user_details_t_handler_json
7837 (vl_api_sw_interface_vhost_user_details_t * mp)
7839 vat_main_t * vam = &vat_main;
7840 vat_json_node_t *node = NULL;
7842 if (VAT_JSON_ARRAY != vam->json_tree.type) {
7843 ASSERT(VAT_JSON_NONE == vam->json_tree.type);
7844 vat_json_init_array(&vam->json_tree);
7846 node = vat_json_array_add(&vam->json_tree);
7848 vat_json_init_object(node);
7849 vat_json_object_add_uint(node, "sw_if_index", ntohl(mp->sw_if_index));
7850 vat_json_object_add_string_copy(node, "interface_name", mp->interface_name);
7851 vat_json_object_add_uint(node, "virtio_net_hdr_sz", ntohl(mp->virtio_net_hdr_sz));
7852 vat_json_object_add_uint(node, "features", clib_net_to_host_u64(mp->features));
7853 vat_json_object_add_uint(node, "is_server", mp->is_server);
7854 vat_json_object_add_string_copy(node, "sock_filename", mp->sock_filename);
7855 vat_json_object_add_uint(node, "num_regions", ntohl(mp->num_regions));
7856 vat_json_object_add_uint(node, "sock_errno", ntohl(mp->sock_errno));
7859 static int api_sw_interface_vhost_user_dump (vat_main_t * vam)
7861 vl_api_sw_interface_vhost_user_dump_t *mp;
7863 fformat(vam->ofp, "Interface name idx hdr_sz features server regions filename\n");
7865 /* Get list of vhost-user interfaces */
7866 M(SW_INTERFACE_VHOST_USER_DUMP, sw_interface_vhost_user_dump);
7869 /* Use a control ping for synchronization */
7871 vl_api_control_ping_t * mp;
7872 M(CONTROL_PING, control_ping);
7878 static int api_show_version (vat_main_t * vam)
7880 vl_api_show_version_t *mp;
7883 M(SHOW_VERSION, show_version);
7890 static uword unformat_nsh_gre_decap_next
7891 (unformat_input_t * input, va_list * args)
7893 u32 * result = va_arg (*args, u32 *);
7896 if (unformat (input, "drop"))
7897 *result = NSH_GRE_INPUT_NEXT_DROP;
7898 else if (unformat (input, "ip4"))
7899 *result = NSH_GRE_INPUT_NEXT_IP4_INPUT;
7900 else if (unformat (input, "ip6"))
7901 *result = NSH_GRE_INPUT_NEXT_IP6_INPUT;
7902 else if (unformat (input, "ethernet"))
7903 *result = NSH_GRE_INPUT_NEXT_ETHERNET_INPUT;
7904 else if (unformat (input, "%d", &tmp))
7911 static int api_nsh_gre_add_del_tunnel (vat_main_t * vam)
7913 unformat_input_t * line_input = vam->input;
7914 vl_api_nsh_gre_add_del_tunnel_t *mp;
7916 ip4_address_t src, dst;
7920 u32 encap_vrf_id = 0;
7921 u32 decap_vrf_id = 0;
7924 u8 next_protocol = 1; /* ip4 */
7935 u32 decap_next_index = NSH_GRE_INPUT_NEXT_IP4_INPUT;
7939 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) {
7940 if (unformat (line_input, "del"))
7942 else if (unformat (line_input, "src %U",
7943 unformat_ip4_address, &src))
7945 else if (unformat (line_input, "dst %U",
7946 unformat_ip4_address, &dst))
7948 else if (unformat (line_input, "encap-vrf-id %d", &encap_vrf_id))
7950 else if (unformat (line_input, "decap-vrf-id %d", &decap_vrf_id))
7952 else if (unformat (line_input, "decap-next %U",
7953 unformat_nsh_gre_decap_next, &decap_next_index))
7955 else if (unformat (line_input, "version %d", &tmp))
7956 ver_o_c |= (tmp & 3) << 6;
7957 else if (unformat (line_input, "o-bit %d", &tmp))
7958 ver_o_c |= (tmp & 1) << 5;
7959 else if (unformat (line_input, "c-bit %d", &tmp))
7960 ver_o_c |= (tmp & 1) << 4;
7961 else if (unformat (line_input, "md-type %d", &tmp))
7963 else if (unformat(line_input, "next-ip4"))
7965 else if (unformat(line_input, "next-ip6"))
7967 else if (unformat(line_input, "next-ethernet"))
7969 else if (unformat (line_input, "c1 %d", &c1))
7971 else if (unformat (line_input, "c2 %d", &c2))
7973 else if (unformat (line_input, "c3 %d", &c3))
7975 else if (unformat (line_input, "c4 %d", &c4))
7977 else if (unformat (line_input, "spi %d", &spi))
7979 else if (unformat (line_input, "si %d", &si))
7981 else if (unformat (line_input, "tlv %x"))
7982 vec_add1 (tlvs, tmp);
7984 errmsg ("parse error '%U'\n", format_unformat_error, line_input);
7990 errmsg ("tunnel src address not specified\n");
7994 errmsg ("tunnel dst address not specified\n");
7999 errmsg ("spi not specified\n");
8004 errmsg ("si not specified\n");
8008 M2 (NSH_GRE_ADD_DEL_TUNNEL, nsh_gre_add_del_tunnel,
8009 sizeof(u32) * vec_len (tlvs));
8011 spi_si = (spi<<8) | si;
8013 mp->src = src.as_u32;
8014 mp->dst = dst.as_u32;
8015 mp->encap_vrf_id = ntohl(encap_vrf_id);
8016 mp->decap_vrf_id = ntohl(decap_vrf_id);
8017 mp->decap_next_index = ntohl(decap_next_index);
8018 mp->tlv_len_in_words = vec_len (tlvs);
8019 mp->is_add = is_add;
8020 mp->ver_o_c = ver_o_c;
8021 mp->length = 6 + vec_len(tlvs);
8022 mp->md_type = md_type;
8023 mp->next_protocol = next_protocol;
8024 mp->spi_si = ntohl(spi_si);
8030 for (i = 0; i < vec_len(tlvs); i++)
8031 mp->tlvs[i] = ntohl(tlvs[i]);
8040 static uword unformat_nsh_vxlan_gpe_decap_next
8041 (unformat_input_t * input, va_list * args)
8043 u32 * result = va_arg (*args, u32 *);
8046 if (unformat (input, "drop"))
8047 *result = NSH_VXLAN_GPE_INPUT_NEXT_DROP;
8048 else if (unformat (input, "ip4"))
8049 *result = NSH_VXLAN_GPE_INPUT_NEXT_IP4_INPUT;
8050 else if (unformat (input, "ip6"))
8051 *result = NSH_VXLAN_GPE_INPUT_NEXT_IP6_INPUT;
8052 else if (unformat (input, "ethernet"))
8053 *result = NSH_VXLAN_GPE_INPUT_NEXT_ETHERNET_INPUT;
8054 else if (unformat (input, "nsh-vxlan-gpe"))
8055 *result = NSH_VXLAN_GPE_INPUT_NEXT_ETHERNET_INPUT;
8056 else if (unformat (input, "%d", &tmp))
8063 static int api_nsh_vxlan_gpe_add_del_tunnel (vat_main_t * vam)
8065 unformat_input_t * line_input = vam->input;
8066 vl_api_nsh_vxlan_gpe_add_del_tunnel_t *mp;
8068 ip4_address_t src, dst;
8072 u32 encap_vrf_id = 0;
8073 u32 decap_vrf_id = 0;
8076 u8 next_protocol = 1; /* ip4 */
8087 u32 decap_next_index = NSH_GRE_INPUT_NEXT_IP4_INPUT;
8093 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) {
8094 if (unformat (line_input, "del"))
8096 else if (unformat (line_input, "src %U",
8097 unformat_ip4_address, &src))
8099 else if (unformat (line_input, "dst %U",
8100 unformat_ip4_address, &dst))
8102 else if (unformat (line_input, "encap-vrf-id %d", &encap_vrf_id))
8104 else if (unformat (line_input, "decap-vrf-id %d", &decap_vrf_id))
8106 else if (unformat (line_input, "decap-next %U",
8107 unformat_nsh_vxlan_gpe_decap_next,
8110 else if (unformat (line_input, "vni %d", &vni))
8112 else if (unformat (line_input, "version %d", &tmp))
8113 ver_o_c |= (tmp & 3) << 6;
8114 else if (unformat (line_input, "o-bit %d", &tmp))
8115 ver_o_c |= (tmp & 1) << 5;
8116 else if (unformat (line_input, "c-bit %d", &tmp))
8117 ver_o_c |= (tmp & 1) << 4;
8118 else if (unformat (line_input, "md-type %d", &tmp))
8120 else if (unformat(line_input, "next-ip4"))
8122 else if (unformat(line_input, "next-ip6"))
8124 else if (unformat(line_input, "next-ethernet"))
8126 else if (unformat (line_input, "c1 %d", &c1))
8128 else if (unformat (line_input, "c2 %d", &c2))
8130 else if (unformat (line_input, "c3 %d", &c3))
8132 else if (unformat (line_input, "c4 %d", &c4))
8134 else if (unformat (line_input, "spi %d", &spi))
8136 else if (unformat (line_input, "si %d", &si))
8138 else if (unformat (line_input, "tlv %x"))
8139 vec_add1 (tlvs, tmp);
8141 errmsg ("parse error '%U'\n", format_unformat_error, line_input);
8147 errmsg ("tunnel src address not specified\n");
8151 errmsg ("tunnel dst address not specified\n");
8156 errmsg ("spi not specified\n");
8161 errmsg ("si not specified\n");
8165 errmsg ("vni not specified\n");
8169 M2 (NSH_VXLAN_GPE_ADD_DEL_TUNNEL, nsh_vxlan_gpe_add_del_tunnel,
8170 sizeof(u32) * vec_len (tlvs));
8172 spi_si = (spi<<8) | si;
8174 mp->src = src.as_u32;
8175 mp->dst = dst.as_u32;
8176 mp->encap_vrf_id = ntohl(encap_vrf_id);
8177 mp->decap_vrf_id = ntohl(decap_vrf_id);
8178 mp->decap_next_index = ntohl(decap_next_index);
8179 mp->tlv_len_in_words = vec_len (tlvs);
8180 mp->vni = ntohl(vni);
8181 mp->is_add = is_add;
8182 mp->ver_o_c = ver_o_c;
8183 mp->length = 6 + vec_len(tlvs);
8184 mp->md_type = md_type;
8185 mp->next_protocol = next_protocol;
8186 mp->spi_si = ntohl(spi_si);
8192 for (i = 0; i < vec_len(tlvs); i++)
8193 mp->tlvs[i] = ntohl(tlvs[i]);
8202 static uword unformat_lisp_gpe_decap_next (unformat_input_t * input,
8205 u32 * result = va_arg (*args, u32 *);
8208 if (unformat (input, "drop"))
8209 *result = LISP_GPE_INPUT_NEXT_DROP;
8210 else if (unformat (input, "ip4"))
8211 *result = LISP_GPE_INPUT_NEXT_IP4_INPUT;
8212 else if (unformat (input, "ip6"))
8213 *result = LISP_GPE_INPUT_NEXT_IP6_INPUT;
8214 else if (unformat (input, "ethernet"))
8215 *result = LISP_GPE_INPUT_NEXT_IP6_INPUT;
8216 else if (unformat (input, "%d", &tmp))
8224 api_lisp_gpe_add_del_tunnel (vat_main_t * vam)
8226 unformat_input_t * line_input = vam->input;
8227 vl_api_lisp_gpe_add_del_tunnel_t *mp;
8229 ip4_address_t src, dst;
8233 u32 encap_vrf_id = 0;
8234 u32 decap_vrf_id = 0;
8235 u8 next_protocol = LISP_GPE_NEXT_PROTOCOL_IP4;
8236 u32 decap_next_index = LISP_GPE_INPUT_NEXT_IP4_INPUT;
8237 u8 flags = LISP_GPE_FLAGS_P;
8244 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) {
8245 if (unformat (line_input, "del"))
8247 else if (unformat (line_input, "src %U",
8248 unformat_ip4_address, &src))
8250 else if (unformat (line_input, "dst %U",
8251 unformat_ip4_address, &dst))
8253 else if (unformat (line_input, "encap-vrf-id %d", &encap_vrf_id))
8255 else if (unformat (line_input, "decap-vrf-id %d", &decap_vrf_id))
8257 else if (unformat (line_input, "decap-next %U",
8258 unformat_lisp_gpe_decap_next,
8261 else if (unformat(line_input, "next-ip4"))
8263 else if (unformat(line_input, "next-ip6"))
8265 else if (unformat(line_input, "next-ethernet"))
8267 else if (unformat(line_input, "next-nsh"))
8269 /* Allow the user to specify anything they want in the LISP hdr */
8270 else if (unformat (line_input, "ver_res %x", &tmp))
8272 else if (unformat (line_input, "res %x", &tmp))
8274 else if (unformat (line_input, "flags %x", &tmp))
8276 else if (unformat (line_input, "n-bit"))
8277 flags |= LISP_GPE_FLAGS_N;
8278 else if (unformat (line_input, "l-bit"))
8279 flags |= LISP_GPE_FLAGS_L;
8280 else if (unformat (line_input, "e-bit"))
8281 flags |= LISP_GPE_FLAGS_E;
8282 else if (unformat (line_input, "v-bit"))
8283 flags |= LISP_GPE_FLAGS_V;
8284 else if (unformat (line_input, "i-bit"))
8285 flags |= LISP_GPE_FLAGS_V;
8286 else if (unformat (line_input, "not-p-bit"))
8287 flags &= !LISP_GPE_FLAGS_P;
8288 else if (unformat (line_input, "p-bit"))
8289 flags |= LISP_GPE_FLAGS_P;
8290 else if (unformat (line_input, "o-bit"))
8291 flags |= LISP_GPE_FLAGS_O;
8292 else if (unformat (line_input, "iidx %x", &iid))
8294 else if (unformat (line_input, "iid %d", &iid))
8297 errmsg ("parse error '%U'\n", format_unformat_error, line_input);
8303 errmsg ("tunnel src address not specified\n");
8307 errmsg ("tunnel dst address not specified\n");
8311 errmsg ("iid not specified\n");
8315 M(LISP_GPE_ADD_DEL_TUNNEL, lisp_gpe_add_del_tunnel);
8317 mp->src = src.as_u32;
8318 mp->dst = dst.as_u32;
8319 mp->encap_vrf_id = ntohl(encap_vrf_id);
8320 mp->decap_vrf_id = ntohl(decap_vrf_id);
8321 mp->decap_next_index = ntohl(decap_next_index);
8322 mp->is_add = is_add;
8324 mp->ver_res = ver_res;
8326 mp->next_protocol = next_protocol;
8327 mp->iid = ntohl(iid);
8336 u8 * format_l2_fib_mac_address (u8 * s, va_list * args)
8338 u8 * a = va_arg (*args, u8 *);
8340 return format (s, "%02x:%02x:%02x:%02x:%02x:%02x",
8341 a[2], a[3], a[4], a[5], a[6], a[7]);
8344 static void vl_api_l2_fib_table_entry_t_handler
8345 (vl_api_l2_fib_table_entry_t * mp)
8347 vat_main_t * vam = &vat_main;
8349 fformat(vam->ofp, "%3" PRIu32 " %U %3" PRIu32
8351 ntohl(mp->bd_id), format_l2_fib_mac_address, &mp->mac,
8352 ntohl(mp->sw_if_index), mp->static_mac, mp->filter_mac,
8356 static void vl_api_l2_fib_table_entry_t_handler_json
8357 (vl_api_l2_fib_table_entry_t * mp)
8359 vat_main_t * vam = &vat_main;
8360 vat_json_node_t *node = NULL;
8362 if (VAT_JSON_ARRAY != vam->json_tree.type) {
8363 ASSERT(VAT_JSON_NONE == vam->json_tree.type);
8364 vat_json_init_array(&vam->json_tree);
8366 node = vat_json_array_add(&vam->json_tree);
8368 vat_json_init_object(node);
8369 vat_json_object_add_uint(node, "bd_id", ntohl(mp->bd_id));
8370 vat_json_object_add_uint(node, "mac", clib_net_to_host_u64(mp->mac));
8371 vat_json_object_add_uint(node, "sw_if_index", ntohl(mp->sw_if_index));
8372 vat_json_object_add_uint(node, "static_mac", mp->static_mac);
8373 vat_json_object_add_uint(node, "filter_mac", mp->filter_mac);
8374 vat_json_object_add_uint(node, "bvi_mac", mp->bvi_mac);
8377 static int api_l2_fib_table_dump (vat_main_t * vam)
8379 unformat_input_t * i = vam->input;
8380 vl_api_l2_fib_table_dump_t *mp;
8385 /* Parse args required to build the message */
8386 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
8387 if (unformat (i, "bd_id %d", &bd_id))
8393 if (bd_id_set == 0) {
8394 errmsg ("missing bridge domain\n");
8398 fformat(vam->ofp, "BD-ID Mac Address sw-ndx Static Filter BVI\n");
8400 /* Get list of l2 fib entries */
8401 M(L2_FIB_TABLE_DUMP, l2_fib_table_dump);
8403 mp->bd_id = ntohl(bd_id);
8406 /* Use a control ping for synchronization */
8408 vl_api_control_ping_t * mp;
8409 M(CONTROL_PING, control_ping);
8417 api_interface_name_renumber (vat_main_t * vam)
8419 unformat_input_t * line_input = vam->input;
8420 vl_api_interface_name_renumber_t *mp;
8421 u32 sw_if_index = ~0;
8423 u32 new_show_dev_instance = ~0;
8425 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) {
8426 if (unformat (line_input, "%U", unformat_sw_if_index, vam,
8429 else if (unformat (line_input, "sw_if_index %d", &sw_if_index))
8431 else if (unformat (line_input, "new_show_dev_instance %d",
8432 &new_show_dev_instance))
8438 if (sw_if_index == ~0) {
8439 errmsg ("missing interface name or sw_if_index\n");
8443 if (new_show_dev_instance == ~0) {
8444 errmsg ("missing new_show_dev_instance\n");
8448 M(INTERFACE_NAME_RENUMBER, interface_name_renumber);
8450 mp->sw_if_index = ntohl (sw_if_index);
8451 mp->new_show_dev_instance = ntohl (new_show_dev_instance);
8457 api_want_ip4_arp_events (vat_main_t * vam)
8459 unformat_input_t * line_input = vam->input;
8460 vl_api_want_ip4_arp_events_t * mp;
8462 ip4_address_t address;
8463 int address_set = 0;
8464 u32 enable_disable = 1;
8466 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) {
8467 if (unformat (line_input, "address %U",
8468 unformat_ip4_address, &address))
8470 else if (unformat (line_input, "del"))
8476 if (address_set == 0) {
8477 errmsg ("missing addresses\n");
8481 M(WANT_IP4_ARP_EVENTS, want_ip4_arp_events);
8482 mp->enable_disable = enable_disable;
8484 mp->address = address.as_u32;
8489 static int api_input_acl_set_interface (vat_main_t * vam)
8491 unformat_input_t * i = vam->input;
8492 vl_api_input_acl_set_interface_t *mp;
8495 int sw_if_index_set;
8496 u32 ip4_table_index = ~0;
8497 u32 ip6_table_index = ~0;
8498 u32 l2_table_index = ~0;
8501 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
8502 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
8503 sw_if_index_set = 1;
8504 else if (unformat (i, "sw_if_index %d", &sw_if_index))
8505 sw_if_index_set = 1;
8506 else if (unformat (i, "del"))
8508 else if (unformat (i, "ip4-table %d", &ip4_table_index))
8510 else if (unformat (i, "ip6-table %d", &ip6_table_index))
8512 else if (unformat (i, "l2-table %d", &l2_table_index))
8515 clib_warning ("parse error '%U'", format_unformat_error, i);
8520 if (sw_if_index_set == 0) {
8521 errmsg ("missing interface name or sw_if_index\n");
8525 M(INPUT_ACL_SET_INTERFACE, input_acl_set_interface);
8527 mp->sw_if_index = ntohl(sw_if_index);
8528 mp->ip4_table_index = ntohl(ip4_table_index);
8529 mp->ip6_table_index = ntohl(ip6_table_index);
8530 mp->l2_table_index = ntohl(l2_table_index);
8531 mp->is_add = is_add;
8539 api_ip_address_dump (vat_main_t * vam)
8541 unformat_input_t * i = vam->input;
8542 vl_api_ip_address_dump_t * mp;
8543 u32 sw_if_index = ~0;
8544 u8 sw_if_index_set = 0;
8549 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
8550 if (unformat (i, "sw_if_index %d", &sw_if_index))
8551 sw_if_index_set = 1;
8552 else if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
8553 sw_if_index_set = 1;
8554 else if (unformat (i, "ipv4"))
8556 else if (unformat (i, "ipv6"))
8562 if (ipv4_set && ipv6_set) {
8563 errmsg ("ipv4 and ipv6 flags cannot be both set\n");
8567 if ((!ipv4_set) && (!ipv6_set)) {
8568 errmsg ("no ipv4 nor ipv6 flag set\n");
8572 if (sw_if_index_set == 0) {
8573 errmsg ("missing interface name or sw_if_index\n");
8577 vam->current_sw_if_index = sw_if_index;
8578 vam->is_ipv6 = ipv6_set;
8580 M(IP_ADDRESS_DUMP, ip_address_dump);
8581 mp->sw_if_index = ntohl(sw_if_index);
8582 mp->is_ipv6 = ipv6_set;
8585 /* Use a control ping for synchronization */
8587 vl_api_control_ping_t * mp;
8588 M(CONTROL_PING, control_ping);
8595 api_ip_dump (vat_main_t * vam)
8597 vl_api_ip_dump_t * mp;
8598 unformat_input_t * in = vam->input;
8605 while (unformat_check_input (in) != UNFORMAT_END_OF_INPUT) {
8606 if (unformat (in, "ipv4"))
8608 else if (unformat (in, "ipv6"))
8614 if (ipv4_set && ipv6_set) {
8615 errmsg ("ipv4 and ipv6 flags cannot be both set\n");
8619 if ((!ipv4_set) && (!ipv6_set)) {
8620 errmsg ("no ipv4 nor ipv6 flag set\n");
8625 vam->is_ipv6 = is_ipv6;
8628 for (i = 0; i < vec_len(vam->ip_details_by_sw_if_index[is_ipv6]); i++) {
8629 vec_free(vam->ip_details_by_sw_if_index[is_ipv6][i].addr);
8631 vec_free(vam->ip_details_by_sw_if_index[is_ipv6]);
8633 M(IP_DUMP, ip_dump);
8634 mp->is_ipv6 = ipv6_set;
8637 /* Use a control ping for synchronization */
8639 vl_api_control_ping_t * mp;
8640 M(CONTROL_PING, control_ping);
8647 api_ipsec_spd_add_del (vat_main_t * vam)
8650 unformat_input_t * i = vam->input;
8651 vl_api_ipsec_spd_add_del_t *mp;
8656 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
8657 if (unformat (i, "spd_id %d", &spd_id))
8659 else if (unformat (i, "del"))
8662 clib_warning ("parse error '%U'", format_unformat_error, i);
8667 errmsg ("spd_id must be set\n");
8671 M(IPSEC_SPD_ADD_DEL, ipsec_spd_add_del);
8673 mp->spd_id = ntohl(spd_id);
8674 mp->is_add = is_add;
8680 clib_warning ("unsupported (no dpdk)");
8686 api_ipsec_interface_add_del_spd (vat_main_t * vam)
8689 unformat_input_t * i = vam->input;
8690 vl_api_ipsec_interface_add_del_spd_t *mp;
8693 u8 sw_if_index_set = 0;
8694 u32 spd_id = (u32) ~0;
8697 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
8698 if (unformat (i, "del"))
8700 else if (unformat (i, "spd_id %d", &spd_id))
8702 else if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
8703 sw_if_index_set = 1;
8704 else if (unformat (i, "sw_if_index %d", &sw_if_index))
8705 sw_if_index_set = 1;
8707 clib_warning ("parse error '%U'", format_unformat_error, i);
8713 if (spd_id == (u32) ~0) {
8714 errmsg ("spd_id must be set\n");
8718 if (sw_if_index_set == 0) {
8719 errmsg ("missing interface name or sw_if_index\n");
8723 M(IPSEC_INTERFACE_ADD_DEL_SPD, ipsec_interface_add_del_spd);
8725 mp->spd_id = ntohl(spd_id);
8726 mp->sw_if_index = ntohl (sw_if_index);
8727 mp->is_add = is_add;
8733 clib_warning ("unsupported (no dpdk)");
8739 api_ipsec_spd_add_del_entry (vat_main_t * vam)
8742 unformat_input_t * i = vam->input;
8743 vl_api_ipsec_spd_add_del_entry_t *mp;
8745 u8 is_add = 1, is_outbound = 0, is_ipv6 = 0, is_ip_any = 1;
8746 u32 spd_id, sa_id, protocol = 0, policy = 0;
8748 u32 rport_start = 0, rport_stop = (u32) ~0;
8749 u32 lport_start = 0, lport_stop = (u32) ~0;
8750 ip4_address_t laddr4_start, laddr4_stop, raddr4_start, raddr4_stop;
8751 ip6_address_t laddr6_start, laddr6_stop, raddr6_start, raddr6_stop;
8753 laddr4_start.as_u32 = raddr4_start.as_u32 = 0;
8754 laddr4_stop.as_u32 = raddr4_stop.as_u32 = (u32) ~0;
8755 laddr6_start.as_u64[0] = raddr6_start.as_u64[0] = 0;
8756 laddr6_start.as_u64[1] = raddr6_start.as_u64[1] = 0;
8757 laddr6_stop.as_u64[0] = raddr6_stop.as_u64[0] = (u64) ~0;
8758 laddr6_stop.as_u64[1] = raddr6_stop.as_u64[1] = (u64) ~0;
8760 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
8761 if (unformat (i, "del"))
8763 if (unformat (i, "outbound"))
8765 if (unformat (i, "inbound"))
8767 else if (unformat (i, "spd_id %d", &spd_id))
8769 else if (unformat (i, "sa_id %d", &sa_id))
8771 else if (unformat (i, "priority %d", &priority))
8773 else if (unformat (i, "protocol %d", &protocol))
8775 else if (unformat (i, "lport_start %d", &lport_start))
8777 else if (unformat (i, "lport_stop %d", &lport_stop))
8779 else if (unformat (i, "rport_start %d", &rport_start))
8781 else if (unformat (i, "rport_stop %d", &rport_stop))
8783 else if (unformat (i, "laddr_start %U", unformat_ip4_address, &laddr4_start))
8788 else if (unformat (i, "laddr_stop %U", unformat_ip4_address, &laddr4_stop))
8793 else if (unformat (i, "raddr_start %U", unformat_ip4_address, &raddr4_start))
8798 else if (unformat (i, "raddr_stop %U", unformat_ip4_address, &raddr4_stop))
8803 else if (unformat (i, "laddr_start %U", unformat_ip6_address, &laddr6_start))
8808 else if (unformat (i, "laddr_stop %U", unformat_ip6_address, &laddr6_stop))
8813 else if (unformat (i, "raddr_start %U", unformat_ip6_address, &raddr6_start))
8818 else if (unformat (i, "raddr_stop %U", unformat_ip6_address, &raddr6_stop))
8823 else if (unformat (i, "action %U", unformat_ipsec_policy_action, &policy))
8825 if (policy == IPSEC_POLICY_ACTION_RESOLVE) {
8826 clib_warning ("unsupported action: 'resolve'");
8831 clib_warning ("parse error '%U'", format_unformat_error, i);
8837 M(IPSEC_SPD_ADD_DEL_ENTRY, ipsec_spd_add_del_entry);
8839 mp->spd_id = ntohl(spd_id);
8840 mp->priority = ntohl(priority);
8841 mp->is_outbound = is_outbound;
8843 mp->is_ipv6 = is_ipv6;
8844 if (is_ipv6 || is_ip_any) {
8845 clib_memcpy (mp->remote_address_start, &raddr6_start, sizeof(ip6_address_t));
8846 clib_memcpy (mp->remote_address_stop, &raddr6_stop, sizeof(ip6_address_t));
8847 clib_memcpy (mp->local_address_start, &laddr6_start, sizeof(ip6_address_t));
8848 clib_memcpy (mp->local_address_stop, &laddr6_stop, sizeof(ip6_address_t));
8850 clib_memcpy (mp->remote_address_start, &raddr4_start, sizeof(ip4_address_t));
8851 clib_memcpy (mp->remote_address_stop, &raddr4_stop, sizeof(ip4_address_t));
8852 clib_memcpy (mp->local_address_start, &laddr4_start, sizeof(ip4_address_t));
8853 clib_memcpy (mp->local_address_stop, &laddr4_stop, sizeof(ip4_address_t));
8855 mp->protocol = (u8) protocol;
8856 mp->local_port_start = ntohs((u16) lport_start);
8857 mp->local_port_stop = ntohs((u16) lport_stop);
8858 mp->remote_port_start = ntohs((u16) rport_start);
8859 mp->remote_port_stop = ntohs((u16) rport_stop);
8860 mp->policy = (u8) policy;
8861 mp->sa_id = ntohl(sa_id);
8862 mp->is_add = is_add;
8863 mp->is_ip_any = is_ip_any;
8868 clib_warning ("unsupported (no dpdk)");
8874 api_ipsec_sad_add_del_entry (vat_main_t * vam)
8877 unformat_input_t * i = vam->input;
8878 vl_api_ipsec_sad_add_del_entry_t *mp;
8884 u8 protocol = IPSEC_PROTOCOL_AH;
8885 u8 is_tunnel = 0, is_tunnel_ipv6 = 0;
8886 u32 crypto_alg = 0, integ_alg = 0;
8887 ip4_address_t tun_src4;
8888 ip4_address_t tun_dst4;
8889 ip6_address_t tun_src6;
8890 ip6_address_t tun_dst6;
8892 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
8893 if (unformat (i, "del"))
8895 else if (unformat (i, "sad_id %d", &sad_id))
8897 else if (unformat (i, "spi %d", &spi))
8899 else if (unformat (i, "esp"))
8900 protocol = IPSEC_PROTOCOL_ESP;
8901 else if (unformat (i, "tunnel_src %U", unformat_ip4_address, &tun_src4)) {
8905 else if (unformat (i, "tunnel_dst %U", unformat_ip4_address, &tun_dst4)) {
8909 else if (unformat (i, "tunnel_src %U", unformat_ip6_address, &tun_src6)) {
8913 else if (unformat (i, "tunnel_dst %U", unformat_ip6_address, &tun_dst6)) {
8917 else if (unformat (i, "crypto_alg %U", unformat_ipsec_crypto_alg, &crypto_alg)) {
8918 if (crypto_alg < IPSEC_CRYPTO_ALG_AES_CBC_128 ||
8919 crypto_alg > IPSEC_INTEG_ALG_SHA_512_256) {
8920 clib_warning ("unsupported crypto-alg: '%U'",
8921 format_ipsec_crypto_alg, crypto_alg);
8925 else if (unformat (i, "crypto_key %U", unformat_hex_string, &ck))
8927 else if (unformat (i, "integ_alg %U", unformat_ipsec_integ_alg, &integ_alg)) {
8928 if (integ_alg < IPSEC_INTEG_ALG_SHA1_96 ||
8929 integ_alg > IPSEC_INTEG_ALG_SHA_512_256) {
8930 clib_warning ("unsupported integ-alg: '%U'",
8931 format_ipsec_integ_alg, integ_alg);
8935 else if (unformat (i, "integ_key %U", unformat_hex_string, &ik))
8938 clib_warning ("parse error '%U'", format_unformat_error, i);
8944 M(IPSEC_SAD_ADD_DEL_ENTRY, ipsec_sad_add_del_entry);
8946 mp->sad_id = ntohl(sad_id);
8947 mp->is_add = is_add;
8948 mp->protocol = protocol;
8949 mp->spi = ntohl(spi);
8950 mp->is_tunnel = is_tunnel;
8951 mp->is_tunnel_ipv6 = is_tunnel_ipv6;
8952 mp->crypto_algorithm = crypto_alg;
8953 mp->integrity_algorithm = integ_alg;
8954 mp->crypto_key_length = vec_len(ck);
8955 mp->integrity_key_length = vec_len(ik);
8957 if (mp->crypto_key_length > sizeof(mp->crypto_key))
8958 mp->crypto_key_length = sizeof(mp->crypto_key);
8960 if (mp->integrity_key_length > sizeof(mp->integrity_key))
8961 mp->integrity_key_length = sizeof(mp->integrity_key);
8963 clib_memcpy (mp->crypto_key, ck, mp->crypto_key_length);
8964 clib_memcpy (mp->integrity_key, ik, mp->integrity_key_length);
8967 if (is_tunnel_ipv6) {
8968 clib_memcpy (mp->tunnel_src_address, &tun_src6, sizeof(ip6_address_t));
8969 clib_memcpy (mp->tunnel_dst_address, &tun_dst6, sizeof(ip6_address_t));
8971 clib_memcpy (mp->tunnel_src_address, &tun_src4, sizeof(ip4_address_t));
8972 clib_memcpy (mp->tunnel_dst_address, &tun_dst4, sizeof(ip4_address_t));
8980 clib_warning ("unsupported (no dpdk)");
8986 api_ipsec_sa_set_key (vat_main_t * vam)
8989 unformat_input_t * i = vam->input;
8990 vl_api_ipsec_sa_set_key_t *mp;
8995 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
8996 if (unformat (i, "sa_id %d", &sa_id))
8998 else if (unformat (i, "crypto_key %U", unformat_hex_string, &ck))
9000 else if (unformat (i, "integ_key %U", unformat_hex_string, &ik))
9003 clib_warning ("parse error '%U'", format_unformat_error, i);
9008 M(IPSEC_SA_SET_KEY, ipsec_set_sa_key);
9010 mp->sa_id = ntohl(sa_id);
9011 mp->crypto_key_length = vec_len(ck);
9012 mp->integrity_key_length = vec_len(ik);
9014 if (mp->crypto_key_length > sizeof(mp->crypto_key))
9015 mp->crypto_key_length = sizeof(mp->crypto_key);
9017 if (mp->integrity_key_length > sizeof(mp->integrity_key))
9018 mp->integrity_key_length = sizeof(mp->integrity_key);
9020 clib_memcpy (mp->crypto_key, ck, mp->crypto_key_length);
9021 clib_memcpy (mp->integrity_key, ik, mp->integrity_key_length);
9027 clib_warning ("unsupported (no dpdk)");
9033 api_ikev2_profile_add_del (vat_main_t * vam)
9036 unformat_input_t * i = vam->input;
9037 vl_api_ikev2_profile_add_del_t * mp;
9042 const char * valid_chars = "a-zA-Z0-9_";
9044 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
9045 if (unformat (i, "del"))
9047 else if (unformat (i, "name %U", unformat_token, valid_chars, &name))
9050 errmsg ("parse error '%U'", format_unformat_error, i);
9055 if (!vec_len (name)) {
9056 errmsg ("profile name must be specified");
9060 if (vec_len (name) > 64) {
9061 errmsg ("profile name too long");
9065 M(IKEV2_PROFILE_ADD_DEL, ikev2_profile_add_del);
9067 clib_memcpy(mp->name, name, vec_len (name));
9068 mp->is_add = is_add;
9075 clib_warning ("unsupported (no dpdk)");
9081 api_ikev2_profile_set_auth (vat_main_t * vam)
9084 unformat_input_t * i = vam->input;
9085 vl_api_ikev2_profile_set_auth_t * mp;
9089 u32 auth_method = 0;
9092 const char * valid_chars = "a-zA-Z0-9_";
9094 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
9095 if (unformat (i, "name %U", unformat_token, valid_chars, &name))
9097 else if (unformat (i, "auth_method %U",
9098 unformat_ikev2_auth_method, &auth_method))
9100 else if (unformat (i, "auth_data 0x%U", unformat_hex_string, &data))
9102 else if (unformat (i, "auth_data %v", &data))
9105 errmsg ("parse error '%U'", format_unformat_error, i);
9110 if (!vec_len (name)) {
9111 errmsg ("profile name must be specified");
9115 if (vec_len (name) > 64) {
9116 errmsg ("profile name too long");
9120 if (!vec_len(data)) {
9121 errmsg ("auth_data must be specified");
9126 errmsg ("auth_method must be specified");
9130 M(IKEV2_PROFILE_SET_AUTH, ikev2_profile_set_auth);
9132 mp->is_hex = is_hex;
9133 mp->auth_method = (u8) auth_method;
9134 mp->data_len = vec_len (data);
9135 clib_memcpy (mp->name, name, vec_len (name));
9136 clib_memcpy (mp->data, data, vec_len (data));
9144 clib_warning ("unsupported (no dpdk)");
9150 api_ikev2_profile_set_id (vat_main_t * vam)
9153 unformat_input_t * i = vam->input;
9154 vl_api_ikev2_profile_set_id_t * mp;
9162 const char * valid_chars = "a-zA-Z0-9_";
9164 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
9165 if (unformat (i, "name %U", unformat_token, valid_chars, &name))
9167 else if (unformat (i, "id_type %U",
9168 unformat_ikev2_id_type, &id_type))
9170 else if (unformat (i, "id_data %U", unformat_ip4_address, &ip4))
9172 data = vec_new(u8, 4);
9173 clib_memcpy(data, ip4.as_u8, 4);
9175 else if (unformat (i, "id_data 0x%U", unformat_hex_string, &data))
9177 else if (unformat (i, "id_data %v", &data))
9179 else if (unformat (i, "local"))
9181 else if (unformat (i, "remote"))
9184 errmsg ("parse error '%U'", format_unformat_error, i);
9189 if (!vec_len (name)) {
9190 errmsg ("profile name must be specified");
9194 if (vec_len (name) > 64) {
9195 errmsg ("profile name too long");
9199 if (!vec_len(data)) {
9200 errmsg ("id_data must be specified");
9205 errmsg ("id_type must be specified");
9209 M(IKEV2_PROFILE_SET_ID, ikev2_profile_set_id);
9211 mp->is_local = is_local;
9212 mp->id_type = (u8) id_type;
9213 mp->data_len = vec_len (data);
9214 clib_memcpy (mp->name, name, vec_len (name));
9215 clib_memcpy (mp->data, data, vec_len (data));
9223 clib_warning ("unsupported (no dpdk)");
9229 api_ikev2_profile_set_ts (vat_main_t * vam)
9232 unformat_input_t * i = vam->input;
9233 vl_api_ikev2_profile_set_ts_t * mp;
9237 u32 proto = 0, start_port = 0, end_port = (u32) ~0;
9238 ip4_address_t start_addr, end_addr;
9240 const char * valid_chars = "a-zA-Z0-9_";
9242 start_addr.as_u32 = 0;
9243 end_addr.as_u32 = (u32) ~0;
9245 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
9246 if (unformat (i, "name %U", unformat_token, valid_chars, &name))
9248 else if (unformat (i, "protocol %d", &proto))
9250 else if (unformat (i, "start_port %d", &start_port))
9252 else if (unformat (i, "end_port %d", &end_port))
9254 else if (unformat (i, "start_addr %U", unformat_ip4_address, &start_addr))
9256 else if (unformat (i, "end_addr %U", unformat_ip4_address, &end_addr))
9258 else if (unformat (i, "local"))
9260 else if (unformat (i, "remote"))
9263 errmsg ("parse error '%U'", format_unformat_error, i);
9268 if (!vec_len (name)) {
9269 errmsg ("profile name must be specified");
9273 if (vec_len (name) > 64) {
9274 errmsg ("profile name too long");
9278 M(IKEV2_PROFILE_SET_TS, ikev2_profile_set_ts);
9280 mp->is_local = is_local;
9281 mp->proto = (u8) proto;
9282 mp->start_port = (u16) start_port;
9283 mp->end_port = (u16) end_port;
9284 mp->start_addr = start_addr.as_u32;
9285 mp->end_addr = end_addr.as_u32;
9286 clib_memcpy (mp->name, name, vec_len (name));
9293 clib_warning ("unsupported (no dpdk)");
9299 api_ikev2_set_local_key (vat_main_t * vam)
9302 unformat_input_t * i = vam->input;
9303 vl_api_ikev2_set_local_key_t * mp;
9307 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
9308 if (unformat (i, "file %v", &file))
9311 errmsg ("parse error '%U'", format_unformat_error, i);
9316 if (!vec_len (file)) {
9317 errmsg ("RSA key file must be specified");
9321 if (vec_len (file) > 256) {
9322 errmsg ("file name too long");
9326 M(IKEV2_SET_LOCAL_KEY, ikev2_set_local_key);
9328 clib_memcpy (mp->key_file, file, vec_len (file));
9335 clib_warning ("unsupported (no dpdk)");
9343 static int api_map_add_domain (vat_main_t * vam)
9345 unformat_input_t *i = vam->input;
9346 vl_api_map_add_domain_t *mp;
9349 ip4_address_t ip4_prefix;
9350 ip6_address_t ip6_prefix;
9351 ip6_address_t ip6_src;
9353 u32 ip6_prefix_len, ip4_prefix_len, ea_bits_len, psid_offset,
9355 u8 is_translation = 0;
9357 u8 ip6_src_len = 128;
9359 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
9360 if (unformat (i, "ip4-pfx %U/%d", unformat_ip4_address,
9361 &ip4_prefix, &ip4_prefix_len))
9363 else if (unformat (i, "ip6-pfx %U/%d", unformat_ip6_address,
9364 &ip6_prefix, &ip6_prefix_len))
9366 else if (unformat (i, "ip6-src %U/%d", unformat_ip6_address, &ip6_src, &ip6_src_len))
9368 else if (unformat (i, "ip6-src %U", unformat_ip6_address, &ip6_src))
9370 else if (unformat (i, "ea-bits-len %d", &ea_bits_len))
9372 else if (unformat (i, "psid-offset %d", &psid_offset))
9374 else if (unformat (i, "psid-len %d", &psid_length))
9376 else if (unformat (i, "mtu %d", &mtu))
9378 else if (unformat (i, "map-t"))
9381 clib_warning ("parse error '%U'", format_unformat_error, i);
9386 if (num_m_args != 6) {
9387 errmsg("mandatory argument(s) missing\n");
9391 /* Construct the API message */
9392 M(MAP_ADD_DOMAIN, map_add_domain);
9394 clib_memcpy(mp->ip4_prefix, &ip4_prefix, sizeof(ip4_prefix));
9395 mp->ip4_prefix_len = ip4_prefix_len;
9397 clib_memcpy(mp->ip6_prefix, &ip6_prefix, sizeof(ip6_prefix));
9398 mp->ip6_prefix_len = ip6_prefix_len;
9400 clib_memcpy(mp->ip6_src, &ip6_src, sizeof(ip6_src));
9401 mp->ip6_src_prefix_len = ip6_src_len;
9403 mp->ea_bits_len = ea_bits_len;
9404 mp->psid_offset = psid_offset;
9405 mp->psid_length = psid_length;
9406 mp->is_translation = is_translation;
9407 mp->mtu = htons(mtu);
9412 /* Wait for a reply, return good/bad news */
9416 static int api_map_del_domain (vat_main_t * vam)
9418 unformat_input_t *i = vam->input;
9419 vl_api_map_del_domain_t *mp;
9425 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
9426 if (unformat (i, "index %d", &index))
9429 clib_warning ("parse error '%U'", format_unformat_error, i);
9434 if (num_m_args != 1) {
9435 errmsg("mandatory argument(s) missing\n");
9439 /* Construct the API message */
9440 M(MAP_DEL_DOMAIN, map_del_domain);
9442 mp->index = ntohl(index);
9447 /* Wait for a reply, return good/bad news */
9451 static int api_map_add_del_rule (vat_main_t * vam)
9453 unformat_input_t *i = vam->input;
9454 vl_api_map_add_del_rule_t *mp;
9457 ip6_address_t ip6_dst;
9458 u32 num_m_args = 0, index, psid;
9460 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
9461 if (unformat (i, "index %d", &index))
9463 else if (unformat (i, "psid %d", &psid))
9465 else if (unformat (i, "dst %U", unformat_ip6_address, &ip6_dst))
9467 else if (unformat (i, "del")) {
9470 clib_warning ("parse error '%U'", format_unformat_error, i);
9475 /* Construct the API message */
9476 M(MAP_ADD_DEL_RULE, map_add_del_rule);
9478 mp->index = ntohl(index);
9479 mp->is_add = is_add;
9480 clib_memcpy(mp->ip6_dst, &ip6_dst, sizeof(ip6_dst));
9481 mp->psid = ntohs(psid);
9486 /* Wait for a reply, return good/bad news */
9490 static int api_map_domain_dump (vat_main_t * vam)
9492 vl_api_map_domain_dump_t *mp;
9495 /* Construct the API message */
9496 M(MAP_DOMAIN_DUMP, map_domain_dump);
9501 /* Use a control ping for synchronization */
9503 vl_api_control_ping_t * mp;
9504 M(CONTROL_PING, control_ping);
9510 static int api_map_rule_dump (vat_main_t * vam)
9512 unformat_input_t *i = vam->input;
9513 vl_api_map_rule_dump_t *mp;
9515 u32 domain_index = ~0;
9517 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
9518 if (unformat (i, "index %u", &domain_index))
9524 if (domain_index == ~0) {
9525 clib_warning("parse error: domain index expected");
9529 /* Construct the API message */
9530 M(MAP_RULE_DUMP, map_rule_dump);
9532 mp->domain_index = htonl(domain_index);
9537 /* Use a control ping for synchronization */
9539 vl_api_control_ping_t * mp;
9540 M(CONTROL_PING, control_ping);
9546 static void vl_api_map_add_domain_reply_t_handler
9547 (vl_api_map_add_domain_reply_t * mp)
9549 vat_main_t * vam = &vat_main;
9550 i32 retval = ntohl(mp->retval);
9552 if (vam->async_mode) {
9553 vam->async_errors += (retval < 0);
9555 vam->retval = retval;
9556 vam->result_ready = 1;
9560 static void vl_api_map_add_domain_reply_t_handler_json
9561 (vl_api_map_add_domain_reply_t * mp)
9563 vat_main_t * vam = &vat_main;
9564 vat_json_node_t node;
9566 vat_json_init_object(&node);
9567 vat_json_object_add_int(&node, "retval", ntohl(mp->retval));
9568 vat_json_object_add_uint(&node, "index", ntohl(mp->index));
9570 vat_json_print(vam->ofp, &node);
9571 vat_json_free(&node);
9573 vam->retval = ntohl(mp->retval);
9574 vam->result_ready = 1;
9578 api_get_first_msg_id (vat_main_t * vam)
9580 vl_api_get_first_msg_id_t * mp;
9582 unformat_input_t * i = vam->input;
9586 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
9587 if (unformat (i, "client %s", &name))
9593 if (name_set == 0) {
9594 errmsg ("missing client name\n");
9599 if (vec_len (name) > 63) {
9600 errmsg ("client name too long\n");
9604 M(GET_FIRST_MSG_ID, get_first_msg_id);
9605 clib_memcpy (mp->name, name, vec_len(name));
9611 static int api_cop_interface_enable_disable (vat_main_t * vam)
9613 unformat_input_t * line_input = vam->input;
9614 vl_api_cop_interface_enable_disable_t * mp;
9616 u32 sw_if_index = ~0;
9617 u8 enable_disable = 1;
9619 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) {
9620 if (unformat (line_input, "disable"))
9622 if (unformat (line_input, "enable"))
9624 else if (unformat (line_input, "%U", unformat_sw_if_index,
9627 else if (unformat (line_input, "sw_if_index %d", &sw_if_index))
9633 if (sw_if_index == ~0) {
9634 errmsg ("missing interface name or sw_if_index\n");
9638 /* Construct the API message */
9639 M(COP_INTERFACE_ENABLE_DISABLE, cop_interface_enable_disable);
9640 mp->sw_if_index = ntohl(sw_if_index);
9641 mp->enable_disable = enable_disable;
9645 /* Wait for the reply */
9649 static int api_cop_whitelist_enable_disable (vat_main_t * vam)
9651 unformat_input_t * line_input = vam->input;
9652 vl_api_cop_whitelist_enable_disable_t * mp;
9654 u32 sw_if_index = ~0;
9655 u8 ip4=0, ip6=0, default_cop=0;
9658 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) {
9659 if (unformat (line_input, "ip4"))
9661 else if (unformat (line_input, "ip6"))
9663 else if (unformat (line_input, "default"))
9665 else if (unformat (line_input, "%U", unformat_sw_if_index,
9668 else if (unformat (line_input, "sw_if_index %d", &sw_if_index))
9670 else if (unformat (line_input, "fib-id %d", &fib_id))
9676 if (sw_if_index == ~0) {
9677 errmsg ("missing interface name or sw_if_index\n");
9681 /* Construct the API message */
9682 M(COP_WHITELIST_ENABLE_DISABLE, cop_whitelist_enable_disable);
9683 mp->sw_if_index = ntohl(sw_if_index);
9684 mp->fib_id = ntohl(fib_id);
9687 mp->default_cop = default_cop;
9691 /* Wait for the reply */
9695 static int api_get_node_graph (vat_main_t * vam)
9697 vl_api_get_node_graph_t * mp;
9700 M(GET_NODE_GRAPH, get_node_graph);
9704 /* Wait for the reply */
9709 api_lisp_add_del_locator_set(vat_main_t * vam)
9711 unformat_input_t * input = vam->input;
9712 vl_api_lisp_add_del_locator_set_t *mp;
9715 u8 *locator_set_name = NULL;
9716 u8 locator_set_name_set = 0;
9718 /* Parse args required to build the message */
9719 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) {
9720 if (unformat(input, "del")) {
9722 } else if (unformat(input, "locator-set %s", &locator_set_name)) {
9723 locator_set_name_set = 1;
9728 if (locator_set_name_set == 0) {
9729 errmsg ("missing locator-set name");
9733 if (vec_len(locator_set_name) > 64) {
9734 errmsg ("locator-set name too long\n");
9735 vec_free(locator_set_name);
9738 vec_add1(locator_set_name, 0);
9740 /* Construct the API message */
9741 M(LISP_ADD_DEL_LOCATOR_SET, lisp_add_del_locator_set);
9743 mp->is_add = is_add;
9744 clib_memcpy(mp->locator_set_name, locator_set_name,
9745 vec_len(locator_set_name));
9746 vec_free(locator_set_name);
9751 /* Wait for a reply... */
9759 api_lisp_add_del_locator(vat_main_t * vam)
9761 unformat_input_t * input = vam->input;
9762 vl_api_lisp_add_del_locator_t *mp;
9764 u32 tmp_if_index = ~0;
9765 u32 sw_if_index = ~0;
9766 u8 sw_if_index_set = 0;
9767 u8 sw_if_index_if_name_set = 0;
9769 u8 priority_set = 0;
9773 u8 *locator_set_name = NULL;
9774 u8 locator_set_name_set = 0;
9776 /* Parse args required to build the message */
9777 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) {
9778 if (unformat(input, "del")) {
9780 } else if (unformat(input, "locator-set %s", &locator_set_name)) {
9781 locator_set_name_set = 1;
9782 } else if (unformat(input, "iface %U", unformat_sw_if_index, vam,
9784 sw_if_index_if_name_set = 1;
9785 sw_if_index = tmp_if_index;
9786 } else if (unformat(input,"sw_if_index %d", &tmp_if_index)) {
9787 sw_if_index_set = 1;
9788 sw_if_index = tmp_if_index;
9789 } else if (unformat(input, "p %d", &priority)) {
9791 } else if (unformat(input, "w %d", &weight)) {
9797 if (locator_set_name_set == 0) {
9798 errmsg ("missing locator-set name");
9802 if (sw_if_index_set == 0 && sw_if_index_if_name_set == 0) {
9803 errmsg ("missing sw_if_index");
9804 vec_free(locator_set_name);
9808 if (sw_if_index_set != 0 && sw_if_index_if_name_set != 0) {
9809 errmsg ("cannot use both params interface name and sw_if_index");
9810 vec_free(locator_set_name);
9814 if (priority_set == 0) {
9815 errmsg ("missing locator-set priority\n");
9816 vec_free(locator_set_name);
9820 if (weight_set == 0) {
9821 errmsg ("missing locator-set weight\n");
9822 vec_free(locator_set_name);
9826 if (vec_len(locator_set_name) > 64) {
9827 errmsg ("locator-set name too long\n");
9828 vec_free(locator_set_name);
9831 vec_add1(locator_set_name, 0);
9833 /* Construct the API message */
9834 M(LISP_ADD_DEL_LOCATOR, lisp_add_del_locator);
9836 mp->is_add = is_add;
9837 mp->sw_if_index = ntohl(sw_if_index);
9838 mp->priority = priority;
9839 mp->weight = weight;
9840 clib_memcpy(mp->locator_set_name, locator_set_name,
9841 vec_len(locator_set_name));
9842 vec_free(locator_set_name);
9847 /* Wait for a reply... */
9855 api_lisp_add_del_local_eid(vat_main_t * vam)
9857 unformat_input_t * input = vam->input;
9858 vl_api_lisp_add_del_local_eid_t *mp;
9863 ip4_address_t eidv4;
9864 ip6_address_t eidv6;
9865 u8 tmp_eid_lenght = ~0;
9867 u8 *locator_set_name = NULL;
9868 u8 locator_set_name_set = 0;
9870 /* Parse args required to build the message */
9871 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) {
9872 if (unformat(input, "del")) {
9874 } else if (unformat(input, "eid %U/%d", unformat_ip4_address,
9875 &eidv4, &tmp_eid_lenght)) {
9876 eid_lenght = tmp_eid_lenght;
9878 } else if (unformat(input, "eid %U/%d", unformat_ip6_address,
9879 &eidv6, &tmp_eid_lenght)) {
9880 eid_lenght = tmp_eid_lenght;
9882 } else if (unformat(input, "locator-set %s", &locator_set_name)) {
9883 locator_set_name_set = 1;
9888 if (locator_set_name_set == 0) {
9889 errmsg ("missing locator-set name\n");
9893 if (vec_len(locator_set_name) > 64) {
9894 errmsg ("locator-set name too long\n");
9895 vec_free(locator_set_name);
9898 vec_add1(locator_set_name, 0);
9900 if (eidv4_set && eidv6_set) {
9901 errmsg ("both eid v4 and v6 addresses set\n");
9902 vec_free(locator_set_name);
9906 if (!eidv4_set && !eidv6_set) {
9907 errmsg ("eid addresses not set\n");
9908 vec_free(locator_set_name);
9912 /* Construct the API message */
9913 M(LISP_ADD_DEL_LOCAL_EID, lisp_add_del_local_eid);
9915 mp->is_add = is_add;
9918 clib_memcpy(mp->ip_address, &eidv6, sizeof(eidv6));
9921 clib_memcpy(mp->ip_address, &eidv4, sizeof(eidv4));
9923 mp->prefix_len = eid_lenght;
9924 clib_memcpy(mp->locator_set_name, locator_set_name,
9925 vec_len(locator_set_name));
9926 vec_free(locator_set_name);
9931 /* Wait for a reply... */
9939 api_lisp_gpe_add_del_fwd_entry(vat_main_t * vam)
9941 unformat_input_t * input = vam->input;
9942 vl_api_lisp_gpe_add_del_fwd_entry_t *mp;
9945 u8 eidv4_set = 0, slocv4_set = 0, dlocv4_set = 0;
9946 u8 eidv6_set = 0, slocv6_set = 0, dlocv6_set = 0;
9947 ip4_address_t eidv4, slocv4, dlocv4;
9948 ip6_address_t eidv6, slocv6, dlocv6;
9949 u8 tmp_eid_lenght = ~0;
9952 /* Parse args required to build the message */
9953 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) {
9954 if (unformat(input, "del")) {
9956 } else if (unformat(input, "eid %U/%d", unformat_ip4_address,
9957 &eidv4, &tmp_eid_lenght)) {
9958 eid_lenght = tmp_eid_lenght;
9960 } else if (unformat(input, "eid %U/%d", unformat_ip6_address,
9961 &eidv6, &tmp_eid_lenght)) {
9962 eid_lenght = tmp_eid_lenght;
9964 } else if (unformat(input, "sloc %U", unformat_ip4_address, &slocv4)) {
9966 } else if (unformat(input, "sloc %U", unformat_ip6_address, &slocv6)) {
9968 } else if (unformat(input, "dloc %U", unformat_ip4_address, &dlocv4)) {
9970 } else if (unformat(input, "dloc %U", unformat_ip6_address, &dlocv6)) {
9976 if (eidv4_set && eidv6_set) {
9977 errmsg ("both eid v4 and v6 addresses set\n");
9981 if (!eidv4_set && !eidv6_set) {
9982 errmsg ("eid addresses not set\n");
9986 if (slocv4_set && slocv6_set) {
9987 errmsg ("both source v4 and v6 addresses set\n");
9991 if (!slocv4_set && !slocv6_set) {
9992 errmsg ("source addresses not set\n");
9996 if (dlocv4_set && dlocv6_set) {
9997 errmsg ("both destination v4 and v6 addresses set\n");
10001 if (dlocv4_set && dlocv6_set) {
10002 errmsg ("destination addresses not set\n");
10006 if (!(slocv4_set == dlocv4_set && slocv6_set == dlocv6_set)) {
10007 errmsg ("mixing type of source and destination address\n");
10011 /* Construct the API message */
10012 M(LISP_GPE_ADD_DEL_FWD_ENTRY, lisp_gpe_add_del_fwd_entry);
10014 mp->is_add = is_add;
10016 mp->eid_is_ipv6 = 1;
10017 clib_memcpy(mp->eid_ip_address, &eidv6, sizeof(eidv6));
10019 mp->eid_is_ipv6 = 0;
10020 clib_memcpy(mp->eid_ip_address, &eidv4, sizeof(eidv4));
10022 mp->eid_prefix_len = eid_lenght;
10024 mp->address_is_ipv6 = 1;
10025 clib_memcpy(mp->source_ip_address, &slocv6, sizeof(slocv6));
10026 clib_memcpy(mp->destination_ip_address, &dlocv6, sizeof(dlocv6));
10028 mp->address_is_ipv6 = 0;
10029 clib_memcpy(mp->source_ip_address, &slocv4, sizeof(slocv4));
10030 clib_memcpy(mp->destination_ip_address, &dlocv4, sizeof(dlocv4));
10036 /* Wait for a reply... */
10044 api_lisp_add_del_map_resolver(vat_main_t * vam)
10046 unformat_input_t * input = vam->input;
10047 vl_api_lisp_add_del_map_resolver_t *mp;
10052 ip4_address_t ipv4;
10053 ip6_address_t ipv6;
10055 /* Parse args required to build the message */
10056 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) {
10057 if (unformat(input, "del")) {
10059 } else if (unformat(input, "%U", unformat_ip4_address, &ipv4)) {
10061 } else if (unformat(input, "%U", unformat_ip6_address, &ipv6)) {
10067 if (ipv4_set && ipv6_set) {
10068 errmsg ("both eid v4 and v6 addresses set\n");
10072 if (!ipv4_set && !ipv6_set) {
10073 errmsg ("eid addresses not set\n");
10077 /* Construct the API message */
10078 M(LISP_ADD_DEL_MAP_RESOLVER, lisp_add_del_map_resolver);
10080 mp->is_add = is_add;
10083 clib_memcpy(mp->ip_address, &ipv6, sizeof(ipv6));
10086 clib_memcpy(mp->ip_address, &ipv4, sizeof(ipv4));
10092 /* Wait for a reply... */
10100 api_lisp_gpe_enable_disable (vat_main_t * vam)
10102 unformat_input_t * input = vam->input;
10103 vl_api_lisp_gpe_enable_disable_t *mp;
10108 /* Parse args required to build the message */
10109 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) {
10110 if (unformat(input, "enable")) {
10113 } else if (unformat(input, "disable")) {
10121 errmsg("Value not set\n");
10125 /* Construct the API message */
10126 M(LISP_GPE_ENABLE_DISABLE, lisp_gpe_enable_disable);
10133 /* Wait for a reply... */
10141 api_lisp_gpe_add_del_iface(vat_main_t * vam)
10143 unformat_input_t * input = vam->input;
10144 vl_api_lisp_gpe_add_del_iface_t *mp;
10150 /* Parse args required to build the message */
10151 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) {
10152 if (unformat(input, "up")) {
10155 } else if (unformat(input, "down")) {
10158 } else if (unformat(input, "table_id %d", &table_id)) {
10160 } else if (unformat(input, "vni %d", &vni)) {
10167 errmsg("Value not set\n");
10171 /* Construct the API message */
10172 M(LISP_GPE_ADD_DEL_IFACE, lisp_gpe_add_del_iface);
10174 mp->is_add = is_add;
10175 mp->table_id = table_id;
10181 /* Wait for a reply... */
10189 api_lisp_locator_set_dump(vat_main_t *vam)
10191 vl_api_lisp_locator_set_dump_t *mp;
10194 if (!vam->json_output) {
10195 fformat(vam->ofp, "%=20s%=16s%=16s%=16s\n",
10196 "Locator-set", "Locator", "Priority", "Weight");
10199 M(LISP_LOCATOR_SET_DUMP, lisp_locator_set_dump);
10203 /* Use a control ping for synchronization */
10205 vl_api_control_ping_t * mp;
10206 M(CONTROL_PING, control_ping);
10209 /* Wait for a reply... */
10217 api_lisp_local_eid_table_dump(vat_main_t *vam)
10219 vl_api_lisp_local_eid_table_dump_t *mp;
10222 if (!vam->json_output) {
10223 fformat(vam->ofp, "%=20s%=30s\n",
10224 "Locator-set", "Eid");
10227 M(LISP_LOCAL_EID_TABLE_DUMP, lisp_local_eid_table_dump);
10231 /* Use a control ping for synchronization */
10233 vl_api_control_ping_t * mp;
10234 M(CONTROL_PING, control_ping);
10237 /* Wait for a reply... */
10245 api_lisp_gpe_tunnel_dump(vat_main_t *vam)
10247 vl_api_lisp_gpe_tunnel_dump_t *mp;
10250 if (!vam->json_output) {
10251 fformat(vam->ofp, "%=20s%=30s%=16s%=16s%=16s%=16s"
10252 "%=16s%=16s%=16s%=16s%=16s\n",
10253 "Tunel", "Source", "Destination", "Fib encap", "Fib decap",
10254 "Decap next", "Lisp version", "Flags", "Next protocol",
10255 "ver_res", "res", "iid");
10258 M(LISP_GPE_TUNNEL_DUMP, lisp_gpe_tunnel_dump);
10262 /* Use a control ping for synchronization */
10264 vl_api_control_ping_t * mp;
10265 M(CONTROL_PING, control_ping);
10268 /* Wait for a reply... */
10276 api_lisp_map_resolver_dump(vat_main_t *vam)
10278 vl_api_lisp_map_resolver_dump_t *mp;
10281 if (!vam->json_output) {
10282 fformat(vam->ofp, "%=20s\n",
10286 M(LISP_MAP_RESOLVER_DUMP, lisp_map_resolver_dump);
10290 /* Use a control ping for synchronization */
10292 vl_api_control_ping_t * mp;
10293 M(CONTROL_PING, control_ping);
10296 /* Wait for a reply... */
10303 static int q_or_quit (vat_main_t * vam)
10305 longjmp (vam->jump_buf, 1);
10306 return 0; /* not so much */
10308 static int q (vat_main_t * vam) {return q_or_quit (vam);}
10309 static int quit (vat_main_t * vam) {return q_or_quit (vam);}
10311 static int comment (vat_main_t * vam)
10316 static int cmd_cmp (void * a1, void * a2)
10321 return strcmp ((char *)(c1[0]), (char *)(c2[0]));
10324 static int help (vat_main_t * vam)
10329 unformat_input_t * i = vam->input;
10332 if (unformat (i, "%s", &name)) {
10337 hs = hash_get_mem (vam->help_by_name, name);
10339 fformat (vam->ofp, "usage: %s %s\n", name, hs[0]);
10341 fformat (vam->ofp, "No such msg / command '%s'\n", name);
10346 fformat(vam->ofp, "Help is available for the following:\n");
10348 hash_foreach_pair (p, vam->function_by_name,
10350 vec_add1 (cmds, (u8 *)(p->key));
10353 vec_sort_with_function (cmds, cmd_cmp);
10355 for (j = 0; j < vec_len(cmds); j++)
10356 fformat (vam->ofp, "%s\n", cmds[j]);
10362 static int set (vat_main_t * vam)
10364 u8 * name = 0, * value = 0;
10365 unformat_input_t * i = vam->input;
10367 if (unformat (i, "%s", &name)) {
10368 /* The input buffer is a vector, not a string. */
10369 value = vec_dup (i->buffer);
10370 vec_delete (value, i->index, 0);
10371 /* Almost certainly has a trailing newline */
10372 if (value[vec_len(value)-1] == '\n')
10373 value[vec_len(value)-1] = 0;
10374 /* Make sure it's a proper string, one way or the other */
10375 vec_add1 (value, 0);
10376 (void) clib_macro_set_value (&vam->macro_main,
10377 (char *)name, (char *)value);
10380 errmsg ("usage: set <name> <value>\n");
10387 static int unset (vat_main_t * vam)
10391 if (unformat (vam->input, "%s", &name))
10392 if (clib_macro_unset (&vam->macro_main, (char *)name) == 1)
10393 errmsg ("unset: %s wasn't set\n", name);
10404 static int macro_sort_cmp (void * a1, void * a2)
10406 macro_sort_t * s1 = a1;
10407 macro_sort_t * s2 = a2;
10409 return strcmp ((char *)(s1->name), (char *)(s2->name));
10412 static int dump_macro_table (vat_main_t * vam)
10414 macro_sort_t * sort_me = 0, * sm;
10418 hash_foreach_pair (p, vam->macro_main.the_value_table_hash,
10420 vec_add2 (sort_me, sm, 1);
10421 sm->name = (u8 *)(p->key);
10422 sm->value = (u8 *) (p->value[0]);
10425 vec_sort_with_function (sort_me, macro_sort_cmp);
10427 if (vec_len(sort_me))
10428 fformat (vam->ofp, "%-15s%s\n", "Name", "Value");
10430 fformat (vam->ofp, "The macro table is empty...\n");
10432 for (i = 0; i < vec_len (sort_me); i++)
10433 fformat (vam->ofp, "%-15s%s\n", sort_me[i].name,
10438 static int dump_node_table (vat_main_t * vam)
10441 vlib_node_t * node, * next_node;
10443 if (vec_len (vam->graph_nodes) == 0) {
10444 fformat (vam->ofp, "Node table empty, issue get_node_graph...\n");
10448 for (i = 0; i < vec_len (vam->graph_nodes); i++) {
10449 node = vam->graph_nodes[i];
10450 fformat (vam->ofp, "[%d] %s\n", i, node->name);
10451 for (j = 0; j < vec_len (node->next_nodes); j++) {
10452 if (node->next_nodes[j] != ~0) {
10453 next_node = vam->graph_nodes[node->next_nodes[j]];
10454 fformat (vam->ofp, " [%d] %s\n", j, next_node->name);
10461 static int search_node_table (vat_main_t * vam)
10463 unformat_input_t * line_input = vam->input;
10466 vlib_node_t * node, * next_node;
10469 if (vam->graph_node_index_by_name == 0) {
10470 fformat (vam->ofp, "Node table empty, issue get_node_graph...\n");
10474 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) {
10475 if (unformat (line_input, "%s", &node_to_find)) {
10476 vec_add1 (node_to_find, 0);
10477 p = hash_get_mem (vam->graph_node_index_by_name, node_to_find);
10479 fformat (vam->ofp, "%s not found...\n", node_to_find);
10482 node = vam->graph_nodes[p[0]];
10483 fformat (vam->ofp, "[%d] %s\n", p[0], node->name);
10484 for (j = 0; j < vec_len (node->next_nodes); j++) {
10485 if (node->next_nodes[j] != ~0) {
10486 next_node = vam->graph_nodes[node->next_nodes[j]];
10487 fformat (vam->ofp, " [%d] %s\n", j, next_node->name);
10493 clib_warning ("parse error '%U'", format_unformat_error,
10499 vec_free(node_to_find);
10507 static int script (vat_main_t * vam)
10510 char * save_current_file;
10511 unformat_input_t save_input;
10512 jmp_buf save_jump_buf;
10513 u32 save_line_number;
10515 FILE * new_fp, * save_ifp;
10517 if (unformat (vam->input, "%s", &s)) {
10518 new_fp = fopen ((char *)s, "r");
10520 errmsg ("Couldn't open script file %s\n", s);
10525 errmsg ("Missing script name\n");
10529 clib_memcpy (&save_input, &vam->input, sizeof (save_input));
10530 clib_memcpy (&save_jump_buf, &vam->jump_buf, sizeof (save_jump_buf));
10531 save_ifp = vam->ifp;
10532 save_line_number = vam->input_line_number;
10533 save_current_file = (char *) vam->current_file;
10535 vam->input_line_number = 0;
10537 vam->current_file = s;
10540 clib_memcpy (&vam->input, &save_input, sizeof (vam->input));
10541 clib_memcpy (&vam->jump_buf, &save_jump_buf, sizeof (save_jump_buf));
10542 vam->ifp = save_ifp;
10543 vam->input_line_number = save_line_number;
10544 vam->current_file = (u8 *) save_current_file;
10550 static int echo (vat_main_t * vam)
10552 fformat (vam->ofp, "%v", vam->input->buffer);
10556 /* List of API message constructors, CLI names map to api_xxx */
10557 #define foreach_vpe_api_msg \
10558 _(create_loopback,"[mac <mac-addr>]") \
10559 _(sw_interface_dump,"") \
10560 _(sw_interface_set_flags, \
10561 "<intfc> | sw_if_index <id> admin-up | admin-down link-up | link down") \
10562 _(sw_interface_add_del_address, \
10563 "<intfc> | sw_if_index <id> <ip4-address> | <ip6-address> [del] [del-all] ") \
10564 _(sw_interface_set_table, \
10565 "<intfc> | sw_if_index <id> vrf <table-id> [ipv6]") \
10566 _(sw_interface_set_vpath, \
10567 "<intfc> | sw_if_index <id> enable | disable") \
10568 _(sw_interface_set_l2_xconnect, \
10569 "rx <intfc> | rx_sw_if_index <id> tx <intfc> | tx_sw_if_index <id>\n" \
10570 "enable | disable") \
10571 _(sw_interface_set_l2_bridge, \
10572 "rx <intfc> | rx_sw_if_index <id> bd_id <bridge-domain-id>\n" \
10573 "[shg <split-horizon-group>] [bvi]\n" \
10574 "enable | disable") \
10575 _(bridge_domain_add_del, \
10576 "bd_id <bridge-domain-id> [flood 1|0] [uu-flood 1|0] [forward 1|0] [learn 1|0] [arp-term 1|0] [del]\n")\
10577 _(bridge_domain_dump, "[bd_id <bridge-domain-id>]\n") \
10579 "mac <mac-addr> bd_id <bridge-domain-id> [del] | sw_if <intfc> | sw_if_index <id> [static] [filter] [bvi]\n") \
10581 "sw_if <intfc> | sw_if_index <id> [learn] [forward] [uu-flood] [flood]\n") \
10583 "bd_id <bridge-domain-id> [learn] [forward] [uu-flood] [flood] [arp-term] [disable]\n") \
10585 "tapname <name> mac <mac-addr> | random-mac") \
10587 "<vpp-if-name> | sw_if_index <id> tapname <name> mac <mac-addr> | random-mac") \
10589 "<vpp-if-name> | sw_if_index <id>") \
10590 _(sw_interface_tap_dump, "") \
10591 _(ip_add_del_route, \
10592 "<addr>/<mask> via <addr> [vrf <n>]\n" \
10593 "[<intfc> | sw_if_index <id>] [resolve-attempts <n>]\n" \
10594 "[weight <n>] [drop] [local] [classify <n>] [del]\n" \
10595 "[multipath] [count <n>]") \
10596 _(proxy_arp_add_del, \
10597 "<lo-ip4-addr> - <hi-ip4-addr> [vrf <n>] [del]") \
10598 _(proxy_arp_intfc_enable_disable, \
10599 "<intfc> | sw_if_index <id> enable | disable") \
10600 _(mpls_add_del_encap, \
10601 "label <n> dst <ip4-addr> [vrf <n>] [del]") \
10602 _(mpls_add_del_decap, \
10603 "label <n> [rx_vrf_id <n>] [tx_vrf_id] [s-bit-clear][del]") \
10604 _(mpls_gre_add_del_tunnel, \
10605 "inner_vrf_id <n> outer_vrf_id <n> src <ip4-address> dst <ip4-address>\n" \
10606 "adj <ip4-address>/<mask-width> [del]") \
10607 _(sw_interface_set_unnumbered, \
10608 "<intfc> | sw_if_index <id> unnum_if_index <id> [del]") \
10609 _(ip_neighbor_add_del, \
10610 "<intfc> | sw_if_index <id> dst <ip46-address> mac <mac-addr>") \
10611 _(reset_vrf, "vrf <id> [ipv6]") \
10612 _(create_vlan_subif, "<intfc> | sw_if_index <id> vlan <n>") \
10613 _(create_subif, "<intfc> | sw_if_index <id> sub_id <n>\n" \
10614 "[outer_vlan_id <n>][inner_vlan_id <n>]\n" \
10615 "[no_tags][one_tag][two_tags][dot1ad][exact_match][default_sub]\n" \
10616 "[outer_vlan_id_any][inner_vlan_id_any]") \
10617 _(oam_add_del, "src <ip4-address> dst <ip4-address> [vrf <n>] [del]") \
10618 _(reset_fib, "vrf <n> [ipv6]") \
10619 _(dhcp_proxy_config, \
10620 "svr <v46-address> src <v46-address>\n" \
10621 "insert-cid <n> [del]") \
10622 _(dhcp_proxy_config_2, \
10623 "svr <v46-address> src <v46-address>\n" \
10624 "rx_vrf_id <nn> server_vrf_id <nn> insert-cid <n> [del]") \
10625 _(dhcp_proxy_set_vss, \
10626 "tbl_id <n> fib_id <n> oui <n> [ipv6] [del]") \
10627 _(dhcp_client_config, \
10628 "<intfc> | sw_if_index <id> [hostname <name>] [disable_event] [del]") \
10629 _(set_ip_flow_hash, \
10630 "vrf <n> [src] [dst] [sport] [dport] [proto] [reverse] [ipv6]") \
10631 _(sw_interface_ip6_enable_disable, \
10632 "<intfc> | sw_if_index <id> enable | disable") \
10633 _(sw_interface_ip6_set_link_local_address, \
10634 "<intfc> | sw_if_index <id> <ip6-address>/<mask-width>") \
10635 _(sw_interface_ip6nd_ra_prefix, \
10636 "<intfc> | sw_if_index <id> <ip6-address>/<mask-width>\n" \
10637 "val_life <n> pref_life <n> [def] [noadv] [offl] [noauto]\n" \
10638 "[nolink] [isno]") \
10639 _(sw_interface_ip6nd_ra_config, \
10640 "<intfc> | sw_if_index <id> [maxint <n>] [minint <n>]\n" \
10641 "[life <n>] [count <n>] [interval <n>] [surpress]\n" \
10642 "[managed] [other] [ll] [send] [cease] [isno] [def]") \
10643 _(set_arp_neighbor_limit, "arp_nbr_limit <n> [ipv6]") \
10644 _(l2_patch_add_del, \
10645 "rx <intfc> | rx_sw_if_index <id> tx <intfc> | tx_sw_if_index <id>\n" \
10646 "enable | disable") \
10647 _(mpls_ethernet_add_del_tunnel, \
10648 "tx <intfc> | tx_sw_if_index <n> dst <mac-addr>\n" \
10649 "adj <ip4-addr>/<mw> dst <mac-addr> [del]") \
10650 _(mpls_ethernet_add_del_tunnel_2, \
10651 "inner_vrf_id <n> outer_vrf_id <n> next-hop <ip4-addr>\n" \
10652 "resolve-attempts <n> resolve-if-needed 0 | 1 [del]") \
10653 _(sr_tunnel_add_del, \
10654 "[name <name>] src <ip6-addr> dst <ip6-addr>/<mw> \n" \
10655 "(next <ip6-addr>)+ [tag <ip6-addr>]* [clean] [reroute] \n" \
10656 "[policy <policy_name>]") \
10657 _(sr_policy_add_del, \
10658 "name <name> tunnel <tunnel-name> [tunnel <tunnel-name>]* [del]") \
10659 _(sr_multicast_map_add_del, \
10660 "address [ip6 multicast address] sr-policy [policy name] [del]") \
10661 _(classify_add_del_table, \
10662 "buckets <nn> [skip <n>] [match <n>] [memory_size <nn-bytes>]\n" \
10663 "[del] mask <mask-value>\n" \
10664 " [l2-miss-next | miss-next | acl-miss-next] <name|nn>") \
10665 _(classify_add_del_session, \
10666 "[hit-next|l2-hit-next|acl-hit-next] <name|nn> table-index <nn>\n" \
10667 "skip_n <nn> match_n <nn> match [hex] [l2] [l3 [ip4|ip6]]") \
10668 _(classify_set_interface_ip_table, \
10669 "<intfc> | sw_if_index <nn> table <nn>") \
10670 _(classify_set_interface_l2_tables, \
10671 "<intfc> | sw_if_index <nn> [ip4-table <nn>] [ip6-table <nn>]\n" \
10672 " [other-table <nn>]") \
10673 _(get_node_index, "node <node-name") \
10674 _(add_node_next, "node <node-name> next <next-node-name>") \
10675 _(l2tpv3_create_tunnel, \
10676 "client_address <ip6-addr> our_address <ip6-addr>\n" \
10677 "[local_session_id <nn>][remote_session_id <nn>][local_cookie <nn>]\n"\
10678 "[remote_cookie <nn>]\n[l2-sublayer-preset]\n") \
10679 _(l2tpv3_set_tunnel_cookies, \
10680 "<intfc> | sw_if_index <nn> [new_local_cookie <nn>]\n" \
10681 "[new_remote_cookie <nn>]\n") \
10682 _(l2tpv3_interface_enable_disable, \
10683 "<intfc> | sw_if_index <nn> enable | disable") \
10684 _(l2tpv3_set_lookup_key, \
10685 "lookup_v6_src | lookup_v6_dst | lookup_session_id") \
10686 _(sw_if_l2tpv3_tunnel_dump, "") \
10687 _(vxlan_add_del_tunnel, \
10688 "src <ip4-addr> dst <ip4-addr> vni <vni> [encap-vrf-id <nn>]\n" \
10689 " [decap-next l2|ip4|ip6] [del]") \
10690 _(vxlan_tunnel_dump, "[<intfc> | sw_if_index <nn>]") \
10691 _(gre_add_del_tunnel, \
10692 "src <ip4-addr> dst <ip4-addr> [outer-fib-id <nn>] [del]\n") \
10693 _(gre_tunnel_dump, "[<intfc> | sw_if_index <nn>]") \
10694 _(l2_fib_clear_table, "") \
10695 _(l2_interface_efp_filter, "sw_if_index <nn> enable | disable") \
10696 _(l2_interface_vlan_tag_rewrite, \
10697 "<intfc> | sw_if_index <nn> \n" \
10698 "[disable][push-[1|2]][pop-[1|2]][translate-1-[1|2]] \n" \
10699 "[translate-2-[1|2]] [push_dot1q 0] tag1 <nn> tag2 <nn>") \
10700 _(create_vhost_user_if, \
10701 "socket <filename> [server] [renumber <dev_instance>] " \
10702 "[mac <mac_address>]") \
10703 _(modify_vhost_user_if, \
10704 "<intfc> | sw_if_index <nn> socket <filename>\n" \
10705 "[server] [renumber <dev_instance>]") \
10706 _(delete_vhost_user_if, "<intfc> | sw_if_index <nn>") \
10707 _(sw_interface_vhost_user_dump, "") \
10708 _(show_version, "") \
10709 _(nsh_gre_add_del_tunnel, \
10710 "src <ip4-addr> dst <ip4-addr>" \
10711 "c1 <nn> c2 <nn> c3 <nn> c4 <nn> spi <nn> si <nn>\n" \
10712 "[encap-fib-id <nn>] [decap-fib-id <nn>] [o-bit <1|0>]\n" \
10713 "[c-bit <1|0>] [md-type <nn>][next-ip4][next-ip6][next-ethernet]\n" \
10714 "[tlv <xx>][del]") \
10715 _(nsh_vxlan_gpe_add_del_tunnel, \
10716 "src <ip4-addr> dst <ip4-addr> vni <nn>\n" \
10717 "c1 <nn> c2 <nn> c3 <nn> c4 <nn> spi <nn> si <nn>\n" \
10718 "[encap-vrf-id <nn>] [decap-vrf-id <nn>] [o-bit <1|0>]\n" \
10719 "[c-bit <1|0>] [md-type <nn>][next-ip4][next-ip6][next-ethernet]\n" \
10720 "[tlv <xx>][del]") \
10721 _(l2_fib_table_dump, "bd_id <bridge-domain-id>") \
10722 _(lisp_gpe_add_del_tunnel, \
10723 "src <ip4-addr> dst <ip4-addr> iid <nn>|iidx <0xnn>\n" \
10724 "[encap-vrf-id <nn>] [decap-vrf-id <nn>]\n" \
10725 "[n-bit][l-bit][e-bit][v-bit][i-bit][p-bit][not-p-bit][o-bit]\n" \
10726 "[next-ip4][next-ip6][next-ethernet][next-nsh]\n" \
10727 "[decap-next [ip4|ip6|ethernet|nsh-encap|<nn>]][del]") \
10728 _(interface_name_renumber, \
10729 "<intfc> | sw_if_index <nn> new_show_dev_instance <nn>") \
10730 _(input_acl_set_interface, \
10731 "<intfc> | sw_if_index <nn> [ip4-table <nn>] [ip6-table <nn>]\n" \
10732 " [l2-table <nn>] [del]") \
10733 _(want_ip4_arp_events, "address <ip4-address> [del]") \
10734 _(ip_address_dump, "(ipv4 | ipv6) (<intfc> | sw_if_index <id>)") \
10735 _(ip_dump, "ipv4 | ipv6") \
10736 _(ipsec_spd_add_del, "spd_id <n> [del]") \
10737 _(ipsec_interface_add_del_spd, "(<intfc> | sw_if_index <id>)\n" \
10739 _(ipsec_sad_add_del_entry, "sad_id <n> spi <n> crypto_alg <alg>\n" \
10740 " crypto_key <hex> tunnel_src <ip4|ip6> tunnel_dst <ip4|ip6>\n" \
10741 " integ_alg <alg> integ_key <hex>") \
10742 _(ipsec_spd_add_del_entry, "spd_id <n> priority <n> action <action>\n" \
10743 " (inbound|outbound) [sa_id <n>] laddr_start <ip4|ip6>\n" \
10744 " laddr_stop <ip4|ip6> raddr_start <ip4|ip6> raddr_stop <ip4|ip6>\n" \
10745 " [lport_start <n> lport_stop <n>] [rport_start <n> rport_stop <n>]" )\
10746 _(ipsec_sa_set_key, "sa_id <n> crypto_key <hex> integ_key <hex>") \
10747 _(ikev2_profile_add_del, "name <profile_name> [del]") \
10748 _(ikev2_profile_set_auth, "name <profile_name> auth_method <method>\n" \
10749 "(auth_data 0x<data> | auth_data <data>)") \
10750 _(ikev2_profile_set_id, "name <profile_name> id_type <type>\n" \
10751 "(id_data 0x<data> | id_data <data>) (local|remote)") \
10752 _(ikev2_profile_set_ts, "name <profile_name> protocol <proto>\n" \
10753 "start_port <port> end_port <port> start_addr <ip4> end_addr <ip4>\n" \
10754 "(local|remote)") \
10755 _(ikev2_set_local_key, "file <absolute_file_path>") \
10756 _(delete_loopback,"sw_if_index <nn>") \
10757 _(bd_ip_mac_add_del, "bd_id <bridge-domain-id> <ip4/6-addr> <mac-addr> [del]") \
10758 _(map_add_domain, \
10759 "ip4-pfx <ip4pfx> ip6-pfx <ip6pfx> " \
10760 "ip6-src <ip6addr> " \
10761 "ea-bits-len <n> psid-offset <n> psid-len <n>") \
10762 _(map_del_domain, "index <n>") \
10763 _(map_add_del_rule, \
10764 "index <n> psid <n> dst <ip6addr> [del]") \
10765 _(map_domain_dump, "") \
10766 _(map_rule_dump, "index <map-domain>") \
10767 _(want_interface_events, "enable|disable") \
10768 _(want_stats,"enable|disable") \
10769 _(get_first_msg_id, "client <name>") \
10770 _(cop_interface_enable_disable, "<intfc> | sw_if_index <nn> [disable]") \
10771 _(cop_whitelist_enable_disable, "<intfc> | sw_if_index <nn>\n" \
10772 "fib-id <nn> [ip4][ip6][default]") \
10773 _(get_node_graph, " ") \
10774 _(sw_interface_clear_stats,"<intfc> | sw_if_index <nn>") \
10775 _(trace_profile_add, "id <nn> trace-type <0x1f|0x3|0x9|0x11|0x19> " \
10776 "trace-elts <nn> trace-tsp <0|1|2|3> node-id <node id in hex> " \
10777 "app-data <app_data in hex> [pow] [ppc <encap|decap>]") \
10778 _(trace_profile_apply, "id <nn> <ip6-address>/<width>" \
10779 " vrf_id <nn> add | pop | none") \
10780 _(trace_profile_del, "") \
10781 _(lisp_add_del_locator_set, "locator-set <locator_name> [del]") \
10782 _(lisp_add_del_locator, "locator-set <locator_name> " \
10783 "iface <intf> | sw_if_index <sw_if_index> " \
10784 "p <priority> w <weight> [del]") \
10785 _(lisp_add_del_local_eid, "<ipv4|ipv6>/<prefix> " \
10786 "locator-set <locator_name> [del]") \
10787 _(lisp_gpe_add_del_fwd_entry, "eid <ip4|6-addr>/<prefix> " \
10788 "sloc <ip4/6-addr> dloc <ip4|6-addr> [del]") \
10789 _(lisp_add_del_map_resolver, "<ip4|6-addr> [del]") \
10790 _(lisp_gpe_enable_disable, "enable|disable") \
10791 _(lisp_gpe_add_del_iface, "up|down") \
10792 _(lisp_locator_set_dump, "") \
10793 _(lisp_local_eid_table_dump, "") \
10794 _(lisp_gpe_tunnel_dump, "") \
10795 _(lisp_map_resolver_dump, "")
10797 /* List of command functions, CLI names map directly to functions */
10798 #define foreach_cli_function \
10799 _(comment, "usage: comment <ignore-rest-of-line>") \
10800 _(dump_interface_table, "usage: dump_interface_table") \
10801 _(dump_sub_interface_table, "usage: dump_sub_interface_table") \
10802 _(dump_ipv4_table, "usage: dump_ipv4_table") \
10803 _(dump_ipv6_table, "usage: dump_ipv6_table") \
10804 _(dump_stats_table, "usage: dump_stats_table") \
10805 _(dump_macro_table, "usage: dump_macro_table ") \
10806 _(dump_node_table, "usage: dump_node_table") \
10807 _(echo, "usage: echo <message>") \
10808 _(exec, "usage: exec <vpe-debug-CLI-command>") \
10809 _(help, "usage: help") \
10810 _(q, "usage: quit") \
10811 _(quit, "usage: quit") \
10812 _(search_node_table, "usage: search_node_table <name>...") \
10813 _(set, "usage: set <variable-name> <value>") \
10814 _(script, "usage: script <file-name>") \
10815 _(unset, "usage: unset <variable-name>")
10818 static void vl_api_##n##_t_handler_uni \
10819 (vl_api_##n##_t * mp) \
10821 vat_main_t * vam = &vat_main; \
10822 if (vam->json_output) { \
10823 vl_api_##n##_t_handler_json(mp); \
10825 vl_api_##n##_t_handler(mp); \
10828 foreach_vpe_api_reply_msg;
10831 void vat_api_hookup (vat_main_t *vam)
10834 vl_msg_api_set_handlers(VL_API_##N, #n, \
10835 vl_api_##n##_t_handler_uni, \
10837 vl_api_##n##_t_endian, \
10838 vl_api_##n##_t_print, \
10839 sizeof(vl_api_##n##_t), 1);
10840 foreach_vpe_api_reply_msg;
10843 vl_msg_api_set_first_available_msg_id (VL_MSG_FIRST_AVAILABLE);
10845 vam->sw_if_index_by_interface_name =
10846 hash_create_string (0, sizeof (uword));
10848 vam->function_by_name =
10849 hash_create_string (0, sizeof(uword));
10851 vam->help_by_name =
10852 hash_create_string (0, sizeof(uword));
10854 /* API messages we can send */
10855 #define _(n,h) hash_set_mem (vam->function_by_name, #n, api_##n);
10856 foreach_vpe_api_msg;
10860 #define _(n,h) hash_set_mem (vam->help_by_name, #n, h);
10861 foreach_vpe_api_msg;
10864 /* CLI functions */
10865 #define _(n,h) hash_set_mem (vam->function_by_name, #n, n);
10866 foreach_cli_function;
10870 #define _(n,h) hash_set_mem (vam->help_by_name, #n, h);
10871 foreach_cli_function;
10875 #undef vl_api_version
10876 #define vl_api_version(n,v) static u32 vpe_api_version = v;
10877 #include <api/vpe.api.h>
10878 #undef vl_api_version
10880 void vl_client_add_api_signatures (vl_api_memclnt_create_t *mp)
10883 * Send the main API signature in slot 0. This bit of code must
10884 * match the checks in ../vpe/api/api.c: vl_msg_api_version_check().
10886 mp->api_versions[0] = clib_host_to_net_u32 (vpe_api_version);