test: change the name of the packet test case

This commit is contained in:
luwenpeng
2024-07-02 10:09:54 +08:00
parent 761329e530
commit 5591227b9a
4 changed files with 123 additions and 45 deletions

View File

@@ -1,6 +1,3 @@
add_executable(gtest_packet gtest_packet.cpp)
target_link_libraries(gtest_packet packet gtest)
add_executable(gtest_tunnel gtest_tunnel.cpp)
target_link_libraries(gtest_tunnel packet gtest)
@@ -37,8 +34,13 @@ target_link_libraries(gtest_l2tp_utils packet gtest)
add_executable(gtest_packet_frag gtest_packet_frag.cpp)
target_link_libraries(gtest_packet_frag packet gtest)
add_executable(gtest_packet_parse gtest_packet_parse.cpp)
target_link_libraries(gtest_packet_parse packet gtest)
add_executable(gtest_packet_ldbc gtest_packet_ldbc.cpp)
target_link_libraries(gtest_packet_ldbc packet gtest)
include(GoogleTest)
gtest_discover_tests(gtest_packet)
gtest_discover_tests(gtest_tunnel)
gtest_discover_tests(gtest_udp_utils)
gtest_discover_tests(gtest_tcp_utils)
@@ -50,4 +52,6 @@ gtest_discover_tests(gtest_vlan_utils)
gtest_discover_tests(gtest_vxlan_utils)
gtest_discover_tests(gtest_gre_utils)
gtest_discover_tests(gtest_l2tp_utils)
gtest_discover_tests(gtest_packet_frag)
gtest_discover_tests(gtest_packet_frag)
gtest_discover_tests(gtest_packet_parse)
gtest_discover_tests(gtest_packet_ldbc)

View File

@@ -0,0 +1,96 @@
#include <gtest/gtest.h>
#include <arpa/inet.h>
#include "packet_def.h"
#include "packet_ldbc.h"
#include "packet_parse.h"
/******************************************************************************
* [Protocols in frame: eth:ethertype:ip:ipv6:tcp]
******************************************************************************
*
* Frame 1: 106 bytes on wire (848 bits), 106 bytes captured (848 bits)
* Ethernet II, Src: JuniperN_45:88:29 (2c:6b:f5:45:88:29), Dst: JuniperN_2a:a2:00 (5c:5e:ab:2a:a2:00)
* Destination: JuniperN_2a:a2:00 (5c:5e:ab:2a:a2:00)
* Source: JuniperN_45:88:29 (2c:6b:f5:45:88:29)
* Type: IPv4 (0x0800)
* Internet Protocol Version 4, Src: 210.77.88.163, Dst: 59.66.4.50
* 0100 .... = Version: 4
* .... 0101 = Header Length: 20 bytes (5)
* Differentiated Services Field: 0x00 (DSCP: CS0, ECN: Not-ECT)
* Total Length: 92
* Identification: 0x0b4d (2893)
* 000. .... = Flags: 0x0
* ...0 0000 0000 0000 = Fragment Offset: 0
* Time to Live: 59
* Protocol: IPv6 (41)
* Header Checksum: 0x09c8 [validation disabled]
* [Header checksum status: Unverified]
* Source Address: 210.77.88.163
* Destination Address: 59.66.4.50
* Internet Protocol Version 6, Src: 2001:da8:200:900e:200:5efe:d24d:58a3, Dst: 2600:140e:6::1702:1058
* 0110 .... = Version: 6
* .... 0000 0000 .... .... .... .... .... = Traffic Class: 0x00 (DSCP: CS0, ECN: Not-ECT)
* .... 0000 0000 0000 0000 0000 = Flow Label: 0x00000
* Payload Length: 32
* Next Header: TCP (6)
* Hop Limit: 64
* Source Address: 2001:da8:200:900e:200:5efe:d24d:58a3
* Destination Address: 2600:140e:6::1702:1058
* [Source ISATAP IPv4: 210.77.88.163]
* Transmission Control Protocol, Src Port: 52556, Dst Port: 80, Seq: 0, Len: 0
* Source Port: 52556
* Destination Port: 80
* [Stream index: 0]
* [Conversation completeness: Complete, WITH_DATA (31)]
* [TCP Segment Len: 0]
* Sequence Number: 0 (relative sequence number)
* Sequence Number (raw): 2172673142
* [Next Sequence Number: 1 (relative sequence number)]
* Acknowledgment Number: 0
* Acknowledgment number (raw): 0
* 1000 .... = Header Length: 32 bytes (8)
* Flags: 0x002 (SYN)
* Window: 8192
* [Calculated window size: 8192]
* Checksum: 0xf757 [unverified]
* [Checksum Status: Unverified]
* Urgent Pointer: 0
* Options: (12 bytes), Maximum segment size, No-Operation (NOP), Window scale, No-Operation (NOP), No-Operation (NOP), SACK permitted
* [Timestamps]
*/
unsigned char data[] = {
0x5c, 0x5e, 0xab, 0x2a, 0xa2, 0x00, 0x2c, 0x6b, 0xf5, 0x45, 0x88, 0x29, 0x08, 0x00, 0x45, 0x00, 0x00, 0x5c, 0x0b, 0x4d, 0x00, 0x00, 0x3b, 0x29, 0x09, 0xc8,
0xd2, 0x4d, 0x58, 0xa3, 0x3b, 0x42, 0x04, 0x32, 0x60, 0x00, 0x00, 0x00, 0x00, 0x20, 0x06, 0x40, 0x20, 0x01, 0x0d, 0xa8, 0x02, 0x00, 0x90, 0x0e, 0x02, 0x00,
0x5e, 0xfe, 0xd2, 0x4d, 0x58, 0xa3, 0x26, 0x00, 0x14, 0x0e, 0x00, 0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x17, 0x02, 0x10, 0x58, 0xcd, 0x4c, 0x00, 0x50,
0x81, 0x80, 0x5c, 0x76, 0x00, 0x00, 0x00, 0x00, 0x80, 0x02, 0x20, 0x00, 0xf7, 0x57, 0x00, 0x00, 0x02, 0x04, 0x04, 0xc4, 0x01, 0x03, 0x03, 0x08, 0x01, 0x01,
0x04, 0x02};
#if 1
TEST(PACKET_LDBC, HASH_VALUE)
{
struct packet handler;
memset(&handler, 0, sizeof(handler));
const char *payload = packet_parse(&handler, (const char *)data, sizeof(data));
EXPECT_TRUE(payload != nullptr);
EXPECT_TRUE((char *)payload - (char *)&data == 106);
packet_print(&handler);
// buffer: "2001:da8:200:900e:200:5efe:d24d:58a3 0 2600:140e:6::1702:1058 0"
// buffer: "210.77.88.163 0 59.66.4.50 0"
EXPECT_TRUE(packet_ldbc_hash(&handler, LDBC_HASH_OUTERMOST_INT_IP, PACKET_DIRECTION_INCOMING) == packet_ldbc_hash(&handler, LDBC_HASH_OUTERMOST_EXT_IP, PACKET_DIRECTION_OUTGOING));
EXPECT_TRUE(packet_ldbc_hash(&handler, LDBC_HASH_OUTERMOST_EXT_IP, PACKET_DIRECTION_INCOMING) == packet_ldbc_hash(&handler, LDBC_HASH_OUTERMOST_INT_IP, PACKET_DIRECTION_OUTGOING));
EXPECT_TRUE(packet_ldbc_hash(&handler, LDBC_HASH_OUTERMOST_INT_EXT_IP, PACKET_DIRECTION_INCOMING) == packet_ldbc_hash(&handler, LDBC_HASH_OUTERMOST_INT_EXT_IP, PACKET_DIRECTION_OUTGOING));
EXPECT_TRUE(packet_ldbc_hash(&handler, LDBC_HASH_INNERMOST_INT_IP, PACKET_DIRECTION_INCOMING) == packet_ldbc_hash(&handler, LDBC_HASH_INNERMOST_EXT_IP, PACKET_DIRECTION_OUTGOING));
}
#endif
int main(int argc, char **argv)
{
::testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}

View File

@@ -3,9 +3,7 @@
#include "tuple.h"
#include "packet_def.h"
#include "packet_ldbc.h"
#include "packet_parse.h"
#include "packet_build.h"
#include "packet_utils.h"
#include "packet_layer.h"
@@ -80,7 +78,7 @@ unsigned char data1[] = {
0xab, 0xcd, 0xab, 0xcd, 0xab, 0xcd, 0xab, 0xcd, 0xab, 0xcd, 0xab, 0xcd, 0xab, 0xcd};
#if 1
TEST(PACKET, ETH_VLAN_VLAN_IP4_IP4_UDP)
TEST(PACKET_PARSE, ETH_VLAN_VLAN_IP4_IP4_UDP)
{
char buffer[256];
struct packet handler;
@@ -284,7 +282,7 @@ unsigned char data2[] = {
0x2b, 0xb6, 0x3a, 0x9c, 0x84, 0x0e, 0x15, 0x5e, 0x75, 0x3b, 0xc9, 0x0e, 0x94, 0xe6, 0x48, 0x0e, 0x37, 0x07, 0xf8, 0xd9, 0x59, 0x4b, 0x04, 0x50};
#if 1
TEST(PACKET, ETH_IP6_IP4_TCP_SSH)
TEST(PACKET_PARSE, ETH_IP6_IP4_TCP_SSH)
{
char buffer[256];
struct packet handler;
@@ -477,7 +475,7 @@ unsigned char data3[] = {
0x00, 0x00, 0x03, 0x84, 0x00, 0x09, 0x3a, 0x80, 0x00, 0x01, 0x51, 0x80};
#if 1
TEST(PACKET, ETH_VLAN_IP6_IP4_GRE_PPP_IP4_UDP_DNS)
TEST(PACKET_PARSE, ETH_VLAN_IP6_IP4_GRE_PPP_IP4_UDP_DNS)
{
char buffer[256];
struct packet handler;
@@ -684,7 +682,7 @@ unsigned char data4[] = {
0x04, 0x02};
#if 1
TEST(PACKET, ETH_IP4_IP6_TCP)
TEST(PACKET_PARSE, ETH_IP4_IP6_TCP)
{
char buffer[256];
struct packet handler;
@@ -839,7 +837,7 @@ unsigned char data5[] = {
0x58, 0x58};
#if 1
TEST(PACKET, ETH_IP6_IP6_UDP)
TEST(PACKET_PARSE, ETH_IP6_IP6_UDP)
{
char buffer[256];
struct packet handler;
@@ -995,7 +993,7 @@ unsigned char data6[] = {
0x20, 0x00, 0xa7, 0x77, 0x00, 0x00, 0x02, 0x04, 0x05, 0xb4, 0x01, 0x03, 0x03, 0x08, 0x01, 0x01, 0x04, 0x02};
#if 1
TEST(PACKET, ETH_MPLS_IP4_TCP)
TEST(PACKET_PARSE, ETH_MPLS_IP4_TCP)
{
char buffer[256];
struct packet handler;
@@ -1162,7 +1160,7 @@ unsigned char data7[] = {
0x00, 0x00, 0x60, 0x02, 0x10, 0x20, 0xf7, 0x91, 0x00, 0x00, 0x02, 0x04, 0x02, 0x18};
#if 1
TEST(PACKET, ETH_MPLS_MPLS_IP4_TCP)
TEST(PACKET_PARSE, ETH_MPLS_MPLS_IP4_TCP)
{
char buffer[256];
struct packet handler;
@@ -1339,7 +1337,7 @@ unsigned char data8[] = {
0xda, 0x72, 0x7c, 0x31, 0xf8, 0x20, 0x80, 0x10, 0x0f, 0xc0, 0xc3, 0x61, 0x00, 0x00, 0x01, 0x01, 0x08, 0x0a, 0x00, 0x6f, 0xab, 0xdf, 0x9c, 0x61, 0xc7, 0xc5};
#if 1
TEST(PACKET, ETH_VLAN_PPPOE_IP4_TCP)
TEST(PACKET_PARSE, ETH_VLAN_PPPOE_IP4_TCP)
{
char buffer[256];
struct packet handler;
@@ -1592,7 +1590,7 @@ unsigned char data9[] = {
0x87, 0x9c, 0x8f, 0x93, 0x97, 0xd4, 0xa2, 0x28, 0x2c, 0x79, 0x22, 0xc8};
#if 1
TEST(PACKET, ETH_IP6_UDP_GTP_IP6_TCP_TLS)
TEST(PACKET_PARSE, ETH_IP6_UDP_GTP_IP6_TCP_TLS)
{
char buffer[256];
struct packet handler;
@@ -1846,7 +1844,7 @@ unsigned char data10[] = {
0x4f, 0xe9, 0xf5, 0xf0, 0x61, 0x5d, 0x7f, 0xc4, 0xc4, 0xd1, 0x05, 0x54, 0x13, 0xdb};
#if 1
TEST(PACKET, ETH_IP6_UDP_GTP_IP4_TCP_TLS)
TEST(PACKET_PARSE, ETH_IP6_UDP_GTP_IP4_TCP_TLS)
{
char buffer[256];
struct packet handler;
@@ -2048,7 +2046,7 @@ unsigned char data11[] = {
0x03, 0x77, 0x77, 0x77, 0x06, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x03, 0x63, 0x6f, 0x6d, 0x00, 0x00, 0x01, 0x00, 0x01};
#if 1
TEST(PACKET, ETH_IP4_UDP_VXLAN_ETH_IP4_UDP_DNS)
TEST(PACKET_PARSE, ETH_IP4_UDP_VXLAN_ETH_IP4_UDP_DNS)
{
char buffer[256];
struct packet handler;
@@ -2206,7 +2204,7 @@ unsigned char data12[] = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
#if 1
TEST(PACKET, ETH_MPLS_MPLS_PWETHCW_ETH_ARP)
TEST(PACKET_PARSE, ETH_MPLS_MPLS_PWETHCW_ETH_ARP)
{
struct packet handler;
@@ -2342,7 +2340,7 @@ unsigned char data13[] = {
0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f, 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37};
#if 1
TEST(PACKET, ETH_IP4_ICMP)
TEST(PACKET_PARSE, ETH_IP4_ICMP)
{
char buffer[256];
struct packet handler;
@@ -2448,7 +2446,7 @@ unsigned char data14[] = {
0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f, 0x30, 0x31, 0x32, 0x33};
#if 1
TEST(PACKET, ETH_IP6_ICMP6)
TEST(PACKET_PARSE, ETH_IP6_ICMP6)
{
char buffer[256];
struct packet handler;
@@ -2613,7 +2611,7 @@ unsigned char data15[] = {
0x00, 0x01, 0xc0, 0x0c, 0x00, 0x20, 0x00, 0x01, 0x00, 0x04, 0x93, 0xe0, 0x00, 0x06, 0x00, 0x00, 0xac, 0x10, 0x02, 0x64};
#if 1
TEST(PACKET, ETH_IP4_UDP_L2TPV2_PPP_IP4_UDP)
TEST(PACKET_PARSE, ETH_IP4_UDP_L2TPV2_PPP_IP4_UDP)
{
char buffer[256];
struct packet handler;
@@ -2778,7 +2776,7 @@ unsigned char data16[] = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
#if 1
TEST(PACKET, ETH_IP4_TCP_PADDING)
TEST(PACKET_PARSE, ETH_IP4_TCP_PADDING)
{
char buffer[256];
struct packet handler;
@@ -2843,28 +2841,6 @@ TEST(PACKET, ETH_IP4_TCP_PADDING)
}
#endif
#if 1
TEST(PACKET, HASH_VALUE)
{
struct packet handler;
memset(&handler, 0, sizeof(handler));
const char *payload = packet_parse(&handler, (const char *)data4, sizeof(data4));
EXPECT_TRUE(payload != nullptr);
EXPECT_TRUE((char *)payload - (char *)&data4 == 106);
packet_print(&handler);
// buffer: "2001:da8:200:900e:200:5efe:d24d:58a3 0 2600:140e:6::1702:1058 0"
// buffer: "210.77.88.163 0 59.66.4.50 0"
EXPECT_TRUE(packet_ldbc_hash(&handler, LDBC_HASH_OUTERMOST_INT_IP, PACKET_DIRECTION_INCOMING) == packet_ldbc_hash(&handler, LDBC_HASH_OUTERMOST_EXT_IP, PACKET_DIRECTION_OUTGOING));
EXPECT_TRUE(packet_ldbc_hash(&handler, LDBC_HASH_OUTERMOST_EXT_IP, PACKET_DIRECTION_INCOMING) == packet_ldbc_hash(&handler, LDBC_HASH_OUTERMOST_INT_IP, PACKET_DIRECTION_OUTGOING));
EXPECT_TRUE(packet_ldbc_hash(&handler, LDBC_HASH_OUTERMOST_INT_EXT_IP, PACKET_DIRECTION_INCOMING) == packet_ldbc_hash(&handler, LDBC_HASH_OUTERMOST_INT_EXT_IP, PACKET_DIRECTION_OUTGOING));
EXPECT_TRUE(packet_ldbc_hash(&handler, LDBC_HASH_INNERMOST_INT_IP, PACKET_DIRECTION_INCOMING) == packet_ldbc_hash(&handler, LDBC_HASH_INNERMOST_EXT_IP, PACKET_DIRECTION_OUTGOING));
}
#endif
int main(int argc, char **argv)
{
::testing::InitGoogleTest(&argc, argv);