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>
44 #include "vat/json_format.h"
46 #define vl_typedefs /* define message structures */
47 #include <api/vpe_all_api_h.h>
50 /* declare message handlers for each api */
52 #define vl_endianfun /* define message structures */
53 #include <api/vpe_all_api_h.h>
56 /* instantiate all the print functions we know about */
57 #define vl_print(handle, ...)
59 #include <api/vpe_all_api_h.h>
62 uword unformat_sw_if_index (unformat_input_t * input, va_list * args)
64 vat_main_t * vam = va_arg (*args, vat_main_t *);
65 u32 * result = va_arg (*args, u32 *);
69 if (!unformat (input, "%s", &if_name))
72 p = hash_get_mem (vam->sw_if_index_by_interface_name, if_name);
79 /* Parse an IP4 address %d.%d.%d.%d. */
80 uword unformat_ip4_address (unformat_input_t * input, va_list * args)
82 u8 * result = va_arg (*args, u8 *);
85 if (! unformat (input, "%d.%d.%d.%d", &a[0], &a[1], &a[2], &a[3]))
88 if (a[0] >= 256 || a[1] >= 256 || a[2] >= 256 || a[3] >= 256)
101 unformat_ethernet_address (unformat_input_t * input, va_list * args)
103 u8 * result = va_arg (*args, u8 *);
106 if (! unformat (input, "%_%x:%x:%x:%x:%x:%x%_",
107 &a[0], &a[1], &a[2], &a[3], &a[4], &a[5]))
111 for (i = 0; i < 6; i++)
112 if (a[i] >= (1 << 8))
115 for (i = 0; i < 6; i++)
121 /* Returns ethernet type as an int in host byte order. */
123 unformat_ethernet_type_host_byte_order (unformat_input_t * input,
126 u16 * result = va_arg (*args, u16 *);
130 if (unformat (input, "0x%x", &type)
131 || unformat (input, "%d", &type))
133 if (type >= (1 << 16))
141 /* Parse an IP6 address. */
142 uword unformat_ip6_address (unformat_input_t * input, va_list * args)
144 ip6_address_t * result = va_arg (*args, ip6_address_t *);
146 uword hex_quad, n_hex_quads, hex_digit, n_hex_digits;
147 uword c, n_colon, double_colon_index;
149 n_hex_quads = hex_quad = n_hex_digits = n_colon = 0;
150 double_colon_index = ARRAY_LEN (hex_quads);
151 while ((c = unformat_get_input (input)) != UNFORMAT_END_OF_INPUT)
154 if (c >= '0' && c <= '9')
156 else if (c >= 'a' && c <= 'f')
157 hex_digit = c + 10 - 'a';
158 else if (c >= 'A' && c <= 'F')
159 hex_digit = c + 10 - 'A';
160 else if (c == ':' && n_colon < 2)
164 unformat_put_input (input);
168 /* Too many hex quads. */
169 if (n_hex_quads >= ARRAY_LEN (hex_quads))
174 hex_quad = (hex_quad << 4) | hex_digit;
176 /* Hex quad must fit in 16 bits. */
177 if (n_hex_digits >= 4)
184 /* Save position of :: */
187 /* More than one :: ? */
188 if (double_colon_index < ARRAY_LEN (hex_quads))
190 double_colon_index = n_hex_quads;
193 if (n_colon > 0 && n_hex_digits > 0)
195 hex_quads[n_hex_quads++] = hex_quad;
201 if (n_hex_digits > 0)
202 hex_quads[n_hex_quads++] = hex_quad;
207 /* Expand :: to appropriate number of zero hex quads. */
208 if (double_colon_index < ARRAY_LEN (hex_quads))
210 word n_zero = ARRAY_LEN (hex_quads) - n_hex_quads;
212 for (i = n_hex_quads - 1; i >= (signed) double_colon_index; i--)
213 hex_quads[n_zero + i] = hex_quads[i];
215 for (i = 0; i < n_zero; i++)
216 hex_quads[double_colon_index + i] = 0;
218 n_hex_quads = ARRAY_LEN (hex_quads);
221 /* Too few hex quads given. */
222 if (n_hex_quads < ARRAY_LEN (hex_quads))
225 for (i = 0; i < ARRAY_LEN (hex_quads); i++)
226 result->as_u16[i] = clib_host_to_net_u16 (hex_quads[i]);
233 unformat_ipsec_policy_action (unformat_input_t * input, va_list * args)
236 u32 * r = va_arg (*args, u32 *);
239 #define _(v,f,s) else if (unformat (input, s)) *r = IPSEC_POLICY_ACTION_##f;
240 foreach_ipsec_policy_action
251 unformat_ipsec_crypto_alg (unformat_input_t * input, va_list * args)
254 u32 * r = va_arg (*args, u32 *);
257 #define _(v,f,s) else if (unformat (input, s)) *r = IPSEC_CRYPTO_ALG_##f;
258 foreach_ipsec_crypto_alg
269 format_ipsec_crypto_alg (u8 * s, va_list * args)
272 u32 i = va_arg (*args, u32);
277 #define _(v,f,str) case IPSEC_CRYPTO_ALG_##f: t = (u8 *) str; break;
278 foreach_ipsec_crypto_alg
281 return format (s, "unknown");
283 return format (s, "%s", t);
285 return format (s, "Unimplemented");
290 unformat_ipsec_integ_alg (unformat_input_t * input, va_list * args)
293 u32 * r = va_arg (*args, u32 *);
296 #define _(v,f,s) else if (unformat (input, s)) *r = IPSEC_INTEG_ALG_##f;
297 foreach_ipsec_integ_alg
308 format_ipsec_integ_alg (u8 * s, va_list * args)
311 u32 i = va_arg (*args, u32);
316 #define _(v,f,str) case IPSEC_INTEG_ALG_##f: t = (u8 *) str; break;
317 foreach_ipsec_integ_alg
320 return format (s, "unknown");
322 return format (s, "%s", t);
324 return format (s, "Unsupported");
328 u8 * format_ip4_address (u8 * s, va_list * args)
330 u8 * a = va_arg (*args, u8 *);
331 return format (s, "%d.%d.%d.%d", a[0], a[1], a[2], a[3]);
334 u8 * format_ip6_address (u8 * s, va_list * args)
336 ip6_address_t * a = va_arg (*args, ip6_address_t *);
337 u32 i, i_max_n_zero, max_n_zeros, i_first_zero, n_zeros, last_double_colon;
339 i_max_n_zero = ARRAY_LEN (a->as_u16);
341 i_first_zero = i_max_n_zero;
343 for (i = 0; i < ARRAY_LEN (a->as_u16); i++)
345 u32 is_zero = a->as_u16[i] == 0;
346 if (is_zero && i_first_zero >= ARRAY_LEN (a->as_u16))
352 if ((! is_zero && n_zeros > max_n_zeros)
353 || (i + 1 >= ARRAY_LEN (a->as_u16) && n_zeros > max_n_zeros))
355 i_max_n_zero = i_first_zero;
356 max_n_zeros = n_zeros;
357 i_first_zero = ARRAY_LEN (a->as_u16);
362 last_double_colon = 0;
363 for (i = 0; i < ARRAY_LEN (a->as_u16); i++)
365 if (i == i_max_n_zero && max_n_zeros > 1)
367 s = format (s, "::");
368 i += max_n_zeros - 1;
369 last_double_colon = 1;
373 s = format (s, "%s%x",
374 (last_double_colon || i == 0) ? "" : ":",
375 clib_net_to_host_u16 (a->as_u16[i]));
376 last_double_colon = 0;
383 u8 * format_ethernet_address (u8 * s, va_list * args)
385 u8 * a = va_arg (*args, u8 *);
387 return format (s, "%02x:%02x:%02x:%02x:%02x:%02x",
388 a[0], a[1], a[2], a[3], a[4], a[5]);
391 void increment_v4_address (ip4_address_t * a)
395 v = ntohl(a->as_u32) + 1;
396 a->as_u32 = ntohl(v);
399 void increment_v6_address (ip6_address_t * a)
403 v0 = clib_net_to_host_u64 (a->as_u64[0]);
404 v1 = clib_net_to_host_u64 (a->as_u64[1]);
409 a->as_u64[0] = clib_net_to_host_u64 (v0);
410 a->as_u64[1] = clib_net_to_host_u64 (v1);
414 static void vl_api_create_loopback_reply_t_handler
415 (vl_api_create_loopback_reply_t * mp)
417 vat_main_t * vam = &vat_main;
418 i32 retval = ntohl(mp->retval);
420 vam->retval = retval;
421 vam->result_ready = 1;
422 vam->regenerate_interface_table = 1;
425 static void vl_api_create_loopback_reply_t_handler_json
426 (vl_api_create_loopback_reply_t * mp)
428 vat_main_t * vam = &vat_main;
429 vat_json_node_t node;
431 vat_json_init_object(&node);
432 vat_json_object_add_int(&node, "retval", ntohl(mp->retval));
433 vat_json_object_add_uint(&node, "sw_if_index", ntohl(mp->sw_if_index));
435 vat_json_print(vam->ofp, &node);
436 vat_json_free(&node);
438 vam->retval = ntohl(mp->retval);
439 vam->result_ready = 1;
442 static void vl_api_create_vlan_subif_reply_t_handler
443 (vl_api_create_vlan_subif_reply_t * mp)
445 vat_main_t * vam = &vat_main;
446 i32 retval = ntohl(mp->retval);
448 vam->retval = retval;
449 vam->result_ready = 1;
450 vam->regenerate_interface_table = 1;
453 static void vl_api_create_vlan_subif_reply_t_handler_json
454 (vl_api_create_vlan_subif_reply_t * mp)
456 vat_main_t * vam = &vat_main;
457 vat_json_node_t node;
459 vat_json_init_object(&node);
460 vat_json_object_add_int(&node, "retval", ntohl(mp->retval));
461 vat_json_object_add_uint(&node, "sw_if_index", ntohl(mp->sw_if_index));
463 vat_json_print(vam->ofp, &node);
464 vat_json_free(&node);
466 vam->retval = ntohl(mp->retval);
467 vam->result_ready = 1;
470 static void vl_api_create_subif_reply_t_handler
471 (vl_api_create_subif_reply_t * mp)
473 vat_main_t * vam = &vat_main;
474 i32 retval = ntohl(mp->retval);
476 vam->retval = retval;
477 vam->result_ready = 1;
478 vam->regenerate_interface_table = 1;
481 static void vl_api_create_subif_reply_t_handler_json
482 (vl_api_create_subif_reply_t * mp)
484 vat_main_t * vam = &vat_main;
485 vat_json_node_t node;
487 vat_json_init_object(&node);
488 vat_json_object_add_int(&node, "retval", ntohl(mp->retval));
489 vat_json_object_add_uint(&node, "sw_if_index", ntohl(mp->sw_if_index));
491 vat_json_print(vam->ofp, &node);
492 vat_json_free(&node);
494 vam->retval = ntohl(mp->retval);
495 vam->result_ready = 1;
498 static void vl_api_interface_name_renumber_reply_t_handler
499 (vl_api_interface_name_renumber_reply_t * mp)
501 vat_main_t * vam = &vat_main;
502 i32 retval = ntohl(mp->retval);
504 vam->retval = retval;
505 vam->result_ready = 1;
506 vam->regenerate_interface_table = 1;
509 static void vl_api_interface_name_renumber_reply_t_handler_json
510 (vl_api_interface_name_renumber_reply_t * mp)
512 vat_main_t * vam = &vat_main;
513 vat_json_node_t node;
515 vat_json_init_object(&node);
516 vat_json_object_add_int(&node, "retval", ntohl(mp->retval));
518 vat_json_print(vam->ofp, &node);
519 vat_json_free(&node);
521 vam->retval = ntohl(mp->retval);
522 vam->result_ready = 1;
526 * Special-case: build the interface table, maintain
527 * the next loopback sw_if_index vbl.
529 static void vl_api_sw_interface_details_t_handler
530 (vl_api_sw_interface_details_t * mp)
532 vat_main_t * vam = &vat_main;
533 u8 * s = format (0, "%s%c", mp->interface_name, 0);
535 hash_set_mem (vam->sw_if_index_by_interface_name, s,
536 ntohl(mp->sw_if_index));
538 /* In sub interface case, fill the sub interface table entry */
539 if (mp->sw_if_index != mp->sup_sw_if_index) {
540 sw_interface_subif_t * sub = NULL;
542 vec_add2(vam->sw_if_subif_table, sub, 1);
544 vec_validate(sub->interface_name, strlen((char *)s) + 1);
545 strncpy((char *)sub->interface_name, (char *)s,
546 vec_len(sub->interface_name));
547 sub->sw_if_index = ntohl(mp->sw_if_index);
548 sub->sub_id = ntohl(mp->sub_id);
550 sub->sub_dot1ad = mp->sub_dot1ad;
551 sub->sub_number_of_tags = mp->sub_number_of_tags;
552 sub->sub_outer_vlan_id = ntohs(mp->sub_outer_vlan_id);
553 sub->sub_inner_vlan_id = ntohs(mp->sub_inner_vlan_id);
554 sub->sub_exact_match = mp->sub_exact_match;
555 sub->sub_default = mp->sub_default;
556 sub->sub_outer_vlan_id_any = mp->sub_outer_vlan_id_any;
557 sub->sub_inner_vlan_id_any = mp->sub_inner_vlan_id_any;
559 /* vlan tag rewrite */
560 sub->vtr_op = ntohl(mp->vtr_op);
561 sub->vtr_push_dot1q = ntohl(mp->vtr_push_dot1q);
562 sub->vtr_tag1 = ntohl(mp->vtr_tag1);
563 sub->vtr_tag2 = ntohl(mp->vtr_tag2);
567 static void vl_api_sw_interface_details_t_handler_json
568 (vl_api_sw_interface_details_t * mp)
570 vat_main_t * vam = &vat_main;
571 vat_json_node_t *node = NULL;
573 if (VAT_JSON_ARRAY != vam->json_tree.type) {
574 ASSERT(VAT_JSON_NONE == vam->json_tree.type);
575 vat_json_init_array(&vam->json_tree);
577 node = vat_json_array_add(&vam->json_tree);
579 vat_json_init_object(node);
580 vat_json_object_add_uint(node, "sw_if_index", ntohl(mp->sw_if_index));
581 vat_json_object_add_uint(node, "sup_sw_if_index", ntohl(mp->sup_sw_if_index));
582 vat_json_object_add_uint(node, "l2_address_length", ntohl(mp->l2_address_length));
583 vat_json_object_add_bytes(node, "l2_address", mp->l2_address, sizeof(mp->l2_address));
584 vat_json_object_add_string_copy(node, "interface_name", mp->interface_name);
585 vat_json_object_add_uint(node, "admin_up_down", mp->admin_up_down);
586 vat_json_object_add_uint(node, "link_up_down", mp->link_up_down);
587 vat_json_object_add_uint(node, "link_duplex", mp->link_duplex);
588 vat_json_object_add_uint(node, "link_speed", mp->link_speed);
589 vat_json_object_add_uint(node, "sub_id", ntohl(mp->sub_id));
590 vat_json_object_add_uint(node, "sub_dot1ad", mp->sub_dot1ad);
591 vat_json_object_add_uint(node, "sub_number_of_tags", mp->sub_number_of_tags);
592 vat_json_object_add_uint(node, "sub_outer_vlan_id", ntohs(mp->sub_outer_vlan_id));
593 vat_json_object_add_uint(node, "sub_inner_vlan_id", ntohs(mp->sub_inner_vlan_id));
594 vat_json_object_add_uint(node, "sub_exact_match", mp->sub_exact_match);
595 vat_json_object_add_uint(node, "sub_default", mp->sub_default);
596 vat_json_object_add_uint(node, "sub_outer_vlan_id_any", mp->sub_outer_vlan_id_any);
597 vat_json_object_add_uint(node, "sub_inner_vlan_id_any", mp->sub_inner_vlan_id_any);
598 vat_json_object_add_uint(node, "vtr_op", ntohl(mp->vtr_op));
599 vat_json_object_add_uint(node, "vtr_push_dot1q", ntohl(mp->vtr_push_dot1q));
600 vat_json_object_add_uint(node, "vtr_tag1", ntohl(mp->vtr_tag1));
601 vat_json_object_add_uint(node, "vtr_tag2", ntohl(mp->vtr_tag2));
604 static void vl_api_sw_interface_set_flags_t_handler
605 (vl_api_sw_interface_set_flags_t * mp)
607 vat_main_t * vam = &vat_main;
608 if (vam->interface_event_display)
609 errmsg ("interface flags: sw_if_index %d %s %s\n",
610 ntohl(mp->sw_if_index),
611 mp->admin_up_down ? "admin-up" : "admin-down",
612 mp->link_up_down ? "link-up" : "link-down");
615 static void vl_api_sw_interface_set_flags_t_handler_json
616 (vl_api_sw_interface_set_flags_t * mp)
618 /* JSON output not supported */
621 static void vl_api_cli_reply_t_handler
622 (vl_api_cli_reply_t * mp)
624 vat_main_t * vam = &vat_main;
625 i32 retval = ntohl(mp->retval);
627 vam->retval = retval;
628 vam->shmem_result = (u8 *) mp->reply_in_shmem;
629 vam->result_ready = 1;
632 static void vl_api_cli_reply_t_handler_json
633 (vl_api_cli_reply_t * mp)
635 vat_main_t * vam = &vat_main;
636 vat_json_node_t node;
638 vat_json_init_object(&node);
639 vat_json_object_add_int(&node, "retval", ntohl(mp->retval));
640 vat_json_object_add_uint(&node, "reply_in_shmem", ntohl(mp->reply_in_shmem));
642 vat_json_print(vam->ofp, &node);
643 vat_json_free(&node);
645 vam->retval = ntohl(mp->retval);
646 vam->result_ready = 1;
649 static void vl_api_classify_add_del_table_reply_t_handler
650 (vl_api_classify_add_del_table_reply_t * mp)
652 vat_main_t * vam = &vat_main;
653 i32 retval = ntohl(mp->retval);
654 if (vam->async_mode) {
655 vam->async_errors += (retval < 0);
657 vam->retval = retval;
658 vam->result_ready = 1;
660 ((mp->new_table_index != 0xFFFFFFFF) ||
661 (mp->skip_n_vectors != 0xFFFFFFFF) ||
662 (mp->match_n_vectors != 0xFFFFFFFF)))
664 * Note: this is just barely thread-safe, depends on
665 * the main thread spinning waiting for an answer...
667 errmsg ("new index %d, skip_n_vectors %d, match_n_vectors %d\n",
668 ntohl(mp->new_table_index),
669 ntohl(mp->skip_n_vectors), ntohl(mp->match_n_vectors));
673 static void vl_api_classify_add_del_table_reply_t_handler_json
674 (vl_api_classify_add_del_table_reply_t * mp)
676 vat_main_t * vam = &vat_main;
677 vat_json_node_t node;
679 vat_json_init_object(&node);
680 vat_json_object_add_int(&node, "retval", ntohl(mp->retval));
681 vat_json_object_add_uint(&node, "new_table_index", ntohl(mp->new_table_index));
682 vat_json_object_add_uint(&node, "skip_n_vectors", ntohl(mp->skip_n_vectors));
683 vat_json_object_add_uint(&node, "match_n_vectors", ntohl(mp->match_n_vectors));
685 vat_json_print(vam->ofp, &node);
686 vat_json_free(&node);
688 vam->retval = ntohl(mp->retval);
689 vam->result_ready = 1;
692 static void vl_api_get_node_index_reply_t_handler
693 (vl_api_get_node_index_reply_t * mp)
695 vat_main_t * vam = &vat_main;
696 i32 retval = ntohl(mp->retval);
697 if (vam->async_mode) {
698 vam->async_errors += (retval < 0);
700 vam->retval = retval;
701 vam->result_ready = 1;
703 errmsg ("node index %d\n", ntohl(mp->node_index));
707 static void vl_api_get_node_index_reply_t_handler_json
708 (vl_api_get_node_index_reply_t * mp)
710 vat_main_t * vam = &vat_main;
711 vat_json_node_t node;
713 vat_json_init_object(&node);
714 vat_json_object_add_int(&node, "retval", ntohl(mp->retval));
715 vat_json_object_add_uint(&node, "node_index", ntohl(mp->node_index));
717 vat_json_print(vam->ofp, &node);
718 vat_json_free(&node);
720 vam->retval = ntohl(mp->retval);
721 vam->result_ready = 1;
724 static void vl_api_add_node_next_reply_t_handler
725 (vl_api_add_node_next_reply_t * mp)
727 vat_main_t * vam = &vat_main;
728 i32 retval = ntohl(mp->retval);
729 if (vam->async_mode) {
730 vam->async_errors += (retval < 0);
732 vam->retval = retval;
733 vam->result_ready = 1;
735 errmsg ("next index %d\n", ntohl(mp->next_index));
739 static void vl_api_add_node_next_reply_t_handler_json
740 (vl_api_add_node_next_reply_t * mp)
742 vat_main_t * vam = &vat_main;
743 vat_json_node_t node;
745 vat_json_init_object(&node);
746 vat_json_object_add_int(&node, "retval", ntohl(mp->retval));
747 vat_json_object_add_uint(&node, "next_index", ntohl(mp->next_index));
749 vat_json_print(vam->ofp, &node);
750 vat_json_free(&node);
752 vam->retval = ntohl(mp->retval);
753 vam->result_ready = 1;
756 static void vl_api_mpls_gre_add_del_tunnel_reply_t_handler
757 (vl_api_mpls_gre_add_del_tunnel_reply_t * mp)
759 vat_main_t * vam = &vat_main;
760 i32 retval = ntohl(mp->retval);
761 u32 sw_if_index = ntohl(mp->tunnel_sw_if_index);
763 if (retval >= 0 && sw_if_index != (u32)~0) {
764 errmsg ("tunnel_sw_if_index %d\n", sw_if_index);
766 vam->retval = retval;
767 vam->result_ready = 1;
770 static void vl_api_mpls_gre_add_del_tunnel_reply_t_handler_json
771 (vl_api_mpls_gre_add_del_tunnel_reply_t * mp)
773 vat_main_t * vam = &vat_main;
774 vat_json_node_t node;
776 vat_json_init_object(&node);
777 vat_json_object_add_int(&node, "retval", ntohl(mp->retval));
778 vat_json_object_add_uint(&node, "tunnel_sw_if_index", ntohl(mp->tunnel_sw_if_index));
780 vat_json_print(vam->ofp, &node);
781 vat_json_free(&node);
783 vam->retval = ntohl(mp->retval);
784 vam->result_ready = 1;
787 static void vl_api_nsh_gre_add_del_tunnel_reply_t_handler
788 (vl_api_nsh_gre_add_del_tunnel_reply_t * mp)
790 vat_main_t * vam = &vat_main;
791 i32 retval = ntohl(mp->retval);
792 u32 sw_if_index = ntohl(mp->sw_if_index);
794 if (retval >= 0 && sw_if_index != (u32)~0) {
795 errmsg ("sw_if_index %d\n", ntohl(mp->sw_if_index));
797 vam->retval = retval;
798 vam->result_ready = 1;
801 static void vl_api_nsh_gre_add_del_tunnel_reply_t_handler_json
802 (vl_api_nsh_gre_add_del_tunnel_reply_t * mp)
804 vat_main_t * vam = &vat_main;
805 vat_json_node_t node;
807 vat_json_init_object(&node);
808 vat_json_object_add_int(&node, "retval", ntohl(mp->retval));
809 vat_json_object_add_uint(&node, "sw_if_index", ntohl(mp->sw_if_index));
811 vat_json_print(vam->ofp, &node);
812 vat_json_free(&node);
814 vam->retval = ntohl(mp->retval);
815 vam->result_ready = 1;
818 static void vl_api_nsh_vxlan_gpe_add_del_tunnel_reply_t_handler
819 (vl_api_nsh_vxlan_gpe_add_del_tunnel_reply_t * mp)
821 vat_main_t * vam = &vat_main;
822 i32 retval = ntohl(mp->retval);
823 u32 sw_if_index = ntohl(mp->sw_if_index);
825 if (retval >= 0 && sw_if_index != (u32)~0) {
826 errmsg ("sw_if_index %d\n", ntohl(mp->sw_if_index));
828 vam->retval = retval;
829 vam->result_ready = 1;
832 static void vl_api_nsh_vxlan_gpe_add_del_tunnel_reply_t_handler_json
833 (vl_api_nsh_vxlan_gpe_add_del_tunnel_reply_t * mp)
835 vat_main_t * vam = &vat_main;
836 vat_json_node_t node;
838 vat_json_init_object(&node);
839 vat_json_object_add_int(&node, "retval", ntohl(mp->retval));
840 vat_json_object_add_uint(&node, "sw_if_index", ntohl(mp->sw_if_index));
842 vat_json_print(vam->ofp, &node);
843 vat_json_free(&node);
845 vam->retval = ntohl(mp->retval);
846 vam->result_ready = 1;
849 static void vl_api_lisp_gpe_add_del_tunnel_reply_t_handler
850 (vl_api_lisp_gpe_add_del_tunnel_reply_t * mp)
852 vat_main_t * vam = &vat_main;
853 i32 retval = ntohl(mp->retval);
854 u32 sw_if_index = ntohl(mp->sw_if_index);
856 if (retval >= 0 && sw_if_index != (u32)~0) {
857 errmsg ("sw_if_index %d\n", ntohl(mp->sw_if_index));
859 vam->retval = retval;
860 vam->result_ready = 1;
863 static void vl_api_lisp_gpe_add_del_tunnel_reply_t_handler_json
864 (vl_api_lisp_gpe_add_del_tunnel_reply_t * mp)
866 vat_main_t * vam = &vat_main;
867 vat_json_node_t node;
869 vat_json_init_object(&node);
870 vat_json_object_add_int(&node, "retval", ntohl(mp->retval));
871 vat_json_object_add_uint(&node, "sw_if_index", ntohl(mp->sw_if_index));
873 vat_json_print(vam->ofp, &node);
874 vat_json_free(&node);
876 vam->retval = ntohl(mp->retval);
877 vam->result_ready = 1;
880 static void vl_api_show_version_reply_t_handler
881 (vl_api_show_version_reply_t * mp)
883 vat_main_t * vam = &vat_main;
884 i32 retval = ntohl(mp->retval);
887 errmsg (" program: %s\n", mp->program);
888 errmsg (" version: %s\n", mp->version);
889 errmsg (" build date: %s\n", mp->build_date);
890 errmsg ("build directory: %s\n", mp->build_directory);
892 vam->retval = retval;
893 vam->result_ready = 1;
896 static void vl_api_show_version_reply_t_handler_json
897 (vl_api_show_version_reply_t * mp)
899 vat_main_t * vam = &vat_main;
900 vat_json_node_t node;
902 vat_json_init_object(&node);
903 vat_json_object_add_int(&node, "retval", ntohl(mp->retval));
904 vat_json_object_add_string_copy(&node, "program", mp->program);
905 vat_json_object_add_string_copy(&node, "version", mp->version);
906 vat_json_object_add_string_copy(&node, "build_date", mp->build_date);
907 vat_json_object_add_string_copy(&node, "build_directory", mp->build_directory);
909 vat_json_print(vam->ofp, &node);
910 vat_json_free(&node);
912 vam->retval = ntohl(mp->retval);
913 vam->result_ready = 1;
916 static void vl_api_ip4_arp_event_t_handler
917 (vl_api_ip4_arp_event_t * mp)
919 vat_main_t * vam = &vat_main;
920 errmsg ("arp event: address %U new mac %U sw_if_index %d\n",
921 format_ip4_address, &mp->address,
922 format_ethernet_address, mp->new_mac, mp->sw_if_index);
925 static void vl_api_ip4_arp_event_t_handler_json
926 (vl_api_ip4_arp_event_t * mp)
928 /* JSON output not supported */
932 * Special-case: build the bridge domain table, maintain
933 * the next bd id vbl.
935 static void vl_api_bridge_domain_details_t_handler
936 (vl_api_bridge_domain_details_t * mp)
938 vat_main_t * vam = &vat_main;
939 u32 n_sw_ifs = ntohl (mp->n_sw_ifs);
941 fformat (vam->ofp, "\n%-3s %-3s %-3s %-3s %-3s %-3s\n",
942 " ID", "LRN", "FWD", "FLD", "BVI", "#IF");
944 fformat (vam->ofp, "%3d %3d %3d %3d %3d %3d\n",
945 ntohl (mp->bd_id), mp->learn, mp->forward,
946 mp->flood, ntohl (mp->bvi_sw_if_index), n_sw_ifs);
949 fformat (vam->ofp, "\n\n%s %s %s\n", "sw_if_index", "SHG",
953 static void vl_api_bridge_domain_details_t_handler_json
954 (vl_api_bridge_domain_details_t * mp)
956 vat_main_t * vam = &vat_main;
957 vat_json_node_t *node, *array = NULL;
959 if (VAT_JSON_ARRAY != vam->json_tree.type) {
960 ASSERT(VAT_JSON_NONE == vam->json_tree.type);
961 vat_json_init_array(&vam->json_tree);
963 node = vat_json_array_add(&vam->json_tree);
965 vat_json_init_object(node);
966 vat_json_object_add_uint(node, "bd_id", ntohl(mp->bd_id));
967 vat_json_object_add_uint(node, "flood", mp->flood);
968 vat_json_object_add_uint(node, "forward", mp->forward);
969 vat_json_object_add_uint(node, "learn", mp->learn);
970 vat_json_object_add_uint(node, "bvi_sw_if_index", ntohl(mp->bvi_sw_if_index));
971 vat_json_object_add_uint(node, "n_sw_ifs", ntohl(mp->n_sw_ifs));
972 array = vat_json_object_add(node, "sw_if");
973 vat_json_init_array(array);
977 * Special-case: build the bridge domain sw if table.
979 static void vl_api_bridge_domain_sw_if_details_t_handler
980 (vl_api_bridge_domain_sw_if_details_t * mp)
982 vat_main_t * vam = &vat_main;
987 sw_if_index = ntohl (mp->sw_if_index);
988 hash_foreach_pair (p, vam->sw_if_index_by_interface_name,
990 if ((u32) p->value[0] == sw_if_index) {
991 sw_if_name = (u8 *)(p->key);
996 fformat (vam->ofp, "%7d %3d %s", sw_if_index,
997 mp->shg, sw_if_name ? (char *)sw_if_name :
998 "sw_if_index not found!");
1001 static void vl_api_bridge_domain_sw_if_details_t_handler_json
1002 (vl_api_bridge_domain_sw_if_details_t * mp)
1004 vat_main_t * vam = &vat_main;
1005 vat_json_node_t *node = NULL;
1006 uword last_index = 0;
1008 ASSERT(VAT_JSON_ARRAY == vam->json_tree.type);
1009 ASSERT(vec_len(vam->json_tree.array) >= 1);
1010 last_index = vec_len(vam->json_tree.array) - 1;
1011 node = &vam->json_tree.array[last_index];
1012 node = vat_json_object_get_element(node, "sw_if");
1013 ASSERT(NULL != node);
1014 node = vat_json_array_add(node);
1016 vat_json_init_object(node);
1017 vat_json_object_add_uint(node, "bd_id", ntohl(mp->bd_id));
1018 vat_json_object_add_uint(node, "sw_if_index", ntohl(mp->sw_if_index));
1019 vat_json_object_add_uint(node, "shg", mp->shg);
1022 static void vl_api_control_ping_reply_t_handler
1023 (vl_api_control_ping_reply_t * mp)
1025 vat_main_t * vam = &vat_main;
1026 i32 retval = ntohl(mp->retval);
1027 if (vam->async_mode) {
1028 vam->async_errors += (retval < 0);
1030 vam->retval = retval;
1031 vam->result_ready = 1;
1035 static void vl_api_control_ping_reply_t_handler_json
1036 (vl_api_control_ping_reply_t * mp)
1038 vat_main_t * vam = &vat_main;
1039 i32 retval = ntohl(mp->retval);
1041 if (VAT_JSON_NONE != vam->json_tree.type) {
1042 vat_json_print(vam->ofp, &vam->json_tree);
1043 vat_json_free(&vam->json_tree);
1044 vam->json_tree.type = VAT_JSON_NONE;
1047 vat_json_init_array(&vam->json_tree);
1048 vat_json_print(vam->ofp, &vam->json_tree);
1049 vam->json_tree.type = VAT_JSON_NONE;
1052 vam->retval = retval;
1053 vam->result_ready = 1;
1056 static void vl_api_l2_flags_reply_t_handler
1057 (vl_api_l2_flags_reply_t * mp)
1059 vat_main_t * vam = &vat_main;
1060 i32 retval = ntohl(mp->retval);
1061 if (vam->async_mode) {
1062 vam->async_errors += (retval < 0);
1064 vam->retval = retval;
1065 vam->result_ready = 1;
1069 static void vl_api_l2_flags_reply_t_handler_json
1070 (vl_api_l2_flags_reply_t * mp)
1072 vat_main_t * vam = &vat_main;
1073 vat_json_node_t node;
1075 vat_json_init_object(&node);
1076 vat_json_object_add_int(&node, "retval", ntohl(mp->retval));
1077 vat_json_object_add_uint(&node, "resulting_feature_bitmap", ntohl(mp->resulting_feature_bitmap));
1079 vat_json_print(vam->ofp, &node);
1080 vat_json_free(&node);
1082 vam->retval = ntohl(mp->retval);
1083 vam->result_ready = 1;
1086 static void vl_api_bridge_flags_reply_t_handler
1087 (vl_api_bridge_flags_reply_t * mp)
1089 vat_main_t * vam = &vat_main;
1090 i32 retval = ntohl(mp->retval);
1091 if (vam->async_mode) {
1092 vam->async_errors += (retval < 0);
1094 vam->retval = retval;
1095 vam->result_ready = 1;
1099 static void vl_api_bridge_flags_reply_t_handler_json
1100 (vl_api_bridge_flags_reply_t * mp)
1102 vat_main_t * vam = &vat_main;
1103 vat_json_node_t node;
1105 vat_json_init_object(&node);
1106 vat_json_object_add_int(&node, "retval", ntohl(mp->retval));
1107 vat_json_object_add_uint(&node, "resulting_feature_bitmap", ntohl(mp->resulting_feature_bitmap));
1109 vat_json_print(vam->ofp, &node);
1110 vat_json_free(&node);
1112 vam->retval = ntohl(mp->retval);
1113 vam->result_ready = 1;
1116 static void vl_api_tap_connect_reply_t_handler
1117 (vl_api_tap_connect_reply_t * mp)
1119 vat_main_t * vam = &vat_main;
1120 i32 retval = ntohl(mp->retval);
1121 if (vam->async_mode) {
1122 vam->async_errors += (retval < 0);
1124 vam->retval = retval;
1125 vam->result_ready = 1;
1129 static void vl_api_tap_connect_reply_t_handler_json
1130 (vl_api_tap_connect_reply_t * mp)
1132 vat_main_t * vam = &vat_main;
1133 vat_json_node_t node;
1135 vat_json_init_object(&node);
1136 vat_json_object_add_int(&node, "retval", ntohl(mp->retval));
1137 vat_json_object_add_uint(&node, "sw_if_index", ntohl(mp->sw_if_index));
1139 vat_json_print(vam->ofp, &node);
1140 vat_json_free(&node);
1142 vam->retval = ntohl(mp->retval);
1143 vam->result_ready = 1;
1146 static void vl_api_tap_modify_reply_t_handler
1147 (vl_api_tap_modify_reply_t * mp)
1149 vat_main_t * vam = &vat_main;
1150 i32 retval = ntohl(mp->retval);
1151 if (vam->async_mode) {
1152 vam->async_errors += (retval < 0);
1154 vam->retval = retval;
1155 vam->result_ready = 1;
1159 static void vl_api_tap_modify_reply_t_handler_json
1160 (vl_api_tap_modify_reply_t * mp)
1162 vat_main_t * vam = &vat_main;
1163 vat_json_node_t node;
1165 vat_json_init_object(&node);
1166 vat_json_object_add_int(&node, "retval", ntohl(mp->retval));
1167 vat_json_object_add_uint(&node, "sw_if_index", ntohl(mp->sw_if_index));
1169 vat_json_print(vam->ofp, &node);
1170 vat_json_free(&node);
1172 vam->retval = ntohl(mp->retval);
1173 vam->result_ready = 1;
1176 static void vl_api_tap_delete_reply_t_handler
1177 (vl_api_tap_delete_reply_t * mp)
1179 vat_main_t * vam = &vat_main;
1180 i32 retval = ntohl(mp->retval);
1181 if (vam->async_mode) {
1182 vam->async_errors += (retval < 0);
1184 vam->retval = retval;
1185 vam->result_ready = 1;
1189 static void vl_api_tap_delete_reply_t_handler_json
1190 (vl_api_tap_delete_reply_t * mp)
1192 vat_main_t * vam = &vat_main;
1193 vat_json_node_t node;
1195 vat_json_init_object(&node);
1196 vat_json_object_add_int(&node, "retval", ntohl(mp->retval));
1198 vat_json_print(vam->ofp, &node);
1199 vat_json_free(&node);
1201 vam->retval = ntohl(mp->retval);
1202 vam->result_ready = 1;
1205 static void vl_api_mpls_ethernet_add_del_tunnel_reply_t_handler
1206 (vl_api_mpls_ethernet_add_del_tunnel_reply_t * mp)
1208 vat_main_t * vam = &vat_main;
1209 i32 retval = ntohl(mp->retval);
1210 if (vam->async_mode) {
1211 vam->async_errors += (retval < 0);
1213 vam->retval = retval;
1214 vam->result_ready = 1;
1218 static void vl_api_mpls_ethernet_add_del_tunnel_reply_t_handler_json
1219 (vl_api_mpls_ethernet_add_del_tunnel_reply_t * mp)
1221 vat_main_t * vam = &vat_main;
1222 vat_json_node_t node;
1224 vat_json_init_object(&node);
1225 vat_json_object_add_int(&node, "retval", ntohl(mp->retval));
1226 vat_json_object_add_uint(&node, "tunnel_sw_if_index", ntohl(mp->tunnel_sw_if_index));
1228 vat_json_print(vam->ofp, &node);
1229 vat_json_free(&node);
1231 vam->retval = ntohl(mp->retval);
1232 vam->result_ready = 1;
1235 static void vl_api_l2tpv3_create_tunnel_reply_t_handler
1236 (vl_api_l2tpv3_create_tunnel_reply_t * mp)
1238 vat_main_t * vam = &vat_main;
1239 i32 retval = ntohl(mp->retval);
1240 if (vam->async_mode) {
1241 vam->async_errors += (retval < 0);
1243 vam->retval = retval;
1244 vam->result_ready = 1;
1248 static void vl_api_l2tpv3_create_tunnel_reply_t_handler_json
1249 (vl_api_l2tpv3_create_tunnel_reply_t * mp)
1251 vat_main_t * vam = &vat_main;
1252 vat_json_node_t node;
1254 vat_json_init_object(&node);
1255 vat_json_object_add_int(&node, "retval", ntohl(mp->retval));
1256 vat_json_object_add_uint(&node, "sw_if_index", ntohl(mp->sw_if_index));
1258 vat_json_print(vam->ofp, &node);
1259 vat_json_free(&node);
1261 vam->retval = ntohl(mp->retval);
1262 vam->result_ready = 1;
1265 static void vl_api_vxlan_add_del_tunnel_reply_t_handler
1266 (vl_api_vxlan_add_del_tunnel_reply_t * mp)
1268 vat_main_t * vam = &vat_main;
1269 i32 retval = ntohl(mp->retval);
1270 if (vam->async_mode) {
1271 vam->async_errors += (retval < 0);
1273 vam->retval = retval;
1274 vam->result_ready = 1;
1278 static void vl_api_vxlan_add_del_tunnel_reply_t_handler_json
1279 (vl_api_vxlan_add_del_tunnel_reply_t * mp)
1281 vat_main_t * vam = &vat_main;
1282 vat_json_node_t node;
1284 vat_json_init_object(&node);
1285 vat_json_object_add_int(&node, "retval", ntohl(mp->retval));
1286 vat_json_object_add_uint(&node, "sw_if_index", ntohl(mp->sw_if_index));
1288 vat_json_print(vam->ofp, &node);
1289 vat_json_free(&node);
1291 vam->retval = ntohl(mp->retval);
1292 vam->result_ready = 1;
1295 static void vl_api_create_vhost_user_if_reply_t_handler
1296 (vl_api_create_vhost_user_if_reply_t * mp)
1298 vat_main_t * vam = &vat_main;
1299 i32 retval = ntohl(mp->retval);
1300 if (vam->async_mode) {
1301 vam->async_errors += (retval < 0);
1303 vam->retval = retval;
1304 vam->result_ready = 1;
1308 static void vl_api_create_vhost_user_if_reply_t_handler_json
1309 (vl_api_create_vhost_user_if_reply_t * mp)
1311 vat_main_t * vam = &vat_main;
1312 vat_json_node_t node;
1314 vat_json_init_object(&node);
1315 vat_json_object_add_int(&node, "retval", ntohl(mp->retval));
1316 vat_json_object_add_uint(&node, "sw_if_index", ntohl(mp->sw_if_index));
1318 vat_json_print(vam->ofp, &node);
1319 vat_json_free(&node);
1321 vam->retval = ntohl(mp->retval);
1322 vam->result_ready = 1;
1325 static void vl_api_ip_address_details_t_handler
1326 (vl_api_ip_address_details_t * mp)
1328 vat_main_t * vam = &vat_main;
1329 static ip_address_details_t empty_ip_address_details = {{0}};
1330 ip_address_details_t * address = NULL;
1331 ip_details_t * current_ip_details = NULL;
1332 ip_details_t * details = NULL;
1334 details = vam->ip_details_by_sw_if_index[vam->is_ipv6];
1336 if (!details || vam->current_sw_if_index >= vec_len(details)
1337 || !details[vam->current_sw_if_index].present) {
1338 errmsg ("ip address details arrived but not stored\n");
1339 errmsg ("ip_dump should be called first\n");
1343 current_ip_details = vec_elt_at_index(details,
1344 vam->current_sw_if_index);
1346 #define addresses (current_ip_details->addr)
1348 vec_validate_init_empty(addresses, vec_len(addresses),
1349 empty_ip_address_details);
1351 address = vec_elt_at_index(addresses, vec_len(addresses) - 1);
1353 memcpy(&address->ip, &mp->ip, sizeof(address->ip));
1354 address->prefix_length = mp->prefix_length;
1358 static void vl_api_ip_address_details_t_handler_json
1359 (vl_api_ip_address_details_t * mp)
1361 vat_main_t * vam = &vat_main;
1362 vat_json_node_t *node = NULL;
1363 struct in6_addr ip6;
1366 if (VAT_JSON_ARRAY != vam->json_tree.type) {
1367 ASSERT(VAT_JSON_NONE == vam->json_tree.type);
1368 vat_json_init_array(&vam->json_tree);
1370 node = vat_json_array_add(&vam->json_tree);
1372 vat_json_init_object(node);
1374 memcpy(&ip6, mp->ip, sizeof(ip6));
1375 vat_json_object_add_ip6(node, "ip", ip6);
1377 memcpy(&ip4, mp->ip, sizeof(ip4));
1378 vat_json_object_add_ip4(node, "ip", ip4);
1380 vat_json_object_add_uint(node, "prefix_length", mp->prefix_length);
1383 static void vl_api_ip_details_t_handler (vl_api_ip_details_t * mp)
1385 vat_main_t * vam = &vat_main;
1386 static ip_details_t empty_ip_details = {0};
1387 ip_details_t * ip = NULL;
1388 u32 sw_if_index = ~0;
1390 sw_if_index = ntohl(mp->sw_if_index);
1392 vec_validate_init_empty(vam->ip_details_by_sw_if_index[vam->is_ipv6],
1393 sw_if_index, empty_ip_details);
1395 ip = vec_elt_at_index(vam->ip_details_by_sw_if_index[vam->is_ipv6],
1401 static void vl_api_ip_details_t_handler_json (vl_api_ip_details_t * mp)
1403 vat_main_t * vam = &vat_main;
1405 if (VAT_JSON_ARRAY != vam->json_tree.type) {
1406 ASSERT(VAT_JSON_NONE == vam->json_tree.type);
1407 vat_json_init_array(&vam->json_tree);
1409 vat_json_array_add_uint(&vam->json_tree, clib_net_to_host_u32(mp->sw_if_index));
1412 static void vl_api_map_domain_details_t_handler_json
1413 (vl_api_map_domain_details_t * mp)
1415 vat_json_node_t * node = NULL;
1416 vat_main_t * vam = &vat_main;
1417 struct in6_addr ip6;
1420 if (VAT_JSON_ARRAY != vam->json_tree.type) {
1421 ASSERT(VAT_JSON_NONE == vam->json_tree.type);
1422 vat_json_init_array(&vam->json_tree);
1425 node = vat_json_array_add(&vam->json_tree);
1426 vat_json_init_object(node);
1428 vat_json_object_add_uint(node, "domain_index", clib_net_to_host_u32(mp->domain_index));
1429 memcpy(&ip6, mp->ip6_prefix, sizeof(ip6));
1430 vat_json_object_add_ip6(node, "ip6_prefix", ip6);
1431 memcpy(&ip4, mp->ip4_prefix, sizeof(ip4));
1432 vat_json_object_add_ip4(node, "ip4_prefix", ip4);
1433 memcpy(&ip6, mp->ip6_src, sizeof(ip6));
1434 vat_json_object_add_ip6(node, "ip6_src", ip6);
1435 vat_json_object_add_int(node, "ip6_prefix_len", mp->ip6_prefix_len);
1436 vat_json_object_add_int(node, "ip4_prefix_len", mp->ip4_prefix_len);
1437 vat_json_object_add_int(node, "ip6_src_len", mp->ip6_src_len);
1438 vat_json_object_add_int(node, "ea_bits_len", mp->ea_bits_len);
1439 vat_json_object_add_int(node, "psid_offset", mp->psid_offset);
1440 vat_json_object_add_int(node, "psid_length", mp->psid_length);
1441 vat_json_object_add_uint(node, "flags", mp->flags);
1442 vat_json_object_add_uint(node, "mtu", clib_net_to_host_u16(mp->mtu));
1443 vat_json_object_add_int(node, "is_translation", mp->is_translation);
1446 static void vl_api_map_domain_details_t_handler
1447 (vl_api_map_domain_details_t * mp)
1449 vat_main_t * vam = &vat_main;
1451 if (mp->is_translation) {
1452 fformat(vam->ofp, "* %U/%d (ipv4-prefix) %U/%d (ipv6-prefix) %U/%d (ip6-src) index: %u\n",
1453 format_ip4_address, mp->ip4_prefix, mp->ip4_prefix_len,
1454 format_ip6_address, mp->ip6_prefix, mp->ip6_prefix_len,
1455 format_ip6_address, mp->ip6_src, mp->ip6_src_len, clib_net_to_host_u32(mp->domain_index));
1457 fformat(vam->ofp, "* %U/%d (ipv4-prefix) %U/%d (ipv6-prefix) %U (ip6-src) index: %u\n",
1458 format_ip4_address, mp->ip4_prefix, mp->ip4_prefix_len,
1459 format_ip6_address, mp->ip6_prefix, mp->ip6_prefix_len,
1460 format_ip6_address, mp->ip6_src, clib_net_to_host_u32(mp->domain_index));
1462 fformat(vam->ofp, " ea-len %d psid-offset %d psid-len %d mtu %d %s\n",
1463 mp->ea_bits_len, mp->psid_offset, mp->psid_length, mp->mtu, mp->is_translation? "map-t":"");
1466 static void vl_api_map_rule_details_t_handler_json
1467 (vl_api_map_rule_details_t * mp)
1469 struct in6_addr ip6;
1470 vat_json_node_t * node = NULL;
1471 vat_main_t * vam = &vat_main;
1473 if (VAT_JSON_ARRAY != vam->json_tree.type) {
1474 ASSERT(VAT_JSON_NONE == vam->json_tree.type);
1475 vat_json_init_array(&vam->json_tree);
1478 node = vat_json_array_add(&vam->json_tree);
1479 vat_json_init_object(node);
1481 vat_json_object_add_uint(node, "psid", clib_net_to_host_u16(mp->psid));
1482 memcpy(&ip6, mp->ip6_dst, sizeof(ip6));
1483 vat_json_object_add_ip6(node, "ip6_dst", ip6);
1486 static void vl_api_map_rule_details_t_handler
1487 (vl_api_map_rule_details_t * mp)
1489 vat_main_t * vam = &vat_main;
1490 fformat(vam->ofp, " %d (psid) %U (ip6-dst)\n", clib_net_to_host_u16(mp->psid),
1491 format_ip6_address, mp->ip6_dst);
1494 static void vl_api_dhcp_compl_event_t_handler
1495 (vl_api_dhcp_compl_event_t * mp)
1497 vat_main_t * vam = &vat_main;
1498 errmsg ("DHCP compl event: pid %d %s hostname %s host_addr %U "
1499 "router_addr %U host_mac %U\n",
1500 mp->pid, mp->is_ipv6 ? "ipv6":"ipv4", mp->hostname,
1501 format_ip4_address, &mp->host_address,
1502 format_ip4_address, &mp->router_address,
1503 format_ethernet_address, mp->host_mac);
1506 static void vl_api_dhcp_compl_event_t_handler_json
1507 (vl_api_dhcp_compl_event_t * mp)
1509 /* JSON output not supported */
1512 static void set_simple_interface_counter (u8 vnet_counter_type, u32 sw_if_index,
1515 vat_main_t * vam = &vat_main;
1516 static u64 default_counter = 0;
1518 vec_validate_init_empty(vam->simple_interface_counters, vnet_counter_type, NULL);
1519 vec_validate_init_empty(vam->simple_interface_counters[vnet_counter_type],
1520 sw_if_index, default_counter);
1521 vam->simple_interface_counters[vnet_counter_type][sw_if_index] = counter;
1524 static void set_combined_interface_counter (u8 vnet_counter_type, u32 sw_if_index,
1525 interface_counter_t counter)
1527 vat_main_t * vam = &vat_main;
1528 static interface_counter_t default_counter = {0, };
1530 vec_validate_init_empty(vam->combined_interface_counters, vnet_counter_type, NULL);
1531 vec_validate_init_empty(vam->combined_interface_counters[vnet_counter_type],
1532 sw_if_index, default_counter);
1533 vam->combined_interface_counters[vnet_counter_type][sw_if_index] = counter;
1536 static void vl_api_vnet_interface_counters_t_handler
1537 (vl_api_vnet_interface_counters_t *mp)
1542 static void vl_api_vnet_interface_counters_t_handler_json
1543 (vl_api_vnet_interface_counters_t *mp)
1545 interface_counter_t counter;
1550 u32 first_sw_if_index;
1553 count = ntohl(mp->count);
1554 first_sw_if_index = ntohl(mp->first_sw_if_index);
1556 if (!mp->is_combined) {
1557 v_packets = (u64*)&mp->data;
1558 for (i = 0; i < count; i++) {
1559 packets = clib_net_to_host_u64(clib_mem_unaligned(v_packets, u64));
1560 set_simple_interface_counter(mp->vnet_counter_type,
1561 first_sw_if_index + i, packets);
1565 v = (vlib_counter_t*)&mp->data;
1566 for (i = 0; i < count; i++) {
1567 counter.packets = clib_net_to_host_u64(
1568 clib_mem_unaligned(&v->packets, u64));
1569 counter.bytes = clib_net_to_host_u64(
1570 clib_mem_unaligned(&v->bytes, u64));
1571 set_combined_interface_counter(mp->vnet_counter_type,
1572 first_sw_if_index + i, counter);
1578 static u32 ip4_fib_counters_get_vrf_index_by_vrf_id (u32 vrf_id)
1580 vat_main_t * vam = &vat_main;
1583 for (i = 0; i < vec_len(vam->ip4_fib_counters_vrf_id_by_index); i++) {
1584 if (vam->ip4_fib_counters_vrf_id_by_index[i] == vrf_id) {
1591 static u32 ip6_fib_counters_get_vrf_index_by_vrf_id (u32 vrf_id)
1593 vat_main_t * vam = &vat_main;
1596 for (i = 0; i < vec_len(vam->ip6_fib_counters_vrf_id_by_index); i++) {
1597 if (vam->ip6_fib_counters_vrf_id_by_index[i] == vrf_id) {
1604 static void vl_api_vnet_ip4_fib_counters_t_handler
1605 (vl_api_vnet_ip4_fib_counters_t *mp)
1610 static void vl_api_vnet_ip4_fib_counters_t_handler_json
1611 (vl_api_vnet_ip4_fib_counters_t *mp)
1613 vat_main_t * vam = &vat_main;
1614 vl_api_ip4_fib_counter_t *v;
1615 ip4_fib_counter_t *counter;
1622 vrf_id = ntohl(mp->vrf_id);
1623 vrf_index = ip4_fib_counters_get_vrf_index_by_vrf_id(vrf_id);
1624 if (~0 == vrf_index) {
1625 vrf_index = vec_len(vam->ip4_fib_counters_vrf_id_by_index);
1626 vec_validate(vam->ip4_fib_counters_vrf_id_by_index, vrf_index);
1627 vam->ip4_fib_counters_vrf_id_by_index[vrf_index] = vrf_id;
1628 vec_validate(vam->ip4_fib_counters, vrf_index);
1629 vam->ip4_fib_counters[vrf_index] = NULL;
1632 vec_free(vam->ip4_fib_counters[vrf_index]);
1633 v = (vl_api_ip4_fib_counter_t*)&mp->c;
1634 count = ntohl(mp->count);
1635 for (i = 0; i < count; i++) {
1636 vec_validate(vam->ip4_fib_counters[vrf_index], i);
1637 counter = &vam->ip4_fib_counters[vrf_index][i];
1638 memcpy(&ip4, &v->address, sizeof(ip4));
1639 counter->address = ip4;
1640 counter->address_length = v->address_length;
1641 counter->packets = clib_net_to_host_u64(v->packets);
1642 counter->bytes = clib_net_to_host_u64(v->bytes);
1647 static void vl_api_vnet_ip6_fib_counters_t_handler
1648 (vl_api_vnet_ip6_fib_counters_t *mp)
1653 static void vl_api_vnet_ip6_fib_counters_t_handler_json
1654 (vl_api_vnet_ip6_fib_counters_t *mp)
1656 vat_main_t * vam = &vat_main;
1657 vl_api_ip6_fib_counter_t *v;
1658 ip6_fib_counter_t *counter;
1659 struct in6_addr ip6;
1665 vrf_id = ntohl(mp->vrf_id);
1666 vrf_index = ip6_fib_counters_get_vrf_index_by_vrf_id(vrf_id);
1667 if (~0 == vrf_index) {
1668 vrf_index = vec_len(vam->ip6_fib_counters_vrf_id_by_index);
1669 vec_validate(vam->ip6_fib_counters_vrf_id_by_index, vrf_index);
1670 vam->ip6_fib_counters_vrf_id_by_index[vrf_index] = vrf_id;
1671 vec_validate(vam->ip6_fib_counters, vrf_index);
1672 vam->ip6_fib_counters[vrf_index] = NULL;
1675 vec_free(vam->ip6_fib_counters[vrf_index]);
1676 v = (vl_api_ip6_fib_counter_t*)&mp->c;
1677 count = ntohl(mp->count);
1678 for (i = 0; i < count; i++) {
1679 vec_validate(vam->ip6_fib_counters[vrf_index], i);
1680 counter = &vam->ip6_fib_counters[vrf_index][i];
1681 memcpy(&ip6, &v->address, sizeof(ip6));
1682 counter->address = ip6;
1683 counter->address_length = v->address_length;
1684 counter->packets = clib_net_to_host_u64(v->packets);
1685 counter->bytes = clib_net_to_host_u64(v->bytes);
1690 static void vl_api_get_first_msg_id_reply_t_handler
1691 (vl_api_get_first_msg_id_reply_t * mp)
1693 vat_main_t * vam = &vat_main;
1694 i32 retval = ntohl(mp->retval);
1696 if (vam->async_mode) {
1697 vam->async_errors += (retval < 0);
1699 vam->retval = retval;
1700 vam->result_ready = 1;
1703 errmsg ("first message id %d\n", ntohs(mp->first_msg_id));
1707 static void vl_api_get_first_msg_id_reply_t_handler_json
1708 (vl_api_get_first_msg_id_reply_t * mp)
1710 vat_main_t * vam = &vat_main;
1711 vat_json_node_t node;
1713 vat_json_init_object(&node);
1714 vat_json_object_add_int(&node, "retval", ntohl(mp->retval));
1715 vat_json_object_add_uint(&node, "first_msg_id",
1716 (uint) ntohs(mp->first_msg_id));
1718 vat_json_print(vam->ofp, &node);
1719 vat_json_free(&node);
1721 vam->retval = ntohl(mp->retval);
1722 vam->result_ready = 1;
1725 #define vl_api_vnet_ip4_fib_counters_t_endian vl_noop_handler
1726 #define vl_api_vnet_ip4_fib_counters_t_print vl_noop_handler
1727 #define vl_api_vnet_ip6_fib_counters_t_endian vl_noop_handler
1728 #define vl_api_vnet_ip6_fib_counters_t_print vl_noop_handler
1731 * Generate boilerplate reply handlers, which
1732 * dig the return value out of the xxx_reply_t API message,
1733 * stick it into vam->retval, and set vam->result_ready
1735 * Could also do this by pointing N message decode slots at
1736 * a single function, but that could break in subtle ways.
1739 #define foreach_standard_reply_retval_handler \
1740 _(sw_interface_set_flags_reply) \
1741 _(sw_interface_add_del_address_reply) \
1742 _(sw_interface_set_table_reply) \
1743 _(sw_interface_set_vpath_reply) \
1744 _(sw_interface_set_l2_bridge_reply) \
1745 _(bridge_domain_add_del_reply) \
1746 _(sw_interface_set_l2_xconnect_reply) \
1747 _(l2fib_add_del_reply) \
1748 _(ip_add_del_route_reply) \
1749 _(proxy_arp_add_del_reply) \
1750 _(proxy_arp_intfc_enable_disable_reply) \
1751 _(mpls_add_del_encap_reply) \
1752 _(mpls_add_del_decap_reply) \
1753 _(mpls_ethernet_add_del_tunnel_2_reply) \
1754 _(sw_interface_set_unnumbered_reply) \
1755 _(ip_neighbor_add_del_reply) \
1756 _(reset_vrf_reply) \
1757 _(oam_add_del_reply) \
1758 _(reset_fib_reply) \
1759 _(dhcp_proxy_config_reply) \
1760 _(dhcp_proxy_config_2_reply) \
1761 _(dhcp_proxy_set_vss_reply) \
1762 _(dhcp_client_config_reply) \
1763 _(set_ip_flow_hash_reply) \
1764 _(sw_interface_ip6_enable_disable_reply) \
1765 _(sw_interface_ip6_set_link_local_address_reply) \
1766 _(sw_interface_ip6nd_ra_prefix_reply) \
1767 _(sw_interface_ip6nd_ra_config_reply) \
1768 _(set_arp_neighbor_limit_reply) \
1769 _(l2_patch_add_del_reply) \
1770 _(sr_tunnel_add_del_reply) \
1771 _(classify_add_del_session_reply) \
1772 _(classify_set_interface_ip_table_reply) \
1773 _(classify_set_interface_l2_tables_reply) \
1774 _(l2tpv3_set_tunnel_cookies_reply) \
1775 _(l2tpv3_interface_enable_disable_reply) \
1776 _(l2tpv3_set_lookup_key_reply) \
1777 _(l2_fib_clear_table_reply) \
1778 _(l2_interface_efp_filter_reply) \
1779 _(l2_interface_vlan_tag_rewrite_reply) \
1780 _(modify_vhost_user_if_reply) \
1781 _(delete_vhost_user_if_reply) \
1782 _(want_ip4_arp_events_reply) \
1783 _(input_acl_set_interface_reply) \
1784 _(ipsec_spd_add_del_reply) \
1785 _(ipsec_interface_add_del_spd_reply) \
1786 _(ipsec_spd_add_del_entry_reply) \
1787 _(ipsec_sad_add_del_entry_reply) \
1788 _(ipsec_sa_set_key_reply) \
1789 _(delete_loopback_reply) \
1790 _(bd_ip_mac_add_del_reply) \
1791 _(map_del_domain_reply) \
1792 _(map_add_del_rule_reply) \
1793 _(want_interface_events_reply) \
1797 static void vl_api_##n##_t_handler \
1798 (vl_api_##n##_t * mp) \
1800 vat_main_t * vam = &vat_main; \
1801 i32 retval = ntohl(mp->retval); \
1802 if (vam->async_mode) { \
1803 vam->async_errors += (retval < 0); \
1805 vam->retval = retval; \
1806 vam->result_ready = 1; \
1809 foreach_standard_reply_retval_handler;
1813 static void vl_api_##n##_t_handler_json \
1814 (vl_api_##n##_t * mp) \
1816 vat_main_t * vam = &vat_main; \
1817 vat_json_node_t node; \
1818 vat_json_init_object(&node); \
1819 vat_json_object_add_int(&node, "retval", ntohl(mp->retval)); \
1820 vat_json_print(vam->ofp, &node); \
1821 vam->retval = ntohl(mp->retval); \
1822 vam->result_ready = 1; \
1824 foreach_standard_reply_retval_handler;
1828 * Table of message reply handlers, must include boilerplate handlers
1832 #define foreach_vpe_api_reply_msg \
1833 _(CREATE_LOOPBACK_REPLY, create_loopback_reply) \
1834 _(SW_INTERFACE_DETAILS, sw_interface_details) \
1835 _(SW_INTERFACE_SET_FLAGS, sw_interface_set_flags) \
1836 _(SW_INTERFACE_SET_FLAGS_REPLY, sw_interface_set_flags_reply) \
1837 _(CONTROL_PING_REPLY, control_ping_reply) \
1838 _(CLI_REPLY, cli_reply) \
1839 _(SW_INTERFACE_ADD_DEL_ADDRESS_REPLY, \
1840 sw_interface_add_del_address_reply) \
1841 _(SW_INTERFACE_SET_TABLE_REPLY, sw_interface_set_table_reply) \
1842 _(SW_INTERFACE_SET_VPATH_REPLY, sw_interface_set_vpath_reply) \
1843 _(SW_INTERFACE_SET_L2_XCONNECT_REPLY, \
1844 sw_interface_set_l2_xconnect_reply) \
1845 _(SW_INTERFACE_SET_L2_BRIDGE_REPLY, \
1846 sw_interface_set_l2_bridge_reply) \
1847 _(BRIDGE_DOMAIN_ADD_DEL_REPLY, bridge_domain_add_del_reply) \
1848 _(BRIDGE_DOMAIN_DETAILS, bridge_domain_details) \
1849 _(BRIDGE_DOMAIN_SW_IF_DETAILS, bridge_domain_sw_if_details) \
1850 _(L2FIB_ADD_DEL_REPLY, l2fib_add_del_reply) \
1851 _(L2_FLAGS_REPLY, l2_flags_reply) \
1852 _(BRIDGE_FLAGS_REPLY, bridge_flags_reply) \
1853 _(TAP_CONNECT_REPLY, tap_connect_reply) \
1854 _(TAP_MODIFY_REPLY, tap_modify_reply) \
1855 _(TAP_DELETE_REPLY, tap_delete_reply) \
1856 _(SW_INTERFACE_TAP_DETAILS, sw_interface_tap_details) \
1857 _(IP_ADD_DEL_ROUTE_REPLY, ip_add_del_route_reply) \
1858 _(PROXY_ARP_ADD_DEL_REPLY, proxy_arp_add_del_reply) \
1859 _(PROXY_ARP_INTFC_ENABLE_DISABLE_REPLY, \
1860 proxy_arp_intfc_enable_disable_reply) \
1861 _(MPLS_ADD_DEL_ENCAP_REPLY, mpls_add_del_encap_reply) \
1862 _(MPLS_ADD_DEL_DECAP_REPLY, mpls_add_del_decap_reply) \
1863 _(MPLS_GRE_ADD_DEL_TUNNEL_REPLY, mpls_gre_add_del_tunnel_reply) \
1864 _(MPLS_ETHERNET_ADD_DEL_TUNNEL_REPLY, \
1865 mpls_ethernet_add_del_tunnel_reply) \
1866 _(MPLS_ETHERNET_ADD_DEL_TUNNEL_2_REPLY, \
1867 mpls_ethernet_add_del_tunnel_2_reply) \
1868 _(SW_INTERFACE_SET_UNNUMBERED_REPLY, \
1869 sw_interface_set_unnumbered_reply) \
1870 _(IP_NEIGHBOR_ADD_DEL_REPLY, ip_neighbor_add_del_reply) \
1871 _(RESET_VRF_REPLY, reset_vrf_reply) \
1872 _(CREATE_VLAN_SUBIF_REPLY, create_vlan_subif_reply) \
1873 _(CREATE_SUBIF_REPLY, create_subif_reply) \
1874 _(OAM_ADD_DEL_REPLY, oam_add_del_reply) \
1875 _(RESET_FIB_REPLY, reset_fib_reply) \
1876 _(DHCP_PROXY_CONFIG_REPLY, dhcp_proxy_config_reply) \
1877 _(DHCP_PROXY_CONFIG_2_REPLY, dhcp_proxy_config_2_reply) \
1878 _(DHCP_PROXY_SET_VSS_REPLY, dhcp_proxy_set_vss_reply) \
1879 _(DHCP_CLIENT_CONFIG_REPLY, dhcp_client_config_reply) \
1880 _(SET_IP_FLOW_HASH_REPLY, set_ip_flow_hash_reply) \
1881 _(SW_INTERFACE_IP6_ENABLE_DISABLE_REPLY, \
1882 sw_interface_ip6_enable_disable_reply) \
1883 _(SW_INTERFACE_IP6_SET_LINK_LOCAL_ADDRESS_REPLY, \
1884 sw_interface_ip6_set_link_local_address_reply) \
1885 _(SW_INTERFACE_IP6ND_RA_PREFIX_REPLY, \
1886 sw_interface_ip6nd_ra_prefix_reply) \
1887 _(SW_INTERFACE_IP6ND_RA_CONFIG_REPLY, \
1888 sw_interface_ip6nd_ra_config_reply) \
1889 _(SET_ARP_NEIGHBOR_LIMIT_REPLY, set_arp_neighbor_limit_reply) \
1890 _(L2_PATCH_ADD_DEL_REPLY, l2_patch_add_del_reply) \
1891 _(SR_TUNNEL_ADD_DEL_REPLY, sr_tunnel_add_del_reply) \
1892 _(CLASSIFY_ADD_DEL_TABLE_REPLY, classify_add_del_table_reply) \
1893 _(CLASSIFY_ADD_DEL_SESSION_REPLY, classify_add_del_session_reply) \
1894 _(CLASSIFY_SET_INTERFACE_IP_TABLE_REPLY, \
1895 classify_set_interface_ip_table_reply) \
1896 _(CLASSIFY_SET_INTERFACE_L2_TABLES_REPLY, \
1897 classify_set_interface_l2_tables_reply) \
1898 _(GET_NODE_INDEX_REPLY, get_node_index_reply) \
1899 _(ADD_NODE_NEXT_REPLY, add_node_next_reply) \
1900 _(L2TPV3_CREATE_TUNNEL_REPLY, l2tpv3_create_tunnel_reply) \
1901 _(L2TPV3_SET_TUNNEL_COOKIES_REPLY, l2tpv3_set_tunnel_cookies_reply) \
1902 _(L2TPV3_INTERFACE_ENABLE_DISABLE_REPLY, \
1903 l2tpv3_interface_enable_disable_reply) \
1904 _(L2TPV3_SET_LOOKUP_KEY_REPLY, l2tpv3_set_lookup_key_reply) \
1905 _(SW_IF_L2TPV3_TUNNEL_DETAILS, sw_if_l2tpv3_tunnel_details) \
1906 _(VXLAN_ADD_DEL_TUNNEL_REPLY, vxlan_add_del_tunnel_reply) \
1907 _(VXLAN_TUNNEL_DETAILS, vxlan_tunnel_details) \
1908 _(L2_FIB_CLEAR_TABLE_REPLY, l2_fib_clear_table_reply) \
1909 _(L2_INTERFACE_EFP_FILTER_REPLY, l2_interface_efp_filter_reply) \
1910 _(L2_INTERFACE_VLAN_TAG_REWRITE_REPLY, l2_interface_vlan_tag_rewrite_reply) \
1911 _(SW_INTERFACE_VHOST_USER_DETAILS, sw_interface_vhost_user_details) \
1912 _(CREATE_VHOST_USER_IF_REPLY, create_vhost_user_if_reply) \
1913 _(MODIFY_VHOST_USER_IF_REPLY, modify_vhost_user_if_reply) \
1914 _(DELETE_VHOST_USER_IF_REPLY, delete_vhost_user_if_reply) \
1915 _(SHOW_VERSION_REPLY, show_version_reply) \
1916 _(NSH_GRE_ADD_DEL_TUNNEL_REPLY, nsh_gre_add_del_tunnel_reply) \
1917 _(L2_FIB_TABLE_ENTRY, l2_fib_table_entry) \
1918 _(NSH_VXLAN_GPE_ADD_DEL_TUNNEL_REPLY, nsh_vxlan_gpe_add_del_tunnel_reply) \
1919 _(LISP_GPE_ADD_DEL_TUNNEL_REPLY, lisp_gpe_add_del_tunnel_reply) \
1920 _(INTERFACE_NAME_RENUMBER_REPLY, interface_name_renumber_reply) \
1921 _(WANT_IP4_ARP_EVENTS_REPLY, want_ip4_arp_events_reply) \
1922 _(IP4_ARP_EVENT, ip4_arp_event) \
1923 _(INPUT_ACL_SET_INTERFACE_REPLY, input_acl_set_interface_reply) \
1924 _(IP_ADDRESS_DETAILS, ip_address_details) \
1925 _(IP_DETAILS, ip_details) \
1926 _(IPSEC_SPD_ADD_DEL_REPLY, ipsec_spd_add_del_reply) \
1927 _(IPSEC_INTERFACE_ADD_DEL_SPD_REPLY, ipsec_interface_add_del_spd_reply) \
1928 _(IPSEC_SPD_ADD_DEL_ENTRY_REPLY, ipsec_spd_add_del_entry_reply) \
1929 _(IPSEC_SAD_ADD_DEL_ENTRY_REPLY, ipsec_sad_add_del_entry_reply) \
1930 _(IPSEC_SA_SET_KEY_REPLY, ipsec_sa_set_key_reply) \
1931 _(DELETE_LOOPBACK_REPLY, delete_loopback_reply) \
1932 _(BD_IP_MAC_ADD_DEL_REPLY, bd_ip_mac_add_del_reply) \
1933 _(DHCP_COMPL_EVENT, dhcp_compl_event) \
1934 _(VNET_INTERFACE_COUNTERS, vnet_interface_counters) \
1935 _(VNET_IP4_FIB_COUNTERS, vnet_ip4_fib_counters) \
1936 _(VNET_IP6_FIB_COUNTERS, vnet_ip6_fib_counters) \
1937 _(MAP_ADD_DOMAIN_REPLY, map_add_domain_reply) \
1938 _(MAP_DEL_DOMAIN_REPLY, map_del_domain_reply) \
1939 _(MAP_ADD_DEL_RULE_REPLY, map_add_del_rule_reply) \
1940 _(MAP_DOMAIN_DETAILS, map_domain_details) \
1941 _(MAP_RULE_DETAILS, map_rule_details) \
1942 _(WANT_INTERFACE_EVENTS_REPLY, want_interface_events_reply) \
1943 _(WANT_STATS_REPLY, want_stats_reply) \
1944 _(GET_FIRST_MSG_ID_REPLY, get_first_msg_id_reply)
1946 /* M: construct, but don't yet send a message */
1950 vam->result_ready = 0; \
1951 mp = vl_msg_api_alloc(sizeof(*mp)); \
1952 memset (mp, 0, sizeof (*mp)); \
1953 mp->_vl_msg_id = ntohs (VL_API_##T); \
1954 mp->client_index = vam->my_client_index; \
1959 vam->result_ready = 0; \
1960 mp = vl_msg_api_alloc(sizeof(*mp)+(n)); \
1961 memset (mp, 0, sizeof (*mp)); \
1962 mp->_vl_msg_id = ntohs (VL_API_##T); \
1963 mp->client_index = vam->my_client_index; \
1967 /* S: send a message */
1968 #define S (vl_msg_api_send_shmem (vam->vl_input_queue, (u8 *)&mp))
1970 /* W: wait for results, with timeout */
1973 timeout = vat_time_now (vam) + 1.0; \
1975 while (vat_time_now (vam) < timeout) { \
1976 if (vam->result_ready == 1) { \
1977 return (vam->retval); \
1989 #define STR_VTR_OP_CASE(op) \
1990 case L2_VTR_ ## op: \
1993 static const char *str_vtr_op(u32 vtr_op)
1996 STR_VTR_OP_CASE(DISABLED);
1997 STR_VTR_OP_CASE(PUSH_1);
1998 STR_VTR_OP_CASE(PUSH_2);
1999 STR_VTR_OP_CASE(POP_1);
2000 STR_VTR_OP_CASE(POP_2);
2001 STR_VTR_OP_CASE(TRANSLATE_1_1);
2002 STR_VTR_OP_CASE(TRANSLATE_1_2);
2003 STR_VTR_OP_CASE(TRANSLATE_2_1);
2004 STR_VTR_OP_CASE(TRANSLATE_2_2);
2010 static int dump_sub_interface_table (vat_main_t * vam)
2012 const sw_interface_subif_t * sub = NULL;
2014 if (vam->json_output) {
2015 clib_warning ("JSON output supported only for VPE API calls and dump_stats_table");
2020 "%-30s%-12s%-11s%-7s%-5s%-9s%-9s%-6s%-8s%-10s%-10s\n",
2021 "Interface", "sw_if_index",
2022 "sub id", "dot1ad", "tags", "outer id",
2023 "inner id", "exact", "default",
2024 "outer any", "inner any");
2026 vec_foreach (sub, vam->sw_if_subif_table) {
2028 "%-30s%-12d%-11d%-7s%-5d%-9d%-9d%-6d%-8d%-10d%-10d\n",
2029 sub->interface_name,
2031 sub->sub_id, sub->sub_dot1ad ? "dot1ad" : "dot1q",
2032 sub->sub_number_of_tags, sub->sub_outer_vlan_id,
2033 sub->sub_inner_vlan_id, sub->sub_exact_match, sub->sub_default,
2034 sub->sub_outer_vlan_id_any, sub->sub_inner_vlan_id_any);
2035 if (sub->vtr_op != L2_VTR_DISABLED) {
2037 " vlan-tag-rewrite - op: %-14s [ dot1q: %d "
2038 "tag1: %d tag2: %d ]\n",
2039 str_vtr_op(sub->vtr_op), sub->vtr_push_dot1q,
2040 sub->vtr_tag1, sub->vtr_tag2);
2047 static int name_sort_cmp (void * a1, void * a2)
2049 name_sort_t * n1 = a1;
2050 name_sort_t * n2 = a2;
2052 return strcmp ((char *)n1->name, (char *)n2->name);
2055 static int dump_interface_table (vat_main_t * vam)
2058 name_sort_t * nses = 0, * ns;
2060 if (vam->json_output) {
2061 clib_warning ("JSON output supported only for VPE API calls and dump_stats_table");
2065 hash_foreach_pair (p, vam->sw_if_index_by_interface_name,
2067 vec_add2 (nses, ns, 1);
2068 ns->name = (u8 *)(p->key);
2069 ns->value = (u32) p->value[0];
2072 vec_sort_with_function (nses, name_sort_cmp);
2074 fformat (vam->ofp, "%-25s%-15s\n", "Interface", "sw_if_index");
2075 vec_foreach (ns, nses) {
2076 fformat (vam->ofp, "%-25s%-15d\n", ns->name, ns->value);
2082 static int dump_ip_table (vat_main_t * vam, int is_ipv6)
2084 const ip_details_t * det = NULL;
2085 const ip_address_details_t * address = NULL;
2092 if (0 == vam->ip_details_by_sw_if_index) {
2096 vec_foreach (det, vam->ip_details_by_sw_if_index[is_ipv6]) {
2098 if (!det->present) {
2106 "Address", "Prefix length");
2110 vec_foreach (address, det->addr) {
2113 is_ipv6 ? format_ip6_address : format_ip4_address,
2115 address->prefix_length);
2122 static int dump_ipv4_table (vat_main_t * vam)
2124 if (vam->json_output) {
2125 clib_warning ("JSON output supported only for VPE API calls and dump_stats_table");
2129 return dump_ip_table (vam, 0);
2132 static int dump_ipv6_table (vat_main_t * vam)
2134 if (vam->json_output) {
2135 clib_warning ("JSON output supported only for VPE API calls and dump_stats_table");
2139 return dump_ip_table (vam, 1);
2142 static char* counter_type_to_str (u8 counter_type, u8 is_combined)
2145 switch(counter_type) {
2146 case VNET_INTERFACE_COUNTER_DROP:
2148 case VNET_INTERFACE_COUNTER_PUNT:
2150 case VNET_INTERFACE_COUNTER_IP4:
2152 case VNET_INTERFACE_COUNTER_IP6:
2154 case VNET_INTERFACE_COUNTER_RX_NO_BUF:
2156 case VNET_INTERFACE_COUNTER_RX_MISS:
2158 case VNET_INTERFACE_COUNTER_RX_ERROR:
2160 case VNET_INTERFACE_COUNTER_TX_ERROR:
2163 return "INVALID-COUNTER-TYPE";
2166 switch(counter_type) {
2167 case VNET_INTERFACE_COUNTER_RX:
2169 case VNET_INTERFACE_COUNTER_TX:
2172 return "INVALID-COUNTER-TYPE";
2177 static int dump_stats_table (vat_main_t * vam)
2179 vat_json_node_t node;
2180 vat_json_node_t *msg_array;
2181 vat_json_node_t *msg;
2182 vat_json_node_t *counter_array;
2183 vat_json_node_t *counter;
2184 interface_counter_t c;
2186 ip4_fib_counter_t *c4;
2187 ip6_fib_counter_t *c6;
2190 if (!vam->json_output) {
2191 clib_warning ("dump_stats_table supported only in JSON format");
2195 vat_json_init_object(&node);
2197 /* interface counters */
2198 msg_array = vat_json_object_add(&node, "interface_counters");
2199 vat_json_init_array(msg_array);
2200 for (i = 0; i < vec_len(vam->simple_interface_counters); i++) {
2201 msg = vat_json_array_add(msg_array);
2202 vat_json_init_object(msg);
2203 vat_json_object_add_string_copy(msg, "vnet_counter_type",
2204 (u8*)counter_type_to_str(i, 0));
2205 vat_json_object_add_int(msg, "is_combined", 0);
2206 counter_array = vat_json_object_add(msg, "data");
2207 vat_json_init_array(counter_array);
2208 for (j = 0; j < vec_len(vam->simple_interface_counters[i]); j++) {
2209 packets = vam->simple_interface_counters[i][j];
2210 vat_json_array_add_uint(counter_array, packets);
2213 for (i = 0; i < vec_len(vam->combined_interface_counters); i++) {
2214 msg = vat_json_array_add(msg_array);
2215 vat_json_init_object(msg);
2216 vat_json_object_add_string_copy(msg, "vnet_counter_type",
2217 (u8*)counter_type_to_str(i, 1));
2218 vat_json_object_add_int(msg, "is_combined", 1);
2219 counter_array = vat_json_object_add(msg, "data");
2220 vat_json_init_array(counter_array);
2221 for (j = 0; j < vec_len(vam->combined_interface_counters[i]); j++) {
2222 c = vam->combined_interface_counters[i][j];
2223 counter = vat_json_array_add(counter_array);
2224 vat_json_init_object(counter);
2225 vat_json_object_add_uint(counter, "packets", c.packets);
2226 vat_json_object_add_uint(counter, "bytes", c.bytes);
2230 /* ip4 fib counters */
2231 msg_array = vat_json_object_add(&node, "ip4_fib_counters");
2232 vat_json_init_array(msg_array);
2233 for (i = 0; i < vec_len(vam->ip4_fib_counters); i++) {
2234 msg = vat_json_array_add(msg_array);
2235 vat_json_init_object(msg);
2236 vat_json_object_add_uint(msg, "vrf_id", vam->ip4_fib_counters_vrf_id_by_index[i]);
2237 counter_array = vat_json_object_add(msg, "c");
2238 vat_json_init_array(counter_array);
2239 for (j = 0; j < vec_len(vam->ip4_fib_counters[i]); j++) {
2240 counter = vat_json_array_add(counter_array);
2241 vat_json_init_object(counter);
2242 c4 = &vam->ip4_fib_counters[i][j];
2243 vat_json_object_add_ip4(counter, "address", c4->address);
2244 vat_json_object_add_uint(counter, "address_length", c4->address_length);
2245 vat_json_object_add_uint(counter, "packets", c4->packets);
2246 vat_json_object_add_uint(counter, "bytes", c4->bytes);
2250 /* ip6 fib counters */
2251 msg_array = vat_json_object_add(&node, "ip6_fib_counters");
2252 vat_json_init_array(msg_array);
2253 for (i = 0; i < vec_len(vam->ip6_fib_counters); i++) {
2254 msg = vat_json_array_add(msg_array);
2255 vat_json_init_object(msg);
2256 vat_json_object_add_uint(msg, "vrf_id", vam->ip6_fib_counters_vrf_id_by_index[i]);
2257 counter_array = vat_json_object_add(msg, "c");
2258 vat_json_init_array(counter_array);
2259 for (j = 0; j < vec_len(vam->ip6_fib_counters[i]); j++) {
2260 counter = vat_json_array_add(counter_array);
2261 vat_json_init_object(counter);
2262 c6 = &vam->ip6_fib_counters[i][j];
2263 vat_json_object_add_ip6(counter, "address", c6->address);
2264 vat_json_object_add_uint(counter, "address_length", c6->address_length);
2265 vat_json_object_add_uint(counter, "packets", c6->packets);
2266 vat_json_object_add_uint(counter, "bytes", c6->bytes);
2270 vat_json_print(vam->ofp, &node);
2271 vat_json_free(&node);
2276 int exec (vat_main_t * vam)
2278 api_main_t * am = &api_main;
2279 vl_api_cli_request_t *mp;
2283 unformat_input_t * i = vam->input;
2285 if (vec_len(i->buffer) == 0)
2288 if (vam->exec_mode == 0 && unformat (i, "mode")) {
2292 if (vam->exec_mode == 1 &&
2293 (unformat (i, "exit") || unformat (i, "quit"))) {
2299 M(CLI_REQUEST, cli_request);
2302 * Copy cmd into shared memory.
2303 * In order for the CLI command to work, it
2304 * must be a vector ending in \n, not a C-string ending
2307 pthread_mutex_lock (&am->vlib_rp->mutex);
2308 oldheap = svm_push_data_heap (am->vlib_rp);
2310 vec_validate (cmd, vec_len(vam->input->buffer)-1);
2311 memcpy (cmd, vam->input->buffer, vec_len(vam->input->buffer));
2313 svm_pop_heap (oldheap);
2314 pthread_mutex_unlock (&am->vlib_rp->mutex);
2316 mp->cmd_in_shmem = (u64) cmd;
2318 timeout = vat_time_now (vam) + 10.0;
2320 while (vat_time_now (vam) < timeout) {
2321 if (vam->result_ready == 1) {
2323 fformat (vam->ofp, "%s", vam->shmem_result);
2324 pthread_mutex_lock (&am->vlib_rp->mutex);
2325 oldheap = svm_push_data_heap (am->vlib_rp);
2327 free_me = (u8 *)vam->shmem_result;
2330 svm_pop_heap (oldheap);
2331 pthread_mutex_unlock (&am->vlib_rp->mutex);
2338 static int api_create_loopback (vat_main_t * vam)
2340 unformat_input_t * i = vam->input;
2341 vl_api_create_loopback_t *mp;
2346 memset (mac_address, 0, sizeof (mac_address));
2348 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
2350 if (unformat (i, "mac %U", unformat_ethernet_address, mac_address))
2356 /* Construct the API message */
2357 M(CREATE_LOOPBACK, create_loopback);
2359 memcpy (mp->mac_address, mac_address, sizeof (mac_address));
2364 static int api_delete_loopback (vat_main_t * vam)
2366 unformat_input_t * i = vam->input;
2367 vl_api_delete_loopback_t *mp;
2369 u32 sw_if_index = ~0;
2371 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
2373 if (unformat (i, "sw_if_index %d", &sw_if_index))
2379 if (sw_if_index == ~0)
2381 errmsg ("missing sw_if_index\n");
2385 /* Construct the API message */
2386 M(DELETE_LOOPBACK, delete_loopback);
2387 mp->sw_if_index = ntohl (sw_if_index);
2392 static int api_want_stats (vat_main_t * vam)
2394 unformat_input_t * i = vam->input;
2395 vl_api_want_stats_t * mp;
2399 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
2401 if (unformat (i, "enable"))
2403 else if (unformat (i, "disable"))
2411 errmsg ("missing enable|disable\n");
2415 M(WANT_STATS, want_stats);
2416 mp->enable_disable = enable;
2421 static int api_want_interface_events (vat_main_t * vam)
2423 unformat_input_t * i = vam->input;
2424 vl_api_want_interface_events_t * mp;
2428 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
2430 if (unformat (i, "enable"))
2432 else if (unformat (i, "disable"))
2440 errmsg ("missing enable|disable\n");
2444 M(WANT_INTERFACE_EVENTS, want_interface_events);
2445 mp->enable_disable = enable;
2447 vam->interface_event_display = enable;
2453 /* Note: non-static, called once to set up the initial intfc table */
2454 int api_sw_interface_dump (vat_main_t * vam)
2456 vl_api_sw_interface_dump_t *mp;
2459 name_sort_t * nses = 0, * ns;
2460 sw_interface_subif_t * sub = NULL;
2462 /* Toss the old name table */
2463 hash_foreach_pair (p, vam->sw_if_index_by_interface_name,
2465 vec_add2 (nses, ns, 1);
2466 ns->name = (u8 *)(p->key);
2467 ns->value = (u32) p->value[0];
2470 hash_free (vam->sw_if_index_by_interface_name);
2472 vec_foreach (ns, nses)
2473 vec_free (ns->name);
2477 vec_foreach (sub, vam->sw_if_subif_table) {
2478 vec_free (sub->interface_name);
2480 vec_free (vam->sw_if_subif_table);
2482 /* recreate the interface name hash table */
2483 vam->sw_if_index_by_interface_name
2484 = hash_create_string (0, sizeof(uword));
2486 /* Get list of ethernets */
2487 M(SW_INTERFACE_DUMP, sw_interface_dump);
2488 mp->name_filter_valid = 1;
2489 strncpy ((char *) mp->name_filter, "Ether", sizeof(mp->name_filter-1));
2492 /* and local / loopback interfaces */
2493 M(SW_INTERFACE_DUMP, sw_interface_dump);
2494 mp->name_filter_valid = 1;
2495 strncpy ((char *) mp->name_filter, "lo", sizeof(mp->name_filter-1));
2498 /* and vxlan tunnel interfaces */
2499 M(SW_INTERFACE_DUMP, sw_interface_dump);
2500 mp->name_filter_valid = 1;
2501 strncpy ((char *) mp->name_filter, "vxlan", sizeof(mp->name_filter-1));
2504 /* and l2tpv3 tunnel interfaces */
2505 M(SW_INTERFACE_DUMP, sw_interface_dump);
2506 mp->name_filter_valid = 1;
2507 strncpy ((char *) mp->name_filter, "l2tpv3_tunnel", sizeof(mp->name_filter-1));
2510 /* Use a control ping for synchronization */
2512 vl_api_control_ping_t * mp;
2513 M(CONTROL_PING, control_ping);
2519 static int api_sw_interface_set_flags (vat_main_t * vam)
2521 unformat_input_t * i = vam->input;
2522 vl_api_sw_interface_set_flags_t *mp;
2525 u8 sw_if_index_set = 0;
2526 u8 admin_up = 0, link_up = 0;
2528 /* Parse args required to build the message */
2529 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
2530 if (unformat (i, "admin-up"))
2532 else if (unformat (i, "admin-down"))
2534 else if (unformat (i, "link-up"))
2536 else if (unformat (i, "link-down"))
2538 else if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
2539 sw_if_index_set = 1;
2540 else if (unformat (i, "sw_if_index %d", &sw_if_index))
2541 sw_if_index_set = 1;
2546 if (sw_if_index_set == 0) {
2547 errmsg ("missing interface name or sw_if_index\n");
2551 /* Construct the API message */
2552 M(SW_INTERFACE_SET_FLAGS, sw_interface_set_flags);
2553 mp->sw_if_index = ntohl (sw_if_index);
2554 mp->admin_up_down = admin_up;
2555 mp->link_up_down = link_up;
2560 /* Wait for a reply, return the good/bad news... */
2564 static int api_sw_interface_add_del_address (vat_main_t * vam)
2566 unformat_input_t * i = vam->input;
2567 vl_api_sw_interface_add_del_address_t *mp;
2570 u8 sw_if_index_set = 0;
2571 u8 is_add = 1, del_all = 0;
2572 u32 address_length = 0;
2573 u8 v4_address_set = 0;
2574 u8 v6_address_set = 0;
2575 ip4_address_t v4address;
2576 ip6_address_t v6address;
2578 /* Parse args required to build the message */
2579 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
2580 if (unformat (i, "del-all"))
2582 else if (unformat (i, "del"))
2584 else if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
2585 sw_if_index_set = 1;
2586 else if (unformat (i, "sw_if_index %d", &sw_if_index))
2587 sw_if_index_set = 1;
2588 else if (unformat (i, "%U/%d",
2589 unformat_ip4_address, &v4address,
2592 else if (unformat (i, "%U/%d",
2593 unformat_ip6_address, &v6address,
2600 if (sw_if_index_set == 0) {
2601 errmsg ("missing interface name or sw_if_index\n");
2604 if (v4_address_set && v6_address_set) {
2605 errmsg ("both v4 and v6 addresses set\n");
2608 if (!v4_address_set && !v6_address_set && !del_all) {
2609 errmsg ("no addresses set\n");
2613 /* Construct the API message */
2614 M(SW_INTERFACE_ADD_DEL_ADDRESS, sw_interface_add_del_address);
2616 mp->sw_if_index = ntohl (sw_if_index);
2617 mp->is_add = is_add;
2618 mp->del_all = del_all;
2619 if (v6_address_set) {
2621 memcpy (mp->address, &v6address, sizeof (v6address));
2623 memcpy (mp->address, &v4address, sizeof (v4address));
2625 mp->address_length = address_length;
2630 /* Wait for a reply, return good/bad news */
2634 static int api_sw_interface_set_table (vat_main_t * vam)
2636 unformat_input_t * i = vam->input;
2637 vl_api_sw_interface_set_table_t *mp;
2639 u32 sw_if_index, vrf_id = 0;
2640 u8 sw_if_index_set = 0;
2643 /* Parse args required to build the message */
2644 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
2645 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
2646 sw_if_index_set = 1;
2647 else if (unformat (i, "sw_if_index %d", &sw_if_index))
2648 sw_if_index_set = 1;
2649 else if (unformat (i, "vrf %d", &vrf_id))
2651 else if (unformat (i, "ipv6"))
2657 if (sw_if_index_set == 0) {
2658 errmsg ("missing interface name or sw_if_index\n");
2662 /* Construct the API message */
2663 M(SW_INTERFACE_SET_TABLE, sw_interface_set_table);
2665 mp->sw_if_index = ntohl (sw_if_index);
2666 mp->is_ipv6 = is_ipv6;
2667 mp->vrf_id = ntohl (vrf_id);
2672 /* Wait for a reply... */
2676 static int api_sw_interface_set_vpath (vat_main_t * vam)
2678 unformat_input_t * i = vam->input;
2679 vl_api_sw_interface_set_vpath_t *mp;
2681 u32 sw_if_index = 0;
2682 u8 sw_if_index_set = 0;
2685 /* Parse args required to build the message */
2686 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
2687 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
2688 sw_if_index_set = 1;
2689 else if (unformat (i, "sw_if_index %d", &sw_if_index))
2690 sw_if_index_set = 1;
2691 else if (unformat (i, "enable"))
2693 else if (unformat (i, "disable"))
2699 if (sw_if_index_set == 0) {
2700 errmsg ("missing interface name or sw_if_index\n");
2704 /* Construct the API message */
2705 M(SW_INTERFACE_SET_VPATH, sw_interface_set_vpath);
2707 mp->sw_if_index = ntohl (sw_if_index);
2708 mp->enable = is_enable;
2713 /* Wait for a reply... */
2717 static int api_sw_interface_set_l2_xconnect (vat_main_t * vam)
2719 unformat_input_t * i = vam->input;
2720 vl_api_sw_interface_set_l2_xconnect_t *mp;
2723 u8 rx_sw_if_index_set = 0;
2725 u8 tx_sw_if_index_set = 0;
2728 /* Parse args required to build the message */
2729 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
2730 if (unformat (i, "rx_sw_if_index %d", &rx_sw_if_index))
2731 rx_sw_if_index_set = 1;
2732 else if (unformat (i, "tx_sw_if_index %d", &tx_sw_if_index))
2733 tx_sw_if_index_set = 1;
2734 else if (unformat (i, "rx")) {
2735 if (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
2736 if (unformat (i, "%U", unformat_sw_if_index, vam,
2738 rx_sw_if_index_set = 1;
2741 } else if (unformat (i, "tx")) {
2742 if (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
2743 if (unformat (i, "%U", unformat_sw_if_index, vam,
2745 tx_sw_if_index_set = 1;
2748 } else if (unformat (i, "enable"))
2750 else if (unformat (i, "disable"))
2756 if (rx_sw_if_index_set == 0) {
2757 errmsg ("missing rx interface name or rx_sw_if_index\n");
2761 if (enable && (tx_sw_if_index_set == 0)) {
2762 errmsg ("missing tx interface name or tx_sw_if_index\n");
2766 M(SW_INTERFACE_SET_L2_XCONNECT, sw_interface_set_l2_xconnect);
2768 mp->rx_sw_if_index = ntohl(rx_sw_if_index);
2769 mp->tx_sw_if_index = ntohl(tx_sw_if_index);
2770 mp->enable = enable;
2777 static int api_sw_interface_set_l2_bridge (vat_main_t * vam)
2779 unformat_input_t * i = vam->input;
2780 vl_api_sw_interface_set_l2_bridge_t *mp;
2783 u8 rx_sw_if_index_set = 0;
2790 /* Parse args required to build the message */
2791 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
2792 if (unformat (i, "sw_if_index %d", &rx_sw_if_index))
2793 rx_sw_if_index_set = 1;
2794 else if (unformat (i, "bd_id %d", &bd_id))
2796 else if (unformat (i, "%U", unformat_sw_if_index, vam,
2798 rx_sw_if_index_set = 1;
2799 else if (unformat (i, "shg %d", &shg))
2801 else if (unformat (i, "bvi"))
2803 else if (unformat (i, "enable"))
2805 else if (unformat (i, "disable"))
2811 if (rx_sw_if_index_set == 0) {
2812 errmsg ("missing rx interface name or sw_if_index\n");
2816 if (enable && (bd_id_set == 0)) {
2817 errmsg ("missing bridge domain\n");
2821 M(SW_INTERFACE_SET_L2_BRIDGE, sw_interface_set_l2_bridge);
2823 mp->rx_sw_if_index = ntohl(rx_sw_if_index);
2824 mp->bd_id = ntohl(bd_id);
2827 mp->enable = enable;
2834 static int api_bridge_domain_dump (vat_main_t * vam)
2836 unformat_input_t * i = vam->input;
2837 vl_api_bridge_domain_dump_t *mp;
2841 /* Parse args required to build the message */
2842 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
2843 if (unformat (i, "bd_id %d", &bd_id))
2849 M(BRIDGE_DOMAIN_DUMP, bridge_domain_dump);
2850 mp->bd_id = ntohl(bd_id);
2853 /* Use a control ping for synchronization */
2855 vl_api_control_ping_t * mp;
2856 M(CONTROL_PING, control_ping);
2865 static int api_bridge_domain_add_del (vat_main_t * vam)
2867 unformat_input_t * i = vam->input;
2868 vl_api_bridge_domain_add_del_t *mp;
2872 u32 flood = 1, forward = 1, learn = 1, uu_flood = 1, arp_term = 0;
2874 /* Parse args required to build the message */
2875 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
2876 if (unformat (i, "bd_id %d", &bd_id))
2878 else if (unformat (i, "flood %d", &flood))
2880 else if (unformat (i, "uu-flood %d", &uu_flood))
2882 else if (unformat (i, "forward %d", &forward))
2884 else if (unformat (i, "learn %d", &learn))
2886 else if (unformat (i, "arp-term %d", &arp_term))
2888 else if (unformat (i, "del")) {
2890 flood = uu_flood = forward = learn = 0;
2897 errmsg ("missing bridge domain\n");
2901 M(BRIDGE_DOMAIN_ADD_DEL, bridge_domain_add_del);
2903 mp->bd_id = ntohl(bd_id);
2905 mp->uu_flood = uu_flood;
2906 mp->forward = forward;
2908 mp->arp_term = arp_term;
2909 mp->is_add = is_add;
2916 static int api_l2fib_add_del (vat_main_t * vam)
2918 unformat_input_t * i = vam->input;
2919 vl_api_l2fib_add_del_t *mp;
2926 u8 sw_if_index_set = 0;
2931 /* Parse args required to build the message */
2932 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
2933 if (unformat (i, "mac %U", unformat_ethernet_address, &mac))
2935 else if (unformat (i, "bd_id %d", &bd_id))
2937 else if (unformat (i, "sw_if_index %d", &sw_if_index))
2938 sw_if_index_set = 1;
2939 else if (unformat (i, "sw_if")) {
2940 if (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
2941 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
2942 sw_if_index_set = 1;
2945 } else if (unformat (i, "static"))
2947 else if (unformat (i, "filter")) {
2950 } else if (unformat (i, "del"))
2957 errmsg ("missing mac address\n");
2961 if (bd_id_set == 0) {
2962 errmsg ("missing bridge domain\n");
2966 if (is_add && (sw_if_index_set == 0)) {
2967 errmsg ("missing interface name or sw_if_index\n");
2971 M(L2FIB_ADD_DEL, l2fib_add_del);
2974 mp->bd_id = ntohl(bd_id);
2975 mp->is_add = is_add;
2978 mp->sw_if_index = ntohl(sw_if_index);
2979 mp->static_mac = static_mac;
2980 mp->filter_mac = filter_mac;
2988 static int api_l2_flags (vat_main_t * vam)
2990 unformat_input_t * i = vam->input;
2991 vl_api_l2_flags_t *mp;
2994 u32 feature_bitmap = 0;
2995 u8 sw_if_index_set = 0;
2997 /* Parse args required to build the message */
2998 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
2999 if (unformat (i, "sw_if_index %d", &sw_if_index))
3000 sw_if_index_set = 1;
3001 else if (unformat (i, "sw_if")) {
3002 if (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
3003 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
3004 sw_if_index_set = 1;
3007 } else if (unformat (i, "learn"))
3008 feature_bitmap |= L2INPUT_FEAT_LEARN;
3009 else if (unformat (i, "forward"))
3010 feature_bitmap |= L2INPUT_FEAT_FWD;
3011 else if (unformat (i, "flood"))
3012 feature_bitmap |= L2INPUT_FEAT_FLOOD;
3013 else if (unformat (i, "uu-flood"))
3014 feature_bitmap |= L2INPUT_FEAT_UU_FLOOD;
3019 if (sw_if_index_set == 0) {
3020 errmsg ("missing interface name or sw_if_index\n");
3024 M(L2_FLAGS, l2_flags);
3026 mp->sw_if_index = ntohl(sw_if_index);
3027 mp->feature_bitmap = ntohl(feature_bitmap);
3034 static int api_bridge_flags (vat_main_t * vam)
3036 unformat_input_t * i = vam->input;
3037 vl_api_bridge_flags_t *mp;
3044 /* Parse args required to build the message */
3045 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
3046 if (unformat (i, "bd_id %d", &bd_id))
3048 else if (unformat (i, "learn"))
3050 else if (unformat (i, "forward"))
3052 else if (unformat (i, "flood"))
3054 else if (unformat (i, "uu-flood"))
3055 flags |= L2_UU_FLOOD;
3056 else if (unformat (i, "arp-term"))
3057 flags |= L2_ARP_TERM;
3058 else if (unformat (i, "off"))
3060 else if (unformat (i, "disable"))
3066 if (bd_id_set == 0) {
3067 errmsg ("missing bridge domain\n");
3071 M(BRIDGE_FLAGS, bridge_flags);
3073 mp->bd_id = ntohl(bd_id);
3074 mp->feature_bitmap = ntohl(flags);
3075 mp->is_set = is_set;
3082 static int api_bd_ip_mac_add_del (vat_main_t * vam)
3084 unformat_input_t * i = vam->input;
3085 vl_api_bd_ip_mac_add_del_t *mp;
3093 ip4_address_t v4addr;
3094 ip6_address_t v6addr;
3098 /* Parse args required to build the message */
3099 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
3100 if (unformat (i, "bd_id %d", &bd_id)) {
3102 } else if (unformat (i, "%U", unformat_ip4_address, &v4addr)) {
3104 } else if (unformat (i, "%U", unformat_ip6_address, &v6addr)) {
3107 } else if (unformat (i, "%U", unformat_ethernet_address, macaddr)) {
3109 } else if (unformat (i, "del"))
3115 if (bd_id_set == 0) {
3116 errmsg ("missing bridge domain\n");
3118 } else if (ip_set == 0) {
3119 errmsg ("missing IP address\n");
3121 } else if (mac_set == 0) {
3122 errmsg ("missing MAC address\n");
3126 M(BD_IP_MAC_ADD_DEL, bd_ip_mac_add_del);
3128 mp->bd_id = ntohl(bd_id);
3129 mp->is_ipv6 = is_ipv6;
3130 mp->is_add = is_add;
3132 memcpy (mp->ip_address, &v6addr, sizeof (v6addr));
3133 else memcpy (mp->ip_address, &v4addr, sizeof (v4addr));
3134 memcpy (mp->mac_address, macaddr, 6);
3140 static int api_tap_connect (vat_main_t * vam)
3142 unformat_input_t * i = vam->input;
3143 vl_api_tap_connect_t *mp;
3150 memset (mac_address, 0, sizeof (mac_address));
3152 /* Parse args required to build the message */
3153 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
3154 if (unformat (i, "mac %U", unformat_ethernet_address, mac_address)) {
3157 else if (unformat (i, "random-mac"))
3159 else if (unformat (i, "tapname %s", &tap_name))
3165 if (name_set == 0) {
3166 errmsg ("missing tap name\n");
3169 if (vec_len (tap_name) > 63) {
3170 errmsg ("tap name too long\n");
3172 vec_add1 (tap_name, 0);
3174 /* Construct the API message */
3175 M(TAP_CONNECT, tap_connect);
3177 mp->use_random_mac = random_mac;
3178 memcpy (mp->mac_address, mac_address, 6);
3179 memcpy (mp->tap_name, tap_name, vec_len (tap_name));
3180 vec_free (tap_name);
3185 /* Wait for a reply... */
3189 static int api_tap_modify (vat_main_t * vam)
3191 unformat_input_t * i = vam->input;
3192 vl_api_tap_modify_t *mp;
3198 u32 sw_if_index = ~0;
3199 u8 sw_if_index_set = 0;
3201 memset (mac_address, 0, sizeof (mac_address));
3203 /* Parse args required to build the message */
3204 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
3205 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
3206 sw_if_index_set = 1;
3207 else if (unformat (i, "sw_if_index %d", &sw_if_index))
3208 sw_if_index_set = 1;
3209 else if (unformat (i, "mac %U", unformat_ethernet_address, mac_address)) {
3212 else if (unformat (i, "random-mac"))
3214 else if (unformat (i, "tapname %s", &tap_name))
3220 if (sw_if_index_set == 0) {
3221 errmsg ("missing vpp interface name");
3224 if (name_set == 0) {
3225 errmsg ("missing tap name\n");
3228 if (vec_len (tap_name) > 63) {
3229 errmsg ("tap name too long\n");
3231 vec_add1 (tap_name, 0);
3233 /* Construct the API message */
3234 M(TAP_MODIFY, tap_modify);
3236 mp->use_random_mac = random_mac;
3237 mp->sw_if_index = ntohl(sw_if_index);
3238 memcpy (mp->mac_address, mac_address, 6);
3239 memcpy (mp->tap_name, tap_name, vec_len (tap_name));
3240 vec_free (tap_name);
3245 /* Wait for a reply... */
3249 static int api_tap_delete (vat_main_t * vam)
3251 unformat_input_t * i = vam->input;
3252 vl_api_tap_delete_t *mp;
3254 u32 sw_if_index = ~0;
3255 u8 sw_if_index_set = 0;
3257 /* Parse args required to build the message */
3258 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
3259 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
3260 sw_if_index_set = 1;
3261 else if (unformat (i, "sw_if_index %d", &sw_if_index))
3262 sw_if_index_set = 1;
3267 if (sw_if_index_set == 0) {
3268 errmsg ("missing vpp interface name");
3272 /* Construct the API message */
3273 M(TAP_DELETE, tap_delete);
3275 mp->sw_if_index = ntohl(sw_if_index);
3280 /* Wait for a reply... */
3284 static int api_ip_add_del_route (vat_main_t * vam)
3286 unformat_input_t * i = vam->input;
3287 vl_api_ip_add_del_route_t *mp;
3289 u32 sw_if_index = 0, vrf_id = 0;
3290 u8 sw_if_index_set = 0;
3292 u8 is_local = 0, is_drop = 0;
3293 u8 create_vrf_if_needed = 0;
3295 u8 next_hop_weight = 1;
3297 u8 is_multipath = 0;
3299 u8 address_length_set = 0;
3300 u32 lookup_in_vrf = 0;
3301 u32 resolve_attempts = 0;
3302 u32 dst_address_length = 0;
3303 u8 next_hop_set = 0;
3304 ip4_address_t v4_dst_address, v4_next_hop_address;
3305 ip6_address_t v6_dst_address, v6_next_hop_address;
3309 u32 random_add_del = 0;
3310 u32 * random_vector = 0;
3311 uword * random_hash;
3312 u32 random_seed = 0xdeaddabe;
3313 u32 classify_table_index = ~0;
3316 /* Parse args required to build the message */
3317 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
3318 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
3319 sw_if_index_set = 1;
3320 else if (unformat (i, "sw_if_index %d", &sw_if_index))
3321 sw_if_index_set = 1;
3322 else if (unformat (i, "%U", unformat_ip4_address,
3327 else if (unformat (i, "%U", unformat_ip6_address, &v6_dst_address)) {
3331 else if (unformat (i, "/%d", &dst_address_length)) {
3332 address_length_set = 1;
3335 else if (is_ipv6 == 0 && unformat (i, "via %U", unformat_ip4_address,
3336 &v4_next_hop_address)) {
3339 else if (is_ipv6 == 1 && unformat (i, "via %U", unformat_ip6_address,
3340 &v6_next_hop_address)) {
3343 else if (unformat (i, "resolve-attempts %d", &resolve_attempts))
3345 else if (unformat (i, "weight %d", &next_hop_weight))
3347 else if (unformat (i, "drop")) {
3349 } else if (unformat (i, "local")) {
3351 } else if (unformat (i, "classify %d", &classify_table_index)) {
3353 } else if (unformat (i, "del"))
3355 else if (unformat (i, "add"))
3357 else if (unformat (i, "not-last"))
3359 else if (unformat (i, "multipath"))
3361 else if (unformat (i, "vrf %d", &vrf_id))
3363 else if (unformat (i, "create-vrf"))
3364 create_vrf_if_needed = 1;
3365 else if (unformat (i, "count %d", &count))
3367 else if (unformat (i, "lookup-in-vrf %d", &lookup_in_vrf))
3369 else if (unformat (i, "random"))
3371 else if (unformat (i, "seed %d", &random_seed))
3374 clib_warning ("parse error '%U'", format_unformat_error, i);
3379 if (resolve_attempts > 0 && sw_if_index_set == 0) {
3380 errmsg ("ARP resolution needs explicit interface or sw_if_index\n");
3384 if (!next_hop_set && !is_drop && !is_local && !is_classify) {
3385 errmsg ("next hop / local / drop / classify not set\n");
3389 if (address_set == 0) {
3390 errmsg ("missing addresses\n");
3394 if (address_length_set == 0) {
3395 errmsg ("missing address length\n");
3399 /* Generate a pile of unique, random routes */
3400 if (random_add_del) {
3401 u32 this_random_address;
3402 random_hash = hash_create (count, sizeof(uword));
3404 hash_set (random_hash, v4_next_hop_address.as_u32, 1);
3405 for (j = 0; j <= count; j++) {
3407 this_random_address = random_u32 (&random_seed);
3408 this_random_address =
3409 clib_host_to_net_u32 (this_random_address);
3410 } while (hash_get (random_hash, this_random_address));
3411 vec_add1 (random_vector, this_random_address);
3412 hash_set (random_hash, this_random_address, 1);
3414 hash_free (random_hash);
3415 v4_dst_address.as_u32 = random_vector[0];
3419 /* Turn on async mode */
3420 vam->async_mode = 1;
3421 vam->async_errors = 0;
3422 before = vat_time_now(vam);
3425 for (j = 0; j < count; j++) {
3426 /* Construct the API message */
3427 M(IP_ADD_DEL_ROUTE, ip_add_del_route);
3429 mp->next_hop_sw_if_index = ntohl (sw_if_index);
3430 mp->vrf_id = ntohl (vrf_id);
3431 if (resolve_attempts > 0) {
3432 mp->resolve_attempts = ntohl (resolve_attempts);
3433 mp->resolve_if_needed = 1;
3435 mp->create_vrf_if_needed = create_vrf_if_needed;
3437 mp->is_add = is_add;
3438 mp->is_drop = is_drop;
3439 mp->is_ipv6 = is_ipv6;
3440 mp->is_local = is_local;
3441 mp->is_classify = is_classify;
3442 mp->is_multipath = is_multipath;
3443 mp->not_last = not_last;
3444 mp->next_hop_weight = next_hop_weight;
3445 mp->dst_address_length = dst_address_length;
3446 mp->lookup_in_vrf = ntohl(lookup_in_vrf);
3447 mp->classify_table_index = ntohl(classify_table_index);
3450 memcpy (mp->dst_address, &v6_dst_address, sizeof (v6_dst_address));
3452 memcpy (mp->next_hop_address, &v6_next_hop_address,
3453 sizeof (v6_next_hop_address));
3454 increment_v6_address (&v6_dst_address);
3456 memcpy (mp->dst_address, &v4_dst_address, sizeof (v4_dst_address));
3458 memcpy (mp->next_hop_address, &v4_next_hop_address,
3459 sizeof (v4_next_hop_address));
3461 v4_dst_address.as_u32 = random_vector[j+1];
3463 increment_v4_address (&v4_dst_address);
3469 /* When testing multiple add/del ops, use a control-ping to sync */
3471 vl_api_control_ping_t * mp;
3474 /* Shut off async mode */
3475 vam->async_mode = 0;
3477 M(CONTROL_PING, control_ping);
3480 timeout = vat_time_now(vam) + 1.0;
3481 while (vat_time_now (vam) < timeout)
3482 if (vam->result_ready == 1)
3487 if (vam->retval == -99)
3488 errmsg ("timeout\n");
3490 if (vam->async_errors > 0) {
3491 errmsg ("%d asynchronous errors\n", vam->async_errors);
3494 vam->async_errors = 0;
3495 after = vat_time_now(vam);
3497 fformat(vam->ofp, "%d routes in %.6f secs, %.2f routes/sec\n",
3498 count, after - before, count / (after - before));
3500 /* Wait for a reply... */
3504 /* Return the good/bad news */
3505 return (vam->retval);
3508 static int api_proxy_arp_add_del (vat_main_t * vam)
3510 unformat_input_t * i = vam->input;
3511 vl_api_proxy_arp_add_del_t *mp;
3515 ip4_address_t lo, hi;
3518 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
3519 if (unformat (i, "vrf %d", &vrf_id))
3521 else if (unformat (i, "%U - %U", unformat_ip4_address, &lo,
3522 unformat_ip4_address, &hi))
3524 else if (unformat (i, "del"))
3527 clib_warning ("parse error '%U'", format_unformat_error, i);
3532 if (range_set == 0) {
3533 errmsg ("address range not set\n");
3537 M(PROXY_ARP_ADD_DEL, proxy_arp_add_del);
3539 mp->vrf_id = ntohl(vrf_id);
3540 mp->is_add = is_add;
3541 memcpy(mp->low_address, &lo, sizeof (mp->low_address));
3542 memcpy(mp->hi_address, &hi, sizeof (mp->hi_address));
3549 static int api_proxy_arp_intfc_enable_disable (vat_main_t * vam)
3551 unformat_input_t * i = vam->input;
3552 vl_api_proxy_arp_intfc_enable_disable_t *mp;
3556 u8 sw_if_index_set = 0;
3558 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
3559 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
3560 sw_if_index_set = 1;
3561 else if (unformat (i, "sw_if_index %d", &sw_if_index))
3562 sw_if_index_set = 1;
3563 else if (unformat (i, "enable"))
3565 else if (unformat (i, "disable"))
3568 clib_warning ("parse error '%U'", format_unformat_error, i);
3573 if (sw_if_index_set == 0) {
3574 errmsg ("missing interface name or sw_if_index\n");
3578 M(PROXY_ARP_INTFC_ENABLE_DISABLE, proxy_arp_intfc_enable_disable);
3580 mp->sw_if_index = ntohl(sw_if_index);
3581 mp->enable_disable = enable;
3588 static int api_mpls_add_del_decap (vat_main_t * vam)
3590 unformat_input_t * i = vam->input;
3591 vl_api_mpls_add_del_decap_t *mp;
3600 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
3601 if (unformat (i, "rx_vrf_id %d", &rx_vrf_id))
3603 else if (unformat (i, "tx_vrf_id %d", &tx_vrf_id))
3605 else if (unformat (i, "label %d", &label))
3607 else if (unformat (i, "next-index %d", &next_index))
3609 else if (unformat (i, "del"))
3611 else if (unformat (i, "s-bit-clear"))
3614 clib_warning ("parse error '%U'", format_unformat_error, i);
3619 M(MPLS_ADD_DEL_DECAP, mpls_add_del_decap);
3621 mp->rx_vrf_id = ntohl(rx_vrf_id);
3622 mp->tx_vrf_id = ntohl(tx_vrf_id);
3623 mp->label = ntohl(label);
3624 mp->next_index = ntohl(next_index);
3626 mp->is_add = is_add;
3633 static int api_mpls_add_del_encap (vat_main_t * vam)
3635 unformat_input_t * i = vam->input;
3636 vl_api_mpls_add_del_encap_t *mp;
3641 ip4_address_t dst_address;
3644 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
3645 if (unformat (i, "vrf %d", &vrf_id))
3647 else if (unformat (i, "label %d", &label))
3648 vec_add1 (labels, ntohl(label));
3649 else if (unformat (i, "dst %U", unformat_ip4_address, &dst_address))
3651 else if (unformat (i, "del"))
3654 clib_warning ("parse error '%U'", format_unformat_error, i);
3659 if (vec_len (labels) == 0) {
3660 errmsg ("missing encap label stack\n");
3664 M2(MPLS_ADD_DEL_ENCAP, mpls_add_del_encap,
3665 sizeof (u32) * vec_len (labels));
3667 mp->vrf_id = ntohl(vrf_id);
3668 memcpy(mp->dst_address, &dst_address, sizeof (dst_address));
3669 mp->is_add = is_add;
3670 mp->nlabels = vec_len (labels);
3671 memcpy(mp->labels, labels, sizeof(u32)*mp->nlabels);
3680 static int api_mpls_gre_add_del_tunnel (vat_main_t * vam)
3682 unformat_input_t * i = vam->input;
3683 vl_api_mpls_gre_add_del_tunnel_t *mp;
3685 u32 inner_vrf_id = 0;
3686 u32 outer_vrf_id = 0;
3687 ip4_address_t src_address;
3688 ip4_address_t dst_address;
3689 ip4_address_t intfc_address;
3691 u8 intfc_address_length = 0;
3695 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
3696 if (unformat (i, "inner_vrf_id %d", &inner_vrf_id))
3698 else if (unformat (i, "outer_vrf_id %d", &outer_vrf_id))
3700 else if (unformat (i, "src %U", unformat_ip4_address, &src_address))
3702 else if (unformat (i, "dst %U", unformat_ip4_address, &dst_address))
3704 else if (unformat (i, "adj %U/%d", unformat_ip4_address,
3705 &intfc_address, &tmp))
3706 intfc_address_length = tmp;
3707 else if (unformat (i, "l2-only"))
3709 else if (unformat (i, "del"))
3712 clib_warning ("parse error '%U'", format_unformat_error, i);
3717 M(MPLS_GRE_ADD_DEL_TUNNEL, mpls_gre_add_del_tunnel);
3719 mp->inner_vrf_id = ntohl(inner_vrf_id);
3720 mp->outer_vrf_id = ntohl(outer_vrf_id);
3721 memcpy(mp->src_address, &src_address, sizeof (src_address));
3722 memcpy(mp->dst_address, &dst_address, sizeof (dst_address));
3723 memcpy(mp->intfc_address, &intfc_address, sizeof (intfc_address));
3724 mp->intfc_address_length = intfc_address_length;
3725 mp->l2_only = l2_only;
3726 mp->is_add = is_add;
3733 static int api_mpls_ethernet_add_del_tunnel (vat_main_t * vam)
3735 unformat_input_t * i = vam->input;
3736 vl_api_mpls_ethernet_add_del_tunnel_t *mp;
3738 u32 inner_vrf_id = 0;
3739 ip4_address_t intfc_address;
3740 u8 dst_mac_address[6];
3743 u8 intfc_address_length = 0;
3747 int tx_sw_if_index_set = 0;
3749 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
3750 if (unformat (i, "vrf %d", &inner_vrf_id))
3752 else if (unformat (i, "adj %U/%d", unformat_ip4_address,
3753 &intfc_address, &tmp))
3754 intfc_address_length = tmp;
3755 else if (unformat (i, "%U",
3756 unformat_sw_if_index, vam, &tx_sw_if_index))
3757 tx_sw_if_index_set = 1;
3758 else if (unformat (i, "tx_sw_if_index %d", &tx_sw_if_index))
3759 tx_sw_if_index_set = 1;
3760 else if (unformat (i, "dst %U", unformat_ethernet_address,
3763 else if (unformat (i, "l2-only"))
3765 else if (unformat (i, "del"))
3768 clib_warning ("parse error '%U'", format_unformat_error, i);
3774 errmsg ("dst (mac address) not set\n");
3777 if (!tx_sw_if_index_set) {
3778 errmsg ("tx-intfc not set\n");
3782 M(MPLS_ETHERNET_ADD_DEL_TUNNEL, mpls_ethernet_add_del_tunnel);
3784 mp->vrf_id = ntohl(inner_vrf_id);
3785 memcpy (mp->adj_address, &intfc_address, sizeof (intfc_address));
3786 mp->adj_address_length = intfc_address_length;
3787 memcpy (mp->dst_mac_address, dst_mac_address, sizeof (dst_mac_address));
3788 mp->tx_sw_if_index = ntohl(tx_sw_if_index);
3789 mp->l2_only = l2_only;
3790 mp->is_add = is_add;
3797 static int api_mpls_ethernet_add_del_tunnel_2 (vat_main_t * vam)
3799 unformat_input_t * i = vam->input;
3800 vl_api_mpls_ethernet_add_del_tunnel_2_t *mp;
3802 u32 inner_vrf_id = 0;
3803 u32 outer_vrf_id = 0;
3804 ip4_address_t adj_address;
3805 int adj_address_set = 0;
3806 ip4_address_t next_hop_address;
3807 int next_hop_address_set = 0;
3809 u8 adj_address_length = 0;
3812 u32 resolve_attempts = 5;
3813 u8 resolve_if_needed = 1;
3815 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
3816 if (unformat (i, "inner_vrf_id %d", &inner_vrf_id))
3818 else if (unformat (i, "outer_vrf_id %d", &outer_vrf_id))
3820 else if (unformat (i, "adj %U/%d", unformat_ip4_address,
3821 &adj_address, &tmp)) {
3822 adj_address_length = tmp;
3823 adj_address_set = 1;
3825 else if (unformat (i, "next-hop %U", unformat_ip4_address,
3827 next_hop_address_set = 1;
3828 else if (unformat (i, "resolve-attempts %d", &resolve_attempts))
3830 else if (unformat (i, "resolve-if-needed %d", &tmp))
3831 resolve_if_needed = tmp;
3832 else if (unformat (i, "l2-only"))
3834 else if (unformat (i, "del"))
3837 clib_warning ("parse error '%U'", format_unformat_error, i);
3842 if (!adj_address_set) {
3843 errmsg ("adjacency address/mask not set\n");
3846 if (!next_hop_address_set) {
3847 errmsg ("ip4 next hop address (in outer fib) not set\n");
3851 M(MPLS_ETHERNET_ADD_DEL_TUNNEL_2, mpls_ethernet_add_del_tunnel_2);
3853 mp->inner_vrf_id = ntohl(inner_vrf_id);
3854 mp->outer_vrf_id = ntohl(outer_vrf_id);
3855 mp->resolve_attempts = ntohl(resolve_attempts);
3856 mp->resolve_if_needed = resolve_if_needed;
3857 mp->is_add = is_add;
3858 mp->l2_only = l2_only;
3859 memcpy (mp->adj_address, &adj_address, sizeof (adj_address));
3860 mp->adj_address_length = adj_address_length;
3861 memcpy (mp->next_hop_ip4_address_in_outer_vrf, &next_hop_address,
3862 sizeof (next_hop_address));
3869 static int api_sw_interface_set_unnumbered (vat_main_t * vam)
3871 unformat_input_t * i = vam->input;
3872 vl_api_sw_interface_set_unnumbered_t *mp;
3877 u8 sw_if_index_set = 0;
3879 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
3880 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
3881 sw_if_index_set = 1;
3882 else if (unformat (i, "sw_if_index %d", &sw_if_index))
3883 sw_if_index_set = 1;
3884 else if (unformat (i, "unnum_if_index %d", &unnum_sw_index))
3886 else if (unformat (i, "del"))
3889 clib_warning ("parse error '%U'", format_unformat_error, i);
3894 if (sw_if_index_set == 0) {
3895 errmsg ("missing interface name or sw_if_index\n");
3899 M(SW_INTERFACE_SET_UNNUMBERED, sw_interface_set_unnumbered);
3901 mp->sw_if_index = ntohl(sw_if_index);
3902 mp->unnumbered_sw_if_index = ntohl(unnum_sw_index);
3903 mp->is_add = is_add;
3910 static int api_ip_neighbor_add_del (vat_main_t * vam)
3912 unformat_input_t * i = vam->input;
3913 vl_api_ip_neighbor_add_del_t *mp;
3916 u8 sw_if_index_set = 0;
3922 u8 v4_address_set = 0;
3923 u8 v6_address_set = 0;
3924 ip4_address_t v4address;
3925 ip6_address_t v6address;
3927 memset (mac_address, 0, sizeof (mac_address));
3929 /* Parse args required to build the message */
3930 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
3931 if (unformat (i, "mac %U", unformat_ethernet_address, mac_address)) {
3934 else if (unformat (i, "del"))
3936 else if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
3937 sw_if_index_set = 1;
3938 else if (unformat (i, "sw_if_index %d", &sw_if_index))
3939 sw_if_index_set = 1;
3940 else if (unformat (i, "is_static"))
3942 else if (unformat (i, "vrf %d", &vrf_id))
3944 else if (unformat (i, "dst %U",
3945 unformat_ip4_address, &v4address))
3947 else if (unformat (i, "dst %U",
3948 unformat_ip6_address, &v6address))
3951 clib_warning ("parse error '%U'", format_unformat_error, i);
3956 if (sw_if_index_set == 0) {
3957 errmsg ("missing interface name or sw_if_index\n");
3960 if (v4_address_set && v6_address_set) {
3961 errmsg ("both v4 and v6 addresses set\n");
3964 if (!v4_address_set && !v6_address_set) {
3965 errmsg ("no addresses set\n");
3969 /* Construct the API message */
3970 M(IP_NEIGHBOR_ADD_DEL, ip_neighbor_add_del);
3972 mp->sw_if_index = ntohl (sw_if_index);
3973 mp->is_add = is_add;
3974 mp->vrf_id = ntohl (vrf_id);
3975 mp->is_static = is_static;
3977 memcpy (mp->mac_address, mac_address, 6);
3978 if (v6_address_set) {
3980 memcpy (mp->dst_address, &v6address, sizeof (v6address));
3982 /* mp->is_ipv6 = 0; via memset in M macro above */
3983 memcpy (mp->dst_address, &v4address, sizeof (v4address));
3989 /* Wait for a reply, return good/bad news */
3996 static int api_reset_vrf (vat_main_t * vam)
3998 unformat_input_t * i = vam->input;
3999 vl_api_reset_vrf_t *mp;
4005 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
4006 if (unformat (i, "vrf %d", &vrf_id))
4008 else if (unformat (i, "ipv6"))
4011 clib_warning ("parse error '%U'", format_unformat_error, i);
4016 if (vrf_id_set == 0) {
4017 errmsg ("missing vrf id\n");
4021 M(RESET_VRF, reset_vrf);
4023 mp->vrf_id = ntohl(vrf_id);
4024 mp->is_ipv6 = is_ipv6;
4031 static int api_create_vlan_subif (vat_main_t * vam)
4033 unformat_input_t * i = vam->input;
4034 vl_api_create_vlan_subif_t *mp;
4037 u8 sw_if_index_set = 0;
4041 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
4042 if (unformat (i, "sw_if_index %d", &sw_if_index))
4043 sw_if_index_set = 1;
4044 else if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
4045 sw_if_index_set = 1;
4046 else if (unformat (i, "vlan %d", &vlan_id))
4049 clib_warning ("parse error '%U'", format_unformat_error, i);
4054 if (sw_if_index_set == 0) {
4055 errmsg ("missing interface name or sw_if_index\n");
4059 if (vlan_id_set == 0) {
4060 errmsg ("missing vlan_id\n");
4063 M(CREATE_VLAN_SUBIF, create_vlan_subif);
4065 mp->sw_if_index = ntohl(sw_if_index);
4066 mp->vlan_id = ntohl(vlan_id);
4073 #define foreach_create_subif_bit \
4080 _(outer_vlan_id_any) \
4081 _(inner_vlan_id_any)
4083 static int api_create_subif (vat_main_t * vam)
4085 unformat_input_t * i = vam->input;
4086 vl_api_create_subif_t *mp;
4089 u8 sw_if_index_set = 0;
4096 u32 exact_match = 0;
4097 u32 default_sub = 0;
4098 u32 outer_vlan_id_any = 0;
4099 u32 inner_vlan_id_any = 0;
4101 u16 outer_vlan_id = 0;
4102 u16 inner_vlan_id = 0;
4104 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
4105 if (unformat (i, "sw_if_index %d", &sw_if_index))
4106 sw_if_index_set = 1;
4107 else if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
4108 sw_if_index_set = 1;
4109 else if (unformat (i, "sub_id %d", &sub_id))
4111 else if (unformat (i, "outer_vlan_id %d", &tmp))
4112 outer_vlan_id = tmp;
4113 else if (unformat (i, "inner_vlan_id %d", &tmp))
4114 inner_vlan_id = tmp;
4116 #define _(a) else if (unformat (i, #a)) a = 1 ;
4117 foreach_create_subif_bit
4121 clib_warning ("parse error '%U'", format_unformat_error, i);
4126 if (sw_if_index_set == 0) {
4127 errmsg ("missing interface name or sw_if_index\n");
4131 if (sub_id_set == 0) {
4132 errmsg ("missing sub_id\n");
4135 M(CREATE_SUBIF, create_subif);
4137 mp->sw_if_index = ntohl(sw_if_index);
4138 mp->sub_id = ntohl(sub_id);
4140 #define _(a) mp->a = a;
4141 foreach_create_subif_bit;
4144 mp->outer_vlan_id = ntohs (outer_vlan_id);
4145 mp->inner_vlan_id = ntohs (inner_vlan_id);
4152 static int api_oam_add_del (vat_main_t * vam)
4154 unformat_input_t * i = vam->input;
4155 vl_api_oam_add_del_t *mp;
4159 ip4_address_t src, dst;
4163 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
4164 if (unformat (i, "vrf %d", &vrf_id))
4166 else if (unformat (i, "src %U", unformat_ip4_address, &src))
4168 else if (unformat (i, "dst %U", unformat_ip4_address, &dst))
4170 else if (unformat (i, "del"))
4173 clib_warning ("parse error '%U'", format_unformat_error, i);
4179 errmsg ("missing src addr\n");
4184 errmsg ("missing dst addr\n");
4188 M(OAM_ADD_DEL, oam_add_del);
4190 mp->vrf_id = ntohl(vrf_id);
4191 mp->is_add = is_add;
4192 memcpy(mp->src_address, &src, sizeof (mp->src_address));
4193 memcpy(mp->dst_address, &dst, sizeof (mp->dst_address));
4200 static int api_reset_fib (vat_main_t * vam)
4202 unformat_input_t * i = vam->input;
4203 vl_api_reset_fib_t *mp;
4209 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
4210 if (unformat (i, "vrf %d", &vrf_id))
4212 else if (unformat (i, "ipv6"))
4215 clib_warning ("parse error '%U'", format_unformat_error, i);
4220 if (vrf_id_set == 0) {
4221 errmsg ("missing vrf id\n");
4225 M(RESET_FIB, reset_fib);
4227 mp->vrf_id = ntohl(vrf_id);
4228 mp->is_ipv6 = is_ipv6;
4235 static int api_dhcp_proxy_config (vat_main_t * vam)
4237 unformat_input_t * i = vam->input;
4238 vl_api_dhcp_proxy_config_t *mp;
4243 u8 v4_address_set = 0;
4244 u8 v6_address_set = 0;
4245 ip4_address_t v4address;
4246 ip6_address_t v6address;
4247 u8 v4_src_address_set = 0;
4248 u8 v6_src_address_set = 0;
4249 ip4_address_t v4srcaddress;
4250 ip6_address_t v6srcaddress;
4252 /* Parse args required to build the message */
4253 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
4254 if (unformat (i, "del"))
4256 else if (unformat (i, "vrf %d", &vrf_id))
4258 else if (unformat (i, "insert-cid %d", &insert_cid))
4260 else if (unformat (i, "svr %U",
4261 unformat_ip4_address, &v4address))
4263 else if (unformat (i, "svr %U",
4264 unformat_ip6_address, &v6address))
4266 else if (unformat (i, "src %U",
4267 unformat_ip4_address, &v4srcaddress))
4268 v4_src_address_set = 1;
4269 else if (unformat (i, "src %U",
4270 unformat_ip6_address, &v6srcaddress))
4271 v6_src_address_set = 1;
4276 if (v4_address_set && v6_address_set) {
4277 errmsg ("both v4 and v6 server addresses set\n");
4280 if (!v4_address_set && !v6_address_set) {
4281 errmsg ("no server addresses set\n");
4285 if (v4_src_address_set && v6_src_address_set) {
4286 errmsg ("both v4 and v6 src addresses set\n");
4289 if (!v4_src_address_set && !v6_src_address_set) {
4290 errmsg ("no src addresses set\n");
4294 if (!(v4_src_address_set && v4_address_set) &&
4295 !(v6_src_address_set && v6_address_set)) {
4296 errmsg ("no matching server and src addresses set\n");
4300 /* Construct the API message */
4301 M(DHCP_PROXY_CONFIG, dhcp_proxy_config);
4303 mp->insert_circuit_id = insert_cid;
4304 mp->is_add = is_add;
4305 mp->vrf_id = ntohl (vrf_id);
4306 if (v6_address_set) {
4308 memcpy (mp->dhcp_server, &v6address, sizeof (v6address));
4309 memcpy (mp->dhcp_src_address, &v6srcaddress, sizeof (v6address));
4311 memcpy (mp->dhcp_server, &v4address, sizeof (v4address));
4312 memcpy (mp->dhcp_src_address, &v4srcaddress, sizeof (v4address));
4318 /* Wait for a reply, return good/bad news */
4324 static int api_dhcp_proxy_config_2 (vat_main_t * vam)
4326 unformat_input_t * i = vam->input;
4327 vl_api_dhcp_proxy_config_2_t *mp;
4330 u32 server_vrf_id = 0;
4333 u8 v4_address_set = 0;
4334 u8 v6_address_set = 0;
4335 ip4_address_t v4address;
4336 ip6_address_t v6address;
4337 u8 v4_src_address_set = 0;
4338 u8 v6_src_address_set = 0;
4339 ip4_address_t v4srcaddress;
4340 ip6_address_t v6srcaddress;
4342 /* Parse args required to build the message */
4343 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
4344 if (unformat (i, "del"))
4346 else if (unformat (i, "rx_vrf_id %d", &rx_vrf_id))
4348 else if (unformat (i, "server_vrf_id %d", &server_vrf_id))
4350 else if (unformat (i, "insert-cid %d", &insert_cid))
4352 else if (unformat (i, "svr %U",
4353 unformat_ip4_address, &v4address))
4355 else if (unformat (i, "svr %U",
4356 unformat_ip6_address, &v6address))
4358 else if (unformat (i, "src %U",
4359 unformat_ip4_address, &v4srcaddress))
4360 v4_src_address_set = 1;
4361 else if (unformat (i, "src %U",
4362 unformat_ip6_address, &v6srcaddress))
4363 v6_src_address_set = 1;
4368 if (v4_address_set && v6_address_set) {
4369 errmsg ("both v4 and v6 server addresses set\n");
4372 if (!v4_address_set && !v6_address_set) {
4373 errmsg ("no server addresses set\n");
4377 if (v4_src_address_set && v6_src_address_set) {
4378 errmsg ("both v4 and v6 src addresses set\n");
4381 if (!v4_src_address_set && !v6_src_address_set) {
4382 errmsg ("no src addresses set\n");
4386 if (!(v4_src_address_set && v4_address_set) &&
4387 !(v6_src_address_set && v6_address_set)) {
4388 errmsg ("no matching server and src addresses set\n");
4392 /* Construct the API message */
4393 M(DHCP_PROXY_CONFIG_2, dhcp_proxy_config_2);
4395 mp->insert_circuit_id = insert_cid;
4396 mp->is_add = is_add;
4397 mp->rx_vrf_id = ntohl (rx_vrf_id);
4398 mp->server_vrf_id = ntohl (server_vrf_id);
4399 if (v6_address_set) {
4401 memcpy (mp->dhcp_server, &v6address, sizeof (v6address));
4402 memcpy (mp->dhcp_src_address, &v6srcaddress, sizeof (v6address));
4404 memcpy (mp->dhcp_server, &v4address, sizeof (v4address));
4405 memcpy (mp->dhcp_src_address, &v4srcaddress, sizeof (v4address));
4411 /* Wait for a reply, return good/bad news */
4417 static int api_dhcp_proxy_set_vss (vat_main_t * vam)
4419 unformat_input_t * i = vam->input;
4420 vl_api_dhcp_proxy_set_vss_t *mp;
4431 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
4432 if (unformat (i, "tbl_id %d", &tbl_id))
4434 if (unformat (i, "fib_id %d", &fib_id))
4436 if (unformat (i, "oui %d", &oui))
4438 else if (unformat (i, "ipv6"))
4440 else if (unformat (i, "del"))
4443 clib_warning ("parse error '%U'", format_unformat_error, i);
4448 if (tbl_id_set == 0) {
4449 errmsg ("missing tbl id\n");
4453 if (fib_id_set == 0) {
4454 errmsg ("missing fib id\n");
4458 errmsg ("missing oui\n");
4462 M(DHCP_PROXY_SET_VSS, dhcp_proxy_set_vss);
4463 mp->tbl_id = ntohl(tbl_id);
4464 mp->fib_id = ntohl(fib_id);
4465 mp->oui = ntohl(oui);
4466 mp->is_ipv6 = is_ipv6;
4467 mp->is_add = is_add;
4474 static int api_dhcp_client_config (vat_main_t * vam)
4476 unformat_input_t * i = vam->input;
4477 vl_api_dhcp_client_config_t *mp;
4480 u8 sw_if_index_set = 0;
4483 u8 disable_event = 0;
4485 /* Parse args required to build the message */
4486 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
4487 if (unformat (i, "del"))
4489 else if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
4490 sw_if_index_set = 1;
4491 else if (unformat (i, "sw_if_index %d", &sw_if_index))
4492 sw_if_index_set = 1;
4493 else if (unformat (i, "hostname %s", &hostname))
4495 else if (unformat (i, "disable_event"))
4501 if (sw_if_index_set == 0) {
4502 errmsg ("missing interface name or sw_if_index\n");
4506 if (vec_len (hostname) > 63) {
4507 errmsg ("hostname too long\n");
4509 vec_add1 (hostname, 0);
4511 /* Construct the API message */
4512 M(DHCP_CLIENT_CONFIG, dhcp_client_config);
4514 mp->sw_if_index = ntohl (sw_if_index);
4515 memcpy (mp->hostname, hostname, vec_len (hostname));
4516 vec_free (hostname);
4517 mp->is_add = is_add;
4518 mp->want_dhcp_event = disable_event ? 0 : 1;
4524 /* Wait for a reply, return good/bad news */
4530 static int api_set_ip_flow_hash (vat_main_t * vam)
4532 unformat_input_t * i = vam->input;
4533 vl_api_set_ip_flow_hash_t *mp;
4545 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
4546 if (unformat (i, "vrf %d", &vrf_id))
4548 else if (unformat (i, "ipv6"))
4550 else if (unformat (i, "src"))
4552 else if (unformat (i, "dst"))
4554 else if (unformat (i, "sport"))
4556 else if (unformat (i, "dport"))
4558 else if (unformat (i, "proto"))
4560 else if (unformat (i, "reverse"))
4564 clib_warning ("parse error '%U'", format_unformat_error, i);
4569 if (vrf_id_set == 0) {
4570 errmsg ("missing vrf id\n");
4574 M(SET_IP_FLOW_HASH, set_ip_flow_hash);
4580 mp->reverse = reverse;
4581 mp->vrf_id = ntohl(vrf_id);
4582 mp->is_ipv6 = is_ipv6;
4589 static int api_sw_interface_ip6_enable_disable (vat_main_t * vam)
4591 unformat_input_t * i = vam->input;
4592 vl_api_sw_interface_ip6_enable_disable_t *mp;
4595 u8 sw_if_index_set = 0;
4598 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
4599 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
4600 sw_if_index_set = 1;
4601 else if (unformat (i, "sw_if_index %d", &sw_if_index))
4602 sw_if_index_set = 1;
4603 else if (unformat (i, "enable"))
4605 else if (unformat (i, "disable"))
4608 clib_warning ("parse error '%U'", format_unformat_error, i);
4613 if (sw_if_index_set == 0) {
4614 errmsg ("missing interface name or sw_if_index\n");
4618 M(SW_INTERFACE_IP6_ENABLE_DISABLE, sw_interface_ip6_enable_disable);
4620 mp->sw_if_index = ntohl(sw_if_index);
4621 mp->enable = enable;
4628 static int api_sw_interface_ip6_set_link_local_address (vat_main_t * vam)
4630 unformat_input_t * i = vam->input;
4631 vl_api_sw_interface_ip6_set_link_local_address_t *mp;
4634 u8 sw_if_index_set = 0;
4635 u32 address_length = 0;
4636 u8 v6_address_set = 0;
4637 ip6_address_t v6address;
4639 /* Parse args required to build the message */
4640 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
4641 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
4642 sw_if_index_set = 1;
4643 else if (unformat (i, "sw_if_index %d", &sw_if_index))
4644 sw_if_index_set = 1;
4645 else if (unformat (i, "%U/%d",
4646 unformat_ip6_address, &v6address,
4653 if (sw_if_index_set == 0) {
4654 errmsg ("missing interface name or sw_if_index\n");
4657 if (!v6_address_set) {
4658 errmsg ("no address set\n");
4662 /* Construct the API message */
4663 M(SW_INTERFACE_IP6_SET_LINK_LOCAL_ADDRESS, \
4664 sw_interface_ip6_set_link_local_address);
4666 mp->sw_if_index = ntohl (sw_if_index);
4667 memcpy (mp->address, &v6address, sizeof (v6address));
4668 mp->address_length = address_length;
4673 /* Wait for a reply, return good/bad news */
4681 static int api_sw_interface_ip6nd_ra_prefix (vat_main_t * vam)
4683 unformat_input_t * i = vam->input;
4684 vl_api_sw_interface_ip6nd_ra_prefix_t *mp;
4687 u8 sw_if_index_set = 0;
4688 u32 address_length = 0;
4689 u8 v6_address_set = 0;
4690 ip6_address_t v6address;
4692 u8 no_advertise = 0;
4694 u8 no_autoconfig = 0;
4697 u32 val_lifetime = 0;
4698 u32 pref_lifetime = 0;
4700 /* Parse args required to build the message */
4701 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
4702 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
4703 sw_if_index_set = 1;
4704 else if (unformat (i, "sw_if_index %d", &sw_if_index))
4705 sw_if_index_set = 1;
4706 else if (unformat (i, "%U/%d",
4707 unformat_ip6_address, &v6address,
4710 else if (unformat (i, "val_life %d", &val_lifetime))
4712 else if (unformat (i, "pref_life %d", &pref_lifetime))
4714 else if (unformat (i, "def"))
4716 else if (unformat (i, "noadv"))
4718 else if (unformat (i, "offl"))
4720 else if (unformat (i, "noauto"))
4722 else if (unformat (i, "nolink"))
4724 else if (unformat (i, "isno"))
4727 clib_warning ("parse error '%U'", format_unformat_error, i);
4732 if (sw_if_index_set == 0) {
4733 errmsg ("missing interface name or sw_if_index\n");
4736 if (!v6_address_set) {
4737 errmsg ("no address set\n");
4741 /* Construct the API message */
4742 M(SW_INTERFACE_IP6ND_RA_PREFIX, sw_interface_ip6nd_ra_prefix);
4744 mp->sw_if_index = ntohl (sw_if_index);
4745 memcpy (mp->address, &v6address, sizeof (v6address));
4746 mp->address_length = address_length;
4747 mp->use_default = use_default;
4748 mp->no_advertise = no_advertise;
4749 mp->off_link = off_link;
4750 mp->no_autoconfig = no_autoconfig;
4751 mp->no_onlink = no_onlink;
4753 mp->val_lifetime = ntohl(val_lifetime);
4754 mp->pref_lifetime = ntohl(pref_lifetime);
4759 /* Wait for a reply, return good/bad news */
4766 static int api_sw_interface_ip6nd_ra_config (vat_main_t * vam)
4768 unformat_input_t * i = vam->input;
4769 vl_api_sw_interface_ip6nd_ra_config_t *mp;
4772 u8 sw_if_index_set = 0;
4777 u8 send_unicast = 0;
4780 u8 default_router = 0;
4781 u32 max_interval = 0;
4782 u32 min_interval = 0;
4784 u32 initial_count = 0;
4785 u32 initial_interval = 0;
4788 /* Parse args required to build the message */
4789 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
4790 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
4791 sw_if_index_set = 1;
4792 else if (unformat (i, "sw_if_index %d", &sw_if_index))
4793 sw_if_index_set = 1;
4794 else if (unformat (i, "maxint %d", &max_interval))
4796 else if (unformat (i, "minint %d", &min_interval))
4798 else if (unformat (i, "life %d", &lifetime))
4800 else if (unformat (i, "count %d", &initial_count))
4802 else if (unformat (i, "interval %d", &initial_interval))
4804 else if (unformat (i, "surpress"))
4806 else if (unformat (i, "managed"))
4808 else if (unformat (i, "other"))
4810 else if (unformat (i, "ll"))
4812 else if (unformat (i, "send"))
4814 else if (unformat (i, "cease"))
4816 else if (unformat (i, "isno"))
4818 else if (unformat (i, "def"))
4821 clib_warning ("parse error '%U'", format_unformat_error, i);
4826 if (sw_if_index_set == 0) {
4827 errmsg ("missing interface name or sw_if_index\n");
4831 /* Construct the API message */
4832 M(SW_INTERFACE_IP6ND_RA_CONFIG, sw_interface_ip6nd_ra_config);
4834 mp->sw_if_index = ntohl (sw_if_index);
4835 mp->max_interval = ntohl(max_interval);
4836 mp->min_interval = ntohl(min_interval);
4837 mp->lifetime = ntohl(lifetime);
4838 mp->initial_count = ntohl(initial_count);
4839 mp->initial_interval = ntohl(initial_interval);
4840 mp->surpress = surpress;
4841 mp->managed = managed;
4843 mp->ll_option = ll_option;
4844 mp->send_unicast = send_unicast;
4847 mp->default_router = default_router;
4852 /* Wait for a reply, return good/bad news */
4859 static int api_set_arp_neighbor_limit (vat_main_t * vam)
4861 unformat_input_t * i = vam->input;
4862 vl_api_set_arp_neighbor_limit_t *mp;
4868 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
4869 if (unformat (i, "arp_nbr_limit %d", &arp_nbr_limit))
4871 else if (unformat (i, "ipv6"))
4874 clib_warning ("parse error '%U'", format_unformat_error, i);
4879 if (limit_set == 0) {
4880 errmsg ("missing limit value\n");
4884 M(SET_ARP_NEIGHBOR_LIMIT, set_arp_neighbor_limit);
4886 mp->arp_neighbor_limit = ntohl(arp_nbr_limit);
4887 mp->is_ipv6 = is_ipv6;
4894 static int api_l2_patch_add_del (vat_main_t * vam)
4896 unformat_input_t * i = vam->input;
4897 vl_api_l2_patch_add_del_t *mp;
4900 u8 rx_sw_if_index_set = 0;
4902 u8 tx_sw_if_index_set = 0;
4905 /* Parse args required to build the message */
4906 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
4907 if (unformat (i, "rx_sw_if_index %d", &rx_sw_if_index))
4908 rx_sw_if_index_set = 1;
4909 else if (unformat (i, "tx_sw_if_index %d", &tx_sw_if_index))
4910 tx_sw_if_index_set = 1;
4911 else if (unformat (i, "rx")) {
4912 if (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
4913 if (unformat (i, "%U", unformat_sw_if_index, vam,
4915 rx_sw_if_index_set = 1;
4918 } else if (unformat (i, "tx")) {
4919 if (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
4920 if (unformat (i, "%U", unformat_sw_if_index, vam,
4922 tx_sw_if_index_set = 1;
4925 } else if (unformat (i, "del"))
4931 if (rx_sw_if_index_set == 0) {
4932 errmsg ("missing rx interface name or rx_sw_if_index\n");
4936 if (tx_sw_if_index_set == 0) {
4937 errmsg ("missing tx interface name or tx_sw_if_index\n");
4941 M(L2_PATCH_ADD_DEL, l2_patch_add_del);
4943 mp->rx_sw_if_index = ntohl(rx_sw_if_index);
4944 mp->tx_sw_if_index = ntohl(tx_sw_if_index);
4945 mp->is_add = is_add;
4952 static int api_sr_tunnel_add_del (vat_main_t * vam)
4954 unformat_input_t * i = vam->input;
4955 vl_api_sr_tunnel_add_del_t *mp;
4959 ip6_address_t src_address;
4960 int src_address_set = 0;
4961 ip6_address_t dst_address;
4963 int dst_address_set = 0;
4965 u32 rx_table_id = 0;
4966 u32 tx_table_id = 0;
4967 ip6_address_t * segments = 0;
4968 ip6_address_t * this_seg;
4969 ip6_address_t * tags = 0;
4970 ip6_address_t * this_tag;
4971 ip6_address_t next_address, tag;
4973 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
4975 if (unformat (i, "del"))
4977 else if (unformat (i, "rx_fib_id %d", &rx_table_id))
4979 else if (unformat (i, "tx_fib_id %d", &tx_table_id))
4981 else if (unformat (i, "src %U", unformat_ip6_address, &src_address))
4982 src_address_set = 1;
4983 else if (unformat (i, "dst %U/%d",
4984 unformat_ip6_address, &dst_address,
4986 dst_address_set = 1;
4987 else if (unformat (i, "next %U", unformat_ip6_address,
4990 vec_add2 (segments, this_seg, 1);
4991 memcpy (this_seg->as_u8, next_address.as_u8, sizeof (*this_seg));
4993 else if (unformat (i, "tag %U", unformat_ip6_address,
4996 vec_add2 (tags, this_tag, 1);
4997 memcpy (this_tag->as_u8, tag.as_u8, sizeof (*this_tag));
4999 else if (unformat (i, "clean"))
5000 flags |= IP6_SR_HEADER_FLAG_CLEANUP;
5001 else if (unformat (i, "protected"))
5002 flags |= IP6_SR_HEADER_FLAG_PROTECTED;
5003 else if (unformat (i, "InPE %d", &pl_index))
5005 if (pl_index <= 0 || pl_index > 4)
5007 pl_index_range_error:
5008 errmsg ("pl index %d out of range\n", pl_index);
5011 flags |= IP6_SR_HEADER_FLAG_PL_ELT_INGRESS_PE << (3*(pl_index - 1));
5013 else if (unformat (i, "EgPE %d", &pl_index))
5015 if (pl_index <= 0 || pl_index > 4)
5016 goto pl_index_range_error;
5017 flags |= IP6_SR_HEADER_FLAG_PL_ELT_EGRESS_PE << (3*(pl_index - 1));
5019 else if (unformat (i, "OrgSrc %d", &pl_index))
5021 if (pl_index <= 0 || pl_index > 4)
5022 goto pl_index_range_error;
5023 flags |= IP6_SR_HEADER_FLAG_PL_ELT_ORIG_SRC_ADDR << (3*(pl_index - 1));
5029 if (!src_address_set)
5031 errmsg ("src address required\n");
5035 if (!dst_address_set)
5037 errmsg ("dst address required\n");
5043 errmsg ("at least one sr segment required\n");
5047 M2(SR_TUNNEL_ADD_DEL, sr_tunnel_add_del,
5048 vec_len(segments) * sizeof (ip6_address_t)
5049 + vec_len(tags) * sizeof (ip6_address_t));
5051 memcpy (mp->src_address, &src_address, sizeof (mp->src_address));
5052 memcpy (mp->dst_address, &dst_address, sizeof (mp->dst_address));
5053 mp->dst_mask_width = dst_mask_width;
5054 mp->flags_net_byte_order = clib_host_to_net_u16 (flags);
5055 mp->n_segments = vec_len (segments);
5056 mp->n_tags = vec_len (tags);
5057 mp->is_add = is_del == 0;
5058 memcpy (mp->segs_and_tags, segments,
5059 vec_len(segments)* sizeof (ip6_address_t));
5060 memcpy (mp->segs_and_tags + vec_len(segments)*sizeof (ip6_address_t),
5061 tags, vec_len(tags)* sizeof (ip6_address_t));
5063 mp->outer_vrf_id = ntohl (rx_table_id);
5064 mp->inner_vrf_id = ntohl (tx_table_id);
5066 vec_free (segments);
5074 #define foreach_ip4_proto_field \
5084 uword unformat_ip4_mask (unformat_input_t * input, va_list * args)
5086 u8 ** maskp = va_arg (*args, u8 **);
5088 u8 found_something = 0;
5091 #define _(a) u8 a=0;
5092 foreach_ip4_proto_field;
5098 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
5100 if (unformat (input, "version"))
5102 else if (unformat (input, "hdr_length"))
5104 else if (unformat (input, "src"))
5106 else if (unformat (input, "dst"))
5108 else if (unformat (input, "proto"))
5111 #define _(a) else if (unformat (input, #a)) a=1;
5112 foreach_ip4_proto_field
5118 #define _(a) found_something += a;
5119 foreach_ip4_proto_field;
5122 if (found_something == 0)
5125 vec_validate (mask, sizeof (*ip) - 1);
5127 ip = (ip4_header_t *) mask;
5129 #define _(a) if (a) memset (&ip->a, 0xff, sizeof (ip->a));
5130 foreach_ip4_proto_field;
5133 ip->ip_version_and_header_length = 0;
5136 ip->ip_version_and_header_length |= 0xF0;
5139 ip->ip_version_and_header_length |= 0x0F;
5145 #define foreach_ip6_proto_field \
5152 uword unformat_ip6_mask (unformat_input_t * input, va_list * args)
5154 u8 ** maskp = va_arg (*args, u8 **);
5156 u8 found_something = 0;
5158 u32 ip_version_traffic_class_and_flow_label;
5160 #define _(a) u8 a=0;
5161 foreach_ip6_proto_field;
5164 u8 traffic_class = 0;
5167 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
5169 if (unformat (input, "version"))
5171 else if (unformat (input, "traffic-class"))
5173 else if (unformat (input, "flow-label"))
5175 else if (unformat (input, "src"))
5177 else if (unformat (input, "dst"))
5179 else if (unformat (input, "proto"))
5182 #define _(a) else if (unformat (input, #a)) a=1;
5183 foreach_ip6_proto_field
5189 #define _(a) found_something += a;
5190 foreach_ip6_proto_field;
5193 if (found_something == 0)
5196 vec_validate (mask, sizeof (*ip) - 1);
5198 ip = (ip6_header_t *) mask;
5200 #define _(a) if (a) memset (&ip->a, 0xff, sizeof (ip->a));
5201 foreach_ip6_proto_field;
5204 ip_version_traffic_class_and_flow_label = 0;
5207 ip_version_traffic_class_and_flow_label |= 0xF0000000;
5210 ip_version_traffic_class_and_flow_label |= 0x0FF00000;
5213 ip_version_traffic_class_and_flow_label |= 0x000FFFFF;
5215 ip->ip_version_traffic_class_and_flow_label =
5216 clib_host_to_net_u32 (ip_version_traffic_class_and_flow_label);
5222 uword unformat_l3_mask (unformat_input_t * input, va_list * args)
5224 u8 ** maskp = va_arg (*args, u8 **);
5226 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) {
5227 if (unformat (input, "ip4 %U", unformat_ip4_mask, maskp))
5229 else if (unformat (input, "ip6 %U", unformat_ip6_mask, maskp))
5237 uword unformat_l2_mask (unformat_input_t * input, va_list * args)
5239 u8 ** maskp = va_arg (*args, u8 **);
5254 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) {
5255 if (unformat (input, "src"))
5257 else if (unformat (input, "dst"))
5259 else if (unformat (input, "proto"))
5261 else if (unformat (input, "tag1"))
5263 else if (unformat (input, "tag2"))
5265 else if (unformat (input, "ignore-tag1"))
5267 else if (unformat (input, "ignore-tag2"))
5269 else if (unformat (input, "cos1"))
5271 else if (unformat (input, "cos2"))
5273 else if (unformat (input, "dot1q"))
5275 else if (unformat (input, "dot1ad"))
5280 if ((src + dst + proto + tag1 + tag2 + dot1q + dot1ad +
5281 ignore_tag1 + ignore_tag2 + cos1 + cos2) == 0)
5284 if (tag1 || ignore_tag1 || cos1 || dot1q)
5286 if (tag2 || ignore_tag2 || cos2 || dot1ad)
5289 vec_validate (mask, len-1);
5292 memset (mask, 0xff, 6);
5295 memset (mask + 6, 0xff, 6);
5299 /* inner vlan tag */
5308 mask[21] = mask [20] = 0xff;
5329 mask[16] = mask [17] = 0xff;
5339 mask[12] = mask [13] = 0xff;
5345 uword unformat_classify_mask (unformat_input_t * input, va_list * args)
5347 u8 ** maskp = va_arg (*args, u8 **);
5348 u32 * skipp = va_arg (*args, u32 *);
5349 u32 * matchp = va_arg (*args, u32 *);
5356 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) {
5357 if (unformat (input, "hex %U", unformat_hex_string, &mask))
5359 else if (unformat (input, "l2 %U", unformat_l2_mask, &l2))
5361 else if (unformat (input, "l3 %U", unformat_l3_mask, &l3))
5367 if (mask || l2 || l3)
5371 /* "With a free Ethernet header in every package" */
5373 vec_validate (l2, 13);
5375 vec_append (mask, l3);
5379 /* Scan forward looking for the first significant mask octet */
5380 for (i = 0; i < vec_len (mask); i++)
5384 /* compute (skip, match) params */
5385 *skipp = i / sizeof(u32x4);
5386 vec_delete (mask, *skipp * sizeof(u32x4), 0);
5388 /* Pad mask to an even multiple of the vector size */
5389 while (vec_len (mask) % sizeof (u32x4))
5392 match = vec_len (mask) / sizeof (u32x4);
5394 for (i = match*sizeof(u32x4); i > 0; i-= sizeof(u32x4))
5396 u64 *tmp = (u64 *)(mask + (i-sizeof(u32x4)));
5397 if (*tmp || *(tmp+1))
5402 clib_warning ("BUG: match 0");
5404 _vec_len (mask) = match * sizeof(u32x4);
5415 #define foreach_l2_next \
5417 _(ethernet, ETHERNET_INPUT) \
5421 uword unformat_l2_next_index (unformat_input_t * input, va_list * args)
5423 u32 * miss_next_indexp = va_arg (*args, u32 *);
5428 if (unformat (input, #n)) { next_index = L2_CLASSIFY_NEXT_##N; goto out;}
5432 if (unformat (input, "%d", &tmp))
5441 *miss_next_indexp = next_index;
5445 #define foreach_ip_next \
5451 uword unformat_ip_next_index (unformat_input_t * input, va_list * args)
5453 u32 * miss_next_indexp = va_arg (*args, u32 *);
5458 if (unformat (input, #n)) { next_index = IP_LOOKUP_NEXT_##N; goto out;}
5462 if (unformat (input, "%d", &tmp))
5471 *miss_next_indexp = next_index;
5475 #define foreach_acl_next \
5478 uword unformat_acl_next_index (unformat_input_t * input, va_list * args)
5480 u32 * miss_next_indexp = va_arg (*args, u32 *);
5485 if (unformat (input, #n)) { next_index = ACL_NEXT_INDEX_##N; goto out;}
5489 if (unformat (input, "permit"))
5494 else if (unformat (input, "%d", &tmp))
5503 *miss_next_indexp = next_index;
5507 static int api_classify_add_del_table (vat_main_t * vam)
5509 unformat_input_t * i = vam->input;
5510 vl_api_classify_add_del_table_t *mp;
5516 u32 table_index = ~0;
5517 u32 next_table_index = ~0;
5518 u32 miss_next_index = ~0;
5519 u32 memory_size = 32<<20;
5523 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
5524 if (unformat (i, "del"))
5526 else if (unformat (i, "buckets %d", &nbuckets))
5528 else if (unformat (i, "memory_size %d", &memory_size))
5530 else if (unformat (i, "skip %d", &skip))
5532 else if (unformat (i, "match %d", &match))
5534 else if (unformat (i, "table %d", &table_index))
5536 else if (unformat (i, "mask %U", unformat_classify_mask,
5537 &mask, &skip, &match))
5539 else if (unformat (i, "next-table %d", &next_table_index))
5541 else if (unformat (i, "miss-next %U", unformat_ip_next_index,
5544 else if (unformat (i, "l2-miss-next %U", unformat_l2_next_index,
5547 else if (unformat (i, "acl-miss-next %U", unformat_acl_next_index,
5554 if (is_add && mask == 0) {
5555 errmsg ("Mask required\n");
5559 if (is_add && skip == ~0) {
5560 errmsg ("skip count required\n");
5564 if (is_add && match == ~0) {
5565 errmsg ("match count required\n");
5569 if (!is_add && table_index == ~0) {
5570 errmsg ("table index required for delete\n");
5574 M2 (CLASSIFY_ADD_DEL_TABLE, classify_add_del_table,
5577 mp->is_add = is_add;
5578 mp->table_index = ntohl(table_index);
5579 mp->nbuckets = ntohl(nbuckets);
5580 mp->memory_size = ntohl(memory_size);
5581 mp->skip_n_vectors = ntohl(skip);
5582 mp->match_n_vectors = ntohl(match);
5583 mp->next_table_index = ntohl(next_table_index);
5584 mp->miss_next_index = ntohl(miss_next_index);
5585 memcpy (mp->mask, mask, vec_len(mask));
5593 uword unformat_ip4_match (unformat_input_t * input, va_list * args)
5595 u8 ** matchp = va_arg (*args, u8 **);
5602 int src = 0, dst = 0;
5603 ip4_address_t src_val, dst_val;
5610 int fragment_id = 0;
5611 u32 fragment_id_val;
5617 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
5619 if (unformat (input, "version %d", &version_val))
5621 else if (unformat (input, "hdr_length %d", &hdr_length_val))
5623 else if (unformat (input, "src %U", unformat_ip4_address, &src_val))
5625 else if (unformat (input, "dst %U", unformat_ip4_address, &dst_val))
5627 else if (unformat (input, "proto %d", &proto_val))
5629 else if (unformat (input, "tos %d", &tos_val))
5631 else if (unformat (input, "length %d", &length_val))
5633 else if (unformat (input, "fragment_id %d", &fragment_id_val))
5635 else if (unformat (input, "ttl %d", &ttl_val))
5637 else if (unformat (input, "checksum %d", &checksum_val))
5643 if (version + hdr_length + src + dst + proto + tos + length + fragment_id
5644 + ttl + checksum == 0)
5648 * Aligned because we use the real comparison functions
5650 vec_validate_aligned (match, sizeof (*ip) - 1, sizeof(u32x4));
5652 ip = (ip4_header_t *) match;
5654 /* These are realistically matched in practice */
5656 ip->src_address.as_u32 = src_val.as_u32;
5659 ip->dst_address.as_u32 = dst_val.as_u32;
5662 ip->protocol = proto_val;
5665 /* These are not, but they're included for completeness */
5667 ip->ip_version_and_header_length |= (version_val & 0xF)<<4;
5670 ip->ip_version_and_header_length |= (hdr_length_val & 0xF);
5676 ip->length = length_val;
5682 ip->checksum = checksum_val;
5688 uword unformat_ip6_match (unformat_input_t * input, va_list * args)
5690 u8 ** matchp = va_arg (*args, u8 **);
5696 u32 traffic_class_val;
5699 int src = 0, dst = 0;
5700 ip6_address_t src_val, dst_val;
5703 int payload_length = 0;
5704 u32 payload_length_val;
5707 u32 ip_version_traffic_class_and_flow_label;
5709 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
5711 if (unformat (input, "version %d", &version_val))
5713 else if (unformat (input, "traffic_class %d", &traffic_class_val))
5715 else if (unformat (input, "flow_label %d", &flow_label_val))
5717 else if (unformat (input, "src %U", unformat_ip6_address, &src_val))
5719 else if (unformat (input, "dst %U", unformat_ip6_address, &dst_val))
5721 else if (unformat (input, "proto %d", &proto_val))
5723 else if (unformat (input, "payload_length %d", &payload_length_val))
5725 else if (unformat (input, "hop_limit %d", &hop_limit_val))
5731 if (version + traffic_class + flow_label + src + dst + proto +
5732 payload_length + hop_limit == 0)
5736 * Aligned because we use the real comparison functions
5738 vec_validate_aligned (match, sizeof (*ip) - 1, sizeof(u32x4));
5740 ip = (ip6_header_t *) match;
5743 memcpy (&ip->src_address, &src_val, sizeof (ip->src_address));
5746 memcpy (&ip->dst_address, &dst_val, sizeof (ip->dst_address));
5749 ip->protocol = proto_val;
5751 ip_version_traffic_class_and_flow_label = 0;
5754 ip_version_traffic_class_and_flow_label |= (version_val & 0xF) << 28;
5757 ip_version_traffic_class_and_flow_label |= (traffic_class_val & 0xFF) << 20;
5760 ip_version_traffic_class_and_flow_label |= (flow_label_val & 0xFFFFF);
5762 ip->ip_version_traffic_class_and_flow_label =
5763 clib_host_to_net_u32 (ip_version_traffic_class_and_flow_label);
5766 ip->payload_length = clib_host_to_net_u16 (payload_length_val);
5769 ip->hop_limit = hop_limit_val;
5775 uword unformat_l3_match (unformat_input_t * input, va_list * args)
5777 u8 ** matchp = va_arg (*args, u8 **);
5779 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) {
5780 if (unformat (input, "ip4 %U", unformat_ip4_match, matchp))
5782 else if (unformat (input, "ip6 %U", unformat_ip6_match, matchp))
5790 uword unformat_vlan_tag (unformat_input_t * input, va_list * args)
5792 u8 * tagp = va_arg (*args, u8 *);
5795 if (unformat(input, "%d", &tag))
5797 tagp[0] = (tag>>8) & 0x0F;
5798 tagp[1] = tag & 0xFF;
5805 uword unformat_l2_match (unformat_input_t * input, va_list * args)
5807 u8 ** matchp = va_arg (*args, u8 **);
5827 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) {
5828 if (unformat (input, "src %U", unformat_ethernet_address, &src_val))
5830 else if (unformat (input, "dst %U", unformat_ethernet_address, &dst_val))
5832 else if (unformat (input, "proto %U",
5833 unformat_ethernet_type_host_byte_order, &proto_val))
5835 else if (unformat (input, "tag1 %U", unformat_vlan_tag, tag1_val))
5837 else if (unformat (input, "tag2 %U", unformat_vlan_tag, tag2_val))
5839 else if (unformat (input, "ignore-tag1"))
5841 else if (unformat (input, "ignore-tag2"))
5843 else if (unformat (input, "cos1 %d", &cos1_val))
5845 else if (unformat (input, "cos2 %d", &cos2_val))
5850 if ((src + dst + proto + tag1 + tag2 +
5851 ignore_tag1 + ignore_tag2 + cos1 + cos2) == 0)
5854 if (tag1 || ignore_tag1 || cos1)
5856 if (tag2 || ignore_tag2 || cos2)
5859 vec_validate_aligned (match, len-1, sizeof(u32x4));
5862 memcpy (match, dst_val, 6);
5865 memcpy (match + 6, src_val, 6);
5869 /* inner vlan tag */
5870 match[19] = tag2_val[1];
5871 match[18] = tag2_val[0];
5873 match [18] |= (cos2_val & 0x7) << 5;
5876 match[21] = proto_val & 0xff;
5877 match[20] = proto_val >> 8;
5881 match [15] = tag1_val[1];
5882 match [14] = tag1_val[0];
5885 match [14] |= (cos1_val & 0x7) << 5;
5891 match [15] = tag1_val[1];
5892 match [14] = tag1_val[0];
5895 match[17] = proto_val & 0xff;
5896 match[16] = proto_val >> 8;
5899 match [14] |= (cos1_val & 0x7) << 5;
5905 match [18] |= (cos2_val & 0x7) << 5;
5907 match [14] |= (cos1_val & 0x7) << 5;
5910 match[13] = proto_val & 0xff;
5911 match[12] = proto_val >> 8;
5919 uword unformat_classify_match (unformat_input_t * input, va_list * args)
5921 u8 ** matchp = va_arg (*args, u8 **);
5922 u32 skip_n_vectors = va_arg (*args, u32);
5923 u32 match_n_vectors = va_arg (*args, u32);
5929 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) {
5930 if (unformat (input, "hex %U", unformat_hex_string, &match))
5932 else if (unformat (input, "l2 %U", unformat_l2_match, &l2))
5934 else if (unformat (input, "l3 %U", unformat_l3_match, &l3))
5940 if (match || l2 || l3)
5944 /* "Win a free Ethernet header in every packet" */
5946 vec_validate_aligned (l2, 13, sizeof(u32x4));
5948 vec_append_aligned (match, l3, sizeof(u32x4));
5952 /* Make sure the vector is big enough even if key is all 0's */
5953 vec_validate_aligned
5954 (match, ((match_n_vectors + skip_n_vectors) * sizeof(u32x4)) - 1,
5957 /* Set size, include skipped vectors*/
5958 _vec_len (match) = (match_n_vectors+skip_n_vectors) * sizeof(u32x4);
5968 static int api_classify_add_del_session (vat_main_t * vam)
5970 unformat_input_t * i = vam->input;
5971 vl_api_classify_add_del_session_t *mp;
5973 u32 table_index = ~0;
5974 u32 hit_next_index = ~0;
5975 u32 opaque_index = ~0;
5979 u32 skip_n_vectors = 0;
5980 u32 match_n_vectors = 0;
5983 * Warning: you have to supply skip_n and match_n
5984 * because the API client cant simply look at the classify
5988 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
5989 if (unformat (i, "del"))
5991 else if (unformat (i, "hit-next %U", unformat_ip_next_index,
5994 else if (unformat (i, "l2-hit-next %U", unformat_l2_next_index,
5997 else if (unformat (i, "acl-hit-next %U", unformat_acl_next_index,
6000 else if (unformat (i, "opaque-index %d", &opaque_index))
6002 else if (unformat (i, "skip_n %d", &skip_n_vectors))
6004 else if (unformat (i, "match_n %d", &match_n_vectors))
6006 else if (unformat (i, "match %U", unformat_classify_match,
6007 &match, skip_n_vectors, match_n_vectors))
6009 else if (unformat (i, "advance %d", &advance))
6011 else if (unformat (i, "table-index %d", &table_index))
6017 if (table_index == ~0) {
6018 errmsg ("Table index required\n");
6022 if (is_add && match == 0) {
6023 errmsg ("Match value required\n");
6027 M2 (CLASSIFY_ADD_DEL_SESSION, classify_add_del_session,
6030 mp->is_add = is_add;
6031 mp->table_index = ntohl(table_index);
6032 mp->hit_next_index = ntohl(hit_next_index);
6033 mp->opaque_index = ntohl(opaque_index);
6034 mp->advance = ntohl(advance);
6035 memcpy (mp->match, match, vec_len(match));
6042 static int api_classify_set_interface_ip_table (vat_main_t * vam)
6044 unformat_input_t * i = vam->input;
6045 vl_api_classify_set_interface_ip_table_t *mp;
6048 int sw_if_index_set;
6049 u32 table_index = ~0;
6052 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
6053 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
6054 sw_if_index_set = 1;
6055 else if (unformat (i, "sw_if_index %d", &sw_if_index))
6056 sw_if_index_set = 1;
6057 else if (unformat (i, "table %d", &table_index))
6060 clib_warning ("parse error '%U'", format_unformat_error, i);
6065 if (sw_if_index_set == 0) {
6066 errmsg ("missing interface name or sw_if_index\n");
6071 M(CLASSIFY_SET_INTERFACE_IP_TABLE, classify_set_interface_ip_table);
6073 mp->sw_if_index = ntohl(sw_if_index);
6074 mp->table_index = ntohl(table_index);
6075 mp->is_ipv6 = is_ipv6;
6082 static int api_classify_set_interface_l2_tables (vat_main_t * vam)
6084 unformat_input_t * i = vam->input;
6085 vl_api_classify_set_interface_l2_tables_t *mp;
6088 int sw_if_index_set;
6089 u32 ip4_table_index = ~0;
6090 u32 ip6_table_index = ~0;
6091 u32 other_table_index = ~0;
6093 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
6094 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
6095 sw_if_index_set = 1;
6096 else if (unformat (i, "sw_if_index %d", &sw_if_index))
6097 sw_if_index_set = 1;
6098 else if (unformat (i, "ip4-table %d", &ip4_table_index))
6100 else if (unformat (i, "ip6-table %d", &ip6_table_index))
6102 else if (unformat (i, "other-table %d", &other_table_index))
6105 clib_warning ("parse error '%U'", format_unformat_error, i);
6110 if (sw_if_index_set == 0) {
6111 errmsg ("missing interface name or sw_if_index\n");
6116 M(CLASSIFY_SET_INTERFACE_L2_TABLES, classify_set_interface_l2_tables);
6118 mp->sw_if_index = ntohl(sw_if_index);
6119 mp->ip4_table_index = ntohl(ip4_table_index);
6120 mp->ip6_table_index = ntohl(ip6_table_index);
6121 mp->other_table_index = ntohl(other_table_index);
6129 static int api_get_node_index (vat_main_t * vam)
6131 unformat_input_t * i = vam->input;
6132 vl_api_get_node_index_t * mp;
6136 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
6137 if (unformat (i, "node %s", &name))
6143 errmsg ("node name required\n");
6146 if (vec_len (name) >= ARRAY_LEN(mp->node_name)) {
6147 errmsg ("node name too long, max %d\n", ARRAY_LEN(mp->node_name));
6151 M(GET_NODE_INDEX, get_node_index);
6152 memcpy (mp->node_name, name, vec_len(name));
6160 static int api_add_node_next (vat_main_t * vam)
6162 unformat_input_t * i = vam->input;
6163 vl_api_add_node_next_t * mp;
6168 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
6169 if (unformat (i, "node %s", &name))
6171 else if (unformat (i, "next %s", &next))
6177 errmsg ("node name required\n");
6180 if (vec_len (name) >= ARRAY_LEN(mp->node_name)) {
6181 errmsg ("node name too long, max %d\n", ARRAY_LEN(mp->node_name));
6185 errmsg ("next node required\n");
6188 if (vec_len (next) >= ARRAY_LEN(mp->next_name)) {
6189 errmsg ("next name too long, max %d\n", ARRAY_LEN(mp->next_name));
6193 M(ADD_NODE_NEXT, add_node_next);
6194 memcpy (mp->node_name, name, vec_len(name));
6195 memcpy (mp->next_name, next, vec_len(next));
6204 static int api_l2tpv3_create_tunnel (vat_main_t * vam)
6206 unformat_input_t * i = vam->input;
6207 ip6_address_t client_address, our_address;
6208 int client_address_set = 0;
6209 int our_address_set = 0;
6210 u32 local_session_id = 0;
6211 u32 remote_session_id = 0;
6212 u64 local_cookie = 0;
6213 u64 remote_cookie = 0;
6214 u8 l2_sublayer_present = 0;
6215 vl_api_l2tpv3_create_tunnel_t * mp;
6218 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
6219 if (unformat (i, "client_address %U", unformat_ip6_address,
6221 client_address_set = 1;
6222 else if (unformat (i, "our_address %U", unformat_ip6_address,
6224 our_address_set = 1;
6225 else if (unformat (i, "local_session_id %d", &local_session_id))
6227 else if (unformat (i, "remote_session_id %d", &remote_session_id))
6229 else if (unformat (i, "local_cookie %lld", &local_cookie))
6231 else if (unformat (i, "remote_cookie %lld", &remote_cookie))
6233 else if (unformat (i, "l2-sublayer-present"))
6234 l2_sublayer_present = 1;
6239 if (client_address_set == 0) {
6240 errmsg ("client_address required\n");
6244 if (our_address_set == 0) {
6245 errmsg ("our_address required\n");
6249 M(L2TPV3_CREATE_TUNNEL, l2tpv3_create_tunnel);
6251 memcpy (mp->client_address, client_address.as_u8,
6252 sizeof (mp->client_address));
6254 memcpy (mp->our_address, our_address.as_u8,
6255 sizeof (mp->our_address));
6257 mp->local_session_id = ntohl (local_session_id);
6258 mp->remote_session_id = ntohl (remote_session_id);
6259 mp->local_cookie = clib_host_to_net_u64 (local_cookie);
6260 mp->remote_cookie = clib_host_to_net_u64 (remote_cookie);
6261 mp->l2_sublayer_present = l2_sublayer_present;
6269 static int api_l2tpv3_set_tunnel_cookies (vat_main_t * vam)
6271 unformat_input_t * i = vam->input;
6273 u8 sw_if_index_set = 0;
6274 u64 new_local_cookie = 0;
6275 u64 new_remote_cookie = 0;
6276 vl_api_l2tpv3_set_tunnel_cookies_t *mp;
6279 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
6280 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
6281 sw_if_index_set = 1;
6282 else if (unformat (i, "sw_if_index %d", &sw_if_index))
6283 sw_if_index_set = 1;
6284 else if (unformat (i, "new_local_cookie %lld", &new_local_cookie))
6286 else if (unformat (i, "new_remote_cookie %lld", &new_remote_cookie))
6292 if (sw_if_index_set == 0) {
6293 errmsg ("missing interface name or sw_if_index\n");
6297 M(L2TPV3_SET_TUNNEL_COOKIES, l2tpv3_set_tunnel_cookies);
6299 mp->sw_if_index = ntohl(sw_if_index);
6300 mp->new_local_cookie = clib_host_to_net_u64 (new_local_cookie);
6301 mp->new_remote_cookie = clib_host_to_net_u64 (new_remote_cookie);
6308 static int api_l2tpv3_interface_enable_disable (vat_main_t * vam)
6310 unformat_input_t * i = vam->input;
6311 vl_api_l2tpv3_interface_enable_disable_t *mp;
6314 u8 sw_if_index_set = 0;
6315 u8 enable_disable = 1;
6317 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
6318 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
6319 sw_if_index_set = 1;
6320 else if (unformat (i, "sw_if_index %d", &sw_if_index))
6321 sw_if_index_set = 1;
6322 else if (unformat (i, "enable"))
6324 else if (unformat (i, "disable"))
6330 if (sw_if_index_set == 0) {
6331 errmsg ("missing interface name or sw_if_index\n");
6335 M(L2TPV3_INTERFACE_ENABLE_DISABLE, l2tpv3_interface_enable_disable);
6337 mp->sw_if_index = ntohl(sw_if_index);
6338 mp->enable_disable = enable_disable;
6345 static int api_l2tpv3_set_lookup_key (vat_main_t * vam)
6347 unformat_input_t * i = vam->input;
6348 vl_api_l2tpv3_set_lookup_key_t * mp;
6352 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
6353 if (unformat (i, "lookup_v6_src"))
6354 key = L2T_LOOKUP_SRC_ADDRESS;
6355 else if (unformat (i, "lookup_v6_dst"))
6356 key = L2T_LOOKUP_DST_ADDRESS;
6357 else if (unformat (i, "lookup_session_id"))
6358 key = L2T_LOOKUP_SESSION_ID;
6364 errmsg ("l2tp session lookup key unset\n");
6368 M(L2TPV3_SET_LOOKUP_KEY, l2tpv3_set_lookup_key);
6377 static void vl_api_sw_if_l2tpv3_tunnel_details_t_handler
6378 (vl_api_sw_if_l2tpv3_tunnel_details_t * mp)
6380 vat_main_t * vam = &vat_main;
6382 fformat(vam->ofp, "* %U (our) %U (client) (sw_if_index %d)\n",
6383 format_ip6_address, mp->our_address,
6384 format_ip6_address, mp->client_address,
6385 clib_net_to_host_u32(mp->sw_if_index));
6387 fformat (vam->ofp, " local cookies %016llx %016llx remote cookie %016llx\n",
6388 clib_net_to_host_u64 (mp->local_cookie[0]),
6389 clib_net_to_host_u64 (mp->local_cookie[1]),
6390 clib_net_to_host_u64 (mp->remote_cookie));
6392 fformat (vam->ofp, " local session-id %d remote session-id %d\n",
6393 clib_net_to_host_u32 (mp->local_session_id),
6394 clib_net_to_host_u32 (mp->remote_session_id));
6396 fformat (vam->ofp, " l2 specific sublayer %s\n\n",
6397 mp->l2_sublayer_present ? "preset" : "absent");
6401 static void vl_api_sw_if_l2tpv3_tunnel_details_t_handler_json
6402 (vl_api_sw_if_l2tpv3_tunnel_details_t * mp)
6404 vat_main_t * vam = &vat_main;
6405 vat_json_node_t *node = NULL;
6406 struct in6_addr addr;
6408 if (VAT_JSON_ARRAY != vam->json_tree.type) {
6409 ASSERT(VAT_JSON_NONE == vam->json_tree.type);
6410 vat_json_init_array(&vam->json_tree);
6412 node = vat_json_array_add(&vam->json_tree);
6414 vat_json_init_object(node);
6416 memcpy(&addr, mp->our_address, sizeof(addr));
6417 vat_json_object_add_ip6(node, "our_address", addr);
6418 memcpy(&addr, mp->client_address, sizeof(addr));
6419 vat_json_object_add_ip6(node, "client_address", addr);
6421 vat_json_node_t * lc = vat_json_object_add(node, "local_cookie");
6422 vat_json_init_array(lc);
6423 vat_json_array_add_uint(lc, clib_net_to_host_u64(mp->local_cookie[0]));
6424 vat_json_array_add_uint(lc, clib_net_to_host_u64(mp->local_cookie[1]));
6425 vat_json_object_add_uint(node, "remote_cookie", clib_net_to_host_u64(mp->remote_cookie));
6427 printf("local id: %u", clib_net_to_host_u32(mp->local_session_id));
6428 vat_json_object_add_uint(node, "local_session_id", clib_net_to_host_u32(mp->local_session_id));
6429 vat_json_object_add_uint(node, "remote_session_id", clib_net_to_host_u32(mp->remote_session_id));
6430 vat_json_object_add_string_copy(node, "l2_sublayer", mp->l2_sublayer_present ?
6431 (u8*)"present" : (u8*)"absent");
6434 static int api_sw_if_l2tpv3_tunnel_dump (vat_main_t * vam)
6436 vl_api_sw_if_l2tpv3_tunnel_dump_t *mp;
6439 /* Get list of l2tpv3-tunnel interfaces */
6440 M(SW_IF_L2TPV3_TUNNEL_DUMP, sw_if_l2tpv3_tunnel_dump);
6443 /* Use a control ping for synchronization */
6445 vl_api_control_ping_t * mp;
6446 M(CONTROL_PING, control_ping);
6453 static void vl_api_sw_interface_tap_details_t_handler
6454 (vl_api_sw_interface_tap_details_t * mp)
6456 vat_main_t * vam = &vat_main;
6458 fformat(vam->ofp, "%-16s %d\n",
6460 clib_net_to_host_u32(mp->sw_if_index));
6463 static void vl_api_sw_interface_tap_details_t_handler_json
6464 (vl_api_sw_interface_tap_details_t * mp)
6466 vat_main_t * vam = &vat_main;
6467 vat_json_node_t *node = NULL;
6469 if (VAT_JSON_ARRAY != vam->json_tree.type) {
6470 ASSERT(VAT_JSON_NONE == vam->json_tree.type);
6471 vat_json_init_array(&vam->json_tree);
6473 node = vat_json_array_add(&vam->json_tree);
6475 vat_json_init_object(node);
6476 vat_json_object_add_uint(node, "sw_if_index", ntohl(mp->sw_if_index));
6477 vat_json_object_add_string_copy(node, "dev_name", mp->dev_name);
6480 static int api_sw_interface_tap_dump (vat_main_t * vam)
6482 vl_api_sw_interface_tap_dump_t *mp;
6485 fformat(vam->ofp, "\n%-16s %s\n", "dev_name", "sw_if_index");
6486 /* Get list of tap interfaces */
6487 M(SW_INTERFACE_TAP_DUMP, sw_interface_tap_dump);
6490 /* Use a control ping for synchronization */
6492 vl_api_control_ping_t * mp;
6493 M(CONTROL_PING, control_ping);
6499 static uword unformat_vxlan_decap_next
6500 (unformat_input_t * input, va_list * args)
6502 u32 * result = va_arg (*args, u32 *);
6505 if (unformat (input, "drop"))
6506 *result = VXLAN_INPUT_NEXT_DROP;
6507 else if (unformat (input, "ip4"))
6508 *result = VXLAN_INPUT_NEXT_IP4_INPUT;
6509 else if (unformat (input, "ip6"))
6510 *result = VXLAN_INPUT_NEXT_IP6_INPUT;
6511 else if (unformat (input, "l2"))
6512 *result = VXLAN_INPUT_NEXT_L2_INPUT;
6513 else if (unformat (input, "%d", &tmp))
6520 static int api_vxlan_add_del_tunnel (vat_main_t * vam)
6522 unformat_input_t * line_input = vam->input;
6523 vl_api_vxlan_add_del_tunnel_t *mp;
6525 ip4_address_t src, dst;
6529 u32 encap_vrf_id = 0;
6530 u32 decap_next_index = ~0;
6533 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) {
6534 if (unformat (line_input, "del"))
6536 else if (unformat (line_input, "src %U",
6537 unformat_ip4_address, &src))
6539 else if (unformat (line_input, "dst %U",
6540 unformat_ip4_address, &dst))
6542 else if (unformat (line_input, "encap-vrf-id %d", &encap_vrf_id))
6544 else if (unformat (line_input, "decap-next %U",
6545 unformat_vxlan_decap_next, &decap_next_index))
6547 else if (unformat (line_input, "vni %d", &vni))
6550 errmsg ("parse error '%U'\n", format_unformat_error, line_input);
6556 errmsg ("tunnel src address not specified\n");
6560 errmsg ("tunnel dst address not specified\n");
6564 if ((vni == 0) || (vni>>24)) {
6565 errmsg ("vni not specified or out of range\n");
6569 M (VXLAN_ADD_DEL_TUNNEL, vxlan_add_del_tunnel);
6571 mp->src_address = src.as_u32;
6572 mp->dst_address = dst.as_u32;
6573 mp->encap_vrf_id = ntohl(encap_vrf_id);
6574 mp->decap_next_index = ntohl(decap_next_index);
6575 mp->vni = ntohl(vni);
6576 mp->is_add = is_add;
6583 static void vl_api_vxlan_tunnel_details_t_handler
6584 (vl_api_vxlan_tunnel_details_t * mp)
6586 vat_main_t * vam = &vat_main;
6588 fformat(vam->ofp, "%11d%13U%13U%14d%18d%13d\n",
6589 ntohl(mp->sw_if_index),
6590 format_ip4_address, &mp->src_address,
6591 format_ip4_address, &mp->dst_address,
6592 ntohl(mp->encap_vrf_id),
6593 ntohl(mp->decap_next_index),
6597 static void vl_api_vxlan_tunnel_details_t_handler_json
6598 (vl_api_vxlan_tunnel_details_t * mp)
6600 vat_main_t * vam = &vat_main;
6601 vat_json_node_t *node = NULL;
6604 if (VAT_JSON_ARRAY != vam->json_tree.type) {
6605 ASSERT(VAT_JSON_NONE == vam->json_tree.type);
6606 vat_json_init_array(&vam->json_tree);
6608 node = vat_json_array_add(&vam->json_tree);
6610 vat_json_init_object(node);
6611 vat_json_object_add_uint(node, "sw_if_index", ntohl(mp->sw_if_index));
6612 memcpy(&ip4, &mp->src_address, sizeof(ip4));
6613 vat_json_object_add_ip4(node, "src_address", ip4);
6614 memcpy(&ip4, &mp->dst_address, sizeof(ip4));
6615 vat_json_object_add_ip4(node, "dst_address", ip4);
6616 vat_json_object_add_uint(node, "encap_vrf_id", ntohl(mp->encap_vrf_id));
6617 vat_json_object_add_uint(node, "decap_next_index", ntohl(mp->decap_next_index));
6618 vat_json_object_add_uint(node, "vni", ntohl(mp->vni));
6621 static int api_vxlan_tunnel_dump (vat_main_t * vam)
6623 unformat_input_t * i = vam->input;
6624 vl_api_vxlan_tunnel_dump_t *mp;
6627 u8 sw_if_index_set = 0;
6629 /* Parse args required to build the message */
6630 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
6631 if (unformat (i, "sw_if_index %d", &sw_if_index))
6632 sw_if_index_set = 1;
6637 if (sw_if_index_set == 0) {
6641 if (!vam->json_output) {
6642 fformat(vam->ofp, "%11s%13s%13s%14s%18s%13s\n",
6643 "sw_if_index", "src_address", "dst_address",
6644 "encap_vrf_id", "decap_next_index", "vni");
6647 /* Get list of l2tpv3-tunnel interfaces */
6648 M(VXLAN_TUNNEL_DUMP, vxlan_tunnel_dump);
6650 mp->sw_if_index = htonl(sw_if_index);
6654 /* Use a control ping for synchronization */
6656 vl_api_control_ping_t * mp;
6657 M(CONTROL_PING, control_ping);
6663 static int api_l2_fib_clear_table (vat_main_t * vam)
6665 // unformat_input_t * i = vam->input;
6666 vl_api_l2_fib_clear_table_t *mp;
6669 M(L2_FIB_CLEAR_TABLE, l2_fib_clear_table);
6676 static int api_l2_interface_efp_filter (vat_main_t * vam)
6678 unformat_input_t * i = vam->input;
6679 vl_api_l2_interface_efp_filter_t *mp;
6683 u8 sw_if_index_set = 0;
6685 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
6686 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
6687 sw_if_index_set = 1;
6688 else if (unformat (i, "sw_if_index %d", &sw_if_index))
6689 sw_if_index_set = 1;
6690 else if (unformat (i, "enable"))
6692 else if (unformat (i, "disable"))
6695 clib_warning ("parse error '%U'", format_unformat_error, i);
6700 if (sw_if_index_set == 0) {
6701 errmsg ("missing sw_if_index\n");
6705 M(L2_INTERFACE_EFP_FILTER, l2_interface_efp_filter);
6707 mp->sw_if_index = ntohl(sw_if_index);
6708 mp->enable_disable = enable;
6715 #define foreach_vtr_op \
6716 _("disable", L2_VTR_DISABLED) \
6717 _("push-1", L2_VTR_PUSH_1) \
6718 _("push-2", L2_VTR_PUSH_2) \
6719 _("pop-1", L2_VTR_POP_1) \
6720 _("pop-2", L2_VTR_POP_2) \
6721 _("translate-1-1", L2_VTR_TRANSLATE_1_1) \
6722 _("translate-1-2", L2_VTR_TRANSLATE_1_2) \
6723 _("translate-2-1", L2_VTR_TRANSLATE_2_1) \
6724 _("translate-2-2", L2_VTR_TRANSLATE_2_2)
6726 static int api_l2_interface_vlan_tag_rewrite (vat_main_t * vam)
6728 unformat_input_t * i = vam->input;
6729 vl_api_l2_interface_vlan_tag_rewrite_t *mp;
6732 u8 sw_if_index_set = 0;
6739 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
6740 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
6741 sw_if_index_set = 1;
6742 else if (unformat (i, "sw_if_index %d", &sw_if_index))
6743 sw_if_index_set = 1;
6744 else if (unformat (i, "vtr_op %d", &vtr_op))
6746 #define _(n,v) else if (unformat(i, n)) {vtr_op = v; vtr_op_set = 1;}
6750 else if (unformat (i, "push_dot1q %d", &push_dot1q))
6752 else if (unformat (i, "tag1 %d", &tag1))
6754 else if (unformat (i, "tag2 %d", &tag2))
6757 clib_warning ("parse error '%U'", format_unformat_error, i);
6762 if ((sw_if_index_set == 0)||(vtr_op_set == 0)) {
6763 errmsg ("missing vtr operation or sw_if_index\n");
6767 M(L2_INTERFACE_VLAN_TAG_REWRITE, l2_interface_vlan_tag_rewrite)
6769 mp->sw_if_index = ntohl(sw_if_index);
6770 mp->vtr_op = ntohl(vtr_op);
6771 mp->push_dot1q = ntohl(push_dot1q);
6772 mp->tag1 = ntohl(tag1);
6773 mp->tag2 = ntohl(tag2);
6780 static int api_create_vhost_user_if (vat_main_t * vam)
6782 unformat_input_t * i = vam->input;
6783 vl_api_create_vhost_user_if_t *mp;
6787 u8 file_name_set = 0;
6788 u32 custom_dev_instance = ~0;
6790 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
6791 if (unformat (i, "socket %s", &file_name)) {
6794 else if (unformat (i, "renumber %"PRIu32, &custom_dev_instance))
6796 else if (unformat (i, "server"))
6802 if (file_name_set == 0) {
6803 errmsg ("missing socket file name\n");
6807 if (vec_len (file_name) > 255) {
6808 errmsg ("socket file name too long\n");
6811 vec_add1 (file_name, 0);
6813 M(CREATE_VHOST_USER_IF, create_vhost_user_if);
6815 mp->is_server = is_server;
6816 memcpy(mp->sock_filename, file_name, vec_len(file_name));
6817 vec_free(file_name);
6818 if (custom_dev_instance != ~0) {
6820 mp->custom_dev_instance = ntohl(custom_dev_instance);
6828 static int api_modify_vhost_user_if (vat_main_t * vam)
6830 unformat_input_t * i = vam->input;
6831 vl_api_modify_vhost_user_if_t *mp;
6835 u8 file_name_set = 0;
6836 u32 custom_dev_instance = ~0;
6837 u8 sw_if_index_set = 0;
6838 u32 sw_if_index = (u32)~0;
6840 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
6841 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
6842 sw_if_index_set = 1;
6843 else if (unformat (i, "sw_if_index %d", &sw_if_index))
6844 sw_if_index_set = 1;
6845 else if (unformat (i, "socket %s", &file_name)) {
6848 else if (unformat (i, "renumber %"PRIu32, &custom_dev_instance))
6850 else if (unformat (i, "server"))
6856 if (sw_if_index_set == 0) {
6857 errmsg ("missing sw_if_index or interface name\n");
6861 if (file_name_set == 0) {
6862 errmsg ("missing socket file name\n");
6866 if (vec_len (file_name) > 255) {
6867 errmsg ("socket file name too long\n");
6870 vec_add1 (file_name, 0);
6872 M(MODIFY_VHOST_USER_IF, modify_vhost_user_if);
6874 mp->sw_if_index = ntohl(sw_if_index);
6875 mp->is_server = is_server;
6876 memcpy(mp->sock_filename, file_name, vec_len(file_name));
6877 vec_free(file_name);
6878 if (custom_dev_instance != ~0) {
6880 mp->custom_dev_instance = ntohl(custom_dev_instance);
6888 static int api_delete_vhost_user_if (vat_main_t * vam)
6890 unformat_input_t * i = vam->input;
6891 vl_api_delete_vhost_user_if_t *mp;
6893 u32 sw_if_index = ~0;
6894 u8 sw_if_index_set = 0;
6896 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
6897 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
6898 sw_if_index_set = 1;
6899 else if (unformat (i, "sw_if_index %d", &sw_if_index))
6900 sw_if_index_set = 1;
6905 if (sw_if_index_set == 0) {
6906 errmsg ("missing sw_if_index or interface name\n");
6911 M(DELETE_VHOST_USER_IF, delete_vhost_user_if);
6913 mp->sw_if_index = ntohl(sw_if_index);
6920 static void vl_api_sw_interface_vhost_user_details_t_handler
6921 (vl_api_sw_interface_vhost_user_details_t * mp)
6923 vat_main_t * vam = &vat_main;
6925 fformat(vam->ofp, "%-25s %3" PRIu32 " %6" PRIu32 " %8x %6d %7d %s\n",
6926 (char *)mp->interface_name,
6927 ntohl(mp->sw_if_index), ntohl(mp->virtio_net_hdr_sz),
6928 clib_net_to_host_u64(mp->features), mp->is_server,
6929 ntohl(mp->num_regions), (char *)mp->sock_filename);
6930 fformat(vam->ofp, " Status: '%s'\n", strerror(ntohl(mp->sock_errno)));
6933 static void vl_api_sw_interface_vhost_user_details_t_handler_json
6934 (vl_api_sw_interface_vhost_user_details_t * mp)
6936 vat_main_t * vam = &vat_main;
6937 vat_json_node_t *node = NULL;
6939 if (VAT_JSON_ARRAY != vam->json_tree.type) {
6940 ASSERT(VAT_JSON_NONE == vam->json_tree.type);
6941 vat_json_init_array(&vam->json_tree);
6943 node = vat_json_array_add(&vam->json_tree);
6945 vat_json_init_object(node);
6946 vat_json_object_add_uint(node, "sw_if_index", ntohl(mp->sw_if_index));
6947 vat_json_object_add_string_copy(node, "interface_name", mp->interface_name);
6948 vat_json_object_add_uint(node, "virtio_net_hdr_sz", ntohl(mp->virtio_net_hdr_sz));
6949 vat_json_object_add_uint(node, "features", clib_net_to_host_u64(mp->features));
6950 vat_json_object_add_uint(node, "is_server", mp->is_server);
6951 vat_json_object_add_string_copy(node, "sock_filename", mp->sock_filename);
6952 vat_json_object_add_uint(node, "num_regions", ntohl(mp->num_regions));
6953 vat_json_object_add_uint(node, "sock_errno", ntohl(mp->sock_errno));
6956 static int api_sw_interface_vhost_user_dump (vat_main_t * vam)
6958 vl_api_sw_interface_vhost_user_dump_t *mp;
6960 fformat(vam->ofp, "Interface name idx hdr_sz features server regions filename\n");
6962 /* Get list of vhost-user interfaces */
6963 M(SW_INTERFACE_VHOST_USER_DUMP, sw_interface_vhost_user_dump);
6966 /* Use a control ping for synchronization */
6968 vl_api_control_ping_t * mp;
6969 M(CONTROL_PING, control_ping);
6975 static int api_show_version (vat_main_t * vam)
6977 vl_api_show_version_t *mp;
6980 M(SHOW_VERSION, show_version);
6987 static uword unformat_nsh_gre_decap_next
6988 (unformat_input_t * input, va_list * args)
6990 u32 * result = va_arg (*args, u32 *);
6993 if (unformat (input, "drop"))
6994 *result = NSH_INPUT_NEXT_DROP;
6995 else if (unformat (input, "ip4"))
6996 *result = NSH_INPUT_NEXT_IP4_INPUT;
6997 else if (unformat (input, "ip6"))
6998 *result = NSH_INPUT_NEXT_IP6_INPUT;
6999 else if (unformat (input, "ethernet"))
7000 *result = NSH_INPUT_NEXT_ETHERNET_INPUT;
7001 else if (unformat (input, "%d", &tmp))
7008 static int api_nsh_gre_add_del_tunnel (vat_main_t * vam)
7010 unformat_input_t * line_input = vam->input;
7011 vl_api_nsh_gre_add_del_tunnel_t *mp;
7013 ip4_address_t src, dst;
7017 u32 encap_vrf_id = 0;
7018 u32 decap_vrf_id = 0;
7021 u8 next_protocol = 1; /* ip4 */
7032 u32 decap_next_index = NSH_INPUT_NEXT_IP4_INPUT;
7036 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) {
7037 if (unformat (line_input, "del"))
7039 else if (unformat (line_input, "src %U",
7040 unformat_ip4_address, &src))
7042 else if (unformat (line_input, "dst %U",
7043 unformat_ip4_address, &dst))
7045 else if (unformat (line_input, "encap-vrf-id %d", &encap_vrf_id))
7047 else if (unformat (line_input, "decap-vrf-id %d", &decap_vrf_id))
7049 else if (unformat (line_input, "decap-next %U",
7050 unformat_nsh_gre_decap_next, &decap_next_index))
7052 else if (unformat (line_input, "version %d", &tmp))
7053 ver_o_c |= (tmp & 3) << 6;
7054 else if (unformat (line_input, "o-bit %d", &tmp))
7055 ver_o_c |= (tmp & 1) << 5;
7056 else if (unformat (line_input, "c-bit %d", &tmp))
7057 ver_o_c |= (tmp & 1) << 4;
7058 else if (unformat (line_input, "md-type %d", &tmp))
7060 else if (unformat(line_input, "next-ip4"))
7062 else if (unformat(line_input, "next-ip6"))
7064 else if (unformat(line_input, "next-ethernet"))
7066 else if (unformat (line_input, "c1 %d", &c1))
7068 else if (unformat (line_input, "c2 %d", &c2))
7070 else if (unformat (line_input, "c3 %d", &c3))
7072 else if (unformat (line_input, "c4 %d", &c4))
7074 else if (unformat (line_input, "spi %d", &spi))
7076 else if (unformat (line_input, "si %d", &si))
7078 else if (unformat (line_input, "tlv %x"))
7079 vec_add1 (tlvs, tmp);
7081 errmsg ("parse error '%U'\n", format_unformat_error, line_input);
7087 errmsg ("tunnel src address not specified\n");
7091 errmsg ("tunnel dst address not specified\n");
7096 errmsg ("spi not specified\n");
7101 errmsg ("si not specified\n");
7105 M2 (NSH_GRE_ADD_DEL_TUNNEL, nsh_gre_add_del_tunnel,
7106 sizeof(u32) * vec_len (tlvs));
7108 spi_si = (spi<<8) | si;
7110 mp->src = src.as_u32;
7111 mp->dst = dst.as_u32;
7112 mp->encap_vrf_id = ntohl(encap_vrf_id);
7113 mp->decap_vrf_id = ntohl(decap_vrf_id);
7114 mp->decap_next_index = ntohl(decap_next_index);
7115 mp->tlv_len_in_words = vec_len (tlvs);
7116 mp->is_add = is_add;
7117 mp->ver_o_c = ver_o_c;
7118 mp->length = 6 + vec_len(tlvs);
7119 mp->md_type = md_type;
7120 mp->next_protocol = next_protocol;
7121 mp->spi_si = ntohl(spi_si);
7127 for (i = 0; i < vec_len(tlvs); i++)
7128 mp->tlvs[i] = ntohl(tlvs[i]);
7137 static uword unformat_nsh_vxlan_gpe_decap_next
7138 (unformat_input_t * input, va_list * args)
7140 u32 * result = va_arg (*args, u32 *);
7143 if (unformat (input, "drop"))
7144 *result = NSH_VXLAN_GPE_INPUT_NEXT_DROP;
7145 else if (unformat (input, "ip4"))
7146 *result = NSH_VXLAN_GPE_INPUT_NEXT_IP4_INPUT;
7147 else if (unformat (input, "ip6"))
7148 *result = NSH_VXLAN_GPE_INPUT_NEXT_IP6_INPUT;
7149 else if (unformat (input, "ethernet"))
7150 *result = NSH_VXLAN_GPE_INPUT_NEXT_ETHERNET_INPUT;
7151 else if (unformat (input, "nsh-vxlan-gpe"))
7152 *result = NSH_VXLAN_GPE_INPUT_NEXT_ETHERNET_INPUT;
7153 else if (unformat (input, "%d", &tmp))
7160 static int api_nsh_vxlan_gpe_add_del_tunnel (vat_main_t * vam)
7162 unformat_input_t * line_input = vam->input;
7163 vl_api_nsh_vxlan_gpe_add_del_tunnel_t *mp;
7165 ip4_address_t src, dst;
7169 u32 encap_vrf_id = 0;
7170 u32 decap_vrf_id = 0;
7173 u8 next_protocol = 1; /* ip4 */
7184 u32 decap_next_index = NSH_INPUT_NEXT_IP4_INPUT;
7190 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) {
7191 if (unformat (line_input, "del"))
7193 else if (unformat (line_input, "src %U",
7194 unformat_ip4_address, &src))
7196 else if (unformat (line_input, "dst %U",
7197 unformat_ip4_address, &dst))
7199 else if (unformat (line_input, "encap-vrf-id %d", &encap_vrf_id))
7201 else if (unformat (line_input, "decap-vrf-id %d", &decap_vrf_id))
7203 else if (unformat (line_input, "decap-next %U",
7204 unformat_nsh_vxlan_gpe_decap_next,
7207 else if (unformat (line_input, "vni %d", &vni))
7209 else if (unformat (line_input, "version %d", &tmp))
7210 ver_o_c |= (tmp & 3) << 6;
7211 else if (unformat (line_input, "o-bit %d", &tmp))
7212 ver_o_c |= (tmp & 1) << 5;
7213 else if (unformat (line_input, "c-bit %d", &tmp))
7214 ver_o_c |= (tmp & 1) << 4;
7215 else if (unformat (line_input, "md-type %d", &tmp))
7217 else if (unformat(line_input, "next-ip4"))
7219 else if (unformat(line_input, "next-ip6"))
7221 else if (unformat(line_input, "next-ethernet"))
7223 else if (unformat (line_input, "c1 %d", &c1))
7225 else if (unformat (line_input, "c2 %d", &c2))
7227 else if (unformat (line_input, "c3 %d", &c3))
7229 else if (unformat (line_input, "c4 %d", &c4))
7231 else if (unformat (line_input, "spi %d", &spi))
7233 else if (unformat (line_input, "si %d", &si))
7235 else if (unformat (line_input, "tlv %x"))
7236 vec_add1 (tlvs, tmp);
7238 errmsg ("parse error '%U'\n", format_unformat_error, line_input);
7244 errmsg ("tunnel src address not specified\n");
7248 errmsg ("tunnel dst address not specified\n");
7253 errmsg ("spi not specified\n");
7258 errmsg ("si not specified\n");
7262 errmsg ("vni not specified\n");
7266 M2 (NSH_VXLAN_GPE_ADD_DEL_TUNNEL, nsh_vxlan_gpe_add_del_tunnel,
7267 sizeof(u32) * vec_len (tlvs));
7269 spi_si = (spi<<8) | si;
7271 mp->src = src.as_u32;
7272 mp->dst = dst.as_u32;
7273 mp->encap_vrf_id = ntohl(encap_vrf_id);
7274 mp->decap_vrf_id = ntohl(decap_vrf_id);
7275 mp->decap_next_index = ntohl(decap_next_index);
7276 mp->tlv_len_in_words = vec_len (tlvs);
7277 mp->vni = ntohl(vni);
7278 mp->is_add = is_add;
7279 mp->ver_o_c = ver_o_c;
7280 mp->length = 6 + vec_len(tlvs);
7281 mp->md_type = md_type;
7282 mp->next_protocol = next_protocol;
7283 mp->spi_si = ntohl(spi_si);
7289 for (i = 0; i < vec_len(tlvs); i++)
7290 mp->tlvs[i] = ntohl(tlvs[i]);
7299 static uword unformat_lisp_gpe_decap_next (unformat_input_t * input,
7302 u32 * result = va_arg (*args, u32 *);
7305 if (unformat (input, "drop"))
7306 *result = LISP_GPE_INPUT_NEXT_DROP;
7307 else if (unformat (input, "ip4"))
7308 *result = LISP_GPE_INPUT_NEXT_IP4_INPUT;
7309 else if (unformat (input, "ip6"))
7310 *result = LISP_GPE_INPUT_NEXT_IP6_INPUT;
7311 else if (unformat (input, "ethernet"))
7312 *result = LISP_GPE_INPUT_NEXT_IP6_INPUT;
7313 else if (unformat (input, "lisp-gpe"))
7314 *result = LISP_GPE_INPUT_NEXT_LISP_GPE_ENCAP;
7315 else if (unformat (input, "%d", &tmp))
7323 api_lisp_gpe_add_del_tunnel (vat_main_t * vam)
7325 unformat_input_t * line_input = vam->input;
7326 vl_api_lisp_gpe_add_del_tunnel_t *mp;
7328 ip4_address_t src, dst;
7332 u32 encap_vrf_id = 0;
7333 u32 decap_vrf_id = 0;
7334 u8 next_protocol = LISP_GPE_NEXT_PROTOCOL_IP4;
7335 u32 decap_next_index = LISP_GPE_INPUT_NEXT_IP4_INPUT;
7336 u8 flags = LISP_GPE_FLAGS_P;
7343 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) {
7344 if (unformat (line_input, "del"))
7346 else if (unformat (line_input, "src %U",
7347 unformat_ip4_address, &src))
7349 else if (unformat (line_input, "dst %U",
7350 unformat_ip4_address, &dst))
7352 else if (unformat (line_input, "encap-vrf-id %d", &encap_vrf_id))
7354 else if (unformat (line_input, "decap-vrf-id %d", &decap_vrf_id))
7356 else if (unformat (line_input, "decap-next %U",
7357 unformat_lisp_gpe_decap_next,
7360 else if (unformat(line_input, "next-ip4"))
7362 else if (unformat(line_input, "next-ip6"))
7364 else if (unformat(line_input, "next-ethernet"))
7366 else if (unformat(line_input, "next-nsh"))
7368 /* Allow the user to specify anything they want in the LISP hdr */
7369 else if (unformat (line_input, "ver_res %x", &tmp))
7371 else if (unformat (line_input, "res %x", &tmp))
7373 else if (unformat (line_input, "flags %x", &tmp))
7375 else if (unformat (line_input, "n-bit"))
7376 flags |= LISP_GPE_FLAGS_N;
7377 else if (unformat (line_input, "l-bit"))
7378 flags |= LISP_GPE_FLAGS_L;
7379 else if (unformat (line_input, "e-bit"))
7380 flags |= LISP_GPE_FLAGS_E;
7381 else if (unformat (line_input, "v-bit"))
7382 flags |= LISP_GPE_FLAGS_V;
7383 else if (unformat (line_input, "i-bit"))
7384 flags |= LISP_GPE_FLAGS_V;
7385 else if (unformat (line_input, "not-p-bit"))
7386 flags &= !LISP_GPE_FLAGS_P;
7387 else if (unformat (line_input, "p-bit"))
7388 flags |= LISP_GPE_FLAGS_P;
7389 else if (unformat (line_input, "o-bit"))
7390 flags |= LISP_GPE_FLAGS_O;
7391 else if (unformat (line_input, "iidx %x", &iid))
7393 else if (unformat (line_input, "iid %d", &iid))
7396 errmsg ("parse error '%U'\n", format_unformat_error, line_input);
7402 errmsg ("tunnel src address not specified\n");
7406 errmsg ("tunnel dst address not specified\n");
7410 errmsg ("iid not specified\n");
7414 M(LISP_GPE_ADD_DEL_TUNNEL, lisp_gpe_add_del_tunnel);
7416 mp->src = src.as_u32;
7417 mp->dst = dst.as_u32;
7418 mp->encap_vrf_id = ntohl(encap_vrf_id);
7419 mp->decap_vrf_id = ntohl(decap_vrf_id);
7420 mp->decap_next_index = ntohl(decap_next_index);
7421 mp->is_add = is_add;
7423 mp->ver_res = ver_res;
7425 mp->next_protocol = next_protocol;
7426 mp->iid = ntohl(iid);
7435 u8 * format_l2_fib_mac_address (u8 * s, va_list * args)
7437 u8 * a = va_arg (*args, u8 *);
7439 return format (s, "%02x:%02x:%02x:%02x:%02x:%02x",
7440 a[2], a[3], a[4], a[5], a[6], a[7]);
7443 static void vl_api_l2_fib_table_entry_t_handler
7444 (vl_api_l2_fib_table_entry_t * mp)
7446 vat_main_t * vam = &vat_main;
7448 fformat(vam->ofp, "%3" PRIu32 " %U %3" PRIu32
7450 ntohl(mp->bd_id), format_l2_fib_mac_address, &mp->mac,
7451 ntohl(mp->sw_if_index), mp->static_mac, mp->filter_mac,
7455 static void vl_api_l2_fib_table_entry_t_handler_json
7456 (vl_api_l2_fib_table_entry_t * mp)
7458 vat_main_t * vam = &vat_main;
7459 vat_json_node_t *node = NULL;
7461 if (VAT_JSON_ARRAY != vam->json_tree.type) {
7462 ASSERT(VAT_JSON_NONE == vam->json_tree.type);
7463 vat_json_init_array(&vam->json_tree);
7465 node = vat_json_array_add(&vam->json_tree);
7467 vat_json_init_object(node);
7468 vat_json_object_add_uint(node, "bd_id", ntohl(mp->bd_id));
7469 vat_json_object_add_uint(node, "mac", clib_net_to_host_u64(mp->mac));
7470 vat_json_object_add_uint(node, "sw_if_index", ntohl(mp->sw_if_index));
7471 vat_json_object_add_uint(node, "static_mac", mp->static_mac);
7472 vat_json_object_add_uint(node, "filter_mac", mp->filter_mac);
7473 vat_json_object_add_uint(node, "bvi_mac", mp->bvi_mac);
7476 static int api_l2_fib_table_dump (vat_main_t * vam)
7478 unformat_input_t * i = vam->input;
7479 vl_api_l2_fib_table_dump_t *mp;
7484 /* Parse args required to build the message */
7485 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
7486 if (unformat (i, "bd_id %d", &bd_id))
7492 if (bd_id_set == 0) {
7493 errmsg ("missing bridge domain\n");
7497 fformat(vam->ofp, "BD-ID Mac Address sw-ndx Static Filter BVI\n");
7499 /* Get list of l2 fib entries */
7500 M(L2_FIB_TABLE_DUMP, l2_fib_table_dump);
7502 mp->bd_id = ntohl(bd_id);
7505 /* Use a control ping for synchronization */
7507 vl_api_control_ping_t * mp;
7508 M(CONTROL_PING, control_ping);
7516 api_interface_name_renumber (vat_main_t * vam)
7518 unformat_input_t * line_input = vam->input;
7519 vl_api_interface_name_renumber_t *mp;
7520 u32 sw_if_index = ~0;
7522 u32 new_show_dev_instance = ~0;
7524 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) {
7525 if (unformat (line_input, "%U", unformat_sw_if_index, vam,
7528 else if (unformat (line_input, "sw_if_index %d", &sw_if_index))
7530 else if (unformat (line_input, "new_show_dev_instance %d",
7531 &new_show_dev_instance))
7537 if (sw_if_index == ~0) {
7538 errmsg ("missing interface name or sw_if_index\n");
7542 if (new_show_dev_instance == ~0) {
7543 errmsg ("missing new_show_dev_instance\n");
7547 M(INTERFACE_NAME_RENUMBER, interface_name_renumber);
7549 mp->sw_if_index = ntohl (sw_if_index);
7550 mp->new_show_dev_instance = ntohl (new_show_dev_instance);
7556 api_want_ip4_arp_events (vat_main_t * vam)
7558 unformat_input_t * line_input = vam->input;
7559 vl_api_want_ip4_arp_events_t * mp;
7561 ip4_address_t address;
7562 int address_set = 0;
7563 u32 enable_disable = 1;
7565 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) {
7566 if (unformat (line_input, "address %U",
7567 unformat_ip4_address, &address))
7569 else if (unformat (line_input, "del"))
7575 if (address_set == 0) {
7576 errmsg ("missing addresses\n");
7580 M(WANT_IP4_ARP_EVENTS, want_ip4_arp_events);
7581 mp->enable_disable = enable_disable;
7583 mp->address = address.as_u32;
7588 static int api_input_acl_set_interface (vat_main_t * vam)
7590 unformat_input_t * i = vam->input;
7591 vl_api_input_acl_set_interface_t *mp;
7594 int sw_if_index_set;
7595 u32 ip4_table_index = ~0;
7596 u32 ip6_table_index = ~0;
7597 u32 l2_table_index = ~0;
7600 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
7601 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
7602 sw_if_index_set = 1;
7603 else if (unformat (i, "sw_if_index %d", &sw_if_index))
7604 sw_if_index_set = 1;
7605 else if (unformat (i, "del"))
7607 else if (unformat (i, "ip4-table %d", &ip4_table_index))
7609 else if (unformat (i, "ip6-table %d", &ip6_table_index))
7611 else if (unformat (i, "l2-table %d", &l2_table_index))
7614 clib_warning ("parse error '%U'", format_unformat_error, i);
7619 if (sw_if_index_set == 0) {
7620 errmsg ("missing interface name or sw_if_index\n");
7624 M(INPUT_ACL_SET_INTERFACE, input_acl_set_interface);
7626 mp->sw_if_index = ntohl(sw_if_index);
7627 mp->ip4_table_index = ntohl(ip4_table_index);
7628 mp->ip6_table_index = ntohl(ip6_table_index);
7629 mp->l2_table_index = ntohl(l2_table_index);
7630 mp->is_add = is_add;
7638 api_ip_address_dump (vat_main_t * vam)
7640 unformat_input_t * i = vam->input;
7641 vl_api_ip_address_dump_t * mp;
7642 u32 sw_if_index = ~0;
7643 u8 sw_if_index_set = 0;
7648 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
7649 if (unformat (i, "sw_if_index %d", &sw_if_index))
7650 sw_if_index_set = 1;
7651 else if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
7652 sw_if_index_set = 1;
7653 else if (unformat (i, "ipv4"))
7655 else if (unformat (i, "ipv6"))
7661 if (ipv4_set && ipv6_set) {
7662 errmsg ("ipv4 and ipv6 flags cannot be both set\n");
7666 if ((!ipv4_set) && (!ipv6_set)) {
7667 errmsg ("no ipv4 nor ipv6 flag set\n");
7671 if (sw_if_index_set == 0) {
7672 errmsg ("missing interface name or sw_if_index\n");
7676 vam->current_sw_if_index = sw_if_index;
7677 vam->is_ipv6 = ipv6_set;
7679 M(IP_ADDRESS_DUMP, ip_address_dump);
7680 mp->sw_if_index = ntohl(sw_if_index);
7681 mp->is_ipv6 = ipv6_set;
7684 /* Use a control ping for synchronization */
7686 vl_api_control_ping_t * mp;
7687 M(CONTROL_PING, control_ping);
7694 api_ip_dump (vat_main_t * vam)
7696 vl_api_ip_dump_t * mp;
7697 unformat_input_t * in = vam->input;
7704 while (unformat_check_input (in) != UNFORMAT_END_OF_INPUT) {
7705 if (unformat (in, "ipv4"))
7707 else if (unformat (in, "ipv6"))
7713 if (ipv4_set && ipv6_set) {
7714 errmsg ("ipv4 and ipv6 flags cannot be both set\n");
7718 if ((!ipv4_set) && (!ipv6_set)) {
7719 errmsg ("no ipv4 nor ipv6 flag set\n");
7724 vam->is_ipv6 = is_ipv6;
7727 for (i = 0; i < vec_len(vam->ip_details_by_sw_if_index[is_ipv6]); i++) {
7728 vec_free(vam->ip_details_by_sw_if_index[is_ipv6][i].addr);
7730 vec_free(vam->ip_details_by_sw_if_index[is_ipv6]);
7732 M(IP_DUMP, ip_dump);
7733 mp->is_ipv6 = ipv6_set;
7736 /* Use a control ping for synchronization */
7738 vl_api_control_ping_t * mp;
7739 M(CONTROL_PING, control_ping);
7746 api_ipsec_spd_add_del (vat_main_t * vam)
7749 unformat_input_t * i = vam->input;
7750 vl_api_ipsec_spd_add_del_t *mp;
7755 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
7756 if (unformat (i, "spd_id %d", &spd_id))
7758 else if (unformat (i, "del"))
7761 clib_warning ("parse error '%U'", format_unformat_error, i);
7766 errmsg ("spd_id must be set\n");
7770 M(IPSEC_SPD_ADD_DEL, ipsec_spd_add_del);
7772 mp->spd_id = ntohl(spd_id);
7773 mp->is_add = is_add;
7779 clib_warning ("unsupported (no dpdk)");
7785 api_ipsec_interface_add_del_spd (vat_main_t * vam)
7788 unformat_input_t * i = vam->input;
7789 vl_api_ipsec_interface_add_del_spd_t *mp;
7792 u8 sw_if_index_set = 0;
7793 u32 spd_id = (u32) ~0;
7796 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
7797 if (unformat (i, "del"))
7799 else if (unformat (i, "spd_id %d", &spd_id))
7801 else if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
7802 sw_if_index_set = 1;
7803 else if (unformat (i, "sw_if_index %d", &sw_if_index))
7804 sw_if_index_set = 1;
7806 clib_warning ("parse error '%U'", format_unformat_error, i);
7812 if (spd_id == (u32) ~0) {
7813 errmsg ("spd_id must be set\n");
7817 if (sw_if_index_set == 0) {
7818 errmsg ("missing interface name or sw_if_index\n");
7822 M(IPSEC_INTERFACE_ADD_DEL_SPD, ipsec_interface_add_del_spd);
7824 mp->spd_id = ntohl(spd_id);
7825 mp->sw_if_index = ntohl (sw_if_index);
7826 mp->is_add = is_add;
7832 clib_warning ("unsupported (no dpdk)");
7838 api_ipsec_spd_add_del_entry (vat_main_t * vam)
7841 unformat_input_t * i = vam->input;
7842 vl_api_ipsec_spd_add_del_entry_t *mp;
7844 u8 is_add = 1, is_outbound = 0, is_ipv6 = 0, is_ip_any = 1;
7845 u32 spd_id, sa_id, protocol = 0, policy = 0;
7847 u32 rport_start = 0, rport_stop = (u32) ~0;
7848 u32 lport_start = 0, lport_stop = (u32) ~0;
7849 ip4_address_t laddr4_start, laddr4_stop, raddr4_start, raddr4_stop;
7850 ip6_address_t laddr6_start, laddr6_stop, raddr6_start, raddr6_stop;
7852 laddr4_start.as_u32 = raddr4_start.as_u32 = 0;
7853 laddr4_stop.as_u32 = raddr4_stop.as_u32 = (u32) ~0;
7854 laddr6_start.as_u64[0] = raddr6_start.as_u64[0] = 0;
7855 laddr6_start.as_u64[1] = raddr6_start.as_u64[1] = 0;
7856 laddr6_stop.as_u64[0] = raddr6_stop.as_u64[0] = (u64) ~0;
7857 laddr6_stop.as_u64[1] = raddr6_stop.as_u64[1] = (u64) ~0;
7859 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
7860 if (unformat (i, "del"))
7862 if (unformat (i, "outbound"))
7864 if (unformat (i, "inbound"))
7866 else if (unformat (i, "spd_id %d", &spd_id))
7868 else if (unformat (i, "sa_id %d", &sa_id))
7870 else if (unformat (i, "priority %d", &priority))
7872 else if (unformat (i, "protocol %d", &protocol))
7874 else if (unformat (i, "lport_start %d", &lport_start))
7876 else if (unformat (i, "lport_stop %d", &lport_stop))
7878 else if (unformat (i, "rport_start %d", &rport_start))
7880 else if (unformat (i, "rport_stop %d", &rport_stop))
7882 else if (unformat (i, "laddr_start %U", unformat_ip4_address, &laddr4_start))
7887 else if (unformat (i, "laddr_stop %U", unformat_ip4_address, &laddr4_stop))
7892 else if (unformat (i, "raddr_start %U", unformat_ip4_address, &raddr4_start))
7897 else if (unformat (i, "raddr_stop %U", unformat_ip4_address, &raddr4_stop))
7902 else if (unformat (i, "laddr_start %U", unformat_ip6_address, &laddr6_start))
7907 else if (unformat (i, "laddr_stop %U", unformat_ip6_address, &laddr6_stop))
7912 else if (unformat (i, "raddr_start %U", unformat_ip6_address, &raddr6_start))
7917 else if (unformat (i, "raddr_stop %U", unformat_ip6_address, &raddr6_stop))
7922 else if (unformat (i, "action %U", unformat_ipsec_policy_action, &policy))
7924 if (policy == IPSEC_POLICY_ACTION_RESOLVE) {
7925 clib_warning ("unsupported action: 'resolve'");
7930 clib_warning ("parse error '%U'", format_unformat_error, i);
7936 M(IPSEC_SPD_ADD_DEL_ENTRY, ipsec_spd_add_del_entry);
7938 mp->spd_id = ntohl(spd_id);
7939 mp->priority = ntohl(priority);
7940 mp->is_outbound = is_outbound;
7942 mp->is_ipv6 = is_ipv6;
7943 if (is_ipv6 || is_ip_any) {
7944 memcpy (mp->remote_address_start, &raddr6_start, sizeof(ip6_address_t));
7945 memcpy (mp->remote_address_stop, &raddr6_stop, sizeof(ip6_address_t));
7946 memcpy (mp->local_address_start, &laddr6_start, sizeof(ip6_address_t));
7947 memcpy (mp->local_address_stop, &laddr6_stop, sizeof(ip6_address_t));
7949 memcpy (mp->remote_address_start, &raddr4_start, sizeof(ip4_address_t));
7950 memcpy (mp->remote_address_stop, &raddr4_stop, sizeof(ip4_address_t));
7951 memcpy (mp->local_address_start, &laddr4_start, sizeof(ip4_address_t));
7952 memcpy (mp->local_address_stop, &laddr4_stop, sizeof(ip4_address_t));
7954 mp->protocol = (u8) protocol;
7955 mp->local_port_start = ntohs((u16) lport_start);
7956 mp->local_port_stop = ntohs((u16) lport_stop);
7957 mp->remote_port_start = ntohs((u16) rport_start);
7958 mp->remote_port_stop = ntohs((u16) rport_stop);
7959 mp->policy = (u8) policy;
7960 mp->sa_id = ntohl(sa_id);
7961 mp->is_add = is_add;
7962 mp->is_ip_any = is_ip_any;
7967 clib_warning ("unsupported (no dpdk)");
7973 api_ipsec_sad_add_del_entry (vat_main_t * vam)
7976 unformat_input_t * i = vam->input;
7977 vl_api_ipsec_sad_add_del_entry_t *mp;
7983 u8 protocol = IPSEC_PROTOCOL_AH;
7984 u8 is_tunnel = 0, is_tunnel_ipv6 = 0;
7985 u32 crypto_alg = 0, integ_alg = 0;
7986 ip4_address_t tun_src4;
7987 ip4_address_t tun_dst4;
7988 ip6_address_t tun_src6;
7989 ip6_address_t tun_dst6;
7991 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
7992 if (unformat (i, "del"))
7994 else if (unformat (i, "sad_id %d", &sad_id))
7996 else if (unformat (i, "spi %d", &spi))
7998 else if (unformat (i, "esp"))
7999 protocol = IPSEC_PROTOCOL_ESP;
8000 else if (unformat (i, "tunnel_src %U", unformat_ip4_address, &tun_src4)) {
8004 else if (unformat (i, "tunnel_dst %U", unformat_ip4_address, &tun_dst4)) {
8008 else if (unformat (i, "tunnel_src %U", unformat_ip6_address, &tun_src6)) {
8012 else if (unformat (i, "tunnel_dst %U", unformat_ip6_address, &tun_dst6)) {
8016 else if (unformat (i, "crypto_alg %U", unformat_ipsec_crypto_alg, &crypto_alg)) {
8017 if (crypto_alg < IPSEC_CRYPTO_ALG_AES_CBC_128 ||
8018 crypto_alg > IPSEC_INTEG_ALG_SHA_512_256) {
8019 clib_warning ("unsupported crypto-alg: '%U'",
8020 format_ipsec_crypto_alg, crypto_alg);
8024 else if (unformat (i, "crypto_key %U", unformat_hex_string, &ck))
8026 else if (unformat (i, "integ_alg %U", unformat_ipsec_integ_alg, &integ_alg)) {
8027 if (integ_alg < IPSEC_INTEG_ALG_SHA1_96 ||
8028 integ_alg > IPSEC_INTEG_ALG_SHA_512_256) {
8029 clib_warning ("unsupported integ-alg: '%U'",
8030 format_ipsec_integ_alg, integ_alg);
8034 else if (unformat (i, "integ_key %U", unformat_hex_string, &ik))
8037 clib_warning ("parse error '%U'", format_unformat_error, i);
8043 M(IPSEC_SAD_ADD_DEL_ENTRY, ipsec_sad_add_del_entry);
8045 mp->sad_id = ntohl(sad_id);
8046 mp->is_add = is_add;
8047 mp->protocol = protocol;
8048 mp->spi = ntohl(spi);
8049 mp->is_tunnel = is_tunnel;
8050 mp->is_tunnel_ipv6 = is_tunnel_ipv6;
8051 mp->crypto_algorithm = crypto_alg;
8052 mp->integrity_algorithm = integ_alg;
8053 mp->crypto_key_length = vec_len(ck);
8054 mp->integrity_key_length = vec_len(ik);
8056 if (mp->crypto_key_length > sizeof(mp->crypto_key))
8057 mp->crypto_key_length = sizeof(mp->crypto_key);
8059 if (mp->integrity_key_length > sizeof(mp->integrity_key))
8060 mp->integrity_key_length = sizeof(mp->integrity_key);
8062 memcpy (mp->crypto_key, ck, mp->crypto_key_length);
8063 memcpy (mp->integrity_key, ik, mp->integrity_key_length);
8066 if (is_tunnel_ipv6) {
8067 memcpy (mp->tunnel_src_address, &tun_src6, sizeof(ip6_address_t));
8068 memcpy (mp->tunnel_dst_address, &tun_dst6, sizeof(ip6_address_t));
8070 memcpy (mp->tunnel_src_address, &tun_src4, sizeof(ip4_address_t));
8071 memcpy (mp->tunnel_dst_address, &tun_dst4, sizeof(ip4_address_t));
8079 clib_warning ("unsupported (no dpdk)");
8085 api_ipsec_sa_set_key (vat_main_t * vam)
8088 unformat_input_t * i = vam->input;
8089 vl_api_ipsec_sa_set_key_t *mp;
8094 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
8095 if (unformat (i, "sa_id %d", &sa_id))
8097 else if (unformat (i, "crypto_key %U", unformat_hex_string, &ck))
8099 else if (unformat (i, "integ_key %U", unformat_hex_string, &ik))
8102 clib_warning ("parse error '%U'", format_unformat_error, i);
8107 M(IPSEC_SA_SET_KEY, ipsec_set_sa_key);
8109 mp->sa_id = ntohl(sa_id);
8110 mp->crypto_key_length = vec_len(ck);
8111 mp->integrity_key_length = vec_len(ik);
8113 if (mp->crypto_key_length > sizeof(mp->crypto_key))
8114 mp->crypto_key_length = sizeof(mp->crypto_key);
8116 if (mp->integrity_key_length > sizeof(mp->integrity_key))
8117 mp->integrity_key_length = sizeof(mp->integrity_key);
8119 memcpy (mp->crypto_key, ck, mp->crypto_key_length);
8120 memcpy (mp->integrity_key, ik, mp->integrity_key_length);
8126 clib_warning ("unsupported (no dpdk)");
8134 static int api_map_add_domain (vat_main_t * vam)
8136 unformat_input_t *i = vam->input;
8137 vl_api_map_add_domain_t *mp;
8140 ip4_address_t ip4_prefix;
8141 ip6_address_t ip6_prefix;
8142 ip6_address_t ip6_src;
8144 u32 ip6_prefix_len, ip4_prefix_len, ea_bits_len, psid_offset,
8146 u8 is_translation = 0;
8148 u8 ip6_src_len = 128;
8150 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
8151 if (unformat (i, "ip4-pfx %U/%d", unformat_ip4_address,
8152 &ip4_prefix, &ip4_prefix_len))
8154 else if (unformat (i, "ip6-pfx %U/%d", unformat_ip6_address,
8155 &ip6_prefix, &ip6_prefix_len))
8157 else if (unformat (i, "ip6-src %U/%d", unformat_ip6_address, &ip6_src, &ip6_src_len))
8159 else if (unformat (i, "ip6-src %U", unformat_ip6_address, &ip6_src))
8161 else if (unformat (i, "ea-bits-len %d", &ea_bits_len))
8163 else if (unformat (i, "psid-offset %d", &psid_offset))
8165 else if (unformat (i, "psid-len %d", &psid_length))
8167 else if (unformat (i, "mtu %d", &mtu))
8169 else if (unformat (i, "map-t"))
8172 clib_warning ("parse error '%U'", format_unformat_error, i);
8177 if (num_m_args != 6) {
8178 errmsg("mandatory argument(s) missing\n");
8182 /* Construct the API message */
8183 M(MAP_ADD_DOMAIN, map_add_domain);
8185 memcpy(mp->ip4_prefix, &ip4_prefix, sizeof(ip4_prefix));
8186 mp->ip4_prefix_len = ip4_prefix_len;
8188 memcpy(mp->ip6_prefix, &ip6_prefix, sizeof(ip6_prefix));
8189 mp->ip6_prefix_len = ip6_prefix_len;
8191 memcpy(mp->ip6_src, &ip6_src, sizeof(ip6_src));
8192 mp->ip6_src_prefix_len = ip6_src_len;
8194 mp->ea_bits_len = ea_bits_len;
8195 mp->psid_offset = psid_offset;
8196 mp->psid_length = psid_length;
8197 mp->is_translation = is_translation;
8198 mp->mtu = htons(mtu);
8203 /* Wait for a reply, return good/bad news */
8207 static int api_map_del_domain (vat_main_t * vam)
8209 unformat_input_t *i = vam->input;
8210 vl_api_map_del_domain_t *mp;
8216 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
8217 if (unformat (i, "index %d", &index))
8220 clib_warning ("parse error '%U'", format_unformat_error, i);
8225 if (num_m_args != 1) {
8226 errmsg("mandatory argument(s) missing\n");
8230 /* Construct the API message */
8231 M(MAP_DEL_DOMAIN, map_del_domain);
8233 mp->index = ntohl(index);
8238 /* Wait for a reply, return good/bad news */
8242 static int api_map_add_del_rule (vat_main_t * vam)
8244 unformat_input_t *i = vam->input;
8245 vl_api_map_add_del_rule_t *mp;
8248 ip6_address_t ip6_dst;
8249 u32 num_m_args = 0, index, psid;
8251 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
8252 if (unformat (i, "index %d", &index))
8254 else if (unformat (i, "psid %d", &psid))
8256 else if (unformat (i, "dst %U", unformat_ip6_address, &ip6_dst))
8258 else if (unformat (i, "del")) {
8261 clib_warning ("parse error '%U'", format_unformat_error, i);
8266 /* Construct the API message */
8267 M(MAP_ADD_DEL_RULE, map_add_del_rule);
8269 mp->index = ntohl(index);
8270 mp->is_add = is_add;
8271 memcpy(mp->ip6_dst, &ip6_dst, sizeof(ip6_dst));
8272 mp->psid = ntohs(psid);
8277 /* Wait for a reply, return good/bad news */
8281 static int api_map_domain_dump (vat_main_t * vam)
8283 vl_api_map_domain_dump_t *mp;
8286 /* Construct the API message */
8287 M(MAP_DOMAIN_DUMP, map_domain_dump);
8292 /* Use a control ping for synchronization */
8294 vl_api_control_ping_t * mp;
8295 M(CONTROL_PING, control_ping);
8301 static int api_map_rule_dump (vat_main_t * vam)
8303 unformat_input_t *i = vam->input;
8304 vl_api_map_rule_dump_t *mp;
8306 u32 domain_index = ~0;
8308 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
8309 if (unformat (i, "index %u", &domain_index))
8315 if (domain_index == ~0) {
8316 clib_warning("parse error: domain index expected");
8320 /* Construct the API message */
8321 M(MAP_RULE_DUMP, map_rule_dump);
8323 mp->domain_index = htonl(domain_index);
8328 /* Use a control ping for synchronization */
8330 vl_api_control_ping_t * mp;
8331 M(CONTROL_PING, control_ping);
8337 static void vl_api_map_add_domain_reply_t_handler
8338 (vl_api_map_add_domain_reply_t * mp)
8340 vat_main_t * vam = &vat_main;
8341 i32 retval = ntohl(mp->retval);
8343 if (vam->async_mode) {
8344 vam->async_errors += (retval < 0);
8346 vam->retval = retval;
8347 vam->result_ready = 1;
8351 static void vl_api_map_add_domain_reply_t_handler_json
8352 (vl_api_map_add_domain_reply_t * mp)
8354 vat_main_t * vam = &vat_main;
8355 vat_json_node_t node;
8357 vat_json_init_object(&node);
8358 vat_json_object_add_int(&node, "retval", ntohl(mp->retval));
8359 vat_json_object_add_uint(&node, "index", ntohl(mp->index));
8361 vat_json_print(vam->ofp, &node);
8362 vat_json_free(&node);
8364 vam->retval = ntohl(mp->retval);
8365 vam->result_ready = 1;
8369 api_get_first_msg_id (vat_main_t * vam)
8371 vl_api_get_first_msg_id_t * mp;
8373 unformat_input_t * i = vam->input;
8377 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
8378 if (unformat (i, "client %s", &name))
8384 if (name_set == 0) {
8385 errmsg ("missing client name\n");
8390 if (vec_len (name) > 63) {
8391 errmsg ("client name too long\n");
8395 M(GET_FIRST_MSG_ID, get_first_msg_id);
8396 memcpy (mp->name, name, vec_len(name));
8402 static int q_or_quit (vat_main_t * vam)
8404 longjmp (vam->jump_buf, 1);
8405 return 0; /* not so much */
8407 static int q (vat_main_t * vam) {return q_or_quit (vam);}
8408 static int quit (vat_main_t * vam) {return q_or_quit (vam);}
8410 static int comment (vat_main_t * vam)
8415 static int cmd_cmp (void * a1, void * a2)
8420 return strcmp ((char *)(c1[0]), (char *)(c2[0]));
8423 static int help (vat_main_t * vam)
8428 unformat_input_t * i = vam->input;
8431 if (unformat (i, "%s", &name)) {
8436 hs = hash_get_mem (vam->help_by_name, name);
8438 fformat (vam->ofp, "usage: %s %s\n", name, hs[0]);
8440 fformat (vam->ofp, "No such msg / command '%s'\n", name);
8445 fformat(vam->ofp, "Help is available for the following:\n");
8447 hash_foreach_pair (p, vam->function_by_name,
8449 vec_add1 (cmds, (u8 *)(p->key));
8452 vec_sort_with_function (cmds, cmd_cmp);
8454 for (j = 0; j < vec_len(cmds); j++)
8455 fformat (vam->ofp, "%s\n", cmds[j]);
8461 static int set (vat_main_t * vam)
8463 u8 * name = 0, * value = 0;
8464 unformat_input_t * i = vam->input;
8466 if (unformat (i, "%s", &name)) {
8467 /* The input buffer is a vector, not a string. */
8468 value = vec_dup (i->buffer);
8469 vec_delete (value, i->index, 0);
8470 /* Almost certainly has a trailing newline */
8471 if (value[vec_len(value)-1] == '\n')
8472 value[vec_len(value)-1] = 0;
8473 /* Make sure it's a proper string, one way or the other */
8474 vec_add1 (value, 0);
8475 (void) clib_macro_set_value (&vam->macro_main,
8476 (char *)name, (char *)value);
8479 errmsg ("usage: set <name> <value>\n");
8486 static int unset (vat_main_t * vam)
8490 if (unformat (vam->input, "%s", &name))
8491 if (clib_macro_unset (&vam->macro_main, (char *)name) == 1)
8492 errmsg ("unset: %s wasn't set\n", name);
8503 static int macro_sort_cmp (void * a1, void * a2)
8505 macro_sort_t * s1 = a1;
8506 macro_sort_t * s2 = a2;
8508 return strcmp ((char *)(s1->name), (char *)(s2->name));
8511 static int dump_macro_table (vat_main_t * vam)
8513 macro_sort_t * sort_me = 0, * sm;
8517 hash_foreach_pair (p, vam->macro_main.the_value_table_hash,
8519 vec_add2 (sort_me, sm, 1);
8520 sm->name = (u8 *)(p->key);
8521 sm->value = (u8 *) (p->value[0]);
8524 vec_sort_with_function (sort_me, macro_sort_cmp);
8526 if (vec_len(sort_me))
8527 fformat (vam->ofp, "%-15s%s\n", "Name", "Value");
8529 fformat (vam->ofp, "The macro table is empty...\n");
8531 for (i = 0; i < vec_len (sort_me); i++)
8532 fformat (vam->ofp, "%-15s%s\n", sort_me[i].name,
8537 static int script (vat_main_t * vam)
8540 char * save_current_file;
8541 unformat_input_t save_input;
8542 jmp_buf save_jump_buf;
8543 u32 save_line_number;
8545 FILE * new_fp, * save_ifp;
8547 if (unformat (vam->input, "%s", &s)) {
8548 new_fp = fopen ((char *)s, "r");
8550 errmsg ("Couldn't open script file %s\n", s);
8555 errmsg ("Missing script name\n");
8559 memcpy (&save_input, &vam->input, sizeof (save_input));
8560 memcpy (&save_jump_buf, &vam->jump_buf, sizeof (save_jump_buf));
8561 save_ifp = vam->ifp;
8562 save_line_number = vam->input_line_number;
8563 save_current_file = (char *) vam->current_file;
8565 vam->input_line_number = 0;
8567 vam->current_file = s;
8570 memcpy (&vam->input, &save_input, sizeof (vam->input));
8571 memcpy (&vam->jump_buf, &save_jump_buf, sizeof (save_jump_buf));
8572 vam->ifp = save_ifp;
8573 vam->input_line_number = save_line_number;
8574 vam->current_file = (u8 *) save_current_file;
8580 static int echo (vat_main_t * vam)
8582 fformat (vam->ofp, "%v", vam->input->buffer);
8586 /* List of API message constructors, CLI names map to api_xxx */
8587 #define foreach_vpe_api_msg \
8588 _(create_loopback,"[mac <mac-addr>]") \
8589 _(sw_interface_dump,"") \
8590 _(sw_interface_set_flags, \
8591 "<intfc> | sw_if_index <id> admin-up | admin-down link-up | link down") \
8592 _(sw_interface_add_del_address, \
8593 "<intfc> | sw_if_index <id> <ip4-address> | <ip6-address> [del] [del-all] ") \
8594 _(sw_interface_set_table, \
8595 "<intfc> | sw_if_index <id> vrf <table-id> [ipv6]") \
8596 _(sw_interface_set_vpath, \
8597 "<intfc> | sw_if_index <id> enable | disable") \
8598 _(sw_interface_set_l2_xconnect, \
8599 "rx <intfc> | rx_sw_if_index <id> tx <intfc> | tx_sw_if_index <id>\n" \
8600 "enable | disable") \
8601 _(sw_interface_set_l2_bridge, \
8602 "rx <intfc> | rx_sw_if_index <id> bd_id <bridge-domain-id>\n" \
8603 "[shg <split-horizon-group>] [bvi]\n" \
8604 "enable | disable") \
8605 _(bridge_domain_add_del, \
8606 "bd_id <bridge-domain-id> [flood 1|0] [uu-flood 1|0] [forward 1|0] [learn 1|0] [arp-term 1|0] [del]\n")\
8607 _(bridge_domain_dump, "[bd_id <bridge-domain-id>]\n") \
8609 "mac <mac-addr> bd_id <bridge-domain-id> [del] | sw_if <intfc> | sw_if_index <id> [static] [filter] [bvi]\n") \
8611 "sw_if <intfc> | sw_if_index <id> [learn] [forward] [uu-flood] [flood]\n") \
8613 "bd_id <bridge-domain-id> [learn] [forward] [uu-flood] [flood] [arp-term] [disable]\n") \
8615 "tapname <name> mac <mac-addr> | random-mac") \
8617 "<vpp-if-name> | sw_if_index <id> tapname <name> mac <mac-addr> | random-mac") \
8619 "<vpp-if-name> | sw_if_index <id>") \
8620 _(sw_interface_tap_dump, "") \
8621 _(ip_add_del_route, \
8622 "<addr>/<mask> via <addr> [vrf <n>]\n" \
8623 "[<intfc> | sw_if_index <id>] [resolve-attempts <n>]\n" \
8624 "[weight <n>] [drop] [local] [classify <n>] [del]\n" \
8625 "[multipath] [count <n>]") \
8626 _(proxy_arp_add_del, \
8627 "<lo-ip4-addr> - <hi-ip4-addr> [vrf <n>] [del]") \
8628 _(proxy_arp_intfc_enable_disable, \
8629 "<intfc> | sw_if_index <id> enable | disable") \
8630 _(mpls_add_del_encap, \
8631 "label <n> dst <ip4-addr> [vrf <n>] [del]") \
8632 _(mpls_add_del_decap, \
8633 "label <n> [rx_vrf_id <n>] [tx_vrf_id] [s-bit-clear][del]") \
8634 _(mpls_gre_add_del_tunnel, \
8635 "inner_vrf_id <n> outer_vrf_id <n> src <ip4-address> dst <ip4-address>\n" \
8636 "adj <ip4-address>/<mask-width> [del]") \
8637 _(sw_interface_set_unnumbered, \
8638 "<intfc> | sw_if_index <id> unnum_if_index <id> [del]") \
8639 _(ip_neighbor_add_del, \
8640 "<intfc> | sw_if_index <id> dst <ip46-address> mac <mac-addr>") \
8641 _(reset_vrf, "vrf <id> [ipv6]") \
8642 _(create_vlan_subif, "<intfc> | sw_if_index <id> vlan <n>") \
8643 _(create_subif, "<intfc> | sw_if_index <id> sub_id <n>\n" \
8644 "[outer_vlan_id <n>][inner_vlan_id <n>]\n" \
8645 "[no_tags][one_tag][two_tags][dot1ad][exact_match][default_sub]\n" \
8646 "[outer_vlan_id_any][inner_vlan_id_any]") \
8647 _(oam_add_del, "src <ip4-address> dst <ip4-address> [vrf <n>] [del]") \
8648 _(reset_fib, "vrf <n> [ipv6]") \
8649 _(dhcp_proxy_config, \
8650 "svr <v46-address> src <v46-address>\n" \
8651 "insert-cid <n> [del]") \
8652 _(dhcp_proxy_config_2, \
8653 "svr <v46-address> src <v46-address>\n" \
8654 "rx_vrf_id <nn> server_vrf_id <nn> insert-cid <n> [del]") \
8655 _(dhcp_proxy_set_vss, \
8656 "tbl_id <n> fib_id <n> oui <n> [ipv6] [del]") \
8657 _(dhcp_client_config, \
8658 "<intfc> | sw_if_index <id> [hostname <name>] [disable_event] [del]") \
8659 _(set_ip_flow_hash, \
8660 "vrf <n> [src] [dst] [sport] [dport] [proto] [reverse] [ipv6]") \
8661 _(sw_interface_ip6_enable_disable, \
8662 "<intfc> | sw_if_index <id> enable | disable") \
8663 _(sw_interface_ip6_set_link_local_address, \
8664 "<intfc> | sw_if_index <id> <ip6-address>/<mask-width>") \
8665 _(sw_interface_ip6nd_ra_prefix, \
8666 "<intfc> | sw_if_index <id> <ip6-address>/<mask-width>\n" \
8667 "val_life <n> pref_life <n> [def] [noadv] [offl] [noauto]\n" \
8668 "[nolink] [isno]") \
8669 _(sw_interface_ip6nd_ra_config, \
8670 "<intfc> | sw_if_index <id> [maxint <n>] [minint <n>]\n" \
8671 "[life <n>] [count <n>] [interval <n>] [surpress]\n" \
8672 "[managed] [other] [ll] [send] [cease] [isno] [def]") \
8673 _(set_arp_neighbor_limit, "arp_nbr_limit <n> [ipv6]") \
8674 _(l2_patch_add_del, \
8675 "rx <intfc> | rx_sw_if_index <id> tx <intfc> | tx_sw_if_index <id>\n" \
8676 "enable | disable") \
8677 _(mpls_ethernet_add_del_tunnel, \
8678 "tx <intfc> | tx_sw_if_index <n> dst <mac-addr>\n" \
8679 "adj <ip4-addr>/<mw> dst <mac-addr> [del]") \
8680 _(mpls_ethernet_add_del_tunnel_2, \
8681 "inner_vrf_id <n> outer_vrf_id <n> next-hop <ip4-addr>\n" \
8682 "resolve-attempts <n> resolve-if-needed 0 | 1 [del]") \
8683 _(sr_tunnel_add_del, \
8684 "src <ip6-addr> dst <ip6-addr>/<mw> (next <ip6-addr>)+\n" \
8685 " [tag <ip6-addr>]* [clean] [reroute]") \
8686 _(classify_add_del_table, \
8687 "buckets <nn> [skip <n>] [match <n>] [memory_size <nn-bytes>]\n" \
8688 "[del] mask <mask-value>\n" \
8689 " [l2-miss-next | miss-next | acl-miss-next] <name|nn>") \
8690 _(classify_add_del_session, \
8691 "[hit-next|l2-hit-next|acl-hit-next] <name|nn> table-index <nn>\n" \
8692 "skip_n <nn> match_n <nn> match [hex] [l2] [l3 [ip4|ip6]]") \
8693 _(classify_set_interface_ip_table, \
8694 "<intfc> | sw_if_index <nn> table <nn>") \
8695 _(classify_set_interface_l2_tables, \
8696 "<intfc> | sw_if_index <nn> [ip4-table <nn>] [ip6-table <nn>]\n" \
8697 " [other-table <nn>]") \
8698 _(get_node_index, "node <node-name") \
8699 _(add_node_next, "node <node-name> next <next-node-name>") \
8700 _(l2tpv3_create_tunnel, \
8701 "client_address <ip6-addr> our_address <ip6-addr>\n" \
8702 "[local_session_id <nn>][remote_session_id <nn>][local_cookie <nn>]\n"\
8703 "[remote_cookie <nn>]\n[l2-sublayer-preset]\n") \
8704 _(l2tpv3_set_tunnel_cookies, \
8705 "<intfc> | sw_if_index <nn> [new_local_cookie <nn>]\n" \
8706 "[new_remote_cookie <nn>]\n") \
8707 _(l2tpv3_interface_enable_disable, \
8708 "<intfc> | sw_if_index <nn> enable | disable") \
8709 _(l2tpv3_set_lookup_key, \
8710 "lookup_v6_src | lookup_v6_dst | lookup_session_id") \
8711 _(sw_if_l2tpv3_tunnel_dump, "") \
8712 _(vxlan_add_del_tunnel, \
8713 "src <ip4-addr> dst <ip4-addr> vni [encap-vrf-id <nn>]\n" \
8714 " [decap-next l2|ip4|ip6] [del]") \
8715 _(vxlan_tunnel_dump, "[<intfc> | sw_if_index <nn>]") \
8716 _(l2_fib_clear_table, "") \
8717 _(l2_interface_efp_filter, "sw_if_index <nn> enable | disable") \
8718 _(l2_interface_vlan_tag_rewrite, \
8719 "<intfc> | sw_if_index <nn> \n" \
8720 "[disable][push-[1|2]][pop-[1|2]][translate-1-[1|2]] \n" \
8721 "[translate-2-[1|2]] [push_dot1q 0] tag1 <nn> tag2 <nn>") \
8722 _(create_vhost_user_if, \
8723 "socket <filename> [server] [renumber <dev_instance>]") \
8724 _(modify_vhost_user_if, \
8725 "<intfc> | sw_if_index <nn> socket <filename>\n" \
8726 "[server] [renumber <dev_instance>]") \
8727 _(delete_vhost_user_if, "<intfc> | sw_if_index <nn>") \
8728 _(sw_interface_vhost_user_dump, "") \
8729 _(show_version, "") \
8730 _(nsh_gre_add_del_tunnel, \
8731 "src <ip4-addr> dst <ip4-addr>" \
8732 "c1 <nn> c2 <nn> c3 <nn> c4 <nn> spi <nn> si <nn>\n" \
8733 "[encap-fib-id <nn>] [decap-fib-id <nn>] [o-bit <1|0>]\n" \
8734 "[c-bit <1|0>] [md-type <nn>][next-ip4][next-ip6][next-ethernet]\n" \
8735 "[tlv <xx>][del]") \
8736 _(nsh_vxlan_gpe_add_del_tunnel, \
8737 "src <ip4-addr> dst <ip4-addr> vni <nn>\n" \
8738 "c1 <nn> c2 <nn> c3 <nn> c4 <nn> spi <nn> si <nn>\n" \
8739 "[encap-vrf-id <nn>] [decap-vrf-id <nn>] [o-bit <1|0>]\n" \
8740 "[c-bit <1|0>] [md-type <nn>][next-ip4][next-ip6][next-ethernet]\n" \
8741 "[tlv <xx>][del]") \
8742 _(l2_fib_table_dump, "bd_id <bridge-domain-id>") \
8743 _(lisp_gpe_add_del_tunnel, \
8744 "src <ip4-addr> dst <ip4-addr> iid <nn>|iidx <0xnn>\n" \
8745 "[encap-vrf-id <nn>] [decap-vrf-id <nn>]\n" \
8746 "[n-bit][l-bit][e-bit][v-bit][i-bit][p-bit][not-p-bit][o-bit]\n" \
8747 "[next-ip4][next-ip6][next-ethernet][next-nsh]\n" \
8748 "[decap-next [ip4|ip6|ethernet|nsh-encap|<nn>]][del]") \
8749 _(interface_name_renumber, \
8750 "<intfc> | sw_if_index <nn> new_show_dev_instance <nn>") \
8751 _(input_acl_set_interface, \
8752 "<intfc> | sw_if_index <nn> [ip4-table <nn>] [ip6-table <nn>]\n" \
8753 " [l2-table <nn>] [del]") \
8754 _(want_ip4_arp_events, "address <ip4-address> [del]") \
8755 _(ip_address_dump, "(ipv4 | ipv6) (<intfc> | sw_if_index <id>)") \
8756 _(ip_dump, "ipv4 | ipv6") \
8757 _(ipsec_spd_add_del, "spd_id <n> [del]") \
8758 _(ipsec_interface_add_del_spd, "(<intfc> | sw_if_index <id>)\n" \
8760 _(ipsec_sad_add_del_entry, "sad_id <n> spi <n> crypto_alg <alg>\n" \
8761 " crypto_key <hex> tunnel_src <ip4|ip6> tunnel_dst <ip4|ip6>\n" \
8762 " integ_alg <alg> integ_key <hex>") \
8763 _(ipsec_spd_add_del_entry, "spd_id <n> priority <n> action <action>\n" \
8764 " (inbound|outbound) [sa_id <n>] laddr_start <ip4|ip6>\n" \
8765 " laddr_stop <ip4|ip6> raddr_start <ip4|ip6> raddr_stop <ip4|ip6>\n" \
8766 " [lport_start <n> lport_stop <n>] [rport_start <n> rport_stop <n>]" )\
8767 _(ipsec_sa_set_key, "sa_id <n> crypto_key <hex> integ_key <hex>") \
8768 _(delete_loopback,"sw_if_index <nn>") \
8769 _(bd_ip_mac_add_del, "bd_id <bridge-domain-id> <ip4/6-addr> <mac-addr> [del]") \
8771 "ip4-pfx <ip4pfx> ip6-pfx <ip6pfx> " \
8772 "ip6-src <ip6addr> " \
8773 "ea-bits-len <n> psid-offset <n> psid-len <n>") \
8774 _(map_del_domain, "index <n>") \
8775 _(map_add_del_rule, \
8776 "index <n> psid <n> dst <ip6addr> [del]") \
8777 _(map_domain_dump, "") \
8778 _(map_rule_dump, "index <map-domain>") \
8779 _(want_interface_events, "enable|disable") \
8780 _(want_stats,"enable|disable") \
8781 _(get_first_msg_id, "client <name>")
8783 /* List of command functions, CLI names map directly to functions */
8784 #define foreach_cli_function \
8785 _(comment, "usage: comment <ignore-rest-of-line>") \
8786 _(dump_interface_table, "usage: dump_interface_table") \
8787 _(dump_sub_interface_table, "usage: dump_sub_interface_table") \
8788 _(dump_ipv4_table, "usage: dump_ipv4_table") \
8789 _(dump_ipv6_table, "usage: dump_ipv6_table") \
8790 _(dump_stats_table, "usage: dump_stats_table") \
8791 _(dump_macro_table, "usage: dump_macro_table ") \
8792 _(echo, "usage: echo <message>") \
8793 _(exec, "usage: exec <vpe-debug-CLI-command>") \
8794 _(help, "usage: help") \
8795 _(q, "usage: quit") \
8796 _(quit, "usage: quit") \
8797 _(set, "usage: set <variable-name> <value>") \
8798 _(script, "usage: script <file-name>") \
8799 _(unset, "usage: unset <variable-name>")
8802 static void vl_api_##n##_t_handler_uni \
8803 (vl_api_##n##_t * mp) \
8805 vat_main_t * vam = &vat_main; \
8806 if (vam->json_output) { \
8807 vl_api_##n##_t_handler_json(mp); \
8809 vl_api_##n##_t_handler(mp); \
8812 foreach_vpe_api_reply_msg;
8815 void vat_api_hookup (vat_main_t *vam)
8818 vl_msg_api_set_handlers(VL_API_##N, #n, \
8819 vl_api_##n##_t_handler_uni, \
8821 vl_api_##n##_t_endian, \
8822 vl_api_##n##_t_print, \
8823 sizeof(vl_api_##n##_t), 1);
8824 foreach_vpe_api_reply_msg;
8827 vl_msg_api_set_first_available_msg_id (VL_MSG_FIRST_AVAILABLE);
8829 vam->sw_if_index_by_interface_name =
8830 hash_create_string (0, sizeof (uword));
8832 vam->function_by_name =
8833 hash_create_string (0, sizeof(uword));
8836 hash_create_string (0, sizeof(uword));
8838 /* API messages we can send */
8839 #define _(n,h) hash_set_mem (vam->function_by_name, #n, api_##n);
8840 foreach_vpe_api_msg;
8844 #define _(n,h) hash_set_mem (vam->help_by_name, #n, h);
8845 foreach_vpe_api_msg;
8849 #define _(n,h) hash_set_mem (vam->function_by_name, #n, n);
8850 foreach_cli_function;
8854 #define _(n,h) hash_set_mem (vam->help_by_name, #n, h);
8855 foreach_cli_function;
8859 #undef vl_api_version
8860 #define vl_api_version(n,v) static u32 vpe_api_version = v;
8861 #include <api/vpe.api.h>
8862 #undef vl_api_version
8864 void vl_client_add_api_signatures (vl_api_memclnt_create_t *mp)
8867 * Send the main API signature in slot 0. This bit of code must
8868 * match the checks in ../vpe/api/api.c: vl_msg_api_version_check().
8870 mp->api_versions[0] = clib_host_to_net_u32 (vpe_api_version);