X-Git-Url: https://gerrit.fd.io/r/gitweb?a=blobdiff_plain;f=src%2Fvat%2Fapi_format.c;h=45ba025f191d63648550e69d2bfadad5505e9acf;hb=HEAD;hp=33e5a275551b4b05494c4ea975bb726ba3851bea;hpb=a1400cecb8d8b423e83bd584e59fa817b8a243d9;p=vpp.git diff --git a/src/vat/api_format.c b/src/vat/api_format.c index 33e5a275551..45ba025f191 100644 --- a/src/vat/api_format.c +++ b/src/vat/api_format.c @@ -29,7 +29,6 @@ #include #include -#include #include #include #include @@ -56,24 +55,22 @@ #include #include -#define vl_typedefs /* define message structures */ -#include -#undef vl_typedefs - -/* declare message handlers for each api */ +#include +#include +#include +#include #define vl_endianfun /* define message structures */ -#include +#include #undef vl_endianfun +#define vl_calcsizefun +#include +#undef vl_calcsizefun + /* instantiate all the print functions we know about */ -#if VPP_API_TEST_BUILTIN == 0 -#define vl_print(handle, ...) -#else -#define vl_print(handle, ...) vlib_cli_output (handle, __VA_ARGS__) -#endif #define vl_printfun -#include +#include #undef vl_printfun #define __plugin_msg_base 0 @@ -174,23 +171,6 @@ errmsg (char *fmt, ...) } #if VPP_API_TEST_BUILTIN == 0 -static uword -api_unformat_sw_if_index (unformat_input_t * input, va_list * args) -{ - vat_main_t *vam = va_arg (*args, vat_main_t *); - u32 *result = va_arg (*args, u32 *); - u8 *if_name; - uword *p; - - if (!unformat (input, "%s", &if_name)) - return 0; - - p = hash_get_mem (vam->sw_if_index_by_interface_name, if_name); - if (p == 0) - return 0; - *result = p[0]; - return 1; -} /* Parse an IP4 address %d.%d.%d.%d. */ uword @@ -579,47 +559,6 @@ ip_set (ip46_address_t * dst, void *src, u8 is_ip4) } -static void vl_api_show_version_reply_t_handler - (vl_api_show_version_reply_t * mp) -{ - vat_main_t *vam = &vat_main; - i32 retval = ntohl (mp->retval); - - if (retval >= 0) - { - errmsg (" program: %s", mp->program); - errmsg (" version: %s", mp->version); - errmsg (" build date: %s", mp->build_date); - errmsg ("build directory: %s", mp->build_directory); - } - vam->retval = retval; - vam->result_ready = 1; -} - -static void vl_api_show_version_reply_t_handler_json - (vl_api_show_version_reply_t * mp) -{ - vat_main_t *vam = &vat_main; - vat_json_node_t node; - - vat_json_init_object (&node); - vat_json_object_add_int (&node, "retval", ntohl (mp->retval)); - vat_json_object_add_string_copy (&node, "program", mp->program); - vat_json_object_add_string_copy (&node, "version", mp->version); - vat_json_object_add_string_copy (&node, "build_date", mp->build_date); - vat_json_object_add_string_copy (&node, "build_directory", - mp->build_directory); - - vat_json_print (vam->ofp, &node); - vat_json_free (&node); - - vam->retval = ntohl (mp->retval); - vam->result_ready = 1; -} - -#define vl_api_bridge_domain_details_t_endian vl_noop_handler -#define vl_api_bridge_domain_details_t_print vl_noop_handler - static void vl_api_get_first_msg_id_reply_t_handler (vl_api_get_first_msg_id_reply_t * mp) { @@ -686,6 +625,48 @@ format_hex_bytes (u8 * s, va_list * va) return s; } +static void +vl_api_control_ping_reply_t_handler (vl_api_control_ping_reply_t *mp) +{ + vat_main_t *vam = &vat_main; + i32 retval = ntohl (mp->retval); + if (vam->async_mode) + { + vam->async_errors += (retval < 0); + } + else + { + vam->retval = retval; + vam->result_ready = 1; + } + if (vam->socket_client_main) + vam->socket_client_main->control_pings_outstanding--; +} + +static void +vl_api_control_ping_reply_t_handler_json (vl_api_control_ping_reply_t *mp) +{ + vat_main_t *vam = &vat_main; + i32 retval = ntohl (mp->retval); + + if (VAT_JSON_NONE != vam->json_tree.type) + { + vat_json_print (vam->ofp, &vam->json_tree); + vat_json_free (&vam->json_tree); + vam->json_tree.type = VAT_JSON_NONE; + } + else + { + /* just print [] */ + vat_json_init_array (&vam->json_tree); + vat_json_print (vam->ofp, &vam->json_tree); + vam->json_tree.type = VAT_JSON_NONE; + } + + vam->retval = retval; + vam->result_ready = 1; +} + /* * Generate boilerplate reply handlers, which * dig the return value out of the xxx_reply_t API message, @@ -735,7 +716,7 @@ foreach_standard_reply_retval_handler; #define foreach_vpe_api_reply_msg \ _ (GET_FIRST_MSG_ID_REPLY, get_first_msg_id_reply) \ - _ (SHOW_VERSION_REPLY, show_version_reply) \ + _ (CONTROL_PING_REPLY, control_ping_reply) #define foreach_standalone_reply_msg \ @@ -749,10 +730,23 @@ typedef struct case L2_VTR_ ## op: \ return "" # op; -int -api_sw_interface_dump (vat_main_t *vam) +static const char * +str_vtr_op (u32 vtr_op) { - return 0; + switch (vtr_op) + { + STR_VTR_OP_CASE (DISABLED); + STR_VTR_OP_CASE (PUSH_1); + STR_VTR_OP_CASE (PUSH_2); + STR_VTR_OP_CASE (POP_1); + STR_VTR_OP_CASE (POP_2); + STR_VTR_OP_CASE (TRANSLATE_1_1); + STR_VTR_OP_CASE (TRANSLATE_1_2); + STR_VTR_OP_CASE (TRANSLATE_2_1); + STR_VTR_OP_CASE (TRANSLATE_2_2); + } + + return "UNKNOWN"; } uword @@ -1425,7 +1419,7 @@ unformat_classify_mask (unformat_input_t * input, va_list * args) if (match == 0) clib_warning ("BUG: match 0"); - _vec_len (mask) = match * sizeof (u32x4); + vec_set_len (mask, match * sizeof (u32x4)); *matchp = match; *maskp = mask; @@ -1992,7 +1986,7 @@ api_unformat_classify_match (unformat_input_t * input, va_list * args) sizeof (u32x4)); /* Set size, include skipped vectors */ - _vec_len (match) = (match_n_vectors + skip_n_vectors) * sizeof (u32x4); + vec_set_len (match, (match_n_vectors + skip_n_vectors) * sizeof (u32x4)); *matchp = match; @@ -2013,19 +2007,6 @@ api_unformat_classify_match (unformat_input_t * input, va_list * args) _ ("translate-2-1", L2_VTR_TRANSLATE_2_1) \ _ ("translate-2-2", L2_VTR_TRANSLATE_2_2) -static int -api_show_version (vat_main_t *vam) -{ - vl_api_show_version_t *mp; - int ret; - - M (SHOW_VERSION, mp); - - S (mp); - W (ret); - return ret; -} - static int api_get_first_msg_id (vat_main_t *vam) { @@ -2355,12 +2336,10 @@ help (vat_main_t * vam) print (vam->ofp, "Help is available for the following:"); - /* *INDENT-OFF* */ hash_foreach_pair (p, vam->function_by_name, ({ vec_add1 (cmds, (u8 *)(p->key)); })); - /* *INDENT-ON* */ vec_sort_with_function (cmds, cmd_cmp); @@ -2433,14 +2412,11 @@ dump_macro_table (vat_main_t * vam) int i; hash_pair_t *p; - /* *INDENT-OFF* */ - hash_foreach_pair (p, vam->macro_main.the_value_table_hash, - ({ - vec_add2 (sort_me, sm, 1); - sm->name = (u8 *)(p->key); - sm->value = (u8 *) (p->value[0]); - })); - /* *INDENT-ON* */ + hash_foreach_pair (p, vam->macro_main.the_value_table_hash, ({ + vec_add2 (sort_me, sm, 1); + sm->name = (u8 *) (p->key); + sm->value = (u8 *) (p->value[0]); + })); vec_sort_with_function (sort_me, macro_sort_cmp); @@ -2476,14 +2452,12 @@ dump_msg_api_table (vat_main_t * vam) hash_pair_t *hp; int i; - /* *INDENT-OFF* */ hash_foreach_pair (hp, am->msg_index_by_name_and_crc, ({ vec_add2 (nses, ns, 1); ns->name = (u8 *)(hp->key); ns->value = (u32) hp->value[0]; })); - /* *INDENT-ON* */ vec_sort_with_function (nses, value_sort_cmp); @@ -2636,30 +2610,107 @@ exec (vat_main_t *vam) return -1; } +static int +name_sort_cmp (void *a1, void *a2) +{ + name_sort_t *n1 = a1; + name_sort_t *n2 = a2; + + return strcmp ((char *) n1->name, (char *) n2->name); +} + +static int +dump_interface_table (vat_main_t *vam) +{ + hash_pair_t *p; + name_sort_t *nses = 0, *ns; + + if (vam->json_output) + { + clib_warning ( + "JSON output supported only for VPE API calls and dump_stats_table"); + return -99; + } + + hash_foreach_pair (p, vam->sw_if_index_by_interface_name, ({ + vec_add2 (nses, ns, 1); + ns->name = (u8 *) (p->key); + ns->value = (u32) p->value[0]; + })); + + vec_sort_with_function (nses, name_sort_cmp); + + print (vam->ofp, "%-25s%-15s", "Interface", "sw_if_index"); + vec_foreach (ns, nses) + { + print (vam->ofp, "%-25s%-15d", ns->name, ns->value); + } + vec_free (nses); + return 0; +} + +static int +dump_sub_interface_table (vat_main_t *vam) +{ + const sw_interface_subif_t *sub = NULL; + + if (vam->json_output) + { + clib_warning ( + "JSON output supported only for VPE API calls and dump_stats_table"); + return -99; + } + + print (vam->ofp, "%-30s%-12s%-11s%-7s%-5s%-9s%-9s%-6s%-8s%-10s%-10s", + "Interface", "sw_if_index", "sub id", "dot1ad", "tags", "outer id", + "inner id", "exact", "default", "outer any", "inner any"); + + vec_foreach (sub, vam->sw_if_subif_table) + { + print (vam->ofp, "%-30s%-12d%-11d%-7s%-5d%-9d%-9d%-6d%-8d%-10d%-10d", + sub->interface_name, sub->sw_if_index, sub->sub_id, + sub->sub_dot1ad ? "dot1ad" : "dot1q", sub->sub_number_of_tags, + sub->sub_outer_vlan_id, sub->sub_inner_vlan_id, + sub->sub_exact_match, sub->sub_default, + sub->sub_outer_vlan_id_any, sub->sub_inner_vlan_id_any); + if (sub->vtr_op != L2_VTR_DISABLED) + { + print (vam->ofp, + " vlan-tag-rewrite - op: %-14s [ dot1q: %d " + "tag1: %d tag2: %d ]", + str_vtr_op (sub->vtr_op), sub->vtr_push_dot1q, sub->vtr_tag1, + sub->vtr_tag2); + } + } + + return 0; +} + /* List of API message constructors, CLI names map to api_xxx */ #define foreach_vpe_api_msg \ -_(show_version, "") \ _(get_first_msg_id, "client ") \ _(sock_init_shm, "size ") \ /* List of command functions, CLI names map directly to functions */ -#define foreach_cli_function \ -_(comment, "usage: comment ") \ -_(dump_macro_table, "usage: dump_macro_table ") \ -_(dump_msg_api_table, "usage: dump_msg_api_table") \ -_(elog_setup, "usage: elog_setup [nevents, default 128K]") \ -_(elog_disable, "usage: elog_disable") \ -_(elog_enable, "usage: elog_enable") \ -_(elog_save, "usage: elog_save ") \ -_(get_msg_id, "usage: get_msg_id name_and_crc") \ -_(echo, "usage: echo ") \ -_(help, "usage: help") \ -_(q, "usage: quit") \ -_(quit, "usage: quit") \ -_(search_node_table, "usage: search_node_table ...") \ -_(set, "usage: set ") \ -_(script, "usage: script ") \ -_(statseg, "usage: statseg") \ -_(unset, "usage: unset ") +#define foreach_cli_function \ + _ (comment, "usage: comment ") \ + _ (dump_interface_table, "usage: dump_interface_table") \ + _ (dump_sub_interface_table, "usage: dump_sub_interface_table") \ + _ (dump_macro_table, "usage: dump_macro_table ") \ + _ (dump_msg_api_table, "usage: dump_msg_api_table") \ + _ (elog_setup, "usage: elog_setup [nevents, default 128K]") \ + _ (elog_disable, "usage: elog_disable") \ + _ (elog_enable, "usage: elog_enable") \ + _ (elog_save, "usage: elog_save ") \ + _ (get_msg_id, "usage: get_msg_id name_and_crc") \ + _ (echo, "usage: echo ") \ + _ (help, "usage: help") \ + _ (q, "usage: quit") \ + _ (quit, "usage: quit") \ + _ (search_node_table, "usage: search_node_table ...") \ + _ (set, "usage: set ") \ + _ (script, "usage: script ") \ + _ (statseg, "usage: statseg") \ + _ (unset, "usage: unset ") #define _(N,n) \ static void vl_api_##n##_t_handler_uni \ @@ -2681,13 +2732,19 @@ foreach_standalone_reply_msg; void vat_api_hookup (vat_main_t * vam) { -#define _(N,n) \ - vl_msg_api_set_handlers(VL_API_##N, #n, \ - vl_api_##n##_t_handler_uni, \ - vl_noop_handler, \ - vl_api_##n##_t_endian, \ - vl_api_##n##_t_print, \ - sizeof(vl_api_##n##_t), 1); +#define _(N, n) \ + vl_msg_api_config (&(vl_msg_api_msg_config_t){ \ + .id = VL_API_##N + 1, \ + .name = #n, \ + .handler = vl_api_##n##_t_handler_uni, \ + .endian = vl_api_##n##_t_endian, \ + .format_fn = vl_api_##n##_t_format, \ + .size = sizeof (vl_api_##n##_t), \ + .traced = 1, \ + .tojson = vl_api_##n##_t_tojson, \ + .fromjson = vl_api_##n##_t_fromjson, \ + .calc_size = vl_api_##n##_t_calc_size, \ + }); foreach_vpe_api_reply_msg; #if VPP_API_TEST_BUILTIN == 0 foreach_standalone_reply_msg; @@ -2695,7 +2752,7 @@ vat_api_hookup (vat_main_t * vam) #undef _ #if (VPP_API_TEST_BUILTIN==0) - vl_msg_api_set_first_available_msg_id (VL_MSG_FIRST_AVAILABLE); + vl_msg_api_set_first_available_msg_id (VL_MSG_MEMCLNT_LAST + 1); vam->sw_if_index_by_interface_name = hash_create_string (0, sizeof (uword));