From: Semir Sionek Date: Thu, 22 May 2025 13:14:59 +0000 (+0000) Subject: http: disable timer node if session disabled X-Git-Url: https://gerrit.fd.io/r/gitweb?a=commitdiff_plain;h=refs%2Fchanges%2F06%2F43006%2F7;p=vpp.git http: disable timer node if session disabled Type: improvement Change-Id: Ie6d343c7712edfd644b6d133007ae10b40359894 Signed-off-by: Semir Sionek --- diff --git a/extras/hs-test/http_test.go b/extras/hs-test/http_test.go index f85804e165e..e572826a19d 100644 --- a/extras/hs-test/http_test.go +++ b/extras/hs-test/http_test.go @@ -37,7 +37,7 @@ func init() { HttpClientGetTlsNoRespBodyTest, HttpClientPostFileTest, HttpClientPostFilePtrTest, HttpUnitTest, HttpRequestLineTest, HttpClientGetTimeout, HttpStaticFileHandlerWrkTest, HttpStaticUrlHandlerWrkTest, HttpConnTimeoutTest, HttpClientGetRepeatTest, HttpClientPostRepeatTest, HttpIgnoreH2UpgradeTest, HttpInvalidAuthorityFormUriTest, HttpHeaderErrorConnectionDropTest, - HttpClientInvalidHeaderNameTest, HttpStaticHttp1OnlyTest) + HttpClientInvalidHeaderNameTest, HttpStaticHttp1OnlyTest, HttpTimerSessionDisable) RegisterNoTopoSoloTests(HttpStaticPromTest, HttpGetTpsTest, HttpGetTpsInterruptModeTest, PromConcurrentConnectionsTest, PromMemLeakTest, HttpClientPostMemLeakTest, HttpInvalidClientRequestMemLeakTest, HttpPostTpsTest, HttpPostTpsInterruptModeTest, PromConsecutiveConnectionsTest, HttpGetTpsTlsTest, HttpPostTpsTlsTest, HttpClientGetRepeatMTTest, HttpClientPtrGetRepeatMTTest) @@ -1376,6 +1376,23 @@ func HttpInvalidRequestLineTest(s *NoTopoSuite) { s.AssertContains(resp, "HTTP/1.1 400 Bad Request", "'HTTP1.1' invalid http version not allowed") } +func HttpTimerSessionDisable(s *NoTopoSuite) { + vpp := s.Containers.Vpp.VppInstance + serverAddress := s.VppAddr() + ":" + s.Ports.Http + s.Log(vpp.Vppctl("http static server www-root " + wwwRootPath + " uri tcp://" + serverAddress)) + time.Sleep(250 * time.Millisecond) + resp := vpp.Vppctl("show node http-timer-process") + s.AssertContains(resp, "node http-timer-process, type process, state \"any wait\"") + vpp.Vppctl("session disable") + time.Sleep(1 * time.Second) + resp = vpp.Vppctl("show node http-timer-process") + s.AssertContains(resp, "node http-timer-process, type process, state \"not started\"") + vpp.Vppctl("session enable") + time.Sleep(100 * time.Millisecond) + resp = vpp.Vppctl("show node http-timer-process") + s.AssertContains(resp, "node http-timer-process, type process, state \"any wait\"") +} + func HttpRequestLineTest(s *NoTopoSuite) { vpp := s.Containers.Vpp.VppInstance serverAddress := s.VppAddr() + ":" + s.Ports.Http diff --git a/src/plugins/http/http.c b/src/plugins/http/http.c index 1aed2fd358d..2c923c69eed 100644 --- a/src/plugins/http/http.c +++ b/src/plugins/http/http.c @@ -792,6 +792,7 @@ http_transport_enable (vlib_main_t *vm, u8 is_en) da->app_index = hm->app_index; da->api_client_index = APP_INVALID_INDEX; vnet_application_detach (da); + http_timers_set_state (vm, false); return 0; } @@ -819,7 +820,10 @@ http_transport_enable (vlib_main_t *vm, u8 is_en) vec_free (a->name); if (hm->is_init) - return 0; + { + http_timers_set_state (vm, true); + return 0; + } vec_validate (hm->wrk, num_threads - 1); vec_validate (hm->rx_bufs, num_threads - 1); diff --git a/src/plugins/http/http_timer.c b/src/plugins/http/http_timer.c index 580f31657a9..5cb4daa52dc 100644 --- a/src/plugins/http/http_timer.c +++ b/src/plugins/http/http_timer.c @@ -18,6 +18,9 @@ http_tw_ctx_t http_tw_ctx; +static uword http_timer_process (vlib_main_t *vm, vlib_node_runtime_t *rt, + vlib_frame_t *f); + static void http_timer_process_expired_cb (u32 *expired_timers) { @@ -42,6 +45,13 @@ http_timer_process_expired_cb (u32 *expired_timers) } } +VLIB_REGISTER_NODE (http_timer_process_node) = { + .function = http_timer_process, + .type = VLIB_NODE_TYPE_PROCESS, + .name = "http-timer-process", + .state = VLIB_NODE_STATE_DISABLED, +}; + static uword http_timer_process (vlib_main_t *vm, vlib_node_runtime_t *rt, vlib_frame_t *f) { @@ -50,7 +60,8 @@ http_timer_process (vlib_main_t *vm, vlib_node_runtime_t *rt, vlib_frame_t *f) uword *event_data = 0; uword __clib_unused event_type; - while (1) + while (vlib_node_get_state (vm, http_timer_process_node.index) != + VLIB_NODE_STATE_DISABLED) { vlib_process_wait_for_event_or_clock (vm, timeout); now = vlib_time_now (vm); @@ -66,19 +77,26 @@ http_timer_process (vlib_main_t *vm, vlib_node_runtime_t *rt, vlib_frame_t *f) return 0; } -VLIB_REGISTER_NODE (http_timer_process_node) = { - .function = http_timer_process, - .type = VLIB_NODE_TYPE_PROCESS, - .name = "http-timer-process", - .state = VLIB_NODE_STATE_DISABLED, -}; +void +http_timers_set_state (vlib_main_t *vm, bool enabled) +{ + vlib_node_t *n; + + vlib_node_set_state ( + vm, http_timer_process_node.index, + (enabled ? VLIB_NODE_STATE_POLLING : VLIB_NODE_STATE_DISABLED)); + if (enabled) + { + n = vlib_get_node (vm, http_timer_process_node.index); + vlib_start_process (vm, n->runtime_index); + } +} void http_timers_init (vlib_main_t *vm, http_conn_timeout_fn *rpc_cb, http_conn_invalidate_timer_fn *invalidate_cb) { http_tw_ctx_t *twc = &http_tw_ctx; - vlib_node_t *n; ASSERT (twc->tw.timers == 0); @@ -88,10 +106,7 @@ http_timers_init (vlib_main_t *vm, http_conn_timeout_fn *rpc_cb, twc->rpc_cb = rpc_cb; twc->invalidate_cb = invalidate_cb; - vlib_node_set_state (vm, http_timer_process_node.index, - VLIB_NODE_STATE_POLLING); - n = vlib_get_node (vm, http_timer_process_node.index); - vlib_start_process (vm, n->runtime_index); + http_timers_set_state (vm, true); } /* diff --git a/src/plugins/http/http_timer.h b/src/plugins/http/http_timer.h index 5ce42032f20..ac4f71afab6 100644 --- a/src/plugins/http/http_timer.h +++ b/src/plugins/http/http_timer.h @@ -37,6 +37,7 @@ extern http_tw_ctx_t http_tw_ctx; void http_timers_init (vlib_main_t *vm, http_conn_timeout_fn *rpc_cb, http_conn_invalidate_timer_fn *invalidate_cb); +void http_timers_set_state (vlib_main_t *vm, bool enabled); static inline void http_conn_timer_start (http_conn_t *hc)