From: Ole Troan Date: Tue, 18 Dec 2018 11:23:13 +0000 (+0100) Subject: VAPI/VOM: Removing legacy stats tests, add string type. X-Git-Tag: v19.04-rc0~134 X-Git-Url: https://gerrit.fd.io/r/gitweb?p=vpp.git;a=commitdiff_plain;h=003d5da298b2cd1e20400fb5fdcefce752ca616e VAPI/VOM: Removing legacy stats tests, add string type. Fix misc VAPI/VOM generation and test cases. Change-Id: I1abf9ecdb6f8a2129f11e0a9ed1c0fe04cdf5c47 Signed-off-by: Ole Troan --- diff --git a/extras/vom/vom/igmp_listen_cmds.cpp b/extras/vom/vom/igmp_listen_cmds.cpp index 683b2b9a0b6..69e243d9b4a 100644 --- a/extras/vom/vom/igmp_listen_cmds.cpp +++ b/extras/vom/vom/igmp_listen_cmds.cpp @@ -22,7 +22,7 @@ namespace VOM { namespace igmp_listen_cmds { listen_cmd::listen_cmd(HW::item& item, const handle_t& itf, - const boost::asio::ip::address& gaddr, + const boost::asio::ip::address_v4& gaddr, const igmp_listen::src_addrs_t& saddrs) : rpc_cmd(item) , m_itf(itf) @@ -34,7 +34,8 @@ listen_cmd::listen_cmd(HW::item& item, bool listen_cmd::operator==(const listen_cmd& other) const { - return ((m_itf == other.m_itf) && (m_gaddr == other.m_gaddr)); + return ((m_itf == other.m_itf) && (m_gaddr == other.m_gaddr) && + (m_saddrs == other.m_saddrs)); } rc_t @@ -45,7 +46,7 @@ listen_cmd::issue(connection& con) auto& payload = req.get_request().get_payload(); payload.group.sw_if_index = m_itf.value(); - to_api(m_gaddr.to_v4(), payload.group.gaddr); + to_api(m_gaddr, payload.group.gaddr); if (0 == size) { // no sources => (*,G) join @@ -85,7 +86,7 @@ listen_cmd::to_string() const unlisten_cmd::unlisten_cmd(HW::item& item, const handle_t& itf, - const boost::asio::ip::address& gaddr) + const boost::asio::ip::address_v4& gaddr) : rpc_cmd(item) , m_itf(itf) , m_gaddr(gaddr) @@ -107,7 +108,7 @@ unlisten_cmd::issue(connection& con) payload.group.sw_if_index = m_itf.value(); payload.group.n_srcs = 0; payload.group.filter = INCLUDE; - to_api(m_gaddr.to_v4(), payload.group.gaddr); + to_api(m_gaddr, payload.group.gaddr); VAPI_CALL(req.execute()); diff --git a/extras/vom/vom/igmp_listen_cmds.hpp b/extras/vom/vom/igmp_listen_cmds.hpp index c062358e4dd..5bfea47914b 100644 --- a/extras/vom/vom/igmp_listen_cmds.hpp +++ b/extras/vom/vom/igmp_listen_cmds.hpp @@ -36,7 +36,7 @@ public: */ listen_cmd(HW::item& item, const handle_t& itf, - const boost::asio::ip::address& gaddr, + const boost::asio::ip::address_v4& gaddr, const igmp_listen::src_addrs_t& saddrs); /** @@ -62,7 +62,7 @@ private: /** * The igmp group to bind */ - const boost::asio::ip::address& m_gaddr; + const boost::asio::ip::address_v4& m_gaddr; /** * The igmp srouce specific addresses to listen them @@ -81,7 +81,7 @@ public: */ unlisten_cmd(HW::item& item, const handle_t& itf, - const boost::asio::ip::address& gaddr); + const boost::asio::ip::address_v4& gaddr); /** * Issue the command to VPP/HW @@ -107,7 +107,7 @@ private: /** * The igmp group to unlisten */ - const boost::asio::ip::address& m_gaddr; + const boost::asio::ip::address_v4& m_gaddr; }; /** diff --git a/src/vlibapi/api_types.h b/src/vlibapi/api_types.h index 8a86612f0fb..406ccfa6745 100644 --- a/src/vlibapi/api_types.h +++ b/src/vlibapi/api_types.h @@ -21,6 +21,8 @@ #define included_api_types_h #include +#include +#include /* VPP API string type */ typedef struct @@ -32,8 +34,8 @@ typedef struct static inline int vl_api_to_api_string (u32 len, const char *buf, vl_api_string_t * str) { - clib_memcpy(str->buf, buf, len); - str->length = clib_host_to_net_u32 (len); + memcpy(str->buf, buf, len); + str->length = htonl (len); return len + sizeof (u32); } @@ -47,13 +49,13 @@ vl_api_from_api_string (vl_api_string_t * astr) static inline u32 vl_api_string_len (vl_api_string_t * astr) { - return clib_net_to_host_u32 (astr->length); + return ntohl (astr->length); } static inline char * vl_api_from_api_string_c (vl_api_string_t *astr) { - return strndup((char *)astr->buf, clib_net_to_host_u32(astr->length)); + return strndup((char *)astr->buf, ntohl (astr->length)); } #endif diff --git a/src/vpp-api/vapi/vapi.h b/src/vpp-api/vapi/vapi.h index 2a401c21189..08d016b0dd7 100644 --- a/src/vpp-api/vapi/vapi.h +++ b/src/vpp-api/vapi/vapi.h @@ -21,6 +21,7 @@ #include #include #include +#include #include #include diff --git a/src/vpp-api/vapi/vapi_json_parser.py b/src/vpp-api/vapi/vapi_json_parser.py index 3eb5d3616e1..2c08b90a93b 100644 --- a/src/vpp-api/vapi/vapi_json_parser.py +++ b/src/vpp-api/vapi/vapi_json_parser.py @@ -302,6 +302,7 @@ class JsonParser(object): ] } + self.types['string'] = simple_type_class('vl_api_string_t') self.replies = set() self.events = set() self.simple_type_class = simple_type_class diff --git a/test/ext/vapi_c_test.c b/test/ext/vapi_c_test.c index 9fbb2a61302..0b22fff1706 100644 --- a/test/ext/vapi_c_test.c +++ b/test/ext/vapi_c_test.c @@ -27,13 +27,11 @@ #include #include #include -#include #include DEFINE_VAPI_MSG_IDS_VPE_API_JSON; DEFINE_VAPI_MSG_IDS_INTERFACE_API_JSON; DEFINE_VAPI_MSG_IDS_L2_API_JSON; -DEFINE_VAPI_MSG_IDS_STATS_API_JSON; DEFINE_VAPI_MSG_IDS_FAKE_API_JSON; static char *app_name = NULL; @@ -106,41 +104,6 @@ START_TEST (test_hton_2) END_TEST; -START_TEST (test_hton_3) -{ - const size_t data_size = 10; - vapi_msg_vnet_interface_combined_counters *m = - malloc (sizeof (vapi_msg_vnet_interface_combined_counters) + - data_size * sizeof (vapi_type_vlib_counter)); - ck_assert_ptr_ne (NULL, m); - vapi_payload_vnet_interface_combined_counters *p = &m->payload; - const u16 _vl_msg_id = 1; - p->_vl_msg_id = _vl_msg_id; - const u32 first_sw_if_index = 2; - p->first_sw_if_index = first_sw_if_index; - p->count = data_size; - const u64 packets = 1234; - const u64 bytes = 2345; - int i; - for (i = 0; i < data_size; ++i) - { - p->data[i].packets = packets; - p->data[i].bytes = bytes; - } - vapi_msg_vnet_interface_combined_counters_hton (m); - ck_assert_int_eq (_vl_msg_id, be16toh (p->_vl_msg_id)); - ck_assert_int_eq (first_sw_if_index, be32toh (p->first_sw_if_index)); - ck_assert_int_eq (data_size, be32toh (p->count)); - for (i = 0; i < data_size; ++i) - { - ck_assert_int_eq (packets, be64toh (p->data[i].packets)); - ck_assert_int_eq (bytes, be64toh (p->data[i].bytes)); - } - free (p); -} - -END_TEST; - #define verify_hton_swap(expr, value) \ if (4 == sizeof (expr)) \ { \ @@ -278,42 +241,6 @@ START_TEST (test_ntoh_2) END_TEST; -START_TEST (test_ntoh_3) -{ - const size_t data_size = 10; - vapi_msg_vnet_interface_combined_counters *m = - malloc (sizeof (vapi_msg_vnet_interface_combined_counters) + - data_size * sizeof (vapi_type_vlib_counter)); - ck_assert_ptr_ne (NULL, m); - vapi_payload_vnet_interface_combined_counters *p = &m->payload; - const u16 _vl_msg_id = 1; - p->_vl_msg_id = _vl_msg_id; - const u32 first_sw_if_index = 2; - p->first_sw_if_index = first_sw_if_index; - const size_t be_data_size = htobe32 (data_size); - p->count = be_data_size; - const u64 packets = 1234; - const u64 bytes = 2345; - int i; - for (i = 0; i < data_size; ++i) - { - p->data[i].packets = packets; - p->data[i].bytes = bytes; - } - vapi_msg_vnet_interface_combined_counters_ntoh (m); - ck_assert_int_eq (_vl_msg_id, be16toh (p->_vl_msg_id)); - ck_assert_int_eq (first_sw_if_index, be32toh (p->first_sw_if_index)); - ck_assert_int_eq (be_data_size, be32toh (p->count)); - for (i = 0; i < data_size; ++i) - { - ck_assert_int_eq (packets, htobe64 (p->data[i].packets)); - ck_assert_int_eq (bytes, htobe64 (p->data[i].bytes)); - } - free (p); -} - -END_TEST; - #define verify_ntoh_swap(expr, value) \ if (4 == sizeof (expr)) \ { \ @@ -432,11 +359,14 @@ show_version_cb (vapi_ctx_t ctx, void *caller_ctx, { ck_assert_int_eq (VAPI_OK, rv); ck_assert_int_eq (true, is_last); - ck_assert_str_eq ("vpe", (char *) p->program); + ck_assert_str_eq ("vpe", (char *) vl_api_from_api_string (&p->program)); printf ("show_version_reply: program: `%s', version: `%s', build directory: " - "`%s', build date: `%s'\n", p->program, p->version, p->build_directory, - p->build_date); + "`%s', build date: `%s'\n", + vl_api_from_api_string (&p->program), + vl_api_from_api_string (&p->version), + vl_api_from_api_string (&p->build_directory), + vl_api_from_api_string (&p->build_date)); ++*(int *) caller_ctx; return VAPI_OK; } @@ -863,69 +793,6 @@ START_TEST (test_loopbacks_2) END_TEST; -vapi_error_e -interface_simple_stats_cb (vapi_ctx_t ctx, void *callback_ctx, - vapi_error_e rv, bool is_last, - vapi_payload_want_interface_simple_stats_reply * - payload) -{ - return VAPI_OK; -} - -vapi_error_e -simple_counters_cb (vapi_ctx_t ctx, void *callback_ctx, - vapi_payload_vnet_interface_simple_counters * payload) -{ - int *called = callback_ctx; - ++*called; - printf ("simple counters: first_sw_if_index=%u\n", - payload->first_sw_if_index); - return VAPI_OK; -} - -START_TEST (test_stats_1) -{ - printf ("--- Receive stats using generic blocking API ---\n"); - vapi_msg_want_interface_simple_stats *ws = - vapi_alloc_want_interface_simple_stats (ctx); - ws->payload.enable_disable = 1; - ws->payload.pid = getpid (); - vapi_error_e rv; - rv = vapi_want_interface_simple_stats (ctx, ws, interface_simple_stats_cb, - NULL); - ck_assert_int_eq (VAPI_OK, rv); - int called = 0; - vapi_set_event_cb (ctx, vapi_msg_id_vnet_interface_simple_counters, - (vapi_event_cb) simple_counters_cb, &called); - rv = vapi_dispatch_one (ctx); - ck_assert_int_eq (VAPI_OK, rv); - ck_assert_int_eq (1, called); -} - -END_TEST; - -START_TEST (test_stats_2) -{ - printf ("--- Receive stats using stat-specific blocking API ---\n"); - vapi_msg_want_interface_simple_stats *ws = - vapi_alloc_want_interface_simple_stats (ctx); - ws->payload.enable_disable = 1; - ws->payload.pid = getpid (); - vapi_error_e rv; - rv = vapi_want_interface_simple_stats (ctx, ws, interface_simple_stats_cb, - NULL); - ck_assert_int_eq (VAPI_OK, rv); - int called = 0; - vapi_set_vapi_msg_vnet_interface_simple_counters_event_cb (ctx, - simple_counters_cb, - &called); - rv = vapi_dispatch_one (ctx); - ck_assert_int_eq (VAPI_OK, rv); - ck_assert_int_eq (1, called); -} - -END_TEST; - vapi_error_e generic_cb (vapi_ctx_t ctx, void *callback_ctx, vapi_msg_id_t id, void *msg) { @@ -935,7 +802,9 @@ generic_cb (vapi_ctx_t ctx, void *callback_ctx, vapi_msg_id_t id, void *msg) ck_assert_int_eq (id, vapi_msg_id_show_version_reply); ck_assert_ptr_ne (NULL, msg); vapi_msg_show_version_reply *reply = msg; - ck_assert_str_eq ("vpe", (char *) reply->payload.program); + ck_assert_str_eq ("vpe", + (char *) vl_api_from_api_string (&reply-> + payload.program)); return VAPI_OK; } @@ -970,53 +839,6 @@ START_TEST (test_show_version_5) END_TEST; -vapi_error_e -combined_counters_cb (struct vapi_ctx_s *ctx, void *callback_ctx, - vapi_payload_vnet_interface_combined_counters * payload) -{ - int *called = callback_ctx; - ++*called; - printf ("combined counters: first_sw_if_index=%u\n", - payload->first_sw_if_index); - return VAPI_OK; -} - -vapi_error_e -stats_cb (vapi_ctx_t ctx, void *callback_ctx, vapi_error_e rv, - bool is_last, vapi_payload_want_stats_reply * payload) -{ - return VAPI_OK; -} - -START_TEST (test_stats_3) -{ - printf ("--- Receive multiple stats using stat-specific non-blocking API " - "---\n"); - vapi_msg_want_stats *ws = vapi_alloc_want_stats (ctx); - ws->payload.enable_disable = 1; - ws->payload.pid = getpid (); - vapi_error_e rv; - rv = vapi_want_stats (ctx, ws, stats_cb, NULL); - ck_assert_int_eq (VAPI_OK, rv); - int called = 0; - int called2 = 0; - vapi_set_vapi_msg_vnet_interface_simple_counters_event_cb (ctx, - simple_counters_cb, - &called); - vapi_set_vapi_msg_vnet_interface_combined_counters_event_cb (ctx, - combined_counters_cb, - &called2); - while (!called || !called2) - { - if (VAPI_EAGAIN != (rv = vapi_dispatch_one (ctx))) - { - ck_assert_int_eq (VAPI_OK, rv); - } - } -} - -END_TEST; - vapi_error_e show_version_no_cb (vapi_ctx_t ctx, void *caller_ctx, vapi_error_e rv, bool is_last, @@ -1106,11 +928,9 @@ test_suite (void) TCase *tc_swap = tcase_create ("Byteswap tests"); tcase_add_test (tc_swap, test_hton_1); tcase_add_test (tc_swap, test_hton_2); - tcase_add_test (tc_swap, test_hton_3); tcase_add_test (tc_swap, test_hton_4); tcase_add_test (tc_swap, test_ntoh_1); tcase_add_test (tc_swap, test_ntoh_2); - tcase_add_test (tc_swap, test_ntoh_3); tcase_add_test (tc_swap, test_ntoh_4); suite_add_tcase (s, tc_swap); @@ -1124,8 +944,6 @@ test_suite (void) tcase_add_test (tc_block, test_show_version_1); tcase_add_test (tc_block, test_show_version_2); tcase_add_test (tc_block, test_loopbacks_1); - tcase_add_test (tc_block, test_stats_1); - tcase_add_test (tc_block, test_stats_2); suite_add_tcase (s, tc_block); TCase *tc_nonblock = tcase_create ("Nonblocking API"); @@ -1135,7 +953,6 @@ test_suite (void) tcase_add_test (tc_nonblock, test_show_version_4); tcase_add_test (tc_nonblock, test_show_version_5); tcase_add_test (tc_nonblock, test_loopbacks_2); - tcase_add_test (tc_nonblock, test_stats_3); tcase_add_test (tc_nonblock, test_no_response_1); tcase_add_test (tc_nonblock, test_no_response_2); suite_add_tcase (s, tc_nonblock); diff --git a/test/ext/vapi_cpp_test.cpp b/test/ext/vapi_cpp_test.cpp index 25ea9cc7f7b..68366af2ac8 100644 --- a/test/ext/vapi_cpp_test.cpp +++ b/test/ext/vapi_cpp_test.cpp @@ -24,12 +24,10 @@ #include #include #include -#include #include DEFINE_VAPI_MSG_IDS_VPE_API_JSON; DEFINE_VAPI_MSG_IDS_INTERFACE_API_JSON; -DEFINE_VAPI_MSG_IDS_STATS_API_JSON; DEFINE_VAPI_MSG_IDS_FAKE_API_JSON; static char *app_name = nullptr; @@ -51,8 +49,11 @@ void verify_show_version_reply (const Show_version_reply &r) auto &p = r.get_payload (); printf ("show_version_reply: program: `%s', version: `%s', build directory: " "`%s', build date: `%s'\n", - p.program, p.version, p.build_directory, p.build_date); - ck_assert_str_eq ("vpe", (char *)p.program); + vl_api_from_api_string (&p.program), + vl_api_from_api_string (&p.version), + vl_api_from_api_string (&p.build_directory), + vl_api_from_api_string (&p.build_date)); + ck_assert_str_eq ("vpe", (char *)vl_api_from_api_string (&p.program)); } Connection con; @@ -358,152 +359,6 @@ START_TEST (test_loopbacks_2) END_TEST; -START_TEST (test_stats_1) -{ - printf ("--- Receive single stats by waiting for response ---\n"); - Want_stats ws (con); - auto &payload = ws.get_request ().get_payload (); - payload.enable_disable = 1; - payload.pid = getpid (); - auto rv = ws.execute (); - ck_assert_int_eq (VAPI_OK, rv); - Event_registration sc (con); - WAIT_FOR_RESPONSE (sc, rv); - ck_assert_int_eq (VAPI_OK, rv); - auto &rs = sc.get_result_set (); - int count = 0; - for (auto &r : rs) - { - printf ("simple counters: first_sw_if_index=%u\n", - r.get_payload ().first_sw_if_index); - ++count; - } - ck_assert_int_ne (0, count); -} - -END_TEST; - -struct Vnet_interface_simple_counters_cb -{ - Vnet_interface_simple_counters_cb () : called{0} {}; - int called; - vapi_error_e - operator() (Event_registration &e) - { - ++called; - auto &rs = e.get_result_set (); - int count = 0; - for (auto &r : rs) - { - printf ("simple counters: first_sw_if_index=%u\n", - r.get_payload ().first_sw_if_index); - ++count; - } - ck_assert_int_ne (0, count); - return VAPI_OK; - } -}; - -START_TEST (test_stats_2) -{ - printf ("--- Receive single stats by getting a callback ---\n"); - Want_stats ws (con); - auto &payload = ws.get_request ().get_payload (); - payload.enable_disable = 1; - payload.pid = getpid (); - auto rv = ws.execute (); - ck_assert_int_eq (VAPI_OK, rv); - Vnet_interface_simple_counters_cb cb; - Event_registration sc (con, std::ref (cb)); - WAIT_FOR_RESPONSE (sc, rv); - ck_assert_int_eq (VAPI_OK, rv); - ck_assert_int_ne (0, cb.called); -} - -END_TEST; - -struct Vnet_interface_simple_counters_2_cb -{ - Vnet_interface_simple_counters_2_cb () : called{0}, total{0} {}; - int called; - int total; - vapi_error_e - operator() (Event_registration &e) - { - ++called; - auto &rs = e.get_result_set (); - int count = 0; - for (auto &r : rs) - { - printf ("simple counters: first_sw_if_index=%u\n", - r.get_payload ().first_sw_if_index); - ++count; - } - rs.free_all_responses (); - ck_assert_int_ne (0, count); - total += count; - return VAPI_OK; - } -}; - -START_TEST (test_stats_3) -{ - printf ( - "--- Receive single stats by getting a callback - clear results ---\n"); - Want_stats ws (con); - auto &payload = ws.get_request ().get_payload (); - payload.enable_disable = 1; - payload.pid = getpid (); - auto rv = ws.execute (); - ck_assert_int_eq (VAPI_OK, rv); - Vnet_interface_simple_counters_2_cb cb; - Event_registration sc (con, std::ref (cb)); - for (int i = 0; i < 5; ++i) - { - WAIT_FOR_RESPONSE (sc, rv); - } - ck_assert_int_eq (VAPI_OK, rv); - ck_assert_int_eq (5, cb.called); - ck_assert_int_eq (5, cb.total); -} - -END_TEST; - -START_TEST (test_stats_4) -{ - printf ("--- Receive multiple stats by waiting for response ---\n"); - Want_stats ws (con); - auto &payload = ws.get_request ().get_payload (); - payload.enable_disable = 1; - payload.pid = getpid (); - auto rv = ws.execute (); - ck_assert_int_eq (VAPI_OK, rv); - Event_registration sc (con); - Event_registration cc (con); - WAIT_FOR_RESPONSE (sc, rv); - ck_assert_int_eq (VAPI_OK, rv); - WAIT_FOR_RESPONSE (cc, rv); - ck_assert_int_eq (VAPI_OK, rv); - int count = 0; - for (auto &r : sc.get_result_set ()) - { - printf ("simple counters: first_sw_if_index=%u\n", - r.get_payload ().first_sw_if_index); - ++count; - } - ck_assert_int_ne (0, count); - count = 0; - for (auto &r : cc.get_result_set ()) - { - printf ("combined counters: first_sw_if_index=%u\n", - r.get_payload ().first_sw_if_index); - ++count; - } - ck_assert_int_ne (0, count); -} - -END_TEST; - START_TEST (test_unsupported) { printf ("--- Unsupported messages ---\n"); @@ -556,10 +411,6 @@ Suite *test_suite (void) tcase_add_test (tc_cpp_api, test_show_version_2); tcase_add_test (tc_cpp_api, test_loopbacks_1); tcase_add_test (tc_cpp_api, test_loopbacks_2); - tcase_add_test (tc_cpp_api, test_stats_1); - tcase_add_test (tc_cpp_api, test_stats_2); - tcase_add_test (tc_cpp_api, test_stats_3); - tcase_add_test (tc_cpp_api, test_stats_4); tcase_add_test (tc_cpp_api, test_unsupported); suite_add_tcase (s, tc_cpp_api); diff --git a/test/ext/vom_test.cpp b/test/ext/vom_test.cpp index 6aacea9803b..7d7325413bd 100644 --- a/test/ext/vom_test.cpp +++ b/test/ext/vom_test.cpp @@ -1348,9 +1348,9 @@ BOOST_AUTO_TEST_CASE(test_igmp) { const std::string Isaiah = "IsaiahBerlin"; rc_t rc = rc_t::OK; - boost::asio::ip::address gaddr = boost::asio::ip::address::from_string("232.0.0.1"); - boost::asio::ip::address saddr1 = boost::asio::ip::address::from_string("192.168.0.20"); - boost::asio::ip::address saddr2 = boost::asio::ip::address::from_string("192.168.0.30"); + boost::asio::ip::address_v4 gaddr = boost::asio::ip::address_v4::from_string("232.0.0.1"); + boost::asio::ip::address_v4 saddr1 = boost::asio::ip::address_v4::from_string("192.168.0.20"); + boost::asio::ip::address_v4 saddr2 = boost::asio::ip::address_v4::from_string("192.168.0.30"); std::string itf3_name = "host3"; interface itf3(itf3_name,