summaryrefslogtreecommitdiffstats
path: root/src/plugins/http/http_timer.c
diff options
context:
space:
mode:
authorFlorin Coras <fcoras@cisco.com>2022-01-13 11:59:44 -0800
committerFlorin Coras <fcoras@cisco.com>2022-01-20 00:39:21 -0800
commit0b65621d41619e242b136e78fecfb325c90ae0bc (patch)
tree300e7002f2eae2afb5c235e2fe96705e34a79dbe /src/plugins/http/http_timer.c
parentb85de19145a01d3acdf326c3cfa4e94b585bb59f (diff)
http: add http protocol plugin
Basic HTTP/1.1 server side implementation. Type: feature Signed-off-by: Florin Coras <fcoras@cisco.com> Change-Id: I06bddaf7f11e28db802b4cd7ef8160c78cb019b6
Diffstat (limited to 'src/plugins/http/http_timer.c')
-rw-r--r--src/plugins/http/http_timer.c91
1 files changed, 91 insertions, 0 deletions
diff --git a/src/plugins/http/http_timer.c b/src/plugins/http/http_timer.c
new file mode 100644
index 00000000000..42fe69076fe
--- /dev/null
+++ b/src/plugins/http/http_timer.c
@@ -0,0 +1,91 @@
+/*
+ * Copyright (c) 2022 Cisco and/or its affiliates.
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at:
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <http/http_timer.h>
+#include <vnet/session/session.h>
+
+http_tw_ctx_t http_tw_ctx;
+
+static void
+http_timer_process_expired_cb (u32 *expired_timers)
+{
+ http_tw_ctx_t *twc = &http_tw_ctx;
+ u32 hs_handle;
+ int i;
+
+ for (i = 0; i < vec_len (expired_timers); i++)
+ {
+ /* Get session handle. The first bit is the timer id */
+ hs_handle = expired_timers[i] & 0x7FFFFFFF;
+ session_send_rpc_evt_to_thread (hs_handle >> 24, twc->cb_fn,
+ uword_to_pointer (hs_handle, void *));
+ }
+}
+
+static uword
+http_timer_process (vlib_main_t *vm, vlib_node_runtime_t *rt, vlib_frame_t *f)
+{
+ http_tw_ctx_t *twc = &http_tw_ctx;
+ f64 now, timeout = 1.0;
+ uword *event_data = 0;
+ uword __clib_unused event_type;
+
+ while (1)
+ {
+ vlib_process_wait_for_event_or_clock (vm, timeout);
+ now = vlib_time_now (vm);
+ event_type = vlib_process_get_events (vm, (uword **) &event_data);
+
+ /* expire timers */
+ clib_spinlock_lock (&twc->tw_lock);
+ tw_timer_expire_timers_2t_1w_2048sl (&twc->tw, now);
+ clib_spinlock_unlock (&twc->tw_lock);
+
+ vec_reset_length (event_data);
+ }
+ 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_init (vlib_main_t *vm, http_conn_timeout_fn *cb_fn)
+{
+ http_tw_ctx_t *twc = &http_tw_ctx;
+ vlib_node_t *n;
+
+ tw_timer_wheel_init_2t_1w_2048sl (&twc->tw, http_timer_process_expired_cb,
+ 1.0 /* timer interval */, ~0);
+ clib_spinlock_init (&twc->tw_lock);
+ twc->cb_fn = cb_fn;
+
+ 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);
+}
+
+/*
+ * fd.io coding-style-patch-verification: ON
+ *
+ * Local Variables:
+ * eval: (c-set-style "gnu")
+ * End:
+ */