Refactor the session manager using session transformation 2D array & Update test case

This commit is contained in:
luwenpeng
2024-03-14 10:56:09 +08:00
parent 639614622b
commit ce00122557
47 changed files with 3403 additions and 3563 deletions

View File

@@ -137,7 +137,7 @@ static void *main_loop(void *arg)
int nr_recv;
int need_drop_pkt = 1; // TODO
uint64_t now_sec = 0;
uint64_t now = 0;
uint16_t thr_idx = threads_ctx->index;
if (packet_io_init(packet_io, thr_idx) != 0)
@@ -152,7 +152,7 @@ static void *main_loop(void *arg)
while (ATOMIC_READ(&threads_ctx->need_exit) == 0)
{
now_sec = timestamp_get_sec(); // TODO
now = timestamp_get_msec(); // TODO
nr_recv = packet_io_ingress(packet_io, thr_idx, packets, RX_BURST_MAX);
if (nr_recv == 0)
{
@@ -166,7 +166,7 @@ static void *main_loop(void *arg)
// call plugin_manager_dispatch_raw_pkt();
if (packet_is_fragment(pkt))
{
struct packet *defraged_pkt = ip_reassembly_packet(ip_reass, pkt, now_sec);
struct packet *defraged_pkt = ip_reassembly_packet(ip_reass, pkt, now);
if (defraged_pkt == NULL)
{
continue;
@@ -183,19 +183,17 @@ static void *main_loop(void *arg)
sess = session_manager_lookup_session(sess_mgr, pkt);
if (sess == NULL)
{
sess = session_manager_new_session(sess_mgr, pkt);
sess = session_manager_new_session(sess_mgr, pkt, now);
if (sess == NULL)
{
continue;
}
plug_mgr_ctx = plugin_manager_new_ctx();
session_set_id(sess, id_generator_alloc(now_sec, thr_idx));
session_set_user_data(sess, plug_mgr_ctx);
}
else
{
session_manager_update_session(sess_mgr, sess, pkt);
session_manager_update_session(sess_mgr, sess, pkt, now);
}
plugin_manager_dispatch(plug_mgr, sess, pkt);
}
@@ -232,7 +230,7 @@ static void *main_loop(void *arg)
}
}
while ((expired_sess = session_manager_get_expired_session(sess_mgr)))
while ((expired_sess = session_manager_get_expired_session(sess_mgr, now)))
{
plug_mgr_ctx = session_get_user_data(expired_sess);
plugin_manager_free_ctx(plug_mgr_ctx);
@@ -253,6 +251,7 @@ static void *main_loop(void *arg)
static int thread_context_init(struct stellar_context *ctx, uint8_t nr_threads)
{
uint64_t now = timestamp_get_msec();
for (uint8_t i = 0; i < nr_threads; i++)
{
struct thread_context *threads_ctx = &ctx->threads_ctx[i];
@@ -260,7 +259,7 @@ static int thread_context_init(struct stellar_context *ctx, uint8_t nr_threads)
threads_ctx->need_exit = 0;
threads_ctx->is_runing = 0;
threads_ctx->sess_mgr = session_manager_new(sess_mgr_opts);
threads_ctx->sess_mgr = session_manager_new(sess_mgr_opts, now);
if (threads_ctx->sess_mgr == NULL)
{
STELLAR_LOG_ERROR("unable to create session manager");