diff mbox

[PATCHv2,1/1] validation: classification: fix TCP/UDP checksum update

Message ID 1477573255-28602-1-git-send-email-bala.manoharan@linaro.org
State Accepted
Commit 9c0fc2112137a07b5265646338a4034662d299b3
Headers show

Commit Message

Balasubramanian Manoharan Oct. 27, 2016, 1 p.m. UTC
Fixes https://bugs.linaro.org/show_bug.cgi?id=2512

Signed-off-by: Balasubramanian Manoharan <bala.manoharan@linaro.org>

---
v2: Incorporates review comments
 .../api/classification/odp_classification_common.c         | 14 +++++++++++++-
 .../api/classification/odp_classification_test_pmr.c       |  3 +++
 2 files changed, 16 insertions(+), 1 deletion(-)

-- 
1.9.1

Comments

Maxim Uvarov Nov. 3, 2016, 12:42 p.m. UTC | #1
ping, please review.

Maxim.

On 10/27/16 16:00, Balasubramanian Manoharan wrote:
> Fixes https://bugs.linaro.org/show_bug.cgi?id=2512

>

> Signed-off-by: Balasubramanian Manoharan <bala.manoharan@linaro.org>

> ---

> v2: Incorporates review comments

>   .../api/classification/odp_classification_common.c         | 14 +++++++++++++-

>   .../api/classification/odp_classification_test_pmr.c       |  3 +++

>   2 files changed, 16 insertions(+), 1 deletion(-)

>

> diff --git a/test/common_plat/validation/api/classification/odp_classification_common.c b/test/common_plat/validation/api/classification/odp_classification_common.c

> index 7a42ac7..2923a71 100644

> --- a/test/common_plat/validation/api/classification/odp_classification_common.c

> +++ b/test/common_plat/validation/api/classification/odp_classification_common.c

> @@ -11,6 +11,7 @@

>   #include <odp/helper/ip.h>

>   #include <odp/helper/udp.h>

>   #include <odp/helper/tcp.h>

> +#include "test_debug.h"

>   

>   typedef struct cls_test_packet {

>   	odp_u32be_t magic;

> @@ -291,6 +292,8 @@ odp_packet_t create_packet_len(odp_pool_t pool, bool vlan,

>   	parse_ipv4_string(CLS_DEFAULT_SADDR, &addr, &mask);

>   	ip->src_addr = odp_cpu_to_be_32(addr);

>   	ip->ver_ihl = ODPH_IPV4 << 4 | ODPH_IPV4HDR_IHL_MIN;

> +	odp_packet_has_ipv4_set(pkt, 1);

> +

>   	if (flag_udp)

>   		ip->tot_len = odp_cpu_to_be_16(ODPH_UDPHDR_LEN + payload_len +

>   					       ODPH_IPV4HDR_LEN);

> @@ -318,14 +321,23 @@ odp_packet_t create_packet_len(odp_pool_t pool, bool vlan,

>   		udp->dst_port = odp_cpu_to_be_16(CLS_DEFAULT_DPORT);

>   		udp->length = odp_cpu_to_be_16(payload_len + ODPH_UDPHDR_LEN);

>   		udp->chksum = 0;

> +		odp_packet_has_udp_set(pkt, 1);

> +		if (odph_udp_tcp_chksum(pkt, ODPH_CHKSUM_GENERATE, NULL) != 0) {

> +			LOG_ERR("odph_udp_tcp_chksum failed\n");

> +			return ODP_PACKET_INVALID;

> +		}

>   	} else {

>   		odp_packet_l4_offset_set(pkt, offset);

>   		tcp = (odph_tcphdr_t *)odp_packet_l4_ptr(pkt, NULL);

>   		tcp->src_port = odp_cpu_to_be_16(CLS_DEFAULT_SPORT);

>   		tcp->dst_port = odp_cpu_to_be_16(CLS_DEFAULT_DPORT);

>   		tcp->hl = ODPH_TCPHDR_LEN / 4;

> -		/* TODO: checksum field has to be updated */

>   		tcp->cksm = 0;

> +		odp_packet_has_tcp_set(pkt, 1);

> +		if (odph_udp_tcp_chksum(pkt, ODPH_CHKSUM_GENERATE, NULL) != 0) {

> +			LOG_ERR("odph_udp_tcp_chksum failed\n");

> +			return ODP_PACKET_INVALID;

> +		}

>   	}

>   

>   	/* set pkt sequence number */

> diff --git a/test/common_plat/validation/api/classification/odp_classification_test_pmr.c b/test/common_plat/validation/api/classification/odp_classification_test_pmr.c

> index c8bbf50..88fbf8f 100644

> --- a/test/common_plat/validation/api/classification/odp_classification_test_pmr.c

> +++ b/test/common_plat/validation/api/classification/odp_classification_test_pmr.c

> @@ -717,6 +717,7 @@ void classification_test_pmr_term_dmac(void)

>   

>   	/* Other packets delivered to default queue */

>   	pkt = create_packet(pkt_pool, false, &seq, false);

> +	CU_ASSERT_FATAL(pkt != ODP_PACKET_INVALID);

>   	eth = (odph_ethhdr_t *)odp_packet_l2_ptr(pkt, NULL);

>   	memset(eth->dst.addr, 0, ODPH_ETHADDR_LEN);

>   	CU_ASSERT_FATAL(pkt != ODP_PACKET_INVALID);

> @@ -1102,6 +1103,7 @@ static void classification_test_pmr_term_daddr(void)

>   	/* packet with dst ip address matching PMR rule to be

>   	received in the CoS queue*/

>   	pkt = create_packet(pkt_pool, false, &seq, false);

> +	CU_ASSERT_FATAL(pkt != ODP_PACKET_INVALID);

>   	eth = (odph_ethhdr_t *)odp_packet_l2_ptr(pkt, NULL);

>   	odp_pktio_mac_addr(pktio, eth->src.addr, ODPH_ETHADDR_LEN);

>   	odp_pktio_mac_addr(pktio, eth->dst.addr, ODPH_ETHADDR_LEN);

> @@ -1122,6 +1124,7 @@ static void classification_test_pmr_term_daddr(void)

>   

>   	/* Other packets delivered to default queue */

>   	pkt = create_packet(pkt_pool, false, &seq, false);

> +	CU_ASSERT_FATAL(pkt != ODP_PACKET_INVALID);

>   	seqno = cls_pkt_get_seq(pkt);

>   	CU_ASSERT(seqno != TEST_SEQ_INVALID);

>   	eth = (odph_ethhdr_t *)odp_packet_l2_ptr(pkt, NULL);
Nikhil Agarwal Dec. 13, 2016, 6:05 a.m. UTC | #2
Reviewed-by: Nikhil Agarwal <nikhil.agarwal@linaro.org>


Regards
Nikhil

-----Original Message-----
From: lng-odp [mailto:lng-odp-bounces@lists.linaro.org] On Behalf Of Balasubramanian Manoharan

Sent: Thursday, October 27, 2016 6:31 PM
To: lng-odp@lists.linaro.org
Subject: [lng-odp] [PATCHv2 1/1] validation: classification: fix TCP/UDP checksum update

Fixes https://bugs.linaro.org/show_bug.cgi?id=2512

Signed-off-by: Balasubramanian Manoharan <bala.manoharan@linaro.org>

---
v2: Incorporates review comments
 .../api/classification/odp_classification_common.c         | 14 +++++++++++++-
 .../api/classification/odp_classification_test_pmr.c       |  3 +++
 2 files changed, 16 insertions(+), 1 deletion(-)

diff --git a/test/common_plat/validation/api/classification/odp_classification_common.c b/test/common_plat/validation/api/classification/odp_classification_common.c
index 7a42ac7..2923a71 100644
--- a/test/common_plat/validation/api/classification/odp_classification_common.c
+++ b/test/common_plat/validation/api/classification/odp_classification_
+++ common.c
@@ -11,6 +11,7 @@
 #include <odp/helper/ip.h>
 #include <odp/helper/udp.h>
 #include <odp/helper/tcp.h>
+#include "test_debug.h"
 
 typedef struct cls_test_packet {
 	odp_u32be_t magic;
@@ -291,6 +292,8 @@ odp_packet_t create_packet_len(odp_pool_t pool, bool vlan,
 	parse_ipv4_string(CLS_DEFAULT_SADDR, &addr, &mask);
 	ip->src_addr = odp_cpu_to_be_32(addr);
 	ip->ver_ihl = ODPH_IPV4 << 4 | ODPH_IPV4HDR_IHL_MIN;
+	odp_packet_has_ipv4_set(pkt, 1);
+
 	if (flag_udp)
 		ip->tot_len = odp_cpu_to_be_16(ODPH_UDPHDR_LEN + payload_len +
 					       ODPH_IPV4HDR_LEN);
@@ -318,14 +321,23 @@ odp_packet_t create_packet_len(odp_pool_t pool, bool vlan,
 		udp->dst_port = odp_cpu_to_be_16(CLS_DEFAULT_DPORT);
 		udp->length = odp_cpu_to_be_16(payload_len + ODPH_UDPHDR_LEN);
 		udp->chksum = 0;
+		odp_packet_has_udp_set(pkt, 1);
+		if (odph_udp_tcp_chksum(pkt, ODPH_CHKSUM_GENERATE, NULL) != 0) {
+			LOG_ERR("odph_udp_tcp_chksum failed\n");
+			return ODP_PACKET_INVALID;
+		}
 	} else {
 		odp_packet_l4_offset_set(pkt, offset);
 		tcp = (odph_tcphdr_t *)odp_packet_l4_ptr(pkt, NULL);
 		tcp->src_port = odp_cpu_to_be_16(CLS_DEFAULT_SPORT);
 		tcp->dst_port = odp_cpu_to_be_16(CLS_DEFAULT_DPORT);
 		tcp->hl = ODPH_TCPHDR_LEN / 4;
-		/* TODO: checksum field has to be updated */
 		tcp->cksm = 0;
+		odp_packet_has_tcp_set(pkt, 1);
+		if (odph_udp_tcp_chksum(pkt, ODPH_CHKSUM_GENERATE, NULL) != 0) {
+			LOG_ERR("odph_udp_tcp_chksum failed\n");
+			return ODP_PACKET_INVALID;
+		}
 	}
 
 	/* set pkt sequence number */
diff --git a/test/common_plat/validation/api/classification/odp_classification_test_pmr.c b/test/common_plat/validation/api/classification/odp_classification_test_pmr.c
index c8bbf50..88fbf8f 100644
--- a/test/common_plat/validation/api/classification/odp_classification_test_pmr.c
+++ b/test/common_plat/validation/api/classification/odp_classification_
+++ test_pmr.c
@@ -717,6 +717,7 @@ void classification_test_pmr_term_dmac(void)
 
 	/* Other packets delivered to default queue */
 	pkt = create_packet(pkt_pool, false, &seq, false);
+	CU_ASSERT_FATAL(pkt != ODP_PACKET_INVALID);
 	eth = (odph_ethhdr_t *)odp_packet_l2_ptr(pkt, NULL);
 	memset(eth->dst.addr, 0, ODPH_ETHADDR_LEN);
 	CU_ASSERT_FATAL(pkt != ODP_PACKET_INVALID); @@ -1102,6 +1103,7 @@ static void classification_test_pmr_term_daddr(void)
 	/* packet with dst ip address matching PMR rule to be
 	received in the CoS queue*/
 	pkt = create_packet(pkt_pool, false, &seq, false);
+	CU_ASSERT_FATAL(pkt != ODP_PACKET_INVALID);
 	eth = (odph_ethhdr_t *)odp_packet_l2_ptr(pkt, NULL);
 	odp_pktio_mac_addr(pktio, eth->src.addr, ODPH_ETHADDR_LEN);
 	odp_pktio_mac_addr(pktio, eth->dst.addr, ODPH_ETHADDR_LEN); @@ -1122,6 +1124,7 @@ static void classification_test_pmr_term_daddr(void)
 
 	/* Other packets delivered to default queue */
 	pkt = create_packet(pkt_pool, false, &seq, false);
+	CU_ASSERT_FATAL(pkt != ODP_PACKET_INVALID);
 	seqno = cls_pkt_get_seq(pkt);
 	CU_ASSERT(seqno != TEST_SEQ_INVALID);
 	eth = (odph_ethhdr_t *)odp_packet_l2_ptr(pkt, NULL);
--
1.9.1
Maxim Uvarov Dec. 13, 2016, 2:48 p.m. UTC | #3
Merged,
Maxim.

On 12/13/16 09:05, Nikhil Agarwal wrote:
> Reviewed-by: Nikhil Agarwal <nikhil.agarwal@linaro.org>

> 

> Regards

> Nikhil

> 

> -----Original Message-----

> From: lng-odp [mailto:lng-odp-bounces@lists.linaro.org] On Behalf Of Balasubramanian Manoharan

> Sent: Thursday, October 27, 2016 6:31 PM

> To: lng-odp@lists.linaro.org

> Subject: [lng-odp] [PATCHv2 1/1] validation: classification: fix TCP/UDP checksum update

> 

> Fixes https://bugs.linaro.org/show_bug.cgi?id=2512

> 

> Signed-off-by: Balasubramanian Manoharan <bala.manoharan@linaro.org>

> ---

> v2: Incorporates review comments

>  .../api/classification/odp_classification_common.c         | 14 +++++++++++++-

>  .../api/classification/odp_classification_test_pmr.c       |  3 +++

>  2 files changed, 16 insertions(+), 1 deletion(-)

> 

> diff --git a/test/common_plat/validation/api/classification/odp_classification_common.c b/test/common_plat/validation/api/classification/odp_classification_common.c

> index 7a42ac7..2923a71 100644

> --- a/test/common_plat/validation/api/classification/odp_classification_common.c

> +++ b/test/common_plat/validation/api/classification/odp_classification_

> +++ common.c

> @@ -11,6 +11,7 @@

>  #include <odp/helper/ip.h>

>  #include <odp/helper/udp.h>

>  #include <odp/helper/tcp.h>

> +#include "test_debug.h"

>  

>  typedef struct cls_test_packet {

>  	odp_u32be_t magic;

> @@ -291,6 +292,8 @@ odp_packet_t create_packet_len(odp_pool_t pool, bool vlan,

>  	parse_ipv4_string(CLS_DEFAULT_SADDR, &addr, &mask);

>  	ip->src_addr = odp_cpu_to_be_32(addr);

>  	ip->ver_ihl = ODPH_IPV4 << 4 | ODPH_IPV4HDR_IHL_MIN;

> +	odp_packet_has_ipv4_set(pkt, 1);

> +

>  	if (flag_udp)

>  		ip->tot_len = odp_cpu_to_be_16(ODPH_UDPHDR_LEN + payload_len +

>  					       ODPH_IPV4HDR_LEN);

> @@ -318,14 +321,23 @@ odp_packet_t create_packet_len(odp_pool_t pool, bool vlan,

>  		udp->dst_port = odp_cpu_to_be_16(CLS_DEFAULT_DPORT);

>  		udp->length = odp_cpu_to_be_16(payload_len + ODPH_UDPHDR_LEN);

>  		udp->chksum = 0;

> +		odp_packet_has_udp_set(pkt, 1);

> +		if (odph_udp_tcp_chksum(pkt, ODPH_CHKSUM_GENERATE, NULL) != 0) {

> +			LOG_ERR("odph_udp_tcp_chksum failed\n");

> +			return ODP_PACKET_INVALID;

> +		}

>  	} else {

>  		odp_packet_l4_offset_set(pkt, offset);

>  		tcp = (odph_tcphdr_t *)odp_packet_l4_ptr(pkt, NULL);

>  		tcp->src_port = odp_cpu_to_be_16(CLS_DEFAULT_SPORT);

>  		tcp->dst_port = odp_cpu_to_be_16(CLS_DEFAULT_DPORT);

>  		tcp->hl = ODPH_TCPHDR_LEN / 4;

> -		/* TODO: checksum field has to be updated */

>  		tcp->cksm = 0;

> +		odp_packet_has_tcp_set(pkt, 1);

> +		if (odph_udp_tcp_chksum(pkt, ODPH_CHKSUM_GENERATE, NULL) != 0) {

> +			LOG_ERR("odph_udp_tcp_chksum failed\n");

> +			return ODP_PACKET_INVALID;

> +		}

>  	}

>  

>  	/* set pkt sequence number */

> diff --git a/test/common_plat/validation/api/classification/odp_classification_test_pmr.c b/test/common_plat/validation/api/classification/odp_classification_test_pmr.c

> index c8bbf50..88fbf8f 100644

> --- a/test/common_plat/validation/api/classification/odp_classification_test_pmr.c

> +++ b/test/common_plat/validation/api/classification/odp_classification_

> +++ test_pmr.c

> @@ -717,6 +717,7 @@ void classification_test_pmr_term_dmac(void)

>  

>  	/* Other packets delivered to default queue */

>  	pkt = create_packet(pkt_pool, false, &seq, false);

> +	CU_ASSERT_FATAL(pkt != ODP_PACKET_INVALID);

>  	eth = (odph_ethhdr_t *)odp_packet_l2_ptr(pkt, NULL);

>  	memset(eth->dst.addr, 0, ODPH_ETHADDR_LEN);

>  	CU_ASSERT_FATAL(pkt != ODP_PACKET_INVALID); @@ -1102,6 +1103,7 @@ static void classification_test_pmr_term_daddr(void)

>  	/* packet with dst ip address matching PMR rule to be

>  	received in the CoS queue*/

>  	pkt = create_packet(pkt_pool, false, &seq, false);

> +	CU_ASSERT_FATAL(pkt != ODP_PACKET_INVALID);

>  	eth = (odph_ethhdr_t *)odp_packet_l2_ptr(pkt, NULL);

>  	odp_pktio_mac_addr(pktio, eth->src.addr, ODPH_ETHADDR_LEN);

>  	odp_pktio_mac_addr(pktio, eth->dst.addr, ODPH_ETHADDR_LEN); @@ -1122,6 +1124,7 @@ static void classification_test_pmr_term_daddr(void)

>  

>  	/* Other packets delivered to default queue */

>  	pkt = create_packet(pkt_pool, false, &seq, false);

> +	CU_ASSERT_FATAL(pkt != ODP_PACKET_INVALID);

>  	seqno = cls_pkt_get_seq(pkt);

>  	CU_ASSERT(seqno != TEST_SEQ_INVALID);

>  	eth = (odph_ethhdr_t *)odp_packet_l2_ptr(pkt, NULL);

> --

> 1.9.1

>
diff mbox

Patch

diff --git a/test/common_plat/validation/api/classification/odp_classification_common.c b/test/common_plat/validation/api/classification/odp_classification_common.c
index 7a42ac7..2923a71 100644
--- a/test/common_plat/validation/api/classification/odp_classification_common.c
+++ b/test/common_plat/validation/api/classification/odp_classification_common.c
@@ -11,6 +11,7 @@ 
 #include <odp/helper/ip.h>
 #include <odp/helper/udp.h>
 #include <odp/helper/tcp.h>
+#include "test_debug.h"
 
 typedef struct cls_test_packet {
 	odp_u32be_t magic;
@@ -291,6 +292,8 @@  odp_packet_t create_packet_len(odp_pool_t pool, bool vlan,
 	parse_ipv4_string(CLS_DEFAULT_SADDR, &addr, &mask);
 	ip->src_addr = odp_cpu_to_be_32(addr);
 	ip->ver_ihl = ODPH_IPV4 << 4 | ODPH_IPV4HDR_IHL_MIN;
+	odp_packet_has_ipv4_set(pkt, 1);
+
 	if (flag_udp)
 		ip->tot_len = odp_cpu_to_be_16(ODPH_UDPHDR_LEN + payload_len +
 					       ODPH_IPV4HDR_LEN);
@@ -318,14 +321,23 @@  odp_packet_t create_packet_len(odp_pool_t pool, bool vlan,
 		udp->dst_port = odp_cpu_to_be_16(CLS_DEFAULT_DPORT);
 		udp->length = odp_cpu_to_be_16(payload_len + ODPH_UDPHDR_LEN);
 		udp->chksum = 0;
+		odp_packet_has_udp_set(pkt, 1);
+		if (odph_udp_tcp_chksum(pkt, ODPH_CHKSUM_GENERATE, NULL) != 0) {
+			LOG_ERR("odph_udp_tcp_chksum failed\n");
+			return ODP_PACKET_INVALID;
+		}
 	} else {
 		odp_packet_l4_offset_set(pkt, offset);
 		tcp = (odph_tcphdr_t *)odp_packet_l4_ptr(pkt, NULL);
 		tcp->src_port = odp_cpu_to_be_16(CLS_DEFAULT_SPORT);
 		tcp->dst_port = odp_cpu_to_be_16(CLS_DEFAULT_DPORT);
 		tcp->hl = ODPH_TCPHDR_LEN / 4;
-		/* TODO: checksum field has to be updated */
 		tcp->cksm = 0;
+		odp_packet_has_tcp_set(pkt, 1);
+		if (odph_udp_tcp_chksum(pkt, ODPH_CHKSUM_GENERATE, NULL) != 0) {
+			LOG_ERR("odph_udp_tcp_chksum failed\n");
+			return ODP_PACKET_INVALID;
+		}
 	}
 
 	/* set pkt sequence number */
diff --git a/test/common_plat/validation/api/classification/odp_classification_test_pmr.c b/test/common_plat/validation/api/classification/odp_classification_test_pmr.c
index c8bbf50..88fbf8f 100644
--- a/test/common_plat/validation/api/classification/odp_classification_test_pmr.c
+++ b/test/common_plat/validation/api/classification/odp_classification_test_pmr.c
@@ -717,6 +717,7 @@  void classification_test_pmr_term_dmac(void)
 
 	/* Other packets delivered to default queue */
 	pkt = create_packet(pkt_pool, false, &seq, false);
+	CU_ASSERT_FATAL(pkt != ODP_PACKET_INVALID);
 	eth = (odph_ethhdr_t *)odp_packet_l2_ptr(pkt, NULL);
 	memset(eth->dst.addr, 0, ODPH_ETHADDR_LEN);
 	CU_ASSERT_FATAL(pkt != ODP_PACKET_INVALID);
@@ -1102,6 +1103,7 @@  static void classification_test_pmr_term_daddr(void)
 	/* packet with dst ip address matching PMR rule to be
 	received in the CoS queue*/
 	pkt = create_packet(pkt_pool, false, &seq, false);
+	CU_ASSERT_FATAL(pkt != ODP_PACKET_INVALID);
 	eth = (odph_ethhdr_t *)odp_packet_l2_ptr(pkt, NULL);
 	odp_pktio_mac_addr(pktio, eth->src.addr, ODPH_ETHADDR_LEN);
 	odp_pktio_mac_addr(pktio, eth->dst.addr, ODPH_ETHADDR_LEN);
@@ -1122,6 +1124,7 @@  static void classification_test_pmr_term_daddr(void)
 
 	/* Other packets delivered to default queue */
 	pkt = create_packet(pkt_pool, false, &seq, false);
+	CU_ASSERT_FATAL(pkt != ODP_PACKET_INVALID);
 	seqno = cls_pkt_get_seq(pkt);
 	CU_ASSERT(seqno != TEST_SEQ_INVALID);
 	eth = (odph_ethhdr_t *)odp_packet_l2_ptr(pkt, NULL);