rename packet_filter to packet_dabloom
This commit is contained in:
@@ -3,7 +3,7 @@ add_library(packet_manager
|
|||||||
packet_pool.c
|
packet_pool.c
|
||||||
packet_parser.c
|
packet_parser.c
|
||||||
packet_builder.c
|
packet_builder.c
|
||||||
packet_filter.c
|
packet_dabloom.c
|
||||||
packet_dump.c
|
packet_dump.c
|
||||||
packet_utils.c
|
packet_utils.c
|
||||||
checksum.c)
|
checksum.c)
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
#include "dablooms.h"
|
#include "dablooms.h"
|
||||||
#include "packet_filter.h"
|
#include "packet_dabloom.h"
|
||||||
#include "packet_internal.h"
|
#include "packet_internal.h"
|
||||||
|
|
||||||
struct packet_key
|
struct packet_key
|
||||||
@@ -17,7 +17,7 @@ struct packet_key
|
|||||||
uint32_t dst_addr; // network order
|
uint32_t dst_addr; // network order
|
||||||
} __attribute__((__packed__));
|
} __attribute__((__packed__));
|
||||||
|
|
||||||
struct packet_filter
|
struct packet_dabloom
|
||||||
{
|
{
|
||||||
struct expiry_dablooms_handle *dablooms;
|
struct expiry_dablooms_handle *dablooms;
|
||||||
};
|
};
|
||||||
@@ -69,41 +69,41 @@ static inline int packet_key_get(const struct packet *packet, struct packet_key
|
|||||||
* Public API
|
* Public API
|
||||||
******************************************************************************/
|
******************************************************************************/
|
||||||
|
|
||||||
struct packet_filter *packet_filter_new(uint32_t capacity, uint32_t timeout, double error_rate, uint64_t now)
|
struct packet_dabloom *packet_dabloom_new(uint32_t capacity, uint32_t timeout, double error_rate, uint64_t now)
|
||||||
{
|
{
|
||||||
struct packet_filter *filter = (struct packet_filter *)calloc(1, sizeof(struct packet_filter));
|
struct packet_dabloom *pkt_dab = (struct packet_dabloom *)calloc(1, sizeof(struct packet_dabloom));
|
||||||
if (filter == NULL)
|
if (pkt_dab == NULL)
|
||||||
{
|
{
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
filter->dablooms = expiry_dablooms_new(capacity, error_rate, now, timeout);
|
pkt_dab->dablooms = expiry_dablooms_new(capacity, error_rate, now, timeout);
|
||||||
if (filter->dablooms == NULL)
|
if (pkt_dab->dablooms == NULL)
|
||||||
{
|
{
|
||||||
free(filter);
|
free(pkt_dab);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
return filter;
|
return pkt_dab;
|
||||||
}
|
}
|
||||||
|
|
||||||
void packet_filter_free(struct packet_filter *filter)
|
void packet_dabloom_free(struct packet_dabloom *pkt_dab)
|
||||||
{
|
{
|
||||||
if (filter)
|
if (pkt_dab)
|
||||||
{
|
{
|
||||||
if (filter->dablooms)
|
if (pkt_dab->dablooms)
|
||||||
{
|
{
|
||||||
expiry_dablooms_free(filter->dablooms);
|
expiry_dablooms_free(pkt_dab->dablooms);
|
||||||
filter->dablooms = NULL;
|
pkt_dab->dablooms = NULL;
|
||||||
}
|
}
|
||||||
free(filter);
|
free(pkt_dab);
|
||||||
filter = NULL;
|
pkt_dab = NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// return 1: found
|
// return 1: found
|
||||||
// reutrn 0: no found
|
// reutrn 0: no found
|
||||||
int packet_filter_lookup(struct packet_filter *filter, const struct packet *packet, uint64_t now)
|
int packet_dabloom_lookup(struct packet_dabloom *pkt_dab, const struct packet *packet, uint64_t now)
|
||||||
{
|
{
|
||||||
struct packet_key key;
|
struct packet_key key;
|
||||||
if (packet_key_get(packet, &key) == -1)
|
if (packet_key_get(packet, &key) == -1)
|
||||||
@@ -111,7 +111,7 @@ int packet_filter_lookup(struct packet_filter *filter, const struct packet *pack
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (expiry_dablooms_search(filter->dablooms, (const char *)&key, sizeof(struct packet_key), now) == 1)
|
if (expiry_dablooms_search(pkt_dab->dablooms, (const char *)&key, sizeof(struct packet_key), now) == 1)
|
||||||
{
|
{
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
@@ -119,7 +119,7 @@ int packet_filter_lookup(struct packet_filter *filter, const struct packet *pack
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void packet_filter_add(struct packet_filter *filter, const struct packet *packet, uint64_t now)
|
void packet_dabloom_add(struct packet_dabloom *pkt_dab, const struct packet *packet, uint64_t now)
|
||||||
{
|
{
|
||||||
struct packet_key key;
|
struct packet_key key;
|
||||||
if (packet_key_get(packet, &key) == -1)
|
if (packet_key_get(packet, &key) == -1)
|
||||||
@@ -127,5 +127,5 @@ void packet_filter_add(struct packet_filter *filter, const struct packet *packet
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
expiry_dablooms_add(filter->dablooms, (const char *)&key, sizeof(struct packet_key), now);
|
expiry_dablooms_add(pkt_dab->dablooms, (const char *)&key, sizeof(struct packet_key), now);
|
||||||
}
|
}
|
||||||
22
infra/packet_manager/packet_dabloom.h
Normal file
22
infra/packet_manager/packet_dabloom.h
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C"
|
||||||
|
{
|
||||||
|
#endif
|
||||||
|
|
||||||
|
struct packet;
|
||||||
|
|
||||||
|
// Duplicated Packet Filter for IPv4 Packet
|
||||||
|
struct packet_dabloom;
|
||||||
|
struct packet_dabloom *packet_dabloom_new(uint32_t capacity, uint32_t timeout, double error_rate, uint64_t now);
|
||||||
|
void packet_dabloom_free(struct packet_dabloom *pkt_dab);
|
||||||
|
|
||||||
|
// return 1: found
|
||||||
|
// reutrn 0: no found
|
||||||
|
int packet_dabloom_lookup(struct packet_dabloom *pkt_dab, const struct packet *pkt, uint64_t now);
|
||||||
|
void packet_dabloom_add(struct packet_dabloom *pkt_dab, const struct packet *pkt, uint64_t now);
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
@@ -1,22 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
extern "C"
|
|
||||||
{
|
|
||||||
#endif
|
|
||||||
|
|
||||||
struct packet;
|
|
||||||
|
|
||||||
// Duplicated Packet Filter for IPv4 Packet
|
|
||||||
struct packet_filter;
|
|
||||||
struct packet_filter *packet_filter_new(uint32_t capacity, uint32_t timeout, double error_rate, uint64_t now);
|
|
||||||
void packet_filter_free(struct packet_filter *filter);
|
|
||||||
|
|
||||||
// return 1: found
|
|
||||||
// reutrn 0: no found
|
|
||||||
int packet_filter_lookup(struct packet_filter *filter, const struct packet *pkt, uint64_t now);
|
|
||||||
void packet_filter_add(struct packet_filter *filter, const struct packet *pkt, uint64_t now);
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
@@ -49,8 +49,8 @@ target_link_libraries(gtest_packet_parser packet_manager gtest)
|
|||||||
add_executable(gtest_packet_builder gtest_packet_builder.cpp)
|
add_executable(gtest_packet_builder gtest_packet_builder.cpp)
|
||||||
target_link_libraries(gtest_packet_builder packet_manager gtest)
|
target_link_libraries(gtest_packet_builder packet_manager gtest)
|
||||||
|
|
||||||
add_executable(gtest_packet_filter gtest_packet_filter.cpp)
|
add_executable(gtest_packet_dabloom gtest_packet_dabloom.cpp)
|
||||||
target_link_libraries(gtest_packet_filter packet_manager gtest)
|
target_link_libraries(gtest_packet_dabloom packet_manager gtest)
|
||||||
|
|
||||||
add_executable(gtest_packet_ldbc gtest_packet_ldbc.cpp)
|
add_executable(gtest_packet_ldbc gtest_packet_ldbc.cpp)
|
||||||
target_link_libraries(gtest_packet_ldbc packet_manager gtest)
|
target_link_libraries(gtest_packet_ldbc packet_manager gtest)
|
||||||
@@ -79,7 +79,7 @@ gtest_discover_tests(gtest_gtp2_utils)
|
|||||||
gtest_discover_tests(gtest_packet_frag)
|
gtest_discover_tests(gtest_packet_frag)
|
||||||
gtest_discover_tests(gtest_packet_parser)
|
gtest_discover_tests(gtest_packet_parser)
|
||||||
gtest_discover_tests(gtest_packet_builder)
|
gtest_discover_tests(gtest_packet_builder)
|
||||||
gtest_discover_tests(gtest_packet_filter)
|
gtest_discover_tests(gtest_packet_dabloom)
|
||||||
gtest_discover_tests(gtest_packet_ldbc)
|
gtest_discover_tests(gtest_packet_ldbc)
|
||||||
gtest_discover_tests(gtest_packet_pool)
|
gtest_discover_tests(gtest_packet_pool)
|
||||||
gtest_discover_tests(gtest_packet_manager)
|
gtest_discover_tests(gtest_packet_manager)
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
#include "tuple.h"
|
#include "tuple.h"
|
||||||
#include "packet_internal.h"
|
#include "packet_internal.h"
|
||||||
#include "packet_parser.h"
|
#include "packet_parser.h"
|
||||||
#include "packet_filter.h"
|
#include "packet_dabloom.h"
|
||||||
|
|
||||||
/******************************************************************************
|
/******************************************************************************
|
||||||
* [Protocols in frame: eth:ethertype:ip:ipv6:tcp]
|
* [Protocols in frame: eth:ethertype:ip:ipv6:tcp]
|
||||||
@@ -67,7 +67,7 @@ unsigned char data[] = {
|
|||||||
0x81, 0x80, 0x5c, 0x76, 0x00, 0x00, 0x00, 0x00, 0x80, 0x02, 0x20, 0x00, 0xf7, 0x57, 0x00, 0x00, 0x02, 0x04, 0x04, 0xc4, 0x01, 0x03, 0x03, 0x08, 0x01, 0x01,
|
0x81, 0x80, 0x5c, 0x76, 0x00, 0x00, 0x00, 0x00, 0x80, 0x02, 0x20, 0x00, 0xf7, 0x57, 0x00, 0x00, 0x02, 0x04, 0x04, 0xc4, 0x01, 0x03, 0x03, 0x08, 0x01, 0x01,
|
||||||
0x04, 0x02};
|
0x04, 0x02};
|
||||||
|
|
||||||
TEST(DUPLICATED_PACKET_FILTER, TEST)
|
TEST(PACKET_DABLOOM, TEST)
|
||||||
{
|
{
|
||||||
struct packet pkt;
|
struct packet pkt;
|
||||||
uint32_t capacity = 1000000;
|
uint32_t capacity = 1000000;
|
||||||
@@ -77,17 +77,17 @@ TEST(DUPLICATED_PACKET_FILTER, TEST)
|
|||||||
memset(&pkt, 0, sizeof(pkt));
|
memset(&pkt, 0, sizeof(pkt));
|
||||||
packet_parse(&pkt, (const char *)data, sizeof(data));
|
packet_parse(&pkt, (const char *)data, sizeof(data));
|
||||||
|
|
||||||
struct packet_filter *filter = packet_filter_new(capacity, timeout, error_rate, 1);
|
struct packet_dabloom *filter = packet_dabloom_new(capacity, timeout, error_rate, 1);
|
||||||
EXPECT_TRUE(filter != nullptr);
|
EXPECT_TRUE(filter != nullptr);
|
||||||
|
|
||||||
EXPECT_TRUE(packet_filter_lookup(filter, &pkt, 1) == 0); // no found
|
EXPECT_TRUE(packet_dabloom_lookup(filter, &pkt, 1) == 0); // no found
|
||||||
packet_filter_add(filter, &pkt, 1); // add
|
packet_dabloom_add(filter, &pkt, 1); // add
|
||||||
EXPECT_TRUE(packet_filter_lookup(filter, &pkt, 1) == 1); // found
|
EXPECT_TRUE(packet_dabloom_lookup(filter, &pkt, 1) == 1); // found
|
||||||
EXPECT_TRUE(packet_filter_lookup(filter, &pkt, 2) == 1); // found
|
EXPECT_TRUE(packet_dabloom_lookup(filter, &pkt, 2) == 1); // found
|
||||||
EXPECT_TRUE(packet_filter_lookup(filter, &pkt, 3) == 0); // not found
|
EXPECT_TRUE(packet_dabloom_lookup(filter, &pkt, 3) == 0); // not found
|
||||||
EXPECT_TRUE(packet_filter_lookup(filter, &pkt, 4) == 0); // not found
|
EXPECT_TRUE(packet_dabloom_lookup(filter, &pkt, 4) == 0); // not found
|
||||||
|
|
||||||
packet_filter_free(filter);
|
packet_dabloom_free(filter);
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, char **argv)
|
int main(int argc, char **argv)
|
||||||
Reference in New Issue
Block a user