refactor: move evicted_session_filter to session dir
This commit is contained in:
@@ -1,5 +0,0 @@
|
||||
add_library(evicted_session_filter evicted_session_filter.cpp)
|
||||
target_include_directories(evicted_session_filter PUBLIC ${CMAKE_CURRENT_LIST_DIR})
|
||||
target_link_libraries(evicted_session_filter packet dablooms)
|
||||
|
||||
add_subdirectory(test)
|
||||
@@ -1,18 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
struct evicted_session_filter *evicted_session_filter_new(uint32_t capacity, uint32_t timeout, double error_rate, uint64_t now);
|
||||
void evicted_session_filter_free(struct evicted_session_filter *filter);
|
||||
|
||||
// return 1: found
|
||||
// reutrn 0: no found
|
||||
int evicted_session_filter_lookup(struct evicted_session_filter *filter, const struct tuple6 *key, uint64_t now);
|
||||
void evicted_session_filter_add(struct evicted_session_filter *filter, const struct tuple6 *key, uint64_t now);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
@@ -1,5 +0,0 @@
|
||||
add_executable(gtest_evicted_session_filter gtest_evicted_session_filter.cpp)
|
||||
target_link_libraries(gtest_evicted_session_filter evicted_session_filter gtest)
|
||||
|
||||
include(GoogleTest)
|
||||
gtest_discover_tests(gtest_evicted_session_filter)
|
||||
@@ -3,6 +3,7 @@ add_library(session_manager
|
||||
session_pool.cpp
|
||||
session_table.cpp
|
||||
session_timer.cpp
|
||||
session_filter.cpp
|
||||
session_manager.cpp
|
||||
session_transition.cpp
|
||||
)
|
||||
@@ -10,6 +11,6 @@ target_include_directories(session_manager PUBLIC ${CMAKE_CURRENT_LIST_DIR})
|
||||
target_include_directories(session_manager PUBLIC ${CMAKE_SOURCE_DIR}/src/stellar)
|
||||
target_include_directories(session_manager PUBLIC ${CMAKE_SOURCE_DIR}/include)
|
||||
target_include_directories(session_manager PUBLIC ${CMAKE_SOURCE_DIR}/src/utils)
|
||||
target_link_libraries(session_manager timeout snowflake duplicated_packet_filter evicted_session_filter log tcp_reassembly)
|
||||
target_link_libraries(session_manager timeout snowflake duplicated_packet_filter dablooms log tcp_reassembly)
|
||||
|
||||
add_subdirectory(test)
|
||||
@@ -1,24 +1,15 @@
|
||||
#include <string.h>
|
||||
|
||||
#include "tuple.h"
|
||||
#include "dablooms.h"
|
||||
#include "udp_utils.h"
|
||||
#include "ip4_utils.h"
|
||||
#include "ip6_utils.h"
|
||||
#include "evicted_session_filter.h"
|
||||
#include "session_filter.h"
|
||||
|
||||
struct evicted_session_filter
|
||||
struct session_filter
|
||||
{
|
||||
struct expiry_dablooms_handle *dablooms;
|
||||
};
|
||||
|
||||
/******************************************************************************
|
||||
* Public API
|
||||
******************************************************************************/
|
||||
|
||||
struct evicted_session_filter *evicted_session_filter_new(uint32_t capacity, uint32_t timeout, double error_rate, uint64_t now)
|
||||
struct session_filter *session_filter_new(uint32_t capacity, uint32_t timeout, double error_rate, uint64_t now)
|
||||
{
|
||||
struct evicted_session_filter *filter = (struct evicted_session_filter *)calloc(1, sizeof(struct evicted_session_filter));
|
||||
struct session_filter *filter = (struct session_filter *)calloc(1, sizeof(struct session_filter));
|
||||
if (filter == NULL)
|
||||
{
|
||||
return NULL;
|
||||
@@ -34,7 +25,7 @@ struct evicted_session_filter *evicted_session_filter_new(uint32_t capacity, uin
|
||||
return filter;
|
||||
}
|
||||
|
||||
void evicted_session_filter_free(struct evicted_session_filter *filter)
|
||||
void session_filter_free(struct session_filter *filter)
|
||||
{
|
||||
if (filter)
|
||||
{
|
||||
@@ -50,7 +41,7 @@ void evicted_session_filter_free(struct evicted_session_filter *filter)
|
||||
|
||||
// return 1: found
|
||||
// reutrn 0: no found
|
||||
int evicted_session_filter_lookup(struct evicted_session_filter *filter, const struct tuple6 *key, uint64_t now)
|
||||
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)
|
||||
{
|
||||
@@ -60,7 +51,7 @@ int evicted_session_filter_lookup(struct evicted_session_filter *filter, const s
|
||||
return 0;
|
||||
}
|
||||
|
||||
void evicted_session_filter_add(struct evicted_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)
|
||||
{
|
||||
struct tuple6 reverse_key;
|
||||
tuple6_reverse(key, &reverse_key);
|
||||
18
src/session/session_filter.h
Normal file
18
src/session/session_filter.h
Normal file
@@ -0,0 +1,18 @@
|
||||
#pragma once
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
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);
|
||||
|
||||
// return 1: found
|
||||
// reutrn 0: no found
|
||||
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
|
||||
@@ -14,9 +14,9 @@
|
||||
#include "session_pool.h"
|
||||
#include "session_table.h"
|
||||
#include "session_timer.h"
|
||||
#include "session_filter.h"
|
||||
#include "session_manager.h"
|
||||
#include "session_transition.h"
|
||||
#include "evicted_session_filter.h"
|
||||
#include "duplicated_packet_filter.h"
|
||||
|
||||
#define SESSION_LOG_ERROR(format, ...) LOG_ERROR("session", format, ##__VA_ARGS__)
|
||||
@@ -31,7 +31,7 @@ struct session_manager
|
||||
struct session_table *udp_sess_table;
|
||||
|
||||
struct duplicated_packet_filter *dup_pkt_filter;
|
||||
struct evicted_session_filter *evicte_sess_filter;
|
||||
struct session_filter *evicte_sess_filter;
|
||||
|
||||
struct session_manager_stat stat;
|
||||
struct session_manager_options opts;
|
||||
@@ -479,7 +479,7 @@ static int udp_overload_bypass(struct session_manager *mgr, const struct tuple6
|
||||
|
||||
static int evicted_session_bypass(struct session_manager *mgr, const struct tuple6 *key)
|
||||
{
|
||||
if (mgr->opts.evicted_session_filter_enable && evicted_session_filter_lookup(mgr->evicte_sess_filter, key, mgr->now_ms))
|
||||
if (mgr->opts.evicted_session_filter_enable && session_filter_lookup(mgr->evicte_sess_filter, key, mgr->now_ms))
|
||||
{
|
||||
mgr->stat.udp_pkts_evctd_bypass++;
|
||||
return 1;
|
||||
@@ -639,7 +639,7 @@ static void session_manager_evicte_session(struct session_manager *mgr, struct s
|
||||
session_table_del(mgr->udp_sess_table, sess);
|
||||
if (mgr->opts.evicted_session_filter_enable)
|
||||
{
|
||||
evicted_session_filter_add(mgr->evicte_sess_filter, session_get_tuple6(sess), mgr->now_ms);
|
||||
session_filter_add(mgr->evicte_sess_filter, session_get_tuple6(sess), mgr->now_ms);
|
||||
}
|
||||
SESS_MGR_STAT_UPDATE(&mgr->stat, curr_state, next_state, udp);
|
||||
mgr->stat.udp_sess_evicted++;
|
||||
@@ -908,7 +908,7 @@ struct session_manager *session_manager_new(struct session_manager_options *opts
|
||||
}
|
||||
if (mgr->opts.evicted_session_filter_enable)
|
||||
{
|
||||
mgr->evicte_sess_filter = evicted_session_filter_new(mgr->opts.evicted_session_filter_capacity,
|
||||
mgr->evicte_sess_filter = session_filter_new(mgr->opts.evicted_session_filter_capacity,
|
||||
mgr->opts.evicted_session_filter_timeout,
|
||||
mgr->opts.evicted_session_filter_error_rate, now_ms);
|
||||
if (mgr->evicte_sess_filter == NULL)
|
||||
@@ -962,7 +962,7 @@ void session_manager_free(struct session_manager *mgr)
|
||||
}
|
||||
if (mgr->opts.evicted_session_filter_enable)
|
||||
{
|
||||
evicted_session_filter_free(mgr->evicte_sess_filter);
|
||||
session_filter_free(mgr->evicte_sess_filter);
|
||||
}
|
||||
if (mgr->opts.duplicated_packet_filter_enable)
|
||||
{
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include "tuple.h"
|
||||
#include "evicted_session_filter.h"
|
||||
#include "session_filter.h"
|
||||
|
||||
TEST(EVICTED_SESSION_FILTER, TEST)
|
||||
TEST(SESSION_FILTER, TEST)
|
||||
{
|
||||
struct tuple6 c2s_key;
|
||||
struct tuple6 s2c_key;
|
||||
@@ -30,20 +30,20 @@ TEST(EVICTED_SESSION_FILTER, TEST)
|
||||
s2c_key.ip_proto = 0x05;
|
||||
s2c_key.domain = 0x0606060606060606;
|
||||
|
||||
struct evicted_session_filter *filter = evicted_session_filter_new(capacity, timeout, error_rate, 1);
|
||||
struct session_filter *filter = session_filter_new(capacity, timeout, error_rate, 1);
|
||||
EXPECT_TRUE(filter != nullptr);
|
||||
|
||||
EXPECT_TRUE(evicted_session_filter_lookup(filter, &c2s_key, 1) == 0); // no found
|
||||
EXPECT_TRUE(evicted_session_filter_lookup(filter, &s2c_key, 1) == 0); // no found
|
||||
evicted_session_filter_add(filter, &c2s_key, 1); // add
|
||||
EXPECT_TRUE(evicted_session_filter_lookup(filter, &c2s_key, 1) == 1); // found
|
||||
EXPECT_TRUE(evicted_session_filter_lookup(filter, &s2c_key, 1) == 1); // found
|
||||
EXPECT_TRUE(evicted_session_filter_lookup(filter, &c2s_key, 2) == 1); // found
|
||||
EXPECT_TRUE(evicted_session_filter_lookup(filter, &s2c_key, 2) == 1); // found
|
||||
EXPECT_TRUE(evicted_session_filter_lookup(filter, &c2s_key, 3) == 0); // not found
|
||||
EXPECT_TRUE(evicted_session_filter_lookup(filter, &s2c_key, 3) == 0); // not found
|
||||
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
|
||||
|
||||
evicted_session_filter_free(filter);
|
||||
session_filter_free(filter);
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
Reference in New Issue
Block a user