2 *------------------------------------------------------------------
5 * Copyright (c) 2014 Cisco and/or its affiliates.
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at:
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 *------------------------------------------------------------------
21 #include <vlibapi/api.h>
22 #include <vlibmemory/api.h>
23 #include <vlibsocket/api.h>
24 #include <vnet/ip/ip.h>
25 #include <vnet/sr/sr_packet.h>
26 #include <vnet/l2/l2_input.h>
27 #include <vnet/l2tp/l2tp.h>
28 #include <vnet/vxlan/vxlan.h>
29 #include <vnet/gre/gre.h>
30 #include <vnet/vxlan-gpe/vxlan_gpe.h>
31 #include <vnet/lisp-gpe/lisp_gpe.h>
33 #include <api/vpe_msg_enum.h>
34 #include <vnet/l2/l2_classify.h>
35 #include <vnet/l2/l2_vtr.h>
36 #include <vnet/classify/input_acl.h>
38 #include <vnet/ipsec/ipsec.h>
39 #include <vnet/ipsec/ikev2.h>
43 #include <vnet/map/map.h>
44 #include <vnet/cop/cop.h>
45 #include <vnet/ip/ip6_hop_by_hop.h>
46 #include <vnet/policer/xlate.h>
48 #include "vat/json_format.h"
50 #define vl_typedefs /* define message structures */
51 #include <api/vpe_all_api_h.h>
54 /* declare message handlers for each api */
56 #define vl_endianfun /* define message structures */
57 #include <api/vpe_all_api_h.h>
60 /* instantiate all the print functions we know about */
61 #define vl_print(handle, ...)
63 #include <api/vpe_all_api_h.h>
66 uword unformat_sw_if_index (unformat_input_t * input, va_list * args)
68 vat_main_t * vam = va_arg (*args, vat_main_t *);
69 u32 * result = va_arg (*args, u32 *);
73 if (!unformat (input, "%s", &if_name))
76 p = hash_get_mem (vam->sw_if_index_by_interface_name, if_name);
83 /* Parse an IP4 address %d.%d.%d.%d. */
84 uword unformat_ip4_address (unformat_input_t * input, va_list * args)
86 u8 * result = va_arg (*args, u8 *);
89 if (! unformat (input, "%d.%d.%d.%d", &a[0], &a[1], &a[2], &a[3]))
92 if (a[0] >= 256 || a[1] >= 256 || a[2] >= 256 || a[3] >= 256)
105 unformat_ethernet_address (unformat_input_t * input, va_list * args)
107 u8 * result = va_arg (*args, u8 *);
110 if (! unformat (input, "%_%x:%x:%x:%x:%x:%x%_",
111 &a[0], &a[1], &a[2], &a[3], &a[4], &a[5]))
115 for (i = 0; i < 6; i++)
116 if (a[i] >= (1 << 8))
119 for (i = 0; i < 6; i++)
125 /* Returns ethernet type as an int in host byte order. */
127 unformat_ethernet_type_host_byte_order (unformat_input_t * input,
130 u16 * result = va_arg (*args, u16 *);
134 if (unformat (input, "0x%x", &type)
135 || unformat (input, "%d", &type))
137 if (type >= (1 << 16))
145 /* Parse an IP6 address. */
146 uword unformat_ip6_address (unformat_input_t * input, va_list * args)
148 ip6_address_t * result = va_arg (*args, ip6_address_t *);
150 uword hex_quad, n_hex_quads, hex_digit, n_hex_digits;
151 uword c, n_colon, double_colon_index;
153 n_hex_quads = hex_quad = n_hex_digits = n_colon = 0;
154 double_colon_index = ARRAY_LEN (hex_quads);
155 while ((c = unformat_get_input (input)) != UNFORMAT_END_OF_INPUT)
158 if (c >= '0' && c <= '9')
160 else if (c >= 'a' && c <= 'f')
161 hex_digit = c + 10 - 'a';
162 else if (c >= 'A' && c <= 'F')
163 hex_digit = c + 10 - 'A';
164 else if (c == ':' && n_colon < 2)
168 unformat_put_input (input);
172 /* Too many hex quads. */
173 if (n_hex_quads >= ARRAY_LEN (hex_quads))
178 hex_quad = (hex_quad << 4) | hex_digit;
180 /* Hex quad must fit in 16 bits. */
181 if (n_hex_digits >= 4)
188 /* Save position of :: */
191 /* More than one :: ? */
192 if (double_colon_index < ARRAY_LEN (hex_quads))
194 double_colon_index = n_hex_quads;
197 if (n_colon > 0 && n_hex_digits > 0)
199 hex_quads[n_hex_quads++] = hex_quad;
205 if (n_hex_digits > 0)
206 hex_quads[n_hex_quads++] = hex_quad;
211 /* Expand :: to appropriate number of zero hex quads. */
212 if (double_colon_index < ARRAY_LEN (hex_quads))
214 word n_zero = ARRAY_LEN (hex_quads) - n_hex_quads;
216 for (i = n_hex_quads - 1; i >= (signed) double_colon_index; i--)
217 hex_quads[n_zero + i] = hex_quads[i];
219 for (i = 0; i < n_zero; i++)
220 hex_quads[double_colon_index + i] = 0;
222 n_hex_quads = ARRAY_LEN (hex_quads);
225 /* Too few hex quads given. */
226 if (n_hex_quads < ARRAY_LEN (hex_quads))
229 for (i = 0; i < ARRAY_LEN (hex_quads); i++)
230 result->as_u16[i] = clib_host_to_net_u16 (hex_quads[i]);
237 unformat_ipsec_policy_action (unformat_input_t * input, va_list * args)
240 u32 * r = va_arg (*args, u32 *);
243 #define _(v,f,s) else if (unformat (input, s)) *r = IPSEC_POLICY_ACTION_##f;
244 foreach_ipsec_policy_action
255 unformat_ipsec_crypto_alg (unformat_input_t * input, va_list * args)
258 u32 * r = va_arg (*args, u32 *);
261 #define _(v,f,s) else if (unformat (input, s)) *r = IPSEC_CRYPTO_ALG_##f;
262 foreach_ipsec_crypto_alg
273 format_ipsec_crypto_alg (u8 * s, va_list * args)
276 u32 i = va_arg (*args, u32);
281 #define _(v,f,str) case IPSEC_CRYPTO_ALG_##f: t = (u8 *) str; break;
282 foreach_ipsec_crypto_alg
285 return format (s, "unknown");
287 return format (s, "%s", t);
289 return format (s, "Unimplemented");
294 unformat_ipsec_integ_alg (unformat_input_t * input, va_list * args)
297 u32 * r = va_arg (*args, u32 *);
300 #define _(v,f,s) else if (unformat (input, s)) *r = IPSEC_INTEG_ALG_##f;
301 foreach_ipsec_integ_alg
312 format_ipsec_integ_alg (u8 * s, va_list * args)
315 u32 i = va_arg (*args, u32);
320 #define _(v,f,str) case IPSEC_INTEG_ALG_##f: t = (u8 *) str; break;
321 foreach_ipsec_integ_alg
324 return format (s, "unknown");
326 return format (s, "%s", t);
328 return format (s, "Unsupported");
333 unformat_ikev2_auth_method (unformat_input_t * input, va_list * args)
336 u32 * r = va_arg (*args, u32 *);
339 #define _(v,f,s) else if (unformat (input, s)) *r = IKEV2_AUTH_METHOD_##f;
340 foreach_ikev2_auth_method
351 unformat_ikev2_id_type (unformat_input_t * input, va_list * args)
354 u32 * r = va_arg (*args, u32 *);
357 #define _(v,f,s) else if (unformat (input, s)) *r = IKEV2_ID_TYPE_##f;
358 foreach_ikev2_id_type
369 unformat_policer_rate_type (unformat_input_t * input, va_list * args)
371 u8 * r = va_arg (*args, u8 *);
373 if (unformat (input, "kbps"))
374 *r = SSE2_QOS_RATE_KBPS;
375 else if (unformat(input, "pps"))
376 *r = SSE2_QOS_RATE_PPS;
383 unformat_policer_round_type (unformat_input_t * input, va_list * args)
385 u8 * r = va_arg (*args, u8 *);
387 if (unformat(input, "closest"))
388 *r = SSE2_QOS_ROUND_TO_CLOSEST;
389 else if (unformat (input, "up"))
390 *r = SSE2_QOS_ROUND_TO_UP;
391 else if (unformat (input, "down"))
392 *r = SSE2_QOS_ROUND_TO_DOWN;
399 unformat_policer_type (unformat_input_t * input, va_list * args)
401 u8 * r = va_arg (*args, u8 *);
403 if (unformat (input, "1r2c"))
404 *r = SSE2_QOS_POLICER_TYPE_1R2C;
405 else if (unformat (input, "1r3c"))
406 *r = SSE2_QOS_POLICER_TYPE_1R3C_RFC_2697;
407 else if (unformat (input, "2r3c-2698"))
408 *r = SSE2_QOS_POLICER_TYPE_2R3C_RFC_2698;
409 else if (unformat (input, "2r3c-4115"))
410 *r = SSE2_QOS_POLICER_TYPE_2R3C_RFC_4115;
411 else if (unformat (input, "2r3c-mef5cf1"))
412 *r = SSE2_QOS_POLICER_TYPE_2R3C_RFC_MEF5CF1;
418 u8 * format_ip4_address (u8 * s, va_list * args)
420 u8 * a = va_arg (*args, u8 *);
421 return format (s, "%d.%d.%d.%d", a[0], a[1], a[2], a[3]);
424 u8 * format_ip6_address (u8 * s, va_list * args)
426 ip6_address_t * a = va_arg (*args, ip6_address_t *);
427 u32 i, i_max_n_zero, max_n_zeros, i_first_zero, n_zeros, last_double_colon;
429 i_max_n_zero = ARRAY_LEN (a->as_u16);
431 i_first_zero = i_max_n_zero;
433 for (i = 0; i < ARRAY_LEN (a->as_u16); i++)
435 u32 is_zero = a->as_u16[i] == 0;
436 if (is_zero && i_first_zero >= ARRAY_LEN (a->as_u16))
442 if ((! is_zero && n_zeros > max_n_zeros)
443 || (i + 1 >= ARRAY_LEN (a->as_u16) && n_zeros > max_n_zeros))
445 i_max_n_zero = i_first_zero;
446 max_n_zeros = n_zeros;
447 i_first_zero = ARRAY_LEN (a->as_u16);
452 last_double_colon = 0;
453 for (i = 0; i < ARRAY_LEN (a->as_u16); i++)
455 if (i == i_max_n_zero && max_n_zeros > 1)
457 s = format (s, "::");
458 i += max_n_zeros - 1;
459 last_double_colon = 1;
463 s = format (s, "%s%x",
464 (last_double_colon || i == 0) ? "" : ":",
465 clib_net_to_host_u16 (a->as_u16[i]));
466 last_double_colon = 0;
473 /* Format an IP46 address. */
474 u8 * format_ip46_address (u8 * s, va_list * args)
476 ip46_address_t *ip46 = va_arg (*args, ip46_address_t *);
477 return ip46_address_is_ip4(ip46)?
478 format(s, "%U", format_ip4_address, &ip46->ip4):
479 format(s, "%U", format_ip6_address, &ip46->ip6);
482 u8 * format_ethernet_address (u8 * s, va_list * args)
484 u8 * a = va_arg (*args, u8 *);
486 return format (s, "%02x:%02x:%02x:%02x:%02x:%02x",
487 a[0], a[1], a[2], a[3], a[4], a[5]);
490 void increment_v4_address (ip4_address_t * a)
494 v = ntohl(a->as_u32) + 1;
495 a->as_u32 = ntohl(v);
498 void increment_v6_address (ip6_address_t * a)
502 v0 = clib_net_to_host_u64 (a->as_u64[0]);
503 v1 = clib_net_to_host_u64 (a->as_u64[1]);
508 a->as_u64[0] = clib_net_to_host_u64 (v0);
509 a->as_u64[1] = clib_net_to_host_u64 (v1);
513 static void vl_api_create_loopback_reply_t_handler
514 (vl_api_create_loopback_reply_t * mp)
516 vat_main_t * vam = &vat_main;
517 i32 retval = ntohl(mp->retval);
519 vam->retval = retval;
520 vam->result_ready = 1;
521 vam->regenerate_interface_table = 1;
524 static void vl_api_create_loopback_reply_t_handler_json
525 (vl_api_create_loopback_reply_t * mp)
527 vat_main_t * vam = &vat_main;
528 vat_json_node_t node;
530 vat_json_init_object(&node);
531 vat_json_object_add_int(&node, "retval", ntohl(mp->retval));
532 vat_json_object_add_uint(&node, "sw_if_index", ntohl(mp->sw_if_index));
534 vat_json_print(vam->ofp, &node);
535 vat_json_free(&node);
537 vam->retval = ntohl(mp->retval);
538 vam->result_ready = 1;
541 static void vl_api_create_vlan_subif_reply_t_handler
542 (vl_api_create_vlan_subif_reply_t * mp)
544 vat_main_t * vam = &vat_main;
545 i32 retval = ntohl(mp->retval);
547 vam->retval = retval;
548 vam->result_ready = 1;
549 vam->regenerate_interface_table = 1;
552 static void vl_api_create_vlan_subif_reply_t_handler_json
553 (vl_api_create_vlan_subif_reply_t * mp)
555 vat_main_t * vam = &vat_main;
556 vat_json_node_t node;
558 vat_json_init_object(&node);
559 vat_json_object_add_int(&node, "retval", ntohl(mp->retval));
560 vat_json_object_add_uint(&node, "sw_if_index", ntohl(mp->sw_if_index));
562 vat_json_print(vam->ofp, &node);
563 vat_json_free(&node);
565 vam->retval = ntohl(mp->retval);
566 vam->result_ready = 1;
569 static void vl_api_create_subif_reply_t_handler
570 (vl_api_create_subif_reply_t * mp)
572 vat_main_t * vam = &vat_main;
573 i32 retval = ntohl(mp->retval);
575 vam->retval = retval;
576 vam->result_ready = 1;
577 vam->regenerate_interface_table = 1;
580 static void vl_api_create_subif_reply_t_handler_json
581 (vl_api_create_subif_reply_t * mp)
583 vat_main_t * vam = &vat_main;
584 vat_json_node_t node;
586 vat_json_init_object(&node);
587 vat_json_object_add_int(&node, "retval", ntohl(mp->retval));
588 vat_json_object_add_uint(&node, "sw_if_index", ntohl(mp->sw_if_index));
590 vat_json_print(vam->ofp, &node);
591 vat_json_free(&node);
593 vam->retval = ntohl(mp->retval);
594 vam->result_ready = 1;
597 static void vl_api_interface_name_renumber_reply_t_handler
598 (vl_api_interface_name_renumber_reply_t * mp)
600 vat_main_t * vam = &vat_main;
601 i32 retval = ntohl(mp->retval);
603 vam->retval = retval;
604 vam->result_ready = 1;
605 vam->regenerate_interface_table = 1;
608 static void vl_api_interface_name_renumber_reply_t_handler_json
609 (vl_api_interface_name_renumber_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));
617 vat_json_print(vam->ofp, &node);
618 vat_json_free(&node);
620 vam->retval = ntohl(mp->retval);
621 vam->result_ready = 1;
625 * Special-case: build the interface table, maintain
626 * the next loopback sw_if_index vbl.
628 static void vl_api_sw_interface_details_t_handler
629 (vl_api_sw_interface_details_t * mp)
631 vat_main_t * vam = &vat_main;
632 u8 * s = format (0, "%s%c", mp->interface_name, 0);
634 hash_set_mem (vam->sw_if_index_by_interface_name, s,
635 ntohl(mp->sw_if_index));
637 /* In sub interface case, fill the sub interface table entry */
638 if (mp->sw_if_index != mp->sup_sw_if_index) {
639 sw_interface_subif_t * sub = NULL;
641 vec_add2(vam->sw_if_subif_table, sub, 1);
643 vec_validate(sub->interface_name, strlen((char *)s) + 1);
644 strncpy((char *)sub->interface_name, (char *)s,
645 vec_len(sub->interface_name));
646 sub->sw_if_index = ntohl(mp->sw_if_index);
647 sub->sub_id = ntohl(mp->sub_id);
649 sub->sub_dot1ad = mp->sub_dot1ad;
650 sub->sub_number_of_tags = mp->sub_number_of_tags;
651 sub->sub_outer_vlan_id = ntohs(mp->sub_outer_vlan_id);
652 sub->sub_inner_vlan_id = ntohs(mp->sub_inner_vlan_id);
653 sub->sub_exact_match = mp->sub_exact_match;
654 sub->sub_default = mp->sub_default;
655 sub->sub_outer_vlan_id_any = mp->sub_outer_vlan_id_any;
656 sub->sub_inner_vlan_id_any = mp->sub_inner_vlan_id_any;
658 /* vlan tag rewrite */
659 sub->vtr_op = ntohl(mp->vtr_op);
660 sub->vtr_push_dot1q = ntohl(mp->vtr_push_dot1q);
661 sub->vtr_tag1 = ntohl(mp->vtr_tag1);
662 sub->vtr_tag2 = ntohl(mp->vtr_tag2);
666 static void vl_api_sw_interface_details_t_handler_json
667 (vl_api_sw_interface_details_t * mp)
669 vat_main_t * vam = &vat_main;
670 vat_json_node_t *node = NULL;
672 if (VAT_JSON_ARRAY != vam->json_tree.type) {
673 ASSERT(VAT_JSON_NONE == vam->json_tree.type);
674 vat_json_init_array(&vam->json_tree);
676 node = vat_json_array_add(&vam->json_tree);
678 vat_json_init_object(node);
679 vat_json_object_add_uint(node, "sw_if_index", ntohl(mp->sw_if_index));
680 vat_json_object_add_uint(node, "sup_sw_if_index", ntohl(mp->sup_sw_if_index));
681 vat_json_object_add_uint(node, "l2_address_length", ntohl(mp->l2_address_length));
682 vat_json_object_add_bytes(node, "l2_address", mp->l2_address, sizeof(mp->l2_address));
683 vat_json_object_add_string_copy(node, "interface_name", mp->interface_name);
684 vat_json_object_add_uint(node, "admin_up_down", mp->admin_up_down);
685 vat_json_object_add_uint(node, "link_up_down", mp->link_up_down);
686 vat_json_object_add_uint(node, "link_duplex", mp->link_duplex);
687 vat_json_object_add_uint(node, "link_speed", mp->link_speed);
688 vat_json_object_add_uint(node, "mtu", ntohs(mp->link_mtu));
689 vat_json_object_add_uint(node, "sub_id", ntohl(mp->sub_id));
690 vat_json_object_add_uint(node, "sub_dot1ad", mp->sub_dot1ad);
691 vat_json_object_add_uint(node, "sub_number_of_tags", mp->sub_number_of_tags);
692 vat_json_object_add_uint(node, "sub_outer_vlan_id", ntohs(mp->sub_outer_vlan_id));
693 vat_json_object_add_uint(node, "sub_inner_vlan_id", ntohs(mp->sub_inner_vlan_id));
694 vat_json_object_add_uint(node, "sub_exact_match", mp->sub_exact_match);
695 vat_json_object_add_uint(node, "sub_default", mp->sub_default);
696 vat_json_object_add_uint(node, "sub_outer_vlan_id_any", mp->sub_outer_vlan_id_any);
697 vat_json_object_add_uint(node, "sub_inner_vlan_id_any", mp->sub_inner_vlan_id_any);
698 vat_json_object_add_uint(node, "vtr_op", ntohl(mp->vtr_op));
699 vat_json_object_add_uint(node, "vtr_push_dot1q", ntohl(mp->vtr_push_dot1q));
700 vat_json_object_add_uint(node, "vtr_tag1", ntohl(mp->vtr_tag1));
701 vat_json_object_add_uint(node, "vtr_tag2", ntohl(mp->vtr_tag2));
704 static void vl_api_sw_interface_set_flags_t_handler
705 (vl_api_sw_interface_set_flags_t * mp)
707 vat_main_t * vam = &vat_main;
708 if (vam->interface_event_display)
709 errmsg ("interface flags: sw_if_index %d %s %s\n",
710 ntohl(mp->sw_if_index),
711 mp->admin_up_down ? "admin-up" : "admin-down",
712 mp->link_up_down ? "link-up" : "link-down");
715 static void vl_api_sw_interface_set_flags_t_handler_json
716 (vl_api_sw_interface_set_flags_t * mp)
718 /* JSON output not supported */
721 static void vl_api_cli_reply_t_handler
722 (vl_api_cli_reply_t * mp)
724 vat_main_t * vam = &vat_main;
725 i32 retval = ntohl(mp->retval);
727 vam->retval = retval;
728 vam->shmem_result = (u8 *) mp->reply_in_shmem;
729 vam->result_ready = 1;
732 static void vl_api_cli_reply_t_handler_json
733 (vl_api_cli_reply_t * mp)
735 vat_main_t * vam = &vat_main;
736 vat_json_node_t node;
737 api_main_t * am = &api_main;
741 vat_json_init_object(&node);
742 vat_json_object_add_int(&node, "retval", ntohl(mp->retval));
743 vat_json_object_add_uint(&node, "reply_in_shmem",
744 ntohl(mp->reply_in_shmem));
745 /* Toss the shared-memory original... */
746 pthread_mutex_lock (&am->vlib_rp->mutex);
747 oldheap = svm_push_data_heap (am->vlib_rp);
749 reply = (u8 *)(mp->reply_in_shmem);
752 svm_pop_heap (oldheap);
753 pthread_mutex_unlock (&am->vlib_rp->mutex);
755 vat_json_print(vam->ofp, &node);
756 vat_json_free(&node);
758 vam->retval = ntohl(mp->retval);
759 vam->result_ready = 1;
762 static void vl_api_classify_add_del_table_reply_t_handler
763 (vl_api_classify_add_del_table_reply_t * mp)
765 vat_main_t * vam = &vat_main;
766 i32 retval = ntohl(mp->retval);
767 if (vam->async_mode) {
768 vam->async_errors += (retval < 0);
770 vam->retval = retval;
771 vam->result_ready = 1;
773 ((mp->new_table_index != 0xFFFFFFFF) ||
774 (mp->skip_n_vectors != 0xFFFFFFFF) ||
775 (mp->match_n_vectors != 0xFFFFFFFF)))
777 * Note: this is just barely thread-safe, depends on
778 * the main thread spinning waiting for an answer...
780 errmsg ("new index %d, skip_n_vectors %d, match_n_vectors %d\n",
781 ntohl(mp->new_table_index),
782 ntohl(mp->skip_n_vectors), ntohl(mp->match_n_vectors));
786 static void vl_api_classify_add_del_table_reply_t_handler_json
787 (vl_api_classify_add_del_table_reply_t * mp)
789 vat_main_t * vam = &vat_main;
790 vat_json_node_t node;
792 vat_json_init_object(&node);
793 vat_json_object_add_int(&node, "retval", ntohl(mp->retval));
794 vat_json_object_add_uint(&node, "new_table_index", ntohl(mp->new_table_index));
795 vat_json_object_add_uint(&node, "skip_n_vectors", ntohl(mp->skip_n_vectors));
796 vat_json_object_add_uint(&node, "match_n_vectors", ntohl(mp->match_n_vectors));
798 vat_json_print(vam->ofp, &node);
799 vat_json_free(&node);
801 vam->retval = ntohl(mp->retval);
802 vam->result_ready = 1;
805 static void vl_api_get_node_index_reply_t_handler
806 (vl_api_get_node_index_reply_t * mp)
808 vat_main_t * vam = &vat_main;
809 i32 retval = ntohl(mp->retval);
810 if (vam->async_mode) {
811 vam->async_errors += (retval < 0);
813 vam->retval = retval;
814 vam->result_ready = 1;
816 errmsg ("node index %d\n", ntohl(mp->node_index));
820 static void vl_api_get_node_index_reply_t_handler_json
821 (vl_api_get_node_index_reply_t * mp)
823 vat_main_t * vam = &vat_main;
824 vat_json_node_t node;
826 vat_json_init_object(&node);
827 vat_json_object_add_int(&node, "retval", ntohl(mp->retval));
828 vat_json_object_add_uint(&node, "node_index", ntohl(mp->node_index));
830 vat_json_print(vam->ofp, &node);
831 vat_json_free(&node);
833 vam->retval = ntohl(mp->retval);
834 vam->result_ready = 1;
837 static void vl_api_add_node_next_reply_t_handler
838 (vl_api_add_node_next_reply_t * mp)
840 vat_main_t * vam = &vat_main;
841 i32 retval = ntohl(mp->retval);
842 if (vam->async_mode) {
843 vam->async_errors += (retval < 0);
845 vam->retval = retval;
846 vam->result_ready = 1;
848 errmsg ("next index %d\n", ntohl(mp->next_index));
852 static void vl_api_add_node_next_reply_t_handler_json
853 (vl_api_add_node_next_reply_t * mp)
855 vat_main_t * vam = &vat_main;
856 vat_json_node_t node;
858 vat_json_init_object(&node);
859 vat_json_object_add_int(&node, "retval", ntohl(mp->retval));
860 vat_json_object_add_uint(&node, "next_index", ntohl(mp->next_index));
862 vat_json_print(vam->ofp, &node);
863 vat_json_free(&node);
865 vam->retval = ntohl(mp->retval);
866 vam->result_ready = 1;
869 static void vl_api_mpls_gre_add_del_tunnel_reply_t_handler
870 (vl_api_mpls_gre_add_del_tunnel_reply_t * mp)
872 vat_main_t * vam = &vat_main;
873 i32 retval = ntohl(mp->retval);
874 u32 sw_if_index = ntohl(mp->tunnel_sw_if_index);
876 if (retval >= 0 && sw_if_index != (u32)~0) {
877 errmsg ("tunnel_sw_if_index %d\n", sw_if_index);
879 vam->retval = retval;
880 vam->result_ready = 1;
883 static void vl_api_mpls_gre_add_del_tunnel_reply_t_handler_json
884 (vl_api_mpls_gre_add_del_tunnel_reply_t * mp)
886 vat_main_t * vam = &vat_main;
887 vat_json_node_t node;
889 vat_json_init_object(&node);
890 vat_json_object_add_int(&node, "retval", ntohl(mp->retval));
891 vat_json_object_add_uint(&node, "tunnel_sw_if_index", ntohl(mp->tunnel_sw_if_index));
893 vat_json_print(vam->ofp, &node);
894 vat_json_free(&node);
896 vam->retval = ntohl(mp->retval);
897 vam->result_ready = 1;
901 static void vl_api_show_version_reply_t_handler
902 (vl_api_show_version_reply_t * mp)
904 vat_main_t * vam = &vat_main;
905 i32 retval = ntohl(mp->retval);
908 errmsg (" program: %s\n", mp->program);
909 errmsg (" version: %s\n", mp->version);
910 errmsg (" build date: %s\n", mp->build_date);
911 errmsg ("build directory: %s\n", mp->build_directory);
913 vam->retval = retval;
914 vam->result_ready = 1;
917 static void vl_api_show_version_reply_t_handler_json
918 (vl_api_show_version_reply_t * mp)
920 vat_main_t * vam = &vat_main;
921 vat_json_node_t node;
923 vat_json_init_object(&node);
924 vat_json_object_add_int(&node, "retval", ntohl(mp->retval));
925 vat_json_object_add_string_copy(&node, "program", mp->program);
926 vat_json_object_add_string_copy(&node, "version", mp->version);
927 vat_json_object_add_string_copy(&node, "build_date", mp->build_date);
928 vat_json_object_add_string_copy(&node, "build_directory", mp->build_directory);
930 vat_json_print(vam->ofp, &node);
931 vat_json_free(&node);
933 vam->retval = ntohl(mp->retval);
934 vam->result_ready = 1;
937 static void vl_api_ip4_arp_event_t_handler
938 (vl_api_ip4_arp_event_t * mp)
940 vat_main_t * vam = &vat_main;
941 errmsg ("arp event: address %U new mac %U sw_if_index %d\n",
942 format_ip4_address, &mp->address,
943 format_ethernet_address, mp->new_mac, mp->sw_if_index);
946 static void vl_api_ip4_arp_event_t_handler_json
947 (vl_api_ip4_arp_event_t * mp)
949 /* JSON output not supported */
953 * Special-case: build the bridge domain table, maintain
954 * the next bd id vbl.
956 static void vl_api_bridge_domain_details_t_handler
957 (vl_api_bridge_domain_details_t * mp)
959 vat_main_t * vam = &vat_main;
960 u32 n_sw_ifs = ntohl (mp->n_sw_ifs);
962 fformat (vam->ofp, "\n%-3s %-3s %-3s %-3s %-3s %-3s\n",
963 " ID", "LRN", "FWD", "FLD", "BVI", "#IF");
965 fformat (vam->ofp, "%3d %3d %3d %3d %3d %3d\n",
966 ntohl (mp->bd_id), mp->learn, mp->forward,
967 mp->flood, ntohl (mp->bvi_sw_if_index), n_sw_ifs);
970 fformat (vam->ofp, "\n\n%s %s %s\n", "sw_if_index", "SHG",
974 static void vl_api_bridge_domain_details_t_handler_json
975 (vl_api_bridge_domain_details_t * mp)
977 vat_main_t * vam = &vat_main;
978 vat_json_node_t *node, *array = NULL;
980 if (VAT_JSON_ARRAY != vam->json_tree.type) {
981 ASSERT(VAT_JSON_NONE == vam->json_tree.type);
982 vat_json_init_array(&vam->json_tree);
984 node = vat_json_array_add(&vam->json_tree);
986 vat_json_init_object(node);
987 vat_json_object_add_uint(node, "bd_id", ntohl(mp->bd_id));
988 vat_json_object_add_uint(node, "flood", mp->flood);
989 vat_json_object_add_uint(node, "forward", mp->forward);
990 vat_json_object_add_uint(node, "learn", mp->learn);
991 vat_json_object_add_uint(node, "bvi_sw_if_index", ntohl(mp->bvi_sw_if_index));
992 vat_json_object_add_uint(node, "n_sw_ifs", ntohl(mp->n_sw_ifs));
993 array = vat_json_object_add(node, "sw_if");
994 vat_json_init_array(array);
998 * Special-case: build the bridge domain sw if table.
1000 static void vl_api_bridge_domain_sw_if_details_t_handler
1001 (vl_api_bridge_domain_sw_if_details_t * mp)
1003 vat_main_t * vam = &vat_main;
1005 u8 * sw_if_name = 0;
1008 sw_if_index = ntohl (mp->sw_if_index);
1009 hash_foreach_pair (p, vam->sw_if_index_by_interface_name,
1011 if ((u32) p->value[0] == sw_if_index) {
1012 sw_if_name = (u8 *)(p->key);
1017 fformat (vam->ofp, "%7d %3d %s", sw_if_index,
1018 mp->shg, sw_if_name ? (char *)sw_if_name :
1019 "sw_if_index not found!");
1022 static void vl_api_bridge_domain_sw_if_details_t_handler_json
1023 (vl_api_bridge_domain_sw_if_details_t * mp)
1025 vat_main_t * vam = &vat_main;
1026 vat_json_node_t *node = NULL;
1027 uword last_index = 0;
1029 ASSERT(VAT_JSON_ARRAY == vam->json_tree.type);
1030 ASSERT(vec_len(vam->json_tree.array) >= 1);
1031 last_index = vec_len(vam->json_tree.array) - 1;
1032 node = &vam->json_tree.array[last_index];
1033 node = vat_json_object_get_element(node, "sw_if");
1034 ASSERT(NULL != node);
1035 node = vat_json_array_add(node);
1037 vat_json_init_object(node);
1038 vat_json_object_add_uint(node, "bd_id", ntohl(mp->bd_id));
1039 vat_json_object_add_uint(node, "sw_if_index", ntohl(mp->sw_if_index));
1040 vat_json_object_add_uint(node, "shg", mp->shg);
1043 static void vl_api_control_ping_reply_t_handler
1044 (vl_api_control_ping_reply_t * mp)
1046 vat_main_t * vam = &vat_main;
1047 i32 retval = ntohl(mp->retval);
1048 if (vam->async_mode) {
1049 vam->async_errors += (retval < 0);
1051 vam->retval = retval;
1052 vam->result_ready = 1;
1056 static void vl_api_control_ping_reply_t_handler_json
1057 (vl_api_control_ping_reply_t * mp)
1059 vat_main_t * vam = &vat_main;
1060 i32 retval = ntohl(mp->retval);
1062 if (VAT_JSON_NONE != vam->json_tree.type) {
1063 vat_json_print(vam->ofp, &vam->json_tree);
1064 vat_json_free(&vam->json_tree);
1065 vam->json_tree.type = VAT_JSON_NONE;
1068 vat_json_init_array(&vam->json_tree);
1069 vat_json_print(vam->ofp, &vam->json_tree);
1070 vam->json_tree.type = VAT_JSON_NONE;
1073 vam->retval = retval;
1074 vam->result_ready = 1;
1077 static void vl_api_l2_flags_reply_t_handler
1078 (vl_api_l2_flags_reply_t * mp)
1080 vat_main_t * vam = &vat_main;
1081 i32 retval = ntohl(mp->retval);
1082 if (vam->async_mode) {
1083 vam->async_errors += (retval < 0);
1085 vam->retval = retval;
1086 vam->result_ready = 1;
1090 static void vl_api_l2_flags_reply_t_handler_json
1091 (vl_api_l2_flags_reply_t * mp)
1093 vat_main_t * vam = &vat_main;
1094 vat_json_node_t node;
1096 vat_json_init_object(&node);
1097 vat_json_object_add_int(&node, "retval", ntohl(mp->retval));
1098 vat_json_object_add_uint(&node, "resulting_feature_bitmap", ntohl(mp->resulting_feature_bitmap));
1100 vat_json_print(vam->ofp, &node);
1101 vat_json_free(&node);
1103 vam->retval = ntohl(mp->retval);
1104 vam->result_ready = 1;
1107 static void vl_api_bridge_flags_reply_t_handler
1108 (vl_api_bridge_flags_reply_t * mp)
1110 vat_main_t * vam = &vat_main;
1111 i32 retval = ntohl(mp->retval);
1112 if (vam->async_mode) {
1113 vam->async_errors += (retval < 0);
1115 vam->retval = retval;
1116 vam->result_ready = 1;
1120 static void vl_api_bridge_flags_reply_t_handler_json
1121 (vl_api_bridge_flags_reply_t * mp)
1123 vat_main_t * vam = &vat_main;
1124 vat_json_node_t node;
1126 vat_json_init_object(&node);
1127 vat_json_object_add_int(&node, "retval", ntohl(mp->retval));
1128 vat_json_object_add_uint(&node, "resulting_feature_bitmap", ntohl(mp->resulting_feature_bitmap));
1130 vat_json_print(vam->ofp, &node);
1131 vat_json_free(&node);
1133 vam->retval = ntohl(mp->retval);
1134 vam->result_ready = 1;
1137 static void vl_api_tap_connect_reply_t_handler
1138 (vl_api_tap_connect_reply_t * mp)
1140 vat_main_t * vam = &vat_main;
1141 i32 retval = ntohl(mp->retval);
1142 if (vam->async_mode) {
1143 vam->async_errors += (retval < 0);
1145 vam->retval = retval;
1146 vam->result_ready = 1;
1150 static void vl_api_tap_connect_reply_t_handler_json
1151 (vl_api_tap_connect_reply_t * mp)
1153 vat_main_t * vam = &vat_main;
1154 vat_json_node_t node;
1156 vat_json_init_object(&node);
1157 vat_json_object_add_int(&node, "retval", ntohl(mp->retval));
1158 vat_json_object_add_uint(&node, "sw_if_index", ntohl(mp->sw_if_index));
1160 vat_json_print(vam->ofp, &node);
1161 vat_json_free(&node);
1163 vam->retval = ntohl(mp->retval);
1164 vam->result_ready = 1;
1167 static void vl_api_tap_modify_reply_t_handler
1168 (vl_api_tap_modify_reply_t * mp)
1170 vat_main_t * vam = &vat_main;
1171 i32 retval = ntohl(mp->retval);
1172 if (vam->async_mode) {
1173 vam->async_errors += (retval < 0);
1175 vam->retval = retval;
1176 vam->result_ready = 1;
1180 static void vl_api_tap_modify_reply_t_handler_json
1181 (vl_api_tap_modify_reply_t * mp)
1183 vat_main_t * vam = &vat_main;
1184 vat_json_node_t node;
1186 vat_json_init_object(&node);
1187 vat_json_object_add_int(&node, "retval", ntohl(mp->retval));
1188 vat_json_object_add_uint(&node, "sw_if_index", ntohl(mp->sw_if_index));
1190 vat_json_print(vam->ofp, &node);
1191 vat_json_free(&node);
1193 vam->retval = ntohl(mp->retval);
1194 vam->result_ready = 1;
1197 static void vl_api_tap_delete_reply_t_handler
1198 (vl_api_tap_delete_reply_t * mp)
1200 vat_main_t * vam = &vat_main;
1201 i32 retval = ntohl(mp->retval);
1202 if (vam->async_mode) {
1203 vam->async_errors += (retval < 0);
1205 vam->retval = retval;
1206 vam->result_ready = 1;
1210 static void vl_api_tap_delete_reply_t_handler_json
1211 (vl_api_tap_delete_reply_t * mp)
1213 vat_main_t * vam = &vat_main;
1214 vat_json_node_t node;
1216 vat_json_init_object(&node);
1217 vat_json_object_add_int(&node, "retval", ntohl(mp->retval));
1219 vat_json_print(vam->ofp, &node);
1220 vat_json_free(&node);
1222 vam->retval = ntohl(mp->retval);
1223 vam->result_ready = 1;
1226 static void vl_api_mpls_ethernet_add_del_tunnel_reply_t_handler
1227 (vl_api_mpls_ethernet_add_del_tunnel_reply_t * mp)
1229 vat_main_t * vam = &vat_main;
1230 i32 retval = ntohl(mp->retval);
1231 if (vam->async_mode) {
1232 vam->async_errors += (retval < 0);
1234 vam->retval = retval;
1235 vam->result_ready = 1;
1239 static void vl_api_mpls_ethernet_add_del_tunnel_reply_t_handler_json
1240 (vl_api_mpls_ethernet_add_del_tunnel_reply_t * mp)
1242 vat_main_t * vam = &vat_main;
1243 vat_json_node_t node;
1245 vat_json_init_object(&node);
1246 vat_json_object_add_int(&node, "retval", ntohl(mp->retval));
1247 vat_json_object_add_uint(&node, "tunnel_sw_if_index", ntohl(mp->tunnel_sw_if_index));
1249 vat_json_print(vam->ofp, &node);
1250 vat_json_free(&node);
1252 vam->retval = ntohl(mp->retval);
1253 vam->result_ready = 1;
1256 static void vl_api_l2tpv3_create_tunnel_reply_t_handler
1257 (vl_api_l2tpv3_create_tunnel_reply_t * mp)
1259 vat_main_t * vam = &vat_main;
1260 i32 retval = ntohl(mp->retval);
1261 if (vam->async_mode) {
1262 vam->async_errors += (retval < 0);
1264 vam->retval = retval;
1265 vam->result_ready = 1;
1269 static void vl_api_l2tpv3_create_tunnel_reply_t_handler_json
1270 (vl_api_l2tpv3_create_tunnel_reply_t * mp)
1272 vat_main_t * vam = &vat_main;
1273 vat_json_node_t node;
1275 vat_json_init_object(&node);
1276 vat_json_object_add_int(&node, "retval", ntohl(mp->retval));
1277 vat_json_object_add_uint(&node, "sw_if_index", ntohl(mp->sw_if_index));
1279 vat_json_print(vam->ofp, &node);
1280 vat_json_free(&node);
1282 vam->retval = ntohl(mp->retval);
1283 vam->result_ready = 1;
1286 static void vl_api_vxlan_add_del_tunnel_reply_t_handler
1287 (vl_api_vxlan_add_del_tunnel_reply_t * mp)
1289 vat_main_t * vam = &vat_main;
1290 i32 retval = ntohl(mp->retval);
1291 if (vam->async_mode) {
1292 vam->async_errors += (retval < 0);
1294 vam->retval = retval;
1295 vam->result_ready = 1;
1299 static void vl_api_vxlan_add_del_tunnel_reply_t_handler_json
1300 (vl_api_vxlan_add_del_tunnel_reply_t * mp)
1302 vat_main_t * vam = &vat_main;
1303 vat_json_node_t node;
1305 vat_json_init_object(&node);
1306 vat_json_object_add_int(&node, "retval", ntohl(mp->retval));
1307 vat_json_object_add_uint(&node, "sw_if_index", ntohl(mp->sw_if_index));
1309 vat_json_print(vam->ofp, &node);
1310 vat_json_free(&node);
1312 vam->retval = ntohl(mp->retval);
1313 vam->result_ready = 1;
1316 static void vl_api_gre_add_del_tunnel_reply_t_handler
1317 (vl_api_gre_add_del_tunnel_reply_t * mp)
1319 vat_main_t * vam = &vat_main;
1320 i32 retval = ntohl(mp->retval);
1321 if (vam->async_mode) {
1322 vam->async_errors += (retval < 0);
1324 vam->retval = retval;
1325 vam->result_ready = 1;
1329 static void vl_api_gre_add_del_tunnel_reply_t_handler_json
1330 (vl_api_gre_add_del_tunnel_reply_t * mp)
1332 vat_main_t * vam = &vat_main;
1333 vat_json_node_t node;
1335 vat_json_init_object(&node);
1336 vat_json_object_add_int(&node, "retval", ntohl(mp->retval));
1337 vat_json_object_add_uint(&node, "sw_if_index", ntohl(mp->sw_if_index));
1339 vat_json_print(vam->ofp, &node);
1340 vat_json_free(&node);
1342 vam->retval = ntohl(mp->retval);
1343 vam->result_ready = 1;
1346 static void vl_api_create_vhost_user_if_reply_t_handler
1347 (vl_api_create_vhost_user_if_reply_t * mp)
1349 vat_main_t * vam = &vat_main;
1350 i32 retval = ntohl(mp->retval);
1351 if (vam->async_mode) {
1352 vam->async_errors += (retval < 0);
1354 vam->retval = retval;
1355 vam->result_ready = 1;
1359 static void vl_api_create_vhost_user_if_reply_t_handler_json
1360 (vl_api_create_vhost_user_if_reply_t * mp)
1362 vat_main_t * vam = &vat_main;
1363 vat_json_node_t node;
1365 vat_json_init_object(&node);
1366 vat_json_object_add_int(&node, "retval", ntohl(mp->retval));
1367 vat_json_object_add_uint(&node, "sw_if_index", ntohl(mp->sw_if_index));
1369 vat_json_print(vam->ofp, &node);
1370 vat_json_free(&node);
1372 vam->retval = ntohl(mp->retval);
1373 vam->result_ready = 1;
1376 static void vl_api_ip_address_details_t_handler
1377 (vl_api_ip_address_details_t * mp)
1379 vat_main_t * vam = &vat_main;
1380 static ip_address_details_t empty_ip_address_details = {{0}};
1381 ip_address_details_t * address = NULL;
1382 ip_details_t * current_ip_details = NULL;
1383 ip_details_t * details = NULL;
1385 details = vam->ip_details_by_sw_if_index[vam->is_ipv6];
1387 if (!details || vam->current_sw_if_index >= vec_len(details)
1388 || !details[vam->current_sw_if_index].present) {
1389 errmsg ("ip address details arrived but not stored\n");
1390 errmsg ("ip_dump should be called first\n");
1394 current_ip_details = vec_elt_at_index(details,
1395 vam->current_sw_if_index);
1397 #define addresses (current_ip_details->addr)
1399 vec_validate_init_empty(addresses, vec_len(addresses),
1400 empty_ip_address_details);
1402 address = vec_elt_at_index(addresses, vec_len(addresses) - 1);
1404 clib_memcpy(&address->ip, &mp->ip, sizeof(address->ip));
1405 address->prefix_length = mp->prefix_length;
1409 static void vl_api_ip_address_details_t_handler_json
1410 (vl_api_ip_address_details_t * mp)
1412 vat_main_t * vam = &vat_main;
1413 vat_json_node_t *node = NULL;
1414 struct in6_addr ip6;
1417 if (VAT_JSON_ARRAY != vam->json_tree.type) {
1418 ASSERT(VAT_JSON_NONE == vam->json_tree.type);
1419 vat_json_init_array(&vam->json_tree);
1421 node = vat_json_array_add(&vam->json_tree);
1423 vat_json_init_object(node);
1425 clib_memcpy(&ip6, mp->ip, sizeof(ip6));
1426 vat_json_object_add_ip6(node, "ip", ip6);
1428 clib_memcpy(&ip4, mp->ip, sizeof(ip4));
1429 vat_json_object_add_ip4(node, "ip", ip4);
1431 vat_json_object_add_uint(node, "prefix_length", mp->prefix_length);
1434 static void vl_api_ip_details_t_handler (vl_api_ip_details_t * mp)
1436 vat_main_t * vam = &vat_main;
1437 static ip_details_t empty_ip_details = {0};
1438 ip_details_t * ip = NULL;
1439 u32 sw_if_index = ~0;
1441 sw_if_index = ntohl(mp->sw_if_index);
1443 vec_validate_init_empty(vam->ip_details_by_sw_if_index[vam->is_ipv6],
1444 sw_if_index, empty_ip_details);
1446 ip = vec_elt_at_index(vam->ip_details_by_sw_if_index[vam->is_ipv6],
1452 static void vl_api_ip_details_t_handler_json (vl_api_ip_details_t * mp)
1454 vat_main_t * vam = &vat_main;
1456 if (VAT_JSON_ARRAY != vam->json_tree.type) {
1457 ASSERT(VAT_JSON_NONE == vam->json_tree.type);
1458 vat_json_init_array(&vam->json_tree);
1460 vat_json_array_add_uint(&vam->json_tree, clib_net_to_host_u32(mp->sw_if_index));
1463 static void vl_api_map_domain_details_t_handler_json
1464 (vl_api_map_domain_details_t * mp)
1466 vat_json_node_t * node = NULL;
1467 vat_main_t * vam = &vat_main;
1468 struct in6_addr ip6;
1471 if (VAT_JSON_ARRAY != vam->json_tree.type) {
1472 ASSERT(VAT_JSON_NONE == vam->json_tree.type);
1473 vat_json_init_array(&vam->json_tree);
1476 node = vat_json_array_add(&vam->json_tree);
1477 vat_json_init_object(node);
1479 vat_json_object_add_uint(node, "domain_index", clib_net_to_host_u32(mp->domain_index));
1480 clib_memcpy(&ip6, mp->ip6_prefix, sizeof(ip6));
1481 vat_json_object_add_ip6(node, "ip6_prefix", ip6);
1482 clib_memcpy(&ip4, mp->ip4_prefix, sizeof(ip4));
1483 vat_json_object_add_ip4(node, "ip4_prefix", ip4);
1484 clib_memcpy(&ip6, mp->ip6_src, sizeof(ip6));
1485 vat_json_object_add_ip6(node, "ip6_src", ip6);
1486 vat_json_object_add_int(node, "ip6_prefix_len", mp->ip6_prefix_len);
1487 vat_json_object_add_int(node, "ip4_prefix_len", mp->ip4_prefix_len);
1488 vat_json_object_add_int(node, "ip6_src_len", mp->ip6_src_len);
1489 vat_json_object_add_int(node, "ea_bits_len", mp->ea_bits_len);
1490 vat_json_object_add_int(node, "psid_offset", mp->psid_offset);
1491 vat_json_object_add_int(node, "psid_length", mp->psid_length);
1492 vat_json_object_add_uint(node, "flags", mp->flags);
1493 vat_json_object_add_uint(node, "mtu", clib_net_to_host_u16(mp->mtu));
1494 vat_json_object_add_int(node, "is_translation", mp->is_translation);
1497 static void vl_api_map_domain_details_t_handler
1498 (vl_api_map_domain_details_t * mp)
1500 vat_main_t * vam = &vat_main;
1502 if (mp->is_translation) {
1503 fformat(vam->ofp, "* %U/%d (ipv4-prefix) %U/%d (ipv6-prefix) %U/%d (ip6-src) index: %u\n",
1504 format_ip4_address, mp->ip4_prefix, mp->ip4_prefix_len,
1505 format_ip6_address, mp->ip6_prefix, mp->ip6_prefix_len,
1506 format_ip6_address, mp->ip6_src, mp->ip6_src_len, clib_net_to_host_u32(mp->domain_index));
1508 fformat(vam->ofp, "* %U/%d (ipv4-prefix) %U/%d (ipv6-prefix) %U (ip6-src) index: %u\n",
1509 format_ip4_address, mp->ip4_prefix, mp->ip4_prefix_len,
1510 format_ip6_address, mp->ip6_prefix, mp->ip6_prefix_len,
1511 format_ip6_address, mp->ip6_src, clib_net_to_host_u32(mp->domain_index));
1513 fformat(vam->ofp, " ea-len %d psid-offset %d psid-len %d mtu %d %s\n",
1514 mp->ea_bits_len, mp->psid_offset, mp->psid_length, mp->mtu, mp->is_translation? "map-t":"");
1517 static void vl_api_map_rule_details_t_handler_json
1518 (vl_api_map_rule_details_t * mp)
1520 struct in6_addr ip6;
1521 vat_json_node_t * node = NULL;
1522 vat_main_t * vam = &vat_main;
1524 if (VAT_JSON_ARRAY != vam->json_tree.type) {
1525 ASSERT(VAT_JSON_NONE == vam->json_tree.type);
1526 vat_json_init_array(&vam->json_tree);
1529 node = vat_json_array_add(&vam->json_tree);
1530 vat_json_init_object(node);
1532 vat_json_object_add_uint(node, "psid", clib_net_to_host_u16(mp->psid));
1533 clib_memcpy(&ip6, mp->ip6_dst, sizeof(ip6));
1534 vat_json_object_add_ip6(node, "ip6_dst", ip6);
1537 static void vl_api_map_rule_details_t_handler
1538 (vl_api_map_rule_details_t * mp)
1540 vat_main_t * vam = &vat_main;
1541 fformat(vam->ofp, " %d (psid) %U (ip6-dst)\n", clib_net_to_host_u16(mp->psid),
1542 format_ip6_address, mp->ip6_dst);
1545 static void vl_api_dhcp_compl_event_t_handler
1546 (vl_api_dhcp_compl_event_t * mp)
1548 vat_main_t * vam = &vat_main;
1549 errmsg ("DHCP compl event: pid %d %s hostname %s host_addr %U "
1550 "router_addr %U host_mac %U\n",
1551 mp->pid, mp->is_ipv6 ? "ipv6":"ipv4", mp->hostname,
1552 format_ip4_address, &mp->host_address,
1553 format_ip4_address, &mp->router_address,
1554 format_ethernet_address, mp->host_mac);
1557 static void vl_api_dhcp_compl_event_t_handler_json
1558 (vl_api_dhcp_compl_event_t * mp)
1560 /* JSON output not supported */
1563 static void set_simple_interface_counter (u8 vnet_counter_type, u32 sw_if_index,
1566 vat_main_t * vam = &vat_main;
1567 static u64 default_counter = 0;
1569 vec_validate_init_empty(vam->simple_interface_counters, vnet_counter_type, NULL);
1570 vec_validate_init_empty(vam->simple_interface_counters[vnet_counter_type],
1571 sw_if_index, default_counter);
1572 vam->simple_interface_counters[vnet_counter_type][sw_if_index] = counter;
1575 static void set_combined_interface_counter (u8 vnet_counter_type, u32 sw_if_index,
1576 interface_counter_t counter)
1578 vat_main_t * vam = &vat_main;
1579 static interface_counter_t default_counter = {0, };
1581 vec_validate_init_empty(vam->combined_interface_counters, vnet_counter_type, NULL);
1582 vec_validate_init_empty(vam->combined_interface_counters[vnet_counter_type],
1583 sw_if_index, default_counter);
1584 vam->combined_interface_counters[vnet_counter_type][sw_if_index] = counter;
1587 static void vl_api_vnet_interface_counters_t_handler
1588 (vl_api_vnet_interface_counters_t *mp)
1593 static void vl_api_vnet_interface_counters_t_handler_json
1594 (vl_api_vnet_interface_counters_t *mp)
1596 interface_counter_t counter;
1601 u32 first_sw_if_index;
1604 count = ntohl(mp->count);
1605 first_sw_if_index = ntohl(mp->first_sw_if_index);
1607 if (!mp->is_combined) {
1608 v_packets = (u64*)&mp->data;
1609 for (i = 0; i < count; i++) {
1610 packets = clib_net_to_host_u64(clib_mem_unaligned(v_packets, u64));
1611 set_simple_interface_counter(mp->vnet_counter_type,
1612 first_sw_if_index + i, packets);
1616 v = (vlib_counter_t*)&mp->data;
1617 for (i = 0; i < count; i++) {
1618 counter.packets = clib_net_to_host_u64(
1619 clib_mem_unaligned(&v->packets, u64));
1620 counter.bytes = clib_net_to_host_u64(
1621 clib_mem_unaligned(&v->bytes, u64));
1622 set_combined_interface_counter(mp->vnet_counter_type,
1623 first_sw_if_index + i, counter);
1629 static u32 ip4_fib_counters_get_vrf_index_by_vrf_id (u32 vrf_id)
1631 vat_main_t * vam = &vat_main;
1634 for (i = 0; i < vec_len(vam->ip4_fib_counters_vrf_id_by_index); i++) {
1635 if (vam->ip4_fib_counters_vrf_id_by_index[i] == vrf_id) {
1642 static u32 ip6_fib_counters_get_vrf_index_by_vrf_id (u32 vrf_id)
1644 vat_main_t * vam = &vat_main;
1647 for (i = 0; i < vec_len(vam->ip6_fib_counters_vrf_id_by_index); i++) {
1648 if (vam->ip6_fib_counters_vrf_id_by_index[i] == vrf_id) {
1655 static void vl_api_vnet_ip4_fib_counters_t_handler
1656 (vl_api_vnet_ip4_fib_counters_t *mp)
1661 static void vl_api_vnet_ip4_fib_counters_t_handler_json
1662 (vl_api_vnet_ip4_fib_counters_t *mp)
1664 vat_main_t * vam = &vat_main;
1665 vl_api_ip4_fib_counter_t *v;
1666 ip4_fib_counter_t *counter;
1673 vrf_id = ntohl(mp->vrf_id);
1674 vrf_index = ip4_fib_counters_get_vrf_index_by_vrf_id(vrf_id);
1675 if (~0 == vrf_index) {
1676 vrf_index = vec_len(vam->ip4_fib_counters_vrf_id_by_index);
1677 vec_validate(vam->ip4_fib_counters_vrf_id_by_index, vrf_index);
1678 vam->ip4_fib_counters_vrf_id_by_index[vrf_index] = vrf_id;
1679 vec_validate(vam->ip4_fib_counters, vrf_index);
1680 vam->ip4_fib_counters[vrf_index] = NULL;
1683 vec_free(vam->ip4_fib_counters[vrf_index]);
1684 v = (vl_api_ip4_fib_counter_t*)&mp->c;
1685 count = ntohl(mp->count);
1686 for (i = 0; i < count; i++) {
1687 vec_validate(vam->ip4_fib_counters[vrf_index], i);
1688 counter = &vam->ip4_fib_counters[vrf_index][i];
1689 clib_memcpy(&ip4, &v->address, sizeof(ip4));
1690 counter->address = ip4;
1691 counter->address_length = v->address_length;
1692 counter->packets = clib_net_to_host_u64(v->packets);
1693 counter->bytes = clib_net_to_host_u64(v->bytes);
1698 static void vl_api_vnet_ip6_fib_counters_t_handler
1699 (vl_api_vnet_ip6_fib_counters_t *mp)
1704 static void vl_api_vnet_ip6_fib_counters_t_handler_json
1705 (vl_api_vnet_ip6_fib_counters_t *mp)
1707 vat_main_t * vam = &vat_main;
1708 vl_api_ip6_fib_counter_t *v;
1709 ip6_fib_counter_t *counter;
1710 struct in6_addr ip6;
1716 vrf_id = ntohl(mp->vrf_id);
1717 vrf_index = ip6_fib_counters_get_vrf_index_by_vrf_id(vrf_id);
1718 if (~0 == vrf_index) {
1719 vrf_index = vec_len(vam->ip6_fib_counters_vrf_id_by_index);
1720 vec_validate(vam->ip6_fib_counters_vrf_id_by_index, vrf_index);
1721 vam->ip6_fib_counters_vrf_id_by_index[vrf_index] = vrf_id;
1722 vec_validate(vam->ip6_fib_counters, vrf_index);
1723 vam->ip6_fib_counters[vrf_index] = NULL;
1726 vec_free(vam->ip6_fib_counters[vrf_index]);
1727 v = (vl_api_ip6_fib_counter_t*)&mp->c;
1728 count = ntohl(mp->count);
1729 for (i = 0; i < count; i++) {
1730 vec_validate(vam->ip6_fib_counters[vrf_index], i);
1731 counter = &vam->ip6_fib_counters[vrf_index][i];
1732 clib_memcpy(&ip6, &v->address, sizeof(ip6));
1733 counter->address = ip6;
1734 counter->address_length = v->address_length;
1735 counter->packets = clib_net_to_host_u64(v->packets);
1736 counter->bytes = clib_net_to_host_u64(v->bytes);
1741 static void vl_api_get_first_msg_id_reply_t_handler
1742 (vl_api_get_first_msg_id_reply_t * mp)
1744 vat_main_t * vam = &vat_main;
1745 i32 retval = ntohl(mp->retval);
1747 if (vam->async_mode) {
1748 vam->async_errors += (retval < 0);
1750 vam->retval = retval;
1751 vam->result_ready = 1;
1754 errmsg ("first message id %d\n", ntohs(mp->first_msg_id));
1758 static void vl_api_get_first_msg_id_reply_t_handler_json
1759 (vl_api_get_first_msg_id_reply_t * mp)
1761 vat_main_t * vam = &vat_main;
1762 vat_json_node_t node;
1764 vat_json_init_object(&node);
1765 vat_json_object_add_int(&node, "retval", ntohl(mp->retval));
1766 vat_json_object_add_uint(&node, "first_msg_id",
1767 (uint) ntohs(mp->first_msg_id));
1769 vat_json_print(vam->ofp, &node);
1770 vat_json_free(&node);
1772 vam->retval = ntohl(mp->retval);
1773 vam->result_ready = 1;
1776 static void vl_api_get_node_graph_reply_t_handler
1777 (vl_api_get_node_graph_reply_t * mp)
1779 vat_main_t * vam = &vat_main;
1780 api_main_t * am = &api_main;
1781 i32 retval = ntohl(mp->retval);
1782 u8 * pvt_copy, * reply;
1787 if (vam->async_mode) {
1788 vam->async_errors += (retval < 0);
1790 vam->retval = retval;
1791 vam->result_ready = 1;
1794 /* "Should never happen..." */
1798 reply = (u8 *)(mp->reply_in_shmem);
1799 pvt_copy = vec_dup (reply);
1801 /* Toss the shared-memory original... */
1802 pthread_mutex_lock (&am->vlib_rp->mutex);
1803 oldheap = svm_push_data_heap (am->vlib_rp);
1807 svm_pop_heap (oldheap);
1808 pthread_mutex_unlock (&am->vlib_rp->mutex);
1810 if (vam->graph_nodes) {
1811 hash_free (vam->graph_node_index_by_name);
1813 for (i = 0; i < vec_len (vam->graph_nodes); i++) {
1814 node = vam->graph_nodes[i];
1815 vec_free (node->name);
1816 vec_free (node->next_nodes);
1819 vec_free(vam->graph_nodes);
1822 vam->graph_node_index_by_name = hash_create_string (0, sizeof(uword));
1823 vam->graph_nodes = vlib_node_unserialize (pvt_copy);
1824 vec_free (pvt_copy);
1826 for (i = 0; i < vec_len (vam->graph_nodes); i++) {
1827 node = vam->graph_nodes[i];
1828 hash_set_mem (vam->graph_node_index_by_name, node->name, i);
1832 static void vl_api_get_node_graph_reply_t_handler_json
1833 (vl_api_get_node_graph_reply_t * mp)
1835 vat_main_t * vam = &vat_main;
1836 api_main_t * am = &api_main;
1838 vat_json_node_t node;
1841 /* $$$$ make this real? */
1842 vat_json_init_object(&node);
1843 vat_json_object_add_int(&node, "retval", ntohl(mp->retval));
1844 vat_json_object_add_uint(&node, "reply_in_shmem", mp->reply_in_shmem);
1846 reply = (u8 *)(mp->reply_in_shmem);
1848 /* Toss the shared-memory original... */
1849 pthread_mutex_lock (&am->vlib_rp->mutex);
1850 oldheap = svm_push_data_heap (am->vlib_rp);
1854 svm_pop_heap (oldheap);
1855 pthread_mutex_unlock (&am->vlib_rp->mutex);
1857 vat_json_print(vam->ofp, &node);
1858 vat_json_free(&node);
1860 vam->retval = ntohl(mp->retval);
1861 vam->result_ready = 1;
1865 vl_api_lisp_locator_set_details_t_handler (
1866 vl_api_lisp_locator_set_details_t *mp)
1868 vat_main_t *vam = &vat_main;
1869 u8 * tmp_str = NULL;
1872 fformat(vam->ofp, "%=20s%=16d%=16d%=16d\n",
1873 mp->locator_set_name,
1874 ntohl(mp->sw_if_index),
1878 tmp_str = format(0,"%U/%d",
1879 mp->is_ipv6 ? format_ip6_address : format_ip4_address,
1883 fformat(vam->ofp, "%=20s%=16s%=16d%=16d\n",
1884 mp->locator_set_name,
1893 vl_api_lisp_locator_set_details_t_handler_json (
1894 vl_api_lisp_locator_set_details_t *mp)
1896 vat_main_t *vam = &vat_main;
1897 vat_json_node_t *node = NULL;
1898 struct in6_addr ip6;
1901 if (VAT_JSON_ARRAY != vam->json_tree.type) {
1902 ASSERT(VAT_JSON_NONE == vam->json_tree.type);
1903 vat_json_init_array(&vam->json_tree);
1905 node = vat_json_array_add(&vam->json_tree);
1907 vat_json_init_object(node);
1908 vat_json_object_add_string_copy(node, "locator-set", mp->locator_set_name);
1910 vat_json_object_add_uint(node, "locator", ntohl(mp->sw_if_index));
1913 clib_memcpy(&ip6, mp->ip_address, sizeof(ip6));
1914 vat_json_object_add_ip6(node, "locator", ip6);
1916 clib_memcpy(&ip4, mp->ip_address, sizeof(ip4));
1917 vat_json_object_add_ip4(node, "locator", ip4);
1919 vat_json_object_add_uint(node, "prefix-length", mp->prefix_len);
1921 vat_json_object_add_uint(node, "priority", mp->priority);
1922 vat_json_object_add_uint(node, "weight", mp->weight);
1926 vl_api_lisp_local_eid_table_details_t_handler (
1927 vl_api_lisp_local_eid_table_details_t *mp)
1929 vat_main_t *vam = &vat_main;
1932 prefix = format(0, "%U/%d",
1933 mp->eid_is_ipv6 ? format_ip6_address : format_ip4_address,
1935 mp->eid_prefix_len);
1937 fformat(vam->ofp, "%=20s%=30s\n",
1938 mp->locator_set_name, prefix);
1944 vl_api_lisp_local_eid_table_details_t_handler_json (
1945 vl_api_lisp_local_eid_table_details_t *mp)
1947 vat_main_t *vam = &vat_main;
1948 vat_json_node_t *node = NULL;
1949 struct in6_addr ip6;
1952 if (VAT_JSON_ARRAY != vam->json_tree.type) {
1953 ASSERT(VAT_JSON_NONE == vam->json_tree.type);
1954 vat_json_init_array(&vam->json_tree);
1956 node = vat_json_array_add(&vam->json_tree);
1958 vat_json_init_object(node);
1959 vat_json_object_add_string_copy(node, "locator-set", mp->locator_set_name);
1960 if (mp->eid_is_ipv6) {
1961 clib_memcpy(&ip6, mp->eid_ip_address, sizeof(ip6));
1962 vat_json_object_add_ip6(node, "eid address", ip6);
1964 clib_memcpy(&ip4, mp->eid_ip_address, sizeof(ip4));
1965 vat_json_object_add_ip4(node, "eid address", ip4);
1967 vat_json_object_add_uint(node, "eid prefix len", mp->eid_prefix_len);
1971 format_decap_next (u8 * s, va_list * args)
1973 u32 next_index = va_arg (*args, u32);
1977 case LISP_GPE_INPUT_NEXT_DROP:
1978 return format (s, "drop");
1979 case LISP_GPE_INPUT_NEXT_IP4_INPUT:
1980 return format (s, "ip4");
1981 case LISP_GPE_INPUT_NEXT_IP6_INPUT:
1982 return format (s, "ip6");
1984 return format (s, "unknown %d", next_index);
1990 vl_api_lisp_gpe_tunnel_details_t_handler (vl_api_lisp_gpe_tunnel_details_t *mp)
1992 vat_main_t *vam = &vat_main;
1994 u8 *flag_str = NULL;
1996 iid_str = format(0, "%d (0x%x)", ntohl(mp->iid), ntohl(mp->iid));
1998 #define _(n,v) if (mp->flags & v) flag_str = format (flag_str, "%s-bit ", #n);
1999 foreach_lisp_gpe_flag_bit;
2002 fformat(vam->ofp, "%=20d%=30U%=16U%=16d%=16d%=16U"
2003 "%=16d%=16d%=16sd=16d%=16s%=16s\n",
2005 mp->is_ipv6 ? format_ip6_address : format_ip4_address,
2007 mp->is_ipv6 ? format_ip6_address : format_ip4_address,
2009 ntohl(mp->encap_fib_id),
2010 ntohl(mp->decap_fib_id),
2011 format_decap_next, ntohl(mp->dcap_next),
2023 vl_api_lisp_gpe_tunnel_details_t_handler_json (
2024 vl_api_lisp_gpe_tunnel_details_t *mp)
2026 vat_main_t *vam = &vat_main;
2027 vat_json_node_t *node = NULL;
2028 struct in6_addr ip6;
2032 next_decap_str = format(0, "%U", format_decap_next, htonl(mp->dcap_next));
2034 if (VAT_JSON_ARRAY != vam->json_tree.type) {
2035 ASSERT(VAT_JSON_NONE == vam->json_tree.type);
2036 vat_json_init_array(&vam->json_tree);
2038 node = vat_json_array_add(&vam->json_tree);
2040 vat_json_init_object(node);
2041 vat_json_object_add_uint(node, "tunel", mp->tunnels);
2043 clib_memcpy(&ip6, mp->source_ip, sizeof(ip6));
2044 vat_json_object_add_ip6(node, "source address", ip6);
2045 clib_memcpy(&ip6, mp->destination_ip, sizeof(ip6));
2046 vat_json_object_add_ip6(node, "destination address", ip6);
2048 clib_memcpy(&ip4, mp->source_ip, sizeof(ip4));
2049 vat_json_object_add_ip4(node, "source address", ip4);
2050 clib_memcpy(&ip4, mp->destination_ip, sizeof(ip4));
2051 vat_json_object_add_ip4(node, "destination address", ip4);
2053 vat_json_object_add_uint(node, "fib encap", ntohl(mp->encap_fib_id));
2054 vat_json_object_add_uint(node, "fib decap", ntohl(mp->decap_fib_id));
2055 vat_json_object_add_string_copy(node, "decap next", next_decap_str);
2056 vat_json_object_add_uint(node, "lisp version", mp->ver_res >> 6);
2057 vat_json_object_add_uint(node, "flags", mp->flags);
2058 vat_json_object_add_uint(node, "next protocol", mp->next_protocol);
2059 vat_json_object_add_uint(node, "ver_res", mp->ver_res);
2060 vat_json_object_add_uint(node, "res", mp->res);
2061 vat_json_object_add_uint(node, "iid", ntohl(mp->iid));
2063 vec_free(next_decap_str);
2067 vl_api_lisp_map_resolver_details_t_handler (
2068 vl_api_lisp_map_resolver_details_t *mp)
2070 vat_main_t *vam = &vat_main;
2072 fformat(vam->ofp, "%=20U\n",
2073 mp->is_ipv6 ? format_ip6_address : format_ip4_address,
2078 vl_api_lisp_map_resolver_details_t_handler_json (
2079 vl_api_lisp_map_resolver_details_t *mp)
2081 vat_main_t *vam = &vat_main;
2082 vat_json_node_t *node = NULL;
2083 struct in6_addr ip6;
2086 if (VAT_JSON_ARRAY != vam->json_tree.type) {
2087 ASSERT(VAT_JSON_NONE == vam->json_tree.type);
2088 vat_json_init_array(&vam->json_tree);
2090 node = vat_json_array_add(&vam->json_tree);
2092 vat_json_init_object(node);
2094 clib_memcpy(&ip6, mp->ip_address, sizeof(ip6));
2095 vat_json_object_add_ip6(node, "map resolver", ip6);
2097 clib_memcpy(&ip4, mp->ip_address, sizeof(ip4));
2098 vat_json_object_add_ip4(node, "map resolver", ip4);
2103 vl_api_lisp_enable_disable_status_details_t_handler
2104 (vl_api_lisp_enable_disable_status_details_t *mp)
2106 vat_main_t *vam = &vat_main;
2108 fformat(vam->ofp, "feature: %s\ngpe: %s\n",
2109 mp->feature_status ? "enabled" : "disabled",
2110 mp->gpe_status ? "enabled" : "disabled");
2114 vl_api_lisp_enable_disable_status_details_t_handler_json
2115 (vl_api_lisp_enable_disable_status_details_t *mp)
2117 vat_main_t *vam = &vat_main;
2118 vat_json_node_t *node = NULL;
2119 u8 * gpe_status = NULL;
2120 u8 * feature_status = NULL;
2122 gpe_status = format (0, "%s", mp->gpe_status ? "enabled" : "disabled");
2123 feature_status = format (0, "%s",
2124 mp->feature_status ? "enabled" : "disabled");
2126 if (VAT_JSON_ARRAY != vam->json_tree.type) {
2127 ASSERT(VAT_JSON_NONE == vam->json_tree.type);
2128 vat_json_init_array(&vam->json_tree);
2130 node = vat_json_array_add(&vam->json_tree);
2132 vat_json_init_object(node);
2133 vat_json_object_add_string_copy(node, "gpe_status", gpe_status);
2134 vat_json_object_add_string_copy(node, "feature_status", feature_status);
2136 vec_free (gpe_status);
2137 vec_free (feature_status);
2140 #define vl_api_vnet_ip4_fib_counters_t_endian vl_noop_handler
2141 #define vl_api_vnet_ip4_fib_counters_t_print vl_noop_handler
2142 #define vl_api_vnet_ip6_fib_counters_t_endian vl_noop_handler
2143 #define vl_api_vnet_ip6_fib_counters_t_print vl_noop_handler
2146 * Generate boilerplate reply handlers, which
2147 * dig the return value out of the xxx_reply_t API message,
2148 * stick it into vam->retval, and set vam->result_ready
2150 * Could also do this by pointing N message decode slots at
2151 * a single function, but that could break in subtle ways.
2154 #define foreach_standard_reply_retval_handler \
2155 _(sw_interface_set_flags_reply) \
2156 _(sw_interface_add_del_address_reply) \
2157 _(sw_interface_set_table_reply) \
2158 _(sw_interface_set_vpath_reply) \
2159 _(sw_interface_set_l2_bridge_reply) \
2160 _(bridge_domain_add_del_reply) \
2161 _(sw_interface_set_l2_xconnect_reply) \
2162 _(l2fib_add_del_reply) \
2163 _(ip_add_del_route_reply) \
2164 _(proxy_arp_add_del_reply) \
2165 _(proxy_arp_intfc_enable_disable_reply) \
2166 _(mpls_add_del_encap_reply) \
2167 _(mpls_add_del_decap_reply) \
2168 _(mpls_ethernet_add_del_tunnel_2_reply) \
2169 _(sw_interface_set_unnumbered_reply) \
2170 _(ip_neighbor_add_del_reply) \
2171 _(reset_vrf_reply) \
2172 _(oam_add_del_reply) \
2173 _(reset_fib_reply) \
2174 _(dhcp_proxy_config_reply) \
2175 _(dhcp_proxy_config_2_reply) \
2176 _(dhcp_proxy_set_vss_reply) \
2177 _(dhcp_client_config_reply) \
2178 _(set_ip_flow_hash_reply) \
2179 _(sw_interface_ip6_enable_disable_reply) \
2180 _(sw_interface_ip6_set_link_local_address_reply) \
2181 _(sw_interface_ip6nd_ra_prefix_reply) \
2182 _(sw_interface_ip6nd_ra_config_reply) \
2183 _(set_arp_neighbor_limit_reply) \
2184 _(l2_patch_add_del_reply) \
2185 _(sr_tunnel_add_del_reply) \
2186 _(sr_policy_add_del_reply) \
2187 _(sr_multicast_map_add_del_reply) \
2188 _(classify_add_del_session_reply) \
2189 _(classify_set_interface_ip_table_reply) \
2190 _(classify_set_interface_l2_tables_reply) \
2191 _(l2tpv3_set_tunnel_cookies_reply) \
2192 _(l2tpv3_interface_enable_disable_reply) \
2193 _(l2tpv3_set_lookup_key_reply) \
2194 _(l2_fib_clear_table_reply) \
2195 _(l2_interface_efp_filter_reply) \
2196 _(l2_interface_vlan_tag_rewrite_reply) \
2197 _(modify_vhost_user_if_reply) \
2198 _(delete_vhost_user_if_reply) \
2199 _(want_ip4_arp_events_reply) \
2200 _(input_acl_set_interface_reply) \
2201 _(ipsec_spd_add_del_reply) \
2202 _(ipsec_interface_add_del_spd_reply) \
2203 _(ipsec_spd_add_del_entry_reply) \
2204 _(ipsec_sad_add_del_entry_reply) \
2205 _(ipsec_sa_set_key_reply) \
2206 _(ikev2_profile_add_del_reply) \
2207 _(ikev2_profile_set_auth_reply) \
2208 _(ikev2_profile_set_id_reply) \
2209 _(ikev2_profile_set_ts_reply) \
2210 _(ikev2_set_local_key_reply) \
2211 _(delete_loopback_reply) \
2212 _(bd_ip_mac_add_del_reply) \
2213 _(map_del_domain_reply) \
2214 _(map_add_del_rule_reply) \
2215 _(want_interface_events_reply) \
2216 _(want_stats_reply) \
2217 _(cop_interface_enable_disable_reply) \
2218 _(cop_whitelist_enable_disable_reply) \
2219 _(sw_interface_clear_stats_reply) \
2220 _(trace_profile_add_reply) \
2221 _(trace_profile_apply_reply) \
2222 _(trace_profile_del_reply) \
2223 _(lisp_add_del_locator_set_reply) \
2224 _(lisp_add_del_locator_reply) \
2225 _(lisp_add_del_local_eid_reply) \
2226 _(lisp_gpe_add_del_fwd_entry_reply) \
2227 _(lisp_add_del_map_resolver_reply) \
2228 _(lisp_gpe_enable_disable_reply) \
2229 _(lisp_gpe_add_del_iface_reply) \
2230 _(lisp_enable_disable_reply) \
2231 _(vxlan_gpe_add_del_tunnel_reply) \
2232 _(af_packet_create_reply) \
2233 _(af_packet_delete_reply) \
2234 _(policer_add_del_reply)
2237 static void vl_api_##n##_t_handler \
2238 (vl_api_##n##_t * mp) \
2240 vat_main_t * vam = &vat_main; \
2241 i32 retval = ntohl(mp->retval); \
2242 if (vam->async_mode) { \
2243 vam->async_errors += (retval < 0); \
2245 vam->retval = retval; \
2246 vam->result_ready = 1; \
2249 foreach_standard_reply_retval_handler;
2253 static void vl_api_##n##_t_handler_json \
2254 (vl_api_##n##_t * mp) \
2256 vat_main_t * vam = &vat_main; \
2257 vat_json_node_t node; \
2258 vat_json_init_object(&node); \
2259 vat_json_object_add_int(&node, "retval", ntohl(mp->retval)); \
2260 vat_json_print(vam->ofp, &node); \
2261 vam->retval = ntohl(mp->retval); \
2262 vam->result_ready = 1; \
2264 foreach_standard_reply_retval_handler;
2268 * Table of message reply handlers, must include boilerplate handlers
2272 #define foreach_vpe_api_reply_msg \
2273 _(CREATE_LOOPBACK_REPLY, create_loopback_reply) \
2274 _(SW_INTERFACE_DETAILS, sw_interface_details) \
2275 _(SW_INTERFACE_SET_FLAGS, sw_interface_set_flags) \
2276 _(SW_INTERFACE_SET_FLAGS_REPLY, sw_interface_set_flags_reply) \
2277 _(CONTROL_PING_REPLY, control_ping_reply) \
2278 _(CLI_REPLY, cli_reply) \
2279 _(SW_INTERFACE_ADD_DEL_ADDRESS_REPLY, \
2280 sw_interface_add_del_address_reply) \
2281 _(SW_INTERFACE_SET_TABLE_REPLY, sw_interface_set_table_reply) \
2282 _(SW_INTERFACE_SET_VPATH_REPLY, sw_interface_set_vpath_reply) \
2283 _(SW_INTERFACE_SET_L2_XCONNECT_REPLY, \
2284 sw_interface_set_l2_xconnect_reply) \
2285 _(SW_INTERFACE_SET_L2_BRIDGE_REPLY, \
2286 sw_interface_set_l2_bridge_reply) \
2287 _(BRIDGE_DOMAIN_ADD_DEL_REPLY, bridge_domain_add_del_reply) \
2288 _(BRIDGE_DOMAIN_DETAILS, bridge_domain_details) \
2289 _(BRIDGE_DOMAIN_SW_IF_DETAILS, bridge_domain_sw_if_details) \
2290 _(L2FIB_ADD_DEL_REPLY, l2fib_add_del_reply) \
2291 _(L2_FLAGS_REPLY, l2_flags_reply) \
2292 _(BRIDGE_FLAGS_REPLY, bridge_flags_reply) \
2293 _(TAP_CONNECT_REPLY, tap_connect_reply) \
2294 _(TAP_MODIFY_REPLY, tap_modify_reply) \
2295 _(TAP_DELETE_REPLY, tap_delete_reply) \
2296 _(SW_INTERFACE_TAP_DETAILS, sw_interface_tap_details) \
2297 _(IP_ADD_DEL_ROUTE_REPLY, ip_add_del_route_reply) \
2298 _(PROXY_ARP_ADD_DEL_REPLY, proxy_arp_add_del_reply) \
2299 _(PROXY_ARP_INTFC_ENABLE_DISABLE_REPLY, \
2300 proxy_arp_intfc_enable_disable_reply) \
2301 _(MPLS_ADD_DEL_ENCAP_REPLY, mpls_add_del_encap_reply) \
2302 _(MPLS_ADD_DEL_DECAP_REPLY, mpls_add_del_decap_reply) \
2303 _(MPLS_GRE_ADD_DEL_TUNNEL_REPLY, mpls_gre_add_del_tunnel_reply) \
2304 _(MPLS_ETHERNET_ADD_DEL_TUNNEL_REPLY, \
2305 mpls_ethernet_add_del_tunnel_reply) \
2306 _(MPLS_ETHERNET_ADD_DEL_TUNNEL_2_REPLY, \
2307 mpls_ethernet_add_del_tunnel_2_reply) \
2308 _(SW_INTERFACE_SET_UNNUMBERED_REPLY, \
2309 sw_interface_set_unnumbered_reply) \
2310 _(IP_NEIGHBOR_ADD_DEL_REPLY, ip_neighbor_add_del_reply) \
2311 _(RESET_VRF_REPLY, reset_vrf_reply) \
2312 _(CREATE_VLAN_SUBIF_REPLY, create_vlan_subif_reply) \
2313 _(CREATE_SUBIF_REPLY, create_subif_reply) \
2314 _(OAM_ADD_DEL_REPLY, oam_add_del_reply) \
2315 _(RESET_FIB_REPLY, reset_fib_reply) \
2316 _(DHCP_PROXY_CONFIG_REPLY, dhcp_proxy_config_reply) \
2317 _(DHCP_PROXY_CONFIG_2_REPLY, dhcp_proxy_config_2_reply) \
2318 _(DHCP_PROXY_SET_VSS_REPLY, dhcp_proxy_set_vss_reply) \
2319 _(DHCP_CLIENT_CONFIG_REPLY, dhcp_client_config_reply) \
2320 _(SET_IP_FLOW_HASH_REPLY, set_ip_flow_hash_reply) \
2321 _(SW_INTERFACE_IP6_ENABLE_DISABLE_REPLY, \
2322 sw_interface_ip6_enable_disable_reply) \
2323 _(SW_INTERFACE_IP6_SET_LINK_LOCAL_ADDRESS_REPLY, \
2324 sw_interface_ip6_set_link_local_address_reply) \
2325 _(SW_INTERFACE_IP6ND_RA_PREFIX_REPLY, \
2326 sw_interface_ip6nd_ra_prefix_reply) \
2327 _(SW_INTERFACE_IP6ND_RA_CONFIG_REPLY, \
2328 sw_interface_ip6nd_ra_config_reply) \
2329 _(SET_ARP_NEIGHBOR_LIMIT_REPLY, set_arp_neighbor_limit_reply) \
2330 _(L2_PATCH_ADD_DEL_REPLY, l2_patch_add_del_reply) \
2331 _(SR_TUNNEL_ADD_DEL_REPLY, sr_tunnel_add_del_reply) \
2332 _(SR_POLICY_ADD_DEL_REPLY, sr_policy_add_del_reply) \
2333 _(SR_MULTICAST_MAP_ADD_DEL_REPLY, sr_multicast_map_add_del_reply) \
2334 _(CLASSIFY_ADD_DEL_TABLE_REPLY, classify_add_del_table_reply) \
2335 _(CLASSIFY_ADD_DEL_SESSION_REPLY, classify_add_del_session_reply) \
2336 _(CLASSIFY_SET_INTERFACE_IP_TABLE_REPLY, \
2337 classify_set_interface_ip_table_reply) \
2338 _(CLASSIFY_SET_INTERFACE_L2_TABLES_REPLY, \
2339 classify_set_interface_l2_tables_reply) \
2340 _(GET_NODE_INDEX_REPLY, get_node_index_reply) \
2341 _(ADD_NODE_NEXT_REPLY, add_node_next_reply) \
2342 _(L2TPV3_CREATE_TUNNEL_REPLY, l2tpv3_create_tunnel_reply) \
2343 _(L2TPV3_SET_TUNNEL_COOKIES_REPLY, l2tpv3_set_tunnel_cookies_reply) \
2344 _(L2TPV3_INTERFACE_ENABLE_DISABLE_REPLY, \
2345 l2tpv3_interface_enable_disable_reply) \
2346 _(L2TPV3_SET_LOOKUP_KEY_REPLY, l2tpv3_set_lookup_key_reply) \
2347 _(SW_IF_L2TPV3_TUNNEL_DETAILS, sw_if_l2tpv3_tunnel_details) \
2348 _(VXLAN_ADD_DEL_TUNNEL_REPLY, vxlan_add_del_tunnel_reply) \
2349 _(VXLAN_TUNNEL_DETAILS, vxlan_tunnel_details) \
2350 _(GRE_ADD_DEL_TUNNEL_REPLY, gre_add_del_tunnel_reply) \
2351 _(GRE_TUNNEL_DETAILS, gre_tunnel_details) \
2352 _(L2_FIB_CLEAR_TABLE_REPLY, l2_fib_clear_table_reply) \
2353 _(L2_INTERFACE_EFP_FILTER_REPLY, l2_interface_efp_filter_reply) \
2354 _(L2_INTERFACE_VLAN_TAG_REWRITE_REPLY, l2_interface_vlan_tag_rewrite_reply) \
2355 _(SW_INTERFACE_VHOST_USER_DETAILS, sw_interface_vhost_user_details) \
2356 _(CREATE_VHOST_USER_IF_REPLY, create_vhost_user_if_reply) \
2357 _(MODIFY_VHOST_USER_IF_REPLY, modify_vhost_user_if_reply) \
2358 _(DELETE_VHOST_USER_IF_REPLY, delete_vhost_user_if_reply) \
2359 _(SHOW_VERSION_REPLY, show_version_reply) \
2360 _(L2_FIB_TABLE_ENTRY, l2_fib_table_entry) \
2361 _(VXLAN_GPE_ADD_DEL_TUNNEL_REPLY, vxlan_gpe_add_del_tunnel_reply) \
2362 _(INTERFACE_NAME_RENUMBER_REPLY, interface_name_renumber_reply) \
2363 _(WANT_IP4_ARP_EVENTS_REPLY, want_ip4_arp_events_reply) \
2364 _(IP4_ARP_EVENT, ip4_arp_event) \
2365 _(INPUT_ACL_SET_INTERFACE_REPLY, input_acl_set_interface_reply) \
2366 _(IP_ADDRESS_DETAILS, ip_address_details) \
2367 _(IP_DETAILS, ip_details) \
2368 _(IPSEC_SPD_ADD_DEL_REPLY, ipsec_spd_add_del_reply) \
2369 _(IPSEC_INTERFACE_ADD_DEL_SPD_REPLY, ipsec_interface_add_del_spd_reply) \
2370 _(IPSEC_SPD_ADD_DEL_ENTRY_REPLY, ipsec_spd_add_del_entry_reply) \
2371 _(IPSEC_SAD_ADD_DEL_ENTRY_REPLY, ipsec_sad_add_del_entry_reply) \
2372 _(IPSEC_SA_SET_KEY_REPLY, ipsec_sa_set_key_reply) \
2373 _(IKEV2_PROFILE_ADD_DEL_REPLY, ikev2_profile_add_del_reply) \
2374 _(IKEV2_PROFILE_SET_AUTH_REPLY, ikev2_profile_set_auth_reply) \
2375 _(IKEV2_PROFILE_SET_ID_REPLY, ikev2_profile_set_id_reply) \
2376 _(IKEV2_PROFILE_SET_TS_REPLY, ikev2_profile_set_ts_reply) \
2377 _(IKEV2_SET_LOCAL_KEY_REPLY, ikev2_set_local_key_reply) \
2378 _(DELETE_LOOPBACK_REPLY, delete_loopback_reply) \
2379 _(BD_IP_MAC_ADD_DEL_REPLY, bd_ip_mac_add_del_reply) \
2380 _(DHCP_COMPL_EVENT, dhcp_compl_event) \
2381 _(VNET_INTERFACE_COUNTERS, vnet_interface_counters) \
2382 _(VNET_IP4_FIB_COUNTERS, vnet_ip4_fib_counters) \
2383 _(VNET_IP6_FIB_COUNTERS, vnet_ip6_fib_counters) \
2384 _(MAP_ADD_DOMAIN_REPLY, map_add_domain_reply) \
2385 _(MAP_DEL_DOMAIN_REPLY, map_del_domain_reply) \
2386 _(MAP_ADD_DEL_RULE_REPLY, map_add_del_rule_reply) \
2387 _(MAP_DOMAIN_DETAILS, map_domain_details) \
2388 _(MAP_RULE_DETAILS, map_rule_details) \
2389 _(WANT_INTERFACE_EVENTS_REPLY, want_interface_events_reply) \
2390 _(WANT_STATS_REPLY, want_stats_reply) \
2391 _(GET_FIRST_MSG_ID_REPLY, get_first_msg_id_reply) \
2392 _(COP_INTERFACE_ENABLE_DISABLE_REPLY, cop_interface_enable_disable_reply) \
2393 _(COP_WHITELIST_ENABLE_DISABLE_REPLY, cop_whitelist_enable_disable_reply) \
2394 _(GET_NODE_GRAPH_REPLY, get_node_graph_reply) \
2395 _(SW_INTERFACE_CLEAR_STATS_REPLY, sw_interface_clear_stats_reply) \
2396 _(TRACE_PROFILE_ADD_REPLY, trace_profile_add_reply) \
2397 _(TRACE_PROFILE_APPLY_REPLY, trace_profile_apply_reply) \
2398 _(TRACE_PROFILE_DEL_REPLY, trace_profile_del_reply) \
2399 _(LISP_ADD_DEL_LOCATOR_SET_REPLY, lisp_add_del_locator_set_reply) \
2400 _(LISP_ADD_DEL_LOCATOR_REPLY, lisp_add_del_locator_reply) \
2401 _(LISP_ADD_DEL_LOCAL_EID_REPLY, lisp_add_del_local_eid_reply) \
2402 _(LISP_GPE_ADD_DEL_FWD_ENTRY_REPLY, lisp_gpe_add_del_fwd_entry_reply) \
2403 _(LISP_ADD_DEL_MAP_RESOLVER_REPLY, lisp_add_del_map_resolver_reply) \
2404 _(LISP_GPE_ENABLE_DISABLE_REPLY, lisp_gpe_enable_disable_reply) \
2405 _(LISP_ENABLE_DISABLE_REPLY, lisp_enable_disable_reply) \
2406 _(LISP_GPE_ADD_DEL_IFACE_REPLY, lisp_gpe_add_del_iface_reply) \
2407 _(LISP_LOCATOR_SET_DETAILS, lisp_locator_set_details) \
2408 _(LISP_LOCAL_EID_TABLE_DETAILS, lisp_local_eid_table_details) \
2409 _(LISP_GPE_TUNNEL_DETAILS, lisp_gpe_tunnel_details) \
2410 _(LISP_MAP_RESOLVER_DETAILS, lisp_map_resolver_details) \
2411 _(LISP_ENABLE_DISABLE_STATUS_DETAILS, \
2412 lisp_enable_disable_status_details) \
2413 _(AF_PACKET_CREATE_REPLY, af_packet_create_reply) \
2414 _(AF_PACKET_DELETE_REPLY, af_packet_delete_reply) \
2415 _(POLICER_ADD_DEL_REPLY, policer_add_del_reply)
2417 /* M: construct, but don't yet send a message */
2421 vam->result_ready = 0; \
2422 mp = vl_msg_api_alloc(sizeof(*mp)); \
2423 memset (mp, 0, sizeof (*mp)); \
2424 mp->_vl_msg_id = ntohs (VL_API_##T); \
2425 mp->client_index = vam->my_client_index; \
2430 vam->result_ready = 0; \
2431 mp = vl_msg_api_alloc(sizeof(*mp)+(n)); \
2432 memset (mp, 0, sizeof (*mp)); \
2433 mp->_vl_msg_id = ntohs (VL_API_##T); \
2434 mp->client_index = vam->my_client_index; \
2438 /* S: send a message */
2439 #define S (vl_msg_api_send_shmem (vam->vl_input_queue, (u8 *)&mp))
2441 /* W: wait for results, with timeout */
2444 timeout = vat_time_now (vam) + 1.0; \
2446 while (vat_time_now (vam) < timeout) { \
2447 if (vam->result_ready == 1) { \
2448 return (vam->retval); \
2460 #define STR_VTR_OP_CASE(op) \
2461 case L2_VTR_ ## op: \
2464 static const char *str_vtr_op(u32 vtr_op)
2467 STR_VTR_OP_CASE(DISABLED);
2468 STR_VTR_OP_CASE(PUSH_1);
2469 STR_VTR_OP_CASE(PUSH_2);
2470 STR_VTR_OP_CASE(POP_1);
2471 STR_VTR_OP_CASE(POP_2);
2472 STR_VTR_OP_CASE(TRANSLATE_1_1);
2473 STR_VTR_OP_CASE(TRANSLATE_1_2);
2474 STR_VTR_OP_CASE(TRANSLATE_2_1);
2475 STR_VTR_OP_CASE(TRANSLATE_2_2);
2481 static int dump_sub_interface_table (vat_main_t * vam)
2483 const sw_interface_subif_t * sub = NULL;
2485 if (vam->json_output) {
2486 clib_warning ("JSON output supported only for VPE API calls and dump_stats_table");
2491 "%-30s%-12s%-11s%-7s%-5s%-9s%-9s%-6s%-8s%-10s%-10s\n",
2492 "Interface", "sw_if_index",
2493 "sub id", "dot1ad", "tags", "outer id",
2494 "inner id", "exact", "default",
2495 "outer any", "inner any");
2497 vec_foreach (sub, vam->sw_if_subif_table) {
2499 "%-30s%-12d%-11d%-7s%-5d%-9d%-9d%-6d%-8d%-10d%-10d\n",
2500 sub->interface_name,
2502 sub->sub_id, sub->sub_dot1ad ? "dot1ad" : "dot1q",
2503 sub->sub_number_of_tags, sub->sub_outer_vlan_id,
2504 sub->sub_inner_vlan_id, sub->sub_exact_match, sub->sub_default,
2505 sub->sub_outer_vlan_id_any, sub->sub_inner_vlan_id_any);
2506 if (sub->vtr_op != L2_VTR_DISABLED) {
2508 " vlan-tag-rewrite - op: %-14s [ dot1q: %d "
2509 "tag1: %d tag2: %d ]\n",
2510 str_vtr_op(sub->vtr_op), sub->vtr_push_dot1q,
2511 sub->vtr_tag1, sub->vtr_tag2);
2518 static int name_sort_cmp (void * a1, void * a2)
2520 name_sort_t * n1 = a1;
2521 name_sort_t * n2 = a2;
2523 return strcmp ((char *)n1->name, (char *)n2->name);
2526 static int dump_interface_table (vat_main_t * vam)
2529 name_sort_t * nses = 0, * ns;
2531 if (vam->json_output) {
2532 clib_warning ("JSON output supported only for VPE API calls and dump_stats_table");
2536 hash_foreach_pair (p, vam->sw_if_index_by_interface_name,
2538 vec_add2 (nses, ns, 1);
2539 ns->name = (u8 *)(p->key);
2540 ns->value = (u32) p->value[0];
2543 vec_sort_with_function (nses, name_sort_cmp);
2545 fformat (vam->ofp, "%-25s%-15s\n", "Interface", "sw_if_index");
2546 vec_foreach (ns, nses) {
2547 fformat (vam->ofp, "%-25s%-15d\n", ns->name, ns->value);
2553 static int dump_ip_table (vat_main_t * vam, int is_ipv6)
2555 const ip_details_t * det = NULL;
2556 const ip_address_details_t * address = NULL;
2567 vec_foreach (det, vam->ip_details_by_sw_if_index[is_ipv6]) {
2569 if (!det->present) {
2577 "Address", "Prefix length");
2581 vec_foreach (address, det->addr) {
2584 is_ipv6 ? format_ip6_address : format_ip4_address,
2586 address->prefix_length);
2593 static int dump_ipv4_table (vat_main_t * vam)
2595 if (vam->json_output) {
2596 clib_warning ("JSON output supported only for VPE API calls and dump_stats_table");
2600 return dump_ip_table (vam, 0);
2603 static int dump_ipv6_table (vat_main_t * vam)
2605 if (vam->json_output) {
2606 clib_warning ("JSON output supported only for VPE API calls and dump_stats_table");
2610 return dump_ip_table (vam, 1);
2613 static char* counter_type_to_str (u8 counter_type, u8 is_combined)
2616 switch(counter_type) {
2617 case VNET_INTERFACE_COUNTER_DROP:
2619 case VNET_INTERFACE_COUNTER_PUNT:
2621 case VNET_INTERFACE_COUNTER_IP4:
2623 case VNET_INTERFACE_COUNTER_IP6:
2625 case VNET_INTERFACE_COUNTER_RX_NO_BUF:
2627 case VNET_INTERFACE_COUNTER_RX_MISS:
2629 case VNET_INTERFACE_COUNTER_RX_ERROR:
2631 case VNET_INTERFACE_COUNTER_TX_ERROR:
2634 return "INVALID-COUNTER-TYPE";
2637 switch(counter_type) {
2638 case VNET_INTERFACE_COUNTER_RX:
2640 case VNET_INTERFACE_COUNTER_TX:
2643 return "INVALID-COUNTER-TYPE";
2648 static int dump_stats_table (vat_main_t * vam)
2650 vat_json_node_t node;
2651 vat_json_node_t *msg_array;
2652 vat_json_node_t *msg;
2653 vat_json_node_t *counter_array;
2654 vat_json_node_t *counter;
2655 interface_counter_t c;
2657 ip4_fib_counter_t *c4;
2658 ip6_fib_counter_t *c6;
2661 if (!vam->json_output) {
2662 clib_warning ("dump_stats_table supported only in JSON format");
2666 vat_json_init_object(&node);
2668 /* interface counters */
2669 msg_array = vat_json_object_add(&node, "interface_counters");
2670 vat_json_init_array(msg_array);
2671 for (i = 0; i < vec_len(vam->simple_interface_counters); i++) {
2672 msg = vat_json_array_add(msg_array);
2673 vat_json_init_object(msg);
2674 vat_json_object_add_string_copy(msg, "vnet_counter_type",
2675 (u8*)counter_type_to_str(i, 0));
2676 vat_json_object_add_int(msg, "is_combined", 0);
2677 counter_array = vat_json_object_add(msg, "data");
2678 vat_json_init_array(counter_array);
2679 for (j = 0; j < vec_len(vam->simple_interface_counters[i]); j++) {
2680 packets = vam->simple_interface_counters[i][j];
2681 vat_json_array_add_uint(counter_array, packets);
2684 for (i = 0; i < vec_len(vam->combined_interface_counters); i++) {
2685 msg = vat_json_array_add(msg_array);
2686 vat_json_init_object(msg);
2687 vat_json_object_add_string_copy(msg, "vnet_counter_type",
2688 (u8*)counter_type_to_str(i, 1));
2689 vat_json_object_add_int(msg, "is_combined", 1);
2690 counter_array = vat_json_object_add(msg, "data");
2691 vat_json_init_array(counter_array);
2692 for (j = 0; j < vec_len(vam->combined_interface_counters[i]); j++) {
2693 c = vam->combined_interface_counters[i][j];
2694 counter = vat_json_array_add(counter_array);
2695 vat_json_init_object(counter);
2696 vat_json_object_add_uint(counter, "packets", c.packets);
2697 vat_json_object_add_uint(counter, "bytes", c.bytes);
2701 /* ip4 fib counters */
2702 msg_array = vat_json_object_add(&node, "ip4_fib_counters");
2703 vat_json_init_array(msg_array);
2704 for (i = 0; i < vec_len(vam->ip4_fib_counters); i++) {
2705 msg = vat_json_array_add(msg_array);
2706 vat_json_init_object(msg);
2707 vat_json_object_add_uint(msg, "vrf_id", vam->ip4_fib_counters_vrf_id_by_index[i]);
2708 counter_array = vat_json_object_add(msg, "c");
2709 vat_json_init_array(counter_array);
2710 for (j = 0; j < vec_len(vam->ip4_fib_counters[i]); j++) {
2711 counter = vat_json_array_add(counter_array);
2712 vat_json_init_object(counter);
2713 c4 = &vam->ip4_fib_counters[i][j];
2714 vat_json_object_add_ip4(counter, "address", c4->address);
2715 vat_json_object_add_uint(counter, "address_length", c4->address_length);
2716 vat_json_object_add_uint(counter, "packets", c4->packets);
2717 vat_json_object_add_uint(counter, "bytes", c4->bytes);
2721 /* ip6 fib counters */
2722 msg_array = vat_json_object_add(&node, "ip6_fib_counters");
2723 vat_json_init_array(msg_array);
2724 for (i = 0; i < vec_len(vam->ip6_fib_counters); i++) {
2725 msg = vat_json_array_add(msg_array);
2726 vat_json_init_object(msg);
2727 vat_json_object_add_uint(msg, "vrf_id", vam->ip6_fib_counters_vrf_id_by_index[i]);
2728 counter_array = vat_json_object_add(msg, "c");
2729 vat_json_init_array(counter_array);
2730 for (j = 0; j < vec_len(vam->ip6_fib_counters[i]); j++) {
2731 counter = vat_json_array_add(counter_array);
2732 vat_json_init_object(counter);
2733 c6 = &vam->ip6_fib_counters[i][j];
2734 vat_json_object_add_ip6(counter, "address", c6->address);
2735 vat_json_object_add_uint(counter, "address_length", c6->address_length);
2736 vat_json_object_add_uint(counter, "packets", c6->packets);
2737 vat_json_object_add_uint(counter, "bytes", c6->bytes);
2741 vat_json_print(vam->ofp, &node);
2742 vat_json_free(&node);
2747 int exec (vat_main_t * vam)
2749 api_main_t * am = &api_main;
2750 vl_api_cli_request_t *mp;
2754 unformat_input_t * i = vam->input;
2756 if (vec_len(i->buffer) == 0)
2759 if (vam->exec_mode == 0 && unformat (i, "mode")) {
2763 if (vam->exec_mode == 1 &&
2764 (unformat (i, "exit") || unformat (i, "quit"))) {
2770 M(CLI_REQUEST, cli_request);
2773 * Copy cmd into shared memory.
2774 * In order for the CLI command to work, it
2775 * must be a vector ending in \n, not a C-string ending
2778 pthread_mutex_lock (&am->vlib_rp->mutex);
2779 oldheap = svm_push_data_heap (am->vlib_rp);
2781 vec_validate (cmd, vec_len(vam->input->buffer)-1);
2782 clib_memcpy (cmd, vam->input->buffer, vec_len(vam->input->buffer));
2784 svm_pop_heap (oldheap);
2785 pthread_mutex_unlock (&am->vlib_rp->mutex);
2787 mp->cmd_in_shmem = (u64) cmd;
2789 timeout = vat_time_now (vam) + 10.0;
2791 while (vat_time_now (vam) < timeout) {
2792 if (vam->result_ready == 1) {
2794 if (vam->shmem_result != NULL)
2795 fformat (vam->ofp, "%s", vam->shmem_result);
2796 pthread_mutex_lock (&am->vlib_rp->mutex);
2797 oldheap = svm_push_data_heap (am->vlib_rp);
2799 free_me = (u8 *)vam->shmem_result;
2802 svm_pop_heap (oldheap);
2803 pthread_mutex_unlock (&am->vlib_rp->mutex);
2810 static int api_create_loopback (vat_main_t * vam)
2812 unformat_input_t * i = vam->input;
2813 vl_api_create_loopback_t *mp;
2818 memset (mac_address, 0, sizeof (mac_address));
2820 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
2822 if (unformat (i, "mac %U", unformat_ethernet_address, mac_address))
2828 /* Construct the API message */
2829 M(CREATE_LOOPBACK, create_loopback);
2831 clib_memcpy (mp->mac_address, mac_address, sizeof (mac_address));
2836 static int api_delete_loopback (vat_main_t * vam)
2838 unformat_input_t * i = vam->input;
2839 vl_api_delete_loopback_t *mp;
2841 u32 sw_if_index = ~0;
2843 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
2845 if (unformat (i, "sw_if_index %d", &sw_if_index))
2851 if (sw_if_index == ~0)
2853 errmsg ("missing sw_if_index\n");
2857 /* Construct the API message */
2858 M(DELETE_LOOPBACK, delete_loopback);
2859 mp->sw_if_index = ntohl (sw_if_index);
2864 static int api_want_stats (vat_main_t * vam)
2866 unformat_input_t * i = vam->input;
2867 vl_api_want_stats_t * mp;
2871 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
2873 if (unformat (i, "enable"))
2875 else if (unformat (i, "disable"))
2883 errmsg ("missing enable|disable\n");
2887 M(WANT_STATS, want_stats);
2888 mp->enable_disable = enable;
2893 static int api_want_interface_events (vat_main_t * vam)
2895 unformat_input_t * i = vam->input;
2896 vl_api_want_interface_events_t * mp;
2900 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
2902 if (unformat (i, "enable"))
2904 else if (unformat (i, "disable"))
2912 errmsg ("missing enable|disable\n");
2916 M(WANT_INTERFACE_EVENTS, want_interface_events);
2917 mp->enable_disable = enable;
2919 vam->interface_event_display = enable;
2925 /* Note: non-static, called once to set up the initial intfc table */
2926 int api_sw_interface_dump (vat_main_t * vam)
2928 vl_api_sw_interface_dump_t *mp;
2931 name_sort_t * nses = 0, * ns;
2932 sw_interface_subif_t * sub = NULL;
2934 /* Toss the old name table */
2935 hash_foreach_pair (p, vam->sw_if_index_by_interface_name,
2937 vec_add2 (nses, ns, 1);
2938 ns->name = (u8 *)(p->key);
2939 ns->value = (u32) p->value[0];
2942 hash_free (vam->sw_if_index_by_interface_name);
2944 vec_foreach (ns, nses)
2945 vec_free (ns->name);
2949 vec_foreach (sub, vam->sw_if_subif_table) {
2950 vec_free (sub->interface_name);
2952 vec_free (vam->sw_if_subif_table);
2954 /* recreate the interface name hash table */
2955 vam->sw_if_index_by_interface_name
2956 = hash_create_string (0, sizeof(uword));
2958 /* Get list of ethernets */
2959 M(SW_INTERFACE_DUMP, sw_interface_dump);
2960 mp->name_filter_valid = 1;
2961 strncpy ((char *) mp->name_filter, "Ether", sizeof(mp->name_filter)-1);
2964 /* and local / loopback interfaces */
2965 M(SW_INTERFACE_DUMP, sw_interface_dump);
2966 mp->name_filter_valid = 1;
2967 strncpy ((char *) mp->name_filter, "lo", sizeof(mp->name_filter)-1);
2970 /* and vxlan tunnel interfaces */
2971 M(SW_INTERFACE_DUMP, sw_interface_dump);
2972 mp->name_filter_valid = 1;
2973 strncpy ((char *) mp->name_filter, "vxlan", sizeof(mp->name_filter)-1);
2976 /* and host (af_packet) interfaces */
2977 M(SW_INTERFACE_DUMP, sw_interface_dump);
2978 mp->name_filter_valid = 1;
2979 strncpy ((char *) mp->name_filter, "host", sizeof(mp->name_filter)-1);
2982 /* and l2tpv3 tunnel interfaces */
2983 M(SW_INTERFACE_DUMP, sw_interface_dump);
2984 mp->name_filter_valid = 1;
2985 strncpy ((char *) mp->name_filter, "l2tpv3_tunnel", sizeof(mp->name_filter)-1);
2988 /* and GRE tunnel interfaces */
2989 M(SW_INTERFACE_DUMP, sw_interface_dump);
2990 mp->name_filter_valid = 1;
2991 strncpy ((char *) mp->name_filter, "gre", sizeof(mp->name_filter)-1);
2994 /* Use a control ping for synchronization */
2996 vl_api_control_ping_t * mp;
2997 M(CONTROL_PING, control_ping);
3003 static int api_sw_interface_set_flags (vat_main_t * vam)
3005 unformat_input_t * i = vam->input;
3006 vl_api_sw_interface_set_flags_t *mp;
3009 u8 sw_if_index_set = 0;
3010 u8 admin_up = 0, link_up = 0;
3012 /* Parse args required to build the message */
3013 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
3014 if (unformat (i, "admin-up"))
3016 else if (unformat (i, "admin-down"))
3018 else if (unformat (i, "link-up"))
3020 else if (unformat (i, "link-down"))
3022 else if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
3023 sw_if_index_set = 1;
3024 else if (unformat (i, "sw_if_index %d", &sw_if_index))
3025 sw_if_index_set = 1;
3030 if (sw_if_index_set == 0) {
3031 errmsg ("missing interface name or sw_if_index\n");
3035 /* Construct the API message */
3036 M(SW_INTERFACE_SET_FLAGS, sw_interface_set_flags);
3037 mp->sw_if_index = ntohl (sw_if_index);
3038 mp->admin_up_down = admin_up;
3039 mp->link_up_down = link_up;
3044 /* Wait for a reply, return the good/bad news... */
3048 static int api_sw_interface_clear_stats (vat_main_t * vam)
3050 unformat_input_t * i = vam->input;
3051 vl_api_sw_interface_clear_stats_t *mp;
3054 u8 sw_if_index_set = 0;
3056 /* Parse args required to build the message */
3057 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
3058 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
3059 sw_if_index_set = 1;
3060 else if (unformat (i, "sw_if_index %d", &sw_if_index))
3061 sw_if_index_set = 1;
3066 /* Construct the API message */
3067 M(SW_INTERFACE_CLEAR_STATS, sw_interface_clear_stats);
3069 if (sw_if_index_set == 1)
3070 mp->sw_if_index = ntohl (sw_if_index);
3072 mp->sw_if_index = ~0;
3077 /* Wait for a reply, return the good/bad news... */
3081 static int api_sw_interface_add_del_address (vat_main_t * vam)
3083 unformat_input_t * i = vam->input;
3084 vl_api_sw_interface_add_del_address_t *mp;
3087 u8 sw_if_index_set = 0;
3088 u8 is_add = 1, del_all = 0;
3089 u32 address_length = 0;
3090 u8 v4_address_set = 0;
3091 u8 v6_address_set = 0;
3092 ip4_address_t v4address;
3093 ip6_address_t v6address;
3095 /* Parse args required to build the message */
3096 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
3097 if (unformat (i, "del-all"))
3099 else if (unformat (i, "del"))
3101 else if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
3102 sw_if_index_set = 1;
3103 else if (unformat (i, "sw_if_index %d", &sw_if_index))
3104 sw_if_index_set = 1;
3105 else if (unformat (i, "%U/%d",
3106 unformat_ip4_address, &v4address,
3109 else if (unformat (i, "%U/%d",
3110 unformat_ip6_address, &v6address,
3117 if (sw_if_index_set == 0) {
3118 errmsg ("missing interface name or sw_if_index\n");
3121 if (v4_address_set && v6_address_set) {
3122 errmsg ("both v4 and v6 addresses set\n");
3125 if (!v4_address_set && !v6_address_set && !del_all) {
3126 errmsg ("no addresses set\n");
3130 /* Construct the API message */
3131 M(SW_INTERFACE_ADD_DEL_ADDRESS, sw_interface_add_del_address);
3133 mp->sw_if_index = ntohl (sw_if_index);
3134 mp->is_add = is_add;
3135 mp->del_all = del_all;
3136 if (v6_address_set) {
3138 clib_memcpy (mp->address, &v6address, sizeof (v6address));
3140 clib_memcpy (mp->address, &v4address, sizeof (v4address));
3142 mp->address_length = address_length;
3147 /* Wait for a reply, return good/bad news */
3151 static int api_sw_interface_set_table (vat_main_t * vam)
3153 unformat_input_t * i = vam->input;
3154 vl_api_sw_interface_set_table_t *mp;
3156 u32 sw_if_index, vrf_id = 0;
3157 u8 sw_if_index_set = 0;
3160 /* Parse args required to build the message */
3161 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
3162 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
3163 sw_if_index_set = 1;
3164 else if (unformat (i, "sw_if_index %d", &sw_if_index))
3165 sw_if_index_set = 1;
3166 else if (unformat (i, "vrf %d", &vrf_id))
3168 else if (unformat (i, "ipv6"))
3174 if (sw_if_index_set == 0) {
3175 errmsg ("missing interface name or sw_if_index\n");
3179 /* Construct the API message */
3180 M(SW_INTERFACE_SET_TABLE, sw_interface_set_table);
3182 mp->sw_if_index = ntohl (sw_if_index);
3183 mp->is_ipv6 = is_ipv6;
3184 mp->vrf_id = ntohl (vrf_id);
3189 /* Wait for a reply... */
3193 static int api_sw_interface_set_vpath (vat_main_t * vam)
3195 unformat_input_t * i = vam->input;
3196 vl_api_sw_interface_set_vpath_t *mp;
3198 u32 sw_if_index = 0;
3199 u8 sw_if_index_set = 0;
3202 /* Parse args required to build the message */
3203 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
3204 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
3205 sw_if_index_set = 1;
3206 else if (unformat (i, "sw_if_index %d", &sw_if_index))
3207 sw_if_index_set = 1;
3208 else if (unformat (i, "enable"))
3210 else if (unformat (i, "disable"))
3216 if (sw_if_index_set == 0) {
3217 errmsg ("missing interface name or sw_if_index\n");
3221 /* Construct the API message */
3222 M(SW_INTERFACE_SET_VPATH, sw_interface_set_vpath);
3224 mp->sw_if_index = ntohl (sw_if_index);
3225 mp->enable = is_enable;
3230 /* Wait for a reply... */
3234 static int api_sw_interface_set_l2_xconnect (vat_main_t * vam)
3236 unformat_input_t * i = vam->input;
3237 vl_api_sw_interface_set_l2_xconnect_t *mp;
3240 u8 rx_sw_if_index_set = 0;
3242 u8 tx_sw_if_index_set = 0;
3245 /* Parse args required to build the message */
3246 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
3247 if (unformat (i, "rx_sw_if_index %d", &rx_sw_if_index))
3248 rx_sw_if_index_set = 1;
3249 else if (unformat (i, "tx_sw_if_index %d", &tx_sw_if_index))
3250 tx_sw_if_index_set = 1;
3251 else if (unformat (i, "rx")) {
3252 if (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
3253 if (unformat (i, "%U", unformat_sw_if_index, vam,
3255 rx_sw_if_index_set = 1;
3258 } else if (unformat (i, "tx")) {
3259 if (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
3260 if (unformat (i, "%U", unformat_sw_if_index, vam,
3262 tx_sw_if_index_set = 1;
3265 } else if (unformat (i, "enable"))
3267 else if (unformat (i, "disable"))
3273 if (rx_sw_if_index_set == 0) {
3274 errmsg ("missing rx interface name or rx_sw_if_index\n");
3278 if (enable && (tx_sw_if_index_set == 0)) {
3279 errmsg ("missing tx interface name or tx_sw_if_index\n");
3283 M(SW_INTERFACE_SET_L2_XCONNECT, sw_interface_set_l2_xconnect);
3285 mp->rx_sw_if_index = ntohl(rx_sw_if_index);
3286 mp->tx_sw_if_index = ntohl(tx_sw_if_index);
3287 mp->enable = enable;
3294 static int api_sw_interface_set_l2_bridge (vat_main_t * vam)
3296 unformat_input_t * i = vam->input;
3297 vl_api_sw_interface_set_l2_bridge_t *mp;
3300 u8 rx_sw_if_index_set = 0;
3307 /* Parse args required to build the message */
3308 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
3309 if (unformat (i, "sw_if_index %d", &rx_sw_if_index))
3310 rx_sw_if_index_set = 1;
3311 else if (unformat (i, "bd_id %d", &bd_id))
3313 else if (unformat (i, "%U", unformat_sw_if_index, vam,
3315 rx_sw_if_index_set = 1;
3316 else if (unformat (i, "shg %d", &shg))
3318 else if (unformat (i, "bvi"))
3320 else if (unformat (i, "enable"))
3322 else if (unformat (i, "disable"))
3328 if (rx_sw_if_index_set == 0) {
3329 errmsg ("missing rx interface name or sw_if_index\n");
3333 if (enable && (bd_id_set == 0)) {
3334 errmsg ("missing bridge domain\n");
3338 M(SW_INTERFACE_SET_L2_BRIDGE, sw_interface_set_l2_bridge);
3340 mp->rx_sw_if_index = ntohl(rx_sw_if_index);
3341 mp->bd_id = ntohl(bd_id);
3344 mp->enable = enable;
3351 static int api_bridge_domain_dump (vat_main_t * vam)
3353 unformat_input_t * i = vam->input;
3354 vl_api_bridge_domain_dump_t *mp;
3358 /* Parse args required to build the message */
3359 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
3360 if (unformat (i, "bd_id %d", &bd_id))
3366 M(BRIDGE_DOMAIN_DUMP, bridge_domain_dump);
3367 mp->bd_id = ntohl(bd_id);
3370 /* Use a control ping for synchronization */
3372 vl_api_control_ping_t * mp;
3373 M(CONTROL_PING, control_ping);
3382 static int api_bridge_domain_add_del (vat_main_t * vam)
3384 unformat_input_t * i = vam->input;
3385 vl_api_bridge_domain_add_del_t *mp;
3389 u32 flood = 1, forward = 1, learn = 1, uu_flood = 1, arp_term = 0;
3391 /* Parse args required to build the message */
3392 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
3393 if (unformat (i, "bd_id %d", &bd_id))
3395 else if (unformat (i, "flood %d", &flood))
3397 else if (unformat (i, "uu-flood %d", &uu_flood))
3399 else if (unformat (i, "forward %d", &forward))
3401 else if (unformat (i, "learn %d", &learn))
3403 else if (unformat (i, "arp-term %d", &arp_term))
3405 else if (unformat (i, "del")) {
3407 flood = uu_flood = forward = learn = 0;
3414 errmsg ("missing bridge domain\n");
3418 M(BRIDGE_DOMAIN_ADD_DEL, bridge_domain_add_del);
3420 mp->bd_id = ntohl(bd_id);
3422 mp->uu_flood = uu_flood;
3423 mp->forward = forward;
3425 mp->arp_term = arp_term;
3426 mp->is_add = is_add;
3433 static int api_l2fib_add_del (vat_main_t * vam)
3435 unformat_input_t * i = vam->input;
3436 vl_api_l2fib_add_del_t *mp;
3443 u8 sw_if_index_set = 0;
3448 /* Parse args required to build the message */
3449 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
3450 if (unformat (i, "mac %U", unformat_ethernet_address, &mac))
3452 else if (unformat (i, "bd_id %d", &bd_id))
3454 else if (unformat (i, "sw_if_index %d", &sw_if_index))
3455 sw_if_index_set = 1;
3456 else if (unformat (i, "sw_if")) {
3457 if (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
3458 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
3459 sw_if_index_set = 1;
3462 } else if (unformat (i, "static"))
3464 else if (unformat (i, "filter")) {
3467 } else if (unformat (i, "del"))
3474 errmsg ("missing mac address\n");
3478 if (bd_id_set == 0) {
3479 errmsg ("missing bridge domain\n");
3483 if (is_add && (sw_if_index_set == 0)) {
3484 errmsg ("missing interface name or sw_if_index\n");
3488 M(L2FIB_ADD_DEL, l2fib_add_del);
3491 mp->bd_id = ntohl(bd_id);
3492 mp->is_add = is_add;
3495 mp->sw_if_index = ntohl(sw_if_index);
3496 mp->static_mac = static_mac;
3497 mp->filter_mac = filter_mac;
3505 static int api_l2_flags (vat_main_t * vam)
3507 unformat_input_t * i = vam->input;
3508 vl_api_l2_flags_t *mp;
3511 u32 feature_bitmap = 0;
3512 u8 sw_if_index_set = 0;
3514 /* Parse args required to build the message */
3515 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
3516 if (unformat (i, "sw_if_index %d", &sw_if_index))
3517 sw_if_index_set = 1;
3518 else if (unformat (i, "sw_if")) {
3519 if (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
3520 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
3521 sw_if_index_set = 1;
3524 } else if (unformat (i, "learn"))
3525 feature_bitmap |= L2INPUT_FEAT_LEARN;
3526 else if (unformat (i, "forward"))
3527 feature_bitmap |= L2INPUT_FEAT_FWD;
3528 else if (unformat (i, "flood"))
3529 feature_bitmap |= L2INPUT_FEAT_FLOOD;
3530 else if (unformat (i, "uu-flood"))
3531 feature_bitmap |= L2INPUT_FEAT_UU_FLOOD;
3536 if (sw_if_index_set == 0) {
3537 errmsg ("missing interface name or sw_if_index\n");
3541 M(L2_FLAGS, l2_flags);
3543 mp->sw_if_index = ntohl(sw_if_index);
3544 mp->feature_bitmap = ntohl(feature_bitmap);
3551 static int api_bridge_flags (vat_main_t * vam)
3553 unformat_input_t * i = vam->input;
3554 vl_api_bridge_flags_t *mp;
3561 /* Parse args required to build the message */
3562 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
3563 if (unformat (i, "bd_id %d", &bd_id))
3565 else if (unformat (i, "learn"))
3567 else if (unformat (i, "forward"))
3569 else if (unformat (i, "flood"))
3571 else if (unformat (i, "uu-flood"))
3572 flags |= L2_UU_FLOOD;
3573 else if (unformat (i, "arp-term"))
3574 flags |= L2_ARP_TERM;
3575 else if (unformat (i, "off"))
3577 else if (unformat (i, "disable"))
3583 if (bd_id_set == 0) {
3584 errmsg ("missing bridge domain\n");
3588 M(BRIDGE_FLAGS, bridge_flags);
3590 mp->bd_id = ntohl(bd_id);
3591 mp->feature_bitmap = ntohl(flags);
3592 mp->is_set = is_set;
3599 static int api_bd_ip_mac_add_del (vat_main_t * vam)
3601 unformat_input_t * i = vam->input;
3602 vl_api_bd_ip_mac_add_del_t *mp;
3610 ip4_address_t v4addr;
3611 ip6_address_t v6addr;
3615 /* Parse args required to build the message */
3616 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
3617 if (unformat (i, "bd_id %d", &bd_id)) {
3619 } else if (unformat (i, "%U", unformat_ip4_address, &v4addr)) {
3621 } else if (unformat (i, "%U", unformat_ip6_address, &v6addr)) {
3624 } else if (unformat (i, "%U", unformat_ethernet_address, macaddr)) {
3626 } else if (unformat (i, "del"))
3632 if (bd_id_set == 0) {
3633 errmsg ("missing bridge domain\n");
3635 } else if (ip_set == 0) {
3636 errmsg ("missing IP address\n");
3638 } else if (mac_set == 0) {
3639 errmsg ("missing MAC address\n");
3643 M(BD_IP_MAC_ADD_DEL, bd_ip_mac_add_del);
3645 mp->bd_id = ntohl(bd_id);
3646 mp->is_ipv6 = is_ipv6;
3647 mp->is_add = is_add;
3649 clib_memcpy (mp->ip_address, &v6addr, sizeof (v6addr));
3650 else clib_memcpy (mp->ip_address, &v4addr, sizeof (v4addr));
3651 clib_memcpy (mp->mac_address, macaddr, 6);
3657 static int api_tap_connect (vat_main_t * vam)
3659 unformat_input_t * i = vam->input;
3660 vl_api_tap_connect_t *mp;
3667 memset (mac_address, 0, sizeof (mac_address));
3669 /* Parse args required to build the message */
3670 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
3671 if (unformat (i, "mac %U", unformat_ethernet_address, mac_address)) {
3674 else if (unformat (i, "random-mac"))
3676 else if (unformat (i, "tapname %s", &tap_name))
3682 if (name_set == 0) {
3683 errmsg ("missing tap name\n");
3686 if (vec_len (tap_name) > 63) {
3687 errmsg ("tap name too long\n");
3689 vec_add1 (tap_name, 0);
3691 /* Construct the API message */
3692 M(TAP_CONNECT, tap_connect);
3694 mp->use_random_mac = random_mac;
3695 clib_memcpy (mp->mac_address, mac_address, 6);
3696 clib_memcpy (mp->tap_name, tap_name, vec_len (tap_name));
3697 vec_free (tap_name);
3702 /* Wait for a reply... */
3706 static int api_tap_modify (vat_main_t * vam)
3708 unformat_input_t * i = vam->input;
3709 vl_api_tap_modify_t *mp;
3715 u32 sw_if_index = ~0;
3716 u8 sw_if_index_set = 0;
3718 memset (mac_address, 0, sizeof (mac_address));
3720 /* Parse args required to build the message */
3721 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
3722 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
3723 sw_if_index_set = 1;
3724 else if (unformat (i, "sw_if_index %d", &sw_if_index))
3725 sw_if_index_set = 1;
3726 else if (unformat (i, "mac %U", unformat_ethernet_address, mac_address)) {
3729 else if (unformat (i, "random-mac"))
3731 else if (unformat (i, "tapname %s", &tap_name))
3737 if (sw_if_index_set == 0) {
3738 errmsg ("missing vpp interface name");
3741 if (name_set == 0) {
3742 errmsg ("missing tap name\n");
3745 if (vec_len (tap_name) > 63) {
3746 errmsg ("tap name too long\n");
3748 vec_add1 (tap_name, 0);
3750 /* Construct the API message */
3751 M(TAP_MODIFY, tap_modify);
3753 mp->use_random_mac = random_mac;
3754 mp->sw_if_index = ntohl(sw_if_index);
3755 clib_memcpy (mp->mac_address, mac_address, 6);
3756 clib_memcpy (mp->tap_name, tap_name, vec_len (tap_name));
3757 vec_free (tap_name);
3762 /* Wait for a reply... */
3766 static int api_tap_delete (vat_main_t * vam)
3768 unformat_input_t * i = vam->input;
3769 vl_api_tap_delete_t *mp;
3771 u32 sw_if_index = ~0;
3772 u8 sw_if_index_set = 0;
3774 /* Parse args required to build the message */
3775 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
3776 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
3777 sw_if_index_set = 1;
3778 else if (unformat (i, "sw_if_index %d", &sw_if_index))
3779 sw_if_index_set = 1;
3784 if (sw_if_index_set == 0) {
3785 errmsg ("missing vpp interface name");
3789 /* Construct the API message */
3790 M(TAP_DELETE, tap_delete);
3792 mp->sw_if_index = ntohl(sw_if_index);
3797 /* Wait for a reply... */
3801 static int api_ip_add_del_route (vat_main_t * vam)
3803 unformat_input_t * i = vam->input;
3804 vl_api_ip_add_del_route_t *mp;
3806 u32 sw_if_index = 0, vrf_id = 0;
3807 u8 sw_if_index_set = 0;
3809 u8 is_local = 0, is_drop = 0;
3810 u8 create_vrf_if_needed = 0;
3812 u8 next_hop_weight = 1;
3814 u8 is_multipath = 0;
3816 u8 address_length_set = 0;
3817 u32 lookup_in_vrf = 0;
3818 u32 resolve_attempts = 0;
3819 u32 dst_address_length = 0;
3820 u8 next_hop_set = 0;
3821 ip4_address_t v4_dst_address, v4_next_hop_address;
3822 ip6_address_t v6_dst_address, v6_next_hop_address;
3826 u32 random_add_del = 0;
3827 u32 * random_vector = 0;
3828 uword * random_hash;
3829 u32 random_seed = 0xdeaddabe;
3830 u32 classify_table_index = ~0;
3833 /* Parse args required to build the message */
3834 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
3835 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
3836 sw_if_index_set = 1;
3837 else if (unformat (i, "sw_if_index %d", &sw_if_index))
3838 sw_if_index_set = 1;
3839 else if (unformat (i, "%U", unformat_ip4_address,
3844 else if (unformat (i, "%U", unformat_ip6_address, &v6_dst_address)) {
3848 else if (unformat (i, "/%d", &dst_address_length)) {
3849 address_length_set = 1;
3852 else if (is_ipv6 == 0 && unformat (i, "via %U", unformat_ip4_address,
3853 &v4_next_hop_address)) {
3856 else if (is_ipv6 == 1 && unformat (i, "via %U", unformat_ip6_address,
3857 &v6_next_hop_address)) {
3860 else if (unformat (i, "resolve-attempts %d", &resolve_attempts))
3862 else if (unformat (i, "weight %d", &next_hop_weight))
3864 else if (unformat (i, "drop")) {
3866 } else if (unformat (i, "local")) {
3868 } else if (unformat (i, "classify %d", &classify_table_index)) {
3870 } else if (unformat (i, "del"))
3872 else if (unformat (i, "add"))
3874 else if (unformat (i, "not-last"))
3876 else if (unformat (i, "multipath"))
3878 else if (unformat (i, "vrf %d", &vrf_id))
3880 else if (unformat (i, "create-vrf"))
3881 create_vrf_if_needed = 1;
3882 else if (unformat (i, "count %d", &count))
3884 else if (unformat (i, "lookup-in-vrf %d", &lookup_in_vrf))
3886 else if (unformat (i, "random"))
3888 else if (unformat (i, "seed %d", &random_seed))
3891 clib_warning ("parse error '%U'", format_unformat_error, i);
3896 if (resolve_attempts > 0 && sw_if_index_set == 0) {
3897 errmsg ("ARP resolution needs explicit interface or sw_if_index\n");
3901 if (!next_hop_set && !is_drop && !is_local && !is_classify) {
3902 errmsg ("next hop / local / drop / classify not set\n");
3906 if (address_set == 0) {
3907 errmsg ("missing addresses\n");
3911 if (address_length_set == 0) {
3912 errmsg ("missing address length\n");
3916 /* Generate a pile of unique, random routes */
3917 if (random_add_del) {
3918 u32 this_random_address;
3919 random_hash = hash_create (count, sizeof(uword));
3921 hash_set (random_hash, v4_next_hop_address.as_u32, 1);
3922 for (j = 0; j <= count; j++) {
3924 this_random_address = random_u32 (&random_seed);
3925 this_random_address =
3926 clib_host_to_net_u32 (this_random_address);
3927 } while (hash_get (random_hash, this_random_address));
3928 vec_add1 (random_vector, this_random_address);
3929 hash_set (random_hash, this_random_address, 1);
3931 hash_free (random_hash);
3932 v4_dst_address.as_u32 = random_vector[0];
3936 /* Turn on async mode */
3937 vam->async_mode = 1;
3938 vam->async_errors = 0;
3939 before = vat_time_now(vam);
3942 for (j = 0; j < count; j++) {
3943 /* Construct the API message */
3944 M(IP_ADD_DEL_ROUTE, ip_add_del_route);
3946 mp->next_hop_sw_if_index = ntohl (sw_if_index);
3947 mp->vrf_id = ntohl (vrf_id);
3948 if (resolve_attempts > 0) {
3949 mp->resolve_attempts = ntohl (resolve_attempts);
3950 mp->resolve_if_needed = 1;
3952 mp->create_vrf_if_needed = create_vrf_if_needed;
3954 mp->is_add = is_add;
3955 mp->is_drop = is_drop;
3956 mp->is_ipv6 = is_ipv6;
3957 mp->is_local = is_local;
3958 mp->is_classify = is_classify;
3959 mp->is_multipath = is_multipath;
3960 mp->not_last = not_last;
3961 mp->next_hop_weight = next_hop_weight;
3962 mp->dst_address_length = dst_address_length;
3963 mp->lookup_in_vrf = ntohl(lookup_in_vrf);
3964 mp->classify_table_index = ntohl(classify_table_index);
3967 clib_memcpy (mp->dst_address, &v6_dst_address, sizeof (v6_dst_address));
3969 clib_memcpy (mp->next_hop_address, &v6_next_hop_address,
3970 sizeof (v6_next_hop_address));
3971 increment_v6_address (&v6_dst_address);
3973 clib_memcpy (mp->dst_address, &v4_dst_address, sizeof (v4_dst_address));
3975 clib_memcpy (mp->next_hop_address, &v4_next_hop_address,
3976 sizeof (v4_next_hop_address));
3978 v4_dst_address.as_u32 = random_vector[j+1];
3980 increment_v4_address (&v4_dst_address);
3986 /* When testing multiple add/del ops, use a control-ping to sync */
3988 vl_api_control_ping_t * mp;
3991 /* Shut off async mode */
3992 vam->async_mode = 0;
3994 M(CONTROL_PING, control_ping);
3997 timeout = vat_time_now(vam) + 1.0;
3998 while (vat_time_now (vam) < timeout)
3999 if (vam->result_ready == 1)
4004 if (vam->retval == -99)
4005 errmsg ("timeout\n");
4007 if (vam->async_errors > 0) {
4008 errmsg ("%d asynchronous errors\n", vam->async_errors);
4011 vam->async_errors = 0;
4012 after = vat_time_now(vam);
4014 fformat(vam->ofp, "%d routes in %.6f secs, %.2f routes/sec\n",
4015 count, after - before, count / (after - before));
4017 /* Wait for a reply... */
4021 /* Return the good/bad news */
4022 return (vam->retval);
4025 static int api_proxy_arp_add_del (vat_main_t * vam)
4027 unformat_input_t * i = vam->input;
4028 vl_api_proxy_arp_add_del_t *mp;
4032 ip4_address_t lo, hi;
4035 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
4036 if (unformat (i, "vrf %d", &vrf_id))
4038 else if (unformat (i, "%U - %U", unformat_ip4_address, &lo,
4039 unformat_ip4_address, &hi))
4041 else if (unformat (i, "del"))
4044 clib_warning ("parse error '%U'", format_unformat_error, i);
4049 if (range_set == 0) {
4050 errmsg ("address range not set\n");
4054 M(PROXY_ARP_ADD_DEL, proxy_arp_add_del);
4056 mp->vrf_id = ntohl(vrf_id);
4057 mp->is_add = is_add;
4058 clib_memcpy(mp->low_address, &lo, sizeof (mp->low_address));
4059 clib_memcpy(mp->hi_address, &hi, sizeof (mp->hi_address));
4066 static int api_proxy_arp_intfc_enable_disable (vat_main_t * vam)
4068 unformat_input_t * i = vam->input;
4069 vl_api_proxy_arp_intfc_enable_disable_t *mp;
4073 u8 sw_if_index_set = 0;
4075 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
4076 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
4077 sw_if_index_set = 1;
4078 else if (unformat (i, "sw_if_index %d", &sw_if_index))
4079 sw_if_index_set = 1;
4080 else if (unformat (i, "enable"))
4082 else if (unformat (i, "disable"))
4085 clib_warning ("parse error '%U'", format_unformat_error, i);
4090 if (sw_if_index_set == 0) {
4091 errmsg ("missing interface name or sw_if_index\n");
4095 M(PROXY_ARP_INTFC_ENABLE_DISABLE, proxy_arp_intfc_enable_disable);
4097 mp->sw_if_index = ntohl(sw_if_index);
4098 mp->enable_disable = enable;
4105 static int api_mpls_add_del_decap (vat_main_t * vam)
4107 unformat_input_t * i = vam->input;
4108 vl_api_mpls_add_del_decap_t *mp;
4117 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
4118 if (unformat (i, "rx_vrf_id %d", &rx_vrf_id))
4120 else if (unformat (i, "tx_vrf_id %d", &tx_vrf_id))
4122 else if (unformat (i, "label %d", &label))
4124 else if (unformat (i, "next-index %d", &next_index))
4126 else if (unformat (i, "del"))
4128 else if (unformat (i, "s-bit-clear"))
4131 clib_warning ("parse error '%U'", format_unformat_error, i);
4136 M(MPLS_ADD_DEL_DECAP, mpls_add_del_decap);
4138 mp->rx_vrf_id = ntohl(rx_vrf_id);
4139 mp->tx_vrf_id = ntohl(tx_vrf_id);
4140 mp->label = ntohl(label);
4141 mp->next_index = ntohl(next_index);
4143 mp->is_add = is_add;
4150 static int api_mpls_add_del_encap (vat_main_t * vam)
4152 unformat_input_t * i = vam->input;
4153 vl_api_mpls_add_del_encap_t *mp;
4158 ip4_address_t dst_address;
4161 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
4162 if (unformat (i, "vrf %d", &vrf_id))
4164 else if (unformat (i, "label %d", &label))
4165 vec_add1 (labels, ntohl(label));
4166 else if (unformat (i, "dst %U", unformat_ip4_address, &dst_address))
4168 else if (unformat (i, "del"))
4171 clib_warning ("parse error '%U'", format_unformat_error, i);
4176 if (vec_len (labels) == 0) {
4177 errmsg ("missing encap label stack\n");
4181 M2(MPLS_ADD_DEL_ENCAP, mpls_add_del_encap,
4182 sizeof (u32) * vec_len (labels));
4184 mp->vrf_id = ntohl(vrf_id);
4185 clib_memcpy(mp->dst_address, &dst_address, sizeof (dst_address));
4186 mp->is_add = is_add;
4187 mp->nlabels = vec_len (labels);
4188 clib_memcpy(mp->labels, labels, sizeof(u32)*mp->nlabels);
4197 static int api_mpls_gre_add_del_tunnel (vat_main_t * vam)
4199 unformat_input_t * i = vam->input;
4200 vl_api_mpls_gre_add_del_tunnel_t *mp;
4202 u32 inner_vrf_id = 0;
4203 u32 outer_vrf_id = 0;
4204 ip4_address_t src_address;
4205 ip4_address_t dst_address;
4206 ip4_address_t intfc_address;
4208 u8 intfc_address_length = 0;
4212 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
4213 if (unformat (i, "inner_vrf_id %d", &inner_vrf_id))
4215 else if (unformat (i, "outer_vrf_id %d", &outer_vrf_id))
4217 else if (unformat (i, "src %U", unformat_ip4_address, &src_address))
4219 else if (unformat (i, "dst %U", unformat_ip4_address, &dst_address))
4221 else if (unformat (i, "adj %U/%d", unformat_ip4_address,
4222 &intfc_address, &tmp))
4223 intfc_address_length = tmp;
4224 else if (unformat (i, "l2-only"))
4226 else if (unformat (i, "del"))
4229 clib_warning ("parse error '%U'", format_unformat_error, i);
4234 M(MPLS_GRE_ADD_DEL_TUNNEL, mpls_gre_add_del_tunnel);
4236 mp->inner_vrf_id = ntohl(inner_vrf_id);
4237 mp->outer_vrf_id = ntohl(outer_vrf_id);
4238 clib_memcpy(mp->src_address, &src_address, sizeof (src_address));
4239 clib_memcpy(mp->dst_address, &dst_address, sizeof (dst_address));
4240 clib_memcpy(mp->intfc_address, &intfc_address, sizeof (intfc_address));
4241 mp->intfc_address_length = intfc_address_length;
4242 mp->l2_only = l2_only;
4243 mp->is_add = is_add;
4250 static int api_mpls_ethernet_add_del_tunnel (vat_main_t * vam)
4252 unformat_input_t * i = vam->input;
4253 vl_api_mpls_ethernet_add_del_tunnel_t *mp;
4255 u32 inner_vrf_id = 0;
4256 ip4_address_t intfc_address;
4257 u8 dst_mac_address[6];
4260 u8 intfc_address_length = 0;
4264 int tx_sw_if_index_set = 0;
4266 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
4267 if (unformat (i, "vrf %d", &inner_vrf_id))
4269 else if (unformat (i, "adj %U/%d", unformat_ip4_address,
4270 &intfc_address, &tmp))
4271 intfc_address_length = tmp;
4272 else if (unformat (i, "%U",
4273 unformat_sw_if_index, vam, &tx_sw_if_index))
4274 tx_sw_if_index_set = 1;
4275 else if (unformat (i, "tx_sw_if_index %d", &tx_sw_if_index))
4276 tx_sw_if_index_set = 1;
4277 else if (unformat (i, "dst %U", unformat_ethernet_address,
4280 else if (unformat (i, "l2-only"))
4282 else if (unformat (i, "del"))
4285 clib_warning ("parse error '%U'", format_unformat_error, i);
4291 errmsg ("dst (mac address) not set\n");
4294 if (!tx_sw_if_index_set) {
4295 errmsg ("tx-intfc not set\n");
4299 M(MPLS_ETHERNET_ADD_DEL_TUNNEL, mpls_ethernet_add_del_tunnel);
4301 mp->vrf_id = ntohl(inner_vrf_id);
4302 clib_memcpy (mp->adj_address, &intfc_address, sizeof (intfc_address));
4303 mp->adj_address_length = intfc_address_length;
4304 clib_memcpy (mp->dst_mac_address, dst_mac_address, sizeof (dst_mac_address));
4305 mp->tx_sw_if_index = ntohl(tx_sw_if_index);
4306 mp->l2_only = l2_only;
4307 mp->is_add = is_add;
4314 static int api_mpls_ethernet_add_del_tunnel_2 (vat_main_t * vam)
4316 unformat_input_t * i = vam->input;
4317 vl_api_mpls_ethernet_add_del_tunnel_2_t *mp;
4319 u32 inner_vrf_id = 0;
4320 u32 outer_vrf_id = 0;
4321 ip4_address_t adj_address;
4322 int adj_address_set = 0;
4323 ip4_address_t next_hop_address;
4324 int next_hop_address_set = 0;
4326 u8 adj_address_length = 0;
4329 u32 resolve_attempts = 5;
4330 u8 resolve_if_needed = 1;
4332 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
4333 if (unformat (i, "inner_vrf_id %d", &inner_vrf_id))
4335 else if (unformat (i, "outer_vrf_id %d", &outer_vrf_id))
4337 else if (unformat (i, "adj %U/%d", unformat_ip4_address,
4338 &adj_address, &tmp)) {
4339 adj_address_length = tmp;
4340 adj_address_set = 1;
4342 else if (unformat (i, "next-hop %U", unformat_ip4_address,
4344 next_hop_address_set = 1;
4345 else if (unformat (i, "resolve-attempts %d", &resolve_attempts))
4347 else if (unformat (i, "resolve-if-needed %d", &tmp))
4348 resolve_if_needed = tmp;
4349 else if (unformat (i, "l2-only"))
4351 else if (unformat (i, "del"))
4354 clib_warning ("parse error '%U'", format_unformat_error, i);
4359 if (!adj_address_set) {
4360 errmsg ("adjacency address/mask not set\n");
4363 if (!next_hop_address_set) {
4364 errmsg ("ip4 next hop address (in outer fib) not set\n");
4368 M(MPLS_ETHERNET_ADD_DEL_TUNNEL_2, mpls_ethernet_add_del_tunnel_2);
4370 mp->inner_vrf_id = ntohl(inner_vrf_id);
4371 mp->outer_vrf_id = ntohl(outer_vrf_id);
4372 mp->resolve_attempts = ntohl(resolve_attempts);
4373 mp->resolve_if_needed = resolve_if_needed;
4374 mp->is_add = is_add;
4375 mp->l2_only = l2_only;
4376 clib_memcpy (mp->adj_address, &adj_address, sizeof (adj_address));
4377 mp->adj_address_length = adj_address_length;
4378 clib_memcpy (mp->next_hop_ip4_address_in_outer_vrf, &next_hop_address,
4379 sizeof (next_hop_address));
4386 static int api_sw_interface_set_unnumbered (vat_main_t * vam)
4388 unformat_input_t * i = vam->input;
4389 vl_api_sw_interface_set_unnumbered_t *mp;
4394 u8 sw_if_index_set = 0;
4396 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
4397 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
4398 sw_if_index_set = 1;
4399 else if (unformat (i, "sw_if_index %d", &sw_if_index))
4400 sw_if_index_set = 1;
4401 else if (unformat (i, "unnum_if_index %d", &unnum_sw_index))
4403 else if (unformat (i, "del"))
4406 clib_warning ("parse error '%U'", format_unformat_error, i);
4411 if (sw_if_index_set == 0) {
4412 errmsg ("missing interface name or sw_if_index\n");
4416 M(SW_INTERFACE_SET_UNNUMBERED, sw_interface_set_unnumbered);
4418 mp->sw_if_index = ntohl(sw_if_index);
4419 mp->unnumbered_sw_if_index = ntohl(unnum_sw_index);
4420 mp->is_add = is_add;
4427 static int api_ip_neighbor_add_del (vat_main_t * vam)
4429 unformat_input_t * i = vam->input;
4430 vl_api_ip_neighbor_add_del_t *mp;
4433 u8 sw_if_index_set = 0;
4439 u8 v4_address_set = 0;
4440 u8 v6_address_set = 0;
4441 ip4_address_t v4address;
4442 ip6_address_t v6address;
4444 memset (mac_address, 0, sizeof (mac_address));
4446 /* Parse args required to build the message */
4447 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
4448 if (unformat (i, "mac %U", unformat_ethernet_address, mac_address)) {
4451 else if (unformat (i, "del"))
4453 else if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
4454 sw_if_index_set = 1;
4455 else if (unformat (i, "sw_if_index %d", &sw_if_index))
4456 sw_if_index_set = 1;
4457 else if (unformat (i, "is_static"))
4459 else if (unformat (i, "vrf %d", &vrf_id))
4461 else if (unformat (i, "dst %U",
4462 unformat_ip4_address, &v4address))
4464 else if (unformat (i, "dst %U",
4465 unformat_ip6_address, &v6address))
4468 clib_warning ("parse error '%U'", format_unformat_error, i);
4473 if (sw_if_index_set == 0) {
4474 errmsg ("missing interface name or sw_if_index\n");
4477 if (v4_address_set && v6_address_set) {
4478 errmsg ("both v4 and v6 addresses set\n");
4481 if (!v4_address_set && !v6_address_set) {
4482 errmsg ("no addresses set\n");
4486 /* Construct the API message */
4487 M(IP_NEIGHBOR_ADD_DEL, ip_neighbor_add_del);
4489 mp->sw_if_index = ntohl (sw_if_index);
4490 mp->is_add = is_add;
4491 mp->vrf_id = ntohl (vrf_id);
4492 mp->is_static = is_static;
4494 clib_memcpy (mp->mac_address, mac_address, 6);
4495 if (v6_address_set) {
4497 clib_memcpy (mp->dst_address, &v6address, sizeof (v6address));
4499 /* mp->is_ipv6 = 0; via memset in M macro above */
4500 clib_memcpy (mp->dst_address, &v4address, sizeof (v4address));
4506 /* Wait for a reply, return good/bad news */
4513 static int api_reset_vrf (vat_main_t * vam)
4515 unformat_input_t * i = vam->input;
4516 vl_api_reset_vrf_t *mp;
4522 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
4523 if (unformat (i, "vrf %d", &vrf_id))
4525 else if (unformat (i, "ipv6"))
4528 clib_warning ("parse error '%U'", format_unformat_error, i);
4533 if (vrf_id_set == 0) {
4534 errmsg ("missing vrf id\n");
4538 M(RESET_VRF, reset_vrf);
4540 mp->vrf_id = ntohl(vrf_id);
4541 mp->is_ipv6 = is_ipv6;
4548 static int api_create_vlan_subif (vat_main_t * vam)
4550 unformat_input_t * i = vam->input;
4551 vl_api_create_vlan_subif_t *mp;
4554 u8 sw_if_index_set = 0;
4558 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
4559 if (unformat (i, "sw_if_index %d", &sw_if_index))
4560 sw_if_index_set = 1;
4561 else if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
4562 sw_if_index_set = 1;
4563 else if (unformat (i, "vlan %d", &vlan_id))
4566 clib_warning ("parse error '%U'", format_unformat_error, i);
4571 if (sw_if_index_set == 0) {
4572 errmsg ("missing interface name or sw_if_index\n");
4576 if (vlan_id_set == 0) {
4577 errmsg ("missing vlan_id\n");
4580 M(CREATE_VLAN_SUBIF, create_vlan_subif);
4582 mp->sw_if_index = ntohl(sw_if_index);
4583 mp->vlan_id = ntohl(vlan_id);
4590 #define foreach_create_subif_bit \
4597 _(outer_vlan_id_any) \
4598 _(inner_vlan_id_any)
4600 static int api_create_subif (vat_main_t * vam)
4602 unformat_input_t * i = vam->input;
4603 vl_api_create_subif_t *mp;
4606 u8 sw_if_index_set = 0;
4613 u32 exact_match = 0;
4614 u32 default_sub = 0;
4615 u32 outer_vlan_id_any = 0;
4616 u32 inner_vlan_id_any = 0;
4618 u16 outer_vlan_id = 0;
4619 u16 inner_vlan_id = 0;
4621 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
4622 if (unformat (i, "sw_if_index %d", &sw_if_index))
4623 sw_if_index_set = 1;
4624 else if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
4625 sw_if_index_set = 1;
4626 else if (unformat (i, "sub_id %d", &sub_id))
4628 else if (unformat (i, "outer_vlan_id %d", &tmp))
4629 outer_vlan_id = tmp;
4630 else if (unformat (i, "inner_vlan_id %d", &tmp))
4631 inner_vlan_id = tmp;
4633 #define _(a) else if (unformat (i, #a)) a = 1 ;
4634 foreach_create_subif_bit
4638 clib_warning ("parse error '%U'", format_unformat_error, i);
4643 if (sw_if_index_set == 0) {
4644 errmsg ("missing interface name or sw_if_index\n");
4648 if (sub_id_set == 0) {
4649 errmsg ("missing sub_id\n");
4652 M(CREATE_SUBIF, create_subif);
4654 mp->sw_if_index = ntohl(sw_if_index);
4655 mp->sub_id = ntohl(sub_id);
4657 #define _(a) mp->a = a;
4658 foreach_create_subif_bit;
4661 mp->outer_vlan_id = ntohs (outer_vlan_id);
4662 mp->inner_vlan_id = ntohs (inner_vlan_id);
4669 static int api_oam_add_del (vat_main_t * vam)
4671 unformat_input_t * i = vam->input;
4672 vl_api_oam_add_del_t *mp;
4676 ip4_address_t src, dst;
4680 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
4681 if (unformat (i, "vrf %d", &vrf_id))
4683 else if (unformat (i, "src %U", unformat_ip4_address, &src))
4685 else if (unformat (i, "dst %U", unformat_ip4_address, &dst))
4687 else if (unformat (i, "del"))
4690 clib_warning ("parse error '%U'", format_unformat_error, i);
4696 errmsg ("missing src addr\n");
4701 errmsg ("missing dst addr\n");
4705 M(OAM_ADD_DEL, oam_add_del);
4707 mp->vrf_id = ntohl(vrf_id);
4708 mp->is_add = is_add;
4709 clib_memcpy(mp->src_address, &src, sizeof (mp->src_address));
4710 clib_memcpy(mp->dst_address, &dst, sizeof (mp->dst_address));
4717 static int api_reset_fib (vat_main_t * vam)
4719 unformat_input_t * i = vam->input;
4720 vl_api_reset_fib_t *mp;
4726 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
4727 if (unformat (i, "vrf %d", &vrf_id))
4729 else if (unformat (i, "ipv6"))
4732 clib_warning ("parse error '%U'", format_unformat_error, i);
4737 if (vrf_id_set == 0) {
4738 errmsg ("missing vrf id\n");
4742 M(RESET_FIB, reset_fib);
4744 mp->vrf_id = ntohl(vrf_id);
4745 mp->is_ipv6 = is_ipv6;
4752 static int api_dhcp_proxy_config (vat_main_t * vam)
4754 unformat_input_t * i = vam->input;
4755 vl_api_dhcp_proxy_config_t *mp;
4760 u8 v4_address_set = 0;
4761 u8 v6_address_set = 0;
4762 ip4_address_t v4address;
4763 ip6_address_t v6address;
4764 u8 v4_src_address_set = 0;
4765 u8 v6_src_address_set = 0;
4766 ip4_address_t v4srcaddress;
4767 ip6_address_t v6srcaddress;
4769 /* Parse args required to build the message */
4770 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
4771 if (unformat (i, "del"))
4773 else if (unformat (i, "vrf %d", &vrf_id))
4775 else if (unformat (i, "insert-cid %d", &insert_cid))
4777 else if (unformat (i, "svr %U",
4778 unformat_ip4_address, &v4address))
4780 else if (unformat (i, "svr %U",
4781 unformat_ip6_address, &v6address))
4783 else if (unformat (i, "src %U",
4784 unformat_ip4_address, &v4srcaddress))
4785 v4_src_address_set = 1;
4786 else if (unformat (i, "src %U",
4787 unformat_ip6_address, &v6srcaddress))
4788 v6_src_address_set = 1;
4793 if (v4_address_set && v6_address_set) {
4794 errmsg ("both v4 and v6 server addresses set\n");
4797 if (!v4_address_set && !v6_address_set) {
4798 errmsg ("no server addresses set\n");
4802 if (v4_src_address_set && v6_src_address_set) {
4803 errmsg ("both v4 and v6 src addresses set\n");
4806 if (!v4_src_address_set && !v6_src_address_set) {
4807 errmsg ("no src addresses set\n");
4811 if (!(v4_src_address_set && v4_address_set) &&
4812 !(v6_src_address_set && v6_address_set)) {
4813 errmsg ("no matching server and src addresses set\n");
4817 /* Construct the API message */
4818 M(DHCP_PROXY_CONFIG, dhcp_proxy_config);
4820 mp->insert_circuit_id = insert_cid;
4821 mp->is_add = is_add;
4822 mp->vrf_id = ntohl (vrf_id);
4823 if (v6_address_set) {
4825 clib_memcpy (mp->dhcp_server, &v6address, sizeof (v6address));
4826 clib_memcpy (mp->dhcp_src_address, &v6srcaddress, sizeof (v6address));
4828 clib_memcpy (mp->dhcp_server, &v4address, sizeof (v4address));
4829 clib_memcpy (mp->dhcp_src_address, &v4srcaddress, sizeof (v4address));
4835 /* Wait for a reply, return good/bad news */
4841 static int api_dhcp_proxy_config_2 (vat_main_t * vam)
4843 unformat_input_t * i = vam->input;
4844 vl_api_dhcp_proxy_config_2_t *mp;
4847 u32 server_vrf_id = 0;
4850 u8 v4_address_set = 0;
4851 u8 v6_address_set = 0;
4852 ip4_address_t v4address;
4853 ip6_address_t v6address;
4854 u8 v4_src_address_set = 0;
4855 u8 v6_src_address_set = 0;
4856 ip4_address_t v4srcaddress;
4857 ip6_address_t v6srcaddress;
4859 /* Parse args required to build the message */
4860 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
4861 if (unformat (i, "del"))
4863 else if (unformat (i, "rx_vrf_id %d", &rx_vrf_id))
4865 else if (unformat (i, "server_vrf_id %d", &server_vrf_id))
4867 else if (unformat (i, "insert-cid %d", &insert_cid))
4869 else if (unformat (i, "svr %U",
4870 unformat_ip4_address, &v4address))
4872 else if (unformat (i, "svr %U",
4873 unformat_ip6_address, &v6address))
4875 else if (unformat (i, "src %U",
4876 unformat_ip4_address, &v4srcaddress))
4877 v4_src_address_set = 1;
4878 else if (unformat (i, "src %U",
4879 unformat_ip6_address, &v6srcaddress))
4880 v6_src_address_set = 1;
4885 if (v4_address_set && v6_address_set) {
4886 errmsg ("both v4 and v6 server addresses set\n");
4889 if (!v4_address_set && !v6_address_set) {
4890 errmsg ("no server addresses set\n");
4894 if (v4_src_address_set && v6_src_address_set) {
4895 errmsg ("both v4 and v6 src addresses set\n");
4898 if (!v4_src_address_set && !v6_src_address_set) {
4899 errmsg ("no src addresses set\n");
4903 if (!(v4_src_address_set && v4_address_set) &&
4904 !(v6_src_address_set && v6_address_set)) {
4905 errmsg ("no matching server and src addresses set\n");
4909 /* Construct the API message */
4910 M(DHCP_PROXY_CONFIG_2, dhcp_proxy_config_2);
4912 mp->insert_circuit_id = insert_cid;
4913 mp->is_add = is_add;
4914 mp->rx_vrf_id = ntohl (rx_vrf_id);
4915 mp->server_vrf_id = ntohl (server_vrf_id);
4916 if (v6_address_set) {
4918 clib_memcpy (mp->dhcp_server, &v6address, sizeof (v6address));
4919 clib_memcpy (mp->dhcp_src_address, &v6srcaddress, sizeof (v6address));
4921 clib_memcpy (mp->dhcp_server, &v4address, sizeof (v4address));
4922 clib_memcpy (mp->dhcp_src_address, &v4srcaddress, sizeof (v4address));
4928 /* Wait for a reply, return good/bad news */
4934 static int api_dhcp_proxy_set_vss (vat_main_t * vam)
4936 unformat_input_t * i = vam->input;
4937 vl_api_dhcp_proxy_set_vss_t *mp;
4948 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
4949 if (unformat (i, "tbl_id %d", &tbl_id))
4951 if (unformat (i, "fib_id %d", &fib_id))
4953 if (unformat (i, "oui %d", &oui))
4955 else if (unformat (i, "ipv6"))
4957 else if (unformat (i, "del"))
4960 clib_warning ("parse error '%U'", format_unformat_error, i);
4965 if (tbl_id_set == 0) {
4966 errmsg ("missing tbl id\n");
4970 if (fib_id_set == 0) {
4971 errmsg ("missing fib id\n");
4975 errmsg ("missing oui\n");
4979 M(DHCP_PROXY_SET_VSS, dhcp_proxy_set_vss);
4980 mp->tbl_id = ntohl(tbl_id);
4981 mp->fib_id = ntohl(fib_id);
4982 mp->oui = ntohl(oui);
4983 mp->is_ipv6 = is_ipv6;
4984 mp->is_add = is_add;
4991 static int api_dhcp_client_config (vat_main_t * vam)
4993 unformat_input_t * i = vam->input;
4994 vl_api_dhcp_client_config_t *mp;
4997 u8 sw_if_index_set = 0;
5000 u8 disable_event = 0;
5002 /* Parse args required to build the message */
5003 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
5004 if (unformat (i, "del"))
5006 else if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
5007 sw_if_index_set = 1;
5008 else if (unformat (i, "sw_if_index %d", &sw_if_index))
5009 sw_if_index_set = 1;
5010 else if (unformat (i, "hostname %s", &hostname))
5012 else if (unformat (i, "disable_event"))
5018 if (sw_if_index_set == 0) {
5019 errmsg ("missing interface name or sw_if_index\n");
5023 if (vec_len (hostname) > 63) {
5024 errmsg ("hostname too long\n");
5026 vec_add1 (hostname, 0);
5028 /* Construct the API message */
5029 M(DHCP_CLIENT_CONFIG, dhcp_client_config);
5031 mp->sw_if_index = ntohl (sw_if_index);
5032 clib_memcpy (mp->hostname, hostname, vec_len (hostname));
5033 vec_free (hostname);
5034 mp->is_add = is_add;
5035 mp->want_dhcp_event = disable_event ? 0 : 1;
5041 /* Wait for a reply, return good/bad news */
5047 static int api_set_ip_flow_hash (vat_main_t * vam)
5049 unformat_input_t * i = vam->input;
5050 vl_api_set_ip_flow_hash_t *mp;
5062 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
5063 if (unformat (i, "vrf %d", &vrf_id))
5065 else if (unformat (i, "ipv6"))
5067 else if (unformat (i, "src"))
5069 else if (unformat (i, "dst"))
5071 else if (unformat (i, "sport"))
5073 else if (unformat (i, "dport"))
5075 else if (unformat (i, "proto"))
5077 else if (unformat (i, "reverse"))
5081 clib_warning ("parse error '%U'", format_unformat_error, i);
5086 if (vrf_id_set == 0) {
5087 errmsg ("missing vrf id\n");
5091 M(SET_IP_FLOW_HASH, set_ip_flow_hash);
5097 mp->reverse = reverse;
5098 mp->vrf_id = ntohl(vrf_id);
5099 mp->is_ipv6 = is_ipv6;
5106 static int api_sw_interface_ip6_enable_disable (vat_main_t * vam)
5108 unformat_input_t * i = vam->input;
5109 vl_api_sw_interface_ip6_enable_disable_t *mp;
5112 u8 sw_if_index_set = 0;
5115 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
5116 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
5117 sw_if_index_set = 1;
5118 else if (unformat (i, "sw_if_index %d", &sw_if_index))
5119 sw_if_index_set = 1;
5120 else if (unformat (i, "enable"))
5122 else if (unformat (i, "disable"))
5125 clib_warning ("parse error '%U'", format_unformat_error, i);
5130 if (sw_if_index_set == 0) {
5131 errmsg ("missing interface name or sw_if_index\n");
5135 M(SW_INTERFACE_IP6_ENABLE_DISABLE, sw_interface_ip6_enable_disable);
5137 mp->sw_if_index = ntohl(sw_if_index);
5138 mp->enable = enable;
5145 static int api_sw_interface_ip6_set_link_local_address (vat_main_t * vam)
5147 unformat_input_t * i = vam->input;
5148 vl_api_sw_interface_ip6_set_link_local_address_t *mp;
5151 u8 sw_if_index_set = 0;
5152 u32 address_length = 0;
5153 u8 v6_address_set = 0;
5154 ip6_address_t v6address;
5156 /* Parse args required to build the message */
5157 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
5158 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
5159 sw_if_index_set = 1;
5160 else if (unformat (i, "sw_if_index %d", &sw_if_index))
5161 sw_if_index_set = 1;
5162 else if (unformat (i, "%U/%d",
5163 unformat_ip6_address, &v6address,
5170 if (sw_if_index_set == 0) {
5171 errmsg ("missing interface name or sw_if_index\n");
5174 if (!v6_address_set) {
5175 errmsg ("no address set\n");
5179 /* Construct the API message */
5180 M(SW_INTERFACE_IP6_SET_LINK_LOCAL_ADDRESS, \
5181 sw_interface_ip6_set_link_local_address);
5183 mp->sw_if_index = ntohl (sw_if_index);
5184 clib_memcpy (mp->address, &v6address, sizeof (v6address));
5185 mp->address_length = address_length;
5190 /* Wait for a reply, return good/bad news */
5198 static int api_sw_interface_ip6nd_ra_prefix (vat_main_t * vam)
5200 unformat_input_t * i = vam->input;
5201 vl_api_sw_interface_ip6nd_ra_prefix_t *mp;
5204 u8 sw_if_index_set = 0;
5205 u32 address_length = 0;
5206 u8 v6_address_set = 0;
5207 ip6_address_t v6address;
5209 u8 no_advertise = 0;
5211 u8 no_autoconfig = 0;
5214 u32 val_lifetime = 0;
5215 u32 pref_lifetime = 0;
5217 /* Parse args required to build the message */
5218 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
5219 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
5220 sw_if_index_set = 1;
5221 else if (unformat (i, "sw_if_index %d", &sw_if_index))
5222 sw_if_index_set = 1;
5223 else if (unformat (i, "%U/%d",
5224 unformat_ip6_address, &v6address,
5227 else if (unformat (i, "val_life %d", &val_lifetime))
5229 else if (unformat (i, "pref_life %d", &pref_lifetime))
5231 else if (unformat (i, "def"))
5233 else if (unformat (i, "noadv"))
5235 else if (unformat (i, "offl"))
5237 else if (unformat (i, "noauto"))
5239 else if (unformat (i, "nolink"))
5241 else if (unformat (i, "isno"))
5244 clib_warning ("parse error '%U'", format_unformat_error, i);
5249 if (sw_if_index_set == 0) {
5250 errmsg ("missing interface name or sw_if_index\n");
5253 if (!v6_address_set) {
5254 errmsg ("no address set\n");
5258 /* Construct the API message */
5259 M(SW_INTERFACE_IP6ND_RA_PREFIX, sw_interface_ip6nd_ra_prefix);
5261 mp->sw_if_index = ntohl (sw_if_index);
5262 clib_memcpy (mp->address, &v6address, sizeof (v6address));
5263 mp->address_length = address_length;
5264 mp->use_default = use_default;
5265 mp->no_advertise = no_advertise;
5266 mp->off_link = off_link;
5267 mp->no_autoconfig = no_autoconfig;
5268 mp->no_onlink = no_onlink;
5270 mp->val_lifetime = ntohl(val_lifetime);
5271 mp->pref_lifetime = ntohl(pref_lifetime);
5276 /* Wait for a reply, return good/bad news */
5283 static int api_sw_interface_ip6nd_ra_config (vat_main_t * vam)
5285 unformat_input_t * i = vam->input;
5286 vl_api_sw_interface_ip6nd_ra_config_t *mp;
5289 u8 sw_if_index_set = 0;
5294 u8 send_unicast = 0;
5297 u8 default_router = 0;
5298 u32 max_interval = 0;
5299 u32 min_interval = 0;
5301 u32 initial_count = 0;
5302 u32 initial_interval = 0;
5305 /* Parse args required to build the message */
5306 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
5307 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
5308 sw_if_index_set = 1;
5309 else if (unformat (i, "sw_if_index %d", &sw_if_index))
5310 sw_if_index_set = 1;
5311 else if (unformat (i, "maxint %d", &max_interval))
5313 else if (unformat (i, "minint %d", &min_interval))
5315 else if (unformat (i, "life %d", &lifetime))
5317 else if (unformat (i, "count %d", &initial_count))
5319 else if (unformat (i, "interval %d", &initial_interval))
5321 else if (unformat (i, "surpress"))
5323 else if (unformat (i, "managed"))
5325 else if (unformat (i, "other"))
5327 else if (unformat (i, "ll"))
5329 else if (unformat (i, "send"))
5331 else if (unformat (i, "cease"))
5333 else if (unformat (i, "isno"))
5335 else if (unformat (i, "def"))
5338 clib_warning ("parse error '%U'", format_unformat_error, i);
5343 if (sw_if_index_set == 0) {
5344 errmsg ("missing interface name or sw_if_index\n");
5348 /* Construct the API message */
5349 M(SW_INTERFACE_IP6ND_RA_CONFIG, sw_interface_ip6nd_ra_config);
5351 mp->sw_if_index = ntohl (sw_if_index);
5352 mp->max_interval = ntohl(max_interval);
5353 mp->min_interval = ntohl(min_interval);
5354 mp->lifetime = ntohl(lifetime);
5355 mp->initial_count = ntohl(initial_count);
5356 mp->initial_interval = ntohl(initial_interval);
5357 mp->surpress = surpress;
5358 mp->managed = managed;
5360 mp->ll_option = ll_option;
5361 mp->send_unicast = send_unicast;
5364 mp->default_router = default_router;
5369 /* Wait for a reply, return good/bad news */
5376 static int api_set_arp_neighbor_limit (vat_main_t * vam)
5378 unformat_input_t * i = vam->input;
5379 vl_api_set_arp_neighbor_limit_t *mp;
5385 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
5386 if (unformat (i, "arp_nbr_limit %d", &arp_nbr_limit))
5388 else if (unformat (i, "ipv6"))
5391 clib_warning ("parse error '%U'", format_unformat_error, i);
5396 if (limit_set == 0) {
5397 errmsg ("missing limit value\n");
5401 M(SET_ARP_NEIGHBOR_LIMIT, set_arp_neighbor_limit);
5403 mp->arp_neighbor_limit = ntohl(arp_nbr_limit);
5404 mp->is_ipv6 = is_ipv6;
5411 static int api_l2_patch_add_del (vat_main_t * vam)
5413 unformat_input_t * i = vam->input;
5414 vl_api_l2_patch_add_del_t *mp;
5417 u8 rx_sw_if_index_set = 0;
5419 u8 tx_sw_if_index_set = 0;
5422 /* Parse args required to build the message */
5423 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
5424 if (unformat (i, "rx_sw_if_index %d", &rx_sw_if_index))
5425 rx_sw_if_index_set = 1;
5426 else if (unformat (i, "tx_sw_if_index %d", &tx_sw_if_index))
5427 tx_sw_if_index_set = 1;
5428 else if (unformat (i, "rx")) {
5429 if (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
5430 if (unformat (i, "%U", unformat_sw_if_index, vam,
5432 rx_sw_if_index_set = 1;
5435 } else if (unformat (i, "tx")) {
5436 if (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
5437 if (unformat (i, "%U", unformat_sw_if_index, vam,
5439 tx_sw_if_index_set = 1;
5442 } else if (unformat (i, "del"))
5448 if (rx_sw_if_index_set == 0) {
5449 errmsg ("missing rx interface name or rx_sw_if_index\n");
5453 if (tx_sw_if_index_set == 0) {
5454 errmsg ("missing tx interface name or tx_sw_if_index\n");
5458 M(L2_PATCH_ADD_DEL, l2_patch_add_del);
5460 mp->rx_sw_if_index = ntohl(rx_sw_if_index);
5461 mp->tx_sw_if_index = ntohl(tx_sw_if_index);
5462 mp->is_add = is_add;
5468 static int api_trace_profile_add (vat_main_t *vam)
5470 unformat_input_t * input = vam->input;
5471 vl_api_trace_profile_add_t *mp;
5474 u32 trace_option_elts = 0;
5475 u32 trace_type = 0, node_id = 0, app_data = 0, trace_tsp = 2;
5476 int has_pow_option = 0;
5477 int has_ppc_option = 0;
5479 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
5481 if (unformat (input, "id %d trace-type 0x%x trace-elts %d "
5482 "trace-tsp %d node-id 0x%x app-data 0x%x",
5483 &id, &trace_type, &trace_option_elts, &trace_tsp,
5484 &node_id, &app_data))
5486 else if (unformat (input, "pow"))
5488 else if (unformat (input, "ppc encap"))
5489 has_ppc_option = PPC_ENCAP;
5490 else if (unformat (input, "ppc decap"))
5491 has_ppc_option = PPC_DECAP;
5492 else if (unformat (input, "ppc none"))
5493 has_ppc_option = PPC_NONE;
5497 M(TRACE_PROFILE_ADD, trace_profile_add);
5499 mp->trace_type = trace_type;
5500 mp->trace_num_elt = trace_option_elts;
5501 mp->trace_ppc = has_ppc_option;
5502 mp->trace_app_data = htonl(app_data);
5503 mp->pow_enable = has_pow_option;
5504 mp->trace_tsp = trace_tsp;
5505 mp->node_id = htonl(node_id);
5512 static int api_trace_profile_apply (vat_main_t *vam)
5514 unformat_input_t * input = vam->input;
5515 vl_api_trace_profile_apply_t *mp;
5518 u32 mask_width = ~0;
5525 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
5527 if (unformat (input, "%U/%d",
5528 unformat_ip6_address, &addr, &mask_width))
5530 else if (unformat (input, "id %d", &id))
5532 else if (unformat (input, "vrf-id %d", &vrf_id))
5534 else if (unformat (input, "add"))
5536 else if (unformat (input, "pop"))
5538 else if (unformat (input, "none"))
5544 if ((is_add + is_pop + is_none) != 1) {
5545 errmsg("One of (add, pop, none) required");
5548 if (mask_width == ~0) {
5549 errmsg("<address>/<mask-width> required");
5552 M(TRACE_PROFILE_APPLY, trace_profile_apply);
5553 clib_memcpy(mp->dest_ipv6, &addr, sizeof(mp->dest_ipv6));
5555 mp->prefix_length = htonl(mask_width);
5556 mp->vrf_id = htonl(vrf_id);
5558 mp->trace_op = IOAM_HBYH_ADD;
5560 mp->trace_op = IOAM_HBYH_POP;
5562 mp->trace_op = IOAM_HBYH_MOD;
5574 static int api_trace_profile_del (vat_main_t *vam)
5576 vl_api_trace_profile_del_t *mp;
5579 M(TRACE_PROFILE_DEL, trace_profile_del);
5584 static int api_sr_tunnel_add_del (vat_main_t * vam)
5586 unformat_input_t * i = vam->input;
5587 vl_api_sr_tunnel_add_del_t *mp;
5591 ip6_address_t src_address;
5592 int src_address_set = 0;
5593 ip6_address_t dst_address;
5595 int dst_address_set = 0;
5597 u32 rx_table_id = 0;
5598 u32 tx_table_id = 0;
5599 ip6_address_t * segments = 0;
5600 ip6_address_t * this_seg;
5601 ip6_address_t * tags = 0;
5602 ip6_address_t * this_tag;
5603 ip6_address_t next_address, tag;
5605 u8 * policy_name = 0;
5607 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
5609 if (unformat (i, "del"))
5611 else if (unformat (i, "name %s", &name))
5613 else if (unformat (i, "policy %s", &policy_name))
5615 else if (unformat (i, "rx_fib_id %d", &rx_table_id))
5617 else if (unformat (i, "tx_fib_id %d", &tx_table_id))
5619 else if (unformat (i, "src %U", unformat_ip6_address, &src_address))
5620 src_address_set = 1;
5621 else if (unformat (i, "dst %U/%d",
5622 unformat_ip6_address, &dst_address,
5624 dst_address_set = 1;
5625 else if (unformat (i, "next %U", unformat_ip6_address,
5628 vec_add2 (segments, this_seg, 1);
5629 clib_memcpy (this_seg->as_u8, next_address.as_u8, sizeof (*this_seg));
5631 else if (unformat (i, "tag %U", unformat_ip6_address,
5634 vec_add2 (tags, this_tag, 1);
5635 clib_memcpy (this_tag->as_u8, tag.as_u8, sizeof (*this_tag));
5637 else if (unformat (i, "clean"))
5638 flags |= IP6_SR_HEADER_FLAG_CLEANUP;
5639 else if (unformat (i, "protected"))
5640 flags |= IP6_SR_HEADER_FLAG_PROTECTED;
5641 else if (unformat (i, "InPE %d", &pl_index))
5643 if (pl_index <= 0 || pl_index > 4)
5645 pl_index_range_error:
5646 errmsg ("pl index %d out of range\n", pl_index);
5649 flags |= IP6_SR_HEADER_FLAG_PL_ELT_INGRESS_PE << (3*(pl_index - 1));
5651 else if (unformat (i, "EgPE %d", &pl_index))
5653 if (pl_index <= 0 || pl_index > 4)
5654 goto pl_index_range_error;
5655 flags |= IP6_SR_HEADER_FLAG_PL_ELT_EGRESS_PE << (3*(pl_index - 1));
5657 else if (unformat (i, "OrgSrc %d", &pl_index))
5659 if (pl_index <= 0 || pl_index > 4)
5660 goto pl_index_range_error;
5661 flags |= IP6_SR_HEADER_FLAG_PL_ELT_ORIG_SRC_ADDR << (3*(pl_index - 1));
5667 if (!src_address_set)
5669 errmsg ("src address required\n");
5673 if (!dst_address_set)
5675 errmsg ("dst address required\n");
5681 errmsg ("at least one sr segment required\n");
5685 M2(SR_TUNNEL_ADD_DEL, sr_tunnel_add_del,
5686 vec_len(segments) * sizeof (ip6_address_t)
5687 + vec_len(tags) * sizeof (ip6_address_t));
5689 clib_memcpy (mp->src_address, &src_address, sizeof (mp->src_address));
5690 clib_memcpy (mp->dst_address, &dst_address, sizeof (mp->dst_address));
5691 mp->dst_mask_width = dst_mask_width;
5692 mp->flags_net_byte_order = clib_host_to_net_u16 (flags);
5693 mp->n_segments = vec_len (segments);
5694 mp->n_tags = vec_len (tags);
5695 mp->is_add = is_del == 0;
5696 clib_memcpy (mp->segs_and_tags, segments,
5697 vec_len(segments)* sizeof (ip6_address_t));
5698 clib_memcpy (mp->segs_and_tags + vec_len(segments)*sizeof (ip6_address_t),
5699 tags, vec_len(tags)* sizeof (ip6_address_t));
5701 mp->outer_vrf_id = ntohl (rx_table_id);
5702 mp->inner_vrf_id = ntohl (tx_table_id);
5703 memcpy (mp->name, name, vec_len(name));
5704 memcpy (mp->policy_name, policy_name, vec_len(policy_name));
5706 vec_free (segments);
5713 static int api_sr_policy_add_del (vat_main_t * vam)
5715 unformat_input_t * input = vam->input;
5716 vl_api_sr_policy_add_del_t *mp;
5720 u8 * tunnel_name = 0;
5721 u8 ** tunnel_names = 0;
5726 int tunnel_names_length = 1; // Init to 1 to offset the #tunnel_names counter byte
5727 int tun_name_len = 0; // Different naming convention used as confusing these would be "bad" (TM)
5729 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
5731 if (unformat (input, "del"))
5733 else if (unformat (input, "name %s", &name))
5735 else if (unformat (input, "tunnel %s", &tunnel_name))
5739 vec_add1 (tunnel_names, tunnel_name);
5741 - length = #bytes to store in serial vector
5742 - +1 = byte to store that length
5744 tunnel_names_length += (vec_len (tunnel_name) + 1);
5755 errmsg ("policy name required\n");
5759 if ((!tunnel_set) && (!is_del))
5761 errmsg ("tunnel name required\n");
5765 M2(SR_POLICY_ADD_DEL, sr_policy_add_del, tunnel_names_length);
5769 mp->is_add = !is_del;
5771 memcpy (mp->name, name, vec_len(name));
5772 // Since mp->tunnel_names is of type u8[0] and not a u8 *, u8 ** needs to be serialized
5773 u8 * serial_orig = 0;
5774 vec_validate (serial_orig, tunnel_names_length);
5775 *serial_orig = vec_len(tunnel_names); // Store the number of tunnels as length in first byte of serialized vector
5776 serial_orig += 1; // Move along one byte to store the length of first tunnel_name
5778 for (j=0; j < vec_len(tunnel_names); j++)
5780 tun_name_len = vec_len (tunnel_names[j]);
5781 *serial_orig = tun_name_len; // Store length of tunnel name in first byte of Length/Value pair
5782 serial_orig += 1; // Move along one byte to store the actual tunnel name
5783 memcpy (serial_orig, tunnel_names[j], tun_name_len);
5784 serial_orig += tun_name_len; // Advance past the copy
5786 memcpy (mp->tunnel_names, serial_orig - tunnel_names_length, tunnel_names_length); // Regress serial_orig to head then copy fwd
5788 vec_free (tunnel_names);
5789 vec_free (tunnel_name);
5795 static int api_sr_multicast_map_add_del (vat_main_t * vam)
5797 unformat_input_t * input = vam->input;
5798 vl_api_sr_multicast_map_add_del_t *mp;
5801 ip6_address_t multicast_address;
5802 u8 * policy_name = 0;
5803 int multicast_address_set = 0;
5805 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
5807 if (unformat (input, "del"))
5809 else if (unformat (input, "address %U", unformat_ip6_address, &multicast_address))
5810 multicast_address_set = 1;
5811 else if (unformat (input, "sr-policy %s", &policy_name))
5817 if (!is_del && !policy_name)
5819 errmsg ("sr-policy name required\n");
5824 if (!multicast_address_set)
5826 errmsg ("address required\n");
5830 M(SR_MULTICAST_MAP_ADD_DEL, sr_multicast_map_add_del);
5832 mp->is_add = !is_del;
5833 memcpy (mp->policy_name, policy_name, vec_len(policy_name));
5834 clib_memcpy (mp->multicast_address, &multicast_address, sizeof (mp->multicast_address));
5837 vec_free (policy_name);
5844 #define foreach_ip4_proto_field \
5854 uword unformat_ip4_mask (unformat_input_t * input, va_list * args)
5856 u8 ** maskp = va_arg (*args, u8 **);
5858 u8 found_something = 0;
5861 #define _(a) u8 a=0;
5862 foreach_ip4_proto_field;
5868 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
5870 if (unformat (input, "version"))
5872 else if (unformat (input, "hdr_length"))
5874 else if (unformat (input, "src"))
5876 else if (unformat (input, "dst"))
5878 else if (unformat (input, "proto"))
5881 #define _(a) else if (unformat (input, #a)) a=1;
5882 foreach_ip4_proto_field
5888 #define _(a) found_something += a;
5889 foreach_ip4_proto_field;
5892 if (found_something == 0)
5895 vec_validate (mask, sizeof (*ip) - 1);
5897 ip = (ip4_header_t *) mask;
5899 #define _(a) if (a) memset (&ip->a, 0xff, sizeof (ip->a));
5900 foreach_ip4_proto_field;
5903 ip->ip_version_and_header_length = 0;
5906 ip->ip_version_and_header_length |= 0xF0;
5909 ip->ip_version_and_header_length |= 0x0F;
5915 #define foreach_ip6_proto_field \
5922 uword unformat_ip6_mask (unformat_input_t * input, va_list * args)
5924 u8 ** maskp = va_arg (*args, u8 **);
5926 u8 found_something = 0;
5928 u32 ip_version_traffic_class_and_flow_label;
5930 #define _(a) u8 a=0;
5931 foreach_ip6_proto_field;
5934 u8 traffic_class = 0;
5937 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
5939 if (unformat (input, "version"))
5941 else if (unformat (input, "traffic-class"))
5943 else if (unformat (input, "flow-label"))
5945 else if (unformat (input, "src"))
5947 else if (unformat (input, "dst"))
5949 else if (unformat (input, "proto"))
5952 #define _(a) else if (unformat (input, #a)) a=1;
5953 foreach_ip6_proto_field
5959 #define _(a) found_something += a;
5960 foreach_ip6_proto_field;
5963 if (found_something == 0)
5966 vec_validate (mask, sizeof (*ip) - 1);
5968 ip = (ip6_header_t *) mask;
5970 #define _(a) if (a) memset (&ip->a, 0xff, sizeof (ip->a));
5971 foreach_ip6_proto_field;
5974 ip_version_traffic_class_and_flow_label = 0;
5977 ip_version_traffic_class_and_flow_label |= 0xF0000000;
5980 ip_version_traffic_class_and_flow_label |= 0x0FF00000;
5983 ip_version_traffic_class_and_flow_label |= 0x000FFFFF;
5985 ip->ip_version_traffic_class_and_flow_label =
5986 clib_host_to_net_u32 (ip_version_traffic_class_and_flow_label);
5992 uword unformat_l3_mask (unformat_input_t * input, va_list * args)
5994 u8 ** maskp = va_arg (*args, u8 **);
5996 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) {
5997 if (unformat (input, "ip4 %U", unformat_ip4_mask, maskp))
5999 else if (unformat (input, "ip6 %U", unformat_ip6_mask, maskp))
6007 uword unformat_l2_mask (unformat_input_t * input, va_list * args)
6009 u8 ** maskp = va_arg (*args, u8 **);
6024 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) {
6025 if (unformat (input, "src"))
6027 else if (unformat (input, "dst"))
6029 else if (unformat (input, "proto"))
6031 else if (unformat (input, "tag1"))
6033 else if (unformat (input, "tag2"))
6035 else if (unformat (input, "ignore-tag1"))
6037 else if (unformat (input, "ignore-tag2"))
6039 else if (unformat (input, "cos1"))
6041 else if (unformat (input, "cos2"))
6043 else if (unformat (input, "dot1q"))
6045 else if (unformat (input, "dot1ad"))
6050 if ((src + dst + proto + tag1 + tag2 + dot1q + dot1ad +
6051 ignore_tag1 + ignore_tag2 + cos1 + cos2) == 0)
6054 if (tag1 || ignore_tag1 || cos1 || dot1q)
6056 if (tag2 || ignore_tag2 || cos2 || dot1ad)
6059 vec_validate (mask, len-1);
6062 memset (mask, 0xff, 6);
6065 memset (mask + 6, 0xff, 6);
6069 /* inner vlan tag */
6078 mask[21] = mask [20] = 0xff;
6099 mask[16] = mask [17] = 0xff;
6109 mask[12] = mask [13] = 0xff;
6115 uword unformat_classify_mask (unformat_input_t * input, va_list * args)
6117 u8 ** maskp = va_arg (*args, u8 **);
6118 u32 * skipp = va_arg (*args, u32 *);
6119 u32 * matchp = va_arg (*args, u32 *);
6126 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) {
6127 if (unformat (input, "hex %U", unformat_hex_string, &mask))
6129 else if (unformat (input, "l2 %U", unformat_l2_mask, &l2))
6131 else if (unformat (input, "l3 %U", unformat_l3_mask, &l3))
6137 if (mask || l2 || l3)
6141 /* "With a free Ethernet header in every package" */
6143 vec_validate (l2, 13);
6145 vec_append (mask, l3);
6149 /* Scan forward looking for the first significant mask octet */
6150 for (i = 0; i < vec_len (mask); i++)
6154 /* compute (skip, match) params */
6155 *skipp = i / sizeof(u32x4);
6156 vec_delete (mask, *skipp * sizeof(u32x4), 0);
6158 /* Pad mask to an even multiple of the vector size */
6159 while (vec_len (mask) % sizeof (u32x4))
6162 match = vec_len (mask) / sizeof (u32x4);
6164 for (i = match*sizeof(u32x4); i > 0; i-= sizeof(u32x4))
6166 u64 *tmp = (u64 *)(mask + (i-sizeof(u32x4)));
6167 if (*tmp || *(tmp+1))
6172 clib_warning ("BUG: match 0");
6174 _vec_len (mask) = match * sizeof(u32x4);
6185 #define foreach_l2_next \
6187 _(ethernet, ETHERNET_INPUT) \
6191 uword unformat_l2_next_index (unformat_input_t * input, va_list * args)
6193 u32 * miss_next_indexp = va_arg (*args, u32 *);
6198 if (unformat (input, #n)) { next_index = L2_CLASSIFY_NEXT_##N; goto out;}
6202 if (unformat (input, "%d", &tmp))
6211 *miss_next_indexp = next_index;
6215 #define foreach_ip_next \
6221 uword unformat_ip_next_index (unformat_input_t * input, va_list * args)
6223 u32 * miss_next_indexp = va_arg (*args, u32 *);
6228 if (unformat (input, #n)) { next_index = IP_LOOKUP_NEXT_##N; goto out;}
6232 if (unformat (input, "%d", &tmp))
6241 *miss_next_indexp = next_index;
6245 #define foreach_acl_next \
6248 uword unformat_acl_next_index (unformat_input_t * input, va_list * args)
6250 u32 * miss_next_indexp = va_arg (*args, u32 *);
6255 if (unformat (input, #n)) { next_index = ACL_NEXT_INDEX_##N; goto out;}
6259 if (unformat (input, "permit"))
6264 else if (unformat (input, "%d", &tmp))
6273 *miss_next_indexp = next_index;
6277 static int api_classify_add_del_table (vat_main_t * vam)
6279 unformat_input_t * i = vam->input;
6280 vl_api_classify_add_del_table_t *mp;
6286 u32 table_index = ~0;
6287 u32 next_table_index = ~0;
6288 u32 miss_next_index = ~0;
6289 u32 memory_size = 32<<20;
6293 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
6294 if (unformat (i, "del"))
6296 else if (unformat (i, "buckets %d", &nbuckets))
6298 else if (unformat (i, "memory_size %d", &memory_size))
6300 else if (unformat (i, "skip %d", &skip))
6302 else if (unformat (i, "match %d", &match))
6304 else if (unformat (i, "table %d", &table_index))
6306 else if (unformat (i, "mask %U", unformat_classify_mask,
6307 &mask, &skip, &match))
6309 else if (unformat (i, "next-table %d", &next_table_index))
6311 else if (unformat (i, "miss-next %U", unformat_ip_next_index,
6314 else if (unformat (i, "l2-miss-next %U", unformat_l2_next_index,
6317 else if (unformat (i, "acl-miss-next %U", unformat_acl_next_index,
6324 if (is_add && mask == 0) {
6325 errmsg ("Mask required\n");
6329 if (is_add && skip == ~0) {
6330 errmsg ("skip count required\n");
6334 if (is_add && match == ~0) {
6335 errmsg ("match count required\n");
6339 if (!is_add && table_index == ~0) {
6340 errmsg ("table index required for delete\n");
6344 M2 (CLASSIFY_ADD_DEL_TABLE, classify_add_del_table,
6347 mp->is_add = is_add;
6348 mp->table_index = ntohl(table_index);
6349 mp->nbuckets = ntohl(nbuckets);
6350 mp->memory_size = ntohl(memory_size);
6351 mp->skip_n_vectors = ntohl(skip);
6352 mp->match_n_vectors = ntohl(match);
6353 mp->next_table_index = ntohl(next_table_index);
6354 mp->miss_next_index = ntohl(miss_next_index);
6355 clib_memcpy (mp->mask, mask, vec_len(mask));
6363 uword unformat_ip4_match (unformat_input_t * input, va_list * args)
6365 u8 ** matchp = va_arg (*args, u8 **);
6372 int src = 0, dst = 0;
6373 ip4_address_t src_val, dst_val;
6380 int fragment_id = 0;
6381 u32 fragment_id_val;
6387 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
6389 if (unformat (input, "version %d", &version_val))
6391 else if (unformat (input, "hdr_length %d", &hdr_length_val))
6393 else if (unformat (input, "src %U", unformat_ip4_address, &src_val))
6395 else if (unformat (input, "dst %U", unformat_ip4_address, &dst_val))
6397 else if (unformat (input, "proto %d", &proto_val))
6399 else if (unformat (input, "tos %d", &tos_val))
6401 else if (unformat (input, "length %d", &length_val))
6403 else if (unformat (input, "fragment_id %d", &fragment_id_val))
6405 else if (unformat (input, "ttl %d", &ttl_val))
6407 else if (unformat (input, "checksum %d", &checksum_val))
6413 if (version + hdr_length + src + dst + proto + tos + length + fragment_id
6414 + ttl + checksum == 0)
6418 * Aligned because we use the real comparison functions
6420 vec_validate_aligned (match, sizeof (*ip) - 1, sizeof(u32x4));
6422 ip = (ip4_header_t *) match;
6424 /* These are realistically matched in practice */
6426 ip->src_address.as_u32 = src_val.as_u32;
6429 ip->dst_address.as_u32 = dst_val.as_u32;
6432 ip->protocol = proto_val;
6435 /* These are not, but they're included for completeness */
6437 ip->ip_version_and_header_length |= (version_val & 0xF)<<4;
6440 ip->ip_version_and_header_length |= (hdr_length_val & 0xF);
6446 ip->length = length_val;
6452 ip->checksum = checksum_val;
6458 uword unformat_ip6_match (unformat_input_t * input, va_list * args)
6460 u8 ** matchp = va_arg (*args, u8 **);
6466 u32 traffic_class_val;
6469 int src = 0, dst = 0;
6470 ip6_address_t src_val, dst_val;
6473 int payload_length = 0;
6474 u32 payload_length_val;
6477 u32 ip_version_traffic_class_and_flow_label;
6479 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
6481 if (unformat (input, "version %d", &version_val))
6483 else if (unformat (input, "traffic_class %d", &traffic_class_val))
6485 else if (unformat (input, "flow_label %d", &flow_label_val))
6487 else if (unformat (input, "src %U", unformat_ip6_address, &src_val))
6489 else if (unformat (input, "dst %U", unformat_ip6_address, &dst_val))
6491 else if (unformat (input, "proto %d", &proto_val))
6493 else if (unformat (input, "payload_length %d", &payload_length_val))
6495 else if (unformat (input, "hop_limit %d", &hop_limit_val))
6501 if (version + traffic_class + flow_label + src + dst + proto +
6502 payload_length + hop_limit == 0)
6506 * Aligned because we use the real comparison functions
6508 vec_validate_aligned (match, sizeof (*ip) - 1, sizeof(u32x4));
6510 ip = (ip6_header_t *) match;
6513 clib_memcpy (&ip->src_address, &src_val, sizeof (ip->src_address));
6516 clib_memcpy (&ip->dst_address, &dst_val, sizeof (ip->dst_address));
6519 ip->protocol = proto_val;
6521 ip_version_traffic_class_and_flow_label = 0;
6524 ip_version_traffic_class_and_flow_label |= (version_val & 0xF) << 28;
6527 ip_version_traffic_class_and_flow_label |= (traffic_class_val & 0xFF) << 20;
6530 ip_version_traffic_class_and_flow_label |= (flow_label_val & 0xFFFFF);
6532 ip->ip_version_traffic_class_and_flow_label =
6533 clib_host_to_net_u32 (ip_version_traffic_class_and_flow_label);
6536 ip->payload_length = clib_host_to_net_u16 (payload_length_val);
6539 ip->hop_limit = hop_limit_val;
6545 uword unformat_l3_match (unformat_input_t * input, va_list * args)
6547 u8 ** matchp = va_arg (*args, u8 **);
6549 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) {
6550 if (unformat (input, "ip4 %U", unformat_ip4_match, matchp))
6552 else if (unformat (input, "ip6 %U", unformat_ip6_match, matchp))
6560 uword unformat_vlan_tag (unformat_input_t * input, va_list * args)
6562 u8 * tagp = va_arg (*args, u8 *);
6565 if (unformat(input, "%d", &tag))
6567 tagp[0] = (tag>>8) & 0x0F;
6568 tagp[1] = tag & 0xFF;
6575 uword unformat_l2_match (unformat_input_t * input, va_list * args)
6577 u8 ** matchp = va_arg (*args, u8 **);
6597 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) {
6598 if (unformat (input, "src %U", unformat_ethernet_address, &src_val))
6600 else if (unformat (input, "dst %U", unformat_ethernet_address, &dst_val))
6602 else if (unformat (input, "proto %U",
6603 unformat_ethernet_type_host_byte_order, &proto_val))
6605 else if (unformat (input, "tag1 %U", unformat_vlan_tag, tag1_val))
6607 else if (unformat (input, "tag2 %U", unformat_vlan_tag, tag2_val))
6609 else if (unformat (input, "ignore-tag1"))
6611 else if (unformat (input, "ignore-tag2"))
6613 else if (unformat (input, "cos1 %d", &cos1_val))
6615 else if (unformat (input, "cos2 %d", &cos2_val))
6620 if ((src + dst + proto + tag1 + tag2 +
6621 ignore_tag1 + ignore_tag2 + cos1 + cos2) == 0)
6624 if (tag1 || ignore_tag1 || cos1)
6626 if (tag2 || ignore_tag2 || cos2)
6629 vec_validate_aligned (match, len-1, sizeof(u32x4));
6632 clib_memcpy (match, dst_val, 6);
6635 clib_memcpy (match + 6, src_val, 6);
6639 /* inner vlan tag */
6640 match[19] = tag2_val[1];
6641 match[18] = tag2_val[0];
6643 match [18] |= (cos2_val & 0x7) << 5;
6646 match[21] = proto_val & 0xff;
6647 match[20] = proto_val >> 8;
6651 match [15] = tag1_val[1];
6652 match [14] = tag1_val[0];
6655 match [14] |= (cos1_val & 0x7) << 5;
6661 match [15] = tag1_val[1];
6662 match [14] = tag1_val[0];
6665 match[17] = proto_val & 0xff;
6666 match[16] = proto_val >> 8;
6669 match [14] |= (cos1_val & 0x7) << 5;
6675 match [18] |= (cos2_val & 0x7) << 5;
6677 match [14] |= (cos1_val & 0x7) << 5;
6680 match[13] = proto_val & 0xff;
6681 match[12] = proto_val >> 8;
6689 uword unformat_classify_match (unformat_input_t * input, va_list * args)
6691 u8 ** matchp = va_arg (*args, u8 **);
6692 u32 skip_n_vectors = va_arg (*args, u32);
6693 u32 match_n_vectors = va_arg (*args, u32);
6699 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) {
6700 if (unformat (input, "hex %U", unformat_hex_string, &match))
6702 else if (unformat (input, "l2 %U", unformat_l2_match, &l2))
6704 else if (unformat (input, "l3 %U", unformat_l3_match, &l3))
6710 if (match || l2 || l3)
6714 /* "Win a free Ethernet header in every packet" */
6716 vec_validate_aligned (l2, 13, sizeof(u32x4));
6718 vec_append_aligned (match, l3, sizeof(u32x4));
6722 /* Make sure the vector is big enough even if key is all 0's */
6723 vec_validate_aligned
6724 (match, ((match_n_vectors + skip_n_vectors) * sizeof(u32x4)) - 1,
6727 /* Set size, include skipped vectors*/
6728 _vec_len (match) = (match_n_vectors+skip_n_vectors) * sizeof(u32x4);
6738 static int api_classify_add_del_session (vat_main_t * vam)
6740 unformat_input_t * i = vam->input;
6741 vl_api_classify_add_del_session_t *mp;
6743 u32 table_index = ~0;
6744 u32 hit_next_index = ~0;
6745 u32 opaque_index = ~0;
6749 u32 skip_n_vectors = 0;
6750 u32 match_n_vectors = 0;
6753 * Warning: you have to supply skip_n and match_n
6754 * because the API client cant simply look at the classify
6758 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
6759 if (unformat (i, "del"))
6761 else if (unformat (i, "hit-next %U", unformat_ip_next_index,
6764 else if (unformat (i, "l2-hit-next %U", unformat_l2_next_index,
6767 else if (unformat (i, "acl-hit-next %U", unformat_acl_next_index,
6770 else if (unformat (i, "opaque-index %d", &opaque_index))
6772 else if (unformat (i, "skip_n %d", &skip_n_vectors))
6774 else if (unformat (i, "match_n %d", &match_n_vectors))
6776 else if (unformat (i, "match %U", unformat_classify_match,
6777 &match, skip_n_vectors, match_n_vectors))
6779 else if (unformat (i, "advance %d", &advance))
6781 else if (unformat (i, "table-index %d", &table_index))
6787 if (table_index == ~0) {
6788 errmsg ("Table index required\n");
6792 if (is_add && match == 0) {
6793 errmsg ("Match value required\n");
6797 M2 (CLASSIFY_ADD_DEL_SESSION, classify_add_del_session,
6800 mp->is_add = is_add;
6801 mp->table_index = ntohl(table_index);
6802 mp->hit_next_index = ntohl(hit_next_index);
6803 mp->opaque_index = ntohl(opaque_index);
6804 mp->advance = ntohl(advance);
6805 clib_memcpy (mp->match, match, vec_len(match));
6812 static int api_classify_set_interface_ip_table (vat_main_t * vam)
6814 unformat_input_t * i = vam->input;
6815 vl_api_classify_set_interface_ip_table_t *mp;
6818 int sw_if_index_set;
6819 u32 table_index = ~0;
6822 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
6823 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
6824 sw_if_index_set = 1;
6825 else if (unformat (i, "sw_if_index %d", &sw_if_index))
6826 sw_if_index_set = 1;
6827 else if (unformat (i, "table %d", &table_index))
6830 clib_warning ("parse error '%U'", format_unformat_error, i);
6835 if (sw_if_index_set == 0) {
6836 errmsg ("missing interface name or sw_if_index\n");
6841 M(CLASSIFY_SET_INTERFACE_IP_TABLE, classify_set_interface_ip_table);
6843 mp->sw_if_index = ntohl(sw_if_index);
6844 mp->table_index = ntohl(table_index);
6845 mp->is_ipv6 = is_ipv6;
6852 static int api_classify_set_interface_l2_tables (vat_main_t * vam)
6854 unformat_input_t * i = vam->input;
6855 vl_api_classify_set_interface_l2_tables_t *mp;
6858 int sw_if_index_set;
6859 u32 ip4_table_index = ~0;
6860 u32 ip6_table_index = ~0;
6861 u32 other_table_index = ~0;
6863 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
6864 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
6865 sw_if_index_set = 1;
6866 else if (unformat (i, "sw_if_index %d", &sw_if_index))
6867 sw_if_index_set = 1;
6868 else if (unformat (i, "ip4-table %d", &ip4_table_index))
6870 else if (unformat (i, "ip6-table %d", &ip6_table_index))
6872 else if (unformat (i, "other-table %d", &other_table_index))
6875 clib_warning ("parse error '%U'", format_unformat_error, i);
6880 if (sw_if_index_set == 0) {
6881 errmsg ("missing interface name or sw_if_index\n");
6886 M(CLASSIFY_SET_INTERFACE_L2_TABLES, classify_set_interface_l2_tables);
6888 mp->sw_if_index = ntohl(sw_if_index);
6889 mp->ip4_table_index = ntohl(ip4_table_index);
6890 mp->ip6_table_index = ntohl(ip6_table_index);
6891 mp->other_table_index = ntohl(other_table_index);
6899 static int api_get_node_index (vat_main_t * vam)
6901 unformat_input_t * i = vam->input;
6902 vl_api_get_node_index_t * mp;
6906 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
6907 if (unformat (i, "node %s", &name))
6913 errmsg ("node name required\n");
6916 if (vec_len (name) >= ARRAY_LEN(mp->node_name)) {
6917 errmsg ("node name too long, max %d\n", ARRAY_LEN(mp->node_name));
6921 M(GET_NODE_INDEX, get_node_index);
6922 clib_memcpy (mp->node_name, name, vec_len(name));
6930 static int api_add_node_next (vat_main_t * vam)
6932 unformat_input_t * i = vam->input;
6933 vl_api_add_node_next_t * mp;
6938 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
6939 if (unformat (i, "node %s", &name))
6941 else if (unformat (i, "next %s", &next))
6947 errmsg ("node name required\n");
6950 if (vec_len (name) >= ARRAY_LEN(mp->node_name)) {
6951 errmsg ("node name too long, max %d\n", ARRAY_LEN(mp->node_name));
6955 errmsg ("next node required\n");
6958 if (vec_len (next) >= ARRAY_LEN(mp->next_name)) {
6959 errmsg ("next name too long, max %d\n", ARRAY_LEN(mp->next_name));
6963 M(ADD_NODE_NEXT, add_node_next);
6964 clib_memcpy (mp->node_name, name, vec_len(name));
6965 clib_memcpy (mp->next_name, next, vec_len(next));
6974 static int api_l2tpv3_create_tunnel (vat_main_t * vam)
6976 unformat_input_t * i = vam->input;
6977 ip6_address_t client_address, our_address;
6978 int client_address_set = 0;
6979 int our_address_set = 0;
6980 u32 local_session_id = 0;
6981 u32 remote_session_id = 0;
6982 u64 local_cookie = 0;
6983 u64 remote_cookie = 0;
6984 u8 l2_sublayer_present = 0;
6985 vl_api_l2tpv3_create_tunnel_t * mp;
6988 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
6989 if (unformat (i, "client_address %U", unformat_ip6_address,
6991 client_address_set = 1;
6992 else if (unformat (i, "our_address %U", unformat_ip6_address,
6994 our_address_set = 1;
6995 else if (unformat (i, "local_session_id %d", &local_session_id))
6997 else if (unformat (i, "remote_session_id %d", &remote_session_id))
6999 else if (unformat (i, "local_cookie %lld", &local_cookie))
7001 else if (unformat (i, "remote_cookie %lld", &remote_cookie))
7003 else if (unformat (i, "l2-sublayer-present"))
7004 l2_sublayer_present = 1;
7009 if (client_address_set == 0) {
7010 errmsg ("client_address required\n");
7014 if (our_address_set == 0) {
7015 errmsg ("our_address required\n");
7019 M(L2TPV3_CREATE_TUNNEL, l2tpv3_create_tunnel);
7021 clib_memcpy (mp->client_address, client_address.as_u8,
7022 sizeof (mp->client_address));
7024 clib_memcpy (mp->our_address, our_address.as_u8,
7025 sizeof (mp->our_address));
7027 mp->local_session_id = ntohl (local_session_id);
7028 mp->remote_session_id = ntohl (remote_session_id);
7029 mp->local_cookie = clib_host_to_net_u64 (local_cookie);
7030 mp->remote_cookie = clib_host_to_net_u64 (remote_cookie);
7031 mp->l2_sublayer_present = l2_sublayer_present;
7039 static int api_l2tpv3_set_tunnel_cookies (vat_main_t * vam)
7041 unformat_input_t * i = vam->input;
7043 u8 sw_if_index_set = 0;
7044 u64 new_local_cookie = 0;
7045 u64 new_remote_cookie = 0;
7046 vl_api_l2tpv3_set_tunnel_cookies_t *mp;
7049 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
7050 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
7051 sw_if_index_set = 1;
7052 else if (unformat (i, "sw_if_index %d", &sw_if_index))
7053 sw_if_index_set = 1;
7054 else if (unformat (i, "new_local_cookie %lld", &new_local_cookie))
7056 else if (unformat (i, "new_remote_cookie %lld", &new_remote_cookie))
7062 if (sw_if_index_set == 0) {
7063 errmsg ("missing interface name or sw_if_index\n");
7067 M(L2TPV3_SET_TUNNEL_COOKIES, l2tpv3_set_tunnel_cookies);
7069 mp->sw_if_index = ntohl(sw_if_index);
7070 mp->new_local_cookie = clib_host_to_net_u64 (new_local_cookie);
7071 mp->new_remote_cookie = clib_host_to_net_u64 (new_remote_cookie);
7078 static int api_l2tpv3_interface_enable_disable (vat_main_t * vam)
7080 unformat_input_t * i = vam->input;
7081 vl_api_l2tpv3_interface_enable_disable_t *mp;
7084 u8 sw_if_index_set = 0;
7085 u8 enable_disable = 1;
7087 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
7088 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
7089 sw_if_index_set = 1;
7090 else if (unformat (i, "sw_if_index %d", &sw_if_index))
7091 sw_if_index_set = 1;
7092 else if (unformat (i, "enable"))
7094 else if (unformat (i, "disable"))
7100 if (sw_if_index_set == 0) {
7101 errmsg ("missing interface name or sw_if_index\n");
7105 M(L2TPV3_INTERFACE_ENABLE_DISABLE, l2tpv3_interface_enable_disable);
7107 mp->sw_if_index = ntohl(sw_if_index);
7108 mp->enable_disable = enable_disable;
7115 static int api_l2tpv3_set_lookup_key (vat_main_t * vam)
7117 unformat_input_t * i = vam->input;
7118 vl_api_l2tpv3_set_lookup_key_t * mp;
7122 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
7123 if (unformat (i, "lookup_v6_src"))
7124 key = L2T_LOOKUP_SRC_ADDRESS;
7125 else if (unformat (i, "lookup_v6_dst"))
7126 key = L2T_LOOKUP_DST_ADDRESS;
7127 else if (unformat (i, "lookup_session_id"))
7128 key = L2T_LOOKUP_SESSION_ID;
7133 if (key == (u8) ~0) {
7134 errmsg ("l2tp session lookup key unset\n");
7138 M(L2TPV3_SET_LOOKUP_KEY, l2tpv3_set_lookup_key);
7147 static void vl_api_sw_if_l2tpv3_tunnel_details_t_handler
7148 (vl_api_sw_if_l2tpv3_tunnel_details_t * mp)
7150 vat_main_t * vam = &vat_main;
7152 fformat(vam->ofp, "* %U (our) %U (client) (sw_if_index %d)\n",
7153 format_ip6_address, mp->our_address,
7154 format_ip6_address, mp->client_address,
7155 clib_net_to_host_u32(mp->sw_if_index));
7157 fformat (vam->ofp, " local cookies %016llx %016llx remote cookie %016llx\n",
7158 clib_net_to_host_u64 (mp->local_cookie[0]),
7159 clib_net_to_host_u64 (mp->local_cookie[1]),
7160 clib_net_to_host_u64 (mp->remote_cookie));
7162 fformat (vam->ofp, " local session-id %d remote session-id %d\n",
7163 clib_net_to_host_u32 (mp->local_session_id),
7164 clib_net_to_host_u32 (mp->remote_session_id));
7166 fformat (vam->ofp, " l2 specific sublayer %s\n\n",
7167 mp->l2_sublayer_present ? "preset" : "absent");
7171 static void vl_api_sw_if_l2tpv3_tunnel_details_t_handler_json
7172 (vl_api_sw_if_l2tpv3_tunnel_details_t * mp)
7174 vat_main_t * vam = &vat_main;
7175 vat_json_node_t *node = NULL;
7176 struct in6_addr addr;
7178 if (VAT_JSON_ARRAY != vam->json_tree.type) {
7179 ASSERT(VAT_JSON_NONE == vam->json_tree.type);
7180 vat_json_init_array(&vam->json_tree);
7182 node = vat_json_array_add(&vam->json_tree);
7184 vat_json_init_object(node);
7186 clib_memcpy(&addr, mp->our_address, sizeof(addr));
7187 vat_json_object_add_ip6(node, "our_address", addr);
7188 clib_memcpy(&addr, mp->client_address, sizeof(addr));
7189 vat_json_object_add_ip6(node, "client_address", addr);
7191 vat_json_node_t * lc = vat_json_object_add(node, "local_cookie");
7192 vat_json_init_array(lc);
7193 vat_json_array_add_uint(lc, clib_net_to_host_u64(mp->local_cookie[0]));
7194 vat_json_array_add_uint(lc, clib_net_to_host_u64(mp->local_cookie[1]));
7195 vat_json_object_add_uint(node, "remote_cookie", clib_net_to_host_u64(mp->remote_cookie));
7197 printf("local id: %u", clib_net_to_host_u32(mp->local_session_id));
7198 vat_json_object_add_uint(node, "local_session_id", clib_net_to_host_u32(mp->local_session_id));
7199 vat_json_object_add_uint(node, "remote_session_id", clib_net_to_host_u32(mp->remote_session_id));
7200 vat_json_object_add_string_copy(node, "l2_sublayer", mp->l2_sublayer_present ?
7201 (u8*)"present" : (u8*)"absent");
7204 static int api_sw_if_l2tpv3_tunnel_dump (vat_main_t * vam)
7206 vl_api_sw_if_l2tpv3_tunnel_dump_t *mp;
7209 /* Get list of l2tpv3-tunnel interfaces */
7210 M(SW_IF_L2TPV3_TUNNEL_DUMP, sw_if_l2tpv3_tunnel_dump);
7213 /* Use a control ping for synchronization */
7215 vl_api_control_ping_t * mp;
7216 M(CONTROL_PING, control_ping);
7223 static void vl_api_sw_interface_tap_details_t_handler
7224 (vl_api_sw_interface_tap_details_t * mp)
7226 vat_main_t * vam = &vat_main;
7228 fformat(vam->ofp, "%-16s %d\n",
7230 clib_net_to_host_u32(mp->sw_if_index));
7233 static void vl_api_sw_interface_tap_details_t_handler_json
7234 (vl_api_sw_interface_tap_details_t * mp)
7236 vat_main_t * vam = &vat_main;
7237 vat_json_node_t *node = NULL;
7239 if (VAT_JSON_ARRAY != vam->json_tree.type) {
7240 ASSERT(VAT_JSON_NONE == vam->json_tree.type);
7241 vat_json_init_array(&vam->json_tree);
7243 node = vat_json_array_add(&vam->json_tree);
7245 vat_json_init_object(node);
7246 vat_json_object_add_uint(node, "sw_if_index", ntohl(mp->sw_if_index));
7247 vat_json_object_add_string_copy(node, "dev_name", mp->dev_name);
7250 static int api_sw_interface_tap_dump (vat_main_t * vam)
7252 vl_api_sw_interface_tap_dump_t *mp;
7255 fformat(vam->ofp, "\n%-16s %s\n", "dev_name", "sw_if_index");
7256 /* Get list of tap interfaces */
7257 M(SW_INTERFACE_TAP_DUMP, sw_interface_tap_dump);
7260 /* Use a control ping for synchronization */
7262 vl_api_control_ping_t * mp;
7263 M(CONTROL_PING, control_ping);
7269 static uword unformat_vxlan_decap_next
7270 (unformat_input_t * input, va_list * args)
7272 u32 * result = va_arg (*args, u32 *);
7275 if (unformat (input, "drop"))
7276 *result = VXLAN_INPUT_NEXT_DROP;
7277 else if (unformat (input, "ip4"))
7278 *result = VXLAN_INPUT_NEXT_IP4_INPUT;
7279 else if (unformat (input, "ip6"))
7280 *result = VXLAN_INPUT_NEXT_IP6_INPUT;
7281 else if (unformat (input, "l2"))
7282 *result = VXLAN_INPUT_NEXT_L2_INPUT;
7283 else if (unformat (input, "%d", &tmp))
7290 static int api_vxlan_add_del_tunnel (vat_main_t * vam)
7292 unformat_input_t * line_input = vam->input;
7293 vl_api_vxlan_add_del_tunnel_t *mp;
7295 ip4_address_t src4, dst4;
7296 ip6_address_t src6, dst6;
7298 u8 ipv4_set = 0, ipv6_set = 0;
7301 u32 encap_vrf_id = 0;
7302 u32 decap_next_index = ~0;
7305 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) {
7306 if (unformat (line_input, "del"))
7308 else if (unformat (line_input, "src %U",
7309 unformat_ip4_address, &src4))
7314 else if (unformat (line_input, "dst %U",
7315 unformat_ip4_address, &dst4))
7320 else if (unformat (line_input, "src %U",
7321 unformat_ip6_address, &src6))
7326 else if (unformat (line_input, "dst %U",
7327 unformat_ip6_address, &dst6))
7332 else if (unformat (line_input, "encap-vrf-id %d", &encap_vrf_id))
7334 else if (unformat (line_input, "decap-next %U",
7335 unformat_vxlan_decap_next, &decap_next_index))
7337 else if (unformat (line_input, "vni %d", &vni))
7340 errmsg ("parse error '%U'\n", format_unformat_error, line_input);
7346 errmsg ("tunnel src address not specified\n");
7350 errmsg ("tunnel dst address not specified\n");
7354 if (ipv4_set && ipv6_set) {
7355 errmsg ("both IPv4 and IPv6 addresses specified");
7359 if ((vni == 0) || (vni>>24)) {
7360 errmsg ("vni not specified or out of range\n");
7364 M (VXLAN_ADD_DEL_TUNNEL, vxlan_add_del_tunnel);
7367 clib_memcpy(&mp->dst_address, &src6, sizeof(src6));
7368 clib_memcpy(&mp->dst_address, &src6, sizeof(dst6));
7370 clib_memcpy(&mp->src_address, &src4, sizeof(src4));
7371 clib_memcpy(&mp->dst_address, &dst4, sizeof(dst4));
7373 mp->encap_vrf_id = ntohl(encap_vrf_id);
7374 mp->decap_next_index = ntohl(decap_next_index);
7375 mp->vni = ntohl(vni);
7376 mp->is_add = is_add;
7377 mp->is_ipv6 = ipv6_set;
7384 static void vl_api_vxlan_tunnel_details_t_handler
7385 (vl_api_vxlan_tunnel_details_t * mp)
7387 vat_main_t * vam = &vat_main;
7389 fformat(vam->ofp, "%11d%24U%24U%14d%18d%13d\n",
7390 ntohl(mp->sw_if_index),
7391 format_ip46_address, &(mp->src_address[0]),
7392 format_ip46_address, &(mp->dst_address[0]),
7393 ntohl(mp->encap_vrf_id),
7394 ntohl(mp->decap_next_index),
7398 static void vl_api_vxlan_tunnel_details_t_handler_json
7399 (vl_api_vxlan_tunnel_details_t * mp)
7401 vat_main_t * vam = &vat_main;
7402 vat_json_node_t *node = NULL;
7404 struct in6_addr ip6;
7406 if (VAT_JSON_ARRAY != vam->json_tree.type) {
7407 ASSERT(VAT_JSON_NONE == vam->json_tree.type);
7408 vat_json_init_array(&vam->json_tree);
7410 node = vat_json_array_add(&vam->json_tree);
7412 vat_json_init_object(node);
7413 vat_json_object_add_uint(node, "sw_if_index", ntohl(mp->sw_if_index));
7415 clib_memcpy(&ip6, &(mp->src_address[0]), sizeof(ip6));
7416 vat_json_object_add_ip6(node, "src_address", ip6);
7417 clib_memcpy(&ip6, &(mp->dst_address[0]), sizeof(ip6));
7418 vat_json_object_add_ip6(node, "dst_address", ip6);
7420 clib_memcpy(&ip4, &(mp->src_address[0]), sizeof(ip4));
7421 vat_json_object_add_ip4(node, "src_address", ip4);
7422 clib_memcpy(&ip4, &(mp->dst_address[0]), sizeof(ip4));
7423 vat_json_object_add_ip4(node, "dst_address", ip4);
7425 vat_json_object_add_uint(node, "encap_vrf_id", ntohl(mp->encap_vrf_id));
7426 vat_json_object_add_uint(node, "decap_next_index", ntohl(mp->decap_next_index));
7427 vat_json_object_add_uint(node, "vni", ntohl(mp->vni));
7428 vat_json_object_add_uint(node, "is_ipv6", mp->is_ipv6 ? 1 : 0);
7431 static int api_vxlan_tunnel_dump (vat_main_t * vam)
7433 unformat_input_t * i = vam->input;
7434 vl_api_vxlan_tunnel_dump_t *mp;
7437 u8 sw_if_index_set = 0;
7439 /* Parse args required to build the message */
7440 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
7441 if (unformat (i, "sw_if_index %d", &sw_if_index))
7442 sw_if_index_set = 1;
7447 if (sw_if_index_set == 0) {
7451 if (!vam->json_output) {
7452 fformat(vam->ofp, "%11s%24s%24s%14s%18s%13s\n",
7453 "sw_if_index", "src_address", "dst_address",
7454 "encap_vrf_id", "decap_next_index", "vni");
7457 /* Get list of vxlan-tunnel interfaces */
7458 M(VXLAN_TUNNEL_DUMP, vxlan_tunnel_dump);
7460 mp->sw_if_index = htonl(sw_if_index);
7464 /* Use a control ping for synchronization */
7466 vl_api_control_ping_t * mp;
7467 M(CONTROL_PING, control_ping);
7473 static int api_gre_add_del_tunnel (vat_main_t * vam)
7475 unformat_input_t * line_input = vam->input;
7476 vl_api_gre_add_del_tunnel_t *mp;
7478 ip4_address_t src4, dst4;
7482 u32 outer_fib_id = 0;
7484 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) {
7485 if (unformat (line_input, "del"))
7487 else if (unformat (line_input, "src %U",
7488 unformat_ip4_address, &src4))
7490 else if (unformat (line_input, "dst %U",
7491 unformat_ip4_address, &dst4))
7493 else if (unformat (line_input, "outer-fib-id %d", &outer_fib_id))
7496 errmsg ("parse error '%U'\n", format_unformat_error, line_input);
7502 errmsg ("tunnel src address not specified\n");
7506 errmsg ("tunnel dst address not specified\n");
7511 M (GRE_ADD_DEL_TUNNEL, gre_add_del_tunnel);
7513 clib_memcpy(&mp->src_address, &src4, sizeof(src4));
7514 clib_memcpy(&mp->dst_address, &dst4, sizeof(dst4));
7515 mp->outer_table_id = ntohl(outer_fib_id);
7516 mp->is_add = is_add;
7523 static void vl_api_gre_tunnel_details_t_handler
7524 (vl_api_gre_tunnel_details_t * mp)
7526 vat_main_t * vam = &vat_main;
7528 fformat(vam->ofp, "%11d%15U%15U%14d\n",
7529 ntohl(mp->sw_if_index),
7530 format_ip4_address, &mp->src_address,
7531 format_ip4_address, &mp->dst_address,
7532 ntohl(mp->outer_table_id));
7535 static void vl_api_gre_tunnel_details_t_handler_json
7536 (vl_api_gre_tunnel_details_t * mp)
7538 vat_main_t * vam = &vat_main;
7539 vat_json_node_t *node = NULL;
7542 if (VAT_JSON_ARRAY != vam->json_tree.type) {
7543 ASSERT(VAT_JSON_NONE == vam->json_tree.type);
7544 vat_json_init_array(&vam->json_tree);
7546 node = vat_json_array_add(&vam->json_tree);
7548 vat_json_init_object(node);
7549 vat_json_object_add_uint(node, "sw_if_index", ntohl(mp->sw_if_index));
7550 clib_memcpy(&ip4, &mp->src_address, sizeof(ip4));
7551 vat_json_object_add_ip4(node, "src_address", ip4);
7552 clib_memcpy(&ip4, &mp->dst_address, sizeof(ip4));
7553 vat_json_object_add_ip4(node, "dst_address", ip4);
7554 vat_json_object_add_uint(node, "outer_fib_id", ntohl(mp->outer_table_id));
7557 static int api_gre_tunnel_dump (vat_main_t * vam)
7559 unformat_input_t * i = vam->input;
7560 vl_api_gre_tunnel_dump_t *mp;
7563 u8 sw_if_index_set = 0;
7565 /* Parse args required to build the message */
7566 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
7567 if (unformat (i, "sw_if_index %d", &sw_if_index))
7568 sw_if_index_set = 1;
7573 if (sw_if_index_set == 0) {
7577 if (!vam->json_output) {
7578 fformat(vam->ofp, "%11s%15s%15s%14s\n",
7579 "sw_if_index", "src_address", "dst_address",
7583 /* Get list of gre-tunnel interfaces */
7584 M(GRE_TUNNEL_DUMP, gre_tunnel_dump);
7586 mp->sw_if_index = htonl(sw_if_index);
7590 /* Use a control ping for synchronization */
7592 vl_api_control_ping_t * mp;
7593 M(CONTROL_PING, control_ping);
7599 static int api_l2_fib_clear_table (vat_main_t * vam)
7601 // unformat_input_t * i = vam->input;
7602 vl_api_l2_fib_clear_table_t *mp;
7605 M(L2_FIB_CLEAR_TABLE, l2_fib_clear_table);
7612 static int api_l2_interface_efp_filter (vat_main_t * vam)
7614 unformat_input_t * i = vam->input;
7615 vl_api_l2_interface_efp_filter_t *mp;
7619 u8 sw_if_index_set = 0;
7621 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
7622 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
7623 sw_if_index_set = 1;
7624 else if (unformat (i, "sw_if_index %d", &sw_if_index))
7625 sw_if_index_set = 1;
7626 else if (unformat (i, "enable"))
7628 else if (unformat (i, "disable"))
7631 clib_warning ("parse error '%U'", format_unformat_error, i);
7636 if (sw_if_index_set == 0) {
7637 errmsg ("missing sw_if_index\n");
7641 M(L2_INTERFACE_EFP_FILTER, l2_interface_efp_filter);
7643 mp->sw_if_index = ntohl(sw_if_index);
7644 mp->enable_disable = enable;
7651 #define foreach_vtr_op \
7652 _("disable", L2_VTR_DISABLED) \
7653 _("push-1", L2_VTR_PUSH_1) \
7654 _("push-2", L2_VTR_PUSH_2) \
7655 _("pop-1", L2_VTR_POP_1) \
7656 _("pop-2", L2_VTR_POP_2) \
7657 _("translate-1-1", L2_VTR_TRANSLATE_1_1) \
7658 _("translate-1-2", L2_VTR_TRANSLATE_1_2) \
7659 _("translate-2-1", L2_VTR_TRANSLATE_2_1) \
7660 _("translate-2-2", L2_VTR_TRANSLATE_2_2)
7662 static int api_l2_interface_vlan_tag_rewrite (vat_main_t * vam)
7664 unformat_input_t * i = vam->input;
7665 vl_api_l2_interface_vlan_tag_rewrite_t *mp;
7668 u8 sw_if_index_set = 0;
7675 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
7676 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
7677 sw_if_index_set = 1;
7678 else if (unformat (i, "sw_if_index %d", &sw_if_index))
7679 sw_if_index_set = 1;
7680 else if (unformat (i, "vtr_op %d", &vtr_op))
7682 #define _(n,v) else if (unformat(i, n)) {vtr_op = v; vtr_op_set = 1;}
7686 else if (unformat (i, "push_dot1q %d", &push_dot1q))
7688 else if (unformat (i, "tag1 %d", &tag1))
7690 else if (unformat (i, "tag2 %d", &tag2))
7693 clib_warning ("parse error '%U'", format_unformat_error, i);
7698 if ((sw_if_index_set == 0)||(vtr_op_set == 0)) {
7699 errmsg ("missing vtr operation or sw_if_index\n");
7703 M(L2_INTERFACE_VLAN_TAG_REWRITE, l2_interface_vlan_tag_rewrite)
7705 mp->sw_if_index = ntohl(sw_if_index);
7706 mp->vtr_op = ntohl(vtr_op);
7707 mp->push_dot1q = ntohl(push_dot1q);
7708 mp->tag1 = ntohl(tag1);
7709 mp->tag2 = ntohl(tag2);
7716 static int api_create_vhost_user_if (vat_main_t * vam)
7718 unformat_input_t * i = vam->input;
7719 vl_api_create_vhost_user_if_t *mp;
7723 u8 file_name_set = 0;
7724 u32 custom_dev_instance = ~0;
7726 u8 use_custom_mac = 0;
7728 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
7729 if (unformat (i, "socket %s", &file_name)) {
7732 else if (unformat (i, "renumber %"PRIu32, &custom_dev_instance))
7734 else if (unformat (i, "mac %U", unformat_ethernet_address, hwaddr))
7736 else if (unformat (i, "server"))
7742 if (file_name_set == 0) {
7743 errmsg ("missing socket file name\n");
7747 if (vec_len (file_name) > 255) {
7748 errmsg ("socket file name too long\n");
7751 vec_add1 (file_name, 0);
7753 M(CREATE_VHOST_USER_IF, create_vhost_user_if);
7755 mp->is_server = is_server;
7756 clib_memcpy(mp->sock_filename, file_name, vec_len(file_name));
7757 vec_free(file_name);
7758 if (custom_dev_instance != ~0) {
7760 mp->custom_dev_instance = ntohl(custom_dev_instance);
7762 mp->use_custom_mac = use_custom_mac;
7763 clib_memcpy(mp->mac_address, hwaddr, 6);
7770 static int api_modify_vhost_user_if (vat_main_t * vam)
7772 unformat_input_t * i = vam->input;
7773 vl_api_modify_vhost_user_if_t *mp;
7777 u8 file_name_set = 0;
7778 u32 custom_dev_instance = ~0;
7779 u8 sw_if_index_set = 0;
7780 u32 sw_if_index = (u32)~0;
7782 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
7783 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
7784 sw_if_index_set = 1;
7785 else if (unformat (i, "sw_if_index %d", &sw_if_index))
7786 sw_if_index_set = 1;
7787 else if (unformat (i, "socket %s", &file_name)) {
7790 else if (unformat (i, "renumber %"PRIu32, &custom_dev_instance))
7792 else if (unformat (i, "server"))
7798 if (sw_if_index_set == 0) {
7799 errmsg ("missing sw_if_index or interface name\n");
7803 if (file_name_set == 0) {
7804 errmsg ("missing socket file name\n");
7808 if (vec_len (file_name) > 255) {
7809 errmsg ("socket file name too long\n");
7812 vec_add1 (file_name, 0);
7814 M(MODIFY_VHOST_USER_IF, modify_vhost_user_if);
7816 mp->sw_if_index = ntohl(sw_if_index);
7817 mp->is_server = is_server;
7818 clib_memcpy(mp->sock_filename, file_name, vec_len(file_name));
7819 vec_free(file_name);
7820 if (custom_dev_instance != ~0) {
7822 mp->custom_dev_instance = ntohl(custom_dev_instance);
7830 static int api_delete_vhost_user_if (vat_main_t * vam)
7832 unformat_input_t * i = vam->input;
7833 vl_api_delete_vhost_user_if_t *mp;
7835 u32 sw_if_index = ~0;
7836 u8 sw_if_index_set = 0;
7838 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
7839 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
7840 sw_if_index_set = 1;
7841 else if (unformat (i, "sw_if_index %d", &sw_if_index))
7842 sw_if_index_set = 1;
7847 if (sw_if_index_set == 0) {
7848 errmsg ("missing sw_if_index or interface name\n");
7853 M(DELETE_VHOST_USER_IF, delete_vhost_user_if);
7855 mp->sw_if_index = ntohl(sw_if_index);
7862 static void vl_api_sw_interface_vhost_user_details_t_handler
7863 (vl_api_sw_interface_vhost_user_details_t * mp)
7865 vat_main_t * vam = &vat_main;
7867 fformat(vam->ofp, "%-25s %3" PRIu32 " %6" PRIu32 " %8x %6d %7d %s\n",
7868 (char *)mp->interface_name,
7869 ntohl(mp->sw_if_index), ntohl(mp->virtio_net_hdr_sz),
7870 clib_net_to_host_u64(mp->features), mp->is_server,
7871 ntohl(mp->num_regions), (char *)mp->sock_filename);
7872 fformat(vam->ofp, " Status: '%s'\n", strerror(ntohl(mp->sock_errno)));
7875 static void vl_api_sw_interface_vhost_user_details_t_handler_json
7876 (vl_api_sw_interface_vhost_user_details_t * mp)
7878 vat_main_t * vam = &vat_main;
7879 vat_json_node_t *node = NULL;
7881 if (VAT_JSON_ARRAY != vam->json_tree.type) {
7882 ASSERT(VAT_JSON_NONE == vam->json_tree.type);
7883 vat_json_init_array(&vam->json_tree);
7885 node = vat_json_array_add(&vam->json_tree);
7887 vat_json_init_object(node);
7888 vat_json_object_add_uint(node, "sw_if_index", ntohl(mp->sw_if_index));
7889 vat_json_object_add_string_copy(node, "interface_name", mp->interface_name);
7890 vat_json_object_add_uint(node, "virtio_net_hdr_sz", ntohl(mp->virtio_net_hdr_sz));
7891 vat_json_object_add_uint(node, "features", clib_net_to_host_u64(mp->features));
7892 vat_json_object_add_uint(node, "is_server", mp->is_server);
7893 vat_json_object_add_string_copy(node, "sock_filename", mp->sock_filename);
7894 vat_json_object_add_uint(node, "num_regions", ntohl(mp->num_regions));
7895 vat_json_object_add_uint(node, "sock_errno", ntohl(mp->sock_errno));
7898 static int api_sw_interface_vhost_user_dump (vat_main_t * vam)
7900 vl_api_sw_interface_vhost_user_dump_t *mp;
7902 fformat(vam->ofp, "Interface name idx hdr_sz features server regions filename\n");
7904 /* Get list of vhost-user interfaces */
7905 M(SW_INTERFACE_VHOST_USER_DUMP, sw_interface_vhost_user_dump);
7908 /* Use a control ping for synchronization */
7910 vl_api_control_ping_t * mp;
7911 M(CONTROL_PING, control_ping);
7917 static int api_show_version (vat_main_t * vam)
7919 vl_api_show_version_t *mp;
7922 M(SHOW_VERSION, show_version);
7930 static int api_vxlan_gpe_add_del_tunnel (vat_main_t * vam)
7932 unformat_input_t * line_input = vam->input;
7933 vl_api_vxlan_gpe_add_del_tunnel_t *mp;
7935 ip4_address_t local, remote;
7939 u32 encap_vrf_id = 0;
7940 u32 decap_vrf_id = 0;
7945 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) {
7946 if (unformat (line_input, "del"))
7948 else if (unformat (line_input, "local %U",
7949 unformat_ip4_address, &local))
7951 else if (unformat (line_input, "remote %U",
7952 unformat_ip4_address, &remote))
7954 else if (unformat (line_input, "encap-vrf-id %d", &encap_vrf_id))
7956 else if (unformat (line_input, "decap-vrf-id %d", &decap_vrf_id))
7958 else if (unformat (line_input, "vni %d", &vni))
7960 else if (unformat(line_input, "next-ip4"))
7962 else if (unformat(line_input, "next-ip6"))
7964 else if (unformat(line_input, "next-ethernet"))
7966 else if (unformat(line_input, "next-nsh"))
7969 errmsg ("parse error '%U'\n", format_unformat_error, line_input);
7974 if (local_set == 0) {
7975 errmsg ("tunnel local address not specified\n");
7978 if (remote_set == 0) {
7979 errmsg ("tunnel remote address not specified\n");
7984 errmsg ("vni not specified\n");
7988 M(VXLAN_GPE_ADD_DEL_TUNNEL, vxlan_gpe_add_del_tunnel);
7990 mp->local = local.as_u32;
7991 mp->remote = remote.as_u32;
7992 mp->encap_vrf_id = ntohl(encap_vrf_id);
7993 mp->decap_vrf_id = ntohl(decap_vrf_id);
7994 mp->protocol = ntohl(protocol);
7995 mp->vni = ntohl(vni);
7996 mp->is_add = is_add;
8004 u8 * format_l2_fib_mac_address (u8 * s, va_list * args)
8006 u8 * a = va_arg (*args, u8 *);
8008 return format (s, "%02x:%02x:%02x:%02x:%02x:%02x",
8009 a[2], a[3], a[4], a[5], a[6], a[7]);
8012 static void vl_api_l2_fib_table_entry_t_handler
8013 (vl_api_l2_fib_table_entry_t * mp)
8015 vat_main_t * vam = &vat_main;
8017 fformat(vam->ofp, "%3" PRIu32 " %U %3" PRIu32
8019 ntohl(mp->bd_id), format_l2_fib_mac_address, &mp->mac,
8020 ntohl(mp->sw_if_index), mp->static_mac, mp->filter_mac,
8024 static void vl_api_l2_fib_table_entry_t_handler_json
8025 (vl_api_l2_fib_table_entry_t * mp)
8027 vat_main_t * vam = &vat_main;
8028 vat_json_node_t *node = NULL;
8030 if (VAT_JSON_ARRAY != vam->json_tree.type) {
8031 ASSERT(VAT_JSON_NONE == vam->json_tree.type);
8032 vat_json_init_array(&vam->json_tree);
8034 node = vat_json_array_add(&vam->json_tree);
8036 vat_json_init_object(node);
8037 vat_json_object_add_uint(node, "bd_id", ntohl(mp->bd_id));
8038 vat_json_object_add_uint(node, "mac", clib_net_to_host_u64(mp->mac));
8039 vat_json_object_add_uint(node, "sw_if_index", ntohl(mp->sw_if_index));
8040 vat_json_object_add_uint(node, "static_mac", mp->static_mac);
8041 vat_json_object_add_uint(node, "filter_mac", mp->filter_mac);
8042 vat_json_object_add_uint(node, "bvi_mac", mp->bvi_mac);
8045 static int api_l2_fib_table_dump (vat_main_t * vam)
8047 unformat_input_t * i = vam->input;
8048 vl_api_l2_fib_table_dump_t *mp;
8053 /* Parse args required to build the message */
8054 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
8055 if (unformat (i, "bd_id %d", &bd_id))
8061 if (bd_id_set == 0) {
8062 errmsg ("missing bridge domain\n");
8066 fformat(vam->ofp, "BD-ID Mac Address sw-ndx Static Filter BVI\n");
8068 /* Get list of l2 fib entries */
8069 M(L2_FIB_TABLE_DUMP, l2_fib_table_dump);
8071 mp->bd_id = ntohl(bd_id);
8074 /* Use a control ping for synchronization */
8076 vl_api_control_ping_t * mp;
8077 M(CONTROL_PING, control_ping);
8085 api_interface_name_renumber (vat_main_t * vam)
8087 unformat_input_t * line_input = vam->input;
8088 vl_api_interface_name_renumber_t *mp;
8089 u32 sw_if_index = ~0;
8091 u32 new_show_dev_instance = ~0;
8093 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) {
8094 if (unformat (line_input, "%U", unformat_sw_if_index, vam,
8097 else if (unformat (line_input, "sw_if_index %d", &sw_if_index))
8099 else if (unformat (line_input, "new_show_dev_instance %d",
8100 &new_show_dev_instance))
8106 if (sw_if_index == ~0) {
8107 errmsg ("missing interface name or sw_if_index\n");
8111 if (new_show_dev_instance == ~0) {
8112 errmsg ("missing new_show_dev_instance\n");
8116 M(INTERFACE_NAME_RENUMBER, interface_name_renumber);
8118 mp->sw_if_index = ntohl (sw_if_index);
8119 mp->new_show_dev_instance = ntohl (new_show_dev_instance);
8125 api_want_ip4_arp_events (vat_main_t * vam)
8127 unformat_input_t * line_input = vam->input;
8128 vl_api_want_ip4_arp_events_t * mp;
8130 ip4_address_t address;
8131 int address_set = 0;
8132 u32 enable_disable = 1;
8134 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) {
8135 if (unformat (line_input, "address %U",
8136 unformat_ip4_address, &address))
8138 else if (unformat (line_input, "del"))
8144 if (address_set == 0) {
8145 errmsg ("missing addresses\n");
8149 M(WANT_IP4_ARP_EVENTS, want_ip4_arp_events);
8150 mp->enable_disable = enable_disable;
8152 mp->address = address.as_u32;
8157 static int api_input_acl_set_interface (vat_main_t * vam)
8159 unformat_input_t * i = vam->input;
8160 vl_api_input_acl_set_interface_t *mp;
8163 int sw_if_index_set;
8164 u32 ip4_table_index = ~0;
8165 u32 ip6_table_index = ~0;
8166 u32 l2_table_index = ~0;
8169 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
8170 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
8171 sw_if_index_set = 1;
8172 else if (unformat (i, "sw_if_index %d", &sw_if_index))
8173 sw_if_index_set = 1;
8174 else if (unformat (i, "del"))
8176 else if (unformat (i, "ip4-table %d", &ip4_table_index))
8178 else if (unformat (i, "ip6-table %d", &ip6_table_index))
8180 else if (unformat (i, "l2-table %d", &l2_table_index))
8183 clib_warning ("parse error '%U'", format_unformat_error, i);
8188 if (sw_if_index_set == 0) {
8189 errmsg ("missing interface name or sw_if_index\n");
8193 M(INPUT_ACL_SET_INTERFACE, input_acl_set_interface);
8195 mp->sw_if_index = ntohl(sw_if_index);
8196 mp->ip4_table_index = ntohl(ip4_table_index);
8197 mp->ip6_table_index = ntohl(ip6_table_index);
8198 mp->l2_table_index = ntohl(l2_table_index);
8199 mp->is_add = is_add;
8207 api_ip_address_dump (vat_main_t * vam)
8209 unformat_input_t * i = vam->input;
8210 vl_api_ip_address_dump_t * mp;
8211 u32 sw_if_index = ~0;
8212 u8 sw_if_index_set = 0;
8217 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
8218 if (unformat (i, "sw_if_index %d", &sw_if_index))
8219 sw_if_index_set = 1;
8220 else if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
8221 sw_if_index_set = 1;
8222 else if (unformat (i, "ipv4"))
8224 else if (unformat (i, "ipv6"))
8230 if (ipv4_set && ipv6_set) {
8231 errmsg ("ipv4 and ipv6 flags cannot be both set\n");
8235 if ((!ipv4_set) && (!ipv6_set)) {
8236 errmsg ("no ipv4 nor ipv6 flag set\n");
8240 if (sw_if_index_set == 0) {
8241 errmsg ("missing interface name or sw_if_index\n");
8245 vam->current_sw_if_index = sw_if_index;
8246 vam->is_ipv6 = ipv6_set;
8248 M(IP_ADDRESS_DUMP, ip_address_dump);
8249 mp->sw_if_index = ntohl(sw_if_index);
8250 mp->is_ipv6 = ipv6_set;
8253 /* Use a control ping for synchronization */
8255 vl_api_control_ping_t * mp;
8256 M(CONTROL_PING, control_ping);
8263 api_ip_dump (vat_main_t * vam)
8265 vl_api_ip_dump_t * mp;
8266 unformat_input_t * in = vam->input;
8273 while (unformat_check_input (in) != UNFORMAT_END_OF_INPUT) {
8274 if (unformat (in, "ipv4"))
8276 else if (unformat (in, "ipv6"))
8282 if (ipv4_set && ipv6_set) {
8283 errmsg ("ipv4 and ipv6 flags cannot be both set\n");
8287 if ((!ipv4_set) && (!ipv6_set)) {
8288 errmsg ("no ipv4 nor ipv6 flag set\n");
8293 vam->is_ipv6 = is_ipv6;
8296 for (i = 0; i < vec_len(vam->ip_details_by_sw_if_index[is_ipv6]); i++) {
8297 vec_free(vam->ip_details_by_sw_if_index[is_ipv6][i].addr);
8299 vec_free(vam->ip_details_by_sw_if_index[is_ipv6]);
8301 M(IP_DUMP, ip_dump);
8302 mp->is_ipv6 = ipv6_set;
8305 /* Use a control ping for synchronization */
8307 vl_api_control_ping_t * mp;
8308 M(CONTROL_PING, control_ping);
8315 api_ipsec_spd_add_del (vat_main_t * vam)
8318 unformat_input_t * i = vam->input;
8319 vl_api_ipsec_spd_add_del_t *mp;
8324 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
8325 if (unformat (i, "spd_id %d", &spd_id))
8327 else if (unformat (i, "del"))
8330 clib_warning ("parse error '%U'", format_unformat_error, i);
8335 errmsg ("spd_id must be set\n");
8339 M(IPSEC_SPD_ADD_DEL, ipsec_spd_add_del);
8341 mp->spd_id = ntohl(spd_id);
8342 mp->is_add = is_add;
8348 clib_warning ("unsupported (no dpdk)");
8354 api_ipsec_interface_add_del_spd (vat_main_t * vam)
8357 unformat_input_t * i = vam->input;
8358 vl_api_ipsec_interface_add_del_spd_t *mp;
8361 u8 sw_if_index_set = 0;
8362 u32 spd_id = (u32) ~0;
8365 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
8366 if (unformat (i, "del"))
8368 else if (unformat (i, "spd_id %d", &spd_id))
8370 else if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
8371 sw_if_index_set = 1;
8372 else if (unformat (i, "sw_if_index %d", &sw_if_index))
8373 sw_if_index_set = 1;
8375 clib_warning ("parse error '%U'", format_unformat_error, i);
8381 if (spd_id == (u32) ~0) {
8382 errmsg ("spd_id must be set\n");
8386 if (sw_if_index_set == 0) {
8387 errmsg ("missing interface name or sw_if_index\n");
8391 M(IPSEC_INTERFACE_ADD_DEL_SPD, ipsec_interface_add_del_spd);
8393 mp->spd_id = ntohl(spd_id);
8394 mp->sw_if_index = ntohl (sw_if_index);
8395 mp->is_add = is_add;
8401 clib_warning ("unsupported (no dpdk)");
8407 api_ipsec_spd_add_del_entry (vat_main_t * vam)
8410 unformat_input_t * i = vam->input;
8411 vl_api_ipsec_spd_add_del_entry_t *mp;
8413 u8 is_add = 1, is_outbound = 0, is_ipv6 = 0, is_ip_any = 1;
8414 u32 spd_id, sa_id, protocol = 0, policy = 0;
8416 u32 rport_start = 0, rport_stop = (u32) ~0;
8417 u32 lport_start = 0, lport_stop = (u32) ~0;
8418 ip4_address_t laddr4_start, laddr4_stop, raddr4_start, raddr4_stop;
8419 ip6_address_t laddr6_start, laddr6_stop, raddr6_start, raddr6_stop;
8421 laddr4_start.as_u32 = raddr4_start.as_u32 = 0;
8422 laddr4_stop.as_u32 = raddr4_stop.as_u32 = (u32) ~0;
8423 laddr6_start.as_u64[0] = raddr6_start.as_u64[0] = 0;
8424 laddr6_start.as_u64[1] = raddr6_start.as_u64[1] = 0;
8425 laddr6_stop.as_u64[0] = raddr6_stop.as_u64[0] = (u64) ~0;
8426 laddr6_stop.as_u64[1] = raddr6_stop.as_u64[1] = (u64) ~0;
8428 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
8429 if (unformat (i, "del"))
8431 if (unformat (i, "outbound"))
8433 if (unformat (i, "inbound"))
8435 else if (unformat (i, "spd_id %d", &spd_id))
8437 else if (unformat (i, "sa_id %d", &sa_id))
8439 else if (unformat (i, "priority %d", &priority))
8441 else if (unformat (i, "protocol %d", &protocol))
8443 else if (unformat (i, "lport_start %d", &lport_start))
8445 else if (unformat (i, "lport_stop %d", &lport_stop))
8447 else if (unformat (i, "rport_start %d", &rport_start))
8449 else if (unformat (i, "rport_stop %d", &rport_stop))
8451 else if (unformat (i, "laddr_start %U", unformat_ip4_address, &laddr4_start))
8456 else if (unformat (i, "laddr_stop %U", unformat_ip4_address, &laddr4_stop))
8461 else if (unformat (i, "raddr_start %U", unformat_ip4_address, &raddr4_start))
8466 else if (unformat (i, "raddr_stop %U", unformat_ip4_address, &raddr4_stop))
8471 else if (unformat (i, "laddr_start %U", unformat_ip6_address, &laddr6_start))
8476 else if (unformat (i, "laddr_stop %U", unformat_ip6_address, &laddr6_stop))
8481 else if (unformat (i, "raddr_start %U", unformat_ip6_address, &raddr6_start))
8486 else if (unformat (i, "raddr_stop %U", unformat_ip6_address, &raddr6_stop))
8491 else if (unformat (i, "action %U", unformat_ipsec_policy_action, &policy))
8493 if (policy == IPSEC_POLICY_ACTION_RESOLVE) {
8494 clib_warning ("unsupported action: 'resolve'");
8499 clib_warning ("parse error '%U'", format_unformat_error, i);
8505 M(IPSEC_SPD_ADD_DEL_ENTRY, ipsec_spd_add_del_entry);
8507 mp->spd_id = ntohl(spd_id);
8508 mp->priority = ntohl(priority);
8509 mp->is_outbound = is_outbound;
8511 mp->is_ipv6 = is_ipv6;
8512 if (is_ipv6 || is_ip_any) {
8513 clib_memcpy (mp->remote_address_start, &raddr6_start, sizeof(ip6_address_t));
8514 clib_memcpy (mp->remote_address_stop, &raddr6_stop, sizeof(ip6_address_t));
8515 clib_memcpy (mp->local_address_start, &laddr6_start, sizeof(ip6_address_t));
8516 clib_memcpy (mp->local_address_stop, &laddr6_stop, sizeof(ip6_address_t));
8518 clib_memcpy (mp->remote_address_start, &raddr4_start, sizeof(ip4_address_t));
8519 clib_memcpy (mp->remote_address_stop, &raddr4_stop, sizeof(ip4_address_t));
8520 clib_memcpy (mp->local_address_start, &laddr4_start, sizeof(ip4_address_t));
8521 clib_memcpy (mp->local_address_stop, &laddr4_stop, sizeof(ip4_address_t));
8523 mp->protocol = (u8) protocol;
8524 mp->local_port_start = ntohs((u16) lport_start);
8525 mp->local_port_stop = ntohs((u16) lport_stop);
8526 mp->remote_port_start = ntohs((u16) rport_start);
8527 mp->remote_port_stop = ntohs((u16) rport_stop);
8528 mp->policy = (u8) policy;
8529 mp->sa_id = ntohl(sa_id);
8530 mp->is_add = is_add;
8531 mp->is_ip_any = is_ip_any;
8536 clib_warning ("unsupported (no dpdk)");
8542 api_ipsec_sad_add_del_entry (vat_main_t * vam)
8545 unformat_input_t * i = vam->input;
8546 vl_api_ipsec_sad_add_del_entry_t *mp;
8552 u8 protocol = IPSEC_PROTOCOL_AH;
8553 u8 is_tunnel = 0, is_tunnel_ipv6 = 0;
8554 u32 crypto_alg = 0, integ_alg = 0;
8555 ip4_address_t tun_src4;
8556 ip4_address_t tun_dst4;
8557 ip6_address_t tun_src6;
8558 ip6_address_t tun_dst6;
8560 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
8561 if (unformat (i, "del"))
8563 else if (unformat (i, "sad_id %d", &sad_id))
8565 else if (unformat (i, "spi %d", &spi))
8567 else if (unformat (i, "esp"))
8568 protocol = IPSEC_PROTOCOL_ESP;
8569 else if (unformat (i, "tunnel_src %U", unformat_ip4_address, &tun_src4)) {
8573 else if (unformat (i, "tunnel_dst %U", unformat_ip4_address, &tun_dst4)) {
8577 else if (unformat (i, "tunnel_src %U", unformat_ip6_address, &tun_src6)) {
8581 else if (unformat (i, "tunnel_dst %U", unformat_ip6_address, &tun_dst6)) {
8585 else if (unformat (i, "crypto_alg %U", unformat_ipsec_crypto_alg, &crypto_alg)) {
8586 if (crypto_alg < IPSEC_CRYPTO_ALG_AES_CBC_128 ||
8587 crypto_alg > IPSEC_INTEG_ALG_SHA_512_256) {
8588 clib_warning ("unsupported crypto-alg: '%U'",
8589 format_ipsec_crypto_alg, crypto_alg);
8593 else if (unformat (i, "crypto_key %U", unformat_hex_string, &ck))
8595 else if (unformat (i, "integ_alg %U", unformat_ipsec_integ_alg, &integ_alg)) {
8596 if (integ_alg < IPSEC_INTEG_ALG_SHA1_96 ||
8597 integ_alg > IPSEC_INTEG_ALG_SHA_512_256) {
8598 clib_warning ("unsupported integ-alg: '%U'",
8599 format_ipsec_integ_alg, integ_alg);
8603 else if (unformat (i, "integ_key %U", unformat_hex_string, &ik))
8606 clib_warning ("parse error '%U'", format_unformat_error, i);
8612 M(IPSEC_SAD_ADD_DEL_ENTRY, ipsec_sad_add_del_entry);
8614 mp->sad_id = ntohl(sad_id);
8615 mp->is_add = is_add;
8616 mp->protocol = protocol;
8617 mp->spi = ntohl(spi);
8618 mp->is_tunnel = is_tunnel;
8619 mp->is_tunnel_ipv6 = is_tunnel_ipv6;
8620 mp->crypto_algorithm = crypto_alg;
8621 mp->integrity_algorithm = integ_alg;
8622 mp->crypto_key_length = vec_len(ck);
8623 mp->integrity_key_length = vec_len(ik);
8625 if (mp->crypto_key_length > sizeof(mp->crypto_key))
8626 mp->crypto_key_length = sizeof(mp->crypto_key);
8628 if (mp->integrity_key_length > sizeof(mp->integrity_key))
8629 mp->integrity_key_length = sizeof(mp->integrity_key);
8631 clib_memcpy (mp->crypto_key, ck, mp->crypto_key_length);
8632 clib_memcpy (mp->integrity_key, ik, mp->integrity_key_length);
8635 if (is_tunnel_ipv6) {
8636 clib_memcpy (mp->tunnel_src_address, &tun_src6, sizeof(ip6_address_t));
8637 clib_memcpy (mp->tunnel_dst_address, &tun_dst6, sizeof(ip6_address_t));
8639 clib_memcpy (mp->tunnel_src_address, &tun_src4, sizeof(ip4_address_t));
8640 clib_memcpy (mp->tunnel_dst_address, &tun_dst4, sizeof(ip4_address_t));
8648 clib_warning ("unsupported (no dpdk)");
8654 api_ipsec_sa_set_key (vat_main_t * vam)
8657 unformat_input_t * i = vam->input;
8658 vl_api_ipsec_sa_set_key_t *mp;
8663 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
8664 if (unformat (i, "sa_id %d", &sa_id))
8666 else if (unformat (i, "crypto_key %U", unformat_hex_string, &ck))
8668 else if (unformat (i, "integ_key %U", unformat_hex_string, &ik))
8671 clib_warning ("parse error '%U'", format_unformat_error, i);
8676 M(IPSEC_SA_SET_KEY, ipsec_set_sa_key);
8678 mp->sa_id = ntohl(sa_id);
8679 mp->crypto_key_length = vec_len(ck);
8680 mp->integrity_key_length = vec_len(ik);
8682 if (mp->crypto_key_length > sizeof(mp->crypto_key))
8683 mp->crypto_key_length = sizeof(mp->crypto_key);
8685 if (mp->integrity_key_length > sizeof(mp->integrity_key))
8686 mp->integrity_key_length = sizeof(mp->integrity_key);
8688 clib_memcpy (mp->crypto_key, ck, mp->crypto_key_length);
8689 clib_memcpy (mp->integrity_key, ik, mp->integrity_key_length);
8695 clib_warning ("unsupported (no dpdk)");
8701 api_ikev2_profile_add_del (vat_main_t * vam)
8704 unformat_input_t * i = vam->input;
8705 vl_api_ikev2_profile_add_del_t * mp;
8710 const char * valid_chars = "a-zA-Z0-9_";
8712 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
8713 if (unformat (i, "del"))
8715 else if (unformat (i, "name %U", unformat_token, valid_chars, &name))
8718 errmsg ("parse error '%U'", format_unformat_error, i);
8723 if (!vec_len (name)) {
8724 errmsg ("profile name must be specified");
8728 if (vec_len (name) > 64) {
8729 errmsg ("profile name too long");
8733 M(IKEV2_PROFILE_ADD_DEL, ikev2_profile_add_del);
8735 clib_memcpy(mp->name, name, vec_len (name));
8736 mp->is_add = is_add;
8743 clib_warning ("unsupported (no dpdk)");
8749 api_ikev2_profile_set_auth (vat_main_t * vam)
8752 unformat_input_t * i = vam->input;
8753 vl_api_ikev2_profile_set_auth_t * mp;
8757 u32 auth_method = 0;
8760 const char * valid_chars = "a-zA-Z0-9_";
8762 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
8763 if (unformat (i, "name %U", unformat_token, valid_chars, &name))
8765 else if (unformat (i, "auth_method %U",
8766 unformat_ikev2_auth_method, &auth_method))
8768 else if (unformat (i, "auth_data 0x%U", unformat_hex_string, &data))
8770 else if (unformat (i, "auth_data %v", &data))
8773 errmsg ("parse error '%U'", format_unformat_error, i);
8778 if (!vec_len (name)) {
8779 errmsg ("profile name must be specified");
8783 if (vec_len (name) > 64) {
8784 errmsg ("profile name too long");
8788 if (!vec_len(data)) {
8789 errmsg ("auth_data must be specified");
8794 errmsg ("auth_method must be specified");
8798 M(IKEV2_PROFILE_SET_AUTH, ikev2_profile_set_auth);
8800 mp->is_hex = is_hex;
8801 mp->auth_method = (u8) auth_method;
8802 mp->data_len = vec_len (data);
8803 clib_memcpy (mp->name, name, vec_len (name));
8804 clib_memcpy (mp->data, data, vec_len (data));
8812 clib_warning ("unsupported (no dpdk)");
8818 api_ikev2_profile_set_id (vat_main_t * vam)
8821 unformat_input_t * i = vam->input;
8822 vl_api_ikev2_profile_set_id_t * mp;
8830 const char * valid_chars = "a-zA-Z0-9_";
8832 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
8833 if (unformat (i, "name %U", unformat_token, valid_chars, &name))
8835 else if (unformat (i, "id_type %U",
8836 unformat_ikev2_id_type, &id_type))
8838 else if (unformat (i, "id_data %U", unformat_ip4_address, &ip4))
8840 data = vec_new(u8, 4);
8841 clib_memcpy(data, ip4.as_u8, 4);
8843 else if (unformat (i, "id_data 0x%U", unformat_hex_string, &data))
8845 else if (unformat (i, "id_data %v", &data))
8847 else if (unformat (i, "local"))
8849 else if (unformat (i, "remote"))
8852 errmsg ("parse error '%U'", format_unformat_error, i);
8857 if (!vec_len (name)) {
8858 errmsg ("profile name must be specified");
8862 if (vec_len (name) > 64) {
8863 errmsg ("profile name too long");
8867 if (!vec_len(data)) {
8868 errmsg ("id_data must be specified");
8873 errmsg ("id_type must be specified");
8877 M(IKEV2_PROFILE_SET_ID, ikev2_profile_set_id);
8879 mp->is_local = is_local;
8880 mp->id_type = (u8) id_type;
8881 mp->data_len = vec_len (data);
8882 clib_memcpy (mp->name, name, vec_len (name));
8883 clib_memcpy (mp->data, data, vec_len (data));
8891 clib_warning ("unsupported (no dpdk)");
8897 api_ikev2_profile_set_ts (vat_main_t * vam)
8900 unformat_input_t * i = vam->input;
8901 vl_api_ikev2_profile_set_ts_t * mp;
8905 u32 proto = 0, start_port = 0, end_port = (u32) ~0;
8906 ip4_address_t start_addr, end_addr;
8908 const char * valid_chars = "a-zA-Z0-9_";
8910 start_addr.as_u32 = 0;
8911 end_addr.as_u32 = (u32) ~0;
8913 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
8914 if (unformat (i, "name %U", unformat_token, valid_chars, &name))
8916 else if (unformat (i, "protocol %d", &proto))
8918 else if (unformat (i, "start_port %d", &start_port))
8920 else if (unformat (i, "end_port %d", &end_port))
8922 else if (unformat (i, "start_addr %U", unformat_ip4_address, &start_addr))
8924 else if (unformat (i, "end_addr %U", unformat_ip4_address, &end_addr))
8926 else if (unformat (i, "local"))
8928 else if (unformat (i, "remote"))
8931 errmsg ("parse error '%U'", format_unformat_error, i);
8936 if (!vec_len (name)) {
8937 errmsg ("profile name must be specified");
8941 if (vec_len (name) > 64) {
8942 errmsg ("profile name too long");
8946 M(IKEV2_PROFILE_SET_TS, ikev2_profile_set_ts);
8948 mp->is_local = is_local;
8949 mp->proto = (u8) proto;
8950 mp->start_port = (u16) start_port;
8951 mp->end_port = (u16) end_port;
8952 mp->start_addr = start_addr.as_u32;
8953 mp->end_addr = end_addr.as_u32;
8954 clib_memcpy (mp->name, name, vec_len (name));
8961 clib_warning ("unsupported (no dpdk)");
8967 api_ikev2_set_local_key (vat_main_t * vam)
8970 unformat_input_t * i = vam->input;
8971 vl_api_ikev2_set_local_key_t * mp;
8975 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
8976 if (unformat (i, "file %v", &file))
8979 errmsg ("parse error '%U'", format_unformat_error, i);
8984 if (!vec_len (file)) {
8985 errmsg ("RSA key file must be specified");
8989 if (vec_len (file) > 256) {
8990 errmsg ("file name too long");
8994 M(IKEV2_SET_LOCAL_KEY, ikev2_set_local_key);
8996 clib_memcpy (mp->key_file, file, vec_len (file));
9003 clib_warning ("unsupported (no dpdk)");
9011 static int api_map_add_domain (vat_main_t * vam)
9013 unformat_input_t *i = vam->input;
9014 vl_api_map_add_domain_t *mp;
9017 ip4_address_t ip4_prefix;
9018 ip6_address_t ip6_prefix;
9019 ip6_address_t ip6_src;
9021 u32 ip6_prefix_len, ip4_prefix_len, ea_bits_len, psid_offset,
9023 u8 is_translation = 0;
9025 u8 ip6_src_len = 128;
9027 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
9028 if (unformat (i, "ip4-pfx %U/%d", unformat_ip4_address,
9029 &ip4_prefix, &ip4_prefix_len))
9031 else if (unformat (i, "ip6-pfx %U/%d", unformat_ip6_address,
9032 &ip6_prefix, &ip6_prefix_len))
9034 else if (unformat (i, "ip6-src %U/%d", unformat_ip6_address, &ip6_src, &ip6_src_len))
9036 else if (unformat (i, "ip6-src %U", unformat_ip6_address, &ip6_src))
9038 else if (unformat (i, "ea-bits-len %d", &ea_bits_len))
9040 else if (unformat (i, "psid-offset %d", &psid_offset))
9042 else if (unformat (i, "psid-len %d", &psid_length))
9044 else if (unformat (i, "mtu %d", &mtu))
9046 else if (unformat (i, "map-t"))
9049 clib_warning ("parse error '%U'", format_unformat_error, i);
9054 if (num_m_args != 6) {
9055 errmsg("mandatory argument(s) missing\n");
9059 /* Construct the API message */
9060 M(MAP_ADD_DOMAIN, map_add_domain);
9062 clib_memcpy(mp->ip4_prefix, &ip4_prefix, sizeof(ip4_prefix));
9063 mp->ip4_prefix_len = ip4_prefix_len;
9065 clib_memcpy(mp->ip6_prefix, &ip6_prefix, sizeof(ip6_prefix));
9066 mp->ip6_prefix_len = ip6_prefix_len;
9068 clib_memcpy(mp->ip6_src, &ip6_src, sizeof(ip6_src));
9069 mp->ip6_src_prefix_len = ip6_src_len;
9071 mp->ea_bits_len = ea_bits_len;
9072 mp->psid_offset = psid_offset;
9073 mp->psid_length = psid_length;
9074 mp->is_translation = is_translation;
9075 mp->mtu = htons(mtu);
9080 /* Wait for a reply, return good/bad news */
9084 static int api_map_del_domain (vat_main_t * vam)
9086 unformat_input_t *i = vam->input;
9087 vl_api_map_del_domain_t *mp;
9093 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
9094 if (unformat (i, "index %d", &index))
9097 clib_warning ("parse error '%U'", format_unformat_error, i);
9102 if (num_m_args != 1) {
9103 errmsg("mandatory argument(s) missing\n");
9107 /* Construct the API message */
9108 M(MAP_DEL_DOMAIN, map_del_domain);
9110 mp->index = ntohl(index);
9115 /* Wait for a reply, return good/bad news */
9119 static int api_map_add_del_rule (vat_main_t * vam)
9121 unformat_input_t *i = vam->input;
9122 vl_api_map_add_del_rule_t *mp;
9125 ip6_address_t ip6_dst;
9126 u32 num_m_args = 0, index, psid;
9128 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
9129 if (unformat (i, "index %d", &index))
9131 else if (unformat (i, "psid %d", &psid))
9133 else if (unformat (i, "dst %U", unformat_ip6_address, &ip6_dst))
9135 else if (unformat (i, "del")) {
9138 clib_warning ("parse error '%U'", format_unformat_error, i);
9143 /* Construct the API message */
9144 M(MAP_ADD_DEL_RULE, map_add_del_rule);
9146 mp->index = ntohl(index);
9147 mp->is_add = is_add;
9148 clib_memcpy(mp->ip6_dst, &ip6_dst, sizeof(ip6_dst));
9149 mp->psid = ntohs(psid);
9154 /* Wait for a reply, return good/bad news */
9158 static int api_map_domain_dump (vat_main_t * vam)
9160 vl_api_map_domain_dump_t *mp;
9163 /* Construct the API message */
9164 M(MAP_DOMAIN_DUMP, map_domain_dump);
9169 /* Use a control ping for synchronization */
9171 vl_api_control_ping_t * mp;
9172 M(CONTROL_PING, control_ping);
9178 static int api_map_rule_dump (vat_main_t * vam)
9180 unformat_input_t *i = vam->input;
9181 vl_api_map_rule_dump_t *mp;
9183 u32 domain_index = ~0;
9185 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
9186 if (unformat (i, "index %u", &domain_index))
9192 if (domain_index == ~0) {
9193 clib_warning("parse error: domain index expected");
9197 /* Construct the API message */
9198 M(MAP_RULE_DUMP, map_rule_dump);
9200 mp->domain_index = htonl(domain_index);
9205 /* Use a control ping for synchronization */
9207 vl_api_control_ping_t * mp;
9208 M(CONTROL_PING, control_ping);
9214 static void vl_api_map_add_domain_reply_t_handler
9215 (vl_api_map_add_domain_reply_t * mp)
9217 vat_main_t * vam = &vat_main;
9218 i32 retval = ntohl(mp->retval);
9220 if (vam->async_mode) {
9221 vam->async_errors += (retval < 0);
9223 vam->retval = retval;
9224 vam->result_ready = 1;
9228 static void vl_api_map_add_domain_reply_t_handler_json
9229 (vl_api_map_add_domain_reply_t * mp)
9231 vat_main_t * vam = &vat_main;
9232 vat_json_node_t node;
9234 vat_json_init_object(&node);
9235 vat_json_object_add_int(&node, "retval", ntohl(mp->retval));
9236 vat_json_object_add_uint(&node, "index", ntohl(mp->index));
9238 vat_json_print(vam->ofp, &node);
9239 vat_json_free(&node);
9241 vam->retval = ntohl(mp->retval);
9242 vam->result_ready = 1;
9246 api_get_first_msg_id (vat_main_t * vam)
9248 vl_api_get_first_msg_id_t * mp;
9250 unformat_input_t * i = vam->input;
9254 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
9255 if (unformat (i, "client %s", &name))
9261 if (name_set == 0) {
9262 errmsg ("missing client name\n");
9267 if (vec_len (name) > 63) {
9268 errmsg ("client name too long\n");
9272 M(GET_FIRST_MSG_ID, get_first_msg_id);
9273 clib_memcpy (mp->name, name, vec_len(name));
9279 static int api_cop_interface_enable_disable (vat_main_t * vam)
9281 unformat_input_t * line_input = vam->input;
9282 vl_api_cop_interface_enable_disable_t * mp;
9284 u32 sw_if_index = ~0;
9285 u8 enable_disable = 1;
9287 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) {
9288 if (unformat (line_input, "disable"))
9290 if (unformat (line_input, "enable"))
9292 else if (unformat (line_input, "%U", unformat_sw_if_index,
9295 else if (unformat (line_input, "sw_if_index %d", &sw_if_index))
9301 if (sw_if_index == ~0) {
9302 errmsg ("missing interface name or sw_if_index\n");
9306 /* Construct the API message */
9307 M(COP_INTERFACE_ENABLE_DISABLE, cop_interface_enable_disable);
9308 mp->sw_if_index = ntohl(sw_if_index);
9309 mp->enable_disable = enable_disable;
9313 /* Wait for the reply */
9317 static int api_cop_whitelist_enable_disable (vat_main_t * vam)
9319 unformat_input_t * line_input = vam->input;
9320 vl_api_cop_whitelist_enable_disable_t * mp;
9322 u32 sw_if_index = ~0;
9323 u8 ip4=0, ip6=0, default_cop=0;
9326 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) {
9327 if (unformat (line_input, "ip4"))
9329 else if (unformat (line_input, "ip6"))
9331 else if (unformat (line_input, "default"))
9333 else if (unformat (line_input, "%U", unformat_sw_if_index,
9336 else if (unformat (line_input, "sw_if_index %d", &sw_if_index))
9338 else if (unformat (line_input, "fib-id %d", &fib_id))
9344 if (sw_if_index == ~0) {
9345 errmsg ("missing interface name or sw_if_index\n");
9349 /* Construct the API message */
9350 M(COP_WHITELIST_ENABLE_DISABLE, cop_whitelist_enable_disable);
9351 mp->sw_if_index = ntohl(sw_if_index);
9352 mp->fib_id = ntohl(fib_id);
9355 mp->default_cop = default_cop;
9359 /* Wait for the reply */
9363 static int api_get_node_graph (vat_main_t * vam)
9365 vl_api_get_node_graph_t * mp;
9368 M(GET_NODE_GRAPH, get_node_graph);
9372 /* Wait for the reply */
9377 api_lisp_add_del_locator_set(vat_main_t * vam)
9379 unformat_input_t * input = vam->input;
9380 vl_api_lisp_add_del_locator_set_t *mp;
9383 u8 *locator_set_name = NULL;
9384 u8 locator_set_name_set = 0;
9386 /* Parse args required to build the message */
9387 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) {
9388 if (unformat(input, "del")) {
9390 } else if (unformat(input, "locator-set %s", &locator_set_name)) {
9391 locator_set_name_set = 1;
9396 if (locator_set_name_set == 0) {
9397 errmsg ("missing locator-set name");
9401 if (vec_len(locator_set_name) > 64) {
9402 errmsg ("locator-set name too long\n");
9403 vec_free(locator_set_name);
9406 vec_add1(locator_set_name, 0);
9408 /* Construct the API message */
9409 M(LISP_ADD_DEL_LOCATOR_SET, lisp_add_del_locator_set);
9411 mp->is_add = is_add;
9412 clib_memcpy(mp->locator_set_name, locator_set_name,
9413 vec_len(locator_set_name));
9414 vec_free(locator_set_name);
9419 /* Wait for a reply... */
9427 api_lisp_add_del_locator(vat_main_t * vam)
9429 unformat_input_t * input = vam->input;
9430 vl_api_lisp_add_del_locator_t *mp;
9432 u32 tmp_if_index = ~0;
9433 u32 sw_if_index = ~0;
9434 u8 sw_if_index_set = 0;
9435 u8 sw_if_index_if_name_set = 0;
9437 u8 priority_set = 0;
9441 u8 *locator_set_name = NULL;
9442 u8 locator_set_name_set = 0;
9444 /* Parse args required to build the message */
9445 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) {
9446 if (unformat(input, "del")) {
9448 } else if (unformat(input, "locator-set %s", &locator_set_name)) {
9449 locator_set_name_set = 1;
9450 } else if (unformat(input, "iface %U", unformat_sw_if_index, vam,
9452 sw_if_index_if_name_set = 1;
9453 sw_if_index = tmp_if_index;
9454 } else if (unformat(input,"sw_if_index %d", &tmp_if_index)) {
9455 sw_if_index_set = 1;
9456 sw_if_index = tmp_if_index;
9457 } else if (unformat(input, "p %d", &priority)) {
9459 } else if (unformat(input, "w %d", &weight)) {
9465 if (locator_set_name_set == 0) {
9466 errmsg ("missing locator-set name");
9470 if (sw_if_index_set == 0 && sw_if_index_if_name_set == 0) {
9471 errmsg ("missing sw_if_index");
9472 vec_free(locator_set_name);
9476 if (sw_if_index_set != 0 && sw_if_index_if_name_set != 0) {
9477 errmsg ("cannot use both params interface name and sw_if_index");
9478 vec_free(locator_set_name);
9482 if (priority_set == 0) {
9483 errmsg ("missing locator-set priority\n");
9484 vec_free(locator_set_name);
9488 if (weight_set == 0) {
9489 errmsg ("missing locator-set weight\n");
9490 vec_free(locator_set_name);
9494 if (vec_len(locator_set_name) > 64) {
9495 errmsg ("locator-set name too long\n");
9496 vec_free(locator_set_name);
9499 vec_add1(locator_set_name, 0);
9501 /* Construct the API message */
9502 M(LISP_ADD_DEL_LOCATOR, lisp_add_del_locator);
9504 mp->is_add = is_add;
9505 mp->sw_if_index = ntohl(sw_if_index);
9506 mp->priority = priority;
9507 mp->weight = weight;
9508 clib_memcpy(mp->locator_set_name, locator_set_name,
9509 vec_len(locator_set_name));
9510 vec_free(locator_set_name);
9515 /* Wait for a reply... */
9523 api_lisp_add_del_local_eid(vat_main_t * vam)
9525 unformat_input_t * input = vam->input;
9526 vl_api_lisp_add_del_local_eid_t *mp;
9531 ip4_address_t eidv4;
9532 ip6_address_t eidv6;
9533 u8 tmp_eid_lenght = ~0;
9535 u8 *locator_set_name = NULL;
9536 u8 locator_set_name_set = 0;
9538 /* Parse args required to build the message */
9539 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) {
9540 if (unformat(input, "del")) {
9542 } else if (unformat(input, "eid %U/%d", unformat_ip4_address,
9543 &eidv4, &tmp_eid_lenght)) {
9544 eid_lenght = tmp_eid_lenght;
9546 } else if (unformat(input, "eid %U/%d", unformat_ip6_address,
9547 &eidv6, &tmp_eid_lenght)) {
9548 eid_lenght = tmp_eid_lenght;
9550 } else if (unformat(input, "locator-set %s", &locator_set_name)) {
9551 locator_set_name_set = 1;
9556 if (locator_set_name_set == 0) {
9557 errmsg ("missing locator-set name\n");
9561 if (vec_len(locator_set_name) > 64) {
9562 errmsg ("locator-set name too long\n");
9563 vec_free(locator_set_name);
9566 vec_add1(locator_set_name, 0);
9568 if (eidv4_set && eidv6_set) {
9569 errmsg ("both eid v4 and v6 addresses set\n");
9570 vec_free(locator_set_name);
9574 if (!eidv4_set && !eidv6_set) {
9575 errmsg ("eid addresses not set\n");
9576 vec_free(locator_set_name);
9580 if (eidv4_set && eid_lenght > 32) {
9581 errmsg ("eid prefix to big\n");
9582 vec_free(locator_set_name);
9586 if (eidv6_set && eid_lenght > 128) {
9587 errmsg ("eid prefix to big\n");
9588 vec_free(locator_set_name);
9592 /* Construct the API message */
9593 M(LISP_ADD_DEL_LOCAL_EID, lisp_add_del_local_eid);
9595 mp->is_add = is_add;
9598 clib_memcpy(mp->ip_address, &eidv6, sizeof(eidv6));
9601 clib_memcpy(mp->ip_address, &eidv4, sizeof(eidv4));
9603 mp->prefix_len = eid_lenght;
9604 clib_memcpy(mp->locator_set_name, locator_set_name,
9605 vec_len(locator_set_name));
9606 vec_free(locator_set_name);
9611 /* Wait for a reply... */
9619 api_lisp_gpe_add_del_fwd_entry(vat_main_t * vam)
9621 unformat_input_t * input = vam->input;
9622 vl_api_lisp_gpe_add_del_fwd_entry_t *mp;
9625 u8 eidv4_set = 0, slocv4_set = 0, dlocv4_set = 0;
9626 u8 eidv6_set = 0, slocv6_set = 0, dlocv6_set = 0;
9627 ip4_address_t eidv4, slocv4, dlocv4;
9628 ip6_address_t eidv6, slocv6, dlocv6;
9629 u8 tmp_eid_lenght = ~0;
9632 /* Parse args required to build the message */
9633 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) {
9634 if (unformat(input, "del")) {
9636 } else if (unformat(input, "eid %U/%d", unformat_ip4_address,
9637 &eidv4, &tmp_eid_lenght)) {
9638 eid_lenght = tmp_eid_lenght;
9640 } else if (unformat(input, "eid %U/%d", unformat_ip6_address,
9641 &eidv6, &tmp_eid_lenght)) {
9642 eid_lenght = tmp_eid_lenght;
9644 } else if (unformat(input, "sloc %U", unformat_ip4_address, &slocv4)) {
9646 } else if (unformat(input, "sloc %U", unformat_ip6_address, &slocv6)) {
9648 } else if (unformat(input, "dloc %U", unformat_ip4_address, &dlocv4)) {
9650 } else if (unformat(input, "dloc %U", unformat_ip6_address, &dlocv6)) {
9656 if (eidv4_set && eidv6_set) {
9657 errmsg ("both eid v4 and v6 addresses set\n");
9661 if (!eidv4_set && !eidv6_set) {
9662 errmsg ("eid addresses not set\n");
9666 if (slocv4_set && slocv6_set) {
9667 errmsg ("both source v4 and v6 addresses set\n");
9671 if (!slocv4_set && !slocv6_set) {
9672 errmsg ("source addresses not set\n");
9676 if (dlocv4_set && dlocv6_set) {
9677 errmsg ("both destination v4 and v6 addresses set\n");
9681 if (dlocv4_set && dlocv6_set) {
9682 errmsg ("destination addresses not set\n");
9686 if (!(slocv4_set == dlocv4_set && slocv6_set == dlocv6_set)) {
9687 errmsg ("mixing type of source and destination address\n");
9691 /* Construct the API message */
9692 M(LISP_GPE_ADD_DEL_FWD_ENTRY, lisp_gpe_add_del_fwd_entry);
9694 mp->is_add = is_add;
9696 mp->eid_is_ipv6 = 1;
9697 clib_memcpy(mp->eid_ip_address, &eidv6, sizeof(eidv6));
9699 mp->eid_is_ipv6 = 0;
9700 clib_memcpy(mp->eid_ip_address, &eidv4, sizeof(eidv4));
9702 mp->eid_prefix_len = eid_lenght;
9704 mp->address_is_ipv6 = 1;
9705 clib_memcpy(mp->source_ip_address, &slocv6, sizeof(slocv6));
9706 clib_memcpy(mp->destination_ip_address, &dlocv6, sizeof(dlocv6));
9708 mp->address_is_ipv6 = 0;
9709 clib_memcpy(mp->source_ip_address, &slocv4, sizeof(slocv4));
9710 clib_memcpy(mp->destination_ip_address, &dlocv4, sizeof(dlocv4));
9716 /* Wait for a reply... */
9724 api_lisp_add_del_map_resolver(vat_main_t * vam)
9726 unformat_input_t * input = vam->input;
9727 vl_api_lisp_add_del_map_resolver_t *mp;
9735 /* Parse args required to build the message */
9736 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) {
9737 if (unformat(input, "del")) {
9739 } else if (unformat(input, "%U", unformat_ip4_address, &ipv4)) {
9741 } else if (unformat(input, "%U", unformat_ip6_address, &ipv6)) {
9747 if (ipv4_set && ipv6_set) {
9748 errmsg ("both eid v4 and v6 addresses set\n");
9752 if (!ipv4_set && !ipv6_set) {
9753 errmsg ("eid addresses not set\n");
9757 /* Construct the API message */
9758 M(LISP_ADD_DEL_MAP_RESOLVER, lisp_add_del_map_resolver);
9760 mp->is_add = is_add;
9763 clib_memcpy(mp->ip_address, &ipv6, sizeof(ipv6));
9766 clib_memcpy(mp->ip_address, &ipv4, sizeof(ipv4));
9772 /* Wait for a reply... */
9780 api_lisp_gpe_enable_disable (vat_main_t * vam)
9782 unformat_input_t * input = vam->input;
9783 vl_api_lisp_gpe_enable_disable_t *mp;
9788 /* Parse args required to build the message */
9789 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) {
9790 if (unformat(input, "enable")) {
9793 } else if (unformat(input, "disable")) {
9801 errmsg("Value not set\n");
9805 /* Construct the API message */
9806 M(LISP_GPE_ENABLE_DISABLE, lisp_gpe_enable_disable);
9813 /* Wait for a reply... */
9821 api_lisp_enable_disable (vat_main_t * vam)
9823 unformat_input_t * input = vam->input;
9824 vl_api_lisp_enable_disable_t *mp;
9829 /* Parse args required to build the message */
9830 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
9832 if (unformat (input, "enable"))
9837 else if (unformat (input, "disable"))
9847 errmsg ("Value not set\n");
9851 /* Construct the API message */
9852 M(LISP_ENABLE_DISABLE, lisp_enable_disable);
9859 /* Wait for a reply... */
9866 /** Used for transferring locators via VPP API */
9867 typedef CLIB_PACKED(struct
9869 u8 is_ip4; /**< is locator an IPv4 address? */
9870 u8 addr[16]; /**< IPv4/IPv6 address */
9874 * Add/del remote mapping from LISP control plane and updates
9875 * forwarding entries in data-plane accordingly.
9877 * @param vam vpp API test context
9878 * @return return code
9881 api_lisp_add_del_remote_mapping (vat_main_t * vam)
9883 unformat_input_t * input = vam->input;
9884 vl_api_lisp_add_del_remote_mapping_t *mp;
9887 u8 seid_set = 0, deid_set = 0;
9888 ip4_address_t seid4, deid4, rloc4;
9889 ip6_address_t seid6, deid6, rloc6;
9890 u32 seid_len = 0, deid_len = 0, len;
9891 u8 deid_is_ip4 = 0, seid_is_ip4 = 0;
9894 rloc_t * rlocs = 0, rloc;
9896 /* Parse args required to build the message */
9897 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) {
9898 if (unformat(input, "del")) {
9900 } else if (unformat(input, "add")) {
9902 } else if (unformat(input, "deid %U/%d", unformat_ip4_address,
9907 } else if (unformat(input, "deid %U/%d", unformat_ip6_address,
9912 } else if (unformat(input, "seid %U/%d", unformat_ip4_address,
9917 } else if (unformat(input, "seid %U/%d", unformat_ip6_address,
9922 } else if (unformat(input, "vni %d", &vni)) {
9924 } else if (unformat(input, "rloc %U", unformat_ip4_address, &rloc4)) {
9926 clib_memcpy (&rloc.addr, &rloc4, sizeof (rloc4));
9927 vec_add1 (rlocs, rloc);
9928 } else if (unformat(input, "rloc %U", unformat_ip6_address, &rloc6)) {
9930 clib_memcpy (&rloc.addr, &rloc6, sizeof (rloc6));
9931 vec_add1 (rlocs, rloc);
9932 } else if (unformat(input, "action %d", &action)) {
9935 clib_warning ("parse error '%U'", format_unformat_error, input);
9940 if (!seid_set || !deid_set) {
9941 errmsg ("missing params!");
9945 if (seid_is_ip4 != deid_is_ip4) {
9946 errmsg ("source and destination EIDs are not in " "same IP family!");
9950 if (is_add && (~0 == action)
9951 && 0 == vec_len (rlocs)) {
9952 errmsg ("no action set for negative map-reply!");
9956 M(LISP_ADD_DEL_REMOTE_MAPPING, lisp_add_del_remote_mapping);
9957 mp->is_add = is_add;
9958 mp->vni = htonl (vni);
9959 mp->seid_len = seid_len;
9960 mp->action = (u8) action;
9961 mp->deid_len = deid_len;
9964 clib_memcpy (mp->seid, &seid4, sizeof (seid4));
9967 clib_memcpy (mp->seid, &seid6, sizeof (seid6));
9972 clib_memcpy (mp->deid, &deid4, sizeof (deid4));
9975 clib_memcpy (mp->deid, &deid6, sizeof (deid6));
9978 mp->rloc_num = vec_len (rlocs);
9979 clib_memcpy (mp->rlocs, rlocs, (sizeof (rloc_t) * vec_len (rlocs)));
9985 /* Wait for a reply... */
9993 api_lisp_gpe_add_del_iface(vat_main_t * vam)
9995 unformat_input_t * input = vam->input;
9996 vl_api_lisp_gpe_add_del_iface_t *mp;
10002 /* Parse args required to build the message */
10003 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) {
10004 if (unformat(input, "up")) {
10007 } else if (unformat(input, "down")) {
10010 } else if (unformat(input, "table_id %d", &table_id)) {
10012 } else if (unformat(input, "vni %d", &vni)) {
10019 errmsg("Value not set\n");
10023 /* Construct the API message */
10024 M(LISP_GPE_ADD_DEL_IFACE, lisp_gpe_add_del_iface);
10026 mp->is_add = is_add;
10027 mp->table_id = table_id;
10033 /* Wait for a reply... */
10041 api_lisp_locator_set_dump(vat_main_t *vam)
10043 vl_api_lisp_locator_set_dump_t *mp;
10046 if (!vam->json_output) {
10047 fformat(vam->ofp, "%=20s%=16s%=16s%=16s\n",
10048 "Locator-set", "Locator", "Priority", "Weight");
10051 M(LISP_LOCATOR_SET_DUMP, lisp_locator_set_dump);
10055 /* Use a control ping for synchronization */
10057 vl_api_control_ping_t * mp;
10058 M(CONTROL_PING, control_ping);
10061 /* Wait for a reply... */
10069 api_lisp_local_eid_table_dump(vat_main_t *vam)
10071 vl_api_lisp_local_eid_table_dump_t *mp;
10074 if (!vam->json_output) {
10075 fformat(vam->ofp, "%=20s%=30s\n",
10076 "Locator-set", "Eid");
10079 M(LISP_LOCAL_EID_TABLE_DUMP, lisp_local_eid_table_dump);
10083 /* Use a control ping for synchronization */
10085 vl_api_control_ping_t * mp;
10086 M(CONTROL_PING, control_ping);
10089 /* Wait for a reply... */
10097 api_lisp_gpe_tunnel_dump(vat_main_t *vam)
10099 vl_api_lisp_gpe_tunnel_dump_t *mp;
10102 if (!vam->json_output) {
10103 fformat(vam->ofp, "%=20s%=30s%=16s%=16s%=16s%=16s"
10104 "%=16s%=16s%=16s%=16s%=16s\n",
10105 "Tunel", "Source", "Destination", "Fib encap", "Fib decap",
10106 "Decap next", "Lisp version", "Flags", "Next protocol",
10107 "ver_res", "res", "iid");
10110 M(LISP_GPE_TUNNEL_DUMP, lisp_gpe_tunnel_dump);
10114 /* Use a control ping for synchronization */
10116 vl_api_control_ping_t * mp;
10117 M(CONTROL_PING, control_ping);
10120 /* Wait for a reply... */
10128 api_lisp_map_resolver_dump(vat_main_t *vam)
10130 vl_api_lisp_map_resolver_dump_t *mp;
10133 if (!vam->json_output) {
10134 fformat(vam->ofp, "%=20s\n",
10138 M(LISP_MAP_RESOLVER_DUMP, lisp_map_resolver_dump);
10142 /* Use a control ping for synchronization */
10144 vl_api_control_ping_t * mp;
10145 M(CONTROL_PING, control_ping);
10148 /* Wait for a reply... */
10156 api_lisp_enable_disable_status_dump(vat_main_t *vam)
10158 vl_api_lisp_enable_disable_status_dump_t *mp;
10161 if (!vam->json_output) {
10162 fformat(vam->ofp, "%=20s\n",
10166 M(LISP_ENABLE_DISABLE_STATUS_DUMP,
10167 lisp_enable_disable_status_dump);
10171 /* Use a control ping for synchronization */
10173 vl_api_control_ping_t * mp;
10174 M(CONTROL_PING, control_ping);
10177 /* Wait for a reply... */
10185 api_af_packet_create (vat_main_t * vam)
10187 unformat_input_t * i = vam->input;
10188 vl_api_af_packet_create_t * mp;
10190 u8 * host_if_name = 0;
10192 u8 random_hw_addr = 1;
10194 memset (hw_addr, 0, sizeof (hw_addr));
10196 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
10197 if (unformat (i, "name %s", &host_if_name))
10198 vec_add1 (host_if_name, 0);
10199 else if (unformat (i, "hw_addr %U", unformat_ethernet_address, hw_addr))
10200 random_hw_addr = 0;
10205 if (!vec_len (host_if_name)) {
10206 errmsg ("host-interface name must be specified");
10210 if (vec_len (host_if_name) > 64) {
10211 errmsg ("host-interface name too long");
10215 M(AF_PACKET_CREATE, af_packet_create);
10217 clib_memcpy (mp->host_if_name, host_if_name, vec_len (host_if_name));
10218 clib_memcpy (mp->hw_addr, hw_addr, 6);
10219 mp->use_random_hw_addr = random_hw_addr;
10220 vec_free (host_if_name);
10228 api_af_packet_delete (vat_main_t * vam)
10230 unformat_input_t * i = vam->input;
10231 vl_api_af_packet_delete_t * mp;
10233 u8 * host_if_name = 0;
10235 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
10236 if (unformat (i, "name %s", &host_if_name))
10237 vec_add1 (host_if_name, 0);
10242 if (!vec_len (host_if_name)) {
10243 errmsg ("host-interface name must be specified");
10247 if (vec_len (host_if_name) > 64) {
10248 errmsg ("host-interface name too long");
10252 M(AF_PACKET_DELETE, af_packet_delete);
10254 clib_memcpy (mp->host_if_name, host_if_name, vec_len (host_if_name));
10255 vec_free (host_if_name);
10263 api_policer_add_del (vat_main_t * vam)
10265 unformat_input_t * i = vam->input;
10266 vl_api_policer_add_del_t * mp;
10278 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
10279 if (unformat (i, "del"))
10281 else if (unformat (i, "name %s", &name))
10282 vec_add1 (name, 0);
10283 else if (unformat (i, "cir %u", &cir))
10285 else if (unformat (i, "eir %u", &eir))
10287 else if (unformat (i, "cb %u", &cb))
10289 else if (unformat (i, "eb %u", &eb))
10291 else if (unformat (i, "rate_type %U", unformat_policer_rate_type,
10294 else if (unformat (i, "round_type %U", unformat_policer_round_type,
10297 else if (unformat (i, "type %U", unformat_policer_type, &type))
10303 if (!vec_len (name)) {
10304 errmsg ("policer name must be specified");
10308 if (vec_len (name) > 64) {
10309 errmsg ("policer name too long");
10313 M(POLICER_ADD_DEL, policer_add_del);
10315 clib_memcpy (mp->name, name, vec_len (name));
10317 mp->is_add = is_add;
10322 mp->rate_type = rate_type;
10323 mp->round_type = round_type;
10331 static int q_or_quit (vat_main_t * vam)
10333 longjmp (vam->jump_buf, 1);
10334 return 0; /* not so much */
10336 static int q (vat_main_t * vam) {return q_or_quit (vam);}
10337 static int quit (vat_main_t * vam) {return q_or_quit (vam);}
10339 static int comment (vat_main_t * vam)
10344 static int cmd_cmp (void * a1, void * a2)
10349 return strcmp ((char *)(c1[0]), (char *)(c2[0]));
10352 static int help (vat_main_t * vam)
10357 unformat_input_t * i = vam->input;
10360 if (unformat (i, "%s", &name)) {
10365 hs = hash_get_mem (vam->help_by_name, name);
10367 fformat (vam->ofp, "usage: %s %s\n", name, hs[0]);
10369 fformat (vam->ofp, "No such msg / command '%s'\n", name);
10374 fformat(vam->ofp, "Help is available for the following:\n");
10376 hash_foreach_pair (p, vam->function_by_name,
10378 vec_add1 (cmds, (u8 *)(p->key));
10381 vec_sort_with_function (cmds, cmd_cmp);
10383 for (j = 0; j < vec_len(cmds); j++)
10384 fformat (vam->ofp, "%s\n", cmds[j]);
10390 static int set (vat_main_t * vam)
10392 u8 * name = 0, * value = 0;
10393 unformat_input_t * i = vam->input;
10395 if (unformat (i, "%s", &name)) {
10396 /* The input buffer is a vector, not a string. */
10397 value = vec_dup (i->buffer);
10398 vec_delete (value, i->index, 0);
10399 /* Almost certainly has a trailing newline */
10400 if (value[vec_len(value)-1] == '\n')
10401 value[vec_len(value)-1] = 0;
10402 /* Make sure it's a proper string, one way or the other */
10403 vec_add1 (value, 0);
10404 (void) clib_macro_set_value (&vam->macro_main,
10405 (char *)name, (char *)value);
10408 errmsg ("usage: set <name> <value>\n");
10415 static int unset (vat_main_t * vam)
10419 if (unformat (vam->input, "%s", &name))
10420 if (clib_macro_unset (&vam->macro_main, (char *)name) == 1)
10421 errmsg ("unset: %s wasn't set\n", name);
10432 static int macro_sort_cmp (void * a1, void * a2)
10434 macro_sort_t * s1 = a1;
10435 macro_sort_t * s2 = a2;
10437 return strcmp ((char *)(s1->name), (char *)(s2->name));
10440 static int dump_macro_table (vat_main_t * vam)
10442 macro_sort_t * sort_me = 0, * sm;
10446 hash_foreach_pair (p, vam->macro_main.the_value_table_hash,
10448 vec_add2 (sort_me, sm, 1);
10449 sm->name = (u8 *)(p->key);
10450 sm->value = (u8 *) (p->value[0]);
10453 vec_sort_with_function (sort_me, macro_sort_cmp);
10455 if (vec_len(sort_me))
10456 fformat (vam->ofp, "%-15s%s\n", "Name", "Value");
10458 fformat (vam->ofp, "The macro table is empty...\n");
10460 for (i = 0; i < vec_len (sort_me); i++)
10461 fformat (vam->ofp, "%-15s%s\n", sort_me[i].name,
10466 static int dump_node_table (vat_main_t * vam)
10469 vlib_node_t * node, * next_node;
10471 if (vec_len (vam->graph_nodes) == 0) {
10472 fformat (vam->ofp, "Node table empty, issue get_node_graph...\n");
10476 for (i = 0; i < vec_len (vam->graph_nodes); i++) {
10477 node = vam->graph_nodes[i];
10478 fformat (vam->ofp, "[%d] %s\n", i, node->name);
10479 for (j = 0; j < vec_len (node->next_nodes); j++) {
10480 if (node->next_nodes[j] != ~0) {
10481 next_node = vam->graph_nodes[node->next_nodes[j]];
10482 fformat (vam->ofp, " [%d] %s\n", j, next_node->name);
10489 static int search_node_table (vat_main_t * vam)
10491 unformat_input_t * line_input = vam->input;
10494 vlib_node_t * node, * next_node;
10497 if (vam->graph_node_index_by_name == 0) {
10498 fformat (vam->ofp, "Node table empty, issue get_node_graph...\n");
10502 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) {
10503 if (unformat (line_input, "%s", &node_to_find)) {
10504 vec_add1 (node_to_find, 0);
10505 p = hash_get_mem (vam->graph_node_index_by_name, node_to_find);
10507 fformat (vam->ofp, "%s not found...\n", node_to_find);
10510 node = vam->graph_nodes[p[0]];
10511 fformat (vam->ofp, "[%d] %s\n", p[0], node->name);
10512 for (j = 0; j < vec_len (node->next_nodes); j++) {
10513 if (node->next_nodes[j] != ~0) {
10514 next_node = vam->graph_nodes[node->next_nodes[j]];
10515 fformat (vam->ofp, " [%d] %s\n", j, next_node->name);
10521 clib_warning ("parse error '%U'", format_unformat_error,
10527 vec_free(node_to_find);
10535 static int script (vat_main_t * vam)
10538 char * save_current_file;
10539 unformat_input_t save_input;
10540 jmp_buf save_jump_buf;
10541 u32 save_line_number;
10543 FILE * new_fp, * save_ifp;
10545 if (unformat (vam->input, "%s", &s)) {
10546 new_fp = fopen ((char *)s, "r");
10548 errmsg ("Couldn't open script file %s\n", s);
10553 errmsg ("Missing script name\n");
10557 clib_memcpy (&save_input, &vam->input, sizeof (save_input));
10558 clib_memcpy (&save_jump_buf, &vam->jump_buf, sizeof (save_jump_buf));
10559 save_ifp = vam->ifp;
10560 save_line_number = vam->input_line_number;
10561 save_current_file = (char *) vam->current_file;
10563 vam->input_line_number = 0;
10565 vam->current_file = s;
10568 clib_memcpy (&vam->input, &save_input, sizeof (vam->input));
10569 clib_memcpy (&vam->jump_buf, &save_jump_buf, sizeof (save_jump_buf));
10570 vam->ifp = save_ifp;
10571 vam->input_line_number = save_line_number;
10572 vam->current_file = (u8 *) save_current_file;
10578 static int echo (vat_main_t * vam)
10580 fformat (vam->ofp, "%v", vam->input->buffer);
10584 /* List of API message constructors, CLI names map to api_xxx */
10585 #define foreach_vpe_api_msg \
10586 _(create_loopback,"[mac <mac-addr>]") \
10587 _(sw_interface_dump,"") \
10588 _(sw_interface_set_flags, \
10589 "<intfc> | sw_if_index <id> admin-up | admin-down link-up | link down") \
10590 _(sw_interface_add_del_address, \
10591 "<intfc> | sw_if_index <id> <ip4-address> | <ip6-address> [del] [del-all] ") \
10592 _(sw_interface_set_table, \
10593 "<intfc> | sw_if_index <id> vrf <table-id> [ipv6]") \
10594 _(sw_interface_set_vpath, \
10595 "<intfc> | sw_if_index <id> enable | disable") \
10596 _(sw_interface_set_l2_xconnect, \
10597 "rx <intfc> | rx_sw_if_index <id> tx <intfc> | tx_sw_if_index <id>\n" \
10598 "enable | disable") \
10599 _(sw_interface_set_l2_bridge, \
10600 "rx <intfc> | rx_sw_if_index <id> bd_id <bridge-domain-id>\n" \
10601 "[shg <split-horizon-group>] [bvi]\n" \
10602 "enable | disable") \
10603 _(bridge_domain_add_del, \
10604 "bd_id <bridge-domain-id> [flood 1|0] [uu-flood 1|0] [forward 1|0] [learn 1|0] [arp-term 1|0] [del]\n")\
10605 _(bridge_domain_dump, "[bd_id <bridge-domain-id>]\n") \
10607 "mac <mac-addr> bd_id <bridge-domain-id> [del] | sw_if <intfc> | sw_if_index <id> [static] [filter] [bvi]\n") \
10609 "sw_if <intfc> | sw_if_index <id> [learn] [forward] [uu-flood] [flood]\n") \
10611 "bd_id <bridge-domain-id> [learn] [forward] [uu-flood] [flood] [arp-term] [disable]\n") \
10613 "tapname <name> mac <mac-addr> | random-mac") \
10615 "<vpp-if-name> | sw_if_index <id> tapname <name> mac <mac-addr> | random-mac") \
10617 "<vpp-if-name> | sw_if_index <id>") \
10618 _(sw_interface_tap_dump, "") \
10619 _(ip_add_del_route, \
10620 "<addr>/<mask> via <addr> [vrf <n>]\n" \
10621 "[<intfc> | sw_if_index <id>] [resolve-attempts <n>]\n" \
10622 "[weight <n>] [drop] [local] [classify <n>] [del]\n" \
10623 "[multipath] [count <n>]") \
10624 _(proxy_arp_add_del, \
10625 "<lo-ip4-addr> - <hi-ip4-addr> [vrf <n>] [del]") \
10626 _(proxy_arp_intfc_enable_disable, \
10627 "<intfc> | sw_if_index <id> enable | disable") \
10628 _(mpls_add_del_encap, \
10629 "label <n> dst <ip4-addr> [vrf <n>] [del]") \
10630 _(mpls_add_del_decap, \
10631 "label <n> [rx_vrf_id <n>] [tx_vrf_id] [s-bit-clear][del]") \
10632 _(mpls_gre_add_del_tunnel, \
10633 "inner_vrf_id <n> outer_vrf_id <n> src <ip4-address> dst <ip4-address>\n" \
10634 "adj <ip4-address>/<mask-width> [del]") \
10635 _(sw_interface_set_unnumbered, \
10636 "<intfc> | sw_if_index <id> unnum_if_index <id> [del]") \
10637 _(ip_neighbor_add_del, \
10638 "<intfc> | sw_if_index <id> dst <ip46-address> mac <mac-addr>") \
10639 _(reset_vrf, "vrf <id> [ipv6]") \
10640 _(create_vlan_subif, "<intfc> | sw_if_index <id> vlan <n>") \
10641 _(create_subif, "<intfc> | sw_if_index <id> sub_id <n>\n" \
10642 "[outer_vlan_id <n>][inner_vlan_id <n>]\n" \
10643 "[no_tags][one_tag][two_tags][dot1ad][exact_match][default_sub]\n" \
10644 "[outer_vlan_id_any][inner_vlan_id_any]") \
10645 _(oam_add_del, "src <ip4-address> dst <ip4-address> [vrf <n>] [del]") \
10646 _(reset_fib, "vrf <n> [ipv6]") \
10647 _(dhcp_proxy_config, \
10648 "svr <v46-address> src <v46-address>\n" \
10649 "insert-cid <n> [del]") \
10650 _(dhcp_proxy_config_2, \
10651 "svr <v46-address> src <v46-address>\n" \
10652 "rx_vrf_id <nn> server_vrf_id <nn> insert-cid <n> [del]") \
10653 _(dhcp_proxy_set_vss, \
10654 "tbl_id <n> fib_id <n> oui <n> [ipv6] [del]") \
10655 _(dhcp_client_config, \
10656 "<intfc> | sw_if_index <id> [hostname <name>] [disable_event] [del]") \
10657 _(set_ip_flow_hash, \
10658 "vrf <n> [src] [dst] [sport] [dport] [proto] [reverse] [ipv6]") \
10659 _(sw_interface_ip6_enable_disable, \
10660 "<intfc> | sw_if_index <id> enable | disable") \
10661 _(sw_interface_ip6_set_link_local_address, \
10662 "<intfc> | sw_if_index <id> <ip6-address>/<mask-width>") \
10663 _(sw_interface_ip6nd_ra_prefix, \
10664 "<intfc> | sw_if_index <id> <ip6-address>/<mask-width>\n" \
10665 "val_life <n> pref_life <n> [def] [noadv] [offl] [noauto]\n" \
10666 "[nolink] [isno]") \
10667 _(sw_interface_ip6nd_ra_config, \
10668 "<intfc> | sw_if_index <id> [maxint <n>] [minint <n>]\n" \
10669 "[life <n>] [count <n>] [interval <n>] [surpress]\n" \
10670 "[managed] [other] [ll] [send] [cease] [isno] [def]") \
10671 _(set_arp_neighbor_limit, "arp_nbr_limit <n> [ipv6]") \
10672 _(l2_patch_add_del, \
10673 "rx <intfc> | rx_sw_if_index <id> tx <intfc> | tx_sw_if_index <id>\n" \
10674 "enable | disable") \
10675 _(mpls_ethernet_add_del_tunnel, \
10676 "tx <intfc> | tx_sw_if_index <n> dst <mac-addr>\n" \
10677 "adj <ip4-addr>/<mw> dst <mac-addr> [del]") \
10678 _(mpls_ethernet_add_del_tunnel_2, \
10679 "inner_vrf_id <n> outer_vrf_id <n> next-hop <ip4-addr>\n" \
10680 "resolve-attempts <n> resolve-if-needed 0 | 1 [del]") \
10681 _(sr_tunnel_add_del, \
10682 "[name <name>] src <ip6-addr> dst <ip6-addr>/<mw> \n" \
10683 "(next <ip6-addr>)+ [tag <ip6-addr>]* [clean] [reroute] \n" \
10684 "[policy <policy_name>]") \
10685 _(sr_policy_add_del, \
10686 "name <name> tunnel <tunnel-name> [tunnel <tunnel-name>]* [del]") \
10687 _(sr_multicast_map_add_del, \
10688 "address [ip6 multicast address] sr-policy [policy name] [del]") \
10689 _(classify_add_del_table, \
10690 "buckets <nn> [skip <n>] [match <n>] [memory_size <nn-bytes>]\n" \
10691 "[del] mask <mask-value>\n" \
10692 " [l2-miss-next | miss-next | acl-miss-next] <name|nn>") \
10693 _(classify_add_del_session, \
10694 "[hit-next|l2-hit-next|acl-hit-next] <name|nn> table-index <nn>\n" \
10695 "skip_n <nn> match_n <nn> match [hex] [l2] [l3 [ip4|ip6]]") \
10696 _(classify_set_interface_ip_table, \
10697 "<intfc> | sw_if_index <nn> table <nn>") \
10698 _(classify_set_interface_l2_tables, \
10699 "<intfc> | sw_if_index <nn> [ip4-table <nn>] [ip6-table <nn>]\n" \
10700 " [other-table <nn>]") \
10701 _(get_node_index, "node <node-name") \
10702 _(add_node_next, "node <node-name> next <next-node-name>") \
10703 _(l2tpv3_create_tunnel, \
10704 "client_address <ip6-addr> our_address <ip6-addr>\n" \
10705 "[local_session_id <nn>][remote_session_id <nn>][local_cookie <nn>]\n"\
10706 "[remote_cookie <nn>]\n[l2-sublayer-preset]\n") \
10707 _(l2tpv3_set_tunnel_cookies, \
10708 "<intfc> | sw_if_index <nn> [new_local_cookie <nn>]\n" \
10709 "[new_remote_cookie <nn>]\n") \
10710 _(l2tpv3_interface_enable_disable, \
10711 "<intfc> | sw_if_index <nn> enable | disable") \
10712 _(l2tpv3_set_lookup_key, \
10713 "lookup_v6_src | lookup_v6_dst | lookup_session_id") \
10714 _(sw_if_l2tpv3_tunnel_dump, "") \
10715 _(vxlan_add_del_tunnel, \
10716 "src <ip4-addr> dst <ip4-addr> vni <vni> [encap-vrf-id <nn>]\n" \
10717 " [decap-next l2|ip4|ip6] [del]") \
10718 _(vxlan_tunnel_dump, "[<intfc> | sw_if_index <nn>]") \
10719 _(gre_add_del_tunnel, \
10720 "src <ip4-addr> dst <ip4-addr> [outer-fib-id <nn>] [del]\n") \
10721 _(gre_tunnel_dump, "[<intfc> | sw_if_index <nn>]") \
10722 _(l2_fib_clear_table, "") \
10723 _(l2_interface_efp_filter, "sw_if_index <nn> enable | disable") \
10724 _(l2_interface_vlan_tag_rewrite, \
10725 "<intfc> | sw_if_index <nn> \n" \
10726 "[disable][push-[1|2]][pop-[1|2]][translate-1-[1|2]] \n" \
10727 "[translate-2-[1|2]] [push_dot1q 0] tag1 <nn> tag2 <nn>") \
10728 _(create_vhost_user_if, \
10729 "socket <filename> [server] [renumber <dev_instance>] " \
10730 "[mac <mac_address>]") \
10731 _(modify_vhost_user_if, \
10732 "<intfc> | sw_if_index <nn> socket <filename>\n" \
10733 "[server] [renumber <dev_instance>]") \
10734 _(delete_vhost_user_if, "<intfc> | sw_if_index <nn>") \
10735 _(sw_interface_vhost_user_dump, "") \
10736 _(show_version, "") \
10737 _(vxlan_gpe_add_del_tunnel, \
10738 "local <ip4-addr> remote <ip4-addr> vni <nn>\n" \
10739 "[encap-vrf-id <nn>] [decap-vrf-id <nn>] [next-ip4][next-ip6]" \
10740 "[next-ethernet] [next-nsh]\n") \
10741 _(l2_fib_table_dump, "bd_id <bridge-domain-id>") \
10742 _(interface_name_renumber, \
10743 "<intfc> | sw_if_index <nn> new_show_dev_instance <nn>") \
10744 _(input_acl_set_interface, \
10745 "<intfc> | sw_if_index <nn> [ip4-table <nn>] [ip6-table <nn>]\n" \
10746 " [l2-table <nn>] [del]") \
10747 _(want_ip4_arp_events, "address <ip4-address> [del]") \
10748 _(ip_address_dump, "(ipv4 | ipv6) (<intfc> | sw_if_index <id>)") \
10749 _(ip_dump, "ipv4 | ipv6") \
10750 _(ipsec_spd_add_del, "spd_id <n> [del]") \
10751 _(ipsec_interface_add_del_spd, "(<intfc> | sw_if_index <id>)\n" \
10753 _(ipsec_sad_add_del_entry, "sad_id <n> spi <n> crypto_alg <alg>\n" \
10754 " crypto_key <hex> tunnel_src <ip4|ip6> tunnel_dst <ip4|ip6>\n" \
10755 " integ_alg <alg> integ_key <hex>") \
10756 _(ipsec_spd_add_del_entry, "spd_id <n> priority <n> action <action>\n" \
10757 " (inbound|outbound) [sa_id <n>] laddr_start <ip4|ip6>\n" \
10758 " laddr_stop <ip4|ip6> raddr_start <ip4|ip6> raddr_stop <ip4|ip6>\n" \
10759 " [lport_start <n> lport_stop <n>] [rport_start <n> rport_stop <n>]" )\
10760 _(ipsec_sa_set_key, "sa_id <n> crypto_key <hex> integ_key <hex>") \
10761 _(ikev2_profile_add_del, "name <profile_name> [del]") \
10762 _(ikev2_profile_set_auth, "name <profile_name> auth_method <method>\n" \
10763 "(auth_data 0x<data> | auth_data <data>)") \
10764 _(ikev2_profile_set_id, "name <profile_name> id_type <type>\n" \
10765 "(id_data 0x<data> | id_data <data>) (local|remote)") \
10766 _(ikev2_profile_set_ts, "name <profile_name> protocol <proto>\n" \
10767 "start_port <port> end_port <port> start_addr <ip4> end_addr <ip4>\n" \
10768 "(local|remote)") \
10769 _(ikev2_set_local_key, "file <absolute_file_path>") \
10770 _(delete_loopback,"sw_if_index <nn>") \
10771 _(bd_ip_mac_add_del, "bd_id <bridge-domain-id> <ip4/6-addr> <mac-addr> [del]") \
10772 _(map_add_domain, \
10773 "ip4-pfx <ip4pfx> ip6-pfx <ip6pfx> " \
10774 "ip6-src <ip6addr> " \
10775 "ea-bits-len <n> psid-offset <n> psid-len <n>") \
10776 _(map_del_domain, "index <n>") \
10777 _(map_add_del_rule, \
10778 "index <n> psid <n> dst <ip6addr> [del]") \
10779 _(map_domain_dump, "") \
10780 _(map_rule_dump, "index <map-domain>") \
10781 _(want_interface_events, "enable|disable") \
10782 _(want_stats,"enable|disable") \
10783 _(get_first_msg_id, "client <name>") \
10784 _(cop_interface_enable_disable, "<intfc> | sw_if_index <nn> [disable]") \
10785 _(cop_whitelist_enable_disable, "<intfc> | sw_if_index <nn>\n" \
10786 "fib-id <nn> [ip4][ip6][default]") \
10787 _(get_node_graph, " ") \
10788 _(sw_interface_clear_stats,"<intfc> | sw_if_index <nn>") \
10789 _(trace_profile_add, "id <nn> trace-type <0x1f|0x3|0x9|0x11|0x19> " \
10790 "trace-elts <nn> trace-tsp <0|1|2|3> node-id <node id in hex> " \
10791 "app-data <app_data in hex> [pow] [ppc <encap|decap>]") \
10792 _(trace_profile_apply, "id <nn> <ip6-address>/<width>" \
10793 " vrf_id <nn> add | pop | none") \
10794 _(trace_profile_del, "") \
10795 _(lisp_add_del_locator_set, "locator-set <locator_name> [del]") \
10796 _(lisp_add_del_locator, "locator-set <locator_name> " \
10797 "iface <intf> | sw_if_index <sw_if_index> " \
10798 "p <priority> w <weight> [del]") \
10799 _(lisp_add_del_local_eid, "<ipv4|ipv6>/<prefix> " \
10800 "locator-set <locator_name> [del]") \
10801 _(lisp_gpe_add_del_fwd_entry, "eid <ip4|6-addr>/<prefix> " \
10802 "sloc <ip4/6-addr> dloc <ip4|6-addr> [del]") \
10803 _(lisp_add_del_map_resolver, "<ip4|6-addr> [del]") \
10804 _(lisp_gpe_enable_disable, "enable|disable") \
10805 _(lisp_enable_disable, "enable|disable") \
10806 _(lisp_gpe_add_del_iface, "up|down") \
10807 _(lisp_add_del_remote_mapping, "add|del vni <vni> deid <dest-eid> seid" \
10808 " <src-eid> rloc <locator> " \
10809 "[rloc <loc> ... ]") \
10810 _(lisp_locator_set_dump, "") \
10811 _(lisp_local_eid_table_dump, "") \
10812 _(lisp_gpe_tunnel_dump, "") \
10813 _(lisp_map_resolver_dump, "") \
10814 _(lisp_enable_disable_status_dump, "") \
10815 _(af_packet_create, "name <host interface name> [hw_addr <mac>]") \
10816 _(af_packet_delete, "name <host interface name>") \
10817 _(policer_add_del, "name <policer name> <params> [del]")
10819 /* List of command functions, CLI names map directly to functions */
10820 #define foreach_cli_function \
10821 _(comment, "usage: comment <ignore-rest-of-line>") \
10822 _(dump_interface_table, "usage: dump_interface_table") \
10823 _(dump_sub_interface_table, "usage: dump_sub_interface_table") \
10824 _(dump_ipv4_table, "usage: dump_ipv4_table") \
10825 _(dump_ipv6_table, "usage: dump_ipv6_table") \
10826 _(dump_stats_table, "usage: dump_stats_table") \
10827 _(dump_macro_table, "usage: dump_macro_table ") \
10828 _(dump_node_table, "usage: dump_node_table") \
10829 _(echo, "usage: echo <message>") \
10830 _(exec, "usage: exec <vpe-debug-CLI-command>") \
10831 _(help, "usage: help") \
10832 _(q, "usage: quit") \
10833 _(quit, "usage: quit") \
10834 _(search_node_table, "usage: search_node_table <name>...") \
10835 _(set, "usage: set <variable-name> <value>") \
10836 _(script, "usage: script <file-name>") \
10837 _(unset, "usage: unset <variable-name>")
10840 static void vl_api_##n##_t_handler_uni \
10841 (vl_api_##n##_t * mp) \
10843 vat_main_t * vam = &vat_main; \
10844 if (vam->json_output) { \
10845 vl_api_##n##_t_handler_json(mp); \
10847 vl_api_##n##_t_handler(mp); \
10850 foreach_vpe_api_reply_msg;
10853 void vat_api_hookup (vat_main_t *vam)
10856 vl_msg_api_set_handlers(VL_API_##N, #n, \
10857 vl_api_##n##_t_handler_uni, \
10859 vl_api_##n##_t_endian, \
10860 vl_api_##n##_t_print, \
10861 sizeof(vl_api_##n##_t), 1);
10862 foreach_vpe_api_reply_msg;
10865 vl_msg_api_set_first_available_msg_id (VL_MSG_FIRST_AVAILABLE);
10867 vam->sw_if_index_by_interface_name =
10868 hash_create_string (0, sizeof (uword));
10870 vam->function_by_name =
10871 hash_create_string (0, sizeof(uword));
10873 vam->help_by_name =
10874 hash_create_string (0, sizeof(uword));
10876 /* API messages we can send */
10877 #define _(n,h) hash_set_mem (vam->function_by_name, #n, api_##n);
10878 foreach_vpe_api_msg;
10882 #define _(n,h) hash_set_mem (vam->help_by_name, #n, h);
10883 foreach_vpe_api_msg;
10886 /* CLI functions */
10887 #define _(n,h) hash_set_mem (vam->function_by_name, #n, n);
10888 foreach_cli_function;
10892 #define _(n,h) hash_set_mem (vam->help_by_name, #n, h);
10893 foreach_cli_function;
10897 #undef vl_api_version
10898 #define vl_api_version(n,v) static u32 vpe_api_version = v;
10899 #include <api/vpe.api.h>
10900 #undef vl_api_version
10902 void vl_client_add_api_signatures (vl_api_memclnt_create_t *mp)
10905 * Send the main API signature in slot 0. This bit of code must
10906 * match the checks in ../vpe/api/api.c: vl_msg_api_version_check().
10908 mp->api_versions[0] = clib_host_to_net_u32 (vpe_api_version);