mirror of
https://github.com/pavel-odintsov/fastnetmon
synced 2024-06-06 14:46:30 +02:00
Add support for looking up IPv6 addresses for patricia + tests
This commit is contained in:
parent
1553b9785c
commit
3316373184
|
@ -15,6 +15,8 @@
|
|||
#include "log4cpp/PatternLayout.hh"
|
||||
#include "log4cpp/Priority.hh"
|
||||
|
||||
#include <arpa/inet.h>
|
||||
|
||||
log4cpp::Category& logger = log4cpp::Category::getRoot();
|
||||
|
||||
TEST(BgpFlowSpec, protocol_check_udp) {
|
||||
|
@ -372,3 +374,45 @@ TEST(serialize_vector_by_string_with_prefix, few_elements) {
|
|||
EXPECT_EQ( serialize_vector_by_string_with_prefix(vect, ",", "^"), "^123,^456");
|
||||
}
|
||||
|
||||
/* Patricia tests */
|
||||
|
||||
TEST (patricia, negative_lookup_ipv6_prefix) {
|
||||
patricia_tree_t* lookup_ipv6_tree;
|
||||
lookup_ipv6_tree = New_Patricia(128);
|
||||
|
||||
make_and_lookup_ipv6(lookup_ipv6_tree, (char*)"2a03:f480::/32");
|
||||
|
||||
//Destroy_Patricia(lookup_ipv6_tree, (void_fn_t)0);
|
||||
|
||||
prefix_t prefix_for_check_address;
|
||||
|
||||
// Convert fb.com frontend address to internal structure
|
||||
inet_pton(AF_INET6, "2a03:2880:2130:cf05:face:b00c::1", (void*)&prefix_for_check_address.add.sin6);
|
||||
|
||||
prefix_for_check_address.family = AF_INET6;
|
||||
prefix_for_check_address.bitlen = 128;
|
||||
|
||||
bool found = patricia_search_best2(lookup_ipv6_tree, &prefix_for_check_address, 1) != NULL;
|
||||
|
||||
EXPECT_EQ( found, false );
|
||||
}
|
||||
|
||||
TEST (patricia, positive_lookup_ipv6_prefix) {
|
||||
patricia_tree_t* lookup_ipv6_tree;
|
||||
lookup_ipv6_tree = New_Patricia(128);
|
||||
|
||||
make_and_lookup_ipv6(lookup_ipv6_tree, (char*)"2a03:f480::/32");
|
||||
|
||||
//Destroy_Patricia(lookup_ipv6_tree, (void_fn_t)0);
|
||||
|
||||
prefix_t prefix_for_check_address;
|
||||
|
||||
inet_pton(AF_INET6, "2a03:f480:2130:cf05:face:b00c::1", (void*)&prefix_for_check_address.add.sin6);
|
||||
|
||||
prefix_for_check_address.family = AF_INET6;
|
||||
prefix_for_check_address.bitlen = 128;
|
||||
|
||||
bool found = patricia_search_best2(lookup_ipv6_tree, &prefix_for_check_address, 1) != NULL;
|
||||
|
||||
EXPECT_EQ( found, true );
|
||||
}
|
||||
|
|
|
@ -955,6 +955,19 @@ make_and_lookup (patricia_tree_t *tree, char *string)
|
|||
return (node);
|
||||
}
|
||||
|
||||
patricia_node_t *
|
||||
make_and_lookup_ipv6 (patricia_tree_t *tree, char *string)
|
||||
{
|
||||
prefix_t *prefix;
|
||||
patricia_node_t *node;
|
||||
|
||||
prefix = ascii2prefix (AF_INET6, string);
|
||||
// printf ("make_and_lookup: %s/%d\n", prefix_toa (prefix), prefix->bitlen);
|
||||
node = patricia_lookup (tree, prefix);
|
||||
Deref_Prefix (prefix);
|
||||
return (node);
|
||||
}
|
||||
|
||||
patricia_node_t *
|
||||
try_search_exact (patricia_tree_t *tree, char *string)
|
||||
{
|
||||
|
|
|
@ -104,6 +104,9 @@ ascii2prefix (int family, char *string);
|
|||
patricia_node_t *
|
||||
make_and_lookup (patricia_tree_t *tree, char *string);
|
||||
|
||||
patricia_node_t *
|
||||
make_and_lookup_ipv6 (patricia_tree_t *tree, char *string);
|
||||
|
||||
/* } */
|
||||
|
||||
#define PATRICIA_MAXBITS (sizeof(struct in6_addr) * 8)
|
||||
|
|
Loading…
Reference in New Issue