refactor: move evicted_session_filter to session dir

This commit is contained in:
luwenpeng
2024-08-16 11:18:16 +08:00
parent f4d437d58b
commit da891dffa7
9 changed files with 52 additions and 66 deletions

View File

@@ -14,6 +14,9 @@ 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)
###############################################################################
# gtest state machine (TCP)
###############################################################################
@@ -110,6 +113,7 @@ gtest_discover_tests(gtest_session)
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_state_tcp_init_to_opening)
gtest_discover_tests(gtest_state_tcp_opening_to_active)

View File

@@ -0,0 +1,53 @@
#include <gtest/gtest.h>
#include "tuple.h"
#include "session_filter.h"
TEST(SESSION_FILTER, TEST)
{
struct tuple6 c2s_key;
struct tuple6 s2c_key;
uint32_t capacity = 1000000;
uint32_t timeout = 2;
double error_rate = 0.00001;
memset(&c2s_key, 0, sizeof(c2s_key));
c2s_key.addr_family = AF_INET;
c2s_key.src_addr.v4.s_addr = inet_addr("192.168.1.2");
c2s_key.dst_addr.v4.s_addr = inet_addr("192.168.1.3");
c2s_key.src_port = 0x0303;
c2s_key.dst_port = 0x0404;
c2s_key.ip_proto = 0x05;
c2s_key.domain = 0x0606060606060606;
memset(&s2c_key, 0, sizeof(s2c_key));
s2c_key.addr_family = AF_INET;
s2c_key.src_addr.v4.s_addr = inet_addr("192.168.1.3");
s2c_key.dst_addr.v4.s_addr = inet_addr("192.168.1.2");
s2c_key.src_port = 0x0404;
s2c_key.dst_port = 0x0303;
s2c_key.ip_proto = 0x05;
s2c_key.domain = 0x0606060606060606;
struct session_filter *filter = session_filter_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);
}
int main(int argc, char **argv)
{
::testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}