2 *------------------------------------------------------------------
5 * Copyright (c) 2014 Cisco and/or its affiliates.
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at:
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
17 *------------------------------------------------------------------
21 #include <vlibapi/api.h>
22 #include <vlibmemory/api.h>
23 #include <vlibsocket/api.h>
24 #include <vnet/ip/ip.h>
25 #include <vnet/sr/sr_packet.h>
26 #include <vnet/l2/l2_input.h>
27 #include <vnet/l2tp/l2tp.h>
28 #include <vnet/vxlan/vxlan.h>
29 #include <vnet/nsh-gre/nsh_gre.h>
30 #include <vnet/nsh-vxlan-gpe/nsh_vxlan_gpe.h>
31 #include <vnet/lisp-gpe/lisp_gpe.h>
33 #include <api/vpe_msg_enum.h>
34 #include <vnet/l2/l2_classify.h>
35 #include <vnet/l2/l2_vtr.h>
36 #include <vnet/classify/input_acl.h>
38 #include <vnet/ipsec/ipsec.h>
42 #include <vnet/map/map.h>
43 #include <vnet/cop/cop.h>
45 #include "vat/json_format.h"
47 #define vl_typedefs /* define message structures */
48 #include <api/vpe_all_api_h.h>
51 /* declare message handlers for each api */
53 #define vl_endianfun /* define message structures */
54 #include <api/vpe_all_api_h.h>
57 /* instantiate all the print functions we know about */
58 #define vl_print(handle, ...)
60 #include <api/vpe_all_api_h.h>
63 uword unformat_sw_if_index (unformat_input_t * input, va_list * args)
65 vat_main_t * vam = va_arg (*args, vat_main_t *);
66 u32 * result = va_arg (*args, u32 *);
70 if (!unformat (input, "%s", &if_name))
73 p = hash_get_mem (vam->sw_if_index_by_interface_name, if_name);
80 /* Parse an IP4 address %d.%d.%d.%d. */
81 uword unformat_ip4_address (unformat_input_t * input, va_list * args)
83 u8 * result = va_arg (*args, u8 *);
86 if (! unformat (input, "%d.%d.%d.%d", &a[0], &a[1], &a[2], &a[3]))
89 if (a[0] >= 256 || a[1] >= 256 || a[2] >= 256 || a[3] >= 256)
102 unformat_ethernet_address (unformat_input_t * input, va_list * args)
104 u8 * result = va_arg (*args, u8 *);
107 if (! unformat (input, "%_%x:%x:%x:%x:%x:%x%_",
108 &a[0], &a[1], &a[2], &a[3], &a[4], &a[5]))
112 for (i = 0; i < 6; i++)
113 if (a[i] >= (1 << 8))
116 for (i = 0; i < 6; i++)
122 /* Returns ethernet type as an int in host byte order. */
124 unformat_ethernet_type_host_byte_order (unformat_input_t * input,
127 u16 * result = va_arg (*args, u16 *);
131 if (unformat (input, "0x%x", &type)
132 || unformat (input, "%d", &type))
134 if (type >= (1 << 16))
142 /* Parse an IP6 address. */
143 uword unformat_ip6_address (unformat_input_t * input, va_list * args)
145 ip6_address_t * result = va_arg (*args, ip6_address_t *);
147 uword hex_quad, n_hex_quads, hex_digit, n_hex_digits;
148 uword c, n_colon, double_colon_index;
150 n_hex_quads = hex_quad = n_hex_digits = n_colon = 0;
151 double_colon_index = ARRAY_LEN (hex_quads);
152 while ((c = unformat_get_input (input)) != UNFORMAT_END_OF_INPUT)
155 if (c >= '0' && c <= '9')
157 else if (c >= 'a' && c <= 'f')
158 hex_digit = c + 10 - 'a';
159 else if (c >= 'A' && c <= 'F')
160 hex_digit = c + 10 - 'A';
161 else if (c == ':' && n_colon < 2)
165 unformat_put_input (input);
169 /* Too many hex quads. */
170 if (n_hex_quads >= ARRAY_LEN (hex_quads))
175 hex_quad = (hex_quad << 4) | hex_digit;
177 /* Hex quad must fit in 16 bits. */
178 if (n_hex_digits >= 4)
185 /* Save position of :: */
188 /* More than one :: ? */
189 if (double_colon_index < ARRAY_LEN (hex_quads))
191 double_colon_index = n_hex_quads;
194 if (n_colon > 0 && n_hex_digits > 0)
196 hex_quads[n_hex_quads++] = hex_quad;
202 if (n_hex_digits > 0)
203 hex_quads[n_hex_quads++] = hex_quad;
208 /* Expand :: to appropriate number of zero hex quads. */
209 if (double_colon_index < ARRAY_LEN (hex_quads))
211 word n_zero = ARRAY_LEN (hex_quads) - n_hex_quads;
213 for (i = n_hex_quads - 1; i >= (signed) double_colon_index; i--)
214 hex_quads[n_zero + i] = hex_quads[i];
216 for (i = 0; i < n_zero; i++)
217 hex_quads[double_colon_index + i] = 0;
219 n_hex_quads = ARRAY_LEN (hex_quads);
222 /* Too few hex quads given. */
223 if (n_hex_quads < ARRAY_LEN (hex_quads))
226 for (i = 0; i < ARRAY_LEN (hex_quads); i++)
227 result->as_u16[i] = clib_host_to_net_u16 (hex_quads[i]);
234 unformat_ipsec_policy_action (unformat_input_t * input, va_list * args)
237 u32 * r = va_arg (*args, u32 *);
240 #define _(v,f,s) else if (unformat (input, s)) *r = IPSEC_POLICY_ACTION_##f;
241 foreach_ipsec_policy_action
252 unformat_ipsec_crypto_alg (unformat_input_t * input, va_list * args)
255 u32 * r = va_arg (*args, u32 *);
258 #define _(v,f,s) else if (unformat (input, s)) *r = IPSEC_CRYPTO_ALG_##f;
259 foreach_ipsec_crypto_alg
270 format_ipsec_crypto_alg (u8 * s, va_list * args)
273 u32 i = va_arg (*args, u32);
278 #define _(v,f,str) case IPSEC_CRYPTO_ALG_##f: t = (u8 *) str; break;
279 foreach_ipsec_crypto_alg
282 return format (s, "unknown");
284 return format (s, "%s", t);
286 return format (s, "Unimplemented");
291 unformat_ipsec_integ_alg (unformat_input_t * input, va_list * args)
294 u32 * r = va_arg (*args, u32 *);
297 #define _(v,f,s) else if (unformat (input, s)) *r = IPSEC_INTEG_ALG_##f;
298 foreach_ipsec_integ_alg
309 format_ipsec_integ_alg (u8 * s, va_list * args)
312 u32 i = va_arg (*args, u32);
317 #define _(v,f,str) case IPSEC_INTEG_ALG_##f: t = (u8 *) str; break;
318 foreach_ipsec_integ_alg
321 return format (s, "unknown");
323 return format (s, "%s", t);
325 return format (s, "Unsupported");
329 u8 * format_ip4_address (u8 * s, va_list * args)
331 u8 * a = va_arg (*args, u8 *);
332 return format (s, "%d.%d.%d.%d", a[0], a[1], a[2], a[3]);
335 u8 * format_ip6_address (u8 * s, va_list * args)
337 ip6_address_t * a = va_arg (*args, ip6_address_t *);
338 u32 i, i_max_n_zero, max_n_zeros, i_first_zero, n_zeros, last_double_colon;
340 i_max_n_zero = ARRAY_LEN (a->as_u16);
342 i_first_zero = i_max_n_zero;
344 for (i = 0; i < ARRAY_LEN (a->as_u16); i++)
346 u32 is_zero = a->as_u16[i] == 0;
347 if (is_zero && i_first_zero >= ARRAY_LEN (a->as_u16))
353 if ((! is_zero && n_zeros > max_n_zeros)
354 || (i + 1 >= ARRAY_LEN (a->as_u16) && n_zeros > max_n_zeros))
356 i_max_n_zero = i_first_zero;
357 max_n_zeros = n_zeros;
358 i_first_zero = ARRAY_LEN (a->as_u16);
363 last_double_colon = 0;
364 for (i = 0; i < ARRAY_LEN (a->as_u16); i++)
366 if (i == i_max_n_zero && max_n_zeros > 1)
368 s = format (s, "::");
369 i += max_n_zeros - 1;
370 last_double_colon = 1;
374 s = format (s, "%s%x",
375 (last_double_colon || i == 0) ? "" : ":",
376 clib_net_to_host_u16 (a->as_u16[i]));
377 last_double_colon = 0;
384 u8 * format_ethernet_address (u8 * s, va_list * args)
386 u8 * a = va_arg (*args, u8 *);
388 return format (s, "%02x:%02x:%02x:%02x:%02x:%02x",
389 a[0], a[1], a[2], a[3], a[4], a[5]);
392 void increment_v4_address (ip4_address_t * a)
396 v = ntohl(a->as_u32) + 1;
397 a->as_u32 = ntohl(v);
400 void increment_v6_address (ip6_address_t * a)
404 v0 = clib_net_to_host_u64 (a->as_u64[0]);
405 v1 = clib_net_to_host_u64 (a->as_u64[1]);
410 a->as_u64[0] = clib_net_to_host_u64 (v0);
411 a->as_u64[1] = clib_net_to_host_u64 (v1);
415 static void vl_api_create_loopback_reply_t_handler
416 (vl_api_create_loopback_reply_t * mp)
418 vat_main_t * vam = &vat_main;
419 i32 retval = ntohl(mp->retval);
421 vam->retval = retval;
422 vam->result_ready = 1;
423 vam->regenerate_interface_table = 1;
426 static void vl_api_create_loopback_reply_t_handler_json
427 (vl_api_create_loopback_reply_t * mp)
429 vat_main_t * vam = &vat_main;
430 vat_json_node_t node;
432 vat_json_init_object(&node);
433 vat_json_object_add_int(&node, "retval", ntohl(mp->retval));
434 vat_json_object_add_uint(&node, "sw_if_index", ntohl(mp->sw_if_index));
436 vat_json_print(vam->ofp, &node);
437 vat_json_free(&node);
439 vam->retval = ntohl(mp->retval);
440 vam->result_ready = 1;
443 static void vl_api_create_vlan_subif_reply_t_handler
444 (vl_api_create_vlan_subif_reply_t * mp)
446 vat_main_t * vam = &vat_main;
447 i32 retval = ntohl(mp->retval);
449 vam->retval = retval;
450 vam->result_ready = 1;
451 vam->regenerate_interface_table = 1;
454 static void vl_api_create_vlan_subif_reply_t_handler_json
455 (vl_api_create_vlan_subif_reply_t * mp)
457 vat_main_t * vam = &vat_main;
458 vat_json_node_t node;
460 vat_json_init_object(&node);
461 vat_json_object_add_int(&node, "retval", ntohl(mp->retval));
462 vat_json_object_add_uint(&node, "sw_if_index", ntohl(mp->sw_if_index));
464 vat_json_print(vam->ofp, &node);
465 vat_json_free(&node);
467 vam->retval = ntohl(mp->retval);
468 vam->result_ready = 1;
471 static void vl_api_create_subif_reply_t_handler
472 (vl_api_create_subif_reply_t * mp)
474 vat_main_t * vam = &vat_main;
475 i32 retval = ntohl(mp->retval);
477 vam->retval = retval;
478 vam->result_ready = 1;
479 vam->regenerate_interface_table = 1;
482 static void vl_api_create_subif_reply_t_handler_json
483 (vl_api_create_subif_reply_t * mp)
485 vat_main_t * vam = &vat_main;
486 vat_json_node_t node;
488 vat_json_init_object(&node);
489 vat_json_object_add_int(&node, "retval", ntohl(mp->retval));
490 vat_json_object_add_uint(&node, "sw_if_index", ntohl(mp->sw_if_index));
492 vat_json_print(vam->ofp, &node);
493 vat_json_free(&node);
495 vam->retval = ntohl(mp->retval);
496 vam->result_ready = 1;
499 static void vl_api_interface_name_renumber_reply_t_handler
500 (vl_api_interface_name_renumber_reply_t * mp)
502 vat_main_t * vam = &vat_main;
503 i32 retval = ntohl(mp->retval);
505 vam->retval = retval;
506 vam->result_ready = 1;
507 vam->regenerate_interface_table = 1;
510 static void vl_api_interface_name_renumber_reply_t_handler_json
511 (vl_api_interface_name_renumber_reply_t * mp)
513 vat_main_t * vam = &vat_main;
514 vat_json_node_t node;
516 vat_json_init_object(&node);
517 vat_json_object_add_int(&node, "retval", ntohl(mp->retval));
519 vat_json_print(vam->ofp, &node);
520 vat_json_free(&node);
522 vam->retval = ntohl(mp->retval);
523 vam->result_ready = 1;
527 * Special-case: build the interface table, maintain
528 * the next loopback sw_if_index vbl.
530 static void vl_api_sw_interface_details_t_handler
531 (vl_api_sw_interface_details_t * mp)
533 vat_main_t * vam = &vat_main;
534 u8 * s = format (0, "%s%c", mp->interface_name, 0);
536 hash_set_mem (vam->sw_if_index_by_interface_name, s,
537 ntohl(mp->sw_if_index));
539 /* In sub interface case, fill the sub interface table entry */
540 if (mp->sw_if_index != mp->sup_sw_if_index) {
541 sw_interface_subif_t * sub = NULL;
543 vec_add2(vam->sw_if_subif_table, sub, 1);
545 vec_validate(sub->interface_name, strlen((char *)s) + 1);
546 strncpy((char *)sub->interface_name, (char *)s,
547 vec_len(sub->interface_name));
548 sub->sw_if_index = ntohl(mp->sw_if_index);
549 sub->sub_id = ntohl(mp->sub_id);
551 sub->sub_dot1ad = mp->sub_dot1ad;
552 sub->sub_number_of_tags = mp->sub_number_of_tags;
553 sub->sub_outer_vlan_id = ntohs(mp->sub_outer_vlan_id);
554 sub->sub_inner_vlan_id = ntohs(mp->sub_inner_vlan_id);
555 sub->sub_exact_match = mp->sub_exact_match;
556 sub->sub_default = mp->sub_default;
557 sub->sub_outer_vlan_id_any = mp->sub_outer_vlan_id_any;
558 sub->sub_inner_vlan_id_any = mp->sub_inner_vlan_id_any;
560 /* vlan tag rewrite */
561 sub->vtr_op = ntohl(mp->vtr_op);
562 sub->vtr_push_dot1q = ntohl(mp->vtr_push_dot1q);
563 sub->vtr_tag1 = ntohl(mp->vtr_tag1);
564 sub->vtr_tag2 = ntohl(mp->vtr_tag2);
568 static void vl_api_sw_interface_details_t_handler_json
569 (vl_api_sw_interface_details_t * mp)
571 vat_main_t * vam = &vat_main;
572 vat_json_node_t *node = NULL;
574 if (VAT_JSON_ARRAY != vam->json_tree.type) {
575 ASSERT(VAT_JSON_NONE == vam->json_tree.type);
576 vat_json_init_array(&vam->json_tree);
578 node = vat_json_array_add(&vam->json_tree);
580 vat_json_init_object(node);
581 vat_json_object_add_uint(node, "sw_if_index", ntohl(mp->sw_if_index));
582 vat_json_object_add_uint(node, "sup_sw_if_index", ntohl(mp->sup_sw_if_index));
583 vat_json_object_add_uint(node, "l2_address_length", ntohl(mp->l2_address_length));
584 vat_json_object_add_bytes(node, "l2_address", mp->l2_address, sizeof(mp->l2_address));
585 vat_json_object_add_string_copy(node, "interface_name", mp->interface_name);
586 vat_json_object_add_uint(node, "admin_up_down", mp->admin_up_down);
587 vat_json_object_add_uint(node, "link_up_down", mp->link_up_down);
588 vat_json_object_add_uint(node, "link_duplex", mp->link_duplex);
589 vat_json_object_add_uint(node, "link_speed", mp->link_speed);
590 vat_json_object_add_uint(node, "mtu", ntohs(mp->link_mtu));
591 vat_json_object_add_uint(node, "sub_id", ntohl(mp->sub_id));
592 vat_json_object_add_uint(node, "sub_dot1ad", mp->sub_dot1ad);
593 vat_json_object_add_uint(node, "sub_number_of_tags", mp->sub_number_of_tags);
594 vat_json_object_add_uint(node, "sub_outer_vlan_id", ntohs(mp->sub_outer_vlan_id));
595 vat_json_object_add_uint(node, "sub_inner_vlan_id", ntohs(mp->sub_inner_vlan_id));
596 vat_json_object_add_uint(node, "sub_exact_match", mp->sub_exact_match);
597 vat_json_object_add_uint(node, "sub_default", mp->sub_default);
598 vat_json_object_add_uint(node, "sub_outer_vlan_id_any", mp->sub_outer_vlan_id_any);
599 vat_json_object_add_uint(node, "sub_inner_vlan_id_any", mp->sub_inner_vlan_id_any);
600 vat_json_object_add_uint(node, "vtr_op", ntohl(mp->vtr_op));
601 vat_json_object_add_uint(node, "vtr_push_dot1q", ntohl(mp->vtr_push_dot1q));
602 vat_json_object_add_uint(node, "vtr_tag1", ntohl(mp->vtr_tag1));
603 vat_json_object_add_uint(node, "vtr_tag2", ntohl(mp->vtr_tag2));
606 static void vl_api_sw_interface_set_flags_t_handler
607 (vl_api_sw_interface_set_flags_t * mp)
609 vat_main_t * vam = &vat_main;
610 if (vam->interface_event_display)
611 errmsg ("interface flags: sw_if_index %d %s %s\n",
612 ntohl(mp->sw_if_index),
613 mp->admin_up_down ? "admin-up" : "admin-down",
614 mp->link_up_down ? "link-up" : "link-down");
617 static void vl_api_sw_interface_set_flags_t_handler_json
618 (vl_api_sw_interface_set_flags_t * mp)
620 /* JSON output not supported */
623 static void vl_api_cli_reply_t_handler
624 (vl_api_cli_reply_t * mp)
626 vat_main_t * vam = &vat_main;
627 i32 retval = ntohl(mp->retval);
629 vam->retval = retval;
630 vam->shmem_result = (u8 *) mp->reply_in_shmem;
631 vam->result_ready = 1;
634 static void vl_api_cli_reply_t_handler_json
635 (vl_api_cli_reply_t * mp)
637 vat_main_t * vam = &vat_main;
638 vat_json_node_t node;
639 api_main_t * am = &api_main;
643 vat_json_init_object(&node);
644 vat_json_object_add_int(&node, "retval", ntohl(mp->retval));
645 vat_json_object_add_uint(&node, "reply_in_shmem",
646 ntohl(mp->reply_in_shmem));
647 /* Toss the shared-memory original... */
648 pthread_mutex_lock (&am->vlib_rp->mutex);
649 oldheap = svm_push_data_heap (am->vlib_rp);
651 reply = (u8 *)(mp->reply_in_shmem);
654 svm_pop_heap (oldheap);
655 pthread_mutex_unlock (&am->vlib_rp->mutex);
657 vat_json_print(vam->ofp, &node);
658 vat_json_free(&node);
660 vam->retval = ntohl(mp->retval);
661 vam->result_ready = 1;
664 static void vl_api_classify_add_del_table_reply_t_handler
665 (vl_api_classify_add_del_table_reply_t * mp)
667 vat_main_t * vam = &vat_main;
668 i32 retval = ntohl(mp->retval);
669 if (vam->async_mode) {
670 vam->async_errors += (retval < 0);
672 vam->retval = retval;
673 vam->result_ready = 1;
675 ((mp->new_table_index != 0xFFFFFFFF) ||
676 (mp->skip_n_vectors != 0xFFFFFFFF) ||
677 (mp->match_n_vectors != 0xFFFFFFFF)))
679 * Note: this is just barely thread-safe, depends on
680 * the main thread spinning waiting for an answer...
682 errmsg ("new index %d, skip_n_vectors %d, match_n_vectors %d\n",
683 ntohl(mp->new_table_index),
684 ntohl(mp->skip_n_vectors), ntohl(mp->match_n_vectors));
688 static void vl_api_classify_add_del_table_reply_t_handler_json
689 (vl_api_classify_add_del_table_reply_t * mp)
691 vat_main_t * vam = &vat_main;
692 vat_json_node_t node;
694 vat_json_init_object(&node);
695 vat_json_object_add_int(&node, "retval", ntohl(mp->retval));
696 vat_json_object_add_uint(&node, "new_table_index", ntohl(mp->new_table_index));
697 vat_json_object_add_uint(&node, "skip_n_vectors", ntohl(mp->skip_n_vectors));
698 vat_json_object_add_uint(&node, "match_n_vectors", ntohl(mp->match_n_vectors));
700 vat_json_print(vam->ofp, &node);
701 vat_json_free(&node);
703 vam->retval = ntohl(mp->retval);
704 vam->result_ready = 1;
707 static void vl_api_get_node_index_reply_t_handler
708 (vl_api_get_node_index_reply_t * mp)
710 vat_main_t * vam = &vat_main;
711 i32 retval = ntohl(mp->retval);
712 if (vam->async_mode) {
713 vam->async_errors += (retval < 0);
715 vam->retval = retval;
716 vam->result_ready = 1;
718 errmsg ("node index %d\n", ntohl(mp->node_index));
722 static void vl_api_get_node_index_reply_t_handler_json
723 (vl_api_get_node_index_reply_t * mp)
725 vat_main_t * vam = &vat_main;
726 vat_json_node_t node;
728 vat_json_init_object(&node);
729 vat_json_object_add_int(&node, "retval", ntohl(mp->retval));
730 vat_json_object_add_uint(&node, "node_index", ntohl(mp->node_index));
732 vat_json_print(vam->ofp, &node);
733 vat_json_free(&node);
735 vam->retval = ntohl(mp->retval);
736 vam->result_ready = 1;
739 static void vl_api_add_node_next_reply_t_handler
740 (vl_api_add_node_next_reply_t * mp)
742 vat_main_t * vam = &vat_main;
743 i32 retval = ntohl(mp->retval);
744 if (vam->async_mode) {
745 vam->async_errors += (retval < 0);
747 vam->retval = retval;
748 vam->result_ready = 1;
750 errmsg ("next index %d\n", ntohl(mp->next_index));
754 static void vl_api_add_node_next_reply_t_handler_json
755 (vl_api_add_node_next_reply_t * mp)
757 vat_main_t * vam = &vat_main;
758 vat_json_node_t node;
760 vat_json_init_object(&node);
761 vat_json_object_add_int(&node, "retval", ntohl(mp->retval));
762 vat_json_object_add_uint(&node, "next_index", ntohl(mp->next_index));
764 vat_json_print(vam->ofp, &node);
765 vat_json_free(&node);
767 vam->retval = ntohl(mp->retval);
768 vam->result_ready = 1;
771 static void vl_api_mpls_gre_add_del_tunnel_reply_t_handler
772 (vl_api_mpls_gre_add_del_tunnel_reply_t * mp)
774 vat_main_t * vam = &vat_main;
775 i32 retval = ntohl(mp->retval);
776 u32 sw_if_index = ntohl(mp->tunnel_sw_if_index);
778 if (retval >= 0 && sw_if_index != (u32)~0) {
779 errmsg ("tunnel_sw_if_index %d\n", sw_if_index);
781 vam->retval = retval;
782 vam->result_ready = 1;
785 static void vl_api_mpls_gre_add_del_tunnel_reply_t_handler_json
786 (vl_api_mpls_gre_add_del_tunnel_reply_t * mp)
788 vat_main_t * vam = &vat_main;
789 vat_json_node_t node;
791 vat_json_init_object(&node);
792 vat_json_object_add_int(&node, "retval", ntohl(mp->retval));
793 vat_json_object_add_uint(&node, "tunnel_sw_if_index", ntohl(mp->tunnel_sw_if_index));
795 vat_json_print(vam->ofp, &node);
796 vat_json_free(&node);
798 vam->retval = ntohl(mp->retval);
799 vam->result_ready = 1;
802 static void vl_api_nsh_gre_add_del_tunnel_reply_t_handler
803 (vl_api_nsh_gre_add_del_tunnel_reply_t * mp)
805 vat_main_t * vam = &vat_main;
806 i32 retval = ntohl(mp->retval);
807 u32 sw_if_index = ntohl(mp->sw_if_index);
809 if (retval >= 0 && sw_if_index != (u32)~0) {
810 errmsg ("sw_if_index %d\n", ntohl(mp->sw_if_index));
812 vam->retval = retval;
813 vam->result_ready = 1;
816 static void vl_api_nsh_gre_add_del_tunnel_reply_t_handler_json
817 (vl_api_nsh_gre_add_del_tunnel_reply_t * mp)
819 vat_main_t * vam = &vat_main;
820 vat_json_node_t node;
822 vat_json_init_object(&node);
823 vat_json_object_add_int(&node, "retval", ntohl(mp->retval));
824 vat_json_object_add_uint(&node, "sw_if_index", ntohl(mp->sw_if_index));
826 vat_json_print(vam->ofp, &node);
827 vat_json_free(&node);
829 vam->retval = ntohl(mp->retval);
830 vam->result_ready = 1;
833 static void vl_api_nsh_vxlan_gpe_add_del_tunnel_reply_t_handler
834 (vl_api_nsh_vxlan_gpe_add_del_tunnel_reply_t * mp)
836 vat_main_t * vam = &vat_main;
837 i32 retval = ntohl(mp->retval);
838 u32 sw_if_index = ntohl(mp->sw_if_index);
840 if (retval >= 0 && sw_if_index != (u32)~0) {
841 errmsg ("sw_if_index %d\n", ntohl(mp->sw_if_index));
843 vam->retval = retval;
844 vam->result_ready = 1;
847 static void vl_api_nsh_vxlan_gpe_add_del_tunnel_reply_t_handler_json
848 (vl_api_nsh_vxlan_gpe_add_del_tunnel_reply_t * mp)
850 vat_main_t * vam = &vat_main;
851 vat_json_node_t node;
853 vat_json_init_object(&node);
854 vat_json_object_add_int(&node, "retval", ntohl(mp->retval));
855 vat_json_object_add_uint(&node, "sw_if_index", ntohl(mp->sw_if_index));
857 vat_json_print(vam->ofp, &node);
858 vat_json_free(&node);
860 vam->retval = ntohl(mp->retval);
861 vam->result_ready = 1;
864 static void vl_api_lisp_gpe_add_del_tunnel_reply_t_handler
865 (vl_api_lisp_gpe_add_del_tunnel_reply_t * mp)
867 vat_main_t * vam = &vat_main;
868 i32 retval = ntohl(mp->retval);
869 u32 sw_if_index = ntohl(mp->sw_if_index);
871 if (retval >= 0 && sw_if_index != (u32)~0) {
872 errmsg ("sw_if_index %d\n", ntohl(mp->sw_if_index));
874 vam->retval = retval;
875 vam->result_ready = 1;
878 static void vl_api_lisp_gpe_add_del_tunnel_reply_t_handler_json
879 (vl_api_lisp_gpe_add_del_tunnel_reply_t * mp)
881 vat_main_t * vam = &vat_main;
882 vat_json_node_t node;
884 vat_json_init_object(&node);
885 vat_json_object_add_int(&node, "retval", ntohl(mp->retval));
886 vat_json_object_add_uint(&node, "sw_if_index", ntohl(mp->sw_if_index));
888 vat_json_print(vam->ofp, &node);
889 vat_json_free(&node);
891 vam->retval = ntohl(mp->retval);
892 vam->result_ready = 1;
895 static void vl_api_show_version_reply_t_handler
896 (vl_api_show_version_reply_t * mp)
898 vat_main_t * vam = &vat_main;
899 i32 retval = ntohl(mp->retval);
902 errmsg (" program: %s\n", mp->program);
903 errmsg (" version: %s\n", mp->version);
904 errmsg (" build date: %s\n", mp->build_date);
905 errmsg ("build directory: %s\n", mp->build_directory);
907 vam->retval = retval;
908 vam->result_ready = 1;
911 static void vl_api_show_version_reply_t_handler_json
912 (vl_api_show_version_reply_t * mp)
914 vat_main_t * vam = &vat_main;
915 vat_json_node_t node;
917 vat_json_init_object(&node);
918 vat_json_object_add_int(&node, "retval", ntohl(mp->retval));
919 vat_json_object_add_string_copy(&node, "program", mp->program);
920 vat_json_object_add_string_copy(&node, "version", mp->version);
921 vat_json_object_add_string_copy(&node, "build_date", mp->build_date);
922 vat_json_object_add_string_copy(&node, "build_directory", mp->build_directory);
924 vat_json_print(vam->ofp, &node);
925 vat_json_free(&node);
927 vam->retval = ntohl(mp->retval);
928 vam->result_ready = 1;
931 static void vl_api_ip4_arp_event_t_handler
932 (vl_api_ip4_arp_event_t * mp)
934 vat_main_t * vam = &vat_main;
935 errmsg ("arp event: address %U new mac %U sw_if_index %d\n",
936 format_ip4_address, &mp->address,
937 format_ethernet_address, mp->new_mac, mp->sw_if_index);
940 static void vl_api_ip4_arp_event_t_handler_json
941 (vl_api_ip4_arp_event_t * mp)
943 /* JSON output not supported */
947 * Special-case: build the bridge domain table, maintain
948 * the next bd id vbl.
950 static void vl_api_bridge_domain_details_t_handler
951 (vl_api_bridge_domain_details_t * mp)
953 vat_main_t * vam = &vat_main;
954 u32 n_sw_ifs = ntohl (mp->n_sw_ifs);
956 fformat (vam->ofp, "\n%-3s %-3s %-3s %-3s %-3s %-3s\n",
957 " ID", "LRN", "FWD", "FLD", "BVI", "#IF");
959 fformat (vam->ofp, "%3d %3d %3d %3d %3d %3d\n",
960 ntohl (mp->bd_id), mp->learn, mp->forward,
961 mp->flood, ntohl (mp->bvi_sw_if_index), n_sw_ifs);
964 fformat (vam->ofp, "\n\n%s %s %s\n", "sw_if_index", "SHG",
968 static void vl_api_bridge_domain_details_t_handler_json
969 (vl_api_bridge_domain_details_t * mp)
971 vat_main_t * vam = &vat_main;
972 vat_json_node_t *node, *array = NULL;
974 if (VAT_JSON_ARRAY != vam->json_tree.type) {
975 ASSERT(VAT_JSON_NONE == vam->json_tree.type);
976 vat_json_init_array(&vam->json_tree);
978 node = vat_json_array_add(&vam->json_tree);
980 vat_json_init_object(node);
981 vat_json_object_add_uint(node, "bd_id", ntohl(mp->bd_id));
982 vat_json_object_add_uint(node, "flood", mp->flood);
983 vat_json_object_add_uint(node, "forward", mp->forward);
984 vat_json_object_add_uint(node, "learn", mp->learn);
985 vat_json_object_add_uint(node, "bvi_sw_if_index", ntohl(mp->bvi_sw_if_index));
986 vat_json_object_add_uint(node, "n_sw_ifs", ntohl(mp->n_sw_ifs));
987 array = vat_json_object_add(node, "sw_if");
988 vat_json_init_array(array);
992 * Special-case: build the bridge domain sw if table.
994 static void vl_api_bridge_domain_sw_if_details_t_handler
995 (vl_api_bridge_domain_sw_if_details_t * mp)
997 vat_main_t * vam = &vat_main;
1002 sw_if_index = ntohl (mp->sw_if_index);
1003 hash_foreach_pair (p, vam->sw_if_index_by_interface_name,
1005 if ((u32) p->value[0] == sw_if_index) {
1006 sw_if_name = (u8 *)(p->key);
1011 fformat (vam->ofp, "%7d %3d %s", sw_if_index,
1012 mp->shg, sw_if_name ? (char *)sw_if_name :
1013 "sw_if_index not found!");
1016 static void vl_api_bridge_domain_sw_if_details_t_handler_json
1017 (vl_api_bridge_domain_sw_if_details_t * mp)
1019 vat_main_t * vam = &vat_main;
1020 vat_json_node_t *node = NULL;
1021 uword last_index = 0;
1023 ASSERT(VAT_JSON_ARRAY == vam->json_tree.type);
1024 ASSERT(vec_len(vam->json_tree.array) >= 1);
1025 last_index = vec_len(vam->json_tree.array) - 1;
1026 node = &vam->json_tree.array[last_index];
1027 node = vat_json_object_get_element(node, "sw_if");
1028 ASSERT(NULL != node);
1029 node = vat_json_array_add(node);
1031 vat_json_init_object(node);
1032 vat_json_object_add_uint(node, "bd_id", ntohl(mp->bd_id));
1033 vat_json_object_add_uint(node, "sw_if_index", ntohl(mp->sw_if_index));
1034 vat_json_object_add_uint(node, "shg", mp->shg);
1037 static void vl_api_control_ping_reply_t_handler
1038 (vl_api_control_ping_reply_t * mp)
1040 vat_main_t * vam = &vat_main;
1041 i32 retval = ntohl(mp->retval);
1042 if (vam->async_mode) {
1043 vam->async_errors += (retval < 0);
1045 vam->retval = retval;
1046 vam->result_ready = 1;
1050 static void vl_api_control_ping_reply_t_handler_json
1051 (vl_api_control_ping_reply_t * mp)
1053 vat_main_t * vam = &vat_main;
1054 i32 retval = ntohl(mp->retval);
1056 if (VAT_JSON_NONE != vam->json_tree.type) {
1057 vat_json_print(vam->ofp, &vam->json_tree);
1058 vat_json_free(&vam->json_tree);
1059 vam->json_tree.type = VAT_JSON_NONE;
1062 vat_json_init_array(&vam->json_tree);
1063 vat_json_print(vam->ofp, &vam->json_tree);
1064 vam->json_tree.type = VAT_JSON_NONE;
1067 vam->retval = retval;
1068 vam->result_ready = 1;
1071 static void vl_api_l2_flags_reply_t_handler
1072 (vl_api_l2_flags_reply_t * mp)
1074 vat_main_t * vam = &vat_main;
1075 i32 retval = ntohl(mp->retval);
1076 if (vam->async_mode) {
1077 vam->async_errors += (retval < 0);
1079 vam->retval = retval;
1080 vam->result_ready = 1;
1084 static void vl_api_l2_flags_reply_t_handler_json
1085 (vl_api_l2_flags_reply_t * mp)
1087 vat_main_t * vam = &vat_main;
1088 vat_json_node_t node;
1090 vat_json_init_object(&node);
1091 vat_json_object_add_int(&node, "retval", ntohl(mp->retval));
1092 vat_json_object_add_uint(&node, "resulting_feature_bitmap", ntohl(mp->resulting_feature_bitmap));
1094 vat_json_print(vam->ofp, &node);
1095 vat_json_free(&node);
1097 vam->retval = ntohl(mp->retval);
1098 vam->result_ready = 1;
1101 static void vl_api_bridge_flags_reply_t_handler
1102 (vl_api_bridge_flags_reply_t * mp)
1104 vat_main_t * vam = &vat_main;
1105 i32 retval = ntohl(mp->retval);
1106 if (vam->async_mode) {
1107 vam->async_errors += (retval < 0);
1109 vam->retval = retval;
1110 vam->result_ready = 1;
1114 static void vl_api_bridge_flags_reply_t_handler_json
1115 (vl_api_bridge_flags_reply_t * mp)
1117 vat_main_t * vam = &vat_main;
1118 vat_json_node_t node;
1120 vat_json_init_object(&node);
1121 vat_json_object_add_int(&node, "retval", ntohl(mp->retval));
1122 vat_json_object_add_uint(&node, "resulting_feature_bitmap", ntohl(mp->resulting_feature_bitmap));
1124 vat_json_print(vam->ofp, &node);
1125 vat_json_free(&node);
1127 vam->retval = ntohl(mp->retval);
1128 vam->result_ready = 1;
1131 static void vl_api_tap_connect_reply_t_handler
1132 (vl_api_tap_connect_reply_t * mp)
1134 vat_main_t * vam = &vat_main;
1135 i32 retval = ntohl(mp->retval);
1136 if (vam->async_mode) {
1137 vam->async_errors += (retval < 0);
1139 vam->retval = retval;
1140 vam->result_ready = 1;
1144 static void vl_api_tap_connect_reply_t_handler_json
1145 (vl_api_tap_connect_reply_t * mp)
1147 vat_main_t * vam = &vat_main;
1148 vat_json_node_t node;
1150 vat_json_init_object(&node);
1151 vat_json_object_add_int(&node, "retval", ntohl(mp->retval));
1152 vat_json_object_add_uint(&node, "sw_if_index", ntohl(mp->sw_if_index));
1154 vat_json_print(vam->ofp, &node);
1155 vat_json_free(&node);
1157 vam->retval = ntohl(mp->retval);
1158 vam->result_ready = 1;
1161 static void vl_api_tap_modify_reply_t_handler
1162 (vl_api_tap_modify_reply_t * mp)
1164 vat_main_t * vam = &vat_main;
1165 i32 retval = ntohl(mp->retval);
1166 if (vam->async_mode) {
1167 vam->async_errors += (retval < 0);
1169 vam->retval = retval;
1170 vam->result_ready = 1;
1174 static void vl_api_tap_modify_reply_t_handler_json
1175 (vl_api_tap_modify_reply_t * mp)
1177 vat_main_t * vam = &vat_main;
1178 vat_json_node_t node;
1180 vat_json_init_object(&node);
1181 vat_json_object_add_int(&node, "retval", ntohl(mp->retval));
1182 vat_json_object_add_uint(&node, "sw_if_index", ntohl(mp->sw_if_index));
1184 vat_json_print(vam->ofp, &node);
1185 vat_json_free(&node);
1187 vam->retval = ntohl(mp->retval);
1188 vam->result_ready = 1;
1191 static void vl_api_tap_delete_reply_t_handler
1192 (vl_api_tap_delete_reply_t * mp)
1194 vat_main_t * vam = &vat_main;
1195 i32 retval = ntohl(mp->retval);
1196 if (vam->async_mode) {
1197 vam->async_errors += (retval < 0);
1199 vam->retval = retval;
1200 vam->result_ready = 1;
1204 static void vl_api_tap_delete_reply_t_handler_json
1205 (vl_api_tap_delete_reply_t * mp)
1207 vat_main_t * vam = &vat_main;
1208 vat_json_node_t node;
1210 vat_json_init_object(&node);
1211 vat_json_object_add_int(&node, "retval", ntohl(mp->retval));
1213 vat_json_print(vam->ofp, &node);
1214 vat_json_free(&node);
1216 vam->retval = ntohl(mp->retval);
1217 vam->result_ready = 1;
1220 static void vl_api_mpls_ethernet_add_del_tunnel_reply_t_handler
1221 (vl_api_mpls_ethernet_add_del_tunnel_reply_t * mp)
1223 vat_main_t * vam = &vat_main;
1224 i32 retval = ntohl(mp->retval);
1225 if (vam->async_mode) {
1226 vam->async_errors += (retval < 0);
1228 vam->retval = retval;
1229 vam->result_ready = 1;
1233 static void vl_api_mpls_ethernet_add_del_tunnel_reply_t_handler_json
1234 (vl_api_mpls_ethernet_add_del_tunnel_reply_t * mp)
1236 vat_main_t * vam = &vat_main;
1237 vat_json_node_t node;
1239 vat_json_init_object(&node);
1240 vat_json_object_add_int(&node, "retval", ntohl(mp->retval));
1241 vat_json_object_add_uint(&node, "tunnel_sw_if_index", ntohl(mp->tunnel_sw_if_index));
1243 vat_json_print(vam->ofp, &node);
1244 vat_json_free(&node);
1246 vam->retval = ntohl(mp->retval);
1247 vam->result_ready = 1;
1250 static void vl_api_l2tpv3_create_tunnel_reply_t_handler
1251 (vl_api_l2tpv3_create_tunnel_reply_t * mp)
1253 vat_main_t * vam = &vat_main;
1254 i32 retval = ntohl(mp->retval);
1255 if (vam->async_mode) {
1256 vam->async_errors += (retval < 0);
1258 vam->retval = retval;
1259 vam->result_ready = 1;
1263 static void vl_api_l2tpv3_create_tunnel_reply_t_handler_json
1264 (vl_api_l2tpv3_create_tunnel_reply_t * mp)
1266 vat_main_t * vam = &vat_main;
1267 vat_json_node_t node;
1269 vat_json_init_object(&node);
1270 vat_json_object_add_int(&node, "retval", ntohl(mp->retval));
1271 vat_json_object_add_uint(&node, "sw_if_index", ntohl(mp->sw_if_index));
1273 vat_json_print(vam->ofp, &node);
1274 vat_json_free(&node);
1276 vam->retval = ntohl(mp->retval);
1277 vam->result_ready = 1;
1280 static void vl_api_vxlan_add_del_tunnel_reply_t_handler
1281 (vl_api_vxlan_add_del_tunnel_reply_t * mp)
1283 vat_main_t * vam = &vat_main;
1284 i32 retval = ntohl(mp->retval);
1285 if (vam->async_mode) {
1286 vam->async_errors += (retval < 0);
1288 vam->retval = retval;
1289 vam->result_ready = 1;
1293 static void vl_api_vxlan_add_del_tunnel_reply_t_handler_json
1294 (vl_api_vxlan_add_del_tunnel_reply_t * mp)
1296 vat_main_t * vam = &vat_main;
1297 vat_json_node_t node;
1299 vat_json_init_object(&node);
1300 vat_json_object_add_int(&node, "retval", ntohl(mp->retval));
1301 vat_json_object_add_uint(&node, "sw_if_index", ntohl(mp->sw_if_index));
1303 vat_json_print(vam->ofp, &node);
1304 vat_json_free(&node);
1306 vam->retval = ntohl(mp->retval);
1307 vam->result_ready = 1;
1310 static void vl_api_create_vhost_user_if_reply_t_handler
1311 (vl_api_create_vhost_user_if_reply_t * mp)
1313 vat_main_t * vam = &vat_main;
1314 i32 retval = ntohl(mp->retval);
1315 if (vam->async_mode) {
1316 vam->async_errors += (retval < 0);
1318 vam->retval = retval;
1319 vam->result_ready = 1;
1323 static void vl_api_create_vhost_user_if_reply_t_handler_json
1324 (vl_api_create_vhost_user_if_reply_t * mp)
1326 vat_main_t * vam = &vat_main;
1327 vat_json_node_t node;
1329 vat_json_init_object(&node);
1330 vat_json_object_add_int(&node, "retval", ntohl(mp->retval));
1331 vat_json_object_add_uint(&node, "sw_if_index", ntohl(mp->sw_if_index));
1333 vat_json_print(vam->ofp, &node);
1334 vat_json_free(&node);
1336 vam->retval = ntohl(mp->retval);
1337 vam->result_ready = 1;
1340 static void vl_api_ip_address_details_t_handler
1341 (vl_api_ip_address_details_t * mp)
1343 vat_main_t * vam = &vat_main;
1344 static ip_address_details_t empty_ip_address_details = {{0}};
1345 ip_address_details_t * address = NULL;
1346 ip_details_t * current_ip_details = NULL;
1347 ip_details_t * details = NULL;
1349 details = vam->ip_details_by_sw_if_index[vam->is_ipv6];
1351 if (!details || vam->current_sw_if_index >= vec_len(details)
1352 || !details[vam->current_sw_if_index].present) {
1353 errmsg ("ip address details arrived but not stored\n");
1354 errmsg ("ip_dump should be called first\n");
1358 current_ip_details = vec_elt_at_index(details,
1359 vam->current_sw_if_index);
1361 #define addresses (current_ip_details->addr)
1363 vec_validate_init_empty(addresses, vec_len(addresses),
1364 empty_ip_address_details);
1366 address = vec_elt_at_index(addresses, vec_len(addresses) - 1);
1368 memcpy(&address->ip, &mp->ip, sizeof(address->ip));
1369 address->prefix_length = mp->prefix_length;
1373 static void vl_api_ip_address_details_t_handler_json
1374 (vl_api_ip_address_details_t * mp)
1376 vat_main_t * vam = &vat_main;
1377 vat_json_node_t *node = NULL;
1378 struct in6_addr ip6;
1381 if (VAT_JSON_ARRAY != vam->json_tree.type) {
1382 ASSERT(VAT_JSON_NONE == vam->json_tree.type);
1383 vat_json_init_array(&vam->json_tree);
1385 node = vat_json_array_add(&vam->json_tree);
1387 vat_json_init_object(node);
1389 memcpy(&ip6, mp->ip, sizeof(ip6));
1390 vat_json_object_add_ip6(node, "ip", ip6);
1392 memcpy(&ip4, mp->ip, sizeof(ip4));
1393 vat_json_object_add_ip4(node, "ip", ip4);
1395 vat_json_object_add_uint(node, "prefix_length", mp->prefix_length);
1398 static void vl_api_ip_details_t_handler (vl_api_ip_details_t * mp)
1400 vat_main_t * vam = &vat_main;
1401 static ip_details_t empty_ip_details = {0};
1402 ip_details_t * ip = NULL;
1403 u32 sw_if_index = ~0;
1405 sw_if_index = ntohl(mp->sw_if_index);
1407 vec_validate_init_empty(vam->ip_details_by_sw_if_index[vam->is_ipv6],
1408 sw_if_index, empty_ip_details);
1410 ip = vec_elt_at_index(vam->ip_details_by_sw_if_index[vam->is_ipv6],
1416 static void vl_api_ip_details_t_handler_json (vl_api_ip_details_t * mp)
1418 vat_main_t * vam = &vat_main;
1420 if (VAT_JSON_ARRAY != vam->json_tree.type) {
1421 ASSERT(VAT_JSON_NONE == vam->json_tree.type);
1422 vat_json_init_array(&vam->json_tree);
1424 vat_json_array_add_uint(&vam->json_tree, clib_net_to_host_u32(mp->sw_if_index));
1427 static void vl_api_map_domain_details_t_handler_json
1428 (vl_api_map_domain_details_t * mp)
1430 vat_json_node_t * node = NULL;
1431 vat_main_t * vam = &vat_main;
1432 struct in6_addr ip6;
1435 if (VAT_JSON_ARRAY != vam->json_tree.type) {
1436 ASSERT(VAT_JSON_NONE == vam->json_tree.type);
1437 vat_json_init_array(&vam->json_tree);
1440 node = vat_json_array_add(&vam->json_tree);
1441 vat_json_init_object(node);
1443 vat_json_object_add_uint(node, "domain_index", clib_net_to_host_u32(mp->domain_index));
1444 memcpy(&ip6, mp->ip6_prefix, sizeof(ip6));
1445 vat_json_object_add_ip6(node, "ip6_prefix", ip6);
1446 memcpy(&ip4, mp->ip4_prefix, sizeof(ip4));
1447 vat_json_object_add_ip4(node, "ip4_prefix", ip4);
1448 memcpy(&ip6, mp->ip6_src, sizeof(ip6));
1449 vat_json_object_add_ip6(node, "ip6_src", ip6);
1450 vat_json_object_add_int(node, "ip6_prefix_len", mp->ip6_prefix_len);
1451 vat_json_object_add_int(node, "ip4_prefix_len", mp->ip4_prefix_len);
1452 vat_json_object_add_int(node, "ip6_src_len", mp->ip6_src_len);
1453 vat_json_object_add_int(node, "ea_bits_len", mp->ea_bits_len);
1454 vat_json_object_add_int(node, "psid_offset", mp->psid_offset);
1455 vat_json_object_add_int(node, "psid_length", mp->psid_length);
1456 vat_json_object_add_uint(node, "flags", mp->flags);
1457 vat_json_object_add_uint(node, "mtu", clib_net_to_host_u16(mp->mtu));
1458 vat_json_object_add_int(node, "is_translation", mp->is_translation);
1461 static void vl_api_map_domain_details_t_handler
1462 (vl_api_map_domain_details_t * mp)
1464 vat_main_t * vam = &vat_main;
1466 if (mp->is_translation) {
1467 fformat(vam->ofp, "* %U/%d (ipv4-prefix) %U/%d (ipv6-prefix) %U/%d (ip6-src) index: %u\n",
1468 format_ip4_address, mp->ip4_prefix, mp->ip4_prefix_len,
1469 format_ip6_address, mp->ip6_prefix, mp->ip6_prefix_len,
1470 format_ip6_address, mp->ip6_src, mp->ip6_src_len, clib_net_to_host_u32(mp->domain_index));
1472 fformat(vam->ofp, "* %U/%d (ipv4-prefix) %U/%d (ipv6-prefix) %U (ip6-src) index: %u\n",
1473 format_ip4_address, mp->ip4_prefix, mp->ip4_prefix_len,
1474 format_ip6_address, mp->ip6_prefix, mp->ip6_prefix_len,
1475 format_ip6_address, mp->ip6_src, clib_net_to_host_u32(mp->domain_index));
1477 fformat(vam->ofp, " ea-len %d psid-offset %d psid-len %d mtu %d %s\n",
1478 mp->ea_bits_len, mp->psid_offset, mp->psid_length, mp->mtu, mp->is_translation? "map-t":"");
1481 static void vl_api_map_rule_details_t_handler_json
1482 (vl_api_map_rule_details_t * mp)
1484 struct in6_addr ip6;
1485 vat_json_node_t * node = NULL;
1486 vat_main_t * vam = &vat_main;
1488 if (VAT_JSON_ARRAY != vam->json_tree.type) {
1489 ASSERT(VAT_JSON_NONE == vam->json_tree.type);
1490 vat_json_init_array(&vam->json_tree);
1493 node = vat_json_array_add(&vam->json_tree);
1494 vat_json_init_object(node);
1496 vat_json_object_add_uint(node, "psid", clib_net_to_host_u16(mp->psid));
1497 memcpy(&ip6, mp->ip6_dst, sizeof(ip6));
1498 vat_json_object_add_ip6(node, "ip6_dst", ip6);
1501 static void vl_api_map_rule_details_t_handler
1502 (vl_api_map_rule_details_t * mp)
1504 vat_main_t * vam = &vat_main;
1505 fformat(vam->ofp, " %d (psid) %U (ip6-dst)\n", clib_net_to_host_u16(mp->psid),
1506 format_ip6_address, mp->ip6_dst);
1509 static void vl_api_dhcp_compl_event_t_handler
1510 (vl_api_dhcp_compl_event_t * mp)
1512 vat_main_t * vam = &vat_main;
1513 errmsg ("DHCP compl event: pid %d %s hostname %s host_addr %U "
1514 "router_addr %U host_mac %U\n",
1515 mp->pid, mp->is_ipv6 ? "ipv6":"ipv4", mp->hostname,
1516 format_ip4_address, &mp->host_address,
1517 format_ip4_address, &mp->router_address,
1518 format_ethernet_address, mp->host_mac);
1521 static void vl_api_dhcp_compl_event_t_handler_json
1522 (vl_api_dhcp_compl_event_t * mp)
1524 /* JSON output not supported */
1527 static void set_simple_interface_counter (u8 vnet_counter_type, u32 sw_if_index,
1530 vat_main_t * vam = &vat_main;
1531 static u64 default_counter = 0;
1533 vec_validate_init_empty(vam->simple_interface_counters, vnet_counter_type, NULL);
1534 vec_validate_init_empty(vam->simple_interface_counters[vnet_counter_type],
1535 sw_if_index, default_counter);
1536 vam->simple_interface_counters[vnet_counter_type][sw_if_index] = counter;
1539 static void set_combined_interface_counter (u8 vnet_counter_type, u32 sw_if_index,
1540 interface_counter_t counter)
1542 vat_main_t * vam = &vat_main;
1543 static interface_counter_t default_counter = {0, };
1545 vec_validate_init_empty(vam->combined_interface_counters, vnet_counter_type, NULL);
1546 vec_validate_init_empty(vam->combined_interface_counters[vnet_counter_type],
1547 sw_if_index, default_counter);
1548 vam->combined_interface_counters[vnet_counter_type][sw_if_index] = counter;
1551 static void vl_api_vnet_interface_counters_t_handler
1552 (vl_api_vnet_interface_counters_t *mp)
1557 static void vl_api_vnet_interface_counters_t_handler_json
1558 (vl_api_vnet_interface_counters_t *mp)
1560 interface_counter_t counter;
1565 u32 first_sw_if_index;
1568 count = ntohl(mp->count);
1569 first_sw_if_index = ntohl(mp->first_sw_if_index);
1571 if (!mp->is_combined) {
1572 v_packets = (u64*)&mp->data;
1573 for (i = 0; i < count; i++) {
1574 packets = clib_net_to_host_u64(clib_mem_unaligned(v_packets, u64));
1575 set_simple_interface_counter(mp->vnet_counter_type,
1576 first_sw_if_index + i, packets);
1580 v = (vlib_counter_t*)&mp->data;
1581 for (i = 0; i < count; i++) {
1582 counter.packets = clib_net_to_host_u64(
1583 clib_mem_unaligned(&v->packets, u64));
1584 counter.bytes = clib_net_to_host_u64(
1585 clib_mem_unaligned(&v->bytes, u64));
1586 set_combined_interface_counter(mp->vnet_counter_type,
1587 first_sw_if_index + i, counter);
1593 static u32 ip4_fib_counters_get_vrf_index_by_vrf_id (u32 vrf_id)
1595 vat_main_t * vam = &vat_main;
1598 for (i = 0; i < vec_len(vam->ip4_fib_counters_vrf_id_by_index); i++) {
1599 if (vam->ip4_fib_counters_vrf_id_by_index[i] == vrf_id) {
1606 static u32 ip6_fib_counters_get_vrf_index_by_vrf_id (u32 vrf_id)
1608 vat_main_t * vam = &vat_main;
1611 for (i = 0; i < vec_len(vam->ip6_fib_counters_vrf_id_by_index); i++) {
1612 if (vam->ip6_fib_counters_vrf_id_by_index[i] == vrf_id) {
1619 static void vl_api_vnet_ip4_fib_counters_t_handler
1620 (vl_api_vnet_ip4_fib_counters_t *mp)
1625 static void vl_api_vnet_ip4_fib_counters_t_handler_json
1626 (vl_api_vnet_ip4_fib_counters_t *mp)
1628 vat_main_t * vam = &vat_main;
1629 vl_api_ip4_fib_counter_t *v;
1630 ip4_fib_counter_t *counter;
1637 vrf_id = ntohl(mp->vrf_id);
1638 vrf_index = ip4_fib_counters_get_vrf_index_by_vrf_id(vrf_id);
1639 if (~0 == vrf_index) {
1640 vrf_index = vec_len(vam->ip4_fib_counters_vrf_id_by_index);
1641 vec_validate(vam->ip4_fib_counters_vrf_id_by_index, vrf_index);
1642 vam->ip4_fib_counters_vrf_id_by_index[vrf_index] = vrf_id;
1643 vec_validate(vam->ip4_fib_counters, vrf_index);
1644 vam->ip4_fib_counters[vrf_index] = NULL;
1647 vec_free(vam->ip4_fib_counters[vrf_index]);
1648 v = (vl_api_ip4_fib_counter_t*)&mp->c;
1649 count = ntohl(mp->count);
1650 for (i = 0; i < count; i++) {
1651 vec_validate(vam->ip4_fib_counters[vrf_index], i);
1652 counter = &vam->ip4_fib_counters[vrf_index][i];
1653 memcpy(&ip4, &v->address, sizeof(ip4));
1654 counter->address = ip4;
1655 counter->address_length = v->address_length;
1656 counter->packets = clib_net_to_host_u64(v->packets);
1657 counter->bytes = clib_net_to_host_u64(v->bytes);
1662 static void vl_api_vnet_ip6_fib_counters_t_handler
1663 (vl_api_vnet_ip6_fib_counters_t *mp)
1668 static void vl_api_vnet_ip6_fib_counters_t_handler_json
1669 (vl_api_vnet_ip6_fib_counters_t *mp)
1671 vat_main_t * vam = &vat_main;
1672 vl_api_ip6_fib_counter_t *v;
1673 ip6_fib_counter_t *counter;
1674 struct in6_addr ip6;
1680 vrf_id = ntohl(mp->vrf_id);
1681 vrf_index = ip6_fib_counters_get_vrf_index_by_vrf_id(vrf_id);
1682 if (~0 == vrf_index) {
1683 vrf_index = vec_len(vam->ip6_fib_counters_vrf_id_by_index);
1684 vec_validate(vam->ip6_fib_counters_vrf_id_by_index, vrf_index);
1685 vam->ip6_fib_counters_vrf_id_by_index[vrf_index] = vrf_id;
1686 vec_validate(vam->ip6_fib_counters, vrf_index);
1687 vam->ip6_fib_counters[vrf_index] = NULL;
1690 vec_free(vam->ip6_fib_counters[vrf_index]);
1691 v = (vl_api_ip6_fib_counter_t*)&mp->c;
1692 count = ntohl(mp->count);
1693 for (i = 0; i < count; i++) {
1694 vec_validate(vam->ip6_fib_counters[vrf_index], i);
1695 counter = &vam->ip6_fib_counters[vrf_index][i];
1696 memcpy(&ip6, &v->address, sizeof(ip6));
1697 counter->address = ip6;
1698 counter->address_length = v->address_length;
1699 counter->packets = clib_net_to_host_u64(v->packets);
1700 counter->bytes = clib_net_to_host_u64(v->bytes);
1705 static void vl_api_get_first_msg_id_reply_t_handler
1706 (vl_api_get_first_msg_id_reply_t * mp)
1708 vat_main_t * vam = &vat_main;
1709 i32 retval = ntohl(mp->retval);
1711 if (vam->async_mode) {
1712 vam->async_errors += (retval < 0);
1714 vam->retval = retval;
1715 vam->result_ready = 1;
1718 errmsg ("first message id %d\n", ntohs(mp->first_msg_id));
1722 static void vl_api_get_first_msg_id_reply_t_handler_json
1723 (vl_api_get_first_msg_id_reply_t * mp)
1725 vat_main_t * vam = &vat_main;
1726 vat_json_node_t node;
1728 vat_json_init_object(&node);
1729 vat_json_object_add_int(&node, "retval", ntohl(mp->retval));
1730 vat_json_object_add_uint(&node, "first_msg_id",
1731 (uint) ntohs(mp->first_msg_id));
1733 vat_json_print(vam->ofp, &node);
1734 vat_json_free(&node);
1736 vam->retval = ntohl(mp->retval);
1737 vam->result_ready = 1;
1740 static void vl_api_get_node_graph_reply_t_handler
1741 (vl_api_get_node_graph_reply_t * mp)
1743 vat_main_t * vam = &vat_main;
1744 api_main_t * am = &api_main;
1745 i32 retval = ntohl(mp->retval);
1746 u8 * pvt_copy, * reply;
1751 if (vam->async_mode) {
1752 vam->async_errors += (retval < 0);
1754 vam->retval = retval;
1755 vam->result_ready = 1;
1758 /* "Should never happen..." */
1762 reply = (u8 *)(mp->reply_in_shmem);
1763 pvt_copy = vec_dup (reply);
1765 /* Toss the shared-memory original... */
1766 pthread_mutex_lock (&am->vlib_rp->mutex);
1767 oldheap = svm_push_data_heap (am->vlib_rp);
1771 svm_pop_heap (oldheap);
1772 pthread_mutex_unlock (&am->vlib_rp->mutex);
1774 if (vam->graph_nodes) {
1775 hash_free (vam->graph_node_index_by_name);
1777 for (i = 0; i < vec_len (vam->graph_nodes); i++) {
1778 node = vam->graph_nodes[i];
1779 vec_free (node->name);
1780 vec_free (node->next_nodes);
1783 vec_free(vam->graph_nodes);
1786 vam->graph_node_index_by_name = hash_create_string (0, sizeof(uword));
1787 vam->graph_nodes = vlib_node_unserialize (pvt_copy);
1788 vec_free (pvt_copy);
1790 for (i = 0; i < vec_len (vam->graph_nodes); i++) {
1791 node = vam->graph_nodes[i];
1792 hash_set_mem (vam->graph_node_index_by_name, node->name, i);
1796 static void vl_api_get_node_graph_reply_t_handler_json
1797 (vl_api_get_node_graph_reply_t * mp)
1799 vat_main_t * vam = &vat_main;
1800 api_main_t * am = &api_main;
1802 vat_json_node_t node;
1805 /* $$$$ make this real? */
1806 vat_json_init_object(&node);
1807 vat_json_object_add_int(&node, "retval", ntohl(mp->retval));
1808 vat_json_object_add_uint(&node, "reply_in_shmem", mp->reply_in_shmem);
1810 reply = (u8 *)(mp->reply_in_shmem);
1812 /* Toss the shared-memory original... */
1813 pthread_mutex_lock (&am->vlib_rp->mutex);
1814 oldheap = svm_push_data_heap (am->vlib_rp);
1818 svm_pop_heap (oldheap);
1819 pthread_mutex_unlock (&am->vlib_rp->mutex);
1821 vat_json_print(vam->ofp, &node);
1822 vat_json_free(&node);
1824 vam->retval = ntohl(mp->retval);
1825 vam->result_ready = 1;
1828 #define vl_api_vnet_ip4_fib_counters_t_endian vl_noop_handler
1829 #define vl_api_vnet_ip4_fib_counters_t_print vl_noop_handler
1830 #define vl_api_vnet_ip6_fib_counters_t_endian vl_noop_handler
1831 #define vl_api_vnet_ip6_fib_counters_t_print vl_noop_handler
1834 * Generate boilerplate reply handlers, which
1835 * dig the return value out of the xxx_reply_t API message,
1836 * stick it into vam->retval, and set vam->result_ready
1838 * Could also do this by pointing N message decode slots at
1839 * a single function, but that could break in subtle ways.
1842 #define foreach_standard_reply_retval_handler \
1843 _(sw_interface_set_flags_reply) \
1844 _(sw_interface_add_del_address_reply) \
1845 _(sw_interface_set_table_reply) \
1846 _(sw_interface_set_vpath_reply) \
1847 _(sw_interface_set_l2_bridge_reply) \
1848 _(bridge_domain_add_del_reply) \
1849 _(sw_interface_set_l2_xconnect_reply) \
1850 _(l2fib_add_del_reply) \
1851 _(ip_add_del_route_reply) \
1852 _(proxy_arp_add_del_reply) \
1853 _(proxy_arp_intfc_enable_disable_reply) \
1854 _(mpls_add_del_encap_reply) \
1855 _(mpls_add_del_decap_reply) \
1856 _(mpls_ethernet_add_del_tunnel_2_reply) \
1857 _(sw_interface_set_unnumbered_reply) \
1858 _(ip_neighbor_add_del_reply) \
1859 _(reset_vrf_reply) \
1860 _(oam_add_del_reply) \
1861 _(reset_fib_reply) \
1862 _(dhcp_proxy_config_reply) \
1863 _(dhcp_proxy_config_2_reply) \
1864 _(dhcp_proxy_set_vss_reply) \
1865 _(dhcp_client_config_reply) \
1866 _(set_ip_flow_hash_reply) \
1867 _(sw_interface_ip6_enable_disable_reply) \
1868 _(sw_interface_ip6_set_link_local_address_reply) \
1869 _(sw_interface_ip6nd_ra_prefix_reply) \
1870 _(sw_interface_ip6nd_ra_config_reply) \
1871 _(set_arp_neighbor_limit_reply) \
1872 _(l2_patch_add_del_reply) \
1873 _(sr_tunnel_add_del_reply) \
1874 _(classify_add_del_session_reply) \
1875 _(classify_set_interface_ip_table_reply) \
1876 _(classify_set_interface_l2_tables_reply) \
1877 _(l2tpv3_set_tunnel_cookies_reply) \
1878 _(l2tpv3_interface_enable_disable_reply) \
1879 _(l2tpv3_set_lookup_key_reply) \
1880 _(l2_fib_clear_table_reply) \
1881 _(l2_interface_efp_filter_reply) \
1882 _(l2_interface_vlan_tag_rewrite_reply) \
1883 _(modify_vhost_user_if_reply) \
1884 _(delete_vhost_user_if_reply) \
1885 _(want_ip4_arp_events_reply) \
1886 _(input_acl_set_interface_reply) \
1887 _(ipsec_spd_add_del_reply) \
1888 _(ipsec_interface_add_del_spd_reply) \
1889 _(ipsec_spd_add_del_entry_reply) \
1890 _(ipsec_sad_add_del_entry_reply) \
1891 _(ipsec_sa_set_key_reply) \
1892 _(delete_loopback_reply) \
1893 _(bd_ip_mac_add_del_reply) \
1894 _(map_del_domain_reply) \
1895 _(map_add_del_rule_reply) \
1896 _(want_interface_events_reply) \
1897 _(want_stats_reply) \
1898 _(cop_interface_enable_disable_reply) \
1899 _(cop_whitelist_enable_disable_reply)
1902 static void vl_api_##n##_t_handler \
1903 (vl_api_##n##_t * mp) \
1905 vat_main_t * vam = &vat_main; \
1906 i32 retval = ntohl(mp->retval); \
1907 if (vam->async_mode) { \
1908 vam->async_errors += (retval < 0); \
1910 vam->retval = retval; \
1911 vam->result_ready = 1; \
1914 foreach_standard_reply_retval_handler;
1918 static void vl_api_##n##_t_handler_json \
1919 (vl_api_##n##_t * mp) \
1921 vat_main_t * vam = &vat_main; \
1922 vat_json_node_t node; \
1923 vat_json_init_object(&node); \
1924 vat_json_object_add_int(&node, "retval", ntohl(mp->retval)); \
1925 vat_json_print(vam->ofp, &node); \
1926 vam->retval = ntohl(mp->retval); \
1927 vam->result_ready = 1; \
1929 foreach_standard_reply_retval_handler;
1933 * Table of message reply handlers, must include boilerplate handlers
1937 #define foreach_vpe_api_reply_msg \
1938 _(CREATE_LOOPBACK_REPLY, create_loopback_reply) \
1939 _(SW_INTERFACE_DETAILS, sw_interface_details) \
1940 _(SW_INTERFACE_SET_FLAGS, sw_interface_set_flags) \
1941 _(SW_INTERFACE_SET_FLAGS_REPLY, sw_interface_set_flags_reply) \
1942 _(CONTROL_PING_REPLY, control_ping_reply) \
1943 _(CLI_REPLY, cli_reply) \
1944 _(SW_INTERFACE_ADD_DEL_ADDRESS_REPLY, \
1945 sw_interface_add_del_address_reply) \
1946 _(SW_INTERFACE_SET_TABLE_REPLY, sw_interface_set_table_reply) \
1947 _(SW_INTERFACE_SET_VPATH_REPLY, sw_interface_set_vpath_reply) \
1948 _(SW_INTERFACE_SET_L2_XCONNECT_REPLY, \
1949 sw_interface_set_l2_xconnect_reply) \
1950 _(SW_INTERFACE_SET_L2_BRIDGE_REPLY, \
1951 sw_interface_set_l2_bridge_reply) \
1952 _(BRIDGE_DOMAIN_ADD_DEL_REPLY, bridge_domain_add_del_reply) \
1953 _(BRIDGE_DOMAIN_DETAILS, bridge_domain_details) \
1954 _(BRIDGE_DOMAIN_SW_IF_DETAILS, bridge_domain_sw_if_details) \
1955 _(L2FIB_ADD_DEL_REPLY, l2fib_add_del_reply) \
1956 _(L2_FLAGS_REPLY, l2_flags_reply) \
1957 _(BRIDGE_FLAGS_REPLY, bridge_flags_reply) \
1958 _(TAP_CONNECT_REPLY, tap_connect_reply) \
1959 _(TAP_MODIFY_REPLY, tap_modify_reply) \
1960 _(TAP_DELETE_REPLY, tap_delete_reply) \
1961 _(SW_INTERFACE_TAP_DETAILS, sw_interface_tap_details) \
1962 _(IP_ADD_DEL_ROUTE_REPLY, ip_add_del_route_reply) \
1963 _(PROXY_ARP_ADD_DEL_REPLY, proxy_arp_add_del_reply) \
1964 _(PROXY_ARP_INTFC_ENABLE_DISABLE_REPLY, \
1965 proxy_arp_intfc_enable_disable_reply) \
1966 _(MPLS_ADD_DEL_ENCAP_REPLY, mpls_add_del_encap_reply) \
1967 _(MPLS_ADD_DEL_DECAP_REPLY, mpls_add_del_decap_reply) \
1968 _(MPLS_GRE_ADD_DEL_TUNNEL_REPLY, mpls_gre_add_del_tunnel_reply) \
1969 _(MPLS_ETHERNET_ADD_DEL_TUNNEL_REPLY, \
1970 mpls_ethernet_add_del_tunnel_reply) \
1971 _(MPLS_ETHERNET_ADD_DEL_TUNNEL_2_REPLY, \
1972 mpls_ethernet_add_del_tunnel_2_reply) \
1973 _(SW_INTERFACE_SET_UNNUMBERED_REPLY, \
1974 sw_interface_set_unnumbered_reply) \
1975 _(IP_NEIGHBOR_ADD_DEL_REPLY, ip_neighbor_add_del_reply) \
1976 _(RESET_VRF_REPLY, reset_vrf_reply) \
1977 _(CREATE_VLAN_SUBIF_REPLY, create_vlan_subif_reply) \
1978 _(CREATE_SUBIF_REPLY, create_subif_reply) \
1979 _(OAM_ADD_DEL_REPLY, oam_add_del_reply) \
1980 _(RESET_FIB_REPLY, reset_fib_reply) \
1981 _(DHCP_PROXY_CONFIG_REPLY, dhcp_proxy_config_reply) \
1982 _(DHCP_PROXY_CONFIG_2_REPLY, dhcp_proxy_config_2_reply) \
1983 _(DHCP_PROXY_SET_VSS_REPLY, dhcp_proxy_set_vss_reply) \
1984 _(DHCP_CLIENT_CONFIG_REPLY, dhcp_client_config_reply) \
1985 _(SET_IP_FLOW_HASH_REPLY, set_ip_flow_hash_reply) \
1986 _(SW_INTERFACE_IP6_ENABLE_DISABLE_REPLY, \
1987 sw_interface_ip6_enable_disable_reply) \
1988 _(SW_INTERFACE_IP6_SET_LINK_LOCAL_ADDRESS_REPLY, \
1989 sw_interface_ip6_set_link_local_address_reply) \
1990 _(SW_INTERFACE_IP6ND_RA_PREFIX_REPLY, \
1991 sw_interface_ip6nd_ra_prefix_reply) \
1992 _(SW_INTERFACE_IP6ND_RA_CONFIG_REPLY, \
1993 sw_interface_ip6nd_ra_config_reply) \
1994 _(SET_ARP_NEIGHBOR_LIMIT_REPLY, set_arp_neighbor_limit_reply) \
1995 _(L2_PATCH_ADD_DEL_REPLY, l2_patch_add_del_reply) \
1996 _(SR_TUNNEL_ADD_DEL_REPLY, sr_tunnel_add_del_reply) \
1997 _(CLASSIFY_ADD_DEL_TABLE_REPLY, classify_add_del_table_reply) \
1998 _(CLASSIFY_ADD_DEL_SESSION_REPLY, classify_add_del_session_reply) \
1999 _(CLASSIFY_SET_INTERFACE_IP_TABLE_REPLY, \
2000 classify_set_interface_ip_table_reply) \
2001 _(CLASSIFY_SET_INTERFACE_L2_TABLES_REPLY, \
2002 classify_set_interface_l2_tables_reply) \
2003 _(GET_NODE_INDEX_REPLY, get_node_index_reply) \
2004 _(ADD_NODE_NEXT_REPLY, add_node_next_reply) \
2005 _(L2TPV3_CREATE_TUNNEL_REPLY, l2tpv3_create_tunnel_reply) \
2006 _(L2TPV3_SET_TUNNEL_COOKIES_REPLY, l2tpv3_set_tunnel_cookies_reply) \
2007 _(L2TPV3_INTERFACE_ENABLE_DISABLE_REPLY, \
2008 l2tpv3_interface_enable_disable_reply) \
2009 _(L2TPV3_SET_LOOKUP_KEY_REPLY, l2tpv3_set_lookup_key_reply) \
2010 _(SW_IF_L2TPV3_TUNNEL_DETAILS, sw_if_l2tpv3_tunnel_details) \
2011 _(VXLAN_ADD_DEL_TUNNEL_REPLY, vxlan_add_del_tunnel_reply) \
2012 _(VXLAN_TUNNEL_DETAILS, vxlan_tunnel_details) \
2013 _(L2_FIB_CLEAR_TABLE_REPLY, l2_fib_clear_table_reply) \
2014 _(L2_INTERFACE_EFP_FILTER_REPLY, l2_interface_efp_filter_reply) \
2015 _(L2_INTERFACE_VLAN_TAG_REWRITE_REPLY, l2_interface_vlan_tag_rewrite_reply) \
2016 _(SW_INTERFACE_VHOST_USER_DETAILS, sw_interface_vhost_user_details) \
2017 _(CREATE_VHOST_USER_IF_REPLY, create_vhost_user_if_reply) \
2018 _(MODIFY_VHOST_USER_IF_REPLY, modify_vhost_user_if_reply) \
2019 _(DELETE_VHOST_USER_IF_REPLY, delete_vhost_user_if_reply) \
2020 _(SHOW_VERSION_REPLY, show_version_reply) \
2021 _(NSH_GRE_ADD_DEL_TUNNEL_REPLY, nsh_gre_add_del_tunnel_reply) \
2022 _(L2_FIB_TABLE_ENTRY, l2_fib_table_entry) \
2023 _(NSH_VXLAN_GPE_ADD_DEL_TUNNEL_REPLY, nsh_vxlan_gpe_add_del_tunnel_reply) \
2024 _(LISP_GPE_ADD_DEL_TUNNEL_REPLY, lisp_gpe_add_del_tunnel_reply) \
2025 _(INTERFACE_NAME_RENUMBER_REPLY, interface_name_renumber_reply) \
2026 _(WANT_IP4_ARP_EVENTS_REPLY, want_ip4_arp_events_reply) \
2027 _(IP4_ARP_EVENT, ip4_arp_event) \
2028 _(INPUT_ACL_SET_INTERFACE_REPLY, input_acl_set_interface_reply) \
2029 _(IP_ADDRESS_DETAILS, ip_address_details) \
2030 _(IP_DETAILS, ip_details) \
2031 _(IPSEC_SPD_ADD_DEL_REPLY, ipsec_spd_add_del_reply) \
2032 _(IPSEC_INTERFACE_ADD_DEL_SPD_REPLY, ipsec_interface_add_del_spd_reply) \
2033 _(IPSEC_SPD_ADD_DEL_ENTRY_REPLY, ipsec_spd_add_del_entry_reply) \
2034 _(IPSEC_SAD_ADD_DEL_ENTRY_REPLY, ipsec_sad_add_del_entry_reply) \
2035 _(IPSEC_SA_SET_KEY_REPLY, ipsec_sa_set_key_reply) \
2036 _(DELETE_LOOPBACK_REPLY, delete_loopback_reply) \
2037 _(BD_IP_MAC_ADD_DEL_REPLY, bd_ip_mac_add_del_reply) \
2038 _(DHCP_COMPL_EVENT, dhcp_compl_event) \
2039 _(VNET_INTERFACE_COUNTERS, vnet_interface_counters) \
2040 _(VNET_IP4_FIB_COUNTERS, vnet_ip4_fib_counters) \
2041 _(VNET_IP6_FIB_COUNTERS, vnet_ip6_fib_counters) \
2042 _(MAP_ADD_DOMAIN_REPLY, map_add_domain_reply) \
2043 _(MAP_DEL_DOMAIN_REPLY, map_del_domain_reply) \
2044 _(MAP_ADD_DEL_RULE_REPLY, map_add_del_rule_reply) \
2045 _(MAP_DOMAIN_DETAILS, map_domain_details) \
2046 _(MAP_RULE_DETAILS, map_rule_details) \
2047 _(WANT_INTERFACE_EVENTS_REPLY, want_interface_events_reply) \
2048 _(WANT_STATS_REPLY, want_stats_reply) \
2049 _(GET_FIRST_MSG_ID_REPLY, get_first_msg_id_reply) \
2050 _(COP_INTERFACE_ENABLE_DISABLE_REPLY, cop_interface_enable_disable_reply) \
2051 _(COP_WHITELIST_ENABLE_DISABLE_REPLY, cop_whitelist_enable_disable_reply) \
2052 _(GET_NODE_GRAPH_REPLY, get_node_graph_reply)
2054 /* M: construct, but don't yet send a message */
2058 vam->result_ready = 0; \
2059 mp = vl_msg_api_alloc(sizeof(*mp)); \
2060 memset (mp, 0, sizeof (*mp)); \
2061 mp->_vl_msg_id = ntohs (VL_API_##T); \
2062 mp->client_index = vam->my_client_index; \
2067 vam->result_ready = 0; \
2068 mp = vl_msg_api_alloc(sizeof(*mp)+(n)); \
2069 memset (mp, 0, sizeof (*mp)); \
2070 mp->_vl_msg_id = ntohs (VL_API_##T); \
2071 mp->client_index = vam->my_client_index; \
2075 /* S: send a message */
2076 #define S (vl_msg_api_send_shmem (vam->vl_input_queue, (u8 *)&mp))
2078 /* W: wait for results, with timeout */
2081 timeout = vat_time_now (vam) + 1.0; \
2083 while (vat_time_now (vam) < timeout) { \
2084 if (vam->result_ready == 1) { \
2085 return (vam->retval); \
2097 #define STR_VTR_OP_CASE(op) \
2098 case L2_VTR_ ## op: \
2101 static const char *str_vtr_op(u32 vtr_op)
2104 STR_VTR_OP_CASE(DISABLED);
2105 STR_VTR_OP_CASE(PUSH_1);
2106 STR_VTR_OP_CASE(PUSH_2);
2107 STR_VTR_OP_CASE(POP_1);
2108 STR_VTR_OP_CASE(POP_2);
2109 STR_VTR_OP_CASE(TRANSLATE_1_1);
2110 STR_VTR_OP_CASE(TRANSLATE_1_2);
2111 STR_VTR_OP_CASE(TRANSLATE_2_1);
2112 STR_VTR_OP_CASE(TRANSLATE_2_2);
2118 static int dump_sub_interface_table (vat_main_t * vam)
2120 const sw_interface_subif_t * sub = NULL;
2122 if (vam->json_output) {
2123 clib_warning ("JSON output supported only for VPE API calls and dump_stats_table");
2128 "%-30s%-12s%-11s%-7s%-5s%-9s%-9s%-6s%-8s%-10s%-10s\n",
2129 "Interface", "sw_if_index",
2130 "sub id", "dot1ad", "tags", "outer id",
2131 "inner id", "exact", "default",
2132 "outer any", "inner any");
2134 vec_foreach (sub, vam->sw_if_subif_table) {
2136 "%-30s%-12d%-11d%-7s%-5d%-9d%-9d%-6d%-8d%-10d%-10d\n",
2137 sub->interface_name,
2139 sub->sub_id, sub->sub_dot1ad ? "dot1ad" : "dot1q",
2140 sub->sub_number_of_tags, sub->sub_outer_vlan_id,
2141 sub->sub_inner_vlan_id, sub->sub_exact_match, sub->sub_default,
2142 sub->sub_outer_vlan_id_any, sub->sub_inner_vlan_id_any);
2143 if (sub->vtr_op != L2_VTR_DISABLED) {
2145 " vlan-tag-rewrite - op: %-14s [ dot1q: %d "
2146 "tag1: %d tag2: %d ]\n",
2147 str_vtr_op(sub->vtr_op), sub->vtr_push_dot1q,
2148 sub->vtr_tag1, sub->vtr_tag2);
2155 static int name_sort_cmp (void * a1, void * a2)
2157 name_sort_t * n1 = a1;
2158 name_sort_t * n2 = a2;
2160 return strcmp ((char *)n1->name, (char *)n2->name);
2163 static int dump_interface_table (vat_main_t * vam)
2166 name_sort_t * nses = 0, * ns;
2168 if (vam->json_output) {
2169 clib_warning ("JSON output supported only for VPE API calls and dump_stats_table");
2173 hash_foreach_pair (p, vam->sw_if_index_by_interface_name,
2175 vec_add2 (nses, ns, 1);
2176 ns->name = (u8 *)(p->key);
2177 ns->value = (u32) p->value[0];
2180 vec_sort_with_function (nses, name_sort_cmp);
2182 fformat (vam->ofp, "%-25s%-15s\n", "Interface", "sw_if_index");
2183 vec_foreach (ns, nses) {
2184 fformat (vam->ofp, "%-25s%-15d\n", ns->name, ns->value);
2190 static int dump_ip_table (vat_main_t * vam, int is_ipv6)
2192 const ip_details_t * det = NULL;
2193 const ip_address_details_t * address = NULL;
2200 if (0 == vam->ip_details_by_sw_if_index) {
2204 vec_foreach (det, vam->ip_details_by_sw_if_index[is_ipv6]) {
2206 if (!det->present) {
2214 "Address", "Prefix length");
2218 vec_foreach (address, det->addr) {
2221 is_ipv6 ? format_ip6_address : format_ip4_address,
2223 address->prefix_length);
2230 static int dump_ipv4_table (vat_main_t * vam)
2232 if (vam->json_output) {
2233 clib_warning ("JSON output supported only for VPE API calls and dump_stats_table");
2237 return dump_ip_table (vam, 0);
2240 static int dump_ipv6_table (vat_main_t * vam)
2242 if (vam->json_output) {
2243 clib_warning ("JSON output supported only for VPE API calls and dump_stats_table");
2247 return dump_ip_table (vam, 1);
2250 static char* counter_type_to_str (u8 counter_type, u8 is_combined)
2253 switch(counter_type) {
2254 case VNET_INTERFACE_COUNTER_DROP:
2256 case VNET_INTERFACE_COUNTER_PUNT:
2258 case VNET_INTERFACE_COUNTER_IP4:
2260 case VNET_INTERFACE_COUNTER_IP6:
2262 case VNET_INTERFACE_COUNTER_RX_NO_BUF:
2264 case VNET_INTERFACE_COUNTER_RX_MISS:
2266 case VNET_INTERFACE_COUNTER_RX_ERROR:
2268 case VNET_INTERFACE_COUNTER_TX_ERROR:
2271 return "INVALID-COUNTER-TYPE";
2274 switch(counter_type) {
2275 case VNET_INTERFACE_COUNTER_RX:
2277 case VNET_INTERFACE_COUNTER_TX:
2280 return "INVALID-COUNTER-TYPE";
2285 static int dump_stats_table (vat_main_t * vam)
2287 vat_json_node_t node;
2288 vat_json_node_t *msg_array;
2289 vat_json_node_t *msg;
2290 vat_json_node_t *counter_array;
2291 vat_json_node_t *counter;
2292 interface_counter_t c;
2294 ip4_fib_counter_t *c4;
2295 ip6_fib_counter_t *c6;
2298 if (!vam->json_output) {
2299 clib_warning ("dump_stats_table supported only in JSON format");
2303 vat_json_init_object(&node);
2305 /* interface counters */
2306 msg_array = vat_json_object_add(&node, "interface_counters");
2307 vat_json_init_array(msg_array);
2308 for (i = 0; i < vec_len(vam->simple_interface_counters); i++) {
2309 msg = vat_json_array_add(msg_array);
2310 vat_json_init_object(msg);
2311 vat_json_object_add_string_copy(msg, "vnet_counter_type",
2312 (u8*)counter_type_to_str(i, 0));
2313 vat_json_object_add_int(msg, "is_combined", 0);
2314 counter_array = vat_json_object_add(msg, "data");
2315 vat_json_init_array(counter_array);
2316 for (j = 0; j < vec_len(vam->simple_interface_counters[i]); j++) {
2317 packets = vam->simple_interface_counters[i][j];
2318 vat_json_array_add_uint(counter_array, packets);
2321 for (i = 0; i < vec_len(vam->combined_interface_counters); i++) {
2322 msg = vat_json_array_add(msg_array);
2323 vat_json_init_object(msg);
2324 vat_json_object_add_string_copy(msg, "vnet_counter_type",
2325 (u8*)counter_type_to_str(i, 1));
2326 vat_json_object_add_int(msg, "is_combined", 1);
2327 counter_array = vat_json_object_add(msg, "data");
2328 vat_json_init_array(counter_array);
2329 for (j = 0; j < vec_len(vam->combined_interface_counters[i]); j++) {
2330 c = vam->combined_interface_counters[i][j];
2331 counter = vat_json_array_add(counter_array);
2332 vat_json_init_object(counter);
2333 vat_json_object_add_uint(counter, "packets", c.packets);
2334 vat_json_object_add_uint(counter, "bytes", c.bytes);
2338 /* ip4 fib counters */
2339 msg_array = vat_json_object_add(&node, "ip4_fib_counters");
2340 vat_json_init_array(msg_array);
2341 for (i = 0; i < vec_len(vam->ip4_fib_counters); i++) {
2342 msg = vat_json_array_add(msg_array);
2343 vat_json_init_object(msg);
2344 vat_json_object_add_uint(msg, "vrf_id", vam->ip4_fib_counters_vrf_id_by_index[i]);
2345 counter_array = vat_json_object_add(msg, "c");
2346 vat_json_init_array(counter_array);
2347 for (j = 0; j < vec_len(vam->ip4_fib_counters[i]); j++) {
2348 counter = vat_json_array_add(counter_array);
2349 vat_json_init_object(counter);
2350 c4 = &vam->ip4_fib_counters[i][j];
2351 vat_json_object_add_ip4(counter, "address", c4->address);
2352 vat_json_object_add_uint(counter, "address_length", c4->address_length);
2353 vat_json_object_add_uint(counter, "packets", c4->packets);
2354 vat_json_object_add_uint(counter, "bytes", c4->bytes);
2358 /* ip6 fib counters */
2359 msg_array = vat_json_object_add(&node, "ip6_fib_counters");
2360 vat_json_init_array(msg_array);
2361 for (i = 0; i < vec_len(vam->ip6_fib_counters); i++) {
2362 msg = vat_json_array_add(msg_array);
2363 vat_json_init_object(msg);
2364 vat_json_object_add_uint(msg, "vrf_id", vam->ip6_fib_counters_vrf_id_by_index[i]);
2365 counter_array = vat_json_object_add(msg, "c");
2366 vat_json_init_array(counter_array);
2367 for (j = 0; j < vec_len(vam->ip6_fib_counters[i]); j++) {
2368 counter = vat_json_array_add(counter_array);
2369 vat_json_init_object(counter);
2370 c6 = &vam->ip6_fib_counters[i][j];
2371 vat_json_object_add_ip6(counter, "address", c6->address);
2372 vat_json_object_add_uint(counter, "address_length", c6->address_length);
2373 vat_json_object_add_uint(counter, "packets", c6->packets);
2374 vat_json_object_add_uint(counter, "bytes", c6->bytes);
2378 vat_json_print(vam->ofp, &node);
2379 vat_json_free(&node);
2384 int exec (vat_main_t * vam)
2386 api_main_t * am = &api_main;
2387 vl_api_cli_request_t *mp;
2391 unformat_input_t * i = vam->input;
2393 if (vec_len(i->buffer) == 0)
2396 if (vam->exec_mode == 0 && unformat (i, "mode")) {
2400 if (vam->exec_mode == 1 &&
2401 (unformat (i, "exit") || unformat (i, "quit"))) {
2407 M(CLI_REQUEST, cli_request);
2410 * Copy cmd into shared memory.
2411 * In order for the CLI command to work, it
2412 * must be a vector ending in \n, not a C-string ending
2415 pthread_mutex_lock (&am->vlib_rp->mutex);
2416 oldheap = svm_push_data_heap (am->vlib_rp);
2418 vec_validate (cmd, vec_len(vam->input->buffer)-1);
2419 memcpy (cmd, vam->input->buffer, vec_len(vam->input->buffer));
2421 svm_pop_heap (oldheap);
2422 pthread_mutex_unlock (&am->vlib_rp->mutex);
2424 mp->cmd_in_shmem = (u64) cmd;
2426 timeout = vat_time_now (vam) + 10.0;
2428 while (vat_time_now (vam) < timeout) {
2429 if (vam->result_ready == 1) {
2431 if (vam->shmem_result != NULL)
2432 fformat (vam->ofp, "%s", vam->shmem_result);
2433 pthread_mutex_lock (&am->vlib_rp->mutex);
2434 oldheap = svm_push_data_heap (am->vlib_rp);
2436 free_me = (u8 *)vam->shmem_result;
2439 svm_pop_heap (oldheap);
2440 pthread_mutex_unlock (&am->vlib_rp->mutex);
2447 static int api_create_loopback (vat_main_t * vam)
2449 unformat_input_t * i = vam->input;
2450 vl_api_create_loopback_t *mp;
2455 memset (mac_address, 0, sizeof (mac_address));
2457 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
2459 if (unformat (i, "mac %U", unformat_ethernet_address, mac_address))
2465 /* Construct the API message */
2466 M(CREATE_LOOPBACK, create_loopback);
2468 memcpy (mp->mac_address, mac_address, sizeof (mac_address));
2473 static int api_delete_loopback (vat_main_t * vam)
2475 unformat_input_t * i = vam->input;
2476 vl_api_delete_loopback_t *mp;
2478 u32 sw_if_index = ~0;
2480 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
2482 if (unformat (i, "sw_if_index %d", &sw_if_index))
2488 if (sw_if_index == ~0)
2490 errmsg ("missing sw_if_index\n");
2494 /* Construct the API message */
2495 M(DELETE_LOOPBACK, delete_loopback);
2496 mp->sw_if_index = ntohl (sw_if_index);
2501 static int api_want_stats (vat_main_t * vam)
2503 unformat_input_t * i = vam->input;
2504 vl_api_want_stats_t * mp;
2508 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
2510 if (unformat (i, "enable"))
2512 else if (unformat (i, "disable"))
2520 errmsg ("missing enable|disable\n");
2524 M(WANT_STATS, want_stats);
2525 mp->enable_disable = enable;
2530 static int api_want_interface_events (vat_main_t * vam)
2532 unformat_input_t * i = vam->input;
2533 vl_api_want_interface_events_t * mp;
2537 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
2539 if (unformat (i, "enable"))
2541 else if (unformat (i, "disable"))
2549 errmsg ("missing enable|disable\n");
2553 M(WANT_INTERFACE_EVENTS, want_interface_events);
2554 mp->enable_disable = enable;
2556 vam->interface_event_display = enable;
2562 /* Note: non-static, called once to set up the initial intfc table */
2563 int api_sw_interface_dump (vat_main_t * vam)
2565 vl_api_sw_interface_dump_t *mp;
2568 name_sort_t * nses = 0, * ns;
2569 sw_interface_subif_t * sub = NULL;
2571 /* Toss the old name table */
2572 hash_foreach_pair (p, vam->sw_if_index_by_interface_name,
2574 vec_add2 (nses, ns, 1);
2575 ns->name = (u8 *)(p->key);
2576 ns->value = (u32) p->value[0];
2579 hash_free (vam->sw_if_index_by_interface_name);
2581 vec_foreach (ns, nses)
2582 vec_free (ns->name);
2586 vec_foreach (sub, vam->sw_if_subif_table) {
2587 vec_free (sub->interface_name);
2589 vec_free (vam->sw_if_subif_table);
2591 /* recreate the interface name hash table */
2592 vam->sw_if_index_by_interface_name
2593 = hash_create_string (0, sizeof(uword));
2595 /* Get list of ethernets */
2596 M(SW_INTERFACE_DUMP, sw_interface_dump);
2597 mp->name_filter_valid = 1;
2598 strncpy ((char *) mp->name_filter, "Ether", sizeof(mp->name_filter-1));
2601 /* and local / loopback interfaces */
2602 M(SW_INTERFACE_DUMP, sw_interface_dump);
2603 mp->name_filter_valid = 1;
2604 strncpy ((char *) mp->name_filter, "lo", sizeof(mp->name_filter-1));
2607 /* and vxlan tunnel interfaces */
2608 M(SW_INTERFACE_DUMP, sw_interface_dump);
2609 mp->name_filter_valid = 1;
2610 strncpy ((char *) mp->name_filter, "vxlan", sizeof(mp->name_filter-1));
2613 /* and l2tpv3 tunnel interfaces */
2614 M(SW_INTERFACE_DUMP, sw_interface_dump);
2615 mp->name_filter_valid = 1;
2616 strncpy ((char *) mp->name_filter, "l2tpv3_tunnel", sizeof(mp->name_filter-1));
2619 /* Use a control ping for synchronization */
2621 vl_api_control_ping_t * mp;
2622 M(CONTROL_PING, control_ping);
2628 static int api_sw_interface_set_flags (vat_main_t * vam)
2630 unformat_input_t * i = vam->input;
2631 vl_api_sw_interface_set_flags_t *mp;
2634 u8 sw_if_index_set = 0;
2635 u8 admin_up = 0, link_up = 0;
2637 /* Parse args required to build the message */
2638 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
2639 if (unformat (i, "admin-up"))
2641 else if (unformat (i, "admin-down"))
2643 else if (unformat (i, "link-up"))
2645 else if (unformat (i, "link-down"))
2647 else if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
2648 sw_if_index_set = 1;
2649 else if (unformat (i, "sw_if_index %d", &sw_if_index))
2650 sw_if_index_set = 1;
2655 if (sw_if_index_set == 0) {
2656 errmsg ("missing interface name or sw_if_index\n");
2660 /* Construct the API message */
2661 M(SW_INTERFACE_SET_FLAGS, sw_interface_set_flags);
2662 mp->sw_if_index = ntohl (sw_if_index);
2663 mp->admin_up_down = admin_up;
2664 mp->link_up_down = link_up;
2669 /* Wait for a reply, return the good/bad news... */
2673 static int api_sw_interface_add_del_address (vat_main_t * vam)
2675 unformat_input_t * i = vam->input;
2676 vl_api_sw_interface_add_del_address_t *mp;
2679 u8 sw_if_index_set = 0;
2680 u8 is_add = 1, del_all = 0;
2681 u32 address_length = 0;
2682 u8 v4_address_set = 0;
2683 u8 v6_address_set = 0;
2684 ip4_address_t v4address;
2685 ip6_address_t v6address;
2687 /* Parse args required to build the message */
2688 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
2689 if (unformat (i, "del-all"))
2691 else if (unformat (i, "del"))
2693 else if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
2694 sw_if_index_set = 1;
2695 else if (unformat (i, "sw_if_index %d", &sw_if_index))
2696 sw_if_index_set = 1;
2697 else if (unformat (i, "%U/%d",
2698 unformat_ip4_address, &v4address,
2701 else if (unformat (i, "%U/%d",
2702 unformat_ip6_address, &v6address,
2709 if (sw_if_index_set == 0) {
2710 errmsg ("missing interface name or sw_if_index\n");
2713 if (v4_address_set && v6_address_set) {
2714 errmsg ("both v4 and v6 addresses set\n");
2717 if (!v4_address_set && !v6_address_set && !del_all) {
2718 errmsg ("no addresses set\n");
2722 /* Construct the API message */
2723 M(SW_INTERFACE_ADD_DEL_ADDRESS, sw_interface_add_del_address);
2725 mp->sw_if_index = ntohl (sw_if_index);
2726 mp->is_add = is_add;
2727 mp->del_all = del_all;
2728 if (v6_address_set) {
2730 memcpy (mp->address, &v6address, sizeof (v6address));
2732 memcpy (mp->address, &v4address, sizeof (v4address));
2734 mp->address_length = address_length;
2739 /* Wait for a reply, return good/bad news */
2743 static int api_sw_interface_set_table (vat_main_t * vam)
2745 unformat_input_t * i = vam->input;
2746 vl_api_sw_interface_set_table_t *mp;
2748 u32 sw_if_index, vrf_id = 0;
2749 u8 sw_if_index_set = 0;
2752 /* Parse args required to build the message */
2753 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
2754 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
2755 sw_if_index_set = 1;
2756 else if (unformat (i, "sw_if_index %d", &sw_if_index))
2757 sw_if_index_set = 1;
2758 else if (unformat (i, "vrf %d", &vrf_id))
2760 else if (unformat (i, "ipv6"))
2766 if (sw_if_index_set == 0) {
2767 errmsg ("missing interface name or sw_if_index\n");
2771 /* Construct the API message */
2772 M(SW_INTERFACE_SET_TABLE, sw_interface_set_table);
2774 mp->sw_if_index = ntohl (sw_if_index);
2775 mp->is_ipv6 = is_ipv6;
2776 mp->vrf_id = ntohl (vrf_id);
2781 /* Wait for a reply... */
2785 static int api_sw_interface_set_vpath (vat_main_t * vam)
2787 unformat_input_t * i = vam->input;
2788 vl_api_sw_interface_set_vpath_t *mp;
2790 u32 sw_if_index = 0;
2791 u8 sw_if_index_set = 0;
2794 /* Parse args required to build the message */
2795 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
2796 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
2797 sw_if_index_set = 1;
2798 else if (unformat (i, "sw_if_index %d", &sw_if_index))
2799 sw_if_index_set = 1;
2800 else if (unformat (i, "enable"))
2802 else if (unformat (i, "disable"))
2808 if (sw_if_index_set == 0) {
2809 errmsg ("missing interface name or sw_if_index\n");
2813 /* Construct the API message */
2814 M(SW_INTERFACE_SET_VPATH, sw_interface_set_vpath);
2816 mp->sw_if_index = ntohl (sw_if_index);
2817 mp->enable = is_enable;
2822 /* Wait for a reply... */
2826 static int api_sw_interface_set_l2_xconnect (vat_main_t * vam)
2828 unformat_input_t * i = vam->input;
2829 vl_api_sw_interface_set_l2_xconnect_t *mp;
2832 u8 rx_sw_if_index_set = 0;
2834 u8 tx_sw_if_index_set = 0;
2837 /* Parse args required to build the message */
2838 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
2839 if (unformat (i, "rx_sw_if_index %d", &rx_sw_if_index))
2840 rx_sw_if_index_set = 1;
2841 else if (unformat (i, "tx_sw_if_index %d", &tx_sw_if_index))
2842 tx_sw_if_index_set = 1;
2843 else if (unformat (i, "rx")) {
2844 if (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
2845 if (unformat (i, "%U", unformat_sw_if_index, vam,
2847 rx_sw_if_index_set = 1;
2850 } else if (unformat (i, "tx")) {
2851 if (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
2852 if (unformat (i, "%U", unformat_sw_if_index, vam,
2854 tx_sw_if_index_set = 1;
2857 } else if (unformat (i, "enable"))
2859 else if (unformat (i, "disable"))
2865 if (rx_sw_if_index_set == 0) {
2866 errmsg ("missing rx interface name or rx_sw_if_index\n");
2870 if (enable && (tx_sw_if_index_set == 0)) {
2871 errmsg ("missing tx interface name or tx_sw_if_index\n");
2875 M(SW_INTERFACE_SET_L2_XCONNECT, sw_interface_set_l2_xconnect);
2877 mp->rx_sw_if_index = ntohl(rx_sw_if_index);
2878 mp->tx_sw_if_index = ntohl(tx_sw_if_index);
2879 mp->enable = enable;
2886 static int api_sw_interface_set_l2_bridge (vat_main_t * vam)
2888 unformat_input_t * i = vam->input;
2889 vl_api_sw_interface_set_l2_bridge_t *mp;
2892 u8 rx_sw_if_index_set = 0;
2899 /* Parse args required to build the message */
2900 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
2901 if (unformat (i, "sw_if_index %d", &rx_sw_if_index))
2902 rx_sw_if_index_set = 1;
2903 else if (unformat (i, "bd_id %d", &bd_id))
2905 else if (unformat (i, "%U", unformat_sw_if_index, vam,
2907 rx_sw_if_index_set = 1;
2908 else if (unformat (i, "shg %d", &shg))
2910 else if (unformat (i, "bvi"))
2912 else if (unformat (i, "enable"))
2914 else if (unformat (i, "disable"))
2920 if (rx_sw_if_index_set == 0) {
2921 errmsg ("missing rx interface name or sw_if_index\n");
2925 if (enable && (bd_id_set == 0)) {
2926 errmsg ("missing bridge domain\n");
2930 M(SW_INTERFACE_SET_L2_BRIDGE, sw_interface_set_l2_bridge);
2932 mp->rx_sw_if_index = ntohl(rx_sw_if_index);
2933 mp->bd_id = ntohl(bd_id);
2936 mp->enable = enable;
2943 static int api_bridge_domain_dump (vat_main_t * vam)
2945 unformat_input_t * i = vam->input;
2946 vl_api_bridge_domain_dump_t *mp;
2950 /* Parse args required to build the message */
2951 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
2952 if (unformat (i, "bd_id %d", &bd_id))
2958 M(BRIDGE_DOMAIN_DUMP, bridge_domain_dump);
2959 mp->bd_id = ntohl(bd_id);
2962 /* Use a control ping for synchronization */
2964 vl_api_control_ping_t * mp;
2965 M(CONTROL_PING, control_ping);
2974 static int api_bridge_domain_add_del (vat_main_t * vam)
2976 unformat_input_t * i = vam->input;
2977 vl_api_bridge_domain_add_del_t *mp;
2981 u32 flood = 1, forward = 1, learn = 1, uu_flood = 1, arp_term = 0;
2983 /* Parse args required to build the message */
2984 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
2985 if (unformat (i, "bd_id %d", &bd_id))
2987 else if (unformat (i, "flood %d", &flood))
2989 else if (unformat (i, "uu-flood %d", &uu_flood))
2991 else if (unformat (i, "forward %d", &forward))
2993 else if (unformat (i, "learn %d", &learn))
2995 else if (unformat (i, "arp-term %d", &arp_term))
2997 else if (unformat (i, "del")) {
2999 flood = uu_flood = forward = learn = 0;
3006 errmsg ("missing bridge domain\n");
3010 M(BRIDGE_DOMAIN_ADD_DEL, bridge_domain_add_del);
3012 mp->bd_id = ntohl(bd_id);
3014 mp->uu_flood = uu_flood;
3015 mp->forward = forward;
3017 mp->arp_term = arp_term;
3018 mp->is_add = is_add;
3025 static int api_l2fib_add_del (vat_main_t * vam)
3027 unformat_input_t * i = vam->input;
3028 vl_api_l2fib_add_del_t *mp;
3035 u8 sw_if_index_set = 0;
3040 /* Parse args required to build the message */
3041 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
3042 if (unformat (i, "mac %U", unformat_ethernet_address, &mac))
3044 else if (unformat (i, "bd_id %d", &bd_id))
3046 else if (unformat (i, "sw_if_index %d", &sw_if_index))
3047 sw_if_index_set = 1;
3048 else if (unformat (i, "sw_if")) {
3049 if (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
3050 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
3051 sw_if_index_set = 1;
3054 } else if (unformat (i, "static"))
3056 else if (unformat (i, "filter")) {
3059 } else if (unformat (i, "del"))
3066 errmsg ("missing mac address\n");
3070 if (bd_id_set == 0) {
3071 errmsg ("missing bridge domain\n");
3075 if (is_add && (sw_if_index_set == 0)) {
3076 errmsg ("missing interface name or sw_if_index\n");
3080 M(L2FIB_ADD_DEL, l2fib_add_del);
3083 mp->bd_id = ntohl(bd_id);
3084 mp->is_add = is_add;
3087 mp->sw_if_index = ntohl(sw_if_index);
3088 mp->static_mac = static_mac;
3089 mp->filter_mac = filter_mac;
3097 static int api_l2_flags (vat_main_t * vam)
3099 unformat_input_t * i = vam->input;
3100 vl_api_l2_flags_t *mp;
3103 u32 feature_bitmap = 0;
3104 u8 sw_if_index_set = 0;
3106 /* Parse args required to build the message */
3107 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
3108 if (unformat (i, "sw_if_index %d", &sw_if_index))
3109 sw_if_index_set = 1;
3110 else if (unformat (i, "sw_if")) {
3111 if (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
3112 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
3113 sw_if_index_set = 1;
3116 } else if (unformat (i, "learn"))
3117 feature_bitmap |= L2INPUT_FEAT_LEARN;
3118 else if (unformat (i, "forward"))
3119 feature_bitmap |= L2INPUT_FEAT_FWD;
3120 else if (unformat (i, "flood"))
3121 feature_bitmap |= L2INPUT_FEAT_FLOOD;
3122 else if (unformat (i, "uu-flood"))
3123 feature_bitmap |= L2INPUT_FEAT_UU_FLOOD;
3128 if (sw_if_index_set == 0) {
3129 errmsg ("missing interface name or sw_if_index\n");
3133 M(L2_FLAGS, l2_flags);
3135 mp->sw_if_index = ntohl(sw_if_index);
3136 mp->feature_bitmap = ntohl(feature_bitmap);
3143 static int api_bridge_flags (vat_main_t * vam)
3145 unformat_input_t * i = vam->input;
3146 vl_api_bridge_flags_t *mp;
3153 /* Parse args required to build the message */
3154 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
3155 if (unformat (i, "bd_id %d", &bd_id))
3157 else if (unformat (i, "learn"))
3159 else if (unformat (i, "forward"))
3161 else if (unformat (i, "flood"))
3163 else if (unformat (i, "uu-flood"))
3164 flags |= L2_UU_FLOOD;
3165 else if (unformat (i, "arp-term"))
3166 flags |= L2_ARP_TERM;
3167 else if (unformat (i, "off"))
3169 else if (unformat (i, "disable"))
3175 if (bd_id_set == 0) {
3176 errmsg ("missing bridge domain\n");
3180 M(BRIDGE_FLAGS, bridge_flags);
3182 mp->bd_id = ntohl(bd_id);
3183 mp->feature_bitmap = ntohl(flags);
3184 mp->is_set = is_set;
3191 static int api_bd_ip_mac_add_del (vat_main_t * vam)
3193 unformat_input_t * i = vam->input;
3194 vl_api_bd_ip_mac_add_del_t *mp;
3202 ip4_address_t v4addr;
3203 ip6_address_t v6addr;
3207 /* Parse args required to build the message */
3208 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
3209 if (unformat (i, "bd_id %d", &bd_id)) {
3211 } else if (unformat (i, "%U", unformat_ip4_address, &v4addr)) {
3213 } else if (unformat (i, "%U", unformat_ip6_address, &v6addr)) {
3216 } else if (unformat (i, "%U", unformat_ethernet_address, macaddr)) {
3218 } else if (unformat (i, "del"))
3224 if (bd_id_set == 0) {
3225 errmsg ("missing bridge domain\n");
3227 } else if (ip_set == 0) {
3228 errmsg ("missing IP address\n");
3230 } else if (mac_set == 0) {
3231 errmsg ("missing MAC address\n");
3235 M(BD_IP_MAC_ADD_DEL, bd_ip_mac_add_del);
3237 mp->bd_id = ntohl(bd_id);
3238 mp->is_ipv6 = is_ipv6;
3239 mp->is_add = is_add;
3241 memcpy (mp->ip_address, &v6addr, sizeof (v6addr));
3242 else memcpy (mp->ip_address, &v4addr, sizeof (v4addr));
3243 memcpy (mp->mac_address, macaddr, 6);
3249 static int api_tap_connect (vat_main_t * vam)
3251 unformat_input_t * i = vam->input;
3252 vl_api_tap_connect_t *mp;
3259 memset (mac_address, 0, sizeof (mac_address));
3261 /* Parse args required to build the message */
3262 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
3263 if (unformat (i, "mac %U", unformat_ethernet_address, mac_address)) {
3266 else if (unformat (i, "random-mac"))
3268 else if (unformat (i, "tapname %s", &tap_name))
3274 if (name_set == 0) {
3275 errmsg ("missing tap name\n");
3278 if (vec_len (tap_name) > 63) {
3279 errmsg ("tap name too long\n");
3281 vec_add1 (tap_name, 0);
3283 /* Construct the API message */
3284 M(TAP_CONNECT, tap_connect);
3286 mp->use_random_mac = random_mac;
3287 memcpy (mp->mac_address, mac_address, 6);
3288 memcpy (mp->tap_name, tap_name, vec_len (tap_name));
3289 vec_free (tap_name);
3294 /* Wait for a reply... */
3298 static int api_tap_modify (vat_main_t * vam)
3300 unformat_input_t * i = vam->input;
3301 vl_api_tap_modify_t *mp;
3307 u32 sw_if_index = ~0;
3308 u8 sw_if_index_set = 0;
3310 memset (mac_address, 0, sizeof (mac_address));
3312 /* Parse args required to build the message */
3313 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
3314 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
3315 sw_if_index_set = 1;
3316 else if (unformat (i, "sw_if_index %d", &sw_if_index))
3317 sw_if_index_set = 1;
3318 else if (unformat (i, "mac %U", unformat_ethernet_address, mac_address)) {
3321 else if (unformat (i, "random-mac"))
3323 else if (unformat (i, "tapname %s", &tap_name))
3329 if (sw_if_index_set == 0) {
3330 errmsg ("missing vpp interface name");
3333 if (name_set == 0) {
3334 errmsg ("missing tap name\n");
3337 if (vec_len (tap_name) > 63) {
3338 errmsg ("tap name too long\n");
3340 vec_add1 (tap_name, 0);
3342 /* Construct the API message */
3343 M(TAP_MODIFY, tap_modify);
3345 mp->use_random_mac = random_mac;
3346 mp->sw_if_index = ntohl(sw_if_index);
3347 memcpy (mp->mac_address, mac_address, 6);
3348 memcpy (mp->tap_name, tap_name, vec_len (tap_name));
3349 vec_free (tap_name);
3354 /* Wait for a reply... */
3358 static int api_tap_delete (vat_main_t * vam)
3360 unformat_input_t * i = vam->input;
3361 vl_api_tap_delete_t *mp;
3363 u32 sw_if_index = ~0;
3364 u8 sw_if_index_set = 0;
3366 /* Parse args required to build the message */
3367 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
3368 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
3369 sw_if_index_set = 1;
3370 else if (unformat (i, "sw_if_index %d", &sw_if_index))
3371 sw_if_index_set = 1;
3376 if (sw_if_index_set == 0) {
3377 errmsg ("missing vpp interface name");
3381 /* Construct the API message */
3382 M(TAP_DELETE, tap_delete);
3384 mp->sw_if_index = ntohl(sw_if_index);
3389 /* Wait for a reply... */
3393 static int api_ip_add_del_route (vat_main_t * vam)
3395 unformat_input_t * i = vam->input;
3396 vl_api_ip_add_del_route_t *mp;
3398 u32 sw_if_index = 0, vrf_id = 0;
3399 u8 sw_if_index_set = 0;
3401 u8 is_local = 0, is_drop = 0;
3402 u8 create_vrf_if_needed = 0;
3404 u8 next_hop_weight = 1;
3406 u8 is_multipath = 0;
3408 u8 address_length_set = 0;
3409 u32 lookup_in_vrf = 0;
3410 u32 resolve_attempts = 0;
3411 u32 dst_address_length = 0;
3412 u8 next_hop_set = 0;
3413 ip4_address_t v4_dst_address, v4_next_hop_address;
3414 ip6_address_t v6_dst_address, v6_next_hop_address;
3418 u32 random_add_del = 0;
3419 u32 * random_vector = 0;
3420 uword * random_hash;
3421 u32 random_seed = 0xdeaddabe;
3422 u32 classify_table_index = ~0;
3425 /* Parse args required to build the message */
3426 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
3427 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
3428 sw_if_index_set = 1;
3429 else if (unformat (i, "sw_if_index %d", &sw_if_index))
3430 sw_if_index_set = 1;
3431 else if (unformat (i, "%U", unformat_ip4_address,
3436 else if (unformat (i, "%U", unformat_ip6_address, &v6_dst_address)) {
3440 else if (unformat (i, "/%d", &dst_address_length)) {
3441 address_length_set = 1;
3444 else if (is_ipv6 == 0 && unformat (i, "via %U", unformat_ip4_address,
3445 &v4_next_hop_address)) {
3448 else if (is_ipv6 == 1 && unformat (i, "via %U", unformat_ip6_address,
3449 &v6_next_hop_address)) {
3452 else if (unformat (i, "resolve-attempts %d", &resolve_attempts))
3454 else if (unformat (i, "weight %d", &next_hop_weight))
3456 else if (unformat (i, "drop")) {
3458 } else if (unformat (i, "local")) {
3460 } else if (unformat (i, "classify %d", &classify_table_index)) {
3462 } else if (unformat (i, "del"))
3464 else if (unformat (i, "add"))
3466 else if (unformat (i, "not-last"))
3468 else if (unformat (i, "multipath"))
3470 else if (unformat (i, "vrf %d", &vrf_id))
3472 else if (unformat (i, "create-vrf"))
3473 create_vrf_if_needed = 1;
3474 else if (unformat (i, "count %d", &count))
3476 else if (unformat (i, "lookup-in-vrf %d", &lookup_in_vrf))
3478 else if (unformat (i, "random"))
3480 else if (unformat (i, "seed %d", &random_seed))
3483 clib_warning ("parse error '%U'", format_unformat_error, i);
3488 if (resolve_attempts > 0 && sw_if_index_set == 0) {
3489 errmsg ("ARP resolution needs explicit interface or sw_if_index\n");
3493 if (!next_hop_set && !is_drop && !is_local && !is_classify) {
3494 errmsg ("next hop / local / drop / classify not set\n");
3498 if (address_set == 0) {
3499 errmsg ("missing addresses\n");
3503 if (address_length_set == 0) {
3504 errmsg ("missing address length\n");
3508 /* Generate a pile of unique, random routes */
3509 if (random_add_del) {
3510 u32 this_random_address;
3511 random_hash = hash_create (count, sizeof(uword));
3513 hash_set (random_hash, v4_next_hop_address.as_u32, 1);
3514 for (j = 0; j <= count; j++) {
3516 this_random_address = random_u32 (&random_seed);
3517 this_random_address =
3518 clib_host_to_net_u32 (this_random_address);
3519 } while (hash_get (random_hash, this_random_address));
3520 vec_add1 (random_vector, this_random_address);
3521 hash_set (random_hash, this_random_address, 1);
3523 hash_free (random_hash);
3524 v4_dst_address.as_u32 = random_vector[0];
3528 /* Turn on async mode */
3529 vam->async_mode = 1;
3530 vam->async_errors = 0;
3531 before = vat_time_now(vam);
3534 for (j = 0; j < count; j++) {
3535 /* Construct the API message */
3536 M(IP_ADD_DEL_ROUTE, ip_add_del_route);
3538 mp->next_hop_sw_if_index = ntohl (sw_if_index);
3539 mp->vrf_id = ntohl (vrf_id);
3540 if (resolve_attempts > 0) {
3541 mp->resolve_attempts = ntohl (resolve_attempts);
3542 mp->resolve_if_needed = 1;
3544 mp->create_vrf_if_needed = create_vrf_if_needed;
3546 mp->is_add = is_add;
3547 mp->is_drop = is_drop;
3548 mp->is_ipv6 = is_ipv6;
3549 mp->is_local = is_local;
3550 mp->is_classify = is_classify;
3551 mp->is_multipath = is_multipath;
3552 mp->not_last = not_last;
3553 mp->next_hop_weight = next_hop_weight;
3554 mp->dst_address_length = dst_address_length;
3555 mp->lookup_in_vrf = ntohl(lookup_in_vrf);
3556 mp->classify_table_index = ntohl(classify_table_index);
3559 memcpy (mp->dst_address, &v6_dst_address, sizeof (v6_dst_address));
3561 memcpy (mp->next_hop_address, &v6_next_hop_address,
3562 sizeof (v6_next_hop_address));
3563 increment_v6_address (&v6_dst_address);
3565 memcpy (mp->dst_address, &v4_dst_address, sizeof (v4_dst_address));
3567 memcpy (mp->next_hop_address, &v4_next_hop_address,
3568 sizeof (v4_next_hop_address));
3570 v4_dst_address.as_u32 = random_vector[j+1];
3572 increment_v4_address (&v4_dst_address);
3578 /* When testing multiple add/del ops, use a control-ping to sync */
3580 vl_api_control_ping_t * mp;
3583 /* Shut off async mode */
3584 vam->async_mode = 0;
3586 M(CONTROL_PING, control_ping);
3589 timeout = vat_time_now(vam) + 1.0;
3590 while (vat_time_now (vam) < timeout)
3591 if (vam->result_ready == 1)
3596 if (vam->retval == -99)
3597 errmsg ("timeout\n");
3599 if (vam->async_errors > 0) {
3600 errmsg ("%d asynchronous errors\n", vam->async_errors);
3603 vam->async_errors = 0;
3604 after = vat_time_now(vam);
3606 fformat(vam->ofp, "%d routes in %.6f secs, %.2f routes/sec\n",
3607 count, after - before, count / (after - before));
3609 /* Wait for a reply... */
3613 /* Return the good/bad news */
3614 return (vam->retval);
3617 static int api_proxy_arp_add_del (vat_main_t * vam)
3619 unformat_input_t * i = vam->input;
3620 vl_api_proxy_arp_add_del_t *mp;
3624 ip4_address_t lo, hi;
3627 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
3628 if (unformat (i, "vrf %d", &vrf_id))
3630 else if (unformat (i, "%U - %U", unformat_ip4_address, &lo,
3631 unformat_ip4_address, &hi))
3633 else if (unformat (i, "del"))
3636 clib_warning ("parse error '%U'", format_unformat_error, i);
3641 if (range_set == 0) {
3642 errmsg ("address range not set\n");
3646 M(PROXY_ARP_ADD_DEL, proxy_arp_add_del);
3648 mp->vrf_id = ntohl(vrf_id);
3649 mp->is_add = is_add;
3650 memcpy(mp->low_address, &lo, sizeof (mp->low_address));
3651 memcpy(mp->hi_address, &hi, sizeof (mp->hi_address));
3658 static int api_proxy_arp_intfc_enable_disable (vat_main_t * vam)
3660 unformat_input_t * i = vam->input;
3661 vl_api_proxy_arp_intfc_enable_disable_t *mp;
3665 u8 sw_if_index_set = 0;
3667 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
3668 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
3669 sw_if_index_set = 1;
3670 else if (unformat (i, "sw_if_index %d", &sw_if_index))
3671 sw_if_index_set = 1;
3672 else if (unformat (i, "enable"))
3674 else if (unformat (i, "disable"))
3677 clib_warning ("parse error '%U'", format_unformat_error, i);
3682 if (sw_if_index_set == 0) {
3683 errmsg ("missing interface name or sw_if_index\n");
3687 M(PROXY_ARP_INTFC_ENABLE_DISABLE, proxy_arp_intfc_enable_disable);
3689 mp->sw_if_index = ntohl(sw_if_index);
3690 mp->enable_disable = enable;
3697 static int api_mpls_add_del_decap (vat_main_t * vam)
3699 unformat_input_t * i = vam->input;
3700 vl_api_mpls_add_del_decap_t *mp;
3709 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
3710 if (unformat (i, "rx_vrf_id %d", &rx_vrf_id))
3712 else if (unformat (i, "tx_vrf_id %d", &tx_vrf_id))
3714 else if (unformat (i, "label %d", &label))
3716 else if (unformat (i, "next-index %d", &next_index))
3718 else if (unformat (i, "del"))
3720 else if (unformat (i, "s-bit-clear"))
3723 clib_warning ("parse error '%U'", format_unformat_error, i);
3728 M(MPLS_ADD_DEL_DECAP, mpls_add_del_decap);
3730 mp->rx_vrf_id = ntohl(rx_vrf_id);
3731 mp->tx_vrf_id = ntohl(tx_vrf_id);
3732 mp->label = ntohl(label);
3733 mp->next_index = ntohl(next_index);
3735 mp->is_add = is_add;
3742 static int api_mpls_add_del_encap (vat_main_t * vam)
3744 unformat_input_t * i = vam->input;
3745 vl_api_mpls_add_del_encap_t *mp;
3750 ip4_address_t dst_address;
3753 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
3754 if (unformat (i, "vrf %d", &vrf_id))
3756 else if (unformat (i, "label %d", &label))
3757 vec_add1 (labels, ntohl(label));
3758 else if (unformat (i, "dst %U", unformat_ip4_address, &dst_address))
3760 else if (unformat (i, "del"))
3763 clib_warning ("parse error '%U'", format_unformat_error, i);
3768 if (vec_len (labels) == 0) {
3769 errmsg ("missing encap label stack\n");
3773 M2(MPLS_ADD_DEL_ENCAP, mpls_add_del_encap,
3774 sizeof (u32) * vec_len (labels));
3776 mp->vrf_id = ntohl(vrf_id);
3777 memcpy(mp->dst_address, &dst_address, sizeof (dst_address));
3778 mp->is_add = is_add;
3779 mp->nlabels = vec_len (labels);
3780 memcpy(mp->labels, labels, sizeof(u32)*mp->nlabels);
3789 static int api_mpls_gre_add_del_tunnel (vat_main_t * vam)
3791 unformat_input_t * i = vam->input;
3792 vl_api_mpls_gre_add_del_tunnel_t *mp;
3794 u32 inner_vrf_id = 0;
3795 u32 outer_vrf_id = 0;
3796 ip4_address_t src_address;
3797 ip4_address_t dst_address;
3798 ip4_address_t intfc_address;
3800 u8 intfc_address_length = 0;
3804 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
3805 if (unformat (i, "inner_vrf_id %d", &inner_vrf_id))
3807 else if (unformat (i, "outer_vrf_id %d", &outer_vrf_id))
3809 else if (unformat (i, "src %U", unformat_ip4_address, &src_address))
3811 else if (unformat (i, "dst %U", unformat_ip4_address, &dst_address))
3813 else if (unformat (i, "adj %U/%d", unformat_ip4_address,
3814 &intfc_address, &tmp))
3815 intfc_address_length = tmp;
3816 else if (unformat (i, "l2-only"))
3818 else if (unformat (i, "del"))
3821 clib_warning ("parse error '%U'", format_unformat_error, i);
3826 M(MPLS_GRE_ADD_DEL_TUNNEL, mpls_gre_add_del_tunnel);
3828 mp->inner_vrf_id = ntohl(inner_vrf_id);
3829 mp->outer_vrf_id = ntohl(outer_vrf_id);
3830 memcpy(mp->src_address, &src_address, sizeof (src_address));
3831 memcpy(mp->dst_address, &dst_address, sizeof (dst_address));
3832 memcpy(mp->intfc_address, &intfc_address, sizeof (intfc_address));
3833 mp->intfc_address_length = intfc_address_length;
3834 mp->l2_only = l2_only;
3835 mp->is_add = is_add;
3842 static int api_mpls_ethernet_add_del_tunnel (vat_main_t * vam)
3844 unformat_input_t * i = vam->input;
3845 vl_api_mpls_ethernet_add_del_tunnel_t *mp;
3847 u32 inner_vrf_id = 0;
3848 ip4_address_t intfc_address;
3849 u8 dst_mac_address[6];
3852 u8 intfc_address_length = 0;
3856 int tx_sw_if_index_set = 0;
3858 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
3859 if (unformat (i, "vrf %d", &inner_vrf_id))
3861 else if (unformat (i, "adj %U/%d", unformat_ip4_address,
3862 &intfc_address, &tmp))
3863 intfc_address_length = tmp;
3864 else if (unformat (i, "%U",
3865 unformat_sw_if_index, vam, &tx_sw_if_index))
3866 tx_sw_if_index_set = 1;
3867 else if (unformat (i, "tx_sw_if_index %d", &tx_sw_if_index))
3868 tx_sw_if_index_set = 1;
3869 else if (unformat (i, "dst %U", unformat_ethernet_address,
3872 else if (unformat (i, "l2-only"))
3874 else if (unformat (i, "del"))
3877 clib_warning ("parse error '%U'", format_unformat_error, i);
3883 errmsg ("dst (mac address) not set\n");
3886 if (!tx_sw_if_index_set) {
3887 errmsg ("tx-intfc not set\n");
3891 M(MPLS_ETHERNET_ADD_DEL_TUNNEL, mpls_ethernet_add_del_tunnel);
3893 mp->vrf_id = ntohl(inner_vrf_id);
3894 memcpy (mp->adj_address, &intfc_address, sizeof (intfc_address));
3895 mp->adj_address_length = intfc_address_length;
3896 memcpy (mp->dst_mac_address, dst_mac_address, sizeof (dst_mac_address));
3897 mp->tx_sw_if_index = ntohl(tx_sw_if_index);
3898 mp->l2_only = l2_only;
3899 mp->is_add = is_add;
3906 static int api_mpls_ethernet_add_del_tunnel_2 (vat_main_t * vam)
3908 unformat_input_t * i = vam->input;
3909 vl_api_mpls_ethernet_add_del_tunnel_2_t *mp;
3911 u32 inner_vrf_id = 0;
3912 u32 outer_vrf_id = 0;
3913 ip4_address_t adj_address;
3914 int adj_address_set = 0;
3915 ip4_address_t next_hop_address;
3916 int next_hop_address_set = 0;
3918 u8 adj_address_length = 0;
3921 u32 resolve_attempts = 5;
3922 u8 resolve_if_needed = 1;
3924 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
3925 if (unformat (i, "inner_vrf_id %d", &inner_vrf_id))
3927 else if (unformat (i, "outer_vrf_id %d", &outer_vrf_id))
3929 else if (unformat (i, "adj %U/%d", unformat_ip4_address,
3930 &adj_address, &tmp)) {
3931 adj_address_length = tmp;
3932 adj_address_set = 1;
3934 else if (unformat (i, "next-hop %U", unformat_ip4_address,
3936 next_hop_address_set = 1;
3937 else if (unformat (i, "resolve-attempts %d", &resolve_attempts))
3939 else if (unformat (i, "resolve-if-needed %d", &tmp))
3940 resolve_if_needed = tmp;
3941 else if (unformat (i, "l2-only"))
3943 else if (unformat (i, "del"))
3946 clib_warning ("parse error '%U'", format_unformat_error, i);
3951 if (!adj_address_set) {
3952 errmsg ("adjacency address/mask not set\n");
3955 if (!next_hop_address_set) {
3956 errmsg ("ip4 next hop address (in outer fib) not set\n");
3960 M(MPLS_ETHERNET_ADD_DEL_TUNNEL_2, mpls_ethernet_add_del_tunnel_2);
3962 mp->inner_vrf_id = ntohl(inner_vrf_id);
3963 mp->outer_vrf_id = ntohl(outer_vrf_id);
3964 mp->resolve_attempts = ntohl(resolve_attempts);
3965 mp->resolve_if_needed = resolve_if_needed;
3966 mp->is_add = is_add;
3967 mp->l2_only = l2_only;
3968 memcpy (mp->adj_address, &adj_address, sizeof (adj_address));
3969 mp->adj_address_length = adj_address_length;
3970 memcpy (mp->next_hop_ip4_address_in_outer_vrf, &next_hop_address,
3971 sizeof (next_hop_address));
3978 static int api_sw_interface_set_unnumbered (vat_main_t * vam)
3980 unformat_input_t * i = vam->input;
3981 vl_api_sw_interface_set_unnumbered_t *mp;
3986 u8 sw_if_index_set = 0;
3988 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
3989 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
3990 sw_if_index_set = 1;
3991 else if (unformat (i, "sw_if_index %d", &sw_if_index))
3992 sw_if_index_set = 1;
3993 else if (unformat (i, "unnum_if_index %d", &unnum_sw_index))
3995 else if (unformat (i, "del"))
3998 clib_warning ("parse error '%U'", format_unformat_error, i);
4003 if (sw_if_index_set == 0) {
4004 errmsg ("missing interface name or sw_if_index\n");
4008 M(SW_INTERFACE_SET_UNNUMBERED, sw_interface_set_unnumbered);
4010 mp->sw_if_index = ntohl(sw_if_index);
4011 mp->unnumbered_sw_if_index = ntohl(unnum_sw_index);
4012 mp->is_add = is_add;
4019 static int api_ip_neighbor_add_del (vat_main_t * vam)
4021 unformat_input_t * i = vam->input;
4022 vl_api_ip_neighbor_add_del_t *mp;
4025 u8 sw_if_index_set = 0;
4031 u8 v4_address_set = 0;
4032 u8 v6_address_set = 0;
4033 ip4_address_t v4address;
4034 ip6_address_t v6address;
4036 memset (mac_address, 0, sizeof (mac_address));
4038 /* Parse args required to build the message */
4039 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
4040 if (unformat (i, "mac %U", unformat_ethernet_address, mac_address)) {
4043 else if (unformat (i, "del"))
4045 else if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
4046 sw_if_index_set = 1;
4047 else if (unformat (i, "sw_if_index %d", &sw_if_index))
4048 sw_if_index_set = 1;
4049 else if (unformat (i, "is_static"))
4051 else if (unformat (i, "vrf %d", &vrf_id))
4053 else if (unformat (i, "dst %U",
4054 unformat_ip4_address, &v4address))
4056 else if (unformat (i, "dst %U",
4057 unformat_ip6_address, &v6address))
4060 clib_warning ("parse error '%U'", format_unformat_error, i);
4065 if (sw_if_index_set == 0) {
4066 errmsg ("missing interface name or sw_if_index\n");
4069 if (v4_address_set && v6_address_set) {
4070 errmsg ("both v4 and v6 addresses set\n");
4073 if (!v4_address_set && !v6_address_set) {
4074 errmsg ("no addresses set\n");
4078 /* Construct the API message */
4079 M(IP_NEIGHBOR_ADD_DEL, ip_neighbor_add_del);
4081 mp->sw_if_index = ntohl (sw_if_index);
4082 mp->is_add = is_add;
4083 mp->vrf_id = ntohl (vrf_id);
4084 mp->is_static = is_static;
4086 memcpy (mp->mac_address, mac_address, 6);
4087 if (v6_address_set) {
4089 memcpy (mp->dst_address, &v6address, sizeof (v6address));
4091 /* mp->is_ipv6 = 0; via memset in M macro above */
4092 memcpy (mp->dst_address, &v4address, sizeof (v4address));
4098 /* Wait for a reply, return good/bad news */
4105 static int api_reset_vrf (vat_main_t * vam)
4107 unformat_input_t * i = vam->input;
4108 vl_api_reset_vrf_t *mp;
4114 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
4115 if (unformat (i, "vrf %d", &vrf_id))
4117 else if (unformat (i, "ipv6"))
4120 clib_warning ("parse error '%U'", format_unformat_error, i);
4125 if (vrf_id_set == 0) {
4126 errmsg ("missing vrf id\n");
4130 M(RESET_VRF, reset_vrf);
4132 mp->vrf_id = ntohl(vrf_id);
4133 mp->is_ipv6 = is_ipv6;
4140 static int api_create_vlan_subif (vat_main_t * vam)
4142 unformat_input_t * i = vam->input;
4143 vl_api_create_vlan_subif_t *mp;
4146 u8 sw_if_index_set = 0;
4150 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
4151 if (unformat (i, "sw_if_index %d", &sw_if_index))
4152 sw_if_index_set = 1;
4153 else if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
4154 sw_if_index_set = 1;
4155 else if (unformat (i, "vlan %d", &vlan_id))
4158 clib_warning ("parse error '%U'", format_unformat_error, i);
4163 if (sw_if_index_set == 0) {
4164 errmsg ("missing interface name or sw_if_index\n");
4168 if (vlan_id_set == 0) {
4169 errmsg ("missing vlan_id\n");
4172 M(CREATE_VLAN_SUBIF, create_vlan_subif);
4174 mp->sw_if_index = ntohl(sw_if_index);
4175 mp->vlan_id = ntohl(vlan_id);
4182 #define foreach_create_subif_bit \
4189 _(outer_vlan_id_any) \
4190 _(inner_vlan_id_any)
4192 static int api_create_subif (vat_main_t * vam)
4194 unformat_input_t * i = vam->input;
4195 vl_api_create_subif_t *mp;
4198 u8 sw_if_index_set = 0;
4205 u32 exact_match = 0;
4206 u32 default_sub = 0;
4207 u32 outer_vlan_id_any = 0;
4208 u32 inner_vlan_id_any = 0;
4210 u16 outer_vlan_id = 0;
4211 u16 inner_vlan_id = 0;
4213 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
4214 if (unformat (i, "sw_if_index %d", &sw_if_index))
4215 sw_if_index_set = 1;
4216 else if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
4217 sw_if_index_set = 1;
4218 else if (unformat (i, "sub_id %d", &sub_id))
4220 else if (unformat (i, "outer_vlan_id %d", &tmp))
4221 outer_vlan_id = tmp;
4222 else if (unformat (i, "inner_vlan_id %d", &tmp))
4223 inner_vlan_id = tmp;
4225 #define _(a) else if (unformat (i, #a)) a = 1 ;
4226 foreach_create_subif_bit
4230 clib_warning ("parse error '%U'", format_unformat_error, i);
4235 if (sw_if_index_set == 0) {
4236 errmsg ("missing interface name or sw_if_index\n");
4240 if (sub_id_set == 0) {
4241 errmsg ("missing sub_id\n");
4244 M(CREATE_SUBIF, create_subif);
4246 mp->sw_if_index = ntohl(sw_if_index);
4247 mp->sub_id = ntohl(sub_id);
4249 #define _(a) mp->a = a;
4250 foreach_create_subif_bit;
4253 mp->outer_vlan_id = ntohs (outer_vlan_id);
4254 mp->inner_vlan_id = ntohs (inner_vlan_id);
4261 static int api_oam_add_del (vat_main_t * vam)
4263 unformat_input_t * i = vam->input;
4264 vl_api_oam_add_del_t *mp;
4268 ip4_address_t src, dst;
4272 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
4273 if (unformat (i, "vrf %d", &vrf_id))
4275 else if (unformat (i, "src %U", unformat_ip4_address, &src))
4277 else if (unformat (i, "dst %U", unformat_ip4_address, &dst))
4279 else if (unformat (i, "del"))
4282 clib_warning ("parse error '%U'", format_unformat_error, i);
4288 errmsg ("missing src addr\n");
4293 errmsg ("missing dst addr\n");
4297 M(OAM_ADD_DEL, oam_add_del);
4299 mp->vrf_id = ntohl(vrf_id);
4300 mp->is_add = is_add;
4301 memcpy(mp->src_address, &src, sizeof (mp->src_address));
4302 memcpy(mp->dst_address, &dst, sizeof (mp->dst_address));
4309 static int api_reset_fib (vat_main_t * vam)
4311 unformat_input_t * i = vam->input;
4312 vl_api_reset_fib_t *mp;
4318 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
4319 if (unformat (i, "vrf %d", &vrf_id))
4321 else if (unformat (i, "ipv6"))
4324 clib_warning ("parse error '%U'", format_unformat_error, i);
4329 if (vrf_id_set == 0) {
4330 errmsg ("missing vrf id\n");
4334 M(RESET_FIB, reset_fib);
4336 mp->vrf_id = ntohl(vrf_id);
4337 mp->is_ipv6 = is_ipv6;
4344 static int api_dhcp_proxy_config (vat_main_t * vam)
4346 unformat_input_t * i = vam->input;
4347 vl_api_dhcp_proxy_config_t *mp;
4352 u8 v4_address_set = 0;
4353 u8 v6_address_set = 0;
4354 ip4_address_t v4address;
4355 ip6_address_t v6address;
4356 u8 v4_src_address_set = 0;
4357 u8 v6_src_address_set = 0;
4358 ip4_address_t v4srcaddress;
4359 ip6_address_t v6srcaddress;
4361 /* Parse args required to build the message */
4362 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
4363 if (unformat (i, "del"))
4365 else if (unformat (i, "vrf %d", &vrf_id))
4367 else if (unformat (i, "insert-cid %d", &insert_cid))
4369 else if (unformat (i, "svr %U",
4370 unformat_ip4_address, &v4address))
4372 else if (unformat (i, "svr %U",
4373 unformat_ip6_address, &v6address))
4375 else if (unformat (i, "src %U",
4376 unformat_ip4_address, &v4srcaddress))
4377 v4_src_address_set = 1;
4378 else if (unformat (i, "src %U",
4379 unformat_ip6_address, &v6srcaddress))
4380 v6_src_address_set = 1;
4385 if (v4_address_set && v6_address_set) {
4386 errmsg ("both v4 and v6 server addresses set\n");
4389 if (!v4_address_set && !v6_address_set) {
4390 errmsg ("no server addresses set\n");
4394 if (v4_src_address_set && v6_src_address_set) {
4395 errmsg ("both v4 and v6 src addresses set\n");
4398 if (!v4_src_address_set && !v6_src_address_set) {
4399 errmsg ("no src addresses set\n");
4403 if (!(v4_src_address_set && v4_address_set) &&
4404 !(v6_src_address_set && v6_address_set)) {
4405 errmsg ("no matching server and src addresses set\n");
4409 /* Construct the API message */
4410 M(DHCP_PROXY_CONFIG, dhcp_proxy_config);
4412 mp->insert_circuit_id = insert_cid;
4413 mp->is_add = is_add;
4414 mp->vrf_id = ntohl (vrf_id);
4415 if (v6_address_set) {
4417 memcpy (mp->dhcp_server, &v6address, sizeof (v6address));
4418 memcpy (mp->dhcp_src_address, &v6srcaddress, sizeof (v6address));
4420 memcpy (mp->dhcp_server, &v4address, sizeof (v4address));
4421 memcpy (mp->dhcp_src_address, &v4srcaddress, sizeof (v4address));
4427 /* Wait for a reply, return good/bad news */
4433 static int api_dhcp_proxy_config_2 (vat_main_t * vam)
4435 unformat_input_t * i = vam->input;
4436 vl_api_dhcp_proxy_config_2_t *mp;
4439 u32 server_vrf_id = 0;
4442 u8 v4_address_set = 0;
4443 u8 v6_address_set = 0;
4444 ip4_address_t v4address;
4445 ip6_address_t v6address;
4446 u8 v4_src_address_set = 0;
4447 u8 v6_src_address_set = 0;
4448 ip4_address_t v4srcaddress;
4449 ip6_address_t v6srcaddress;
4451 /* Parse args required to build the message */
4452 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
4453 if (unformat (i, "del"))
4455 else if (unformat (i, "rx_vrf_id %d", &rx_vrf_id))
4457 else if (unformat (i, "server_vrf_id %d", &server_vrf_id))
4459 else if (unformat (i, "insert-cid %d", &insert_cid))
4461 else if (unformat (i, "svr %U",
4462 unformat_ip4_address, &v4address))
4464 else if (unformat (i, "svr %U",
4465 unformat_ip6_address, &v6address))
4467 else if (unformat (i, "src %U",
4468 unformat_ip4_address, &v4srcaddress))
4469 v4_src_address_set = 1;
4470 else if (unformat (i, "src %U",
4471 unformat_ip6_address, &v6srcaddress))
4472 v6_src_address_set = 1;
4477 if (v4_address_set && v6_address_set) {
4478 errmsg ("both v4 and v6 server addresses set\n");
4481 if (!v4_address_set && !v6_address_set) {
4482 errmsg ("no server addresses set\n");
4486 if (v4_src_address_set && v6_src_address_set) {
4487 errmsg ("both v4 and v6 src addresses set\n");
4490 if (!v4_src_address_set && !v6_src_address_set) {
4491 errmsg ("no src addresses set\n");
4495 if (!(v4_src_address_set && v4_address_set) &&
4496 !(v6_src_address_set && v6_address_set)) {
4497 errmsg ("no matching server and src addresses set\n");
4501 /* Construct the API message */
4502 M(DHCP_PROXY_CONFIG_2, dhcp_proxy_config_2);
4504 mp->insert_circuit_id = insert_cid;
4505 mp->is_add = is_add;
4506 mp->rx_vrf_id = ntohl (rx_vrf_id);
4507 mp->server_vrf_id = ntohl (server_vrf_id);
4508 if (v6_address_set) {
4510 memcpy (mp->dhcp_server, &v6address, sizeof (v6address));
4511 memcpy (mp->dhcp_src_address, &v6srcaddress, sizeof (v6address));
4513 memcpy (mp->dhcp_server, &v4address, sizeof (v4address));
4514 memcpy (mp->dhcp_src_address, &v4srcaddress, sizeof (v4address));
4520 /* Wait for a reply, return good/bad news */
4526 static int api_dhcp_proxy_set_vss (vat_main_t * vam)
4528 unformat_input_t * i = vam->input;
4529 vl_api_dhcp_proxy_set_vss_t *mp;
4540 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
4541 if (unformat (i, "tbl_id %d", &tbl_id))
4543 if (unformat (i, "fib_id %d", &fib_id))
4545 if (unformat (i, "oui %d", &oui))
4547 else if (unformat (i, "ipv6"))
4549 else if (unformat (i, "del"))
4552 clib_warning ("parse error '%U'", format_unformat_error, i);
4557 if (tbl_id_set == 0) {
4558 errmsg ("missing tbl id\n");
4562 if (fib_id_set == 0) {
4563 errmsg ("missing fib id\n");
4567 errmsg ("missing oui\n");
4571 M(DHCP_PROXY_SET_VSS, dhcp_proxy_set_vss);
4572 mp->tbl_id = ntohl(tbl_id);
4573 mp->fib_id = ntohl(fib_id);
4574 mp->oui = ntohl(oui);
4575 mp->is_ipv6 = is_ipv6;
4576 mp->is_add = is_add;
4583 static int api_dhcp_client_config (vat_main_t * vam)
4585 unformat_input_t * i = vam->input;
4586 vl_api_dhcp_client_config_t *mp;
4589 u8 sw_if_index_set = 0;
4592 u8 disable_event = 0;
4594 /* Parse args required to build the message */
4595 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
4596 if (unformat (i, "del"))
4598 else if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
4599 sw_if_index_set = 1;
4600 else if (unformat (i, "sw_if_index %d", &sw_if_index))
4601 sw_if_index_set = 1;
4602 else if (unformat (i, "hostname %s", &hostname))
4604 else if (unformat (i, "disable_event"))
4610 if (sw_if_index_set == 0) {
4611 errmsg ("missing interface name or sw_if_index\n");
4615 if (vec_len (hostname) > 63) {
4616 errmsg ("hostname too long\n");
4618 vec_add1 (hostname, 0);
4620 /* Construct the API message */
4621 M(DHCP_CLIENT_CONFIG, dhcp_client_config);
4623 mp->sw_if_index = ntohl (sw_if_index);
4624 memcpy (mp->hostname, hostname, vec_len (hostname));
4625 vec_free (hostname);
4626 mp->is_add = is_add;
4627 mp->want_dhcp_event = disable_event ? 0 : 1;
4633 /* Wait for a reply, return good/bad news */
4639 static int api_set_ip_flow_hash (vat_main_t * vam)
4641 unformat_input_t * i = vam->input;
4642 vl_api_set_ip_flow_hash_t *mp;
4654 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
4655 if (unformat (i, "vrf %d", &vrf_id))
4657 else if (unformat (i, "ipv6"))
4659 else if (unformat (i, "src"))
4661 else if (unformat (i, "dst"))
4663 else if (unformat (i, "sport"))
4665 else if (unformat (i, "dport"))
4667 else if (unformat (i, "proto"))
4669 else if (unformat (i, "reverse"))
4673 clib_warning ("parse error '%U'", format_unformat_error, i);
4678 if (vrf_id_set == 0) {
4679 errmsg ("missing vrf id\n");
4683 M(SET_IP_FLOW_HASH, set_ip_flow_hash);
4689 mp->reverse = reverse;
4690 mp->vrf_id = ntohl(vrf_id);
4691 mp->is_ipv6 = is_ipv6;
4698 static int api_sw_interface_ip6_enable_disable (vat_main_t * vam)
4700 unformat_input_t * i = vam->input;
4701 vl_api_sw_interface_ip6_enable_disable_t *mp;
4704 u8 sw_if_index_set = 0;
4707 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
4708 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
4709 sw_if_index_set = 1;
4710 else if (unformat (i, "sw_if_index %d", &sw_if_index))
4711 sw_if_index_set = 1;
4712 else if (unformat (i, "enable"))
4714 else if (unformat (i, "disable"))
4717 clib_warning ("parse error '%U'", format_unformat_error, i);
4722 if (sw_if_index_set == 0) {
4723 errmsg ("missing interface name or sw_if_index\n");
4727 M(SW_INTERFACE_IP6_ENABLE_DISABLE, sw_interface_ip6_enable_disable);
4729 mp->sw_if_index = ntohl(sw_if_index);
4730 mp->enable = enable;
4737 static int api_sw_interface_ip6_set_link_local_address (vat_main_t * vam)
4739 unformat_input_t * i = vam->input;
4740 vl_api_sw_interface_ip6_set_link_local_address_t *mp;
4743 u8 sw_if_index_set = 0;
4744 u32 address_length = 0;
4745 u8 v6_address_set = 0;
4746 ip6_address_t v6address;
4748 /* Parse args required to build the message */
4749 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
4750 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
4751 sw_if_index_set = 1;
4752 else if (unformat (i, "sw_if_index %d", &sw_if_index))
4753 sw_if_index_set = 1;
4754 else if (unformat (i, "%U/%d",
4755 unformat_ip6_address, &v6address,
4762 if (sw_if_index_set == 0) {
4763 errmsg ("missing interface name or sw_if_index\n");
4766 if (!v6_address_set) {
4767 errmsg ("no address set\n");
4771 /* Construct the API message */
4772 M(SW_INTERFACE_IP6_SET_LINK_LOCAL_ADDRESS, \
4773 sw_interface_ip6_set_link_local_address);
4775 mp->sw_if_index = ntohl (sw_if_index);
4776 memcpy (mp->address, &v6address, sizeof (v6address));
4777 mp->address_length = address_length;
4782 /* Wait for a reply, return good/bad news */
4790 static int api_sw_interface_ip6nd_ra_prefix (vat_main_t * vam)
4792 unformat_input_t * i = vam->input;
4793 vl_api_sw_interface_ip6nd_ra_prefix_t *mp;
4796 u8 sw_if_index_set = 0;
4797 u32 address_length = 0;
4798 u8 v6_address_set = 0;
4799 ip6_address_t v6address;
4801 u8 no_advertise = 0;
4803 u8 no_autoconfig = 0;
4806 u32 val_lifetime = 0;
4807 u32 pref_lifetime = 0;
4809 /* Parse args required to build the message */
4810 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
4811 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
4812 sw_if_index_set = 1;
4813 else if (unformat (i, "sw_if_index %d", &sw_if_index))
4814 sw_if_index_set = 1;
4815 else if (unformat (i, "%U/%d",
4816 unformat_ip6_address, &v6address,
4819 else if (unformat (i, "val_life %d", &val_lifetime))
4821 else if (unformat (i, "pref_life %d", &pref_lifetime))
4823 else if (unformat (i, "def"))
4825 else if (unformat (i, "noadv"))
4827 else if (unformat (i, "offl"))
4829 else if (unformat (i, "noauto"))
4831 else if (unformat (i, "nolink"))
4833 else if (unformat (i, "isno"))
4836 clib_warning ("parse error '%U'", format_unformat_error, i);
4841 if (sw_if_index_set == 0) {
4842 errmsg ("missing interface name or sw_if_index\n");
4845 if (!v6_address_set) {
4846 errmsg ("no address set\n");
4850 /* Construct the API message */
4851 M(SW_INTERFACE_IP6ND_RA_PREFIX, sw_interface_ip6nd_ra_prefix);
4853 mp->sw_if_index = ntohl (sw_if_index);
4854 memcpy (mp->address, &v6address, sizeof (v6address));
4855 mp->address_length = address_length;
4856 mp->use_default = use_default;
4857 mp->no_advertise = no_advertise;
4858 mp->off_link = off_link;
4859 mp->no_autoconfig = no_autoconfig;
4860 mp->no_onlink = no_onlink;
4862 mp->val_lifetime = ntohl(val_lifetime);
4863 mp->pref_lifetime = ntohl(pref_lifetime);
4868 /* Wait for a reply, return good/bad news */
4875 static int api_sw_interface_ip6nd_ra_config (vat_main_t * vam)
4877 unformat_input_t * i = vam->input;
4878 vl_api_sw_interface_ip6nd_ra_config_t *mp;
4881 u8 sw_if_index_set = 0;
4886 u8 send_unicast = 0;
4889 u8 default_router = 0;
4890 u32 max_interval = 0;
4891 u32 min_interval = 0;
4893 u32 initial_count = 0;
4894 u32 initial_interval = 0;
4897 /* Parse args required to build the message */
4898 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
4899 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
4900 sw_if_index_set = 1;
4901 else if (unformat (i, "sw_if_index %d", &sw_if_index))
4902 sw_if_index_set = 1;
4903 else if (unformat (i, "maxint %d", &max_interval))
4905 else if (unformat (i, "minint %d", &min_interval))
4907 else if (unformat (i, "life %d", &lifetime))
4909 else if (unformat (i, "count %d", &initial_count))
4911 else if (unformat (i, "interval %d", &initial_interval))
4913 else if (unformat (i, "surpress"))
4915 else if (unformat (i, "managed"))
4917 else if (unformat (i, "other"))
4919 else if (unformat (i, "ll"))
4921 else if (unformat (i, "send"))
4923 else if (unformat (i, "cease"))
4925 else if (unformat (i, "isno"))
4927 else if (unformat (i, "def"))
4930 clib_warning ("parse error '%U'", format_unformat_error, i);
4935 if (sw_if_index_set == 0) {
4936 errmsg ("missing interface name or sw_if_index\n");
4940 /* Construct the API message */
4941 M(SW_INTERFACE_IP6ND_RA_CONFIG, sw_interface_ip6nd_ra_config);
4943 mp->sw_if_index = ntohl (sw_if_index);
4944 mp->max_interval = ntohl(max_interval);
4945 mp->min_interval = ntohl(min_interval);
4946 mp->lifetime = ntohl(lifetime);
4947 mp->initial_count = ntohl(initial_count);
4948 mp->initial_interval = ntohl(initial_interval);
4949 mp->surpress = surpress;
4950 mp->managed = managed;
4952 mp->ll_option = ll_option;
4953 mp->send_unicast = send_unicast;
4956 mp->default_router = default_router;
4961 /* Wait for a reply, return good/bad news */
4968 static int api_set_arp_neighbor_limit (vat_main_t * vam)
4970 unformat_input_t * i = vam->input;
4971 vl_api_set_arp_neighbor_limit_t *mp;
4977 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
4978 if (unformat (i, "arp_nbr_limit %d", &arp_nbr_limit))
4980 else if (unformat (i, "ipv6"))
4983 clib_warning ("parse error '%U'", format_unformat_error, i);
4988 if (limit_set == 0) {
4989 errmsg ("missing limit value\n");
4993 M(SET_ARP_NEIGHBOR_LIMIT, set_arp_neighbor_limit);
4995 mp->arp_neighbor_limit = ntohl(arp_nbr_limit);
4996 mp->is_ipv6 = is_ipv6;
5003 static int api_l2_patch_add_del (vat_main_t * vam)
5005 unformat_input_t * i = vam->input;
5006 vl_api_l2_patch_add_del_t *mp;
5009 u8 rx_sw_if_index_set = 0;
5011 u8 tx_sw_if_index_set = 0;
5014 /* Parse args required to build the message */
5015 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
5016 if (unformat (i, "rx_sw_if_index %d", &rx_sw_if_index))
5017 rx_sw_if_index_set = 1;
5018 else if (unformat (i, "tx_sw_if_index %d", &tx_sw_if_index))
5019 tx_sw_if_index_set = 1;
5020 else if (unformat (i, "rx")) {
5021 if (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
5022 if (unformat (i, "%U", unformat_sw_if_index, vam,
5024 rx_sw_if_index_set = 1;
5027 } else if (unformat (i, "tx")) {
5028 if (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
5029 if (unformat (i, "%U", unformat_sw_if_index, vam,
5031 tx_sw_if_index_set = 1;
5034 } else if (unformat (i, "del"))
5040 if (rx_sw_if_index_set == 0) {
5041 errmsg ("missing rx interface name or rx_sw_if_index\n");
5045 if (tx_sw_if_index_set == 0) {
5046 errmsg ("missing tx interface name or tx_sw_if_index\n");
5050 M(L2_PATCH_ADD_DEL, l2_patch_add_del);
5052 mp->rx_sw_if_index = ntohl(rx_sw_if_index);
5053 mp->tx_sw_if_index = ntohl(tx_sw_if_index);
5054 mp->is_add = is_add;
5061 static int api_sr_tunnel_add_del (vat_main_t * vam)
5063 unformat_input_t * i = vam->input;
5064 vl_api_sr_tunnel_add_del_t *mp;
5068 ip6_address_t src_address;
5069 int src_address_set = 0;
5070 ip6_address_t dst_address;
5072 int dst_address_set = 0;
5074 u32 rx_table_id = 0;
5075 u32 tx_table_id = 0;
5076 ip6_address_t * segments = 0;
5077 ip6_address_t * this_seg;
5078 ip6_address_t * tags = 0;
5079 ip6_address_t * this_tag;
5080 ip6_address_t next_address, tag;
5082 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
5084 if (unformat (i, "del"))
5086 else if (unformat (i, "rx_fib_id %d", &rx_table_id))
5088 else if (unformat (i, "tx_fib_id %d", &tx_table_id))
5090 else if (unformat (i, "src %U", unformat_ip6_address, &src_address))
5091 src_address_set = 1;
5092 else if (unformat (i, "dst %U/%d",
5093 unformat_ip6_address, &dst_address,
5095 dst_address_set = 1;
5096 else if (unformat (i, "next %U", unformat_ip6_address,
5099 vec_add2 (segments, this_seg, 1);
5100 memcpy (this_seg->as_u8, next_address.as_u8, sizeof (*this_seg));
5102 else if (unformat (i, "tag %U", unformat_ip6_address,
5105 vec_add2 (tags, this_tag, 1);
5106 memcpy (this_tag->as_u8, tag.as_u8, sizeof (*this_tag));
5108 else if (unformat (i, "clean"))
5109 flags |= IP6_SR_HEADER_FLAG_CLEANUP;
5110 else if (unformat (i, "protected"))
5111 flags |= IP6_SR_HEADER_FLAG_PROTECTED;
5112 else if (unformat (i, "InPE %d", &pl_index))
5114 if (pl_index <= 0 || pl_index > 4)
5116 pl_index_range_error:
5117 errmsg ("pl index %d out of range\n", pl_index);
5120 flags |= IP6_SR_HEADER_FLAG_PL_ELT_INGRESS_PE << (3*(pl_index - 1));
5122 else if (unformat (i, "EgPE %d", &pl_index))
5124 if (pl_index <= 0 || pl_index > 4)
5125 goto pl_index_range_error;
5126 flags |= IP6_SR_HEADER_FLAG_PL_ELT_EGRESS_PE << (3*(pl_index - 1));
5128 else if (unformat (i, "OrgSrc %d", &pl_index))
5130 if (pl_index <= 0 || pl_index > 4)
5131 goto pl_index_range_error;
5132 flags |= IP6_SR_HEADER_FLAG_PL_ELT_ORIG_SRC_ADDR << (3*(pl_index - 1));
5138 if (!src_address_set)
5140 errmsg ("src address required\n");
5144 if (!dst_address_set)
5146 errmsg ("dst address required\n");
5152 errmsg ("at least one sr segment required\n");
5156 M2(SR_TUNNEL_ADD_DEL, sr_tunnel_add_del,
5157 vec_len(segments) * sizeof (ip6_address_t)
5158 + vec_len(tags) * sizeof (ip6_address_t));
5160 memcpy (mp->src_address, &src_address, sizeof (mp->src_address));
5161 memcpy (mp->dst_address, &dst_address, sizeof (mp->dst_address));
5162 mp->dst_mask_width = dst_mask_width;
5163 mp->flags_net_byte_order = clib_host_to_net_u16 (flags);
5164 mp->n_segments = vec_len (segments);
5165 mp->n_tags = vec_len (tags);
5166 mp->is_add = is_del == 0;
5167 memcpy (mp->segs_and_tags, segments,
5168 vec_len(segments)* sizeof (ip6_address_t));
5169 memcpy (mp->segs_and_tags + vec_len(segments)*sizeof (ip6_address_t),
5170 tags, vec_len(tags)* sizeof (ip6_address_t));
5172 mp->outer_vrf_id = ntohl (rx_table_id);
5173 mp->inner_vrf_id = ntohl (tx_table_id);
5175 vec_free (segments);
5183 #define foreach_ip4_proto_field \
5193 uword unformat_ip4_mask (unformat_input_t * input, va_list * args)
5195 u8 ** maskp = va_arg (*args, u8 **);
5197 u8 found_something = 0;
5200 #define _(a) u8 a=0;
5201 foreach_ip4_proto_field;
5207 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
5209 if (unformat (input, "version"))
5211 else if (unformat (input, "hdr_length"))
5213 else if (unformat (input, "src"))
5215 else if (unformat (input, "dst"))
5217 else if (unformat (input, "proto"))
5220 #define _(a) else if (unformat (input, #a)) a=1;
5221 foreach_ip4_proto_field
5227 #define _(a) found_something += a;
5228 foreach_ip4_proto_field;
5231 if (found_something == 0)
5234 vec_validate (mask, sizeof (*ip) - 1);
5236 ip = (ip4_header_t *) mask;
5238 #define _(a) if (a) memset (&ip->a, 0xff, sizeof (ip->a));
5239 foreach_ip4_proto_field;
5242 ip->ip_version_and_header_length = 0;
5245 ip->ip_version_and_header_length |= 0xF0;
5248 ip->ip_version_and_header_length |= 0x0F;
5254 #define foreach_ip6_proto_field \
5261 uword unformat_ip6_mask (unformat_input_t * input, va_list * args)
5263 u8 ** maskp = va_arg (*args, u8 **);
5265 u8 found_something = 0;
5267 u32 ip_version_traffic_class_and_flow_label;
5269 #define _(a) u8 a=0;
5270 foreach_ip6_proto_field;
5273 u8 traffic_class = 0;
5276 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
5278 if (unformat (input, "version"))
5280 else if (unformat (input, "traffic-class"))
5282 else if (unformat (input, "flow-label"))
5284 else if (unformat (input, "src"))
5286 else if (unformat (input, "dst"))
5288 else if (unformat (input, "proto"))
5291 #define _(a) else if (unformat (input, #a)) a=1;
5292 foreach_ip6_proto_field
5298 #define _(a) found_something += a;
5299 foreach_ip6_proto_field;
5302 if (found_something == 0)
5305 vec_validate (mask, sizeof (*ip) - 1);
5307 ip = (ip6_header_t *) mask;
5309 #define _(a) if (a) memset (&ip->a, 0xff, sizeof (ip->a));
5310 foreach_ip6_proto_field;
5313 ip_version_traffic_class_and_flow_label = 0;
5316 ip_version_traffic_class_and_flow_label |= 0xF0000000;
5319 ip_version_traffic_class_and_flow_label |= 0x0FF00000;
5322 ip_version_traffic_class_and_flow_label |= 0x000FFFFF;
5324 ip->ip_version_traffic_class_and_flow_label =
5325 clib_host_to_net_u32 (ip_version_traffic_class_and_flow_label);
5331 uword unformat_l3_mask (unformat_input_t * input, va_list * args)
5333 u8 ** maskp = va_arg (*args, u8 **);
5335 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) {
5336 if (unformat (input, "ip4 %U", unformat_ip4_mask, maskp))
5338 else if (unformat (input, "ip6 %U", unformat_ip6_mask, maskp))
5346 uword unformat_l2_mask (unformat_input_t * input, va_list * args)
5348 u8 ** maskp = va_arg (*args, u8 **);
5363 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) {
5364 if (unformat (input, "src"))
5366 else if (unformat (input, "dst"))
5368 else if (unformat (input, "proto"))
5370 else if (unformat (input, "tag1"))
5372 else if (unformat (input, "tag2"))
5374 else if (unformat (input, "ignore-tag1"))
5376 else if (unformat (input, "ignore-tag2"))
5378 else if (unformat (input, "cos1"))
5380 else if (unformat (input, "cos2"))
5382 else if (unformat (input, "dot1q"))
5384 else if (unformat (input, "dot1ad"))
5389 if ((src + dst + proto + tag1 + tag2 + dot1q + dot1ad +
5390 ignore_tag1 + ignore_tag2 + cos1 + cos2) == 0)
5393 if (tag1 || ignore_tag1 || cos1 || dot1q)
5395 if (tag2 || ignore_tag2 || cos2 || dot1ad)
5398 vec_validate (mask, len-1);
5401 memset (mask, 0xff, 6);
5404 memset (mask + 6, 0xff, 6);
5408 /* inner vlan tag */
5417 mask[21] = mask [20] = 0xff;
5438 mask[16] = mask [17] = 0xff;
5448 mask[12] = mask [13] = 0xff;
5454 uword unformat_classify_mask (unformat_input_t * input, va_list * args)
5456 u8 ** maskp = va_arg (*args, u8 **);
5457 u32 * skipp = va_arg (*args, u32 *);
5458 u32 * matchp = va_arg (*args, u32 *);
5465 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) {
5466 if (unformat (input, "hex %U", unformat_hex_string, &mask))
5468 else if (unformat (input, "l2 %U", unformat_l2_mask, &l2))
5470 else if (unformat (input, "l3 %U", unformat_l3_mask, &l3))
5476 if (mask || l2 || l3)
5480 /* "With a free Ethernet header in every package" */
5482 vec_validate (l2, 13);
5484 vec_append (mask, l3);
5488 /* Scan forward looking for the first significant mask octet */
5489 for (i = 0; i < vec_len (mask); i++)
5493 /* compute (skip, match) params */
5494 *skipp = i / sizeof(u32x4);
5495 vec_delete (mask, *skipp * sizeof(u32x4), 0);
5497 /* Pad mask to an even multiple of the vector size */
5498 while (vec_len (mask) % sizeof (u32x4))
5501 match = vec_len (mask) / sizeof (u32x4);
5503 for (i = match*sizeof(u32x4); i > 0; i-= sizeof(u32x4))
5505 u64 *tmp = (u64 *)(mask + (i-sizeof(u32x4)));
5506 if (*tmp || *(tmp+1))
5511 clib_warning ("BUG: match 0");
5513 _vec_len (mask) = match * sizeof(u32x4);
5524 #define foreach_l2_next \
5526 _(ethernet, ETHERNET_INPUT) \
5530 uword unformat_l2_next_index (unformat_input_t * input, va_list * args)
5532 u32 * miss_next_indexp = va_arg (*args, u32 *);
5537 if (unformat (input, #n)) { next_index = L2_CLASSIFY_NEXT_##N; goto out;}
5541 if (unformat (input, "%d", &tmp))
5550 *miss_next_indexp = next_index;
5554 #define foreach_ip_next \
5560 uword unformat_ip_next_index (unformat_input_t * input, va_list * args)
5562 u32 * miss_next_indexp = va_arg (*args, u32 *);
5567 if (unformat (input, #n)) { next_index = IP_LOOKUP_NEXT_##N; goto out;}
5571 if (unformat (input, "%d", &tmp))
5580 *miss_next_indexp = next_index;
5584 #define foreach_acl_next \
5587 uword unformat_acl_next_index (unformat_input_t * input, va_list * args)
5589 u32 * miss_next_indexp = va_arg (*args, u32 *);
5594 if (unformat (input, #n)) { next_index = ACL_NEXT_INDEX_##N; goto out;}
5598 if (unformat (input, "permit"))
5603 else if (unformat (input, "%d", &tmp))
5612 *miss_next_indexp = next_index;
5616 static int api_classify_add_del_table (vat_main_t * vam)
5618 unformat_input_t * i = vam->input;
5619 vl_api_classify_add_del_table_t *mp;
5625 u32 table_index = ~0;
5626 u32 next_table_index = ~0;
5627 u32 miss_next_index = ~0;
5628 u32 memory_size = 32<<20;
5632 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
5633 if (unformat (i, "del"))
5635 else if (unformat (i, "buckets %d", &nbuckets))
5637 else if (unformat (i, "memory_size %d", &memory_size))
5639 else if (unformat (i, "skip %d", &skip))
5641 else if (unformat (i, "match %d", &match))
5643 else if (unformat (i, "table %d", &table_index))
5645 else if (unformat (i, "mask %U", unformat_classify_mask,
5646 &mask, &skip, &match))
5648 else if (unformat (i, "next-table %d", &next_table_index))
5650 else if (unformat (i, "miss-next %U", unformat_ip_next_index,
5653 else if (unformat (i, "l2-miss-next %U", unformat_l2_next_index,
5656 else if (unformat (i, "acl-miss-next %U", unformat_acl_next_index,
5663 if (is_add && mask == 0) {
5664 errmsg ("Mask required\n");
5668 if (is_add && skip == ~0) {
5669 errmsg ("skip count required\n");
5673 if (is_add && match == ~0) {
5674 errmsg ("match count required\n");
5678 if (!is_add && table_index == ~0) {
5679 errmsg ("table index required for delete\n");
5683 M2 (CLASSIFY_ADD_DEL_TABLE, classify_add_del_table,
5686 mp->is_add = is_add;
5687 mp->table_index = ntohl(table_index);
5688 mp->nbuckets = ntohl(nbuckets);
5689 mp->memory_size = ntohl(memory_size);
5690 mp->skip_n_vectors = ntohl(skip);
5691 mp->match_n_vectors = ntohl(match);
5692 mp->next_table_index = ntohl(next_table_index);
5693 mp->miss_next_index = ntohl(miss_next_index);
5694 memcpy (mp->mask, mask, vec_len(mask));
5702 uword unformat_ip4_match (unformat_input_t * input, va_list * args)
5704 u8 ** matchp = va_arg (*args, u8 **);
5711 int src = 0, dst = 0;
5712 ip4_address_t src_val, dst_val;
5719 int fragment_id = 0;
5720 u32 fragment_id_val;
5726 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
5728 if (unformat (input, "version %d", &version_val))
5730 else if (unformat (input, "hdr_length %d", &hdr_length_val))
5732 else if (unformat (input, "src %U", unformat_ip4_address, &src_val))
5734 else if (unformat (input, "dst %U", unformat_ip4_address, &dst_val))
5736 else if (unformat (input, "proto %d", &proto_val))
5738 else if (unformat (input, "tos %d", &tos_val))
5740 else if (unformat (input, "length %d", &length_val))
5742 else if (unformat (input, "fragment_id %d", &fragment_id_val))
5744 else if (unformat (input, "ttl %d", &ttl_val))
5746 else if (unformat (input, "checksum %d", &checksum_val))
5752 if (version + hdr_length + src + dst + proto + tos + length + fragment_id
5753 + ttl + checksum == 0)
5757 * Aligned because we use the real comparison functions
5759 vec_validate_aligned (match, sizeof (*ip) - 1, sizeof(u32x4));
5761 ip = (ip4_header_t *) match;
5763 /* These are realistically matched in practice */
5765 ip->src_address.as_u32 = src_val.as_u32;
5768 ip->dst_address.as_u32 = dst_val.as_u32;
5771 ip->protocol = proto_val;
5774 /* These are not, but they're included for completeness */
5776 ip->ip_version_and_header_length |= (version_val & 0xF)<<4;
5779 ip->ip_version_and_header_length |= (hdr_length_val & 0xF);
5785 ip->length = length_val;
5791 ip->checksum = checksum_val;
5797 uword unformat_ip6_match (unformat_input_t * input, va_list * args)
5799 u8 ** matchp = va_arg (*args, u8 **);
5805 u32 traffic_class_val;
5808 int src = 0, dst = 0;
5809 ip6_address_t src_val, dst_val;
5812 int payload_length = 0;
5813 u32 payload_length_val;
5816 u32 ip_version_traffic_class_and_flow_label;
5818 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
5820 if (unformat (input, "version %d", &version_val))
5822 else if (unformat (input, "traffic_class %d", &traffic_class_val))
5824 else if (unformat (input, "flow_label %d", &flow_label_val))
5826 else if (unformat (input, "src %U", unformat_ip6_address, &src_val))
5828 else if (unformat (input, "dst %U", unformat_ip6_address, &dst_val))
5830 else if (unformat (input, "proto %d", &proto_val))
5832 else if (unformat (input, "payload_length %d", &payload_length_val))
5834 else if (unformat (input, "hop_limit %d", &hop_limit_val))
5840 if (version + traffic_class + flow_label + src + dst + proto +
5841 payload_length + hop_limit == 0)
5845 * Aligned because we use the real comparison functions
5847 vec_validate_aligned (match, sizeof (*ip) - 1, sizeof(u32x4));
5849 ip = (ip6_header_t *) match;
5852 memcpy (&ip->src_address, &src_val, sizeof (ip->src_address));
5855 memcpy (&ip->dst_address, &dst_val, sizeof (ip->dst_address));
5858 ip->protocol = proto_val;
5860 ip_version_traffic_class_and_flow_label = 0;
5863 ip_version_traffic_class_and_flow_label |= (version_val & 0xF) << 28;
5866 ip_version_traffic_class_and_flow_label |= (traffic_class_val & 0xFF) << 20;
5869 ip_version_traffic_class_and_flow_label |= (flow_label_val & 0xFFFFF);
5871 ip->ip_version_traffic_class_and_flow_label =
5872 clib_host_to_net_u32 (ip_version_traffic_class_and_flow_label);
5875 ip->payload_length = clib_host_to_net_u16 (payload_length_val);
5878 ip->hop_limit = hop_limit_val;
5884 uword unformat_l3_match (unformat_input_t * input, va_list * args)
5886 u8 ** matchp = va_arg (*args, u8 **);
5888 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) {
5889 if (unformat (input, "ip4 %U", unformat_ip4_match, matchp))
5891 else if (unformat (input, "ip6 %U", unformat_ip6_match, matchp))
5899 uword unformat_vlan_tag (unformat_input_t * input, va_list * args)
5901 u8 * tagp = va_arg (*args, u8 *);
5904 if (unformat(input, "%d", &tag))
5906 tagp[0] = (tag>>8) & 0x0F;
5907 tagp[1] = tag & 0xFF;
5914 uword unformat_l2_match (unformat_input_t * input, va_list * args)
5916 u8 ** matchp = va_arg (*args, u8 **);
5936 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) {
5937 if (unformat (input, "src %U", unformat_ethernet_address, &src_val))
5939 else if (unformat (input, "dst %U", unformat_ethernet_address, &dst_val))
5941 else if (unformat (input, "proto %U",
5942 unformat_ethernet_type_host_byte_order, &proto_val))
5944 else if (unformat (input, "tag1 %U", unformat_vlan_tag, tag1_val))
5946 else if (unformat (input, "tag2 %U", unformat_vlan_tag, tag2_val))
5948 else if (unformat (input, "ignore-tag1"))
5950 else if (unformat (input, "ignore-tag2"))
5952 else if (unformat (input, "cos1 %d", &cos1_val))
5954 else if (unformat (input, "cos2 %d", &cos2_val))
5959 if ((src + dst + proto + tag1 + tag2 +
5960 ignore_tag1 + ignore_tag2 + cos1 + cos2) == 0)
5963 if (tag1 || ignore_tag1 || cos1)
5965 if (tag2 || ignore_tag2 || cos2)
5968 vec_validate_aligned (match, len-1, sizeof(u32x4));
5971 memcpy (match, dst_val, 6);
5974 memcpy (match + 6, src_val, 6);
5978 /* inner vlan tag */
5979 match[19] = tag2_val[1];
5980 match[18] = tag2_val[0];
5982 match [18] |= (cos2_val & 0x7) << 5;
5985 match[21] = proto_val & 0xff;
5986 match[20] = proto_val >> 8;
5990 match [15] = tag1_val[1];
5991 match [14] = tag1_val[0];
5994 match [14] |= (cos1_val & 0x7) << 5;
6000 match [15] = tag1_val[1];
6001 match [14] = tag1_val[0];
6004 match[17] = proto_val & 0xff;
6005 match[16] = proto_val >> 8;
6008 match [14] |= (cos1_val & 0x7) << 5;
6014 match [18] |= (cos2_val & 0x7) << 5;
6016 match [14] |= (cos1_val & 0x7) << 5;
6019 match[13] = proto_val & 0xff;
6020 match[12] = proto_val >> 8;
6028 uword unformat_classify_match (unformat_input_t * input, va_list * args)
6030 u8 ** matchp = va_arg (*args, u8 **);
6031 u32 skip_n_vectors = va_arg (*args, u32);
6032 u32 match_n_vectors = va_arg (*args, u32);
6038 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) {
6039 if (unformat (input, "hex %U", unformat_hex_string, &match))
6041 else if (unformat (input, "l2 %U", unformat_l2_match, &l2))
6043 else if (unformat (input, "l3 %U", unformat_l3_match, &l3))
6049 if (match || l2 || l3)
6053 /* "Win a free Ethernet header in every packet" */
6055 vec_validate_aligned (l2, 13, sizeof(u32x4));
6057 vec_append_aligned (match, l3, sizeof(u32x4));
6061 /* Make sure the vector is big enough even if key is all 0's */
6062 vec_validate_aligned
6063 (match, ((match_n_vectors + skip_n_vectors) * sizeof(u32x4)) - 1,
6066 /* Set size, include skipped vectors*/
6067 _vec_len (match) = (match_n_vectors+skip_n_vectors) * sizeof(u32x4);
6077 static int api_classify_add_del_session (vat_main_t * vam)
6079 unformat_input_t * i = vam->input;
6080 vl_api_classify_add_del_session_t *mp;
6082 u32 table_index = ~0;
6083 u32 hit_next_index = ~0;
6084 u32 opaque_index = ~0;
6088 u32 skip_n_vectors = 0;
6089 u32 match_n_vectors = 0;
6092 * Warning: you have to supply skip_n and match_n
6093 * because the API client cant simply look at the classify
6097 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
6098 if (unformat (i, "del"))
6100 else if (unformat (i, "hit-next %U", unformat_ip_next_index,
6103 else if (unformat (i, "l2-hit-next %U", unformat_l2_next_index,
6106 else if (unformat (i, "acl-hit-next %U", unformat_acl_next_index,
6109 else if (unformat (i, "opaque-index %d", &opaque_index))
6111 else if (unformat (i, "skip_n %d", &skip_n_vectors))
6113 else if (unformat (i, "match_n %d", &match_n_vectors))
6115 else if (unformat (i, "match %U", unformat_classify_match,
6116 &match, skip_n_vectors, match_n_vectors))
6118 else if (unformat (i, "advance %d", &advance))
6120 else if (unformat (i, "table-index %d", &table_index))
6126 if (table_index == ~0) {
6127 errmsg ("Table index required\n");
6131 if (is_add && match == 0) {
6132 errmsg ("Match value required\n");
6136 M2 (CLASSIFY_ADD_DEL_SESSION, classify_add_del_session,
6139 mp->is_add = is_add;
6140 mp->table_index = ntohl(table_index);
6141 mp->hit_next_index = ntohl(hit_next_index);
6142 mp->opaque_index = ntohl(opaque_index);
6143 mp->advance = ntohl(advance);
6144 memcpy (mp->match, match, vec_len(match));
6151 static int api_classify_set_interface_ip_table (vat_main_t * vam)
6153 unformat_input_t * i = vam->input;
6154 vl_api_classify_set_interface_ip_table_t *mp;
6157 int sw_if_index_set;
6158 u32 table_index = ~0;
6161 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
6162 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
6163 sw_if_index_set = 1;
6164 else if (unformat (i, "sw_if_index %d", &sw_if_index))
6165 sw_if_index_set = 1;
6166 else if (unformat (i, "table %d", &table_index))
6169 clib_warning ("parse error '%U'", format_unformat_error, i);
6174 if (sw_if_index_set == 0) {
6175 errmsg ("missing interface name or sw_if_index\n");
6180 M(CLASSIFY_SET_INTERFACE_IP_TABLE, classify_set_interface_ip_table);
6182 mp->sw_if_index = ntohl(sw_if_index);
6183 mp->table_index = ntohl(table_index);
6184 mp->is_ipv6 = is_ipv6;
6191 static int api_classify_set_interface_l2_tables (vat_main_t * vam)
6193 unformat_input_t * i = vam->input;
6194 vl_api_classify_set_interface_l2_tables_t *mp;
6197 int sw_if_index_set;
6198 u32 ip4_table_index = ~0;
6199 u32 ip6_table_index = ~0;
6200 u32 other_table_index = ~0;
6202 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
6203 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
6204 sw_if_index_set = 1;
6205 else if (unformat (i, "sw_if_index %d", &sw_if_index))
6206 sw_if_index_set = 1;
6207 else if (unformat (i, "ip4-table %d", &ip4_table_index))
6209 else if (unformat (i, "ip6-table %d", &ip6_table_index))
6211 else if (unformat (i, "other-table %d", &other_table_index))
6214 clib_warning ("parse error '%U'", format_unformat_error, i);
6219 if (sw_if_index_set == 0) {
6220 errmsg ("missing interface name or sw_if_index\n");
6225 M(CLASSIFY_SET_INTERFACE_L2_TABLES, classify_set_interface_l2_tables);
6227 mp->sw_if_index = ntohl(sw_if_index);
6228 mp->ip4_table_index = ntohl(ip4_table_index);
6229 mp->ip6_table_index = ntohl(ip6_table_index);
6230 mp->other_table_index = ntohl(other_table_index);
6238 static int api_get_node_index (vat_main_t * vam)
6240 unformat_input_t * i = vam->input;
6241 vl_api_get_node_index_t * mp;
6245 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
6246 if (unformat (i, "node %s", &name))
6252 errmsg ("node name required\n");
6255 if (vec_len (name) >= ARRAY_LEN(mp->node_name)) {
6256 errmsg ("node name too long, max %d\n", ARRAY_LEN(mp->node_name));
6260 M(GET_NODE_INDEX, get_node_index);
6261 memcpy (mp->node_name, name, vec_len(name));
6269 static int api_add_node_next (vat_main_t * vam)
6271 unformat_input_t * i = vam->input;
6272 vl_api_add_node_next_t * mp;
6277 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
6278 if (unformat (i, "node %s", &name))
6280 else if (unformat (i, "next %s", &next))
6286 errmsg ("node name required\n");
6289 if (vec_len (name) >= ARRAY_LEN(mp->node_name)) {
6290 errmsg ("node name too long, max %d\n", ARRAY_LEN(mp->node_name));
6294 errmsg ("next node required\n");
6297 if (vec_len (next) >= ARRAY_LEN(mp->next_name)) {
6298 errmsg ("next name too long, max %d\n", ARRAY_LEN(mp->next_name));
6302 M(ADD_NODE_NEXT, add_node_next);
6303 memcpy (mp->node_name, name, vec_len(name));
6304 memcpy (mp->next_name, next, vec_len(next));
6313 static int api_l2tpv3_create_tunnel (vat_main_t * vam)
6315 unformat_input_t * i = vam->input;
6316 ip6_address_t client_address, our_address;
6317 int client_address_set = 0;
6318 int our_address_set = 0;
6319 u32 local_session_id = 0;
6320 u32 remote_session_id = 0;
6321 u64 local_cookie = 0;
6322 u64 remote_cookie = 0;
6323 u8 l2_sublayer_present = 0;
6324 vl_api_l2tpv3_create_tunnel_t * mp;
6327 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
6328 if (unformat (i, "client_address %U", unformat_ip6_address,
6330 client_address_set = 1;
6331 else if (unformat (i, "our_address %U", unformat_ip6_address,
6333 our_address_set = 1;
6334 else if (unformat (i, "local_session_id %d", &local_session_id))
6336 else if (unformat (i, "remote_session_id %d", &remote_session_id))
6338 else if (unformat (i, "local_cookie %lld", &local_cookie))
6340 else if (unformat (i, "remote_cookie %lld", &remote_cookie))
6342 else if (unformat (i, "l2-sublayer-present"))
6343 l2_sublayer_present = 1;
6348 if (client_address_set == 0) {
6349 errmsg ("client_address required\n");
6353 if (our_address_set == 0) {
6354 errmsg ("our_address required\n");
6358 M(L2TPV3_CREATE_TUNNEL, l2tpv3_create_tunnel);
6360 memcpy (mp->client_address, client_address.as_u8,
6361 sizeof (mp->client_address));
6363 memcpy (mp->our_address, our_address.as_u8,
6364 sizeof (mp->our_address));
6366 mp->local_session_id = ntohl (local_session_id);
6367 mp->remote_session_id = ntohl (remote_session_id);
6368 mp->local_cookie = clib_host_to_net_u64 (local_cookie);
6369 mp->remote_cookie = clib_host_to_net_u64 (remote_cookie);
6370 mp->l2_sublayer_present = l2_sublayer_present;
6378 static int api_l2tpv3_set_tunnel_cookies (vat_main_t * vam)
6380 unformat_input_t * i = vam->input;
6382 u8 sw_if_index_set = 0;
6383 u64 new_local_cookie = 0;
6384 u64 new_remote_cookie = 0;
6385 vl_api_l2tpv3_set_tunnel_cookies_t *mp;
6388 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
6389 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
6390 sw_if_index_set = 1;
6391 else if (unformat (i, "sw_if_index %d", &sw_if_index))
6392 sw_if_index_set = 1;
6393 else if (unformat (i, "new_local_cookie %lld", &new_local_cookie))
6395 else if (unformat (i, "new_remote_cookie %lld", &new_remote_cookie))
6401 if (sw_if_index_set == 0) {
6402 errmsg ("missing interface name or sw_if_index\n");
6406 M(L2TPV3_SET_TUNNEL_COOKIES, l2tpv3_set_tunnel_cookies);
6408 mp->sw_if_index = ntohl(sw_if_index);
6409 mp->new_local_cookie = clib_host_to_net_u64 (new_local_cookie);
6410 mp->new_remote_cookie = clib_host_to_net_u64 (new_remote_cookie);
6417 static int api_l2tpv3_interface_enable_disable (vat_main_t * vam)
6419 unformat_input_t * i = vam->input;
6420 vl_api_l2tpv3_interface_enable_disable_t *mp;
6423 u8 sw_if_index_set = 0;
6424 u8 enable_disable = 1;
6426 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
6427 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
6428 sw_if_index_set = 1;
6429 else if (unformat (i, "sw_if_index %d", &sw_if_index))
6430 sw_if_index_set = 1;
6431 else if (unformat (i, "enable"))
6433 else if (unformat (i, "disable"))
6439 if (sw_if_index_set == 0) {
6440 errmsg ("missing interface name or sw_if_index\n");
6444 M(L2TPV3_INTERFACE_ENABLE_DISABLE, l2tpv3_interface_enable_disable);
6446 mp->sw_if_index = ntohl(sw_if_index);
6447 mp->enable_disable = enable_disable;
6454 static int api_l2tpv3_set_lookup_key (vat_main_t * vam)
6456 unformat_input_t * i = vam->input;
6457 vl_api_l2tpv3_set_lookup_key_t * mp;
6461 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
6462 if (unformat (i, "lookup_v6_src"))
6463 key = L2T_LOOKUP_SRC_ADDRESS;
6464 else if (unformat (i, "lookup_v6_dst"))
6465 key = L2T_LOOKUP_DST_ADDRESS;
6466 else if (unformat (i, "lookup_session_id"))
6467 key = L2T_LOOKUP_SESSION_ID;
6473 errmsg ("l2tp session lookup key unset\n");
6477 M(L2TPV3_SET_LOOKUP_KEY, l2tpv3_set_lookup_key);
6486 static void vl_api_sw_if_l2tpv3_tunnel_details_t_handler
6487 (vl_api_sw_if_l2tpv3_tunnel_details_t * mp)
6489 vat_main_t * vam = &vat_main;
6491 fformat(vam->ofp, "* %U (our) %U (client) (sw_if_index %d)\n",
6492 format_ip6_address, mp->our_address,
6493 format_ip6_address, mp->client_address,
6494 clib_net_to_host_u32(mp->sw_if_index));
6496 fformat (vam->ofp, " local cookies %016llx %016llx remote cookie %016llx\n",
6497 clib_net_to_host_u64 (mp->local_cookie[0]),
6498 clib_net_to_host_u64 (mp->local_cookie[1]),
6499 clib_net_to_host_u64 (mp->remote_cookie));
6501 fformat (vam->ofp, " local session-id %d remote session-id %d\n",
6502 clib_net_to_host_u32 (mp->local_session_id),
6503 clib_net_to_host_u32 (mp->remote_session_id));
6505 fformat (vam->ofp, " l2 specific sublayer %s\n\n",
6506 mp->l2_sublayer_present ? "preset" : "absent");
6510 static void vl_api_sw_if_l2tpv3_tunnel_details_t_handler_json
6511 (vl_api_sw_if_l2tpv3_tunnel_details_t * mp)
6513 vat_main_t * vam = &vat_main;
6514 vat_json_node_t *node = NULL;
6515 struct in6_addr addr;
6517 if (VAT_JSON_ARRAY != vam->json_tree.type) {
6518 ASSERT(VAT_JSON_NONE == vam->json_tree.type);
6519 vat_json_init_array(&vam->json_tree);
6521 node = vat_json_array_add(&vam->json_tree);
6523 vat_json_init_object(node);
6525 memcpy(&addr, mp->our_address, sizeof(addr));
6526 vat_json_object_add_ip6(node, "our_address", addr);
6527 memcpy(&addr, mp->client_address, sizeof(addr));
6528 vat_json_object_add_ip6(node, "client_address", addr);
6530 vat_json_node_t * lc = vat_json_object_add(node, "local_cookie");
6531 vat_json_init_array(lc);
6532 vat_json_array_add_uint(lc, clib_net_to_host_u64(mp->local_cookie[0]));
6533 vat_json_array_add_uint(lc, clib_net_to_host_u64(mp->local_cookie[1]));
6534 vat_json_object_add_uint(node, "remote_cookie", clib_net_to_host_u64(mp->remote_cookie));
6536 printf("local id: %u", clib_net_to_host_u32(mp->local_session_id));
6537 vat_json_object_add_uint(node, "local_session_id", clib_net_to_host_u32(mp->local_session_id));
6538 vat_json_object_add_uint(node, "remote_session_id", clib_net_to_host_u32(mp->remote_session_id));
6539 vat_json_object_add_string_copy(node, "l2_sublayer", mp->l2_sublayer_present ?
6540 (u8*)"present" : (u8*)"absent");
6543 static int api_sw_if_l2tpv3_tunnel_dump (vat_main_t * vam)
6545 vl_api_sw_if_l2tpv3_tunnel_dump_t *mp;
6548 /* Get list of l2tpv3-tunnel interfaces */
6549 M(SW_IF_L2TPV3_TUNNEL_DUMP, sw_if_l2tpv3_tunnel_dump);
6552 /* Use a control ping for synchronization */
6554 vl_api_control_ping_t * mp;
6555 M(CONTROL_PING, control_ping);
6562 static void vl_api_sw_interface_tap_details_t_handler
6563 (vl_api_sw_interface_tap_details_t * mp)
6565 vat_main_t * vam = &vat_main;
6567 fformat(vam->ofp, "%-16s %d\n",
6569 clib_net_to_host_u32(mp->sw_if_index));
6572 static void vl_api_sw_interface_tap_details_t_handler_json
6573 (vl_api_sw_interface_tap_details_t * mp)
6575 vat_main_t * vam = &vat_main;
6576 vat_json_node_t *node = NULL;
6578 if (VAT_JSON_ARRAY != vam->json_tree.type) {
6579 ASSERT(VAT_JSON_NONE == vam->json_tree.type);
6580 vat_json_init_array(&vam->json_tree);
6582 node = vat_json_array_add(&vam->json_tree);
6584 vat_json_init_object(node);
6585 vat_json_object_add_uint(node, "sw_if_index", ntohl(mp->sw_if_index));
6586 vat_json_object_add_string_copy(node, "dev_name", mp->dev_name);
6589 static int api_sw_interface_tap_dump (vat_main_t * vam)
6591 vl_api_sw_interface_tap_dump_t *mp;
6594 fformat(vam->ofp, "\n%-16s %s\n", "dev_name", "sw_if_index");
6595 /* Get list of tap interfaces */
6596 M(SW_INTERFACE_TAP_DUMP, sw_interface_tap_dump);
6599 /* Use a control ping for synchronization */
6601 vl_api_control_ping_t * mp;
6602 M(CONTROL_PING, control_ping);
6608 static uword unformat_vxlan_decap_next
6609 (unformat_input_t * input, va_list * args)
6611 u32 * result = va_arg (*args, u32 *);
6614 if (unformat (input, "drop"))
6615 *result = VXLAN_INPUT_NEXT_DROP;
6616 else if (unformat (input, "ip4"))
6617 *result = VXLAN_INPUT_NEXT_IP4_INPUT;
6618 else if (unformat (input, "ip6"))
6619 *result = VXLAN_INPUT_NEXT_IP6_INPUT;
6620 else if (unformat (input, "l2"))
6621 *result = VXLAN_INPUT_NEXT_L2_INPUT;
6622 else if (unformat (input, "%d", &tmp))
6629 static int api_vxlan_add_del_tunnel (vat_main_t * vam)
6631 unformat_input_t * line_input = vam->input;
6632 vl_api_vxlan_add_del_tunnel_t *mp;
6634 ip4_address_t src, dst;
6638 u32 encap_vrf_id = 0;
6639 u32 decap_next_index = ~0;
6642 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) {
6643 if (unformat (line_input, "del"))
6645 else if (unformat (line_input, "src %U",
6646 unformat_ip4_address, &src))
6648 else if (unformat (line_input, "dst %U",
6649 unformat_ip4_address, &dst))
6651 else if (unformat (line_input, "encap-vrf-id %d", &encap_vrf_id))
6653 else if (unformat (line_input, "decap-next %U",
6654 unformat_vxlan_decap_next, &decap_next_index))
6656 else if (unformat (line_input, "vni %d", &vni))
6659 errmsg ("parse error '%U'\n", format_unformat_error, line_input);
6665 errmsg ("tunnel src address not specified\n");
6669 errmsg ("tunnel dst address not specified\n");
6673 if ((vni == 0) || (vni>>24)) {
6674 errmsg ("vni not specified or out of range\n");
6678 M (VXLAN_ADD_DEL_TUNNEL, vxlan_add_del_tunnel);
6680 mp->src_address = src.as_u32;
6681 mp->dst_address = dst.as_u32;
6682 mp->encap_vrf_id = ntohl(encap_vrf_id);
6683 mp->decap_next_index = ntohl(decap_next_index);
6684 mp->vni = ntohl(vni);
6685 mp->is_add = is_add;
6692 static void vl_api_vxlan_tunnel_details_t_handler
6693 (vl_api_vxlan_tunnel_details_t * mp)
6695 vat_main_t * vam = &vat_main;
6697 fformat(vam->ofp, "%11d%13U%13U%14d%18d%13d\n",
6698 ntohl(mp->sw_if_index),
6699 format_ip4_address, &mp->src_address,
6700 format_ip4_address, &mp->dst_address,
6701 ntohl(mp->encap_vrf_id),
6702 ntohl(mp->decap_next_index),
6706 static void vl_api_vxlan_tunnel_details_t_handler_json
6707 (vl_api_vxlan_tunnel_details_t * mp)
6709 vat_main_t * vam = &vat_main;
6710 vat_json_node_t *node = NULL;
6713 if (VAT_JSON_ARRAY != vam->json_tree.type) {
6714 ASSERT(VAT_JSON_NONE == vam->json_tree.type);
6715 vat_json_init_array(&vam->json_tree);
6717 node = vat_json_array_add(&vam->json_tree);
6719 vat_json_init_object(node);
6720 vat_json_object_add_uint(node, "sw_if_index", ntohl(mp->sw_if_index));
6721 memcpy(&ip4, &mp->src_address, sizeof(ip4));
6722 vat_json_object_add_ip4(node, "src_address", ip4);
6723 memcpy(&ip4, &mp->dst_address, sizeof(ip4));
6724 vat_json_object_add_ip4(node, "dst_address", ip4);
6725 vat_json_object_add_uint(node, "encap_vrf_id", ntohl(mp->encap_vrf_id));
6726 vat_json_object_add_uint(node, "decap_next_index", ntohl(mp->decap_next_index));
6727 vat_json_object_add_uint(node, "vni", ntohl(mp->vni));
6730 static int api_vxlan_tunnel_dump (vat_main_t * vam)
6732 unformat_input_t * i = vam->input;
6733 vl_api_vxlan_tunnel_dump_t *mp;
6736 u8 sw_if_index_set = 0;
6738 /* Parse args required to build the message */
6739 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
6740 if (unformat (i, "sw_if_index %d", &sw_if_index))
6741 sw_if_index_set = 1;
6746 if (sw_if_index_set == 0) {
6750 if (!vam->json_output) {
6751 fformat(vam->ofp, "%11s%13s%13s%14s%18s%13s\n",
6752 "sw_if_index", "src_address", "dst_address",
6753 "encap_vrf_id", "decap_next_index", "vni");
6756 /* Get list of l2tpv3-tunnel interfaces */
6757 M(VXLAN_TUNNEL_DUMP, vxlan_tunnel_dump);
6759 mp->sw_if_index = htonl(sw_if_index);
6763 /* Use a control ping for synchronization */
6765 vl_api_control_ping_t * mp;
6766 M(CONTROL_PING, control_ping);
6772 static int api_l2_fib_clear_table (vat_main_t * vam)
6774 // unformat_input_t * i = vam->input;
6775 vl_api_l2_fib_clear_table_t *mp;
6778 M(L2_FIB_CLEAR_TABLE, l2_fib_clear_table);
6785 static int api_l2_interface_efp_filter (vat_main_t * vam)
6787 unformat_input_t * i = vam->input;
6788 vl_api_l2_interface_efp_filter_t *mp;
6792 u8 sw_if_index_set = 0;
6794 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
6795 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
6796 sw_if_index_set = 1;
6797 else if (unformat (i, "sw_if_index %d", &sw_if_index))
6798 sw_if_index_set = 1;
6799 else if (unformat (i, "enable"))
6801 else if (unformat (i, "disable"))
6804 clib_warning ("parse error '%U'", format_unformat_error, i);
6809 if (sw_if_index_set == 0) {
6810 errmsg ("missing sw_if_index\n");
6814 M(L2_INTERFACE_EFP_FILTER, l2_interface_efp_filter);
6816 mp->sw_if_index = ntohl(sw_if_index);
6817 mp->enable_disable = enable;
6824 #define foreach_vtr_op \
6825 _("disable", L2_VTR_DISABLED) \
6826 _("push-1", L2_VTR_PUSH_1) \
6827 _("push-2", L2_VTR_PUSH_2) \
6828 _("pop-1", L2_VTR_POP_1) \
6829 _("pop-2", L2_VTR_POP_2) \
6830 _("translate-1-1", L2_VTR_TRANSLATE_1_1) \
6831 _("translate-1-2", L2_VTR_TRANSLATE_1_2) \
6832 _("translate-2-1", L2_VTR_TRANSLATE_2_1) \
6833 _("translate-2-2", L2_VTR_TRANSLATE_2_2)
6835 static int api_l2_interface_vlan_tag_rewrite (vat_main_t * vam)
6837 unformat_input_t * i = vam->input;
6838 vl_api_l2_interface_vlan_tag_rewrite_t *mp;
6841 u8 sw_if_index_set = 0;
6848 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
6849 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
6850 sw_if_index_set = 1;
6851 else if (unformat (i, "sw_if_index %d", &sw_if_index))
6852 sw_if_index_set = 1;
6853 else if (unformat (i, "vtr_op %d", &vtr_op))
6855 #define _(n,v) else if (unformat(i, n)) {vtr_op = v; vtr_op_set = 1;}
6859 else if (unformat (i, "push_dot1q %d", &push_dot1q))
6861 else if (unformat (i, "tag1 %d", &tag1))
6863 else if (unformat (i, "tag2 %d", &tag2))
6866 clib_warning ("parse error '%U'", format_unformat_error, i);
6871 if ((sw_if_index_set == 0)||(vtr_op_set == 0)) {
6872 errmsg ("missing vtr operation or sw_if_index\n");
6876 M(L2_INTERFACE_VLAN_TAG_REWRITE, l2_interface_vlan_tag_rewrite)
6878 mp->sw_if_index = ntohl(sw_if_index);
6879 mp->vtr_op = ntohl(vtr_op);
6880 mp->push_dot1q = ntohl(push_dot1q);
6881 mp->tag1 = ntohl(tag1);
6882 mp->tag2 = ntohl(tag2);
6889 static int api_create_vhost_user_if (vat_main_t * vam)
6891 unformat_input_t * i = vam->input;
6892 vl_api_create_vhost_user_if_t *mp;
6896 u8 file_name_set = 0;
6897 u32 custom_dev_instance = ~0;
6899 u8 use_custom_mac = 0;
6901 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
6902 if (unformat (i, "socket %s", &file_name)) {
6905 else if (unformat (i, "renumber %"PRIu32, &custom_dev_instance))
6907 else if (unformat (i, "mac %U", unformat_ethernet_address, hwaddr))
6909 else if (unformat (i, "server"))
6915 if (file_name_set == 0) {
6916 errmsg ("missing socket file name\n");
6920 if (vec_len (file_name) > 255) {
6921 errmsg ("socket file name too long\n");
6924 vec_add1 (file_name, 0);
6926 M(CREATE_VHOST_USER_IF, create_vhost_user_if);
6928 mp->is_server = is_server;
6929 memcpy(mp->sock_filename, file_name, vec_len(file_name));
6930 vec_free(file_name);
6931 if (custom_dev_instance != ~0) {
6933 mp->custom_dev_instance = ntohl(custom_dev_instance);
6935 mp->use_custom_mac = use_custom_mac;
6936 memcpy(mp->mac_address, hwaddr, 6);
6943 static int api_modify_vhost_user_if (vat_main_t * vam)
6945 unformat_input_t * i = vam->input;
6946 vl_api_modify_vhost_user_if_t *mp;
6950 u8 file_name_set = 0;
6951 u32 custom_dev_instance = ~0;
6952 u8 sw_if_index_set = 0;
6953 u32 sw_if_index = (u32)~0;
6955 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
6956 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
6957 sw_if_index_set = 1;
6958 else if (unformat (i, "sw_if_index %d", &sw_if_index))
6959 sw_if_index_set = 1;
6960 else if (unformat (i, "socket %s", &file_name)) {
6963 else if (unformat (i, "renumber %"PRIu32, &custom_dev_instance))
6965 else if (unformat (i, "server"))
6971 if (sw_if_index_set == 0) {
6972 errmsg ("missing sw_if_index or interface name\n");
6976 if (file_name_set == 0) {
6977 errmsg ("missing socket file name\n");
6981 if (vec_len (file_name) > 255) {
6982 errmsg ("socket file name too long\n");
6985 vec_add1 (file_name, 0);
6987 M(MODIFY_VHOST_USER_IF, modify_vhost_user_if);
6989 mp->sw_if_index = ntohl(sw_if_index);
6990 mp->is_server = is_server;
6991 memcpy(mp->sock_filename, file_name, vec_len(file_name));
6992 vec_free(file_name);
6993 if (custom_dev_instance != ~0) {
6995 mp->custom_dev_instance = ntohl(custom_dev_instance);
7003 static int api_delete_vhost_user_if (vat_main_t * vam)
7005 unformat_input_t * i = vam->input;
7006 vl_api_delete_vhost_user_if_t *mp;
7008 u32 sw_if_index = ~0;
7009 u8 sw_if_index_set = 0;
7011 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
7012 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
7013 sw_if_index_set = 1;
7014 else if (unformat (i, "sw_if_index %d", &sw_if_index))
7015 sw_if_index_set = 1;
7020 if (sw_if_index_set == 0) {
7021 errmsg ("missing sw_if_index or interface name\n");
7026 M(DELETE_VHOST_USER_IF, delete_vhost_user_if);
7028 mp->sw_if_index = ntohl(sw_if_index);
7035 static void vl_api_sw_interface_vhost_user_details_t_handler
7036 (vl_api_sw_interface_vhost_user_details_t * mp)
7038 vat_main_t * vam = &vat_main;
7040 fformat(vam->ofp, "%-25s %3" PRIu32 " %6" PRIu32 " %8x %6d %7d %s\n",
7041 (char *)mp->interface_name,
7042 ntohl(mp->sw_if_index), ntohl(mp->virtio_net_hdr_sz),
7043 clib_net_to_host_u64(mp->features), mp->is_server,
7044 ntohl(mp->num_regions), (char *)mp->sock_filename);
7045 fformat(vam->ofp, " Status: '%s'\n", strerror(ntohl(mp->sock_errno)));
7048 static void vl_api_sw_interface_vhost_user_details_t_handler_json
7049 (vl_api_sw_interface_vhost_user_details_t * mp)
7051 vat_main_t * vam = &vat_main;
7052 vat_json_node_t *node = NULL;
7054 if (VAT_JSON_ARRAY != vam->json_tree.type) {
7055 ASSERT(VAT_JSON_NONE == vam->json_tree.type);
7056 vat_json_init_array(&vam->json_tree);
7058 node = vat_json_array_add(&vam->json_tree);
7060 vat_json_init_object(node);
7061 vat_json_object_add_uint(node, "sw_if_index", ntohl(mp->sw_if_index));
7062 vat_json_object_add_string_copy(node, "interface_name", mp->interface_name);
7063 vat_json_object_add_uint(node, "virtio_net_hdr_sz", ntohl(mp->virtio_net_hdr_sz));
7064 vat_json_object_add_uint(node, "features", clib_net_to_host_u64(mp->features));
7065 vat_json_object_add_uint(node, "is_server", mp->is_server);
7066 vat_json_object_add_string_copy(node, "sock_filename", mp->sock_filename);
7067 vat_json_object_add_uint(node, "num_regions", ntohl(mp->num_regions));
7068 vat_json_object_add_uint(node, "sock_errno", ntohl(mp->sock_errno));
7071 static int api_sw_interface_vhost_user_dump (vat_main_t * vam)
7073 vl_api_sw_interface_vhost_user_dump_t *mp;
7075 fformat(vam->ofp, "Interface name idx hdr_sz features server regions filename\n");
7077 /* Get list of vhost-user interfaces */
7078 M(SW_INTERFACE_VHOST_USER_DUMP, sw_interface_vhost_user_dump);
7081 /* Use a control ping for synchronization */
7083 vl_api_control_ping_t * mp;
7084 M(CONTROL_PING, control_ping);
7090 static int api_show_version (vat_main_t * vam)
7092 vl_api_show_version_t *mp;
7095 M(SHOW_VERSION, show_version);
7102 static uword unformat_nsh_gre_decap_next
7103 (unformat_input_t * input, va_list * args)
7105 u32 * result = va_arg (*args, u32 *);
7108 if (unformat (input, "drop"))
7109 *result = NSH_INPUT_NEXT_DROP;
7110 else if (unformat (input, "ip4"))
7111 *result = NSH_INPUT_NEXT_IP4_INPUT;
7112 else if (unformat (input, "ip6"))
7113 *result = NSH_INPUT_NEXT_IP6_INPUT;
7114 else if (unformat (input, "ethernet"))
7115 *result = NSH_INPUT_NEXT_ETHERNET_INPUT;
7116 else if (unformat (input, "%d", &tmp))
7123 static int api_nsh_gre_add_del_tunnel (vat_main_t * vam)
7125 unformat_input_t * line_input = vam->input;
7126 vl_api_nsh_gre_add_del_tunnel_t *mp;
7128 ip4_address_t src, dst;
7132 u32 encap_vrf_id = 0;
7133 u32 decap_vrf_id = 0;
7136 u8 next_protocol = 1; /* ip4 */
7147 u32 decap_next_index = NSH_INPUT_NEXT_IP4_INPUT;
7151 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) {
7152 if (unformat (line_input, "del"))
7154 else if (unformat (line_input, "src %U",
7155 unformat_ip4_address, &src))
7157 else if (unformat (line_input, "dst %U",
7158 unformat_ip4_address, &dst))
7160 else if (unformat (line_input, "encap-vrf-id %d", &encap_vrf_id))
7162 else if (unformat (line_input, "decap-vrf-id %d", &decap_vrf_id))
7164 else if (unformat (line_input, "decap-next %U",
7165 unformat_nsh_gre_decap_next, &decap_next_index))
7167 else if (unformat (line_input, "version %d", &tmp))
7168 ver_o_c |= (tmp & 3) << 6;
7169 else if (unformat (line_input, "o-bit %d", &tmp))
7170 ver_o_c |= (tmp & 1) << 5;
7171 else if (unformat (line_input, "c-bit %d", &tmp))
7172 ver_o_c |= (tmp & 1) << 4;
7173 else if (unformat (line_input, "md-type %d", &tmp))
7175 else if (unformat(line_input, "next-ip4"))
7177 else if (unformat(line_input, "next-ip6"))
7179 else if (unformat(line_input, "next-ethernet"))
7181 else if (unformat (line_input, "c1 %d", &c1))
7183 else if (unformat (line_input, "c2 %d", &c2))
7185 else if (unformat (line_input, "c3 %d", &c3))
7187 else if (unformat (line_input, "c4 %d", &c4))
7189 else if (unformat (line_input, "spi %d", &spi))
7191 else if (unformat (line_input, "si %d", &si))
7193 else if (unformat (line_input, "tlv %x"))
7194 vec_add1 (tlvs, tmp);
7196 errmsg ("parse error '%U'\n", format_unformat_error, line_input);
7202 errmsg ("tunnel src address not specified\n");
7206 errmsg ("tunnel dst address not specified\n");
7211 errmsg ("spi not specified\n");
7216 errmsg ("si not specified\n");
7220 M2 (NSH_GRE_ADD_DEL_TUNNEL, nsh_gre_add_del_tunnel,
7221 sizeof(u32) * vec_len (tlvs));
7223 spi_si = (spi<<8) | si;
7225 mp->src = src.as_u32;
7226 mp->dst = dst.as_u32;
7227 mp->encap_vrf_id = ntohl(encap_vrf_id);
7228 mp->decap_vrf_id = ntohl(decap_vrf_id);
7229 mp->decap_next_index = ntohl(decap_next_index);
7230 mp->tlv_len_in_words = vec_len (tlvs);
7231 mp->is_add = is_add;
7232 mp->ver_o_c = ver_o_c;
7233 mp->length = 6 + vec_len(tlvs);
7234 mp->md_type = md_type;
7235 mp->next_protocol = next_protocol;
7236 mp->spi_si = ntohl(spi_si);
7242 for (i = 0; i < vec_len(tlvs); i++)
7243 mp->tlvs[i] = ntohl(tlvs[i]);
7252 static uword unformat_nsh_vxlan_gpe_decap_next
7253 (unformat_input_t * input, va_list * args)
7255 u32 * result = va_arg (*args, u32 *);
7258 if (unformat (input, "drop"))
7259 *result = NSH_VXLAN_GPE_INPUT_NEXT_DROP;
7260 else if (unformat (input, "ip4"))
7261 *result = NSH_VXLAN_GPE_INPUT_NEXT_IP4_INPUT;
7262 else if (unformat (input, "ip6"))
7263 *result = NSH_VXLAN_GPE_INPUT_NEXT_IP6_INPUT;
7264 else if (unformat (input, "ethernet"))
7265 *result = NSH_VXLAN_GPE_INPUT_NEXT_ETHERNET_INPUT;
7266 else if (unformat (input, "nsh-vxlan-gpe"))
7267 *result = NSH_VXLAN_GPE_INPUT_NEXT_ETHERNET_INPUT;
7268 else if (unformat (input, "%d", &tmp))
7275 static int api_nsh_vxlan_gpe_add_del_tunnel (vat_main_t * vam)
7277 unformat_input_t * line_input = vam->input;
7278 vl_api_nsh_vxlan_gpe_add_del_tunnel_t *mp;
7280 ip4_address_t src, dst;
7284 u32 encap_vrf_id = 0;
7285 u32 decap_vrf_id = 0;
7288 u8 next_protocol = 1; /* ip4 */
7299 u32 decap_next_index = NSH_INPUT_NEXT_IP4_INPUT;
7305 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) {
7306 if (unformat (line_input, "del"))
7308 else if (unformat (line_input, "src %U",
7309 unformat_ip4_address, &src))
7311 else if (unformat (line_input, "dst %U",
7312 unformat_ip4_address, &dst))
7314 else if (unformat (line_input, "encap-vrf-id %d", &encap_vrf_id))
7316 else if (unformat (line_input, "decap-vrf-id %d", &decap_vrf_id))
7318 else if (unformat (line_input, "decap-next %U",
7319 unformat_nsh_vxlan_gpe_decap_next,
7322 else if (unformat (line_input, "vni %d", &vni))
7324 else if (unformat (line_input, "version %d", &tmp))
7325 ver_o_c |= (tmp & 3) << 6;
7326 else if (unformat (line_input, "o-bit %d", &tmp))
7327 ver_o_c |= (tmp & 1) << 5;
7328 else if (unformat (line_input, "c-bit %d", &tmp))
7329 ver_o_c |= (tmp & 1) << 4;
7330 else if (unformat (line_input, "md-type %d", &tmp))
7332 else if (unformat(line_input, "next-ip4"))
7334 else if (unformat(line_input, "next-ip6"))
7336 else if (unformat(line_input, "next-ethernet"))
7338 else if (unformat (line_input, "c1 %d", &c1))
7340 else if (unformat (line_input, "c2 %d", &c2))
7342 else if (unformat (line_input, "c3 %d", &c3))
7344 else if (unformat (line_input, "c4 %d", &c4))
7346 else if (unformat (line_input, "spi %d", &spi))
7348 else if (unformat (line_input, "si %d", &si))
7350 else if (unformat (line_input, "tlv %x"))
7351 vec_add1 (tlvs, tmp);
7353 errmsg ("parse error '%U'\n", format_unformat_error, line_input);
7359 errmsg ("tunnel src address not specified\n");
7363 errmsg ("tunnel dst address not specified\n");
7368 errmsg ("spi not specified\n");
7373 errmsg ("si not specified\n");
7377 errmsg ("vni not specified\n");
7381 M2 (NSH_VXLAN_GPE_ADD_DEL_TUNNEL, nsh_vxlan_gpe_add_del_tunnel,
7382 sizeof(u32) * vec_len (tlvs));
7384 spi_si = (spi<<8) | si;
7386 mp->src = src.as_u32;
7387 mp->dst = dst.as_u32;
7388 mp->encap_vrf_id = ntohl(encap_vrf_id);
7389 mp->decap_vrf_id = ntohl(decap_vrf_id);
7390 mp->decap_next_index = ntohl(decap_next_index);
7391 mp->tlv_len_in_words = vec_len (tlvs);
7392 mp->vni = ntohl(vni);
7393 mp->is_add = is_add;
7394 mp->ver_o_c = ver_o_c;
7395 mp->length = 6 + vec_len(tlvs);
7396 mp->md_type = md_type;
7397 mp->next_protocol = next_protocol;
7398 mp->spi_si = ntohl(spi_si);
7404 for (i = 0; i < vec_len(tlvs); i++)
7405 mp->tlvs[i] = ntohl(tlvs[i]);
7414 static uword unformat_lisp_gpe_decap_next (unformat_input_t * input,
7417 u32 * result = va_arg (*args, u32 *);
7420 if (unformat (input, "drop"))
7421 *result = LISP_GPE_INPUT_NEXT_DROP;
7422 else if (unformat (input, "ip4"))
7423 *result = LISP_GPE_INPUT_NEXT_IP4_INPUT;
7424 else if (unformat (input, "ip6"))
7425 *result = LISP_GPE_INPUT_NEXT_IP6_INPUT;
7426 else if (unformat (input, "ethernet"))
7427 *result = LISP_GPE_INPUT_NEXT_IP6_INPUT;
7428 else if (unformat (input, "lisp-gpe"))
7429 *result = LISP_GPE_INPUT_NEXT_LISP_GPE_ENCAP;
7430 else if (unformat (input, "%d", &tmp))
7438 api_lisp_gpe_add_del_tunnel (vat_main_t * vam)
7440 unformat_input_t * line_input = vam->input;
7441 vl_api_lisp_gpe_add_del_tunnel_t *mp;
7443 ip4_address_t src, dst;
7447 u32 encap_vrf_id = 0;
7448 u32 decap_vrf_id = 0;
7449 u8 next_protocol = LISP_GPE_NEXT_PROTOCOL_IP4;
7450 u32 decap_next_index = LISP_GPE_INPUT_NEXT_IP4_INPUT;
7451 u8 flags = LISP_GPE_FLAGS_P;
7458 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) {
7459 if (unformat (line_input, "del"))
7461 else if (unformat (line_input, "src %U",
7462 unformat_ip4_address, &src))
7464 else if (unformat (line_input, "dst %U",
7465 unformat_ip4_address, &dst))
7467 else if (unformat (line_input, "encap-vrf-id %d", &encap_vrf_id))
7469 else if (unformat (line_input, "decap-vrf-id %d", &decap_vrf_id))
7471 else if (unformat (line_input, "decap-next %U",
7472 unformat_lisp_gpe_decap_next,
7475 else if (unformat(line_input, "next-ip4"))
7477 else if (unformat(line_input, "next-ip6"))
7479 else if (unformat(line_input, "next-ethernet"))
7481 else if (unformat(line_input, "next-nsh"))
7483 /* Allow the user to specify anything they want in the LISP hdr */
7484 else if (unformat (line_input, "ver_res %x", &tmp))
7486 else if (unformat (line_input, "res %x", &tmp))
7488 else if (unformat (line_input, "flags %x", &tmp))
7490 else if (unformat (line_input, "n-bit"))
7491 flags |= LISP_GPE_FLAGS_N;
7492 else if (unformat (line_input, "l-bit"))
7493 flags |= LISP_GPE_FLAGS_L;
7494 else if (unformat (line_input, "e-bit"))
7495 flags |= LISP_GPE_FLAGS_E;
7496 else if (unformat (line_input, "v-bit"))
7497 flags |= LISP_GPE_FLAGS_V;
7498 else if (unformat (line_input, "i-bit"))
7499 flags |= LISP_GPE_FLAGS_V;
7500 else if (unformat (line_input, "not-p-bit"))
7501 flags &= !LISP_GPE_FLAGS_P;
7502 else if (unformat (line_input, "p-bit"))
7503 flags |= LISP_GPE_FLAGS_P;
7504 else if (unformat (line_input, "o-bit"))
7505 flags |= LISP_GPE_FLAGS_O;
7506 else if (unformat (line_input, "iidx %x", &iid))
7508 else if (unformat (line_input, "iid %d", &iid))
7511 errmsg ("parse error '%U'\n", format_unformat_error, line_input);
7517 errmsg ("tunnel src address not specified\n");
7521 errmsg ("tunnel dst address not specified\n");
7525 errmsg ("iid not specified\n");
7529 M(LISP_GPE_ADD_DEL_TUNNEL, lisp_gpe_add_del_tunnel);
7531 mp->src = src.as_u32;
7532 mp->dst = dst.as_u32;
7533 mp->encap_vrf_id = ntohl(encap_vrf_id);
7534 mp->decap_vrf_id = ntohl(decap_vrf_id);
7535 mp->decap_next_index = ntohl(decap_next_index);
7536 mp->is_add = is_add;
7538 mp->ver_res = ver_res;
7540 mp->next_protocol = next_protocol;
7541 mp->iid = ntohl(iid);
7550 u8 * format_l2_fib_mac_address (u8 * s, va_list * args)
7552 u8 * a = va_arg (*args, u8 *);
7554 return format (s, "%02x:%02x:%02x:%02x:%02x:%02x",
7555 a[2], a[3], a[4], a[5], a[6], a[7]);
7558 static void vl_api_l2_fib_table_entry_t_handler
7559 (vl_api_l2_fib_table_entry_t * mp)
7561 vat_main_t * vam = &vat_main;
7563 fformat(vam->ofp, "%3" PRIu32 " %U %3" PRIu32
7565 ntohl(mp->bd_id), format_l2_fib_mac_address, &mp->mac,
7566 ntohl(mp->sw_if_index), mp->static_mac, mp->filter_mac,
7570 static void vl_api_l2_fib_table_entry_t_handler_json
7571 (vl_api_l2_fib_table_entry_t * mp)
7573 vat_main_t * vam = &vat_main;
7574 vat_json_node_t *node = NULL;
7576 if (VAT_JSON_ARRAY != vam->json_tree.type) {
7577 ASSERT(VAT_JSON_NONE == vam->json_tree.type);
7578 vat_json_init_array(&vam->json_tree);
7580 node = vat_json_array_add(&vam->json_tree);
7582 vat_json_init_object(node);
7583 vat_json_object_add_uint(node, "bd_id", ntohl(mp->bd_id));
7584 vat_json_object_add_uint(node, "mac", clib_net_to_host_u64(mp->mac));
7585 vat_json_object_add_uint(node, "sw_if_index", ntohl(mp->sw_if_index));
7586 vat_json_object_add_uint(node, "static_mac", mp->static_mac);
7587 vat_json_object_add_uint(node, "filter_mac", mp->filter_mac);
7588 vat_json_object_add_uint(node, "bvi_mac", mp->bvi_mac);
7591 static int api_l2_fib_table_dump (vat_main_t * vam)
7593 unformat_input_t * i = vam->input;
7594 vl_api_l2_fib_table_dump_t *mp;
7599 /* Parse args required to build the message */
7600 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
7601 if (unformat (i, "bd_id %d", &bd_id))
7607 if (bd_id_set == 0) {
7608 errmsg ("missing bridge domain\n");
7612 fformat(vam->ofp, "BD-ID Mac Address sw-ndx Static Filter BVI\n");
7614 /* Get list of l2 fib entries */
7615 M(L2_FIB_TABLE_DUMP, l2_fib_table_dump);
7617 mp->bd_id = ntohl(bd_id);
7620 /* Use a control ping for synchronization */
7622 vl_api_control_ping_t * mp;
7623 M(CONTROL_PING, control_ping);
7631 api_interface_name_renumber (vat_main_t * vam)
7633 unformat_input_t * line_input = vam->input;
7634 vl_api_interface_name_renumber_t *mp;
7635 u32 sw_if_index = ~0;
7637 u32 new_show_dev_instance = ~0;
7639 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) {
7640 if (unformat (line_input, "%U", unformat_sw_if_index, vam,
7643 else if (unformat (line_input, "sw_if_index %d", &sw_if_index))
7645 else if (unformat (line_input, "new_show_dev_instance %d",
7646 &new_show_dev_instance))
7652 if (sw_if_index == ~0) {
7653 errmsg ("missing interface name or sw_if_index\n");
7657 if (new_show_dev_instance == ~0) {
7658 errmsg ("missing new_show_dev_instance\n");
7662 M(INTERFACE_NAME_RENUMBER, interface_name_renumber);
7664 mp->sw_if_index = ntohl (sw_if_index);
7665 mp->new_show_dev_instance = ntohl (new_show_dev_instance);
7671 api_want_ip4_arp_events (vat_main_t * vam)
7673 unformat_input_t * line_input = vam->input;
7674 vl_api_want_ip4_arp_events_t * mp;
7676 ip4_address_t address;
7677 int address_set = 0;
7678 u32 enable_disable = 1;
7680 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) {
7681 if (unformat (line_input, "address %U",
7682 unformat_ip4_address, &address))
7684 else if (unformat (line_input, "del"))
7690 if (address_set == 0) {
7691 errmsg ("missing addresses\n");
7695 M(WANT_IP4_ARP_EVENTS, want_ip4_arp_events);
7696 mp->enable_disable = enable_disable;
7698 mp->address = address.as_u32;
7703 static int api_input_acl_set_interface (vat_main_t * vam)
7705 unformat_input_t * i = vam->input;
7706 vl_api_input_acl_set_interface_t *mp;
7709 int sw_if_index_set;
7710 u32 ip4_table_index = ~0;
7711 u32 ip6_table_index = ~0;
7712 u32 l2_table_index = ~0;
7715 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
7716 if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
7717 sw_if_index_set = 1;
7718 else if (unformat (i, "sw_if_index %d", &sw_if_index))
7719 sw_if_index_set = 1;
7720 else if (unformat (i, "del"))
7722 else if (unformat (i, "ip4-table %d", &ip4_table_index))
7724 else if (unformat (i, "ip6-table %d", &ip6_table_index))
7726 else if (unformat (i, "l2-table %d", &l2_table_index))
7729 clib_warning ("parse error '%U'", format_unformat_error, i);
7734 if (sw_if_index_set == 0) {
7735 errmsg ("missing interface name or sw_if_index\n");
7739 M(INPUT_ACL_SET_INTERFACE, input_acl_set_interface);
7741 mp->sw_if_index = ntohl(sw_if_index);
7742 mp->ip4_table_index = ntohl(ip4_table_index);
7743 mp->ip6_table_index = ntohl(ip6_table_index);
7744 mp->l2_table_index = ntohl(l2_table_index);
7745 mp->is_add = is_add;
7753 api_ip_address_dump (vat_main_t * vam)
7755 unformat_input_t * i = vam->input;
7756 vl_api_ip_address_dump_t * mp;
7757 u32 sw_if_index = ~0;
7758 u8 sw_if_index_set = 0;
7763 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
7764 if (unformat (i, "sw_if_index %d", &sw_if_index))
7765 sw_if_index_set = 1;
7766 else if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
7767 sw_if_index_set = 1;
7768 else if (unformat (i, "ipv4"))
7770 else if (unformat (i, "ipv6"))
7776 if (ipv4_set && ipv6_set) {
7777 errmsg ("ipv4 and ipv6 flags cannot be both set\n");
7781 if ((!ipv4_set) && (!ipv6_set)) {
7782 errmsg ("no ipv4 nor ipv6 flag set\n");
7786 if (sw_if_index_set == 0) {
7787 errmsg ("missing interface name or sw_if_index\n");
7791 vam->current_sw_if_index = sw_if_index;
7792 vam->is_ipv6 = ipv6_set;
7794 M(IP_ADDRESS_DUMP, ip_address_dump);
7795 mp->sw_if_index = ntohl(sw_if_index);
7796 mp->is_ipv6 = ipv6_set;
7799 /* Use a control ping for synchronization */
7801 vl_api_control_ping_t * mp;
7802 M(CONTROL_PING, control_ping);
7809 api_ip_dump (vat_main_t * vam)
7811 vl_api_ip_dump_t * mp;
7812 unformat_input_t * in = vam->input;
7819 while (unformat_check_input (in) != UNFORMAT_END_OF_INPUT) {
7820 if (unformat (in, "ipv4"))
7822 else if (unformat (in, "ipv6"))
7828 if (ipv4_set && ipv6_set) {
7829 errmsg ("ipv4 and ipv6 flags cannot be both set\n");
7833 if ((!ipv4_set) && (!ipv6_set)) {
7834 errmsg ("no ipv4 nor ipv6 flag set\n");
7839 vam->is_ipv6 = is_ipv6;
7842 for (i = 0; i < vec_len(vam->ip_details_by_sw_if_index[is_ipv6]); i++) {
7843 vec_free(vam->ip_details_by_sw_if_index[is_ipv6][i].addr);
7845 vec_free(vam->ip_details_by_sw_if_index[is_ipv6]);
7847 M(IP_DUMP, ip_dump);
7848 mp->is_ipv6 = ipv6_set;
7851 /* Use a control ping for synchronization */
7853 vl_api_control_ping_t * mp;
7854 M(CONTROL_PING, control_ping);
7861 api_ipsec_spd_add_del (vat_main_t * vam)
7864 unformat_input_t * i = vam->input;
7865 vl_api_ipsec_spd_add_del_t *mp;
7870 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
7871 if (unformat (i, "spd_id %d", &spd_id))
7873 else if (unformat (i, "del"))
7876 clib_warning ("parse error '%U'", format_unformat_error, i);
7881 errmsg ("spd_id must be set\n");
7885 M(IPSEC_SPD_ADD_DEL, ipsec_spd_add_del);
7887 mp->spd_id = ntohl(spd_id);
7888 mp->is_add = is_add;
7894 clib_warning ("unsupported (no dpdk)");
7900 api_ipsec_interface_add_del_spd (vat_main_t * vam)
7903 unformat_input_t * i = vam->input;
7904 vl_api_ipsec_interface_add_del_spd_t *mp;
7907 u8 sw_if_index_set = 0;
7908 u32 spd_id = (u32) ~0;
7911 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
7912 if (unformat (i, "del"))
7914 else if (unformat (i, "spd_id %d", &spd_id))
7916 else if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
7917 sw_if_index_set = 1;
7918 else if (unformat (i, "sw_if_index %d", &sw_if_index))
7919 sw_if_index_set = 1;
7921 clib_warning ("parse error '%U'", format_unformat_error, i);
7927 if (spd_id == (u32) ~0) {
7928 errmsg ("spd_id must be set\n");
7932 if (sw_if_index_set == 0) {
7933 errmsg ("missing interface name or sw_if_index\n");
7937 M(IPSEC_INTERFACE_ADD_DEL_SPD, ipsec_interface_add_del_spd);
7939 mp->spd_id = ntohl(spd_id);
7940 mp->sw_if_index = ntohl (sw_if_index);
7941 mp->is_add = is_add;
7947 clib_warning ("unsupported (no dpdk)");
7953 api_ipsec_spd_add_del_entry (vat_main_t * vam)
7956 unformat_input_t * i = vam->input;
7957 vl_api_ipsec_spd_add_del_entry_t *mp;
7959 u8 is_add = 1, is_outbound = 0, is_ipv6 = 0, is_ip_any = 1;
7960 u32 spd_id, sa_id, protocol = 0, policy = 0;
7962 u32 rport_start = 0, rport_stop = (u32) ~0;
7963 u32 lport_start = 0, lport_stop = (u32) ~0;
7964 ip4_address_t laddr4_start, laddr4_stop, raddr4_start, raddr4_stop;
7965 ip6_address_t laddr6_start, laddr6_stop, raddr6_start, raddr6_stop;
7967 laddr4_start.as_u32 = raddr4_start.as_u32 = 0;
7968 laddr4_stop.as_u32 = raddr4_stop.as_u32 = (u32) ~0;
7969 laddr6_start.as_u64[0] = raddr6_start.as_u64[0] = 0;
7970 laddr6_start.as_u64[1] = raddr6_start.as_u64[1] = 0;
7971 laddr6_stop.as_u64[0] = raddr6_stop.as_u64[0] = (u64) ~0;
7972 laddr6_stop.as_u64[1] = raddr6_stop.as_u64[1] = (u64) ~0;
7974 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
7975 if (unformat (i, "del"))
7977 if (unformat (i, "outbound"))
7979 if (unformat (i, "inbound"))
7981 else if (unformat (i, "spd_id %d", &spd_id))
7983 else if (unformat (i, "sa_id %d", &sa_id))
7985 else if (unformat (i, "priority %d", &priority))
7987 else if (unformat (i, "protocol %d", &protocol))
7989 else if (unformat (i, "lport_start %d", &lport_start))
7991 else if (unformat (i, "lport_stop %d", &lport_stop))
7993 else if (unformat (i, "rport_start %d", &rport_start))
7995 else if (unformat (i, "rport_stop %d", &rport_stop))
7997 else if (unformat (i, "laddr_start %U", unformat_ip4_address, &laddr4_start))
8002 else if (unformat (i, "laddr_stop %U", unformat_ip4_address, &laddr4_stop))
8007 else if (unformat (i, "raddr_start %U", unformat_ip4_address, &raddr4_start))
8012 else if (unformat (i, "raddr_stop %U", unformat_ip4_address, &raddr4_stop))
8017 else if (unformat (i, "laddr_start %U", unformat_ip6_address, &laddr6_start))
8022 else if (unformat (i, "laddr_stop %U", unformat_ip6_address, &laddr6_stop))
8027 else if (unformat (i, "raddr_start %U", unformat_ip6_address, &raddr6_start))
8032 else if (unformat (i, "raddr_stop %U", unformat_ip6_address, &raddr6_stop))
8037 else if (unformat (i, "action %U", unformat_ipsec_policy_action, &policy))
8039 if (policy == IPSEC_POLICY_ACTION_RESOLVE) {
8040 clib_warning ("unsupported action: 'resolve'");
8045 clib_warning ("parse error '%U'", format_unformat_error, i);
8051 M(IPSEC_SPD_ADD_DEL_ENTRY, ipsec_spd_add_del_entry);
8053 mp->spd_id = ntohl(spd_id);
8054 mp->priority = ntohl(priority);
8055 mp->is_outbound = is_outbound;
8057 mp->is_ipv6 = is_ipv6;
8058 if (is_ipv6 || is_ip_any) {
8059 memcpy (mp->remote_address_start, &raddr6_start, sizeof(ip6_address_t));
8060 memcpy (mp->remote_address_stop, &raddr6_stop, sizeof(ip6_address_t));
8061 memcpy (mp->local_address_start, &laddr6_start, sizeof(ip6_address_t));
8062 memcpy (mp->local_address_stop, &laddr6_stop, sizeof(ip6_address_t));
8064 memcpy (mp->remote_address_start, &raddr4_start, sizeof(ip4_address_t));
8065 memcpy (mp->remote_address_stop, &raddr4_stop, sizeof(ip4_address_t));
8066 memcpy (mp->local_address_start, &laddr4_start, sizeof(ip4_address_t));
8067 memcpy (mp->local_address_stop, &laddr4_stop, sizeof(ip4_address_t));
8069 mp->protocol = (u8) protocol;
8070 mp->local_port_start = ntohs((u16) lport_start);
8071 mp->local_port_stop = ntohs((u16) lport_stop);
8072 mp->remote_port_start = ntohs((u16) rport_start);
8073 mp->remote_port_stop = ntohs((u16) rport_stop);
8074 mp->policy = (u8) policy;
8075 mp->sa_id = ntohl(sa_id);
8076 mp->is_add = is_add;
8077 mp->is_ip_any = is_ip_any;
8082 clib_warning ("unsupported (no dpdk)");
8088 api_ipsec_sad_add_del_entry (vat_main_t * vam)
8091 unformat_input_t * i = vam->input;
8092 vl_api_ipsec_sad_add_del_entry_t *mp;
8098 u8 protocol = IPSEC_PROTOCOL_AH;
8099 u8 is_tunnel = 0, is_tunnel_ipv6 = 0;
8100 u32 crypto_alg = 0, integ_alg = 0;
8101 ip4_address_t tun_src4;
8102 ip4_address_t tun_dst4;
8103 ip6_address_t tun_src6;
8104 ip6_address_t tun_dst6;
8106 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
8107 if (unformat (i, "del"))
8109 else if (unformat (i, "sad_id %d", &sad_id))
8111 else if (unformat (i, "spi %d", &spi))
8113 else if (unformat (i, "esp"))
8114 protocol = IPSEC_PROTOCOL_ESP;
8115 else if (unformat (i, "tunnel_src %U", unformat_ip4_address, &tun_src4)) {
8119 else if (unformat (i, "tunnel_dst %U", unformat_ip4_address, &tun_dst4)) {
8123 else if (unformat (i, "tunnel_src %U", unformat_ip6_address, &tun_src6)) {
8127 else if (unformat (i, "tunnel_dst %U", unformat_ip6_address, &tun_dst6)) {
8131 else if (unformat (i, "crypto_alg %U", unformat_ipsec_crypto_alg, &crypto_alg)) {
8132 if (crypto_alg < IPSEC_CRYPTO_ALG_AES_CBC_128 ||
8133 crypto_alg > IPSEC_INTEG_ALG_SHA_512_256) {
8134 clib_warning ("unsupported crypto-alg: '%U'",
8135 format_ipsec_crypto_alg, crypto_alg);
8139 else if (unformat (i, "crypto_key %U", unformat_hex_string, &ck))
8141 else if (unformat (i, "integ_alg %U", unformat_ipsec_integ_alg, &integ_alg)) {
8142 if (integ_alg < IPSEC_INTEG_ALG_SHA1_96 ||
8143 integ_alg > IPSEC_INTEG_ALG_SHA_512_256) {
8144 clib_warning ("unsupported integ-alg: '%U'",
8145 format_ipsec_integ_alg, integ_alg);
8149 else if (unformat (i, "integ_key %U", unformat_hex_string, &ik))
8152 clib_warning ("parse error '%U'", format_unformat_error, i);
8158 M(IPSEC_SAD_ADD_DEL_ENTRY, ipsec_sad_add_del_entry);
8160 mp->sad_id = ntohl(sad_id);
8161 mp->is_add = is_add;
8162 mp->protocol = protocol;
8163 mp->spi = ntohl(spi);
8164 mp->is_tunnel = is_tunnel;
8165 mp->is_tunnel_ipv6 = is_tunnel_ipv6;
8166 mp->crypto_algorithm = crypto_alg;
8167 mp->integrity_algorithm = integ_alg;
8168 mp->crypto_key_length = vec_len(ck);
8169 mp->integrity_key_length = vec_len(ik);
8171 if (mp->crypto_key_length > sizeof(mp->crypto_key))
8172 mp->crypto_key_length = sizeof(mp->crypto_key);
8174 if (mp->integrity_key_length > sizeof(mp->integrity_key))
8175 mp->integrity_key_length = sizeof(mp->integrity_key);
8177 memcpy (mp->crypto_key, ck, mp->crypto_key_length);
8178 memcpy (mp->integrity_key, ik, mp->integrity_key_length);
8181 if (is_tunnel_ipv6) {
8182 memcpy (mp->tunnel_src_address, &tun_src6, sizeof(ip6_address_t));
8183 memcpy (mp->tunnel_dst_address, &tun_dst6, sizeof(ip6_address_t));
8185 memcpy (mp->tunnel_src_address, &tun_src4, sizeof(ip4_address_t));
8186 memcpy (mp->tunnel_dst_address, &tun_dst4, sizeof(ip4_address_t));
8194 clib_warning ("unsupported (no dpdk)");
8200 api_ipsec_sa_set_key (vat_main_t * vam)
8203 unformat_input_t * i = vam->input;
8204 vl_api_ipsec_sa_set_key_t *mp;
8209 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
8210 if (unformat (i, "sa_id %d", &sa_id))
8212 else if (unformat (i, "crypto_key %U", unformat_hex_string, &ck))
8214 else if (unformat (i, "integ_key %U", unformat_hex_string, &ik))
8217 clib_warning ("parse error '%U'", format_unformat_error, i);
8222 M(IPSEC_SA_SET_KEY, ipsec_set_sa_key);
8224 mp->sa_id = ntohl(sa_id);
8225 mp->crypto_key_length = vec_len(ck);
8226 mp->integrity_key_length = vec_len(ik);
8228 if (mp->crypto_key_length > sizeof(mp->crypto_key))
8229 mp->crypto_key_length = sizeof(mp->crypto_key);
8231 if (mp->integrity_key_length > sizeof(mp->integrity_key))
8232 mp->integrity_key_length = sizeof(mp->integrity_key);
8234 memcpy (mp->crypto_key, ck, mp->crypto_key_length);
8235 memcpy (mp->integrity_key, ik, mp->integrity_key_length);
8241 clib_warning ("unsupported (no dpdk)");
8249 static int api_map_add_domain (vat_main_t * vam)
8251 unformat_input_t *i = vam->input;
8252 vl_api_map_add_domain_t *mp;
8255 ip4_address_t ip4_prefix;
8256 ip6_address_t ip6_prefix;
8257 ip6_address_t ip6_src;
8259 u32 ip6_prefix_len, ip4_prefix_len, ea_bits_len, psid_offset,
8261 u8 is_translation = 0;
8263 u8 ip6_src_len = 128;
8265 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
8266 if (unformat (i, "ip4-pfx %U/%d", unformat_ip4_address,
8267 &ip4_prefix, &ip4_prefix_len))
8269 else if (unformat (i, "ip6-pfx %U/%d", unformat_ip6_address,
8270 &ip6_prefix, &ip6_prefix_len))
8272 else if (unformat (i, "ip6-src %U/%d", unformat_ip6_address, &ip6_src, &ip6_src_len))
8274 else if (unformat (i, "ip6-src %U", unformat_ip6_address, &ip6_src))
8276 else if (unformat (i, "ea-bits-len %d", &ea_bits_len))
8278 else if (unformat (i, "psid-offset %d", &psid_offset))
8280 else if (unformat (i, "psid-len %d", &psid_length))
8282 else if (unformat (i, "mtu %d", &mtu))
8284 else if (unformat (i, "map-t"))
8287 clib_warning ("parse error '%U'", format_unformat_error, i);
8292 if (num_m_args != 6) {
8293 errmsg("mandatory argument(s) missing\n");
8297 /* Construct the API message */
8298 M(MAP_ADD_DOMAIN, map_add_domain);
8300 memcpy(mp->ip4_prefix, &ip4_prefix, sizeof(ip4_prefix));
8301 mp->ip4_prefix_len = ip4_prefix_len;
8303 memcpy(mp->ip6_prefix, &ip6_prefix, sizeof(ip6_prefix));
8304 mp->ip6_prefix_len = ip6_prefix_len;
8306 memcpy(mp->ip6_src, &ip6_src, sizeof(ip6_src));
8307 mp->ip6_src_prefix_len = ip6_src_len;
8309 mp->ea_bits_len = ea_bits_len;
8310 mp->psid_offset = psid_offset;
8311 mp->psid_length = psid_length;
8312 mp->is_translation = is_translation;
8313 mp->mtu = htons(mtu);
8318 /* Wait for a reply, return good/bad news */
8322 static int api_map_del_domain (vat_main_t * vam)
8324 unformat_input_t *i = vam->input;
8325 vl_api_map_del_domain_t *mp;
8331 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
8332 if (unformat (i, "index %d", &index))
8335 clib_warning ("parse error '%U'", format_unformat_error, i);
8340 if (num_m_args != 1) {
8341 errmsg("mandatory argument(s) missing\n");
8345 /* Construct the API message */
8346 M(MAP_DEL_DOMAIN, map_del_domain);
8348 mp->index = ntohl(index);
8353 /* Wait for a reply, return good/bad news */
8357 static int api_map_add_del_rule (vat_main_t * vam)
8359 unformat_input_t *i = vam->input;
8360 vl_api_map_add_del_rule_t *mp;
8363 ip6_address_t ip6_dst;
8364 u32 num_m_args = 0, index, psid;
8366 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
8367 if (unformat (i, "index %d", &index))
8369 else if (unformat (i, "psid %d", &psid))
8371 else if (unformat (i, "dst %U", unformat_ip6_address, &ip6_dst))
8373 else if (unformat (i, "del")) {
8376 clib_warning ("parse error '%U'", format_unformat_error, i);
8381 /* Construct the API message */
8382 M(MAP_ADD_DEL_RULE, map_add_del_rule);
8384 mp->index = ntohl(index);
8385 mp->is_add = is_add;
8386 memcpy(mp->ip6_dst, &ip6_dst, sizeof(ip6_dst));
8387 mp->psid = ntohs(psid);
8392 /* Wait for a reply, return good/bad news */
8396 static int api_map_domain_dump (vat_main_t * vam)
8398 vl_api_map_domain_dump_t *mp;
8401 /* Construct the API message */
8402 M(MAP_DOMAIN_DUMP, map_domain_dump);
8407 /* Use a control ping for synchronization */
8409 vl_api_control_ping_t * mp;
8410 M(CONTROL_PING, control_ping);
8416 static int api_map_rule_dump (vat_main_t * vam)
8418 unformat_input_t *i = vam->input;
8419 vl_api_map_rule_dump_t *mp;
8421 u32 domain_index = ~0;
8423 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
8424 if (unformat (i, "index %u", &domain_index))
8430 if (domain_index == ~0) {
8431 clib_warning("parse error: domain index expected");
8435 /* Construct the API message */
8436 M(MAP_RULE_DUMP, map_rule_dump);
8438 mp->domain_index = htonl(domain_index);
8443 /* Use a control ping for synchronization */
8445 vl_api_control_ping_t * mp;
8446 M(CONTROL_PING, control_ping);
8452 static void vl_api_map_add_domain_reply_t_handler
8453 (vl_api_map_add_domain_reply_t * mp)
8455 vat_main_t * vam = &vat_main;
8456 i32 retval = ntohl(mp->retval);
8458 if (vam->async_mode) {
8459 vam->async_errors += (retval < 0);
8461 vam->retval = retval;
8462 vam->result_ready = 1;
8466 static void vl_api_map_add_domain_reply_t_handler_json
8467 (vl_api_map_add_domain_reply_t * mp)
8469 vat_main_t * vam = &vat_main;
8470 vat_json_node_t node;
8472 vat_json_init_object(&node);
8473 vat_json_object_add_int(&node, "retval", ntohl(mp->retval));
8474 vat_json_object_add_uint(&node, "index", ntohl(mp->index));
8476 vat_json_print(vam->ofp, &node);
8477 vat_json_free(&node);
8479 vam->retval = ntohl(mp->retval);
8480 vam->result_ready = 1;
8484 api_get_first_msg_id (vat_main_t * vam)
8486 vl_api_get_first_msg_id_t * mp;
8488 unformat_input_t * i = vam->input;
8492 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
8493 if (unformat (i, "client %s", &name))
8499 if (name_set == 0) {
8500 errmsg ("missing client name\n");
8505 if (vec_len (name) > 63) {
8506 errmsg ("client name too long\n");
8510 M(GET_FIRST_MSG_ID, get_first_msg_id);
8511 memcpy (mp->name, name, vec_len(name));
8517 static int api_cop_interface_enable_disable (vat_main_t * vam)
8519 unformat_input_t * line_input = vam->input;
8520 vl_api_cop_interface_enable_disable_t * mp;
8522 u32 sw_if_index = ~0;
8523 u8 enable_disable = 1;
8525 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) {
8526 if (unformat (line_input, "disable"))
8528 if (unformat (line_input, "enable"))
8530 else if (unformat (line_input, "%U", unformat_sw_if_index,
8533 else if (unformat (line_input, "sw_if_index %d", &sw_if_index))
8539 if (sw_if_index == ~0) {
8540 errmsg ("missing interface name or sw_if_index\n");
8544 /* Construct the API message */
8545 M(COP_INTERFACE_ENABLE_DISABLE, cop_interface_enable_disable);
8546 mp->sw_if_index = ntohl(sw_if_index);
8547 mp->enable_disable = enable_disable;
8551 /* Wait for the reply */
8555 static int api_cop_whitelist_enable_disable (vat_main_t * vam)
8557 unformat_input_t * line_input = vam->input;
8558 vl_api_cop_whitelist_enable_disable_t * mp;
8560 u32 sw_if_index = ~0;
8561 u8 ip4=0, ip6=0, default_cop=0;
8564 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) {
8565 if (unformat (line_input, "ip4"))
8567 else if (unformat (line_input, "ip6"))
8569 else if (unformat (line_input, "default"))
8571 else if (unformat (line_input, "%U", unformat_sw_if_index,
8574 else if (unformat (line_input, "sw_if_index %d", &sw_if_index))
8576 else if (unformat (line_input, "fib-id %d", &fib_id))
8582 if (sw_if_index == ~0) {
8583 errmsg ("missing interface name or sw_if_index\n");
8587 /* Construct the API message */
8588 M(COP_WHITELIST_ENABLE_DISABLE, cop_whitelist_enable_disable);
8589 mp->sw_if_index = ntohl(sw_if_index);
8590 mp->fib_id = ntohl(fib_id);
8593 mp->default_cop = default_cop;
8597 /* Wait for the reply */
8601 static int api_get_node_graph (vat_main_t * vam)
8603 vl_api_get_node_graph_t * mp;
8606 M(GET_NODE_GRAPH, get_node_graph);
8610 /* Wait for the reply */
8614 static int q_or_quit (vat_main_t * vam)
8616 longjmp (vam->jump_buf, 1);
8617 return 0; /* not so much */
8619 static int q (vat_main_t * vam) {return q_or_quit (vam);}
8620 static int quit (vat_main_t * vam) {return q_or_quit (vam);}
8622 static int comment (vat_main_t * vam)
8627 static int cmd_cmp (void * a1, void * a2)
8632 return strcmp ((char *)(c1[0]), (char *)(c2[0]));
8635 static int help (vat_main_t * vam)
8640 unformat_input_t * i = vam->input;
8643 if (unformat (i, "%s", &name)) {
8648 hs = hash_get_mem (vam->help_by_name, name);
8650 fformat (vam->ofp, "usage: %s %s\n", name, hs[0]);
8652 fformat (vam->ofp, "No such msg / command '%s'\n", name);
8657 fformat(vam->ofp, "Help is available for the following:\n");
8659 hash_foreach_pair (p, vam->function_by_name,
8661 vec_add1 (cmds, (u8 *)(p->key));
8664 vec_sort_with_function (cmds, cmd_cmp);
8666 for (j = 0; j < vec_len(cmds); j++)
8667 fformat (vam->ofp, "%s\n", cmds[j]);
8673 static int set (vat_main_t * vam)
8675 u8 * name = 0, * value = 0;
8676 unformat_input_t * i = vam->input;
8678 if (unformat (i, "%s", &name)) {
8679 /* The input buffer is a vector, not a string. */
8680 value = vec_dup (i->buffer);
8681 vec_delete (value, i->index, 0);
8682 /* Almost certainly has a trailing newline */
8683 if (value[vec_len(value)-1] == '\n')
8684 value[vec_len(value)-1] = 0;
8685 /* Make sure it's a proper string, one way or the other */
8686 vec_add1 (value, 0);
8687 (void) clib_macro_set_value (&vam->macro_main,
8688 (char *)name, (char *)value);
8691 errmsg ("usage: set <name> <value>\n");
8698 static int unset (vat_main_t * vam)
8702 if (unformat (vam->input, "%s", &name))
8703 if (clib_macro_unset (&vam->macro_main, (char *)name) == 1)
8704 errmsg ("unset: %s wasn't set\n", name);
8715 static int macro_sort_cmp (void * a1, void * a2)
8717 macro_sort_t * s1 = a1;
8718 macro_sort_t * s2 = a2;
8720 return strcmp ((char *)(s1->name), (char *)(s2->name));
8723 static int dump_macro_table (vat_main_t * vam)
8725 macro_sort_t * sort_me = 0, * sm;
8729 hash_foreach_pair (p, vam->macro_main.the_value_table_hash,
8731 vec_add2 (sort_me, sm, 1);
8732 sm->name = (u8 *)(p->key);
8733 sm->value = (u8 *) (p->value[0]);
8736 vec_sort_with_function (sort_me, macro_sort_cmp);
8738 if (vec_len(sort_me))
8739 fformat (vam->ofp, "%-15s%s\n", "Name", "Value");
8741 fformat (vam->ofp, "The macro table is empty...\n");
8743 for (i = 0; i < vec_len (sort_me); i++)
8744 fformat (vam->ofp, "%-15s%s\n", sort_me[i].name,
8749 static int dump_node_table (vat_main_t * vam)
8752 vlib_node_t * node, * next_node;
8754 if (vec_len (vam->graph_nodes) == 0) {
8755 fformat (vam->ofp, "Node table empty, issue get_node_graph...\n");
8759 for (i = 0; i < vec_len (vam->graph_nodes); i++) {
8760 node = vam->graph_nodes[i];
8761 fformat (vam->ofp, "[%d] %s\n", i, node->name);
8762 for (j = 0; j < vec_len (node->next_nodes); j++) {
8763 if (node->next_nodes[j] != ~0) {
8764 next_node = vam->graph_nodes[node->next_nodes[j]];
8765 fformat (vam->ofp, " [%d] %s\n", j, next_node->name);
8772 static int search_node_table (vat_main_t * vam)
8774 unformat_input_t * line_input = vam->input;
8777 vlib_node_t * node, * next_node;
8780 if (vam->graph_node_index_by_name == 0) {
8781 fformat (vam->ofp, "Node table empty, issue get_node_graph...\n");
8785 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) {
8786 if (unformat (line_input, "%s", &node_to_find)) {
8787 vec_add1 (node_to_find, 0);
8788 p = hash_get_mem (vam->graph_node_index_by_name, node_to_find);
8790 fformat (vam->ofp, "%s not found...\n", node_to_find);
8793 node = vam->graph_nodes[p[0]];
8794 fformat (vam->ofp, "[%d] %s\n", p[0], node->name);
8795 for (j = 0; j < vec_len (node->next_nodes); j++) {
8796 if (node->next_nodes[j] != ~0) {
8797 next_node = vam->graph_nodes[node->next_nodes[j]];
8798 fformat (vam->ofp, " [%d] %s\n", j, next_node->name);
8804 clib_warning ("parse error '%U'", format_unformat_error,
8810 vec_free(node_to_find);
8818 static int script (vat_main_t * vam)
8821 char * save_current_file;
8822 unformat_input_t save_input;
8823 jmp_buf save_jump_buf;
8824 u32 save_line_number;
8826 FILE * new_fp, * save_ifp;
8828 if (unformat (vam->input, "%s", &s)) {
8829 new_fp = fopen ((char *)s, "r");
8831 errmsg ("Couldn't open script file %s\n", s);
8836 errmsg ("Missing script name\n");
8840 memcpy (&save_input, &vam->input, sizeof (save_input));
8841 memcpy (&save_jump_buf, &vam->jump_buf, sizeof (save_jump_buf));
8842 save_ifp = vam->ifp;
8843 save_line_number = vam->input_line_number;
8844 save_current_file = (char *) vam->current_file;
8846 vam->input_line_number = 0;
8848 vam->current_file = s;
8851 memcpy (&vam->input, &save_input, sizeof (vam->input));
8852 memcpy (&vam->jump_buf, &save_jump_buf, sizeof (save_jump_buf));
8853 vam->ifp = save_ifp;
8854 vam->input_line_number = save_line_number;
8855 vam->current_file = (u8 *) save_current_file;
8861 static int echo (vat_main_t * vam)
8863 fformat (vam->ofp, "%v", vam->input->buffer);
8867 /* List of API message constructors, CLI names map to api_xxx */
8868 #define foreach_vpe_api_msg \
8869 _(create_loopback,"[mac <mac-addr>]") \
8870 _(sw_interface_dump,"") \
8871 _(sw_interface_set_flags, \
8872 "<intfc> | sw_if_index <id> admin-up | admin-down link-up | link down") \
8873 _(sw_interface_add_del_address, \
8874 "<intfc> | sw_if_index <id> <ip4-address> | <ip6-address> [del] [del-all] ") \
8875 _(sw_interface_set_table, \
8876 "<intfc> | sw_if_index <id> vrf <table-id> [ipv6]") \
8877 _(sw_interface_set_vpath, \
8878 "<intfc> | sw_if_index <id> enable | disable") \
8879 _(sw_interface_set_l2_xconnect, \
8880 "rx <intfc> | rx_sw_if_index <id> tx <intfc> | tx_sw_if_index <id>\n" \
8881 "enable | disable") \
8882 _(sw_interface_set_l2_bridge, \
8883 "rx <intfc> | rx_sw_if_index <id> bd_id <bridge-domain-id>\n" \
8884 "[shg <split-horizon-group>] [bvi]\n" \
8885 "enable | disable") \
8886 _(bridge_domain_add_del, \
8887 "bd_id <bridge-domain-id> [flood 1|0] [uu-flood 1|0] [forward 1|0] [learn 1|0] [arp-term 1|0] [del]\n")\
8888 _(bridge_domain_dump, "[bd_id <bridge-domain-id>]\n") \
8890 "mac <mac-addr> bd_id <bridge-domain-id> [del] | sw_if <intfc> | sw_if_index <id> [static] [filter] [bvi]\n") \
8892 "sw_if <intfc> | sw_if_index <id> [learn] [forward] [uu-flood] [flood]\n") \
8894 "bd_id <bridge-domain-id> [learn] [forward] [uu-flood] [flood] [arp-term] [disable]\n") \
8896 "tapname <name> mac <mac-addr> | random-mac") \
8898 "<vpp-if-name> | sw_if_index <id> tapname <name> mac <mac-addr> | random-mac") \
8900 "<vpp-if-name> | sw_if_index <id>") \
8901 _(sw_interface_tap_dump, "") \
8902 _(ip_add_del_route, \
8903 "<addr>/<mask> via <addr> [vrf <n>]\n" \
8904 "[<intfc> | sw_if_index <id>] [resolve-attempts <n>]\n" \
8905 "[weight <n>] [drop] [local] [classify <n>] [del]\n" \
8906 "[multipath] [count <n>]") \
8907 _(proxy_arp_add_del, \
8908 "<lo-ip4-addr> - <hi-ip4-addr> [vrf <n>] [del]") \
8909 _(proxy_arp_intfc_enable_disable, \
8910 "<intfc> | sw_if_index <id> enable | disable") \
8911 _(mpls_add_del_encap, \
8912 "label <n> dst <ip4-addr> [vrf <n>] [del]") \
8913 _(mpls_add_del_decap, \
8914 "label <n> [rx_vrf_id <n>] [tx_vrf_id] [s-bit-clear][del]") \
8915 _(mpls_gre_add_del_tunnel, \
8916 "inner_vrf_id <n> outer_vrf_id <n> src <ip4-address> dst <ip4-address>\n" \
8917 "adj <ip4-address>/<mask-width> [del]") \
8918 _(sw_interface_set_unnumbered, \
8919 "<intfc> | sw_if_index <id> unnum_if_index <id> [del]") \
8920 _(ip_neighbor_add_del, \
8921 "<intfc> | sw_if_index <id> dst <ip46-address> mac <mac-addr>") \
8922 _(reset_vrf, "vrf <id> [ipv6]") \
8923 _(create_vlan_subif, "<intfc> | sw_if_index <id> vlan <n>") \
8924 _(create_subif, "<intfc> | sw_if_index <id> sub_id <n>\n" \
8925 "[outer_vlan_id <n>][inner_vlan_id <n>]\n" \
8926 "[no_tags][one_tag][two_tags][dot1ad][exact_match][default_sub]\n" \
8927 "[outer_vlan_id_any][inner_vlan_id_any]") \
8928 _(oam_add_del, "src <ip4-address> dst <ip4-address> [vrf <n>] [del]") \
8929 _(reset_fib, "vrf <n> [ipv6]") \
8930 _(dhcp_proxy_config, \
8931 "svr <v46-address> src <v46-address>\n" \
8932 "insert-cid <n> [del]") \
8933 _(dhcp_proxy_config_2, \
8934 "svr <v46-address> src <v46-address>\n" \
8935 "rx_vrf_id <nn> server_vrf_id <nn> insert-cid <n> [del]") \
8936 _(dhcp_proxy_set_vss, \
8937 "tbl_id <n> fib_id <n> oui <n> [ipv6] [del]") \
8938 _(dhcp_client_config, \
8939 "<intfc> | sw_if_index <id> [hostname <name>] [disable_event] [del]") \
8940 _(set_ip_flow_hash, \
8941 "vrf <n> [src] [dst] [sport] [dport] [proto] [reverse] [ipv6]") \
8942 _(sw_interface_ip6_enable_disable, \
8943 "<intfc> | sw_if_index <id> enable | disable") \
8944 _(sw_interface_ip6_set_link_local_address, \
8945 "<intfc> | sw_if_index <id> <ip6-address>/<mask-width>") \
8946 _(sw_interface_ip6nd_ra_prefix, \
8947 "<intfc> | sw_if_index <id> <ip6-address>/<mask-width>\n" \
8948 "val_life <n> pref_life <n> [def] [noadv] [offl] [noauto]\n" \
8949 "[nolink] [isno]") \
8950 _(sw_interface_ip6nd_ra_config, \
8951 "<intfc> | sw_if_index <id> [maxint <n>] [minint <n>]\n" \
8952 "[life <n>] [count <n>] [interval <n>] [surpress]\n" \
8953 "[managed] [other] [ll] [send] [cease] [isno] [def]") \
8954 _(set_arp_neighbor_limit, "arp_nbr_limit <n> [ipv6]") \
8955 _(l2_patch_add_del, \
8956 "rx <intfc> | rx_sw_if_index <id> tx <intfc> | tx_sw_if_index <id>\n" \
8957 "enable | disable") \
8958 _(mpls_ethernet_add_del_tunnel, \
8959 "tx <intfc> | tx_sw_if_index <n> dst <mac-addr>\n" \
8960 "adj <ip4-addr>/<mw> dst <mac-addr> [del]") \
8961 _(mpls_ethernet_add_del_tunnel_2, \
8962 "inner_vrf_id <n> outer_vrf_id <n> next-hop <ip4-addr>\n" \
8963 "resolve-attempts <n> resolve-if-needed 0 | 1 [del]") \
8964 _(sr_tunnel_add_del, \
8965 "src <ip6-addr> dst <ip6-addr>/<mw> (next <ip6-addr>)+\n" \
8966 " [tag <ip6-addr>]* [clean] [reroute]") \
8967 _(classify_add_del_table, \
8968 "buckets <nn> [skip <n>] [match <n>] [memory_size <nn-bytes>]\n" \
8969 "[del] mask <mask-value>\n" \
8970 " [l2-miss-next | miss-next | acl-miss-next] <name|nn>") \
8971 _(classify_add_del_session, \
8972 "[hit-next|l2-hit-next|acl-hit-next] <name|nn> table-index <nn>\n" \
8973 "skip_n <nn> match_n <nn> match [hex] [l2] [l3 [ip4|ip6]]") \
8974 _(classify_set_interface_ip_table, \
8975 "<intfc> | sw_if_index <nn> table <nn>") \
8976 _(classify_set_interface_l2_tables, \
8977 "<intfc> | sw_if_index <nn> [ip4-table <nn>] [ip6-table <nn>]\n" \
8978 " [other-table <nn>]") \
8979 _(get_node_index, "node <node-name") \
8980 _(add_node_next, "node <node-name> next <next-node-name>") \
8981 _(l2tpv3_create_tunnel, \
8982 "client_address <ip6-addr> our_address <ip6-addr>\n" \
8983 "[local_session_id <nn>][remote_session_id <nn>][local_cookie <nn>]\n"\
8984 "[remote_cookie <nn>]\n[l2-sublayer-preset]\n") \
8985 _(l2tpv3_set_tunnel_cookies, \
8986 "<intfc> | sw_if_index <nn> [new_local_cookie <nn>]\n" \
8987 "[new_remote_cookie <nn>]\n") \
8988 _(l2tpv3_interface_enable_disable, \
8989 "<intfc> | sw_if_index <nn> enable | disable") \
8990 _(l2tpv3_set_lookup_key, \
8991 "lookup_v6_src | lookup_v6_dst | lookup_session_id") \
8992 _(sw_if_l2tpv3_tunnel_dump, "") \
8993 _(vxlan_add_del_tunnel, \
8994 "src <ip4-addr> dst <ip4-addr> vni [encap-vrf-id <nn>]\n" \
8995 " [decap-next l2|ip4|ip6] [del]") \
8996 _(vxlan_tunnel_dump, "[<intfc> | sw_if_index <nn>]") \
8997 _(l2_fib_clear_table, "") \
8998 _(l2_interface_efp_filter, "sw_if_index <nn> enable | disable") \
8999 _(l2_interface_vlan_tag_rewrite, \
9000 "<intfc> | sw_if_index <nn> \n" \
9001 "[disable][push-[1|2]][pop-[1|2]][translate-1-[1|2]] \n" \
9002 "[translate-2-[1|2]] [push_dot1q 0] tag1 <nn> tag2 <nn>") \
9003 _(create_vhost_user_if, \
9004 "socket <filename> [server] [renumber <dev_instance>] " \
9005 "[mac <mac_address>]") \
9006 _(modify_vhost_user_if, \
9007 "<intfc> | sw_if_index <nn> socket <filename>\n" \
9008 "[server] [renumber <dev_instance>]") \
9009 _(delete_vhost_user_if, "<intfc> | sw_if_index <nn>") \
9010 _(sw_interface_vhost_user_dump, "") \
9011 _(show_version, "") \
9012 _(nsh_gre_add_del_tunnel, \
9013 "src <ip4-addr> dst <ip4-addr>" \
9014 "c1 <nn> c2 <nn> c3 <nn> c4 <nn> spi <nn> si <nn>\n" \
9015 "[encap-fib-id <nn>] [decap-fib-id <nn>] [o-bit <1|0>]\n" \
9016 "[c-bit <1|0>] [md-type <nn>][next-ip4][next-ip6][next-ethernet]\n" \
9017 "[tlv <xx>][del]") \
9018 _(nsh_vxlan_gpe_add_del_tunnel, \
9019 "src <ip4-addr> dst <ip4-addr> vni <nn>\n" \
9020 "c1 <nn> c2 <nn> c3 <nn> c4 <nn> spi <nn> si <nn>\n" \
9021 "[encap-vrf-id <nn>] [decap-vrf-id <nn>] [o-bit <1|0>]\n" \
9022 "[c-bit <1|0>] [md-type <nn>][next-ip4][next-ip6][next-ethernet]\n" \
9023 "[tlv <xx>][del]") \
9024 _(l2_fib_table_dump, "bd_id <bridge-domain-id>") \
9025 _(lisp_gpe_add_del_tunnel, \
9026 "src <ip4-addr> dst <ip4-addr> iid <nn>|iidx <0xnn>\n" \
9027 "[encap-vrf-id <nn>] [decap-vrf-id <nn>]\n" \
9028 "[n-bit][l-bit][e-bit][v-bit][i-bit][p-bit][not-p-bit][o-bit]\n" \
9029 "[next-ip4][next-ip6][next-ethernet][next-nsh]\n" \
9030 "[decap-next [ip4|ip6|ethernet|nsh-encap|<nn>]][del]") \
9031 _(interface_name_renumber, \
9032 "<intfc> | sw_if_index <nn> new_show_dev_instance <nn>") \
9033 _(input_acl_set_interface, \
9034 "<intfc> | sw_if_index <nn> [ip4-table <nn>] [ip6-table <nn>]\n" \
9035 " [l2-table <nn>] [del]") \
9036 _(want_ip4_arp_events, "address <ip4-address> [del]") \
9037 _(ip_address_dump, "(ipv4 | ipv6) (<intfc> | sw_if_index <id>)") \
9038 _(ip_dump, "ipv4 | ipv6") \
9039 _(ipsec_spd_add_del, "spd_id <n> [del]") \
9040 _(ipsec_interface_add_del_spd, "(<intfc> | sw_if_index <id>)\n" \
9042 _(ipsec_sad_add_del_entry, "sad_id <n> spi <n> crypto_alg <alg>\n" \
9043 " crypto_key <hex> tunnel_src <ip4|ip6> tunnel_dst <ip4|ip6>\n" \
9044 " integ_alg <alg> integ_key <hex>") \
9045 _(ipsec_spd_add_del_entry, "spd_id <n> priority <n> action <action>\n" \
9046 " (inbound|outbound) [sa_id <n>] laddr_start <ip4|ip6>\n" \
9047 " laddr_stop <ip4|ip6> raddr_start <ip4|ip6> raddr_stop <ip4|ip6>\n" \
9048 " [lport_start <n> lport_stop <n>] [rport_start <n> rport_stop <n>]" )\
9049 _(ipsec_sa_set_key, "sa_id <n> crypto_key <hex> integ_key <hex>") \
9050 _(delete_loopback,"sw_if_index <nn>") \
9051 _(bd_ip_mac_add_del, "bd_id <bridge-domain-id> <ip4/6-addr> <mac-addr> [del]") \
9053 "ip4-pfx <ip4pfx> ip6-pfx <ip6pfx> " \
9054 "ip6-src <ip6addr> " \
9055 "ea-bits-len <n> psid-offset <n> psid-len <n>") \
9056 _(map_del_domain, "index <n>") \
9057 _(map_add_del_rule, \
9058 "index <n> psid <n> dst <ip6addr> [del]") \
9059 _(map_domain_dump, "") \
9060 _(map_rule_dump, "index <map-domain>") \
9061 _(want_interface_events, "enable|disable") \
9062 _(want_stats,"enable|disable") \
9063 _(get_first_msg_id, "client <name>") \
9064 _(cop_interface_enable_disable, "<intfc> | sw_if_index <nn> [disable]") \
9065 _(cop_whitelist_enable_disable, "<intfc> | sw_if_index <nn>\n" \
9066 "fib-id <nn> [ip4][ip6][default]") \
9067 _(get_node_graph, " ")
9069 /* List of command functions, CLI names map directly to functions */
9070 #define foreach_cli_function \
9071 _(comment, "usage: comment <ignore-rest-of-line>") \
9072 _(dump_interface_table, "usage: dump_interface_table") \
9073 _(dump_sub_interface_table, "usage: dump_sub_interface_table") \
9074 _(dump_ipv4_table, "usage: dump_ipv4_table") \
9075 _(dump_ipv6_table, "usage: dump_ipv6_table") \
9076 _(dump_stats_table, "usage: dump_stats_table") \
9077 _(dump_macro_table, "usage: dump_macro_table ") \
9078 _(dump_node_table, "usage: dump_node_table") \
9079 _(echo, "usage: echo <message>") \
9080 _(exec, "usage: exec <vpe-debug-CLI-command>") \
9081 _(help, "usage: help") \
9082 _(q, "usage: quit") \
9083 _(quit, "usage: quit") \
9084 _(search_node_table, "usage: search_node_table <name>...") \
9085 _(set, "usage: set <variable-name> <value>") \
9086 _(script, "usage: script <file-name>") \
9087 _(unset, "usage: unset <variable-name>")
9090 static void vl_api_##n##_t_handler_uni \
9091 (vl_api_##n##_t * mp) \
9093 vat_main_t * vam = &vat_main; \
9094 if (vam->json_output) { \
9095 vl_api_##n##_t_handler_json(mp); \
9097 vl_api_##n##_t_handler(mp); \
9100 foreach_vpe_api_reply_msg;
9103 void vat_api_hookup (vat_main_t *vam)
9106 vl_msg_api_set_handlers(VL_API_##N, #n, \
9107 vl_api_##n##_t_handler_uni, \
9109 vl_api_##n##_t_endian, \
9110 vl_api_##n##_t_print, \
9111 sizeof(vl_api_##n##_t), 1);
9112 foreach_vpe_api_reply_msg;
9115 vl_msg_api_set_first_available_msg_id (VL_MSG_FIRST_AVAILABLE);
9117 vam->sw_if_index_by_interface_name =
9118 hash_create_string (0, sizeof (uword));
9120 vam->function_by_name =
9121 hash_create_string (0, sizeof(uword));
9124 hash_create_string (0, sizeof(uword));
9126 /* API messages we can send */
9127 #define _(n,h) hash_set_mem (vam->function_by_name, #n, api_##n);
9128 foreach_vpe_api_msg;
9132 #define _(n,h) hash_set_mem (vam->help_by_name, #n, h);
9133 foreach_vpe_api_msg;
9137 #define _(n,h) hash_set_mem (vam->function_by_name, #n, n);
9138 foreach_cli_function;
9142 #define _(n,h) hash_set_mem (vam->help_by_name, #n, h);
9143 foreach_cli_function;
9147 #undef vl_api_version
9148 #define vl_api_version(n,v) static u32 vpe_api_version = v;
9149 #include <api/vpe.api.h>
9150 #undef vl_api_version
9152 void vl_client_add_api_signatures (vl_api_memclnt_create_t *mp)
9155 * Send the main API signature in slot 0. This bit of code must
9156 * match the checks in ../vpe/api/api.c: vl_msg_api_version_check().
9158 mp->api_versions[0] = clib_host_to_net_u32 (vpe_api_version);