2 *------------------------------------------------------------------
5 * Copyright (c) 2014 Cisco and/or its affiliates.
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at:
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 *------------------------------------------------------------------
21 #include <vlibapi/api.h>
22 #include <vlibmemory/api.h>
23 #include <vlibsocket/api.h>
24 #include <vnet/ip/ip.h>
25 #include <vnet/sr/sr_packet.h>
26 #include <vnet/l2/l2_input.h>
27 #include <vnet/l2tp/l2tp.h>
28 #include <vnet/vxlan/vxlan.h>
29 #include <vnet/nsh-gre/nsh_gre.h>
30 #include <vnet/nsh-vxlan-gpe/nsh_vxlan_gpe.h>
31 #include <vnet/lisp-gpe/lisp_gpe.h>
33 #include <api/vpe_msg_enum.h>
34 #include <vnet/l2/l2_classify.h>
35 #include <vnet/l2/l2_vtr.h>
36 #include <vnet/classify/input_acl.h>
38 #include <vnet/ipsec/ipsec.h>
42 #include <vnet/map/map.h>
43 #include <vnet/cop/cop.h>
45 #include "vat/json_format.h"
47 #define vl_typedefs /* define message structures */
48 #include <api/vpe_all_api_h.h>
51 /* declare message handlers for each api */
53 #define vl_endianfun /* define message structures */
54 #include <api/vpe_all_api_h.h>
57 /* instantiate all the print functions we know about */
58 #define vl_print(handle, ...)
60 #include <api/vpe_all_api_h.h>
63 uword unformat_sw_if_index (unformat_input_t * input, va_list * args)
65 vat_main_t * vam = va_arg (*args, vat_main_t *);
66 u32 * result = va_arg (*args, u32 *);
70 if (!unformat (input, "%s", &if_name))
73 p = hash_get_mem (vam->sw_if_index_by_interface_name, if_name);
80 /* Parse an IP4 address %d.%d.%d.%d. */
81 uword unformat_ip4_address (unformat_input_t * input, va_list * args)
83 u8 * result = va_arg (*args, u8 *);
86 if (! unformat (input, "%d.%d.%d.%d", &a[0], &a[1], &a[2], &a[3]))
89 if (a[0] >= 256 || a[1] >= 256 || a[2] >= 256 || a[3] >= 256)
102 unformat_ethernet_address (unformat_input_t * input, va_list * args)
104 u8 * result = va_arg (*args, u8 *);
107 if (! unformat (input, "%_%x:%x:%x:%x:%x:%x%_",
108 &a[0], &a[1], &a[2], &a[3], &a[4], &a[5]))
112 for (i = 0; i < 6; i++)
113 if (a[i] >= (1 << 8))
116 for (i = 0; i < 6; i++)
122 /* Returns ethernet type as an int in host byte order. */
124 unformat_ethernet_type_host_byte_order (unformat_input_t * input,
127 u16 * result = va_arg (*args, u16 *);
131 if (unformat (input, "0x%x", &type)
132 || unformat (input, "%d", &type))
134 if (type >= (1 << 16))
142 /* Parse an IP6 address. */
143 uword unformat_ip6_address (unformat_input_t * input, va_list * args)
145 ip6_address_t * result = va_arg (*args, ip6_address_t *);
147 uword hex_quad, n_hex_quads, hex_digit, n_hex_digits;
148 uword c, n_colon, double_colon_index;
150 n_hex_quads = hex_quad = n_hex_digits = n_colon = 0;
151 double_colon_index = ARRAY_LEN (hex_quads);
152 while ((c = unformat_get_input (input)) != UNFORMAT_END_OF_INPUT)
155 if (c >= '0' && c <= '9')
157 else if (c >= 'a' && c <= 'f')
158 hex_digit = c + 10 - 'a';
159 else if (c >= 'A' && c <= 'F')
160 hex_digit = c + 10 - 'A';
161 else if (c == ':' && n_colon < 2)
165 unformat_put_input (input);
169 /* Too many hex quads. */
170 if (n_hex_quads >= ARRAY_LEN (hex_quads))
175 hex_quad = (hex_quad << 4) | hex_digit;
177 /* Hex quad must fit in 16 bits. */
178 if (n_hex_digits >= 4)
185 /* Save position of :: */
188 /* More than one :: ? */
189 if (double_colon_index < ARRAY_LEN (hex_quads))
191 double_colon_index = n_hex_quads;
194 if (n_colon > 0 && n_hex_digits > 0)
196 hex_quads[n_hex_quads++] = hex_quad;
202 if (n_hex_digits > 0)
203 hex_quads[n_hex_quads++] = hex_quad;
208 /* Expand :: to appropriate number of zero hex quads. */
209 if (double_colon_index < ARRAY_LEN (hex_quads))
211 word n_zero = ARRAY_LEN (hex_quads) - n_hex_quads;
213 for (i = n_hex_quads - 1; i >= (signed) double_colon_index; i--)
214 hex_quads[n_zero + i] = hex_quads[i];
216 for (i = 0; i < n_zero; i++)
217 hex_quads[double_colon_index + i] = 0;
219 n_hex_quads = ARRAY_LEN (hex_quads);
222 /* Too few hex quads given. */
223 if (n_hex_quads < ARRAY_LEN (hex_quads))
226 for (i = 0; i < ARRAY_LEN (hex_quads); i++)
227 result->as_u16[i] = clib_host_to_net_u16 (hex_quads[i]);
234 unformat_ipsec_policy_action (unformat_input_t * input, va_list * args)
237 u32 * r = va_arg (*args, u32 *);
240 #define _(v,f,s) else if (unformat (input, s)) *r = IPSEC_POLICY_ACTION_##f;
241 foreach_ipsec_policy_action
252 unformat_ipsec_crypto_alg (unformat_input_t * input, va_list * args)
255 u32 * r = va_arg (*args, u32 *);
258 #define _(v,f,s) else if (unformat (input, s)) *r = IPSEC_CRYPTO_ALG_##f;
259 foreach_ipsec_crypto_alg
270 format_ipsec_crypto_alg (u8 * s, va_list * args)
273 u32 i = va_arg (*args, u32);
278 #define _(v,f,str) case IPSEC_CRYPTO_ALG_##f: t = (u8 *) str; break;
279 foreach_ipsec_crypto_alg
282 return format (s, "unknown");
284 return format (s, "%s", t);
286 return format (s, "Unimplemented");
291 unformat_ipsec_integ_alg (unformat_input_t * input, va_list * args)
294 u32 * r = va_arg (*args, u32 *);
297 #define _(v,f,s) else if (unformat (input, s)) *r = IPSEC_INTEG_ALG_##f;
298 foreach_ipsec_integ_alg
309 format_ipsec_integ_alg (u8 * s, va_list * args)
312 u32 i = va_arg (*args, u32);
317 #define _(v,f,str) case IPSEC_INTEG_ALG_##f: t = (u8 *) str; break;
318 foreach_ipsec_integ_alg
321 return format (s, "unknown");
323 return format (s, "%s", t);
325 return format (s, "Unsupported");
329 u8 * format_ip4_address (u8 * s, va_list * args)
331 u8 * a = va_arg (*args, u8 *);
332 return format (s, "%d.%d.%d.%d", a[0], a[1], a[2], a[3]);
335 u8 * format_ip6_address (u8 * s, va_list * args)
337 ip6_address_t * a = va_arg (*args, ip6_address_t *);
338 u32 i, i_max_n_zero, max_n_zeros, i_first_zero, n_zeros, last_double_colon;
340 i_max_n_zero = ARRAY_LEN (a->as_u16);
342 i_first_zero = i_max_n_zero;
344 for (i = 0; i < ARRAY_LEN (a->as_u16); i++)
346 u32 is_zero = a->as_u16[i] == 0;
347 if (is_zero && i_first_zero >= ARRAY_LEN (a->as_u16))
353 if ((! is_zero && n_zeros > max_n_zeros)
354 || (i + 1 >= ARRAY_LEN (a->as_u16) && n_zeros > max_n_zeros))
356 i_max_n_zero = i_first_zero;
357 max_n_zeros = n_zeros;
358 i_first_zero = ARRAY_LEN (a->as_u16);
363 last_double_colon = 0;
364 for (i = 0; i < ARRAY_LEN (a->as_u16); i++)
366 if (i == i_max_n_zero && max_n_zeros > 1)
368 s = format (s, "::");
369 i += max_n_zeros - 1;
370 last_double_colon = 1;
374 s = format (s, "%s%x",
375 (last_double_colon || i == 0) ? "" : ":",
376 clib_net_to_host_u16 (a->as_u16[i]));
377 last_double_colon = 0;
384 u8 * format_ethernet_address (u8 * s, va_list * args)
386 u8 * a = va_arg (*args, u8 *);
388 return format (s, "%02x:%02x:%02x:%02x:%02x:%02x",
389 a[0], a[1], a[2], a[3], a[4], a[5]);
392 void increment_v4_address (ip4_address_t * a)
396 v = ntohl(a->as_u32) + 1;
397 a->as_u32 = ntohl(v);
400 void increment_v6_address (ip6_address_t * a)
404 v0 = clib_net_to_host_u64 (a->as_u64[0]);
405 v1 = clib_net_to_host_u64 (a->as_u64[1]);
410 a->as_u64[0] = clib_net_to_host_u64 (v0);
411 a->as_u64[1] = clib_net_to_host_u64 (v1);
415 static void vl_api_create_loopback_reply_t_handler
416 (vl_api_create_loopback_reply_t * mp)
418 vat_main_t * vam = &vat_main;
419 i32 retval = ntohl(mp->retval);
421 vam->retval = retval;
422 vam->result_ready = 1;
423 vam->regenerate_interface_table = 1;
426 static void vl_api_create_loopback_reply_t_handler_json
427 (vl_api_create_loopback_reply_t * mp)
429 vat_main_t * vam = &vat_main;
430 vat_json_node_t node;
432 vat_json_init_object(&node);
433 vat_json_object_add_int(&node, "retval", ntohl(mp->retval));
434 vat_json_object_add_uint(&node, "sw_if_index", ntohl(mp->sw_if_index));
436 vat_json_print(vam->ofp, &node);
437 vat_json_free(&node);
439 vam->retval = ntohl(mp->retval);
440 vam->result_ready = 1;
443 static void vl_api_create_vlan_subif_reply_t_handler
444 (vl_api_create_vlan_subif_reply_t * mp)
446 vat_main_t * vam = &vat_main;
447 i32 retval = ntohl(mp->retval);
449 vam->retval = retval;
450 vam->result_ready = 1;
451 vam->regenerate_interface_table = 1;
454 static void vl_api_create_vlan_subif_reply_t_handler_json
455 (vl_api_create_vlan_subif_reply_t * mp)
457 vat_main_t * vam = &vat_main;
458 vat_json_node_t node;
460 vat_json_init_object(&node);
461 vat_json_object_add_int(&node, "retval", ntohl(mp->retval));
462 vat_json_object_add_uint(&node, "sw_if_index", ntohl(mp->sw_if_index));
464 vat_json_print(vam->ofp, &node);
465 vat_json_free(&node);
467 vam->retval = ntohl(mp->retval);
468 vam->result_ready = 1;
471 static void vl_api_create_subif_reply_t_handler
472 (vl_api_create_subif_reply_t * mp)
474 vat_main_t * vam = &vat_main;
475 i32 retval = ntohl(mp->retval);
477 vam->retval = retval;
478 vam->result_ready = 1;
479 vam->regenerate_interface_table = 1;
482 static void vl_api_create_subif_reply_t_handler_json
483 (vl_api_create_subif_reply_t * mp)
485 vat_main_t * vam = &vat_main;
486 vat_json_node_t node;
488 vat_json_init_object(&node);
489 vat_json_object_add_int(&node, "retval", ntohl(mp->retval));
490 vat_json_object_add_uint(&node, "sw_if_index", ntohl(mp->sw_if_index));
492 vat_json_print(vam->ofp, &node);
493 vat_json_free(&node);
495 vam->retval = ntohl(mp->retval);
496 vam->result_ready = 1;
499 static void vl_api_interface_name_renumber_reply_t_handler
500 (vl_api_interface_name_renumber_reply_t * mp)
502 vat_main_t * vam = &vat_main;
503 i32 retval = ntohl(mp->retval);
505 vam->retval = retval;
506 vam->result_ready = 1;
507 vam->regenerate_interface_table = 1;
510 static void vl_api_interface_name_renumber_reply_t_handler_json
511 (vl_api_interface_name_renumber_reply_t * mp)
513 vat_main_t * vam = &vat_main;
514 vat_json_node_t node;
516 vat_json_init_object(&node);
517 vat_json_object_add_int(&node, "retval", ntohl(mp->retval));
519 vat_json_print(vam->ofp, &node);
520 vat_json_free(&node);
522 vam->retval = ntohl(mp->retval);
523 vam->result_ready = 1;
527 * Special-case: build the interface table, maintain
528 * the next loopback sw_if_index vbl.
530 static void vl_api_sw_interface_details_t_handler
531 (vl_api_sw_interface_details_t * mp)
533 vat_main_t * vam = &vat_main;
534 u8 * s = format (0, "%s%c", mp->interface_name, 0);
536 hash_set_mem (vam->sw_if_index_by_interface_name, s,
537 ntohl(mp->sw_if_index));
539 /* In sub interface case, fill the sub interface table entry */
540 if (mp->sw_if_index != mp->sup_sw_if_index) {
541 sw_interface_subif_t * sub = NULL;
543 vec_add2(vam->sw_if_subif_table, sub, 1);
545 vec_validate(sub->interface_name, strlen((char *)s) + 1);
546 strncpy((char *)sub->interface_name, (char *)s,
547 vec_len(sub->interface_name));
548 sub->sw_if_index = ntohl(mp->sw_if_index);
549 sub->sub_id = ntohl(mp->sub_id);
551 sub->sub_dot1ad = mp->sub_dot1ad;
552 sub->sub_number_of_tags = mp->sub_number_of_tags;
553 sub->sub_outer_vlan_id = ntohs(mp->sub_outer_vlan_id);
554 sub->sub_inner_vlan_id = ntohs(mp->sub_inner_vlan_id);
555 sub->sub_exact_match = mp->sub_exact_match;
556 sub->sub_default = mp->sub_default;
557 sub->sub_outer_vlan_id_any = mp->sub_outer_vlan_id_any;
558 sub->sub_inner_vlan_id_any = mp->sub_inner_vlan_id_any;
560 /* vlan tag rewrite */
561 sub->vtr_op = ntohl(mp->vtr_op);
562 sub->vtr_push_dot1q = ntohl(mp->vtr_push_dot1q);
563 sub->vtr_tag1 = ntohl(mp->vtr_tag1);
564 sub->vtr_tag2 = ntohl(mp->vtr_tag2);
568 static void vl_api_sw_interface_details_t_handler_json
569 (vl_api_sw_interface_details_t * mp)
571 vat_main_t * vam = &vat_main;
572 vat_json_node_t *node = NULL;
574 if (VAT_JSON_ARRAY != vam->json_tree.type) {
575 ASSERT(VAT_JSON_NONE == vam->json_tree.type);
576 vat_json_init_array(&vam->json_tree);
578 node = vat_json_array_add(&vam->json_tree);
580 vat_json_init_object(node);
581 vat_json_object_add_uint(node, "sw_if_index", ntohl(mp->sw_if_index));
582 vat_json_object_add_uint(node, "sup_sw_if_index", ntohl(mp->sup_sw_if_index));
583 vat_json_object_add_uint(node, "l2_address_length", ntohl(mp->l2_address_length));
584 vat_json_object_add_bytes(node, "l2_address", mp->l2_address, sizeof(mp->l2_address));
585 vat_json_object_add_string_copy(node, "interface_name", mp->interface_name);
586 vat_json_object_add_uint(node, "admin_up_down", mp->admin_up_down);
587 vat_json_object_add_uint(node, "link_up_down", mp->link_up_down);
588 vat_json_object_add_uint(node, "link_duplex", mp->link_duplex);
589 vat_json_object_add_uint(node, "link_speed", mp->link_speed);
590 vat_json_object_add_uint(node, "mtu", ntohs(mp->link_mtu));
591 vat_json_object_add_uint(node, "sub_id", ntohl(mp->sub_id));
592 vat_json_object_add_uint(node, "sub_dot1ad", mp->sub_dot1ad);
593 vat_json_object_add_uint(node, "sub_number_of_tags", mp->sub_number_of_tags);
594 vat_json_object_add_uint(node, "sub_outer_vlan_id", ntohs(mp->sub_outer_vlan_id));
595 vat_json_object_add_uint(node, "sub_inner_vlan_id", ntohs(mp->sub_inner_vlan_id));
596 vat_json_object_add_uint(node, "sub_exact_match", mp->sub_exact_match);
597 vat_json_object_add_uint(node, "sub_default", mp->sub_default);
598 vat_json_object_add_uint(node, "sub_outer_vlan_id_any", mp->sub_outer_vlan_id_any);
599 vat_json_object_add_uint(node, "sub_inner_vlan_id_any", mp->sub_inner_vlan_id_any);
600 vat_json_object_add_uint(node, "vtr_op", ntohl(mp->vtr_op));
601 vat_json_object_add_uint(node, "vtr_push_dot1q", ntohl(mp->vtr_push_dot1q));
602 vat_json_object_add_uint(node, "vtr_tag1", ntohl(mp->vtr_tag1));
603 vat_json_object_add_uint(node, "vtr_tag2", ntohl(mp->vtr_tag2));
606 static void vl_api_sw_interface_set_flags_t_handler
607 (vl_api_sw_interface_set_flags_t * mp)
609 vat_main_t * vam = &vat_main;
610 if (vam->interface_event_display)
611 errmsg ("interface flags: sw_if_index %d %s %s\n",
612 ntohl(mp->sw_if_index),
613 mp->admin_up_down ? "admin-up" : "admin-down",
614 mp->link_up_down ? "link-up" : "link-down");
617 static void vl_api_sw_interface_set_flags_t_handler_json
618 (vl_api_sw_interface_set_flags_t * mp)
620 /* JSON output not supported */
623 static void vl_api_cli_reply_t_handler
624 (vl_api_cli_reply_t * mp)
626 vat_main_t * vam = &vat_main;
627 i32 retval = ntohl(mp->retval);
629 vam->retval = retval;
630 vam->shmem_result = (u8 *) mp->reply_in_shmem;
631 vam->result_ready = 1;
634 static void vl_api_cli_reply_t_handler_json
635 (vl_api_cli_reply_t * mp)
637 vat_main_t * vam = &vat_main;
638 vat_json_node_t node;
639 api_main_t * am = &api_main;
643 vat_json_init_object(&node);
644 vat_json_object_add_int(&node, "retval", ntohl(mp->retval));
645 vat_json_object_add_uint(&node, "reply_in_shmem",
646 ntohl(mp->reply_in_shmem));
647 /* Toss the shared-memory original... */
648 pthread_mutex_lock (&am->vlib_rp->mutex);
649 oldheap = svm_push_data_heap (am->vlib_rp);
651 reply = (u8 *)(mp->reply_in_shmem);
654 svm_pop_heap (oldheap);
655 pthread_mutex_unlock (&am->vlib_rp->mutex);
657 vat_json_print(vam->ofp, &node);
658 vat_json_free(&node);
660 vam->retval = ntohl(mp->retval);
661 vam->result_ready = 1;
664 static void vl_api_classify_add_del_table_reply_t_handler
665 (vl_api_classify_add_del_table_reply_t * mp)
667 vat_main_t * vam = &vat_main;
668 i32 retval = ntohl(mp->retval);
669 if (vam->async_mode) {
670 vam->async_errors += (retval < 0);
672 vam->retval = retval;
673 vam->result_ready = 1;
675 ((mp->new_table_index != 0xFFFFFFFF) ||
676 (mp->skip_n_vectors != 0xFFFFFFFF) ||
677 (mp->match_n_vectors != 0xFFFFFFFF)))
679 * Note: this is just barely thread-safe, depends on
680 * the main thread spinning waiting for an answer...
682 errmsg ("new index %d, skip_n_vectors %d, match_n_vectors %d\n",
683 ntohl(mp->new_table_index),
684 ntohl(mp->skip_n_vectors), ntohl(mp->match_n_vectors));
688 static void vl_api_classify_add_del_table_reply_t_handler_json
689 (vl_api_classify_add_del_table_reply_t * mp)
691 vat_main_t * vam = &vat_main;
692 vat_json_node_t node;
694 vat_json_init_object(&node);
695 vat_json_object_add_int(&node, "retval", ntohl(mp->retval));
696 vat_json_object_add_uint(&node, "new_table_index", ntohl(mp->new_table_index));
697 vat_json_object_add_uint(&node, "skip_n_vectors", ntohl(mp->skip_n_vectors));
698 vat_json_object_add_uint(&node, "match_n_vectors", ntohl(mp->match_n_vectors));
700 vat_json_print(vam->ofp, &node);
701 vat_json_free(&node);
703 vam->retval = ntohl(mp->retval);
704 vam->result_ready = 1;
707 static void vl_api_get_node_index_reply_t_handler
708 (vl_api_get_node_index_reply_t * mp)
710 vat_main_t * vam = &vat_main;
711 i32 retval = ntohl(mp->retval);
712 if (vam->async_mode) {
713 vam->async_errors += (retval < 0);
715 vam->retval = retval;
716 vam->result_ready = 1;
718 errmsg ("node index %d\n", ntohl(mp->node_index));
722 static void vl_api_get_node_index_reply_t_handler_json
723 (vl_api_get_node_index_reply_t * mp)
725 vat_main_t * vam = &vat_main;
726 vat_json_node_t node;
728 vat_json_init_object(&node);
729 vat_json_object_add_int(&node, "retval", ntohl(mp->retval));
730 vat_json_object_add_uint(&node, "node_index", ntohl(mp->node_index));
732 vat_json_print(vam->ofp, &node);
733 vat_json_free(&node);
735 vam->retval = ntohl(mp->retval);
736 vam->result_ready = 1;
739 static void vl_api_add_node_next_reply_t_handler
740 (vl_api_add_node_next_reply_t * mp)
742 vat_main_t * vam = &vat_main;
743 i32 retval = ntohl(mp->retval);
744 if (vam->async_mode) {
745 vam->async_errors += (retval < 0);
747 vam->retval = retval;
748 vam->result_ready = 1;
750 errmsg ("next index %d\n", ntohl(mp->next_index));
754 static void vl_api_add_node_next_reply_t_handler_json
755 (vl_api_add_node_next_reply_t * mp)
757 vat_main_t * vam = &vat_main;
758 vat_json_node_t node;
760 vat_json_init_object(&node);
761 vat_json_object_add_int(&node, "retval", ntohl(mp->retval));
762 vat_json_object_add_uint(&node, "next_index", ntohl(mp->next_index));
764 vat_json_print(vam->ofp, &node);
765 vat_json_free(&node);
767 vam->retval = ntohl(mp->retval);
768 vam->result_ready = 1;
771 static void vl_api_mpls_gre_add_del_tunnel_reply_t_handler
772 (vl_api_mpls_gre_add_del_tunnel_reply_t * mp)
774 vat_main_t * vam = &vat_main;
775 i32 retval = ntohl(mp->retval);
776 u32 sw_if_index = ntohl(mp->tunnel_sw_if_index);
778 if (retval >= 0 && sw_if_index != (u32)~0) {
779 errmsg ("tunnel_sw_if_index %d\n", sw_if_index);
781 vam->retval = retval;
782 vam->result_ready = 1;
785 static void vl_api_mpls_gre_add_del_tunnel_reply_t_handler_json
786 (vl_api_mpls_gre_add_del_tunnel_reply_t * mp)
788 vat_main_t * vam = &vat_main;
789 vat_json_node_t node;
791 vat_json_init_object(&node);
792 vat_json_object_add_int(&node, "retval", ntohl(mp->retval));
793 vat_json_object_add_uint(&node, "tunnel_sw_if_index", ntohl(mp->tunnel_sw_if_index));
795 vat_json_print(vam->ofp, &node);
796 vat_json_free(&node);
798 vam->retval = ntohl(mp->retval);
799 vam->result_ready = 1;
802 static void vl_api_nsh_gre_add_del_tunnel_reply_t_handler
803 (vl_api_nsh_gre_add_del_tunnel_reply_t * mp)
805 vat_main_t * vam = &vat_main;
806 i32 retval = ntohl(mp->retval);
807 u32 sw_if_index = ntohl(mp->sw_if_index);
809 if (retval >= 0 && sw_if_index != (u32)~0) {
810 errmsg ("sw_if_index %d\n", ntohl(mp->sw_if_index));
812 vam->retval = retval;
813 vam->result_ready = 1;
816 static void vl_api_nsh_gre_add_del_tunnel_reply_t_handler_json
817 (vl_api_nsh_gre_add_del_tunnel_reply_t * mp)
819 vat_main_t * vam = &vat_main;
820 vat_json_node_t node;
822 vat_json_init_object(&node);
823 vat_json_object_add_int(&node, "retval", ntohl(mp->retval));
824 vat_json_object_add_uint(&node, "sw_if_index", ntohl(mp->sw_if_index));
826 vat_json_print(vam->ofp, &node);
827 vat_json_free(&node);
829 vam->retval = ntohl(mp->retval);
830 vam->result_ready = 1;
833 static void vl_api_nsh_vxlan_gpe_add_del_tunnel_reply_t_handler
834 (vl_api_nsh_vxlan_gpe_add_del_tunnel_reply_t * mp)
836 vat_main_t * vam = &vat_main;
837 i32 retval = ntohl(mp->retval);
838 u32 sw_if_index = ntohl(mp->sw_if_index);
840 if (retval >= 0 && sw_if_index != (u32)~0) {
841 errmsg ("sw_if_index %d\n", ntohl(mp->sw_if_index));
843 vam->retval = retval;
844 vam->result_ready = 1;
847 static void vl_api_nsh_vxlan_gpe_add_del_tunnel_reply_t_handler_json
848 (vl_api_nsh_vxlan_gpe_add_del_tunnel_reply_t * mp)
850 vat_main_t * vam = &vat_main;
851 vat_json_node_t node;
853 vat_json_init_object(&node);
854 vat_json_object_add_int(&node, "retval", ntohl(mp->retval));
855 vat_json_object_add_uint(&node, "sw_if_index", ntohl(mp->sw_if_index));
857 vat_json_print(vam->ofp, &node);
858 vat_json_free(&node);
860 vam->retval = ntohl(mp->retval);
861 vam->result_ready = 1;
864 static void vl_api_lisp_gpe_add_del_tunnel_reply_t_handler
865 (vl_api_lisp_gpe_add_del_tunnel_reply_t * mp)
867 vat_main_t * vam = &vat_main;
868 i32 retval = ntohl(mp->retval);
869 u32 sw_if_index = ntohl(mp->sw_if_index);
871 if (retval >= 0 && sw_if_index != (u32)~0) {
872 errmsg ("sw_if_index %d\n", ntohl(mp->sw_if_index));
874 vam->retval = retval;
875 vam->result_ready = 1;
878 static void vl_api_lisp_gpe_add_del_tunnel_reply_t_handler_json
879 (vl_api_lisp_gpe_add_del_tunnel_reply_t * mp)
881 vat_main_t * vam = &vat_main;
882 vat_json_node_t node;
884 vat_json_init_object(&node);
885 vat_json_object_add_int(&node, "retval", ntohl(mp->retval));
886 vat_json_object_add_uint(&node, "sw_if_index", ntohl(mp->sw_if_index));
888 vat_json_print(vam->ofp, &node);
889 vat_json_free(&node);
891 vam->retval = ntohl(mp->retval);
892 vam->result_ready = 1;
895 static void vl_api_show_version_reply_t_handler
896 (vl_api_show_version_reply_t * mp)
898 vat_main_t * vam = &vat_main;
899 i32 retval = ntohl(mp->retval);
902 errmsg (" program: %s\n", mp->program);
903 errmsg (" version: %s\n", mp->version);
904 errmsg (" build date: %s\n", mp->build_date);
905 errmsg ("build directory: %s\n", mp->build_directory);
907 vam->retval = retval;
908 vam->result_ready = 1;
911 static void vl_api_show_version_reply_t_handler_json
912 (vl_api_show_version_reply_t * mp)
914 vat_main_t * vam = &vat_main;
915 vat_json_node_t node;
917 vat_json_init_object(&node);
918 vat_json_object_add_int(&node, "retval", ntohl(mp->retval));
919 vat_json_object_add_string_copy(&node, "program", mp->program);
920 vat_json_object_add_string_copy(&node, "version", mp->version);
921 vat_json_object_add_string_copy(&node, "build_date", mp->build_date);
922 vat_json_object_add_string_copy(&node, "build_directory", mp->build_directory);
924 vat_json_print(vam->ofp, &node);
925 vat_json_free(&node);
927 vam->retval = ntohl(mp->retval);
928 vam->result_ready = 1;
931 static void vl_api_ip4_arp_event_t_handler
932 (vl_api_ip4_arp_event_t * mp)
934 vat_main_t * vam = &vat_main;
935 errmsg ("arp event: address %U new mac %U sw_if_index %d\n",
936 format_ip4_address, &mp->address,
937 format_ethernet_address, mp->new_mac, mp->sw_if_index);
940 static void vl_api_ip4_arp_event_t_handler_json
941 (vl_api_ip4_arp_event_t * mp)
943 /* JSON output not supported */
947 * Special-case: build the bridge domain table, maintain
948 * the next bd id vbl.
950 static void vl_api_bridge_domain_details_t_handler
951 (vl_api_bridge_domain_details_t * mp)
953 vat_main_t * vam = &vat_main;
954 u32 n_sw_ifs = ntohl (mp->n_sw_ifs);
956 fformat (vam->ofp, "\n%-3s %-3s %-3s %-3s %-3s %-3s\n",
957 " ID", "LRN", "FWD", "FLD", "BVI", "#IF");
959 fformat (vam->ofp, "%3d %3d %3d %3d %3d %3d\n",
960 ntohl (mp->bd_id), mp->learn, mp->forward,
961 mp->flood, ntohl (mp->bvi_sw_if_index), n_sw_ifs);
964 fformat (vam->ofp, "\n\n%s %s %s\n", "sw_if_index", "SHG",
968 static void vl_api_bridge_domain_details_t_handler_json
969 (vl_api_bridge_domain_details_t * mp)
971 vat_main_t * vam = &vat_main;
972 vat_json_node_t *node, *array = NULL;
974 if (VAT_JSON_ARRAY != vam->json_tree.type) {
975 ASSERT(VAT_JSON_NONE == vam->json_tree.type);
976 vat_json_init_array(&vam->json_tree);
978 node = vat_json_array_add(&vam->json_tree);
980 vat_json_init_object(node);
981 vat_json_object_add_uint(node, "bd_id", ntohl(mp->bd_id));
982 vat_json_object_add_uint(node, "flood", mp->flood);
983 vat_json_object_add_uint(node, "forward", mp->forward);
984 vat_json_object_add_uint(node, "learn", mp->learn);
985 vat_json_object_add_uint(node, "bvi_sw_if_index", ntohl(mp->bvi_sw_if_index));
986 vat_json_object_add_uint(node, "n_sw_ifs", ntohl(mp->n_sw_ifs));
987 array = vat_json_object_add(node, "sw_if");
988 vat_json_init_array(array);
992 * Special-case: build the bridge domain sw if table.
994 static void vl_api_bridge_domain_sw_if_details_t_handler
995 (vl_api_bridge_domain_sw_if_details_t * mp)
997 vat_main_t * vam = &vat_main;
1002 sw_if_index = ntohl (mp->sw_if_index);
1003 hash_foreach_pair (p, vam->sw_if_index_by_interface_name,
1005 if ((u32) p->value[0] == sw_if_index) {
1006 sw_if_name = (u8 *)(p->key);
1011 fformat (vam->ofp, "%7d %3d %s", sw_if_index,
1012 mp->shg, sw_if_name ? (char *)sw_if_name :
1013 "sw_if_index not found!");
1016 static void vl_api_bridge_domain_sw_if_details_t_handler_json
1017 (vl_api_bridge_domain_sw_if_details_t * mp)
1019 vat_main_t * vam = &vat_main;
1020 vat_json_node_t *node = NULL;
1021 uword last_index = 0;
1023 ASSERT(VAT_JSON_ARRAY == vam->json_tree.type);
1024 ASSERT(vec_len(vam->json_tree.array) >= 1);
1025 last_index = vec_len(vam->json_tree.array) - 1;
1026 node = &vam->json_tree.array[last_index];
1027 node = vat_json_object_get_element(node, "sw_if");
1028 ASSERT(NULL != node);
1029 node = vat_json_array_add(node);
1031 vat_json_init_object(node);
1032 vat_json_object_add_uint(node, "bd_id", ntohl(mp->bd_id));
1033 vat_json_object_add_uint(node, "sw_if_index", ntohl(mp->sw_if_index));
1034 vat_json_object_add_uint(node, "shg", mp->shg);
1037 static void vl_api_control_ping_reply_t_handler
1038 (vl_api_control_ping_reply_t * mp)
1040 vat_main_t * vam = &vat_main;
1041 i32 retval = ntohl(mp->retval);
1042 if (vam->async_mode) {
1043 vam->async_errors += (retval < 0);
1045 vam->retval = retval;
1046 vam->result_ready = 1;
1050 static void vl_api_control_ping_reply_t_handler_json
1051 (vl_api_control_ping_reply_t * mp)
1053 vat_main_t * vam = &vat_main;
1054 i32 retval = ntohl(mp->retval);
1056 if (VAT_JSON_NONE != vam->json_tree.type) {
1057 vat_json_print(vam->ofp, &vam->json_tree);
1058 vat_json_free(&vam->json_tree);
1059 vam->json_tree.type = VAT_JSON_NONE;
1062 vat_json_init_array(&vam->json_tree);
1063 vat_json_print(vam->ofp, &vam->json_tree);
1064 vam->json_tree.type = VAT_JSON_NONE;
1067 vam->retval = retval;
1068 vam->result_ready = 1;
1071 static void vl_api_l2_flags_reply_t_handler
1072 (vl_api_l2_flags_reply_t * mp)
1074 vat_main_t * vam = &vat_main;
1075 i32 retval = ntohl(mp->retval);
1076 if (vam->async_mode) {
1077 vam->async_errors += (retval < 0);
1079 vam->retval = retval;
1080 vam->result_ready = 1;
1084 static void vl_api_l2_flags_reply_t_handler_json
1085 (vl_api_l2_flags_reply_t * mp)
1087 vat_main_t * vam = &vat_main;
1088 vat_json_node_t node;
1090 vat_json_init_object(&node);
1091 vat_json_object_add_int(&node, "retval", ntohl(mp->retval));
1092 vat_json_object_add_uint(&node, "resulting_feature_bitmap", ntohl(mp->resulting_feature_bitmap));
1094 vat_json_print(vam->ofp, &node);
1095 vat_json_free(&node);
1097 vam->retval = ntohl(mp->retval);
1098 vam->result_ready = 1;
1101 static void vl_api_bridge_flags_reply_t_handler
1102 (vl_api_bridge_flags_reply_t * mp)
1104 vat_main_t * vam = &vat_main;
1105 i32 retval = ntohl(mp->retval);
1106 if (vam->async_mode) {
1107 vam->async_errors += (retval < 0);
1109 vam->retval = retval;
1110 vam->result_ready = 1;
1114 static void vl_api_bridge_flags_reply_t_handler_json
1115 (vl_api_bridge_flags_reply_t * mp)
1117 vat_main_t * vam = &vat_main;
1118 vat_json_node_t node;
1120 vat_json_init_object(&node);
1121 vat_json_object_add_int(&node, "retval", ntohl(mp->retval));
1122 vat_json_object_add_uint(&node, "resulting_feature_bitmap", ntohl(mp->resulting_feature_bitmap));
1124 vat_json_print(vam->ofp, &node);
1125 vat_json_free(&node);
1127 vam->retval = ntohl(mp->retval);
1128 vam->result_ready = 1;
1131 static void vl_api_tap_connect_reply_t_handler
1132 (vl_api_tap_connect_reply_t * mp)
1134 vat_main_t * vam = &vat_main;
1135 i32 retval = ntohl(mp->retval);
1136 if (vam->async_mode) {
1137 vam->async_errors += (retval < 0);
1139 vam->retval = retval;
1140 vam->result_ready = 1;
1144 static void vl_api_tap_connect_reply_t_handler_json
1145 (vl_api_tap_connect_reply_t * mp)
1147 vat_main_t * vam = &vat_main;
1148 vat_json_node_t node;
1150 vat_json_init_object(&node);
1151 vat_json_object_add_int(&node, "retval", ntohl(mp->retval));
1152 vat_json_object_add_uint(&node, "sw_if_index", ntohl(mp->sw_if_index));
1154 vat_json_print(vam->ofp, &node);
1155 vat_json_free(&node);
1157 vam->retval = ntohl(mp->retval);
1158 vam->result_ready = 1;
1161 static void vl_api_tap_modify_reply_t_handler
1162 (vl_api_tap_modify_reply_t * mp)
1164 vat_main_t * vam = &vat_main;
1165 i32 retval = ntohl(mp->retval);
1166 if (vam->async_mode) {
1167 vam->async_errors += (retval < 0);
1169 vam->retval = retval;
1170 vam->result_ready = 1;
1174 static void vl_api_tap_modify_reply_t_handler_json
1175 (vl_api_tap_modify_reply_t * mp)
1177 vat_main_t * vam = &vat_main;
1178 vat_json_node_t node;
1180 vat_json_init_object(&node);
1181 vat_json_object_add_int(&node, "retval", ntohl(mp->retval));
1182 vat_json_object_add_uint(&node, "sw_if_index", ntohl(mp->sw_if_index));
1184 vat_json_print(vam->ofp, &node);
1185 vat_json_free(&node);
1187 vam->retval = ntohl(mp->retval);
1188 vam->result_ready = 1;
1191 static void vl_api_tap_delete_reply_t_handler
1192 (vl_api_tap_delete_reply_t * mp)
1194 vat_main_t * vam = &vat_main;
1195 i32 retval = ntohl(mp->retval);
1196 if (vam->async_mode) {
1197 vam->async_errors += (retval < 0);
1199 vam->retval = retval;
1200 vam->result_ready = 1;
1204 static void vl_api_tap_delete_reply_t_handler_json
1205 (vl_api_tap_delete_reply_t * mp)
1207 vat_main_t * vam = &vat_main;
1208 vat_json_node_t node;
1210 vat_json_init_object(&node);
1211 vat_json_object_add_int(&node, "retval", ntohl(mp->retval));
1213 vat_json_print(vam->ofp, &node);
1214 vat_json_free(&node);
1216 vam->retval = ntohl(mp->retval);
1217 vam->result_ready = 1;
1220 static void vl_api_mpls_ethernet_add_del_tunnel_reply_t_handler
1221 (vl_api_mpls_ethernet_add_del_tunnel_reply_t * mp)
1223 vat_main_t * vam = &vat_main;
1224 i32 retval = ntohl(mp->retval);
1225 if (vam->async_mode) {
1226 vam->async_errors += (retval < 0);
1228 vam->retval = retval;
1229 vam->result_ready = 1;
1233 static void vl_api_mpls_ethernet_add_del_tunnel_reply_t_handler_json
1234 (vl_api_mpls_ethernet_add_del_tunnel_reply_t * mp)
1236 vat_main_t * vam = &vat_main;
1237 vat_json_node_t node;
1239 vat_json_init_object(&node);
1240 vat_json_object_add_int(&node, "retval", ntohl(mp->retval));
1241 vat_json_object_add_uint(&node, "tunnel_sw_if_index", ntohl(mp->tunnel_sw_if_index));
1243 vat_json_print(vam->ofp, &node);
1244 vat_json_free(&node);
1246 vam->retval = ntohl(mp->retval);
1247 vam->result_ready = 1;
1250 static void vl_api_l2tpv3_create_tunnel_reply_t_handler
1251 (vl_api_l2tpv3_create_tunnel_reply_t * mp)
1253 vat_main_t * vam = &vat_main;
1254 i32 retval = ntohl(mp->retval);
1255 if (vam->async_mode) {
1256 vam->async_errors += (retval < 0);
1258 vam->retval = retval;
1259 vam->result_ready = 1;
1263 static void vl_api_l2tpv3_create_tunnel_reply_t_handler_json
1264 (vl_api_l2tpv3_create_tunnel_reply_t * mp)
1266 vat_main_t * vam = &vat_main;
1267 vat_json_node_t node;
1269 vat_json_init_object(&node);
1270 vat_json_object_add_int(&node, "retval", ntohl(mp->retval));
1271 vat_json_object_add_uint(&node, "sw_if_index", ntohl(mp->sw_if_index));
1273 vat_json_print(vam->ofp, &node);
1274 vat_json_free(&node);
1276 vam->retval = ntohl(mp->retval);
1277 vam->result_ready = 1;
1280 static void vl_api_vxlan_add_del_tunnel_reply_t_handler
1281 (vl_api_vxlan_add_del_tunnel_reply_t * mp)
1283 vat_main_t * vam = &vat_main;
1284 i32 retval = ntohl(mp->retval);
1285 if (vam->async_mode) {
1286 vam->async_errors += (retval < 0);
1288 vam->retval = retval;
1289 vam->result_ready = 1;
1293 static void vl_api_vxlan_add_del_tunnel_reply_t_handler_json
1294 (vl_api_vxlan_add_del_tunnel_reply_t * mp)
1296 vat_main_t * vam = &vat_main;
1297 vat_json_node_t node;
1299 vat_json_init_object(&node);
1300 vat_json_object_add_int(&node, "retval", ntohl(mp->retval));
1301 vat_json_object_add_uint(&node, "sw_if_index", ntohl(mp->sw_if_index));
1303 vat_json_print(vam->ofp, &node);
1304 vat_json_free(&node);
1306 vam->retval = ntohl(mp->retval);
1307 vam->result_ready = 1;
1310 static void vl_api_create_vhost_user_if_reply_t_handler
1311 (vl_api_create_vhost_user_if_reply_t * mp)
1313 vat_main_t * vam = &vat_main;
1314 i32 retval = ntohl(mp->retval);
1315 if (vam->async_mode) {
1316 vam->async_errors += (retval < 0);
1318 vam->retval = retval;
1319 vam->result_ready = 1;
1323 static void vl_api_create_vhost_user_if_reply_t_handler_json
1324 (vl_api_create_vhost_user_if_reply_t * mp)
1326 vat_main_t * vam = &vat_main;
1327 vat_json_node_t node;
1329 vat_json_init_object(&node);
1330 vat_json_object_add_int(&node, "retval", ntohl(mp->retval));
1331 vat_json_object_add_uint(&node, "sw_if_index", ntohl(mp->sw_if_index));
1333 vat_json_print(vam->ofp, &node);
1334 vat_json_free(&node);
1336 vam->retval = ntohl(mp->retval);
1337 vam->result_ready = 1;
1340 static void vl_api_ip_address_details_t_handler
1341 (vl_api_ip_address_details_t * mp)
1343 vat_main_t * vam = &vat_main;
1344 static ip_address_details_t empty_ip_address_details = {{0}};
1345 ip_address_details_t * address = NULL;
1346 ip_details_t * current_ip_details = NULL;
1347 ip_details_t * details = NULL;
1349 details = vam->ip_details_by_sw_if_index[vam->is_ipv6];
1351 if (!details || vam->current_sw_if_index >= vec_len(details)
1352 || !details[vam->current_sw_if_index].present) {
1353 errmsg ("ip address details arrived but not stored\n");
1354 errmsg ("ip_dump should be called first\n");
1358 current_ip_details = vec_elt_at_index(details,
1359 vam->current_sw_if_index);
1361 #define addresses (current_ip_details->addr)
1363 vec_validate_init_empty(addresses, vec_len(addresses),
1364 empty_ip_address_details);
1366 address = vec_elt_at_index(addresses, vec_len(addresses) - 1);
1368 memcpy(&address->ip, &mp->ip, sizeof(address->ip));
1369 address->prefix_length = mp->prefix_length;
1373 static void vl_api_ip_address_details_t_handler_json
1374 (vl_api_ip_address_details_t * mp)
1376 vat_main_t * vam = &vat_main;
1377 vat_json_node_t *node = NULL;
1378 struct in6_addr ip6;
1381 if (VAT_JSON_ARRAY != vam->json_tree.type) {
1382 ASSERT(VAT_JSON_NONE == vam->json_tree.type);
1383 vat_json_init_array(&vam->json_tree);
1385 node = vat_json_array_add(&vam->json_tree);
1387 vat_json_init_object(node);
1389 memcpy(&ip6, mp->ip, sizeof(ip6));
1390 vat_json_object_add_ip6(node, "ip", ip6);
1392 memcpy(&ip4, mp->ip, sizeof(ip4));
1393 vat_json_object_add_ip4(node, "ip", ip4);
1395 vat_json_object_add_uint(node, "prefix_length", mp->prefix_length);
1398 static void vl_api_ip_details_t_handler (vl_api_ip_details_t * mp)
1400 vat_main_t * vam = &vat_main;
1401 static ip_details_t empty_ip_details = {0};
1402 ip_details_t * ip = NULL;
1403 u32 sw_if_index = ~0;
1405 sw_if_index = ntohl(mp->sw_if_index);
1407 vec_validate_init_empty(vam->ip_details_by_sw_if_index[vam->is_ipv6],
1408 sw_if_index, empty_ip_details);
1410 ip = vec_elt_at_index(vam->ip_details_by_sw_if_index[vam->is_ipv6],
1416 static void vl_api_ip_details_t_handler_json (vl_api_ip_details_t * mp)
1418 vat_main_t * vam = &vat_main;
1420 if (VAT_JSON_ARRAY != vam->json_tree.type) {
1421 ASSERT(VAT_JSON_NONE == vam->json_tree.type);
1422 vat_json_init_array(&vam->json_tree);
1424 vat_json_array_add_uint(&vam->json_tree, clib_net_to_host_u32(mp->sw_if_index));
1427 static void vl_api_map_domain_details_t_handler_json
1428 (vl_api_map_domain_details_t * mp)
1430 vat_json_node_t * node = NULL;
1431 vat_main_t * vam = &vat_main;
1432 struct in6_addr ip6;
1435 if (VAT_JSON_ARRAY != vam->json_tree.type) {
1436 ASSERT(VAT_JSON_NONE == vam->json_tree.type);
1437 vat_json_init_array(&vam->json_tree);
1440 node = vat_json_array_add(&vam->json_tree);
1441 vat_json_init_object(node);
1443 vat_json_object_add_uint(node, "domain_index", clib_net_to_host_u32(mp->domain_index));
1444 memcpy(&ip6, mp->ip6_prefix, sizeof(ip6));
1445 vat_json_object_add_ip6(node, "ip6_prefix", ip6);
1446 memcpy(&ip4, mp->ip4_prefix, sizeof(ip4));
1447 vat_json_object_add_ip4(node, "ip4_prefix", ip4);
1448 memcpy(&ip6, mp->ip6_src, sizeof(ip6));
1449 vat_json_object_add_ip6(node, "ip6_src", ip6);
1450 vat_json_object_add_int(node, "ip6_prefix_len", mp->ip6_prefix_len);
1451 vat_json_object_add_int(node, "ip4_prefix_len", mp->ip4_prefix_len);
1452 vat_json_object_add_int(node, "ip6_src_len", mp->ip6_src_len);
1453 vat_json_object_add_int(node, "ea_bits_len", mp->ea_bits_len);
1454 vat_json_object_add_int(node, "psid_offset", mp->psid_offset);
1455 vat_json_object_add_int(node, "psid_length", mp->psid_length);
1456 vat_json_object_add_uint(node, "flags", mp->flags);
1457 vat_json_object_add_uint(node, "mtu", clib_net_to_host_u16(mp->mtu));
1458 vat_json_object_add_int(node, "is_translation", mp->is_translation);
1461 static void vl_api_map_domain_details_t_handler
1462 (vl_api_map_domain_details_t * mp)
1464 vat_main_t * vam = &vat_main;
1466 if (mp->is_translation) {
1467 fformat(vam->ofp, "* %U/%d (ipv4-prefix) %U/%d (ipv6-prefix) %U/%d (ip6-src) index: %u\n",
1468 format_ip4_address, mp->ip4_prefix, mp->ip4_prefix_len,
1469 format_ip6_address, mp->ip6_prefix, mp->ip6_prefix_len,
1470 format_ip6_address, mp->ip6_src, mp->ip6_src_len, clib_net_to_host_u32(mp->domain_index));
1472 fformat(vam->ofp, "* %U/%d (ipv4-prefix) %U/%d (ipv6-prefix) %U (ip6-src) index: %u\n",
1473 format_ip4_address, mp->ip4_prefix, mp->ip4_prefix_len,
1474 format_ip6_address, mp->ip6_prefix, mp->ip6_prefix_len,
1475 format_ip6_address, mp->ip6_src, clib_net_to_host_u32(mp->domain_index));
1477 fformat(vam->ofp, " ea-len %d psid-offset %d psid-len %d mtu %d %s\n",
1478 mp->ea_bits_len, mp->psid_offset, mp->psid_length, mp->mtu, mp->is_translation? "map-t":"");
1481 static void vl_api_map_rule_details_t_handler_json
1482 (vl_api_map_rule_details_t * mp)
1484 struct in6_addr ip6;
1485 vat_json_node_t * node = NULL;
1486 vat_main_t * vam = &vat_main;
1488 if (VAT_JSON_ARRAY != vam->json_tree.type) {
1489 ASSERT(VAT_JSON_NONE == vam->json_tree.type);
1490 vat_json_init_array(&vam->json_tree);
1493 node = vat_json_array_add(&vam->json_tree);
1494 vat_json_init_object(node);
1496 vat_json_object_add_uint(node, "psid", clib_net_to_host_u16(mp->psid));
1497 memcpy(&ip6, mp->ip6_dst, sizeof(ip6));
1498 vat_json_object_add_ip6(node, "ip6_dst", ip6);
1501 static void vl_api_map_rule_details_t_handler
1502 (vl_api_map_rule_details_t * mp)
1504 vat_main_t * vam = &vat_main;
1505 fformat(vam->ofp, " %d (psid) %U (ip6-dst)\n", clib_net_to_host_u16(mp->psid),
1506 format_ip6_address, mp->ip6_dst);
1509 static void vl_api_dhcp_compl_event_t_handler
1510 (vl_api_dhcp_compl_event_t * mp)
1512 vat_main_t * vam = &vat_main;
1513 errmsg ("DHCP compl event: pid %d %s hostname %s host_addr %U "
1514 "router_addr %U host_mac %U\n",
1515 mp->pid, mp->is_ipv6 ? "ipv6":"ipv4", mp->hostname,
1516 format_ip4_address, &mp->host_address,
1517 format_ip4_address, &mp->router_address,
1518 format_ethernet_address, mp->host_mac);
1521 static void vl_api_dhcp_compl_event_t_handler_json
1522 (vl_api_dhcp_compl_event_t * mp)
1524 /* JSON output not supported */
1527 static void set_simple_interface_counter (u8 vnet_counter_type, u32 sw_if_index,
1530 vat_main_t * vam = &vat_main;
1531 static u64 default_counter = 0;
1533 vec_validate_init_empty(vam->simple_interface_counters, vnet_counter_type, NULL);
1534 vec_validate_init_empty(vam->simple_interface_counters[vnet_counter_type],
1535 sw_if_index, default_counter);
1536 vam->simple_interface_counters[vnet_counter_type][sw_if_index] = counter;
1539 static void set_combined_interface_counter (u8 vnet_counter_type, u32 sw_if_index,
1540 interface_counter_t counter)
1542 vat_main_t * vam = &vat_main;
1543 static interface_counter_t default_counter = {0, };
1545 vec_validate_init_empty(vam->combined_interface_counters, vnet_counter_type, NULL);
1546 vec_validate_init_empty(vam->combined_interface_counters[vnet_counter_type],
1547 sw_if_index, default_counter);
1548 vam->combined_interface_counters[vnet_counter_type][sw_if_index] = counter;
1551 static void vl_api_vnet_interface_counters_t_handler
1552 (vl_api_vnet_interface_counters_t *mp)
1557 static void vl_api_vnet_interface_counters_t_handler_json
1558 (vl_api_vnet_interface_counters_t *mp)
1560 interface_counter_t counter;
1565 u32 first_sw_if_index;
1568 count = ntohl(mp->count);
1569 first_sw_if_index = ntohl(mp->first_sw_if_index);
1571 if (!mp->is_combined) {
1572 v_packets = (u64*)&mp->data;
1573 for (i = 0; i < count; i++) {
1574 packets = clib_net_to_host_u64(clib_mem_unaligned(v_packets, u64));
1575 set_simple_interface_counter(mp->vnet_counter_type,
1576 first_sw_if_index + i, packets);
1580 v = (vlib_counter_t*)&mp->data;
1581 for (i = 0; i < count; i++) {
1582 counter.packets = clib_net_to_host_u64(
1583 clib_mem_unaligned(&v->packets, u64));
1584 counter.bytes = clib_net_to_host_u64(
1585 clib_mem_unaligned(&v->bytes, u64));
1586 set_combined_interface_counter(mp->vnet_counter_type,
1587 first_sw_if_index + i, counter);
1593 static u32 ip4_fib_counters_get_vrf_index_by_vrf_id (u32 vrf_id)
1595 vat_main_t * vam = &vat_main;
1598 for (i = 0; i < vec_len(vam->ip4_fib_counters_vrf_id_by_index); i++) {
1599 if (vam->ip4_fib_counters_vrf_id_by_index[i] == vrf_id) {
1606 static u32 ip6_fib_counters_get_vrf_index_by_vrf_id (u32 vrf_id)
1608 vat_main_t * vam = &vat_main;
1611 for (i = 0; i < vec_len(vam->ip6_fib_counters_vrf_id_by_index); i++) {
1612 if (vam->ip6_fib_counters_vrf_id_by_index[i] == vrf_id) {
1619 static void vl_api_vnet_ip4_fib_counters_t_handler
1620 (vl_api_vnet_ip4_fib_counters_t *mp)
1625 static void vl_api_vnet_ip4_fib_counters_t_handler_json
1626 (vl_api_vnet_ip4_fib_counters_t *mp)
1628 vat_main_t * vam = &vat_main;
1629 vl_api_ip4_fib_counter_t *v;
1630 ip4_fib_counter_t *counter;
1637 vrf_id = ntohl(mp->vrf_id);
1638 vrf_index = ip4_fib_counters_get_vrf_index_by_vrf_id(vrf_id);
1639 if (~0 == vrf_index) {
1640 vrf_index = vec_len(vam->ip4_fib_counters_vrf_id_by_index);
1641 vec_validate(vam->ip4_fib_counters_vrf_id_by_index, vrf_index);
1642 vam->ip4_fib_counters_vrf_id_by_index[vrf_index] = vrf_id;
1643 vec_validate(vam->ip4_fib_counters, vrf_index);
1644 vam->ip4_fib_counters[vrf_index] = NULL;
1647 vec_free(vam->ip4_fib_counters[vrf_index]);
1648 v = (vl_api_ip4_fib_counter_t*)&mp->c;
1649 count = ntohl(mp->count);
1650 for (i = 0; i < count; i++) {
1651 vec_validate(vam->ip4_fib_counters[vrf_index], i);
1652 counter = &vam->ip4_fib_counters[vrf_index][i];
1653 memcpy(&ip4, &v->address, sizeof(ip4));
1654 counter->address = ip4;
1655 counter->address_length = v->address_length;
1656 counter->packets = clib_net_to_host_u64(v->packets);
1657 counter->bytes = clib_net_to_host_u64(v->bytes);
1662 static void vl_api_vnet_ip6_fib_counters_t_handler
1663 (vl_api_vnet_ip6_fib_counters_t *mp)
1668 static void vl_api_vnet_ip6_fib_counters_t_handler_json
1669 (vl_api_vnet_ip6_fib_counters_t *mp)
1671 vat_main_t * vam = &vat_main;
1672 vl_api_ip6_fib_counter_t *v;
1673 ip6_fib_counter_t *counter;
1674 struct in6_addr ip6;
1680 vrf_id = ntohl(mp->vrf_id);
1681 vrf_index = ip6_fib_counters_get_vrf_index_by_vrf_id(vrf_id);
1682 if (~0 == vrf_index) {
1683 vrf_index = vec_len(vam->ip6_fib_counters_vrf_id_by_index);
1684 vec_validate(vam->ip6_fib_counters_vrf_id_by_index, vrf_index);
1685 vam->ip6_fib_counters_vrf_id_by_index[vrf_index] = vrf_id;
1686 vec_validate(vam->ip6_fib_counters, vrf_index);
1687 vam->ip6_fib_counters[vrf_index] = NULL;
1690 vec_free(vam->ip6_fib_counters[vrf_index]);
1691 v = (vl_api_ip6_fib_counter_t*)&mp->c;
1692 count = ntohl(mp->count);
1693 for (i = 0; i < count; i++) {
1694 vec_validate(vam->ip6_fib_counters[vrf_index], i);
1695 counter = &vam->ip6_fib_counters[vrf_index][i];
1696 memcpy(&ip6, &v->address, sizeof(ip6));
1697 counter->address = ip6;
1698 counter->address_length = v->address_length;
1699 counter->packets = clib_net_to_host_u64(v->packets);
1700 counter->bytes = clib_net_to_host_u64(v->bytes);
1705 static void vl_api_get_first_msg_id_reply_t_handler
1706 (vl_api_get_first_msg_id_reply_t * mp)
1708 vat_main_t * vam = &vat_main;
1709 i32 retval = ntohl(mp->retval);
1711 if (vam->async_mode) {
1712 vam->async_errors += (retval < 0);
1714 vam->retval = retval;
1715 vam->result_ready = 1;
1718 errmsg ("first message id %d\n", ntohs(mp->first_msg_id));
1722 static void vl_api_get_first_msg_id_reply_t_handler_json
1723 (vl_api_get_first_msg_id_reply_t * mp)
1725 vat_main_t * vam = &vat_main;
1726 vat_json_node_t node;
1728 vat_json_init_object(&node);
1729 vat_json_object_add_int(&node, "retval", ntohl(mp->retval));
1730 vat_json_object_add_uint(&node, "first_msg_id",
1731 (uint) ntohs(mp->first_msg_id));
1733 vat_json_print(vam->ofp, &node);
1734 vat_json_free(&node);
1736 vam->retval = ntohl(mp->retval);
1737 vam->result_ready = 1;
1740 static void vl_api_get_node_graph_reply_t_handler
1741 (vl_api_get_node_graph_reply_t * mp)
1743 vat_main_t * vam = &vat_main;
1744 api_main_t * am = &api_main;
1745 i32 retval = ntohl(mp->retval);
1746 u8 * pvt_copy, * reply;
1751 if (vam->async_mode) {
1752 vam->async_errors += (retval < 0);
1754 vam->retval = retval;
1755 vam->result_ready = 1;
1758 /* "Should never happen..." */
1762 reply = (u8 *)(mp->reply_in_shmem);
1763 pvt_copy = vec_dup (reply);
1765 /* Toss the shared-memory original... */
1766 pthread_mutex_lock (&am->vlib_rp->mutex);
1767 oldheap = svm_push_data_heap (am->vlib_rp);
1771 svm_pop_heap (oldheap);
1772 pthread_mutex_unlock (&am->vlib_rp->mutex);
1774 if (vam->graph_nodes) {
1775 hash_free (vam->graph_node_index_by_name);
1777 for (i = 0; i < vec_len (vam->graph_nodes); i++) {
1778 node = vam->graph_nodes[i];
1779 vec_free (node->name);
1780 vec_free (node->next_nodes);
1783 vec_free(vam->graph_nodes);
1786 vam->graph_node_index_by_name = hash_create_string (0, sizeof(uword));
1787 vam->graph_nodes = vlib_node_unserialize (pvt_copy);
1788 vec_free (pvt_copy);
1790 for (i = 0; i < vec_len (vam->graph_nodes); i++) {
1791 node = vam->graph_nodes[i];
1792 hash_set_mem (vam->graph_node_index_by_name, node->name, i);
1796 static void vl_api_get_node_graph_reply_t_handler_json
1797 (vl_api_get_node_graph_reply_t * mp)
1799 vat_main_t * vam = &vat_main;
1800 api_main_t * am = &api_main;
1802 vat_json_node_t node;
1805 /* $$$$ make this real? */
1806 vat_json_init_object(&node);
1807 vat_json_object_add_int(&node, "retval", ntohl(mp->retval));
1808 vat_json_object_add_uint(&node, "reply_in_shmem", mp->reply_in_shmem);
1810 reply = (u8 *)(mp->reply_in_shmem);
1812 /* Toss the shared-memory original... */
1813 pthread_mutex_lock (&am->vlib_rp->mutex);
1814 oldheap = svm_push_data_heap (am->vlib_rp);
1818 svm_pop_heap (oldheap);
1819 pthread_mutex_unlock (&am->vlib_rp->mutex);
1821 vat_json_print(vam->ofp, &node);
1822 vat_json_free(&node);
1824 vam->retval = ntohl(mp->retval);
1825 vam->result_ready = 1;
1828 #define vl_api_vnet_ip4_fib_counters_t_endian vl_noop_handler
1829 #define vl_api_vnet_ip4_fib_counters_t_print vl_noop_handler
1830 #define vl_api_vnet_ip6_fib_counters_t_endian vl_noop_handler
1831 #define vl_api_vnet_ip6_fib_counters_t_print vl_noop_handler
1834 * Generate boilerplate reply handlers, which
1835 * dig the return value out of the xxx_reply_t API message,
1836 * stick it into vam->retval, and set vam->result_ready
1838 * Could also do this by pointing N message decode slots at
1839 * a single function, but that could break in subtle ways.
1842 #define foreach_standard_reply_retval_handler \
1843 _(sw_interface_set_flags_reply) \
1844 _(sw_interface_add_del_address_reply) \
1845 _(sw_interface_set_table_reply) \
1846 _(sw_interface_set_vpath_reply) \
1847 _(sw_interface_set_l2_bridge_reply) \
1848 _(bridge_domain_add_del_reply) \
1849 _(sw_interface_set_l2_xconnect_reply) \
1850 _(l2fib_add_del_reply) \
1851 _(ip_add_del_route_reply) \
1852 _(proxy_arp_add_del_reply) \
1853 _(proxy_arp_intfc_enable_disable_reply) \
1854 _(mpls_add_del_encap_reply) \
1855 _(mpls_add_del_decap_reply) \
1856 _(mpls_ethernet_add_del_tunnel_2_reply) \
1857 _(sw_interface_set_unnumbered_reply) \
1858 _(ip_neighbor_add_del_reply) \
1859 _(reset_vrf_reply) \
1860 _(oam_add_del_reply) \
1861 _(reset_fib_reply) \
1862 _(dhcp_proxy_config_reply) \
1863 _(dhcp_proxy_config_2_reply) \
1864 _(dhcp_proxy_set_vss_reply) \
1865 _(dhcp_client_config_reply) \
1866 _(set_ip_flow_hash_reply) \
1867 _(sw_interface_ip6_enable_disable_reply) \
1868 _(sw_interface_ip6_set_link_local_address_reply) \
1869 _(sw_interface_ip6nd_ra_prefix_reply) \
1870 _(sw_interface_ip6nd_ra_config_reply) \
1871 _(set_arp_neighbor_limit_reply) \
1872 _(l2_patch_add_del_reply) \
1873 _(sr_tunnel_add_del_reply) \
1874 _(classify_add_del_session_reply) \
1875 _(classify_set_interface_ip_table_reply) \
1876 _(classify_set_interface_l2_tables_reply) \
1877 _(l2tpv3_set_tunnel_cookies_reply) \
1878 _(l2tpv3_interface_enable_disable_reply) \
1879 _(l2tpv3_set_lookup_key_reply) \
1880 _(l2_fib_clear_table_reply) \
1881 _(l2_interface_efp_filter_reply) \
1882 _(l2_interface_vlan_tag_rewrite_reply) \
1883 _(modify_vhost_user_if_reply) \
1884 _(delete_vhost_user_if_reply) \
1885 _(want_ip4_arp_events_reply) \
1886 _(input_acl_set_interface_reply) \
1887 _(ipsec_spd_add_del_reply) \
1888 _(ipsec_interface_add_del_spd_reply) \
1889 _(ipsec_spd_add_del_entry_reply) \
1890 _(ipsec_sad_add_del_entry_reply) \
1891 _(ipsec_sa_set_key_reply) \
1892 _(delete_loopback_reply) \
1893 _(bd_ip_mac_add_del_reply) \
1894 _(map_del_domain_reply) \
1895 _(map_add_del_rule_reply) \
1896 _(want_interface_events_reply) \
1897 _(want_stats_reply) \
1898 _(cop_interface_enable_disable_reply) \
1899 _(cop_whitelist_enable_disable_reply)
1902 static void vl_api_##n##_t_handler \
1903 (vl_api_##n##_t * mp) \
1905 vat_main_t * vam = &vat_main; \
1906 i32 retval = ntohl(mp->retval); \
1907 if (vam->async_mode) { \
1908 vam->async_errors += (retval < 0); \
1910 vam->retval = retval; \
1911 vam->result_ready = 1; \
1914 foreach_standard_reply_retval_handler;
1918 static void vl_api_##n##_t_handler_json \
1919 (vl_api_##n##_t * mp) \
1921 vat_main_t * vam = &vat_main; \
1922 vat_json_node_t node; \
1923 vat_json_init_object(&node); \
1924 vat_json_object_add_int(&node, "retval", ntohl(mp->retval)); \
1925 vat_json_print(vam->ofp, &node); \
1926 vam->retval = ntohl(mp->retval); \
1927 vam->result_ready = 1; \
1929 foreach_standard_reply_retval_handler;
1933 * Table of message reply handlers, must include boilerplate handlers
1937 #define foreach_vpe_api_reply_msg \
1938 _(CREATE_LOOPBACK_REPLY, create_loopback_reply) \
1939 _(SW_INTERFACE_DETAILS, sw_interface_details) \
1940 _(SW_INTERFACE_SET_FLAGS, sw_interface_set_flags) \
1941 _(SW_INTERFACE_SET_FLAGS_REPLY, sw_interface_set_flags_reply) \
1942 _(CONTROL_PING_REPLY, control_ping_reply) \
1943 _(CLI_REPLY, cli_reply) \
1944 _(SW_INTERFACE_ADD_DEL_ADDRESS_REPLY, \
1945 sw_interface_add_del_address_reply) \
1946 _(SW_INTERFACE_SET_TABLE_REPLY, sw_interface_set_table_reply) \
1947 _(SW_INTERFACE_SET_VPATH_REPLY, sw_interface_set_vpath_reply) \
1948 _(SW_INTERFACE_SET_L2_XCONNECT_REPLY, \
1949 sw_interface_set_l2_xconnect_reply) \
1950 _(SW_INTERFACE_SET_L2_BRIDGE_REPLY, \
1951 sw_interface_set_l2_bridge_reply) \
1952 _(BRIDGE_DOMAIN_ADD_DEL_REPLY, bridge_domain_add_del_reply) \
1953 _(BRIDGE_DOMAIN_DETAILS, bridge_domain_details) \
1954 _(BRIDGE_DOMAIN_SW_IF_DETAILS, bridge_domain_sw_if_details) \
1955 _(L2FIB_ADD_DEL_REPLY, l2fib_add_del_reply) \
1956 _(L2_FLAGS_REPLY, l2_flags_reply) \
1957 _(BRIDGE_FLAGS_REPLY, bridge_flags_reply) \
1958 _(TAP_CONNECT_REPLY, tap_connect_reply) \
1959 _(TAP_MODIFY_REPLY, tap_modify_reply) \
1960 _(TAP_DELETE_REPLY, tap_delete_reply) \
1961 _(SW_INTERFACE_TAP_DETAILS, sw_interface_tap_details) \
1962 _(IP_ADD_DEL_ROUTE_REPLY, ip_add_del_route_reply) \
1963 _(PROXY_ARP_ADD_DEL_REPLY, proxy_arp_add_del_reply) \
1964 _(PROXY_ARP_INTFC_ENABLE_DISABLE_REPLY, \
1965 proxy_arp_intfc_enable_disable_reply) \
1966 _(MPLS_ADD_DEL_ENCAP_REPLY, mpls_add_del_encap_reply) \
1967 _(MPLS_ADD_DEL_DECAP_REPLY, mpls_add_del_decap_reply) \
1968 _(MPLS_GRE_ADD_DEL_TUNNEL_REPLY, mpls_gre_add_del_tunnel_reply) \
1969 _(MPLS_ETHERNET_ADD_DEL_TUNNEL_REPLY, \
1970 mpls_ethernet_add_del_tunnel_reply) \
1971 _(MPLS_ETHERNET_ADD_DEL_TUNNEL_2_REPLY, \
1972 mpls_ethernet_add_del_tunnel_2_reply) \
1973 _(SW_INTERFACE_SET_UNNUMBERED_REPLY, \
1974 sw_interface_set_unnumbered_reply) \
1975 _(IP_NEIGHBOR_ADD_DEL_REPLY, ip_neighbor_add_del_reply) \
1976 _(RESET_VRF_REPLY, reset_vrf_reply) \
1977 _(CREATE_VLAN_SUBIF_REPLY, create_vlan_subif_reply) \
1978 _(CREATE_SUBIF_REPLY, create_subif_reply) \
1979 _(OAM_ADD_DEL_REPLY, oam_add_del_reply) \
1980 _(RESET_FIB_REPLY, reset_fib_reply) \
1981 _(DHCP_PROXY_CONFIG_REPLY, dhcp_proxy_config_reply) \
1982 _(DHCP_PROXY_CONFIG_2_REPLY, dhcp_proxy_config_2_reply) \
1983 _(DHCP_PROXY_SET_VSS_REPLY, dhcp_proxy_set_vss_reply) \
1984 _(DHCP_CLIENT_CONFIG_REPLY, dhcp_client_config_reply) \
1985 _(SET_IP_FLOW_HASH_REPLY, set_ip_flow_hash_reply) \
1986 _(SW_INTERFACE_IP6_ENABLE_DISABLE_REPLY, \
1987 sw_interface_ip6_enable_disable_reply) \
1988 _(SW_INTERFACE_IP6_SET_LINK_LOCAL_ADDRESS_REPLY, \
1989 sw_interface_ip6_set_link_local_address_reply) \
1990 _(SW_INTERFACE_IP6ND_RA_PREFIX_REPLY, \
1991 sw_interface_ip6nd_ra_prefix_reply) \
1992 _(SW_INTERFACE_IP6ND_RA_CONFIG_REPLY, \
1993 sw_interface_ip6nd_ra_config_reply) \
1994 _(SET_ARP_NEIGHBOR_LIMIT_REPLY, set_arp_neighbor_limit_reply) \
1995 _(L2_PATCH_ADD_DEL_REPLY, l2_patch_add_del_reply) \
1996 _(SR_TUNNEL_ADD_DEL_REPLY, sr_tunnel_add_del_reply) \
1997 _(CLASSIFY_ADD_DEL_TABLE_REPLY, classify_add_del_table_reply) \
1998 _(CLASSIFY_ADD_DEL_SESSION_REPLY, classify_add_del_session_reply) \
1999 _(CLASSIFY_SET_INTERFACE_IP_TABLE_REPLY, \
2000 classify_set_interface_ip_table_reply) \
2001 _(CLASSIFY_SET_INTERFACE_L2_TABLES_REPLY, \
2002 classify_set_interface_l2_tables_reply) \
2003 _(GET_NODE_INDEX_REPLY, get_node_index_reply) \
2004 _(ADD_NODE_NEXT_REPLY, add_node_next_reply) \
2005 _(L2TPV3_CREATE_TUNNEL_REPLY, l2tpv3_create_tunnel_reply) \
2006 _(L2TPV3_SET_TUNNEL_COOKIES_REPLY, l2tpv3_set_tunnel_cookies_reply) \
2007 _(L2TPV3_INTERFACE_ENABLE_DISABLE_REPLY, \
2008 l2tpv3_interface_enable_disable_reply) \
2009 _(L2TPV3_SET_LOOKUP_KEY_REPLY, l2tpv3_set_lookup_key_reply) \
2010 _(SW_IF_L2TPV3_TUNNEL_DETAILS, sw_if_l2tpv3_tunnel_details) \
2011 _(VXLAN_ADD_DEL_TUNNEL_REPLY, vxlan_add_del_tunnel_reply) \
2012 _(VXLAN_TUNNEL_DETAILS, vxlan_tunnel_details) \
2013 _(L2_FIB_CLEAR_TABLE_REPLY, l2_fib_clear_table_reply) \
2014 _(L2_INTERFACE_EFP_FILTER_REPLY, l2_interface_efp_filter_reply) \
2015 _(L2_INTERFACE_VLAN_TAG_REWRITE_REPLY, l2_interface_vlan_tag_rewrite_reply) \
2016 _(SW_INTERFACE_VHOST_USER_DETAILS, sw_interface_vhost_user_details) \
2017 _(CREATE_VHOST_USER_IF_REPLY, create_vhost_user_if_reply) \
2018 _(MODIFY_VHOST_USER_IF_REPLY, modify_vhost_user_if_reply) \
2019 _(DELETE_VHOST_USER_IF_REPLY, delete_vhost_user_if_reply) \
2020 _(SHOW_VERSION_REPLY, show_version_reply) \
2021 _(NSH_GRE_ADD_DEL_TUNNEL_REPLY, nsh_gre_add_del_tunnel_reply) \
2022 _(L2_FIB_TABLE_ENTRY, l2_fib_table_entry) \
2023 _(NSH_VXLAN_GPE_ADD_DEL_TUNNEL_REPLY, nsh_vxlan_gpe_add_del_tunnel_reply) \
2024 _(LISP_GPE_ADD_DEL_TUNNEL_REPLY, lisp_gpe_add_del_tunnel_reply) \
2025 _(INTERFACE_NAME_RENUMBER_REPLY, interface_name_renumber_reply) \
2026 _(WANT_IP4_ARP_EVENTS_REPLY, want_ip4_arp_events_reply) \
2027 _(IP4_ARP_EVENT, ip4_arp_event) \
2028 _(INPUT_ACL_SET_INTERFACE_REPLY, input_acl_set_interface_reply) \
2029 _(IP_ADDRESS_DETAILS, ip_address_details) \
2030 _(IP_DETAILS, ip_details) \
2031 _(IPSEC_SPD_ADD_DEL_REPLY, ipsec_spd_add_del_reply) \
2032 _(IPSEC_INTERFACE_ADD_DEL_SPD_REPLY, ipsec_interface_add_del_spd_reply) \
2033 _(IPSEC_SPD_ADD_DEL_ENTRY_REPLY, ipsec_spd_add_del_entry_reply) \
2034 _(IPSEC_SAD_ADD_DEL_ENTRY_REPLY, ipsec_sad_add_del_entry_reply) \
2035 _(IPSEC_SA_SET_KEY_REPLY, ipsec_sa_set_key_reply) \
2036 _(DELETE_LOOPBACK_REPLY, delete_loopback_reply) \
2037 _(BD_IP_MAC_ADD_DEL_REPLY, bd_ip_mac_add_del_reply) \
2038 _(DHCP_COMPL_EVENT, dhcp_compl_event) \
2039 _(VNET_INTERFACE_COUNTERS, vnet_interface_counters) \
2040 _(VNET_IP4_FIB_COUNTERS, vnet_ip4_fib_counters) \
2041 _(VNET_IP6_FIB_COUNTERS, vnet_ip6_fib_counters) \
2042 _(MAP_ADD_DOMAIN_REPLY, map_add_domain_reply) \
2043 _(MAP_DEL_DOMAIN_REPLY, map_del_domain_reply) \
2044 _(MAP_ADD_DEL_RULE_REPLY, map_add_del_rule_reply) \
2045 _(MAP_DOMAIN_DETAILS, map_domain_details) \
2046 _(MAP_RULE_DETAILS, map_rule_details) \
2047 _(WANT_INTERFACE_EVENTS_REPLY, want_interface_events_reply) \
2048 _(WANT_STATS_REPLY, want_stats_reply) \
2049 _(GET_FIRST_MSG_ID_REPLY, get_first_msg_id_reply) \
2050 _(COP_INTERFACE_ENABLE_DISABLE_REPLY, cop_interface_enable_disable_reply) \
2051 _(COP_WHITELIST_ENABLE_DISABLE_REPLY, cop_whitelist_enable_disable_reply) \
2052 _(GET_NODE_GRAPH_REPLY, get_node_graph_reply)
2054 /* M: construct, but don't yet send a message */
2058 vam->result_ready = 0; \
2059 mp = vl_msg_api_alloc(sizeof(*mp)); \
2060 memset (mp, 0, sizeof (*mp)); \
2061 mp->_vl_msg_id = ntohs (VL_API_##T); \
2062 mp->client_index = vam->my_client_index; \
2067 vam->result_ready = 0; \
2068 mp = vl_msg_api_alloc(sizeof(*mp)+(n)); \
2069 memset (mp, 0, sizeof (*mp)); \
2070 mp->_vl_msg_id = ntohs (VL_API_##T); \
2071 mp->client_index = vam->my_client_index; \
2075 /* S: send a message */
2076 #define S (vl_msg_api_send_shmem (vam->vl_input_queue, (u8 *)&mp))
2078 /* W: wait for results, with timeout */
2081 timeout = vat_time_now (vam) + 1.0; \
2083 while (vat_time_now (vam) < timeout) { \
2084 if (vam->result_ready == 1) { \
2085 return (vam->retval); \
2097 #define STR_VTR_OP_CASE(op) \
2098 case L2_VTR_ ## op: \
2101 static const char *str_vtr_op(u32 vtr_op)
2104 STR_VTR_OP_CASE(DISABLED);
2105 STR_VTR_OP_CASE(PUSH_1);
2106 STR_VTR_OP_CASE(PUSH_2);
2107 STR_VTR_OP_CASE(POP_1);
2108 STR_VTR_OP_CASE(POP_2);
2109 STR_VTR_OP_CASE(TRANSLATE_1_1);
2110 STR_VTR_OP_CASE(TRANSLATE_1_2);
2111 STR_VTR_OP_CASE(TRANSLATE_2_1);
2112 STR_VTR_OP_CASE(TRANSLATE_2_2);
2118 static int dump_sub_interface_table (vat_main_t * vam)
2120 const sw_interface_subif_t * sub = NULL;
2122 if (vam->json_output) {
2123 clib_warning ("JSON output supported only for VPE API calls and dump_stats_table");
2128 "%-30s%-12s%-11s%-7s%-5s%-9s%-9s%-6s%-8s%-10s%-10s\n",
2129 "Interface", "sw_if_index",
2130 "sub id", "dot1ad", "tags", "outer id",
2131 "inner id", "exact", "default",
2132 "outer any", "inner any");
2134 vec_foreach (sub, vam->sw_if_subif_table) {
2136 "%-30s%-12d%-11d%-7s%-5d%-9d%-9d%-6d%-8d%-10d%-10d\n",
2137 sub->interface_name,
2139 sub->sub_id, sub->sub_dot1ad ? "dot1ad" : "dot1q",
2140 sub->sub_number_of_tags, sub->sub_outer_vlan_id,
2141 sub->sub_inner_vlan_id, sub->sub_exact_match, sub->sub_default,
2142 sub->sub_outer_vlan_id_any, sub->sub_inner_vlan_id_any);
2143 if (sub->vtr_op != L2_VTR_DISABLED) {
2145 " vlan-tag-rewrite - op: %-14s [ dot1q: %d "
2146 "tag1: %d tag2: %d ]\n",
2147 str_vtr_op(sub->vtr_op), sub->vtr_push_dot1q,
2148 sub->vtr_tag1, sub->vtr_tag2);
2155 static int name_sort_cmp (void * a1, void * a2)
2157 name_sort_t * n1 = a1;
2158 name_sort_t * n2 = a2;
2160 return strcmp ((char *)n1->name, (char *)n2->name);
2163 static int dump_interface_table (vat_main_t * vam)
2166 name_sort_t * nses = 0, * ns;
2168 if (vam->json_output) {
2169 clib_warning ("JSON output supported only for VPE API calls and dump_stats_table");
2173 hash_foreach_pair (p, vam->sw_if_index_by_interface_name,
2175 vec_add2 (nses, ns, 1);
2176 ns->name = (u8 *)(p->key);
2177 ns->value = (u32) p->value[0];
2180 vec_sort_with_function (nses, name_sort_cmp);
2182 fformat (vam->ofp, "%-25s%-15s\n", "Interface", "sw_if_index");
2183 vec_foreach (ns, nses) {
2184 fformat (vam->ofp, "%-25s%-15d\n", ns->name, ns->value);
2190 static int dump_ip_table (vat_main_t * vam, int is_ipv6)
2192 const ip_details_t * det = NULL;
2193 const ip_address_details_t * address = NULL;
2200 if (0 == vam->ip_details_by_sw_if_index) {
2204 vec_foreach (det, vam->ip_details_by_sw_if_index[is_ipv6]) {
2206 if (!det->present) {
2214 "Address", "Prefix length");
2218 vec_foreach (address, det->addr) {
2221 is_ipv6 ? format_ip6_address : format_ip4_address,
2223 address->prefix_length);
2230 static int dump_ipv4_table (vat_main_t * vam)
2232 if (vam->json_output) {
2233 clib_warning ("JSON output supported only for VPE API calls and dump_stats_table");
2237 return dump_ip_table (vam, 0);
2240 static int dump_ipv6_table (vat_main_t * vam)
2242 if (vam->json_output) {
2243 clib_warning ("JSON output supported only for VPE API calls and dump_stats_table");
2247 return dump_ip_table (vam, 1);
2250 static char* counter_type_to_str (u8 counter_type, u8 is_combined)
2253 switch(counter_type) {
2254 case VNET_INTERFACE_COUNTER_DROP:
2256 case VNET_INTERFACE_COUNTER_PUNT:
2258 case VNET_INTERFACE_COUNTER_IP4:
2260 case VNET_INTERFACE_COUNTER_IP6:
2262 case VNET_INTERFACE_COUNTER_RX_NO_BUF:
2264 case VNET_INTERFACE_COUNTER_RX_MISS:
2266 case VNET_INTERFACE_COUNTER_RX_ERROR:
2268 case VNET_INTERFACE_COUNTER_TX_ERROR:
2271 return "INVALID-COUNTER-TYPE";
2274 switch(counter_type) {
2275 case VNET_INTERFACE_COUNTER_RX:
2277 case VNET_INTERFACE_COUNTER_TX:
2280 return "INVALID-COUNTER-TYPE";
2285 static int dump_stats_table (vat_main_t * vam)
2287 vat_json_node_t node;
2288 vat_json_node_t *msg_array;
2289 vat_json_node_t *msg;
2290 vat_json_node_t *counter_array;
2291 vat_json_node_t *counter;
2292 interface_counter_t c;
2294 ip4_fib_counter_t *c4;
2295 ip6_fib_counter_t *c6;
2298 if (!vam->json_output) {
2299 clib_warning ("dump_stats_table supported only in JSON format");
2303 vat_json_init_object(&node);
2305 /* interface counters */
2306 msg_array = vat_json_object_add(&node, "interface_counters");
2307 vat_json_init_array(msg_array);
2308 for (i = 0; i < vec_len(vam->simple_interface_counters); i++) {
2309 msg = vat_json_array_add(msg_array);
2310 vat_json_init_object(msg);
2311 vat_json_object_add_string_copy(msg, "vnet_counter_type",
2312 (u8*)counter_type_to_str(i, 0));
2313 vat_json_object_add_int(msg, "is_combined", 0);
2314 counter_array = vat_json_object_add(msg, "data");
2315 vat_json_init_array(counter_array);
2316 for (j = 0; j < vec_len(vam->simple_interface_counters[i]); j++) {
2317 packets = vam->simple_interface_counters[i][j];
2318 vat_json_array_add_uint(counter_array, packets);
2321 for (i = 0; i < vec_len(vam->combined_interface_counters); i++) {
2322 msg = vat_json_array_add(msg_array);
2323 vat_json_init_object(msg);
2324 vat_json_object_add_string_copy(msg, "vnet_counter_type",
2325 (u8*)counter_type_to_str(i, 1));
2326 vat_json_object_add_int(msg, "is_combined", 1);
2327 counter_array = vat_json_object_add(msg, "data");
2328 vat_json_init_array(counter_array);
2329 for (j = 0; j < vec_len(vam->combined_interface_counters[i]); j++) {
2330 c = vam->combined_interface_counters[i][j];
2331 counter = vat_json_array_add(counter_array);
2332 vat_json_init_object(counter);
2333 vat_json_object_add_uint(counter, "packets", c.packets);
2334 vat_json_object_add_uint(counter, "bytes", c.bytes);
2338 /* ip4 fib counters */
2339 msg_array = vat_json_object_add(&node, "ip4_fib_counters");
2340 vat_json_init_array(msg_array);
2341 for (i = 0; i < vec_len(vam->ip4_fib_counters); i++) {
2342 msg = vat_json_array_add(msg_array);
2343 vat_json_init_object(msg);
2344 vat_json_object_add_uint(msg, "vrf_id", vam->ip4_fib_counters_vrf_id_by_index[i]);
2345 counter_array = vat_json_object_add(msg, "c");
2346 vat_json_init_array(counter_array);
2347 for (j = 0; j < vec_len(vam->ip4_fib_counters[i]); j++) {
2348 counter = vat_json_array_add(counter_array);
2349 vat_json_init_object(counter);
2350 c4 = &vam->ip4_fib_counters[i][j];
2351 vat_json_object_add_ip4(counter, "address", c4->address);
2352 vat_json_object_add_uint(counter, "address_length", c4->address_length);
2353 vat_json_object_add_uint(counter, "packets", c4->packets);
2354 vat_json_object_add_uint(counter, "bytes", c4->bytes);
2358 /* ip6 fib counters */
2359 msg_array = vat_json_object_add(&node, "ip6_fib_counters");
2360 vat_json_init_array(msg_array);
2361 for (i = 0; i < vec_len(vam->ip6_fib_counters); i++) {
2362 msg = vat_json_array_add(msg_array);
2363 vat_json_init_object(msg);
2364 vat_json_object_add_uint(msg, "vrf_id", vam->ip6_fib_counters_vrf_id_by_index[i]);
2365 counter_array = vat_json_object_add(msg, "c");
2366 vat_json_init_array(counter_array);
2367 for (j = 0; j < vec_len(vam->ip6_fib_counters[i]); j++) {
2368 counter = vat_json_array_add(counter_array);
2369 vat_json_init_object(counter);
2370 c6 = &vam->ip6_fib_counters[i][j];
2371 vat_json_object_add_ip6(counter, "address", c6->address);
2372 vat_json_object_add_uint(counter, "address_length", c6->address_length);
2373 vat_json_object_add_uint(counter, "packets", c6->packets);
2374 vat_json_object_add_uint(counter, "bytes", c6->bytes);
2378 vat_json_print(vam->ofp, &node);
2379 vat_json_free(&node);
2384 int exec (vat_main_t * vam)
2386 api_main_t * am = &api_main;
2387 vl_api_cli_request_t *mp;
2391 unformat_input_t * i = vam->input;
2393 if (vec_len(i->buffer) == 0)
2396 if (vam->exec_mode == 0 && unformat (i, "mode")) {
2400 if (vam->exec_mode == 1 &&
2401 (unformat (i, "exit") || unformat (i, "quit"))) {
2407 M(CLI_REQUEST, cli_request);
2410 * Copy cmd into shared memory.
2411 * In order for the CLI command to work, it
2412 * must be a vector ending in \n, not a C-string ending
2415 pthread_mutex_lock (&am->vlib_rp->mutex);
2416 oldheap = svm_push_data_heap (am->vlib_rp);
2418 vec_validate (cmd, vec_len(vam->input->buffer)-1);
2419 memcpy (cmd, vam->input->buffer, vec_len(vam->input->buffer));
2421 svm_pop_heap (oldheap);
2422 pthread_mutex_unlock (&am->vlib_rp->mutex);
2424 mp->cmd_in_shmem = (u64) cmd;
2426 timeout = vat_time_now (vam) + 10.0;
2428 while (vat_time_now (vam) < timeout) {
2429 if (vam->result_ready == 1) {
2431 fformat (vam->ofp, "%s", vam->shmem_result);
2432 pthread_mutex_lock (&am->vlib_rp->mutex);
2433 oldheap = svm_push_data_heap (am->vlib_rp);
2435 free_me = (u8 *)vam->shmem_result;
2438 svm_pop_heap (oldheap);
2439 pthread_mutex_unlock (&am->vlib_rp->mutex);
2446 static int api_create_loopback (vat_main_t * vam)
2448 unformat_input_t * i = vam->input;
2449 vl_api_create_loopback_t *mp;
2454 memset (mac_address, 0, sizeof (mac_address));
2456 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
2458 if (unformat (i, "mac %U", unformat_ethernet_address, mac_address))
2464 /* Construct the API message */
2465 M(CREATE_LOOPBACK, create_loopback);
2467 memcpy (mp->mac_address, mac_address, sizeof (mac_address));
2472 static int api_delete_loopback (vat_main_t * vam)
2474 unformat_input_t * i = vam->input;
2475 vl_api_delete_loopback_t *mp;
2477 u32 sw_if_index = ~0;
2479 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
2481 if (unformat (i, "sw_if_index %d", &sw_if_index))
2487 if (sw_if_index == ~0)
2489 errmsg ("missing sw_if_index\n");
2493 /* Construct the API message */
2494 M(DELETE_LOOPBACK, delete_loopback);
2495 mp->sw_if_index = ntohl (sw_if_index);
2500 static int api_want_stats (vat_main_t * vam)
2502 unformat_input_t * i = vam->input;
2503 vl_api_want_stats_t * mp;
2507 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
2509 if (unformat (i, "enable"))
2511 else if (unformat (i, "disable"))
2519 errmsg ("missing enable|disable\n");
2523 M(WANT_STATS, want_stats);
2524 mp->enable_disable = enable;
2529 static int api_want_interface_events (vat_main_t * vam)
2531 unformat_input_t * i = vam->input;
2532 vl_api_want_interface_events_t * mp;
2536 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
2538 if (unformat (i, "enable"))
2540 else if (unformat (i, "disable"))
2548 errmsg ("missing enable|disable\n");
2552 M(WANT_INTERFACE_EVENTS, want_interface_events);
2553 mp->enable_disable = enable;
2555 vam->interface_event_display = enable;
2561 /* Note: non-static, called once to set up the initial intfc table */
2562 int api_sw_interface_dump (vat_main_t * vam)
2564 vl_api_sw_interface_dump_t *mp;
2567 name_sort_t * nses = 0, * ns;
2568 sw_interface_subif_t * sub = NULL;
2570 /* Toss the old name table */
2571 hash_foreach_pair (p, vam->sw_if_index_by_interface_name,
2573 vec_add2 (nses, ns, 1);
2574 ns->name = (u8 *)(p->key);
2575 ns->value = (u32) p->value[0];
2578 hash_free (vam->sw_if_index_by_interface_name);
2580 vec_foreach (ns, nses)
2581 vec_free (ns->name);
2585 vec_foreach (sub, vam->sw_if_subif_table) {
2586 vec_free (sub->interface_name);
2588 vec_free (vam->sw_if_subif_table);
2590 /* recreate the interface name hash table */
2591 vam->sw_if_index_by_interface_name
2592 = hash_create_string (0, sizeof(uword));
2594 /* Get list of ethernets */
2595 M(SW_INTERFACE_DUMP, sw_interface_dump);
2596 mp->name_filter_valid = 1;
2597 strncpy ((char *) mp->name_filter, "Ether", sizeof(mp->name_filter-1));
2600 /* and local / loopback interfaces */
2601 M(SW_INTERFACE_DUMP, sw_interface_dump);
2602 mp->name_filter_valid = 1;
2603 strncpy ((char *) mp->name_filter, "lo", sizeof(mp->name_filter-1));
2606 /* and vxlan tunnel interfaces */
2607 M(SW_INTERFACE_DUMP, sw_interface_dump);
2608 mp->name_filter_valid = 1;
2609 strncpy ((char *) mp->name_filter, "vxlan", sizeof(mp->name_filter-1));
2612 /* and l2tpv3 tunnel interfaces */
2613 M(SW_INTERFACE_DUMP, sw_interface_dump);
2614 mp->name_filter_valid = 1;
2615 strncpy ((char *) mp->name_filter, "l2tpv3_tunnel", sizeof(mp->name_filter-1));
2618 /* Use a control ping for synchronization */
2620 vl_api_control_ping_t * mp;
2621 M(CONTROL_PING, control_ping);
2627 static int api_sw_interface_set_flags (vat_main_t * vam)
2629 unformat_input_t * i = vam->input;
2630 vl_api_sw_interface_set_flags_t *mp;
2633 u8 sw_if_index_set = 0;
2634 u8 admin_up = 0, link_up = 0;
2636 /* Parse args required to build the message */
2637 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
2638 if (unformat (i, "admin-up"))
2640 else if (unformat (i, "admin-down"))
2642 else if (unformat (i, "link-up"))
2644 else if (unformat (i, "link-down"))
2646 else if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
2647 sw_if_index_set = 1;
2648 else if (unformat (i, "sw_if_index %d", &sw_if_index))
2649 sw_if_index_set = 1;
2654 if (sw_if_index_set == 0) {
2655 errmsg ("missing interface name or sw_if_index\n");
2659 /* Construct the API message */
2660 M(SW_INTERFACE_SET_FLAGS, sw_interface_set_flags);
2661 mp->sw_if_index = ntohl (sw_if_index);
2662 mp->admin_up_down = admin_up;
2663 mp->link_up_down = link_up;
2668 /* Wait for a reply, return the good/bad news... */
2672 static int api_sw_interface_add_del_address (vat_main_t * vam)
2674 unformat_input_t * i = vam->input;
2675 vl_api_sw_interface_add_del_address_t *mp;
2678 u8 sw_if_index_set = 0;
2679 u8 is_add = 1, del_all = 0;
2680 u32 address_length = 0;
2681 u8 v4_address_set = 0;
2682 u8 v6_address_set = 0;
2683 ip4_address_t v4address;
2684 ip6_address_t v6address;
2686 /* Parse args required to build the message */
2687 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
2688 if (unformat (i, "del-all"))
2690 else if (unformat (i, "del"))
2692 else if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
2693 sw_if_index_set = 1;
2694 else if (unformat (i, "sw_if_index %d", &sw_if_index))
2695 sw_if_index_set = 1;
2696 else if (unformat (i, "%U/%d",
2697 unformat_ip4_address, &v4address,
2700 else if (unformat (i, "%U/%d",
2701 unformat_ip6_address, &v6address,
2708 if (sw_if_index_set == 0) {
2709 errmsg ("missing interface name or sw_if_index\n");
2712 if (v4_address_set && v6_address_set) {
2713 errmsg ("both v4 and v6 addresses set\n");
2716 if (!v4_address_set && !v6_address_set && !del_all) {
2717 errmsg ("no addresses set\n");
2721 /* Construct the API message */
2722 M(SW_INTERFACE_ADD_DEL_ADDRESS, sw_interface_add_del_address);
2724 mp->sw_if_index = ntohl (sw_if_index);
2725 mp->is_add = is_add;
2726 mp->del_all = del_all;
2727 if (v6_address_set) {
2729 memcpy (mp->address, &v6address, sizeof (v6address));
2731 memcpy (mp->address, &v4address, sizeof (v4address));
2733 mp->address_length = address_length;
2738 /* Wait for a reply, return good/bad news */
2742 static int api_sw_interface_set_table (vat_main_t * vam)
2744 unformat_input_t * i = vam->input;
2745 vl_api_sw_interface_set_table_t *mp;
2747 u32 sw_if_index, vrf_id = 0;
2748 u8 sw_if_index_set = 0;
2751 /* Parse args required to build the message */
2752 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
2753 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
2754 sw_if_index_set = 1;
2755 else if (unformat (i, "sw_if_index %d", &sw_if_index))
2756 sw_if_index_set = 1;
2757 else if (unformat (i, "vrf %d", &vrf_id))
2759 else if (unformat (i, "ipv6"))
2765 if (sw_if_index_set == 0) {
2766 errmsg ("missing interface name or sw_if_index\n");
2770 /* Construct the API message */
2771 M(SW_INTERFACE_SET_TABLE, sw_interface_set_table);
2773 mp->sw_if_index = ntohl (sw_if_index);
2774 mp->is_ipv6 = is_ipv6;
2775 mp->vrf_id = ntohl (vrf_id);
2780 /* Wait for a reply... */
2784 static int api_sw_interface_set_vpath (vat_main_t * vam)
2786 unformat_input_t * i = vam->input;
2787 vl_api_sw_interface_set_vpath_t *mp;
2789 u32 sw_if_index = 0;
2790 u8 sw_if_index_set = 0;
2793 /* Parse args required to build the message */
2794 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
2795 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
2796 sw_if_index_set = 1;
2797 else if (unformat (i, "sw_if_index %d", &sw_if_index))
2798 sw_if_index_set = 1;
2799 else if (unformat (i, "enable"))
2801 else if (unformat (i, "disable"))
2807 if (sw_if_index_set == 0) {
2808 errmsg ("missing interface name or sw_if_index\n");
2812 /* Construct the API message */
2813 M(SW_INTERFACE_SET_VPATH, sw_interface_set_vpath);
2815 mp->sw_if_index = ntohl (sw_if_index);
2816 mp->enable = is_enable;
2821 /* Wait for a reply... */
2825 static int api_sw_interface_set_l2_xconnect (vat_main_t * vam)
2827 unformat_input_t * i = vam->input;
2828 vl_api_sw_interface_set_l2_xconnect_t *mp;
2831 u8 rx_sw_if_index_set = 0;
2833 u8 tx_sw_if_index_set = 0;
2836 /* Parse args required to build the message */
2837 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
2838 if (unformat (i, "rx_sw_if_index %d", &rx_sw_if_index))
2839 rx_sw_if_index_set = 1;
2840 else if (unformat (i, "tx_sw_if_index %d", &tx_sw_if_index))
2841 tx_sw_if_index_set = 1;
2842 else if (unformat (i, "rx")) {
2843 if (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
2844 if (unformat (i, "%U", unformat_sw_if_index, vam,
2846 rx_sw_if_index_set = 1;
2849 } else if (unformat (i, "tx")) {
2850 if (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
2851 if (unformat (i, "%U", unformat_sw_if_index, vam,
2853 tx_sw_if_index_set = 1;
2856 } else if (unformat (i, "enable"))
2858 else if (unformat (i, "disable"))
2864 if (rx_sw_if_index_set == 0) {
2865 errmsg ("missing rx interface name or rx_sw_if_index\n");
2869 if (enable && (tx_sw_if_index_set == 0)) {
2870 errmsg ("missing tx interface name or tx_sw_if_index\n");
2874 M(SW_INTERFACE_SET_L2_XCONNECT, sw_interface_set_l2_xconnect);
2876 mp->rx_sw_if_index = ntohl(rx_sw_if_index);
2877 mp->tx_sw_if_index = ntohl(tx_sw_if_index);
2878 mp->enable = enable;
2885 static int api_sw_interface_set_l2_bridge (vat_main_t * vam)
2887 unformat_input_t * i = vam->input;
2888 vl_api_sw_interface_set_l2_bridge_t *mp;
2891 u8 rx_sw_if_index_set = 0;
2898 /* Parse args required to build the message */
2899 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
2900 if (unformat (i, "sw_if_index %d", &rx_sw_if_index))
2901 rx_sw_if_index_set = 1;
2902 else if (unformat (i, "bd_id %d", &bd_id))
2904 else if (unformat (i, "%U", unformat_sw_if_index, vam,
2906 rx_sw_if_index_set = 1;
2907 else if (unformat (i, "shg %d", &shg))
2909 else if (unformat (i, "bvi"))
2911 else if (unformat (i, "enable"))
2913 else if (unformat (i, "disable"))
2919 if (rx_sw_if_index_set == 0) {
2920 errmsg ("missing rx interface name or sw_if_index\n");
2924 if (enable && (bd_id_set == 0)) {
2925 errmsg ("missing bridge domain\n");
2929 M(SW_INTERFACE_SET_L2_BRIDGE, sw_interface_set_l2_bridge);
2931 mp->rx_sw_if_index = ntohl(rx_sw_if_index);
2932 mp->bd_id = ntohl(bd_id);
2935 mp->enable = enable;
2942 static int api_bridge_domain_dump (vat_main_t * vam)
2944 unformat_input_t * i = vam->input;
2945 vl_api_bridge_domain_dump_t *mp;
2949 /* Parse args required to build the message */
2950 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
2951 if (unformat (i, "bd_id %d", &bd_id))
2957 M(BRIDGE_DOMAIN_DUMP, bridge_domain_dump);
2958 mp->bd_id = ntohl(bd_id);
2961 /* Use a control ping for synchronization */
2963 vl_api_control_ping_t * mp;
2964 M(CONTROL_PING, control_ping);
2973 static int api_bridge_domain_add_del (vat_main_t * vam)
2975 unformat_input_t * i = vam->input;
2976 vl_api_bridge_domain_add_del_t *mp;
2980 u32 flood = 1, forward = 1, learn = 1, uu_flood = 1, arp_term = 0;
2982 /* Parse args required to build the message */
2983 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
2984 if (unformat (i, "bd_id %d", &bd_id))
2986 else if (unformat (i, "flood %d", &flood))
2988 else if (unformat (i, "uu-flood %d", &uu_flood))
2990 else if (unformat (i, "forward %d", &forward))
2992 else if (unformat (i, "learn %d", &learn))
2994 else if (unformat (i, "arp-term %d", &arp_term))
2996 else if (unformat (i, "del")) {
2998 flood = uu_flood = forward = learn = 0;
3005 errmsg ("missing bridge domain\n");
3009 M(BRIDGE_DOMAIN_ADD_DEL, bridge_domain_add_del);
3011 mp->bd_id = ntohl(bd_id);
3013 mp->uu_flood = uu_flood;
3014 mp->forward = forward;
3016 mp->arp_term = arp_term;
3017 mp->is_add = is_add;
3024 static int api_l2fib_add_del (vat_main_t * vam)
3026 unformat_input_t * i = vam->input;
3027 vl_api_l2fib_add_del_t *mp;
3034 u8 sw_if_index_set = 0;
3039 /* Parse args required to build the message */
3040 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
3041 if (unformat (i, "mac %U", unformat_ethernet_address, &mac))
3043 else if (unformat (i, "bd_id %d", &bd_id))
3045 else if (unformat (i, "sw_if_index %d", &sw_if_index))
3046 sw_if_index_set = 1;
3047 else if (unformat (i, "sw_if")) {
3048 if (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
3049 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
3050 sw_if_index_set = 1;
3053 } else if (unformat (i, "static"))
3055 else if (unformat (i, "filter")) {
3058 } else if (unformat (i, "del"))
3065 errmsg ("missing mac address\n");
3069 if (bd_id_set == 0) {
3070 errmsg ("missing bridge domain\n");
3074 if (is_add && (sw_if_index_set == 0)) {
3075 errmsg ("missing interface name or sw_if_index\n");
3079 M(L2FIB_ADD_DEL, l2fib_add_del);
3082 mp->bd_id = ntohl(bd_id);
3083 mp->is_add = is_add;
3086 mp->sw_if_index = ntohl(sw_if_index);
3087 mp->static_mac = static_mac;
3088 mp->filter_mac = filter_mac;
3096 static int api_l2_flags (vat_main_t * vam)
3098 unformat_input_t * i = vam->input;
3099 vl_api_l2_flags_t *mp;
3102 u32 feature_bitmap = 0;
3103 u8 sw_if_index_set = 0;
3105 /* Parse args required to build the message */
3106 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
3107 if (unformat (i, "sw_if_index %d", &sw_if_index))
3108 sw_if_index_set = 1;
3109 else if (unformat (i, "sw_if")) {
3110 if (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
3111 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
3112 sw_if_index_set = 1;
3115 } else if (unformat (i, "learn"))
3116 feature_bitmap |= L2INPUT_FEAT_LEARN;
3117 else if (unformat (i, "forward"))
3118 feature_bitmap |= L2INPUT_FEAT_FWD;
3119 else if (unformat (i, "flood"))
3120 feature_bitmap |= L2INPUT_FEAT_FLOOD;
3121 else if (unformat (i, "uu-flood"))
3122 feature_bitmap |= L2INPUT_FEAT_UU_FLOOD;
3127 if (sw_if_index_set == 0) {
3128 errmsg ("missing interface name or sw_if_index\n");
3132 M(L2_FLAGS, l2_flags);
3134 mp->sw_if_index = ntohl(sw_if_index);
3135 mp->feature_bitmap = ntohl(feature_bitmap);
3142 static int api_bridge_flags (vat_main_t * vam)
3144 unformat_input_t * i = vam->input;
3145 vl_api_bridge_flags_t *mp;
3152 /* Parse args required to build the message */
3153 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
3154 if (unformat (i, "bd_id %d", &bd_id))
3156 else if (unformat (i, "learn"))
3158 else if (unformat (i, "forward"))
3160 else if (unformat (i, "flood"))
3162 else if (unformat (i, "uu-flood"))
3163 flags |= L2_UU_FLOOD;
3164 else if (unformat (i, "arp-term"))
3165 flags |= L2_ARP_TERM;
3166 else if (unformat (i, "off"))
3168 else if (unformat (i, "disable"))
3174 if (bd_id_set == 0) {
3175 errmsg ("missing bridge domain\n");
3179 M(BRIDGE_FLAGS, bridge_flags);
3181 mp->bd_id = ntohl(bd_id);
3182 mp->feature_bitmap = ntohl(flags);
3183 mp->is_set = is_set;
3190 static int api_bd_ip_mac_add_del (vat_main_t * vam)
3192 unformat_input_t * i = vam->input;
3193 vl_api_bd_ip_mac_add_del_t *mp;
3201 ip4_address_t v4addr;
3202 ip6_address_t v6addr;
3206 /* Parse args required to build the message */
3207 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
3208 if (unformat (i, "bd_id %d", &bd_id)) {
3210 } else if (unformat (i, "%U", unformat_ip4_address, &v4addr)) {
3212 } else if (unformat (i, "%U", unformat_ip6_address, &v6addr)) {
3215 } else if (unformat (i, "%U", unformat_ethernet_address, macaddr)) {
3217 } else if (unformat (i, "del"))
3223 if (bd_id_set == 0) {
3224 errmsg ("missing bridge domain\n");
3226 } else if (ip_set == 0) {
3227 errmsg ("missing IP address\n");
3229 } else if (mac_set == 0) {
3230 errmsg ("missing MAC address\n");
3234 M(BD_IP_MAC_ADD_DEL, bd_ip_mac_add_del);
3236 mp->bd_id = ntohl(bd_id);
3237 mp->is_ipv6 = is_ipv6;
3238 mp->is_add = is_add;
3240 memcpy (mp->ip_address, &v6addr, sizeof (v6addr));
3241 else memcpy (mp->ip_address, &v4addr, sizeof (v4addr));
3242 memcpy (mp->mac_address, macaddr, 6);
3248 static int api_tap_connect (vat_main_t * vam)
3250 unformat_input_t * i = vam->input;
3251 vl_api_tap_connect_t *mp;
3258 memset (mac_address, 0, sizeof (mac_address));
3260 /* Parse args required to build the message */
3261 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
3262 if (unformat (i, "mac %U", unformat_ethernet_address, mac_address)) {
3265 else if (unformat (i, "random-mac"))
3267 else if (unformat (i, "tapname %s", &tap_name))
3273 if (name_set == 0) {
3274 errmsg ("missing tap name\n");
3277 if (vec_len (tap_name) > 63) {
3278 errmsg ("tap name too long\n");
3280 vec_add1 (tap_name, 0);
3282 /* Construct the API message */
3283 M(TAP_CONNECT, tap_connect);
3285 mp->use_random_mac = random_mac;
3286 memcpy (mp->mac_address, mac_address, 6);
3287 memcpy (mp->tap_name, tap_name, vec_len (tap_name));
3288 vec_free (tap_name);
3293 /* Wait for a reply... */
3297 static int api_tap_modify (vat_main_t * vam)
3299 unformat_input_t * i = vam->input;
3300 vl_api_tap_modify_t *mp;
3306 u32 sw_if_index = ~0;
3307 u8 sw_if_index_set = 0;
3309 memset (mac_address, 0, sizeof (mac_address));
3311 /* Parse args required to build the message */
3312 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
3313 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
3314 sw_if_index_set = 1;
3315 else if (unformat (i, "sw_if_index %d", &sw_if_index))
3316 sw_if_index_set = 1;
3317 else if (unformat (i, "mac %U", unformat_ethernet_address, mac_address)) {
3320 else if (unformat (i, "random-mac"))
3322 else if (unformat (i, "tapname %s", &tap_name))
3328 if (sw_if_index_set == 0) {
3329 errmsg ("missing vpp interface name");
3332 if (name_set == 0) {
3333 errmsg ("missing tap name\n");
3336 if (vec_len (tap_name) > 63) {
3337 errmsg ("tap name too long\n");
3339 vec_add1 (tap_name, 0);
3341 /* Construct the API message */
3342 M(TAP_MODIFY, tap_modify);
3344 mp->use_random_mac = random_mac;
3345 mp->sw_if_index = ntohl(sw_if_index);
3346 memcpy (mp->mac_address, mac_address, 6);
3347 memcpy (mp->tap_name, tap_name, vec_len (tap_name));
3348 vec_free (tap_name);
3353 /* Wait for a reply... */
3357 static int api_tap_delete (vat_main_t * vam)
3359 unformat_input_t * i = vam->input;
3360 vl_api_tap_delete_t *mp;
3362 u32 sw_if_index = ~0;
3363 u8 sw_if_index_set = 0;
3365 /* Parse args required to build the message */
3366 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
3367 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
3368 sw_if_index_set = 1;
3369 else if (unformat (i, "sw_if_index %d", &sw_if_index))
3370 sw_if_index_set = 1;
3375 if (sw_if_index_set == 0) {
3376 errmsg ("missing vpp interface name");
3380 /* Construct the API message */
3381 M(TAP_DELETE, tap_delete);
3383 mp->sw_if_index = ntohl(sw_if_index);
3388 /* Wait for a reply... */
3392 static int api_ip_add_del_route (vat_main_t * vam)
3394 unformat_input_t * i = vam->input;
3395 vl_api_ip_add_del_route_t *mp;
3397 u32 sw_if_index = 0, vrf_id = 0;
3398 u8 sw_if_index_set = 0;
3400 u8 is_local = 0, is_drop = 0;
3401 u8 create_vrf_if_needed = 0;
3403 u8 next_hop_weight = 1;
3405 u8 is_multipath = 0;
3407 u8 address_length_set = 0;
3408 u32 lookup_in_vrf = 0;
3409 u32 resolve_attempts = 0;
3410 u32 dst_address_length = 0;
3411 u8 next_hop_set = 0;
3412 ip4_address_t v4_dst_address, v4_next_hop_address;
3413 ip6_address_t v6_dst_address, v6_next_hop_address;
3417 u32 random_add_del = 0;
3418 u32 * random_vector = 0;
3419 uword * random_hash;
3420 u32 random_seed = 0xdeaddabe;
3421 u32 classify_table_index = ~0;
3424 /* Parse args required to build the message */
3425 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
3426 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
3427 sw_if_index_set = 1;
3428 else if (unformat (i, "sw_if_index %d", &sw_if_index))
3429 sw_if_index_set = 1;
3430 else if (unformat (i, "%U", unformat_ip4_address,
3435 else if (unformat (i, "%U", unformat_ip6_address, &v6_dst_address)) {
3439 else if (unformat (i, "/%d", &dst_address_length)) {
3440 address_length_set = 1;
3443 else if (is_ipv6 == 0 && unformat (i, "via %U", unformat_ip4_address,
3444 &v4_next_hop_address)) {
3447 else if (is_ipv6 == 1 && unformat (i, "via %U", unformat_ip6_address,
3448 &v6_next_hop_address)) {
3451 else if (unformat (i, "resolve-attempts %d", &resolve_attempts))
3453 else if (unformat (i, "weight %d", &next_hop_weight))
3455 else if (unformat (i, "drop")) {
3457 } else if (unformat (i, "local")) {
3459 } else if (unformat (i, "classify %d", &classify_table_index)) {
3461 } else if (unformat (i, "del"))
3463 else if (unformat (i, "add"))
3465 else if (unformat (i, "not-last"))
3467 else if (unformat (i, "multipath"))
3469 else if (unformat (i, "vrf %d", &vrf_id))
3471 else if (unformat (i, "create-vrf"))
3472 create_vrf_if_needed = 1;
3473 else if (unformat (i, "count %d", &count))
3475 else if (unformat (i, "lookup-in-vrf %d", &lookup_in_vrf))
3477 else if (unformat (i, "random"))
3479 else if (unformat (i, "seed %d", &random_seed))
3482 clib_warning ("parse error '%U'", format_unformat_error, i);
3487 if (resolve_attempts > 0 && sw_if_index_set == 0) {
3488 errmsg ("ARP resolution needs explicit interface or sw_if_index\n");
3492 if (!next_hop_set && !is_drop && !is_local && !is_classify) {
3493 errmsg ("next hop / local / drop / classify not set\n");
3497 if (address_set == 0) {
3498 errmsg ("missing addresses\n");
3502 if (address_length_set == 0) {
3503 errmsg ("missing address length\n");
3507 /* Generate a pile of unique, random routes */
3508 if (random_add_del) {
3509 u32 this_random_address;
3510 random_hash = hash_create (count, sizeof(uword));
3512 hash_set (random_hash, v4_next_hop_address.as_u32, 1);
3513 for (j = 0; j <= count; j++) {
3515 this_random_address = random_u32 (&random_seed);
3516 this_random_address =
3517 clib_host_to_net_u32 (this_random_address);
3518 } while (hash_get (random_hash, this_random_address));
3519 vec_add1 (random_vector, this_random_address);
3520 hash_set (random_hash, this_random_address, 1);
3522 hash_free (random_hash);
3523 v4_dst_address.as_u32 = random_vector[0];
3527 /* Turn on async mode */
3528 vam->async_mode = 1;
3529 vam->async_errors = 0;
3530 before = vat_time_now(vam);
3533 for (j = 0; j < count; j++) {
3534 /* Construct the API message */
3535 M(IP_ADD_DEL_ROUTE, ip_add_del_route);
3537 mp->next_hop_sw_if_index = ntohl (sw_if_index);
3538 mp->vrf_id = ntohl (vrf_id);
3539 if (resolve_attempts > 0) {
3540 mp->resolve_attempts = ntohl (resolve_attempts);
3541 mp->resolve_if_needed = 1;
3543 mp->create_vrf_if_needed = create_vrf_if_needed;
3545 mp->is_add = is_add;
3546 mp->is_drop = is_drop;
3547 mp->is_ipv6 = is_ipv6;
3548 mp->is_local = is_local;
3549 mp->is_classify = is_classify;
3550 mp->is_multipath = is_multipath;
3551 mp->not_last = not_last;
3552 mp->next_hop_weight = next_hop_weight;
3553 mp->dst_address_length = dst_address_length;
3554 mp->lookup_in_vrf = ntohl(lookup_in_vrf);
3555 mp->classify_table_index = ntohl(classify_table_index);
3558 memcpy (mp->dst_address, &v6_dst_address, sizeof (v6_dst_address));
3560 memcpy (mp->next_hop_address, &v6_next_hop_address,
3561 sizeof (v6_next_hop_address));
3562 increment_v6_address (&v6_dst_address);
3564 memcpy (mp->dst_address, &v4_dst_address, sizeof (v4_dst_address));
3566 memcpy (mp->next_hop_address, &v4_next_hop_address,
3567 sizeof (v4_next_hop_address));
3569 v4_dst_address.as_u32 = random_vector[j+1];
3571 increment_v4_address (&v4_dst_address);
3577 /* When testing multiple add/del ops, use a control-ping to sync */
3579 vl_api_control_ping_t * mp;
3582 /* Shut off async mode */
3583 vam->async_mode = 0;
3585 M(CONTROL_PING, control_ping);
3588 timeout = vat_time_now(vam) + 1.0;
3589 while (vat_time_now (vam) < timeout)
3590 if (vam->result_ready == 1)
3595 if (vam->retval == -99)
3596 errmsg ("timeout\n");
3598 if (vam->async_errors > 0) {
3599 errmsg ("%d asynchronous errors\n", vam->async_errors);
3602 vam->async_errors = 0;
3603 after = vat_time_now(vam);
3605 fformat(vam->ofp, "%d routes in %.6f secs, %.2f routes/sec\n",
3606 count, after - before, count / (after - before));
3608 /* Wait for a reply... */
3612 /* Return the good/bad news */
3613 return (vam->retval);
3616 static int api_proxy_arp_add_del (vat_main_t * vam)
3618 unformat_input_t * i = vam->input;
3619 vl_api_proxy_arp_add_del_t *mp;
3623 ip4_address_t lo, hi;
3626 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
3627 if (unformat (i, "vrf %d", &vrf_id))
3629 else if (unformat (i, "%U - %U", unformat_ip4_address, &lo,
3630 unformat_ip4_address, &hi))
3632 else if (unformat (i, "del"))
3635 clib_warning ("parse error '%U'", format_unformat_error, i);
3640 if (range_set == 0) {
3641 errmsg ("address range not set\n");
3645 M(PROXY_ARP_ADD_DEL, proxy_arp_add_del);
3647 mp->vrf_id = ntohl(vrf_id);
3648 mp->is_add = is_add;
3649 memcpy(mp->low_address, &lo, sizeof (mp->low_address));
3650 memcpy(mp->hi_address, &hi, sizeof (mp->hi_address));
3657 static int api_proxy_arp_intfc_enable_disable (vat_main_t * vam)
3659 unformat_input_t * i = vam->input;
3660 vl_api_proxy_arp_intfc_enable_disable_t *mp;
3664 u8 sw_if_index_set = 0;
3666 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
3667 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
3668 sw_if_index_set = 1;
3669 else if (unformat (i, "sw_if_index %d", &sw_if_index))
3670 sw_if_index_set = 1;
3671 else if (unformat (i, "enable"))
3673 else if (unformat (i, "disable"))
3676 clib_warning ("parse error '%U'", format_unformat_error, i);
3681 if (sw_if_index_set == 0) {
3682 errmsg ("missing interface name or sw_if_index\n");
3686 M(PROXY_ARP_INTFC_ENABLE_DISABLE, proxy_arp_intfc_enable_disable);
3688 mp->sw_if_index = ntohl(sw_if_index);
3689 mp->enable_disable = enable;
3696 static int api_mpls_add_del_decap (vat_main_t * vam)
3698 unformat_input_t * i = vam->input;
3699 vl_api_mpls_add_del_decap_t *mp;
3708 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
3709 if (unformat (i, "rx_vrf_id %d", &rx_vrf_id))
3711 else if (unformat (i, "tx_vrf_id %d", &tx_vrf_id))
3713 else if (unformat (i, "label %d", &label))
3715 else if (unformat (i, "next-index %d", &next_index))
3717 else if (unformat (i, "del"))
3719 else if (unformat (i, "s-bit-clear"))
3722 clib_warning ("parse error '%U'", format_unformat_error, i);
3727 M(MPLS_ADD_DEL_DECAP, mpls_add_del_decap);
3729 mp->rx_vrf_id = ntohl(rx_vrf_id);
3730 mp->tx_vrf_id = ntohl(tx_vrf_id);
3731 mp->label = ntohl(label);
3732 mp->next_index = ntohl(next_index);
3734 mp->is_add = is_add;
3741 static int api_mpls_add_del_encap (vat_main_t * vam)
3743 unformat_input_t * i = vam->input;
3744 vl_api_mpls_add_del_encap_t *mp;
3749 ip4_address_t dst_address;
3752 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
3753 if (unformat (i, "vrf %d", &vrf_id))
3755 else if (unformat (i, "label %d", &label))
3756 vec_add1 (labels, ntohl(label));
3757 else if (unformat (i, "dst %U", unformat_ip4_address, &dst_address))
3759 else if (unformat (i, "del"))
3762 clib_warning ("parse error '%U'", format_unformat_error, i);
3767 if (vec_len (labels) == 0) {
3768 errmsg ("missing encap label stack\n");
3772 M2(MPLS_ADD_DEL_ENCAP, mpls_add_del_encap,
3773 sizeof (u32) * vec_len (labels));
3775 mp->vrf_id = ntohl(vrf_id);
3776 memcpy(mp->dst_address, &dst_address, sizeof (dst_address));
3777 mp->is_add = is_add;
3778 mp->nlabels = vec_len (labels);
3779 memcpy(mp->labels, labels, sizeof(u32)*mp->nlabels);
3788 static int api_mpls_gre_add_del_tunnel (vat_main_t * vam)
3790 unformat_input_t * i = vam->input;
3791 vl_api_mpls_gre_add_del_tunnel_t *mp;
3793 u32 inner_vrf_id = 0;
3794 u32 outer_vrf_id = 0;
3795 ip4_address_t src_address;
3796 ip4_address_t dst_address;
3797 ip4_address_t intfc_address;
3799 u8 intfc_address_length = 0;
3803 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
3804 if (unformat (i, "inner_vrf_id %d", &inner_vrf_id))
3806 else if (unformat (i, "outer_vrf_id %d", &outer_vrf_id))
3808 else if (unformat (i, "src %U", unformat_ip4_address, &src_address))
3810 else if (unformat (i, "dst %U", unformat_ip4_address, &dst_address))
3812 else if (unformat (i, "adj %U/%d", unformat_ip4_address,
3813 &intfc_address, &tmp))
3814 intfc_address_length = tmp;
3815 else if (unformat (i, "l2-only"))
3817 else if (unformat (i, "del"))
3820 clib_warning ("parse error '%U'", format_unformat_error, i);
3825 M(MPLS_GRE_ADD_DEL_TUNNEL, mpls_gre_add_del_tunnel);
3827 mp->inner_vrf_id = ntohl(inner_vrf_id);
3828 mp->outer_vrf_id = ntohl(outer_vrf_id);
3829 memcpy(mp->src_address, &src_address, sizeof (src_address));
3830 memcpy(mp->dst_address, &dst_address, sizeof (dst_address));
3831 memcpy(mp->intfc_address, &intfc_address, sizeof (intfc_address));
3832 mp->intfc_address_length = intfc_address_length;
3833 mp->l2_only = l2_only;
3834 mp->is_add = is_add;
3841 static int api_mpls_ethernet_add_del_tunnel (vat_main_t * vam)
3843 unformat_input_t * i = vam->input;
3844 vl_api_mpls_ethernet_add_del_tunnel_t *mp;
3846 u32 inner_vrf_id = 0;
3847 ip4_address_t intfc_address;
3848 u8 dst_mac_address[6];
3851 u8 intfc_address_length = 0;
3855 int tx_sw_if_index_set = 0;
3857 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
3858 if (unformat (i, "vrf %d", &inner_vrf_id))
3860 else if (unformat (i, "adj %U/%d", unformat_ip4_address,
3861 &intfc_address, &tmp))
3862 intfc_address_length = tmp;
3863 else if (unformat (i, "%U",
3864 unformat_sw_if_index, vam, &tx_sw_if_index))
3865 tx_sw_if_index_set = 1;
3866 else if (unformat (i, "tx_sw_if_index %d", &tx_sw_if_index))
3867 tx_sw_if_index_set = 1;
3868 else if (unformat (i, "dst %U", unformat_ethernet_address,
3871 else if (unformat (i, "l2-only"))
3873 else if (unformat (i, "del"))
3876 clib_warning ("parse error '%U'", format_unformat_error, i);
3882 errmsg ("dst (mac address) not set\n");
3885 if (!tx_sw_if_index_set) {
3886 errmsg ("tx-intfc not set\n");
3890 M(MPLS_ETHERNET_ADD_DEL_TUNNEL, mpls_ethernet_add_del_tunnel);
3892 mp->vrf_id = ntohl(inner_vrf_id);
3893 memcpy (mp->adj_address, &intfc_address, sizeof (intfc_address));
3894 mp->adj_address_length = intfc_address_length;
3895 memcpy (mp->dst_mac_address, dst_mac_address, sizeof (dst_mac_address));
3896 mp->tx_sw_if_index = ntohl(tx_sw_if_index);
3897 mp->l2_only = l2_only;
3898 mp->is_add = is_add;
3905 static int api_mpls_ethernet_add_del_tunnel_2 (vat_main_t * vam)
3907 unformat_input_t * i = vam->input;
3908 vl_api_mpls_ethernet_add_del_tunnel_2_t *mp;
3910 u32 inner_vrf_id = 0;
3911 u32 outer_vrf_id = 0;
3912 ip4_address_t adj_address;
3913 int adj_address_set = 0;
3914 ip4_address_t next_hop_address;
3915 int next_hop_address_set = 0;
3917 u8 adj_address_length = 0;
3920 u32 resolve_attempts = 5;
3921 u8 resolve_if_needed = 1;
3923 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
3924 if (unformat (i, "inner_vrf_id %d", &inner_vrf_id))
3926 else if (unformat (i, "outer_vrf_id %d", &outer_vrf_id))
3928 else if (unformat (i, "adj %U/%d", unformat_ip4_address,
3929 &adj_address, &tmp)) {
3930 adj_address_length = tmp;
3931 adj_address_set = 1;
3933 else if (unformat (i, "next-hop %U", unformat_ip4_address,
3935 next_hop_address_set = 1;
3936 else if (unformat (i, "resolve-attempts %d", &resolve_attempts))
3938 else if (unformat (i, "resolve-if-needed %d", &tmp))
3939 resolve_if_needed = tmp;
3940 else if (unformat (i, "l2-only"))
3942 else if (unformat (i, "del"))
3945 clib_warning ("parse error '%U'", format_unformat_error, i);
3950 if (!adj_address_set) {
3951 errmsg ("adjacency address/mask not set\n");
3954 if (!next_hop_address_set) {
3955 errmsg ("ip4 next hop address (in outer fib) not set\n");
3959 M(MPLS_ETHERNET_ADD_DEL_TUNNEL_2, mpls_ethernet_add_del_tunnel_2);
3961 mp->inner_vrf_id = ntohl(inner_vrf_id);
3962 mp->outer_vrf_id = ntohl(outer_vrf_id);
3963 mp->resolve_attempts = ntohl(resolve_attempts);
3964 mp->resolve_if_needed = resolve_if_needed;
3965 mp->is_add = is_add;
3966 mp->l2_only = l2_only;
3967 memcpy (mp->adj_address, &adj_address, sizeof (adj_address));
3968 mp->adj_address_length = adj_address_length;
3969 memcpy (mp->next_hop_ip4_address_in_outer_vrf, &next_hop_address,
3970 sizeof (next_hop_address));
3977 static int api_sw_interface_set_unnumbered (vat_main_t * vam)
3979 unformat_input_t * i = vam->input;
3980 vl_api_sw_interface_set_unnumbered_t *mp;
3985 u8 sw_if_index_set = 0;
3987 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
3988 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
3989 sw_if_index_set = 1;
3990 else if (unformat (i, "sw_if_index %d", &sw_if_index))
3991 sw_if_index_set = 1;
3992 else if (unformat (i, "unnum_if_index %d", &unnum_sw_index))
3994 else if (unformat (i, "del"))
3997 clib_warning ("parse error '%U'", format_unformat_error, i);
4002 if (sw_if_index_set == 0) {
4003 errmsg ("missing interface name or sw_if_index\n");
4007 M(SW_INTERFACE_SET_UNNUMBERED, sw_interface_set_unnumbered);
4009 mp->sw_if_index = ntohl(sw_if_index);
4010 mp->unnumbered_sw_if_index = ntohl(unnum_sw_index);
4011 mp->is_add = is_add;
4018 static int api_ip_neighbor_add_del (vat_main_t * vam)
4020 unformat_input_t * i = vam->input;
4021 vl_api_ip_neighbor_add_del_t *mp;
4024 u8 sw_if_index_set = 0;
4030 u8 v4_address_set = 0;
4031 u8 v6_address_set = 0;
4032 ip4_address_t v4address;
4033 ip6_address_t v6address;
4035 memset (mac_address, 0, sizeof (mac_address));
4037 /* Parse args required to build the message */
4038 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
4039 if (unformat (i, "mac %U", unformat_ethernet_address, mac_address)) {
4042 else if (unformat (i, "del"))
4044 else if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
4045 sw_if_index_set = 1;
4046 else if (unformat (i, "sw_if_index %d", &sw_if_index))
4047 sw_if_index_set = 1;
4048 else if (unformat (i, "is_static"))
4050 else if (unformat (i, "vrf %d", &vrf_id))
4052 else if (unformat (i, "dst %U",
4053 unformat_ip4_address, &v4address))
4055 else if (unformat (i, "dst %U",
4056 unformat_ip6_address, &v6address))
4059 clib_warning ("parse error '%U'", format_unformat_error, i);
4064 if (sw_if_index_set == 0) {
4065 errmsg ("missing interface name or sw_if_index\n");
4068 if (v4_address_set && v6_address_set) {
4069 errmsg ("both v4 and v6 addresses set\n");
4072 if (!v4_address_set && !v6_address_set) {
4073 errmsg ("no addresses set\n");
4077 /* Construct the API message */
4078 M(IP_NEIGHBOR_ADD_DEL, ip_neighbor_add_del);
4080 mp->sw_if_index = ntohl (sw_if_index);
4081 mp->is_add = is_add;
4082 mp->vrf_id = ntohl (vrf_id);
4083 mp->is_static = is_static;
4085 memcpy (mp->mac_address, mac_address, 6);
4086 if (v6_address_set) {
4088 memcpy (mp->dst_address, &v6address, sizeof (v6address));
4090 /* mp->is_ipv6 = 0; via memset in M macro above */
4091 memcpy (mp->dst_address, &v4address, sizeof (v4address));
4097 /* Wait for a reply, return good/bad news */
4104 static int api_reset_vrf (vat_main_t * vam)
4106 unformat_input_t * i = vam->input;
4107 vl_api_reset_vrf_t *mp;
4113 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
4114 if (unformat (i, "vrf %d", &vrf_id))
4116 else if (unformat (i, "ipv6"))
4119 clib_warning ("parse error '%U'", format_unformat_error, i);
4124 if (vrf_id_set == 0) {
4125 errmsg ("missing vrf id\n");
4129 M(RESET_VRF, reset_vrf);
4131 mp->vrf_id = ntohl(vrf_id);
4132 mp->is_ipv6 = is_ipv6;
4139 static int api_create_vlan_subif (vat_main_t * vam)
4141 unformat_input_t * i = vam->input;
4142 vl_api_create_vlan_subif_t *mp;
4145 u8 sw_if_index_set = 0;
4149 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
4150 if (unformat (i, "sw_if_index %d", &sw_if_index))
4151 sw_if_index_set = 1;
4152 else if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
4153 sw_if_index_set = 1;
4154 else if (unformat (i, "vlan %d", &vlan_id))
4157 clib_warning ("parse error '%U'", format_unformat_error, i);
4162 if (sw_if_index_set == 0) {
4163 errmsg ("missing interface name or sw_if_index\n");
4167 if (vlan_id_set == 0) {
4168 errmsg ("missing vlan_id\n");
4171 M(CREATE_VLAN_SUBIF, create_vlan_subif);
4173 mp->sw_if_index = ntohl(sw_if_index);
4174 mp->vlan_id = ntohl(vlan_id);
4181 #define foreach_create_subif_bit \
4188 _(outer_vlan_id_any) \
4189 _(inner_vlan_id_any)
4191 static int api_create_subif (vat_main_t * vam)
4193 unformat_input_t * i = vam->input;
4194 vl_api_create_subif_t *mp;
4197 u8 sw_if_index_set = 0;
4204 u32 exact_match = 0;
4205 u32 default_sub = 0;
4206 u32 outer_vlan_id_any = 0;
4207 u32 inner_vlan_id_any = 0;
4209 u16 outer_vlan_id = 0;
4210 u16 inner_vlan_id = 0;
4212 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
4213 if (unformat (i, "sw_if_index %d", &sw_if_index))
4214 sw_if_index_set = 1;
4215 else if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
4216 sw_if_index_set = 1;
4217 else if (unformat (i, "sub_id %d", &sub_id))
4219 else if (unformat (i, "outer_vlan_id %d", &tmp))
4220 outer_vlan_id = tmp;
4221 else if (unformat (i, "inner_vlan_id %d", &tmp))
4222 inner_vlan_id = tmp;
4224 #define _(a) else if (unformat (i, #a)) a = 1 ;
4225 foreach_create_subif_bit
4229 clib_warning ("parse error '%U'", format_unformat_error, i);
4234 if (sw_if_index_set == 0) {
4235 errmsg ("missing interface name or sw_if_index\n");
4239 if (sub_id_set == 0) {
4240 errmsg ("missing sub_id\n");
4243 M(CREATE_SUBIF, create_subif);
4245 mp->sw_if_index = ntohl(sw_if_index);
4246 mp->sub_id = ntohl(sub_id);
4248 #define _(a) mp->a = a;
4249 foreach_create_subif_bit;
4252 mp->outer_vlan_id = ntohs (outer_vlan_id);
4253 mp->inner_vlan_id = ntohs (inner_vlan_id);
4260 static int api_oam_add_del (vat_main_t * vam)
4262 unformat_input_t * i = vam->input;
4263 vl_api_oam_add_del_t *mp;
4267 ip4_address_t src, dst;
4271 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
4272 if (unformat (i, "vrf %d", &vrf_id))
4274 else if (unformat (i, "src %U", unformat_ip4_address, &src))
4276 else if (unformat (i, "dst %U", unformat_ip4_address, &dst))
4278 else if (unformat (i, "del"))
4281 clib_warning ("parse error '%U'", format_unformat_error, i);
4287 errmsg ("missing src addr\n");
4292 errmsg ("missing dst addr\n");
4296 M(OAM_ADD_DEL, oam_add_del);
4298 mp->vrf_id = ntohl(vrf_id);
4299 mp->is_add = is_add;
4300 memcpy(mp->src_address, &src, sizeof (mp->src_address));
4301 memcpy(mp->dst_address, &dst, sizeof (mp->dst_address));
4308 static int api_reset_fib (vat_main_t * vam)
4310 unformat_input_t * i = vam->input;
4311 vl_api_reset_fib_t *mp;
4317 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
4318 if (unformat (i, "vrf %d", &vrf_id))
4320 else if (unformat (i, "ipv6"))
4323 clib_warning ("parse error '%U'", format_unformat_error, i);
4328 if (vrf_id_set == 0) {
4329 errmsg ("missing vrf id\n");
4333 M(RESET_FIB, reset_fib);
4335 mp->vrf_id = ntohl(vrf_id);
4336 mp->is_ipv6 = is_ipv6;
4343 static int api_dhcp_proxy_config (vat_main_t * vam)
4345 unformat_input_t * i = vam->input;
4346 vl_api_dhcp_proxy_config_t *mp;
4351 u8 v4_address_set = 0;
4352 u8 v6_address_set = 0;
4353 ip4_address_t v4address;
4354 ip6_address_t v6address;
4355 u8 v4_src_address_set = 0;
4356 u8 v6_src_address_set = 0;
4357 ip4_address_t v4srcaddress;
4358 ip6_address_t v6srcaddress;
4360 /* Parse args required to build the message */
4361 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
4362 if (unformat (i, "del"))
4364 else if (unformat (i, "vrf %d", &vrf_id))
4366 else if (unformat (i, "insert-cid %d", &insert_cid))
4368 else if (unformat (i, "svr %U",
4369 unformat_ip4_address, &v4address))
4371 else if (unformat (i, "svr %U",
4372 unformat_ip6_address, &v6address))
4374 else if (unformat (i, "src %U",
4375 unformat_ip4_address, &v4srcaddress))
4376 v4_src_address_set = 1;
4377 else if (unformat (i, "src %U",
4378 unformat_ip6_address, &v6srcaddress))
4379 v6_src_address_set = 1;
4384 if (v4_address_set && v6_address_set) {
4385 errmsg ("both v4 and v6 server addresses set\n");
4388 if (!v4_address_set && !v6_address_set) {
4389 errmsg ("no server addresses set\n");
4393 if (v4_src_address_set && v6_src_address_set) {
4394 errmsg ("both v4 and v6 src addresses set\n");
4397 if (!v4_src_address_set && !v6_src_address_set) {
4398 errmsg ("no src addresses set\n");
4402 if (!(v4_src_address_set && v4_address_set) &&
4403 !(v6_src_address_set && v6_address_set)) {
4404 errmsg ("no matching server and src addresses set\n");
4408 /* Construct the API message */
4409 M(DHCP_PROXY_CONFIG, dhcp_proxy_config);
4411 mp->insert_circuit_id = insert_cid;
4412 mp->is_add = is_add;
4413 mp->vrf_id = ntohl (vrf_id);
4414 if (v6_address_set) {
4416 memcpy (mp->dhcp_server, &v6address, sizeof (v6address));
4417 memcpy (mp->dhcp_src_address, &v6srcaddress, sizeof (v6address));
4419 memcpy (mp->dhcp_server, &v4address, sizeof (v4address));
4420 memcpy (mp->dhcp_src_address, &v4srcaddress, sizeof (v4address));
4426 /* Wait for a reply, return good/bad news */
4432 static int api_dhcp_proxy_config_2 (vat_main_t * vam)
4434 unformat_input_t * i = vam->input;
4435 vl_api_dhcp_proxy_config_2_t *mp;
4438 u32 server_vrf_id = 0;
4441 u8 v4_address_set = 0;
4442 u8 v6_address_set = 0;
4443 ip4_address_t v4address;
4444 ip6_address_t v6address;
4445 u8 v4_src_address_set = 0;
4446 u8 v6_src_address_set = 0;
4447 ip4_address_t v4srcaddress;
4448 ip6_address_t v6srcaddress;
4450 /* Parse args required to build the message */
4451 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
4452 if (unformat (i, "del"))
4454 else if (unformat (i, "rx_vrf_id %d", &rx_vrf_id))
4456 else if (unformat (i, "server_vrf_id %d", &server_vrf_id))
4458 else if (unformat (i, "insert-cid %d", &insert_cid))
4460 else if (unformat (i, "svr %U",
4461 unformat_ip4_address, &v4address))
4463 else if (unformat (i, "svr %U",
4464 unformat_ip6_address, &v6address))
4466 else if (unformat (i, "src %U",
4467 unformat_ip4_address, &v4srcaddress))
4468 v4_src_address_set = 1;
4469 else if (unformat (i, "src %U",
4470 unformat_ip6_address, &v6srcaddress))
4471 v6_src_address_set = 1;
4476 if (v4_address_set && v6_address_set) {
4477 errmsg ("both v4 and v6 server addresses set\n");
4480 if (!v4_address_set && !v6_address_set) {
4481 errmsg ("no server addresses set\n");
4485 if (v4_src_address_set && v6_src_address_set) {
4486 errmsg ("both v4 and v6 src addresses set\n");
4489 if (!v4_src_address_set && !v6_src_address_set) {
4490 errmsg ("no src addresses set\n");
4494 if (!(v4_src_address_set && v4_address_set) &&
4495 !(v6_src_address_set && v6_address_set)) {
4496 errmsg ("no matching server and src addresses set\n");
4500 /* Construct the API message */
4501 M(DHCP_PROXY_CONFIG_2, dhcp_proxy_config_2);
4503 mp->insert_circuit_id = insert_cid;
4504 mp->is_add = is_add;
4505 mp->rx_vrf_id = ntohl (rx_vrf_id);
4506 mp->server_vrf_id = ntohl (server_vrf_id);
4507 if (v6_address_set) {
4509 memcpy (mp->dhcp_server, &v6address, sizeof (v6address));
4510 memcpy (mp->dhcp_src_address, &v6srcaddress, sizeof (v6address));
4512 memcpy (mp->dhcp_server, &v4address, sizeof (v4address));
4513 memcpy (mp->dhcp_src_address, &v4srcaddress, sizeof (v4address));
4519 /* Wait for a reply, return good/bad news */
4525 static int api_dhcp_proxy_set_vss (vat_main_t * vam)
4527 unformat_input_t * i = vam->input;
4528 vl_api_dhcp_proxy_set_vss_t *mp;
4539 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
4540 if (unformat (i, "tbl_id %d", &tbl_id))
4542 if (unformat (i, "fib_id %d", &fib_id))
4544 if (unformat (i, "oui %d", &oui))
4546 else if (unformat (i, "ipv6"))
4548 else if (unformat (i, "del"))
4551 clib_warning ("parse error '%U'", format_unformat_error, i);
4556 if (tbl_id_set == 0) {
4557 errmsg ("missing tbl id\n");
4561 if (fib_id_set == 0) {
4562 errmsg ("missing fib id\n");
4566 errmsg ("missing oui\n");
4570 M(DHCP_PROXY_SET_VSS, dhcp_proxy_set_vss);
4571 mp->tbl_id = ntohl(tbl_id);
4572 mp->fib_id = ntohl(fib_id);
4573 mp->oui = ntohl(oui);
4574 mp->is_ipv6 = is_ipv6;
4575 mp->is_add = is_add;
4582 static int api_dhcp_client_config (vat_main_t * vam)
4584 unformat_input_t * i = vam->input;
4585 vl_api_dhcp_client_config_t *mp;
4588 u8 sw_if_index_set = 0;
4591 u8 disable_event = 0;
4593 /* Parse args required to build the message */
4594 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
4595 if (unformat (i, "del"))
4597 else if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
4598 sw_if_index_set = 1;
4599 else if (unformat (i, "sw_if_index %d", &sw_if_index))
4600 sw_if_index_set = 1;
4601 else if (unformat (i, "hostname %s", &hostname))
4603 else if (unformat (i, "disable_event"))
4609 if (sw_if_index_set == 0) {
4610 errmsg ("missing interface name or sw_if_index\n");
4614 if (vec_len (hostname) > 63) {
4615 errmsg ("hostname too long\n");
4617 vec_add1 (hostname, 0);
4619 /* Construct the API message */
4620 M(DHCP_CLIENT_CONFIG, dhcp_client_config);
4622 mp->sw_if_index = ntohl (sw_if_index);
4623 memcpy (mp->hostname, hostname, vec_len (hostname));
4624 vec_free (hostname);
4625 mp->is_add = is_add;
4626 mp->want_dhcp_event = disable_event ? 0 : 1;
4632 /* Wait for a reply, return good/bad news */
4638 static int api_set_ip_flow_hash (vat_main_t * vam)
4640 unformat_input_t * i = vam->input;
4641 vl_api_set_ip_flow_hash_t *mp;
4653 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
4654 if (unformat (i, "vrf %d", &vrf_id))
4656 else if (unformat (i, "ipv6"))
4658 else if (unformat (i, "src"))
4660 else if (unformat (i, "dst"))
4662 else if (unformat (i, "sport"))
4664 else if (unformat (i, "dport"))
4666 else if (unformat (i, "proto"))
4668 else if (unformat (i, "reverse"))
4672 clib_warning ("parse error '%U'", format_unformat_error, i);
4677 if (vrf_id_set == 0) {
4678 errmsg ("missing vrf id\n");
4682 M(SET_IP_FLOW_HASH, set_ip_flow_hash);
4688 mp->reverse = reverse;
4689 mp->vrf_id = ntohl(vrf_id);
4690 mp->is_ipv6 = is_ipv6;
4697 static int api_sw_interface_ip6_enable_disable (vat_main_t * vam)
4699 unformat_input_t * i = vam->input;
4700 vl_api_sw_interface_ip6_enable_disable_t *mp;
4703 u8 sw_if_index_set = 0;
4706 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
4707 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
4708 sw_if_index_set = 1;
4709 else if (unformat (i, "sw_if_index %d", &sw_if_index))
4710 sw_if_index_set = 1;
4711 else if (unformat (i, "enable"))
4713 else if (unformat (i, "disable"))
4716 clib_warning ("parse error '%U'", format_unformat_error, i);
4721 if (sw_if_index_set == 0) {
4722 errmsg ("missing interface name or sw_if_index\n");
4726 M(SW_INTERFACE_IP6_ENABLE_DISABLE, sw_interface_ip6_enable_disable);
4728 mp->sw_if_index = ntohl(sw_if_index);
4729 mp->enable = enable;
4736 static int api_sw_interface_ip6_set_link_local_address (vat_main_t * vam)
4738 unformat_input_t * i = vam->input;
4739 vl_api_sw_interface_ip6_set_link_local_address_t *mp;
4742 u8 sw_if_index_set = 0;
4743 u32 address_length = 0;
4744 u8 v6_address_set = 0;
4745 ip6_address_t v6address;
4747 /* Parse args required to build the message */
4748 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
4749 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
4750 sw_if_index_set = 1;
4751 else if (unformat (i, "sw_if_index %d", &sw_if_index))
4752 sw_if_index_set = 1;
4753 else if (unformat (i, "%U/%d",
4754 unformat_ip6_address, &v6address,
4761 if (sw_if_index_set == 0) {
4762 errmsg ("missing interface name or sw_if_index\n");
4765 if (!v6_address_set) {
4766 errmsg ("no address set\n");
4770 /* Construct the API message */
4771 M(SW_INTERFACE_IP6_SET_LINK_LOCAL_ADDRESS, \
4772 sw_interface_ip6_set_link_local_address);
4774 mp->sw_if_index = ntohl (sw_if_index);
4775 memcpy (mp->address, &v6address, sizeof (v6address));
4776 mp->address_length = address_length;
4781 /* Wait for a reply, return good/bad news */
4789 static int api_sw_interface_ip6nd_ra_prefix (vat_main_t * vam)
4791 unformat_input_t * i = vam->input;
4792 vl_api_sw_interface_ip6nd_ra_prefix_t *mp;
4795 u8 sw_if_index_set = 0;
4796 u32 address_length = 0;
4797 u8 v6_address_set = 0;
4798 ip6_address_t v6address;
4800 u8 no_advertise = 0;
4802 u8 no_autoconfig = 0;
4805 u32 val_lifetime = 0;
4806 u32 pref_lifetime = 0;
4808 /* Parse args required to build the message */
4809 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
4810 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
4811 sw_if_index_set = 1;
4812 else if (unformat (i, "sw_if_index %d", &sw_if_index))
4813 sw_if_index_set = 1;
4814 else if (unformat (i, "%U/%d",
4815 unformat_ip6_address, &v6address,
4818 else if (unformat (i, "val_life %d", &val_lifetime))
4820 else if (unformat (i, "pref_life %d", &pref_lifetime))
4822 else if (unformat (i, "def"))
4824 else if (unformat (i, "noadv"))
4826 else if (unformat (i, "offl"))
4828 else if (unformat (i, "noauto"))
4830 else if (unformat (i, "nolink"))
4832 else if (unformat (i, "isno"))
4835 clib_warning ("parse error '%U'", format_unformat_error, i);
4840 if (sw_if_index_set == 0) {
4841 errmsg ("missing interface name or sw_if_index\n");
4844 if (!v6_address_set) {
4845 errmsg ("no address set\n");
4849 /* Construct the API message */
4850 M(SW_INTERFACE_IP6ND_RA_PREFIX, sw_interface_ip6nd_ra_prefix);
4852 mp->sw_if_index = ntohl (sw_if_index);
4853 memcpy (mp->address, &v6address, sizeof (v6address));
4854 mp->address_length = address_length;
4855 mp->use_default = use_default;
4856 mp->no_advertise = no_advertise;
4857 mp->off_link = off_link;
4858 mp->no_autoconfig = no_autoconfig;
4859 mp->no_onlink = no_onlink;
4861 mp->val_lifetime = ntohl(val_lifetime);
4862 mp->pref_lifetime = ntohl(pref_lifetime);
4867 /* Wait for a reply, return good/bad news */
4874 static int api_sw_interface_ip6nd_ra_config (vat_main_t * vam)
4876 unformat_input_t * i = vam->input;
4877 vl_api_sw_interface_ip6nd_ra_config_t *mp;
4880 u8 sw_if_index_set = 0;
4885 u8 send_unicast = 0;
4888 u8 default_router = 0;
4889 u32 max_interval = 0;
4890 u32 min_interval = 0;
4892 u32 initial_count = 0;
4893 u32 initial_interval = 0;
4896 /* Parse args required to build the message */
4897 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
4898 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
4899 sw_if_index_set = 1;
4900 else if (unformat (i, "sw_if_index %d", &sw_if_index))
4901 sw_if_index_set = 1;
4902 else if (unformat (i, "maxint %d", &max_interval))
4904 else if (unformat (i, "minint %d", &min_interval))
4906 else if (unformat (i, "life %d", &lifetime))
4908 else if (unformat (i, "count %d", &initial_count))
4910 else if (unformat (i, "interval %d", &initial_interval))
4912 else if (unformat (i, "surpress"))
4914 else if (unformat (i, "managed"))
4916 else if (unformat (i, "other"))
4918 else if (unformat (i, "ll"))
4920 else if (unformat (i, "send"))
4922 else if (unformat (i, "cease"))
4924 else if (unformat (i, "isno"))
4926 else if (unformat (i, "def"))
4929 clib_warning ("parse error '%U'", format_unformat_error, i);
4934 if (sw_if_index_set == 0) {
4935 errmsg ("missing interface name or sw_if_index\n");
4939 /* Construct the API message */
4940 M(SW_INTERFACE_IP6ND_RA_CONFIG, sw_interface_ip6nd_ra_config);
4942 mp->sw_if_index = ntohl (sw_if_index);
4943 mp->max_interval = ntohl(max_interval);
4944 mp->min_interval = ntohl(min_interval);
4945 mp->lifetime = ntohl(lifetime);
4946 mp->initial_count = ntohl(initial_count);
4947 mp->initial_interval = ntohl(initial_interval);
4948 mp->surpress = surpress;
4949 mp->managed = managed;
4951 mp->ll_option = ll_option;
4952 mp->send_unicast = send_unicast;
4955 mp->default_router = default_router;
4960 /* Wait for a reply, return good/bad news */
4967 static int api_set_arp_neighbor_limit (vat_main_t * vam)
4969 unformat_input_t * i = vam->input;
4970 vl_api_set_arp_neighbor_limit_t *mp;
4976 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
4977 if (unformat (i, "arp_nbr_limit %d", &arp_nbr_limit))
4979 else if (unformat (i, "ipv6"))
4982 clib_warning ("parse error '%U'", format_unformat_error, i);
4987 if (limit_set == 0) {
4988 errmsg ("missing limit value\n");
4992 M(SET_ARP_NEIGHBOR_LIMIT, set_arp_neighbor_limit);
4994 mp->arp_neighbor_limit = ntohl(arp_nbr_limit);
4995 mp->is_ipv6 = is_ipv6;
5002 static int api_l2_patch_add_del (vat_main_t * vam)
5004 unformat_input_t * i = vam->input;
5005 vl_api_l2_patch_add_del_t *mp;
5008 u8 rx_sw_if_index_set = 0;
5010 u8 tx_sw_if_index_set = 0;
5013 /* Parse args required to build the message */
5014 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
5015 if (unformat (i, "rx_sw_if_index %d", &rx_sw_if_index))
5016 rx_sw_if_index_set = 1;
5017 else if (unformat (i, "tx_sw_if_index %d", &tx_sw_if_index))
5018 tx_sw_if_index_set = 1;
5019 else if (unformat (i, "rx")) {
5020 if (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
5021 if (unformat (i, "%U", unformat_sw_if_index, vam,
5023 rx_sw_if_index_set = 1;
5026 } else if (unformat (i, "tx")) {
5027 if (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
5028 if (unformat (i, "%U", unformat_sw_if_index, vam,
5030 tx_sw_if_index_set = 1;
5033 } else if (unformat (i, "del"))
5039 if (rx_sw_if_index_set == 0) {
5040 errmsg ("missing rx interface name or rx_sw_if_index\n");
5044 if (tx_sw_if_index_set == 0) {
5045 errmsg ("missing tx interface name or tx_sw_if_index\n");
5049 M(L2_PATCH_ADD_DEL, l2_patch_add_del);
5051 mp->rx_sw_if_index = ntohl(rx_sw_if_index);
5052 mp->tx_sw_if_index = ntohl(tx_sw_if_index);
5053 mp->is_add = is_add;
5060 static int api_sr_tunnel_add_del (vat_main_t * vam)
5062 unformat_input_t * i = vam->input;
5063 vl_api_sr_tunnel_add_del_t *mp;
5067 ip6_address_t src_address;
5068 int src_address_set = 0;
5069 ip6_address_t dst_address;
5071 int dst_address_set = 0;
5073 u32 rx_table_id = 0;
5074 u32 tx_table_id = 0;
5075 ip6_address_t * segments = 0;
5076 ip6_address_t * this_seg;
5077 ip6_address_t * tags = 0;
5078 ip6_address_t * this_tag;
5079 ip6_address_t next_address, tag;
5081 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
5083 if (unformat (i, "del"))
5085 else if (unformat (i, "rx_fib_id %d", &rx_table_id))
5087 else if (unformat (i, "tx_fib_id %d", &tx_table_id))
5089 else if (unformat (i, "src %U", unformat_ip6_address, &src_address))
5090 src_address_set = 1;
5091 else if (unformat (i, "dst %U/%d",
5092 unformat_ip6_address, &dst_address,
5094 dst_address_set = 1;
5095 else if (unformat (i, "next %U", unformat_ip6_address,
5098 vec_add2 (segments, this_seg, 1);
5099 memcpy (this_seg->as_u8, next_address.as_u8, sizeof (*this_seg));
5101 else if (unformat (i, "tag %U", unformat_ip6_address,
5104 vec_add2 (tags, this_tag, 1);
5105 memcpy (this_tag->as_u8, tag.as_u8, sizeof (*this_tag));
5107 else if (unformat (i, "clean"))
5108 flags |= IP6_SR_HEADER_FLAG_CLEANUP;
5109 else if (unformat (i, "protected"))
5110 flags |= IP6_SR_HEADER_FLAG_PROTECTED;
5111 else if (unformat (i, "InPE %d", &pl_index))
5113 if (pl_index <= 0 || pl_index > 4)
5115 pl_index_range_error:
5116 errmsg ("pl index %d out of range\n", pl_index);
5119 flags |= IP6_SR_HEADER_FLAG_PL_ELT_INGRESS_PE << (3*(pl_index - 1));
5121 else if (unformat (i, "EgPE %d", &pl_index))
5123 if (pl_index <= 0 || pl_index > 4)
5124 goto pl_index_range_error;
5125 flags |= IP6_SR_HEADER_FLAG_PL_ELT_EGRESS_PE << (3*(pl_index - 1));
5127 else if (unformat (i, "OrgSrc %d", &pl_index))
5129 if (pl_index <= 0 || pl_index > 4)
5130 goto pl_index_range_error;
5131 flags |= IP6_SR_HEADER_FLAG_PL_ELT_ORIG_SRC_ADDR << (3*(pl_index - 1));
5137 if (!src_address_set)
5139 errmsg ("src address required\n");
5143 if (!dst_address_set)
5145 errmsg ("dst address required\n");
5151 errmsg ("at least one sr segment required\n");
5155 M2(SR_TUNNEL_ADD_DEL, sr_tunnel_add_del,
5156 vec_len(segments) * sizeof (ip6_address_t)
5157 + vec_len(tags) * sizeof (ip6_address_t));
5159 memcpy (mp->src_address, &src_address, sizeof (mp->src_address));
5160 memcpy (mp->dst_address, &dst_address, sizeof (mp->dst_address));
5161 mp->dst_mask_width = dst_mask_width;
5162 mp->flags_net_byte_order = clib_host_to_net_u16 (flags);
5163 mp->n_segments = vec_len (segments);
5164 mp->n_tags = vec_len (tags);
5165 mp->is_add = is_del == 0;
5166 memcpy (mp->segs_and_tags, segments,
5167 vec_len(segments)* sizeof (ip6_address_t));
5168 memcpy (mp->segs_and_tags + vec_len(segments)*sizeof (ip6_address_t),
5169 tags, vec_len(tags)* sizeof (ip6_address_t));
5171 mp->outer_vrf_id = ntohl (rx_table_id);
5172 mp->inner_vrf_id = ntohl (tx_table_id);
5174 vec_free (segments);
5182 #define foreach_ip4_proto_field \
5192 uword unformat_ip4_mask (unformat_input_t * input, va_list * args)
5194 u8 ** maskp = va_arg (*args, u8 **);
5196 u8 found_something = 0;
5199 #define _(a) u8 a=0;
5200 foreach_ip4_proto_field;
5206 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
5208 if (unformat (input, "version"))
5210 else if (unformat (input, "hdr_length"))
5212 else if (unformat (input, "src"))
5214 else if (unformat (input, "dst"))
5216 else if (unformat (input, "proto"))
5219 #define _(a) else if (unformat (input, #a)) a=1;
5220 foreach_ip4_proto_field
5226 #define _(a) found_something += a;
5227 foreach_ip4_proto_field;
5230 if (found_something == 0)
5233 vec_validate (mask, sizeof (*ip) - 1);
5235 ip = (ip4_header_t *) mask;
5237 #define _(a) if (a) memset (&ip->a, 0xff, sizeof (ip->a));
5238 foreach_ip4_proto_field;
5241 ip->ip_version_and_header_length = 0;
5244 ip->ip_version_and_header_length |= 0xF0;
5247 ip->ip_version_and_header_length |= 0x0F;
5253 #define foreach_ip6_proto_field \
5260 uword unformat_ip6_mask (unformat_input_t * input, va_list * args)
5262 u8 ** maskp = va_arg (*args, u8 **);
5264 u8 found_something = 0;
5266 u32 ip_version_traffic_class_and_flow_label;
5268 #define _(a) u8 a=0;
5269 foreach_ip6_proto_field;
5272 u8 traffic_class = 0;
5275 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
5277 if (unformat (input, "version"))
5279 else if (unformat (input, "traffic-class"))
5281 else if (unformat (input, "flow-label"))
5283 else if (unformat (input, "src"))
5285 else if (unformat (input, "dst"))
5287 else if (unformat (input, "proto"))
5290 #define _(a) else if (unformat (input, #a)) a=1;
5291 foreach_ip6_proto_field
5297 #define _(a) found_something += a;
5298 foreach_ip6_proto_field;
5301 if (found_something == 0)
5304 vec_validate (mask, sizeof (*ip) - 1);
5306 ip = (ip6_header_t *) mask;
5308 #define _(a) if (a) memset (&ip->a, 0xff, sizeof (ip->a));
5309 foreach_ip6_proto_field;
5312 ip_version_traffic_class_and_flow_label = 0;
5315 ip_version_traffic_class_and_flow_label |= 0xF0000000;
5318 ip_version_traffic_class_and_flow_label |= 0x0FF00000;
5321 ip_version_traffic_class_and_flow_label |= 0x000FFFFF;
5323 ip->ip_version_traffic_class_and_flow_label =
5324 clib_host_to_net_u32 (ip_version_traffic_class_and_flow_label);
5330 uword unformat_l3_mask (unformat_input_t * input, va_list * args)
5332 u8 ** maskp = va_arg (*args, u8 **);
5334 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) {
5335 if (unformat (input, "ip4 %U", unformat_ip4_mask, maskp))
5337 else if (unformat (input, "ip6 %U", unformat_ip6_mask, maskp))
5345 uword unformat_l2_mask (unformat_input_t * input, va_list * args)
5347 u8 ** maskp = va_arg (*args, u8 **);
5362 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) {
5363 if (unformat (input, "src"))
5365 else if (unformat (input, "dst"))
5367 else if (unformat (input, "proto"))
5369 else if (unformat (input, "tag1"))
5371 else if (unformat (input, "tag2"))
5373 else if (unformat (input, "ignore-tag1"))
5375 else if (unformat (input, "ignore-tag2"))
5377 else if (unformat (input, "cos1"))
5379 else if (unformat (input, "cos2"))
5381 else if (unformat (input, "dot1q"))
5383 else if (unformat (input, "dot1ad"))
5388 if ((src + dst + proto + tag1 + tag2 + dot1q + dot1ad +
5389 ignore_tag1 + ignore_tag2 + cos1 + cos2) == 0)
5392 if (tag1 || ignore_tag1 || cos1 || dot1q)
5394 if (tag2 || ignore_tag2 || cos2 || dot1ad)
5397 vec_validate (mask, len-1);
5400 memset (mask, 0xff, 6);
5403 memset (mask + 6, 0xff, 6);
5407 /* inner vlan tag */
5416 mask[21] = mask [20] = 0xff;
5437 mask[16] = mask [17] = 0xff;
5447 mask[12] = mask [13] = 0xff;
5453 uword unformat_classify_mask (unformat_input_t * input, va_list * args)
5455 u8 ** maskp = va_arg (*args, u8 **);
5456 u32 * skipp = va_arg (*args, u32 *);
5457 u32 * matchp = va_arg (*args, u32 *);
5464 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) {
5465 if (unformat (input, "hex %U", unformat_hex_string, &mask))
5467 else if (unformat (input, "l2 %U", unformat_l2_mask, &l2))
5469 else if (unformat (input, "l3 %U", unformat_l3_mask, &l3))
5475 if (mask || l2 || l3)
5479 /* "With a free Ethernet header in every package" */
5481 vec_validate (l2, 13);
5483 vec_append (mask, l3);
5487 /* Scan forward looking for the first significant mask octet */
5488 for (i = 0; i < vec_len (mask); i++)
5492 /* compute (skip, match) params */
5493 *skipp = i / sizeof(u32x4);
5494 vec_delete (mask, *skipp * sizeof(u32x4), 0);
5496 /* Pad mask to an even multiple of the vector size */
5497 while (vec_len (mask) % sizeof (u32x4))
5500 match = vec_len (mask) / sizeof (u32x4);
5502 for (i = match*sizeof(u32x4); i > 0; i-= sizeof(u32x4))
5504 u64 *tmp = (u64 *)(mask + (i-sizeof(u32x4)));
5505 if (*tmp || *(tmp+1))
5510 clib_warning ("BUG: match 0");
5512 _vec_len (mask) = match * sizeof(u32x4);
5523 #define foreach_l2_next \
5525 _(ethernet, ETHERNET_INPUT) \
5529 uword unformat_l2_next_index (unformat_input_t * input, va_list * args)
5531 u32 * miss_next_indexp = va_arg (*args, u32 *);
5536 if (unformat (input, #n)) { next_index = L2_CLASSIFY_NEXT_##N; goto out;}
5540 if (unformat (input, "%d", &tmp))
5549 *miss_next_indexp = next_index;
5553 #define foreach_ip_next \
5559 uword unformat_ip_next_index (unformat_input_t * input, va_list * args)
5561 u32 * miss_next_indexp = va_arg (*args, u32 *);
5566 if (unformat (input, #n)) { next_index = IP_LOOKUP_NEXT_##N; goto out;}
5570 if (unformat (input, "%d", &tmp))
5579 *miss_next_indexp = next_index;
5583 #define foreach_acl_next \
5586 uword unformat_acl_next_index (unformat_input_t * input, va_list * args)
5588 u32 * miss_next_indexp = va_arg (*args, u32 *);
5593 if (unformat (input, #n)) { next_index = ACL_NEXT_INDEX_##N; goto out;}
5597 if (unformat (input, "permit"))
5602 else if (unformat (input, "%d", &tmp))
5611 *miss_next_indexp = next_index;
5615 static int api_classify_add_del_table (vat_main_t * vam)
5617 unformat_input_t * i = vam->input;
5618 vl_api_classify_add_del_table_t *mp;
5624 u32 table_index = ~0;
5625 u32 next_table_index = ~0;
5626 u32 miss_next_index = ~0;
5627 u32 memory_size = 32<<20;
5631 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
5632 if (unformat (i, "del"))
5634 else if (unformat (i, "buckets %d", &nbuckets))
5636 else if (unformat (i, "memory_size %d", &memory_size))
5638 else if (unformat (i, "skip %d", &skip))
5640 else if (unformat (i, "match %d", &match))
5642 else if (unformat (i, "table %d", &table_index))
5644 else if (unformat (i, "mask %U", unformat_classify_mask,
5645 &mask, &skip, &match))
5647 else if (unformat (i, "next-table %d", &next_table_index))
5649 else if (unformat (i, "miss-next %U", unformat_ip_next_index,
5652 else if (unformat (i, "l2-miss-next %U", unformat_l2_next_index,
5655 else if (unformat (i, "acl-miss-next %U", unformat_acl_next_index,
5662 if (is_add && mask == 0) {
5663 errmsg ("Mask required\n");
5667 if (is_add && skip == ~0) {
5668 errmsg ("skip count required\n");
5672 if (is_add && match == ~0) {
5673 errmsg ("match count required\n");
5677 if (!is_add && table_index == ~0) {
5678 errmsg ("table index required for delete\n");
5682 M2 (CLASSIFY_ADD_DEL_TABLE, classify_add_del_table,
5685 mp->is_add = is_add;
5686 mp->table_index = ntohl(table_index);
5687 mp->nbuckets = ntohl(nbuckets);
5688 mp->memory_size = ntohl(memory_size);
5689 mp->skip_n_vectors = ntohl(skip);
5690 mp->match_n_vectors = ntohl(match);
5691 mp->next_table_index = ntohl(next_table_index);
5692 mp->miss_next_index = ntohl(miss_next_index);
5693 memcpy (mp->mask, mask, vec_len(mask));
5701 uword unformat_ip4_match (unformat_input_t * input, va_list * args)
5703 u8 ** matchp = va_arg (*args, u8 **);
5710 int src = 0, dst = 0;
5711 ip4_address_t src_val, dst_val;
5718 int fragment_id = 0;
5719 u32 fragment_id_val;
5725 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
5727 if (unformat (input, "version %d", &version_val))
5729 else if (unformat (input, "hdr_length %d", &hdr_length_val))
5731 else if (unformat (input, "src %U", unformat_ip4_address, &src_val))
5733 else if (unformat (input, "dst %U", unformat_ip4_address, &dst_val))
5735 else if (unformat (input, "proto %d", &proto_val))
5737 else if (unformat (input, "tos %d", &tos_val))
5739 else if (unformat (input, "length %d", &length_val))
5741 else if (unformat (input, "fragment_id %d", &fragment_id_val))
5743 else if (unformat (input, "ttl %d", &ttl_val))
5745 else if (unformat (input, "checksum %d", &checksum_val))
5751 if (version + hdr_length + src + dst + proto + tos + length + fragment_id
5752 + ttl + checksum == 0)
5756 * Aligned because we use the real comparison functions
5758 vec_validate_aligned (match, sizeof (*ip) - 1, sizeof(u32x4));
5760 ip = (ip4_header_t *) match;
5762 /* These are realistically matched in practice */
5764 ip->src_address.as_u32 = src_val.as_u32;
5767 ip->dst_address.as_u32 = dst_val.as_u32;
5770 ip->protocol = proto_val;
5773 /* These are not, but they're included for completeness */
5775 ip->ip_version_and_header_length |= (version_val & 0xF)<<4;
5778 ip->ip_version_and_header_length |= (hdr_length_val & 0xF);
5784 ip->length = length_val;
5790 ip->checksum = checksum_val;
5796 uword unformat_ip6_match (unformat_input_t * input, va_list * args)
5798 u8 ** matchp = va_arg (*args, u8 **);
5804 u32 traffic_class_val;
5807 int src = 0, dst = 0;
5808 ip6_address_t src_val, dst_val;
5811 int payload_length = 0;
5812 u32 payload_length_val;
5815 u32 ip_version_traffic_class_and_flow_label;
5817 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
5819 if (unformat (input, "version %d", &version_val))
5821 else if (unformat (input, "traffic_class %d", &traffic_class_val))
5823 else if (unformat (input, "flow_label %d", &flow_label_val))
5825 else if (unformat (input, "src %U", unformat_ip6_address, &src_val))
5827 else if (unformat (input, "dst %U", unformat_ip6_address, &dst_val))
5829 else if (unformat (input, "proto %d", &proto_val))
5831 else if (unformat (input, "payload_length %d", &payload_length_val))
5833 else if (unformat (input, "hop_limit %d", &hop_limit_val))
5839 if (version + traffic_class + flow_label + src + dst + proto +
5840 payload_length + hop_limit == 0)
5844 * Aligned because we use the real comparison functions
5846 vec_validate_aligned (match, sizeof (*ip) - 1, sizeof(u32x4));
5848 ip = (ip6_header_t *) match;
5851 memcpy (&ip->src_address, &src_val, sizeof (ip->src_address));
5854 memcpy (&ip->dst_address, &dst_val, sizeof (ip->dst_address));
5857 ip->protocol = proto_val;
5859 ip_version_traffic_class_and_flow_label = 0;
5862 ip_version_traffic_class_and_flow_label |= (version_val & 0xF) << 28;
5865 ip_version_traffic_class_and_flow_label |= (traffic_class_val & 0xFF) << 20;
5868 ip_version_traffic_class_and_flow_label |= (flow_label_val & 0xFFFFF);
5870 ip->ip_version_traffic_class_and_flow_label =
5871 clib_host_to_net_u32 (ip_version_traffic_class_and_flow_label);
5874 ip->payload_length = clib_host_to_net_u16 (payload_length_val);
5877 ip->hop_limit = hop_limit_val;
5883 uword unformat_l3_match (unformat_input_t * input, va_list * args)
5885 u8 ** matchp = va_arg (*args, u8 **);
5887 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) {
5888 if (unformat (input, "ip4 %U", unformat_ip4_match, matchp))
5890 else if (unformat (input, "ip6 %U", unformat_ip6_match, matchp))
5898 uword unformat_vlan_tag (unformat_input_t * input, va_list * args)
5900 u8 * tagp = va_arg (*args, u8 *);
5903 if (unformat(input, "%d", &tag))
5905 tagp[0] = (tag>>8) & 0x0F;
5906 tagp[1] = tag & 0xFF;
5913 uword unformat_l2_match (unformat_input_t * input, va_list * args)
5915 u8 ** matchp = va_arg (*args, u8 **);
5935 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) {
5936 if (unformat (input, "src %U", unformat_ethernet_address, &src_val))
5938 else if (unformat (input, "dst %U", unformat_ethernet_address, &dst_val))
5940 else if (unformat (input, "proto %U",
5941 unformat_ethernet_type_host_byte_order, &proto_val))
5943 else if (unformat (input, "tag1 %U", unformat_vlan_tag, tag1_val))
5945 else if (unformat (input, "tag2 %U", unformat_vlan_tag, tag2_val))
5947 else if (unformat (input, "ignore-tag1"))
5949 else if (unformat (input, "ignore-tag2"))
5951 else if (unformat (input, "cos1 %d", &cos1_val))
5953 else if (unformat (input, "cos2 %d", &cos2_val))
5958 if ((src + dst + proto + tag1 + tag2 +
5959 ignore_tag1 + ignore_tag2 + cos1 + cos2) == 0)
5962 if (tag1 || ignore_tag1 || cos1)
5964 if (tag2 || ignore_tag2 || cos2)
5967 vec_validate_aligned (match, len-1, sizeof(u32x4));
5970 memcpy (match, dst_val, 6);
5973 memcpy (match + 6, src_val, 6);
5977 /* inner vlan tag */
5978 match[19] = tag2_val[1];
5979 match[18] = tag2_val[0];
5981 match [18] |= (cos2_val & 0x7) << 5;
5984 match[21] = proto_val & 0xff;
5985 match[20] = proto_val >> 8;
5989 match [15] = tag1_val[1];
5990 match [14] = tag1_val[0];
5993 match [14] |= (cos1_val & 0x7) << 5;
5999 match [15] = tag1_val[1];
6000 match [14] = tag1_val[0];
6003 match[17] = proto_val & 0xff;
6004 match[16] = proto_val >> 8;
6007 match [14] |= (cos1_val & 0x7) << 5;
6013 match [18] |= (cos2_val & 0x7) << 5;
6015 match [14] |= (cos1_val & 0x7) << 5;
6018 match[13] = proto_val & 0xff;
6019 match[12] = proto_val >> 8;
6027 uword unformat_classify_match (unformat_input_t * input, va_list * args)
6029 u8 ** matchp = va_arg (*args, u8 **);
6030 u32 skip_n_vectors = va_arg (*args, u32);
6031 u32 match_n_vectors = va_arg (*args, u32);
6037 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) {
6038 if (unformat (input, "hex %U", unformat_hex_string, &match))
6040 else if (unformat (input, "l2 %U", unformat_l2_match, &l2))
6042 else if (unformat (input, "l3 %U", unformat_l3_match, &l3))
6048 if (match || l2 || l3)
6052 /* "Win a free Ethernet header in every packet" */
6054 vec_validate_aligned (l2, 13, sizeof(u32x4));
6056 vec_append_aligned (match, l3, sizeof(u32x4));
6060 /* Make sure the vector is big enough even if key is all 0's */
6061 vec_validate_aligned
6062 (match, ((match_n_vectors + skip_n_vectors) * sizeof(u32x4)) - 1,
6065 /* Set size, include skipped vectors*/
6066 _vec_len (match) = (match_n_vectors+skip_n_vectors) * sizeof(u32x4);
6076 static int api_classify_add_del_session (vat_main_t * vam)
6078 unformat_input_t * i = vam->input;
6079 vl_api_classify_add_del_session_t *mp;
6081 u32 table_index = ~0;
6082 u32 hit_next_index = ~0;
6083 u32 opaque_index = ~0;
6087 u32 skip_n_vectors = 0;
6088 u32 match_n_vectors = 0;
6091 * Warning: you have to supply skip_n and match_n
6092 * because the API client cant simply look at the classify
6096 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
6097 if (unformat (i, "del"))
6099 else if (unformat (i, "hit-next %U", unformat_ip_next_index,
6102 else if (unformat (i, "l2-hit-next %U", unformat_l2_next_index,
6105 else if (unformat (i, "acl-hit-next %U", unformat_acl_next_index,
6108 else if (unformat (i, "opaque-index %d", &opaque_index))
6110 else if (unformat (i, "skip_n %d", &skip_n_vectors))
6112 else if (unformat (i, "match_n %d", &match_n_vectors))
6114 else if (unformat (i, "match %U", unformat_classify_match,
6115 &match, skip_n_vectors, match_n_vectors))
6117 else if (unformat (i, "advance %d", &advance))
6119 else if (unformat (i, "table-index %d", &table_index))
6125 if (table_index == ~0) {
6126 errmsg ("Table index required\n");
6130 if (is_add && match == 0) {
6131 errmsg ("Match value required\n");
6135 M2 (CLASSIFY_ADD_DEL_SESSION, classify_add_del_session,
6138 mp->is_add = is_add;
6139 mp->table_index = ntohl(table_index);
6140 mp->hit_next_index = ntohl(hit_next_index);
6141 mp->opaque_index = ntohl(opaque_index);
6142 mp->advance = ntohl(advance);
6143 memcpy (mp->match, match, vec_len(match));
6150 static int api_classify_set_interface_ip_table (vat_main_t * vam)
6152 unformat_input_t * i = vam->input;
6153 vl_api_classify_set_interface_ip_table_t *mp;
6156 int sw_if_index_set;
6157 u32 table_index = ~0;
6160 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
6161 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
6162 sw_if_index_set = 1;
6163 else if (unformat (i, "sw_if_index %d", &sw_if_index))
6164 sw_if_index_set = 1;
6165 else if (unformat (i, "table %d", &table_index))
6168 clib_warning ("parse error '%U'", format_unformat_error, i);
6173 if (sw_if_index_set == 0) {
6174 errmsg ("missing interface name or sw_if_index\n");
6179 M(CLASSIFY_SET_INTERFACE_IP_TABLE, classify_set_interface_ip_table);
6181 mp->sw_if_index = ntohl(sw_if_index);
6182 mp->table_index = ntohl(table_index);
6183 mp->is_ipv6 = is_ipv6;
6190 static int api_classify_set_interface_l2_tables (vat_main_t * vam)
6192 unformat_input_t * i = vam->input;
6193 vl_api_classify_set_interface_l2_tables_t *mp;
6196 int sw_if_index_set;
6197 u32 ip4_table_index = ~0;
6198 u32 ip6_table_index = ~0;
6199 u32 other_table_index = ~0;
6201 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
6202 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
6203 sw_if_index_set = 1;
6204 else if (unformat (i, "sw_if_index %d", &sw_if_index))
6205 sw_if_index_set = 1;
6206 else if (unformat (i, "ip4-table %d", &ip4_table_index))
6208 else if (unformat (i, "ip6-table %d", &ip6_table_index))
6210 else if (unformat (i, "other-table %d", &other_table_index))
6213 clib_warning ("parse error '%U'", format_unformat_error, i);
6218 if (sw_if_index_set == 0) {
6219 errmsg ("missing interface name or sw_if_index\n");
6224 M(CLASSIFY_SET_INTERFACE_L2_TABLES, classify_set_interface_l2_tables);
6226 mp->sw_if_index = ntohl(sw_if_index);
6227 mp->ip4_table_index = ntohl(ip4_table_index);
6228 mp->ip6_table_index = ntohl(ip6_table_index);
6229 mp->other_table_index = ntohl(other_table_index);
6237 static int api_get_node_index (vat_main_t * vam)
6239 unformat_input_t * i = vam->input;
6240 vl_api_get_node_index_t * mp;
6244 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
6245 if (unformat (i, "node %s", &name))
6251 errmsg ("node name required\n");
6254 if (vec_len (name) >= ARRAY_LEN(mp->node_name)) {
6255 errmsg ("node name too long, max %d\n", ARRAY_LEN(mp->node_name));
6259 M(GET_NODE_INDEX, get_node_index);
6260 memcpy (mp->node_name, name, vec_len(name));
6268 static int api_add_node_next (vat_main_t * vam)
6270 unformat_input_t * i = vam->input;
6271 vl_api_add_node_next_t * mp;
6276 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
6277 if (unformat (i, "node %s", &name))
6279 else if (unformat (i, "next %s", &next))
6285 errmsg ("node name required\n");
6288 if (vec_len (name) >= ARRAY_LEN(mp->node_name)) {
6289 errmsg ("node name too long, max %d\n", ARRAY_LEN(mp->node_name));
6293 errmsg ("next node required\n");
6296 if (vec_len (next) >= ARRAY_LEN(mp->next_name)) {
6297 errmsg ("next name too long, max %d\n", ARRAY_LEN(mp->next_name));
6301 M(ADD_NODE_NEXT, add_node_next);
6302 memcpy (mp->node_name, name, vec_len(name));
6303 memcpy (mp->next_name, next, vec_len(next));
6312 static int api_l2tpv3_create_tunnel (vat_main_t * vam)
6314 unformat_input_t * i = vam->input;
6315 ip6_address_t client_address, our_address;
6316 int client_address_set = 0;
6317 int our_address_set = 0;
6318 u32 local_session_id = 0;
6319 u32 remote_session_id = 0;
6320 u64 local_cookie = 0;
6321 u64 remote_cookie = 0;
6322 u8 l2_sublayer_present = 0;
6323 vl_api_l2tpv3_create_tunnel_t * mp;
6326 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
6327 if (unformat (i, "client_address %U", unformat_ip6_address,
6329 client_address_set = 1;
6330 else if (unformat (i, "our_address %U", unformat_ip6_address,
6332 our_address_set = 1;
6333 else if (unformat (i, "local_session_id %d", &local_session_id))
6335 else if (unformat (i, "remote_session_id %d", &remote_session_id))
6337 else if (unformat (i, "local_cookie %lld", &local_cookie))
6339 else if (unformat (i, "remote_cookie %lld", &remote_cookie))
6341 else if (unformat (i, "l2-sublayer-present"))
6342 l2_sublayer_present = 1;
6347 if (client_address_set == 0) {
6348 errmsg ("client_address required\n");
6352 if (our_address_set == 0) {
6353 errmsg ("our_address required\n");
6357 M(L2TPV3_CREATE_TUNNEL, l2tpv3_create_tunnel);
6359 memcpy (mp->client_address, client_address.as_u8,
6360 sizeof (mp->client_address));
6362 memcpy (mp->our_address, our_address.as_u8,
6363 sizeof (mp->our_address));
6365 mp->local_session_id = ntohl (local_session_id);
6366 mp->remote_session_id = ntohl (remote_session_id);
6367 mp->local_cookie = clib_host_to_net_u64 (local_cookie);
6368 mp->remote_cookie = clib_host_to_net_u64 (remote_cookie);
6369 mp->l2_sublayer_present = l2_sublayer_present;
6377 static int api_l2tpv3_set_tunnel_cookies (vat_main_t * vam)
6379 unformat_input_t * i = vam->input;
6381 u8 sw_if_index_set = 0;
6382 u64 new_local_cookie = 0;
6383 u64 new_remote_cookie = 0;
6384 vl_api_l2tpv3_set_tunnel_cookies_t *mp;
6387 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
6388 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
6389 sw_if_index_set = 1;
6390 else if (unformat (i, "sw_if_index %d", &sw_if_index))
6391 sw_if_index_set = 1;
6392 else if (unformat (i, "new_local_cookie %lld", &new_local_cookie))
6394 else if (unformat (i, "new_remote_cookie %lld", &new_remote_cookie))
6400 if (sw_if_index_set == 0) {
6401 errmsg ("missing interface name or sw_if_index\n");
6405 M(L2TPV3_SET_TUNNEL_COOKIES, l2tpv3_set_tunnel_cookies);
6407 mp->sw_if_index = ntohl(sw_if_index);
6408 mp->new_local_cookie = clib_host_to_net_u64 (new_local_cookie);
6409 mp->new_remote_cookie = clib_host_to_net_u64 (new_remote_cookie);
6416 static int api_l2tpv3_interface_enable_disable (vat_main_t * vam)
6418 unformat_input_t * i = vam->input;
6419 vl_api_l2tpv3_interface_enable_disable_t *mp;
6422 u8 sw_if_index_set = 0;
6423 u8 enable_disable = 1;
6425 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
6426 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
6427 sw_if_index_set = 1;
6428 else if (unformat (i, "sw_if_index %d", &sw_if_index))
6429 sw_if_index_set = 1;
6430 else if (unformat (i, "enable"))
6432 else if (unformat (i, "disable"))
6438 if (sw_if_index_set == 0) {
6439 errmsg ("missing interface name or sw_if_index\n");
6443 M(L2TPV3_INTERFACE_ENABLE_DISABLE, l2tpv3_interface_enable_disable);
6445 mp->sw_if_index = ntohl(sw_if_index);
6446 mp->enable_disable = enable_disable;
6453 static int api_l2tpv3_set_lookup_key (vat_main_t * vam)
6455 unformat_input_t * i = vam->input;
6456 vl_api_l2tpv3_set_lookup_key_t * mp;
6460 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
6461 if (unformat (i, "lookup_v6_src"))
6462 key = L2T_LOOKUP_SRC_ADDRESS;
6463 else if (unformat (i, "lookup_v6_dst"))
6464 key = L2T_LOOKUP_DST_ADDRESS;
6465 else if (unformat (i, "lookup_session_id"))
6466 key = L2T_LOOKUP_SESSION_ID;
6472 errmsg ("l2tp session lookup key unset\n");
6476 M(L2TPV3_SET_LOOKUP_KEY, l2tpv3_set_lookup_key);
6485 static void vl_api_sw_if_l2tpv3_tunnel_details_t_handler
6486 (vl_api_sw_if_l2tpv3_tunnel_details_t * mp)
6488 vat_main_t * vam = &vat_main;
6490 fformat(vam->ofp, "* %U (our) %U (client) (sw_if_index %d)\n",
6491 format_ip6_address, mp->our_address,
6492 format_ip6_address, mp->client_address,
6493 clib_net_to_host_u32(mp->sw_if_index));
6495 fformat (vam->ofp, " local cookies %016llx %016llx remote cookie %016llx\n",
6496 clib_net_to_host_u64 (mp->local_cookie[0]),
6497 clib_net_to_host_u64 (mp->local_cookie[1]),
6498 clib_net_to_host_u64 (mp->remote_cookie));
6500 fformat (vam->ofp, " local session-id %d remote session-id %d\n",
6501 clib_net_to_host_u32 (mp->local_session_id),
6502 clib_net_to_host_u32 (mp->remote_session_id));
6504 fformat (vam->ofp, " l2 specific sublayer %s\n\n",
6505 mp->l2_sublayer_present ? "preset" : "absent");
6509 static void vl_api_sw_if_l2tpv3_tunnel_details_t_handler_json
6510 (vl_api_sw_if_l2tpv3_tunnel_details_t * mp)
6512 vat_main_t * vam = &vat_main;
6513 vat_json_node_t *node = NULL;
6514 struct in6_addr addr;
6516 if (VAT_JSON_ARRAY != vam->json_tree.type) {
6517 ASSERT(VAT_JSON_NONE == vam->json_tree.type);
6518 vat_json_init_array(&vam->json_tree);
6520 node = vat_json_array_add(&vam->json_tree);
6522 vat_json_init_object(node);
6524 memcpy(&addr, mp->our_address, sizeof(addr));
6525 vat_json_object_add_ip6(node, "our_address", addr);
6526 memcpy(&addr, mp->client_address, sizeof(addr));
6527 vat_json_object_add_ip6(node, "client_address", addr);
6529 vat_json_node_t * lc = vat_json_object_add(node, "local_cookie");
6530 vat_json_init_array(lc);
6531 vat_json_array_add_uint(lc, clib_net_to_host_u64(mp->local_cookie[0]));
6532 vat_json_array_add_uint(lc, clib_net_to_host_u64(mp->local_cookie[1]));
6533 vat_json_object_add_uint(node, "remote_cookie", clib_net_to_host_u64(mp->remote_cookie));
6535 printf("local id: %u", clib_net_to_host_u32(mp->local_session_id));
6536 vat_json_object_add_uint(node, "local_session_id", clib_net_to_host_u32(mp->local_session_id));
6537 vat_json_object_add_uint(node, "remote_session_id", clib_net_to_host_u32(mp->remote_session_id));
6538 vat_json_object_add_string_copy(node, "l2_sublayer", mp->l2_sublayer_present ?
6539 (u8*)"present" : (u8*)"absent");
6542 static int api_sw_if_l2tpv3_tunnel_dump (vat_main_t * vam)
6544 vl_api_sw_if_l2tpv3_tunnel_dump_t *mp;
6547 /* Get list of l2tpv3-tunnel interfaces */
6548 M(SW_IF_L2TPV3_TUNNEL_DUMP, sw_if_l2tpv3_tunnel_dump);
6551 /* Use a control ping for synchronization */
6553 vl_api_control_ping_t * mp;
6554 M(CONTROL_PING, control_ping);
6561 static void vl_api_sw_interface_tap_details_t_handler
6562 (vl_api_sw_interface_tap_details_t * mp)
6564 vat_main_t * vam = &vat_main;
6566 fformat(vam->ofp, "%-16s %d\n",
6568 clib_net_to_host_u32(mp->sw_if_index));
6571 static void vl_api_sw_interface_tap_details_t_handler_json
6572 (vl_api_sw_interface_tap_details_t * mp)
6574 vat_main_t * vam = &vat_main;
6575 vat_json_node_t *node = NULL;
6577 if (VAT_JSON_ARRAY != vam->json_tree.type) {
6578 ASSERT(VAT_JSON_NONE == vam->json_tree.type);
6579 vat_json_init_array(&vam->json_tree);
6581 node = vat_json_array_add(&vam->json_tree);
6583 vat_json_init_object(node);
6584 vat_json_object_add_uint(node, "sw_if_index", ntohl(mp->sw_if_index));
6585 vat_json_object_add_string_copy(node, "dev_name", mp->dev_name);
6588 static int api_sw_interface_tap_dump (vat_main_t * vam)
6590 vl_api_sw_interface_tap_dump_t *mp;
6593 fformat(vam->ofp, "\n%-16s %s\n", "dev_name", "sw_if_index");
6594 /* Get list of tap interfaces */
6595 M(SW_INTERFACE_TAP_DUMP, sw_interface_tap_dump);
6598 /* Use a control ping for synchronization */
6600 vl_api_control_ping_t * mp;
6601 M(CONTROL_PING, control_ping);
6607 static uword unformat_vxlan_decap_next
6608 (unformat_input_t * input, va_list * args)
6610 u32 * result = va_arg (*args, u32 *);
6613 if (unformat (input, "drop"))
6614 *result = VXLAN_INPUT_NEXT_DROP;
6615 else if (unformat (input, "ip4"))
6616 *result = VXLAN_INPUT_NEXT_IP4_INPUT;
6617 else if (unformat (input, "ip6"))
6618 *result = VXLAN_INPUT_NEXT_IP6_INPUT;
6619 else if (unformat (input, "l2"))
6620 *result = VXLAN_INPUT_NEXT_L2_INPUT;
6621 else if (unformat (input, "%d", &tmp))
6628 static int api_vxlan_add_del_tunnel (vat_main_t * vam)
6630 unformat_input_t * line_input = vam->input;
6631 vl_api_vxlan_add_del_tunnel_t *mp;
6633 ip4_address_t src, dst;
6637 u32 encap_vrf_id = 0;
6638 u32 decap_next_index = ~0;
6641 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) {
6642 if (unformat (line_input, "del"))
6644 else if (unformat (line_input, "src %U",
6645 unformat_ip4_address, &src))
6647 else if (unformat (line_input, "dst %U",
6648 unformat_ip4_address, &dst))
6650 else if (unformat (line_input, "encap-vrf-id %d", &encap_vrf_id))
6652 else if (unformat (line_input, "decap-next %U",
6653 unformat_vxlan_decap_next, &decap_next_index))
6655 else if (unformat (line_input, "vni %d", &vni))
6658 errmsg ("parse error '%U'\n", format_unformat_error, line_input);
6664 errmsg ("tunnel src address not specified\n");
6668 errmsg ("tunnel dst address not specified\n");
6672 if ((vni == 0) || (vni>>24)) {
6673 errmsg ("vni not specified or out of range\n");
6677 M (VXLAN_ADD_DEL_TUNNEL, vxlan_add_del_tunnel);
6679 mp->src_address = src.as_u32;
6680 mp->dst_address = dst.as_u32;
6681 mp->encap_vrf_id = ntohl(encap_vrf_id);
6682 mp->decap_next_index = ntohl(decap_next_index);
6683 mp->vni = ntohl(vni);
6684 mp->is_add = is_add;
6691 static void vl_api_vxlan_tunnel_details_t_handler
6692 (vl_api_vxlan_tunnel_details_t * mp)
6694 vat_main_t * vam = &vat_main;
6696 fformat(vam->ofp, "%11d%13U%13U%14d%18d%13d\n",
6697 ntohl(mp->sw_if_index),
6698 format_ip4_address, &mp->src_address,
6699 format_ip4_address, &mp->dst_address,
6700 ntohl(mp->encap_vrf_id),
6701 ntohl(mp->decap_next_index),
6705 static void vl_api_vxlan_tunnel_details_t_handler_json
6706 (vl_api_vxlan_tunnel_details_t * mp)
6708 vat_main_t * vam = &vat_main;
6709 vat_json_node_t *node = NULL;
6712 if (VAT_JSON_ARRAY != vam->json_tree.type) {
6713 ASSERT(VAT_JSON_NONE == vam->json_tree.type);
6714 vat_json_init_array(&vam->json_tree);
6716 node = vat_json_array_add(&vam->json_tree);
6718 vat_json_init_object(node);
6719 vat_json_object_add_uint(node, "sw_if_index", ntohl(mp->sw_if_index));
6720 memcpy(&ip4, &mp->src_address, sizeof(ip4));
6721 vat_json_object_add_ip4(node, "src_address", ip4);
6722 memcpy(&ip4, &mp->dst_address, sizeof(ip4));
6723 vat_json_object_add_ip4(node, "dst_address", ip4);
6724 vat_json_object_add_uint(node, "encap_vrf_id", ntohl(mp->encap_vrf_id));
6725 vat_json_object_add_uint(node, "decap_next_index", ntohl(mp->decap_next_index));
6726 vat_json_object_add_uint(node, "vni", ntohl(mp->vni));
6729 static int api_vxlan_tunnel_dump (vat_main_t * vam)
6731 unformat_input_t * i = vam->input;
6732 vl_api_vxlan_tunnel_dump_t *mp;
6735 u8 sw_if_index_set = 0;
6737 /* Parse args required to build the message */
6738 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
6739 if (unformat (i, "sw_if_index %d", &sw_if_index))
6740 sw_if_index_set = 1;
6745 if (sw_if_index_set == 0) {
6749 if (!vam->json_output) {
6750 fformat(vam->ofp, "%11s%13s%13s%14s%18s%13s\n",
6751 "sw_if_index", "src_address", "dst_address",
6752 "encap_vrf_id", "decap_next_index", "vni");
6755 /* Get list of l2tpv3-tunnel interfaces */
6756 M(VXLAN_TUNNEL_DUMP, vxlan_tunnel_dump);
6758 mp->sw_if_index = htonl(sw_if_index);
6762 /* Use a control ping for synchronization */
6764 vl_api_control_ping_t * mp;
6765 M(CONTROL_PING, control_ping);
6771 static int api_l2_fib_clear_table (vat_main_t * vam)
6773 // unformat_input_t * i = vam->input;
6774 vl_api_l2_fib_clear_table_t *mp;
6777 M(L2_FIB_CLEAR_TABLE, l2_fib_clear_table);
6784 static int api_l2_interface_efp_filter (vat_main_t * vam)
6786 unformat_input_t * i = vam->input;
6787 vl_api_l2_interface_efp_filter_t *mp;
6791 u8 sw_if_index_set = 0;
6793 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
6794 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
6795 sw_if_index_set = 1;
6796 else if (unformat (i, "sw_if_index %d", &sw_if_index))
6797 sw_if_index_set = 1;
6798 else if (unformat (i, "enable"))
6800 else if (unformat (i, "disable"))
6803 clib_warning ("parse error '%U'", format_unformat_error, i);
6808 if (sw_if_index_set == 0) {
6809 errmsg ("missing sw_if_index\n");
6813 M(L2_INTERFACE_EFP_FILTER, l2_interface_efp_filter);
6815 mp->sw_if_index = ntohl(sw_if_index);
6816 mp->enable_disable = enable;
6823 #define foreach_vtr_op \
6824 _("disable", L2_VTR_DISABLED) \
6825 _("push-1", L2_VTR_PUSH_1) \
6826 _("push-2", L2_VTR_PUSH_2) \
6827 _("pop-1", L2_VTR_POP_1) \
6828 _("pop-2", L2_VTR_POP_2) \
6829 _("translate-1-1", L2_VTR_TRANSLATE_1_1) \
6830 _("translate-1-2", L2_VTR_TRANSLATE_1_2) \
6831 _("translate-2-1", L2_VTR_TRANSLATE_2_1) \
6832 _("translate-2-2", L2_VTR_TRANSLATE_2_2)
6834 static int api_l2_interface_vlan_tag_rewrite (vat_main_t * vam)
6836 unformat_input_t * i = vam->input;
6837 vl_api_l2_interface_vlan_tag_rewrite_t *mp;
6840 u8 sw_if_index_set = 0;
6847 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
6848 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
6849 sw_if_index_set = 1;
6850 else if (unformat (i, "sw_if_index %d", &sw_if_index))
6851 sw_if_index_set = 1;
6852 else if (unformat (i, "vtr_op %d", &vtr_op))
6854 #define _(n,v) else if (unformat(i, n)) {vtr_op = v; vtr_op_set = 1;}
6858 else if (unformat (i, "push_dot1q %d", &push_dot1q))
6860 else if (unformat (i, "tag1 %d", &tag1))
6862 else if (unformat (i, "tag2 %d", &tag2))
6865 clib_warning ("parse error '%U'", format_unformat_error, i);
6870 if ((sw_if_index_set == 0)||(vtr_op_set == 0)) {
6871 errmsg ("missing vtr operation or sw_if_index\n");
6875 M(L2_INTERFACE_VLAN_TAG_REWRITE, l2_interface_vlan_tag_rewrite)
6877 mp->sw_if_index = ntohl(sw_if_index);
6878 mp->vtr_op = ntohl(vtr_op);
6879 mp->push_dot1q = ntohl(push_dot1q);
6880 mp->tag1 = ntohl(tag1);
6881 mp->tag2 = ntohl(tag2);
6888 static int api_create_vhost_user_if (vat_main_t * vam)
6890 unformat_input_t * i = vam->input;
6891 vl_api_create_vhost_user_if_t *mp;
6895 u8 file_name_set = 0;
6896 u32 custom_dev_instance = ~0;
6898 u8 use_custom_mac = 0;
6900 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
6901 if (unformat (i, "socket %s", &file_name)) {
6904 else if (unformat (i, "renumber %"PRIu32, &custom_dev_instance))
6906 else if (unformat (i, "mac %U", unformat_ethernet_address, hwaddr))
6908 else if (unformat (i, "server"))
6914 if (file_name_set == 0) {
6915 errmsg ("missing socket file name\n");
6919 if (vec_len (file_name) > 255) {
6920 errmsg ("socket file name too long\n");
6923 vec_add1 (file_name, 0);
6925 M(CREATE_VHOST_USER_IF, create_vhost_user_if);
6927 mp->is_server = is_server;
6928 memcpy(mp->sock_filename, file_name, vec_len(file_name));
6929 vec_free(file_name);
6930 if (custom_dev_instance != ~0) {
6932 mp->custom_dev_instance = ntohl(custom_dev_instance);
6934 mp->use_custom_mac = use_custom_mac;
6935 memcpy(mp->mac_address, hwaddr, 6);
6942 static int api_modify_vhost_user_if (vat_main_t * vam)
6944 unformat_input_t * i = vam->input;
6945 vl_api_modify_vhost_user_if_t *mp;
6949 u8 file_name_set = 0;
6950 u32 custom_dev_instance = ~0;
6951 u8 sw_if_index_set = 0;
6952 u32 sw_if_index = (u32)~0;
6954 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
6955 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
6956 sw_if_index_set = 1;
6957 else if (unformat (i, "sw_if_index %d", &sw_if_index))
6958 sw_if_index_set = 1;
6959 else if (unformat (i, "socket %s", &file_name)) {
6962 else if (unformat (i, "renumber %"PRIu32, &custom_dev_instance))
6964 else if (unformat (i, "server"))
6970 if (sw_if_index_set == 0) {
6971 errmsg ("missing sw_if_index or interface name\n");
6975 if (file_name_set == 0) {
6976 errmsg ("missing socket file name\n");
6980 if (vec_len (file_name) > 255) {
6981 errmsg ("socket file name too long\n");
6984 vec_add1 (file_name, 0);
6986 M(MODIFY_VHOST_USER_IF, modify_vhost_user_if);
6988 mp->sw_if_index = ntohl(sw_if_index);
6989 mp->is_server = is_server;
6990 memcpy(mp->sock_filename, file_name, vec_len(file_name));
6991 vec_free(file_name);
6992 if (custom_dev_instance != ~0) {
6994 mp->custom_dev_instance = ntohl(custom_dev_instance);
7002 static int api_delete_vhost_user_if (vat_main_t * vam)
7004 unformat_input_t * i = vam->input;
7005 vl_api_delete_vhost_user_if_t *mp;
7007 u32 sw_if_index = ~0;
7008 u8 sw_if_index_set = 0;
7010 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
7011 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
7012 sw_if_index_set = 1;
7013 else if (unformat (i, "sw_if_index %d", &sw_if_index))
7014 sw_if_index_set = 1;
7019 if (sw_if_index_set == 0) {
7020 errmsg ("missing sw_if_index or interface name\n");
7025 M(DELETE_VHOST_USER_IF, delete_vhost_user_if);
7027 mp->sw_if_index = ntohl(sw_if_index);
7034 static void vl_api_sw_interface_vhost_user_details_t_handler
7035 (vl_api_sw_interface_vhost_user_details_t * mp)
7037 vat_main_t * vam = &vat_main;
7039 fformat(vam->ofp, "%-25s %3" PRIu32 " %6" PRIu32 " %8x %6d %7d %s\n",
7040 (char *)mp->interface_name,
7041 ntohl(mp->sw_if_index), ntohl(mp->virtio_net_hdr_sz),
7042 clib_net_to_host_u64(mp->features), mp->is_server,
7043 ntohl(mp->num_regions), (char *)mp->sock_filename);
7044 fformat(vam->ofp, " Status: '%s'\n", strerror(ntohl(mp->sock_errno)));
7047 static void vl_api_sw_interface_vhost_user_details_t_handler_json
7048 (vl_api_sw_interface_vhost_user_details_t * mp)
7050 vat_main_t * vam = &vat_main;
7051 vat_json_node_t *node = NULL;
7053 if (VAT_JSON_ARRAY != vam->json_tree.type) {
7054 ASSERT(VAT_JSON_NONE == vam->json_tree.type);
7055 vat_json_init_array(&vam->json_tree);
7057 node = vat_json_array_add(&vam->json_tree);
7059 vat_json_init_object(node);
7060 vat_json_object_add_uint(node, "sw_if_index", ntohl(mp->sw_if_index));
7061 vat_json_object_add_string_copy(node, "interface_name", mp->interface_name);
7062 vat_json_object_add_uint(node, "virtio_net_hdr_sz", ntohl(mp->virtio_net_hdr_sz));
7063 vat_json_object_add_uint(node, "features", clib_net_to_host_u64(mp->features));
7064 vat_json_object_add_uint(node, "is_server", mp->is_server);
7065 vat_json_object_add_string_copy(node, "sock_filename", mp->sock_filename);
7066 vat_json_object_add_uint(node, "num_regions", ntohl(mp->num_regions));
7067 vat_json_object_add_uint(node, "sock_errno", ntohl(mp->sock_errno));
7070 static int api_sw_interface_vhost_user_dump (vat_main_t * vam)
7072 vl_api_sw_interface_vhost_user_dump_t *mp;
7074 fformat(vam->ofp, "Interface name idx hdr_sz features server regions filename\n");
7076 /* Get list of vhost-user interfaces */
7077 M(SW_INTERFACE_VHOST_USER_DUMP, sw_interface_vhost_user_dump);
7080 /* Use a control ping for synchronization */
7082 vl_api_control_ping_t * mp;
7083 M(CONTROL_PING, control_ping);
7089 static int api_show_version (vat_main_t * vam)
7091 vl_api_show_version_t *mp;
7094 M(SHOW_VERSION, show_version);
7101 static uword unformat_nsh_gre_decap_next
7102 (unformat_input_t * input, va_list * args)
7104 u32 * result = va_arg (*args, u32 *);
7107 if (unformat (input, "drop"))
7108 *result = NSH_INPUT_NEXT_DROP;
7109 else if (unformat (input, "ip4"))
7110 *result = NSH_INPUT_NEXT_IP4_INPUT;
7111 else if (unformat (input, "ip6"))
7112 *result = NSH_INPUT_NEXT_IP6_INPUT;
7113 else if (unformat (input, "ethernet"))
7114 *result = NSH_INPUT_NEXT_ETHERNET_INPUT;
7115 else if (unformat (input, "%d", &tmp))
7122 static int api_nsh_gre_add_del_tunnel (vat_main_t * vam)
7124 unformat_input_t * line_input = vam->input;
7125 vl_api_nsh_gre_add_del_tunnel_t *mp;
7127 ip4_address_t src, dst;
7131 u32 encap_vrf_id = 0;
7132 u32 decap_vrf_id = 0;
7135 u8 next_protocol = 1; /* ip4 */
7146 u32 decap_next_index = NSH_INPUT_NEXT_IP4_INPUT;
7150 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) {
7151 if (unformat (line_input, "del"))
7153 else if (unformat (line_input, "src %U",
7154 unformat_ip4_address, &src))
7156 else if (unformat (line_input, "dst %U",
7157 unformat_ip4_address, &dst))
7159 else if (unformat (line_input, "encap-vrf-id %d", &encap_vrf_id))
7161 else if (unformat (line_input, "decap-vrf-id %d", &decap_vrf_id))
7163 else if (unformat (line_input, "decap-next %U",
7164 unformat_nsh_gre_decap_next, &decap_next_index))
7166 else if (unformat (line_input, "version %d", &tmp))
7167 ver_o_c |= (tmp & 3) << 6;
7168 else if (unformat (line_input, "o-bit %d", &tmp))
7169 ver_o_c |= (tmp & 1) << 5;
7170 else if (unformat (line_input, "c-bit %d", &tmp))
7171 ver_o_c |= (tmp & 1) << 4;
7172 else if (unformat (line_input, "md-type %d", &tmp))
7174 else if (unformat(line_input, "next-ip4"))
7176 else if (unformat(line_input, "next-ip6"))
7178 else if (unformat(line_input, "next-ethernet"))
7180 else if (unformat (line_input, "c1 %d", &c1))
7182 else if (unformat (line_input, "c2 %d", &c2))
7184 else if (unformat (line_input, "c3 %d", &c3))
7186 else if (unformat (line_input, "c4 %d", &c4))
7188 else if (unformat (line_input, "spi %d", &spi))
7190 else if (unformat (line_input, "si %d", &si))
7192 else if (unformat (line_input, "tlv %x"))
7193 vec_add1 (tlvs, tmp);
7195 errmsg ("parse error '%U'\n", format_unformat_error, line_input);
7201 errmsg ("tunnel src address not specified\n");
7205 errmsg ("tunnel dst address not specified\n");
7210 errmsg ("spi not specified\n");
7215 errmsg ("si not specified\n");
7219 M2 (NSH_GRE_ADD_DEL_TUNNEL, nsh_gre_add_del_tunnel,
7220 sizeof(u32) * vec_len (tlvs));
7222 spi_si = (spi<<8) | si;
7224 mp->src = src.as_u32;
7225 mp->dst = dst.as_u32;
7226 mp->encap_vrf_id = ntohl(encap_vrf_id);
7227 mp->decap_vrf_id = ntohl(decap_vrf_id);
7228 mp->decap_next_index = ntohl(decap_next_index);
7229 mp->tlv_len_in_words = vec_len (tlvs);
7230 mp->is_add = is_add;
7231 mp->ver_o_c = ver_o_c;
7232 mp->length = 6 + vec_len(tlvs);
7233 mp->md_type = md_type;
7234 mp->next_protocol = next_protocol;
7235 mp->spi_si = ntohl(spi_si);
7241 for (i = 0; i < vec_len(tlvs); i++)
7242 mp->tlvs[i] = ntohl(tlvs[i]);
7251 static uword unformat_nsh_vxlan_gpe_decap_next
7252 (unformat_input_t * input, va_list * args)
7254 u32 * result = va_arg (*args, u32 *);
7257 if (unformat (input, "drop"))
7258 *result = NSH_VXLAN_GPE_INPUT_NEXT_DROP;
7259 else if (unformat (input, "ip4"))
7260 *result = NSH_VXLAN_GPE_INPUT_NEXT_IP4_INPUT;
7261 else if (unformat (input, "ip6"))
7262 *result = NSH_VXLAN_GPE_INPUT_NEXT_IP6_INPUT;
7263 else if (unformat (input, "ethernet"))
7264 *result = NSH_VXLAN_GPE_INPUT_NEXT_ETHERNET_INPUT;
7265 else if (unformat (input, "nsh-vxlan-gpe"))
7266 *result = NSH_VXLAN_GPE_INPUT_NEXT_ETHERNET_INPUT;
7267 else if (unformat (input, "%d", &tmp))
7274 static int api_nsh_vxlan_gpe_add_del_tunnel (vat_main_t * vam)
7276 unformat_input_t * line_input = vam->input;
7277 vl_api_nsh_vxlan_gpe_add_del_tunnel_t *mp;
7279 ip4_address_t src, dst;
7283 u32 encap_vrf_id = 0;
7284 u32 decap_vrf_id = 0;
7287 u8 next_protocol = 1; /* ip4 */
7298 u32 decap_next_index = NSH_INPUT_NEXT_IP4_INPUT;
7304 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) {
7305 if (unformat (line_input, "del"))
7307 else if (unformat (line_input, "src %U",
7308 unformat_ip4_address, &src))
7310 else if (unformat (line_input, "dst %U",
7311 unformat_ip4_address, &dst))
7313 else if (unformat (line_input, "encap-vrf-id %d", &encap_vrf_id))
7315 else if (unformat (line_input, "decap-vrf-id %d", &decap_vrf_id))
7317 else if (unformat (line_input, "decap-next %U",
7318 unformat_nsh_vxlan_gpe_decap_next,
7321 else if (unformat (line_input, "vni %d", &vni))
7323 else if (unformat (line_input, "version %d", &tmp))
7324 ver_o_c |= (tmp & 3) << 6;
7325 else if (unformat (line_input, "o-bit %d", &tmp))
7326 ver_o_c |= (tmp & 1) << 5;
7327 else if (unformat (line_input, "c-bit %d", &tmp))
7328 ver_o_c |= (tmp & 1) << 4;
7329 else if (unformat (line_input, "md-type %d", &tmp))
7331 else if (unformat(line_input, "next-ip4"))
7333 else if (unformat(line_input, "next-ip6"))
7335 else if (unformat(line_input, "next-ethernet"))
7337 else if (unformat (line_input, "c1 %d", &c1))
7339 else if (unformat (line_input, "c2 %d", &c2))
7341 else if (unformat (line_input, "c3 %d", &c3))
7343 else if (unformat (line_input, "c4 %d", &c4))
7345 else if (unformat (line_input, "spi %d", &spi))
7347 else if (unformat (line_input, "si %d", &si))
7349 else if (unformat (line_input, "tlv %x"))
7350 vec_add1 (tlvs, tmp);
7352 errmsg ("parse error '%U'\n", format_unformat_error, line_input);
7358 errmsg ("tunnel src address not specified\n");
7362 errmsg ("tunnel dst address not specified\n");
7367 errmsg ("spi not specified\n");
7372 errmsg ("si not specified\n");
7376 errmsg ("vni not specified\n");
7380 M2 (NSH_VXLAN_GPE_ADD_DEL_TUNNEL, nsh_vxlan_gpe_add_del_tunnel,
7381 sizeof(u32) * vec_len (tlvs));
7383 spi_si = (spi<<8) | si;
7385 mp->src = src.as_u32;
7386 mp->dst = dst.as_u32;
7387 mp->encap_vrf_id = ntohl(encap_vrf_id);
7388 mp->decap_vrf_id = ntohl(decap_vrf_id);
7389 mp->decap_next_index = ntohl(decap_next_index);
7390 mp->tlv_len_in_words = vec_len (tlvs);
7391 mp->vni = ntohl(vni);
7392 mp->is_add = is_add;
7393 mp->ver_o_c = ver_o_c;
7394 mp->length = 6 + vec_len(tlvs);
7395 mp->md_type = md_type;
7396 mp->next_protocol = next_protocol;
7397 mp->spi_si = ntohl(spi_si);
7403 for (i = 0; i < vec_len(tlvs); i++)
7404 mp->tlvs[i] = ntohl(tlvs[i]);
7413 static uword unformat_lisp_gpe_decap_next (unformat_input_t * input,
7416 u32 * result = va_arg (*args, u32 *);
7419 if (unformat (input, "drop"))
7420 *result = LISP_GPE_INPUT_NEXT_DROP;
7421 else if (unformat (input, "ip4"))
7422 *result = LISP_GPE_INPUT_NEXT_IP4_INPUT;
7423 else if (unformat (input, "ip6"))
7424 *result = LISP_GPE_INPUT_NEXT_IP6_INPUT;
7425 else if (unformat (input, "ethernet"))
7426 *result = LISP_GPE_INPUT_NEXT_IP6_INPUT;
7427 else if (unformat (input, "lisp-gpe"))
7428 *result = LISP_GPE_INPUT_NEXT_LISP_GPE_ENCAP;
7429 else if (unformat (input, "%d", &tmp))
7437 api_lisp_gpe_add_del_tunnel (vat_main_t * vam)
7439 unformat_input_t * line_input = vam->input;
7440 vl_api_lisp_gpe_add_del_tunnel_t *mp;
7442 ip4_address_t src, dst;
7446 u32 encap_vrf_id = 0;
7447 u32 decap_vrf_id = 0;
7448 u8 next_protocol = LISP_GPE_NEXT_PROTOCOL_IP4;
7449 u32 decap_next_index = LISP_GPE_INPUT_NEXT_IP4_INPUT;
7450 u8 flags = LISP_GPE_FLAGS_P;
7457 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) {
7458 if (unformat (line_input, "del"))
7460 else if (unformat (line_input, "src %U",
7461 unformat_ip4_address, &src))
7463 else if (unformat (line_input, "dst %U",
7464 unformat_ip4_address, &dst))
7466 else if (unformat (line_input, "encap-vrf-id %d", &encap_vrf_id))
7468 else if (unformat (line_input, "decap-vrf-id %d", &decap_vrf_id))
7470 else if (unformat (line_input, "decap-next %U",
7471 unformat_lisp_gpe_decap_next,
7474 else if (unformat(line_input, "next-ip4"))
7476 else if (unformat(line_input, "next-ip6"))
7478 else if (unformat(line_input, "next-ethernet"))
7480 else if (unformat(line_input, "next-nsh"))
7482 /* Allow the user to specify anything they want in the LISP hdr */
7483 else if (unformat (line_input, "ver_res %x", &tmp))
7485 else if (unformat (line_input, "res %x", &tmp))
7487 else if (unformat (line_input, "flags %x", &tmp))
7489 else if (unformat (line_input, "n-bit"))
7490 flags |= LISP_GPE_FLAGS_N;
7491 else if (unformat (line_input, "l-bit"))
7492 flags |= LISP_GPE_FLAGS_L;
7493 else if (unformat (line_input, "e-bit"))
7494 flags |= LISP_GPE_FLAGS_E;
7495 else if (unformat (line_input, "v-bit"))
7496 flags |= LISP_GPE_FLAGS_V;
7497 else if (unformat (line_input, "i-bit"))
7498 flags |= LISP_GPE_FLAGS_V;
7499 else if (unformat (line_input, "not-p-bit"))
7500 flags &= !LISP_GPE_FLAGS_P;
7501 else if (unformat (line_input, "p-bit"))
7502 flags |= LISP_GPE_FLAGS_P;
7503 else if (unformat (line_input, "o-bit"))
7504 flags |= LISP_GPE_FLAGS_O;
7505 else if (unformat (line_input, "iidx %x", &iid))
7507 else if (unformat (line_input, "iid %d", &iid))
7510 errmsg ("parse error '%U'\n", format_unformat_error, line_input);
7516 errmsg ("tunnel src address not specified\n");
7520 errmsg ("tunnel dst address not specified\n");
7524 errmsg ("iid not specified\n");
7528 M(LISP_GPE_ADD_DEL_TUNNEL, lisp_gpe_add_del_tunnel);
7530 mp->src = src.as_u32;
7531 mp->dst = dst.as_u32;
7532 mp->encap_vrf_id = ntohl(encap_vrf_id);
7533 mp->decap_vrf_id = ntohl(decap_vrf_id);
7534 mp->decap_next_index = ntohl(decap_next_index);
7535 mp->is_add = is_add;
7537 mp->ver_res = ver_res;
7539 mp->next_protocol = next_protocol;
7540 mp->iid = ntohl(iid);
7549 u8 * format_l2_fib_mac_address (u8 * s, va_list * args)
7551 u8 * a = va_arg (*args, u8 *);
7553 return format (s, "%02x:%02x:%02x:%02x:%02x:%02x",
7554 a[2], a[3], a[4], a[5], a[6], a[7]);
7557 static void vl_api_l2_fib_table_entry_t_handler
7558 (vl_api_l2_fib_table_entry_t * mp)
7560 vat_main_t * vam = &vat_main;
7562 fformat(vam->ofp, "%3" PRIu32 " %U %3" PRIu32
7564 ntohl(mp->bd_id), format_l2_fib_mac_address, &mp->mac,
7565 ntohl(mp->sw_if_index), mp->static_mac, mp->filter_mac,
7569 static void vl_api_l2_fib_table_entry_t_handler_json
7570 (vl_api_l2_fib_table_entry_t * mp)
7572 vat_main_t * vam = &vat_main;
7573 vat_json_node_t *node = NULL;
7575 if (VAT_JSON_ARRAY != vam->json_tree.type) {
7576 ASSERT(VAT_JSON_NONE == vam->json_tree.type);
7577 vat_json_init_array(&vam->json_tree);
7579 node = vat_json_array_add(&vam->json_tree);
7581 vat_json_init_object(node);
7582 vat_json_object_add_uint(node, "bd_id", ntohl(mp->bd_id));
7583 vat_json_object_add_uint(node, "mac", clib_net_to_host_u64(mp->mac));
7584 vat_json_object_add_uint(node, "sw_if_index", ntohl(mp->sw_if_index));
7585 vat_json_object_add_uint(node, "static_mac", mp->static_mac);
7586 vat_json_object_add_uint(node, "filter_mac", mp->filter_mac);
7587 vat_json_object_add_uint(node, "bvi_mac", mp->bvi_mac);
7590 static int api_l2_fib_table_dump (vat_main_t * vam)
7592 unformat_input_t * i = vam->input;
7593 vl_api_l2_fib_table_dump_t *mp;
7598 /* Parse args required to build the message */
7599 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
7600 if (unformat (i, "bd_id %d", &bd_id))
7606 if (bd_id_set == 0) {
7607 errmsg ("missing bridge domain\n");
7611 fformat(vam->ofp, "BD-ID Mac Address sw-ndx Static Filter BVI\n");
7613 /* Get list of l2 fib entries */
7614 M(L2_FIB_TABLE_DUMP, l2_fib_table_dump);
7616 mp->bd_id = ntohl(bd_id);
7619 /* Use a control ping for synchronization */
7621 vl_api_control_ping_t * mp;
7622 M(CONTROL_PING, control_ping);
7630 api_interface_name_renumber (vat_main_t * vam)
7632 unformat_input_t * line_input = vam->input;
7633 vl_api_interface_name_renumber_t *mp;
7634 u32 sw_if_index = ~0;
7636 u32 new_show_dev_instance = ~0;
7638 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) {
7639 if (unformat (line_input, "%U", unformat_sw_if_index, vam,
7642 else if (unformat (line_input, "sw_if_index %d", &sw_if_index))
7644 else if (unformat (line_input, "new_show_dev_instance %d",
7645 &new_show_dev_instance))
7651 if (sw_if_index == ~0) {
7652 errmsg ("missing interface name or sw_if_index\n");
7656 if (new_show_dev_instance == ~0) {
7657 errmsg ("missing new_show_dev_instance\n");
7661 M(INTERFACE_NAME_RENUMBER, interface_name_renumber);
7663 mp->sw_if_index = ntohl (sw_if_index);
7664 mp->new_show_dev_instance = ntohl (new_show_dev_instance);
7670 api_want_ip4_arp_events (vat_main_t * vam)
7672 unformat_input_t * line_input = vam->input;
7673 vl_api_want_ip4_arp_events_t * mp;
7675 ip4_address_t address;
7676 int address_set = 0;
7677 u32 enable_disable = 1;
7679 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) {
7680 if (unformat (line_input, "address %U",
7681 unformat_ip4_address, &address))
7683 else if (unformat (line_input, "del"))
7689 if (address_set == 0) {
7690 errmsg ("missing addresses\n");
7694 M(WANT_IP4_ARP_EVENTS, want_ip4_arp_events);
7695 mp->enable_disable = enable_disable;
7697 mp->address = address.as_u32;
7702 static int api_input_acl_set_interface (vat_main_t * vam)
7704 unformat_input_t * i = vam->input;
7705 vl_api_input_acl_set_interface_t *mp;
7708 int sw_if_index_set;
7709 u32 ip4_table_index = ~0;
7710 u32 ip6_table_index = ~0;
7711 u32 l2_table_index = ~0;
7714 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
7715 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
7716 sw_if_index_set = 1;
7717 else if (unformat (i, "sw_if_index %d", &sw_if_index))
7718 sw_if_index_set = 1;
7719 else if (unformat (i, "del"))
7721 else if (unformat (i, "ip4-table %d", &ip4_table_index))
7723 else if (unformat (i, "ip6-table %d", &ip6_table_index))
7725 else if (unformat (i, "l2-table %d", &l2_table_index))
7728 clib_warning ("parse error '%U'", format_unformat_error, i);
7733 if (sw_if_index_set == 0) {
7734 errmsg ("missing interface name or sw_if_index\n");
7738 M(INPUT_ACL_SET_INTERFACE, input_acl_set_interface);
7740 mp->sw_if_index = ntohl(sw_if_index);
7741 mp->ip4_table_index = ntohl(ip4_table_index);
7742 mp->ip6_table_index = ntohl(ip6_table_index);
7743 mp->l2_table_index = ntohl(l2_table_index);
7744 mp->is_add = is_add;
7752 api_ip_address_dump (vat_main_t * vam)
7754 unformat_input_t * i = vam->input;
7755 vl_api_ip_address_dump_t * mp;
7756 u32 sw_if_index = ~0;
7757 u8 sw_if_index_set = 0;
7762 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
7763 if (unformat (i, "sw_if_index %d", &sw_if_index))
7764 sw_if_index_set = 1;
7765 else if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
7766 sw_if_index_set = 1;
7767 else if (unformat (i, "ipv4"))
7769 else if (unformat (i, "ipv6"))
7775 if (ipv4_set && ipv6_set) {
7776 errmsg ("ipv4 and ipv6 flags cannot be both set\n");
7780 if ((!ipv4_set) && (!ipv6_set)) {
7781 errmsg ("no ipv4 nor ipv6 flag set\n");
7785 if (sw_if_index_set == 0) {
7786 errmsg ("missing interface name or sw_if_index\n");
7790 vam->current_sw_if_index = sw_if_index;
7791 vam->is_ipv6 = ipv6_set;
7793 M(IP_ADDRESS_DUMP, ip_address_dump);
7794 mp->sw_if_index = ntohl(sw_if_index);
7795 mp->is_ipv6 = ipv6_set;
7798 /* Use a control ping for synchronization */
7800 vl_api_control_ping_t * mp;
7801 M(CONTROL_PING, control_ping);
7808 api_ip_dump (vat_main_t * vam)
7810 vl_api_ip_dump_t * mp;
7811 unformat_input_t * in = vam->input;
7818 while (unformat_check_input (in) != UNFORMAT_END_OF_INPUT) {
7819 if (unformat (in, "ipv4"))
7821 else if (unformat (in, "ipv6"))
7827 if (ipv4_set && ipv6_set) {
7828 errmsg ("ipv4 and ipv6 flags cannot be both set\n");
7832 if ((!ipv4_set) && (!ipv6_set)) {
7833 errmsg ("no ipv4 nor ipv6 flag set\n");
7838 vam->is_ipv6 = is_ipv6;
7841 for (i = 0; i < vec_len(vam->ip_details_by_sw_if_index[is_ipv6]); i++) {
7842 vec_free(vam->ip_details_by_sw_if_index[is_ipv6][i].addr);
7844 vec_free(vam->ip_details_by_sw_if_index[is_ipv6]);
7846 M(IP_DUMP, ip_dump);
7847 mp->is_ipv6 = ipv6_set;
7850 /* Use a control ping for synchronization */
7852 vl_api_control_ping_t * mp;
7853 M(CONTROL_PING, control_ping);
7860 api_ipsec_spd_add_del (vat_main_t * vam)
7863 unformat_input_t * i = vam->input;
7864 vl_api_ipsec_spd_add_del_t *mp;
7869 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
7870 if (unformat (i, "spd_id %d", &spd_id))
7872 else if (unformat (i, "del"))
7875 clib_warning ("parse error '%U'", format_unformat_error, i);
7880 errmsg ("spd_id must be set\n");
7884 M(IPSEC_SPD_ADD_DEL, ipsec_spd_add_del);
7886 mp->spd_id = ntohl(spd_id);
7887 mp->is_add = is_add;
7893 clib_warning ("unsupported (no dpdk)");
7899 api_ipsec_interface_add_del_spd (vat_main_t * vam)
7902 unformat_input_t * i = vam->input;
7903 vl_api_ipsec_interface_add_del_spd_t *mp;
7906 u8 sw_if_index_set = 0;
7907 u32 spd_id = (u32) ~0;
7910 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
7911 if (unformat (i, "del"))
7913 else if (unformat (i, "spd_id %d", &spd_id))
7915 else if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
7916 sw_if_index_set = 1;
7917 else if (unformat (i, "sw_if_index %d", &sw_if_index))
7918 sw_if_index_set = 1;
7920 clib_warning ("parse error '%U'", format_unformat_error, i);
7926 if (spd_id == (u32) ~0) {
7927 errmsg ("spd_id must be set\n");
7931 if (sw_if_index_set == 0) {
7932 errmsg ("missing interface name or sw_if_index\n");
7936 M(IPSEC_INTERFACE_ADD_DEL_SPD, ipsec_interface_add_del_spd);
7938 mp->spd_id = ntohl(spd_id);
7939 mp->sw_if_index = ntohl (sw_if_index);
7940 mp->is_add = is_add;
7946 clib_warning ("unsupported (no dpdk)");
7952 api_ipsec_spd_add_del_entry (vat_main_t * vam)
7955 unformat_input_t * i = vam->input;
7956 vl_api_ipsec_spd_add_del_entry_t *mp;
7958 u8 is_add = 1, is_outbound = 0, is_ipv6 = 0, is_ip_any = 1;
7959 u32 spd_id, sa_id, protocol = 0, policy = 0;
7961 u32 rport_start = 0, rport_stop = (u32) ~0;
7962 u32 lport_start = 0, lport_stop = (u32) ~0;
7963 ip4_address_t laddr4_start, laddr4_stop, raddr4_start, raddr4_stop;
7964 ip6_address_t laddr6_start, laddr6_stop, raddr6_start, raddr6_stop;
7966 laddr4_start.as_u32 = raddr4_start.as_u32 = 0;
7967 laddr4_stop.as_u32 = raddr4_stop.as_u32 = (u32) ~0;
7968 laddr6_start.as_u64[0] = raddr6_start.as_u64[0] = 0;
7969 laddr6_start.as_u64[1] = raddr6_start.as_u64[1] = 0;
7970 laddr6_stop.as_u64[0] = raddr6_stop.as_u64[0] = (u64) ~0;
7971 laddr6_stop.as_u64[1] = raddr6_stop.as_u64[1] = (u64) ~0;
7973 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
7974 if (unformat (i, "del"))
7976 if (unformat (i, "outbound"))
7978 if (unformat (i, "inbound"))
7980 else if (unformat (i, "spd_id %d", &spd_id))
7982 else if (unformat (i, "sa_id %d", &sa_id))
7984 else if (unformat (i, "priority %d", &priority))
7986 else if (unformat (i, "protocol %d", &protocol))
7988 else if (unformat (i, "lport_start %d", &lport_start))
7990 else if (unformat (i, "lport_stop %d", &lport_stop))
7992 else if (unformat (i, "rport_start %d", &rport_start))
7994 else if (unformat (i, "rport_stop %d", &rport_stop))
7996 else if (unformat (i, "laddr_start %U", unformat_ip4_address, &laddr4_start))
8001 else if (unformat (i, "laddr_stop %U", unformat_ip4_address, &laddr4_stop))
8006 else if (unformat (i, "raddr_start %U", unformat_ip4_address, &raddr4_start))
8011 else if (unformat (i, "raddr_stop %U", unformat_ip4_address, &raddr4_stop))
8016 else if (unformat (i, "laddr_start %U", unformat_ip6_address, &laddr6_start))
8021 else if (unformat (i, "laddr_stop %U", unformat_ip6_address, &laddr6_stop))
8026 else if (unformat (i, "raddr_start %U", unformat_ip6_address, &raddr6_start))
8031 else if (unformat (i, "raddr_stop %U", unformat_ip6_address, &raddr6_stop))
8036 else if (unformat (i, "action %U", unformat_ipsec_policy_action, &policy))
8038 if (policy == IPSEC_POLICY_ACTION_RESOLVE) {
8039 clib_warning ("unsupported action: 'resolve'");
8044 clib_warning ("parse error '%U'", format_unformat_error, i);
8050 M(IPSEC_SPD_ADD_DEL_ENTRY, ipsec_spd_add_del_entry);
8052 mp->spd_id = ntohl(spd_id);
8053 mp->priority = ntohl(priority);
8054 mp->is_outbound = is_outbound;
8056 mp->is_ipv6 = is_ipv6;
8057 if (is_ipv6 || is_ip_any) {
8058 memcpy (mp->remote_address_start, &raddr6_start, sizeof(ip6_address_t));
8059 memcpy (mp->remote_address_stop, &raddr6_stop, sizeof(ip6_address_t));
8060 memcpy (mp->local_address_start, &laddr6_start, sizeof(ip6_address_t));
8061 memcpy (mp->local_address_stop, &laddr6_stop, sizeof(ip6_address_t));
8063 memcpy (mp->remote_address_start, &raddr4_start, sizeof(ip4_address_t));
8064 memcpy (mp->remote_address_stop, &raddr4_stop, sizeof(ip4_address_t));
8065 memcpy (mp->local_address_start, &laddr4_start, sizeof(ip4_address_t));
8066 memcpy (mp->local_address_stop, &laddr4_stop, sizeof(ip4_address_t));
8068 mp->protocol = (u8) protocol;
8069 mp->local_port_start = ntohs((u16) lport_start);
8070 mp->local_port_stop = ntohs((u16) lport_stop);
8071 mp->remote_port_start = ntohs((u16) rport_start);
8072 mp->remote_port_stop = ntohs((u16) rport_stop);
8073 mp->policy = (u8) policy;
8074 mp->sa_id = ntohl(sa_id);
8075 mp->is_add = is_add;
8076 mp->is_ip_any = is_ip_any;
8081 clib_warning ("unsupported (no dpdk)");
8087 api_ipsec_sad_add_del_entry (vat_main_t * vam)
8090 unformat_input_t * i = vam->input;
8091 vl_api_ipsec_sad_add_del_entry_t *mp;
8097 u8 protocol = IPSEC_PROTOCOL_AH;
8098 u8 is_tunnel = 0, is_tunnel_ipv6 = 0;
8099 u32 crypto_alg = 0, integ_alg = 0;
8100 ip4_address_t tun_src4;
8101 ip4_address_t tun_dst4;
8102 ip6_address_t tun_src6;
8103 ip6_address_t tun_dst6;
8105 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
8106 if (unformat (i, "del"))
8108 else if (unformat (i, "sad_id %d", &sad_id))
8110 else if (unformat (i, "spi %d", &spi))
8112 else if (unformat (i, "esp"))
8113 protocol = IPSEC_PROTOCOL_ESP;
8114 else if (unformat (i, "tunnel_src %U", unformat_ip4_address, &tun_src4)) {
8118 else if (unformat (i, "tunnel_dst %U", unformat_ip4_address, &tun_dst4)) {
8122 else if (unformat (i, "tunnel_src %U", unformat_ip6_address, &tun_src6)) {
8126 else if (unformat (i, "tunnel_dst %U", unformat_ip6_address, &tun_dst6)) {
8130 else if (unformat (i, "crypto_alg %U", unformat_ipsec_crypto_alg, &crypto_alg)) {
8131 if (crypto_alg < IPSEC_CRYPTO_ALG_AES_CBC_128 ||
8132 crypto_alg > IPSEC_INTEG_ALG_SHA_512_256) {
8133 clib_warning ("unsupported crypto-alg: '%U'",
8134 format_ipsec_crypto_alg, crypto_alg);
8138 else if (unformat (i, "crypto_key %U", unformat_hex_string, &ck))
8140 else if (unformat (i, "integ_alg %U", unformat_ipsec_integ_alg, &integ_alg)) {
8141 if (integ_alg < IPSEC_INTEG_ALG_SHA1_96 ||
8142 integ_alg > IPSEC_INTEG_ALG_SHA_512_256) {
8143 clib_warning ("unsupported integ-alg: '%U'",
8144 format_ipsec_integ_alg, integ_alg);
8148 else if (unformat (i, "integ_key %U", unformat_hex_string, &ik))
8151 clib_warning ("parse error '%U'", format_unformat_error, i);
8157 M(IPSEC_SAD_ADD_DEL_ENTRY, ipsec_sad_add_del_entry);
8159 mp->sad_id = ntohl(sad_id);
8160 mp->is_add = is_add;
8161 mp->protocol = protocol;
8162 mp->spi = ntohl(spi);
8163 mp->is_tunnel = is_tunnel;
8164 mp->is_tunnel_ipv6 = is_tunnel_ipv6;
8165 mp->crypto_algorithm = crypto_alg;
8166 mp->integrity_algorithm = integ_alg;
8167 mp->crypto_key_length = vec_len(ck);
8168 mp->integrity_key_length = vec_len(ik);
8170 if (mp->crypto_key_length > sizeof(mp->crypto_key))
8171 mp->crypto_key_length = sizeof(mp->crypto_key);
8173 if (mp->integrity_key_length > sizeof(mp->integrity_key))
8174 mp->integrity_key_length = sizeof(mp->integrity_key);
8176 memcpy (mp->crypto_key, ck, mp->crypto_key_length);
8177 memcpy (mp->integrity_key, ik, mp->integrity_key_length);
8180 if (is_tunnel_ipv6) {
8181 memcpy (mp->tunnel_src_address, &tun_src6, sizeof(ip6_address_t));
8182 memcpy (mp->tunnel_dst_address, &tun_dst6, sizeof(ip6_address_t));
8184 memcpy (mp->tunnel_src_address, &tun_src4, sizeof(ip4_address_t));
8185 memcpy (mp->tunnel_dst_address, &tun_dst4, sizeof(ip4_address_t));
8193 clib_warning ("unsupported (no dpdk)");
8199 api_ipsec_sa_set_key (vat_main_t * vam)
8202 unformat_input_t * i = vam->input;
8203 vl_api_ipsec_sa_set_key_t *mp;
8208 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
8209 if (unformat (i, "sa_id %d", &sa_id))
8211 else if (unformat (i, "crypto_key %U", unformat_hex_string, &ck))
8213 else if (unformat (i, "integ_key %U", unformat_hex_string, &ik))
8216 clib_warning ("parse error '%U'", format_unformat_error, i);
8221 M(IPSEC_SA_SET_KEY, ipsec_set_sa_key);
8223 mp->sa_id = ntohl(sa_id);
8224 mp->crypto_key_length = vec_len(ck);
8225 mp->integrity_key_length = vec_len(ik);
8227 if (mp->crypto_key_length > sizeof(mp->crypto_key))
8228 mp->crypto_key_length = sizeof(mp->crypto_key);
8230 if (mp->integrity_key_length > sizeof(mp->integrity_key))
8231 mp->integrity_key_length = sizeof(mp->integrity_key);
8233 memcpy (mp->crypto_key, ck, mp->crypto_key_length);
8234 memcpy (mp->integrity_key, ik, mp->integrity_key_length);
8240 clib_warning ("unsupported (no dpdk)");
8248 static int api_map_add_domain (vat_main_t * vam)
8250 unformat_input_t *i = vam->input;
8251 vl_api_map_add_domain_t *mp;
8254 ip4_address_t ip4_prefix;
8255 ip6_address_t ip6_prefix;
8256 ip6_address_t ip6_src;
8258 u32 ip6_prefix_len, ip4_prefix_len, ea_bits_len, psid_offset,
8260 u8 is_translation = 0;
8262 u8 ip6_src_len = 128;
8264 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
8265 if (unformat (i, "ip4-pfx %U/%d", unformat_ip4_address,
8266 &ip4_prefix, &ip4_prefix_len))
8268 else if (unformat (i, "ip6-pfx %U/%d", unformat_ip6_address,
8269 &ip6_prefix, &ip6_prefix_len))
8271 else if (unformat (i, "ip6-src %U/%d", unformat_ip6_address, &ip6_src, &ip6_src_len))
8273 else if (unformat (i, "ip6-src %U", unformat_ip6_address, &ip6_src))
8275 else if (unformat (i, "ea-bits-len %d", &ea_bits_len))
8277 else if (unformat (i, "psid-offset %d", &psid_offset))
8279 else if (unformat (i, "psid-len %d", &psid_length))
8281 else if (unformat (i, "mtu %d", &mtu))
8283 else if (unformat (i, "map-t"))
8286 clib_warning ("parse error '%U'", format_unformat_error, i);
8291 if (num_m_args != 6) {
8292 errmsg("mandatory argument(s) missing\n");
8296 /* Construct the API message */
8297 M(MAP_ADD_DOMAIN, map_add_domain);
8299 memcpy(mp->ip4_prefix, &ip4_prefix, sizeof(ip4_prefix));
8300 mp->ip4_prefix_len = ip4_prefix_len;
8302 memcpy(mp->ip6_prefix, &ip6_prefix, sizeof(ip6_prefix));
8303 mp->ip6_prefix_len = ip6_prefix_len;
8305 memcpy(mp->ip6_src, &ip6_src, sizeof(ip6_src));
8306 mp->ip6_src_prefix_len = ip6_src_len;
8308 mp->ea_bits_len = ea_bits_len;
8309 mp->psid_offset = psid_offset;
8310 mp->psid_length = psid_length;
8311 mp->is_translation = is_translation;
8312 mp->mtu = htons(mtu);
8317 /* Wait for a reply, return good/bad news */
8321 static int api_map_del_domain (vat_main_t * vam)
8323 unformat_input_t *i = vam->input;
8324 vl_api_map_del_domain_t *mp;
8330 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
8331 if (unformat (i, "index %d", &index))
8334 clib_warning ("parse error '%U'", format_unformat_error, i);
8339 if (num_m_args != 1) {
8340 errmsg("mandatory argument(s) missing\n");
8344 /* Construct the API message */
8345 M(MAP_DEL_DOMAIN, map_del_domain);
8347 mp->index = ntohl(index);
8352 /* Wait for a reply, return good/bad news */
8356 static int api_map_add_del_rule (vat_main_t * vam)
8358 unformat_input_t *i = vam->input;
8359 vl_api_map_add_del_rule_t *mp;
8362 ip6_address_t ip6_dst;
8363 u32 num_m_args = 0, index, psid;
8365 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
8366 if (unformat (i, "index %d", &index))
8368 else if (unformat (i, "psid %d", &psid))
8370 else if (unformat (i, "dst %U", unformat_ip6_address, &ip6_dst))
8372 else if (unformat (i, "del")) {
8375 clib_warning ("parse error '%U'", format_unformat_error, i);
8380 /* Construct the API message */
8381 M(MAP_ADD_DEL_RULE, map_add_del_rule);
8383 mp->index = ntohl(index);
8384 mp->is_add = is_add;
8385 memcpy(mp->ip6_dst, &ip6_dst, sizeof(ip6_dst));
8386 mp->psid = ntohs(psid);
8391 /* Wait for a reply, return good/bad news */
8395 static int api_map_domain_dump (vat_main_t * vam)
8397 vl_api_map_domain_dump_t *mp;
8400 /* Construct the API message */
8401 M(MAP_DOMAIN_DUMP, map_domain_dump);
8406 /* Use a control ping for synchronization */
8408 vl_api_control_ping_t * mp;
8409 M(CONTROL_PING, control_ping);
8415 static int api_map_rule_dump (vat_main_t * vam)
8417 unformat_input_t *i = vam->input;
8418 vl_api_map_rule_dump_t *mp;
8420 u32 domain_index = ~0;
8422 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
8423 if (unformat (i, "index %u", &domain_index))
8429 if (domain_index == ~0) {
8430 clib_warning("parse error: domain index expected");
8434 /* Construct the API message */
8435 M(MAP_RULE_DUMP, map_rule_dump);
8437 mp->domain_index = htonl(domain_index);
8442 /* Use a control ping for synchronization */
8444 vl_api_control_ping_t * mp;
8445 M(CONTROL_PING, control_ping);
8451 static void vl_api_map_add_domain_reply_t_handler
8452 (vl_api_map_add_domain_reply_t * mp)
8454 vat_main_t * vam = &vat_main;
8455 i32 retval = ntohl(mp->retval);
8457 if (vam->async_mode) {
8458 vam->async_errors += (retval < 0);
8460 vam->retval = retval;
8461 vam->result_ready = 1;
8465 static void vl_api_map_add_domain_reply_t_handler_json
8466 (vl_api_map_add_domain_reply_t * mp)
8468 vat_main_t * vam = &vat_main;
8469 vat_json_node_t node;
8471 vat_json_init_object(&node);
8472 vat_json_object_add_int(&node, "retval", ntohl(mp->retval));
8473 vat_json_object_add_uint(&node, "index", ntohl(mp->index));
8475 vat_json_print(vam->ofp, &node);
8476 vat_json_free(&node);
8478 vam->retval = ntohl(mp->retval);
8479 vam->result_ready = 1;
8483 api_get_first_msg_id (vat_main_t * vam)
8485 vl_api_get_first_msg_id_t * mp;
8487 unformat_input_t * i = vam->input;
8491 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
8492 if (unformat (i, "client %s", &name))
8498 if (name_set == 0) {
8499 errmsg ("missing client name\n");
8504 if (vec_len (name) > 63) {
8505 errmsg ("client name too long\n");
8509 M(GET_FIRST_MSG_ID, get_first_msg_id);
8510 memcpy (mp->name, name, vec_len(name));
8516 static int api_cop_interface_enable_disable (vat_main_t * vam)
8518 unformat_input_t * line_input = vam->input;
8519 vl_api_cop_interface_enable_disable_t * mp;
8521 u32 sw_if_index = ~0;
8522 u8 enable_disable = 1;
8524 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) {
8525 if (unformat (line_input, "disable"))
8527 if (unformat (line_input, "enable"))
8529 else if (unformat (line_input, "%U", unformat_sw_if_index,
8532 else if (unformat (line_input, "sw_if_index %d", &sw_if_index))
8538 if (sw_if_index == ~0) {
8539 errmsg ("missing interface name or sw_if_index\n");
8543 /* Construct the API message */
8544 M(COP_INTERFACE_ENABLE_DISABLE, cop_interface_enable_disable);
8545 mp->sw_if_index = ntohl(sw_if_index);
8546 mp->enable_disable = enable_disable;
8550 /* Wait for the reply */
8554 static int api_cop_whitelist_enable_disable (vat_main_t * vam)
8556 unformat_input_t * line_input = vam->input;
8557 vl_api_cop_whitelist_enable_disable_t * mp;
8559 u32 sw_if_index = ~0;
8560 u8 ip4=0, ip6=0, default_cop=0;
8563 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) {
8564 if (unformat (line_input, "ip4"))
8566 else if (unformat (line_input, "ip6"))
8568 else if (unformat (line_input, "default"))
8570 else if (unformat (line_input, "%U", unformat_sw_if_index,
8573 else if (unformat (line_input, "sw_if_index %d", &sw_if_index))
8575 else if (unformat (line_input, "fib-id %d", &fib_id))
8581 if (sw_if_index == ~0) {
8582 errmsg ("missing interface name or sw_if_index\n");
8586 /* Construct the API message */
8587 M(COP_WHITELIST_ENABLE_DISABLE, cop_whitelist_enable_disable);
8588 mp->sw_if_index = ntohl(sw_if_index);
8589 mp->fib_id = ntohl(fib_id);
8592 mp->default_cop = default_cop;
8596 /* Wait for the reply */
8600 static int api_get_node_graph (vat_main_t * vam)
8602 vl_api_get_node_graph_t * mp;
8605 M(GET_NODE_GRAPH, get_node_graph);
8609 /* Wait for the reply */
8613 static int q_or_quit (vat_main_t * vam)
8615 longjmp (vam->jump_buf, 1);
8616 return 0; /* not so much */
8618 static int q (vat_main_t * vam) {return q_or_quit (vam);}
8619 static int quit (vat_main_t * vam) {return q_or_quit (vam);}
8621 static int comment (vat_main_t * vam)
8626 static int cmd_cmp (void * a1, void * a2)
8631 return strcmp ((char *)(c1[0]), (char *)(c2[0]));
8634 static int help (vat_main_t * vam)
8639 unformat_input_t * i = vam->input;
8642 if (unformat (i, "%s", &name)) {
8647 hs = hash_get_mem (vam->help_by_name, name);
8649 fformat (vam->ofp, "usage: %s %s\n", name, hs[0]);
8651 fformat (vam->ofp, "No such msg / command '%s'\n", name);
8656 fformat(vam->ofp, "Help is available for the following:\n");
8658 hash_foreach_pair (p, vam->function_by_name,
8660 vec_add1 (cmds, (u8 *)(p->key));
8663 vec_sort_with_function (cmds, cmd_cmp);
8665 for (j = 0; j < vec_len(cmds); j++)
8666 fformat (vam->ofp, "%s\n", cmds[j]);
8672 static int set (vat_main_t * vam)
8674 u8 * name = 0, * value = 0;
8675 unformat_input_t * i = vam->input;
8677 if (unformat (i, "%s", &name)) {
8678 /* The input buffer is a vector, not a string. */
8679 value = vec_dup (i->buffer);
8680 vec_delete (value, i->index, 0);
8681 /* Almost certainly has a trailing newline */
8682 if (value[vec_len(value)-1] == '\n')
8683 value[vec_len(value)-1] = 0;
8684 /* Make sure it's a proper string, one way or the other */
8685 vec_add1 (value, 0);
8686 (void) clib_macro_set_value (&vam->macro_main,
8687 (char *)name, (char *)value);
8690 errmsg ("usage: set <name> <value>\n");
8697 static int unset (vat_main_t * vam)
8701 if (unformat (vam->input, "%s", &name))
8702 if (clib_macro_unset (&vam->macro_main, (char *)name) == 1)
8703 errmsg ("unset: %s wasn't set\n", name);
8714 static int macro_sort_cmp (void * a1, void * a2)
8716 macro_sort_t * s1 = a1;
8717 macro_sort_t * s2 = a2;
8719 return strcmp ((char *)(s1->name), (char *)(s2->name));
8722 static int dump_macro_table (vat_main_t * vam)
8724 macro_sort_t * sort_me = 0, * sm;
8728 hash_foreach_pair (p, vam->macro_main.the_value_table_hash,
8730 vec_add2 (sort_me, sm, 1);
8731 sm->name = (u8 *)(p->key);
8732 sm->value = (u8 *) (p->value[0]);
8735 vec_sort_with_function (sort_me, macro_sort_cmp);
8737 if (vec_len(sort_me))
8738 fformat (vam->ofp, "%-15s%s\n", "Name", "Value");
8740 fformat (vam->ofp, "The macro table is empty...\n");
8742 for (i = 0; i < vec_len (sort_me); i++)
8743 fformat (vam->ofp, "%-15s%s\n", sort_me[i].name,
8748 static int dump_node_table (vat_main_t * vam)
8751 vlib_node_t * node, * next_node;
8753 if (vec_len (vam->graph_nodes) == 0) {
8754 fformat (vam->ofp, "Node table empty, issue get_node_graph...\n");
8758 for (i = 0; i < vec_len (vam->graph_nodes); i++) {
8759 node = vam->graph_nodes[i];
8760 fformat (vam->ofp, "[%d] %s\n", i, node->name);
8761 for (j = 0; j < vec_len (node->next_nodes); j++) {
8762 if (node->next_nodes[j] != ~0) {
8763 next_node = vam->graph_nodes[node->next_nodes[j]];
8764 fformat (vam->ofp, " [%d] %s\n", j, next_node->name);
8771 static int search_node_table (vat_main_t * vam)
8773 unformat_input_t * line_input = vam->input;
8776 vlib_node_t * node, * next_node;
8779 if (vam->graph_node_index_by_name == 0) {
8780 fformat (vam->ofp, "Node table empty, issue get_node_graph...\n");
8784 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) {
8785 if (unformat (line_input, "%s", &node_to_find)) {
8786 vec_add1 (node_to_find, 0);
8787 p = hash_get_mem (vam->graph_node_index_by_name, node_to_find);
8789 fformat (vam->ofp, "%s not found...\n", node_to_find);
8792 node = vam->graph_nodes[p[0]];
8793 fformat (vam->ofp, "[%d] %s\n", p[0], node->name);
8794 for (j = 0; j < vec_len (node->next_nodes); j++) {
8795 if (node->next_nodes[j] != ~0) {
8796 next_node = vam->graph_nodes[node->next_nodes[j]];
8797 fformat (vam->ofp, " [%d] %s\n", j, next_node->name);
8803 clib_warning ("parse error '%U'", format_unformat_error,
8809 vec_free(node_to_find);
8817 static int script (vat_main_t * vam)
8820 char * save_current_file;
8821 unformat_input_t save_input;
8822 jmp_buf save_jump_buf;
8823 u32 save_line_number;
8825 FILE * new_fp, * save_ifp;
8827 if (unformat (vam->input, "%s", &s)) {
8828 new_fp = fopen ((char *)s, "r");
8830 errmsg ("Couldn't open script file %s\n", s);
8835 errmsg ("Missing script name\n");
8839 memcpy (&save_input, &vam->input, sizeof (save_input));
8840 memcpy (&save_jump_buf, &vam->jump_buf, sizeof (save_jump_buf));
8841 save_ifp = vam->ifp;
8842 save_line_number = vam->input_line_number;
8843 save_current_file = (char *) vam->current_file;
8845 vam->input_line_number = 0;
8847 vam->current_file = s;
8850 memcpy (&vam->input, &save_input, sizeof (vam->input));
8851 memcpy (&vam->jump_buf, &save_jump_buf, sizeof (save_jump_buf));
8852 vam->ifp = save_ifp;
8853 vam->input_line_number = save_line_number;
8854 vam->current_file = (u8 *) save_current_file;
8860 static int echo (vat_main_t * vam)
8862 fformat (vam->ofp, "%v", vam->input->buffer);
8866 /* List of API message constructors, CLI names map to api_xxx */
8867 #define foreach_vpe_api_msg \
8868 _(create_loopback,"[mac <mac-addr>]") \
8869 _(sw_interface_dump,"") \
8870 _(sw_interface_set_flags, \
8871 "<intfc> | sw_if_index <id> admin-up | admin-down link-up | link down") \
8872 _(sw_interface_add_del_address, \
8873 "<intfc> | sw_if_index <id> <ip4-address> | <ip6-address> [del] [del-all] ") \
8874 _(sw_interface_set_table, \
8875 "<intfc> | sw_if_index <id> vrf <table-id> [ipv6]") \
8876 _(sw_interface_set_vpath, \
8877 "<intfc> | sw_if_index <id> enable | disable") \
8878 _(sw_interface_set_l2_xconnect, \
8879 "rx <intfc> | rx_sw_if_index <id> tx <intfc> | tx_sw_if_index <id>\n" \
8880 "enable | disable") \
8881 _(sw_interface_set_l2_bridge, \
8882 "rx <intfc> | rx_sw_if_index <id> bd_id <bridge-domain-id>\n" \
8883 "[shg <split-horizon-group>] [bvi]\n" \
8884 "enable | disable") \
8885 _(bridge_domain_add_del, \
8886 "bd_id <bridge-domain-id> [flood 1|0] [uu-flood 1|0] [forward 1|0] [learn 1|0] [arp-term 1|0] [del]\n")\
8887 _(bridge_domain_dump, "[bd_id <bridge-domain-id>]\n") \
8889 "mac <mac-addr> bd_id <bridge-domain-id> [del] | sw_if <intfc> | sw_if_index <id> [static] [filter] [bvi]\n") \
8891 "sw_if <intfc> | sw_if_index <id> [learn] [forward] [uu-flood] [flood]\n") \
8893 "bd_id <bridge-domain-id> [learn] [forward] [uu-flood] [flood] [arp-term] [disable]\n") \
8895 "tapname <name> mac <mac-addr> | random-mac") \
8897 "<vpp-if-name> | sw_if_index <id> tapname <name> mac <mac-addr> | random-mac") \
8899 "<vpp-if-name> | sw_if_index <id>") \
8900 _(sw_interface_tap_dump, "") \
8901 _(ip_add_del_route, \
8902 "<addr>/<mask> via <addr> [vrf <n>]\n" \
8903 "[<intfc> | sw_if_index <id>] [resolve-attempts <n>]\n" \
8904 "[weight <n>] [drop] [local] [classify <n>] [del]\n" \
8905 "[multipath] [count <n>]") \
8906 _(proxy_arp_add_del, \
8907 "<lo-ip4-addr> - <hi-ip4-addr> [vrf <n>] [del]") \
8908 _(proxy_arp_intfc_enable_disable, \
8909 "<intfc> | sw_if_index <id> enable | disable") \
8910 _(mpls_add_del_encap, \
8911 "label <n> dst <ip4-addr> [vrf <n>] [del]") \
8912 _(mpls_add_del_decap, \
8913 "label <n> [rx_vrf_id <n>] [tx_vrf_id] [s-bit-clear][del]") \
8914 _(mpls_gre_add_del_tunnel, \
8915 "inner_vrf_id <n> outer_vrf_id <n> src <ip4-address> dst <ip4-address>\n" \
8916 "adj <ip4-address>/<mask-width> [del]") \
8917 _(sw_interface_set_unnumbered, \
8918 "<intfc> | sw_if_index <id> unnum_if_index <id> [del]") \
8919 _(ip_neighbor_add_del, \
8920 "<intfc> | sw_if_index <id> dst <ip46-address> mac <mac-addr>") \
8921 _(reset_vrf, "vrf <id> [ipv6]") \
8922 _(create_vlan_subif, "<intfc> | sw_if_index <id> vlan <n>") \
8923 _(create_subif, "<intfc> | sw_if_index <id> sub_id <n>\n" \
8924 "[outer_vlan_id <n>][inner_vlan_id <n>]\n" \
8925 "[no_tags][one_tag][two_tags][dot1ad][exact_match][default_sub]\n" \
8926 "[outer_vlan_id_any][inner_vlan_id_any]") \
8927 _(oam_add_del, "src <ip4-address> dst <ip4-address> [vrf <n>] [del]") \
8928 _(reset_fib, "vrf <n> [ipv6]") \
8929 _(dhcp_proxy_config, \
8930 "svr <v46-address> src <v46-address>\n" \
8931 "insert-cid <n> [del]") \
8932 _(dhcp_proxy_config_2, \
8933 "svr <v46-address> src <v46-address>\n" \
8934 "rx_vrf_id <nn> server_vrf_id <nn> insert-cid <n> [del]") \
8935 _(dhcp_proxy_set_vss, \
8936 "tbl_id <n> fib_id <n> oui <n> [ipv6] [del]") \
8937 _(dhcp_client_config, \
8938 "<intfc> | sw_if_index <id> [hostname <name>] [disable_event] [del]") \
8939 _(set_ip_flow_hash, \
8940 "vrf <n> [src] [dst] [sport] [dport] [proto] [reverse] [ipv6]") \
8941 _(sw_interface_ip6_enable_disable, \
8942 "<intfc> | sw_if_index <id> enable | disable") \
8943 _(sw_interface_ip6_set_link_local_address, \
8944 "<intfc> | sw_if_index <id> <ip6-address>/<mask-width>") \
8945 _(sw_interface_ip6nd_ra_prefix, \
8946 "<intfc> | sw_if_index <id> <ip6-address>/<mask-width>\n" \
8947 "val_life <n> pref_life <n> [def] [noadv] [offl] [noauto]\n" \
8948 "[nolink] [isno]") \
8949 _(sw_interface_ip6nd_ra_config, \
8950 "<intfc> | sw_if_index <id> [maxint <n>] [minint <n>]\n" \
8951 "[life <n>] [count <n>] [interval <n>] [surpress]\n" \
8952 "[managed] [other] [ll] [send] [cease] [isno] [def]") \
8953 _(set_arp_neighbor_limit, "arp_nbr_limit <n> [ipv6]") \
8954 _(l2_patch_add_del, \
8955 "rx <intfc> | rx_sw_if_index <id> tx <intfc> | tx_sw_if_index <id>\n" \
8956 "enable | disable") \
8957 _(mpls_ethernet_add_del_tunnel, \
8958 "tx <intfc> | tx_sw_if_index <n> dst <mac-addr>\n" \
8959 "adj <ip4-addr>/<mw> dst <mac-addr> [del]") \
8960 _(mpls_ethernet_add_del_tunnel_2, \
8961 "inner_vrf_id <n> outer_vrf_id <n> next-hop <ip4-addr>\n" \
8962 "resolve-attempts <n> resolve-if-needed 0 | 1 [del]") \
8963 _(sr_tunnel_add_del, \
8964 "src <ip6-addr> dst <ip6-addr>/<mw> (next <ip6-addr>)+\n" \
8965 " [tag <ip6-addr>]* [clean] [reroute]") \
8966 _(classify_add_del_table, \
8967 "buckets <nn> [skip <n>] [match <n>] [memory_size <nn-bytes>]\n" \
8968 "[del] mask <mask-value>\n" \
8969 " [l2-miss-next | miss-next | acl-miss-next] <name|nn>") \
8970 _(classify_add_del_session, \
8971 "[hit-next|l2-hit-next|acl-hit-next] <name|nn> table-index <nn>\n" \
8972 "skip_n <nn> match_n <nn> match [hex] [l2] [l3 [ip4|ip6]]") \
8973 _(classify_set_interface_ip_table, \
8974 "<intfc> | sw_if_index <nn> table <nn>") \
8975 _(classify_set_interface_l2_tables, \
8976 "<intfc> | sw_if_index <nn> [ip4-table <nn>] [ip6-table <nn>]\n" \
8977 " [other-table <nn>]") \
8978 _(get_node_index, "node <node-name") \
8979 _(add_node_next, "node <node-name> next <next-node-name>") \
8980 _(l2tpv3_create_tunnel, \
8981 "client_address <ip6-addr> our_address <ip6-addr>\n" \
8982 "[local_session_id <nn>][remote_session_id <nn>][local_cookie <nn>]\n"\
8983 "[remote_cookie <nn>]\n[l2-sublayer-preset]\n") \
8984 _(l2tpv3_set_tunnel_cookies, \
8985 "<intfc> | sw_if_index <nn> [new_local_cookie <nn>]\n" \
8986 "[new_remote_cookie <nn>]\n") \
8987 _(l2tpv3_interface_enable_disable, \
8988 "<intfc> | sw_if_index <nn> enable | disable") \
8989 _(l2tpv3_set_lookup_key, \
8990 "lookup_v6_src | lookup_v6_dst | lookup_session_id") \
8991 _(sw_if_l2tpv3_tunnel_dump, "") \
8992 _(vxlan_add_del_tunnel, \
8993 "src <ip4-addr> dst <ip4-addr> vni [encap-vrf-id <nn>]\n" \
8994 " [decap-next l2|ip4|ip6] [del]") \
8995 _(vxlan_tunnel_dump, "[<intfc> | sw_if_index <nn>]") \
8996 _(l2_fib_clear_table, "") \
8997 _(l2_interface_efp_filter, "sw_if_index <nn> enable | disable") \
8998 _(l2_interface_vlan_tag_rewrite, \
8999 "<intfc> | sw_if_index <nn> \n" \
9000 "[disable][push-[1|2]][pop-[1|2]][translate-1-[1|2]] \n" \
9001 "[translate-2-[1|2]] [push_dot1q 0] tag1 <nn> tag2 <nn>") \
9002 _(create_vhost_user_if, \
9003 "socket <filename> [server] [renumber <dev_instance>] " \
9004 "[mac <mac_address>]") \
9005 _(modify_vhost_user_if, \
9006 "<intfc> | sw_if_index <nn> socket <filename>\n" \
9007 "[server] [renumber <dev_instance>]") \
9008 _(delete_vhost_user_if, "<intfc> | sw_if_index <nn>") \
9009 _(sw_interface_vhost_user_dump, "") \
9010 _(show_version, "") \
9011 _(nsh_gre_add_del_tunnel, \
9012 "src <ip4-addr> dst <ip4-addr>" \
9013 "c1 <nn> c2 <nn> c3 <nn> c4 <nn> spi <nn> si <nn>\n" \
9014 "[encap-fib-id <nn>] [decap-fib-id <nn>] [o-bit <1|0>]\n" \
9015 "[c-bit <1|0>] [md-type <nn>][next-ip4][next-ip6][next-ethernet]\n" \
9016 "[tlv <xx>][del]") \
9017 _(nsh_vxlan_gpe_add_del_tunnel, \
9018 "src <ip4-addr> dst <ip4-addr> vni <nn>\n" \
9019 "c1 <nn> c2 <nn> c3 <nn> c4 <nn> spi <nn> si <nn>\n" \
9020 "[encap-vrf-id <nn>] [decap-vrf-id <nn>] [o-bit <1|0>]\n" \
9021 "[c-bit <1|0>] [md-type <nn>][next-ip4][next-ip6][next-ethernet]\n" \
9022 "[tlv <xx>][del]") \
9023 _(l2_fib_table_dump, "bd_id <bridge-domain-id>") \
9024 _(lisp_gpe_add_del_tunnel, \
9025 "src <ip4-addr> dst <ip4-addr> iid <nn>|iidx <0xnn>\n" \
9026 "[encap-vrf-id <nn>] [decap-vrf-id <nn>]\n" \
9027 "[n-bit][l-bit][e-bit][v-bit][i-bit][p-bit][not-p-bit][o-bit]\n" \
9028 "[next-ip4][next-ip6][next-ethernet][next-nsh]\n" \
9029 "[decap-next [ip4|ip6|ethernet|nsh-encap|<nn>]][del]") \
9030 _(interface_name_renumber, \
9031 "<intfc> | sw_if_index <nn> new_show_dev_instance <nn>") \
9032 _(input_acl_set_interface, \
9033 "<intfc> | sw_if_index <nn> [ip4-table <nn>] [ip6-table <nn>]\n" \
9034 " [l2-table <nn>] [del]") \
9035 _(want_ip4_arp_events, "address <ip4-address> [del]") \
9036 _(ip_address_dump, "(ipv4 | ipv6) (<intfc> | sw_if_index <id>)") \
9037 _(ip_dump, "ipv4 | ipv6") \
9038 _(ipsec_spd_add_del, "spd_id <n> [del]") \
9039 _(ipsec_interface_add_del_spd, "(<intfc> | sw_if_index <id>)\n" \
9041 _(ipsec_sad_add_del_entry, "sad_id <n> spi <n> crypto_alg <alg>\n" \
9042 " crypto_key <hex> tunnel_src <ip4|ip6> tunnel_dst <ip4|ip6>\n" \
9043 " integ_alg <alg> integ_key <hex>") \
9044 _(ipsec_spd_add_del_entry, "spd_id <n> priority <n> action <action>\n" \
9045 " (inbound|outbound) [sa_id <n>] laddr_start <ip4|ip6>\n" \
9046 " laddr_stop <ip4|ip6> raddr_start <ip4|ip6> raddr_stop <ip4|ip6>\n" \
9047 " [lport_start <n> lport_stop <n>] [rport_start <n> rport_stop <n>]" )\
9048 _(ipsec_sa_set_key, "sa_id <n> crypto_key <hex> integ_key <hex>") \
9049 _(delete_loopback,"sw_if_index <nn>") \
9050 _(bd_ip_mac_add_del, "bd_id <bridge-domain-id> <ip4/6-addr> <mac-addr> [del]") \
9052 "ip4-pfx <ip4pfx> ip6-pfx <ip6pfx> " \
9053 "ip6-src <ip6addr> " \
9054 "ea-bits-len <n> psid-offset <n> psid-len <n>") \
9055 _(map_del_domain, "index <n>") \
9056 _(map_add_del_rule, \
9057 "index <n> psid <n> dst <ip6addr> [del]") \
9058 _(map_domain_dump, "") \
9059 _(map_rule_dump, "index <map-domain>") \
9060 _(want_interface_events, "enable|disable") \
9061 _(want_stats,"enable|disable") \
9062 _(get_first_msg_id, "client <name>") \
9063 _(cop_interface_enable_disable, "<intfc> | sw_if_index <nn> [disable]") \
9064 _(cop_whitelist_enable_disable, "<intfc> | sw_if_index <nn>\n" \
9065 "fib-id <nn> [ip4][ip6][default]") \
9066 _(get_node_graph, " ")
9068 /* List of command functions, CLI names map directly to functions */
9069 #define foreach_cli_function \
9070 _(comment, "usage: comment <ignore-rest-of-line>") \
9071 _(dump_interface_table, "usage: dump_interface_table") \
9072 _(dump_sub_interface_table, "usage: dump_sub_interface_table") \
9073 _(dump_ipv4_table, "usage: dump_ipv4_table") \
9074 _(dump_ipv6_table, "usage: dump_ipv6_table") \
9075 _(dump_stats_table, "usage: dump_stats_table") \
9076 _(dump_macro_table, "usage: dump_macro_table ") \
9077 _(dump_node_table, "usage: dump_node_table") \
9078 _(echo, "usage: echo <message>") \
9079 _(exec, "usage: exec <vpe-debug-CLI-command>") \
9080 _(help, "usage: help") \
9081 _(q, "usage: quit") \
9082 _(quit, "usage: quit") \
9083 _(search_node_table, "usage: search_node_table <name>...") \
9084 _(set, "usage: set <variable-name> <value>") \
9085 _(script, "usage: script <file-name>") \
9086 _(unset, "usage: unset <variable-name>")
9089 static void vl_api_##n##_t_handler_uni \
9090 (vl_api_##n##_t * mp) \
9092 vat_main_t * vam = &vat_main; \
9093 if (vam->json_output) { \
9094 vl_api_##n##_t_handler_json(mp); \
9096 vl_api_##n##_t_handler(mp); \
9099 foreach_vpe_api_reply_msg;
9102 void vat_api_hookup (vat_main_t *vam)
9105 vl_msg_api_set_handlers(VL_API_##N, #n, \
9106 vl_api_##n##_t_handler_uni, \
9108 vl_api_##n##_t_endian, \
9109 vl_api_##n##_t_print, \
9110 sizeof(vl_api_##n##_t), 1);
9111 foreach_vpe_api_reply_msg;
9114 vl_msg_api_set_first_available_msg_id (VL_MSG_FIRST_AVAILABLE);
9116 vam->sw_if_index_by_interface_name =
9117 hash_create_string (0, sizeof (uword));
9119 vam->function_by_name =
9120 hash_create_string (0, sizeof(uword));
9123 hash_create_string (0, sizeof(uword));
9125 /* API messages we can send */
9126 #define _(n,h) hash_set_mem (vam->function_by_name, #n, api_##n);
9127 foreach_vpe_api_msg;
9131 #define _(n,h) hash_set_mem (vam->help_by_name, #n, h);
9132 foreach_vpe_api_msg;
9136 #define _(n,h) hash_set_mem (vam->function_by_name, #n, n);
9137 foreach_cli_function;
9141 #define _(n,h) hash_set_mem (vam->help_by_name, #n, h);
9142 foreach_cli_function;
9146 #undef vl_api_version
9147 #define vl_api_version(n,v) static u32 vpe_api_version = v;
9148 #include <api/vpe.api.h>
9149 #undef vl_api_version
9151 void vl_client_add_api_signatures (vl_api_memclnt_create_t *mp)
9154 * Send the main API signature in slot 0. This bit of code must
9155 * match the checks in ../vpe/api/api.c: vl_msg_api_version_check().
9157 mp->api_versions[0] = clib_host_to_net_u32 (vpe_api_version);