X-Git-Url: https://gerrit.fd.io/r/gitweb?a=blobdiff_plain;f=src%2Fplugins%2Funittest%2Fsession_test.c;h=70d9fd02048d5a8850046f7ae2adc9071e9b38c8;hb=309f7aac170767028a2e6e7e9424ec3d13304aff;hp=fa6a99ffbf039f2deea34edd12d3cb07036d8aad;hpb=a5160d7d1f0dda554960e1f0e9f7074bda256baa;p=vpp.git diff --git a/src/plugins/unittest/session_test.c b/src/plugins/unittest/session_test.c index fa6a99ffbf0..70d9fd02048 100644 --- a/src/plugins/unittest/session_test.c +++ b/src/plugins/unittest/session_test.c @@ -45,7 +45,7 @@ fformat(stderr, _comment "\n", ##_args); \ void -dummy_session_reset_callback (session_t * s) +placeholder_session_reset_callback (session_t * s) { clib_warning ("called..."); } @@ -53,8 +53,8 @@ dummy_session_reset_callback (session_t * s) volatile u32 connected_session_index = ~0; volatile u32 connected_session_thread = ~0; int -dummy_session_connected_callback (u32 app_index, u32 api_context, - session_t * s, u8 is_fail) +placeholder_session_connected_callback (u32 app_index, u32 api_context, + session_t * s, session_error_t err) { if (s) { @@ -64,36 +64,36 @@ dummy_session_connected_callback (u32 app_index, u32 api_context, return 0; } -static u32 dummy_segment_count; +static u32 placeholder_segment_count; int -dummy_add_segment_callback (u32 client_index, u64 segment_handle) +placeholder_add_segment_callback (u32 client_index, u64 segment_handle) { - dummy_segment_count = 1; + placeholder_segment_count = 1; return 0; } int -dummy_del_segment_callback (u32 client_index, u64 segment_handle) +placeholder_del_segment_callback (u32 client_index, u64 segment_handle) { - dummy_segment_count = 0; + placeholder_segment_count = 0; return 0; } void -dummy_session_disconnect_callback (session_t * s) +placeholder_session_disconnect_callback (session_t * s) { clib_warning ("called..."); } -static u32 dummy_accept; +static u32 placeholder_accept; volatile u32 accepted_session_index; volatile u32 accepted_session_thread; int -dummy_session_accept_callback (session_t * s) +placeholder_session_accept_callback (session_t * s) { - dummy_accept = 1; + placeholder_accept = 1; accepted_session_index = s->session_index; accepted_session_thread = s->thread_index; s->session_state = SESSION_STATE_READY; @@ -101,21 +101,21 @@ dummy_session_accept_callback (session_t * s) } int -dummy_server_rx_callback (session_t * s) +placeholder_server_rx_callback (session_t * s) { clib_warning ("called..."); return -1; } /* *INDENT-OFF* */ -static session_cb_vft_t dummy_session_cbs = { - .session_reset_callback = dummy_session_reset_callback, - .session_connected_callback = dummy_session_connected_callback, - .session_accept_callback = dummy_session_accept_callback, - .session_disconnect_callback = dummy_session_disconnect_callback, - .builtin_app_rx_callback = dummy_server_rx_callback, - .add_segment_callback = dummy_add_segment_callback, - .del_segment_callback = dummy_del_segment_callback, +static session_cb_vft_t placeholder_session_cbs = { + .session_reset_callback = placeholder_session_reset_callback, + .session_connected_callback = placeholder_session_connected_callback, + .session_accept_callback = placeholder_session_accept_callback, + .session_disconnect_callback = placeholder_session_disconnect_callback, + .builtin_app_rx_callback = placeholder_server_rx_callback, + .add_segment_callback = placeholder_add_segment_callback, + .del_segment_callback = placeholder_del_segment_callback, }; /* *INDENT-ON* */ @@ -136,7 +136,7 @@ session_create_lookpback (u32 table_id, u32 * sw_if_index, if (table_id != 0) { ip_table_create (FIB_PROTOCOL_IP4, table_id, 0, 0); - ip_table_bind (FIB_PROTOCOL_IP4, *sw_if_index, table_id, 0); + ip_table_bind (FIB_PROTOCOL_IP4, *sw_if_index, table_id); } vnet_sw_interface_set_flags (vnet_get_main (), *sw_if_index, @@ -158,12 +158,14 @@ session_delete_loopback (u32 sw_if_index) { /* fails spectacularly */ /* vnet_delete_loopback_interface (sw_if_index); */ + + vnet_sw_interface_set_flags (vnet_get_main (), sw_if_index, 0); } static int session_test_basic (vlib_main_t * vm, unformat_input_t * input) { - session_endpoint_t server_sep = SESSION_ENDPOINT_NULL; + session_endpoint_cfg_t server_sep = SESSION_ENDPOINT_CFG_NULL; u64 options[APP_OPTIONS_N_OPTIONS], bind4_handle, bind6_handle; u32 server_index; int error = 0; @@ -176,7 +178,7 @@ session_test_basic (vlib_main_t * vm, unformat_input_t * input) .api_client_index = ~0, .options = options, .namespace_id = 0, - .session_cb_vft = &dummy_session_cbs, + .session_cb_vft = &placeholder_session_cbs, .name = format (0, "session_test"), }; @@ -187,8 +189,9 @@ session_test_basic (vlib_main_t * vm, unformat_input_t * input) server_sep.is_ip4 = 1; vnet_listen_args_t bind_args = { - .sep = server_sep, + .sep_ext = server_sep, .app_index = 0, + .wrk_map_index = 0, }; bind_args.app_index = server_index; @@ -275,9 +278,9 @@ session_test_endpoint_cfg (vlib_main_t * vm, unformat_input_t * input) { session_endpoint_cfg_t client_sep = SESSION_ENDPOINT_CFG_NULL; u32 server_index, client_index, sw_if_index[2], tries = 0; - u64 options[APP_OPTIONS_N_OPTIONS], dummy_secret = 1234; - u16 dummy_server_port = 1234, dummy_client_port = 5678; - session_endpoint_t server_sep = SESSION_ENDPOINT_NULL; + u64 options[APP_OPTIONS_N_OPTIONS], placeholder_secret = 1234; + u16 placeholder_server_port = 1234, placeholder_client_port = 5678; + session_endpoint_cfg_t server_sep = SESSION_ENDPOINT_CFG_NULL; ip4_address_t intf_addr[3]; transport_connection_t *tc; session_t *s; @@ -287,11 +290,11 @@ session_test_endpoint_cfg (vlib_main_t * vm, unformat_input_t * input) /* * Create the loopbacks */ - intf_addr[0].as_u32 = clib_host_to_net_u32 (0x01010101), - session_create_lookpback (0, &sw_if_index[0], &intf_addr[0]); + intf_addr[0].as_u32 = clib_host_to_net_u32 (0x01010101); + session_create_lookpback (0, &sw_if_index[0], &intf_addr[0]); - intf_addr[1].as_u32 = clib_host_to_net_u32 (0x02020202), - session_create_lookpback (1, &sw_if_index[1], &intf_addr[1]); + intf_addr[1].as_u32 = clib_host_to_net_u32 (0x02020202); + session_create_lookpback (1, &sw_if_index[1], &intf_addr[1]); session_add_del_route_via_lookup_in_table (0, 1, &intf_addr[1], 32, 1 /* is_add */ ); @@ -304,7 +307,7 @@ session_test_endpoint_cfg (vlib_main_t * vm, unformat_input_t * input) appns_id = format (0, "appns1"); vnet_app_namespace_add_del_args_t ns_args = { .ns_id = appns_id, - .secret = dummy_secret, + .secret = placeholder_secret, .sw_if_index = sw_if_index[1], .ip4_fib_id = 0, .is_add = 1 @@ -323,7 +326,7 @@ session_test_endpoint_cfg (vlib_main_t * vm, unformat_input_t * input) .api_client_index = ~0, .options = options, .namespace_id = 0, - .session_cb_vft = &dummy_session_cbs, + .session_cb_vft = &placeholder_session_cbs, .name = format (0, "session_test_client"), }; @@ -334,7 +337,10 @@ session_test_endpoint_cfg (vlib_main_t * vm, unformat_input_t * input) attach_args.name = format (0, "session_test_server"); attach_args.namespace_id = appns_id; - attach_args.options[APP_OPTIONS_NAMESPACE_SECRET] = dummy_secret; + /* Allow server to allocate another segment for listens. Needed + * because by default we do not allow segment additions */ + attach_args.options[APP_OPTIONS_ADD_SEGMENT_SIZE] = 32 << 20; + attach_args.options[APP_OPTIONS_NAMESPACE_SECRET] = placeholder_secret; error = vnet_application_attach (&attach_args); SESSION_TEST ((error == 0), "server app attached: %U", format_clib_error, error); @@ -342,9 +348,9 @@ session_test_endpoint_cfg (vlib_main_t * vm, unformat_input_t * input) server_index = attach_args.app_index; server_sep.is_ip4 = 1; - server_sep.port = dummy_server_port; + server_sep.port = placeholder_server_port; vnet_listen_args_t bind_args = { - .sep = server_sep, + .sep_ext = server_sep, .app_index = server_index, }; error = vnet_listen (&bind_args); @@ -355,10 +361,10 @@ session_test_endpoint_cfg (vlib_main_t * vm, unformat_input_t * input) */ client_sep.is_ip4 = 1; client_sep.ip.ip4.as_u32 = clib_host_to_net_u32 (0x02020202); - client_sep.port = dummy_server_port; + client_sep.port = placeholder_server_port; client_sep.peer.is_ip4 = 1; client_sep.peer.ip.ip4.as_u32 = clib_host_to_net_u32 (0x01010101); - client_sep.peer.port = dummy_client_port; + client_sep.peer.port = placeholder_client_port; client_sep.transport_proto = TRANSPORT_PROTO_TCP; vnet_connect_args_t connect_args = { @@ -372,9 +378,19 @@ session_test_endpoint_cfg (vlib_main_t * vm, unformat_input_t * input) SESSION_TEST ((error == 0), "connect should work"); /* wait for stuff to happen */ - while ((connected_session_index == ~0 - || vec_len (tcp_main.wrk_ctx[0].pending_acks)) && ++tries < 100) - vlib_process_suspend (vm, 100e-3); + while (connected_session_index == ~0 && ++tries < 100) + { + vlib_worker_thread_barrier_release (vm); + vlib_process_suspend (vm, 100e-3); + vlib_worker_thread_barrier_sync (vm); + } + while (accepted_session_index == ~0 && ++tries < 100) + { + vlib_worker_thread_barrier_release (vm); + vlib_process_suspend (vm, 100e-3); + vlib_worker_thread_barrier_sync (vm); + } + clib_warning ("waited %.1f seconds for connections", tries / 10.0); SESSION_TEST ((connected_session_index != ~0), "session should exist"); SESSION_TEST ((connected_session_thread != ~0), "thread should exist"); @@ -385,15 +401,8 @@ session_test_endpoint_cfg (vlib_main_t * vm, unformat_input_t * input) SESSION_TEST ((tc != 0), "transport should exist"); SESSION_TEST ((memcmp (&tc->lcl_ip, &client_sep.peer.ip, sizeof (tc->lcl_ip)) == 0), "ips should be equal"); - SESSION_TEST ((tc->lcl_port == dummy_client_port), "ports should be equal"); - - /* These sessions, because of the way they're established are pinned to - * main thread, even when we have workers and we avoid polling main thread, - * i.e., we can't cleanup pending disconnects, so force cleanup for both - */ - session_transport_cleanup (s); - s = session_get (accepted_session_index, accepted_session_thread); - session_transport_cleanup (s); + SESSION_TEST ((tc->lcl_port == placeholder_client_port), + "ports should be equal"); vnet_app_detach_args_t detach_args = { .app_index = server_index, @@ -403,6 +412,10 @@ session_test_endpoint_cfg (vlib_main_t * vm, unformat_input_t * input) detach_args.app_index = client_index; vnet_application_detach (&detach_args); + ns_args.is_add = 0; + error = vnet_app_namespace_add_del (&ns_args); + SESSION_TEST ((error == 0), "app ns delete should succeed: %d", error); + /* Allow the disconnects to finish before removing the routes. */ vlib_process_suspend (vm, 10e-3); @@ -419,25 +432,29 @@ session_test_endpoint_cfg (vlib_main_t * vm, unformat_input_t * input) static int session_test_namespace (vlib_main_t * vm, unformat_input_t * input) { - u64 options[APP_OPTIONS_N_OPTIONS], dummy_secret = 1234; + u64 options[APP_OPTIONS_N_OPTIONS], placeholder_secret = 1234, tries; u32 server_index, server_st_index, server_local_st_index; - u32 dummy_port = 1234, client_index, server_wrk_index; - u32 dummy_api_context = 4321, dummy_client_api_index = ~0; - u32 dummy_server_api_index = ~0, sw_if_index = 0; + u32 placeholder_port = 1234, client_index, server_wrk_index; + u32 placeholder_api_context = 4321, placeholder_client_api_index = ~0; + u32 placeholder_server_api_index = ~0, sw_if_index = 0; session_endpoint_t server_sep = SESSION_ENDPOINT_NULL; session_endpoint_t client_sep = SESSION_ENDPOINT_NULL; session_endpoint_t intf_sep = SESSION_ENDPOINT_NULL; - u8 *ns_id = format (0, "appns1"); + u8 *ns_id, *server_name, *client_name; app_namespace_t *app_ns; application_t *server; session_t *s; u64 handle; int error = 0; + ns_id = format (0, "appns1"); + server_name = format (0, "session_test"); + client_name = format (0, "session_test_client"); + server_sep.is_ip4 = 1; - server_sep.port = dummy_port; + server_sep.port = placeholder_port; client_sep.is_ip4 = 1; - client_sep.port = dummy_port; + client_sep.port = placeholder_port; clib_memset (options, 0, sizeof (options)); options[APP_OPTIONS_FLAGS] = APP_OPTIONS_FLAGS_IS_BUILTIN; @@ -445,8 +462,8 @@ session_test_namespace (vlib_main_t * vm, unformat_input_t * input) .api_client_index = ~0, .options = options, .namespace_id = 0, - .session_cb_vft = &dummy_session_cbs, - .name = format (0, "session_test"), + .session_cb_vft = &placeholder_session_cbs, + .name = server_name, }; vnet_listen_args_t bind_args = { @@ -476,7 +493,7 @@ session_test_namespace (vlib_main_t * vm, unformat_input_t * input) intf_sep.ip.ip4 = intf_addr; intf_sep.is_ip4 = 1; - intf_sep.port = dummy_port; + intf_sep.port = placeholder_port; /* * Insert namespace and lookup @@ -484,7 +501,7 @@ session_test_namespace (vlib_main_t * vm, unformat_input_t * input) vnet_app_namespace_add_del_args_t ns_args = { .ns_id = ns_id, - .secret = dummy_secret, + .secret = placeholder_secret, .sw_if_index = APP_NAMESPACE_INVALID_INDEX, .is_add = 1 }; @@ -493,8 +510,8 @@ session_test_namespace (vlib_main_t * vm, unformat_input_t * input) app_ns = app_namespace_get_from_id (ns_id); SESSION_TEST ((app_ns != 0), "should find ns %v status", ns_id); - SESSION_TEST ((app_ns->ns_secret == dummy_secret), "secret should be %d", - dummy_secret); + SESSION_TEST ((app_ns->ns_secret == placeholder_secret), + "secret should be %d", placeholder_secret); SESSION_TEST ((app_ns->sw_if_index == APP_NAMESPACE_INVALID_INDEX), "sw_if_index should be invalid"); @@ -504,9 +521,9 @@ session_test_namespace (vlib_main_t * vm, unformat_input_t * input) options[APP_OPTIONS_FLAGS] |= APP_OPTIONS_FLAGS_USE_GLOBAL_SCOPE; options[APP_OPTIONS_FLAGS] |= APP_OPTIONS_FLAGS_USE_LOCAL_SCOPE; - options[APP_OPTIONS_NAMESPACE_SECRET] = dummy_secret - 1; + options[APP_OPTIONS_NAMESPACE_SECRET] = placeholder_secret - 1; attach_args.namespace_id = ns_id; - attach_args.api_client_index = dummy_server_api_index; + attach_args.api_client_index = placeholder_server_api_index; error = vnet_application_attach (&attach_args); SESSION_TEST ((error != 0), "app attachment should fail"); @@ -520,7 +537,7 @@ session_test_namespace (vlib_main_t * vm, unformat_input_t * input) options[APP_OPTIONS_FLAGS] &= ~APP_OPTIONS_FLAGS_USE_LOCAL_SCOPE; options[APP_OPTIONS_NAMESPACE_SECRET] = 0; attach_args.namespace_id = 0; - attach_args.api_client_index = dummy_server_api_index; + attach_args.api_client_index = placeholder_server_api_index; error = vnet_application_attach (&attach_args); SESSION_TEST ((error == 0), "server attachment should work"); server_index = attach_args.app_index; @@ -558,9 +575,9 @@ session_test_namespace (vlib_main_t * vm, unformat_input_t * input) */ options[APP_OPTIONS_FLAGS] |= APP_OPTIONS_FLAGS_USE_GLOBAL_SCOPE; options[APP_OPTIONS_FLAGS] |= APP_OPTIONS_FLAGS_USE_LOCAL_SCOPE; - options[APP_OPTIONS_NAMESPACE_SECRET] = dummy_secret; + options[APP_OPTIONS_NAMESPACE_SECRET] = placeholder_secret; attach_args.namespace_id = ns_id; - attach_args.api_client_index = dummy_server_api_index; + attach_args.api_client_index = placeholder_server_api_index; error = vnet_application_attach (&attach_args); SESSION_TEST ((error == 0), "server attachment should work"); server_index = attach_args.app_index; @@ -586,35 +603,47 @@ session_test_namespace (vlib_main_t * vm, unformat_input_t * input) * Try client connect with 1) local scope 2) global scope */ options[APP_OPTIONS_FLAGS] &= ~APP_OPTIONS_FLAGS_USE_GLOBAL_SCOPE; - attach_args.api_client_index = dummy_client_api_index; + attach_args.name = client_name; + attach_args.api_client_index = placeholder_client_api_index; error = vnet_application_attach (&attach_args); SESSION_TEST ((error == 0), "client attachment should work"); client_index = attach_args.app_index; - connect_args.api_context = dummy_api_context; + connect_args.api_context = placeholder_api_context; connect_args.app_index = client_index; error = vnet_connect (&connect_args); SESSION_TEST ((error != 0), "client connect should return error code"); - SESSION_TEST ((error == VNET_API_ERROR_INVALID_VALUE), + SESSION_TEST ((error == SESSION_E_INVALID_RMT_IP), "error code should be invalid value (zero ip)"); - SESSION_TEST ((dummy_segment_count == 0), + SESSION_TEST ((placeholder_segment_count == 0), "shouldn't have received request to map new segment"); connect_args.sep.ip.ip4.as_u8[0] = 127; error = vnet_connect (&connect_args); SESSION_TEST ((error == 0), "client connect should not return error code"); - SESSION_TEST ((dummy_segment_count == 1), + + /* wait for accept */ + tries = 0; + while (!placeholder_accept && ++tries < 100) + { + vlib_worker_thread_barrier_release (vm); + vlib_process_suspend (vm, 100e-3); + vlib_worker_thread_barrier_sync (vm); + } + + SESSION_TEST ((placeholder_segment_count == 1), "should've received request to map new segment"); - SESSION_TEST ((dummy_accept == 1), "should've received accept request"); + SESSION_TEST ((placeholder_accept == 1), + "should've received accept request"); detach_args.app_index = client_index; vnet_application_detach (&detach_args); options[APP_OPTIONS_FLAGS] &= ~APP_OPTIONS_FLAGS_USE_LOCAL_SCOPE; options[APP_OPTIONS_FLAGS] |= APP_OPTIONS_FLAGS_USE_GLOBAL_SCOPE; - attach_args.api_client_index = dummy_client_api_index; + attach_args.api_client_index = placeholder_client_api_index; error = vnet_application_attach (&attach_args); SESSION_TEST ((error == 0), "client attachment should work"); error = vnet_connect (&connect_args); SESSION_TEST ((error != 0), "client connect should return error code"); - SESSION_TEST ((error == VNET_API_ERROR_SESSION_CONNECT), + SESSION_TEST ((error == SESSION_E_NOINTF), "error code should be connect (nothing in local scope)"); detach_args.app_index = client_index; vnet_application_detach (&detach_args); @@ -638,7 +667,8 @@ session_test_namespace (vlib_main_t * vm, unformat_input_t * input) options[APP_OPTIONS_FLAGS] &= ~APP_OPTIONS_FLAGS_USE_GLOBAL_SCOPE; options[APP_OPTIONS_FLAGS] |= APP_OPTIONS_FLAGS_USE_LOCAL_SCOPE; - attach_args.api_client_index = dummy_server_api_index; + attach_args.api_client_index = placeholder_server_api_index; + attach_args.name = server_name; error = vnet_application_attach (&attach_args); SESSION_TEST ((error == 0), "app attachment should work"); server_index = attach_args.app_index; @@ -672,12 +702,13 @@ session_test_namespace (vlib_main_t * vm, unformat_input_t * input) options[APP_OPTIONS_FLAGS] &= ~APP_OPTIONS_FLAGS_USE_GLOBAL_SCOPE; options[APP_OPTIONS_FLAGS] |= APP_OPTIONS_FLAGS_USE_LOCAL_SCOPE; attach_args.namespace_id = 0; - attach_args.api_client_index = dummy_client_api_index; + attach_args.api_client_index = placeholder_client_api_index; + attach_args.name = client_name; vnet_application_attach (&attach_args); error = vnet_connect (&connect_args); SESSION_TEST ((error != 0), "client connect should return error code"); - SESSION_TEST ((error == VNET_API_ERROR_SESSION_CONNECT), - "error code should be connect (not in same ns)"); + SESSION_TEST ((error == SESSION_E_NOROUTE), + "error code should be noroute (not in same ns)"); detach_args.app_index = client_index; vnet_application_detach (&detach_args); @@ -704,9 +735,10 @@ session_test_namespace (vlib_main_t * vm, unformat_input_t * input) */ options[APP_OPTIONS_FLAGS] |= APP_OPTIONS_FLAGS_USE_GLOBAL_SCOPE; options[APP_OPTIONS_FLAGS] |= APP_OPTIONS_FLAGS_USE_LOCAL_SCOPE; - options[APP_OPTIONS_NAMESPACE_SECRET] = dummy_secret; + options[APP_OPTIONS_NAMESPACE_SECRET] = placeholder_secret; attach_args.namespace_id = ns_id; - attach_args.api_client_index = dummy_server_api_index; + attach_args.api_client_index = placeholder_server_api_index; + attach_args.name = server_name; error = vnet_application_attach (&attach_args); SESSION_TEST ((error == 0), "server attachment should work"); server_index = attach_args.app_index; @@ -730,10 +762,15 @@ session_test_namespace (vlib_main_t * vm, unformat_input_t * input) detach_args.app_index = server_index; vnet_application_detach (&detach_args); + ns_args.is_add = 0; + error = vnet_app_namespace_add_del (&ns_args); + SESSION_TEST ((error == 0), "app ns delete should succeed: %d", error); + /* * Cleanup */ - vec_free (attach_args.name); + vec_free (server_name); + vec_free (client_name); vec_free (ns_id); session_delete_loopback (sw_if_index); return 0; @@ -1014,9 +1051,9 @@ session_test_rules (vlib_main_t * vm, unformat_input_t * input) u64 options[APP_OPTIONS_N_OPTIONS]; u16 lcl_port = 1234, rmt_port = 4321; u32 server_index, server_index2; - u32 dummy_server_api_index = ~0; + u32 placeholder_server_api_index = ~0; transport_connection_t *tc; - u32 dummy_port = 1111; + u32 placeholder_port = 1111; u8 is_filtered = 0, *ns_id = format (0, "appns1"); session_t *listener, *s; app_namespace_t *default_ns = app_namespace_get_default (); @@ -1040,14 +1077,14 @@ session_test_rules (vlib_main_t * vm, unformat_input_t * input) } server_sep.is_ip4 = 1; - server_sep.port = dummy_port; + server_sep.port = placeholder_port; clib_memset (options, 0, sizeof (options)); vnet_app_attach_args_t attach_args = { .api_client_index = ~0, .options = options, .namespace_id = 0, - .session_cb_vft = &dummy_session_cbs, + .session_cb_vft = &placeholder_session_cbs, .name = format (0, "session_test"), }; @@ -1063,7 +1100,7 @@ session_test_rules (vlib_main_t * vm, unformat_input_t * input) options[APP_OPTIONS_FLAGS] |= APP_OPTIONS_FLAGS_USE_GLOBAL_SCOPE; options[APP_OPTIONS_FLAGS] |= APP_OPTIONS_FLAGS_USE_LOCAL_SCOPE; attach_args.namespace_id = 0; - attach_args.api_client_index = dummy_server_api_index; + attach_args.api_client_index = placeholder_server_api_index; error = vnet_application_attach (&attach_args); SESSION_TEST ((error == 0), "server attached"); server_index = attach_args.app_index; @@ -1253,8 +1290,7 @@ session_test_rules (vlib_main_t * vm, unformat_input_t * input) /* Try connecting */ error = vnet_connect (&connect_args); SESSION_TEST ((error != 0), "connect should fail"); - SESSION_TEST ((error == VNET_API_ERROR_APP_CONNECT_FILTERED), - "connect should be filtered"); + SESSION_TEST ((error == SESSION_E_FILTERED), "connect should be filtered"); sep.ip.ip4.as_u32 -= 1 << 24; @@ -1488,7 +1524,9 @@ session_test_rules (vlib_main_t * vm, unformat_input_t * input) app_ns = app_namespace_get_from_id (ns_id); attach_args.namespace_id = ns_id; - attach_args.api_client_index = dummy_server_api_index; + attach_args.api_client_index = placeholder_server_api_index; + vec_free (attach_args.name); + attach_args.name = format (0, "server_test2"); error = vnet_application_attach (&attach_args); SESSION_TEST ((error == 0), "server2 attached"); server_index2 = attach_args.app_index; @@ -1527,8 +1565,7 @@ session_test_rules (vlib_main_t * vm, unformat_input_t * input) error = vnet_connect (&connect_args); SESSION_TEST ((error != 0), "connect should fail"); - SESSION_TEST ((error == VNET_API_ERROR_APP_CONNECT_FILTERED), - "connect should be filtered"); + SESSION_TEST ((error == SESSION_E_FILTERED), "connect should be filtered"); /* * Lookup test namespace @@ -1540,8 +1577,7 @@ session_test_rules (vlib_main_t * vm, unformat_input_t * input) connect_args.app_index = server_index; error = vnet_connect (&connect_args); SESSION_TEST ((error != 0), "connect should fail"); - SESSION_TEST ((error == VNET_API_ERROR_APP_CONNECT_FILTERED), - "connect should be filtered"); + SESSION_TEST ((error == SESSION_E_FILTERED), "connect should be filtered"); args.table_args.is_add = 0; vnet_session_rule_add_del (&args); @@ -1565,6 +1601,10 @@ session_test_rules (vlib_main_t * vm, unformat_input_t * input) detach_args.app_index = server_index2; vnet_application_detach (&detach_args); + ns_args.is_add = 0; + error = vnet_app_namespace_add_del (&ns_args); + SESSION_TEST ((error == 0), "app ns delete should succeed: %d", error); + vec_free (ns_id); vec_free (attach_args.name); return 0; @@ -1578,7 +1618,7 @@ session_test_proxy (vlib_main_t * vm, unformat_input_t * input) char *show_local_listeners = "sh app ns table default"; unformat_input_t tmp_input; u32 server_index, app_index; - u32 dummy_server_api_index = ~0, sw_if_index = 0; + u32 placeholder_server_api_index = ~0, sw_if_index = 0; u8 is_filtered = 0; session_t *s; transport_connection_t *tc; @@ -1635,11 +1675,11 @@ session_test_proxy (vlib_main_t * vm, unformat_input_t * input) .api_client_index = ~0, .options = options, .namespace_id = 0, - .session_cb_vft = &dummy_session_cbs, + .session_cb_vft = &placeholder_session_cbs, .name = format (0, "session_test"), }; - attach_args.api_client_index = dummy_server_api_index; + attach_args.api_client_index = placeholder_server_api_index; error = vnet_application_attach (&attach_args); SESSION_TEST ((error == 0), "server attachment should work"); server_index = attach_args.app_index; @@ -1693,6 +1733,7 @@ session_test_proxy (vlib_main_t * vm, unformat_input_t * input) if (verbose) unformat_free (&tmp_input); vec_free (attach_args.name); + session_delete_loopback (sw_if_index); return 0; } @@ -1701,9 +1742,7 @@ wait_for_event (svm_msg_q_t * mq, int fd, int epfd, u8 use_eventfd) { if (!use_eventfd) { - svm_msg_q_lock (mq); - while (svm_msg_q_is_empty (mq)) - svm_msg_q_wait (mq); + svm_msg_q_wait (mq, SVM_MQ_WAIT_EMPTY); } else { @@ -1727,16 +1766,13 @@ wait_for_event (svm_msg_q_t * mq, int fd, int epfd, u8 use_eventfd) continue; if (!svm_msg_q_is_empty (mq)) - { - svm_msg_q_lock (mq); - break; - } + break; } } } static int -session_test_mq (vlib_main_t * vm, unformat_input_t * input) +session_test_mq_speed (vlib_main_t * vm, unformat_input_t * input) { int error, __clib_unused verbose, use_eventfd = 0; u64 i, n_test_msgs = 1 << 10, *counter; @@ -1746,7 +1782,6 @@ session_test_mq (vlib_main_t * vm, unformat_input_t * input) vl_api_registration_t *reg; struct epoll_event ep_evt; u32 app_index, api_index; - u32 fifo_segment_index; app_worker_t *app_wrk; segment_manager_t *sm; svm_msg_q_msg_t msg; @@ -1785,14 +1820,12 @@ session_test_mq (vlib_main_t * vm, unformat_input_t * input) /* Shut up coverity */ if (reg == 0) abort (); - if (!session_main.evt_qs_use_memfd_seg) - reg->clib_file_index = VL_API_INVALID_FI; vnet_app_attach_args_t attach_args = { .api_client_index = api_index, .options = options, .namespace_id = 0, - .session_cb_vft = &dummy_session_cbs, + .session_cb_vft = &placeholder_session_cbs, .name = format (0, "session_mq_test"), }; error = vnet_application_attach (&attach_args); @@ -1805,19 +1838,17 @@ session_test_mq (vlib_main_t * vm, unformat_input_t * input) mq = app_wrk->event_queue; if (use_eventfd) { - svm_msg_q_alloc_producer_eventfd (mq); - svm_msg_q_alloc_consumer_eventfd (mq); - prod_fd = svm_msg_q_get_producer_eventfd (mq); + svm_msg_q_alloc_eventfd (mq); + prod_fd = svm_msg_q_get_eventfd (mq); SESSION_TEST (prod_fd != -1, "mq producer eventd valid %u", prod_fd); } - sm = app_worker_get_or_alloc_connect_segment_manager (app_wrk); - segment_manager_alloc_session_fifos (sm, &rx_fifo, &tx_fifo, - &fifo_segment_index); + sm = app_worker_get_connect_segment_manager (app_wrk); + segment_manager_alloc_session_fifos (sm, 0, &rx_fifo, &tx_fifo); s.rx_fifo = rx_fifo; s.tx_fifo = tx_fifo; s.session_state = SESSION_STATE_READY; - counter = (u64 *) rx_fifo->data; + counter = (u64 *) f_head_cptr (rx_fifo)->data; start = vlib_time_now (vm); pid = fork (); @@ -1839,7 +1870,7 @@ session_test_mq (vlib_main_t * vm, unformat_input_t * input) for (i = 0; i < n_test_msgs; i++) { wait_for_event (mq, prod_fd, epfd, use_eventfd); - svm_msg_q_sub_w_lock (mq, &msg); + svm_msg_q_sub_raw (mq, &msg); svm_msg_q_free_msg (mq, &msg); svm_msg_q_unlock (mq); *counter = *counter + 1; @@ -1870,6 +1901,110 @@ session_test_mq (vlib_main_t * vm, unformat_input_t * input) return 0; } +static int +session_test_mq_basic (vlib_main_t * vm, unformat_input_t * input) +{ + svm_msg_q_cfg_t _cfg, *cfg = &_cfg; + svm_msg_q_msg_t msg1, msg2, msg[12]; + int __clib_unused verbose, i, rv; + svm_msg_q_shared_t *smq; + svm_msg_q_ring_t *ring; + svm_msg_q_t _mq = { 0 }, *mq = &_mq; + u8 *rings_ptr; + + while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) + { + if (unformat (input, "verbose")) + verbose = 1; + else + { + vlib_cli_output (vm, "parse error: '%U'", format_unformat_error, + input); + return -1; + } + } + + svm_msg_q_ring_cfg_t rc[2] = { {8, 8, 0} + , {8, 16, 0} + }; + cfg->consumer_pid = ~0; + cfg->n_rings = 2; + cfg->q_nitems = 16; + cfg->ring_cfgs = rc; + + smq = svm_msg_q_alloc (cfg); + svm_msg_q_attach (mq, smq); + SESSION_TEST (smq != 0, "svm_msg_q_alloc"); + SESSION_TEST (vec_len (mq->rings) == 2, "ring allocation"); + rings_ptr = (u8 *) mq->rings[0].shr->data; + vec_foreach (ring, mq->rings) + { + SESSION_TEST (ring->shr->data == rings_ptr, "ring data"); + rings_ptr += (uword) ring->nitems * ring->elsize; + rings_ptr += sizeof (svm_msg_q_ring_shared_t); + } + + msg1 = svm_msg_q_alloc_msg (mq, 8); + rv = (mq->rings[0].shr->cursize != 1 || msg1.ring_index != 0 || + msg1.elt_index != 0); + SESSION_TEST (rv == 0, "msg alloc1"); + + msg2 = svm_msg_q_alloc_msg (mq, 15); + rv = (mq->rings[1].shr->cursize != 1 || msg2.ring_index != 1 || + msg2.elt_index != 0); + SESSION_TEST (rv == 0, "msg alloc2"); + + svm_msg_q_free_msg (mq, &msg1); + SESSION_TEST (mq->rings[0].shr->cursize == 0, "free msg"); + + for (i = 0; i < 12; i++) + { + msg[i] = svm_msg_q_alloc_msg (mq, 7); + *(u32 *) svm_msg_q_msg_data (mq, &msg[i]) = i; + } + + rv = (mq->rings[0].shr->cursize != 8 || mq->rings[1].shr->cursize != 5); + SESSION_TEST (rv == 0, "msg alloc3"); + + *(u32 *) svm_msg_q_msg_data (mq, &msg2) = 123; + svm_msg_q_add (mq, &msg2, SVM_Q_NOWAIT); + for (i = 0; i < 12; i++) + svm_msg_q_add (mq, &msg[i], SVM_Q_NOWAIT); + + rv = svm_msg_q_sub (mq, &msg2, SVM_Q_NOWAIT, 0); + SESSION_TEST (rv == 0, "dequeue1"); + + SESSION_TEST (msg2.ring_index == 1 && msg2.elt_index == 0, + "dequeue1 result"); + rv = (*(u32 *) svm_msg_q_msg_data (mq, &msg2) == 123); + SESSION_TEST (rv, "dequeue 1 data"); + + svm_msg_q_free_msg (mq, &msg2); + + for (i = 0; i < 12; i++) + { + if (svm_msg_q_sub (mq, &msg[i], SVM_Q_NOWAIT, 0)) + SESSION_TEST (0, "dequeue2"); + if (i < 8) + { + if (msg[i].ring_index != 0 || msg[i].elt_index != (i + 1) % 8) + SESSION_TEST (0, "dequeue2 result2"); + } + else + { + if (msg[i].ring_index != 1 || msg[i].elt_index != (i - 8) + 1) + SESSION_TEST (0, "dequeue2 result3"); + } + if (*(u32 *) svm_msg_q_msg_data (mq, &msg[i]) != i) + SESSION_TEST (0, "dequeue2 wrong data"); + svm_msg_q_free_msg (mq, &msg[i]); + } + rv = (mq->rings[0].shr->cursize == 0 && mq->rings[1].shr->cursize == 0); + SESSION_TEST (rv, "post dequeue"); + + return 0; +} + static clib_error_t * session_test (vlib_main_t * vm, unformat_input_t * input, vlib_cli_command_t * cmd_arg) @@ -1892,8 +2027,10 @@ session_test (vlib_main_t * vm, res = session_test_proxy (vm, input); else if (unformat (input, "endpt-cfg")) res = session_test_endpoint_cfg (vm, input); - else if (unformat (input, "mq")) - res = session_test_mq (vm, input); + else if (unformat (input, "mq-speed")) + res = session_test_mq_speed (vm, input); + else if (unformat (input, "mq-basic")) + res = session_test_mq_basic (vm, input); else if (unformat (input, "all")) { if ((res = session_test_basic (vm, input))) @@ -1908,7 +2045,9 @@ session_test (vlib_main_t * vm, goto done; if ((res = session_test_endpoint_cfg (vm, input))) goto done; - if ((res = session_test_mq (vm, input))) + if ((res = session_test_mq_speed (vm, input))) + goto done; + if ((res = session_test_mq_basic (vm, input))) goto done; } else