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/nsh-gre/nsh_gre.h>
30 #include <vnet/nsh-vxlan-gpe/nsh_vxlan_gpe.h>
31 #include <vnet/lisp-gpe/lisp_gpe.h>
33 #include <api/vpe_msg_enum.h>
34 #include <vnet/l2/l2_classify.h>
35 #include <vnet/l2/l2_vtr.h>
36 #include <vnet/classify/input_acl.h>
38 #include <vnet/ipsec/ipsec.h>
42 #include <vnet/map/map.h>
43 #include <vnet/cop/cop.h>
45 #include "vat/json_format.h"
47 #define vl_typedefs /* define message structures */
48 #include <api/vpe_all_api_h.h>
51 /* declare message handlers for each api */
53 #define vl_endianfun /* define message structures */
54 #include <api/vpe_all_api_h.h>
57 /* instantiate all the print functions we know about */
58 #define vl_print(handle, ...)
60 #include <api/vpe_all_api_h.h>
63 uword unformat_sw_if_index (unformat_input_t * input, va_list * args)
65 vat_main_t * vam = va_arg (*args, vat_main_t *);
66 u32 * result = va_arg (*args, u32 *);
70 if (!unformat (input, "%s", &if_name))
73 p = hash_get_mem (vam->sw_if_index_by_interface_name, if_name);
80 /* Parse an IP4 address %d.%d.%d.%d. */
81 uword unformat_ip4_address (unformat_input_t * input, va_list * args)
83 u8 * result = va_arg (*args, u8 *);
86 if (! unformat (input, "%d.%d.%d.%d", &a[0], &a[1], &a[2], &a[3]))
89 if (a[0] >= 256 || a[1] >= 256 || a[2] >= 256 || a[3] >= 256)
102 unformat_ethernet_address (unformat_input_t * input, va_list * args)
104 u8 * result = va_arg (*args, u8 *);
107 if (! unformat (input, "%_%x:%x:%x:%x:%x:%x%_",
108 &a[0], &a[1], &a[2], &a[3], &a[4], &a[5]))
112 for (i = 0; i < 6; i++)
113 if (a[i] >= (1 << 8))
116 for (i = 0; i < 6; i++)
122 /* Returns ethernet type as an int in host byte order. */
124 unformat_ethernet_type_host_byte_order (unformat_input_t * input,
127 u16 * result = va_arg (*args, u16 *);
131 if (unformat (input, "0x%x", &type)
132 || unformat (input, "%d", &type))
134 if (type >= (1 << 16))
142 /* Parse an IP6 address. */
143 uword unformat_ip6_address (unformat_input_t * input, va_list * args)
145 ip6_address_t * result = va_arg (*args, ip6_address_t *);
147 uword hex_quad, n_hex_quads, hex_digit, n_hex_digits;
148 uword c, n_colon, double_colon_index;
150 n_hex_quads = hex_quad = n_hex_digits = n_colon = 0;
151 double_colon_index = ARRAY_LEN (hex_quads);
152 while ((c = unformat_get_input (input)) != UNFORMAT_END_OF_INPUT)
155 if (c >= '0' && c <= '9')
157 else if (c >= 'a' && c <= 'f')
158 hex_digit = c + 10 - 'a';
159 else if (c >= 'A' && c <= 'F')
160 hex_digit = c + 10 - 'A';
161 else if (c == ':' && n_colon < 2)
165 unformat_put_input (input);
169 /* Too many hex quads. */
170 if (n_hex_quads >= ARRAY_LEN (hex_quads))
175 hex_quad = (hex_quad << 4) | hex_digit;
177 /* Hex quad must fit in 16 bits. */
178 if (n_hex_digits >= 4)
185 /* Save position of :: */
188 /* More than one :: ? */
189 if (double_colon_index < ARRAY_LEN (hex_quads))
191 double_colon_index = n_hex_quads;
194 if (n_colon > 0 && n_hex_digits > 0)
196 hex_quads[n_hex_quads++] = hex_quad;
202 if (n_hex_digits > 0)
203 hex_quads[n_hex_quads++] = hex_quad;
208 /* Expand :: to appropriate number of zero hex quads. */
209 if (double_colon_index < ARRAY_LEN (hex_quads))
211 word n_zero = ARRAY_LEN (hex_quads) - n_hex_quads;
213 for (i = n_hex_quads - 1; i >= (signed) double_colon_index; i--)
214 hex_quads[n_zero + i] = hex_quads[i];
216 for (i = 0; i < n_zero; i++)
217 hex_quads[double_colon_index + i] = 0;
219 n_hex_quads = ARRAY_LEN (hex_quads);
222 /* Too few hex quads given. */
223 if (n_hex_quads < ARRAY_LEN (hex_quads))
226 for (i = 0; i < ARRAY_LEN (hex_quads); i++)
227 result->as_u16[i] = clib_host_to_net_u16 (hex_quads[i]);
234 unformat_ipsec_policy_action (unformat_input_t * input, va_list * args)
237 u32 * r = va_arg (*args, u32 *);
240 #define _(v,f,s) else if (unformat (input, s)) *r = IPSEC_POLICY_ACTION_##f;
241 foreach_ipsec_policy_action
252 unformat_ipsec_crypto_alg (unformat_input_t * input, va_list * args)
255 u32 * r = va_arg (*args, u32 *);
258 #define _(v,f,s) else if (unformat (input, s)) *r = IPSEC_CRYPTO_ALG_##f;
259 foreach_ipsec_crypto_alg
270 format_ipsec_crypto_alg (u8 * s, va_list * args)
273 u32 i = va_arg (*args, u32);
278 #define _(v,f,str) case IPSEC_CRYPTO_ALG_##f: t = (u8 *) str; break;
279 foreach_ipsec_crypto_alg
282 return format (s, "unknown");
284 return format (s, "%s", t);
286 return format (s, "Unimplemented");
291 unformat_ipsec_integ_alg (unformat_input_t * input, va_list * args)
294 u32 * r = va_arg (*args, u32 *);
297 #define _(v,f,s) else if (unformat (input, s)) *r = IPSEC_INTEG_ALG_##f;
298 foreach_ipsec_integ_alg
309 format_ipsec_integ_alg (u8 * s, va_list * args)
312 u32 i = va_arg (*args, u32);
317 #define _(v,f,str) case IPSEC_INTEG_ALG_##f: t = (u8 *) str; break;
318 foreach_ipsec_integ_alg
321 return format (s, "unknown");
323 return format (s, "%s", t);
325 return format (s, "Unsupported");
329 u8 * format_ip4_address (u8 * s, va_list * args)
331 u8 * a = va_arg (*args, u8 *);
332 return format (s, "%d.%d.%d.%d", a[0], a[1], a[2], a[3]);
335 u8 * format_ip6_address (u8 * s, va_list * args)
337 ip6_address_t * a = va_arg (*args, ip6_address_t *);
338 u32 i, i_max_n_zero, max_n_zeros, i_first_zero, n_zeros, last_double_colon;
340 i_max_n_zero = ARRAY_LEN (a->as_u16);
342 i_first_zero = i_max_n_zero;
344 for (i = 0; i < ARRAY_LEN (a->as_u16); i++)
346 u32 is_zero = a->as_u16[i] == 0;
347 if (is_zero && i_first_zero >= ARRAY_LEN (a->as_u16))
353 if ((! is_zero && n_zeros > max_n_zeros)
354 || (i + 1 >= ARRAY_LEN (a->as_u16) && n_zeros > max_n_zeros))
356 i_max_n_zero = i_first_zero;
357 max_n_zeros = n_zeros;
358 i_first_zero = ARRAY_LEN (a->as_u16);
363 last_double_colon = 0;
364 for (i = 0; i < ARRAY_LEN (a->as_u16); i++)
366 if (i == i_max_n_zero && max_n_zeros > 1)
368 s = format (s, "::");
369 i += max_n_zeros - 1;
370 last_double_colon = 1;
374 s = format (s, "%s%x",
375 (last_double_colon || i == 0) ? "" : ":",
376 clib_net_to_host_u16 (a->as_u16[i]));
377 last_double_colon = 0;
384 u8 * format_ethernet_address (u8 * s, va_list * args)
386 u8 * a = va_arg (*args, u8 *);
388 return format (s, "%02x:%02x:%02x:%02x:%02x:%02x",
389 a[0], a[1], a[2], a[3], a[4], a[5]);
392 void increment_v4_address (ip4_address_t * a)
396 v = ntohl(a->as_u32) + 1;
397 a->as_u32 = ntohl(v);
400 void increment_v6_address (ip6_address_t * a)
404 v0 = clib_net_to_host_u64 (a->as_u64[0]);
405 v1 = clib_net_to_host_u64 (a->as_u64[1]);
410 a->as_u64[0] = clib_net_to_host_u64 (v0);
411 a->as_u64[1] = clib_net_to_host_u64 (v1);
415 static void vl_api_create_loopback_reply_t_handler
416 (vl_api_create_loopback_reply_t * mp)
418 vat_main_t * vam = &vat_main;
419 i32 retval = ntohl(mp->retval);
421 vam->retval = retval;
422 vam->result_ready = 1;
423 vam->regenerate_interface_table = 1;
426 static void vl_api_create_loopback_reply_t_handler_json
427 (vl_api_create_loopback_reply_t * mp)
429 vat_main_t * vam = &vat_main;
430 vat_json_node_t node;
432 vat_json_init_object(&node);
433 vat_json_object_add_int(&node, "retval", ntohl(mp->retval));
434 vat_json_object_add_uint(&node, "sw_if_index", ntohl(mp->sw_if_index));
436 vat_json_print(vam->ofp, &node);
437 vat_json_free(&node);
439 vam->retval = ntohl(mp->retval);
440 vam->result_ready = 1;
443 static void vl_api_create_vlan_subif_reply_t_handler
444 (vl_api_create_vlan_subif_reply_t * mp)
446 vat_main_t * vam = &vat_main;
447 i32 retval = ntohl(mp->retval);
449 vam->retval = retval;
450 vam->result_ready = 1;
451 vam->regenerate_interface_table = 1;
454 static void vl_api_create_vlan_subif_reply_t_handler_json
455 (vl_api_create_vlan_subif_reply_t * mp)
457 vat_main_t * vam = &vat_main;
458 vat_json_node_t node;
460 vat_json_init_object(&node);
461 vat_json_object_add_int(&node, "retval", ntohl(mp->retval));
462 vat_json_object_add_uint(&node, "sw_if_index", ntohl(mp->sw_if_index));
464 vat_json_print(vam->ofp, &node);
465 vat_json_free(&node);
467 vam->retval = ntohl(mp->retval);
468 vam->result_ready = 1;
471 static void vl_api_create_subif_reply_t_handler
472 (vl_api_create_subif_reply_t * mp)
474 vat_main_t * vam = &vat_main;
475 i32 retval = ntohl(mp->retval);
477 vam->retval = retval;
478 vam->result_ready = 1;
479 vam->regenerate_interface_table = 1;
482 static void vl_api_create_subif_reply_t_handler_json
483 (vl_api_create_subif_reply_t * mp)
485 vat_main_t * vam = &vat_main;
486 vat_json_node_t node;
488 vat_json_init_object(&node);
489 vat_json_object_add_int(&node, "retval", ntohl(mp->retval));
490 vat_json_object_add_uint(&node, "sw_if_index", ntohl(mp->sw_if_index));
492 vat_json_print(vam->ofp, &node);
493 vat_json_free(&node);
495 vam->retval = ntohl(mp->retval);
496 vam->result_ready = 1;
499 static void vl_api_interface_name_renumber_reply_t_handler
500 (vl_api_interface_name_renumber_reply_t * mp)
502 vat_main_t * vam = &vat_main;
503 i32 retval = ntohl(mp->retval);
505 vam->retval = retval;
506 vam->result_ready = 1;
507 vam->regenerate_interface_table = 1;
510 static void vl_api_interface_name_renumber_reply_t_handler_json
511 (vl_api_interface_name_renumber_reply_t * mp)
513 vat_main_t * vam = &vat_main;
514 vat_json_node_t node;
516 vat_json_init_object(&node);
517 vat_json_object_add_int(&node, "retval", ntohl(mp->retval));
519 vat_json_print(vam->ofp, &node);
520 vat_json_free(&node);
522 vam->retval = ntohl(mp->retval);
523 vam->result_ready = 1;
527 * Special-case: build the interface table, maintain
528 * the next loopback sw_if_index vbl.
530 static void vl_api_sw_interface_details_t_handler
531 (vl_api_sw_interface_details_t * mp)
533 vat_main_t * vam = &vat_main;
534 u8 * s = format (0, "%s%c", mp->interface_name, 0);
536 hash_set_mem (vam->sw_if_index_by_interface_name, s,
537 ntohl(mp->sw_if_index));
539 /* In sub interface case, fill the sub interface table entry */
540 if (mp->sw_if_index != mp->sup_sw_if_index) {
541 sw_interface_subif_t * sub = NULL;
543 vec_add2(vam->sw_if_subif_table, sub, 1);
545 vec_validate(sub->interface_name, strlen((char *)s) + 1);
546 strncpy((char *)sub->interface_name, (char *)s,
547 vec_len(sub->interface_name));
548 sub->sw_if_index = ntohl(mp->sw_if_index);
549 sub->sub_id = ntohl(mp->sub_id);
551 sub->sub_dot1ad = mp->sub_dot1ad;
552 sub->sub_number_of_tags = mp->sub_number_of_tags;
553 sub->sub_outer_vlan_id = ntohs(mp->sub_outer_vlan_id);
554 sub->sub_inner_vlan_id = ntohs(mp->sub_inner_vlan_id);
555 sub->sub_exact_match = mp->sub_exact_match;
556 sub->sub_default = mp->sub_default;
557 sub->sub_outer_vlan_id_any = mp->sub_outer_vlan_id_any;
558 sub->sub_inner_vlan_id_any = mp->sub_inner_vlan_id_any;
560 /* vlan tag rewrite */
561 sub->vtr_op = ntohl(mp->vtr_op);
562 sub->vtr_push_dot1q = ntohl(mp->vtr_push_dot1q);
563 sub->vtr_tag1 = ntohl(mp->vtr_tag1);
564 sub->vtr_tag2 = ntohl(mp->vtr_tag2);
568 static void vl_api_sw_interface_details_t_handler_json
569 (vl_api_sw_interface_details_t * mp)
571 vat_main_t * vam = &vat_main;
572 vat_json_node_t *node = NULL;
574 if (VAT_JSON_ARRAY != vam->json_tree.type) {
575 ASSERT(VAT_JSON_NONE == vam->json_tree.type);
576 vat_json_init_array(&vam->json_tree);
578 node = vat_json_array_add(&vam->json_tree);
580 vat_json_init_object(node);
581 vat_json_object_add_uint(node, "sw_if_index", ntohl(mp->sw_if_index));
582 vat_json_object_add_uint(node, "sup_sw_if_index", ntohl(mp->sup_sw_if_index));
583 vat_json_object_add_uint(node, "l2_address_length", ntohl(mp->l2_address_length));
584 vat_json_object_add_bytes(node, "l2_address", mp->l2_address, sizeof(mp->l2_address));
585 vat_json_object_add_string_copy(node, "interface_name", mp->interface_name);
586 vat_json_object_add_uint(node, "admin_up_down", mp->admin_up_down);
587 vat_json_object_add_uint(node, "link_up_down", mp->link_up_down);
588 vat_json_object_add_uint(node, "link_duplex", mp->link_duplex);
589 vat_json_object_add_uint(node, "link_speed", mp->link_speed);
590 vat_json_object_add_uint(node, "sub_id", ntohl(mp->sub_id));
591 vat_json_object_add_uint(node, "sub_dot1ad", mp->sub_dot1ad);
592 vat_json_object_add_uint(node, "sub_number_of_tags", mp->sub_number_of_tags);
593 vat_json_object_add_uint(node, "sub_outer_vlan_id", ntohs(mp->sub_outer_vlan_id));
594 vat_json_object_add_uint(node, "sub_inner_vlan_id", ntohs(mp->sub_inner_vlan_id));
595 vat_json_object_add_uint(node, "sub_exact_match", mp->sub_exact_match);
596 vat_json_object_add_uint(node, "sub_default", mp->sub_default);
597 vat_json_object_add_uint(node, "sub_outer_vlan_id_any", mp->sub_outer_vlan_id_any);
598 vat_json_object_add_uint(node, "sub_inner_vlan_id_any", mp->sub_inner_vlan_id_any);
599 vat_json_object_add_uint(node, "vtr_op", ntohl(mp->vtr_op));
600 vat_json_object_add_uint(node, "vtr_push_dot1q", ntohl(mp->vtr_push_dot1q));
601 vat_json_object_add_uint(node, "vtr_tag1", ntohl(mp->vtr_tag1));
602 vat_json_object_add_uint(node, "vtr_tag2", ntohl(mp->vtr_tag2));
605 static void vl_api_sw_interface_set_flags_t_handler
606 (vl_api_sw_interface_set_flags_t * mp)
608 vat_main_t * vam = &vat_main;
609 if (vam->interface_event_display)
610 errmsg ("interface flags: sw_if_index %d %s %s\n",
611 ntohl(mp->sw_if_index),
612 mp->admin_up_down ? "admin-up" : "admin-down",
613 mp->link_up_down ? "link-up" : "link-down");
616 static void vl_api_sw_interface_set_flags_t_handler_json
617 (vl_api_sw_interface_set_flags_t * mp)
619 /* JSON output not supported */
622 static void vl_api_cli_reply_t_handler
623 (vl_api_cli_reply_t * mp)
625 vat_main_t * vam = &vat_main;
626 i32 retval = ntohl(mp->retval);
628 vam->retval = retval;
629 vam->shmem_result = (u8 *) mp->reply_in_shmem;
630 vam->result_ready = 1;
633 static void vl_api_cli_reply_t_handler_json
634 (vl_api_cli_reply_t * mp)
636 vat_main_t * vam = &vat_main;
637 vat_json_node_t node;
639 vat_json_init_object(&node);
640 vat_json_object_add_int(&node, "retval", ntohl(mp->retval));
641 vat_json_object_add_uint(&node, "reply_in_shmem", ntohl(mp->reply_in_shmem));
643 vat_json_print(vam->ofp, &node);
644 vat_json_free(&node);
646 vam->retval = ntohl(mp->retval);
647 vam->result_ready = 1;
650 static void vl_api_classify_add_del_table_reply_t_handler
651 (vl_api_classify_add_del_table_reply_t * mp)
653 vat_main_t * vam = &vat_main;
654 i32 retval = ntohl(mp->retval);
655 if (vam->async_mode) {
656 vam->async_errors += (retval < 0);
658 vam->retval = retval;
659 vam->result_ready = 1;
661 ((mp->new_table_index != 0xFFFFFFFF) ||
662 (mp->skip_n_vectors != 0xFFFFFFFF) ||
663 (mp->match_n_vectors != 0xFFFFFFFF)))
665 * Note: this is just barely thread-safe, depends on
666 * the main thread spinning waiting for an answer...
668 errmsg ("new index %d, skip_n_vectors %d, match_n_vectors %d\n",
669 ntohl(mp->new_table_index),
670 ntohl(mp->skip_n_vectors), ntohl(mp->match_n_vectors));
674 static void vl_api_classify_add_del_table_reply_t_handler_json
675 (vl_api_classify_add_del_table_reply_t * mp)
677 vat_main_t * vam = &vat_main;
678 vat_json_node_t node;
680 vat_json_init_object(&node);
681 vat_json_object_add_int(&node, "retval", ntohl(mp->retval));
682 vat_json_object_add_uint(&node, "new_table_index", ntohl(mp->new_table_index));
683 vat_json_object_add_uint(&node, "skip_n_vectors", ntohl(mp->skip_n_vectors));
684 vat_json_object_add_uint(&node, "match_n_vectors", ntohl(mp->match_n_vectors));
686 vat_json_print(vam->ofp, &node);
687 vat_json_free(&node);
689 vam->retval = ntohl(mp->retval);
690 vam->result_ready = 1;
693 static void vl_api_get_node_index_reply_t_handler
694 (vl_api_get_node_index_reply_t * mp)
696 vat_main_t * vam = &vat_main;
697 i32 retval = ntohl(mp->retval);
698 if (vam->async_mode) {
699 vam->async_errors += (retval < 0);
701 vam->retval = retval;
702 vam->result_ready = 1;
704 errmsg ("node index %d\n", ntohl(mp->node_index));
708 static void vl_api_get_node_index_reply_t_handler_json
709 (vl_api_get_node_index_reply_t * mp)
711 vat_main_t * vam = &vat_main;
712 vat_json_node_t node;
714 vat_json_init_object(&node);
715 vat_json_object_add_int(&node, "retval", ntohl(mp->retval));
716 vat_json_object_add_uint(&node, "node_index", ntohl(mp->node_index));
718 vat_json_print(vam->ofp, &node);
719 vat_json_free(&node);
721 vam->retval = ntohl(mp->retval);
722 vam->result_ready = 1;
725 static void vl_api_add_node_next_reply_t_handler
726 (vl_api_add_node_next_reply_t * mp)
728 vat_main_t * vam = &vat_main;
729 i32 retval = ntohl(mp->retval);
730 if (vam->async_mode) {
731 vam->async_errors += (retval < 0);
733 vam->retval = retval;
734 vam->result_ready = 1;
736 errmsg ("next index %d\n", ntohl(mp->next_index));
740 static void vl_api_add_node_next_reply_t_handler_json
741 (vl_api_add_node_next_reply_t * mp)
743 vat_main_t * vam = &vat_main;
744 vat_json_node_t node;
746 vat_json_init_object(&node);
747 vat_json_object_add_int(&node, "retval", ntohl(mp->retval));
748 vat_json_object_add_uint(&node, "next_index", ntohl(mp->next_index));
750 vat_json_print(vam->ofp, &node);
751 vat_json_free(&node);
753 vam->retval = ntohl(mp->retval);
754 vam->result_ready = 1;
757 static void vl_api_mpls_gre_add_del_tunnel_reply_t_handler
758 (vl_api_mpls_gre_add_del_tunnel_reply_t * mp)
760 vat_main_t * vam = &vat_main;
761 i32 retval = ntohl(mp->retval);
762 u32 sw_if_index = ntohl(mp->tunnel_sw_if_index);
764 if (retval >= 0 && sw_if_index != (u32)~0) {
765 errmsg ("tunnel_sw_if_index %d\n", sw_if_index);
767 vam->retval = retval;
768 vam->result_ready = 1;
771 static void vl_api_mpls_gre_add_del_tunnel_reply_t_handler_json
772 (vl_api_mpls_gre_add_del_tunnel_reply_t * mp)
774 vat_main_t * vam = &vat_main;
775 vat_json_node_t node;
777 vat_json_init_object(&node);
778 vat_json_object_add_int(&node, "retval", ntohl(mp->retval));
779 vat_json_object_add_uint(&node, "tunnel_sw_if_index", ntohl(mp->tunnel_sw_if_index));
781 vat_json_print(vam->ofp, &node);
782 vat_json_free(&node);
784 vam->retval = ntohl(mp->retval);
785 vam->result_ready = 1;
788 static void vl_api_nsh_gre_add_del_tunnel_reply_t_handler
789 (vl_api_nsh_gre_add_del_tunnel_reply_t * mp)
791 vat_main_t * vam = &vat_main;
792 i32 retval = ntohl(mp->retval);
793 u32 sw_if_index = ntohl(mp->sw_if_index);
795 if (retval >= 0 && sw_if_index != (u32)~0) {
796 errmsg ("sw_if_index %d\n", ntohl(mp->sw_if_index));
798 vam->retval = retval;
799 vam->result_ready = 1;
802 static void vl_api_nsh_gre_add_del_tunnel_reply_t_handler_json
803 (vl_api_nsh_gre_add_del_tunnel_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, "sw_if_index", ntohl(mp->sw_if_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_nsh_vxlan_gpe_add_del_tunnel_reply_t_handler
820 (vl_api_nsh_vxlan_gpe_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->sw_if_index);
826 if (retval >= 0 && sw_if_index != (u32)~0) {
827 errmsg ("sw_if_index %d\n", ntohl(mp->sw_if_index));
829 vam->retval = retval;
830 vam->result_ready = 1;
833 static void vl_api_nsh_vxlan_gpe_add_del_tunnel_reply_t_handler_json
834 (vl_api_nsh_vxlan_gpe_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, "sw_if_index", ntohl(mp->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_lisp_gpe_add_del_tunnel_reply_t_handler
851 (vl_api_lisp_gpe_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_lisp_gpe_add_del_tunnel_reply_t_handler_json
865 (vl_api_lisp_gpe_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_show_version_reply_t_handler
882 (vl_api_show_version_reply_t * mp)
884 vat_main_t * vam = &vat_main;
885 i32 retval = ntohl(mp->retval);
888 errmsg (" program: %s\n", mp->program);
889 errmsg (" version: %s\n", mp->version);
890 errmsg (" build date: %s\n", mp->build_date);
891 errmsg ("build directory: %s\n", mp->build_directory);
893 vam->retval = retval;
894 vam->result_ready = 1;
897 static void vl_api_show_version_reply_t_handler_json
898 (vl_api_show_version_reply_t * mp)
900 vat_main_t * vam = &vat_main;
901 vat_json_node_t node;
903 vat_json_init_object(&node);
904 vat_json_object_add_int(&node, "retval", ntohl(mp->retval));
905 vat_json_object_add_string_copy(&node, "program", mp->program);
906 vat_json_object_add_string_copy(&node, "version", mp->version);
907 vat_json_object_add_string_copy(&node, "build_date", mp->build_date);
908 vat_json_object_add_string_copy(&node, "build_directory", mp->build_directory);
910 vat_json_print(vam->ofp, &node);
911 vat_json_free(&node);
913 vam->retval = ntohl(mp->retval);
914 vam->result_ready = 1;
917 static void vl_api_ip4_arp_event_t_handler
918 (vl_api_ip4_arp_event_t * mp)
920 vat_main_t * vam = &vat_main;
921 errmsg ("arp event: address %U new mac %U sw_if_index %d\n",
922 format_ip4_address, &mp->address,
923 format_ethernet_address, mp->new_mac, mp->sw_if_index);
926 static void vl_api_ip4_arp_event_t_handler_json
927 (vl_api_ip4_arp_event_t * mp)
929 /* JSON output not supported */
933 * Special-case: build the bridge domain table, maintain
934 * the next bd id vbl.
936 static void vl_api_bridge_domain_details_t_handler
937 (vl_api_bridge_domain_details_t * mp)
939 vat_main_t * vam = &vat_main;
940 u32 n_sw_ifs = ntohl (mp->n_sw_ifs);
942 fformat (vam->ofp, "\n%-3s %-3s %-3s %-3s %-3s %-3s\n",
943 " ID", "LRN", "FWD", "FLD", "BVI", "#IF");
945 fformat (vam->ofp, "%3d %3d %3d %3d %3d %3d\n",
946 ntohl (mp->bd_id), mp->learn, mp->forward,
947 mp->flood, ntohl (mp->bvi_sw_if_index), n_sw_ifs);
950 fformat (vam->ofp, "\n\n%s %s %s\n", "sw_if_index", "SHG",
954 static void vl_api_bridge_domain_details_t_handler_json
955 (vl_api_bridge_domain_details_t * mp)
957 vat_main_t * vam = &vat_main;
958 vat_json_node_t *node, *array = NULL;
960 if (VAT_JSON_ARRAY != vam->json_tree.type) {
961 ASSERT(VAT_JSON_NONE == vam->json_tree.type);
962 vat_json_init_array(&vam->json_tree);
964 node = vat_json_array_add(&vam->json_tree);
966 vat_json_init_object(node);
967 vat_json_object_add_uint(node, "bd_id", ntohl(mp->bd_id));
968 vat_json_object_add_uint(node, "flood", mp->flood);
969 vat_json_object_add_uint(node, "forward", mp->forward);
970 vat_json_object_add_uint(node, "learn", mp->learn);
971 vat_json_object_add_uint(node, "bvi_sw_if_index", ntohl(mp->bvi_sw_if_index));
972 vat_json_object_add_uint(node, "n_sw_ifs", ntohl(mp->n_sw_ifs));
973 array = vat_json_object_add(node, "sw_if");
974 vat_json_init_array(array);
978 * Special-case: build the bridge domain sw if table.
980 static void vl_api_bridge_domain_sw_if_details_t_handler
981 (vl_api_bridge_domain_sw_if_details_t * mp)
983 vat_main_t * vam = &vat_main;
988 sw_if_index = ntohl (mp->sw_if_index);
989 hash_foreach_pair (p, vam->sw_if_index_by_interface_name,
991 if ((u32) p->value[0] == sw_if_index) {
992 sw_if_name = (u8 *)(p->key);
997 fformat (vam->ofp, "%7d %3d %s", sw_if_index,
998 mp->shg, sw_if_name ? (char *)sw_if_name :
999 "sw_if_index not found!");
1002 static void vl_api_bridge_domain_sw_if_details_t_handler_json
1003 (vl_api_bridge_domain_sw_if_details_t * mp)
1005 vat_main_t * vam = &vat_main;
1006 vat_json_node_t *node = NULL;
1007 uword last_index = 0;
1009 ASSERT(VAT_JSON_ARRAY == vam->json_tree.type);
1010 ASSERT(vec_len(vam->json_tree.array) >= 1);
1011 last_index = vec_len(vam->json_tree.array) - 1;
1012 node = &vam->json_tree.array[last_index];
1013 node = vat_json_object_get_element(node, "sw_if");
1014 ASSERT(NULL != node);
1015 node = vat_json_array_add(node);
1017 vat_json_init_object(node);
1018 vat_json_object_add_uint(node, "bd_id", ntohl(mp->bd_id));
1019 vat_json_object_add_uint(node, "sw_if_index", ntohl(mp->sw_if_index));
1020 vat_json_object_add_uint(node, "shg", mp->shg);
1023 static void vl_api_control_ping_reply_t_handler
1024 (vl_api_control_ping_reply_t * mp)
1026 vat_main_t * vam = &vat_main;
1027 i32 retval = ntohl(mp->retval);
1028 if (vam->async_mode) {
1029 vam->async_errors += (retval < 0);
1031 vam->retval = retval;
1032 vam->result_ready = 1;
1036 static void vl_api_control_ping_reply_t_handler_json
1037 (vl_api_control_ping_reply_t * mp)
1039 vat_main_t * vam = &vat_main;
1040 i32 retval = ntohl(mp->retval);
1042 if (VAT_JSON_NONE != vam->json_tree.type) {
1043 vat_json_print(vam->ofp, &vam->json_tree);
1044 vat_json_free(&vam->json_tree);
1045 vam->json_tree.type = VAT_JSON_NONE;
1048 vat_json_init_array(&vam->json_tree);
1049 vat_json_print(vam->ofp, &vam->json_tree);
1050 vam->json_tree.type = VAT_JSON_NONE;
1053 vam->retval = retval;
1054 vam->result_ready = 1;
1057 static void vl_api_l2_flags_reply_t_handler
1058 (vl_api_l2_flags_reply_t * mp)
1060 vat_main_t * vam = &vat_main;
1061 i32 retval = ntohl(mp->retval);
1062 if (vam->async_mode) {
1063 vam->async_errors += (retval < 0);
1065 vam->retval = retval;
1066 vam->result_ready = 1;
1070 static void vl_api_l2_flags_reply_t_handler_json
1071 (vl_api_l2_flags_reply_t * mp)
1073 vat_main_t * vam = &vat_main;
1074 vat_json_node_t node;
1076 vat_json_init_object(&node);
1077 vat_json_object_add_int(&node, "retval", ntohl(mp->retval));
1078 vat_json_object_add_uint(&node, "resulting_feature_bitmap", ntohl(mp->resulting_feature_bitmap));
1080 vat_json_print(vam->ofp, &node);
1081 vat_json_free(&node);
1083 vam->retval = ntohl(mp->retval);
1084 vam->result_ready = 1;
1087 static void vl_api_bridge_flags_reply_t_handler
1088 (vl_api_bridge_flags_reply_t * mp)
1090 vat_main_t * vam = &vat_main;
1091 i32 retval = ntohl(mp->retval);
1092 if (vam->async_mode) {
1093 vam->async_errors += (retval < 0);
1095 vam->retval = retval;
1096 vam->result_ready = 1;
1100 static void vl_api_bridge_flags_reply_t_handler_json
1101 (vl_api_bridge_flags_reply_t * mp)
1103 vat_main_t * vam = &vat_main;
1104 vat_json_node_t node;
1106 vat_json_init_object(&node);
1107 vat_json_object_add_int(&node, "retval", ntohl(mp->retval));
1108 vat_json_object_add_uint(&node, "resulting_feature_bitmap", ntohl(mp->resulting_feature_bitmap));
1110 vat_json_print(vam->ofp, &node);
1111 vat_json_free(&node);
1113 vam->retval = ntohl(mp->retval);
1114 vam->result_ready = 1;
1117 static void vl_api_tap_connect_reply_t_handler
1118 (vl_api_tap_connect_reply_t * mp)
1120 vat_main_t * vam = &vat_main;
1121 i32 retval = ntohl(mp->retval);
1122 if (vam->async_mode) {
1123 vam->async_errors += (retval < 0);
1125 vam->retval = retval;
1126 vam->result_ready = 1;
1130 static void vl_api_tap_connect_reply_t_handler_json
1131 (vl_api_tap_connect_reply_t * mp)
1133 vat_main_t * vam = &vat_main;
1134 vat_json_node_t node;
1136 vat_json_init_object(&node);
1137 vat_json_object_add_int(&node, "retval", ntohl(mp->retval));
1138 vat_json_object_add_uint(&node, "sw_if_index", ntohl(mp->sw_if_index));
1140 vat_json_print(vam->ofp, &node);
1141 vat_json_free(&node);
1143 vam->retval = ntohl(mp->retval);
1144 vam->result_ready = 1;
1147 static void vl_api_tap_modify_reply_t_handler
1148 (vl_api_tap_modify_reply_t * mp)
1150 vat_main_t * vam = &vat_main;
1151 i32 retval = ntohl(mp->retval);
1152 if (vam->async_mode) {
1153 vam->async_errors += (retval < 0);
1155 vam->retval = retval;
1156 vam->result_ready = 1;
1160 static void vl_api_tap_modify_reply_t_handler_json
1161 (vl_api_tap_modify_reply_t * mp)
1163 vat_main_t * vam = &vat_main;
1164 vat_json_node_t node;
1166 vat_json_init_object(&node);
1167 vat_json_object_add_int(&node, "retval", ntohl(mp->retval));
1168 vat_json_object_add_uint(&node, "sw_if_index", ntohl(mp->sw_if_index));
1170 vat_json_print(vam->ofp, &node);
1171 vat_json_free(&node);
1173 vam->retval = ntohl(mp->retval);
1174 vam->result_ready = 1;
1177 static void vl_api_tap_delete_reply_t_handler
1178 (vl_api_tap_delete_reply_t * mp)
1180 vat_main_t * vam = &vat_main;
1181 i32 retval = ntohl(mp->retval);
1182 if (vam->async_mode) {
1183 vam->async_errors += (retval < 0);
1185 vam->retval = retval;
1186 vam->result_ready = 1;
1190 static void vl_api_tap_delete_reply_t_handler_json
1191 (vl_api_tap_delete_reply_t * mp)
1193 vat_main_t * vam = &vat_main;
1194 vat_json_node_t node;
1196 vat_json_init_object(&node);
1197 vat_json_object_add_int(&node, "retval", ntohl(mp->retval));
1199 vat_json_print(vam->ofp, &node);
1200 vat_json_free(&node);
1202 vam->retval = ntohl(mp->retval);
1203 vam->result_ready = 1;
1206 static void vl_api_mpls_ethernet_add_del_tunnel_reply_t_handler
1207 (vl_api_mpls_ethernet_add_del_tunnel_reply_t * mp)
1209 vat_main_t * vam = &vat_main;
1210 i32 retval = ntohl(mp->retval);
1211 if (vam->async_mode) {
1212 vam->async_errors += (retval < 0);
1214 vam->retval = retval;
1215 vam->result_ready = 1;
1219 static void vl_api_mpls_ethernet_add_del_tunnel_reply_t_handler_json
1220 (vl_api_mpls_ethernet_add_del_tunnel_reply_t * mp)
1222 vat_main_t * vam = &vat_main;
1223 vat_json_node_t node;
1225 vat_json_init_object(&node);
1226 vat_json_object_add_int(&node, "retval", ntohl(mp->retval));
1227 vat_json_object_add_uint(&node, "tunnel_sw_if_index", ntohl(mp->tunnel_sw_if_index));
1229 vat_json_print(vam->ofp, &node);
1230 vat_json_free(&node);
1232 vam->retval = ntohl(mp->retval);
1233 vam->result_ready = 1;
1236 static void vl_api_l2tpv3_create_tunnel_reply_t_handler
1237 (vl_api_l2tpv3_create_tunnel_reply_t * mp)
1239 vat_main_t * vam = &vat_main;
1240 i32 retval = ntohl(mp->retval);
1241 if (vam->async_mode) {
1242 vam->async_errors += (retval < 0);
1244 vam->retval = retval;
1245 vam->result_ready = 1;
1249 static void vl_api_l2tpv3_create_tunnel_reply_t_handler_json
1250 (vl_api_l2tpv3_create_tunnel_reply_t * mp)
1252 vat_main_t * vam = &vat_main;
1253 vat_json_node_t node;
1255 vat_json_init_object(&node);
1256 vat_json_object_add_int(&node, "retval", ntohl(mp->retval));
1257 vat_json_object_add_uint(&node, "sw_if_index", ntohl(mp->sw_if_index));
1259 vat_json_print(vam->ofp, &node);
1260 vat_json_free(&node);
1262 vam->retval = ntohl(mp->retval);
1263 vam->result_ready = 1;
1266 static void vl_api_vxlan_add_del_tunnel_reply_t_handler
1267 (vl_api_vxlan_add_del_tunnel_reply_t * mp)
1269 vat_main_t * vam = &vat_main;
1270 i32 retval = ntohl(mp->retval);
1271 if (vam->async_mode) {
1272 vam->async_errors += (retval < 0);
1274 vam->retval = retval;
1275 vam->result_ready = 1;
1279 static void vl_api_vxlan_add_del_tunnel_reply_t_handler_json
1280 (vl_api_vxlan_add_del_tunnel_reply_t * mp)
1282 vat_main_t * vam = &vat_main;
1283 vat_json_node_t node;
1285 vat_json_init_object(&node);
1286 vat_json_object_add_int(&node, "retval", ntohl(mp->retval));
1287 vat_json_object_add_uint(&node, "sw_if_index", ntohl(mp->sw_if_index));
1289 vat_json_print(vam->ofp, &node);
1290 vat_json_free(&node);
1292 vam->retval = ntohl(mp->retval);
1293 vam->result_ready = 1;
1296 static void vl_api_create_vhost_user_if_reply_t_handler
1297 (vl_api_create_vhost_user_if_reply_t * mp)
1299 vat_main_t * vam = &vat_main;
1300 i32 retval = ntohl(mp->retval);
1301 if (vam->async_mode) {
1302 vam->async_errors += (retval < 0);
1304 vam->retval = retval;
1305 vam->result_ready = 1;
1309 static void vl_api_create_vhost_user_if_reply_t_handler_json
1310 (vl_api_create_vhost_user_if_reply_t * mp)
1312 vat_main_t * vam = &vat_main;
1313 vat_json_node_t node;
1315 vat_json_init_object(&node);
1316 vat_json_object_add_int(&node, "retval", ntohl(mp->retval));
1317 vat_json_object_add_uint(&node, "sw_if_index", ntohl(mp->sw_if_index));
1319 vat_json_print(vam->ofp, &node);
1320 vat_json_free(&node);
1322 vam->retval = ntohl(mp->retval);
1323 vam->result_ready = 1;
1326 static void vl_api_ip_address_details_t_handler
1327 (vl_api_ip_address_details_t * mp)
1329 vat_main_t * vam = &vat_main;
1330 static ip_address_details_t empty_ip_address_details = {{0}};
1331 ip_address_details_t * address = NULL;
1332 ip_details_t * current_ip_details = NULL;
1333 ip_details_t * details = NULL;
1335 details = vam->ip_details_by_sw_if_index[vam->is_ipv6];
1337 if (!details || vam->current_sw_if_index >= vec_len(details)
1338 || !details[vam->current_sw_if_index].present) {
1339 errmsg ("ip address details arrived but not stored\n");
1340 errmsg ("ip_dump should be called first\n");
1344 current_ip_details = vec_elt_at_index(details,
1345 vam->current_sw_if_index);
1347 #define addresses (current_ip_details->addr)
1349 vec_validate_init_empty(addresses, vec_len(addresses),
1350 empty_ip_address_details);
1352 address = vec_elt_at_index(addresses, vec_len(addresses) - 1);
1354 memcpy(&address->ip, &mp->ip, sizeof(address->ip));
1355 address->prefix_length = mp->prefix_length;
1359 static void vl_api_ip_address_details_t_handler_json
1360 (vl_api_ip_address_details_t * mp)
1362 vat_main_t * vam = &vat_main;
1363 vat_json_node_t *node = NULL;
1364 struct in6_addr ip6;
1367 if (VAT_JSON_ARRAY != vam->json_tree.type) {
1368 ASSERT(VAT_JSON_NONE == vam->json_tree.type);
1369 vat_json_init_array(&vam->json_tree);
1371 node = vat_json_array_add(&vam->json_tree);
1373 vat_json_init_object(node);
1375 memcpy(&ip6, mp->ip, sizeof(ip6));
1376 vat_json_object_add_ip6(node, "ip", ip6);
1378 memcpy(&ip4, mp->ip, sizeof(ip4));
1379 vat_json_object_add_ip4(node, "ip", ip4);
1381 vat_json_object_add_uint(node, "prefix_length", mp->prefix_length);
1384 static void vl_api_ip_details_t_handler (vl_api_ip_details_t * mp)
1386 vat_main_t * vam = &vat_main;
1387 static ip_details_t empty_ip_details = {0};
1388 ip_details_t * ip = NULL;
1389 u32 sw_if_index = ~0;
1391 sw_if_index = ntohl(mp->sw_if_index);
1393 vec_validate_init_empty(vam->ip_details_by_sw_if_index[vam->is_ipv6],
1394 sw_if_index, empty_ip_details);
1396 ip = vec_elt_at_index(vam->ip_details_by_sw_if_index[vam->is_ipv6],
1402 static void vl_api_ip_details_t_handler_json (vl_api_ip_details_t * mp)
1404 vat_main_t * vam = &vat_main;
1406 if (VAT_JSON_ARRAY != vam->json_tree.type) {
1407 ASSERT(VAT_JSON_NONE == vam->json_tree.type);
1408 vat_json_init_array(&vam->json_tree);
1410 vat_json_array_add_uint(&vam->json_tree, clib_net_to_host_u32(mp->sw_if_index));
1413 static void vl_api_map_domain_details_t_handler_json
1414 (vl_api_map_domain_details_t * mp)
1416 vat_json_node_t * node = NULL;
1417 vat_main_t * vam = &vat_main;
1418 struct in6_addr ip6;
1421 if (VAT_JSON_ARRAY != vam->json_tree.type) {
1422 ASSERT(VAT_JSON_NONE == vam->json_tree.type);
1423 vat_json_init_array(&vam->json_tree);
1426 node = vat_json_array_add(&vam->json_tree);
1427 vat_json_init_object(node);
1429 vat_json_object_add_uint(node, "domain_index", clib_net_to_host_u32(mp->domain_index));
1430 memcpy(&ip6, mp->ip6_prefix, sizeof(ip6));
1431 vat_json_object_add_ip6(node, "ip6_prefix", ip6);
1432 memcpy(&ip4, mp->ip4_prefix, sizeof(ip4));
1433 vat_json_object_add_ip4(node, "ip4_prefix", ip4);
1434 memcpy(&ip6, mp->ip6_src, sizeof(ip6));
1435 vat_json_object_add_ip6(node, "ip6_src", ip6);
1436 vat_json_object_add_int(node, "ip6_prefix_len", mp->ip6_prefix_len);
1437 vat_json_object_add_int(node, "ip4_prefix_len", mp->ip4_prefix_len);
1438 vat_json_object_add_int(node, "ip6_src_len", mp->ip6_src_len);
1439 vat_json_object_add_int(node, "ea_bits_len", mp->ea_bits_len);
1440 vat_json_object_add_int(node, "psid_offset", mp->psid_offset);
1441 vat_json_object_add_int(node, "psid_length", mp->psid_length);
1442 vat_json_object_add_uint(node, "flags", mp->flags);
1443 vat_json_object_add_uint(node, "mtu", clib_net_to_host_u16(mp->mtu));
1444 vat_json_object_add_int(node, "is_translation", mp->is_translation);
1447 static void vl_api_map_domain_details_t_handler
1448 (vl_api_map_domain_details_t * mp)
1450 vat_main_t * vam = &vat_main;
1452 if (mp->is_translation) {
1453 fformat(vam->ofp, "* %U/%d (ipv4-prefix) %U/%d (ipv6-prefix) %U/%d (ip6-src) index: %u\n",
1454 format_ip4_address, mp->ip4_prefix, mp->ip4_prefix_len,
1455 format_ip6_address, mp->ip6_prefix, mp->ip6_prefix_len,
1456 format_ip6_address, mp->ip6_src, mp->ip6_src_len, clib_net_to_host_u32(mp->domain_index));
1458 fformat(vam->ofp, "* %U/%d (ipv4-prefix) %U/%d (ipv6-prefix) %U (ip6-src) index: %u\n",
1459 format_ip4_address, mp->ip4_prefix, mp->ip4_prefix_len,
1460 format_ip6_address, mp->ip6_prefix, mp->ip6_prefix_len,
1461 format_ip6_address, mp->ip6_src, clib_net_to_host_u32(mp->domain_index));
1463 fformat(vam->ofp, " ea-len %d psid-offset %d psid-len %d mtu %d %s\n",
1464 mp->ea_bits_len, mp->psid_offset, mp->psid_length, mp->mtu, mp->is_translation? "map-t":"");
1467 static void vl_api_map_rule_details_t_handler_json
1468 (vl_api_map_rule_details_t * mp)
1470 struct in6_addr ip6;
1471 vat_json_node_t * node = NULL;
1472 vat_main_t * vam = &vat_main;
1474 if (VAT_JSON_ARRAY != vam->json_tree.type) {
1475 ASSERT(VAT_JSON_NONE == vam->json_tree.type);
1476 vat_json_init_array(&vam->json_tree);
1479 node = vat_json_array_add(&vam->json_tree);
1480 vat_json_init_object(node);
1482 vat_json_object_add_uint(node, "psid", clib_net_to_host_u16(mp->psid));
1483 memcpy(&ip6, mp->ip6_dst, sizeof(ip6));
1484 vat_json_object_add_ip6(node, "ip6_dst", ip6);
1487 static void vl_api_map_rule_details_t_handler
1488 (vl_api_map_rule_details_t * mp)
1490 vat_main_t * vam = &vat_main;
1491 fformat(vam->ofp, " %d (psid) %U (ip6-dst)\n", clib_net_to_host_u16(mp->psid),
1492 format_ip6_address, mp->ip6_dst);
1495 static void vl_api_dhcp_compl_event_t_handler
1496 (vl_api_dhcp_compl_event_t * mp)
1498 vat_main_t * vam = &vat_main;
1499 errmsg ("DHCP compl event: pid %d %s hostname %s host_addr %U "
1500 "router_addr %U host_mac %U\n",
1501 mp->pid, mp->is_ipv6 ? "ipv6":"ipv4", mp->hostname,
1502 format_ip4_address, &mp->host_address,
1503 format_ip4_address, &mp->router_address,
1504 format_ethernet_address, mp->host_mac);
1507 static void vl_api_dhcp_compl_event_t_handler_json
1508 (vl_api_dhcp_compl_event_t * mp)
1510 /* JSON output not supported */
1513 static void set_simple_interface_counter (u8 vnet_counter_type, u32 sw_if_index,
1516 vat_main_t * vam = &vat_main;
1517 static u64 default_counter = 0;
1519 vec_validate_init_empty(vam->simple_interface_counters, vnet_counter_type, NULL);
1520 vec_validate_init_empty(vam->simple_interface_counters[vnet_counter_type],
1521 sw_if_index, default_counter);
1522 vam->simple_interface_counters[vnet_counter_type][sw_if_index] = counter;
1525 static void set_combined_interface_counter (u8 vnet_counter_type, u32 sw_if_index,
1526 interface_counter_t counter)
1528 vat_main_t * vam = &vat_main;
1529 static interface_counter_t default_counter = {0, };
1531 vec_validate_init_empty(vam->combined_interface_counters, vnet_counter_type, NULL);
1532 vec_validate_init_empty(vam->combined_interface_counters[vnet_counter_type],
1533 sw_if_index, default_counter);
1534 vam->combined_interface_counters[vnet_counter_type][sw_if_index] = counter;
1537 static void vl_api_vnet_interface_counters_t_handler
1538 (vl_api_vnet_interface_counters_t *mp)
1543 static void vl_api_vnet_interface_counters_t_handler_json
1544 (vl_api_vnet_interface_counters_t *mp)
1546 interface_counter_t counter;
1551 u32 first_sw_if_index;
1554 count = ntohl(mp->count);
1555 first_sw_if_index = ntohl(mp->first_sw_if_index);
1557 if (!mp->is_combined) {
1558 v_packets = (u64*)&mp->data;
1559 for (i = 0; i < count; i++) {
1560 packets = clib_net_to_host_u64(clib_mem_unaligned(v_packets, u64));
1561 set_simple_interface_counter(mp->vnet_counter_type,
1562 first_sw_if_index + i, packets);
1566 v = (vlib_counter_t*)&mp->data;
1567 for (i = 0; i < count; i++) {
1568 counter.packets = clib_net_to_host_u64(
1569 clib_mem_unaligned(&v->packets, u64));
1570 counter.bytes = clib_net_to_host_u64(
1571 clib_mem_unaligned(&v->bytes, u64));
1572 set_combined_interface_counter(mp->vnet_counter_type,
1573 first_sw_if_index + i, counter);
1579 static u32 ip4_fib_counters_get_vrf_index_by_vrf_id (u32 vrf_id)
1581 vat_main_t * vam = &vat_main;
1584 for (i = 0; i < vec_len(vam->ip4_fib_counters_vrf_id_by_index); i++) {
1585 if (vam->ip4_fib_counters_vrf_id_by_index[i] == vrf_id) {
1592 static u32 ip6_fib_counters_get_vrf_index_by_vrf_id (u32 vrf_id)
1594 vat_main_t * vam = &vat_main;
1597 for (i = 0; i < vec_len(vam->ip6_fib_counters_vrf_id_by_index); i++) {
1598 if (vam->ip6_fib_counters_vrf_id_by_index[i] == vrf_id) {
1605 static void vl_api_vnet_ip4_fib_counters_t_handler
1606 (vl_api_vnet_ip4_fib_counters_t *mp)
1611 static void vl_api_vnet_ip4_fib_counters_t_handler_json
1612 (vl_api_vnet_ip4_fib_counters_t *mp)
1614 vat_main_t * vam = &vat_main;
1615 vl_api_ip4_fib_counter_t *v;
1616 ip4_fib_counter_t *counter;
1623 vrf_id = ntohl(mp->vrf_id);
1624 vrf_index = ip4_fib_counters_get_vrf_index_by_vrf_id(vrf_id);
1625 if (~0 == vrf_index) {
1626 vrf_index = vec_len(vam->ip4_fib_counters_vrf_id_by_index);
1627 vec_validate(vam->ip4_fib_counters_vrf_id_by_index, vrf_index);
1628 vam->ip4_fib_counters_vrf_id_by_index[vrf_index] = vrf_id;
1629 vec_validate(vam->ip4_fib_counters, vrf_index);
1630 vam->ip4_fib_counters[vrf_index] = NULL;
1633 vec_free(vam->ip4_fib_counters[vrf_index]);
1634 v = (vl_api_ip4_fib_counter_t*)&mp->c;
1635 count = ntohl(mp->count);
1636 for (i = 0; i < count; i++) {
1637 vec_validate(vam->ip4_fib_counters[vrf_index], i);
1638 counter = &vam->ip4_fib_counters[vrf_index][i];
1639 memcpy(&ip4, &v->address, sizeof(ip4));
1640 counter->address = ip4;
1641 counter->address_length = v->address_length;
1642 counter->packets = clib_net_to_host_u64(v->packets);
1643 counter->bytes = clib_net_to_host_u64(v->bytes);
1648 static void vl_api_vnet_ip6_fib_counters_t_handler
1649 (vl_api_vnet_ip6_fib_counters_t *mp)
1654 static void vl_api_vnet_ip6_fib_counters_t_handler_json
1655 (vl_api_vnet_ip6_fib_counters_t *mp)
1657 vat_main_t * vam = &vat_main;
1658 vl_api_ip6_fib_counter_t *v;
1659 ip6_fib_counter_t *counter;
1660 struct in6_addr ip6;
1666 vrf_id = ntohl(mp->vrf_id);
1667 vrf_index = ip6_fib_counters_get_vrf_index_by_vrf_id(vrf_id);
1668 if (~0 == vrf_index) {
1669 vrf_index = vec_len(vam->ip6_fib_counters_vrf_id_by_index);
1670 vec_validate(vam->ip6_fib_counters_vrf_id_by_index, vrf_index);
1671 vam->ip6_fib_counters_vrf_id_by_index[vrf_index] = vrf_id;
1672 vec_validate(vam->ip6_fib_counters, vrf_index);
1673 vam->ip6_fib_counters[vrf_index] = NULL;
1676 vec_free(vam->ip6_fib_counters[vrf_index]);
1677 v = (vl_api_ip6_fib_counter_t*)&mp->c;
1678 count = ntohl(mp->count);
1679 for (i = 0; i < count; i++) {
1680 vec_validate(vam->ip6_fib_counters[vrf_index], i);
1681 counter = &vam->ip6_fib_counters[vrf_index][i];
1682 memcpy(&ip6, &v->address, sizeof(ip6));
1683 counter->address = ip6;
1684 counter->address_length = v->address_length;
1685 counter->packets = clib_net_to_host_u64(v->packets);
1686 counter->bytes = clib_net_to_host_u64(v->bytes);
1691 static void vl_api_get_first_msg_id_reply_t_handler
1692 (vl_api_get_first_msg_id_reply_t * mp)
1694 vat_main_t * vam = &vat_main;
1695 i32 retval = ntohl(mp->retval);
1697 if (vam->async_mode) {
1698 vam->async_errors += (retval < 0);
1700 vam->retval = retval;
1701 vam->result_ready = 1;
1704 errmsg ("first message id %d\n", ntohs(mp->first_msg_id));
1708 static void vl_api_get_first_msg_id_reply_t_handler_json
1709 (vl_api_get_first_msg_id_reply_t * mp)
1711 vat_main_t * vam = &vat_main;
1712 vat_json_node_t node;
1714 vat_json_init_object(&node);
1715 vat_json_object_add_int(&node, "retval", ntohl(mp->retval));
1716 vat_json_object_add_uint(&node, "first_msg_id",
1717 (uint) ntohs(mp->first_msg_id));
1719 vat_json_print(vam->ofp, &node);
1720 vat_json_free(&node);
1722 vam->retval = ntohl(mp->retval);
1723 vam->result_ready = 1;
1726 #define vl_api_vnet_ip4_fib_counters_t_endian vl_noop_handler
1727 #define vl_api_vnet_ip4_fib_counters_t_print vl_noop_handler
1728 #define vl_api_vnet_ip6_fib_counters_t_endian vl_noop_handler
1729 #define vl_api_vnet_ip6_fib_counters_t_print vl_noop_handler
1732 * Generate boilerplate reply handlers, which
1733 * dig the return value out of the xxx_reply_t API message,
1734 * stick it into vam->retval, and set vam->result_ready
1736 * Could also do this by pointing N message decode slots at
1737 * a single function, but that could break in subtle ways.
1740 #define foreach_standard_reply_retval_handler \
1741 _(sw_interface_set_flags_reply) \
1742 _(sw_interface_add_del_address_reply) \
1743 _(sw_interface_set_table_reply) \
1744 _(sw_interface_set_vpath_reply) \
1745 _(sw_interface_set_l2_bridge_reply) \
1746 _(bridge_domain_add_del_reply) \
1747 _(sw_interface_set_l2_xconnect_reply) \
1748 _(l2fib_add_del_reply) \
1749 _(ip_add_del_route_reply) \
1750 _(proxy_arp_add_del_reply) \
1751 _(proxy_arp_intfc_enable_disable_reply) \
1752 _(mpls_add_del_encap_reply) \
1753 _(mpls_add_del_decap_reply) \
1754 _(mpls_ethernet_add_del_tunnel_2_reply) \
1755 _(sw_interface_set_unnumbered_reply) \
1756 _(ip_neighbor_add_del_reply) \
1757 _(reset_vrf_reply) \
1758 _(oam_add_del_reply) \
1759 _(reset_fib_reply) \
1760 _(dhcp_proxy_config_reply) \
1761 _(dhcp_proxy_config_2_reply) \
1762 _(dhcp_proxy_set_vss_reply) \
1763 _(dhcp_client_config_reply) \
1764 _(set_ip_flow_hash_reply) \
1765 _(sw_interface_ip6_enable_disable_reply) \
1766 _(sw_interface_ip6_set_link_local_address_reply) \
1767 _(sw_interface_ip6nd_ra_prefix_reply) \
1768 _(sw_interface_ip6nd_ra_config_reply) \
1769 _(set_arp_neighbor_limit_reply) \
1770 _(l2_patch_add_del_reply) \
1771 _(sr_tunnel_add_del_reply) \
1772 _(classify_add_del_session_reply) \
1773 _(classify_set_interface_ip_table_reply) \
1774 _(classify_set_interface_l2_tables_reply) \
1775 _(l2tpv3_set_tunnel_cookies_reply) \
1776 _(l2tpv3_interface_enable_disable_reply) \
1777 _(l2tpv3_set_lookup_key_reply) \
1778 _(l2_fib_clear_table_reply) \
1779 _(l2_interface_efp_filter_reply) \
1780 _(l2_interface_vlan_tag_rewrite_reply) \
1781 _(modify_vhost_user_if_reply) \
1782 _(delete_vhost_user_if_reply) \
1783 _(want_ip4_arp_events_reply) \
1784 _(input_acl_set_interface_reply) \
1785 _(ipsec_spd_add_del_reply) \
1786 _(ipsec_interface_add_del_spd_reply) \
1787 _(ipsec_spd_add_del_entry_reply) \
1788 _(ipsec_sad_add_del_entry_reply) \
1789 _(ipsec_sa_set_key_reply) \
1790 _(delete_loopback_reply) \
1791 _(bd_ip_mac_add_del_reply) \
1792 _(map_del_domain_reply) \
1793 _(map_add_del_rule_reply) \
1794 _(want_interface_events_reply) \
1795 _(want_stats_reply) \
1796 _(cop_interface_enable_disable_reply) \
1797 _(cop_whitelist_enable_disable_reply)
1800 static void vl_api_##n##_t_handler \
1801 (vl_api_##n##_t * mp) \
1803 vat_main_t * vam = &vat_main; \
1804 i32 retval = ntohl(mp->retval); \
1805 if (vam->async_mode) { \
1806 vam->async_errors += (retval < 0); \
1808 vam->retval = retval; \
1809 vam->result_ready = 1; \
1812 foreach_standard_reply_retval_handler;
1816 static void vl_api_##n##_t_handler_json \
1817 (vl_api_##n##_t * mp) \
1819 vat_main_t * vam = &vat_main; \
1820 vat_json_node_t node; \
1821 vat_json_init_object(&node); \
1822 vat_json_object_add_int(&node, "retval", ntohl(mp->retval)); \
1823 vat_json_print(vam->ofp, &node); \
1824 vam->retval = ntohl(mp->retval); \
1825 vam->result_ready = 1; \
1827 foreach_standard_reply_retval_handler;
1831 * Table of message reply handlers, must include boilerplate handlers
1835 #define foreach_vpe_api_reply_msg \
1836 _(CREATE_LOOPBACK_REPLY, create_loopback_reply) \
1837 _(SW_INTERFACE_DETAILS, sw_interface_details) \
1838 _(SW_INTERFACE_SET_FLAGS, sw_interface_set_flags) \
1839 _(SW_INTERFACE_SET_FLAGS_REPLY, sw_interface_set_flags_reply) \
1840 _(CONTROL_PING_REPLY, control_ping_reply) \
1841 _(CLI_REPLY, cli_reply) \
1842 _(SW_INTERFACE_ADD_DEL_ADDRESS_REPLY, \
1843 sw_interface_add_del_address_reply) \
1844 _(SW_INTERFACE_SET_TABLE_REPLY, sw_interface_set_table_reply) \
1845 _(SW_INTERFACE_SET_VPATH_REPLY, sw_interface_set_vpath_reply) \
1846 _(SW_INTERFACE_SET_L2_XCONNECT_REPLY, \
1847 sw_interface_set_l2_xconnect_reply) \
1848 _(SW_INTERFACE_SET_L2_BRIDGE_REPLY, \
1849 sw_interface_set_l2_bridge_reply) \
1850 _(BRIDGE_DOMAIN_ADD_DEL_REPLY, bridge_domain_add_del_reply) \
1851 _(BRIDGE_DOMAIN_DETAILS, bridge_domain_details) \
1852 _(BRIDGE_DOMAIN_SW_IF_DETAILS, bridge_domain_sw_if_details) \
1853 _(L2FIB_ADD_DEL_REPLY, l2fib_add_del_reply) \
1854 _(L2_FLAGS_REPLY, l2_flags_reply) \
1855 _(BRIDGE_FLAGS_REPLY, bridge_flags_reply) \
1856 _(TAP_CONNECT_REPLY, tap_connect_reply) \
1857 _(TAP_MODIFY_REPLY, tap_modify_reply) \
1858 _(TAP_DELETE_REPLY, tap_delete_reply) \
1859 _(SW_INTERFACE_TAP_DETAILS, sw_interface_tap_details) \
1860 _(IP_ADD_DEL_ROUTE_REPLY, ip_add_del_route_reply) \
1861 _(PROXY_ARP_ADD_DEL_REPLY, proxy_arp_add_del_reply) \
1862 _(PROXY_ARP_INTFC_ENABLE_DISABLE_REPLY, \
1863 proxy_arp_intfc_enable_disable_reply) \
1864 _(MPLS_ADD_DEL_ENCAP_REPLY, mpls_add_del_encap_reply) \
1865 _(MPLS_ADD_DEL_DECAP_REPLY, mpls_add_del_decap_reply) \
1866 _(MPLS_GRE_ADD_DEL_TUNNEL_REPLY, mpls_gre_add_del_tunnel_reply) \
1867 _(MPLS_ETHERNET_ADD_DEL_TUNNEL_REPLY, \
1868 mpls_ethernet_add_del_tunnel_reply) \
1869 _(MPLS_ETHERNET_ADD_DEL_TUNNEL_2_REPLY, \
1870 mpls_ethernet_add_del_tunnel_2_reply) \
1871 _(SW_INTERFACE_SET_UNNUMBERED_REPLY, \
1872 sw_interface_set_unnumbered_reply) \
1873 _(IP_NEIGHBOR_ADD_DEL_REPLY, ip_neighbor_add_del_reply) \
1874 _(RESET_VRF_REPLY, reset_vrf_reply) \
1875 _(CREATE_VLAN_SUBIF_REPLY, create_vlan_subif_reply) \
1876 _(CREATE_SUBIF_REPLY, create_subif_reply) \
1877 _(OAM_ADD_DEL_REPLY, oam_add_del_reply) \
1878 _(RESET_FIB_REPLY, reset_fib_reply) \
1879 _(DHCP_PROXY_CONFIG_REPLY, dhcp_proxy_config_reply) \
1880 _(DHCP_PROXY_CONFIG_2_REPLY, dhcp_proxy_config_2_reply) \
1881 _(DHCP_PROXY_SET_VSS_REPLY, dhcp_proxy_set_vss_reply) \
1882 _(DHCP_CLIENT_CONFIG_REPLY, dhcp_client_config_reply) \
1883 _(SET_IP_FLOW_HASH_REPLY, set_ip_flow_hash_reply) \
1884 _(SW_INTERFACE_IP6_ENABLE_DISABLE_REPLY, \
1885 sw_interface_ip6_enable_disable_reply) \
1886 _(SW_INTERFACE_IP6_SET_LINK_LOCAL_ADDRESS_REPLY, \
1887 sw_interface_ip6_set_link_local_address_reply) \
1888 _(SW_INTERFACE_IP6ND_RA_PREFIX_REPLY, \
1889 sw_interface_ip6nd_ra_prefix_reply) \
1890 _(SW_INTERFACE_IP6ND_RA_CONFIG_REPLY, \
1891 sw_interface_ip6nd_ra_config_reply) \
1892 _(SET_ARP_NEIGHBOR_LIMIT_REPLY, set_arp_neighbor_limit_reply) \
1893 _(L2_PATCH_ADD_DEL_REPLY, l2_patch_add_del_reply) \
1894 _(SR_TUNNEL_ADD_DEL_REPLY, sr_tunnel_add_del_reply) \
1895 _(CLASSIFY_ADD_DEL_TABLE_REPLY, classify_add_del_table_reply) \
1896 _(CLASSIFY_ADD_DEL_SESSION_REPLY, classify_add_del_session_reply) \
1897 _(CLASSIFY_SET_INTERFACE_IP_TABLE_REPLY, \
1898 classify_set_interface_ip_table_reply) \
1899 _(CLASSIFY_SET_INTERFACE_L2_TABLES_REPLY, \
1900 classify_set_interface_l2_tables_reply) \
1901 _(GET_NODE_INDEX_REPLY, get_node_index_reply) \
1902 _(ADD_NODE_NEXT_REPLY, add_node_next_reply) \
1903 _(L2TPV3_CREATE_TUNNEL_REPLY, l2tpv3_create_tunnel_reply) \
1904 _(L2TPV3_SET_TUNNEL_COOKIES_REPLY, l2tpv3_set_tunnel_cookies_reply) \
1905 _(L2TPV3_INTERFACE_ENABLE_DISABLE_REPLY, \
1906 l2tpv3_interface_enable_disable_reply) \
1907 _(L2TPV3_SET_LOOKUP_KEY_REPLY, l2tpv3_set_lookup_key_reply) \
1908 _(SW_IF_L2TPV3_TUNNEL_DETAILS, sw_if_l2tpv3_tunnel_details) \
1909 _(VXLAN_ADD_DEL_TUNNEL_REPLY, vxlan_add_del_tunnel_reply) \
1910 _(VXLAN_TUNNEL_DETAILS, vxlan_tunnel_details) \
1911 _(L2_FIB_CLEAR_TABLE_REPLY, l2_fib_clear_table_reply) \
1912 _(L2_INTERFACE_EFP_FILTER_REPLY, l2_interface_efp_filter_reply) \
1913 _(L2_INTERFACE_VLAN_TAG_REWRITE_REPLY, l2_interface_vlan_tag_rewrite_reply) \
1914 _(SW_INTERFACE_VHOST_USER_DETAILS, sw_interface_vhost_user_details) \
1915 _(CREATE_VHOST_USER_IF_REPLY, create_vhost_user_if_reply) \
1916 _(MODIFY_VHOST_USER_IF_REPLY, modify_vhost_user_if_reply) \
1917 _(DELETE_VHOST_USER_IF_REPLY, delete_vhost_user_if_reply) \
1918 _(SHOW_VERSION_REPLY, show_version_reply) \
1919 _(NSH_GRE_ADD_DEL_TUNNEL_REPLY, nsh_gre_add_del_tunnel_reply) \
1920 _(L2_FIB_TABLE_ENTRY, l2_fib_table_entry) \
1921 _(NSH_VXLAN_GPE_ADD_DEL_TUNNEL_REPLY, nsh_vxlan_gpe_add_del_tunnel_reply) \
1922 _(LISP_GPE_ADD_DEL_TUNNEL_REPLY, lisp_gpe_add_del_tunnel_reply) \
1923 _(INTERFACE_NAME_RENUMBER_REPLY, interface_name_renumber_reply) \
1924 _(WANT_IP4_ARP_EVENTS_REPLY, want_ip4_arp_events_reply) \
1925 _(IP4_ARP_EVENT, ip4_arp_event) \
1926 _(INPUT_ACL_SET_INTERFACE_REPLY, input_acl_set_interface_reply) \
1927 _(IP_ADDRESS_DETAILS, ip_address_details) \
1928 _(IP_DETAILS, ip_details) \
1929 _(IPSEC_SPD_ADD_DEL_REPLY, ipsec_spd_add_del_reply) \
1930 _(IPSEC_INTERFACE_ADD_DEL_SPD_REPLY, ipsec_interface_add_del_spd_reply) \
1931 _(IPSEC_SPD_ADD_DEL_ENTRY_REPLY, ipsec_spd_add_del_entry_reply) \
1932 _(IPSEC_SAD_ADD_DEL_ENTRY_REPLY, ipsec_sad_add_del_entry_reply) \
1933 _(IPSEC_SA_SET_KEY_REPLY, ipsec_sa_set_key_reply) \
1934 _(DELETE_LOOPBACK_REPLY, delete_loopback_reply) \
1935 _(BD_IP_MAC_ADD_DEL_REPLY, bd_ip_mac_add_del_reply) \
1936 _(DHCP_COMPL_EVENT, dhcp_compl_event) \
1937 _(VNET_INTERFACE_COUNTERS, vnet_interface_counters) \
1938 _(VNET_IP4_FIB_COUNTERS, vnet_ip4_fib_counters) \
1939 _(VNET_IP6_FIB_COUNTERS, vnet_ip6_fib_counters) \
1940 _(MAP_ADD_DOMAIN_REPLY, map_add_domain_reply) \
1941 _(MAP_DEL_DOMAIN_REPLY, map_del_domain_reply) \
1942 _(MAP_ADD_DEL_RULE_REPLY, map_add_del_rule_reply) \
1943 _(MAP_DOMAIN_DETAILS, map_domain_details) \
1944 _(MAP_RULE_DETAILS, map_rule_details) \
1945 _(WANT_INTERFACE_EVENTS_REPLY, want_interface_events_reply) \
1946 _(WANT_STATS_REPLY, want_stats_reply) \
1947 _(GET_FIRST_MSG_ID_REPLY, get_first_msg_id_reply) \
1948 _(COP_INTERFACE_ENABLE_DISABLE_REPLY, cop_interface_enable_disable_reply) \
1949 _(COP_WHITELIST_ENABLE_DISABLE_REPLY, cop_whitelist_enable_disable_reply)
1951 /* M: construct, but don't yet send a message */
1955 vam->result_ready = 0; \
1956 mp = vl_msg_api_alloc(sizeof(*mp)); \
1957 memset (mp, 0, sizeof (*mp)); \
1958 mp->_vl_msg_id = ntohs (VL_API_##T); \
1959 mp->client_index = vam->my_client_index; \
1964 vam->result_ready = 0; \
1965 mp = vl_msg_api_alloc(sizeof(*mp)+(n)); \
1966 memset (mp, 0, sizeof (*mp)); \
1967 mp->_vl_msg_id = ntohs (VL_API_##T); \
1968 mp->client_index = vam->my_client_index; \
1972 /* S: send a message */
1973 #define S (vl_msg_api_send_shmem (vam->vl_input_queue, (u8 *)&mp))
1975 /* W: wait for results, with timeout */
1978 timeout = vat_time_now (vam) + 1.0; \
1980 while (vat_time_now (vam) < timeout) { \
1981 if (vam->result_ready == 1) { \
1982 return (vam->retval); \
1994 #define STR_VTR_OP_CASE(op) \
1995 case L2_VTR_ ## op: \
1998 static const char *str_vtr_op(u32 vtr_op)
2001 STR_VTR_OP_CASE(DISABLED);
2002 STR_VTR_OP_CASE(PUSH_1);
2003 STR_VTR_OP_CASE(PUSH_2);
2004 STR_VTR_OP_CASE(POP_1);
2005 STR_VTR_OP_CASE(POP_2);
2006 STR_VTR_OP_CASE(TRANSLATE_1_1);
2007 STR_VTR_OP_CASE(TRANSLATE_1_2);
2008 STR_VTR_OP_CASE(TRANSLATE_2_1);
2009 STR_VTR_OP_CASE(TRANSLATE_2_2);
2015 static int dump_sub_interface_table (vat_main_t * vam)
2017 const sw_interface_subif_t * sub = NULL;
2019 if (vam->json_output) {
2020 clib_warning ("JSON output supported only for VPE API calls and dump_stats_table");
2025 "%-30s%-12s%-11s%-7s%-5s%-9s%-9s%-6s%-8s%-10s%-10s\n",
2026 "Interface", "sw_if_index",
2027 "sub id", "dot1ad", "tags", "outer id",
2028 "inner id", "exact", "default",
2029 "outer any", "inner any");
2031 vec_foreach (sub, vam->sw_if_subif_table) {
2033 "%-30s%-12d%-11d%-7s%-5d%-9d%-9d%-6d%-8d%-10d%-10d\n",
2034 sub->interface_name,
2036 sub->sub_id, sub->sub_dot1ad ? "dot1ad" : "dot1q",
2037 sub->sub_number_of_tags, sub->sub_outer_vlan_id,
2038 sub->sub_inner_vlan_id, sub->sub_exact_match, sub->sub_default,
2039 sub->sub_outer_vlan_id_any, sub->sub_inner_vlan_id_any);
2040 if (sub->vtr_op != L2_VTR_DISABLED) {
2042 " vlan-tag-rewrite - op: %-14s [ dot1q: %d "
2043 "tag1: %d tag2: %d ]\n",
2044 str_vtr_op(sub->vtr_op), sub->vtr_push_dot1q,
2045 sub->vtr_tag1, sub->vtr_tag2);
2052 static int name_sort_cmp (void * a1, void * a2)
2054 name_sort_t * n1 = a1;
2055 name_sort_t * n2 = a2;
2057 return strcmp ((char *)n1->name, (char *)n2->name);
2060 static int dump_interface_table (vat_main_t * vam)
2063 name_sort_t * nses = 0, * ns;
2065 if (vam->json_output) {
2066 clib_warning ("JSON output supported only for VPE API calls and dump_stats_table");
2070 hash_foreach_pair (p, vam->sw_if_index_by_interface_name,
2072 vec_add2 (nses, ns, 1);
2073 ns->name = (u8 *)(p->key);
2074 ns->value = (u32) p->value[0];
2077 vec_sort_with_function (nses, name_sort_cmp);
2079 fformat (vam->ofp, "%-25s%-15s\n", "Interface", "sw_if_index");
2080 vec_foreach (ns, nses) {
2081 fformat (vam->ofp, "%-25s%-15d\n", ns->name, ns->value);
2087 static int dump_ip_table (vat_main_t * vam, int is_ipv6)
2089 const ip_details_t * det = NULL;
2090 const ip_address_details_t * address = NULL;
2097 if (0 == vam->ip_details_by_sw_if_index) {
2101 vec_foreach (det, vam->ip_details_by_sw_if_index[is_ipv6]) {
2103 if (!det->present) {
2111 "Address", "Prefix length");
2115 vec_foreach (address, det->addr) {
2118 is_ipv6 ? format_ip6_address : format_ip4_address,
2120 address->prefix_length);
2127 static int dump_ipv4_table (vat_main_t * vam)
2129 if (vam->json_output) {
2130 clib_warning ("JSON output supported only for VPE API calls and dump_stats_table");
2134 return dump_ip_table (vam, 0);
2137 static int dump_ipv6_table (vat_main_t * vam)
2139 if (vam->json_output) {
2140 clib_warning ("JSON output supported only for VPE API calls and dump_stats_table");
2144 return dump_ip_table (vam, 1);
2147 static char* counter_type_to_str (u8 counter_type, u8 is_combined)
2150 switch(counter_type) {
2151 case VNET_INTERFACE_COUNTER_DROP:
2153 case VNET_INTERFACE_COUNTER_PUNT:
2155 case VNET_INTERFACE_COUNTER_IP4:
2157 case VNET_INTERFACE_COUNTER_IP6:
2159 case VNET_INTERFACE_COUNTER_RX_NO_BUF:
2161 case VNET_INTERFACE_COUNTER_RX_MISS:
2163 case VNET_INTERFACE_COUNTER_RX_ERROR:
2165 case VNET_INTERFACE_COUNTER_TX_ERROR:
2168 return "INVALID-COUNTER-TYPE";
2171 switch(counter_type) {
2172 case VNET_INTERFACE_COUNTER_RX:
2174 case VNET_INTERFACE_COUNTER_TX:
2177 return "INVALID-COUNTER-TYPE";
2182 static int dump_stats_table (vat_main_t * vam)
2184 vat_json_node_t node;
2185 vat_json_node_t *msg_array;
2186 vat_json_node_t *msg;
2187 vat_json_node_t *counter_array;
2188 vat_json_node_t *counter;
2189 interface_counter_t c;
2191 ip4_fib_counter_t *c4;
2192 ip6_fib_counter_t *c6;
2195 if (!vam->json_output) {
2196 clib_warning ("dump_stats_table supported only in JSON format");
2200 vat_json_init_object(&node);
2202 /* interface counters */
2203 msg_array = vat_json_object_add(&node, "interface_counters");
2204 vat_json_init_array(msg_array);
2205 for (i = 0; i < vec_len(vam->simple_interface_counters); i++) {
2206 msg = vat_json_array_add(msg_array);
2207 vat_json_init_object(msg);
2208 vat_json_object_add_string_copy(msg, "vnet_counter_type",
2209 (u8*)counter_type_to_str(i, 0));
2210 vat_json_object_add_int(msg, "is_combined", 0);
2211 counter_array = vat_json_object_add(msg, "data");
2212 vat_json_init_array(counter_array);
2213 for (j = 0; j < vec_len(vam->simple_interface_counters[i]); j++) {
2214 packets = vam->simple_interface_counters[i][j];
2215 vat_json_array_add_uint(counter_array, packets);
2218 for (i = 0; i < vec_len(vam->combined_interface_counters); i++) {
2219 msg = vat_json_array_add(msg_array);
2220 vat_json_init_object(msg);
2221 vat_json_object_add_string_copy(msg, "vnet_counter_type",
2222 (u8*)counter_type_to_str(i, 1));
2223 vat_json_object_add_int(msg, "is_combined", 1);
2224 counter_array = vat_json_object_add(msg, "data");
2225 vat_json_init_array(counter_array);
2226 for (j = 0; j < vec_len(vam->combined_interface_counters[i]); j++) {
2227 c = vam->combined_interface_counters[i][j];
2228 counter = vat_json_array_add(counter_array);
2229 vat_json_init_object(counter);
2230 vat_json_object_add_uint(counter, "packets", c.packets);
2231 vat_json_object_add_uint(counter, "bytes", c.bytes);
2235 /* ip4 fib counters */
2236 msg_array = vat_json_object_add(&node, "ip4_fib_counters");
2237 vat_json_init_array(msg_array);
2238 for (i = 0; i < vec_len(vam->ip4_fib_counters); i++) {
2239 msg = vat_json_array_add(msg_array);
2240 vat_json_init_object(msg);
2241 vat_json_object_add_uint(msg, "vrf_id", vam->ip4_fib_counters_vrf_id_by_index[i]);
2242 counter_array = vat_json_object_add(msg, "c");
2243 vat_json_init_array(counter_array);
2244 for (j = 0; j < vec_len(vam->ip4_fib_counters[i]); j++) {
2245 counter = vat_json_array_add(counter_array);
2246 vat_json_init_object(counter);
2247 c4 = &vam->ip4_fib_counters[i][j];
2248 vat_json_object_add_ip4(counter, "address", c4->address);
2249 vat_json_object_add_uint(counter, "address_length", c4->address_length);
2250 vat_json_object_add_uint(counter, "packets", c4->packets);
2251 vat_json_object_add_uint(counter, "bytes", c4->bytes);
2255 /* ip6 fib counters */
2256 msg_array = vat_json_object_add(&node, "ip6_fib_counters");
2257 vat_json_init_array(msg_array);
2258 for (i = 0; i < vec_len(vam->ip6_fib_counters); i++) {
2259 msg = vat_json_array_add(msg_array);
2260 vat_json_init_object(msg);
2261 vat_json_object_add_uint(msg, "vrf_id", vam->ip6_fib_counters_vrf_id_by_index[i]);
2262 counter_array = vat_json_object_add(msg, "c");
2263 vat_json_init_array(counter_array);
2264 for (j = 0; j < vec_len(vam->ip6_fib_counters[i]); j++) {
2265 counter = vat_json_array_add(counter_array);
2266 vat_json_init_object(counter);
2267 c6 = &vam->ip6_fib_counters[i][j];
2268 vat_json_object_add_ip6(counter, "address", c6->address);
2269 vat_json_object_add_uint(counter, "address_length", c6->address_length);
2270 vat_json_object_add_uint(counter, "packets", c6->packets);
2271 vat_json_object_add_uint(counter, "bytes", c6->bytes);
2275 vat_json_print(vam->ofp, &node);
2276 vat_json_free(&node);
2281 int exec (vat_main_t * vam)
2283 api_main_t * am = &api_main;
2284 vl_api_cli_request_t *mp;
2288 unformat_input_t * i = vam->input;
2290 if (vec_len(i->buffer) == 0)
2293 if (vam->exec_mode == 0 && unformat (i, "mode")) {
2297 if (vam->exec_mode == 1 &&
2298 (unformat (i, "exit") || unformat (i, "quit"))) {
2304 M(CLI_REQUEST, cli_request);
2307 * Copy cmd into shared memory.
2308 * In order for the CLI command to work, it
2309 * must be a vector ending in \n, not a C-string ending
2312 pthread_mutex_lock (&am->vlib_rp->mutex);
2313 oldheap = svm_push_data_heap (am->vlib_rp);
2315 vec_validate (cmd, vec_len(vam->input->buffer)-1);
2316 memcpy (cmd, vam->input->buffer, vec_len(vam->input->buffer));
2318 svm_pop_heap (oldheap);
2319 pthread_mutex_unlock (&am->vlib_rp->mutex);
2321 mp->cmd_in_shmem = (u64) cmd;
2323 timeout = vat_time_now (vam) + 10.0;
2325 while (vat_time_now (vam) < timeout) {
2326 if (vam->result_ready == 1) {
2328 fformat (vam->ofp, "%s", vam->shmem_result);
2329 pthread_mutex_lock (&am->vlib_rp->mutex);
2330 oldheap = svm_push_data_heap (am->vlib_rp);
2332 free_me = (u8 *)vam->shmem_result;
2335 svm_pop_heap (oldheap);
2336 pthread_mutex_unlock (&am->vlib_rp->mutex);
2343 static int api_create_loopback (vat_main_t * vam)
2345 unformat_input_t * i = vam->input;
2346 vl_api_create_loopback_t *mp;
2351 memset (mac_address, 0, sizeof (mac_address));
2353 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
2355 if (unformat (i, "mac %U", unformat_ethernet_address, mac_address))
2361 /* Construct the API message */
2362 M(CREATE_LOOPBACK, create_loopback);
2364 memcpy (mp->mac_address, mac_address, sizeof (mac_address));
2369 static int api_delete_loopback (vat_main_t * vam)
2371 unformat_input_t * i = vam->input;
2372 vl_api_delete_loopback_t *mp;
2374 u32 sw_if_index = ~0;
2376 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
2378 if (unformat (i, "sw_if_index %d", &sw_if_index))
2384 if (sw_if_index == ~0)
2386 errmsg ("missing sw_if_index\n");
2390 /* Construct the API message */
2391 M(DELETE_LOOPBACK, delete_loopback);
2392 mp->sw_if_index = ntohl (sw_if_index);
2397 static int api_want_stats (vat_main_t * vam)
2399 unformat_input_t * i = vam->input;
2400 vl_api_want_stats_t * mp;
2404 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
2406 if (unformat (i, "enable"))
2408 else if (unformat (i, "disable"))
2416 errmsg ("missing enable|disable\n");
2420 M(WANT_STATS, want_stats);
2421 mp->enable_disable = enable;
2426 static int api_want_interface_events (vat_main_t * vam)
2428 unformat_input_t * i = vam->input;
2429 vl_api_want_interface_events_t * mp;
2433 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
2435 if (unformat (i, "enable"))
2437 else if (unformat (i, "disable"))
2445 errmsg ("missing enable|disable\n");
2449 M(WANT_INTERFACE_EVENTS, want_interface_events);
2450 mp->enable_disable = enable;
2452 vam->interface_event_display = enable;
2458 /* Note: non-static, called once to set up the initial intfc table */
2459 int api_sw_interface_dump (vat_main_t * vam)
2461 vl_api_sw_interface_dump_t *mp;
2464 name_sort_t * nses = 0, * ns;
2465 sw_interface_subif_t * sub = NULL;
2467 /* Toss the old name table */
2468 hash_foreach_pair (p, vam->sw_if_index_by_interface_name,
2470 vec_add2 (nses, ns, 1);
2471 ns->name = (u8 *)(p->key);
2472 ns->value = (u32) p->value[0];
2475 hash_free (vam->sw_if_index_by_interface_name);
2477 vec_foreach (ns, nses)
2478 vec_free (ns->name);
2482 vec_foreach (sub, vam->sw_if_subif_table) {
2483 vec_free (sub->interface_name);
2485 vec_free (vam->sw_if_subif_table);
2487 /* recreate the interface name hash table */
2488 vam->sw_if_index_by_interface_name
2489 = hash_create_string (0, sizeof(uword));
2491 /* Get list of ethernets */
2492 M(SW_INTERFACE_DUMP, sw_interface_dump);
2493 mp->name_filter_valid = 1;
2494 strncpy ((char *) mp->name_filter, "Ether", sizeof(mp->name_filter-1));
2497 /* and local / loopback interfaces */
2498 M(SW_INTERFACE_DUMP, sw_interface_dump);
2499 mp->name_filter_valid = 1;
2500 strncpy ((char *) mp->name_filter, "lo", sizeof(mp->name_filter-1));
2503 /* and vxlan tunnel interfaces */
2504 M(SW_INTERFACE_DUMP, sw_interface_dump);
2505 mp->name_filter_valid = 1;
2506 strncpy ((char *) mp->name_filter, "vxlan", sizeof(mp->name_filter-1));
2509 /* and l2tpv3 tunnel interfaces */
2510 M(SW_INTERFACE_DUMP, sw_interface_dump);
2511 mp->name_filter_valid = 1;
2512 strncpy ((char *) mp->name_filter, "l2tpv3_tunnel", sizeof(mp->name_filter-1));
2515 /* Use a control ping for synchronization */
2517 vl_api_control_ping_t * mp;
2518 M(CONTROL_PING, control_ping);
2524 static int api_sw_interface_set_flags (vat_main_t * vam)
2526 unformat_input_t * i = vam->input;
2527 vl_api_sw_interface_set_flags_t *mp;
2530 u8 sw_if_index_set = 0;
2531 u8 admin_up = 0, link_up = 0;
2533 /* Parse args required to build the message */
2534 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
2535 if (unformat (i, "admin-up"))
2537 else if (unformat (i, "admin-down"))
2539 else if (unformat (i, "link-up"))
2541 else if (unformat (i, "link-down"))
2543 else if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
2544 sw_if_index_set = 1;
2545 else if (unformat (i, "sw_if_index %d", &sw_if_index))
2546 sw_if_index_set = 1;
2551 if (sw_if_index_set == 0) {
2552 errmsg ("missing interface name or sw_if_index\n");
2556 /* Construct the API message */
2557 M(SW_INTERFACE_SET_FLAGS, sw_interface_set_flags);
2558 mp->sw_if_index = ntohl (sw_if_index);
2559 mp->admin_up_down = admin_up;
2560 mp->link_up_down = link_up;
2565 /* Wait for a reply, return the good/bad news... */
2569 static int api_sw_interface_add_del_address (vat_main_t * vam)
2571 unformat_input_t * i = vam->input;
2572 vl_api_sw_interface_add_del_address_t *mp;
2575 u8 sw_if_index_set = 0;
2576 u8 is_add = 1, del_all = 0;
2577 u32 address_length = 0;
2578 u8 v4_address_set = 0;
2579 u8 v6_address_set = 0;
2580 ip4_address_t v4address;
2581 ip6_address_t v6address;
2583 /* Parse args required to build the message */
2584 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
2585 if (unformat (i, "del-all"))
2587 else if (unformat (i, "del"))
2589 else if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
2590 sw_if_index_set = 1;
2591 else if (unformat (i, "sw_if_index %d", &sw_if_index))
2592 sw_if_index_set = 1;
2593 else if (unformat (i, "%U/%d",
2594 unformat_ip4_address, &v4address,
2597 else if (unformat (i, "%U/%d",
2598 unformat_ip6_address, &v6address,
2605 if (sw_if_index_set == 0) {
2606 errmsg ("missing interface name or sw_if_index\n");
2609 if (v4_address_set && v6_address_set) {
2610 errmsg ("both v4 and v6 addresses set\n");
2613 if (!v4_address_set && !v6_address_set && !del_all) {
2614 errmsg ("no addresses set\n");
2618 /* Construct the API message */
2619 M(SW_INTERFACE_ADD_DEL_ADDRESS, sw_interface_add_del_address);
2621 mp->sw_if_index = ntohl (sw_if_index);
2622 mp->is_add = is_add;
2623 mp->del_all = del_all;
2624 if (v6_address_set) {
2626 memcpy (mp->address, &v6address, sizeof (v6address));
2628 memcpy (mp->address, &v4address, sizeof (v4address));
2630 mp->address_length = address_length;
2635 /* Wait for a reply, return good/bad news */
2639 static int api_sw_interface_set_table (vat_main_t * vam)
2641 unformat_input_t * i = vam->input;
2642 vl_api_sw_interface_set_table_t *mp;
2644 u32 sw_if_index, vrf_id = 0;
2645 u8 sw_if_index_set = 0;
2648 /* Parse args required to build the message */
2649 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
2650 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
2651 sw_if_index_set = 1;
2652 else if (unformat (i, "sw_if_index %d", &sw_if_index))
2653 sw_if_index_set = 1;
2654 else if (unformat (i, "vrf %d", &vrf_id))
2656 else if (unformat (i, "ipv6"))
2662 if (sw_if_index_set == 0) {
2663 errmsg ("missing interface name or sw_if_index\n");
2667 /* Construct the API message */
2668 M(SW_INTERFACE_SET_TABLE, sw_interface_set_table);
2670 mp->sw_if_index = ntohl (sw_if_index);
2671 mp->is_ipv6 = is_ipv6;
2672 mp->vrf_id = ntohl (vrf_id);
2677 /* Wait for a reply... */
2681 static int api_sw_interface_set_vpath (vat_main_t * vam)
2683 unformat_input_t * i = vam->input;
2684 vl_api_sw_interface_set_vpath_t *mp;
2686 u32 sw_if_index = 0;
2687 u8 sw_if_index_set = 0;
2690 /* Parse args required to build the message */
2691 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
2692 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
2693 sw_if_index_set = 1;
2694 else if (unformat (i, "sw_if_index %d", &sw_if_index))
2695 sw_if_index_set = 1;
2696 else if (unformat (i, "enable"))
2698 else if (unformat (i, "disable"))
2704 if (sw_if_index_set == 0) {
2705 errmsg ("missing interface name or sw_if_index\n");
2709 /* Construct the API message */
2710 M(SW_INTERFACE_SET_VPATH, sw_interface_set_vpath);
2712 mp->sw_if_index = ntohl (sw_if_index);
2713 mp->enable = is_enable;
2718 /* Wait for a reply... */
2722 static int api_sw_interface_set_l2_xconnect (vat_main_t * vam)
2724 unformat_input_t * i = vam->input;
2725 vl_api_sw_interface_set_l2_xconnect_t *mp;
2728 u8 rx_sw_if_index_set = 0;
2730 u8 tx_sw_if_index_set = 0;
2733 /* Parse args required to build the message */
2734 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
2735 if (unformat (i, "rx_sw_if_index %d", &rx_sw_if_index))
2736 rx_sw_if_index_set = 1;
2737 else if (unformat (i, "tx_sw_if_index %d", &tx_sw_if_index))
2738 tx_sw_if_index_set = 1;
2739 else if (unformat (i, "rx")) {
2740 if (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
2741 if (unformat (i, "%U", unformat_sw_if_index, vam,
2743 rx_sw_if_index_set = 1;
2746 } else if (unformat (i, "tx")) {
2747 if (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
2748 if (unformat (i, "%U", unformat_sw_if_index, vam,
2750 tx_sw_if_index_set = 1;
2753 } else if (unformat (i, "enable"))
2755 else if (unformat (i, "disable"))
2761 if (rx_sw_if_index_set == 0) {
2762 errmsg ("missing rx interface name or rx_sw_if_index\n");
2766 if (enable && (tx_sw_if_index_set == 0)) {
2767 errmsg ("missing tx interface name or tx_sw_if_index\n");
2771 M(SW_INTERFACE_SET_L2_XCONNECT, sw_interface_set_l2_xconnect);
2773 mp->rx_sw_if_index = ntohl(rx_sw_if_index);
2774 mp->tx_sw_if_index = ntohl(tx_sw_if_index);
2775 mp->enable = enable;
2782 static int api_sw_interface_set_l2_bridge (vat_main_t * vam)
2784 unformat_input_t * i = vam->input;
2785 vl_api_sw_interface_set_l2_bridge_t *mp;
2788 u8 rx_sw_if_index_set = 0;
2795 /* Parse args required to build the message */
2796 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
2797 if (unformat (i, "sw_if_index %d", &rx_sw_if_index))
2798 rx_sw_if_index_set = 1;
2799 else if (unformat (i, "bd_id %d", &bd_id))
2801 else if (unformat (i, "%U", unformat_sw_if_index, vam,
2803 rx_sw_if_index_set = 1;
2804 else if (unformat (i, "shg %d", &shg))
2806 else if (unformat (i, "bvi"))
2808 else if (unformat (i, "enable"))
2810 else if (unformat (i, "disable"))
2816 if (rx_sw_if_index_set == 0) {
2817 errmsg ("missing rx interface name or sw_if_index\n");
2821 if (enable && (bd_id_set == 0)) {
2822 errmsg ("missing bridge domain\n");
2826 M(SW_INTERFACE_SET_L2_BRIDGE, sw_interface_set_l2_bridge);
2828 mp->rx_sw_if_index = ntohl(rx_sw_if_index);
2829 mp->bd_id = ntohl(bd_id);
2832 mp->enable = enable;
2839 static int api_bridge_domain_dump (vat_main_t * vam)
2841 unformat_input_t * i = vam->input;
2842 vl_api_bridge_domain_dump_t *mp;
2846 /* Parse args required to build the message */
2847 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
2848 if (unformat (i, "bd_id %d", &bd_id))
2854 M(BRIDGE_DOMAIN_DUMP, bridge_domain_dump);
2855 mp->bd_id = ntohl(bd_id);
2858 /* Use a control ping for synchronization */
2860 vl_api_control_ping_t * mp;
2861 M(CONTROL_PING, control_ping);
2870 static int api_bridge_domain_add_del (vat_main_t * vam)
2872 unformat_input_t * i = vam->input;
2873 vl_api_bridge_domain_add_del_t *mp;
2877 u32 flood = 1, forward = 1, learn = 1, uu_flood = 1, arp_term = 0;
2879 /* Parse args required to build the message */
2880 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
2881 if (unformat (i, "bd_id %d", &bd_id))
2883 else if (unformat (i, "flood %d", &flood))
2885 else if (unformat (i, "uu-flood %d", &uu_flood))
2887 else if (unformat (i, "forward %d", &forward))
2889 else if (unformat (i, "learn %d", &learn))
2891 else if (unformat (i, "arp-term %d", &arp_term))
2893 else if (unformat (i, "del")) {
2895 flood = uu_flood = forward = learn = 0;
2902 errmsg ("missing bridge domain\n");
2906 M(BRIDGE_DOMAIN_ADD_DEL, bridge_domain_add_del);
2908 mp->bd_id = ntohl(bd_id);
2910 mp->uu_flood = uu_flood;
2911 mp->forward = forward;
2913 mp->arp_term = arp_term;
2914 mp->is_add = is_add;
2921 static int api_l2fib_add_del (vat_main_t * vam)
2923 unformat_input_t * i = vam->input;
2924 vl_api_l2fib_add_del_t *mp;
2931 u8 sw_if_index_set = 0;
2936 /* Parse args required to build the message */
2937 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
2938 if (unformat (i, "mac %U", unformat_ethernet_address, &mac))
2940 else if (unformat (i, "bd_id %d", &bd_id))
2942 else if (unformat (i, "sw_if_index %d", &sw_if_index))
2943 sw_if_index_set = 1;
2944 else if (unformat (i, "sw_if")) {
2945 if (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
2946 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
2947 sw_if_index_set = 1;
2950 } else if (unformat (i, "static"))
2952 else if (unformat (i, "filter")) {
2955 } else if (unformat (i, "del"))
2962 errmsg ("missing mac address\n");
2966 if (bd_id_set == 0) {
2967 errmsg ("missing bridge domain\n");
2971 if (is_add && (sw_if_index_set == 0)) {
2972 errmsg ("missing interface name or sw_if_index\n");
2976 M(L2FIB_ADD_DEL, l2fib_add_del);
2979 mp->bd_id = ntohl(bd_id);
2980 mp->is_add = is_add;
2983 mp->sw_if_index = ntohl(sw_if_index);
2984 mp->static_mac = static_mac;
2985 mp->filter_mac = filter_mac;
2993 static int api_l2_flags (vat_main_t * vam)
2995 unformat_input_t * i = vam->input;
2996 vl_api_l2_flags_t *mp;
2999 u32 feature_bitmap = 0;
3000 u8 sw_if_index_set = 0;
3002 /* Parse args required to build the message */
3003 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
3004 if (unformat (i, "sw_if_index %d", &sw_if_index))
3005 sw_if_index_set = 1;
3006 else if (unformat (i, "sw_if")) {
3007 if (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
3008 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
3009 sw_if_index_set = 1;
3012 } else if (unformat (i, "learn"))
3013 feature_bitmap |= L2INPUT_FEAT_LEARN;
3014 else if (unformat (i, "forward"))
3015 feature_bitmap |= L2INPUT_FEAT_FWD;
3016 else if (unformat (i, "flood"))
3017 feature_bitmap |= L2INPUT_FEAT_FLOOD;
3018 else if (unformat (i, "uu-flood"))
3019 feature_bitmap |= L2INPUT_FEAT_UU_FLOOD;
3024 if (sw_if_index_set == 0) {
3025 errmsg ("missing interface name or sw_if_index\n");
3029 M(L2_FLAGS, l2_flags);
3031 mp->sw_if_index = ntohl(sw_if_index);
3032 mp->feature_bitmap = ntohl(feature_bitmap);
3039 static int api_bridge_flags (vat_main_t * vam)
3041 unformat_input_t * i = vam->input;
3042 vl_api_bridge_flags_t *mp;
3049 /* Parse args required to build the message */
3050 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
3051 if (unformat (i, "bd_id %d", &bd_id))
3053 else if (unformat (i, "learn"))
3055 else if (unformat (i, "forward"))
3057 else if (unformat (i, "flood"))
3059 else if (unformat (i, "uu-flood"))
3060 flags |= L2_UU_FLOOD;
3061 else if (unformat (i, "arp-term"))
3062 flags |= L2_ARP_TERM;
3063 else if (unformat (i, "off"))
3065 else if (unformat (i, "disable"))
3071 if (bd_id_set == 0) {
3072 errmsg ("missing bridge domain\n");
3076 M(BRIDGE_FLAGS, bridge_flags);
3078 mp->bd_id = ntohl(bd_id);
3079 mp->feature_bitmap = ntohl(flags);
3080 mp->is_set = is_set;
3087 static int api_bd_ip_mac_add_del (vat_main_t * vam)
3089 unformat_input_t * i = vam->input;
3090 vl_api_bd_ip_mac_add_del_t *mp;
3098 ip4_address_t v4addr;
3099 ip6_address_t v6addr;
3103 /* Parse args required to build the message */
3104 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
3105 if (unformat (i, "bd_id %d", &bd_id)) {
3107 } else if (unformat (i, "%U", unformat_ip4_address, &v4addr)) {
3109 } else if (unformat (i, "%U", unformat_ip6_address, &v6addr)) {
3112 } else if (unformat (i, "%U", unformat_ethernet_address, macaddr)) {
3114 } else if (unformat (i, "del"))
3120 if (bd_id_set == 0) {
3121 errmsg ("missing bridge domain\n");
3123 } else if (ip_set == 0) {
3124 errmsg ("missing IP address\n");
3126 } else if (mac_set == 0) {
3127 errmsg ("missing MAC address\n");
3131 M(BD_IP_MAC_ADD_DEL, bd_ip_mac_add_del);
3133 mp->bd_id = ntohl(bd_id);
3134 mp->is_ipv6 = is_ipv6;
3135 mp->is_add = is_add;
3137 memcpy (mp->ip_address, &v6addr, sizeof (v6addr));
3138 else memcpy (mp->ip_address, &v4addr, sizeof (v4addr));
3139 memcpy (mp->mac_address, macaddr, 6);
3145 static int api_tap_connect (vat_main_t * vam)
3147 unformat_input_t * i = vam->input;
3148 vl_api_tap_connect_t *mp;
3155 memset (mac_address, 0, sizeof (mac_address));
3157 /* Parse args required to build the message */
3158 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
3159 if (unformat (i, "mac %U", unformat_ethernet_address, mac_address)) {
3162 else if (unformat (i, "random-mac"))
3164 else if (unformat (i, "tapname %s", &tap_name))
3170 if (name_set == 0) {
3171 errmsg ("missing tap name\n");
3174 if (vec_len (tap_name) > 63) {
3175 errmsg ("tap name too long\n");
3177 vec_add1 (tap_name, 0);
3179 /* Construct the API message */
3180 M(TAP_CONNECT, tap_connect);
3182 mp->use_random_mac = random_mac;
3183 memcpy (mp->mac_address, mac_address, 6);
3184 memcpy (mp->tap_name, tap_name, vec_len (tap_name));
3185 vec_free (tap_name);
3190 /* Wait for a reply... */
3194 static int api_tap_modify (vat_main_t * vam)
3196 unformat_input_t * i = vam->input;
3197 vl_api_tap_modify_t *mp;
3203 u32 sw_if_index = ~0;
3204 u8 sw_if_index_set = 0;
3206 memset (mac_address, 0, sizeof (mac_address));
3208 /* Parse args required to build the message */
3209 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
3210 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
3211 sw_if_index_set = 1;
3212 else if (unformat (i, "sw_if_index %d", &sw_if_index))
3213 sw_if_index_set = 1;
3214 else if (unformat (i, "mac %U", unformat_ethernet_address, mac_address)) {
3217 else if (unformat (i, "random-mac"))
3219 else if (unformat (i, "tapname %s", &tap_name))
3225 if (sw_if_index_set == 0) {
3226 errmsg ("missing vpp interface name");
3229 if (name_set == 0) {
3230 errmsg ("missing tap name\n");
3233 if (vec_len (tap_name) > 63) {
3234 errmsg ("tap name too long\n");
3236 vec_add1 (tap_name, 0);
3238 /* Construct the API message */
3239 M(TAP_MODIFY, tap_modify);
3241 mp->use_random_mac = random_mac;
3242 mp->sw_if_index = ntohl(sw_if_index);
3243 memcpy (mp->mac_address, mac_address, 6);
3244 memcpy (mp->tap_name, tap_name, vec_len (tap_name));
3245 vec_free (tap_name);
3250 /* Wait for a reply... */
3254 static int api_tap_delete (vat_main_t * vam)
3256 unformat_input_t * i = vam->input;
3257 vl_api_tap_delete_t *mp;
3259 u32 sw_if_index = ~0;
3260 u8 sw_if_index_set = 0;
3262 /* Parse args required to build the message */
3263 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
3264 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
3265 sw_if_index_set = 1;
3266 else if (unformat (i, "sw_if_index %d", &sw_if_index))
3267 sw_if_index_set = 1;
3272 if (sw_if_index_set == 0) {
3273 errmsg ("missing vpp interface name");
3277 /* Construct the API message */
3278 M(TAP_DELETE, tap_delete);
3280 mp->sw_if_index = ntohl(sw_if_index);
3285 /* Wait for a reply... */
3289 static int api_ip_add_del_route (vat_main_t * vam)
3291 unformat_input_t * i = vam->input;
3292 vl_api_ip_add_del_route_t *mp;
3294 u32 sw_if_index = 0, vrf_id = 0;
3295 u8 sw_if_index_set = 0;
3297 u8 is_local = 0, is_drop = 0;
3298 u8 create_vrf_if_needed = 0;
3300 u8 next_hop_weight = 1;
3302 u8 is_multipath = 0;
3304 u8 address_length_set = 0;
3305 u32 lookup_in_vrf = 0;
3306 u32 resolve_attempts = 0;
3307 u32 dst_address_length = 0;
3308 u8 next_hop_set = 0;
3309 ip4_address_t v4_dst_address, v4_next_hop_address;
3310 ip6_address_t v6_dst_address, v6_next_hop_address;
3314 u32 random_add_del = 0;
3315 u32 * random_vector = 0;
3316 uword * random_hash;
3317 u32 random_seed = 0xdeaddabe;
3318 u32 classify_table_index = ~0;
3321 /* Parse args required to build the message */
3322 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
3323 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
3324 sw_if_index_set = 1;
3325 else if (unformat (i, "sw_if_index %d", &sw_if_index))
3326 sw_if_index_set = 1;
3327 else if (unformat (i, "%U", unformat_ip4_address,
3332 else if (unformat (i, "%U", unformat_ip6_address, &v6_dst_address)) {
3336 else if (unformat (i, "/%d", &dst_address_length)) {
3337 address_length_set = 1;
3340 else if (is_ipv6 == 0 && unformat (i, "via %U", unformat_ip4_address,
3341 &v4_next_hop_address)) {
3344 else if (is_ipv6 == 1 && unformat (i, "via %U", unformat_ip6_address,
3345 &v6_next_hop_address)) {
3348 else if (unformat (i, "resolve-attempts %d", &resolve_attempts))
3350 else if (unformat (i, "weight %d", &next_hop_weight))
3352 else if (unformat (i, "drop")) {
3354 } else if (unformat (i, "local")) {
3356 } else if (unformat (i, "classify %d", &classify_table_index)) {
3358 } else if (unformat (i, "del"))
3360 else if (unformat (i, "add"))
3362 else if (unformat (i, "not-last"))
3364 else if (unformat (i, "multipath"))
3366 else if (unformat (i, "vrf %d", &vrf_id))
3368 else if (unformat (i, "create-vrf"))
3369 create_vrf_if_needed = 1;
3370 else if (unformat (i, "count %d", &count))
3372 else if (unformat (i, "lookup-in-vrf %d", &lookup_in_vrf))
3374 else if (unformat (i, "random"))
3376 else if (unformat (i, "seed %d", &random_seed))
3379 clib_warning ("parse error '%U'", format_unformat_error, i);
3384 if (resolve_attempts > 0 && sw_if_index_set == 0) {
3385 errmsg ("ARP resolution needs explicit interface or sw_if_index\n");
3389 if (!next_hop_set && !is_drop && !is_local && !is_classify) {
3390 errmsg ("next hop / local / drop / classify not set\n");
3394 if (address_set == 0) {
3395 errmsg ("missing addresses\n");
3399 if (address_length_set == 0) {
3400 errmsg ("missing address length\n");
3404 /* Generate a pile of unique, random routes */
3405 if (random_add_del) {
3406 u32 this_random_address;
3407 random_hash = hash_create (count, sizeof(uword));
3409 hash_set (random_hash, v4_next_hop_address.as_u32, 1);
3410 for (j = 0; j <= count; j++) {
3412 this_random_address = random_u32 (&random_seed);
3413 this_random_address =
3414 clib_host_to_net_u32 (this_random_address);
3415 } while (hash_get (random_hash, this_random_address));
3416 vec_add1 (random_vector, this_random_address);
3417 hash_set (random_hash, this_random_address, 1);
3419 hash_free (random_hash);
3420 v4_dst_address.as_u32 = random_vector[0];
3424 /* Turn on async mode */
3425 vam->async_mode = 1;
3426 vam->async_errors = 0;
3427 before = vat_time_now(vam);
3430 for (j = 0; j < count; j++) {
3431 /* Construct the API message */
3432 M(IP_ADD_DEL_ROUTE, ip_add_del_route);
3434 mp->next_hop_sw_if_index = ntohl (sw_if_index);
3435 mp->vrf_id = ntohl (vrf_id);
3436 if (resolve_attempts > 0) {
3437 mp->resolve_attempts = ntohl (resolve_attempts);
3438 mp->resolve_if_needed = 1;
3440 mp->create_vrf_if_needed = create_vrf_if_needed;
3442 mp->is_add = is_add;
3443 mp->is_drop = is_drop;
3444 mp->is_ipv6 = is_ipv6;
3445 mp->is_local = is_local;
3446 mp->is_classify = is_classify;
3447 mp->is_multipath = is_multipath;
3448 mp->not_last = not_last;
3449 mp->next_hop_weight = next_hop_weight;
3450 mp->dst_address_length = dst_address_length;
3451 mp->lookup_in_vrf = ntohl(lookup_in_vrf);
3452 mp->classify_table_index = ntohl(classify_table_index);
3455 memcpy (mp->dst_address, &v6_dst_address, sizeof (v6_dst_address));
3457 memcpy (mp->next_hop_address, &v6_next_hop_address,
3458 sizeof (v6_next_hop_address));
3459 increment_v6_address (&v6_dst_address);
3461 memcpy (mp->dst_address, &v4_dst_address, sizeof (v4_dst_address));
3463 memcpy (mp->next_hop_address, &v4_next_hop_address,
3464 sizeof (v4_next_hop_address));
3466 v4_dst_address.as_u32 = random_vector[j+1];
3468 increment_v4_address (&v4_dst_address);
3474 /* When testing multiple add/del ops, use a control-ping to sync */
3476 vl_api_control_ping_t * mp;
3479 /* Shut off async mode */
3480 vam->async_mode = 0;
3482 M(CONTROL_PING, control_ping);
3485 timeout = vat_time_now(vam) + 1.0;
3486 while (vat_time_now (vam) < timeout)
3487 if (vam->result_ready == 1)
3492 if (vam->retval == -99)
3493 errmsg ("timeout\n");
3495 if (vam->async_errors > 0) {
3496 errmsg ("%d asynchronous errors\n", vam->async_errors);
3499 vam->async_errors = 0;
3500 after = vat_time_now(vam);
3502 fformat(vam->ofp, "%d routes in %.6f secs, %.2f routes/sec\n",
3503 count, after - before, count / (after - before));
3505 /* Wait for a reply... */
3509 /* Return the good/bad news */
3510 return (vam->retval);
3513 static int api_proxy_arp_add_del (vat_main_t * vam)
3515 unformat_input_t * i = vam->input;
3516 vl_api_proxy_arp_add_del_t *mp;
3520 ip4_address_t lo, hi;
3523 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
3524 if (unformat (i, "vrf %d", &vrf_id))
3526 else if (unformat (i, "%U - %U", unformat_ip4_address, &lo,
3527 unformat_ip4_address, &hi))
3529 else if (unformat (i, "del"))
3532 clib_warning ("parse error '%U'", format_unformat_error, i);
3537 if (range_set == 0) {
3538 errmsg ("address range not set\n");
3542 M(PROXY_ARP_ADD_DEL, proxy_arp_add_del);
3544 mp->vrf_id = ntohl(vrf_id);
3545 mp->is_add = is_add;
3546 memcpy(mp->low_address, &lo, sizeof (mp->low_address));
3547 memcpy(mp->hi_address, &hi, sizeof (mp->hi_address));
3554 static int api_proxy_arp_intfc_enable_disable (vat_main_t * vam)
3556 unformat_input_t * i = vam->input;
3557 vl_api_proxy_arp_intfc_enable_disable_t *mp;
3561 u8 sw_if_index_set = 0;
3563 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
3564 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
3565 sw_if_index_set = 1;
3566 else if (unformat (i, "sw_if_index %d", &sw_if_index))
3567 sw_if_index_set = 1;
3568 else if (unformat (i, "enable"))
3570 else if (unformat (i, "disable"))
3573 clib_warning ("parse error '%U'", format_unformat_error, i);
3578 if (sw_if_index_set == 0) {
3579 errmsg ("missing interface name or sw_if_index\n");
3583 M(PROXY_ARP_INTFC_ENABLE_DISABLE, proxy_arp_intfc_enable_disable);
3585 mp->sw_if_index = ntohl(sw_if_index);
3586 mp->enable_disable = enable;
3593 static int api_mpls_add_del_decap (vat_main_t * vam)
3595 unformat_input_t * i = vam->input;
3596 vl_api_mpls_add_del_decap_t *mp;
3605 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
3606 if (unformat (i, "rx_vrf_id %d", &rx_vrf_id))
3608 else if (unformat (i, "tx_vrf_id %d", &tx_vrf_id))
3610 else if (unformat (i, "label %d", &label))
3612 else if (unformat (i, "next-index %d", &next_index))
3614 else if (unformat (i, "del"))
3616 else if (unformat (i, "s-bit-clear"))
3619 clib_warning ("parse error '%U'", format_unformat_error, i);
3624 M(MPLS_ADD_DEL_DECAP, mpls_add_del_decap);
3626 mp->rx_vrf_id = ntohl(rx_vrf_id);
3627 mp->tx_vrf_id = ntohl(tx_vrf_id);
3628 mp->label = ntohl(label);
3629 mp->next_index = ntohl(next_index);
3631 mp->is_add = is_add;
3638 static int api_mpls_add_del_encap (vat_main_t * vam)
3640 unformat_input_t * i = vam->input;
3641 vl_api_mpls_add_del_encap_t *mp;
3646 ip4_address_t dst_address;
3649 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
3650 if (unformat (i, "vrf %d", &vrf_id))
3652 else if (unformat (i, "label %d", &label))
3653 vec_add1 (labels, ntohl(label));
3654 else if (unformat (i, "dst %U", unformat_ip4_address, &dst_address))
3656 else if (unformat (i, "del"))
3659 clib_warning ("parse error '%U'", format_unformat_error, i);
3664 if (vec_len (labels) == 0) {
3665 errmsg ("missing encap label stack\n");
3669 M2(MPLS_ADD_DEL_ENCAP, mpls_add_del_encap,
3670 sizeof (u32) * vec_len (labels));
3672 mp->vrf_id = ntohl(vrf_id);
3673 memcpy(mp->dst_address, &dst_address, sizeof (dst_address));
3674 mp->is_add = is_add;
3675 mp->nlabels = vec_len (labels);
3676 memcpy(mp->labels, labels, sizeof(u32)*mp->nlabels);
3685 static int api_mpls_gre_add_del_tunnel (vat_main_t * vam)
3687 unformat_input_t * i = vam->input;
3688 vl_api_mpls_gre_add_del_tunnel_t *mp;
3690 u32 inner_vrf_id = 0;
3691 u32 outer_vrf_id = 0;
3692 ip4_address_t src_address;
3693 ip4_address_t dst_address;
3694 ip4_address_t intfc_address;
3696 u8 intfc_address_length = 0;
3700 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
3701 if (unformat (i, "inner_vrf_id %d", &inner_vrf_id))
3703 else if (unformat (i, "outer_vrf_id %d", &outer_vrf_id))
3705 else if (unformat (i, "src %U", unformat_ip4_address, &src_address))
3707 else if (unformat (i, "dst %U", unformat_ip4_address, &dst_address))
3709 else if (unformat (i, "adj %U/%d", unformat_ip4_address,
3710 &intfc_address, &tmp))
3711 intfc_address_length = tmp;
3712 else if (unformat (i, "l2-only"))
3714 else if (unformat (i, "del"))
3717 clib_warning ("parse error '%U'", format_unformat_error, i);
3722 M(MPLS_GRE_ADD_DEL_TUNNEL, mpls_gre_add_del_tunnel);
3724 mp->inner_vrf_id = ntohl(inner_vrf_id);
3725 mp->outer_vrf_id = ntohl(outer_vrf_id);
3726 memcpy(mp->src_address, &src_address, sizeof (src_address));
3727 memcpy(mp->dst_address, &dst_address, sizeof (dst_address));
3728 memcpy(mp->intfc_address, &intfc_address, sizeof (intfc_address));
3729 mp->intfc_address_length = intfc_address_length;
3730 mp->l2_only = l2_only;
3731 mp->is_add = is_add;
3738 static int api_mpls_ethernet_add_del_tunnel (vat_main_t * vam)
3740 unformat_input_t * i = vam->input;
3741 vl_api_mpls_ethernet_add_del_tunnel_t *mp;
3743 u32 inner_vrf_id = 0;
3744 ip4_address_t intfc_address;
3745 u8 dst_mac_address[6];
3748 u8 intfc_address_length = 0;
3752 int tx_sw_if_index_set = 0;
3754 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
3755 if (unformat (i, "vrf %d", &inner_vrf_id))
3757 else if (unformat (i, "adj %U/%d", unformat_ip4_address,
3758 &intfc_address, &tmp))
3759 intfc_address_length = tmp;
3760 else if (unformat (i, "%U",
3761 unformat_sw_if_index, vam, &tx_sw_if_index))
3762 tx_sw_if_index_set = 1;
3763 else if (unformat (i, "tx_sw_if_index %d", &tx_sw_if_index))
3764 tx_sw_if_index_set = 1;
3765 else if (unformat (i, "dst %U", unformat_ethernet_address,
3768 else if (unformat (i, "l2-only"))
3770 else if (unformat (i, "del"))
3773 clib_warning ("parse error '%U'", format_unformat_error, i);
3779 errmsg ("dst (mac address) not set\n");
3782 if (!tx_sw_if_index_set) {
3783 errmsg ("tx-intfc not set\n");
3787 M(MPLS_ETHERNET_ADD_DEL_TUNNEL, mpls_ethernet_add_del_tunnel);
3789 mp->vrf_id = ntohl(inner_vrf_id);
3790 memcpy (mp->adj_address, &intfc_address, sizeof (intfc_address));
3791 mp->adj_address_length = intfc_address_length;
3792 memcpy (mp->dst_mac_address, dst_mac_address, sizeof (dst_mac_address));
3793 mp->tx_sw_if_index = ntohl(tx_sw_if_index);
3794 mp->l2_only = l2_only;
3795 mp->is_add = is_add;
3802 static int api_mpls_ethernet_add_del_tunnel_2 (vat_main_t * vam)
3804 unformat_input_t * i = vam->input;
3805 vl_api_mpls_ethernet_add_del_tunnel_2_t *mp;
3807 u32 inner_vrf_id = 0;
3808 u32 outer_vrf_id = 0;
3809 ip4_address_t adj_address;
3810 int adj_address_set = 0;
3811 ip4_address_t next_hop_address;
3812 int next_hop_address_set = 0;
3814 u8 adj_address_length = 0;
3817 u32 resolve_attempts = 5;
3818 u8 resolve_if_needed = 1;
3820 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
3821 if (unformat (i, "inner_vrf_id %d", &inner_vrf_id))
3823 else if (unformat (i, "outer_vrf_id %d", &outer_vrf_id))
3825 else if (unformat (i, "adj %U/%d", unformat_ip4_address,
3826 &adj_address, &tmp)) {
3827 adj_address_length = tmp;
3828 adj_address_set = 1;
3830 else if (unformat (i, "next-hop %U", unformat_ip4_address,
3832 next_hop_address_set = 1;
3833 else if (unformat (i, "resolve-attempts %d", &resolve_attempts))
3835 else if (unformat (i, "resolve-if-needed %d", &tmp))
3836 resolve_if_needed = tmp;
3837 else if (unformat (i, "l2-only"))
3839 else if (unformat (i, "del"))
3842 clib_warning ("parse error '%U'", format_unformat_error, i);
3847 if (!adj_address_set) {
3848 errmsg ("adjacency address/mask not set\n");
3851 if (!next_hop_address_set) {
3852 errmsg ("ip4 next hop address (in outer fib) not set\n");
3856 M(MPLS_ETHERNET_ADD_DEL_TUNNEL_2, mpls_ethernet_add_del_tunnel_2);
3858 mp->inner_vrf_id = ntohl(inner_vrf_id);
3859 mp->outer_vrf_id = ntohl(outer_vrf_id);
3860 mp->resolve_attempts = ntohl(resolve_attempts);
3861 mp->resolve_if_needed = resolve_if_needed;
3862 mp->is_add = is_add;
3863 mp->l2_only = l2_only;
3864 memcpy (mp->adj_address, &adj_address, sizeof (adj_address));
3865 mp->adj_address_length = adj_address_length;
3866 memcpy (mp->next_hop_ip4_address_in_outer_vrf, &next_hop_address,
3867 sizeof (next_hop_address));
3874 static int api_sw_interface_set_unnumbered (vat_main_t * vam)
3876 unformat_input_t * i = vam->input;
3877 vl_api_sw_interface_set_unnumbered_t *mp;
3882 u8 sw_if_index_set = 0;
3884 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
3885 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
3886 sw_if_index_set = 1;
3887 else if (unformat (i, "sw_if_index %d", &sw_if_index))
3888 sw_if_index_set = 1;
3889 else if (unformat (i, "unnum_if_index %d", &unnum_sw_index))
3891 else if (unformat (i, "del"))
3894 clib_warning ("parse error '%U'", format_unformat_error, i);
3899 if (sw_if_index_set == 0) {
3900 errmsg ("missing interface name or sw_if_index\n");
3904 M(SW_INTERFACE_SET_UNNUMBERED, sw_interface_set_unnumbered);
3906 mp->sw_if_index = ntohl(sw_if_index);
3907 mp->unnumbered_sw_if_index = ntohl(unnum_sw_index);
3908 mp->is_add = is_add;
3915 static int api_ip_neighbor_add_del (vat_main_t * vam)
3917 unformat_input_t * i = vam->input;
3918 vl_api_ip_neighbor_add_del_t *mp;
3921 u8 sw_if_index_set = 0;
3927 u8 v4_address_set = 0;
3928 u8 v6_address_set = 0;
3929 ip4_address_t v4address;
3930 ip6_address_t v6address;
3932 memset (mac_address, 0, sizeof (mac_address));
3934 /* Parse args required to build the message */
3935 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
3936 if (unformat (i, "mac %U", unformat_ethernet_address, mac_address)) {
3939 else if (unformat (i, "del"))
3941 else if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
3942 sw_if_index_set = 1;
3943 else if (unformat (i, "sw_if_index %d", &sw_if_index))
3944 sw_if_index_set = 1;
3945 else if (unformat (i, "is_static"))
3947 else if (unformat (i, "vrf %d", &vrf_id))
3949 else if (unformat (i, "dst %U",
3950 unformat_ip4_address, &v4address))
3952 else if (unformat (i, "dst %U",
3953 unformat_ip6_address, &v6address))
3956 clib_warning ("parse error '%U'", format_unformat_error, i);
3961 if (sw_if_index_set == 0) {
3962 errmsg ("missing interface name or sw_if_index\n");
3965 if (v4_address_set && v6_address_set) {
3966 errmsg ("both v4 and v6 addresses set\n");
3969 if (!v4_address_set && !v6_address_set) {
3970 errmsg ("no addresses set\n");
3974 /* Construct the API message */
3975 M(IP_NEIGHBOR_ADD_DEL, ip_neighbor_add_del);
3977 mp->sw_if_index = ntohl (sw_if_index);
3978 mp->is_add = is_add;
3979 mp->vrf_id = ntohl (vrf_id);
3980 mp->is_static = is_static;
3982 memcpy (mp->mac_address, mac_address, 6);
3983 if (v6_address_set) {
3985 memcpy (mp->dst_address, &v6address, sizeof (v6address));
3987 /* mp->is_ipv6 = 0; via memset in M macro above */
3988 memcpy (mp->dst_address, &v4address, sizeof (v4address));
3994 /* Wait for a reply, return good/bad news */
4001 static int api_reset_vrf (vat_main_t * vam)
4003 unformat_input_t * i = vam->input;
4004 vl_api_reset_vrf_t *mp;
4010 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
4011 if (unformat (i, "vrf %d", &vrf_id))
4013 else if (unformat (i, "ipv6"))
4016 clib_warning ("parse error '%U'", format_unformat_error, i);
4021 if (vrf_id_set == 0) {
4022 errmsg ("missing vrf id\n");
4026 M(RESET_VRF, reset_vrf);
4028 mp->vrf_id = ntohl(vrf_id);
4029 mp->is_ipv6 = is_ipv6;
4036 static int api_create_vlan_subif (vat_main_t * vam)
4038 unformat_input_t * i = vam->input;
4039 vl_api_create_vlan_subif_t *mp;
4042 u8 sw_if_index_set = 0;
4046 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
4047 if (unformat (i, "sw_if_index %d", &sw_if_index))
4048 sw_if_index_set = 1;
4049 else if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
4050 sw_if_index_set = 1;
4051 else if (unformat (i, "vlan %d", &vlan_id))
4054 clib_warning ("parse error '%U'", format_unformat_error, i);
4059 if (sw_if_index_set == 0) {
4060 errmsg ("missing interface name or sw_if_index\n");
4064 if (vlan_id_set == 0) {
4065 errmsg ("missing vlan_id\n");
4068 M(CREATE_VLAN_SUBIF, create_vlan_subif);
4070 mp->sw_if_index = ntohl(sw_if_index);
4071 mp->vlan_id = ntohl(vlan_id);
4078 #define foreach_create_subif_bit \
4085 _(outer_vlan_id_any) \
4086 _(inner_vlan_id_any)
4088 static int api_create_subif (vat_main_t * vam)
4090 unformat_input_t * i = vam->input;
4091 vl_api_create_subif_t *mp;
4094 u8 sw_if_index_set = 0;
4101 u32 exact_match = 0;
4102 u32 default_sub = 0;
4103 u32 outer_vlan_id_any = 0;
4104 u32 inner_vlan_id_any = 0;
4106 u16 outer_vlan_id = 0;
4107 u16 inner_vlan_id = 0;
4109 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
4110 if (unformat (i, "sw_if_index %d", &sw_if_index))
4111 sw_if_index_set = 1;
4112 else if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
4113 sw_if_index_set = 1;
4114 else if (unformat (i, "sub_id %d", &sub_id))
4116 else if (unformat (i, "outer_vlan_id %d", &tmp))
4117 outer_vlan_id = tmp;
4118 else if (unformat (i, "inner_vlan_id %d", &tmp))
4119 inner_vlan_id = tmp;
4121 #define _(a) else if (unformat (i, #a)) a = 1 ;
4122 foreach_create_subif_bit
4126 clib_warning ("parse error '%U'", format_unformat_error, i);
4131 if (sw_if_index_set == 0) {
4132 errmsg ("missing interface name or sw_if_index\n");
4136 if (sub_id_set == 0) {
4137 errmsg ("missing sub_id\n");
4140 M(CREATE_SUBIF, create_subif);
4142 mp->sw_if_index = ntohl(sw_if_index);
4143 mp->sub_id = ntohl(sub_id);
4145 #define _(a) mp->a = a;
4146 foreach_create_subif_bit;
4149 mp->outer_vlan_id = ntohs (outer_vlan_id);
4150 mp->inner_vlan_id = ntohs (inner_vlan_id);
4157 static int api_oam_add_del (vat_main_t * vam)
4159 unformat_input_t * i = vam->input;
4160 vl_api_oam_add_del_t *mp;
4164 ip4_address_t src, dst;
4168 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
4169 if (unformat (i, "vrf %d", &vrf_id))
4171 else if (unformat (i, "src %U", unformat_ip4_address, &src))
4173 else if (unformat (i, "dst %U", unformat_ip4_address, &dst))
4175 else if (unformat (i, "del"))
4178 clib_warning ("parse error '%U'", format_unformat_error, i);
4184 errmsg ("missing src addr\n");
4189 errmsg ("missing dst addr\n");
4193 M(OAM_ADD_DEL, oam_add_del);
4195 mp->vrf_id = ntohl(vrf_id);
4196 mp->is_add = is_add;
4197 memcpy(mp->src_address, &src, sizeof (mp->src_address));
4198 memcpy(mp->dst_address, &dst, sizeof (mp->dst_address));
4205 static int api_reset_fib (vat_main_t * vam)
4207 unformat_input_t * i = vam->input;
4208 vl_api_reset_fib_t *mp;
4214 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
4215 if (unformat (i, "vrf %d", &vrf_id))
4217 else if (unformat (i, "ipv6"))
4220 clib_warning ("parse error '%U'", format_unformat_error, i);
4225 if (vrf_id_set == 0) {
4226 errmsg ("missing vrf id\n");
4230 M(RESET_FIB, reset_fib);
4232 mp->vrf_id = ntohl(vrf_id);
4233 mp->is_ipv6 = is_ipv6;
4240 static int api_dhcp_proxy_config (vat_main_t * vam)
4242 unformat_input_t * i = vam->input;
4243 vl_api_dhcp_proxy_config_t *mp;
4248 u8 v4_address_set = 0;
4249 u8 v6_address_set = 0;
4250 ip4_address_t v4address;
4251 ip6_address_t v6address;
4252 u8 v4_src_address_set = 0;
4253 u8 v6_src_address_set = 0;
4254 ip4_address_t v4srcaddress;
4255 ip6_address_t v6srcaddress;
4257 /* Parse args required to build the message */
4258 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
4259 if (unformat (i, "del"))
4261 else if (unformat (i, "vrf %d", &vrf_id))
4263 else if (unformat (i, "insert-cid %d", &insert_cid))
4265 else if (unformat (i, "svr %U",
4266 unformat_ip4_address, &v4address))
4268 else if (unformat (i, "svr %U",
4269 unformat_ip6_address, &v6address))
4271 else if (unformat (i, "src %U",
4272 unformat_ip4_address, &v4srcaddress))
4273 v4_src_address_set = 1;
4274 else if (unformat (i, "src %U",
4275 unformat_ip6_address, &v6srcaddress))
4276 v6_src_address_set = 1;
4281 if (v4_address_set && v6_address_set) {
4282 errmsg ("both v4 and v6 server addresses set\n");
4285 if (!v4_address_set && !v6_address_set) {
4286 errmsg ("no server addresses set\n");
4290 if (v4_src_address_set && v6_src_address_set) {
4291 errmsg ("both v4 and v6 src addresses set\n");
4294 if (!v4_src_address_set && !v6_src_address_set) {
4295 errmsg ("no src addresses set\n");
4299 if (!(v4_src_address_set && v4_address_set) &&
4300 !(v6_src_address_set && v6_address_set)) {
4301 errmsg ("no matching server and src addresses set\n");
4305 /* Construct the API message */
4306 M(DHCP_PROXY_CONFIG, dhcp_proxy_config);
4308 mp->insert_circuit_id = insert_cid;
4309 mp->is_add = is_add;
4310 mp->vrf_id = ntohl (vrf_id);
4311 if (v6_address_set) {
4313 memcpy (mp->dhcp_server, &v6address, sizeof (v6address));
4314 memcpy (mp->dhcp_src_address, &v6srcaddress, sizeof (v6address));
4316 memcpy (mp->dhcp_server, &v4address, sizeof (v4address));
4317 memcpy (mp->dhcp_src_address, &v4srcaddress, sizeof (v4address));
4323 /* Wait for a reply, return good/bad news */
4329 static int api_dhcp_proxy_config_2 (vat_main_t * vam)
4331 unformat_input_t * i = vam->input;
4332 vl_api_dhcp_proxy_config_2_t *mp;
4335 u32 server_vrf_id = 0;
4338 u8 v4_address_set = 0;
4339 u8 v6_address_set = 0;
4340 ip4_address_t v4address;
4341 ip6_address_t v6address;
4342 u8 v4_src_address_set = 0;
4343 u8 v6_src_address_set = 0;
4344 ip4_address_t v4srcaddress;
4345 ip6_address_t v6srcaddress;
4347 /* Parse args required to build the message */
4348 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
4349 if (unformat (i, "del"))
4351 else if (unformat (i, "rx_vrf_id %d", &rx_vrf_id))
4353 else if (unformat (i, "server_vrf_id %d", &server_vrf_id))
4355 else if (unformat (i, "insert-cid %d", &insert_cid))
4357 else if (unformat (i, "svr %U",
4358 unformat_ip4_address, &v4address))
4360 else if (unformat (i, "svr %U",
4361 unformat_ip6_address, &v6address))
4363 else if (unformat (i, "src %U",
4364 unformat_ip4_address, &v4srcaddress))
4365 v4_src_address_set = 1;
4366 else if (unformat (i, "src %U",
4367 unformat_ip6_address, &v6srcaddress))
4368 v6_src_address_set = 1;
4373 if (v4_address_set && v6_address_set) {
4374 errmsg ("both v4 and v6 server addresses set\n");
4377 if (!v4_address_set && !v6_address_set) {
4378 errmsg ("no server addresses set\n");
4382 if (v4_src_address_set && v6_src_address_set) {
4383 errmsg ("both v4 and v6 src addresses set\n");
4386 if (!v4_src_address_set && !v6_src_address_set) {
4387 errmsg ("no src addresses set\n");
4391 if (!(v4_src_address_set && v4_address_set) &&
4392 !(v6_src_address_set && v6_address_set)) {
4393 errmsg ("no matching server and src addresses set\n");
4397 /* Construct the API message */
4398 M(DHCP_PROXY_CONFIG_2, dhcp_proxy_config_2);
4400 mp->insert_circuit_id = insert_cid;
4401 mp->is_add = is_add;
4402 mp->rx_vrf_id = ntohl (rx_vrf_id);
4403 mp->server_vrf_id = ntohl (server_vrf_id);
4404 if (v6_address_set) {
4406 memcpy (mp->dhcp_server, &v6address, sizeof (v6address));
4407 memcpy (mp->dhcp_src_address, &v6srcaddress, sizeof (v6address));
4409 memcpy (mp->dhcp_server, &v4address, sizeof (v4address));
4410 memcpy (mp->dhcp_src_address, &v4srcaddress, sizeof (v4address));
4416 /* Wait for a reply, return good/bad news */
4422 static int api_dhcp_proxy_set_vss (vat_main_t * vam)
4424 unformat_input_t * i = vam->input;
4425 vl_api_dhcp_proxy_set_vss_t *mp;
4436 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
4437 if (unformat (i, "tbl_id %d", &tbl_id))
4439 if (unformat (i, "fib_id %d", &fib_id))
4441 if (unformat (i, "oui %d", &oui))
4443 else if (unformat (i, "ipv6"))
4445 else if (unformat (i, "del"))
4448 clib_warning ("parse error '%U'", format_unformat_error, i);
4453 if (tbl_id_set == 0) {
4454 errmsg ("missing tbl id\n");
4458 if (fib_id_set == 0) {
4459 errmsg ("missing fib id\n");
4463 errmsg ("missing oui\n");
4467 M(DHCP_PROXY_SET_VSS, dhcp_proxy_set_vss);
4468 mp->tbl_id = ntohl(tbl_id);
4469 mp->fib_id = ntohl(fib_id);
4470 mp->oui = ntohl(oui);
4471 mp->is_ipv6 = is_ipv6;
4472 mp->is_add = is_add;
4479 static int api_dhcp_client_config (vat_main_t * vam)
4481 unformat_input_t * i = vam->input;
4482 vl_api_dhcp_client_config_t *mp;
4485 u8 sw_if_index_set = 0;
4488 u8 disable_event = 0;
4490 /* Parse args required to build the message */
4491 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
4492 if (unformat (i, "del"))
4494 else if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
4495 sw_if_index_set = 1;
4496 else if (unformat (i, "sw_if_index %d", &sw_if_index))
4497 sw_if_index_set = 1;
4498 else if (unformat (i, "hostname %s", &hostname))
4500 else if (unformat (i, "disable_event"))
4506 if (sw_if_index_set == 0) {
4507 errmsg ("missing interface name or sw_if_index\n");
4511 if (vec_len (hostname) > 63) {
4512 errmsg ("hostname too long\n");
4514 vec_add1 (hostname, 0);
4516 /* Construct the API message */
4517 M(DHCP_CLIENT_CONFIG, dhcp_client_config);
4519 mp->sw_if_index = ntohl (sw_if_index);
4520 memcpy (mp->hostname, hostname, vec_len (hostname));
4521 vec_free (hostname);
4522 mp->is_add = is_add;
4523 mp->want_dhcp_event = disable_event ? 0 : 1;
4529 /* Wait for a reply, return good/bad news */
4535 static int api_set_ip_flow_hash (vat_main_t * vam)
4537 unformat_input_t * i = vam->input;
4538 vl_api_set_ip_flow_hash_t *mp;
4550 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
4551 if (unformat (i, "vrf %d", &vrf_id))
4553 else if (unformat (i, "ipv6"))
4555 else if (unformat (i, "src"))
4557 else if (unformat (i, "dst"))
4559 else if (unformat (i, "sport"))
4561 else if (unformat (i, "dport"))
4563 else if (unformat (i, "proto"))
4565 else if (unformat (i, "reverse"))
4569 clib_warning ("parse error '%U'", format_unformat_error, i);
4574 if (vrf_id_set == 0) {
4575 errmsg ("missing vrf id\n");
4579 M(SET_IP_FLOW_HASH, set_ip_flow_hash);
4585 mp->reverse = reverse;
4586 mp->vrf_id = ntohl(vrf_id);
4587 mp->is_ipv6 = is_ipv6;
4594 static int api_sw_interface_ip6_enable_disable (vat_main_t * vam)
4596 unformat_input_t * i = vam->input;
4597 vl_api_sw_interface_ip6_enable_disable_t *mp;
4600 u8 sw_if_index_set = 0;
4603 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
4604 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
4605 sw_if_index_set = 1;
4606 else if (unformat (i, "sw_if_index %d", &sw_if_index))
4607 sw_if_index_set = 1;
4608 else if (unformat (i, "enable"))
4610 else if (unformat (i, "disable"))
4613 clib_warning ("parse error '%U'", format_unformat_error, i);
4618 if (sw_if_index_set == 0) {
4619 errmsg ("missing interface name or sw_if_index\n");
4623 M(SW_INTERFACE_IP6_ENABLE_DISABLE, sw_interface_ip6_enable_disable);
4625 mp->sw_if_index = ntohl(sw_if_index);
4626 mp->enable = enable;
4633 static int api_sw_interface_ip6_set_link_local_address (vat_main_t * vam)
4635 unformat_input_t * i = vam->input;
4636 vl_api_sw_interface_ip6_set_link_local_address_t *mp;
4639 u8 sw_if_index_set = 0;
4640 u32 address_length = 0;
4641 u8 v6_address_set = 0;
4642 ip6_address_t v6address;
4644 /* Parse args required to build the message */
4645 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
4646 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
4647 sw_if_index_set = 1;
4648 else if (unformat (i, "sw_if_index %d", &sw_if_index))
4649 sw_if_index_set = 1;
4650 else if (unformat (i, "%U/%d",
4651 unformat_ip6_address, &v6address,
4658 if (sw_if_index_set == 0) {
4659 errmsg ("missing interface name or sw_if_index\n");
4662 if (!v6_address_set) {
4663 errmsg ("no address set\n");
4667 /* Construct the API message */
4668 M(SW_INTERFACE_IP6_SET_LINK_LOCAL_ADDRESS, \
4669 sw_interface_ip6_set_link_local_address);
4671 mp->sw_if_index = ntohl (sw_if_index);
4672 memcpy (mp->address, &v6address, sizeof (v6address));
4673 mp->address_length = address_length;
4678 /* Wait for a reply, return good/bad news */
4686 static int api_sw_interface_ip6nd_ra_prefix (vat_main_t * vam)
4688 unformat_input_t * i = vam->input;
4689 vl_api_sw_interface_ip6nd_ra_prefix_t *mp;
4692 u8 sw_if_index_set = 0;
4693 u32 address_length = 0;
4694 u8 v6_address_set = 0;
4695 ip6_address_t v6address;
4697 u8 no_advertise = 0;
4699 u8 no_autoconfig = 0;
4702 u32 val_lifetime = 0;
4703 u32 pref_lifetime = 0;
4705 /* Parse args required to build the message */
4706 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
4707 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
4708 sw_if_index_set = 1;
4709 else if (unformat (i, "sw_if_index %d", &sw_if_index))
4710 sw_if_index_set = 1;
4711 else if (unformat (i, "%U/%d",
4712 unformat_ip6_address, &v6address,
4715 else if (unformat (i, "val_life %d", &val_lifetime))
4717 else if (unformat (i, "pref_life %d", &pref_lifetime))
4719 else if (unformat (i, "def"))
4721 else if (unformat (i, "noadv"))
4723 else if (unformat (i, "offl"))
4725 else if (unformat (i, "noauto"))
4727 else if (unformat (i, "nolink"))
4729 else if (unformat (i, "isno"))
4732 clib_warning ("parse error '%U'", format_unformat_error, i);
4737 if (sw_if_index_set == 0) {
4738 errmsg ("missing interface name or sw_if_index\n");
4741 if (!v6_address_set) {
4742 errmsg ("no address set\n");
4746 /* Construct the API message */
4747 M(SW_INTERFACE_IP6ND_RA_PREFIX, sw_interface_ip6nd_ra_prefix);
4749 mp->sw_if_index = ntohl (sw_if_index);
4750 memcpy (mp->address, &v6address, sizeof (v6address));
4751 mp->address_length = address_length;
4752 mp->use_default = use_default;
4753 mp->no_advertise = no_advertise;
4754 mp->off_link = off_link;
4755 mp->no_autoconfig = no_autoconfig;
4756 mp->no_onlink = no_onlink;
4758 mp->val_lifetime = ntohl(val_lifetime);
4759 mp->pref_lifetime = ntohl(pref_lifetime);
4764 /* Wait for a reply, return good/bad news */
4771 static int api_sw_interface_ip6nd_ra_config (vat_main_t * vam)
4773 unformat_input_t * i = vam->input;
4774 vl_api_sw_interface_ip6nd_ra_config_t *mp;
4777 u8 sw_if_index_set = 0;
4782 u8 send_unicast = 0;
4785 u8 default_router = 0;
4786 u32 max_interval = 0;
4787 u32 min_interval = 0;
4789 u32 initial_count = 0;
4790 u32 initial_interval = 0;
4793 /* Parse args required to build the message */
4794 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
4795 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
4796 sw_if_index_set = 1;
4797 else if (unformat (i, "sw_if_index %d", &sw_if_index))
4798 sw_if_index_set = 1;
4799 else if (unformat (i, "maxint %d", &max_interval))
4801 else if (unformat (i, "minint %d", &min_interval))
4803 else if (unformat (i, "life %d", &lifetime))
4805 else if (unformat (i, "count %d", &initial_count))
4807 else if (unformat (i, "interval %d", &initial_interval))
4809 else if (unformat (i, "surpress"))
4811 else if (unformat (i, "managed"))
4813 else if (unformat (i, "other"))
4815 else if (unformat (i, "ll"))
4817 else if (unformat (i, "send"))
4819 else if (unformat (i, "cease"))
4821 else if (unformat (i, "isno"))
4823 else if (unformat (i, "def"))
4826 clib_warning ("parse error '%U'", format_unformat_error, i);
4831 if (sw_if_index_set == 0) {
4832 errmsg ("missing interface name or sw_if_index\n");
4836 /* Construct the API message */
4837 M(SW_INTERFACE_IP6ND_RA_CONFIG, sw_interface_ip6nd_ra_config);
4839 mp->sw_if_index = ntohl (sw_if_index);
4840 mp->max_interval = ntohl(max_interval);
4841 mp->min_interval = ntohl(min_interval);
4842 mp->lifetime = ntohl(lifetime);
4843 mp->initial_count = ntohl(initial_count);
4844 mp->initial_interval = ntohl(initial_interval);
4845 mp->surpress = surpress;
4846 mp->managed = managed;
4848 mp->ll_option = ll_option;
4849 mp->send_unicast = send_unicast;
4852 mp->default_router = default_router;
4857 /* Wait for a reply, return good/bad news */
4864 static int api_set_arp_neighbor_limit (vat_main_t * vam)
4866 unformat_input_t * i = vam->input;
4867 vl_api_set_arp_neighbor_limit_t *mp;
4873 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
4874 if (unformat (i, "arp_nbr_limit %d", &arp_nbr_limit))
4876 else if (unformat (i, "ipv6"))
4879 clib_warning ("parse error '%U'", format_unformat_error, i);
4884 if (limit_set == 0) {
4885 errmsg ("missing limit value\n");
4889 M(SET_ARP_NEIGHBOR_LIMIT, set_arp_neighbor_limit);
4891 mp->arp_neighbor_limit = ntohl(arp_nbr_limit);
4892 mp->is_ipv6 = is_ipv6;
4899 static int api_l2_patch_add_del (vat_main_t * vam)
4901 unformat_input_t * i = vam->input;
4902 vl_api_l2_patch_add_del_t *mp;
4905 u8 rx_sw_if_index_set = 0;
4907 u8 tx_sw_if_index_set = 0;
4910 /* Parse args required to build the message */
4911 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
4912 if (unformat (i, "rx_sw_if_index %d", &rx_sw_if_index))
4913 rx_sw_if_index_set = 1;
4914 else if (unformat (i, "tx_sw_if_index %d", &tx_sw_if_index))
4915 tx_sw_if_index_set = 1;
4916 else if (unformat (i, "rx")) {
4917 if (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
4918 if (unformat (i, "%U", unformat_sw_if_index, vam,
4920 rx_sw_if_index_set = 1;
4923 } else if (unformat (i, "tx")) {
4924 if (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
4925 if (unformat (i, "%U", unformat_sw_if_index, vam,
4927 tx_sw_if_index_set = 1;
4930 } else if (unformat (i, "del"))
4936 if (rx_sw_if_index_set == 0) {
4937 errmsg ("missing rx interface name or rx_sw_if_index\n");
4941 if (tx_sw_if_index_set == 0) {
4942 errmsg ("missing tx interface name or tx_sw_if_index\n");
4946 M(L2_PATCH_ADD_DEL, l2_patch_add_del);
4948 mp->rx_sw_if_index = ntohl(rx_sw_if_index);
4949 mp->tx_sw_if_index = ntohl(tx_sw_if_index);
4950 mp->is_add = is_add;
4957 static int api_sr_tunnel_add_del (vat_main_t * vam)
4959 unformat_input_t * i = vam->input;
4960 vl_api_sr_tunnel_add_del_t *mp;
4964 ip6_address_t src_address;
4965 int src_address_set = 0;
4966 ip6_address_t dst_address;
4968 int dst_address_set = 0;
4970 u32 rx_table_id = 0;
4971 u32 tx_table_id = 0;
4972 ip6_address_t * segments = 0;
4973 ip6_address_t * this_seg;
4974 ip6_address_t * tags = 0;
4975 ip6_address_t * this_tag;
4976 ip6_address_t next_address, tag;
4978 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
4980 if (unformat (i, "del"))
4982 else if (unformat (i, "rx_fib_id %d", &rx_table_id))
4984 else if (unformat (i, "tx_fib_id %d", &tx_table_id))
4986 else if (unformat (i, "src %U", unformat_ip6_address, &src_address))
4987 src_address_set = 1;
4988 else if (unformat (i, "dst %U/%d",
4989 unformat_ip6_address, &dst_address,
4991 dst_address_set = 1;
4992 else if (unformat (i, "next %U", unformat_ip6_address,
4995 vec_add2 (segments, this_seg, 1);
4996 memcpy (this_seg->as_u8, next_address.as_u8, sizeof (*this_seg));
4998 else if (unformat (i, "tag %U", unformat_ip6_address,
5001 vec_add2 (tags, this_tag, 1);
5002 memcpy (this_tag->as_u8, tag.as_u8, sizeof (*this_tag));
5004 else if (unformat (i, "clean"))
5005 flags |= IP6_SR_HEADER_FLAG_CLEANUP;
5006 else if (unformat (i, "protected"))
5007 flags |= IP6_SR_HEADER_FLAG_PROTECTED;
5008 else if (unformat (i, "InPE %d", &pl_index))
5010 if (pl_index <= 0 || pl_index > 4)
5012 pl_index_range_error:
5013 errmsg ("pl index %d out of range\n", pl_index);
5016 flags |= IP6_SR_HEADER_FLAG_PL_ELT_INGRESS_PE << (3*(pl_index - 1));
5018 else if (unformat (i, "EgPE %d", &pl_index))
5020 if (pl_index <= 0 || pl_index > 4)
5021 goto pl_index_range_error;
5022 flags |= IP6_SR_HEADER_FLAG_PL_ELT_EGRESS_PE << (3*(pl_index - 1));
5024 else if (unformat (i, "OrgSrc %d", &pl_index))
5026 if (pl_index <= 0 || pl_index > 4)
5027 goto pl_index_range_error;
5028 flags |= IP6_SR_HEADER_FLAG_PL_ELT_ORIG_SRC_ADDR << (3*(pl_index - 1));
5034 if (!src_address_set)
5036 errmsg ("src address required\n");
5040 if (!dst_address_set)
5042 errmsg ("dst address required\n");
5048 errmsg ("at least one sr segment required\n");
5052 M2(SR_TUNNEL_ADD_DEL, sr_tunnel_add_del,
5053 vec_len(segments) * sizeof (ip6_address_t)
5054 + vec_len(tags) * sizeof (ip6_address_t));
5056 memcpy (mp->src_address, &src_address, sizeof (mp->src_address));
5057 memcpy (mp->dst_address, &dst_address, sizeof (mp->dst_address));
5058 mp->dst_mask_width = dst_mask_width;
5059 mp->flags_net_byte_order = clib_host_to_net_u16 (flags);
5060 mp->n_segments = vec_len (segments);
5061 mp->n_tags = vec_len (tags);
5062 mp->is_add = is_del == 0;
5063 memcpy (mp->segs_and_tags, segments,
5064 vec_len(segments)* sizeof (ip6_address_t));
5065 memcpy (mp->segs_and_tags + vec_len(segments)*sizeof (ip6_address_t),
5066 tags, vec_len(tags)* sizeof (ip6_address_t));
5068 mp->outer_vrf_id = ntohl (rx_table_id);
5069 mp->inner_vrf_id = ntohl (tx_table_id);
5071 vec_free (segments);
5079 #define foreach_ip4_proto_field \
5089 uword unformat_ip4_mask (unformat_input_t * input, va_list * args)
5091 u8 ** maskp = va_arg (*args, u8 **);
5093 u8 found_something = 0;
5096 #define _(a) u8 a=0;
5097 foreach_ip4_proto_field;
5103 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
5105 if (unformat (input, "version"))
5107 else if (unformat (input, "hdr_length"))
5109 else if (unformat (input, "src"))
5111 else if (unformat (input, "dst"))
5113 else if (unformat (input, "proto"))
5116 #define _(a) else if (unformat (input, #a)) a=1;
5117 foreach_ip4_proto_field
5123 #define _(a) found_something += a;
5124 foreach_ip4_proto_field;
5127 if (found_something == 0)
5130 vec_validate (mask, sizeof (*ip) - 1);
5132 ip = (ip4_header_t *) mask;
5134 #define _(a) if (a) memset (&ip->a, 0xff, sizeof (ip->a));
5135 foreach_ip4_proto_field;
5138 ip->ip_version_and_header_length = 0;
5141 ip->ip_version_and_header_length |= 0xF0;
5144 ip->ip_version_and_header_length |= 0x0F;
5150 #define foreach_ip6_proto_field \
5157 uword unformat_ip6_mask (unformat_input_t * input, va_list * args)
5159 u8 ** maskp = va_arg (*args, u8 **);
5161 u8 found_something = 0;
5163 u32 ip_version_traffic_class_and_flow_label;
5165 #define _(a) u8 a=0;
5166 foreach_ip6_proto_field;
5169 u8 traffic_class = 0;
5172 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
5174 if (unformat (input, "version"))
5176 else if (unformat (input, "traffic-class"))
5178 else if (unformat (input, "flow-label"))
5180 else if (unformat (input, "src"))
5182 else if (unformat (input, "dst"))
5184 else if (unformat (input, "proto"))
5187 #define _(a) else if (unformat (input, #a)) a=1;
5188 foreach_ip6_proto_field
5194 #define _(a) found_something += a;
5195 foreach_ip6_proto_field;
5198 if (found_something == 0)
5201 vec_validate (mask, sizeof (*ip) - 1);
5203 ip = (ip6_header_t *) mask;
5205 #define _(a) if (a) memset (&ip->a, 0xff, sizeof (ip->a));
5206 foreach_ip6_proto_field;
5209 ip_version_traffic_class_and_flow_label = 0;
5212 ip_version_traffic_class_and_flow_label |= 0xF0000000;
5215 ip_version_traffic_class_and_flow_label |= 0x0FF00000;
5218 ip_version_traffic_class_and_flow_label |= 0x000FFFFF;
5220 ip->ip_version_traffic_class_and_flow_label =
5221 clib_host_to_net_u32 (ip_version_traffic_class_and_flow_label);
5227 uword unformat_l3_mask (unformat_input_t * input, va_list * args)
5229 u8 ** maskp = va_arg (*args, u8 **);
5231 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) {
5232 if (unformat (input, "ip4 %U", unformat_ip4_mask, maskp))
5234 else if (unformat (input, "ip6 %U", unformat_ip6_mask, maskp))
5242 uword unformat_l2_mask (unformat_input_t * input, va_list * args)
5244 u8 ** maskp = va_arg (*args, u8 **);
5259 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) {
5260 if (unformat (input, "src"))
5262 else if (unformat (input, "dst"))
5264 else if (unformat (input, "proto"))
5266 else if (unformat (input, "tag1"))
5268 else if (unformat (input, "tag2"))
5270 else if (unformat (input, "ignore-tag1"))
5272 else if (unformat (input, "ignore-tag2"))
5274 else if (unformat (input, "cos1"))
5276 else if (unformat (input, "cos2"))
5278 else if (unformat (input, "dot1q"))
5280 else if (unformat (input, "dot1ad"))
5285 if ((src + dst + proto + tag1 + tag2 + dot1q + dot1ad +
5286 ignore_tag1 + ignore_tag2 + cos1 + cos2) == 0)
5289 if (tag1 || ignore_tag1 || cos1 || dot1q)
5291 if (tag2 || ignore_tag2 || cos2 || dot1ad)
5294 vec_validate (mask, len-1);
5297 memset (mask, 0xff, 6);
5300 memset (mask + 6, 0xff, 6);
5304 /* inner vlan tag */
5313 mask[21] = mask [20] = 0xff;
5334 mask[16] = mask [17] = 0xff;
5344 mask[12] = mask [13] = 0xff;
5350 uword unformat_classify_mask (unformat_input_t * input, va_list * args)
5352 u8 ** maskp = va_arg (*args, u8 **);
5353 u32 * skipp = va_arg (*args, u32 *);
5354 u32 * matchp = va_arg (*args, u32 *);
5361 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) {
5362 if (unformat (input, "hex %U", unformat_hex_string, &mask))
5364 else if (unformat (input, "l2 %U", unformat_l2_mask, &l2))
5366 else if (unformat (input, "l3 %U", unformat_l3_mask, &l3))
5372 if (mask || l2 || l3)
5376 /* "With a free Ethernet header in every package" */
5378 vec_validate (l2, 13);
5380 vec_append (mask, l3);
5384 /* Scan forward looking for the first significant mask octet */
5385 for (i = 0; i < vec_len (mask); i++)
5389 /* compute (skip, match) params */
5390 *skipp = i / sizeof(u32x4);
5391 vec_delete (mask, *skipp * sizeof(u32x4), 0);
5393 /* Pad mask to an even multiple of the vector size */
5394 while (vec_len (mask) % sizeof (u32x4))
5397 match = vec_len (mask) / sizeof (u32x4);
5399 for (i = match*sizeof(u32x4); i > 0; i-= sizeof(u32x4))
5401 u64 *tmp = (u64 *)(mask + (i-sizeof(u32x4)));
5402 if (*tmp || *(tmp+1))
5407 clib_warning ("BUG: match 0");
5409 _vec_len (mask) = match * sizeof(u32x4);
5420 #define foreach_l2_next \
5422 _(ethernet, ETHERNET_INPUT) \
5426 uword unformat_l2_next_index (unformat_input_t * input, va_list * args)
5428 u32 * miss_next_indexp = va_arg (*args, u32 *);
5433 if (unformat (input, #n)) { next_index = L2_CLASSIFY_NEXT_##N; goto out;}
5437 if (unformat (input, "%d", &tmp))
5446 *miss_next_indexp = next_index;
5450 #define foreach_ip_next \
5456 uword unformat_ip_next_index (unformat_input_t * input, va_list * args)
5458 u32 * miss_next_indexp = va_arg (*args, u32 *);
5463 if (unformat (input, #n)) { next_index = IP_LOOKUP_NEXT_##N; goto out;}
5467 if (unformat (input, "%d", &tmp))
5476 *miss_next_indexp = next_index;
5480 #define foreach_acl_next \
5483 uword unformat_acl_next_index (unformat_input_t * input, va_list * args)
5485 u32 * miss_next_indexp = va_arg (*args, u32 *);
5490 if (unformat (input, #n)) { next_index = ACL_NEXT_INDEX_##N; goto out;}
5494 if (unformat (input, "permit"))
5499 else if (unformat (input, "%d", &tmp))
5508 *miss_next_indexp = next_index;
5512 static int api_classify_add_del_table (vat_main_t * vam)
5514 unformat_input_t * i = vam->input;
5515 vl_api_classify_add_del_table_t *mp;
5521 u32 table_index = ~0;
5522 u32 next_table_index = ~0;
5523 u32 miss_next_index = ~0;
5524 u32 memory_size = 32<<20;
5528 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
5529 if (unformat (i, "del"))
5531 else if (unformat (i, "buckets %d", &nbuckets))
5533 else if (unformat (i, "memory_size %d", &memory_size))
5535 else if (unformat (i, "skip %d", &skip))
5537 else if (unformat (i, "match %d", &match))
5539 else if (unformat (i, "table %d", &table_index))
5541 else if (unformat (i, "mask %U", unformat_classify_mask,
5542 &mask, &skip, &match))
5544 else if (unformat (i, "next-table %d", &next_table_index))
5546 else if (unformat (i, "miss-next %U", unformat_ip_next_index,
5549 else if (unformat (i, "l2-miss-next %U", unformat_l2_next_index,
5552 else if (unformat (i, "acl-miss-next %U", unformat_acl_next_index,
5559 if (is_add && mask == 0) {
5560 errmsg ("Mask required\n");
5564 if (is_add && skip == ~0) {
5565 errmsg ("skip count required\n");
5569 if (is_add && match == ~0) {
5570 errmsg ("match count required\n");
5574 if (!is_add && table_index == ~0) {
5575 errmsg ("table index required for delete\n");
5579 M2 (CLASSIFY_ADD_DEL_TABLE, classify_add_del_table,
5582 mp->is_add = is_add;
5583 mp->table_index = ntohl(table_index);
5584 mp->nbuckets = ntohl(nbuckets);
5585 mp->memory_size = ntohl(memory_size);
5586 mp->skip_n_vectors = ntohl(skip);
5587 mp->match_n_vectors = ntohl(match);
5588 mp->next_table_index = ntohl(next_table_index);
5589 mp->miss_next_index = ntohl(miss_next_index);
5590 memcpy (mp->mask, mask, vec_len(mask));
5598 uword unformat_ip4_match (unformat_input_t * input, va_list * args)
5600 u8 ** matchp = va_arg (*args, u8 **);
5607 int src = 0, dst = 0;
5608 ip4_address_t src_val, dst_val;
5615 int fragment_id = 0;
5616 u32 fragment_id_val;
5622 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
5624 if (unformat (input, "version %d", &version_val))
5626 else if (unformat (input, "hdr_length %d", &hdr_length_val))
5628 else if (unformat (input, "src %U", unformat_ip4_address, &src_val))
5630 else if (unformat (input, "dst %U", unformat_ip4_address, &dst_val))
5632 else if (unformat (input, "proto %d", &proto_val))
5634 else if (unformat (input, "tos %d", &tos_val))
5636 else if (unformat (input, "length %d", &length_val))
5638 else if (unformat (input, "fragment_id %d", &fragment_id_val))
5640 else if (unformat (input, "ttl %d", &ttl_val))
5642 else if (unformat (input, "checksum %d", &checksum_val))
5648 if (version + hdr_length + src + dst + proto + tos + length + fragment_id
5649 + ttl + checksum == 0)
5653 * Aligned because we use the real comparison functions
5655 vec_validate_aligned (match, sizeof (*ip) - 1, sizeof(u32x4));
5657 ip = (ip4_header_t *) match;
5659 /* These are realistically matched in practice */
5661 ip->src_address.as_u32 = src_val.as_u32;
5664 ip->dst_address.as_u32 = dst_val.as_u32;
5667 ip->protocol = proto_val;
5670 /* These are not, but they're included for completeness */
5672 ip->ip_version_and_header_length |= (version_val & 0xF)<<4;
5675 ip->ip_version_and_header_length |= (hdr_length_val & 0xF);
5681 ip->length = length_val;
5687 ip->checksum = checksum_val;
5693 uword unformat_ip6_match (unformat_input_t * input, va_list * args)
5695 u8 ** matchp = va_arg (*args, u8 **);
5701 u32 traffic_class_val;
5704 int src = 0, dst = 0;
5705 ip6_address_t src_val, dst_val;
5708 int payload_length = 0;
5709 u32 payload_length_val;
5712 u32 ip_version_traffic_class_and_flow_label;
5714 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
5716 if (unformat (input, "version %d", &version_val))
5718 else if (unformat (input, "traffic_class %d", &traffic_class_val))
5720 else if (unformat (input, "flow_label %d", &flow_label_val))
5722 else if (unformat (input, "src %U", unformat_ip6_address, &src_val))
5724 else if (unformat (input, "dst %U", unformat_ip6_address, &dst_val))
5726 else if (unformat (input, "proto %d", &proto_val))
5728 else if (unformat (input, "payload_length %d", &payload_length_val))
5730 else if (unformat (input, "hop_limit %d", &hop_limit_val))
5736 if (version + traffic_class + flow_label + src + dst + proto +
5737 payload_length + hop_limit == 0)
5741 * Aligned because we use the real comparison functions
5743 vec_validate_aligned (match, sizeof (*ip) - 1, sizeof(u32x4));
5745 ip = (ip6_header_t *) match;
5748 memcpy (&ip->src_address, &src_val, sizeof (ip->src_address));
5751 memcpy (&ip->dst_address, &dst_val, sizeof (ip->dst_address));
5754 ip->protocol = proto_val;
5756 ip_version_traffic_class_and_flow_label = 0;
5759 ip_version_traffic_class_and_flow_label |= (version_val & 0xF) << 28;
5762 ip_version_traffic_class_and_flow_label |= (traffic_class_val & 0xFF) << 20;
5765 ip_version_traffic_class_and_flow_label |= (flow_label_val & 0xFFFFF);
5767 ip->ip_version_traffic_class_and_flow_label =
5768 clib_host_to_net_u32 (ip_version_traffic_class_and_flow_label);
5771 ip->payload_length = clib_host_to_net_u16 (payload_length_val);
5774 ip->hop_limit = hop_limit_val;
5780 uword unformat_l3_match (unformat_input_t * input, va_list * args)
5782 u8 ** matchp = va_arg (*args, u8 **);
5784 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) {
5785 if (unformat (input, "ip4 %U", unformat_ip4_match, matchp))
5787 else if (unformat (input, "ip6 %U", unformat_ip6_match, matchp))
5795 uword unformat_vlan_tag (unformat_input_t * input, va_list * args)
5797 u8 * tagp = va_arg (*args, u8 *);
5800 if (unformat(input, "%d", &tag))
5802 tagp[0] = (tag>>8) & 0x0F;
5803 tagp[1] = tag & 0xFF;
5810 uword unformat_l2_match (unformat_input_t * input, va_list * args)
5812 u8 ** matchp = va_arg (*args, u8 **);
5832 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) {
5833 if (unformat (input, "src %U", unformat_ethernet_address, &src_val))
5835 else if (unformat (input, "dst %U", unformat_ethernet_address, &dst_val))
5837 else if (unformat (input, "proto %U",
5838 unformat_ethernet_type_host_byte_order, &proto_val))
5840 else if (unformat (input, "tag1 %U", unformat_vlan_tag, tag1_val))
5842 else if (unformat (input, "tag2 %U", unformat_vlan_tag, tag2_val))
5844 else if (unformat (input, "ignore-tag1"))
5846 else if (unformat (input, "ignore-tag2"))
5848 else if (unformat (input, "cos1 %d", &cos1_val))
5850 else if (unformat (input, "cos2 %d", &cos2_val))
5855 if ((src + dst + proto + tag1 + tag2 +
5856 ignore_tag1 + ignore_tag2 + cos1 + cos2) == 0)
5859 if (tag1 || ignore_tag1 || cos1)
5861 if (tag2 || ignore_tag2 || cos2)
5864 vec_validate_aligned (match, len-1, sizeof(u32x4));
5867 memcpy (match, dst_val, 6);
5870 memcpy (match + 6, src_val, 6);
5874 /* inner vlan tag */
5875 match[19] = tag2_val[1];
5876 match[18] = tag2_val[0];
5878 match [18] |= (cos2_val & 0x7) << 5;
5881 match[21] = proto_val & 0xff;
5882 match[20] = proto_val >> 8;
5886 match [15] = tag1_val[1];
5887 match [14] = tag1_val[0];
5890 match [14] |= (cos1_val & 0x7) << 5;
5896 match [15] = tag1_val[1];
5897 match [14] = tag1_val[0];
5900 match[17] = proto_val & 0xff;
5901 match[16] = proto_val >> 8;
5904 match [14] |= (cos1_val & 0x7) << 5;
5910 match [18] |= (cos2_val & 0x7) << 5;
5912 match [14] |= (cos1_val & 0x7) << 5;
5915 match[13] = proto_val & 0xff;
5916 match[12] = proto_val >> 8;
5924 uword unformat_classify_match (unformat_input_t * input, va_list * args)
5926 u8 ** matchp = va_arg (*args, u8 **);
5927 u32 skip_n_vectors = va_arg (*args, u32);
5928 u32 match_n_vectors = va_arg (*args, u32);
5934 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) {
5935 if (unformat (input, "hex %U", unformat_hex_string, &match))
5937 else if (unformat (input, "l2 %U", unformat_l2_match, &l2))
5939 else if (unformat (input, "l3 %U", unformat_l3_match, &l3))
5945 if (match || l2 || l3)
5949 /* "Win a free Ethernet header in every packet" */
5951 vec_validate_aligned (l2, 13, sizeof(u32x4));
5953 vec_append_aligned (match, l3, sizeof(u32x4));
5957 /* Make sure the vector is big enough even if key is all 0's */
5958 vec_validate_aligned
5959 (match, ((match_n_vectors + skip_n_vectors) * sizeof(u32x4)) - 1,
5962 /* Set size, include skipped vectors*/
5963 _vec_len (match) = (match_n_vectors+skip_n_vectors) * sizeof(u32x4);
5973 static int api_classify_add_del_session (vat_main_t * vam)
5975 unformat_input_t * i = vam->input;
5976 vl_api_classify_add_del_session_t *mp;
5978 u32 table_index = ~0;
5979 u32 hit_next_index = ~0;
5980 u32 opaque_index = ~0;
5984 u32 skip_n_vectors = 0;
5985 u32 match_n_vectors = 0;
5988 * Warning: you have to supply skip_n and match_n
5989 * because the API client cant simply look at the classify
5993 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
5994 if (unformat (i, "del"))
5996 else if (unformat (i, "hit-next %U", unformat_ip_next_index,
5999 else if (unformat (i, "l2-hit-next %U", unformat_l2_next_index,
6002 else if (unformat (i, "acl-hit-next %U", unformat_acl_next_index,
6005 else if (unformat (i, "opaque-index %d", &opaque_index))
6007 else if (unformat (i, "skip_n %d", &skip_n_vectors))
6009 else if (unformat (i, "match_n %d", &match_n_vectors))
6011 else if (unformat (i, "match %U", unformat_classify_match,
6012 &match, skip_n_vectors, match_n_vectors))
6014 else if (unformat (i, "advance %d", &advance))
6016 else if (unformat (i, "table-index %d", &table_index))
6022 if (table_index == ~0) {
6023 errmsg ("Table index required\n");
6027 if (is_add && match == 0) {
6028 errmsg ("Match value required\n");
6032 M2 (CLASSIFY_ADD_DEL_SESSION, classify_add_del_session,
6035 mp->is_add = is_add;
6036 mp->table_index = ntohl(table_index);
6037 mp->hit_next_index = ntohl(hit_next_index);
6038 mp->opaque_index = ntohl(opaque_index);
6039 mp->advance = ntohl(advance);
6040 memcpy (mp->match, match, vec_len(match));
6047 static int api_classify_set_interface_ip_table (vat_main_t * vam)
6049 unformat_input_t * i = vam->input;
6050 vl_api_classify_set_interface_ip_table_t *mp;
6053 int sw_if_index_set;
6054 u32 table_index = ~0;
6057 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
6058 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
6059 sw_if_index_set = 1;
6060 else if (unformat (i, "sw_if_index %d", &sw_if_index))
6061 sw_if_index_set = 1;
6062 else if (unformat (i, "table %d", &table_index))
6065 clib_warning ("parse error '%U'", format_unformat_error, i);
6070 if (sw_if_index_set == 0) {
6071 errmsg ("missing interface name or sw_if_index\n");
6076 M(CLASSIFY_SET_INTERFACE_IP_TABLE, classify_set_interface_ip_table);
6078 mp->sw_if_index = ntohl(sw_if_index);
6079 mp->table_index = ntohl(table_index);
6080 mp->is_ipv6 = is_ipv6;
6087 static int api_classify_set_interface_l2_tables (vat_main_t * vam)
6089 unformat_input_t * i = vam->input;
6090 vl_api_classify_set_interface_l2_tables_t *mp;
6093 int sw_if_index_set;
6094 u32 ip4_table_index = ~0;
6095 u32 ip6_table_index = ~0;
6096 u32 other_table_index = ~0;
6098 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
6099 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
6100 sw_if_index_set = 1;
6101 else if (unformat (i, "sw_if_index %d", &sw_if_index))
6102 sw_if_index_set = 1;
6103 else if (unformat (i, "ip4-table %d", &ip4_table_index))
6105 else if (unformat (i, "ip6-table %d", &ip6_table_index))
6107 else if (unformat (i, "other-table %d", &other_table_index))
6110 clib_warning ("parse error '%U'", format_unformat_error, i);
6115 if (sw_if_index_set == 0) {
6116 errmsg ("missing interface name or sw_if_index\n");
6121 M(CLASSIFY_SET_INTERFACE_L2_TABLES, classify_set_interface_l2_tables);
6123 mp->sw_if_index = ntohl(sw_if_index);
6124 mp->ip4_table_index = ntohl(ip4_table_index);
6125 mp->ip6_table_index = ntohl(ip6_table_index);
6126 mp->other_table_index = ntohl(other_table_index);
6134 static int api_get_node_index (vat_main_t * vam)
6136 unformat_input_t * i = vam->input;
6137 vl_api_get_node_index_t * mp;
6141 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
6142 if (unformat (i, "node %s", &name))
6148 errmsg ("node name required\n");
6151 if (vec_len (name) >= ARRAY_LEN(mp->node_name)) {
6152 errmsg ("node name too long, max %d\n", ARRAY_LEN(mp->node_name));
6156 M(GET_NODE_INDEX, get_node_index);
6157 memcpy (mp->node_name, name, vec_len(name));
6165 static int api_add_node_next (vat_main_t * vam)
6167 unformat_input_t * i = vam->input;
6168 vl_api_add_node_next_t * mp;
6173 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
6174 if (unformat (i, "node %s", &name))
6176 else if (unformat (i, "next %s", &next))
6182 errmsg ("node name required\n");
6185 if (vec_len (name) >= ARRAY_LEN(mp->node_name)) {
6186 errmsg ("node name too long, max %d\n", ARRAY_LEN(mp->node_name));
6190 errmsg ("next node required\n");
6193 if (vec_len (next) >= ARRAY_LEN(mp->next_name)) {
6194 errmsg ("next name too long, max %d\n", ARRAY_LEN(mp->next_name));
6198 M(ADD_NODE_NEXT, add_node_next);
6199 memcpy (mp->node_name, name, vec_len(name));
6200 memcpy (mp->next_name, next, vec_len(next));
6209 static int api_l2tpv3_create_tunnel (vat_main_t * vam)
6211 unformat_input_t * i = vam->input;
6212 ip6_address_t client_address, our_address;
6213 int client_address_set = 0;
6214 int our_address_set = 0;
6215 u32 local_session_id = 0;
6216 u32 remote_session_id = 0;
6217 u64 local_cookie = 0;
6218 u64 remote_cookie = 0;
6219 u8 l2_sublayer_present = 0;
6220 vl_api_l2tpv3_create_tunnel_t * mp;
6223 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
6224 if (unformat (i, "client_address %U", unformat_ip6_address,
6226 client_address_set = 1;
6227 else if (unformat (i, "our_address %U", unformat_ip6_address,
6229 our_address_set = 1;
6230 else if (unformat (i, "local_session_id %d", &local_session_id))
6232 else if (unformat (i, "remote_session_id %d", &remote_session_id))
6234 else if (unformat (i, "local_cookie %lld", &local_cookie))
6236 else if (unformat (i, "remote_cookie %lld", &remote_cookie))
6238 else if (unformat (i, "l2-sublayer-present"))
6239 l2_sublayer_present = 1;
6244 if (client_address_set == 0) {
6245 errmsg ("client_address required\n");
6249 if (our_address_set == 0) {
6250 errmsg ("our_address required\n");
6254 M(L2TPV3_CREATE_TUNNEL, l2tpv3_create_tunnel);
6256 memcpy (mp->client_address, client_address.as_u8,
6257 sizeof (mp->client_address));
6259 memcpy (mp->our_address, our_address.as_u8,
6260 sizeof (mp->our_address));
6262 mp->local_session_id = ntohl (local_session_id);
6263 mp->remote_session_id = ntohl (remote_session_id);
6264 mp->local_cookie = clib_host_to_net_u64 (local_cookie);
6265 mp->remote_cookie = clib_host_to_net_u64 (remote_cookie);
6266 mp->l2_sublayer_present = l2_sublayer_present;
6274 static int api_l2tpv3_set_tunnel_cookies (vat_main_t * vam)
6276 unformat_input_t * i = vam->input;
6278 u8 sw_if_index_set = 0;
6279 u64 new_local_cookie = 0;
6280 u64 new_remote_cookie = 0;
6281 vl_api_l2tpv3_set_tunnel_cookies_t *mp;
6284 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
6285 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
6286 sw_if_index_set = 1;
6287 else if (unformat (i, "sw_if_index %d", &sw_if_index))
6288 sw_if_index_set = 1;
6289 else if (unformat (i, "new_local_cookie %lld", &new_local_cookie))
6291 else if (unformat (i, "new_remote_cookie %lld", &new_remote_cookie))
6297 if (sw_if_index_set == 0) {
6298 errmsg ("missing interface name or sw_if_index\n");
6302 M(L2TPV3_SET_TUNNEL_COOKIES, l2tpv3_set_tunnel_cookies);
6304 mp->sw_if_index = ntohl(sw_if_index);
6305 mp->new_local_cookie = clib_host_to_net_u64 (new_local_cookie);
6306 mp->new_remote_cookie = clib_host_to_net_u64 (new_remote_cookie);
6313 static int api_l2tpv3_interface_enable_disable (vat_main_t * vam)
6315 unformat_input_t * i = vam->input;
6316 vl_api_l2tpv3_interface_enable_disable_t *mp;
6319 u8 sw_if_index_set = 0;
6320 u8 enable_disable = 1;
6322 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
6323 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
6324 sw_if_index_set = 1;
6325 else if (unformat (i, "sw_if_index %d", &sw_if_index))
6326 sw_if_index_set = 1;
6327 else if (unformat (i, "enable"))
6329 else if (unformat (i, "disable"))
6335 if (sw_if_index_set == 0) {
6336 errmsg ("missing interface name or sw_if_index\n");
6340 M(L2TPV3_INTERFACE_ENABLE_DISABLE, l2tpv3_interface_enable_disable);
6342 mp->sw_if_index = ntohl(sw_if_index);
6343 mp->enable_disable = enable_disable;
6350 static int api_l2tpv3_set_lookup_key (vat_main_t * vam)
6352 unformat_input_t * i = vam->input;
6353 vl_api_l2tpv3_set_lookup_key_t * mp;
6357 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
6358 if (unformat (i, "lookup_v6_src"))
6359 key = L2T_LOOKUP_SRC_ADDRESS;
6360 else if (unformat (i, "lookup_v6_dst"))
6361 key = L2T_LOOKUP_DST_ADDRESS;
6362 else if (unformat (i, "lookup_session_id"))
6363 key = L2T_LOOKUP_SESSION_ID;
6369 errmsg ("l2tp session lookup key unset\n");
6373 M(L2TPV3_SET_LOOKUP_KEY, l2tpv3_set_lookup_key);
6382 static void vl_api_sw_if_l2tpv3_tunnel_details_t_handler
6383 (vl_api_sw_if_l2tpv3_tunnel_details_t * mp)
6385 vat_main_t * vam = &vat_main;
6387 fformat(vam->ofp, "* %U (our) %U (client) (sw_if_index %d)\n",
6388 format_ip6_address, mp->our_address,
6389 format_ip6_address, mp->client_address,
6390 clib_net_to_host_u32(mp->sw_if_index));
6392 fformat (vam->ofp, " local cookies %016llx %016llx remote cookie %016llx\n",
6393 clib_net_to_host_u64 (mp->local_cookie[0]),
6394 clib_net_to_host_u64 (mp->local_cookie[1]),
6395 clib_net_to_host_u64 (mp->remote_cookie));
6397 fformat (vam->ofp, " local session-id %d remote session-id %d\n",
6398 clib_net_to_host_u32 (mp->local_session_id),
6399 clib_net_to_host_u32 (mp->remote_session_id));
6401 fformat (vam->ofp, " l2 specific sublayer %s\n\n",
6402 mp->l2_sublayer_present ? "preset" : "absent");
6406 static void vl_api_sw_if_l2tpv3_tunnel_details_t_handler_json
6407 (vl_api_sw_if_l2tpv3_tunnel_details_t * mp)
6409 vat_main_t * vam = &vat_main;
6410 vat_json_node_t *node = NULL;
6411 struct in6_addr addr;
6413 if (VAT_JSON_ARRAY != vam->json_tree.type) {
6414 ASSERT(VAT_JSON_NONE == vam->json_tree.type);
6415 vat_json_init_array(&vam->json_tree);
6417 node = vat_json_array_add(&vam->json_tree);
6419 vat_json_init_object(node);
6421 memcpy(&addr, mp->our_address, sizeof(addr));
6422 vat_json_object_add_ip6(node, "our_address", addr);
6423 memcpy(&addr, mp->client_address, sizeof(addr));
6424 vat_json_object_add_ip6(node, "client_address", addr);
6426 vat_json_node_t * lc = vat_json_object_add(node, "local_cookie");
6427 vat_json_init_array(lc);
6428 vat_json_array_add_uint(lc, clib_net_to_host_u64(mp->local_cookie[0]));
6429 vat_json_array_add_uint(lc, clib_net_to_host_u64(mp->local_cookie[1]));
6430 vat_json_object_add_uint(node, "remote_cookie", clib_net_to_host_u64(mp->remote_cookie));
6432 printf("local id: %u", clib_net_to_host_u32(mp->local_session_id));
6433 vat_json_object_add_uint(node, "local_session_id", clib_net_to_host_u32(mp->local_session_id));
6434 vat_json_object_add_uint(node, "remote_session_id", clib_net_to_host_u32(mp->remote_session_id));
6435 vat_json_object_add_string_copy(node, "l2_sublayer", mp->l2_sublayer_present ?
6436 (u8*)"present" : (u8*)"absent");
6439 static int api_sw_if_l2tpv3_tunnel_dump (vat_main_t * vam)
6441 vl_api_sw_if_l2tpv3_tunnel_dump_t *mp;
6444 /* Get list of l2tpv3-tunnel interfaces */
6445 M(SW_IF_L2TPV3_TUNNEL_DUMP, sw_if_l2tpv3_tunnel_dump);
6448 /* Use a control ping for synchronization */
6450 vl_api_control_ping_t * mp;
6451 M(CONTROL_PING, control_ping);
6458 static void vl_api_sw_interface_tap_details_t_handler
6459 (vl_api_sw_interface_tap_details_t * mp)
6461 vat_main_t * vam = &vat_main;
6463 fformat(vam->ofp, "%-16s %d\n",
6465 clib_net_to_host_u32(mp->sw_if_index));
6468 static void vl_api_sw_interface_tap_details_t_handler_json
6469 (vl_api_sw_interface_tap_details_t * mp)
6471 vat_main_t * vam = &vat_main;
6472 vat_json_node_t *node = NULL;
6474 if (VAT_JSON_ARRAY != vam->json_tree.type) {
6475 ASSERT(VAT_JSON_NONE == vam->json_tree.type);
6476 vat_json_init_array(&vam->json_tree);
6478 node = vat_json_array_add(&vam->json_tree);
6480 vat_json_init_object(node);
6481 vat_json_object_add_uint(node, "sw_if_index", ntohl(mp->sw_if_index));
6482 vat_json_object_add_string_copy(node, "dev_name", mp->dev_name);
6485 static int api_sw_interface_tap_dump (vat_main_t * vam)
6487 vl_api_sw_interface_tap_dump_t *mp;
6490 fformat(vam->ofp, "\n%-16s %s\n", "dev_name", "sw_if_index");
6491 /* Get list of tap interfaces */
6492 M(SW_INTERFACE_TAP_DUMP, sw_interface_tap_dump);
6495 /* Use a control ping for synchronization */
6497 vl_api_control_ping_t * mp;
6498 M(CONTROL_PING, control_ping);
6504 static uword unformat_vxlan_decap_next
6505 (unformat_input_t * input, va_list * args)
6507 u32 * result = va_arg (*args, u32 *);
6510 if (unformat (input, "drop"))
6511 *result = VXLAN_INPUT_NEXT_DROP;
6512 else if (unformat (input, "ip4"))
6513 *result = VXLAN_INPUT_NEXT_IP4_INPUT;
6514 else if (unformat (input, "ip6"))
6515 *result = VXLAN_INPUT_NEXT_IP6_INPUT;
6516 else if (unformat (input, "l2"))
6517 *result = VXLAN_INPUT_NEXT_L2_INPUT;
6518 else if (unformat (input, "%d", &tmp))
6525 static int api_vxlan_add_del_tunnel (vat_main_t * vam)
6527 unformat_input_t * line_input = vam->input;
6528 vl_api_vxlan_add_del_tunnel_t *mp;
6530 ip4_address_t src, dst;
6534 u32 encap_vrf_id = 0;
6535 u32 decap_next_index = ~0;
6538 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) {
6539 if (unformat (line_input, "del"))
6541 else if (unformat (line_input, "src %U",
6542 unformat_ip4_address, &src))
6544 else if (unformat (line_input, "dst %U",
6545 unformat_ip4_address, &dst))
6547 else if (unformat (line_input, "encap-vrf-id %d", &encap_vrf_id))
6549 else if (unformat (line_input, "decap-next %U",
6550 unformat_vxlan_decap_next, &decap_next_index))
6552 else if (unformat (line_input, "vni %d", &vni))
6555 errmsg ("parse error '%U'\n", format_unformat_error, line_input);
6561 errmsg ("tunnel src address not specified\n");
6565 errmsg ("tunnel dst address not specified\n");
6569 if ((vni == 0) || (vni>>24)) {
6570 errmsg ("vni not specified or out of range\n");
6574 M (VXLAN_ADD_DEL_TUNNEL, vxlan_add_del_tunnel);
6576 mp->src_address = src.as_u32;
6577 mp->dst_address = dst.as_u32;
6578 mp->encap_vrf_id = ntohl(encap_vrf_id);
6579 mp->decap_next_index = ntohl(decap_next_index);
6580 mp->vni = ntohl(vni);
6581 mp->is_add = is_add;
6588 static void vl_api_vxlan_tunnel_details_t_handler
6589 (vl_api_vxlan_tunnel_details_t * mp)
6591 vat_main_t * vam = &vat_main;
6593 fformat(vam->ofp, "%11d%13U%13U%14d%18d%13d\n",
6594 ntohl(mp->sw_if_index),
6595 format_ip4_address, &mp->src_address,
6596 format_ip4_address, &mp->dst_address,
6597 ntohl(mp->encap_vrf_id),
6598 ntohl(mp->decap_next_index),
6602 static void vl_api_vxlan_tunnel_details_t_handler_json
6603 (vl_api_vxlan_tunnel_details_t * mp)
6605 vat_main_t * vam = &vat_main;
6606 vat_json_node_t *node = NULL;
6609 if (VAT_JSON_ARRAY != vam->json_tree.type) {
6610 ASSERT(VAT_JSON_NONE == vam->json_tree.type);
6611 vat_json_init_array(&vam->json_tree);
6613 node = vat_json_array_add(&vam->json_tree);
6615 vat_json_init_object(node);
6616 vat_json_object_add_uint(node, "sw_if_index", ntohl(mp->sw_if_index));
6617 memcpy(&ip4, &mp->src_address, sizeof(ip4));
6618 vat_json_object_add_ip4(node, "src_address", ip4);
6619 memcpy(&ip4, &mp->dst_address, sizeof(ip4));
6620 vat_json_object_add_ip4(node, "dst_address", ip4);
6621 vat_json_object_add_uint(node, "encap_vrf_id", ntohl(mp->encap_vrf_id));
6622 vat_json_object_add_uint(node, "decap_next_index", ntohl(mp->decap_next_index));
6623 vat_json_object_add_uint(node, "vni", ntohl(mp->vni));
6626 static int api_vxlan_tunnel_dump (vat_main_t * vam)
6628 unformat_input_t * i = vam->input;
6629 vl_api_vxlan_tunnel_dump_t *mp;
6632 u8 sw_if_index_set = 0;
6634 /* Parse args required to build the message */
6635 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
6636 if (unformat (i, "sw_if_index %d", &sw_if_index))
6637 sw_if_index_set = 1;
6642 if (sw_if_index_set == 0) {
6646 if (!vam->json_output) {
6647 fformat(vam->ofp, "%11s%13s%13s%14s%18s%13s\n",
6648 "sw_if_index", "src_address", "dst_address",
6649 "encap_vrf_id", "decap_next_index", "vni");
6652 /* Get list of l2tpv3-tunnel interfaces */
6653 M(VXLAN_TUNNEL_DUMP, vxlan_tunnel_dump);
6655 mp->sw_if_index = htonl(sw_if_index);
6659 /* Use a control ping for synchronization */
6661 vl_api_control_ping_t * mp;
6662 M(CONTROL_PING, control_ping);
6668 static int api_l2_fib_clear_table (vat_main_t * vam)
6670 // unformat_input_t * i = vam->input;
6671 vl_api_l2_fib_clear_table_t *mp;
6674 M(L2_FIB_CLEAR_TABLE, l2_fib_clear_table);
6681 static int api_l2_interface_efp_filter (vat_main_t * vam)
6683 unformat_input_t * i = vam->input;
6684 vl_api_l2_interface_efp_filter_t *mp;
6688 u8 sw_if_index_set = 0;
6690 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
6691 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
6692 sw_if_index_set = 1;
6693 else if (unformat (i, "sw_if_index %d", &sw_if_index))
6694 sw_if_index_set = 1;
6695 else if (unformat (i, "enable"))
6697 else if (unformat (i, "disable"))
6700 clib_warning ("parse error '%U'", format_unformat_error, i);
6705 if (sw_if_index_set == 0) {
6706 errmsg ("missing sw_if_index\n");
6710 M(L2_INTERFACE_EFP_FILTER, l2_interface_efp_filter);
6712 mp->sw_if_index = ntohl(sw_if_index);
6713 mp->enable_disable = enable;
6720 #define foreach_vtr_op \
6721 _("disable", L2_VTR_DISABLED) \
6722 _("push-1", L2_VTR_PUSH_1) \
6723 _("push-2", L2_VTR_PUSH_2) \
6724 _("pop-1", L2_VTR_POP_1) \
6725 _("pop-2", L2_VTR_POP_2) \
6726 _("translate-1-1", L2_VTR_TRANSLATE_1_1) \
6727 _("translate-1-2", L2_VTR_TRANSLATE_1_2) \
6728 _("translate-2-1", L2_VTR_TRANSLATE_2_1) \
6729 _("translate-2-2", L2_VTR_TRANSLATE_2_2)
6731 static int api_l2_interface_vlan_tag_rewrite (vat_main_t * vam)
6733 unformat_input_t * i = vam->input;
6734 vl_api_l2_interface_vlan_tag_rewrite_t *mp;
6737 u8 sw_if_index_set = 0;
6744 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
6745 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
6746 sw_if_index_set = 1;
6747 else if (unformat (i, "sw_if_index %d", &sw_if_index))
6748 sw_if_index_set = 1;
6749 else if (unformat (i, "vtr_op %d", &vtr_op))
6751 #define _(n,v) else if (unformat(i, n)) {vtr_op = v; vtr_op_set = 1;}
6755 else if (unformat (i, "push_dot1q %d", &push_dot1q))
6757 else if (unformat (i, "tag1 %d", &tag1))
6759 else if (unformat (i, "tag2 %d", &tag2))
6762 clib_warning ("parse error '%U'", format_unformat_error, i);
6767 if ((sw_if_index_set == 0)||(vtr_op_set == 0)) {
6768 errmsg ("missing vtr operation or sw_if_index\n");
6772 M(L2_INTERFACE_VLAN_TAG_REWRITE, l2_interface_vlan_tag_rewrite)
6774 mp->sw_if_index = ntohl(sw_if_index);
6775 mp->vtr_op = ntohl(vtr_op);
6776 mp->push_dot1q = ntohl(push_dot1q);
6777 mp->tag1 = ntohl(tag1);
6778 mp->tag2 = ntohl(tag2);
6785 static int api_create_vhost_user_if (vat_main_t * vam)
6787 unformat_input_t * i = vam->input;
6788 vl_api_create_vhost_user_if_t *mp;
6792 u8 file_name_set = 0;
6793 u32 custom_dev_instance = ~0;
6795 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
6796 if (unformat (i, "socket %s", &file_name)) {
6799 else if (unformat (i, "renumber %"PRIu32, &custom_dev_instance))
6801 else if (unformat (i, "server"))
6807 if (file_name_set == 0) {
6808 errmsg ("missing socket file name\n");
6812 if (vec_len (file_name) > 255) {
6813 errmsg ("socket file name too long\n");
6816 vec_add1 (file_name, 0);
6818 M(CREATE_VHOST_USER_IF, create_vhost_user_if);
6820 mp->is_server = is_server;
6821 memcpy(mp->sock_filename, file_name, vec_len(file_name));
6822 vec_free(file_name);
6823 if (custom_dev_instance != ~0) {
6825 mp->custom_dev_instance = ntohl(custom_dev_instance);
6833 static int api_modify_vhost_user_if (vat_main_t * vam)
6835 unformat_input_t * i = vam->input;
6836 vl_api_modify_vhost_user_if_t *mp;
6840 u8 file_name_set = 0;
6841 u32 custom_dev_instance = ~0;
6842 u8 sw_if_index_set = 0;
6843 u32 sw_if_index = (u32)~0;
6845 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
6846 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
6847 sw_if_index_set = 1;
6848 else if (unformat (i, "sw_if_index %d", &sw_if_index))
6849 sw_if_index_set = 1;
6850 else if (unformat (i, "socket %s", &file_name)) {
6853 else if (unformat (i, "renumber %"PRIu32, &custom_dev_instance))
6855 else if (unformat (i, "server"))
6861 if (sw_if_index_set == 0) {
6862 errmsg ("missing sw_if_index or interface name\n");
6866 if (file_name_set == 0) {
6867 errmsg ("missing socket file name\n");
6871 if (vec_len (file_name) > 255) {
6872 errmsg ("socket file name too long\n");
6875 vec_add1 (file_name, 0);
6877 M(MODIFY_VHOST_USER_IF, modify_vhost_user_if);
6879 mp->sw_if_index = ntohl(sw_if_index);
6880 mp->is_server = is_server;
6881 memcpy(mp->sock_filename, file_name, vec_len(file_name));
6882 vec_free(file_name);
6883 if (custom_dev_instance != ~0) {
6885 mp->custom_dev_instance = ntohl(custom_dev_instance);
6893 static int api_delete_vhost_user_if (vat_main_t * vam)
6895 unformat_input_t * i = vam->input;
6896 vl_api_delete_vhost_user_if_t *mp;
6898 u32 sw_if_index = ~0;
6899 u8 sw_if_index_set = 0;
6901 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
6902 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
6903 sw_if_index_set = 1;
6904 else if (unformat (i, "sw_if_index %d", &sw_if_index))
6905 sw_if_index_set = 1;
6910 if (sw_if_index_set == 0) {
6911 errmsg ("missing sw_if_index or interface name\n");
6916 M(DELETE_VHOST_USER_IF, delete_vhost_user_if);
6918 mp->sw_if_index = ntohl(sw_if_index);
6925 static void vl_api_sw_interface_vhost_user_details_t_handler
6926 (vl_api_sw_interface_vhost_user_details_t * mp)
6928 vat_main_t * vam = &vat_main;
6930 fformat(vam->ofp, "%-25s %3" PRIu32 " %6" PRIu32 " %8x %6d %7d %s\n",
6931 (char *)mp->interface_name,
6932 ntohl(mp->sw_if_index), ntohl(mp->virtio_net_hdr_sz),
6933 clib_net_to_host_u64(mp->features), mp->is_server,
6934 ntohl(mp->num_regions), (char *)mp->sock_filename);
6935 fformat(vam->ofp, " Status: '%s'\n", strerror(ntohl(mp->sock_errno)));
6938 static void vl_api_sw_interface_vhost_user_details_t_handler_json
6939 (vl_api_sw_interface_vhost_user_details_t * mp)
6941 vat_main_t * vam = &vat_main;
6942 vat_json_node_t *node = NULL;
6944 if (VAT_JSON_ARRAY != vam->json_tree.type) {
6945 ASSERT(VAT_JSON_NONE == vam->json_tree.type);
6946 vat_json_init_array(&vam->json_tree);
6948 node = vat_json_array_add(&vam->json_tree);
6950 vat_json_init_object(node);
6951 vat_json_object_add_uint(node, "sw_if_index", ntohl(mp->sw_if_index));
6952 vat_json_object_add_string_copy(node, "interface_name", mp->interface_name);
6953 vat_json_object_add_uint(node, "virtio_net_hdr_sz", ntohl(mp->virtio_net_hdr_sz));
6954 vat_json_object_add_uint(node, "features", clib_net_to_host_u64(mp->features));
6955 vat_json_object_add_uint(node, "is_server", mp->is_server);
6956 vat_json_object_add_string_copy(node, "sock_filename", mp->sock_filename);
6957 vat_json_object_add_uint(node, "num_regions", ntohl(mp->num_regions));
6958 vat_json_object_add_uint(node, "sock_errno", ntohl(mp->sock_errno));
6961 static int api_sw_interface_vhost_user_dump (vat_main_t * vam)
6963 vl_api_sw_interface_vhost_user_dump_t *mp;
6965 fformat(vam->ofp, "Interface name idx hdr_sz features server regions filename\n");
6967 /* Get list of vhost-user interfaces */
6968 M(SW_INTERFACE_VHOST_USER_DUMP, sw_interface_vhost_user_dump);
6971 /* Use a control ping for synchronization */
6973 vl_api_control_ping_t * mp;
6974 M(CONTROL_PING, control_ping);
6980 static int api_show_version (vat_main_t * vam)
6982 vl_api_show_version_t *mp;
6985 M(SHOW_VERSION, show_version);
6992 static uword unformat_nsh_gre_decap_next
6993 (unformat_input_t * input, va_list * args)
6995 u32 * result = va_arg (*args, u32 *);
6998 if (unformat (input, "drop"))
6999 *result = NSH_INPUT_NEXT_DROP;
7000 else if (unformat (input, "ip4"))
7001 *result = NSH_INPUT_NEXT_IP4_INPUT;
7002 else if (unformat (input, "ip6"))
7003 *result = NSH_INPUT_NEXT_IP6_INPUT;
7004 else if (unformat (input, "ethernet"))
7005 *result = NSH_INPUT_NEXT_ETHERNET_INPUT;
7006 else if (unformat (input, "%d", &tmp))
7013 static int api_nsh_gre_add_del_tunnel (vat_main_t * vam)
7015 unformat_input_t * line_input = vam->input;
7016 vl_api_nsh_gre_add_del_tunnel_t *mp;
7018 ip4_address_t src, dst;
7022 u32 encap_vrf_id = 0;
7023 u32 decap_vrf_id = 0;
7026 u8 next_protocol = 1; /* ip4 */
7037 u32 decap_next_index = NSH_INPUT_NEXT_IP4_INPUT;
7041 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) {
7042 if (unformat (line_input, "del"))
7044 else if (unformat (line_input, "src %U",
7045 unformat_ip4_address, &src))
7047 else if (unformat (line_input, "dst %U",
7048 unformat_ip4_address, &dst))
7050 else if (unformat (line_input, "encap-vrf-id %d", &encap_vrf_id))
7052 else if (unformat (line_input, "decap-vrf-id %d", &decap_vrf_id))
7054 else if (unformat (line_input, "decap-next %U",
7055 unformat_nsh_gre_decap_next, &decap_next_index))
7057 else if (unformat (line_input, "version %d", &tmp))
7058 ver_o_c |= (tmp & 3) << 6;
7059 else if (unformat (line_input, "o-bit %d", &tmp))
7060 ver_o_c |= (tmp & 1) << 5;
7061 else if (unformat (line_input, "c-bit %d", &tmp))
7062 ver_o_c |= (tmp & 1) << 4;
7063 else if (unformat (line_input, "md-type %d", &tmp))
7065 else if (unformat(line_input, "next-ip4"))
7067 else if (unformat(line_input, "next-ip6"))
7069 else if (unformat(line_input, "next-ethernet"))
7071 else if (unformat (line_input, "c1 %d", &c1))
7073 else if (unformat (line_input, "c2 %d", &c2))
7075 else if (unformat (line_input, "c3 %d", &c3))
7077 else if (unformat (line_input, "c4 %d", &c4))
7079 else if (unformat (line_input, "spi %d", &spi))
7081 else if (unformat (line_input, "si %d", &si))
7083 else if (unformat (line_input, "tlv %x"))
7084 vec_add1 (tlvs, tmp);
7086 errmsg ("parse error '%U'\n", format_unformat_error, line_input);
7092 errmsg ("tunnel src address not specified\n");
7096 errmsg ("tunnel dst address not specified\n");
7101 errmsg ("spi not specified\n");
7106 errmsg ("si not specified\n");
7110 M2 (NSH_GRE_ADD_DEL_TUNNEL, nsh_gre_add_del_tunnel,
7111 sizeof(u32) * vec_len (tlvs));
7113 spi_si = (spi<<8) | si;
7115 mp->src = src.as_u32;
7116 mp->dst = dst.as_u32;
7117 mp->encap_vrf_id = ntohl(encap_vrf_id);
7118 mp->decap_vrf_id = ntohl(decap_vrf_id);
7119 mp->decap_next_index = ntohl(decap_next_index);
7120 mp->tlv_len_in_words = vec_len (tlvs);
7121 mp->is_add = is_add;
7122 mp->ver_o_c = ver_o_c;
7123 mp->length = 6 + vec_len(tlvs);
7124 mp->md_type = md_type;
7125 mp->next_protocol = next_protocol;
7126 mp->spi_si = ntohl(spi_si);
7132 for (i = 0; i < vec_len(tlvs); i++)
7133 mp->tlvs[i] = ntohl(tlvs[i]);
7142 static uword unformat_nsh_vxlan_gpe_decap_next
7143 (unformat_input_t * input, va_list * args)
7145 u32 * result = va_arg (*args, u32 *);
7148 if (unformat (input, "drop"))
7149 *result = NSH_VXLAN_GPE_INPUT_NEXT_DROP;
7150 else if (unformat (input, "ip4"))
7151 *result = NSH_VXLAN_GPE_INPUT_NEXT_IP4_INPUT;
7152 else if (unformat (input, "ip6"))
7153 *result = NSH_VXLAN_GPE_INPUT_NEXT_IP6_INPUT;
7154 else if (unformat (input, "ethernet"))
7155 *result = NSH_VXLAN_GPE_INPUT_NEXT_ETHERNET_INPUT;
7156 else if (unformat (input, "nsh-vxlan-gpe"))
7157 *result = NSH_VXLAN_GPE_INPUT_NEXT_ETHERNET_INPUT;
7158 else if (unformat (input, "%d", &tmp))
7165 static int api_nsh_vxlan_gpe_add_del_tunnel (vat_main_t * vam)
7167 unformat_input_t * line_input = vam->input;
7168 vl_api_nsh_vxlan_gpe_add_del_tunnel_t *mp;
7170 ip4_address_t src, dst;
7174 u32 encap_vrf_id = 0;
7175 u32 decap_vrf_id = 0;
7178 u8 next_protocol = 1; /* ip4 */
7189 u32 decap_next_index = NSH_INPUT_NEXT_IP4_INPUT;
7195 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) {
7196 if (unformat (line_input, "del"))
7198 else if (unformat (line_input, "src %U",
7199 unformat_ip4_address, &src))
7201 else if (unformat (line_input, "dst %U",
7202 unformat_ip4_address, &dst))
7204 else if (unformat (line_input, "encap-vrf-id %d", &encap_vrf_id))
7206 else if (unformat (line_input, "decap-vrf-id %d", &decap_vrf_id))
7208 else if (unformat (line_input, "decap-next %U",
7209 unformat_nsh_vxlan_gpe_decap_next,
7212 else if (unformat (line_input, "vni %d", &vni))
7214 else if (unformat (line_input, "version %d", &tmp))
7215 ver_o_c |= (tmp & 3) << 6;
7216 else if (unformat (line_input, "o-bit %d", &tmp))
7217 ver_o_c |= (tmp & 1) << 5;
7218 else if (unformat (line_input, "c-bit %d", &tmp))
7219 ver_o_c |= (tmp & 1) << 4;
7220 else if (unformat (line_input, "md-type %d", &tmp))
7222 else if (unformat(line_input, "next-ip4"))
7224 else if (unformat(line_input, "next-ip6"))
7226 else if (unformat(line_input, "next-ethernet"))
7228 else if (unformat (line_input, "c1 %d", &c1))
7230 else if (unformat (line_input, "c2 %d", &c2))
7232 else if (unformat (line_input, "c3 %d", &c3))
7234 else if (unformat (line_input, "c4 %d", &c4))
7236 else if (unformat (line_input, "spi %d", &spi))
7238 else if (unformat (line_input, "si %d", &si))
7240 else if (unformat (line_input, "tlv %x"))
7241 vec_add1 (tlvs, tmp);
7243 errmsg ("parse error '%U'\n", format_unformat_error, line_input);
7249 errmsg ("tunnel src address not specified\n");
7253 errmsg ("tunnel dst address not specified\n");
7258 errmsg ("spi not specified\n");
7263 errmsg ("si not specified\n");
7267 errmsg ("vni not specified\n");
7271 M2 (NSH_VXLAN_GPE_ADD_DEL_TUNNEL, nsh_vxlan_gpe_add_del_tunnel,
7272 sizeof(u32) * vec_len (tlvs));
7274 spi_si = (spi<<8) | si;
7276 mp->src = src.as_u32;
7277 mp->dst = dst.as_u32;
7278 mp->encap_vrf_id = ntohl(encap_vrf_id);
7279 mp->decap_vrf_id = ntohl(decap_vrf_id);
7280 mp->decap_next_index = ntohl(decap_next_index);
7281 mp->tlv_len_in_words = vec_len (tlvs);
7282 mp->vni = ntohl(vni);
7283 mp->is_add = is_add;
7284 mp->ver_o_c = ver_o_c;
7285 mp->length = 6 + vec_len(tlvs);
7286 mp->md_type = md_type;
7287 mp->next_protocol = next_protocol;
7288 mp->spi_si = ntohl(spi_si);
7294 for (i = 0; i < vec_len(tlvs); i++)
7295 mp->tlvs[i] = ntohl(tlvs[i]);
7304 static uword unformat_lisp_gpe_decap_next (unformat_input_t * input,
7307 u32 * result = va_arg (*args, u32 *);
7310 if (unformat (input, "drop"))
7311 *result = LISP_GPE_INPUT_NEXT_DROP;
7312 else if (unformat (input, "ip4"))
7313 *result = LISP_GPE_INPUT_NEXT_IP4_INPUT;
7314 else if (unformat (input, "ip6"))
7315 *result = LISP_GPE_INPUT_NEXT_IP6_INPUT;
7316 else if (unformat (input, "ethernet"))
7317 *result = LISP_GPE_INPUT_NEXT_IP6_INPUT;
7318 else if (unformat (input, "lisp-gpe"))
7319 *result = LISP_GPE_INPUT_NEXT_LISP_GPE_ENCAP;
7320 else if (unformat (input, "%d", &tmp))
7328 api_lisp_gpe_add_del_tunnel (vat_main_t * vam)
7330 unformat_input_t * line_input = vam->input;
7331 vl_api_lisp_gpe_add_del_tunnel_t *mp;
7333 ip4_address_t src, dst;
7337 u32 encap_vrf_id = 0;
7338 u32 decap_vrf_id = 0;
7339 u8 next_protocol = LISP_GPE_NEXT_PROTOCOL_IP4;
7340 u32 decap_next_index = LISP_GPE_INPUT_NEXT_IP4_INPUT;
7341 u8 flags = LISP_GPE_FLAGS_P;
7348 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) {
7349 if (unformat (line_input, "del"))
7351 else if (unformat (line_input, "src %U",
7352 unformat_ip4_address, &src))
7354 else if (unformat (line_input, "dst %U",
7355 unformat_ip4_address, &dst))
7357 else if (unformat (line_input, "encap-vrf-id %d", &encap_vrf_id))
7359 else if (unformat (line_input, "decap-vrf-id %d", &decap_vrf_id))
7361 else if (unformat (line_input, "decap-next %U",
7362 unformat_lisp_gpe_decap_next,
7365 else if (unformat(line_input, "next-ip4"))
7367 else if (unformat(line_input, "next-ip6"))
7369 else if (unformat(line_input, "next-ethernet"))
7371 else if (unformat(line_input, "next-nsh"))
7373 /* Allow the user to specify anything they want in the LISP hdr */
7374 else if (unformat (line_input, "ver_res %x", &tmp))
7376 else if (unformat (line_input, "res %x", &tmp))
7378 else if (unformat (line_input, "flags %x", &tmp))
7380 else if (unformat (line_input, "n-bit"))
7381 flags |= LISP_GPE_FLAGS_N;
7382 else if (unformat (line_input, "l-bit"))
7383 flags |= LISP_GPE_FLAGS_L;
7384 else if (unformat (line_input, "e-bit"))
7385 flags |= LISP_GPE_FLAGS_E;
7386 else if (unformat (line_input, "v-bit"))
7387 flags |= LISP_GPE_FLAGS_V;
7388 else if (unformat (line_input, "i-bit"))
7389 flags |= LISP_GPE_FLAGS_V;
7390 else if (unformat (line_input, "not-p-bit"))
7391 flags &= !LISP_GPE_FLAGS_P;
7392 else if (unformat (line_input, "p-bit"))
7393 flags |= LISP_GPE_FLAGS_P;
7394 else if (unformat (line_input, "o-bit"))
7395 flags |= LISP_GPE_FLAGS_O;
7396 else if (unformat (line_input, "iidx %x", &iid))
7398 else if (unformat (line_input, "iid %d", &iid))
7401 errmsg ("parse error '%U'\n", format_unformat_error, line_input);
7407 errmsg ("tunnel src address not specified\n");
7411 errmsg ("tunnel dst address not specified\n");
7415 errmsg ("iid not specified\n");
7419 M(LISP_GPE_ADD_DEL_TUNNEL, lisp_gpe_add_del_tunnel);
7421 mp->src = src.as_u32;
7422 mp->dst = dst.as_u32;
7423 mp->encap_vrf_id = ntohl(encap_vrf_id);
7424 mp->decap_vrf_id = ntohl(decap_vrf_id);
7425 mp->decap_next_index = ntohl(decap_next_index);
7426 mp->is_add = is_add;
7428 mp->ver_res = ver_res;
7430 mp->next_protocol = next_protocol;
7431 mp->iid = ntohl(iid);
7440 u8 * format_l2_fib_mac_address (u8 * s, va_list * args)
7442 u8 * a = va_arg (*args, u8 *);
7444 return format (s, "%02x:%02x:%02x:%02x:%02x:%02x",
7445 a[2], a[3], a[4], a[5], a[6], a[7]);
7448 static void vl_api_l2_fib_table_entry_t_handler
7449 (vl_api_l2_fib_table_entry_t * mp)
7451 vat_main_t * vam = &vat_main;
7453 fformat(vam->ofp, "%3" PRIu32 " %U %3" PRIu32
7455 ntohl(mp->bd_id), format_l2_fib_mac_address, &mp->mac,
7456 ntohl(mp->sw_if_index), mp->static_mac, mp->filter_mac,
7460 static void vl_api_l2_fib_table_entry_t_handler_json
7461 (vl_api_l2_fib_table_entry_t * mp)
7463 vat_main_t * vam = &vat_main;
7464 vat_json_node_t *node = NULL;
7466 if (VAT_JSON_ARRAY != vam->json_tree.type) {
7467 ASSERT(VAT_JSON_NONE == vam->json_tree.type);
7468 vat_json_init_array(&vam->json_tree);
7470 node = vat_json_array_add(&vam->json_tree);
7472 vat_json_init_object(node);
7473 vat_json_object_add_uint(node, "bd_id", ntohl(mp->bd_id));
7474 vat_json_object_add_uint(node, "mac", clib_net_to_host_u64(mp->mac));
7475 vat_json_object_add_uint(node, "sw_if_index", ntohl(mp->sw_if_index));
7476 vat_json_object_add_uint(node, "static_mac", mp->static_mac);
7477 vat_json_object_add_uint(node, "filter_mac", mp->filter_mac);
7478 vat_json_object_add_uint(node, "bvi_mac", mp->bvi_mac);
7481 static int api_l2_fib_table_dump (vat_main_t * vam)
7483 unformat_input_t * i = vam->input;
7484 vl_api_l2_fib_table_dump_t *mp;
7489 /* Parse args required to build the message */
7490 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
7491 if (unformat (i, "bd_id %d", &bd_id))
7497 if (bd_id_set == 0) {
7498 errmsg ("missing bridge domain\n");
7502 fformat(vam->ofp, "BD-ID Mac Address sw-ndx Static Filter BVI\n");
7504 /* Get list of l2 fib entries */
7505 M(L2_FIB_TABLE_DUMP, l2_fib_table_dump);
7507 mp->bd_id = ntohl(bd_id);
7510 /* Use a control ping for synchronization */
7512 vl_api_control_ping_t * mp;
7513 M(CONTROL_PING, control_ping);
7521 api_interface_name_renumber (vat_main_t * vam)
7523 unformat_input_t * line_input = vam->input;
7524 vl_api_interface_name_renumber_t *mp;
7525 u32 sw_if_index = ~0;
7527 u32 new_show_dev_instance = ~0;
7529 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) {
7530 if (unformat (line_input, "%U", unformat_sw_if_index, vam,
7533 else if (unformat (line_input, "sw_if_index %d", &sw_if_index))
7535 else if (unformat (line_input, "new_show_dev_instance %d",
7536 &new_show_dev_instance))
7542 if (sw_if_index == ~0) {
7543 errmsg ("missing interface name or sw_if_index\n");
7547 if (new_show_dev_instance == ~0) {
7548 errmsg ("missing new_show_dev_instance\n");
7552 M(INTERFACE_NAME_RENUMBER, interface_name_renumber);
7554 mp->sw_if_index = ntohl (sw_if_index);
7555 mp->new_show_dev_instance = ntohl (new_show_dev_instance);
7561 api_want_ip4_arp_events (vat_main_t * vam)
7563 unformat_input_t * line_input = vam->input;
7564 vl_api_want_ip4_arp_events_t * mp;
7566 ip4_address_t address;
7567 int address_set = 0;
7568 u32 enable_disable = 1;
7570 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) {
7571 if (unformat (line_input, "address %U",
7572 unformat_ip4_address, &address))
7574 else if (unformat (line_input, "del"))
7580 if (address_set == 0) {
7581 errmsg ("missing addresses\n");
7585 M(WANT_IP4_ARP_EVENTS, want_ip4_arp_events);
7586 mp->enable_disable = enable_disable;
7588 mp->address = address.as_u32;
7593 static int api_input_acl_set_interface (vat_main_t * vam)
7595 unformat_input_t * i = vam->input;
7596 vl_api_input_acl_set_interface_t *mp;
7599 int sw_if_index_set;
7600 u32 ip4_table_index = ~0;
7601 u32 ip6_table_index = ~0;
7602 u32 l2_table_index = ~0;
7605 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
7606 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
7607 sw_if_index_set = 1;
7608 else if (unformat (i, "sw_if_index %d", &sw_if_index))
7609 sw_if_index_set = 1;
7610 else if (unformat (i, "del"))
7612 else if (unformat (i, "ip4-table %d", &ip4_table_index))
7614 else if (unformat (i, "ip6-table %d", &ip6_table_index))
7616 else if (unformat (i, "l2-table %d", &l2_table_index))
7619 clib_warning ("parse error '%U'", format_unformat_error, i);
7624 if (sw_if_index_set == 0) {
7625 errmsg ("missing interface name or sw_if_index\n");
7629 M(INPUT_ACL_SET_INTERFACE, input_acl_set_interface);
7631 mp->sw_if_index = ntohl(sw_if_index);
7632 mp->ip4_table_index = ntohl(ip4_table_index);
7633 mp->ip6_table_index = ntohl(ip6_table_index);
7634 mp->l2_table_index = ntohl(l2_table_index);
7635 mp->is_add = is_add;
7643 api_ip_address_dump (vat_main_t * vam)
7645 unformat_input_t * i = vam->input;
7646 vl_api_ip_address_dump_t * mp;
7647 u32 sw_if_index = ~0;
7648 u8 sw_if_index_set = 0;
7653 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
7654 if (unformat (i, "sw_if_index %d", &sw_if_index))
7655 sw_if_index_set = 1;
7656 else if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
7657 sw_if_index_set = 1;
7658 else if (unformat (i, "ipv4"))
7660 else if (unformat (i, "ipv6"))
7666 if (ipv4_set && ipv6_set) {
7667 errmsg ("ipv4 and ipv6 flags cannot be both set\n");
7671 if ((!ipv4_set) && (!ipv6_set)) {
7672 errmsg ("no ipv4 nor ipv6 flag set\n");
7676 if (sw_if_index_set == 0) {
7677 errmsg ("missing interface name or sw_if_index\n");
7681 vam->current_sw_if_index = sw_if_index;
7682 vam->is_ipv6 = ipv6_set;
7684 M(IP_ADDRESS_DUMP, ip_address_dump);
7685 mp->sw_if_index = ntohl(sw_if_index);
7686 mp->is_ipv6 = ipv6_set;
7689 /* Use a control ping for synchronization */
7691 vl_api_control_ping_t * mp;
7692 M(CONTROL_PING, control_ping);
7699 api_ip_dump (vat_main_t * vam)
7701 vl_api_ip_dump_t * mp;
7702 unformat_input_t * in = vam->input;
7709 while (unformat_check_input (in) != UNFORMAT_END_OF_INPUT) {
7710 if (unformat (in, "ipv4"))
7712 else if (unformat (in, "ipv6"))
7718 if (ipv4_set && ipv6_set) {
7719 errmsg ("ipv4 and ipv6 flags cannot be both set\n");
7723 if ((!ipv4_set) && (!ipv6_set)) {
7724 errmsg ("no ipv4 nor ipv6 flag set\n");
7729 vam->is_ipv6 = is_ipv6;
7732 for (i = 0; i < vec_len(vam->ip_details_by_sw_if_index[is_ipv6]); i++) {
7733 vec_free(vam->ip_details_by_sw_if_index[is_ipv6][i].addr);
7735 vec_free(vam->ip_details_by_sw_if_index[is_ipv6]);
7737 M(IP_DUMP, ip_dump);
7738 mp->is_ipv6 = ipv6_set;
7741 /* Use a control ping for synchronization */
7743 vl_api_control_ping_t * mp;
7744 M(CONTROL_PING, control_ping);
7751 api_ipsec_spd_add_del (vat_main_t * vam)
7754 unformat_input_t * i = vam->input;
7755 vl_api_ipsec_spd_add_del_t *mp;
7760 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
7761 if (unformat (i, "spd_id %d", &spd_id))
7763 else if (unformat (i, "del"))
7766 clib_warning ("parse error '%U'", format_unformat_error, i);
7771 errmsg ("spd_id must be set\n");
7775 M(IPSEC_SPD_ADD_DEL, ipsec_spd_add_del);
7777 mp->spd_id = ntohl(spd_id);
7778 mp->is_add = is_add;
7784 clib_warning ("unsupported (no dpdk)");
7790 api_ipsec_interface_add_del_spd (vat_main_t * vam)
7793 unformat_input_t * i = vam->input;
7794 vl_api_ipsec_interface_add_del_spd_t *mp;
7797 u8 sw_if_index_set = 0;
7798 u32 spd_id = (u32) ~0;
7801 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
7802 if (unformat (i, "del"))
7804 else if (unformat (i, "spd_id %d", &spd_id))
7806 else if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
7807 sw_if_index_set = 1;
7808 else if (unformat (i, "sw_if_index %d", &sw_if_index))
7809 sw_if_index_set = 1;
7811 clib_warning ("parse error '%U'", format_unformat_error, i);
7817 if (spd_id == (u32) ~0) {
7818 errmsg ("spd_id must be set\n");
7822 if (sw_if_index_set == 0) {
7823 errmsg ("missing interface name or sw_if_index\n");
7827 M(IPSEC_INTERFACE_ADD_DEL_SPD, ipsec_interface_add_del_spd);
7829 mp->spd_id = ntohl(spd_id);
7830 mp->sw_if_index = ntohl (sw_if_index);
7831 mp->is_add = is_add;
7837 clib_warning ("unsupported (no dpdk)");
7843 api_ipsec_spd_add_del_entry (vat_main_t * vam)
7846 unformat_input_t * i = vam->input;
7847 vl_api_ipsec_spd_add_del_entry_t *mp;
7849 u8 is_add = 1, is_outbound = 0, is_ipv6 = 0, is_ip_any = 1;
7850 u32 spd_id, sa_id, protocol = 0, policy = 0;
7852 u32 rport_start = 0, rport_stop = (u32) ~0;
7853 u32 lport_start = 0, lport_stop = (u32) ~0;
7854 ip4_address_t laddr4_start, laddr4_stop, raddr4_start, raddr4_stop;
7855 ip6_address_t laddr6_start, laddr6_stop, raddr6_start, raddr6_stop;
7857 laddr4_start.as_u32 = raddr4_start.as_u32 = 0;
7858 laddr4_stop.as_u32 = raddr4_stop.as_u32 = (u32) ~0;
7859 laddr6_start.as_u64[0] = raddr6_start.as_u64[0] = 0;
7860 laddr6_start.as_u64[1] = raddr6_start.as_u64[1] = 0;
7861 laddr6_stop.as_u64[0] = raddr6_stop.as_u64[0] = (u64) ~0;
7862 laddr6_stop.as_u64[1] = raddr6_stop.as_u64[1] = (u64) ~0;
7864 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
7865 if (unformat (i, "del"))
7867 if (unformat (i, "outbound"))
7869 if (unformat (i, "inbound"))
7871 else if (unformat (i, "spd_id %d", &spd_id))
7873 else if (unformat (i, "sa_id %d", &sa_id))
7875 else if (unformat (i, "priority %d", &priority))
7877 else if (unformat (i, "protocol %d", &protocol))
7879 else if (unformat (i, "lport_start %d", &lport_start))
7881 else if (unformat (i, "lport_stop %d", &lport_stop))
7883 else if (unformat (i, "rport_start %d", &rport_start))
7885 else if (unformat (i, "rport_stop %d", &rport_stop))
7887 else if (unformat (i, "laddr_start %U", unformat_ip4_address, &laddr4_start))
7892 else if (unformat (i, "laddr_stop %U", unformat_ip4_address, &laddr4_stop))
7897 else if (unformat (i, "raddr_start %U", unformat_ip4_address, &raddr4_start))
7902 else if (unformat (i, "raddr_stop %U", unformat_ip4_address, &raddr4_stop))
7907 else if (unformat (i, "laddr_start %U", unformat_ip6_address, &laddr6_start))
7912 else if (unformat (i, "laddr_stop %U", unformat_ip6_address, &laddr6_stop))
7917 else if (unformat (i, "raddr_start %U", unformat_ip6_address, &raddr6_start))
7922 else if (unformat (i, "raddr_stop %U", unformat_ip6_address, &raddr6_stop))
7927 else if (unformat (i, "action %U", unformat_ipsec_policy_action, &policy))
7929 if (policy == IPSEC_POLICY_ACTION_RESOLVE) {
7930 clib_warning ("unsupported action: 'resolve'");
7935 clib_warning ("parse error '%U'", format_unformat_error, i);
7941 M(IPSEC_SPD_ADD_DEL_ENTRY, ipsec_spd_add_del_entry);
7943 mp->spd_id = ntohl(spd_id);
7944 mp->priority = ntohl(priority);
7945 mp->is_outbound = is_outbound;
7947 mp->is_ipv6 = is_ipv6;
7948 if (is_ipv6 || is_ip_any) {
7949 memcpy (mp->remote_address_start, &raddr6_start, sizeof(ip6_address_t));
7950 memcpy (mp->remote_address_stop, &raddr6_stop, sizeof(ip6_address_t));
7951 memcpy (mp->local_address_start, &laddr6_start, sizeof(ip6_address_t));
7952 memcpy (mp->local_address_stop, &laddr6_stop, sizeof(ip6_address_t));
7954 memcpy (mp->remote_address_start, &raddr4_start, sizeof(ip4_address_t));
7955 memcpy (mp->remote_address_stop, &raddr4_stop, sizeof(ip4_address_t));
7956 memcpy (mp->local_address_start, &laddr4_start, sizeof(ip4_address_t));
7957 memcpy (mp->local_address_stop, &laddr4_stop, sizeof(ip4_address_t));
7959 mp->protocol = (u8) protocol;
7960 mp->local_port_start = ntohs((u16) lport_start);
7961 mp->local_port_stop = ntohs((u16) lport_stop);
7962 mp->remote_port_start = ntohs((u16) rport_start);
7963 mp->remote_port_stop = ntohs((u16) rport_stop);
7964 mp->policy = (u8) policy;
7965 mp->sa_id = ntohl(sa_id);
7966 mp->is_add = is_add;
7967 mp->is_ip_any = is_ip_any;
7972 clib_warning ("unsupported (no dpdk)");
7978 api_ipsec_sad_add_del_entry (vat_main_t * vam)
7981 unformat_input_t * i = vam->input;
7982 vl_api_ipsec_sad_add_del_entry_t *mp;
7988 u8 protocol = IPSEC_PROTOCOL_AH;
7989 u8 is_tunnel = 0, is_tunnel_ipv6 = 0;
7990 u32 crypto_alg = 0, integ_alg = 0;
7991 ip4_address_t tun_src4;
7992 ip4_address_t tun_dst4;
7993 ip6_address_t tun_src6;
7994 ip6_address_t tun_dst6;
7996 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
7997 if (unformat (i, "del"))
7999 else if (unformat (i, "sad_id %d", &sad_id))
8001 else if (unformat (i, "spi %d", &spi))
8003 else if (unformat (i, "esp"))
8004 protocol = IPSEC_PROTOCOL_ESP;
8005 else if (unformat (i, "tunnel_src %U", unformat_ip4_address, &tun_src4)) {
8009 else if (unformat (i, "tunnel_dst %U", unformat_ip4_address, &tun_dst4)) {
8013 else if (unformat (i, "tunnel_src %U", unformat_ip6_address, &tun_src6)) {
8017 else if (unformat (i, "tunnel_dst %U", unformat_ip6_address, &tun_dst6)) {
8021 else if (unformat (i, "crypto_alg %U", unformat_ipsec_crypto_alg, &crypto_alg)) {
8022 if (crypto_alg < IPSEC_CRYPTO_ALG_AES_CBC_128 ||
8023 crypto_alg > IPSEC_INTEG_ALG_SHA_512_256) {
8024 clib_warning ("unsupported crypto-alg: '%U'",
8025 format_ipsec_crypto_alg, crypto_alg);
8029 else if (unformat (i, "crypto_key %U", unformat_hex_string, &ck))
8031 else if (unformat (i, "integ_alg %U", unformat_ipsec_integ_alg, &integ_alg)) {
8032 if (integ_alg < IPSEC_INTEG_ALG_SHA1_96 ||
8033 integ_alg > IPSEC_INTEG_ALG_SHA_512_256) {
8034 clib_warning ("unsupported integ-alg: '%U'",
8035 format_ipsec_integ_alg, integ_alg);
8039 else if (unformat (i, "integ_key %U", unformat_hex_string, &ik))
8042 clib_warning ("parse error '%U'", format_unformat_error, i);
8048 M(IPSEC_SAD_ADD_DEL_ENTRY, ipsec_sad_add_del_entry);
8050 mp->sad_id = ntohl(sad_id);
8051 mp->is_add = is_add;
8052 mp->protocol = protocol;
8053 mp->spi = ntohl(spi);
8054 mp->is_tunnel = is_tunnel;
8055 mp->is_tunnel_ipv6 = is_tunnel_ipv6;
8056 mp->crypto_algorithm = crypto_alg;
8057 mp->integrity_algorithm = integ_alg;
8058 mp->crypto_key_length = vec_len(ck);
8059 mp->integrity_key_length = vec_len(ik);
8061 if (mp->crypto_key_length > sizeof(mp->crypto_key))
8062 mp->crypto_key_length = sizeof(mp->crypto_key);
8064 if (mp->integrity_key_length > sizeof(mp->integrity_key))
8065 mp->integrity_key_length = sizeof(mp->integrity_key);
8067 memcpy (mp->crypto_key, ck, mp->crypto_key_length);
8068 memcpy (mp->integrity_key, ik, mp->integrity_key_length);
8071 if (is_tunnel_ipv6) {
8072 memcpy (mp->tunnel_src_address, &tun_src6, sizeof(ip6_address_t));
8073 memcpy (mp->tunnel_dst_address, &tun_dst6, sizeof(ip6_address_t));
8075 memcpy (mp->tunnel_src_address, &tun_src4, sizeof(ip4_address_t));
8076 memcpy (mp->tunnel_dst_address, &tun_dst4, sizeof(ip4_address_t));
8084 clib_warning ("unsupported (no dpdk)");
8090 api_ipsec_sa_set_key (vat_main_t * vam)
8093 unformat_input_t * i = vam->input;
8094 vl_api_ipsec_sa_set_key_t *mp;
8099 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
8100 if (unformat (i, "sa_id %d", &sa_id))
8102 else if (unformat (i, "crypto_key %U", unformat_hex_string, &ck))
8104 else if (unformat (i, "integ_key %U", unformat_hex_string, &ik))
8107 clib_warning ("parse error '%U'", format_unformat_error, i);
8112 M(IPSEC_SA_SET_KEY, ipsec_set_sa_key);
8114 mp->sa_id = ntohl(sa_id);
8115 mp->crypto_key_length = vec_len(ck);
8116 mp->integrity_key_length = vec_len(ik);
8118 if (mp->crypto_key_length > sizeof(mp->crypto_key))
8119 mp->crypto_key_length = sizeof(mp->crypto_key);
8121 if (mp->integrity_key_length > sizeof(mp->integrity_key))
8122 mp->integrity_key_length = sizeof(mp->integrity_key);
8124 memcpy (mp->crypto_key, ck, mp->crypto_key_length);
8125 memcpy (mp->integrity_key, ik, mp->integrity_key_length);
8131 clib_warning ("unsupported (no dpdk)");
8139 static int api_map_add_domain (vat_main_t * vam)
8141 unformat_input_t *i = vam->input;
8142 vl_api_map_add_domain_t *mp;
8145 ip4_address_t ip4_prefix;
8146 ip6_address_t ip6_prefix;
8147 ip6_address_t ip6_src;
8149 u32 ip6_prefix_len, ip4_prefix_len, ea_bits_len, psid_offset,
8151 u8 is_translation = 0;
8153 u8 ip6_src_len = 128;
8155 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
8156 if (unformat (i, "ip4-pfx %U/%d", unformat_ip4_address,
8157 &ip4_prefix, &ip4_prefix_len))
8159 else if (unformat (i, "ip6-pfx %U/%d", unformat_ip6_address,
8160 &ip6_prefix, &ip6_prefix_len))
8162 else if (unformat (i, "ip6-src %U/%d", unformat_ip6_address, &ip6_src, &ip6_src_len))
8164 else if (unformat (i, "ip6-src %U", unformat_ip6_address, &ip6_src))
8166 else if (unformat (i, "ea-bits-len %d", &ea_bits_len))
8168 else if (unformat (i, "psid-offset %d", &psid_offset))
8170 else if (unformat (i, "psid-len %d", &psid_length))
8172 else if (unformat (i, "mtu %d", &mtu))
8174 else if (unformat (i, "map-t"))
8177 clib_warning ("parse error '%U'", format_unformat_error, i);
8182 if (num_m_args != 6) {
8183 errmsg("mandatory argument(s) missing\n");
8187 /* Construct the API message */
8188 M(MAP_ADD_DOMAIN, map_add_domain);
8190 memcpy(mp->ip4_prefix, &ip4_prefix, sizeof(ip4_prefix));
8191 mp->ip4_prefix_len = ip4_prefix_len;
8193 memcpy(mp->ip6_prefix, &ip6_prefix, sizeof(ip6_prefix));
8194 mp->ip6_prefix_len = ip6_prefix_len;
8196 memcpy(mp->ip6_src, &ip6_src, sizeof(ip6_src));
8197 mp->ip6_src_prefix_len = ip6_src_len;
8199 mp->ea_bits_len = ea_bits_len;
8200 mp->psid_offset = psid_offset;
8201 mp->psid_length = psid_length;
8202 mp->is_translation = is_translation;
8203 mp->mtu = htons(mtu);
8208 /* Wait for a reply, return good/bad news */
8212 static int api_map_del_domain (vat_main_t * vam)
8214 unformat_input_t *i = vam->input;
8215 vl_api_map_del_domain_t *mp;
8221 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
8222 if (unformat (i, "index %d", &index))
8225 clib_warning ("parse error '%U'", format_unformat_error, i);
8230 if (num_m_args != 1) {
8231 errmsg("mandatory argument(s) missing\n");
8235 /* Construct the API message */
8236 M(MAP_DEL_DOMAIN, map_del_domain);
8238 mp->index = ntohl(index);
8243 /* Wait for a reply, return good/bad news */
8247 static int api_map_add_del_rule (vat_main_t * vam)
8249 unformat_input_t *i = vam->input;
8250 vl_api_map_add_del_rule_t *mp;
8253 ip6_address_t ip6_dst;
8254 u32 num_m_args = 0, index, psid;
8256 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
8257 if (unformat (i, "index %d", &index))
8259 else if (unformat (i, "psid %d", &psid))
8261 else if (unformat (i, "dst %U", unformat_ip6_address, &ip6_dst))
8263 else if (unformat (i, "del")) {
8266 clib_warning ("parse error '%U'", format_unformat_error, i);
8271 /* Construct the API message */
8272 M(MAP_ADD_DEL_RULE, map_add_del_rule);
8274 mp->index = ntohl(index);
8275 mp->is_add = is_add;
8276 memcpy(mp->ip6_dst, &ip6_dst, sizeof(ip6_dst));
8277 mp->psid = ntohs(psid);
8282 /* Wait for a reply, return good/bad news */
8286 static int api_map_domain_dump (vat_main_t * vam)
8288 vl_api_map_domain_dump_t *mp;
8291 /* Construct the API message */
8292 M(MAP_DOMAIN_DUMP, map_domain_dump);
8297 /* Use a control ping for synchronization */
8299 vl_api_control_ping_t * mp;
8300 M(CONTROL_PING, control_ping);
8306 static int api_map_rule_dump (vat_main_t * vam)
8308 unformat_input_t *i = vam->input;
8309 vl_api_map_rule_dump_t *mp;
8311 u32 domain_index = ~0;
8313 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
8314 if (unformat (i, "index %u", &domain_index))
8320 if (domain_index == ~0) {
8321 clib_warning("parse error: domain index expected");
8325 /* Construct the API message */
8326 M(MAP_RULE_DUMP, map_rule_dump);
8328 mp->domain_index = htonl(domain_index);
8333 /* Use a control ping for synchronization */
8335 vl_api_control_ping_t * mp;
8336 M(CONTROL_PING, control_ping);
8342 static void vl_api_map_add_domain_reply_t_handler
8343 (vl_api_map_add_domain_reply_t * mp)
8345 vat_main_t * vam = &vat_main;
8346 i32 retval = ntohl(mp->retval);
8348 if (vam->async_mode) {
8349 vam->async_errors += (retval < 0);
8351 vam->retval = retval;
8352 vam->result_ready = 1;
8356 static void vl_api_map_add_domain_reply_t_handler_json
8357 (vl_api_map_add_domain_reply_t * mp)
8359 vat_main_t * vam = &vat_main;
8360 vat_json_node_t node;
8362 vat_json_init_object(&node);
8363 vat_json_object_add_int(&node, "retval", ntohl(mp->retval));
8364 vat_json_object_add_uint(&node, "index", ntohl(mp->index));
8366 vat_json_print(vam->ofp, &node);
8367 vat_json_free(&node);
8369 vam->retval = ntohl(mp->retval);
8370 vam->result_ready = 1;
8374 api_get_first_msg_id (vat_main_t * vam)
8376 vl_api_get_first_msg_id_t * mp;
8378 unformat_input_t * i = vam->input;
8382 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
8383 if (unformat (i, "client %s", &name))
8389 if (name_set == 0) {
8390 errmsg ("missing client name\n");
8395 if (vec_len (name) > 63) {
8396 errmsg ("client name too long\n");
8400 M(GET_FIRST_MSG_ID, get_first_msg_id);
8401 memcpy (mp->name, name, vec_len(name));
8407 static int api_cop_interface_enable_disable (vat_main_t * vam)
8409 unformat_input_t * line_input = vam->input;
8410 vl_api_cop_interface_enable_disable_t * mp;
8412 u32 sw_if_index = ~0;
8413 u8 enable_disable = 1;
8415 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) {
8416 if (unformat (line_input, "disable"))
8418 if (unformat (line_input, "enable"))
8420 else if (unformat (line_input, "%U", unformat_sw_if_index,
8423 else if (unformat (line_input, "sw_if_index %d", &sw_if_index))
8429 if (sw_if_index == ~0) {
8430 errmsg ("missing interface name or sw_if_index\n");
8434 /* Construct the API message */
8435 M(COP_INTERFACE_ENABLE_DISABLE, cop_interface_enable_disable);
8436 mp->sw_if_index = ntohl(sw_if_index);
8437 mp->enable_disable = enable_disable;
8441 /* Wait for the reply */
8445 static int api_cop_whitelist_enable_disable (vat_main_t * vam)
8447 unformat_input_t * line_input = vam->input;
8448 vl_api_cop_whitelist_enable_disable_t * mp;
8450 u32 sw_if_index = ~0;
8451 u8 ip4=0, ip6=0, default_cop=0;
8454 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) {
8455 if (unformat (line_input, "ip4"))
8457 else if (unformat (line_input, "ip6"))
8459 else if (unformat (line_input, "default"))
8461 else if (unformat (line_input, "%U", unformat_sw_if_index,
8464 else if (unformat (line_input, "sw_if_index %d", &sw_if_index))
8466 else if (unformat (line_input, "fib-id %d", &fib_id))
8472 if (sw_if_index == ~0) {
8473 errmsg ("missing interface name or sw_if_index\n");
8477 /* Construct the API message */
8478 M(COP_WHITELIST_ENABLE_DISABLE, cop_whitelist_enable_disable);
8479 mp->sw_if_index = ntohl(sw_if_index);
8480 mp->fib_id = ntohl(fib_id);
8483 mp->default_cop = default_cop;
8487 /* Wait for the reply */
8491 static int q_or_quit (vat_main_t * vam)
8493 longjmp (vam->jump_buf, 1);
8494 return 0; /* not so much */
8496 static int q (vat_main_t * vam) {return q_or_quit (vam);}
8497 static int quit (vat_main_t * vam) {return q_or_quit (vam);}
8499 static int comment (vat_main_t * vam)
8504 static int cmd_cmp (void * a1, void * a2)
8509 return strcmp ((char *)(c1[0]), (char *)(c2[0]));
8512 static int help (vat_main_t * vam)
8517 unformat_input_t * i = vam->input;
8520 if (unformat (i, "%s", &name)) {
8525 hs = hash_get_mem (vam->help_by_name, name);
8527 fformat (vam->ofp, "usage: %s %s\n", name, hs[0]);
8529 fformat (vam->ofp, "No such msg / command '%s'\n", name);
8534 fformat(vam->ofp, "Help is available for the following:\n");
8536 hash_foreach_pair (p, vam->function_by_name,
8538 vec_add1 (cmds, (u8 *)(p->key));
8541 vec_sort_with_function (cmds, cmd_cmp);
8543 for (j = 0; j < vec_len(cmds); j++)
8544 fformat (vam->ofp, "%s\n", cmds[j]);
8550 static int set (vat_main_t * vam)
8552 u8 * name = 0, * value = 0;
8553 unformat_input_t * i = vam->input;
8555 if (unformat (i, "%s", &name)) {
8556 /* The input buffer is a vector, not a string. */
8557 value = vec_dup (i->buffer);
8558 vec_delete (value, i->index, 0);
8559 /* Almost certainly has a trailing newline */
8560 if (value[vec_len(value)-1] == '\n')
8561 value[vec_len(value)-1] = 0;
8562 /* Make sure it's a proper string, one way or the other */
8563 vec_add1 (value, 0);
8564 (void) clib_macro_set_value (&vam->macro_main,
8565 (char *)name, (char *)value);
8568 errmsg ("usage: set <name> <value>\n");
8575 static int unset (vat_main_t * vam)
8579 if (unformat (vam->input, "%s", &name))
8580 if (clib_macro_unset (&vam->macro_main, (char *)name) == 1)
8581 errmsg ("unset: %s wasn't set\n", name);
8592 static int macro_sort_cmp (void * a1, void * a2)
8594 macro_sort_t * s1 = a1;
8595 macro_sort_t * s2 = a2;
8597 return strcmp ((char *)(s1->name), (char *)(s2->name));
8600 static int dump_macro_table (vat_main_t * vam)
8602 macro_sort_t * sort_me = 0, * sm;
8606 hash_foreach_pair (p, vam->macro_main.the_value_table_hash,
8608 vec_add2 (sort_me, sm, 1);
8609 sm->name = (u8 *)(p->key);
8610 sm->value = (u8 *) (p->value[0]);
8613 vec_sort_with_function (sort_me, macro_sort_cmp);
8615 if (vec_len(sort_me))
8616 fformat (vam->ofp, "%-15s%s\n", "Name", "Value");
8618 fformat (vam->ofp, "The macro table is empty...\n");
8620 for (i = 0; i < vec_len (sort_me); i++)
8621 fformat (vam->ofp, "%-15s%s\n", sort_me[i].name,
8626 static int script (vat_main_t * vam)
8629 char * save_current_file;
8630 unformat_input_t save_input;
8631 jmp_buf save_jump_buf;
8632 u32 save_line_number;
8634 FILE * new_fp, * save_ifp;
8636 if (unformat (vam->input, "%s", &s)) {
8637 new_fp = fopen ((char *)s, "r");
8639 errmsg ("Couldn't open script file %s\n", s);
8644 errmsg ("Missing script name\n");
8648 memcpy (&save_input, &vam->input, sizeof (save_input));
8649 memcpy (&save_jump_buf, &vam->jump_buf, sizeof (save_jump_buf));
8650 save_ifp = vam->ifp;
8651 save_line_number = vam->input_line_number;
8652 save_current_file = (char *) vam->current_file;
8654 vam->input_line_number = 0;
8656 vam->current_file = s;
8659 memcpy (&vam->input, &save_input, sizeof (vam->input));
8660 memcpy (&vam->jump_buf, &save_jump_buf, sizeof (save_jump_buf));
8661 vam->ifp = save_ifp;
8662 vam->input_line_number = save_line_number;
8663 vam->current_file = (u8 *) save_current_file;
8669 static int echo (vat_main_t * vam)
8671 fformat (vam->ofp, "%v", vam->input->buffer);
8675 /* List of API message constructors, CLI names map to api_xxx */
8676 #define foreach_vpe_api_msg \
8677 _(create_loopback,"[mac <mac-addr>]") \
8678 _(sw_interface_dump,"") \
8679 _(sw_interface_set_flags, \
8680 "<intfc> | sw_if_index <id> admin-up | admin-down link-up | link down") \
8681 _(sw_interface_add_del_address, \
8682 "<intfc> | sw_if_index <id> <ip4-address> | <ip6-address> [del] [del-all] ") \
8683 _(sw_interface_set_table, \
8684 "<intfc> | sw_if_index <id> vrf <table-id> [ipv6]") \
8685 _(sw_interface_set_vpath, \
8686 "<intfc> | sw_if_index <id> enable | disable") \
8687 _(sw_interface_set_l2_xconnect, \
8688 "rx <intfc> | rx_sw_if_index <id> tx <intfc> | tx_sw_if_index <id>\n" \
8689 "enable | disable") \
8690 _(sw_interface_set_l2_bridge, \
8691 "rx <intfc> | rx_sw_if_index <id> bd_id <bridge-domain-id>\n" \
8692 "[shg <split-horizon-group>] [bvi]\n" \
8693 "enable | disable") \
8694 _(bridge_domain_add_del, \
8695 "bd_id <bridge-domain-id> [flood 1|0] [uu-flood 1|0] [forward 1|0] [learn 1|0] [arp-term 1|0] [del]\n")\
8696 _(bridge_domain_dump, "[bd_id <bridge-domain-id>]\n") \
8698 "mac <mac-addr> bd_id <bridge-domain-id> [del] | sw_if <intfc> | sw_if_index <id> [static] [filter] [bvi]\n") \
8700 "sw_if <intfc> | sw_if_index <id> [learn] [forward] [uu-flood] [flood]\n") \
8702 "bd_id <bridge-domain-id> [learn] [forward] [uu-flood] [flood] [arp-term] [disable]\n") \
8704 "tapname <name> mac <mac-addr> | random-mac") \
8706 "<vpp-if-name> | sw_if_index <id> tapname <name> mac <mac-addr> | random-mac") \
8708 "<vpp-if-name> | sw_if_index <id>") \
8709 _(sw_interface_tap_dump, "") \
8710 _(ip_add_del_route, \
8711 "<addr>/<mask> via <addr> [vrf <n>]\n" \
8712 "[<intfc> | sw_if_index <id>] [resolve-attempts <n>]\n" \
8713 "[weight <n>] [drop] [local] [classify <n>] [del]\n" \
8714 "[multipath] [count <n>]") \
8715 _(proxy_arp_add_del, \
8716 "<lo-ip4-addr> - <hi-ip4-addr> [vrf <n>] [del]") \
8717 _(proxy_arp_intfc_enable_disable, \
8718 "<intfc> | sw_if_index <id> enable | disable") \
8719 _(mpls_add_del_encap, \
8720 "label <n> dst <ip4-addr> [vrf <n>] [del]") \
8721 _(mpls_add_del_decap, \
8722 "label <n> [rx_vrf_id <n>] [tx_vrf_id] [s-bit-clear][del]") \
8723 _(mpls_gre_add_del_tunnel, \
8724 "inner_vrf_id <n> outer_vrf_id <n> src <ip4-address> dst <ip4-address>\n" \
8725 "adj <ip4-address>/<mask-width> [del]") \
8726 _(sw_interface_set_unnumbered, \
8727 "<intfc> | sw_if_index <id> unnum_if_index <id> [del]") \
8728 _(ip_neighbor_add_del, \
8729 "<intfc> | sw_if_index <id> dst <ip46-address> mac <mac-addr>") \
8730 _(reset_vrf, "vrf <id> [ipv6]") \
8731 _(create_vlan_subif, "<intfc> | sw_if_index <id> vlan <n>") \
8732 _(create_subif, "<intfc> | sw_if_index <id> sub_id <n>\n" \
8733 "[outer_vlan_id <n>][inner_vlan_id <n>]\n" \
8734 "[no_tags][one_tag][two_tags][dot1ad][exact_match][default_sub]\n" \
8735 "[outer_vlan_id_any][inner_vlan_id_any]") \
8736 _(oam_add_del, "src <ip4-address> dst <ip4-address> [vrf <n>] [del]") \
8737 _(reset_fib, "vrf <n> [ipv6]") \
8738 _(dhcp_proxy_config, \
8739 "svr <v46-address> src <v46-address>\n" \
8740 "insert-cid <n> [del]") \
8741 _(dhcp_proxy_config_2, \
8742 "svr <v46-address> src <v46-address>\n" \
8743 "rx_vrf_id <nn> server_vrf_id <nn> insert-cid <n> [del]") \
8744 _(dhcp_proxy_set_vss, \
8745 "tbl_id <n> fib_id <n> oui <n> [ipv6] [del]") \
8746 _(dhcp_client_config, \
8747 "<intfc> | sw_if_index <id> [hostname <name>] [disable_event] [del]") \
8748 _(set_ip_flow_hash, \
8749 "vrf <n> [src] [dst] [sport] [dport] [proto] [reverse] [ipv6]") \
8750 _(sw_interface_ip6_enable_disable, \
8751 "<intfc> | sw_if_index <id> enable | disable") \
8752 _(sw_interface_ip6_set_link_local_address, \
8753 "<intfc> | sw_if_index <id> <ip6-address>/<mask-width>") \
8754 _(sw_interface_ip6nd_ra_prefix, \
8755 "<intfc> | sw_if_index <id> <ip6-address>/<mask-width>\n" \
8756 "val_life <n> pref_life <n> [def] [noadv] [offl] [noauto]\n" \
8757 "[nolink] [isno]") \
8758 _(sw_interface_ip6nd_ra_config, \
8759 "<intfc> | sw_if_index <id> [maxint <n>] [minint <n>]\n" \
8760 "[life <n>] [count <n>] [interval <n>] [surpress]\n" \
8761 "[managed] [other] [ll] [send] [cease] [isno] [def]") \
8762 _(set_arp_neighbor_limit, "arp_nbr_limit <n> [ipv6]") \
8763 _(l2_patch_add_del, \
8764 "rx <intfc> | rx_sw_if_index <id> tx <intfc> | tx_sw_if_index <id>\n" \
8765 "enable | disable") \
8766 _(mpls_ethernet_add_del_tunnel, \
8767 "tx <intfc> | tx_sw_if_index <n> dst <mac-addr>\n" \
8768 "adj <ip4-addr>/<mw> dst <mac-addr> [del]") \
8769 _(mpls_ethernet_add_del_tunnel_2, \
8770 "inner_vrf_id <n> outer_vrf_id <n> next-hop <ip4-addr>\n" \
8771 "resolve-attempts <n> resolve-if-needed 0 | 1 [del]") \
8772 _(sr_tunnel_add_del, \
8773 "src <ip6-addr> dst <ip6-addr>/<mw> (next <ip6-addr>)+\n" \
8774 " [tag <ip6-addr>]* [clean] [reroute]") \
8775 _(classify_add_del_table, \
8776 "buckets <nn> [skip <n>] [match <n>] [memory_size <nn-bytes>]\n" \
8777 "[del] mask <mask-value>\n" \
8778 " [l2-miss-next | miss-next | acl-miss-next] <name|nn>") \
8779 _(classify_add_del_session, \
8780 "[hit-next|l2-hit-next|acl-hit-next] <name|nn> table-index <nn>\n" \
8781 "skip_n <nn> match_n <nn> match [hex] [l2] [l3 [ip4|ip6]]") \
8782 _(classify_set_interface_ip_table, \
8783 "<intfc> | sw_if_index <nn> table <nn>") \
8784 _(classify_set_interface_l2_tables, \
8785 "<intfc> | sw_if_index <nn> [ip4-table <nn>] [ip6-table <nn>]\n" \
8786 " [other-table <nn>]") \
8787 _(get_node_index, "node <node-name") \
8788 _(add_node_next, "node <node-name> next <next-node-name>") \
8789 _(l2tpv3_create_tunnel, \
8790 "client_address <ip6-addr> our_address <ip6-addr>\n" \
8791 "[local_session_id <nn>][remote_session_id <nn>][local_cookie <nn>]\n"\
8792 "[remote_cookie <nn>]\n[l2-sublayer-preset]\n") \
8793 _(l2tpv3_set_tunnel_cookies, \
8794 "<intfc> | sw_if_index <nn> [new_local_cookie <nn>]\n" \
8795 "[new_remote_cookie <nn>]\n") \
8796 _(l2tpv3_interface_enable_disable, \
8797 "<intfc> | sw_if_index <nn> enable | disable") \
8798 _(l2tpv3_set_lookup_key, \
8799 "lookup_v6_src | lookup_v6_dst | lookup_session_id") \
8800 _(sw_if_l2tpv3_tunnel_dump, "") \
8801 _(vxlan_add_del_tunnel, \
8802 "src <ip4-addr> dst <ip4-addr> vni [encap-vrf-id <nn>]\n" \
8803 " [decap-next l2|ip4|ip6] [del]") \
8804 _(vxlan_tunnel_dump, "[<intfc> | sw_if_index <nn>]") \
8805 _(l2_fib_clear_table, "") \
8806 _(l2_interface_efp_filter, "sw_if_index <nn> enable | disable") \
8807 _(l2_interface_vlan_tag_rewrite, \
8808 "<intfc> | sw_if_index <nn> \n" \
8809 "[disable][push-[1|2]][pop-[1|2]][translate-1-[1|2]] \n" \
8810 "[translate-2-[1|2]] [push_dot1q 0] tag1 <nn> tag2 <nn>") \
8811 _(create_vhost_user_if, \
8812 "socket <filename> [server] [renumber <dev_instance>]") \
8813 _(modify_vhost_user_if, \
8814 "<intfc> | sw_if_index <nn> socket <filename>\n" \
8815 "[server] [renumber <dev_instance>]") \
8816 _(delete_vhost_user_if, "<intfc> | sw_if_index <nn>") \
8817 _(sw_interface_vhost_user_dump, "") \
8818 _(show_version, "") \
8819 _(nsh_gre_add_del_tunnel, \
8820 "src <ip4-addr> dst <ip4-addr>" \
8821 "c1 <nn> c2 <nn> c3 <nn> c4 <nn> spi <nn> si <nn>\n" \
8822 "[encap-fib-id <nn>] [decap-fib-id <nn>] [o-bit <1|0>]\n" \
8823 "[c-bit <1|0>] [md-type <nn>][next-ip4][next-ip6][next-ethernet]\n" \
8824 "[tlv <xx>][del]") \
8825 _(nsh_vxlan_gpe_add_del_tunnel, \
8826 "src <ip4-addr> dst <ip4-addr> vni <nn>\n" \
8827 "c1 <nn> c2 <nn> c3 <nn> c4 <nn> spi <nn> si <nn>\n" \
8828 "[encap-vrf-id <nn>] [decap-vrf-id <nn>] [o-bit <1|0>]\n" \
8829 "[c-bit <1|0>] [md-type <nn>][next-ip4][next-ip6][next-ethernet]\n" \
8830 "[tlv <xx>][del]") \
8831 _(l2_fib_table_dump, "bd_id <bridge-domain-id>") \
8832 _(lisp_gpe_add_del_tunnel, \
8833 "src <ip4-addr> dst <ip4-addr> iid <nn>|iidx <0xnn>\n" \
8834 "[encap-vrf-id <nn>] [decap-vrf-id <nn>]\n" \
8835 "[n-bit][l-bit][e-bit][v-bit][i-bit][p-bit][not-p-bit][o-bit]\n" \
8836 "[next-ip4][next-ip6][next-ethernet][next-nsh]\n" \
8837 "[decap-next [ip4|ip6|ethernet|nsh-encap|<nn>]][del]") \
8838 _(interface_name_renumber, \
8839 "<intfc> | sw_if_index <nn> new_show_dev_instance <nn>") \
8840 _(input_acl_set_interface, \
8841 "<intfc> | sw_if_index <nn> [ip4-table <nn>] [ip6-table <nn>]\n" \
8842 " [l2-table <nn>] [del]") \
8843 _(want_ip4_arp_events, "address <ip4-address> [del]") \
8844 _(ip_address_dump, "(ipv4 | ipv6) (<intfc> | sw_if_index <id>)") \
8845 _(ip_dump, "ipv4 | ipv6") \
8846 _(ipsec_spd_add_del, "spd_id <n> [del]") \
8847 _(ipsec_interface_add_del_spd, "(<intfc> | sw_if_index <id>)\n" \
8849 _(ipsec_sad_add_del_entry, "sad_id <n> spi <n> crypto_alg <alg>\n" \
8850 " crypto_key <hex> tunnel_src <ip4|ip6> tunnel_dst <ip4|ip6>\n" \
8851 " integ_alg <alg> integ_key <hex>") \
8852 _(ipsec_spd_add_del_entry, "spd_id <n> priority <n> action <action>\n" \
8853 " (inbound|outbound) [sa_id <n>] laddr_start <ip4|ip6>\n" \
8854 " laddr_stop <ip4|ip6> raddr_start <ip4|ip6> raddr_stop <ip4|ip6>\n" \
8855 " [lport_start <n> lport_stop <n>] [rport_start <n> rport_stop <n>]" )\
8856 _(ipsec_sa_set_key, "sa_id <n> crypto_key <hex> integ_key <hex>") \
8857 _(delete_loopback,"sw_if_index <nn>") \
8858 _(bd_ip_mac_add_del, "bd_id <bridge-domain-id> <ip4/6-addr> <mac-addr> [del]") \
8860 "ip4-pfx <ip4pfx> ip6-pfx <ip6pfx> " \
8861 "ip6-src <ip6addr> " \
8862 "ea-bits-len <n> psid-offset <n> psid-len <n>") \
8863 _(map_del_domain, "index <n>") \
8864 _(map_add_del_rule, \
8865 "index <n> psid <n> dst <ip6addr> [del]") \
8866 _(map_domain_dump, "") \
8867 _(map_rule_dump, "index <map-domain>") \
8868 _(want_interface_events, "enable|disable") \
8869 _(want_stats,"enable|disable") \
8870 _(get_first_msg_id, "client <name>") \
8871 _(cop_interface_enable_disable, "<intfc> | sw_if_index <nn> [disable]") \
8872 _(cop_whitelist_enable_disable, "<intfc> | sw_if_index <nn>\n" \
8873 "fib-id <nn> [ip4][ip6][default]")
8875 /* List of command functions, CLI names map directly to functions */
8876 #define foreach_cli_function \
8877 _(comment, "usage: comment <ignore-rest-of-line>") \
8878 _(dump_interface_table, "usage: dump_interface_table") \
8879 _(dump_sub_interface_table, "usage: dump_sub_interface_table") \
8880 _(dump_ipv4_table, "usage: dump_ipv4_table") \
8881 _(dump_ipv6_table, "usage: dump_ipv6_table") \
8882 _(dump_stats_table, "usage: dump_stats_table") \
8883 _(dump_macro_table, "usage: dump_macro_table ") \
8884 _(echo, "usage: echo <message>") \
8885 _(exec, "usage: exec <vpe-debug-CLI-command>") \
8886 _(help, "usage: help") \
8887 _(q, "usage: quit") \
8888 _(quit, "usage: quit") \
8889 _(set, "usage: set <variable-name> <value>") \
8890 _(script, "usage: script <file-name>") \
8891 _(unset, "usage: unset <variable-name>")
8894 static void vl_api_##n##_t_handler_uni \
8895 (vl_api_##n##_t * mp) \
8897 vat_main_t * vam = &vat_main; \
8898 if (vam->json_output) { \
8899 vl_api_##n##_t_handler_json(mp); \
8901 vl_api_##n##_t_handler(mp); \
8904 foreach_vpe_api_reply_msg;
8907 void vat_api_hookup (vat_main_t *vam)
8910 vl_msg_api_set_handlers(VL_API_##N, #n, \
8911 vl_api_##n##_t_handler_uni, \
8913 vl_api_##n##_t_endian, \
8914 vl_api_##n##_t_print, \
8915 sizeof(vl_api_##n##_t), 1);
8916 foreach_vpe_api_reply_msg;
8919 vl_msg_api_set_first_available_msg_id (VL_MSG_FIRST_AVAILABLE);
8921 vam->sw_if_index_by_interface_name =
8922 hash_create_string (0, sizeof (uword));
8924 vam->function_by_name =
8925 hash_create_string (0, sizeof(uword));
8928 hash_create_string (0, sizeof(uword));
8930 /* API messages we can send */
8931 #define _(n,h) hash_set_mem (vam->function_by_name, #n, api_##n);
8932 foreach_vpe_api_msg;
8936 #define _(n,h) hash_set_mem (vam->help_by_name, #n, h);
8937 foreach_vpe_api_msg;
8941 #define _(n,h) hash_set_mem (vam->function_by_name, #n, n);
8942 foreach_cli_function;
8946 #define _(n,h) hash_set_mem (vam->help_by_name, #n, h);
8947 foreach_cli_function;
8951 #undef vl_api_version
8952 #define vl_api_version(n,v) static u32 vpe_api_version = v;
8953 #include <api/vpe.api.h>
8954 #undef vl_api_version
8956 void vl_client_add_api_signatures (vl_api_memclnt_create_t *mp)
8959 * Send the main API signature in slot 0. This bit of code must
8960 * match the checks in ../vpe/api/api.c: vl_msg_api_version_check().
8962 mp->api_versions[0] = clib_host_to_net_u32 (vpe_api_version);