Add dablooms
This commit is contained in:
71
src/dablooms/test/gtest_dablooms.cpp
Normal file
71
src/dablooms/test/gtest_dablooms.cpp
Normal file
@@ -0,0 +1,71 @@
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include "dablooms.h"
|
||||
|
||||
struct packet_key
|
||||
{
|
||||
unsigned int tcp_seq;
|
||||
unsigned int tcp_ack;
|
||||
unsigned short sport;
|
||||
unsigned short dport;
|
||||
unsigned short checksum;
|
||||
unsigned short ip_id;
|
||||
unsigned int ip_src;
|
||||
unsigned int ip_dst;
|
||||
} __attribute__((packed, aligned(1)));
|
||||
|
||||
struct duplicate_packet_idetify_config
|
||||
{
|
||||
int enable;
|
||||
|
||||
unsigned int capacity;
|
||||
double error_rate;
|
||||
int expiry_time;
|
||||
} config = {
|
||||
.enable = 1,
|
||||
.capacity = 1000000,
|
||||
.error_rate = 0.00001,
|
||||
.expiry_time = 10,
|
||||
};
|
||||
|
||||
struct packet_key key = {
|
||||
.tcp_seq = 2172673142,
|
||||
.tcp_ack = 2198097831,
|
||||
.sport = 46582,
|
||||
.dport = 443,
|
||||
.checksum = 0x2c4b,
|
||||
.ip_id = 65535,
|
||||
.ip_src = 123456,
|
||||
.ip_dst = 789000,
|
||||
};
|
||||
|
||||
TEST(DABLOOMS, ADD_SEARCH)
|
||||
{
|
||||
struct expiry_dablooms_handle *handle = expiry_dablooms_init(config.capacity, config.error_rate, time(NULL), config.expiry_time);
|
||||
EXPECT_TRUE(handle != nullptr);
|
||||
|
||||
EXPECT_TRUE(expiry_dablooms_search(handle, (const char *)&key, sizeof(key), time(NULL)) != 1); // no exist
|
||||
EXPECT_TRUE(expiry_dablooms_add(handle, (const char *)&key, sizeof(key), time(NULL)) == 0); // add
|
||||
|
||||
for (int i = 0; i < 15; i++)
|
||||
{
|
||||
if (i < config.expiry_time)
|
||||
{
|
||||
EXPECT_TRUE(expiry_dablooms_search(handle, (const char *)&key, sizeof(key), time(NULL)) == 1); // exist
|
||||
}
|
||||
else
|
||||
{
|
||||
EXPECT_TRUE(expiry_dablooms_search(handle, (const char *)&key, sizeof(key), time(NULL)) != 1); // no exist
|
||||
}
|
||||
sleep(1);
|
||||
printf("sleep[%02d] 1s\n", i);
|
||||
}
|
||||
|
||||
expiry_dablooms_destroy(handle);
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
::testing::InitGoogleTest(&argc, argv);
|
||||
return RUN_ALL_TESTS();
|
||||
}
|
||||
Reference in New Issue
Block a user