From 975bb8b43047abd4d7c6fa674f44f6b6dd4ae376 Mon Sep 17 00:00:00 2001 From: liuchang Date: Fri, 14 Apr 2023 03:36:38 +0000 Subject: directly forward tcp pure control packet, ignoring queue len --- shaping/src/shaper.cpp | 14 +++++++------- shaping/test/gtest_shaper.cpp | 19 +++++++++---------- 2 files changed, 16 insertions(+), 17 deletions(-) diff --git a/shaping/src/shaper.cpp b/shaping/src/shaper.cpp index 554b2b9..76bc555 100644 --- a/shaping/src/shaper.cpp +++ b/shaping/src/shaper.cpp @@ -769,6 +769,13 @@ void shaping_packet_process(struct shaping_thread_ctx *ctx, marsio_buff_t *rx_bu struct shaping_marsio_info *marsio_info = ctx->marsio_info; struct timespec curr_time; + if (meta->is_tcp_pure_ctrl) { + marsio_send_burst(marsio_info->mr_path, ctx->thread_index, &rx_buff, 1); + shaper_global_stat_throughput_inc(ctx->global_stat, SHAPING_GLOBAL_STAT_TX, meta->raw_len); + shaper_stat_forward_all_rule_inc(stat, sf, meta->dir, meta->raw_len, ctx->thread_index); + goto JUDGE_CLOSE;//for tcp pure control pkt, transmit it directly + } + clock_gettime(CLOCK_MONOTONIC, &curr_time); if (!shaper_queue_empty(sf)) {//already have queueing pkt, enqueue directly s_rule = &sf->matched_rule_infos[0]; @@ -784,13 +791,6 @@ void shaping_packet_process(struct shaping_thread_ctx *ctx, marsio_buff_t *rx_bu } } else { - if (meta->is_tcp_pure_ctrl) { - marsio_send_burst(marsio_info->mr_path, ctx->thread_index, &rx_buff, 1); - shaper_global_stat_throughput_inc(ctx->global_stat, SHAPING_GLOBAL_STAT_TX, meta->raw_len); - shaper_stat_forward_all_rule_inc(stat, sf, meta->dir, meta->raw_len, ctx->thread_index); - goto JUDGE_CLOSE;//for tcp pure control pkt, transmit it directly - } - if (0 != shaper_packet_enqueue(ctx, sf, rx_buff, &curr_time, meta)) { marsio_buff_free(marsio_info->instance, &rx_buff, 1, 0, ctx->thread_index); shaper_global_stat_drop_inc(ctx->global_stat, meta->raw_len); diff --git a/shaping/test/gtest_shaper.cpp b/shaping/test/gtest_shaper.cpp index 3f18a99..b6d0f9e 100644 --- a/shaping/test/gtest_shaper.cpp +++ b/shaping/test/gtest_shaper.cpp @@ -3,6 +3,7 @@ #include #include #include +#include #include "shaper.h" #include "shaper_maat.h" @@ -298,6 +299,7 @@ TEST(single_session, udp_tx_in_order) TEST(single_session, tcp_tx_in_order) { struct stub_pkt_queue expec_tx_queue; + struct stub_pkt_queue expec_pure_ctl_tx_queue; struct stub_pkt_queue *actual_tx_queue; struct shaping_ctx *ctx = NULL; struct shaping_flow *sf = NULL; @@ -307,6 +309,7 @@ TEST(single_session, tcp_tx_in_order) int profile_id[][MAX_REF_PROFILE] = {{0}}; TAILQ_INIT(&expec_tx_queue); + TAILQ_INIT(&expec_pure_ctl_tx_queue); stub_init(); ctx = shaping_engine_init(); ASSERT_TRUE(ctx != NULL); @@ -320,10 +323,12 @@ TEST(single_session, tcp_tx_in_order) /*******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, 20, 100, SHAPING_DIR_OUT, &expec_tx_queue, 1, 1); + send_packets(&ctx->thread_ctx[0], sf, 20, 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)); + //20 pure ctrl pkts + ASSERT_EQ(0, judge_packet_eq(&expec_pure_ctl_tx_queue, actual_tx_queue, 20)); ASSERT_TRUE(TAILQ_EMPTY(actual_tx_queue)); @@ -340,12 +345,6 @@ TEST(single_session, tcp_tx_in_order) } ASSERT_EQ(0, judge_packet_eq(&expec_tx_queue, actual_tx_queue, 10)); - while (!TAILQ_EMPTY(&expec_tx_queue)) {//20 pure contorl pkts - polling_entry(ctx->thread_ctx[0].sp, ctx->thread_ctx[0].stat, &ctx->thread_ctx[0]); - ASSERT_EQ(0, judge_packet_eq(&expec_tx_queue, actual_tx_queue, 1)); - stub_curr_time_inc(STUB_TIME_INC_FOR_PACKET); - } - /***********send stat data here********************/ stub_curr_time_inc(STUB_TIME_INC_FOR_METRIC_SEND);//inc time to send metric fieldstat_dynamic_passive_output(ctx->stat->instance);//send metric manualy @@ -362,10 +361,10 @@ 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, 10, 1000, 0, 30, 0, 1, SHAPING_DIR_OUT, profile_type_primary); + shaping_stat_judge(line, 0, 0, 1, 30, 3000, 0, 10, 0, 1, SHAPING_DIR_OUT, profile_type_primary); ASSERT_TRUE(NULL != fgets(line, sizeof(line), stat_file)); - shaping_stat_judge(line, 0, 0, 1, 30, 3000, 0, 0, 30 + (STUB_TIME_INC_FOR_METRIC_SEND / 1000), 0, SHAPING_DIR_OUT, profile_type_primary); + shaping_stat_judge(line, 0, 0, 1, 10, 1000, 0, 0, 30 + (STUB_TIME_INC_FOR_METRIC_SEND / 1000), 0, SHAPING_DIR_OUT, profile_type_primary); fclose(stat_file); stat_file = fopen(SHAPING_STAT_FILE_NAME, "w");//clear stat file @@ -1604,6 +1603,6 @@ TEST(statistics, udp_queueing_pkt) int main(int argc, char **argv) { testing::InitGoogleTest(&argc, argv); - //testing::GTEST_FLAG(filter) = "two_session_diff_priority_same_profile.udp_random_tx_in_order"; + //testing::GTEST_FLAG(filter) = "single_session.tcp_tx_in_order"; return RUN_ALL_TESTS(); } \ No newline at end of file -- cgit v1.2.3