diff options
| author | 刘畅 <[email protected]> | 2024-01-09 08:29:08 +0000 |
|---|---|---|
| committer | 刘畅 <[email protected]> | 2024-01-09 08:29:08 +0000 |
| commit | 9a54fa318e5f744c2e545e25f6eff9bac4722de0 (patch) | |
| tree | ad90f13e0866045d6a7afe5aa45f5ecad71b1c9d | |
| parent | 7c599b8c88ecc009651062eddbff0b07909b8928 (diff) | |
| parent | 5f4d71b683d3d460bb0785a9426a4f12c81d99c9 (diff) | |
Merge branch 'bugfix_ignore_dup_primary_profile' into 'rel'v3.1.20
同一个profile作为primary profile只处理一次
See merge request tango/shaping-engine!70
| -rw-r--r-- | shaping/include/shaper.h | 1 | ||||
| -rw-r--r-- | shaping/src/shaper.cpp | 5 | ||||
| -rw-r--r-- | shaping/src/shaper_maat.cpp | 16 | ||||
| -rw-r--r-- | shaping/src/shaper_stat.cpp | 4 | ||||
| -rw-r--r-- | shaping/test/gtest_shaper.cpp | 58 | ||||
| -rw-r--r-- | shaping/test/gtest_shaper_maat.cpp | 49 |
6 files changed, 131 insertions, 2 deletions
diff --git a/shaping/include/shaper.h b/shaping/include/shaper.h index 33eb103..b7741a3 100644 --- a/shaping/include/shaper.h +++ b/shaping/include/shaper.h @@ -113,6 +113,7 @@ struct shaping_rule_info { int vsys_id; int id;//rule_id int fair_factor; + int has_dup_profile; struct shaping_profile_info primary; struct shaping_profile_info borrowing[SHAPING_REF_PROFILE_NUM_MAX]; int borrowing_num; diff --git a/shaping/src/shaper.cpp b/shaping/src/shaper.cpp index 5a53232..6ea2afe 100644 --- a/shaping/src/shaper.cpp +++ b/shaping/src/shaper.cpp @@ -729,8 +729,11 @@ static int shaper_token_consume(struct shaping_thread_ctx *ctx, struct shaping_f } struct shaping_rule_info *rule = &sf->matched_rule_infos[sf->anchor]; + if (rule->has_dup_profile) { + return SHAPER_TOKEN_GET_PASS;//dup profile, don't need to get token and forward packet + } + time_t curr_time = time(NULL); - if (curr_time - sf->check_rule_time >= ctx->conf.check_rule_enable_interval_sec) { sf->check_rule_time = curr_time; if (shaper_rule_is_enabled(ctx, rule->id) != 1) { diff --git a/shaping/src/shaper_maat.cpp b/shaping/src/shaper_maat.cpp index f159c2f..f48f68e 100644 --- a/shaping/src/shaper_maat.cpp +++ b/shaping/src/shaper_maat.cpp @@ -358,6 +358,20 @@ static int shaper_rules_dup_remove(struct shaping_flow *sf, long long *rule_comp return rule_num_remove_dup; } +static void shaper_rules_dup_profile_check(struct shaping_flow *sf) +{ + for (int i = 0; i < sf->rule_num; i++) { + for (int j = i + 1; j < sf->rule_num; j++) { + if (sf->matched_rule_infos[i].primary.id == sf->matched_rule_infos[j].primary.id) { + sf->matched_rule_infos[j].has_dup_profile = 1; + LOG_INFO("%s: shaping rule %d and %d have same primary profile %d", LOG_TAG_MAAT, sf->matched_rule_infos[i].id, sf->matched_rule_infos[j].id, sf->matched_rule_infos[i].primary.id); + } + } + } + + return; +} + void shaper_rules_update(struct shaping_thread_ctx *ctx, struct shaping_flow *sf, long long *rule_compile_ids, int rule_num) { int i, j; @@ -399,6 +413,8 @@ void shaper_rules_update(struct shaping_thread_ctx *ctx, struct shaping_flow *sf sf->rule_num += rule_num_remove_dup; shaper_profiles_priority_update(sf); + shaper_rules_dup_profile_check(sf); + return; } diff --git a/shaping/src/shaper_stat.cpp b/shaping/src/shaper_stat.cpp index db5b5f7..24edc08 100644 --- a/shaping/src/shaper_stat.cpp +++ b/shaping/src/shaper_stat.cpp @@ -276,6 +276,10 @@ void shaper_stat_forward_all_rule_inc(struct shaping_stat *stat, struct shaping_ for (i = 0; i < sf->rule_num; i++) { rule = &sf->matched_rule_infos[i]; + if (rule->has_dup_profile || !rule->is_enabled) { + continue; + } + shaper_stat_forward_inc(&rule->primary.stat, direction, pkt_len, thread_id); } diff --git a/shaping/test/gtest_shaper.cpp b/shaping/test/gtest_shaper.cpp index b129c25..d72a410 100644 --- a/shaping/test/gtest_shaper.cpp +++ b/shaping/test/gtest_shaper.cpp @@ -1655,6 +1655,62 @@ TEST(two_sessions, priority_block_borrow) /*session1 match rule1 rule1: + profile_a + rule2: + profile_a + + profile_a(id 0): limit 1000 +*/ +TEST(single_session, dup_primary_profile)//dup primary profile, just process the first rule and ignore others +{ + struct stub_pkt_queue expec_tx_queue; + struct stub_pkt_queue *actual_tx_queue; + struct shaping_ctx *ctx = NULL; + struct shaping_flow *sf = NULL; + long long rule_ids[] = {1, 2}; + int profile_nums[] = {1, 1}; + int prioritys[] = {1, 2}; + int profile_id[][MAX_REF_PROFILE] = {{0}, {0}}; + + + TAILQ_INIT(&expec_tx_queue); + stub_init(); + + ctx = shaping_engine_init(); + ASSERT_TRUE(ctx != NULL); + sf = shaping_flow_new(&ctx->thread_ctx[0]); + ASSERT_TRUE(sf != NULL); + + stub_set_matched_shaping_rules(2, rule_ids, prioritys, profile_nums, profile_id); + + stub_set_token_bucket_avl_per_sec(0, 1000, SHAPING_DIR_OUT); + actual_tx_queue = stub_get_tx_queue(); + shaper_rules_update(&ctx->thread_ctx[0], sf, rule_ids, 2); + + /*******send packets***********/ + send_packets(&ctx->thread_ctx[0], sf, 100, 100, SHAPING_DIR_OUT, &expec_tx_queue, 2, 0); + ASSERT_EQ(0, judge_packet_eq(&expec_tx_queue, actual_tx_queue, 10)); + ASSERT_TRUE(TAILQ_EMPTY(actual_tx_queue)); + + while (!TAILQ_EMPTY(&expec_tx_queue)) {//last 90 packets + stub_refresh_token_bucket(0); + 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_queue, actual_tx_queue, 10)); + ASSERT_TRUE(TAILQ_EMPTY(actual_tx_queue)); + } + + shaping_flow_free(&ctx->thread_ctx[0], sf); + fieldstat_global_disable_prometheus_endpoint(); + shaper_thread_resource_clear(); + shaping_engine_destroy(ctx); + stub_clear_matched_shaping_rules(); +} + +/*session1 match rule1 + rule1: profile: limit 1000*/ TEST(statistics, udp_drop_pkt) { @@ -1821,6 +1877,6 @@ TEST(statistics, udp_queueing_pkt) int main(int argc, char **argv) { testing::InitGoogleTest(&argc, argv); - //testing::GTEST_FLAG(filter) = "two_sessions.priority_block_borrow"; + //testing::GTEST_FLAG(filter) = "single_session.dup_primary_profile"; return RUN_ALL_TESTS(); }
\ No newline at end of file diff --git a/shaping/test/gtest_shaper_maat.cpp b/shaping/test/gtest_shaper_maat.cpp index ff94efe..25d8dee 100644 --- a/shaping/test/gtest_shaper_maat.cpp +++ b/shaping/test/gtest_shaper_maat.cpp @@ -178,6 +178,55 @@ TEST(shaping_flow, update_rule_dup) free(ctx.maat_info); } +TEST(shaping_flow, update_primary_profile_dup) +{ + struct shaping_thread_ctx ctx; + struct shaping_flow sf; + struct shaping_rule_info *rule_info; + long long rule_ids[] = {1, 2, 3}; + int prioritys[] = {1, 2, 3}; + int profile_nums[] = {1, 1, 1}; + int profile_ids[][MAX_REF_PROFILE] = {{1}, {1}, {1}}; + + stub_init(); + + stub_set_matched_shaping_rules(3, rule_ids, prioritys, profile_nums, profile_ids); + + ctx.maat_info = (struct shaping_maat_info *)calloc(1, sizeof(struct shaping_maat_info)); + ctx.maat_info->rule_table_id = STUB_MAAT_SHAPING_RULE_TABLE_ID; + ctx.maat_info->profile_table_id = STUB_MAAT_SHAPING_PROFILE_TABLE_ID; + + memset(&sf, 0, sizeof(sf)); + sf.priority = SHAPING_PRIORITY_NUM_MAX; + + shaper_rules_update(&ctx, &sf, rule_ids, 3); + + EXPECT_EQ(sf.rule_num, 3); + + rule_info = &sf.matched_rule_infos[0]; + EXPECT_EQ(rule_info->id, 1); + EXPECT_EQ(rule_info->primary.id, 1); + EXPECT_EQ(rule_info->primary.priority, 1); + EXPECT_EQ(rule_info->borrowing_num, 0); + EXPECT_EQ(rule_info->has_dup_profile, 0); + + rule_info = &sf.matched_rule_infos[1]; + EXPECT_EQ(rule_info->id, 2); + EXPECT_EQ(rule_info->primary.id, 1); + EXPECT_EQ(rule_info->primary.priority, 1); + EXPECT_EQ(rule_info->borrowing_num, 0); + EXPECT_EQ(rule_info->has_dup_profile, 1); + + rule_info = &sf.matched_rule_infos[2]; + EXPECT_EQ(rule_info->id, 3); + EXPECT_EQ(rule_info->primary.id, 1); + EXPECT_EQ(rule_info->primary.priority, 1); + EXPECT_EQ(rule_info->borrowing_num, 0); + EXPECT_EQ(rule_info->has_dup_profile, 1); + + free(ctx.maat_info); +} + TEST(shaping_flow, update_rule_after_priority_confirmed) { struct shaping_thread_ctx ctx; |
