rename session_filter to session_dabloom
This commit is contained in:
60
infra/session_manager/session_dabloom.c
Normal file
60
infra/session_manager/session_dabloom.c
Normal file
@@ -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);
|
||||
}
|
||||
18
infra/session_manager/session_dabloom.h
Normal file
18
infra/session_manager/session_dabloom.h
Normal file
@@ -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
|
||||
@@ -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);
|
||||
}
|
||||
@@ -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
|
||||
@@ -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)
|
||||
|
||||
@@ -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
|
||||
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_filter_free(filter);
|
||||
session_dabloom_free(filter);
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
@@ -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"
|
||||
|
||||
Reference in New Issue
Block a user