summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorluwenpeng <[email protected]>2024-11-07 19:11:49 +0800
committerluwenpeng <[email protected]>2024-11-07 19:11:49 +0800
commit50a841919def2d5536fddf0dcdac2ebfc2d53e53 (patch)
treebc5d146c2a5408bcac7030df6cc4a93a25caafa4
parente93480d05de6c7b8635bf933efa68050363f6c7e (diff)
rename session_filter to session_dabloom
-rw-r--r--infra/session_manager/session_dabloom.c60
-rw-r--r--infra/session_manager/session_dabloom.h18
-rw-r--r--infra/session_manager/session_filter.c60
-rw-r--r--infra/session_manager/session_filter.h17
-rw-r--r--infra/session_manager/test/CMakeLists.txt6
-rw-r--r--infra/session_manager/test/gtest_session_dabloom.cpp (renamed from infra/session_manager/test/gtest_session_filter.cpp)26
-rw-r--r--infra/session_manager/test/test_utils.h2
7 files changed, 95 insertions, 94 deletions
diff --git a/infra/session_manager/session_dabloom.c b/infra/session_manager/session_dabloom.c
new file mode 100644
index 0000000..6cf828c
--- /dev/null
+++ b/infra/session_manager/session_dabloom.c
@@ -0,0 +1,60 @@
+#include "dablooms.h"
+#include "session_dabloom.h"
+
+struct session_dabloom
+{
+ struct expiry_dablooms_handle *dablooms;
+};
+
+struct session_dabloom *session_dabloom_new(uint32_t capacity, uint32_t timeout, double error_rate, uint64_t now)
+{
+ struct session_dabloom *sess_dab = (struct session_dabloom *)calloc(1, sizeof(struct session_dabloom));
+ if (sess_dab == NULL)
+ {
+ return NULL;
+ }
+
+ sess_dab->dablooms = expiry_dablooms_new(capacity, error_rate, now, timeout);
+ if (sess_dab->dablooms == NULL)
+ {
+ free(sess_dab);
+ return NULL;
+ }
+
+ return sess_dab;
+}
+
+void session_dabloom_free(struct session_dabloom *sess_dab)
+{
+ if (sess_dab)
+ {
+ if (sess_dab->dablooms)
+ {
+ expiry_dablooms_free(sess_dab->dablooms);
+ sess_dab->dablooms = NULL;
+ }
+ free(sess_dab);
+ sess_dab = NULL;
+ }
+}
+
+// return 1: found
+// reutrn 0: no found
+int session_dabloom_lookup(struct session_dabloom *sess_dab, const struct tuple6 *key, uint64_t now)
+{
+ if (expiry_dablooms_search(sess_dab->dablooms, (const char *)key, sizeof(struct tuple6), now) == 1)
+ {
+ return 1;
+ }
+
+ return 0;
+}
+
+void session_dabloom_add(struct session_dabloom *sess_dab, const struct tuple6 *key, uint64_t now)
+{
+ struct tuple6 reverse_key;
+ tuple6_reverse(key, &reverse_key);
+
+ expiry_dablooms_add(sess_dab->dablooms, (const char *)key, sizeof(struct tuple6), now);
+ expiry_dablooms_add(sess_dab->dablooms, (const char *)&reverse_key, sizeof(struct tuple6), now);
+}
diff --git a/infra/session_manager/session_dabloom.h b/infra/session_manager/session_dabloom.h
new file mode 100644
index 0000000..b0de2ac
--- /dev/null
+++ b/infra/session_manager/session_dabloom.h
@@ -0,0 +1,18 @@
+#pragma once
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+#include "tuple.h"
+
+struct session_dabloom *session_dabloom_new(uint32_t capacity, uint32_t timeout, double error_rate, uint64_t now);
+void session_dabloom_free(struct session_dabloom *sess_dab);
+
+int session_dabloom_lookup(struct session_dabloom *sess_dab, const struct tuple6 *key, uint64_t now);
+void session_dabloom_add(struct session_dabloom *sess_dab, const struct tuple6 *key, uint64_t now);
+
+#ifdef __cplusplus
+}
+#endif
diff --git a/infra/session_manager/session_filter.c b/infra/session_manager/session_filter.c
deleted file mode 100644
index 8a3c40f..0000000
--- a/infra/session_manager/session_filter.c
+++ /dev/null
@@ -1,60 +0,0 @@
-#include "dablooms.h"
-#include "session_filter.h"
-
-struct session_filter
-{
- struct expiry_dablooms_handle *dablooms;
-};
-
-struct session_filter *session_filter_new(uint32_t capacity, uint32_t timeout, double error_rate, uint64_t now)
-{
- struct session_filter *filter = (struct session_filter *)calloc(1, sizeof(struct session_filter));
- if (filter == NULL)
- {
- return NULL;
- }
-
- filter->dablooms = expiry_dablooms_new(capacity, error_rate, now, timeout);
- if (filter->dablooms == NULL)
- {
- free(filter);
- return NULL;
- }
-
- return filter;
-}
-
-void session_filter_free(struct session_filter *filter)
-{
- if (filter)
- {
- if (filter->dablooms)
- {
- expiry_dablooms_free(filter->dablooms);
- filter->dablooms = NULL;
- }
- free(filter);
- filter = NULL;
- }
-}
-
-// return 1: found
-// reutrn 0: no found
-int session_filter_lookup(struct session_filter *filter, const struct tuple6 *key, uint64_t now)
-{
- if (expiry_dablooms_search(filter->dablooms, (const char *)key, sizeof(struct tuple6), now) == 1)
- {
- return 1;
- }
-
- return 0;
-}
-
-void session_filter_add(struct session_filter *filter, const struct tuple6 *key, uint64_t now)
-{
- struct tuple6 reverse_key;
- tuple6_reverse(key, &reverse_key);
-
- expiry_dablooms_add(filter->dablooms, (const char *)key, sizeof(struct tuple6), now);
- expiry_dablooms_add(filter->dablooms, (const char *)&reverse_key, sizeof(struct tuple6), now);
-}
diff --git a/infra/session_manager/session_filter.h b/infra/session_manager/session_filter.h
deleted file mode 100644
index f8be6a2..0000000
--- a/infra/session_manager/session_filter.h
+++ /dev/null
@@ -1,17 +0,0 @@
-#pragma once
-
-#ifdef __cplusplus
-extern "C"
-{
-#endif
-
-#include "tuple.h"
-
-struct session_filter *session_filter_new(uint32_t capacity, uint32_t timeout, double error_rate, uint64_t now);
-void session_filter_free(struct session_filter *filter);
-int session_filter_lookup(struct session_filter *filter, const struct tuple6 *key, uint64_t now);
-void session_filter_add(struct session_filter *filter, const struct tuple6 *key, uint64_t now);
-
-#ifdef __cplusplus
-}
-#endif
diff --git a/infra/session_manager/test/CMakeLists.txt b/infra/session_manager/test/CMakeLists.txt
index 63823a5..e0e7ede 100644
--- a/infra/session_manager/test/CMakeLists.txt
+++ b/infra/session_manager/test/CMakeLists.txt
@@ -11,8 +11,8 @@ target_link_libraries(gtest_session_table session_manager gtest)
add_executable(gtest_session_timer gtest_session_timer.cpp)
target_link_libraries(gtest_session_timer session_manager gtest)
-add_executable(gtest_session_filter gtest_session_filter.cpp)
-target_link_libraries(gtest_session_filter session_manager gtest)
+add_executable(gtest_session_dabloom gtest_session_dabloom.cpp)
+target_link_libraries(gtest_session_dabloom session_manager gtest)
###############################################################################
# gtest state machine (TCP)
@@ -123,7 +123,7 @@ include(GoogleTest)
gtest_discover_tests(gtest_session_pool)
gtest_discover_tests(gtest_session_table)
gtest_discover_tests(gtest_session_timer)
-gtest_discover_tests(gtest_session_filter)
+gtest_discover_tests(gtest_session_dabloom)
gtest_discover_tests(gtest_state_tcp_init_to_opening)
gtest_discover_tests(gtest_state_tcp_opening_to_active)
diff --git a/infra/session_manager/test/gtest_session_filter.cpp b/infra/session_manager/test/gtest_session_dabloom.cpp
index c9c6d05..293f08e 100644
--- a/infra/session_manager/test/gtest_session_filter.cpp
+++ b/infra/session_manager/test/gtest_session_dabloom.cpp
@@ -1,6 +1,6 @@
#include "test_utils.h"
-TEST(SESSION_FILTER, TEST)
+TEST(SESSION_DABLOOM, TEST)
{
struct tuple6 c2s_key;
struct tuple6 s2c_key;
@@ -27,20 +27,20 @@ TEST(SESSION_FILTER, TEST)
s2c_key.ip_proto = 0x05;
s2c_key.domain = 0x0606060606060606;
- struct session_filter *filter = session_filter_new(capacity, timeout, error_rate, 1);
+ struct session_dabloom *filter = session_dabloom_new(capacity, timeout, error_rate, 1);
EXPECT_TRUE(filter != nullptr);
- EXPECT_TRUE(session_filter_lookup(filter, &c2s_key, 1) == 0); // no found
- EXPECT_TRUE(session_filter_lookup(filter, &s2c_key, 1) == 0); // no found
- session_filter_add(filter, &c2s_key, 1); // add
- EXPECT_TRUE(session_filter_lookup(filter, &c2s_key, 1) == 1); // found
- EXPECT_TRUE(session_filter_lookup(filter, &s2c_key, 1) == 1); // found
- EXPECT_TRUE(session_filter_lookup(filter, &c2s_key, 2) == 1); // found
- EXPECT_TRUE(session_filter_lookup(filter, &s2c_key, 2) == 1); // found
- EXPECT_TRUE(session_filter_lookup(filter, &c2s_key, 3) == 0); // not found
- EXPECT_TRUE(session_filter_lookup(filter, &s2c_key, 3) == 0); // not found
-
- session_filter_free(filter);
+ EXPECT_TRUE(session_dabloom_lookup(filter, &c2s_key, 1) == 0); // no found
+ EXPECT_TRUE(session_dabloom_lookup(filter, &s2c_key, 1) == 0); // no found
+ session_dabloom_add(filter, &c2s_key, 1); // add
+ EXPECT_TRUE(session_dabloom_lookup(filter, &c2s_key, 1) == 1); // found
+ EXPECT_TRUE(session_dabloom_lookup(filter, &s2c_key, 1) == 1); // found
+ EXPECT_TRUE(session_dabloom_lookup(filter, &c2s_key, 2) == 1); // found
+ EXPECT_TRUE(session_dabloom_lookup(filter, &s2c_key, 2) == 1); // found
+ EXPECT_TRUE(session_dabloom_lookup(filter, &c2s_key, 3) == 0); // not found
+ EXPECT_TRUE(session_dabloom_lookup(filter, &s2c_key, 3) == 0); // not found
+
+ session_dabloom_free(filter);
}
int main(int argc, char **argv)
diff --git a/infra/session_manager/test/test_utils.h b/infra/session_manager/test/test_utils.h
index c3ceedb..66ae334 100644
--- a/infra/session_manager/test/test_utils.h
+++ b/infra/session_manager/test/test_utils.h
@@ -15,7 +15,7 @@ extern "C"
#include "session_pool.h"
#include "session_timer.h"
#include "session_table.h"
-#include "session_filter.h"
+#include "session_dabloom.h"
#include "session_internal.h"
#include "session_transition.h"
#include "session_manager_cfg.h"