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);
2117 vl_api_lisp_gpe_enable_disable_status_details_t_handler
2118 (vl_api_lisp_gpe_enable_disable_status_details_t *mp)
2120 vat_main_t *vam = &vat_main;
2122 fformat(vam->ofp, "%=20s\n",
2123 mp->is_en ? "enable" : "disable");
2127 vl_api_lisp_gpe_enable_disable_status_details_t_handler_json
2128 (vl_api_lisp_gpe_enable_disable_status_details_t *mp)
2130 vat_main_t *vam = &vat_main;
2131 vat_json_node_t *node = NULL;
2134 str = format(0, "%s", mp->is_en ? "enable" : "disable");
2136 if (VAT_JSON_ARRAY != vam->json_tree.type) {
2137 ASSERT(VAT_JSON_NONE == vam->json_tree.type);
2138 vat_json_init_array(&vam->json_tree);
2140 node = vat_json_array_add(&vam->json_tree);
2142 vat_json_init_object(node);
2143 vat_json_object_add_string_copy(node, "lisp_gpe", str);
2146 #define vl_api_vnet_ip4_fib_counters_t_endian vl_noop_handler
2147 #define vl_api_vnet_ip4_fib_counters_t_print vl_noop_handler
2148 #define vl_api_vnet_ip6_fib_counters_t_endian vl_noop_handler
2149 #define vl_api_vnet_ip6_fib_counters_t_print vl_noop_handler
2152 * Generate boilerplate reply handlers, which
2153 * dig the return value out of the xxx_reply_t API message,
2154 * stick it into vam->retval, and set vam->result_ready
2156 * Could also do this by pointing N message decode slots at
2157 * a single function, but that could break in subtle ways.
2160 #define foreach_standard_reply_retval_handler \
2161 _(sw_interface_set_flags_reply) \
2162 _(sw_interface_add_del_address_reply) \
2163 _(sw_interface_set_table_reply) \
2164 _(sw_interface_set_vpath_reply) \
2165 _(sw_interface_set_l2_bridge_reply) \
2166 _(bridge_domain_add_del_reply) \
2167 _(sw_interface_set_l2_xconnect_reply) \
2168 _(l2fib_add_del_reply) \
2169 _(ip_add_del_route_reply) \
2170 _(proxy_arp_add_del_reply) \
2171 _(proxy_arp_intfc_enable_disable_reply) \
2172 _(mpls_add_del_encap_reply) \
2173 _(mpls_add_del_decap_reply) \
2174 _(mpls_ethernet_add_del_tunnel_2_reply) \
2175 _(sw_interface_set_unnumbered_reply) \
2176 _(ip_neighbor_add_del_reply) \
2177 _(reset_vrf_reply) \
2178 _(oam_add_del_reply) \
2179 _(reset_fib_reply) \
2180 _(dhcp_proxy_config_reply) \
2181 _(dhcp_proxy_config_2_reply) \
2182 _(dhcp_proxy_set_vss_reply) \
2183 _(dhcp_client_config_reply) \
2184 _(set_ip_flow_hash_reply) \
2185 _(sw_interface_ip6_enable_disable_reply) \
2186 _(sw_interface_ip6_set_link_local_address_reply) \
2187 _(sw_interface_ip6nd_ra_prefix_reply) \
2188 _(sw_interface_ip6nd_ra_config_reply) \
2189 _(set_arp_neighbor_limit_reply) \
2190 _(l2_patch_add_del_reply) \
2191 _(sr_tunnel_add_del_reply) \
2192 _(sr_policy_add_del_reply) \
2193 _(sr_multicast_map_add_del_reply) \
2194 _(classify_add_del_session_reply) \
2195 _(classify_set_interface_ip_table_reply) \
2196 _(classify_set_interface_l2_tables_reply) \
2197 _(l2tpv3_set_tunnel_cookies_reply) \
2198 _(l2tpv3_interface_enable_disable_reply) \
2199 _(l2tpv3_set_lookup_key_reply) \
2200 _(l2_fib_clear_table_reply) \
2201 _(l2_interface_efp_filter_reply) \
2202 _(l2_interface_vlan_tag_rewrite_reply) \
2203 _(modify_vhost_user_if_reply) \
2204 _(delete_vhost_user_if_reply) \
2205 _(want_ip4_arp_events_reply) \
2206 _(input_acl_set_interface_reply) \
2207 _(ipsec_spd_add_del_reply) \
2208 _(ipsec_interface_add_del_spd_reply) \
2209 _(ipsec_spd_add_del_entry_reply) \
2210 _(ipsec_sad_add_del_entry_reply) \
2211 _(ipsec_sa_set_key_reply) \
2212 _(ikev2_profile_add_del_reply) \
2213 _(ikev2_profile_set_auth_reply) \
2214 _(ikev2_profile_set_id_reply) \
2215 _(ikev2_profile_set_ts_reply) \
2216 _(ikev2_set_local_key_reply) \
2217 _(delete_loopback_reply) \
2218 _(bd_ip_mac_add_del_reply) \
2219 _(map_del_domain_reply) \
2220 _(map_add_del_rule_reply) \
2221 _(want_interface_events_reply) \
2222 _(want_stats_reply) \
2223 _(cop_interface_enable_disable_reply) \
2224 _(cop_whitelist_enable_disable_reply) \
2225 _(sw_interface_clear_stats_reply) \
2226 _(trace_profile_add_reply) \
2227 _(trace_profile_apply_reply) \
2228 _(trace_profile_del_reply) \
2229 _(lisp_add_del_locator_set_reply) \
2230 _(lisp_add_del_locator_reply) \
2231 _(lisp_add_del_local_eid_reply) \
2232 _(lisp_gpe_add_del_fwd_entry_reply) \
2233 _(lisp_add_del_map_resolver_reply) \
2234 _(lisp_gpe_enable_disable_reply) \
2235 _(lisp_gpe_add_del_iface_reply)
2238 static void vl_api_##n##_t_handler \
2239 (vl_api_##n##_t * mp) \
2241 vat_main_t * vam = &vat_main; \
2242 i32 retval = ntohl(mp->retval); \
2243 if (vam->async_mode) { \
2244 vam->async_errors += (retval < 0); \
2246 vam->retval = retval; \
2247 vam->result_ready = 1; \
2250 foreach_standard_reply_retval_handler;
2254 static void vl_api_##n##_t_handler_json \
2255 (vl_api_##n##_t * mp) \
2257 vat_main_t * vam = &vat_main; \
2258 vat_json_node_t node; \
2259 vat_json_init_object(&node); \
2260 vat_json_object_add_int(&node, "retval", ntohl(mp->retval)); \
2261 vat_json_print(vam->ofp, &node); \
2262 vam->retval = ntohl(mp->retval); \
2263 vam->result_ready = 1; \
2265 foreach_standard_reply_retval_handler;
2269 * Table of message reply handlers, must include boilerplate handlers
2273 #define foreach_vpe_api_reply_msg \
2274 _(CREATE_LOOPBACK_REPLY, create_loopback_reply) \
2275 _(SW_INTERFACE_DETAILS, sw_interface_details) \
2276 _(SW_INTERFACE_SET_FLAGS, sw_interface_set_flags) \
2277 _(SW_INTERFACE_SET_FLAGS_REPLY, sw_interface_set_flags_reply) \
2278 _(CONTROL_PING_REPLY, control_ping_reply) \
2279 _(CLI_REPLY, cli_reply) \
2280 _(SW_INTERFACE_ADD_DEL_ADDRESS_REPLY, \
2281 sw_interface_add_del_address_reply) \
2282 _(SW_INTERFACE_SET_TABLE_REPLY, sw_interface_set_table_reply) \
2283 _(SW_INTERFACE_SET_VPATH_REPLY, sw_interface_set_vpath_reply) \
2284 _(SW_INTERFACE_SET_L2_XCONNECT_REPLY, \
2285 sw_interface_set_l2_xconnect_reply) \
2286 _(SW_INTERFACE_SET_L2_BRIDGE_REPLY, \
2287 sw_interface_set_l2_bridge_reply) \
2288 _(BRIDGE_DOMAIN_ADD_DEL_REPLY, bridge_domain_add_del_reply) \
2289 _(BRIDGE_DOMAIN_DETAILS, bridge_domain_details) \
2290 _(BRIDGE_DOMAIN_SW_IF_DETAILS, bridge_domain_sw_if_details) \
2291 _(L2FIB_ADD_DEL_REPLY, l2fib_add_del_reply) \
2292 _(L2_FLAGS_REPLY, l2_flags_reply) \
2293 _(BRIDGE_FLAGS_REPLY, bridge_flags_reply) \
2294 _(TAP_CONNECT_REPLY, tap_connect_reply) \
2295 _(TAP_MODIFY_REPLY, tap_modify_reply) \
2296 _(TAP_DELETE_REPLY, tap_delete_reply) \
2297 _(SW_INTERFACE_TAP_DETAILS, sw_interface_tap_details) \
2298 _(IP_ADD_DEL_ROUTE_REPLY, ip_add_del_route_reply) \
2299 _(PROXY_ARP_ADD_DEL_REPLY, proxy_arp_add_del_reply) \
2300 _(PROXY_ARP_INTFC_ENABLE_DISABLE_REPLY, \
2301 proxy_arp_intfc_enable_disable_reply) \
2302 _(MPLS_ADD_DEL_ENCAP_REPLY, mpls_add_del_encap_reply) \
2303 _(MPLS_ADD_DEL_DECAP_REPLY, mpls_add_del_decap_reply) \
2304 _(MPLS_GRE_ADD_DEL_TUNNEL_REPLY, mpls_gre_add_del_tunnel_reply) \
2305 _(MPLS_ETHERNET_ADD_DEL_TUNNEL_REPLY, \
2306 mpls_ethernet_add_del_tunnel_reply) \
2307 _(MPLS_ETHERNET_ADD_DEL_TUNNEL_2_REPLY, \
2308 mpls_ethernet_add_del_tunnel_2_reply) \
2309 _(SW_INTERFACE_SET_UNNUMBERED_REPLY, \
2310 sw_interface_set_unnumbered_reply) \
2311 _(IP_NEIGHBOR_ADD_DEL_REPLY, ip_neighbor_add_del_reply) \
2312 _(RESET_VRF_REPLY, reset_vrf_reply) \
2313 _(CREATE_VLAN_SUBIF_REPLY, create_vlan_subif_reply) \
2314 _(CREATE_SUBIF_REPLY, create_subif_reply) \
2315 _(OAM_ADD_DEL_REPLY, oam_add_del_reply) \
2316 _(RESET_FIB_REPLY, reset_fib_reply) \
2317 _(DHCP_PROXY_CONFIG_REPLY, dhcp_proxy_config_reply) \
2318 _(DHCP_PROXY_CONFIG_2_REPLY, dhcp_proxy_config_2_reply) \
2319 _(DHCP_PROXY_SET_VSS_REPLY, dhcp_proxy_set_vss_reply) \
2320 _(DHCP_CLIENT_CONFIG_REPLY, dhcp_client_config_reply) \
2321 _(SET_IP_FLOW_HASH_REPLY, set_ip_flow_hash_reply) \
2322 _(SW_INTERFACE_IP6_ENABLE_DISABLE_REPLY, \
2323 sw_interface_ip6_enable_disable_reply) \
2324 _(SW_INTERFACE_IP6_SET_LINK_LOCAL_ADDRESS_REPLY, \
2325 sw_interface_ip6_set_link_local_address_reply) \
2326 _(SW_INTERFACE_IP6ND_RA_PREFIX_REPLY, \
2327 sw_interface_ip6nd_ra_prefix_reply) \
2328 _(SW_INTERFACE_IP6ND_RA_CONFIG_REPLY, \
2329 sw_interface_ip6nd_ra_config_reply) \
2330 _(SET_ARP_NEIGHBOR_LIMIT_REPLY, set_arp_neighbor_limit_reply) \
2331 _(L2_PATCH_ADD_DEL_REPLY, l2_patch_add_del_reply) \
2332 _(SR_TUNNEL_ADD_DEL_REPLY, sr_tunnel_add_del_reply) \
2333 _(SR_POLICY_ADD_DEL_REPLY, sr_policy_add_del_reply) \
2334 _(SR_MULTICAST_MAP_ADD_DEL_REPLY, sr_multicast_map_add_del_reply) \
2335 _(CLASSIFY_ADD_DEL_TABLE_REPLY, classify_add_del_table_reply) \
2336 _(CLASSIFY_ADD_DEL_SESSION_REPLY, classify_add_del_session_reply) \
2337 _(CLASSIFY_SET_INTERFACE_IP_TABLE_REPLY, \
2338 classify_set_interface_ip_table_reply) \
2339 _(CLASSIFY_SET_INTERFACE_L2_TABLES_REPLY, \
2340 classify_set_interface_l2_tables_reply) \
2341 _(GET_NODE_INDEX_REPLY, get_node_index_reply) \
2342 _(ADD_NODE_NEXT_REPLY, add_node_next_reply) \
2343 _(L2TPV3_CREATE_TUNNEL_REPLY, l2tpv3_create_tunnel_reply) \
2344 _(L2TPV3_SET_TUNNEL_COOKIES_REPLY, l2tpv3_set_tunnel_cookies_reply) \
2345 _(L2TPV3_INTERFACE_ENABLE_DISABLE_REPLY, \
2346 l2tpv3_interface_enable_disable_reply) \
2347 _(L2TPV3_SET_LOOKUP_KEY_REPLY, l2tpv3_set_lookup_key_reply) \
2348 _(SW_IF_L2TPV3_TUNNEL_DETAILS, sw_if_l2tpv3_tunnel_details) \
2349 _(VXLAN_ADD_DEL_TUNNEL_REPLY, vxlan_add_del_tunnel_reply) \
2350 _(VXLAN_TUNNEL_DETAILS, vxlan_tunnel_details) \
2351 _(GRE_ADD_DEL_TUNNEL_REPLY, gre_add_del_tunnel_reply) \
2352 _(GRE_TUNNEL_DETAILS, gre_tunnel_details) \
2353 _(L2_FIB_CLEAR_TABLE_REPLY, l2_fib_clear_table_reply) \
2354 _(L2_INTERFACE_EFP_FILTER_REPLY, l2_interface_efp_filter_reply) \
2355 _(L2_INTERFACE_VLAN_TAG_REWRITE_REPLY, l2_interface_vlan_tag_rewrite_reply) \
2356 _(SW_INTERFACE_VHOST_USER_DETAILS, sw_interface_vhost_user_details) \
2357 _(CREATE_VHOST_USER_IF_REPLY, create_vhost_user_if_reply) \
2358 _(MODIFY_VHOST_USER_IF_REPLY, modify_vhost_user_if_reply) \
2359 _(DELETE_VHOST_USER_IF_REPLY, delete_vhost_user_if_reply) \
2360 _(SHOW_VERSION_REPLY, show_version_reply) \
2361 _(NSH_GRE_ADD_DEL_TUNNEL_REPLY, nsh_gre_add_del_tunnel_reply) \
2362 _(L2_FIB_TABLE_ENTRY, l2_fib_table_entry) \
2363 _(NSH_VXLAN_GPE_ADD_DEL_TUNNEL_REPLY, nsh_vxlan_gpe_add_del_tunnel_reply) \
2364 _(LISP_GPE_ADD_DEL_TUNNEL_REPLY, lisp_gpe_add_del_tunnel_reply) \
2365 _(INTERFACE_NAME_RENUMBER_REPLY, interface_name_renumber_reply) \
2366 _(WANT_IP4_ARP_EVENTS_REPLY, want_ip4_arp_events_reply) \
2367 _(IP4_ARP_EVENT, ip4_arp_event) \
2368 _(INPUT_ACL_SET_INTERFACE_REPLY, input_acl_set_interface_reply) \
2369 _(IP_ADDRESS_DETAILS, ip_address_details) \
2370 _(IP_DETAILS, ip_details) \
2371 _(IPSEC_SPD_ADD_DEL_REPLY, ipsec_spd_add_del_reply) \
2372 _(IPSEC_INTERFACE_ADD_DEL_SPD_REPLY, ipsec_interface_add_del_spd_reply) \
2373 _(IPSEC_SPD_ADD_DEL_ENTRY_REPLY, ipsec_spd_add_del_entry_reply) \
2374 _(IPSEC_SAD_ADD_DEL_ENTRY_REPLY, ipsec_sad_add_del_entry_reply) \
2375 _(IPSEC_SA_SET_KEY_REPLY, ipsec_sa_set_key_reply) \
2376 _(IKEV2_PROFILE_ADD_DEL_REPLY, ikev2_profile_add_del_reply) \
2377 _(IKEV2_PROFILE_SET_AUTH_REPLY, ikev2_profile_set_auth_reply) \
2378 _(IKEV2_PROFILE_SET_ID_REPLY, ikev2_profile_set_id_reply) \
2379 _(IKEV2_PROFILE_SET_TS_REPLY, ikev2_profile_set_ts_reply) \
2380 _(IKEV2_SET_LOCAL_KEY_REPLY, ikev2_set_local_key_reply) \
2381 _(DELETE_LOOPBACK_REPLY, delete_loopback_reply) \
2382 _(BD_IP_MAC_ADD_DEL_REPLY, bd_ip_mac_add_del_reply) \
2383 _(DHCP_COMPL_EVENT, dhcp_compl_event) \
2384 _(VNET_INTERFACE_COUNTERS, vnet_interface_counters) \
2385 _(VNET_IP4_FIB_COUNTERS, vnet_ip4_fib_counters) \
2386 _(VNET_IP6_FIB_COUNTERS, vnet_ip6_fib_counters) \
2387 _(MAP_ADD_DOMAIN_REPLY, map_add_domain_reply) \
2388 _(MAP_DEL_DOMAIN_REPLY, map_del_domain_reply) \
2389 _(MAP_ADD_DEL_RULE_REPLY, map_add_del_rule_reply) \
2390 _(MAP_DOMAIN_DETAILS, map_domain_details) \
2391 _(MAP_RULE_DETAILS, map_rule_details) \
2392 _(WANT_INTERFACE_EVENTS_REPLY, want_interface_events_reply) \
2393 _(WANT_STATS_REPLY, want_stats_reply) \
2394 _(GET_FIRST_MSG_ID_REPLY, get_first_msg_id_reply) \
2395 _(COP_INTERFACE_ENABLE_DISABLE_REPLY, cop_interface_enable_disable_reply) \
2396 _(COP_WHITELIST_ENABLE_DISABLE_REPLY, cop_whitelist_enable_disable_reply) \
2397 _(GET_NODE_GRAPH_REPLY, get_node_graph_reply) \
2398 _(SW_INTERFACE_CLEAR_STATS_REPLY, sw_interface_clear_stats_reply) \
2399 _(TRACE_PROFILE_ADD_REPLY, trace_profile_add_reply) \
2400 _(TRACE_PROFILE_APPLY_REPLY, trace_profile_apply_reply) \
2401 _(TRACE_PROFILE_DEL_REPLY, trace_profile_del_reply) \
2402 _(LISP_ADD_DEL_LOCATOR_SET_REPLY, lisp_add_del_locator_set_reply) \
2403 _(LISP_ADD_DEL_LOCATOR_REPLY, lisp_add_del_locator_reply) \
2404 _(LISP_ADD_DEL_LOCAL_EID_REPLY, lisp_add_del_local_eid_reply) \
2405 _(LISP_GPE_ADD_DEL_FWD_ENTRY_REPLY, lisp_gpe_add_del_fwd_entry_reply) \
2406 _(LISP_ADD_DEL_MAP_RESOLVER_REPLY, lisp_add_del_map_resolver_reply) \
2407 _(LISP_GPE_ENABLE_DISABLE_REPLY, lisp_gpe_enable_disable_reply) \
2408 _(LISP_GPE_ADD_DEL_IFACE_REPLY, lisp_gpe_add_del_iface_reply) \
2409 _(LISP_LOCATOR_SET_DETAILS, lisp_locator_set_details) \
2410 _(LISP_LOCAL_EID_TABLE_DETAILS, lisp_local_eid_table_details) \
2411 _(LISP_GPE_TUNNEL_DETAILS, lisp_gpe_tunnel_details) \
2412 _(LISP_MAP_RESOLVER_DETAILS, lisp_map_resolver_details) \
2413 _(LISP_GPE_ENABLE_DISABLE_STATUS_DETAILS, \
2414 lisp_gpe_enable_disable_status_details)
2416 /* M: construct, but don't yet send a message */
2420 vam->result_ready = 0; \
2421 mp = vl_msg_api_alloc(sizeof(*mp)); \
2422 memset (mp, 0, sizeof (*mp)); \
2423 mp->_vl_msg_id = ntohs (VL_API_##T); \
2424 mp->client_index = vam->my_client_index; \
2429 vam->result_ready = 0; \
2430 mp = vl_msg_api_alloc(sizeof(*mp)+(n)); \
2431 memset (mp, 0, sizeof (*mp)); \
2432 mp->_vl_msg_id = ntohs (VL_API_##T); \
2433 mp->client_index = vam->my_client_index; \
2437 /* S: send a message */
2438 #define S (vl_msg_api_send_shmem (vam->vl_input_queue, (u8 *)&mp))
2440 /* W: wait for results, with timeout */
2443 timeout = vat_time_now (vam) + 1.0; \
2445 while (vat_time_now (vam) < timeout) { \
2446 if (vam->result_ready == 1) { \
2447 return (vam->retval); \
2459 #define STR_VTR_OP_CASE(op) \
2460 case L2_VTR_ ## op: \
2463 static const char *str_vtr_op(u32 vtr_op)
2466 STR_VTR_OP_CASE(DISABLED);
2467 STR_VTR_OP_CASE(PUSH_1);
2468 STR_VTR_OP_CASE(PUSH_2);
2469 STR_VTR_OP_CASE(POP_1);
2470 STR_VTR_OP_CASE(POP_2);
2471 STR_VTR_OP_CASE(TRANSLATE_1_1);
2472 STR_VTR_OP_CASE(TRANSLATE_1_2);
2473 STR_VTR_OP_CASE(TRANSLATE_2_1);
2474 STR_VTR_OP_CASE(TRANSLATE_2_2);
2480 static int dump_sub_interface_table (vat_main_t * vam)
2482 const sw_interface_subif_t * sub = NULL;
2484 if (vam->json_output) {
2485 clib_warning ("JSON output supported only for VPE API calls and dump_stats_table");
2490 "%-30s%-12s%-11s%-7s%-5s%-9s%-9s%-6s%-8s%-10s%-10s\n",
2491 "Interface", "sw_if_index",
2492 "sub id", "dot1ad", "tags", "outer id",
2493 "inner id", "exact", "default",
2494 "outer any", "inner any");
2496 vec_foreach (sub, vam->sw_if_subif_table) {
2498 "%-30s%-12d%-11d%-7s%-5d%-9d%-9d%-6d%-8d%-10d%-10d\n",
2499 sub->interface_name,
2501 sub->sub_id, sub->sub_dot1ad ? "dot1ad" : "dot1q",
2502 sub->sub_number_of_tags, sub->sub_outer_vlan_id,
2503 sub->sub_inner_vlan_id, sub->sub_exact_match, sub->sub_default,
2504 sub->sub_outer_vlan_id_any, sub->sub_inner_vlan_id_any);
2505 if (sub->vtr_op != L2_VTR_DISABLED) {
2507 " vlan-tag-rewrite - op: %-14s [ dot1q: %d "
2508 "tag1: %d tag2: %d ]\n",
2509 str_vtr_op(sub->vtr_op), sub->vtr_push_dot1q,
2510 sub->vtr_tag1, sub->vtr_tag2);
2517 static int name_sort_cmp (void * a1, void * a2)
2519 name_sort_t * n1 = a1;
2520 name_sort_t * n2 = a2;
2522 return strcmp ((char *)n1->name, (char *)n2->name);
2525 static int dump_interface_table (vat_main_t * vam)
2528 name_sort_t * nses = 0, * ns;
2530 if (vam->json_output) {
2531 clib_warning ("JSON output supported only for VPE API calls and dump_stats_table");
2535 hash_foreach_pair (p, vam->sw_if_index_by_interface_name,
2537 vec_add2 (nses, ns, 1);
2538 ns->name = (u8 *)(p->key);
2539 ns->value = (u32) p->value[0];
2542 vec_sort_with_function (nses, name_sort_cmp);
2544 fformat (vam->ofp, "%-25s%-15s\n", "Interface", "sw_if_index");
2545 vec_foreach (ns, nses) {
2546 fformat (vam->ofp, "%-25s%-15d\n", ns->name, ns->value);
2552 static int dump_ip_table (vat_main_t * vam, int is_ipv6)
2554 const ip_details_t * det = NULL;
2555 const ip_address_details_t * address = NULL;
2566 vec_foreach (det, vam->ip_details_by_sw_if_index[is_ipv6]) {
2568 if (!det->present) {
2576 "Address", "Prefix length");
2580 vec_foreach (address, det->addr) {
2583 is_ipv6 ? format_ip6_address : format_ip4_address,
2585 address->prefix_length);
2592 static int dump_ipv4_table (vat_main_t * vam)
2594 if (vam->json_output) {
2595 clib_warning ("JSON output supported only for VPE API calls and dump_stats_table");
2599 return dump_ip_table (vam, 0);
2602 static int dump_ipv6_table (vat_main_t * vam)
2604 if (vam->json_output) {
2605 clib_warning ("JSON output supported only for VPE API calls and dump_stats_table");
2609 return dump_ip_table (vam, 1);
2612 static char* counter_type_to_str (u8 counter_type, u8 is_combined)
2615 switch(counter_type) {
2616 case VNET_INTERFACE_COUNTER_DROP:
2618 case VNET_INTERFACE_COUNTER_PUNT:
2620 case VNET_INTERFACE_COUNTER_IP4:
2622 case VNET_INTERFACE_COUNTER_IP6:
2624 case VNET_INTERFACE_COUNTER_RX_NO_BUF:
2626 case VNET_INTERFACE_COUNTER_RX_MISS:
2628 case VNET_INTERFACE_COUNTER_RX_ERROR:
2630 case VNET_INTERFACE_COUNTER_TX_ERROR:
2633 return "INVALID-COUNTER-TYPE";
2636 switch(counter_type) {
2637 case VNET_INTERFACE_COUNTER_RX:
2639 case VNET_INTERFACE_COUNTER_TX:
2642 return "INVALID-COUNTER-TYPE";
2647 static int dump_stats_table (vat_main_t * vam)
2649 vat_json_node_t node;
2650 vat_json_node_t *msg_array;
2651 vat_json_node_t *msg;
2652 vat_json_node_t *counter_array;
2653 vat_json_node_t *counter;
2654 interface_counter_t c;
2656 ip4_fib_counter_t *c4;
2657 ip6_fib_counter_t *c6;
2660 if (!vam->json_output) {
2661 clib_warning ("dump_stats_table supported only in JSON format");
2665 vat_json_init_object(&node);
2667 /* interface counters */
2668 msg_array = vat_json_object_add(&node, "interface_counters");
2669 vat_json_init_array(msg_array);
2670 for (i = 0; i < vec_len(vam->simple_interface_counters); i++) {
2671 msg = vat_json_array_add(msg_array);
2672 vat_json_init_object(msg);
2673 vat_json_object_add_string_copy(msg, "vnet_counter_type",
2674 (u8*)counter_type_to_str(i, 0));
2675 vat_json_object_add_int(msg, "is_combined", 0);
2676 counter_array = vat_json_object_add(msg, "data");
2677 vat_json_init_array(counter_array);
2678 for (j = 0; j < vec_len(vam->simple_interface_counters[i]); j++) {
2679 packets = vam->simple_interface_counters[i][j];
2680 vat_json_array_add_uint(counter_array, packets);
2683 for (i = 0; i < vec_len(vam->combined_interface_counters); i++) {
2684 msg = vat_json_array_add(msg_array);
2685 vat_json_init_object(msg);
2686 vat_json_object_add_string_copy(msg, "vnet_counter_type",
2687 (u8*)counter_type_to_str(i, 1));
2688 vat_json_object_add_int(msg, "is_combined", 1);
2689 counter_array = vat_json_object_add(msg, "data");
2690 vat_json_init_array(counter_array);
2691 for (j = 0; j < vec_len(vam->combined_interface_counters[i]); j++) {
2692 c = vam->combined_interface_counters[i][j];
2693 counter = vat_json_array_add(counter_array);
2694 vat_json_init_object(counter);
2695 vat_json_object_add_uint(counter, "packets", c.packets);
2696 vat_json_object_add_uint(counter, "bytes", c.bytes);
2700 /* ip4 fib counters */
2701 msg_array = vat_json_object_add(&node, "ip4_fib_counters");
2702 vat_json_init_array(msg_array);
2703 for (i = 0; i < vec_len(vam->ip4_fib_counters); i++) {
2704 msg = vat_json_array_add(msg_array);
2705 vat_json_init_object(msg);
2706 vat_json_object_add_uint(msg, "vrf_id", vam->ip4_fib_counters_vrf_id_by_index[i]);
2707 counter_array = vat_json_object_add(msg, "c");
2708 vat_json_init_array(counter_array);
2709 for (j = 0; j < vec_len(vam->ip4_fib_counters[i]); j++) {
2710 counter = vat_json_array_add(counter_array);
2711 vat_json_init_object(counter);
2712 c4 = &vam->ip4_fib_counters[i][j];
2713 vat_json_object_add_ip4(counter, "address", c4->address);
2714 vat_json_object_add_uint(counter, "address_length", c4->address_length);
2715 vat_json_object_add_uint(counter, "packets", c4->packets);
2716 vat_json_object_add_uint(counter, "bytes", c4->bytes);
2720 /* ip6 fib counters */
2721 msg_array = vat_json_object_add(&node, "ip6_fib_counters");
2722 vat_json_init_array(msg_array);
2723 for (i = 0; i < vec_len(vam->ip6_fib_counters); i++) {
2724 msg = vat_json_array_add(msg_array);
2725 vat_json_init_object(msg);
2726 vat_json_object_add_uint(msg, "vrf_id", vam->ip6_fib_counters_vrf_id_by_index[i]);
2727 counter_array = vat_json_object_add(msg, "c");
2728 vat_json_init_array(counter_array);
2729 for (j = 0; j < vec_len(vam->ip6_fib_counters[i]); j++) {
2730 counter = vat_json_array_add(counter_array);
2731 vat_json_init_object(counter);
2732 c6 = &vam->ip6_fib_counters[i][j];
2733 vat_json_object_add_ip6(counter, "address", c6->address);
2734 vat_json_object_add_uint(counter, "address_length", c6->address_length);
2735 vat_json_object_add_uint(counter, "packets", c6->packets);
2736 vat_json_object_add_uint(counter, "bytes", c6->bytes);
2740 vat_json_print(vam->ofp, &node);
2741 vat_json_free(&node);
2746 int exec (vat_main_t * vam)
2748 api_main_t * am = &api_main;
2749 vl_api_cli_request_t *mp;
2753 unformat_input_t * i = vam->input;
2755 if (vec_len(i->buffer) == 0)
2758 if (vam->exec_mode == 0 && unformat (i, "mode")) {
2762 if (vam->exec_mode == 1 &&
2763 (unformat (i, "exit") || unformat (i, "quit"))) {
2769 M(CLI_REQUEST, cli_request);
2772 * Copy cmd into shared memory.
2773 * In order for the CLI command to work, it
2774 * must be a vector ending in \n, not a C-string ending
2777 pthread_mutex_lock (&am->vlib_rp->mutex);
2778 oldheap = svm_push_data_heap (am->vlib_rp);
2780 vec_validate (cmd, vec_len(vam->input->buffer)-1);
2781 clib_memcpy (cmd, vam->input->buffer, vec_len(vam->input->buffer));
2783 svm_pop_heap (oldheap);
2784 pthread_mutex_unlock (&am->vlib_rp->mutex);
2786 mp->cmd_in_shmem = (u64) cmd;
2788 timeout = vat_time_now (vam) + 10.0;
2790 while (vat_time_now (vam) < timeout) {
2791 if (vam->result_ready == 1) {
2793 if (vam->shmem_result != NULL)
2794 fformat (vam->ofp, "%s", vam->shmem_result);
2795 pthread_mutex_lock (&am->vlib_rp->mutex);
2796 oldheap = svm_push_data_heap (am->vlib_rp);
2798 free_me = (u8 *)vam->shmem_result;
2801 svm_pop_heap (oldheap);
2802 pthread_mutex_unlock (&am->vlib_rp->mutex);
2809 static int api_create_loopback (vat_main_t * vam)
2811 unformat_input_t * i = vam->input;
2812 vl_api_create_loopback_t *mp;
2817 memset (mac_address, 0, sizeof (mac_address));
2819 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
2821 if (unformat (i, "mac %U", unformat_ethernet_address, mac_address))
2827 /* Construct the API message */
2828 M(CREATE_LOOPBACK, create_loopback);
2830 clib_memcpy (mp->mac_address, mac_address, sizeof (mac_address));
2835 static int api_delete_loopback (vat_main_t * vam)
2837 unformat_input_t * i = vam->input;
2838 vl_api_delete_loopback_t *mp;
2840 u32 sw_if_index = ~0;
2842 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
2844 if (unformat (i, "sw_if_index %d", &sw_if_index))
2850 if (sw_if_index == ~0)
2852 errmsg ("missing sw_if_index\n");
2856 /* Construct the API message */
2857 M(DELETE_LOOPBACK, delete_loopback);
2858 mp->sw_if_index = ntohl (sw_if_index);
2863 static int api_want_stats (vat_main_t * vam)
2865 unformat_input_t * i = vam->input;
2866 vl_api_want_stats_t * mp;
2870 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
2872 if (unformat (i, "enable"))
2874 else if (unformat (i, "disable"))
2882 errmsg ("missing enable|disable\n");
2886 M(WANT_STATS, want_stats);
2887 mp->enable_disable = enable;
2892 static int api_want_interface_events (vat_main_t * vam)
2894 unformat_input_t * i = vam->input;
2895 vl_api_want_interface_events_t * mp;
2899 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
2901 if (unformat (i, "enable"))
2903 else if (unformat (i, "disable"))
2911 errmsg ("missing enable|disable\n");
2915 M(WANT_INTERFACE_EVENTS, want_interface_events);
2916 mp->enable_disable = enable;
2918 vam->interface_event_display = enable;
2924 /* Note: non-static, called once to set up the initial intfc table */
2925 int api_sw_interface_dump (vat_main_t * vam)
2927 vl_api_sw_interface_dump_t *mp;
2930 name_sort_t * nses = 0, * ns;
2931 sw_interface_subif_t * sub = NULL;
2933 /* Toss the old name table */
2934 hash_foreach_pair (p, vam->sw_if_index_by_interface_name,
2936 vec_add2 (nses, ns, 1);
2937 ns->name = (u8 *)(p->key);
2938 ns->value = (u32) p->value[0];
2941 hash_free (vam->sw_if_index_by_interface_name);
2943 vec_foreach (ns, nses)
2944 vec_free (ns->name);
2948 vec_foreach (sub, vam->sw_if_subif_table) {
2949 vec_free (sub->interface_name);
2951 vec_free (vam->sw_if_subif_table);
2953 /* recreate the interface name hash table */
2954 vam->sw_if_index_by_interface_name
2955 = hash_create_string (0, sizeof(uword));
2957 /* Get list of ethernets */
2958 M(SW_INTERFACE_DUMP, sw_interface_dump);
2959 mp->name_filter_valid = 1;
2960 strncpy ((char *) mp->name_filter, "Ether", sizeof(mp->name_filter)-1);
2963 /* and local / loopback interfaces */
2964 M(SW_INTERFACE_DUMP, sw_interface_dump);
2965 mp->name_filter_valid = 1;
2966 strncpy ((char *) mp->name_filter, "lo", sizeof(mp->name_filter)-1);
2969 /* and vxlan tunnel interfaces */
2970 M(SW_INTERFACE_DUMP, sw_interface_dump);
2971 mp->name_filter_valid = 1;
2972 strncpy ((char *) mp->name_filter, "vxlan", sizeof(mp->name_filter)-1);
2975 /* and host (af_packet) interfaces */
2976 M(SW_INTERFACE_DUMP, sw_interface_dump);
2977 mp->name_filter_valid = 1;
2978 strncpy ((char *) mp->name_filter, "host", sizeof(mp->name_filter)-1);
2981 /* and l2tpv3 tunnel interfaces */
2982 M(SW_INTERFACE_DUMP, sw_interface_dump);
2983 mp->name_filter_valid = 1;
2984 strncpy ((char *) mp->name_filter, "l2tpv3_tunnel", sizeof(mp->name_filter)-1);
2987 /* Use a control ping for synchronization */
2989 vl_api_control_ping_t * mp;
2990 M(CONTROL_PING, control_ping);
2996 static int api_sw_interface_set_flags (vat_main_t * vam)
2998 unformat_input_t * i = vam->input;
2999 vl_api_sw_interface_set_flags_t *mp;
3002 u8 sw_if_index_set = 0;
3003 u8 admin_up = 0, link_up = 0;
3005 /* Parse args required to build the message */
3006 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
3007 if (unformat (i, "admin-up"))
3009 else if (unformat (i, "admin-down"))
3011 else if (unformat (i, "link-up"))
3013 else if (unformat (i, "link-down"))
3015 else if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
3016 sw_if_index_set = 1;
3017 else if (unformat (i, "sw_if_index %d", &sw_if_index))
3018 sw_if_index_set = 1;
3023 if (sw_if_index_set == 0) {
3024 errmsg ("missing interface name or sw_if_index\n");
3028 /* Construct the API message */
3029 M(SW_INTERFACE_SET_FLAGS, sw_interface_set_flags);
3030 mp->sw_if_index = ntohl (sw_if_index);
3031 mp->admin_up_down = admin_up;
3032 mp->link_up_down = link_up;
3037 /* Wait for a reply, return the good/bad news... */
3041 static int api_sw_interface_clear_stats (vat_main_t * vam)
3043 unformat_input_t * i = vam->input;
3044 vl_api_sw_interface_clear_stats_t *mp;
3047 u8 sw_if_index_set = 0;
3049 /* Parse args required to build the message */
3050 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
3051 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
3052 sw_if_index_set = 1;
3053 else if (unformat (i, "sw_if_index %d", &sw_if_index))
3054 sw_if_index_set = 1;
3059 /* Construct the API message */
3060 M(SW_INTERFACE_CLEAR_STATS, sw_interface_clear_stats);
3062 if (sw_if_index_set == 1)
3063 mp->sw_if_index = ntohl (sw_if_index);
3065 mp->sw_if_index = ~0;
3070 /* Wait for a reply, return the good/bad news... */
3074 static int api_sw_interface_add_del_address (vat_main_t * vam)
3076 unformat_input_t * i = vam->input;
3077 vl_api_sw_interface_add_del_address_t *mp;
3080 u8 sw_if_index_set = 0;
3081 u8 is_add = 1, del_all = 0;
3082 u32 address_length = 0;
3083 u8 v4_address_set = 0;
3084 u8 v6_address_set = 0;
3085 ip4_address_t v4address;
3086 ip6_address_t v6address;
3088 /* Parse args required to build the message */
3089 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
3090 if (unformat (i, "del-all"))
3092 else if (unformat (i, "del"))
3094 else if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
3095 sw_if_index_set = 1;
3096 else if (unformat (i, "sw_if_index %d", &sw_if_index))
3097 sw_if_index_set = 1;
3098 else if (unformat (i, "%U/%d",
3099 unformat_ip4_address, &v4address,
3102 else if (unformat (i, "%U/%d",
3103 unformat_ip6_address, &v6address,
3110 if (sw_if_index_set == 0) {
3111 errmsg ("missing interface name or sw_if_index\n");
3114 if (v4_address_set && v6_address_set) {
3115 errmsg ("both v4 and v6 addresses set\n");
3118 if (!v4_address_set && !v6_address_set && !del_all) {
3119 errmsg ("no addresses set\n");
3123 /* Construct the API message */
3124 M(SW_INTERFACE_ADD_DEL_ADDRESS, sw_interface_add_del_address);
3126 mp->sw_if_index = ntohl (sw_if_index);
3127 mp->is_add = is_add;
3128 mp->del_all = del_all;
3129 if (v6_address_set) {
3131 clib_memcpy (mp->address, &v6address, sizeof (v6address));
3133 clib_memcpy (mp->address, &v4address, sizeof (v4address));
3135 mp->address_length = address_length;
3140 /* Wait for a reply, return good/bad news */
3144 static int api_sw_interface_set_table (vat_main_t * vam)
3146 unformat_input_t * i = vam->input;
3147 vl_api_sw_interface_set_table_t *mp;
3149 u32 sw_if_index, vrf_id = 0;
3150 u8 sw_if_index_set = 0;
3153 /* Parse args required to build the message */
3154 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
3155 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
3156 sw_if_index_set = 1;
3157 else if (unformat (i, "sw_if_index %d", &sw_if_index))
3158 sw_if_index_set = 1;
3159 else if (unformat (i, "vrf %d", &vrf_id))
3161 else if (unformat (i, "ipv6"))
3167 if (sw_if_index_set == 0) {
3168 errmsg ("missing interface name or sw_if_index\n");
3172 /* Construct the API message */
3173 M(SW_INTERFACE_SET_TABLE, sw_interface_set_table);
3175 mp->sw_if_index = ntohl (sw_if_index);
3176 mp->is_ipv6 = is_ipv6;
3177 mp->vrf_id = ntohl (vrf_id);
3182 /* Wait for a reply... */
3186 static int api_sw_interface_set_vpath (vat_main_t * vam)
3188 unformat_input_t * i = vam->input;
3189 vl_api_sw_interface_set_vpath_t *mp;
3191 u32 sw_if_index = 0;
3192 u8 sw_if_index_set = 0;
3195 /* Parse args required to build the message */
3196 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
3197 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
3198 sw_if_index_set = 1;
3199 else if (unformat (i, "sw_if_index %d", &sw_if_index))
3200 sw_if_index_set = 1;
3201 else if (unformat (i, "enable"))
3203 else if (unformat (i, "disable"))
3209 if (sw_if_index_set == 0) {
3210 errmsg ("missing interface name or sw_if_index\n");
3214 /* Construct the API message */
3215 M(SW_INTERFACE_SET_VPATH, sw_interface_set_vpath);
3217 mp->sw_if_index = ntohl (sw_if_index);
3218 mp->enable = is_enable;
3223 /* Wait for a reply... */
3227 static int api_sw_interface_set_l2_xconnect (vat_main_t * vam)
3229 unformat_input_t * i = vam->input;
3230 vl_api_sw_interface_set_l2_xconnect_t *mp;
3233 u8 rx_sw_if_index_set = 0;
3235 u8 tx_sw_if_index_set = 0;
3238 /* Parse args required to build the message */
3239 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
3240 if (unformat (i, "rx_sw_if_index %d", &rx_sw_if_index))
3241 rx_sw_if_index_set = 1;
3242 else if (unformat (i, "tx_sw_if_index %d", &tx_sw_if_index))
3243 tx_sw_if_index_set = 1;
3244 else if (unformat (i, "rx")) {
3245 if (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
3246 if (unformat (i, "%U", unformat_sw_if_index, vam,
3248 rx_sw_if_index_set = 1;
3251 } else if (unformat (i, "tx")) {
3252 if (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
3253 if (unformat (i, "%U", unformat_sw_if_index, vam,
3255 tx_sw_if_index_set = 1;
3258 } else if (unformat (i, "enable"))
3260 else if (unformat (i, "disable"))
3266 if (rx_sw_if_index_set == 0) {
3267 errmsg ("missing rx interface name or rx_sw_if_index\n");
3271 if (enable && (tx_sw_if_index_set == 0)) {
3272 errmsg ("missing tx interface name or tx_sw_if_index\n");
3276 M(SW_INTERFACE_SET_L2_XCONNECT, sw_interface_set_l2_xconnect);
3278 mp->rx_sw_if_index = ntohl(rx_sw_if_index);
3279 mp->tx_sw_if_index = ntohl(tx_sw_if_index);
3280 mp->enable = enable;
3287 static int api_sw_interface_set_l2_bridge (vat_main_t * vam)
3289 unformat_input_t * i = vam->input;
3290 vl_api_sw_interface_set_l2_bridge_t *mp;
3293 u8 rx_sw_if_index_set = 0;
3300 /* Parse args required to build the message */
3301 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
3302 if (unformat (i, "sw_if_index %d", &rx_sw_if_index))
3303 rx_sw_if_index_set = 1;
3304 else if (unformat (i, "bd_id %d", &bd_id))
3306 else if (unformat (i, "%U", unformat_sw_if_index, vam,
3308 rx_sw_if_index_set = 1;
3309 else if (unformat (i, "shg %d", &shg))
3311 else if (unformat (i, "bvi"))
3313 else if (unformat (i, "enable"))
3315 else if (unformat (i, "disable"))
3321 if (rx_sw_if_index_set == 0) {
3322 errmsg ("missing rx interface name or sw_if_index\n");
3326 if (enable && (bd_id_set == 0)) {
3327 errmsg ("missing bridge domain\n");
3331 M(SW_INTERFACE_SET_L2_BRIDGE, sw_interface_set_l2_bridge);
3333 mp->rx_sw_if_index = ntohl(rx_sw_if_index);
3334 mp->bd_id = ntohl(bd_id);
3337 mp->enable = enable;
3344 static int api_bridge_domain_dump (vat_main_t * vam)
3346 unformat_input_t * i = vam->input;
3347 vl_api_bridge_domain_dump_t *mp;
3351 /* Parse args required to build the message */
3352 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
3353 if (unformat (i, "bd_id %d", &bd_id))
3359 M(BRIDGE_DOMAIN_DUMP, bridge_domain_dump);
3360 mp->bd_id = ntohl(bd_id);
3363 /* Use a control ping for synchronization */
3365 vl_api_control_ping_t * mp;
3366 M(CONTROL_PING, control_ping);
3375 static int api_bridge_domain_add_del (vat_main_t * vam)
3377 unformat_input_t * i = vam->input;
3378 vl_api_bridge_domain_add_del_t *mp;
3382 u32 flood = 1, forward = 1, learn = 1, uu_flood = 1, arp_term = 0;
3384 /* Parse args required to build the message */
3385 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
3386 if (unformat (i, "bd_id %d", &bd_id))
3388 else if (unformat (i, "flood %d", &flood))
3390 else if (unformat (i, "uu-flood %d", &uu_flood))
3392 else if (unformat (i, "forward %d", &forward))
3394 else if (unformat (i, "learn %d", &learn))
3396 else if (unformat (i, "arp-term %d", &arp_term))
3398 else if (unformat (i, "del")) {
3400 flood = uu_flood = forward = learn = 0;
3407 errmsg ("missing bridge domain\n");
3411 M(BRIDGE_DOMAIN_ADD_DEL, bridge_domain_add_del);
3413 mp->bd_id = ntohl(bd_id);
3415 mp->uu_flood = uu_flood;
3416 mp->forward = forward;
3418 mp->arp_term = arp_term;
3419 mp->is_add = is_add;
3426 static int api_l2fib_add_del (vat_main_t * vam)
3428 unformat_input_t * i = vam->input;
3429 vl_api_l2fib_add_del_t *mp;
3436 u8 sw_if_index_set = 0;
3441 /* Parse args required to build the message */
3442 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
3443 if (unformat (i, "mac %U", unformat_ethernet_address, &mac))
3445 else if (unformat (i, "bd_id %d", &bd_id))
3447 else if (unformat (i, "sw_if_index %d", &sw_if_index))
3448 sw_if_index_set = 1;
3449 else if (unformat (i, "sw_if")) {
3450 if (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
3451 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
3452 sw_if_index_set = 1;
3455 } else if (unformat (i, "static"))
3457 else if (unformat (i, "filter")) {
3460 } else if (unformat (i, "del"))
3467 errmsg ("missing mac address\n");
3471 if (bd_id_set == 0) {
3472 errmsg ("missing bridge domain\n");
3476 if (is_add && (sw_if_index_set == 0)) {
3477 errmsg ("missing interface name or sw_if_index\n");
3481 M(L2FIB_ADD_DEL, l2fib_add_del);
3484 mp->bd_id = ntohl(bd_id);
3485 mp->is_add = is_add;
3488 mp->sw_if_index = ntohl(sw_if_index);
3489 mp->static_mac = static_mac;
3490 mp->filter_mac = filter_mac;
3498 static int api_l2_flags (vat_main_t * vam)
3500 unformat_input_t * i = vam->input;
3501 vl_api_l2_flags_t *mp;
3504 u32 feature_bitmap = 0;
3505 u8 sw_if_index_set = 0;
3507 /* Parse args required to build the message */
3508 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
3509 if (unformat (i, "sw_if_index %d", &sw_if_index))
3510 sw_if_index_set = 1;
3511 else if (unformat (i, "sw_if")) {
3512 if (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
3513 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
3514 sw_if_index_set = 1;
3517 } else if (unformat (i, "learn"))
3518 feature_bitmap |= L2INPUT_FEAT_LEARN;
3519 else if (unformat (i, "forward"))
3520 feature_bitmap |= L2INPUT_FEAT_FWD;
3521 else if (unformat (i, "flood"))
3522 feature_bitmap |= L2INPUT_FEAT_FLOOD;
3523 else if (unformat (i, "uu-flood"))
3524 feature_bitmap |= L2INPUT_FEAT_UU_FLOOD;
3529 if (sw_if_index_set == 0) {
3530 errmsg ("missing interface name or sw_if_index\n");
3534 M(L2_FLAGS, l2_flags);
3536 mp->sw_if_index = ntohl(sw_if_index);
3537 mp->feature_bitmap = ntohl(feature_bitmap);
3544 static int api_bridge_flags (vat_main_t * vam)
3546 unformat_input_t * i = vam->input;
3547 vl_api_bridge_flags_t *mp;
3554 /* Parse args required to build the message */
3555 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
3556 if (unformat (i, "bd_id %d", &bd_id))
3558 else if (unformat (i, "learn"))
3560 else if (unformat (i, "forward"))
3562 else if (unformat (i, "flood"))
3564 else if (unformat (i, "uu-flood"))
3565 flags |= L2_UU_FLOOD;
3566 else if (unformat (i, "arp-term"))
3567 flags |= L2_ARP_TERM;
3568 else if (unformat (i, "off"))
3570 else if (unformat (i, "disable"))
3576 if (bd_id_set == 0) {
3577 errmsg ("missing bridge domain\n");
3581 M(BRIDGE_FLAGS, bridge_flags);
3583 mp->bd_id = ntohl(bd_id);
3584 mp->feature_bitmap = ntohl(flags);
3585 mp->is_set = is_set;
3592 static int api_bd_ip_mac_add_del (vat_main_t * vam)
3594 unformat_input_t * i = vam->input;
3595 vl_api_bd_ip_mac_add_del_t *mp;
3603 ip4_address_t v4addr;
3604 ip6_address_t v6addr;
3608 /* Parse args required to build the message */
3609 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
3610 if (unformat (i, "bd_id %d", &bd_id)) {
3612 } else if (unformat (i, "%U", unformat_ip4_address, &v4addr)) {
3614 } else if (unformat (i, "%U", unformat_ip6_address, &v6addr)) {
3617 } else if (unformat (i, "%U", unformat_ethernet_address, macaddr)) {
3619 } else if (unformat (i, "del"))
3625 if (bd_id_set == 0) {
3626 errmsg ("missing bridge domain\n");
3628 } else if (ip_set == 0) {
3629 errmsg ("missing IP address\n");
3631 } else if (mac_set == 0) {
3632 errmsg ("missing MAC address\n");
3636 M(BD_IP_MAC_ADD_DEL, bd_ip_mac_add_del);
3638 mp->bd_id = ntohl(bd_id);
3639 mp->is_ipv6 = is_ipv6;
3640 mp->is_add = is_add;
3642 clib_memcpy (mp->ip_address, &v6addr, sizeof (v6addr));
3643 else clib_memcpy (mp->ip_address, &v4addr, sizeof (v4addr));
3644 clib_memcpy (mp->mac_address, macaddr, 6);
3650 static int api_tap_connect (vat_main_t * vam)
3652 unformat_input_t * i = vam->input;
3653 vl_api_tap_connect_t *mp;
3660 memset (mac_address, 0, sizeof (mac_address));
3662 /* Parse args required to build the message */
3663 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
3664 if (unformat (i, "mac %U", unformat_ethernet_address, mac_address)) {
3667 else if (unformat (i, "random-mac"))
3669 else if (unformat (i, "tapname %s", &tap_name))
3675 if (name_set == 0) {
3676 errmsg ("missing tap name\n");
3679 if (vec_len (tap_name) > 63) {
3680 errmsg ("tap name too long\n");
3682 vec_add1 (tap_name, 0);
3684 /* Construct the API message */
3685 M(TAP_CONNECT, tap_connect);
3687 mp->use_random_mac = random_mac;
3688 clib_memcpy (mp->mac_address, mac_address, 6);
3689 clib_memcpy (mp->tap_name, tap_name, vec_len (tap_name));
3690 vec_free (tap_name);
3695 /* Wait for a reply... */
3699 static int api_tap_modify (vat_main_t * vam)
3701 unformat_input_t * i = vam->input;
3702 vl_api_tap_modify_t *mp;
3708 u32 sw_if_index = ~0;
3709 u8 sw_if_index_set = 0;
3711 memset (mac_address, 0, sizeof (mac_address));
3713 /* Parse args required to build the message */
3714 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
3715 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
3716 sw_if_index_set = 1;
3717 else if (unformat (i, "sw_if_index %d", &sw_if_index))
3718 sw_if_index_set = 1;
3719 else if (unformat (i, "mac %U", unformat_ethernet_address, mac_address)) {
3722 else if (unformat (i, "random-mac"))
3724 else if (unformat (i, "tapname %s", &tap_name))
3730 if (sw_if_index_set == 0) {
3731 errmsg ("missing vpp interface name");
3734 if (name_set == 0) {
3735 errmsg ("missing tap name\n");
3738 if (vec_len (tap_name) > 63) {
3739 errmsg ("tap name too long\n");
3741 vec_add1 (tap_name, 0);
3743 /* Construct the API message */
3744 M(TAP_MODIFY, tap_modify);
3746 mp->use_random_mac = random_mac;
3747 mp->sw_if_index = ntohl(sw_if_index);
3748 clib_memcpy (mp->mac_address, mac_address, 6);
3749 clib_memcpy (mp->tap_name, tap_name, vec_len (tap_name));
3750 vec_free (tap_name);
3755 /* Wait for a reply... */
3759 static int api_tap_delete (vat_main_t * vam)
3761 unformat_input_t * i = vam->input;
3762 vl_api_tap_delete_t *mp;
3764 u32 sw_if_index = ~0;
3765 u8 sw_if_index_set = 0;
3767 /* Parse args required to build the message */
3768 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
3769 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
3770 sw_if_index_set = 1;
3771 else if (unformat (i, "sw_if_index %d", &sw_if_index))
3772 sw_if_index_set = 1;
3777 if (sw_if_index_set == 0) {
3778 errmsg ("missing vpp interface name");
3782 /* Construct the API message */
3783 M(TAP_DELETE, tap_delete);
3785 mp->sw_if_index = ntohl(sw_if_index);
3790 /* Wait for a reply... */
3794 static int api_ip_add_del_route (vat_main_t * vam)
3796 unformat_input_t * i = vam->input;
3797 vl_api_ip_add_del_route_t *mp;
3799 u32 sw_if_index = 0, vrf_id = 0;
3800 u8 sw_if_index_set = 0;
3802 u8 is_local = 0, is_drop = 0;
3803 u8 create_vrf_if_needed = 0;
3805 u8 next_hop_weight = 1;
3807 u8 is_multipath = 0;
3809 u8 address_length_set = 0;
3810 u32 lookup_in_vrf = 0;
3811 u32 resolve_attempts = 0;
3812 u32 dst_address_length = 0;
3813 u8 next_hop_set = 0;
3814 ip4_address_t v4_dst_address, v4_next_hop_address;
3815 ip6_address_t v6_dst_address, v6_next_hop_address;
3819 u32 random_add_del = 0;
3820 u32 * random_vector = 0;
3821 uword * random_hash;
3822 u32 random_seed = 0xdeaddabe;
3823 u32 classify_table_index = ~0;
3826 /* Parse args required to build the message */
3827 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
3828 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
3829 sw_if_index_set = 1;
3830 else if (unformat (i, "sw_if_index %d", &sw_if_index))
3831 sw_if_index_set = 1;
3832 else if (unformat (i, "%U", unformat_ip4_address,
3837 else if (unformat (i, "%U", unformat_ip6_address, &v6_dst_address)) {
3841 else if (unformat (i, "/%d", &dst_address_length)) {
3842 address_length_set = 1;
3845 else if (is_ipv6 == 0 && unformat (i, "via %U", unformat_ip4_address,
3846 &v4_next_hop_address)) {
3849 else if (is_ipv6 == 1 && unformat (i, "via %U", unformat_ip6_address,
3850 &v6_next_hop_address)) {
3853 else if (unformat (i, "resolve-attempts %d", &resolve_attempts))
3855 else if (unformat (i, "weight %d", &next_hop_weight))
3857 else if (unformat (i, "drop")) {
3859 } else if (unformat (i, "local")) {
3861 } else if (unformat (i, "classify %d", &classify_table_index)) {
3863 } else if (unformat (i, "del"))
3865 else if (unformat (i, "add"))
3867 else if (unformat (i, "not-last"))
3869 else if (unformat (i, "multipath"))
3871 else if (unformat (i, "vrf %d", &vrf_id))
3873 else if (unformat (i, "create-vrf"))
3874 create_vrf_if_needed = 1;
3875 else if (unformat (i, "count %d", &count))
3877 else if (unformat (i, "lookup-in-vrf %d", &lookup_in_vrf))
3879 else if (unformat (i, "random"))
3881 else if (unformat (i, "seed %d", &random_seed))
3884 clib_warning ("parse error '%U'", format_unformat_error, i);
3889 if (resolve_attempts > 0 && sw_if_index_set == 0) {
3890 errmsg ("ARP resolution needs explicit interface or sw_if_index\n");
3894 if (!next_hop_set && !is_drop && !is_local && !is_classify) {
3895 errmsg ("next hop / local / drop / classify not set\n");
3899 if (address_set == 0) {
3900 errmsg ("missing addresses\n");
3904 if (address_length_set == 0) {
3905 errmsg ("missing address length\n");
3909 /* Generate a pile of unique, random routes */
3910 if (random_add_del) {
3911 u32 this_random_address;
3912 random_hash = hash_create (count, sizeof(uword));
3914 hash_set (random_hash, v4_next_hop_address.as_u32, 1);
3915 for (j = 0; j <= count; j++) {
3917 this_random_address = random_u32 (&random_seed);
3918 this_random_address =
3919 clib_host_to_net_u32 (this_random_address);
3920 } while (hash_get (random_hash, this_random_address));
3921 vec_add1 (random_vector, this_random_address);
3922 hash_set (random_hash, this_random_address, 1);
3924 hash_free (random_hash);
3925 v4_dst_address.as_u32 = random_vector[0];
3929 /* Turn on async mode */
3930 vam->async_mode = 1;
3931 vam->async_errors = 0;
3932 before = vat_time_now(vam);
3935 for (j = 0; j < count; j++) {
3936 /* Construct the API message */
3937 M(IP_ADD_DEL_ROUTE, ip_add_del_route);
3939 mp->next_hop_sw_if_index = ntohl (sw_if_index);
3940 mp->vrf_id = ntohl (vrf_id);
3941 if (resolve_attempts > 0) {
3942 mp->resolve_attempts = ntohl (resolve_attempts);
3943 mp->resolve_if_needed = 1;
3945 mp->create_vrf_if_needed = create_vrf_if_needed;
3947 mp->is_add = is_add;
3948 mp->is_drop = is_drop;
3949 mp->is_ipv6 = is_ipv6;
3950 mp->is_local = is_local;
3951 mp->is_classify = is_classify;
3952 mp->is_multipath = is_multipath;
3953 mp->not_last = not_last;
3954 mp->next_hop_weight = next_hop_weight;
3955 mp->dst_address_length = dst_address_length;
3956 mp->lookup_in_vrf = ntohl(lookup_in_vrf);
3957 mp->classify_table_index = ntohl(classify_table_index);
3960 clib_memcpy (mp->dst_address, &v6_dst_address, sizeof (v6_dst_address));
3962 clib_memcpy (mp->next_hop_address, &v6_next_hop_address,
3963 sizeof (v6_next_hop_address));
3964 increment_v6_address (&v6_dst_address);
3966 clib_memcpy (mp->dst_address, &v4_dst_address, sizeof (v4_dst_address));
3968 clib_memcpy (mp->next_hop_address, &v4_next_hop_address,
3969 sizeof (v4_next_hop_address));
3971 v4_dst_address.as_u32 = random_vector[j+1];
3973 increment_v4_address (&v4_dst_address);
3979 /* When testing multiple add/del ops, use a control-ping to sync */
3981 vl_api_control_ping_t * mp;
3984 /* Shut off async mode */
3985 vam->async_mode = 0;
3987 M(CONTROL_PING, control_ping);
3990 timeout = vat_time_now(vam) + 1.0;
3991 while (vat_time_now (vam) < timeout)
3992 if (vam->result_ready == 1)
3997 if (vam->retval == -99)
3998 errmsg ("timeout\n");
4000 if (vam->async_errors > 0) {
4001 errmsg ("%d asynchronous errors\n", vam->async_errors);
4004 vam->async_errors = 0;
4005 after = vat_time_now(vam);
4007 fformat(vam->ofp, "%d routes in %.6f secs, %.2f routes/sec\n",
4008 count, after - before, count / (after - before));
4010 /* Wait for a reply... */
4014 /* Return the good/bad news */
4015 return (vam->retval);
4018 static int api_proxy_arp_add_del (vat_main_t * vam)
4020 unformat_input_t * i = vam->input;
4021 vl_api_proxy_arp_add_del_t *mp;
4025 ip4_address_t lo, hi;
4028 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
4029 if (unformat (i, "vrf %d", &vrf_id))
4031 else if (unformat (i, "%U - %U", unformat_ip4_address, &lo,
4032 unformat_ip4_address, &hi))
4034 else if (unformat (i, "del"))
4037 clib_warning ("parse error '%U'", format_unformat_error, i);
4042 if (range_set == 0) {
4043 errmsg ("address range not set\n");
4047 M(PROXY_ARP_ADD_DEL, proxy_arp_add_del);
4049 mp->vrf_id = ntohl(vrf_id);
4050 mp->is_add = is_add;
4051 clib_memcpy(mp->low_address, &lo, sizeof (mp->low_address));
4052 clib_memcpy(mp->hi_address, &hi, sizeof (mp->hi_address));
4059 static int api_proxy_arp_intfc_enable_disable (vat_main_t * vam)
4061 unformat_input_t * i = vam->input;
4062 vl_api_proxy_arp_intfc_enable_disable_t *mp;
4066 u8 sw_if_index_set = 0;
4068 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
4069 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
4070 sw_if_index_set = 1;
4071 else if (unformat (i, "sw_if_index %d", &sw_if_index))
4072 sw_if_index_set = 1;
4073 else if (unformat (i, "enable"))
4075 else if (unformat (i, "disable"))
4078 clib_warning ("parse error '%U'", format_unformat_error, i);
4083 if (sw_if_index_set == 0) {
4084 errmsg ("missing interface name or sw_if_index\n");
4088 M(PROXY_ARP_INTFC_ENABLE_DISABLE, proxy_arp_intfc_enable_disable);
4090 mp->sw_if_index = ntohl(sw_if_index);
4091 mp->enable_disable = enable;
4098 static int api_mpls_add_del_decap (vat_main_t * vam)
4100 unformat_input_t * i = vam->input;
4101 vl_api_mpls_add_del_decap_t *mp;
4110 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
4111 if (unformat (i, "rx_vrf_id %d", &rx_vrf_id))
4113 else if (unformat (i, "tx_vrf_id %d", &tx_vrf_id))
4115 else if (unformat (i, "label %d", &label))
4117 else if (unformat (i, "next-index %d", &next_index))
4119 else if (unformat (i, "del"))
4121 else if (unformat (i, "s-bit-clear"))
4124 clib_warning ("parse error '%U'", format_unformat_error, i);
4129 M(MPLS_ADD_DEL_DECAP, mpls_add_del_decap);
4131 mp->rx_vrf_id = ntohl(rx_vrf_id);
4132 mp->tx_vrf_id = ntohl(tx_vrf_id);
4133 mp->label = ntohl(label);
4134 mp->next_index = ntohl(next_index);
4136 mp->is_add = is_add;
4143 static int api_mpls_add_del_encap (vat_main_t * vam)
4145 unformat_input_t * i = vam->input;
4146 vl_api_mpls_add_del_encap_t *mp;
4151 ip4_address_t dst_address;
4154 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
4155 if (unformat (i, "vrf %d", &vrf_id))
4157 else if (unformat (i, "label %d", &label))
4158 vec_add1 (labels, ntohl(label));
4159 else if (unformat (i, "dst %U", unformat_ip4_address, &dst_address))
4161 else if (unformat (i, "del"))
4164 clib_warning ("parse error '%U'", format_unformat_error, i);
4169 if (vec_len (labels) == 0) {
4170 errmsg ("missing encap label stack\n");
4174 M2(MPLS_ADD_DEL_ENCAP, mpls_add_del_encap,
4175 sizeof (u32) * vec_len (labels));
4177 mp->vrf_id = ntohl(vrf_id);
4178 clib_memcpy(mp->dst_address, &dst_address, sizeof (dst_address));
4179 mp->is_add = is_add;
4180 mp->nlabels = vec_len (labels);
4181 clib_memcpy(mp->labels, labels, sizeof(u32)*mp->nlabels);
4190 static int api_mpls_gre_add_del_tunnel (vat_main_t * vam)
4192 unformat_input_t * i = vam->input;
4193 vl_api_mpls_gre_add_del_tunnel_t *mp;
4195 u32 inner_vrf_id = 0;
4196 u32 outer_vrf_id = 0;
4197 ip4_address_t src_address;
4198 ip4_address_t dst_address;
4199 ip4_address_t intfc_address;
4201 u8 intfc_address_length = 0;
4205 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
4206 if (unformat (i, "inner_vrf_id %d", &inner_vrf_id))
4208 else if (unformat (i, "outer_vrf_id %d", &outer_vrf_id))
4210 else if (unformat (i, "src %U", unformat_ip4_address, &src_address))
4212 else if (unformat (i, "dst %U", unformat_ip4_address, &dst_address))
4214 else if (unformat (i, "adj %U/%d", unformat_ip4_address,
4215 &intfc_address, &tmp))
4216 intfc_address_length = tmp;
4217 else if (unformat (i, "l2-only"))
4219 else if (unformat (i, "del"))
4222 clib_warning ("parse error '%U'", format_unformat_error, i);
4227 M(MPLS_GRE_ADD_DEL_TUNNEL, mpls_gre_add_del_tunnel);
4229 mp->inner_vrf_id = ntohl(inner_vrf_id);
4230 mp->outer_vrf_id = ntohl(outer_vrf_id);
4231 clib_memcpy(mp->src_address, &src_address, sizeof (src_address));
4232 clib_memcpy(mp->dst_address, &dst_address, sizeof (dst_address));
4233 clib_memcpy(mp->intfc_address, &intfc_address, sizeof (intfc_address));
4234 mp->intfc_address_length = intfc_address_length;
4235 mp->l2_only = l2_only;
4236 mp->is_add = is_add;
4243 static int api_mpls_ethernet_add_del_tunnel (vat_main_t * vam)
4245 unformat_input_t * i = vam->input;
4246 vl_api_mpls_ethernet_add_del_tunnel_t *mp;
4248 u32 inner_vrf_id = 0;
4249 ip4_address_t intfc_address;
4250 u8 dst_mac_address[6];
4253 u8 intfc_address_length = 0;
4257 int tx_sw_if_index_set = 0;
4259 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
4260 if (unformat (i, "vrf %d", &inner_vrf_id))
4262 else if (unformat (i, "adj %U/%d", unformat_ip4_address,
4263 &intfc_address, &tmp))
4264 intfc_address_length = tmp;
4265 else if (unformat (i, "%U",
4266 unformat_sw_if_index, vam, &tx_sw_if_index))
4267 tx_sw_if_index_set = 1;
4268 else if (unformat (i, "tx_sw_if_index %d", &tx_sw_if_index))
4269 tx_sw_if_index_set = 1;
4270 else if (unformat (i, "dst %U", unformat_ethernet_address,
4273 else if (unformat (i, "l2-only"))
4275 else if (unformat (i, "del"))
4278 clib_warning ("parse error '%U'", format_unformat_error, i);
4284 errmsg ("dst (mac address) not set\n");
4287 if (!tx_sw_if_index_set) {
4288 errmsg ("tx-intfc not set\n");
4292 M(MPLS_ETHERNET_ADD_DEL_TUNNEL, mpls_ethernet_add_del_tunnel);
4294 mp->vrf_id = ntohl(inner_vrf_id);
4295 clib_memcpy (mp->adj_address, &intfc_address, sizeof (intfc_address));
4296 mp->adj_address_length = intfc_address_length;
4297 clib_memcpy (mp->dst_mac_address, dst_mac_address, sizeof (dst_mac_address));
4298 mp->tx_sw_if_index = ntohl(tx_sw_if_index);
4299 mp->l2_only = l2_only;
4300 mp->is_add = is_add;
4307 static int api_mpls_ethernet_add_del_tunnel_2 (vat_main_t * vam)
4309 unformat_input_t * i = vam->input;
4310 vl_api_mpls_ethernet_add_del_tunnel_2_t *mp;
4312 u32 inner_vrf_id = 0;
4313 u32 outer_vrf_id = 0;
4314 ip4_address_t adj_address;
4315 int adj_address_set = 0;
4316 ip4_address_t next_hop_address;
4317 int next_hop_address_set = 0;
4319 u8 adj_address_length = 0;
4322 u32 resolve_attempts = 5;
4323 u8 resolve_if_needed = 1;
4325 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
4326 if (unformat (i, "inner_vrf_id %d", &inner_vrf_id))
4328 else if (unformat (i, "outer_vrf_id %d", &outer_vrf_id))
4330 else if (unformat (i, "adj %U/%d", unformat_ip4_address,
4331 &adj_address, &tmp)) {
4332 adj_address_length = tmp;
4333 adj_address_set = 1;
4335 else if (unformat (i, "next-hop %U", unformat_ip4_address,
4337 next_hop_address_set = 1;
4338 else if (unformat (i, "resolve-attempts %d", &resolve_attempts))
4340 else if (unformat (i, "resolve-if-needed %d", &tmp))
4341 resolve_if_needed = tmp;
4342 else if (unformat (i, "l2-only"))
4344 else if (unformat (i, "del"))
4347 clib_warning ("parse error '%U'", format_unformat_error, i);
4352 if (!adj_address_set) {
4353 errmsg ("adjacency address/mask not set\n");
4356 if (!next_hop_address_set) {
4357 errmsg ("ip4 next hop address (in outer fib) not set\n");
4361 M(MPLS_ETHERNET_ADD_DEL_TUNNEL_2, mpls_ethernet_add_del_tunnel_2);
4363 mp->inner_vrf_id = ntohl(inner_vrf_id);
4364 mp->outer_vrf_id = ntohl(outer_vrf_id);
4365 mp->resolve_attempts = ntohl(resolve_attempts);
4366 mp->resolve_if_needed = resolve_if_needed;
4367 mp->is_add = is_add;
4368 mp->l2_only = l2_only;
4369 clib_memcpy (mp->adj_address, &adj_address, sizeof (adj_address));
4370 mp->adj_address_length = adj_address_length;
4371 clib_memcpy (mp->next_hop_ip4_address_in_outer_vrf, &next_hop_address,
4372 sizeof (next_hop_address));
4379 static int api_sw_interface_set_unnumbered (vat_main_t * vam)
4381 unformat_input_t * i = vam->input;
4382 vl_api_sw_interface_set_unnumbered_t *mp;
4387 u8 sw_if_index_set = 0;
4389 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
4390 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
4391 sw_if_index_set = 1;
4392 else if (unformat (i, "sw_if_index %d", &sw_if_index))
4393 sw_if_index_set = 1;
4394 else if (unformat (i, "unnum_if_index %d", &unnum_sw_index))
4396 else if (unformat (i, "del"))
4399 clib_warning ("parse error '%U'", format_unformat_error, i);
4404 if (sw_if_index_set == 0) {
4405 errmsg ("missing interface name or sw_if_index\n");
4409 M(SW_INTERFACE_SET_UNNUMBERED, sw_interface_set_unnumbered);
4411 mp->sw_if_index = ntohl(sw_if_index);
4412 mp->unnumbered_sw_if_index = ntohl(unnum_sw_index);
4413 mp->is_add = is_add;
4420 static int api_ip_neighbor_add_del (vat_main_t * vam)
4422 unformat_input_t * i = vam->input;
4423 vl_api_ip_neighbor_add_del_t *mp;
4426 u8 sw_if_index_set = 0;
4432 u8 v4_address_set = 0;
4433 u8 v6_address_set = 0;
4434 ip4_address_t v4address;
4435 ip6_address_t v6address;
4437 memset (mac_address, 0, sizeof (mac_address));
4439 /* Parse args required to build the message */
4440 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
4441 if (unformat (i, "mac %U", unformat_ethernet_address, mac_address)) {
4444 else if (unformat (i, "del"))
4446 else if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
4447 sw_if_index_set = 1;
4448 else if (unformat (i, "sw_if_index %d", &sw_if_index))
4449 sw_if_index_set = 1;
4450 else if (unformat (i, "is_static"))
4452 else if (unformat (i, "vrf %d", &vrf_id))
4454 else if (unformat (i, "dst %U",
4455 unformat_ip4_address, &v4address))
4457 else if (unformat (i, "dst %U",
4458 unformat_ip6_address, &v6address))
4461 clib_warning ("parse error '%U'", format_unformat_error, i);
4466 if (sw_if_index_set == 0) {
4467 errmsg ("missing interface name or sw_if_index\n");
4470 if (v4_address_set && v6_address_set) {
4471 errmsg ("both v4 and v6 addresses set\n");
4474 if (!v4_address_set && !v6_address_set) {
4475 errmsg ("no addresses set\n");
4479 /* Construct the API message */
4480 M(IP_NEIGHBOR_ADD_DEL, ip_neighbor_add_del);
4482 mp->sw_if_index = ntohl (sw_if_index);
4483 mp->is_add = is_add;
4484 mp->vrf_id = ntohl (vrf_id);
4485 mp->is_static = is_static;
4487 clib_memcpy (mp->mac_address, mac_address, 6);
4488 if (v6_address_set) {
4490 clib_memcpy (mp->dst_address, &v6address, sizeof (v6address));
4492 /* mp->is_ipv6 = 0; via memset in M macro above */
4493 clib_memcpy (mp->dst_address, &v4address, sizeof (v4address));
4499 /* Wait for a reply, return good/bad news */
4506 static int api_reset_vrf (vat_main_t * vam)
4508 unformat_input_t * i = vam->input;
4509 vl_api_reset_vrf_t *mp;
4515 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
4516 if (unformat (i, "vrf %d", &vrf_id))
4518 else if (unformat (i, "ipv6"))
4521 clib_warning ("parse error '%U'", format_unformat_error, i);
4526 if (vrf_id_set == 0) {
4527 errmsg ("missing vrf id\n");
4531 M(RESET_VRF, reset_vrf);
4533 mp->vrf_id = ntohl(vrf_id);
4534 mp->is_ipv6 = is_ipv6;
4541 static int api_create_vlan_subif (vat_main_t * vam)
4543 unformat_input_t * i = vam->input;
4544 vl_api_create_vlan_subif_t *mp;
4547 u8 sw_if_index_set = 0;
4551 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
4552 if (unformat (i, "sw_if_index %d", &sw_if_index))
4553 sw_if_index_set = 1;
4554 else if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
4555 sw_if_index_set = 1;
4556 else if (unformat (i, "vlan %d", &vlan_id))
4559 clib_warning ("parse error '%U'", format_unformat_error, i);
4564 if (sw_if_index_set == 0) {
4565 errmsg ("missing interface name or sw_if_index\n");
4569 if (vlan_id_set == 0) {
4570 errmsg ("missing vlan_id\n");
4573 M(CREATE_VLAN_SUBIF, create_vlan_subif);
4575 mp->sw_if_index = ntohl(sw_if_index);
4576 mp->vlan_id = ntohl(vlan_id);
4583 #define foreach_create_subif_bit \
4590 _(outer_vlan_id_any) \
4591 _(inner_vlan_id_any)
4593 static int api_create_subif (vat_main_t * vam)
4595 unformat_input_t * i = vam->input;
4596 vl_api_create_subif_t *mp;
4599 u8 sw_if_index_set = 0;
4606 u32 exact_match = 0;
4607 u32 default_sub = 0;
4608 u32 outer_vlan_id_any = 0;
4609 u32 inner_vlan_id_any = 0;
4611 u16 outer_vlan_id = 0;
4612 u16 inner_vlan_id = 0;
4614 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
4615 if (unformat (i, "sw_if_index %d", &sw_if_index))
4616 sw_if_index_set = 1;
4617 else if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
4618 sw_if_index_set = 1;
4619 else if (unformat (i, "sub_id %d", &sub_id))
4621 else if (unformat (i, "outer_vlan_id %d", &tmp))
4622 outer_vlan_id = tmp;
4623 else if (unformat (i, "inner_vlan_id %d", &tmp))
4624 inner_vlan_id = tmp;
4626 #define _(a) else if (unformat (i, #a)) a = 1 ;
4627 foreach_create_subif_bit
4631 clib_warning ("parse error '%U'", format_unformat_error, i);
4636 if (sw_if_index_set == 0) {
4637 errmsg ("missing interface name or sw_if_index\n");
4641 if (sub_id_set == 0) {
4642 errmsg ("missing sub_id\n");
4645 M(CREATE_SUBIF, create_subif);
4647 mp->sw_if_index = ntohl(sw_if_index);
4648 mp->sub_id = ntohl(sub_id);
4650 #define _(a) mp->a = a;
4651 foreach_create_subif_bit;
4654 mp->outer_vlan_id = ntohs (outer_vlan_id);
4655 mp->inner_vlan_id = ntohs (inner_vlan_id);
4662 static int api_oam_add_del (vat_main_t * vam)
4664 unformat_input_t * i = vam->input;
4665 vl_api_oam_add_del_t *mp;
4669 ip4_address_t src, dst;
4673 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
4674 if (unformat (i, "vrf %d", &vrf_id))
4676 else if (unformat (i, "src %U", unformat_ip4_address, &src))
4678 else if (unformat (i, "dst %U", unformat_ip4_address, &dst))
4680 else if (unformat (i, "del"))
4683 clib_warning ("parse error '%U'", format_unformat_error, i);
4689 errmsg ("missing src addr\n");
4694 errmsg ("missing dst addr\n");
4698 M(OAM_ADD_DEL, oam_add_del);
4700 mp->vrf_id = ntohl(vrf_id);
4701 mp->is_add = is_add;
4702 clib_memcpy(mp->src_address, &src, sizeof (mp->src_address));
4703 clib_memcpy(mp->dst_address, &dst, sizeof (mp->dst_address));
4710 static int api_reset_fib (vat_main_t * vam)
4712 unformat_input_t * i = vam->input;
4713 vl_api_reset_fib_t *mp;
4719 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
4720 if (unformat (i, "vrf %d", &vrf_id))
4722 else if (unformat (i, "ipv6"))
4725 clib_warning ("parse error '%U'", format_unformat_error, i);
4730 if (vrf_id_set == 0) {
4731 errmsg ("missing vrf id\n");
4735 M(RESET_FIB, reset_fib);
4737 mp->vrf_id = ntohl(vrf_id);
4738 mp->is_ipv6 = is_ipv6;
4745 static int api_dhcp_proxy_config (vat_main_t * vam)
4747 unformat_input_t * i = vam->input;
4748 vl_api_dhcp_proxy_config_t *mp;
4753 u8 v4_address_set = 0;
4754 u8 v6_address_set = 0;
4755 ip4_address_t v4address;
4756 ip6_address_t v6address;
4757 u8 v4_src_address_set = 0;
4758 u8 v6_src_address_set = 0;
4759 ip4_address_t v4srcaddress;
4760 ip6_address_t v6srcaddress;
4762 /* Parse args required to build the message */
4763 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
4764 if (unformat (i, "del"))
4766 else if (unformat (i, "vrf %d", &vrf_id))
4768 else if (unformat (i, "insert-cid %d", &insert_cid))
4770 else if (unformat (i, "svr %U",
4771 unformat_ip4_address, &v4address))
4773 else if (unformat (i, "svr %U",
4774 unformat_ip6_address, &v6address))
4776 else if (unformat (i, "src %U",
4777 unformat_ip4_address, &v4srcaddress))
4778 v4_src_address_set = 1;
4779 else if (unformat (i, "src %U",
4780 unformat_ip6_address, &v6srcaddress))
4781 v6_src_address_set = 1;
4786 if (v4_address_set && v6_address_set) {
4787 errmsg ("both v4 and v6 server addresses set\n");
4790 if (!v4_address_set && !v6_address_set) {
4791 errmsg ("no server addresses set\n");
4795 if (v4_src_address_set && v6_src_address_set) {
4796 errmsg ("both v4 and v6 src addresses set\n");
4799 if (!v4_src_address_set && !v6_src_address_set) {
4800 errmsg ("no src addresses set\n");
4804 if (!(v4_src_address_set && v4_address_set) &&
4805 !(v6_src_address_set && v6_address_set)) {
4806 errmsg ("no matching server and src addresses set\n");
4810 /* Construct the API message */
4811 M(DHCP_PROXY_CONFIG, dhcp_proxy_config);
4813 mp->insert_circuit_id = insert_cid;
4814 mp->is_add = is_add;
4815 mp->vrf_id = ntohl (vrf_id);
4816 if (v6_address_set) {
4818 clib_memcpy (mp->dhcp_server, &v6address, sizeof (v6address));
4819 clib_memcpy (mp->dhcp_src_address, &v6srcaddress, sizeof (v6address));
4821 clib_memcpy (mp->dhcp_server, &v4address, sizeof (v4address));
4822 clib_memcpy (mp->dhcp_src_address, &v4srcaddress, sizeof (v4address));
4828 /* Wait for a reply, return good/bad news */
4834 static int api_dhcp_proxy_config_2 (vat_main_t * vam)
4836 unformat_input_t * i = vam->input;
4837 vl_api_dhcp_proxy_config_2_t *mp;
4840 u32 server_vrf_id = 0;
4843 u8 v4_address_set = 0;
4844 u8 v6_address_set = 0;
4845 ip4_address_t v4address;
4846 ip6_address_t v6address;
4847 u8 v4_src_address_set = 0;
4848 u8 v6_src_address_set = 0;
4849 ip4_address_t v4srcaddress;
4850 ip6_address_t v6srcaddress;
4852 /* Parse args required to build the message */
4853 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
4854 if (unformat (i, "del"))
4856 else if (unformat (i, "rx_vrf_id %d", &rx_vrf_id))
4858 else if (unformat (i, "server_vrf_id %d", &server_vrf_id))
4860 else if (unformat (i, "insert-cid %d", &insert_cid))
4862 else if (unformat (i, "svr %U",
4863 unformat_ip4_address, &v4address))
4865 else if (unformat (i, "svr %U",
4866 unformat_ip6_address, &v6address))
4868 else if (unformat (i, "src %U",
4869 unformat_ip4_address, &v4srcaddress))
4870 v4_src_address_set = 1;
4871 else if (unformat (i, "src %U",
4872 unformat_ip6_address, &v6srcaddress))
4873 v6_src_address_set = 1;
4878 if (v4_address_set && v6_address_set) {
4879 errmsg ("both v4 and v6 server addresses set\n");
4882 if (!v4_address_set && !v6_address_set) {
4883 errmsg ("no server addresses set\n");
4887 if (v4_src_address_set && v6_src_address_set) {
4888 errmsg ("both v4 and v6 src addresses set\n");
4891 if (!v4_src_address_set && !v6_src_address_set) {
4892 errmsg ("no src addresses set\n");
4896 if (!(v4_src_address_set && v4_address_set) &&
4897 !(v6_src_address_set && v6_address_set)) {
4898 errmsg ("no matching server and src addresses set\n");
4902 /* Construct the API message */
4903 M(DHCP_PROXY_CONFIG_2, dhcp_proxy_config_2);
4905 mp->insert_circuit_id = insert_cid;
4906 mp->is_add = is_add;
4907 mp->rx_vrf_id = ntohl (rx_vrf_id);
4908 mp->server_vrf_id = ntohl (server_vrf_id);
4909 if (v6_address_set) {
4911 clib_memcpy (mp->dhcp_server, &v6address, sizeof (v6address));
4912 clib_memcpy (mp->dhcp_src_address, &v6srcaddress, sizeof (v6address));
4914 clib_memcpy (mp->dhcp_server, &v4address, sizeof (v4address));
4915 clib_memcpy (mp->dhcp_src_address, &v4srcaddress, sizeof (v4address));
4921 /* Wait for a reply, return good/bad news */
4927 static int api_dhcp_proxy_set_vss (vat_main_t * vam)
4929 unformat_input_t * i = vam->input;
4930 vl_api_dhcp_proxy_set_vss_t *mp;
4941 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
4942 if (unformat (i, "tbl_id %d", &tbl_id))
4944 if (unformat (i, "fib_id %d", &fib_id))
4946 if (unformat (i, "oui %d", &oui))
4948 else if (unformat (i, "ipv6"))
4950 else if (unformat (i, "del"))
4953 clib_warning ("parse error '%U'", format_unformat_error, i);
4958 if (tbl_id_set == 0) {
4959 errmsg ("missing tbl id\n");
4963 if (fib_id_set == 0) {
4964 errmsg ("missing fib id\n");
4968 errmsg ("missing oui\n");
4972 M(DHCP_PROXY_SET_VSS, dhcp_proxy_set_vss);
4973 mp->tbl_id = ntohl(tbl_id);
4974 mp->fib_id = ntohl(fib_id);
4975 mp->oui = ntohl(oui);
4976 mp->is_ipv6 = is_ipv6;
4977 mp->is_add = is_add;
4984 static int api_dhcp_client_config (vat_main_t * vam)
4986 unformat_input_t * i = vam->input;
4987 vl_api_dhcp_client_config_t *mp;
4990 u8 sw_if_index_set = 0;
4993 u8 disable_event = 0;
4995 /* Parse args required to build the message */
4996 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
4997 if (unformat (i, "del"))
4999 else if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
5000 sw_if_index_set = 1;
5001 else if (unformat (i, "sw_if_index %d", &sw_if_index))
5002 sw_if_index_set = 1;
5003 else if (unformat (i, "hostname %s", &hostname))
5005 else if (unformat (i, "disable_event"))
5011 if (sw_if_index_set == 0) {
5012 errmsg ("missing interface name or sw_if_index\n");
5016 if (vec_len (hostname) > 63) {
5017 errmsg ("hostname too long\n");
5019 vec_add1 (hostname, 0);
5021 /* Construct the API message */
5022 M(DHCP_CLIENT_CONFIG, dhcp_client_config);
5024 mp->sw_if_index = ntohl (sw_if_index);
5025 clib_memcpy (mp->hostname, hostname, vec_len (hostname));
5026 vec_free (hostname);
5027 mp->is_add = is_add;
5028 mp->want_dhcp_event = disable_event ? 0 : 1;
5034 /* Wait for a reply, return good/bad news */
5040 static int api_set_ip_flow_hash (vat_main_t * vam)
5042 unformat_input_t * i = vam->input;
5043 vl_api_set_ip_flow_hash_t *mp;
5055 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
5056 if (unformat (i, "vrf %d", &vrf_id))
5058 else if (unformat (i, "ipv6"))
5060 else if (unformat (i, "src"))
5062 else if (unformat (i, "dst"))
5064 else if (unformat (i, "sport"))
5066 else if (unformat (i, "dport"))
5068 else if (unformat (i, "proto"))
5070 else if (unformat (i, "reverse"))
5074 clib_warning ("parse error '%U'", format_unformat_error, i);
5079 if (vrf_id_set == 0) {
5080 errmsg ("missing vrf id\n");
5084 M(SET_IP_FLOW_HASH, set_ip_flow_hash);
5090 mp->reverse = reverse;
5091 mp->vrf_id = ntohl(vrf_id);
5092 mp->is_ipv6 = is_ipv6;
5099 static int api_sw_interface_ip6_enable_disable (vat_main_t * vam)
5101 unformat_input_t * i = vam->input;
5102 vl_api_sw_interface_ip6_enable_disable_t *mp;
5105 u8 sw_if_index_set = 0;
5108 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
5109 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
5110 sw_if_index_set = 1;
5111 else if (unformat (i, "sw_if_index %d", &sw_if_index))
5112 sw_if_index_set = 1;
5113 else if (unformat (i, "enable"))
5115 else if (unformat (i, "disable"))
5118 clib_warning ("parse error '%U'", format_unformat_error, i);
5123 if (sw_if_index_set == 0) {
5124 errmsg ("missing interface name or sw_if_index\n");
5128 M(SW_INTERFACE_IP6_ENABLE_DISABLE, sw_interface_ip6_enable_disable);
5130 mp->sw_if_index = ntohl(sw_if_index);
5131 mp->enable = enable;
5138 static int api_sw_interface_ip6_set_link_local_address (vat_main_t * vam)
5140 unformat_input_t * i = vam->input;
5141 vl_api_sw_interface_ip6_set_link_local_address_t *mp;
5144 u8 sw_if_index_set = 0;
5145 u32 address_length = 0;
5146 u8 v6_address_set = 0;
5147 ip6_address_t v6address;
5149 /* Parse args required to build the message */
5150 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
5151 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
5152 sw_if_index_set = 1;
5153 else if (unformat (i, "sw_if_index %d", &sw_if_index))
5154 sw_if_index_set = 1;
5155 else if (unformat (i, "%U/%d",
5156 unformat_ip6_address, &v6address,
5163 if (sw_if_index_set == 0) {
5164 errmsg ("missing interface name or sw_if_index\n");
5167 if (!v6_address_set) {
5168 errmsg ("no address set\n");
5172 /* Construct the API message */
5173 M(SW_INTERFACE_IP6_SET_LINK_LOCAL_ADDRESS, \
5174 sw_interface_ip6_set_link_local_address);
5176 mp->sw_if_index = ntohl (sw_if_index);
5177 clib_memcpy (mp->address, &v6address, sizeof (v6address));
5178 mp->address_length = address_length;
5183 /* Wait for a reply, return good/bad news */
5191 static int api_sw_interface_ip6nd_ra_prefix (vat_main_t * vam)
5193 unformat_input_t * i = vam->input;
5194 vl_api_sw_interface_ip6nd_ra_prefix_t *mp;
5197 u8 sw_if_index_set = 0;
5198 u32 address_length = 0;
5199 u8 v6_address_set = 0;
5200 ip6_address_t v6address;
5202 u8 no_advertise = 0;
5204 u8 no_autoconfig = 0;
5207 u32 val_lifetime = 0;
5208 u32 pref_lifetime = 0;
5210 /* Parse args required to build the message */
5211 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
5212 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
5213 sw_if_index_set = 1;
5214 else if (unformat (i, "sw_if_index %d", &sw_if_index))
5215 sw_if_index_set = 1;
5216 else if (unformat (i, "%U/%d",
5217 unformat_ip6_address, &v6address,
5220 else if (unformat (i, "val_life %d", &val_lifetime))
5222 else if (unformat (i, "pref_life %d", &pref_lifetime))
5224 else if (unformat (i, "def"))
5226 else if (unformat (i, "noadv"))
5228 else if (unformat (i, "offl"))
5230 else if (unformat (i, "noauto"))
5232 else if (unformat (i, "nolink"))
5234 else if (unformat (i, "isno"))
5237 clib_warning ("parse error '%U'", format_unformat_error, i);
5242 if (sw_if_index_set == 0) {
5243 errmsg ("missing interface name or sw_if_index\n");
5246 if (!v6_address_set) {
5247 errmsg ("no address set\n");
5251 /* Construct the API message */
5252 M(SW_INTERFACE_IP6ND_RA_PREFIX, sw_interface_ip6nd_ra_prefix);
5254 mp->sw_if_index = ntohl (sw_if_index);
5255 clib_memcpy (mp->address, &v6address, sizeof (v6address));
5256 mp->address_length = address_length;
5257 mp->use_default = use_default;
5258 mp->no_advertise = no_advertise;
5259 mp->off_link = off_link;
5260 mp->no_autoconfig = no_autoconfig;
5261 mp->no_onlink = no_onlink;
5263 mp->val_lifetime = ntohl(val_lifetime);
5264 mp->pref_lifetime = ntohl(pref_lifetime);
5269 /* Wait for a reply, return good/bad news */
5276 static int api_sw_interface_ip6nd_ra_config (vat_main_t * vam)
5278 unformat_input_t * i = vam->input;
5279 vl_api_sw_interface_ip6nd_ra_config_t *mp;
5282 u8 sw_if_index_set = 0;
5287 u8 send_unicast = 0;
5290 u8 default_router = 0;
5291 u32 max_interval = 0;
5292 u32 min_interval = 0;
5294 u32 initial_count = 0;
5295 u32 initial_interval = 0;
5298 /* Parse args required to build the message */
5299 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
5300 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
5301 sw_if_index_set = 1;
5302 else if (unformat (i, "sw_if_index %d", &sw_if_index))
5303 sw_if_index_set = 1;
5304 else if (unformat (i, "maxint %d", &max_interval))
5306 else if (unformat (i, "minint %d", &min_interval))
5308 else if (unformat (i, "life %d", &lifetime))
5310 else if (unformat (i, "count %d", &initial_count))
5312 else if (unformat (i, "interval %d", &initial_interval))
5314 else if (unformat (i, "surpress"))
5316 else if (unformat (i, "managed"))
5318 else if (unformat (i, "other"))
5320 else if (unformat (i, "ll"))
5322 else if (unformat (i, "send"))
5324 else if (unformat (i, "cease"))
5326 else if (unformat (i, "isno"))
5328 else if (unformat (i, "def"))
5331 clib_warning ("parse error '%U'", format_unformat_error, i);
5336 if (sw_if_index_set == 0) {
5337 errmsg ("missing interface name or sw_if_index\n");
5341 /* Construct the API message */
5342 M(SW_INTERFACE_IP6ND_RA_CONFIG, sw_interface_ip6nd_ra_config);
5344 mp->sw_if_index = ntohl (sw_if_index);
5345 mp->max_interval = ntohl(max_interval);
5346 mp->min_interval = ntohl(min_interval);
5347 mp->lifetime = ntohl(lifetime);
5348 mp->initial_count = ntohl(initial_count);
5349 mp->initial_interval = ntohl(initial_interval);
5350 mp->surpress = surpress;
5351 mp->managed = managed;
5353 mp->ll_option = ll_option;
5354 mp->send_unicast = send_unicast;
5357 mp->default_router = default_router;
5362 /* Wait for a reply, return good/bad news */
5369 static int api_set_arp_neighbor_limit (vat_main_t * vam)
5371 unformat_input_t * i = vam->input;
5372 vl_api_set_arp_neighbor_limit_t *mp;
5378 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
5379 if (unformat (i, "arp_nbr_limit %d", &arp_nbr_limit))
5381 else if (unformat (i, "ipv6"))
5384 clib_warning ("parse error '%U'", format_unformat_error, i);
5389 if (limit_set == 0) {
5390 errmsg ("missing limit value\n");
5394 M(SET_ARP_NEIGHBOR_LIMIT, set_arp_neighbor_limit);
5396 mp->arp_neighbor_limit = ntohl(arp_nbr_limit);
5397 mp->is_ipv6 = is_ipv6;
5404 static int api_l2_patch_add_del (vat_main_t * vam)
5406 unformat_input_t * i = vam->input;
5407 vl_api_l2_patch_add_del_t *mp;
5410 u8 rx_sw_if_index_set = 0;
5412 u8 tx_sw_if_index_set = 0;
5415 /* Parse args required to build the message */
5416 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
5417 if (unformat (i, "rx_sw_if_index %d", &rx_sw_if_index))
5418 rx_sw_if_index_set = 1;
5419 else if (unformat (i, "tx_sw_if_index %d", &tx_sw_if_index))
5420 tx_sw_if_index_set = 1;
5421 else if (unformat (i, "rx")) {
5422 if (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
5423 if (unformat (i, "%U", unformat_sw_if_index, vam,
5425 rx_sw_if_index_set = 1;
5428 } else if (unformat (i, "tx")) {
5429 if (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
5430 if (unformat (i, "%U", unformat_sw_if_index, vam,
5432 tx_sw_if_index_set = 1;
5435 } else if (unformat (i, "del"))
5441 if (rx_sw_if_index_set == 0) {
5442 errmsg ("missing rx interface name or rx_sw_if_index\n");
5446 if (tx_sw_if_index_set == 0) {
5447 errmsg ("missing tx interface name or tx_sw_if_index\n");
5451 M(L2_PATCH_ADD_DEL, l2_patch_add_del);
5453 mp->rx_sw_if_index = ntohl(rx_sw_if_index);
5454 mp->tx_sw_if_index = ntohl(tx_sw_if_index);
5455 mp->is_add = is_add;
5461 static int api_trace_profile_add (vat_main_t *vam)
5463 unformat_input_t * input = vam->input;
5464 vl_api_trace_profile_add_t *mp;
5467 u32 trace_option_elts = 0;
5468 u32 trace_type = 0, node_id = 0, app_data = 0, trace_tsp = 2;
5469 int has_pow_option = 0;
5470 int has_ppc_option = 0;
5472 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
5474 if (unformat (input, "id %d trace-type 0x%x trace-elts %d "
5475 "trace-tsp %d node-id 0x%x app-data 0x%x",
5476 &id, &trace_type, &trace_option_elts, &trace_tsp,
5477 &node_id, &app_data))
5479 else if (unformat (input, "pow"))
5481 else if (unformat (input, "ppc encap"))
5482 has_ppc_option = PPC_ENCAP;
5483 else if (unformat (input, "ppc decap"))
5484 has_ppc_option = PPC_DECAP;
5485 else if (unformat (input, "ppc none"))
5486 has_ppc_option = PPC_NONE;
5490 M(TRACE_PROFILE_ADD, trace_profile_add);
5492 mp->trace_type = trace_type;
5493 mp->trace_num_elt = trace_option_elts;
5494 mp->trace_ppc = has_ppc_option;
5495 mp->trace_app_data = htonl(app_data);
5496 mp->pow_enable = has_pow_option;
5497 mp->trace_tsp = trace_tsp;
5498 mp->node_id = htonl(node_id);
5505 static int api_trace_profile_apply (vat_main_t *vam)
5507 unformat_input_t * input = vam->input;
5508 vl_api_trace_profile_apply_t *mp;
5511 u32 mask_width = ~0;
5518 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
5520 if (unformat (input, "%U/%d",
5521 unformat_ip6_address, &addr, &mask_width))
5523 else if (unformat (input, "id %d", &id))
5525 else if (unformat (input, "vrf-id %d", &vrf_id))
5527 else if (unformat (input, "add"))
5529 else if (unformat (input, "pop"))
5531 else if (unformat (input, "none"))
5537 if ((is_add + is_pop + is_none) != 1) {
5538 errmsg("One of (add, pop, none) required");
5541 if (mask_width == ~0) {
5542 errmsg("<address>/<mask-width> required");
5545 M(TRACE_PROFILE_APPLY, trace_profile_apply);
5546 clib_memcpy(mp->dest_ipv6, &addr, sizeof(mp->dest_ipv6));
5548 mp->prefix_length = htonl(mask_width);
5549 mp->vrf_id = htonl(vrf_id);
5551 mp->trace_op = IOAM_HBYH_ADD;
5553 mp->trace_op = IOAM_HBYH_POP;
5555 mp->trace_op = IOAM_HBYH_MOD;
5567 static int api_trace_profile_del (vat_main_t *vam)
5569 vl_api_trace_profile_del_t *mp;
5572 M(TRACE_PROFILE_DEL, trace_profile_del);
5577 static int api_sr_tunnel_add_del (vat_main_t * vam)
5579 unformat_input_t * i = vam->input;
5580 vl_api_sr_tunnel_add_del_t *mp;
5584 ip6_address_t src_address;
5585 int src_address_set = 0;
5586 ip6_address_t dst_address;
5588 int dst_address_set = 0;
5590 u32 rx_table_id = 0;
5591 u32 tx_table_id = 0;
5592 ip6_address_t * segments = 0;
5593 ip6_address_t * this_seg;
5594 ip6_address_t * tags = 0;
5595 ip6_address_t * this_tag;
5596 ip6_address_t next_address, tag;
5598 u8 * policy_name = 0;
5600 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
5602 if (unformat (i, "del"))
5604 else if (unformat (i, "name %s", &name))
5606 else if (unformat (i, "policy %s", &policy_name))
5608 else if (unformat (i, "rx_fib_id %d", &rx_table_id))
5610 else if (unformat (i, "tx_fib_id %d", &tx_table_id))
5612 else if (unformat (i, "src %U", unformat_ip6_address, &src_address))
5613 src_address_set = 1;
5614 else if (unformat (i, "dst %U/%d",
5615 unformat_ip6_address, &dst_address,
5617 dst_address_set = 1;
5618 else if (unformat (i, "next %U", unformat_ip6_address,
5621 vec_add2 (segments, this_seg, 1);
5622 clib_memcpy (this_seg->as_u8, next_address.as_u8, sizeof (*this_seg));
5624 else if (unformat (i, "tag %U", unformat_ip6_address,
5627 vec_add2 (tags, this_tag, 1);
5628 clib_memcpy (this_tag->as_u8, tag.as_u8, sizeof (*this_tag));
5630 else if (unformat (i, "clean"))
5631 flags |= IP6_SR_HEADER_FLAG_CLEANUP;
5632 else if (unformat (i, "protected"))
5633 flags |= IP6_SR_HEADER_FLAG_PROTECTED;
5634 else if (unformat (i, "InPE %d", &pl_index))
5636 if (pl_index <= 0 || pl_index > 4)
5638 pl_index_range_error:
5639 errmsg ("pl index %d out of range\n", pl_index);
5642 flags |= IP6_SR_HEADER_FLAG_PL_ELT_INGRESS_PE << (3*(pl_index - 1));
5644 else if (unformat (i, "EgPE %d", &pl_index))
5646 if (pl_index <= 0 || pl_index > 4)
5647 goto pl_index_range_error;
5648 flags |= IP6_SR_HEADER_FLAG_PL_ELT_EGRESS_PE << (3*(pl_index - 1));
5650 else if (unformat (i, "OrgSrc %d", &pl_index))
5652 if (pl_index <= 0 || pl_index > 4)
5653 goto pl_index_range_error;
5654 flags |= IP6_SR_HEADER_FLAG_PL_ELT_ORIG_SRC_ADDR << (3*(pl_index - 1));
5660 if (!src_address_set)
5662 errmsg ("src address required\n");
5666 if (!dst_address_set)
5668 errmsg ("dst address required\n");
5674 errmsg ("at least one sr segment required\n");
5678 M2(SR_TUNNEL_ADD_DEL, sr_tunnel_add_del,
5679 vec_len(segments) * sizeof (ip6_address_t)
5680 + vec_len(tags) * sizeof (ip6_address_t));
5682 clib_memcpy (mp->src_address, &src_address, sizeof (mp->src_address));
5683 clib_memcpy (mp->dst_address, &dst_address, sizeof (mp->dst_address));
5684 mp->dst_mask_width = dst_mask_width;
5685 mp->flags_net_byte_order = clib_host_to_net_u16 (flags);
5686 mp->n_segments = vec_len (segments);
5687 mp->n_tags = vec_len (tags);
5688 mp->is_add = is_del == 0;
5689 clib_memcpy (mp->segs_and_tags, segments,
5690 vec_len(segments)* sizeof (ip6_address_t));
5691 clib_memcpy (mp->segs_and_tags + vec_len(segments)*sizeof (ip6_address_t),
5692 tags, vec_len(tags)* sizeof (ip6_address_t));
5694 mp->outer_vrf_id = ntohl (rx_table_id);
5695 mp->inner_vrf_id = ntohl (tx_table_id);
5696 memcpy (mp->name, name, vec_len(name));
5697 memcpy (mp->policy_name, policy_name, vec_len(policy_name));
5699 vec_free (segments);
5706 static int api_sr_policy_add_del (vat_main_t * vam)
5708 unformat_input_t * input = vam->input;
5709 vl_api_sr_policy_add_del_t *mp;
5713 u8 * tunnel_name = 0;
5714 u8 ** tunnel_names = 0;
5719 int tunnel_names_length = 1; // Init to 1 to offset the #tunnel_names counter byte
5720 int tun_name_len = 0; // Different naming convention used as confusing these would be "bad" (TM)
5722 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
5724 if (unformat (input, "del"))
5726 else if (unformat (input, "name %s", &name))
5728 else if (unformat (input, "tunnel %s", &tunnel_name))
5732 vec_add1 (tunnel_names, tunnel_name);
5734 - length = #bytes to store in serial vector
5735 - +1 = byte to store that length
5737 tunnel_names_length += (vec_len (tunnel_name) + 1);
5748 errmsg ("policy name required\n");
5752 if ((!tunnel_set) && (!is_del))
5754 errmsg ("tunnel name required\n");
5758 M2(SR_POLICY_ADD_DEL, sr_policy_add_del, tunnel_names_length);
5762 mp->is_add = !is_del;
5764 memcpy (mp->name, name, vec_len(name));
5765 // Since mp->tunnel_names is of type u8[0] and not a u8 *, u8 ** needs to be serialized
5766 u8 * serial_orig = 0;
5767 vec_validate (serial_orig, tunnel_names_length);
5768 *serial_orig = vec_len(tunnel_names); // Store the number of tunnels as length in first byte of serialized vector
5769 serial_orig += 1; // Move along one byte to store the length of first tunnel_name
5771 for (j=0; j < vec_len(tunnel_names); j++)
5773 tun_name_len = vec_len (tunnel_names[j]);
5774 *serial_orig = tun_name_len; // Store length of tunnel name in first byte of Length/Value pair
5775 serial_orig += 1; // Move along one byte to store the actual tunnel name
5776 memcpy (serial_orig, tunnel_names[j], tun_name_len);
5777 serial_orig += tun_name_len; // Advance past the copy
5779 memcpy (mp->tunnel_names, serial_orig - tunnel_names_length, tunnel_names_length); // Regress serial_orig to head then copy fwd
5781 vec_free (tunnel_names);
5782 vec_free (tunnel_name);
5788 static int api_sr_multicast_map_add_del (vat_main_t * vam)
5790 unformat_input_t * input = vam->input;
5791 vl_api_sr_multicast_map_add_del_t *mp;
5794 ip6_address_t multicast_address;
5795 u8 * policy_name = 0;
5796 int multicast_address_set = 0;
5798 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
5800 if (unformat (input, "del"))
5802 else if (unformat (input, "address %U", unformat_ip6_address, &multicast_address))
5803 multicast_address_set = 1;
5804 else if (unformat (input, "sr-policy %s", &policy_name))
5810 if (!is_del && !policy_name)
5812 errmsg ("sr-policy name required\n");
5817 if (!multicast_address_set)
5819 errmsg ("address required\n");
5823 M(SR_MULTICAST_MAP_ADD_DEL, sr_multicast_map_add_del);
5825 mp->is_add = !is_del;
5826 memcpy (mp->policy_name, policy_name, vec_len(policy_name));
5827 clib_memcpy (mp->multicast_address, &multicast_address, sizeof (mp->multicast_address));
5830 vec_free (policy_name);
5837 #define foreach_ip4_proto_field \
5847 uword unformat_ip4_mask (unformat_input_t * input, va_list * args)
5849 u8 ** maskp = va_arg (*args, u8 **);
5851 u8 found_something = 0;
5854 #define _(a) u8 a=0;
5855 foreach_ip4_proto_field;
5861 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
5863 if (unformat (input, "version"))
5865 else if (unformat (input, "hdr_length"))
5867 else if (unformat (input, "src"))
5869 else if (unformat (input, "dst"))
5871 else if (unformat (input, "proto"))
5874 #define _(a) else if (unformat (input, #a)) a=1;
5875 foreach_ip4_proto_field
5881 #define _(a) found_something += a;
5882 foreach_ip4_proto_field;
5885 if (found_something == 0)
5888 vec_validate (mask, sizeof (*ip) - 1);
5890 ip = (ip4_header_t *) mask;
5892 #define _(a) if (a) memset (&ip->a, 0xff, sizeof (ip->a));
5893 foreach_ip4_proto_field;
5896 ip->ip_version_and_header_length = 0;
5899 ip->ip_version_and_header_length |= 0xF0;
5902 ip->ip_version_and_header_length |= 0x0F;
5908 #define foreach_ip6_proto_field \
5915 uword unformat_ip6_mask (unformat_input_t * input, va_list * args)
5917 u8 ** maskp = va_arg (*args, u8 **);
5919 u8 found_something = 0;
5921 u32 ip_version_traffic_class_and_flow_label;
5923 #define _(a) u8 a=0;
5924 foreach_ip6_proto_field;
5927 u8 traffic_class = 0;
5930 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
5932 if (unformat (input, "version"))
5934 else if (unformat (input, "traffic-class"))
5936 else if (unformat (input, "flow-label"))
5938 else if (unformat (input, "src"))
5940 else if (unformat (input, "dst"))
5942 else if (unformat (input, "proto"))
5945 #define _(a) else if (unformat (input, #a)) a=1;
5946 foreach_ip6_proto_field
5952 #define _(a) found_something += a;
5953 foreach_ip6_proto_field;
5956 if (found_something == 0)
5959 vec_validate (mask, sizeof (*ip) - 1);
5961 ip = (ip6_header_t *) mask;
5963 #define _(a) if (a) memset (&ip->a, 0xff, sizeof (ip->a));
5964 foreach_ip6_proto_field;
5967 ip_version_traffic_class_and_flow_label = 0;
5970 ip_version_traffic_class_and_flow_label |= 0xF0000000;
5973 ip_version_traffic_class_and_flow_label |= 0x0FF00000;
5976 ip_version_traffic_class_and_flow_label |= 0x000FFFFF;
5978 ip->ip_version_traffic_class_and_flow_label =
5979 clib_host_to_net_u32 (ip_version_traffic_class_and_flow_label);
5985 uword unformat_l3_mask (unformat_input_t * input, va_list * args)
5987 u8 ** maskp = va_arg (*args, u8 **);
5989 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) {
5990 if (unformat (input, "ip4 %U", unformat_ip4_mask, maskp))
5992 else if (unformat (input, "ip6 %U", unformat_ip6_mask, maskp))
6000 uword unformat_l2_mask (unformat_input_t * input, va_list * args)
6002 u8 ** maskp = va_arg (*args, u8 **);
6017 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) {
6018 if (unformat (input, "src"))
6020 else if (unformat (input, "dst"))
6022 else if (unformat (input, "proto"))
6024 else if (unformat (input, "tag1"))
6026 else if (unformat (input, "tag2"))
6028 else if (unformat (input, "ignore-tag1"))
6030 else if (unformat (input, "ignore-tag2"))
6032 else if (unformat (input, "cos1"))
6034 else if (unformat (input, "cos2"))
6036 else if (unformat (input, "dot1q"))
6038 else if (unformat (input, "dot1ad"))
6043 if ((src + dst + proto + tag1 + tag2 + dot1q + dot1ad +
6044 ignore_tag1 + ignore_tag2 + cos1 + cos2) == 0)
6047 if (tag1 || ignore_tag1 || cos1 || dot1q)
6049 if (tag2 || ignore_tag2 || cos2 || dot1ad)
6052 vec_validate (mask, len-1);
6055 memset (mask, 0xff, 6);
6058 memset (mask + 6, 0xff, 6);
6062 /* inner vlan tag */
6071 mask[21] = mask [20] = 0xff;
6092 mask[16] = mask [17] = 0xff;
6102 mask[12] = mask [13] = 0xff;
6108 uword unformat_classify_mask (unformat_input_t * input, va_list * args)
6110 u8 ** maskp = va_arg (*args, u8 **);
6111 u32 * skipp = va_arg (*args, u32 *);
6112 u32 * matchp = va_arg (*args, u32 *);
6119 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) {
6120 if (unformat (input, "hex %U", unformat_hex_string, &mask))
6122 else if (unformat (input, "l2 %U", unformat_l2_mask, &l2))
6124 else if (unformat (input, "l3 %U", unformat_l3_mask, &l3))
6130 if (mask || l2 || l3)
6134 /* "With a free Ethernet header in every package" */
6136 vec_validate (l2, 13);
6138 vec_append (mask, l3);
6142 /* Scan forward looking for the first significant mask octet */
6143 for (i = 0; i < vec_len (mask); i++)
6147 /* compute (skip, match) params */
6148 *skipp = i / sizeof(u32x4);
6149 vec_delete (mask, *skipp * sizeof(u32x4), 0);
6151 /* Pad mask to an even multiple of the vector size */
6152 while (vec_len (mask) % sizeof (u32x4))
6155 match = vec_len (mask) / sizeof (u32x4);
6157 for (i = match*sizeof(u32x4); i > 0; i-= sizeof(u32x4))
6159 u64 *tmp = (u64 *)(mask + (i-sizeof(u32x4)));
6160 if (*tmp || *(tmp+1))
6165 clib_warning ("BUG: match 0");
6167 _vec_len (mask) = match * sizeof(u32x4);
6178 #define foreach_l2_next \
6180 _(ethernet, ETHERNET_INPUT) \
6184 uword unformat_l2_next_index (unformat_input_t * input, va_list * args)
6186 u32 * miss_next_indexp = va_arg (*args, u32 *);
6191 if (unformat (input, #n)) { next_index = L2_CLASSIFY_NEXT_##N; goto out;}
6195 if (unformat (input, "%d", &tmp))
6204 *miss_next_indexp = next_index;
6208 #define foreach_ip_next \
6214 uword unformat_ip_next_index (unformat_input_t * input, va_list * args)
6216 u32 * miss_next_indexp = va_arg (*args, u32 *);
6221 if (unformat (input, #n)) { next_index = IP_LOOKUP_NEXT_##N; goto out;}
6225 if (unformat (input, "%d", &tmp))
6234 *miss_next_indexp = next_index;
6238 #define foreach_acl_next \
6241 uword unformat_acl_next_index (unformat_input_t * input, va_list * args)
6243 u32 * miss_next_indexp = va_arg (*args, u32 *);
6248 if (unformat (input, #n)) { next_index = ACL_NEXT_INDEX_##N; goto out;}
6252 if (unformat (input, "permit"))
6257 else if (unformat (input, "%d", &tmp))
6266 *miss_next_indexp = next_index;
6270 static int api_classify_add_del_table (vat_main_t * vam)
6272 unformat_input_t * i = vam->input;
6273 vl_api_classify_add_del_table_t *mp;
6279 u32 table_index = ~0;
6280 u32 next_table_index = ~0;
6281 u32 miss_next_index = ~0;
6282 u32 memory_size = 32<<20;
6286 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
6287 if (unformat (i, "del"))
6289 else if (unformat (i, "buckets %d", &nbuckets))
6291 else if (unformat (i, "memory_size %d", &memory_size))
6293 else if (unformat (i, "skip %d", &skip))
6295 else if (unformat (i, "match %d", &match))
6297 else if (unformat (i, "table %d", &table_index))
6299 else if (unformat (i, "mask %U", unformat_classify_mask,
6300 &mask, &skip, &match))
6302 else if (unformat (i, "next-table %d", &next_table_index))
6304 else if (unformat (i, "miss-next %U", unformat_ip_next_index,
6307 else if (unformat (i, "l2-miss-next %U", unformat_l2_next_index,
6310 else if (unformat (i, "acl-miss-next %U", unformat_acl_next_index,
6317 if (is_add && mask == 0) {
6318 errmsg ("Mask required\n");
6322 if (is_add && skip == ~0) {
6323 errmsg ("skip count required\n");
6327 if (is_add && match == ~0) {
6328 errmsg ("match count required\n");
6332 if (!is_add && table_index == ~0) {
6333 errmsg ("table index required for delete\n");
6337 M2 (CLASSIFY_ADD_DEL_TABLE, classify_add_del_table,
6340 mp->is_add = is_add;
6341 mp->table_index = ntohl(table_index);
6342 mp->nbuckets = ntohl(nbuckets);
6343 mp->memory_size = ntohl(memory_size);
6344 mp->skip_n_vectors = ntohl(skip);
6345 mp->match_n_vectors = ntohl(match);
6346 mp->next_table_index = ntohl(next_table_index);
6347 mp->miss_next_index = ntohl(miss_next_index);
6348 clib_memcpy (mp->mask, mask, vec_len(mask));
6356 uword unformat_ip4_match (unformat_input_t * input, va_list * args)
6358 u8 ** matchp = va_arg (*args, u8 **);
6365 int src = 0, dst = 0;
6366 ip4_address_t src_val, dst_val;
6373 int fragment_id = 0;
6374 u32 fragment_id_val;
6380 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
6382 if (unformat (input, "version %d", &version_val))
6384 else if (unformat (input, "hdr_length %d", &hdr_length_val))
6386 else if (unformat (input, "src %U", unformat_ip4_address, &src_val))
6388 else if (unformat (input, "dst %U", unformat_ip4_address, &dst_val))
6390 else if (unformat (input, "proto %d", &proto_val))
6392 else if (unformat (input, "tos %d", &tos_val))
6394 else if (unformat (input, "length %d", &length_val))
6396 else if (unformat (input, "fragment_id %d", &fragment_id_val))
6398 else if (unformat (input, "ttl %d", &ttl_val))
6400 else if (unformat (input, "checksum %d", &checksum_val))
6406 if (version + hdr_length + src + dst + proto + tos + length + fragment_id
6407 + ttl + checksum == 0)
6411 * Aligned because we use the real comparison functions
6413 vec_validate_aligned (match, sizeof (*ip) - 1, sizeof(u32x4));
6415 ip = (ip4_header_t *) match;
6417 /* These are realistically matched in practice */
6419 ip->src_address.as_u32 = src_val.as_u32;
6422 ip->dst_address.as_u32 = dst_val.as_u32;
6425 ip->protocol = proto_val;
6428 /* These are not, but they're included for completeness */
6430 ip->ip_version_and_header_length |= (version_val & 0xF)<<4;
6433 ip->ip_version_and_header_length |= (hdr_length_val & 0xF);
6439 ip->length = length_val;
6445 ip->checksum = checksum_val;
6451 uword unformat_ip6_match (unformat_input_t * input, va_list * args)
6453 u8 ** matchp = va_arg (*args, u8 **);
6459 u32 traffic_class_val;
6462 int src = 0, dst = 0;
6463 ip6_address_t src_val, dst_val;
6466 int payload_length = 0;
6467 u32 payload_length_val;
6470 u32 ip_version_traffic_class_and_flow_label;
6472 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
6474 if (unformat (input, "version %d", &version_val))
6476 else if (unformat (input, "traffic_class %d", &traffic_class_val))
6478 else if (unformat (input, "flow_label %d", &flow_label_val))
6480 else if (unformat (input, "src %U", unformat_ip6_address, &src_val))
6482 else if (unformat (input, "dst %U", unformat_ip6_address, &dst_val))
6484 else if (unformat (input, "proto %d", &proto_val))
6486 else if (unformat (input, "payload_length %d", &payload_length_val))
6488 else if (unformat (input, "hop_limit %d", &hop_limit_val))
6494 if (version + traffic_class + flow_label + src + dst + proto +
6495 payload_length + hop_limit == 0)
6499 * Aligned because we use the real comparison functions
6501 vec_validate_aligned (match, sizeof (*ip) - 1, sizeof(u32x4));
6503 ip = (ip6_header_t *) match;
6506 clib_memcpy (&ip->src_address, &src_val, sizeof (ip->src_address));
6509 clib_memcpy (&ip->dst_address, &dst_val, sizeof (ip->dst_address));
6512 ip->protocol = proto_val;
6514 ip_version_traffic_class_and_flow_label = 0;
6517 ip_version_traffic_class_and_flow_label |= (version_val & 0xF) << 28;
6520 ip_version_traffic_class_and_flow_label |= (traffic_class_val & 0xFF) << 20;
6523 ip_version_traffic_class_and_flow_label |= (flow_label_val & 0xFFFFF);
6525 ip->ip_version_traffic_class_and_flow_label =
6526 clib_host_to_net_u32 (ip_version_traffic_class_and_flow_label);
6529 ip->payload_length = clib_host_to_net_u16 (payload_length_val);
6532 ip->hop_limit = hop_limit_val;
6538 uword unformat_l3_match (unformat_input_t * input, va_list * args)
6540 u8 ** matchp = va_arg (*args, u8 **);
6542 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) {
6543 if (unformat (input, "ip4 %U", unformat_ip4_match, matchp))
6545 else if (unformat (input, "ip6 %U", unformat_ip6_match, matchp))
6553 uword unformat_vlan_tag (unformat_input_t * input, va_list * args)
6555 u8 * tagp = va_arg (*args, u8 *);
6558 if (unformat(input, "%d", &tag))
6560 tagp[0] = (tag>>8) & 0x0F;
6561 tagp[1] = tag & 0xFF;
6568 uword unformat_l2_match (unformat_input_t * input, va_list * args)
6570 u8 ** matchp = va_arg (*args, u8 **);
6590 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) {
6591 if (unformat (input, "src %U", unformat_ethernet_address, &src_val))
6593 else if (unformat (input, "dst %U", unformat_ethernet_address, &dst_val))
6595 else if (unformat (input, "proto %U",
6596 unformat_ethernet_type_host_byte_order, &proto_val))
6598 else if (unformat (input, "tag1 %U", unformat_vlan_tag, tag1_val))
6600 else if (unformat (input, "tag2 %U", unformat_vlan_tag, tag2_val))
6602 else if (unformat (input, "ignore-tag1"))
6604 else if (unformat (input, "ignore-tag2"))
6606 else if (unformat (input, "cos1 %d", &cos1_val))
6608 else if (unformat (input, "cos2 %d", &cos2_val))
6613 if ((src + dst + proto + tag1 + tag2 +
6614 ignore_tag1 + ignore_tag2 + cos1 + cos2) == 0)
6617 if (tag1 || ignore_tag1 || cos1)
6619 if (tag2 || ignore_tag2 || cos2)
6622 vec_validate_aligned (match, len-1, sizeof(u32x4));
6625 clib_memcpy (match, dst_val, 6);
6628 clib_memcpy (match + 6, src_val, 6);
6632 /* inner vlan tag */
6633 match[19] = tag2_val[1];
6634 match[18] = tag2_val[0];
6636 match [18] |= (cos2_val & 0x7) << 5;
6639 match[21] = proto_val & 0xff;
6640 match[20] = proto_val >> 8;
6644 match [15] = tag1_val[1];
6645 match [14] = tag1_val[0];
6648 match [14] |= (cos1_val & 0x7) << 5;
6654 match [15] = tag1_val[1];
6655 match [14] = tag1_val[0];
6658 match[17] = proto_val & 0xff;
6659 match[16] = proto_val >> 8;
6662 match [14] |= (cos1_val & 0x7) << 5;
6668 match [18] |= (cos2_val & 0x7) << 5;
6670 match [14] |= (cos1_val & 0x7) << 5;
6673 match[13] = proto_val & 0xff;
6674 match[12] = proto_val >> 8;
6682 uword unformat_classify_match (unformat_input_t * input, va_list * args)
6684 u8 ** matchp = va_arg (*args, u8 **);
6685 u32 skip_n_vectors = va_arg (*args, u32);
6686 u32 match_n_vectors = va_arg (*args, u32);
6692 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) {
6693 if (unformat (input, "hex %U", unformat_hex_string, &match))
6695 else if (unformat (input, "l2 %U", unformat_l2_match, &l2))
6697 else if (unformat (input, "l3 %U", unformat_l3_match, &l3))
6703 if (match || l2 || l3)
6707 /* "Win a free Ethernet header in every packet" */
6709 vec_validate_aligned (l2, 13, sizeof(u32x4));
6711 vec_append_aligned (match, l3, sizeof(u32x4));
6715 /* Make sure the vector is big enough even if key is all 0's */
6716 vec_validate_aligned
6717 (match, ((match_n_vectors + skip_n_vectors) * sizeof(u32x4)) - 1,
6720 /* Set size, include skipped vectors*/
6721 _vec_len (match) = (match_n_vectors+skip_n_vectors) * sizeof(u32x4);
6731 static int api_classify_add_del_session (vat_main_t * vam)
6733 unformat_input_t * i = vam->input;
6734 vl_api_classify_add_del_session_t *mp;
6736 u32 table_index = ~0;
6737 u32 hit_next_index = ~0;
6738 u32 opaque_index = ~0;
6742 u32 skip_n_vectors = 0;
6743 u32 match_n_vectors = 0;
6746 * Warning: you have to supply skip_n and match_n
6747 * because the API client cant simply look at the classify
6751 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
6752 if (unformat (i, "del"))
6754 else if (unformat (i, "hit-next %U", unformat_ip_next_index,
6757 else if (unformat (i, "l2-hit-next %U", unformat_l2_next_index,
6760 else if (unformat (i, "acl-hit-next %U", unformat_acl_next_index,
6763 else if (unformat (i, "opaque-index %d", &opaque_index))
6765 else if (unformat (i, "skip_n %d", &skip_n_vectors))
6767 else if (unformat (i, "match_n %d", &match_n_vectors))
6769 else if (unformat (i, "match %U", unformat_classify_match,
6770 &match, skip_n_vectors, match_n_vectors))
6772 else if (unformat (i, "advance %d", &advance))
6774 else if (unformat (i, "table-index %d", &table_index))
6780 if (table_index == ~0) {
6781 errmsg ("Table index required\n");
6785 if (is_add && match == 0) {
6786 errmsg ("Match value required\n");
6790 M2 (CLASSIFY_ADD_DEL_SESSION, classify_add_del_session,
6793 mp->is_add = is_add;
6794 mp->table_index = ntohl(table_index);
6795 mp->hit_next_index = ntohl(hit_next_index);
6796 mp->opaque_index = ntohl(opaque_index);
6797 mp->advance = ntohl(advance);
6798 clib_memcpy (mp->match, match, vec_len(match));
6805 static int api_classify_set_interface_ip_table (vat_main_t * vam)
6807 unformat_input_t * i = vam->input;
6808 vl_api_classify_set_interface_ip_table_t *mp;
6811 int sw_if_index_set;
6812 u32 table_index = ~0;
6815 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
6816 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
6817 sw_if_index_set = 1;
6818 else if (unformat (i, "sw_if_index %d", &sw_if_index))
6819 sw_if_index_set = 1;
6820 else if (unformat (i, "table %d", &table_index))
6823 clib_warning ("parse error '%U'", format_unformat_error, i);
6828 if (sw_if_index_set == 0) {
6829 errmsg ("missing interface name or sw_if_index\n");
6834 M(CLASSIFY_SET_INTERFACE_IP_TABLE, classify_set_interface_ip_table);
6836 mp->sw_if_index = ntohl(sw_if_index);
6837 mp->table_index = ntohl(table_index);
6838 mp->is_ipv6 = is_ipv6;
6845 static int api_classify_set_interface_l2_tables (vat_main_t * vam)
6847 unformat_input_t * i = vam->input;
6848 vl_api_classify_set_interface_l2_tables_t *mp;
6851 int sw_if_index_set;
6852 u32 ip4_table_index = ~0;
6853 u32 ip6_table_index = ~0;
6854 u32 other_table_index = ~0;
6856 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
6857 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
6858 sw_if_index_set = 1;
6859 else if (unformat (i, "sw_if_index %d", &sw_if_index))
6860 sw_if_index_set = 1;
6861 else if (unformat (i, "ip4-table %d", &ip4_table_index))
6863 else if (unformat (i, "ip6-table %d", &ip6_table_index))
6865 else if (unformat (i, "other-table %d", &other_table_index))
6868 clib_warning ("parse error '%U'", format_unformat_error, i);
6873 if (sw_if_index_set == 0) {
6874 errmsg ("missing interface name or sw_if_index\n");
6879 M(CLASSIFY_SET_INTERFACE_L2_TABLES, classify_set_interface_l2_tables);
6881 mp->sw_if_index = ntohl(sw_if_index);
6882 mp->ip4_table_index = ntohl(ip4_table_index);
6883 mp->ip6_table_index = ntohl(ip6_table_index);
6884 mp->other_table_index = ntohl(other_table_index);
6892 static int api_get_node_index (vat_main_t * vam)
6894 unformat_input_t * i = vam->input;
6895 vl_api_get_node_index_t * mp;
6899 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
6900 if (unformat (i, "node %s", &name))
6906 errmsg ("node name required\n");
6909 if (vec_len (name) >= ARRAY_LEN(mp->node_name)) {
6910 errmsg ("node name too long, max %d\n", ARRAY_LEN(mp->node_name));
6914 M(GET_NODE_INDEX, get_node_index);
6915 clib_memcpy (mp->node_name, name, vec_len(name));
6923 static int api_add_node_next (vat_main_t * vam)
6925 unformat_input_t * i = vam->input;
6926 vl_api_add_node_next_t * mp;
6931 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
6932 if (unformat (i, "node %s", &name))
6934 else if (unformat (i, "next %s", &next))
6940 errmsg ("node name required\n");
6943 if (vec_len (name) >= ARRAY_LEN(mp->node_name)) {
6944 errmsg ("node name too long, max %d\n", ARRAY_LEN(mp->node_name));
6948 errmsg ("next node required\n");
6951 if (vec_len (next) >= ARRAY_LEN(mp->next_name)) {
6952 errmsg ("next name too long, max %d\n", ARRAY_LEN(mp->next_name));
6956 M(ADD_NODE_NEXT, add_node_next);
6957 clib_memcpy (mp->node_name, name, vec_len(name));
6958 clib_memcpy (mp->next_name, next, vec_len(next));
6967 static int api_l2tpv3_create_tunnel (vat_main_t * vam)
6969 unformat_input_t * i = vam->input;
6970 ip6_address_t client_address, our_address;
6971 int client_address_set = 0;
6972 int our_address_set = 0;
6973 u32 local_session_id = 0;
6974 u32 remote_session_id = 0;
6975 u64 local_cookie = 0;
6976 u64 remote_cookie = 0;
6977 u8 l2_sublayer_present = 0;
6978 vl_api_l2tpv3_create_tunnel_t * mp;
6981 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
6982 if (unformat (i, "client_address %U", unformat_ip6_address,
6984 client_address_set = 1;
6985 else if (unformat (i, "our_address %U", unformat_ip6_address,
6987 our_address_set = 1;
6988 else if (unformat (i, "local_session_id %d", &local_session_id))
6990 else if (unformat (i, "remote_session_id %d", &remote_session_id))
6992 else if (unformat (i, "local_cookie %lld", &local_cookie))
6994 else if (unformat (i, "remote_cookie %lld", &remote_cookie))
6996 else if (unformat (i, "l2-sublayer-present"))
6997 l2_sublayer_present = 1;
7002 if (client_address_set == 0) {
7003 errmsg ("client_address required\n");
7007 if (our_address_set == 0) {
7008 errmsg ("our_address required\n");
7012 M(L2TPV3_CREATE_TUNNEL, l2tpv3_create_tunnel);
7014 clib_memcpy (mp->client_address, client_address.as_u8,
7015 sizeof (mp->client_address));
7017 clib_memcpy (mp->our_address, our_address.as_u8,
7018 sizeof (mp->our_address));
7020 mp->local_session_id = ntohl (local_session_id);
7021 mp->remote_session_id = ntohl (remote_session_id);
7022 mp->local_cookie = clib_host_to_net_u64 (local_cookie);
7023 mp->remote_cookie = clib_host_to_net_u64 (remote_cookie);
7024 mp->l2_sublayer_present = l2_sublayer_present;
7032 static int api_l2tpv3_set_tunnel_cookies (vat_main_t * vam)
7034 unformat_input_t * i = vam->input;
7036 u8 sw_if_index_set = 0;
7037 u64 new_local_cookie = 0;
7038 u64 new_remote_cookie = 0;
7039 vl_api_l2tpv3_set_tunnel_cookies_t *mp;
7042 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
7043 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
7044 sw_if_index_set = 1;
7045 else if (unformat (i, "sw_if_index %d", &sw_if_index))
7046 sw_if_index_set = 1;
7047 else if (unformat (i, "new_local_cookie %lld", &new_local_cookie))
7049 else if (unformat (i, "new_remote_cookie %lld", &new_remote_cookie))
7055 if (sw_if_index_set == 0) {
7056 errmsg ("missing interface name or sw_if_index\n");
7060 M(L2TPV3_SET_TUNNEL_COOKIES, l2tpv3_set_tunnel_cookies);
7062 mp->sw_if_index = ntohl(sw_if_index);
7063 mp->new_local_cookie = clib_host_to_net_u64 (new_local_cookie);
7064 mp->new_remote_cookie = clib_host_to_net_u64 (new_remote_cookie);
7071 static int api_l2tpv3_interface_enable_disable (vat_main_t * vam)
7073 unformat_input_t * i = vam->input;
7074 vl_api_l2tpv3_interface_enable_disable_t *mp;
7077 u8 sw_if_index_set = 0;
7078 u8 enable_disable = 1;
7080 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
7081 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
7082 sw_if_index_set = 1;
7083 else if (unformat (i, "sw_if_index %d", &sw_if_index))
7084 sw_if_index_set = 1;
7085 else if (unformat (i, "enable"))
7087 else if (unformat (i, "disable"))
7093 if (sw_if_index_set == 0) {
7094 errmsg ("missing interface name or sw_if_index\n");
7098 M(L2TPV3_INTERFACE_ENABLE_DISABLE, l2tpv3_interface_enable_disable);
7100 mp->sw_if_index = ntohl(sw_if_index);
7101 mp->enable_disable = enable_disable;
7108 static int api_l2tpv3_set_lookup_key (vat_main_t * vam)
7110 unformat_input_t * i = vam->input;
7111 vl_api_l2tpv3_set_lookup_key_t * mp;
7115 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
7116 if (unformat (i, "lookup_v6_src"))
7117 key = L2T_LOOKUP_SRC_ADDRESS;
7118 else if (unformat (i, "lookup_v6_dst"))
7119 key = L2T_LOOKUP_DST_ADDRESS;
7120 else if (unformat (i, "lookup_session_id"))
7121 key = L2T_LOOKUP_SESSION_ID;
7126 if (key == (u8) ~0) {
7127 errmsg ("l2tp session lookup key unset\n");
7131 M(L2TPV3_SET_LOOKUP_KEY, l2tpv3_set_lookup_key);
7140 static void vl_api_sw_if_l2tpv3_tunnel_details_t_handler
7141 (vl_api_sw_if_l2tpv3_tunnel_details_t * mp)
7143 vat_main_t * vam = &vat_main;
7145 fformat(vam->ofp, "* %U (our) %U (client) (sw_if_index %d)\n",
7146 format_ip6_address, mp->our_address,
7147 format_ip6_address, mp->client_address,
7148 clib_net_to_host_u32(mp->sw_if_index));
7150 fformat (vam->ofp, " local cookies %016llx %016llx remote cookie %016llx\n",
7151 clib_net_to_host_u64 (mp->local_cookie[0]),
7152 clib_net_to_host_u64 (mp->local_cookie[1]),
7153 clib_net_to_host_u64 (mp->remote_cookie));
7155 fformat (vam->ofp, " local session-id %d remote session-id %d\n",
7156 clib_net_to_host_u32 (mp->local_session_id),
7157 clib_net_to_host_u32 (mp->remote_session_id));
7159 fformat (vam->ofp, " l2 specific sublayer %s\n\n",
7160 mp->l2_sublayer_present ? "preset" : "absent");
7164 static void vl_api_sw_if_l2tpv3_tunnel_details_t_handler_json
7165 (vl_api_sw_if_l2tpv3_tunnel_details_t * mp)
7167 vat_main_t * vam = &vat_main;
7168 vat_json_node_t *node = NULL;
7169 struct in6_addr addr;
7171 if (VAT_JSON_ARRAY != vam->json_tree.type) {
7172 ASSERT(VAT_JSON_NONE == vam->json_tree.type);
7173 vat_json_init_array(&vam->json_tree);
7175 node = vat_json_array_add(&vam->json_tree);
7177 vat_json_init_object(node);
7179 clib_memcpy(&addr, mp->our_address, sizeof(addr));
7180 vat_json_object_add_ip6(node, "our_address", addr);
7181 clib_memcpy(&addr, mp->client_address, sizeof(addr));
7182 vat_json_object_add_ip6(node, "client_address", addr);
7184 vat_json_node_t * lc = vat_json_object_add(node, "local_cookie");
7185 vat_json_init_array(lc);
7186 vat_json_array_add_uint(lc, clib_net_to_host_u64(mp->local_cookie[0]));
7187 vat_json_array_add_uint(lc, clib_net_to_host_u64(mp->local_cookie[1]));
7188 vat_json_object_add_uint(node, "remote_cookie", clib_net_to_host_u64(mp->remote_cookie));
7190 printf("local id: %u", clib_net_to_host_u32(mp->local_session_id));
7191 vat_json_object_add_uint(node, "local_session_id", clib_net_to_host_u32(mp->local_session_id));
7192 vat_json_object_add_uint(node, "remote_session_id", clib_net_to_host_u32(mp->remote_session_id));
7193 vat_json_object_add_string_copy(node, "l2_sublayer", mp->l2_sublayer_present ?
7194 (u8*)"present" : (u8*)"absent");
7197 static int api_sw_if_l2tpv3_tunnel_dump (vat_main_t * vam)
7199 vl_api_sw_if_l2tpv3_tunnel_dump_t *mp;
7202 /* Get list of l2tpv3-tunnel interfaces */
7203 M(SW_IF_L2TPV3_TUNNEL_DUMP, sw_if_l2tpv3_tunnel_dump);
7206 /* Use a control ping for synchronization */
7208 vl_api_control_ping_t * mp;
7209 M(CONTROL_PING, control_ping);
7216 static void vl_api_sw_interface_tap_details_t_handler
7217 (vl_api_sw_interface_tap_details_t * mp)
7219 vat_main_t * vam = &vat_main;
7221 fformat(vam->ofp, "%-16s %d\n",
7223 clib_net_to_host_u32(mp->sw_if_index));
7226 static void vl_api_sw_interface_tap_details_t_handler_json
7227 (vl_api_sw_interface_tap_details_t * mp)
7229 vat_main_t * vam = &vat_main;
7230 vat_json_node_t *node = NULL;
7232 if (VAT_JSON_ARRAY != vam->json_tree.type) {
7233 ASSERT(VAT_JSON_NONE == vam->json_tree.type);
7234 vat_json_init_array(&vam->json_tree);
7236 node = vat_json_array_add(&vam->json_tree);
7238 vat_json_init_object(node);
7239 vat_json_object_add_uint(node, "sw_if_index", ntohl(mp->sw_if_index));
7240 vat_json_object_add_string_copy(node, "dev_name", mp->dev_name);
7243 static int api_sw_interface_tap_dump (vat_main_t * vam)
7245 vl_api_sw_interface_tap_dump_t *mp;
7248 fformat(vam->ofp, "\n%-16s %s\n", "dev_name", "sw_if_index");
7249 /* Get list of tap interfaces */
7250 M(SW_INTERFACE_TAP_DUMP, sw_interface_tap_dump);
7253 /* Use a control ping for synchronization */
7255 vl_api_control_ping_t * mp;
7256 M(CONTROL_PING, control_ping);
7262 static uword unformat_vxlan_decap_next
7263 (unformat_input_t * input, va_list * args)
7265 u32 * result = va_arg (*args, u32 *);
7268 if (unformat (input, "drop"))
7269 *result = VXLAN_INPUT_NEXT_DROP;
7270 else if (unformat (input, "ip4"))
7271 *result = VXLAN_INPUT_NEXT_IP4_INPUT;
7272 else if (unformat (input, "ip6"))
7273 *result = VXLAN_INPUT_NEXT_IP6_INPUT;
7274 else if (unformat (input, "l2"))
7275 *result = VXLAN_INPUT_NEXT_L2_INPUT;
7276 else if (unformat (input, "%d", &tmp))
7283 static int api_vxlan_add_del_tunnel (vat_main_t * vam)
7285 unformat_input_t * line_input = vam->input;
7286 vl_api_vxlan_add_del_tunnel_t *mp;
7288 ip4_address_t src4, dst4;
7289 ip6_address_t src6, dst6;
7291 u8 ipv4_set = 0, ipv6_set = 0;
7294 u32 encap_vrf_id = 0;
7295 u32 decap_next_index = ~0;
7298 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) {
7299 if (unformat (line_input, "del"))
7301 else if (unformat (line_input, "src %U",
7302 unformat_ip4_address, &src4))
7307 else if (unformat (line_input, "dst %U",
7308 unformat_ip4_address, &dst4))
7313 else if (unformat (line_input, "src %U",
7314 unformat_ip6_address, &src6))
7319 else if (unformat (line_input, "dst %U",
7320 unformat_ip6_address, &dst6))
7325 else if (unformat (line_input, "encap-vrf-id %d", &encap_vrf_id))
7327 else if (unformat (line_input, "decap-next %U",
7328 unformat_vxlan_decap_next, &decap_next_index))
7330 else if (unformat (line_input, "vni %d", &vni))
7333 errmsg ("parse error '%U'\n", format_unformat_error, line_input);
7339 errmsg ("tunnel src address not specified\n");
7343 errmsg ("tunnel dst address not specified\n");
7347 if (ipv4_set && ipv6_set) {
7348 errmsg ("both IPv4 and IPv6 addresses specified");
7352 if ((vni == 0) || (vni>>24)) {
7353 errmsg ("vni not specified or out of range\n");
7357 M (VXLAN_ADD_DEL_TUNNEL, vxlan_add_del_tunnel);
7360 clib_memcpy(&mp->dst_address, &src6, sizeof(src6));
7361 clib_memcpy(&mp->dst_address, &src6, sizeof(dst6));
7363 clib_memcpy(&mp->src_address, &src4, sizeof(src4));
7364 clib_memcpy(&mp->dst_address, &dst4, sizeof(dst4));
7366 mp->encap_vrf_id = ntohl(encap_vrf_id);
7367 mp->decap_next_index = ntohl(decap_next_index);
7368 mp->vni = ntohl(vni);
7369 mp->is_add = is_add;
7370 mp->is_ipv6 = ipv6_set;
7377 static void vl_api_vxlan_tunnel_details_t_handler
7378 (vl_api_vxlan_tunnel_details_t * mp)
7380 vat_main_t * vam = &vat_main;
7382 fformat(vam->ofp, "%11d%24U%24U%14d%18d%13d\n",
7383 ntohl(mp->sw_if_index),
7384 format_ip46_address, &(mp->src_address[0]),
7385 format_ip46_address, &(mp->dst_address[0]),
7386 ntohl(mp->encap_vrf_id),
7387 ntohl(mp->decap_next_index),
7391 static void vl_api_vxlan_tunnel_details_t_handler_json
7392 (vl_api_vxlan_tunnel_details_t * mp)
7394 vat_main_t * vam = &vat_main;
7395 vat_json_node_t *node = NULL;
7397 struct in6_addr ip6;
7399 if (VAT_JSON_ARRAY != vam->json_tree.type) {
7400 ASSERT(VAT_JSON_NONE == vam->json_tree.type);
7401 vat_json_init_array(&vam->json_tree);
7403 node = vat_json_array_add(&vam->json_tree);
7405 vat_json_init_object(node);
7406 vat_json_object_add_uint(node, "sw_if_index", ntohl(mp->sw_if_index));
7408 clib_memcpy(&ip6, &(mp->src_address[0]), sizeof(ip6));
7409 vat_json_object_add_ip6(node, "src_address", ip6);
7410 clib_memcpy(&ip6, &(mp->dst_address[0]), sizeof(ip6));
7411 vat_json_object_add_ip6(node, "dst_address", ip6);
7413 clib_memcpy(&ip4, &(mp->src_address[0]), sizeof(ip4));
7414 vat_json_object_add_ip4(node, "src_address", ip4);
7415 clib_memcpy(&ip4, &(mp->dst_address[0]), sizeof(ip4));
7416 vat_json_object_add_ip4(node, "dst_address", ip4);
7418 vat_json_object_add_uint(node, "encap_vrf_id", ntohl(mp->encap_vrf_id));
7419 vat_json_object_add_uint(node, "decap_next_index", ntohl(mp->decap_next_index));
7420 vat_json_object_add_uint(node, "vni", ntohl(mp->vni));
7421 vat_json_object_add_uint(node, "is_ipv6", mp->is_ipv6 ? 1 : 0);
7424 static int api_vxlan_tunnel_dump (vat_main_t * vam)
7426 unformat_input_t * i = vam->input;
7427 vl_api_vxlan_tunnel_dump_t *mp;
7430 u8 sw_if_index_set = 0;
7432 /* Parse args required to build the message */
7433 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
7434 if (unformat (i, "sw_if_index %d", &sw_if_index))
7435 sw_if_index_set = 1;
7440 if (sw_if_index_set == 0) {
7444 if (!vam->json_output) {
7445 fformat(vam->ofp, "%11s%24s%24s%14s%18s%13s\n",
7446 "sw_if_index", "src_address", "dst_address",
7447 "encap_vrf_id", "decap_next_index", "vni");
7450 /* Get list of vxlan-tunnel interfaces */
7451 M(VXLAN_TUNNEL_DUMP, vxlan_tunnel_dump);
7453 mp->sw_if_index = htonl(sw_if_index);
7457 /* Use a control ping for synchronization */
7459 vl_api_control_ping_t * mp;
7460 M(CONTROL_PING, control_ping);
7466 static int api_gre_add_del_tunnel (vat_main_t * vam)
7468 unformat_input_t * line_input = vam->input;
7469 vl_api_gre_add_del_tunnel_t *mp;
7471 ip4_address_t src4, dst4;
7475 u32 outer_fib_id = 0;
7477 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) {
7478 if (unformat (line_input, "del"))
7480 else if (unformat (line_input, "src %U",
7481 unformat_ip4_address, &src4))
7483 else if (unformat (line_input, "dst %U",
7484 unformat_ip4_address, &dst4))
7486 else if (unformat (line_input, "outer-fib-id %d", &outer_fib_id))
7489 errmsg ("parse error '%U'\n", format_unformat_error, line_input);
7495 errmsg ("tunnel src address not specified\n");
7499 errmsg ("tunnel dst address not specified\n");
7504 M (GRE_ADD_DEL_TUNNEL, gre_add_del_tunnel);
7506 clib_memcpy(&mp->src_address, &src4, sizeof(src4));
7507 clib_memcpy(&mp->dst_address, &dst4, sizeof(dst4));
7508 mp->outer_table_id = ntohl(outer_fib_id);
7509 mp->is_add = is_add;
7516 static void vl_api_gre_tunnel_details_t_handler
7517 (vl_api_gre_tunnel_details_t * mp)
7519 vat_main_t * vam = &vat_main;
7521 fformat(vam->ofp, "%11d%15U%15U%14d\n",
7522 ntohl(mp->sw_if_index),
7523 format_ip4_address, &mp->src_address,
7524 format_ip4_address, &mp->dst_address,
7525 ntohl(mp->outer_table_id));
7528 static void vl_api_gre_tunnel_details_t_handler_json
7529 (vl_api_gre_tunnel_details_t * mp)
7531 vat_main_t * vam = &vat_main;
7532 vat_json_node_t *node = NULL;
7535 if (VAT_JSON_ARRAY != vam->json_tree.type) {
7536 ASSERT(VAT_JSON_NONE == vam->json_tree.type);
7537 vat_json_init_array(&vam->json_tree);
7539 node = vat_json_array_add(&vam->json_tree);
7541 vat_json_init_object(node);
7542 vat_json_object_add_uint(node, "sw_if_index", ntohl(mp->sw_if_index));
7543 clib_memcpy(&ip4, &mp->src_address, sizeof(ip4));
7544 vat_json_object_add_ip4(node, "src_address", ip4);
7545 clib_memcpy(&ip4, &mp->dst_address, sizeof(ip4));
7546 vat_json_object_add_ip4(node, "dst_address", ip4);
7547 vat_json_object_add_uint(node, "outer_fib_id", ntohl(mp->outer_table_id));
7550 static int api_gre_tunnel_dump (vat_main_t * vam)
7552 unformat_input_t * i = vam->input;
7553 vl_api_gre_tunnel_dump_t *mp;
7556 u8 sw_if_index_set = 0;
7558 /* Parse args required to build the message */
7559 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
7560 if (unformat (i, "sw_if_index %d", &sw_if_index))
7561 sw_if_index_set = 1;
7566 if (sw_if_index_set == 0) {
7570 if (!vam->json_output) {
7571 fformat(vam->ofp, "%11s%15s%15s%14s\n",
7572 "sw_if_index", "src_address", "dst_address",
7576 /* Get list of gre-tunnel interfaces */
7577 M(GRE_TUNNEL_DUMP, gre_tunnel_dump);
7579 mp->sw_if_index = htonl(sw_if_index);
7583 /* Use a control ping for synchronization */
7585 vl_api_control_ping_t * mp;
7586 M(CONTROL_PING, control_ping);
7592 static int api_l2_fib_clear_table (vat_main_t * vam)
7594 // unformat_input_t * i = vam->input;
7595 vl_api_l2_fib_clear_table_t *mp;
7598 M(L2_FIB_CLEAR_TABLE, l2_fib_clear_table);
7605 static int api_l2_interface_efp_filter (vat_main_t * vam)
7607 unformat_input_t * i = vam->input;
7608 vl_api_l2_interface_efp_filter_t *mp;
7612 u8 sw_if_index_set = 0;
7614 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
7615 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
7616 sw_if_index_set = 1;
7617 else if (unformat (i, "sw_if_index %d", &sw_if_index))
7618 sw_if_index_set = 1;
7619 else if (unformat (i, "enable"))
7621 else if (unformat (i, "disable"))
7624 clib_warning ("parse error '%U'", format_unformat_error, i);
7629 if (sw_if_index_set == 0) {
7630 errmsg ("missing sw_if_index\n");
7634 M(L2_INTERFACE_EFP_FILTER, l2_interface_efp_filter);
7636 mp->sw_if_index = ntohl(sw_if_index);
7637 mp->enable_disable = enable;
7644 #define foreach_vtr_op \
7645 _("disable", L2_VTR_DISABLED) \
7646 _("push-1", L2_VTR_PUSH_1) \
7647 _("push-2", L2_VTR_PUSH_2) \
7648 _("pop-1", L2_VTR_POP_1) \
7649 _("pop-2", L2_VTR_POP_2) \
7650 _("translate-1-1", L2_VTR_TRANSLATE_1_1) \
7651 _("translate-1-2", L2_VTR_TRANSLATE_1_2) \
7652 _("translate-2-1", L2_VTR_TRANSLATE_2_1) \
7653 _("translate-2-2", L2_VTR_TRANSLATE_2_2)
7655 static int api_l2_interface_vlan_tag_rewrite (vat_main_t * vam)
7657 unformat_input_t * i = vam->input;
7658 vl_api_l2_interface_vlan_tag_rewrite_t *mp;
7661 u8 sw_if_index_set = 0;
7668 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
7669 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
7670 sw_if_index_set = 1;
7671 else if (unformat (i, "sw_if_index %d", &sw_if_index))
7672 sw_if_index_set = 1;
7673 else if (unformat (i, "vtr_op %d", &vtr_op))
7675 #define _(n,v) else if (unformat(i, n)) {vtr_op = v; vtr_op_set = 1;}
7679 else if (unformat (i, "push_dot1q %d", &push_dot1q))
7681 else if (unformat (i, "tag1 %d", &tag1))
7683 else if (unformat (i, "tag2 %d", &tag2))
7686 clib_warning ("parse error '%U'", format_unformat_error, i);
7691 if ((sw_if_index_set == 0)||(vtr_op_set == 0)) {
7692 errmsg ("missing vtr operation or sw_if_index\n");
7696 M(L2_INTERFACE_VLAN_TAG_REWRITE, l2_interface_vlan_tag_rewrite)
7698 mp->sw_if_index = ntohl(sw_if_index);
7699 mp->vtr_op = ntohl(vtr_op);
7700 mp->push_dot1q = ntohl(push_dot1q);
7701 mp->tag1 = ntohl(tag1);
7702 mp->tag2 = ntohl(tag2);
7709 static int api_create_vhost_user_if (vat_main_t * vam)
7711 unformat_input_t * i = vam->input;
7712 vl_api_create_vhost_user_if_t *mp;
7716 u8 file_name_set = 0;
7717 u32 custom_dev_instance = ~0;
7719 u8 use_custom_mac = 0;
7721 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
7722 if (unformat (i, "socket %s", &file_name)) {
7725 else if (unformat (i, "renumber %"PRIu32, &custom_dev_instance))
7727 else if (unformat (i, "mac %U", unformat_ethernet_address, hwaddr))
7729 else if (unformat (i, "server"))
7735 if (file_name_set == 0) {
7736 errmsg ("missing socket file name\n");
7740 if (vec_len (file_name) > 255) {
7741 errmsg ("socket file name too long\n");
7744 vec_add1 (file_name, 0);
7746 M(CREATE_VHOST_USER_IF, create_vhost_user_if);
7748 mp->is_server = is_server;
7749 clib_memcpy(mp->sock_filename, file_name, vec_len(file_name));
7750 vec_free(file_name);
7751 if (custom_dev_instance != ~0) {
7753 mp->custom_dev_instance = ntohl(custom_dev_instance);
7755 mp->use_custom_mac = use_custom_mac;
7756 clib_memcpy(mp->mac_address, hwaddr, 6);
7763 static int api_modify_vhost_user_if (vat_main_t * vam)
7765 unformat_input_t * i = vam->input;
7766 vl_api_modify_vhost_user_if_t *mp;
7770 u8 file_name_set = 0;
7771 u32 custom_dev_instance = ~0;
7772 u8 sw_if_index_set = 0;
7773 u32 sw_if_index = (u32)~0;
7775 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
7776 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
7777 sw_if_index_set = 1;
7778 else if (unformat (i, "sw_if_index %d", &sw_if_index))
7779 sw_if_index_set = 1;
7780 else if (unformat (i, "socket %s", &file_name)) {
7783 else if (unformat (i, "renumber %"PRIu32, &custom_dev_instance))
7785 else if (unformat (i, "server"))
7791 if (sw_if_index_set == 0) {
7792 errmsg ("missing sw_if_index or interface name\n");
7796 if (file_name_set == 0) {
7797 errmsg ("missing socket file name\n");
7801 if (vec_len (file_name) > 255) {
7802 errmsg ("socket file name too long\n");
7805 vec_add1 (file_name, 0);
7807 M(MODIFY_VHOST_USER_IF, modify_vhost_user_if);
7809 mp->sw_if_index = ntohl(sw_if_index);
7810 mp->is_server = is_server;
7811 clib_memcpy(mp->sock_filename, file_name, vec_len(file_name));
7812 vec_free(file_name);
7813 if (custom_dev_instance != ~0) {
7815 mp->custom_dev_instance = ntohl(custom_dev_instance);
7823 static int api_delete_vhost_user_if (vat_main_t * vam)
7825 unformat_input_t * i = vam->input;
7826 vl_api_delete_vhost_user_if_t *mp;
7828 u32 sw_if_index = ~0;
7829 u8 sw_if_index_set = 0;
7831 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
7832 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
7833 sw_if_index_set = 1;
7834 else if (unformat (i, "sw_if_index %d", &sw_if_index))
7835 sw_if_index_set = 1;
7840 if (sw_if_index_set == 0) {
7841 errmsg ("missing sw_if_index or interface name\n");
7846 M(DELETE_VHOST_USER_IF, delete_vhost_user_if);
7848 mp->sw_if_index = ntohl(sw_if_index);
7855 static void vl_api_sw_interface_vhost_user_details_t_handler
7856 (vl_api_sw_interface_vhost_user_details_t * mp)
7858 vat_main_t * vam = &vat_main;
7860 fformat(vam->ofp, "%-25s %3" PRIu32 " %6" PRIu32 " %8x %6d %7d %s\n",
7861 (char *)mp->interface_name,
7862 ntohl(mp->sw_if_index), ntohl(mp->virtio_net_hdr_sz),
7863 clib_net_to_host_u64(mp->features), mp->is_server,
7864 ntohl(mp->num_regions), (char *)mp->sock_filename);
7865 fformat(vam->ofp, " Status: '%s'\n", strerror(ntohl(mp->sock_errno)));
7868 static void vl_api_sw_interface_vhost_user_details_t_handler_json
7869 (vl_api_sw_interface_vhost_user_details_t * mp)
7871 vat_main_t * vam = &vat_main;
7872 vat_json_node_t *node = NULL;
7874 if (VAT_JSON_ARRAY != vam->json_tree.type) {
7875 ASSERT(VAT_JSON_NONE == vam->json_tree.type);
7876 vat_json_init_array(&vam->json_tree);
7878 node = vat_json_array_add(&vam->json_tree);
7880 vat_json_init_object(node);
7881 vat_json_object_add_uint(node, "sw_if_index", ntohl(mp->sw_if_index));
7882 vat_json_object_add_string_copy(node, "interface_name", mp->interface_name);
7883 vat_json_object_add_uint(node, "virtio_net_hdr_sz", ntohl(mp->virtio_net_hdr_sz));
7884 vat_json_object_add_uint(node, "features", clib_net_to_host_u64(mp->features));
7885 vat_json_object_add_uint(node, "is_server", mp->is_server);
7886 vat_json_object_add_string_copy(node, "sock_filename", mp->sock_filename);
7887 vat_json_object_add_uint(node, "num_regions", ntohl(mp->num_regions));
7888 vat_json_object_add_uint(node, "sock_errno", ntohl(mp->sock_errno));
7891 static int api_sw_interface_vhost_user_dump (vat_main_t * vam)
7893 vl_api_sw_interface_vhost_user_dump_t *mp;
7895 fformat(vam->ofp, "Interface name idx hdr_sz features server regions filename\n");
7897 /* Get list of vhost-user interfaces */
7898 M(SW_INTERFACE_VHOST_USER_DUMP, sw_interface_vhost_user_dump);
7901 /* Use a control ping for synchronization */
7903 vl_api_control_ping_t * mp;
7904 M(CONTROL_PING, control_ping);
7910 static int api_show_version (vat_main_t * vam)
7912 vl_api_show_version_t *mp;
7915 M(SHOW_VERSION, show_version);
7922 static uword unformat_nsh_gre_decap_next
7923 (unformat_input_t * input, va_list * args)
7925 u32 * result = va_arg (*args, u32 *);
7928 if (unformat (input, "drop"))
7929 *result = NSH_GRE_INPUT_NEXT_DROP;
7930 else if (unformat (input, "ip4"))
7931 *result = NSH_GRE_INPUT_NEXT_IP4_INPUT;
7932 else if (unformat (input, "ip6"))
7933 *result = NSH_GRE_INPUT_NEXT_IP6_INPUT;
7934 else if (unformat (input, "ethernet"))
7935 *result = NSH_GRE_INPUT_NEXT_ETHERNET_INPUT;
7936 else if (unformat (input, "%d", &tmp))
7943 static int api_nsh_gre_add_del_tunnel (vat_main_t * vam)
7945 unformat_input_t * line_input = vam->input;
7946 vl_api_nsh_gre_add_del_tunnel_t *mp;
7948 ip4_address_t src, dst;
7952 u32 encap_vrf_id = 0;
7953 u32 decap_vrf_id = 0;
7956 u8 next_protocol = 1; /* ip4 */
7967 u32 decap_next_index = NSH_GRE_INPUT_NEXT_IP4_INPUT;
7971 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) {
7972 if (unformat (line_input, "del"))
7974 else if (unformat (line_input, "src %U",
7975 unformat_ip4_address, &src))
7977 else if (unformat (line_input, "dst %U",
7978 unformat_ip4_address, &dst))
7980 else if (unformat (line_input, "encap-vrf-id %d", &encap_vrf_id))
7982 else if (unformat (line_input, "decap-vrf-id %d", &decap_vrf_id))
7984 else if (unformat (line_input, "decap-next %U",
7985 unformat_nsh_gre_decap_next, &decap_next_index))
7987 else if (unformat (line_input, "version %d", &tmp))
7988 ver_o_c |= (tmp & 3) << 6;
7989 else if (unformat (line_input, "o-bit %d", &tmp))
7990 ver_o_c |= (tmp & 1) << 5;
7991 else if (unformat (line_input, "c-bit %d", &tmp))
7992 ver_o_c |= (tmp & 1) << 4;
7993 else if (unformat (line_input, "md-type %d", &tmp))
7995 else if (unformat(line_input, "next-ip4"))
7997 else if (unformat(line_input, "next-ip6"))
7999 else if (unformat(line_input, "next-ethernet"))
8001 else if (unformat (line_input, "c1 %d", &c1))
8003 else if (unformat (line_input, "c2 %d", &c2))
8005 else if (unformat (line_input, "c3 %d", &c3))
8007 else if (unformat (line_input, "c4 %d", &c4))
8009 else if (unformat (line_input, "spi %d", &spi))
8011 else if (unformat (line_input, "si %d", &si))
8013 else if (unformat (line_input, "tlv %x"))
8014 vec_add1 (tlvs, tmp);
8016 errmsg ("parse error '%U'\n", format_unformat_error, line_input);
8022 errmsg ("tunnel src address not specified\n");
8026 errmsg ("tunnel dst address not specified\n");
8031 errmsg ("spi not specified\n");
8036 errmsg ("si not specified\n");
8040 M2 (NSH_GRE_ADD_DEL_TUNNEL, nsh_gre_add_del_tunnel,
8041 sizeof(u32) * vec_len (tlvs));
8043 spi_si = (spi<<8) | si;
8045 mp->src = src.as_u32;
8046 mp->dst = dst.as_u32;
8047 mp->encap_vrf_id = ntohl(encap_vrf_id);
8048 mp->decap_vrf_id = ntohl(decap_vrf_id);
8049 mp->decap_next_index = ntohl(decap_next_index);
8050 mp->tlv_len_in_words = vec_len (tlvs);
8051 mp->is_add = is_add;
8052 mp->ver_o_c = ver_o_c;
8053 mp->length = 6 + vec_len(tlvs);
8054 mp->md_type = md_type;
8055 mp->next_protocol = next_protocol;
8056 mp->spi_si = ntohl(spi_si);
8062 for (i = 0; i < vec_len(tlvs); i++)
8063 mp->tlvs[i] = ntohl(tlvs[i]);
8072 static uword unformat_nsh_vxlan_gpe_decap_next
8073 (unformat_input_t * input, va_list * args)
8075 u32 * result = va_arg (*args, u32 *);
8078 if (unformat (input, "drop"))
8079 *result = NSH_VXLAN_GPE_INPUT_NEXT_DROP;
8080 else if (unformat (input, "ip4"))
8081 *result = NSH_VXLAN_GPE_INPUT_NEXT_IP4_INPUT;
8082 else if (unformat (input, "ip6"))
8083 *result = NSH_VXLAN_GPE_INPUT_NEXT_IP6_INPUT;
8084 else if (unformat (input, "ethernet"))
8085 *result = NSH_VXLAN_GPE_INPUT_NEXT_ETHERNET_INPUT;
8086 else if (unformat (input, "nsh-vxlan-gpe"))
8087 *result = NSH_VXLAN_GPE_INPUT_NEXT_ETHERNET_INPUT;
8088 else if (unformat (input, "%d", &tmp))
8095 static int api_nsh_vxlan_gpe_add_del_tunnel (vat_main_t * vam)
8097 unformat_input_t * line_input = vam->input;
8098 vl_api_nsh_vxlan_gpe_add_del_tunnel_t *mp;
8100 ip4_address_t src, dst;
8104 u32 encap_vrf_id = 0;
8105 u32 decap_vrf_id = 0;
8108 u8 next_protocol = 1; /* ip4 */
8119 u32 decap_next_index = NSH_GRE_INPUT_NEXT_IP4_INPUT;
8125 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) {
8126 if (unformat (line_input, "del"))
8128 else if (unformat (line_input, "src %U",
8129 unformat_ip4_address, &src))
8131 else if (unformat (line_input, "dst %U",
8132 unformat_ip4_address, &dst))
8134 else if (unformat (line_input, "encap-vrf-id %d", &encap_vrf_id))
8136 else if (unformat (line_input, "decap-vrf-id %d", &decap_vrf_id))
8138 else if (unformat (line_input, "decap-next %U",
8139 unformat_nsh_vxlan_gpe_decap_next,
8142 else if (unformat (line_input, "vni %d", &vni))
8144 else if (unformat (line_input, "version %d", &tmp))
8145 ver_o_c |= (tmp & 3) << 6;
8146 else if (unformat (line_input, "o-bit %d", &tmp))
8147 ver_o_c |= (tmp & 1) << 5;
8148 else if (unformat (line_input, "c-bit %d", &tmp))
8149 ver_o_c |= (tmp & 1) << 4;
8150 else if (unformat (line_input, "md-type %d", &tmp))
8152 else if (unformat(line_input, "next-ip4"))
8154 else if (unformat(line_input, "next-ip6"))
8156 else if (unformat(line_input, "next-ethernet"))
8158 else if (unformat (line_input, "c1 %d", &c1))
8160 else if (unformat (line_input, "c2 %d", &c2))
8162 else if (unformat (line_input, "c3 %d", &c3))
8164 else if (unformat (line_input, "c4 %d", &c4))
8166 else if (unformat (line_input, "spi %d", &spi))
8168 else if (unformat (line_input, "si %d", &si))
8170 else if (unformat (line_input, "tlv %x"))
8171 vec_add1 (tlvs, tmp);
8173 errmsg ("parse error '%U'\n", format_unformat_error, line_input);
8179 errmsg ("tunnel src address not specified\n");
8183 errmsg ("tunnel dst address not specified\n");
8188 errmsg ("spi not specified\n");
8193 errmsg ("si not specified\n");
8197 errmsg ("vni not specified\n");
8201 M2 (NSH_VXLAN_GPE_ADD_DEL_TUNNEL, nsh_vxlan_gpe_add_del_tunnel,
8202 sizeof(u32) * vec_len (tlvs));
8204 spi_si = (spi<<8) | si;
8206 mp->src = src.as_u32;
8207 mp->dst = dst.as_u32;
8208 mp->encap_vrf_id = ntohl(encap_vrf_id);
8209 mp->decap_vrf_id = ntohl(decap_vrf_id);
8210 mp->decap_next_index = ntohl(decap_next_index);
8211 mp->tlv_len_in_words = vec_len (tlvs);
8212 mp->vni = ntohl(vni);
8213 mp->is_add = is_add;
8214 mp->ver_o_c = ver_o_c;
8215 mp->length = 6 + vec_len(tlvs);
8216 mp->md_type = md_type;
8217 mp->next_protocol = next_protocol;
8218 mp->spi_si = ntohl(spi_si);
8224 for (i = 0; i < vec_len(tlvs); i++)
8225 mp->tlvs[i] = ntohl(tlvs[i]);
8234 static uword unformat_lisp_gpe_decap_next (unformat_input_t * input,
8237 u32 * result = va_arg (*args, u32 *);
8240 if (unformat (input, "drop"))
8241 *result = LISP_GPE_INPUT_NEXT_DROP;
8242 else if (unformat (input, "ip4"))
8243 *result = LISP_GPE_INPUT_NEXT_IP4_INPUT;
8244 else if (unformat (input, "ip6"))
8245 *result = LISP_GPE_INPUT_NEXT_IP6_INPUT;
8246 else if (unformat (input, "ethernet"))
8247 *result = LISP_GPE_INPUT_NEXT_IP6_INPUT;
8248 else if (unformat (input, "%d", &tmp))
8256 api_lisp_gpe_add_del_tunnel (vat_main_t * vam)
8258 unformat_input_t * line_input = vam->input;
8259 vl_api_lisp_gpe_add_del_tunnel_t *mp;
8261 ip4_address_t src, dst;
8265 u32 encap_vrf_id = 0;
8266 u32 decap_vrf_id = 0;
8267 u8 next_protocol = LISP_GPE_NEXT_PROTOCOL_IP4;
8268 u32 decap_next_index = LISP_GPE_INPUT_NEXT_IP4_INPUT;
8269 u8 flags = LISP_GPE_FLAGS_P;
8276 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) {
8277 if (unformat (line_input, "del"))
8279 else if (unformat (line_input, "src %U",
8280 unformat_ip4_address, &src))
8282 else if (unformat (line_input, "dst %U",
8283 unformat_ip4_address, &dst))
8285 else if (unformat (line_input, "encap-vrf-id %d", &encap_vrf_id))
8287 else if (unformat (line_input, "decap-vrf-id %d", &decap_vrf_id))
8289 else if (unformat (line_input, "decap-next %U",
8290 unformat_lisp_gpe_decap_next,
8293 else if (unformat(line_input, "next-ip4"))
8295 else if (unformat(line_input, "next-ip6"))
8297 else if (unformat(line_input, "next-ethernet"))
8299 else if (unformat(line_input, "next-nsh"))
8301 /* Allow the user to specify anything they want in the LISP hdr */
8302 else if (unformat (line_input, "ver_res %x", &tmp))
8304 else if (unformat (line_input, "res %x", &tmp))
8306 else if (unformat (line_input, "flags %x", &tmp))
8308 else if (unformat (line_input, "n-bit"))
8309 flags |= LISP_GPE_FLAGS_N;
8310 else if (unformat (line_input, "l-bit"))
8311 flags |= LISP_GPE_FLAGS_L;
8312 else if (unformat (line_input, "e-bit"))
8313 flags |= LISP_GPE_FLAGS_E;
8314 else if (unformat (line_input, "v-bit"))
8315 flags |= LISP_GPE_FLAGS_V;
8316 else if (unformat (line_input, "i-bit"))
8317 flags |= LISP_GPE_FLAGS_V;
8318 else if (unformat (line_input, "not-p-bit"))
8319 flags &= !LISP_GPE_FLAGS_P;
8320 else if (unformat (line_input, "p-bit"))
8321 flags |= LISP_GPE_FLAGS_P;
8322 else if (unformat (line_input, "o-bit"))
8323 flags |= LISP_GPE_FLAGS_O;
8324 else if (unformat (line_input, "iidx %x", &iid))
8326 else if (unformat (line_input, "iid %d", &iid))
8329 errmsg ("parse error '%U'\n", format_unformat_error, line_input);
8335 errmsg ("tunnel src address not specified\n");
8339 errmsg ("tunnel dst address not specified\n");
8343 errmsg ("iid not specified\n");
8347 M(LISP_GPE_ADD_DEL_TUNNEL, lisp_gpe_add_del_tunnel);
8349 mp->src = src.as_u32;
8350 mp->dst = dst.as_u32;
8351 mp->encap_vrf_id = ntohl(encap_vrf_id);
8352 mp->decap_vrf_id = ntohl(decap_vrf_id);
8353 mp->decap_next_index = ntohl(decap_next_index);
8354 mp->is_add = is_add;
8356 mp->ver_res = ver_res;
8358 mp->next_protocol = next_protocol;
8359 mp->iid = ntohl(iid);
8368 u8 * format_l2_fib_mac_address (u8 * s, va_list * args)
8370 u8 * a = va_arg (*args, u8 *);
8372 return format (s, "%02x:%02x:%02x:%02x:%02x:%02x",
8373 a[2], a[3], a[4], a[5], a[6], a[7]);
8376 static void vl_api_l2_fib_table_entry_t_handler
8377 (vl_api_l2_fib_table_entry_t * mp)
8379 vat_main_t * vam = &vat_main;
8381 fformat(vam->ofp, "%3" PRIu32 " %U %3" PRIu32
8383 ntohl(mp->bd_id), format_l2_fib_mac_address, &mp->mac,
8384 ntohl(mp->sw_if_index), mp->static_mac, mp->filter_mac,
8388 static void vl_api_l2_fib_table_entry_t_handler_json
8389 (vl_api_l2_fib_table_entry_t * mp)
8391 vat_main_t * vam = &vat_main;
8392 vat_json_node_t *node = NULL;
8394 if (VAT_JSON_ARRAY != vam->json_tree.type) {
8395 ASSERT(VAT_JSON_NONE == vam->json_tree.type);
8396 vat_json_init_array(&vam->json_tree);
8398 node = vat_json_array_add(&vam->json_tree);
8400 vat_json_init_object(node);
8401 vat_json_object_add_uint(node, "bd_id", ntohl(mp->bd_id));
8402 vat_json_object_add_uint(node, "mac", clib_net_to_host_u64(mp->mac));
8403 vat_json_object_add_uint(node, "sw_if_index", ntohl(mp->sw_if_index));
8404 vat_json_object_add_uint(node, "static_mac", mp->static_mac);
8405 vat_json_object_add_uint(node, "filter_mac", mp->filter_mac);
8406 vat_json_object_add_uint(node, "bvi_mac", mp->bvi_mac);
8409 static int api_l2_fib_table_dump (vat_main_t * vam)
8411 unformat_input_t * i = vam->input;
8412 vl_api_l2_fib_table_dump_t *mp;
8417 /* Parse args required to build the message */
8418 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
8419 if (unformat (i, "bd_id %d", &bd_id))
8425 if (bd_id_set == 0) {
8426 errmsg ("missing bridge domain\n");
8430 fformat(vam->ofp, "BD-ID Mac Address sw-ndx Static Filter BVI\n");
8432 /* Get list of l2 fib entries */
8433 M(L2_FIB_TABLE_DUMP, l2_fib_table_dump);
8435 mp->bd_id = ntohl(bd_id);
8438 /* Use a control ping for synchronization */
8440 vl_api_control_ping_t * mp;
8441 M(CONTROL_PING, control_ping);
8449 api_interface_name_renumber (vat_main_t * vam)
8451 unformat_input_t * line_input = vam->input;
8452 vl_api_interface_name_renumber_t *mp;
8453 u32 sw_if_index = ~0;
8455 u32 new_show_dev_instance = ~0;
8457 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) {
8458 if (unformat (line_input, "%U", unformat_sw_if_index, vam,
8461 else if (unformat (line_input, "sw_if_index %d", &sw_if_index))
8463 else if (unformat (line_input, "new_show_dev_instance %d",
8464 &new_show_dev_instance))
8470 if (sw_if_index == ~0) {
8471 errmsg ("missing interface name or sw_if_index\n");
8475 if (new_show_dev_instance == ~0) {
8476 errmsg ("missing new_show_dev_instance\n");
8480 M(INTERFACE_NAME_RENUMBER, interface_name_renumber);
8482 mp->sw_if_index = ntohl (sw_if_index);
8483 mp->new_show_dev_instance = ntohl (new_show_dev_instance);
8489 api_want_ip4_arp_events (vat_main_t * vam)
8491 unformat_input_t * line_input = vam->input;
8492 vl_api_want_ip4_arp_events_t * mp;
8494 ip4_address_t address;
8495 int address_set = 0;
8496 u32 enable_disable = 1;
8498 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) {
8499 if (unformat (line_input, "address %U",
8500 unformat_ip4_address, &address))
8502 else if (unformat (line_input, "del"))
8508 if (address_set == 0) {
8509 errmsg ("missing addresses\n");
8513 M(WANT_IP4_ARP_EVENTS, want_ip4_arp_events);
8514 mp->enable_disable = enable_disable;
8516 mp->address = address.as_u32;
8521 static int api_input_acl_set_interface (vat_main_t * vam)
8523 unformat_input_t * i = vam->input;
8524 vl_api_input_acl_set_interface_t *mp;
8527 int sw_if_index_set;
8528 u32 ip4_table_index = ~0;
8529 u32 ip6_table_index = ~0;
8530 u32 l2_table_index = ~0;
8533 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
8534 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
8535 sw_if_index_set = 1;
8536 else if (unformat (i, "sw_if_index %d", &sw_if_index))
8537 sw_if_index_set = 1;
8538 else if (unformat (i, "del"))
8540 else if (unformat (i, "ip4-table %d", &ip4_table_index))
8542 else if (unformat (i, "ip6-table %d", &ip6_table_index))
8544 else if (unformat (i, "l2-table %d", &l2_table_index))
8547 clib_warning ("parse error '%U'", format_unformat_error, i);
8552 if (sw_if_index_set == 0) {
8553 errmsg ("missing interface name or sw_if_index\n");
8557 M(INPUT_ACL_SET_INTERFACE, input_acl_set_interface);
8559 mp->sw_if_index = ntohl(sw_if_index);
8560 mp->ip4_table_index = ntohl(ip4_table_index);
8561 mp->ip6_table_index = ntohl(ip6_table_index);
8562 mp->l2_table_index = ntohl(l2_table_index);
8563 mp->is_add = is_add;
8571 api_ip_address_dump (vat_main_t * vam)
8573 unformat_input_t * i = vam->input;
8574 vl_api_ip_address_dump_t * mp;
8575 u32 sw_if_index = ~0;
8576 u8 sw_if_index_set = 0;
8581 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
8582 if (unformat (i, "sw_if_index %d", &sw_if_index))
8583 sw_if_index_set = 1;
8584 else if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
8585 sw_if_index_set = 1;
8586 else if (unformat (i, "ipv4"))
8588 else if (unformat (i, "ipv6"))
8594 if (ipv4_set && ipv6_set) {
8595 errmsg ("ipv4 and ipv6 flags cannot be both set\n");
8599 if ((!ipv4_set) && (!ipv6_set)) {
8600 errmsg ("no ipv4 nor ipv6 flag set\n");
8604 if (sw_if_index_set == 0) {
8605 errmsg ("missing interface name or sw_if_index\n");
8609 vam->current_sw_if_index = sw_if_index;
8610 vam->is_ipv6 = ipv6_set;
8612 M(IP_ADDRESS_DUMP, ip_address_dump);
8613 mp->sw_if_index = ntohl(sw_if_index);
8614 mp->is_ipv6 = ipv6_set;
8617 /* Use a control ping for synchronization */
8619 vl_api_control_ping_t * mp;
8620 M(CONTROL_PING, control_ping);
8627 api_ip_dump (vat_main_t * vam)
8629 vl_api_ip_dump_t * mp;
8630 unformat_input_t * in = vam->input;
8637 while (unformat_check_input (in) != UNFORMAT_END_OF_INPUT) {
8638 if (unformat (in, "ipv4"))
8640 else if (unformat (in, "ipv6"))
8646 if (ipv4_set && ipv6_set) {
8647 errmsg ("ipv4 and ipv6 flags cannot be both set\n");
8651 if ((!ipv4_set) && (!ipv6_set)) {
8652 errmsg ("no ipv4 nor ipv6 flag set\n");
8657 vam->is_ipv6 = is_ipv6;
8660 for (i = 0; i < vec_len(vam->ip_details_by_sw_if_index[is_ipv6]); i++) {
8661 vec_free(vam->ip_details_by_sw_if_index[is_ipv6][i].addr);
8663 vec_free(vam->ip_details_by_sw_if_index[is_ipv6]);
8665 M(IP_DUMP, ip_dump);
8666 mp->is_ipv6 = ipv6_set;
8669 /* Use a control ping for synchronization */
8671 vl_api_control_ping_t * mp;
8672 M(CONTROL_PING, control_ping);
8679 api_ipsec_spd_add_del (vat_main_t * vam)
8682 unformat_input_t * i = vam->input;
8683 vl_api_ipsec_spd_add_del_t *mp;
8688 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
8689 if (unformat (i, "spd_id %d", &spd_id))
8691 else if (unformat (i, "del"))
8694 clib_warning ("parse error '%U'", format_unformat_error, i);
8699 errmsg ("spd_id must be set\n");
8703 M(IPSEC_SPD_ADD_DEL, ipsec_spd_add_del);
8705 mp->spd_id = ntohl(spd_id);
8706 mp->is_add = is_add;
8712 clib_warning ("unsupported (no dpdk)");
8718 api_ipsec_interface_add_del_spd (vat_main_t * vam)
8721 unformat_input_t * i = vam->input;
8722 vl_api_ipsec_interface_add_del_spd_t *mp;
8725 u8 sw_if_index_set = 0;
8726 u32 spd_id = (u32) ~0;
8729 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
8730 if (unformat (i, "del"))
8732 else if (unformat (i, "spd_id %d", &spd_id))
8734 else if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
8735 sw_if_index_set = 1;
8736 else if (unformat (i, "sw_if_index %d", &sw_if_index))
8737 sw_if_index_set = 1;
8739 clib_warning ("parse error '%U'", format_unformat_error, i);
8745 if (spd_id == (u32) ~0) {
8746 errmsg ("spd_id must be set\n");
8750 if (sw_if_index_set == 0) {
8751 errmsg ("missing interface name or sw_if_index\n");
8755 M(IPSEC_INTERFACE_ADD_DEL_SPD, ipsec_interface_add_del_spd);
8757 mp->spd_id = ntohl(spd_id);
8758 mp->sw_if_index = ntohl (sw_if_index);
8759 mp->is_add = is_add;
8765 clib_warning ("unsupported (no dpdk)");
8771 api_ipsec_spd_add_del_entry (vat_main_t * vam)
8774 unformat_input_t * i = vam->input;
8775 vl_api_ipsec_spd_add_del_entry_t *mp;
8777 u8 is_add = 1, is_outbound = 0, is_ipv6 = 0, is_ip_any = 1;
8778 u32 spd_id, sa_id, protocol = 0, policy = 0;
8780 u32 rport_start = 0, rport_stop = (u32) ~0;
8781 u32 lport_start = 0, lport_stop = (u32) ~0;
8782 ip4_address_t laddr4_start, laddr4_stop, raddr4_start, raddr4_stop;
8783 ip6_address_t laddr6_start, laddr6_stop, raddr6_start, raddr6_stop;
8785 laddr4_start.as_u32 = raddr4_start.as_u32 = 0;
8786 laddr4_stop.as_u32 = raddr4_stop.as_u32 = (u32) ~0;
8787 laddr6_start.as_u64[0] = raddr6_start.as_u64[0] = 0;
8788 laddr6_start.as_u64[1] = raddr6_start.as_u64[1] = 0;
8789 laddr6_stop.as_u64[0] = raddr6_stop.as_u64[0] = (u64) ~0;
8790 laddr6_stop.as_u64[1] = raddr6_stop.as_u64[1] = (u64) ~0;
8792 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
8793 if (unformat (i, "del"))
8795 if (unformat (i, "outbound"))
8797 if (unformat (i, "inbound"))
8799 else if (unformat (i, "spd_id %d", &spd_id))
8801 else if (unformat (i, "sa_id %d", &sa_id))
8803 else if (unformat (i, "priority %d", &priority))
8805 else if (unformat (i, "protocol %d", &protocol))
8807 else if (unformat (i, "lport_start %d", &lport_start))
8809 else if (unformat (i, "lport_stop %d", &lport_stop))
8811 else if (unformat (i, "rport_start %d", &rport_start))
8813 else if (unformat (i, "rport_stop %d", &rport_stop))
8815 else if (unformat (i, "laddr_start %U", unformat_ip4_address, &laddr4_start))
8820 else if (unformat (i, "laddr_stop %U", unformat_ip4_address, &laddr4_stop))
8825 else if (unformat (i, "raddr_start %U", unformat_ip4_address, &raddr4_start))
8830 else if (unformat (i, "raddr_stop %U", unformat_ip4_address, &raddr4_stop))
8835 else if (unformat (i, "laddr_start %U", unformat_ip6_address, &laddr6_start))
8840 else if (unformat (i, "laddr_stop %U", unformat_ip6_address, &laddr6_stop))
8845 else if (unformat (i, "raddr_start %U", unformat_ip6_address, &raddr6_start))
8850 else if (unformat (i, "raddr_stop %U", unformat_ip6_address, &raddr6_stop))
8855 else if (unformat (i, "action %U", unformat_ipsec_policy_action, &policy))
8857 if (policy == IPSEC_POLICY_ACTION_RESOLVE) {
8858 clib_warning ("unsupported action: 'resolve'");
8863 clib_warning ("parse error '%U'", format_unformat_error, i);
8869 M(IPSEC_SPD_ADD_DEL_ENTRY, ipsec_spd_add_del_entry);
8871 mp->spd_id = ntohl(spd_id);
8872 mp->priority = ntohl(priority);
8873 mp->is_outbound = is_outbound;
8875 mp->is_ipv6 = is_ipv6;
8876 if (is_ipv6 || is_ip_any) {
8877 clib_memcpy (mp->remote_address_start, &raddr6_start, sizeof(ip6_address_t));
8878 clib_memcpy (mp->remote_address_stop, &raddr6_stop, sizeof(ip6_address_t));
8879 clib_memcpy (mp->local_address_start, &laddr6_start, sizeof(ip6_address_t));
8880 clib_memcpy (mp->local_address_stop, &laddr6_stop, sizeof(ip6_address_t));
8882 clib_memcpy (mp->remote_address_start, &raddr4_start, sizeof(ip4_address_t));
8883 clib_memcpy (mp->remote_address_stop, &raddr4_stop, sizeof(ip4_address_t));
8884 clib_memcpy (mp->local_address_start, &laddr4_start, sizeof(ip4_address_t));
8885 clib_memcpy (mp->local_address_stop, &laddr4_stop, sizeof(ip4_address_t));
8887 mp->protocol = (u8) protocol;
8888 mp->local_port_start = ntohs((u16) lport_start);
8889 mp->local_port_stop = ntohs((u16) lport_stop);
8890 mp->remote_port_start = ntohs((u16) rport_start);
8891 mp->remote_port_stop = ntohs((u16) rport_stop);
8892 mp->policy = (u8) policy;
8893 mp->sa_id = ntohl(sa_id);
8894 mp->is_add = is_add;
8895 mp->is_ip_any = is_ip_any;
8900 clib_warning ("unsupported (no dpdk)");
8906 api_ipsec_sad_add_del_entry (vat_main_t * vam)
8909 unformat_input_t * i = vam->input;
8910 vl_api_ipsec_sad_add_del_entry_t *mp;
8916 u8 protocol = IPSEC_PROTOCOL_AH;
8917 u8 is_tunnel = 0, is_tunnel_ipv6 = 0;
8918 u32 crypto_alg = 0, integ_alg = 0;
8919 ip4_address_t tun_src4;
8920 ip4_address_t tun_dst4;
8921 ip6_address_t tun_src6;
8922 ip6_address_t tun_dst6;
8924 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
8925 if (unformat (i, "del"))
8927 else if (unformat (i, "sad_id %d", &sad_id))
8929 else if (unformat (i, "spi %d", &spi))
8931 else if (unformat (i, "esp"))
8932 protocol = IPSEC_PROTOCOL_ESP;
8933 else if (unformat (i, "tunnel_src %U", unformat_ip4_address, &tun_src4)) {
8937 else if (unformat (i, "tunnel_dst %U", unformat_ip4_address, &tun_dst4)) {
8941 else if (unformat (i, "tunnel_src %U", unformat_ip6_address, &tun_src6)) {
8945 else if (unformat (i, "tunnel_dst %U", unformat_ip6_address, &tun_dst6)) {
8949 else if (unformat (i, "crypto_alg %U", unformat_ipsec_crypto_alg, &crypto_alg)) {
8950 if (crypto_alg < IPSEC_CRYPTO_ALG_AES_CBC_128 ||
8951 crypto_alg > IPSEC_INTEG_ALG_SHA_512_256) {
8952 clib_warning ("unsupported crypto-alg: '%U'",
8953 format_ipsec_crypto_alg, crypto_alg);
8957 else if (unformat (i, "crypto_key %U", unformat_hex_string, &ck))
8959 else if (unformat (i, "integ_alg %U", unformat_ipsec_integ_alg, &integ_alg)) {
8960 if (integ_alg < IPSEC_INTEG_ALG_SHA1_96 ||
8961 integ_alg > IPSEC_INTEG_ALG_SHA_512_256) {
8962 clib_warning ("unsupported integ-alg: '%U'",
8963 format_ipsec_integ_alg, integ_alg);
8967 else if (unformat (i, "integ_key %U", unformat_hex_string, &ik))
8970 clib_warning ("parse error '%U'", format_unformat_error, i);
8976 M(IPSEC_SAD_ADD_DEL_ENTRY, ipsec_sad_add_del_entry);
8978 mp->sad_id = ntohl(sad_id);
8979 mp->is_add = is_add;
8980 mp->protocol = protocol;
8981 mp->spi = ntohl(spi);
8982 mp->is_tunnel = is_tunnel;
8983 mp->is_tunnel_ipv6 = is_tunnel_ipv6;
8984 mp->crypto_algorithm = crypto_alg;
8985 mp->integrity_algorithm = integ_alg;
8986 mp->crypto_key_length = vec_len(ck);
8987 mp->integrity_key_length = vec_len(ik);
8989 if (mp->crypto_key_length > sizeof(mp->crypto_key))
8990 mp->crypto_key_length = sizeof(mp->crypto_key);
8992 if (mp->integrity_key_length > sizeof(mp->integrity_key))
8993 mp->integrity_key_length = sizeof(mp->integrity_key);
8995 clib_memcpy (mp->crypto_key, ck, mp->crypto_key_length);
8996 clib_memcpy (mp->integrity_key, ik, mp->integrity_key_length);
8999 if (is_tunnel_ipv6) {
9000 clib_memcpy (mp->tunnel_src_address, &tun_src6, sizeof(ip6_address_t));
9001 clib_memcpy (mp->tunnel_dst_address, &tun_dst6, sizeof(ip6_address_t));
9003 clib_memcpy (mp->tunnel_src_address, &tun_src4, sizeof(ip4_address_t));
9004 clib_memcpy (mp->tunnel_dst_address, &tun_dst4, sizeof(ip4_address_t));
9012 clib_warning ("unsupported (no dpdk)");
9018 api_ipsec_sa_set_key (vat_main_t * vam)
9021 unformat_input_t * i = vam->input;
9022 vl_api_ipsec_sa_set_key_t *mp;
9027 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
9028 if (unformat (i, "sa_id %d", &sa_id))
9030 else if (unformat (i, "crypto_key %U", unformat_hex_string, &ck))
9032 else if (unformat (i, "integ_key %U", unformat_hex_string, &ik))
9035 clib_warning ("parse error '%U'", format_unformat_error, i);
9040 M(IPSEC_SA_SET_KEY, ipsec_set_sa_key);
9042 mp->sa_id = ntohl(sa_id);
9043 mp->crypto_key_length = vec_len(ck);
9044 mp->integrity_key_length = vec_len(ik);
9046 if (mp->crypto_key_length > sizeof(mp->crypto_key))
9047 mp->crypto_key_length = sizeof(mp->crypto_key);
9049 if (mp->integrity_key_length > sizeof(mp->integrity_key))
9050 mp->integrity_key_length = sizeof(mp->integrity_key);
9052 clib_memcpy (mp->crypto_key, ck, mp->crypto_key_length);
9053 clib_memcpy (mp->integrity_key, ik, mp->integrity_key_length);
9059 clib_warning ("unsupported (no dpdk)");
9065 api_ikev2_profile_add_del (vat_main_t * vam)
9068 unformat_input_t * i = vam->input;
9069 vl_api_ikev2_profile_add_del_t * mp;
9074 const char * valid_chars = "a-zA-Z0-9_";
9076 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
9077 if (unformat (i, "del"))
9079 else if (unformat (i, "name %U", unformat_token, valid_chars, &name))
9082 errmsg ("parse error '%U'", format_unformat_error, i);
9087 if (!vec_len (name)) {
9088 errmsg ("profile name must be specified");
9092 if (vec_len (name) > 64) {
9093 errmsg ("profile name too long");
9097 M(IKEV2_PROFILE_ADD_DEL, ikev2_profile_add_del);
9099 clib_memcpy(mp->name, name, vec_len (name));
9100 mp->is_add = is_add;
9107 clib_warning ("unsupported (no dpdk)");
9113 api_ikev2_profile_set_auth (vat_main_t * vam)
9116 unformat_input_t * i = vam->input;
9117 vl_api_ikev2_profile_set_auth_t * mp;
9121 u32 auth_method = 0;
9124 const char * valid_chars = "a-zA-Z0-9_";
9126 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
9127 if (unformat (i, "name %U", unformat_token, valid_chars, &name))
9129 else if (unformat (i, "auth_method %U",
9130 unformat_ikev2_auth_method, &auth_method))
9132 else if (unformat (i, "auth_data 0x%U", unformat_hex_string, &data))
9134 else if (unformat (i, "auth_data %v", &data))
9137 errmsg ("parse error '%U'", format_unformat_error, i);
9142 if (!vec_len (name)) {
9143 errmsg ("profile name must be specified");
9147 if (vec_len (name) > 64) {
9148 errmsg ("profile name too long");
9152 if (!vec_len(data)) {
9153 errmsg ("auth_data must be specified");
9158 errmsg ("auth_method must be specified");
9162 M(IKEV2_PROFILE_SET_AUTH, ikev2_profile_set_auth);
9164 mp->is_hex = is_hex;
9165 mp->auth_method = (u8) auth_method;
9166 mp->data_len = vec_len (data);
9167 clib_memcpy (mp->name, name, vec_len (name));
9168 clib_memcpy (mp->data, data, vec_len (data));
9176 clib_warning ("unsupported (no dpdk)");
9182 api_ikev2_profile_set_id (vat_main_t * vam)
9185 unformat_input_t * i = vam->input;
9186 vl_api_ikev2_profile_set_id_t * mp;
9194 const char * valid_chars = "a-zA-Z0-9_";
9196 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
9197 if (unformat (i, "name %U", unformat_token, valid_chars, &name))
9199 else if (unformat (i, "id_type %U",
9200 unformat_ikev2_id_type, &id_type))
9202 else if (unformat (i, "id_data %U", unformat_ip4_address, &ip4))
9204 data = vec_new(u8, 4);
9205 clib_memcpy(data, ip4.as_u8, 4);
9207 else if (unformat (i, "id_data 0x%U", unformat_hex_string, &data))
9209 else if (unformat (i, "id_data %v", &data))
9211 else if (unformat (i, "local"))
9213 else if (unformat (i, "remote"))
9216 errmsg ("parse error '%U'", format_unformat_error, i);
9221 if (!vec_len (name)) {
9222 errmsg ("profile name must be specified");
9226 if (vec_len (name) > 64) {
9227 errmsg ("profile name too long");
9231 if (!vec_len(data)) {
9232 errmsg ("id_data must be specified");
9237 errmsg ("id_type must be specified");
9241 M(IKEV2_PROFILE_SET_ID, ikev2_profile_set_id);
9243 mp->is_local = is_local;
9244 mp->id_type = (u8) id_type;
9245 mp->data_len = vec_len (data);
9246 clib_memcpy (mp->name, name, vec_len (name));
9247 clib_memcpy (mp->data, data, vec_len (data));
9255 clib_warning ("unsupported (no dpdk)");
9261 api_ikev2_profile_set_ts (vat_main_t * vam)
9264 unformat_input_t * i = vam->input;
9265 vl_api_ikev2_profile_set_ts_t * mp;
9269 u32 proto = 0, start_port = 0, end_port = (u32) ~0;
9270 ip4_address_t start_addr, end_addr;
9272 const char * valid_chars = "a-zA-Z0-9_";
9274 start_addr.as_u32 = 0;
9275 end_addr.as_u32 = (u32) ~0;
9277 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
9278 if (unformat (i, "name %U", unformat_token, valid_chars, &name))
9280 else if (unformat (i, "protocol %d", &proto))
9282 else if (unformat (i, "start_port %d", &start_port))
9284 else if (unformat (i, "end_port %d", &end_port))
9286 else if (unformat (i, "start_addr %U", unformat_ip4_address, &start_addr))
9288 else if (unformat (i, "end_addr %U", unformat_ip4_address, &end_addr))
9290 else if (unformat (i, "local"))
9292 else if (unformat (i, "remote"))
9295 errmsg ("parse error '%U'", format_unformat_error, i);
9300 if (!vec_len (name)) {
9301 errmsg ("profile name must be specified");
9305 if (vec_len (name) > 64) {
9306 errmsg ("profile name too long");
9310 M(IKEV2_PROFILE_SET_TS, ikev2_profile_set_ts);
9312 mp->is_local = is_local;
9313 mp->proto = (u8) proto;
9314 mp->start_port = (u16) start_port;
9315 mp->end_port = (u16) end_port;
9316 mp->start_addr = start_addr.as_u32;
9317 mp->end_addr = end_addr.as_u32;
9318 clib_memcpy (mp->name, name, vec_len (name));
9325 clib_warning ("unsupported (no dpdk)");
9331 api_ikev2_set_local_key (vat_main_t * vam)
9334 unformat_input_t * i = vam->input;
9335 vl_api_ikev2_set_local_key_t * mp;
9339 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
9340 if (unformat (i, "file %v", &file))
9343 errmsg ("parse error '%U'", format_unformat_error, i);
9348 if (!vec_len (file)) {
9349 errmsg ("RSA key file must be specified");
9353 if (vec_len (file) > 256) {
9354 errmsg ("file name too long");
9358 M(IKEV2_SET_LOCAL_KEY, ikev2_set_local_key);
9360 clib_memcpy (mp->key_file, file, vec_len (file));
9367 clib_warning ("unsupported (no dpdk)");
9375 static int api_map_add_domain (vat_main_t * vam)
9377 unformat_input_t *i = vam->input;
9378 vl_api_map_add_domain_t *mp;
9381 ip4_address_t ip4_prefix;
9382 ip6_address_t ip6_prefix;
9383 ip6_address_t ip6_src;
9385 u32 ip6_prefix_len, ip4_prefix_len, ea_bits_len, psid_offset,
9387 u8 is_translation = 0;
9389 u8 ip6_src_len = 128;
9391 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
9392 if (unformat (i, "ip4-pfx %U/%d", unformat_ip4_address,
9393 &ip4_prefix, &ip4_prefix_len))
9395 else if (unformat (i, "ip6-pfx %U/%d", unformat_ip6_address,
9396 &ip6_prefix, &ip6_prefix_len))
9398 else if (unformat (i, "ip6-src %U/%d", unformat_ip6_address, &ip6_src, &ip6_src_len))
9400 else if (unformat (i, "ip6-src %U", unformat_ip6_address, &ip6_src))
9402 else if (unformat (i, "ea-bits-len %d", &ea_bits_len))
9404 else if (unformat (i, "psid-offset %d", &psid_offset))
9406 else if (unformat (i, "psid-len %d", &psid_length))
9408 else if (unformat (i, "mtu %d", &mtu))
9410 else if (unformat (i, "map-t"))
9413 clib_warning ("parse error '%U'", format_unformat_error, i);
9418 if (num_m_args != 6) {
9419 errmsg("mandatory argument(s) missing\n");
9423 /* Construct the API message */
9424 M(MAP_ADD_DOMAIN, map_add_domain);
9426 clib_memcpy(mp->ip4_prefix, &ip4_prefix, sizeof(ip4_prefix));
9427 mp->ip4_prefix_len = ip4_prefix_len;
9429 clib_memcpy(mp->ip6_prefix, &ip6_prefix, sizeof(ip6_prefix));
9430 mp->ip6_prefix_len = ip6_prefix_len;
9432 clib_memcpy(mp->ip6_src, &ip6_src, sizeof(ip6_src));
9433 mp->ip6_src_prefix_len = ip6_src_len;
9435 mp->ea_bits_len = ea_bits_len;
9436 mp->psid_offset = psid_offset;
9437 mp->psid_length = psid_length;
9438 mp->is_translation = is_translation;
9439 mp->mtu = htons(mtu);
9444 /* Wait for a reply, return good/bad news */
9448 static int api_map_del_domain (vat_main_t * vam)
9450 unformat_input_t *i = vam->input;
9451 vl_api_map_del_domain_t *mp;
9457 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
9458 if (unformat (i, "index %d", &index))
9461 clib_warning ("parse error '%U'", format_unformat_error, i);
9466 if (num_m_args != 1) {
9467 errmsg("mandatory argument(s) missing\n");
9471 /* Construct the API message */
9472 M(MAP_DEL_DOMAIN, map_del_domain);
9474 mp->index = ntohl(index);
9479 /* Wait for a reply, return good/bad news */
9483 static int api_map_add_del_rule (vat_main_t * vam)
9485 unformat_input_t *i = vam->input;
9486 vl_api_map_add_del_rule_t *mp;
9489 ip6_address_t ip6_dst;
9490 u32 num_m_args = 0, index, psid;
9492 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
9493 if (unformat (i, "index %d", &index))
9495 else if (unformat (i, "psid %d", &psid))
9497 else if (unformat (i, "dst %U", unformat_ip6_address, &ip6_dst))
9499 else if (unformat (i, "del")) {
9502 clib_warning ("parse error '%U'", format_unformat_error, i);
9507 /* Construct the API message */
9508 M(MAP_ADD_DEL_RULE, map_add_del_rule);
9510 mp->index = ntohl(index);
9511 mp->is_add = is_add;
9512 clib_memcpy(mp->ip6_dst, &ip6_dst, sizeof(ip6_dst));
9513 mp->psid = ntohs(psid);
9518 /* Wait for a reply, return good/bad news */
9522 static int api_map_domain_dump (vat_main_t * vam)
9524 vl_api_map_domain_dump_t *mp;
9527 /* Construct the API message */
9528 M(MAP_DOMAIN_DUMP, map_domain_dump);
9533 /* Use a control ping for synchronization */
9535 vl_api_control_ping_t * mp;
9536 M(CONTROL_PING, control_ping);
9542 static int api_map_rule_dump (vat_main_t * vam)
9544 unformat_input_t *i = vam->input;
9545 vl_api_map_rule_dump_t *mp;
9547 u32 domain_index = ~0;
9549 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
9550 if (unformat (i, "index %u", &domain_index))
9556 if (domain_index == ~0) {
9557 clib_warning("parse error: domain index expected");
9561 /* Construct the API message */
9562 M(MAP_RULE_DUMP, map_rule_dump);
9564 mp->domain_index = htonl(domain_index);
9569 /* Use a control ping for synchronization */
9571 vl_api_control_ping_t * mp;
9572 M(CONTROL_PING, control_ping);
9578 static void vl_api_map_add_domain_reply_t_handler
9579 (vl_api_map_add_domain_reply_t * mp)
9581 vat_main_t * vam = &vat_main;
9582 i32 retval = ntohl(mp->retval);
9584 if (vam->async_mode) {
9585 vam->async_errors += (retval < 0);
9587 vam->retval = retval;
9588 vam->result_ready = 1;
9592 static void vl_api_map_add_domain_reply_t_handler_json
9593 (vl_api_map_add_domain_reply_t * mp)
9595 vat_main_t * vam = &vat_main;
9596 vat_json_node_t node;
9598 vat_json_init_object(&node);
9599 vat_json_object_add_int(&node, "retval", ntohl(mp->retval));
9600 vat_json_object_add_uint(&node, "index", ntohl(mp->index));
9602 vat_json_print(vam->ofp, &node);
9603 vat_json_free(&node);
9605 vam->retval = ntohl(mp->retval);
9606 vam->result_ready = 1;
9610 api_get_first_msg_id (vat_main_t * vam)
9612 vl_api_get_first_msg_id_t * mp;
9614 unformat_input_t * i = vam->input;
9618 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
9619 if (unformat (i, "client %s", &name))
9625 if (name_set == 0) {
9626 errmsg ("missing client name\n");
9631 if (vec_len (name) > 63) {
9632 errmsg ("client name too long\n");
9636 M(GET_FIRST_MSG_ID, get_first_msg_id);
9637 clib_memcpy (mp->name, name, vec_len(name));
9643 static int api_cop_interface_enable_disable (vat_main_t * vam)
9645 unformat_input_t * line_input = vam->input;
9646 vl_api_cop_interface_enable_disable_t * mp;
9648 u32 sw_if_index = ~0;
9649 u8 enable_disable = 1;
9651 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) {
9652 if (unformat (line_input, "disable"))
9654 if (unformat (line_input, "enable"))
9656 else if (unformat (line_input, "%U", unformat_sw_if_index,
9659 else if (unformat (line_input, "sw_if_index %d", &sw_if_index))
9665 if (sw_if_index == ~0) {
9666 errmsg ("missing interface name or sw_if_index\n");
9670 /* Construct the API message */
9671 M(COP_INTERFACE_ENABLE_DISABLE, cop_interface_enable_disable);
9672 mp->sw_if_index = ntohl(sw_if_index);
9673 mp->enable_disable = enable_disable;
9677 /* Wait for the reply */
9681 static int api_cop_whitelist_enable_disable (vat_main_t * vam)
9683 unformat_input_t * line_input = vam->input;
9684 vl_api_cop_whitelist_enable_disable_t * mp;
9686 u32 sw_if_index = ~0;
9687 u8 ip4=0, ip6=0, default_cop=0;
9690 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) {
9691 if (unformat (line_input, "ip4"))
9693 else if (unformat (line_input, "ip6"))
9695 else if (unformat (line_input, "default"))
9697 else if (unformat (line_input, "%U", unformat_sw_if_index,
9700 else if (unformat (line_input, "sw_if_index %d", &sw_if_index))
9702 else if (unformat (line_input, "fib-id %d", &fib_id))
9708 if (sw_if_index == ~0) {
9709 errmsg ("missing interface name or sw_if_index\n");
9713 /* Construct the API message */
9714 M(COP_WHITELIST_ENABLE_DISABLE, cop_whitelist_enable_disable);
9715 mp->sw_if_index = ntohl(sw_if_index);
9716 mp->fib_id = ntohl(fib_id);
9719 mp->default_cop = default_cop;
9723 /* Wait for the reply */
9727 static int api_get_node_graph (vat_main_t * vam)
9729 vl_api_get_node_graph_t * mp;
9732 M(GET_NODE_GRAPH, get_node_graph);
9736 /* Wait for the reply */
9741 api_lisp_add_del_locator_set(vat_main_t * vam)
9743 unformat_input_t * input = vam->input;
9744 vl_api_lisp_add_del_locator_set_t *mp;
9747 u8 *locator_set_name = NULL;
9748 u8 locator_set_name_set = 0;
9750 /* Parse args required to build the message */
9751 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) {
9752 if (unformat(input, "del")) {
9754 } else if (unformat(input, "locator-set %s", &locator_set_name)) {
9755 locator_set_name_set = 1;
9760 if (locator_set_name_set == 0) {
9761 errmsg ("missing locator-set name");
9765 if (vec_len(locator_set_name) > 64) {
9766 errmsg ("locator-set name too long\n");
9767 vec_free(locator_set_name);
9770 vec_add1(locator_set_name, 0);
9772 /* Construct the API message */
9773 M(LISP_ADD_DEL_LOCATOR_SET, lisp_add_del_locator_set);
9775 mp->is_add = is_add;
9776 clib_memcpy(mp->locator_set_name, locator_set_name,
9777 vec_len(locator_set_name));
9778 vec_free(locator_set_name);
9783 /* Wait for a reply... */
9791 api_lisp_add_del_locator(vat_main_t * vam)
9793 unformat_input_t * input = vam->input;
9794 vl_api_lisp_add_del_locator_t *mp;
9796 u32 tmp_if_index = ~0;
9797 u32 sw_if_index = ~0;
9798 u8 sw_if_index_set = 0;
9799 u8 sw_if_index_if_name_set = 0;
9801 u8 priority_set = 0;
9805 u8 *locator_set_name = NULL;
9806 u8 locator_set_name_set = 0;
9808 /* Parse args required to build the message */
9809 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) {
9810 if (unformat(input, "del")) {
9812 } else if (unformat(input, "locator-set %s", &locator_set_name)) {
9813 locator_set_name_set = 1;
9814 } else if (unformat(input, "iface %U", unformat_sw_if_index, vam,
9816 sw_if_index_if_name_set = 1;
9817 sw_if_index = tmp_if_index;
9818 } else if (unformat(input,"sw_if_index %d", &tmp_if_index)) {
9819 sw_if_index_set = 1;
9820 sw_if_index = tmp_if_index;
9821 } else if (unformat(input, "p %d", &priority)) {
9823 } else if (unformat(input, "w %d", &weight)) {
9829 if (locator_set_name_set == 0) {
9830 errmsg ("missing locator-set name");
9834 if (sw_if_index_set == 0 && sw_if_index_if_name_set == 0) {
9835 errmsg ("missing sw_if_index");
9836 vec_free(locator_set_name);
9840 if (sw_if_index_set != 0 && sw_if_index_if_name_set != 0) {
9841 errmsg ("cannot use both params interface name and sw_if_index");
9842 vec_free(locator_set_name);
9846 if (priority_set == 0) {
9847 errmsg ("missing locator-set priority\n");
9848 vec_free(locator_set_name);
9852 if (weight_set == 0) {
9853 errmsg ("missing locator-set weight\n");
9854 vec_free(locator_set_name);
9858 if (vec_len(locator_set_name) > 64) {
9859 errmsg ("locator-set name too long\n");
9860 vec_free(locator_set_name);
9863 vec_add1(locator_set_name, 0);
9865 /* Construct the API message */
9866 M(LISP_ADD_DEL_LOCATOR, lisp_add_del_locator);
9868 mp->is_add = is_add;
9869 mp->sw_if_index = ntohl(sw_if_index);
9870 mp->priority = priority;
9871 mp->weight = weight;
9872 clib_memcpy(mp->locator_set_name, locator_set_name,
9873 vec_len(locator_set_name));
9874 vec_free(locator_set_name);
9879 /* Wait for a reply... */
9887 api_lisp_add_del_local_eid(vat_main_t * vam)
9889 unformat_input_t * input = vam->input;
9890 vl_api_lisp_add_del_local_eid_t *mp;
9895 ip4_address_t eidv4;
9896 ip6_address_t eidv6;
9897 u8 tmp_eid_lenght = ~0;
9899 u8 *locator_set_name = NULL;
9900 u8 locator_set_name_set = 0;
9902 /* Parse args required to build the message */
9903 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) {
9904 if (unformat(input, "del")) {
9906 } else if (unformat(input, "eid %U/%d", unformat_ip4_address,
9907 &eidv4, &tmp_eid_lenght)) {
9908 eid_lenght = tmp_eid_lenght;
9910 } else if (unformat(input, "eid %U/%d", unformat_ip6_address,
9911 &eidv6, &tmp_eid_lenght)) {
9912 eid_lenght = tmp_eid_lenght;
9914 } else if (unformat(input, "locator-set %s", &locator_set_name)) {
9915 locator_set_name_set = 1;
9920 if (locator_set_name_set == 0) {
9921 errmsg ("missing locator-set name\n");
9925 if (vec_len(locator_set_name) > 64) {
9926 errmsg ("locator-set name too long\n");
9927 vec_free(locator_set_name);
9930 vec_add1(locator_set_name, 0);
9932 if (eidv4_set && eidv6_set) {
9933 errmsg ("both eid v4 and v6 addresses set\n");
9934 vec_free(locator_set_name);
9938 if (!eidv4_set && !eidv6_set) {
9939 errmsg ("eid addresses not set\n");
9940 vec_free(locator_set_name);
9944 /* Construct the API message */
9945 M(LISP_ADD_DEL_LOCAL_EID, lisp_add_del_local_eid);
9947 mp->is_add = is_add;
9950 clib_memcpy(mp->ip_address, &eidv6, sizeof(eidv6));
9953 clib_memcpy(mp->ip_address, &eidv4, sizeof(eidv4));
9955 mp->prefix_len = eid_lenght;
9956 clib_memcpy(mp->locator_set_name, locator_set_name,
9957 vec_len(locator_set_name));
9958 vec_free(locator_set_name);
9963 /* Wait for a reply... */
9971 api_lisp_gpe_add_del_fwd_entry(vat_main_t * vam)
9973 unformat_input_t * input = vam->input;
9974 vl_api_lisp_gpe_add_del_fwd_entry_t *mp;
9977 u8 eidv4_set = 0, slocv4_set = 0, dlocv4_set = 0;
9978 u8 eidv6_set = 0, slocv6_set = 0, dlocv6_set = 0;
9979 ip4_address_t eidv4, slocv4, dlocv4;
9980 ip6_address_t eidv6, slocv6, dlocv6;
9981 u8 tmp_eid_lenght = ~0;
9984 /* Parse args required to build the message */
9985 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) {
9986 if (unformat(input, "del")) {
9988 } else if (unformat(input, "eid %U/%d", unformat_ip4_address,
9989 &eidv4, &tmp_eid_lenght)) {
9990 eid_lenght = tmp_eid_lenght;
9992 } else if (unformat(input, "eid %U/%d", unformat_ip6_address,
9993 &eidv6, &tmp_eid_lenght)) {
9994 eid_lenght = tmp_eid_lenght;
9996 } else if (unformat(input, "sloc %U", unformat_ip4_address, &slocv4)) {
9998 } else if (unformat(input, "sloc %U", unformat_ip6_address, &slocv6)) {
10000 } else if (unformat(input, "dloc %U", unformat_ip4_address, &dlocv4)) {
10002 } else if (unformat(input, "dloc %U", unformat_ip6_address, &dlocv6)) {
10008 if (eidv4_set && eidv6_set) {
10009 errmsg ("both eid v4 and v6 addresses set\n");
10013 if (!eidv4_set && !eidv6_set) {
10014 errmsg ("eid addresses not set\n");
10018 if (slocv4_set && slocv6_set) {
10019 errmsg ("both source v4 and v6 addresses set\n");
10023 if (!slocv4_set && !slocv6_set) {
10024 errmsg ("source addresses not set\n");
10028 if (dlocv4_set && dlocv6_set) {
10029 errmsg ("both destination v4 and v6 addresses set\n");
10033 if (dlocv4_set && dlocv6_set) {
10034 errmsg ("destination addresses not set\n");
10038 if (!(slocv4_set == dlocv4_set && slocv6_set == dlocv6_set)) {
10039 errmsg ("mixing type of source and destination address\n");
10043 /* Construct the API message */
10044 M(LISP_GPE_ADD_DEL_FWD_ENTRY, lisp_gpe_add_del_fwd_entry);
10046 mp->is_add = is_add;
10048 mp->eid_is_ipv6 = 1;
10049 clib_memcpy(mp->eid_ip_address, &eidv6, sizeof(eidv6));
10051 mp->eid_is_ipv6 = 0;
10052 clib_memcpy(mp->eid_ip_address, &eidv4, sizeof(eidv4));
10054 mp->eid_prefix_len = eid_lenght;
10056 mp->address_is_ipv6 = 1;
10057 clib_memcpy(mp->source_ip_address, &slocv6, sizeof(slocv6));
10058 clib_memcpy(mp->destination_ip_address, &dlocv6, sizeof(dlocv6));
10060 mp->address_is_ipv6 = 0;
10061 clib_memcpy(mp->source_ip_address, &slocv4, sizeof(slocv4));
10062 clib_memcpy(mp->destination_ip_address, &dlocv4, sizeof(dlocv4));
10068 /* Wait for a reply... */
10076 api_lisp_add_del_map_resolver(vat_main_t * vam)
10078 unformat_input_t * input = vam->input;
10079 vl_api_lisp_add_del_map_resolver_t *mp;
10084 ip4_address_t ipv4;
10085 ip6_address_t ipv6;
10087 /* Parse args required to build the message */
10088 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) {
10089 if (unformat(input, "del")) {
10091 } else if (unformat(input, "%U", unformat_ip4_address, &ipv4)) {
10093 } else if (unformat(input, "%U", unformat_ip6_address, &ipv6)) {
10099 if (ipv4_set && ipv6_set) {
10100 errmsg ("both eid v4 and v6 addresses set\n");
10104 if (!ipv4_set && !ipv6_set) {
10105 errmsg ("eid addresses not set\n");
10109 /* Construct the API message */
10110 M(LISP_ADD_DEL_MAP_RESOLVER, lisp_add_del_map_resolver);
10112 mp->is_add = is_add;
10115 clib_memcpy(mp->ip_address, &ipv6, sizeof(ipv6));
10118 clib_memcpy(mp->ip_address, &ipv4, sizeof(ipv4));
10124 /* Wait for a reply... */
10132 api_lisp_gpe_enable_disable (vat_main_t * vam)
10134 unformat_input_t * input = vam->input;
10135 vl_api_lisp_gpe_enable_disable_t *mp;
10140 /* Parse args required to build the message */
10141 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) {
10142 if (unformat(input, "enable")) {
10145 } else if (unformat(input, "disable")) {
10153 errmsg("Value not set\n");
10157 /* Construct the API message */
10158 M(LISP_GPE_ENABLE_DISABLE, lisp_gpe_enable_disable);
10165 /* Wait for a reply... */
10173 api_lisp_gpe_add_del_iface(vat_main_t * vam)
10175 unformat_input_t * input = vam->input;
10176 vl_api_lisp_gpe_add_del_iface_t *mp;
10182 /* Parse args required to build the message */
10183 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) {
10184 if (unformat(input, "up")) {
10187 } else if (unformat(input, "down")) {
10190 } else if (unformat(input, "table_id %d", &table_id)) {
10192 } else if (unformat(input, "vni %d", &vni)) {
10199 errmsg("Value not set\n");
10203 /* Construct the API message */
10204 M(LISP_GPE_ADD_DEL_IFACE, lisp_gpe_add_del_iface);
10206 mp->is_add = is_add;
10207 mp->table_id = table_id;
10213 /* Wait for a reply... */
10221 api_lisp_locator_set_dump(vat_main_t *vam)
10223 vl_api_lisp_locator_set_dump_t *mp;
10226 if (!vam->json_output) {
10227 fformat(vam->ofp, "%=20s%=16s%=16s%=16s\n",
10228 "Locator-set", "Locator", "Priority", "Weight");
10231 M(LISP_LOCATOR_SET_DUMP, lisp_locator_set_dump);
10235 /* Use a control ping for synchronization */
10237 vl_api_control_ping_t * mp;
10238 M(CONTROL_PING, control_ping);
10241 /* Wait for a reply... */
10249 api_lisp_local_eid_table_dump(vat_main_t *vam)
10251 vl_api_lisp_local_eid_table_dump_t *mp;
10254 if (!vam->json_output) {
10255 fformat(vam->ofp, "%=20s%=30s\n",
10256 "Locator-set", "Eid");
10259 M(LISP_LOCAL_EID_TABLE_DUMP, lisp_local_eid_table_dump);
10263 /* Use a control ping for synchronization */
10265 vl_api_control_ping_t * mp;
10266 M(CONTROL_PING, control_ping);
10269 /* Wait for a reply... */
10277 api_lisp_gpe_tunnel_dump(vat_main_t *vam)
10279 vl_api_lisp_gpe_tunnel_dump_t *mp;
10282 if (!vam->json_output) {
10283 fformat(vam->ofp, "%=20s%=30s%=16s%=16s%=16s%=16s"
10284 "%=16s%=16s%=16s%=16s%=16s\n",
10285 "Tunel", "Source", "Destination", "Fib encap", "Fib decap",
10286 "Decap next", "Lisp version", "Flags", "Next protocol",
10287 "ver_res", "res", "iid");
10290 M(LISP_GPE_TUNNEL_DUMP, lisp_gpe_tunnel_dump);
10294 /* Use a control ping for synchronization */
10296 vl_api_control_ping_t * mp;
10297 M(CONTROL_PING, control_ping);
10300 /* Wait for a reply... */
10308 api_lisp_map_resolver_dump(vat_main_t *vam)
10310 vl_api_lisp_map_resolver_dump_t *mp;
10313 if (!vam->json_output) {
10314 fformat(vam->ofp, "%=20s\n",
10318 M(LISP_MAP_RESOLVER_DUMP, lisp_map_resolver_dump);
10322 /* Use a control ping for synchronization */
10324 vl_api_control_ping_t * mp;
10325 M(CONTROL_PING, control_ping);
10328 /* Wait for a reply... */
10336 api_lisp_gpe_enable_disable_status_dump(vat_main_t *vam)
10338 vl_api_lisp_gpe_enable_disable_status_dump_t *mp;
10341 if (!vam->json_output) {
10342 fformat(vam->ofp, "%=20s\n",
10346 M(LISP_GPE_ENABLE_DISABLE_STATUS_DUMP,
10347 lisp_gpe_enable_disable_status_dump);
10351 /* Use a control ping for synchronization */
10353 vl_api_control_ping_t * mp;
10354 M(CONTROL_PING, control_ping);
10357 /* Wait for a reply... */
10364 static int q_or_quit (vat_main_t * vam)
10366 longjmp (vam->jump_buf, 1);
10367 return 0; /* not so much */
10369 static int q (vat_main_t * vam) {return q_or_quit (vam);}
10370 static int quit (vat_main_t * vam) {return q_or_quit (vam);}
10372 static int comment (vat_main_t * vam)
10377 static int cmd_cmp (void * a1, void * a2)
10382 return strcmp ((char *)(c1[0]), (char *)(c2[0]));
10385 static int help (vat_main_t * vam)
10390 unformat_input_t * i = vam->input;
10393 if (unformat (i, "%s", &name)) {
10398 hs = hash_get_mem (vam->help_by_name, name);
10400 fformat (vam->ofp, "usage: %s %s\n", name, hs[0]);
10402 fformat (vam->ofp, "No such msg / command '%s'\n", name);
10407 fformat(vam->ofp, "Help is available for the following:\n");
10409 hash_foreach_pair (p, vam->function_by_name,
10411 vec_add1 (cmds, (u8 *)(p->key));
10414 vec_sort_with_function (cmds, cmd_cmp);
10416 for (j = 0; j < vec_len(cmds); j++)
10417 fformat (vam->ofp, "%s\n", cmds[j]);
10423 static int set (vat_main_t * vam)
10425 u8 * name = 0, * value = 0;
10426 unformat_input_t * i = vam->input;
10428 if (unformat (i, "%s", &name)) {
10429 /* The input buffer is a vector, not a string. */
10430 value = vec_dup (i->buffer);
10431 vec_delete (value, i->index, 0);
10432 /* Almost certainly has a trailing newline */
10433 if (value[vec_len(value)-1] == '\n')
10434 value[vec_len(value)-1] = 0;
10435 /* Make sure it's a proper string, one way or the other */
10436 vec_add1 (value, 0);
10437 (void) clib_macro_set_value (&vam->macro_main,
10438 (char *)name, (char *)value);
10441 errmsg ("usage: set <name> <value>\n");
10448 static int unset (vat_main_t * vam)
10452 if (unformat (vam->input, "%s", &name))
10453 if (clib_macro_unset (&vam->macro_main, (char *)name) == 1)
10454 errmsg ("unset: %s wasn't set\n", name);
10465 static int macro_sort_cmp (void * a1, void * a2)
10467 macro_sort_t * s1 = a1;
10468 macro_sort_t * s2 = a2;
10470 return strcmp ((char *)(s1->name), (char *)(s2->name));
10473 static int dump_macro_table (vat_main_t * vam)
10475 macro_sort_t * sort_me = 0, * sm;
10479 hash_foreach_pair (p, vam->macro_main.the_value_table_hash,
10481 vec_add2 (sort_me, sm, 1);
10482 sm->name = (u8 *)(p->key);
10483 sm->value = (u8 *) (p->value[0]);
10486 vec_sort_with_function (sort_me, macro_sort_cmp);
10488 if (vec_len(sort_me))
10489 fformat (vam->ofp, "%-15s%s\n", "Name", "Value");
10491 fformat (vam->ofp, "The macro table is empty...\n");
10493 for (i = 0; i < vec_len (sort_me); i++)
10494 fformat (vam->ofp, "%-15s%s\n", sort_me[i].name,
10499 static int dump_node_table (vat_main_t * vam)
10502 vlib_node_t * node, * next_node;
10504 if (vec_len (vam->graph_nodes) == 0) {
10505 fformat (vam->ofp, "Node table empty, issue get_node_graph...\n");
10509 for (i = 0; i < vec_len (vam->graph_nodes); i++) {
10510 node = vam->graph_nodes[i];
10511 fformat (vam->ofp, "[%d] %s\n", i, node->name);
10512 for (j = 0; j < vec_len (node->next_nodes); j++) {
10513 if (node->next_nodes[j] != ~0) {
10514 next_node = vam->graph_nodes[node->next_nodes[j]];
10515 fformat (vam->ofp, " [%d] %s\n", j, next_node->name);
10522 static int search_node_table (vat_main_t * vam)
10524 unformat_input_t * line_input = vam->input;
10527 vlib_node_t * node, * next_node;
10530 if (vam->graph_node_index_by_name == 0) {
10531 fformat (vam->ofp, "Node table empty, issue get_node_graph...\n");
10535 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) {
10536 if (unformat (line_input, "%s", &node_to_find)) {
10537 vec_add1 (node_to_find, 0);
10538 p = hash_get_mem (vam->graph_node_index_by_name, node_to_find);
10540 fformat (vam->ofp, "%s not found...\n", node_to_find);
10543 node = vam->graph_nodes[p[0]];
10544 fformat (vam->ofp, "[%d] %s\n", p[0], node->name);
10545 for (j = 0; j < vec_len (node->next_nodes); j++) {
10546 if (node->next_nodes[j] != ~0) {
10547 next_node = vam->graph_nodes[node->next_nodes[j]];
10548 fformat (vam->ofp, " [%d] %s\n", j, next_node->name);
10554 clib_warning ("parse error '%U'", format_unformat_error,
10560 vec_free(node_to_find);
10568 static int script (vat_main_t * vam)
10571 char * save_current_file;
10572 unformat_input_t save_input;
10573 jmp_buf save_jump_buf;
10574 u32 save_line_number;
10576 FILE * new_fp, * save_ifp;
10578 if (unformat (vam->input, "%s", &s)) {
10579 new_fp = fopen ((char *)s, "r");
10581 errmsg ("Couldn't open script file %s\n", s);
10586 errmsg ("Missing script name\n");
10590 clib_memcpy (&save_input, &vam->input, sizeof (save_input));
10591 clib_memcpy (&save_jump_buf, &vam->jump_buf, sizeof (save_jump_buf));
10592 save_ifp = vam->ifp;
10593 save_line_number = vam->input_line_number;
10594 save_current_file = (char *) vam->current_file;
10596 vam->input_line_number = 0;
10598 vam->current_file = s;
10601 clib_memcpy (&vam->input, &save_input, sizeof (vam->input));
10602 clib_memcpy (&vam->jump_buf, &save_jump_buf, sizeof (save_jump_buf));
10603 vam->ifp = save_ifp;
10604 vam->input_line_number = save_line_number;
10605 vam->current_file = (u8 *) save_current_file;
10611 static int echo (vat_main_t * vam)
10613 fformat (vam->ofp, "%v", vam->input->buffer);
10617 /* List of API message constructors, CLI names map to api_xxx */
10618 #define foreach_vpe_api_msg \
10619 _(create_loopback,"[mac <mac-addr>]") \
10620 _(sw_interface_dump,"") \
10621 _(sw_interface_set_flags, \
10622 "<intfc> | sw_if_index <id> admin-up | admin-down link-up | link down") \
10623 _(sw_interface_add_del_address, \
10624 "<intfc> | sw_if_index <id> <ip4-address> | <ip6-address> [del] [del-all] ") \
10625 _(sw_interface_set_table, \
10626 "<intfc> | sw_if_index <id> vrf <table-id> [ipv6]") \
10627 _(sw_interface_set_vpath, \
10628 "<intfc> | sw_if_index <id> enable | disable") \
10629 _(sw_interface_set_l2_xconnect, \
10630 "rx <intfc> | rx_sw_if_index <id> tx <intfc> | tx_sw_if_index <id>\n" \
10631 "enable | disable") \
10632 _(sw_interface_set_l2_bridge, \
10633 "rx <intfc> | rx_sw_if_index <id> bd_id <bridge-domain-id>\n" \
10634 "[shg <split-horizon-group>] [bvi]\n" \
10635 "enable | disable") \
10636 _(bridge_domain_add_del, \
10637 "bd_id <bridge-domain-id> [flood 1|0] [uu-flood 1|0] [forward 1|0] [learn 1|0] [arp-term 1|0] [del]\n")\
10638 _(bridge_domain_dump, "[bd_id <bridge-domain-id>]\n") \
10640 "mac <mac-addr> bd_id <bridge-domain-id> [del] | sw_if <intfc> | sw_if_index <id> [static] [filter] [bvi]\n") \
10642 "sw_if <intfc> | sw_if_index <id> [learn] [forward] [uu-flood] [flood]\n") \
10644 "bd_id <bridge-domain-id> [learn] [forward] [uu-flood] [flood] [arp-term] [disable]\n") \
10646 "tapname <name> mac <mac-addr> | random-mac") \
10648 "<vpp-if-name> | sw_if_index <id> tapname <name> mac <mac-addr> | random-mac") \
10650 "<vpp-if-name> | sw_if_index <id>") \
10651 _(sw_interface_tap_dump, "") \
10652 _(ip_add_del_route, \
10653 "<addr>/<mask> via <addr> [vrf <n>]\n" \
10654 "[<intfc> | sw_if_index <id>] [resolve-attempts <n>]\n" \
10655 "[weight <n>] [drop] [local] [classify <n>] [del]\n" \
10656 "[multipath] [count <n>]") \
10657 _(proxy_arp_add_del, \
10658 "<lo-ip4-addr> - <hi-ip4-addr> [vrf <n>] [del]") \
10659 _(proxy_arp_intfc_enable_disable, \
10660 "<intfc> | sw_if_index <id> enable | disable") \
10661 _(mpls_add_del_encap, \
10662 "label <n> dst <ip4-addr> [vrf <n>] [del]") \
10663 _(mpls_add_del_decap, \
10664 "label <n> [rx_vrf_id <n>] [tx_vrf_id] [s-bit-clear][del]") \
10665 _(mpls_gre_add_del_tunnel, \
10666 "inner_vrf_id <n> outer_vrf_id <n> src <ip4-address> dst <ip4-address>\n" \
10667 "adj <ip4-address>/<mask-width> [del]") \
10668 _(sw_interface_set_unnumbered, \
10669 "<intfc> | sw_if_index <id> unnum_if_index <id> [del]") \
10670 _(ip_neighbor_add_del, \
10671 "<intfc> | sw_if_index <id> dst <ip46-address> mac <mac-addr>") \
10672 _(reset_vrf, "vrf <id> [ipv6]") \
10673 _(create_vlan_subif, "<intfc> | sw_if_index <id> vlan <n>") \
10674 _(create_subif, "<intfc> | sw_if_index <id> sub_id <n>\n" \
10675 "[outer_vlan_id <n>][inner_vlan_id <n>]\n" \
10676 "[no_tags][one_tag][two_tags][dot1ad][exact_match][default_sub]\n" \
10677 "[outer_vlan_id_any][inner_vlan_id_any]") \
10678 _(oam_add_del, "src <ip4-address> dst <ip4-address> [vrf <n>] [del]") \
10679 _(reset_fib, "vrf <n> [ipv6]") \
10680 _(dhcp_proxy_config, \
10681 "svr <v46-address> src <v46-address>\n" \
10682 "insert-cid <n> [del]") \
10683 _(dhcp_proxy_config_2, \
10684 "svr <v46-address> src <v46-address>\n" \
10685 "rx_vrf_id <nn> server_vrf_id <nn> insert-cid <n> [del]") \
10686 _(dhcp_proxy_set_vss, \
10687 "tbl_id <n> fib_id <n> oui <n> [ipv6] [del]") \
10688 _(dhcp_client_config, \
10689 "<intfc> | sw_if_index <id> [hostname <name>] [disable_event] [del]") \
10690 _(set_ip_flow_hash, \
10691 "vrf <n> [src] [dst] [sport] [dport] [proto] [reverse] [ipv6]") \
10692 _(sw_interface_ip6_enable_disable, \
10693 "<intfc> | sw_if_index <id> enable | disable") \
10694 _(sw_interface_ip6_set_link_local_address, \
10695 "<intfc> | sw_if_index <id> <ip6-address>/<mask-width>") \
10696 _(sw_interface_ip6nd_ra_prefix, \
10697 "<intfc> | sw_if_index <id> <ip6-address>/<mask-width>\n" \
10698 "val_life <n> pref_life <n> [def] [noadv] [offl] [noauto]\n" \
10699 "[nolink] [isno]") \
10700 _(sw_interface_ip6nd_ra_config, \
10701 "<intfc> | sw_if_index <id> [maxint <n>] [minint <n>]\n" \
10702 "[life <n>] [count <n>] [interval <n>] [surpress]\n" \
10703 "[managed] [other] [ll] [send] [cease] [isno] [def]") \
10704 _(set_arp_neighbor_limit, "arp_nbr_limit <n> [ipv6]") \
10705 _(l2_patch_add_del, \
10706 "rx <intfc> | rx_sw_if_index <id> tx <intfc> | tx_sw_if_index <id>\n" \
10707 "enable | disable") \
10708 _(mpls_ethernet_add_del_tunnel, \
10709 "tx <intfc> | tx_sw_if_index <n> dst <mac-addr>\n" \
10710 "adj <ip4-addr>/<mw> dst <mac-addr> [del]") \
10711 _(mpls_ethernet_add_del_tunnel_2, \
10712 "inner_vrf_id <n> outer_vrf_id <n> next-hop <ip4-addr>\n" \
10713 "resolve-attempts <n> resolve-if-needed 0 | 1 [del]") \
10714 _(sr_tunnel_add_del, \
10715 "[name <name>] src <ip6-addr> dst <ip6-addr>/<mw> \n" \
10716 "(next <ip6-addr>)+ [tag <ip6-addr>]* [clean] [reroute] \n" \
10717 "[policy <policy_name>]") \
10718 _(sr_policy_add_del, \
10719 "name <name> tunnel <tunnel-name> [tunnel <tunnel-name>]* [del]") \
10720 _(sr_multicast_map_add_del, \
10721 "address [ip6 multicast address] sr-policy [policy name] [del]") \
10722 _(classify_add_del_table, \
10723 "buckets <nn> [skip <n>] [match <n>] [memory_size <nn-bytes>]\n" \
10724 "[del] mask <mask-value>\n" \
10725 " [l2-miss-next | miss-next | acl-miss-next] <name|nn>") \
10726 _(classify_add_del_session, \
10727 "[hit-next|l2-hit-next|acl-hit-next] <name|nn> table-index <nn>\n" \
10728 "skip_n <nn> match_n <nn> match [hex] [l2] [l3 [ip4|ip6]]") \
10729 _(classify_set_interface_ip_table, \
10730 "<intfc> | sw_if_index <nn> table <nn>") \
10731 _(classify_set_interface_l2_tables, \
10732 "<intfc> | sw_if_index <nn> [ip4-table <nn>] [ip6-table <nn>]\n" \
10733 " [other-table <nn>]") \
10734 _(get_node_index, "node <node-name") \
10735 _(add_node_next, "node <node-name> next <next-node-name>") \
10736 _(l2tpv3_create_tunnel, \
10737 "client_address <ip6-addr> our_address <ip6-addr>\n" \
10738 "[local_session_id <nn>][remote_session_id <nn>][local_cookie <nn>]\n"\
10739 "[remote_cookie <nn>]\n[l2-sublayer-preset]\n") \
10740 _(l2tpv3_set_tunnel_cookies, \
10741 "<intfc> | sw_if_index <nn> [new_local_cookie <nn>]\n" \
10742 "[new_remote_cookie <nn>]\n") \
10743 _(l2tpv3_interface_enable_disable, \
10744 "<intfc> | sw_if_index <nn> enable | disable") \
10745 _(l2tpv3_set_lookup_key, \
10746 "lookup_v6_src | lookup_v6_dst | lookup_session_id") \
10747 _(sw_if_l2tpv3_tunnel_dump, "") \
10748 _(vxlan_add_del_tunnel, \
10749 "src <ip4-addr> dst <ip4-addr> vni <vni> [encap-vrf-id <nn>]\n" \
10750 " [decap-next l2|ip4|ip6] [del]") \
10751 _(vxlan_tunnel_dump, "[<intfc> | sw_if_index <nn>]") \
10752 _(gre_add_del_tunnel, \
10753 "src <ip4-addr> dst <ip4-addr> [outer-fib-id <nn>] [del]\n") \
10754 _(gre_tunnel_dump, "[<intfc> | sw_if_index <nn>]") \
10755 _(l2_fib_clear_table, "") \
10756 _(l2_interface_efp_filter, "sw_if_index <nn> enable | disable") \
10757 _(l2_interface_vlan_tag_rewrite, \
10758 "<intfc> | sw_if_index <nn> \n" \
10759 "[disable][push-[1|2]][pop-[1|2]][translate-1-[1|2]] \n" \
10760 "[translate-2-[1|2]] [push_dot1q 0] tag1 <nn> tag2 <nn>") \
10761 _(create_vhost_user_if, \
10762 "socket <filename> [server] [renumber <dev_instance>] " \
10763 "[mac <mac_address>]") \
10764 _(modify_vhost_user_if, \
10765 "<intfc> | sw_if_index <nn> socket <filename>\n" \
10766 "[server] [renumber <dev_instance>]") \
10767 _(delete_vhost_user_if, "<intfc> | sw_if_index <nn>") \
10768 _(sw_interface_vhost_user_dump, "") \
10769 _(show_version, "") \
10770 _(nsh_gre_add_del_tunnel, \
10771 "src <ip4-addr> dst <ip4-addr>" \
10772 "c1 <nn> c2 <nn> c3 <nn> c4 <nn> spi <nn> si <nn>\n" \
10773 "[encap-fib-id <nn>] [decap-fib-id <nn>] [o-bit <1|0>]\n" \
10774 "[c-bit <1|0>] [md-type <nn>][next-ip4][next-ip6][next-ethernet]\n" \
10775 "[tlv <xx>][del]") \
10776 _(nsh_vxlan_gpe_add_del_tunnel, \
10777 "src <ip4-addr> dst <ip4-addr> vni <nn>\n" \
10778 "c1 <nn> c2 <nn> c3 <nn> c4 <nn> spi <nn> si <nn>\n" \
10779 "[encap-vrf-id <nn>] [decap-vrf-id <nn>] [o-bit <1|0>]\n" \
10780 "[c-bit <1|0>] [md-type <nn>][next-ip4][next-ip6][next-ethernet]\n" \
10781 "[tlv <xx>][del]") \
10782 _(l2_fib_table_dump, "bd_id <bridge-domain-id>") \
10783 _(lisp_gpe_add_del_tunnel, \
10784 "src <ip4-addr> dst <ip4-addr> iid <nn>|iidx <0xnn>\n" \
10785 "[encap-vrf-id <nn>] [decap-vrf-id <nn>]\n" \
10786 "[n-bit][l-bit][e-bit][v-bit][i-bit][p-bit][not-p-bit][o-bit]\n" \
10787 "[next-ip4][next-ip6][next-ethernet][next-nsh]\n" \
10788 "[decap-next [ip4|ip6|ethernet|nsh-encap|<nn>]][del]") \
10789 _(interface_name_renumber, \
10790 "<intfc> | sw_if_index <nn> new_show_dev_instance <nn>") \
10791 _(input_acl_set_interface, \
10792 "<intfc> | sw_if_index <nn> [ip4-table <nn>] [ip6-table <nn>]\n" \
10793 " [l2-table <nn>] [del]") \
10794 _(want_ip4_arp_events, "address <ip4-address> [del]") \
10795 _(ip_address_dump, "(ipv4 | ipv6) (<intfc> | sw_if_index <id>)") \
10796 _(ip_dump, "ipv4 | ipv6") \
10797 _(ipsec_spd_add_del, "spd_id <n> [del]") \
10798 _(ipsec_interface_add_del_spd, "(<intfc> | sw_if_index <id>)\n" \
10800 _(ipsec_sad_add_del_entry, "sad_id <n> spi <n> crypto_alg <alg>\n" \
10801 " crypto_key <hex> tunnel_src <ip4|ip6> tunnel_dst <ip4|ip6>\n" \
10802 " integ_alg <alg> integ_key <hex>") \
10803 _(ipsec_spd_add_del_entry, "spd_id <n> priority <n> action <action>\n" \
10804 " (inbound|outbound) [sa_id <n>] laddr_start <ip4|ip6>\n" \
10805 " laddr_stop <ip4|ip6> raddr_start <ip4|ip6> raddr_stop <ip4|ip6>\n" \
10806 " [lport_start <n> lport_stop <n>] [rport_start <n> rport_stop <n>]" )\
10807 _(ipsec_sa_set_key, "sa_id <n> crypto_key <hex> integ_key <hex>") \
10808 _(ikev2_profile_add_del, "name <profile_name> [del]") \
10809 _(ikev2_profile_set_auth, "name <profile_name> auth_method <method>\n" \
10810 "(auth_data 0x<data> | auth_data <data>)") \
10811 _(ikev2_profile_set_id, "name <profile_name> id_type <type>\n" \
10812 "(id_data 0x<data> | id_data <data>) (local|remote)") \
10813 _(ikev2_profile_set_ts, "name <profile_name> protocol <proto>\n" \
10814 "start_port <port> end_port <port> start_addr <ip4> end_addr <ip4>\n" \
10815 "(local|remote)") \
10816 _(ikev2_set_local_key, "file <absolute_file_path>") \
10817 _(delete_loopback,"sw_if_index <nn>") \
10818 _(bd_ip_mac_add_del, "bd_id <bridge-domain-id> <ip4/6-addr> <mac-addr> [del]") \
10819 _(map_add_domain, \
10820 "ip4-pfx <ip4pfx> ip6-pfx <ip6pfx> " \
10821 "ip6-src <ip6addr> " \
10822 "ea-bits-len <n> psid-offset <n> psid-len <n>") \
10823 _(map_del_domain, "index <n>") \
10824 _(map_add_del_rule, \
10825 "index <n> psid <n> dst <ip6addr> [del]") \
10826 _(map_domain_dump, "") \
10827 _(map_rule_dump, "index <map-domain>") \
10828 _(want_interface_events, "enable|disable") \
10829 _(want_stats,"enable|disable") \
10830 _(get_first_msg_id, "client <name>") \
10831 _(cop_interface_enable_disable, "<intfc> | sw_if_index <nn> [disable]") \
10832 _(cop_whitelist_enable_disable, "<intfc> | sw_if_index <nn>\n" \
10833 "fib-id <nn> [ip4][ip6][default]") \
10834 _(get_node_graph, " ") \
10835 _(sw_interface_clear_stats,"<intfc> | sw_if_index <nn>") \
10836 _(trace_profile_add, "id <nn> trace-type <0x1f|0x3|0x9|0x11|0x19> " \
10837 "trace-elts <nn> trace-tsp <0|1|2|3> node-id <node id in hex> " \
10838 "app-data <app_data in hex> [pow] [ppc <encap|decap>]") \
10839 _(trace_profile_apply, "id <nn> <ip6-address>/<width>" \
10840 " vrf_id <nn> add | pop | none") \
10841 _(trace_profile_del, "") \
10842 _(lisp_add_del_locator_set, "locator-set <locator_name> [del]") \
10843 _(lisp_add_del_locator, "locator-set <locator_name> " \
10844 "iface <intf> | sw_if_index <sw_if_index> " \
10845 "p <priority> w <weight> [del]") \
10846 _(lisp_add_del_local_eid, "<ipv4|ipv6>/<prefix> " \
10847 "locator-set <locator_name> [del]") \
10848 _(lisp_gpe_add_del_fwd_entry, "eid <ip4|6-addr>/<prefix> " \
10849 "sloc <ip4/6-addr> dloc <ip4|6-addr> [del]") \
10850 _(lisp_add_del_map_resolver, "<ip4|6-addr> [del]") \
10851 _(lisp_gpe_enable_disable, "enable|disable") \
10852 _(lisp_gpe_add_del_iface, "up|down") \
10853 _(lisp_locator_set_dump, "") \
10854 _(lisp_local_eid_table_dump, "") \
10855 _(lisp_gpe_tunnel_dump, "") \
10856 _(lisp_map_resolver_dump, "") \
10857 _(lisp_gpe_enable_disable_status_dump, "")
10859 /* List of command functions, CLI names map directly to functions */
10860 #define foreach_cli_function \
10861 _(comment, "usage: comment <ignore-rest-of-line>") \
10862 _(dump_interface_table, "usage: dump_interface_table") \
10863 _(dump_sub_interface_table, "usage: dump_sub_interface_table") \
10864 _(dump_ipv4_table, "usage: dump_ipv4_table") \
10865 _(dump_ipv6_table, "usage: dump_ipv6_table") \
10866 _(dump_stats_table, "usage: dump_stats_table") \
10867 _(dump_macro_table, "usage: dump_macro_table ") \
10868 _(dump_node_table, "usage: dump_node_table") \
10869 _(echo, "usage: echo <message>") \
10870 _(exec, "usage: exec <vpe-debug-CLI-command>") \
10871 _(help, "usage: help") \
10872 _(q, "usage: quit") \
10873 _(quit, "usage: quit") \
10874 _(search_node_table, "usage: search_node_table <name>...") \
10875 _(set, "usage: set <variable-name> <value>") \
10876 _(script, "usage: script <file-name>") \
10877 _(unset, "usage: unset <variable-name>")
10880 static void vl_api_##n##_t_handler_uni \
10881 (vl_api_##n##_t * mp) \
10883 vat_main_t * vam = &vat_main; \
10884 if (vam->json_output) { \
10885 vl_api_##n##_t_handler_json(mp); \
10887 vl_api_##n##_t_handler(mp); \
10890 foreach_vpe_api_reply_msg;
10893 void vat_api_hookup (vat_main_t *vam)
10896 vl_msg_api_set_handlers(VL_API_##N, #n, \
10897 vl_api_##n##_t_handler_uni, \
10899 vl_api_##n##_t_endian, \
10900 vl_api_##n##_t_print, \
10901 sizeof(vl_api_##n##_t), 1);
10902 foreach_vpe_api_reply_msg;
10905 vl_msg_api_set_first_available_msg_id (VL_MSG_FIRST_AVAILABLE);
10907 vam->sw_if_index_by_interface_name =
10908 hash_create_string (0, sizeof (uword));
10910 vam->function_by_name =
10911 hash_create_string (0, sizeof(uword));
10913 vam->help_by_name =
10914 hash_create_string (0, sizeof(uword));
10916 /* API messages we can send */
10917 #define _(n,h) hash_set_mem (vam->function_by_name, #n, api_##n);
10918 foreach_vpe_api_msg;
10922 #define _(n,h) hash_set_mem (vam->help_by_name, #n, h);
10923 foreach_vpe_api_msg;
10926 /* CLI functions */
10927 #define _(n,h) hash_set_mem (vam->function_by_name, #n, n);
10928 foreach_cli_function;
10932 #define _(n,h) hash_set_mem (vam->help_by_name, #n, h);
10933 foreach_cli_function;
10937 #undef vl_api_version
10938 #define vl_api_version(n,v) static u32 vpe_api_version = v;
10939 #include <api/vpe.api.h>
10940 #undef vl_api_version
10942 void vl_client_add_api_signatures (vl_api_memclnt_create_t *mp)
10945 * Send the main API signature in slot 0. This bit of code must
10946 * match the checks in ../vpe/api/api.c: vl_msg_api_version_check().
10948 mp->api_versions[0] = clib_host_to_net_u32 (vpe_api_version);