From: Filip Tehlar Date: Mon, 21 Jun 2021 10:57:49 +0000 (+0000) Subject: misc: ipfix api cleanup X-Git-Tag: v22.02-rc0~295 X-Git-Url: https://gerrit.fd.io/r/gitweb?p=vpp.git;a=commitdiff_plain;h=53dea2792b55bc2bc1b29a7a1b7169023acae406 misc: ipfix api cleanup Use autogenerated code. Does not change API definitions. Type: improvement Change-Id: I864979ce490651bf1f5fed107620e9bc4ca4bf93 Signed-off-by: Filip Tehlar --- diff --git a/src/vat/api_format.c b/src/vat/api_format.c index 23de7b9a312..4512aff523f 100644 --- a/src/vat/api_format.c +++ b/src/vat/api_format.c @@ -2851,9 +2851,6 @@ _(sw_interface_clear_stats_reply) \ _(ioam_enable_reply) \ _(ioam_disable_reply) \ _(af_packet_delete_reply) \ -_(set_ipfix_exporter_reply) \ -_(set_ipfix_classify_stream_reply) \ -_(ipfix_classify_table_add_del_reply) \ _(sw_interface_span_enable_disable_reply) \ _(pg_capture_reply) \ _(pg_enable_disable_reply) \ @@ -3021,12 +3018,6 @@ _(POLICER_DETAILS, policer_details) \ _(MPLS_TUNNEL_DETAILS, mpls_tunnel_details) \ _(MPLS_TABLE_DETAILS, mpls_table_details) \ _(MPLS_ROUTE_DETAILS, mpls_route_details) \ -_(SET_IPFIX_EXPORTER_REPLY, set_ipfix_exporter_reply) \ -_(IPFIX_EXPORTER_DETAILS, ipfix_exporter_details) \ -_(SET_IPFIX_CLASSIFY_STREAM_REPLY, set_ipfix_classify_stream_reply) \ -_(IPFIX_CLASSIFY_STREAM_DETAILS, ipfix_classify_stream_details) \ -_(IPFIX_CLASSIFY_TABLE_ADD_DEL_REPLY, ipfix_classify_table_add_del_reply) \ -_(IPFIX_CLASSIFY_TABLE_DETAILS, ipfix_classify_table_details) \ _(SW_INTERFACE_SPAN_ENABLE_DISABLE_REPLY, sw_interface_span_enable_disable_reply) \ _(SW_INTERFACE_SPAN_DETAILS, sw_interface_span_details) \ _(GET_NEXT_INDEX_REPLY, get_next_index_reply) \ @@ -7910,167 +7901,6 @@ api_unformat_classify_match (unformat_input_t * input, va_list * args) return 0; } -static int -api_set_ipfix_exporter (vat_main_t *vam) -{ - unformat_input_t *i = vam->input; - vl_api_set_ipfix_exporter_t *mp; - ip4_address_t collector_address; - u8 collector_address_set = 0; - u32 collector_port = ~0; - ip4_address_t src_address; - u8 src_address_set = 0; - u32 vrf_id = ~0; - u32 path_mtu = ~0; - u32 template_interval = ~0; - u8 udp_checksum = 0; - int ret; - - while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) - { - if (unformat (i, "collector_address %U", unformat_ip4_address, - &collector_address)) - collector_address_set = 1; - else if (unformat (i, "collector_port %d", &collector_port)) - ; - else if (unformat (i, "src_address %U", unformat_ip4_address, - &src_address)) - src_address_set = 1; - else if (unformat (i, "vrf_id %d", &vrf_id)) - ; - else if (unformat (i, "path_mtu %d", &path_mtu)) - ; - else if (unformat (i, "template_interval %d", &template_interval)) - ; - else if (unformat (i, "udp_checksum")) - udp_checksum = 1; - else - break; - } - - if (collector_address_set == 0) - { - errmsg ("collector_address required"); - return -99; - } - - if (src_address_set == 0) - { - errmsg ("src_address required"); - return -99; - } - - M (SET_IPFIX_EXPORTER, mp); - - memcpy (mp->collector_address.un.ip4, collector_address.data, - sizeof (collector_address.data)); - mp->collector_port = htons ((u16) collector_port); - memcpy (mp->src_address.un.ip4, src_address.data, - sizeof (src_address.data)); - mp->vrf_id = htonl (vrf_id); - mp->path_mtu = htonl (path_mtu); - mp->template_interval = htonl (template_interval); - mp->udp_checksum = udp_checksum; - - S (mp); - W (ret); - return ret; -} - -static int -api_set_ipfix_classify_stream (vat_main_t * vam) -{ - unformat_input_t *i = vam->input; - vl_api_set_ipfix_classify_stream_t *mp; - u32 domain_id = 0; - u32 src_port = UDP_DST_PORT_ipfix; - int ret; - - while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) - { - if (unformat (i, "domain %d", &domain_id)) - ; - else if (unformat (i, "src_port %d", &src_port)) - ; - else - { - errmsg ("unknown input `%U'", format_unformat_error, i); - return -99; - } - } - - M (SET_IPFIX_CLASSIFY_STREAM, mp); - - mp->domain_id = htonl (domain_id); - mp->src_port = htons ((u16) src_port); - - S (mp); - W (ret); - return ret; -} - -static int -api_ipfix_classify_table_add_del (vat_main_t * vam) -{ - unformat_input_t *i = vam->input; - vl_api_ipfix_classify_table_add_del_t *mp; - int is_add = -1; - u32 classify_table_index = ~0; - u8 ip_version = 0; - u8 transport_protocol = 255; - int ret; - - while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) - { - if (unformat (i, "add")) - is_add = 1; - else if (unformat (i, "del")) - is_add = 0; - else if (unformat (i, "table %d", &classify_table_index)) - ; - else if (unformat (i, "ip4")) - ip_version = 4; - else if (unformat (i, "ip6")) - ip_version = 6; - else if (unformat (i, "tcp")) - transport_protocol = 6; - else if (unformat (i, "udp")) - transport_protocol = 17; - else - { - errmsg ("unknown input `%U'", format_unformat_error, i); - return -99; - } - } - - if (is_add == -1) - { - errmsg ("expecting: add|del"); - return -99; - } - if (classify_table_index == ~0) - { - errmsg ("classifier table not specified"); - return -99; - } - if (ip_version == 0) - { - errmsg ("IP version not specified"); - return -99; - } - - M (IPFIX_CLASSIFY_TABLE_ADD_DEL, mp); - - mp->is_add = is_add; - mp->table_id = htonl (classify_table_index); - mp->ip_version = ip_version; - mp->transport_protocol = transport_protocol; - - S (mp); - W (ret); - return ret; -} - static int api_get_node_index (vat_main_t * vam) { @@ -10502,171 +10332,6 @@ api_ip_route_dump (vat_main_t * vam) return ret; } -static void -vl_api_ipfix_exporter_details_t_handler (vl_api_ipfix_exporter_details_t * mp) -{ - vat_main_t *vam = &vat_main; - - print (vam->ofp, "collector_address %U, collector_port %d, " - "src_address %U, vrf_id %d, path_mtu %u, " - "template_interval %u, udp_checksum %d", - format_ip4_address, mp->collector_address, - ntohs (mp->collector_port), - format_ip4_address, mp->src_address, - ntohl (mp->vrf_id), ntohl (mp->path_mtu), - ntohl (mp->template_interval), mp->udp_checksum); - - vam->retval = 0; - vam->result_ready = 1; -} - -static void - vl_api_ipfix_exporter_details_t_handler_json - (vl_api_ipfix_exporter_details_t * mp) -{ - vat_main_t *vam = &vat_main; - vat_json_node_t node; - struct in_addr collector_address; - struct in_addr src_address; - - vat_json_init_object (&node); - clib_memcpy (&collector_address, &mp->collector_address, - sizeof (collector_address)); - vat_json_object_add_ip4 (&node, "collector_address", collector_address); - vat_json_object_add_uint (&node, "collector_port", - ntohs (mp->collector_port)); - clib_memcpy (&src_address, &mp->src_address, sizeof (src_address)); - vat_json_object_add_ip4 (&node, "src_address", src_address); - vat_json_object_add_int (&node, "vrf_id", ntohl (mp->vrf_id)); - vat_json_object_add_uint (&node, "path_mtu", ntohl (mp->path_mtu)); - vat_json_object_add_uint (&node, "template_interval", - ntohl (mp->template_interval)); - vat_json_object_add_int (&node, "udp_checksum", mp->udp_checksum); - - vat_json_print (vam->ofp, &node); - vat_json_free (&node); - vam->retval = 0; - vam->result_ready = 1; -} - -int -api_ipfix_exporter_dump (vat_main_t * vam) -{ - vl_api_ipfix_exporter_dump_t *mp; - int ret; - - /* Construct the API message */ - M (IPFIX_EXPORTER_DUMP, mp); - mp->context = 0; - - S (mp); - W (ret); - return ret; -} - -static int -api_ipfix_classify_stream_dump (vat_main_t * vam) -{ - vl_api_ipfix_classify_stream_dump_t *mp; - int ret; - - /* Construct the API message */ - M (IPFIX_CLASSIFY_STREAM_DUMP, mp); - mp->context = 0; - - S (mp); - W (ret); - return ret; - /* NOTREACHED */ - return 0; -} - -static void - vl_api_ipfix_classify_stream_details_t_handler - (vl_api_ipfix_classify_stream_details_t * mp) -{ - vat_main_t *vam = &vat_main; - print (vam->ofp, "domain_id %d, src_port %d", - ntohl (mp->domain_id), ntohs (mp->src_port)); - vam->retval = 0; - vam->result_ready = 1; -} - -static void - vl_api_ipfix_classify_stream_details_t_handler_json - (vl_api_ipfix_classify_stream_details_t * mp) -{ - vat_main_t *vam = &vat_main; - vat_json_node_t node; - - vat_json_init_object (&node); - vat_json_object_add_uint (&node, "domain_id", ntohl (mp->domain_id)); - vat_json_object_add_uint (&node, "src_port", ntohs (mp->src_port)); - - vat_json_print (vam->ofp, &node); - vat_json_free (&node); - vam->retval = 0; - vam->result_ready = 1; -} - -static int -api_ipfix_classify_table_dump (vat_main_t * vam) -{ - vl_api_ipfix_classify_table_dump_t *mp; - vl_api_control_ping_t *mp_ping; - int ret; - - if (!vam->json_output) - { - print (vam->ofp, "%15s%15s%20s", "table_id", "ip_version", - "transport_protocol"); - } - - /* Construct the API message */ - M (IPFIX_CLASSIFY_TABLE_DUMP, mp); - - /* send it... */ - S (mp); - - /* Use a control ping for synchronization */ - MPING (CONTROL_PING, mp_ping); - S (mp_ping); - - W (ret); - return ret; -} - -static void - vl_api_ipfix_classify_table_details_t_handler - (vl_api_ipfix_classify_table_details_t * mp) -{ - vat_main_t *vam = &vat_main; - print (vam->ofp, "%15d%15d%20d", ntohl (mp->table_id), mp->ip_version, - mp->transport_protocol); -} - -static void - vl_api_ipfix_classify_table_details_t_handler_json - (vl_api_ipfix_classify_table_details_t * mp) -{ - vat_json_node_t *node = NULL; - vat_main_t *vam = &vat_main; - - if (VAT_JSON_ARRAY != vam->json_tree.type) - { - ASSERT (VAT_JSON_NONE == vam->json_tree.type); - vat_json_init_array (&vam->json_tree); - } - - node = vat_json_array_add (&vam->json_tree); - vat_json_init_object (node); - - vat_json_object_add_uint (node, "table_id", ntohl (mp->table_id)); - vat_json_object_add_uint (node, "ip_version", mp->ip_version); - vat_json_object_add_uint (node, "transport_protocol", - mp->transport_protocol); -} - static int api_sw_interface_span_enable_disable (vat_main_t * vam) { @@ -12919,14 +12584,6 @@ _(policer_dump, "[name ]") \ _(mpls_tunnel_dump, "tunnel_index ") \ _(mpls_table_dump, "") \ _(mpls_route_dump, "table-id ") \ -_(set_ipfix_exporter, "collector_address [collector_port ] " \ - "src_address [vrf_id ] [path_mtu ] " \ - "[template_interval ] [udp_checksum]") \ -_(ipfix_exporter_dump, "") \ -_(set_ipfix_classify_stream, "[domain ] [src_port ]") \ -_(ipfix_classify_stream_dump, "") \ -_(ipfix_classify_table_add_del, "table ip4|ip6 [tcp|udp]") \ -_(ipfix_classify_table_dump, "") \ _(sw_interface_span_enable_disable, "[l2] [src | src_sw_if_index ] [disable | [[dst | dst_sw_if_index ] [both|rx|tx]]]") \ _(sw_interface_span_dump, "[l2]") \ _(get_next_index, "node-name next-node-name ") \ diff --git a/src/vnet/ipfix-export/flow_api.c b/src/vnet/ipfix-export/flow_api.c index f4b3fc8be3b..75a656468db 100644 --- a/src/vnet/ipfix-export/flow_api.c +++ b/src/vnet/ipfix-export/flow_api.c @@ -29,33 +29,13 @@ #include #include -#include - -#define vl_typedefs /* define message structures */ -#include -#undef vl_typedefs - -#define vl_endianfun /* define message structures */ -#include -#undef vl_endianfun - -/* instantiate all the print functions we know about */ -#define vl_print(handle, ...) vlib_cli_output (handle, __VA_ARGS__) -#define vl_printfun -#include -#undef vl_printfun +#include +#include +#include +#define REPLY_MSG_ID_BASE frm->msg_id_base #include -#define foreach_vpe_api_msg \ -_(SET_IPFIX_EXPORTER, set_ipfix_exporter) \ -_(IPFIX_EXPORTER_DUMP, ipfix_exporter_dump) \ -_(SET_IPFIX_CLASSIFY_STREAM, set_ipfix_classify_stream) \ -_(IPFIX_CLASSIFY_STREAM_DUMP, ipfix_classify_stream_dump) \ -_(IPFIX_CLASSIFY_TABLE_ADD_DEL, ipfix_classify_table_add_del) \ -_(IPFIX_CLASSIFY_TABLE_DUMP, ipfix_classify_table_dump) \ -_(IPFIX_FLUSH, ipfix_flush) - static void vl_api_set_ipfix_exporter_t_handler (vl_api_set_ipfix_exporter_t * mp) { @@ -366,6 +346,7 @@ static void static void vl_api_ipfix_flush_t_handler (vl_api_ipfix_flush_t * mp) { + flow_report_main_t *frm = &flow_report_main; vl_api_ipfix_flush_reply_t *rmp; vl_api_registration_t *reg; vlib_main_t *vm = vlib_get_main (); @@ -382,44 +363,15 @@ vl_api_ipfix_flush_t_handler (vl_api_ipfix_flush_t * mp) REPLY_MACRO (VL_API_IPFIX_FLUSH_REPLY); } -/* - * flow_api_hookup - * Add vpe's API message handlers to the table. - * vlib has already mapped shared memory and - * added the client registration handlers. - * See .../vlib-api/vlibmemory/memclnt_vlib.c:memclnt_process() - */ -#define vl_msg_name_crc_list -#include -#undef vl_msg_name_crc_list - -static void -setup_message_id_table (api_main_t * am) -{ -#define _(id,n,crc) vl_msg_api_add_msg_name_crc (am, #n "_" #crc, id); - foreach_vl_msg_name_crc_ipfix_export; -#undef _ -} - +#include static clib_error_t * flow_api_hookup (vlib_main_t * vm) { - api_main_t *am = vlibapi_get_main (); - -#define _(N,n) \ - vl_msg_api_set_handlers(VL_API_##N, #n, \ - vl_api_##n##_t_handler, \ - vl_noop_handler, \ - vl_api_##n##_t_endian, \ - vl_api_##n##_t_print, \ - sizeof(vl_api_##n##_t), 1); - foreach_vpe_api_msg; -#undef _ - + flow_report_main_t *frm = &flow_report_main; /* * Set up the (msg_name, crc, message-id) table */ - setup_message_id_table (am); + REPLY_MSG_ID_BASE = setup_message_id_table (); return 0; } diff --git a/src/vnet/ipfix-export/flow_report.h b/src/vnet/ipfix-export/flow_report.h index 98da146427a..f40015879c4 100644 --- a/src/vnet/ipfix-export/flow_report.h +++ b/src/vnet/ipfix-export/flow_report.h @@ -134,6 +134,8 @@ typedef struct flow_report_main /* convenience variables */ vlib_main_t *vlib_main; vnet_main_t *vnet_main; + + u16 msg_id_base; } flow_report_main_t; extern flow_report_main_t flow_report_main; diff --git a/src/vnet/vnet_all_api_h.h b/src/vnet/vnet_all_api_h.h index 7e26a9b7745..47e22795cbf 100644 --- a/src/vnet/vnet_all_api_h.h +++ b/src/vnet/vnet_all_api_h.h @@ -47,7 +47,6 @@ #include #include #include -#include #include #include #include