diff mbox series

[v1,1/2] validation: packet: add IPv4 fragments

Message ID 1518782408-24067-2-git-send-email-odpbot@yandex.ru
State New
Headers show
Series [v1,1/2] validation: packet: add IPv4 fragments | expand

Commit Message

Github ODP bot Feb. 16, 2018, noon UTC
From: Petri Savolainen <petri.savolainen@linaro.org>


Added test cases for IPv4/UDP fragments.

Signed-off-by: Petri Savolainen <petri.savolainen@linaro.org>

---
/** Email created from pull request 487 (psavol:master-parser-validation-2)
 ** https://github.com/Linaro/odp/pull/487
 ** Patch: https://github.com/Linaro/odp/pull/487.patch
 ** Base sha: ea529e1c3312459b6722c8a175d7f03ad0251a0a
 ** Merge commit sha: eaabe19cc054a6abb16e8ea22cc256106e47a7c5
 **/
 test/common/test_packet_parser.h    | 35 +++++++++++++++++++
 test/validation/api/packet/packet.c | 70 ++++++++++++++++++++++++++++++++++++-
 2 files changed, 104 insertions(+), 1 deletion(-)
diff mbox series

Patch

diff --git a/test/common/test_packet_parser.h b/test/common/test_packet_parser.h
index d0a0582ab..fd1b40abf 100644
--- a/test/common/test_packet_parser.h
+++ b/test/common/test_packet_parser.h
@@ -389,6 +389,41 @@  static const uint8_t test_packet_mcast_eth_ipv6_udp[] = {
 	0x79, 0x74, 0x65, 0x73, 0x2E
 };
 
+static const uint8_t test_packet_ipv4_udp_first_frag[] = {
+	0x02, 0x00, 0x00, 0x04, 0x05, 0x06, 0x02, 0x00,
+	0x00, 0x01, 0x02, 0x03, 0x08, 0x00, 0x45, 0x00,
+	0x00, 0x63, 0x00, 0x01, 0x20, 0x00, 0x40, 0x11,
+	0xD9, 0x35, 0xC0, 0xA8, 0x00, 0x01, 0xC0, 0xA8,
+	0x00, 0x02, 0x04, 0xD2, 0x16, 0x2E, 0x01, 0x17,
+	0x54, 0xF3, 0x54, 0x68, 0x69, 0x73, 0x20, 0x69,
+	0x73, 0x20, 0x6D, 0x79, 0x20, 0x64, 0x75, 0x6D,
+	0x6D, 0x79, 0x20, 0x70, 0x61, 0x79, 0x6C, 0x6F,
+	0x61, 0x64, 0x20, 0x73, 0x74, 0x72, 0x69, 0x6E,
+	0x67, 0x2E, 0x20, 0x54, 0x68, 0x65, 0x20, 0x6C,
+	0x65, 0x6E, 0x67, 0x74, 0x68, 0x20, 0x6F, 0x66,
+	0x20, 0x74, 0x68, 0x69, 0x73, 0x20, 0x73, 0x74,
+	0x72, 0x69, 0x6E, 0x67, 0x20, 0x69, 0x73, 0x20,
+	0x37, 0x31, 0x20, 0x62, 0x79, 0x74, 0x65, 0x73,
+	0x2E
+};
+
+static const uint8_t test_packet_ipv4_udp_last_frag[] = {
+	0x02, 0x00, 0x00, 0x04, 0x05, 0x06, 0x02, 0x00,
+	0x00, 0x01, 0x02, 0x03, 0x08, 0x00, 0x45, 0x00,
+	0x00, 0x5B, 0x00, 0x01, 0x00, 0x0A, 0x40, 0x11,
+	0xF9, 0x33, 0xC0, 0xA8, 0x00, 0x01, 0xC0, 0xA8,
+	0x00, 0x02, 0x54, 0x68, 0x69, 0x73, 0x20, 0x69,
+	0x73, 0x20, 0x6D, 0x79, 0x20, 0x64, 0x75, 0x6D,
+	0x6D, 0x79, 0x20, 0x70, 0x61, 0x79, 0x6C, 0x6F,
+	0x61, 0x64, 0x20, 0x73, 0x74, 0x72, 0x69, 0x6E,
+	0x67, 0x2E, 0x20, 0x54, 0x68, 0x65, 0x20, 0x6C,
+	0x65, 0x6E, 0x67, 0x74, 0x68, 0x20, 0x6F, 0x66,
+	0x20, 0x74, 0x68, 0x69, 0x73, 0x20, 0x73, 0x74,
+	0x72, 0x69, 0x6E, 0x67, 0x20, 0x69, 0x73, 0x20,
+	0x37, 0x31, 0x20, 0x62, 0x79, 0x74, 0x65, 0x73,
+	0x2E
+};
+
 #ifdef __cplusplus
 }
 #endif
diff --git a/test/validation/api/packet/packet.c b/test/validation/api/packet/packet.c
index db3a47cf8..71bf1d861 100644
--- a/test/validation/api/packet/packet.c
+++ b/test/validation/api/packet/packet.c
@@ -68,7 +68,9 @@  static uint32_t parse_test_pkt_len[] = {
 	sizeof(test_packet_ipv6_ipsec_esp),
 	sizeof(test_packet_mcast_eth_ipv4_udp),
 	sizeof(test_packet_bcast_eth_ipv4_udp),
-	sizeof(test_packet_mcast_eth_ipv6_udp)
+	sizeof(test_packet_mcast_eth_ipv6_udp),
+	sizeof(test_packet_ipv4_udp_first_frag),
+	sizeof(test_packet_ipv4_udp_last_frag)
 };
 
 #define packet_compare_offset(pkt1, off1, pkt2, off2, len) \
@@ -3157,6 +3159,70 @@  static void parse_mcast_eth_ipv6_udp(void)
 	odp_packet_free_multi(pkt, num_pkt);
 }
 
+/* Ethernet/IPv4/UDP first fragment */
+static void parse_eth_ipv4_udp_first_frag(void)
+{
+	odp_packet_parse_param_t parse;
+	int i;
+	int num_pkt = PARSE_TEST_NUM_PKT;
+	odp_packet_t pkt[num_pkt];
+
+	parse_test_alloc(pkt, test_packet_ipv4_udp_first_frag,
+			 sizeof(test_packet_ipv4_udp_first_frag));
+
+	parse.proto = ODP_PROTO_ETH;
+	parse.last_layer = ODP_PROTO_LAYER_L4;
+	parse.chksums.all_chksum = 0;
+
+	CU_ASSERT(odp_packet_parse(pkt[0], 0, &parse) == 0);
+	CU_ASSERT(odp_packet_parse_multi(&pkt[1], parse_test.offset_zero,
+					 num_pkt - 1, &parse) == (num_pkt - 1));
+
+	for (i = 0; i < num_pkt; i++) {
+		CU_ASSERT(odp_packet_has_eth(pkt[i]));
+		CU_ASSERT(odp_packet_has_ipv4(pkt[i]));
+		CU_ASSERT(odp_packet_has_ipfrag(pkt[i]));
+		CU_ASSERT(odp_packet_has_udp(pkt[i]));
+		CU_ASSERT(!odp_packet_has_ipv6(pkt[i]));
+		CU_ASSERT(!odp_packet_has_tcp(pkt[i]));
+		CU_ASSERT(!odp_packet_has_ipopt(pkt[i]));
+	}
+
+	odp_packet_free_multi(pkt, num_pkt);
+}
+
+/* Ethernet/IPv4/UDP last fragment */
+static void parse_eth_ipv4_udp_last_frag(void)
+{
+	odp_packet_parse_param_t parse;
+	int i;
+	int num_pkt = PARSE_TEST_NUM_PKT;
+	odp_packet_t pkt[num_pkt];
+
+	parse_test_alloc(pkt, test_packet_ipv4_udp_last_frag,
+			 sizeof(test_packet_ipv4_udp_last_frag));
+
+	parse.proto = ODP_PROTO_ETH;
+	parse.last_layer = ODP_PROTO_LAYER_L4;
+	parse.chksums.all_chksum = 0;
+
+	CU_ASSERT(odp_packet_parse(pkt[0], 0, &parse) == 0);
+	CU_ASSERT(odp_packet_parse_multi(&pkt[1], parse_test.offset_zero,
+					 num_pkt - 1, &parse) == (num_pkt - 1));
+
+	for (i = 0; i < num_pkt; i++) {
+		CU_ASSERT(odp_packet_has_eth(pkt[i]));
+		CU_ASSERT(odp_packet_has_ipv4(pkt[i]));
+		CU_ASSERT(odp_packet_has_ipfrag(pkt[i]));
+		CU_ASSERT(odp_packet_has_udp(pkt[i]));
+		CU_ASSERT(!odp_packet_has_ipv6(pkt[i]));
+		CU_ASSERT(!odp_packet_has_tcp(pkt[i]));
+		CU_ASSERT(!odp_packet_has_ipopt(pkt[i]));
+	}
+
+	odp_packet_free_multi(pkt, num_pkt);
+}
+
 odp_testinfo_t packet_suite[] = {
 	ODP_TEST_INFO(packet_test_alloc_free),
 	ODP_TEST_INFO(packet_test_alloc_free_multi),
@@ -3211,6 +3277,8 @@  odp_testinfo_t packet_parse_suite[] = {
 	ODP_TEST_INFO(parse_mcast_eth_ipv4_udp),
 	ODP_TEST_INFO(parse_bcast_eth_ipv4_udp),
 	ODP_TEST_INFO(parse_mcast_eth_ipv6_udp),
+	ODP_TEST_INFO(parse_eth_ipv4_udp_first_frag),
+	ODP_TEST_INFO(parse_eth_ipv4_udp_last_frag),
 	ODP_TEST_INFO_NULL,
 };