summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--shaping/include/shaper.h6
-rw-r--r--shaping/src/shaper.cpp112
-rw-r--r--shaping/test/gtest_shaper.cpp86
3 files changed, 122 insertions, 82 deletions
diff --git a/shaping/include/shaper.h b/shaping/include/shaper.h
index 62f0eb6..8aabc42 100644
--- a/shaping/include/shaper.h
+++ b/shaping/include/shaper.h
@@ -107,7 +107,7 @@ enum shaping_profile_limit_direction {
struct shaper_token_multiple {
int token_get_multiple;
- unsigned char has_drop_by_queue_full;
+ unsigned char token_not_enough;
unsigned char has_failed_get_token;
time_t token_multiple_update_time_s;
};
@@ -119,7 +119,7 @@ struct shaping_profile_hash_node {
long long in_deposit_token_bits[SHAPING_PRIORITY_NUM_MAX];
long long out_deposit_token_bits[SHAPING_PRIORITY_NUM_MAX];
long long bidirection_deposit_token_bits[SHAPING_PRIORITY_NUM_MAX];
- long long last_failed_get_token_ms;
+ long long last_failed_get_token_ms[SHAPING_DIR_MAX];
long long last_hmget_ms;
long long queue_len[SHAPING_PRIORITY_NUM_MAX];
long long local_queue_len[SHAPING_PRIORITY_NUM_MAX];
@@ -145,7 +145,7 @@ struct shaping_profile_info {
long long in_deposit_token_bits;
long long out_deposit_token_bits;
long long bidirection_deposit_token_bits;
- long long last_failed_get_token_ms;
+ long long last_failed_get_token_ms[SHAPING_DIR_MAX];
unsigned long long enqueue_time_us;//to calculate max latency
struct shaping_stat_for_profile stat;
struct shaping_profile_hash_node *hash_node;
diff --git a/shaping/src/shaper.cpp b/shaping/src/shaper.cpp
index 16c9475..4accf9c 100644
--- a/shaping/src/shaper.cpp
+++ b/shaping/src/shaper.cpp
@@ -379,7 +379,6 @@ int shaper_flow_in_order_get(struct shaper *sp, struct shaper_flow_instance sf_i
avl_node = avl_tree_next_in_order_node_get(avl_node);
}
-
return count;
}
@@ -412,7 +411,43 @@ static int shaper_profile_async_pass_get(struct shaping_profile_info *profile, u
}
}
-static void shaper_deposit_token_add(struct shaping_profile_info *profile, int req_token_bits, unsigned char direction, int priority)
+static void shaper_token_multiple_update(struct shaping_thread_ctx *ctx, struct shaping_profile_info *profile)
+{
+ if (profile->type != PROFILE_TYPE_GENERIC) {
+ return;
+ }
+
+ struct shaper_token_multiple *token_multiple = &profile->hash_node->token_multiple;
+ int curr_multiple = token_multiple->token_get_multiple;
+ time_t curr_time_s = time(NULL);
+ int token_multiple_min = ctx->conf.token_multiple_min;
+ int token_multiple_max = ctx->conf.token_multiple_max;
+
+ if (curr_time_s - token_multiple->token_multiple_update_time_s < TOKEN_MULTIPLE_UPDATE_INTERVAL_S) {
+ return;
+ }
+
+ token_multiple->token_multiple_update_time_s = curr_time_s;
+
+ if (token_multiple->has_failed_get_token) {
+ token_multiple->token_get_multiple = (curr_multiple - 1) < token_multiple_min ? token_multiple_min : (curr_multiple - 1);
+ goto END;
+ }
+
+ if (token_multiple->token_not_enough) {
+ token_multiple->token_get_multiple = (curr_multiple + 1) > token_multiple_max ? token_multiple_max : (curr_multiple + 1);
+ goto END;
+ }
+
+END:
+ LOG_INFO("%s: profile id %d, token_get_multiple %d, has_failed_get_token %d, token_not_enough %d", LOG_TAG_SHAPING, profile->id, token_multiple->token_get_multiple, token_multiple->has_failed_get_token, token_multiple->token_not_enough);
+ token_multiple->has_failed_get_token = 0;
+ token_multiple->token_not_enough = 0;
+
+ return;
+}
+
+static void shaper_deposit_token_add(struct shaping_thread_ctx *ctx, struct shaping_profile_info *profile, int req_token_bits, unsigned char direction, int priority)
{
long long *deposit_token;
struct shaping_profile_hash_node *pf_hash_node = profile->hash_node;
@@ -446,45 +481,12 @@ static void shaper_deposit_token_add(struct shaping_profile_info *profile, int r
*deposit_token += req_token_bits;
if (*deposit_token > 0) {
shaper_profile_async_pass_set(profile, direction, priority, 1);
+ } else {
+ pf_hash_node->token_multiple.token_not_enough = 1;
+ shaper_token_multiple_update(ctx, profile);
}
}
-static void shaper_token_multiple_update(struct shaping_thread_ctx *ctx, struct shaping_profile_info *profile)
-{
- if (profile->type != PROFILE_TYPE_GENERIC) {
- return;
- }
-
- struct shaper_token_multiple *token_multiple = &profile->hash_node->token_multiple;
- int curr_multiple = token_multiple->token_get_multiple;
- time_t curr_time_s = time(NULL);
- int token_multiple_min = ctx->conf.token_multiple_min;
- int token_multiple_max = ctx->conf.token_multiple_max;
-
- if (curr_time_s - token_multiple->token_multiple_update_time_s < TOKEN_MULTIPLE_UPDATE_INTERVAL_S) {
- return;
- }
-
- token_multiple->token_multiple_update_time_s = curr_time_s;
-
- if (token_multiple->has_failed_get_token) {
- token_multiple->token_get_multiple = (curr_multiple - 1) < token_multiple_min ? token_multiple_min : (curr_multiple - 1);
- goto END;
- }
-
- if (token_multiple->has_drop_by_queue_full) {
- token_multiple->token_get_multiple = (curr_multiple + 1) > token_multiple_max ? token_multiple_max : (curr_multiple + 1);
- goto END;
- }
-
-END:
- LOG_INFO("%s: profile id %d, token_get_multiple %d, has_failed_get_token %d, has_drop_by_queue_full %d", LOG_TAG_SHAPING, profile->id, token_multiple->token_get_multiple, token_multiple->has_failed_get_token, token_multiple->has_drop_by_queue_full);
- token_multiple->has_failed_get_token = 0;
- token_multiple->has_drop_by_queue_full = 0;
-
- return;
-}
-
static void shaper_token_get_cb(const struct swarmkv_reply *reply, void * cb_arg)
{
struct shaping_tconsume_cb_arg *arg = (struct shaping_tconsume_cb_arg*)cb_arg;
@@ -519,7 +521,7 @@ static void shaper_token_get_cb(const struct swarmkv_reply *reply, void * cb_arg
}
if (reply->integer > 0) {
- shaper_deposit_token_add(profile, reply->integer, arg->direction, profile->priority);//deposit tokens to profile
+ shaper_deposit_token_add(ctx, profile, reply->integer, arg->direction, profile->priority);//deposit tokens to profile
}
if (reply->integer == 0) {
@@ -537,12 +539,12 @@ END:
if (reply->type != SWARMKV_REPLY_INTEGER || reply->integer == 0) {
switch (profile->type) {
case PROFILE_TYPE_GENERIC:
- pf_hash_node->last_failed_get_token_ms = curr_time.tv_sec * MILLI_SECONDS_PER_SEC + curr_time.tv_nsec / NANO_SECONDS_PER_MILLI_SEC;
+ pf_hash_node->last_failed_get_token_ms[arg->direction] = curr_time.tv_sec * MILLI_SECONDS_PER_SEC + curr_time.tv_nsec / NANO_SECONDS_PER_MILLI_SEC;
break;
case PROFILE_TYPE_HOST_FARINESS:
case PROFILE_TYPE_MAX_MIN_HOST_FAIRNESS:
case PROFILE_TYPE_SPLIT_BY_LOCAL_HOST:
- profile->last_failed_get_token_ms = curr_time.tv_sec * MILLI_SECONDS_PER_SEC + curr_time.tv_nsec / NANO_SECONDS_PER_MILLI_SEC;
+ profile->last_failed_get_token_ms[arg->direction] = curr_time.tv_sec * MILLI_SECONDS_PER_SEC + curr_time.tv_nsec / NANO_SECONDS_PER_MILLI_SEC;
break;
}
}
@@ -560,6 +562,7 @@ static int shaper_deposit_token_get(struct shaping_profile_info *profile, int re
long long *deposit_token;
struct shaping_profile_hash_node *pf_hash_node = profile->hash_node;
int ret = -1;
+ int token_multiple;
switch (profile->type) {
case PROFILE_TYPE_GENERIC:
@@ -570,9 +573,19 @@ static int shaper_deposit_token_get(struct shaping_profile_info *profile, int re
} else {
deposit_token = &pf_hash_node->out_deposit_token_bits[priority];
}
+ token_multiple = pf_hash_node->token_multiple.token_get_multiple;
break;
case PROFILE_TYPE_HOST_FARINESS:
case PROFILE_TYPE_MAX_MIN_HOST_FAIRNESS:
+ if (pf_hash_node->limit_direction == PROFILE_LIMIT_DIRECTION_BIDIRECTION) {
+ deposit_token = &profile->bidirection_deposit_token_bits;
+ } else if (direction == SHAPING_DIR_IN) {
+ deposit_token = &profile->in_deposit_token_bits;
+ } else {
+ deposit_token = &profile->out_deposit_token_bits;
+ }
+ token_multiple = 1;
+ break;
case PROFILE_TYPE_SPLIT_BY_LOCAL_HOST:
if (pf_hash_node->limit_direction == PROFILE_LIMIT_DIRECTION_BIDIRECTION) {
deposit_token = &profile->bidirection_deposit_token_bits;
@@ -581,6 +594,7 @@ static int shaper_deposit_token_get(struct shaping_profile_info *profile, int re
} else {
deposit_token = &profile->out_deposit_token_bits;
}
+ token_multiple = TOKEN_MULTIPLE_DEFAULT;
break;
default:
LOG_ERROR("%s: invalid profile type %d, profile id %d", LOG_TAG_SHAPING, profile->type, profile->id);
@@ -596,6 +610,10 @@ static int shaper_deposit_token_get(struct shaping_profile_info *profile, int re
ret = 0;
}
+ if (*deposit_token + (req_token_bits * token_multiple * 2) < 0) {
+ shaper_profile_async_pass_set(profile, direction, priority, 0);
+ }
+
return ret;
}
@@ -786,18 +804,18 @@ void shaper_profile_hash_node_set(struct shaping_thread_ctx *ctx, struct shaping
return;
}
-static int shaping_swarmkv_is_too_short_interval(long long curr_time_ms, struct shaping_profile_info *profile)
+static int shaping_swarmkv_is_too_short_interval(long long curr_time_ms, struct shaping_profile_info *profile, unsigned char direction)
{
long long last_failed_ms = 0;
switch (profile->type) {
case PROFILE_TYPE_GENERIC:
- last_failed_ms = profile->hash_node->last_failed_get_token_ms;
+ last_failed_ms = profile->hash_node->last_failed_get_token_ms[direction];
break;
case PROFILE_TYPE_HOST_FARINESS:
case PROFILE_TYPE_MAX_MIN_HOST_FAIRNESS:
case PROFILE_TYPE_SPLIT_BY_LOCAL_HOST:
- last_failed_ms = profile->last_failed_get_token_ms;
+ last_failed_ms = profile->last_failed_get_token_ms[direction];
break;
}
@@ -842,7 +860,7 @@ static int shaper_token_consume(struct shaping_thread_ctx *ctx, struct shaping_f
long long curr_time_ms = curr_timespec->tv_sec * MILLI_SECONDS_PER_SEC + curr_timespec->tv_nsec / NANO_SECONDS_PER_MILLI_SEC;
- if (shaping_swarmkv_is_too_short_interval(curr_time_ms, profile)) {
+ if (shaping_swarmkv_is_too_short_interval(curr_time_ms, profile, direction)) {
return ret;
}
@@ -1036,8 +1054,6 @@ DROP:
shaper_stat_drop_inc(&pf_info->stat, meta->dir, ctx->thread_index);
sf->anchor = 0;
- pf_info->hash_node->token_multiple.has_drop_by_queue_full = 1;
- shaper_token_multiple_update(ctx, pf_info);
return SHAPING_DROP;
}
@@ -1156,8 +1172,6 @@ void shaping_packet_process(struct shaping_thread_ctx *ctx, marsio_buff_t *rx_bu
shaper_global_stat_queueing_inc(&ctx->thread_global_stat, meta->raw_len);
} else {
struct shaping_profile_info *pf_info = &s_rule->primary;
- pf_info->hash_node->token_multiple.has_drop_by_queue_full = 1;
- shaper_token_multiple_update(ctx, pf_info);
shaper_stat_drop_inc(&pf_info->stat, meta->dir, ctx->thread_index);
shaper_global_stat_drop_inc(&ctx->thread_global_stat, meta->raw_len);
diff --git a/shaping/test/gtest_shaper.cpp b/shaping/test/gtest_shaper.cpp
index e735d7f..905a4f8 100644
--- a/shaping/test/gtest_shaper.cpp
+++ b/shaping/test/gtest_shaper.cpp
@@ -250,11 +250,12 @@ TEST(single_session, udp_tx_in_order)
/**********send packets*********************/
- send_packets(&ctx->thread_ctx[0], sf, 100, 100, SHAPING_DIR_OUT, &expec_tx_queue, 1, 0);
+ send_packets(&ctx->thread_ctx[0], sf, 101, 100, SHAPING_DIR_OUT, &expec_tx_queue, 1, 0);
/*******************************************/
//first 10 packets
ASSERT_EQ(0, judge_packet_eq(&expec_tx_queue, actual_tx_queue, 10));
+ ASSERT_EQ(0, judge_packet_eq(&expec_tx_queue, actual_tx_queue, 1));//async pass 1 packet
ASSERT_TRUE(TAILQ_EMPTY(actual_tx_queue));
while (!TAILQ_EMPTY(&expec_tx_queue)) {//last 90 delay packets
@@ -287,7 +288,7 @@ TEST(single_session, udp_tx_in_order)
stat_file = fopen(SHAPING_STAT_FILE_NAME, "r");
memset(line, 0, sizeof(line));
ASSERT_TRUE(NULL != fgets(line, sizeof(line), stat_file));
- shaping_stat_judge(line, 0, 0, 1, 100, 10000, 0, 0, 171000, SHAPING_DIR_OUT, profile_type_primary);//max latency is last 10 pkts
+ shaping_stat_judge(line, 0, 0, 1, 101, 10100, 0, 0, 171000, SHAPING_DIR_OUT, profile_type_primary);//max latency is last 10 pkts
fclose(stat_file);
stat_file = fopen(SHAPING_STAT_FILE_NAME, "w");//clear stat file
fclose(stat_file);
@@ -296,7 +297,7 @@ TEST(single_session, udp_tx_in_order)
stat_file = fopen(SHAPING_GLOBAL_STAT_FILE_NAME, "r");
memset(line, 0, sizeof(line));
ASSERT_TRUE(NULL != fgets(line, sizeof(line), stat_file));
- shaping_global_stat_judge(line, 100, 10000, 0, 0, 0, 0);
+ shaping_global_stat_judge(line, 101, 10100, 0, 0, 0, 0);
fclose(stat_file);
}
@@ -392,11 +393,12 @@ TEST(max_min_host_fairness_profile, udp_tx_in_order)
/**********send packets*********************/
- send_packets(&ctx->thread_ctx[0], sf, 100, 100, SHAPING_DIR_OUT, &expec_tx_queue, 1, 0);
+ send_packets(&ctx->thread_ctx[0], sf, 101, 100, SHAPING_DIR_OUT, &expec_tx_queue, 1, 0);
/*******************************************/
//first 10 packets
ASSERT_EQ(0, judge_packet_eq(&expec_tx_queue, actual_tx_queue, 10));
+ ASSERT_EQ(0, judge_packet_eq(&expec_tx_queue, actual_tx_queue, 1));//async pass 1 packet
ASSERT_TRUE(TAILQ_EMPTY(actual_tx_queue));
while (!TAILQ_EMPTY(&expec_tx_queue)) {//last 90 delay packets
@@ -429,7 +431,7 @@ TEST(max_min_host_fairness_profile, udp_tx_in_order)
stat_file = fopen(SHAPING_STAT_FILE_NAME, "r");
memset(line, 0, sizeof(line));
ASSERT_TRUE(NULL != fgets(line, sizeof(line), stat_file));
- shaping_stat_judge(line, 0, 0, 1, 100, 10000, 0, 0, 171000, SHAPING_DIR_OUT, profile_type_primary);//max latency is last 10 pkts
+ shaping_stat_judge(line, 0, 0, 1, 101, 10100, 0, 0, 172000, SHAPING_DIR_OUT, profile_type_primary);//max latency is last 10 pkts
fclose(stat_file);
stat_file = fopen(SHAPING_STAT_FILE_NAME, "w");//clear stat file
fclose(stat_file);
@@ -438,7 +440,7 @@ TEST(max_min_host_fairness_profile, udp_tx_in_order)
stat_file = fopen(SHAPING_GLOBAL_STAT_FILE_NAME, "r");
memset(line, 0, sizeof(line));
ASSERT_TRUE(NULL != fgets(line, sizeof(line), stat_file));
- shaping_global_stat_judge(line, 100, 10000, 0, 0, 0, 0);
+ shaping_global_stat_judge(line, 101, 10100, 0, 0, 0, 0);
fclose(stat_file);
}
@@ -471,11 +473,12 @@ TEST(single_session, tcp_tx_in_order)
shaper_rules_update(&ctx->thread_ctx[0], sf, rule_id, 1);
/*******send packets***********/
- send_packets(&ctx->thread_ctx[0], sf, 20, 100, SHAPING_DIR_OUT, &expec_tx_queue, 1, 0);
+ send_packets(&ctx->thread_ctx[0], sf, 21, 100, SHAPING_DIR_OUT, &expec_tx_queue, 1, 0);
send_packets(&ctx->thread_ctx[0], sf, 10, 100, SHAPING_DIR_OUT, &expec_pure_ctl_tx_queue, 1, 1);
//first 10 packets
ASSERT_EQ(0, judge_packet_eq(&expec_tx_queue, actual_tx_queue, 10));
+ ASSERT_EQ(0, judge_packet_eq(&expec_tx_queue, actual_tx_queue, 1));//async pass 1 packet
//10 pure ctrl pkts
ASSERT_EQ(0, judge_packet_eq(&expec_pure_ctl_tx_queue, actual_tx_queue, 10));
ASSERT_TRUE(TAILQ_EMPTY(actual_tx_queue));
@@ -519,7 +522,7 @@ TEST(single_session, tcp_tx_in_order)
stat_file = fopen(SHAPING_STAT_FILE_NAME, "r");
memset(line, 0, sizeof(line));
ASSERT_TRUE(NULL != fgets(line, sizeof(line), stat_file));
- shaping_stat_judge(line, 0, 0, 1, 20, 2000, 0, 10, 0, SHAPING_DIR_OUT, profile_type_primary);
+ shaping_stat_judge(line, 0, 0, 1, 21, 2100, 0, 10, 0, SHAPING_DIR_OUT, profile_type_primary);
ASSERT_TRUE(NULL != fgets(line, sizeof(line), stat_file));
shaping_stat_judge(line, 0, 0, 1, 10, 1000, 0, 0, 31000, SHAPING_DIR_OUT, profile_type_primary);
@@ -597,9 +600,9 @@ TEST(single_session, udp_diff_direction)
stat_file = fopen(SHAPING_STAT_FILE_NAME, "r");
memset(line, 0, sizeof(line));
ASSERT_TRUE(NULL != fgets(line, sizeof(line), stat_file));
- shaping_stat_judge(line, 0, 0, 1, 20, 2000, 0, 0, 21000, SHAPING_DIR_OUT, profile_type_primary);
+ shaping_stat_judge(line, 0, 0, 1, 20, 2000, 0, 0, 20000, SHAPING_DIR_OUT, profile_type_primary);
- shaping_stat_judge(line, 0, 0, 1, 20, 2000, 0, 0, 21000, SHAPING_DIR_IN, profile_type_primary);
+ shaping_stat_judge(line, 0, 0, 1, 20, 2000, 0, 0, 20000, SHAPING_DIR_IN, profile_type_primary);
fclose(stat_file);
stat_file = fopen(SHAPING_STAT_FILE_NAME, "w");//clear stat file
fclose(stat_file);
@@ -638,11 +641,12 @@ TEST(single_session, udp_multi_rules)
shaper_rules_update(&ctx->thread_ctx[0], sf, rule_id, 3);
/*******send packets***********/
- send_packets(&ctx->thread_ctx[0], sf, 100, 100, SHAPING_DIR_OUT, &expec_tx_queue, 5, 0);
+ send_packets(&ctx->thread_ctx[0], sf, 101, 100, SHAPING_DIR_OUT, &expec_tx_queue, 5, 0);
//first 10 packets
ASSERT_EQ(0, judge_packet_eq(&expec_tx_queue, actual_tx_queue, 10));
+ ASSERT_EQ(0, judge_packet_eq(&expec_tx_queue, actual_tx_queue, 1));//async pass 1 packet
while (!TAILQ_EMPTY(&expec_tx_queue)) {//last 90 delay packets
stub_refresh_token_bucket(0);
@@ -675,13 +679,13 @@ TEST(single_session, udp_multi_rules)
stat_file = fopen(SHAPING_STAT_FILE_NAME, "r");
memset(line, 0, sizeof(line));
ASSERT_TRUE(NULL != fgets(line, sizeof(line), stat_file));//profile_id 0
- shaping_stat_judge(line, 0, 0, 1, 100, 10000, 0, 0, 507000, SHAPING_DIR_OUT, profile_type_primary);
+ shaping_stat_judge(line, 0, 0, 1, 101, 10100, 0, 0, 507000, SHAPING_DIR_OUT, profile_type_primary);
ASSERT_TRUE(NULL != fgets(line, sizeof(line), stat_file));//profile_id 1
- shaping_stat_judge(line, 1, 1, 1, 100, 10000, 0, 0, 1000, SHAPING_DIR_OUT, profile_type_primary);
+ shaping_stat_judge(line, 1, 1, 1, 101, 10100, 0, 0, 1000, SHAPING_DIR_OUT, profile_type_primary);
ASSERT_TRUE(NULL != fgets(line, sizeof(line), stat_file));//profile_id 2
- shaping_stat_judge(line, 2, 2, 1, 100, 10000, 0, 0, 91000, SHAPING_DIR_OUT, profile_type_primary);//max latency is first queued pkt
+ shaping_stat_judge(line, 2, 2, 1, 101, 10100, 0, 0, 91000, SHAPING_DIR_OUT, profile_type_primary);//max latency is first queued pkt
fclose(stat_file);
stat_file = fopen(SHAPING_STAT_FILE_NAME, "w");//clear stat file
@@ -717,11 +721,12 @@ TEST(single_session, udp_borrow)
shaper_rules_update(&ctx->thread_ctx[0], sf, rule_id, 1);
/*******send packets***********/
- send_packets(&ctx->thread_ctx[0], sf, 100, 100, SHAPING_DIR_OUT, &expec_tx_queue, 1, 0);
+ send_packets(&ctx->thread_ctx[0], sf, 101, 100, SHAPING_DIR_OUT, &expec_tx_queue, 1, 0);
//first 10 packets
ASSERT_EQ(0, judge_packet_eq(&expec_tx_queue, actual_tx_queue, 10));
+ ASSERT_EQ(0, judge_packet_eq(&expec_tx_queue, actual_tx_queue, 1));//async pass 1 packet
while (!TAILQ_EMPTY(&expec_tx_queue)) {//last 90 delay packets
stub_refresh_token_bucket(2);
@@ -753,7 +758,7 @@ TEST(single_session, udp_borrow)
shaping_stat_judge(line, 1, 1, 1, 0, 0, 0, 0, 171000, SHAPING_DIR_OUT, profile_type_primary);
ASSERT_TRUE(NULL != fgets(line, sizeof(line), stat_file));//profile_id 2, borrow
- shaping_stat_judge(line, 1, 2, 2, 100, 10000, 0, 0, 0, SHAPING_DIR_OUT, profile_type_borrow);
+ shaping_stat_judge(line, 1, 2, 2, 101, 10100, 0, 0, 0, SHAPING_DIR_OUT, profile_type_borrow);
fclose(stat_file);
stat_file = fopen(SHAPING_STAT_FILE_NAME, "w");//clear stat file
@@ -792,11 +797,12 @@ TEST(single_session, udp_borrow_same_priority_9)
shaper_rules_update(&ctx->thread_ctx[0], sf, rule_id, 1);
/*******send packets***********/
- send_packets(&ctx->thread_ctx[0], sf, 100, 100, SHAPING_DIR_OUT, &expec_tx_queue, 1, 0);
+ send_packets(&ctx->thread_ctx[0], sf, 101, 100, SHAPING_DIR_OUT, &expec_tx_queue, 1, 0);
//first 10 packets
ASSERT_EQ(0, judge_packet_eq(&expec_tx_queue, actual_tx_queue, 10));
+ ASSERT_EQ(0, judge_packet_eq(&expec_tx_queue, actual_tx_queue, 1));//async pass 1 packet
while (!TAILQ_EMPTY(&expec_tx_queue)) {//last 90 delay packets
stub_refresh_token_bucket(3);
@@ -833,7 +839,7 @@ TEST(single_session, udp_borrow_same_priority_9)
#endif
ASSERT_TRUE(NULL != fgets(line, sizeof(line), stat_file));//profile_id 3, borrow
- shaping_stat_judge(line, 1, 3, 9, 100, 10000, 0, 0, 0, SHAPING_DIR_OUT, profile_type_borrow);
+ shaping_stat_judge(line, 1, 3, 9, 101, 10100, 0, 0, 0, SHAPING_DIR_OUT, profile_type_borrow);
fclose(stat_file);
stat_file = fopen(SHAPING_STAT_FILE_NAME, "w");//clear stat file
@@ -939,12 +945,22 @@ TEST(two_session_diff_priority_same_profile, udp_borrow_in_order)
/*******send packets***********/
- send_packets(&ctx->thread_ctx[0], sf1, 100, 100, SHAPING_DIR_OUT, &expec_tx_queue1, 1, 0);
- send_packets(&ctx->thread_ctx[0], sf2, 100, 100, SHAPING_DIR_OUT, &expec_tx_queue2, 1, 0);
+ send_packets(&ctx->thread_ctx[0], sf1, 101, 100, SHAPING_DIR_OUT, &expec_tx_queue1, 1, 0);
+ send_packets(&ctx->thread_ctx[0], sf2, 101, 100, SHAPING_DIR_OUT, &expec_tx_queue2, 1, 0);
//first 10 packets
ASSERT_EQ(0, judge_packet_eq(&expec_tx_queue1, actual_tx_queue, 10));
+ ASSERT_EQ(0, judge_packet_eq(&expec_tx_queue1, actual_tx_queue, 1));//async pass 1 packet
+ ASSERT_TRUE(TAILQ_EMPTY(actual_tx_queue));
+
+ stub_refresh_token_bucket(2);
+ for (int i = 0; i < 20; i++) {
+ polling_entry(ctx->thread_ctx[0].sp, ctx->thread_ctx[0].stat, &ctx->thread_ctx[0]);
+ stub_curr_time_ns_inc(STUB_TIME_INC_FOR_PACKET);
+ }
+ ASSERT_EQ(0, judge_packet_eq(&expec_tx_queue2, actual_tx_queue, 10));
+ ASSERT_EQ(0, judge_packet_eq(&expec_tx_queue2, actual_tx_queue, 1));//async pass 1 packet
ASSERT_TRUE(TAILQ_EMPTY(actual_tx_queue));
while (!TAILQ_EMPTY(&expec_tx_queue2)) {
@@ -987,13 +1003,13 @@ TEST(two_session_diff_priority_same_profile, udp_borrow_in_order)
stat_file = fopen(SHAPING_STAT_FILE_NAME, "r");
memset(line, 0, sizeof(line));
ASSERT_TRUE(NULL != fgets(line, sizeof(line), stat_file));//profile_id 1, primary
- shaping_stat_judge(line, 1, 1, 1, 0, 0, 0, 0, 1471000, SHAPING_DIR_OUT, profile_type_primary);
+ shaping_stat_judge(line, 1, 1, 1, 0, 0, 0, 0, 1472000, SHAPING_DIR_OUT, profile_type_primary);
ASSERT_TRUE(NULL != fgets(line, sizeof(line), stat_file));//profile_id 2, borrow
- shaping_stat_judge(line, 1, 2, 2, 100, 10000, 0, 0, 0, SHAPING_DIR_OUT, profile_type_borrow);
+ shaping_stat_judge(line, 1, 2, 2, 101, 10100, 0, 0, 0, SHAPING_DIR_OUT, profile_type_borrow);
ASSERT_TRUE(NULL != fgets(line, sizeof(line), stat_file));//profile_id 2, primary
- shaping_stat_judge(line, 2, 2, 1, 100, 10000, 0, 0, 191000, SHAPING_DIR_OUT, profile_type_primary);
+ shaping_stat_judge(line, 2, 2, 1, 101, 10100, 0, 0, 191000, SHAPING_DIR_OUT, profile_type_primary);
fclose(stat_file);
stat_file = fopen(SHAPING_STAT_FILE_NAME, "w");//clear stat file
@@ -1048,6 +1064,7 @@ TEST(two_session_diff_priority_same_profile, two_thread_udp_tx_in_order)
send_packets(&ctx->thread_ctx[0], sf1, 100, 100, SHAPING_DIR_OUT, &expec_tx_queue1, 1, 0);
send_packets(&ctx->thread_ctx[1], sf2, 100, 100, SHAPING_DIR_OUT, &expec_tx_queue2, 1, 0);
ASSERT_EQ(0, judge_packet_eq(&expec_tx_queue1, actual_tx_queue, 10));
+ ASSERT_EQ(0, judge_packet_eq(&expec_tx_queue1, actual_tx_queue, 1));//async pass 1 packet
ASSERT_TRUE(TAILQ_EMPTY(actual_tx_queue));
shaper_stat_refresh(&ctx->thread_ctx[0], sf1, 1);//刷新线程0中的优先级队列长度到swarmkv中
@@ -1134,6 +1151,7 @@ TEST(two_session_diff_priority_same_profile, profile_timer_test)
send_packets(&ctx->thread_ctx[0], sf1, 100, 100, SHAPING_DIR_OUT, &expec_tx_queue1, 1, 0);
send_packets(&ctx->thread_ctx[1], sf2, 100, 100, SHAPING_DIR_OUT, &expec_tx_queue2, 1, 0);
ASSERT_EQ(0, judge_packet_eq(&expec_tx_queue1, actual_tx_queue, 10));
+ ASSERT_EQ(0, judge_packet_eq(&expec_tx_queue1, actual_tx_queue, 1));//async pass 1 packet
ASSERT_TRUE(TAILQ_EMPTY(actual_tx_queue));
sleep(3);//wait profile timer to expire, to refresh priority queue_len to swarmkv
@@ -1241,6 +1259,8 @@ TEST(two_sessions, priority_non_block)
send_packets(&ctx->thread_ctx[0], sf1, 100, 100, SHAPING_DIR_OUT, &expec_tx_queue1, 3, 0);//sf1 blocked by rule2(profile id 1), while rule3(profile id 0) still has 1000 token
send_packets(&ctx->thread_ctx[1], sf2, 10, 100, SHAPING_DIR_OUT, &expec_tx_queue2, 1, 0);
ASSERT_EQ(0, judge_packet_eq(&expec_tx_queue1, actual_tx_queue, 10));//sf1 should send 10 pkts
+ ASSERT_EQ(0, judge_packet_eq(&expec_tx_queue1, actual_tx_queue, 1));//sf1 async pass 1 pkts
+
ASSERT_EQ(0, judge_packet_eq(&expec_tx_queue2, actual_tx_queue, 10));//sf2 should send 10 pkts cause rule3(profile id 0) has 1000 token
ASSERT_TRUE(TAILQ_EMPTY(actual_tx_queue));
@@ -1314,6 +1334,7 @@ TEST(two_sessions, borrow_when_primary_profile_priority_blocked)
send_packets(&ctx->thread_ctx[0], sf1, 100, 100, SHAPING_DIR_OUT, &expec_tx_queue1, 1, 0);
send_packets(&ctx->thread_ctx[1], sf2, 100, 100, SHAPING_DIR_OUT, &expec_tx_queue2, 1, 0);
ASSERT_EQ(0, judge_packet_eq(&expec_tx_queue1, actual_tx_queue, 10));
+ ASSERT_EQ(0, judge_packet_eq(&expec_tx_queue1, actual_tx_queue, 1));//async pass 1 packet
while (!TAILQ_EMPTY(&expec_tx_queue2)) {
stub_refresh_token_bucket(1);
@@ -1386,10 +1407,13 @@ TEST(two_sessions, primary_profile_priority_blocked_by_borrow_profile)
shaper_rules_update(&ctx->thread_ctx[1], sf2, rule_id2, 1);
/*******send packets***********/
- send_packets(&ctx->thread_ctx[0], sf1, 100, 100, SHAPING_DIR_OUT, &expec_tx_queue1, 1, 0);
+ send_packets(&ctx->thread_ctx[0], sf1, 101, 100, SHAPING_DIR_OUT, &expec_tx_queue1, 1, 0);
send_packets(&ctx->thread_ctx[1], sf2, 100, 100, SHAPING_DIR_OUT, &expec_tx_queue2, 1, 0);
ASSERT_EQ(0, judge_packet_eq(&expec_tx_queue1, actual_tx_queue, 10));
+ ASSERT_EQ(0, judge_packet_eq(&expec_tx_queue1, actual_tx_queue, 1));//async pass 1 packet
+ ASSERT_TRUE(TAILQ_EMPTY(actual_tx_queue));
+
while (!TAILQ_EMPTY(&expec_tx_queue1)) {
stub_refresh_token_bucket(1);
polling_entry(ctx->thread_ctx[0].sp, ctx->thread_ctx[0].stat, &ctx->thread_ctx[0]);
@@ -1444,11 +1468,12 @@ TEST(statistics, udp_drop_pkt)
shaper_rules_update(&ctx->thread_ctx[0], sf, rule_id, 1);
/*******send packets***********/
- send_packets(&ctx->thread_ctx[0], sf, SHAPING_SESSION_QUEUE_LEN + 10, 100, SHAPING_DIR_OUT, &expec_tx_queue, 1, 0);
+ send_packets(&ctx->thread_ctx[0], sf, SHAPING_SESSION_QUEUE_LEN + 10 + 1, 100, SHAPING_DIR_OUT, &expec_tx_queue, 1, 0);
send_packets(&ctx->thread_ctx[0], sf, 100, 100, SHAPING_DIR_OUT, NULL, 1, 0);//these 100 pkts will be dropped
//first 10 packets
ASSERT_EQ(0, judge_packet_eq(&expec_tx_queue, actual_tx_queue, 10));
+ ASSERT_EQ(0, judge_packet_eq(&expec_tx_queue, actual_tx_queue, 1));//async pass 1 packet
ASSERT_TRUE(TAILQ_EMPTY(actual_tx_queue));
while (!TAILQ_EMPTY(&expec_tx_queue)) {
@@ -1478,7 +1503,7 @@ TEST(statistics, udp_drop_pkt)
stat_file = fopen(SHAPING_STAT_FILE_NAME, "r");
memset(line, 0, sizeof(line));
ASSERT_TRUE(NULL != fgets(line, sizeof(line), stat_file));
- shaping_stat_judge(line, 0, 0, 1, SHAPING_SESSION_QUEUE_LEN+10, (SHAPING_SESSION_QUEUE_LEN+10)*100, 100, 0, 228000, SHAPING_DIR_OUT, profile_type_primary);//every queued pkt's latency is max
+ shaping_stat_judge(line, 0, 0, 1, SHAPING_SESSION_QUEUE_LEN+10+1, (SHAPING_SESSION_QUEUE_LEN+10+1)*100, 100, 0, 228000, SHAPING_DIR_OUT, profile_type_primary);//every queued pkt's latency is max
fclose(stat_file);
stat_file = fopen(SHAPING_STAT_FILE_NAME, "w");//clear stat file
fclose(stat_file);
@@ -1487,7 +1512,7 @@ TEST(statistics, udp_drop_pkt)
stat_file = fopen(SHAPING_GLOBAL_STAT_FILE_NAME, "r");
memset(line, 0, sizeof(line));
ASSERT_TRUE(NULL != fgets(line, sizeof(line), stat_file));
- shaping_global_stat_judge(line, SHAPING_SESSION_QUEUE_LEN+10, (SHAPING_SESSION_QUEUE_LEN+10)*100, 100, 10000, 0, 0);
+ shaping_global_stat_judge(line, SHAPING_SESSION_QUEUE_LEN+10+1, (SHAPING_SESSION_QUEUE_LEN+10+1)*100, 100, 10000, 0, 0);
fclose(stat_file);
}
@@ -1520,7 +1545,7 @@ TEST(statistics, udp_queueing_pkt)
shaper_rules_update(&ctx->thread_ctx[0], sf, rule_id, 1);
/*******send packets***********/
- send_packets(&ctx->thread_ctx[0], sf, 100, 100, SHAPING_DIR_OUT, &expec_tx_queue, 1, 0);
+ send_packets(&ctx->thread_ctx[0], sf, 101, 100, SHAPING_DIR_OUT, &expec_tx_queue, 1, 0);
/***********send stat data here********************/
@@ -1533,11 +1558,12 @@ TEST(statistics, udp_queueing_pkt)
stat_file = fopen(SHAPING_GLOBAL_STAT_FILE_NAME, "r");
memset(line, 0, sizeof(line));
ASSERT_TRUE(NULL != fgets(line, sizeof(line), stat_file));
- shaping_global_stat_judge(line, 10, 1000, 0, 0, 90, 9000);
+ shaping_global_stat_judge(line, 11, 1100, 0, 0, 90, 9000);
fclose(stat_file);
//first 10 packets
ASSERT_EQ(0, judge_packet_eq(&expec_tx_queue, actual_tx_queue, 10));
+ ASSERT_EQ(0, judge_packet_eq(&expec_tx_queue, actual_tx_queue, 1));//async pass 1 packet
ASSERT_TRUE(TAILQ_EMPTY(actual_tx_queue));
while (!TAILQ_EMPTY(&expec_tx_queue)) {//last 90 delay packets
@@ -1567,7 +1593,7 @@ TEST(statistics, udp_queueing_pkt)
memset(line, 0, sizeof(line));
ASSERT_TRUE(NULL != fgets(line, sizeof(line), stat_file));//stat data first sent
- shaping_stat_judge(line, 0, 0, 1, 10, 1000, 0, 90, 0, SHAPING_DIR_OUT, profile_type_primary);
+ shaping_stat_judge(line, 0, 0, 1, 11, 1100, 0, 90, 0, SHAPING_DIR_OUT, profile_type_primary);
ASSERT_TRUE(NULL != fgets(line, sizeof(line), stat_file));//stat data last sent
shaping_stat_judge(line, 0, 0, 1, 90, 9000, 0, 0, 90000, SHAPING_DIR_OUT, profile_type_primary);