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, "sub_id", ntohl(mp->sub_id));
591 vat_json_object_add_uint(node, "sub_dot1ad", mp->sub_dot1ad);
592 vat_json_object_add_uint(node, "sub_number_of_tags", mp->sub_number_of_tags);
593 vat_json_object_add_uint(node, "sub_outer_vlan_id", ntohs(mp->sub_outer_vlan_id));
594 vat_json_object_add_uint(node, "sub_inner_vlan_id", ntohs(mp->sub_inner_vlan_id));
595 vat_json_object_add_uint(node, "sub_exact_match", mp->sub_exact_match);
596 vat_json_object_add_uint(node, "sub_default", mp->sub_default);
597 vat_json_object_add_uint(node, "sub_outer_vlan_id_any", mp->sub_outer_vlan_id_any);
598 vat_json_object_add_uint(node, "sub_inner_vlan_id_any", mp->sub_inner_vlan_id_any);
599 vat_json_object_add_uint(node, "vtr_op", ntohl(mp->vtr_op));
600 vat_json_object_add_uint(node, "vtr_push_dot1q", ntohl(mp->vtr_push_dot1q));
601 vat_json_object_add_uint(node, "vtr_tag1", ntohl(mp->vtr_tag1));
602 vat_json_object_add_uint(node, "vtr_tag2", ntohl(mp->vtr_tag2));
605 static void vl_api_sw_interface_set_flags_t_handler
606 (vl_api_sw_interface_set_flags_t * mp)
608 vat_main_t * vam = &vat_main;
609 if (vam->interface_event_display)
610 errmsg ("interface flags: sw_if_index %d %s %s\n",
611 ntohl(mp->sw_if_index),
612 mp->admin_up_down ? "admin-up" : "admin-down",
613 mp->link_up_down ? "link-up" : "link-down");
616 static void vl_api_sw_interface_set_flags_t_handler_json
617 (vl_api_sw_interface_set_flags_t * mp)
619 /* JSON output not supported */
622 static void vl_api_cli_reply_t_handler
623 (vl_api_cli_reply_t * mp)
625 vat_main_t * vam = &vat_main;
626 i32 retval = ntohl(mp->retval);
628 vam->retval = retval;
629 vam->shmem_result = (u8 *) mp->reply_in_shmem;
630 vam->result_ready = 1;
633 static void vl_api_cli_reply_t_handler_json
634 (vl_api_cli_reply_t * mp)
636 vat_main_t * vam = &vat_main;
637 vat_json_node_t node;
638 api_main_t * am = &api_main;
642 vat_json_init_object(&node);
643 vat_json_object_add_int(&node, "retval", ntohl(mp->retval));
644 vat_json_object_add_uint(&node, "reply_in_shmem",
645 ntohl(mp->reply_in_shmem));
646 /* Toss the shared-memory original... */
647 pthread_mutex_lock (&am->vlib_rp->mutex);
648 oldheap = svm_push_data_heap (am->vlib_rp);
650 reply = (u8 *)(mp->reply_in_shmem);
653 svm_pop_heap (oldheap);
654 pthread_mutex_unlock (&am->vlib_rp->mutex);
656 vat_json_print(vam->ofp, &node);
657 vat_json_free(&node);
659 vam->retval = ntohl(mp->retval);
660 vam->result_ready = 1;
663 static void vl_api_classify_add_del_table_reply_t_handler
664 (vl_api_classify_add_del_table_reply_t * mp)
666 vat_main_t * vam = &vat_main;
667 i32 retval = ntohl(mp->retval);
668 if (vam->async_mode) {
669 vam->async_errors += (retval < 0);
671 vam->retval = retval;
672 vam->result_ready = 1;
674 ((mp->new_table_index != 0xFFFFFFFF) ||
675 (mp->skip_n_vectors != 0xFFFFFFFF) ||
676 (mp->match_n_vectors != 0xFFFFFFFF)))
678 * Note: this is just barely thread-safe, depends on
679 * the main thread spinning waiting for an answer...
681 errmsg ("new index %d, skip_n_vectors %d, match_n_vectors %d\n",
682 ntohl(mp->new_table_index),
683 ntohl(mp->skip_n_vectors), ntohl(mp->match_n_vectors));
687 static void vl_api_classify_add_del_table_reply_t_handler_json
688 (vl_api_classify_add_del_table_reply_t * mp)
690 vat_main_t * vam = &vat_main;
691 vat_json_node_t node;
693 vat_json_init_object(&node);
694 vat_json_object_add_int(&node, "retval", ntohl(mp->retval));
695 vat_json_object_add_uint(&node, "new_table_index", ntohl(mp->new_table_index));
696 vat_json_object_add_uint(&node, "skip_n_vectors", ntohl(mp->skip_n_vectors));
697 vat_json_object_add_uint(&node, "match_n_vectors", ntohl(mp->match_n_vectors));
699 vat_json_print(vam->ofp, &node);
700 vat_json_free(&node);
702 vam->retval = ntohl(mp->retval);
703 vam->result_ready = 1;
706 static void vl_api_get_node_index_reply_t_handler
707 (vl_api_get_node_index_reply_t * mp)
709 vat_main_t * vam = &vat_main;
710 i32 retval = ntohl(mp->retval);
711 if (vam->async_mode) {
712 vam->async_errors += (retval < 0);
714 vam->retval = retval;
715 vam->result_ready = 1;
717 errmsg ("node index %d\n", ntohl(mp->node_index));
721 static void vl_api_get_node_index_reply_t_handler_json
722 (vl_api_get_node_index_reply_t * mp)
724 vat_main_t * vam = &vat_main;
725 vat_json_node_t node;
727 vat_json_init_object(&node);
728 vat_json_object_add_int(&node, "retval", ntohl(mp->retval));
729 vat_json_object_add_uint(&node, "node_index", ntohl(mp->node_index));
731 vat_json_print(vam->ofp, &node);
732 vat_json_free(&node);
734 vam->retval = ntohl(mp->retval);
735 vam->result_ready = 1;
738 static void vl_api_add_node_next_reply_t_handler
739 (vl_api_add_node_next_reply_t * mp)
741 vat_main_t * vam = &vat_main;
742 i32 retval = ntohl(mp->retval);
743 if (vam->async_mode) {
744 vam->async_errors += (retval < 0);
746 vam->retval = retval;
747 vam->result_ready = 1;
749 errmsg ("next index %d\n", ntohl(mp->next_index));
753 static void vl_api_add_node_next_reply_t_handler_json
754 (vl_api_add_node_next_reply_t * mp)
756 vat_main_t * vam = &vat_main;
757 vat_json_node_t node;
759 vat_json_init_object(&node);
760 vat_json_object_add_int(&node, "retval", ntohl(mp->retval));
761 vat_json_object_add_uint(&node, "next_index", ntohl(mp->next_index));
763 vat_json_print(vam->ofp, &node);
764 vat_json_free(&node);
766 vam->retval = ntohl(mp->retval);
767 vam->result_ready = 1;
770 static void vl_api_mpls_gre_add_del_tunnel_reply_t_handler
771 (vl_api_mpls_gre_add_del_tunnel_reply_t * mp)
773 vat_main_t * vam = &vat_main;
774 i32 retval = ntohl(mp->retval);
775 u32 sw_if_index = ntohl(mp->tunnel_sw_if_index);
777 if (retval >= 0 && sw_if_index != (u32)~0) {
778 errmsg ("tunnel_sw_if_index %d\n", sw_if_index);
780 vam->retval = retval;
781 vam->result_ready = 1;
784 static void vl_api_mpls_gre_add_del_tunnel_reply_t_handler_json
785 (vl_api_mpls_gre_add_del_tunnel_reply_t * mp)
787 vat_main_t * vam = &vat_main;
788 vat_json_node_t node;
790 vat_json_init_object(&node);
791 vat_json_object_add_int(&node, "retval", ntohl(mp->retval));
792 vat_json_object_add_uint(&node, "tunnel_sw_if_index", ntohl(mp->tunnel_sw_if_index));
794 vat_json_print(vam->ofp, &node);
795 vat_json_free(&node);
797 vam->retval = ntohl(mp->retval);
798 vam->result_ready = 1;
801 static void vl_api_nsh_gre_add_del_tunnel_reply_t_handler
802 (vl_api_nsh_gre_add_del_tunnel_reply_t * mp)
804 vat_main_t * vam = &vat_main;
805 i32 retval = ntohl(mp->retval);
806 u32 sw_if_index = ntohl(mp->sw_if_index);
808 if (retval >= 0 && sw_if_index != (u32)~0) {
809 errmsg ("sw_if_index %d\n", ntohl(mp->sw_if_index));
811 vam->retval = retval;
812 vam->result_ready = 1;
815 static void vl_api_nsh_gre_add_del_tunnel_reply_t_handler_json
816 (vl_api_nsh_gre_add_del_tunnel_reply_t * mp)
818 vat_main_t * vam = &vat_main;
819 vat_json_node_t node;
821 vat_json_init_object(&node);
822 vat_json_object_add_int(&node, "retval", ntohl(mp->retval));
823 vat_json_object_add_uint(&node, "sw_if_index", ntohl(mp->sw_if_index));
825 vat_json_print(vam->ofp, &node);
826 vat_json_free(&node);
828 vam->retval = ntohl(mp->retval);
829 vam->result_ready = 1;
832 static void vl_api_nsh_vxlan_gpe_add_del_tunnel_reply_t_handler
833 (vl_api_nsh_vxlan_gpe_add_del_tunnel_reply_t * mp)
835 vat_main_t * vam = &vat_main;
836 i32 retval = ntohl(mp->retval);
837 u32 sw_if_index = ntohl(mp->sw_if_index);
839 if (retval >= 0 && sw_if_index != (u32)~0) {
840 errmsg ("sw_if_index %d\n", ntohl(mp->sw_if_index));
842 vam->retval = retval;
843 vam->result_ready = 1;
846 static void vl_api_nsh_vxlan_gpe_add_del_tunnel_reply_t_handler_json
847 (vl_api_nsh_vxlan_gpe_add_del_tunnel_reply_t * mp)
849 vat_main_t * vam = &vat_main;
850 vat_json_node_t node;
852 vat_json_init_object(&node);
853 vat_json_object_add_int(&node, "retval", ntohl(mp->retval));
854 vat_json_object_add_uint(&node, "sw_if_index", ntohl(mp->sw_if_index));
856 vat_json_print(vam->ofp, &node);
857 vat_json_free(&node);
859 vam->retval = ntohl(mp->retval);
860 vam->result_ready = 1;
863 static void vl_api_lisp_gpe_add_del_tunnel_reply_t_handler
864 (vl_api_lisp_gpe_add_del_tunnel_reply_t * mp)
866 vat_main_t * vam = &vat_main;
867 i32 retval = ntohl(mp->retval);
868 u32 sw_if_index = ntohl(mp->sw_if_index);
870 if (retval >= 0 && sw_if_index != (u32)~0) {
871 errmsg ("sw_if_index %d\n", ntohl(mp->sw_if_index));
873 vam->retval = retval;
874 vam->result_ready = 1;
877 static void vl_api_lisp_gpe_add_del_tunnel_reply_t_handler_json
878 (vl_api_lisp_gpe_add_del_tunnel_reply_t * mp)
880 vat_main_t * vam = &vat_main;
881 vat_json_node_t node;
883 vat_json_init_object(&node);
884 vat_json_object_add_int(&node, "retval", ntohl(mp->retval));
885 vat_json_object_add_uint(&node, "sw_if_index", ntohl(mp->sw_if_index));
887 vat_json_print(vam->ofp, &node);
888 vat_json_free(&node);
890 vam->retval = ntohl(mp->retval);
891 vam->result_ready = 1;
894 static void vl_api_show_version_reply_t_handler
895 (vl_api_show_version_reply_t * mp)
897 vat_main_t * vam = &vat_main;
898 i32 retval = ntohl(mp->retval);
901 errmsg (" program: %s\n", mp->program);
902 errmsg (" version: %s\n", mp->version);
903 errmsg (" build date: %s\n", mp->build_date);
904 errmsg ("build directory: %s\n", mp->build_directory);
906 vam->retval = retval;
907 vam->result_ready = 1;
910 static void vl_api_show_version_reply_t_handler_json
911 (vl_api_show_version_reply_t * mp)
913 vat_main_t * vam = &vat_main;
914 vat_json_node_t node;
916 vat_json_init_object(&node);
917 vat_json_object_add_int(&node, "retval", ntohl(mp->retval));
918 vat_json_object_add_string_copy(&node, "program", mp->program);
919 vat_json_object_add_string_copy(&node, "version", mp->version);
920 vat_json_object_add_string_copy(&node, "build_date", mp->build_date);
921 vat_json_object_add_string_copy(&node, "build_directory", mp->build_directory);
923 vat_json_print(vam->ofp, &node);
924 vat_json_free(&node);
926 vam->retval = ntohl(mp->retval);
927 vam->result_ready = 1;
930 static void vl_api_ip4_arp_event_t_handler
931 (vl_api_ip4_arp_event_t * mp)
933 vat_main_t * vam = &vat_main;
934 errmsg ("arp event: address %U new mac %U sw_if_index %d\n",
935 format_ip4_address, &mp->address,
936 format_ethernet_address, mp->new_mac, mp->sw_if_index);
939 static void vl_api_ip4_arp_event_t_handler_json
940 (vl_api_ip4_arp_event_t * mp)
942 /* JSON output not supported */
946 * Special-case: build the bridge domain table, maintain
947 * the next bd id vbl.
949 static void vl_api_bridge_domain_details_t_handler
950 (vl_api_bridge_domain_details_t * mp)
952 vat_main_t * vam = &vat_main;
953 u32 n_sw_ifs = ntohl (mp->n_sw_ifs);
955 fformat (vam->ofp, "\n%-3s %-3s %-3s %-3s %-3s %-3s\n",
956 " ID", "LRN", "FWD", "FLD", "BVI", "#IF");
958 fformat (vam->ofp, "%3d %3d %3d %3d %3d %3d\n",
959 ntohl (mp->bd_id), mp->learn, mp->forward,
960 mp->flood, ntohl (mp->bvi_sw_if_index), n_sw_ifs);
963 fformat (vam->ofp, "\n\n%s %s %s\n", "sw_if_index", "SHG",
967 static void vl_api_bridge_domain_details_t_handler_json
968 (vl_api_bridge_domain_details_t * mp)
970 vat_main_t * vam = &vat_main;
971 vat_json_node_t *node, *array = NULL;
973 if (VAT_JSON_ARRAY != vam->json_tree.type) {
974 ASSERT(VAT_JSON_NONE == vam->json_tree.type);
975 vat_json_init_array(&vam->json_tree);
977 node = vat_json_array_add(&vam->json_tree);
979 vat_json_init_object(node);
980 vat_json_object_add_uint(node, "bd_id", ntohl(mp->bd_id));
981 vat_json_object_add_uint(node, "flood", mp->flood);
982 vat_json_object_add_uint(node, "forward", mp->forward);
983 vat_json_object_add_uint(node, "learn", mp->learn);
984 vat_json_object_add_uint(node, "bvi_sw_if_index", ntohl(mp->bvi_sw_if_index));
985 vat_json_object_add_uint(node, "n_sw_ifs", ntohl(mp->n_sw_ifs));
986 array = vat_json_object_add(node, "sw_if");
987 vat_json_init_array(array);
991 * Special-case: build the bridge domain sw if table.
993 static void vl_api_bridge_domain_sw_if_details_t_handler
994 (vl_api_bridge_domain_sw_if_details_t * mp)
996 vat_main_t * vam = &vat_main;
1001 sw_if_index = ntohl (mp->sw_if_index);
1002 hash_foreach_pair (p, vam->sw_if_index_by_interface_name,
1004 if ((u32) p->value[0] == sw_if_index) {
1005 sw_if_name = (u8 *)(p->key);
1010 fformat (vam->ofp, "%7d %3d %s", sw_if_index,
1011 mp->shg, sw_if_name ? (char *)sw_if_name :
1012 "sw_if_index not found!");
1015 static void vl_api_bridge_domain_sw_if_details_t_handler_json
1016 (vl_api_bridge_domain_sw_if_details_t * mp)
1018 vat_main_t * vam = &vat_main;
1019 vat_json_node_t *node = NULL;
1020 uword last_index = 0;
1022 ASSERT(VAT_JSON_ARRAY == vam->json_tree.type);
1023 ASSERT(vec_len(vam->json_tree.array) >= 1);
1024 last_index = vec_len(vam->json_tree.array) - 1;
1025 node = &vam->json_tree.array[last_index];
1026 node = vat_json_object_get_element(node, "sw_if");
1027 ASSERT(NULL != node);
1028 node = vat_json_array_add(node);
1030 vat_json_init_object(node);
1031 vat_json_object_add_uint(node, "bd_id", ntohl(mp->bd_id));
1032 vat_json_object_add_uint(node, "sw_if_index", ntohl(mp->sw_if_index));
1033 vat_json_object_add_uint(node, "shg", mp->shg);
1036 static void vl_api_control_ping_reply_t_handler
1037 (vl_api_control_ping_reply_t * mp)
1039 vat_main_t * vam = &vat_main;
1040 i32 retval = ntohl(mp->retval);
1041 if (vam->async_mode) {
1042 vam->async_errors += (retval < 0);
1044 vam->retval = retval;
1045 vam->result_ready = 1;
1049 static void vl_api_control_ping_reply_t_handler_json
1050 (vl_api_control_ping_reply_t * mp)
1052 vat_main_t * vam = &vat_main;
1053 i32 retval = ntohl(mp->retval);
1055 if (VAT_JSON_NONE != vam->json_tree.type) {
1056 vat_json_print(vam->ofp, &vam->json_tree);
1057 vat_json_free(&vam->json_tree);
1058 vam->json_tree.type = VAT_JSON_NONE;
1061 vat_json_init_array(&vam->json_tree);
1062 vat_json_print(vam->ofp, &vam->json_tree);
1063 vam->json_tree.type = VAT_JSON_NONE;
1066 vam->retval = retval;
1067 vam->result_ready = 1;
1070 static void vl_api_l2_flags_reply_t_handler
1071 (vl_api_l2_flags_reply_t * mp)
1073 vat_main_t * vam = &vat_main;
1074 i32 retval = ntohl(mp->retval);
1075 if (vam->async_mode) {
1076 vam->async_errors += (retval < 0);
1078 vam->retval = retval;
1079 vam->result_ready = 1;
1083 static void vl_api_l2_flags_reply_t_handler_json
1084 (vl_api_l2_flags_reply_t * mp)
1086 vat_main_t * vam = &vat_main;
1087 vat_json_node_t node;
1089 vat_json_init_object(&node);
1090 vat_json_object_add_int(&node, "retval", ntohl(mp->retval));
1091 vat_json_object_add_uint(&node, "resulting_feature_bitmap", ntohl(mp->resulting_feature_bitmap));
1093 vat_json_print(vam->ofp, &node);
1094 vat_json_free(&node);
1096 vam->retval = ntohl(mp->retval);
1097 vam->result_ready = 1;
1100 static void vl_api_bridge_flags_reply_t_handler
1101 (vl_api_bridge_flags_reply_t * mp)
1103 vat_main_t * vam = &vat_main;
1104 i32 retval = ntohl(mp->retval);
1105 if (vam->async_mode) {
1106 vam->async_errors += (retval < 0);
1108 vam->retval = retval;
1109 vam->result_ready = 1;
1113 static void vl_api_bridge_flags_reply_t_handler_json
1114 (vl_api_bridge_flags_reply_t * mp)
1116 vat_main_t * vam = &vat_main;
1117 vat_json_node_t node;
1119 vat_json_init_object(&node);
1120 vat_json_object_add_int(&node, "retval", ntohl(mp->retval));
1121 vat_json_object_add_uint(&node, "resulting_feature_bitmap", ntohl(mp->resulting_feature_bitmap));
1123 vat_json_print(vam->ofp, &node);
1124 vat_json_free(&node);
1126 vam->retval = ntohl(mp->retval);
1127 vam->result_ready = 1;
1130 static void vl_api_tap_connect_reply_t_handler
1131 (vl_api_tap_connect_reply_t * mp)
1133 vat_main_t * vam = &vat_main;
1134 i32 retval = ntohl(mp->retval);
1135 if (vam->async_mode) {
1136 vam->async_errors += (retval < 0);
1138 vam->retval = retval;
1139 vam->result_ready = 1;
1143 static void vl_api_tap_connect_reply_t_handler_json
1144 (vl_api_tap_connect_reply_t * mp)
1146 vat_main_t * vam = &vat_main;
1147 vat_json_node_t node;
1149 vat_json_init_object(&node);
1150 vat_json_object_add_int(&node, "retval", ntohl(mp->retval));
1151 vat_json_object_add_uint(&node, "sw_if_index", ntohl(mp->sw_if_index));
1153 vat_json_print(vam->ofp, &node);
1154 vat_json_free(&node);
1156 vam->retval = ntohl(mp->retval);
1157 vam->result_ready = 1;
1160 static void vl_api_tap_modify_reply_t_handler
1161 (vl_api_tap_modify_reply_t * mp)
1163 vat_main_t * vam = &vat_main;
1164 i32 retval = ntohl(mp->retval);
1165 if (vam->async_mode) {
1166 vam->async_errors += (retval < 0);
1168 vam->retval = retval;
1169 vam->result_ready = 1;
1173 static void vl_api_tap_modify_reply_t_handler_json
1174 (vl_api_tap_modify_reply_t * mp)
1176 vat_main_t * vam = &vat_main;
1177 vat_json_node_t node;
1179 vat_json_init_object(&node);
1180 vat_json_object_add_int(&node, "retval", ntohl(mp->retval));
1181 vat_json_object_add_uint(&node, "sw_if_index", ntohl(mp->sw_if_index));
1183 vat_json_print(vam->ofp, &node);
1184 vat_json_free(&node);
1186 vam->retval = ntohl(mp->retval);
1187 vam->result_ready = 1;
1190 static void vl_api_tap_delete_reply_t_handler
1191 (vl_api_tap_delete_reply_t * mp)
1193 vat_main_t * vam = &vat_main;
1194 i32 retval = ntohl(mp->retval);
1195 if (vam->async_mode) {
1196 vam->async_errors += (retval < 0);
1198 vam->retval = retval;
1199 vam->result_ready = 1;
1203 static void vl_api_tap_delete_reply_t_handler_json
1204 (vl_api_tap_delete_reply_t * mp)
1206 vat_main_t * vam = &vat_main;
1207 vat_json_node_t node;
1209 vat_json_init_object(&node);
1210 vat_json_object_add_int(&node, "retval", ntohl(mp->retval));
1212 vat_json_print(vam->ofp, &node);
1213 vat_json_free(&node);
1215 vam->retval = ntohl(mp->retval);
1216 vam->result_ready = 1;
1219 static void vl_api_mpls_ethernet_add_del_tunnel_reply_t_handler
1220 (vl_api_mpls_ethernet_add_del_tunnel_reply_t * mp)
1222 vat_main_t * vam = &vat_main;
1223 i32 retval = ntohl(mp->retval);
1224 if (vam->async_mode) {
1225 vam->async_errors += (retval < 0);
1227 vam->retval = retval;
1228 vam->result_ready = 1;
1232 static void vl_api_mpls_ethernet_add_del_tunnel_reply_t_handler_json
1233 (vl_api_mpls_ethernet_add_del_tunnel_reply_t * mp)
1235 vat_main_t * vam = &vat_main;
1236 vat_json_node_t node;
1238 vat_json_init_object(&node);
1239 vat_json_object_add_int(&node, "retval", ntohl(mp->retval));
1240 vat_json_object_add_uint(&node, "tunnel_sw_if_index", ntohl(mp->tunnel_sw_if_index));
1242 vat_json_print(vam->ofp, &node);
1243 vat_json_free(&node);
1245 vam->retval = ntohl(mp->retval);
1246 vam->result_ready = 1;
1249 static void vl_api_l2tpv3_create_tunnel_reply_t_handler
1250 (vl_api_l2tpv3_create_tunnel_reply_t * mp)
1252 vat_main_t * vam = &vat_main;
1253 i32 retval = ntohl(mp->retval);
1254 if (vam->async_mode) {
1255 vam->async_errors += (retval < 0);
1257 vam->retval = retval;
1258 vam->result_ready = 1;
1262 static void vl_api_l2tpv3_create_tunnel_reply_t_handler_json
1263 (vl_api_l2tpv3_create_tunnel_reply_t * mp)
1265 vat_main_t * vam = &vat_main;
1266 vat_json_node_t node;
1268 vat_json_init_object(&node);
1269 vat_json_object_add_int(&node, "retval", ntohl(mp->retval));
1270 vat_json_object_add_uint(&node, "sw_if_index", ntohl(mp->sw_if_index));
1272 vat_json_print(vam->ofp, &node);
1273 vat_json_free(&node);
1275 vam->retval = ntohl(mp->retval);
1276 vam->result_ready = 1;
1279 static void vl_api_vxlan_add_del_tunnel_reply_t_handler
1280 (vl_api_vxlan_add_del_tunnel_reply_t * mp)
1282 vat_main_t * vam = &vat_main;
1283 i32 retval = ntohl(mp->retval);
1284 if (vam->async_mode) {
1285 vam->async_errors += (retval < 0);
1287 vam->retval = retval;
1288 vam->result_ready = 1;
1292 static void vl_api_vxlan_add_del_tunnel_reply_t_handler_json
1293 (vl_api_vxlan_add_del_tunnel_reply_t * mp)
1295 vat_main_t * vam = &vat_main;
1296 vat_json_node_t node;
1298 vat_json_init_object(&node);
1299 vat_json_object_add_int(&node, "retval", ntohl(mp->retval));
1300 vat_json_object_add_uint(&node, "sw_if_index", ntohl(mp->sw_if_index));
1302 vat_json_print(vam->ofp, &node);
1303 vat_json_free(&node);
1305 vam->retval = ntohl(mp->retval);
1306 vam->result_ready = 1;
1309 static void vl_api_create_vhost_user_if_reply_t_handler
1310 (vl_api_create_vhost_user_if_reply_t * mp)
1312 vat_main_t * vam = &vat_main;
1313 i32 retval = ntohl(mp->retval);
1314 if (vam->async_mode) {
1315 vam->async_errors += (retval < 0);
1317 vam->retval = retval;
1318 vam->result_ready = 1;
1322 static void vl_api_create_vhost_user_if_reply_t_handler_json
1323 (vl_api_create_vhost_user_if_reply_t * mp)
1325 vat_main_t * vam = &vat_main;
1326 vat_json_node_t node;
1328 vat_json_init_object(&node);
1329 vat_json_object_add_int(&node, "retval", ntohl(mp->retval));
1330 vat_json_object_add_uint(&node, "sw_if_index", ntohl(mp->sw_if_index));
1332 vat_json_print(vam->ofp, &node);
1333 vat_json_free(&node);
1335 vam->retval = ntohl(mp->retval);
1336 vam->result_ready = 1;
1339 static void vl_api_ip_address_details_t_handler
1340 (vl_api_ip_address_details_t * mp)
1342 vat_main_t * vam = &vat_main;
1343 static ip_address_details_t empty_ip_address_details = {{0}};
1344 ip_address_details_t * address = NULL;
1345 ip_details_t * current_ip_details = NULL;
1346 ip_details_t * details = NULL;
1348 details = vam->ip_details_by_sw_if_index[vam->is_ipv6];
1350 if (!details || vam->current_sw_if_index >= vec_len(details)
1351 || !details[vam->current_sw_if_index].present) {
1352 errmsg ("ip address details arrived but not stored\n");
1353 errmsg ("ip_dump should be called first\n");
1357 current_ip_details = vec_elt_at_index(details,
1358 vam->current_sw_if_index);
1360 #define addresses (current_ip_details->addr)
1362 vec_validate_init_empty(addresses, vec_len(addresses),
1363 empty_ip_address_details);
1365 address = vec_elt_at_index(addresses, vec_len(addresses) - 1);
1367 memcpy(&address->ip, &mp->ip, sizeof(address->ip));
1368 address->prefix_length = mp->prefix_length;
1372 static void vl_api_ip_address_details_t_handler_json
1373 (vl_api_ip_address_details_t * mp)
1375 vat_main_t * vam = &vat_main;
1376 vat_json_node_t *node = NULL;
1377 struct in6_addr ip6;
1380 if (VAT_JSON_ARRAY != vam->json_tree.type) {
1381 ASSERT(VAT_JSON_NONE == vam->json_tree.type);
1382 vat_json_init_array(&vam->json_tree);
1384 node = vat_json_array_add(&vam->json_tree);
1386 vat_json_init_object(node);
1388 memcpy(&ip6, mp->ip, sizeof(ip6));
1389 vat_json_object_add_ip6(node, "ip", ip6);
1391 memcpy(&ip4, mp->ip, sizeof(ip4));
1392 vat_json_object_add_ip4(node, "ip", ip4);
1394 vat_json_object_add_uint(node, "prefix_length", mp->prefix_length);
1397 static void vl_api_ip_details_t_handler (vl_api_ip_details_t * mp)
1399 vat_main_t * vam = &vat_main;
1400 static ip_details_t empty_ip_details = {0};
1401 ip_details_t * ip = NULL;
1402 u32 sw_if_index = ~0;
1404 sw_if_index = ntohl(mp->sw_if_index);
1406 vec_validate_init_empty(vam->ip_details_by_sw_if_index[vam->is_ipv6],
1407 sw_if_index, empty_ip_details);
1409 ip = vec_elt_at_index(vam->ip_details_by_sw_if_index[vam->is_ipv6],
1415 static void vl_api_ip_details_t_handler_json (vl_api_ip_details_t * mp)
1417 vat_main_t * vam = &vat_main;
1419 if (VAT_JSON_ARRAY != vam->json_tree.type) {
1420 ASSERT(VAT_JSON_NONE == vam->json_tree.type);
1421 vat_json_init_array(&vam->json_tree);
1423 vat_json_array_add_uint(&vam->json_tree, clib_net_to_host_u32(mp->sw_if_index));
1426 static void vl_api_map_domain_details_t_handler_json
1427 (vl_api_map_domain_details_t * mp)
1429 vat_json_node_t * node = NULL;
1430 vat_main_t * vam = &vat_main;
1431 struct in6_addr ip6;
1434 if (VAT_JSON_ARRAY != vam->json_tree.type) {
1435 ASSERT(VAT_JSON_NONE == vam->json_tree.type);
1436 vat_json_init_array(&vam->json_tree);
1439 node = vat_json_array_add(&vam->json_tree);
1440 vat_json_init_object(node);
1442 vat_json_object_add_uint(node, "domain_index", clib_net_to_host_u32(mp->domain_index));
1443 memcpy(&ip6, mp->ip6_prefix, sizeof(ip6));
1444 vat_json_object_add_ip6(node, "ip6_prefix", ip6);
1445 memcpy(&ip4, mp->ip4_prefix, sizeof(ip4));
1446 vat_json_object_add_ip4(node, "ip4_prefix", ip4);
1447 memcpy(&ip6, mp->ip6_src, sizeof(ip6));
1448 vat_json_object_add_ip6(node, "ip6_src", ip6);
1449 vat_json_object_add_int(node, "ip6_prefix_len", mp->ip6_prefix_len);
1450 vat_json_object_add_int(node, "ip4_prefix_len", mp->ip4_prefix_len);
1451 vat_json_object_add_int(node, "ip6_src_len", mp->ip6_src_len);
1452 vat_json_object_add_int(node, "ea_bits_len", mp->ea_bits_len);
1453 vat_json_object_add_int(node, "psid_offset", mp->psid_offset);
1454 vat_json_object_add_int(node, "psid_length", mp->psid_length);
1455 vat_json_object_add_uint(node, "flags", mp->flags);
1456 vat_json_object_add_uint(node, "mtu", clib_net_to_host_u16(mp->mtu));
1457 vat_json_object_add_int(node, "is_translation", mp->is_translation);
1460 static void vl_api_map_domain_details_t_handler
1461 (vl_api_map_domain_details_t * mp)
1463 vat_main_t * vam = &vat_main;
1465 if (mp->is_translation) {
1466 fformat(vam->ofp, "* %U/%d (ipv4-prefix) %U/%d (ipv6-prefix) %U/%d (ip6-src) index: %u\n",
1467 format_ip4_address, mp->ip4_prefix, mp->ip4_prefix_len,
1468 format_ip6_address, mp->ip6_prefix, mp->ip6_prefix_len,
1469 format_ip6_address, mp->ip6_src, mp->ip6_src_len, clib_net_to_host_u32(mp->domain_index));
1471 fformat(vam->ofp, "* %U/%d (ipv4-prefix) %U/%d (ipv6-prefix) %U (ip6-src) index: %u\n",
1472 format_ip4_address, mp->ip4_prefix, mp->ip4_prefix_len,
1473 format_ip6_address, mp->ip6_prefix, mp->ip6_prefix_len,
1474 format_ip6_address, mp->ip6_src, clib_net_to_host_u32(mp->domain_index));
1476 fformat(vam->ofp, " ea-len %d psid-offset %d psid-len %d mtu %d %s\n",
1477 mp->ea_bits_len, mp->psid_offset, mp->psid_length, mp->mtu, mp->is_translation? "map-t":"");
1480 static void vl_api_map_rule_details_t_handler_json
1481 (vl_api_map_rule_details_t * mp)
1483 struct in6_addr ip6;
1484 vat_json_node_t * node = NULL;
1485 vat_main_t * vam = &vat_main;
1487 if (VAT_JSON_ARRAY != vam->json_tree.type) {
1488 ASSERT(VAT_JSON_NONE == vam->json_tree.type);
1489 vat_json_init_array(&vam->json_tree);
1492 node = vat_json_array_add(&vam->json_tree);
1493 vat_json_init_object(node);
1495 vat_json_object_add_uint(node, "psid", clib_net_to_host_u16(mp->psid));
1496 memcpy(&ip6, mp->ip6_dst, sizeof(ip6));
1497 vat_json_object_add_ip6(node, "ip6_dst", ip6);
1500 static void vl_api_map_rule_details_t_handler
1501 (vl_api_map_rule_details_t * mp)
1503 vat_main_t * vam = &vat_main;
1504 fformat(vam->ofp, " %d (psid) %U (ip6-dst)\n", clib_net_to_host_u16(mp->psid),
1505 format_ip6_address, mp->ip6_dst);
1508 static void vl_api_dhcp_compl_event_t_handler
1509 (vl_api_dhcp_compl_event_t * mp)
1511 vat_main_t * vam = &vat_main;
1512 errmsg ("DHCP compl event: pid %d %s hostname %s host_addr %U "
1513 "router_addr %U host_mac %U\n",
1514 mp->pid, mp->is_ipv6 ? "ipv6":"ipv4", mp->hostname,
1515 format_ip4_address, &mp->host_address,
1516 format_ip4_address, &mp->router_address,
1517 format_ethernet_address, mp->host_mac);
1520 static void vl_api_dhcp_compl_event_t_handler_json
1521 (vl_api_dhcp_compl_event_t * mp)
1523 /* JSON output not supported */
1526 static void set_simple_interface_counter (u8 vnet_counter_type, u32 sw_if_index,
1529 vat_main_t * vam = &vat_main;
1530 static u64 default_counter = 0;
1532 vec_validate_init_empty(vam->simple_interface_counters, vnet_counter_type, NULL);
1533 vec_validate_init_empty(vam->simple_interface_counters[vnet_counter_type],
1534 sw_if_index, default_counter);
1535 vam->simple_interface_counters[vnet_counter_type][sw_if_index] = counter;
1538 static void set_combined_interface_counter (u8 vnet_counter_type, u32 sw_if_index,
1539 interface_counter_t counter)
1541 vat_main_t * vam = &vat_main;
1542 static interface_counter_t default_counter = {0, };
1544 vec_validate_init_empty(vam->combined_interface_counters, vnet_counter_type, NULL);
1545 vec_validate_init_empty(vam->combined_interface_counters[vnet_counter_type],
1546 sw_if_index, default_counter);
1547 vam->combined_interface_counters[vnet_counter_type][sw_if_index] = counter;
1550 static void vl_api_vnet_interface_counters_t_handler
1551 (vl_api_vnet_interface_counters_t *mp)
1556 static void vl_api_vnet_interface_counters_t_handler_json
1557 (vl_api_vnet_interface_counters_t *mp)
1559 interface_counter_t counter;
1564 u32 first_sw_if_index;
1567 count = ntohl(mp->count);
1568 first_sw_if_index = ntohl(mp->first_sw_if_index);
1570 if (!mp->is_combined) {
1571 v_packets = (u64*)&mp->data;
1572 for (i = 0; i < count; i++) {
1573 packets = clib_net_to_host_u64(clib_mem_unaligned(v_packets, u64));
1574 set_simple_interface_counter(mp->vnet_counter_type,
1575 first_sw_if_index + i, packets);
1579 v = (vlib_counter_t*)&mp->data;
1580 for (i = 0; i < count; i++) {
1581 counter.packets = clib_net_to_host_u64(
1582 clib_mem_unaligned(&v->packets, u64));
1583 counter.bytes = clib_net_to_host_u64(
1584 clib_mem_unaligned(&v->bytes, u64));
1585 set_combined_interface_counter(mp->vnet_counter_type,
1586 first_sw_if_index + i, counter);
1592 static u32 ip4_fib_counters_get_vrf_index_by_vrf_id (u32 vrf_id)
1594 vat_main_t * vam = &vat_main;
1597 for (i = 0; i < vec_len(vam->ip4_fib_counters_vrf_id_by_index); i++) {
1598 if (vam->ip4_fib_counters_vrf_id_by_index[i] == vrf_id) {
1605 static u32 ip6_fib_counters_get_vrf_index_by_vrf_id (u32 vrf_id)
1607 vat_main_t * vam = &vat_main;
1610 for (i = 0; i < vec_len(vam->ip6_fib_counters_vrf_id_by_index); i++) {
1611 if (vam->ip6_fib_counters_vrf_id_by_index[i] == vrf_id) {
1618 static void vl_api_vnet_ip4_fib_counters_t_handler
1619 (vl_api_vnet_ip4_fib_counters_t *mp)
1624 static void vl_api_vnet_ip4_fib_counters_t_handler_json
1625 (vl_api_vnet_ip4_fib_counters_t *mp)
1627 vat_main_t * vam = &vat_main;
1628 vl_api_ip4_fib_counter_t *v;
1629 ip4_fib_counter_t *counter;
1636 vrf_id = ntohl(mp->vrf_id);
1637 vrf_index = ip4_fib_counters_get_vrf_index_by_vrf_id(vrf_id);
1638 if (~0 == vrf_index) {
1639 vrf_index = vec_len(vam->ip4_fib_counters_vrf_id_by_index);
1640 vec_validate(vam->ip4_fib_counters_vrf_id_by_index, vrf_index);
1641 vam->ip4_fib_counters_vrf_id_by_index[vrf_index] = vrf_id;
1642 vec_validate(vam->ip4_fib_counters, vrf_index);
1643 vam->ip4_fib_counters[vrf_index] = NULL;
1646 vec_free(vam->ip4_fib_counters[vrf_index]);
1647 v = (vl_api_ip4_fib_counter_t*)&mp->c;
1648 count = ntohl(mp->count);
1649 for (i = 0; i < count; i++) {
1650 vec_validate(vam->ip4_fib_counters[vrf_index], i);
1651 counter = &vam->ip4_fib_counters[vrf_index][i];
1652 memcpy(&ip4, &v->address, sizeof(ip4));
1653 counter->address = ip4;
1654 counter->address_length = v->address_length;
1655 counter->packets = clib_net_to_host_u64(v->packets);
1656 counter->bytes = clib_net_to_host_u64(v->bytes);
1661 static void vl_api_vnet_ip6_fib_counters_t_handler
1662 (vl_api_vnet_ip6_fib_counters_t *mp)
1667 static void vl_api_vnet_ip6_fib_counters_t_handler_json
1668 (vl_api_vnet_ip6_fib_counters_t *mp)
1670 vat_main_t * vam = &vat_main;
1671 vl_api_ip6_fib_counter_t *v;
1672 ip6_fib_counter_t *counter;
1673 struct in6_addr ip6;
1679 vrf_id = ntohl(mp->vrf_id);
1680 vrf_index = ip6_fib_counters_get_vrf_index_by_vrf_id(vrf_id);
1681 if (~0 == vrf_index) {
1682 vrf_index = vec_len(vam->ip6_fib_counters_vrf_id_by_index);
1683 vec_validate(vam->ip6_fib_counters_vrf_id_by_index, vrf_index);
1684 vam->ip6_fib_counters_vrf_id_by_index[vrf_index] = vrf_id;
1685 vec_validate(vam->ip6_fib_counters, vrf_index);
1686 vam->ip6_fib_counters[vrf_index] = NULL;
1689 vec_free(vam->ip6_fib_counters[vrf_index]);
1690 v = (vl_api_ip6_fib_counter_t*)&mp->c;
1691 count = ntohl(mp->count);
1692 for (i = 0; i < count; i++) {
1693 vec_validate(vam->ip6_fib_counters[vrf_index], i);
1694 counter = &vam->ip6_fib_counters[vrf_index][i];
1695 memcpy(&ip6, &v->address, sizeof(ip6));
1696 counter->address = ip6;
1697 counter->address_length = v->address_length;
1698 counter->packets = clib_net_to_host_u64(v->packets);
1699 counter->bytes = clib_net_to_host_u64(v->bytes);
1704 static void vl_api_get_first_msg_id_reply_t_handler
1705 (vl_api_get_first_msg_id_reply_t * mp)
1707 vat_main_t * vam = &vat_main;
1708 i32 retval = ntohl(mp->retval);
1710 if (vam->async_mode) {
1711 vam->async_errors += (retval < 0);
1713 vam->retval = retval;
1714 vam->result_ready = 1;
1717 errmsg ("first message id %d\n", ntohs(mp->first_msg_id));
1721 static void vl_api_get_first_msg_id_reply_t_handler_json
1722 (vl_api_get_first_msg_id_reply_t * mp)
1724 vat_main_t * vam = &vat_main;
1725 vat_json_node_t node;
1727 vat_json_init_object(&node);
1728 vat_json_object_add_int(&node, "retval", ntohl(mp->retval));
1729 vat_json_object_add_uint(&node, "first_msg_id",
1730 (uint) ntohs(mp->first_msg_id));
1732 vat_json_print(vam->ofp, &node);
1733 vat_json_free(&node);
1735 vam->retval = ntohl(mp->retval);
1736 vam->result_ready = 1;
1739 static void vl_api_get_node_graph_reply_t_handler
1740 (vl_api_get_node_graph_reply_t * mp)
1742 vat_main_t * vam = &vat_main;
1743 api_main_t * am = &api_main;
1744 i32 retval = ntohl(mp->retval);
1745 u8 * pvt_copy, * reply;
1750 if (vam->async_mode) {
1751 vam->async_errors += (retval < 0);
1753 vam->retval = retval;
1754 vam->result_ready = 1;
1757 /* "Should never happen..." */
1761 reply = (u8 *)(mp->reply_in_shmem);
1762 pvt_copy = vec_dup (reply);
1764 /* Toss the shared-memory original... */
1765 pthread_mutex_lock (&am->vlib_rp->mutex);
1766 oldheap = svm_push_data_heap (am->vlib_rp);
1770 svm_pop_heap (oldheap);
1771 pthread_mutex_unlock (&am->vlib_rp->mutex);
1773 if (vam->graph_nodes) {
1774 hash_free (vam->graph_node_index_by_name);
1776 for (i = 0; i < vec_len (vam->graph_nodes); i++) {
1777 node = vam->graph_nodes[i];
1778 vec_free (node->name);
1779 vec_free (node->next_nodes);
1782 vec_free(vam->graph_nodes);
1785 vam->graph_node_index_by_name = hash_create_string (0, sizeof(uword));
1786 vam->graph_nodes = vlib_node_unserialize (pvt_copy);
1787 vec_free (pvt_copy);
1789 for (i = 0; i < vec_len (vam->graph_nodes); i++) {
1790 node = vam->graph_nodes[i];
1791 hash_set_mem (vam->graph_node_index_by_name, node->name, i);
1795 static void vl_api_get_node_graph_reply_t_handler_json
1796 (vl_api_get_node_graph_reply_t * mp)
1798 vat_main_t * vam = &vat_main;
1799 api_main_t * am = &api_main;
1801 vat_json_node_t node;
1804 /* $$$$ make this real? */
1805 vat_json_init_object(&node);
1806 vat_json_object_add_int(&node, "retval", ntohl(mp->retval));
1807 vat_json_object_add_uint(&node, "reply_in_shmem", mp->reply_in_shmem);
1809 reply = (u8 *)(mp->reply_in_shmem);
1811 /* Toss the shared-memory original... */
1812 pthread_mutex_lock (&am->vlib_rp->mutex);
1813 oldheap = svm_push_data_heap (am->vlib_rp);
1817 svm_pop_heap (oldheap);
1818 pthread_mutex_unlock (&am->vlib_rp->mutex);
1820 vat_json_print(vam->ofp, &node);
1821 vat_json_free(&node);
1823 vam->retval = ntohl(mp->retval);
1824 vam->result_ready = 1;
1827 #define vl_api_vnet_ip4_fib_counters_t_endian vl_noop_handler
1828 #define vl_api_vnet_ip4_fib_counters_t_print vl_noop_handler
1829 #define vl_api_vnet_ip6_fib_counters_t_endian vl_noop_handler
1830 #define vl_api_vnet_ip6_fib_counters_t_print vl_noop_handler
1833 * Generate boilerplate reply handlers, which
1834 * dig the return value out of the xxx_reply_t API message,
1835 * stick it into vam->retval, and set vam->result_ready
1837 * Could also do this by pointing N message decode slots at
1838 * a single function, but that could break in subtle ways.
1841 #define foreach_standard_reply_retval_handler \
1842 _(sw_interface_set_flags_reply) \
1843 _(sw_interface_add_del_address_reply) \
1844 _(sw_interface_set_table_reply) \
1845 _(sw_interface_set_vpath_reply) \
1846 _(sw_interface_set_l2_bridge_reply) \
1847 _(bridge_domain_add_del_reply) \
1848 _(sw_interface_set_l2_xconnect_reply) \
1849 _(l2fib_add_del_reply) \
1850 _(ip_add_del_route_reply) \
1851 _(proxy_arp_add_del_reply) \
1852 _(proxy_arp_intfc_enable_disable_reply) \
1853 _(mpls_add_del_encap_reply) \
1854 _(mpls_add_del_decap_reply) \
1855 _(mpls_ethernet_add_del_tunnel_2_reply) \
1856 _(sw_interface_set_unnumbered_reply) \
1857 _(ip_neighbor_add_del_reply) \
1858 _(reset_vrf_reply) \
1859 _(oam_add_del_reply) \
1860 _(reset_fib_reply) \
1861 _(dhcp_proxy_config_reply) \
1862 _(dhcp_proxy_config_2_reply) \
1863 _(dhcp_proxy_set_vss_reply) \
1864 _(dhcp_client_config_reply) \
1865 _(set_ip_flow_hash_reply) \
1866 _(sw_interface_ip6_enable_disable_reply) \
1867 _(sw_interface_ip6_set_link_local_address_reply) \
1868 _(sw_interface_ip6nd_ra_prefix_reply) \
1869 _(sw_interface_ip6nd_ra_config_reply) \
1870 _(set_arp_neighbor_limit_reply) \
1871 _(l2_patch_add_del_reply) \
1872 _(sr_tunnel_add_del_reply) \
1873 _(classify_add_del_session_reply) \
1874 _(classify_set_interface_ip_table_reply) \
1875 _(classify_set_interface_l2_tables_reply) \
1876 _(l2tpv3_set_tunnel_cookies_reply) \
1877 _(l2tpv3_interface_enable_disable_reply) \
1878 _(l2tpv3_set_lookup_key_reply) \
1879 _(l2_fib_clear_table_reply) \
1880 _(l2_interface_efp_filter_reply) \
1881 _(l2_interface_vlan_tag_rewrite_reply) \
1882 _(modify_vhost_user_if_reply) \
1883 _(delete_vhost_user_if_reply) \
1884 _(want_ip4_arp_events_reply) \
1885 _(input_acl_set_interface_reply) \
1886 _(ipsec_spd_add_del_reply) \
1887 _(ipsec_interface_add_del_spd_reply) \
1888 _(ipsec_spd_add_del_entry_reply) \
1889 _(ipsec_sad_add_del_entry_reply) \
1890 _(ipsec_sa_set_key_reply) \
1891 _(delete_loopback_reply) \
1892 _(bd_ip_mac_add_del_reply) \
1893 _(map_del_domain_reply) \
1894 _(map_add_del_rule_reply) \
1895 _(want_interface_events_reply) \
1896 _(want_stats_reply) \
1897 _(cop_interface_enable_disable_reply) \
1898 _(cop_whitelist_enable_disable_reply)
1901 static void vl_api_##n##_t_handler \
1902 (vl_api_##n##_t * mp) \
1904 vat_main_t * vam = &vat_main; \
1905 i32 retval = ntohl(mp->retval); \
1906 if (vam->async_mode) { \
1907 vam->async_errors += (retval < 0); \
1909 vam->retval = retval; \
1910 vam->result_ready = 1; \
1913 foreach_standard_reply_retval_handler;
1917 static void vl_api_##n##_t_handler_json \
1918 (vl_api_##n##_t * mp) \
1920 vat_main_t * vam = &vat_main; \
1921 vat_json_node_t node; \
1922 vat_json_init_object(&node); \
1923 vat_json_object_add_int(&node, "retval", ntohl(mp->retval)); \
1924 vat_json_print(vam->ofp, &node); \
1925 vam->retval = ntohl(mp->retval); \
1926 vam->result_ready = 1; \
1928 foreach_standard_reply_retval_handler;
1932 * Table of message reply handlers, must include boilerplate handlers
1936 #define foreach_vpe_api_reply_msg \
1937 _(CREATE_LOOPBACK_REPLY, create_loopback_reply) \
1938 _(SW_INTERFACE_DETAILS, sw_interface_details) \
1939 _(SW_INTERFACE_SET_FLAGS, sw_interface_set_flags) \
1940 _(SW_INTERFACE_SET_FLAGS_REPLY, sw_interface_set_flags_reply) \
1941 _(CONTROL_PING_REPLY, control_ping_reply) \
1942 _(CLI_REPLY, cli_reply) \
1943 _(SW_INTERFACE_ADD_DEL_ADDRESS_REPLY, \
1944 sw_interface_add_del_address_reply) \
1945 _(SW_INTERFACE_SET_TABLE_REPLY, sw_interface_set_table_reply) \
1946 _(SW_INTERFACE_SET_VPATH_REPLY, sw_interface_set_vpath_reply) \
1947 _(SW_INTERFACE_SET_L2_XCONNECT_REPLY, \
1948 sw_interface_set_l2_xconnect_reply) \
1949 _(SW_INTERFACE_SET_L2_BRIDGE_REPLY, \
1950 sw_interface_set_l2_bridge_reply) \
1951 _(BRIDGE_DOMAIN_ADD_DEL_REPLY, bridge_domain_add_del_reply) \
1952 _(BRIDGE_DOMAIN_DETAILS, bridge_domain_details) \
1953 _(BRIDGE_DOMAIN_SW_IF_DETAILS, bridge_domain_sw_if_details) \
1954 _(L2FIB_ADD_DEL_REPLY, l2fib_add_del_reply) \
1955 _(L2_FLAGS_REPLY, l2_flags_reply) \
1956 _(BRIDGE_FLAGS_REPLY, bridge_flags_reply) \
1957 _(TAP_CONNECT_REPLY, tap_connect_reply) \
1958 _(TAP_MODIFY_REPLY, tap_modify_reply) \
1959 _(TAP_DELETE_REPLY, tap_delete_reply) \
1960 _(SW_INTERFACE_TAP_DETAILS, sw_interface_tap_details) \
1961 _(IP_ADD_DEL_ROUTE_REPLY, ip_add_del_route_reply) \
1962 _(PROXY_ARP_ADD_DEL_REPLY, proxy_arp_add_del_reply) \
1963 _(PROXY_ARP_INTFC_ENABLE_DISABLE_REPLY, \
1964 proxy_arp_intfc_enable_disable_reply) \
1965 _(MPLS_ADD_DEL_ENCAP_REPLY, mpls_add_del_encap_reply) \
1966 _(MPLS_ADD_DEL_DECAP_REPLY, mpls_add_del_decap_reply) \
1967 _(MPLS_GRE_ADD_DEL_TUNNEL_REPLY, mpls_gre_add_del_tunnel_reply) \
1968 _(MPLS_ETHERNET_ADD_DEL_TUNNEL_REPLY, \
1969 mpls_ethernet_add_del_tunnel_reply) \
1970 _(MPLS_ETHERNET_ADD_DEL_TUNNEL_2_REPLY, \
1971 mpls_ethernet_add_del_tunnel_2_reply) \
1972 _(SW_INTERFACE_SET_UNNUMBERED_REPLY, \
1973 sw_interface_set_unnumbered_reply) \
1974 _(IP_NEIGHBOR_ADD_DEL_REPLY, ip_neighbor_add_del_reply) \
1975 _(RESET_VRF_REPLY, reset_vrf_reply) \
1976 _(CREATE_VLAN_SUBIF_REPLY, create_vlan_subif_reply) \
1977 _(CREATE_SUBIF_REPLY, create_subif_reply) \
1978 _(OAM_ADD_DEL_REPLY, oam_add_del_reply) \
1979 _(RESET_FIB_REPLY, reset_fib_reply) \
1980 _(DHCP_PROXY_CONFIG_REPLY, dhcp_proxy_config_reply) \
1981 _(DHCP_PROXY_CONFIG_2_REPLY, dhcp_proxy_config_2_reply) \
1982 _(DHCP_PROXY_SET_VSS_REPLY, dhcp_proxy_set_vss_reply) \
1983 _(DHCP_CLIENT_CONFIG_REPLY, dhcp_client_config_reply) \
1984 _(SET_IP_FLOW_HASH_REPLY, set_ip_flow_hash_reply) \
1985 _(SW_INTERFACE_IP6_ENABLE_DISABLE_REPLY, \
1986 sw_interface_ip6_enable_disable_reply) \
1987 _(SW_INTERFACE_IP6_SET_LINK_LOCAL_ADDRESS_REPLY, \
1988 sw_interface_ip6_set_link_local_address_reply) \
1989 _(SW_INTERFACE_IP6ND_RA_PREFIX_REPLY, \
1990 sw_interface_ip6nd_ra_prefix_reply) \
1991 _(SW_INTERFACE_IP6ND_RA_CONFIG_REPLY, \
1992 sw_interface_ip6nd_ra_config_reply) \
1993 _(SET_ARP_NEIGHBOR_LIMIT_REPLY, set_arp_neighbor_limit_reply) \
1994 _(L2_PATCH_ADD_DEL_REPLY, l2_patch_add_del_reply) \
1995 _(SR_TUNNEL_ADD_DEL_REPLY, sr_tunnel_add_del_reply) \
1996 _(CLASSIFY_ADD_DEL_TABLE_REPLY, classify_add_del_table_reply) \
1997 _(CLASSIFY_ADD_DEL_SESSION_REPLY, classify_add_del_session_reply) \
1998 _(CLASSIFY_SET_INTERFACE_IP_TABLE_REPLY, \
1999 classify_set_interface_ip_table_reply) \
2000 _(CLASSIFY_SET_INTERFACE_L2_TABLES_REPLY, \
2001 classify_set_interface_l2_tables_reply) \
2002 _(GET_NODE_INDEX_REPLY, get_node_index_reply) \
2003 _(ADD_NODE_NEXT_REPLY, add_node_next_reply) \
2004 _(L2TPV3_CREATE_TUNNEL_REPLY, l2tpv3_create_tunnel_reply) \
2005 _(L2TPV3_SET_TUNNEL_COOKIES_REPLY, l2tpv3_set_tunnel_cookies_reply) \
2006 _(L2TPV3_INTERFACE_ENABLE_DISABLE_REPLY, \
2007 l2tpv3_interface_enable_disable_reply) \
2008 _(L2TPV3_SET_LOOKUP_KEY_REPLY, l2tpv3_set_lookup_key_reply) \
2009 _(SW_IF_L2TPV3_TUNNEL_DETAILS, sw_if_l2tpv3_tunnel_details) \
2010 _(VXLAN_ADD_DEL_TUNNEL_REPLY, vxlan_add_del_tunnel_reply) \
2011 _(VXLAN_TUNNEL_DETAILS, vxlan_tunnel_details) \
2012 _(L2_FIB_CLEAR_TABLE_REPLY, l2_fib_clear_table_reply) \
2013 _(L2_INTERFACE_EFP_FILTER_REPLY, l2_interface_efp_filter_reply) \
2014 _(L2_INTERFACE_VLAN_TAG_REWRITE_REPLY, l2_interface_vlan_tag_rewrite_reply) \
2015 _(SW_INTERFACE_VHOST_USER_DETAILS, sw_interface_vhost_user_details) \
2016 _(CREATE_VHOST_USER_IF_REPLY, create_vhost_user_if_reply) \
2017 _(MODIFY_VHOST_USER_IF_REPLY, modify_vhost_user_if_reply) \
2018 _(DELETE_VHOST_USER_IF_REPLY, delete_vhost_user_if_reply) \
2019 _(SHOW_VERSION_REPLY, show_version_reply) \
2020 _(NSH_GRE_ADD_DEL_TUNNEL_REPLY, nsh_gre_add_del_tunnel_reply) \
2021 _(L2_FIB_TABLE_ENTRY, l2_fib_table_entry) \
2022 _(NSH_VXLAN_GPE_ADD_DEL_TUNNEL_REPLY, nsh_vxlan_gpe_add_del_tunnel_reply) \
2023 _(LISP_GPE_ADD_DEL_TUNNEL_REPLY, lisp_gpe_add_del_tunnel_reply) \
2024 _(INTERFACE_NAME_RENUMBER_REPLY, interface_name_renumber_reply) \
2025 _(WANT_IP4_ARP_EVENTS_REPLY, want_ip4_arp_events_reply) \
2026 _(IP4_ARP_EVENT, ip4_arp_event) \
2027 _(INPUT_ACL_SET_INTERFACE_REPLY, input_acl_set_interface_reply) \
2028 _(IP_ADDRESS_DETAILS, ip_address_details) \
2029 _(IP_DETAILS, ip_details) \
2030 _(IPSEC_SPD_ADD_DEL_REPLY, ipsec_spd_add_del_reply) \
2031 _(IPSEC_INTERFACE_ADD_DEL_SPD_REPLY, ipsec_interface_add_del_spd_reply) \
2032 _(IPSEC_SPD_ADD_DEL_ENTRY_REPLY, ipsec_spd_add_del_entry_reply) \
2033 _(IPSEC_SAD_ADD_DEL_ENTRY_REPLY, ipsec_sad_add_del_entry_reply) \
2034 _(IPSEC_SA_SET_KEY_REPLY, ipsec_sa_set_key_reply) \
2035 _(DELETE_LOOPBACK_REPLY, delete_loopback_reply) \
2036 _(BD_IP_MAC_ADD_DEL_REPLY, bd_ip_mac_add_del_reply) \
2037 _(DHCP_COMPL_EVENT, dhcp_compl_event) \
2038 _(VNET_INTERFACE_COUNTERS, vnet_interface_counters) \
2039 _(VNET_IP4_FIB_COUNTERS, vnet_ip4_fib_counters) \
2040 _(VNET_IP6_FIB_COUNTERS, vnet_ip6_fib_counters) \
2041 _(MAP_ADD_DOMAIN_REPLY, map_add_domain_reply) \
2042 _(MAP_DEL_DOMAIN_REPLY, map_del_domain_reply) \
2043 _(MAP_ADD_DEL_RULE_REPLY, map_add_del_rule_reply) \
2044 _(MAP_DOMAIN_DETAILS, map_domain_details) \
2045 _(MAP_RULE_DETAILS, map_rule_details) \
2046 _(WANT_INTERFACE_EVENTS_REPLY, want_interface_events_reply) \
2047 _(WANT_STATS_REPLY, want_stats_reply) \
2048 _(GET_FIRST_MSG_ID_REPLY, get_first_msg_id_reply) \
2049 _(COP_INTERFACE_ENABLE_DISABLE_REPLY, cop_interface_enable_disable_reply) \
2050 _(COP_WHITELIST_ENABLE_DISABLE_REPLY, cop_whitelist_enable_disable_reply) \
2051 _(GET_NODE_GRAPH_REPLY, get_node_graph_reply)
2053 /* M: construct, but don't yet send a message */
2057 vam->result_ready = 0; \
2058 mp = vl_msg_api_alloc(sizeof(*mp)); \
2059 memset (mp, 0, sizeof (*mp)); \
2060 mp->_vl_msg_id = ntohs (VL_API_##T); \
2061 mp->client_index = vam->my_client_index; \
2066 vam->result_ready = 0; \
2067 mp = vl_msg_api_alloc(sizeof(*mp)+(n)); \
2068 memset (mp, 0, sizeof (*mp)); \
2069 mp->_vl_msg_id = ntohs (VL_API_##T); \
2070 mp->client_index = vam->my_client_index; \
2074 /* S: send a message */
2075 #define S (vl_msg_api_send_shmem (vam->vl_input_queue, (u8 *)&mp))
2077 /* W: wait for results, with timeout */
2080 timeout = vat_time_now (vam) + 1.0; \
2082 while (vat_time_now (vam) < timeout) { \
2083 if (vam->result_ready == 1) { \
2084 return (vam->retval); \
2096 #define STR_VTR_OP_CASE(op) \
2097 case L2_VTR_ ## op: \
2100 static const char *str_vtr_op(u32 vtr_op)
2103 STR_VTR_OP_CASE(DISABLED);
2104 STR_VTR_OP_CASE(PUSH_1);
2105 STR_VTR_OP_CASE(PUSH_2);
2106 STR_VTR_OP_CASE(POP_1);
2107 STR_VTR_OP_CASE(POP_2);
2108 STR_VTR_OP_CASE(TRANSLATE_1_1);
2109 STR_VTR_OP_CASE(TRANSLATE_1_2);
2110 STR_VTR_OP_CASE(TRANSLATE_2_1);
2111 STR_VTR_OP_CASE(TRANSLATE_2_2);
2117 static int dump_sub_interface_table (vat_main_t * vam)
2119 const sw_interface_subif_t * sub = NULL;
2121 if (vam->json_output) {
2122 clib_warning ("JSON output supported only for VPE API calls and dump_stats_table");
2127 "%-30s%-12s%-11s%-7s%-5s%-9s%-9s%-6s%-8s%-10s%-10s\n",
2128 "Interface", "sw_if_index",
2129 "sub id", "dot1ad", "tags", "outer id",
2130 "inner id", "exact", "default",
2131 "outer any", "inner any");
2133 vec_foreach (sub, vam->sw_if_subif_table) {
2135 "%-30s%-12d%-11d%-7s%-5d%-9d%-9d%-6d%-8d%-10d%-10d\n",
2136 sub->interface_name,
2138 sub->sub_id, sub->sub_dot1ad ? "dot1ad" : "dot1q",
2139 sub->sub_number_of_tags, sub->sub_outer_vlan_id,
2140 sub->sub_inner_vlan_id, sub->sub_exact_match, sub->sub_default,
2141 sub->sub_outer_vlan_id_any, sub->sub_inner_vlan_id_any);
2142 if (sub->vtr_op != L2_VTR_DISABLED) {
2144 " vlan-tag-rewrite - op: %-14s [ dot1q: %d "
2145 "tag1: %d tag2: %d ]\n",
2146 str_vtr_op(sub->vtr_op), sub->vtr_push_dot1q,
2147 sub->vtr_tag1, sub->vtr_tag2);
2154 static int name_sort_cmp (void * a1, void * a2)
2156 name_sort_t * n1 = a1;
2157 name_sort_t * n2 = a2;
2159 return strcmp ((char *)n1->name, (char *)n2->name);
2162 static int dump_interface_table (vat_main_t * vam)
2165 name_sort_t * nses = 0, * ns;
2167 if (vam->json_output) {
2168 clib_warning ("JSON output supported only for VPE API calls and dump_stats_table");
2172 hash_foreach_pair (p, vam->sw_if_index_by_interface_name,
2174 vec_add2 (nses, ns, 1);
2175 ns->name = (u8 *)(p->key);
2176 ns->value = (u32) p->value[0];
2179 vec_sort_with_function (nses, name_sort_cmp);
2181 fformat (vam->ofp, "%-25s%-15s\n", "Interface", "sw_if_index");
2182 vec_foreach (ns, nses) {
2183 fformat (vam->ofp, "%-25s%-15d\n", ns->name, ns->value);
2189 static int dump_ip_table (vat_main_t * vam, int is_ipv6)
2191 const ip_details_t * det = NULL;
2192 const ip_address_details_t * address = NULL;
2199 if (0 == vam->ip_details_by_sw_if_index) {
2203 vec_foreach (det, vam->ip_details_by_sw_if_index[is_ipv6]) {
2205 if (!det->present) {
2213 "Address", "Prefix length");
2217 vec_foreach (address, det->addr) {
2220 is_ipv6 ? format_ip6_address : format_ip4_address,
2222 address->prefix_length);
2229 static int dump_ipv4_table (vat_main_t * vam)
2231 if (vam->json_output) {
2232 clib_warning ("JSON output supported only for VPE API calls and dump_stats_table");
2236 return dump_ip_table (vam, 0);
2239 static int dump_ipv6_table (vat_main_t * vam)
2241 if (vam->json_output) {
2242 clib_warning ("JSON output supported only for VPE API calls and dump_stats_table");
2246 return dump_ip_table (vam, 1);
2249 static char* counter_type_to_str (u8 counter_type, u8 is_combined)
2252 switch(counter_type) {
2253 case VNET_INTERFACE_COUNTER_DROP:
2255 case VNET_INTERFACE_COUNTER_PUNT:
2257 case VNET_INTERFACE_COUNTER_IP4:
2259 case VNET_INTERFACE_COUNTER_IP6:
2261 case VNET_INTERFACE_COUNTER_RX_NO_BUF:
2263 case VNET_INTERFACE_COUNTER_RX_MISS:
2265 case VNET_INTERFACE_COUNTER_RX_ERROR:
2267 case VNET_INTERFACE_COUNTER_TX_ERROR:
2270 return "INVALID-COUNTER-TYPE";
2273 switch(counter_type) {
2274 case VNET_INTERFACE_COUNTER_RX:
2276 case VNET_INTERFACE_COUNTER_TX:
2279 return "INVALID-COUNTER-TYPE";
2284 static int dump_stats_table (vat_main_t * vam)
2286 vat_json_node_t node;
2287 vat_json_node_t *msg_array;
2288 vat_json_node_t *msg;
2289 vat_json_node_t *counter_array;
2290 vat_json_node_t *counter;
2291 interface_counter_t c;
2293 ip4_fib_counter_t *c4;
2294 ip6_fib_counter_t *c6;
2297 if (!vam->json_output) {
2298 clib_warning ("dump_stats_table supported only in JSON format");
2302 vat_json_init_object(&node);
2304 /* interface counters */
2305 msg_array = vat_json_object_add(&node, "interface_counters");
2306 vat_json_init_array(msg_array);
2307 for (i = 0; i < vec_len(vam->simple_interface_counters); i++) {
2308 msg = vat_json_array_add(msg_array);
2309 vat_json_init_object(msg);
2310 vat_json_object_add_string_copy(msg, "vnet_counter_type",
2311 (u8*)counter_type_to_str(i, 0));
2312 vat_json_object_add_int(msg, "is_combined", 0);
2313 counter_array = vat_json_object_add(msg, "data");
2314 vat_json_init_array(counter_array);
2315 for (j = 0; j < vec_len(vam->simple_interface_counters[i]); j++) {
2316 packets = vam->simple_interface_counters[i][j];
2317 vat_json_array_add_uint(counter_array, packets);
2320 for (i = 0; i < vec_len(vam->combined_interface_counters); i++) {
2321 msg = vat_json_array_add(msg_array);
2322 vat_json_init_object(msg);
2323 vat_json_object_add_string_copy(msg, "vnet_counter_type",
2324 (u8*)counter_type_to_str(i, 1));
2325 vat_json_object_add_int(msg, "is_combined", 1);
2326 counter_array = vat_json_object_add(msg, "data");
2327 vat_json_init_array(counter_array);
2328 for (j = 0; j < vec_len(vam->combined_interface_counters[i]); j++) {
2329 c = vam->combined_interface_counters[i][j];
2330 counter = vat_json_array_add(counter_array);
2331 vat_json_init_object(counter);
2332 vat_json_object_add_uint(counter, "packets", c.packets);
2333 vat_json_object_add_uint(counter, "bytes", c.bytes);
2337 /* ip4 fib counters */
2338 msg_array = vat_json_object_add(&node, "ip4_fib_counters");
2339 vat_json_init_array(msg_array);
2340 for (i = 0; i < vec_len(vam->ip4_fib_counters); i++) {
2341 msg = vat_json_array_add(msg_array);
2342 vat_json_init_object(msg);
2343 vat_json_object_add_uint(msg, "vrf_id", vam->ip4_fib_counters_vrf_id_by_index[i]);
2344 counter_array = vat_json_object_add(msg, "c");
2345 vat_json_init_array(counter_array);
2346 for (j = 0; j < vec_len(vam->ip4_fib_counters[i]); j++) {
2347 counter = vat_json_array_add(counter_array);
2348 vat_json_init_object(counter);
2349 c4 = &vam->ip4_fib_counters[i][j];
2350 vat_json_object_add_ip4(counter, "address", c4->address);
2351 vat_json_object_add_uint(counter, "address_length", c4->address_length);
2352 vat_json_object_add_uint(counter, "packets", c4->packets);
2353 vat_json_object_add_uint(counter, "bytes", c4->bytes);
2357 /* ip6 fib counters */
2358 msg_array = vat_json_object_add(&node, "ip6_fib_counters");
2359 vat_json_init_array(msg_array);
2360 for (i = 0; i < vec_len(vam->ip6_fib_counters); i++) {
2361 msg = vat_json_array_add(msg_array);
2362 vat_json_init_object(msg);
2363 vat_json_object_add_uint(msg, "vrf_id", vam->ip6_fib_counters_vrf_id_by_index[i]);
2364 counter_array = vat_json_object_add(msg, "c");
2365 vat_json_init_array(counter_array);
2366 for (j = 0; j < vec_len(vam->ip6_fib_counters[i]); j++) {
2367 counter = vat_json_array_add(counter_array);
2368 vat_json_init_object(counter);
2369 c6 = &vam->ip6_fib_counters[i][j];
2370 vat_json_object_add_ip6(counter, "address", c6->address);
2371 vat_json_object_add_uint(counter, "address_length", c6->address_length);
2372 vat_json_object_add_uint(counter, "packets", c6->packets);
2373 vat_json_object_add_uint(counter, "bytes", c6->bytes);
2377 vat_json_print(vam->ofp, &node);
2378 vat_json_free(&node);
2383 int exec (vat_main_t * vam)
2385 api_main_t * am = &api_main;
2386 vl_api_cli_request_t *mp;
2390 unformat_input_t * i = vam->input;
2392 if (vec_len(i->buffer) == 0)
2395 if (vam->exec_mode == 0 && unformat (i, "mode")) {
2399 if (vam->exec_mode == 1 &&
2400 (unformat (i, "exit") || unformat (i, "quit"))) {
2406 M(CLI_REQUEST, cli_request);
2409 * Copy cmd into shared memory.
2410 * In order for the CLI command to work, it
2411 * must be a vector ending in \n, not a C-string ending
2414 pthread_mutex_lock (&am->vlib_rp->mutex);
2415 oldheap = svm_push_data_heap (am->vlib_rp);
2417 vec_validate (cmd, vec_len(vam->input->buffer)-1);
2418 memcpy (cmd, vam->input->buffer, vec_len(vam->input->buffer));
2420 svm_pop_heap (oldheap);
2421 pthread_mutex_unlock (&am->vlib_rp->mutex);
2423 mp->cmd_in_shmem = (u64) cmd;
2425 timeout = vat_time_now (vam) + 10.0;
2427 while (vat_time_now (vam) < timeout) {
2428 if (vam->result_ready == 1) {
2430 fformat (vam->ofp, "%s", vam->shmem_result);
2431 pthread_mutex_lock (&am->vlib_rp->mutex);
2432 oldheap = svm_push_data_heap (am->vlib_rp);
2434 free_me = (u8 *)vam->shmem_result;
2437 svm_pop_heap (oldheap);
2438 pthread_mutex_unlock (&am->vlib_rp->mutex);
2445 static int api_create_loopback (vat_main_t * vam)
2447 unformat_input_t * i = vam->input;
2448 vl_api_create_loopback_t *mp;
2453 memset (mac_address, 0, sizeof (mac_address));
2455 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
2457 if (unformat (i, "mac %U", unformat_ethernet_address, mac_address))
2463 /* Construct the API message */
2464 M(CREATE_LOOPBACK, create_loopback);
2466 memcpy (mp->mac_address, mac_address, sizeof (mac_address));
2471 static int api_delete_loopback (vat_main_t * vam)
2473 unformat_input_t * i = vam->input;
2474 vl_api_delete_loopback_t *mp;
2476 u32 sw_if_index = ~0;
2478 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
2480 if (unformat (i, "sw_if_index %d", &sw_if_index))
2486 if (sw_if_index == ~0)
2488 errmsg ("missing sw_if_index\n");
2492 /* Construct the API message */
2493 M(DELETE_LOOPBACK, delete_loopback);
2494 mp->sw_if_index = ntohl (sw_if_index);
2499 static int api_want_stats (vat_main_t * vam)
2501 unformat_input_t * i = vam->input;
2502 vl_api_want_stats_t * mp;
2506 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
2508 if (unformat (i, "enable"))
2510 else if (unformat (i, "disable"))
2518 errmsg ("missing enable|disable\n");
2522 M(WANT_STATS, want_stats);
2523 mp->enable_disable = enable;
2528 static int api_want_interface_events (vat_main_t * vam)
2530 unformat_input_t * i = vam->input;
2531 vl_api_want_interface_events_t * mp;
2535 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
2537 if (unformat (i, "enable"))
2539 else if (unformat (i, "disable"))
2547 errmsg ("missing enable|disable\n");
2551 M(WANT_INTERFACE_EVENTS, want_interface_events);
2552 mp->enable_disable = enable;
2554 vam->interface_event_display = enable;
2560 /* Note: non-static, called once to set up the initial intfc table */
2561 int api_sw_interface_dump (vat_main_t * vam)
2563 vl_api_sw_interface_dump_t *mp;
2566 name_sort_t * nses = 0, * ns;
2567 sw_interface_subif_t * sub = NULL;
2569 /* Toss the old name table */
2570 hash_foreach_pair (p, vam->sw_if_index_by_interface_name,
2572 vec_add2 (nses, ns, 1);
2573 ns->name = (u8 *)(p->key);
2574 ns->value = (u32) p->value[0];
2577 hash_free (vam->sw_if_index_by_interface_name);
2579 vec_foreach (ns, nses)
2580 vec_free (ns->name);
2584 vec_foreach (sub, vam->sw_if_subif_table) {
2585 vec_free (sub->interface_name);
2587 vec_free (vam->sw_if_subif_table);
2589 /* recreate the interface name hash table */
2590 vam->sw_if_index_by_interface_name
2591 = hash_create_string (0, sizeof(uword));
2593 /* Get list of ethernets */
2594 M(SW_INTERFACE_DUMP, sw_interface_dump);
2595 mp->name_filter_valid = 1;
2596 strncpy ((char *) mp->name_filter, "Ether", sizeof(mp->name_filter-1));
2599 /* and local / loopback interfaces */
2600 M(SW_INTERFACE_DUMP, sw_interface_dump);
2601 mp->name_filter_valid = 1;
2602 strncpy ((char *) mp->name_filter, "lo", sizeof(mp->name_filter-1));
2605 /* and vxlan tunnel interfaces */
2606 M(SW_INTERFACE_DUMP, sw_interface_dump);
2607 mp->name_filter_valid = 1;
2608 strncpy ((char *) mp->name_filter, "vxlan", sizeof(mp->name_filter-1));
2611 /* and l2tpv3 tunnel interfaces */
2612 M(SW_INTERFACE_DUMP, sw_interface_dump);
2613 mp->name_filter_valid = 1;
2614 strncpy ((char *) mp->name_filter, "l2tpv3_tunnel", sizeof(mp->name_filter-1));
2617 /* Use a control ping for synchronization */
2619 vl_api_control_ping_t * mp;
2620 M(CONTROL_PING, control_ping);
2626 static int api_sw_interface_set_flags (vat_main_t * vam)
2628 unformat_input_t * i = vam->input;
2629 vl_api_sw_interface_set_flags_t *mp;
2632 u8 sw_if_index_set = 0;
2633 u8 admin_up = 0, link_up = 0;
2635 /* Parse args required to build the message */
2636 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
2637 if (unformat (i, "admin-up"))
2639 else if (unformat (i, "admin-down"))
2641 else if (unformat (i, "link-up"))
2643 else if (unformat (i, "link-down"))
2645 else if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
2646 sw_if_index_set = 1;
2647 else if (unformat (i, "sw_if_index %d", &sw_if_index))
2648 sw_if_index_set = 1;
2653 if (sw_if_index_set == 0) {
2654 errmsg ("missing interface name or sw_if_index\n");
2658 /* Construct the API message */
2659 M(SW_INTERFACE_SET_FLAGS, sw_interface_set_flags);
2660 mp->sw_if_index = ntohl (sw_if_index);
2661 mp->admin_up_down = admin_up;
2662 mp->link_up_down = link_up;
2667 /* Wait for a reply, return the good/bad news... */
2671 static int api_sw_interface_add_del_address (vat_main_t * vam)
2673 unformat_input_t * i = vam->input;
2674 vl_api_sw_interface_add_del_address_t *mp;
2677 u8 sw_if_index_set = 0;
2678 u8 is_add = 1, del_all = 0;
2679 u32 address_length = 0;
2680 u8 v4_address_set = 0;
2681 u8 v6_address_set = 0;
2682 ip4_address_t v4address;
2683 ip6_address_t v6address;
2685 /* Parse args required to build the message */
2686 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
2687 if (unformat (i, "del-all"))
2689 else if (unformat (i, "del"))
2691 else if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
2692 sw_if_index_set = 1;
2693 else if (unformat (i, "sw_if_index %d", &sw_if_index))
2694 sw_if_index_set = 1;
2695 else if (unformat (i, "%U/%d",
2696 unformat_ip4_address, &v4address,
2699 else if (unformat (i, "%U/%d",
2700 unformat_ip6_address, &v6address,
2707 if (sw_if_index_set == 0) {
2708 errmsg ("missing interface name or sw_if_index\n");
2711 if (v4_address_set && v6_address_set) {
2712 errmsg ("both v4 and v6 addresses set\n");
2715 if (!v4_address_set && !v6_address_set && !del_all) {
2716 errmsg ("no addresses set\n");
2720 /* Construct the API message */
2721 M(SW_INTERFACE_ADD_DEL_ADDRESS, sw_interface_add_del_address);
2723 mp->sw_if_index = ntohl (sw_if_index);
2724 mp->is_add = is_add;
2725 mp->del_all = del_all;
2726 if (v6_address_set) {
2728 memcpy (mp->address, &v6address, sizeof (v6address));
2730 memcpy (mp->address, &v4address, sizeof (v4address));
2732 mp->address_length = address_length;
2737 /* Wait for a reply, return good/bad news */
2741 static int api_sw_interface_set_table (vat_main_t * vam)
2743 unformat_input_t * i = vam->input;
2744 vl_api_sw_interface_set_table_t *mp;
2746 u32 sw_if_index, vrf_id = 0;
2747 u8 sw_if_index_set = 0;
2750 /* Parse args required to build the message */
2751 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
2752 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
2753 sw_if_index_set = 1;
2754 else if (unformat (i, "sw_if_index %d", &sw_if_index))
2755 sw_if_index_set = 1;
2756 else if (unformat (i, "vrf %d", &vrf_id))
2758 else if (unformat (i, "ipv6"))
2764 if (sw_if_index_set == 0) {
2765 errmsg ("missing interface name or sw_if_index\n");
2769 /* Construct the API message */
2770 M(SW_INTERFACE_SET_TABLE, sw_interface_set_table);
2772 mp->sw_if_index = ntohl (sw_if_index);
2773 mp->is_ipv6 = is_ipv6;
2774 mp->vrf_id = ntohl (vrf_id);
2779 /* Wait for a reply... */
2783 static int api_sw_interface_set_vpath (vat_main_t * vam)
2785 unformat_input_t * i = vam->input;
2786 vl_api_sw_interface_set_vpath_t *mp;
2788 u32 sw_if_index = 0;
2789 u8 sw_if_index_set = 0;
2792 /* Parse args required to build the message */
2793 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
2794 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
2795 sw_if_index_set = 1;
2796 else if (unformat (i, "sw_if_index %d", &sw_if_index))
2797 sw_if_index_set = 1;
2798 else if (unformat (i, "enable"))
2800 else if (unformat (i, "disable"))
2806 if (sw_if_index_set == 0) {
2807 errmsg ("missing interface name or sw_if_index\n");
2811 /* Construct the API message */
2812 M(SW_INTERFACE_SET_VPATH, sw_interface_set_vpath);
2814 mp->sw_if_index = ntohl (sw_if_index);
2815 mp->enable = is_enable;
2820 /* Wait for a reply... */
2824 static int api_sw_interface_set_l2_xconnect (vat_main_t * vam)
2826 unformat_input_t * i = vam->input;
2827 vl_api_sw_interface_set_l2_xconnect_t *mp;
2830 u8 rx_sw_if_index_set = 0;
2832 u8 tx_sw_if_index_set = 0;
2835 /* Parse args required to build the message */
2836 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
2837 if (unformat (i, "rx_sw_if_index %d", &rx_sw_if_index))
2838 rx_sw_if_index_set = 1;
2839 else if (unformat (i, "tx_sw_if_index %d", &tx_sw_if_index))
2840 tx_sw_if_index_set = 1;
2841 else if (unformat (i, "rx")) {
2842 if (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
2843 if (unformat (i, "%U", unformat_sw_if_index, vam,
2845 rx_sw_if_index_set = 1;
2848 } else if (unformat (i, "tx")) {
2849 if (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
2850 if (unformat (i, "%U", unformat_sw_if_index, vam,
2852 tx_sw_if_index_set = 1;
2855 } else if (unformat (i, "enable"))
2857 else if (unformat (i, "disable"))
2863 if (rx_sw_if_index_set == 0) {
2864 errmsg ("missing rx interface name or rx_sw_if_index\n");
2868 if (enable && (tx_sw_if_index_set == 0)) {
2869 errmsg ("missing tx interface name or tx_sw_if_index\n");
2873 M(SW_INTERFACE_SET_L2_XCONNECT, sw_interface_set_l2_xconnect);
2875 mp->rx_sw_if_index = ntohl(rx_sw_if_index);
2876 mp->tx_sw_if_index = ntohl(tx_sw_if_index);
2877 mp->enable = enable;
2884 static int api_sw_interface_set_l2_bridge (vat_main_t * vam)
2886 unformat_input_t * i = vam->input;
2887 vl_api_sw_interface_set_l2_bridge_t *mp;
2890 u8 rx_sw_if_index_set = 0;
2897 /* Parse args required to build the message */
2898 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
2899 if (unformat (i, "sw_if_index %d", &rx_sw_if_index))
2900 rx_sw_if_index_set = 1;
2901 else if (unformat (i, "bd_id %d", &bd_id))
2903 else if (unformat (i, "%U", unformat_sw_if_index, vam,
2905 rx_sw_if_index_set = 1;
2906 else if (unformat (i, "shg %d", &shg))
2908 else if (unformat (i, "bvi"))
2910 else if (unformat (i, "enable"))
2912 else if (unformat (i, "disable"))
2918 if (rx_sw_if_index_set == 0) {
2919 errmsg ("missing rx interface name or sw_if_index\n");
2923 if (enable && (bd_id_set == 0)) {
2924 errmsg ("missing bridge domain\n");
2928 M(SW_INTERFACE_SET_L2_BRIDGE, sw_interface_set_l2_bridge);
2930 mp->rx_sw_if_index = ntohl(rx_sw_if_index);
2931 mp->bd_id = ntohl(bd_id);
2934 mp->enable = enable;
2941 static int api_bridge_domain_dump (vat_main_t * vam)
2943 unformat_input_t * i = vam->input;
2944 vl_api_bridge_domain_dump_t *mp;
2948 /* Parse args required to build the message */
2949 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
2950 if (unformat (i, "bd_id %d", &bd_id))
2956 M(BRIDGE_DOMAIN_DUMP, bridge_domain_dump);
2957 mp->bd_id = ntohl(bd_id);
2960 /* Use a control ping for synchronization */
2962 vl_api_control_ping_t * mp;
2963 M(CONTROL_PING, control_ping);
2972 static int api_bridge_domain_add_del (vat_main_t * vam)
2974 unformat_input_t * i = vam->input;
2975 vl_api_bridge_domain_add_del_t *mp;
2979 u32 flood = 1, forward = 1, learn = 1, uu_flood = 1, arp_term = 0;
2981 /* Parse args required to build the message */
2982 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
2983 if (unformat (i, "bd_id %d", &bd_id))
2985 else if (unformat (i, "flood %d", &flood))
2987 else if (unformat (i, "uu-flood %d", &uu_flood))
2989 else if (unformat (i, "forward %d", &forward))
2991 else if (unformat (i, "learn %d", &learn))
2993 else if (unformat (i, "arp-term %d", &arp_term))
2995 else if (unformat (i, "del")) {
2997 flood = uu_flood = forward = learn = 0;
3004 errmsg ("missing bridge domain\n");
3008 M(BRIDGE_DOMAIN_ADD_DEL, bridge_domain_add_del);
3010 mp->bd_id = ntohl(bd_id);
3012 mp->uu_flood = uu_flood;
3013 mp->forward = forward;
3015 mp->arp_term = arp_term;
3016 mp->is_add = is_add;
3023 static int api_l2fib_add_del (vat_main_t * vam)
3025 unformat_input_t * i = vam->input;
3026 vl_api_l2fib_add_del_t *mp;
3033 u8 sw_if_index_set = 0;
3038 /* Parse args required to build the message */
3039 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
3040 if (unformat (i, "mac %U", unformat_ethernet_address, &mac))
3042 else if (unformat (i, "bd_id %d", &bd_id))
3044 else if (unformat (i, "sw_if_index %d", &sw_if_index))
3045 sw_if_index_set = 1;
3046 else if (unformat (i, "sw_if")) {
3047 if (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
3048 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
3049 sw_if_index_set = 1;
3052 } else if (unformat (i, "static"))
3054 else if (unformat (i, "filter")) {
3057 } else if (unformat (i, "del"))
3064 errmsg ("missing mac address\n");
3068 if (bd_id_set == 0) {
3069 errmsg ("missing bridge domain\n");
3073 if (is_add && (sw_if_index_set == 0)) {
3074 errmsg ("missing interface name or sw_if_index\n");
3078 M(L2FIB_ADD_DEL, l2fib_add_del);
3081 mp->bd_id = ntohl(bd_id);
3082 mp->is_add = is_add;
3085 mp->sw_if_index = ntohl(sw_if_index);
3086 mp->static_mac = static_mac;
3087 mp->filter_mac = filter_mac;
3095 static int api_l2_flags (vat_main_t * vam)
3097 unformat_input_t * i = vam->input;
3098 vl_api_l2_flags_t *mp;
3101 u32 feature_bitmap = 0;
3102 u8 sw_if_index_set = 0;
3104 /* Parse args required to build the message */
3105 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
3106 if (unformat (i, "sw_if_index %d", &sw_if_index))
3107 sw_if_index_set = 1;
3108 else if (unformat (i, "sw_if")) {
3109 if (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
3110 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
3111 sw_if_index_set = 1;
3114 } else if (unformat (i, "learn"))
3115 feature_bitmap |= L2INPUT_FEAT_LEARN;
3116 else if (unformat (i, "forward"))
3117 feature_bitmap |= L2INPUT_FEAT_FWD;
3118 else if (unformat (i, "flood"))
3119 feature_bitmap |= L2INPUT_FEAT_FLOOD;
3120 else if (unformat (i, "uu-flood"))
3121 feature_bitmap |= L2INPUT_FEAT_UU_FLOOD;
3126 if (sw_if_index_set == 0) {
3127 errmsg ("missing interface name or sw_if_index\n");
3131 M(L2_FLAGS, l2_flags);
3133 mp->sw_if_index = ntohl(sw_if_index);
3134 mp->feature_bitmap = ntohl(feature_bitmap);
3141 static int api_bridge_flags (vat_main_t * vam)
3143 unformat_input_t * i = vam->input;
3144 vl_api_bridge_flags_t *mp;
3151 /* Parse args required to build the message */
3152 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
3153 if (unformat (i, "bd_id %d", &bd_id))
3155 else if (unformat (i, "learn"))
3157 else if (unformat (i, "forward"))
3159 else if (unformat (i, "flood"))
3161 else if (unformat (i, "uu-flood"))
3162 flags |= L2_UU_FLOOD;
3163 else if (unformat (i, "arp-term"))
3164 flags |= L2_ARP_TERM;
3165 else if (unformat (i, "off"))
3167 else if (unformat (i, "disable"))
3173 if (bd_id_set == 0) {
3174 errmsg ("missing bridge domain\n");
3178 M(BRIDGE_FLAGS, bridge_flags);
3180 mp->bd_id = ntohl(bd_id);
3181 mp->feature_bitmap = ntohl(flags);
3182 mp->is_set = is_set;
3189 static int api_bd_ip_mac_add_del (vat_main_t * vam)
3191 unformat_input_t * i = vam->input;
3192 vl_api_bd_ip_mac_add_del_t *mp;
3200 ip4_address_t v4addr;
3201 ip6_address_t v6addr;
3205 /* Parse args required to build the message */
3206 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
3207 if (unformat (i, "bd_id %d", &bd_id)) {
3209 } else if (unformat (i, "%U", unformat_ip4_address, &v4addr)) {
3211 } else if (unformat (i, "%U", unformat_ip6_address, &v6addr)) {
3214 } else if (unformat (i, "%U", unformat_ethernet_address, macaddr)) {
3216 } else if (unformat (i, "del"))
3222 if (bd_id_set == 0) {
3223 errmsg ("missing bridge domain\n");
3225 } else if (ip_set == 0) {
3226 errmsg ("missing IP address\n");
3228 } else if (mac_set == 0) {
3229 errmsg ("missing MAC address\n");
3233 M(BD_IP_MAC_ADD_DEL, bd_ip_mac_add_del);
3235 mp->bd_id = ntohl(bd_id);
3236 mp->is_ipv6 = is_ipv6;
3237 mp->is_add = is_add;
3239 memcpy (mp->ip_address, &v6addr, sizeof (v6addr));
3240 else memcpy (mp->ip_address, &v4addr, sizeof (v4addr));
3241 memcpy (mp->mac_address, macaddr, 6);
3247 static int api_tap_connect (vat_main_t * vam)
3249 unformat_input_t * i = vam->input;
3250 vl_api_tap_connect_t *mp;
3257 memset (mac_address, 0, sizeof (mac_address));
3259 /* Parse args required to build the message */
3260 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
3261 if (unformat (i, "mac %U", unformat_ethernet_address, mac_address)) {
3264 else if (unformat (i, "random-mac"))
3266 else if (unformat (i, "tapname %s", &tap_name))
3272 if (name_set == 0) {
3273 errmsg ("missing tap name\n");
3276 if (vec_len (tap_name) > 63) {
3277 errmsg ("tap name too long\n");
3279 vec_add1 (tap_name, 0);
3281 /* Construct the API message */
3282 M(TAP_CONNECT, tap_connect);
3284 mp->use_random_mac = random_mac;
3285 memcpy (mp->mac_address, mac_address, 6);
3286 memcpy (mp->tap_name, tap_name, vec_len (tap_name));
3287 vec_free (tap_name);
3292 /* Wait for a reply... */
3296 static int api_tap_modify (vat_main_t * vam)
3298 unformat_input_t * i = vam->input;
3299 vl_api_tap_modify_t *mp;
3305 u32 sw_if_index = ~0;
3306 u8 sw_if_index_set = 0;
3308 memset (mac_address, 0, sizeof (mac_address));
3310 /* Parse args required to build the message */
3311 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
3312 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
3313 sw_if_index_set = 1;
3314 else if (unformat (i, "sw_if_index %d", &sw_if_index))
3315 sw_if_index_set = 1;
3316 else if (unformat (i, "mac %U", unformat_ethernet_address, mac_address)) {
3319 else if (unformat (i, "random-mac"))
3321 else if (unformat (i, "tapname %s", &tap_name))
3327 if (sw_if_index_set == 0) {
3328 errmsg ("missing vpp interface name");
3331 if (name_set == 0) {
3332 errmsg ("missing tap name\n");
3335 if (vec_len (tap_name) > 63) {
3336 errmsg ("tap name too long\n");
3338 vec_add1 (tap_name, 0);
3340 /* Construct the API message */
3341 M(TAP_MODIFY, tap_modify);
3343 mp->use_random_mac = random_mac;
3344 mp->sw_if_index = ntohl(sw_if_index);
3345 memcpy (mp->mac_address, mac_address, 6);
3346 memcpy (mp->tap_name, tap_name, vec_len (tap_name));
3347 vec_free (tap_name);
3352 /* Wait for a reply... */
3356 static int api_tap_delete (vat_main_t * vam)
3358 unformat_input_t * i = vam->input;
3359 vl_api_tap_delete_t *mp;
3361 u32 sw_if_index = ~0;
3362 u8 sw_if_index_set = 0;
3364 /* Parse args required to build the message */
3365 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
3366 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
3367 sw_if_index_set = 1;
3368 else if (unformat (i, "sw_if_index %d", &sw_if_index))
3369 sw_if_index_set = 1;
3374 if (sw_if_index_set == 0) {
3375 errmsg ("missing vpp interface name");
3379 /* Construct the API message */
3380 M(TAP_DELETE, tap_delete);
3382 mp->sw_if_index = ntohl(sw_if_index);
3387 /* Wait for a reply... */
3391 static int api_ip_add_del_route (vat_main_t * vam)
3393 unformat_input_t * i = vam->input;
3394 vl_api_ip_add_del_route_t *mp;
3396 u32 sw_if_index = 0, vrf_id = 0;
3397 u8 sw_if_index_set = 0;
3399 u8 is_local = 0, is_drop = 0;
3400 u8 create_vrf_if_needed = 0;
3402 u8 next_hop_weight = 1;
3404 u8 is_multipath = 0;
3406 u8 address_length_set = 0;
3407 u32 lookup_in_vrf = 0;
3408 u32 resolve_attempts = 0;
3409 u32 dst_address_length = 0;
3410 u8 next_hop_set = 0;
3411 ip4_address_t v4_dst_address, v4_next_hop_address;
3412 ip6_address_t v6_dst_address, v6_next_hop_address;
3416 u32 random_add_del = 0;
3417 u32 * random_vector = 0;
3418 uword * random_hash;
3419 u32 random_seed = 0xdeaddabe;
3420 u32 classify_table_index = ~0;
3423 /* Parse args required to build the message */
3424 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
3425 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
3426 sw_if_index_set = 1;
3427 else if (unformat (i, "sw_if_index %d", &sw_if_index))
3428 sw_if_index_set = 1;
3429 else if (unformat (i, "%U", unformat_ip4_address,
3434 else if (unformat (i, "%U", unformat_ip6_address, &v6_dst_address)) {
3438 else if (unformat (i, "/%d", &dst_address_length)) {
3439 address_length_set = 1;
3442 else if (is_ipv6 == 0 && unformat (i, "via %U", unformat_ip4_address,
3443 &v4_next_hop_address)) {
3446 else if (is_ipv6 == 1 && unformat (i, "via %U", unformat_ip6_address,
3447 &v6_next_hop_address)) {
3450 else if (unformat (i, "resolve-attempts %d", &resolve_attempts))
3452 else if (unformat (i, "weight %d", &next_hop_weight))
3454 else if (unformat (i, "drop")) {
3456 } else if (unformat (i, "local")) {
3458 } else if (unformat (i, "classify %d", &classify_table_index)) {
3460 } else if (unformat (i, "del"))
3462 else if (unformat (i, "add"))
3464 else if (unformat (i, "not-last"))
3466 else if (unformat (i, "multipath"))
3468 else if (unformat (i, "vrf %d", &vrf_id))
3470 else if (unformat (i, "create-vrf"))
3471 create_vrf_if_needed = 1;
3472 else if (unformat (i, "count %d", &count))
3474 else if (unformat (i, "lookup-in-vrf %d", &lookup_in_vrf))
3476 else if (unformat (i, "random"))
3478 else if (unformat (i, "seed %d", &random_seed))
3481 clib_warning ("parse error '%U'", format_unformat_error, i);
3486 if (resolve_attempts > 0 && sw_if_index_set == 0) {
3487 errmsg ("ARP resolution needs explicit interface or sw_if_index\n");
3491 if (!next_hop_set && !is_drop && !is_local && !is_classify) {
3492 errmsg ("next hop / local / drop / classify not set\n");
3496 if (address_set == 0) {
3497 errmsg ("missing addresses\n");
3501 if (address_length_set == 0) {
3502 errmsg ("missing address length\n");
3506 /* Generate a pile of unique, random routes */
3507 if (random_add_del) {
3508 u32 this_random_address;
3509 random_hash = hash_create (count, sizeof(uword));
3511 hash_set (random_hash, v4_next_hop_address.as_u32, 1);
3512 for (j = 0; j <= count; j++) {
3514 this_random_address = random_u32 (&random_seed);
3515 this_random_address =
3516 clib_host_to_net_u32 (this_random_address);
3517 } while (hash_get (random_hash, this_random_address));
3518 vec_add1 (random_vector, this_random_address);
3519 hash_set (random_hash, this_random_address, 1);
3521 hash_free (random_hash);
3522 v4_dst_address.as_u32 = random_vector[0];
3526 /* Turn on async mode */
3527 vam->async_mode = 1;
3528 vam->async_errors = 0;
3529 before = vat_time_now(vam);
3532 for (j = 0; j < count; j++) {
3533 /* Construct the API message */
3534 M(IP_ADD_DEL_ROUTE, ip_add_del_route);
3536 mp->next_hop_sw_if_index = ntohl (sw_if_index);
3537 mp->vrf_id = ntohl (vrf_id);
3538 if (resolve_attempts > 0) {
3539 mp->resolve_attempts = ntohl (resolve_attempts);
3540 mp->resolve_if_needed = 1;
3542 mp->create_vrf_if_needed = create_vrf_if_needed;
3544 mp->is_add = is_add;
3545 mp->is_drop = is_drop;
3546 mp->is_ipv6 = is_ipv6;
3547 mp->is_local = is_local;
3548 mp->is_classify = is_classify;
3549 mp->is_multipath = is_multipath;
3550 mp->not_last = not_last;
3551 mp->next_hop_weight = next_hop_weight;
3552 mp->dst_address_length = dst_address_length;
3553 mp->lookup_in_vrf = ntohl(lookup_in_vrf);
3554 mp->classify_table_index = ntohl(classify_table_index);
3557 memcpy (mp->dst_address, &v6_dst_address, sizeof (v6_dst_address));
3559 memcpy (mp->next_hop_address, &v6_next_hop_address,
3560 sizeof (v6_next_hop_address));
3561 increment_v6_address (&v6_dst_address);
3563 memcpy (mp->dst_address, &v4_dst_address, sizeof (v4_dst_address));
3565 memcpy (mp->next_hop_address, &v4_next_hop_address,
3566 sizeof (v4_next_hop_address));
3568 v4_dst_address.as_u32 = random_vector[j+1];
3570 increment_v4_address (&v4_dst_address);
3576 /* When testing multiple add/del ops, use a control-ping to sync */
3578 vl_api_control_ping_t * mp;
3581 /* Shut off async mode */
3582 vam->async_mode = 0;
3584 M(CONTROL_PING, control_ping);
3587 timeout = vat_time_now(vam) + 1.0;
3588 while (vat_time_now (vam) < timeout)
3589 if (vam->result_ready == 1)
3594 if (vam->retval == -99)
3595 errmsg ("timeout\n");
3597 if (vam->async_errors > 0) {
3598 errmsg ("%d asynchronous errors\n", vam->async_errors);
3601 vam->async_errors = 0;
3602 after = vat_time_now(vam);
3604 fformat(vam->ofp, "%d routes in %.6f secs, %.2f routes/sec\n",
3605 count, after - before, count / (after - before));
3607 /* Wait for a reply... */
3611 /* Return the good/bad news */
3612 return (vam->retval);
3615 static int api_proxy_arp_add_del (vat_main_t * vam)
3617 unformat_input_t * i = vam->input;
3618 vl_api_proxy_arp_add_del_t *mp;
3622 ip4_address_t lo, hi;
3625 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
3626 if (unformat (i, "vrf %d", &vrf_id))
3628 else if (unformat (i, "%U - %U", unformat_ip4_address, &lo,
3629 unformat_ip4_address, &hi))
3631 else if (unformat (i, "del"))
3634 clib_warning ("parse error '%U'", format_unformat_error, i);
3639 if (range_set == 0) {
3640 errmsg ("address range not set\n");
3644 M(PROXY_ARP_ADD_DEL, proxy_arp_add_del);
3646 mp->vrf_id = ntohl(vrf_id);
3647 mp->is_add = is_add;
3648 memcpy(mp->low_address, &lo, sizeof (mp->low_address));
3649 memcpy(mp->hi_address, &hi, sizeof (mp->hi_address));
3656 static int api_proxy_arp_intfc_enable_disable (vat_main_t * vam)
3658 unformat_input_t * i = vam->input;
3659 vl_api_proxy_arp_intfc_enable_disable_t *mp;
3663 u8 sw_if_index_set = 0;
3665 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
3666 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
3667 sw_if_index_set = 1;
3668 else if (unformat (i, "sw_if_index %d", &sw_if_index))
3669 sw_if_index_set = 1;
3670 else if (unformat (i, "enable"))
3672 else if (unformat (i, "disable"))
3675 clib_warning ("parse error '%U'", format_unformat_error, i);
3680 if (sw_if_index_set == 0) {
3681 errmsg ("missing interface name or sw_if_index\n");
3685 M(PROXY_ARP_INTFC_ENABLE_DISABLE, proxy_arp_intfc_enable_disable);
3687 mp->sw_if_index = ntohl(sw_if_index);
3688 mp->enable_disable = enable;
3695 static int api_mpls_add_del_decap (vat_main_t * vam)
3697 unformat_input_t * i = vam->input;
3698 vl_api_mpls_add_del_decap_t *mp;
3707 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
3708 if (unformat (i, "rx_vrf_id %d", &rx_vrf_id))
3710 else if (unformat (i, "tx_vrf_id %d", &tx_vrf_id))
3712 else if (unformat (i, "label %d", &label))
3714 else if (unformat (i, "next-index %d", &next_index))
3716 else if (unformat (i, "del"))
3718 else if (unformat (i, "s-bit-clear"))
3721 clib_warning ("parse error '%U'", format_unformat_error, i);
3726 M(MPLS_ADD_DEL_DECAP, mpls_add_del_decap);
3728 mp->rx_vrf_id = ntohl(rx_vrf_id);
3729 mp->tx_vrf_id = ntohl(tx_vrf_id);
3730 mp->label = ntohl(label);
3731 mp->next_index = ntohl(next_index);
3733 mp->is_add = is_add;
3740 static int api_mpls_add_del_encap (vat_main_t * vam)
3742 unformat_input_t * i = vam->input;
3743 vl_api_mpls_add_del_encap_t *mp;
3748 ip4_address_t dst_address;
3751 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
3752 if (unformat (i, "vrf %d", &vrf_id))
3754 else if (unformat (i, "label %d", &label))
3755 vec_add1 (labels, ntohl(label));
3756 else if (unformat (i, "dst %U", unformat_ip4_address, &dst_address))
3758 else if (unformat (i, "del"))
3761 clib_warning ("parse error '%U'", format_unformat_error, i);
3766 if (vec_len (labels) == 0) {
3767 errmsg ("missing encap label stack\n");
3771 M2(MPLS_ADD_DEL_ENCAP, mpls_add_del_encap,
3772 sizeof (u32) * vec_len (labels));
3774 mp->vrf_id = ntohl(vrf_id);
3775 memcpy(mp->dst_address, &dst_address, sizeof (dst_address));
3776 mp->is_add = is_add;
3777 mp->nlabels = vec_len (labels);
3778 memcpy(mp->labels, labels, sizeof(u32)*mp->nlabels);
3787 static int api_mpls_gre_add_del_tunnel (vat_main_t * vam)
3789 unformat_input_t * i = vam->input;
3790 vl_api_mpls_gre_add_del_tunnel_t *mp;
3792 u32 inner_vrf_id = 0;
3793 u32 outer_vrf_id = 0;
3794 ip4_address_t src_address;
3795 ip4_address_t dst_address;
3796 ip4_address_t intfc_address;
3798 u8 intfc_address_length = 0;
3802 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
3803 if (unformat (i, "inner_vrf_id %d", &inner_vrf_id))
3805 else if (unformat (i, "outer_vrf_id %d", &outer_vrf_id))
3807 else if (unformat (i, "src %U", unformat_ip4_address, &src_address))
3809 else if (unformat (i, "dst %U", unformat_ip4_address, &dst_address))
3811 else if (unformat (i, "adj %U/%d", unformat_ip4_address,
3812 &intfc_address, &tmp))
3813 intfc_address_length = tmp;
3814 else if (unformat (i, "l2-only"))
3816 else if (unformat (i, "del"))
3819 clib_warning ("parse error '%U'", format_unformat_error, i);
3824 M(MPLS_GRE_ADD_DEL_TUNNEL, mpls_gre_add_del_tunnel);
3826 mp->inner_vrf_id = ntohl(inner_vrf_id);
3827 mp->outer_vrf_id = ntohl(outer_vrf_id);
3828 memcpy(mp->src_address, &src_address, sizeof (src_address));
3829 memcpy(mp->dst_address, &dst_address, sizeof (dst_address));
3830 memcpy(mp->intfc_address, &intfc_address, sizeof (intfc_address));
3831 mp->intfc_address_length = intfc_address_length;
3832 mp->l2_only = l2_only;
3833 mp->is_add = is_add;
3840 static int api_mpls_ethernet_add_del_tunnel (vat_main_t * vam)
3842 unformat_input_t * i = vam->input;
3843 vl_api_mpls_ethernet_add_del_tunnel_t *mp;
3845 u32 inner_vrf_id = 0;
3846 ip4_address_t intfc_address;
3847 u8 dst_mac_address[6];
3850 u8 intfc_address_length = 0;
3854 int tx_sw_if_index_set = 0;
3856 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
3857 if (unformat (i, "vrf %d", &inner_vrf_id))
3859 else if (unformat (i, "adj %U/%d", unformat_ip4_address,
3860 &intfc_address, &tmp))
3861 intfc_address_length = tmp;
3862 else if (unformat (i, "%U",
3863 unformat_sw_if_index, vam, &tx_sw_if_index))
3864 tx_sw_if_index_set = 1;
3865 else if (unformat (i, "tx_sw_if_index %d", &tx_sw_if_index))
3866 tx_sw_if_index_set = 1;
3867 else if (unformat (i, "dst %U", unformat_ethernet_address,
3870 else if (unformat (i, "l2-only"))
3872 else if (unformat (i, "del"))
3875 clib_warning ("parse error '%U'", format_unformat_error, i);
3881 errmsg ("dst (mac address) not set\n");
3884 if (!tx_sw_if_index_set) {
3885 errmsg ("tx-intfc not set\n");
3889 M(MPLS_ETHERNET_ADD_DEL_TUNNEL, mpls_ethernet_add_del_tunnel);
3891 mp->vrf_id = ntohl(inner_vrf_id);
3892 memcpy (mp->adj_address, &intfc_address, sizeof (intfc_address));
3893 mp->adj_address_length = intfc_address_length;
3894 memcpy (mp->dst_mac_address, dst_mac_address, sizeof (dst_mac_address));
3895 mp->tx_sw_if_index = ntohl(tx_sw_if_index);
3896 mp->l2_only = l2_only;
3897 mp->is_add = is_add;
3904 static int api_mpls_ethernet_add_del_tunnel_2 (vat_main_t * vam)
3906 unformat_input_t * i = vam->input;
3907 vl_api_mpls_ethernet_add_del_tunnel_2_t *mp;
3909 u32 inner_vrf_id = 0;
3910 u32 outer_vrf_id = 0;
3911 ip4_address_t adj_address;
3912 int adj_address_set = 0;
3913 ip4_address_t next_hop_address;
3914 int next_hop_address_set = 0;
3916 u8 adj_address_length = 0;
3919 u32 resolve_attempts = 5;
3920 u8 resolve_if_needed = 1;
3922 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
3923 if (unformat (i, "inner_vrf_id %d", &inner_vrf_id))
3925 else if (unformat (i, "outer_vrf_id %d", &outer_vrf_id))
3927 else if (unformat (i, "adj %U/%d", unformat_ip4_address,
3928 &adj_address, &tmp)) {
3929 adj_address_length = tmp;
3930 adj_address_set = 1;
3932 else if (unformat (i, "next-hop %U", unformat_ip4_address,
3934 next_hop_address_set = 1;
3935 else if (unformat (i, "resolve-attempts %d", &resolve_attempts))
3937 else if (unformat (i, "resolve-if-needed %d", &tmp))
3938 resolve_if_needed = tmp;
3939 else if (unformat (i, "l2-only"))
3941 else if (unformat (i, "del"))
3944 clib_warning ("parse error '%U'", format_unformat_error, i);
3949 if (!adj_address_set) {
3950 errmsg ("adjacency address/mask not set\n");
3953 if (!next_hop_address_set) {
3954 errmsg ("ip4 next hop address (in outer fib) not set\n");
3958 M(MPLS_ETHERNET_ADD_DEL_TUNNEL_2, mpls_ethernet_add_del_tunnel_2);
3960 mp->inner_vrf_id = ntohl(inner_vrf_id);
3961 mp->outer_vrf_id = ntohl(outer_vrf_id);
3962 mp->resolve_attempts = ntohl(resolve_attempts);
3963 mp->resolve_if_needed = resolve_if_needed;
3964 mp->is_add = is_add;
3965 mp->l2_only = l2_only;
3966 memcpy (mp->adj_address, &adj_address, sizeof (adj_address));
3967 mp->adj_address_length = adj_address_length;
3968 memcpy (mp->next_hop_ip4_address_in_outer_vrf, &next_hop_address,
3969 sizeof (next_hop_address));
3976 static int api_sw_interface_set_unnumbered (vat_main_t * vam)
3978 unformat_input_t * i = vam->input;
3979 vl_api_sw_interface_set_unnumbered_t *mp;
3984 u8 sw_if_index_set = 0;
3986 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
3987 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
3988 sw_if_index_set = 1;
3989 else if (unformat (i, "sw_if_index %d", &sw_if_index))
3990 sw_if_index_set = 1;
3991 else if (unformat (i, "unnum_if_index %d", &unnum_sw_index))
3993 else if (unformat (i, "del"))
3996 clib_warning ("parse error '%U'", format_unformat_error, i);
4001 if (sw_if_index_set == 0) {
4002 errmsg ("missing interface name or sw_if_index\n");
4006 M(SW_INTERFACE_SET_UNNUMBERED, sw_interface_set_unnumbered);
4008 mp->sw_if_index = ntohl(sw_if_index);
4009 mp->unnumbered_sw_if_index = ntohl(unnum_sw_index);
4010 mp->is_add = is_add;
4017 static int api_ip_neighbor_add_del (vat_main_t * vam)
4019 unformat_input_t * i = vam->input;
4020 vl_api_ip_neighbor_add_del_t *mp;
4023 u8 sw_if_index_set = 0;
4029 u8 v4_address_set = 0;
4030 u8 v6_address_set = 0;
4031 ip4_address_t v4address;
4032 ip6_address_t v6address;
4034 memset (mac_address, 0, sizeof (mac_address));
4036 /* Parse args required to build the message */
4037 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
4038 if (unformat (i, "mac %U", unformat_ethernet_address, mac_address)) {
4041 else if (unformat (i, "del"))
4043 else if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
4044 sw_if_index_set = 1;
4045 else if (unformat (i, "sw_if_index %d", &sw_if_index))
4046 sw_if_index_set = 1;
4047 else if (unformat (i, "is_static"))
4049 else if (unformat (i, "vrf %d", &vrf_id))
4051 else if (unformat (i, "dst %U",
4052 unformat_ip4_address, &v4address))
4054 else if (unformat (i, "dst %U",
4055 unformat_ip6_address, &v6address))
4058 clib_warning ("parse error '%U'", format_unformat_error, i);
4063 if (sw_if_index_set == 0) {
4064 errmsg ("missing interface name or sw_if_index\n");
4067 if (v4_address_set && v6_address_set) {
4068 errmsg ("both v4 and v6 addresses set\n");
4071 if (!v4_address_set && !v6_address_set) {
4072 errmsg ("no addresses set\n");
4076 /* Construct the API message */
4077 M(IP_NEIGHBOR_ADD_DEL, ip_neighbor_add_del);
4079 mp->sw_if_index = ntohl (sw_if_index);
4080 mp->is_add = is_add;
4081 mp->vrf_id = ntohl (vrf_id);
4082 mp->is_static = is_static;
4084 memcpy (mp->mac_address, mac_address, 6);
4085 if (v6_address_set) {
4087 memcpy (mp->dst_address, &v6address, sizeof (v6address));
4089 /* mp->is_ipv6 = 0; via memset in M macro above */
4090 memcpy (mp->dst_address, &v4address, sizeof (v4address));
4096 /* Wait for a reply, return good/bad news */
4103 static int api_reset_vrf (vat_main_t * vam)
4105 unformat_input_t * i = vam->input;
4106 vl_api_reset_vrf_t *mp;
4112 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
4113 if (unformat (i, "vrf %d", &vrf_id))
4115 else if (unformat (i, "ipv6"))
4118 clib_warning ("parse error '%U'", format_unformat_error, i);
4123 if (vrf_id_set == 0) {
4124 errmsg ("missing vrf id\n");
4128 M(RESET_VRF, reset_vrf);
4130 mp->vrf_id = ntohl(vrf_id);
4131 mp->is_ipv6 = is_ipv6;
4138 static int api_create_vlan_subif (vat_main_t * vam)
4140 unformat_input_t * i = vam->input;
4141 vl_api_create_vlan_subif_t *mp;
4144 u8 sw_if_index_set = 0;
4148 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
4149 if (unformat (i, "sw_if_index %d", &sw_if_index))
4150 sw_if_index_set = 1;
4151 else if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
4152 sw_if_index_set = 1;
4153 else if (unformat (i, "vlan %d", &vlan_id))
4156 clib_warning ("parse error '%U'", format_unformat_error, i);
4161 if (sw_if_index_set == 0) {
4162 errmsg ("missing interface name or sw_if_index\n");
4166 if (vlan_id_set == 0) {
4167 errmsg ("missing vlan_id\n");
4170 M(CREATE_VLAN_SUBIF, create_vlan_subif);
4172 mp->sw_if_index = ntohl(sw_if_index);
4173 mp->vlan_id = ntohl(vlan_id);
4180 #define foreach_create_subif_bit \
4187 _(outer_vlan_id_any) \
4188 _(inner_vlan_id_any)
4190 static int api_create_subif (vat_main_t * vam)
4192 unformat_input_t * i = vam->input;
4193 vl_api_create_subif_t *mp;
4196 u8 sw_if_index_set = 0;
4203 u32 exact_match = 0;
4204 u32 default_sub = 0;
4205 u32 outer_vlan_id_any = 0;
4206 u32 inner_vlan_id_any = 0;
4208 u16 outer_vlan_id = 0;
4209 u16 inner_vlan_id = 0;
4211 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
4212 if (unformat (i, "sw_if_index %d", &sw_if_index))
4213 sw_if_index_set = 1;
4214 else if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
4215 sw_if_index_set = 1;
4216 else if (unformat (i, "sub_id %d", &sub_id))
4218 else if (unformat (i, "outer_vlan_id %d", &tmp))
4219 outer_vlan_id = tmp;
4220 else if (unformat (i, "inner_vlan_id %d", &tmp))
4221 inner_vlan_id = tmp;
4223 #define _(a) else if (unformat (i, #a)) a = 1 ;
4224 foreach_create_subif_bit
4228 clib_warning ("parse error '%U'", format_unformat_error, i);
4233 if (sw_if_index_set == 0) {
4234 errmsg ("missing interface name or sw_if_index\n");
4238 if (sub_id_set == 0) {
4239 errmsg ("missing sub_id\n");
4242 M(CREATE_SUBIF, create_subif);
4244 mp->sw_if_index = ntohl(sw_if_index);
4245 mp->sub_id = ntohl(sub_id);
4247 #define _(a) mp->a = a;
4248 foreach_create_subif_bit;
4251 mp->outer_vlan_id = ntohs (outer_vlan_id);
4252 mp->inner_vlan_id = ntohs (inner_vlan_id);
4259 static int api_oam_add_del (vat_main_t * vam)
4261 unformat_input_t * i = vam->input;
4262 vl_api_oam_add_del_t *mp;
4266 ip4_address_t src, dst;
4270 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
4271 if (unformat (i, "vrf %d", &vrf_id))
4273 else if (unformat (i, "src %U", unformat_ip4_address, &src))
4275 else if (unformat (i, "dst %U", unformat_ip4_address, &dst))
4277 else if (unformat (i, "del"))
4280 clib_warning ("parse error '%U'", format_unformat_error, i);
4286 errmsg ("missing src addr\n");
4291 errmsg ("missing dst addr\n");
4295 M(OAM_ADD_DEL, oam_add_del);
4297 mp->vrf_id = ntohl(vrf_id);
4298 mp->is_add = is_add;
4299 memcpy(mp->src_address, &src, sizeof (mp->src_address));
4300 memcpy(mp->dst_address, &dst, sizeof (mp->dst_address));
4307 static int api_reset_fib (vat_main_t * vam)
4309 unformat_input_t * i = vam->input;
4310 vl_api_reset_fib_t *mp;
4316 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
4317 if (unformat (i, "vrf %d", &vrf_id))
4319 else if (unformat (i, "ipv6"))
4322 clib_warning ("parse error '%U'", format_unformat_error, i);
4327 if (vrf_id_set == 0) {
4328 errmsg ("missing vrf id\n");
4332 M(RESET_FIB, reset_fib);
4334 mp->vrf_id = ntohl(vrf_id);
4335 mp->is_ipv6 = is_ipv6;
4342 static int api_dhcp_proxy_config (vat_main_t * vam)
4344 unformat_input_t * i = vam->input;
4345 vl_api_dhcp_proxy_config_t *mp;
4350 u8 v4_address_set = 0;
4351 u8 v6_address_set = 0;
4352 ip4_address_t v4address;
4353 ip6_address_t v6address;
4354 u8 v4_src_address_set = 0;
4355 u8 v6_src_address_set = 0;
4356 ip4_address_t v4srcaddress;
4357 ip6_address_t v6srcaddress;
4359 /* Parse args required to build the message */
4360 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
4361 if (unformat (i, "del"))
4363 else if (unformat (i, "vrf %d", &vrf_id))
4365 else if (unformat (i, "insert-cid %d", &insert_cid))
4367 else if (unformat (i, "svr %U",
4368 unformat_ip4_address, &v4address))
4370 else if (unformat (i, "svr %U",
4371 unformat_ip6_address, &v6address))
4373 else if (unformat (i, "src %U",
4374 unformat_ip4_address, &v4srcaddress))
4375 v4_src_address_set = 1;
4376 else if (unformat (i, "src %U",
4377 unformat_ip6_address, &v6srcaddress))
4378 v6_src_address_set = 1;
4383 if (v4_address_set && v6_address_set) {
4384 errmsg ("both v4 and v6 server addresses set\n");
4387 if (!v4_address_set && !v6_address_set) {
4388 errmsg ("no server addresses set\n");
4392 if (v4_src_address_set && v6_src_address_set) {
4393 errmsg ("both v4 and v6 src addresses set\n");
4396 if (!v4_src_address_set && !v6_src_address_set) {
4397 errmsg ("no src addresses set\n");
4401 if (!(v4_src_address_set && v4_address_set) &&
4402 !(v6_src_address_set && v6_address_set)) {
4403 errmsg ("no matching server and src addresses set\n");
4407 /* Construct the API message */
4408 M(DHCP_PROXY_CONFIG, dhcp_proxy_config);
4410 mp->insert_circuit_id = insert_cid;
4411 mp->is_add = is_add;
4412 mp->vrf_id = ntohl (vrf_id);
4413 if (v6_address_set) {
4415 memcpy (mp->dhcp_server, &v6address, sizeof (v6address));
4416 memcpy (mp->dhcp_src_address, &v6srcaddress, sizeof (v6address));
4418 memcpy (mp->dhcp_server, &v4address, sizeof (v4address));
4419 memcpy (mp->dhcp_src_address, &v4srcaddress, sizeof (v4address));
4425 /* Wait for a reply, return good/bad news */
4431 static int api_dhcp_proxy_config_2 (vat_main_t * vam)
4433 unformat_input_t * i = vam->input;
4434 vl_api_dhcp_proxy_config_2_t *mp;
4437 u32 server_vrf_id = 0;
4440 u8 v4_address_set = 0;
4441 u8 v6_address_set = 0;
4442 ip4_address_t v4address;
4443 ip6_address_t v6address;
4444 u8 v4_src_address_set = 0;
4445 u8 v6_src_address_set = 0;
4446 ip4_address_t v4srcaddress;
4447 ip6_address_t v6srcaddress;
4449 /* Parse args required to build the message */
4450 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
4451 if (unformat (i, "del"))
4453 else if (unformat (i, "rx_vrf_id %d", &rx_vrf_id))
4455 else if (unformat (i, "server_vrf_id %d", &server_vrf_id))
4457 else if (unformat (i, "insert-cid %d", &insert_cid))
4459 else if (unformat (i, "svr %U",
4460 unformat_ip4_address, &v4address))
4462 else if (unformat (i, "svr %U",
4463 unformat_ip6_address, &v6address))
4465 else if (unformat (i, "src %U",
4466 unformat_ip4_address, &v4srcaddress))
4467 v4_src_address_set = 1;
4468 else if (unformat (i, "src %U",
4469 unformat_ip6_address, &v6srcaddress))
4470 v6_src_address_set = 1;
4475 if (v4_address_set && v6_address_set) {
4476 errmsg ("both v4 and v6 server addresses set\n");
4479 if (!v4_address_set && !v6_address_set) {
4480 errmsg ("no server addresses set\n");
4484 if (v4_src_address_set && v6_src_address_set) {
4485 errmsg ("both v4 and v6 src addresses set\n");
4488 if (!v4_src_address_set && !v6_src_address_set) {
4489 errmsg ("no src addresses set\n");
4493 if (!(v4_src_address_set && v4_address_set) &&
4494 !(v6_src_address_set && v6_address_set)) {
4495 errmsg ("no matching server and src addresses set\n");
4499 /* Construct the API message */
4500 M(DHCP_PROXY_CONFIG_2, dhcp_proxy_config_2);
4502 mp->insert_circuit_id = insert_cid;
4503 mp->is_add = is_add;
4504 mp->rx_vrf_id = ntohl (rx_vrf_id);
4505 mp->server_vrf_id = ntohl (server_vrf_id);
4506 if (v6_address_set) {
4508 memcpy (mp->dhcp_server, &v6address, sizeof (v6address));
4509 memcpy (mp->dhcp_src_address, &v6srcaddress, sizeof (v6address));
4511 memcpy (mp->dhcp_server, &v4address, sizeof (v4address));
4512 memcpy (mp->dhcp_src_address, &v4srcaddress, sizeof (v4address));
4518 /* Wait for a reply, return good/bad news */
4524 static int api_dhcp_proxy_set_vss (vat_main_t * vam)
4526 unformat_input_t * i = vam->input;
4527 vl_api_dhcp_proxy_set_vss_t *mp;
4538 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
4539 if (unformat (i, "tbl_id %d", &tbl_id))
4541 if (unformat (i, "fib_id %d", &fib_id))
4543 if (unformat (i, "oui %d", &oui))
4545 else if (unformat (i, "ipv6"))
4547 else if (unformat (i, "del"))
4550 clib_warning ("parse error '%U'", format_unformat_error, i);
4555 if (tbl_id_set == 0) {
4556 errmsg ("missing tbl id\n");
4560 if (fib_id_set == 0) {
4561 errmsg ("missing fib id\n");
4565 errmsg ("missing oui\n");
4569 M(DHCP_PROXY_SET_VSS, dhcp_proxy_set_vss);
4570 mp->tbl_id = ntohl(tbl_id);
4571 mp->fib_id = ntohl(fib_id);
4572 mp->oui = ntohl(oui);
4573 mp->is_ipv6 = is_ipv6;
4574 mp->is_add = is_add;
4581 static int api_dhcp_client_config (vat_main_t * vam)
4583 unformat_input_t * i = vam->input;
4584 vl_api_dhcp_client_config_t *mp;
4587 u8 sw_if_index_set = 0;
4590 u8 disable_event = 0;
4592 /* Parse args required to build the message */
4593 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
4594 if (unformat (i, "del"))
4596 else if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
4597 sw_if_index_set = 1;
4598 else if (unformat (i, "sw_if_index %d", &sw_if_index))
4599 sw_if_index_set = 1;
4600 else if (unformat (i, "hostname %s", &hostname))
4602 else if (unformat (i, "disable_event"))
4608 if (sw_if_index_set == 0) {
4609 errmsg ("missing interface name or sw_if_index\n");
4613 if (vec_len (hostname) > 63) {
4614 errmsg ("hostname too long\n");
4616 vec_add1 (hostname, 0);
4618 /* Construct the API message */
4619 M(DHCP_CLIENT_CONFIG, dhcp_client_config);
4621 mp->sw_if_index = ntohl (sw_if_index);
4622 memcpy (mp->hostname, hostname, vec_len (hostname));
4623 vec_free (hostname);
4624 mp->is_add = is_add;
4625 mp->want_dhcp_event = disable_event ? 0 : 1;
4631 /* Wait for a reply, return good/bad news */
4637 static int api_set_ip_flow_hash (vat_main_t * vam)
4639 unformat_input_t * i = vam->input;
4640 vl_api_set_ip_flow_hash_t *mp;
4652 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
4653 if (unformat (i, "vrf %d", &vrf_id))
4655 else if (unformat (i, "ipv6"))
4657 else if (unformat (i, "src"))
4659 else if (unformat (i, "dst"))
4661 else if (unformat (i, "sport"))
4663 else if (unformat (i, "dport"))
4665 else if (unformat (i, "proto"))
4667 else if (unformat (i, "reverse"))
4671 clib_warning ("parse error '%U'", format_unformat_error, i);
4676 if (vrf_id_set == 0) {
4677 errmsg ("missing vrf id\n");
4681 M(SET_IP_FLOW_HASH, set_ip_flow_hash);
4687 mp->reverse = reverse;
4688 mp->vrf_id = ntohl(vrf_id);
4689 mp->is_ipv6 = is_ipv6;
4696 static int api_sw_interface_ip6_enable_disable (vat_main_t * vam)
4698 unformat_input_t * i = vam->input;
4699 vl_api_sw_interface_ip6_enable_disable_t *mp;
4702 u8 sw_if_index_set = 0;
4705 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
4706 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
4707 sw_if_index_set = 1;
4708 else if (unformat (i, "sw_if_index %d", &sw_if_index))
4709 sw_if_index_set = 1;
4710 else if (unformat (i, "enable"))
4712 else if (unformat (i, "disable"))
4715 clib_warning ("parse error '%U'", format_unformat_error, i);
4720 if (sw_if_index_set == 0) {
4721 errmsg ("missing interface name or sw_if_index\n");
4725 M(SW_INTERFACE_IP6_ENABLE_DISABLE, sw_interface_ip6_enable_disable);
4727 mp->sw_if_index = ntohl(sw_if_index);
4728 mp->enable = enable;
4735 static int api_sw_interface_ip6_set_link_local_address (vat_main_t * vam)
4737 unformat_input_t * i = vam->input;
4738 vl_api_sw_interface_ip6_set_link_local_address_t *mp;
4741 u8 sw_if_index_set = 0;
4742 u32 address_length = 0;
4743 u8 v6_address_set = 0;
4744 ip6_address_t v6address;
4746 /* Parse args required to build the message */
4747 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
4748 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
4749 sw_if_index_set = 1;
4750 else if (unformat (i, "sw_if_index %d", &sw_if_index))
4751 sw_if_index_set = 1;
4752 else if (unformat (i, "%U/%d",
4753 unformat_ip6_address, &v6address,
4760 if (sw_if_index_set == 0) {
4761 errmsg ("missing interface name or sw_if_index\n");
4764 if (!v6_address_set) {
4765 errmsg ("no address set\n");
4769 /* Construct the API message */
4770 M(SW_INTERFACE_IP6_SET_LINK_LOCAL_ADDRESS, \
4771 sw_interface_ip6_set_link_local_address);
4773 mp->sw_if_index = ntohl (sw_if_index);
4774 memcpy (mp->address, &v6address, sizeof (v6address));
4775 mp->address_length = address_length;
4780 /* Wait for a reply, return good/bad news */
4788 static int api_sw_interface_ip6nd_ra_prefix (vat_main_t * vam)
4790 unformat_input_t * i = vam->input;
4791 vl_api_sw_interface_ip6nd_ra_prefix_t *mp;
4794 u8 sw_if_index_set = 0;
4795 u32 address_length = 0;
4796 u8 v6_address_set = 0;
4797 ip6_address_t v6address;
4799 u8 no_advertise = 0;
4801 u8 no_autoconfig = 0;
4804 u32 val_lifetime = 0;
4805 u32 pref_lifetime = 0;
4807 /* Parse args required to build the message */
4808 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
4809 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
4810 sw_if_index_set = 1;
4811 else if (unformat (i, "sw_if_index %d", &sw_if_index))
4812 sw_if_index_set = 1;
4813 else if (unformat (i, "%U/%d",
4814 unformat_ip6_address, &v6address,
4817 else if (unformat (i, "val_life %d", &val_lifetime))
4819 else if (unformat (i, "pref_life %d", &pref_lifetime))
4821 else if (unformat (i, "def"))
4823 else if (unformat (i, "noadv"))
4825 else if (unformat (i, "offl"))
4827 else if (unformat (i, "noauto"))
4829 else if (unformat (i, "nolink"))
4831 else if (unformat (i, "isno"))
4834 clib_warning ("parse error '%U'", format_unformat_error, i);
4839 if (sw_if_index_set == 0) {
4840 errmsg ("missing interface name or sw_if_index\n");
4843 if (!v6_address_set) {
4844 errmsg ("no address set\n");
4848 /* Construct the API message */
4849 M(SW_INTERFACE_IP6ND_RA_PREFIX, sw_interface_ip6nd_ra_prefix);
4851 mp->sw_if_index = ntohl (sw_if_index);
4852 memcpy (mp->address, &v6address, sizeof (v6address));
4853 mp->address_length = address_length;
4854 mp->use_default = use_default;
4855 mp->no_advertise = no_advertise;
4856 mp->off_link = off_link;
4857 mp->no_autoconfig = no_autoconfig;
4858 mp->no_onlink = no_onlink;
4860 mp->val_lifetime = ntohl(val_lifetime);
4861 mp->pref_lifetime = ntohl(pref_lifetime);
4866 /* Wait for a reply, return good/bad news */
4873 static int api_sw_interface_ip6nd_ra_config (vat_main_t * vam)
4875 unformat_input_t * i = vam->input;
4876 vl_api_sw_interface_ip6nd_ra_config_t *mp;
4879 u8 sw_if_index_set = 0;
4884 u8 send_unicast = 0;
4887 u8 default_router = 0;
4888 u32 max_interval = 0;
4889 u32 min_interval = 0;
4891 u32 initial_count = 0;
4892 u32 initial_interval = 0;
4895 /* Parse args required to build the message */
4896 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
4897 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
4898 sw_if_index_set = 1;
4899 else if (unformat (i, "sw_if_index %d", &sw_if_index))
4900 sw_if_index_set = 1;
4901 else if (unformat (i, "maxint %d", &max_interval))
4903 else if (unformat (i, "minint %d", &min_interval))
4905 else if (unformat (i, "life %d", &lifetime))
4907 else if (unformat (i, "count %d", &initial_count))
4909 else if (unformat (i, "interval %d", &initial_interval))
4911 else if (unformat (i, "surpress"))
4913 else if (unformat (i, "managed"))
4915 else if (unformat (i, "other"))
4917 else if (unformat (i, "ll"))
4919 else if (unformat (i, "send"))
4921 else if (unformat (i, "cease"))
4923 else if (unformat (i, "isno"))
4925 else if (unformat (i, "def"))
4928 clib_warning ("parse error '%U'", format_unformat_error, i);
4933 if (sw_if_index_set == 0) {
4934 errmsg ("missing interface name or sw_if_index\n");
4938 /* Construct the API message */
4939 M(SW_INTERFACE_IP6ND_RA_CONFIG, sw_interface_ip6nd_ra_config);
4941 mp->sw_if_index = ntohl (sw_if_index);
4942 mp->max_interval = ntohl(max_interval);
4943 mp->min_interval = ntohl(min_interval);
4944 mp->lifetime = ntohl(lifetime);
4945 mp->initial_count = ntohl(initial_count);
4946 mp->initial_interval = ntohl(initial_interval);
4947 mp->surpress = surpress;
4948 mp->managed = managed;
4950 mp->ll_option = ll_option;
4951 mp->send_unicast = send_unicast;
4954 mp->default_router = default_router;
4959 /* Wait for a reply, return good/bad news */
4966 static int api_set_arp_neighbor_limit (vat_main_t * vam)
4968 unformat_input_t * i = vam->input;
4969 vl_api_set_arp_neighbor_limit_t *mp;
4975 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
4976 if (unformat (i, "arp_nbr_limit %d", &arp_nbr_limit))
4978 else if (unformat (i, "ipv6"))
4981 clib_warning ("parse error '%U'", format_unformat_error, i);
4986 if (limit_set == 0) {
4987 errmsg ("missing limit value\n");
4991 M(SET_ARP_NEIGHBOR_LIMIT, set_arp_neighbor_limit);
4993 mp->arp_neighbor_limit = ntohl(arp_nbr_limit);
4994 mp->is_ipv6 = is_ipv6;
5001 static int api_l2_patch_add_del (vat_main_t * vam)
5003 unformat_input_t * i = vam->input;
5004 vl_api_l2_patch_add_del_t *mp;
5007 u8 rx_sw_if_index_set = 0;
5009 u8 tx_sw_if_index_set = 0;
5012 /* Parse args required to build the message */
5013 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
5014 if (unformat (i, "rx_sw_if_index %d", &rx_sw_if_index))
5015 rx_sw_if_index_set = 1;
5016 else if (unformat (i, "tx_sw_if_index %d", &tx_sw_if_index))
5017 tx_sw_if_index_set = 1;
5018 else if (unformat (i, "rx")) {
5019 if (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
5020 if (unformat (i, "%U", unformat_sw_if_index, vam,
5022 rx_sw_if_index_set = 1;
5025 } else if (unformat (i, "tx")) {
5026 if (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
5027 if (unformat (i, "%U", unformat_sw_if_index, vam,
5029 tx_sw_if_index_set = 1;
5032 } else if (unformat (i, "del"))
5038 if (rx_sw_if_index_set == 0) {
5039 errmsg ("missing rx interface name or rx_sw_if_index\n");
5043 if (tx_sw_if_index_set == 0) {
5044 errmsg ("missing tx interface name or tx_sw_if_index\n");
5048 M(L2_PATCH_ADD_DEL, l2_patch_add_del);
5050 mp->rx_sw_if_index = ntohl(rx_sw_if_index);
5051 mp->tx_sw_if_index = ntohl(tx_sw_if_index);
5052 mp->is_add = is_add;
5059 static int api_sr_tunnel_add_del (vat_main_t * vam)
5061 unformat_input_t * i = vam->input;
5062 vl_api_sr_tunnel_add_del_t *mp;
5066 ip6_address_t src_address;
5067 int src_address_set = 0;
5068 ip6_address_t dst_address;
5070 int dst_address_set = 0;
5072 u32 rx_table_id = 0;
5073 u32 tx_table_id = 0;
5074 ip6_address_t * segments = 0;
5075 ip6_address_t * this_seg;
5076 ip6_address_t * tags = 0;
5077 ip6_address_t * this_tag;
5078 ip6_address_t next_address, tag;
5080 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
5082 if (unformat (i, "del"))
5084 else if (unformat (i, "rx_fib_id %d", &rx_table_id))
5086 else if (unformat (i, "tx_fib_id %d", &tx_table_id))
5088 else if (unformat (i, "src %U", unformat_ip6_address, &src_address))
5089 src_address_set = 1;
5090 else if (unformat (i, "dst %U/%d",
5091 unformat_ip6_address, &dst_address,
5093 dst_address_set = 1;
5094 else if (unformat (i, "next %U", unformat_ip6_address,
5097 vec_add2 (segments, this_seg, 1);
5098 memcpy (this_seg->as_u8, next_address.as_u8, sizeof (*this_seg));
5100 else if (unformat (i, "tag %U", unformat_ip6_address,
5103 vec_add2 (tags, this_tag, 1);
5104 memcpy (this_tag->as_u8, tag.as_u8, sizeof (*this_tag));
5106 else if (unformat (i, "clean"))
5107 flags |= IP6_SR_HEADER_FLAG_CLEANUP;
5108 else if (unformat (i, "protected"))
5109 flags |= IP6_SR_HEADER_FLAG_PROTECTED;
5110 else if (unformat (i, "InPE %d", &pl_index))
5112 if (pl_index <= 0 || pl_index > 4)
5114 pl_index_range_error:
5115 errmsg ("pl index %d out of range\n", pl_index);
5118 flags |= IP6_SR_HEADER_FLAG_PL_ELT_INGRESS_PE << (3*(pl_index - 1));
5120 else if (unformat (i, "EgPE %d", &pl_index))
5122 if (pl_index <= 0 || pl_index > 4)
5123 goto pl_index_range_error;
5124 flags |= IP6_SR_HEADER_FLAG_PL_ELT_EGRESS_PE << (3*(pl_index - 1));
5126 else if (unformat (i, "OrgSrc %d", &pl_index))
5128 if (pl_index <= 0 || pl_index > 4)
5129 goto pl_index_range_error;
5130 flags |= IP6_SR_HEADER_FLAG_PL_ELT_ORIG_SRC_ADDR << (3*(pl_index - 1));
5136 if (!src_address_set)
5138 errmsg ("src address required\n");
5142 if (!dst_address_set)
5144 errmsg ("dst address required\n");
5150 errmsg ("at least one sr segment required\n");
5154 M2(SR_TUNNEL_ADD_DEL, sr_tunnel_add_del,
5155 vec_len(segments) * sizeof (ip6_address_t)
5156 + vec_len(tags) * sizeof (ip6_address_t));
5158 memcpy (mp->src_address, &src_address, sizeof (mp->src_address));
5159 memcpy (mp->dst_address, &dst_address, sizeof (mp->dst_address));
5160 mp->dst_mask_width = dst_mask_width;
5161 mp->flags_net_byte_order = clib_host_to_net_u16 (flags);
5162 mp->n_segments = vec_len (segments);
5163 mp->n_tags = vec_len (tags);
5164 mp->is_add = is_del == 0;
5165 memcpy (mp->segs_and_tags, segments,
5166 vec_len(segments)* sizeof (ip6_address_t));
5167 memcpy (mp->segs_and_tags + vec_len(segments)*sizeof (ip6_address_t),
5168 tags, vec_len(tags)* sizeof (ip6_address_t));
5170 mp->outer_vrf_id = ntohl (rx_table_id);
5171 mp->inner_vrf_id = ntohl (tx_table_id);
5173 vec_free (segments);
5181 #define foreach_ip4_proto_field \
5191 uword unformat_ip4_mask (unformat_input_t * input, va_list * args)
5193 u8 ** maskp = va_arg (*args, u8 **);
5195 u8 found_something = 0;
5198 #define _(a) u8 a=0;
5199 foreach_ip4_proto_field;
5205 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
5207 if (unformat (input, "version"))
5209 else if (unformat (input, "hdr_length"))
5211 else if (unformat (input, "src"))
5213 else if (unformat (input, "dst"))
5215 else if (unformat (input, "proto"))
5218 #define _(a) else if (unformat (input, #a)) a=1;
5219 foreach_ip4_proto_field
5225 #define _(a) found_something += a;
5226 foreach_ip4_proto_field;
5229 if (found_something == 0)
5232 vec_validate (mask, sizeof (*ip) - 1);
5234 ip = (ip4_header_t *) mask;
5236 #define _(a) if (a) memset (&ip->a, 0xff, sizeof (ip->a));
5237 foreach_ip4_proto_field;
5240 ip->ip_version_and_header_length = 0;
5243 ip->ip_version_and_header_length |= 0xF0;
5246 ip->ip_version_and_header_length |= 0x0F;
5252 #define foreach_ip6_proto_field \
5259 uword unformat_ip6_mask (unformat_input_t * input, va_list * args)
5261 u8 ** maskp = va_arg (*args, u8 **);
5263 u8 found_something = 0;
5265 u32 ip_version_traffic_class_and_flow_label;
5267 #define _(a) u8 a=0;
5268 foreach_ip6_proto_field;
5271 u8 traffic_class = 0;
5274 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
5276 if (unformat (input, "version"))
5278 else if (unformat (input, "traffic-class"))
5280 else if (unformat (input, "flow-label"))
5282 else if (unformat (input, "src"))
5284 else if (unformat (input, "dst"))
5286 else if (unformat (input, "proto"))
5289 #define _(a) else if (unformat (input, #a)) a=1;
5290 foreach_ip6_proto_field
5296 #define _(a) found_something += a;
5297 foreach_ip6_proto_field;
5300 if (found_something == 0)
5303 vec_validate (mask, sizeof (*ip) - 1);
5305 ip = (ip6_header_t *) mask;
5307 #define _(a) if (a) memset (&ip->a, 0xff, sizeof (ip->a));
5308 foreach_ip6_proto_field;
5311 ip_version_traffic_class_and_flow_label = 0;
5314 ip_version_traffic_class_and_flow_label |= 0xF0000000;
5317 ip_version_traffic_class_and_flow_label |= 0x0FF00000;
5320 ip_version_traffic_class_and_flow_label |= 0x000FFFFF;
5322 ip->ip_version_traffic_class_and_flow_label =
5323 clib_host_to_net_u32 (ip_version_traffic_class_and_flow_label);
5329 uword unformat_l3_mask (unformat_input_t * input, va_list * args)
5331 u8 ** maskp = va_arg (*args, u8 **);
5333 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) {
5334 if (unformat (input, "ip4 %U", unformat_ip4_mask, maskp))
5336 else if (unformat (input, "ip6 %U", unformat_ip6_mask, maskp))
5344 uword unformat_l2_mask (unformat_input_t * input, va_list * args)
5346 u8 ** maskp = va_arg (*args, u8 **);
5361 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) {
5362 if (unformat (input, "src"))
5364 else if (unformat (input, "dst"))
5366 else if (unformat (input, "proto"))
5368 else if (unformat (input, "tag1"))
5370 else if (unformat (input, "tag2"))
5372 else if (unformat (input, "ignore-tag1"))
5374 else if (unformat (input, "ignore-tag2"))
5376 else if (unformat (input, "cos1"))
5378 else if (unformat (input, "cos2"))
5380 else if (unformat (input, "dot1q"))
5382 else if (unformat (input, "dot1ad"))
5387 if ((src + dst + proto + tag1 + tag2 + dot1q + dot1ad +
5388 ignore_tag1 + ignore_tag2 + cos1 + cos2) == 0)
5391 if (tag1 || ignore_tag1 || cos1 || dot1q)
5393 if (tag2 || ignore_tag2 || cos2 || dot1ad)
5396 vec_validate (mask, len-1);
5399 memset (mask, 0xff, 6);
5402 memset (mask + 6, 0xff, 6);
5406 /* inner vlan tag */
5415 mask[21] = mask [20] = 0xff;
5436 mask[16] = mask [17] = 0xff;
5446 mask[12] = mask [13] = 0xff;
5452 uword unformat_classify_mask (unformat_input_t * input, va_list * args)
5454 u8 ** maskp = va_arg (*args, u8 **);
5455 u32 * skipp = va_arg (*args, u32 *);
5456 u32 * matchp = va_arg (*args, u32 *);
5463 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) {
5464 if (unformat (input, "hex %U", unformat_hex_string, &mask))
5466 else if (unformat (input, "l2 %U", unformat_l2_mask, &l2))
5468 else if (unformat (input, "l3 %U", unformat_l3_mask, &l3))
5474 if (mask || l2 || l3)
5478 /* "With a free Ethernet header in every package" */
5480 vec_validate (l2, 13);
5482 vec_append (mask, l3);
5486 /* Scan forward looking for the first significant mask octet */
5487 for (i = 0; i < vec_len (mask); i++)
5491 /* compute (skip, match) params */
5492 *skipp = i / sizeof(u32x4);
5493 vec_delete (mask, *skipp * sizeof(u32x4), 0);
5495 /* Pad mask to an even multiple of the vector size */
5496 while (vec_len (mask) % sizeof (u32x4))
5499 match = vec_len (mask) / sizeof (u32x4);
5501 for (i = match*sizeof(u32x4); i > 0; i-= sizeof(u32x4))
5503 u64 *tmp = (u64 *)(mask + (i-sizeof(u32x4)));
5504 if (*tmp || *(tmp+1))
5509 clib_warning ("BUG: match 0");
5511 _vec_len (mask) = match * sizeof(u32x4);
5522 #define foreach_l2_next \
5524 _(ethernet, ETHERNET_INPUT) \
5528 uword unformat_l2_next_index (unformat_input_t * input, va_list * args)
5530 u32 * miss_next_indexp = va_arg (*args, u32 *);
5535 if (unformat (input, #n)) { next_index = L2_CLASSIFY_NEXT_##N; goto out;}
5539 if (unformat (input, "%d", &tmp))
5548 *miss_next_indexp = next_index;
5552 #define foreach_ip_next \
5558 uword unformat_ip_next_index (unformat_input_t * input, va_list * args)
5560 u32 * miss_next_indexp = va_arg (*args, u32 *);
5565 if (unformat (input, #n)) { next_index = IP_LOOKUP_NEXT_##N; goto out;}
5569 if (unformat (input, "%d", &tmp))
5578 *miss_next_indexp = next_index;
5582 #define foreach_acl_next \
5585 uword unformat_acl_next_index (unformat_input_t * input, va_list * args)
5587 u32 * miss_next_indexp = va_arg (*args, u32 *);
5592 if (unformat (input, #n)) { next_index = ACL_NEXT_INDEX_##N; goto out;}
5596 if (unformat (input, "permit"))
5601 else if (unformat (input, "%d", &tmp))
5610 *miss_next_indexp = next_index;
5614 static int api_classify_add_del_table (vat_main_t * vam)
5616 unformat_input_t * i = vam->input;
5617 vl_api_classify_add_del_table_t *mp;
5623 u32 table_index = ~0;
5624 u32 next_table_index = ~0;
5625 u32 miss_next_index = ~0;
5626 u32 memory_size = 32<<20;
5630 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
5631 if (unformat (i, "del"))
5633 else if (unformat (i, "buckets %d", &nbuckets))
5635 else if (unformat (i, "memory_size %d", &memory_size))
5637 else if (unformat (i, "skip %d", &skip))
5639 else if (unformat (i, "match %d", &match))
5641 else if (unformat (i, "table %d", &table_index))
5643 else if (unformat (i, "mask %U", unformat_classify_mask,
5644 &mask, &skip, &match))
5646 else if (unformat (i, "next-table %d", &next_table_index))
5648 else if (unformat (i, "miss-next %U", unformat_ip_next_index,
5651 else if (unformat (i, "l2-miss-next %U", unformat_l2_next_index,
5654 else if (unformat (i, "acl-miss-next %U", unformat_acl_next_index,
5661 if (is_add && mask == 0) {
5662 errmsg ("Mask required\n");
5666 if (is_add && skip == ~0) {
5667 errmsg ("skip count required\n");
5671 if (is_add && match == ~0) {
5672 errmsg ("match count required\n");
5676 if (!is_add && table_index == ~0) {
5677 errmsg ("table index required for delete\n");
5681 M2 (CLASSIFY_ADD_DEL_TABLE, classify_add_del_table,
5684 mp->is_add = is_add;
5685 mp->table_index = ntohl(table_index);
5686 mp->nbuckets = ntohl(nbuckets);
5687 mp->memory_size = ntohl(memory_size);
5688 mp->skip_n_vectors = ntohl(skip);
5689 mp->match_n_vectors = ntohl(match);
5690 mp->next_table_index = ntohl(next_table_index);
5691 mp->miss_next_index = ntohl(miss_next_index);
5692 memcpy (mp->mask, mask, vec_len(mask));
5700 uword unformat_ip4_match (unformat_input_t * input, va_list * args)
5702 u8 ** matchp = va_arg (*args, u8 **);
5709 int src = 0, dst = 0;
5710 ip4_address_t src_val, dst_val;
5717 int fragment_id = 0;
5718 u32 fragment_id_val;
5724 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
5726 if (unformat (input, "version %d", &version_val))
5728 else if (unformat (input, "hdr_length %d", &hdr_length_val))
5730 else if (unformat (input, "src %U", unformat_ip4_address, &src_val))
5732 else if (unformat (input, "dst %U", unformat_ip4_address, &dst_val))
5734 else if (unformat (input, "proto %d", &proto_val))
5736 else if (unformat (input, "tos %d", &tos_val))
5738 else if (unformat (input, "length %d", &length_val))
5740 else if (unformat (input, "fragment_id %d", &fragment_id_val))
5742 else if (unformat (input, "ttl %d", &ttl_val))
5744 else if (unformat (input, "checksum %d", &checksum_val))
5750 if (version + hdr_length + src + dst + proto + tos + length + fragment_id
5751 + ttl + checksum == 0)
5755 * Aligned because we use the real comparison functions
5757 vec_validate_aligned (match, sizeof (*ip) - 1, sizeof(u32x4));
5759 ip = (ip4_header_t *) match;
5761 /* These are realistically matched in practice */
5763 ip->src_address.as_u32 = src_val.as_u32;
5766 ip->dst_address.as_u32 = dst_val.as_u32;
5769 ip->protocol = proto_val;
5772 /* These are not, but they're included for completeness */
5774 ip->ip_version_and_header_length |= (version_val & 0xF)<<4;
5777 ip->ip_version_and_header_length |= (hdr_length_val & 0xF);
5783 ip->length = length_val;
5789 ip->checksum = checksum_val;
5795 uword unformat_ip6_match (unformat_input_t * input, va_list * args)
5797 u8 ** matchp = va_arg (*args, u8 **);
5803 u32 traffic_class_val;
5806 int src = 0, dst = 0;
5807 ip6_address_t src_val, dst_val;
5810 int payload_length = 0;
5811 u32 payload_length_val;
5814 u32 ip_version_traffic_class_and_flow_label;
5816 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
5818 if (unformat (input, "version %d", &version_val))
5820 else if (unformat (input, "traffic_class %d", &traffic_class_val))
5822 else if (unformat (input, "flow_label %d", &flow_label_val))
5824 else if (unformat (input, "src %U", unformat_ip6_address, &src_val))
5826 else if (unformat (input, "dst %U", unformat_ip6_address, &dst_val))
5828 else if (unformat (input, "proto %d", &proto_val))
5830 else if (unformat (input, "payload_length %d", &payload_length_val))
5832 else if (unformat (input, "hop_limit %d", &hop_limit_val))
5838 if (version + traffic_class + flow_label + src + dst + proto +
5839 payload_length + hop_limit == 0)
5843 * Aligned because we use the real comparison functions
5845 vec_validate_aligned (match, sizeof (*ip) - 1, sizeof(u32x4));
5847 ip = (ip6_header_t *) match;
5850 memcpy (&ip->src_address, &src_val, sizeof (ip->src_address));
5853 memcpy (&ip->dst_address, &dst_val, sizeof (ip->dst_address));
5856 ip->protocol = proto_val;
5858 ip_version_traffic_class_and_flow_label = 0;
5861 ip_version_traffic_class_and_flow_label |= (version_val & 0xF) << 28;
5864 ip_version_traffic_class_and_flow_label |= (traffic_class_val & 0xFF) << 20;
5867 ip_version_traffic_class_and_flow_label |= (flow_label_val & 0xFFFFF);
5869 ip->ip_version_traffic_class_and_flow_label =
5870 clib_host_to_net_u32 (ip_version_traffic_class_and_flow_label);
5873 ip->payload_length = clib_host_to_net_u16 (payload_length_val);
5876 ip->hop_limit = hop_limit_val;
5882 uword unformat_l3_match (unformat_input_t * input, va_list * args)
5884 u8 ** matchp = va_arg (*args, u8 **);
5886 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) {
5887 if (unformat (input, "ip4 %U", unformat_ip4_match, matchp))
5889 else if (unformat (input, "ip6 %U", unformat_ip6_match, matchp))
5897 uword unformat_vlan_tag (unformat_input_t * input, va_list * args)
5899 u8 * tagp = va_arg (*args, u8 *);
5902 if (unformat(input, "%d", &tag))
5904 tagp[0] = (tag>>8) & 0x0F;
5905 tagp[1] = tag & 0xFF;
5912 uword unformat_l2_match (unformat_input_t * input, va_list * args)
5914 u8 ** matchp = va_arg (*args, u8 **);
5934 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) {
5935 if (unformat (input, "src %U", unformat_ethernet_address, &src_val))
5937 else if (unformat (input, "dst %U", unformat_ethernet_address, &dst_val))
5939 else if (unformat (input, "proto %U",
5940 unformat_ethernet_type_host_byte_order, &proto_val))
5942 else if (unformat (input, "tag1 %U", unformat_vlan_tag, tag1_val))
5944 else if (unformat (input, "tag2 %U", unformat_vlan_tag, tag2_val))
5946 else if (unformat (input, "ignore-tag1"))
5948 else if (unformat (input, "ignore-tag2"))
5950 else if (unformat (input, "cos1 %d", &cos1_val))
5952 else if (unformat (input, "cos2 %d", &cos2_val))
5957 if ((src + dst + proto + tag1 + tag2 +
5958 ignore_tag1 + ignore_tag2 + cos1 + cos2) == 0)
5961 if (tag1 || ignore_tag1 || cos1)
5963 if (tag2 || ignore_tag2 || cos2)
5966 vec_validate_aligned (match, len-1, sizeof(u32x4));
5969 memcpy (match, dst_val, 6);
5972 memcpy (match + 6, src_val, 6);
5976 /* inner vlan tag */
5977 match[19] = tag2_val[1];
5978 match[18] = tag2_val[0];
5980 match [18] |= (cos2_val & 0x7) << 5;
5983 match[21] = proto_val & 0xff;
5984 match[20] = proto_val >> 8;
5988 match [15] = tag1_val[1];
5989 match [14] = tag1_val[0];
5992 match [14] |= (cos1_val & 0x7) << 5;
5998 match [15] = tag1_val[1];
5999 match [14] = tag1_val[0];
6002 match[17] = proto_val & 0xff;
6003 match[16] = proto_val >> 8;
6006 match [14] |= (cos1_val & 0x7) << 5;
6012 match [18] |= (cos2_val & 0x7) << 5;
6014 match [14] |= (cos1_val & 0x7) << 5;
6017 match[13] = proto_val & 0xff;
6018 match[12] = proto_val >> 8;
6026 uword unformat_classify_match (unformat_input_t * input, va_list * args)
6028 u8 ** matchp = va_arg (*args, u8 **);
6029 u32 skip_n_vectors = va_arg (*args, u32);
6030 u32 match_n_vectors = va_arg (*args, u32);
6036 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) {
6037 if (unformat (input, "hex %U", unformat_hex_string, &match))
6039 else if (unformat (input, "l2 %U", unformat_l2_match, &l2))
6041 else if (unformat (input, "l3 %U", unformat_l3_match, &l3))
6047 if (match || l2 || l3)
6051 /* "Win a free Ethernet header in every packet" */
6053 vec_validate_aligned (l2, 13, sizeof(u32x4));
6055 vec_append_aligned (match, l3, sizeof(u32x4));
6059 /* Make sure the vector is big enough even if key is all 0's */
6060 vec_validate_aligned
6061 (match, ((match_n_vectors + skip_n_vectors) * sizeof(u32x4)) - 1,
6064 /* Set size, include skipped vectors*/
6065 _vec_len (match) = (match_n_vectors+skip_n_vectors) * sizeof(u32x4);
6075 static int api_classify_add_del_session (vat_main_t * vam)
6077 unformat_input_t * i = vam->input;
6078 vl_api_classify_add_del_session_t *mp;
6080 u32 table_index = ~0;
6081 u32 hit_next_index = ~0;
6082 u32 opaque_index = ~0;
6086 u32 skip_n_vectors = 0;
6087 u32 match_n_vectors = 0;
6090 * Warning: you have to supply skip_n and match_n
6091 * because the API client cant simply look at the classify
6095 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
6096 if (unformat (i, "del"))
6098 else if (unformat (i, "hit-next %U", unformat_ip_next_index,
6101 else if (unformat (i, "l2-hit-next %U", unformat_l2_next_index,
6104 else if (unformat (i, "acl-hit-next %U", unformat_acl_next_index,
6107 else if (unformat (i, "opaque-index %d", &opaque_index))
6109 else if (unformat (i, "skip_n %d", &skip_n_vectors))
6111 else if (unformat (i, "match_n %d", &match_n_vectors))
6113 else if (unformat (i, "match %U", unformat_classify_match,
6114 &match, skip_n_vectors, match_n_vectors))
6116 else if (unformat (i, "advance %d", &advance))
6118 else if (unformat (i, "table-index %d", &table_index))
6124 if (table_index == ~0) {
6125 errmsg ("Table index required\n");
6129 if (is_add && match == 0) {
6130 errmsg ("Match value required\n");
6134 M2 (CLASSIFY_ADD_DEL_SESSION, classify_add_del_session,
6137 mp->is_add = is_add;
6138 mp->table_index = ntohl(table_index);
6139 mp->hit_next_index = ntohl(hit_next_index);
6140 mp->opaque_index = ntohl(opaque_index);
6141 mp->advance = ntohl(advance);
6142 memcpy (mp->match, match, vec_len(match));
6149 static int api_classify_set_interface_ip_table (vat_main_t * vam)
6151 unformat_input_t * i = vam->input;
6152 vl_api_classify_set_interface_ip_table_t *mp;
6155 int sw_if_index_set;
6156 u32 table_index = ~0;
6159 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
6160 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
6161 sw_if_index_set = 1;
6162 else if (unformat (i, "sw_if_index %d", &sw_if_index))
6163 sw_if_index_set = 1;
6164 else if (unformat (i, "table %d", &table_index))
6167 clib_warning ("parse error '%U'", format_unformat_error, i);
6172 if (sw_if_index_set == 0) {
6173 errmsg ("missing interface name or sw_if_index\n");
6178 M(CLASSIFY_SET_INTERFACE_IP_TABLE, classify_set_interface_ip_table);
6180 mp->sw_if_index = ntohl(sw_if_index);
6181 mp->table_index = ntohl(table_index);
6182 mp->is_ipv6 = is_ipv6;
6189 static int api_classify_set_interface_l2_tables (vat_main_t * vam)
6191 unformat_input_t * i = vam->input;
6192 vl_api_classify_set_interface_l2_tables_t *mp;
6195 int sw_if_index_set;
6196 u32 ip4_table_index = ~0;
6197 u32 ip6_table_index = ~0;
6198 u32 other_table_index = ~0;
6200 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
6201 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
6202 sw_if_index_set = 1;
6203 else if (unformat (i, "sw_if_index %d", &sw_if_index))
6204 sw_if_index_set = 1;
6205 else if (unformat (i, "ip4-table %d", &ip4_table_index))
6207 else if (unformat (i, "ip6-table %d", &ip6_table_index))
6209 else if (unformat (i, "other-table %d", &other_table_index))
6212 clib_warning ("parse error '%U'", format_unformat_error, i);
6217 if (sw_if_index_set == 0) {
6218 errmsg ("missing interface name or sw_if_index\n");
6223 M(CLASSIFY_SET_INTERFACE_L2_TABLES, classify_set_interface_l2_tables);
6225 mp->sw_if_index = ntohl(sw_if_index);
6226 mp->ip4_table_index = ntohl(ip4_table_index);
6227 mp->ip6_table_index = ntohl(ip6_table_index);
6228 mp->other_table_index = ntohl(other_table_index);
6236 static int api_get_node_index (vat_main_t * vam)
6238 unformat_input_t * i = vam->input;
6239 vl_api_get_node_index_t * mp;
6243 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
6244 if (unformat (i, "node %s", &name))
6250 errmsg ("node name required\n");
6253 if (vec_len (name) >= ARRAY_LEN(mp->node_name)) {
6254 errmsg ("node name too long, max %d\n", ARRAY_LEN(mp->node_name));
6258 M(GET_NODE_INDEX, get_node_index);
6259 memcpy (mp->node_name, name, vec_len(name));
6267 static int api_add_node_next (vat_main_t * vam)
6269 unformat_input_t * i = vam->input;
6270 vl_api_add_node_next_t * mp;
6275 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
6276 if (unformat (i, "node %s", &name))
6278 else if (unformat (i, "next %s", &next))
6284 errmsg ("node name required\n");
6287 if (vec_len (name) >= ARRAY_LEN(mp->node_name)) {
6288 errmsg ("node name too long, max %d\n", ARRAY_LEN(mp->node_name));
6292 errmsg ("next node required\n");
6295 if (vec_len (next) >= ARRAY_LEN(mp->next_name)) {
6296 errmsg ("next name too long, max %d\n", ARRAY_LEN(mp->next_name));
6300 M(ADD_NODE_NEXT, add_node_next);
6301 memcpy (mp->node_name, name, vec_len(name));
6302 memcpy (mp->next_name, next, vec_len(next));
6311 static int api_l2tpv3_create_tunnel (vat_main_t * vam)
6313 unformat_input_t * i = vam->input;
6314 ip6_address_t client_address, our_address;
6315 int client_address_set = 0;
6316 int our_address_set = 0;
6317 u32 local_session_id = 0;
6318 u32 remote_session_id = 0;
6319 u64 local_cookie = 0;
6320 u64 remote_cookie = 0;
6321 u8 l2_sublayer_present = 0;
6322 vl_api_l2tpv3_create_tunnel_t * mp;
6325 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
6326 if (unformat (i, "client_address %U", unformat_ip6_address,
6328 client_address_set = 1;
6329 else if (unformat (i, "our_address %U", unformat_ip6_address,
6331 our_address_set = 1;
6332 else if (unformat (i, "local_session_id %d", &local_session_id))
6334 else if (unformat (i, "remote_session_id %d", &remote_session_id))
6336 else if (unformat (i, "local_cookie %lld", &local_cookie))
6338 else if (unformat (i, "remote_cookie %lld", &remote_cookie))
6340 else if (unformat (i, "l2-sublayer-present"))
6341 l2_sublayer_present = 1;
6346 if (client_address_set == 0) {
6347 errmsg ("client_address required\n");
6351 if (our_address_set == 0) {
6352 errmsg ("our_address required\n");
6356 M(L2TPV3_CREATE_TUNNEL, l2tpv3_create_tunnel);
6358 memcpy (mp->client_address, client_address.as_u8,
6359 sizeof (mp->client_address));
6361 memcpy (mp->our_address, our_address.as_u8,
6362 sizeof (mp->our_address));
6364 mp->local_session_id = ntohl (local_session_id);
6365 mp->remote_session_id = ntohl (remote_session_id);
6366 mp->local_cookie = clib_host_to_net_u64 (local_cookie);
6367 mp->remote_cookie = clib_host_to_net_u64 (remote_cookie);
6368 mp->l2_sublayer_present = l2_sublayer_present;
6376 static int api_l2tpv3_set_tunnel_cookies (vat_main_t * vam)
6378 unformat_input_t * i = vam->input;
6380 u8 sw_if_index_set = 0;
6381 u64 new_local_cookie = 0;
6382 u64 new_remote_cookie = 0;
6383 vl_api_l2tpv3_set_tunnel_cookies_t *mp;
6386 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
6387 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
6388 sw_if_index_set = 1;
6389 else if (unformat (i, "sw_if_index %d", &sw_if_index))
6390 sw_if_index_set = 1;
6391 else if (unformat (i, "new_local_cookie %lld", &new_local_cookie))
6393 else if (unformat (i, "new_remote_cookie %lld", &new_remote_cookie))
6399 if (sw_if_index_set == 0) {
6400 errmsg ("missing interface name or sw_if_index\n");
6404 M(L2TPV3_SET_TUNNEL_COOKIES, l2tpv3_set_tunnel_cookies);
6406 mp->sw_if_index = ntohl(sw_if_index);
6407 mp->new_local_cookie = clib_host_to_net_u64 (new_local_cookie);
6408 mp->new_remote_cookie = clib_host_to_net_u64 (new_remote_cookie);
6415 static int api_l2tpv3_interface_enable_disable (vat_main_t * vam)
6417 unformat_input_t * i = vam->input;
6418 vl_api_l2tpv3_interface_enable_disable_t *mp;
6421 u8 sw_if_index_set = 0;
6422 u8 enable_disable = 1;
6424 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
6425 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
6426 sw_if_index_set = 1;
6427 else if (unformat (i, "sw_if_index %d", &sw_if_index))
6428 sw_if_index_set = 1;
6429 else if (unformat (i, "enable"))
6431 else if (unformat (i, "disable"))
6437 if (sw_if_index_set == 0) {
6438 errmsg ("missing interface name or sw_if_index\n");
6442 M(L2TPV3_INTERFACE_ENABLE_DISABLE, l2tpv3_interface_enable_disable);
6444 mp->sw_if_index = ntohl(sw_if_index);
6445 mp->enable_disable = enable_disable;
6452 static int api_l2tpv3_set_lookup_key (vat_main_t * vam)
6454 unformat_input_t * i = vam->input;
6455 vl_api_l2tpv3_set_lookup_key_t * mp;
6459 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
6460 if (unformat (i, "lookup_v6_src"))
6461 key = L2T_LOOKUP_SRC_ADDRESS;
6462 else if (unformat (i, "lookup_v6_dst"))
6463 key = L2T_LOOKUP_DST_ADDRESS;
6464 else if (unformat (i, "lookup_session_id"))
6465 key = L2T_LOOKUP_SESSION_ID;
6471 errmsg ("l2tp session lookup key unset\n");
6475 M(L2TPV3_SET_LOOKUP_KEY, l2tpv3_set_lookup_key);
6484 static void vl_api_sw_if_l2tpv3_tunnel_details_t_handler
6485 (vl_api_sw_if_l2tpv3_tunnel_details_t * mp)
6487 vat_main_t * vam = &vat_main;
6489 fformat(vam->ofp, "* %U (our) %U (client) (sw_if_index %d)\n",
6490 format_ip6_address, mp->our_address,
6491 format_ip6_address, mp->client_address,
6492 clib_net_to_host_u32(mp->sw_if_index));
6494 fformat (vam->ofp, " local cookies %016llx %016llx remote cookie %016llx\n",
6495 clib_net_to_host_u64 (mp->local_cookie[0]),
6496 clib_net_to_host_u64 (mp->local_cookie[1]),
6497 clib_net_to_host_u64 (mp->remote_cookie));
6499 fformat (vam->ofp, " local session-id %d remote session-id %d\n",
6500 clib_net_to_host_u32 (mp->local_session_id),
6501 clib_net_to_host_u32 (mp->remote_session_id));
6503 fformat (vam->ofp, " l2 specific sublayer %s\n\n",
6504 mp->l2_sublayer_present ? "preset" : "absent");
6508 static void vl_api_sw_if_l2tpv3_tunnel_details_t_handler_json
6509 (vl_api_sw_if_l2tpv3_tunnel_details_t * mp)
6511 vat_main_t * vam = &vat_main;
6512 vat_json_node_t *node = NULL;
6513 struct in6_addr addr;
6515 if (VAT_JSON_ARRAY != vam->json_tree.type) {
6516 ASSERT(VAT_JSON_NONE == vam->json_tree.type);
6517 vat_json_init_array(&vam->json_tree);
6519 node = vat_json_array_add(&vam->json_tree);
6521 vat_json_init_object(node);
6523 memcpy(&addr, mp->our_address, sizeof(addr));
6524 vat_json_object_add_ip6(node, "our_address", addr);
6525 memcpy(&addr, mp->client_address, sizeof(addr));
6526 vat_json_object_add_ip6(node, "client_address", addr);
6528 vat_json_node_t * lc = vat_json_object_add(node, "local_cookie");
6529 vat_json_init_array(lc);
6530 vat_json_array_add_uint(lc, clib_net_to_host_u64(mp->local_cookie[0]));
6531 vat_json_array_add_uint(lc, clib_net_to_host_u64(mp->local_cookie[1]));
6532 vat_json_object_add_uint(node, "remote_cookie", clib_net_to_host_u64(mp->remote_cookie));
6534 printf("local id: %u", clib_net_to_host_u32(mp->local_session_id));
6535 vat_json_object_add_uint(node, "local_session_id", clib_net_to_host_u32(mp->local_session_id));
6536 vat_json_object_add_uint(node, "remote_session_id", clib_net_to_host_u32(mp->remote_session_id));
6537 vat_json_object_add_string_copy(node, "l2_sublayer", mp->l2_sublayer_present ?
6538 (u8*)"present" : (u8*)"absent");
6541 static int api_sw_if_l2tpv3_tunnel_dump (vat_main_t * vam)
6543 vl_api_sw_if_l2tpv3_tunnel_dump_t *mp;
6546 /* Get list of l2tpv3-tunnel interfaces */
6547 M(SW_IF_L2TPV3_TUNNEL_DUMP, sw_if_l2tpv3_tunnel_dump);
6550 /* Use a control ping for synchronization */
6552 vl_api_control_ping_t * mp;
6553 M(CONTROL_PING, control_ping);
6560 static void vl_api_sw_interface_tap_details_t_handler
6561 (vl_api_sw_interface_tap_details_t * mp)
6563 vat_main_t * vam = &vat_main;
6565 fformat(vam->ofp, "%-16s %d\n",
6567 clib_net_to_host_u32(mp->sw_if_index));
6570 static void vl_api_sw_interface_tap_details_t_handler_json
6571 (vl_api_sw_interface_tap_details_t * mp)
6573 vat_main_t * vam = &vat_main;
6574 vat_json_node_t *node = NULL;
6576 if (VAT_JSON_ARRAY != vam->json_tree.type) {
6577 ASSERT(VAT_JSON_NONE == vam->json_tree.type);
6578 vat_json_init_array(&vam->json_tree);
6580 node = vat_json_array_add(&vam->json_tree);
6582 vat_json_init_object(node);
6583 vat_json_object_add_uint(node, "sw_if_index", ntohl(mp->sw_if_index));
6584 vat_json_object_add_string_copy(node, "dev_name", mp->dev_name);
6587 static int api_sw_interface_tap_dump (vat_main_t * vam)
6589 vl_api_sw_interface_tap_dump_t *mp;
6592 fformat(vam->ofp, "\n%-16s %s\n", "dev_name", "sw_if_index");
6593 /* Get list of tap interfaces */
6594 M(SW_INTERFACE_TAP_DUMP, sw_interface_tap_dump);
6597 /* Use a control ping for synchronization */
6599 vl_api_control_ping_t * mp;
6600 M(CONTROL_PING, control_ping);
6606 static uword unformat_vxlan_decap_next
6607 (unformat_input_t * input, va_list * args)
6609 u32 * result = va_arg (*args, u32 *);
6612 if (unformat (input, "drop"))
6613 *result = VXLAN_INPUT_NEXT_DROP;
6614 else if (unformat (input, "ip4"))
6615 *result = VXLAN_INPUT_NEXT_IP4_INPUT;
6616 else if (unformat (input, "ip6"))
6617 *result = VXLAN_INPUT_NEXT_IP6_INPUT;
6618 else if (unformat (input, "l2"))
6619 *result = VXLAN_INPUT_NEXT_L2_INPUT;
6620 else if (unformat (input, "%d", &tmp))
6627 static int api_vxlan_add_del_tunnel (vat_main_t * vam)
6629 unformat_input_t * line_input = vam->input;
6630 vl_api_vxlan_add_del_tunnel_t *mp;
6632 ip4_address_t src, dst;
6636 u32 encap_vrf_id = 0;
6637 u32 decap_next_index = ~0;
6640 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) {
6641 if (unformat (line_input, "del"))
6643 else if (unformat (line_input, "src %U",
6644 unformat_ip4_address, &src))
6646 else if (unformat (line_input, "dst %U",
6647 unformat_ip4_address, &dst))
6649 else if (unformat (line_input, "encap-vrf-id %d", &encap_vrf_id))
6651 else if (unformat (line_input, "decap-next %U",
6652 unformat_vxlan_decap_next, &decap_next_index))
6654 else if (unformat (line_input, "vni %d", &vni))
6657 errmsg ("parse error '%U'\n", format_unformat_error, line_input);
6663 errmsg ("tunnel src address not specified\n");
6667 errmsg ("tunnel dst address not specified\n");
6671 if ((vni == 0) || (vni>>24)) {
6672 errmsg ("vni not specified or out of range\n");
6676 M (VXLAN_ADD_DEL_TUNNEL, vxlan_add_del_tunnel);
6678 mp->src_address = src.as_u32;
6679 mp->dst_address = dst.as_u32;
6680 mp->encap_vrf_id = ntohl(encap_vrf_id);
6681 mp->decap_next_index = ntohl(decap_next_index);
6682 mp->vni = ntohl(vni);
6683 mp->is_add = is_add;
6690 static void vl_api_vxlan_tunnel_details_t_handler
6691 (vl_api_vxlan_tunnel_details_t * mp)
6693 vat_main_t * vam = &vat_main;
6695 fformat(vam->ofp, "%11d%13U%13U%14d%18d%13d\n",
6696 ntohl(mp->sw_if_index),
6697 format_ip4_address, &mp->src_address,
6698 format_ip4_address, &mp->dst_address,
6699 ntohl(mp->encap_vrf_id),
6700 ntohl(mp->decap_next_index),
6704 static void vl_api_vxlan_tunnel_details_t_handler_json
6705 (vl_api_vxlan_tunnel_details_t * mp)
6707 vat_main_t * vam = &vat_main;
6708 vat_json_node_t *node = NULL;
6711 if (VAT_JSON_ARRAY != vam->json_tree.type) {
6712 ASSERT(VAT_JSON_NONE == vam->json_tree.type);
6713 vat_json_init_array(&vam->json_tree);
6715 node = vat_json_array_add(&vam->json_tree);
6717 vat_json_init_object(node);
6718 vat_json_object_add_uint(node, "sw_if_index", ntohl(mp->sw_if_index));
6719 memcpy(&ip4, &mp->src_address, sizeof(ip4));
6720 vat_json_object_add_ip4(node, "src_address", ip4);
6721 memcpy(&ip4, &mp->dst_address, sizeof(ip4));
6722 vat_json_object_add_ip4(node, "dst_address", ip4);
6723 vat_json_object_add_uint(node, "encap_vrf_id", ntohl(mp->encap_vrf_id));
6724 vat_json_object_add_uint(node, "decap_next_index", ntohl(mp->decap_next_index));
6725 vat_json_object_add_uint(node, "vni", ntohl(mp->vni));
6728 static int api_vxlan_tunnel_dump (vat_main_t * vam)
6730 unformat_input_t * i = vam->input;
6731 vl_api_vxlan_tunnel_dump_t *mp;
6734 u8 sw_if_index_set = 0;
6736 /* Parse args required to build the message */
6737 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
6738 if (unformat (i, "sw_if_index %d", &sw_if_index))
6739 sw_if_index_set = 1;
6744 if (sw_if_index_set == 0) {
6748 if (!vam->json_output) {
6749 fformat(vam->ofp, "%11s%13s%13s%14s%18s%13s\n",
6750 "sw_if_index", "src_address", "dst_address",
6751 "encap_vrf_id", "decap_next_index", "vni");
6754 /* Get list of l2tpv3-tunnel interfaces */
6755 M(VXLAN_TUNNEL_DUMP, vxlan_tunnel_dump);
6757 mp->sw_if_index = htonl(sw_if_index);
6761 /* Use a control ping for synchronization */
6763 vl_api_control_ping_t * mp;
6764 M(CONTROL_PING, control_ping);
6770 static int api_l2_fib_clear_table (vat_main_t * vam)
6772 // unformat_input_t * i = vam->input;
6773 vl_api_l2_fib_clear_table_t *mp;
6776 M(L2_FIB_CLEAR_TABLE, l2_fib_clear_table);
6783 static int api_l2_interface_efp_filter (vat_main_t * vam)
6785 unformat_input_t * i = vam->input;
6786 vl_api_l2_interface_efp_filter_t *mp;
6790 u8 sw_if_index_set = 0;
6792 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
6793 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
6794 sw_if_index_set = 1;
6795 else if (unformat (i, "sw_if_index %d", &sw_if_index))
6796 sw_if_index_set = 1;
6797 else if (unformat (i, "enable"))
6799 else if (unformat (i, "disable"))
6802 clib_warning ("parse error '%U'", format_unformat_error, i);
6807 if (sw_if_index_set == 0) {
6808 errmsg ("missing sw_if_index\n");
6812 M(L2_INTERFACE_EFP_FILTER, l2_interface_efp_filter);
6814 mp->sw_if_index = ntohl(sw_if_index);
6815 mp->enable_disable = enable;
6822 #define foreach_vtr_op \
6823 _("disable", L2_VTR_DISABLED) \
6824 _("push-1", L2_VTR_PUSH_1) \
6825 _("push-2", L2_VTR_PUSH_2) \
6826 _("pop-1", L2_VTR_POP_1) \
6827 _("pop-2", L2_VTR_POP_2) \
6828 _("translate-1-1", L2_VTR_TRANSLATE_1_1) \
6829 _("translate-1-2", L2_VTR_TRANSLATE_1_2) \
6830 _("translate-2-1", L2_VTR_TRANSLATE_2_1) \
6831 _("translate-2-2", L2_VTR_TRANSLATE_2_2)
6833 static int api_l2_interface_vlan_tag_rewrite (vat_main_t * vam)
6835 unformat_input_t * i = vam->input;
6836 vl_api_l2_interface_vlan_tag_rewrite_t *mp;
6839 u8 sw_if_index_set = 0;
6846 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
6847 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
6848 sw_if_index_set = 1;
6849 else if (unformat (i, "sw_if_index %d", &sw_if_index))
6850 sw_if_index_set = 1;
6851 else if (unformat (i, "vtr_op %d", &vtr_op))
6853 #define _(n,v) else if (unformat(i, n)) {vtr_op = v; vtr_op_set = 1;}
6857 else if (unformat (i, "push_dot1q %d", &push_dot1q))
6859 else if (unformat (i, "tag1 %d", &tag1))
6861 else if (unformat (i, "tag2 %d", &tag2))
6864 clib_warning ("parse error '%U'", format_unformat_error, i);
6869 if ((sw_if_index_set == 0)||(vtr_op_set == 0)) {
6870 errmsg ("missing vtr operation or sw_if_index\n");
6874 M(L2_INTERFACE_VLAN_TAG_REWRITE, l2_interface_vlan_tag_rewrite)
6876 mp->sw_if_index = ntohl(sw_if_index);
6877 mp->vtr_op = ntohl(vtr_op);
6878 mp->push_dot1q = ntohl(push_dot1q);
6879 mp->tag1 = ntohl(tag1);
6880 mp->tag2 = ntohl(tag2);
6887 static int api_create_vhost_user_if (vat_main_t * vam)
6889 unformat_input_t * i = vam->input;
6890 vl_api_create_vhost_user_if_t *mp;
6894 u8 file_name_set = 0;
6895 u32 custom_dev_instance = ~0;
6897 u8 use_custom_mac = 0;
6899 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
6900 if (unformat (i, "socket %s", &file_name)) {
6903 else if (unformat (i, "renumber %"PRIu32, &custom_dev_instance))
6905 else if (unformat (i, "mac %U", unformat_ethernet_address, hwaddr))
6907 else if (unformat (i, "server"))
6913 if (file_name_set == 0) {
6914 errmsg ("missing socket file name\n");
6918 if (vec_len (file_name) > 255) {
6919 errmsg ("socket file name too long\n");
6922 vec_add1 (file_name, 0);
6924 M(CREATE_VHOST_USER_IF, create_vhost_user_if);
6926 mp->is_server = is_server;
6927 memcpy(mp->sock_filename, file_name, vec_len(file_name));
6928 vec_free(file_name);
6929 if (custom_dev_instance != ~0) {
6931 mp->custom_dev_instance = ntohl(custom_dev_instance);
6933 mp->use_custom_mac = use_custom_mac;
6934 memcpy(mp->mac_address, hwaddr, 6);
6941 static int api_modify_vhost_user_if (vat_main_t * vam)
6943 unformat_input_t * i = vam->input;
6944 vl_api_modify_vhost_user_if_t *mp;
6948 u8 file_name_set = 0;
6949 u32 custom_dev_instance = ~0;
6950 u8 sw_if_index_set = 0;
6951 u32 sw_if_index = (u32)~0;
6953 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
6954 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
6955 sw_if_index_set = 1;
6956 else if (unformat (i, "sw_if_index %d", &sw_if_index))
6957 sw_if_index_set = 1;
6958 else if (unformat (i, "socket %s", &file_name)) {
6961 else if (unformat (i, "renumber %"PRIu32, &custom_dev_instance))
6963 else if (unformat (i, "server"))
6969 if (sw_if_index_set == 0) {
6970 errmsg ("missing sw_if_index or interface name\n");
6974 if (file_name_set == 0) {
6975 errmsg ("missing socket file name\n");
6979 if (vec_len (file_name) > 255) {
6980 errmsg ("socket file name too long\n");
6983 vec_add1 (file_name, 0);
6985 M(MODIFY_VHOST_USER_IF, modify_vhost_user_if);
6987 mp->sw_if_index = ntohl(sw_if_index);
6988 mp->is_server = is_server;
6989 memcpy(mp->sock_filename, file_name, vec_len(file_name));
6990 vec_free(file_name);
6991 if (custom_dev_instance != ~0) {
6993 mp->custom_dev_instance = ntohl(custom_dev_instance);
7001 static int api_delete_vhost_user_if (vat_main_t * vam)
7003 unformat_input_t * i = vam->input;
7004 vl_api_delete_vhost_user_if_t *mp;
7006 u32 sw_if_index = ~0;
7007 u8 sw_if_index_set = 0;
7009 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
7010 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
7011 sw_if_index_set = 1;
7012 else if (unformat (i, "sw_if_index %d", &sw_if_index))
7013 sw_if_index_set = 1;
7018 if (sw_if_index_set == 0) {
7019 errmsg ("missing sw_if_index or interface name\n");
7024 M(DELETE_VHOST_USER_IF, delete_vhost_user_if);
7026 mp->sw_if_index = ntohl(sw_if_index);
7033 static void vl_api_sw_interface_vhost_user_details_t_handler
7034 (vl_api_sw_interface_vhost_user_details_t * mp)
7036 vat_main_t * vam = &vat_main;
7038 fformat(vam->ofp, "%-25s %3" PRIu32 " %6" PRIu32 " %8x %6d %7d %s\n",
7039 (char *)mp->interface_name,
7040 ntohl(mp->sw_if_index), ntohl(mp->virtio_net_hdr_sz),
7041 clib_net_to_host_u64(mp->features), mp->is_server,
7042 ntohl(mp->num_regions), (char *)mp->sock_filename);
7043 fformat(vam->ofp, " Status: '%s'\n", strerror(ntohl(mp->sock_errno)));
7046 static void vl_api_sw_interface_vhost_user_details_t_handler_json
7047 (vl_api_sw_interface_vhost_user_details_t * mp)
7049 vat_main_t * vam = &vat_main;
7050 vat_json_node_t *node = NULL;
7052 if (VAT_JSON_ARRAY != vam->json_tree.type) {
7053 ASSERT(VAT_JSON_NONE == vam->json_tree.type);
7054 vat_json_init_array(&vam->json_tree);
7056 node = vat_json_array_add(&vam->json_tree);
7058 vat_json_init_object(node);
7059 vat_json_object_add_uint(node, "sw_if_index", ntohl(mp->sw_if_index));
7060 vat_json_object_add_string_copy(node, "interface_name", mp->interface_name);
7061 vat_json_object_add_uint(node, "virtio_net_hdr_sz", ntohl(mp->virtio_net_hdr_sz));
7062 vat_json_object_add_uint(node, "features", clib_net_to_host_u64(mp->features));
7063 vat_json_object_add_uint(node, "is_server", mp->is_server);
7064 vat_json_object_add_string_copy(node, "sock_filename", mp->sock_filename);
7065 vat_json_object_add_uint(node, "num_regions", ntohl(mp->num_regions));
7066 vat_json_object_add_uint(node, "sock_errno", ntohl(mp->sock_errno));
7069 static int api_sw_interface_vhost_user_dump (vat_main_t * vam)
7071 vl_api_sw_interface_vhost_user_dump_t *mp;
7073 fformat(vam->ofp, "Interface name idx hdr_sz features server regions filename\n");
7075 /* Get list of vhost-user interfaces */
7076 M(SW_INTERFACE_VHOST_USER_DUMP, sw_interface_vhost_user_dump);
7079 /* Use a control ping for synchronization */
7081 vl_api_control_ping_t * mp;
7082 M(CONTROL_PING, control_ping);
7088 static int api_show_version (vat_main_t * vam)
7090 vl_api_show_version_t *mp;
7093 M(SHOW_VERSION, show_version);
7100 static uword unformat_nsh_gre_decap_next
7101 (unformat_input_t * input, va_list * args)
7103 u32 * result = va_arg (*args, u32 *);
7106 if (unformat (input, "drop"))
7107 *result = NSH_INPUT_NEXT_DROP;
7108 else if (unformat (input, "ip4"))
7109 *result = NSH_INPUT_NEXT_IP4_INPUT;
7110 else if (unformat (input, "ip6"))
7111 *result = NSH_INPUT_NEXT_IP6_INPUT;
7112 else if (unformat (input, "ethernet"))
7113 *result = NSH_INPUT_NEXT_ETHERNET_INPUT;
7114 else if (unformat (input, "%d", &tmp))
7121 static int api_nsh_gre_add_del_tunnel (vat_main_t * vam)
7123 unformat_input_t * line_input = vam->input;
7124 vl_api_nsh_gre_add_del_tunnel_t *mp;
7126 ip4_address_t src, dst;
7130 u32 encap_vrf_id = 0;
7131 u32 decap_vrf_id = 0;
7134 u8 next_protocol = 1; /* ip4 */
7145 u32 decap_next_index = NSH_INPUT_NEXT_IP4_INPUT;
7149 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) {
7150 if (unformat (line_input, "del"))
7152 else if (unformat (line_input, "src %U",
7153 unformat_ip4_address, &src))
7155 else if (unformat (line_input, "dst %U",
7156 unformat_ip4_address, &dst))
7158 else if (unformat (line_input, "encap-vrf-id %d", &encap_vrf_id))
7160 else if (unformat (line_input, "decap-vrf-id %d", &decap_vrf_id))
7162 else if (unformat (line_input, "decap-next %U",
7163 unformat_nsh_gre_decap_next, &decap_next_index))
7165 else if (unformat (line_input, "version %d", &tmp))
7166 ver_o_c |= (tmp & 3) << 6;
7167 else if (unformat (line_input, "o-bit %d", &tmp))
7168 ver_o_c |= (tmp & 1) << 5;
7169 else if (unformat (line_input, "c-bit %d", &tmp))
7170 ver_o_c |= (tmp & 1) << 4;
7171 else if (unformat (line_input, "md-type %d", &tmp))
7173 else if (unformat(line_input, "next-ip4"))
7175 else if (unformat(line_input, "next-ip6"))
7177 else if (unformat(line_input, "next-ethernet"))
7179 else if (unformat (line_input, "c1 %d", &c1))
7181 else if (unformat (line_input, "c2 %d", &c2))
7183 else if (unformat (line_input, "c3 %d", &c3))
7185 else if (unformat (line_input, "c4 %d", &c4))
7187 else if (unformat (line_input, "spi %d", &spi))
7189 else if (unformat (line_input, "si %d", &si))
7191 else if (unformat (line_input, "tlv %x"))
7192 vec_add1 (tlvs, tmp);
7194 errmsg ("parse error '%U'\n", format_unformat_error, line_input);
7200 errmsg ("tunnel src address not specified\n");
7204 errmsg ("tunnel dst address not specified\n");
7209 errmsg ("spi not specified\n");
7214 errmsg ("si not specified\n");
7218 M2 (NSH_GRE_ADD_DEL_TUNNEL, nsh_gre_add_del_tunnel,
7219 sizeof(u32) * vec_len (tlvs));
7221 spi_si = (spi<<8) | si;
7223 mp->src = src.as_u32;
7224 mp->dst = dst.as_u32;
7225 mp->encap_vrf_id = ntohl(encap_vrf_id);
7226 mp->decap_vrf_id = ntohl(decap_vrf_id);
7227 mp->decap_next_index = ntohl(decap_next_index);
7228 mp->tlv_len_in_words = vec_len (tlvs);
7229 mp->is_add = is_add;
7230 mp->ver_o_c = ver_o_c;
7231 mp->length = 6 + vec_len(tlvs);
7232 mp->md_type = md_type;
7233 mp->next_protocol = next_protocol;
7234 mp->spi_si = ntohl(spi_si);
7240 for (i = 0; i < vec_len(tlvs); i++)
7241 mp->tlvs[i] = ntohl(tlvs[i]);
7250 static uword unformat_nsh_vxlan_gpe_decap_next
7251 (unformat_input_t * input, va_list * args)
7253 u32 * result = va_arg (*args, u32 *);
7256 if (unformat (input, "drop"))
7257 *result = NSH_VXLAN_GPE_INPUT_NEXT_DROP;
7258 else if (unformat (input, "ip4"))
7259 *result = NSH_VXLAN_GPE_INPUT_NEXT_IP4_INPUT;
7260 else if (unformat (input, "ip6"))
7261 *result = NSH_VXLAN_GPE_INPUT_NEXT_IP6_INPUT;
7262 else if (unformat (input, "ethernet"))
7263 *result = NSH_VXLAN_GPE_INPUT_NEXT_ETHERNET_INPUT;
7264 else if (unformat (input, "nsh-vxlan-gpe"))
7265 *result = NSH_VXLAN_GPE_INPUT_NEXT_ETHERNET_INPUT;
7266 else if (unformat (input, "%d", &tmp))
7273 static int api_nsh_vxlan_gpe_add_del_tunnel (vat_main_t * vam)
7275 unformat_input_t * line_input = vam->input;
7276 vl_api_nsh_vxlan_gpe_add_del_tunnel_t *mp;
7278 ip4_address_t src, dst;
7282 u32 encap_vrf_id = 0;
7283 u32 decap_vrf_id = 0;
7286 u8 next_protocol = 1; /* ip4 */
7297 u32 decap_next_index = NSH_INPUT_NEXT_IP4_INPUT;
7303 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) {
7304 if (unformat (line_input, "del"))
7306 else if (unformat (line_input, "src %U",
7307 unformat_ip4_address, &src))
7309 else if (unformat (line_input, "dst %U",
7310 unformat_ip4_address, &dst))
7312 else if (unformat (line_input, "encap-vrf-id %d", &encap_vrf_id))
7314 else if (unformat (line_input, "decap-vrf-id %d", &decap_vrf_id))
7316 else if (unformat (line_input, "decap-next %U",
7317 unformat_nsh_vxlan_gpe_decap_next,
7320 else if (unformat (line_input, "vni %d", &vni))
7322 else if (unformat (line_input, "version %d", &tmp))
7323 ver_o_c |= (tmp & 3) << 6;
7324 else if (unformat (line_input, "o-bit %d", &tmp))
7325 ver_o_c |= (tmp & 1) << 5;
7326 else if (unformat (line_input, "c-bit %d", &tmp))
7327 ver_o_c |= (tmp & 1) << 4;
7328 else if (unformat (line_input, "md-type %d", &tmp))
7330 else if (unformat(line_input, "next-ip4"))
7332 else if (unformat(line_input, "next-ip6"))
7334 else if (unformat(line_input, "next-ethernet"))
7336 else if (unformat (line_input, "c1 %d", &c1))
7338 else if (unformat (line_input, "c2 %d", &c2))
7340 else if (unformat (line_input, "c3 %d", &c3))
7342 else if (unformat (line_input, "c4 %d", &c4))
7344 else if (unformat (line_input, "spi %d", &spi))
7346 else if (unformat (line_input, "si %d", &si))
7348 else if (unformat (line_input, "tlv %x"))
7349 vec_add1 (tlvs, tmp);
7351 errmsg ("parse error '%U'\n", format_unformat_error, line_input);
7357 errmsg ("tunnel src address not specified\n");
7361 errmsg ("tunnel dst address not specified\n");
7366 errmsg ("spi not specified\n");
7371 errmsg ("si not specified\n");
7375 errmsg ("vni not specified\n");
7379 M2 (NSH_VXLAN_GPE_ADD_DEL_TUNNEL, nsh_vxlan_gpe_add_del_tunnel,
7380 sizeof(u32) * vec_len (tlvs));
7382 spi_si = (spi<<8) | si;
7384 mp->src = src.as_u32;
7385 mp->dst = dst.as_u32;
7386 mp->encap_vrf_id = ntohl(encap_vrf_id);
7387 mp->decap_vrf_id = ntohl(decap_vrf_id);
7388 mp->decap_next_index = ntohl(decap_next_index);
7389 mp->tlv_len_in_words = vec_len (tlvs);
7390 mp->vni = ntohl(vni);
7391 mp->is_add = is_add;
7392 mp->ver_o_c = ver_o_c;
7393 mp->length = 6 + vec_len(tlvs);
7394 mp->md_type = md_type;
7395 mp->next_protocol = next_protocol;
7396 mp->spi_si = ntohl(spi_si);
7402 for (i = 0; i < vec_len(tlvs); i++)
7403 mp->tlvs[i] = ntohl(tlvs[i]);
7412 static uword unformat_lisp_gpe_decap_next (unformat_input_t * input,
7415 u32 * result = va_arg (*args, u32 *);
7418 if (unformat (input, "drop"))
7419 *result = LISP_GPE_INPUT_NEXT_DROP;
7420 else if (unformat (input, "ip4"))
7421 *result = LISP_GPE_INPUT_NEXT_IP4_INPUT;
7422 else if (unformat (input, "ip6"))
7423 *result = LISP_GPE_INPUT_NEXT_IP6_INPUT;
7424 else if (unformat (input, "ethernet"))
7425 *result = LISP_GPE_INPUT_NEXT_IP6_INPUT;
7426 else if (unformat (input, "lisp-gpe"))
7427 *result = LISP_GPE_INPUT_NEXT_LISP_GPE_ENCAP;
7428 else if (unformat (input, "%d", &tmp))
7436 api_lisp_gpe_add_del_tunnel (vat_main_t * vam)
7438 unformat_input_t * line_input = vam->input;
7439 vl_api_lisp_gpe_add_del_tunnel_t *mp;
7441 ip4_address_t src, dst;
7445 u32 encap_vrf_id = 0;
7446 u32 decap_vrf_id = 0;
7447 u8 next_protocol = LISP_GPE_NEXT_PROTOCOL_IP4;
7448 u32 decap_next_index = LISP_GPE_INPUT_NEXT_IP4_INPUT;
7449 u8 flags = LISP_GPE_FLAGS_P;
7456 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) {
7457 if (unformat (line_input, "del"))
7459 else if (unformat (line_input, "src %U",
7460 unformat_ip4_address, &src))
7462 else if (unformat (line_input, "dst %U",
7463 unformat_ip4_address, &dst))
7465 else if (unformat (line_input, "encap-vrf-id %d", &encap_vrf_id))
7467 else if (unformat (line_input, "decap-vrf-id %d", &decap_vrf_id))
7469 else if (unformat (line_input, "decap-next %U",
7470 unformat_lisp_gpe_decap_next,
7473 else if (unformat(line_input, "next-ip4"))
7475 else if (unformat(line_input, "next-ip6"))
7477 else if (unformat(line_input, "next-ethernet"))
7479 else if (unformat(line_input, "next-nsh"))
7481 /* Allow the user to specify anything they want in the LISP hdr */
7482 else if (unformat (line_input, "ver_res %x", &tmp))
7484 else if (unformat (line_input, "res %x", &tmp))
7486 else if (unformat (line_input, "flags %x", &tmp))
7488 else if (unformat (line_input, "n-bit"))
7489 flags |= LISP_GPE_FLAGS_N;
7490 else if (unformat (line_input, "l-bit"))
7491 flags |= LISP_GPE_FLAGS_L;
7492 else if (unformat (line_input, "e-bit"))
7493 flags |= LISP_GPE_FLAGS_E;
7494 else if (unformat (line_input, "v-bit"))
7495 flags |= LISP_GPE_FLAGS_V;
7496 else if (unformat (line_input, "i-bit"))
7497 flags |= LISP_GPE_FLAGS_V;
7498 else if (unformat (line_input, "not-p-bit"))
7499 flags &= !LISP_GPE_FLAGS_P;
7500 else if (unformat (line_input, "p-bit"))
7501 flags |= LISP_GPE_FLAGS_P;
7502 else if (unformat (line_input, "o-bit"))
7503 flags |= LISP_GPE_FLAGS_O;
7504 else if (unformat (line_input, "iidx %x", &iid))
7506 else if (unformat (line_input, "iid %d", &iid))
7509 errmsg ("parse error '%U'\n", format_unformat_error, line_input);
7515 errmsg ("tunnel src address not specified\n");
7519 errmsg ("tunnel dst address not specified\n");
7523 errmsg ("iid not specified\n");
7527 M(LISP_GPE_ADD_DEL_TUNNEL, lisp_gpe_add_del_tunnel);
7529 mp->src = src.as_u32;
7530 mp->dst = dst.as_u32;
7531 mp->encap_vrf_id = ntohl(encap_vrf_id);
7532 mp->decap_vrf_id = ntohl(decap_vrf_id);
7533 mp->decap_next_index = ntohl(decap_next_index);
7534 mp->is_add = is_add;
7536 mp->ver_res = ver_res;
7538 mp->next_protocol = next_protocol;
7539 mp->iid = ntohl(iid);
7548 u8 * format_l2_fib_mac_address (u8 * s, va_list * args)
7550 u8 * a = va_arg (*args, u8 *);
7552 return format (s, "%02x:%02x:%02x:%02x:%02x:%02x",
7553 a[2], a[3], a[4], a[5], a[6], a[7]);
7556 static void vl_api_l2_fib_table_entry_t_handler
7557 (vl_api_l2_fib_table_entry_t * mp)
7559 vat_main_t * vam = &vat_main;
7561 fformat(vam->ofp, "%3" PRIu32 " %U %3" PRIu32
7563 ntohl(mp->bd_id), format_l2_fib_mac_address, &mp->mac,
7564 ntohl(mp->sw_if_index), mp->static_mac, mp->filter_mac,
7568 static void vl_api_l2_fib_table_entry_t_handler_json
7569 (vl_api_l2_fib_table_entry_t * mp)
7571 vat_main_t * vam = &vat_main;
7572 vat_json_node_t *node = NULL;
7574 if (VAT_JSON_ARRAY != vam->json_tree.type) {
7575 ASSERT(VAT_JSON_NONE == vam->json_tree.type);
7576 vat_json_init_array(&vam->json_tree);
7578 node = vat_json_array_add(&vam->json_tree);
7580 vat_json_init_object(node);
7581 vat_json_object_add_uint(node, "bd_id", ntohl(mp->bd_id));
7582 vat_json_object_add_uint(node, "mac", clib_net_to_host_u64(mp->mac));
7583 vat_json_object_add_uint(node, "sw_if_index", ntohl(mp->sw_if_index));
7584 vat_json_object_add_uint(node, "static_mac", mp->static_mac);
7585 vat_json_object_add_uint(node, "filter_mac", mp->filter_mac);
7586 vat_json_object_add_uint(node, "bvi_mac", mp->bvi_mac);
7589 static int api_l2_fib_table_dump (vat_main_t * vam)
7591 unformat_input_t * i = vam->input;
7592 vl_api_l2_fib_table_dump_t *mp;
7597 /* Parse args required to build the message */
7598 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
7599 if (unformat (i, "bd_id %d", &bd_id))
7605 if (bd_id_set == 0) {
7606 errmsg ("missing bridge domain\n");
7610 fformat(vam->ofp, "BD-ID Mac Address sw-ndx Static Filter BVI\n");
7612 /* Get list of l2 fib entries */
7613 M(L2_FIB_TABLE_DUMP, l2_fib_table_dump);
7615 mp->bd_id = ntohl(bd_id);
7618 /* Use a control ping for synchronization */
7620 vl_api_control_ping_t * mp;
7621 M(CONTROL_PING, control_ping);
7629 api_interface_name_renumber (vat_main_t * vam)
7631 unformat_input_t * line_input = vam->input;
7632 vl_api_interface_name_renumber_t *mp;
7633 u32 sw_if_index = ~0;
7635 u32 new_show_dev_instance = ~0;
7637 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) {
7638 if (unformat (line_input, "%U", unformat_sw_if_index, vam,
7641 else if (unformat (line_input, "sw_if_index %d", &sw_if_index))
7643 else if (unformat (line_input, "new_show_dev_instance %d",
7644 &new_show_dev_instance))
7650 if (sw_if_index == ~0) {
7651 errmsg ("missing interface name or sw_if_index\n");
7655 if (new_show_dev_instance == ~0) {
7656 errmsg ("missing new_show_dev_instance\n");
7660 M(INTERFACE_NAME_RENUMBER, interface_name_renumber);
7662 mp->sw_if_index = ntohl (sw_if_index);
7663 mp->new_show_dev_instance = ntohl (new_show_dev_instance);
7669 api_want_ip4_arp_events (vat_main_t * vam)
7671 unformat_input_t * line_input = vam->input;
7672 vl_api_want_ip4_arp_events_t * mp;
7674 ip4_address_t address;
7675 int address_set = 0;
7676 u32 enable_disable = 1;
7678 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) {
7679 if (unformat (line_input, "address %U",
7680 unformat_ip4_address, &address))
7682 else if (unformat (line_input, "del"))
7688 if (address_set == 0) {
7689 errmsg ("missing addresses\n");
7693 M(WANT_IP4_ARP_EVENTS, want_ip4_arp_events);
7694 mp->enable_disable = enable_disable;
7696 mp->address = address.as_u32;
7701 static int api_input_acl_set_interface (vat_main_t * vam)
7703 unformat_input_t * i = vam->input;
7704 vl_api_input_acl_set_interface_t *mp;
7707 int sw_if_index_set;
7708 u32 ip4_table_index = ~0;
7709 u32 ip6_table_index = ~0;
7710 u32 l2_table_index = ~0;
7713 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
7714 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
7715 sw_if_index_set = 1;
7716 else if (unformat (i, "sw_if_index %d", &sw_if_index))
7717 sw_if_index_set = 1;
7718 else if (unformat (i, "del"))
7720 else if (unformat (i, "ip4-table %d", &ip4_table_index))
7722 else if (unformat (i, "ip6-table %d", &ip6_table_index))
7724 else if (unformat (i, "l2-table %d", &l2_table_index))
7727 clib_warning ("parse error '%U'", format_unformat_error, i);
7732 if (sw_if_index_set == 0) {
7733 errmsg ("missing interface name or sw_if_index\n");
7737 M(INPUT_ACL_SET_INTERFACE, input_acl_set_interface);
7739 mp->sw_if_index = ntohl(sw_if_index);
7740 mp->ip4_table_index = ntohl(ip4_table_index);
7741 mp->ip6_table_index = ntohl(ip6_table_index);
7742 mp->l2_table_index = ntohl(l2_table_index);
7743 mp->is_add = is_add;
7751 api_ip_address_dump (vat_main_t * vam)
7753 unformat_input_t * i = vam->input;
7754 vl_api_ip_address_dump_t * mp;
7755 u32 sw_if_index = ~0;
7756 u8 sw_if_index_set = 0;
7761 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
7762 if (unformat (i, "sw_if_index %d", &sw_if_index))
7763 sw_if_index_set = 1;
7764 else if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
7765 sw_if_index_set = 1;
7766 else if (unformat (i, "ipv4"))
7768 else if (unformat (i, "ipv6"))
7774 if (ipv4_set && ipv6_set) {
7775 errmsg ("ipv4 and ipv6 flags cannot be both set\n");
7779 if ((!ipv4_set) && (!ipv6_set)) {
7780 errmsg ("no ipv4 nor ipv6 flag set\n");
7784 if (sw_if_index_set == 0) {
7785 errmsg ("missing interface name or sw_if_index\n");
7789 vam->current_sw_if_index = sw_if_index;
7790 vam->is_ipv6 = ipv6_set;
7792 M(IP_ADDRESS_DUMP, ip_address_dump);
7793 mp->sw_if_index = ntohl(sw_if_index);
7794 mp->is_ipv6 = ipv6_set;
7797 /* Use a control ping for synchronization */
7799 vl_api_control_ping_t * mp;
7800 M(CONTROL_PING, control_ping);
7807 api_ip_dump (vat_main_t * vam)
7809 vl_api_ip_dump_t * mp;
7810 unformat_input_t * in = vam->input;
7817 while (unformat_check_input (in) != UNFORMAT_END_OF_INPUT) {
7818 if (unformat (in, "ipv4"))
7820 else if (unformat (in, "ipv6"))
7826 if (ipv4_set && ipv6_set) {
7827 errmsg ("ipv4 and ipv6 flags cannot be both set\n");
7831 if ((!ipv4_set) && (!ipv6_set)) {
7832 errmsg ("no ipv4 nor ipv6 flag set\n");
7837 vam->is_ipv6 = is_ipv6;
7840 for (i = 0; i < vec_len(vam->ip_details_by_sw_if_index[is_ipv6]); i++) {
7841 vec_free(vam->ip_details_by_sw_if_index[is_ipv6][i].addr);
7843 vec_free(vam->ip_details_by_sw_if_index[is_ipv6]);
7845 M(IP_DUMP, ip_dump);
7846 mp->is_ipv6 = ipv6_set;
7849 /* Use a control ping for synchronization */
7851 vl_api_control_ping_t * mp;
7852 M(CONTROL_PING, control_ping);
7859 api_ipsec_spd_add_del (vat_main_t * vam)
7862 unformat_input_t * i = vam->input;
7863 vl_api_ipsec_spd_add_del_t *mp;
7868 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
7869 if (unformat (i, "spd_id %d", &spd_id))
7871 else if (unformat (i, "del"))
7874 clib_warning ("parse error '%U'", format_unformat_error, i);
7879 errmsg ("spd_id must be set\n");
7883 M(IPSEC_SPD_ADD_DEL, ipsec_spd_add_del);
7885 mp->spd_id = ntohl(spd_id);
7886 mp->is_add = is_add;
7892 clib_warning ("unsupported (no dpdk)");
7898 api_ipsec_interface_add_del_spd (vat_main_t * vam)
7901 unformat_input_t * i = vam->input;
7902 vl_api_ipsec_interface_add_del_spd_t *mp;
7905 u8 sw_if_index_set = 0;
7906 u32 spd_id = (u32) ~0;
7909 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
7910 if (unformat (i, "del"))
7912 else if (unformat (i, "spd_id %d", &spd_id))
7914 else if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
7915 sw_if_index_set = 1;
7916 else if (unformat (i, "sw_if_index %d", &sw_if_index))
7917 sw_if_index_set = 1;
7919 clib_warning ("parse error '%U'", format_unformat_error, i);
7925 if (spd_id == (u32) ~0) {
7926 errmsg ("spd_id must be set\n");
7930 if (sw_if_index_set == 0) {
7931 errmsg ("missing interface name or sw_if_index\n");
7935 M(IPSEC_INTERFACE_ADD_DEL_SPD, ipsec_interface_add_del_spd);
7937 mp->spd_id = ntohl(spd_id);
7938 mp->sw_if_index = ntohl (sw_if_index);
7939 mp->is_add = is_add;
7945 clib_warning ("unsupported (no dpdk)");
7951 api_ipsec_spd_add_del_entry (vat_main_t * vam)
7954 unformat_input_t * i = vam->input;
7955 vl_api_ipsec_spd_add_del_entry_t *mp;
7957 u8 is_add = 1, is_outbound = 0, is_ipv6 = 0, is_ip_any = 1;
7958 u32 spd_id, sa_id, protocol = 0, policy = 0;
7960 u32 rport_start = 0, rport_stop = (u32) ~0;
7961 u32 lport_start = 0, lport_stop = (u32) ~0;
7962 ip4_address_t laddr4_start, laddr4_stop, raddr4_start, raddr4_stop;
7963 ip6_address_t laddr6_start, laddr6_stop, raddr6_start, raddr6_stop;
7965 laddr4_start.as_u32 = raddr4_start.as_u32 = 0;
7966 laddr4_stop.as_u32 = raddr4_stop.as_u32 = (u32) ~0;
7967 laddr6_start.as_u64[0] = raddr6_start.as_u64[0] = 0;
7968 laddr6_start.as_u64[1] = raddr6_start.as_u64[1] = 0;
7969 laddr6_stop.as_u64[0] = raddr6_stop.as_u64[0] = (u64) ~0;
7970 laddr6_stop.as_u64[1] = raddr6_stop.as_u64[1] = (u64) ~0;
7972 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
7973 if (unformat (i, "del"))
7975 if (unformat (i, "outbound"))
7977 if (unformat (i, "inbound"))
7979 else if (unformat (i, "spd_id %d", &spd_id))
7981 else if (unformat (i, "sa_id %d", &sa_id))
7983 else if (unformat (i, "priority %d", &priority))
7985 else if (unformat (i, "protocol %d", &protocol))
7987 else if (unformat (i, "lport_start %d", &lport_start))
7989 else if (unformat (i, "lport_stop %d", &lport_stop))
7991 else if (unformat (i, "rport_start %d", &rport_start))
7993 else if (unformat (i, "rport_stop %d", &rport_stop))
7995 else if (unformat (i, "laddr_start %U", unformat_ip4_address, &laddr4_start))
8000 else if (unformat (i, "laddr_stop %U", unformat_ip4_address, &laddr4_stop))
8005 else if (unformat (i, "raddr_start %U", unformat_ip4_address, &raddr4_start))
8010 else if (unformat (i, "raddr_stop %U", unformat_ip4_address, &raddr4_stop))
8015 else if (unformat (i, "laddr_start %U", unformat_ip6_address, &laddr6_start))
8020 else if (unformat (i, "laddr_stop %U", unformat_ip6_address, &laddr6_stop))
8025 else if (unformat (i, "raddr_start %U", unformat_ip6_address, &raddr6_start))
8030 else if (unformat (i, "raddr_stop %U", unformat_ip6_address, &raddr6_stop))
8035 else if (unformat (i, "action %U", unformat_ipsec_policy_action, &policy))
8037 if (policy == IPSEC_POLICY_ACTION_RESOLVE) {
8038 clib_warning ("unsupported action: 'resolve'");
8043 clib_warning ("parse error '%U'", format_unformat_error, i);
8049 M(IPSEC_SPD_ADD_DEL_ENTRY, ipsec_spd_add_del_entry);
8051 mp->spd_id = ntohl(spd_id);
8052 mp->priority = ntohl(priority);
8053 mp->is_outbound = is_outbound;
8055 mp->is_ipv6 = is_ipv6;
8056 if (is_ipv6 || is_ip_any) {
8057 memcpy (mp->remote_address_start, &raddr6_start, sizeof(ip6_address_t));
8058 memcpy (mp->remote_address_stop, &raddr6_stop, sizeof(ip6_address_t));
8059 memcpy (mp->local_address_start, &laddr6_start, sizeof(ip6_address_t));
8060 memcpy (mp->local_address_stop, &laddr6_stop, sizeof(ip6_address_t));
8062 memcpy (mp->remote_address_start, &raddr4_start, sizeof(ip4_address_t));
8063 memcpy (mp->remote_address_stop, &raddr4_stop, sizeof(ip4_address_t));
8064 memcpy (mp->local_address_start, &laddr4_start, sizeof(ip4_address_t));
8065 memcpy (mp->local_address_stop, &laddr4_stop, sizeof(ip4_address_t));
8067 mp->protocol = (u8) protocol;
8068 mp->local_port_start = ntohs((u16) lport_start);
8069 mp->local_port_stop = ntohs((u16) lport_stop);
8070 mp->remote_port_start = ntohs((u16) rport_start);
8071 mp->remote_port_stop = ntohs((u16) rport_stop);
8072 mp->policy = (u8) policy;
8073 mp->sa_id = ntohl(sa_id);
8074 mp->is_add = is_add;
8075 mp->is_ip_any = is_ip_any;
8080 clib_warning ("unsupported (no dpdk)");
8086 api_ipsec_sad_add_del_entry (vat_main_t * vam)
8089 unformat_input_t * i = vam->input;
8090 vl_api_ipsec_sad_add_del_entry_t *mp;
8096 u8 protocol = IPSEC_PROTOCOL_AH;
8097 u8 is_tunnel = 0, is_tunnel_ipv6 = 0;
8098 u32 crypto_alg = 0, integ_alg = 0;
8099 ip4_address_t tun_src4;
8100 ip4_address_t tun_dst4;
8101 ip6_address_t tun_src6;
8102 ip6_address_t tun_dst6;
8104 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
8105 if (unformat (i, "del"))
8107 else if (unformat (i, "sad_id %d", &sad_id))
8109 else if (unformat (i, "spi %d", &spi))
8111 else if (unformat (i, "esp"))
8112 protocol = IPSEC_PROTOCOL_ESP;
8113 else if (unformat (i, "tunnel_src %U", unformat_ip4_address, &tun_src4)) {
8117 else if (unformat (i, "tunnel_dst %U", unformat_ip4_address, &tun_dst4)) {
8121 else if (unformat (i, "tunnel_src %U", unformat_ip6_address, &tun_src6)) {
8125 else if (unformat (i, "tunnel_dst %U", unformat_ip6_address, &tun_dst6)) {
8129 else if (unformat (i, "crypto_alg %U", unformat_ipsec_crypto_alg, &crypto_alg)) {
8130 if (crypto_alg < IPSEC_CRYPTO_ALG_AES_CBC_128 ||
8131 crypto_alg > IPSEC_INTEG_ALG_SHA_512_256) {
8132 clib_warning ("unsupported crypto-alg: '%U'",
8133 format_ipsec_crypto_alg, crypto_alg);
8137 else if (unformat (i, "crypto_key %U", unformat_hex_string, &ck))
8139 else if (unformat (i, "integ_alg %U", unformat_ipsec_integ_alg, &integ_alg)) {
8140 if (integ_alg < IPSEC_INTEG_ALG_SHA1_96 ||
8141 integ_alg > IPSEC_INTEG_ALG_SHA_512_256) {
8142 clib_warning ("unsupported integ-alg: '%U'",
8143 format_ipsec_integ_alg, integ_alg);
8147 else if (unformat (i, "integ_key %U", unformat_hex_string, &ik))
8150 clib_warning ("parse error '%U'", format_unformat_error, i);
8156 M(IPSEC_SAD_ADD_DEL_ENTRY, ipsec_sad_add_del_entry);
8158 mp->sad_id = ntohl(sad_id);
8159 mp->is_add = is_add;
8160 mp->protocol = protocol;
8161 mp->spi = ntohl(spi);
8162 mp->is_tunnel = is_tunnel;
8163 mp->is_tunnel_ipv6 = is_tunnel_ipv6;
8164 mp->crypto_algorithm = crypto_alg;
8165 mp->integrity_algorithm = integ_alg;
8166 mp->crypto_key_length = vec_len(ck);
8167 mp->integrity_key_length = vec_len(ik);
8169 if (mp->crypto_key_length > sizeof(mp->crypto_key))
8170 mp->crypto_key_length = sizeof(mp->crypto_key);
8172 if (mp->integrity_key_length > sizeof(mp->integrity_key))
8173 mp->integrity_key_length = sizeof(mp->integrity_key);
8175 memcpy (mp->crypto_key, ck, mp->crypto_key_length);
8176 memcpy (mp->integrity_key, ik, mp->integrity_key_length);
8179 if (is_tunnel_ipv6) {
8180 memcpy (mp->tunnel_src_address, &tun_src6, sizeof(ip6_address_t));
8181 memcpy (mp->tunnel_dst_address, &tun_dst6, sizeof(ip6_address_t));
8183 memcpy (mp->tunnel_src_address, &tun_src4, sizeof(ip4_address_t));
8184 memcpy (mp->tunnel_dst_address, &tun_dst4, sizeof(ip4_address_t));
8192 clib_warning ("unsupported (no dpdk)");
8198 api_ipsec_sa_set_key (vat_main_t * vam)
8201 unformat_input_t * i = vam->input;
8202 vl_api_ipsec_sa_set_key_t *mp;
8207 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
8208 if (unformat (i, "sa_id %d", &sa_id))
8210 else if (unformat (i, "crypto_key %U", unformat_hex_string, &ck))
8212 else if (unformat (i, "integ_key %U", unformat_hex_string, &ik))
8215 clib_warning ("parse error '%U'", format_unformat_error, i);
8220 M(IPSEC_SA_SET_KEY, ipsec_set_sa_key);
8222 mp->sa_id = ntohl(sa_id);
8223 mp->crypto_key_length = vec_len(ck);
8224 mp->integrity_key_length = vec_len(ik);
8226 if (mp->crypto_key_length > sizeof(mp->crypto_key))
8227 mp->crypto_key_length = sizeof(mp->crypto_key);
8229 if (mp->integrity_key_length > sizeof(mp->integrity_key))
8230 mp->integrity_key_length = sizeof(mp->integrity_key);
8232 memcpy (mp->crypto_key, ck, mp->crypto_key_length);
8233 memcpy (mp->integrity_key, ik, mp->integrity_key_length);
8239 clib_warning ("unsupported (no dpdk)");
8247 static int api_map_add_domain (vat_main_t * vam)
8249 unformat_input_t *i = vam->input;
8250 vl_api_map_add_domain_t *mp;
8253 ip4_address_t ip4_prefix;
8254 ip6_address_t ip6_prefix;
8255 ip6_address_t ip6_src;
8257 u32 ip6_prefix_len, ip4_prefix_len, ea_bits_len, psid_offset,
8259 u8 is_translation = 0;
8261 u8 ip6_src_len = 128;
8263 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
8264 if (unformat (i, "ip4-pfx %U/%d", unformat_ip4_address,
8265 &ip4_prefix, &ip4_prefix_len))
8267 else if (unformat (i, "ip6-pfx %U/%d", unformat_ip6_address,
8268 &ip6_prefix, &ip6_prefix_len))
8270 else if (unformat (i, "ip6-src %U/%d", unformat_ip6_address, &ip6_src, &ip6_src_len))
8272 else if (unformat (i, "ip6-src %U", unformat_ip6_address, &ip6_src))
8274 else if (unformat (i, "ea-bits-len %d", &ea_bits_len))
8276 else if (unformat (i, "psid-offset %d", &psid_offset))
8278 else if (unformat (i, "psid-len %d", &psid_length))
8280 else if (unformat (i, "mtu %d", &mtu))
8282 else if (unformat (i, "map-t"))
8285 clib_warning ("parse error '%U'", format_unformat_error, i);
8290 if (num_m_args != 6) {
8291 errmsg("mandatory argument(s) missing\n");
8295 /* Construct the API message */
8296 M(MAP_ADD_DOMAIN, map_add_domain);
8298 memcpy(mp->ip4_prefix, &ip4_prefix, sizeof(ip4_prefix));
8299 mp->ip4_prefix_len = ip4_prefix_len;
8301 memcpy(mp->ip6_prefix, &ip6_prefix, sizeof(ip6_prefix));
8302 mp->ip6_prefix_len = ip6_prefix_len;
8304 memcpy(mp->ip6_src, &ip6_src, sizeof(ip6_src));
8305 mp->ip6_src_prefix_len = ip6_src_len;
8307 mp->ea_bits_len = ea_bits_len;
8308 mp->psid_offset = psid_offset;
8309 mp->psid_length = psid_length;
8310 mp->is_translation = is_translation;
8311 mp->mtu = htons(mtu);
8316 /* Wait for a reply, return good/bad news */
8320 static int api_map_del_domain (vat_main_t * vam)
8322 unformat_input_t *i = vam->input;
8323 vl_api_map_del_domain_t *mp;
8329 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
8330 if (unformat (i, "index %d", &index))
8333 clib_warning ("parse error '%U'", format_unformat_error, i);
8338 if (num_m_args != 1) {
8339 errmsg("mandatory argument(s) missing\n");
8343 /* Construct the API message */
8344 M(MAP_DEL_DOMAIN, map_del_domain);
8346 mp->index = ntohl(index);
8351 /* Wait for a reply, return good/bad news */
8355 static int api_map_add_del_rule (vat_main_t * vam)
8357 unformat_input_t *i = vam->input;
8358 vl_api_map_add_del_rule_t *mp;
8361 ip6_address_t ip6_dst;
8362 u32 num_m_args = 0, index, psid;
8364 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
8365 if (unformat (i, "index %d", &index))
8367 else if (unformat (i, "psid %d", &psid))
8369 else if (unformat (i, "dst %U", unformat_ip6_address, &ip6_dst))
8371 else if (unformat (i, "del")) {
8374 clib_warning ("parse error '%U'", format_unformat_error, i);
8379 /* Construct the API message */
8380 M(MAP_ADD_DEL_RULE, map_add_del_rule);
8382 mp->index = ntohl(index);
8383 mp->is_add = is_add;
8384 memcpy(mp->ip6_dst, &ip6_dst, sizeof(ip6_dst));
8385 mp->psid = ntohs(psid);
8390 /* Wait for a reply, return good/bad news */
8394 static int api_map_domain_dump (vat_main_t * vam)
8396 vl_api_map_domain_dump_t *mp;
8399 /* Construct the API message */
8400 M(MAP_DOMAIN_DUMP, map_domain_dump);
8405 /* Use a control ping for synchronization */
8407 vl_api_control_ping_t * mp;
8408 M(CONTROL_PING, control_ping);
8414 static int api_map_rule_dump (vat_main_t * vam)
8416 unformat_input_t *i = vam->input;
8417 vl_api_map_rule_dump_t *mp;
8419 u32 domain_index = ~0;
8421 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
8422 if (unformat (i, "index %u", &domain_index))
8428 if (domain_index == ~0) {
8429 clib_warning("parse error: domain index expected");
8433 /* Construct the API message */
8434 M(MAP_RULE_DUMP, map_rule_dump);
8436 mp->domain_index = htonl(domain_index);
8441 /* Use a control ping for synchronization */
8443 vl_api_control_ping_t * mp;
8444 M(CONTROL_PING, control_ping);
8450 static void vl_api_map_add_domain_reply_t_handler
8451 (vl_api_map_add_domain_reply_t * mp)
8453 vat_main_t * vam = &vat_main;
8454 i32 retval = ntohl(mp->retval);
8456 if (vam->async_mode) {
8457 vam->async_errors += (retval < 0);
8459 vam->retval = retval;
8460 vam->result_ready = 1;
8464 static void vl_api_map_add_domain_reply_t_handler_json
8465 (vl_api_map_add_domain_reply_t * mp)
8467 vat_main_t * vam = &vat_main;
8468 vat_json_node_t node;
8470 vat_json_init_object(&node);
8471 vat_json_object_add_int(&node, "retval", ntohl(mp->retval));
8472 vat_json_object_add_uint(&node, "index", ntohl(mp->index));
8474 vat_json_print(vam->ofp, &node);
8475 vat_json_free(&node);
8477 vam->retval = ntohl(mp->retval);
8478 vam->result_ready = 1;
8482 api_get_first_msg_id (vat_main_t * vam)
8484 vl_api_get_first_msg_id_t * mp;
8486 unformat_input_t * i = vam->input;
8490 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
8491 if (unformat (i, "client %s", &name))
8497 if (name_set == 0) {
8498 errmsg ("missing client name\n");
8503 if (vec_len (name) > 63) {
8504 errmsg ("client name too long\n");
8508 M(GET_FIRST_MSG_ID, get_first_msg_id);
8509 memcpy (mp->name, name, vec_len(name));
8515 static int api_cop_interface_enable_disable (vat_main_t * vam)
8517 unformat_input_t * line_input = vam->input;
8518 vl_api_cop_interface_enable_disable_t * mp;
8520 u32 sw_if_index = ~0;
8521 u8 enable_disable = 1;
8523 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) {
8524 if (unformat (line_input, "disable"))
8526 if (unformat (line_input, "enable"))
8528 else if (unformat (line_input, "%U", unformat_sw_if_index,
8531 else if (unformat (line_input, "sw_if_index %d", &sw_if_index))
8537 if (sw_if_index == ~0) {
8538 errmsg ("missing interface name or sw_if_index\n");
8542 /* Construct the API message */
8543 M(COP_INTERFACE_ENABLE_DISABLE, cop_interface_enable_disable);
8544 mp->sw_if_index = ntohl(sw_if_index);
8545 mp->enable_disable = enable_disable;
8549 /* Wait for the reply */
8553 static int api_cop_whitelist_enable_disable (vat_main_t * vam)
8555 unformat_input_t * line_input = vam->input;
8556 vl_api_cop_whitelist_enable_disable_t * mp;
8558 u32 sw_if_index = ~0;
8559 u8 ip4=0, ip6=0, default_cop=0;
8562 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) {
8563 if (unformat (line_input, "ip4"))
8565 else if (unformat (line_input, "ip6"))
8567 else if (unformat (line_input, "default"))
8569 else if (unformat (line_input, "%U", unformat_sw_if_index,
8572 else if (unformat (line_input, "sw_if_index %d", &sw_if_index))
8574 else if (unformat (line_input, "fib-id %d", &fib_id))
8580 if (sw_if_index == ~0) {
8581 errmsg ("missing interface name or sw_if_index\n");
8585 /* Construct the API message */
8586 M(COP_WHITELIST_ENABLE_DISABLE, cop_whitelist_enable_disable);
8587 mp->sw_if_index = ntohl(sw_if_index);
8588 mp->fib_id = ntohl(fib_id);
8591 mp->default_cop = default_cop;
8595 /* Wait for the reply */
8599 static int api_get_node_graph (vat_main_t * vam)
8601 vl_api_get_node_graph_t * mp;
8604 M(GET_NODE_GRAPH, get_node_graph);
8608 /* Wait for the reply */
8612 static int q_or_quit (vat_main_t * vam)
8614 longjmp (vam->jump_buf, 1);
8615 return 0; /* not so much */
8617 static int q (vat_main_t * vam) {return q_or_quit (vam);}
8618 static int quit (vat_main_t * vam) {return q_or_quit (vam);}
8620 static int comment (vat_main_t * vam)
8625 static int cmd_cmp (void * a1, void * a2)
8630 return strcmp ((char *)(c1[0]), (char *)(c2[0]));
8633 static int help (vat_main_t * vam)
8638 unformat_input_t * i = vam->input;
8641 if (unformat (i, "%s", &name)) {
8646 hs = hash_get_mem (vam->help_by_name, name);
8648 fformat (vam->ofp, "usage: %s %s\n", name, hs[0]);
8650 fformat (vam->ofp, "No such msg / command '%s'\n", name);
8655 fformat(vam->ofp, "Help is available for the following:\n");
8657 hash_foreach_pair (p, vam->function_by_name,
8659 vec_add1 (cmds, (u8 *)(p->key));
8662 vec_sort_with_function (cmds, cmd_cmp);
8664 for (j = 0; j < vec_len(cmds); j++)
8665 fformat (vam->ofp, "%s\n", cmds[j]);
8671 static int set (vat_main_t * vam)
8673 u8 * name = 0, * value = 0;
8674 unformat_input_t * i = vam->input;
8676 if (unformat (i, "%s", &name)) {
8677 /* The input buffer is a vector, not a string. */
8678 value = vec_dup (i->buffer);
8679 vec_delete (value, i->index, 0);
8680 /* Almost certainly has a trailing newline */
8681 if (value[vec_len(value)-1] == '\n')
8682 value[vec_len(value)-1] = 0;
8683 /* Make sure it's a proper string, one way or the other */
8684 vec_add1 (value, 0);
8685 (void) clib_macro_set_value (&vam->macro_main,
8686 (char *)name, (char *)value);
8689 errmsg ("usage: set <name> <value>\n");
8696 static int unset (vat_main_t * vam)
8700 if (unformat (vam->input, "%s", &name))
8701 if (clib_macro_unset (&vam->macro_main, (char *)name) == 1)
8702 errmsg ("unset: %s wasn't set\n", name);
8713 static int macro_sort_cmp (void * a1, void * a2)
8715 macro_sort_t * s1 = a1;
8716 macro_sort_t * s2 = a2;
8718 return strcmp ((char *)(s1->name), (char *)(s2->name));
8721 static int dump_macro_table (vat_main_t * vam)
8723 macro_sort_t * sort_me = 0, * sm;
8727 hash_foreach_pair (p, vam->macro_main.the_value_table_hash,
8729 vec_add2 (sort_me, sm, 1);
8730 sm->name = (u8 *)(p->key);
8731 sm->value = (u8 *) (p->value[0]);
8734 vec_sort_with_function (sort_me, macro_sort_cmp);
8736 if (vec_len(sort_me))
8737 fformat (vam->ofp, "%-15s%s\n", "Name", "Value");
8739 fformat (vam->ofp, "The macro table is empty...\n");
8741 for (i = 0; i < vec_len (sort_me); i++)
8742 fformat (vam->ofp, "%-15s%s\n", sort_me[i].name,
8747 static int dump_node_table (vat_main_t * vam)
8750 vlib_node_t * node, * next_node;
8752 if (vec_len (vam->graph_nodes) == 0) {
8753 fformat (vam->ofp, "Node table empty, issue get_node_graph...\n");
8757 for (i = 0; i < vec_len (vam->graph_nodes); i++) {
8758 node = vam->graph_nodes[i];
8759 fformat (vam->ofp, "[%d] %s\n", i, node->name);
8760 for (j = 0; j < vec_len (node->next_nodes); j++) {
8761 if (node->next_nodes[j] != ~0) {
8762 next_node = vam->graph_nodes[node->next_nodes[j]];
8763 fformat (vam->ofp, " [%d] %s\n", j, next_node->name);
8770 static int search_node_table (vat_main_t * vam)
8772 unformat_input_t * line_input = vam->input;
8775 vlib_node_t * node, * next_node;
8778 if (vam->graph_node_index_by_name == 0) {
8779 fformat (vam->ofp, "Node table empty, issue get_node_graph...\n");
8783 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) {
8784 if (unformat (line_input, "%s", &node_to_find)) {
8785 vec_add1 (node_to_find, 0);
8786 p = hash_get_mem (vam->graph_node_index_by_name, node_to_find);
8788 fformat (vam->ofp, "%s not found...\n", node_to_find);
8791 node = vam->graph_nodes[p[0]];
8792 fformat (vam->ofp, "[%d] %s\n", p[0], node->name);
8793 for (j = 0; j < vec_len (node->next_nodes); j++) {
8794 if (node->next_nodes[j] != ~0) {
8795 next_node = vam->graph_nodes[node->next_nodes[j]];
8796 fformat (vam->ofp, " [%d] %s\n", j, next_node->name);
8802 clib_warning ("parse error '%U'", format_unformat_error,
8808 vec_free(node_to_find);
8816 static int script (vat_main_t * vam)
8819 char * save_current_file;
8820 unformat_input_t save_input;
8821 jmp_buf save_jump_buf;
8822 u32 save_line_number;
8824 FILE * new_fp, * save_ifp;
8826 if (unformat (vam->input, "%s", &s)) {
8827 new_fp = fopen ((char *)s, "r");
8829 errmsg ("Couldn't open script file %s\n", s);
8834 errmsg ("Missing script name\n");
8838 memcpy (&save_input, &vam->input, sizeof (save_input));
8839 memcpy (&save_jump_buf, &vam->jump_buf, sizeof (save_jump_buf));
8840 save_ifp = vam->ifp;
8841 save_line_number = vam->input_line_number;
8842 save_current_file = (char *) vam->current_file;
8844 vam->input_line_number = 0;
8846 vam->current_file = s;
8849 memcpy (&vam->input, &save_input, sizeof (vam->input));
8850 memcpy (&vam->jump_buf, &save_jump_buf, sizeof (save_jump_buf));
8851 vam->ifp = save_ifp;
8852 vam->input_line_number = save_line_number;
8853 vam->current_file = (u8 *) save_current_file;
8859 static int echo (vat_main_t * vam)
8861 fformat (vam->ofp, "%v", vam->input->buffer);
8865 /* List of API message constructors, CLI names map to api_xxx */
8866 #define foreach_vpe_api_msg \
8867 _(create_loopback,"[mac <mac-addr>]") \
8868 _(sw_interface_dump,"") \
8869 _(sw_interface_set_flags, \
8870 "<intfc> | sw_if_index <id> admin-up | admin-down link-up | link down") \
8871 _(sw_interface_add_del_address, \
8872 "<intfc> | sw_if_index <id> <ip4-address> | <ip6-address> [del] [del-all] ") \
8873 _(sw_interface_set_table, \
8874 "<intfc> | sw_if_index <id> vrf <table-id> [ipv6]") \
8875 _(sw_interface_set_vpath, \
8876 "<intfc> | sw_if_index <id> enable | disable") \
8877 _(sw_interface_set_l2_xconnect, \
8878 "rx <intfc> | rx_sw_if_index <id> tx <intfc> | tx_sw_if_index <id>\n" \
8879 "enable | disable") \
8880 _(sw_interface_set_l2_bridge, \
8881 "rx <intfc> | rx_sw_if_index <id> bd_id <bridge-domain-id>\n" \
8882 "[shg <split-horizon-group>] [bvi]\n" \
8883 "enable | disable") \
8884 _(bridge_domain_add_del, \
8885 "bd_id <bridge-domain-id> [flood 1|0] [uu-flood 1|0] [forward 1|0] [learn 1|0] [arp-term 1|0] [del]\n")\
8886 _(bridge_domain_dump, "[bd_id <bridge-domain-id>]\n") \
8888 "mac <mac-addr> bd_id <bridge-domain-id> [del] | sw_if <intfc> | sw_if_index <id> [static] [filter] [bvi]\n") \
8890 "sw_if <intfc> | sw_if_index <id> [learn] [forward] [uu-flood] [flood]\n") \
8892 "bd_id <bridge-domain-id> [learn] [forward] [uu-flood] [flood] [arp-term] [disable]\n") \
8894 "tapname <name> mac <mac-addr> | random-mac") \
8896 "<vpp-if-name> | sw_if_index <id> tapname <name> mac <mac-addr> | random-mac") \
8898 "<vpp-if-name> | sw_if_index <id>") \
8899 _(sw_interface_tap_dump, "") \
8900 _(ip_add_del_route, \
8901 "<addr>/<mask> via <addr> [vrf <n>]\n" \
8902 "[<intfc> | sw_if_index <id>] [resolve-attempts <n>]\n" \
8903 "[weight <n>] [drop] [local] [classify <n>] [del]\n" \
8904 "[multipath] [count <n>]") \
8905 _(proxy_arp_add_del, \
8906 "<lo-ip4-addr> - <hi-ip4-addr> [vrf <n>] [del]") \
8907 _(proxy_arp_intfc_enable_disable, \
8908 "<intfc> | sw_if_index <id> enable | disable") \
8909 _(mpls_add_del_encap, \
8910 "label <n> dst <ip4-addr> [vrf <n>] [del]") \
8911 _(mpls_add_del_decap, \
8912 "label <n> [rx_vrf_id <n>] [tx_vrf_id] [s-bit-clear][del]") \
8913 _(mpls_gre_add_del_tunnel, \
8914 "inner_vrf_id <n> outer_vrf_id <n> src <ip4-address> dst <ip4-address>\n" \
8915 "adj <ip4-address>/<mask-width> [del]") \
8916 _(sw_interface_set_unnumbered, \
8917 "<intfc> | sw_if_index <id> unnum_if_index <id> [del]") \
8918 _(ip_neighbor_add_del, \
8919 "<intfc> | sw_if_index <id> dst <ip46-address> mac <mac-addr>") \
8920 _(reset_vrf, "vrf <id> [ipv6]") \
8921 _(create_vlan_subif, "<intfc> | sw_if_index <id> vlan <n>") \
8922 _(create_subif, "<intfc> | sw_if_index <id> sub_id <n>\n" \
8923 "[outer_vlan_id <n>][inner_vlan_id <n>]\n" \
8924 "[no_tags][one_tag][two_tags][dot1ad][exact_match][default_sub]\n" \
8925 "[outer_vlan_id_any][inner_vlan_id_any]") \
8926 _(oam_add_del, "src <ip4-address> dst <ip4-address> [vrf <n>] [del]") \
8927 _(reset_fib, "vrf <n> [ipv6]") \
8928 _(dhcp_proxy_config, \
8929 "svr <v46-address> src <v46-address>\n" \
8930 "insert-cid <n> [del]") \
8931 _(dhcp_proxy_config_2, \
8932 "svr <v46-address> src <v46-address>\n" \
8933 "rx_vrf_id <nn> server_vrf_id <nn> insert-cid <n> [del]") \
8934 _(dhcp_proxy_set_vss, \
8935 "tbl_id <n> fib_id <n> oui <n> [ipv6] [del]") \
8936 _(dhcp_client_config, \
8937 "<intfc> | sw_if_index <id> [hostname <name>] [disable_event] [del]") \
8938 _(set_ip_flow_hash, \
8939 "vrf <n> [src] [dst] [sport] [dport] [proto] [reverse] [ipv6]") \
8940 _(sw_interface_ip6_enable_disable, \
8941 "<intfc> | sw_if_index <id> enable | disable") \
8942 _(sw_interface_ip6_set_link_local_address, \
8943 "<intfc> | sw_if_index <id> <ip6-address>/<mask-width>") \
8944 _(sw_interface_ip6nd_ra_prefix, \
8945 "<intfc> | sw_if_index <id> <ip6-address>/<mask-width>\n" \
8946 "val_life <n> pref_life <n> [def] [noadv] [offl] [noauto]\n" \
8947 "[nolink] [isno]") \
8948 _(sw_interface_ip6nd_ra_config, \
8949 "<intfc> | sw_if_index <id> [maxint <n>] [minint <n>]\n" \
8950 "[life <n>] [count <n>] [interval <n>] [surpress]\n" \
8951 "[managed] [other] [ll] [send] [cease] [isno] [def]") \
8952 _(set_arp_neighbor_limit, "arp_nbr_limit <n> [ipv6]") \
8953 _(l2_patch_add_del, \
8954 "rx <intfc> | rx_sw_if_index <id> tx <intfc> | tx_sw_if_index <id>\n" \
8955 "enable | disable") \
8956 _(mpls_ethernet_add_del_tunnel, \
8957 "tx <intfc> | tx_sw_if_index <n> dst <mac-addr>\n" \
8958 "adj <ip4-addr>/<mw> dst <mac-addr> [del]") \
8959 _(mpls_ethernet_add_del_tunnel_2, \
8960 "inner_vrf_id <n> outer_vrf_id <n> next-hop <ip4-addr>\n" \
8961 "resolve-attempts <n> resolve-if-needed 0 | 1 [del]") \
8962 _(sr_tunnel_add_del, \
8963 "src <ip6-addr> dst <ip6-addr>/<mw> (next <ip6-addr>)+\n" \
8964 " [tag <ip6-addr>]* [clean] [reroute]") \
8965 _(classify_add_del_table, \
8966 "buckets <nn> [skip <n>] [match <n>] [memory_size <nn-bytes>]\n" \
8967 "[del] mask <mask-value>\n" \
8968 " [l2-miss-next | miss-next | acl-miss-next] <name|nn>") \
8969 _(classify_add_del_session, \
8970 "[hit-next|l2-hit-next|acl-hit-next] <name|nn> table-index <nn>\n" \
8971 "skip_n <nn> match_n <nn> match [hex] [l2] [l3 [ip4|ip6]]") \
8972 _(classify_set_interface_ip_table, \
8973 "<intfc> | sw_if_index <nn> table <nn>") \
8974 _(classify_set_interface_l2_tables, \
8975 "<intfc> | sw_if_index <nn> [ip4-table <nn>] [ip6-table <nn>]\n" \
8976 " [other-table <nn>]") \
8977 _(get_node_index, "node <node-name") \
8978 _(add_node_next, "node <node-name> next <next-node-name>") \
8979 _(l2tpv3_create_tunnel, \
8980 "client_address <ip6-addr> our_address <ip6-addr>\n" \
8981 "[local_session_id <nn>][remote_session_id <nn>][local_cookie <nn>]\n"\
8982 "[remote_cookie <nn>]\n[l2-sublayer-preset]\n") \
8983 _(l2tpv3_set_tunnel_cookies, \
8984 "<intfc> | sw_if_index <nn> [new_local_cookie <nn>]\n" \
8985 "[new_remote_cookie <nn>]\n") \
8986 _(l2tpv3_interface_enable_disable, \
8987 "<intfc> | sw_if_index <nn> enable | disable") \
8988 _(l2tpv3_set_lookup_key, \
8989 "lookup_v6_src | lookup_v6_dst | lookup_session_id") \
8990 _(sw_if_l2tpv3_tunnel_dump, "") \
8991 _(vxlan_add_del_tunnel, \
8992 "src <ip4-addr> dst <ip4-addr> vni [encap-vrf-id <nn>]\n" \
8993 " [decap-next l2|ip4|ip6] [del]") \
8994 _(vxlan_tunnel_dump, "[<intfc> | sw_if_index <nn>]") \
8995 _(l2_fib_clear_table, "") \
8996 _(l2_interface_efp_filter, "sw_if_index <nn> enable | disable") \
8997 _(l2_interface_vlan_tag_rewrite, \
8998 "<intfc> | sw_if_index <nn> \n" \
8999 "[disable][push-[1|2]][pop-[1|2]][translate-1-[1|2]] \n" \
9000 "[translate-2-[1|2]] [push_dot1q 0] tag1 <nn> tag2 <nn>") \
9001 _(create_vhost_user_if, \
9002 "socket <filename> [server] [renumber <dev_instance>] " \
9003 "[mac <mac_address>]") \
9004 _(modify_vhost_user_if, \
9005 "<intfc> | sw_if_index <nn> socket <filename>\n" \
9006 "[server] [renumber <dev_instance>]") \
9007 _(delete_vhost_user_if, "<intfc> | sw_if_index <nn>") \
9008 _(sw_interface_vhost_user_dump, "") \
9009 _(show_version, "") \
9010 _(nsh_gre_add_del_tunnel, \
9011 "src <ip4-addr> dst <ip4-addr>" \
9012 "c1 <nn> c2 <nn> c3 <nn> c4 <nn> spi <nn> si <nn>\n" \
9013 "[encap-fib-id <nn>] [decap-fib-id <nn>] [o-bit <1|0>]\n" \
9014 "[c-bit <1|0>] [md-type <nn>][next-ip4][next-ip6][next-ethernet]\n" \
9015 "[tlv <xx>][del]") \
9016 _(nsh_vxlan_gpe_add_del_tunnel, \
9017 "src <ip4-addr> dst <ip4-addr> vni <nn>\n" \
9018 "c1 <nn> c2 <nn> c3 <nn> c4 <nn> spi <nn> si <nn>\n" \
9019 "[encap-vrf-id <nn>] [decap-vrf-id <nn>] [o-bit <1|0>]\n" \
9020 "[c-bit <1|0>] [md-type <nn>][next-ip4][next-ip6][next-ethernet]\n" \
9021 "[tlv <xx>][del]") \
9022 _(l2_fib_table_dump, "bd_id <bridge-domain-id>") \
9023 _(lisp_gpe_add_del_tunnel, \
9024 "src <ip4-addr> dst <ip4-addr> iid <nn>|iidx <0xnn>\n" \
9025 "[encap-vrf-id <nn>] [decap-vrf-id <nn>]\n" \
9026 "[n-bit][l-bit][e-bit][v-bit][i-bit][p-bit][not-p-bit][o-bit]\n" \
9027 "[next-ip4][next-ip6][next-ethernet][next-nsh]\n" \
9028 "[decap-next [ip4|ip6|ethernet|nsh-encap|<nn>]][del]") \
9029 _(interface_name_renumber, \
9030 "<intfc> | sw_if_index <nn> new_show_dev_instance <nn>") \
9031 _(input_acl_set_interface, \
9032 "<intfc> | sw_if_index <nn> [ip4-table <nn>] [ip6-table <nn>]\n" \
9033 " [l2-table <nn>] [del]") \
9034 _(want_ip4_arp_events, "address <ip4-address> [del]") \
9035 _(ip_address_dump, "(ipv4 | ipv6) (<intfc> | sw_if_index <id>)") \
9036 _(ip_dump, "ipv4 | ipv6") \
9037 _(ipsec_spd_add_del, "spd_id <n> [del]") \
9038 _(ipsec_interface_add_del_spd, "(<intfc> | sw_if_index <id>)\n" \
9040 _(ipsec_sad_add_del_entry, "sad_id <n> spi <n> crypto_alg <alg>\n" \
9041 " crypto_key <hex> tunnel_src <ip4|ip6> tunnel_dst <ip4|ip6>\n" \
9042 " integ_alg <alg> integ_key <hex>") \
9043 _(ipsec_spd_add_del_entry, "spd_id <n> priority <n> action <action>\n" \
9044 " (inbound|outbound) [sa_id <n>] laddr_start <ip4|ip6>\n" \
9045 " laddr_stop <ip4|ip6> raddr_start <ip4|ip6> raddr_stop <ip4|ip6>\n" \
9046 " [lport_start <n> lport_stop <n>] [rport_start <n> rport_stop <n>]" )\
9047 _(ipsec_sa_set_key, "sa_id <n> crypto_key <hex> integ_key <hex>") \
9048 _(delete_loopback,"sw_if_index <nn>") \
9049 _(bd_ip_mac_add_del, "bd_id <bridge-domain-id> <ip4/6-addr> <mac-addr> [del]") \
9051 "ip4-pfx <ip4pfx> ip6-pfx <ip6pfx> " \
9052 "ip6-src <ip6addr> " \
9053 "ea-bits-len <n> psid-offset <n> psid-len <n>") \
9054 _(map_del_domain, "index <n>") \
9055 _(map_add_del_rule, \
9056 "index <n> psid <n> dst <ip6addr> [del]") \
9057 _(map_domain_dump, "") \
9058 _(map_rule_dump, "index <map-domain>") \
9059 _(want_interface_events, "enable|disable") \
9060 _(want_stats,"enable|disable") \
9061 _(get_first_msg_id, "client <name>") \
9062 _(cop_interface_enable_disable, "<intfc> | sw_if_index <nn> [disable]") \
9063 _(cop_whitelist_enable_disable, "<intfc> | sw_if_index <nn>\n" \
9064 "fib-id <nn> [ip4][ip6][default]") \
9065 _(get_node_graph, " ")
9067 /* List of command functions, CLI names map directly to functions */
9068 #define foreach_cli_function \
9069 _(comment, "usage: comment <ignore-rest-of-line>") \
9070 _(dump_interface_table, "usage: dump_interface_table") \
9071 _(dump_sub_interface_table, "usage: dump_sub_interface_table") \
9072 _(dump_ipv4_table, "usage: dump_ipv4_table") \
9073 _(dump_ipv6_table, "usage: dump_ipv6_table") \
9074 _(dump_stats_table, "usage: dump_stats_table") \
9075 _(dump_macro_table, "usage: dump_macro_table ") \
9076 _(dump_node_table, "usage: dump_node_table") \
9077 _(echo, "usage: echo <message>") \
9078 _(exec, "usage: exec <vpe-debug-CLI-command>") \
9079 _(help, "usage: help") \
9080 _(q, "usage: quit") \
9081 _(quit, "usage: quit") \
9082 _(search_node_table, "usage: search_node_table <name>...") \
9083 _(set, "usage: set <variable-name> <value>") \
9084 _(script, "usage: script <file-name>") \
9085 _(unset, "usage: unset <variable-name>")
9088 static void vl_api_##n##_t_handler_uni \
9089 (vl_api_##n##_t * mp) \
9091 vat_main_t * vam = &vat_main; \
9092 if (vam->json_output) { \
9093 vl_api_##n##_t_handler_json(mp); \
9095 vl_api_##n##_t_handler(mp); \
9098 foreach_vpe_api_reply_msg;
9101 void vat_api_hookup (vat_main_t *vam)
9104 vl_msg_api_set_handlers(VL_API_##N, #n, \
9105 vl_api_##n##_t_handler_uni, \
9107 vl_api_##n##_t_endian, \
9108 vl_api_##n##_t_print, \
9109 sizeof(vl_api_##n##_t), 1);
9110 foreach_vpe_api_reply_msg;
9113 vl_msg_api_set_first_available_msg_id (VL_MSG_FIRST_AVAILABLE);
9115 vam->sw_if_index_by_interface_name =
9116 hash_create_string (0, sizeof (uword));
9118 vam->function_by_name =
9119 hash_create_string (0, sizeof(uword));
9122 hash_create_string (0, sizeof(uword));
9124 /* API messages we can send */
9125 #define _(n,h) hash_set_mem (vam->function_by_name, #n, api_##n);
9126 foreach_vpe_api_msg;
9130 #define _(n,h) hash_set_mem (vam->help_by_name, #n, h);
9131 foreach_vpe_api_msg;
9135 #define _(n,h) hash_set_mem (vam->function_by_name, #n, n);
9136 foreach_cli_function;
9140 #define _(n,h) hash_set_mem (vam->help_by_name, #n, h);
9141 foreach_cli_function;
9145 #undef vl_api_version
9146 #define vl_api_version(n,v) static u32 vpe_api_version = v;
9147 #include <api/vpe.api.h>
9148 #undef vl_api_version
9150 void vl_client_add_api_signatures (vl_api_memclnt_create_t *mp)
9153 * Send the main API signature in slot 0. This bit of code must
9154 * match the checks in ../vpe/api/api.c: vl_msg_api_version_check().
9156 mp->api_versions[0] = clib_host_to_net_u32 (vpe_api_version);