diff mbox series

[v2,4/7] validation: packet: add IPv4 SCTP parse test

Message ID 1518530410-18574-5-git-send-email-odpbot@yandex.ru
State New
Headers show
Series [v2,1/7] validation: common: remove camel case names | expand

Commit Message

Github ODP bot Feb. 13, 2018, 2 p.m. UTC
From: Petri Savolainen <petri.savolainen@linaro.org>


Added test for IPv4 / SCTP packet with payload data chunk type.

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

---
/** Email created from pull request 472 (psavol:master-parser-validation)
 ** https://github.com/Linaro/odp/pull/472
 ** Patch: https://github.com/Linaro/odp/pull/472.patch
 ** Base sha: 41b3fa2cd994a7ef68290a07dcde5564e4640847
 ** Merge commit sha: 38d924655e8119f902e986011a477e1ad9094ab6
 **/
 test/common/test_packet_parser.h    | 74 ++++++++++++++++++-------------------
 test/validation/api/packet/packet.c | 35 +++++++++++++++++-
 2 files changed, 71 insertions(+), 38 deletions(-)
diff mbox series

Patch

diff --git a/test/common/test_packet_parser.h b/test/common/test_packet_parser.h
index 918e0ad65..22c7e6c57 100644
--- a/test/common/test_packet_parser.h
+++ b/test/common/test_packet_parser.h
@@ -4,12 +4,6 @@ 
  * SPDX-License-Identifier:     BSD-3-Clause
  */
 
-/**
- * @file
- *
- * Test packets for parser tests
- */
-
 #ifndef TEST_PACKET_PARSER_H_
 #define TEST_PACKET_PARSER_H_
 
@@ -21,9 +15,7 @@  extern "C" {
 
 /* Test packets without CRC */
 
-/**
- * ARP request
- */
+/* ARP request */
 static const uint8_t test_packet_arp[] = {
 	0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x00,
 	0x09, 0x00, 0x04, 0x00, 0x08, 0x06, 0x00, 0x01,
@@ -35,9 +27,7 @@  static const uint8_t test_packet_arp[] = {
 	0x0E, 0x0F, 0x10, 0x11
 };
 
-/**
- * ICMPv4 echo reply
- */
+/* ICMPv4 echo reply */
 static const uint8_t test_packet_ipv4_icmp[] = {
 	0x00, 0x00, 0x09, 0x00, 0x05, 0x00, 0x00, 0x00,
 	0x09, 0x00, 0x04, 0x00, 0x08, 0x00, 0x45, 0x00,
@@ -49,9 +39,7 @@  static const uint8_t test_packet_ipv4_icmp[] = {
 	0x0E, 0x0F, 0x10, 0x11
 };
 
-/**
- * IPv4 TCP
- */
+/* IPv4 TCP */
 static const uint8_t test_packet_ipv4_tcp[] = {
 	0x00, 0x00, 0x09, 0x00, 0x05, 0x00, 0x00, 0x00,
 	0x09, 0x00, 0x04, 0x00, 0x08, 0x00, 0x45, 0x00,
@@ -63,9 +51,7 @@  static const uint8_t test_packet_ipv4_tcp[] = {
 	0x02, 0x03, 0x04, 0x05
 };
 
-/**
- * IPv4 UDP
- */
+/* IPv4 UDP */
 static const uint8_t test_packet_ipv4_udp[] = {
 	0x00, 0x00, 0x09, 0x00, 0x05, 0x00, 0x00, 0x00,
 	0x09, 0x00, 0x04, 0x00, 0x08, 0x00, 0x45, 0x00,
@@ -77,9 +63,8 @@  static const uint8_t test_packet_ipv4_udp[] = {
 	0x0E, 0x0F, 0x10, 0x11
 };
 
-/**
- * VLAN IPv4 UDP
- * - ID: 23
+/* VLAN IPv4 UDP
+ * - type 0x8100, tag 23
  */
 static const uint8_t test_packet_vlan_ipv4_udp[] = {
 	0x00, 0x00, 0x09, 0x00, 0x05, 0x00, 0x00, 0x00,
@@ -92,10 +77,9 @@  static const uint8_t test_packet_vlan_ipv4_udp[] = {
 	0x0A, 0x0B, 0x0C, 0x0D
 };
 
-/**
- * VLAN Q-in-Q IPv4 UDP
- * - Outer: Tag Protocol ID 0x88a8, VLAN ID 1
- * - Inner: Tag Protocol ID 0x8100, VLAN ID 2
+/* VLAN Q-in-Q IPv4 UDP
+ * - Outer: type 0x88a8, tag 1
+ * - Inner: type 0x8100, tag 2
  */
 static const uint8_t test_packet_vlan_qinq_ipv4_udp[] = {
 	0x00, 0x00, 0x09, 0x00, 0x05, 0x00, 0x00, 0x00,
@@ -108,9 +92,7 @@  static const uint8_t test_packet_vlan_qinq_ipv4_udp[] = {
 	0x06, 0x07, 0x08, 0x09
 };
 
-/**
- * ICMPv6 echo request
- */
+/* ICMPv6 echo request */
 static const uint8_t test_packet_ipv6_icmp[] = {
 	0x00, 0x00, 0x09, 0x00, 0x05, 0x00, 0x00, 0x00,
 	0x09, 0x00, 0x04, 0x00, 0x86, 0xDD, 0x60, 0x30,
@@ -122,9 +104,7 @@  static const uint8_t test_packet_ipv6_icmp[] = {
 	0x1B, 0xC2, 0x00, 0x01, 0x00, 0x02
 };
 
-/**
- * IPv6 TCP
- */
+/* IPv6 TCP */
 static const uint8_t test_packet_ipv6_tcp[] = {
 	0x00, 0x00, 0x09, 0x00, 0x05, 0x00, 0x00, 0x00,
 	0x09, 0x00, 0x04, 0x00, 0x86, 0xDD, 0x60, 0x30,
@@ -138,9 +118,7 @@  static const uint8_t test_packet_ipv6_tcp[] = {
 	0x00, 0x00
 };
 
-/**
- * IPv6 UDP
- */
+/* IPv6 UDP */
 static const uint8_t test_packet_ipv6_udp[] = {
 	0x00, 0x00, 0x09, 0x00, 0x05, 0x00, 0x00, 0x00,
 	0x09, 0x00, 0x04, 0x00, 0x86, 0xDD, 0x60, 0x30,
@@ -152,9 +130,8 @@  static const uint8_t test_packet_ipv6_udp[] = {
 	0x00, 0x3F, 0x00, 0x08, 0x9B, 0x68
 };
 
-/**
- * VLAN IPv6
- * - ID: 23
+/* VLAN IPv6
+ * - type 0x8100, tag 23
  */
 static const uint8_t test_packet_vlan_ipv6_udp[] = {
 	0x00, 0x00, 0x09, 0x00, 0x05, 0x00, 0x00, 0x00,
@@ -168,6 +145,29 @@  static const uint8_t test_packet_vlan_ipv6_udp[] = {
 	0x9B, 0x68
 };
 
+/* IPv4 SCTP
+ * - chunk type: payload data
+ */
+static const uint8_t test_packet_ipv4_sctp[] = {
+	0x00, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x00, 0x01,
+	0x02, 0x03, 0x04, 0x05, 0x08, 0x00, 0x45, 0x00,
+	0x00, 0x77, 0x00, 0x01, 0x00, 0x00, 0x40, 0x84,
+	0xF8, 0xAE, 0xC0, 0xA8, 0x00, 0x01, 0xC0, 0xA8,
+	0x00, 0x02, 0x04, 0xD2, 0x16, 0x2E, 0xDE, 0xAD,
+	0xBE, 0xEF, 0x31, 0x44, 0xE3, 0xFE, 0x00, 0x00,
+	0x00, 0x57, 0x00, 0x00, 0x00, 0x0A, 0x00, 0x00,
+	0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 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 ea7e89b2f..ad5520408 100644
--- a/test/validation/api/packet/packet.c
+++ b/test/validation/api/packet/packet.c
@@ -60,7 +60,8 @@  static uint32_t parse_test_pkt_len[] = {
 	sizeof(test_packet_ipv6_icmp),
 	sizeof(test_packet_ipv6_tcp),
 	sizeof(test_packet_ipv6_udp),
-	sizeof(test_packet_vlan_ipv6_udp)
+	sizeof(test_packet_vlan_ipv6_udp),
+	sizeof(test_packet_ipv4_sctp)
 };
 
 #define packet_compare_offset(pkt1, off1, pkt2, off2, len) \
@@ -2891,6 +2892,37 @@  static void parse_eth_ipv6_icmp(void)
 	odp_packet_free_multi(pkt, num_pkt);
 }
 
+/* Ethernet/IPv4/SCTP */
+static void parse_eth_ipv4_sctp(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_sctp,
+			 sizeof(test_packet_ipv4_sctp));
+
+	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_sctp(pkt[i]));
+		CU_ASSERT(!odp_packet_has_ipv6(pkt[i]));
+		CU_ASSERT(!odp_packet_has_tcp(pkt[i]));
+		CU_ASSERT(!odp_packet_has_udp(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),
@@ -2937,6 +2969,7 @@  odp_testinfo_t packet_parse_suite[] = {
 	ODP_TEST_INFO(parse_eth_arp),
 	ODP_TEST_INFO(parse_eth_ipv4_icmp),
 	ODP_TEST_INFO(parse_eth_ipv6_icmp),
+	ODP_TEST_INFO(parse_eth_ipv4_sctp),
 	ODP_TEST_INFO_NULL,
 };