feature: add GTP utils, support overwrite message length of GTP header
This commit is contained in:
@@ -7,11 +7,11 @@ target_link_libraries(gtest_udp_utils packet gtest)
|
||||
add_executable(gtest_tcp_utils gtest_tcp_utils.cpp)
|
||||
target_link_libraries(gtest_tcp_utils packet gtest)
|
||||
|
||||
add_executable(gtest_ipv4_utils gtest_ipv4_utils.cpp)
|
||||
target_link_libraries(gtest_ipv4_utils packet gtest)
|
||||
add_executable(gtest_ip4_utils gtest_ip4_utils.cpp)
|
||||
target_link_libraries(gtest_ip4_utils packet gtest)
|
||||
|
||||
add_executable(gtest_ipv6_utils gtest_ipv6_utils.cpp)
|
||||
target_link_libraries(gtest_ipv6_utils packet gtest)
|
||||
add_executable(gtest_ip6_utils gtest_ip6_utils.cpp)
|
||||
target_link_libraries(gtest_ip6_utils packet gtest)
|
||||
|
||||
add_executable(gtest_mpls_utils gtest_mpls_utils.cpp)
|
||||
target_link_libraries(gtest_mpls_utils packet gtest)
|
||||
@@ -31,6 +31,12 @@ target_link_libraries(gtest_gre_utils packet gtest)
|
||||
add_executable(gtest_l2tp_utils gtest_l2tp_utils.cpp)
|
||||
target_link_libraries(gtest_l2tp_utils packet gtest)
|
||||
|
||||
add_executable(gtest_gtp1_utils gtest_gtp1_utils.cpp)
|
||||
target_link_libraries(gtest_gtp1_utils packet gtest)
|
||||
|
||||
add_executable(gtest_gtp2_utils gtest_gtp2_utils.cpp)
|
||||
target_link_libraries(gtest_gtp2_utils packet gtest)
|
||||
|
||||
add_executable(gtest_packet_frag gtest_packet_frag.cpp)
|
||||
target_link_libraries(gtest_packet_frag packet gtest)
|
||||
|
||||
@@ -47,14 +53,16 @@ include(GoogleTest)
|
||||
gtest_discover_tests(gtest_tunnel)
|
||||
gtest_discover_tests(gtest_udp_utils)
|
||||
gtest_discover_tests(gtest_tcp_utils)
|
||||
gtest_discover_tests(gtest_ipv4_utils)
|
||||
gtest_discover_tests(gtest_ipv6_utils)
|
||||
gtest_discover_tests(gtest_ip4_utils)
|
||||
gtest_discover_tests(gtest_ip6_utils)
|
||||
gtest_discover_tests(gtest_mpls_utils)
|
||||
gtest_discover_tests(gtest_eth_utils)
|
||||
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_gtp1_utils)
|
||||
gtest_discover_tests(gtest_gtp2_utils)
|
||||
gtest_discover_tests(gtest_packet_frag)
|
||||
gtest_discover_tests(gtest_packet_parse)
|
||||
gtest_discover_tests(gtest_packet_build)
|
||||
|
||||
243
src/packet/test/gtest_gtp1_utils.cpp
Normal file
243
src/packet/test/gtest_gtp1_utils.cpp
Normal file
@@ -0,0 +1,243 @@
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include "gtp1_utils.h"
|
||||
|
||||
/*
|
||||
* User Datagram Protocol, Src Port: 2123, Dst Port: 2123
|
||||
* GPRS Tunneling Protocol
|
||||
* Flags: 0x32
|
||||
* 001. .... = Version: GTP release 99 version (1)
|
||||
* ...1 .... = Protocol type: GTP (1)
|
||||
* .... 0... = Reserved: 0
|
||||
* .... .0.. = Is Next Extension Header present?: No
|
||||
* .... ..1. = Is Sequence Number present?: Yes
|
||||
* .... ...0 = Is N-PDU number present?: No
|
||||
* Message Type: Create PDP context request (0x10)
|
||||
* Length: 151
|
||||
* TEID: 0x00000000 (0)
|
||||
* Sequence number: 0x00fe (254)
|
||||
* IMSI: 27203
|
||||
* [Association IMSI: 27203]
|
||||
* Mobile Country Code (MCC): Ireland (272)
|
||||
* Mobile Network Code (MNC): Eircom Ltd (03)
|
||||
* Routing Area Identity
|
||||
* Mobile Country Code (MCC): Ireland (272)
|
||||
* Mobile Network Code (MNC): Eircom Ltd (03)
|
||||
* Location Area Code (LAC): 65534
|
||||
* Routing Area Code (RAC): 255
|
||||
* Recovery: 93
|
||||
* Selection mode: MS or network provided APN, subscribed verified
|
||||
* .... ..00 = Selection mode: MS or network provided APN, subscribed verified (0)
|
||||
* TEID Data I: 0x372f0000 (925827072)
|
||||
* TEID Control Plane: 0x372f0000 (925827072)
|
||||
* NSAPI: 5
|
||||
* .... 0101 = NSAPI: 5
|
||||
* End user address (IETF/IPv4)
|
||||
* Length: 2
|
||||
* PDP type organization: IETF (1)
|
||||
* PDP type number: IPv4 (0x21)
|
||||
* Access Point Name: mms.mymeteor.ie
|
||||
* APN length: 16
|
||||
* APN: mms.mymeteor.ie
|
||||
* Protocol configuration options
|
||||
* Length: 34
|
||||
* [Link direction: MS to network (0)]
|
||||
* 1... .... = Extension: True
|
||||
* .... .000 = Configuration Protocol: PPP for use with IP PDP type or IP PDN type (0)
|
||||
* Protocol or Container ID: Password Authentication Protocol (0xc023)
|
||||
* Length: 0x0b (11)
|
||||
* PPP Password Authentication Protocol
|
||||
* Code: Authenticate-Request (1)
|
||||
* Identifier: 0
|
||||
* Length: 11
|
||||
* Data
|
||||
* Peer-ID-Length: 2
|
||||
* Peer-ID: my
|
||||
* Password-Length: 3
|
||||
* Password: wap
|
||||
* Protocol or Container ID: Internet Protocol Control Protocol (0x8021)
|
||||
* Length: 0x10 (16)
|
||||
* PPP IP Control Protocol
|
||||
* Code: Configuration Request (1)
|
||||
* Identifier: 0 (0x00)
|
||||
* Length: 16
|
||||
* Options: (12 bytes), Primary DNS Server IP Address, Secondary DNS Server IP Address
|
||||
* Primary DNS Server IP Address
|
||||
* Type: Primary DNS Server IP Address (129)
|
||||
* Length: 6
|
||||
* Primary DNS Address: 0.0.0.0
|
||||
* Secondary DNS Server IP Address
|
||||
* Type: Secondary DNS Server IP Address (131)
|
||||
* Length: 6
|
||||
* Secondary DNS Address: 0.0.0.0
|
||||
* GSN address : 212.129.65.13
|
||||
* GSN address length: 4
|
||||
* GSN address IPv4: 212.129.65.13
|
||||
* GSN address : 212.129.65.23
|
||||
* GSN address length: 4
|
||||
* GSN address IPv4: 212.129.65.23
|
||||
* MS international PSTN/ISDN number
|
||||
* Length: 7
|
||||
* 1... .... = Extension: No Extension
|
||||
* .001 .... = Nature of number: International Number (0x1)
|
||||
* .... 0001 = Number plan: ISDN/Telephony Numbering (Rec ITU-T E.164) (0x1)
|
||||
* E.164 number (MSISDN): 353800000000
|
||||
* Country Code: Ireland (353)
|
||||
* Quality of Service
|
||||
* Length: 12
|
||||
* Allocation/Retention priority: 2
|
||||
* 00.. .... = Spare: 0
|
||||
* ..10 0... = QoS delay: Delay class 4 (best effort) (4)
|
||||
* .... .011 = QoS reliability: Unacknowledged GTP/LLC, Ack RLC, Protected data (3)
|
||||
* 0110 .... = QoS peak: Up to 32 000 oct/s (6)
|
||||
* .... 0... = Spare: 0
|
||||
* .... .010 = QoS precedence: Normal priority (2)
|
||||
* 000. .... = Spare: 0
|
||||
* ...1 1111 = QoS mean: Best effort (31)
|
||||
* 100. .... = Traffic class: Background class (4)
|
||||
* ...1 0... = Delivery order: Without delivery order ('no') (2)
|
||||
* .... .011 = Delivery of erroneous SDU: Erroneous SDUs are not delivered ('no') (3)
|
||||
* Maximum SDU size: 1500 octets
|
||||
* Maximum bit rate for uplink: 256 kbps
|
||||
* Maximum bit rate for downlink: 256 kbps
|
||||
* 0111 .... = Residual BER: 1/100 000 = 1x10^-5 (7)
|
||||
* .... 0100 = SDU Error ratio: 1/10 000 = 1x10^-4 (4)
|
||||
* 1111 10.. = Transfer delay: 4000 ms (62)
|
||||
* .... ..11 = Traffic handling priority: Priority level 3 (3)
|
||||
* Guaranteed bit rate for uplink: 0 kbps (255)
|
||||
* Guaranteed bit rate for downlink: 0 kbps (255)
|
||||
* RAT Type: GERAN
|
||||
* Length: 1
|
||||
* RAT Type: GERAN (2)
|
||||
* IMEI(SV): 3598100185893512
|
||||
* Length: 8
|
||||
* IMEI(SV): 3598100185893512
|
||||
* [Response In: 2]
|
||||
*/
|
||||
|
||||
unsigned char gtp1_c[] = {
|
||||
0x32, 0x10, 0x00, 0x97, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfe, 0x00, 0x00, 0x02, 0x72, 0x02, 0xf3, 0x01, 0x00, 0x00, 0x00, 0x00, 0x03, 0x72, 0xf2, 0x30, 0xff,
|
||||
0xfe, 0xff, 0x0e, 0x5d, 0x0f, 0xfc, 0x10, 0x37, 0x2f, 0x00, 0x00, 0x11, 0x37, 0x2f, 0x00, 0x00, 0x14, 0x05, 0x80, 0x00, 0x02, 0xf1, 0x21, 0x83, 0x00, 0x10,
|
||||
0x03, 0x6d, 0x6d, 0x73, 0x08, 0x6d, 0x79, 0x6d, 0x65, 0x74, 0x65, 0x6f, 0x72, 0x02, 0x69, 0x65, 0x84, 0x00, 0x22, 0x80, 0xc0, 0x23, 0x0b, 0x01, 0x00, 0x00,
|
||||
0x0b, 0x02, 0x6d, 0x79, 0x03, 0x77, 0x61, 0x70, 0x80, 0x21, 0x10, 0x01, 0x00, 0x00, 0x10, 0x81, 0x06, 0x00, 0x00, 0x00, 0x00, 0x83, 0x06, 0x00, 0x00, 0x00,
|
||||
0x00, 0x85, 0x00, 0x04, 0xd4, 0x81, 0x41, 0x0d, 0x85, 0x00, 0x04, 0xd4, 0x81, 0x41, 0x17, 0x86, 0x00, 0x07, 0x91, 0x53, 0x83, 0x00, 0x00, 0x00, 0x00, 0x87,
|
||||
0x00, 0x0c, 0x02, 0x23, 0x62, 0x1f, 0x93, 0x96, 0x58, 0x58, 0x74, 0xfb, 0xff, 0xff, 0x97, 0x00, 0x01, 0x02, 0x9a, 0x00, 0x08, 0x53, 0x89, 0x01, 0x10, 0x58,
|
||||
0x98, 0x53, 0x21};
|
||||
|
||||
TEST(GTP1_UTILS, C_GET)
|
||||
{
|
||||
const struct gtp1_hdr *hdr = (struct gtp1_hdr *)gtp1_c;
|
||||
|
||||
// GTP Fixed Header Length + GTPv1-C Optional Headers + GTPv1-C Extension Headers
|
||||
EXPECT_TRUE(calc_gtp1_hdr_len((const char *)gtp1_c, sizeof(gtp1_c)) == 12);
|
||||
EXPECT_TRUE(gtp1_hdr_get_flags(hdr) == 0x32);
|
||||
EXPECT_TRUE(gtp1_hdr_get_version(hdr) == 1);
|
||||
EXPECT_TRUE(gtp1_hdr_get_protocol(hdr) == 1);
|
||||
EXPECT_TRUE(gtp1_hdr_get_reserved(hdr) == 0);
|
||||
EXPECT_TRUE(gtp1_hdr_get_ext_flag(hdr) == 0);
|
||||
EXPECT_TRUE(gtp1_hdr_get_seq_flag(hdr) == 1);
|
||||
EXPECT_TRUE(gtp1_hdr_get_npdu_flag(hdr) == 0);
|
||||
EXPECT_TRUE(gtp1_hdr_get_msg_type(hdr) == 0x10);
|
||||
EXPECT_TRUE(gtp1_hdr_get_msg_len(hdr) == 151);
|
||||
EXPECT_TRUE(gtp1_hdr_get_teid(hdr) == 0);
|
||||
EXPECT_TRUE(gtp1_hdr_get_seq(hdr) == 254);
|
||||
EXPECT_TRUE(gtp1_hdr_get_npdu(hdr) == 0);
|
||||
EXPECT_TRUE(gtp1_hdr_get_next_ext_type(hdr) == 0);
|
||||
|
||||
char buff[1024] = {0};
|
||||
gtp1_hdr_to_str(hdr, buff, sizeof(buff));
|
||||
printf("%s\n", buff);
|
||||
}
|
||||
|
||||
TEST(GTP1_UTILS, C_SET)
|
||||
{
|
||||
char buff[12] = {0};
|
||||
|
||||
struct gtp1_hdr *hdr = (struct gtp1_hdr *)buff;
|
||||
gtp1_hdr_set_flags(hdr, 0x32);
|
||||
gtp1_hdr_set_version(hdr, 1);
|
||||
gtp1_hdr_set_protocol(hdr, 1);
|
||||
gtp1_hdr_set_reserved(hdr, 0);
|
||||
gtp1_hdr_set_ext_flag(hdr, 0);
|
||||
gtp1_hdr_set_seq_flag(hdr, 1);
|
||||
gtp1_hdr_set_npdu_flag(hdr, 0);
|
||||
gtp1_hdr_set_msg_type(hdr, 0x10);
|
||||
gtp1_hdr_set_msg_len(hdr, 151);
|
||||
gtp1_hdr_set_teid(hdr, 0);
|
||||
gtp1_hdr_set_seq(hdr, 254);
|
||||
gtp1_hdr_set_npdu(hdr, 0);
|
||||
gtp1_hdr_set_next_ext_type(hdr, 0);
|
||||
|
||||
EXPECT_TRUE(memcmp(buff, gtp1_c, 12) == 0);
|
||||
}
|
||||
|
||||
/*
|
||||
* User Datagram Protocol, Src Port: 2152, Dst Port: 2152
|
||||
* GPRS Tunneling Protocol
|
||||
* Flags: 0x30
|
||||
* 001. .... = Version: GTP release 99 version (1)
|
||||
* ...1 .... = Protocol type: GTP (1)
|
||||
* .... 0... = Reserved: 0
|
||||
* .... .0.. = Is Next Extension Header present?: No
|
||||
* .... ..0. = Is Sequence Number present?: No
|
||||
* .... ...0 = Is N-PDU number present?: No
|
||||
* Message Type: T-PDU (0xff)
|
||||
* Length: 40
|
||||
* TEID: 0x001e849a (2000026)
|
||||
*/
|
||||
|
||||
unsigned char gtp1_u[] = {
|
||||
0x30, 0xff, 0x00, 0x28, 0x00, 0x1e, 0x84, 0x9a};
|
||||
|
||||
TEST(GTP1_UTILS, U_GET)
|
||||
{
|
||||
const struct gtp1_hdr *hdr = (struct gtp1_hdr *)gtp1_u;
|
||||
|
||||
// GTP Fixed Header Length + GTPv1-U Optional Headers + GTPv1-U Extension Headers
|
||||
EXPECT_TRUE(calc_gtp1_hdr_len((const char *)gtp1_u, sizeof(gtp1_u)) == 8);
|
||||
EXPECT_TRUE(gtp1_hdr_get_flags(hdr) == 0x30);
|
||||
EXPECT_TRUE(gtp1_hdr_get_version(hdr) == 1);
|
||||
EXPECT_TRUE(gtp1_hdr_get_protocol(hdr) == 1);
|
||||
EXPECT_TRUE(gtp1_hdr_get_reserved(hdr) == 0);
|
||||
EXPECT_TRUE(gtp1_hdr_get_ext_flag(hdr) == 0);
|
||||
EXPECT_TRUE(gtp1_hdr_get_seq_flag(hdr) == 0);
|
||||
EXPECT_TRUE(gtp1_hdr_get_npdu_flag(hdr) == 0);
|
||||
EXPECT_TRUE(gtp1_hdr_get_msg_type(hdr) == 0xff);
|
||||
EXPECT_TRUE(gtp1_hdr_get_msg_len(hdr) == 40);
|
||||
EXPECT_TRUE(gtp1_hdr_get_teid(hdr) == 2000026);
|
||||
EXPECT_TRUE(gtp1_hdr_get_seq(hdr) == 0);
|
||||
EXPECT_TRUE(gtp1_hdr_get_npdu(hdr) == 0);
|
||||
EXPECT_TRUE(gtp1_hdr_get_next_ext_type(hdr) == 0);
|
||||
|
||||
char buff[1024] = {0};
|
||||
gtp1_hdr_to_str(hdr, buff, sizeof(buff));
|
||||
printf("%s\n", buff);
|
||||
}
|
||||
|
||||
TEST(GTP1_UTILS, U_SET)
|
||||
{
|
||||
char buff[8] = {0};
|
||||
|
||||
struct gtp1_hdr *hdr = (struct gtp1_hdr *)buff;
|
||||
gtp1_hdr_set_flags(hdr, 0x30);
|
||||
gtp1_hdr_set_version(hdr, 1);
|
||||
gtp1_hdr_set_protocol(hdr, 1);
|
||||
gtp1_hdr_set_reserved(hdr, 0);
|
||||
gtp1_hdr_set_ext_flag(hdr, 0);
|
||||
gtp1_hdr_set_seq_flag(hdr, 0);
|
||||
gtp1_hdr_set_npdu_flag(hdr, 0);
|
||||
gtp1_hdr_set_msg_type(hdr, 0xff);
|
||||
gtp1_hdr_set_msg_len(hdr, 40);
|
||||
gtp1_hdr_set_teid(hdr, 2000026);
|
||||
gtp1_hdr_set_seq(hdr, 0);
|
||||
gtp1_hdr_set_npdu(hdr, 0);
|
||||
gtp1_hdr_set_next_ext_type(hdr, 0);
|
||||
|
||||
EXPECT_TRUE(memcmp(buff, gtp1_u, 8) == 0);
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
::testing::InitGoogleTest(&argc, argv);
|
||||
return RUN_ALL_TESTS();
|
||||
}
|
||||
150
src/packet/test/gtest_gtp2_utils.cpp
Normal file
150
src/packet/test/gtest_gtp2_utils.cpp
Normal file
@@ -0,0 +1,150 @@
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include "gtp2_utils.h"
|
||||
|
||||
/*
|
||||
* User Datagram Protocol, Src Port: 2123, Dst Port: 12491
|
||||
* GPRS Tunneling Protocol V2
|
||||
* Flags: 0x48
|
||||
* 010. .... = Version: 2
|
||||
* ...0 .... = Piggybacking flag (P): 0
|
||||
* .... 1... = TEID flag (T): 1
|
||||
* .... .0.. = Message Priority(MP): 0
|
||||
* Message Type: Delete Session Response (37)
|
||||
* Message Length: 19
|
||||
* Tunnel Endpoint Identifier: 0x0e05cd4d (235261261)
|
||||
* Sequence Number: 0x000ce7 (3303)
|
||||
* Spare: 0
|
||||
* Cause : Request accepted (16)
|
||||
* IE Type: Cause (2)
|
||||
* IE Length: 2
|
||||
* 0000 .... = CR flag: 0
|
||||
* .... 0000 = Instance: 0
|
||||
* Cause: Request accepted (16)
|
||||
* 0000 0... = Spare bit(s): 0
|
||||
* .... .0.. = PCE (PDN Connection IE Error): False
|
||||
* .... ..0. = BCE (Bearer Context IE Error): False
|
||||
* .... ...0 = CS (Cause Source): Originated by node sending the message
|
||||
* Recovery (Restart Counter) : 13
|
||||
* IE Type: Recovery (Restart Counter) (3)
|
||||
* IE Length: 1
|
||||
* 0000 .... = CR flag: 0
|
||||
* .... 0000 = Instance: 0
|
||||
* Restart Counter: 13
|
||||
*/
|
||||
|
||||
unsigned char gtp2_c_pkt1[] = {
|
||||
0x48, 0x25, 0x00, 0x13, 0x0e, 0x05, 0xcd, 0x4d, 0x00, 0x0c, 0xe7, 0x00, 0x02, 0x00, 0x02, 0x00, 0x10, 0x00, 0x03, 0x00, 0x01, 0x00, 0x0d};
|
||||
|
||||
// have teid
|
||||
|
||||
TEST(GTP2_UTILS, C_GET1)
|
||||
{
|
||||
const struct gtp2_hdr *hdr = (struct gtp2_hdr *)gtp2_c_pkt1;
|
||||
|
||||
EXPECT_TRUE(calc_gtp2_hdr_len((const char *)gtp2_c_pkt1, sizeof(gtp2_c_pkt1)) == 12);
|
||||
EXPECT_TRUE(gtp2_hdr_get_flags(hdr) == 0x48);
|
||||
EXPECT_TRUE(gtp2_hdr_get_version(hdr) == 2);
|
||||
EXPECT_TRUE(gtp2_hdr_get_piggyback_flag(hdr) == 0);
|
||||
EXPECT_TRUE(gtp2_hdr_get_teid_flag(hdr) == 1);
|
||||
EXPECT_TRUE(gtp2_hdr_get_spare_flag(hdr) == 0);
|
||||
EXPECT_TRUE(gtp2_hdr_get_msg_type(hdr) == 37);
|
||||
EXPECT_TRUE(gtp2_hdr_get_msg_len(hdr) == 19);
|
||||
EXPECT_TRUE(gtp2_hdr_get_teid(hdr) == 0x0e05cd4d);
|
||||
EXPECT_TRUE(gtp2_hdr_get_seq(hdr) == 0x000ce7);
|
||||
EXPECT_TRUE(gtp2_hdr_get_spare(hdr) == 0);
|
||||
|
||||
char buff[1024] = {0};
|
||||
gtp2_hdr_to_str(hdr, buff, sizeof(buff));
|
||||
printf("%s\n", buff);
|
||||
}
|
||||
|
||||
TEST(GTP2_UTILS, C_SET1)
|
||||
{
|
||||
char buff[12] = {0};
|
||||
|
||||
struct gtp2_hdr *hdr = (struct gtp2_hdr *)buff;
|
||||
gtp2_hdr_set_flags(hdr, 0x48);
|
||||
gtp2_hdr_set_version(hdr, 2);
|
||||
gtp2_hdr_set_piggyback_flag(hdr, 0);
|
||||
gtp2_hdr_set_teid_flag(hdr, 1);
|
||||
gtp2_hdr_set_spare_flag(hdr, 0);
|
||||
gtp2_hdr_set_msg_type(hdr, 37);
|
||||
gtp2_hdr_set_msg_len(hdr, 19);
|
||||
gtp2_hdr_set_teid(hdr, 0x0e05cd4d);
|
||||
gtp2_hdr_set_seq(hdr, 0x000ce7);
|
||||
gtp2_hdr_set_spare(hdr, 0);
|
||||
|
||||
EXPECT_TRUE(memcmp(buff, gtp2_c_pkt1, 12) == 0);
|
||||
}
|
||||
|
||||
/*
|
||||
* User Datagram Protocol, Src Port: 2123, Dst Port: 2123
|
||||
* GPRS Tunneling Protocol V2
|
||||
* Flags: 0x40
|
||||
* 010. .... = Version: 2
|
||||
* ...0 .... = Piggybacking flag (P): 0
|
||||
* .... 0... = TEID flag (T): 0
|
||||
* .... .0.. = Message Priority(MP): 0
|
||||
* Message Type: Echo Request (1)
|
||||
* Message Length: 9
|
||||
* Sequence Number: 0x0041d4 (16852)
|
||||
* Spare: 0
|
||||
* Recovery (Restart Counter) : 5
|
||||
* IE Type: Recovery (Restart Counter) (3)
|
||||
* IE Length: 1
|
||||
* 0000 .... = CR flag: 0
|
||||
* .... 0000 = Instance: 0
|
||||
* Restart Counter: 5
|
||||
*/
|
||||
|
||||
unsigned char gtp2_c_pkt2[] = {
|
||||
0x40, 0x01, 0x00, 0x09, 0x00, 0x41, 0xd4, 0x00, 0x03, 0x00, 0x01, 0x00, 0x05};
|
||||
|
||||
// no teid
|
||||
|
||||
TEST(GTP2_UTILS, C_GET2)
|
||||
{
|
||||
const struct gtp2_hdr *hdr = (struct gtp2_hdr *)gtp2_c_pkt2;
|
||||
|
||||
EXPECT_TRUE(calc_gtp2_hdr_len((const char *)gtp2_c_pkt2, sizeof(gtp2_c_pkt2)) == 8);
|
||||
EXPECT_TRUE(gtp2_hdr_get_flags(hdr) == 0x40);
|
||||
EXPECT_TRUE(gtp2_hdr_get_version(hdr) == 2);
|
||||
EXPECT_TRUE(gtp2_hdr_get_piggyback_flag(hdr) == 0);
|
||||
EXPECT_TRUE(gtp2_hdr_get_teid_flag(hdr) == 0);
|
||||
EXPECT_TRUE(gtp2_hdr_get_spare_flag(hdr) == 0);
|
||||
EXPECT_TRUE(gtp2_hdr_get_msg_type(hdr) == 1);
|
||||
EXPECT_TRUE(gtp2_hdr_get_msg_len(hdr) == 9);
|
||||
EXPECT_TRUE(gtp2_hdr_get_teid(hdr) == 0);
|
||||
EXPECT_TRUE(gtp2_hdr_get_seq(hdr) == 0x0041d4);
|
||||
EXPECT_TRUE(gtp2_hdr_get_spare(hdr) == 0);
|
||||
|
||||
char buff[1024] = {0};
|
||||
gtp2_hdr_to_str(hdr, buff, sizeof(buff));
|
||||
printf("%s\n", buff);
|
||||
}
|
||||
|
||||
TEST(GTP2_UTILS, C_SET2)
|
||||
{
|
||||
char buff[8] = {0};
|
||||
|
||||
struct gtp2_hdr *hdr = (struct gtp2_hdr *)buff;
|
||||
gtp2_hdr_set_flags(hdr, 0x40);
|
||||
gtp2_hdr_set_version(hdr, 2);
|
||||
gtp2_hdr_set_piggyback_flag(hdr, 0);
|
||||
gtp2_hdr_set_teid_flag(hdr, 0);
|
||||
gtp2_hdr_set_spare_flag(hdr, 0);
|
||||
gtp2_hdr_set_msg_type(hdr, 1);
|
||||
gtp2_hdr_set_msg_len(hdr, 9);
|
||||
gtp2_hdr_set_teid(hdr, 0);
|
||||
gtp2_hdr_set_seq(hdr, 0x0041d4);
|
||||
gtp2_hdr_set_spare(hdr, 0);
|
||||
|
||||
EXPECT_TRUE(memcmp(buff, gtp2_c_pkt2, 8) == 0);
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
::testing::InitGoogleTest(&argc, argv);
|
||||
return RUN_ALL_TESTS();
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include "ipv4_utils.h"
|
||||
#include "ip4_utils.h"
|
||||
|
||||
/******************************************************************************
|
||||
* more fragment
|
||||
@@ -36,23 +36,23 @@ unsigned char data1[] = {0x45, 0x00, 0x00, 0x2c, 0xff, 0xff, 0x20, 0x00, 0x7f, 0
|
||||
TEST(IPV4_UTILS, GET1)
|
||||
{
|
||||
const struct ip *hdr = (struct ip *)data1;
|
||||
EXPECT_TRUE(ipv4_hdr_get_version(hdr) == 4);
|
||||
EXPECT_TRUE(ipv4_hdr_get_hdr_len(hdr) == 20);
|
||||
EXPECT_TRUE(ipv4_hdr_get_tos(hdr) == 0);
|
||||
EXPECT_TRUE(ipv4_hdr_get_total_len(hdr) == 44);
|
||||
EXPECT_TRUE(ipv4_hdr_get_ipid(hdr) == 65535);
|
||||
EXPECT_TRUE(ipv4_hdr_get_flags(hdr) == 1);
|
||||
EXPECT_TRUE(ipv4_hdr_get_rf_flag(hdr) == false);
|
||||
EXPECT_TRUE(ipv4_hdr_get_df_flag(hdr) == false);
|
||||
EXPECT_TRUE(ipv4_hdr_get_mf_flag(hdr) == true);
|
||||
EXPECT_TRUE(ipv4_hdr_get_frag_offset(hdr) == 0);
|
||||
EXPECT_TRUE(ipv4_hdr_get_ttl(hdr) == 127);
|
||||
EXPECT_TRUE(ipv4_hdr_get_proto(hdr) == 6);
|
||||
EXPECT_TRUE(ipv4_hdr_get_checksum(hdr) == 0x4d8b);
|
||||
EXPECT_TRUE(ipv4_hdr_get_src_addr(hdr) == 0xc0a82467);
|
||||
EXPECT_TRUE(ipv4_hdr_get_dst_addr(hdr) == 0xc0a82889);
|
||||
EXPECT_TRUE(ipv4_hdr_get_opt_len(hdr) == 0);
|
||||
EXPECT_TRUE(ipv4_hdr_get_opt_data(hdr) == NULL);
|
||||
EXPECT_TRUE(ip4_hdr_get_version(hdr) == 4);
|
||||
EXPECT_TRUE(ip4_hdr_get_hdr_len(hdr) == 20);
|
||||
EXPECT_TRUE(ip4_hdr_get_tos(hdr) == 0);
|
||||
EXPECT_TRUE(ip4_hdr_get_total_len(hdr) == 44);
|
||||
EXPECT_TRUE(ip4_hdr_get_ipid(hdr) == 65535);
|
||||
EXPECT_TRUE(ip4_hdr_get_flags(hdr) == 1);
|
||||
EXPECT_TRUE(ip4_hdr_get_rf_flag(hdr) == false);
|
||||
EXPECT_TRUE(ip4_hdr_get_df_flag(hdr) == false);
|
||||
EXPECT_TRUE(ip4_hdr_get_mf_flag(hdr) == true);
|
||||
EXPECT_TRUE(ip4_hdr_get_frag_offset(hdr) == 0);
|
||||
EXPECT_TRUE(ip4_hdr_get_ttl(hdr) == 127);
|
||||
EXPECT_TRUE(ip4_hdr_get_proto(hdr) == 6);
|
||||
EXPECT_TRUE(ip4_hdr_get_checksum(hdr) == 0x4d8b);
|
||||
EXPECT_TRUE(ip4_hdr_get_src_addr(hdr) == 0xc0a82467);
|
||||
EXPECT_TRUE(ip4_hdr_get_dst_addr(hdr) == 0xc0a82889);
|
||||
EXPECT_TRUE(ip4_hdr_get_opt_len(hdr) == 0);
|
||||
EXPECT_TRUE(ip4_hdr_get_opt_data(hdr) == NULL);
|
||||
}
|
||||
|
||||
TEST(IPV4_UTILS, SET1)
|
||||
@@ -60,26 +60,26 @@ TEST(IPV4_UTILS, SET1)
|
||||
char buff[20] = {0};
|
||||
|
||||
struct ip *hdr = (struct ip *)buff;
|
||||
ipv4_hdr_set_version(hdr, 4);
|
||||
ipv4_hdr_set_hdr_len(hdr, 20);
|
||||
ipv4_hdr_set_tos(hdr, 0);
|
||||
ipv4_hdr_set_total_len(hdr, 44);
|
||||
ipv4_hdr_set_ipid(hdr, 65535);
|
||||
ipv4_hdr_set_frag_offset(hdr, 0);
|
||||
ipv4_hdr_set_ttl(hdr, 127);
|
||||
ipv4_hdr_set_protocol(hdr, 6);
|
||||
ipv4_hdr_set_checksum(hdr, 0x4d8b);
|
||||
ipv4_hdr_set_src_addr(hdr, 0xc0a82467);
|
||||
ipv4_hdr_set_dst_addr(hdr, 0xc0a82889);
|
||||
ipv4_hdr_set_opt_len(hdr, 0);
|
||||
ipv4_hdr_set_opt_data(hdr, NULL);
|
||||
ip4_hdr_set_version(hdr, 4);
|
||||
ip4_hdr_set_hdr_len(hdr, 20);
|
||||
ip4_hdr_set_tos(hdr, 0);
|
||||
ip4_hdr_set_total_len(hdr, 44);
|
||||
ip4_hdr_set_ipid(hdr, 65535);
|
||||
ip4_hdr_set_frag_offset(hdr, 0);
|
||||
ip4_hdr_set_ttl(hdr, 127);
|
||||
ip4_hdr_set_protocol(hdr, 6);
|
||||
ip4_hdr_set_checksum(hdr, 0x4d8b);
|
||||
ip4_hdr_set_src_addr(hdr, 0xc0a82467);
|
||||
ip4_hdr_set_dst_addr(hdr, 0xc0a82889);
|
||||
ip4_hdr_set_opt_len(hdr, 0);
|
||||
ip4_hdr_set_opt_data(hdr, NULL);
|
||||
|
||||
ipv4_hdr_set_flags(hdr, 1);
|
||||
ip4_hdr_set_flags(hdr, 1);
|
||||
EXPECT_TRUE(memcmp(buff, data1, 20) == 0);
|
||||
|
||||
ipv4_hdr_set_rf_flag(hdr, false);
|
||||
ipv4_hdr_set_df_flag(hdr, false);
|
||||
ipv4_hdr_set_mf_flag(hdr, true);
|
||||
ip4_hdr_set_rf_flag(hdr, false);
|
||||
ip4_hdr_set_df_flag(hdr, false);
|
||||
ip4_hdr_set_mf_flag(hdr, true);
|
||||
EXPECT_TRUE(memcmp(buff, data1, 20) == 0);
|
||||
}
|
||||
|
||||
@@ -127,23 +127,23 @@ unsigned char data2[] = {0x45, 0x00, 0x00, 0x2c, 0xff, 0xff, 0x00, 0x03, 0x7f, 0
|
||||
TEST(IPV4_UTILS, GET2)
|
||||
{
|
||||
const struct ip *hdr = (struct ip *)data2;
|
||||
EXPECT_TRUE(ipv4_hdr_get_version(hdr) == 4);
|
||||
EXPECT_TRUE(ipv4_hdr_get_hdr_len(hdr) == 20);
|
||||
EXPECT_TRUE(ipv4_hdr_get_tos(hdr) == 0);
|
||||
EXPECT_TRUE(ipv4_hdr_get_total_len(hdr) == 44);
|
||||
EXPECT_TRUE(ipv4_hdr_get_ipid(hdr) == 65535);
|
||||
EXPECT_TRUE(ipv4_hdr_get_flags(hdr) == 0);
|
||||
EXPECT_TRUE(ipv4_hdr_get_rf_flag(hdr) == false);
|
||||
EXPECT_TRUE(ipv4_hdr_get_df_flag(hdr) == false);
|
||||
EXPECT_TRUE(ipv4_hdr_get_mf_flag(hdr) == false);
|
||||
EXPECT_TRUE(ipv4_hdr_get_frag_offset(hdr) == 24);
|
||||
EXPECT_TRUE(ipv4_hdr_get_ttl(hdr) == 127);
|
||||
EXPECT_TRUE(ipv4_hdr_get_proto(hdr) == 6);
|
||||
EXPECT_TRUE(ipv4_hdr_get_checksum(hdr) == 0x6d88);
|
||||
EXPECT_TRUE(ipv4_hdr_get_src_addr(hdr) == 0xc0a82467);
|
||||
EXPECT_TRUE(ipv4_hdr_get_dst_addr(hdr) == 0xc0a82889);
|
||||
EXPECT_TRUE(ipv4_hdr_get_opt_len(hdr) == 0);
|
||||
EXPECT_TRUE(ipv4_hdr_get_opt_data(hdr) == NULL);
|
||||
EXPECT_TRUE(ip4_hdr_get_version(hdr) == 4);
|
||||
EXPECT_TRUE(ip4_hdr_get_hdr_len(hdr) == 20);
|
||||
EXPECT_TRUE(ip4_hdr_get_tos(hdr) == 0);
|
||||
EXPECT_TRUE(ip4_hdr_get_total_len(hdr) == 44);
|
||||
EXPECT_TRUE(ip4_hdr_get_ipid(hdr) == 65535);
|
||||
EXPECT_TRUE(ip4_hdr_get_flags(hdr) == 0);
|
||||
EXPECT_TRUE(ip4_hdr_get_rf_flag(hdr) == false);
|
||||
EXPECT_TRUE(ip4_hdr_get_df_flag(hdr) == false);
|
||||
EXPECT_TRUE(ip4_hdr_get_mf_flag(hdr) == false);
|
||||
EXPECT_TRUE(ip4_hdr_get_frag_offset(hdr) == 24);
|
||||
EXPECT_TRUE(ip4_hdr_get_ttl(hdr) == 127);
|
||||
EXPECT_TRUE(ip4_hdr_get_proto(hdr) == 6);
|
||||
EXPECT_TRUE(ip4_hdr_get_checksum(hdr) == 0x6d88);
|
||||
EXPECT_TRUE(ip4_hdr_get_src_addr(hdr) == 0xc0a82467);
|
||||
EXPECT_TRUE(ip4_hdr_get_dst_addr(hdr) == 0xc0a82889);
|
||||
EXPECT_TRUE(ip4_hdr_get_opt_len(hdr) == 0);
|
||||
EXPECT_TRUE(ip4_hdr_get_opt_data(hdr) == NULL);
|
||||
}
|
||||
|
||||
TEST(IPV4_UTILS, SET2)
|
||||
@@ -151,26 +151,26 @@ TEST(IPV4_UTILS, SET2)
|
||||
char buff[20] = {0};
|
||||
|
||||
struct ip *hdr = (struct ip *)buff;
|
||||
ipv4_hdr_set_version(hdr, 4);
|
||||
ipv4_hdr_set_hdr_len(hdr, 20);
|
||||
ipv4_hdr_set_tos(hdr, 0);
|
||||
ipv4_hdr_set_total_len(hdr, 44);
|
||||
ipv4_hdr_set_ipid(hdr, 65535);
|
||||
ipv4_hdr_set_frag_offset(hdr, 24);
|
||||
ipv4_hdr_set_ttl(hdr, 127);
|
||||
ipv4_hdr_set_protocol(hdr, 6);
|
||||
ipv4_hdr_set_checksum(hdr, 0x6d88);
|
||||
ipv4_hdr_set_src_addr(hdr, 0xc0a82467);
|
||||
ipv4_hdr_set_dst_addr(hdr, 0xc0a82889);
|
||||
ipv4_hdr_set_opt_len(hdr, 0);
|
||||
ipv4_hdr_set_opt_data(hdr, NULL);
|
||||
ip4_hdr_set_version(hdr, 4);
|
||||
ip4_hdr_set_hdr_len(hdr, 20);
|
||||
ip4_hdr_set_tos(hdr, 0);
|
||||
ip4_hdr_set_total_len(hdr, 44);
|
||||
ip4_hdr_set_ipid(hdr, 65535);
|
||||
ip4_hdr_set_frag_offset(hdr, 24);
|
||||
ip4_hdr_set_ttl(hdr, 127);
|
||||
ip4_hdr_set_protocol(hdr, 6);
|
||||
ip4_hdr_set_checksum(hdr, 0x6d88);
|
||||
ip4_hdr_set_src_addr(hdr, 0xc0a82467);
|
||||
ip4_hdr_set_dst_addr(hdr, 0xc0a82889);
|
||||
ip4_hdr_set_opt_len(hdr, 0);
|
||||
ip4_hdr_set_opt_data(hdr, NULL);
|
||||
|
||||
ipv4_hdr_set_flags(hdr, 0);
|
||||
ip4_hdr_set_flags(hdr, 0);
|
||||
EXPECT_TRUE(memcmp(buff, data2, 20) == 0);
|
||||
|
||||
ipv4_hdr_set_rf_flag(hdr, false);
|
||||
ipv4_hdr_set_df_flag(hdr, false);
|
||||
ipv4_hdr_set_mf_flag(hdr, false);
|
||||
ip4_hdr_set_rf_flag(hdr, false);
|
||||
ip4_hdr_set_df_flag(hdr, false);
|
||||
ip4_hdr_set_mf_flag(hdr, false);
|
||||
EXPECT_TRUE(memcmp(buff, data2, 20) == 0);
|
||||
}
|
||||
|
||||
@@ -220,23 +220,23 @@ unsigned char data3[] = {
|
||||
TEST(IPV4_UTILS, GET3)
|
||||
{
|
||||
const struct ip *hdr = (struct ip *)data3;
|
||||
EXPECT_TRUE(ipv4_hdr_get_version(hdr) == 4);
|
||||
EXPECT_TRUE(ipv4_hdr_get_hdr_len(hdr) == 60);
|
||||
EXPECT_TRUE(ipv4_hdr_get_tos(hdr) == 0);
|
||||
EXPECT_TRUE(ipv4_hdr_get_total_len(hdr) == 124);
|
||||
EXPECT_TRUE(ipv4_hdr_get_ipid(hdr) == 0);
|
||||
EXPECT_TRUE(ipv4_hdr_get_flags(hdr) == 2);
|
||||
EXPECT_TRUE(ipv4_hdr_get_rf_flag(hdr) == false);
|
||||
EXPECT_TRUE(ipv4_hdr_get_df_flag(hdr) == true);
|
||||
EXPECT_TRUE(ipv4_hdr_get_mf_flag(hdr) == false);
|
||||
EXPECT_TRUE(ipv4_hdr_get_frag_offset(hdr) == 0);
|
||||
EXPECT_TRUE(ipv4_hdr_get_ttl(hdr) == 64);
|
||||
EXPECT_TRUE(ipv4_hdr_get_proto(hdr) == 1);
|
||||
EXPECT_TRUE(ipv4_hdr_get_checksum(hdr) == 0xfd30);
|
||||
EXPECT_TRUE(ipv4_hdr_get_src_addr(hdr) == 0x7f000001);
|
||||
EXPECT_TRUE(ipv4_hdr_get_dst_addr(hdr) == 0x7f000001);
|
||||
EXPECT_TRUE(ipv4_hdr_get_opt_len(hdr) == 40);
|
||||
EXPECT_TRUE(ipv4_hdr_get_opt_data(hdr) == (const char *)(data3 + 20));
|
||||
EXPECT_TRUE(ip4_hdr_get_version(hdr) == 4);
|
||||
EXPECT_TRUE(ip4_hdr_get_hdr_len(hdr) == 60);
|
||||
EXPECT_TRUE(ip4_hdr_get_tos(hdr) == 0);
|
||||
EXPECT_TRUE(ip4_hdr_get_total_len(hdr) == 124);
|
||||
EXPECT_TRUE(ip4_hdr_get_ipid(hdr) == 0);
|
||||
EXPECT_TRUE(ip4_hdr_get_flags(hdr) == 2);
|
||||
EXPECT_TRUE(ip4_hdr_get_rf_flag(hdr) == false);
|
||||
EXPECT_TRUE(ip4_hdr_get_df_flag(hdr) == true);
|
||||
EXPECT_TRUE(ip4_hdr_get_mf_flag(hdr) == false);
|
||||
EXPECT_TRUE(ip4_hdr_get_frag_offset(hdr) == 0);
|
||||
EXPECT_TRUE(ip4_hdr_get_ttl(hdr) == 64);
|
||||
EXPECT_TRUE(ip4_hdr_get_proto(hdr) == 1);
|
||||
EXPECT_TRUE(ip4_hdr_get_checksum(hdr) == 0xfd30);
|
||||
EXPECT_TRUE(ip4_hdr_get_src_addr(hdr) == 0x7f000001);
|
||||
EXPECT_TRUE(ip4_hdr_get_dst_addr(hdr) == 0x7f000001);
|
||||
EXPECT_TRUE(ip4_hdr_get_opt_len(hdr) == 40);
|
||||
EXPECT_TRUE(ip4_hdr_get_opt_data(hdr) == (const char *)(data3 + 20));
|
||||
}
|
||||
|
||||
TEST(IPV4_UTILS, SET3)
|
||||
@@ -244,26 +244,26 @@ TEST(IPV4_UTILS, SET3)
|
||||
char buff[60] = {0};
|
||||
|
||||
struct ip *hdr = (struct ip *)buff;
|
||||
ipv4_hdr_set_version(hdr, 4);
|
||||
ipv4_hdr_set_hdr_len(hdr, 60);
|
||||
ipv4_hdr_set_tos(hdr, 0);
|
||||
ipv4_hdr_set_total_len(hdr, 124);
|
||||
ipv4_hdr_set_ipid(hdr, 0);
|
||||
ipv4_hdr_set_frag_offset(hdr, 0);
|
||||
ipv4_hdr_set_ttl(hdr, 64);
|
||||
ipv4_hdr_set_protocol(hdr, 1);
|
||||
ipv4_hdr_set_checksum(hdr, 0xfd30);
|
||||
ipv4_hdr_set_src_addr(hdr, 0x7f000001);
|
||||
ipv4_hdr_set_dst_addr(hdr, 0x7f000001);
|
||||
ipv4_hdr_set_opt_len(hdr, 40);
|
||||
ipv4_hdr_set_opt_data(hdr, (const char *)(data3 + 20));
|
||||
ip4_hdr_set_version(hdr, 4);
|
||||
ip4_hdr_set_hdr_len(hdr, 60);
|
||||
ip4_hdr_set_tos(hdr, 0);
|
||||
ip4_hdr_set_total_len(hdr, 124);
|
||||
ip4_hdr_set_ipid(hdr, 0);
|
||||
ip4_hdr_set_frag_offset(hdr, 0);
|
||||
ip4_hdr_set_ttl(hdr, 64);
|
||||
ip4_hdr_set_protocol(hdr, 1);
|
||||
ip4_hdr_set_checksum(hdr, 0xfd30);
|
||||
ip4_hdr_set_src_addr(hdr, 0x7f000001);
|
||||
ip4_hdr_set_dst_addr(hdr, 0x7f000001);
|
||||
ip4_hdr_set_opt_len(hdr, 40);
|
||||
ip4_hdr_set_opt_data(hdr, (const char *)(data3 + 20));
|
||||
|
||||
ipv4_hdr_set_flags(hdr, 2);
|
||||
ip4_hdr_set_flags(hdr, 2);
|
||||
EXPECT_TRUE(memcmp(buff, data3, 60) == 0);
|
||||
|
||||
ipv4_hdr_set_rf_flag(hdr, false);
|
||||
ipv4_hdr_set_df_flag(hdr, true);
|
||||
ipv4_hdr_set_mf_flag(hdr, false);
|
||||
ip4_hdr_set_rf_flag(hdr, false);
|
||||
ip4_hdr_set_df_flag(hdr, true);
|
||||
ip4_hdr_set_mf_flag(hdr, false);
|
||||
EXPECT_TRUE(memcmp(buff, data3, 60) == 0);
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include "ipv6_utils.h"
|
||||
#include "ip6_utils.h"
|
||||
|
||||
/*
|
||||
* Internet Protocol Version 6, Src: fe80::250:56ff:fe69:dc00, Dst: ff02::1:2
|
||||
@@ -26,14 +26,14 @@ TEST(IPV6_UTILS, GET)
|
||||
char src_str[INET6_ADDRSTRLEN];
|
||||
char dst_str[INET6_ADDRSTRLEN];
|
||||
const struct ip6_hdr *hdr = (struct ip6_hdr *)data;
|
||||
EXPECT_TRUE(ipv6_hdr_get_version(hdr) == 6);
|
||||
EXPECT_TRUE(ipv6_hdr_get_traffic_class(hdr) == 0);
|
||||
EXPECT_TRUE(ipv6_hdr_get_flow_label(hdr) == 0);
|
||||
EXPECT_TRUE(ipv6_hdr_get_payload_len(hdr) == 60);
|
||||
EXPECT_TRUE(ipv6_hdr_get_next_header(hdr) == 17);
|
||||
EXPECT_TRUE(ipv6_hdr_get_hop_limit(hdr) == 1);
|
||||
struct in6_addr src_addr = ipv6_hdr_get_src_in6_addr(hdr);
|
||||
struct in6_addr dst_addr = ipv6_hdr_get_dst_in6_addr(hdr);
|
||||
EXPECT_TRUE(ip6_hdr_get_version(hdr) == 6);
|
||||
EXPECT_TRUE(ip6_hdr_get_traffic_class(hdr) == 0);
|
||||
EXPECT_TRUE(ip6_hdr_get_flow_label(hdr) == 0);
|
||||
EXPECT_TRUE(ip6_hdr_get_payload_len(hdr) == 60);
|
||||
EXPECT_TRUE(ip6_hdr_get_next_header(hdr) == 17);
|
||||
EXPECT_TRUE(ip6_hdr_get_hop_limit(hdr) == 1);
|
||||
struct in6_addr src_addr = ip6_hdr_get_src_in6_addr(hdr);
|
||||
struct in6_addr dst_addr = ip6_hdr_get_dst_in6_addr(hdr);
|
||||
|
||||
inet_ntop(AF_INET6, &src_addr, src_str, INET6_ADDRSTRLEN);
|
||||
inet_ntop(AF_INET6, &dst_addr, dst_str, INET6_ADDRSTRLEN);
|
||||
@@ -50,14 +50,14 @@ TEST(IPV6_UTILS, SET)
|
||||
|
||||
inet_pton(AF_INET6, "fe80::250:56ff:fe69:dc00", &src_addr);
|
||||
inet_pton(AF_INET6, "ff02::1:2", &dst_addr);
|
||||
ipv6_hdr_set_version(hdr, 6);
|
||||
ipv6_hdr_set_traffic_class(hdr, 0);
|
||||
ipv6_hdr_set_flow_label(hdr, 0);
|
||||
ipv6_hdr_set_payload_len(hdr, 60);
|
||||
ipv6_hdr_set_next_header(hdr, 17);
|
||||
ipv6_hdr_set_hop_limit(hdr, 1);
|
||||
ipv6_hdr_set_src_in6_addr(hdr, src_addr);
|
||||
ipv6_hdr_set_dst_in6_addr(hdr, dst_addr);
|
||||
ip6_hdr_set_version(hdr, 6);
|
||||
ip6_hdr_set_traffic_class(hdr, 0);
|
||||
ip6_hdr_set_flow_label(hdr, 0);
|
||||
ip6_hdr_set_payload_len(hdr, 60);
|
||||
ip6_hdr_set_next_header(hdr, 17);
|
||||
ip6_hdr_set_hop_limit(hdr, 1);
|
||||
ip6_hdr_set_src_in6_addr(hdr, src_addr);
|
||||
ip6_hdr_set_dst_in6_addr(hdr, dst_addr);
|
||||
|
||||
EXPECT_TRUE(memcmp(buff, data, 40) == 0);
|
||||
}
|
||||
@@ -1635,9 +1635,9 @@ TEST(PACKET_PARSE, ETH_IP6_UDP_GTP_IP6_TCP_TLS)
|
||||
EXPECT_TRUE(outer_udp_record->hdr_len == 8);
|
||||
EXPECT_TRUE(outer_udp_record->pld_len == 1380);
|
||||
|
||||
// LAYER_PROTO_GTP
|
||||
const struct raw_layer *outer_gtp_record = packet_get_outermost_raw_layer(&handler, LAYER_PROTO_GTP);
|
||||
const struct raw_layer *inner_gtp_record = packet_get_innermost_raw_layer(&handler, LAYER_PROTO_GTP);
|
||||
// LAYER_PROTO_GTP_U
|
||||
const struct raw_layer *outer_gtp_record = packet_get_outermost_raw_layer(&handler, LAYER_PROTO_GTP_U);
|
||||
const struct raw_layer *inner_gtp_record = packet_get_innermost_raw_layer(&handler, LAYER_PROTO_GTP_U);
|
||||
|
||||
EXPECT_TRUE(outer_gtp_record != nullptr);
|
||||
EXPECT_TRUE(inner_gtp_record != nullptr);
|
||||
@@ -1892,9 +1892,9 @@ TEST(PACKET_PARSE, ETH_IP6_UDP_GTP_IP4_TCP_TLS)
|
||||
EXPECT_TRUE(outer_udp_record->hdr_len == 8);
|
||||
EXPECT_TRUE(outer_udp_record->pld_len == 1408);
|
||||
|
||||
// LAYER_PROTO_GTP
|
||||
const struct raw_layer *outer_gtp_record = packet_get_outermost_raw_layer(&handler, LAYER_PROTO_GTP);
|
||||
const struct raw_layer *inner_gtp_record = packet_get_innermost_raw_layer(&handler, LAYER_PROTO_GTP);
|
||||
// LAYER_PROTO_GTP_U
|
||||
const struct raw_layer *outer_gtp_record = packet_get_outermost_raw_layer(&handler, LAYER_PROTO_GTP_U);
|
||||
const struct raw_layer *inner_gtp_record = packet_get_innermost_raw_layer(&handler, LAYER_PROTO_GTP_U);
|
||||
|
||||
EXPECT_TRUE(outer_gtp_record != nullptr);
|
||||
EXPECT_TRUE(inner_gtp_record != nullptr);
|
||||
|
||||
@@ -2,8 +2,8 @@
|
||||
|
||||
#include "udp_utils.h"
|
||||
#include "gre_utils.h"
|
||||
#include "ipv4_utils.h"
|
||||
#include "ipv6_utils.h"
|
||||
#include "ip4_utils.h"
|
||||
#include "ip6_utils.h"
|
||||
#include "vxlan_utils.h"
|
||||
#include "packet_def.h"
|
||||
#include "packet_parse.h"
|
||||
@@ -626,7 +626,7 @@ TEST(TUNNEL, GTP)
|
||||
EXPECT_TRUE(out.layers[1].proto == LAYER_PROTO_UDP);
|
||||
EXPECT_TRUE(out.layers[1].hdr_len == 8);
|
||||
|
||||
EXPECT_TRUE(out.layers[2].proto == LAYER_PROTO_GTP);
|
||||
EXPECT_TRUE(out.layers[2].proto == LAYER_PROTO_GTP_U);
|
||||
EXPECT_TRUE(out.layers[2].hdr_len == 8);
|
||||
|
||||
// No tunnel
|
||||
|
||||
Reference in New Issue
Block a user