From abc9363ac16db3fb396051dc0f41dc5f3638b688 Mon Sep 17 00:00:00 2001 From: yangyubo Date: Fri, 25 Aug 2023 11:00:23 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0mpack=E5=A4=84=E7=90=86?= =?UTF-8?q?=E5=8E=9F=E5=A7=8B=E8=B4=9F=E8=BD=BD=E7=9A=84=E6=B5=8B=E8=AF=95?= =?UTF-8?q?=E7=94=A8=E4=BE=8B;=E4=BF=AE=E5=A4=8D=E7=AC=94=E8=AF=AFtcp=5Fac?= =?UTF-8?q?k=5Fsids?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/tsg_proxy.cpp | 2 +- test/src/gtest_sync_state.cpp | 51 +++++++++++++++++++++++++++++++++-- 2 files changed, 50 insertions(+), 3 deletions(-) diff --git a/src/tsg_proxy.cpp b/src/tsg_proxy.cpp index 1ec7276..7e3bc9f 100644 --- a/src/tsg_proxy.cpp +++ b/src/tsg_proxy.cpp @@ -587,7 +587,7 @@ void tsg_proxy_update_policy_fill(const struct streaminfo *stream, struct update cmsg->tcp_ack_route_ctx.len = server->route_ctx_len; cmsg->tcp_ack_route_ctx.buff = (char *)server->route_ctx; - update_segment_sids(&cmsg->tcp_seq_sids, segment_ids->sid_list+1, segment_ids->sz_sidlist-1); // delete intercept sid + update_segment_sids(&cmsg->tcp_ack_sids, segment_ids->sid_list+1, segment_ids->sz_sidlist-1); // delete intercept sid update_segment_sids(&cmsg->tcp_ack_sids, server->sid_list.sid_list, server->sid_list.sz_sidlist); if (client->wscale_set && server->wscale_set) { diff --git a/test/src/gtest_sync_state.cpp b/test/src/gtest_sync_state.cpp index cb9fd1e..b478d87 100644 --- a/test/src/gtest_sync_state.cpp +++ b/test/src/gtest_sync_state.cpp @@ -12,12 +12,12 @@ #include "mpack.h" struct tsg_rt_para g_tsg_para; - +unsigned long long g_session_id = 10; extern int get_ctrl_pkt(char *buf, int len); unsigned long long tsg_get_stream_trace_id(const struct streaminfo *a_stream) { - return 10; + return g_session_id; } void *session_log_update_data_get(const struct streaminfo *a_stream, enum TSG_SERVICE service) @@ -1439,6 +1439,53 @@ TEST(LOG_UPDATE, ProxyTwice) mpack_data = NULL; } +// 16进制转字符串 +int hex_to_str(const char *hex_str, char *payload) +{ + int len = strlen(hex_str); + int i = 0, j = 0; + unsigned int num; + + for (i = 0; i < len; i += 2) + { + sscanf(hex_str + i, "%2x", &num); + payload[j] = (char)num; + j++; + i++; // 空格或者回车 + } + payload[j] = '\0'; + + printf("Hex string: %s\n", hex_str); + printf("ASCII string: %s\n", payload); + + return j; +} + +TEST(LOG_UPDATE, Payload) +{ + const char *hex_str = "85 a5 74 73 79 6e 63 a3 32 2e 30 aa 73 65 73 73 69 6f 6e 5f 69 64 cf 04 09 e2 7c a9 6d 90 e7 a5 73 74 61 74 65 a6 61 63 74 69 76 65 a6 6d 65 74 68 6f 64 aa 6c 6f 67 5f 75 70 64 61 74 65 a6 70 61 72 61 6d 73 81 a3 73 63 65 81 ae 73 66 5f 70 72 6f 66 69 6c 65 5f 69 64 73 90"; + char payload[1024] = {0}; + int len = hex_to_str(hex_str, payload); + + const struct streaminfo a_stream = {0}; + g_session_id = 291012675988459751; + EXPECT_EQ(-1, tsg_parse_log_update_payload(&a_stream, payload, len)); + + const char *hex_str1 = "85 a5 74 73 79 6e 63 a3 32 2e 30 aa 73 65 73 73 69 6f 6e 5f 69 64 cf 04 0a 42 7c a8 55 12 b9 a5 73 74 61 74 65 a6 61 63 74 69 76 65 a6 6d 65 74 68 6f 64 aa 6c 6f 67 5f 75 70 64 61 74 65 a6 70 61 72 61 6d 73 81 a3 73 63 65 81 ae 73 66 5f 70 72 6f 66 69 6c 65 5f 69 64 73 91 02"; + len = hex_to_str(hex_str1, payload); + g_session_id = 291118229086343865; + ASSERT_EQ(0, tsg_parse_log_update_payload(&a_stream, payload, len)); + + struct sce_log_update *sce = (struct sce_log_update *)session_log_update_data_get(&a_stream, TSG_SERVICE_CHAINING); + ASSERT_TRUE(sce); + EXPECT_EQ(sce->n_profile_ids, 1); + EXPECT_EQ(sce->profile_ids[0], 2); + + free(sce); + sce = NULL; + session_log_update_data_put(&a_stream, TSG_SERVICE_CHAINING, NULL); +} + int main(int argc, char *argv[]) { g_tsg_para.logger = MESA_create_runtime_log_handle("log/tsg_sync_state", 10);