Update session timer
This commit is contained in:
@@ -472,40 +472,6 @@ void session_free_all_ex_data(struct session *sess)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/******************************************************************************
|
|
||||||
* session expire
|
|
||||||
******************************************************************************/
|
|
||||||
|
|
||||||
// session expire
|
|
||||||
void session_set_expirecb(struct session *sess, session_expire_cb expire_cb, void *expire_arg, uint64_t expire_abs_ts)
|
|
||||||
{
|
|
||||||
struct timeout *timeout = &sess->timeout;
|
|
||||||
|
|
||||||
timeout_init(timeout, TIMEOUT_ABS);
|
|
||||||
timeout_setcb(timeout, NULL, sess);
|
|
||||||
sess->expire_cb = expire_cb;
|
|
||||||
sess->expire_arg = expire_arg;
|
|
||||||
sess->expire_abs_ts = expire_abs_ts;
|
|
||||||
}
|
|
||||||
|
|
||||||
void session_del_expirecb(struct session *sess)
|
|
||||||
{
|
|
||||||
struct timeout *timeout = &sess->timeout;
|
|
||||||
|
|
||||||
timeout_init(timeout, 0);
|
|
||||||
sess->expire_cb = NULL;
|
|
||||||
sess->expire_arg = NULL;
|
|
||||||
sess->expire_abs_ts = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
void session_run_expirecb(struct session *sess)
|
|
||||||
{
|
|
||||||
if (sess->expire_cb)
|
|
||||||
{
|
|
||||||
sess->expire_cb(sess, sess->expire_arg);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/******************************************************************************
|
/******************************************************************************
|
||||||
* session dump
|
* session dump
|
||||||
******************************************************************************/
|
******************************************************************************/
|
||||||
|
|||||||
@@ -165,17 +165,6 @@ void *session_get0_ex_data(const struct session *sess, uint8_t idx);
|
|||||||
void session_free_ex_data(struct session *sess, uint8_t idx);
|
void session_free_ex_data(struct session *sess, uint8_t idx);
|
||||||
void session_free_all_ex_data(struct session *sess);
|
void session_free_all_ex_data(struct session *sess);
|
||||||
|
|
||||||
/******************************************************************************
|
|
||||||
* session expire
|
|
||||||
******************************************************************************/
|
|
||||||
|
|
||||||
typedef void (*session_expire_cb)(struct session *sess, void *arg);
|
|
||||||
|
|
||||||
// session timer
|
|
||||||
void session_set_expirecb(struct session *sess, session_expire_cb expire_cb, void *expire_arg, uint64_t expire_abs_ts);
|
|
||||||
void session_del_expirecb(struct session *sess);
|
|
||||||
void session_run_expirecb(struct session *sess);
|
|
||||||
|
|
||||||
/******************************************************************************
|
/******************************************************************************
|
||||||
* session dump
|
* session dump
|
||||||
******************************************************************************/
|
******************************************************************************/
|
||||||
|
|||||||
@@ -406,13 +406,6 @@ static int session_filter_run(struct session_manager *mgr, enum filter_stage sta
|
|||||||
* Session Manager
|
* Session Manager
|
||||||
******************************************************************************/
|
******************************************************************************/
|
||||||
|
|
||||||
static void timer_update(struct session_timer *timer, struct session *sess, uint64_t abs_timeout)
|
|
||||||
{
|
|
||||||
session_timer_del(timer, sess);
|
|
||||||
session_set_expirecb(sess, NULL, NULL, abs_timeout);
|
|
||||||
session_timer_add(timer, sess);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void session_update(struct session *sess, enum session_state next_state, const struct packet *pkt, const struct tuple6 *key, enum session_dir dir, uint64_t now)
|
static void session_update(struct session *sess, enum session_state next_state, const struct packet *pkt, const struct tuple6 *key, enum session_dir dir, uint64_t now)
|
||||||
{
|
{
|
||||||
if (session_get_state(sess) == SESSION_STATE_INIT)
|
if (session_get_state(sess) == SESSION_STATE_INIT)
|
||||||
@@ -532,7 +525,7 @@ static struct session *session_manager_new_tcp_session(struct session_manager *m
|
|||||||
session_insert_tcp_payload(sess, tcp_hdr_get_seq(hdr), tcp_layer->pld_ptr, tcp_layer->pld_len, now);
|
session_insert_tcp_payload(sess, tcp_hdr_get_seq(hdr), tcp_layer->pld_ptr, tcp_layer->pld_len, now);
|
||||||
|
|
||||||
uint64_t timeout = (flags & TH_ACK) ? mgr->tcp_handshake_timeout : mgr->tcp_init_timeout;
|
uint64_t timeout = (flags & TH_ACK) ? mgr->tcp_handshake_timeout : mgr->tcp_init_timeout;
|
||||||
timer_update(mgr->sess_timer, sess, now + timeout);
|
session_timer_update(mgr->sess_timer, sess, now + timeout);
|
||||||
session_table_add(mgr->tcp_sess_table, key, sess);
|
session_table_add(mgr->tcp_sess_table, key, sess);
|
||||||
|
|
||||||
duplicated_packet_filter_add(mgr->dup_pkt_filter, pkt, now);
|
duplicated_packet_filter_add(mgr->dup_pkt_filter, pkt, now);
|
||||||
@@ -565,7 +558,7 @@ static struct session *session_manager_new_udp_session(struct session_manager *m
|
|||||||
session_transition_log(sess, SESSION_STATE_INIT, next_state, UDP_DATA);
|
session_transition_log(sess, SESSION_STATE_INIT, next_state, UDP_DATA);
|
||||||
session_stat_inc(&mgr->stat.udp_sess, next_state);
|
session_stat_inc(&mgr->stat.udp_sess, next_state);
|
||||||
|
|
||||||
timer_update(mgr->sess_timer, sess, now + mgr->udp_data_timeout);
|
session_timer_update(mgr->sess_timer, sess, now + mgr->udp_data_timeout);
|
||||||
session_table_add(mgr->udp_sess_table, key, sess);
|
session_table_add(mgr->udp_sess_table, key, sess);
|
||||||
|
|
||||||
return sess;
|
return sess;
|
||||||
@@ -630,7 +623,7 @@ static int session_manager_update_tcp_session(struct session_manager *mgr, struc
|
|||||||
case SESSION_STATE_CLOSING:
|
case SESSION_STATE_CLOSING:
|
||||||
if (flags & TH_FIN)
|
if (flags & TH_FIN)
|
||||||
{
|
{
|
||||||
timeout = (history & C2S_FIN_RECV && history & S2C_FIN_RECV) ? mgr->tcp_half_closed_timeout : mgr->tcp_time_wait_timeout;
|
timeout = (history & C2S_FIN_RECV && history & S2C_FIN_RECV) ? mgr->tcp_time_wait_timeout : mgr->tcp_half_closed_timeout;
|
||||||
}
|
}
|
||||||
else if (flags & TH_RST)
|
else if (flags & TH_RST)
|
||||||
{
|
{
|
||||||
@@ -648,7 +641,7 @@ static int session_manager_update_tcp_session(struct session_manager *mgr, struc
|
|||||||
assert(0);
|
assert(0);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
timer_update(mgr->sess_timer, sess, now + timeout);
|
session_timer_update(mgr->sess_timer, sess, now + timeout);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@@ -661,7 +654,7 @@ static int session_manager_update_udp_session(struct session_manager *mgr, struc
|
|||||||
session_update(sess, next_state, pkt, key, dir, now);
|
session_update(sess, next_state, pkt, key, dir, now);
|
||||||
session_transition_log(sess, curr_state, next_state, UDP_DATA);
|
session_transition_log(sess, curr_state, next_state, UDP_DATA);
|
||||||
session_stat_update(mgr, sess, curr_state, next_state);
|
session_stat_update(mgr, sess, curr_state, next_state);
|
||||||
timer_update(mgr->sess_timer, sess, now + mgr->udp_data_timeout);
|
session_timer_update(mgr->sess_timer, sess, now + mgr->udp_data_timeout);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@@ -723,7 +716,7 @@ struct session_manager *session_manager_new(struct session_manager_options *opts
|
|||||||
mgr->sess_pool = session_pool_new(mgr->max_tcp_session_num + mgr->max_udp_session_num);
|
mgr->sess_pool = session_pool_new(mgr->max_tcp_session_num + mgr->max_udp_session_num);
|
||||||
mgr->tcp_sess_table = session_table_new();
|
mgr->tcp_sess_table = session_table_new();
|
||||||
mgr->udp_sess_table = session_table_new();
|
mgr->udp_sess_table = session_table_new();
|
||||||
mgr->sess_timer = session_timer_new();
|
mgr->sess_timer = session_timer_new(now);
|
||||||
mgr->dup_pkt_filter = duplicated_packet_filter_new(&duplicated_packet_filter_opts, now);
|
mgr->dup_pkt_filter = duplicated_packet_filter_new(&duplicated_packet_filter_opts, now);
|
||||||
mgr->evicte_sess_filter = evicted_session_filter_new(&evicted_session_filter_opts, now);
|
mgr->evicte_sess_filter = evicted_session_filter_new(&evicted_session_filter_opts, now);
|
||||||
if (mgr->sess_pool == NULL || mgr->tcp_sess_table == NULL || mgr->udp_sess_table == NULL || mgr->sess_timer == NULL || mgr->dup_pkt_filter == NULL || mgr->evicte_sess_filter == NULL)
|
if (mgr->sess_pool == NULL || mgr->tcp_sess_table == NULL || mgr->udp_sess_table == NULL || mgr->sess_timer == NULL || mgr->dup_pkt_filter == NULL || mgr->evicte_sess_filter == NULL)
|
||||||
@@ -909,7 +902,7 @@ struct session *session_manager_get_expired_session(struct session_manager *mgr,
|
|||||||
assert(0);
|
assert(0);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
timer_update(mgr->sess_timer, sess, now + timeout);
|
session_timer_update(mgr->sess_timer, sess, now + timeout);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -82,11 +82,7 @@ struct session
|
|||||||
* Session Timer Zone
|
* Session Timer Zone
|
||||||
******************************/
|
******************************/
|
||||||
|
|
||||||
// session timer
|
|
||||||
struct timeout timeout;
|
struct timeout timeout;
|
||||||
session_expire_cb expire_cb;
|
|
||||||
void *expire_arg;
|
|
||||||
uint64_t expire_abs_ts;
|
|
||||||
|
|
||||||
/******************************
|
/******************************
|
||||||
* Session Table Zone
|
* Session Table Zone
|
||||||
@@ -103,9 +99,9 @@ struct session
|
|||||||
* Session Queue Node
|
* Session Queue Node
|
||||||
******************************/
|
******************************/
|
||||||
|
|
||||||
struct list_head evicte; // used for evicte queue
|
|
||||||
struct list_head lru; // used for lru queue
|
struct list_head lru; // used for lru queue
|
||||||
struct list_head free; // used for free queue
|
struct list_head free; // used for free queue
|
||||||
|
struct list_head evicte; // used for evicte queue
|
||||||
};
|
};
|
||||||
|
|
||||||
#ifdef __cpluscplus
|
#ifdef __cpluscplus
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ struct session_timer
|
|||||||
struct timeouts *timeouts;
|
struct timeouts *timeouts;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct session_timer *session_timer_new()
|
struct session_timer *session_timer_new(uint64_t now)
|
||||||
{
|
{
|
||||||
timeout_error_t err;
|
timeout_error_t err;
|
||||||
struct session_timer *timer = (struct session_timer *)calloc(1, sizeof(struct session_timer));
|
struct session_timer *timer = (struct session_timer *)calloc(1, sizeof(struct session_timer));
|
||||||
@@ -20,6 +20,7 @@ struct session_timer *session_timer_new()
|
|||||||
{
|
{
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
|
timeouts_update(timer->timeouts, now);
|
||||||
|
|
||||||
return timer;
|
return timer;
|
||||||
|
|
||||||
@@ -42,21 +43,26 @@ void session_timer_free(struct session_timer *timer)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void session_timer_add(struct session_timer *timer, struct session *sess)
|
void session_timer_add(struct session_timer *timer, struct session *sess, uint64_t expires)
|
||||||
{
|
{
|
||||||
struct timeout *timeout = &sess->timeout;
|
timeout_init(&sess->timeout, TIMEOUT_ABS);
|
||||||
timeouts_add(timer->timeouts, timeout, sess->expire_abs_ts);
|
timeouts_add(timer->timeouts, &sess->timeout, expires);
|
||||||
}
|
}
|
||||||
|
|
||||||
void session_timer_del(struct session_timer *timer, struct session *sess)
|
void session_timer_del(struct session_timer *timer, struct session *sess)
|
||||||
{
|
{
|
||||||
struct timeout *timeout = &sess->timeout;
|
timeouts_del(timer->timeouts, &sess->timeout);
|
||||||
timeouts_del(timer->timeouts, timeout);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
struct session *session_timer_expire(struct session_timer *timer, uint64_t abs_current_ts)
|
void session_timer_update(struct session_timer *timer, struct session *sess, uint64_t expires)
|
||||||
{
|
{
|
||||||
timeouts_update(timer->timeouts, abs_current_ts);
|
session_timer_del(timer, sess);
|
||||||
|
session_timer_add(timer, sess, expires);
|
||||||
|
}
|
||||||
|
|
||||||
|
struct session *session_timer_expire(struct session_timer *timer, uint64_t now)
|
||||||
|
{
|
||||||
|
timeouts_update(timer->timeouts, now);
|
||||||
|
|
||||||
struct timeout *timeout = timeouts_get(timer->timeouts);
|
struct timeout *timeout = timeouts_get(timer->timeouts);
|
||||||
if (timeout == NULL)
|
if (timeout == NULL)
|
||||||
@@ -64,8 +70,7 @@ struct session *session_timer_expire(struct session_timer *timer, uint64_t abs_c
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct session *sess = (struct session *)timeout->callback.arg;
|
return container_of(timeout, struct session, timeout);
|
||||||
return sess;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
uint64_t session_timer_next_expire_interval(struct session_timer *timer)
|
uint64_t session_timer_next_expire_interval(struct session_timer *timer)
|
||||||
|
|||||||
@@ -9,9 +9,10 @@ extern "C"
|
|||||||
#include "session.h"
|
#include "session.h"
|
||||||
|
|
||||||
struct session_timer;
|
struct session_timer;
|
||||||
struct session_timer *session_timer_new();
|
struct session_timer *session_timer_new(uint64_t now);
|
||||||
void session_timer_free(struct session_timer *timer);
|
void session_timer_free(struct session_timer *timer);
|
||||||
void session_timer_add(struct session_timer *timer, struct session *sess);
|
void session_timer_update(struct session_timer *timer, struct session *sess, uint64_t expires);
|
||||||
|
void session_timer_add(struct session_timer *timer, struct session *sess, uint64_t expires);
|
||||||
void session_timer_del(struct session_timer *timer, struct session *sess);
|
void session_timer_del(struct session_timer *timer, struct session *sess);
|
||||||
/*
|
/*
|
||||||
* return one session which timeout, or NULL if no session timeout.
|
* return one session which timeout, or NULL if no session timeout.
|
||||||
|
|||||||
@@ -238,8 +238,8 @@ TEST(SESS_MGR_TCP_REASSEMBLY, OUT_OF_ORDER)
|
|||||||
session_consume_tcp_payload(sess, len);
|
session_consume_tcp_payload(sess, len);
|
||||||
|
|
||||||
// expire session
|
// expire session
|
||||||
EXPECT_TRUE(session_manager_get_expired_session(mgr, 7 + opts.tcp_data_timeout) == NULL); // active -> closing
|
EXPECT_TRUE(session_manager_get_expired_session(mgr, 7 + opts.tcp_data_timeout) == NULL); // active -> closing
|
||||||
sess = session_manager_get_expired_session(mgr, 7 + opts.tcp_data_timeout + opts.tcp_time_wait_timeout); // closing -> closed
|
sess = session_manager_get_expired_session(mgr, 7 + opts.tcp_data_timeout + opts.tcp_data_timeout); // closing -> closed
|
||||||
EXPECT_TRUE(sess);
|
EXPECT_TRUE(sess);
|
||||||
EXPECT_TRUE(session_get_state(sess) == SESSION_STATE_CLOSED);
|
EXPECT_TRUE(session_get_state(sess) == SESSION_STATE_CLOSED);
|
||||||
EXPECT_TRUE(session_get_closing_reason(sess) == CLOSING_BY_TIMEOUT);
|
EXPECT_TRUE(session_get_closing_reason(sess) == CLOSING_BY_TIMEOUT);
|
||||||
@@ -330,8 +330,8 @@ TEST(SESS_MGR_TCP_REASSEMBLY, SEQ_WRAPAROUND)
|
|||||||
session_consume_tcp_payload(sess, len);
|
session_consume_tcp_payload(sess, len);
|
||||||
|
|
||||||
// expire session
|
// expire session
|
||||||
EXPECT_TRUE(session_manager_get_expired_session(mgr, 4 + opts.tcp_data_timeout) == NULL); // active -> closing
|
EXPECT_TRUE(session_manager_get_expired_session(mgr, 4 + opts.tcp_data_timeout) == NULL); // active -> closing
|
||||||
sess = session_manager_get_expired_session(mgr, 4 + opts.tcp_data_timeout + opts.tcp_time_wait_timeout); // closing -> closed
|
sess = session_manager_get_expired_session(mgr, 4 + opts.tcp_data_timeout + opts.tcp_data_timeout); // closing -> closed
|
||||||
EXPECT_TRUE(sess);
|
EXPECT_TRUE(sess);
|
||||||
EXPECT_TRUE(session_get_state(sess) == SESSION_STATE_CLOSED);
|
EXPECT_TRUE(session_get_state(sess) == SESSION_STATE_CLOSED);
|
||||||
EXPECT_TRUE(session_get_closing_reason(sess) == CLOSING_BY_TIMEOUT);
|
EXPECT_TRUE(session_get_closing_reason(sess) == CLOSING_BY_TIMEOUT);
|
||||||
|
|||||||
@@ -3,62 +3,42 @@
|
|||||||
#include "session_timer.h"
|
#include "session_timer.h"
|
||||||
#include "session_private.h"
|
#include "session_private.h"
|
||||||
|
|
||||||
static void session_expire(struct session *sess, void *arg)
|
|
||||||
{
|
|
||||||
printf("=== session %lu expired ===\n", session_get_id(sess));
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST(SESSION_TIMER, ADD_DEL)
|
|
||||||
{
|
|
||||||
struct session sess;
|
|
||||||
struct session_timer *timer = session_timer_new();
|
|
||||||
EXPECT_TRUE(timer != NULL);
|
|
||||||
|
|
||||||
session_init(&sess);
|
|
||||||
session_set_id(&sess, 1);
|
|
||||||
session_set_expirecb(&sess, session_expire, NULL, 1000);
|
|
||||||
|
|
||||||
session_timer_add(timer, &sess);
|
|
||||||
session_timer_del(timer, &sess);
|
|
||||||
|
|
||||||
session_timer_free(timer);
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST(SESSION_TIMER, EXPIRE)
|
TEST(SESSION_TIMER, EXPIRE)
|
||||||
{
|
{
|
||||||
struct session *sess = NULL;
|
struct session *sess = NULL;
|
||||||
struct session sess1;
|
struct session sess1;
|
||||||
struct session sess2;
|
struct session sess2;
|
||||||
struct session sess3;
|
struct session sess3;
|
||||||
struct session_timer *timer = session_timer_new();
|
struct session_timer *timer = session_timer_new(100);
|
||||||
EXPECT_TRUE(timer != NULL);
|
EXPECT_TRUE(timer != NULL);
|
||||||
|
|
||||||
session_init(&sess1);
|
session_init(&sess1);
|
||||||
session_init(&sess2);
|
session_init(&sess2);
|
||||||
session_init(&sess3);
|
session_init(&sess3);
|
||||||
session_set_id(&sess1, 1);
|
|
||||||
session_set_id(&sess2, 2);
|
|
||||||
session_set_id(&sess3, 3);
|
|
||||||
session_set_expirecb(&sess1, session_expire, NULL, 5);
|
|
||||||
session_set_expirecb(&sess2, session_expire, NULL, 5);
|
|
||||||
session_set_expirecb(&sess3, session_expire, NULL, 10);
|
|
||||||
|
|
||||||
session_timer_add(timer, &sess1);
|
session_timer_add(timer, &sess1, 100 + 5);
|
||||||
session_timer_add(timer, &sess2);
|
session_timer_add(timer, &sess2, 100 + 5);
|
||||||
session_timer_add(timer, &sess3);
|
session_timer_add(timer, &sess3, 100 + 10);
|
||||||
|
|
||||||
for (uint64_t abs_current_ts = 0; abs_current_ts < 15; abs_current_ts++)
|
// not expire
|
||||||
{
|
sess = session_timer_expire(timer, 100 + 4);
|
||||||
printf("current timestamp %lu\n", abs_current_ts);
|
EXPECT_TRUE(sess == NULL);
|
||||||
do
|
// expire
|
||||||
{
|
sess = session_timer_expire(timer, 100 + 5);
|
||||||
sess = session_timer_expire(timer, abs_current_ts);
|
EXPECT_TRUE(sess == &sess1);
|
||||||
if (sess != NULL)
|
sess = session_timer_expire(timer, 100 + 5);
|
||||||
{
|
EXPECT_TRUE(sess == &sess2);
|
||||||
session_run_expirecb(sess);
|
// not expire
|
||||||
}
|
sess = session_timer_expire(timer, 100 + 5);
|
||||||
} while (sess);
|
EXPECT_TRUE(sess == NULL);
|
||||||
}
|
sess = session_timer_expire(timer, 100 + 9);
|
||||||
|
EXPECT_TRUE(sess == NULL);
|
||||||
|
// expire
|
||||||
|
sess = session_timer_expire(timer, 100 + 10);
|
||||||
|
EXPECT_TRUE(sess == &sess3);
|
||||||
|
// not expire
|
||||||
|
sess = session_timer_expire(timer, 100 + 10);
|
||||||
|
EXPECT_TRUE(sess == NULL);
|
||||||
|
|
||||||
session_timer_free(timer);
|
session_timer_free(timer);
|
||||||
}
|
}
|
||||||
@@ -69,40 +49,65 @@ TEST(SESSION_TIMER, BEFORE_EXPIRE_DEL)
|
|||||||
struct session sess1;
|
struct session sess1;
|
||||||
struct session sess2;
|
struct session sess2;
|
||||||
struct session sess3;
|
struct session sess3;
|
||||||
struct session_timer *timer = session_timer_new();
|
struct session_timer *timer = session_timer_new(1);
|
||||||
EXPECT_TRUE(timer != NULL);
|
EXPECT_TRUE(timer != NULL);
|
||||||
|
|
||||||
session_init(&sess1);
|
session_init(&sess1);
|
||||||
session_init(&sess2);
|
session_init(&sess2);
|
||||||
session_init(&sess3);
|
session_init(&sess3);
|
||||||
session_set_id(&sess1, 1);
|
|
||||||
session_set_id(&sess2, 2);
|
|
||||||
session_set_id(&sess3, 3);
|
|
||||||
session_set_expirecb(&sess1, session_expire, NULL, 5);
|
|
||||||
session_set_expirecb(&sess2, session_expire, NULL, 5);
|
|
||||||
session_set_expirecb(&sess3, session_expire, NULL, 10);
|
|
||||||
|
|
||||||
session_timer_add(timer, &sess1);
|
session_timer_add(timer, &sess1, 100 + 5);
|
||||||
session_timer_add(timer, &sess2);
|
session_timer_add(timer, &sess2, 100 + 5);
|
||||||
session_timer_add(timer, &sess3);
|
session_timer_add(timer, &sess3, 100 + 10);
|
||||||
|
|
||||||
for (uint64_t abs_current_ts = 0; abs_current_ts < 15; abs_current_ts++)
|
// not expire
|
||||||
{
|
sess = session_timer_expire(timer, 100 + 4);
|
||||||
printf("current timestamp %lu\n", abs_current_ts);
|
EXPECT_TRUE(sess == NULL);
|
||||||
if (abs_current_ts == 2)
|
// del sess1
|
||||||
{
|
session_timer_del(timer, &sess1);
|
||||||
printf("delete timer 2\n");
|
// expire
|
||||||
session_timer_del(timer, &sess2);
|
sess = session_timer_expire(timer, 100 + 5);
|
||||||
}
|
EXPECT_TRUE(sess == &sess2);
|
||||||
do
|
sess = session_timer_expire(timer, 100 + 5);
|
||||||
{
|
EXPECT_TRUE(sess == NULL);
|
||||||
sess = session_timer_expire(timer, abs_current_ts);
|
// expire
|
||||||
if (sess != NULL)
|
sess = session_timer_expire(timer, 100 + 10);
|
||||||
{
|
EXPECT_TRUE(sess == &sess3);
|
||||||
session_run_expirecb(sess);
|
// not expire
|
||||||
}
|
sess = session_timer_expire(timer, 100 + 10);
|
||||||
} while (sess);
|
EXPECT_TRUE(sess == NULL);
|
||||||
}
|
|
||||||
|
session_timer_free(timer);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(SESSION_TIMER, AFTER_EXPIRE_DEL)
|
||||||
|
{
|
||||||
|
struct session *sess = NULL;
|
||||||
|
struct session sess1;
|
||||||
|
struct session sess2;
|
||||||
|
struct session sess3;
|
||||||
|
struct session_timer *timer = session_timer_new(1);
|
||||||
|
EXPECT_TRUE(timer != NULL);
|
||||||
|
|
||||||
|
session_init(&sess1);
|
||||||
|
session_init(&sess2);
|
||||||
|
session_init(&sess3);
|
||||||
|
|
||||||
|
session_timer_add(timer, &sess1, 100 + 5);
|
||||||
|
session_timer_add(timer, &sess2, 100 + 5);
|
||||||
|
session_timer_add(timer, &sess3, 100 + 10);
|
||||||
|
|
||||||
|
// expire
|
||||||
|
sess = session_timer_expire(timer, 100 + 5);
|
||||||
|
EXPECT_TRUE(sess == &sess1);
|
||||||
|
// del sess2
|
||||||
|
session_timer_del(timer, &sess2);
|
||||||
|
// not expire
|
||||||
|
sess = session_timer_expire(timer, 100 + 5);
|
||||||
|
EXPECT_TRUE(sess == NULL);
|
||||||
|
// expire
|
||||||
|
sess = session_timer_expire(timer, 100 + 10);
|
||||||
|
EXPECT_TRUE(sess == &sess3);
|
||||||
|
|
||||||
session_timer_free(timer);
|
session_timer_free(timer);
|
||||||
}
|
}
|
||||||
@@ -112,43 +117,32 @@ TEST(SESSION_TIMER, BEFORE_EXPIRE_UPDATE)
|
|||||||
struct session *sess = NULL;
|
struct session *sess = NULL;
|
||||||
struct session sess1;
|
struct session sess1;
|
||||||
struct session sess2;
|
struct session sess2;
|
||||||
struct session sess3;
|
struct session_timer *timer = session_timer_new(100);
|
||||||
struct session_timer *timer = session_timer_new();
|
|
||||||
EXPECT_TRUE(timer != NULL);
|
EXPECT_TRUE(timer != NULL);
|
||||||
|
|
||||||
session_init(&sess1);
|
session_init(&sess1);
|
||||||
session_init(&sess2);
|
session_init(&sess2);
|
||||||
session_init(&sess3);
|
|
||||||
session_set_id(&sess1, 1);
|
|
||||||
session_set_id(&sess2, 2);
|
|
||||||
session_set_id(&sess3, 3);
|
|
||||||
session_set_expirecb(&sess1, session_expire, NULL, 5);
|
|
||||||
session_set_expirecb(&sess2, session_expire, NULL, 5);
|
|
||||||
session_set_expirecb(&sess3, session_expire, NULL, 10);
|
|
||||||
|
|
||||||
session_timer_add(timer, &sess1);
|
session_timer_add(timer, &sess1, 100 + 5);
|
||||||
session_timer_add(timer, &sess2);
|
session_timer_add(timer, &sess2, 100 + 10);
|
||||||
session_timer_add(timer, &sess3);
|
|
||||||
|
|
||||||
for (uint64_t abs_current_ts = 0; abs_current_ts < 15; abs_current_ts++)
|
// not expire
|
||||||
{
|
sess = session_timer_expire(timer, 100 + 4);
|
||||||
printf("current timestamp %lu\n", abs_current_ts);
|
EXPECT_TRUE(sess == NULL);
|
||||||
if (abs_current_ts == 2)
|
// expire
|
||||||
{
|
sess = session_timer_expire(timer, 100 + 5);
|
||||||
printf("update timer 2\n");
|
EXPECT_TRUE(sess == &sess1);
|
||||||
session_timer_del(timer, &sess2);
|
// not expire
|
||||||
session_set_expirecb(&sess2, session_expire, NULL, 8);
|
sess = session_timer_expire(timer, 100 + 5);
|
||||||
session_timer_add(timer, &sess2);
|
EXPECT_TRUE(sess == NULL);
|
||||||
}
|
// update sess2
|
||||||
do
|
session_timer_update(timer, &sess2, 100 + 20);
|
||||||
{
|
// not expire
|
||||||
sess = session_timer_expire(timer, abs_current_ts);
|
sess = session_timer_expire(timer, 100 + 19);
|
||||||
if (sess != NULL)
|
EXPECT_TRUE(sess == NULL);
|
||||||
{
|
// expire
|
||||||
session_run_expirecb(sess);
|
sess = session_timer_expire(timer, 100 + 20);
|
||||||
}
|
EXPECT_TRUE(sess == &sess2);
|
||||||
} while (sess);
|
|
||||||
}
|
|
||||||
|
|
||||||
session_timer_free(timer);
|
session_timer_free(timer);
|
||||||
}
|
}
|
||||||
@@ -157,20 +151,16 @@ TEST(SESSION_TIMER, NEXT_EXPIRE_INTERVAL)
|
|||||||
{
|
{
|
||||||
struct session sess1;
|
struct session sess1;
|
||||||
struct session sess2;
|
struct session sess2;
|
||||||
struct session_timer *timer = session_timer_new();
|
struct session_timer *timer = session_timer_new(100);
|
||||||
EXPECT_TRUE(timer != NULL);
|
EXPECT_TRUE(timer != NULL);
|
||||||
|
|
||||||
session_init(&sess1);
|
session_init(&sess1);
|
||||||
session_init(&sess2);
|
session_init(&sess2);
|
||||||
session_set_id(&sess1, 1);
|
|
||||||
session_set_id(&sess2, 2);
|
|
||||||
session_set_expirecb(&sess1, session_expire, NULL, 1000);
|
|
||||||
session_set_expirecb(&sess2, session_expire, NULL, 1000);
|
|
||||||
|
|
||||||
EXPECT_TRUE(session_timer_next_expire_interval(timer) == UINT64_MAX);
|
EXPECT_TRUE(session_timer_next_expire_interval(timer) == UINT64_MAX);
|
||||||
|
|
||||||
session_timer_add(timer, &sess1);
|
session_timer_add(timer, &sess1, 1000);
|
||||||
session_timer_add(timer, &sess2);
|
session_timer_add(timer, &sess2, 1000);
|
||||||
EXPECT_TRUE(session_timer_next_expire_interval(timer) < UINT64_MAX);
|
EXPECT_TRUE(session_timer_next_expire_interval(timer) < UINT64_MAX);
|
||||||
|
|
||||||
EXPECT_TRUE(session_timer_expire(timer, 900) == NULL);
|
EXPECT_TRUE(session_timer_expire(timer, 900) == NULL);
|
||||||
|
|||||||
@@ -370,7 +370,7 @@ TEST(TCP_ACTIVE_TO_CLOSING, BY_DATA_TIMEOUT)
|
|||||||
|
|
||||||
// expire session
|
// expire session
|
||||||
EXPECT_TRUE(session_manager_get_expired_session(mgr, 2 + opts.tcp_data_timeout) == NULL);
|
EXPECT_TRUE(session_manager_get_expired_session(mgr, 2 + opts.tcp_data_timeout) == NULL);
|
||||||
sess = session_manager_get_expired_session(mgr, 2 + opts.tcp_data_timeout + opts.tcp_time_wait_timeout);
|
sess = session_manager_get_expired_session(mgr, 2 + opts.tcp_data_timeout + opts.tcp_data_timeout);
|
||||||
EXPECT_TRUE(sess);
|
EXPECT_TRUE(sess);
|
||||||
EXPECT_TRUE(session_get_state(sess) == SESSION_STATE_CLOSED);
|
EXPECT_TRUE(session_get_state(sess) == SESSION_STATE_CLOSED);
|
||||||
EXPECT_TRUE(session_get_closing_reason(sess) == CLOSING_BY_TIMEOUT);
|
EXPECT_TRUE(session_get_closing_reason(sess) == CLOSING_BY_TIMEOUT);
|
||||||
@@ -451,7 +451,7 @@ TEST(TCP_ACTIVE_TO_CLOSING, BY_C2S_HALF_CLOSED_TIMEOUT)
|
|||||||
EXPECT_TRUE(stat->tcp_sess.nr_sess_closing == 1);
|
EXPECT_TRUE(stat->tcp_sess.nr_sess_closing == 1);
|
||||||
|
|
||||||
// expire session
|
// expire session
|
||||||
sess = session_manager_get_expired_session(mgr, 3 + opts.tcp_time_wait_timeout);
|
sess = session_manager_get_expired_session(mgr, 3 + opts.tcp_half_closed_timeout);
|
||||||
EXPECT_TRUE(sess);
|
EXPECT_TRUE(sess);
|
||||||
EXPECT_TRUE(session_get_state(sess) == SESSION_STATE_CLOSED);
|
EXPECT_TRUE(session_get_state(sess) == SESSION_STATE_CLOSED);
|
||||||
EXPECT_TRUE(session_get_closing_reason(sess) == CLOSING_BY_CLIENT_FIN);
|
EXPECT_TRUE(session_get_closing_reason(sess) == CLOSING_BY_CLIENT_FIN);
|
||||||
@@ -532,7 +532,7 @@ TEST(TCP_ACTIVE_TO_CLOSING, BY_S2C_HALF_CLOSED_TIMEOUT)
|
|||||||
EXPECT_TRUE(stat->tcp_sess.nr_sess_closing == 1);
|
EXPECT_TRUE(stat->tcp_sess.nr_sess_closing == 1);
|
||||||
|
|
||||||
// expire session
|
// expire session
|
||||||
sess = session_manager_get_expired_session(mgr, 3 + opts.tcp_time_wait_timeout);
|
sess = session_manager_get_expired_session(mgr, 3 + opts.tcp_half_closed_timeout);
|
||||||
EXPECT_TRUE(sess);
|
EXPECT_TRUE(sess);
|
||||||
EXPECT_TRUE(session_get_state(sess) == SESSION_STATE_CLOSED);
|
EXPECT_TRUE(session_get_state(sess) == SESSION_STATE_CLOSED);
|
||||||
EXPECT_TRUE(session_get_closing_reason(sess) == CLOSING_BY_SERVER_FIN);
|
EXPECT_TRUE(session_get_closing_reason(sess) == CLOSING_BY_SERVER_FIN);
|
||||||
|
|||||||
@@ -105,8 +105,8 @@ TEST(TCP_INIT_TO_OPENING, BY_SYN)
|
|||||||
EXPECT_TRUE(stat->tcp_sess.nr_sess_closing == 0);
|
EXPECT_TRUE(stat->tcp_sess.nr_sess_closing == 0);
|
||||||
|
|
||||||
// expire session
|
// expire session
|
||||||
EXPECT_TRUE(session_manager_get_expired_session(mgr, 1 + opts.tcp_init_timeout) == NULL); // opening -> closing
|
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_time_wait_timeout); // closing -> closed
|
sess = session_manager_get_expired_session(mgr, 1 + opts.tcp_init_timeout + opts.tcp_data_timeout); // closing -> closed
|
||||||
EXPECT_TRUE(sess);
|
EXPECT_TRUE(sess);
|
||||||
EXPECT_TRUE(session_get_state(sess) == SESSION_STATE_CLOSED);
|
EXPECT_TRUE(session_get_state(sess) == SESSION_STATE_CLOSED);
|
||||||
EXPECT_TRUE(session_get_closing_reason(sess) == CLOSING_BY_TIMEOUT);
|
EXPECT_TRUE(session_get_closing_reason(sess) == CLOSING_BY_TIMEOUT);
|
||||||
@@ -186,7 +186,7 @@ TEST(TCP_INIT_TO_OPENING, BY_SYNACK)
|
|||||||
|
|
||||||
// expire session
|
// expire session
|
||||||
EXPECT_TRUE(session_manager_get_expired_session(mgr, 1 + opts.tcp_handshake_timeout) == NULL);
|
EXPECT_TRUE(session_manager_get_expired_session(mgr, 1 + opts.tcp_handshake_timeout) == NULL);
|
||||||
sess = session_manager_get_expired_session(mgr, 1 + opts.tcp_handshake_timeout + opts.tcp_time_wait_timeout);
|
sess = session_manager_get_expired_session(mgr, 1 + opts.tcp_handshake_timeout + opts.tcp_data_timeout);
|
||||||
EXPECT_TRUE(sess);
|
EXPECT_TRUE(sess);
|
||||||
EXPECT_TRUE(session_get_state(sess) == SESSION_STATE_CLOSED);
|
EXPECT_TRUE(session_get_state(sess) == SESSION_STATE_CLOSED);
|
||||||
EXPECT_TRUE(session_get_closing_reason(sess) == CLOSING_BY_TIMEOUT);
|
EXPECT_TRUE(session_get_closing_reason(sess) == CLOSING_BY_TIMEOUT);
|
||||||
@@ -277,7 +277,7 @@ TEST(TCP_INIT_TO_OPENING, BY_SYN_SYNACK)
|
|||||||
|
|
||||||
// expire session
|
// expire session
|
||||||
EXPECT_TRUE(session_manager_get_expired_session(mgr, 2 + opts.tcp_handshake_timeout) == NULL);
|
EXPECT_TRUE(session_manager_get_expired_session(mgr, 2 + opts.tcp_handshake_timeout) == NULL);
|
||||||
sess = session_manager_get_expired_session(mgr, 2 + opts.tcp_handshake_timeout + opts.tcp_time_wait_timeout);
|
sess = session_manager_get_expired_session(mgr, 2 + opts.tcp_handshake_timeout + opts.tcp_data_timeout);
|
||||||
EXPECT_TRUE(sess);
|
EXPECT_TRUE(sess);
|
||||||
EXPECT_TRUE(session_get_state(sess) == SESSION_STATE_CLOSED);
|
EXPECT_TRUE(session_get_state(sess) == SESSION_STATE_CLOSED);
|
||||||
EXPECT_TRUE(session_get_closing_reason(sess) == CLOSING_BY_TIMEOUT);
|
EXPECT_TRUE(session_get_closing_reason(sess) == CLOSING_BY_TIMEOUT);
|
||||||
@@ -378,7 +378,7 @@ TEST(TCP_INIT_TO_OPENING, BY_SYN_SYNACK_ACK)
|
|||||||
|
|
||||||
// expire session
|
// expire session
|
||||||
EXPECT_TRUE(session_manager_get_expired_session(mgr, 3 + opts.tcp_data_timeout) == NULL);
|
EXPECT_TRUE(session_manager_get_expired_session(mgr, 3 + opts.tcp_data_timeout) == NULL);
|
||||||
sess = session_manager_get_expired_session(mgr, 3 + opts.tcp_data_timeout + opts.tcp_time_wait_timeout);
|
sess = session_manager_get_expired_session(mgr, 3 + opts.tcp_data_timeout + opts.tcp_data_timeout);
|
||||||
EXPECT_TRUE(sess);
|
EXPECT_TRUE(sess);
|
||||||
EXPECT_TRUE(session_get_state(sess) == SESSION_STATE_CLOSED);
|
EXPECT_TRUE(session_get_state(sess) == SESSION_STATE_CLOSED);
|
||||||
EXPECT_TRUE(session_get_closing_reason(sess) == CLOSING_BY_TIMEOUT);
|
EXPECT_TRUE(session_get_closing_reason(sess) == CLOSING_BY_TIMEOUT);
|
||||||
@@ -476,7 +476,7 @@ TEST(TCP_INIT_TO_OPENING, BY_SYN_RETRANSMISSION)
|
|||||||
|
|
||||||
// expire session
|
// expire session
|
||||||
EXPECT_TRUE(session_manager_get_expired_session(mgr, 2 + opts.tcp_init_timeout) == NULL);
|
EXPECT_TRUE(session_manager_get_expired_session(mgr, 2 + opts.tcp_init_timeout) == NULL);
|
||||||
sess = session_manager_get_expired_session(mgr, 2 + opts.tcp_init_timeout + opts.tcp_time_wait_timeout);
|
sess = session_manager_get_expired_session(mgr, 2 + opts.tcp_init_timeout + opts.tcp_data_timeout);
|
||||||
EXPECT_TRUE(sess);
|
EXPECT_TRUE(sess);
|
||||||
EXPECT_TRUE(session_get_state(sess) == SESSION_STATE_CLOSED);
|
EXPECT_TRUE(session_get_state(sess) == SESSION_STATE_CLOSED);
|
||||||
EXPECT_TRUE(session_get_closing_reason(sess) == CLOSING_BY_TIMEOUT);
|
EXPECT_TRUE(session_get_closing_reason(sess) == CLOSING_BY_TIMEOUT);
|
||||||
@@ -575,7 +575,7 @@ TEST(TCP_INIT_TO_OPENING, BY_SYNACK_RETRANSMISSION)
|
|||||||
|
|
||||||
// expire session
|
// expire session
|
||||||
EXPECT_TRUE(session_manager_get_expired_session(mgr, 2 + opts.tcp_handshake_timeout) == NULL);
|
EXPECT_TRUE(session_manager_get_expired_session(mgr, 2 + opts.tcp_handshake_timeout) == NULL);
|
||||||
sess = session_manager_get_expired_session(mgr, 2 + opts.tcp_handshake_timeout + opts.tcp_time_wait_timeout);
|
sess = session_manager_get_expired_session(mgr, 2 + opts.tcp_handshake_timeout + opts.tcp_data_timeout);
|
||||||
EXPECT_TRUE(sess);
|
EXPECT_TRUE(sess);
|
||||||
EXPECT_TRUE(session_get_state(sess) == SESSION_STATE_CLOSED);
|
EXPECT_TRUE(session_get_state(sess) == SESSION_STATE_CLOSED);
|
||||||
EXPECT_TRUE(session_get_closing_reason(sess) == CLOSING_BY_TIMEOUT);
|
EXPECT_TRUE(session_get_closing_reason(sess) == CLOSING_BY_TIMEOUT);
|
||||||
@@ -666,7 +666,7 @@ TEST(TCP_INIT_TO_OPENING, BY_C2S_ASMMETRIC)
|
|||||||
|
|
||||||
// expire session
|
// expire session
|
||||||
EXPECT_TRUE(session_manager_get_expired_session(mgr, 2 + opts.tcp_data_timeout) == NULL);
|
EXPECT_TRUE(session_manager_get_expired_session(mgr, 2 + opts.tcp_data_timeout) == NULL);
|
||||||
sess = session_manager_get_expired_session(mgr, 2 + opts.tcp_data_timeout + opts.tcp_time_wait_timeout);
|
sess = session_manager_get_expired_session(mgr, 2 + opts.tcp_data_timeout + opts.tcp_data_timeout);
|
||||||
EXPECT_TRUE(sess);
|
EXPECT_TRUE(sess);
|
||||||
EXPECT_TRUE(session_get_state(sess) == SESSION_STATE_CLOSED);
|
EXPECT_TRUE(session_get_state(sess) == SESSION_STATE_CLOSED);
|
||||||
EXPECT_TRUE(session_get_closing_reason(sess) == CLOSING_BY_TIMEOUT);
|
EXPECT_TRUE(session_get_closing_reason(sess) == CLOSING_BY_TIMEOUT);
|
||||||
@@ -757,7 +757,7 @@ TEST(TCP_INIT_TO_OPENING, BY_S2C_ASMMETRIC)
|
|||||||
|
|
||||||
// expire session
|
// expire session
|
||||||
EXPECT_TRUE(session_manager_get_expired_session(mgr, 2 + opts.tcp_data_timeout) == NULL);
|
EXPECT_TRUE(session_manager_get_expired_session(mgr, 2 + opts.tcp_data_timeout) == NULL);
|
||||||
sess = session_manager_get_expired_session(mgr, 2 + opts.tcp_data_timeout + opts.tcp_time_wait_timeout);
|
sess = session_manager_get_expired_session(mgr, 2 + opts.tcp_data_timeout + opts.tcp_data_timeout);
|
||||||
EXPECT_TRUE(sess);
|
EXPECT_TRUE(sess);
|
||||||
EXPECT_TRUE(session_get_state(sess) == SESSION_STATE_CLOSED);
|
EXPECT_TRUE(session_get_state(sess) == SESSION_STATE_CLOSED);
|
||||||
EXPECT_TRUE(session_get_closing_reason(sess) == CLOSING_BY_TIMEOUT);
|
EXPECT_TRUE(session_get_closing_reason(sess) == CLOSING_BY_TIMEOUT);
|
||||||
|
|||||||
@@ -115,7 +115,7 @@ TEST(TCP_OPENING_TO_ACTIVE, BY_SYN_C2S_DATA)
|
|||||||
|
|
||||||
// expire session
|
// expire session
|
||||||
EXPECT_TRUE(session_manager_get_expired_session(mgr, 2 + opts.tcp_data_timeout) == NULL);
|
EXPECT_TRUE(session_manager_get_expired_session(mgr, 2 + opts.tcp_data_timeout) == NULL);
|
||||||
sess = session_manager_get_expired_session(mgr, 2 + opts.tcp_data_timeout + opts.tcp_time_wait_timeout);
|
sess = session_manager_get_expired_session(mgr, 2 + opts.tcp_data_timeout + opts.tcp_data_timeout);
|
||||||
EXPECT_TRUE(sess);
|
EXPECT_TRUE(sess);
|
||||||
EXPECT_TRUE(session_get_state(sess) == SESSION_STATE_CLOSED);
|
EXPECT_TRUE(session_get_state(sess) == SESSION_STATE_CLOSED);
|
||||||
EXPECT_TRUE(session_get_closing_reason(sess) == CLOSING_BY_TIMEOUT);
|
EXPECT_TRUE(session_get_closing_reason(sess) == CLOSING_BY_TIMEOUT);
|
||||||
@@ -205,7 +205,7 @@ TEST(TCP_OPENING_TO_ACTIVE, BY_SYNACK_S2C_DATA)
|
|||||||
|
|
||||||
// expire session
|
// expire session
|
||||||
EXPECT_TRUE(session_manager_get_expired_session(mgr, 2 + opts.tcp_data_timeout) == NULL);
|
EXPECT_TRUE(session_manager_get_expired_session(mgr, 2 + opts.tcp_data_timeout) == NULL);
|
||||||
sess = session_manager_get_expired_session(mgr, 2 + opts.tcp_data_timeout + opts.tcp_time_wait_timeout);
|
sess = session_manager_get_expired_session(mgr, 2 + opts.tcp_data_timeout + opts.tcp_data_timeout);
|
||||||
EXPECT_TRUE(sess);
|
EXPECT_TRUE(sess);
|
||||||
EXPECT_TRUE(session_get_state(sess) == SESSION_STATE_CLOSED);
|
EXPECT_TRUE(session_get_state(sess) == SESSION_STATE_CLOSED);
|
||||||
EXPECT_TRUE(session_get_closing_reason(sess) == CLOSING_BY_TIMEOUT);
|
EXPECT_TRUE(session_get_closing_reason(sess) == CLOSING_BY_TIMEOUT);
|
||||||
|
|||||||
@@ -376,7 +376,7 @@ TEST(TCP_OPENING_TO_CLOSING, BY_INIT_TIMEOUT)
|
|||||||
|
|
||||||
// expire session
|
// expire session
|
||||||
EXPECT_TRUE(session_manager_get_expired_session(mgr, 1 + opts.tcp_init_timeout) == NULL);
|
EXPECT_TRUE(session_manager_get_expired_session(mgr, 1 + opts.tcp_init_timeout) == NULL);
|
||||||
sess = session_manager_get_expired_session(mgr, 1 + opts.tcp_init_timeout + opts.tcp_time_wait_timeout);
|
sess = session_manager_get_expired_session(mgr, 1 + opts.tcp_init_timeout + opts.tcp_data_timeout);
|
||||||
EXPECT_TRUE(sess);
|
EXPECT_TRUE(sess);
|
||||||
EXPECT_TRUE(session_get_state(sess) == SESSION_STATE_CLOSED);
|
EXPECT_TRUE(session_get_state(sess) == SESSION_STATE_CLOSED);
|
||||||
EXPECT_TRUE(session_get_closing_reason(sess) == CLOSING_BY_TIMEOUT);
|
EXPECT_TRUE(session_get_closing_reason(sess) == CLOSING_BY_TIMEOUT);
|
||||||
@@ -466,7 +466,7 @@ TEST(TCP_OPENING_TO_CLOSING, BY_HANDSHAKE_TIMEOUT)
|
|||||||
|
|
||||||
// expire session
|
// expire session
|
||||||
EXPECT_TRUE(session_manager_get_expired_session(mgr, 2 + opts.tcp_handshake_timeout) == NULL);
|
EXPECT_TRUE(session_manager_get_expired_session(mgr, 2 + opts.tcp_handshake_timeout) == NULL);
|
||||||
sess = session_manager_get_expired_session(mgr, 2 + opts.tcp_handshake_timeout + opts.tcp_time_wait_timeout);
|
sess = session_manager_get_expired_session(mgr, 2 + opts.tcp_handshake_timeout + opts.tcp_data_timeout);
|
||||||
EXPECT_TRUE(sess);
|
EXPECT_TRUE(sess);
|
||||||
EXPECT_TRUE(session_get_state(sess) == SESSION_STATE_CLOSED);
|
EXPECT_TRUE(session_get_state(sess) == SESSION_STATE_CLOSED);
|
||||||
EXPECT_TRUE(session_get_closing_reason(sess) == CLOSING_BY_TIMEOUT);
|
EXPECT_TRUE(session_get_closing_reason(sess) == CLOSING_BY_TIMEOUT);
|
||||||
@@ -567,7 +567,7 @@ TEST(TCP_OPENING_TO_CLOSING, BY_DATA_TIMEOUT)
|
|||||||
|
|
||||||
// expire session
|
// expire session
|
||||||
EXPECT_TRUE(session_manager_get_expired_session(mgr, 3 + opts.tcp_data_timeout) == NULL);
|
EXPECT_TRUE(session_manager_get_expired_session(mgr, 3 + opts.tcp_data_timeout) == NULL);
|
||||||
sess = session_manager_get_expired_session(mgr, 3 + opts.tcp_data_timeout + opts.tcp_time_wait_timeout);
|
sess = session_manager_get_expired_session(mgr, 3 + opts.tcp_data_timeout + opts.tcp_data_timeout);
|
||||||
EXPECT_TRUE(sess);
|
EXPECT_TRUE(sess);
|
||||||
EXPECT_TRUE(session_get_state(sess) == SESSION_STATE_CLOSED);
|
EXPECT_TRUE(session_get_state(sess) == SESSION_STATE_CLOSED);
|
||||||
EXPECT_TRUE(session_get_closing_reason(sess) == CLOSING_BY_TIMEOUT);
|
EXPECT_TRUE(session_get_closing_reason(sess) == CLOSING_BY_TIMEOUT);
|
||||||
@@ -656,7 +656,7 @@ TEST(TCP_OPENING_TO_CLOSING, BY_C2S_HALF_FIN)
|
|||||||
EXPECT_TRUE(stat->tcp_sess.nr_sess_closing == 1);
|
EXPECT_TRUE(stat->tcp_sess.nr_sess_closing == 1);
|
||||||
|
|
||||||
// expire session
|
// expire session
|
||||||
sess = session_manager_get_expired_session(mgr, 2 + opts.tcp_time_wait_timeout);
|
sess = session_manager_get_expired_session(mgr, 2 + opts.tcp_half_closed_timeout);
|
||||||
EXPECT_TRUE(sess);
|
EXPECT_TRUE(sess);
|
||||||
EXPECT_TRUE(session_get_state(sess) == SESSION_STATE_CLOSED);
|
EXPECT_TRUE(session_get_state(sess) == SESSION_STATE_CLOSED);
|
||||||
EXPECT_TRUE(session_get_closing_reason(sess) == CLOSING_BY_CLIENT_FIN);
|
EXPECT_TRUE(session_get_closing_reason(sess) == CLOSING_BY_CLIENT_FIN);
|
||||||
@@ -745,7 +745,7 @@ TEST(TCP_OPENING_TO_CLOSING, BY_S2C_HALF_FIN)
|
|||||||
EXPECT_TRUE(stat->tcp_sess.nr_sess_closing == 1);
|
EXPECT_TRUE(stat->tcp_sess.nr_sess_closing == 1);
|
||||||
|
|
||||||
// expire session
|
// expire session
|
||||||
sess = session_manager_get_expired_session(mgr, 2 + opts.tcp_time_wait_timeout);
|
sess = session_manager_get_expired_session(mgr, 2 + opts.tcp_half_closed_timeout);
|
||||||
EXPECT_TRUE(sess);
|
EXPECT_TRUE(sess);
|
||||||
EXPECT_TRUE(session_get_state(sess) == SESSION_STATE_CLOSED);
|
EXPECT_TRUE(session_get_state(sess) == SESSION_STATE_CLOSED);
|
||||||
EXPECT_TRUE(session_get_closing_reason(sess) == CLOSING_BY_SERVER_FIN);
|
EXPECT_TRUE(session_get_closing_reason(sess) == CLOSING_BY_SERVER_FIN);
|
||||||
|
|||||||
@@ -79,7 +79,7 @@ TEST(TIMEOUT, TCP_TIMEOUT_DATA)
|
|||||||
|
|
||||||
// expire session
|
// expire session
|
||||||
EXPECT_TRUE(session_manager_get_expired_session(mgr, 2 + opts.tcp_data_timeout) == NULL);
|
EXPECT_TRUE(session_manager_get_expired_session(mgr, 2 + opts.tcp_data_timeout) == NULL);
|
||||||
sess = session_manager_get_expired_session(mgr, 2 + opts.tcp_data_timeout + opts.tcp_time_wait_timeout);
|
sess = session_manager_get_expired_session(mgr, 2 + opts.tcp_data_timeout + opts.tcp_data_timeout);
|
||||||
EXPECT_TRUE(sess);
|
EXPECT_TRUE(sess);
|
||||||
EXPECT_TRUE(session_get_state(sess) == SESSION_STATE_CLOSED);
|
EXPECT_TRUE(session_get_state(sess) == SESSION_STATE_CLOSED);
|
||||||
EXPECT_TRUE(session_get_closing_reason(sess) == CLOSING_BY_TIMEOUT);
|
EXPECT_TRUE(session_get_closing_reason(sess) == CLOSING_BY_TIMEOUT);
|
||||||
|
|||||||
@@ -69,7 +69,7 @@ TEST(TIMEOUT, TCP_TIMEOUT_HANDSHAKE)
|
|||||||
|
|
||||||
// expire session
|
// expire session
|
||||||
EXPECT_TRUE(session_manager_get_expired_session(mgr, 1 + opts.tcp_handshake_timeout) == NULL);
|
EXPECT_TRUE(session_manager_get_expired_session(mgr, 1 + opts.tcp_handshake_timeout) == NULL);
|
||||||
sess = session_manager_get_expired_session(mgr, 1 + opts.tcp_handshake_timeout + opts.tcp_time_wait_timeout);
|
sess = session_manager_get_expired_session(mgr, 1 + opts.tcp_handshake_timeout + opts.tcp_data_timeout);
|
||||||
EXPECT_TRUE(sess);
|
EXPECT_TRUE(sess);
|
||||||
EXPECT_TRUE(session_get_state(sess) == SESSION_STATE_CLOSED);
|
EXPECT_TRUE(session_get_state(sess) == SESSION_STATE_CLOSED);
|
||||||
EXPECT_TRUE(session_get_closing_reason(sess) == CLOSING_BY_TIMEOUT);
|
EXPECT_TRUE(session_get_closing_reason(sess) == CLOSING_BY_TIMEOUT);
|
||||||
|
|||||||
@@ -68,8 +68,8 @@ TEST(TIMEOUT, TCP_TIMEOUT_INIT)
|
|||||||
EXPECT_TRUE(sess);
|
EXPECT_TRUE(sess);
|
||||||
|
|
||||||
// expire session
|
// expire session
|
||||||
EXPECT_TRUE(session_manager_get_expired_session(mgr, 1 + opts.tcp_init_timeout) == NULL); // opening -> closing
|
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_time_wait_timeout); // closing -> closed
|
sess = session_manager_get_expired_session(mgr, 1 + opts.tcp_init_timeout + opts.tcp_data_timeout); // closing -> closed
|
||||||
EXPECT_TRUE(sess);
|
EXPECT_TRUE(sess);
|
||||||
EXPECT_TRUE(session_get_state(sess) == SESSION_STATE_CLOSED);
|
EXPECT_TRUE(session_get_state(sess) == SESSION_STATE_CLOSED);
|
||||||
EXPECT_TRUE(session_get_closing_reason(sess) == CLOSING_BY_TIMEOUT);
|
EXPECT_TRUE(session_get_closing_reason(sess) == CLOSING_BY_TIMEOUT);
|
||||||
|
|||||||
Reference in New Issue
Block a user