http: disable timer node if session disabled 06/43006/7
authorSemir Sionek <[email protected]>
Thu, 22 May 2025 13:14:59 +0000 (13:14 +0000)
committerFlorin Coras <[email protected]>
Wed, 28 May 2025 17:46:27 +0000 (17:46 +0000)
Type: improvement
Change-Id: Ie6d343c7712edfd644b6d133007ae10b40359894
Signed-off-by: Semir Sionek <[email protected]>
extras/hs-test/http_test.go
src/plugins/http/http.c
src/plugins/http/http_timer.c
src/plugins/http/http_timer.h

index f85804e..e572826 100644 (file)
@@ -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
index 1aed2fd..2c923c6 100644 (file)
@@ -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);
index 580f316..5cb4daa 100644 (file)
@@ -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);
 }
 
 /*
index 5ce4203..ac4f71a 100644 (file)
@@ -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)