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 /* and GRE tunnel interfaces */
2988 M(SW_INTERFACE_DUMP, sw_interface_dump);
2989 mp->name_filter_valid = 1;
2990 strncpy ((char *) mp->name_filter, "gre", sizeof(mp->name_filter)-1);
2993 /* Use a control ping for synchronization */
2995 vl_api_control_ping_t * mp;
2996 M(CONTROL_PING, control_ping);
3002 static int api_sw_interface_set_flags (vat_main_t * vam)
3004 unformat_input_t * i = vam->input;
3005 vl_api_sw_interface_set_flags_t *mp;
3008 u8 sw_if_index_set = 0;
3009 u8 admin_up = 0, link_up = 0;
3011 /* Parse args required to build the message */
3012 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
3013 if (unformat (i, "admin-up"))
3015 else if (unformat (i, "admin-down"))
3017 else if (unformat (i, "link-up"))
3019 else if (unformat (i, "link-down"))
3021 else if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
3022 sw_if_index_set = 1;
3023 else if (unformat (i, "sw_if_index %d", &sw_if_index))
3024 sw_if_index_set = 1;
3029 if (sw_if_index_set == 0) {
3030 errmsg ("missing interface name or sw_if_index\n");
3034 /* Construct the API message */
3035 M(SW_INTERFACE_SET_FLAGS, sw_interface_set_flags);
3036 mp->sw_if_index = ntohl (sw_if_index);
3037 mp->admin_up_down = admin_up;
3038 mp->link_up_down = link_up;
3043 /* Wait for a reply, return the good/bad news... */
3047 static int api_sw_interface_clear_stats (vat_main_t * vam)
3049 unformat_input_t * i = vam->input;
3050 vl_api_sw_interface_clear_stats_t *mp;
3053 u8 sw_if_index_set = 0;
3055 /* Parse args required to build the message */
3056 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
3057 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
3058 sw_if_index_set = 1;
3059 else if (unformat (i, "sw_if_index %d", &sw_if_index))
3060 sw_if_index_set = 1;
3065 /* Construct the API message */
3066 M(SW_INTERFACE_CLEAR_STATS, sw_interface_clear_stats);
3068 if (sw_if_index_set == 1)
3069 mp->sw_if_index = ntohl (sw_if_index);
3071 mp->sw_if_index = ~0;
3076 /* Wait for a reply, return the good/bad news... */
3080 static int api_sw_interface_add_del_address (vat_main_t * vam)
3082 unformat_input_t * i = vam->input;
3083 vl_api_sw_interface_add_del_address_t *mp;
3086 u8 sw_if_index_set = 0;
3087 u8 is_add = 1, del_all = 0;
3088 u32 address_length = 0;
3089 u8 v4_address_set = 0;
3090 u8 v6_address_set = 0;
3091 ip4_address_t v4address;
3092 ip6_address_t v6address;
3094 /* Parse args required to build the message */
3095 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
3096 if (unformat (i, "del-all"))
3098 else if (unformat (i, "del"))
3100 else if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
3101 sw_if_index_set = 1;
3102 else if (unformat (i, "sw_if_index %d", &sw_if_index))
3103 sw_if_index_set = 1;
3104 else if (unformat (i, "%U/%d",
3105 unformat_ip4_address, &v4address,
3108 else if (unformat (i, "%U/%d",
3109 unformat_ip6_address, &v6address,
3116 if (sw_if_index_set == 0) {
3117 errmsg ("missing interface name or sw_if_index\n");
3120 if (v4_address_set && v6_address_set) {
3121 errmsg ("both v4 and v6 addresses set\n");
3124 if (!v4_address_set && !v6_address_set && !del_all) {
3125 errmsg ("no addresses set\n");
3129 /* Construct the API message */
3130 M(SW_INTERFACE_ADD_DEL_ADDRESS, sw_interface_add_del_address);
3132 mp->sw_if_index = ntohl (sw_if_index);
3133 mp->is_add = is_add;
3134 mp->del_all = del_all;
3135 if (v6_address_set) {
3137 clib_memcpy (mp->address, &v6address, sizeof (v6address));
3139 clib_memcpy (mp->address, &v4address, sizeof (v4address));
3141 mp->address_length = address_length;
3146 /* Wait for a reply, return good/bad news */
3150 static int api_sw_interface_set_table (vat_main_t * vam)
3152 unformat_input_t * i = vam->input;
3153 vl_api_sw_interface_set_table_t *mp;
3155 u32 sw_if_index, vrf_id = 0;
3156 u8 sw_if_index_set = 0;
3159 /* Parse args required to build the message */
3160 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
3161 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
3162 sw_if_index_set = 1;
3163 else if (unformat (i, "sw_if_index %d", &sw_if_index))
3164 sw_if_index_set = 1;
3165 else if (unformat (i, "vrf %d", &vrf_id))
3167 else if (unformat (i, "ipv6"))
3173 if (sw_if_index_set == 0) {
3174 errmsg ("missing interface name or sw_if_index\n");
3178 /* Construct the API message */
3179 M(SW_INTERFACE_SET_TABLE, sw_interface_set_table);
3181 mp->sw_if_index = ntohl (sw_if_index);
3182 mp->is_ipv6 = is_ipv6;
3183 mp->vrf_id = ntohl (vrf_id);
3188 /* Wait for a reply... */
3192 static int api_sw_interface_set_vpath (vat_main_t * vam)
3194 unformat_input_t * i = vam->input;
3195 vl_api_sw_interface_set_vpath_t *mp;
3197 u32 sw_if_index = 0;
3198 u8 sw_if_index_set = 0;
3201 /* Parse args required to build the message */
3202 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
3203 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
3204 sw_if_index_set = 1;
3205 else if (unformat (i, "sw_if_index %d", &sw_if_index))
3206 sw_if_index_set = 1;
3207 else if (unformat (i, "enable"))
3209 else if (unformat (i, "disable"))
3215 if (sw_if_index_set == 0) {
3216 errmsg ("missing interface name or sw_if_index\n");
3220 /* Construct the API message */
3221 M(SW_INTERFACE_SET_VPATH, sw_interface_set_vpath);
3223 mp->sw_if_index = ntohl (sw_if_index);
3224 mp->enable = is_enable;
3229 /* Wait for a reply... */
3233 static int api_sw_interface_set_l2_xconnect (vat_main_t * vam)
3235 unformat_input_t * i = vam->input;
3236 vl_api_sw_interface_set_l2_xconnect_t *mp;
3239 u8 rx_sw_if_index_set = 0;
3241 u8 tx_sw_if_index_set = 0;
3244 /* Parse args required to build the message */
3245 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
3246 if (unformat (i, "rx_sw_if_index %d", &rx_sw_if_index))
3247 rx_sw_if_index_set = 1;
3248 else if (unformat (i, "tx_sw_if_index %d", &tx_sw_if_index))
3249 tx_sw_if_index_set = 1;
3250 else if (unformat (i, "rx")) {
3251 if (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
3252 if (unformat (i, "%U", unformat_sw_if_index, vam,
3254 rx_sw_if_index_set = 1;
3257 } else if (unformat (i, "tx")) {
3258 if (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
3259 if (unformat (i, "%U", unformat_sw_if_index, vam,
3261 tx_sw_if_index_set = 1;
3264 } else if (unformat (i, "enable"))
3266 else if (unformat (i, "disable"))
3272 if (rx_sw_if_index_set == 0) {
3273 errmsg ("missing rx interface name or rx_sw_if_index\n");
3277 if (enable && (tx_sw_if_index_set == 0)) {
3278 errmsg ("missing tx interface name or tx_sw_if_index\n");
3282 M(SW_INTERFACE_SET_L2_XCONNECT, sw_interface_set_l2_xconnect);
3284 mp->rx_sw_if_index = ntohl(rx_sw_if_index);
3285 mp->tx_sw_if_index = ntohl(tx_sw_if_index);
3286 mp->enable = enable;
3293 static int api_sw_interface_set_l2_bridge (vat_main_t * vam)
3295 unformat_input_t * i = vam->input;
3296 vl_api_sw_interface_set_l2_bridge_t *mp;
3299 u8 rx_sw_if_index_set = 0;
3306 /* Parse args required to build the message */
3307 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
3308 if (unformat (i, "sw_if_index %d", &rx_sw_if_index))
3309 rx_sw_if_index_set = 1;
3310 else if (unformat (i, "bd_id %d", &bd_id))
3312 else if (unformat (i, "%U", unformat_sw_if_index, vam,
3314 rx_sw_if_index_set = 1;
3315 else if (unformat (i, "shg %d", &shg))
3317 else if (unformat (i, "bvi"))
3319 else if (unformat (i, "enable"))
3321 else if (unformat (i, "disable"))
3327 if (rx_sw_if_index_set == 0) {
3328 errmsg ("missing rx interface name or sw_if_index\n");
3332 if (enable && (bd_id_set == 0)) {
3333 errmsg ("missing bridge domain\n");
3337 M(SW_INTERFACE_SET_L2_BRIDGE, sw_interface_set_l2_bridge);
3339 mp->rx_sw_if_index = ntohl(rx_sw_if_index);
3340 mp->bd_id = ntohl(bd_id);
3343 mp->enable = enable;
3350 static int api_bridge_domain_dump (vat_main_t * vam)
3352 unformat_input_t * i = vam->input;
3353 vl_api_bridge_domain_dump_t *mp;
3357 /* Parse args required to build the message */
3358 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
3359 if (unformat (i, "bd_id %d", &bd_id))
3365 M(BRIDGE_DOMAIN_DUMP, bridge_domain_dump);
3366 mp->bd_id = ntohl(bd_id);
3369 /* Use a control ping for synchronization */
3371 vl_api_control_ping_t * mp;
3372 M(CONTROL_PING, control_ping);
3381 static int api_bridge_domain_add_del (vat_main_t * vam)
3383 unformat_input_t * i = vam->input;
3384 vl_api_bridge_domain_add_del_t *mp;
3388 u32 flood = 1, forward = 1, learn = 1, uu_flood = 1, arp_term = 0;
3390 /* Parse args required to build the message */
3391 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
3392 if (unformat (i, "bd_id %d", &bd_id))
3394 else if (unformat (i, "flood %d", &flood))
3396 else if (unformat (i, "uu-flood %d", &uu_flood))
3398 else if (unformat (i, "forward %d", &forward))
3400 else if (unformat (i, "learn %d", &learn))
3402 else if (unformat (i, "arp-term %d", &arp_term))
3404 else if (unformat (i, "del")) {
3406 flood = uu_flood = forward = learn = 0;
3413 errmsg ("missing bridge domain\n");
3417 M(BRIDGE_DOMAIN_ADD_DEL, bridge_domain_add_del);
3419 mp->bd_id = ntohl(bd_id);
3421 mp->uu_flood = uu_flood;
3422 mp->forward = forward;
3424 mp->arp_term = arp_term;
3425 mp->is_add = is_add;
3432 static int api_l2fib_add_del (vat_main_t * vam)
3434 unformat_input_t * i = vam->input;
3435 vl_api_l2fib_add_del_t *mp;
3442 u8 sw_if_index_set = 0;
3447 /* Parse args required to build the message */
3448 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
3449 if (unformat (i, "mac %U", unformat_ethernet_address, &mac))
3451 else if (unformat (i, "bd_id %d", &bd_id))
3453 else if (unformat (i, "sw_if_index %d", &sw_if_index))
3454 sw_if_index_set = 1;
3455 else if (unformat (i, "sw_if")) {
3456 if (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
3457 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
3458 sw_if_index_set = 1;
3461 } else if (unformat (i, "static"))
3463 else if (unformat (i, "filter")) {
3466 } else if (unformat (i, "del"))
3473 errmsg ("missing mac address\n");
3477 if (bd_id_set == 0) {
3478 errmsg ("missing bridge domain\n");
3482 if (is_add && (sw_if_index_set == 0)) {
3483 errmsg ("missing interface name or sw_if_index\n");
3487 M(L2FIB_ADD_DEL, l2fib_add_del);
3490 mp->bd_id = ntohl(bd_id);
3491 mp->is_add = is_add;
3494 mp->sw_if_index = ntohl(sw_if_index);
3495 mp->static_mac = static_mac;
3496 mp->filter_mac = filter_mac;
3504 static int api_l2_flags (vat_main_t * vam)
3506 unformat_input_t * i = vam->input;
3507 vl_api_l2_flags_t *mp;
3510 u32 feature_bitmap = 0;
3511 u8 sw_if_index_set = 0;
3513 /* Parse args required to build the message */
3514 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
3515 if (unformat (i, "sw_if_index %d", &sw_if_index))
3516 sw_if_index_set = 1;
3517 else if (unformat (i, "sw_if")) {
3518 if (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
3519 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
3520 sw_if_index_set = 1;
3523 } else if (unformat (i, "learn"))
3524 feature_bitmap |= L2INPUT_FEAT_LEARN;
3525 else if (unformat (i, "forward"))
3526 feature_bitmap |= L2INPUT_FEAT_FWD;
3527 else if (unformat (i, "flood"))
3528 feature_bitmap |= L2INPUT_FEAT_FLOOD;
3529 else if (unformat (i, "uu-flood"))
3530 feature_bitmap |= L2INPUT_FEAT_UU_FLOOD;
3535 if (sw_if_index_set == 0) {
3536 errmsg ("missing interface name or sw_if_index\n");
3540 M(L2_FLAGS, l2_flags);
3542 mp->sw_if_index = ntohl(sw_if_index);
3543 mp->feature_bitmap = ntohl(feature_bitmap);
3550 static int api_bridge_flags (vat_main_t * vam)
3552 unformat_input_t * i = vam->input;
3553 vl_api_bridge_flags_t *mp;
3560 /* Parse args required to build the message */
3561 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
3562 if (unformat (i, "bd_id %d", &bd_id))
3564 else if (unformat (i, "learn"))
3566 else if (unformat (i, "forward"))
3568 else if (unformat (i, "flood"))
3570 else if (unformat (i, "uu-flood"))
3571 flags |= L2_UU_FLOOD;
3572 else if (unformat (i, "arp-term"))
3573 flags |= L2_ARP_TERM;
3574 else if (unformat (i, "off"))
3576 else if (unformat (i, "disable"))
3582 if (bd_id_set == 0) {
3583 errmsg ("missing bridge domain\n");
3587 M(BRIDGE_FLAGS, bridge_flags);
3589 mp->bd_id = ntohl(bd_id);
3590 mp->feature_bitmap = ntohl(flags);
3591 mp->is_set = is_set;
3598 static int api_bd_ip_mac_add_del (vat_main_t * vam)
3600 unformat_input_t * i = vam->input;
3601 vl_api_bd_ip_mac_add_del_t *mp;
3609 ip4_address_t v4addr;
3610 ip6_address_t v6addr;
3614 /* Parse args required to build the message */
3615 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
3616 if (unformat (i, "bd_id %d", &bd_id)) {
3618 } else if (unformat (i, "%U", unformat_ip4_address, &v4addr)) {
3620 } else if (unformat (i, "%U", unformat_ip6_address, &v6addr)) {
3623 } else if (unformat (i, "%U", unformat_ethernet_address, macaddr)) {
3625 } else if (unformat (i, "del"))
3631 if (bd_id_set == 0) {
3632 errmsg ("missing bridge domain\n");
3634 } else if (ip_set == 0) {
3635 errmsg ("missing IP address\n");
3637 } else if (mac_set == 0) {
3638 errmsg ("missing MAC address\n");
3642 M(BD_IP_MAC_ADD_DEL, bd_ip_mac_add_del);
3644 mp->bd_id = ntohl(bd_id);
3645 mp->is_ipv6 = is_ipv6;
3646 mp->is_add = is_add;
3648 clib_memcpy (mp->ip_address, &v6addr, sizeof (v6addr));
3649 else clib_memcpy (mp->ip_address, &v4addr, sizeof (v4addr));
3650 clib_memcpy (mp->mac_address, macaddr, 6);
3656 static int api_tap_connect (vat_main_t * vam)
3658 unformat_input_t * i = vam->input;
3659 vl_api_tap_connect_t *mp;
3666 memset (mac_address, 0, sizeof (mac_address));
3668 /* Parse args required to build the message */
3669 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
3670 if (unformat (i, "mac %U", unformat_ethernet_address, mac_address)) {
3673 else if (unformat (i, "random-mac"))
3675 else if (unformat (i, "tapname %s", &tap_name))
3681 if (name_set == 0) {
3682 errmsg ("missing tap name\n");
3685 if (vec_len (tap_name) > 63) {
3686 errmsg ("tap name too long\n");
3688 vec_add1 (tap_name, 0);
3690 /* Construct the API message */
3691 M(TAP_CONNECT, tap_connect);
3693 mp->use_random_mac = random_mac;
3694 clib_memcpy (mp->mac_address, mac_address, 6);
3695 clib_memcpy (mp->tap_name, tap_name, vec_len (tap_name));
3696 vec_free (tap_name);
3701 /* Wait for a reply... */
3705 static int api_tap_modify (vat_main_t * vam)
3707 unformat_input_t * i = vam->input;
3708 vl_api_tap_modify_t *mp;
3714 u32 sw_if_index = ~0;
3715 u8 sw_if_index_set = 0;
3717 memset (mac_address, 0, sizeof (mac_address));
3719 /* Parse args required to build the message */
3720 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
3721 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
3722 sw_if_index_set = 1;
3723 else if (unformat (i, "sw_if_index %d", &sw_if_index))
3724 sw_if_index_set = 1;
3725 else if (unformat (i, "mac %U", unformat_ethernet_address, mac_address)) {
3728 else if (unformat (i, "random-mac"))
3730 else if (unformat (i, "tapname %s", &tap_name))
3736 if (sw_if_index_set == 0) {
3737 errmsg ("missing vpp interface name");
3740 if (name_set == 0) {
3741 errmsg ("missing tap name\n");
3744 if (vec_len (tap_name) > 63) {
3745 errmsg ("tap name too long\n");
3747 vec_add1 (tap_name, 0);
3749 /* Construct the API message */
3750 M(TAP_MODIFY, tap_modify);
3752 mp->use_random_mac = random_mac;
3753 mp->sw_if_index = ntohl(sw_if_index);
3754 clib_memcpy (mp->mac_address, mac_address, 6);
3755 clib_memcpy (mp->tap_name, tap_name, vec_len (tap_name));
3756 vec_free (tap_name);
3761 /* Wait for a reply... */
3765 static int api_tap_delete (vat_main_t * vam)
3767 unformat_input_t * i = vam->input;
3768 vl_api_tap_delete_t *mp;
3770 u32 sw_if_index = ~0;
3771 u8 sw_if_index_set = 0;
3773 /* Parse args required to build the message */
3774 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
3775 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
3776 sw_if_index_set = 1;
3777 else if (unformat (i, "sw_if_index %d", &sw_if_index))
3778 sw_if_index_set = 1;
3783 if (sw_if_index_set == 0) {
3784 errmsg ("missing vpp interface name");
3788 /* Construct the API message */
3789 M(TAP_DELETE, tap_delete);
3791 mp->sw_if_index = ntohl(sw_if_index);
3796 /* Wait for a reply... */
3800 static int api_ip_add_del_route (vat_main_t * vam)
3802 unformat_input_t * i = vam->input;
3803 vl_api_ip_add_del_route_t *mp;
3805 u32 sw_if_index = 0, vrf_id = 0;
3806 u8 sw_if_index_set = 0;
3808 u8 is_local = 0, is_drop = 0;
3809 u8 create_vrf_if_needed = 0;
3811 u8 next_hop_weight = 1;
3813 u8 is_multipath = 0;
3815 u8 address_length_set = 0;
3816 u32 lookup_in_vrf = 0;
3817 u32 resolve_attempts = 0;
3818 u32 dst_address_length = 0;
3819 u8 next_hop_set = 0;
3820 ip4_address_t v4_dst_address, v4_next_hop_address;
3821 ip6_address_t v6_dst_address, v6_next_hop_address;
3825 u32 random_add_del = 0;
3826 u32 * random_vector = 0;
3827 uword * random_hash;
3828 u32 random_seed = 0xdeaddabe;
3829 u32 classify_table_index = ~0;
3832 /* Parse args required to build the message */
3833 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
3834 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
3835 sw_if_index_set = 1;
3836 else if (unformat (i, "sw_if_index %d", &sw_if_index))
3837 sw_if_index_set = 1;
3838 else if (unformat (i, "%U", unformat_ip4_address,
3843 else if (unformat (i, "%U", unformat_ip6_address, &v6_dst_address)) {
3847 else if (unformat (i, "/%d", &dst_address_length)) {
3848 address_length_set = 1;
3851 else if (is_ipv6 == 0 && unformat (i, "via %U", unformat_ip4_address,
3852 &v4_next_hop_address)) {
3855 else if (is_ipv6 == 1 && unformat (i, "via %U", unformat_ip6_address,
3856 &v6_next_hop_address)) {
3859 else if (unformat (i, "resolve-attempts %d", &resolve_attempts))
3861 else if (unformat (i, "weight %d", &next_hop_weight))
3863 else if (unformat (i, "drop")) {
3865 } else if (unformat (i, "local")) {
3867 } else if (unformat (i, "classify %d", &classify_table_index)) {
3869 } else if (unformat (i, "del"))
3871 else if (unformat (i, "add"))
3873 else if (unformat (i, "not-last"))
3875 else if (unformat (i, "multipath"))
3877 else if (unformat (i, "vrf %d", &vrf_id))
3879 else if (unformat (i, "create-vrf"))
3880 create_vrf_if_needed = 1;
3881 else if (unformat (i, "count %d", &count))
3883 else if (unformat (i, "lookup-in-vrf %d", &lookup_in_vrf))
3885 else if (unformat (i, "random"))
3887 else if (unformat (i, "seed %d", &random_seed))
3890 clib_warning ("parse error '%U'", format_unformat_error, i);
3895 if (resolve_attempts > 0 && sw_if_index_set == 0) {
3896 errmsg ("ARP resolution needs explicit interface or sw_if_index\n");
3900 if (!next_hop_set && !is_drop && !is_local && !is_classify) {
3901 errmsg ("next hop / local / drop / classify not set\n");
3905 if (address_set == 0) {
3906 errmsg ("missing addresses\n");
3910 if (address_length_set == 0) {
3911 errmsg ("missing address length\n");
3915 /* Generate a pile of unique, random routes */
3916 if (random_add_del) {
3917 u32 this_random_address;
3918 random_hash = hash_create (count, sizeof(uword));
3920 hash_set (random_hash, v4_next_hop_address.as_u32, 1);
3921 for (j = 0; j <= count; j++) {
3923 this_random_address = random_u32 (&random_seed);
3924 this_random_address =
3925 clib_host_to_net_u32 (this_random_address);
3926 } while (hash_get (random_hash, this_random_address));
3927 vec_add1 (random_vector, this_random_address);
3928 hash_set (random_hash, this_random_address, 1);
3930 hash_free (random_hash);
3931 v4_dst_address.as_u32 = random_vector[0];
3935 /* Turn on async mode */
3936 vam->async_mode = 1;
3937 vam->async_errors = 0;
3938 before = vat_time_now(vam);
3941 for (j = 0; j < count; j++) {
3942 /* Construct the API message */
3943 M(IP_ADD_DEL_ROUTE, ip_add_del_route);
3945 mp->next_hop_sw_if_index = ntohl (sw_if_index);
3946 mp->vrf_id = ntohl (vrf_id);
3947 if (resolve_attempts > 0) {
3948 mp->resolve_attempts = ntohl (resolve_attempts);
3949 mp->resolve_if_needed = 1;
3951 mp->create_vrf_if_needed = create_vrf_if_needed;
3953 mp->is_add = is_add;
3954 mp->is_drop = is_drop;
3955 mp->is_ipv6 = is_ipv6;
3956 mp->is_local = is_local;
3957 mp->is_classify = is_classify;
3958 mp->is_multipath = is_multipath;
3959 mp->not_last = not_last;
3960 mp->next_hop_weight = next_hop_weight;
3961 mp->dst_address_length = dst_address_length;
3962 mp->lookup_in_vrf = ntohl(lookup_in_vrf);
3963 mp->classify_table_index = ntohl(classify_table_index);
3966 clib_memcpy (mp->dst_address, &v6_dst_address, sizeof (v6_dst_address));
3968 clib_memcpy (mp->next_hop_address, &v6_next_hop_address,
3969 sizeof (v6_next_hop_address));
3970 increment_v6_address (&v6_dst_address);
3972 clib_memcpy (mp->dst_address, &v4_dst_address, sizeof (v4_dst_address));
3974 clib_memcpy (mp->next_hop_address, &v4_next_hop_address,
3975 sizeof (v4_next_hop_address));
3977 v4_dst_address.as_u32 = random_vector[j+1];
3979 increment_v4_address (&v4_dst_address);
3985 /* When testing multiple add/del ops, use a control-ping to sync */
3987 vl_api_control_ping_t * mp;
3990 /* Shut off async mode */
3991 vam->async_mode = 0;
3993 M(CONTROL_PING, control_ping);
3996 timeout = vat_time_now(vam) + 1.0;
3997 while (vat_time_now (vam) < timeout)
3998 if (vam->result_ready == 1)
4003 if (vam->retval == -99)
4004 errmsg ("timeout\n");
4006 if (vam->async_errors > 0) {
4007 errmsg ("%d asynchronous errors\n", vam->async_errors);
4010 vam->async_errors = 0;
4011 after = vat_time_now(vam);
4013 fformat(vam->ofp, "%d routes in %.6f secs, %.2f routes/sec\n",
4014 count, after - before, count / (after - before));
4016 /* Wait for a reply... */
4020 /* Return the good/bad news */
4021 return (vam->retval);
4024 static int api_proxy_arp_add_del (vat_main_t * vam)
4026 unformat_input_t * i = vam->input;
4027 vl_api_proxy_arp_add_del_t *mp;
4031 ip4_address_t lo, hi;
4034 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
4035 if (unformat (i, "vrf %d", &vrf_id))
4037 else if (unformat (i, "%U - %U", unformat_ip4_address, &lo,
4038 unformat_ip4_address, &hi))
4040 else if (unformat (i, "del"))
4043 clib_warning ("parse error '%U'", format_unformat_error, i);
4048 if (range_set == 0) {
4049 errmsg ("address range not set\n");
4053 M(PROXY_ARP_ADD_DEL, proxy_arp_add_del);
4055 mp->vrf_id = ntohl(vrf_id);
4056 mp->is_add = is_add;
4057 clib_memcpy(mp->low_address, &lo, sizeof (mp->low_address));
4058 clib_memcpy(mp->hi_address, &hi, sizeof (mp->hi_address));
4065 static int api_proxy_arp_intfc_enable_disable (vat_main_t * vam)
4067 unformat_input_t * i = vam->input;
4068 vl_api_proxy_arp_intfc_enable_disable_t *mp;
4072 u8 sw_if_index_set = 0;
4074 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
4075 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
4076 sw_if_index_set = 1;
4077 else if (unformat (i, "sw_if_index %d", &sw_if_index))
4078 sw_if_index_set = 1;
4079 else if (unformat (i, "enable"))
4081 else if (unformat (i, "disable"))
4084 clib_warning ("parse error '%U'", format_unformat_error, i);
4089 if (sw_if_index_set == 0) {
4090 errmsg ("missing interface name or sw_if_index\n");
4094 M(PROXY_ARP_INTFC_ENABLE_DISABLE, proxy_arp_intfc_enable_disable);
4096 mp->sw_if_index = ntohl(sw_if_index);
4097 mp->enable_disable = enable;
4104 static int api_mpls_add_del_decap (vat_main_t * vam)
4106 unformat_input_t * i = vam->input;
4107 vl_api_mpls_add_del_decap_t *mp;
4116 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
4117 if (unformat (i, "rx_vrf_id %d", &rx_vrf_id))
4119 else if (unformat (i, "tx_vrf_id %d", &tx_vrf_id))
4121 else if (unformat (i, "label %d", &label))
4123 else if (unformat (i, "next-index %d", &next_index))
4125 else if (unformat (i, "del"))
4127 else if (unformat (i, "s-bit-clear"))
4130 clib_warning ("parse error '%U'", format_unformat_error, i);
4135 M(MPLS_ADD_DEL_DECAP, mpls_add_del_decap);
4137 mp->rx_vrf_id = ntohl(rx_vrf_id);
4138 mp->tx_vrf_id = ntohl(tx_vrf_id);
4139 mp->label = ntohl(label);
4140 mp->next_index = ntohl(next_index);
4142 mp->is_add = is_add;
4149 static int api_mpls_add_del_encap (vat_main_t * vam)
4151 unformat_input_t * i = vam->input;
4152 vl_api_mpls_add_del_encap_t *mp;
4157 ip4_address_t dst_address;
4160 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
4161 if (unformat (i, "vrf %d", &vrf_id))
4163 else if (unformat (i, "label %d", &label))
4164 vec_add1 (labels, ntohl(label));
4165 else if (unformat (i, "dst %U", unformat_ip4_address, &dst_address))
4167 else if (unformat (i, "del"))
4170 clib_warning ("parse error '%U'", format_unformat_error, i);
4175 if (vec_len (labels) == 0) {
4176 errmsg ("missing encap label stack\n");
4180 M2(MPLS_ADD_DEL_ENCAP, mpls_add_del_encap,
4181 sizeof (u32) * vec_len (labels));
4183 mp->vrf_id = ntohl(vrf_id);
4184 clib_memcpy(mp->dst_address, &dst_address, sizeof (dst_address));
4185 mp->is_add = is_add;
4186 mp->nlabels = vec_len (labels);
4187 clib_memcpy(mp->labels, labels, sizeof(u32)*mp->nlabels);
4196 static int api_mpls_gre_add_del_tunnel (vat_main_t * vam)
4198 unformat_input_t * i = vam->input;
4199 vl_api_mpls_gre_add_del_tunnel_t *mp;
4201 u32 inner_vrf_id = 0;
4202 u32 outer_vrf_id = 0;
4203 ip4_address_t src_address;
4204 ip4_address_t dst_address;
4205 ip4_address_t intfc_address;
4207 u8 intfc_address_length = 0;
4211 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
4212 if (unformat (i, "inner_vrf_id %d", &inner_vrf_id))
4214 else if (unformat (i, "outer_vrf_id %d", &outer_vrf_id))
4216 else if (unformat (i, "src %U", unformat_ip4_address, &src_address))
4218 else if (unformat (i, "dst %U", unformat_ip4_address, &dst_address))
4220 else if (unformat (i, "adj %U/%d", unformat_ip4_address,
4221 &intfc_address, &tmp))
4222 intfc_address_length = tmp;
4223 else if (unformat (i, "l2-only"))
4225 else if (unformat (i, "del"))
4228 clib_warning ("parse error '%U'", format_unformat_error, i);
4233 M(MPLS_GRE_ADD_DEL_TUNNEL, mpls_gre_add_del_tunnel);
4235 mp->inner_vrf_id = ntohl(inner_vrf_id);
4236 mp->outer_vrf_id = ntohl(outer_vrf_id);
4237 clib_memcpy(mp->src_address, &src_address, sizeof (src_address));
4238 clib_memcpy(mp->dst_address, &dst_address, sizeof (dst_address));
4239 clib_memcpy(mp->intfc_address, &intfc_address, sizeof (intfc_address));
4240 mp->intfc_address_length = intfc_address_length;
4241 mp->l2_only = l2_only;
4242 mp->is_add = is_add;
4249 static int api_mpls_ethernet_add_del_tunnel (vat_main_t * vam)
4251 unformat_input_t * i = vam->input;
4252 vl_api_mpls_ethernet_add_del_tunnel_t *mp;
4254 u32 inner_vrf_id = 0;
4255 ip4_address_t intfc_address;
4256 u8 dst_mac_address[6];
4259 u8 intfc_address_length = 0;
4263 int tx_sw_if_index_set = 0;
4265 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
4266 if (unformat (i, "vrf %d", &inner_vrf_id))
4268 else if (unformat (i, "adj %U/%d", unformat_ip4_address,
4269 &intfc_address, &tmp))
4270 intfc_address_length = tmp;
4271 else if (unformat (i, "%U",
4272 unformat_sw_if_index, vam, &tx_sw_if_index))
4273 tx_sw_if_index_set = 1;
4274 else if (unformat (i, "tx_sw_if_index %d", &tx_sw_if_index))
4275 tx_sw_if_index_set = 1;
4276 else if (unformat (i, "dst %U", unformat_ethernet_address,
4279 else if (unformat (i, "l2-only"))
4281 else if (unformat (i, "del"))
4284 clib_warning ("parse error '%U'", format_unformat_error, i);
4290 errmsg ("dst (mac address) not set\n");
4293 if (!tx_sw_if_index_set) {
4294 errmsg ("tx-intfc not set\n");
4298 M(MPLS_ETHERNET_ADD_DEL_TUNNEL, mpls_ethernet_add_del_tunnel);
4300 mp->vrf_id = ntohl(inner_vrf_id);
4301 clib_memcpy (mp->adj_address, &intfc_address, sizeof (intfc_address));
4302 mp->adj_address_length = intfc_address_length;
4303 clib_memcpy (mp->dst_mac_address, dst_mac_address, sizeof (dst_mac_address));
4304 mp->tx_sw_if_index = ntohl(tx_sw_if_index);
4305 mp->l2_only = l2_only;
4306 mp->is_add = is_add;
4313 static int api_mpls_ethernet_add_del_tunnel_2 (vat_main_t * vam)
4315 unformat_input_t * i = vam->input;
4316 vl_api_mpls_ethernet_add_del_tunnel_2_t *mp;
4318 u32 inner_vrf_id = 0;
4319 u32 outer_vrf_id = 0;
4320 ip4_address_t adj_address;
4321 int adj_address_set = 0;
4322 ip4_address_t next_hop_address;
4323 int next_hop_address_set = 0;
4325 u8 adj_address_length = 0;
4328 u32 resolve_attempts = 5;
4329 u8 resolve_if_needed = 1;
4331 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
4332 if (unformat (i, "inner_vrf_id %d", &inner_vrf_id))
4334 else if (unformat (i, "outer_vrf_id %d", &outer_vrf_id))
4336 else if (unformat (i, "adj %U/%d", unformat_ip4_address,
4337 &adj_address, &tmp)) {
4338 adj_address_length = tmp;
4339 adj_address_set = 1;
4341 else if (unformat (i, "next-hop %U", unformat_ip4_address,
4343 next_hop_address_set = 1;
4344 else if (unformat (i, "resolve-attempts %d", &resolve_attempts))
4346 else if (unformat (i, "resolve-if-needed %d", &tmp))
4347 resolve_if_needed = tmp;
4348 else if (unformat (i, "l2-only"))
4350 else if (unformat (i, "del"))
4353 clib_warning ("parse error '%U'", format_unformat_error, i);
4358 if (!adj_address_set) {
4359 errmsg ("adjacency address/mask not set\n");
4362 if (!next_hop_address_set) {
4363 errmsg ("ip4 next hop address (in outer fib) not set\n");
4367 M(MPLS_ETHERNET_ADD_DEL_TUNNEL_2, mpls_ethernet_add_del_tunnel_2);
4369 mp->inner_vrf_id = ntohl(inner_vrf_id);
4370 mp->outer_vrf_id = ntohl(outer_vrf_id);
4371 mp->resolve_attempts = ntohl(resolve_attempts);
4372 mp->resolve_if_needed = resolve_if_needed;
4373 mp->is_add = is_add;
4374 mp->l2_only = l2_only;
4375 clib_memcpy (mp->adj_address, &adj_address, sizeof (adj_address));
4376 mp->adj_address_length = adj_address_length;
4377 clib_memcpy (mp->next_hop_ip4_address_in_outer_vrf, &next_hop_address,
4378 sizeof (next_hop_address));
4385 static int api_sw_interface_set_unnumbered (vat_main_t * vam)
4387 unformat_input_t * i = vam->input;
4388 vl_api_sw_interface_set_unnumbered_t *mp;
4393 u8 sw_if_index_set = 0;
4395 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
4396 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
4397 sw_if_index_set = 1;
4398 else if (unformat (i, "sw_if_index %d", &sw_if_index))
4399 sw_if_index_set = 1;
4400 else if (unformat (i, "unnum_if_index %d", &unnum_sw_index))
4402 else if (unformat (i, "del"))
4405 clib_warning ("parse error '%U'", format_unformat_error, i);
4410 if (sw_if_index_set == 0) {
4411 errmsg ("missing interface name or sw_if_index\n");
4415 M(SW_INTERFACE_SET_UNNUMBERED, sw_interface_set_unnumbered);
4417 mp->sw_if_index = ntohl(sw_if_index);
4418 mp->unnumbered_sw_if_index = ntohl(unnum_sw_index);
4419 mp->is_add = is_add;
4426 static int api_ip_neighbor_add_del (vat_main_t * vam)
4428 unformat_input_t * i = vam->input;
4429 vl_api_ip_neighbor_add_del_t *mp;
4432 u8 sw_if_index_set = 0;
4438 u8 v4_address_set = 0;
4439 u8 v6_address_set = 0;
4440 ip4_address_t v4address;
4441 ip6_address_t v6address;
4443 memset (mac_address, 0, sizeof (mac_address));
4445 /* Parse args required to build the message */
4446 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
4447 if (unformat (i, "mac %U", unformat_ethernet_address, mac_address)) {
4450 else if (unformat (i, "del"))
4452 else if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
4453 sw_if_index_set = 1;
4454 else if (unformat (i, "sw_if_index %d", &sw_if_index))
4455 sw_if_index_set = 1;
4456 else if (unformat (i, "is_static"))
4458 else if (unformat (i, "vrf %d", &vrf_id))
4460 else if (unformat (i, "dst %U",
4461 unformat_ip4_address, &v4address))
4463 else if (unformat (i, "dst %U",
4464 unformat_ip6_address, &v6address))
4467 clib_warning ("parse error '%U'", format_unformat_error, i);
4472 if (sw_if_index_set == 0) {
4473 errmsg ("missing interface name or sw_if_index\n");
4476 if (v4_address_set && v6_address_set) {
4477 errmsg ("both v4 and v6 addresses set\n");
4480 if (!v4_address_set && !v6_address_set) {
4481 errmsg ("no addresses set\n");
4485 /* Construct the API message */
4486 M(IP_NEIGHBOR_ADD_DEL, ip_neighbor_add_del);
4488 mp->sw_if_index = ntohl (sw_if_index);
4489 mp->is_add = is_add;
4490 mp->vrf_id = ntohl (vrf_id);
4491 mp->is_static = is_static;
4493 clib_memcpy (mp->mac_address, mac_address, 6);
4494 if (v6_address_set) {
4496 clib_memcpy (mp->dst_address, &v6address, sizeof (v6address));
4498 /* mp->is_ipv6 = 0; via memset in M macro above */
4499 clib_memcpy (mp->dst_address, &v4address, sizeof (v4address));
4505 /* Wait for a reply, return good/bad news */
4512 static int api_reset_vrf (vat_main_t * vam)
4514 unformat_input_t * i = vam->input;
4515 vl_api_reset_vrf_t *mp;
4521 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
4522 if (unformat (i, "vrf %d", &vrf_id))
4524 else if (unformat (i, "ipv6"))
4527 clib_warning ("parse error '%U'", format_unformat_error, i);
4532 if (vrf_id_set == 0) {
4533 errmsg ("missing vrf id\n");
4537 M(RESET_VRF, reset_vrf);
4539 mp->vrf_id = ntohl(vrf_id);
4540 mp->is_ipv6 = is_ipv6;
4547 static int api_create_vlan_subif (vat_main_t * vam)
4549 unformat_input_t * i = vam->input;
4550 vl_api_create_vlan_subif_t *mp;
4553 u8 sw_if_index_set = 0;
4557 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
4558 if (unformat (i, "sw_if_index %d", &sw_if_index))
4559 sw_if_index_set = 1;
4560 else if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
4561 sw_if_index_set = 1;
4562 else if (unformat (i, "vlan %d", &vlan_id))
4565 clib_warning ("parse error '%U'", format_unformat_error, i);
4570 if (sw_if_index_set == 0) {
4571 errmsg ("missing interface name or sw_if_index\n");
4575 if (vlan_id_set == 0) {
4576 errmsg ("missing vlan_id\n");
4579 M(CREATE_VLAN_SUBIF, create_vlan_subif);
4581 mp->sw_if_index = ntohl(sw_if_index);
4582 mp->vlan_id = ntohl(vlan_id);
4589 #define foreach_create_subif_bit \
4596 _(outer_vlan_id_any) \
4597 _(inner_vlan_id_any)
4599 static int api_create_subif (vat_main_t * vam)
4601 unformat_input_t * i = vam->input;
4602 vl_api_create_subif_t *mp;
4605 u8 sw_if_index_set = 0;
4612 u32 exact_match = 0;
4613 u32 default_sub = 0;
4614 u32 outer_vlan_id_any = 0;
4615 u32 inner_vlan_id_any = 0;
4617 u16 outer_vlan_id = 0;
4618 u16 inner_vlan_id = 0;
4620 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
4621 if (unformat (i, "sw_if_index %d", &sw_if_index))
4622 sw_if_index_set = 1;
4623 else if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
4624 sw_if_index_set = 1;
4625 else if (unformat (i, "sub_id %d", &sub_id))
4627 else if (unformat (i, "outer_vlan_id %d", &tmp))
4628 outer_vlan_id = tmp;
4629 else if (unformat (i, "inner_vlan_id %d", &tmp))
4630 inner_vlan_id = tmp;
4632 #define _(a) else if (unformat (i, #a)) a = 1 ;
4633 foreach_create_subif_bit
4637 clib_warning ("parse error '%U'", format_unformat_error, i);
4642 if (sw_if_index_set == 0) {
4643 errmsg ("missing interface name or sw_if_index\n");
4647 if (sub_id_set == 0) {
4648 errmsg ("missing sub_id\n");
4651 M(CREATE_SUBIF, create_subif);
4653 mp->sw_if_index = ntohl(sw_if_index);
4654 mp->sub_id = ntohl(sub_id);
4656 #define _(a) mp->a = a;
4657 foreach_create_subif_bit;
4660 mp->outer_vlan_id = ntohs (outer_vlan_id);
4661 mp->inner_vlan_id = ntohs (inner_vlan_id);
4668 static int api_oam_add_del (vat_main_t * vam)
4670 unformat_input_t * i = vam->input;
4671 vl_api_oam_add_del_t *mp;
4675 ip4_address_t src, dst;
4679 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
4680 if (unformat (i, "vrf %d", &vrf_id))
4682 else if (unformat (i, "src %U", unformat_ip4_address, &src))
4684 else if (unformat (i, "dst %U", unformat_ip4_address, &dst))
4686 else if (unformat (i, "del"))
4689 clib_warning ("parse error '%U'", format_unformat_error, i);
4695 errmsg ("missing src addr\n");
4700 errmsg ("missing dst addr\n");
4704 M(OAM_ADD_DEL, oam_add_del);
4706 mp->vrf_id = ntohl(vrf_id);
4707 mp->is_add = is_add;
4708 clib_memcpy(mp->src_address, &src, sizeof (mp->src_address));
4709 clib_memcpy(mp->dst_address, &dst, sizeof (mp->dst_address));
4716 static int api_reset_fib (vat_main_t * vam)
4718 unformat_input_t * i = vam->input;
4719 vl_api_reset_fib_t *mp;
4725 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
4726 if (unformat (i, "vrf %d", &vrf_id))
4728 else if (unformat (i, "ipv6"))
4731 clib_warning ("parse error '%U'", format_unformat_error, i);
4736 if (vrf_id_set == 0) {
4737 errmsg ("missing vrf id\n");
4741 M(RESET_FIB, reset_fib);
4743 mp->vrf_id = ntohl(vrf_id);
4744 mp->is_ipv6 = is_ipv6;
4751 static int api_dhcp_proxy_config (vat_main_t * vam)
4753 unformat_input_t * i = vam->input;
4754 vl_api_dhcp_proxy_config_t *mp;
4759 u8 v4_address_set = 0;
4760 u8 v6_address_set = 0;
4761 ip4_address_t v4address;
4762 ip6_address_t v6address;
4763 u8 v4_src_address_set = 0;
4764 u8 v6_src_address_set = 0;
4765 ip4_address_t v4srcaddress;
4766 ip6_address_t v6srcaddress;
4768 /* Parse args required to build the message */
4769 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
4770 if (unformat (i, "del"))
4772 else if (unformat (i, "vrf %d", &vrf_id))
4774 else if (unformat (i, "insert-cid %d", &insert_cid))
4776 else if (unformat (i, "svr %U",
4777 unformat_ip4_address, &v4address))
4779 else if (unformat (i, "svr %U",
4780 unformat_ip6_address, &v6address))
4782 else if (unformat (i, "src %U",
4783 unformat_ip4_address, &v4srcaddress))
4784 v4_src_address_set = 1;
4785 else if (unformat (i, "src %U",
4786 unformat_ip6_address, &v6srcaddress))
4787 v6_src_address_set = 1;
4792 if (v4_address_set && v6_address_set) {
4793 errmsg ("both v4 and v6 server addresses set\n");
4796 if (!v4_address_set && !v6_address_set) {
4797 errmsg ("no server addresses set\n");
4801 if (v4_src_address_set && v6_src_address_set) {
4802 errmsg ("both v4 and v6 src addresses set\n");
4805 if (!v4_src_address_set && !v6_src_address_set) {
4806 errmsg ("no src addresses set\n");
4810 if (!(v4_src_address_set && v4_address_set) &&
4811 !(v6_src_address_set && v6_address_set)) {
4812 errmsg ("no matching server and src addresses set\n");
4816 /* Construct the API message */
4817 M(DHCP_PROXY_CONFIG, dhcp_proxy_config);
4819 mp->insert_circuit_id = insert_cid;
4820 mp->is_add = is_add;
4821 mp->vrf_id = ntohl (vrf_id);
4822 if (v6_address_set) {
4824 clib_memcpy (mp->dhcp_server, &v6address, sizeof (v6address));
4825 clib_memcpy (mp->dhcp_src_address, &v6srcaddress, sizeof (v6address));
4827 clib_memcpy (mp->dhcp_server, &v4address, sizeof (v4address));
4828 clib_memcpy (mp->dhcp_src_address, &v4srcaddress, sizeof (v4address));
4834 /* Wait for a reply, return good/bad news */
4840 static int api_dhcp_proxy_config_2 (vat_main_t * vam)
4842 unformat_input_t * i = vam->input;
4843 vl_api_dhcp_proxy_config_2_t *mp;
4846 u32 server_vrf_id = 0;
4849 u8 v4_address_set = 0;
4850 u8 v6_address_set = 0;
4851 ip4_address_t v4address;
4852 ip6_address_t v6address;
4853 u8 v4_src_address_set = 0;
4854 u8 v6_src_address_set = 0;
4855 ip4_address_t v4srcaddress;
4856 ip6_address_t v6srcaddress;
4858 /* Parse args required to build the message */
4859 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
4860 if (unformat (i, "del"))
4862 else if (unformat (i, "rx_vrf_id %d", &rx_vrf_id))
4864 else if (unformat (i, "server_vrf_id %d", &server_vrf_id))
4866 else if (unformat (i, "insert-cid %d", &insert_cid))
4868 else if (unformat (i, "svr %U",
4869 unformat_ip4_address, &v4address))
4871 else if (unformat (i, "svr %U",
4872 unformat_ip6_address, &v6address))
4874 else if (unformat (i, "src %U",
4875 unformat_ip4_address, &v4srcaddress))
4876 v4_src_address_set = 1;
4877 else if (unformat (i, "src %U",
4878 unformat_ip6_address, &v6srcaddress))
4879 v6_src_address_set = 1;
4884 if (v4_address_set && v6_address_set) {
4885 errmsg ("both v4 and v6 server addresses set\n");
4888 if (!v4_address_set && !v6_address_set) {
4889 errmsg ("no server addresses set\n");
4893 if (v4_src_address_set && v6_src_address_set) {
4894 errmsg ("both v4 and v6 src addresses set\n");
4897 if (!v4_src_address_set && !v6_src_address_set) {
4898 errmsg ("no src addresses set\n");
4902 if (!(v4_src_address_set && v4_address_set) &&
4903 !(v6_src_address_set && v6_address_set)) {
4904 errmsg ("no matching server and src addresses set\n");
4908 /* Construct the API message */
4909 M(DHCP_PROXY_CONFIG_2, dhcp_proxy_config_2);
4911 mp->insert_circuit_id = insert_cid;
4912 mp->is_add = is_add;
4913 mp->rx_vrf_id = ntohl (rx_vrf_id);
4914 mp->server_vrf_id = ntohl (server_vrf_id);
4915 if (v6_address_set) {
4917 clib_memcpy (mp->dhcp_server, &v6address, sizeof (v6address));
4918 clib_memcpy (mp->dhcp_src_address, &v6srcaddress, sizeof (v6address));
4920 clib_memcpy (mp->dhcp_server, &v4address, sizeof (v4address));
4921 clib_memcpy (mp->dhcp_src_address, &v4srcaddress, sizeof (v4address));
4927 /* Wait for a reply, return good/bad news */
4933 static int api_dhcp_proxy_set_vss (vat_main_t * vam)
4935 unformat_input_t * i = vam->input;
4936 vl_api_dhcp_proxy_set_vss_t *mp;
4947 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
4948 if (unformat (i, "tbl_id %d", &tbl_id))
4950 if (unformat (i, "fib_id %d", &fib_id))
4952 if (unformat (i, "oui %d", &oui))
4954 else if (unformat (i, "ipv6"))
4956 else if (unformat (i, "del"))
4959 clib_warning ("parse error '%U'", format_unformat_error, i);
4964 if (tbl_id_set == 0) {
4965 errmsg ("missing tbl id\n");
4969 if (fib_id_set == 0) {
4970 errmsg ("missing fib id\n");
4974 errmsg ("missing oui\n");
4978 M(DHCP_PROXY_SET_VSS, dhcp_proxy_set_vss);
4979 mp->tbl_id = ntohl(tbl_id);
4980 mp->fib_id = ntohl(fib_id);
4981 mp->oui = ntohl(oui);
4982 mp->is_ipv6 = is_ipv6;
4983 mp->is_add = is_add;
4990 static int api_dhcp_client_config (vat_main_t * vam)
4992 unformat_input_t * i = vam->input;
4993 vl_api_dhcp_client_config_t *mp;
4996 u8 sw_if_index_set = 0;
4999 u8 disable_event = 0;
5001 /* Parse args required to build the message */
5002 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
5003 if (unformat (i, "del"))
5005 else if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
5006 sw_if_index_set = 1;
5007 else if (unformat (i, "sw_if_index %d", &sw_if_index))
5008 sw_if_index_set = 1;
5009 else if (unformat (i, "hostname %s", &hostname))
5011 else if (unformat (i, "disable_event"))
5017 if (sw_if_index_set == 0) {
5018 errmsg ("missing interface name or sw_if_index\n");
5022 if (vec_len (hostname) > 63) {
5023 errmsg ("hostname too long\n");
5025 vec_add1 (hostname, 0);
5027 /* Construct the API message */
5028 M(DHCP_CLIENT_CONFIG, dhcp_client_config);
5030 mp->sw_if_index = ntohl (sw_if_index);
5031 clib_memcpy (mp->hostname, hostname, vec_len (hostname));
5032 vec_free (hostname);
5033 mp->is_add = is_add;
5034 mp->want_dhcp_event = disable_event ? 0 : 1;
5040 /* Wait for a reply, return good/bad news */
5046 static int api_set_ip_flow_hash (vat_main_t * vam)
5048 unformat_input_t * i = vam->input;
5049 vl_api_set_ip_flow_hash_t *mp;
5061 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
5062 if (unformat (i, "vrf %d", &vrf_id))
5064 else if (unformat (i, "ipv6"))
5066 else if (unformat (i, "src"))
5068 else if (unformat (i, "dst"))
5070 else if (unformat (i, "sport"))
5072 else if (unformat (i, "dport"))
5074 else if (unformat (i, "proto"))
5076 else if (unformat (i, "reverse"))
5080 clib_warning ("parse error '%U'", format_unformat_error, i);
5085 if (vrf_id_set == 0) {
5086 errmsg ("missing vrf id\n");
5090 M(SET_IP_FLOW_HASH, set_ip_flow_hash);
5096 mp->reverse = reverse;
5097 mp->vrf_id = ntohl(vrf_id);
5098 mp->is_ipv6 = is_ipv6;
5105 static int api_sw_interface_ip6_enable_disable (vat_main_t * vam)
5107 unformat_input_t * i = vam->input;
5108 vl_api_sw_interface_ip6_enable_disable_t *mp;
5111 u8 sw_if_index_set = 0;
5114 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
5115 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
5116 sw_if_index_set = 1;
5117 else if (unformat (i, "sw_if_index %d", &sw_if_index))
5118 sw_if_index_set = 1;
5119 else if (unformat (i, "enable"))
5121 else if (unformat (i, "disable"))
5124 clib_warning ("parse error '%U'", format_unformat_error, i);
5129 if (sw_if_index_set == 0) {
5130 errmsg ("missing interface name or sw_if_index\n");
5134 M(SW_INTERFACE_IP6_ENABLE_DISABLE, sw_interface_ip6_enable_disable);
5136 mp->sw_if_index = ntohl(sw_if_index);
5137 mp->enable = enable;
5144 static int api_sw_interface_ip6_set_link_local_address (vat_main_t * vam)
5146 unformat_input_t * i = vam->input;
5147 vl_api_sw_interface_ip6_set_link_local_address_t *mp;
5150 u8 sw_if_index_set = 0;
5151 u32 address_length = 0;
5152 u8 v6_address_set = 0;
5153 ip6_address_t v6address;
5155 /* Parse args required to build the message */
5156 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
5157 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
5158 sw_if_index_set = 1;
5159 else if (unformat (i, "sw_if_index %d", &sw_if_index))
5160 sw_if_index_set = 1;
5161 else if (unformat (i, "%U/%d",
5162 unformat_ip6_address, &v6address,
5169 if (sw_if_index_set == 0) {
5170 errmsg ("missing interface name or sw_if_index\n");
5173 if (!v6_address_set) {
5174 errmsg ("no address set\n");
5178 /* Construct the API message */
5179 M(SW_INTERFACE_IP6_SET_LINK_LOCAL_ADDRESS, \
5180 sw_interface_ip6_set_link_local_address);
5182 mp->sw_if_index = ntohl (sw_if_index);
5183 clib_memcpy (mp->address, &v6address, sizeof (v6address));
5184 mp->address_length = address_length;
5189 /* Wait for a reply, return good/bad news */
5197 static int api_sw_interface_ip6nd_ra_prefix (vat_main_t * vam)
5199 unformat_input_t * i = vam->input;
5200 vl_api_sw_interface_ip6nd_ra_prefix_t *mp;
5203 u8 sw_if_index_set = 0;
5204 u32 address_length = 0;
5205 u8 v6_address_set = 0;
5206 ip6_address_t v6address;
5208 u8 no_advertise = 0;
5210 u8 no_autoconfig = 0;
5213 u32 val_lifetime = 0;
5214 u32 pref_lifetime = 0;
5216 /* Parse args required to build the message */
5217 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
5218 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
5219 sw_if_index_set = 1;
5220 else if (unformat (i, "sw_if_index %d", &sw_if_index))
5221 sw_if_index_set = 1;
5222 else if (unformat (i, "%U/%d",
5223 unformat_ip6_address, &v6address,
5226 else if (unformat (i, "val_life %d", &val_lifetime))
5228 else if (unformat (i, "pref_life %d", &pref_lifetime))
5230 else if (unformat (i, "def"))
5232 else if (unformat (i, "noadv"))
5234 else if (unformat (i, "offl"))
5236 else if (unformat (i, "noauto"))
5238 else if (unformat (i, "nolink"))
5240 else if (unformat (i, "isno"))
5243 clib_warning ("parse error '%U'", format_unformat_error, i);
5248 if (sw_if_index_set == 0) {
5249 errmsg ("missing interface name or sw_if_index\n");
5252 if (!v6_address_set) {
5253 errmsg ("no address set\n");
5257 /* Construct the API message */
5258 M(SW_INTERFACE_IP6ND_RA_PREFIX, sw_interface_ip6nd_ra_prefix);
5260 mp->sw_if_index = ntohl (sw_if_index);
5261 clib_memcpy (mp->address, &v6address, sizeof (v6address));
5262 mp->address_length = address_length;
5263 mp->use_default = use_default;
5264 mp->no_advertise = no_advertise;
5265 mp->off_link = off_link;
5266 mp->no_autoconfig = no_autoconfig;
5267 mp->no_onlink = no_onlink;
5269 mp->val_lifetime = ntohl(val_lifetime);
5270 mp->pref_lifetime = ntohl(pref_lifetime);
5275 /* Wait for a reply, return good/bad news */
5282 static int api_sw_interface_ip6nd_ra_config (vat_main_t * vam)
5284 unformat_input_t * i = vam->input;
5285 vl_api_sw_interface_ip6nd_ra_config_t *mp;
5288 u8 sw_if_index_set = 0;
5293 u8 send_unicast = 0;
5296 u8 default_router = 0;
5297 u32 max_interval = 0;
5298 u32 min_interval = 0;
5300 u32 initial_count = 0;
5301 u32 initial_interval = 0;
5304 /* Parse args required to build the message */
5305 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
5306 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
5307 sw_if_index_set = 1;
5308 else if (unformat (i, "sw_if_index %d", &sw_if_index))
5309 sw_if_index_set = 1;
5310 else if (unformat (i, "maxint %d", &max_interval))
5312 else if (unformat (i, "minint %d", &min_interval))
5314 else if (unformat (i, "life %d", &lifetime))
5316 else if (unformat (i, "count %d", &initial_count))
5318 else if (unformat (i, "interval %d", &initial_interval))
5320 else if (unformat (i, "surpress"))
5322 else if (unformat (i, "managed"))
5324 else if (unformat (i, "other"))
5326 else if (unformat (i, "ll"))
5328 else if (unformat (i, "send"))
5330 else if (unformat (i, "cease"))
5332 else if (unformat (i, "isno"))
5334 else if (unformat (i, "def"))
5337 clib_warning ("parse error '%U'", format_unformat_error, i);
5342 if (sw_if_index_set == 0) {
5343 errmsg ("missing interface name or sw_if_index\n");
5347 /* Construct the API message */
5348 M(SW_INTERFACE_IP6ND_RA_CONFIG, sw_interface_ip6nd_ra_config);
5350 mp->sw_if_index = ntohl (sw_if_index);
5351 mp->max_interval = ntohl(max_interval);
5352 mp->min_interval = ntohl(min_interval);
5353 mp->lifetime = ntohl(lifetime);
5354 mp->initial_count = ntohl(initial_count);
5355 mp->initial_interval = ntohl(initial_interval);
5356 mp->surpress = surpress;
5357 mp->managed = managed;
5359 mp->ll_option = ll_option;
5360 mp->send_unicast = send_unicast;
5363 mp->default_router = default_router;
5368 /* Wait for a reply, return good/bad news */
5375 static int api_set_arp_neighbor_limit (vat_main_t * vam)
5377 unformat_input_t * i = vam->input;
5378 vl_api_set_arp_neighbor_limit_t *mp;
5384 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
5385 if (unformat (i, "arp_nbr_limit %d", &arp_nbr_limit))
5387 else if (unformat (i, "ipv6"))
5390 clib_warning ("parse error '%U'", format_unformat_error, i);
5395 if (limit_set == 0) {
5396 errmsg ("missing limit value\n");
5400 M(SET_ARP_NEIGHBOR_LIMIT, set_arp_neighbor_limit);
5402 mp->arp_neighbor_limit = ntohl(arp_nbr_limit);
5403 mp->is_ipv6 = is_ipv6;
5410 static int api_l2_patch_add_del (vat_main_t * vam)
5412 unformat_input_t * i = vam->input;
5413 vl_api_l2_patch_add_del_t *mp;
5416 u8 rx_sw_if_index_set = 0;
5418 u8 tx_sw_if_index_set = 0;
5421 /* Parse args required to build the message */
5422 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
5423 if (unformat (i, "rx_sw_if_index %d", &rx_sw_if_index))
5424 rx_sw_if_index_set = 1;
5425 else if (unformat (i, "tx_sw_if_index %d", &tx_sw_if_index))
5426 tx_sw_if_index_set = 1;
5427 else if (unformat (i, "rx")) {
5428 if (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
5429 if (unformat (i, "%U", unformat_sw_if_index, vam,
5431 rx_sw_if_index_set = 1;
5434 } else if (unformat (i, "tx")) {
5435 if (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
5436 if (unformat (i, "%U", unformat_sw_if_index, vam,
5438 tx_sw_if_index_set = 1;
5441 } else if (unformat (i, "del"))
5447 if (rx_sw_if_index_set == 0) {
5448 errmsg ("missing rx interface name or rx_sw_if_index\n");
5452 if (tx_sw_if_index_set == 0) {
5453 errmsg ("missing tx interface name or tx_sw_if_index\n");
5457 M(L2_PATCH_ADD_DEL, l2_patch_add_del);
5459 mp->rx_sw_if_index = ntohl(rx_sw_if_index);
5460 mp->tx_sw_if_index = ntohl(tx_sw_if_index);
5461 mp->is_add = is_add;
5467 static int api_trace_profile_add (vat_main_t *vam)
5469 unformat_input_t * input = vam->input;
5470 vl_api_trace_profile_add_t *mp;
5473 u32 trace_option_elts = 0;
5474 u32 trace_type = 0, node_id = 0, app_data = 0, trace_tsp = 2;
5475 int has_pow_option = 0;
5476 int has_ppc_option = 0;
5478 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
5480 if (unformat (input, "id %d trace-type 0x%x trace-elts %d "
5481 "trace-tsp %d node-id 0x%x app-data 0x%x",
5482 &id, &trace_type, &trace_option_elts, &trace_tsp,
5483 &node_id, &app_data))
5485 else if (unformat (input, "pow"))
5487 else if (unformat (input, "ppc encap"))
5488 has_ppc_option = PPC_ENCAP;
5489 else if (unformat (input, "ppc decap"))
5490 has_ppc_option = PPC_DECAP;
5491 else if (unformat (input, "ppc none"))
5492 has_ppc_option = PPC_NONE;
5496 M(TRACE_PROFILE_ADD, trace_profile_add);
5498 mp->trace_type = trace_type;
5499 mp->trace_num_elt = trace_option_elts;
5500 mp->trace_ppc = has_ppc_option;
5501 mp->trace_app_data = htonl(app_data);
5502 mp->pow_enable = has_pow_option;
5503 mp->trace_tsp = trace_tsp;
5504 mp->node_id = htonl(node_id);
5511 static int api_trace_profile_apply (vat_main_t *vam)
5513 unformat_input_t * input = vam->input;
5514 vl_api_trace_profile_apply_t *mp;
5517 u32 mask_width = ~0;
5524 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
5526 if (unformat (input, "%U/%d",
5527 unformat_ip6_address, &addr, &mask_width))
5529 else if (unformat (input, "id %d", &id))
5531 else if (unformat (input, "vrf-id %d", &vrf_id))
5533 else if (unformat (input, "add"))
5535 else if (unformat (input, "pop"))
5537 else if (unformat (input, "none"))
5543 if ((is_add + is_pop + is_none) != 1) {
5544 errmsg("One of (add, pop, none) required");
5547 if (mask_width == ~0) {
5548 errmsg("<address>/<mask-width> required");
5551 M(TRACE_PROFILE_APPLY, trace_profile_apply);
5552 clib_memcpy(mp->dest_ipv6, &addr, sizeof(mp->dest_ipv6));
5554 mp->prefix_length = htonl(mask_width);
5555 mp->vrf_id = htonl(vrf_id);
5557 mp->trace_op = IOAM_HBYH_ADD;
5559 mp->trace_op = IOAM_HBYH_POP;
5561 mp->trace_op = IOAM_HBYH_MOD;
5573 static int api_trace_profile_del (vat_main_t *vam)
5575 vl_api_trace_profile_del_t *mp;
5578 M(TRACE_PROFILE_DEL, trace_profile_del);
5583 static int api_sr_tunnel_add_del (vat_main_t * vam)
5585 unformat_input_t * i = vam->input;
5586 vl_api_sr_tunnel_add_del_t *mp;
5590 ip6_address_t src_address;
5591 int src_address_set = 0;
5592 ip6_address_t dst_address;
5594 int dst_address_set = 0;
5596 u32 rx_table_id = 0;
5597 u32 tx_table_id = 0;
5598 ip6_address_t * segments = 0;
5599 ip6_address_t * this_seg;
5600 ip6_address_t * tags = 0;
5601 ip6_address_t * this_tag;
5602 ip6_address_t next_address, tag;
5604 u8 * policy_name = 0;
5606 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
5608 if (unformat (i, "del"))
5610 else if (unformat (i, "name %s", &name))
5612 else if (unformat (i, "policy %s", &policy_name))
5614 else if (unformat (i, "rx_fib_id %d", &rx_table_id))
5616 else if (unformat (i, "tx_fib_id %d", &tx_table_id))
5618 else if (unformat (i, "src %U", unformat_ip6_address, &src_address))
5619 src_address_set = 1;
5620 else if (unformat (i, "dst %U/%d",
5621 unformat_ip6_address, &dst_address,
5623 dst_address_set = 1;
5624 else if (unformat (i, "next %U", unformat_ip6_address,
5627 vec_add2 (segments, this_seg, 1);
5628 clib_memcpy (this_seg->as_u8, next_address.as_u8, sizeof (*this_seg));
5630 else if (unformat (i, "tag %U", unformat_ip6_address,
5633 vec_add2 (tags, this_tag, 1);
5634 clib_memcpy (this_tag->as_u8, tag.as_u8, sizeof (*this_tag));
5636 else if (unformat (i, "clean"))
5637 flags |= IP6_SR_HEADER_FLAG_CLEANUP;
5638 else if (unformat (i, "protected"))
5639 flags |= IP6_SR_HEADER_FLAG_PROTECTED;
5640 else if (unformat (i, "InPE %d", &pl_index))
5642 if (pl_index <= 0 || pl_index > 4)
5644 pl_index_range_error:
5645 errmsg ("pl index %d out of range\n", pl_index);
5648 flags |= IP6_SR_HEADER_FLAG_PL_ELT_INGRESS_PE << (3*(pl_index - 1));
5650 else if (unformat (i, "EgPE %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_EGRESS_PE << (3*(pl_index - 1));
5656 else if (unformat (i, "OrgSrc %d", &pl_index))
5658 if (pl_index <= 0 || pl_index > 4)
5659 goto pl_index_range_error;
5660 flags |= IP6_SR_HEADER_FLAG_PL_ELT_ORIG_SRC_ADDR << (3*(pl_index - 1));
5666 if (!src_address_set)
5668 errmsg ("src address required\n");
5672 if (!dst_address_set)
5674 errmsg ("dst address required\n");
5680 errmsg ("at least one sr segment required\n");
5684 M2(SR_TUNNEL_ADD_DEL, sr_tunnel_add_del,
5685 vec_len(segments) * sizeof (ip6_address_t)
5686 + vec_len(tags) * sizeof (ip6_address_t));
5688 clib_memcpy (mp->src_address, &src_address, sizeof (mp->src_address));
5689 clib_memcpy (mp->dst_address, &dst_address, sizeof (mp->dst_address));
5690 mp->dst_mask_width = dst_mask_width;
5691 mp->flags_net_byte_order = clib_host_to_net_u16 (flags);
5692 mp->n_segments = vec_len (segments);
5693 mp->n_tags = vec_len (tags);
5694 mp->is_add = is_del == 0;
5695 clib_memcpy (mp->segs_and_tags, segments,
5696 vec_len(segments)* sizeof (ip6_address_t));
5697 clib_memcpy (mp->segs_and_tags + vec_len(segments)*sizeof (ip6_address_t),
5698 tags, vec_len(tags)* sizeof (ip6_address_t));
5700 mp->outer_vrf_id = ntohl (rx_table_id);
5701 mp->inner_vrf_id = ntohl (tx_table_id);
5702 memcpy (mp->name, name, vec_len(name));
5703 memcpy (mp->policy_name, policy_name, vec_len(policy_name));
5705 vec_free (segments);
5712 static int api_sr_policy_add_del (vat_main_t * vam)
5714 unformat_input_t * input = vam->input;
5715 vl_api_sr_policy_add_del_t *mp;
5719 u8 * tunnel_name = 0;
5720 u8 ** tunnel_names = 0;
5725 int tunnel_names_length = 1; // Init to 1 to offset the #tunnel_names counter byte
5726 int tun_name_len = 0; // Different naming convention used as confusing these would be "bad" (TM)
5728 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
5730 if (unformat (input, "del"))
5732 else if (unformat (input, "name %s", &name))
5734 else if (unformat (input, "tunnel %s", &tunnel_name))
5738 vec_add1 (tunnel_names, tunnel_name);
5740 - length = #bytes to store in serial vector
5741 - +1 = byte to store that length
5743 tunnel_names_length += (vec_len (tunnel_name) + 1);
5754 errmsg ("policy name required\n");
5758 if ((!tunnel_set) && (!is_del))
5760 errmsg ("tunnel name required\n");
5764 M2(SR_POLICY_ADD_DEL, sr_policy_add_del, tunnel_names_length);
5768 mp->is_add = !is_del;
5770 memcpy (mp->name, name, vec_len(name));
5771 // Since mp->tunnel_names is of type u8[0] and not a u8 *, u8 ** needs to be serialized
5772 u8 * serial_orig = 0;
5773 vec_validate (serial_orig, tunnel_names_length);
5774 *serial_orig = vec_len(tunnel_names); // Store the number of tunnels as length in first byte of serialized vector
5775 serial_orig += 1; // Move along one byte to store the length of first tunnel_name
5777 for (j=0; j < vec_len(tunnel_names); j++)
5779 tun_name_len = vec_len (tunnel_names[j]);
5780 *serial_orig = tun_name_len; // Store length of tunnel name in first byte of Length/Value pair
5781 serial_orig += 1; // Move along one byte to store the actual tunnel name
5782 memcpy (serial_orig, tunnel_names[j], tun_name_len);
5783 serial_orig += tun_name_len; // Advance past the copy
5785 memcpy (mp->tunnel_names, serial_orig - tunnel_names_length, tunnel_names_length); // Regress serial_orig to head then copy fwd
5787 vec_free (tunnel_names);
5788 vec_free (tunnel_name);
5794 static int api_sr_multicast_map_add_del (vat_main_t * vam)
5796 unformat_input_t * input = vam->input;
5797 vl_api_sr_multicast_map_add_del_t *mp;
5800 ip6_address_t multicast_address;
5801 u8 * policy_name = 0;
5802 int multicast_address_set = 0;
5804 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
5806 if (unformat (input, "del"))
5808 else if (unformat (input, "address %U", unformat_ip6_address, &multicast_address))
5809 multicast_address_set = 1;
5810 else if (unformat (input, "sr-policy %s", &policy_name))
5816 if (!is_del && !policy_name)
5818 errmsg ("sr-policy name required\n");
5823 if (!multicast_address_set)
5825 errmsg ("address required\n");
5829 M(SR_MULTICAST_MAP_ADD_DEL, sr_multicast_map_add_del);
5831 mp->is_add = !is_del;
5832 memcpy (mp->policy_name, policy_name, vec_len(policy_name));
5833 clib_memcpy (mp->multicast_address, &multicast_address, sizeof (mp->multicast_address));
5836 vec_free (policy_name);
5843 #define foreach_ip4_proto_field \
5853 uword unformat_ip4_mask (unformat_input_t * input, va_list * args)
5855 u8 ** maskp = va_arg (*args, u8 **);
5857 u8 found_something = 0;
5860 #define _(a) u8 a=0;
5861 foreach_ip4_proto_field;
5867 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
5869 if (unformat (input, "version"))
5871 else if (unformat (input, "hdr_length"))
5873 else if (unformat (input, "src"))
5875 else if (unformat (input, "dst"))
5877 else if (unformat (input, "proto"))
5880 #define _(a) else if (unformat (input, #a)) a=1;
5881 foreach_ip4_proto_field
5887 #define _(a) found_something += a;
5888 foreach_ip4_proto_field;
5891 if (found_something == 0)
5894 vec_validate (mask, sizeof (*ip) - 1);
5896 ip = (ip4_header_t *) mask;
5898 #define _(a) if (a) memset (&ip->a, 0xff, sizeof (ip->a));
5899 foreach_ip4_proto_field;
5902 ip->ip_version_and_header_length = 0;
5905 ip->ip_version_and_header_length |= 0xF0;
5908 ip->ip_version_and_header_length |= 0x0F;
5914 #define foreach_ip6_proto_field \
5921 uword unformat_ip6_mask (unformat_input_t * input, va_list * args)
5923 u8 ** maskp = va_arg (*args, u8 **);
5925 u8 found_something = 0;
5927 u32 ip_version_traffic_class_and_flow_label;
5929 #define _(a) u8 a=0;
5930 foreach_ip6_proto_field;
5933 u8 traffic_class = 0;
5936 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
5938 if (unformat (input, "version"))
5940 else if (unformat (input, "traffic-class"))
5942 else if (unformat (input, "flow-label"))
5944 else if (unformat (input, "src"))
5946 else if (unformat (input, "dst"))
5948 else if (unformat (input, "proto"))
5951 #define _(a) else if (unformat (input, #a)) a=1;
5952 foreach_ip6_proto_field
5958 #define _(a) found_something += a;
5959 foreach_ip6_proto_field;
5962 if (found_something == 0)
5965 vec_validate (mask, sizeof (*ip) - 1);
5967 ip = (ip6_header_t *) mask;
5969 #define _(a) if (a) memset (&ip->a, 0xff, sizeof (ip->a));
5970 foreach_ip6_proto_field;
5973 ip_version_traffic_class_and_flow_label = 0;
5976 ip_version_traffic_class_and_flow_label |= 0xF0000000;
5979 ip_version_traffic_class_and_flow_label |= 0x0FF00000;
5982 ip_version_traffic_class_and_flow_label |= 0x000FFFFF;
5984 ip->ip_version_traffic_class_and_flow_label =
5985 clib_host_to_net_u32 (ip_version_traffic_class_and_flow_label);
5991 uword unformat_l3_mask (unformat_input_t * input, va_list * args)
5993 u8 ** maskp = va_arg (*args, u8 **);
5995 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) {
5996 if (unformat (input, "ip4 %U", unformat_ip4_mask, maskp))
5998 else if (unformat (input, "ip6 %U", unformat_ip6_mask, maskp))
6006 uword unformat_l2_mask (unformat_input_t * input, va_list * args)
6008 u8 ** maskp = va_arg (*args, u8 **);
6023 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) {
6024 if (unformat (input, "src"))
6026 else if (unformat (input, "dst"))
6028 else if (unformat (input, "proto"))
6030 else if (unformat (input, "tag1"))
6032 else if (unformat (input, "tag2"))
6034 else if (unformat (input, "ignore-tag1"))
6036 else if (unformat (input, "ignore-tag2"))
6038 else if (unformat (input, "cos1"))
6040 else if (unformat (input, "cos2"))
6042 else if (unformat (input, "dot1q"))
6044 else if (unformat (input, "dot1ad"))
6049 if ((src + dst + proto + tag1 + tag2 + dot1q + dot1ad +
6050 ignore_tag1 + ignore_tag2 + cos1 + cos2) == 0)
6053 if (tag1 || ignore_tag1 || cos1 || dot1q)
6055 if (tag2 || ignore_tag2 || cos2 || dot1ad)
6058 vec_validate (mask, len-1);
6061 memset (mask, 0xff, 6);
6064 memset (mask + 6, 0xff, 6);
6068 /* inner vlan tag */
6077 mask[21] = mask [20] = 0xff;
6098 mask[16] = mask [17] = 0xff;
6108 mask[12] = mask [13] = 0xff;
6114 uword unformat_classify_mask (unformat_input_t * input, va_list * args)
6116 u8 ** maskp = va_arg (*args, u8 **);
6117 u32 * skipp = va_arg (*args, u32 *);
6118 u32 * matchp = va_arg (*args, u32 *);
6125 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) {
6126 if (unformat (input, "hex %U", unformat_hex_string, &mask))
6128 else if (unformat (input, "l2 %U", unformat_l2_mask, &l2))
6130 else if (unformat (input, "l3 %U", unformat_l3_mask, &l3))
6136 if (mask || l2 || l3)
6140 /* "With a free Ethernet header in every package" */
6142 vec_validate (l2, 13);
6144 vec_append (mask, l3);
6148 /* Scan forward looking for the first significant mask octet */
6149 for (i = 0; i < vec_len (mask); i++)
6153 /* compute (skip, match) params */
6154 *skipp = i / sizeof(u32x4);
6155 vec_delete (mask, *skipp * sizeof(u32x4), 0);
6157 /* Pad mask to an even multiple of the vector size */
6158 while (vec_len (mask) % sizeof (u32x4))
6161 match = vec_len (mask) / sizeof (u32x4);
6163 for (i = match*sizeof(u32x4); i > 0; i-= sizeof(u32x4))
6165 u64 *tmp = (u64 *)(mask + (i-sizeof(u32x4)));
6166 if (*tmp || *(tmp+1))
6171 clib_warning ("BUG: match 0");
6173 _vec_len (mask) = match * sizeof(u32x4);
6184 #define foreach_l2_next \
6186 _(ethernet, ETHERNET_INPUT) \
6190 uword unformat_l2_next_index (unformat_input_t * input, va_list * args)
6192 u32 * miss_next_indexp = va_arg (*args, u32 *);
6197 if (unformat (input, #n)) { next_index = L2_CLASSIFY_NEXT_##N; goto out;}
6201 if (unformat (input, "%d", &tmp))
6210 *miss_next_indexp = next_index;
6214 #define foreach_ip_next \
6220 uword unformat_ip_next_index (unformat_input_t * input, va_list * args)
6222 u32 * miss_next_indexp = va_arg (*args, u32 *);
6227 if (unformat (input, #n)) { next_index = IP_LOOKUP_NEXT_##N; goto out;}
6231 if (unformat (input, "%d", &tmp))
6240 *miss_next_indexp = next_index;
6244 #define foreach_acl_next \
6247 uword unformat_acl_next_index (unformat_input_t * input, va_list * args)
6249 u32 * miss_next_indexp = va_arg (*args, u32 *);
6254 if (unformat (input, #n)) { next_index = ACL_NEXT_INDEX_##N; goto out;}
6258 if (unformat (input, "permit"))
6263 else if (unformat (input, "%d", &tmp))
6272 *miss_next_indexp = next_index;
6276 static int api_classify_add_del_table (vat_main_t * vam)
6278 unformat_input_t * i = vam->input;
6279 vl_api_classify_add_del_table_t *mp;
6285 u32 table_index = ~0;
6286 u32 next_table_index = ~0;
6287 u32 miss_next_index = ~0;
6288 u32 memory_size = 32<<20;
6292 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
6293 if (unformat (i, "del"))
6295 else if (unformat (i, "buckets %d", &nbuckets))
6297 else if (unformat (i, "memory_size %d", &memory_size))
6299 else if (unformat (i, "skip %d", &skip))
6301 else if (unformat (i, "match %d", &match))
6303 else if (unformat (i, "table %d", &table_index))
6305 else if (unformat (i, "mask %U", unformat_classify_mask,
6306 &mask, &skip, &match))
6308 else if (unformat (i, "next-table %d", &next_table_index))
6310 else if (unformat (i, "miss-next %U", unformat_ip_next_index,
6313 else if (unformat (i, "l2-miss-next %U", unformat_l2_next_index,
6316 else if (unformat (i, "acl-miss-next %U", unformat_acl_next_index,
6323 if (is_add && mask == 0) {
6324 errmsg ("Mask required\n");
6328 if (is_add && skip == ~0) {
6329 errmsg ("skip count required\n");
6333 if (is_add && match == ~0) {
6334 errmsg ("match count required\n");
6338 if (!is_add && table_index == ~0) {
6339 errmsg ("table index required for delete\n");
6343 M2 (CLASSIFY_ADD_DEL_TABLE, classify_add_del_table,
6346 mp->is_add = is_add;
6347 mp->table_index = ntohl(table_index);
6348 mp->nbuckets = ntohl(nbuckets);
6349 mp->memory_size = ntohl(memory_size);
6350 mp->skip_n_vectors = ntohl(skip);
6351 mp->match_n_vectors = ntohl(match);
6352 mp->next_table_index = ntohl(next_table_index);
6353 mp->miss_next_index = ntohl(miss_next_index);
6354 clib_memcpy (mp->mask, mask, vec_len(mask));
6362 uword unformat_ip4_match (unformat_input_t * input, va_list * args)
6364 u8 ** matchp = va_arg (*args, u8 **);
6371 int src = 0, dst = 0;
6372 ip4_address_t src_val, dst_val;
6379 int fragment_id = 0;
6380 u32 fragment_id_val;
6386 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
6388 if (unformat (input, "version %d", &version_val))
6390 else if (unformat (input, "hdr_length %d", &hdr_length_val))
6392 else if (unformat (input, "src %U", unformat_ip4_address, &src_val))
6394 else if (unformat (input, "dst %U", unformat_ip4_address, &dst_val))
6396 else if (unformat (input, "proto %d", &proto_val))
6398 else if (unformat (input, "tos %d", &tos_val))
6400 else if (unformat (input, "length %d", &length_val))
6402 else if (unformat (input, "fragment_id %d", &fragment_id_val))
6404 else if (unformat (input, "ttl %d", &ttl_val))
6406 else if (unformat (input, "checksum %d", &checksum_val))
6412 if (version + hdr_length + src + dst + proto + tos + length + fragment_id
6413 + ttl + checksum == 0)
6417 * Aligned because we use the real comparison functions
6419 vec_validate_aligned (match, sizeof (*ip) - 1, sizeof(u32x4));
6421 ip = (ip4_header_t *) match;
6423 /* These are realistically matched in practice */
6425 ip->src_address.as_u32 = src_val.as_u32;
6428 ip->dst_address.as_u32 = dst_val.as_u32;
6431 ip->protocol = proto_val;
6434 /* These are not, but they're included for completeness */
6436 ip->ip_version_and_header_length |= (version_val & 0xF)<<4;
6439 ip->ip_version_and_header_length |= (hdr_length_val & 0xF);
6445 ip->length = length_val;
6451 ip->checksum = checksum_val;
6457 uword unformat_ip6_match (unformat_input_t * input, va_list * args)
6459 u8 ** matchp = va_arg (*args, u8 **);
6465 u32 traffic_class_val;
6468 int src = 0, dst = 0;
6469 ip6_address_t src_val, dst_val;
6472 int payload_length = 0;
6473 u32 payload_length_val;
6476 u32 ip_version_traffic_class_and_flow_label;
6478 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
6480 if (unformat (input, "version %d", &version_val))
6482 else if (unformat (input, "traffic_class %d", &traffic_class_val))
6484 else if (unformat (input, "flow_label %d", &flow_label_val))
6486 else if (unformat (input, "src %U", unformat_ip6_address, &src_val))
6488 else if (unformat (input, "dst %U", unformat_ip6_address, &dst_val))
6490 else if (unformat (input, "proto %d", &proto_val))
6492 else if (unformat (input, "payload_length %d", &payload_length_val))
6494 else if (unformat (input, "hop_limit %d", &hop_limit_val))
6500 if (version + traffic_class + flow_label + src + dst + proto +
6501 payload_length + hop_limit == 0)
6505 * Aligned because we use the real comparison functions
6507 vec_validate_aligned (match, sizeof (*ip) - 1, sizeof(u32x4));
6509 ip = (ip6_header_t *) match;
6512 clib_memcpy (&ip->src_address, &src_val, sizeof (ip->src_address));
6515 clib_memcpy (&ip->dst_address, &dst_val, sizeof (ip->dst_address));
6518 ip->protocol = proto_val;
6520 ip_version_traffic_class_and_flow_label = 0;
6523 ip_version_traffic_class_and_flow_label |= (version_val & 0xF) << 28;
6526 ip_version_traffic_class_and_flow_label |= (traffic_class_val & 0xFF) << 20;
6529 ip_version_traffic_class_and_flow_label |= (flow_label_val & 0xFFFFF);
6531 ip->ip_version_traffic_class_and_flow_label =
6532 clib_host_to_net_u32 (ip_version_traffic_class_and_flow_label);
6535 ip->payload_length = clib_host_to_net_u16 (payload_length_val);
6538 ip->hop_limit = hop_limit_val;
6544 uword unformat_l3_match (unformat_input_t * input, va_list * args)
6546 u8 ** matchp = va_arg (*args, u8 **);
6548 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) {
6549 if (unformat (input, "ip4 %U", unformat_ip4_match, matchp))
6551 else if (unformat (input, "ip6 %U", unformat_ip6_match, matchp))
6559 uword unformat_vlan_tag (unformat_input_t * input, va_list * args)
6561 u8 * tagp = va_arg (*args, u8 *);
6564 if (unformat(input, "%d", &tag))
6566 tagp[0] = (tag>>8) & 0x0F;
6567 tagp[1] = tag & 0xFF;
6574 uword unformat_l2_match (unformat_input_t * input, va_list * args)
6576 u8 ** matchp = va_arg (*args, u8 **);
6596 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) {
6597 if (unformat (input, "src %U", unformat_ethernet_address, &src_val))
6599 else if (unformat (input, "dst %U", unformat_ethernet_address, &dst_val))
6601 else if (unformat (input, "proto %U",
6602 unformat_ethernet_type_host_byte_order, &proto_val))
6604 else if (unformat (input, "tag1 %U", unformat_vlan_tag, tag1_val))
6606 else if (unformat (input, "tag2 %U", unformat_vlan_tag, tag2_val))
6608 else if (unformat (input, "ignore-tag1"))
6610 else if (unformat (input, "ignore-tag2"))
6612 else if (unformat (input, "cos1 %d", &cos1_val))
6614 else if (unformat (input, "cos2 %d", &cos2_val))
6619 if ((src + dst + proto + tag1 + tag2 +
6620 ignore_tag1 + ignore_tag2 + cos1 + cos2) == 0)
6623 if (tag1 || ignore_tag1 || cos1)
6625 if (tag2 || ignore_tag2 || cos2)
6628 vec_validate_aligned (match, len-1, sizeof(u32x4));
6631 clib_memcpy (match, dst_val, 6);
6634 clib_memcpy (match + 6, src_val, 6);
6638 /* inner vlan tag */
6639 match[19] = tag2_val[1];
6640 match[18] = tag2_val[0];
6642 match [18] |= (cos2_val & 0x7) << 5;
6645 match[21] = proto_val & 0xff;
6646 match[20] = proto_val >> 8;
6650 match [15] = tag1_val[1];
6651 match [14] = tag1_val[0];
6654 match [14] |= (cos1_val & 0x7) << 5;
6660 match [15] = tag1_val[1];
6661 match [14] = tag1_val[0];
6664 match[17] = proto_val & 0xff;
6665 match[16] = proto_val >> 8;
6668 match [14] |= (cos1_val & 0x7) << 5;
6674 match [18] |= (cos2_val & 0x7) << 5;
6676 match [14] |= (cos1_val & 0x7) << 5;
6679 match[13] = proto_val & 0xff;
6680 match[12] = proto_val >> 8;
6688 uword unformat_classify_match (unformat_input_t * input, va_list * args)
6690 u8 ** matchp = va_arg (*args, u8 **);
6691 u32 skip_n_vectors = va_arg (*args, u32);
6692 u32 match_n_vectors = va_arg (*args, u32);
6698 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) {
6699 if (unformat (input, "hex %U", unformat_hex_string, &match))
6701 else if (unformat (input, "l2 %U", unformat_l2_match, &l2))
6703 else if (unformat (input, "l3 %U", unformat_l3_match, &l3))
6709 if (match || l2 || l3)
6713 /* "Win a free Ethernet header in every packet" */
6715 vec_validate_aligned (l2, 13, sizeof(u32x4));
6717 vec_append_aligned (match, l3, sizeof(u32x4));
6721 /* Make sure the vector is big enough even if key is all 0's */
6722 vec_validate_aligned
6723 (match, ((match_n_vectors + skip_n_vectors) * sizeof(u32x4)) - 1,
6726 /* Set size, include skipped vectors*/
6727 _vec_len (match) = (match_n_vectors+skip_n_vectors) * sizeof(u32x4);
6737 static int api_classify_add_del_session (vat_main_t * vam)
6739 unformat_input_t * i = vam->input;
6740 vl_api_classify_add_del_session_t *mp;
6742 u32 table_index = ~0;
6743 u32 hit_next_index = ~0;
6744 u32 opaque_index = ~0;
6748 u32 skip_n_vectors = 0;
6749 u32 match_n_vectors = 0;
6752 * Warning: you have to supply skip_n and match_n
6753 * because the API client cant simply look at the classify
6757 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
6758 if (unformat (i, "del"))
6760 else if (unformat (i, "hit-next %U", unformat_ip_next_index,
6763 else if (unformat (i, "l2-hit-next %U", unformat_l2_next_index,
6766 else if (unformat (i, "acl-hit-next %U", unformat_acl_next_index,
6769 else if (unformat (i, "opaque-index %d", &opaque_index))
6771 else if (unformat (i, "skip_n %d", &skip_n_vectors))
6773 else if (unformat (i, "match_n %d", &match_n_vectors))
6775 else if (unformat (i, "match %U", unformat_classify_match,
6776 &match, skip_n_vectors, match_n_vectors))
6778 else if (unformat (i, "advance %d", &advance))
6780 else if (unformat (i, "table-index %d", &table_index))
6786 if (table_index == ~0) {
6787 errmsg ("Table index required\n");
6791 if (is_add && match == 0) {
6792 errmsg ("Match value required\n");
6796 M2 (CLASSIFY_ADD_DEL_SESSION, classify_add_del_session,
6799 mp->is_add = is_add;
6800 mp->table_index = ntohl(table_index);
6801 mp->hit_next_index = ntohl(hit_next_index);
6802 mp->opaque_index = ntohl(opaque_index);
6803 mp->advance = ntohl(advance);
6804 clib_memcpy (mp->match, match, vec_len(match));
6811 static int api_classify_set_interface_ip_table (vat_main_t * vam)
6813 unformat_input_t * i = vam->input;
6814 vl_api_classify_set_interface_ip_table_t *mp;
6817 int sw_if_index_set;
6818 u32 table_index = ~0;
6821 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
6822 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
6823 sw_if_index_set = 1;
6824 else if (unformat (i, "sw_if_index %d", &sw_if_index))
6825 sw_if_index_set = 1;
6826 else if (unformat (i, "table %d", &table_index))
6829 clib_warning ("parse error '%U'", format_unformat_error, i);
6834 if (sw_if_index_set == 0) {
6835 errmsg ("missing interface name or sw_if_index\n");
6840 M(CLASSIFY_SET_INTERFACE_IP_TABLE, classify_set_interface_ip_table);
6842 mp->sw_if_index = ntohl(sw_if_index);
6843 mp->table_index = ntohl(table_index);
6844 mp->is_ipv6 = is_ipv6;
6851 static int api_classify_set_interface_l2_tables (vat_main_t * vam)
6853 unformat_input_t * i = vam->input;
6854 vl_api_classify_set_interface_l2_tables_t *mp;
6857 int sw_if_index_set;
6858 u32 ip4_table_index = ~0;
6859 u32 ip6_table_index = ~0;
6860 u32 other_table_index = ~0;
6862 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
6863 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
6864 sw_if_index_set = 1;
6865 else if (unformat (i, "sw_if_index %d", &sw_if_index))
6866 sw_if_index_set = 1;
6867 else if (unformat (i, "ip4-table %d", &ip4_table_index))
6869 else if (unformat (i, "ip6-table %d", &ip6_table_index))
6871 else if (unformat (i, "other-table %d", &other_table_index))
6874 clib_warning ("parse error '%U'", format_unformat_error, i);
6879 if (sw_if_index_set == 0) {
6880 errmsg ("missing interface name or sw_if_index\n");
6885 M(CLASSIFY_SET_INTERFACE_L2_TABLES, classify_set_interface_l2_tables);
6887 mp->sw_if_index = ntohl(sw_if_index);
6888 mp->ip4_table_index = ntohl(ip4_table_index);
6889 mp->ip6_table_index = ntohl(ip6_table_index);
6890 mp->other_table_index = ntohl(other_table_index);
6898 static int api_get_node_index (vat_main_t * vam)
6900 unformat_input_t * i = vam->input;
6901 vl_api_get_node_index_t * mp;
6905 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
6906 if (unformat (i, "node %s", &name))
6912 errmsg ("node name required\n");
6915 if (vec_len (name) >= ARRAY_LEN(mp->node_name)) {
6916 errmsg ("node name too long, max %d\n", ARRAY_LEN(mp->node_name));
6920 M(GET_NODE_INDEX, get_node_index);
6921 clib_memcpy (mp->node_name, name, vec_len(name));
6929 static int api_add_node_next (vat_main_t * vam)
6931 unformat_input_t * i = vam->input;
6932 vl_api_add_node_next_t * mp;
6937 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
6938 if (unformat (i, "node %s", &name))
6940 else if (unformat (i, "next %s", &next))
6946 errmsg ("node name required\n");
6949 if (vec_len (name) >= ARRAY_LEN(mp->node_name)) {
6950 errmsg ("node name too long, max %d\n", ARRAY_LEN(mp->node_name));
6954 errmsg ("next node required\n");
6957 if (vec_len (next) >= ARRAY_LEN(mp->next_name)) {
6958 errmsg ("next name too long, max %d\n", ARRAY_LEN(mp->next_name));
6962 M(ADD_NODE_NEXT, add_node_next);
6963 clib_memcpy (mp->node_name, name, vec_len(name));
6964 clib_memcpy (mp->next_name, next, vec_len(next));
6973 static int api_l2tpv3_create_tunnel (vat_main_t * vam)
6975 unformat_input_t * i = vam->input;
6976 ip6_address_t client_address, our_address;
6977 int client_address_set = 0;
6978 int our_address_set = 0;
6979 u32 local_session_id = 0;
6980 u32 remote_session_id = 0;
6981 u64 local_cookie = 0;
6982 u64 remote_cookie = 0;
6983 u8 l2_sublayer_present = 0;
6984 vl_api_l2tpv3_create_tunnel_t * mp;
6987 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
6988 if (unformat (i, "client_address %U", unformat_ip6_address,
6990 client_address_set = 1;
6991 else if (unformat (i, "our_address %U", unformat_ip6_address,
6993 our_address_set = 1;
6994 else if (unformat (i, "local_session_id %d", &local_session_id))
6996 else if (unformat (i, "remote_session_id %d", &remote_session_id))
6998 else if (unformat (i, "local_cookie %lld", &local_cookie))
7000 else if (unformat (i, "remote_cookie %lld", &remote_cookie))
7002 else if (unformat (i, "l2-sublayer-present"))
7003 l2_sublayer_present = 1;
7008 if (client_address_set == 0) {
7009 errmsg ("client_address required\n");
7013 if (our_address_set == 0) {
7014 errmsg ("our_address required\n");
7018 M(L2TPV3_CREATE_TUNNEL, l2tpv3_create_tunnel);
7020 clib_memcpy (mp->client_address, client_address.as_u8,
7021 sizeof (mp->client_address));
7023 clib_memcpy (mp->our_address, our_address.as_u8,
7024 sizeof (mp->our_address));
7026 mp->local_session_id = ntohl (local_session_id);
7027 mp->remote_session_id = ntohl (remote_session_id);
7028 mp->local_cookie = clib_host_to_net_u64 (local_cookie);
7029 mp->remote_cookie = clib_host_to_net_u64 (remote_cookie);
7030 mp->l2_sublayer_present = l2_sublayer_present;
7038 static int api_l2tpv3_set_tunnel_cookies (vat_main_t * vam)
7040 unformat_input_t * i = vam->input;
7042 u8 sw_if_index_set = 0;
7043 u64 new_local_cookie = 0;
7044 u64 new_remote_cookie = 0;
7045 vl_api_l2tpv3_set_tunnel_cookies_t *mp;
7048 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
7049 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
7050 sw_if_index_set = 1;
7051 else if (unformat (i, "sw_if_index %d", &sw_if_index))
7052 sw_if_index_set = 1;
7053 else if (unformat (i, "new_local_cookie %lld", &new_local_cookie))
7055 else if (unformat (i, "new_remote_cookie %lld", &new_remote_cookie))
7061 if (sw_if_index_set == 0) {
7062 errmsg ("missing interface name or sw_if_index\n");
7066 M(L2TPV3_SET_TUNNEL_COOKIES, l2tpv3_set_tunnel_cookies);
7068 mp->sw_if_index = ntohl(sw_if_index);
7069 mp->new_local_cookie = clib_host_to_net_u64 (new_local_cookie);
7070 mp->new_remote_cookie = clib_host_to_net_u64 (new_remote_cookie);
7077 static int api_l2tpv3_interface_enable_disable (vat_main_t * vam)
7079 unformat_input_t * i = vam->input;
7080 vl_api_l2tpv3_interface_enable_disable_t *mp;
7083 u8 sw_if_index_set = 0;
7084 u8 enable_disable = 1;
7086 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
7087 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
7088 sw_if_index_set = 1;
7089 else if (unformat (i, "sw_if_index %d", &sw_if_index))
7090 sw_if_index_set = 1;
7091 else if (unformat (i, "enable"))
7093 else if (unformat (i, "disable"))
7099 if (sw_if_index_set == 0) {
7100 errmsg ("missing interface name or sw_if_index\n");
7104 M(L2TPV3_INTERFACE_ENABLE_DISABLE, l2tpv3_interface_enable_disable);
7106 mp->sw_if_index = ntohl(sw_if_index);
7107 mp->enable_disable = enable_disable;
7114 static int api_l2tpv3_set_lookup_key (vat_main_t * vam)
7116 unformat_input_t * i = vam->input;
7117 vl_api_l2tpv3_set_lookup_key_t * mp;
7121 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
7122 if (unformat (i, "lookup_v6_src"))
7123 key = L2T_LOOKUP_SRC_ADDRESS;
7124 else if (unformat (i, "lookup_v6_dst"))
7125 key = L2T_LOOKUP_DST_ADDRESS;
7126 else if (unformat (i, "lookup_session_id"))
7127 key = L2T_LOOKUP_SESSION_ID;
7132 if (key == (u8) ~0) {
7133 errmsg ("l2tp session lookup key unset\n");
7137 M(L2TPV3_SET_LOOKUP_KEY, l2tpv3_set_lookup_key);
7146 static void vl_api_sw_if_l2tpv3_tunnel_details_t_handler
7147 (vl_api_sw_if_l2tpv3_tunnel_details_t * mp)
7149 vat_main_t * vam = &vat_main;
7151 fformat(vam->ofp, "* %U (our) %U (client) (sw_if_index %d)\n",
7152 format_ip6_address, mp->our_address,
7153 format_ip6_address, mp->client_address,
7154 clib_net_to_host_u32(mp->sw_if_index));
7156 fformat (vam->ofp, " local cookies %016llx %016llx remote cookie %016llx\n",
7157 clib_net_to_host_u64 (mp->local_cookie[0]),
7158 clib_net_to_host_u64 (mp->local_cookie[1]),
7159 clib_net_to_host_u64 (mp->remote_cookie));
7161 fformat (vam->ofp, " local session-id %d remote session-id %d\n",
7162 clib_net_to_host_u32 (mp->local_session_id),
7163 clib_net_to_host_u32 (mp->remote_session_id));
7165 fformat (vam->ofp, " l2 specific sublayer %s\n\n",
7166 mp->l2_sublayer_present ? "preset" : "absent");
7170 static void vl_api_sw_if_l2tpv3_tunnel_details_t_handler_json
7171 (vl_api_sw_if_l2tpv3_tunnel_details_t * mp)
7173 vat_main_t * vam = &vat_main;
7174 vat_json_node_t *node = NULL;
7175 struct in6_addr addr;
7177 if (VAT_JSON_ARRAY != vam->json_tree.type) {
7178 ASSERT(VAT_JSON_NONE == vam->json_tree.type);
7179 vat_json_init_array(&vam->json_tree);
7181 node = vat_json_array_add(&vam->json_tree);
7183 vat_json_init_object(node);
7185 clib_memcpy(&addr, mp->our_address, sizeof(addr));
7186 vat_json_object_add_ip6(node, "our_address", addr);
7187 clib_memcpy(&addr, mp->client_address, sizeof(addr));
7188 vat_json_object_add_ip6(node, "client_address", addr);
7190 vat_json_node_t * lc = vat_json_object_add(node, "local_cookie");
7191 vat_json_init_array(lc);
7192 vat_json_array_add_uint(lc, clib_net_to_host_u64(mp->local_cookie[0]));
7193 vat_json_array_add_uint(lc, clib_net_to_host_u64(mp->local_cookie[1]));
7194 vat_json_object_add_uint(node, "remote_cookie", clib_net_to_host_u64(mp->remote_cookie));
7196 printf("local id: %u", clib_net_to_host_u32(mp->local_session_id));
7197 vat_json_object_add_uint(node, "local_session_id", clib_net_to_host_u32(mp->local_session_id));
7198 vat_json_object_add_uint(node, "remote_session_id", clib_net_to_host_u32(mp->remote_session_id));
7199 vat_json_object_add_string_copy(node, "l2_sublayer", mp->l2_sublayer_present ?
7200 (u8*)"present" : (u8*)"absent");
7203 static int api_sw_if_l2tpv3_tunnel_dump (vat_main_t * vam)
7205 vl_api_sw_if_l2tpv3_tunnel_dump_t *mp;
7208 /* Get list of l2tpv3-tunnel interfaces */
7209 M(SW_IF_L2TPV3_TUNNEL_DUMP, sw_if_l2tpv3_tunnel_dump);
7212 /* Use a control ping for synchronization */
7214 vl_api_control_ping_t * mp;
7215 M(CONTROL_PING, control_ping);
7222 static void vl_api_sw_interface_tap_details_t_handler
7223 (vl_api_sw_interface_tap_details_t * mp)
7225 vat_main_t * vam = &vat_main;
7227 fformat(vam->ofp, "%-16s %d\n",
7229 clib_net_to_host_u32(mp->sw_if_index));
7232 static void vl_api_sw_interface_tap_details_t_handler_json
7233 (vl_api_sw_interface_tap_details_t * mp)
7235 vat_main_t * vam = &vat_main;
7236 vat_json_node_t *node = NULL;
7238 if (VAT_JSON_ARRAY != vam->json_tree.type) {
7239 ASSERT(VAT_JSON_NONE == vam->json_tree.type);
7240 vat_json_init_array(&vam->json_tree);
7242 node = vat_json_array_add(&vam->json_tree);
7244 vat_json_init_object(node);
7245 vat_json_object_add_uint(node, "sw_if_index", ntohl(mp->sw_if_index));
7246 vat_json_object_add_string_copy(node, "dev_name", mp->dev_name);
7249 static int api_sw_interface_tap_dump (vat_main_t * vam)
7251 vl_api_sw_interface_tap_dump_t *mp;
7254 fformat(vam->ofp, "\n%-16s %s\n", "dev_name", "sw_if_index");
7255 /* Get list of tap interfaces */
7256 M(SW_INTERFACE_TAP_DUMP, sw_interface_tap_dump);
7259 /* Use a control ping for synchronization */
7261 vl_api_control_ping_t * mp;
7262 M(CONTROL_PING, control_ping);
7268 static uword unformat_vxlan_decap_next
7269 (unformat_input_t * input, va_list * args)
7271 u32 * result = va_arg (*args, u32 *);
7274 if (unformat (input, "drop"))
7275 *result = VXLAN_INPUT_NEXT_DROP;
7276 else if (unformat (input, "ip4"))
7277 *result = VXLAN_INPUT_NEXT_IP4_INPUT;
7278 else if (unformat (input, "ip6"))
7279 *result = VXLAN_INPUT_NEXT_IP6_INPUT;
7280 else if (unformat (input, "l2"))
7281 *result = VXLAN_INPUT_NEXT_L2_INPUT;
7282 else if (unformat (input, "%d", &tmp))
7289 static int api_vxlan_add_del_tunnel (vat_main_t * vam)
7291 unformat_input_t * line_input = vam->input;
7292 vl_api_vxlan_add_del_tunnel_t *mp;
7294 ip4_address_t src4, dst4;
7295 ip6_address_t src6, dst6;
7297 u8 ipv4_set = 0, ipv6_set = 0;
7300 u32 encap_vrf_id = 0;
7301 u32 decap_next_index = ~0;
7304 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) {
7305 if (unformat (line_input, "del"))
7307 else if (unformat (line_input, "src %U",
7308 unformat_ip4_address, &src4))
7313 else if (unformat (line_input, "dst %U",
7314 unformat_ip4_address, &dst4))
7319 else if (unformat (line_input, "src %U",
7320 unformat_ip6_address, &src6))
7325 else if (unformat (line_input, "dst %U",
7326 unformat_ip6_address, &dst6))
7331 else if (unformat (line_input, "encap-vrf-id %d", &encap_vrf_id))
7333 else if (unformat (line_input, "decap-next %U",
7334 unformat_vxlan_decap_next, &decap_next_index))
7336 else if (unformat (line_input, "vni %d", &vni))
7339 errmsg ("parse error '%U'\n", format_unformat_error, line_input);
7345 errmsg ("tunnel src address not specified\n");
7349 errmsg ("tunnel dst address not specified\n");
7353 if (ipv4_set && ipv6_set) {
7354 errmsg ("both IPv4 and IPv6 addresses specified");
7358 if ((vni == 0) || (vni>>24)) {
7359 errmsg ("vni not specified or out of range\n");
7363 M (VXLAN_ADD_DEL_TUNNEL, vxlan_add_del_tunnel);
7366 clib_memcpy(&mp->dst_address, &src6, sizeof(src6));
7367 clib_memcpy(&mp->dst_address, &src6, sizeof(dst6));
7369 clib_memcpy(&mp->src_address, &src4, sizeof(src4));
7370 clib_memcpy(&mp->dst_address, &dst4, sizeof(dst4));
7372 mp->encap_vrf_id = ntohl(encap_vrf_id);
7373 mp->decap_next_index = ntohl(decap_next_index);
7374 mp->vni = ntohl(vni);
7375 mp->is_add = is_add;
7376 mp->is_ipv6 = ipv6_set;
7383 static void vl_api_vxlan_tunnel_details_t_handler
7384 (vl_api_vxlan_tunnel_details_t * mp)
7386 vat_main_t * vam = &vat_main;
7388 fformat(vam->ofp, "%11d%24U%24U%14d%18d%13d\n",
7389 ntohl(mp->sw_if_index),
7390 format_ip46_address, &(mp->src_address[0]),
7391 format_ip46_address, &(mp->dst_address[0]),
7392 ntohl(mp->encap_vrf_id),
7393 ntohl(mp->decap_next_index),
7397 static void vl_api_vxlan_tunnel_details_t_handler_json
7398 (vl_api_vxlan_tunnel_details_t * mp)
7400 vat_main_t * vam = &vat_main;
7401 vat_json_node_t *node = NULL;
7403 struct in6_addr ip6;
7405 if (VAT_JSON_ARRAY != vam->json_tree.type) {
7406 ASSERT(VAT_JSON_NONE == vam->json_tree.type);
7407 vat_json_init_array(&vam->json_tree);
7409 node = vat_json_array_add(&vam->json_tree);
7411 vat_json_init_object(node);
7412 vat_json_object_add_uint(node, "sw_if_index", ntohl(mp->sw_if_index));
7414 clib_memcpy(&ip6, &(mp->src_address[0]), sizeof(ip6));
7415 vat_json_object_add_ip6(node, "src_address", ip6);
7416 clib_memcpy(&ip6, &(mp->dst_address[0]), sizeof(ip6));
7417 vat_json_object_add_ip6(node, "dst_address", ip6);
7419 clib_memcpy(&ip4, &(mp->src_address[0]), sizeof(ip4));
7420 vat_json_object_add_ip4(node, "src_address", ip4);
7421 clib_memcpy(&ip4, &(mp->dst_address[0]), sizeof(ip4));
7422 vat_json_object_add_ip4(node, "dst_address", ip4);
7424 vat_json_object_add_uint(node, "encap_vrf_id", ntohl(mp->encap_vrf_id));
7425 vat_json_object_add_uint(node, "decap_next_index", ntohl(mp->decap_next_index));
7426 vat_json_object_add_uint(node, "vni", ntohl(mp->vni));
7427 vat_json_object_add_uint(node, "is_ipv6", mp->is_ipv6 ? 1 : 0);
7430 static int api_vxlan_tunnel_dump (vat_main_t * vam)
7432 unformat_input_t * i = vam->input;
7433 vl_api_vxlan_tunnel_dump_t *mp;
7436 u8 sw_if_index_set = 0;
7438 /* Parse args required to build the message */
7439 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
7440 if (unformat (i, "sw_if_index %d", &sw_if_index))
7441 sw_if_index_set = 1;
7446 if (sw_if_index_set == 0) {
7450 if (!vam->json_output) {
7451 fformat(vam->ofp, "%11s%24s%24s%14s%18s%13s\n",
7452 "sw_if_index", "src_address", "dst_address",
7453 "encap_vrf_id", "decap_next_index", "vni");
7456 /* Get list of vxlan-tunnel interfaces */
7457 M(VXLAN_TUNNEL_DUMP, vxlan_tunnel_dump);
7459 mp->sw_if_index = htonl(sw_if_index);
7463 /* Use a control ping for synchronization */
7465 vl_api_control_ping_t * mp;
7466 M(CONTROL_PING, control_ping);
7472 static int api_gre_add_del_tunnel (vat_main_t * vam)
7474 unformat_input_t * line_input = vam->input;
7475 vl_api_gre_add_del_tunnel_t *mp;
7477 ip4_address_t src4, dst4;
7481 u32 outer_fib_id = 0;
7483 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) {
7484 if (unformat (line_input, "del"))
7486 else if (unformat (line_input, "src %U",
7487 unformat_ip4_address, &src4))
7489 else if (unformat (line_input, "dst %U",
7490 unformat_ip4_address, &dst4))
7492 else if (unformat (line_input, "outer-fib-id %d", &outer_fib_id))
7495 errmsg ("parse error '%U'\n", format_unformat_error, line_input);
7501 errmsg ("tunnel src address not specified\n");
7505 errmsg ("tunnel dst address not specified\n");
7510 M (GRE_ADD_DEL_TUNNEL, gre_add_del_tunnel);
7512 clib_memcpy(&mp->src_address, &src4, sizeof(src4));
7513 clib_memcpy(&mp->dst_address, &dst4, sizeof(dst4));
7514 mp->outer_table_id = ntohl(outer_fib_id);
7515 mp->is_add = is_add;
7522 static void vl_api_gre_tunnel_details_t_handler
7523 (vl_api_gre_tunnel_details_t * mp)
7525 vat_main_t * vam = &vat_main;
7527 fformat(vam->ofp, "%11d%15U%15U%14d\n",
7528 ntohl(mp->sw_if_index),
7529 format_ip4_address, &mp->src_address,
7530 format_ip4_address, &mp->dst_address,
7531 ntohl(mp->outer_table_id));
7534 static void vl_api_gre_tunnel_details_t_handler_json
7535 (vl_api_gre_tunnel_details_t * mp)
7537 vat_main_t * vam = &vat_main;
7538 vat_json_node_t *node = NULL;
7541 if (VAT_JSON_ARRAY != vam->json_tree.type) {
7542 ASSERT(VAT_JSON_NONE == vam->json_tree.type);
7543 vat_json_init_array(&vam->json_tree);
7545 node = vat_json_array_add(&vam->json_tree);
7547 vat_json_init_object(node);
7548 vat_json_object_add_uint(node, "sw_if_index", ntohl(mp->sw_if_index));
7549 clib_memcpy(&ip4, &mp->src_address, sizeof(ip4));
7550 vat_json_object_add_ip4(node, "src_address", ip4);
7551 clib_memcpy(&ip4, &mp->dst_address, sizeof(ip4));
7552 vat_json_object_add_ip4(node, "dst_address", ip4);
7553 vat_json_object_add_uint(node, "outer_fib_id", ntohl(mp->outer_table_id));
7556 static int api_gre_tunnel_dump (vat_main_t * vam)
7558 unformat_input_t * i = vam->input;
7559 vl_api_gre_tunnel_dump_t *mp;
7562 u8 sw_if_index_set = 0;
7564 /* Parse args required to build the message */
7565 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
7566 if (unformat (i, "sw_if_index %d", &sw_if_index))
7567 sw_if_index_set = 1;
7572 if (sw_if_index_set == 0) {
7576 if (!vam->json_output) {
7577 fformat(vam->ofp, "%11s%15s%15s%14s\n",
7578 "sw_if_index", "src_address", "dst_address",
7582 /* Get list of gre-tunnel interfaces */
7583 M(GRE_TUNNEL_DUMP, gre_tunnel_dump);
7585 mp->sw_if_index = htonl(sw_if_index);
7589 /* Use a control ping for synchronization */
7591 vl_api_control_ping_t * mp;
7592 M(CONTROL_PING, control_ping);
7598 static int api_l2_fib_clear_table (vat_main_t * vam)
7600 // unformat_input_t * i = vam->input;
7601 vl_api_l2_fib_clear_table_t *mp;
7604 M(L2_FIB_CLEAR_TABLE, l2_fib_clear_table);
7611 static int api_l2_interface_efp_filter (vat_main_t * vam)
7613 unformat_input_t * i = vam->input;
7614 vl_api_l2_interface_efp_filter_t *mp;
7618 u8 sw_if_index_set = 0;
7620 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
7621 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
7622 sw_if_index_set = 1;
7623 else if (unformat (i, "sw_if_index %d", &sw_if_index))
7624 sw_if_index_set = 1;
7625 else if (unformat (i, "enable"))
7627 else if (unformat (i, "disable"))
7630 clib_warning ("parse error '%U'", format_unformat_error, i);
7635 if (sw_if_index_set == 0) {
7636 errmsg ("missing sw_if_index\n");
7640 M(L2_INTERFACE_EFP_FILTER, l2_interface_efp_filter);
7642 mp->sw_if_index = ntohl(sw_if_index);
7643 mp->enable_disable = enable;
7650 #define foreach_vtr_op \
7651 _("disable", L2_VTR_DISABLED) \
7652 _("push-1", L2_VTR_PUSH_1) \
7653 _("push-2", L2_VTR_PUSH_2) \
7654 _("pop-1", L2_VTR_POP_1) \
7655 _("pop-2", L2_VTR_POP_2) \
7656 _("translate-1-1", L2_VTR_TRANSLATE_1_1) \
7657 _("translate-1-2", L2_VTR_TRANSLATE_1_2) \
7658 _("translate-2-1", L2_VTR_TRANSLATE_2_1) \
7659 _("translate-2-2", L2_VTR_TRANSLATE_2_2)
7661 static int api_l2_interface_vlan_tag_rewrite (vat_main_t * vam)
7663 unformat_input_t * i = vam->input;
7664 vl_api_l2_interface_vlan_tag_rewrite_t *mp;
7667 u8 sw_if_index_set = 0;
7674 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
7675 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
7676 sw_if_index_set = 1;
7677 else if (unformat (i, "sw_if_index %d", &sw_if_index))
7678 sw_if_index_set = 1;
7679 else if (unformat (i, "vtr_op %d", &vtr_op))
7681 #define _(n,v) else if (unformat(i, n)) {vtr_op = v; vtr_op_set = 1;}
7685 else if (unformat (i, "push_dot1q %d", &push_dot1q))
7687 else if (unformat (i, "tag1 %d", &tag1))
7689 else if (unformat (i, "tag2 %d", &tag2))
7692 clib_warning ("parse error '%U'", format_unformat_error, i);
7697 if ((sw_if_index_set == 0)||(vtr_op_set == 0)) {
7698 errmsg ("missing vtr operation or sw_if_index\n");
7702 M(L2_INTERFACE_VLAN_TAG_REWRITE, l2_interface_vlan_tag_rewrite)
7704 mp->sw_if_index = ntohl(sw_if_index);
7705 mp->vtr_op = ntohl(vtr_op);
7706 mp->push_dot1q = ntohl(push_dot1q);
7707 mp->tag1 = ntohl(tag1);
7708 mp->tag2 = ntohl(tag2);
7715 static int api_create_vhost_user_if (vat_main_t * vam)
7717 unformat_input_t * i = vam->input;
7718 vl_api_create_vhost_user_if_t *mp;
7722 u8 file_name_set = 0;
7723 u32 custom_dev_instance = ~0;
7725 u8 use_custom_mac = 0;
7727 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
7728 if (unformat (i, "socket %s", &file_name)) {
7731 else if (unformat (i, "renumber %"PRIu32, &custom_dev_instance))
7733 else if (unformat (i, "mac %U", unformat_ethernet_address, hwaddr))
7735 else if (unformat (i, "server"))
7741 if (file_name_set == 0) {
7742 errmsg ("missing socket file name\n");
7746 if (vec_len (file_name) > 255) {
7747 errmsg ("socket file name too long\n");
7750 vec_add1 (file_name, 0);
7752 M(CREATE_VHOST_USER_IF, create_vhost_user_if);
7754 mp->is_server = is_server;
7755 clib_memcpy(mp->sock_filename, file_name, vec_len(file_name));
7756 vec_free(file_name);
7757 if (custom_dev_instance != ~0) {
7759 mp->custom_dev_instance = ntohl(custom_dev_instance);
7761 mp->use_custom_mac = use_custom_mac;
7762 clib_memcpy(mp->mac_address, hwaddr, 6);
7769 static int api_modify_vhost_user_if (vat_main_t * vam)
7771 unformat_input_t * i = vam->input;
7772 vl_api_modify_vhost_user_if_t *mp;
7776 u8 file_name_set = 0;
7777 u32 custom_dev_instance = ~0;
7778 u8 sw_if_index_set = 0;
7779 u32 sw_if_index = (u32)~0;
7781 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
7782 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
7783 sw_if_index_set = 1;
7784 else if (unformat (i, "sw_if_index %d", &sw_if_index))
7785 sw_if_index_set = 1;
7786 else if (unformat (i, "socket %s", &file_name)) {
7789 else if (unformat (i, "renumber %"PRIu32, &custom_dev_instance))
7791 else if (unformat (i, "server"))
7797 if (sw_if_index_set == 0) {
7798 errmsg ("missing sw_if_index or interface name\n");
7802 if (file_name_set == 0) {
7803 errmsg ("missing socket file name\n");
7807 if (vec_len (file_name) > 255) {
7808 errmsg ("socket file name too long\n");
7811 vec_add1 (file_name, 0);
7813 M(MODIFY_VHOST_USER_IF, modify_vhost_user_if);
7815 mp->sw_if_index = ntohl(sw_if_index);
7816 mp->is_server = is_server;
7817 clib_memcpy(mp->sock_filename, file_name, vec_len(file_name));
7818 vec_free(file_name);
7819 if (custom_dev_instance != ~0) {
7821 mp->custom_dev_instance = ntohl(custom_dev_instance);
7829 static int api_delete_vhost_user_if (vat_main_t * vam)
7831 unformat_input_t * i = vam->input;
7832 vl_api_delete_vhost_user_if_t *mp;
7834 u32 sw_if_index = ~0;
7835 u8 sw_if_index_set = 0;
7837 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
7838 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
7839 sw_if_index_set = 1;
7840 else if (unformat (i, "sw_if_index %d", &sw_if_index))
7841 sw_if_index_set = 1;
7846 if (sw_if_index_set == 0) {
7847 errmsg ("missing sw_if_index or interface name\n");
7852 M(DELETE_VHOST_USER_IF, delete_vhost_user_if);
7854 mp->sw_if_index = ntohl(sw_if_index);
7861 static void vl_api_sw_interface_vhost_user_details_t_handler
7862 (vl_api_sw_interface_vhost_user_details_t * mp)
7864 vat_main_t * vam = &vat_main;
7866 fformat(vam->ofp, "%-25s %3" PRIu32 " %6" PRIu32 " %8x %6d %7d %s\n",
7867 (char *)mp->interface_name,
7868 ntohl(mp->sw_if_index), ntohl(mp->virtio_net_hdr_sz),
7869 clib_net_to_host_u64(mp->features), mp->is_server,
7870 ntohl(mp->num_regions), (char *)mp->sock_filename);
7871 fformat(vam->ofp, " Status: '%s'\n", strerror(ntohl(mp->sock_errno)));
7874 static void vl_api_sw_interface_vhost_user_details_t_handler_json
7875 (vl_api_sw_interface_vhost_user_details_t * mp)
7877 vat_main_t * vam = &vat_main;
7878 vat_json_node_t *node = NULL;
7880 if (VAT_JSON_ARRAY != vam->json_tree.type) {
7881 ASSERT(VAT_JSON_NONE == vam->json_tree.type);
7882 vat_json_init_array(&vam->json_tree);
7884 node = vat_json_array_add(&vam->json_tree);
7886 vat_json_init_object(node);
7887 vat_json_object_add_uint(node, "sw_if_index", ntohl(mp->sw_if_index));
7888 vat_json_object_add_string_copy(node, "interface_name", mp->interface_name);
7889 vat_json_object_add_uint(node, "virtio_net_hdr_sz", ntohl(mp->virtio_net_hdr_sz));
7890 vat_json_object_add_uint(node, "features", clib_net_to_host_u64(mp->features));
7891 vat_json_object_add_uint(node, "is_server", mp->is_server);
7892 vat_json_object_add_string_copy(node, "sock_filename", mp->sock_filename);
7893 vat_json_object_add_uint(node, "num_regions", ntohl(mp->num_regions));
7894 vat_json_object_add_uint(node, "sock_errno", ntohl(mp->sock_errno));
7897 static int api_sw_interface_vhost_user_dump (vat_main_t * vam)
7899 vl_api_sw_interface_vhost_user_dump_t *mp;
7901 fformat(vam->ofp, "Interface name idx hdr_sz features server regions filename\n");
7903 /* Get list of vhost-user interfaces */
7904 M(SW_INTERFACE_VHOST_USER_DUMP, sw_interface_vhost_user_dump);
7907 /* Use a control ping for synchronization */
7909 vl_api_control_ping_t * mp;
7910 M(CONTROL_PING, control_ping);
7916 static int api_show_version (vat_main_t * vam)
7918 vl_api_show_version_t *mp;
7921 M(SHOW_VERSION, show_version);
7928 static uword unformat_nsh_gre_decap_next
7929 (unformat_input_t * input, va_list * args)
7931 u32 * result = va_arg (*args, u32 *);
7934 if (unformat (input, "drop"))
7935 *result = NSH_GRE_INPUT_NEXT_DROP;
7936 else if (unformat (input, "ip4"))
7937 *result = NSH_GRE_INPUT_NEXT_IP4_INPUT;
7938 else if (unformat (input, "ip6"))
7939 *result = NSH_GRE_INPUT_NEXT_IP6_INPUT;
7940 else if (unformat (input, "ethernet"))
7941 *result = NSH_GRE_INPUT_NEXT_ETHERNET_INPUT;
7942 else if (unformat (input, "%d", &tmp))
7949 static int api_nsh_gre_add_del_tunnel (vat_main_t * vam)
7951 unformat_input_t * line_input = vam->input;
7952 vl_api_nsh_gre_add_del_tunnel_t *mp;
7954 ip4_address_t src, dst;
7958 u32 encap_vrf_id = 0;
7959 u32 decap_vrf_id = 0;
7962 u8 next_protocol = 1; /* ip4 */
7973 u32 decap_next_index = NSH_GRE_INPUT_NEXT_IP4_INPUT;
7977 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) {
7978 if (unformat (line_input, "del"))
7980 else if (unformat (line_input, "src %U",
7981 unformat_ip4_address, &src))
7983 else if (unformat (line_input, "dst %U",
7984 unformat_ip4_address, &dst))
7986 else if (unformat (line_input, "encap-vrf-id %d", &encap_vrf_id))
7988 else if (unformat (line_input, "decap-vrf-id %d", &decap_vrf_id))
7990 else if (unformat (line_input, "decap-next %U",
7991 unformat_nsh_gre_decap_next, &decap_next_index))
7993 else if (unformat (line_input, "version %d", &tmp))
7994 ver_o_c |= (tmp & 3) << 6;
7995 else if (unformat (line_input, "o-bit %d", &tmp))
7996 ver_o_c |= (tmp & 1) << 5;
7997 else if (unformat (line_input, "c-bit %d", &tmp))
7998 ver_o_c |= (tmp & 1) << 4;
7999 else if (unformat (line_input, "md-type %d", &tmp))
8001 else if (unformat(line_input, "next-ip4"))
8003 else if (unformat(line_input, "next-ip6"))
8005 else if (unformat(line_input, "next-ethernet"))
8007 else if (unformat (line_input, "c1 %d", &c1))
8009 else if (unformat (line_input, "c2 %d", &c2))
8011 else if (unformat (line_input, "c3 %d", &c3))
8013 else if (unformat (line_input, "c4 %d", &c4))
8015 else if (unformat (line_input, "spi %d", &spi))
8017 else if (unformat (line_input, "si %d", &si))
8019 else if (unformat (line_input, "tlv %x"))
8020 vec_add1 (tlvs, tmp);
8022 errmsg ("parse error '%U'\n", format_unformat_error, line_input);
8028 errmsg ("tunnel src address not specified\n");
8032 errmsg ("tunnel dst address not specified\n");
8037 errmsg ("spi not specified\n");
8042 errmsg ("si not specified\n");
8046 M2 (NSH_GRE_ADD_DEL_TUNNEL, nsh_gre_add_del_tunnel,
8047 sizeof(u32) * vec_len (tlvs));
8049 spi_si = (spi<<8) | si;
8051 mp->src = src.as_u32;
8052 mp->dst = dst.as_u32;
8053 mp->encap_vrf_id = ntohl(encap_vrf_id);
8054 mp->decap_vrf_id = ntohl(decap_vrf_id);
8055 mp->decap_next_index = ntohl(decap_next_index);
8056 mp->tlv_len_in_words = vec_len (tlvs);
8057 mp->is_add = is_add;
8058 mp->ver_o_c = ver_o_c;
8059 mp->length = 6 + vec_len(tlvs);
8060 mp->md_type = md_type;
8061 mp->next_protocol = next_protocol;
8062 mp->spi_si = ntohl(spi_si);
8068 for (i = 0; i < vec_len(tlvs); i++)
8069 mp->tlvs[i] = ntohl(tlvs[i]);
8078 static uword unformat_nsh_vxlan_gpe_decap_next
8079 (unformat_input_t * input, va_list * args)
8081 u32 * result = va_arg (*args, u32 *);
8084 if (unformat (input, "drop"))
8085 *result = NSH_VXLAN_GPE_INPUT_NEXT_DROP;
8086 else if (unformat (input, "ip4"))
8087 *result = NSH_VXLAN_GPE_INPUT_NEXT_IP4_INPUT;
8088 else if (unformat (input, "ip6"))
8089 *result = NSH_VXLAN_GPE_INPUT_NEXT_IP6_INPUT;
8090 else if (unformat (input, "ethernet"))
8091 *result = NSH_VXLAN_GPE_INPUT_NEXT_ETHERNET_INPUT;
8092 else if (unformat (input, "nsh-vxlan-gpe"))
8093 *result = NSH_VXLAN_GPE_INPUT_NEXT_ETHERNET_INPUT;
8094 else if (unformat (input, "%d", &tmp))
8101 static int api_nsh_vxlan_gpe_add_del_tunnel (vat_main_t * vam)
8103 unformat_input_t * line_input = vam->input;
8104 vl_api_nsh_vxlan_gpe_add_del_tunnel_t *mp;
8106 ip4_address_t src, dst;
8110 u32 encap_vrf_id = 0;
8111 u32 decap_vrf_id = 0;
8114 u8 next_protocol = 1; /* ip4 */
8125 u32 decap_next_index = NSH_GRE_INPUT_NEXT_IP4_INPUT;
8131 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) {
8132 if (unformat (line_input, "del"))
8134 else if (unformat (line_input, "src %U",
8135 unformat_ip4_address, &src))
8137 else if (unformat (line_input, "dst %U",
8138 unformat_ip4_address, &dst))
8140 else if (unformat (line_input, "encap-vrf-id %d", &encap_vrf_id))
8142 else if (unformat (line_input, "decap-vrf-id %d", &decap_vrf_id))
8144 else if (unformat (line_input, "decap-next %U",
8145 unformat_nsh_vxlan_gpe_decap_next,
8148 else if (unformat (line_input, "vni %d", &vni))
8150 else if (unformat (line_input, "version %d", &tmp))
8151 ver_o_c |= (tmp & 3) << 6;
8152 else if (unformat (line_input, "o-bit %d", &tmp))
8153 ver_o_c |= (tmp & 1) << 5;
8154 else if (unformat (line_input, "c-bit %d", &tmp))
8155 ver_o_c |= (tmp & 1) << 4;
8156 else if (unformat (line_input, "md-type %d", &tmp))
8158 else if (unformat(line_input, "next-ip4"))
8160 else if (unformat(line_input, "next-ip6"))
8162 else if (unformat(line_input, "next-ethernet"))
8164 else if (unformat (line_input, "c1 %d", &c1))
8166 else if (unformat (line_input, "c2 %d", &c2))
8168 else if (unformat (line_input, "c3 %d", &c3))
8170 else if (unformat (line_input, "c4 %d", &c4))
8172 else if (unformat (line_input, "spi %d", &spi))
8174 else if (unformat (line_input, "si %d", &si))
8176 else if (unformat (line_input, "tlv %x"))
8177 vec_add1 (tlvs, tmp);
8179 errmsg ("parse error '%U'\n", format_unformat_error, line_input);
8185 errmsg ("tunnel src address not specified\n");
8189 errmsg ("tunnel dst address not specified\n");
8194 errmsg ("spi not specified\n");
8199 errmsg ("si not specified\n");
8203 errmsg ("vni not specified\n");
8207 M2 (NSH_VXLAN_GPE_ADD_DEL_TUNNEL, nsh_vxlan_gpe_add_del_tunnel,
8208 sizeof(u32) * vec_len (tlvs));
8210 spi_si = (spi<<8) | si;
8212 mp->src = src.as_u32;
8213 mp->dst = dst.as_u32;
8214 mp->encap_vrf_id = ntohl(encap_vrf_id);
8215 mp->decap_vrf_id = ntohl(decap_vrf_id);
8216 mp->decap_next_index = ntohl(decap_next_index);
8217 mp->tlv_len_in_words = vec_len (tlvs);
8218 mp->vni = ntohl(vni);
8219 mp->is_add = is_add;
8220 mp->ver_o_c = ver_o_c;
8221 mp->length = 6 + vec_len(tlvs);
8222 mp->md_type = md_type;
8223 mp->next_protocol = next_protocol;
8224 mp->spi_si = ntohl(spi_si);
8230 for (i = 0; i < vec_len(tlvs); i++)
8231 mp->tlvs[i] = ntohl(tlvs[i]);
8240 static uword unformat_lisp_gpe_decap_next (unformat_input_t * input,
8243 u32 * result = va_arg (*args, u32 *);
8246 if (unformat (input, "drop"))
8247 *result = LISP_GPE_INPUT_NEXT_DROP;
8248 else if (unformat (input, "ip4"))
8249 *result = LISP_GPE_INPUT_NEXT_IP4_INPUT;
8250 else if (unformat (input, "ip6"))
8251 *result = LISP_GPE_INPUT_NEXT_IP6_INPUT;
8252 else if (unformat (input, "ethernet"))
8253 *result = LISP_GPE_INPUT_NEXT_IP6_INPUT;
8254 else if (unformat (input, "%d", &tmp))
8262 api_lisp_gpe_add_del_tunnel (vat_main_t * vam)
8264 unformat_input_t * line_input = vam->input;
8265 vl_api_lisp_gpe_add_del_tunnel_t *mp;
8267 ip4_address_t src, dst;
8271 u32 encap_vrf_id = 0;
8272 u32 decap_vrf_id = 0;
8273 u8 next_protocol = LISP_GPE_NEXT_PROTOCOL_IP4;
8274 u32 decap_next_index = LISP_GPE_INPUT_NEXT_IP4_INPUT;
8275 u8 flags = LISP_GPE_FLAGS_P;
8282 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) {
8283 if (unformat (line_input, "del"))
8285 else if (unformat (line_input, "src %U",
8286 unformat_ip4_address, &src))
8288 else if (unformat (line_input, "dst %U",
8289 unformat_ip4_address, &dst))
8291 else if (unformat (line_input, "encap-vrf-id %d", &encap_vrf_id))
8293 else if (unformat (line_input, "decap-vrf-id %d", &decap_vrf_id))
8295 else if (unformat (line_input, "decap-next %U",
8296 unformat_lisp_gpe_decap_next,
8299 else if (unformat(line_input, "next-ip4"))
8301 else if (unformat(line_input, "next-ip6"))
8303 else if (unformat(line_input, "next-ethernet"))
8305 else if (unformat(line_input, "next-nsh"))
8307 /* Allow the user to specify anything they want in the LISP hdr */
8308 else if (unformat (line_input, "ver_res %x", &tmp))
8310 else if (unformat (line_input, "res %x", &tmp))
8312 else if (unformat (line_input, "flags %x", &tmp))
8314 else if (unformat (line_input, "n-bit"))
8315 flags |= LISP_GPE_FLAGS_N;
8316 else if (unformat (line_input, "l-bit"))
8317 flags |= LISP_GPE_FLAGS_L;
8318 else if (unformat (line_input, "e-bit"))
8319 flags |= LISP_GPE_FLAGS_E;
8320 else if (unformat (line_input, "v-bit"))
8321 flags |= LISP_GPE_FLAGS_V;
8322 else if (unformat (line_input, "i-bit"))
8323 flags |= LISP_GPE_FLAGS_V;
8324 else if (unformat (line_input, "not-p-bit"))
8325 flags &= !LISP_GPE_FLAGS_P;
8326 else if (unformat (line_input, "p-bit"))
8327 flags |= LISP_GPE_FLAGS_P;
8328 else if (unformat (line_input, "o-bit"))
8329 flags |= LISP_GPE_FLAGS_O;
8330 else if (unformat (line_input, "iidx %x", &iid))
8332 else if (unformat (line_input, "iid %d", &iid))
8335 errmsg ("parse error '%U'\n", format_unformat_error, line_input);
8341 errmsg ("tunnel src address not specified\n");
8345 errmsg ("tunnel dst address not specified\n");
8349 errmsg ("iid not specified\n");
8353 M(LISP_GPE_ADD_DEL_TUNNEL, lisp_gpe_add_del_tunnel);
8355 mp->src = src.as_u32;
8356 mp->dst = dst.as_u32;
8357 mp->encap_vrf_id = ntohl(encap_vrf_id);
8358 mp->decap_vrf_id = ntohl(decap_vrf_id);
8359 mp->decap_next_index = ntohl(decap_next_index);
8360 mp->is_add = is_add;
8362 mp->ver_res = ver_res;
8364 mp->next_protocol = next_protocol;
8365 mp->iid = ntohl(iid);
8374 u8 * format_l2_fib_mac_address (u8 * s, va_list * args)
8376 u8 * a = va_arg (*args, u8 *);
8378 return format (s, "%02x:%02x:%02x:%02x:%02x:%02x",
8379 a[2], a[3], a[4], a[5], a[6], a[7]);
8382 static void vl_api_l2_fib_table_entry_t_handler
8383 (vl_api_l2_fib_table_entry_t * mp)
8385 vat_main_t * vam = &vat_main;
8387 fformat(vam->ofp, "%3" PRIu32 " %U %3" PRIu32
8389 ntohl(mp->bd_id), format_l2_fib_mac_address, &mp->mac,
8390 ntohl(mp->sw_if_index), mp->static_mac, mp->filter_mac,
8394 static void vl_api_l2_fib_table_entry_t_handler_json
8395 (vl_api_l2_fib_table_entry_t * mp)
8397 vat_main_t * vam = &vat_main;
8398 vat_json_node_t *node = NULL;
8400 if (VAT_JSON_ARRAY != vam->json_tree.type) {
8401 ASSERT(VAT_JSON_NONE == vam->json_tree.type);
8402 vat_json_init_array(&vam->json_tree);
8404 node = vat_json_array_add(&vam->json_tree);
8406 vat_json_init_object(node);
8407 vat_json_object_add_uint(node, "bd_id", ntohl(mp->bd_id));
8408 vat_json_object_add_uint(node, "mac", clib_net_to_host_u64(mp->mac));
8409 vat_json_object_add_uint(node, "sw_if_index", ntohl(mp->sw_if_index));
8410 vat_json_object_add_uint(node, "static_mac", mp->static_mac);
8411 vat_json_object_add_uint(node, "filter_mac", mp->filter_mac);
8412 vat_json_object_add_uint(node, "bvi_mac", mp->bvi_mac);
8415 static int api_l2_fib_table_dump (vat_main_t * vam)
8417 unformat_input_t * i = vam->input;
8418 vl_api_l2_fib_table_dump_t *mp;
8423 /* Parse args required to build the message */
8424 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
8425 if (unformat (i, "bd_id %d", &bd_id))
8431 if (bd_id_set == 0) {
8432 errmsg ("missing bridge domain\n");
8436 fformat(vam->ofp, "BD-ID Mac Address sw-ndx Static Filter BVI\n");
8438 /* Get list of l2 fib entries */
8439 M(L2_FIB_TABLE_DUMP, l2_fib_table_dump);
8441 mp->bd_id = ntohl(bd_id);
8444 /* Use a control ping for synchronization */
8446 vl_api_control_ping_t * mp;
8447 M(CONTROL_PING, control_ping);
8455 api_interface_name_renumber (vat_main_t * vam)
8457 unformat_input_t * line_input = vam->input;
8458 vl_api_interface_name_renumber_t *mp;
8459 u32 sw_if_index = ~0;
8461 u32 new_show_dev_instance = ~0;
8463 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) {
8464 if (unformat (line_input, "%U", unformat_sw_if_index, vam,
8467 else if (unformat (line_input, "sw_if_index %d", &sw_if_index))
8469 else if (unformat (line_input, "new_show_dev_instance %d",
8470 &new_show_dev_instance))
8476 if (sw_if_index == ~0) {
8477 errmsg ("missing interface name or sw_if_index\n");
8481 if (new_show_dev_instance == ~0) {
8482 errmsg ("missing new_show_dev_instance\n");
8486 M(INTERFACE_NAME_RENUMBER, interface_name_renumber);
8488 mp->sw_if_index = ntohl (sw_if_index);
8489 mp->new_show_dev_instance = ntohl (new_show_dev_instance);
8495 api_want_ip4_arp_events (vat_main_t * vam)
8497 unformat_input_t * line_input = vam->input;
8498 vl_api_want_ip4_arp_events_t * mp;
8500 ip4_address_t address;
8501 int address_set = 0;
8502 u32 enable_disable = 1;
8504 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) {
8505 if (unformat (line_input, "address %U",
8506 unformat_ip4_address, &address))
8508 else if (unformat (line_input, "del"))
8514 if (address_set == 0) {
8515 errmsg ("missing addresses\n");
8519 M(WANT_IP4_ARP_EVENTS, want_ip4_arp_events);
8520 mp->enable_disable = enable_disable;
8522 mp->address = address.as_u32;
8527 static int api_input_acl_set_interface (vat_main_t * vam)
8529 unformat_input_t * i = vam->input;
8530 vl_api_input_acl_set_interface_t *mp;
8533 int sw_if_index_set;
8534 u32 ip4_table_index = ~0;
8535 u32 ip6_table_index = ~0;
8536 u32 l2_table_index = ~0;
8539 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
8540 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
8541 sw_if_index_set = 1;
8542 else if (unformat (i, "sw_if_index %d", &sw_if_index))
8543 sw_if_index_set = 1;
8544 else if (unformat (i, "del"))
8546 else if (unformat (i, "ip4-table %d", &ip4_table_index))
8548 else if (unformat (i, "ip6-table %d", &ip6_table_index))
8550 else if (unformat (i, "l2-table %d", &l2_table_index))
8553 clib_warning ("parse error '%U'", format_unformat_error, i);
8558 if (sw_if_index_set == 0) {
8559 errmsg ("missing interface name or sw_if_index\n");
8563 M(INPUT_ACL_SET_INTERFACE, input_acl_set_interface);
8565 mp->sw_if_index = ntohl(sw_if_index);
8566 mp->ip4_table_index = ntohl(ip4_table_index);
8567 mp->ip6_table_index = ntohl(ip6_table_index);
8568 mp->l2_table_index = ntohl(l2_table_index);
8569 mp->is_add = is_add;
8577 api_ip_address_dump (vat_main_t * vam)
8579 unformat_input_t * i = vam->input;
8580 vl_api_ip_address_dump_t * mp;
8581 u32 sw_if_index = ~0;
8582 u8 sw_if_index_set = 0;
8587 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
8588 if (unformat (i, "sw_if_index %d", &sw_if_index))
8589 sw_if_index_set = 1;
8590 else if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
8591 sw_if_index_set = 1;
8592 else if (unformat (i, "ipv4"))
8594 else if (unformat (i, "ipv6"))
8600 if (ipv4_set && ipv6_set) {
8601 errmsg ("ipv4 and ipv6 flags cannot be both set\n");
8605 if ((!ipv4_set) && (!ipv6_set)) {
8606 errmsg ("no ipv4 nor ipv6 flag set\n");
8610 if (sw_if_index_set == 0) {
8611 errmsg ("missing interface name or sw_if_index\n");
8615 vam->current_sw_if_index = sw_if_index;
8616 vam->is_ipv6 = ipv6_set;
8618 M(IP_ADDRESS_DUMP, ip_address_dump);
8619 mp->sw_if_index = ntohl(sw_if_index);
8620 mp->is_ipv6 = ipv6_set;
8623 /* Use a control ping for synchronization */
8625 vl_api_control_ping_t * mp;
8626 M(CONTROL_PING, control_ping);
8633 api_ip_dump (vat_main_t * vam)
8635 vl_api_ip_dump_t * mp;
8636 unformat_input_t * in = vam->input;
8643 while (unformat_check_input (in) != UNFORMAT_END_OF_INPUT) {
8644 if (unformat (in, "ipv4"))
8646 else if (unformat (in, "ipv6"))
8652 if (ipv4_set && ipv6_set) {
8653 errmsg ("ipv4 and ipv6 flags cannot be both set\n");
8657 if ((!ipv4_set) && (!ipv6_set)) {
8658 errmsg ("no ipv4 nor ipv6 flag set\n");
8663 vam->is_ipv6 = is_ipv6;
8666 for (i = 0; i < vec_len(vam->ip_details_by_sw_if_index[is_ipv6]); i++) {
8667 vec_free(vam->ip_details_by_sw_if_index[is_ipv6][i].addr);
8669 vec_free(vam->ip_details_by_sw_if_index[is_ipv6]);
8671 M(IP_DUMP, ip_dump);
8672 mp->is_ipv6 = ipv6_set;
8675 /* Use a control ping for synchronization */
8677 vl_api_control_ping_t * mp;
8678 M(CONTROL_PING, control_ping);
8685 api_ipsec_spd_add_del (vat_main_t * vam)
8688 unformat_input_t * i = vam->input;
8689 vl_api_ipsec_spd_add_del_t *mp;
8694 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
8695 if (unformat (i, "spd_id %d", &spd_id))
8697 else if (unformat (i, "del"))
8700 clib_warning ("parse error '%U'", format_unformat_error, i);
8705 errmsg ("spd_id must be set\n");
8709 M(IPSEC_SPD_ADD_DEL, ipsec_spd_add_del);
8711 mp->spd_id = ntohl(spd_id);
8712 mp->is_add = is_add;
8718 clib_warning ("unsupported (no dpdk)");
8724 api_ipsec_interface_add_del_spd (vat_main_t * vam)
8727 unformat_input_t * i = vam->input;
8728 vl_api_ipsec_interface_add_del_spd_t *mp;
8731 u8 sw_if_index_set = 0;
8732 u32 spd_id = (u32) ~0;
8735 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
8736 if (unformat (i, "del"))
8738 else if (unformat (i, "spd_id %d", &spd_id))
8740 else if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
8741 sw_if_index_set = 1;
8742 else if (unformat (i, "sw_if_index %d", &sw_if_index))
8743 sw_if_index_set = 1;
8745 clib_warning ("parse error '%U'", format_unformat_error, i);
8751 if (spd_id == (u32) ~0) {
8752 errmsg ("spd_id must be set\n");
8756 if (sw_if_index_set == 0) {
8757 errmsg ("missing interface name or sw_if_index\n");
8761 M(IPSEC_INTERFACE_ADD_DEL_SPD, ipsec_interface_add_del_spd);
8763 mp->spd_id = ntohl(spd_id);
8764 mp->sw_if_index = ntohl (sw_if_index);
8765 mp->is_add = is_add;
8771 clib_warning ("unsupported (no dpdk)");
8777 api_ipsec_spd_add_del_entry (vat_main_t * vam)
8780 unformat_input_t * i = vam->input;
8781 vl_api_ipsec_spd_add_del_entry_t *mp;
8783 u8 is_add = 1, is_outbound = 0, is_ipv6 = 0, is_ip_any = 1;
8784 u32 spd_id, sa_id, protocol = 0, policy = 0;
8786 u32 rport_start = 0, rport_stop = (u32) ~0;
8787 u32 lport_start = 0, lport_stop = (u32) ~0;
8788 ip4_address_t laddr4_start, laddr4_stop, raddr4_start, raddr4_stop;
8789 ip6_address_t laddr6_start, laddr6_stop, raddr6_start, raddr6_stop;
8791 laddr4_start.as_u32 = raddr4_start.as_u32 = 0;
8792 laddr4_stop.as_u32 = raddr4_stop.as_u32 = (u32) ~0;
8793 laddr6_start.as_u64[0] = raddr6_start.as_u64[0] = 0;
8794 laddr6_start.as_u64[1] = raddr6_start.as_u64[1] = 0;
8795 laddr6_stop.as_u64[0] = raddr6_stop.as_u64[0] = (u64) ~0;
8796 laddr6_stop.as_u64[1] = raddr6_stop.as_u64[1] = (u64) ~0;
8798 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
8799 if (unformat (i, "del"))
8801 if (unformat (i, "outbound"))
8803 if (unformat (i, "inbound"))
8805 else if (unformat (i, "spd_id %d", &spd_id))
8807 else if (unformat (i, "sa_id %d", &sa_id))
8809 else if (unformat (i, "priority %d", &priority))
8811 else if (unformat (i, "protocol %d", &protocol))
8813 else if (unformat (i, "lport_start %d", &lport_start))
8815 else if (unformat (i, "lport_stop %d", &lport_stop))
8817 else if (unformat (i, "rport_start %d", &rport_start))
8819 else if (unformat (i, "rport_stop %d", &rport_stop))
8821 else if (unformat (i, "laddr_start %U", unformat_ip4_address, &laddr4_start))
8826 else if (unformat (i, "laddr_stop %U", unformat_ip4_address, &laddr4_stop))
8831 else if (unformat (i, "raddr_start %U", unformat_ip4_address, &raddr4_start))
8836 else if (unformat (i, "raddr_stop %U", unformat_ip4_address, &raddr4_stop))
8841 else if (unformat (i, "laddr_start %U", unformat_ip6_address, &laddr6_start))
8846 else if (unformat (i, "laddr_stop %U", unformat_ip6_address, &laddr6_stop))
8851 else if (unformat (i, "raddr_start %U", unformat_ip6_address, &raddr6_start))
8856 else if (unformat (i, "raddr_stop %U", unformat_ip6_address, &raddr6_stop))
8861 else if (unformat (i, "action %U", unformat_ipsec_policy_action, &policy))
8863 if (policy == IPSEC_POLICY_ACTION_RESOLVE) {
8864 clib_warning ("unsupported action: 'resolve'");
8869 clib_warning ("parse error '%U'", format_unformat_error, i);
8875 M(IPSEC_SPD_ADD_DEL_ENTRY, ipsec_spd_add_del_entry);
8877 mp->spd_id = ntohl(spd_id);
8878 mp->priority = ntohl(priority);
8879 mp->is_outbound = is_outbound;
8881 mp->is_ipv6 = is_ipv6;
8882 if (is_ipv6 || is_ip_any) {
8883 clib_memcpy (mp->remote_address_start, &raddr6_start, sizeof(ip6_address_t));
8884 clib_memcpy (mp->remote_address_stop, &raddr6_stop, sizeof(ip6_address_t));
8885 clib_memcpy (mp->local_address_start, &laddr6_start, sizeof(ip6_address_t));
8886 clib_memcpy (mp->local_address_stop, &laddr6_stop, sizeof(ip6_address_t));
8888 clib_memcpy (mp->remote_address_start, &raddr4_start, sizeof(ip4_address_t));
8889 clib_memcpy (mp->remote_address_stop, &raddr4_stop, sizeof(ip4_address_t));
8890 clib_memcpy (mp->local_address_start, &laddr4_start, sizeof(ip4_address_t));
8891 clib_memcpy (mp->local_address_stop, &laddr4_stop, sizeof(ip4_address_t));
8893 mp->protocol = (u8) protocol;
8894 mp->local_port_start = ntohs((u16) lport_start);
8895 mp->local_port_stop = ntohs((u16) lport_stop);
8896 mp->remote_port_start = ntohs((u16) rport_start);
8897 mp->remote_port_stop = ntohs((u16) rport_stop);
8898 mp->policy = (u8) policy;
8899 mp->sa_id = ntohl(sa_id);
8900 mp->is_add = is_add;
8901 mp->is_ip_any = is_ip_any;
8906 clib_warning ("unsupported (no dpdk)");
8912 api_ipsec_sad_add_del_entry (vat_main_t * vam)
8915 unformat_input_t * i = vam->input;
8916 vl_api_ipsec_sad_add_del_entry_t *mp;
8922 u8 protocol = IPSEC_PROTOCOL_AH;
8923 u8 is_tunnel = 0, is_tunnel_ipv6 = 0;
8924 u32 crypto_alg = 0, integ_alg = 0;
8925 ip4_address_t tun_src4;
8926 ip4_address_t tun_dst4;
8927 ip6_address_t tun_src6;
8928 ip6_address_t tun_dst6;
8930 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
8931 if (unformat (i, "del"))
8933 else if (unformat (i, "sad_id %d", &sad_id))
8935 else if (unformat (i, "spi %d", &spi))
8937 else if (unformat (i, "esp"))
8938 protocol = IPSEC_PROTOCOL_ESP;
8939 else if (unformat (i, "tunnel_src %U", unformat_ip4_address, &tun_src4)) {
8943 else if (unformat (i, "tunnel_dst %U", unformat_ip4_address, &tun_dst4)) {
8947 else if (unformat (i, "tunnel_src %U", unformat_ip6_address, &tun_src6)) {
8951 else if (unformat (i, "tunnel_dst %U", unformat_ip6_address, &tun_dst6)) {
8955 else if (unformat (i, "crypto_alg %U", unformat_ipsec_crypto_alg, &crypto_alg)) {
8956 if (crypto_alg < IPSEC_CRYPTO_ALG_AES_CBC_128 ||
8957 crypto_alg > IPSEC_INTEG_ALG_SHA_512_256) {
8958 clib_warning ("unsupported crypto-alg: '%U'",
8959 format_ipsec_crypto_alg, crypto_alg);
8963 else if (unformat (i, "crypto_key %U", unformat_hex_string, &ck))
8965 else if (unformat (i, "integ_alg %U", unformat_ipsec_integ_alg, &integ_alg)) {
8966 if (integ_alg < IPSEC_INTEG_ALG_SHA1_96 ||
8967 integ_alg > IPSEC_INTEG_ALG_SHA_512_256) {
8968 clib_warning ("unsupported integ-alg: '%U'",
8969 format_ipsec_integ_alg, integ_alg);
8973 else if (unformat (i, "integ_key %U", unformat_hex_string, &ik))
8976 clib_warning ("parse error '%U'", format_unformat_error, i);
8982 M(IPSEC_SAD_ADD_DEL_ENTRY, ipsec_sad_add_del_entry);
8984 mp->sad_id = ntohl(sad_id);
8985 mp->is_add = is_add;
8986 mp->protocol = protocol;
8987 mp->spi = ntohl(spi);
8988 mp->is_tunnel = is_tunnel;
8989 mp->is_tunnel_ipv6 = is_tunnel_ipv6;
8990 mp->crypto_algorithm = crypto_alg;
8991 mp->integrity_algorithm = integ_alg;
8992 mp->crypto_key_length = vec_len(ck);
8993 mp->integrity_key_length = vec_len(ik);
8995 if (mp->crypto_key_length > sizeof(mp->crypto_key))
8996 mp->crypto_key_length = sizeof(mp->crypto_key);
8998 if (mp->integrity_key_length > sizeof(mp->integrity_key))
8999 mp->integrity_key_length = sizeof(mp->integrity_key);
9001 clib_memcpy (mp->crypto_key, ck, mp->crypto_key_length);
9002 clib_memcpy (mp->integrity_key, ik, mp->integrity_key_length);
9005 if (is_tunnel_ipv6) {
9006 clib_memcpy (mp->tunnel_src_address, &tun_src6, sizeof(ip6_address_t));
9007 clib_memcpy (mp->tunnel_dst_address, &tun_dst6, sizeof(ip6_address_t));
9009 clib_memcpy (mp->tunnel_src_address, &tun_src4, sizeof(ip4_address_t));
9010 clib_memcpy (mp->tunnel_dst_address, &tun_dst4, sizeof(ip4_address_t));
9018 clib_warning ("unsupported (no dpdk)");
9024 api_ipsec_sa_set_key (vat_main_t * vam)
9027 unformat_input_t * i = vam->input;
9028 vl_api_ipsec_sa_set_key_t *mp;
9033 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
9034 if (unformat (i, "sa_id %d", &sa_id))
9036 else if (unformat (i, "crypto_key %U", unformat_hex_string, &ck))
9038 else if (unformat (i, "integ_key %U", unformat_hex_string, &ik))
9041 clib_warning ("parse error '%U'", format_unformat_error, i);
9046 M(IPSEC_SA_SET_KEY, ipsec_set_sa_key);
9048 mp->sa_id = ntohl(sa_id);
9049 mp->crypto_key_length = vec_len(ck);
9050 mp->integrity_key_length = vec_len(ik);
9052 if (mp->crypto_key_length > sizeof(mp->crypto_key))
9053 mp->crypto_key_length = sizeof(mp->crypto_key);
9055 if (mp->integrity_key_length > sizeof(mp->integrity_key))
9056 mp->integrity_key_length = sizeof(mp->integrity_key);
9058 clib_memcpy (mp->crypto_key, ck, mp->crypto_key_length);
9059 clib_memcpy (mp->integrity_key, ik, mp->integrity_key_length);
9065 clib_warning ("unsupported (no dpdk)");
9071 api_ikev2_profile_add_del (vat_main_t * vam)
9074 unformat_input_t * i = vam->input;
9075 vl_api_ikev2_profile_add_del_t * mp;
9080 const char * valid_chars = "a-zA-Z0-9_";
9082 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
9083 if (unformat (i, "del"))
9085 else if (unformat (i, "name %U", unformat_token, valid_chars, &name))
9088 errmsg ("parse error '%U'", format_unformat_error, i);
9093 if (!vec_len (name)) {
9094 errmsg ("profile name must be specified");
9098 if (vec_len (name) > 64) {
9099 errmsg ("profile name too long");
9103 M(IKEV2_PROFILE_ADD_DEL, ikev2_profile_add_del);
9105 clib_memcpy(mp->name, name, vec_len (name));
9106 mp->is_add = is_add;
9113 clib_warning ("unsupported (no dpdk)");
9119 api_ikev2_profile_set_auth (vat_main_t * vam)
9122 unformat_input_t * i = vam->input;
9123 vl_api_ikev2_profile_set_auth_t * mp;
9127 u32 auth_method = 0;
9130 const char * valid_chars = "a-zA-Z0-9_";
9132 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
9133 if (unformat (i, "name %U", unformat_token, valid_chars, &name))
9135 else if (unformat (i, "auth_method %U",
9136 unformat_ikev2_auth_method, &auth_method))
9138 else if (unformat (i, "auth_data 0x%U", unformat_hex_string, &data))
9140 else if (unformat (i, "auth_data %v", &data))
9143 errmsg ("parse error '%U'", format_unformat_error, i);
9148 if (!vec_len (name)) {
9149 errmsg ("profile name must be specified");
9153 if (vec_len (name) > 64) {
9154 errmsg ("profile name too long");
9158 if (!vec_len(data)) {
9159 errmsg ("auth_data must be specified");
9164 errmsg ("auth_method must be specified");
9168 M(IKEV2_PROFILE_SET_AUTH, ikev2_profile_set_auth);
9170 mp->is_hex = is_hex;
9171 mp->auth_method = (u8) auth_method;
9172 mp->data_len = vec_len (data);
9173 clib_memcpy (mp->name, name, vec_len (name));
9174 clib_memcpy (mp->data, data, vec_len (data));
9182 clib_warning ("unsupported (no dpdk)");
9188 api_ikev2_profile_set_id (vat_main_t * vam)
9191 unformat_input_t * i = vam->input;
9192 vl_api_ikev2_profile_set_id_t * mp;
9200 const char * valid_chars = "a-zA-Z0-9_";
9202 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
9203 if (unformat (i, "name %U", unformat_token, valid_chars, &name))
9205 else if (unformat (i, "id_type %U",
9206 unformat_ikev2_id_type, &id_type))
9208 else if (unformat (i, "id_data %U", unformat_ip4_address, &ip4))
9210 data = vec_new(u8, 4);
9211 clib_memcpy(data, ip4.as_u8, 4);
9213 else if (unformat (i, "id_data 0x%U", unformat_hex_string, &data))
9215 else if (unformat (i, "id_data %v", &data))
9217 else if (unformat (i, "local"))
9219 else if (unformat (i, "remote"))
9222 errmsg ("parse error '%U'", format_unformat_error, i);
9227 if (!vec_len (name)) {
9228 errmsg ("profile name must be specified");
9232 if (vec_len (name) > 64) {
9233 errmsg ("profile name too long");
9237 if (!vec_len(data)) {
9238 errmsg ("id_data must be specified");
9243 errmsg ("id_type must be specified");
9247 M(IKEV2_PROFILE_SET_ID, ikev2_profile_set_id);
9249 mp->is_local = is_local;
9250 mp->id_type = (u8) id_type;
9251 mp->data_len = vec_len (data);
9252 clib_memcpy (mp->name, name, vec_len (name));
9253 clib_memcpy (mp->data, data, vec_len (data));
9261 clib_warning ("unsupported (no dpdk)");
9267 api_ikev2_profile_set_ts (vat_main_t * vam)
9270 unformat_input_t * i = vam->input;
9271 vl_api_ikev2_profile_set_ts_t * mp;
9275 u32 proto = 0, start_port = 0, end_port = (u32) ~0;
9276 ip4_address_t start_addr, end_addr;
9278 const char * valid_chars = "a-zA-Z0-9_";
9280 start_addr.as_u32 = 0;
9281 end_addr.as_u32 = (u32) ~0;
9283 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
9284 if (unformat (i, "name %U", unformat_token, valid_chars, &name))
9286 else if (unformat (i, "protocol %d", &proto))
9288 else if (unformat (i, "start_port %d", &start_port))
9290 else if (unformat (i, "end_port %d", &end_port))
9292 else if (unformat (i, "start_addr %U", unformat_ip4_address, &start_addr))
9294 else if (unformat (i, "end_addr %U", unformat_ip4_address, &end_addr))
9296 else if (unformat (i, "local"))
9298 else if (unformat (i, "remote"))
9301 errmsg ("parse error '%U'", format_unformat_error, i);
9306 if (!vec_len (name)) {
9307 errmsg ("profile name must be specified");
9311 if (vec_len (name) > 64) {
9312 errmsg ("profile name too long");
9316 M(IKEV2_PROFILE_SET_TS, ikev2_profile_set_ts);
9318 mp->is_local = is_local;
9319 mp->proto = (u8) proto;
9320 mp->start_port = (u16) start_port;
9321 mp->end_port = (u16) end_port;
9322 mp->start_addr = start_addr.as_u32;
9323 mp->end_addr = end_addr.as_u32;
9324 clib_memcpy (mp->name, name, vec_len (name));
9331 clib_warning ("unsupported (no dpdk)");
9337 api_ikev2_set_local_key (vat_main_t * vam)
9340 unformat_input_t * i = vam->input;
9341 vl_api_ikev2_set_local_key_t * mp;
9345 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
9346 if (unformat (i, "file %v", &file))
9349 errmsg ("parse error '%U'", format_unformat_error, i);
9354 if (!vec_len (file)) {
9355 errmsg ("RSA key file must be specified");
9359 if (vec_len (file) > 256) {
9360 errmsg ("file name too long");
9364 M(IKEV2_SET_LOCAL_KEY, ikev2_set_local_key);
9366 clib_memcpy (mp->key_file, file, vec_len (file));
9373 clib_warning ("unsupported (no dpdk)");
9381 static int api_map_add_domain (vat_main_t * vam)
9383 unformat_input_t *i = vam->input;
9384 vl_api_map_add_domain_t *mp;
9387 ip4_address_t ip4_prefix;
9388 ip6_address_t ip6_prefix;
9389 ip6_address_t ip6_src;
9391 u32 ip6_prefix_len, ip4_prefix_len, ea_bits_len, psid_offset,
9393 u8 is_translation = 0;
9395 u8 ip6_src_len = 128;
9397 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
9398 if (unformat (i, "ip4-pfx %U/%d", unformat_ip4_address,
9399 &ip4_prefix, &ip4_prefix_len))
9401 else if (unformat (i, "ip6-pfx %U/%d", unformat_ip6_address,
9402 &ip6_prefix, &ip6_prefix_len))
9404 else if (unformat (i, "ip6-src %U/%d", unformat_ip6_address, &ip6_src, &ip6_src_len))
9406 else if (unformat (i, "ip6-src %U", unformat_ip6_address, &ip6_src))
9408 else if (unformat (i, "ea-bits-len %d", &ea_bits_len))
9410 else if (unformat (i, "psid-offset %d", &psid_offset))
9412 else if (unformat (i, "psid-len %d", &psid_length))
9414 else if (unformat (i, "mtu %d", &mtu))
9416 else if (unformat (i, "map-t"))
9419 clib_warning ("parse error '%U'", format_unformat_error, i);
9424 if (num_m_args != 6) {
9425 errmsg("mandatory argument(s) missing\n");
9429 /* Construct the API message */
9430 M(MAP_ADD_DOMAIN, map_add_domain);
9432 clib_memcpy(mp->ip4_prefix, &ip4_prefix, sizeof(ip4_prefix));
9433 mp->ip4_prefix_len = ip4_prefix_len;
9435 clib_memcpy(mp->ip6_prefix, &ip6_prefix, sizeof(ip6_prefix));
9436 mp->ip6_prefix_len = ip6_prefix_len;
9438 clib_memcpy(mp->ip6_src, &ip6_src, sizeof(ip6_src));
9439 mp->ip6_src_prefix_len = ip6_src_len;
9441 mp->ea_bits_len = ea_bits_len;
9442 mp->psid_offset = psid_offset;
9443 mp->psid_length = psid_length;
9444 mp->is_translation = is_translation;
9445 mp->mtu = htons(mtu);
9450 /* Wait for a reply, return good/bad news */
9454 static int api_map_del_domain (vat_main_t * vam)
9456 unformat_input_t *i = vam->input;
9457 vl_api_map_del_domain_t *mp;
9463 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
9464 if (unformat (i, "index %d", &index))
9467 clib_warning ("parse error '%U'", format_unformat_error, i);
9472 if (num_m_args != 1) {
9473 errmsg("mandatory argument(s) missing\n");
9477 /* Construct the API message */
9478 M(MAP_DEL_DOMAIN, map_del_domain);
9480 mp->index = ntohl(index);
9485 /* Wait for a reply, return good/bad news */
9489 static int api_map_add_del_rule (vat_main_t * vam)
9491 unformat_input_t *i = vam->input;
9492 vl_api_map_add_del_rule_t *mp;
9495 ip6_address_t ip6_dst;
9496 u32 num_m_args = 0, index, psid;
9498 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
9499 if (unformat (i, "index %d", &index))
9501 else if (unformat (i, "psid %d", &psid))
9503 else if (unformat (i, "dst %U", unformat_ip6_address, &ip6_dst))
9505 else if (unformat (i, "del")) {
9508 clib_warning ("parse error '%U'", format_unformat_error, i);
9513 /* Construct the API message */
9514 M(MAP_ADD_DEL_RULE, map_add_del_rule);
9516 mp->index = ntohl(index);
9517 mp->is_add = is_add;
9518 clib_memcpy(mp->ip6_dst, &ip6_dst, sizeof(ip6_dst));
9519 mp->psid = ntohs(psid);
9524 /* Wait for a reply, return good/bad news */
9528 static int api_map_domain_dump (vat_main_t * vam)
9530 vl_api_map_domain_dump_t *mp;
9533 /* Construct the API message */
9534 M(MAP_DOMAIN_DUMP, map_domain_dump);
9539 /* Use a control ping for synchronization */
9541 vl_api_control_ping_t * mp;
9542 M(CONTROL_PING, control_ping);
9548 static int api_map_rule_dump (vat_main_t * vam)
9550 unformat_input_t *i = vam->input;
9551 vl_api_map_rule_dump_t *mp;
9553 u32 domain_index = ~0;
9555 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
9556 if (unformat (i, "index %u", &domain_index))
9562 if (domain_index == ~0) {
9563 clib_warning("parse error: domain index expected");
9567 /* Construct the API message */
9568 M(MAP_RULE_DUMP, map_rule_dump);
9570 mp->domain_index = htonl(domain_index);
9575 /* Use a control ping for synchronization */
9577 vl_api_control_ping_t * mp;
9578 M(CONTROL_PING, control_ping);
9584 static void vl_api_map_add_domain_reply_t_handler
9585 (vl_api_map_add_domain_reply_t * mp)
9587 vat_main_t * vam = &vat_main;
9588 i32 retval = ntohl(mp->retval);
9590 if (vam->async_mode) {
9591 vam->async_errors += (retval < 0);
9593 vam->retval = retval;
9594 vam->result_ready = 1;
9598 static void vl_api_map_add_domain_reply_t_handler_json
9599 (vl_api_map_add_domain_reply_t * mp)
9601 vat_main_t * vam = &vat_main;
9602 vat_json_node_t node;
9604 vat_json_init_object(&node);
9605 vat_json_object_add_int(&node, "retval", ntohl(mp->retval));
9606 vat_json_object_add_uint(&node, "index", ntohl(mp->index));
9608 vat_json_print(vam->ofp, &node);
9609 vat_json_free(&node);
9611 vam->retval = ntohl(mp->retval);
9612 vam->result_ready = 1;
9616 api_get_first_msg_id (vat_main_t * vam)
9618 vl_api_get_first_msg_id_t * mp;
9620 unformat_input_t * i = vam->input;
9624 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
9625 if (unformat (i, "client %s", &name))
9631 if (name_set == 0) {
9632 errmsg ("missing client name\n");
9637 if (vec_len (name) > 63) {
9638 errmsg ("client name too long\n");
9642 M(GET_FIRST_MSG_ID, get_first_msg_id);
9643 clib_memcpy (mp->name, name, vec_len(name));
9649 static int api_cop_interface_enable_disable (vat_main_t * vam)
9651 unformat_input_t * line_input = vam->input;
9652 vl_api_cop_interface_enable_disable_t * mp;
9654 u32 sw_if_index = ~0;
9655 u8 enable_disable = 1;
9657 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) {
9658 if (unformat (line_input, "disable"))
9660 if (unformat (line_input, "enable"))
9662 else if (unformat (line_input, "%U", unformat_sw_if_index,
9665 else if (unformat (line_input, "sw_if_index %d", &sw_if_index))
9671 if (sw_if_index == ~0) {
9672 errmsg ("missing interface name or sw_if_index\n");
9676 /* Construct the API message */
9677 M(COP_INTERFACE_ENABLE_DISABLE, cop_interface_enable_disable);
9678 mp->sw_if_index = ntohl(sw_if_index);
9679 mp->enable_disable = enable_disable;
9683 /* Wait for the reply */
9687 static int api_cop_whitelist_enable_disable (vat_main_t * vam)
9689 unformat_input_t * line_input = vam->input;
9690 vl_api_cop_whitelist_enable_disable_t * mp;
9692 u32 sw_if_index = ~0;
9693 u8 ip4=0, ip6=0, default_cop=0;
9696 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) {
9697 if (unformat (line_input, "ip4"))
9699 else if (unformat (line_input, "ip6"))
9701 else if (unformat (line_input, "default"))
9703 else if (unformat (line_input, "%U", unformat_sw_if_index,
9706 else if (unformat (line_input, "sw_if_index %d", &sw_if_index))
9708 else if (unformat (line_input, "fib-id %d", &fib_id))
9714 if (sw_if_index == ~0) {
9715 errmsg ("missing interface name or sw_if_index\n");
9719 /* Construct the API message */
9720 M(COP_WHITELIST_ENABLE_DISABLE, cop_whitelist_enable_disable);
9721 mp->sw_if_index = ntohl(sw_if_index);
9722 mp->fib_id = ntohl(fib_id);
9725 mp->default_cop = default_cop;
9729 /* Wait for the reply */
9733 static int api_get_node_graph (vat_main_t * vam)
9735 vl_api_get_node_graph_t * mp;
9738 M(GET_NODE_GRAPH, get_node_graph);
9742 /* Wait for the reply */
9747 api_lisp_add_del_locator_set(vat_main_t * vam)
9749 unformat_input_t * input = vam->input;
9750 vl_api_lisp_add_del_locator_set_t *mp;
9753 u8 *locator_set_name = NULL;
9754 u8 locator_set_name_set = 0;
9756 /* Parse args required to build the message */
9757 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) {
9758 if (unformat(input, "del")) {
9760 } else if (unformat(input, "locator-set %s", &locator_set_name)) {
9761 locator_set_name_set = 1;
9766 if (locator_set_name_set == 0) {
9767 errmsg ("missing locator-set name");
9771 if (vec_len(locator_set_name) > 64) {
9772 errmsg ("locator-set name too long\n");
9773 vec_free(locator_set_name);
9776 vec_add1(locator_set_name, 0);
9778 /* Construct the API message */
9779 M(LISP_ADD_DEL_LOCATOR_SET, lisp_add_del_locator_set);
9781 mp->is_add = is_add;
9782 clib_memcpy(mp->locator_set_name, locator_set_name,
9783 vec_len(locator_set_name));
9784 vec_free(locator_set_name);
9789 /* Wait for a reply... */
9797 api_lisp_add_del_locator(vat_main_t * vam)
9799 unformat_input_t * input = vam->input;
9800 vl_api_lisp_add_del_locator_t *mp;
9802 u32 tmp_if_index = ~0;
9803 u32 sw_if_index = ~0;
9804 u8 sw_if_index_set = 0;
9805 u8 sw_if_index_if_name_set = 0;
9807 u8 priority_set = 0;
9811 u8 *locator_set_name = NULL;
9812 u8 locator_set_name_set = 0;
9814 /* Parse args required to build the message */
9815 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) {
9816 if (unformat(input, "del")) {
9818 } else if (unformat(input, "locator-set %s", &locator_set_name)) {
9819 locator_set_name_set = 1;
9820 } else if (unformat(input, "iface %U", unformat_sw_if_index, vam,
9822 sw_if_index_if_name_set = 1;
9823 sw_if_index = tmp_if_index;
9824 } else if (unformat(input,"sw_if_index %d", &tmp_if_index)) {
9825 sw_if_index_set = 1;
9826 sw_if_index = tmp_if_index;
9827 } else if (unformat(input, "p %d", &priority)) {
9829 } else if (unformat(input, "w %d", &weight)) {
9835 if (locator_set_name_set == 0) {
9836 errmsg ("missing locator-set name");
9840 if (sw_if_index_set == 0 && sw_if_index_if_name_set == 0) {
9841 errmsg ("missing sw_if_index");
9842 vec_free(locator_set_name);
9846 if (sw_if_index_set != 0 && sw_if_index_if_name_set != 0) {
9847 errmsg ("cannot use both params interface name and sw_if_index");
9848 vec_free(locator_set_name);
9852 if (priority_set == 0) {
9853 errmsg ("missing locator-set priority\n");
9854 vec_free(locator_set_name);
9858 if (weight_set == 0) {
9859 errmsg ("missing locator-set weight\n");
9860 vec_free(locator_set_name);
9864 if (vec_len(locator_set_name) > 64) {
9865 errmsg ("locator-set name too long\n");
9866 vec_free(locator_set_name);
9869 vec_add1(locator_set_name, 0);
9871 /* Construct the API message */
9872 M(LISP_ADD_DEL_LOCATOR, lisp_add_del_locator);
9874 mp->is_add = is_add;
9875 mp->sw_if_index = ntohl(sw_if_index);
9876 mp->priority = priority;
9877 mp->weight = weight;
9878 clib_memcpy(mp->locator_set_name, locator_set_name,
9879 vec_len(locator_set_name));
9880 vec_free(locator_set_name);
9885 /* Wait for a reply... */
9893 api_lisp_add_del_local_eid(vat_main_t * vam)
9895 unformat_input_t * input = vam->input;
9896 vl_api_lisp_add_del_local_eid_t *mp;
9901 ip4_address_t eidv4;
9902 ip6_address_t eidv6;
9903 u8 tmp_eid_lenght = ~0;
9905 u8 *locator_set_name = NULL;
9906 u8 locator_set_name_set = 0;
9908 /* Parse args required to build the message */
9909 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) {
9910 if (unformat(input, "del")) {
9912 } else if (unformat(input, "eid %U/%d", unformat_ip4_address,
9913 &eidv4, &tmp_eid_lenght)) {
9914 eid_lenght = tmp_eid_lenght;
9916 } else if (unformat(input, "eid %U/%d", unformat_ip6_address,
9917 &eidv6, &tmp_eid_lenght)) {
9918 eid_lenght = tmp_eid_lenght;
9920 } else if (unformat(input, "locator-set %s", &locator_set_name)) {
9921 locator_set_name_set = 1;
9926 if (locator_set_name_set == 0) {
9927 errmsg ("missing locator-set name\n");
9931 if (vec_len(locator_set_name) > 64) {
9932 errmsg ("locator-set name too long\n");
9933 vec_free(locator_set_name);
9936 vec_add1(locator_set_name, 0);
9938 if (eidv4_set && eidv6_set) {
9939 errmsg ("both eid v4 and v6 addresses set\n");
9940 vec_free(locator_set_name);
9944 if (!eidv4_set && !eidv6_set) {
9945 errmsg ("eid addresses not set\n");
9946 vec_free(locator_set_name);
9950 /* Construct the API message */
9951 M(LISP_ADD_DEL_LOCAL_EID, lisp_add_del_local_eid);
9953 mp->is_add = is_add;
9956 clib_memcpy(mp->ip_address, &eidv6, sizeof(eidv6));
9959 clib_memcpy(mp->ip_address, &eidv4, sizeof(eidv4));
9961 mp->prefix_len = eid_lenght;
9962 clib_memcpy(mp->locator_set_name, locator_set_name,
9963 vec_len(locator_set_name));
9964 vec_free(locator_set_name);
9969 /* Wait for a reply... */
9977 api_lisp_gpe_add_del_fwd_entry(vat_main_t * vam)
9979 unformat_input_t * input = vam->input;
9980 vl_api_lisp_gpe_add_del_fwd_entry_t *mp;
9983 u8 eidv4_set = 0, slocv4_set = 0, dlocv4_set = 0;
9984 u8 eidv6_set = 0, slocv6_set = 0, dlocv6_set = 0;
9985 ip4_address_t eidv4, slocv4, dlocv4;
9986 ip6_address_t eidv6, slocv6, dlocv6;
9987 u8 tmp_eid_lenght = ~0;
9990 /* Parse args required to build the message */
9991 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) {
9992 if (unformat(input, "del")) {
9994 } else if (unformat(input, "eid %U/%d", unformat_ip4_address,
9995 &eidv4, &tmp_eid_lenght)) {
9996 eid_lenght = tmp_eid_lenght;
9998 } else if (unformat(input, "eid %U/%d", unformat_ip6_address,
9999 &eidv6, &tmp_eid_lenght)) {
10000 eid_lenght = tmp_eid_lenght;
10002 } else if (unformat(input, "sloc %U", unformat_ip4_address, &slocv4)) {
10004 } else if (unformat(input, "sloc %U", unformat_ip6_address, &slocv6)) {
10006 } else if (unformat(input, "dloc %U", unformat_ip4_address, &dlocv4)) {
10008 } else if (unformat(input, "dloc %U", unformat_ip6_address, &dlocv6)) {
10014 if (eidv4_set && eidv6_set) {
10015 errmsg ("both eid v4 and v6 addresses set\n");
10019 if (!eidv4_set && !eidv6_set) {
10020 errmsg ("eid addresses not set\n");
10024 if (slocv4_set && slocv6_set) {
10025 errmsg ("both source v4 and v6 addresses set\n");
10029 if (!slocv4_set && !slocv6_set) {
10030 errmsg ("source addresses not set\n");
10034 if (dlocv4_set && dlocv6_set) {
10035 errmsg ("both destination v4 and v6 addresses set\n");
10039 if (dlocv4_set && dlocv6_set) {
10040 errmsg ("destination addresses not set\n");
10044 if (!(slocv4_set == dlocv4_set && slocv6_set == dlocv6_set)) {
10045 errmsg ("mixing type of source and destination address\n");
10049 /* Construct the API message */
10050 M(LISP_GPE_ADD_DEL_FWD_ENTRY, lisp_gpe_add_del_fwd_entry);
10052 mp->is_add = is_add;
10054 mp->eid_is_ipv6 = 1;
10055 clib_memcpy(mp->eid_ip_address, &eidv6, sizeof(eidv6));
10057 mp->eid_is_ipv6 = 0;
10058 clib_memcpy(mp->eid_ip_address, &eidv4, sizeof(eidv4));
10060 mp->eid_prefix_len = eid_lenght;
10062 mp->address_is_ipv6 = 1;
10063 clib_memcpy(mp->source_ip_address, &slocv6, sizeof(slocv6));
10064 clib_memcpy(mp->destination_ip_address, &dlocv6, sizeof(dlocv6));
10066 mp->address_is_ipv6 = 0;
10067 clib_memcpy(mp->source_ip_address, &slocv4, sizeof(slocv4));
10068 clib_memcpy(mp->destination_ip_address, &dlocv4, sizeof(dlocv4));
10074 /* Wait for a reply... */
10082 api_lisp_add_del_map_resolver(vat_main_t * vam)
10084 unformat_input_t * input = vam->input;
10085 vl_api_lisp_add_del_map_resolver_t *mp;
10090 ip4_address_t ipv4;
10091 ip6_address_t ipv6;
10093 /* Parse args required to build the message */
10094 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) {
10095 if (unformat(input, "del")) {
10097 } else if (unformat(input, "%U", unformat_ip4_address, &ipv4)) {
10099 } else if (unformat(input, "%U", unformat_ip6_address, &ipv6)) {
10105 if (ipv4_set && ipv6_set) {
10106 errmsg ("both eid v4 and v6 addresses set\n");
10110 if (!ipv4_set && !ipv6_set) {
10111 errmsg ("eid addresses not set\n");
10115 /* Construct the API message */
10116 M(LISP_ADD_DEL_MAP_RESOLVER, lisp_add_del_map_resolver);
10118 mp->is_add = is_add;
10121 clib_memcpy(mp->ip_address, &ipv6, sizeof(ipv6));
10124 clib_memcpy(mp->ip_address, &ipv4, sizeof(ipv4));
10130 /* Wait for a reply... */
10138 api_lisp_gpe_enable_disable (vat_main_t * vam)
10140 unformat_input_t * input = vam->input;
10141 vl_api_lisp_gpe_enable_disable_t *mp;
10146 /* Parse args required to build the message */
10147 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) {
10148 if (unformat(input, "enable")) {
10151 } else if (unformat(input, "disable")) {
10159 errmsg("Value not set\n");
10163 /* Construct the API message */
10164 M(LISP_GPE_ENABLE_DISABLE, lisp_gpe_enable_disable);
10171 /* Wait for a reply... */
10179 api_lisp_gpe_add_del_iface(vat_main_t * vam)
10181 unformat_input_t * input = vam->input;
10182 vl_api_lisp_gpe_add_del_iface_t *mp;
10188 /* Parse args required to build the message */
10189 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) {
10190 if (unformat(input, "up")) {
10193 } else if (unformat(input, "down")) {
10196 } else if (unformat(input, "table_id %d", &table_id)) {
10198 } else if (unformat(input, "vni %d", &vni)) {
10205 errmsg("Value not set\n");
10209 /* Construct the API message */
10210 M(LISP_GPE_ADD_DEL_IFACE, lisp_gpe_add_del_iface);
10212 mp->is_add = is_add;
10213 mp->table_id = table_id;
10219 /* Wait for a reply... */
10227 api_lisp_locator_set_dump(vat_main_t *vam)
10229 vl_api_lisp_locator_set_dump_t *mp;
10232 if (!vam->json_output) {
10233 fformat(vam->ofp, "%=20s%=16s%=16s%=16s\n",
10234 "Locator-set", "Locator", "Priority", "Weight");
10237 M(LISP_LOCATOR_SET_DUMP, lisp_locator_set_dump);
10241 /* Use a control ping for synchronization */
10243 vl_api_control_ping_t * mp;
10244 M(CONTROL_PING, control_ping);
10247 /* Wait for a reply... */
10255 api_lisp_local_eid_table_dump(vat_main_t *vam)
10257 vl_api_lisp_local_eid_table_dump_t *mp;
10260 if (!vam->json_output) {
10261 fformat(vam->ofp, "%=20s%=30s\n",
10262 "Locator-set", "Eid");
10265 M(LISP_LOCAL_EID_TABLE_DUMP, lisp_local_eid_table_dump);
10269 /* Use a control ping for synchronization */
10271 vl_api_control_ping_t * mp;
10272 M(CONTROL_PING, control_ping);
10275 /* Wait for a reply... */
10283 api_lisp_gpe_tunnel_dump(vat_main_t *vam)
10285 vl_api_lisp_gpe_tunnel_dump_t *mp;
10288 if (!vam->json_output) {
10289 fformat(vam->ofp, "%=20s%=30s%=16s%=16s%=16s%=16s"
10290 "%=16s%=16s%=16s%=16s%=16s\n",
10291 "Tunel", "Source", "Destination", "Fib encap", "Fib decap",
10292 "Decap next", "Lisp version", "Flags", "Next protocol",
10293 "ver_res", "res", "iid");
10296 M(LISP_GPE_TUNNEL_DUMP, lisp_gpe_tunnel_dump);
10300 /* Use a control ping for synchronization */
10302 vl_api_control_ping_t * mp;
10303 M(CONTROL_PING, control_ping);
10306 /* Wait for a reply... */
10314 api_lisp_map_resolver_dump(vat_main_t *vam)
10316 vl_api_lisp_map_resolver_dump_t *mp;
10319 if (!vam->json_output) {
10320 fformat(vam->ofp, "%=20s\n",
10324 M(LISP_MAP_RESOLVER_DUMP, lisp_map_resolver_dump);
10328 /* Use a control ping for synchronization */
10330 vl_api_control_ping_t * mp;
10331 M(CONTROL_PING, control_ping);
10334 /* Wait for a reply... */
10342 api_lisp_gpe_enable_disable_status_dump(vat_main_t *vam)
10344 vl_api_lisp_gpe_enable_disable_status_dump_t *mp;
10347 if (!vam->json_output) {
10348 fformat(vam->ofp, "%=20s\n",
10352 M(LISP_GPE_ENABLE_DISABLE_STATUS_DUMP,
10353 lisp_gpe_enable_disable_status_dump);
10357 /* Use a control ping for synchronization */
10359 vl_api_control_ping_t * mp;
10360 M(CONTROL_PING, control_ping);
10363 /* Wait for a reply... */
10370 static int q_or_quit (vat_main_t * vam)
10372 longjmp (vam->jump_buf, 1);
10373 return 0; /* not so much */
10375 static int q (vat_main_t * vam) {return q_or_quit (vam);}
10376 static int quit (vat_main_t * vam) {return q_or_quit (vam);}
10378 static int comment (vat_main_t * vam)
10383 static int cmd_cmp (void * a1, void * a2)
10388 return strcmp ((char *)(c1[0]), (char *)(c2[0]));
10391 static int help (vat_main_t * vam)
10396 unformat_input_t * i = vam->input;
10399 if (unformat (i, "%s", &name)) {
10404 hs = hash_get_mem (vam->help_by_name, name);
10406 fformat (vam->ofp, "usage: %s %s\n", name, hs[0]);
10408 fformat (vam->ofp, "No such msg / command '%s'\n", name);
10413 fformat(vam->ofp, "Help is available for the following:\n");
10415 hash_foreach_pair (p, vam->function_by_name,
10417 vec_add1 (cmds, (u8 *)(p->key));
10420 vec_sort_with_function (cmds, cmd_cmp);
10422 for (j = 0; j < vec_len(cmds); j++)
10423 fformat (vam->ofp, "%s\n", cmds[j]);
10429 static int set (vat_main_t * vam)
10431 u8 * name = 0, * value = 0;
10432 unformat_input_t * i = vam->input;
10434 if (unformat (i, "%s", &name)) {
10435 /* The input buffer is a vector, not a string. */
10436 value = vec_dup (i->buffer);
10437 vec_delete (value, i->index, 0);
10438 /* Almost certainly has a trailing newline */
10439 if (value[vec_len(value)-1] == '\n')
10440 value[vec_len(value)-1] = 0;
10441 /* Make sure it's a proper string, one way or the other */
10442 vec_add1 (value, 0);
10443 (void) clib_macro_set_value (&vam->macro_main,
10444 (char *)name, (char *)value);
10447 errmsg ("usage: set <name> <value>\n");
10454 static int unset (vat_main_t * vam)
10458 if (unformat (vam->input, "%s", &name))
10459 if (clib_macro_unset (&vam->macro_main, (char *)name) == 1)
10460 errmsg ("unset: %s wasn't set\n", name);
10471 static int macro_sort_cmp (void * a1, void * a2)
10473 macro_sort_t * s1 = a1;
10474 macro_sort_t * s2 = a2;
10476 return strcmp ((char *)(s1->name), (char *)(s2->name));
10479 static int dump_macro_table (vat_main_t * vam)
10481 macro_sort_t * sort_me = 0, * sm;
10485 hash_foreach_pair (p, vam->macro_main.the_value_table_hash,
10487 vec_add2 (sort_me, sm, 1);
10488 sm->name = (u8 *)(p->key);
10489 sm->value = (u8 *) (p->value[0]);
10492 vec_sort_with_function (sort_me, macro_sort_cmp);
10494 if (vec_len(sort_me))
10495 fformat (vam->ofp, "%-15s%s\n", "Name", "Value");
10497 fformat (vam->ofp, "The macro table is empty...\n");
10499 for (i = 0; i < vec_len (sort_me); i++)
10500 fformat (vam->ofp, "%-15s%s\n", sort_me[i].name,
10505 static int dump_node_table (vat_main_t * vam)
10508 vlib_node_t * node, * next_node;
10510 if (vec_len (vam->graph_nodes) == 0) {
10511 fformat (vam->ofp, "Node table empty, issue get_node_graph...\n");
10515 for (i = 0; i < vec_len (vam->graph_nodes); i++) {
10516 node = vam->graph_nodes[i];
10517 fformat (vam->ofp, "[%d] %s\n", i, node->name);
10518 for (j = 0; j < vec_len (node->next_nodes); j++) {
10519 if (node->next_nodes[j] != ~0) {
10520 next_node = vam->graph_nodes[node->next_nodes[j]];
10521 fformat (vam->ofp, " [%d] %s\n", j, next_node->name);
10528 static int search_node_table (vat_main_t * vam)
10530 unformat_input_t * line_input = vam->input;
10533 vlib_node_t * node, * next_node;
10536 if (vam->graph_node_index_by_name == 0) {
10537 fformat (vam->ofp, "Node table empty, issue get_node_graph...\n");
10541 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) {
10542 if (unformat (line_input, "%s", &node_to_find)) {
10543 vec_add1 (node_to_find, 0);
10544 p = hash_get_mem (vam->graph_node_index_by_name, node_to_find);
10546 fformat (vam->ofp, "%s not found...\n", node_to_find);
10549 node = vam->graph_nodes[p[0]];
10550 fformat (vam->ofp, "[%d] %s\n", p[0], node->name);
10551 for (j = 0; j < vec_len (node->next_nodes); j++) {
10552 if (node->next_nodes[j] != ~0) {
10553 next_node = vam->graph_nodes[node->next_nodes[j]];
10554 fformat (vam->ofp, " [%d] %s\n", j, next_node->name);
10560 clib_warning ("parse error '%U'", format_unformat_error,
10566 vec_free(node_to_find);
10574 static int script (vat_main_t * vam)
10577 char * save_current_file;
10578 unformat_input_t save_input;
10579 jmp_buf save_jump_buf;
10580 u32 save_line_number;
10582 FILE * new_fp, * save_ifp;
10584 if (unformat (vam->input, "%s", &s)) {
10585 new_fp = fopen ((char *)s, "r");
10587 errmsg ("Couldn't open script file %s\n", s);
10592 errmsg ("Missing script name\n");
10596 clib_memcpy (&save_input, &vam->input, sizeof (save_input));
10597 clib_memcpy (&save_jump_buf, &vam->jump_buf, sizeof (save_jump_buf));
10598 save_ifp = vam->ifp;
10599 save_line_number = vam->input_line_number;
10600 save_current_file = (char *) vam->current_file;
10602 vam->input_line_number = 0;
10604 vam->current_file = s;
10607 clib_memcpy (&vam->input, &save_input, sizeof (vam->input));
10608 clib_memcpy (&vam->jump_buf, &save_jump_buf, sizeof (save_jump_buf));
10609 vam->ifp = save_ifp;
10610 vam->input_line_number = save_line_number;
10611 vam->current_file = (u8 *) save_current_file;
10617 static int echo (vat_main_t * vam)
10619 fformat (vam->ofp, "%v", vam->input->buffer);
10623 /* List of API message constructors, CLI names map to api_xxx */
10624 #define foreach_vpe_api_msg \
10625 _(create_loopback,"[mac <mac-addr>]") \
10626 _(sw_interface_dump,"") \
10627 _(sw_interface_set_flags, \
10628 "<intfc> | sw_if_index <id> admin-up | admin-down link-up | link down") \
10629 _(sw_interface_add_del_address, \
10630 "<intfc> | sw_if_index <id> <ip4-address> | <ip6-address> [del] [del-all] ") \
10631 _(sw_interface_set_table, \
10632 "<intfc> | sw_if_index <id> vrf <table-id> [ipv6]") \
10633 _(sw_interface_set_vpath, \
10634 "<intfc> | sw_if_index <id> enable | disable") \
10635 _(sw_interface_set_l2_xconnect, \
10636 "rx <intfc> | rx_sw_if_index <id> tx <intfc> | tx_sw_if_index <id>\n" \
10637 "enable | disable") \
10638 _(sw_interface_set_l2_bridge, \
10639 "rx <intfc> | rx_sw_if_index <id> bd_id <bridge-domain-id>\n" \
10640 "[shg <split-horizon-group>] [bvi]\n" \
10641 "enable | disable") \
10642 _(bridge_domain_add_del, \
10643 "bd_id <bridge-domain-id> [flood 1|0] [uu-flood 1|0] [forward 1|0] [learn 1|0] [arp-term 1|0] [del]\n")\
10644 _(bridge_domain_dump, "[bd_id <bridge-domain-id>]\n") \
10646 "mac <mac-addr> bd_id <bridge-domain-id> [del] | sw_if <intfc> | sw_if_index <id> [static] [filter] [bvi]\n") \
10648 "sw_if <intfc> | sw_if_index <id> [learn] [forward] [uu-flood] [flood]\n") \
10650 "bd_id <bridge-domain-id> [learn] [forward] [uu-flood] [flood] [arp-term] [disable]\n") \
10652 "tapname <name> mac <mac-addr> | random-mac") \
10654 "<vpp-if-name> | sw_if_index <id> tapname <name> mac <mac-addr> | random-mac") \
10656 "<vpp-if-name> | sw_if_index <id>") \
10657 _(sw_interface_tap_dump, "") \
10658 _(ip_add_del_route, \
10659 "<addr>/<mask> via <addr> [vrf <n>]\n" \
10660 "[<intfc> | sw_if_index <id>] [resolve-attempts <n>]\n" \
10661 "[weight <n>] [drop] [local] [classify <n>] [del]\n" \
10662 "[multipath] [count <n>]") \
10663 _(proxy_arp_add_del, \
10664 "<lo-ip4-addr> - <hi-ip4-addr> [vrf <n>] [del]") \
10665 _(proxy_arp_intfc_enable_disable, \
10666 "<intfc> | sw_if_index <id> enable | disable") \
10667 _(mpls_add_del_encap, \
10668 "label <n> dst <ip4-addr> [vrf <n>] [del]") \
10669 _(mpls_add_del_decap, \
10670 "label <n> [rx_vrf_id <n>] [tx_vrf_id] [s-bit-clear][del]") \
10671 _(mpls_gre_add_del_tunnel, \
10672 "inner_vrf_id <n> outer_vrf_id <n> src <ip4-address> dst <ip4-address>\n" \
10673 "adj <ip4-address>/<mask-width> [del]") \
10674 _(sw_interface_set_unnumbered, \
10675 "<intfc> | sw_if_index <id> unnum_if_index <id> [del]") \
10676 _(ip_neighbor_add_del, \
10677 "<intfc> | sw_if_index <id> dst <ip46-address> mac <mac-addr>") \
10678 _(reset_vrf, "vrf <id> [ipv6]") \
10679 _(create_vlan_subif, "<intfc> | sw_if_index <id> vlan <n>") \
10680 _(create_subif, "<intfc> | sw_if_index <id> sub_id <n>\n" \
10681 "[outer_vlan_id <n>][inner_vlan_id <n>]\n" \
10682 "[no_tags][one_tag][two_tags][dot1ad][exact_match][default_sub]\n" \
10683 "[outer_vlan_id_any][inner_vlan_id_any]") \
10684 _(oam_add_del, "src <ip4-address> dst <ip4-address> [vrf <n>] [del]") \
10685 _(reset_fib, "vrf <n> [ipv6]") \
10686 _(dhcp_proxy_config, \
10687 "svr <v46-address> src <v46-address>\n" \
10688 "insert-cid <n> [del]") \
10689 _(dhcp_proxy_config_2, \
10690 "svr <v46-address> src <v46-address>\n" \
10691 "rx_vrf_id <nn> server_vrf_id <nn> insert-cid <n> [del]") \
10692 _(dhcp_proxy_set_vss, \
10693 "tbl_id <n> fib_id <n> oui <n> [ipv6] [del]") \
10694 _(dhcp_client_config, \
10695 "<intfc> | sw_if_index <id> [hostname <name>] [disable_event] [del]") \
10696 _(set_ip_flow_hash, \
10697 "vrf <n> [src] [dst] [sport] [dport] [proto] [reverse] [ipv6]") \
10698 _(sw_interface_ip6_enable_disable, \
10699 "<intfc> | sw_if_index <id> enable | disable") \
10700 _(sw_interface_ip6_set_link_local_address, \
10701 "<intfc> | sw_if_index <id> <ip6-address>/<mask-width>") \
10702 _(sw_interface_ip6nd_ra_prefix, \
10703 "<intfc> | sw_if_index <id> <ip6-address>/<mask-width>\n" \
10704 "val_life <n> pref_life <n> [def] [noadv] [offl] [noauto]\n" \
10705 "[nolink] [isno]") \
10706 _(sw_interface_ip6nd_ra_config, \
10707 "<intfc> | sw_if_index <id> [maxint <n>] [minint <n>]\n" \
10708 "[life <n>] [count <n>] [interval <n>] [surpress]\n" \
10709 "[managed] [other] [ll] [send] [cease] [isno] [def]") \
10710 _(set_arp_neighbor_limit, "arp_nbr_limit <n> [ipv6]") \
10711 _(l2_patch_add_del, \
10712 "rx <intfc> | rx_sw_if_index <id> tx <intfc> | tx_sw_if_index <id>\n" \
10713 "enable | disable") \
10714 _(mpls_ethernet_add_del_tunnel, \
10715 "tx <intfc> | tx_sw_if_index <n> dst <mac-addr>\n" \
10716 "adj <ip4-addr>/<mw> dst <mac-addr> [del]") \
10717 _(mpls_ethernet_add_del_tunnel_2, \
10718 "inner_vrf_id <n> outer_vrf_id <n> next-hop <ip4-addr>\n" \
10719 "resolve-attempts <n> resolve-if-needed 0 | 1 [del]") \
10720 _(sr_tunnel_add_del, \
10721 "[name <name>] src <ip6-addr> dst <ip6-addr>/<mw> \n" \
10722 "(next <ip6-addr>)+ [tag <ip6-addr>]* [clean] [reroute] \n" \
10723 "[policy <policy_name>]") \
10724 _(sr_policy_add_del, \
10725 "name <name> tunnel <tunnel-name> [tunnel <tunnel-name>]* [del]") \
10726 _(sr_multicast_map_add_del, \
10727 "address [ip6 multicast address] sr-policy [policy name] [del]") \
10728 _(classify_add_del_table, \
10729 "buckets <nn> [skip <n>] [match <n>] [memory_size <nn-bytes>]\n" \
10730 "[del] mask <mask-value>\n" \
10731 " [l2-miss-next | miss-next | acl-miss-next] <name|nn>") \
10732 _(classify_add_del_session, \
10733 "[hit-next|l2-hit-next|acl-hit-next] <name|nn> table-index <nn>\n" \
10734 "skip_n <nn> match_n <nn> match [hex] [l2] [l3 [ip4|ip6]]") \
10735 _(classify_set_interface_ip_table, \
10736 "<intfc> | sw_if_index <nn> table <nn>") \
10737 _(classify_set_interface_l2_tables, \
10738 "<intfc> | sw_if_index <nn> [ip4-table <nn>] [ip6-table <nn>]\n" \
10739 " [other-table <nn>]") \
10740 _(get_node_index, "node <node-name") \
10741 _(add_node_next, "node <node-name> next <next-node-name>") \
10742 _(l2tpv3_create_tunnel, \
10743 "client_address <ip6-addr> our_address <ip6-addr>\n" \
10744 "[local_session_id <nn>][remote_session_id <nn>][local_cookie <nn>]\n"\
10745 "[remote_cookie <nn>]\n[l2-sublayer-preset]\n") \
10746 _(l2tpv3_set_tunnel_cookies, \
10747 "<intfc> | sw_if_index <nn> [new_local_cookie <nn>]\n" \
10748 "[new_remote_cookie <nn>]\n") \
10749 _(l2tpv3_interface_enable_disable, \
10750 "<intfc> | sw_if_index <nn> enable | disable") \
10751 _(l2tpv3_set_lookup_key, \
10752 "lookup_v6_src | lookup_v6_dst | lookup_session_id") \
10753 _(sw_if_l2tpv3_tunnel_dump, "") \
10754 _(vxlan_add_del_tunnel, \
10755 "src <ip4-addr> dst <ip4-addr> vni <vni> [encap-vrf-id <nn>]\n" \
10756 " [decap-next l2|ip4|ip6] [del]") \
10757 _(vxlan_tunnel_dump, "[<intfc> | sw_if_index <nn>]") \
10758 _(gre_add_del_tunnel, \
10759 "src <ip4-addr> dst <ip4-addr> [outer-fib-id <nn>] [del]\n") \
10760 _(gre_tunnel_dump, "[<intfc> | sw_if_index <nn>]") \
10761 _(l2_fib_clear_table, "") \
10762 _(l2_interface_efp_filter, "sw_if_index <nn> enable | disable") \
10763 _(l2_interface_vlan_tag_rewrite, \
10764 "<intfc> | sw_if_index <nn> \n" \
10765 "[disable][push-[1|2]][pop-[1|2]][translate-1-[1|2]] \n" \
10766 "[translate-2-[1|2]] [push_dot1q 0] tag1 <nn> tag2 <nn>") \
10767 _(create_vhost_user_if, \
10768 "socket <filename> [server] [renumber <dev_instance>] " \
10769 "[mac <mac_address>]") \
10770 _(modify_vhost_user_if, \
10771 "<intfc> | sw_if_index <nn> socket <filename>\n" \
10772 "[server] [renumber <dev_instance>]") \
10773 _(delete_vhost_user_if, "<intfc> | sw_if_index <nn>") \
10774 _(sw_interface_vhost_user_dump, "") \
10775 _(show_version, "") \
10776 _(nsh_gre_add_del_tunnel, \
10777 "src <ip4-addr> dst <ip4-addr>" \
10778 "c1 <nn> c2 <nn> c3 <nn> c4 <nn> spi <nn> si <nn>\n" \
10779 "[encap-fib-id <nn>] [decap-fib-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 _(nsh_vxlan_gpe_add_del_tunnel, \
10783 "src <ip4-addr> dst <ip4-addr> vni <nn>\n" \
10784 "c1 <nn> c2 <nn> c3 <nn> c4 <nn> spi <nn> si <nn>\n" \
10785 "[encap-vrf-id <nn>] [decap-vrf-id <nn>] [o-bit <1|0>]\n" \
10786 "[c-bit <1|0>] [md-type <nn>][next-ip4][next-ip6][next-ethernet]\n" \
10787 "[tlv <xx>][del]") \
10788 _(l2_fib_table_dump, "bd_id <bridge-domain-id>") \
10789 _(lisp_gpe_add_del_tunnel, \
10790 "src <ip4-addr> dst <ip4-addr> iid <nn>|iidx <0xnn>\n" \
10791 "[encap-vrf-id <nn>] [decap-vrf-id <nn>]\n" \
10792 "[n-bit][l-bit][e-bit][v-bit][i-bit][p-bit][not-p-bit][o-bit]\n" \
10793 "[next-ip4][next-ip6][next-ethernet][next-nsh]\n" \
10794 "[decap-next [ip4|ip6|ethernet|nsh-encap|<nn>]][del]") \
10795 _(interface_name_renumber, \
10796 "<intfc> | sw_if_index <nn> new_show_dev_instance <nn>") \
10797 _(input_acl_set_interface, \
10798 "<intfc> | sw_if_index <nn> [ip4-table <nn>] [ip6-table <nn>]\n" \
10799 " [l2-table <nn>] [del]") \
10800 _(want_ip4_arp_events, "address <ip4-address> [del]") \
10801 _(ip_address_dump, "(ipv4 | ipv6) (<intfc> | sw_if_index <id>)") \
10802 _(ip_dump, "ipv4 | ipv6") \
10803 _(ipsec_spd_add_del, "spd_id <n> [del]") \
10804 _(ipsec_interface_add_del_spd, "(<intfc> | sw_if_index <id>)\n" \
10806 _(ipsec_sad_add_del_entry, "sad_id <n> spi <n> crypto_alg <alg>\n" \
10807 " crypto_key <hex> tunnel_src <ip4|ip6> tunnel_dst <ip4|ip6>\n" \
10808 " integ_alg <alg> integ_key <hex>") \
10809 _(ipsec_spd_add_del_entry, "spd_id <n> priority <n> action <action>\n" \
10810 " (inbound|outbound) [sa_id <n>] laddr_start <ip4|ip6>\n" \
10811 " laddr_stop <ip4|ip6> raddr_start <ip4|ip6> raddr_stop <ip4|ip6>\n" \
10812 " [lport_start <n> lport_stop <n>] [rport_start <n> rport_stop <n>]" )\
10813 _(ipsec_sa_set_key, "sa_id <n> crypto_key <hex> integ_key <hex>") \
10814 _(ikev2_profile_add_del, "name <profile_name> [del]") \
10815 _(ikev2_profile_set_auth, "name <profile_name> auth_method <method>\n" \
10816 "(auth_data 0x<data> | auth_data <data>)") \
10817 _(ikev2_profile_set_id, "name <profile_name> id_type <type>\n" \
10818 "(id_data 0x<data> | id_data <data>) (local|remote)") \
10819 _(ikev2_profile_set_ts, "name <profile_name> protocol <proto>\n" \
10820 "start_port <port> end_port <port> start_addr <ip4> end_addr <ip4>\n" \
10821 "(local|remote)") \
10822 _(ikev2_set_local_key, "file <absolute_file_path>") \
10823 _(delete_loopback,"sw_if_index <nn>") \
10824 _(bd_ip_mac_add_del, "bd_id <bridge-domain-id> <ip4/6-addr> <mac-addr> [del]") \
10825 _(map_add_domain, \
10826 "ip4-pfx <ip4pfx> ip6-pfx <ip6pfx> " \
10827 "ip6-src <ip6addr> " \
10828 "ea-bits-len <n> psid-offset <n> psid-len <n>") \
10829 _(map_del_domain, "index <n>") \
10830 _(map_add_del_rule, \
10831 "index <n> psid <n> dst <ip6addr> [del]") \
10832 _(map_domain_dump, "") \
10833 _(map_rule_dump, "index <map-domain>") \
10834 _(want_interface_events, "enable|disable") \
10835 _(want_stats,"enable|disable") \
10836 _(get_first_msg_id, "client <name>") \
10837 _(cop_interface_enable_disable, "<intfc> | sw_if_index <nn> [disable]") \
10838 _(cop_whitelist_enable_disable, "<intfc> | sw_if_index <nn>\n" \
10839 "fib-id <nn> [ip4][ip6][default]") \
10840 _(get_node_graph, " ") \
10841 _(sw_interface_clear_stats,"<intfc> | sw_if_index <nn>") \
10842 _(trace_profile_add, "id <nn> trace-type <0x1f|0x3|0x9|0x11|0x19> " \
10843 "trace-elts <nn> trace-tsp <0|1|2|3> node-id <node id in hex> " \
10844 "app-data <app_data in hex> [pow] [ppc <encap|decap>]") \
10845 _(trace_profile_apply, "id <nn> <ip6-address>/<width>" \
10846 " vrf_id <nn> add | pop | none") \
10847 _(trace_profile_del, "") \
10848 _(lisp_add_del_locator_set, "locator-set <locator_name> [del]") \
10849 _(lisp_add_del_locator, "locator-set <locator_name> " \
10850 "iface <intf> | sw_if_index <sw_if_index> " \
10851 "p <priority> w <weight> [del]") \
10852 _(lisp_add_del_local_eid, "<ipv4|ipv6>/<prefix> " \
10853 "locator-set <locator_name> [del]") \
10854 _(lisp_gpe_add_del_fwd_entry, "eid <ip4|6-addr>/<prefix> " \
10855 "sloc <ip4/6-addr> dloc <ip4|6-addr> [del]") \
10856 _(lisp_add_del_map_resolver, "<ip4|6-addr> [del]") \
10857 _(lisp_gpe_enable_disable, "enable|disable") \
10858 _(lisp_gpe_add_del_iface, "up|down") \
10859 _(lisp_locator_set_dump, "") \
10860 _(lisp_local_eid_table_dump, "") \
10861 _(lisp_gpe_tunnel_dump, "") \
10862 _(lisp_map_resolver_dump, "") \
10863 _(lisp_gpe_enable_disable_status_dump, "")
10865 /* List of command functions, CLI names map directly to functions */
10866 #define foreach_cli_function \
10867 _(comment, "usage: comment <ignore-rest-of-line>") \
10868 _(dump_interface_table, "usage: dump_interface_table") \
10869 _(dump_sub_interface_table, "usage: dump_sub_interface_table") \
10870 _(dump_ipv4_table, "usage: dump_ipv4_table") \
10871 _(dump_ipv6_table, "usage: dump_ipv6_table") \
10872 _(dump_stats_table, "usage: dump_stats_table") \
10873 _(dump_macro_table, "usage: dump_macro_table ") \
10874 _(dump_node_table, "usage: dump_node_table") \
10875 _(echo, "usage: echo <message>") \
10876 _(exec, "usage: exec <vpe-debug-CLI-command>") \
10877 _(help, "usage: help") \
10878 _(q, "usage: quit") \
10879 _(quit, "usage: quit") \
10880 _(search_node_table, "usage: search_node_table <name>...") \
10881 _(set, "usage: set <variable-name> <value>") \
10882 _(script, "usage: script <file-name>") \
10883 _(unset, "usage: unset <variable-name>")
10886 static void vl_api_##n##_t_handler_uni \
10887 (vl_api_##n##_t * mp) \
10889 vat_main_t * vam = &vat_main; \
10890 if (vam->json_output) { \
10891 vl_api_##n##_t_handler_json(mp); \
10893 vl_api_##n##_t_handler(mp); \
10896 foreach_vpe_api_reply_msg;
10899 void vat_api_hookup (vat_main_t *vam)
10902 vl_msg_api_set_handlers(VL_API_##N, #n, \
10903 vl_api_##n##_t_handler_uni, \
10905 vl_api_##n##_t_endian, \
10906 vl_api_##n##_t_print, \
10907 sizeof(vl_api_##n##_t), 1);
10908 foreach_vpe_api_reply_msg;
10911 vl_msg_api_set_first_available_msg_id (VL_MSG_FIRST_AVAILABLE);
10913 vam->sw_if_index_by_interface_name =
10914 hash_create_string (0, sizeof (uword));
10916 vam->function_by_name =
10917 hash_create_string (0, sizeof(uword));
10919 vam->help_by_name =
10920 hash_create_string (0, sizeof(uword));
10922 /* API messages we can send */
10923 #define _(n,h) hash_set_mem (vam->function_by_name, #n, api_##n);
10924 foreach_vpe_api_msg;
10928 #define _(n,h) hash_set_mem (vam->help_by_name, #n, h);
10929 foreach_vpe_api_msg;
10932 /* CLI functions */
10933 #define _(n,h) hash_set_mem (vam->function_by_name, #n, n);
10934 foreach_cli_function;
10938 #define _(n,h) hash_set_mem (vam->help_by_name, #n, h);
10939 foreach_cli_function;
10943 #undef vl_api_version
10944 #define vl_api_version(n,v) static u32 vpe_api_version = v;
10945 #include <api/vpe.api.h>
10946 #undef vl_api_version
10948 void vl_client_add_api_signatures (vl_api_memclnt_create_t *mp)
10951 * Send the main API signature in slot 0. This bit of code must
10952 * match the checks in ../vpe/api/api.c: vl_msg_api_version_check().
10954 mp->api_versions[0] = clib_host_to_net_u32 (vpe_api_version);