[v1,2/2] validation: packet: add IPv4 options

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

Commit Message

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


Added test case for IPv4 options.

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    | 12 ++++++++++++
 test/validation/api/packet/packet.c | 37 ++++++++++++++++++++++++++++++++++++-
 2 files changed, 48 insertions(+), 1 deletion(-)

Patch

diff --git a/test/common/test_packet_parser.h b/test/common/test_packet_parser.h
index fd1b40abf..09c998c9d 100644
--- a/test/common/test_packet_parser.h
+++ b/test/common/test_packet_parser.h
@@ -424,6 +424,18 @@  static const uint8_t test_packet_ipv4_udp_last_frag[] = {
 	0x2E
 };
 
+/* IPv4 / Record Route + NOP options / ICMP */
+static const uint8_t test_packet_ipv4_rr_nop_icmp[] = {
+	0x02, 0x00, 0x00, 0x04, 0x05, 0x06, 0x02, 0x00,
+	0x00, 0x01, 0x02, 0x03, 0x08, 0x00, 0x49, 0x00,
+	0x00, 0x2C, 0x00, 0x01, 0x00, 0x00, 0x40, 0x01,
+	0x8E, 0xE2, 0xC0, 0xA8, 0x00, 0x01, 0xC0, 0xA8,
+	0x00, 0x02, 0x07, 0x0F, 0x0C, 0xC0, 0xA8, 0x04,
+	0x01, 0xC0, 0xA8, 0x05, 0x01, 0x00, 0x00, 0x00,
+	0x00, 0x01, 0x08, 0x00, 0xF7, 0xFF, 0x00, 0x00,
+	0x00, 0x00
+};
+
 #ifdef __cplusplus
 }
 #endif
diff --git a/test/validation/api/packet/packet.c b/test/validation/api/packet/packet.c
index 71bf1d861..054a0d4ef 100644
--- a/test/validation/api/packet/packet.c
+++ b/test/validation/api/packet/packet.c
@@ -70,7 +70,8 @@  static uint32_t parse_test_pkt_len[] = {
 	sizeof(test_packet_bcast_eth_ipv4_udp),
 	sizeof(test_packet_mcast_eth_ipv6_udp),
 	sizeof(test_packet_ipv4_udp_first_frag),
-	sizeof(test_packet_ipv4_udp_last_frag)
+	sizeof(test_packet_ipv4_udp_last_frag),
+	sizeof(test_packet_ipv4_rr_nop_icmp)
 };
 
 #define packet_compare_offset(pkt1, off1, pkt2, off2, len) \
@@ -3223,6 +3224,39 @@  static void parse_eth_ipv4_udp_last_frag(void)
 	odp_packet_free_multi(pkt, num_pkt);
 }
 
+/* Ethernet/IPv4 + options (Record route, NOP)/ICMP */
+static void parse_eth_ipv4_rr_nop_icmp(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_rr_nop_icmp,
+			 sizeof(test_packet_ipv4_rr_nop_icmp));
+
+	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_ipopt(pkt[i]));
+		CU_ASSERT(odp_packet_has_icmp(pkt[i]));
+		CU_ASSERT(!odp_packet_has_ipfrag(pkt[i]));
+		CU_ASSERT(!odp_packet_has_ipv6(pkt[i]));
+		CU_ASSERT(!odp_packet_has_udp(pkt[i]));
+		CU_ASSERT(!odp_packet_has_tcp(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),
@@ -3279,6 +3313,7 @@  odp_testinfo_t packet_parse_suite[] = {
 	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(parse_eth_ipv4_rr_nop_icmp),
 	ODP_TEST_INFO_NULL,
 };