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>
37 #include <vnet/ipsec/ipsec.h>
38 #include <vnet/map/map.h>
40 #include "vat/json_format.h"
42 #define vl_typedefs /* define message structures */
43 #include <api/vpe_all_api_h.h>
46 /* declare message handlers for each api */
48 #define vl_endianfun /* define message structures */
49 #include <api/vpe_all_api_h.h>
52 /* instantiate all the print functions we know about */
53 #define vl_print(handle, ...)
55 #include <api/vpe_all_api_h.h>
58 uword unformat_sw_if_index (unformat_input_t * input, va_list * args)
60 vat_main_t * vam = va_arg (*args, vat_main_t *);
61 u32 * result = va_arg (*args, u32 *);
65 if (!unformat (input, "%s", &if_name))
68 p = hash_get_mem (vam->sw_if_index_by_interface_name, if_name);
75 /* Parse an IP4 address %d.%d.%d.%d. */
76 uword unformat_ip4_address (unformat_input_t * input, va_list * args)
78 u8 * result = va_arg (*args, u8 *);
81 if (! unformat (input, "%d.%d.%d.%d", &a[0], &a[1], &a[2], &a[3]))
84 if (a[0] >= 256 || a[1] >= 256 || a[2] >= 256 || a[3] >= 256)
97 unformat_ethernet_address (unformat_input_t * input, va_list * args)
99 u8 * result = va_arg (*args, u8 *);
102 if (! unformat (input, "%_%x:%x:%x:%x:%x:%x%_",
103 &a[0], &a[1], &a[2], &a[3], &a[4], &a[5]))
107 for (i = 0; i < 6; i++)
108 if (a[i] >= (1 << 8))
111 for (i = 0; i < 6; i++)
117 /* Returns ethernet type as an int in host byte order. */
119 unformat_ethernet_type_host_byte_order (unformat_input_t * input,
122 u16 * result = va_arg (*args, u16 *);
126 if (unformat (input, "0x%x", &type)
127 || unformat (input, "%d", &type))
129 if (type >= (1 << 16))
137 /* Parse an IP6 address. */
138 uword unformat_ip6_address (unformat_input_t * input, va_list * args)
140 ip6_address_t * result = va_arg (*args, ip6_address_t *);
142 uword hex_quad, n_hex_quads, hex_digit, n_hex_digits;
143 uword c, n_colon, double_colon_index;
145 n_hex_quads = hex_quad = n_hex_digits = n_colon = 0;
146 double_colon_index = ARRAY_LEN (hex_quads);
147 while ((c = unformat_get_input (input)) != UNFORMAT_END_OF_INPUT)
150 if (c >= '0' && c <= '9')
152 else if (c >= 'a' && c <= 'f')
153 hex_digit = c + 10 - 'a';
154 else if (c >= 'A' && c <= 'F')
155 hex_digit = c + 10 - 'A';
156 else if (c == ':' && n_colon < 2)
160 unformat_put_input (input);
164 /* Too many hex quads. */
165 if (n_hex_quads >= ARRAY_LEN (hex_quads))
170 hex_quad = (hex_quad << 4) | hex_digit;
172 /* Hex quad must fit in 16 bits. */
173 if (n_hex_digits >= 4)
180 /* Save position of :: */
183 /* More than one :: ? */
184 if (double_colon_index < ARRAY_LEN (hex_quads))
186 double_colon_index = n_hex_quads;
189 if (n_colon > 0 && n_hex_digits > 0)
191 hex_quads[n_hex_quads++] = hex_quad;
197 if (n_hex_digits > 0)
198 hex_quads[n_hex_quads++] = hex_quad;
203 /* Expand :: to appropriate number of zero hex quads. */
204 if (double_colon_index < ARRAY_LEN (hex_quads))
206 word n_zero = ARRAY_LEN (hex_quads) - n_hex_quads;
208 for (i = n_hex_quads - 1; i >= (signed) double_colon_index; i--)
209 hex_quads[n_zero + i] = hex_quads[i];
211 for (i = 0; i < n_zero; i++)
212 hex_quads[double_colon_index + i] = 0;
214 n_hex_quads = ARRAY_LEN (hex_quads);
217 /* Too few hex quads given. */
218 if (n_hex_quads < ARRAY_LEN (hex_quads))
221 for (i = 0; i < ARRAY_LEN (hex_quads); i++)
222 result->as_u16[i] = clib_host_to_net_u16 (hex_quads[i]);
229 unformat_ipsec_policy_action (unformat_input_t * input, va_list * args)
231 u32 * r = va_arg (*args, u32 *);
234 #define _(v,f,s) else if (unformat (input, s)) *r = IPSEC_POLICY_ACTION_##f;
235 foreach_ipsec_policy_action
243 unformat_ipsec_crypto_alg (unformat_input_t * input, va_list * args)
245 u32 * r = va_arg (*args, u32 *);
248 #define _(v,f,s) else if (unformat (input, s)) *r = IPSEC_CRYPTO_ALG_##f;
249 foreach_ipsec_crypto_alg
257 format_ipsec_crypto_alg (u8 * s, va_list * args)
259 u32 i = va_arg (*args, u32);
264 #define _(v,f,str) case IPSEC_CRYPTO_ALG_##f: t = (u8 *) str; break;
265 foreach_ipsec_crypto_alg
268 return format (s, "unknown");
270 return format (s, "%s", t);
274 unformat_ipsec_integ_alg (unformat_input_t * input, va_list * args)
276 u32 * r = va_arg (*args, u32 *);
279 #define _(v,f,s) else if (unformat (input, s)) *r = IPSEC_INTEG_ALG_##f;
280 foreach_ipsec_integ_alg
288 format_ipsec_integ_alg (u8 * s, va_list * args)
290 u32 i = va_arg (*args, u32);
295 #define _(v,f,str) case IPSEC_INTEG_ALG_##f: t = (u8 *) str; break;
296 foreach_ipsec_integ_alg
299 return format (s, "unknown");
301 return format (s, "%s", t);
304 u8 * format_ip4_address (u8 * s, va_list * args)
306 u8 * a = va_arg (*args, u8 *);
307 return format (s, "%d.%d.%d.%d", a[0], a[1], a[2], a[3]);
310 u8 * format_ip6_address (u8 * s, va_list * args)
312 ip6_address_t * a = va_arg (*args, ip6_address_t *);
313 u32 i, i_max_n_zero, max_n_zeros, i_first_zero, n_zeros, last_double_colon;
315 i_max_n_zero = ARRAY_LEN (a->as_u16);
317 i_first_zero = i_max_n_zero;
319 for (i = 0; i < ARRAY_LEN (a->as_u16); i++)
321 u32 is_zero = a->as_u16[i] == 0;
322 if (is_zero && i_first_zero >= ARRAY_LEN (a->as_u16))
328 if ((! is_zero && n_zeros > max_n_zeros)
329 || (i + 1 >= ARRAY_LEN (a->as_u16) && n_zeros > max_n_zeros))
331 i_max_n_zero = i_first_zero;
332 max_n_zeros = n_zeros;
333 i_first_zero = ARRAY_LEN (a->as_u16);
338 last_double_colon = 0;
339 for (i = 0; i < ARRAY_LEN (a->as_u16); i++)
341 if (i == i_max_n_zero && max_n_zeros > 1)
343 s = format (s, "::");
344 i += max_n_zeros - 1;
345 last_double_colon = 1;
349 s = format (s, "%s%x",
350 (last_double_colon || i == 0) ? "" : ":",
351 clib_net_to_host_u16 (a->as_u16[i]));
352 last_double_colon = 0;
359 u8 * format_ethernet_address (u8 * s, va_list * args)
361 u8 * a = va_arg (*args, u8 *);
363 return format (s, "%02x:%02x:%02x:%02x:%02x:%02x",
364 a[0], a[1], a[2], a[3], a[4], a[5]);
367 void increment_v4_address (ip4_address_t * a)
371 v = ntohl(a->as_u32) + 1;
372 a->as_u32 = ntohl(v);
375 void increment_v6_address (ip6_address_t * a)
379 v0 = clib_net_to_host_u64 (a->as_u64[0]);
380 v1 = clib_net_to_host_u64 (a->as_u64[1]);
385 a->as_u64[0] = clib_net_to_host_u64 (v0);
386 a->as_u64[1] = clib_net_to_host_u64 (v1);
390 static void vl_api_create_loopback_reply_t_handler
391 (vl_api_create_loopback_reply_t * mp)
393 vat_main_t * vam = &vat_main;
394 i32 retval = ntohl(mp->retval);
396 vam->retval = retval;
397 vam->result_ready = 1;
398 vam->regenerate_interface_table = 1;
401 static void vl_api_create_loopback_reply_t_handler_json
402 (vl_api_create_loopback_reply_t * mp)
404 vat_main_t * vam = &vat_main;
405 vat_json_node_t node;
407 vat_json_init_object(&node);
408 vat_json_object_add_int(&node, "retval", ntohl(mp->retval));
409 vat_json_object_add_uint(&node, "sw_if_index", ntohl(mp->sw_if_index));
411 vat_json_print(vam->ofp, &node);
412 vat_json_free(&node);
414 vam->retval = ntohl(mp->retval);
415 vam->result_ready = 1;
418 static void vl_api_create_vlan_subif_reply_t_handler
419 (vl_api_create_vlan_subif_reply_t * mp)
421 vat_main_t * vam = &vat_main;
422 i32 retval = ntohl(mp->retval);
424 vam->retval = retval;
425 vam->result_ready = 1;
426 vam->regenerate_interface_table = 1;
429 static void vl_api_create_vlan_subif_reply_t_handler_json
430 (vl_api_create_vlan_subif_reply_t * mp)
432 vat_main_t * vam = &vat_main;
433 vat_json_node_t node;
435 vat_json_init_object(&node);
436 vat_json_object_add_int(&node, "retval", ntohl(mp->retval));
437 vat_json_object_add_uint(&node, "sw_if_index", ntohl(mp->sw_if_index));
439 vat_json_print(vam->ofp, &node);
440 vat_json_free(&node);
442 vam->retval = ntohl(mp->retval);
443 vam->result_ready = 1;
446 static void vl_api_create_subif_reply_t_handler
447 (vl_api_create_subif_reply_t * mp)
449 vat_main_t * vam = &vat_main;
450 i32 retval = ntohl(mp->retval);
452 vam->retval = retval;
453 vam->result_ready = 1;
454 vam->regenerate_interface_table = 1;
457 static void vl_api_create_subif_reply_t_handler_json
458 (vl_api_create_subif_reply_t * mp)
460 vat_main_t * vam = &vat_main;
461 vat_json_node_t node;
463 vat_json_init_object(&node);
464 vat_json_object_add_int(&node, "retval", ntohl(mp->retval));
465 vat_json_object_add_uint(&node, "sw_if_index", ntohl(mp->sw_if_index));
467 vat_json_print(vam->ofp, &node);
468 vat_json_free(&node);
470 vam->retval = ntohl(mp->retval);
471 vam->result_ready = 1;
474 static void vl_api_interface_name_renumber_reply_t_handler
475 (vl_api_interface_name_renumber_reply_t * mp)
477 vat_main_t * vam = &vat_main;
478 i32 retval = ntohl(mp->retval);
480 vam->retval = retval;
481 vam->result_ready = 1;
482 vam->regenerate_interface_table = 1;
485 static void vl_api_interface_name_renumber_reply_t_handler_json
486 (vl_api_interface_name_renumber_reply_t * mp)
488 vat_main_t * vam = &vat_main;
489 vat_json_node_t node;
491 vat_json_init_object(&node);
492 vat_json_object_add_int(&node, "retval", ntohl(mp->retval));
494 vat_json_print(vam->ofp, &node);
495 vat_json_free(&node);
497 vam->retval = ntohl(mp->retval);
498 vam->result_ready = 1;
502 * Special-case: build the interface table, maintain
503 * the next loopback sw_if_index vbl.
505 static void vl_api_sw_interface_details_t_handler
506 (vl_api_sw_interface_details_t * mp)
508 vat_main_t * vam = &vat_main;
509 u8 * s = format (0, "%s%c", mp->interface_name, 0);
511 hash_set_mem (vam->sw_if_index_by_interface_name, s,
512 ntohl(mp->sw_if_index));
514 /* In sub interface case, fill the sub interface table entry */
515 if (mp->sw_if_index != mp->sup_sw_if_index) {
516 sw_interface_subif_t * sub = NULL;
518 vec_add2(vam->sw_if_subif_table, sub, 1);
520 vec_validate(sub->interface_name, strlen((char *)s) + 1);
521 strncpy((char *)sub->interface_name, (char *)s,
522 vec_len(sub->interface_name));
523 sub->sw_if_index = ntohl(mp->sw_if_index);
524 sub->sub_id = ntohl(mp->sub_id);
526 sub->sub_dot1ad = mp->sub_dot1ad;
527 sub->sub_number_of_tags = mp->sub_number_of_tags;
528 sub->sub_outer_vlan_id = ntohs(mp->sub_outer_vlan_id);
529 sub->sub_inner_vlan_id = ntohs(mp->sub_inner_vlan_id);
530 sub->sub_exact_match = mp->sub_exact_match;
531 sub->sub_default = mp->sub_default;
532 sub->sub_outer_vlan_id_any = mp->sub_outer_vlan_id_any;
533 sub->sub_inner_vlan_id_any = mp->sub_inner_vlan_id_any;
535 /* vlan tag rewrite */
536 sub->vtr_op = ntohl(mp->vtr_op);
537 sub->vtr_push_dot1q = ntohl(mp->vtr_push_dot1q);
538 sub->vtr_tag1 = ntohl(mp->vtr_tag1);
539 sub->vtr_tag2 = ntohl(mp->vtr_tag2);
543 static void vl_api_sw_interface_details_t_handler_json
544 (vl_api_sw_interface_details_t * mp)
546 vat_main_t * vam = &vat_main;
547 vat_json_node_t *node = NULL;
549 if (VAT_JSON_ARRAY != vam->json_tree.type) {
550 ASSERT(VAT_JSON_NONE == vam->json_tree.type);
551 vat_json_init_array(&vam->json_tree);
553 node = vat_json_array_add(&vam->json_tree);
555 vat_json_init_object(node);
556 vat_json_object_add_uint(node, "sw_if_index", ntohl(mp->sw_if_index));
557 vat_json_object_add_uint(node, "sup_sw_if_index", ntohl(mp->sup_sw_if_index));
558 vat_json_object_add_uint(node, "l2_address_length", ntohl(mp->l2_address_length));
559 vat_json_object_add_bytes(node, "l2_address", mp->l2_address, sizeof(mp->l2_address));
560 vat_json_object_add_string_copy(node, "interface_name", mp->interface_name);
561 vat_json_object_add_uint(node, "admin_up_down", mp->admin_up_down);
562 vat_json_object_add_uint(node, "link_up_down", mp->link_up_down);
563 vat_json_object_add_uint(node, "link_duplex", mp->link_duplex);
564 vat_json_object_add_uint(node, "link_speed", mp->link_speed);
565 vat_json_object_add_uint(node, "sub_id", ntohl(mp->sub_id));
566 vat_json_object_add_uint(node, "sub_dot1ad", mp->sub_dot1ad);
567 vat_json_object_add_uint(node, "sub_number_of_tags", mp->sub_number_of_tags);
568 vat_json_object_add_uint(node, "sub_outer_vlan_id", ntohs(mp->sub_outer_vlan_id));
569 vat_json_object_add_uint(node, "sub_inner_vlan_id", ntohs(mp->sub_inner_vlan_id));
570 vat_json_object_add_uint(node, "sub_exact_match", mp->sub_exact_match);
571 vat_json_object_add_uint(node, "sub_default", mp->sub_default);
572 vat_json_object_add_uint(node, "sub_outer_vlan_id_any", mp->sub_outer_vlan_id_any);
573 vat_json_object_add_uint(node, "sub_inner_vlan_id_any", mp->sub_inner_vlan_id_any);
574 vat_json_object_add_uint(node, "vtr_op", ntohl(mp->vtr_op));
575 vat_json_object_add_uint(node, "vtr_push_dot1q", ntohl(mp->vtr_push_dot1q));
576 vat_json_object_add_uint(node, "vtr_tag1", ntohl(mp->vtr_tag1));
577 vat_json_object_add_uint(node, "vtr_tag2", ntohl(mp->vtr_tag2));
580 static void vl_api_sw_interface_set_flags_t_handler
581 (vl_api_sw_interface_set_flags_t * mp)
583 vat_main_t * vam = &vat_main;
584 if (vam->interface_event_display)
585 errmsg ("interface flags: sw_if_index %d %s %s\n",
586 ntohl(mp->sw_if_index),
587 mp->admin_up_down ? "admin-up" : "admin-down",
588 mp->link_up_down ? "link-up" : "link-down");
591 static void vl_api_sw_interface_set_flags_t_handler_json
592 (vl_api_sw_interface_set_flags_t * mp)
594 /* JSON output not supported */
597 static void vl_api_cli_reply_t_handler
598 (vl_api_cli_reply_t * mp)
600 vat_main_t * vam = &vat_main;
601 i32 retval = ntohl(mp->retval);
603 vam->retval = retval;
604 vam->shmem_result = (u8 *) mp->reply_in_shmem;
605 vam->result_ready = 1;
608 static void vl_api_cli_reply_t_handler_json
609 (vl_api_cli_reply_t * mp)
611 vat_main_t * vam = &vat_main;
612 vat_json_node_t node;
614 vat_json_init_object(&node);
615 vat_json_object_add_int(&node, "retval", ntohl(mp->retval));
616 vat_json_object_add_uint(&node, "reply_in_shmem", ntohl(mp->reply_in_shmem));
618 vat_json_print(vam->ofp, &node);
619 vat_json_free(&node);
621 vam->retval = ntohl(mp->retval);
622 vam->result_ready = 1;
625 static void vl_api_classify_add_del_table_reply_t_handler
626 (vl_api_classify_add_del_table_reply_t * mp)
628 vat_main_t * vam = &vat_main;
629 i32 retval = ntohl(mp->retval);
630 if (vam->async_mode) {
631 vam->async_errors += (retval < 0);
633 vam->retval = retval;
634 vam->result_ready = 1;
636 ((mp->new_table_index != 0xFFFFFFFF) ||
637 (mp->skip_n_vectors != 0xFFFFFFFF) ||
638 (mp->match_n_vectors != 0xFFFFFFFF)))
640 * Note: this is just barely thread-safe, depends on
641 * the main thread spinning waiting for an answer...
643 errmsg ("new index %d, skip_n_vectors %d, match_n_vectors %d\n",
644 ntohl(mp->new_table_index),
645 ntohl(mp->skip_n_vectors), ntohl(mp->match_n_vectors));
649 static void vl_api_classify_add_del_table_reply_t_handler_json
650 (vl_api_classify_add_del_table_reply_t * mp)
652 vat_main_t * vam = &vat_main;
653 vat_json_node_t node;
655 vat_json_init_object(&node);
656 vat_json_object_add_int(&node, "retval", ntohl(mp->retval));
657 vat_json_object_add_uint(&node, "new_table_index", ntohl(mp->new_table_index));
658 vat_json_object_add_uint(&node, "skip_n_vectors", ntohl(mp->skip_n_vectors));
659 vat_json_object_add_uint(&node, "match_n_vectors", ntohl(mp->match_n_vectors));
661 vat_json_print(vam->ofp, &node);
662 vat_json_free(&node);
664 vam->retval = ntohl(mp->retval);
665 vam->result_ready = 1;
668 static void vl_api_get_node_index_reply_t_handler
669 (vl_api_get_node_index_reply_t * mp)
671 vat_main_t * vam = &vat_main;
672 i32 retval = ntohl(mp->retval);
673 if (vam->async_mode) {
674 vam->async_errors += (retval < 0);
676 vam->retval = retval;
677 vam->result_ready = 1;
679 errmsg ("node index %d\n", ntohl(mp->node_index));
683 static void vl_api_get_node_index_reply_t_handler_json
684 (vl_api_get_node_index_reply_t * mp)
686 vat_main_t * vam = &vat_main;
687 vat_json_node_t node;
689 vat_json_init_object(&node);
690 vat_json_object_add_int(&node, "retval", ntohl(mp->retval));
691 vat_json_object_add_uint(&node, "node_index", ntohl(mp->node_index));
693 vat_json_print(vam->ofp, &node);
694 vat_json_free(&node);
696 vam->retval = ntohl(mp->retval);
697 vam->result_ready = 1;
700 static void vl_api_add_node_next_reply_t_handler
701 (vl_api_add_node_next_reply_t * mp)
703 vat_main_t * vam = &vat_main;
704 i32 retval = ntohl(mp->retval);
705 if (vam->async_mode) {
706 vam->async_errors += (retval < 0);
708 vam->retval = retval;
709 vam->result_ready = 1;
711 errmsg ("next index %d\n", ntohl(mp->next_index));
715 static void vl_api_add_node_next_reply_t_handler_json
716 (vl_api_add_node_next_reply_t * mp)
718 vat_main_t * vam = &vat_main;
719 vat_json_node_t node;
721 vat_json_init_object(&node);
722 vat_json_object_add_int(&node, "retval", ntohl(mp->retval));
723 vat_json_object_add_uint(&node, "next_index", ntohl(mp->next_index));
725 vat_json_print(vam->ofp, &node);
726 vat_json_free(&node);
728 vam->retval = ntohl(mp->retval);
729 vam->result_ready = 1;
732 static void vl_api_mpls_gre_add_del_tunnel_reply_t_handler
733 (vl_api_mpls_gre_add_del_tunnel_reply_t * mp)
735 vat_main_t * vam = &vat_main;
736 i32 retval = ntohl(mp->retval);
737 u32 sw_if_index = ntohl(mp->tunnel_sw_if_index);
739 if (retval >= 0 && sw_if_index != (u32)~0) {
740 errmsg ("tunnel_sw_if_index %d\n", sw_if_index);
742 vam->retval = retval;
743 vam->result_ready = 1;
746 static void vl_api_mpls_gre_add_del_tunnel_reply_t_handler_json
747 (vl_api_mpls_gre_add_del_tunnel_reply_t * mp)
749 vat_main_t * vam = &vat_main;
750 vat_json_node_t node;
752 vat_json_init_object(&node);
753 vat_json_object_add_int(&node, "retval", ntohl(mp->retval));
754 vat_json_object_add_uint(&node, "tunnel_sw_if_index", ntohl(mp->tunnel_sw_if_index));
756 vat_json_print(vam->ofp, &node);
757 vat_json_free(&node);
759 vam->retval = ntohl(mp->retval);
760 vam->result_ready = 1;
763 static void vl_api_nsh_gre_add_del_tunnel_reply_t_handler
764 (vl_api_nsh_gre_add_del_tunnel_reply_t * mp)
766 vat_main_t * vam = &vat_main;
767 i32 retval = ntohl(mp->retval);
768 u32 sw_if_index = ntohl(mp->sw_if_index);
770 if (retval >= 0 && sw_if_index != (u32)~0) {
771 errmsg ("sw_if_index %d\n", ntohl(mp->sw_if_index));
773 vam->retval = retval;
774 vam->result_ready = 1;
777 static void vl_api_nsh_gre_add_del_tunnel_reply_t_handler_json
778 (vl_api_nsh_gre_add_del_tunnel_reply_t * mp)
780 vat_main_t * vam = &vat_main;
781 vat_json_node_t node;
783 vat_json_init_object(&node);
784 vat_json_object_add_int(&node, "retval", ntohl(mp->retval));
785 vat_json_object_add_uint(&node, "sw_if_index", ntohl(mp->sw_if_index));
787 vat_json_print(vam->ofp, &node);
788 vat_json_free(&node);
790 vam->retval = ntohl(mp->retval);
791 vam->result_ready = 1;
794 static void vl_api_nsh_vxlan_gpe_add_del_tunnel_reply_t_handler
795 (vl_api_nsh_vxlan_gpe_add_del_tunnel_reply_t * mp)
797 vat_main_t * vam = &vat_main;
798 i32 retval = ntohl(mp->retval);
799 u32 sw_if_index = ntohl(mp->sw_if_index);
801 if (retval >= 0 && sw_if_index != (u32)~0) {
802 errmsg ("sw_if_index %d\n", ntohl(mp->sw_if_index));
804 vam->retval = retval;
805 vam->result_ready = 1;
808 static void vl_api_nsh_vxlan_gpe_add_del_tunnel_reply_t_handler_json
809 (vl_api_nsh_vxlan_gpe_add_del_tunnel_reply_t * mp)
811 vat_main_t * vam = &vat_main;
812 vat_json_node_t node;
814 vat_json_init_object(&node);
815 vat_json_object_add_int(&node, "retval", ntohl(mp->retval));
816 vat_json_object_add_uint(&node, "sw_if_index", ntohl(mp->sw_if_index));
818 vat_json_print(vam->ofp, &node);
819 vat_json_free(&node);
821 vam->retval = ntohl(mp->retval);
822 vam->result_ready = 1;
825 static void vl_api_lisp_gpe_add_del_tunnel_reply_t_handler
826 (vl_api_lisp_gpe_add_del_tunnel_reply_t * mp)
828 vat_main_t * vam = &vat_main;
829 i32 retval = ntohl(mp->retval);
830 u32 sw_if_index = ntohl(mp->sw_if_index);
832 if (retval >= 0 && sw_if_index != (u32)~0) {
833 errmsg ("sw_if_index %d\n", ntohl(mp->sw_if_index));
835 vam->retval = retval;
836 vam->result_ready = 1;
839 static void vl_api_lisp_gpe_add_del_tunnel_reply_t_handler_json
840 (vl_api_lisp_gpe_add_del_tunnel_reply_t * mp)
842 vat_main_t * vam = &vat_main;
843 vat_json_node_t node;
845 vat_json_init_object(&node);
846 vat_json_object_add_int(&node, "retval", ntohl(mp->retval));
847 vat_json_object_add_uint(&node, "sw_if_index", ntohl(mp->sw_if_index));
849 vat_json_print(vam->ofp, &node);
850 vat_json_free(&node);
852 vam->retval = ntohl(mp->retval);
853 vam->result_ready = 1;
856 static void vl_api_show_version_reply_t_handler
857 (vl_api_show_version_reply_t * mp)
859 vat_main_t * vam = &vat_main;
860 i32 retval = ntohl(mp->retval);
863 errmsg (" program: %s\n", mp->program);
864 errmsg (" version: %s\n", mp->version);
865 errmsg (" build date: %s\n", mp->build_date);
866 errmsg ("build directory: %s\n", mp->build_directory);
868 vam->retval = retval;
869 vam->result_ready = 1;
872 static void vl_api_show_version_reply_t_handler_json
873 (vl_api_show_version_reply_t * mp)
875 vat_main_t * vam = &vat_main;
876 vat_json_node_t node;
878 vat_json_init_object(&node);
879 vat_json_object_add_int(&node, "retval", ntohl(mp->retval));
880 vat_json_object_add_string_copy(&node, "program", mp->program);
881 vat_json_object_add_string_copy(&node, "version", mp->version);
882 vat_json_object_add_string_copy(&node, "build_date", mp->build_date);
883 vat_json_object_add_string_copy(&node, "build_directory", mp->build_directory);
885 vat_json_print(vam->ofp, &node);
886 vat_json_free(&node);
888 vam->retval = ntohl(mp->retval);
889 vam->result_ready = 1;
892 static void vl_api_ip4_arp_event_t_handler
893 (vl_api_ip4_arp_event_t * mp)
895 vat_main_t * vam = &vat_main;
896 errmsg ("arp event: address %U new mac %U sw_if_index %d\n",
897 format_ip4_address, &mp->address,
898 format_ethernet_address, mp->new_mac, mp->sw_if_index);
901 static void vl_api_ip4_arp_event_t_handler_json
902 (vl_api_ip4_arp_event_t * mp)
904 /* JSON output not supported */
908 * Special-case: build the bridge domain table, maintain
909 * the next bd id vbl.
911 static void vl_api_bridge_domain_details_t_handler
912 (vl_api_bridge_domain_details_t * mp)
914 vat_main_t * vam = &vat_main;
915 u32 n_sw_ifs = ntohl (mp->n_sw_ifs);
917 fformat (vam->ofp, "\n%-3s %-3s %-3s %-3s %-3s %-3s\n",
918 " ID", "LRN", "FWD", "FLD", "BVI", "#IF");
920 fformat (vam->ofp, "%3d %3d %3d %3d %3d %3d\n",
921 ntohl (mp->bd_id), mp->learn, mp->forward,
922 mp->flood, ntohl (mp->bvi_sw_if_index), n_sw_ifs);
925 fformat (vam->ofp, "\n\n%s %s %s\n", "sw_if_index", "SHG",
929 static void vl_api_bridge_domain_details_t_handler_json
930 (vl_api_bridge_domain_details_t * mp)
932 vat_main_t * vam = &vat_main;
933 vat_json_node_t *node, *array = NULL;
935 if (VAT_JSON_ARRAY != vam->json_tree.type) {
936 ASSERT(VAT_JSON_NONE == vam->json_tree.type);
937 vat_json_init_array(&vam->json_tree);
939 node = vat_json_array_add(&vam->json_tree);
941 vat_json_init_object(node);
942 vat_json_object_add_uint(node, "bd_id", ntohl(mp->bd_id));
943 vat_json_object_add_uint(node, "flood", mp->flood);
944 vat_json_object_add_uint(node, "forward", mp->forward);
945 vat_json_object_add_uint(node, "learn", mp->learn);
946 vat_json_object_add_uint(node, "bvi_sw_if_index", ntohl(mp->bvi_sw_if_index));
947 vat_json_object_add_uint(node, "n_sw_ifs", ntohl(mp->n_sw_ifs));
948 array = vat_json_object_add(node, "sw_if");
949 vat_json_init_array(array);
953 * Special-case: build the bridge domain sw if table.
955 static void vl_api_bridge_domain_sw_if_details_t_handler
956 (vl_api_bridge_domain_sw_if_details_t * mp)
958 vat_main_t * vam = &vat_main;
963 sw_if_index = ntohl (mp->sw_if_index);
964 hash_foreach_pair (p, vam->sw_if_index_by_interface_name,
966 if ((u32) p->value[0] == sw_if_index) {
967 sw_if_name = (u8 *)(p->key);
972 fformat (vam->ofp, "%7d %3d %s", sw_if_index,
973 mp->shg, sw_if_name ? (char *)sw_if_name :
974 "sw_if_index not found!");
977 static void vl_api_bridge_domain_sw_if_details_t_handler_json
978 (vl_api_bridge_domain_sw_if_details_t * mp)
980 vat_main_t * vam = &vat_main;
981 vat_json_node_t *node = NULL;
982 uword last_index = 0;
984 ASSERT(VAT_JSON_ARRAY == vam->json_tree.type);
985 ASSERT(vec_len(vam->json_tree.array) >= 1);
986 last_index = vec_len(vam->json_tree.array) - 1;
987 node = &vam->json_tree.array[last_index];
988 node = vat_json_object_get_element(node, "sw_if");
989 ASSERT(NULL != node);
990 node = vat_json_array_add(node);
992 vat_json_init_object(node);
993 vat_json_object_add_uint(node, "bd_id", ntohl(mp->bd_id));
994 vat_json_object_add_uint(node, "sw_if_index", ntohl(mp->sw_if_index));
995 vat_json_object_add_uint(node, "shg", mp->shg);
998 static void vl_api_control_ping_reply_t_handler
999 (vl_api_control_ping_reply_t * mp)
1001 vat_main_t * vam = &vat_main;
1002 i32 retval = ntohl(mp->retval);
1003 if (vam->async_mode) {
1004 vam->async_errors += (retval < 0);
1006 vam->retval = retval;
1007 vam->result_ready = 1;
1011 static void vl_api_control_ping_reply_t_handler_json
1012 (vl_api_control_ping_reply_t * mp)
1014 vat_main_t * vam = &vat_main;
1015 i32 retval = ntohl(mp->retval);
1017 if (VAT_JSON_NONE != vam->json_tree.type) {
1018 vat_json_print(vam->ofp, &vam->json_tree);
1019 vat_json_free(&vam->json_tree);
1020 vam->json_tree.type = VAT_JSON_NONE;
1023 vat_json_init_array(&vam->json_tree);
1024 vat_json_print(vam->ofp, &vam->json_tree);
1025 vam->json_tree.type = VAT_JSON_NONE;
1028 vam->retval = retval;
1029 vam->result_ready = 1;
1032 static void vl_api_l2_flags_reply_t_handler
1033 (vl_api_l2_flags_reply_t * mp)
1035 vat_main_t * vam = &vat_main;
1036 i32 retval = ntohl(mp->retval);
1037 if (vam->async_mode) {
1038 vam->async_errors += (retval < 0);
1040 vam->retval = retval;
1041 vam->result_ready = 1;
1045 static void vl_api_l2_flags_reply_t_handler_json
1046 (vl_api_l2_flags_reply_t * mp)
1048 vat_main_t * vam = &vat_main;
1049 vat_json_node_t node;
1051 vat_json_init_object(&node);
1052 vat_json_object_add_int(&node, "retval", ntohl(mp->retval));
1053 vat_json_object_add_uint(&node, "resulting_feature_bitmap", ntohl(mp->resulting_feature_bitmap));
1055 vat_json_print(vam->ofp, &node);
1056 vat_json_free(&node);
1058 vam->retval = ntohl(mp->retval);
1059 vam->result_ready = 1;
1062 static void vl_api_bridge_flags_reply_t_handler
1063 (vl_api_bridge_flags_reply_t * mp)
1065 vat_main_t * vam = &vat_main;
1066 i32 retval = ntohl(mp->retval);
1067 if (vam->async_mode) {
1068 vam->async_errors += (retval < 0);
1070 vam->retval = retval;
1071 vam->result_ready = 1;
1075 static void vl_api_bridge_flags_reply_t_handler_json
1076 (vl_api_bridge_flags_reply_t * mp)
1078 vat_main_t * vam = &vat_main;
1079 vat_json_node_t node;
1081 vat_json_init_object(&node);
1082 vat_json_object_add_int(&node, "retval", ntohl(mp->retval));
1083 vat_json_object_add_uint(&node, "resulting_feature_bitmap", ntohl(mp->resulting_feature_bitmap));
1085 vat_json_print(vam->ofp, &node);
1086 vat_json_free(&node);
1088 vam->retval = ntohl(mp->retval);
1089 vam->result_ready = 1;
1092 static void vl_api_tap_connect_reply_t_handler
1093 (vl_api_tap_connect_reply_t * mp)
1095 vat_main_t * vam = &vat_main;
1096 i32 retval = ntohl(mp->retval);
1097 if (vam->async_mode) {
1098 vam->async_errors += (retval < 0);
1100 vam->retval = retval;
1101 vam->result_ready = 1;
1105 static void vl_api_tap_connect_reply_t_handler_json
1106 (vl_api_tap_connect_reply_t * mp)
1108 vat_main_t * vam = &vat_main;
1109 vat_json_node_t node;
1111 vat_json_init_object(&node);
1112 vat_json_object_add_int(&node, "retval", ntohl(mp->retval));
1113 vat_json_object_add_uint(&node, "sw_if_index", ntohl(mp->sw_if_index));
1115 vat_json_print(vam->ofp, &node);
1116 vat_json_free(&node);
1118 vam->retval = ntohl(mp->retval);
1119 vam->result_ready = 1;
1122 static void vl_api_tap_modify_reply_t_handler
1123 (vl_api_tap_modify_reply_t * mp)
1125 vat_main_t * vam = &vat_main;
1126 i32 retval = ntohl(mp->retval);
1127 if (vam->async_mode) {
1128 vam->async_errors += (retval < 0);
1130 vam->retval = retval;
1131 vam->result_ready = 1;
1135 static void vl_api_tap_modify_reply_t_handler_json
1136 (vl_api_tap_modify_reply_t * mp)
1138 vat_main_t * vam = &vat_main;
1139 vat_json_node_t node;
1141 vat_json_init_object(&node);
1142 vat_json_object_add_int(&node, "retval", ntohl(mp->retval));
1143 vat_json_object_add_uint(&node, "sw_if_index", ntohl(mp->sw_if_index));
1145 vat_json_print(vam->ofp, &node);
1146 vat_json_free(&node);
1148 vam->retval = ntohl(mp->retval);
1149 vam->result_ready = 1;
1152 static void vl_api_tap_delete_reply_t_handler
1153 (vl_api_tap_delete_reply_t * mp)
1155 vat_main_t * vam = &vat_main;
1156 i32 retval = ntohl(mp->retval);
1157 if (vam->async_mode) {
1158 vam->async_errors += (retval < 0);
1160 vam->retval = retval;
1161 vam->result_ready = 1;
1165 static void vl_api_tap_delete_reply_t_handler_json
1166 (vl_api_tap_delete_reply_t * mp)
1168 vat_main_t * vam = &vat_main;
1169 vat_json_node_t node;
1171 vat_json_init_object(&node);
1172 vat_json_object_add_int(&node, "retval", ntohl(mp->retval));
1174 vat_json_print(vam->ofp, &node);
1175 vat_json_free(&node);
1177 vam->retval = ntohl(mp->retval);
1178 vam->result_ready = 1;
1181 static void vl_api_mpls_ethernet_add_del_tunnel_reply_t_handler
1182 (vl_api_mpls_ethernet_add_del_tunnel_reply_t * mp)
1184 vat_main_t * vam = &vat_main;
1185 i32 retval = ntohl(mp->retval);
1186 if (vam->async_mode) {
1187 vam->async_errors += (retval < 0);
1189 vam->retval = retval;
1190 vam->result_ready = 1;
1194 static void vl_api_mpls_ethernet_add_del_tunnel_reply_t_handler_json
1195 (vl_api_mpls_ethernet_add_del_tunnel_reply_t * mp)
1197 vat_main_t * vam = &vat_main;
1198 vat_json_node_t node;
1200 vat_json_init_object(&node);
1201 vat_json_object_add_int(&node, "retval", ntohl(mp->retval));
1202 vat_json_object_add_uint(&node, "tunnel_sw_if_index", ntohl(mp->tunnel_sw_if_index));
1204 vat_json_print(vam->ofp, &node);
1205 vat_json_free(&node);
1207 vam->retval = ntohl(mp->retval);
1208 vam->result_ready = 1;
1211 static void vl_api_l2tpv3_create_tunnel_reply_t_handler
1212 (vl_api_l2tpv3_create_tunnel_reply_t * mp)
1214 vat_main_t * vam = &vat_main;
1215 i32 retval = ntohl(mp->retval);
1216 if (vam->async_mode) {
1217 vam->async_errors += (retval < 0);
1219 vam->retval = retval;
1220 vam->result_ready = 1;
1224 static void vl_api_l2tpv3_create_tunnel_reply_t_handler_json
1225 (vl_api_l2tpv3_create_tunnel_reply_t * mp)
1227 vat_main_t * vam = &vat_main;
1228 vat_json_node_t node;
1230 vat_json_init_object(&node);
1231 vat_json_object_add_int(&node, "retval", ntohl(mp->retval));
1232 vat_json_object_add_uint(&node, "sw_if_index", ntohl(mp->sw_if_index));
1234 vat_json_print(vam->ofp, &node);
1235 vat_json_free(&node);
1237 vam->retval = ntohl(mp->retval);
1238 vam->result_ready = 1;
1241 static void vl_api_vxlan_add_del_tunnel_reply_t_handler
1242 (vl_api_vxlan_add_del_tunnel_reply_t * mp)
1244 vat_main_t * vam = &vat_main;
1245 i32 retval = ntohl(mp->retval);
1246 if (vam->async_mode) {
1247 vam->async_errors += (retval < 0);
1249 vam->retval = retval;
1250 vam->result_ready = 1;
1254 static void vl_api_vxlan_add_del_tunnel_reply_t_handler_json
1255 (vl_api_vxlan_add_del_tunnel_reply_t * mp)
1257 vat_main_t * vam = &vat_main;
1258 vat_json_node_t node;
1260 vat_json_init_object(&node);
1261 vat_json_object_add_int(&node, "retval", ntohl(mp->retval));
1262 vat_json_object_add_uint(&node, "sw_if_index", ntohl(mp->sw_if_index));
1264 vat_json_print(vam->ofp, &node);
1265 vat_json_free(&node);
1267 vam->retval = ntohl(mp->retval);
1268 vam->result_ready = 1;
1271 static void vl_api_create_vhost_user_if_reply_t_handler
1272 (vl_api_create_vhost_user_if_reply_t * mp)
1274 vat_main_t * vam = &vat_main;
1275 i32 retval = ntohl(mp->retval);
1276 if (vam->async_mode) {
1277 vam->async_errors += (retval < 0);
1279 vam->retval = retval;
1280 vam->result_ready = 1;
1284 static void vl_api_create_vhost_user_if_reply_t_handler_json
1285 (vl_api_create_vhost_user_if_reply_t * mp)
1287 vat_main_t * vam = &vat_main;
1288 vat_json_node_t node;
1290 vat_json_init_object(&node);
1291 vat_json_object_add_int(&node, "retval", ntohl(mp->retval));
1292 vat_json_object_add_uint(&node, "sw_if_index", ntohl(mp->sw_if_index));
1294 vat_json_print(vam->ofp, &node);
1295 vat_json_free(&node);
1297 vam->retval = ntohl(mp->retval);
1298 vam->result_ready = 1;
1301 static void vl_api_ip_address_details_t_handler
1302 (vl_api_ip_address_details_t * mp)
1304 vat_main_t * vam = &vat_main;
1305 static ip_address_details_t empty_ip_address_details = {{0}};
1306 ip_address_details_t * address = NULL;
1307 ip_details_t * current_ip_details = NULL;
1308 ip_details_t * details = NULL;
1310 details = vam->ip_details_by_sw_if_index[vam->is_ipv6];
1312 if (!details || vam->current_sw_if_index >= vec_len(details)
1313 || !details[vam->current_sw_if_index].present) {
1314 errmsg ("ip address details arrived but not stored\n");
1315 errmsg ("ip_dump should be called first\n");
1319 current_ip_details = vec_elt_at_index(details,
1320 vam->current_sw_if_index);
1322 #define addresses (current_ip_details->addr)
1324 vec_validate_init_empty(addresses, vec_len(addresses),
1325 empty_ip_address_details);
1327 address = vec_elt_at_index(addresses, vec_len(addresses) - 1);
1329 memcpy(&address->ip, &mp->ip, sizeof(address->ip));
1330 address->prefix_length = mp->prefix_length;
1334 static void vl_api_ip_address_details_t_handler_json
1335 (vl_api_ip_address_details_t * mp)
1337 vat_main_t * vam = &vat_main;
1338 vat_json_node_t *node = NULL;
1339 struct in6_addr ip6;
1342 if (VAT_JSON_ARRAY != vam->json_tree.type) {
1343 ASSERT(VAT_JSON_NONE == vam->json_tree.type);
1344 vat_json_init_array(&vam->json_tree);
1346 node = vat_json_array_add(&vam->json_tree);
1348 vat_json_init_object(node);
1350 memcpy(&ip6, mp->ip, sizeof(ip6));
1351 vat_json_object_add_ip6(node, "ip", ip6);
1353 memcpy(&ip4, mp->ip, sizeof(ip4));
1354 vat_json_object_add_ip4(node, "ip", ip4);
1356 vat_json_object_add_uint(node, "prefix_length", mp->prefix_length);
1359 static void vl_api_ip_details_t_handler (vl_api_ip_details_t * mp)
1361 vat_main_t * vam = &vat_main;
1362 static ip_details_t empty_ip_details = {0};
1363 ip_details_t * ip = NULL;
1364 u32 sw_if_index = ~0;
1366 sw_if_index = ntohl(mp->sw_if_index);
1368 vec_validate_init_empty(vam->ip_details_by_sw_if_index[vam->is_ipv6],
1369 sw_if_index, empty_ip_details);
1371 ip = vec_elt_at_index(vam->ip_details_by_sw_if_index[vam->is_ipv6],
1377 static void vl_api_ip_details_t_handler_json (vl_api_ip_details_t * mp)
1379 vat_main_t * vam = &vat_main;
1381 if (VAT_JSON_ARRAY != vam->json_tree.type) {
1382 ASSERT(VAT_JSON_NONE == vam->json_tree.type);
1383 vat_json_init_array(&vam->json_tree);
1385 vat_json_array_add_uint(&vam->json_tree, clib_net_to_host_u32(mp->sw_if_index));
1388 static void vl_api_map_domain_details_t_handler_json
1389 (vl_api_map_domain_details_t * mp)
1391 vat_json_node_t * node = NULL;
1392 vat_main_t * vam = &vat_main;
1393 struct in6_addr ip6;
1396 if (VAT_JSON_ARRAY != vam->json_tree.type) {
1397 ASSERT(VAT_JSON_NONE == vam->json_tree.type);
1398 vat_json_init_array(&vam->json_tree);
1401 node = vat_json_array_add(&vam->json_tree);
1402 vat_json_init_object(node);
1404 vat_json_object_add_uint(node, "domain_index", clib_net_to_host_u32(mp->domain_index));
1405 memcpy(&ip6, mp->ip6_prefix, sizeof(ip6));
1406 vat_json_object_add_ip6(node, "ip6_prefix", ip6);
1407 memcpy(&ip4, mp->ip4_prefix, sizeof(ip4));
1408 vat_json_object_add_ip4(node, "ip4_prefix", ip4);
1409 memcpy(&ip6, mp->ip6_src, sizeof(ip6));
1410 vat_json_object_add_ip6(node, "ip6_src", ip6);
1411 vat_json_object_add_int(node, "ip6_prefix_len", mp->ip6_prefix_len);
1412 vat_json_object_add_int(node, "ip4_prefix_len", mp->ip4_prefix_len);
1413 vat_json_object_add_int(node, "ip6_src_len", mp->ip6_src_len);
1414 vat_json_object_add_int(node, "ea_bits_len", mp->ea_bits_len);
1415 vat_json_object_add_int(node, "psid_offset", mp->psid_offset);
1416 vat_json_object_add_int(node, "psid_length", mp->psid_length);
1417 vat_json_object_add_uint(node, "flags", mp->flags);
1418 vat_json_object_add_uint(node, "mtu", clib_net_to_host_u16(mp->mtu));
1419 vat_json_object_add_int(node, "is_translation", mp->is_translation);
1422 static void vl_api_map_domain_details_t_handler
1423 (vl_api_map_domain_details_t * mp)
1425 vat_main_t * vam = &vat_main;
1427 if (mp->is_translation) {
1428 fformat(vam->ofp, "* %U/%d (ipv4-prefix) %U/%d (ipv6-prefix) %U/%d (ip6-src) index: %u\n",
1429 format_ip4_address, mp->ip4_prefix, mp->ip4_prefix_len,
1430 format_ip6_address, mp->ip6_prefix, mp->ip6_prefix_len,
1431 format_ip6_address, mp->ip6_src, mp->ip6_src_len, clib_net_to_host_u32(mp->domain_index));
1433 fformat(vam->ofp, "* %U/%d (ipv4-prefix) %U/%d (ipv6-prefix) %U (ip6-src) index: %u\n",
1434 format_ip4_address, mp->ip4_prefix, mp->ip4_prefix_len,
1435 format_ip6_address, mp->ip6_prefix, mp->ip6_prefix_len,
1436 format_ip6_address, mp->ip6_src, clib_net_to_host_u32(mp->domain_index));
1438 fformat(vam->ofp, " ea-len %d psid-offset %d psid-len %d mtu %d %s\n",
1439 mp->ea_bits_len, mp->psid_offset, mp->psid_length, mp->mtu, mp->is_translation? "map-t":"");
1442 static void vl_api_map_rule_details_t_handler_json
1443 (vl_api_map_rule_details_t * mp)
1445 struct in6_addr ip6;
1446 vat_json_node_t * node = NULL;
1447 vat_main_t * vam = &vat_main;
1449 if (VAT_JSON_ARRAY != vam->json_tree.type) {
1450 ASSERT(VAT_JSON_NONE == vam->json_tree.type);
1451 vat_json_init_array(&vam->json_tree);
1454 node = vat_json_array_add(&vam->json_tree);
1455 vat_json_init_object(node);
1457 vat_json_object_add_uint(node, "psid", clib_net_to_host_u16(mp->psid));
1458 memcpy(&ip6, mp->ip6_dst, sizeof(ip6));
1459 vat_json_object_add_ip6(node, "ip6_dst", ip6);
1462 static void vl_api_map_rule_details_t_handler
1463 (vl_api_map_rule_details_t * mp)
1465 vat_main_t * vam = &vat_main;
1466 fformat(vam->ofp, " %d (psid) %U (ip6-dst)\n", clib_net_to_host_u16(mp->psid),
1467 format_ip6_address, mp->ip6_dst);
1470 static void vl_api_dhcp_compl_event_t_handler
1471 (vl_api_dhcp_compl_event_t * mp)
1473 vat_main_t * vam = &vat_main;
1474 errmsg ("DHCP compl event: pid %d %s hostname %s host_addr %U "
1475 "router_addr %U host_mac %U\n",
1476 mp->pid, mp->is_ipv6 ? "ipv6":"ipv4", mp->hostname,
1477 format_ip4_address, &mp->host_address,
1478 format_ip4_address, &mp->router_address,
1479 format_ethernet_address, mp->host_mac);
1482 static void vl_api_dhcp_compl_event_t_handler_json
1483 (vl_api_dhcp_compl_event_t * mp)
1485 /* JSON output not supported */
1488 static void set_simple_interface_counter (u8 vnet_counter_type, u32 sw_if_index,
1491 vat_main_t * vam = &vat_main;
1492 static u64 default_counter = 0;
1494 vec_validate_init_empty(vam->simple_interface_counters, vnet_counter_type, NULL);
1495 vec_validate_init_empty(vam->simple_interface_counters[vnet_counter_type],
1496 sw_if_index, default_counter);
1497 vam->simple_interface_counters[vnet_counter_type][sw_if_index] = counter;
1500 static void set_combined_interface_counter (u8 vnet_counter_type, u32 sw_if_index,
1501 interface_counter_t counter)
1503 vat_main_t * vam = &vat_main;
1504 static interface_counter_t default_counter = {0, };
1506 vec_validate_init_empty(vam->combined_interface_counters, vnet_counter_type, NULL);
1507 vec_validate_init_empty(vam->combined_interface_counters[vnet_counter_type],
1508 sw_if_index, default_counter);
1509 vam->combined_interface_counters[vnet_counter_type][sw_if_index] = counter;
1512 static void vl_api_vnet_interface_counters_t_handler
1513 (vl_api_vnet_interface_counters_t *mp)
1518 static void vl_api_vnet_interface_counters_t_handler_json
1519 (vl_api_vnet_interface_counters_t *mp)
1521 interface_counter_t counter;
1526 u32 first_sw_if_index;
1529 count = ntohl(mp->count);
1530 first_sw_if_index = ntohl(mp->first_sw_if_index);
1532 if (!mp->is_combined) {
1533 v_packets = (u64*)&mp->data;
1534 for (i = 0; i < count; i++) {
1535 packets = clib_net_to_host_u64(clib_mem_unaligned(v_packets, u64));
1536 set_simple_interface_counter(mp->vnet_counter_type,
1537 first_sw_if_index + i, packets);
1541 v = (vlib_counter_t*)&mp->data;
1542 for (i = 0; i < count; i++) {
1543 counter.packets = clib_net_to_host_u64(
1544 clib_mem_unaligned(&v->packets, u64));
1545 counter.bytes = clib_net_to_host_u64(
1546 clib_mem_unaligned(&v->bytes, u64));
1547 set_combined_interface_counter(mp->vnet_counter_type,
1548 first_sw_if_index + i, counter);
1554 static u32 ip4_fib_counters_get_vrf_index_by_vrf_id (u32 vrf_id)
1556 vat_main_t * vam = &vat_main;
1559 for (i = 0; i < vec_len(vam->ip4_fib_counters_vrf_id_by_index); i++) {
1560 if (vam->ip4_fib_counters_vrf_id_by_index[i] == vrf_id) {
1567 static u32 ip6_fib_counters_get_vrf_index_by_vrf_id (u32 vrf_id)
1569 vat_main_t * vam = &vat_main;
1572 for (i = 0; i < vec_len(vam->ip6_fib_counters_vrf_id_by_index); i++) {
1573 if (vam->ip6_fib_counters_vrf_id_by_index[i] == vrf_id) {
1580 static void vl_api_vnet_ip4_fib_counters_t_handler
1581 (vl_api_vnet_ip4_fib_counters_t *mp)
1586 static void vl_api_vnet_ip4_fib_counters_t_handler_json
1587 (vl_api_vnet_ip4_fib_counters_t *mp)
1589 vat_main_t * vam = &vat_main;
1590 vl_api_ip4_fib_counter_t *v;
1591 ip4_fib_counter_t *counter;
1598 vrf_id = ntohl(mp->vrf_id);
1599 vrf_index = ip4_fib_counters_get_vrf_index_by_vrf_id(vrf_id);
1600 if (~0 == vrf_index) {
1601 vrf_index = vec_len(vam->ip4_fib_counters_vrf_id_by_index);
1602 vec_validate(vam->ip4_fib_counters_vrf_id_by_index, vrf_index);
1603 vam->ip4_fib_counters_vrf_id_by_index[vrf_index] = vrf_id;
1604 vec_validate(vam->ip4_fib_counters, vrf_index);
1605 vam->ip4_fib_counters[vrf_index] = NULL;
1608 vec_free(vam->ip4_fib_counters[vrf_index]);
1609 v = (vl_api_ip4_fib_counter_t*)&mp->c;
1610 count = ntohl(mp->count);
1611 for (i = 0; i < count; i++) {
1612 vec_validate(vam->ip4_fib_counters[vrf_index], i);
1613 counter = &vam->ip4_fib_counters[vrf_index][i];
1614 memcpy(&ip4, &v->address, sizeof(ip4));
1615 counter->address = ip4;
1616 counter->address_length = v->address_length;
1617 counter->packets = clib_net_to_host_u64(v->packets);
1618 counter->bytes = clib_net_to_host_u64(v->bytes);
1623 static void vl_api_vnet_ip6_fib_counters_t_handler
1624 (vl_api_vnet_ip6_fib_counters_t *mp)
1629 static void vl_api_vnet_ip6_fib_counters_t_handler_json
1630 (vl_api_vnet_ip6_fib_counters_t *mp)
1632 vat_main_t * vam = &vat_main;
1633 vl_api_ip6_fib_counter_t *v;
1634 ip6_fib_counter_t *counter;
1635 struct in6_addr ip6;
1641 vrf_id = ntohl(mp->vrf_id);
1642 vrf_index = ip6_fib_counters_get_vrf_index_by_vrf_id(vrf_id);
1643 if (~0 == vrf_index) {
1644 vrf_index = vec_len(vam->ip6_fib_counters_vrf_id_by_index);
1645 vec_validate(vam->ip6_fib_counters_vrf_id_by_index, vrf_index);
1646 vam->ip6_fib_counters_vrf_id_by_index[vrf_index] = vrf_id;
1647 vec_validate(vam->ip6_fib_counters, vrf_index);
1648 vam->ip6_fib_counters[vrf_index] = NULL;
1651 vec_free(vam->ip6_fib_counters[vrf_index]);
1652 v = (vl_api_ip6_fib_counter_t*)&mp->c;
1653 count = ntohl(mp->count);
1654 for (i = 0; i < count; i++) {
1655 vec_validate(vam->ip6_fib_counters[vrf_index], i);
1656 counter = &vam->ip6_fib_counters[vrf_index][i];
1657 memcpy(&ip6, &v->address, sizeof(ip6));
1658 counter->address = ip6;
1659 counter->address_length = v->address_length;
1660 counter->packets = clib_net_to_host_u64(v->packets);
1661 counter->bytes = clib_net_to_host_u64(v->bytes);
1666 static void vl_api_get_first_msg_id_reply_t_handler
1667 (vl_api_get_first_msg_id_reply_t * mp)
1669 vat_main_t * vam = &vat_main;
1670 i32 retval = ntohl(mp->retval);
1672 if (vam->async_mode) {
1673 vam->async_errors += (retval < 0);
1675 vam->retval = retval;
1676 vam->result_ready = 1;
1679 errmsg ("first message id %d\n", ntohs(mp->first_msg_id));
1683 static void vl_api_get_first_msg_id_reply_t_handler_json
1684 (vl_api_get_first_msg_id_reply_t * mp)
1686 vat_main_t * vam = &vat_main;
1687 vat_json_node_t node;
1689 vat_json_init_object(&node);
1690 vat_json_object_add_int(&node, "retval", ntohl(mp->retval));
1691 vat_json_object_add_uint(&node, "first_msg_id",
1692 (uint) ntohs(mp->first_msg_id));
1694 vat_json_print(vam->ofp, &node);
1695 vat_json_free(&node);
1697 vam->retval = ntohl(mp->retval);
1698 vam->result_ready = 1;
1701 #define vl_api_vnet_ip4_fib_counters_t_endian vl_noop_handler
1702 #define vl_api_vnet_ip4_fib_counters_t_print vl_noop_handler
1703 #define vl_api_vnet_ip6_fib_counters_t_endian vl_noop_handler
1704 #define vl_api_vnet_ip6_fib_counters_t_print vl_noop_handler
1707 * Generate boilerplate reply handlers, which
1708 * dig the return value out of the xxx_reply_t API message,
1709 * stick it into vam->retval, and set vam->result_ready
1711 * Could also do this by pointing N message decode slots at
1712 * a single function, but that could break in subtle ways.
1715 #define foreach_standard_reply_retval_handler \
1716 _(sw_interface_set_flags_reply) \
1717 _(sw_interface_add_del_address_reply) \
1718 _(sw_interface_set_table_reply) \
1719 _(sw_interface_set_vpath_reply) \
1720 _(sw_interface_set_l2_bridge_reply) \
1721 _(bridge_domain_add_del_reply) \
1722 _(sw_interface_set_l2_xconnect_reply) \
1723 _(l2fib_add_del_reply) \
1724 _(ip_add_del_route_reply) \
1725 _(proxy_arp_add_del_reply) \
1726 _(proxy_arp_intfc_enable_disable_reply) \
1727 _(mpls_add_del_encap_reply) \
1728 _(mpls_add_del_decap_reply) \
1729 _(mpls_ethernet_add_del_tunnel_2_reply) \
1730 _(sw_interface_set_unnumbered_reply) \
1731 _(ip_neighbor_add_del_reply) \
1732 _(reset_vrf_reply) \
1733 _(oam_add_del_reply) \
1734 _(reset_fib_reply) \
1735 _(dhcp_proxy_config_reply) \
1736 _(dhcp_proxy_config_2_reply) \
1737 _(dhcp_proxy_set_vss_reply) \
1738 _(dhcp_client_config_reply) \
1739 _(set_ip_flow_hash_reply) \
1740 _(sw_interface_ip6_enable_disable_reply) \
1741 _(sw_interface_ip6_set_link_local_address_reply) \
1742 _(sw_interface_ip6nd_ra_prefix_reply) \
1743 _(sw_interface_ip6nd_ra_config_reply) \
1744 _(set_arp_neighbor_limit_reply) \
1745 _(l2_patch_add_del_reply) \
1746 _(sr_tunnel_add_del_reply) \
1747 _(classify_add_del_session_reply) \
1748 _(classify_set_interface_ip_table_reply) \
1749 _(classify_set_interface_l2_tables_reply) \
1750 _(l2tpv3_set_tunnel_cookies_reply) \
1751 _(l2tpv3_interface_enable_disable_reply) \
1752 _(l2tpv3_set_lookup_key_reply) \
1753 _(l2_fib_clear_table_reply) \
1754 _(l2_interface_efp_filter_reply) \
1755 _(l2_interface_vlan_tag_rewrite_reply) \
1756 _(modify_vhost_user_if_reply) \
1757 _(delete_vhost_user_if_reply) \
1758 _(want_ip4_arp_events_reply) \
1759 _(input_acl_set_interface_reply) \
1760 _(ipsec_spd_add_del_reply) \
1761 _(ipsec_interface_add_del_spd_reply) \
1762 _(ipsec_spd_add_del_entry_reply) \
1763 _(ipsec_sad_add_del_entry_reply) \
1764 _(ipsec_sa_set_key_reply) \
1765 _(delete_loopback_reply) \
1766 _(bd_ip_mac_add_del_reply) \
1767 _(map_del_domain_reply) \
1768 _(map_add_del_rule_reply) \
1769 _(want_interface_events_reply) \
1773 static void vl_api_##n##_t_handler \
1774 (vl_api_##n##_t * mp) \
1776 vat_main_t * vam = &vat_main; \
1777 i32 retval = ntohl(mp->retval); \
1778 if (vam->async_mode) { \
1779 vam->async_errors += (retval < 0); \
1781 vam->retval = retval; \
1782 vam->result_ready = 1; \
1785 foreach_standard_reply_retval_handler;
1789 static void vl_api_##n##_t_handler_json \
1790 (vl_api_##n##_t * mp) \
1792 vat_main_t * vam = &vat_main; \
1793 vat_json_node_t node; \
1794 vat_json_init_object(&node); \
1795 vat_json_object_add_int(&node, "retval", ntohl(mp->retval)); \
1796 vat_json_print(vam->ofp, &node); \
1797 vam->retval = ntohl(mp->retval); \
1798 vam->result_ready = 1; \
1800 foreach_standard_reply_retval_handler;
1804 * Table of message reply handlers, must include boilerplate handlers
1808 #define foreach_vpe_api_reply_msg \
1809 _(CREATE_LOOPBACK_REPLY, create_loopback_reply) \
1810 _(SW_INTERFACE_DETAILS, sw_interface_details) \
1811 _(SW_INTERFACE_SET_FLAGS, sw_interface_set_flags) \
1812 _(SW_INTERFACE_SET_FLAGS_REPLY, sw_interface_set_flags_reply) \
1813 _(CONTROL_PING_REPLY, control_ping_reply) \
1814 _(CLI_REPLY, cli_reply) \
1815 _(SW_INTERFACE_ADD_DEL_ADDRESS_REPLY, \
1816 sw_interface_add_del_address_reply) \
1817 _(SW_INTERFACE_SET_TABLE_REPLY, sw_interface_set_table_reply) \
1818 _(SW_INTERFACE_SET_VPATH_REPLY, sw_interface_set_vpath_reply) \
1819 _(SW_INTERFACE_SET_L2_XCONNECT_REPLY, \
1820 sw_interface_set_l2_xconnect_reply) \
1821 _(SW_INTERFACE_SET_L2_BRIDGE_REPLY, \
1822 sw_interface_set_l2_bridge_reply) \
1823 _(BRIDGE_DOMAIN_ADD_DEL_REPLY, bridge_domain_add_del_reply) \
1824 _(BRIDGE_DOMAIN_DETAILS, bridge_domain_details) \
1825 _(BRIDGE_DOMAIN_SW_IF_DETAILS, bridge_domain_sw_if_details) \
1826 _(L2FIB_ADD_DEL_REPLY, l2fib_add_del_reply) \
1827 _(L2_FLAGS_REPLY, l2_flags_reply) \
1828 _(BRIDGE_FLAGS_REPLY, bridge_flags_reply) \
1829 _(TAP_CONNECT_REPLY, tap_connect_reply) \
1830 _(TAP_MODIFY_REPLY, tap_modify_reply) \
1831 _(TAP_DELETE_REPLY, tap_delete_reply) \
1832 _(SW_INTERFACE_TAP_DETAILS, sw_interface_tap_details) \
1833 _(IP_ADD_DEL_ROUTE_REPLY, ip_add_del_route_reply) \
1834 _(PROXY_ARP_ADD_DEL_REPLY, proxy_arp_add_del_reply) \
1835 _(PROXY_ARP_INTFC_ENABLE_DISABLE_REPLY, \
1836 proxy_arp_intfc_enable_disable_reply) \
1837 _(MPLS_ADD_DEL_ENCAP_REPLY, mpls_add_del_encap_reply) \
1838 _(MPLS_ADD_DEL_DECAP_REPLY, mpls_add_del_decap_reply) \
1839 _(MPLS_GRE_ADD_DEL_TUNNEL_REPLY, mpls_gre_add_del_tunnel_reply) \
1840 _(MPLS_ETHERNET_ADD_DEL_TUNNEL_REPLY, \
1841 mpls_ethernet_add_del_tunnel_reply) \
1842 _(MPLS_ETHERNET_ADD_DEL_TUNNEL_2_REPLY, \
1843 mpls_ethernet_add_del_tunnel_2_reply) \
1844 _(SW_INTERFACE_SET_UNNUMBERED_REPLY, \
1845 sw_interface_set_unnumbered_reply) \
1846 _(IP_NEIGHBOR_ADD_DEL_REPLY, ip_neighbor_add_del_reply) \
1847 _(RESET_VRF_REPLY, reset_vrf_reply) \
1848 _(CREATE_VLAN_SUBIF_REPLY, create_vlan_subif_reply) \
1849 _(CREATE_SUBIF_REPLY, create_subif_reply) \
1850 _(OAM_ADD_DEL_REPLY, oam_add_del_reply) \
1851 _(RESET_FIB_REPLY, reset_fib_reply) \
1852 _(DHCP_PROXY_CONFIG_REPLY, dhcp_proxy_config_reply) \
1853 _(DHCP_PROXY_CONFIG_2_REPLY, dhcp_proxy_config_2_reply) \
1854 _(DHCP_PROXY_SET_VSS_REPLY, dhcp_proxy_set_vss_reply) \
1855 _(DHCP_CLIENT_CONFIG_REPLY, dhcp_client_config_reply) \
1856 _(SET_IP_FLOW_HASH_REPLY, set_ip_flow_hash_reply) \
1857 _(SW_INTERFACE_IP6_ENABLE_DISABLE_REPLY, \
1858 sw_interface_ip6_enable_disable_reply) \
1859 _(SW_INTERFACE_IP6_SET_LINK_LOCAL_ADDRESS_REPLY, \
1860 sw_interface_ip6_set_link_local_address_reply) \
1861 _(SW_INTERFACE_IP6ND_RA_PREFIX_REPLY, \
1862 sw_interface_ip6nd_ra_prefix_reply) \
1863 _(SW_INTERFACE_IP6ND_RA_CONFIG_REPLY, \
1864 sw_interface_ip6nd_ra_config_reply) \
1865 _(SET_ARP_NEIGHBOR_LIMIT_REPLY, set_arp_neighbor_limit_reply) \
1866 _(L2_PATCH_ADD_DEL_REPLY, l2_patch_add_del_reply) \
1867 _(SR_TUNNEL_ADD_DEL_REPLY, sr_tunnel_add_del_reply) \
1868 _(CLASSIFY_ADD_DEL_TABLE_REPLY, classify_add_del_table_reply) \
1869 _(CLASSIFY_ADD_DEL_SESSION_REPLY, classify_add_del_session_reply) \
1870 _(CLASSIFY_SET_INTERFACE_IP_TABLE_REPLY, \
1871 classify_set_interface_ip_table_reply) \
1872 _(CLASSIFY_SET_INTERFACE_L2_TABLES_REPLY, \
1873 classify_set_interface_l2_tables_reply) \
1874 _(GET_NODE_INDEX_REPLY, get_node_index_reply) \
1875 _(ADD_NODE_NEXT_REPLY, add_node_next_reply) \
1876 _(L2TPV3_CREATE_TUNNEL_REPLY, l2tpv3_create_tunnel_reply) \
1877 _(L2TPV3_SET_TUNNEL_COOKIES_REPLY, l2tpv3_set_tunnel_cookies_reply) \
1878 _(L2TPV3_INTERFACE_ENABLE_DISABLE_REPLY, \
1879 l2tpv3_interface_enable_disable_reply) \
1880 _(L2TPV3_SET_LOOKUP_KEY_REPLY, l2tpv3_set_lookup_key_reply) \
1881 _(SW_IF_L2TPV3_TUNNEL_DETAILS, sw_if_l2tpv3_tunnel_details) \
1882 _(VXLAN_ADD_DEL_TUNNEL_REPLY, vxlan_add_del_tunnel_reply) \
1883 _(VXLAN_TUNNEL_DETAILS, vxlan_tunnel_details) \
1884 _(L2_FIB_CLEAR_TABLE_REPLY, l2_fib_clear_table_reply) \
1885 _(L2_INTERFACE_EFP_FILTER_REPLY, l2_interface_efp_filter_reply) \
1886 _(L2_INTERFACE_VLAN_TAG_REWRITE_REPLY, l2_interface_vlan_tag_rewrite_reply) \
1887 _(SW_INTERFACE_VHOST_USER_DETAILS, sw_interface_vhost_user_details) \
1888 _(CREATE_VHOST_USER_IF_REPLY, create_vhost_user_if_reply) \
1889 _(MODIFY_VHOST_USER_IF_REPLY, modify_vhost_user_if_reply) \
1890 _(DELETE_VHOST_USER_IF_REPLY, delete_vhost_user_if_reply) \
1891 _(SHOW_VERSION_REPLY, show_version_reply) \
1892 _(NSH_GRE_ADD_DEL_TUNNEL_REPLY, nsh_gre_add_del_tunnel_reply) \
1893 _(L2_FIB_TABLE_ENTRY, l2_fib_table_entry) \
1894 _(NSH_VXLAN_GPE_ADD_DEL_TUNNEL_REPLY, nsh_vxlan_gpe_add_del_tunnel_reply) \
1895 _(LISP_GPE_ADD_DEL_TUNNEL_REPLY, lisp_gpe_add_del_tunnel_reply) \
1896 _(INTERFACE_NAME_RENUMBER_REPLY, interface_name_renumber_reply) \
1897 _(WANT_IP4_ARP_EVENTS_REPLY, want_ip4_arp_events_reply) \
1898 _(IP4_ARP_EVENT, ip4_arp_event) \
1899 _(INPUT_ACL_SET_INTERFACE_REPLY, input_acl_set_interface_reply) \
1900 _(IP_ADDRESS_DETAILS, ip_address_details) \
1901 _(IP_DETAILS, ip_details) \
1902 _(IPSEC_SPD_ADD_DEL_REPLY, ipsec_spd_add_del_reply) \
1903 _(IPSEC_INTERFACE_ADD_DEL_SPD_REPLY, ipsec_interface_add_del_spd_reply) \
1904 _(IPSEC_SPD_ADD_DEL_ENTRY_REPLY, ipsec_spd_add_del_entry_reply) \
1905 _(IPSEC_SAD_ADD_DEL_ENTRY_REPLY, ipsec_sad_add_del_entry_reply) \
1906 _(IPSEC_SA_SET_KEY_REPLY, ipsec_sa_set_key_reply) \
1907 _(DELETE_LOOPBACK_REPLY, delete_loopback_reply) \
1908 _(BD_IP_MAC_ADD_DEL_REPLY, bd_ip_mac_add_del_reply) \
1909 _(DHCP_COMPL_EVENT, dhcp_compl_event) \
1910 _(VNET_INTERFACE_COUNTERS, vnet_interface_counters) \
1911 _(VNET_IP4_FIB_COUNTERS, vnet_ip4_fib_counters) \
1912 _(VNET_IP6_FIB_COUNTERS, vnet_ip6_fib_counters) \
1913 _(MAP_ADD_DOMAIN_REPLY, map_add_domain_reply) \
1914 _(MAP_DEL_DOMAIN_REPLY, map_del_domain_reply) \
1915 _(MAP_ADD_DEL_RULE_REPLY, map_add_del_rule_reply) \
1916 _(MAP_DOMAIN_DETAILS, map_domain_details) \
1917 _(MAP_RULE_DETAILS, map_rule_details) \
1918 _(WANT_INTERFACE_EVENTS_REPLY, want_interface_events_reply) \
1919 _(WANT_STATS_REPLY, want_stats_reply) \
1920 _(GET_FIRST_MSG_ID_REPLY, get_first_msg_id_reply)
1922 /* M: construct, but don't yet send a message */
1926 vam->result_ready = 0; \
1927 mp = vl_msg_api_alloc(sizeof(*mp)); \
1928 memset (mp, 0, sizeof (*mp)); \
1929 mp->_vl_msg_id = ntohs (VL_API_##T); \
1930 mp->client_index = vam->my_client_index; \
1935 vam->result_ready = 0; \
1936 mp = vl_msg_api_alloc(sizeof(*mp)+(n)); \
1937 memset (mp, 0, sizeof (*mp)); \
1938 mp->_vl_msg_id = ntohs (VL_API_##T); \
1939 mp->client_index = vam->my_client_index; \
1943 /* S: send a message */
1944 #define S (vl_msg_api_send_shmem (vam->vl_input_queue, (u8 *)&mp))
1946 /* W: wait for results, with timeout */
1949 timeout = vat_time_now (vam) + 1.0; \
1951 while (vat_time_now (vam) < timeout) { \
1952 if (vam->result_ready == 1) { \
1953 return (vam->retval); \
1965 #define STR_VTR_OP_CASE(op) \
1966 case L2_VTR_ ## op: \
1969 static const char *str_vtr_op(u32 vtr_op)
1972 STR_VTR_OP_CASE(DISABLED);
1973 STR_VTR_OP_CASE(PUSH_1);
1974 STR_VTR_OP_CASE(PUSH_2);
1975 STR_VTR_OP_CASE(POP_1);
1976 STR_VTR_OP_CASE(POP_2);
1977 STR_VTR_OP_CASE(TRANSLATE_1_1);
1978 STR_VTR_OP_CASE(TRANSLATE_1_2);
1979 STR_VTR_OP_CASE(TRANSLATE_2_1);
1980 STR_VTR_OP_CASE(TRANSLATE_2_2);
1986 static int dump_sub_interface_table (vat_main_t * vam)
1988 const sw_interface_subif_t * sub = NULL;
1990 if (vam->json_output) {
1991 clib_warning ("JSON output supported only for VPE API calls and dump_stats_table");
1996 "%-30s%-12s%-11s%-7s%-5s%-9s%-9s%-6s%-8s%-10s%-10s\n",
1997 "Interface", "sw_if_index",
1998 "sub id", "dot1ad", "tags", "outer id",
1999 "inner id", "exact", "default",
2000 "outer any", "inner any");
2002 vec_foreach (sub, vam->sw_if_subif_table) {
2004 "%-30s%-12d%-11d%-7s%-5d%-9d%-9d%-6d%-8d%-10d%-10d\n",
2005 sub->interface_name,
2007 sub->sub_id, sub->sub_dot1ad ? "dot1ad" : "dot1q",
2008 sub->sub_number_of_tags, sub->sub_outer_vlan_id,
2009 sub->sub_inner_vlan_id, sub->sub_exact_match, sub->sub_default,
2010 sub->sub_outer_vlan_id_any, sub->sub_inner_vlan_id_any);
2011 if (sub->vtr_op != L2_VTR_DISABLED) {
2013 " vlan-tag-rewrite - op: %-14s [ dot1q: %d "
2014 "tag1: %d tag2: %d ]\n",
2015 str_vtr_op(sub->vtr_op), sub->vtr_push_dot1q,
2016 sub->vtr_tag1, sub->vtr_tag2);
2023 static int name_sort_cmp (void * a1, void * a2)
2025 name_sort_t * n1 = a1;
2026 name_sort_t * n2 = a2;
2028 return strcmp ((char *)n1->name, (char *)n2->name);
2031 static int dump_interface_table (vat_main_t * vam)
2034 name_sort_t * nses = 0, * ns;
2036 if (vam->json_output) {
2037 clib_warning ("JSON output supported only for VPE API calls and dump_stats_table");
2041 hash_foreach_pair (p, vam->sw_if_index_by_interface_name,
2043 vec_add2 (nses, ns, 1);
2044 ns->name = (u8 *)(p->key);
2045 ns->value = (u32) p->value[0];
2048 vec_sort_with_function (nses, name_sort_cmp);
2050 fformat (vam->ofp, "%-25s%-15s\n", "Interface", "sw_if_index");
2051 vec_foreach (ns, nses) {
2052 fformat (vam->ofp, "%-25s%-15d\n", ns->name, ns->value);
2058 static int dump_ip_table (vat_main_t * vam, int is_ipv6)
2060 const ip_details_t * det = NULL;
2061 const ip_address_details_t * address = NULL;
2068 if (0 == vam->ip_details_by_sw_if_index) {
2072 vec_foreach (det, vam->ip_details_by_sw_if_index[is_ipv6]) {
2074 if (!det->present) {
2082 "Address", "Prefix length");
2086 vec_foreach (address, det->addr) {
2089 is_ipv6 ? format_ip6_address : format_ip4_address,
2091 address->prefix_length);
2098 static int dump_ipv4_table (vat_main_t * vam)
2100 if (vam->json_output) {
2101 clib_warning ("JSON output supported only for VPE API calls and dump_stats_table");
2105 return dump_ip_table (vam, 0);
2108 static int dump_ipv6_table (vat_main_t * vam)
2110 if (vam->json_output) {
2111 clib_warning ("JSON output supported only for VPE API calls and dump_stats_table");
2115 return dump_ip_table (vam, 1);
2118 static char* counter_type_to_str (u8 counter_type, u8 is_combined)
2121 switch(counter_type) {
2122 case VNET_INTERFACE_COUNTER_DROP:
2124 case VNET_INTERFACE_COUNTER_PUNT:
2126 case VNET_INTERFACE_COUNTER_IP4:
2128 case VNET_INTERFACE_COUNTER_IP6:
2130 case VNET_INTERFACE_COUNTER_RX_NO_BUF:
2132 case VNET_INTERFACE_COUNTER_RX_MISS:
2134 case VNET_INTERFACE_COUNTER_RX_ERROR:
2136 case VNET_INTERFACE_COUNTER_TX_ERROR:
2139 return "INVALID-COUNTER-TYPE";
2142 switch(counter_type) {
2143 case VNET_INTERFACE_COUNTER_RX:
2145 case VNET_INTERFACE_COUNTER_TX:
2148 return "INVALID-COUNTER-TYPE";
2153 static int dump_stats_table (vat_main_t * vam)
2155 vat_json_node_t node;
2156 vat_json_node_t *msg_array;
2157 vat_json_node_t *msg;
2158 vat_json_node_t *counter_array;
2159 vat_json_node_t *counter;
2160 interface_counter_t c;
2162 ip4_fib_counter_t *c4;
2163 ip6_fib_counter_t *c6;
2166 if (!vam->json_output) {
2167 clib_warning ("dump_stats_table supported only in JSON format");
2171 vat_json_init_object(&node);
2173 /* interface counters */
2174 msg_array = vat_json_object_add(&node, "interface_counters");
2175 vat_json_init_array(msg_array);
2176 for (i = 0; i < vec_len(vam->simple_interface_counters); i++) {
2177 msg = vat_json_array_add(msg_array);
2178 vat_json_init_object(msg);
2179 vat_json_object_add_string_copy(msg, "vnet_counter_type",
2180 (u8*)counter_type_to_str(i, 0));
2181 vat_json_object_add_int(msg, "is_combined", 0);
2182 counter_array = vat_json_object_add(msg, "data");
2183 vat_json_init_array(counter_array);
2184 for (j = 0; j < vec_len(vam->simple_interface_counters[i]); j++) {
2185 packets = vam->simple_interface_counters[i][j];
2186 vat_json_array_add_uint(counter_array, packets);
2189 for (i = 0; i < vec_len(vam->combined_interface_counters); i++) {
2190 msg = vat_json_array_add(msg_array);
2191 vat_json_init_object(msg);
2192 vat_json_object_add_string_copy(msg, "vnet_counter_type",
2193 (u8*)counter_type_to_str(i, 1));
2194 vat_json_object_add_int(msg, "is_combined", 1);
2195 counter_array = vat_json_object_add(msg, "data");
2196 vat_json_init_array(counter_array);
2197 for (j = 0; j < vec_len(vam->combined_interface_counters[i]); j++) {
2198 c = vam->combined_interface_counters[i][j];
2199 counter = vat_json_array_add(counter_array);
2200 vat_json_init_object(counter);
2201 vat_json_object_add_uint(counter, "packets", c.packets);
2202 vat_json_object_add_uint(counter, "bytes", c.bytes);
2206 /* ip4 fib counters */
2207 msg_array = vat_json_object_add(&node, "ip4_fib_counters");
2208 vat_json_init_array(msg_array);
2209 for (i = 0; i < vec_len(vam->ip4_fib_counters); i++) {
2210 msg = vat_json_array_add(msg_array);
2211 vat_json_init_object(msg);
2212 vat_json_object_add_uint(msg, "vrf_id", vam->ip4_fib_counters_vrf_id_by_index[i]);
2213 counter_array = vat_json_object_add(msg, "c");
2214 vat_json_init_array(counter_array);
2215 for (j = 0; j < vec_len(vam->ip4_fib_counters[i]); j++) {
2216 counter = vat_json_array_add(counter_array);
2217 vat_json_init_object(counter);
2218 c4 = &vam->ip4_fib_counters[i][j];
2219 vat_json_object_add_ip4(counter, "address", c4->address);
2220 vat_json_object_add_uint(counter, "address_length", c4->address_length);
2221 vat_json_object_add_uint(counter, "packets", c4->packets);
2222 vat_json_object_add_uint(counter, "bytes", c4->bytes);
2226 /* ip6 fib counters */
2227 msg_array = vat_json_object_add(&node, "ip6_fib_counters");
2228 vat_json_init_array(msg_array);
2229 for (i = 0; i < vec_len(vam->ip6_fib_counters); i++) {
2230 msg = vat_json_array_add(msg_array);
2231 vat_json_init_object(msg);
2232 vat_json_object_add_uint(msg, "vrf_id", vam->ip6_fib_counters_vrf_id_by_index[i]);
2233 counter_array = vat_json_object_add(msg, "c");
2234 vat_json_init_array(counter_array);
2235 for (j = 0; j < vec_len(vam->ip6_fib_counters[i]); j++) {
2236 counter = vat_json_array_add(counter_array);
2237 vat_json_init_object(counter);
2238 c6 = &vam->ip6_fib_counters[i][j];
2239 vat_json_object_add_ip6(counter, "address", c6->address);
2240 vat_json_object_add_uint(counter, "address_length", c6->address_length);
2241 vat_json_object_add_uint(counter, "packets", c6->packets);
2242 vat_json_object_add_uint(counter, "bytes", c6->bytes);
2246 vat_json_print(vam->ofp, &node);
2247 vat_json_free(&node);
2252 int exec (vat_main_t * vam)
2254 api_main_t * am = &api_main;
2255 vl_api_cli_request_t *mp;
2259 unformat_input_t * i = vam->input;
2261 if (vec_len(i->buffer) == 0)
2264 if (vam->exec_mode == 0 && unformat (i, "mode")) {
2268 if (vam->exec_mode == 1 &&
2269 (unformat (i, "exit") || unformat (i, "quit"))) {
2275 M(CLI_REQUEST, cli_request);
2278 * Copy cmd into shared memory.
2279 * In order for the CLI command to work, it
2280 * must be a vector ending in \n, not a C-string ending
2283 pthread_mutex_lock (&am->vlib_rp->mutex);
2284 oldheap = svm_push_data_heap (am->vlib_rp);
2286 vec_validate (cmd, vec_len(vam->input->buffer)-1);
2287 memcpy (cmd, vam->input->buffer, vec_len(vam->input->buffer));
2289 svm_pop_heap (oldheap);
2290 pthread_mutex_unlock (&am->vlib_rp->mutex);
2292 mp->cmd_in_shmem = (u64) cmd;
2294 timeout = vat_time_now (vam) + 10.0;
2296 while (vat_time_now (vam) < timeout) {
2297 if (vam->result_ready == 1) {
2299 fformat (vam->ofp, "%s", vam->shmem_result);
2300 pthread_mutex_lock (&am->vlib_rp->mutex);
2301 oldheap = svm_push_data_heap (am->vlib_rp);
2303 free_me = (u8 *)vam->shmem_result;
2306 svm_pop_heap (oldheap);
2307 pthread_mutex_unlock (&am->vlib_rp->mutex);
2314 static int api_create_loopback (vat_main_t * vam)
2316 unformat_input_t * i = vam->input;
2317 vl_api_create_loopback_t *mp;
2322 memset (mac_address, 0, sizeof (mac_address));
2324 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
2326 if (unformat (i, "mac %U", unformat_ethernet_address, mac_address))
2332 /* Construct the API message */
2333 M(CREATE_LOOPBACK, create_loopback);
2335 memcpy (mp->mac_address, mac_address, sizeof (mac_address));
2340 static int api_delete_loopback (vat_main_t * vam)
2342 unformat_input_t * i = vam->input;
2343 vl_api_delete_loopback_t *mp;
2345 u32 sw_if_index = ~0;
2347 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
2349 if (unformat (i, "sw_if_index %d", &sw_if_index))
2355 if (sw_if_index == ~0)
2357 errmsg ("missing sw_if_index\n");
2361 /* Construct the API message */
2362 M(DELETE_LOOPBACK, delete_loopback);
2363 mp->sw_if_index = ntohl (sw_if_index);
2368 static int api_want_stats (vat_main_t * vam)
2370 unformat_input_t * i = vam->input;
2371 vl_api_want_stats_t * mp;
2375 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
2377 if (unformat (i, "enable"))
2379 else if (unformat (i, "disable"))
2387 errmsg ("missing enable|disable\n");
2391 M(WANT_STATS, want_stats);
2392 mp->enable_disable = enable;
2397 static int api_want_interface_events (vat_main_t * vam)
2399 unformat_input_t * i = vam->input;
2400 vl_api_want_interface_events_t * mp;
2404 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
2406 if (unformat (i, "enable"))
2408 else if (unformat (i, "disable"))
2416 errmsg ("missing enable|disable\n");
2420 M(WANT_INTERFACE_EVENTS, want_interface_events);
2421 mp->enable_disable = enable;
2423 vam->interface_event_display = enable;
2429 /* Note: non-static, called once to set up the initial intfc table */
2430 int api_sw_interface_dump (vat_main_t * vam)
2432 vl_api_sw_interface_dump_t *mp;
2435 name_sort_t * nses = 0, * ns;
2436 sw_interface_subif_t * sub = NULL;
2438 /* Toss the old name table */
2439 hash_foreach_pair (p, vam->sw_if_index_by_interface_name,
2441 vec_add2 (nses, ns, 1);
2442 ns->name = (u8 *)(p->key);
2443 ns->value = (u32) p->value[0];
2446 hash_free (vam->sw_if_index_by_interface_name);
2448 vec_foreach (ns, nses)
2449 vec_free (ns->name);
2453 vec_foreach (sub, vam->sw_if_subif_table) {
2454 vec_free (sub->interface_name);
2456 vec_free (vam->sw_if_subif_table);
2458 /* recreate the interface name hash table */
2459 vam->sw_if_index_by_interface_name
2460 = hash_create_string (0, sizeof(uword));
2462 /* Get list of ethernets */
2463 M(SW_INTERFACE_DUMP, sw_interface_dump);
2464 mp->name_filter_valid = 1;
2465 strncpy ((char *) mp->name_filter, "Ether", sizeof(mp->name_filter-1));
2468 /* and local / loopback interfaces */
2469 M(SW_INTERFACE_DUMP, sw_interface_dump);
2470 mp->name_filter_valid = 1;
2471 strncpy ((char *) mp->name_filter, "lo", sizeof(mp->name_filter-1));
2474 /* and vxlan tunnel interfaces */
2475 M(SW_INTERFACE_DUMP, sw_interface_dump);
2476 mp->name_filter_valid = 1;
2477 strncpy ((char *) mp->name_filter, "vxlan", sizeof(mp->name_filter-1));
2480 /* and l2tpv3 tunnel interfaces */
2481 M(SW_INTERFACE_DUMP, sw_interface_dump);
2482 mp->name_filter_valid = 1;
2483 strncpy ((char *) mp->name_filter, "l2tpv3_tunnel", sizeof(mp->name_filter-1));
2486 /* Use a control ping for synchronization */
2488 vl_api_control_ping_t * mp;
2489 M(CONTROL_PING, control_ping);
2495 static int api_sw_interface_set_flags (vat_main_t * vam)
2497 unformat_input_t * i = vam->input;
2498 vl_api_sw_interface_set_flags_t *mp;
2501 u8 sw_if_index_set = 0;
2502 u8 admin_up = 0, link_up = 0;
2504 /* Parse args required to build the message */
2505 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
2506 if (unformat (i, "admin-up"))
2508 else if (unformat (i, "admin-down"))
2510 else if (unformat (i, "link-up"))
2512 else if (unformat (i, "link-down"))
2514 else if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
2515 sw_if_index_set = 1;
2516 else if (unformat (i, "sw_if_index %d", &sw_if_index))
2517 sw_if_index_set = 1;
2522 if (sw_if_index_set == 0) {
2523 errmsg ("missing interface name or sw_if_index\n");
2527 /* Construct the API message */
2528 M(SW_INTERFACE_SET_FLAGS, sw_interface_set_flags);
2529 mp->sw_if_index = ntohl (sw_if_index);
2530 mp->admin_up_down = admin_up;
2531 mp->link_up_down = link_up;
2536 /* Wait for a reply, return the good/bad news... */
2540 static int api_sw_interface_add_del_address (vat_main_t * vam)
2542 unformat_input_t * i = vam->input;
2543 vl_api_sw_interface_add_del_address_t *mp;
2546 u8 sw_if_index_set = 0;
2547 u8 is_add = 1, del_all = 0;
2548 u32 address_length = 0;
2549 u8 v4_address_set = 0;
2550 u8 v6_address_set = 0;
2551 ip4_address_t v4address;
2552 ip6_address_t v6address;
2554 /* Parse args required to build the message */
2555 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
2556 if (unformat (i, "del-all"))
2558 else if (unformat (i, "del"))
2560 else if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
2561 sw_if_index_set = 1;
2562 else if (unformat (i, "sw_if_index %d", &sw_if_index))
2563 sw_if_index_set = 1;
2564 else if (unformat (i, "%U/%d",
2565 unformat_ip4_address, &v4address,
2568 else if (unformat (i, "%U/%d",
2569 unformat_ip6_address, &v6address,
2576 if (sw_if_index_set == 0) {
2577 errmsg ("missing interface name or sw_if_index\n");
2580 if (v4_address_set && v6_address_set) {
2581 errmsg ("both v4 and v6 addresses set\n");
2584 if (!v4_address_set && !v6_address_set && !del_all) {
2585 errmsg ("no addresses set\n");
2589 /* Construct the API message */
2590 M(SW_INTERFACE_ADD_DEL_ADDRESS, sw_interface_add_del_address);
2592 mp->sw_if_index = ntohl (sw_if_index);
2593 mp->is_add = is_add;
2594 mp->del_all = del_all;
2595 if (v6_address_set) {
2597 memcpy (mp->address, &v6address, sizeof (v6address));
2599 memcpy (mp->address, &v4address, sizeof (v4address));
2601 mp->address_length = address_length;
2606 /* Wait for a reply, return good/bad news */
2610 static int api_sw_interface_set_table (vat_main_t * vam)
2612 unformat_input_t * i = vam->input;
2613 vl_api_sw_interface_set_table_t *mp;
2615 u32 sw_if_index, vrf_id = 0;
2616 u8 sw_if_index_set = 0;
2619 /* Parse args required to build the message */
2620 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
2621 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
2622 sw_if_index_set = 1;
2623 else if (unformat (i, "sw_if_index %d", &sw_if_index))
2624 sw_if_index_set = 1;
2625 else if (unformat (i, "vrf %d", &vrf_id))
2627 else if (unformat (i, "ipv6"))
2633 if (sw_if_index_set == 0) {
2634 errmsg ("missing interface name or sw_if_index\n");
2638 /* Construct the API message */
2639 M(SW_INTERFACE_SET_TABLE, sw_interface_set_table);
2641 mp->sw_if_index = ntohl (sw_if_index);
2642 mp->is_ipv6 = is_ipv6;
2643 mp->vrf_id = ntohl (vrf_id);
2648 /* Wait for a reply... */
2652 static int api_sw_interface_set_vpath (vat_main_t * vam)
2654 unformat_input_t * i = vam->input;
2655 vl_api_sw_interface_set_vpath_t *mp;
2657 u32 sw_if_index = 0;
2658 u8 sw_if_index_set = 0;
2661 /* Parse args required to build the message */
2662 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
2663 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
2664 sw_if_index_set = 1;
2665 else if (unformat (i, "sw_if_index %d", &sw_if_index))
2666 sw_if_index_set = 1;
2667 else if (unformat (i, "enable"))
2669 else if (unformat (i, "disable"))
2675 if (sw_if_index_set == 0) {
2676 errmsg ("missing interface name or sw_if_index\n");
2680 /* Construct the API message */
2681 M(SW_INTERFACE_SET_VPATH, sw_interface_set_vpath);
2683 mp->sw_if_index = ntohl (sw_if_index);
2684 mp->enable = is_enable;
2689 /* Wait for a reply... */
2693 static int api_sw_interface_set_l2_xconnect (vat_main_t * vam)
2695 unformat_input_t * i = vam->input;
2696 vl_api_sw_interface_set_l2_xconnect_t *mp;
2699 u8 rx_sw_if_index_set = 0;
2701 u8 tx_sw_if_index_set = 0;
2704 /* Parse args required to build the message */
2705 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
2706 if (unformat (i, "rx_sw_if_index %d", &rx_sw_if_index))
2707 rx_sw_if_index_set = 1;
2708 else if (unformat (i, "tx_sw_if_index %d", &tx_sw_if_index))
2709 tx_sw_if_index_set = 1;
2710 else if (unformat (i, "rx")) {
2711 if (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
2712 if (unformat (i, "%U", unformat_sw_if_index, vam,
2714 rx_sw_if_index_set = 1;
2717 } else if (unformat (i, "tx")) {
2718 if (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
2719 if (unformat (i, "%U", unformat_sw_if_index, vam,
2721 tx_sw_if_index_set = 1;
2724 } else if (unformat (i, "enable"))
2726 else if (unformat (i, "disable"))
2732 if (rx_sw_if_index_set == 0) {
2733 errmsg ("missing rx interface name or rx_sw_if_index\n");
2737 if (enable && (tx_sw_if_index_set == 0)) {
2738 errmsg ("missing tx interface name or tx_sw_if_index\n");
2742 M(SW_INTERFACE_SET_L2_XCONNECT, sw_interface_set_l2_xconnect);
2744 mp->rx_sw_if_index = ntohl(rx_sw_if_index);
2745 mp->tx_sw_if_index = ntohl(tx_sw_if_index);
2746 mp->enable = enable;
2753 static int api_sw_interface_set_l2_bridge (vat_main_t * vam)
2755 unformat_input_t * i = vam->input;
2756 vl_api_sw_interface_set_l2_bridge_t *mp;
2759 u8 rx_sw_if_index_set = 0;
2766 /* Parse args required to build the message */
2767 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
2768 if (unformat (i, "sw_if_index %d", &rx_sw_if_index))
2769 rx_sw_if_index_set = 1;
2770 else if (unformat (i, "bd_id %d", &bd_id))
2772 else if (unformat (i, "%U", unformat_sw_if_index, vam,
2774 rx_sw_if_index_set = 1;
2775 else if (unformat (i, "shg %d", &shg))
2777 else if (unformat (i, "bvi"))
2779 else if (unformat (i, "enable"))
2781 else if (unformat (i, "disable"))
2787 if (rx_sw_if_index_set == 0) {
2788 errmsg ("missing rx interface name or sw_if_index\n");
2792 if (enable && (bd_id_set == 0)) {
2793 errmsg ("missing bridge domain\n");
2797 M(SW_INTERFACE_SET_L2_BRIDGE, sw_interface_set_l2_bridge);
2799 mp->rx_sw_if_index = ntohl(rx_sw_if_index);
2800 mp->bd_id = ntohl(bd_id);
2803 mp->enable = enable;
2810 static int api_bridge_domain_dump (vat_main_t * vam)
2812 unformat_input_t * i = vam->input;
2813 vl_api_bridge_domain_dump_t *mp;
2817 /* Parse args required to build the message */
2818 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
2819 if (unformat (i, "bd_id %d", &bd_id))
2825 M(BRIDGE_DOMAIN_DUMP, bridge_domain_dump);
2826 mp->bd_id = ntohl(bd_id);
2829 /* Use a control ping for synchronization */
2831 vl_api_control_ping_t * mp;
2832 M(CONTROL_PING, control_ping);
2841 static int api_bridge_domain_add_del (vat_main_t * vam)
2843 unformat_input_t * i = vam->input;
2844 vl_api_bridge_domain_add_del_t *mp;
2848 u32 flood = 1, forward = 1, learn = 1, uu_flood = 1, arp_term = 0;
2850 /* Parse args required to build the message */
2851 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
2852 if (unformat (i, "bd_id %d", &bd_id))
2854 else if (unformat (i, "flood %d", &flood))
2856 else if (unformat (i, "uu-flood %d", &uu_flood))
2858 else if (unformat (i, "forward %d", &forward))
2860 else if (unformat (i, "learn %d", &learn))
2862 else if (unformat (i, "arp-term %d", &arp_term))
2864 else if (unformat (i, "del")) {
2866 flood = uu_flood = forward = learn = 0;
2873 errmsg ("missing bridge domain\n");
2877 M(BRIDGE_DOMAIN_ADD_DEL, bridge_domain_add_del);
2879 mp->bd_id = ntohl(bd_id);
2881 mp->uu_flood = uu_flood;
2882 mp->forward = forward;
2884 mp->arp_term = arp_term;
2885 mp->is_add = is_add;
2892 static int api_l2fib_add_del (vat_main_t * vam)
2894 unformat_input_t * i = vam->input;
2895 vl_api_l2fib_add_del_t *mp;
2902 u8 sw_if_index_set = 0;
2907 /* Parse args required to build the message */
2908 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
2909 if (unformat (i, "mac %U", unformat_ethernet_address, &mac))
2911 else if (unformat (i, "bd_id %d", &bd_id))
2913 else if (unformat (i, "sw_if_index %d", &sw_if_index))
2914 sw_if_index_set = 1;
2915 else if (unformat (i, "sw_if")) {
2916 if (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
2917 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
2918 sw_if_index_set = 1;
2921 } else if (unformat (i, "static"))
2923 else if (unformat (i, "filter")) {
2926 } else if (unformat (i, "del"))
2933 errmsg ("missing mac address\n");
2937 if (bd_id_set == 0) {
2938 errmsg ("missing bridge domain\n");
2942 if (is_add && (sw_if_index_set == 0)) {
2943 errmsg ("missing interface name or sw_if_index\n");
2947 M(L2FIB_ADD_DEL, l2fib_add_del);
2950 mp->bd_id = ntohl(bd_id);
2951 mp->is_add = is_add;
2954 mp->sw_if_index = ntohl(sw_if_index);
2955 mp->static_mac = static_mac;
2956 mp->filter_mac = filter_mac;
2964 static int api_l2_flags (vat_main_t * vam)
2966 unformat_input_t * i = vam->input;
2967 vl_api_l2_flags_t *mp;
2970 u32 feature_bitmap = 0;
2971 u8 sw_if_index_set = 0;
2973 /* Parse args required to build the message */
2974 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
2975 if (unformat (i, "sw_if_index %d", &sw_if_index))
2976 sw_if_index_set = 1;
2977 else if (unformat (i, "sw_if")) {
2978 if (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
2979 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
2980 sw_if_index_set = 1;
2983 } else if (unformat (i, "learn"))
2984 feature_bitmap |= L2INPUT_FEAT_LEARN;
2985 else if (unformat (i, "forward"))
2986 feature_bitmap |= L2INPUT_FEAT_FWD;
2987 else if (unformat (i, "flood"))
2988 feature_bitmap |= L2INPUT_FEAT_FLOOD;
2989 else if (unformat (i, "uu-flood"))
2990 feature_bitmap |= L2INPUT_FEAT_UU_FLOOD;
2995 if (sw_if_index_set == 0) {
2996 errmsg ("missing interface name or sw_if_index\n");
3000 M(L2_FLAGS, l2_flags);
3002 mp->sw_if_index = ntohl(sw_if_index);
3003 mp->feature_bitmap = ntohl(feature_bitmap);
3010 static int api_bridge_flags (vat_main_t * vam)
3012 unformat_input_t * i = vam->input;
3013 vl_api_bridge_flags_t *mp;
3020 /* Parse args required to build the message */
3021 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
3022 if (unformat (i, "bd_id %d", &bd_id))
3024 else if (unformat (i, "learn"))
3026 else if (unformat (i, "forward"))
3028 else if (unformat (i, "flood"))
3030 else if (unformat (i, "uu-flood"))
3031 flags |= L2_UU_FLOOD;
3032 else if (unformat (i, "arp-term"))
3033 flags |= L2_ARP_TERM;
3034 else if (unformat (i, "off"))
3036 else if (unformat (i, "disable"))
3042 if (bd_id_set == 0) {
3043 errmsg ("missing bridge domain\n");
3047 M(BRIDGE_FLAGS, bridge_flags);
3049 mp->bd_id = ntohl(bd_id);
3050 mp->feature_bitmap = ntohl(flags);
3051 mp->is_set = is_set;
3058 static int api_bd_ip_mac_add_del (vat_main_t * vam)
3060 unformat_input_t * i = vam->input;
3061 vl_api_bd_ip_mac_add_del_t *mp;
3069 ip4_address_t v4addr;
3070 ip6_address_t v6addr;
3074 /* Parse args required to build the message */
3075 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
3076 if (unformat (i, "bd_id %d", &bd_id)) {
3078 } else if (unformat (i, "%U", unformat_ip4_address, &v4addr)) {
3080 } else if (unformat (i, "%U", unformat_ip6_address, &v6addr)) {
3083 } else if (unformat (i, "%U", unformat_ethernet_address, macaddr)) {
3085 } else if (unformat (i, "del"))
3091 if (bd_id_set == 0) {
3092 errmsg ("missing bridge domain\n");
3094 } else if (ip_set == 0) {
3095 errmsg ("missing IP address\n");
3097 } else if (mac_set == 0) {
3098 errmsg ("missing MAC address\n");
3102 M(BD_IP_MAC_ADD_DEL, bd_ip_mac_add_del);
3104 mp->bd_id = ntohl(bd_id);
3105 mp->is_ipv6 = is_ipv6;
3106 mp->is_add = is_add;
3108 memcpy (mp->ip_address, &v6addr, sizeof (v6addr));
3109 else memcpy (mp->ip_address, &v4addr, sizeof (v4addr));
3110 memcpy (mp->mac_address, macaddr, 6);
3116 static int api_tap_connect (vat_main_t * vam)
3118 unformat_input_t * i = vam->input;
3119 vl_api_tap_connect_t *mp;
3126 memset (mac_address, 0, sizeof (mac_address));
3128 /* Parse args required to build the message */
3129 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
3130 if (unformat (i, "mac %U", unformat_ethernet_address, mac_address)) {
3133 else if (unformat (i, "random-mac"))
3135 else if (unformat (i, "tapname %s", &tap_name))
3141 if (name_set == 0) {
3142 errmsg ("missing tap name\n");
3145 if (vec_len (tap_name) > 63) {
3146 errmsg ("tap name too long\n");
3148 vec_add1 (tap_name, 0);
3150 /* Construct the API message */
3151 M(TAP_CONNECT, tap_connect);
3153 mp->use_random_mac = random_mac;
3154 memcpy (mp->mac_address, mac_address, 6);
3155 memcpy (mp->tap_name, tap_name, vec_len (tap_name));
3156 vec_free (tap_name);
3161 /* Wait for a reply... */
3165 static int api_tap_modify (vat_main_t * vam)
3167 unformat_input_t * i = vam->input;
3168 vl_api_tap_modify_t *mp;
3174 u32 sw_if_index = ~0;
3175 u8 sw_if_index_set = 0;
3177 memset (mac_address, 0, sizeof (mac_address));
3179 /* Parse args required to build the message */
3180 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
3181 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
3182 sw_if_index_set = 1;
3183 else if (unformat (i, "sw_if_index %d", &sw_if_index))
3184 sw_if_index_set = 1;
3185 else if (unformat (i, "mac %U", unformat_ethernet_address, mac_address)) {
3188 else if (unformat (i, "random-mac"))
3190 else if (unformat (i, "tapname %s", &tap_name))
3196 if (sw_if_index_set == 0) {
3197 errmsg ("missing vpp interface name");
3200 if (name_set == 0) {
3201 errmsg ("missing tap name\n");
3204 if (vec_len (tap_name) > 63) {
3205 errmsg ("tap name too long\n");
3207 vec_add1 (tap_name, 0);
3209 /* Construct the API message */
3210 M(TAP_MODIFY, tap_modify);
3212 mp->use_random_mac = random_mac;
3213 mp->sw_if_index = ntohl(sw_if_index);
3214 memcpy (mp->mac_address, mac_address, 6);
3215 memcpy (mp->tap_name, tap_name, vec_len (tap_name));
3216 vec_free (tap_name);
3221 /* Wait for a reply... */
3225 static int api_tap_delete (vat_main_t * vam)
3227 unformat_input_t * i = vam->input;
3228 vl_api_tap_delete_t *mp;
3230 u32 sw_if_index = ~0;
3231 u8 sw_if_index_set = 0;
3233 /* Parse args required to build the message */
3234 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
3235 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
3236 sw_if_index_set = 1;
3237 else if (unformat (i, "sw_if_index %d", &sw_if_index))
3238 sw_if_index_set = 1;
3243 if (sw_if_index_set == 0) {
3244 errmsg ("missing vpp interface name");
3248 /* Construct the API message */
3249 M(TAP_DELETE, tap_delete);
3251 mp->sw_if_index = ntohl(sw_if_index);
3256 /* Wait for a reply... */
3260 static int api_ip_add_del_route (vat_main_t * vam)
3262 unformat_input_t * i = vam->input;
3263 vl_api_ip_add_del_route_t *mp;
3265 u32 sw_if_index = 0, vrf_id = 0;
3266 u8 sw_if_index_set = 0;
3268 u8 is_local = 0, is_drop = 0;
3269 u8 create_vrf_if_needed = 0;
3271 u8 next_hop_weight = 1;
3273 u8 is_multipath = 0;
3275 u8 address_length_set = 0;
3276 u32 lookup_in_vrf = 0;
3277 u32 resolve_attempts = 0;
3278 u32 dst_address_length = 0;
3279 u8 next_hop_set = 0;
3280 ip4_address_t v4_dst_address, v4_next_hop_address;
3281 ip6_address_t v6_dst_address, v6_next_hop_address;
3285 u32 random_add_del = 0;
3286 u32 * random_vector = 0;
3287 uword * random_hash;
3288 u32 random_seed = 0xdeaddabe;
3289 u32 classify_table_index = ~0;
3292 /* Parse args required to build the message */
3293 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
3294 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
3295 sw_if_index_set = 1;
3296 else if (unformat (i, "sw_if_index %d", &sw_if_index))
3297 sw_if_index_set = 1;
3298 else if (unformat (i, "%U", unformat_ip4_address,
3303 else if (unformat (i, "%U", unformat_ip6_address, &v6_dst_address)) {
3307 else if (unformat (i, "/%d", &dst_address_length)) {
3308 address_length_set = 1;
3311 else if (is_ipv6 == 0 && unformat (i, "via %U", unformat_ip4_address,
3312 &v4_next_hop_address)) {
3315 else if (is_ipv6 == 1 && unformat (i, "via %U", unformat_ip6_address,
3316 &v6_next_hop_address)) {
3319 else if (unformat (i, "resolve-attempts %d", &resolve_attempts))
3321 else if (unformat (i, "weight %d", &next_hop_weight))
3323 else if (unformat (i, "drop")) {
3325 } else if (unformat (i, "local")) {
3327 } else if (unformat (i, "classify %d", &classify_table_index)) {
3329 } else if (unformat (i, "del"))
3331 else if (unformat (i, "add"))
3333 else if (unformat (i, "not-last"))
3335 else if (unformat (i, "multipath"))
3337 else if (unformat (i, "vrf %d", &vrf_id))
3339 else if (unformat (i, "create-vrf"))
3340 create_vrf_if_needed = 1;
3341 else if (unformat (i, "count %d", &count))
3343 else if (unformat (i, "lookup-in-vrf %d", &lookup_in_vrf))
3345 else if (unformat (i, "random"))
3347 else if (unformat (i, "seed %d", &random_seed))
3350 clib_warning ("parse error '%U'", format_unformat_error, i);
3355 if (resolve_attempts > 0 && sw_if_index_set == 0) {
3356 errmsg ("ARP resolution needs explicit interface or sw_if_index\n");
3360 if (!next_hop_set && !is_drop && !is_local && !is_classify) {
3361 errmsg ("next hop / local / drop / classify not set\n");
3365 if (address_set == 0) {
3366 errmsg ("missing addresses\n");
3370 if (address_length_set == 0) {
3371 errmsg ("missing address length\n");
3375 /* Generate a pile of unique, random routes */
3376 if (random_add_del) {
3377 u32 this_random_address;
3378 random_hash = hash_create (count, sizeof(uword));
3380 hash_set (random_hash, v4_next_hop_address.as_u32, 1);
3381 for (j = 0; j <= count; j++) {
3383 this_random_address = random_u32 (&random_seed);
3384 this_random_address =
3385 clib_host_to_net_u32 (this_random_address);
3386 } while (hash_get (random_hash, this_random_address));
3387 vec_add1 (random_vector, this_random_address);
3388 hash_set (random_hash, this_random_address, 1);
3390 hash_free (random_hash);
3391 v4_dst_address.as_u32 = random_vector[0];
3395 /* Turn on async mode */
3396 vam->async_mode = 1;
3397 vam->async_errors = 0;
3398 before = vat_time_now(vam);
3401 for (j = 0; j < count; j++) {
3402 /* Construct the API message */
3403 M(IP_ADD_DEL_ROUTE, ip_add_del_route);
3405 mp->next_hop_sw_if_index = ntohl (sw_if_index);
3406 mp->vrf_id = ntohl (vrf_id);
3407 if (resolve_attempts > 0) {
3408 mp->resolve_attempts = ntohl (resolve_attempts);
3409 mp->resolve_if_needed = 1;
3411 mp->create_vrf_if_needed = create_vrf_if_needed;
3413 mp->is_add = is_add;
3414 mp->is_drop = is_drop;
3415 mp->is_ipv6 = is_ipv6;
3416 mp->is_local = is_local;
3417 mp->is_classify = is_classify;
3418 mp->is_multipath = is_multipath;
3419 mp->not_last = not_last;
3420 mp->next_hop_weight = next_hop_weight;
3421 mp->dst_address_length = dst_address_length;
3422 mp->lookup_in_vrf = ntohl(lookup_in_vrf);
3423 mp->classify_table_index = ntohl(classify_table_index);
3426 memcpy (mp->dst_address, &v6_dst_address, sizeof (v6_dst_address));
3428 memcpy (mp->next_hop_address, &v6_next_hop_address,
3429 sizeof (v6_next_hop_address));
3430 increment_v6_address (&v6_dst_address);
3432 memcpy (mp->dst_address, &v4_dst_address, sizeof (v4_dst_address));
3434 memcpy (mp->next_hop_address, &v4_next_hop_address,
3435 sizeof (v4_next_hop_address));
3437 v4_dst_address.as_u32 = random_vector[j+1];
3439 increment_v4_address (&v4_dst_address);
3445 /* When testing multiple add/del ops, use a control-ping to sync */
3447 vl_api_control_ping_t * mp;
3450 /* Shut off async mode */
3451 vam->async_mode = 0;
3453 M(CONTROL_PING, control_ping);
3456 timeout = vat_time_now(vam) + 1.0;
3457 while (vat_time_now (vam) < timeout)
3458 if (vam->result_ready == 1)
3463 if (vam->retval == -99)
3464 errmsg ("timeout\n");
3466 if (vam->async_errors > 0) {
3467 errmsg ("%d asynchronous errors\n", vam->async_errors);
3470 vam->async_errors = 0;
3471 after = vat_time_now(vam);
3473 fformat(vam->ofp, "%d routes in %.6f secs, %.2f routes/sec\n",
3474 count, after - before, count / (after - before));
3476 /* Wait for a reply... */
3480 /* Return the good/bad news */
3481 return (vam->retval);
3484 static int api_proxy_arp_add_del (vat_main_t * vam)
3486 unformat_input_t * i = vam->input;
3487 vl_api_proxy_arp_add_del_t *mp;
3491 ip4_address_t lo, hi;
3494 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
3495 if (unformat (i, "vrf %d", &vrf_id))
3497 else if (unformat (i, "%U - %U", unformat_ip4_address, &lo,
3498 unformat_ip4_address, &hi))
3500 else if (unformat (i, "del"))
3503 clib_warning ("parse error '%U'", format_unformat_error, i);
3508 if (range_set == 0) {
3509 errmsg ("address range not set\n");
3513 M(PROXY_ARP_ADD_DEL, proxy_arp_add_del);
3515 mp->vrf_id = ntohl(vrf_id);
3516 mp->is_add = is_add;
3517 memcpy(mp->low_address, &lo, sizeof (mp->low_address));
3518 memcpy(mp->hi_address, &hi, sizeof (mp->hi_address));
3525 static int api_proxy_arp_intfc_enable_disable (vat_main_t * vam)
3527 unformat_input_t * i = vam->input;
3528 vl_api_proxy_arp_intfc_enable_disable_t *mp;
3532 u8 sw_if_index_set = 0;
3534 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
3535 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
3536 sw_if_index_set = 1;
3537 else if (unformat (i, "sw_if_index %d", &sw_if_index))
3538 sw_if_index_set = 1;
3539 else if (unformat (i, "enable"))
3541 else if (unformat (i, "disable"))
3544 clib_warning ("parse error '%U'", format_unformat_error, i);
3549 if (sw_if_index_set == 0) {
3550 errmsg ("missing interface name or sw_if_index\n");
3554 M(PROXY_ARP_INTFC_ENABLE_DISABLE, proxy_arp_intfc_enable_disable);
3556 mp->sw_if_index = ntohl(sw_if_index);
3557 mp->enable_disable = enable;
3564 static int api_mpls_add_del_decap (vat_main_t * vam)
3566 unformat_input_t * i = vam->input;
3567 vl_api_mpls_add_del_decap_t *mp;
3576 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
3577 if (unformat (i, "rx_vrf_id %d", &rx_vrf_id))
3579 else if (unformat (i, "tx_vrf_id %d", &tx_vrf_id))
3581 else if (unformat (i, "label %d", &label))
3583 else if (unformat (i, "next-index %d", &next_index))
3585 else if (unformat (i, "del"))
3587 else if (unformat (i, "s-bit-clear"))
3590 clib_warning ("parse error '%U'", format_unformat_error, i);
3595 M(MPLS_ADD_DEL_DECAP, mpls_add_del_decap);
3597 mp->rx_vrf_id = ntohl(rx_vrf_id);
3598 mp->tx_vrf_id = ntohl(tx_vrf_id);
3599 mp->label = ntohl(label);
3600 mp->next_index = ntohl(next_index);
3602 mp->is_add = is_add;
3609 static int api_mpls_add_del_encap (vat_main_t * vam)
3611 unformat_input_t * i = vam->input;
3612 vl_api_mpls_add_del_encap_t *mp;
3617 ip4_address_t dst_address;
3620 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
3621 if (unformat (i, "vrf %d", &vrf_id))
3623 else if (unformat (i, "label %d", &label))
3624 vec_add1 (labels, ntohl(label));
3625 else if (unformat (i, "dst %U", unformat_ip4_address, &dst_address))
3627 else if (unformat (i, "del"))
3630 clib_warning ("parse error '%U'", format_unformat_error, i);
3635 if (vec_len (labels) == 0) {
3636 errmsg ("missing encap label stack\n");
3640 M2(MPLS_ADD_DEL_ENCAP, mpls_add_del_encap,
3641 sizeof (u32) * vec_len (labels));
3643 mp->vrf_id = ntohl(vrf_id);
3644 memcpy(mp->dst_address, &dst_address, sizeof (dst_address));
3645 mp->is_add = is_add;
3646 mp->nlabels = vec_len (labels);
3647 memcpy(mp->labels, labels, sizeof(u32)*mp->nlabels);
3656 static int api_mpls_gre_add_del_tunnel (vat_main_t * vam)
3658 unformat_input_t * i = vam->input;
3659 vl_api_mpls_gre_add_del_tunnel_t *mp;
3661 u32 inner_vrf_id = 0;
3662 u32 outer_vrf_id = 0;
3663 ip4_address_t src_address;
3664 ip4_address_t dst_address;
3665 ip4_address_t intfc_address;
3667 u8 intfc_address_length = 0;
3671 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
3672 if (unformat (i, "inner_vrf_id %d", &inner_vrf_id))
3674 else if (unformat (i, "outer_vrf_id %d", &outer_vrf_id))
3676 else if (unformat (i, "src %U", unformat_ip4_address, &src_address))
3678 else if (unformat (i, "dst %U", unformat_ip4_address, &dst_address))
3680 else if (unformat (i, "adj %U/%d", unformat_ip4_address,
3681 &intfc_address, &tmp))
3682 intfc_address_length = tmp;
3683 else if (unformat (i, "l2-only"))
3685 else if (unformat (i, "del"))
3688 clib_warning ("parse error '%U'", format_unformat_error, i);
3693 M(MPLS_GRE_ADD_DEL_TUNNEL, mpls_gre_add_del_tunnel);
3695 mp->inner_vrf_id = ntohl(inner_vrf_id);
3696 mp->outer_vrf_id = ntohl(outer_vrf_id);
3697 memcpy(mp->src_address, &src_address, sizeof (src_address));
3698 memcpy(mp->dst_address, &dst_address, sizeof (dst_address));
3699 memcpy(mp->intfc_address, &intfc_address, sizeof (intfc_address));
3700 mp->intfc_address_length = intfc_address_length;
3701 mp->l2_only = l2_only;
3702 mp->is_add = is_add;
3709 static int api_mpls_ethernet_add_del_tunnel (vat_main_t * vam)
3711 unformat_input_t * i = vam->input;
3712 vl_api_mpls_ethernet_add_del_tunnel_t *mp;
3714 u32 inner_vrf_id = 0;
3715 ip4_address_t intfc_address;
3716 u8 dst_mac_address[6];
3719 u8 intfc_address_length = 0;
3723 int tx_sw_if_index_set = 0;
3725 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
3726 if (unformat (i, "vrf %d", &inner_vrf_id))
3728 else if (unformat (i, "adj %U/%d", unformat_ip4_address,
3729 &intfc_address, &tmp))
3730 intfc_address_length = tmp;
3731 else if (unformat (i, "%U",
3732 unformat_sw_if_index, vam, &tx_sw_if_index))
3733 tx_sw_if_index_set = 1;
3734 else if (unformat (i, "tx_sw_if_index %d", &tx_sw_if_index))
3735 tx_sw_if_index_set = 1;
3736 else if (unformat (i, "dst %U", unformat_ethernet_address,
3739 else if (unformat (i, "l2-only"))
3741 else if (unformat (i, "del"))
3744 clib_warning ("parse error '%U'", format_unformat_error, i);
3750 errmsg ("dst (mac address) not set\n");
3753 if (!tx_sw_if_index_set) {
3754 errmsg ("tx-intfc not set\n");
3758 M(MPLS_ETHERNET_ADD_DEL_TUNNEL, mpls_ethernet_add_del_tunnel);
3760 mp->vrf_id = ntohl(inner_vrf_id);
3761 memcpy (mp->adj_address, &intfc_address, sizeof (intfc_address));
3762 mp->adj_address_length = intfc_address_length;
3763 memcpy (mp->dst_mac_address, dst_mac_address, sizeof (dst_mac_address));
3764 mp->tx_sw_if_index = ntohl(tx_sw_if_index);
3765 mp->l2_only = l2_only;
3766 mp->is_add = is_add;
3773 static int api_mpls_ethernet_add_del_tunnel_2 (vat_main_t * vam)
3775 unformat_input_t * i = vam->input;
3776 vl_api_mpls_ethernet_add_del_tunnel_2_t *mp;
3778 u32 inner_vrf_id = 0;
3779 u32 outer_vrf_id = 0;
3780 ip4_address_t adj_address;
3781 int adj_address_set = 0;
3782 ip4_address_t next_hop_address;
3783 int next_hop_address_set = 0;
3785 u8 adj_address_length = 0;
3788 u32 resolve_attempts = 5;
3789 u8 resolve_if_needed = 1;
3791 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
3792 if (unformat (i, "inner_vrf_id %d", &inner_vrf_id))
3794 else if (unformat (i, "outer_vrf_id %d", &outer_vrf_id))
3796 else if (unformat (i, "adj %U/%d", unformat_ip4_address,
3797 &adj_address, &tmp)) {
3798 adj_address_length = tmp;
3799 adj_address_set = 1;
3801 else if (unformat (i, "next-hop %U", unformat_ip4_address,
3803 next_hop_address_set = 1;
3804 else if (unformat (i, "resolve-attempts %d", &resolve_attempts))
3806 else if (unformat (i, "resolve-if-needed %d", &tmp))
3807 resolve_if_needed = tmp;
3808 else if (unformat (i, "l2-only"))
3810 else if (unformat (i, "del"))
3813 clib_warning ("parse error '%U'", format_unformat_error, i);
3818 if (!adj_address_set) {
3819 errmsg ("adjacency address/mask not set\n");
3822 if (!next_hop_address_set) {
3823 errmsg ("ip4 next hop address (in outer fib) not set\n");
3827 M(MPLS_ETHERNET_ADD_DEL_TUNNEL_2, mpls_ethernet_add_del_tunnel_2);
3829 mp->inner_vrf_id = ntohl(inner_vrf_id);
3830 mp->outer_vrf_id = ntohl(outer_vrf_id);
3831 mp->resolve_attempts = ntohl(resolve_attempts);
3832 mp->resolve_if_needed = resolve_if_needed;
3833 mp->is_add = is_add;
3834 mp->l2_only = l2_only;
3835 memcpy (mp->adj_address, &adj_address, sizeof (adj_address));
3836 mp->adj_address_length = adj_address_length;
3837 memcpy (mp->next_hop_ip4_address_in_outer_vrf, &next_hop_address,
3838 sizeof (next_hop_address));
3845 static int api_sw_interface_set_unnumbered (vat_main_t * vam)
3847 unformat_input_t * i = vam->input;
3848 vl_api_sw_interface_set_unnumbered_t *mp;
3853 u8 sw_if_index_set = 0;
3855 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
3856 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
3857 sw_if_index_set = 1;
3858 else if (unformat (i, "sw_if_index %d", &sw_if_index))
3859 sw_if_index_set = 1;
3860 else if (unformat (i, "unnum_if_index %d", &unnum_sw_index))
3862 else if (unformat (i, "del"))
3865 clib_warning ("parse error '%U'", format_unformat_error, i);
3870 if (sw_if_index_set == 0) {
3871 errmsg ("missing interface name or sw_if_index\n");
3875 M(SW_INTERFACE_SET_UNNUMBERED, sw_interface_set_unnumbered);
3877 mp->sw_if_index = ntohl(sw_if_index);
3878 mp->unnumbered_sw_if_index = ntohl(unnum_sw_index);
3879 mp->is_add = is_add;
3886 static int api_ip_neighbor_add_del (vat_main_t * vam)
3888 unformat_input_t * i = vam->input;
3889 vl_api_ip_neighbor_add_del_t *mp;
3892 u8 sw_if_index_set = 0;
3898 u8 v4_address_set = 0;
3899 u8 v6_address_set = 0;
3900 ip4_address_t v4address;
3901 ip6_address_t v6address;
3903 memset (mac_address, 0, sizeof (mac_address));
3905 /* Parse args required to build the message */
3906 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
3907 if (unformat (i, "mac %U", unformat_ethernet_address, mac_address)) {
3910 else if (unformat (i, "del"))
3912 else if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
3913 sw_if_index_set = 1;
3914 else if (unformat (i, "sw_if_index %d", &sw_if_index))
3915 sw_if_index_set = 1;
3916 else if (unformat (i, "is_static"))
3918 else if (unformat (i, "vrf %d", &vrf_id))
3920 else if (unformat (i, "dst %U",
3921 unformat_ip4_address, &v4address))
3923 else if (unformat (i, "dst %U",
3924 unformat_ip6_address, &v6address))
3927 clib_warning ("parse error '%U'", format_unformat_error, i);
3932 if (sw_if_index_set == 0) {
3933 errmsg ("missing interface name or sw_if_index\n");
3936 if (v4_address_set && v6_address_set) {
3937 errmsg ("both v4 and v6 addresses set\n");
3940 if (!v4_address_set && !v6_address_set) {
3941 errmsg ("no addresses set\n");
3945 /* Construct the API message */
3946 M(IP_NEIGHBOR_ADD_DEL, ip_neighbor_add_del);
3948 mp->sw_if_index = ntohl (sw_if_index);
3949 mp->is_add = is_add;
3950 mp->vrf_id = ntohl (vrf_id);
3951 mp->is_static = is_static;
3953 memcpy (mp->mac_address, mac_address, 6);
3954 if (v6_address_set) {
3956 memcpy (mp->dst_address, &v6address, sizeof (v6address));
3958 /* mp->is_ipv6 = 0; via memset in M macro above */
3959 memcpy (mp->dst_address, &v4address, sizeof (v4address));
3965 /* Wait for a reply, return good/bad news */
3972 static int api_reset_vrf (vat_main_t * vam)
3974 unformat_input_t * i = vam->input;
3975 vl_api_reset_vrf_t *mp;
3981 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
3982 if (unformat (i, "vrf %d", &vrf_id))
3984 else if (unformat (i, "ipv6"))
3987 clib_warning ("parse error '%U'", format_unformat_error, i);
3992 if (vrf_id_set == 0) {
3993 errmsg ("missing vrf id\n");
3997 M(RESET_VRF, reset_vrf);
3999 mp->vrf_id = ntohl(vrf_id);
4000 mp->is_ipv6 = is_ipv6;
4007 static int api_create_vlan_subif (vat_main_t * vam)
4009 unformat_input_t * i = vam->input;
4010 vl_api_create_vlan_subif_t *mp;
4013 u8 sw_if_index_set = 0;
4017 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
4018 if (unformat (i, "sw_if_index %d", &sw_if_index))
4019 sw_if_index_set = 1;
4020 else if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
4021 sw_if_index_set = 1;
4022 else if (unformat (i, "vlan %d", &vlan_id))
4025 clib_warning ("parse error '%U'", format_unformat_error, i);
4030 if (sw_if_index_set == 0) {
4031 errmsg ("missing interface name or sw_if_index\n");
4035 if (vlan_id_set == 0) {
4036 errmsg ("missing vlan_id\n");
4039 M(CREATE_VLAN_SUBIF, create_vlan_subif);
4041 mp->sw_if_index = ntohl(sw_if_index);
4042 mp->vlan_id = ntohl(vlan_id);
4049 #define foreach_create_subif_bit \
4056 _(outer_vlan_id_any) \
4057 _(inner_vlan_id_any)
4059 static int api_create_subif (vat_main_t * vam)
4061 unformat_input_t * i = vam->input;
4062 vl_api_create_subif_t *mp;
4065 u8 sw_if_index_set = 0;
4072 u32 exact_match = 0;
4073 u32 default_sub = 0;
4074 u32 outer_vlan_id_any = 0;
4075 u32 inner_vlan_id_any = 0;
4077 u16 outer_vlan_id = 0;
4078 u16 inner_vlan_id = 0;
4080 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
4081 if (unformat (i, "sw_if_index %d", &sw_if_index))
4082 sw_if_index_set = 1;
4083 else if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
4084 sw_if_index_set = 1;
4085 else if (unformat (i, "sub_id %d", &sub_id))
4087 else if (unformat (i, "outer_vlan_id %d", &tmp))
4088 outer_vlan_id = tmp;
4089 else if (unformat (i, "inner_vlan_id %d", &tmp))
4090 inner_vlan_id = tmp;
4092 #define _(a) else if (unformat (i, #a)) a = 1 ;
4093 foreach_create_subif_bit
4097 clib_warning ("parse error '%U'", format_unformat_error, i);
4102 if (sw_if_index_set == 0) {
4103 errmsg ("missing interface name or sw_if_index\n");
4107 if (sub_id_set == 0) {
4108 errmsg ("missing sub_id\n");
4111 M(CREATE_SUBIF, create_subif);
4113 mp->sw_if_index = ntohl(sw_if_index);
4114 mp->sub_id = ntohl(sub_id);
4116 #define _(a) mp->a = a;
4117 foreach_create_subif_bit;
4120 mp->outer_vlan_id = ntohs (outer_vlan_id);
4121 mp->inner_vlan_id = ntohs (inner_vlan_id);
4128 static int api_oam_add_del (vat_main_t * vam)
4130 unformat_input_t * i = vam->input;
4131 vl_api_oam_add_del_t *mp;
4135 ip4_address_t src, dst;
4139 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
4140 if (unformat (i, "vrf %d", &vrf_id))
4142 else if (unformat (i, "src %U", unformat_ip4_address, &src))
4144 else if (unformat (i, "dst %U", unformat_ip4_address, &dst))
4146 else if (unformat (i, "del"))
4149 clib_warning ("parse error '%U'", format_unformat_error, i);
4155 errmsg ("missing src addr\n");
4160 errmsg ("missing dst addr\n");
4164 M(OAM_ADD_DEL, oam_add_del);
4166 mp->vrf_id = ntohl(vrf_id);
4167 mp->is_add = is_add;
4168 memcpy(mp->src_address, &src, sizeof (mp->src_address));
4169 memcpy(mp->dst_address, &dst, sizeof (mp->dst_address));
4176 static int api_reset_fib (vat_main_t * vam)
4178 unformat_input_t * i = vam->input;
4179 vl_api_reset_fib_t *mp;
4185 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
4186 if (unformat (i, "vrf %d", &vrf_id))
4188 else if (unformat (i, "ipv6"))
4191 clib_warning ("parse error '%U'", format_unformat_error, i);
4196 if (vrf_id_set == 0) {
4197 errmsg ("missing vrf id\n");
4201 M(RESET_FIB, reset_fib);
4203 mp->vrf_id = ntohl(vrf_id);
4204 mp->is_ipv6 = is_ipv6;
4211 static int api_dhcp_proxy_config (vat_main_t * vam)
4213 unformat_input_t * i = vam->input;
4214 vl_api_dhcp_proxy_config_t *mp;
4219 u8 v4_address_set = 0;
4220 u8 v6_address_set = 0;
4221 ip4_address_t v4address;
4222 ip6_address_t v6address;
4223 u8 v4_src_address_set = 0;
4224 u8 v6_src_address_set = 0;
4225 ip4_address_t v4srcaddress;
4226 ip6_address_t v6srcaddress;
4228 /* Parse args required to build the message */
4229 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
4230 if (unformat (i, "del"))
4232 else if (unformat (i, "vrf %d", &vrf_id))
4234 else if (unformat (i, "insert-cid %d", &insert_cid))
4236 else if (unformat (i, "svr %U",
4237 unformat_ip4_address, &v4address))
4239 else if (unformat (i, "svr %U",
4240 unformat_ip6_address, &v6address))
4242 else if (unformat (i, "src %U",
4243 unformat_ip4_address, &v4srcaddress))
4244 v4_src_address_set = 1;
4245 else if (unformat (i, "src %U",
4246 unformat_ip6_address, &v6srcaddress))
4247 v6_src_address_set = 1;
4252 if (v4_address_set && v6_address_set) {
4253 errmsg ("both v4 and v6 server addresses set\n");
4256 if (!v4_address_set && !v6_address_set) {
4257 errmsg ("no server addresses set\n");
4261 if (v4_src_address_set && v6_src_address_set) {
4262 errmsg ("both v4 and v6 src addresses set\n");
4265 if (!v4_src_address_set && !v6_src_address_set) {
4266 errmsg ("no src addresses set\n");
4270 if (!(v4_src_address_set && v4_address_set) &&
4271 !(v6_src_address_set && v6_address_set)) {
4272 errmsg ("no matching server and src addresses set\n");
4276 /* Construct the API message */
4277 M(DHCP_PROXY_CONFIG, dhcp_proxy_config);
4279 mp->insert_circuit_id = insert_cid;
4280 mp->is_add = is_add;
4281 mp->vrf_id = ntohl (vrf_id);
4282 if (v6_address_set) {
4284 memcpy (mp->dhcp_server, &v6address, sizeof (v6address));
4285 memcpy (mp->dhcp_src_address, &v6srcaddress, sizeof (v6address));
4287 memcpy (mp->dhcp_server, &v4address, sizeof (v4address));
4288 memcpy (mp->dhcp_src_address, &v4srcaddress, sizeof (v4address));
4294 /* Wait for a reply, return good/bad news */
4300 static int api_dhcp_proxy_config_2 (vat_main_t * vam)
4302 unformat_input_t * i = vam->input;
4303 vl_api_dhcp_proxy_config_2_t *mp;
4306 u32 server_vrf_id = 0;
4309 u8 v4_address_set = 0;
4310 u8 v6_address_set = 0;
4311 ip4_address_t v4address;
4312 ip6_address_t v6address;
4313 u8 v4_src_address_set = 0;
4314 u8 v6_src_address_set = 0;
4315 ip4_address_t v4srcaddress;
4316 ip6_address_t v6srcaddress;
4318 /* Parse args required to build the message */
4319 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
4320 if (unformat (i, "del"))
4322 else if (unformat (i, "rx_vrf_id %d", &rx_vrf_id))
4324 else if (unformat (i, "server_vrf_id %d", &server_vrf_id))
4326 else if (unformat (i, "insert-cid %d", &insert_cid))
4328 else if (unformat (i, "svr %U",
4329 unformat_ip4_address, &v4address))
4331 else if (unformat (i, "svr %U",
4332 unformat_ip6_address, &v6address))
4334 else if (unformat (i, "src %U",
4335 unformat_ip4_address, &v4srcaddress))
4336 v4_src_address_set = 1;
4337 else if (unformat (i, "src %U",
4338 unformat_ip6_address, &v6srcaddress))
4339 v6_src_address_set = 1;
4344 if (v4_address_set && v6_address_set) {
4345 errmsg ("both v4 and v6 server addresses set\n");
4348 if (!v4_address_set && !v6_address_set) {
4349 errmsg ("no server addresses set\n");
4353 if (v4_src_address_set && v6_src_address_set) {
4354 errmsg ("both v4 and v6 src addresses set\n");
4357 if (!v4_src_address_set && !v6_src_address_set) {
4358 errmsg ("no src addresses set\n");
4362 if (!(v4_src_address_set && v4_address_set) &&
4363 !(v6_src_address_set && v6_address_set)) {
4364 errmsg ("no matching server and src addresses set\n");
4368 /* Construct the API message */
4369 M(DHCP_PROXY_CONFIG_2, dhcp_proxy_config_2);
4371 mp->insert_circuit_id = insert_cid;
4372 mp->is_add = is_add;
4373 mp->rx_vrf_id = ntohl (rx_vrf_id);
4374 mp->server_vrf_id = ntohl (server_vrf_id);
4375 if (v6_address_set) {
4377 memcpy (mp->dhcp_server, &v6address, sizeof (v6address));
4378 memcpy (mp->dhcp_src_address, &v6srcaddress, sizeof (v6address));
4380 memcpy (mp->dhcp_server, &v4address, sizeof (v4address));
4381 memcpy (mp->dhcp_src_address, &v4srcaddress, sizeof (v4address));
4387 /* Wait for a reply, return good/bad news */
4393 static int api_dhcp_proxy_set_vss (vat_main_t * vam)
4395 unformat_input_t * i = vam->input;
4396 vl_api_dhcp_proxy_set_vss_t *mp;
4407 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
4408 if (unformat (i, "tbl_id %d", &tbl_id))
4410 if (unformat (i, "fib_id %d", &fib_id))
4412 if (unformat (i, "oui %d", &oui))
4414 else if (unformat (i, "ipv6"))
4416 else if (unformat (i, "del"))
4419 clib_warning ("parse error '%U'", format_unformat_error, i);
4424 if (tbl_id_set == 0) {
4425 errmsg ("missing tbl id\n");
4429 if (fib_id_set == 0) {
4430 errmsg ("missing fib id\n");
4434 errmsg ("missing oui\n");
4438 M(DHCP_PROXY_SET_VSS, dhcp_proxy_set_vss);
4439 mp->tbl_id = ntohl(tbl_id);
4440 mp->fib_id = ntohl(fib_id);
4441 mp->oui = ntohl(oui);
4442 mp->is_ipv6 = is_ipv6;
4443 mp->is_add = is_add;
4450 static int api_dhcp_client_config (vat_main_t * vam)
4452 unformat_input_t * i = vam->input;
4453 vl_api_dhcp_client_config_t *mp;
4456 u8 sw_if_index_set = 0;
4459 u8 disable_event = 0;
4461 /* Parse args required to build the message */
4462 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
4463 if (unformat (i, "del"))
4465 else if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
4466 sw_if_index_set = 1;
4467 else if (unformat (i, "sw_if_index %d", &sw_if_index))
4468 sw_if_index_set = 1;
4469 else if (unformat (i, "hostname %s", &hostname))
4471 else if (unformat (i, "disable_event"))
4477 if (sw_if_index_set == 0) {
4478 errmsg ("missing interface name or sw_if_index\n");
4482 if (vec_len (hostname) > 63) {
4483 errmsg ("hostname too long\n");
4485 vec_add1 (hostname, 0);
4487 /* Construct the API message */
4488 M(DHCP_CLIENT_CONFIG, dhcp_client_config);
4490 mp->sw_if_index = ntohl (sw_if_index);
4491 memcpy (mp->hostname, hostname, vec_len (hostname));
4492 vec_free (hostname);
4493 mp->is_add = is_add;
4494 mp->want_dhcp_event = disable_event ? 0 : 1;
4500 /* Wait for a reply, return good/bad news */
4506 static int api_set_ip_flow_hash (vat_main_t * vam)
4508 unformat_input_t * i = vam->input;
4509 vl_api_set_ip_flow_hash_t *mp;
4521 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
4522 if (unformat (i, "vrf %d", &vrf_id))
4524 else if (unformat (i, "ipv6"))
4526 else if (unformat (i, "src"))
4528 else if (unformat (i, "dst"))
4530 else if (unformat (i, "sport"))
4532 else if (unformat (i, "dport"))
4534 else if (unformat (i, "proto"))
4536 else if (unformat (i, "reverse"))
4540 clib_warning ("parse error '%U'", format_unformat_error, i);
4545 if (vrf_id_set == 0) {
4546 errmsg ("missing vrf id\n");
4550 M(SET_IP_FLOW_HASH, set_ip_flow_hash);
4556 mp->reverse = reverse;
4557 mp->vrf_id = ntohl(vrf_id);
4558 mp->is_ipv6 = is_ipv6;
4565 static int api_sw_interface_ip6_enable_disable (vat_main_t * vam)
4567 unformat_input_t * i = vam->input;
4568 vl_api_sw_interface_ip6_enable_disable_t *mp;
4571 u8 sw_if_index_set = 0;
4574 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
4575 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
4576 sw_if_index_set = 1;
4577 else if (unformat (i, "sw_if_index %d", &sw_if_index))
4578 sw_if_index_set = 1;
4579 else if (unformat (i, "enable"))
4581 else if (unformat (i, "disable"))
4584 clib_warning ("parse error '%U'", format_unformat_error, i);
4589 if (sw_if_index_set == 0) {
4590 errmsg ("missing interface name or sw_if_index\n");
4594 M(SW_INTERFACE_IP6_ENABLE_DISABLE, sw_interface_ip6_enable_disable);
4596 mp->sw_if_index = ntohl(sw_if_index);
4597 mp->enable = enable;
4604 static int api_sw_interface_ip6_set_link_local_address (vat_main_t * vam)
4606 unformat_input_t * i = vam->input;
4607 vl_api_sw_interface_ip6_set_link_local_address_t *mp;
4610 u8 sw_if_index_set = 0;
4611 u32 address_length = 0;
4612 u8 v6_address_set = 0;
4613 ip6_address_t v6address;
4615 /* Parse args required to build the message */
4616 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
4617 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
4618 sw_if_index_set = 1;
4619 else if (unformat (i, "sw_if_index %d", &sw_if_index))
4620 sw_if_index_set = 1;
4621 else if (unformat (i, "%U/%d",
4622 unformat_ip6_address, &v6address,
4629 if (sw_if_index_set == 0) {
4630 errmsg ("missing interface name or sw_if_index\n");
4633 if (!v6_address_set) {
4634 errmsg ("no address set\n");
4638 /* Construct the API message */
4639 M(SW_INTERFACE_IP6_SET_LINK_LOCAL_ADDRESS, \
4640 sw_interface_ip6_set_link_local_address);
4642 mp->sw_if_index = ntohl (sw_if_index);
4643 memcpy (mp->address, &v6address, sizeof (v6address));
4644 mp->address_length = address_length;
4649 /* Wait for a reply, return good/bad news */
4657 static int api_sw_interface_ip6nd_ra_prefix (vat_main_t * vam)
4659 unformat_input_t * i = vam->input;
4660 vl_api_sw_interface_ip6nd_ra_prefix_t *mp;
4663 u8 sw_if_index_set = 0;
4664 u32 address_length = 0;
4665 u8 v6_address_set = 0;
4666 ip6_address_t v6address;
4668 u8 no_advertise = 0;
4670 u8 no_autoconfig = 0;
4673 u32 val_lifetime = 0;
4674 u32 pref_lifetime = 0;
4676 /* Parse args required to build the message */
4677 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
4678 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
4679 sw_if_index_set = 1;
4680 else if (unformat (i, "sw_if_index %d", &sw_if_index))
4681 sw_if_index_set = 1;
4682 else if (unformat (i, "%U/%d",
4683 unformat_ip6_address, &v6address,
4686 else if (unformat (i, "val_life %d", &val_lifetime))
4688 else if (unformat (i, "pref_life %d", &pref_lifetime))
4690 else if (unformat (i, "def"))
4692 else if (unformat (i, "noadv"))
4694 else if (unformat (i, "offl"))
4696 else if (unformat (i, "noauto"))
4698 else if (unformat (i, "nolink"))
4700 else if (unformat (i, "isno"))
4703 clib_warning ("parse error '%U'", format_unformat_error, i);
4708 if (sw_if_index_set == 0) {
4709 errmsg ("missing interface name or sw_if_index\n");
4712 if (!v6_address_set) {
4713 errmsg ("no address set\n");
4717 /* Construct the API message */
4718 M(SW_INTERFACE_IP6ND_RA_PREFIX, sw_interface_ip6nd_ra_prefix);
4720 mp->sw_if_index = ntohl (sw_if_index);
4721 memcpy (mp->address, &v6address, sizeof (v6address));
4722 mp->address_length = address_length;
4723 mp->use_default = use_default;
4724 mp->no_advertise = no_advertise;
4725 mp->off_link = off_link;
4726 mp->no_autoconfig = no_autoconfig;
4727 mp->no_onlink = no_onlink;
4729 mp->val_lifetime = ntohl(val_lifetime);
4730 mp->pref_lifetime = ntohl(pref_lifetime);
4735 /* Wait for a reply, return good/bad news */
4742 static int api_sw_interface_ip6nd_ra_config (vat_main_t * vam)
4744 unformat_input_t * i = vam->input;
4745 vl_api_sw_interface_ip6nd_ra_config_t *mp;
4748 u8 sw_if_index_set = 0;
4753 u8 send_unicast = 0;
4756 u8 default_router = 0;
4757 u32 max_interval = 0;
4758 u32 min_interval = 0;
4760 u32 initial_count = 0;
4761 u32 initial_interval = 0;
4764 /* Parse args required to build the message */
4765 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
4766 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
4767 sw_if_index_set = 1;
4768 else if (unformat (i, "sw_if_index %d", &sw_if_index))
4769 sw_if_index_set = 1;
4770 else if (unformat (i, "maxint %d", &max_interval))
4772 else if (unformat (i, "minint %d", &min_interval))
4774 else if (unformat (i, "life %d", &lifetime))
4776 else if (unformat (i, "count %d", &initial_count))
4778 else if (unformat (i, "interval %d", &initial_interval))
4780 else if (unformat (i, "surpress"))
4782 else if (unformat (i, "managed"))
4784 else if (unformat (i, "other"))
4786 else if (unformat (i, "ll"))
4788 else if (unformat (i, "send"))
4790 else if (unformat (i, "cease"))
4792 else if (unformat (i, "isno"))
4794 else if (unformat (i, "def"))
4797 clib_warning ("parse error '%U'", format_unformat_error, i);
4802 if (sw_if_index_set == 0) {
4803 errmsg ("missing interface name or sw_if_index\n");
4807 /* Construct the API message */
4808 M(SW_INTERFACE_IP6ND_RA_CONFIG, sw_interface_ip6nd_ra_config);
4810 mp->sw_if_index = ntohl (sw_if_index);
4811 mp->max_interval = ntohl(max_interval);
4812 mp->min_interval = ntohl(min_interval);
4813 mp->lifetime = ntohl(lifetime);
4814 mp->initial_count = ntohl(initial_count);
4815 mp->initial_interval = ntohl(initial_interval);
4816 mp->surpress = surpress;
4817 mp->managed = managed;
4819 mp->ll_option = ll_option;
4820 mp->send_unicast = send_unicast;
4823 mp->default_router = default_router;
4828 /* Wait for a reply, return good/bad news */
4835 static int api_set_arp_neighbor_limit (vat_main_t * vam)
4837 unformat_input_t * i = vam->input;
4838 vl_api_set_arp_neighbor_limit_t *mp;
4844 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
4845 if (unformat (i, "arp_nbr_limit %d", &arp_nbr_limit))
4847 else if (unformat (i, "ipv6"))
4850 clib_warning ("parse error '%U'", format_unformat_error, i);
4855 if (limit_set == 0) {
4856 errmsg ("missing limit value\n");
4860 M(SET_ARP_NEIGHBOR_LIMIT, set_arp_neighbor_limit);
4862 mp->arp_neighbor_limit = ntohl(arp_nbr_limit);
4863 mp->is_ipv6 = is_ipv6;
4870 static int api_l2_patch_add_del (vat_main_t * vam)
4872 unformat_input_t * i = vam->input;
4873 vl_api_l2_patch_add_del_t *mp;
4876 u8 rx_sw_if_index_set = 0;
4878 u8 tx_sw_if_index_set = 0;
4881 /* Parse args required to build the message */
4882 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
4883 if (unformat (i, "rx_sw_if_index %d", &rx_sw_if_index))
4884 rx_sw_if_index_set = 1;
4885 else if (unformat (i, "tx_sw_if_index %d", &tx_sw_if_index))
4886 tx_sw_if_index_set = 1;
4887 else if (unformat (i, "rx")) {
4888 if (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
4889 if (unformat (i, "%U", unformat_sw_if_index, vam,
4891 rx_sw_if_index_set = 1;
4894 } else if (unformat (i, "tx")) {
4895 if (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
4896 if (unformat (i, "%U", unformat_sw_if_index, vam,
4898 tx_sw_if_index_set = 1;
4901 } else if (unformat (i, "del"))
4907 if (rx_sw_if_index_set == 0) {
4908 errmsg ("missing rx interface name or rx_sw_if_index\n");
4912 if (tx_sw_if_index_set == 0) {
4913 errmsg ("missing tx interface name or tx_sw_if_index\n");
4917 M(L2_PATCH_ADD_DEL, l2_patch_add_del);
4919 mp->rx_sw_if_index = ntohl(rx_sw_if_index);
4920 mp->tx_sw_if_index = ntohl(tx_sw_if_index);
4921 mp->is_add = is_add;
4928 static int api_sr_tunnel_add_del (vat_main_t * vam)
4930 unformat_input_t * i = vam->input;
4931 vl_api_sr_tunnel_add_del_t *mp;
4935 ip6_address_t src_address;
4936 int src_address_set = 0;
4937 ip6_address_t dst_address;
4939 int dst_address_set = 0;
4941 u32 rx_table_id = 0;
4942 u32 tx_table_id = 0;
4943 ip6_address_t * segments = 0;
4944 ip6_address_t * this_seg;
4945 ip6_address_t * tags = 0;
4946 ip6_address_t * this_tag;
4947 ip6_address_t next_address, tag;
4949 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
4951 if (unformat (i, "del"))
4953 else if (unformat (i, "rx_fib_id %d", &rx_table_id))
4955 else if (unformat (i, "tx_fib_id %d", &tx_table_id))
4957 else if (unformat (i, "src %U", unformat_ip6_address, &src_address))
4958 src_address_set = 1;
4959 else if (unformat (i, "dst %U/%d",
4960 unformat_ip6_address, &dst_address,
4962 dst_address_set = 1;
4963 else if (unformat (i, "next %U", unformat_ip6_address,
4966 vec_add2 (segments, this_seg, 1);
4967 memcpy (this_seg->as_u8, next_address.as_u8, sizeof (*this_seg));
4969 else if (unformat (i, "tag %U", unformat_ip6_address,
4972 vec_add2 (tags, this_tag, 1);
4973 memcpy (this_tag->as_u8, tag.as_u8, sizeof (*this_tag));
4975 else if (unformat (i, "clean"))
4976 flags |= IP6_SR_HEADER_FLAG_CLEANUP;
4977 else if (unformat (i, "protected"))
4978 flags |= IP6_SR_HEADER_FLAG_PROTECTED;
4979 else if (unformat (i, "InPE %d", &pl_index))
4981 if (pl_index <= 0 || pl_index > 4)
4983 pl_index_range_error:
4984 errmsg ("pl index %d out of range\n", pl_index);
4987 flags |= IP6_SR_HEADER_FLAG_PL_ELT_INGRESS_PE << (3*(pl_index - 1));
4989 else if (unformat (i, "EgPE %d", &pl_index))
4991 if (pl_index <= 0 || pl_index > 4)
4992 goto pl_index_range_error;
4993 flags |= IP6_SR_HEADER_FLAG_PL_ELT_EGRESS_PE << (3*(pl_index - 1));
4995 else if (unformat (i, "OrgSrc %d", &pl_index))
4997 if (pl_index <= 0 || pl_index > 4)
4998 goto pl_index_range_error;
4999 flags |= IP6_SR_HEADER_FLAG_PL_ELT_ORIG_SRC_ADDR << (3*(pl_index - 1));
5005 if (!src_address_set)
5007 errmsg ("src address required\n");
5011 if (!dst_address_set)
5013 errmsg ("dst address required\n");
5019 errmsg ("at least one sr segment required\n");
5023 M2(SR_TUNNEL_ADD_DEL, sr_tunnel_add_del,
5024 vec_len(segments) * sizeof (ip6_address_t)
5025 + vec_len(tags) * sizeof (ip6_address_t));
5027 memcpy (mp->src_address, &src_address, sizeof (mp->src_address));
5028 memcpy (mp->dst_address, &dst_address, sizeof (mp->dst_address));
5029 mp->dst_mask_width = dst_mask_width;
5030 mp->flags_net_byte_order = clib_host_to_net_u16 (flags);
5031 mp->n_segments = vec_len (segments);
5032 mp->n_tags = vec_len (tags);
5033 mp->is_add = is_del == 0;
5034 memcpy (mp->segs_and_tags, segments,
5035 vec_len(segments)* sizeof (ip6_address_t));
5036 memcpy (mp->segs_and_tags + vec_len(segments)*sizeof (ip6_address_t),
5037 tags, vec_len(tags)* sizeof (ip6_address_t));
5039 mp->outer_vrf_id = ntohl (rx_table_id);
5040 mp->inner_vrf_id = ntohl (tx_table_id);
5042 vec_free (segments);
5050 #define foreach_ip4_proto_field \
5060 uword unformat_ip4_mask (unformat_input_t * input, va_list * args)
5062 u8 ** maskp = va_arg (*args, u8 **);
5064 u8 found_something = 0;
5067 #define _(a) u8 a=0;
5068 foreach_ip4_proto_field;
5074 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
5076 if (unformat (input, "version"))
5078 else if (unformat (input, "hdr_length"))
5080 else if (unformat (input, "src"))
5082 else if (unformat (input, "dst"))
5084 else if (unformat (input, "proto"))
5087 #define _(a) else if (unformat (input, #a)) a=1;
5088 foreach_ip4_proto_field
5094 #define _(a) found_something += a;
5095 foreach_ip4_proto_field;
5098 if (found_something == 0)
5101 vec_validate (mask, sizeof (*ip) - 1);
5103 ip = (ip4_header_t *) mask;
5105 #define _(a) if (a) memset (&ip->a, 0xff, sizeof (ip->a));
5106 foreach_ip4_proto_field;
5109 ip->ip_version_and_header_length = 0;
5112 ip->ip_version_and_header_length |= 0xF0;
5115 ip->ip_version_and_header_length |= 0x0F;
5121 #define foreach_ip6_proto_field \
5128 uword unformat_ip6_mask (unformat_input_t * input, va_list * args)
5130 u8 ** maskp = va_arg (*args, u8 **);
5132 u8 found_something = 0;
5134 u32 ip_version_traffic_class_and_flow_label;
5136 #define _(a) u8 a=0;
5137 foreach_ip6_proto_field;
5140 u8 traffic_class = 0;
5143 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
5145 if (unformat (input, "version"))
5147 else if (unformat (input, "traffic-class"))
5149 else if (unformat (input, "flow-label"))
5151 else if (unformat (input, "src"))
5153 else if (unformat (input, "dst"))
5155 else if (unformat (input, "proto"))
5158 #define _(a) else if (unformat (input, #a)) a=1;
5159 foreach_ip6_proto_field
5165 #define _(a) found_something += a;
5166 foreach_ip6_proto_field;
5169 if (found_something == 0)
5172 vec_validate (mask, sizeof (*ip) - 1);
5174 ip = (ip6_header_t *) mask;
5176 #define _(a) if (a) memset (&ip->a, 0xff, sizeof (ip->a));
5177 foreach_ip6_proto_field;
5180 ip_version_traffic_class_and_flow_label = 0;
5183 ip_version_traffic_class_and_flow_label |= 0xF0000000;
5186 ip_version_traffic_class_and_flow_label |= 0x0FF00000;
5189 ip_version_traffic_class_and_flow_label |= 0x000FFFFF;
5191 ip->ip_version_traffic_class_and_flow_label =
5192 clib_host_to_net_u32 (ip_version_traffic_class_and_flow_label);
5198 uword unformat_l3_mask (unformat_input_t * input, va_list * args)
5200 u8 ** maskp = va_arg (*args, u8 **);
5202 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) {
5203 if (unformat (input, "ip4 %U", unformat_ip4_mask, maskp))
5205 else if (unformat (input, "ip6 %U", unformat_ip6_mask, maskp))
5213 uword unformat_l2_mask (unformat_input_t * input, va_list * args)
5215 u8 ** maskp = va_arg (*args, u8 **);
5230 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) {
5231 if (unformat (input, "src"))
5233 else if (unformat (input, "dst"))
5235 else if (unformat (input, "proto"))
5237 else if (unformat (input, "tag1"))
5239 else if (unformat (input, "tag2"))
5241 else if (unformat (input, "ignore-tag1"))
5243 else if (unformat (input, "ignore-tag2"))
5245 else if (unformat (input, "cos1"))
5247 else if (unformat (input, "cos2"))
5249 else if (unformat (input, "dot1q"))
5251 else if (unformat (input, "dot1ad"))
5256 if ((src + dst + proto + tag1 + tag2 + dot1q + dot1ad +
5257 ignore_tag1 + ignore_tag2 + cos1 + cos2) == 0)
5260 if (tag1 || ignore_tag1 || cos1 || dot1q)
5262 if (tag2 || ignore_tag2 || cos2 || dot1ad)
5265 vec_validate (mask, len-1);
5268 memset (mask, 0xff, 6);
5271 memset (mask + 6, 0xff, 6);
5275 /* inner vlan tag */
5284 mask[21] = mask [20] = 0xff;
5305 mask[16] = mask [17] = 0xff;
5315 mask[12] = mask [13] = 0xff;
5321 uword unformat_classify_mask (unformat_input_t * input, va_list * args)
5323 u8 ** maskp = va_arg (*args, u8 **);
5324 u32 * skipp = va_arg (*args, u32 *);
5325 u32 * matchp = va_arg (*args, u32 *);
5332 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) {
5333 if (unformat (input, "hex %U", unformat_hex_string, &mask))
5335 else if (unformat (input, "l2 %U", unformat_l2_mask, &l2))
5337 else if (unformat (input, "l3 %U", unformat_l3_mask, &l3))
5343 if (mask || l2 || l3)
5347 /* "With a free Ethernet header in every package" */
5349 vec_validate (l2, 13);
5351 vec_append (mask, l3);
5355 /* Scan forward looking for the first significant mask octet */
5356 for (i = 0; i < vec_len (mask); i++)
5360 /* compute (skip, match) params */
5361 *skipp = i / sizeof(u32x4);
5362 vec_delete (mask, *skipp * sizeof(u32x4), 0);
5364 /* Pad mask to an even multiple of the vector size */
5365 while (vec_len (mask) % sizeof (u32x4))
5368 match = vec_len (mask) / sizeof (u32x4);
5370 for (i = match*sizeof(u32x4); i > 0; i-= sizeof(u32x4))
5372 u64 *tmp = (u64 *)(mask + (i-sizeof(u32x4)));
5373 if (*tmp || *(tmp+1))
5378 clib_warning ("BUG: match 0");
5380 _vec_len (mask) = match * sizeof(u32x4);
5391 #define foreach_l2_next \
5393 _(ethernet, ETHERNET_INPUT) \
5397 uword unformat_l2_next_index (unformat_input_t * input, va_list * args)
5399 u32 * miss_next_indexp = va_arg (*args, u32 *);
5404 if (unformat (input, #n)) { next_index = L2_CLASSIFY_NEXT_##N; goto out;}
5408 if (unformat (input, "%d", &tmp))
5417 *miss_next_indexp = next_index;
5421 #define foreach_ip_next \
5427 uword unformat_ip_next_index (unformat_input_t * input, va_list * args)
5429 u32 * miss_next_indexp = va_arg (*args, u32 *);
5434 if (unformat (input, #n)) { next_index = IP_LOOKUP_NEXT_##N; goto out;}
5438 if (unformat (input, "%d", &tmp))
5447 *miss_next_indexp = next_index;
5451 #define foreach_acl_next \
5454 uword unformat_acl_next_index (unformat_input_t * input, va_list * args)
5456 u32 * miss_next_indexp = va_arg (*args, u32 *);
5461 if (unformat (input, #n)) { next_index = ACL_NEXT_INDEX_##N; goto out;}
5465 if (unformat (input, "permit"))
5470 else if (unformat (input, "%d", &tmp))
5479 *miss_next_indexp = next_index;
5483 static int api_classify_add_del_table (vat_main_t * vam)
5485 unformat_input_t * i = vam->input;
5486 vl_api_classify_add_del_table_t *mp;
5492 u32 table_index = ~0;
5493 u32 next_table_index = ~0;
5494 u32 miss_next_index = ~0;
5495 u32 memory_size = 32<<20;
5499 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
5500 if (unformat (i, "del"))
5502 else if (unformat (i, "buckets %d", &nbuckets))
5504 else if (unformat (i, "memory_size %d", &memory_size))
5506 else if (unformat (i, "skip %d", &skip))
5508 else if (unformat (i, "match %d", &match))
5510 else if (unformat (i, "table %d", &table_index))
5512 else if (unformat (i, "mask %U", unformat_classify_mask,
5513 &mask, &skip, &match))
5515 else if (unformat (i, "next-table %d", &next_table_index))
5517 else if (unformat (i, "miss-next %U", unformat_ip_next_index,
5520 else if (unformat (i, "l2-miss-next %U", unformat_l2_next_index,
5523 else if (unformat (i, "acl-miss-next %U", unformat_acl_next_index,
5530 if (is_add && mask == 0) {
5531 errmsg ("Mask required\n");
5535 if (is_add && skip == ~0) {
5536 errmsg ("skip count required\n");
5540 if (is_add && match == ~0) {
5541 errmsg ("match count required\n");
5545 if (!is_add && table_index == ~0) {
5546 errmsg ("table index required for delete\n");
5550 M2 (CLASSIFY_ADD_DEL_TABLE, classify_add_del_table,
5553 mp->is_add = is_add;
5554 mp->table_index = ntohl(table_index);
5555 mp->nbuckets = ntohl(nbuckets);
5556 mp->memory_size = ntohl(memory_size);
5557 mp->skip_n_vectors = ntohl(skip);
5558 mp->match_n_vectors = ntohl(match);
5559 mp->next_table_index = ntohl(next_table_index);
5560 mp->miss_next_index = ntohl(miss_next_index);
5561 memcpy (mp->mask, mask, vec_len(mask));
5569 uword unformat_ip4_match (unformat_input_t * input, va_list * args)
5571 u8 ** matchp = va_arg (*args, u8 **);
5578 int src = 0, dst = 0;
5579 ip4_address_t src_val, dst_val;
5586 int fragment_id = 0;
5587 u32 fragment_id_val;
5593 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
5595 if (unformat (input, "version %d", &version_val))
5597 else if (unformat (input, "hdr_length %d", &hdr_length_val))
5599 else if (unformat (input, "src %U", unformat_ip4_address, &src_val))
5601 else if (unformat (input, "dst %U", unformat_ip4_address, &dst_val))
5603 else if (unformat (input, "proto %d", &proto_val))
5605 else if (unformat (input, "tos %d", &tos_val))
5607 else if (unformat (input, "length %d", &length_val))
5609 else if (unformat (input, "fragment_id %d", &fragment_id_val))
5611 else if (unformat (input, "ttl %d", &ttl_val))
5613 else if (unformat (input, "checksum %d", &checksum_val))
5619 if (version + hdr_length + src + dst + proto + tos + length + fragment_id
5620 + ttl + checksum == 0)
5624 * Aligned because we use the real comparison functions
5626 vec_validate_aligned (match, sizeof (*ip) - 1, sizeof(u32x4));
5628 ip = (ip4_header_t *) match;
5630 /* These are realistically matched in practice */
5632 ip->src_address.as_u32 = src_val.as_u32;
5635 ip->dst_address.as_u32 = dst_val.as_u32;
5638 ip->protocol = proto_val;
5641 /* These are not, but they're included for completeness */
5643 ip->ip_version_and_header_length |= (version_val & 0xF)<<4;
5646 ip->ip_version_and_header_length |= (hdr_length_val & 0xF);
5652 ip->length = length_val;
5658 ip->checksum = checksum_val;
5664 uword unformat_ip6_match (unformat_input_t * input, va_list * args)
5666 u8 ** matchp = va_arg (*args, u8 **);
5672 u32 traffic_class_val;
5675 int src = 0, dst = 0;
5676 ip6_address_t src_val, dst_val;
5679 int payload_length = 0;
5680 u32 payload_length_val;
5683 u32 ip_version_traffic_class_and_flow_label;
5685 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
5687 if (unformat (input, "version %d", &version_val))
5689 else if (unformat (input, "traffic_class %d", &traffic_class_val))
5691 else if (unformat (input, "flow_label %d", &flow_label_val))
5693 else if (unformat (input, "src %U", unformat_ip6_address, &src_val))
5695 else if (unformat (input, "dst %U", unformat_ip6_address, &dst_val))
5697 else if (unformat (input, "proto %d", &proto_val))
5699 else if (unformat (input, "payload_length %d", &payload_length_val))
5701 else if (unformat (input, "hop_limit %d", &hop_limit_val))
5707 if (version + traffic_class + flow_label + src + dst + proto +
5708 payload_length + hop_limit == 0)
5712 * Aligned because we use the real comparison functions
5714 vec_validate_aligned (match, sizeof (*ip) - 1, sizeof(u32x4));
5716 ip = (ip6_header_t *) match;
5719 memcpy (&ip->src_address, &src_val, sizeof (ip->src_address));
5722 memcpy (&ip->dst_address, &dst_val, sizeof (ip->dst_address));
5725 ip->protocol = proto_val;
5727 ip_version_traffic_class_and_flow_label = 0;
5730 ip_version_traffic_class_and_flow_label |= (version_val & 0xF) << 28;
5733 ip_version_traffic_class_and_flow_label |= (traffic_class_val & 0xFF) << 20;
5736 ip_version_traffic_class_and_flow_label |= (flow_label_val & 0xFFFFF);
5738 ip->ip_version_traffic_class_and_flow_label =
5739 clib_host_to_net_u32 (ip_version_traffic_class_and_flow_label);
5742 ip->payload_length = clib_host_to_net_u16 (payload_length_val);
5745 ip->hop_limit = hop_limit_val;
5751 uword unformat_l3_match (unformat_input_t * input, va_list * args)
5753 u8 ** matchp = va_arg (*args, u8 **);
5755 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) {
5756 if (unformat (input, "ip4 %U", unformat_ip4_match, matchp))
5758 else if (unformat (input, "ip6 %U", unformat_ip6_match, matchp))
5766 uword unformat_vlan_tag (unformat_input_t * input, va_list * args)
5768 u8 * tagp = va_arg (*args, u8 *);
5771 if (unformat(input, "%d", &tag))
5773 tagp[0] = (tag>>8) & 0x0F;
5774 tagp[1] = tag & 0xFF;
5781 uword unformat_l2_match (unformat_input_t * input, va_list * args)
5783 u8 ** matchp = va_arg (*args, u8 **);
5803 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) {
5804 if (unformat (input, "src %U", unformat_ethernet_address, &src_val))
5806 else if (unformat (input, "dst %U", unformat_ethernet_address, &dst_val))
5808 else if (unformat (input, "proto %U",
5809 unformat_ethernet_type_host_byte_order, &proto_val))
5811 else if (unformat (input, "tag1 %U", unformat_vlan_tag, tag1_val))
5813 else if (unformat (input, "tag2 %U", unformat_vlan_tag, tag2_val))
5815 else if (unformat (input, "ignore-tag1"))
5817 else if (unformat (input, "ignore-tag2"))
5819 else if (unformat (input, "cos1 %d", &cos1_val))
5821 else if (unformat (input, "cos2 %d", &cos2_val))
5826 if ((src + dst + proto + tag1 + tag2 +
5827 ignore_tag1 + ignore_tag2 + cos1 + cos2) == 0)
5830 if (tag1 || ignore_tag1 || cos1)
5832 if (tag2 || ignore_tag2 || cos2)
5835 vec_validate_aligned (match, len-1, sizeof(u32x4));
5838 memcpy (match, dst_val, 6);
5841 memcpy (match + 6, src_val, 6);
5845 /* inner vlan tag */
5846 match[19] = tag2_val[1];
5847 match[18] = tag2_val[0];
5849 match [18] |= (cos2_val & 0x7) << 5;
5852 match[21] = proto_val & 0xff;
5853 match[20] = proto_val >> 8;
5857 match [15] = tag1_val[1];
5858 match [14] = tag1_val[0];
5861 match [14] |= (cos1_val & 0x7) << 5;
5867 match [15] = tag1_val[1];
5868 match [14] = tag1_val[0];
5871 match[17] = proto_val & 0xff;
5872 match[16] = proto_val >> 8;
5875 match [14] |= (cos1_val & 0x7) << 5;
5881 match [18] |= (cos2_val & 0x7) << 5;
5883 match [14] |= (cos1_val & 0x7) << 5;
5886 match[13] = proto_val & 0xff;
5887 match[12] = proto_val >> 8;
5895 uword unformat_classify_match (unformat_input_t * input, va_list * args)
5897 u8 ** matchp = va_arg (*args, u8 **);
5898 u32 skip_n_vectors = va_arg (*args, u32);
5899 u32 match_n_vectors = va_arg (*args, u32);
5905 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) {
5906 if (unformat (input, "hex %U", unformat_hex_string, &match))
5908 else if (unformat (input, "l2 %U", unformat_l2_match, &l2))
5910 else if (unformat (input, "l3 %U", unformat_l3_match, &l3))
5916 if (match || l2 || l3)
5920 /* "Win a free Ethernet header in every packet" */
5922 vec_validate_aligned (l2, 13, sizeof(u32x4));
5924 vec_append_aligned (match, l3, sizeof(u32x4));
5928 /* Make sure the vector is big enough even if key is all 0's */
5929 vec_validate_aligned
5930 (match, ((match_n_vectors + skip_n_vectors) * sizeof(u32x4)) - 1,
5933 /* Set size, include skipped vectors*/
5934 _vec_len (match) = (match_n_vectors+skip_n_vectors) * sizeof(u32x4);
5944 static int api_classify_add_del_session (vat_main_t * vam)
5946 unformat_input_t * i = vam->input;
5947 vl_api_classify_add_del_session_t *mp;
5949 u32 table_index = ~0;
5950 u32 hit_next_index = ~0;
5951 u32 opaque_index = ~0;
5955 u32 skip_n_vectors = 0;
5956 u32 match_n_vectors = 0;
5959 * Warning: you have to supply skip_n and match_n
5960 * because the API client cant simply look at the classify
5964 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
5965 if (unformat (i, "del"))
5967 else if (unformat (i, "hit-next %U", unformat_ip_next_index,
5970 else if (unformat (i, "l2-hit-next %U", unformat_l2_next_index,
5973 else if (unformat (i, "acl-hit-next %U", unformat_acl_next_index,
5976 else if (unformat (i, "opaque-index %d", &opaque_index))
5978 else if (unformat (i, "skip_n %d", &skip_n_vectors))
5980 else if (unformat (i, "match_n %d", &match_n_vectors))
5982 else if (unformat (i, "match %U", unformat_classify_match,
5983 &match, skip_n_vectors, match_n_vectors))
5985 else if (unformat (i, "advance %d", &advance))
5987 else if (unformat (i, "table-index %d", &table_index))
5993 if (table_index == ~0) {
5994 errmsg ("Table index required\n");
5998 if (is_add && match == 0) {
5999 errmsg ("Match value required\n");
6003 M2 (CLASSIFY_ADD_DEL_SESSION, classify_add_del_session,
6006 mp->is_add = is_add;
6007 mp->table_index = ntohl(table_index);
6008 mp->hit_next_index = ntohl(hit_next_index);
6009 mp->opaque_index = ntohl(opaque_index);
6010 mp->advance = ntohl(advance);
6011 memcpy (mp->match, match, vec_len(match));
6018 static int api_classify_set_interface_ip_table (vat_main_t * vam)
6020 unformat_input_t * i = vam->input;
6021 vl_api_classify_set_interface_ip_table_t *mp;
6024 int sw_if_index_set;
6025 u32 table_index = ~0;
6028 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
6029 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
6030 sw_if_index_set = 1;
6031 else if (unformat (i, "sw_if_index %d", &sw_if_index))
6032 sw_if_index_set = 1;
6033 else if (unformat (i, "table %d", &table_index))
6036 clib_warning ("parse error '%U'", format_unformat_error, i);
6041 if (sw_if_index_set == 0) {
6042 errmsg ("missing interface name or sw_if_index\n");
6047 M(CLASSIFY_SET_INTERFACE_IP_TABLE, classify_set_interface_ip_table);
6049 mp->sw_if_index = ntohl(sw_if_index);
6050 mp->table_index = ntohl(table_index);
6051 mp->is_ipv6 = is_ipv6;
6058 static int api_classify_set_interface_l2_tables (vat_main_t * vam)
6060 unformat_input_t * i = vam->input;
6061 vl_api_classify_set_interface_l2_tables_t *mp;
6064 int sw_if_index_set;
6065 u32 ip4_table_index = ~0;
6066 u32 ip6_table_index = ~0;
6067 u32 other_table_index = ~0;
6069 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
6070 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
6071 sw_if_index_set = 1;
6072 else if (unformat (i, "sw_if_index %d", &sw_if_index))
6073 sw_if_index_set = 1;
6074 else if (unformat (i, "ip4-table %d", &ip4_table_index))
6076 else if (unformat (i, "ip6-table %d", &ip6_table_index))
6078 else if (unformat (i, "other-table %d", &other_table_index))
6081 clib_warning ("parse error '%U'", format_unformat_error, i);
6086 if (sw_if_index_set == 0) {
6087 errmsg ("missing interface name or sw_if_index\n");
6092 M(CLASSIFY_SET_INTERFACE_L2_TABLES, classify_set_interface_l2_tables);
6094 mp->sw_if_index = ntohl(sw_if_index);
6095 mp->ip4_table_index = ntohl(ip4_table_index);
6096 mp->ip6_table_index = ntohl(ip6_table_index);
6097 mp->other_table_index = ntohl(other_table_index);
6105 static int api_get_node_index (vat_main_t * vam)
6107 unformat_input_t * i = vam->input;
6108 vl_api_get_node_index_t * mp;
6112 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
6113 if (unformat (i, "node %s", &name))
6119 errmsg ("node name required\n");
6122 if (vec_len (name) >= ARRAY_LEN(mp->node_name)) {
6123 errmsg ("node name too long, max %d\n", ARRAY_LEN(mp->node_name));
6127 M(GET_NODE_INDEX, get_node_index);
6128 memcpy (mp->node_name, name, vec_len(name));
6136 static int api_add_node_next (vat_main_t * vam)
6138 unformat_input_t * i = vam->input;
6139 vl_api_add_node_next_t * mp;
6144 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
6145 if (unformat (i, "node %s", &name))
6147 else if (unformat (i, "next %s", &next))
6153 errmsg ("node name required\n");
6156 if (vec_len (name) >= ARRAY_LEN(mp->node_name)) {
6157 errmsg ("node name too long, max %d\n", ARRAY_LEN(mp->node_name));
6161 errmsg ("next node required\n");
6164 if (vec_len (next) >= ARRAY_LEN(mp->next_name)) {
6165 errmsg ("next name too long, max %d\n", ARRAY_LEN(mp->next_name));
6169 M(ADD_NODE_NEXT, add_node_next);
6170 memcpy (mp->node_name, name, vec_len(name));
6171 memcpy (mp->next_name, next, vec_len(next));
6180 static int api_l2tpv3_create_tunnel (vat_main_t * vam)
6182 unformat_input_t * i = vam->input;
6183 ip6_address_t client_address, our_address;
6184 int client_address_set = 0;
6185 int our_address_set = 0;
6186 u32 local_session_id = 0;
6187 u32 remote_session_id = 0;
6188 u64 local_cookie = 0;
6189 u64 remote_cookie = 0;
6190 u8 l2_sublayer_present = 0;
6191 vl_api_l2tpv3_create_tunnel_t * mp;
6194 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
6195 if (unformat (i, "client_address %U", unformat_ip6_address,
6197 client_address_set = 1;
6198 else if (unformat (i, "our_address %U", unformat_ip6_address,
6200 our_address_set = 1;
6201 else if (unformat (i, "local_session_id %d", &local_session_id))
6203 else if (unformat (i, "remote_session_id %d", &remote_session_id))
6205 else if (unformat (i, "local_cookie %lld", &local_cookie))
6207 else if (unformat (i, "remote_cookie %lld", &remote_cookie))
6209 else if (unformat (i, "l2-sublayer-present"))
6210 l2_sublayer_present = 1;
6215 if (client_address_set == 0) {
6216 errmsg ("client_address required\n");
6220 if (our_address_set == 0) {
6221 errmsg ("our_address required\n");
6225 M(L2TPV3_CREATE_TUNNEL, l2tpv3_create_tunnel);
6227 memcpy (mp->client_address, client_address.as_u8,
6228 sizeof (mp->client_address));
6230 memcpy (mp->our_address, our_address.as_u8,
6231 sizeof (mp->our_address));
6233 mp->local_session_id = ntohl (local_session_id);
6234 mp->remote_session_id = ntohl (remote_session_id);
6235 mp->local_cookie = clib_host_to_net_u64 (local_cookie);
6236 mp->remote_cookie = clib_host_to_net_u64 (remote_cookie);
6237 mp->l2_sublayer_present = l2_sublayer_present;
6245 static int api_l2tpv3_set_tunnel_cookies (vat_main_t * vam)
6247 unformat_input_t * i = vam->input;
6249 u8 sw_if_index_set = 0;
6250 u64 new_local_cookie = 0;
6251 u64 new_remote_cookie = 0;
6252 vl_api_l2tpv3_set_tunnel_cookies_t *mp;
6255 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
6256 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
6257 sw_if_index_set = 1;
6258 else if (unformat (i, "sw_if_index %d", &sw_if_index))
6259 sw_if_index_set = 1;
6260 else if (unformat (i, "new_local_cookie %lld", &new_local_cookie))
6262 else if (unformat (i, "new_remote_cookie %lld", &new_remote_cookie))
6268 if (sw_if_index_set == 0) {
6269 errmsg ("missing interface name or sw_if_index\n");
6273 M(L2TPV3_SET_TUNNEL_COOKIES, l2tpv3_set_tunnel_cookies);
6275 mp->sw_if_index = ntohl(sw_if_index);
6276 mp->new_local_cookie = clib_host_to_net_u64 (new_local_cookie);
6277 mp->new_remote_cookie = clib_host_to_net_u64 (new_remote_cookie);
6284 static int api_l2tpv3_interface_enable_disable (vat_main_t * vam)
6286 unformat_input_t * i = vam->input;
6287 vl_api_l2tpv3_interface_enable_disable_t *mp;
6290 u8 sw_if_index_set = 0;
6291 u8 enable_disable = 1;
6293 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
6294 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
6295 sw_if_index_set = 1;
6296 else if (unformat (i, "sw_if_index %d", &sw_if_index))
6297 sw_if_index_set = 1;
6298 else if (unformat (i, "enable"))
6300 else if (unformat (i, "disable"))
6306 if (sw_if_index_set == 0) {
6307 errmsg ("missing interface name or sw_if_index\n");
6311 M(L2TPV3_INTERFACE_ENABLE_DISABLE, l2tpv3_interface_enable_disable);
6313 mp->sw_if_index = ntohl(sw_if_index);
6314 mp->enable_disable = enable_disable;
6321 static int api_l2tpv3_set_lookup_key (vat_main_t * vam)
6323 unformat_input_t * i = vam->input;
6324 vl_api_l2tpv3_set_lookup_key_t * mp;
6328 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
6329 if (unformat (i, "lookup_v6_src"))
6330 key = L2T_LOOKUP_SRC_ADDRESS;
6331 else if (unformat (i, "lookup_v6_dst"))
6332 key = L2T_LOOKUP_DST_ADDRESS;
6333 else if (unformat (i, "lookup_session_id"))
6334 key = L2T_LOOKUP_SESSION_ID;
6340 errmsg ("l2tp session lookup key unset\n");
6344 M(L2TPV3_SET_LOOKUP_KEY, l2tpv3_set_lookup_key);
6353 static void vl_api_sw_if_l2tpv3_tunnel_details_t_handler
6354 (vl_api_sw_if_l2tpv3_tunnel_details_t * mp)
6356 vat_main_t * vam = &vat_main;
6358 fformat(vam->ofp, "* %U (our) %U (client) (sw_if_index %d)\n",
6359 format_ip6_address, mp->our_address,
6360 format_ip6_address, mp->client_address,
6361 clib_net_to_host_u32(mp->sw_if_index));
6363 fformat (vam->ofp, " local cookies %016llx %016llx remote cookie %016llx\n",
6364 clib_net_to_host_u64 (mp->local_cookie[0]),
6365 clib_net_to_host_u64 (mp->local_cookie[1]),
6366 clib_net_to_host_u64 (mp->remote_cookie));
6368 fformat (vam->ofp, " local session-id %d remote session-id %d\n",
6369 clib_net_to_host_u32 (mp->local_session_id),
6370 clib_net_to_host_u32 (mp->remote_session_id));
6372 fformat (vam->ofp, " l2 specific sublayer %s\n\n",
6373 mp->l2_sublayer_present ? "preset" : "absent");
6377 static void vl_api_sw_if_l2tpv3_tunnel_details_t_handler_json
6378 (vl_api_sw_if_l2tpv3_tunnel_details_t * mp)
6380 vat_main_t * vam = &vat_main;
6381 vat_json_node_t *node = NULL;
6382 struct in6_addr addr;
6384 if (VAT_JSON_ARRAY != vam->json_tree.type) {
6385 ASSERT(VAT_JSON_NONE == vam->json_tree.type);
6386 vat_json_init_array(&vam->json_tree);
6388 node = vat_json_array_add(&vam->json_tree);
6390 vat_json_init_object(node);
6392 memcpy(&addr, mp->our_address, sizeof(addr));
6393 vat_json_object_add_ip6(node, "our_address", addr);
6394 memcpy(&addr, mp->client_address, sizeof(addr));
6395 vat_json_object_add_ip6(node, "client_address", addr);
6397 vat_json_node_t * lc = vat_json_object_add(node, "local_cookie");
6398 vat_json_init_array(lc);
6399 vat_json_array_add_uint(lc, clib_net_to_host_u64(mp->local_cookie[0]));
6400 vat_json_array_add_uint(lc, clib_net_to_host_u64(mp->local_cookie[1]));
6401 vat_json_object_add_uint(node, "remote_cookie", clib_net_to_host_u64(mp->remote_cookie));
6403 printf("local id: %u", clib_net_to_host_u32(mp->local_session_id));
6404 vat_json_object_add_uint(node, "local_session_id", clib_net_to_host_u32(mp->local_session_id));
6405 vat_json_object_add_uint(node, "remote_session_id", clib_net_to_host_u32(mp->remote_session_id));
6406 vat_json_object_add_string_copy(node, "l2_sublayer", mp->l2_sublayer_present ?
6407 (u8*)"present" : (u8*)"absent");
6410 static int api_sw_if_l2tpv3_tunnel_dump (vat_main_t * vam)
6412 vl_api_sw_if_l2tpv3_tunnel_dump_t *mp;
6415 /* Get list of l2tpv3-tunnel interfaces */
6416 M(SW_IF_L2TPV3_TUNNEL_DUMP, sw_if_l2tpv3_tunnel_dump);
6419 /* Use a control ping for synchronization */
6421 vl_api_control_ping_t * mp;
6422 M(CONTROL_PING, control_ping);
6429 static void vl_api_sw_interface_tap_details_t_handler
6430 (vl_api_sw_interface_tap_details_t * mp)
6432 vat_main_t * vam = &vat_main;
6434 fformat(vam->ofp, "%-16s %d\n",
6436 clib_net_to_host_u32(mp->sw_if_index));
6439 static void vl_api_sw_interface_tap_details_t_handler_json
6440 (vl_api_sw_interface_tap_details_t * mp)
6442 vat_main_t * vam = &vat_main;
6443 vat_json_node_t *node = NULL;
6445 if (VAT_JSON_ARRAY != vam->json_tree.type) {
6446 ASSERT(VAT_JSON_NONE == vam->json_tree.type);
6447 vat_json_init_array(&vam->json_tree);
6449 node = vat_json_array_add(&vam->json_tree);
6451 vat_json_init_object(node);
6452 vat_json_object_add_uint(node, "sw_if_index", ntohl(mp->sw_if_index));
6453 vat_json_object_add_string_copy(node, "dev_name", mp->dev_name);
6456 static int api_sw_interface_tap_dump (vat_main_t * vam)
6458 vl_api_sw_interface_tap_dump_t *mp;
6461 fformat(vam->ofp, "\n%-16s %s\n", "dev_name", "sw_if_index");
6462 /* Get list of tap interfaces */
6463 M(SW_INTERFACE_TAP_DUMP, sw_interface_tap_dump);
6466 /* Use a control ping for synchronization */
6468 vl_api_control_ping_t * mp;
6469 M(CONTROL_PING, control_ping);
6475 static uword unformat_vxlan_decap_next
6476 (unformat_input_t * input, va_list * args)
6478 u32 * result = va_arg (*args, u32 *);
6481 if (unformat (input, "drop"))
6482 *result = VXLAN_INPUT_NEXT_DROP;
6483 else if (unformat (input, "ip4"))
6484 *result = VXLAN_INPUT_NEXT_IP4_INPUT;
6485 else if (unformat (input, "ip6"))
6486 *result = VXLAN_INPUT_NEXT_IP6_INPUT;
6487 else if (unformat (input, "l2"))
6488 *result = VXLAN_INPUT_NEXT_L2_INPUT;
6489 else if (unformat (input, "%d", &tmp))
6496 static int api_vxlan_add_del_tunnel (vat_main_t * vam)
6498 unformat_input_t * line_input = vam->input;
6499 vl_api_vxlan_add_del_tunnel_t *mp;
6501 ip4_address_t src, dst;
6505 u32 encap_vrf_id = 0;
6506 u32 decap_next_index = ~0;
6509 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) {
6510 if (unformat (line_input, "del"))
6512 else if (unformat (line_input, "src %U",
6513 unformat_ip4_address, &src))
6515 else if (unformat (line_input, "dst %U",
6516 unformat_ip4_address, &dst))
6518 else if (unformat (line_input, "encap-vrf-id %d", &encap_vrf_id))
6520 else if (unformat (line_input, "decap-next %U",
6521 unformat_vxlan_decap_next, &decap_next_index))
6523 else if (unformat (line_input, "vni %d", &vni))
6526 errmsg ("parse error '%U'\n", format_unformat_error, line_input);
6532 errmsg ("tunnel src address not specified\n");
6536 errmsg ("tunnel dst address not specified\n");
6540 if ((vni == 0) || (vni>>24)) {
6541 errmsg ("vni not specified or out of range\n");
6545 M (VXLAN_ADD_DEL_TUNNEL, vxlan_add_del_tunnel);
6547 mp->src_address = src.as_u32;
6548 mp->dst_address = dst.as_u32;
6549 mp->encap_vrf_id = ntohl(encap_vrf_id);
6550 mp->decap_next_index = ntohl(decap_next_index);
6551 mp->vni = ntohl(vni);
6552 mp->is_add = is_add;
6559 static void vl_api_vxlan_tunnel_details_t_handler
6560 (vl_api_vxlan_tunnel_details_t * mp)
6562 vat_main_t * vam = &vat_main;
6564 fformat(vam->ofp, "%11d%13U%13U%14d%18d%13d\n",
6565 ntohl(mp->sw_if_index),
6566 format_ip4_address, &mp->src_address,
6567 format_ip4_address, &mp->dst_address,
6568 ntohl(mp->encap_vrf_id),
6569 ntohl(mp->decap_next_index),
6573 static void vl_api_vxlan_tunnel_details_t_handler_json
6574 (vl_api_vxlan_tunnel_details_t * mp)
6576 vat_main_t * vam = &vat_main;
6577 vat_json_node_t *node = NULL;
6580 if (VAT_JSON_ARRAY != vam->json_tree.type) {
6581 ASSERT(VAT_JSON_NONE == vam->json_tree.type);
6582 vat_json_init_array(&vam->json_tree);
6584 node = vat_json_array_add(&vam->json_tree);
6586 vat_json_init_object(node);
6587 vat_json_object_add_uint(node, "sw_if_index", ntohl(mp->sw_if_index));
6588 memcpy(&ip4, &mp->src_address, sizeof(ip4));
6589 vat_json_object_add_ip4(node, "src_address", ip4);
6590 memcpy(&ip4, &mp->dst_address, sizeof(ip4));
6591 vat_json_object_add_ip4(node, "dst_address", ip4);
6592 vat_json_object_add_uint(node, "encap_vrf_id", ntohl(mp->encap_vrf_id));
6593 vat_json_object_add_uint(node, "decap_next_index", ntohl(mp->decap_next_index));
6594 vat_json_object_add_uint(node, "vni", ntohl(mp->vni));
6597 static int api_vxlan_tunnel_dump (vat_main_t * vam)
6599 unformat_input_t * i = vam->input;
6600 vl_api_vxlan_tunnel_dump_t *mp;
6603 u8 sw_if_index_set = 0;
6605 /* Parse args required to build the message */
6606 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
6607 if (unformat (i, "sw_if_index %d", &sw_if_index))
6608 sw_if_index_set = 1;
6613 if (sw_if_index_set == 0) {
6617 if (!vam->json_output) {
6618 fformat(vam->ofp, "%11s%13s%13s%14s%18s%13s\n",
6619 "sw_if_index", "src_address", "dst_address",
6620 "encap_vrf_id", "decap_next_index", "vni");
6623 /* Get list of l2tpv3-tunnel interfaces */
6624 M(VXLAN_TUNNEL_DUMP, vxlan_tunnel_dump);
6626 mp->sw_if_index = htonl(sw_if_index);
6630 /* Use a control ping for synchronization */
6632 vl_api_control_ping_t * mp;
6633 M(CONTROL_PING, control_ping);
6639 static int api_l2_fib_clear_table (vat_main_t * vam)
6641 // unformat_input_t * i = vam->input;
6642 vl_api_l2_fib_clear_table_t *mp;
6645 M(L2_FIB_CLEAR_TABLE, l2_fib_clear_table);
6652 static int api_l2_interface_efp_filter (vat_main_t * vam)
6654 unformat_input_t * i = vam->input;
6655 vl_api_l2_interface_efp_filter_t *mp;
6659 u8 sw_if_index_set = 0;
6661 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
6662 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
6663 sw_if_index_set = 1;
6664 else if (unformat (i, "sw_if_index %d", &sw_if_index))
6665 sw_if_index_set = 1;
6666 else if (unformat (i, "enable"))
6668 else if (unformat (i, "disable"))
6671 clib_warning ("parse error '%U'", format_unformat_error, i);
6676 if (sw_if_index_set == 0) {
6677 errmsg ("missing sw_if_index\n");
6681 M(L2_INTERFACE_EFP_FILTER, l2_interface_efp_filter);
6683 mp->sw_if_index = ntohl(sw_if_index);
6684 mp->enable_disable = enable;
6691 #define foreach_vtr_op \
6692 _("disable", L2_VTR_DISABLED) \
6693 _("push-1", L2_VTR_PUSH_1) \
6694 _("push-2", L2_VTR_PUSH_2) \
6695 _("pop-1", L2_VTR_POP_1) \
6696 _("pop-2", L2_VTR_POP_2) \
6697 _("translate-1-1", L2_VTR_TRANSLATE_1_1) \
6698 _("translate-1-2", L2_VTR_TRANSLATE_1_2) \
6699 _("translate-2-1", L2_VTR_TRANSLATE_2_1) \
6700 _("translate-2-2", L2_VTR_TRANSLATE_2_2)
6702 static int api_l2_interface_vlan_tag_rewrite (vat_main_t * vam)
6704 unformat_input_t * i = vam->input;
6705 vl_api_l2_interface_vlan_tag_rewrite_t *mp;
6708 u8 sw_if_index_set = 0;
6715 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
6716 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
6717 sw_if_index_set = 1;
6718 else if (unformat (i, "sw_if_index %d", &sw_if_index))
6719 sw_if_index_set = 1;
6720 else if (unformat (i, "vtr_op %d", &vtr_op))
6722 #define _(n,v) else if (unformat(i, n)) {vtr_op = v; vtr_op_set = 1;}
6726 else if (unformat (i, "push_dot1q %d", &push_dot1q))
6728 else if (unformat (i, "tag1 %d", &tag1))
6730 else if (unformat (i, "tag2 %d", &tag2))
6733 clib_warning ("parse error '%U'", format_unformat_error, i);
6738 if ((sw_if_index_set == 0)||(vtr_op_set == 0)) {
6739 errmsg ("missing vtr operation or sw_if_index\n");
6743 M(L2_INTERFACE_VLAN_TAG_REWRITE, l2_interface_vlan_tag_rewrite)
6745 mp->sw_if_index = ntohl(sw_if_index);
6746 mp->vtr_op = ntohl(vtr_op);
6747 mp->push_dot1q = ntohl(push_dot1q);
6748 mp->tag1 = ntohl(tag1);
6749 mp->tag2 = ntohl(tag2);
6756 static int api_create_vhost_user_if (vat_main_t * vam)
6758 unformat_input_t * i = vam->input;
6759 vl_api_create_vhost_user_if_t *mp;
6763 u8 file_name_set = 0;
6764 u32 custom_dev_instance = ~0;
6766 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
6767 if (unformat (i, "socket %s", &file_name)) {
6770 else if (unformat (i, "renumber %"PRIu32, &custom_dev_instance))
6772 else if (unformat (i, "server"))
6778 if (file_name_set == 0) {
6779 errmsg ("missing socket file name\n");
6783 if (vec_len (file_name) > 255) {
6784 errmsg ("socket file name too long\n");
6787 vec_add1 (file_name, 0);
6789 M(CREATE_VHOST_USER_IF, create_vhost_user_if);
6791 mp->is_server = is_server;
6792 memcpy(mp->sock_filename, file_name, vec_len(file_name));
6793 vec_free(file_name);
6794 if (custom_dev_instance != ~0) {
6796 mp->custom_dev_instance = ntohl(custom_dev_instance);
6804 static int api_modify_vhost_user_if (vat_main_t * vam)
6806 unformat_input_t * i = vam->input;
6807 vl_api_modify_vhost_user_if_t *mp;
6811 u8 file_name_set = 0;
6812 u32 custom_dev_instance = ~0;
6813 u8 sw_if_index_set = 0;
6814 u32 sw_if_index = (u32)~0;
6816 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
6817 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
6818 sw_if_index_set = 1;
6819 else if (unformat (i, "sw_if_index %d", &sw_if_index))
6820 sw_if_index_set = 1;
6821 else if (unformat (i, "socket %s", &file_name)) {
6824 else if (unformat (i, "renumber %"PRIu32, &custom_dev_instance))
6826 else if (unformat (i, "server"))
6832 if (sw_if_index_set == 0) {
6833 errmsg ("missing sw_if_index or interface name\n");
6837 if (file_name_set == 0) {
6838 errmsg ("missing socket file name\n");
6842 if (vec_len (file_name) > 255) {
6843 errmsg ("socket file name too long\n");
6846 vec_add1 (file_name, 0);
6848 M(MODIFY_VHOST_USER_IF, modify_vhost_user_if);
6850 mp->sw_if_index = ntohl(sw_if_index);
6851 mp->is_server = is_server;
6852 memcpy(mp->sock_filename, file_name, vec_len(file_name));
6853 vec_free(file_name);
6854 if (custom_dev_instance != ~0) {
6856 mp->custom_dev_instance = ntohl(custom_dev_instance);
6864 static int api_delete_vhost_user_if (vat_main_t * vam)
6866 unformat_input_t * i = vam->input;
6867 vl_api_delete_vhost_user_if_t *mp;
6869 u32 sw_if_index = ~0;
6870 u8 sw_if_index_set = 0;
6872 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
6873 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
6874 sw_if_index_set = 1;
6875 else if (unformat (i, "sw_if_index %d", &sw_if_index))
6876 sw_if_index_set = 1;
6881 if (sw_if_index_set == 0) {
6882 errmsg ("missing sw_if_index or interface name\n");
6887 M(DELETE_VHOST_USER_IF, delete_vhost_user_if);
6889 mp->sw_if_index = ntohl(sw_if_index);
6896 static void vl_api_sw_interface_vhost_user_details_t_handler
6897 (vl_api_sw_interface_vhost_user_details_t * mp)
6899 vat_main_t * vam = &vat_main;
6901 fformat(vam->ofp, "%-25s %3" PRIu32 " %6" PRIu32 " %8x %6d %7d %s\n",
6902 (char *)mp->interface_name,
6903 ntohl(mp->sw_if_index), ntohl(mp->virtio_net_hdr_sz),
6904 clib_net_to_host_u64(mp->features), mp->is_server,
6905 ntohl(mp->num_regions), (char *)mp->sock_filename);
6906 fformat(vam->ofp, " Status: '%s'\n", strerror(ntohl(mp->sock_errno)));
6909 static void vl_api_sw_interface_vhost_user_details_t_handler_json
6910 (vl_api_sw_interface_vhost_user_details_t * mp)
6912 vat_main_t * vam = &vat_main;
6913 vat_json_node_t *node = NULL;
6915 if (VAT_JSON_ARRAY != vam->json_tree.type) {
6916 ASSERT(VAT_JSON_NONE == vam->json_tree.type);
6917 vat_json_init_array(&vam->json_tree);
6919 node = vat_json_array_add(&vam->json_tree);
6921 vat_json_init_object(node);
6922 vat_json_object_add_uint(node, "sw_if_index", ntohl(mp->sw_if_index));
6923 vat_json_object_add_string_copy(node, "interface_name", mp->interface_name);
6924 vat_json_object_add_uint(node, "virtio_net_hdr_sz", ntohl(mp->virtio_net_hdr_sz));
6925 vat_json_object_add_uint(node, "features", clib_net_to_host_u64(mp->features));
6926 vat_json_object_add_uint(node, "is_server", mp->is_server);
6927 vat_json_object_add_string_copy(node, "sock_filename", mp->sock_filename);
6928 vat_json_object_add_uint(node, "num_regions", ntohl(mp->num_regions));
6929 vat_json_object_add_uint(node, "sock_errno", ntohl(mp->sock_errno));
6932 static int api_sw_interface_vhost_user_dump (vat_main_t * vam)
6934 vl_api_sw_interface_vhost_user_dump_t *mp;
6936 fformat(vam->ofp, "Interface name idx hdr_sz features server regions filename\n");
6938 /* Get list of vhost-user interfaces */
6939 M(SW_INTERFACE_VHOST_USER_DUMP, sw_interface_vhost_user_dump);
6942 /* Use a control ping for synchronization */
6944 vl_api_control_ping_t * mp;
6945 M(CONTROL_PING, control_ping);
6951 static int api_show_version (vat_main_t * vam)
6953 vl_api_show_version_t *mp;
6956 M(SHOW_VERSION, show_version);
6963 static uword unformat_nsh_gre_decap_next
6964 (unformat_input_t * input, va_list * args)
6966 u32 * result = va_arg (*args, u32 *);
6969 if (unformat (input, "drop"))
6970 *result = NSH_INPUT_NEXT_DROP;
6971 else if (unformat (input, "ip4"))
6972 *result = NSH_INPUT_NEXT_IP4_INPUT;
6973 else if (unformat (input, "ip6"))
6974 *result = NSH_INPUT_NEXT_IP6_INPUT;
6975 else if (unformat (input, "ethernet"))
6976 *result = NSH_INPUT_NEXT_ETHERNET_INPUT;
6977 else if (unformat (input, "%d", &tmp))
6984 static int api_nsh_gre_add_del_tunnel (vat_main_t * vam)
6986 unformat_input_t * line_input = vam->input;
6987 vl_api_nsh_gre_add_del_tunnel_t *mp;
6989 ip4_address_t src, dst;
6993 u32 encap_vrf_id = 0;
6994 u32 decap_vrf_id = 0;
6997 u8 next_protocol = 1; /* ip4 */
7008 u32 decap_next_index = NSH_INPUT_NEXT_IP4_INPUT;
7012 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) {
7013 if (unformat (line_input, "del"))
7015 else if (unformat (line_input, "src %U",
7016 unformat_ip4_address, &src))
7018 else if (unformat (line_input, "dst %U",
7019 unformat_ip4_address, &dst))
7021 else if (unformat (line_input, "encap-vrf-id %d", &encap_vrf_id))
7023 else if (unformat (line_input, "decap-vrf-id %d", &decap_vrf_id))
7025 else if (unformat (line_input, "decap-next %U",
7026 unformat_nsh_gre_decap_next, &decap_next_index))
7028 else if (unformat (line_input, "version %d", &tmp))
7029 ver_o_c |= (tmp & 3) << 6;
7030 else if (unformat (line_input, "o-bit %d", &tmp))
7031 ver_o_c |= (tmp & 1) << 5;
7032 else if (unformat (line_input, "c-bit %d", &tmp))
7033 ver_o_c |= (tmp & 1) << 4;
7034 else if (unformat (line_input, "md-type %d", &tmp))
7036 else if (unformat(line_input, "next-ip4"))
7038 else if (unformat(line_input, "next-ip6"))
7040 else if (unformat(line_input, "next-ethernet"))
7042 else if (unformat (line_input, "c1 %d", &c1))
7044 else if (unformat (line_input, "c2 %d", &c2))
7046 else if (unformat (line_input, "c3 %d", &c3))
7048 else if (unformat (line_input, "c4 %d", &c4))
7050 else if (unformat (line_input, "spi %d", &spi))
7052 else if (unformat (line_input, "si %d", &si))
7054 else if (unformat (line_input, "tlv %x"))
7055 vec_add1 (tlvs, tmp);
7057 errmsg ("parse error '%U'\n", format_unformat_error, line_input);
7063 errmsg ("tunnel src address not specified\n");
7067 errmsg ("tunnel dst address not specified\n");
7072 errmsg ("spi not specified\n");
7077 errmsg ("si not specified\n");
7081 M2 (NSH_GRE_ADD_DEL_TUNNEL, nsh_gre_add_del_tunnel,
7082 sizeof(u32) * vec_len (tlvs));
7084 spi_si = (spi<<8) | si;
7086 mp->src = src.as_u32;
7087 mp->dst = dst.as_u32;
7088 mp->encap_vrf_id = ntohl(encap_vrf_id);
7089 mp->decap_vrf_id = ntohl(decap_vrf_id);
7090 mp->decap_next_index = ntohl(decap_next_index);
7091 mp->tlv_len_in_words = vec_len (tlvs);
7092 mp->is_add = is_add;
7093 mp->ver_o_c = ver_o_c;
7094 mp->length = 6 + vec_len(tlvs);
7095 mp->md_type = md_type;
7096 mp->next_protocol = next_protocol;
7097 mp->spi_si = ntohl(spi_si);
7103 for (i = 0; i < vec_len(tlvs); i++)
7104 mp->tlvs[i] = ntohl(tlvs[i]);
7113 static uword unformat_nsh_vxlan_gpe_decap_next
7114 (unformat_input_t * input, va_list * args)
7116 u32 * result = va_arg (*args, u32 *);
7119 if (unformat (input, "drop"))
7120 *result = NSH_VXLAN_GPE_INPUT_NEXT_DROP;
7121 else if (unformat (input, "ip4"))
7122 *result = NSH_VXLAN_GPE_INPUT_NEXT_IP4_INPUT;
7123 else if (unformat (input, "ip6"))
7124 *result = NSH_VXLAN_GPE_INPUT_NEXT_IP6_INPUT;
7125 else if (unformat (input, "ethernet"))
7126 *result = NSH_VXLAN_GPE_INPUT_NEXT_ETHERNET_INPUT;
7127 else if (unformat (input, "nsh-vxlan-gpe"))
7128 *result = NSH_VXLAN_GPE_INPUT_NEXT_ETHERNET_INPUT;
7129 else if (unformat (input, "%d", &tmp))
7136 static int api_nsh_vxlan_gpe_add_del_tunnel (vat_main_t * vam)
7138 unformat_input_t * line_input = vam->input;
7139 vl_api_nsh_vxlan_gpe_add_del_tunnel_t *mp;
7141 ip4_address_t src, dst;
7145 u32 encap_vrf_id = 0;
7146 u32 decap_vrf_id = 0;
7149 u8 next_protocol = 1; /* ip4 */
7160 u32 decap_next_index = NSH_INPUT_NEXT_IP4_INPUT;
7166 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) {
7167 if (unformat (line_input, "del"))
7169 else if (unformat (line_input, "src %U",
7170 unformat_ip4_address, &src))
7172 else if (unformat (line_input, "dst %U",
7173 unformat_ip4_address, &dst))
7175 else if (unformat (line_input, "encap-vrf-id %d", &encap_vrf_id))
7177 else if (unformat (line_input, "decap-vrf-id %d", &decap_vrf_id))
7179 else if (unformat (line_input, "decap-next %U",
7180 unformat_nsh_vxlan_gpe_decap_next,
7183 else if (unformat (line_input, "vni %d", &vni))
7185 else if (unformat (line_input, "version %d", &tmp))
7186 ver_o_c |= (tmp & 3) << 6;
7187 else if (unformat (line_input, "o-bit %d", &tmp))
7188 ver_o_c |= (tmp & 1) << 5;
7189 else if (unformat (line_input, "c-bit %d", &tmp))
7190 ver_o_c |= (tmp & 1) << 4;
7191 else if (unformat (line_input, "md-type %d", &tmp))
7193 else if (unformat(line_input, "next-ip4"))
7195 else if (unformat(line_input, "next-ip6"))
7197 else if (unformat(line_input, "next-ethernet"))
7199 else if (unformat (line_input, "c1 %d", &c1))
7201 else if (unformat (line_input, "c2 %d", &c2))
7203 else if (unformat (line_input, "c3 %d", &c3))
7205 else if (unformat (line_input, "c4 %d", &c4))
7207 else if (unformat (line_input, "spi %d", &spi))
7209 else if (unformat (line_input, "si %d", &si))
7211 else if (unformat (line_input, "tlv %x"))
7212 vec_add1 (tlvs, tmp);
7214 errmsg ("parse error '%U'\n", format_unformat_error, line_input);
7220 errmsg ("tunnel src address not specified\n");
7224 errmsg ("tunnel dst address not specified\n");
7229 errmsg ("spi not specified\n");
7234 errmsg ("si not specified\n");
7238 errmsg ("vni not specified\n");
7242 M2 (NSH_VXLAN_GPE_ADD_DEL_TUNNEL, nsh_vxlan_gpe_add_del_tunnel,
7243 sizeof(u32) * vec_len (tlvs));
7245 spi_si = (spi<<8) | si;
7247 mp->src = src.as_u32;
7248 mp->dst = dst.as_u32;
7249 mp->encap_vrf_id = ntohl(encap_vrf_id);
7250 mp->decap_vrf_id = ntohl(decap_vrf_id);
7251 mp->decap_next_index = ntohl(decap_next_index);
7252 mp->tlv_len_in_words = vec_len (tlvs);
7253 mp->vni = ntohl(vni);
7254 mp->is_add = is_add;
7255 mp->ver_o_c = ver_o_c;
7256 mp->length = 6 + vec_len(tlvs);
7257 mp->md_type = md_type;
7258 mp->next_protocol = next_protocol;
7259 mp->spi_si = ntohl(spi_si);
7265 for (i = 0; i < vec_len(tlvs); i++)
7266 mp->tlvs[i] = ntohl(tlvs[i]);
7275 static uword unformat_lisp_gpe_decap_next (unformat_input_t * input,
7278 u32 * result = va_arg (*args, u32 *);
7281 if (unformat (input, "drop"))
7282 *result = LISP_GPE_INPUT_NEXT_DROP;
7283 else if (unformat (input, "ip4"))
7284 *result = LISP_GPE_INPUT_NEXT_IP4_INPUT;
7285 else if (unformat (input, "ip6"))
7286 *result = LISP_GPE_INPUT_NEXT_IP6_INPUT;
7287 else if (unformat (input, "ethernet"))
7288 *result = LISP_GPE_INPUT_NEXT_IP6_INPUT;
7289 else if (unformat (input, "lisp-gpe"))
7290 *result = LISP_GPE_INPUT_NEXT_LISP_GPE_ENCAP;
7291 else if (unformat (input, "%d", &tmp))
7299 api_lisp_gpe_add_del_tunnel (vat_main_t * vam)
7301 unformat_input_t * line_input = vam->input;
7302 vl_api_lisp_gpe_add_del_tunnel_t *mp;
7304 ip4_address_t src, dst;
7308 u32 encap_vrf_id = 0;
7309 u32 decap_vrf_id = 0;
7310 u8 next_protocol = LISP_GPE_NEXT_PROTOCOL_IP4;
7311 u32 decap_next_index = LISP_GPE_INPUT_NEXT_IP4_INPUT;
7312 u8 flags = LISP_GPE_FLAGS_P;
7319 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) {
7320 if (unformat (line_input, "del"))
7322 else if (unformat (line_input, "src %U",
7323 unformat_ip4_address, &src))
7325 else if (unformat (line_input, "dst %U",
7326 unformat_ip4_address, &dst))
7328 else if (unformat (line_input, "encap-vrf-id %d", &encap_vrf_id))
7330 else if (unformat (line_input, "decap-vrf-id %d", &decap_vrf_id))
7332 else if (unformat (line_input, "decap-next %U",
7333 unformat_lisp_gpe_decap_next,
7336 else if (unformat(line_input, "next-ip4"))
7338 else if (unformat(line_input, "next-ip6"))
7340 else if (unformat(line_input, "next-ethernet"))
7342 else if (unformat(line_input, "next-nsh"))
7344 /* Allow the user to specify anything they want in the LISP hdr */
7345 else if (unformat (line_input, "ver_res %x", &tmp))
7347 else if (unformat (line_input, "res %x", &tmp))
7349 else if (unformat (line_input, "flags %x", &tmp))
7351 else if (unformat (line_input, "n-bit"))
7352 flags |= LISP_GPE_FLAGS_N;
7353 else if (unformat (line_input, "l-bit"))
7354 flags |= LISP_GPE_FLAGS_L;
7355 else if (unformat (line_input, "e-bit"))
7356 flags |= LISP_GPE_FLAGS_E;
7357 else if (unformat (line_input, "v-bit"))
7358 flags |= LISP_GPE_FLAGS_V;
7359 else if (unformat (line_input, "i-bit"))
7360 flags |= LISP_GPE_FLAGS_V;
7361 else if (unformat (line_input, "not-p-bit"))
7362 flags &= !LISP_GPE_FLAGS_P;
7363 else if (unformat (line_input, "p-bit"))
7364 flags |= LISP_GPE_FLAGS_P;
7365 else if (unformat (line_input, "o-bit"))
7366 flags |= LISP_GPE_FLAGS_O;
7367 else if (unformat (line_input, "iidx %x", &iid))
7369 else if (unformat (line_input, "iid %d", &iid))
7372 errmsg ("parse error '%U'\n", format_unformat_error, line_input);
7378 errmsg ("tunnel src address not specified\n");
7382 errmsg ("tunnel dst address not specified\n");
7386 errmsg ("iid not specified\n");
7390 M(LISP_GPE_ADD_DEL_TUNNEL, lisp_gpe_add_del_tunnel);
7392 mp->src = src.as_u32;
7393 mp->dst = dst.as_u32;
7394 mp->encap_vrf_id = ntohl(encap_vrf_id);
7395 mp->decap_vrf_id = ntohl(decap_vrf_id);
7396 mp->decap_next_index = ntohl(decap_next_index);
7397 mp->is_add = is_add;
7399 mp->ver_res = ver_res;
7401 mp->next_protocol = next_protocol;
7402 mp->iid = ntohl(iid);
7411 u8 * format_l2_fib_mac_address (u8 * s, va_list * args)
7413 u8 * a = va_arg (*args, u8 *);
7415 return format (s, "%02x:%02x:%02x:%02x:%02x:%02x",
7416 a[2], a[3], a[4], a[5], a[6], a[7]);
7419 static void vl_api_l2_fib_table_entry_t_handler
7420 (vl_api_l2_fib_table_entry_t * mp)
7422 vat_main_t * vam = &vat_main;
7424 fformat(vam->ofp, "%3" PRIu32 " %U %3" PRIu32
7426 ntohl(mp->bd_id), format_l2_fib_mac_address, &mp->mac,
7427 ntohl(mp->sw_if_index), mp->static_mac, mp->filter_mac,
7431 static void vl_api_l2_fib_table_entry_t_handler_json
7432 (vl_api_l2_fib_table_entry_t * mp)
7434 vat_main_t * vam = &vat_main;
7435 vat_json_node_t *node = NULL;
7437 if (VAT_JSON_ARRAY != vam->json_tree.type) {
7438 ASSERT(VAT_JSON_NONE == vam->json_tree.type);
7439 vat_json_init_array(&vam->json_tree);
7441 node = vat_json_array_add(&vam->json_tree);
7443 vat_json_init_object(node);
7444 vat_json_object_add_uint(node, "bd_id", ntohl(mp->bd_id));
7445 vat_json_object_add_uint(node, "mac", clib_net_to_host_u64(mp->mac));
7446 vat_json_object_add_uint(node, "sw_if_index", ntohl(mp->sw_if_index));
7447 vat_json_object_add_uint(node, "static_mac", mp->static_mac);
7448 vat_json_object_add_uint(node, "filter_mac", mp->filter_mac);
7449 vat_json_object_add_uint(node, "bvi_mac", mp->bvi_mac);
7452 static int api_l2_fib_table_dump (vat_main_t * vam)
7454 unformat_input_t * i = vam->input;
7455 vl_api_l2_fib_table_dump_t *mp;
7460 /* Parse args required to build the message */
7461 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
7462 if (unformat (i, "bd_id %d", &bd_id))
7468 if (bd_id_set == 0) {
7469 errmsg ("missing bridge domain\n");
7473 fformat(vam->ofp, "BD-ID Mac Address sw-ndx Static Filter BVI\n");
7475 /* Get list of l2 fib entries */
7476 M(L2_FIB_TABLE_DUMP, l2_fib_table_dump);
7478 mp->bd_id = ntohl(bd_id);
7481 /* Use a control ping for synchronization */
7483 vl_api_control_ping_t * mp;
7484 M(CONTROL_PING, control_ping);
7492 api_interface_name_renumber (vat_main_t * vam)
7494 unformat_input_t * line_input = vam->input;
7495 vl_api_interface_name_renumber_t *mp;
7496 u32 sw_if_index = ~0;
7498 u32 new_show_dev_instance = ~0;
7500 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) {
7501 if (unformat (line_input, "%U", unformat_sw_if_index, vam,
7504 else if (unformat (line_input, "sw_if_index %d", &sw_if_index))
7506 else if (unformat (line_input, "new_show_dev_instance %d",
7507 &new_show_dev_instance))
7513 if (sw_if_index == ~0) {
7514 errmsg ("missing interface name or sw_if_index\n");
7518 if (new_show_dev_instance == ~0) {
7519 errmsg ("missing new_show_dev_instance\n");
7523 M(INTERFACE_NAME_RENUMBER, interface_name_renumber);
7525 mp->sw_if_index = ntohl (sw_if_index);
7526 mp->new_show_dev_instance = ntohl (new_show_dev_instance);
7532 api_want_ip4_arp_events (vat_main_t * vam)
7534 unformat_input_t * line_input = vam->input;
7535 vl_api_want_ip4_arp_events_t * mp;
7537 ip4_address_t address;
7538 int address_set = 0;
7539 u32 enable_disable = 1;
7541 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) {
7542 if (unformat (line_input, "address %U",
7543 unformat_ip4_address, &address))
7545 else if (unformat (line_input, "del"))
7551 if (address_set == 0) {
7552 errmsg ("missing addresses\n");
7556 M(WANT_IP4_ARP_EVENTS, want_ip4_arp_events);
7557 mp->enable_disable = enable_disable;
7559 mp->address = address.as_u32;
7564 static int api_input_acl_set_interface (vat_main_t * vam)
7566 unformat_input_t * i = vam->input;
7567 vl_api_input_acl_set_interface_t *mp;
7570 int sw_if_index_set;
7571 u32 ip4_table_index = ~0;
7572 u32 ip6_table_index = ~0;
7573 u32 l2_table_index = ~0;
7576 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
7577 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
7578 sw_if_index_set = 1;
7579 else if (unformat (i, "sw_if_index %d", &sw_if_index))
7580 sw_if_index_set = 1;
7581 else if (unformat (i, "del"))
7583 else if (unformat (i, "ip4-table %d", &ip4_table_index))
7585 else if (unformat (i, "ip6-table %d", &ip6_table_index))
7587 else if (unformat (i, "l2-table %d", &l2_table_index))
7590 clib_warning ("parse error '%U'", format_unformat_error, i);
7595 if (sw_if_index_set == 0) {
7596 errmsg ("missing interface name or sw_if_index\n");
7600 M(INPUT_ACL_SET_INTERFACE, input_acl_set_interface);
7602 mp->sw_if_index = ntohl(sw_if_index);
7603 mp->ip4_table_index = ntohl(ip4_table_index);
7604 mp->ip6_table_index = ntohl(ip6_table_index);
7605 mp->l2_table_index = ntohl(l2_table_index);
7606 mp->is_add = is_add;
7614 api_ip_address_dump (vat_main_t * vam)
7616 unformat_input_t * i = vam->input;
7617 vl_api_ip_address_dump_t * mp;
7618 u32 sw_if_index = ~0;
7619 u8 sw_if_index_set = 0;
7624 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
7625 if (unformat (i, "sw_if_index %d", &sw_if_index))
7626 sw_if_index_set = 1;
7627 else if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
7628 sw_if_index_set = 1;
7629 else if (unformat (i, "ipv4"))
7631 else if (unformat (i, "ipv6"))
7637 if (ipv4_set && ipv6_set) {
7638 errmsg ("ipv4 and ipv6 flags cannot be both set\n");
7642 if ((!ipv4_set) && (!ipv6_set)) {
7643 errmsg ("no ipv4 nor ipv6 flag set\n");
7647 if (sw_if_index_set == 0) {
7648 errmsg ("missing interface name or sw_if_index\n");
7652 vam->current_sw_if_index = sw_if_index;
7653 vam->is_ipv6 = ipv6_set;
7655 M(IP_ADDRESS_DUMP, ip_address_dump);
7656 mp->sw_if_index = ntohl(sw_if_index);
7657 mp->is_ipv6 = ipv6_set;
7660 /* Use a control ping for synchronization */
7662 vl_api_control_ping_t * mp;
7663 M(CONTROL_PING, control_ping);
7670 api_ip_dump (vat_main_t * vam)
7672 vl_api_ip_dump_t * mp;
7673 unformat_input_t * in = vam->input;
7680 while (unformat_check_input (in) != UNFORMAT_END_OF_INPUT) {
7681 if (unformat (in, "ipv4"))
7683 else if (unformat (in, "ipv6"))
7689 if (ipv4_set && ipv6_set) {
7690 errmsg ("ipv4 and ipv6 flags cannot be both set\n");
7694 if ((!ipv4_set) && (!ipv6_set)) {
7695 errmsg ("no ipv4 nor ipv6 flag set\n");
7700 vam->is_ipv6 = is_ipv6;
7703 for (i = 0; i < vec_len(vam->ip_details_by_sw_if_index[is_ipv6]); i++) {
7704 vec_free(vam->ip_details_by_sw_if_index[is_ipv6][i].addr);
7706 vec_free(vam->ip_details_by_sw_if_index[is_ipv6]);
7708 M(IP_DUMP, ip_dump);
7709 mp->is_ipv6 = ipv6_set;
7712 /* Use a control ping for synchronization */
7714 vl_api_control_ping_t * mp;
7715 M(CONTROL_PING, control_ping);
7722 api_ipsec_spd_add_del (vat_main_t * vam)
7724 unformat_input_t * i = vam->input;
7725 vl_api_ipsec_spd_add_del_t *mp;
7730 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
7731 if (unformat (i, "spd_id %d", &spd_id))
7733 else if (unformat (i, "del"))
7736 clib_warning ("parse error '%U'", format_unformat_error, i);
7741 errmsg ("spd_id must be set\n");
7745 M(IPSEC_SPD_ADD_DEL, ipsec_spd_add_del);
7747 mp->spd_id = ntohl(spd_id);
7748 mp->is_add = is_add;
7756 api_ipsec_interface_add_del_spd (vat_main_t * vam)
7758 unformat_input_t * i = vam->input;
7759 vl_api_ipsec_interface_add_del_spd_t *mp;
7762 u8 sw_if_index_set = 0;
7763 u32 spd_id = (u32) ~0;
7766 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
7767 if (unformat (i, "del"))
7769 else if (unformat (i, "spd_id %d", &spd_id))
7771 else if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
7772 sw_if_index_set = 1;
7773 else if (unformat (i, "sw_if_index %d", &sw_if_index))
7774 sw_if_index_set = 1;
7776 clib_warning ("parse error '%U'", format_unformat_error, i);
7782 if (spd_id == (u32) ~0) {
7783 errmsg ("spd_id must be set\n");
7787 if (sw_if_index_set == 0) {
7788 errmsg ("missing interface name or sw_if_index\n");
7792 M(IPSEC_INTERFACE_ADD_DEL_SPD, ipsec_interface_add_del_spd);
7794 mp->spd_id = ntohl(spd_id);
7795 mp->sw_if_index = ntohl (sw_if_index);
7796 mp->is_add = is_add;
7804 api_ipsec_spd_add_del_entry (vat_main_t * vam)
7806 unformat_input_t * i = vam->input;
7807 vl_api_ipsec_spd_add_del_entry_t *mp;
7809 u8 is_add = 1, is_outbound = 0, is_ipv6 = 0, is_ip_any = 1;
7810 u32 spd_id, sa_id, protocol = 0, policy = 0;
7812 u32 rport_start = 0, rport_stop = (u32) ~0;
7813 u32 lport_start = 0, lport_stop = (u32) ~0;
7814 ip4_address_t laddr4_start, laddr4_stop, raddr4_start, raddr4_stop;
7815 ip6_address_t laddr6_start, laddr6_stop, raddr6_start, raddr6_stop;
7817 laddr4_start.as_u32 = raddr4_start.as_u32 = 0;
7818 laddr4_stop.as_u32 = raddr4_stop.as_u32 = (u32) ~0;
7819 laddr6_start.as_u64[0] = raddr6_start.as_u64[0] = 0;
7820 laddr6_start.as_u64[1] = raddr6_start.as_u64[1] = 0;
7821 laddr6_stop.as_u64[0] = raddr6_stop.as_u64[0] = (u64) ~0;
7822 laddr6_stop.as_u64[1] = raddr6_stop.as_u64[1] = (u64) ~0;
7824 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
7825 if (unformat (i, "del"))
7827 if (unformat (i, "outbound"))
7829 if (unformat (i, "inbound"))
7831 else if (unformat (i, "spd_id %d", &spd_id))
7833 else if (unformat (i, "sa_id %d", &sa_id))
7835 else if (unformat (i, "priority %d", &priority))
7837 else if (unformat (i, "protocol %d", &protocol))
7839 else if (unformat (i, "lport_start %d", &lport_start))
7841 else if (unformat (i, "lport_stop %d", &lport_stop))
7843 else if (unformat (i, "rport_start %d", &rport_start))
7845 else if (unformat (i, "rport_stop %d", &rport_stop))
7847 else if (unformat (i, "laddr_start %U", unformat_ip4_address, &laddr4_start))
7852 else if (unformat (i, "laddr_stop %U", unformat_ip4_address, &laddr4_stop))
7857 else if (unformat (i, "raddr_start %U", unformat_ip4_address, &raddr4_start))
7862 else if (unformat (i, "raddr_stop %U", unformat_ip4_address, &raddr4_stop))
7867 else if (unformat (i, "laddr_start %U", unformat_ip6_address, &laddr6_start))
7872 else if (unformat (i, "laddr_stop %U", unformat_ip6_address, &laddr6_stop))
7877 else if (unformat (i, "raddr_start %U", unformat_ip6_address, &raddr6_start))
7882 else if (unformat (i, "raddr_stop %U", unformat_ip6_address, &raddr6_stop))
7887 else if (unformat (i, "action %U", unformat_ipsec_policy_action, &policy))
7889 if (policy == IPSEC_POLICY_ACTION_RESOLVE) {
7890 clib_warning ("unsupported action: 'resolve'");
7895 clib_warning ("parse error '%U'", format_unformat_error, i);
7901 M(IPSEC_SPD_ADD_DEL_ENTRY, ipsec_spd_add_del_entry);
7903 mp->spd_id = ntohl(spd_id);
7904 mp->priority = ntohl(priority);
7905 mp->is_outbound = is_outbound;
7907 mp->is_ipv6 = is_ipv6;
7908 if (is_ipv6 || is_ip_any) {
7909 memcpy (mp->remote_address_start, &raddr6_start, sizeof(ip6_address_t));
7910 memcpy (mp->remote_address_stop, &raddr6_stop, sizeof(ip6_address_t));
7911 memcpy (mp->local_address_start, &laddr6_start, sizeof(ip6_address_t));
7912 memcpy (mp->local_address_stop, &laddr6_stop, sizeof(ip6_address_t));
7914 memcpy (mp->remote_address_start, &raddr4_start, sizeof(ip4_address_t));
7915 memcpy (mp->remote_address_stop, &raddr4_stop, sizeof(ip4_address_t));
7916 memcpy (mp->local_address_start, &laddr4_start, sizeof(ip4_address_t));
7917 memcpy (mp->local_address_stop, &laddr4_stop, sizeof(ip4_address_t));
7919 mp->protocol = (u8) protocol;
7920 mp->local_port_start = ntohs((u16) lport_start);
7921 mp->local_port_stop = ntohs((u16) lport_stop);
7922 mp->remote_port_start = ntohs((u16) rport_start);
7923 mp->remote_port_stop = ntohs((u16) rport_stop);
7924 mp->policy = (u8) policy;
7925 mp->sa_id = ntohl(sa_id);
7926 mp->is_add = is_add;
7927 mp->is_ip_any = is_ip_any;
7934 api_ipsec_sad_add_del_entry (vat_main_t * vam)
7936 unformat_input_t * i = vam->input;
7937 vl_api_ipsec_sad_add_del_entry_t *mp;
7943 u8 protocol = IPSEC_PROTOCOL_AH;
7944 u8 is_tunnel = 0, is_tunnel_ipv6 = 0;
7945 u32 crypto_alg = 0, integ_alg = 0;
7946 ip4_address_t tun_src4;
7947 ip4_address_t tun_dst4;
7948 ip6_address_t tun_src6;
7949 ip6_address_t tun_dst6;
7951 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
7952 if (unformat (i, "del"))
7954 else if (unformat (i, "sad_id %d", &sad_id))
7956 else if (unformat (i, "spi %d", &spi))
7958 else if (unformat (i, "esp"))
7959 protocol = IPSEC_PROTOCOL_ESP;
7960 else if (unformat (i, "tunnel_src %U", unformat_ip4_address, &tun_src4)) {
7964 else if (unformat (i, "tunnel_dst %U", unformat_ip4_address, &tun_dst4)) {
7968 else if (unformat (i, "tunnel_src %U", unformat_ip6_address, &tun_src6)) {
7972 else if (unformat (i, "tunnel_dst %U", unformat_ip6_address, &tun_dst6)) {
7976 else if (unformat (i, "crypto_alg %U", unformat_ipsec_crypto_alg, &crypto_alg)) {
7977 if (crypto_alg < IPSEC_CRYPTO_ALG_AES_CBC_128 ||
7978 crypto_alg > IPSEC_INTEG_ALG_SHA_512_256) {
7979 clib_warning ("unsupported crypto-alg: '%U'",
7980 format_ipsec_crypto_alg, crypto_alg);
7984 else if (unformat (i, "crypto_key %U", unformat_hex_string, &ck))
7986 else if (unformat (i, "integ_alg %U", unformat_ipsec_integ_alg, &integ_alg)) {
7987 if (integ_alg < IPSEC_INTEG_ALG_SHA1_96 ||
7988 integ_alg > IPSEC_INTEG_ALG_SHA_512_256) {
7989 clib_warning ("unsupported integ-alg: '%U'",
7990 format_ipsec_integ_alg, integ_alg);
7994 else if (unformat (i, "integ_key %U", unformat_hex_string, &ik))
7997 clib_warning ("parse error '%U'", format_unformat_error, i);
8003 M(IPSEC_SAD_ADD_DEL_ENTRY, ipsec_sad_add_del_entry);
8005 mp->sad_id = ntohl(sad_id);
8006 mp->is_add = is_add;
8007 mp->protocol = protocol;
8008 mp->spi = ntohl(spi);
8009 mp->is_tunnel = is_tunnel;
8010 mp->is_tunnel_ipv6 = is_tunnel_ipv6;
8011 mp->crypto_algorithm = crypto_alg;
8012 mp->integrity_algorithm = integ_alg;
8013 mp->crypto_key_length = vec_len(ck);
8014 mp->integrity_key_length = vec_len(ik);
8016 if (mp->crypto_key_length > sizeof(mp->crypto_key))
8017 mp->crypto_key_length = sizeof(mp->crypto_key);
8019 if (mp->integrity_key_length > sizeof(mp->integrity_key))
8020 mp->integrity_key_length = sizeof(mp->integrity_key);
8022 memcpy (mp->crypto_key, ck, mp->crypto_key_length);
8023 memcpy (mp->integrity_key, ik, mp->integrity_key_length);
8026 if (is_tunnel_ipv6) {
8027 memcpy (mp->tunnel_src_address, &tun_src6, sizeof(ip6_address_t));
8028 memcpy (mp->tunnel_dst_address, &tun_dst6, sizeof(ip6_address_t));
8030 memcpy (mp->tunnel_src_address, &tun_src4, sizeof(ip4_address_t));
8031 memcpy (mp->tunnel_dst_address, &tun_dst4, sizeof(ip4_address_t));
8041 api_ipsec_sa_set_key (vat_main_t * vam)
8043 unformat_input_t * i = vam->input;
8044 vl_api_ipsec_sa_set_key_t *mp;
8049 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
8050 if (unformat (i, "sa_id %d", &sa_id))
8052 else if (unformat (i, "crypto_key %U", unformat_hex_string, &ck))
8054 else if (unformat (i, "integ_key %U", unformat_hex_string, &ik))
8057 clib_warning ("parse error '%U'", format_unformat_error, i);
8062 M(IPSEC_SA_SET_KEY, ipsec_set_sa_key);
8064 mp->sa_id = ntohl(sa_id);
8065 mp->crypto_key_length = vec_len(ck);
8066 mp->integrity_key_length = vec_len(ik);
8068 if (mp->crypto_key_length > sizeof(mp->crypto_key))
8069 mp->crypto_key_length = sizeof(mp->crypto_key);
8071 if (mp->integrity_key_length > sizeof(mp->integrity_key))
8072 mp->integrity_key_length = sizeof(mp->integrity_key);
8074 memcpy (mp->crypto_key, ck, mp->crypto_key_length);
8075 memcpy (mp->integrity_key, ik, mp->integrity_key_length);
8085 static int api_map_add_domain (vat_main_t * vam)
8087 unformat_input_t *i = vam->input;
8088 vl_api_map_add_domain_t *mp;
8091 ip4_address_t ip4_prefix;
8092 ip6_address_t ip6_prefix;
8093 ip6_address_t ip6_src;
8095 u32 ip6_prefix_len, ip4_prefix_len, ea_bits_len, psid_offset,
8097 u8 is_translation = 0;
8099 u8 ip6_src_len = 128;
8101 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
8102 if (unformat (i, "ip4-pfx %U/%d", unformat_ip4_address,
8103 &ip4_prefix, &ip4_prefix_len))
8105 else if (unformat (i, "ip6-pfx %U/%d", unformat_ip6_address,
8106 &ip6_prefix, &ip6_prefix_len))
8108 else if (unformat (i, "ip6-src %U/%d", unformat_ip6_address, &ip6_src, &ip6_src_len))
8110 else if (unformat (i, "ip6-src %U", unformat_ip6_address, &ip6_src))
8112 else if (unformat (i, "ea-bits-len %d", &ea_bits_len))
8114 else if (unformat (i, "psid-offset %d", &psid_offset))
8116 else if (unformat (i, "psid-len %d", &psid_length))
8118 else if (unformat (i, "mtu %d", &mtu))
8120 else if (unformat (i, "map-t"))
8123 clib_warning ("parse error '%U'", format_unformat_error, i);
8128 if (num_m_args != 6) {
8129 errmsg("mandatory argument(s) missing\n");
8133 /* Construct the API message */
8134 M(MAP_ADD_DOMAIN, map_add_domain);
8136 memcpy(mp->ip4_prefix, &ip4_prefix, sizeof(ip4_prefix));
8137 mp->ip4_prefix_len = ip4_prefix_len;
8139 memcpy(mp->ip6_prefix, &ip6_prefix, sizeof(ip6_prefix));
8140 mp->ip6_prefix_len = ip6_prefix_len;
8142 memcpy(mp->ip6_src, &ip6_src, sizeof(ip6_src));
8143 mp->ip6_src_prefix_len = ip6_src_len;
8145 mp->ea_bits_len = ea_bits_len;
8146 mp->psid_offset = psid_offset;
8147 mp->psid_length = psid_length;
8148 mp->is_translation = is_translation;
8149 mp->mtu = htons(mtu);
8154 /* Wait for a reply, return good/bad news */
8158 static int api_map_del_domain (vat_main_t * vam)
8160 unformat_input_t *i = vam->input;
8161 vl_api_map_del_domain_t *mp;
8167 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
8168 if (unformat (i, "index %d", &index))
8171 clib_warning ("parse error '%U'", format_unformat_error, i);
8176 if (num_m_args != 1) {
8177 errmsg("mandatory argument(s) missing\n");
8181 /* Construct the API message */
8182 M(MAP_DEL_DOMAIN, map_del_domain);
8184 mp->index = ntohl(index);
8189 /* Wait for a reply, return good/bad news */
8193 static int api_map_add_del_rule (vat_main_t * vam)
8195 unformat_input_t *i = vam->input;
8196 vl_api_map_add_del_rule_t *mp;
8199 ip6_address_t ip6_dst;
8200 u32 num_m_args = 0, index, psid;
8202 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
8203 if (unformat (i, "index %d", &index))
8205 else if (unformat (i, "psid %d", &psid))
8207 else if (unformat (i, "dst %U", unformat_ip6_address, &ip6_dst))
8209 else if (unformat (i, "del")) {
8212 clib_warning ("parse error '%U'", format_unformat_error, i);
8217 /* Construct the API message */
8218 M(MAP_ADD_DEL_RULE, map_add_del_rule);
8220 mp->index = ntohl(index);
8221 mp->is_add = is_add;
8222 memcpy(mp->ip6_dst, &ip6_dst, sizeof(ip6_dst));
8223 mp->psid = ntohs(psid);
8228 /* Wait for a reply, return good/bad news */
8232 static int api_map_domain_dump (vat_main_t * vam)
8234 vl_api_map_domain_dump_t *mp;
8237 /* Construct the API message */
8238 M(MAP_DOMAIN_DUMP, map_domain_dump);
8243 /* Use a control ping for synchronization */
8245 vl_api_control_ping_t * mp;
8246 M(CONTROL_PING, control_ping);
8252 static int api_map_rule_dump (vat_main_t * vam)
8254 unformat_input_t *i = vam->input;
8255 vl_api_map_rule_dump_t *mp;
8257 u32 domain_index = ~0;
8259 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
8260 if (unformat (i, "index %u", &domain_index))
8266 if (domain_index == ~0) {
8267 clib_warning("parse error: domain index expected");
8271 /* Construct the API message */
8272 M(MAP_RULE_DUMP, map_rule_dump);
8274 mp->domain_index = htonl(domain_index);
8279 /* Use a control ping for synchronization */
8281 vl_api_control_ping_t * mp;
8282 M(CONTROL_PING, control_ping);
8288 static void vl_api_map_add_domain_reply_t_handler
8289 (vl_api_map_add_domain_reply_t * mp)
8291 vat_main_t * vam = &vat_main;
8292 i32 retval = ntohl(mp->retval);
8294 if (vam->async_mode) {
8295 vam->async_errors += (retval < 0);
8297 vam->retval = retval;
8298 vam->result_ready = 1;
8302 static void vl_api_map_add_domain_reply_t_handler_json
8303 (vl_api_map_add_domain_reply_t * mp)
8305 vat_main_t * vam = &vat_main;
8306 vat_json_node_t node;
8308 vat_json_init_object(&node);
8309 vat_json_object_add_int(&node, "retval", ntohl(mp->retval));
8310 vat_json_object_add_uint(&node, "index", ntohl(mp->index));
8312 vat_json_print(vam->ofp, &node);
8313 vat_json_free(&node);
8315 vam->retval = ntohl(mp->retval);
8316 vam->result_ready = 1;
8320 api_get_first_msg_id (vat_main_t * vam)
8322 vl_api_get_first_msg_id_t * mp;
8324 unformat_input_t * i = vam->input;
8328 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
8329 if (unformat (i, "client %s", &name))
8335 if (name_set == 0) {
8336 errmsg ("missing client name\n");
8341 if (vec_len (name) > 63) {
8342 errmsg ("client name too long\n");
8346 M(GET_FIRST_MSG_ID, get_first_msg_id);
8347 memcpy (mp->name, name, vec_len(name));
8353 static int q_or_quit (vat_main_t * vam)
8355 longjmp (vam->jump_buf, 1);
8356 return 0; /* not so much */
8358 static int q (vat_main_t * vam) {return q_or_quit (vam);}
8359 static int quit (vat_main_t * vam) {return q_or_quit (vam);}
8361 static int comment (vat_main_t * vam)
8366 static int cmd_cmp (void * a1, void * a2)
8371 return strcmp ((char *)(c1[0]), (char *)(c2[0]));
8374 static int help (vat_main_t * vam)
8379 unformat_input_t * i = vam->input;
8382 if (unformat (i, "%s", &name)) {
8387 hs = hash_get_mem (vam->help_by_name, name);
8389 fformat (vam->ofp, "usage: %s %s\n", name, hs[0]);
8391 fformat (vam->ofp, "No such msg / command '%s'\n", name);
8396 fformat(vam->ofp, "Help is available for the following:\n");
8398 hash_foreach_pair (p, vam->function_by_name,
8400 vec_add1 (cmds, (u8 *)(p->key));
8403 vec_sort_with_function (cmds, cmd_cmp);
8405 for (j = 0; j < vec_len(cmds); j++)
8406 fformat (vam->ofp, "%s\n", cmds[j]);
8412 static int set (vat_main_t * vam)
8414 u8 * name = 0, * value = 0;
8415 unformat_input_t * i = vam->input;
8417 if (unformat (i, "%s", &name)) {
8418 /* The input buffer is a vector, not a string. */
8419 value = vec_dup (i->buffer);
8420 vec_delete (value, i->index, 0);
8421 /* Almost certainly has a trailing newline */
8422 if (value[vec_len(value)-1] == '\n')
8423 value[vec_len(value)-1] = 0;
8424 /* Make sure it's a proper string, one way or the other */
8425 vec_add1 (value, 0);
8426 (void) clib_macro_set_value (&vam->macro_main,
8427 (char *)name, (char *)value);
8430 errmsg ("usage: set <name> <value>\n");
8437 static int unset (vat_main_t * vam)
8441 if (unformat (vam->input, "%s", &name))
8442 if (clib_macro_unset (&vam->macro_main, (char *)name) == 1)
8443 errmsg ("unset: %s wasn't set\n", name);
8454 static int macro_sort_cmp (void * a1, void * a2)
8456 macro_sort_t * s1 = a1;
8457 macro_sort_t * s2 = a2;
8459 return strcmp ((char *)(s1->name), (char *)(s2->name));
8462 static int dump_macro_table (vat_main_t * vam)
8464 macro_sort_t * sort_me = 0, * sm;
8468 hash_foreach_pair (p, vam->macro_main.the_value_table_hash,
8470 vec_add2 (sort_me, sm, 1);
8471 sm->name = (u8 *)(p->key);
8472 sm->value = (u8 *) (p->value[0]);
8475 vec_sort_with_function (sort_me, macro_sort_cmp);
8477 if (vec_len(sort_me))
8478 fformat (vam->ofp, "%-15s%s\n", "Name", "Value");
8480 fformat (vam->ofp, "The macro table is empty...\n");
8482 for (i = 0; i < vec_len (sort_me); i++)
8483 fformat (vam->ofp, "%-15s%s\n", sort_me[i].name,
8488 static int script (vat_main_t * vam)
8491 char * save_current_file;
8492 unformat_input_t save_input;
8493 jmp_buf save_jump_buf;
8494 u32 save_line_number;
8496 FILE * new_fp, * save_ifp;
8498 if (unformat (vam->input, "%s", &s)) {
8499 new_fp = fopen ((char *)s, "r");
8501 errmsg ("Couldn't open script file %s\n", s);
8506 errmsg ("Missing script name\n");
8510 memcpy (&save_input, &vam->input, sizeof (save_input));
8511 memcpy (&save_jump_buf, &vam->jump_buf, sizeof (save_jump_buf));
8512 save_ifp = vam->ifp;
8513 save_line_number = vam->input_line_number;
8514 save_current_file = (char *) vam->current_file;
8516 vam->input_line_number = 0;
8518 vam->current_file = s;
8521 memcpy (&vam->input, &save_input, sizeof (vam->input));
8522 memcpy (&vam->jump_buf, &save_jump_buf, sizeof (save_jump_buf));
8523 vam->ifp = save_ifp;
8524 vam->input_line_number = save_line_number;
8525 vam->current_file = (u8 *) save_current_file;
8531 static int echo (vat_main_t * vam)
8533 fformat (vam->ofp, "%v", vam->input->buffer);
8537 /* List of API message constructors, CLI names map to api_xxx */
8538 #define foreach_vpe_api_msg \
8539 _(create_loopback,"[mac <mac-addr>]") \
8540 _(sw_interface_dump,"") \
8541 _(sw_interface_set_flags, \
8542 "<intfc> | sw_if_index <id> admin-up | admin-down link-up | link down") \
8543 _(sw_interface_add_del_address, \
8544 "<intfc> | sw_if_index <id> <ip4-address> | <ip6-address> [del] [del-all] ") \
8545 _(sw_interface_set_table, \
8546 "<intfc> | sw_if_index <id> vrf <table-id> [ipv6]") \
8547 _(sw_interface_set_vpath, \
8548 "<intfc> | sw_if_index <id> enable | disable") \
8549 _(sw_interface_set_l2_xconnect, \
8550 "rx <intfc> | rx_sw_if_index <id> tx <intfc> | tx_sw_if_index <id>\n" \
8551 "enable | disable") \
8552 _(sw_interface_set_l2_bridge, \
8553 "rx <intfc> | rx_sw_if_index <id> bd_id <bridge-domain-id>\n" \
8554 "[shg <split-horizon-group>] [bvi]\n" \
8555 "enable | disable") \
8556 _(bridge_domain_add_del, \
8557 "bd_id <bridge-domain-id> [flood 1|0] [uu-flood 1|0] [forward 1|0] [learn 1|0] [arp-term 1|0] [del]\n")\
8558 _(bridge_domain_dump, "[bd_id <bridge-domain-id>]\n") \
8560 "mac <mac-addr> bd_id <bridge-domain-id> [del] | sw_if <intfc> | sw_if_index <id> [static] [filter] [bvi]\n") \
8562 "sw_if <intfc> | sw_if_index <id> [learn] [forward] [uu-flood] [flood]\n") \
8564 "bd_id <bridge-domain-id> [learn] [forward] [uu-flood] [flood] [arp-term] [disable]\n") \
8566 "tapname <name> mac <mac-addr> | random-mac") \
8568 "<vpp-if-name> | sw_if_index <id> tapname <name> mac <mac-addr> | random-mac") \
8570 "<vpp-if-name> | sw_if_index <id>") \
8571 _(sw_interface_tap_dump, "") \
8572 _(ip_add_del_route, \
8573 "<addr>/<mask> via <addr> [vrf <n>]\n" \
8574 "[<intfc> | sw_if_index <id>] [resolve-attempts <n>]\n" \
8575 "[weight <n>] [drop] [local] [classify <n>] [del]\n" \
8576 "[multipath] [count <n>]") \
8577 _(proxy_arp_add_del, \
8578 "<lo-ip4-addr> - <hi-ip4-addr> [vrf <n>] [del]") \
8579 _(proxy_arp_intfc_enable_disable, \
8580 "<intfc> | sw_if_index <id> enable | disable") \
8581 _(mpls_add_del_encap, \
8582 "label <n> dst <ip4-addr> [vrf <n>] [del]") \
8583 _(mpls_add_del_decap, \
8584 "label <n> [rx_vrf_id <n>] [tx_vrf_id] [s-bit-clear][del]") \
8585 _(mpls_gre_add_del_tunnel, \
8586 "inner_vrf_id <n> outer_vrf_id <n> src <ip4-address> dst <ip4-address>\n" \
8587 "adj <ip4-address>/<mask-width> [del]") \
8588 _(sw_interface_set_unnumbered, \
8589 "<intfc> | sw_if_index <id> unnum_if_index <id> [del]") \
8590 _(ip_neighbor_add_del, \
8591 "<intfc> | sw_if_index <id> dst <ip46-address> mac <mac-addr>") \
8592 _(reset_vrf, "vrf <id> [ipv6]") \
8593 _(create_vlan_subif, "<intfc> | sw_if_index <id> vlan <n>") \
8594 _(create_subif, "<intfc> | sw_if_index <id> sub_id <n>\n" \
8595 "[outer_vlan_id <n>][inner_vlan_id <n>]\n" \
8596 "[no_tags][one_tag][two_tags][dot1ad][exact_match][default_sub]\n" \
8597 "[outer_vlan_id_any][inner_vlan_id_any]") \
8598 _(oam_add_del, "src <ip4-address> dst <ip4-address> [vrf <n>] [del]") \
8599 _(reset_fib, "vrf <n> [ipv6]") \
8600 _(dhcp_proxy_config, \
8601 "svr <v46-address> src <v46-address>\n" \
8602 "insert-cid <n> [del]") \
8603 _(dhcp_proxy_config_2, \
8604 "svr <v46-address> src <v46-address>\n" \
8605 "rx_vrf_id <nn> server_vrf_id <nn> insert-cid <n> [del]") \
8606 _(dhcp_proxy_set_vss, \
8607 "tbl_id <n> fib_id <n> oui <n> [ipv6] [del]") \
8608 _(dhcp_client_config, \
8609 "<intfc> | sw_if_index <id> [hostname <name>] [disable_event] [del]") \
8610 _(set_ip_flow_hash, \
8611 "vrf <n> [src] [dst] [sport] [dport] [proto] [reverse] [ipv6]") \
8612 _(sw_interface_ip6_enable_disable, \
8613 "<intfc> | sw_if_index <id> enable | disable") \
8614 _(sw_interface_ip6_set_link_local_address, \
8615 "<intfc> | sw_if_index <id> <ip6-address>/<mask-width>") \
8616 _(sw_interface_ip6nd_ra_prefix, \
8617 "<intfc> | sw_if_index <id> <ip6-address>/<mask-width>\n" \
8618 "val_life <n> pref_life <n> [def] [noadv] [offl] [noauto]\n" \
8619 "[nolink] [isno]") \
8620 _(sw_interface_ip6nd_ra_config, \
8621 "<intfc> | sw_if_index <id> [maxint <n>] [minint <n>]\n" \
8622 "[life <n>] [count <n>] [interval <n>] [surpress]\n" \
8623 "[managed] [other] [ll] [send] [cease] [isno] [def]") \
8624 _(set_arp_neighbor_limit, "arp_nbr_limit <n> [ipv6]") \
8625 _(l2_patch_add_del, \
8626 "rx <intfc> | rx_sw_if_index <id> tx <intfc> | tx_sw_if_index <id>\n" \
8627 "enable | disable") \
8628 _(mpls_ethernet_add_del_tunnel, \
8629 "tx <intfc> | tx_sw_if_index <n> dst <mac-addr>\n" \
8630 "adj <ip4-addr>/<mw> dst <mac-addr> [del]") \
8631 _(mpls_ethernet_add_del_tunnel_2, \
8632 "inner_vrf_id <n> outer_vrf_id <n> next-hop <ip4-addr>\n" \
8633 "resolve-attempts <n> resolve-if-needed 0 | 1 [del]") \
8634 _(sr_tunnel_add_del, \
8635 "src <ip6-addr> dst <ip6-addr>/<mw> (next <ip6-addr>)+\n" \
8636 " [tag <ip6-addr>]* [clean] [reroute]") \
8637 _(classify_add_del_table, \
8638 "buckets <nn> [skip <n>] [match <n>] [memory_size <nn-bytes>]\n" \
8639 "[del] mask <mask-value>\n" \
8640 " [l2-miss-next | miss-next | acl-miss-next] <name|nn>") \
8641 _(classify_add_del_session, \
8642 "[hit-next|l2-hit-next|acl-hit-next] <name|nn> table-index <nn>\n" \
8643 "skip_n <nn> match_n <nn> match [hex] [l2] [l3 [ip4|ip6]]") \
8644 _(classify_set_interface_ip_table, \
8645 "<intfc> | sw_if_index <nn> table <nn>") \
8646 _(classify_set_interface_l2_tables, \
8647 "<intfc> | sw_if_index <nn> [ip4-table <nn>] [ip6-table <nn>]\n" \
8648 " [other-table <nn>]") \
8649 _(get_node_index, "node <node-name") \
8650 _(add_node_next, "node <node-name> next <next-node-name>") \
8651 _(l2tpv3_create_tunnel, \
8652 "client_address <ip6-addr> our_address <ip6-addr>\n" \
8653 "[local_session_id <nn>][remote_session_id <nn>][local_cookie <nn>]\n"\
8654 "[remote_cookie <nn>]\n[l2-sublayer-preset]\n") \
8655 _(l2tpv3_set_tunnel_cookies, \
8656 "<intfc> | sw_if_index <nn> [new_local_cookie <nn>]\n" \
8657 "[new_remote_cookie <nn>]\n") \
8658 _(l2tpv3_interface_enable_disable, \
8659 "<intfc> | sw_if_index <nn> enable | disable") \
8660 _(l2tpv3_set_lookup_key, \
8661 "lookup_v6_src | lookup_v6_dst | lookup_session_id") \
8662 _(sw_if_l2tpv3_tunnel_dump, "") \
8663 _(vxlan_add_del_tunnel, \
8664 "src <ip4-addr> dst <ip4-addr> vni [encap-vrf-id <nn>]\n" \
8665 " [decap-next l2|ip4|ip6] [del]") \
8666 _(vxlan_tunnel_dump, "[<intfc> | sw_if_index <nn>]") \
8667 _(l2_fib_clear_table, "") \
8668 _(l2_interface_efp_filter, "sw_if_index <nn> enable | disable") \
8669 _(l2_interface_vlan_tag_rewrite, \
8670 "<intfc> | sw_if_index <nn> \n" \
8671 "[disable][push-[1|2]][pop-[1|2]][translate-1-[1|2]] \n" \
8672 "[translate-2-[1|2]] [push_dot1q 0] tag1 <nn> tag2 <nn>") \
8673 _(create_vhost_user_if, \
8674 "socket <filename> [server] [renumber <dev_instance>]") \
8675 _(modify_vhost_user_if, \
8676 "<intfc> | sw_if_index <nn> socket <filename>\n" \
8677 "[server] [renumber <dev_instance>]") \
8678 _(delete_vhost_user_if, "<intfc> | sw_if_index <nn>") \
8679 _(sw_interface_vhost_user_dump, "") \
8680 _(show_version, "") \
8681 _(nsh_gre_add_del_tunnel, \
8682 "src <ip4-addr> dst <ip4-addr>" \
8683 "c1 <nn> c2 <nn> c3 <nn> c4 <nn> spi <nn> si <nn>\n" \
8684 "[encap-fib-id <nn>] [decap-fib-id <nn>] [o-bit <1|0>]\n" \
8685 "[c-bit <1|0>] [md-type <nn>][next-ip4][next-ip6][next-ethernet]\n" \
8686 "[tlv <xx>][del]") \
8687 _(nsh_vxlan_gpe_add_del_tunnel, \
8688 "src <ip4-addr> dst <ip4-addr> vni <nn>\n" \
8689 "c1 <nn> c2 <nn> c3 <nn> c4 <nn> spi <nn> si <nn>\n" \
8690 "[encap-vrf-id <nn>] [decap-vrf-id <nn>] [o-bit <1|0>]\n" \
8691 "[c-bit <1|0>] [md-type <nn>][next-ip4][next-ip6][next-ethernet]\n" \
8692 "[tlv <xx>][del]") \
8693 _(l2_fib_table_dump, "bd_id <bridge-domain-id>") \
8694 _(lisp_gpe_add_del_tunnel, \
8695 "src <ip4-addr> dst <ip4-addr> iid <nn>|iidx <0xnn>\n" \
8696 "[encap-vrf-id <nn>] [decap-vrf-id <nn>]\n" \
8697 "[n-bit][l-bit][e-bit][v-bit][i-bit][p-bit][not-p-bit][o-bit]\n" \
8698 "[next-ip4][next-ip6][next-ethernet][next-nsh]\n" \
8699 "[decap-next [ip4|ip6|ethernet|nsh-encap|<nn>]][del]") \
8700 _(interface_name_renumber, \
8701 "<intfc> | sw_if_index <nn> new_show_dev_instance <nn>") \
8702 _(input_acl_set_interface, \
8703 "<intfc> | sw_if_index <nn> [ip4-table <nn>] [ip6-table <nn>]\n" \
8704 " [l2-table <nn>] [del]") \
8705 _(want_ip4_arp_events, "address <ip4-address> [del]") \
8706 _(ip_address_dump, "(ipv4 | ipv6) (<intfc> | sw_if_index <id>)") \
8707 _(ip_dump, "ipv4 | ipv6") \
8708 _(ipsec_spd_add_del, "spd_id <n> [del]") \
8709 _(ipsec_interface_add_del_spd, "(<intfc> | sw_if_index <id>)\n" \
8711 _(ipsec_sad_add_del_entry, "sad_id <n> spi <n> crypto_alg <alg>\n" \
8712 " crypto_key <hex> tunnel_src <ip4|ip6> tunnel_dst <ip4|ip6>\n" \
8713 " integ_alg <alg> integ_key <hex>") \
8714 _(ipsec_spd_add_del_entry, "spd_id <n> priority <n> action <action>\n" \
8715 " (inbound|outbound) [sa_id <n>] laddr_start <ip4|ip6>\n" \
8716 " laddr_stop <ip4|ip6> raddr_start <ip4|ip6> raddr_stop <ip4|ip6>\n" \
8717 " [lport_start <n> lport_stop <n>] [rport_start <n> rport_stop <n>]" )\
8718 _(ipsec_sa_set_key, "sa_id <n> crypto_key <hex> integ_key <hex>") \
8719 _(delete_loopback,"sw_if_index <nn>") \
8720 _(bd_ip_mac_add_del, "bd_id <bridge-domain-id> <ip4/6-addr> <mac-addr> [del]") \
8722 "ip4-pfx <ip4pfx> ip6-pfx <ip6pfx> " \
8723 "ip6-src <ip6addr> " \
8724 "ea-bits-len <n> psid-offset <n> psid-len <n>") \
8725 _(map_del_domain, "index <n>") \
8726 _(map_add_del_rule, \
8727 "index <n> psid <n> dst <ip6addr> [del]") \
8728 _(map_domain_dump, "") \
8729 _(map_rule_dump, "index <map-domain>") \
8730 _(want_interface_events, "enable|disable") \
8731 _(want_stats,"enable|disable") \
8732 _(get_first_msg_id, "client <name>")
8734 /* List of command functions, CLI names map directly to functions */
8735 #define foreach_cli_function \
8736 _(comment, "usage: comment <ignore-rest-of-line>") \
8737 _(dump_interface_table, "usage: dump_interface_table") \
8738 _(dump_sub_interface_table, "usage: dump_sub_interface_table") \
8739 _(dump_ipv4_table, "usage: dump_ipv4_table") \
8740 _(dump_ipv6_table, "usage: dump_ipv6_table") \
8741 _(dump_stats_table, "usage: dump_stats_table") \
8742 _(dump_macro_table, "usage: dump_macro_table ") \
8743 _(echo, "usage: echo <message>") \
8744 _(exec, "usage: exec <vpe-debug-CLI-command>") \
8745 _(help, "usage: help") \
8746 _(q, "usage: quit") \
8747 _(quit, "usage: quit") \
8748 _(set, "usage: set <variable-name> <value>") \
8749 _(script, "usage: script <file-name>") \
8750 _(unset, "usage: unset <variable-name>")
8753 static void vl_api_##n##_t_handler_uni \
8754 (vl_api_##n##_t * mp) \
8756 vat_main_t * vam = &vat_main; \
8757 if (vam->json_output) { \
8758 vl_api_##n##_t_handler_json(mp); \
8760 vl_api_##n##_t_handler(mp); \
8763 foreach_vpe_api_reply_msg;
8766 void vat_api_hookup (vat_main_t *vam)
8769 vl_msg_api_set_handlers(VL_API_##N, #n, \
8770 vl_api_##n##_t_handler_uni, \
8772 vl_api_##n##_t_endian, \
8773 vl_api_##n##_t_print, \
8774 sizeof(vl_api_##n##_t), 1);
8775 foreach_vpe_api_reply_msg;
8778 vl_msg_api_set_first_available_msg_id (VL_MSG_FIRST_AVAILABLE);
8780 vam->sw_if_index_by_interface_name =
8781 hash_create_string (0, sizeof (uword));
8783 vam->function_by_name =
8784 hash_create_string (0, sizeof(uword));
8787 hash_create_string (0, sizeof(uword));
8789 /* API messages we can send */
8790 #define _(n,h) hash_set_mem (vam->function_by_name, #n, api_##n);
8791 foreach_vpe_api_msg;
8795 #define _(n,h) hash_set_mem (vam->help_by_name, #n, h);
8796 foreach_vpe_api_msg;
8800 #define _(n,h) hash_set_mem (vam->function_by_name, #n, n);
8801 foreach_cli_function;
8805 #define _(n,h) hash_set_mem (vam->help_by_name, #n, h);
8806 foreach_cli_function;
8810 #undef vl_api_version
8811 #define vl_api_version(n,v) static u32 vpe_api_version = v;
8812 #include <api/vpe.api.h>
8813 #undef vl_api_version
8815 void vl_client_add_api_signatures (vl_api_memclnt_create_t *mp)
8818 * Send the main API signature in slot 0. This bit of code must
8819 * match the checks in ../vpe/api/api.c: vl_msg_api_version_check().
8821 mp->api_versions[0] = clib_host_to_net_u32 (vpe_api_version);