Optimize packet I/O and timeouts
- Introduce per-thread I/O statistics for packet I/O to reduce performance overhead. - Implement packet_io_yield() for better thread management during I/O operations. - Refactor time wheel management: - Replace timeouts-based cron tasks with (now_ts - last_ts > timeout) for scheduled tasks. - Update the time wheel every 5 ms for improved time management.
This commit is contained in:
@@ -11,5 +11,4 @@ add_subdirectory(duplicated_packet_filter)
|
||||
add_subdirectory(evicted_session_filter)
|
||||
add_subdirectory(session)
|
||||
add_subdirectory(plugin)
|
||||
add_subdirectory(config)
|
||||
add_subdirectory(stellar)
|
||||
@@ -1,3 +0,0 @@
|
||||
add_library(config config.cpp)
|
||||
target_include_directories(config PUBLIC ${CMAKE_CURRENT_LIST_DIR})
|
||||
target_link_libraries(config toml packet_io ip_reassembly session_manager)
|
||||
@@ -832,7 +832,7 @@ void ip_reassembly_expire(struct ip_reassembly *assy, uint64_t now)
|
||||
}
|
||||
}
|
||||
|
||||
struct ip_reassembly_stat *ip_reassembly_get_stat(struct ip_reassembly *assy)
|
||||
struct ip_reassembly_stat *ip_reassembly_stat(struct ip_reassembly *assy)
|
||||
{
|
||||
if (assy)
|
||||
{
|
||||
|
||||
@@ -52,7 +52,7 @@ struct ip_reassembly_stat
|
||||
struct ip_reassembly *ip_reassembly_new(const struct ip_reassembly_options *opts);
|
||||
void ip_reassembly_free(struct ip_reassembly *assy);
|
||||
void ip_reassembly_expire(struct ip_reassembly *assy, uint64_t now);
|
||||
struct ip_reassembly_stat *ip_reassembly_get_stat(struct ip_reassembly *assy);
|
||||
struct ip_reassembly_stat *ip_reassembly_stat(struct ip_reassembly *assy);
|
||||
|
||||
/*
|
||||
* Returns the reassembled packet, or NULL if the packet is not reassembled
|
||||
|
||||
@@ -208,7 +208,7 @@ TEST(IPV4_REASSEMBLE, PADDING_ORDER)
|
||||
assy = ip_reassembly_new(&opts);
|
||||
EXPECT_TRUE(assy != NULL);
|
||||
|
||||
check_stat(ip_reassembly_get_stat(assy),
|
||||
check_stat(ip_reassembly_stat(assy),
|
||||
0, 0, 0, 0, // ip4: find, add, del, timeout
|
||||
0, 0, 0, 0, 0, 0, // ip4: nospace, overlap, many frag, invalid length, dup first frag, dup last frag
|
||||
0, 0, 0, 0, // ip6: find, add, del, timeout
|
||||
@@ -219,7 +219,7 @@ TEST(IPV4_REASSEMBLE, PADDING_ORDER)
|
||||
new_pkt = ip_reassembly_packet(assy, &pkt, 1);
|
||||
EXPECT_TRUE(new_pkt == NULL);
|
||||
|
||||
check_stat(ip_reassembly_get_stat(assy),
|
||||
check_stat(ip_reassembly_stat(assy),
|
||||
1, 1, 0, 0, // ip4: find, add, del, timeout
|
||||
0, 0, 0, 0, 0, 0, // ip4: nospace, overlap, many frag, invalid length, dup first frag, dup last frag
|
||||
0, 0, 0, 0, // ip6: find, add, del, timeout
|
||||
@@ -230,7 +230,7 @@ TEST(IPV4_REASSEMBLE, PADDING_ORDER)
|
||||
new_pkt = ip_reassembly_packet(assy, &pkt, 1);
|
||||
EXPECT_TRUE(new_pkt);
|
||||
|
||||
check_stat(ip_reassembly_get_stat(assy),
|
||||
check_stat(ip_reassembly_stat(assy),
|
||||
2, 1, 1, 0, // ip4: find, add, del, timeout
|
||||
0, 0, 0, 0, 0, 0, // ip4: nospace, overlap, many frag, invalid length, dup first frag, dup last frag
|
||||
0, 0, 0, 0, // ip6: find, add, del, timeout
|
||||
@@ -301,7 +301,7 @@ TEST(IPV4_REASSEMBLE, PADDING_UNORDER)
|
||||
assy = ip_reassembly_new(&opts);
|
||||
EXPECT_TRUE(assy != NULL);
|
||||
|
||||
check_stat(ip_reassembly_get_stat(assy),
|
||||
check_stat(ip_reassembly_stat(assy),
|
||||
0, 0, 0, 0, // ip4: find, add, del, timeout
|
||||
0, 0, 0, 0, 0, 0, // ip4: nospace, overlap, many frag, invalid length, dup first frag, dup last frag
|
||||
0, 0, 0, 0, // ip6: find, add, del, timeout
|
||||
@@ -312,7 +312,7 @@ TEST(IPV4_REASSEMBLE, PADDING_UNORDER)
|
||||
new_pkt = ip_reassembly_packet(assy, &pkt, 1);
|
||||
EXPECT_TRUE(new_pkt == NULL);
|
||||
|
||||
check_stat(ip_reassembly_get_stat(assy),
|
||||
check_stat(ip_reassembly_stat(assy),
|
||||
1, 1, 0, 0, // ip4: find, add, del, timeout
|
||||
0, 0, 0, 0, 0, 0, // ip4: nospace, overlap, many frag, invalid length, dup first frag, dup last frag
|
||||
0, 0, 0, 0, // ip6: find, add, del, timeout
|
||||
@@ -323,7 +323,7 @@ TEST(IPV4_REASSEMBLE, PADDING_UNORDER)
|
||||
new_pkt = ip_reassembly_packet(assy, &pkt, 1);
|
||||
EXPECT_TRUE(new_pkt);
|
||||
|
||||
check_stat(ip_reassembly_get_stat(assy),
|
||||
check_stat(ip_reassembly_stat(assy),
|
||||
2, 1, 1, 0, // ip4: find, add, del, timeout
|
||||
0, 0, 0, 0, 0, 0, // ip4: nospace, overlap, many frag, invalid length, dup first frag, dup last frag
|
||||
0, 0, 0, 0, // ip6: find, add, del, timeout
|
||||
@@ -393,7 +393,7 @@ TEST(IPV4_REASSEMBLE, EXPIRE)
|
||||
assy = ip_reassembly_new(&opts);
|
||||
EXPECT_TRUE(assy != NULL);
|
||||
|
||||
check_stat(ip_reassembly_get_stat(assy),
|
||||
check_stat(ip_reassembly_stat(assy),
|
||||
0, 0, 0, 0, // ip4: find, add, del, timeout
|
||||
0, 0, 0, 0, 0, 0, // ip4: nospace, overlap, many frag, invalid length, dup first frag, dup last frag
|
||||
0, 0, 0, 0, // ip6: find, add, del, timeout
|
||||
@@ -404,7 +404,7 @@ TEST(IPV4_REASSEMBLE, EXPIRE)
|
||||
new_pkt = ip_reassembly_packet(assy, &pkt, 1);
|
||||
EXPECT_TRUE(new_pkt == NULL);
|
||||
|
||||
check_stat(ip_reassembly_get_stat(assy),
|
||||
check_stat(ip_reassembly_stat(assy),
|
||||
1, 1, 0, 0, // ip4: find, add, del, timeout
|
||||
0, 0, 0, 0, 0, 0, // ip4: nospace, overlap, many frag, invalid length, dup first frag, dup last frag
|
||||
0, 0, 0, 0, // ip6: find, add, del, timeout
|
||||
@@ -415,7 +415,7 @@ TEST(IPV4_REASSEMBLE, EXPIRE)
|
||||
new_pkt = ip_reassembly_packet(assy, &pkt, 2);
|
||||
EXPECT_TRUE(new_pkt == NULL);
|
||||
|
||||
check_stat(ip_reassembly_get_stat(assy),
|
||||
check_stat(ip_reassembly_stat(assy),
|
||||
2, 2, 1, 1, // ip4: find, add, del, timeout
|
||||
0, 0, 0, 0, 0, 0, // ip4: nospace, overlap, many frag, invalid length, dup first frag, dup last frag
|
||||
0, 0, 0, 0, // ip6: find, add, del, timeout
|
||||
@@ -445,7 +445,7 @@ TEST(IPV4_REASSEMBLE, DUP_FIRST_FRAG)
|
||||
assy = ip_reassembly_new(&opts);
|
||||
EXPECT_TRUE(assy != NULL);
|
||||
|
||||
check_stat(ip_reassembly_get_stat(assy),
|
||||
check_stat(ip_reassembly_stat(assy),
|
||||
0, 0, 0, 0, // ip4: find, add, del, timeout
|
||||
0, 0, 0, 0, 0, 0, // ip4: nospace, overlap, many frag, invalid length, dup first frag, dup last frag
|
||||
0, 0, 0, 0, // ip6: find, add, del, timeout
|
||||
@@ -456,7 +456,7 @@ TEST(IPV4_REASSEMBLE, DUP_FIRST_FRAG)
|
||||
new_pkt = ip_reassembly_packet(assy, &pkt, 1);
|
||||
EXPECT_TRUE(new_pkt == NULL);
|
||||
|
||||
check_stat(ip_reassembly_get_stat(assy),
|
||||
check_stat(ip_reassembly_stat(assy),
|
||||
1, 1, 0, 0, // ip4: find, add, del, timeout
|
||||
0, 0, 0, 0, 0, 0, // ip4: nospace, overlap, many frag, invalid length, dup first frag, dup last frag
|
||||
0, 0, 0, 0, // ip6: find, add, del, timeout
|
||||
@@ -467,7 +467,7 @@ TEST(IPV4_REASSEMBLE, DUP_FIRST_FRAG)
|
||||
new_pkt = ip_reassembly_packet(assy, &pkt, 1);
|
||||
EXPECT_TRUE(new_pkt == NULL);
|
||||
|
||||
check_stat(ip_reassembly_get_stat(assy),
|
||||
check_stat(ip_reassembly_stat(assy),
|
||||
2, 1, 0, 0, // ip4: find, add, del, timeout
|
||||
0, 0, 0, 0, 1, 0, // ip4: nospace, overlap, many frag, invalid length, dup first frag, dup last frag
|
||||
0, 0, 0, 0, // ip6: find, add, del, timeout
|
||||
@@ -478,7 +478,7 @@ TEST(IPV4_REASSEMBLE, DUP_FIRST_FRAG)
|
||||
new_pkt = ip_reassembly_packet(assy, &pkt, 1);
|
||||
EXPECT_TRUE(new_pkt);
|
||||
|
||||
check_stat(ip_reassembly_get_stat(assy),
|
||||
check_stat(ip_reassembly_stat(assy),
|
||||
3, 1, 1, 0, // ip4: find, add, del, timeout
|
||||
0, 0, 0, 0, 1, 0, // ip4: nospace, overlap, many frag, invalid length, dup first frag, dup last frag
|
||||
0, 0, 0, 0, // ip6: find, add, del, timeout
|
||||
@@ -549,7 +549,7 @@ TEST(IPV4_REASSEMBLE, DUP_LAST_FRAG)
|
||||
assy = ip_reassembly_new(&opts);
|
||||
EXPECT_TRUE(assy != NULL);
|
||||
|
||||
check_stat(ip_reassembly_get_stat(assy),
|
||||
check_stat(ip_reassembly_stat(assy),
|
||||
0, 0, 0, 0, // ip4: find, add, del, timeout
|
||||
0, 0, 0, 0, 0, 0, // ip4: nospace, overlap, many frag, invalid length, dup first frag, dup last frag
|
||||
0, 0, 0, 0, // ip6: find, add, del, timeout
|
||||
@@ -560,7 +560,7 @@ TEST(IPV4_REASSEMBLE, DUP_LAST_FRAG)
|
||||
new_pkt = ip_reassembly_packet(assy, &pkt, 1);
|
||||
EXPECT_TRUE(new_pkt == NULL);
|
||||
|
||||
check_stat(ip_reassembly_get_stat(assy),
|
||||
check_stat(ip_reassembly_stat(assy),
|
||||
1, 1, 0, 0, // ip4: find, add, del, timeout
|
||||
0, 0, 0, 0, 0, 0, // ip4: nospace, overlap, many frag, invalid length, dup first frag, dup last frag
|
||||
0, 0, 0, 0, // ip6: find, add, del, timeout
|
||||
@@ -571,7 +571,7 @@ TEST(IPV4_REASSEMBLE, DUP_LAST_FRAG)
|
||||
new_pkt = ip_reassembly_packet(assy, &pkt, 1);
|
||||
EXPECT_TRUE(new_pkt == NULL);
|
||||
|
||||
check_stat(ip_reassembly_get_stat(assy),
|
||||
check_stat(ip_reassembly_stat(assy),
|
||||
2, 1, 0, 0, // ip4: find, add, del, timeout
|
||||
0, 0, 0, 0, 0, 1, // ip4: nospace, overlap, many frag, invalid length, dup first frag, dup last frag
|
||||
0, 0, 0, 0, // ip6: find, add, del, timeout
|
||||
@@ -582,7 +582,7 @@ TEST(IPV4_REASSEMBLE, DUP_LAST_FRAG)
|
||||
new_pkt = ip_reassembly_packet(assy, &pkt, 1);
|
||||
EXPECT_TRUE(new_pkt);
|
||||
|
||||
check_stat(ip_reassembly_get_stat(assy),
|
||||
check_stat(ip_reassembly_stat(assy),
|
||||
3, 1, 1, 0, // ip4: find, add, del, timeout
|
||||
0, 0, 0, 0, 0, 1, // ip4: nospace, overlap, many frag, invalid length, dup first frag, dup last frag
|
||||
0, 0, 0, 0, // ip6: find, add, del, timeout
|
||||
@@ -652,7 +652,7 @@ TEST(IPV4_REASSEMBLE, FULL)
|
||||
assy = ip_reassembly_new(&opts);
|
||||
EXPECT_TRUE(assy != NULL);
|
||||
|
||||
check_stat(ip_reassembly_get_stat(assy),
|
||||
check_stat(ip_reassembly_stat(assy),
|
||||
0, 0, 0, 0, // ip4: find, add, del, timeout
|
||||
0, 0, 0, 0, 0, 0, // ip4: nospace, overlap, many frag, invalid length, dup first frag, dup last frag
|
||||
0, 0, 0, 0, // ip6: find, add, del, timeout
|
||||
@@ -667,7 +667,7 @@ TEST(IPV4_REASSEMBLE, FULL)
|
||||
new_pkt = ip_reassembly_packet(assy, &pkt, 1);
|
||||
EXPECT_TRUE(new_pkt == NULL);
|
||||
|
||||
check_stat(ip_reassembly_get_stat(assy),
|
||||
check_stat(ip_reassembly_stat(assy),
|
||||
1, 1, 0, 0, // ip4: find, add, del, timeout
|
||||
0, 0, 0, 0, 0, 0, // ip4: nospace, overlap, many frag, invalid length, dup first frag, dup last frag
|
||||
0, 0, 0, 0, // ip6: find, add, del, timeout
|
||||
@@ -678,7 +678,7 @@ TEST(IPV4_REASSEMBLE, FULL)
|
||||
new_pkt = ip_reassembly_packet(assy, &pkt, 1);
|
||||
EXPECT_TRUE(new_pkt == NULL);
|
||||
|
||||
check_stat(ip_reassembly_get_stat(assy),
|
||||
check_stat(ip_reassembly_stat(assy),
|
||||
2, 2, 0, 0, // ip4: find, add, del, timeout
|
||||
0, 0, 0, 0, 0, 0, // ip4: nospace, overlap, many frag, invalid length, dup first frag, dup last frag
|
||||
0, 0, 0, 0, // ip6: find, add, del, timeout
|
||||
@@ -689,7 +689,7 @@ TEST(IPV4_REASSEMBLE, FULL)
|
||||
new_pkt = ip_reassembly_packet(assy, &pkt, 1);
|
||||
EXPECT_TRUE(new_pkt == NULL);
|
||||
|
||||
check_stat(ip_reassembly_get_stat(assy),
|
||||
check_stat(ip_reassembly_stat(assy),
|
||||
3, 2, 0, 0, // ip4: find, add, del, timeout
|
||||
1, 0, 0, 0, 0, 0, // ip4: nospace, overlap, many frag, invalid length, dup first frag, dup last frag
|
||||
0, 0, 0, 0, // ip6: find, add, del, timeout
|
||||
|
||||
@@ -619,7 +619,7 @@ TEST(IPV6_REASSEMBLE, NORMAL)
|
||||
assy = ip_reassembly_new(&opts);
|
||||
EXPECT_TRUE(assy != NULL);
|
||||
|
||||
check_stat(ip_reassembly_get_stat(assy),
|
||||
check_stat(ip_reassembly_stat(assy),
|
||||
0, 0, 0, 0, // ip4: find, add, del, timeout
|
||||
0, 0, 0, 0, 0, 0, // ip4: nospace, overlap, many frag, invalid length, dup first frag, dup last frag
|
||||
0, 0, 0, 0, // ip6: find, add, del, timeout
|
||||
@@ -630,7 +630,7 @@ TEST(IPV6_REASSEMBLE, NORMAL)
|
||||
new_pkt = ip_reassembly_packet(assy, &pkt, 1);
|
||||
EXPECT_TRUE(new_pkt == NULL);
|
||||
|
||||
check_stat(ip_reassembly_get_stat(assy),
|
||||
check_stat(ip_reassembly_stat(assy),
|
||||
0, 0, 0, 0, // ip4: find, add, del, timeout
|
||||
0, 0, 0, 0, 0, 0, // ip4: nospace, overlap, many frag, invalid length, dup first frag, dup last frag
|
||||
1, 1, 0, 0, // ip6: find, add, del, timeout
|
||||
@@ -641,7 +641,7 @@ TEST(IPV6_REASSEMBLE, NORMAL)
|
||||
new_pkt = ip_reassembly_packet(assy, &pkt, 1);
|
||||
EXPECT_TRUE(new_pkt == NULL);
|
||||
|
||||
check_stat(ip_reassembly_get_stat(assy),
|
||||
check_stat(ip_reassembly_stat(assy),
|
||||
0, 0, 0, 0, // ip4: find, add, del, timeout
|
||||
0, 0, 0, 0, 0, 0, // ip4: nospace, overlap, many frag, invalid length, dup first frag, dup last frag
|
||||
2, 1, 0, 0, // ip6: find, add, del, timeout
|
||||
@@ -652,7 +652,7 @@ TEST(IPV6_REASSEMBLE, NORMAL)
|
||||
new_pkt = ip_reassembly_packet(assy, &pkt, 1);
|
||||
EXPECT_TRUE(new_pkt == NULL);
|
||||
|
||||
check_stat(ip_reassembly_get_stat(assy),
|
||||
check_stat(ip_reassembly_stat(assy),
|
||||
0, 0, 0, 0, // ip4: find, add, del, timeout
|
||||
0, 0, 0, 0, 0, 0, // ip4: nospace, overlap, many frag, invalid length, dup first frag, dup last frag
|
||||
3, 1, 0, 0, // ip6: find, add, del, timeout
|
||||
@@ -663,7 +663,7 @@ TEST(IPV6_REASSEMBLE, NORMAL)
|
||||
new_pkt = ip_reassembly_packet(assy, &pkt, 1);
|
||||
EXPECT_TRUE(new_pkt);
|
||||
|
||||
check_stat(ip_reassembly_get_stat(assy),
|
||||
check_stat(ip_reassembly_stat(assy),
|
||||
0, 0, 0, 0, // ip4: find, add, del, timeout
|
||||
0, 0, 0, 0, 0, 0, // ip4: nospace, overlap, many frag, invalid length, dup first frag, dup last frag
|
||||
4, 1, 1, 0, // ip6: find, add, del, timeout
|
||||
@@ -727,7 +727,7 @@ TEST(IPV6_REASSEMBLE, EXPIRE)
|
||||
assy = ip_reassembly_new(&opts);
|
||||
EXPECT_TRUE(assy != NULL);
|
||||
|
||||
check_stat(ip_reassembly_get_stat(assy),
|
||||
check_stat(ip_reassembly_stat(assy),
|
||||
0, 0, 0, 0, // ip4: find, add, del, timeout
|
||||
0, 0, 0, 0, 0, 0, // ip4: nospace, overlap, many frag, invalid length, dup first frag, dup last frag
|
||||
0, 0, 0, 0, // ip6: find, add, del, timeout
|
||||
@@ -738,7 +738,7 @@ TEST(IPV6_REASSEMBLE, EXPIRE)
|
||||
new_pkt = ip_reassembly_packet(assy, &pkt, 1);
|
||||
EXPECT_TRUE(new_pkt == NULL);
|
||||
|
||||
check_stat(ip_reassembly_get_stat(assy),
|
||||
check_stat(ip_reassembly_stat(assy),
|
||||
0, 0, 0, 0, // ip4: find, add, del, timeout
|
||||
0, 0, 0, 0, 0, 0, // ip4: nospace, overlap, many frag, invalid length, dup first frag, dup last frag
|
||||
1, 1, 0, 0, // ip6: find, add, del, timeout
|
||||
@@ -749,7 +749,7 @@ TEST(IPV6_REASSEMBLE, EXPIRE)
|
||||
new_pkt = ip_reassembly_packet(assy, &pkt, 2);
|
||||
EXPECT_TRUE(new_pkt == NULL);
|
||||
|
||||
check_stat(ip_reassembly_get_stat(assy),
|
||||
check_stat(ip_reassembly_stat(assy),
|
||||
0, 0, 0, 0, // ip4: find, add, del, timeout
|
||||
0, 0, 0, 0, 0, 0, // ip4: nospace, overlap, many frag, invalid length, dup first frag, dup last frag
|
||||
2, 2, 1, 1, // ip6: find, add, del, timeout
|
||||
@@ -779,7 +779,7 @@ TEST(IPV6_REASSEMBLE, DUP_FIRST_FRAG)
|
||||
assy = ip_reassembly_new(&opts);
|
||||
EXPECT_TRUE(assy != NULL);
|
||||
|
||||
check_stat(ip_reassembly_get_stat(assy),
|
||||
check_stat(ip_reassembly_stat(assy),
|
||||
0, 0, 0, 0, // ip4: find, add, del, timeout
|
||||
0, 0, 0, 0, 0, 0, // ip4: nospace, overlap, many frag, invalid length, dup first frag, dup last frag
|
||||
0, 0, 0, 0, // ip6: find, add, del, timeout
|
||||
@@ -790,7 +790,7 @@ TEST(IPV6_REASSEMBLE, DUP_FIRST_FRAG)
|
||||
new_pkt = ip_reassembly_packet(assy, &pkt, 1);
|
||||
EXPECT_TRUE(new_pkt == NULL);
|
||||
|
||||
check_stat(ip_reassembly_get_stat(assy),
|
||||
check_stat(ip_reassembly_stat(assy),
|
||||
0, 0, 0, 0, // ip4: find, add, del, timeout
|
||||
0, 0, 0, 0, 0, 0, // ip4: nospace, overlap, many frag, invalid length, dup first frag, dup last frag
|
||||
1, 1, 0, 0, // ip6: find, add, del, timeout
|
||||
@@ -801,7 +801,7 @@ TEST(IPV6_REASSEMBLE, DUP_FIRST_FRAG)
|
||||
new_pkt = ip_reassembly_packet(assy, &pkt, 1);
|
||||
EXPECT_TRUE(new_pkt == NULL);
|
||||
|
||||
check_stat(ip_reassembly_get_stat(assy),
|
||||
check_stat(ip_reassembly_stat(assy),
|
||||
0, 0, 0, 0, // ip4: find, add, del, timeout
|
||||
0, 0, 0, 0, 0, 0, // ip4: nospace, overlap, many frag, invalid length, dup first frag, dup last frag
|
||||
2, 1, 0, 0, // ip6: find, add, del, timeout
|
||||
@@ -812,7 +812,7 @@ TEST(IPV6_REASSEMBLE, DUP_FIRST_FRAG)
|
||||
new_pkt = ip_reassembly_packet(assy, &pkt, 1);
|
||||
EXPECT_TRUE(new_pkt == NULL);
|
||||
|
||||
check_stat(ip_reassembly_get_stat(assy),
|
||||
check_stat(ip_reassembly_stat(assy),
|
||||
0, 0, 0, 0, // ip4: find, add, del, timeout
|
||||
0, 0, 0, 0, 0, 0, // ip4: nospace, overlap, many frag, invalid length, dup first frag, dup last frag
|
||||
3, 1, 0, 0, // ip6: find, add, del, timeout
|
||||
@@ -823,7 +823,7 @@ TEST(IPV6_REASSEMBLE, DUP_FIRST_FRAG)
|
||||
new_pkt = ip_reassembly_packet(assy, &pkt, 1);
|
||||
EXPECT_TRUE(new_pkt == NULL);
|
||||
|
||||
check_stat(ip_reassembly_get_stat(assy),
|
||||
check_stat(ip_reassembly_stat(assy),
|
||||
0, 0, 0, 0, // ip4: find, add, del, timeout
|
||||
0, 0, 0, 0, 0, 0, // ip4: nospace, overlap, many frag, invalid length, dup first frag, dup last frag
|
||||
4, 1, 0, 0, // ip6: find, add, del, timeout
|
||||
@@ -834,7 +834,7 @@ TEST(IPV6_REASSEMBLE, DUP_FIRST_FRAG)
|
||||
new_pkt = ip_reassembly_packet(assy, &pkt, 1);
|
||||
EXPECT_TRUE(new_pkt);
|
||||
|
||||
check_stat(ip_reassembly_get_stat(assy),
|
||||
check_stat(ip_reassembly_stat(assy),
|
||||
0, 0, 0, 0, // ip4: find, add, del, timeout
|
||||
0, 0, 0, 0, 0, 0, // ip4: nospace, overlap, many frag, invalid length, dup first frag, dup last frag
|
||||
5, 1, 1, 0, // ip6: find, add, del, timeout
|
||||
@@ -899,7 +899,7 @@ TEST(IPV6_REASSEMBLE, DUP_LAST_FRAG)
|
||||
assy = ip_reassembly_new(&opts);
|
||||
EXPECT_TRUE(assy != NULL);
|
||||
|
||||
check_stat(ip_reassembly_get_stat(assy),
|
||||
check_stat(ip_reassembly_stat(assy),
|
||||
0, 0, 0, 0, // ip4: find, add, del, timeout
|
||||
0, 0, 0, 0, 0, 0, // ip4: nospace, overlap, many frag, invalid length, dup first frag, dup last frag
|
||||
0, 0, 0, 0, // ip6: find, add, del, timeout
|
||||
@@ -910,7 +910,7 @@ TEST(IPV6_REASSEMBLE, DUP_LAST_FRAG)
|
||||
new_pkt = ip_reassembly_packet(assy, &pkt, 1);
|
||||
EXPECT_TRUE(new_pkt == NULL);
|
||||
|
||||
check_stat(ip_reassembly_get_stat(assy),
|
||||
check_stat(ip_reassembly_stat(assy),
|
||||
0, 0, 0, 0, // ip4: find, add, del, timeout
|
||||
0, 0, 0, 0, 0, 0, // ip4: nospace, overlap, many frag, invalid length, dup first frag, dup last frag
|
||||
1, 1, 0, 0, // ip6: find, add, del, timeout
|
||||
@@ -921,7 +921,7 @@ TEST(IPV6_REASSEMBLE, DUP_LAST_FRAG)
|
||||
new_pkt = ip_reassembly_packet(assy, &pkt, 1);
|
||||
EXPECT_TRUE(new_pkt == NULL);
|
||||
|
||||
check_stat(ip_reassembly_get_stat(assy),
|
||||
check_stat(ip_reassembly_stat(assy),
|
||||
0, 0, 0, 0, // ip4: find, add, del, timeout
|
||||
0, 0, 0, 0, 0, 0, // ip4: nospace, overlap, many frag, invalid length, dup first frag, dup last frag
|
||||
2, 1, 0, 0, // ip6: find, add, del, timeout
|
||||
@@ -932,7 +932,7 @@ TEST(IPV6_REASSEMBLE, DUP_LAST_FRAG)
|
||||
new_pkt = ip_reassembly_packet(assy, &pkt, 1);
|
||||
EXPECT_TRUE(new_pkt == NULL);
|
||||
|
||||
check_stat(ip_reassembly_get_stat(assy),
|
||||
check_stat(ip_reassembly_stat(assy),
|
||||
0, 0, 0, 0, // ip4: find, add, del, timeout
|
||||
0, 0, 0, 0, 0, 0, // ip4: nospace, overlap, many frag, invalid length, dup first frag, dup last frag
|
||||
3, 1, 0, 0, // ip6: find, add, del, timeout
|
||||
@@ -943,7 +943,7 @@ TEST(IPV6_REASSEMBLE, DUP_LAST_FRAG)
|
||||
new_pkt = ip_reassembly_packet(assy, &pkt, 1);
|
||||
EXPECT_TRUE(new_pkt == NULL);
|
||||
|
||||
check_stat(ip_reassembly_get_stat(assy),
|
||||
check_stat(ip_reassembly_stat(assy),
|
||||
0, 0, 0, 0, // ip4: find, add, del, timeout
|
||||
0, 0, 0, 0, 0, 0, // ip4: nospace, overlap, many frag, invalid length, dup first frag, dup last frag
|
||||
4, 1, 0, 0, // ip6: find, add, del, timeout
|
||||
@@ -954,7 +954,7 @@ TEST(IPV6_REASSEMBLE, DUP_LAST_FRAG)
|
||||
new_pkt = ip_reassembly_packet(assy, &pkt, 1);
|
||||
EXPECT_TRUE(new_pkt);
|
||||
|
||||
check_stat(ip_reassembly_get_stat(assy),
|
||||
check_stat(ip_reassembly_stat(assy),
|
||||
0, 0, 0, 0, // ip4: find, add, del, timeout
|
||||
0, 0, 0, 0, 0, 0, // ip4: nospace, overlap, many frag, invalid length, dup first frag, dup last frag
|
||||
5, 1, 1, 0, // ip6: find, add, del, timeout
|
||||
@@ -1019,7 +1019,7 @@ TEST(IPV6_REASSEMBLE, FULL)
|
||||
assy = ip_reassembly_new(&opts);
|
||||
EXPECT_TRUE(assy != NULL);
|
||||
|
||||
check_stat(ip_reassembly_get_stat(assy),
|
||||
check_stat(ip_reassembly_stat(assy),
|
||||
0, 0, 0, 0, // ip4: find, add, del, timeout
|
||||
0, 0, 0, 0, 0, 0, // ip4: nospace, overlap, many frag, invalid length, dup first frag, dup last frag
|
||||
0, 0, 0, 0, // ip6: find, add, del, timeout
|
||||
@@ -1035,7 +1035,7 @@ TEST(IPV6_REASSEMBLE, FULL)
|
||||
new_pkt = ip_reassembly_packet(assy, &pkt, 1);
|
||||
EXPECT_TRUE(new_pkt == NULL);
|
||||
|
||||
check_stat(ip_reassembly_get_stat(assy),
|
||||
check_stat(ip_reassembly_stat(assy),
|
||||
0, 0, 0, 0, // ip4: find, add, del, timeout
|
||||
0, 0, 0, 0, 0, 0, // ip4: nospace, overlap, many frag, invalid length, dup first frag, dup last frag
|
||||
1, 1, 0, 0, // ip6: find, add, del, timeout
|
||||
@@ -1047,7 +1047,7 @@ TEST(IPV6_REASSEMBLE, FULL)
|
||||
new_pkt = ip_reassembly_packet(assy, &pkt, 1);
|
||||
EXPECT_TRUE(new_pkt == NULL);
|
||||
|
||||
check_stat(ip_reassembly_get_stat(assy),
|
||||
check_stat(ip_reassembly_stat(assy),
|
||||
0, 0, 0, 0, // ip4: find, add, del, timeout
|
||||
0, 0, 0, 0, 0, 0, // ip4: nospace, overlap, many frag, invalid length, dup first frag, dup last frag
|
||||
2, 2, 0, 0, // ip6: find, add, del, timeout
|
||||
@@ -1059,7 +1059,7 @@ TEST(IPV6_REASSEMBLE, FULL)
|
||||
new_pkt = ip_reassembly_packet(assy, &pkt, 1);
|
||||
EXPECT_TRUE(new_pkt == NULL);
|
||||
|
||||
check_stat(ip_reassembly_get_stat(assy),
|
||||
check_stat(ip_reassembly_stat(assy),
|
||||
0, 0, 0, 0, // ip4: find, add, del, timeout
|
||||
0, 0, 0, 0, 0, 0, // ip4: nospace, overlap, many frag, invalid length, dup first frag, dup last frag
|
||||
3, 2, 0, 0, // ip6: find, add, del, timeout
|
||||
@@ -1088,7 +1088,7 @@ TEST(IPV6_REASSEMBLE, OVERLAP)
|
||||
assy = ip_reassembly_new(&opts);
|
||||
EXPECT_TRUE(assy != NULL);
|
||||
|
||||
check_stat(ip_reassembly_get_stat(assy),
|
||||
check_stat(ip_reassembly_stat(assy),
|
||||
0, 0, 0, 0, // ip4: find, add, del, timeout
|
||||
0, 0, 0, 0, 0, 0, // ip4: nospace, overlap, many frag, invalid length, dup first frag, dup last frag
|
||||
0, 0, 0, 0, // ip6: find, add, del, timeout
|
||||
@@ -1099,7 +1099,7 @@ TEST(IPV6_REASSEMBLE, OVERLAP)
|
||||
new_pkt = ip_reassembly_packet(assy, &pkt, 1);
|
||||
EXPECT_TRUE(new_pkt == NULL);
|
||||
|
||||
check_stat(ip_reassembly_get_stat(assy),
|
||||
check_stat(ip_reassembly_stat(assy),
|
||||
0, 0, 0, 0, // ip4: find, add, del, timeout
|
||||
0, 0, 0, 0, 0, 0, // ip4: nospace, overlap, many frag, invalid length, dup first frag, dup last frag
|
||||
1, 1, 0, 0, // ip6: find, add, del, timeout
|
||||
@@ -1110,7 +1110,7 @@ TEST(IPV6_REASSEMBLE, OVERLAP)
|
||||
new_pkt = ip_reassembly_packet(assy, &pkt, 1);
|
||||
EXPECT_TRUE(new_pkt == NULL);
|
||||
|
||||
check_stat(ip_reassembly_get_stat(assy),
|
||||
check_stat(ip_reassembly_stat(assy),
|
||||
0, 0, 0, 0, // ip4: find, add, del, timeout
|
||||
0, 0, 0, 0, 0, 0, // ip4: nospace, overlap, many frag, invalid length, dup first frag, dup last frag
|
||||
2, 1, 0, 0, // ip6: find, add, del, timeout
|
||||
@@ -1124,7 +1124,7 @@ TEST(IPV6_REASSEMBLE, OVERLAP)
|
||||
new_pkt = ip_reassembly_packet(assy, &pkt, 1);
|
||||
EXPECT_TRUE(new_pkt == NULL);
|
||||
|
||||
check_stat(ip_reassembly_get_stat(assy),
|
||||
check_stat(ip_reassembly_stat(assy),
|
||||
0, 0, 0, 0, // ip4: find, add, del, timeout
|
||||
0, 0, 0, 0, 0, 0, // ip4: nospace, overlap, many frag, invalid length, dup first frag, dup last frag
|
||||
3, 1, 0, 0, // ip6: find, add, del, timeout
|
||||
@@ -1135,7 +1135,7 @@ TEST(IPV6_REASSEMBLE, OVERLAP)
|
||||
new_pkt = ip_reassembly_packet(assy, &pkt, 1);
|
||||
EXPECT_TRUE(new_pkt == NULL);
|
||||
|
||||
check_stat(ip_reassembly_get_stat(assy),
|
||||
check_stat(ip_reassembly_stat(assy),
|
||||
0, 0, 0, 0, // ip4: find, add, del, timeout
|
||||
0, 0, 0, 0, 0, 0, // ip4: nospace, overlap, many frag, invalid length, dup first frag, dup last frag
|
||||
4, 1, 1, 0, // ip6: find, add, del, timeout
|
||||
|
||||
@@ -20,7 +20,7 @@ struct dumpfile_io
|
||||
|
||||
pcap_t *pcap;
|
||||
struct lock_free_queue *queue[MAX_THREAD_NUM];
|
||||
struct io_stat stat;
|
||||
struct io_stat stat[MAX_THREAD_NUM];
|
||||
uint64_t io_thread_need_exit;
|
||||
uint64_t io_thread_is_runing;
|
||||
};
|
||||
@@ -193,11 +193,6 @@ void dumpfile_io_free(struct dumpfile_io *handle)
|
||||
}
|
||||
}
|
||||
|
||||
struct io_stat *dumpfile_io_get_stat(struct dumpfile_io *handle)
|
||||
{
|
||||
return &handle->stat;
|
||||
}
|
||||
|
||||
int dumpfile_io_init(struct dumpfile_io *handle, uint16_t thr_idx)
|
||||
{
|
||||
return 0;
|
||||
@@ -206,6 +201,7 @@ int dumpfile_io_init(struct dumpfile_io *handle, uint16_t thr_idx)
|
||||
int dumpfile_io_ingress(struct dumpfile_io *handle, uint16_t thr_idx, struct packet *pkts, int nr_pkts)
|
||||
{
|
||||
struct lock_free_queue *queue = handle->queue[thr_idx];
|
||||
struct io_stat *stat = &handle->stat[thr_idx];
|
||||
struct pcap_pkt *pcap_pkt = NULL;
|
||||
struct packet *pkt;
|
||||
int nr_parsed = 0;
|
||||
@@ -219,11 +215,11 @@ int dumpfile_io_ingress(struct dumpfile_io *handle, uint16_t thr_idx, struct pac
|
||||
}
|
||||
else
|
||||
{
|
||||
ATOMIC_ADD(&handle->stat.dev_rx_pkts, 1);
|
||||
ATOMIC_ADD(&handle->stat.dev_rx_bytes, pcap_pkt->len);
|
||||
stat->dev_rx_pkts++;
|
||||
stat->dev_rx_bytes += pcap_pkt->len;
|
||||
|
||||
ATOMIC_ADD(&handle->stat.raw_rx_pkts, 1);
|
||||
ATOMIC_ADD(&handle->stat.raw_rx_bytes, pcap_pkt->len);
|
||||
stat->raw_rx_pkts++;
|
||||
stat->raw_rx_bytes += pcap_pkt->len;
|
||||
|
||||
pkt = &pkts[nr_parsed];
|
||||
memset(pkt, 0, sizeof(struct packet));
|
||||
@@ -241,16 +237,18 @@ void dumpfile_io_egress(struct dumpfile_io *handle, uint16_t thr_idx, struct pac
|
||||
{
|
||||
int len;
|
||||
struct packet *pkt = NULL;
|
||||
struct io_stat *stat = &handle->stat[thr_idx];
|
||||
|
||||
for (int i = 0; i < nr_pkts; i++)
|
||||
{
|
||||
pkt = &pkts[i];
|
||||
len = packet_get_len(pkt);
|
||||
|
||||
ATOMIC_ADD(&handle->stat.dev_tx_pkts, 1);
|
||||
ATOMIC_ADD(&handle->stat.dev_tx_bytes, len);
|
||||
stat->dev_tx_pkts++;
|
||||
stat->dev_tx_bytes += len;
|
||||
|
||||
ATOMIC_ADD(&handle->stat.raw_tx_pkts, 1);
|
||||
ATOMIC_ADD(&handle->stat.raw_tx_bytes, len);
|
||||
stat->raw_tx_pkts++;
|
||||
stat->raw_tx_bytes += len;
|
||||
|
||||
struct pcap_pkt *pcap_pkt = (struct pcap_pkt *)packet_get_io_ctx(pkt);
|
||||
if (pcap_pkt)
|
||||
@@ -275,3 +273,13 @@ void dumpfile_io_drop(struct dumpfile_io *handle, uint16_t thr_idx, struct packe
|
||||
packet_free(pkt);
|
||||
}
|
||||
}
|
||||
|
||||
void dumpfile_io_yield(struct dumpfile_io *handle, uint16_t thr_idx, uint64_t timeout_ms)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
struct io_stat *dumpfile_io_stat(struct dumpfile_io *handle, uint16_t thr_idx)
|
||||
{
|
||||
return &handle->stat[thr_idx];
|
||||
}
|
||||
@@ -11,12 +11,13 @@ extern "C"
|
||||
struct dumpfile_io;
|
||||
struct dumpfile_io *dumpfile_io_new(const char *directory, uint8_t nr_threads);
|
||||
void dumpfile_io_free(struct dumpfile_io *handle);
|
||||
struct io_stat *dumpfile_io_get_stat(struct dumpfile_io *handle);
|
||||
|
||||
int dumpfile_io_init(struct dumpfile_io *handle, uint16_t thr_idx);
|
||||
int dumpfile_io_ingress(struct dumpfile_io *handle, uint16_t thr_idx, struct packet *pkts, int nr_pkts);
|
||||
void dumpfile_io_egress(struct dumpfile_io *handle, uint16_t thr_idx, struct packet *pkts, int nr_pkts);
|
||||
void dumpfile_io_drop(struct dumpfile_io *handle, uint16_t thr_idx, struct packet *pkts, int nr_pkts);
|
||||
void dumpfile_io_yield(struct dumpfile_io *handle, uint16_t thr_idx, uint64_t timeout_ms);
|
||||
struct io_stat *dumpfile_io_stat(struct dumpfile_io *handle, uint16_t thr_idx);
|
||||
|
||||
#ifdef __cpluscplus
|
||||
}
|
||||
|
||||
@@ -15,7 +15,7 @@ struct marsio_io
|
||||
struct mr_vdev *mr_dev;
|
||||
struct mr_sendpath *mr_path;
|
||||
|
||||
struct io_stat stat;
|
||||
struct io_stat stat[MAX_THREAD_NUM];
|
||||
};
|
||||
|
||||
/******************************************************************************
|
||||
@@ -118,11 +118,6 @@ void marsio_io_free(struct marsio_io *handle)
|
||||
}
|
||||
}
|
||||
|
||||
struct io_stat *marsio_io_get_stat(struct marsio_io *handle)
|
||||
{
|
||||
return &handle->stat;
|
||||
}
|
||||
|
||||
int marsio_io_init(struct marsio_io *handle, uint16_t thr_idx)
|
||||
{
|
||||
if (marsio_thread_init(handle->mr_ins) != 0)
|
||||
@@ -139,6 +134,7 @@ int marsio_io_ingress(struct marsio_io *handle, uint16_t thr_idx, struct packet
|
||||
struct packet *pkt;
|
||||
marsio_buff_t *mbuff;
|
||||
marsio_buff_t *rx_buffs[RX_BURST_MAX];
|
||||
struct io_stat *stat = &handle->stat[thr_idx];
|
||||
int nr_recv;
|
||||
int nr_parsed = 0;
|
||||
int len;
|
||||
@@ -156,16 +152,16 @@ int marsio_io_ingress(struct marsio_io *handle, uint16_t thr_idx, struct packet
|
||||
data = marsio_buff_mtod(mbuff);
|
||||
len = marsio_buff_datalen(mbuff);
|
||||
|
||||
ATOMIC_ADD(&handle->stat.dev_rx_pkts, 1);
|
||||
ATOMIC_ADD(&handle->stat.dev_rx_bytes, len);
|
||||
stat->dev_rx_pkts++;
|
||||
stat->dev_rx_bytes += len;
|
||||
|
||||
if (is_keepalive_packet(data, len))
|
||||
{
|
||||
ATOMIC_ADD(&handle->stat.keep_alive_pkts, 1);
|
||||
ATOMIC_ADD(&handle->stat.keep_alive_bytes, len);
|
||||
stat->keep_alive_pkts++;
|
||||
stat->keep_alive_bytes += len;
|
||||
|
||||
ATOMIC_ADD(&handle->stat.dev_tx_pkts, 1);
|
||||
ATOMIC_ADD(&handle->stat.dev_tx_bytes, len);
|
||||
stat->dev_tx_pkts++;
|
||||
stat->dev_tx_bytes += len;
|
||||
|
||||
marsio_send_burst(handle->mr_path, thr_idx, &mbuff, 1);
|
||||
continue;
|
||||
@@ -181,13 +177,13 @@ int marsio_io_ingress(struct marsio_io *handle, uint16_t thr_idx, struct packet
|
||||
if (marsio_buff_is_ctrlbuf(mbuff))
|
||||
{
|
||||
packet_set_ctrl(pkt);
|
||||
ATOMIC_ADD(&handle->stat.ctrl_rx_pkts, 1);
|
||||
ATOMIC_ADD(&handle->stat.ctrl_rx_bytes, len);
|
||||
stat->ctrl_rx_pkts++;
|
||||
stat->ctrl_rx_bytes += len;
|
||||
}
|
||||
else
|
||||
{
|
||||
ATOMIC_ADD(&handle->stat.raw_rx_pkts, 1);
|
||||
ATOMIC_ADD(&handle->stat.raw_rx_bytes, len);
|
||||
stat->raw_rx_pkts++;
|
||||
stat->raw_rx_bytes += len;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -198,6 +194,7 @@ void marsio_io_egress(struct marsio_io *handle, uint16_t thr_idx, struct packet
|
||||
{
|
||||
struct packet *pkt;
|
||||
marsio_buff_t *mbuff;
|
||||
struct io_stat *stat = &handle->stat[thr_idx];
|
||||
int len;
|
||||
|
||||
for (int i = 0; i < nr_pkts; i++)
|
||||
@@ -205,21 +202,21 @@ void marsio_io_egress(struct marsio_io *handle, uint16_t thr_idx, struct packet
|
||||
pkt = &pkts[i];
|
||||
len = packet_get_len(pkt);
|
||||
|
||||
ATOMIC_ADD(&handle->stat.dev_tx_pkts, 1);
|
||||
ATOMIC_ADD(&handle->stat.dev_tx_bytes, len);
|
||||
stat->dev_tx_pkts++;
|
||||
stat->dev_tx_bytes += len;
|
||||
|
||||
mbuff = (marsio_buff_t *)packet_get_io_ctx(pkt);
|
||||
assert(mbuff != NULL);
|
||||
|
||||
if (marsio_buff_is_ctrlbuf(mbuff))
|
||||
{
|
||||
ATOMIC_ADD(&handle->stat.ctrl_tx_pkts, 1);
|
||||
ATOMIC_ADD(&handle->stat.ctrl_tx_bytes, len);
|
||||
stat->ctrl_tx_pkts++;
|
||||
stat->ctrl_tx_bytes += len;
|
||||
}
|
||||
else
|
||||
{
|
||||
ATOMIC_ADD(&handle->stat.raw_tx_pkts, 1);
|
||||
ATOMIC_ADD(&handle->stat.raw_tx_bytes, len);
|
||||
stat->raw_tx_pkts++;
|
||||
stat->raw_tx_bytes += len;
|
||||
}
|
||||
|
||||
marsio_send_burst(handle->mr_path, thr_idx, &mbuff, 1);
|
||||
@@ -243,3 +240,17 @@ void marsio_io_drop(struct marsio_io *handle, uint16_t thr_idx, struct packet *p
|
||||
packet_free(pkt);
|
||||
}
|
||||
}
|
||||
|
||||
void marsio_io_yield(struct marsio_io *handle, uint16_t thr_idx, uint64_t timeout_ms)
|
||||
{
|
||||
struct mr_vdev *vdevs[1] = {
|
||||
handle->mr_dev,
|
||||
};
|
||||
|
||||
marsio_poll_wait(handle->mr_ins, vdevs, 1, thr_idx, timeout_ms);
|
||||
}
|
||||
|
||||
struct io_stat *marsio_io_stat(struct marsio_io *handle, uint16_t thr_idx)
|
||||
{
|
||||
return &handle->stat[thr_idx];
|
||||
}
|
||||
|
||||
@@ -11,12 +11,13 @@ extern "C"
|
||||
struct marsio_io;
|
||||
struct marsio_io *marsio_io_new(const char *app_symbol, const char *dev_symbol, uint16_t *cpu_mask, uint8_t nr_threads);
|
||||
void marsio_io_free(struct marsio_io *handle);
|
||||
struct io_stat *marsio_io_get_stat(struct marsio_io *handle);
|
||||
|
||||
int marsio_io_init(struct marsio_io *handle, uint16_t thr_idx);
|
||||
int marsio_io_ingress(struct marsio_io *handle, uint16_t thr_idx, struct packet *pkts, int nr_pkts);
|
||||
void marsio_io_egress(struct marsio_io *handle, uint16_t thr_idx, struct packet *pkts, int nr_pkts);
|
||||
void marsio_io_drop(struct marsio_io *handle, uint16_t thr_idx, struct packet *pkts, int nr_pkts);
|
||||
void marsio_io_yield(struct marsio_io *handle, uint16_t thr_idx, uint64_t timeout_ms);
|
||||
struct io_stat *marsio_io_stat(struct marsio_io *handle, uint16_t thr_idx);
|
||||
|
||||
#ifdef __cpluscplus
|
||||
}
|
||||
|
||||
@@ -45,7 +45,7 @@ void packet_io_free(struct packet_io *packet_io)
|
||||
{
|
||||
if (packet_io)
|
||||
{
|
||||
if (packet_io->mode == PACKET_IO_MARSIO)
|
||||
if (likely(packet_io->mode == PACKET_IO_MARSIO))
|
||||
{
|
||||
marsio_io_free(packet_io->marsio);
|
||||
}
|
||||
@@ -58,21 +58,9 @@ void packet_io_free(struct packet_io *packet_io)
|
||||
}
|
||||
}
|
||||
|
||||
struct io_stat *packet_io_get_stat(struct packet_io *packet_io)
|
||||
{
|
||||
if (packet_io->mode == PACKET_IO_MARSIO)
|
||||
{
|
||||
return marsio_io_get_stat(packet_io->marsio);
|
||||
}
|
||||
else
|
||||
{
|
||||
return dumpfile_io_get_stat(packet_io->dumpfile);
|
||||
}
|
||||
}
|
||||
|
||||
int packet_io_init(struct packet_io *packet_io, uint16_t thr_idx)
|
||||
{
|
||||
if (packet_io->mode == PACKET_IO_MARSIO)
|
||||
if (likely(packet_io->mode == PACKET_IO_MARSIO))
|
||||
{
|
||||
return marsio_io_init(packet_io->marsio, thr_idx);
|
||||
}
|
||||
@@ -84,7 +72,7 @@ int packet_io_init(struct packet_io *packet_io, uint16_t thr_idx)
|
||||
|
||||
int packet_io_ingress(struct packet_io *packet_io, uint16_t thr_idx, struct packet *pkts, int nr_pkts)
|
||||
{
|
||||
if (packet_io->mode == PACKET_IO_MARSIO)
|
||||
if (likely(packet_io->mode == PACKET_IO_MARSIO))
|
||||
{
|
||||
return marsio_io_ingress(packet_io->marsio, thr_idx, pkts, nr_pkts);
|
||||
}
|
||||
@@ -96,7 +84,7 @@ int packet_io_ingress(struct packet_io *packet_io, uint16_t thr_idx, struct pack
|
||||
|
||||
void packet_io_egress(struct packet_io *packet_io, uint16_t thr_idx, struct packet *pkts, int nr_pkts)
|
||||
{
|
||||
if (packet_io->mode == PACKET_IO_MARSIO)
|
||||
if (likely(packet_io->mode == PACKET_IO_MARSIO))
|
||||
{
|
||||
marsio_io_egress(packet_io->marsio, thr_idx, pkts, nr_pkts);
|
||||
}
|
||||
@@ -108,7 +96,7 @@ void packet_io_egress(struct packet_io *packet_io, uint16_t thr_idx, struct pack
|
||||
|
||||
void packet_io_drop(struct packet_io *packet_io, uint16_t thr_idx, struct packet *pkts, int nr_pkts)
|
||||
{
|
||||
if (packet_io->mode == PACKET_IO_MARSIO)
|
||||
if (likely(packet_io->mode == PACKET_IO_MARSIO))
|
||||
{
|
||||
marsio_io_drop(packet_io->marsio, thr_idx, pkts, nr_pkts);
|
||||
}
|
||||
@@ -117,3 +105,27 @@ void packet_io_drop(struct packet_io *packet_io, uint16_t thr_idx, struct packet
|
||||
dumpfile_io_drop(packet_io->dumpfile, thr_idx, pkts, nr_pkts);
|
||||
}
|
||||
}
|
||||
|
||||
void packet_io_yield(struct packet_io *packet_io, uint16_t thr_idx, uint64_t timeout_ms)
|
||||
{
|
||||
if (likely(packet_io->mode == PACKET_IO_MARSIO))
|
||||
{
|
||||
marsio_io_yield(packet_io->marsio, thr_idx, timeout_ms);
|
||||
}
|
||||
else
|
||||
{
|
||||
dumpfile_io_yield(packet_io->dumpfile, thr_idx, timeout_ms);
|
||||
}
|
||||
}
|
||||
|
||||
struct io_stat *packet_io_stat(struct packet_io *packet_io, uint16_t thr_idx)
|
||||
{
|
||||
if (likely(packet_io->mode == PACKET_IO_MARSIO))
|
||||
{
|
||||
return marsio_io_stat(packet_io->marsio, thr_idx);
|
||||
}
|
||||
else
|
||||
{
|
||||
return dumpfile_io_stat(packet_io->dumpfile, thr_idx);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -66,12 +66,13 @@ struct packet_io_options
|
||||
struct packet_io;
|
||||
struct packet_io *packet_io_new(struct packet_io_options *opts);
|
||||
void packet_io_free(struct packet_io *packet_io);
|
||||
struct io_stat *packet_io_get_stat(struct packet_io *packet_io);
|
||||
|
||||
int packet_io_init(struct packet_io *packet_io, uint16_t thr_idx);
|
||||
int packet_io_ingress(struct packet_io *packet_io, uint16_t thr_idx, struct packet *pkts, int nr_pkts);
|
||||
void packet_io_egress(struct packet_io *packet_io, uint16_t thr_idx, struct packet *pkts, int nr_pkts);
|
||||
void packet_io_drop(struct packet_io *packet_io, uint16_t thr_idx, struct packet *pkts, int nr_pkts);
|
||||
void packet_io_yield(struct packet_io *packet_io, uint16_t thr_idx, uint64_t timeout_ms);
|
||||
struct io_stat *packet_io_stat(struct packet_io *packet_io, uint16_t thr_idx);
|
||||
|
||||
#ifdef __cpluscplus
|
||||
}
|
||||
|
||||
@@ -1056,22 +1056,7 @@ uint64_t session_manager_get_expire_interval(struct session_manager *mgr)
|
||||
return session_timer_next_expire_interval(mgr->sess_timer);
|
||||
}
|
||||
|
||||
void session_manager_print_stat(struct session_manager *mgr)
|
||||
{
|
||||
if (mgr)
|
||||
{
|
||||
SESSION_LOG_DEBUG("session_manager_stat->tcp_sess: used: %u, opening: %u, active: %u, closing: %u, closed: %u",
|
||||
mgr->stat.nr_tcp_sess_used, mgr->stat.nr_tcp_sess_opening, mgr->stat.nr_tcp_sess_active,
|
||||
mgr->stat.nr_tcp_sess_closing, mgr->stat.nr_tcp_sess_closed);
|
||||
SESSION_LOG_DEBUG("session_manager_stat->udp_sess: used: %u, opening: %u, active: %u, closing: %u, closed: %u",
|
||||
mgr->stat.nr_udp_sess_used, mgr->stat.nr_udp_sess_opening, mgr->stat.nr_udp_sess_active,
|
||||
mgr->stat.nr_udp_sess_closing, mgr->stat.nr_udp_sess_closed);
|
||||
SESSION_LOG_DEBUG("session_manager_stat->evicted_sess: tcp: %u, udp: %u",
|
||||
mgr->stat.nr_tcp_sess_evicted, mgr->stat.nr_udp_sess_evicted);
|
||||
}
|
||||
}
|
||||
|
||||
struct session_manager_stat *session_manager_get_stat(struct session_manager *mgr)
|
||||
struct session_manager_stat *session_manager_stat(struct session_manager *mgr)
|
||||
{
|
||||
return &mgr->stat;
|
||||
}
|
||||
|
||||
@@ -111,8 +111,7 @@ struct session *session_manager_get_evicted_session(struct session_manager *mgr)
|
||||
// return >0: next expire interval
|
||||
uint64_t session_manager_get_expire_interval(struct session_manager *mgr);
|
||||
|
||||
void session_manager_print_stat(struct session_manager *mgr);
|
||||
struct session_manager_stat *session_manager_get_stat(struct session_manager *mgr);
|
||||
struct session_manager_stat *session_manager_stat(struct session_manager *mgr);
|
||||
|
||||
#ifdef __cpluscplus
|
||||
}
|
||||
|
||||
@@ -75,7 +75,7 @@ TEST(TCP_DUPKT_FILTER_ENABLE, SYN_DUP)
|
||||
sess = session_manager_new_session(mgr, &pkt, 1);
|
||||
EXPECT_TRUE(sess);
|
||||
EXPECT_TRUE(session_has_dup_traffic(sess) == 0);
|
||||
stat = session_manager_get_stat(mgr);
|
||||
stat = session_manager_stat(mgr);
|
||||
EXPECT_TRUE(stat);
|
||||
EXPECT_TRUE(stat->nr_tcp_pkts_duped_bypass == 0);
|
||||
|
||||
@@ -90,7 +90,7 @@ TEST(TCP_DUPKT_FILTER_ENABLE, SYN_DUP)
|
||||
// update session
|
||||
EXPECT_TRUE(session_manager_update_session(mgr, sess, &pkt, 2) == -1);
|
||||
EXPECT_TRUE(session_has_dup_traffic(sess) == 1);
|
||||
stat = session_manager_get_stat(mgr);
|
||||
stat = session_manager_stat(mgr);
|
||||
EXPECT_TRUE(stat);
|
||||
EXPECT_TRUE(stat->nr_tcp_pkts_duped_bypass == 1);
|
||||
|
||||
@@ -108,7 +108,7 @@ TEST(TCP_DUPKT_FILTER_ENABLE, SYN_DUP)
|
||||
// update session
|
||||
EXPECT_TRUE(session_manager_update_session(mgr, sess, &pkt, 3) == 0);
|
||||
EXPECT_TRUE(session_has_dup_traffic(sess) == 1);
|
||||
stat = session_manager_get_stat(mgr);
|
||||
stat = session_manager_stat(mgr);
|
||||
EXPECT_TRUE(stat);
|
||||
EXPECT_TRUE(stat->nr_tcp_pkts_duped_bypass == 1);
|
||||
|
||||
@@ -138,7 +138,7 @@ TEST(TCP_DUPKT_FILTER_ENABLE, SYNACK_DUP)
|
||||
sess = session_manager_new_session(mgr, &pkt, 1);
|
||||
EXPECT_TRUE(sess);
|
||||
EXPECT_TRUE(session_has_dup_traffic(sess) == 0);
|
||||
stat = session_manager_get_stat(mgr);
|
||||
stat = session_manager_stat(mgr);
|
||||
EXPECT_TRUE(stat);
|
||||
EXPECT_TRUE(stat->nr_tcp_pkts_duped_bypass == 0);
|
||||
|
||||
@@ -153,7 +153,7 @@ TEST(TCP_DUPKT_FILTER_ENABLE, SYNACK_DUP)
|
||||
// update session
|
||||
EXPECT_TRUE(session_manager_update_session(mgr, sess, &pkt, 2) == -1);
|
||||
EXPECT_TRUE(session_has_dup_traffic(sess) == 1);
|
||||
stat = session_manager_get_stat(mgr);
|
||||
stat = session_manager_stat(mgr);
|
||||
EXPECT_TRUE(stat);
|
||||
EXPECT_TRUE(stat->nr_tcp_pkts_duped_bypass == 1);
|
||||
|
||||
@@ -171,7 +171,7 @@ TEST(TCP_DUPKT_FILTER_ENABLE, SYNACK_DUP)
|
||||
// update session
|
||||
EXPECT_TRUE(session_manager_update_session(mgr, sess, &pkt, 3) == 0);
|
||||
EXPECT_TRUE(session_has_dup_traffic(sess) == 1);
|
||||
stat = session_manager_get_stat(mgr);
|
||||
stat = session_manager_stat(mgr);
|
||||
EXPECT_TRUE(stat);
|
||||
EXPECT_TRUE(stat->nr_tcp_pkts_duped_bypass == 1);
|
||||
|
||||
@@ -202,7 +202,7 @@ TEST(TCP_DUPKT_FILTER_ENABLE, SKIP)
|
||||
sess = session_manager_new_session(mgr, &pkt, 1);
|
||||
EXPECT_TRUE(sess);
|
||||
EXPECT_TRUE(session_has_dup_traffic(sess) == 0);
|
||||
stat = session_manager_get_stat(mgr);
|
||||
stat = session_manager_stat(mgr);
|
||||
EXPECT_TRUE(stat);
|
||||
EXPECT_TRUE(stat->nr_tcp_pkts_duped_bypass == 0);
|
||||
|
||||
@@ -219,7 +219,7 @@ TEST(TCP_DUPKT_FILTER_ENABLE, SKIP)
|
||||
// update session
|
||||
EXPECT_TRUE(session_manager_update_session(mgr, sess, &pkt, 2) == 0);
|
||||
EXPECT_TRUE(session_has_dup_traffic(sess) == 0);
|
||||
stat = session_manager_get_stat(mgr);
|
||||
stat = session_manager_stat(mgr);
|
||||
EXPECT_TRUE(stat);
|
||||
EXPECT_TRUE(stat->nr_tcp_pkts_duped_bypass == 0);
|
||||
|
||||
@@ -236,7 +236,7 @@ TEST(TCP_DUPKT_FILTER_ENABLE, SKIP)
|
||||
// update session
|
||||
EXPECT_TRUE(session_manager_update_session(mgr, sess, &pkt, 3) == 0);
|
||||
EXPECT_TRUE(session_has_dup_traffic(sess) == 0);
|
||||
stat = session_manager_get_stat(mgr);
|
||||
stat = session_manager_stat(mgr);
|
||||
EXPECT_TRUE(stat);
|
||||
EXPECT_TRUE(stat->nr_tcp_pkts_duped_bypass == 0);
|
||||
|
||||
@@ -251,7 +251,7 @@ TEST(TCP_DUPKT_FILTER_ENABLE, SKIP)
|
||||
// update session
|
||||
EXPECT_TRUE(session_manager_update_session(mgr, sess, &pkt, 3) == 0);
|
||||
EXPECT_TRUE(session_has_dup_traffic(sess) == 0);
|
||||
stat = session_manager_get_stat(mgr);
|
||||
stat = session_manager_stat(mgr);
|
||||
EXPECT_TRUE(stat);
|
||||
EXPECT_TRUE(stat->nr_tcp_pkts_duped_bypass == 0);
|
||||
|
||||
@@ -284,7 +284,7 @@ TEST(TCP_DUPKT_FILTER_DISABLE, SYN_DUP)
|
||||
sess = session_manager_new_session(mgr, &pkt, 1);
|
||||
EXPECT_TRUE(sess);
|
||||
EXPECT_TRUE(session_has_dup_traffic(sess) == 0);
|
||||
stat = session_manager_get_stat(mgr);
|
||||
stat = session_manager_stat(mgr);
|
||||
EXPECT_TRUE(stat);
|
||||
EXPECT_TRUE(stat->nr_tcp_pkts_duped_bypass == 0);
|
||||
|
||||
@@ -299,7 +299,7 @@ TEST(TCP_DUPKT_FILTER_DISABLE, SYN_DUP)
|
||||
// update session
|
||||
EXPECT_TRUE(session_manager_update_session(mgr, sess, &pkt, 2) == 0);
|
||||
EXPECT_TRUE(session_has_dup_traffic(sess) == 0);
|
||||
stat = session_manager_get_stat(mgr);
|
||||
stat = session_manager_stat(mgr);
|
||||
EXPECT_TRUE(stat);
|
||||
EXPECT_TRUE(stat->nr_tcp_pkts_duped_bypass == 0);
|
||||
|
||||
@@ -332,7 +332,7 @@ TEST(TCP_DUPKT_FILTER_DISABLE, SYNACK_DUP)
|
||||
sess = session_manager_new_session(mgr, &pkt, 1);
|
||||
EXPECT_TRUE(sess);
|
||||
EXPECT_TRUE(session_has_dup_traffic(sess) == 0);
|
||||
stat = session_manager_get_stat(mgr);
|
||||
stat = session_manager_stat(mgr);
|
||||
EXPECT_TRUE(stat);
|
||||
EXPECT_TRUE(stat->nr_tcp_pkts_duped_bypass == 0);
|
||||
|
||||
@@ -347,7 +347,7 @@ TEST(TCP_DUPKT_FILTER_DISABLE, SYNACK_DUP)
|
||||
// update session
|
||||
EXPECT_TRUE(session_manager_update_session(mgr, sess, &pkt, 2) == 0);
|
||||
EXPECT_TRUE(session_has_dup_traffic(sess) == 0);
|
||||
stat = session_manager_get_stat(mgr);
|
||||
stat = session_manager_stat(mgr);
|
||||
EXPECT_TRUE(stat);
|
||||
EXPECT_TRUE(stat->nr_tcp_pkts_duped_bypass == 0);
|
||||
|
||||
|
||||
@@ -77,8 +77,7 @@ TEST(TCP_OVERLOAD, EVICT_OLD_SESS)
|
||||
EXPECT_TRUE(session_manager_new_session(mgr, &pkt, 1));
|
||||
}
|
||||
printf("=> Session Manager: after add %lu new sessions\n", opts.max_tcp_session_num);
|
||||
session_manager_print_stat(mgr);
|
||||
stat = session_manager_get_stat(mgr);
|
||||
stat = session_manager_stat(mgr);
|
||||
EXPECT_TRUE(stat);
|
||||
EXPECT_TRUE(stat->nr_tcp_sess_used == opts.max_tcp_session_num);
|
||||
EXPECT_TRUE(stat->nr_tcp_sess_opening == RX_BURST_MAX);
|
||||
@@ -118,8 +117,7 @@ TEST(TCP_OVERLOAD, EVICT_NEW_SESS)
|
||||
EXPECT_TRUE(session_manager_new_session(mgr, &pkt, 1));
|
||||
}
|
||||
printf("=> Session Manager: after add %lu new sessions\n", opts.max_tcp_session_num);
|
||||
session_manager_print_stat(mgr);
|
||||
stat = session_manager_get_stat(mgr);
|
||||
stat = session_manager_stat(mgr);
|
||||
EXPECT_TRUE(stat);
|
||||
EXPECT_TRUE(stat->nr_tcp_sess_used == opts.max_tcp_session_num);
|
||||
EXPECT_TRUE(stat->nr_tcp_sess_opening == opts.max_tcp_session_num);
|
||||
@@ -138,8 +136,7 @@ TEST(TCP_OVERLOAD, EVICT_NEW_SESS)
|
||||
EXPECT_TRUE(session_manager_new_session(mgr, &pkt, 1) == NULL);
|
||||
}
|
||||
printf("=> Session Manager: after evicte new session\n");
|
||||
session_manager_print_stat(mgr);
|
||||
stat = session_manager_get_stat(mgr);
|
||||
stat = session_manager_stat(mgr);
|
||||
EXPECT_TRUE(stat);
|
||||
EXPECT_TRUE(stat->nr_tcp_sess_used == opts.max_tcp_session_num);
|
||||
EXPECT_TRUE(stat->nr_tcp_sess_opening == opts.max_tcp_session_num);
|
||||
|
||||
@@ -78,8 +78,7 @@ TEST(UDP_OVERLOAD, EVICT_OLD_SESS)
|
||||
EXPECT_TRUE(session_manager_new_session(mgr, &pkt, 1));
|
||||
}
|
||||
printf("=> Session Manager: after add %lu new sessions\n", opts.max_udp_session_num);
|
||||
session_manager_print_stat(mgr);
|
||||
stat = session_manager_get_stat(mgr);
|
||||
stat = session_manager_stat(mgr);
|
||||
EXPECT_TRUE(stat);
|
||||
EXPECT_TRUE(stat->nr_udp_sess_used == opts.max_udp_session_num);
|
||||
EXPECT_TRUE(stat->nr_udp_sess_opening == RX_BURST_MAX);
|
||||
@@ -111,8 +110,7 @@ TEST(UDP_OVERLOAD, EVICT_OLD_SESS)
|
||||
EXPECT_TRUE(session_manager_new_session(mgr, &pkt, 1) == NULL); // hit evicted session, can't renew session
|
||||
}
|
||||
printf("=> Session Manager: after readd %d evicted sessions\n", RX_BURST_MAX);
|
||||
session_manager_print_stat(mgr);
|
||||
stat = session_manager_get_stat(mgr);
|
||||
stat = session_manager_stat(mgr);
|
||||
EXPECT_TRUE(stat);
|
||||
EXPECT_TRUE(stat->nr_udp_sess_used == RX_BURST_MAX);
|
||||
EXPECT_TRUE(stat->nr_udp_sess_opening == RX_BURST_MAX);
|
||||
@@ -128,8 +126,7 @@ TEST(UDP_OVERLOAD, EVICT_OLD_SESS)
|
||||
EXPECT_TRUE(session_manager_lookup_session(mgr, &pkt) == NULL);
|
||||
EXPECT_TRUE(session_manager_new_session(mgr, &pkt, 1 + opts.evicted_session_filter_timeout));
|
||||
printf("=> Session Manager: after evicted session timeout\n");
|
||||
session_manager_print_stat(mgr);
|
||||
stat = session_manager_get_stat(mgr);
|
||||
stat = session_manager_stat(mgr);
|
||||
EXPECT_TRUE(stat);
|
||||
EXPECT_TRUE(stat->nr_udp_sess_used == RX_BURST_MAX + 1);
|
||||
EXPECT_TRUE(stat->nr_udp_sess_opening == RX_BURST_MAX);
|
||||
@@ -169,8 +166,7 @@ TEST(UDP_OVERLOAD, EVICT_NEW_SESS)
|
||||
EXPECT_TRUE(session_manager_new_session(mgr, &pkt, 1));
|
||||
}
|
||||
printf("=> Session Manager: after add %lu new sessions\n", opts.max_udp_session_num);
|
||||
session_manager_print_stat(mgr);
|
||||
stat = session_manager_get_stat(mgr);
|
||||
stat = session_manager_stat(mgr);
|
||||
EXPECT_TRUE(stat);
|
||||
EXPECT_TRUE(stat->nr_udp_sess_used == opts.max_udp_session_num);
|
||||
EXPECT_TRUE(stat->nr_udp_sess_opening == opts.max_udp_session_num);
|
||||
@@ -192,8 +188,7 @@ TEST(UDP_OVERLOAD, EVICT_NEW_SESS)
|
||||
EXPECT_TRUE(session_manager_new_session(mgr, &pkt, 1) == NULL);
|
||||
}
|
||||
printf("=> Session Manager: after readd %d evicted session\n", RX_BURST_MAX);
|
||||
session_manager_print_stat(mgr);
|
||||
stat = session_manager_get_stat(mgr);
|
||||
stat = session_manager_stat(mgr);
|
||||
EXPECT_TRUE(stat);
|
||||
EXPECT_TRUE(stat->nr_udp_sess_used == opts.max_udp_session_num);
|
||||
EXPECT_TRUE(stat->nr_udp_sess_opening == opts.max_udp_session_num);
|
||||
|
||||
@@ -135,8 +135,7 @@ TEST(TCP_ACTIVE_TO_CLOSING, BY_FIN_FIN)
|
||||
session_print(sess);
|
||||
|
||||
// check stat
|
||||
session_manager_print_stat(mgr);
|
||||
stat = session_manager_get_stat(mgr);
|
||||
stat = session_manager_stat(mgr);
|
||||
EXPECT_TRUE(stat);
|
||||
EXPECT_TRUE(stat->nr_tcp_sess_used == 1);
|
||||
EXPECT_TRUE(stat->nr_tcp_sess_opening == 0);
|
||||
@@ -153,8 +152,7 @@ TEST(TCP_ACTIVE_TO_CLOSING, BY_FIN_FIN)
|
||||
session_manager_free_session(mgr, sess);
|
||||
|
||||
// check stat
|
||||
session_manager_print_stat(mgr);
|
||||
stat = session_manager_get_stat(mgr);
|
||||
stat = session_manager_stat(mgr);
|
||||
EXPECT_TRUE(stat);
|
||||
EXPECT_TRUE(stat->nr_tcp_sess_used == 0);
|
||||
EXPECT_TRUE(stat->nr_tcp_sess_opening == 0);
|
||||
@@ -223,8 +221,7 @@ TEST(TCP_ACTIVE_TO_CLOSING, BY_C2S_RST)
|
||||
session_print(sess);
|
||||
|
||||
// check stat
|
||||
session_manager_print_stat(mgr);
|
||||
stat = session_manager_get_stat(mgr);
|
||||
stat = session_manager_stat(mgr);
|
||||
EXPECT_TRUE(stat);
|
||||
EXPECT_TRUE(stat->nr_tcp_sess_used == 1);
|
||||
EXPECT_TRUE(stat->nr_tcp_sess_opening == 0);
|
||||
@@ -241,8 +238,7 @@ TEST(TCP_ACTIVE_TO_CLOSING, BY_C2S_RST)
|
||||
session_manager_free_session(mgr, sess);
|
||||
|
||||
// check stat
|
||||
session_manager_print_stat(mgr);
|
||||
stat = session_manager_get_stat(mgr);
|
||||
stat = session_manager_stat(mgr);
|
||||
EXPECT_TRUE(stat);
|
||||
EXPECT_TRUE(stat->nr_tcp_sess_used == 0);
|
||||
EXPECT_TRUE(stat->nr_tcp_sess_opening == 0);
|
||||
@@ -311,8 +307,7 @@ TEST(TCP_ACTIVE_TO_CLOSING, BY_S2C_RST)
|
||||
session_print(sess);
|
||||
|
||||
// check stat
|
||||
session_manager_print_stat(mgr);
|
||||
stat = session_manager_get_stat(mgr);
|
||||
stat = session_manager_stat(mgr);
|
||||
EXPECT_TRUE(stat);
|
||||
EXPECT_TRUE(stat->nr_tcp_sess_used == 1);
|
||||
EXPECT_TRUE(stat->nr_tcp_sess_opening == 0);
|
||||
@@ -329,8 +324,7 @@ TEST(TCP_ACTIVE_TO_CLOSING, BY_S2C_RST)
|
||||
session_manager_free_session(mgr, sess);
|
||||
|
||||
// check stat
|
||||
session_manager_print_stat(mgr);
|
||||
stat = session_manager_get_stat(mgr);
|
||||
stat = session_manager_stat(mgr);
|
||||
EXPECT_TRUE(stat);
|
||||
EXPECT_TRUE(stat->nr_tcp_sess_used == 0);
|
||||
EXPECT_TRUE(stat->nr_tcp_sess_opening == 0);
|
||||
@@ -359,8 +353,7 @@ TEST(TCP_ACTIVE_TO_CLOSING, BY_DATA_TIMEOUT)
|
||||
build_active_tcp_session(mgr, sess);
|
||||
|
||||
// check stat
|
||||
session_manager_print_stat(mgr);
|
||||
stat = session_manager_get_stat(mgr);
|
||||
stat = session_manager_stat(mgr);
|
||||
EXPECT_TRUE(stat);
|
||||
EXPECT_TRUE(stat->nr_tcp_sess_used == 1);
|
||||
EXPECT_TRUE(stat->nr_tcp_sess_opening == 0);
|
||||
@@ -378,8 +371,7 @@ TEST(TCP_ACTIVE_TO_CLOSING, BY_DATA_TIMEOUT)
|
||||
session_manager_free_session(mgr, sess);
|
||||
|
||||
// check stat
|
||||
session_manager_print_stat(mgr);
|
||||
stat = session_manager_get_stat(mgr);
|
||||
stat = session_manager_stat(mgr);
|
||||
EXPECT_TRUE(stat);
|
||||
EXPECT_TRUE(stat->nr_tcp_sess_used == 0);
|
||||
EXPECT_TRUE(stat->nr_tcp_sess_opening == 0);
|
||||
@@ -441,8 +433,7 @@ TEST(TCP_ACTIVE_TO_CLOSING, BY_C2S_HALF_CLOSED_TIMEOUT)
|
||||
session_print(sess);
|
||||
|
||||
// check stat
|
||||
session_manager_print_stat(mgr);
|
||||
stat = session_manager_get_stat(mgr);
|
||||
stat = session_manager_stat(mgr);
|
||||
EXPECT_TRUE(stat);
|
||||
EXPECT_TRUE(stat->nr_tcp_sess_used == 1);
|
||||
EXPECT_TRUE(stat->nr_tcp_sess_opening == 0);
|
||||
@@ -459,8 +450,7 @@ TEST(TCP_ACTIVE_TO_CLOSING, BY_C2S_HALF_CLOSED_TIMEOUT)
|
||||
session_manager_free_session(mgr, sess);
|
||||
|
||||
// check stat
|
||||
session_manager_print_stat(mgr);
|
||||
stat = session_manager_get_stat(mgr);
|
||||
stat = session_manager_stat(mgr);
|
||||
EXPECT_TRUE(stat);
|
||||
EXPECT_TRUE(stat->nr_tcp_sess_used == 0);
|
||||
EXPECT_TRUE(stat->nr_tcp_sess_opening == 0);
|
||||
@@ -522,8 +512,7 @@ TEST(TCP_ACTIVE_TO_CLOSING, BY_S2C_HALF_CLOSED_TIMEOUT)
|
||||
session_print(sess);
|
||||
|
||||
// check stat
|
||||
session_manager_print_stat(mgr);
|
||||
stat = session_manager_get_stat(mgr);
|
||||
stat = session_manager_stat(mgr);
|
||||
EXPECT_TRUE(stat);
|
||||
EXPECT_TRUE(stat->nr_tcp_sess_used == 1);
|
||||
EXPECT_TRUE(stat->nr_tcp_sess_opening == 0);
|
||||
@@ -540,8 +529,7 @@ TEST(TCP_ACTIVE_TO_CLOSING, BY_S2C_HALF_CLOSED_TIMEOUT)
|
||||
session_manager_free_session(mgr, sess);
|
||||
|
||||
// check stat
|
||||
session_manager_print_stat(mgr);
|
||||
stat = session_manager_get_stat(mgr);
|
||||
stat = session_manager_stat(mgr);
|
||||
EXPECT_TRUE(stat);
|
||||
EXPECT_TRUE(stat->nr_tcp_sess_used == 0);
|
||||
EXPECT_TRUE(stat->nr_tcp_sess_opening == 0);
|
||||
|
||||
@@ -94,8 +94,7 @@ TEST(TCP_INIT_TO_OPENING, BY_SYN)
|
||||
session_print(sess);
|
||||
|
||||
// check stat
|
||||
session_manager_print_stat(mgr);
|
||||
stat = session_manager_get_stat(mgr);
|
||||
stat = session_manager_stat(mgr);
|
||||
EXPECT_TRUE(stat);
|
||||
EXPECT_TRUE(stat->nr_tcp_sess_used == 1);
|
||||
EXPECT_TRUE(stat->nr_tcp_sess_opening == 1);
|
||||
@@ -113,8 +112,7 @@ TEST(TCP_INIT_TO_OPENING, BY_SYN)
|
||||
session_manager_free_session(mgr, sess);
|
||||
|
||||
// check stat
|
||||
session_manager_print_stat(mgr);
|
||||
stat = session_manager_get_stat(mgr);
|
||||
stat = session_manager_stat(mgr);
|
||||
EXPECT_TRUE(stat);
|
||||
EXPECT_TRUE(stat->nr_tcp_sess_used == 0);
|
||||
EXPECT_TRUE(stat->nr_tcp_sess_opening == 0);
|
||||
@@ -173,8 +171,7 @@ TEST(TCP_INIT_TO_OPENING, BY_SYNACK)
|
||||
session_print(sess);
|
||||
|
||||
// check stat
|
||||
session_manager_print_stat(mgr);
|
||||
stat = session_manager_get_stat(mgr);
|
||||
stat = session_manager_stat(mgr);
|
||||
EXPECT_TRUE(stat);
|
||||
EXPECT_TRUE(stat->nr_tcp_sess_used == 1);
|
||||
EXPECT_TRUE(stat->nr_tcp_sess_opening == 1);
|
||||
@@ -192,8 +189,7 @@ TEST(TCP_INIT_TO_OPENING, BY_SYNACK)
|
||||
session_manager_free_session(mgr, sess);
|
||||
|
||||
// check stat
|
||||
session_manager_print_stat(mgr);
|
||||
stat = session_manager_get_stat(mgr);
|
||||
stat = session_manager_stat(mgr);
|
||||
EXPECT_TRUE(stat);
|
||||
EXPECT_TRUE(stat->nr_tcp_sess_used == 0);
|
||||
EXPECT_TRUE(stat->nr_tcp_sess_opening == 0);
|
||||
@@ -263,8 +259,7 @@ TEST(TCP_INIT_TO_OPENING, BY_SYN_SYNACK)
|
||||
session_print(sess);
|
||||
|
||||
// check stat
|
||||
session_manager_print_stat(mgr);
|
||||
stat = session_manager_get_stat(mgr);
|
||||
stat = session_manager_stat(mgr);
|
||||
EXPECT_TRUE(stat);
|
||||
EXPECT_TRUE(stat->nr_tcp_sess_used == 1);
|
||||
EXPECT_TRUE(stat->nr_tcp_sess_opening == 1);
|
||||
@@ -282,8 +277,7 @@ TEST(TCP_INIT_TO_OPENING, BY_SYN_SYNACK)
|
||||
session_manager_free_session(mgr, sess);
|
||||
|
||||
// check stat
|
||||
session_manager_print_stat(mgr);
|
||||
stat = session_manager_get_stat(mgr);
|
||||
stat = session_manager_stat(mgr);
|
||||
EXPECT_TRUE(stat);
|
||||
EXPECT_TRUE(stat->nr_tcp_sess_used == 0);
|
||||
EXPECT_TRUE(stat->nr_tcp_sess_opening == 0);
|
||||
@@ -364,8 +358,7 @@ TEST(TCP_INIT_TO_OPENING, BY_SYN_SYNACK_ACK)
|
||||
session_print(sess);
|
||||
|
||||
// check stat
|
||||
session_manager_print_stat(mgr);
|
||||
stat = session_manager_get_stat(mgr);
|
||||
stat = session_manager_stat(mgr);
|
||||
EXPECT_TRUE(stat);
|
||||
EXPECT_TRUE(stat->nr_tcp_sess_used == 1);
|
||||
EXPECT_TRUE(stat->nr_tcp_sess_opening == 1);
|
||||
@@ -383,8 +376,7 @@ TEST(TCP_INIT_TO_OPENING, BY_SYN_SYNACK_ACK)
|
||||
session_manager_free_session(mgr, sess);
|
||||
|
||||
// check stat
|
||||
session_manager_print_stat(mgr);
|
||||
stat = session_manager_get_stat(mgr);
|
||||
stat = session_manager_stat(mgr);
|
||||
EXPECT_TRUE(stat);
|
||||
EXPECT_TRUE(stat->nr_tcp_sess_used == 0);
|
||||
EXPECT_TRUE(stat->nr_tcp_sess_opening == 0);
|
||||
@@ -461,8 +453,7 @@ TEST(TCP_INIT_TO_OPENING, BY_SYN_RETRANSMISSION)
|
||||
session_print(sess);
|
||||
|
||||
// check stat
|
||||
session_manager_print_stat(mgr);
|
||||
stat = session_manager_get_stat(mgr);
|
||||
stat = session_manager_stat(mgr);
|
||||
EXPECT_TRUE(stat);
|
||||
EXPECT_TRUE(stat->nr_tcp_sess_used == 1);
|
||||
EXPECT_TRUE(stat->nr_tcp_sess_opening == 1);
|
||||
@@ -480,8 +471,7 @@ TEST(TCP_INIT_TO_OPENING, BY_SYN_RETRANSMISSION)
|
||||
session_manager_free_session(mgr, sess);
|
||||
|
||||
// check stat
|
||||
session_manager_print_stat(mgr);
|
||||
stat = session_manager_get_stat(mgr);
|
||||
stat = session_manager_stat(mgr);
|
||||
EXPECT_TRUE(stat);
|
||||
EXPECT_TRUE(stat->nr_tcp_sess_used == 0);
|
||||
EXPECT_TRUE(stat->nr_tcp_sess_opening == 0);
|
||||
@@ -559,8 +549,7 @@ TEST(TCP_INIT_TO_OPENING, BY_SYNACK_RETRANSMISSION)
|
||||
session_print(sess);
|
||||
|
||||
// check stat
|
||||
session_manager_print_stat(mgr);
|
||||
stat = session_manager_get_stat(mgr);
|
||||
stat = session_manager_stat(mgr);
|
||||
EXPECT_TRUE(stat);
|
||||
EXPECT_TRUE(stat->nr_tcp_sess_used == 1);
|
||||
EXPECT_TRUE(stat->nr_tcp_sess_opening == 1);
|
||||
@@ -578,8 +567,7 @@ TEST(TCP_INIT_TO_OPENING, BY_SYNACK_RETRANSMISSION)
|
||||
session_manager_free_session(mgr, sess);
|
||||
|
||||
// check stat
|
||||
session_manager_print_stat(mgr);
|
||||
stat = session_manager_get_stat(mgr);
|
||||
stat = session_manager_stat(mgr);
|
||||
EXPECT_TRUE(stat);
|
||||
EXPECT_TRUE(stat->nr_tcp_sess_used == 0);
|
||||
EXPECT_TRUE(stat->nr_tcp_sess_opening == 0);
|
||||
@@ -649,8 +637,7 @@ TEST(TCP_INIT_TO_OPENING, BY_C2S_ASMMETRIC)
|
||||
session_print(sess);
|
||||
|
||||
// check stat
|
||||
session_manager_print_stat(mgr);
|
||||
stat = session_manager_get_stat(mgr);
|
||||
stat = session_manager_stat(mgr);
|
||||
EXPECT_TRUE(stat);
|
||||
EXPECT_TRUE(stat->nr_tcp_sess_used == 1);
|
||||
EXPECT_TRUE(stat->nr_tcp_sess_opening == 1);
|
||||
@@ -668,8 +655,7 @@ TEST(TCP_INIT_TO_OPENING, BY_C2S_ASMMETRIC)
|
||||
session_manager_free_session(mgr, sess);
|
||||
|
||||
// check stat
|
||||
session_manager_print_stat(mgr);
|
||||
stat = session_manager_get_stat(mgr);
|
||||
stat = session_manager_stat(mgr);
|
||||
EXPECT_TRUE(stat);
|
||||
EXPECT_TRUE(stat->nr_tcp_sess_used == 0);
|
||||
EXPECT_TRUE(stat->nr_tcp_sess_opening == 0);
|
||||
@@ -739,8 +725,7 @@ TEST(TCP_INIT_TO_OPENING, BY_S2C_ASMMETRIC)
|
||||
session_print(sess);
|
||||
|
||||
// check stat
|
||||
session_manager_print_stat(mgr);
|
||||
stat = session_manager_get_stat(mgr);
|
||||
stat = session_manager_stat(mgr);
|
||||
EXPECT_TRUE(stat);
|
||||
EXPECT_TRUE(stat->nr_tcp_sess_used == 1);
|
||||
EXPECT_TRUE(stat->nr_tcp_sess_opening == 1);
|
||||
@@ -758,8 +743,7 @@ TEST(TCP_INIT_TO_OPENING, BY_S2C_ASMMETRIC)
|
||||
session_manager_free_session(mgr, sess);
|
||||
|
||||
// check stat
|
||||
session_manager_print_stat(mgr);
|
||||
stat = session_manager_get_stat(mgr);
|
||||
stat = session_manager_stat(mgr);
|
||||
EXPECT_TRUE(stat);
|
||||
EXPECT_TRUE(stat->nr_tcp_sess_used == 0);
|
||||
EXPECT_TRUE(stat->nr_tcp_sess_opening == 0);
|
||||
|
||||
@@ -399,8 +399,7 @@ TEST(TCP_INIT_TO_OPENING_TO_ACTIVE_TO_CLOSING_TO_CLOSED, TEST)
|
||||
EXPECT_TRUE(session_get_1st_packet(sess, SESSION_DIRECTION_S2C) != NULL);
|
||||
|
||||
// check stat
|
||||
session_manager_print_stat(mgr);
|
||||
stat = session_manager_get_stat(mgr);
|
||||
stat = session_manager_stat(mgr);
|
||||
EXPECT_TRUE(stat);
|
||||
EXPECT_TRUE(stat->nr_tcp_sess_used == 1);
|
||||
EXPECT_TRUE(stat->nr_tcp_sess_opening == 0);
|
||||
@@ -417,8 +416,7 @@ TEST(TCP_INIT_TO_OPENING_TO_ACTIVE_TO_CLOSING_TO_CLOSED, TEST)
|
||||
session_manager_free_session(mgr, sess);
|
||||
|
||||
// check stat
|
||||
session_manager_print_stat(mgr);
|
||||
stat = session_manager_get_stat(mgr);
|
||||
stat = session_manager_stat(mgr);
|
||||
EXPECT_TRUE(stat);
|
||||
EXPECT_TRUE(stat->nr_tcp_sess_used == 0);
|
||||
EXPECT_TRUE(stat->nr_tcp_sess_opening == 0);
|
||||
|
||||
@@ -104,8 +104,7 @@ TEST(TCP_OPENING_TO_ACTIVE, BY_SYN_C2S_DATA)
|
||||
session_print(sess);
|
||||
|
||||
// check stat
|
||||
session_manager_print_stat(mgr);
|
||||
stat = session_manager_get_stat(mgr);
|
||||
stat = session_manager_stat(mgr);
|
||||
EXPECT_TRUE(stat);
|
||||
EXPECT_TRUE(stat->nr_tcp_sess_used == 1);
|
||||
EXPECT_TRUE(stat->nr_tcp_sess_opening == 0);
|
||||
@@ -123,8 +122,7 @@ TEST(TCP_OPENING_TO_ACTIVE, BY_SYN_C2S_DATA)
|
||||
session_manager_free_session(mgr, sess);
|
||||
|
||||
// check stat
|
||||
session_manager_print_stat(mgr);
|
||||
stat = session_manager_get_stat(mgr);
|
||||
stat = session_manager_stat(mgr);
|
||||
EXPECT_TRUE(stat);
|
||||
EXPECT_TRUE(stat->nr_tcp_sess_used == 0);
|
||||
EXPECT_TRUE(stat->nr_tcp_sess_opening == 0);
|
||||
@@ -194,8 +192,7 @@ TEST(TCP_OPENING_TO_ACTIVE, BY_SYNACK_S2C_DATA)
|
||||
session_print(sess);
|
||||
|
||||
// check stat
|
||||
session_manager_print_stat(mgr);
|
||||
stat = session_manager_get_stat(mgr);
|
||||
stat = session_manager_stat(mgr);
|
||||
EXPECT_TRUE(stat);
|
||||
EXPECT_TRUE(stat->nr_tcp_sess_used == 1);
|
||||
EXPECT_TRUE(stat->nr_tcp_sess_opening == 0);
|
||||
@@ -213,8 +210,7 @@ TEST(TCP_OPENING_TO_ACTIVE, BY_SYNACK_S2C_DATA)
|
||||
session_manager_free_session(mgr, sess);
|
||||
|
||||
// check stat
|
||||
session_manager_print_stat(mgr);
|
||||
stat = session_manager_get_stat(mgr);
|
||||
stat = session_manager_stat(mgr);
|
||||
EXPECT_TRUE(stat);
|
||||
EXPECT_TRUE(stat->nr_tcp_sess_used == 0);
|
||||
EXPECT_TRUE(stat->nr_tcp_sess_opening == 0);
|
||||
|
||||
@@ -116,8 +116,7 @@ TEST(TCP_OPENING_TO_CLOSING, BY_FIN_FIN)
|
||||
session_print(sess);
|
||||
|
||||
// check stat
|
||||
session_manager_print_stat(mgr);
|
||||
stat = session_manager_get_stat(mgr);
|
||||
stat = session_manager_stat(mgr);
|
||||
EXPECT_TRUE(stat);
|
||||
EXPECT_TRUE(stat->nr_tcp_sess_used == 1);
|
||||
EXPECT_TRUE(stat->nr_tcp_sess_opening == 0);
|
||||
@@ -134,8 +133,7 @@ TEST(TCP_OPENING_TO_CLOSING, BY_FIN_FIN)
|
||||
session_manager_free_session(mgr, sess);
|
||||
|
||||
// check stat
|
||||
session_manager_print_stat(mgr);
|
||||
stat = session_manager_get_stat(mgr);
|
||||
stat = session_manager_stat(mgr);
|
||||
EXPECT_TRUE(stat);
|
||||
EXPECT_TRUE(stat->nr_tcp_sess_used == 0);
|
||||
EXPECT_TRUE(stat->nr_tcp_sess_opening == 0);
|
||||
@@ -212,8 +210,7 @@ TEST(TCP_OPENING_TO_CLOSING, BY_C2S_RST)
|
||||
session_print(sess);
|
||||
|
||||
// check stat
|
||||
session_manager_print_stat(mgr);
|
||||
stat = session_manager_get_stat(mgr);
|
||||
stat = session_manager_stat(mgr);
|
||||
EXPECT_TRUE(stat);
|
||||
EXPECT_TRUE(stat->nr_tcp_sess_used == 1);
|
||||
EXPECT_TRUE(stat->nr_tcp_sess_opening == 0);
|
||||
@@ -230,8 +227,7 @@ TEST(TCP_OPENING_TO_CLOSING, BY_C2S_RST)
|
||||
session_manager_free_session(mgr, sess);
|
||||
|
||||
// check stat
|
||||
session_manager_print_stat(mgr);
|
||||
stat = session_manager_get_stat(mgr);
|
||||
stat = session_manager_stat(mgr);
|
||||
EXPECT_TRUE(stat);
|
||||
EXPECT_TRUE(stat->nr_tcp_sess_used == 0);
|
||||
EXPECT_TRUE(stat->nr_tcp_sess_opening == 0);
|
||||
@@ -308,8 +304,7 @@ TEST(TCP_OPENING_TO_CLOSING, BY_S2C_RST)
|
||||
session_print(sess);
|
||||
|
||||
// check stat
|
||||
session_manager_print_stat(mgr);
|
||||
stat = session_manager_get_stat(mgr);
|
||||
stat = session_manager_stat(mgr);
|
||||
EXPECT_TRUE(stat);
|
||||
EXPECT_TRUE(stat->nr_tcp_sess_used == 1);
|
||||
EXPECT_TRUE(stat->nr_tcp_sess_opening == 0);
|
||||
@@ -326,8 +321,7 @@ TEST(TCP_OPENING_TO_CLOSING, BY_S2C_RST)
|
||||
session_manager_free_session(mgr, sess);
|
||||
|
||||
// check stat
|
||||
session_manager_print_stat(mgr);
|
||||
stat = session_manager_get_stat(mgr);
|
||||
stat = session_manager_stat(mgr);
|
||||
EXPECT_TRUE(stat);
|
||||
EXPECT_TRUE(stat->nr_tcp_sess_used == 0);
|
||||
EXPECT_TRUE(stat->nr_tcp_sess_opening == 0);
|
||||
@@ -365,8 +359,7 @@ TEST(TCP_OPENING_TO_CLOSING, BY_INIT_TIMEOUT)
|
||||
EXPECT_TRUE(sess);
|
||||
|
||||
// check stat
|
||||
session_manager_print_stat(mgr);
|
||||
stat = session_manager_get_stat(mgr);
|
||||
stat = session_manager_stat(mgr);
|
||||
EXPECT_TRUE(stat);
|
||||
EXPECT_TRUE(stat->nr_tcp_sess_used == 1);
|
||||
EXPECT_TRUE(stat->nr_tcp_sess_opening == 1);
|
||||
@@ -384,8 +377,7 @@ TEST(TCP_OPENING_TO_CLOSING, BY_INIT_TIMEOUT)
|
||||
session_manager_free_session(mgr, sess);
|
||||
|
||||
// check stat
|
||||
session_manager_print_stat(mgr);
|
||||
stat = session_manager_get_stat(mgr);
|
||||
stat = session_manager_stat(mgr);
|
||||
EXPECT_TRUE(stat);
|
||||
EXPECT_TRUE(stat->nr_tcp_sess_used == 0);
|
||||
EXPECT_TRUE(stat->nr_tcp_sess_opening == 0);
|
||||
@@ -455,8 +447,7 @@ TEST(TCP_OPENING_TO_CLOSING, BY_HANDSHAKE_TIMEOUT)
|
||||
session_print(sess);
|
||||
|
||||
// check stat
|
||||
session_manager_print_stat(mgr);
|
||||
stat = session_manager_get_stat(mgr);
|
||||
stat = session_manager_stat(mgr);
|
||||
EXPECT_TRUE(stat);
|
||||
EXPECT_TRUE(stat->nr_tcp_sess_used == 1);
|
||||
EXPECT_TRUE(stat->nr_tcp_sess_opening == 1);
|
||||
@@ -474,8 +465,7 @@ TEST(TCP_OPENING_TO_CLOSING, BY_HANDSHAKE_TIMEOUT)
|
||||
session_manager_free_session(mgr, sess);
|
||||
|
||||
// check stat
|
||||
session_manager_print_stat(mgr);
|
||||
stat = session_manager_get_stat(mgr);
|
||||
stat = session_manager_stat(mgr);
|
||||
EXPECT_TRUE(stat);
|
||||
EXPECT_TRUE(stat->nr_tcp_sess_used == 0);
|
||||
EXPECT_TRUE(stat->nr_tcp_sess_opening == 0);
|
||||
@@ -556,8 +546,7 @@ TEST(TCP_OPENING_TO_CLOSING, BY_DATA_TIMEOUT)
|
||||
session_print(sess);
|
||||
|
||||
// check stat
|
||||
session_manager_print_stat(mgr);
|
||||
stat = session_manager_get_stat(mgr);
|
||||
stat = session_manager_stat(mgr);
|
||||
EXPECT_TRUE(stat);
|
||||
EXPECT_TRUE(stat->nr_tcp_sess_used == 1);
|
||||
EXPECT_TRUE(stat->nr_tcp_sess_opening == 1);
|
||||
@@ -575,8 +564,7 @@ TEST(TCP_OPENING_TO_CLOSING, BY_DATA_TIMEOUT)
|
||||
session_manager_free_session(mgr, sess);
|
||||
|
||||
// check stat
|
||||
session_manager_print_stat(mgr);
|
||||
stat = session_manager_get_stat(mgr);
|
||||
stat = session_manager_stat(mgr);
|
||||
EXPECT_TRUE(stat);
|
||||
EXPECT_TRUE(stat->nr_tcp_sess_used == 0);
|
||||
EXPECT_TRUE(stat->nr_tcp_sess_opening == 0);
|
||||
@@ -646,8 +634,7 @@ TEST(TCP_OPENING_TO_CLOSING, BY_C2S_HALF_FIN)
|
||||
session_print(sess);
|
||||
|
||||
// check stat
|
||||
session_manager_print_stat(mgr);
|
||||
stat = session_manager_get_stat(mgr);
|
||||
stat = session_manager_stat(mgr);
|
||||
EXPECT_TRUE(stat);
|
||||
EXPECT_TRUE(stat->nr_tcp_sess_used == 1);
|
||||
EXPECT_TRUE(stat->nr_tcp_sess_opening == 0);
|
||||
@@ -664,8 +651,7 @@ TEST(TCP_OPENING_TO_CLOSING, BY_C2S_HALF_FIN)
|
||||
session_manager_free_session(mgr, sess);
|
||||
|
||||
// check stat
|
||||
session_manager_print_stat(mgr);
|
||||
stat = session_manager_get_stat(mgr);
|
||||
stat = session_manager_stat(mgr);
|
||||
EXPECT_TRUE(stat);
|
||||
EXPECT_TRUE(stat->nr_tcp_sess_used == 0);
|
||||
EXPECT_TRUE(stat->nr_tcp_sess_opening == 0);
|
||||
@@ -735,8 +721,7 @@ TEST(TCP_OPENING_TO_CLOSING, BY_S2C_HALF_FIN)
|
||||
session_print(sess);
|
||||
|
||||
// check stat
|
||||
session_manager_print_stat(mgr);
|
||||
stat = session_manager_get_stat(mgr);
|
||||
stat = session_manager_stat(mgr);
|
||||
EXPECT_TRUE(stat);
|
||||
EXPECT_TRUE(stat->nr_tcp_sess_used == 1);
|
||||
EXPECT_TRUE(stat->nr_tcp_sess_opening == 0);
|
||||
@@ -753,8 +738,7 @@ TEST(TCP_OPENING_TO_CLOSING, BY_S2C_HALF_FIN)
|
||||
session_manager_free_session(mgr, sess);
|
||||
|
||||
// check stat
|
||||
session_manager_print_stat(mgr);
|
||||
stat = session_manager_get_stat(mgr);
|
||||
stat = session_manager_stat(mgr);
|
||||
EXPECT_TRUE(stat);
|
||||
EXPECT_TRUE(stat->nr_tcp_sess_used == 0);
|
||||
EXPECT_TRUE(stat->nr_tcp_sess_opening == 0);
|
||||
|
||||
@@ -119,8 +119,7 @@ TEST(UDP_INIT_TO_OPENING_TO_ACTIVE_TO_CLOSING, TEST)
|
||||
session_print(sess);
|
||||
|
||||
// check stat
|
||||
session_manager_print_stat(mgr);
|
||||
stat = session_manager_get_stat(mgr);
|
||||
stat = session_manager_stat(mgr);
|
||||
EXPECT_TRUE(stat);
|
||||
EXPECT_TRUE(stat->nr_udp_sess_used == 1);
|
||||
EXPECT_TRUE(stat->nr_udp_sess_opening == 0);
|
||||
@@ -138,8 +137,7 @@ TEST(UDP_INIT_TO_OPENING_TO_ACTIVE_TO_CLOSING, TEST)
|
||||
session_manager_free_session(mgr, sess);
|
||||
|
||||
// check stat
|
||||
session_manager_print_stat(mgr);
|
||||
stat = session_manager_get_stat(mgr);
|
||||
stat = session_manager_stat(mgr);
|
||||
EXPECT_TRUE(stat);
|
||||
EXPECT_TRUE(stat->nr_udp_sess_used == 0);
|
||||
EXPECT_TRUE(stat->nr_udp_sess_opening == 0);
|
||||
|
||||
@@ -94,8 +94,7 @@ TEST(UDP_INIT_TO_OPENING_TO_CLOSING, BY_C2S)
|
||||
session_print(sess);
|
||||
|
||||
// check stat
|
||||
session_manager_print_stat(mgr);
|
||||
stat = session_manager_get_stat(mgr);
|
||||
stat = session_manager_stat(mgr);
|
||||
EXPECT_TRUE(stat);
|
||||
EXPECT_TRUE(stat->nr_udp_sess_used == 1);
|
||||
EXPECT_TRUE(stat->nr_udp_sess_opening == 1);
|
||||
@@ -113,8 +112,7 @@ TEST(UDP_INIT_TO_OPENING_TO_CLOSING, BY_C2S)
|
||||
session_manager_free_session(mgr, sess);
|
||||
|
||||
// check stat
|
||||
session_manager_print_stat(mgr);
|
||||
stat = session_manager_get_stat(mgr);
|
||||
stat = session_manager_stat(mgr);
|
||||
EXPECT_TRUE(stat);
|
||||
EXPECT_TRUE(stat->nr_udp_sess_used == 0);
|
||||
EXPECT_TRUE(stat->nr_udp_sess_opening == 0);
|
||||
@@ -174,8 +172,7 @@ TEST(UDP_INIT_TO_OPENING_TO_CLOSING, BY_S2C)
|
||||
session_print(sess);
|
||||
|
||||
// check stat
|
||||
session_manager_print_stat(mgr);
|
||||
stat = session_manager_get_stat(mgr);
|
||||
stat = session_manager_stat(mgr);
|
||||
EXPECT_TRUE(stat);
|
||||
EXPECT_TRUE(stat->nr_udp_sess_used == 1);
|
||||
EXPECT_TRUE(stat->nr_udp_sess_opening == 1);
|
||||
@@ -195,8 +192,7 @@ TEST(UDP_INIT_TO_OPENING_TO_CLOSING, BY_S2C)
|
||||
session_manager_free_session(mgr, sess);
|
||||
|
||||
// check stat
|
||||
session_manager_print_stat(mgr);
|
||||
stat = session_manager_get_stat(mgr);
|
||||
stat = session_manager_stat(mgr);
|
||||
EXPECT_TRUE(stat);
|
||||
EXPECT_TRUE(stat->nr_udp_sess_used == 0);
|
||||
EXPECT_TRUE(stat->nr_udp_sess_opening == 0);
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
add_executable(stellar stellar.cpp stat.cpp cron.cpp)
|
||||
target_link_libraries(stellar timestamp session_manager plugin_manager pthread config packet_io fieldstat4)
|
||||
add_executable(stellar config.cpp stat.cpp stellar.cpp)
|
||||
target_link_libraries(stellar timestamp plugin_manager session_manager ip_reassembly packet_io)
|
||||
target_link_libraries(stellar pthread fieldstat4 toml)
|
||||
|
||||
install(TARGETS stellar RUNTIME DESTINATION bin COMPONENT Program)
|
||||
@@ -403,7 +403,7 @@ static int parse_session_manager_section(toml_table_t *root, struct session_mana
|
||||
|
||||
// return 0: success
|
||||
// retuun -1: failed
|
||||
int stellar_config_load(const char *file, struct stellar_config *config)
|
||||
int stellar_load_config(const char *file, struct stellar_config *config)
|
||||
{
|
||||
int ret = -1;
|
||||
char errbuf[200];
|
||||
@@ -461,7 +461,7 @@ error_out:
|
||||
return ret;
|
||||
}
|
||||
|
||||
void stellar_config_print(struct stellar_config *config)
|
||||
void stellar_print_config(struct stellar_config *config)
|
||||
{
|
||||
if (config == NULL)
|
||||
{
|
||||
@@ -27,8 +27,8 @@ struct stellar_config
|
||||
struct session_manager_options sess_mgr_opts;
|
||||
};
|
||||
|
||||
int stellar_config_load(const char *file, struct stellar_config *config);
|
||||
void stellar_config_print(struct stellar_config *config);
|
||||
int stellar_load_config(const char *file, struct stellar_config *config);
|
||||
void stellar_print_config(struct stellar_config *config);
|
||||
|
||||
#ifdef __cpluscplus
|
||||
}
|
||||
@@ -1,69 +0,0 @@
|
||||
#include "cron.h"
|
||||
|
||||
#ifndef container_of
|
||||
#define container_of(ptr, type, member) \
|
||||
(type *)((char *)(ptr) - (char *)&((type *)0)->member)
|
||||
#endif
|
||||
|
||||
struct thread_cron
|
||||
{
|
||||
struct timeouts *timeouts;
|
||||
};
|
||||
|
||||
struct thread_cron *thread_cron_new(uint64_t now)
|
||||
{
|
||||
timeout_error_t err;
|
||||
struct thread_cron *cron = (struct thread_cron *)calloc(1, sizeof(struct thread_cron));
|
||||
if (cron == NULL)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
cron->timeouts = timeouts_open(0, &err);
|
||||
if (cron->timeouts == NULL)
|
||||
{
|
||||
goto error_out;
|
||||
}
|
||||
timeouts_update(cron->timeouts, now);
|
||||
|
||||
return cron;
|
||||
|
||||
error_out:
|
||||
thread_cron_free(cron);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void thread_cron_free(struct thread_cron *cron)
|
||||
{
|
||||
if (cron)
|
||||
{
|
||||
if (cron->timeouts)
|
||||
{
|
||||
timeouts_close(cron->timeouts);
|
||||
}
|
||||
free(cron);
|
||||
cron = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
void thread_cron_run(struct thread_cron *cron, uint64_t now)
|
||||
{
|
||||
struct timeout *timeout;
|
||||
timeouts_update(cron->timeouts, now);
|
||||
while ((timeout = timeouts_get(cron->timeouts)))
|
||||
{
|
||||
struct cron_task *task = container_of(timeout, struct cron_task, timeout);
|
||||
task->callback(task->data);
|
||||
}
|
||||
}
|
||||
|
||||
void thread_cron_add_task(struct thread_cron *cron, struct cron_task *task)
|
||||
{
|
||||
timeout_init(&task->timeout, TIMEOUT_INT);
|
||||
timeouts_add(cron->timeouts, &task->timeout, task->cycle);
|
||||
}
|
||||
|
||||
void thread_cron_del_task(struct thread_cron *cron, struct cron_task *task)
|
||||
{
|
||||
timeouts_del(cron->timeouts, &task->timeout);
|
||||
}
|
||||
@@ -1,32 +0,0 @@
|
||||
#ifndef _CRON_H
|
||||
#define _CRON_H
|
||||
|
||||
#ifdef __cpluscplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
|
||||
#include <stdint.h>
|
||||
#include "timeout.h"
|
||||
|
||||
struct cron_task
|
||||
{
|
||||
struct timeout timeout;
|
||||
void (*callback)(void *);
|
||||
void *data;
|
||||
uint64_t cycle;
|
||||
};
|
||||
|
||||
struct thread_cron;
|
||||
struct thread_cron *thread_cron_new(uint64_t now);
|
||||
void thread_cron_free(struct thread_cron *cron);
|
||||
void thread_cron_run(struct thread_cron *cron, uint64_t now);
|
||||
|
||||
void thread_cron_add_task(struct thread_cron *cron, struct cron_task *task);
|
||||
void thread_cron_del_task(struct thread_cron *cron, struct cron_task *task);
|
||||
|
||||
#ifdef __cpluscplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@@ -80,6 +80,7 @@ struct stellar_stat
|
||||
// thread stat
|
||||
uint16_t nr_thread;
|
||||
int flag[MAX_THREAD_NUM]; // IS_FREE or IS_BUSY
|
||||
struct io_stat thr_io_stat[MAX_THREAD_NUM];
|
||||
struct ip_reassembly_stat thr_ip_stat[MAX_THREAD_NUM];
|
||||
struct session_manager_stat thr_sess_stat[MAX_THREAD_NUM];
|
||||
|
||||
@@ -196,6 +197,28 @@ void stellar_stat_output(struct stellar_stat *stat)
|
||||
{
|
||||
if (ATOMIC_READ(&(stat->flag[i])) == IS_BUSY)
|
||||
{
|
||||
// packet io stat
|
||||
stat->io_stat.dev_rx_pkts += stat->thr_io_stat[i].dev_rx_pkts;
|
||||
stat->io_stat.dev_rx_bytes += stat->thr_io_stat[i].dev_rx_bytes;
|
||||
|
||||
stat->io_stat.dev_tx_pkts += stat->thr_io_stat[i].dev_tx_pkts;
|
||||
stat->io_stat.dev_tx_bytes += stat->thr_io_stat[i].dev_tx_bytes;
|
||||
|
||||
stat->io_stat.keep_alive_pkts += stat->thr_io_stat[i].keep_alive_pkts;
|
||||
stat->io_stat.keep_alive_bytes += stat->thr_io_stat[i].keep_alive_bytes;
|
||||
|
||||
stat->io_stat.raw_rx_pkts += stat->thr_io_stat[i].raw_rx_pkts;
|
||||
stat->io_stat.raw_rx_bytes += stat->thr_io_stat[i].raw_rx_bytes;
|
||||
|
||||
stat->io_stat.raw_tx_pkts += stat->thr_io_stat[i].raw_tx_pkts;
|
||||
stat->io_stat.raw_tx_bytes += stat->thr_io_stat[i].raw_tx_bytes;
|
||||
|
||||
stat->io_stat.ctrl_rx_pkts += stat->thr_io_stat[i].ctrl_rx_pkts;
|
||||
stat->io_stat.ctrl_rx_bytes += stat->thr_io_stat[i].ctrl_rx_bytes;
|
||||
|
||||
stat->io_stat.ctrl_tx_pkts += stat->thr_io_stat[i].ctrl_tx_pkts;
|
||||
stat->io_stat.ctrl_tx_bytes += stat->thr_io_stat[i].ctrl_tx_bytes;
|
||||
|
||||
// ip reassembly stat
|
||||
stat->ip_stat.ip4_flow_find += stat->thr_ip_stat[i].ip4_flow_find;
|
||||
stat->ip_stat.ip4_flow_add += stat->thr_ip_stat[i].ip4_flow_add;
|
||||
@@ -339,34 +362,11 @@ void stellar_stat_output(struct stellar_stat *stat)
|
||||
memset(&stat->sess_stat, 0, sizeof(struct session_manager_stat));
|
||||
}
|
||||
|
||||
void stellar_peek_io_stat(struct stellar_stat *stat, const struct io_stat *pkt_io)
|
||||
{
|
||||
stat->io_stat.dev_rx_pkts += pkt_io->dev_rx_pkts;
|
||||
stat->io_stat.dev_rx_bytes += pkt_io->dev_rx_bytes;
|
||||
|
||||
stat->io_stat.dev_tx_pkts += pkt_io->dev_tx_pkts;
|
||||
stat->io_stat.dev_tx_bytes += pkt_io->dev_tx_bytes;
|
||||
|
||||
stat->io_stat.keep_alive_pkts += pkt_io->keep_alive_pkts;
|
||||
stat->io_stat.keep_alive_bytes += pkt_io->keep_alive_bytes;
|
||||
|
||||
stat->io_stat.raw_rx_pkts += pkt_io->raw_rx_pkts;
|
||||
stat->io_stat.raw_rx_bytes += pkt_io->raw_rx_bytes;
|
||||
|
||||
stat->io_stat.raw_tx_pkts += pkt_io->raw_tx_pkts;
|
||||
stat->io_stat.raw_tx_bytes += pkt_io->raw_tx_bytes;
|
||||
|
||||
stat->io_stat.ctrl_rx_pkts += pkt_io->ctrl_rx_pkts;
|
||||
stat->io_stat.ctrl_rx_bytes += pkt_io->ctrl_rx_bytes;
|
||||
|
||||
stat->io_stat.ctrl_tx_pkts += pkt_io->ctrl_tx_pkts;
|
||||
stat->io_stat.ctrl_tx_bytes += pkt_io->ctrl_tx_bytes;
|
||||
}
|
||||
|
||||
void stellar_peek_thr_stat(struct stellar_stat *stat, const struct thread_stat *thr_stat, uint16_t thr_idx)
|
||||
void stellar_stat_merge(struct stellar_stat *stat, const struct thread_stat *thr_stat, uint16_t thr_idx)
|
||||
{
|
||||
if (ATOMIC_READ(&(stat->flag[thr_idx])) == IS_FREE)
|
||||
{
|
||||
memcpy(&stat->thr_io_stat[thr_idx], thr_stat->io, sizeof(struct io_stat));
|
||||
memcpy(&stat->thr_ip_stat[thr_idx], thr_stat->ip_rea, sizeof(struct ip_reassembly_stat));
|
||||
memcpy(&stat->thr_sess_stat[thr_idx], thr_stat->sess_mgr, sizeof(struct session_manager_stat));
|
||||
|
||||
|
||||
@@ -14,6 +14,7 @@ extern "C"
|
||||
|
||||
struct thread_stat
|
||||
{
|
||||
struct io_stat *io;
|
||||
struct ip_reassembly_stat *ip_rea;
|
||||
struct session_manager_stat *sess_mgr;
|
||||
};
|
||||
@@ -22,9 +23,7 @@ struct stellar_stat;
|
||||
struct stellar_stat *stellar_stat_new(uint16_t nr_thread);
|
||||
void stellar_stat_free(struct stellar_stat *stat);
|
||||
void stellar_stat_output(struct stellar_stat *stat);
|
||||
|
||||
void stellar_peek_io_stat(struct stellar_stat *stat, const struct io_stat *io_stat);
|
||||
void stellar_peek_thr_stat(struct stellar_stat *stat, const struct thread_stat *thr_stat, uint16_t thr_idx);
|
||||
void stellar_stat_merge(struct stellar_stat *stat, const struct thread_stat *thr_stat, uint16_t thr_idx);
|
||||
|
||||
#ifdef __cpluscplus
|
||||
}
|
||||
|
||||
@@ -10,7 +10,6 @@
|
||||
|
||||
#include "logo.h"
|
||||
#include "stat.h"
|
||||
#include "cron.h"
|
||||
#include "stellar.h"
|
||||
#include "config.h"
|
||||
#include "packet_private.h"
|
||||
@@ -25,12 +24,13 @@
|
||||
#define STELLAR_LOG_ERROR(format, ...) LOG_ERROR("stellar", format, ##__VA_ARGS__)
|
||||
#define STELLAR_LOG_DEBUG(format, ...) LOG_DEBUG("stellar", format, ##__VA_ARGS__)
|
||||
|
||||
struct thread_ctx
|
||||
struct stellar_thread
|
||||
{
|
||||
pthread_t tid;
|
||||
uint16_t idx;
|
||||
uint64_t is_runing;
|
||||
struct thread_cron *cron;
|
||||
uint64_t stat_last_merge_ts;
|
||||
uint64_t timing_wheel_last_update_ts;
|
||||
struct ip_reassembly *ip_mgr;
|
||||
struct session_manager *sess_mgr;
|
||||
};
|
||||
@@ -38,25 +38,21 @@ struct thread_ctx
|
||||
struct stellar_runtime
|
||||
{
|
||||
uint64_t need_exit;
|
||||
struct thread_cron *cron;
|
||||
uint64_t stat_last_output_ts;
|
||||
struct stellar_stat *stat;
|
||||
struct packet_io *packet_io;
|
||||
struct plugin_manager *plug_mgr;
|
||||
struct thread_ctx threads[MAX_THREAD_NUM];
|
||||
struct stellar_thread threads[MAX_THREAD_NUM];
|
||||
};
|
||||
struct stellar_runtime __runtime;
|
||||
struct stellar_runtime __runtime = {0};
|
||||
struct stellar_runtime *runtime = &__runtime;
|
||||
|
||||
struct stellar_config __config;
|
||||
struct stellar_config __config = {0};
|
||||
struct stellar_config *config = &__config;
|
||||
|
||||
static const char *log_config_file = "./conf/log.toml";
|
||||
static const char *stellar_config_file = "./conf/stellar.toml";
|
||||
|
||||
/******************************************************************************
|
||||
* util
|
||||
******************************************************************************/
|
||||
|
||||
static void signal_handler(int signo)
|
||||
{
|
||||
if (signo == SIGINT)
|
||||
@@ -84,16 +80,15 @@ static void signal_handler(int signo)
|
||||
}
|
||||
}
|
||||
|
||||
static void execute_packet_action(struct packet_io *packet_io, struct session *sess, struct packet *pkt, uint16_t thr_idx)
|
||||
static void update_session_stat(struct session *sess, struct packet *pkt)
|
||||
{
|
||||
int is_ctrl = packet_is_ctrl(pkt);
|
||||
int need_drop = packet_need_drop(pkt);
|
||||
|
||||
if (sess != NULL)
|
||||
if (sess)
|
||||
{
|
||||
enum session_stat stat_pkt;
|
||||
enum session_stat stat_byte;
|
||||
if (need_drop)
|
||||
enum session_direction dir = session_get_current_direction(sess);
|
||||
int is_ctrl = packet_is_ctrl(pkt);
|
||||
if (packet_need_drop(pkt))
|
||||
{
|
||||
stat_pkt = is_ctrl ? STAT_CTRL_PKTS_DROP : STAT_RAW_PKTS_DROP;
|
||||
stat_byte = is_ctrl ? STAT_CTRL_BYTES_DROP : STAT_RAW_BYTES_DROP;
|
||||
@@ -104,41 +99,61 @@ static void execute_packet_action(struct packet_io *packet_io, struct session *s
|
||||
stat_byte = is_ctrl ? STAT_CTRL_BYTES_TX : STAT_RAW_BYTES_TX;
|
||||
}
|
||||
|
||||
session_inc_stat(sess, session_get_current_direction(sess), stat_pkt, 1);
|
||||
session_inc_stat(sess, session_get_current_direction(sess), stat_byte, packet_get_len(pkt));
|
||||
session_inc_stat(sess, dir, stat_pkt, 1);
|
||||
session_inc_stat(sess, dir, stat_byte, packet_get_len(pkt));
|
||||
session_set_current_packet(sess, NULL);
|
||||
session_set_current_direction(sess, SESSION_DIRECTION_NONE);
|
||||
}
|
||||
}
|
||||
|
||||
if (need_drop)
|
||||
static inline void free_evicted_sessions(struct session_manager *sess_mgr, uint64_t max_free)
|
||||
{
|
||||
void *plugin_ctx = NULL;
|
||||
struct session *sess = NULL;
|
||||
for (uint64_t i = 0; i < max_free; i++)
|
||||
{
|
||||
packet_io_drop(packet_io, thr_idx, pkt, 1);
|
||||
sess = session_manager_get_evicted_session(sess_mgr);
|
||||
if (sess)
|
||||
{
|
||||
plugin_ctx = session_get_user_data(sess);
|
||||
plugin_manager_free_ctx(plugin_ctx);
|
||||
session_manager_free_session(sess_mgr, sess);
|
||||
}
|
||||
else
|
||||
{
|
||||
packet_io_egress(packet_io, thr_idx, pkt, 1);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/******************************************************************************
|
||||
* thread
|
||||
******************************************************************************/
|
||||
|
||||
static inline void thread_set_name(const char *thd_symbol, uint16_t thd_idx)
|
||||
static inline void free_expired_sessions(struct session_manager *sess_mgr, uint64_t max_free, uint64_t now)
|
||||
{
|
||||
char thd_name[16];
|
||||
snprintf(thd_name, sizeof(thd_name), "%s:%d", thd_symbol, thd_idx);
|
||||
prctl(PR_SET_NAME, (unsigned long long)thd_name, NULL, NULL, NULL);
|
||||
void *plugin_ctx = NULL;
|
||||
struct session *sess = NULL;
|
||||
for (uint64_t i = 0; i < max_free; i++)
|
||||
{
|
||||
sess = session_manager_get_expired_session(sess_mgr, now);
|
||||
if (sess)
|
||||
{
|
||||
plugin_ctx = session_get_user_data(sess);
|
||||
plugin_manager_free_ctx(plugin_ctx);
|
||||
session_manager_free_session(sess_mgr, sess);
|
||||
}
|
||||
else
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static inline void thread_stat_merge_cron(void *ctx)
|
||||
static inline void merge_thread_stat(struct stellar_thread *thread, uint64_t now)
|
||||
{
|
||||
struct thread_ctx *thr_ctx = (struct thread_ctx *)ctx;
|
||||
struct thread_stat thr_stat = {
|
||||
ip_reassembly_get_stat(thr_ctx->ip_mgr),
|
||||
session_manager_get_stat(thr_ctx->sess_mgr),
|
||||
packet_io_stat(runtime->packet_io, thread->idx),
|
||||
ip_reassembly_stat(thread->ip_mgr),
|
||||
session_manager_stat(thread->sess_mgr),
|
||||
};
|
||||
stellar_peek_thr_stat(runtime->stat, &thr_stat, thr_ctx->idx);
|
||||
stellar_stat_merge(runtime->stat, &thr_stat, thread->idx);
|
||||
}
|
||||
|
||||
static void *work_thread(void *arg)
|
||||
@@ -146,26 +161,20 @@ static void *work_thread(void *arg)
|
||||
int nr_recv;
|
||||
uint64_t now = 0;
|
||||
uint16_t thr_idx = 0;
|
||||
void *plugin_ctx;
|
||||
struct packet *pkt;
|
||||
char thd_name[16] = {0};
|
||||
void *plugin_ctx = NULL;
|
||||
struct packet *pkt = NULL;
|
||||
struct packet packets[RX_BURST_MAX];
|
||||
struct session *sess;
|
||||
struct session *evicted_sess;
|
||||
struct session *expired_sess;
|
||||
struct session *sess = NULL;
|
||||
struct packet_io *packet_io = runtime->packet_io;
|
||||
struct plugin_manager *plug_mgr = runtime->plug_mgr;
|
||||
struct thread_ctx *thr_ctx = (struct thread_ctx *)arg;
|
||||
struct thread_cron *cron = thr_ctx->cron;
|
||||
struct ip_reassembly *ip_reass = thr_ctx->ip_mgr;
|
||||
struct session_manager *sess_mgr = thr_ctx->sess_mgr;
|
||||
thr_idx = thr_ctx->idx;
|
||||
struct stellar_thread *thread = (struct stellar_thread *)arg;
|
||||
struct ip_reassembly *ip_reass = thread->ip_mgr;
|
||||
struct session_manager *sess_mgr = thread->sess_mgr;
|
||||
thr_idx = thread->idx;
|
||||
|
||||
struct cron_task stat_task = {
|
||||
.callback = thread_stat_merge_cron,
|
||||
.data = thr_ctx,
|
||||
.cycle = 2000, // ms
|
||||
};
|
||||
thread_cron_add_task(cron, &stat_task);
|
||||
snprintf(thd_name, sizeof(thd_name), "stellar:%d", thr_idx);
|
||||
prctl(PR_SET_NAME, (unsigned long long)thd_name, NULL, NULL, NULL);
|
||||
|
||||
if (packet_io_init(packet_io, thr_idx) != 0)
|
||||
{
|
||||
@@ -173,8 +182,7 @@ static void *work_thread(void *arg)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
ATOMIC_SET(&thr_ctx->is_runing, 1);
|
||||
thread_set_name("stellar", thr_idx);
|
||||
ATOMIC_SET(&thread->is_runing, 1);
|
||||
STELLAR_LOG_STATE("worker thread %d runing", thr_idx);
|
||||
|
||||
while (ATOMIC_READ(&runtime->need_exit) == 0)
|
||||
@@ -227,39 +235,47 @@ static void *work_thread(void *arg)
|
||||
plugin_manager_dispatch_session(plug_mgr, sess, pkt);
|
||||
|
||||
fast_path:
|
||||
execute_packet_action(packet_io, sess, pkt, thr_idx);
|
||||
update_session_stat(sess, pkt);
|
||||
if (packet_need_drop(pkt))
|
||||
{
|
||||
packet_io_drop(packet_io, thr_idx, pkt, 1);
|
||||
}
|
||||
else
|
||||
{
|
||||
packet_io_egress(packet_io, thr_idx, pkt, 1);
|
||||
}
|
||||
}
|
||||
|
||||
idle_tasks:
|
||||
// nr_recv packet atmost trigger nr_recv session evict
|
||||
for (int i = 0; i < nr_recv; i++)
|
||||
// nr_recv packet atmost trigger nr_recv session evicted
|
||||
free_evicted_sessions(sess_mgr, nr_recv);
|
||||
|
||||
// per 5 ms, atmost free 8 expired session
|
||||
if (now - thread->timing_wheel_last_update_ts > 5)
|
||||
{
|
||||
evicted_sess = session_manager_get_evicted_session(sess_mgr);
|
||||
if (evicted_sess)
|
||||
{
|
||||
plugin_ctx = session_get_user_data(evicted_sess);
|
||||
plugin_manager_free_ctx(plugin_ctx);
|
||||
session_manager_free_session(sess_mgr, evicted_sess);
|
||||
}
|
||||
free_expired_sessions(sess_mgr, 8, now);
|
||||
thread->timing_wheel_last_update_ts = now;
|
||||
}
|
||||
|
||||
while ((expired_sess = session_manager_get_expired_session(sess_mgr, now)))
|
||||
if (now - thread->stat_last_merge_ts > 1000)
|
||||
{
|
||||
plugin_ctx = session_get_user_data(expired_sess);
|
||||
plugin_manager_free_ctx(plugin_ctx);
|
||||
session_manager_free_session(sess_mgr, expired_sess);
|
||||
merge_thread_stat(thread, now);
|
||||
thread->stat_last_merge_ts = now;
|
||||
}
|
||||
|
||||
ip_reassembly_expire(ip_reass, now);
|
||||
|
||||
thread_cron_run(cron, now);
|
||||
|
||||
// TODO
|
||||
// plugin_manager_cron();
|
||||
// poll_non_packet_events();
|
||||
// packet_io_yield();
|
||||
|
||||
if (nr_recv == 0)
|
||||
{
|
||||
packet_io_yield(packet_io, thr_idx, 10);
|
||||
}
|
||||
}
|
||||
|
||||
ATOMIC_SET(&thr_ctx->is_runing, 0);
|
||||
ATOMIC_SET(&thread->is_runing, 0);
|
||||
STELLAR_LOG_STATE("worker thread %d exit !!!", thr_idx);
|
||||
|
||||
return NULL;
|
||||
@@ -270,23 +286,19 @@ static int stellar_thread_init(struct stellar_runtime *ctx, uint8_t nr_threads)
|
||||
uint64_t now = timestamp_get_msec();
|
||||
for (uint8_t i = 0; i < nr_threads; i++)
|
||||
{
|
||||
struct thread_ctx *thr_ctx = &ctx->threads[i];
|
||||
thr_ctx->idx = i;
|
||||
thr_ctx->is_runing = 0;
|
||||
thr_ctx->cron = thread_cron_new(now);
|
||||
if (thr_ctx->cron == NULL)
|
||||
{
|
||||
STELLAR_LOG_ERROR("unable to create thread cron");
|
||||
return -1;
|
||||
}
|
||||
thr_ctx->sess_mgr = session_manager_new(&config->sess_mgr_opts, now);
|
||||
if (thr_ctx->sess_mgr == NULL)
|
||||
struct stellar_thread *thread = &ctx->threads[i];
|
||||
thread->idx = i;
|
||||
thread->is_runing = 0;
|
||||
thread->stat_last_merge_ts = now;
|
||||
thread->timing_wheel_last_update_ts = now;
|
||||
thread->sess_mgr = session_manager_new(&config->sess_mgr_opts, now);
|
||||
if (thread->sess_mgr == NULL)
|
||||
{
|
||||
STELLAR_LOG_ERROR("unable to create session manager");
|
||||
return -1;
|
||||
}
|
||||
thr_ctx->ip_mgr = ip_reassembly_new(&config->ip_opts);
|
||||
if (thr_ctx->ip_mgr == NULL)
|
||||
thread->ip_mgr = ip_reassembly_new(&config->ip_opts);
|
||||
if (thread->ip_mgr == NULL)
|
||||
{
|
||||
STELLAR_LOG_ERROR("unable to create ip reassemble manager");
|
||||
return -1;
|
||||
@@ -300,13 +312,12 @@ static void stellar_thread_clean(struct stellar_runtime *ctx, uint8_t nr_threads
|
||||
{
|
||||
for (uint8_t i = 0; i < nr_threads; i++)
|
||||
{
|
||||
struct thread_ctx *thr_ctx = &ctx->threads[i];
|
||||
if (ATOMIC_READ(&thr_ctx->is_runing) == 0)
|
||||
struct stellar_thread *thread = &ctx->threads[i];
|
||||
if (ATOMIC_READ(&thread->is_runing) == 0)
|
||||
{
|
||||
STELLAR_LOG_STATE("wait worker thread %d free context", i);
|
||||
session_manager_free(thr_ctx->sess_mgr);
|
||||
ip_reassembly_free(thr_ctx->ip_mgr);
|
||||
thread_cron_free(thr_ctx->cron);
|
||||
session_manager_free(thread->sess_mgr);
|
||||
ip_reassembly_free(thread->ip_mgr);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -315,8 +326,8 @@ static int stellar_thread_run(struct stellar_runtime *ctx, uint8_t nr_threads)
|
||||
{
|
||||
for (uint8_t i = 0; i < nr_threads; i++)
|
||||
{
|
||||
struct thread_ctx *thr_ctx = &ctx->threads[i];
|
||||
if (pthread_create(&thr_ctx->tid, NULL, work_thread, (void *)thr_ctx) < 0)
|
||||
struct stellar_thread *thread = &ctx->threads[i];
|
||||
if (pthread_create(&thread->tid, NULL, work_thread, (void *)thread) < 0)
|
||||
{
|
||||
STELLAR_LOG_ERROR("unable to create worker thread, error %d: %s", errno, strerror(errno));
|
||||
return -1;
|
||||
@@ -330,8 +341,8 @@ static void stellar_thread_join(struct stellar_runtime *ctx, uint8_t nr_threads)
|
||||
{
|
||||
for (uint8_t i = 0; i < nr_threads; i++)
|
||||
{
|
||||
struct thread_ctx *thr_ctx = &ctx->threads[i];
|
||||
while (ATOMIC_READ(&thr_ctx->is_runing) == 1)
|
||||
struct stellar_thread *thread = &ctx->threads[i];
|
||||
while (ATOMIC_READ(&thread->is_runing) == 1)
|
||||
{
|
||||
STELLAR_LOG_STATE("wait worker thread %d stop", i);
|
||||
sleep(1);
|
||||
@@ -339,28 +350,9 @@ static void stellar_thread_join(struct stellar_runtime *ctx, uint8_t nr_threads)
|
||||
}
|
||||
}
|
||||
|
||||
/******************************************************************************
|
||||
* main
|
||||
******************************************************************************/
|
||||
|
||||
static inline void stellar_stat_output_cron(void *ctx)
|
||||
{
|
||||
struct stellar_runtime *runtime = (struct stellar_runtime *)ctx;
|
||||
stellar_peek_io_stat(runtime->stat, packet_io_get_stat(runtime->packet_io));
|
||||
stellar_stat_output(runtime->stat);
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
uint8_t nr_threads = 0;
|
||||
struct cron_task stat_task =
|
||||
{
|
||||
.callback = stellar_stat_output_cron,
|
||||
.data = runtime,
|
||||
.cycle = 2000, // ms
|
||||
};
|
||||
memset(runtime, 0, sizeof(struct stellar_runtime));
|
||||
memset(config, 0, sizeof(struct stellar_config));
|
||||
timestamp_update();
|
||||
|
||||
signal(SIGINT, signal_handler);
|
||||
@@ -375,12 +367,12 @@ int main(int argc, char **argv)
|
||||
}
|
||||
STELLAR_LOG_STATE("start stellar (version: %s)\n %s", __stellar_version, logo_str);
|
||||
|
||||
if (stellar_config_load(stellar_config_file, config) != 0)
|
||||
if (stellar_load_config(stellar_config_file, config) != 0)
|
||||
{
|
||||
STELLAR_LOG_ERROR("unable to load config file");
|
||||
goto error_out;
|
||||
}
|
||||
stellar_config_print(config);
|
||||
stellar_print_config(config);
|
||||
STELLAR_LOG_DEBUG("sizeof(struct session) = %lu bytes", sizeof(struct session));
|
||||
nr_threads = config->io_opts.nr_threads;
|
||||
|
||||
@@ -390,13 +382,6 @@ int main(int argc, char **argv)
|
||||
goto error_out;
|
||||
}
|
||||
|
||||
runtime->cron = thread_cron_new(timestamp_get_msec());
|
||||
if (runtime->cron == NULL)
|
||||
{
|
||||
STELLAR_LOG_ERROR("unable to create runtime cron");
|
||||
goto error_out;
|
||||
}
|
||||
|
||||
runtime->stat = stellar_stat_new(nr_threads);
|
||||
if (runtime->stat == NULL)
|
||||
{
|
||||
@@ -430,12 +415,16 @@ int main(int argc, char **argv)
|
||||
goto error_out;
|
||||
}
|
||||
|
||||
thread_cron_add_task(runtime->cron, &stat_task);
|
||||
runtime->stat_last_output_ts = timestamp_get_msec();
|
||||
while (!ATOMIC_READ(&runtime->need_exit))
|
||||
{
|
||||
timestamp_update();
|
||||
thread_cron_run(runtime->cron, timestamp_get_msec());
|
||||
usleep(5 * 1000);
|
||||
if (timestamp_get_msec() - runtime->stat_last_output_ts > 1000)
|
||||
{
|
||||
runtime->stat_last_output_ts = timestamp_get_msec();
|
||||
stellar_stat_output(runtime->stat);
|
||||
}
|
||||
usleep(1000); // 1ms
|
||||
}
|
||||
|
||||
error_out:
|
||||
@@ -444,7 +433,6 @@ error_out:
|
||||
packet_io_free(runtime->packet_io);
|
||||
plugin_manager_free(runtime->plug_mgr);
|
||||
stellar_stat_free(runtime->stat);
|
||||
thread_cron_free(runtime->cron);
|
||||
STELLAR_LOG_STATE("stellar exit !!!\n");
|
||||
log_free();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user