90 lines
2.6 KiB
C++
90 lines
2.6 KiB
C++
#include <gtest/gtest.h>
|
|
|
|
#include "times.h"
|
|
#include "session_priv.h"
|
|
#include "session_manager.h"
|
|
|
|
#include "ipv4_utils.h"
|
|
#include "test_packets.h"
|
|
|
|
struct session_manager_options opts = {
|
|
// max session number
|
|
.max_tcp_session_num = 256,
|
|
.max_udp_session_num = 256,
|
|
|
|
// session overload
|
|
.tcp_overload_evict_old_sess = 1, // 1: evict old session, 0: bypass new session
|
|
.udp_overload_evict_old_sess = 1, // 1: evict old session, 0: bypass new session
|
|
|
|
// tcp timeout
|
|
.tcp_init_timeout = 1,
|
|
.tcp_handshake_timeout = 2,
|
|
.tcp_data_timeout = 3,
|
|
.tcp_half_closed_timeout = 4,
|
|
.tcp_time_wait_timeout = 5,
|
|
.tcp_discard_timeout = 6,
|
|
.tcp_unverified_rst_timeout = 7,
|
|
|
|
// udp timeout
|
|
.udp_data_timeout = 8,
|
|
|
|
// duplicate packet filter
|
|
.duplicated_packet_filter_enable = 1,
|
|
.duplicated_packet_filter_capacity = 1000,
|
|
.duplicated_packet_filter_timeout = 10,
|
|
.duplicated_packet_filter_error_rate = 0.0001,
|
|
|
|
// evicted session filter
|
|
.evicted_session_filter_enable = 1,
|
|
.evicted_session_filter_capacity = 1000,
|
|
.evicted_session_filter_timeout = 10,
|
|
.evicted_session_filter_error_rate = 0.0001,
|
|
|
|
// TCP Reassembly
|
|
.tcp_reassembly_enable = 1,
|
|
.tcp_reassembly_max_timeout = 60000,
|
|
.tcp_reassembly_max_segments = 16,
|
|
};
|
|
|
|
#if 1
|
|
TEST(TIMEOUT, TCP_TIMEOUT_INIT)
|
|
{
|
|
struct packet pkt;
|
|
struct session *sess = NULL;
|
|
struct session_manager *mgr = NULL;
|
|
|
|
stellar_update_time_cache();
|
|
mgr = session_manager_new(&opts, 1);
|
|
EXPECT_TRUE(mgr != NULL);
|
|
|
|
// C2S SYN Packet
|
|
printf("\n=> Packet Parse: TCP C2S SYN packet\n");
|
|
packet_parse(&pkt, (const char *)tcp_pkt1_c2s_syn, sizeof(tcp_pkt1_c2s_syn));
|
|
printf("<= Packet Parse: done\n\n");
|
|
|
|
// lookup session
|
|
EXPECT_TRUE(session_manager_lookup_session(mgr, &pkt, 1) == NULL);
|
|
// new session
|
|
sess = session_manager_new_session(mgr, &pkt, 1);
|
|
EXPECT_TRUE(sess);
|
|
|
|
// expire session
|
|
EXPECT_TRUE(session_manager_get_expired_session(mgr, 1 + opts.tcp_init_timeout) == NULL); // opening -> closing
|
|
sess = session_manager_get_expired_session(mgr, 1 + opts.tcp_init_timeout + opts.tcp_data_timeout); // closing -> closed
|
|
EXPECT_TRUE(sess);
|
|
EXPECT_TRUE(session_get_state(sess) == SESSION_STATE_CLOSED);
|
|
EXPECT_TRUE(session_get_closing_reason(sess) == CLOSING_BY_TIMEOUT);
|
|
session_print(sess);
|
|
// free session
|
|
session_manager_free_session(mgr, sess);
|
|
|
|
session_manager_free(mgr);
|
|
}
|
|
#endif
|
|
|
|
int main(int argc, char **argv)
|
|
{
|
|
::testing::InitGoogleTest(&argc, argv);
|
|
return RUN_ALL_TESTS();
|
|
}
|