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 (" git branch: %s\n", mp->git_branch);
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, "git_branch", mp->git_branch);
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 _(L2_FIB_CLEAR_TABLE_REPLY, l2_fib_clear_table_reply) \
1884 _(L2_INTERFACE_EFP_FILTER_REPLY, l2_interface_efp_filter_reply) \
1885 _(L2_INTERFACE_VLAN_TAG_REWRITE_REPLY, l2_interface_vlan_tag_rewrite_reply) \
1886 _(SW_INTERFACE_VHOST_USER_DETAILS, sw_interface_vhost_user_details) \
1887 _(CREATE_VHOST_USER_IF_REPLY, create_vhost_user_if_reply) \
1888 _(MODIFY_VHOST_USER_IF_REPLY, modify_vhost_user_if_reply) \
1889 _(DELETE_VHOST_USER_IF_REPLY, delete_vhost_user_if_reply) \
1890 _(SHOW_VERSION_REPLY, show_version_reply) \
1891 _(NSH_GRE_ADD_DEL_TUNNEL_REPLY, nsh_gre_add_del_tunnel_reply) \
1892 _(L2_FIB_TABLE_ENTRY, l2_fib_table_entry) \
1893 _(NSH_VXLAN_GPE_ADD_DEL_TUNNEL_REPLY, nsh_vxlan_gpe_add_del_tunnel_reply) \
1894 _(LISP_GPE_ADD_DEL_TUNNEL_REPLY, lisp_gpe_add_del_tunnel_reply) \
1895 _(INTERFACE_NAME_RENUMBER_REPLY, interface_name_renumber_reply) \
1896 _(WANT_IP4_ARP_EVENTS_REPLY, want_ip4_arp_events_reply) \
1897 _(IP4_ARP_EVENT, ip4_arp_event) \
1898 _(INPUT_ACL_SET_INTERFACE_REPLY, input_acl_set_interface_reply) \
1899 _(IP_ADDRESS_DETAILS, ip_address_details) \
1900 _(IP_DETAILS, ip_details) \
1901 _(IPSEC_SPD_ADD_DEL_REPLY, ipsec_spd_add_del_reply) \
1902 _(IPSEC_INTERFACE_ADD_DEL_SPD_REPLY, ipsec_interface_add_del_spd_reply) \
1903 _(IPSEC_SPD_ADD_DEL_ENTRY_REPLY, ipsec_spd_add_del_entry_reply) \
1904 _(IPSEC_SAD_ADD_DEL_ENTRY_REPLY, ipsec_sad_add_del_entry_reply) \
1905 _(IPSEC_SA_SET_KEY_REPLY, ipsec_sa_set_key_reply) \
1906 _(DELETE_LOOPBACK_REPLY, delete_loopback_reply) \
1907 _(BD_IP_MAC_ADD_DEL_REPLY, bd_ip_mac_add_del_reply) \
1908 _(DHCP_COMPL_EVENT, dhcp_compl_event) \
1909 _(VNET_INTERFACE_COUNTERS, vnet_interface_counters) \
1910 _(VNET_IP4_FIB_COUNTERS, vnet_ip4_fib_counters) \
1911 _(VNET_IP6_FIB_COUNTERS, vnet_ip6_fib_counters) \
1912 _(MAP_ADD_DOMAIN_REPLY, map_add_domain_reply) \
1913 _(MAP_DEL_DOMAIN_REPLY, map_del_domain_reply) \
1914 _(MAP_ADD_DEL_RULE_REPLY, map_add_del_rule_reply) \
1915 _(MAP_DOMAIN_DETAILS, map_domain_details) \
1916 _(MAP_RULE_DETAILS, map_rule_details) \
1917 _(WANT_INTERFACE_EVENTS_REPLY, want_interface_events_reply) \
1918 _(WANT_STATS_REPLY, want_stats_reply) \
1919 _(GET_FIRST_MSG_ID_REPLY, get_first_msg_id_reply)
1921 /* M: construct, but don't yet send a message */
1925 vam->result_ready = 0; \
1926 mp = vl_msg_api_alloc(sizeof(*mp)); \
1927 memset (mp, 0, sizeof (*mp)); \
1928 mp->_vl_msg_id = ntohs (VL_API_##T); \
1929 mp->client_index = vam->my_client_index; \
1934 vam->result_ready = 0; \
1935 mp = vl_msg_api_alloc(sizeof(*mp)+(n)); \
1936 memset (mp, 0, sizeof (*mp)); \
1937 mp->_vl_msg_id = ntohs (VL_API_##T); \
1938 mp->client_index = vam->my_client_index; \
1942 /* S: send a message */
1943 #define S (vl_msg_api_send_shmem (vam->vl_input_queue, (u8 *)&mp))
1945 /* W: wait for results, with timeout */
1948 timeout = vat_time_now (vam) + 1.0; \
1950 while (vat_time_now (vam) < timeout) { \
1951 if (vam->result_ready == 1) { \
1952 return (vam->retval); \
1964 #define STR_VTR_OP_CASE(op) \
1965 case L2_VTR_ ## op: \
1968 static const char *str_vtr_op(u32 vtr_op)
1971 STR_VTR_OP_CASE(DISABLED);
1972 STR_VTR_OP_CASE(PUSH_1);
1973 STR_VTR_OP_CASE(PUSH_2);
1974 STR_VTR_OP_CASE(POP_1);
1975 STR_VTR_OP_CASE(POP_2);
1976 STR_VTR_OP_CASE(TRANSLATE_1_1);
1977 STR_VTR_OP_CASE(TRANSLATE_1_2);
1978 STR_VTR_OP_CASE(TRANSLATE_2_1);
1979 STR_VTR_OP_CASE(TRANSLATE_2_2);
1985 static int dump_sub_interface_table (vat_main_t * vam)
1987 const sw_interface_subif_t * sub = NULL;
1989 if (vam->json_output) {
1990 clib_warning ("JSON output supported only for VPE API calls and dump_stats_table");
1995 "%-30s%-12s%-11s%-7s%-5s%-9s%-9s%-6s%-8s%-10s%-10s\n",
1996 "Interface", "sw_if_index",
1997 "sub id", "dot1ad", "tags", "outer id",
1998 "inner id", "exact", "default",
1999 "outer any", "inner any");
2001 vec_foreach (sub, vam->sw_if_subif_table) {
2003 "%-30s%-12d%-11d%-7s%-5d%-9d%-9d%-6d%-8d%-10d%-10d\n",
2004 sub->interface_name,
2006 sub->sub_id, sub->sub_dot1ad ? "dot1ad" : "dot1q",
2007 sub->sub_number_of_tags, sub->sub_outer_vlan_id,
2008 sub->sub_inner_vlan_id, sub->sub_exact_match, sub->sub_default,
2009 sub->sub_outer_vlan_id_any, sub->sub_inner_vlan_id_any);
2010 if (sub->vtr_op != L2_VTR_DISABLED) {
2012 " vlan-tag-rewrite - op: %-14s [ dot1q: %d "
2013 "tag1: %d tag2: %d ]\n",
2014 str_vtr_op(sub->vtr_op), sub->vtr_push_dot1q,
2015 sub->vtr_tag1, sub->vtr_tag2);
2022 static int dump_interface_table (vat_main_t * vam)
2025 name_sort_t * nses = 0, * ns;
2027 if (vam->json_output) {
2028 clib_warning ("JSON output supported only for VPE API calls and dump_stats_table");
2032 hash_foreach_pair (p, vam->sw_if_index_by_interface_name,
2034 vec_add2 (nses, ns, 1);
2035 ns->name = (u8 *)(p->key);
2036 ns->value = (u32) p->value[0];
2039 vec_sort (nses, n1, n2,
2040 strcmp ((char *)n1->name, (char *)n2->name));
2042 fformat (vam->ofp, "%-25s%-15s\n", "Interface", "sw_if_index");
2043 vec_foreach (ns, nses) {
2044 fformat (vam->ofp, "%-25s%-15d\n", ns->name, ns->value);
2050 static int dump_ip_table (vat_main_t * vam, int is_ipv6)
2052 const ip_details_t * det = NULL;
2053 const ip_address_details_t * address = NULL;
2060 if (0 == vam->ip_details_by_sw_if_index) {
2064 vec_foreach (det, vam->ip_details_by_sw_if_index[is_ipv6]) {
2066 if (!det->present) {
2074 "Address", "Prefix length");
2078 vec_foreach (address, det->addr) {
2081 is_ipv6 ? format_ip6_address : format_ip4_address,
2083 address->prefix_length);
2090 static int dump_ipv4_table (vat_main_t * vam)
2092 if (vam->json_output) {
2093 clib_warning ("JSON output supported only for VPE API calls and dump_stats_table");
2097 return dump_ip_table (vam, 0);
2100 static int dump_ipv6_table (vat_main_t * vam)
2102 if (vam->json_output) {
2103 clib_warning ("JSON output supported only for VPE API calls and dump_stats_table");
2107 return dump_ip_table (vam, 1);
2110 static char* counter_type_to_str (u8 counter_type, u8 is_combined)
2113 switch(counter_type) {
2114 case VNET_INTERFACE_COUNTER_DROP:
2116 case VNET_INTERFACE_COUNTER_PUNT:
2118 case VNET_INTERFACE_COUNTER_IP4:
2120 case VNET_INTERFACE_COUNTER_IP6:
2122 case VNET_INTERFACE_COUNTER_RX_NO_BUF:
2124 case VNET_INTERFACE_COUNTER_RX_MISS:
2126 case VNET_INTERFACE_COUNTER_RX_ERROR:
2128 case VNET_INTERFACE_COUNTER_TX_ERROR:
2131 return "INVALID-COUNTER-TYPE";
2134 switch(counter_type) {
2135 case VNET_INTERFACE_COUNTER_RX:
2137 case VNET_INTERFACE_COUNTER_TX:
2140 return "INVALID-COUNTER-TYPE";
2145 static int dump_stats_table (vat_main_t * vam)
2147 vat_json_node_t node;
2148 vat_json_node_t *msg_array;
2149 vat_json_node_t *msg;
2150 vat_json_node_t *counter_array;
2151 vat_json_node_t *counter;
2152 interface_counter_t c;
2154 ip4_fib_counter_t *c4;
2155 ip6_fib_counter_t *c6;
2158 if (!vam->json_output) {
2159 clib_warning ("dump_stats_table supported only in JSON format");
2163 vat_json_init_object(&node);
2165 /* interface counters */
2166 msg_array = vat_json_object_add(&node, "interface_counters");
2167 vat_json_init_array(msg_array);
2168 for (i = 0; i < vec_len(vam->simple_interface_counters); i++) {
2169 msg = vat_json_array_add(msg_array);
2170 vat_json_init_object(msg);
2171 vat_json_object_add_string_copy(msg, "vnet_counter_type",
2172 (u8*)counter_type_to_str(i, 0));
2173 vat_json_object_add_int(msg, "is_combined", 0);
2174 counter_array = vat_json_object_add(msg, "data");
2175 vat_json_init_array(counter_array);
2176 for (j = 0; j < vec_len(vam->simple_interface_counters[i]); j++) {
2177 packets = vam->simple_interface_counters[i][j];
2178 vat_json_array_add_uint(counter_array, packets);
2181 for (i = 0; i < vec_len(vam->combined_interface_counters); i++) {
2182 msg = vat_json_array_add(msg_array);
2183 vat_json_init_object(msg);
2184 vat_json_object_add_string_copy(msg, "vnet_counter_type",
2185 (u8*)counter_type_to_str(i, 1));
2186 vat_json_object_add_int(msg, "is_combined", 1);
2187 counter_array = vat_json_object_add(msg, "data");
2188 vat_json_init_array(counter_array);
2189 for (j = 0; j < vec_len(vam->combined_interface_counters[i]); j++) {
2190 c = vam->combined_interface_counters[i][j];
2191 counter = vat_json_array_add(counter_array);
2192 vat_json_init_object(counter);
2193 vat_json_object_add_uint(counter, "packets", c.packets);
2194 vat_json_object_add_uint(counter, "bytes", c.bytes);
2198 /* ip4 fib counters */
2199 msg_array = vat_json_object_add(&node, "ip4_fib_counters");
2200 vat_json_init_array(msg_array);
2201 for (i = 0; i < vec_len(vam->ip4_fib_counters); i++) {
2202 msg = vat_json_array_add(msg_array);
2203 vat_json_init_object(msg);
2204 vat_json_object_add_uint(msg, "vrf_id", vam->ip4_fib_counters_vrf_id_by_index[i]);
2205 counter_array = vat_json_object_add(msg, "c");
2206 vat_json_init_array(counter_array);
2207 for (j = 0; j < vec_len(vam->ip4_fib_counters[i]); j++) {
2208 counter = vat_json_array_add(counter_array);
2209 vat_json_init_object(counter);
2210 c4 = &vam->ip4_fib_counters[i][j];
2211 vat_json_object_add_ip4(counter, "address", c4->address);
2212 vat_json_object_add_uint(counter, "address_length", c4->address_length);
2213 vat_json_object_add_uint(counter, "packets", c4->packets);
2214 vat_json_object_add_uint(counter, "bytes", c4->bytes);
2218 /* ip6 fib counters */
2219 msg_array = vat_json_object_add(&node, "ip6_fib_counters");
2220 vat_json_init_array(msg_array);
2221 for (i = 0; i < vec_len(vam->ip6_fib_counters); i++) {
2222 msg = vat_json_array_add(msg_array);
2223 vat_json_init_object(msg);
2224 vat_json_object_add_uint(msg, "vrf_id", vam->ip6_fib_counters_vrf_id_by_index[i]);
2225 counter_array = vat_json_object_add(msg, "c");
2226 vat_json_init_array(counter_array);
2227 for (j = 0; j < vec_len(vam->ip6_fib_counters[i]); j++) {
2228 counter = vat_json_array_add(counter_array);
2229 vat_json_init_object(counter);
2230 c6 = &vam->ip6_fib_counters[i][j];
2231 vat_json_object_add_ip6(counter, "address", c6->address);
2232 vat_json_object_add_uint(counter, "address_length", c6->address_length);
2233 vat_json_object_add_uint(counter, "packets", c6->packets);
2234 vat_json_object_add_uint(counter, "bytes", c6->bytes);
2238 vat_json_print(vam->ofp, &node);
2239 vat_json_free(&node);
2244 int exec (vat_main_t * vam)
2246 api_main_t * am = &api_main;
2247 vl_api_cli_request_t *mp;
2251 unformat_input_t * i = vam->input;
2253 if (vec_len(i->buffer) == 0)
2256 if (vam->exec_mode == 0 && unformat (i, "mode")) {
2260 if (vam->exec_mode == 1 &&
2261 (unformat (i, "exit") || unformat (i, "quit"))) {
2267 M(CLI_REQUEST, cli_request);
2270 * Copy cmd into shared memory.
2271 * In order for the CLI command to work, it
2272 * must be a vector ending in \n, not a C-string ending
2275 pthread_mutex_lock (&am->vlib_rp->mutex);
2276 oldheap = svm_push_data_heap (am->vlib_rp);
2278 vec_validate (cmd, vec_len(vam->input->buffer)-1);
2279 memcpy (cmd, vam->input->buffer, vec_len(vam->input->buffer));
2281 svm_pop_heap (oldheap);
2282 pthread_mutex_unlock (&am->vlib_rp->mutex);
2284 mp->cmd_in_shmem = (u64) cmd;
2286 timeout = vat_time_now (vam) + 10.0;
2288 while (vat_time_now (vam) < timeout) {
2289 if (vam->result_ready == 1) {
2291 fformat (vam->ofp, "%s", vam->shmem_result);
2292 pthread_mutex_lock (&am->vlib_rp->mutex);
2293 oldheap = svm_push_data_heap (am->vlib_rp);
2295 free_me = (u8 *)vam->shmem_result;
2298 svm_pop_heap (oldheap);
2299 pthread_mutex_unlock (&am->vlib_rp->mutex);
2306 static int api_create_loopback (vat_main_t * vam)
2308 unformat_input_t * i = vam->input;
2309 vl_api_create_loopback_t *mp;
2314 memset (mac_address, 0, sizeof (mac_address));
2316 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
2318 if (unformat (i, "mac %U", unformat_ethernet_address, mac_address))
2324 /* Construct the API message */
2325 M(CREATE_LOOPBACK, create_loopback);
2327 memcpy (mp->mac_address, mac_address, sizeof (mac_address));
2332 static int api_delete_loopback (vat_main_t * vam)
2334 unformat_input_t * i = vam->input;
2335 vl_api_delete_loopback_t *mp;
2337 u32 sw_if_index = ~0;
2339 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
2341 if (unformat (i, "sw_if_index %d", &sw_if_index))
2347 if (sw_if_index == ~0)
2349 errmsg ("missing sw_if_index\n");
2353 /* Construct the API message */
2354 M(DELETE_LOOPBACK, delete_loopback);
2355 mp->sw_if_index = ntohl (sw_if_index);
2360 static int api_want_stats (vat_main_t * vam)
2362 unformat_input_t * i = vam->input;
2363 vl_api_want_stats_t * mp;
2367 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
2369 if (unformat (i, "enable"))
2371 else if (unformat (i, "disable"))
2379 errmsg ("missing enable|disable\n");
2383 M(WANT_STATS, want_stats);
2384 mp->enable_disable = enable;
2389 static int api_want_interface_events (vat_main_t * vam)
2391 unformat_input_t * i = vam->input;
2392 vl_api_want_interface_events_t * mp;
2396 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
2398 if (unformat (i, "enable"))
2400 else if (unformat (i, "disable"))
2408 errmsg ("missing enable|disable\n");
2412 M(WANT_INTERFACE_EVENTS, want_interface_events);
2413 mp->enable_disable = enable;
2415 vam->interface_event_display = enable;
2421 /* Note: non-static, called once to set up the initial intfc table */
2422 int api_sw_interface_dump (vat_main_t * vam)
2424 vl_api_sw_interface_dump_t *mp;
2427 name_sort_t * nses = 0, * ns;
2428 sw_interface_subif_t * sub = NULL;
2430 /* Toss the old name table */
2431 hash_foreach_pair (p, vam->sw_if_index_by_interface_name,
2433 vec_add2 (nses, ns, 1);
2434 ns->name = (u8 *)(p->key);
2435 ns->value = (u32) p->value[0];
2438 hash_free (vam->sw_if_index_by_interface_name);
2440 vec_foreach (ns, nses)
2441 vec_free (ns->name);
2445 vec_foreach (sub, vam->sw_if_subif_table) {
2446 vec_free (sub->interface_name);
2448 vec_free (vam->sw_if_subif_table);
2450 /* recreate the interface name hash table */
2451 vam->sw_if_index_by_interface_name
2452 = hash_create_string (0, sizeof(uword));
2454 /* Get list of ethernets */
2455 M(SW_INTERFACE_DUMP, sw_interface_dump);
2456 mp->name_filter_valid = 1;
2457 strncpy ((char *) mp->name_filter, "Ether", sizeof(mp->name_filter-1));
2460 /* and local / loopback interfaces */
2461 M(SW_INTERFACE_DUMP, sw_interface_dump);
2462 mp->name_filter_valid = 1;
2463 strncpy ((char *) mp->name_filter, "lo", sizeof(mp->name_filter-1));
2466 /* and vxlan tunnel interfaces */
2467 M(SW_INTERFACE_DUMP, sw_interface_dump);
2468 mp->name_filter_valid = 1;
2469 strncpy ((char *) mp->name_filter, "vxlan", sizeof(mp->name_filter-1));
2472 /* and l2tpv3 tunnel interfaces */
2473 M(SW_INTERFACE_DUMP, sw_interface_dump);
2474 mp->name_filter_valid = 1;
2475 strncpy ((char *) mp->name_filter, "l2tpv3_tunnel", sizeof(mp->name_filter-1));
2478 /* Use a control ping for synchronization */
2480 vl_api_control_ping_t * mp;
2481 M(CONTROL_PING, control_ping);
2487 static int api_sw_interface_set_flags (vat_main_t * vam)
2489 unformat_input_t * i = vam->input;
2490 vl_api_sw_interface_set_flags_t *mp;
2493 u8 sw_if_index_set = 0;
2494 u8 admin_up = 0, link_up = 0;
2496 /* Parse args required to build the message */
2497 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
2498 if (unformat (i, "admin-up"))
2500 else if (unformat (i, "admin-down"))
2502 else if (unformat (i, "link-up"))
2504 else if (unformat (i, "link-down"))
2506 else if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
2507 sw_if_index_set = 1;
2508 else if (unformat (i, "sw_if_index %d", &sw_if_index))
2509 sw_if_index_set = 1;
2514 if (sw_if_index_set == 0) {
2515 errmsg ("missing interface name or sw_if_index\n");
2519 /* Construct the API message */
2520 M(SW_INTERFACE_SET_FLAGS, sw_interface_set_flags);
2521 mp->sw_if_index = ntohl (sw_if_index);
2522 mp->admin_up_down = admin_up;
2523 mp->link_up_down = link_up;
2528 /* Wait for a reply, return the good/bad news... */
2532 static int api_sw_interface_add_del_address (vat_main_t * vam)
2534 unformat_input_t * i = vam->input;
2535 vl_api_sw_interface_add_del_address_t *mp;
2538 u8 sw_if_index_set = 0;
2539 u8 is_add = 1, del_all = 0;
2540 u32 address_length = 0;
2541 u8 v4_address_set = 0;
2542 u8 v6_address_set = 0;
2543 ip4_address_t v4address;
2544 ip6_address_t v6address;
2546 /* Parse args required to build the message */
2547 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
2548 if (unformat (i, "del-all"))
2550 else if (unformat (i, "del"))
2552 else if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
2553 sw_if_index_set = 1;
2554 else if (unformat (i, "sw_if_index %d", &sw_if_index))
2555 sw_if_index_set = 1;
2556 else if (unformat (i, "%U/%d",
2557 unformat_ip4_address, &v4address,
2560 else if (unformat (i, "%U/%d",
2561 unformat_ip6_address, &v6address,
2568 if (sw_if_index_set == 0) {
2569 errmsg ("missing interface name or sw_if_index\n");
2572 if (v4_address_set && v6_address_set) {
2573 errmsg ("both v4 and v6 addresses set\n");
2576 if (!v4_address_set && !v6_address_set && !del_all) {
2577 errmsg ("no addresses set\n");
2581 /* Construct the API message */
2582 M(SW_INTERFACE_ADD_DEL_ADDRESS, sw_interface_add_del_address);
2584 mp->sw_if_index = ntohl (sw_if_index);
2585 mp->is_add = is_add;
2586 mp->del_all = del_all;
2587 if (v6_address_set) {
2589 memcpy (mp->address, &v6address, sizeof (v6address));
2591 memcpy (mp->address, &v4address, sizeof (v4address));
2593 mp->address_length = address_length;
2598 /* Wait for a reply, return good/bad news */
2602 static int api_sw_interface_set_table (vat_main_t * vam)
2604 unformat_input_t * i = vam->input;
2605 vl_api_sw_interface_set_table_t *mp;
2607 u32 sw_if_index, vrf_id = 0;
2608 u8 sw_if_index_set = 0;
2611 /* Parse args required to build the message */
2612 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
2613 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
2614 sw_if_index_set = 1;
2615 else if (unformat (i, "sw_if_index %d", &sw_if_index))
2616 sw_if_index_set = 1;
2617 else if (unformat (i, "vrf %d", &vrf_id))
2619 else if (unformat (i, "ipv6"))
2625 if (sw_if_index_set == 0) {
2626 errmsg ("missing interface name or sw_if_index\n");
2630 /* Construct the API message */
2631 M(SW_INTERFACE_SET_TABLE, sw_interface_set_table);
2633 mp->sw_if_index = ntohl (sw_if_index);
2634 mp->is_ipv6 = is_ipv6;
2635 mp->vrf_id = ntohl (vrf_id);
2640 /* Wait for a reply... */
2644 static int api_sw_interface_set_vpath (vat_main_t * vam)
2646 unformat_input_t * i = vam->input;
2647 vl_api_sw_interface_set_vpath_t *mp;
2649 u32 sw_if_index = 0;
2650 u8 sw_if_index_set = 0;
2653 /* Parse args required to build the message */
2654 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
2655 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
2656 sw_if_index_set = 1;
2657 else if (unformat (i, "sw_if_index %d", &sw_if_index))
2658 sw_if_index_set = 1;
2659 else if (unformat (i, "enable"))
2661 else if (unformat (i, "disable"))
2667 if (sw_if_index_set == 0) {
2668 errmsg ("missing interface name or sw_if_index\n");
2672 /* Construct the API message */
2673 M(SW_INTERFACE_SET_VPATH, sw_interface_set_vpath);
2675 mp->sw_if_index = ntohl (sw_if_index);
2676 mp->enable = is_enable;
2681 /* Wait for a reply... */
2685 static int api_sw_interface_set_l2_xconnect (vat_main_t * vam)
2687 unformat_input_t * i = vam->input;
2688 vl_api_sw_interface_set_l2_xconnect_t *mp;
2691 u8 rx_sw_if_index_set = 0;
2693 u8 tx_sw_if_index_set = 0;
2696 /* Parse args required to build the message */
2697 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
2698 if (unformat (i, "rx_sw_if_index %d", &rx_sw_if_index))
2699 rx_sw_if_index_set = 1;
2700 else if (unformat (i, "tx_sw_if_index %d", &tx_sw_if_index))
2701 tx_sw_if_index_set = 1;
2702 else if (unformat (i, "rx")) {
2703 if (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
2704 if (unformat (i, "%U", unformat_sw_if_index, vam,
2706 rx_sw_if_index_set = 1;
2709 } else if (unformat (i, "tx")) {
2710 if (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
2711 if (unformat (i, "%U", unformat_sw_if_index, vam,
2713 tx_sw_if_index_set = 1;
2716 } else if (unformat (i, "enable"))
2718 else if (unformat (i, "disable"))
2724 if (rx_sw_if_index_set == 0) {
2725 errmsg ("missing rx interface name or rx_sw_if_index\n");
2729 if (enable && (tx_sw_if_index_set == 0)) {
2730 errmsg ("missing tx interface name or tx_sw_if_index\n");
2734 M(SW_INTERFACE_SET_L2_XCONNECT, sw_interface_set_l2_xconnect);
2736 mp->rx_sw_if_index = ntohl(rx_sw_if_index);
2737 mp->tx_sw_if_index = ntohl(tx_sw_if_index);
2738 mp->enable = enable;
2745 static int api_sw_interface_set_l2_bridge (vat_main_t * vam)
2747 unformat_input_t * i = vam->input;
2748 vl_api_sw_interface_set_l2_bridge_t *mp;
2751 u8 rx_sw_if_index_set = 0;
2758 /* Parse args required to build the message */
2759 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
2760 if (unformat (i, "sw_if_index %d", &rx_sw_if_index))
2761 rx_sw_if_index_set = 1;
2762 else if (unformat (i, "bd_id %d", &bd_id))
2764 else if (unformat (i, "%U", unformat_sw_if_index, vam,
2766 rx_sw_if_index_set = 1;
2767 else if (unformat (i, "shg %d", &shg))
2769 else if (unformat (i, "bvi"))
2771 else if (unformat (i, "enable"))
2773 else if (unformat (i, "disable"))
2779 if (rx_sw_if_index_set == 0) {
2780 errmsg ("missing rx interface name or sw_if_index\n");
2784 if (enable && (bd_id_set == 0)) {
2785 errmsg ("missing bridge domain\n");
2789 M(SW_INTERFACE_SET_L2_BRIDGE, sw_interface_set_l2_bridge);
2791 mp->rx_sw_if_index = ntohl(rx_sw_if_index);
2792 mp->bd_id = ntohl(bd_id);
2795 mp->enable = enable;
2802 static int api_bridge_domain_dump (vat_main_t * vam)
2804 unformat_input_t * i = vam->input;
2805 vl_api_bridge_domain_dump_t *mp;
2809 /* Parse args required to build the message */
2810 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
2811 if (unformat (i, "bd_id %d", &bd_id))
2817 M(BRIDGE_DOMAIN_DUMP, bridge_domain_dump);
2818 mp->bd_id = ntohl(bd_id);
2821 /* Use a control ping for synchronization */
2823 vl_api_control_ping_t * mp;
2824 M(CONTROL_PING, control_ping);
2833 static int api_bridge_domain_add_del (vat_main_t * vam)
2835 unformat_input_t * i = vam->input;
2836 vl_api_bridge_domain_add_del_t *mp;
2840 u32 flood = 1, forward = 1, learn = 1, uu_flood = 1, arp_term = 0;
2842 /* Parse args required to build the message */
2843 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
2844 if (unformat (i, "bd_id %d", &bd_id))
2846 else if (unformat (i, "flood %d", &flood))
2848 else if (unformat (i, "uu-flood %d", &uu_flood))
2850 else if (unformat (i, "forward %d", &forward))
2852 else if (unformat (i, "learn %d", &learn))
2854 else if (unformat (i, "arp-term %d", &arp_term))
2856 else if (unformat (i, "del")) {
2858 flood = uu_flood = forward = learn = 0;
2865 errmsg ("missing bridge domain\n");
2869 M(BRIDGE_DOMAIN_ADD_DEL, bridge_domain_add_del);
2871 mp->bd_id = ntohl(bd_id);
2873 mp->uu_flood = uu_flood;
2874 mp->forward = forward;
2876 mp->arp_term = arp_term;
2877 mp->is_add = is_add;
2884 static int api_l2fib_add_del (vat_main_t * vam)
2886 unformat_input_t * i = vam->input;
2887 vl_api_l2fib_add_del_t *mp;
2894 u8 sw_if_index_set = 0;
2899 /* Parse args required to build the message */
2900 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
2901 if (unformat (i, "mac %U", unformat_ethernet_address, &mac))
2903 else if (unformat (i, "bd_id %d", &bd_id))
2905 else if (unformat (i, "sw_if_index %d", &sw_if_index))
2906 sw_if_index_set = 1;
2907 else if (unformat (i, "sw_if")) {
2908 if (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
2909 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
2910 sw_if_index_set = 1;
2913 } else if (unformat (i, "static"))
2915 else if (unformat (i, "filter")) {
2918 } else if (unformat (i, "del"))
2925 errmsg ("missing mac address\n");
2929 if (bd_id_set == 0) {
2930 errmsg ("missing bridge domain\n");
2934 if (is_add && (sw_if_index_set == 0)) {
2935 errmsg ("missing interface name or sw_if_index\n");
2939 M(L2FIB_ADD_DEL, l2fib_add_del);
2942 mp->bd_id = ntohl(bd_id);
2943 mp->is_add = is_add;
2946 mp->sw_if_index = ntohl(sw_if_index);
2947 mp->static_mac = static_mac;
2948 mp->filter_mac = filter_mac;
2956 static int api_l2_flags (vat_main_t * vam)
2958 unformat_input_t * i = vam->input;
2959 vl_api_l2_flags_t *mp;
2962 u32 feature_bitmap = 0;
2963 u8 sw_if_index_set = 0;
2965 /* Parse args required to build the message */
2966 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
2967 if (unformat (i, "sw_if_index %d", &sw_if_index))
2968 sw_if_index_set = 1;
2969 else if (unformat (i, "sw_if")) {
2970 if (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
2971 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
2972 sw_if_index_set = 1;
2975 } else if (unformat (i, "learn"))
2976 feature_bitmap |= L2INPUT_FEAT_LEARN;
2977 else if (unformat (i, "forward"))
2978 feature_bitmap |= L2INPUT_FEAT_FWD;
2979 else if (unformat (i, "flood"))
2980 feature_bitmap |= L2INPUT_FEAT_FLOOD;
2981 else if (unformat (i, "uu-flood"))
2982 feature_bitmap |= L2INPUT_FEAT_UU_FLOOD;
2987 if (sw_if_index_set == 0) {
2988 errmsg ("missing interface name or sw_if_index\n");
2992 M(L2_FLAGS, l2_flags);
2994 mp->sw_if_index = ntohl(sw_if_index);
2995 mp->feature_bitmap = ntohl(feature_bitmap);
3002 static int api_bridge_flags (vat_main_t * vam)
3004 unformat_input_t * i = vam->input;
3005 vl_api_bridge_flags_t *mp;
3012 /* Parse args required to build the message */
3013 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
3014 if (unformat (i, "bd_id %d", &bd_id))
3016 else if (unformat (i, "learn"))
3018 else if (unformat (i, "forward"))
3020 else if (unformat (i, "flood"))
3022 else if (unformat (i, "uu-flood"))
3023 flags |= L2_UU_FLOOD;
3024 else if (unformat (i, "arp-term"))
3025 flags |= L2_ARP_TERM;
3026 else if (unformat (i, "off"))
3028 else if (unformat (i, "disable"))
3034 if (bd_id_set == 0) {
3035 errmsg ("missing bridge domain\n");
3039 M(BRIDGE_FLAGS, bridge_flags);
3041 mp->bd_id = ntohl(bd_id);
3042 mp->feature_bitmap = ntohl(flags);
3043 mp->is_set = is_set;
3050 static int api_bd_ip_mac_add_del (vat_main_t * vam)
3052 unformat_input_t * i = vam->input;
3053 vl_api_bd_ip_mac_add_del_t *mp;
3061 ip4_address_t v4addr;
3062 ip6_address_t v6addr;
3066 /* Parse args required to build the message */
3067 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
3068 if (unformat (i, "bd_id %d", &bd_id)) {
3070 } else if (unformat (i, "%U", unformat_ip4_address, &v4addr)) {
3072 } else if (unformat (i, "%U", unformat_ip6_address, &v6addr)) {
3075 } else if (unformat (i, "%U", unformat_ethernet_address, macaddr)) {
3077 } else if (unformat (i, "del"))
3083 if (bd_id_set == 0) {
3084 errmsg ("missing bridge domain\n");
3086 } else if (ip_set == 0) {
3087 errmsg ("missing IP address\n");
3089 } else if (mac_set == 0) {
3090 errmsg ("missing MAC address\n");
3094 M(BD_IP_MAC_ADD_DEL, bd_ip_mac_add_del);
3096 mp->bd_id = ntohl(bd_id);
3097 mp->is_ipv6 = is_ipv6;
3098 mp->is_add = is_add;
3100 memcpy (mp->ip_address, &v6addr, sizeof (v6addr));
3101 else memcpy (mp->ip_address, &v4addr, sizeof (v4addr));
3102 memcpy (mp->mac_address, macaddr, 6);
3108 static int api_tap_connect (vat_main_t * vam)
3110 unformat_input_t * i = vam->input;
3111 vl_api_tap_connect_t *mp;
3118 memset (mac_address, 0, sizeof (mac_address));
3120 /* Parse args required to build the message */
3121 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
3122 if (unformat (i, "mac %U", unformat_ethernet_address, mac_address)) {
3125 else if (unformat (i, "random-mac"))
3127 else if (unformat (i, "tapname %s", &tap_name))
3133 if (name_set == 0) {
3134 errmsg ("missing tap name\n");
3137 if (vec_len (tap_name) > 63) {
3138 errmsg ("tap name too long\n");
3140 vec_add1 (tap_name, 0);
3142 /* Construct the API message */
3143 M(TAP_CONNECT, tap_connect);
3145 mp->use_random_mac = random_mac;
3146 memcpy (mp->mac_address, mac_address, 6);
3147 memcpy (mp->tap_name, tap_name, vec_len (tap_name));
3148 vec_free (tap_name);
3153 /* Wait for a reply... */
3157 static int api_tap_modify (vat_main_t * vam)
3159 unformat_input_t * i = vam->input;
3160 vl_api_tap_modify_t *mp;
3166 u32 sw_if_index = ~0;
3167 u8 sw_if_index_set = 0;
3169 memset (mac_address, 0, sizeof (mac_address));
3171 /* Parse args required to build the message */
3172 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
3173 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
3174 sw_if_index_set = 1;
3175 else if (unformat (i, "sw_if_index %d", &sw_if_index))
3176 sw_if_index_set = 1;
3177 else if (unformat (i, "mac %U", unformat_ethernet_address, mac_address)) {
3180 else if (unformat (i, "random-mac"))
3182 else if (unformat (i, "tapname %s", &tap_name))
3188 if (sw_if_index_set == 0) {
3189 errmsg ("missing vpp interface name");
3192 if (name_set == 0) {
3193 errmsg ("missing tap name\n");
3196 if (vec_len (tap_name) > 63) {
3197 errmsg ("tap name too long\n");
3199 vec_add1 (tap_name, 0);
3201 /* Construct the API message */
3202 M(TAP_MODIFY, tap_modify);
3204 mp->use_random_mac = random_mac;
3205 mp->sw_if_index = ntohl(sw_if_index);
3206 memcpy (mp->mac_address, mac_address, 6);
3207 memcpy (mp->tap_name, tap_name, vec_len (tap_name));
3208 vec_free (tap_name);
3213 /* Wait for a reply... */
3217 static int api_tap_delete (vat_main_t * vam)
3219 unformat_input_t * i = vam->input;
3220 vl_api_tap_delete_t *mp;
3222 u32 sw_if_index = ~0;
3223 u8 sw_if_index_set = 0;
3225 /* Parse args required to build the message */
3226 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
3227 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
3228 sw_if_index_set = 1;
3229 else if (unformat (i, "sw_if_index %d", &sw_if_index))
3230 sw_if_index_set = 1;
3235 if (sw_if_index_set == 0) {
3236 errmsg ("missing vpp interface name");
3240 /* Construct the API message */
3241 M(TAP_DELETE, tap_delete);
3243 mp->sw_if_index = ntohl(sw_if_index);
3248 /* Wait for a reply... */
3252 static int api_ip_add_del_route (vat_main_t * vam)
3254 unformat_input_t * i = vam->input;
3255 vl_api_ip_add_del_route_t *mp;
3257 u32 sw_if_index = 0, vrf_id = 0;
3258 u8 sw_if_index_set = 0;
3260 u8 is_local = 0, is_drop = 0;
3261 u8 create_vrf_if_needed = 0;
3263 u8 next_hop_weight = 1;
3265 u8 is_multipath = 0;
3267 u8 address_length_set = 0;
3268 u32 lookup_in_vrf = 0;
3269 u32 resolve_attempts = 0;
3270 u32 dst_address_length = 0;
3271 u8 next_hop_set = 0;
3272 ip4_address_t v4_dst_address, v4_next_hop_address;
3273 ip6_address_t v6_dst_address, v6_next_hop_address;
3277 u32 random_add_del = 0;
3278 u32 * random_vector = 0;
3279 uword * random_hash;
3280 u32 random_seed = 0xdeaddabe;
3281 u32 classify_table_index = ~0;
3284 /* Parse args required to build the message */
3285 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
3286 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
3287 sw_if_index_set = 1;
3288 else if (unformat (i, "sw_if_index %d", &sw_if_index))
3289 sw_if_index_set = 1;
3290 else if (unformat (i, "%U", unformat_ip4_address,
3295 else if (unformat (i, "%U", unformat_ip6_address, &v6_dst_address)) {
3299 else if (unformat (i, "/%d", &dst_address_length)) {
3300 address_length_set = 1;
3303 else if (is_ipv6 == 0 && unformat (i, "via %U", unformat_ip4_address,
3304 &v4_next_hop_address)) {
3307 else if (is_ipv6 == 1 && unformat (i, "via %U", unformat_ip6_address,
3308 &v6_next_hop_address)) {
3311 else if (unformat (i, "resolve-attempts %d", &resolve_attempts))
3313 else if (unformat (i, "weight %d", &next_hop_weight))
3315 else if (unformat (i, "drop")) {
3317 } else if (unformat (i, "local")) {
3319 } else if (unformat (i, "classify %d", &classify_table_index)) {
3321 } else if (unformat (i, "del"))
3323 else if (unformat (i, "add"))
3325 else if (unformat (i, "not-last"))
3327 else if (unformat (i, "multipath"))
3329 else if (unformat (i, "vrf %d", &vrf_id))
3331 else if (unformat (i, "create-vrf"))
3332 create_vrf_if_needed = 1;
3333 else if (unformat (i, "count %d", &count))
3335 else if (unformat (i, "lookup-in-vrf %d", &lookup_in_vrf))
3337 else if (unformat (i, "random"))
3339 else if (unformat (i, "seed %d", &random_seed))
3342 clib_warning ("parse error '%U'", format_unformat_error, i);
3347 if (resolve_attempts > 0 && sw_if_index_set == 0) {
3348 errmsg ("ARP resolution needs explicit interface or sw_if_index\n");
3352 if (!next_hop_set && !is_drop && !is_local && !is_classify) {
3353 errmsg ("next hop / local / drop / classify not set\n");
3357 if (address_set == 0) {
3358 errmsg ("missing addresses\n");
3362 if (address_length_set == 0) {
3363 errmsg ("missing address length\n");
3367 /* Generate a pile of unique, random routes */
3368 if (random_add_del) {
3369 u32 this_random_address;
3370 random_hash = hash_create (count, sizeof(uword));
3372 hash_set (random_hash, v4_next_hop_address.as_u32, 1);
3373 for (j = 0; j <= count; j++) {
3375 this_random_address = random_u32 (&random_seed);
3376 this_random_address =
3377 clib_host_to_net_u32 (this_random_address);
3378 } while (hash_get (random_hash, this_random_address));
3379 vec_add1 (random_vector, this_random_address);
3380 hash_set (random_hash, this_random_address, 1);
3382 hash_free (random_hash);
3383 v4_dst_address.as_u32 = random_vector[0];
3387 /* Turn on async mode */
3388 vam->async_mode = 1;
3389 vam->async_errors = 0;
3390 before = vat_time_now(vam);
3393 for (j = 0; j < count; j++) {
3394 /* Construct the API message */
3395 M(IP_ADD_DEL_ROUTE, ip_add_del_route);
3397 mp->next_hop_sw_if_index = ntohl (sw_if_index);
3398 mp->vrf_id = ntohl (vrf_id);
3399 if (resolve_attempts > 0) {
3400 mp->resolve_attempts = ntohl (resolve_attempts);
3401 mp->resolve_if_needed = 1;
3403 mp->create_vrf_if_needed = create_vrf_if_needed;
3405 mp->is_add = is_add;
3406 mp->is_drop = is_drop;
3407 mp->is_ipv6 = is_ipv6;
3408 mp->is_local = is_local;
3409 mp->is_classify = is_classify;
3410 mp->is_multipath = is_multipath;
3411 mp->not_last = not_last;
3412 mp->next_hop_weight = next_hop_weight;
3413 mp->dst_address_length = dst_address_length;
3414 mp->lookup_in_vrf = ntohl(lookup_in_vrf);
3415 mp->classify_table_index = ntohl(classify_table_index);
3418 memcpy (mp->dst_address, &v6_dst_address, sizeof (v6_dst_address));
3420 memcpy (mp->next_hop_address, &v6_next_hop_address,
3421 sizeof (v6_next_hop_address));
3422 increment_v6_address (&v6_dst_address);
3424 memcpy (mp->dst_address, &v4_dst_address, sizeof (v4_dst_address));
3426 memcpy (mp->next_hop_address, &v4_next_hop_address,
3427 sizeof (v4_next_hop_address));
3429 v4_dst_address.as_u32 = random_vector[j+1];
3431 increment_v4_address (&v4_dst_address);
3437 /* When testing multiple add/del ops, use a control-ping to sync */
3439 vl_api_control_ping_t * mp;
3442 /* Shut off async mode */
3443 vam->async_mode = 0;
3445 M(CONTROL_PING, control_ping);
3448 timeout = vat_time_now(vam) + 1.0;
3449 while (vat_time_now (vam) < timeout)
3450 if (vam->result_ready == 1)
3455 if (vam->retval == -99)
3456 errmsg ("timeout\n");
3458 if (vam->async_errors > 0) {
3459 errmsg ("%d asynchronous errors\n", vam->async_errors);
3462 vam->async_errors = 0;
3463 after = vat_time_now(vam);
3465 fformat(vam->ofp, "%d routes in %.6f secs, %.2f routes/sec\n",
3466 count, after - before, count / (after - before));
3468 /* Wait for a reply... */
3472 /* Return the good/bad news */
3473 return (vam->retval);
3476 static int api_proxy_arp_add_del (vat_main_t * vam)
3478 unformat_input_t * i = vam->input;
3479 vl_api_proxy_arp_add_del_t *mp;
3483 ip4_address_t lo, hi;
3486 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
3487 if (unformat (i, "vrf %d", &vrf_id))
3489 else if (unformat (i, "%U - %U", unformat_ip4_address, &lo,
3490 unformat_ip4_address, &hi))
3492 else if (unformat (i, "del"))
3495 clib_warning ("parse error '%U'", format_unformat_error, i);
3500 if (range_set == 0) {
3501 errmsg ("address range not set\n");
3505 M(PROXY_ARP_ADD_DEL, proxy_arp_add_del);
3507 mp->vrf_id = ntohl(vrf_id);
3508 mp->is_add = is_add;
3509 memcpy(mp->low_address, &lo, sizeof (mp->low_address));
3510 memcpy(mp->hi_address, &hi, sizeof (mp->hi_address));
3517 static int api_proxy_arp_intfc_enable_disable (vat_main_t * vam)
3519 unformat_input_t * i = vam->input;
3520 vl_api_proxy_arp_intfc_enable_disable_t *mp;
3524 u8 sw_if_index_set = 0;
3526 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
3527 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
3528 sw_if_index_set = 1;
3529 else if (unformat (i, "sw_if_index %d", &sw_if_index))
3530 sw_if_index_set = 1;
3531 else if (unformat (i, "enable"))
3533 else if (unformat (i, "disable"))
3536 clib_warning ("parse error '%U'", format_unformat_error, i);
3541 if (sw_if_index_set == 0) {
3542 errmsg ("missing interface name or sw_if_index\n");
3546 M(PROXY_ARP_INTFC_ENABLE_DISABLE, proxy_arp_intfc_enable_disable);
3548 mp->sw_if_index = ntohl(sw_if_index);
3549 mp->enable_disable = enable;
3556 static int api_mpls_add_del_decap (vat_main_t * vam)
3558 unformat_input_t * i = vam->input;
3559 vl_api_mpls_add_del_decap_t *mp;
3568 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
3569 if (unformat (i, "rx_vrf_id %d", &rx_vrf_id))
3571 else if (unformat (i, "tx_vrf_id %d", &tx_vrf_id))
3573 else if (unformat (i, "label %d", &label))
3575 else if (unformat (i, "next-index %d", &next_index))
3577 else if (unformat (i, "del"))
3579 else if (unformat (i, "s-bit-clear"))
3582 clib_warning ("parse error '%U'", format_unformat_error, i);
3587 M(MPLS_ADD_DEL_DECAP, mpls_add_del_decap);
3589 mp->rx_vrf_id = ntohl(rx_vrf_id);
3590 mp->tx_vrf_id = ntohl(tx_vrf_id);
3591 mp->label = ntohl(label);
3592 mp->next_index = ntohl(next_index);
3594 mp->is_add = is_add;
3601 static int api_mpls_add_del_encap (vat_main_t * vam)
3603 unformat_input_t * i = vam->input;
3604 vl_api_mpls_add_del_encap_t *mp;
3609 ip4_address_t dst_address;
3612 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
3613 if (unformat (i, "vrf %d", &vrf_id))
3615 else if (unformat (i, "label %d", &label))
3616 vec_add1 (labels, ntohl(label));
3617 else if (unformat (i, "dst %U", unformat_ip4_address, &dst_address))
3619 else if (unformat (i, "del"))
3622 clib_warning ("parse error '%U'", format_unformat_error, i);
3627 if (vec_len (labels) == 0) {
3628 errmsg ("missing encap label stack\n");
3632 M2(MPLS_ADD_DEL_ENCAP, mpls_add_del_encap,
3633 sizeof (u32) * vec_len (labels));
3635 mp->vrf_id = ntohl(vrf_id);
3636 memcpy(mp->dst_address, &dst_address, sizeof (dst_address));
3637 mp->is_add = is_add;
3638 mp->nlabels = vec_len (labels);
3639 memcpy(mp->labels, labels, sizeof(u32)*mp->nlabels);
3648 static int api_mpls_gre_add_del_tunnel (vat_main_t * vam)
3650 unformat_input_t * i = vam->input;
3651 vl_api_mpls_gre_add_del_tunnel_t *mp;
3653 u32 inner_vrf_id = 0;
3654 u32 outer_vrf_id = 0;
3655 ip4_address_t src_address;
3656 ip4_address_t dst_address;
3657 ip4_address_t intfc_address;
3659 u8 intfc_address_length = 0;
3663 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
3664 if (unformat (i, "inner_vrf_id %d", &inner_vrf_id))
3666 else if (unformat (i, "outer_vrf_id %d", &outer_vrf_id))
3668 else if (unformat (i, "src %U", unformat_ip4_address, &src_address))
3670 else if (unformat (i, "dst %U", unformat_ip4_address, &dst_address))
3672 else if (unformat (i, "adj %U/%d", unformat_ip4_address,
3673 &intfc_address, &tmp))
3674 intfc_address_length = tmp;
3675 else if (unformat (i, "l2-only"))
3677 else if (unformat (i, "del"))
3680 clib_warning ("parse error '%U'", format_unformat_error, i);
3685 M(MPLS_GRE_ADD_DEL_TUNNEL, mpls_gre_add_del_tunnel);
3687 mp->inner_vrf_id = ntohl(inner_vrf_id);
3688 mp->outer_vrf_id = ntohl(outer_vrf_id);
3689 memcpy(mp->src_address, &src_address, sizeof (src_address));
3690 memcpy(mp->dst_address, &dst_address, sizeof (dst_address));
3691 memcpy(mp->intfc_address, &intfc_address, sizeof (intfc_address));
3692 mp->intfc_address_length = intfc_address_length;
3693 mp->l2_only = l2_only;
3694 mp->is_add = is_add;
3701 static int api_mpls_ethernet_add_del_tunnel (vat_main_t * vam)
3703 unformat_input_t * i = vam->input;
3704 vl_api_mpls_ethernet_add_del_tunnel_t *mp;
3706 u32 inner_vrf_id = 0;
3707 ip4_address_t intfc_address;
3708 u8 dst_mac_address[6];
3711 u8 intfc_address_length = 0;
3715 int tx_sw_if_index_set = 0;
3717 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
3718 if (unformat (i, "vrf %d", &inner_vrf_id))
3720 else if (unformat (i, "adj %U/%d", unformat_ip4_address,
3721 &intfc_address, &tmp))
3722 intfc_address_length = tmp;
3723 else if (unformat (i, "%U",
3724 unformat_sw_if_index, vam, &tx_sw_if_index))
3725 tx_sw_if_index_set = 1;
3726 else if (unformat (i, "tx_sw_if_index %d", &tx_sw_if_index))
3727 tx_sw_if_index_set = 1;
3728 else if (unformat (i, "dst %U", unformat_ethernet_address,
3731 else if (unformat (i, "l2-only"))
3733 else if (unformat (i, "del"))
3736 clib_warning ("parse error '%U'", format_unformat_error, i);
3742 errmsg ("dst (mac address) not set\n");
3745 if (!tx_sw_if_index_set) {
3746 errmsg ("tx-intfc not set\n");
3750 M(MPLS_ETHERNET_ADD_DEL_TUNNEL, mpls_ethernet_add_del_tunnel);
3752 mp->vrf_id = ntohl(inner_vrf_id);
3753 memcpy (mp->adj_address, &intfc_address, sizeof (intfc_address));
3754 mp->adj_address_length = intfc_address_length;
3755 memcpy (mp->dst_mac_address, dst_mac_address, sizeof (dst_mac_address));
3756 mp->tx_sw_if_index = ntohl(tx_sw_if_index);
3757 mp->l2_only = l2_only;
3758 mp->is_add = is_add;
3765 static int api_mpls_ethernet_add_del_tunnel_2 (vat_main_t * vam)
3767 unformat_input_t * i = vam->input;
3768 vl_api_mpls_ethernet_add_del_tunnel_2_t *mp;
3770 u32 inner_vrf_id = 0;
3771 u32 outer_vrf_id = 0;
3772 ip4_address_t adj_address;
3773 int adj_address_set = 0;
3774 ip4_address_t next_hop_address;
3775 int next_hop_address_set = 0;
3777 u8 adj_address_length = 0;
3780 u32 resolve_attempts = 5;
3781 u8 resolve_if_needed = 1;
3783 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
3784 if (unformat (i, "inner_vrf_id %d", &inner_vrf_id))
3786 else if (unformat (i, "outer_vrf_id %d", &outer_vrf_id))
3788 else if (unformat (i, "adj %U/%d", unformat_ip4_address,
3789 &adj_address, &tmp)) {
3790 adj_address_length = tmp;
3791 adj_address_set = 1;
3793 else if (unformat (i, "next-hop %U", unformat_ip4_address,
3795 next_hop_address_set = 1;
3796 else if (unformat (i, "resolve-attempts %d", &resolve_attempts))
3798 else if (unformat (i, "resolve-if-needed %d", &tmp))
3799 resolve_if_needed = tmp;
3800 else if (unformat (i, "l2-only"))
3802 else if (unformat (i, "del"))
3805 clib_warning ("parse error '%U'", format_unformat_error, i);
3810 if (!adj_address_set) {
3811 errmsg ("adjacency address/mask not set\n");
3814 if (!next_hop_address_set) {
3815 errmsg ("ip4 next hop address (in outer fib) not set\n");
3819 M(MPLS_ETHERNET_ADD_DEL_TUNNEL_2, mpls_ethernet_add_del_tunnel_2);
3821 mp->inner_vrf_id = ntohl(inner_vrf_id);
3822 mp->outer_vrf_id = ntohl(outer_vrf_id);
3823 mp->resolve_attempts = ntohl(resolve_attempts);
3824 mp->resolve_if_needed = resolve_if_needed;
3825 mp->is_add = is_add;
3826 mp->l2_only = l2_only;
3827 memcpy (mp->adj_address, &adj_address, sizeof (adj_address));
3828 mp->adj_address_length = adj_address_length;
3829 memcpy (mp->next_hop_ip4_address_in_outer_vrf, &next_hop_address,
3830 sizeof (next_hop_address));
3837 static int api_sw_interface_set_unnumbered (vat_main_t * vam)
3839 unformat_input_t * i = vam->input;
3840 vl_api_sw_interface_set_unnumbered_t *mp;
3845 u8 sw_if_index_set = 0;
3847 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
3848 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
3849 sw_if_index_set = 1;
3850 else if (unformat (i, "sw_if_index %d", &sw_if_index))
3851 sw_if_index_set = 1;
3852 else if (unformat (i, "unnum_if_index %d", &unnum_sw_index))
3854 else if (unformat (i, "del"))
3857 clib_warning ("parse error '%U'", format_unformat_error, i);
3862 if (sw_if_index_set == 0) {
3863 errmsg ("missing interface name or sw_if_index\n");
3867 M(SW_INTERFACE_SET_UNNUMBERED, sw_interface_set_unnumbered);
3869 mp->sw_if_index = ntohl(sw_if_index);
3870 mp->unnumbered_sw_if_index = ntohl(unnum_sw_index);
3871 mp->is_add = is_add;
3878 static int api_ip_neighbor_add_del (vat_main_t * vam)
3880 unformat_input_t * i = vam->input;
3881 vl_api_ip_neighbor_add_del_t *mp;
3884 u8 sw_if_index_set = 0;
3890 u8 v4_address_set = 0;
3891 u8 v6_address_set = 0;
3892 ip4_address_t v4address;
3893 ip6_address_t v6address;
3895 memset (mac_address, 0, sizeof (mac_address));
3897 /* Parse args required to build the message */
3898 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
3899 if (unformat (i, "mac %U", unformat_ethernet_address, mac_address)) {
3902 else if (unformat (i, "del"))
3904 else if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
3905 sw_if_index_set = 1;
3906 else if (unformat (i, "sw_if_index %d", &sw_if_index))
3907 sw_if_index_set = 1;
3908 else if (unformat (i, "is_static"))
3910 else if (unformat (i, "vrf %d", &vrf_id))
3912 else if (unformat (i, "dst %U",
3913 unformat_ip4_address, &v4address))
3915 else if (unformat (i, "dst %U",
3916 unformat_ip6_address, &v6address))
3919 clib_warning ("parse error '%U'", format_unformat_error, i);
3924 if (sw_if_index_set == 0) {
3925 errmsg ("missing interface name or sw_if_index\n");
3928 if (v4_address_set && v6_address_set) {
3929 errmsg ("both v4 and v6 addresses set\n");
3932 if (!v4_address_set && !v6_address_set) {
3933 errmsg ("no addresses set\n");
3937 /* Construct the API message */
3938 M(IP_NEIGHBOR_ADD_DEL, ip_neighbor_add_del);
3940 mp->sw_if_index = ntohl (sw_if_index);
3941 mp->is_add = is_add;
3942 mp->vrf_id = ntohl (vrf_id);
3943 mp->is_static = is_static;
3945 memcpy (mp->mac_address, mac_address, 6);
3946 if (v6_address_set) {
3948 memcpy (mp->dst_address, &v6address, sizeof (v6address));
3950 /* mp->is_ipv6 = 0; via memset in M macro above */
3951 memcpy (mp->dst_address, &v4address, sizeof (v4address));
3957 /* Wait for a reply, return good/bad news */
3964 static int api_reset_vrf (vat_main_t * vam)
3966 unformat_input_t * i = vam->input;
3967 vl_api_reset_vrf_t *mp;
3973 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
3974 if (unformat (i, "vrf %d", &vrf_id))
3976 else if (unformat (i, "ipv6"))
3979 clib_warning ("parse error '%U'", format_unformat_error, i);
3984 if (vrf_id_set == 0) {
3985 errmsg ("missing vrf id\n");
3989 M(RESET_VRF, reset_vrf);
3991 mp->vrf_id = ntohl(vrf_id);
3992 mp->is_ipv6 = is_ipv6;
3999 static int api_create_vlan_subif (vat_main_t * vam)
4001 unformat_input_t * i = vam->input;
4002 vl_api_create_vlan_subif_t *mp;
4005 u8 sw_if_index_set = 0;
4009 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
4010 if (unformat (i, "sw_if_index %d", &sw_if_index))
4011 sw_if_index_set = 1;
4012 else if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
4013 sw_if_index_set = 1;
4014 else if (unformat (i, "vlan %d", &vlan_id))
4017 clib_warning ("parse error '%U'", format_unformat_error, i);
4022 if (sw_if_index_set == 0) {
4023 errmsg ("missing interface name or sw_if_index\n");
4027 if (vlan_id_set == 0) {
4028 errmsg ("missing vlan_id\n");
4031 M(CREATE_VLAN_SUBIF, create_vlan_subif);
4033 mp->sw_if_index = ntohl(sw_if_index);
4034 mp->vlan_id = ntohl(vlan_id);
4041 #define foreach_create_subif_bit \
4048 _(outer_vlan_id_any) \
4049 _(inner_vlan_id_any)
4051 static int api_create_subif (vat_main_t * vam)
4053 unformat_input_t * i = vam->input;
4054 vl_api_create_subif_t *mp;
4057 u8 sw_if_index_set = 0;
4064 u32 exact_match = 0;
4065 u32 default_sub = 0;
4066 u32 outer_vlan_id_any = 0;
4067 u32 inner_vlan_id_any = 0;
4069 u16 outer_vlan_id = 0;
4070 u16 inner_vlan_id = 0;
4072 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
4073 if (unformat (i, "sw_if_index %d", &sw_if_index))
4074 sw_if_index_set = 1;
4075 else if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
4076 sw_if_index_set = 1;
4077 else if (unformat (i, "sub_id %d", &sub_id))
4079 else if (unformat (i, "outer_vlan_id %d", &tmp))
4080 outer_vlan_id = tmp;
4081 else if (unformat (i, "inner_vlan_id %d", &tmp))
4082 inner_vlan_id = tmp;
4084 #define _(a) else if (unformat (i, #a)) a = 1 ;
4085 foreach_create_subif_bit
4089 clib_warning ("parse error '%U'", format_unformat_error, i);
4094 if (sw_if_index_set == 0) {
4095 errmsg ("missing interface name or sw_if_index\n");
4099 if (sub_id_set == 0) {
4100 errmsg ("missing sub_id\n");
4103 M(CREATE_SUBIF, create_subif);
4105 mp->sw_if_index = ntohl(sw_if_index);
4106 mp->sub_id = ntohl(sub_id);
4108 #define _(a) mp->a = a;
4109 foreach_create_subif_bit;
4112 mp->outer_vlan_id = ntohs (outer_vlan_id);
4113 mp->inner_vlan_id = ntohs (inner_vlan_id);
4120 static int api_oam_add_del (vat_main_t * vam)
4122 unformat_input_t * i = vam->input;
4123 vl_api_oam_add_del_t *mp;
4127 ip4_address_t src, dst;
4131 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
4132 if (unformat (i, "vrf %d", &vrf_id))
4134 else if (unformat (i, "src %U", unformat_ip4_address, &src))
4136 else if (unformat (i, "dst %U", unformat_ip4_address, &dst))
4138 else if (unformat (i, "del"))
4141 clib_warning ("parse error '%U'", format_unformat_error, i);
4147 errmsg ("missing src addr\n");
4152 errmsg ("missing dst addr\n");
4156 M(OAM_ADD_DEL, oam_add_del);
4158 mp->vrf_id = ntohl(vrf_id);
4159 mp->is_add = is_add;
4160 memcpy(mp->src_address, &src, sizeof (mp->src_address));
4161 memcpy(mp->dst_address, &dst, sizeof (mp->dst_address));
4168 static int api_reset_fib (vat_main_t * vam)
4170 unformat_input_t * i = vam->input;
4171 vl_api_reset_fib_t *mp;
4177 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
4178 if (unformat (i, "vrf %d", &vrf_id))
4180 else if (unformat (i, "ipv6"))
4183 clib_warning ("parse error '%U'", format_unformat_error, i);
4188 if (vrf_id_set == 0) {
4189 errmsg ("missing vrf id\n");
4193 M(RESET_FIB, reset_fib);
4195 mp->vrf_id = ntohl(vrf_id);
4196 mp->is_ipv6 = is_ipv6;
4203 static int api_dhcp_proxy_config (vat_main_t * vam)
4205 unformat_input_t * i = vam->input;
4206 vl_api_dhcp_proxy_config_t *mp;
4211 u8 v4_address_set = 0;
4212 u8 v6_address_set = 0;
4213 ip4_address_t v4address;
4214 ip6_address_t v6address;
4215 u8 v4_src_address_set = 0;
4216 u8 v6_src_address_set = 0;
4217 ip4_address_t v4srcaddress;
4218 ip6_address_t v6srcaddress;
4220 /* Parse args required to build the message */
4221 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
4222 if (unformat (i, "del"))
4224 else if (unformat (i, "vrf %d", &vrf_id))
4226 else if (unformat (i, "insert-cid %d", &insert_cid))
4228 else if (unformat (i, "svr %U",
4229 unformat_ip4_address, &v4address))
4231 else if (unformat (i, "svr %U",
4232 unformat_ip6_address, &v6address))
4234 else if (unformat (i, "src %U",
4235 unformat_ip4_address, &v4srcaddress))
4236 v4_src_address_set = 1;
4237 else if (unformat (i, "src %U",
4238 unformat_ip6_address, &v6srcaddress))
4239 v6_src_address_set = 1;
4244 if (v4_address_set && v6_address_set) {
4245 errmsg ("both v4 and v6 server addresses set\n");
4248 if (!v4_address_set && !v6_address_set) {
4249 errmsg ("no server addresses set\n");
4253 if (v4_src_address_set && v6_src_address_set) {
4254 errmsg ("both v4 and v6 src addresses set\n");
4257 if (!v4_src_address_set && !v6_src_address_set) {
4258 errmsg ("no src addresses set\n");
4262 if (!(v4_src_address_set && v4_address_set) &&
4263 !(v6_src_address_set && v6_address_set)) {
4264 errmsg ("no matching server and src addresses set\n");
4268 /* Construct the API message */
4269 M(DHCP_PROXY_CONFIG, dhcp_proxy_config);
4271 mp->insert_circuit_id = insert_cid;
4272 mp->is_add = is_add;
4273 mp->vrf_id = ntohl (vrf_id);
4274 if (v6_address_set) {
4276 memcpy (mp->dhcp_server, &v6address, sizeof (v6address));
4277 memcpy (mp->dhcp_src_address, &v6srcaddress, sizeof (v6address));
4279 memcpy (mp->dhcp_server, &v4address, sizeof (v4address));
4280 memcpy (mp->dhcp_src_address, &v4srcaddress, sizeof (v4address));
4286 /* Wait for a reply, return good/bad news */
4292 static int api_dhcp_proxy_config_2 (vat_main_t * vam)
4294 unformat_input_t * i = vam->input;
4295 vl_api_dhcp_proxy_config_2_t *mp;
4298 u32 server_vrf_id = 0;
4301 u8 v4_address_set = 0;
4302 u8 v6_address_set = 0;
4303 ip4_address_t v4address;
4304 ip6_address_t v6address;
4305 u8 v4_src_address_set = 0;
4306 u8 v6_src_address_set = 0;
4307 ip4_address_t v4srcaddress;
4308 ip6_address_t v6srcaddress;
4310 /* Parse args required to build the message */
4311 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
4312 if (unformat (i, "del"))
4314 else if (unformat (i, "rx_vrf_id %d", &rx_vrf_id))
4316 else if (unformat (i, "server_vrf_id %d", &server_vrf_id))
4318 else if (unformat (i, "insert-cid %d", &insert_cid))
4320 else if (unformat (i, "svr %U",
4321 unformat_ip4_address, &v4address))
4323 else if (unformat (i, "svr %U",
4324 unformat_ip6_address, &v6address))
4326 else if (unformat (i, "src %U",
4327 unformat_ip4_address, &v4srcaddress))
4328 v4_src_address_set = 1;
4329 else if (unformat (i, "src %U",
4330 unformat_ip6_address, &v6srcaddress))
4331 v6_src_address_set = 1;
4336 if (v4_address_set && v6_address_set) {
4337 errmsg ("both v4 and v6 server addresses set\n");
4340 if (!v4_address_set && !v6_address_set) {
4341 errmsg ("no server addresses set\n");
4345 if (v4_src_address_set && v6_src_address_set) {
4346 errmsg ("both v4 and v6 src addresses set\n");
4349 if (!v4_src_address_set && !v6_src_address_set) {
4350 errmsg ("no src addresses set\n");
4354 if (!(v4_src_address_set && v4_address_set) &&
4355 !(v6_src_address_set && v6_address_set)) {
4356 errmsg ("no matching server and src addresses set\n");
4360 /* Construct the API message */
4361 M(DHCP_PROXY_CONFIG_2, dhcp_proxy_config_2);
4363 mp->insert_circuit_id = insert_cid;
4364 mp->is_add = is_add;
4365 mp->rx_vrf_id = ntohl (rx_vrf_id);
4366 mp->server_vrf_id = ntohl (server_vrf_id);
4367 if (v6_address_set) {
4369 memcpy (mp->dhcp_server, &v6address, sizeof (v6address));
4370 memcpy (mp->dhcp_src_address, &v6srcaddress, sizeof (v6address));
4372 memcpy (mp->dhcp_server, &v4address, sizeof (v4address));
4373 memcpy (mp->dhcp_src_address, &v4srcaddress, sizeof (v4address));
4379 /* Wait for a reply, return good/bad news */
4385 static int api_dhcp_proxy_set_vss (vat_main_t * vam)
4387 unformat_input_t * i = vam->input;
4388 vl_api_dhcp_proxy_set_vss_t *mp;
4399 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
4400 if (unformat (i, "tbl_id %d", &tbl_id))
4402 if (unformat (i, "fib_id %d", &fib_id))
4404 if (unformat (i, "oui %d", &oui))
4406 else if (unformat (i, "ipv6"))
4408 else if (unformat (i, "del"))
4411 clib_warning ("parse error '%U'", format_unformat_error, i);
4416 if (tbl_id_set == 0) {
4417 errmsg ("missing tbl id\n");
4421 if (fib_id_set == 0) {
4422 errmsg ("missing fib id\n");
4426 errmsg ("missing oui\n");
4430 M(DHCP_PROXY_SET_VSS, dhcp_proxy_set_vss);
4431 mp->tbl_id = ntohl(tbl_id);
4432 mp->fib_id = ntohl(fib_id);
4433 mp->oui = ntohl(oui);
4434 mp->is_ipv6 = is_ipv6;
4435 mp->is_add = is_add;
4442 static int api_dhcp_client_config (vat_main_t * vam)
4444 unformat_input_t * i = vam->input;
4445 vl_api_dhcp_client_config_t *mp;
4448 u8 sw_if_index_set = 0;
4451 u8 disable_event = 0;
4453 /* Parse args required to build the message */
4454 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
4455 if (unformat (i, "del"))
4457 else if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
4458 sw_if_index_set = 1;
4459 else if (unformat (i, "sw_if_index %d", &sw_if_index))
4460 sw_if_index_set = 1;
4461 else if (unformat (i, "hostname %s", &hostname))
4463 else if (unformat (i, "disable_event"))
4469 if (sw_if_index_set == 0) {
4470 errmsg ("missing interface name or sw_if_index\n");
4474 if (vec_len (hostname) > 63) {
4475 errmsg ("hostname too long\n");
4477 vec_add1 (hostname, 0);
4479 /* Construct the API message */
4480 M(DHCP_CLIENT_CONFIG, dhcp_client_config);
4482 mp->sw_if_index = ntohl (sw_if_index);
4483 memcpy (mp->hostname, hostname, vec_len (hostname));
4484 vec_free (hostname);
4485 mp->is_add = is_add;
4486 mp->want_dhcp_event = disable_event ? 0 : 1;
4492 /* Wait for a reply, return good/bad news */
4498 static int api_set_ip_flow_hash (vat_main_t * vam)
4500 unformat_input_t * i = vam->input;
4501 vl_api_set_ip_flow_hash_t *mp;
4513 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
4514 if (unformat (i, "vrf %d", &vrf_id))
4516 else if (unformat (i, "ipv6"))
4518 else if (unformat (i, "src"))
4520 else if (unformat (i, "dst"))
4522 else if (unformat (i, "sport"))
4524 else if (unformat (i, "dport"))
4526 else if (unformat (i, "proto"))
4528 else if (unformat (i, "reverse"))
4532 clib_warning ("parse error '%U'", format_unformat_error, i);
4537 if (vrf_id_set == 0) {
4538 errmsg ("missing vrf id\n");
4542 M(SET_IP_FLOW_HASH, set_ip_flow_hash);
4548 mp->reverse = reverse;
4549 mp->vrf_id = ntohl(vrf_id);
4550 mp->is_ipv6 = is_ipv6;
4557 static int api_sw_interface_ip6_enable_disable (vat_main_t * vam)
4559 unformat_input_t * i = vam->input;
4560 vl_api_sw_interface_ip6_enable_disable_t *mp;
4563 u8 sw_if_index_set = 0;
4566 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
4567 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
4568 sw_if_index_set = 1;
4569 else if (unformat (i, "sw_if_index %d", &sw_if_index))
4570 sw_if_index_set = 1;
4571 else if (unformat (i, "enable"))
4573 else if (unformat (i, "disable"))
4576 clib_warning ("parse error '%U'", format_unformat_error, i);
4581 if (sw_if_index_set == 0) {
4582 errmsg ("missing interface name or sw_if_index\n");
4586 M(SW_INTERFACE_IP6_ENABLE_DISABLE, sw_interface_ip6_enable_disable);
4588 mp->sw_if_index = ntohl(sw_if_index);
4589 mp->enable = enable;
4596 static int api_sw_interface_ip6_set_link_local_address (vat_main_t * vam)
4598 unformat_input_t * i = vam->input;
4599 vl_api_sw_interface_ip6_set_link_local_address_t *mp;
4602 u8 sw_if_index_set = 0;
4603 u32 address_length = 0;
4604 u8 v6_address_set = 0;
4605 ip6_address_t v6address;
4607 /* Parse args required to build the message */
4608 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
4609 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
4610 sw_if_index_set = 1;
4611 else if (unformat (i, "sw_if_index %d", &sw_if_index))
4612 sw_if_index_set = 1;
4613 else if (unformat (i, "%U/%d",
4614 unformat_ip6_address, &v6address,
4621 if (sw_if_index_set == 0) {
4622 errmsg ("missing interface name or sw_if_index\n");
4625 if (!v6_address_set) {
4626 errmsg ("no address set\n");
4630 /* Construct the API message */
4631 M(SW_INTERFACE_IP6_SET_LINK_LOCAL_ADDRESS, \
4632 sw_interface_ip6_set_link_local_address);
4634 mp->sw_if_index = ntohl (sw_if_index);
4635 memcpy (mp->address, &v6address, sizeof (v6address));
4636 mp->address_length = address_length;
4641 /* Wait for a reply, return good/bad news */
4649 static int api_sw_interface_ip6nd_ra_prefix (vat_main_t * vam)
4651 unformat_input_t * i = vam->input;
4652 vl_api_sw_interface_ip6nd_ra_prefix_t *mp;
4655 u8 sw_if_index_set = 0;
4656 u32 address_length = 0;
4657 u8 v6_address_set = 0;
4658 ip6_address_t v6address;
4660 u8 no_advertise = 0;
4662 u8 no_autoconfig = 0;
4665 u32 val_lifetime = 0;
4666 u32 pref_lifetime = 0;
4668 /* Parse args required to build the message */
4669 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
4670 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
4671 sw_if_index_set = 1;
4672 else if (unformat (i, "sw_if_index %d", &sw_if_index))
4673 sw_if_index_set = 1;
4674 else if (unformat (i, "%U/%d",
4675 unformat_ip6_address, &v6address,
4678 else if (unformat (i, "val_life %d", &val_lifetime))
4680 else if (unformat (i, "pref_life %d", &pref_lifetime))
4682 else if (unformat (i, "def"))
4684 else if (unformat (i, "noadv"))
4686 else if (unformat (i, "offl"))
4688 else if (unformat (i, "noauto"))
4690 else if (unformat (i, "nolink"))
4692 else if (unformat (i, "isno"))
4695 clib_warning ("parse error '%U'", format_unformat_error, i);
4700 if (sw_if_index_set == 0) {
4701 errmsg ("missing interface name or sw_if_index\n");
4704 if (!v6_address_set) {
4705 errmsg ("no address set\n");
4709 /* Construct the API message */
4710 M(SW_INTERFACE_IP6ND_RA_PREFIX, sw_interface_ip6nd_ra_prefix);
4712 mp->sw_if_index = ntohl (sw_if_index);
4713 memcpy (mp->address, &v6address, sizeof (v6address));
4714 mp->address_length = address_length;
4715 mp->use_default = use_default;
4716 mp->no_advertise = no_advertise;
4717 mp->off_link = off_link;
4718 mp->no_autoconfig = no_autoconfig;
4719 mp->no_onlink = no_onlink;
4721 mp->val_lifetime = ntohl(val_lifetime);
4722 mp->pref_lifetime = ntohl(pref_lifetime);
4727 /* Wait for a reply, return good/bad news */
4734 static int api_sw_interface_ip6nd_ra_config (vat_main_t * vam)
4736 unformat_input_t * i = vam->input;
4737 vl_api_sw_interface_ip6nd_ra_config_t *mp;
4740 u8 sw_if_index_set = 0;
4745 u8 send_unicast = 0;
4748 u8 default_router = 0;
4749 u32 max_interval = 0;
4750 u32 min_interval = 0;
4752 u32 initial_count = 0;
4753 u32 initial_interval = 0;
4756 /* Parse args required to build the message */
4757 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
4758 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
4759 sw_if_index_set = 1;
4760 else if (unformat (i, "sw_if_index %d", &sw_if_index))
4761 sw_if_index_set = 1;
4762 else if (unformat (i, "maxint %d", &max_interval))
4764 else if (unformat (i, "minint %d", &min_interval))
4766 else if (unformat (i, "life %d", &lifetime))
4768 else if (unformat (i, "count %d", &initial_count))
4770 else if (unformat (i, "interval %d", &initial_interval))
4772 else if (unformat (i, "surpress"))
4774 else if (unformat (i, "managed"))
4776 else if (unformat (i, "other"))
4778 else if (unformat (i, "ll"))
4780 else if (unformat (i, "send"))
4782 else if (unformat (i, "cease"))
4784 else if (unformat (i, "isno"))
4786 else if (unformat (i, "def"))
4789 clib_warning ("parse error '%U'", format_unformat_error, i);
4794 if (sw_if_index_set == 0) {
4795 errmsg ("missing interface name or sw_if_index\n");
4799 /* Construct the API message */
4800 M(SW_INTERFACE_IP6ND_RA_CONFIG, sw_interface_ip6nd_ra_config);
4802 mp->sw_if_index = ntohl (sw_if_index);
4803 mp->max_interval = ntohl(max_interval);
4804 mp->min_interval = ntohl(min_interval);
4805 mp->lifetime = ntohl(lifetime);
4806 mp->initial_count = ntohl(initial_count);
4807 mp->initial_interval = ntohl(initial_interval);
4808 mp->surpress = surpress;
4809 mp->managed = managed;
4811 mp->ll_option = ll_option;
4812 mp->send_unicast = send_unicast;
4815 mp->default_router = default_router;
4820 /* Wait for a reply, return good/bad news */
4827 static int api_set_arp_neighbor_limit (vat_main_t * vam)
4829 unformat_input_t * i = vam->input;
4830 vl_api_set_arp_neighbor_limit_t *mp;
4836 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
4837 if (unformat (i, "arp_nbr_limit %d", &arp_nbr_limit))
4839 else if (unformat (i, "ipv6"))
4842 clib_warning ("parse error '%U'", format_unformat_error, i);
4847 if (limit_set == 0) {
4848 errmsg ("missing limit value\n");
4852 M(SET_ARP_NEIGHBOR_LIMIT, set_arp_neighbor_limit);
4854 mp->arp_neighbor_limit = ntohl(arp_nbr_limit);
4855 mp->is_ipv6 = is_ipv6;
4862 static int api_l2_patch_add_del (vat_main_t * vam)
4864 unformat_input_t * i = vam->input;
4865 vl_api_l2_patch_add_del_t *mp;
4868 u8 rx_sw_if_index_set = 0;
4870 u8 tx_sw_if_index_set = 0;
4873 /* Parse args required to build the message */
4874 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
4875 if (unformat (i, "rx_sw_if_index %d", &rx_sw_if_index))
4876 rx_sw_if_index_set = 1;
4877 else if (unformat (i, "tx_sw_if_index %d", &tx_sw_if_index))
4878 tx_sw_if_index_set = 1;
4879 else if (unformat (i, "rx")) {
4880 if (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
4881 if (unformat (i, "%U", unformat_sw_if_index, vam,
4883 rx_sw_if_index_set = 1;
4886 } else if (unformat (i, "tx")) {
4887 if (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
4888 if (unformat (i, "%U", unformat_sw_if_index, vam,
4890 tx_sw_if_index_set = 1;
4893 } else if (unformat (i, "del"))
4899 if (rx_sw_if_index_set == 0) {
4900 errmsg ("missing rx interface name or rx_sw_if_index\n");
4904 if (tx_sw_if_index_set == 0) {
4905 errmsg ("missing tx interface name or tx_sw_if_index\n");
4909 M(L2_PATCH_ADD_DEL, l2_patch_add_del);
4911 mp->rx_sw_if_index = ntohl(rx_sw_if_index);
4912 mp->tx_sw_if_index = ntohl(tx_sw_if_index);
4913 mp->is_add = is_add;
4920 static int api_sr_tunnel_add_del (vat_main_t * vam)
4922 unformat_input_t * i = vam->input;
4923 vl_api_sr_tunnel_add_del_t *mp;
4927 ip6_address_t src_address;
4928 int src_address_set = 0;
4929 ip6_address_t dst_address;
4931 int dst_address_set = 0;
4933 u32 rx_table_id = 0;
4934 u32 tx_table_id = 0;
4935 ip6_address_t * segments = 0;
4936 ip6_address_t * this_seg;
4937 ip6_address_t * tags = 0;
4938 ip6_address_t * this_tag;
4939 ip6_address_t next_address, tag;
4941 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
4943 if (unformat (i, "del"))
4945 else if (unformat (i, "rx_fib_id %d", &rx_table_id))
4947 else if (unformat (i, "tx_fib_id %d", &tx_table_id))
4949 else if (unformat (i, "src %U", unformat_ip6_address, &src_address))
4950 src_address_set = 1;
4951 else if (unformat (i, "dst %U/%d",
4952 unformat_ip6_address, &dst_address,
4954 dst_address_set = 1;
4955 else if (unformat (i, "next %U", unformat_ip6_address,
4958 vec_add2 (segments, this_seg, 1);
4959 memcpy (this_seg->as_u8, next_address.as_u8, sizeof (*this_seg));
4961 else if (unformat (i, "tag %U", unformat_ip6_address,
4964 vec_add2 (tags, this_tag, 1);
4965 memcpy (this_tag->as_u8, tag.as_u8, sizeof (*this_tag));
4967 else if (unformat (i, "clean"))
4968 flags |= IP6_SR_HEADER_FLAG_CLEANUP;
4969 else if (unformat (i, "protected"))
4970 flags |= IP6_SR_HEADER_FLAG_PROTECTED;
4971 else if (unformat (i, "InPE %d", &pl_index))
4973 if (pl_index <= 0 || pl_index > 4)
4975 pl_index_range_error:
4976 errmsg ("pl index %d out of range\n", pl_index);
4979 flags |= IP6_SR_HEADER_FLAG_PL_ELT_INGRESS_PE << (3*(pl_index - 1));
4981 else if (unformat (i, "EgPE %d", &pl_index))
4983 if (pl_index <= 0 || pl_index > 4)
4984 goto pl_index_range_error;
4985 flags |= IP6_SR_HEADER_FLAG_PL_ELT_EGRESS_PE << (3*(pl_index - 1));
4987 else if (unformat (i, "OrgSrc %d", &pl_index))
4989 if (pl_index <= 0 || pl_index > 4)
4990 goto pl_index_range_error;
4991 flags |= IP6_SR_HEADER_FLAG_PL_ELT_ORIG_SRC_ADDR << (3*(pl_index - 1));
4997 if (!src_address_set)
4999 errmsg ("src address required\n");
5003 if (!dst_address_set)
5005 errmsg ("dst address required\n");
5011 errmsg ("at least one sr segment required\n");
5015 M2(SR_TUNNEL_ADD_DEL, sr_tunnel_add_del,
5016 vec_len(segments) * sizeof (ip6_address_t)
5017 + vec_len(tags) * sizeof (ip6_address_t));
5019 memcpy (mp->src_address, &src_address, sizeof (mp->src_address));
5020 memcpy (mp->dst_address, &dst_address, sizeof (mp->dst_address));
5021 mp->dst_mask_width = dst_mask_width;
5022 mp->flags_net_byte_order = clib_host_to_net_u16 (flags);
5023 mp->n_segments = vec_len (segments);
5024 mp->n_tags = vec_len (tags);
5025 mp->is_add = is_del == 0;
5026 memcpy (mp->segs_and_tags, segments,
5027 vec_len(segments)* sizeof (ip6_address_t));
5028 memcpy (mp->segs_and_tags + vec_len(segments)*sizeof (ip6_address_t),
5029 tags, vec_len(tags)* sizeof (ip6_address_t));
5031 mp->outer_vrf_id = ntohl (rx_table_id);
5032 mp->inner_vrf_id = ntohl (tx_table_id);
5034 vec_free (segments);
5042 #define foreach_ip4_proto_field \
5052 uword unformat_ip4_mask (unformat_input_t * input, va_list * args)
5054 u8 ** maskp = va_arg (*args, u8 **);
5056 u8 found_something = 0;
5059 #define _(a) u8 a=0;
5060 foreach_ip4_proto_field;
5066 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
5068 if (unformat (input, "version"))
5070 else if (unformat (input, "hdr_length"))
5072 else if (unformat (input, "src"))
5074 else if (unformat (input, "dst"))
5076 else if (unformat (input, "proto"))
5079 #define _(a) else if (unformat (input, #a)) a=1;
5080 foreach_ip4_proto_field
5086 #define _(a) found_something += a;
5087 foreach_ip4_proto_field;
5090 if (found_something == 0)
5093 vec_validate (mask, sizeof (*ip) - 1);
5095 ip = (ip4_header_t *) mask;
5097 #define _(a) if (a) memset (&ip->a, 0xff, sizeof (ip->a));
5098 foreach_ip4_proto_field;
5101 ip->ip_version_and_header_length = 0;
5104 ip->ip_version_and_header_length |= 0xF0;
5107 ip->ip_version_and_header_length |= 0x0F;
5113 #define foreach_ip6_proto_field \
5120 uword unformat_ip6_mask (unformat_input_t * input, va_list * args)
5122 u8 ** maskp = va_arg (*args, u8 **);
5124 u8 found_something = 0;
5126 u32 ip_version_traffic_class_and_flow_label;
5128 #define _(a) u8 a=0;
5129 foreach_ip6_proto_field;
5132 u8 traffic_class = 0;
5135 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
5137 if (unformat (input, "version"))
5139 else if (unformat (input, "traffic-class"))
5141 else if (unformat (input, "flow-label"))
5143 else if (unformat (input, "src"))
5145 else if (unformat (input, "dst"))
5147 else if (unformat (input, "proto"))
5150 #define _(a) else if (unformat (input, #a)) a=1;
5151 foreach_ip6_proto_field
5157 #define _(a) found_something += a;
5158 foreach_ip6_proto_field;
5161 if (found_something == 0)
5164 vec_validate (mask, sizeof (*ip) - 1);
5166 ip = (ip6_header_t *) mask;
5168 #define _(a) if (a) memset (&ip->a, 0xff, sizeof (ip->a));
5169 foreach_ip6_proto_field;
5172 ip_version_traffic_class_and_flow_label = 0;
5175 ip_version_traffic_class_and_flow_label |= 0xF0000000;
5178 ip_version_traffic_class_and_flow_label |= 0x0FF00000;
5181 ip_version_traffic_class_and_flow_label |= 0x000FFFFF;
5183 ip->ip_version_traffic_class_and_flow_label =
5184 clib_host_to_net_u32 (ip_version_traffic_class_and_flow_label);
5190 uword unformat_l3_mask (unformat_input_t * input, va_list * args)
5192 u8 ** maskp = va_arg (*args, u8 **);
5194 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) {
5195 if (unformat (input, "ip4 %U", unformat_ip4_mask, maskp))
5197 else if (unformat (input, "ip6 %U", unformat_ip6_mask, maskp))
5205 uword unformat_l2_mask (unformat_input_t * input, va_list * args)
5207 u8 ** maskp = va_arg (*args, u8 **);
5222 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) {
5223 if (unformat (input, "src"))
5225 else if (unformat (input, "dst"))
5227 else if (unformat (input, "proto"))
5229 else if (unformat (input, "tag1"))
5231 else if (unformat (input, "tag2"))
5233 else if (unformat (input, "ignore-tag1"))
5235 else if (unformat (input, "ignore-tag2"))
5237 else if (unformat (input, "cos1"))
5239 else if (unformat (input, "cos2"))
5241 else if (unformat (input, "dot1q"))
5243 else if (unformat (input, "dot1ad"))
5248 if ((src + dst + proto + tag1 + tag2 + dot1q + dot1ad +
5249 ignore_tag1 + ignore_tag2 + cos1 + cos2) == 0)
5252 if (tag1 || ignore_tag1 || cos1 || dot1q)
5254 if (tag2 || ignore_tag2 || cos2 || dot1ad)
5257 vec_validate (mask, len-1);
5260 memset (mask, 0xff, 6);
5263 memset (mask + 6, 0xff, 6);
5267 /* inner vlan tag */
5276 mask[21] = mask [20] = 0xff;
5297 mask[16] = mask [17] = 0xff;
5307 mask[12] = mask [13] = 0xff;
5313 uword unformat_classify_mask (unformat_input_t * input, va_list * args)
5315 u8 ** maskp = va_arg (*args, u8 **);
5316 u32 * skipp = va_arg (*args, u32 *);
5317 u32 * matchp = va_arg (*args, u32 *);
5324 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) {
5325 if (unformat (input, "hex %U", unformat_hex_string, &mask))
5327 else if (unformat (input, "l2 %U", unformat_l2_mask, &l2))
5329 else if (unformat (input, "l3 %U", unformat_l3_mask, &l3))
5335 if (mask || l2 || l3)
5339 /* "With a free Ethernet header in every package" */
5341 vec_validate (l2, 13);
5343 vec_append (mask, l3);
5347 /* Scan forward looking for the first significant mask octet */
5348 for (i = 0; i < vec_len (mask); i++)
5352 /* compute (skip, match) params */
5353 *skipp = i / sizeof(u32x4);
5354 vec_delete (mask, *skipp * sizeof(u32x4), 0);
5356 /* Pad mask to an even multiple of the vector size */
5357 while (vec_len (mask) % sizeof (u32x4))
5360 match = vec_len (mask) / sizeof (u32x4);
5362 for (i = match*sizeof(u32x4); i > 0; i-= sizeof(u32x4))
5364 u64 *tmp = (u64 *)(mask + (i-sizeof(u32x4)));
5365 if (*tmp || *(tmp+1))
5370 clib_warning ("BUG: match 0");
5372 _vec_len (mask) = match * sizeof(u32x4);
5383 #define foreach_l2_next \
5385 _(ethernet, ETHERNET_INPUT) \
5389 uword unformat_l2_next_index (unformat_input_t * input, va_list * args)
5391 u32 * miss_next_indexp = va_arg (*args, u32 *);
5396 if (unformat (input, #n)) { next_index = L2_CLASSIFY_NEXT_##N; goto out;}
5400 if (unformat (input, "%d", &tmp))
5409 *miss_next_indexp = next_index;
5413 #define foreach_ip_next \
5419 uword unformat_ip_next_index (unformat_input_t * input, va_list * args)
5421 u32 * miss_next_indexp = va_arg (*args, u32 *);
5426 if (unformat (input, #n)) { next_index = IP_LOOKUP_NEXT_##N; goto out;}
5430 if (unformat (input, "%d", &tmp))
5439 *miss_next_indexp = next_index;
5443 #define foreach_acl_next \
5446 uword unformat_acl_next_index (unformat_input_t * input, va_list * args)
5448 u32 * miss_next_indexp = va_arg (*args, u32 *);
5453 if (unformat (input, #n)) { next_index = ACL_NEXT_INDEX_##N; goto out;}
5457 if (unformat (input, "permit"))
5462 else if (unformat (input, "%d", &tmp))
5471 *miss_next_indexp = next_index;
5475 static int api_classify_add_del_table (vat_main_t * vam)
5477 unformat_input_t * i = vam->input;
5478 vl_api_classify_add_del_table_t *mp;
5484 u32 table_index = ~0;
5485 u32 next_table_index = ~0;
5486 u32 miss_next_index = ~0;
5487 u32 memory_size = 32<<20;
5491 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
5492 if (unformat (i, "del"))
5494 else if (unformat (i, "buckets %d", &nbuckets))
5496 else if (unformat (i, "memory_size %d", &memory_size))
5498 else if (unformat (i, "skip %d", &skip))
5500 else if (unformat (i, "match %d", &match))
5502 else if (unformat (i, "table %d", &table_index))
5504 else if (unformat (i, "mask %U", unformat_classify_mask,
5505 &mask, &skip, &match))
5507 else if (unformat (i, "next-table %d", &next_table_index))
5509 else if (unformat (i, "miss-next %U", unformat_ip_next_index,
5512 else if (unformat (i, "l2-miss-next %U", unformat_l2_next_index,
5515 else if (unformat (i, "acl-miss-next %U", unformat_acl_next_index,
5522 if (is_add && mask == 0) {
5523 errmsg ("Mask required\n");
5527 if (is_add && skip == ~0) {
5528 errmsg ("skip count required\n");
5532 if (is_add && match == ~0) {
5533 errmsg ("match count required\n");
5537 if (!is_add && table_index == ~0) {
5538 errmsg ("table index required for delete\n");
5542 M2 (CLASSIFY_ADD_DEL_TABLE, classify_add_del_table,
5545 mp->is_add = is_add;
5546 mp->table_index = ntohl(table_index);
5547 mp->nbuckets = ntohl(nbuckets);
5548 mp->memory_size = ntohl(memory_size);
5549 mp->skip_n_vectors = ntohl(skip);
5550 mp->match_n_vectors = ntohl(match);
5551 mp->next_table_index = ntohl(next_table_index);
5552 mp->miss_next_index = ntohl(miss_next_index);
5553 memcpy (mp->mask, mask, vec_len(mask));
5561 uword unformat_ip4_match (unformat_input_t * input, va_list * args)
5563 u8 ** matchp = va_arg (*args, u8 **);
5570 int src = 0, dst = 0;
5571 ip4_address_t src_val, dst_val;
5578 int fragment_id = 0;
5579 u32 fragment_id_val;
5585 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
5587 if (unformat (input, "version %d", &version_val))
5589 else if (unformat (input, "hdr_length %d", &hdr_length_val))
5591 else if (unformat (input, "src %U", unformat_ip4_address, &src_val))
5593 else if (unformat (input, "dst %U", unformat_ip4_address, &dst_val))
5595 else if (unformat (input, "proto %d", &proto_val))
5597 else if (unformat (input, "tos %d", &tos_val))
5599 else if (unformat (input, "length %d", &length_val))
5601 else if (unformat (input, "fragment_id %d", &fragment_id_val))
5603 else if (unformat (input, "ttl %d", &ttl_val))
5605 else if (unformat (input, "checksum %d", &checksum_val))
5611 if (version + hdr_length + src + dst + proto + tos + length + fragment_id
5612 + ttl + checksum == 0)
5616 * Aligned because we use the real comparison functions
5618 vec_validate_aligned (match, sizeof (*ip) - 1, sizeof(u32x4));
5620 ip = (ip4_header_t *) match;
5622 /* These are realistically matched in practice */
5624 ip->src_address.as_u32 = src_val.as_u32;
5627 ip->dst_address.as_u32 = dst_val.as_u32;
5630 ip->protocol = proto_val;
5633 /* These are not, but they're included for completeness */
5635 ip->ip_version_and_header_length |= (version_val & 0xF)<<4;
5638 ip->ip_version_and_header_length |= (hdr_length_val & 0xF);
5644 ip->length = length_val;
5650 ip->checksum = checksum_val;
5656 uword unformat_ip6_match (unformat_input_t * input, va_list * args)
5658 u8 ** matchp = va_arg (*args, u8 **);
5664 u32 traffic_class_val;
5667 int src = 0, dst = 0;
5668 ip6_address_t src_val, dst_val;
5671 int payload_length = 0;
5672 u32 payload_length_val;
5675 u32 ip_version_traffic_class_and_flow_label;
5677 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
5679 if (unformat (input, "version %d", &version_val))
5681 else if (unformat (input, "traffic_class %d", &traffic_class_val))
5683 else if (unformat (input, "flow_label %d", &flow_label_val))
5685 else if (unformat (input, "src %U", unformat_ip6_address, &src_val))
5687 else if (unformat (input, "dst %U", unformat_ip6_address, &dst_val))
5689 else if (unformat (input, "proto %d", &proto_val))
5691 else if (unformat (input, "payload_length %d", &payload_length_val))
5693 else if (unformat (input, "hop_limit %d", &hop_limit_val))
5699 if (version + traffic_class + flow_label + src + dst + proto +
5700 payload_length + hop_limit == 0)
5704 * Aligned because we use the real comparison functions
5706 vec_validate_aligned (match, sizeof (*ip) - 1, sizeof(u32x4));
5708 ip = (ip6_header_t *) match;
5711 memcpy (&ip->src_address, &src_val, sizeof (ip->src_address));
5714 memcpy (&ip->dst_address, &dst_val, sizeof (ip->dst_address));
5717 ip->protocol = proto_val;
5719 ip_version_traffic_class_and_flow_label = 0;
5722 ip_version_traffic_class_and_flow_label |= (version_val & 0xF) << 28;
5725 ip_version_traffic_class_and_flow_label |= (traffic_class_val & 0xFF) << 20;
5728 ip_version_traffic_class_and_flow_label |= (flow_label_val & 0xFFFFF);
5730 ip->ip_version_traffic_class_and_flow_label =
5731 clib_host_to_net_u32 (ip_version_traffic_class_and_flow_label);
5734 ip->payload_length = clib_host_to_net_u16 (payload_length_val);
5737 ip->hop_limit = hop_limit_val;
5743 uword unformat_l3_match (unformat_input_t * input, va_list * args)
5745 u8 ** matchp = va_arg (*args, u8 **);
5747 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) {
5748 if (unformat (input, "ip4 %U", unformat_ip4_match, matchp))
5750 else if (unformat (input, "ip6 %U", unformat_ip6_match, matchp))
5758 uword unformat_vlan_tag (unformat_input_t * input, va_list * args)
5760 u8 * tagp = va_arg (*args, u8 *);
5763 if (unformat(input, "%d", &tag))
5765 tagp[0] = (tag>>8) & 0x0F;
5766 tagp[1] = tag & 0xFF;
5773 uword unformat_l2_match (unformat_input_t * input, va_list * args)
5775 u8 ** matchp = va_arg (*args, u8 **);
5795 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) {
5796 if (unformat (input, "src %U", unformat_ethernet_address, &src_val))
5798 else if (unformat (input, "dst %U", unformat_ethernet_address, &dst_val))
5800 else if (unformat (input, "proto %U",
5801 unformat_ethernet_type_host_byte_order, &proto_val))
5803 else if (unformat (input, "tag1 %U", unformat_vlan_tag, tag1_val))
5805 else if (unformat (input, "tag2 %U", unformat_vlan_tag, tag2_val))
5807 else if (unformat (input, "ignore-tag1"))
5809 else if (unformat (input, "ignore-tag2"))
5811 else if (unformat (input, "cos1 %d", &cos1_val))
5813 else if (unformat (input, "cos2 %d", &cos2_val))
5818 if ((src + dst + proto + tag1 + tag2 +
5819 ignore_tag1 + ignore_tag2 + cos1 + cos2) == 0)
5822 if (tag1 || ignore_tag1 || cos1)
5824 if (tag2 || ignore_tag2 || cos2)
5827 vec_validate_aligned (match, len-1, sizeof(u32x4));
5830 memcpy (match, dst_val, 6);
5833 memcpy (match + 6, src_val, 6);
5837 /* inner vlan tag */
5838 match[19] = tag2_val[1];
5839 match[18] = tag2_val[0];
5841 match [18] |= (cos2_val & 0x7) << 5;
5844 match[21] = proto_val & 0xff;
5845 match[20] = proto_val >> 8;
5849 match [15] = tag1_val[1];
5850 match [14] = tag1_val[0];
5853 match [14] |= (cos1_val & 0x7) << 5;
5859 match [15] = tag1_val[1];
5860 match [14] = tag1_val[0];
5863 match[17] = proto_val & 0xff;
5864 match[16] = proto_val >> 8;
5867 match [14] |= (cos1_val & 0x7) << 5;
5873 match [18] |= (cos2_val & 0x7) << 5;
5875 match [14] |= (cos1_val & 0x7) << 5;
5878 match[13] = proto_val & 0xff;
5879 match[12] = proto_val >> 8;
5887 uword unformat_classify_match (unformat_input_t * input, va_list * args)
5889 u8 ** matchp = va_arg (*args, u8 **);
5890 u32 skip_n_vectors = va_arg (*args, u32);
5891 u32 match_n_vectors = va_arg (*args, u32);
5897 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) {
5898 if (unformat (input, "hex %U", unformat_hex_string, &match))
5900 else if (unformat (input, "l2 %U", unformat_l2_match, &l2))
5902 else if (unformat (input, "l3 %U", unformat_l3_match, &l3))
5908 if (match || l2 || l3)
5912 /* "Win a free Ethernet header in every packet" */
5914 vec_validate_aligned (l2, 13, sizeof(u32x4));
5916 vec_append_aligned (match, l3, sizeof(u32x4));
5920 /* Make sure the vector is big enough even if key is all 0's */
5921 vec_validate_aligned
5922 (match, ((match_n_vectors + skip_n_vectors) * sizeof(u32x4)) - 1,
5925 /* Set size, include skipped vectors*/
5926 _vec_len (match) = (match_n_vectors+skip_n_vectors) * sizeof(u32x4);
5936 static int api_classify_add_del_session (vat_main_t * vam)
5938 unformat_input_t * i = vam->input;
5939 vl_api_classify_add_del_session_t *mp;
5941 u32 table_index = ~0;
5942 u32 hit_next_index = ~0;
5943 u32 opaque_index = ~0;
5947 u32 skip_n_vectors = 0;
5948 u32 match_n_vectors = 0;
5951 * Warning: you have to supply skip_n and match_n
5952 * because the API client cant simply look at the classify
5956 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
5957 if (unformat (i, "del"))
5959 else if (unformat (i, "hit-next %U", unformat_ip_next_index,
5962 else if (unformat (i, "l2-hit-next %U", unformat_l2_next_index,
5965 else if (unformat (i, "acl-hit-next %U", unformat_acl_next_index,
5968 else if (unformat (i, "opaque-index %d", &opaque_index))
5970 else if (unformat (i, "skip_n %d", &skip_n_vectors))
5972 else if (unformat (i, "match_n %d", &match_n_vectors))
5974 else if (unformat (i, "match %U", unformat_classify_match,
5975 &match, skip_n_vectors, match_n_vectors))
5977 else if (unformat (i, "advance %d", &advance))
5979 else if (unformat (i, "table-index %d", &table_index))
5985 if (table_index == ~0) {
5986 errmsg ("Table index required\n");
5990 if (is_add && match == 0) {
5991 errmsg ("Match value required\n");
5995 M2 (CLASSIFY_ADD_DEL_SESSION, classify_add_del_session,
5998 mp->is_add = is_add;
5999 mp->table_index = ntohl(table_index);
6000 mp->hit_next_index = ntohl(hit_next_index);
6001 mp->opaque_index = ntohl(opaque_index);
6002 mp->advance = ntohl(advance);
6003 memcpy (mp->match, match, vec_len(match));
6010 static int api_classify_set_interface_ip_table (vat_main_t * vam)
6012 unformat_input_t * i = vam->input;
6013 vl_api_classify_set_interface_ip_table_t *mp;
6016 int sw_if_index_set;
6017 u32 table_index = ~0;
6020 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
6021 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
6022 sw_if_index_set = 1;
6023 else if (unformat (i, "sw_if_index %d", &sw_if_index))
6024 sw_if_index_set = 1;
6025 else if (unformat (i, "table %d", &table_index))
6028 clib_warning ("parse error '%U'", format_unformat_error, i);
6033 if (sw_if_index_set == 0) {
6034 errmsg ("missing interface name or sw_if_index\n");
6039 M(CLASSIFY_SET_INTERFACE_IP_TABLE, classify_set_interface_ip_table);
6041 mp->sw_if_index = ntohl(sw_if_index);
6042 mp->table_index = ntohl(table_index);
6043 mp->is_ipv6 = is_ipv6;
6050 static int api_classify_set_interface_l2_tables (vat_main_t * vam)
6052 unformat_input_t * i = vam->input;
6053 vl_api_classify_set_interface_l2_tables_t *mp;
6056 int sw_if_index_set;
6057 u32 ip4_table_index = ~0;
6058 u32 ip6_table_index = ~0;
6059 u32 other_table_index = ~0;
6061 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
6062 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
6063 sw_if_index_set = 1;
6064 else if (unformat (i, "sw_if_index %d", &sw_if_index))
6065 sw_if_index_set = 1;
6066 else if (unformat (i, "ip4-table %d", &ip4_table_index))
6068 else if (unformat (i, "ip6-table %d", &ip6_table_index))
6070 else if (unformat (i, "other-table %d", &other_table_index))
6073 clib_warning ("parse error '%U'", format_unformat_error, i);
6078 if (sw_if_index_set == 0) {
6079 errmsg ("missing interface name or sw_if_index\n");
6084 M(CLASSIFY_SET_INTERFACE_L2_TABLES, classify_set_interface_l2_tables);
6086 mp->sw_if_index = ntohl(sw_if_index);
6087 mp->ip4_table_index = ntohl(ip4_table_index);
6088 mp->ip6_table_index = ntohl(ip6_table_index);
6089 mp->other_table_index = ntohl(other_table_index);
6097 static int api_get_node_index (vat_main_t * vam)
6099 unformat_input_t * i = vam->input;
6100 vl_api_get_node_index_t * mp;
6104 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
6105 if (unformat (i, "node %s", &name))
6111 errmsg ("node name required\n");
6114 if (vec_len (name) >= ARRAY_LEN(mp->node_name)) {
6115 errmsg ("node name too long, max %d\n", ARRAY_LEN(mp->node_name));
6119 M(GET_NODE_INDEX, get_node_index);
6120 memcpy (mp->node_name, name, vec_len(name));
6128 static int api_add_node_next (vat_main_t * vam)
6130 unformat_input_t * i = vam->input;
6131 vl_api_add_node_next_t * mp;
6136 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
6137 if (unformat (i, "node %s", &name))
6139 else if (unformat (i, "next %s", &next))
6145 errmsg ("node name required\n");
6148 if (vec_len (name) >= ARRAY_LEN(mp->node_name)) {
6149 errmsg ("node name too long, max %d\n", ARRAY_LEN(mp->node_name));
6153 errmsg ("next node required\n");
6156 if (vec_len (next) >= ARRAY_LEN(mp->next_name)) {
6157 errmsg ("next name too long, max %d\n", ARRAY_LEN(mp->next_name));
6161 M(ADD_NODE_NEXT, add_node_next);
6162 memcpy (mp->node_name, name, vec_len(name));
6163 memcpy (mp->next_name, next, vec_len(next));
6172 static int api_l2tpv3_create_tunnel (vat_main_t * vam)
6174 unformat_input_t * i = vam->input;
6175 ip6_address_t client_address, our_address;
6176 int client_address_set = 0;
6177 int our_address_set = 0;
6178 u32 local_session_id = 0;
6179 u32 remote_session_id = 0;
6180 u64 local_cookie = 0;
6181 u64 remote_cookie = 0;
6182 u8 l2_sublayer_present = 0;
6183 vl_api_l2tpv3_create_tunnel_t * mp;
6186 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
6187 if (unformat (i, "client_address %U", unformat_ip6_address,
6189 client_address_set = 1;
6190 else if (unformat (i, "our_address %U", unformat_ip6_address,
6192 our_address_set = 1;
6193 else if (unformat (i, "local_session_id %d", &local_session_id))
6195 else if (unformat (i, "remote_session_id %d", &remote_session_id))
6197 else if (unformat (i, "local_cookie %lld", &local_cookie))
6199 else if (unformat (i, "remote_cookie %lld", &remote_cookie))
6201 else if (unformat (i, "l2-sublayer-present"))
6202 l2_sublayer_present = 1;
6207 if (client_address_set == 0) {
6208 errmsg ("client_address required\n");
6212 if (our_address_set == 0) {
6213 errmsg ("our_address required\n");
6217 M(L2TPV3_CREATE_TUNNEL, l2tpv3_create_tunnel);
6219 memcpy (mp->client_address, client_address.as_u8,
6220 sizeof (mp->client_address));
6222 memcpy (mp->our_address, our_address.as_u8,
6223 sizeof (mp->our_address));
6225 mp->local_session_id = ntohl (local_session_id);
6226 mp->remote_session_id = ntohl (remote_session_id);
6227 mp->local_cookie = clib_host_to_net_u64 (local_cookie);
6228 mp->remote_cookie = clib_host_to_net_u64 (remote_cookie);
6229 mp->l2_sublayer_present = l2_sublayer_present;
6237 static int api_l2tpv3_set_tunnel_cookies (vat_main_t * vam)
6239 unformat_input_t * i = vam->input;
6241 u8 sw_if_index_set = 0;
6242 u64 new_local_cookie = 0;
6243 u64 new_remote_cookie = 0;
6244 vl_api_l2tpv3_set_tunnel_cookies_t *mp;
6247 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
6248 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
6249 sw_if_index_set = 1;
6250 else if (unformat (i, "sw_if_index %d", &sw_if_index))
6251 sw_if_index_set = 1;
6252 else if (unformat (i, "new_local_cookie %lld", &new_local_cookie))
6254 else if (unformat (i, "new_remote_cookie %lld", &new_remote_cookie))
6260 if (sw_if_index_set == 0) {
6261 errmsg ("missing interface name or sw_if_index\n");
6265 M(L2TPV3_SET_TUNNEL_COOKIES, l2tpv3_set_tunnel_cookies);
6267 mp->sw_if_index = ntohl(sw_if_index);
6268 mp->new_local_cookie = clib_host_to_net_u64 (new_local_cookie);
6269 mp->new_remote_cookie = clib_host_to_net_u64 (new_remote_cookie);
6276 static int api_l2tpv3_interface_enable_disable (vat_main_t * vam)
6278 unformat_input_t * i = vam->input;
6279 vl_api_l2tpv3_interface_enable_disable_t *mp;
6282 u8 sw_if_index_set = 0;
6283 u8 enable_disable = 1;
6285 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
6286 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
6287 sw_if_index_set = 1;
6288 else if (unformat (i, "sw_if_index %d", &sw_if_index))
6289 sw_if_index_set = 1;
6290 else if (unformat (i, "enable"))
6292 else if (unformat (i, "disable"))
6298 if (sw_if_index_set == 0) {
6299 errmsg ("missing interface name or sw_if_index\n");
6303 M(L2TPV3_INTERFACE_ENABLE_DISABLE, l2tpv3_interface_enable_disable);
6305 mp->sw_if_index = ntohl(sw_if_index);
6306 mp->enable_disable = enable_disable;
6313 static int api_l2tpv3_set_lookup_key (vat_main_t * vam)
6315 unformat_input_t * i = vam->input;
6316 vl_api_l2tpv3_set_lookup_key_t * mp;
6320 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
6321 if (unformat (i, "lookup_v6_src"))
6322 key = L2T_LOOKUP_SRC_ADDRESS;
6323 else if (unformat (i, "lookup_v6_dst"))
6324 key = L2T_LOOKUP_DST_ADDRESS;
6325 else if (unformat (i, "lookup_session_id"))
6326 key = L2T_LOOKUP_SESSION_ID;
6332 errmsg ("l2tp session lookup key unset\n");
6336 M(L2TPV3_SET_LOOKUP_KEY, l2tpv3_set_lookup_key);
6345 static void vl_api_sw_if_l2tpv3_tunnel_details_t_handler
6346 (vl_api_sw_if_l2tpv3_tunnel_details_t * mp)
6348 vat_main_t * vam = &vat_main;
6350 fformat(vam->ofp, "* %U (our) %U (client) (sw_if_index %d)\n",
6351 format_ip6_address, mp->our_address,
6352 format_ip6_address, mp->client_address,
6353 clib_net_to_host_u32(mp->sw_if_index));
6355 fformat (vam->ofp, " local cookies %016llx %016llx remote cookie %016llx\n",
6356 clib_net_to_host_u64 (mp->local_cookie[0]),
6357 clib_net_to_host_u64 (mp->local_cookie[1]),
6358 clib_net_to_host_u64 (mp->remote_cookie));
6360 fformat (vam->ofp, " local session-id %d remote session-id %d\n",
6361 clib_net_to_host_u32 (mp->local_session_id),
6362 clib_net_to_host_u32 (mp->remote_session_id));
6364 fformat (vam->ofp, " l2 specific sublayer %s\n\n",
6365 mp->l2_sublayer_present ? "preset" : "absent");
6369 static void vl_api_sw_if_l2tpv3_tunnel_details_t_handler_json
6370 (vl_api_sw_if_l2tpv3_tunnel_details_t * mp)
6372 vat_main_t * vam = &vat_main;
6373 vat_json_node_t *node = NULL;
6374 struct in6_addr addr;
6376 if (VAT_JSON_ARRAY != vam->json_tree.type) {
6377 ASSERT(VAT_JSON_NONE == vam->json_tree.type);
6378 vat_json_init_array(&vam->json_tree);
6380 node = vat_json_array_add(&vam->json_tree);
6382 vat_json_init_object(node);
6384 memcpy(&addr, mp->our_address, sizeof(addr));
6385 vat_json_object_add_ip6(node, "our_address", addr);
6386 memcpy(&addr, mp->client_address, sizeof(addr));
6387 vat_json_object_add_ip6(node, "client_address", addr);
6389 vat_json_node_t * lc = vat_json_object_add(node, "local_cookie");
6390 vat_json_init_array(lc);
6391 vat_json_array_add_uint(lc, clib_net_to_host_u64(mp->local_cookie[0]));
6392 vat_json_array_add_uint(lc, clib_net_to_host_u64(mp->local_cookie[1]));
6393 vat_json_object_add_uint(node, "remote_cookie", clib_net_to_host_u64(mp->remote_cookie));
6395 printf("local id: %u", clib_net_to_host_u32(mp->local_session_id));
6396 vat_json_object_add_uint(node, "local_session_id", clib_net_to_host_u32(mp->local_session_id));
6397 vat_json_object_add_uint(node, "remote_session_id", clib_net_to_host_u32(mp->remote_session_id));
6398 vat_json_object_add_string_copy(node, "l2_sublayer", mp->l2_sublayer_present ?
6399 (u8*)"present" : (u8*)"absent");
6402 static int api_sw_if_l2tpv3_tunnel_dump (vat_main_t * vam)
6404 vl_api_sw_if_l2tpv3_tunnel_dump_t *mp;
6407 /* Get list of l2tpv3-tunnel interfaces */
6408 M(SW_IF_L2TPV3_TUNNEL_DUMP, sw_if_l2tpv3_tunnel_dump);
6411 /* Use a control ping for synchronization */
6413 vl_api_control_ping_t * mp;
6414 M(CONTROL_PING, control_ping);
6421 static void vl_api_sw_interface_tap_details_t_handler
6422 (vl_api_sw_interface_tap_details_t * mp)
6424 vat_main_t * vam = &vat_main;
6426 fformat(vam->ofp, "%-16s %d\n",
6428 clib_net_to_host_u32(mp->sw_if_index));
6431 static void vl_api_sw_interface_tap_details_t_handler_json
6432 (vl_api_sw_interface_tap_details_t * mp)
6434 vat_main_t * vam = &vat_main;
6435 vat_json_node_t *node = NULL;
6437 if (VAT_JSON_ARRAY != vam->json_tree.type) {
6438 ASSERT(VAT_JSON_NONE == vam->json_tree.type);
6439 vat_json_init_array(&vam->json_tree);
6441 node = vat_json_array_add(&vam->json_tree);
6443 vat_json_init_object(node);
6444 vat_json_object_add_uint(node, "sw_if_index", ntohl(mp->sw_if_index));
6445 vat_json_object_add_string_copy(node, "dev_name", mp->dev_name);
6448 static int api_sw_interface_tap_dump (vat_main_t * vam)
6450 vl_api_sw_interface_tap_dump_t *mp;
6453 fformat(vam->ofp, "\n%-16s %s\n", "dev_name", "sw_if_index");
6454 /* Get list of tap interfaces */
6455 M(SW_INTERFACE_TAP_DUMP, sw_interface_tap_dump);
6458 /* Use a control ping for synchronization */
6460 vl_api_control_ping_t * mp;
6461 M(CONTROL_PING, control_ping);
6467 static uword unformat_vxlan_decap_next
6468 (unformat_input_t * input, va_list * args)
6470 u32 * result = va_arg (*args, u32 *);
6473 if (unformat (input, "drop"))
6474 *result = VXLAN_INPUT_NEXT_DROP;
6475 else if (unformat (input, "ip4"))
6476 *result = VXLAN_INPUT_NEXT_IP4_INPUT;
6477 else if (unformat (input, "ip6"))
6478 *result = VXLAN_INPUT_NEXT_IP6_INPUT;
6479 else if (unformat (input, "l2"))
6480 *result = VXLAN_INPUT_NEXT_L2_INPUT;
6481 else if (unformat (input, "%d", &tmp))
6488 static int api_vxlan_add_del_tunnel (vat_main_t * vam)
6490 unformat_input_t * line_input = vam->input;
6491 vl_api_vxlan_add_del_tunnel_t *mp;
6493 ip4_address_t src, dst;
6497 u32 encap_vrf_id = 0;
6498 u32 decap_next_index = ~0;
6501 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) {
6502 if (unformat (line_input, "del"))
6504 else if (unformat (line_input, "src %U",
6505 unformat_ip4_address, &src))
6507 else if (unformat (line_input, "dst %U",
6508 unformat_ip4_address, &dst))
6510 else if (unformat (line_input, "encap-vrf-id %d", &encap_vrf_id))
6512 else if (unformat (line_input, "decap-next %U",
6513 unformat_vxlan_decap_next, &decap_next_index))
6515 else if (unformat (line_input, "vni %d", &vni))
6518 errmsg ("parse error '%U'\n", format_unformat_error, line_input);
6524 errmsg ("tunnel src address not specified\n");
6528 errmsg ("tunnel dst address not specified\n");
6532 if ((vni == 0) || (vni>>24)) {
6533 errmsg ("vni not specified or out of range\n");
6537 M (VXLAN_ADD_DEL_TUNNEL, vxlan_add_del_tunnel);
6539 mp->src_address = src.as_u32;
6540 mp->dst_address = dst.as_u32;
6541 mp->encap_vrf_id = ntohl(encap_vrf_id);
6542 mp->decap_next_index = ntohl(decap_next_index);
6543 mp->vni = ntohl(vni);
6544 mp->is_add = is_add;
6551 static int api_l2_fib_clear_table (vat_main_t * vam)
6553 // unformat_input_t * i = vam->input;
6554 vl_api_l2_fib_clear_table_t *mp;
6557 M(L2_FIB_CLEAR_TABLE, l2_fib_clear_table);
6564 static int api_l2_interface_efp_filter (vat_main_t * vam)
6566 unformat_input_t * i = vam->input;
6567 vl_api_l2_interface_efp_filter_t *mp;
6571 u8 sw_if_index_set = 0;
6573 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
6574 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
6575 sw_if_index_set = 1;
6576 else if (unformat (i, "sw_if_index %d", &sw_if_index))
6577 sw_if_index_set = 1;
6578 else if (unformat (i, "enable"))
6580 else if (unformat (i, "disable"))
6583 clib_warning ("parse error '%U'", format_unformat_error, i);
6588 if (sw_if_index_set == 0) {
6589 errmsg ("missing sw_if_index\n");
6593 M(L2_INTERFACE_EFP_FILTER, l2_interface_efp_filter);
6595 mp->sw_if_index = ntohl(sw_if_index);
6596 mp->enable_disable = enable;
6603 #define foreach_vtr_op \
6604 _("disable", L2_VTR_DISABLED) \
6605 _("push-1", L2_VTR_PUSH_1) \
6606 _("push-2", L2_VTR_PUSH_2) \
6607 _("pop-1", L2_VTR_POP_1) \
6608 _("pop-2", L2_VTR_POP_2) \
6609 _("translate-1-1", L2_VTR_TRANSLATE_1_1) \
6610 _("translate-1-2", L2_VTR_TRANSLATE_1_2) \
6611 _("translate-2-1", L2_VTR_TRANSLATE_2_1) \
6612 _("translate-2-2", L2_VTR_TRANSLATE_2_2)
6614 static int api_l2_interface_vlan_tag_rewrite (vat_main_t * vam)
6616 unformat_input_t * i = vam->input;
6617 vl_api_l2_interface_vlan_tag_rewrite_t *mp;
6620 u8 sw_if_index_set = 0;
6627 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
6628 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
6629 sw_if_index_set = 1;
6630 else if (unformat (i, "sw_if_index %d", &sw_if_index))
6631 sw_if_index_set = 1;
6632 else if (unformat (i, "vtr_op %d", &vtr_op))
6634 #define _(n,v) else if (unformat(i, n)) {vtr_op = v; vtr_op_set = 1;}
6638 else if (unformat (i, "push_dot1q %d", &push_dot1q))
6640 else if (unformat (i, "tag1 %d", &tag1))
6642 else if (unformat (i, "tag2 %d", &tag2))
6645 clib_warning ("parse error '%U'", format_unformat_error, i);
6650 if ((sw_if_index_set == 0)||(vtr_op_set == 0)) {
6651 errmsg ("missing vtr operation or sw_if_index\n");
6655 M(L2_INTERFACE_VLAN_TAG_REWRITE, l2_interface_vlan_tag_rewrite)
6657 mp->sw_if_index = ntohl(sw_if_index);
6658 mp->vtr_op = ntohl(vtr_op);
6659 mp->push_dot1q = ntohl(push_dot1q);
6660 mp->tag1 = ntohl(tag1);
6661 mp->tag2 = ntohl(tag2);
6668 static int api_create_vhost_user_if (vat_main_t * vam)
6670 unformat_input_t * i = vam->input;
6671 vl_api_create_vhost_user_if_t *mp;
6675 u8 file_name_set = 0;
6676 u32 custom_dev_instance = ~0;
6678 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
6679 if (unformat (i, "socket %s", &file_name)) {
6682 else if (unformat (i, "renumber %"PRIu32, &custom_dev_instance))
6684 else if (unformat (i, "server"))
6690 if (file_name_set == 0) {
6691 errmsg ("missing socket file name\n");
6695 if (vec_len (file_name) > 255) {
6696 errmsg ("socket file name too long\n");
6699 vec_add1 (file_name, 0);
6701 M(CREATE_VHOST_USER_IF, create_vhost_user_if);
6703 mp->is_server = is_server;
6704 memcpy(mp->sock_filename, file_name, vec_len(file_name));
6705 vec_free(file_name);
6706 if (custom_dev_instance != ~0) {
6708 mp->custom_dev_instance = ntohl(custom_dev_instance);
6716 static int api_modify_vhost_user_if (vat_main_t * vam)
6718 unformat_input_t * i = vam->input;
6719 vl_api_modify_vhost_user_if_t *mp;
6723 u8 file_name_set = 0;
6724 u32 custom_dev_instance = ~0;
6725 u8 sw_if_index_set = 0;
6726 u32 sw_if_index = (u32)~0;
6728 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
6729 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
6730 sw_if_index_set = 1;
6731 else if (unformat (i, "sw_if_index %d", &sw_if_index))
6732 sw_if_index_set = 1;
6733 else if (unformat (i, "socket %s", &file_name)) {
6736 else if (unformat (i, "renumber %"PRIu32, &custom_dev_instance))
6738 else if (unformat (i, "server"))
6744 if (sw_if_index_set == 0) {
6745 errmsg ("missing sw_if_index or interface name\n");
6749 if (file_name_set == 0) {
6750 errmsg ("missing socket file name\n");
6754 if (vec_len (file_name) > 255) {
6755 errmsg ("socket file name too long\n");
6758 vec_add1 (file_name, 0);
6760 M(MODIFY_VHOST_USER_IF, modify_vhost_user_if);
6762 mp->sw_if_index = ntohl(sw_if_index);
6763 mp->is_server = is_server;
6764 memcpy(mp->sock_filename, file_name, vec_len(file_name));
6765 vec_free(file_name);
6766 if (custom_dev_instance != ~0) {
6768 mp->custom_dev_instance = ntohl(custom_dev_instance);
6776 static int api_delete_vhost_user_if (vat_main_t * vam)
6778 unformat_input_t * i = vam->input;
6779 vl_api_delete_vhost_user_if_t *mp;
6781 u32 sw_if_index = ~0;
6782 u8 sw_if_index_set = 0;
6784 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
6785 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
6786 sw_if_index_set = 1;
6787 else if (unformat (i, "sw_if_index %d", &sw_if_index))
6788 sw_if_index_set = 1;
6793 if (sw_if_index_set == 0) {
6794 errmsg ("missing sw_if_index or interface name\n");
6799 M(DELETE_VHOST_USER_IF, delete_vhost_user_if);
6801 mp->sw_if_index = ntohl(sw_if_index);
6808 static void vl_api_sw_interface_vhost_user_details_t_handler
6809 (vl_api_sw_interface_vhost_user_details_t * mp)
6811 vat_main_t * vam = &vat_main;
6813 fformat(vam->ofp, "%-25s %3" PRIu32 " %6" PRIu32 " %8x %6d %7d %s\n",
6814 (char *)mp->interface_name,
6815 ntohl(mp->sw_if_index), ntohl(mp->virtio_net_hdr_sz),
6816 clib_net_to_host_u64(mp->features), mp->is_server,
6817 ntohl(mp->num_regions), (char *)mp->sock_filename);
6818 fformat(vam->ofp, " Status: '%s'\n", strerror(ntohl(mp->sock_errno)));
6821 static void vl_api_sw_interface_vhost_user_details_t_handler_json
6822 (vl_api_sw_interface_vhost_user_details_t * mp)
6824 vat_main_t * vam = &vat_main;
6825 vat_json_node_t *node = NULL;
6827 if (VAT_JSON_ARRAY != vam->json_tree.type) {
6828 ASSERT(VAT_JSON_NONE == vam->json_tree.type);
6829 vat_json_init_array(&vam->json_tree);
6831 node = vat_json_array_add(&vam->json_tree);
6833 vat_json_init_object(node);
6834 vat_json_object_add_uint(node, "sw_if_index", ntohl(mp->sw_if_index));
6835 vat_json_object_add_string_copy(node, "interface_name", mp->interface_name);
6836 vat_json_object_add_uint(node, "virtio_net_hdr_sz", ntohl(mp->virtio_net_hdr_sz));
6837 vat_json_object_add_uint(node, "features", clib_net_to_host_u64(mp->features));
6838 vat_json_object_add_uint(node, "is_server", mp->is_server);
6839 vat_json_object_add_string_copy(node, "sock_filename", mp->sock_filename);
6840 vat_json_object_add_uint(node, "num_regions", ntohl(mp->num_regions));
6841 vat_json_object_add_uint(node, "sock_errno", ntohl(mp->sock_errno));
6844 static int api_sw_interface_vhost_user_dump (vat_main_t * vam)
6846 vl_api_sw_interface_vhost_user_dump_t *mp;
6848 fformat(vam->ofp, "Interface name idx hdr_sz features server regions filename\n");
6850 /* Get list of vhost-user interfaces */
6851 M(SW_INTERFACE_VHOST_USER_DUMP, sw_interface_vhost_user_dump);
6854 /* Use a control ping for synchronization */
6856 vl_api_control_ping_t * mp;
6857 M(CONTROL_PING, control_ping);
6863 static int api_show_version (vat_main_t * vam)
6865 vl_api_show_version_t *mp;
6868 M(SHOW_VERSION, show_version);
6875 static uword unformat_nsh_gre_decap_next
6876 (unformat_input_t * input, va_list * args)
6878 u32 * result = va_arg (*args, u32 *);
6881 if (unformat (input, "drop"))
6882 *result = NSH_INPUT_NEXT_DROP;
6883 else if (unformat (input, "ip4"))
6884 *result = NSH_INPUT_NEXT_IP4_INPUT;
6885 else if (unformat (input, "ip6"))
6886 *result = NSH_INPUT_NEXT_IP6_INPUT;
6887 else if (unformat (input, "ethernet"))
6888 *result = NSH_INPUT_NEXT_ETHERNET_INPUT;
6889 else if (unformat (input, "%d", &tmp))
6896 static int api_nsh_gre_add_del_tunnel (vat_main_t * vam)
6898 unformat_input_t * line_input = vam->input;
6899 vl_api_nsh_gre_add_del_tunnel_t *mp;
6901 ip4_address_t src, dst;
6905 u32 encap_vrf_id = 0;
6906 u32 decap_vrf_id = 0;
6909 u8 next_protocol = 1; /* ip4 */
6920 u32 decap_next_index = NSH_INPUT_NEXT_IP4_INPUT;
6924 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) {
6925 if (unformat (line_input, "del"))
6927 else if (unformat (line_input, "src %U",
6928 unformat_ip4_address, &src))
6930 else if (unformat (line_input, "dst %U",
6931 unformat_ip4_address, &dst))
6933 else if (unformat (line_input, "encap-vrf-id %d", &encap_vrf_id))
6935 else if (unformat (line_input, "decap-vrf-id %d", &decap_vrf_id))
6937 else if (unformat (line_input, "decap-next %U",
6938 unformat_nsh_gre_decap_next, &decap_next_index))
6940 else if (unformat (line_input, "version %d", &tmp))
6941 ver_o_c |= (tmp & 3) << 6;
6942 else if (unformat (line_input, "o-bit %d", &tmp))
6943 ver_o_c |= (tmp & 1) << 5;
6944 else if (unformat (line_input, "c-bit %d", &tmp))
6945 ver_o_c |= (tmp & 1) << 4;
6946 else if (unformat (line_input, "md-type %d", &tmp))
6948 else if (unformat(line_input, "next-ip4"))
6950 else if (unformat(line_input, "next-ip6"))
6952 else if (unformat(line_input, "next-ethernet"))
6954 else if (unformat (line_input, "c1 %d", &c1))
6956 else if (unformat (line_input, "c2 %d", &c2))
6958 else if (unformat (line_input, "c3 %d", &c3))
6960 else if (unformat (line_input, "c4 %d", &c4))
6962 else if (unformat (line_input, "spi %d", &spi))
6964 else if (unformat (line_input, "si %d", &si))
6966 else if (unformat (line_input, "tlv %x"))
6967 vec_add1 (tlvs, tmp);
6969 errmsg ("parse error '%U'\n", format_unformat_error, line_input);
6975 errmsg ("tunnel src address not specified\n");
6979 errmsg ("tunnel dst address not specified\n");
6984 errmsg ("spi not specified\n");
6989 errmsg ("si not specified\n");
6993 M2 (NSH_GRE_ADD_DEL_TUNNEL, nsh_gre_add_del_tunnel,
6994 sizeof(u32) * vec_len (tlvs));
6996 spi_si = (spi<<8) | si;
6998 mp->src = src.as_u32;
6999 mp->dst = dst.as_u32;
7000 mp->encap_vrf_id = ntohl(encap_vrf_id);
7001 mp->decap_vrf_id = ntohl(decap_vrf_id);
7002 mp->decap_next_index = ntohl(decap_next_index);
7003 mp->tlv_len_in_words = vec_len (tlvs);
7004 mp->is_add = is_add;
7005 mp->ver_o_c = ver_o_c;
7006 mp->length = 6 + vec_len(tlvs);
7007 mp->md_type = md_type;
7008 mp->next_protocol = next_protocol;
7009 mp->spi_si = ntohl(spi_si);
7015 for (i = 0; i < vec_len(tlvs); i++)
7016 mp->tlvs[i] = ntohl(tlvs[i]);
7025 static uword unformat_nsh_vxlan_gpe_decap_next
7026 (unformat_input_t * input, va_list * args)
7028 u32 * result = va_arg (*args, u32 *);
7031 if (unformat (input, "drop"))
7032 *result = NSH_VXLAN_GPE_INPUT_NEXT_DROP;
7033 else if (unformat (input, "ip4"))
7034 *result = NSH_VXLAN_GPE_INPUT_NEXT_IP4_INPUT;
7035 else if (unformat (input, "ip6"))
7036 *result = NSH_VXLAN_GPE_INPUT_NEXT_IP6_INPUT;
7037 else if (unformat (input, "ethernet"))
7038 *result = NSH_VXLAN_GPE_INPUT_NEXT_ETHERNET_INPUT;
7039 else if (unformat (input, "nsh-vxlan-gpe"))
7040 *result = NSH_VXLAN_GPE_INPUT_NEXT_ETHERNET_INPUT;
7041 else if (unformat (input, "%d", &tmp))
7048 static int api_nsh_vxlan_gpe_add_del_tunnel (vat_main_t * vam)
7050 unformat_input_t * line_input = vam->input;
7051 vl_api_nsh_vxlan_gpe_add_del_tunnel_t *mp;
7053 ip4_address_t src, dst;
7057 u32 encap_vrf_id = 0;
7058 u32 decap_vrf_id = 0;
7061 u8 next_protocol = 1; /* ip4 */
7072 u32 decap_next_index = NSH_INPUT_NEXT_IP4_INPUT;
7078 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) {
7079 if (unformat (line_input, "del"))
7081 else if (unformat (line_input, "src %U",
7082 unformat_ip4_address, &src))
7084 else if (unformat (line_input, "dst %U",
7085 unformat_ip4_address, &dst))
7087 else if (unformat (line_input, "encap-vrf-id %d", &encap_vrf_id))
7089 else if (unformat (line_input, "decap-vrf-id %d", &decap_vrf_id))
7091 else if (unformat (line_input, "decap-next %U",
7092 unformat_nsh_vxlan_gpe_decap_next,
7095 else if (unformat (line_input, "vni %d", &vni))
7097 else if (unformat (line_input, "version %d", &tmp))
7098 ver_o_c |= (tmp & 3) << 6;
7099 else if (unformat (line_input, "o-bit %d", &tmp))
7100 ver_o_c |= (tmp & 1) << 5;
7101 else if (unformat (line_input, "c-bit %d", &tmp))
7102 ver_o_c |= (tmp & 1) << 4;
7103 else if (unformat (line_input, "md-type %d", &tmp))
7105 else if (unformat(line_input, "next-ip4"))
7107 else if (unformat(line_input, "next-ip6"))
7109 else if (unformat(line_input, "next-ethernet"))
7111 else if (unformat (line_input, "c1 %d", &c1))
7113 else if (unformat (line_input, "c2 %d", &c2))
7115 else if (unformat (line_input, "c3 %d", &c3))
7117 else if (unformat (line_input, "c4 %d", &c4))
7119 else if (unformat (line_input, "spi %d", &spi))
7121 else if (unformat (line_input, "si %d", &si))
7123 else if (unformat (line_input, "tlv %x"))
7124 vec_add1 (tlvs, tmp);
7126 errmsg ("parse error '%U'\n", format_unformat_error, line_input);
7132 errmsg ("tunnel src address not specified\n");
7136 errmsg ("tunnel dst address not specified\n");
7141 errmsg ("spi not specified\n");
7146 errmsg ("si not specified\n");
7150 errmsg ("vni not specified\n");
7154 M2 (NSH_VXLAN_GPE_ADD_DEL_TUNNEL, nsh_vxlan_gpe_add_del_tunnel,
7155 sizeof(u32) * vec_len (tlvs));
7157 spi_si = (spi<<8) | si;
7159 mp->src = src.as_u32;
7160 mp->dst = dst.as_u32;
7161 mp->encap_vrf_id = ntohl(encap_vrf_id);
7162 mp->decap_vrf_id = ntohl(decap_vrf_id);
7163 mp->decap_next_index = ntohl(decap_next_index);
7164 mp->tlv_len_in_words = vec_len (tlvs);
7165 mp->vni = ntohl(vni);
7166 mp->is_add = is_add;
7167 mp->ver_o_c = ver_o_c;
7168 mp->length = 6 + vec_len(tlvs);
7169 mp->md_type = md_type;
7170 mp->next_protocol = next_protocol;
7171 mp->spi_si = ntohl(spi_si);
7177 for (i = 0; i < vec_len(tlvs); i++)
7178 mp->tlvs[i] = ntohl(tlvs[i]);
7187 static uword unformat_lisp_gpe_decap_next (unformat_input_t * input,
7190 u32 * result = va_arg (*args, u32 *);
7193 if (unformat (input, "drop"))
7194 *result = LISP_GPE_INPUT_NEXT_DROP;
7195 else if (unformat (input, "ip4"))
7196 *result = LISP_GPE_INPUT_NEXT_IP4_INPUT;
7197 else if (unformat (input, "ip6"))
7198 *result = LISP_GPE_INPUT_NEXT_IP6_INPUT;
7199 else if (unformat (input, "ethernet"))
7200 *result = LISP_GPE_INPUT_NEXT_IP6_INPUT;
7201 else if (unformat (input, "lisp-gpe"))
7202 *result = LISP_GPE_INPUT_NEXT_LISP_GPE_ENCAP;
7203 else if (unformat (input, "%d", &tmp))
7211 api_lisp_gpe_add_del_tunnel (vat_main_t * vam)
7213 unformat_input_t * line_input = vam->input;
7214 vl_api_lisp_gpe_add_del_tunnel_t *mp;
7216 ip4_address_t src, dst;
7220 u32 encap_vrf_id = 0;
7221 u32 decap_vrf_id = 0;
7222 u8 next_protocol = LISP_GPE_NEXT_PROTOCOL_IP4;
7223 u32 decap_next_index = LISP_GPE_INPUT_NEXT_IP4_INPUT;
7224 u8 flags = LISP_GPE_FLAGS_P;
7231 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) {
7232 if (unformat (line_input, "del"))
7234 else if (unformat (line_input, "src %U",
7235 unformat_ip4_address, &src))
7237 else if (unformat (line_input, "dst %U",
7238 unformat_ip4_address, &dst))
7240 else if (unformat (line_input, "encap-vrf-id %d", &encap_vrf_id))
7242 else if (unformat (line_input, "decap-vrf-id %d", &decap_vrf_id))
7244 else if (unformat (line_input, "decap-next %U",
7245 unformat_lisp_gpe_decap_next,
7248 else if (unformat(line_input, "next-ip4"))
7250 else if (unformat(line_input, "next-ip6"))
7252 else if (unformat(line_input, "next-ethernet"))
7254 else if (unformat(line_input, "next-nsh"))
7256 /* Allow the user to specify anything they want in the LISP hdr */
7257 else if (unformat (line_input, "ver_res %x", &tmp))
7259 else if (unformat (line_input, "res %x", &tmp))
7261 else if (unformat (line_input, "flags %x", &tmp))
7263 else if (unformat (line_input, "n-bit"))
7264 flags |= LISP_GPE_FLAGS_N;
7265 else if (unformat (line_input, "l-bit"))
7266 flags |= LISP_GPE_FLAGS_L;
7267 else if (unformat (line_input, "e-bit"))
7268 flags |= LISP_GPE_FLAGS_E;
7269 else if (unformat (line_input, "v-bit"))
7270 flags |= LISP_GPE_FLAGS_V;
7271 else if (unformat (line_input, "i-bit"))
7272 flags |= LISP_GPE_FLAGS_V;
7273 else if (unformat (line_input, "not-p-bit"))
7274 flags &= !LISP_GPE_FLAGS_P;
7275 else if (unformat (line_input, "p-bit"))
7276 flags |= LISP_GPE_FLAGS_P;
7277 else if (unformat (line_input, "o-bit"))
7278 flags |= LISP_GPE_FLAGS_O;
7279 else if (unformat (line_input, "iidx %x", &iid))
7281 else if (unformat (line_input, "iid %d", &iid))
7284 errmsg ("parse error '%U'\n", format_unformat_error, line_input);
7290 errmsg ("tunnel src address not specified\n");
7294 errmsg ("tunnel dst address not specified\n");
7298 errmsg ("iid not specified\n");
7302 M(LISP_GPE_ADD_DEL_TUNNEL, lisp_gpe_add_del_tunnel);
7304 mp->src = src.as_u32;
7305 mp->dst = dst.as_u32;
7306 mp->encap_vrf_id = ntohl(encap_vrf_id);
7307 mp->decap_vrf_id = ntohl(decap_vrf_id);
7308 mp->decap_next_index = ntohl(decap_next_index);
7309 mp->is_add = is_add;
7311 mp->ver_res = ver_res;
7313 mp->next_protocol = next_protocol;
7314 mp->iid = ntohl(iid);
7323 u8 * format_l2_fib_mac_address (u8 * s, va_list * args)
7325 u8 * a = va_arg (*args, u8 *);
7327 return format (s, "%02x:%02x:%02x:%02x:%02x:%02x",
7328 a[2], a[3], a[4], a[5], a[6], a[7]);
7331 static void vl_api_l2_fib_table_entry_t_handler
7332 (vl_api_l2_fib_table_entry_t * mp)
7334 vat_main_t * vam = &vat_main;
7336 fformat(vam->ofp, "%3" PRIu32 " %U %3" PRIu32
7338 ntohl(mp->bd_id), format_l2_fib_mac_address, &mp->mac,
7339 ntohl(mp->sw_if_index), mp->static_mac, mp->filter_mac,
7343 static void vl_api_l2_fib_table_entry_t_handler_json
7344 (vl_api_l2_fib_table_entry_t * mp)
7346 vat_main_t * vam = &vat_main;
7347 vat_json_node_t *node = NULL;
7349 if (VAT_JSON_ARRAY != vam->json_tree.type) {
7350 ASSERT(VAT_JSON_NONE == vam->json_tree.type);
7351 vat_json_init_array(&vam->json_tree);
7353 node = vat_json_array_add(&vam->json_tree);
7355 vat_json_init_object(node);
7356 vat_json_object_add_uint(node, "bd_id", ntohl(mp->bd_id));
7357 vat_json_object_add_uint(node, "mac", clib_net_to_host_u64(mp->mac));
7358 vat_json_object_add_uint(node, "sw_if_index", ntohl(mp->sw_if_index));
7359 vat_json_object_add_uint(node, "static_mac", mp->static_mac);
7360 vat_json_object_add_uint(node, "filter_mac", mp->filter_mac);
7361 vat_json_object_add_uint(node, "bvi_mac", mp->bvi_mac);
7364 static int api_l2_fib_table_dump (vat_main_t * vam)
7366 unformat_input_t * i = vam->input;
7367 vl_api_l2_fib_table_dump_t *mp;
7372 /* Parse args required to build the message */
7373 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
7374 if (unformat (i, "bd_id %d", &bd_id))
7380 if (bd_id_set == 0) {
7381 errmsg ("missing bridge domain\n");
7385 fformat(vam->ofp, "BD-ID Mac Address sw-ndx Static Filter BVI\n");
7387 /* Get list of l2 fib entries */
7388 M(L2_FIB_TABLE_DUMP, l2_fib_table_dump);
7390 mp->bd_id = ntohl(bd_id);
7393 /* Use a control ping for synchronization */
7395 vl_api_control_ping_t * mp;
7396 M(CONTROL_PING, control_ping);
7404 api_interface_name_renumber (vat_main_t * vam)
7406 unformat_input_t * line_input = vam->input;
7407 vl_api_interface_name_renumber_t *mp;
7408 u32 sw_if_index = ~0;
7410 u32 new_show_dev_instance = ~0;
7412 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) {
7413 if (unformat (line_input, "%U", unformat_sw_if_index, vam,
7416 else if (unformat (line_input, "sw_if_index %d", &sw_if_index))
7418 else if (unformat (line_input, "new_show_dev_instance %d",
7419 &new_show_dev_instance))
7425 if (sw_if_index == ~0) {
7426 errmsg ("missing interface name or sw_if_index\n");
7430 if (new_show_dev_instance == ~0) {
7431 errmsg ("missing new_show_dev_instance\n");
7435 M(INTERFACE_NAME_RENUMBER, interface_name_renumber);
7437 mp->sw_if_index = ntohl (sw_if_index);
7438 mp->new_show_dev_instance = ntohl (new_show_dev_instance);
7444 api_want_ip4_arp_events (vat_main_t * vam)
7446 unformat_input_t * line_input = vam->input;
7447 vl_api_want_ip4_arp_events_t * mp;
7449 ip4_address_t address;
7450 int address_set = 0;
7451 u32 enable_disable = 1;
7453 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) {
7454 if (unformat (line_input, "address %U",
7455 unformat_ip4_address, &address))
7457 else if (unformat (line_input, "del"))
7463 if (address_set == 0) {
7464 errmsg ("missing addresses\n");
7468 M(WANT_IP4_ARP_EVENTS, want_ip4_arp_events);
7469 mp->enable_disable = enable_disable;
7471 mp->address = address.as_u32;
7476 static int api_input_acl_set_interface (vat_main_t * vam)
7478 unformat_input_t * i = vam->input;
7479 vl_api_input_acl_set_interface_t *mp;
7482 int sw_if_index_set;
7483 u32 ip4_table_index = ~0;
7484 u32 ip6_table_index = ~0;
7485 u32 l2_table_index = ~0;
7488 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
7489 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
7490 sw_if_index_set = 1;
7491 else if (unformat (i, "sw_if_index %d", &sw_if_index))
7492 sw_if_index_set = 1;
7493 else if (unformat (i, "del"))
7495 else if (unformat (i, "ip4-table %d", &ip4_table_index))
7497 else if (unformat (i, "ip6-table %d", &ip6_table_index))
7499 else if (unformat (i, "l2-table %d", &l2_table_index))
7502 clib_warning ("parse error '%U'", format_unformat_error, i);
7507 if (sw_if_index_set == 0) {
7508 errmsg ("missing interface name or sw_if_index\n");
7512 M(INPUT_ACL_SET_INTERFACE, input_acl_set_interface);
7514 mp->sw_if_index = ntohl(sw_if_index);
7515 mp->ip4_table_index = ntohl(ip4_table_index);
7516 mp->ip6_table_index = ntohl(ip6_table_index);
7517 mp->l2_table_index = ntohl(l2_table_index);
7518 mp->is_add = is_add;
7526 api_ip_address_dump (vat_main_t * vam)
7528 unformat_input_t * i = vam->input;
7529 vl_api_ip_address_dump_t * mp;
7530 u32 sw_if_index = ~0;
7531 u8 sw_if_index_set = 0;
7536 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
7537 if (unformat (i, "sw_if_index %d", &sw_if_index))
7538 sw_if_index_set = 1;
7539 else if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
7540 sw_if_index_set = 1;
7541 else if (unformat (i, "ipv4"))
7543 else if (unformat (i, "ipv6"))
7549 if (ipv4_set && ipv6_set) {
7550 errmsg ("ipv4 and ipv6 flags cannot be both set\n");
7554 if ((!ipv4_set) && (!ipv6_set)) {
7555 errmsg ("no ipv4 nor ipv6 flag set\n");
7559 if (sw_if_index_set == 0) {
7560 errmsg ("missing interface name or sw_if_index\n");
7564 vam->current_sw_if_index = sw_if_index;
7565 vam->is_ipv6 = ipv6_set;
7567 M(IP_ADDRESS_DUMP, ip_address_dump);
7568 mp->sw_if_index = ntohl(sw_if_index);
7569 mp->is_ipv6 = ipv6_set;
7572 /* Use a control ping for synchronization */
7574 vl_api_control_ping_t * mp;
7575 M(CONTROL_PING, control_ping);
7582 api_ip_dump (vat_main_t * vam)
7584 vl_api_ip_dump_t * mp;
7585 unformat_input_t * in = vam->input;
7592 while (unformat_check_input (in) != UNFORMAT_END_OF_INPUT) {
7593 if (unformat (in, "ipv4"))
7595 else if (unformat (in, "ipv6"))
7601 if (ipv4_set && ipv6_set) {
7602 errmsg ("ipv4 and ipv6 flags cannot be both set\n");
7606 if ((!ipv4_set) && (!ipv6_set)) {
7607 errmsg ("no ipv4 nor ipv6 flag set\n");
7612 vam->is_ipv6 = is_ipv6;
7615 for (i = 0; i < vec_len(vam->ip_details_by_sw_if_index[is_ipv6]); i++) {
7616 vec_free(vam->ip_details_by_sw_if_index[is_ipv6][i].addr);
7618 vec_free(vam->ip_details_by_sw_if_index[is_ipv6]);
7620 M(IP_DUMP, ip_dump);
7621 mp->is_ipv6 = ipv6_set;
7624 /* Use a control ping for synchronization */
7626 vl_api_control_ping_t * mp;
7627 M(CONTROL_PING, control_ping);
7634 api_ipsec_spd_add_del (vat_main_t * vam)
7636 unformat_input_t * i = vam->input;
7637 vl_api_ipsec_spd_add_del_t *mp;
7642 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
7643 if (unformat (i, "spd_id %d", &spd_id))
7645 else if (unformat (i, "del"))
7648 clib_warning ("parse error '%U'", format_unformat_error, i);
7653 errmsg ("spd_id must be set\n");
7657 M(IPSEC_SPD_ADD_DEL, ipsec_spd_add_del);
7659 mp->spd_id = ntohl(spd_id);
7660 mp->is_add = is_add;
7668 api_ipsec_interface_add_del_spd (vat_main_t * vam)
7670 unformat_input_t * i = vam->input;
7671 vl_api_ipsec_interface_add_del_spd_t *mp;
7674 u8 sw_if_index_set = 0;
7675 u32 spd_id = (u32) ~0;
7678 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
7679 if (unformat (i, "del"))
7681 else if (unformat (i, "spd_id %d", &spd_id))
7683 else if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
7684 sw_if_index_set = 1;
7685 else if (unformat (i, "sw_if_index %d", &sw_if_index))
7686 sw_if_index_set = 1;
7688 clib_warning ("parse error '%U'", format_unformat_error, i);
7694 if (spd_id == (u32) ~0) {
7695 errmsg ("spd_id must be set\n");
7699 if (sw_if_index_set == 0) {
7700 errmsg ("missing interface name or sw_if_index\n");
7704 M(IPSEC_INTERFACE_ADD_DEL_SPD, ipsec_interface_add_del_spd);
7706 mp->spd_id = ntohl(spd_id);
7707 mp->sw_if_index = ntohl (sw_if_index);
7708 mp->is_add = is_add;
7716 api_ipsec_spd_add_del_entry (vat_main_t * vam)
7718 unformat_input_t * i = vam->input;
7719 vl_api_ipsec_spd_add_del_entry_t *mp;
7721 u8 is_add = 1, is_outbound = 0, is_ipv6 = 0, is_ip_any = 1;
7722 u32 spd_id, sa_id, protocol = 0, policy = 0;
7724 u32 rport_start = 0, rport_stop = (u32) ~0;
7725 u32 lport_start = 0, lport_stop = (u32) ~0;
7726 ip4_address_t laddr4_start, laddr4_stop, raddr4_start, raddr4_stop;
7727 ip6_address_t laddr6_start, laddr6_stop, raddr6_start, raddr6_stop;
7729 laddr4_start.as_u32 = raddr4_start.as_u32 = 0;
7730 laddr4_stop.as_u32 = raddr4_stop.as_u32 = (u32) ~0;
7731 laddr6_start.as_u64[0] = raddr6_start.as_u64[0] = 0;
7732 laddr6_start.as_u64[1] = raddr6_start.as_u64[1] = 0;
7733 laddr6_stop.as_u64[0] = raddr6_stop.as_u64[0] = (u64) ~0;
7734 laddr6_stop.as_u64[1] = raddr6_stop.as_u64[1] = (u64) ~0;
7736 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
7737 if (unformat (i, "del"))
7739 if (unformat (i, "outbound"))
7741 if (unformat (i, "inbound"))
7743 else if (unformat (i, "spd_id %d", &spd_id))
7745 else if (unformat (i, "sa_id %d", &sa_id))
7747 else if (unformat (i, "priority %d", &priority))
7749 else if (unformat (i, "protocol %d", &protocol))
7751 else if (unformat (i, "lport_start %d", &lport_start))
7753 else if (unformat (i, "lport_stop %d", &lport_stop))
7755 else if (unformat (i, "rport_start %d", &rport_start))
7757 else if (unformat (i, "rport_stop %d", &rport_stop))
7759 else if (unformat (i, "laddr_start %U", unformat_ip4_address, &laddr4_start))
7764 else if (unformat (i, "laddr_stop %U", unformat_ip4_address, &laddr4_stop))
7769 else if (unformat (i, "raddr_start %U", unformat_ip4_address, &raddr4_start))
7774 else if (unformat (i, "raddr_stop %U", unformat_ip4_address, &raddr4_stop))
7779 else if (unformat (i, "laddr_start %U", unformat_ip6_address, &laddr6_start))
7784 else if (unformat (i, "laddr_stop %U", unformat_ip6_address, &laddr6_stop))
7789 else if (unformat (i, "raddr_start %U", unformat_ip6_address, &raddr6_start))
7794 else if (unformat (i, "raddr_stop %U", unformat_ip6_address, &raddr6_stop))
7799 else if (unformat (i, "action %U", unformat_ipsec_policy_action, &policy))
7801 if (policy == IPSEC_POLICY_ACTION_RESOLVE) {
7802 clib_warning ("unsupported action: 'resolve'");
7807 clib_warning ("parse error '%U'", format_unformat_error, i);
7813 M(IPSEC_SPD_ADD_DEL_ENTRY, ipsec_spd_add_del_entry);
7815 mp->spd_id = ntohl(spd_id);
7816 mp->priority = ntohl(priority);
7817 mp->is_outbound = is_outbound;
7819 mp->is_ipv6 = is_ipv6;
7820 if (is_ipv6 || is_ip_any) {
7821 memcpy (mp->remote_address_start, &raddr6_start, sizeof(ip6_address_t));
7822 memcpy (mp->remote_address_stop, &raddr6_stop, sizeof(ip6_address_t));
7823 memcpy (mp->local_address_start, &laddr6_start, sizeof(ip6_address_t));
7824 memcpy (mp->local_address_stop, &laddr6_stop, sizeof(ip6_address_t));
7826 memcpy (mp->remote_address_start, &raddr4_start, sizeof(ip4_address_t));
7827 memcpy (mp->remote_address_stop, &raddr4_stop, sizeof(ip4_address_t));
7828 memcpy (mp->local_address_start, &laddr4_start, sizeof(ip4_address_t));
7829 memcpy (mp->local_address_stop, &laddr4_stop, sizeof(ip4_address_t));
7831 mp->protocol = (u8) protocol;
7832 mp->local_port_start = ntohs((u16) lport_start);
7833 mp->local_port_stop = ntohs((u16) lport_stop);
7834 mp->remote_port_start = ntohs((u16) rport_start);
7835 mp->remote_port_stop = ntohs((u16) rport_stop);
7836 mp->policy = (u8) policy;
7837 mp->sa_id = ntohl(sa_id);
7838 mp->is_add = is_add;
7839 mp->is_ip_any = is_ip_any;
7846 api_ipsec_sad_add_del_entry (vat_main_t * vam)
7848 unformat_input_t * i = vam->input;
7849 vl_api_ipsec_sad_add_del_entry_t *mp;
7855 u8 protocol = IPSEC_PROTOCOL_AH;
7856 u8 is_tunnel = 0, is_tunnel_ipv6 = 0;
7857 u32 crypto_alg = 0, integ_alg = 0;
7858 ip4_address_t tun_src4;
7859 ip4_address_t tun_dst4;
7860 ip6_address_t tun_src6;
7861 ip6_address_t tun_dst6;
7863 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
7864 if (unformat (i, "del"))
7866 else if (unformat (i, "sad_id %d", &sad_id))
7868 else if (unformat (i, "spi %d", &spi))
7870 else if (unformat (i, "esp"))
7871 protocol = IPSEC_PROTOCOL_ESP;
7872 else if (unformat (i, "tunnel_src %U", unformat_ip4_address, &tun_src4)) {
7876 else if (unformat (i, "tunnel_dst %U", unformat_ip4_address, &tun_dst4)) {
7880 else if (unformat (i, "tunnel_src %U", unformat_ip6_address, &tun_src6)) {
7884 else if (unformat (i, "tunnel_dst %U", unformat_ip6_address, &tun_dst6)) {
7888 else if (unformat (i, "crypto_alg %U", unformat_ipsec_crypto_alg, &crypto_alg)) {
7889 if (crypto_alg < IPSEC_CRYPTO_ALG_AES_CBC_128 ||
7890 crypto_alg > IPSEC_INTEG_ALG_SHA_512_256) {
7891 clib_warning ("unsupported crypto-alg: '%U'",
7892 format_ipsec_crypto_alg, crypto_alg);
7896 else if (unformat (i, "crypto_key %U", unformat_hex_string, &ck))
7898 else if (unformat (i, "integ_alg %U", unformat_ipsec_integ_alg, &integ_alg)) {
7899 if (integ_alg < IPSEC_INTEG_ALG_SHA1_96 ||
7900 integ_alg > IPSEC_INTEG_ALG_SHA_512_256) {
7901 clib_warning ("unsupported integ-alg: '%U'",
7902 format_ipsec_integ_alg, integ_alg);
7906 else if (unformat (i, "integ_key %U", unformat_hex_string, &ik))
7909 clib_warning ("parse error '%U'", format_unformat_error, i);
7915 M(IPSEC_SAD_ADD_DEL_ENTRY, ipsec_sad_add_del_entry);
7917 mp->sad_id = ntohl(sad_id);
7918 mp->is_add = is_add;
7919 mp->protocol = protocol;
7920 mp->spi = ntohl(spi);
7921 mp->is_tunnel = is_tunnel;
7922 mp->is_tunnel_ipv6 = is_tunnel_ipv6;
7923 mp->crypto_algorithm = crypto_alg;
7924 mp->integrity_algorithm = integ_alg;
7925 mp->crypto_key_length = vec_len(ck);
7926 mp->integrity_key_length = vec_len(ik);
7928 if (mp->crypto_key_length > sizeof(mp->crypto_key))
7929 mp->crypto_key_length = sizeof(mp->crypto_key);
7931 if (mp->integrity_key_length > sizeof(mp->integrity_key))
7932 mp->integrity_key_length = sizeof(mp->integrity_key);
7934 memcpy (mp->crypto_key, ck, mp->crypto_key_length);
7935 memcpy (mp->integrity_key, ik, mp->integrity_key_length);
7938 if (is_tunnel_ipv6) {
7939 memcpy (mp->tunnel_src_address, &tun_src6, sizeof(ip6_address_t));
7940 memcpy (mp->tunnel_dst_address, &tun_dst6, sizeof(ip6_address_t));
7942 memcpy (mp->tunnel_src_address, &tun_src4, sizeof(ip4_address_t));
7943 memcpy (mp->tunnel_dst_address, &tun_dst4, sizeof(ip4_address_t));
7953 api_ipsec_sa_set_key (vat_main_t * vam)
7955 unformat_input_t * i = vam->input;
7956 vl_api_ipsec_sa_set_key_t *mp;
7961 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
7962 if (unformat (i, "sa_id %d", &sa_id))
7964 else if (unformat (i, "crypto_key %U", unformat_hex_string, &ck))
7966 else if (unformat (i, "integ_key %U", unformat_hex_string, &ik))
7969 clib_warning ("parse error '%U'", format_unformat_error, i);
7974 M(IPSEC_SA_SET_KEY, ipsec_set_sa_key);
7976 mp->sa_id = ntohl(sa_id);
7977 mp->crypto_key_length = vec_len(ck);
7978 mp->integrity_key_length = vec_len(ik);
7980 if (mp->crypto_key_length > sizeof(mp->crypto_key))
7981 mp->crypto_key_length = sizeof(mp->crypto_key);
7983 if (mp->integrity_key_length > sizeof(mp->integrity_key))
7984 mp->integrity_key_length = sizeof(mp->integrity_key);
7986 memcpy (mp->crypto_key, ck, mp->crypto_key_length);
7987 memcpy (mp->integrity_key, ik, mp->integrity_key_length);
7997 static int api_map_add_domain (vat_main_t * vam)
7999 unformat_input_t *i = vam->input;
8000 vl_api_map_add_domain_t *mp;
8003 ip4_address_t ip4_prefix;
8004 ip6_address_t ip6_prefix;
8005 ip6_address_t ip6_src;
8007 u32 ip6_prefix_len, ip4_prefix_len, ea_bits_len, psid_offset,
8009 u8 is_translation = 0;
8011 u8 ip6_src_len = 128;
8013 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
8014 if (unformat (i, "ip4-pfx %U/%d", unformat_ip4_address,
8015 &ip4_prefix, &ip4_prefix_len))
8017 else if (unformat (i, "ip6-pfx %U/%d", unformat_ip6_address,
8018 &ip6_prefix, &ip6_prefix_len))
8020 else if (unformat (i, "ip6-src %U/%d", unformat_ip6_address, &ip6_src, &ip6_src_len))
8022 else if (unformat (i, "ip6-src %U", unformat_ip6_address, &ip6_src))
8024 else if (unformat (i, "ea-bits-len %d", &ea_bits_len))
8026 else if (unformat (i, "psid-offset %d", &psid_offset))
8028 else if (unformat (i, "psid-len %d", &psid_length))
8030 else if (unformat (i, "mtu %d", &mtu))
8032 else if (unformat (i, "map-t"))
8035 clib_warning ("parse error '%U'", format_unformat_error, i);
8040 if (num_m_args != 6) {
8041 errmsg("mandatory argument(s) missing\n");
8045 /* Construct the API message */
8046 M(MAP_ADD_DOMAIN, map_add_domain);
8048 memcpy(mp->ip4_prefix, &ip4_prefix, sizeof(ip4_prefix));
8049 mp->ip4_prefix_len = ip4_prefix_len;
8051 memcpy(mp->ip6_prefix, &ip6_prefix, sizeof(ip6_prefix));
8052 mp->ip6_prefix_len = ip6_prefix_len;
8054 memcpy(mp->ip6_src, &ip6_src, sizeof(ip6_src));
8055 mp->ip6_src_prefix_len = ip6_src_len;
8057 mp->ea_bits_len = ea_bits_len;
8058 mp->psid_offset = psid_offset;
8059 mp->psid_length = psid_length;
8060 mp->is_translation = is_translation;
8061 mp->mtu = htons(mtu);
8066 /* Wait for a reply, return good/bad news */
8070 static int api_map_del_domain (vat_main_t * vam)
8072 unformat_input_t *i = vam->input;
8073 vl_api_map_del_domain_t *mp;
8079 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
8080 if (unformat (i, "index %d", &index))
8083 clib_warning ("parse error '%U'", format_unformat_error, i);
8088 if (num_m_args != 1) {
8089 errmsg("mandatory argument(s) missing\n");
8093 /* Construct the API message */
8094 M(MAP_DEL_DOMAIN, map_del_domain);
8096 mp->index = ntohl(index);
8101 /* Wait for a reply, return good/bad news */
8105 static int api_map_add_del_rule (vat_main_t * vam)
8107 unformat_input_t *i = vam->input;
8108 vl_api_map_add_del_rule_t *mp;
8111 ip6_address_t ip6_dst;
8112 u32 num_m_args = 0, index, psid;
8114 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
8115 if (unformat (i, "index %d", &index))
8117 else if (unformat (i, "psid %d", &psid))
8119 else if (unformat (i, "dst %U", unformat_ip6_address, &ip6_dst))
8121 else if (unformat (i, "del")) {
8124 clib_warning ("parse error '%U'", format_unformat_error, i);
8129 /* Construct the API message */
8130 M(MAP_ADD_DEL_RULE, map_add_del_rule);
8132 mp->index = ntohl(index);
8133 mp->is_add = is_add;
8134 memcpy(mp->ip6_dst, &ip6_dst, sizeof(ip6_dst));
8135 mp->psid = ntohs(psid);
8140 /* Wait for a reply, return good/bad news */
8144 static int api_map_domain_dump (vat_main_t * vam)
8146 vl_api_map_domain_dump_t *mp;
8149 /* Construct the API message */
8150 M(MAP_DOMAIN_DUMP, map_domain_dump);
8155 /* Use a control ping for synchronization */
8157 vl_api_control_ping_t * mp;
8158 M(CONTROL_PING, control_ping);
8164 static int api_map_rule_dump (vat_main_t * vam)
8166 unformat_input_t *i = vam->input;
8167 vl_api_map_rule_dump_t *mp;
8169 u32 domain_index = ~0;
8171 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
8172 if (unformat (i, "index %u", &domain_index))
8178 if (domain_index == ~0) {
8179 clib_warning("parse error: domain index expected");
8183 /* Construct the API message */
8184 M(MAP_RULE_DUMP, map_rule_dump);
8186 mp->domain_index = htonl(domain_index);
8191 /* Use a control ping for synchronization */
8193 vl_api_control_ping_t * mp;
8194 M(CONTROL_PING, control_ping);
8200 static void vl_api_map_add_domain_reply_t_handler
8201 (vl_api_map_add_domain_reply_t * mp)
8203 vat_main_t * vam = &vat_main;
8204 i32 retval = ntohl(mp->retval);
8206 if (vam->async_mode) {
8207 vam->async_errors += (retval < 0);
8209 vam->retval = retval;
8210 vam->result_ready = 1;
8214 static void vl_api_map_add_domain_reply_t_handler_json
8215 (vl_api_map_add_domain_reply_t * mp)
8217 vat_main_t * vam = &vat_main;
8218 vat_json_node_t node;
8220 vat_json_init_object(&node);
8221 vat_json_object_add_int(&node, "retval", ntohl(mp->retval));
8222 vat_json_object_add_uint(&node, "index", ntohl(mp->index));
8224 vat_json_print(vam->ofp, &node);
8225 vat_json_free(&node);
8227 vam->retval = ntohl(mp->retval);
8228 vam->result_ready = 1;
8232 api_get_first_msg_id (vat_main_t * vam)
8234 vl_api_get_first_msg_id_t * mp;
8236 unformat_input_t * i = vam->input;
8240 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
8241 if (unformat (i, "client %s", &name))
8247 if (name_set == 0) {
8248 errmsg ("missing client name\n");
8253 if (vec_len (name) > 63) {
8254 errmsg ("client name too long\n");
8258 M(GET_FIRST_MSG_ID, get_first_msg_id);
8259 memcpy (mp->name, name, vec_len(name));
8265 static int q_or_quit (vat_main_t * vam)
8267 longjmp (vam->jump_buf, 1);
8268 return 0; /* not so much */
8270 static int q (vat_main_t * vam) {return q_or_quit (vam);}
8271 static int quit (vat_main_t * vam) {return q_or_quit (vam);}
8273 static int comment (vat_main_t * vam)
8278 static int help (vat_main_t * vam)
8283 unformat_input_t * i = vam->input;
8286 if (unformat (i, "%s", &name)) {
8291 hs = hash_get_mem (vam->help_by_name, name);
8293 fformat (vam->ofp, "usage: %s %s\n", name, hs[0]);
8295 fformat (vam->ofp, "No such msg / command '%s'\n", name);
8300 fformat(vam->ofp, "Help is available for the following:\n");
8302 hash_foreach_pair (p, vam->function_by_name,
8304 vec_add1 (cmds, (u8 *)(p->key));
8307 vec_sort (cmds, c1, c2,
8308 strcmp ((char *)(c1[0]), (char *)(c2[0])));
8310 for (j = 0; j < vec_len(cmds); j++)
8311 fformat (vam->ofp, "%s\n", cmds[j]);
8317 static int set (vat_main_t * vam)
8319 u8 * name = 0, * value = 0;
8320 unformat_input_t * i = vam->input;
8322 if (unformat (i, "%s", &name)) {
8323 /* The input buffer is a vector, not a string. */
8324 value = vec_dup (i->buffer);
8325 vec_delete (value, i->index, 0);
8326 /* Almost certainly has a trailing newline */
8327 if (value[vec_len(value)-1] == '\n')
8328 value[vec_len(value)-1] = 0;
8329 /* Make sure it's a proper string, one way or the other */
8330 vec_add1 (value, 0);
8331 (void) clib_macro_set_value (&vam->macro_main,
8332 (char *)name, (char *)value);
8335 errmsg ("usage: set <name> <value>\n");
8342 static int unset (vat_main_t * vam)
8346 if (unformat (vam->input, "%s", &name))
8347 if (clib_macro_unset (&vam->macro_main, (char *)name) == 1)
8348 errmsg ("unset: %s wasn't set\n", name);
8359 static int dump_macro_table (vat_main_t * vam)
8361 macro_sort_t * sort_me = 0, * sm;
8365 hash_foreach_pair (p, vam->macro_main.the_value_table_hash,
8367 vec_add2 (sort_me, sm, 1);
8368 sm->name = (u8 *)(p->key);
8369 sm->value = (u8 *) (p->value[0]);
8372 vec_sort (sort_me, s1, s2, strcmp ((char *)(s1->name), (char *)(s2->name)));
8374 if (vec_len(sort_me))
8375 fformat (vam->ofp, "%-15s%s\n", "Name", "Value");
8377 fformat (vam->ofp, "The macro table is empty...\n");
8379 for (i = 0; i < vec_len (sort_me); i++)
8380 fformat (vam->ofp, "%-15s%s\n", sort_me[i].name,
8385 static int script (vat_main_t * vam)
8388 char * save_current_file;
8389 unformat_input_t save_input;
8390 jmp_buf save_jump_buf;
8391 u32 save_line_number;
8393 FILE * new_fp, * save_ifp;
8395 if (unformat (vam->input, "%s", &s)) {
8396 new_fp = fopen ((char *)s, "r");
8398 errmsg ("Couldn't open script file %s\n", s);
8403 errmsg ("Missing script name\n");
8407 memcpy (&save_input, &vam->input, sizeof (save_input));
8408 memcpy (&save_jump_buf, &vam->jump_buf, sizeof (save_jump_buf));
8409 save_ifp = vam->ifp;
8410 save_line_number = vam->input_line_number;
8411 save_current_file = (char *) vam->current_file;
8413 vam->input_line_number = 0;
8415 vam->current_file = s;
8418 memcpy (&vam->input, &save_input, sizeof (vam->input));
8419 memcpy (&vam->jump_buf, &save_jump_buf, sizeof (save_jump_buf));
8420 vam->ifp = save_ifp;
8421 vam->input_line_number = save_line_number;
8422 vam->current_file = (u8 *) save_current_file;
8428 static int echo (vat_main_t * vam)
8430 fformat (vam->ofp, "%v", vam->input->buffer);
8434 /* List of API message constructors, CLI names map to api_xxx */
8435 #define foreach_vpe_api_msg \
8436 _(create_loopback,"[mac <mac-addr>]") \
8437 _(sw_interface_dump,"") \
8438 _(sw_interface_set_flags, \
8439 "<intfc> | sw_if_index <id> admin-up | admin-down link-up | link down") \
8440 _(sw_interface_add_del_address, \
8441 "<intfc> | sw_if_index <id> <ip4-address> | <ip6-address> [del] [del-all] ") \
8442 _(sw_interface_set_table, \
8443 "<intfc> | sw_if_index <id> vrf <table-id> [ipv6]") \
8444 _(sw_interface_set_vpath, \
8445 "<intfc> | sw_if_index <id> enable | disable") \
8446 _(sw_interface_set_l2_xconnect, \
8447 "rx <intfc> | rx_sw_if_index <id> tx <intfc> | tx_sw_if_index <id>\n" \
8448 "enable | disable") \
8449 _(sw_interface_set_l2_bridge, \
8450 "rx <intfc> | rx_sw_if_index <id> bd_id <bridge-domain-id>\n" \
8451 "[shg <split-horizon-group>] [bvi]\n" \
8452 "enable | disable") \
8453 _(bridge_domain_add_del, \
8454 "bd_id <bridge-domain-id> [flood 1|0] [uu-flood 1|0] [forward 1|0] [learn 1|0] [arp-term 1|0] [del]\n")\
8455 _(bridge_domain_dump, "[bd_id <bridge-domain-id>]\n") \
8457 "mac <mac-addr> bd_id <bridge-domain-id> [del] | sw_if <intfc> | sw_if_index <id> [static] [filter] [bvi]\n") \
8459 "sw_if <intfc> | sw_if_index <id> [learn] [forward] [uu-flood] [flood]\n") \
8461 "bd_id <bridge-domain-id> [learn] [forward] [uu-flood] [flood] [arp-term] [disable]\n") \
8463 "tapname <name> mac <mac-addr> | random-mac") \
8465 "<vpp-if-name> | sw_if_index <id> tapname <name> mac <mac-addr> | random-mac") \
8467 "<vpp-if-name> | sw_if_index <id>") \
8468 _(sw_interface_tap_dump, "") \
8469 _(ip_add_del_route, \
8470 "<addr>/<mask> via <addr> [vrf <n>]\n" \
8471 "[<intfc> | sw_if_index <id>] [resolve-attempts <n>]\n" \
8472 "[weight <n>] [drop] [local] [classify <n>] [del]\n" \
8473 "[multipath] [count <n>]") \
8474 _(proxy_arp_add_del, \
8475 "<lo-ip4-addr> - <hi-ip4-addr> [vrf <n>] [del]") \
8476 _(proxy_arp_intfc_enable_disable, \
8477 "<intfc> | sw_if_index <id> enable | disable") \
8478 _(mpls_add_del_encap, \
8479 "label <n> dst <ip4-addr> [vrf <n>] [del]") \
8480 _(mpls_add_del_decap, \
8481 "label <n> [rx_vrf_id <n>] [tx_vrf_id] [s-bit-clear][del]") \
8482 _(mpls_gre_add_del_tunnel, \
8483 "inner_vrf_id <n> outer_vrf_id <n> src <ip4-address> dst <ip4-address>\n" \
8484 "adj <ip4-address>/<mask-width> [del]") \
8485 _(sw_interface_set_unnumbered, \
8486 "<intfc> | sw_if_index <id> unnum_if_index <id> [del]") \
8487 _(ip_neighbor_add_del, \
8488 "<intfc> | sw_if_index <id> dst <ip46-address> mac <mac-addr>") \
8489 _(reset_vrf, "vrf <id> [ipv6]") \
8490 _(create_vlan_subif, "<intfc> | sw_if_index <id> vlan <n>") \
8491 _(create_subif, "<intfc> | sw_if_index <id> sub_id <n>\n" \
8492 "[outer_vlan_id <n>][inner_vlan_id <n>]\n" \
8493 "[no_tags][one_tag][two_tags][dot1ad][exact_match][default_sub]\n" \
8494 "[outer_vlan_id_any][inner_vlan_id_any]") \
8495 _(oam_add_del, "src <ip4-address> dst <ip4-address> [vrf <n>] [del]") \
8496 _(reset_fib, "vrf <n> [ipv6]") \
8497 _(dhcp_proxy_config, \
8498 "svr <v46-address> src <v46-address>\n" \
8499 "insert-cid <n> [del]") \
8500 _(dhcp_proxy_config_2, \
8501 "svr <v46-address> src <v46-address>\n" \
8502 "rx_vrf_id <nn> server_vrf_id <nn> insert-cid <n> [del]") \
8503 _(dhcp_proxy_set_vss, \
8504 "tbl_id <n> fib_id <n> oui <n> [ipv6] [del]") \
8505 _(dhcp_client_config, \
8506 "<intfc> | sw_if_index <id> [hostname <name>] [disable_event] [del]") \
8507 _(set_ip_flow_hash, \
8508 "vrf <n> [src] [dst] [sport] [dport] [proto] [reverse] [ipv6]") \
8509 _(sw_interface_ip6_enable_disable, \
8510 "<intfc> | sw_if_index <id> enable | disable") \
8511 _(sw_interface_ip6_set_link_local_address, \
8512 "<intfc> | sw_if_index <id> <ip6-address>/<mask-width>") \
8513 _(sw_interface_ip6nd_ra_prefix, \
8514 "<intfc> | sw_if_index <id> <ip6-address>/<mask-width>\n" \
8515 "val_life <n> pref_life <n> [def] [noadv] [offl] [noauto]\n" \
8516 "[nolink] [isno]") \
8517 _(sw_interface_ip6nd_ra_config, \
8518 "<intfc> | sw_if_index <id> [maxint <n>] [minint <n>]\n" \
8519 "[life <n>] [count <n>] [interval <n>] [surpress]\n" \
8520 "[managed] [other] [ll] [send] [cease] [isno] [def]") \
8521 _(set_arp_neighbor_limit, "arp_nbr_limit <n> [ipv6]") \
8522 _(l2_patch_add_del, \
8523 "rx <intfc> | rx_sw_if_index <id> tx <intfc> | tx_sw_if_index <id>\n" \
8524 "enable | disable") \
8525 _(mpls_ethernet_add_del_tunnel, \
8526 "tx <intfc> | tx_sw_if_index <n> dst <mac-addr>\n" \
8527 "adj <ip4-addr>/<mw> dst <mac-addr> [del]") \
8528 _(mpls_ethernet_add_del_tunnel_2, \
8529 "inner_vrf_id <n> outer_vrf_id <n> next-hop <ip4-addr>\n" \
8530 "resolve-attempts <n> resolve-if-needed 0 | 1 [del]") \
8531 _(sr_tunnel_add_del, \
8532 "src <ip6-addr> dst <ip6-addr>/<mw> (next <ip6-addr>)+\n" \
8533 " [tag <ip6-addr>]* [clean] [reroute]") \
8534 _(classify_add_del_table, \
8535 "buckets <nn> [skip <n>] [match <n>] [memory_size <nn-bytes>]\n" \
8536 "[del] mask <mask-value>\n" \
8537 " [l2-miss-next | miss-next | acl-miss-next] <name|nn>") \
8538 _(classify_add_del_session, \
8539 "[hit-next|l2-hit-next|acl-hit-next] <name|nn> table-index <nn>\n" \
8540 "skip_n <nn> match_n <nn> match [hex] [l2] [l3 [ip4|ip6]]") \
8541 _(classify_set_interface_ip_table, \
8542 "<intfc> | sw_if_index <nn> table <nn>") \
8543 _(classify_set_interface_l2_tables, \
8544 "<intfc> | sw_if_index <nn> [ip4-table <nn>] [ip6-table <nn>]\n" \
8545 " [other-table <nn>]") \
8546 _(get_node_index, "node <node-name") \
8547 _(add_node_next, "node <node-name> next <next-node-name>") \
8548 _(l2tpv3_create_tunnel, \
8549 "client_address <ip6-addr> our_address <ip6-addr>\n" \
8550 "[local_session_id <nn>][remote_session_id <nn>][local_cookie <nn>]\n"\
8551 "[remote_cookie <nn>]\n[l2-sublayer-preset]\n") \
8552 _(l2tpv3_set_tunnel_cookies, \
8553 "<intfc> | sw_if_index <nn> [new_local_cookie <nn>]\n" \
8554 "[new_remote_cookie <nn>]\n") \
8555 _(l2tpv3_interface_enable_disable, \
8556 "<intfc> | sw_if_index <nn> enable | disable") \
8557 _(l2tpv3_set_lookup_key, \
8558 "lookup_v6_src | lookup_v6_dst | lookup_session_id") \
8559 _(sw_if_l2tpv3_tunnel_dump, "") \
8560 _(vxlan_add_del_tunnel, \
8561 "src <ip4-addr> dst <ip4-addr> vni [encap-vrf-id <nn>]\n" \
8562 " [decap-next l2|ip4|ip6] [del]") \
8563 _(l2_fib_clear_table, "") \
8564 _(l2_interface_efp_filter, "sw_if_index <nn> enable | disable") \
8565 _(l2_interface_vlan_tag_rewrite, \
8566 "<intfc> | sw_if_index <nn> \n" \
8567 "[disable][push-[1|2]][pop-[1|2]][translate-1-[1|2]] \n" \
8568 "[translate-2-[1|2]] [push_dot1q 0] tag1 <nn> tag2 <nn>") \
8569 _(create_vhost_user_if, \
8570 "socket <filename> [server] [renumber <dev_instance>]") \
8571 _(modify_vhost_user_if, \
8572 "<intfc> | sw_if_index <nn> socket <filename>\n" \
8573 "[server] [renumber <dev_instance>]") \
8574 _(delete_vhost_user_if, "<intfc> | sw_if_index <nn>") \
8575 _(sw_interface_vhost_user_dump, "") \
8576 _(show_version, "") \
8577 _(nsh_gre_add_del_tunnel, \
8578 "src <ip4-addr> dst <ip4-addr>" \
8579 "c1 <nn> c2 <nn> c3 <nn> c4 <nn> spi <nn> si <nn>\n" \
8580 "[encap-fib-id <nn>] [decap-fib-id <nn>] [o-bit <1|0>]\n" \
8581 "[c-bit <1|0>] [md-type <nn>][next-ip4][next-ip6][next-ethernet]\n" \
8582 "[tlv <xx>][del]") \
8583 _(nsh_vxlan_gpe_add_del_tunnel, \
8584 "src <ip4-addr> dst <ip4-addr> vni <nn>\n" \
8585 "c1 <nn> c2 <nn> c3 <nn> c4 <nn> spi <nn> si <nn>\n" \
8586 "[encap-vrf-id <nn>] [decap-vrf-id <nn>] [o-bit <1|0>]\n" \
8587 "[c-bit <1|0>] [md-type <nn>][next-ip4][next-ip6][next-ethernet]\n" \
8588 "[tlv <xx>][del]") \
8589 _(l2_fib_table_dump, "bd_id <bridge-domain-id>") \
8590 _(lisp_gpe_add_del_tunnel, \
8591 "src <ip4-addr> dst <ip4-addr> iid <nn>|iidx <0xnn>\n" \
8592 "[encap-vrf-id <nn>] [decap-vrf-id <nn>]\n" \
8593 "[n-bit][l-bit][e-bit][v-bit][i-bit][p-bit][not-p-bit][o-bit]\n" \
8594 "[next-ip4][next-ip6][next-ethernet][next-nsh]\n" \
8595 "[decap-next [ip4|ip6|ethernet|nsh-encap|<nn>]][del]") \
8596 _(interface_name_renumber, \
8597 "<intfc> | sw_if_index <nn> new_show_dev_instance <nn>") \
8598 _(input_acl_set_interface, \
8599 "<intfc> | sw_if_index <nn> [ip4-table <nn>] [ip6-table <nn>]\n" \
8600 " [l2-table <nn>] [del]") \
8601 _(want_ip4_arp_events, "address <ip4-address> [del]") \
8602 _(ip_address_dump, "(ipv4 | ipv6) (<intfc> | sw_if_index <id>)") \
8603 _(ip_dump, "ipv4 | ipv6") \
8604 _(ipsec_spd_add_del, "spd_id <n> [del]") \
8605 _(ipsec_interface_add_del_spd, "(<intfc> | sw_if_index <id>)\n" \
8607 _(ipsec_sad_add_del_entry, "sad_id <n> spi <n> crypto_alg <alg>\n" \
8608 " crypto_key <hex> tunnel_src <ip4|ip6> tunnel_dst <ip4|ip6>\n" \
8609 " integ_alg <alg> integ_key <hex>") \
8610 _(ipsec_spd_add_del_entry, "spd_id <n> priority <n> action <action>\n" \
8611 " (inbound|outbound) [sa_id <n>] laddr_start <ip4|ip6>\n" \
8612 " laddr_stop <ip4|ip6> raddr_start <ip4|ip6> raddr_stop <ip4|ip6>\n" \
8613 " [lport_start <n> lport_stop <n>] [rport_start <n> rport_stop <n>]" )\
8614 _(ipsec_sa_set_key, "sa_id <n> crypto_key <hex> integ_key <hex>") \
8615 _(delete_loopback,"sw_if_index <nn>") \
8616 _(bd_ip_mac_add_del, "bd_id <bridge-domain-id> <ip4/6-addr> <mac-addr> [del]") \
8618 "ip4-pfx <ip4pfx> ip6-pfx <ip6pfx> " \
8619 "ip6-src <ip6addr> " \
8620 "ea-bits-len <n> psid-offset <n> psid-len <n>") \
8621 _(map_del_domain, "index <n>") \
8622 _(map_add_del_rule, \
8623 "index <n> psid <n> dst <ip6addr> [del]") \
8624 _(map_domain_dump, "") \
8625 _(map_rule_dump, "index <map-domain>") \
8626 _(want_interface_events, "enable|disable") \
8627 _(want_stats,"enable|disable") \
8628 _(get_first_msg_id, "client <name>")
8630 /* List of command functions, CLI names map directly to functions */
8631 #define foreach_cli_function \
8632 _(comment, "usage: comment <ignore-rest-of-line>") \
8633 _(dump_interface_table, "usage: dump_interface_table") \
8634 _(dump_sub_interface_table, "usage: dump_sub_interface_table") \
8635 _(dump_ipv4_table, "usage: dump_ipv4_table") \
8636 _(dump_ipv6_table, "usage: dump_ipv6_table") \
8637 _(dump_stats_table, "usage: dump_stats_table") \
8638 _(dump_macro_table, "usage: dump_macro_table ") \
8639 _(echo, "usage: echo <message>") \
8640 _(exec, "usage: exec <vpe-debug-CLI-command>") \
8641 _(help, "usage: help") \
8642 _(q, "usage: quit") \
8643 _(quit, "usage: quit") \
8644 _(set, "usage: set <variable-name> <value>") \
8645 _(script, "usage: script <file-name>") \
8646 _(unset, "usage: unset <variable-name>")
8649 static void vl_api_##n##_t_handler_uni \
8650 (vl_api_##n##_t * mp) \
8652 vat_main_t * vam = &vat_main; \
8653 if (vam->json_output) { \
8654 vl_api_##n##_t_handler_json(mp); \
8656 vl_api_##n##_t_handler(mp); \
8659 foreach_vpe_api_reply_msg;
8662 void vat_api_hookup (vat_main_t *vam)
8665 vl_msg_api_set_handlers(VL_API_##N, #n, \
8666 vl_api_##n##_t_handler_uni, \
8668 vl_api_##n##_t_endian, \
8669 vl_api_##n##_t_print, \
8670 sizeof(vl_api_##n##_t), 1);
8671 foreach_vpe_api_reply_msg;
8674 vl_msg_api_set_first_available_msg_id (VL_MSG_FIRST_AVAILABLE);
8676 vam->sw_if_index_by_interface_name =
8677 hash_create_string (0, sizeof (uword));
8679 vam->function_by_name =
8680 hash_create_string (0, sizeof(uword));
8683 hash_create_string (0, sizeof(uword));
8685 /* API messages we can send */
8686 #define _(n,h) hash_set_mem (vam->function_by_name, #n, api_##n);
8687 foreach_vpe_api_msg;
8691 #define _(n,h) hash_set_mem (vam->help_by_name, #n, h);
8692 foreach_vpe_api_msg;
8696 #define _(n,h) hash_set_mem (vam->function_by_name, #n, n);
8697 foreach_cli_function;
8701 #define _(n,h) hash_set_mem (vam->help_by_name, #n, h);
8702 foreach_cli_function;
8706 #undef vl_api_version
8707 #define vl_api_version(n,v) static u32 vpe_api_version = v;
8708 #include <api/vpe.api.h>
8709 #undef vl_api_version
8711 void vl_client_add_api_signatures (vl_api_memclnt_create_t *mp)
8714 * Send the main API signature in slot 0. This bit of code must
8715 * match the checks in ../vpe/api/api.c: vl_msg_api_version_check().
8717 mp->api_versions[0] = clib_host_to_net_u32 (vpe_api_version);