[lng-odp] [PATCH] example:ipsec: Tunnel mode fixes

2016-01-12 Thread ion.grigore
From: Grigore Ion 

This patch fixes the following issues:
1. ETYPE field in the ETH header is not updated using the
BE byte order (PKT_STATE_IPSEC_IN_FINISH status).
2. IP addresses, from the packet, are not converted to
the CPU endianness, when the inbound policy is checked
(PKT_STATE_IPSEC_IN_FINISH status).
3. Identification field is not set in the outer IP header
when an IN packet is generated.
4. Total Length field is not set in the inner IP header
when an IN packet is generated.

Signed-off-by: Grigore Ion 
---
Note : The fix for the second issue was also proposed by Akhil
Goyal on Nov. 20, 2015 and by Stuart Haslam on Jan. 06, 2016

 example/ipsec/odp_ipsec.c|  6 +++---
 example/ipsec/odp_ipsec_cache.c  | 20 +---
 example/ipsec/odp_ipsec_stream.c | 11 +--
 3 files changed, 21 insertions(+), 16 deletions(-)

diff --git a/example/ipsec/odp_ipsec.c b/example/ipsec/odp_ipsec.c
index fab1035..bdbe1a1 100644
--- a/example/ipsec/odp_ipsec.c
+++ b/example/ipsec/odp_ipsec.c
@@ -767,12 +767,12 @@ pkt_disposition_e do_ipsec_in_finish(odp_packet_t pkt,
odph_ethhdr_t *eth;
 
eth = (odph_ethhdr_t *)odp_packet_l2_ptr(pkt, NULL);
-   eth->type = ODPH_ETHTYPE_IPV4;
+   eth->type = odp_cpu_to_be_16(ODPH_ETHTYPE_IPV4);
ip = (odph_ipv4hdr_t *)odp_packet_l3_ptr(pkt, NULL);
 
/* Check inbound policy */
-   if ((ip->src_addr != ctx->ipsec.src_ip ||
-ip->dst_addr != ctx->ipsec.dst_ip))
+   if (odp_be_to_cpu_32(ip->src_addr) != ctx->ipsec.src_ip ||
+   odp_be_to_cpu_32(ip->dst_addr) != ctx->ipsec.dst_ip)
return PKT_DROP;
 
return PKT_CONTINUE;
diff --git a/example/ipsec/odp_ipsec_cache.c b/example/ipsec/odp_ipsec_cache.c
index 0883d4d..23b0762 100644
--- a/example/ipsec/odp_ipsec_cache.c
+++ b/example/ipsec/odp_ipsec_cache.c
@@ -138,21 +138,19 @@ int create_ipsec_cache_entry(sa_db_entry_t *cipher_sa,
}
 
if (tun) {
+   int ret;
+
entry->tun_src_ip = tun->tun_src_ip;
entry->tun_dst_ip = tun->tun_dst_ip;
mode = IPSEC_SA_MODE_TUNNEL;
 
-   int ret;
-
-   if (!in) {
-   /* init tun hdr id */
-   ret = odp_random_data((uint8_t *)
- >state.tun_hdr_id,
- sizeof(entry->state.tun_hdr_id),
- 1);
-   if (ret != sizeof(entry->state.tun_hdr_id))
-   return -1;
-   }
+   /* init tun hdr id */
+   ret = odp_random_data((uint8_t *)
+ >state.tun_hdr_id,
+ sizeof(entry->state.tun_hdr_id),
+ 1);
+   if (ret != sizeof(entry->state.tun_hdr_id))
+   return -1;
}
entry->mode = mode;
 
diff --git a/example/ipsec/odp_ipsec_stream.c b/example/ipsec/odp_ipsec_stream.c
index f750e18..9422b71 100644
--- a/example/ipsec/odp_ipsec_stream.c
+++ b/example/ipsec/odp_ipsec_stream.c
@@ -211,17 +211,21 @@ odp_packet_t create_ipv4_packet(stream_db_entry_t *stream,
/* Wait until almost finished to fill in mutable fields */
memset((char *)ip, 0, sizeof(*ip));
ip->ver_ihl = 0x45;
-   ip->id = odp_cpu_to_be_16(stream->id);
-   /* Outer IP header in tunnel mode */
if (entry && entry->mode == IPSEC_SA_MODE_TUNNEL &&
(entry == stream->input.entry)) {
+   /* Outer IP header in tunnel mode */
ip->proto = ODPH_IPV4;
ip->src_addr = odp_cpu_to_be_32(entry->tun_src_ip);
ip->dst_addr = odp_cpu_to_be_32(entry->tun_dst_ip);
+   /* New ID is generated for each outer IP header. */
+   if (!entry->state.tun_hdr_id)
+   entry->state.tun_hdr_id++;
+   ip->id = odp_cpu_to_be_16(entry->state.tun_hdr_id++);
} else {
ip->proto = ODPH_IPPROTO_ICMP;
ip->src_addr = odp_cpu_to_be_32(stream->src_ip);
ip->dst_addr = odp_cpu_to_be_32(stream->dst_ip);
+   ip->id = odp_cpu_to_be_16(stream->id);
}
 
/* AH (if specified) */
@@ -269,6 +273,9 @@ odp_packet_t create_ipv4_packet(stream_db_entry_t *stream,
inner_ip->frag_offset = 0;
inner_ip->src_addr = odp_cpu_to_be_32(stream->src_ip);
inner_ip->dst_addr = odp_cpu_to_be_32(stream->dst_ip);
+   inner_ip->tot_len = odp_cpu_to_be_16(sizeof(odph_ipv4hdr_t) +
+   sizeof(odph_icmphdr_t) + sizeof(stream_pkt_hdr_t) +
+   stream->length);
   

[lng-odp] [PATCHv9] helper : Fix UDP checksum computation

2016-01-11 Thread ion.grigore
From: Grigore Ion 

This patch fixes the following problems:
- checksum computation for LE platforms
- checksum computation for packets having the UDP length not a
multiple of 2
- checksum computation in the test and the example applications

Signed-off-by: Grigore Ion 
---
v9:
- Fix comments (Ilya Maximets)
v8:
- Checksum in BE endianness (Ilya Maximets)
v7:
- Make code simpler and more understandable as it was
sugessted by Ilya Maximets
v6:
- Make code more understandable. Not done as it was
sugessted by Ilya Maximets.
v5:
- Checksum in CPU endianness fix added (Ilya Maximets)
v4:
- Verify checksum in CPU endianness in the associated test
(Ilya Maximets)
v3:
- fix the UDP checksum computation in the associated test
(Maxim Uvarov)
v2:
- patch updated to the last master (Maxim Uvarov)
v1:
- Move variables declaration on top of block. (Maxim Uvarov)
- Check patch with checkpatch script.  (Maxim Uvarov)
- L3 header presence is tested twice. (Alexandru Badicioiu)
- Remove unnecessary check for L3 header presence. (Bill Fischofer)

 example/generator/odp_generator.c |  2 +-
 helper/include/odp/helper/udp.h   | 66 ---
 helper/test/odp_chksum.c  |  4 +--
 test/validation/pktio/pktio.c |  2 +-
 4 files changed, 38 insertions(+), 36 deletions(-)

diff --git a/example/generator/odp_generator.c 
b/example/generator/odp_generator.c
index cdbc761..757dc54 100644
--- a/example/generator/odp_generator.c
+++ b/example/generator/odp_generator.c
@@ -242,7 +242,7 @@ static odp_packet_t pack_udp_pkt(odp_pool_t pool)
udp->dst_port = 0;
udp->length = odp_cpu_to_be_16(args->appl.payload + ODPH_UDPHDR_LEN);
udp->chksum = 0;
-   udp->chksum = odp_cpu_to_be_16(odph_ipv4_udp_chksum(pkt));
+   udp->chksum = odph_ipv4_udp_chksum(pkt);
 
return pkt;
 }
diff --git a/helper/include/odp/helper/udp.h b/helper/include/odp/helper/udp.h
index 06c439b..93b342d 100644
--- a/helper/include/odp/helper/udp.h
+++ b/helper/include/odp/helper/udp.h
@@ -4,7 +4,6 @@
  * SPDX-License-Identifier: BSD-3-Clause
  */
 
-
 /**
  * @file
  *
@@ -22,7 +21,6 @@ extern "C" {
 #include 
 #include 
 
-
 /** @addtogroup odph_header ODPH HEADER
  *  @{
  */
@@ -44,46 +42,50 @@ typedef struct ODP_PACKED {
  * This function uses odp packet to calc checksum
  *
  * @param pkt  calculate chksum for pkt
- * @return  checksum value
+ * @return  checksum value in BE endianness
  */
 static inline uint16_t odph_ipv4_udp_chksum(odp_packet_t pkt)
 {
-   uint32_t sum = 0;
-   odph_udphdr_t *udph;
-   odph_ipv4hdr_t *iph;
-   uint16_t udplen;
-   uint8_t *buf;
-
-   if (!odp_packet_l3_offset(pkt))
+   odph_ipv4hdr_t  *iph;
+   odph_udphdr_t   *udph;
+   uint32_tsum;
+   uint16_tudplen, *buf;
+   union {
+   uint8_t v8[2];
+   uint16_t v16;
+   } val;
+
+   if (odp_packet_l4_offset(pkt) == ODP_PACKET_OFFSET_INVALID)
return 0;
-
-   if (!odp_packet_l4_offset(pkt))
-   return 0;
-
iph = (odph_ipv4hdr_t *)odp_packet_l3_ptr(pkt, NULL);
udph = (odph_udphdr_t *)odp_packet_l4_ptr(pkt, NULL);
-   udplen = odp_be_to_cpu_16(udph->length);
-
-   /* 32-bit sum of all 16-bit words covered by UDP chksum */
+   /* 32-bit sum of UDP pseudo-header, seen as a series of 16-bit words */
sum = (iph->src_addr & 0x) + (iph->src_addr >> 16) +
- (iph->dst_addr & 0x) + (iph->dst_addr >> 16) +
- (uint16_t)iph->proto + udplen;
-   for (buf = (uint8_t *)udph; udplen > 1; udplen -= 2) {
-   sum += ((*buf << 8) + *(buf + 1));
-   buf += 2;
+   (iph->dst_addr & 0x) + (iph->dst_addr >> 16) +
+   udph->length;
+   val.v8[0] = 0;
+   val.v8[1] = iph->proto;
+   sum += val.v16;
+   /* 32-bit sum of UDP header (checksum field cleared) and UDP data, seen
+* as a series of 16-bit words */
+   udplen = odp_be_to_cpu_16(udph->length);
+   buf = (uint16_t *)((void *)udph);
+   for ( ; udplen > 1; udplen -= 2)
+   sum += *buf++;
+   /* Length is not a multiple of 2 bytes */
+   if (udplen) {
+   val.v8[0] = *buf;
+   val.v8[1] = 0;
+   sum += val.v16;
}
-
-   /* Fold sum to 16 bits: add carrier to result */
-   while (sum >> 16)
-   sum = (sum & 0x) + (sum >> 16);
-
+   /* Fold sum to 16 bits */
+   sum = (sum & 0x) + (sum >> 16);
+   /* Add carrier (0/1) to result */
+   sum += (sum >> 16);
/* 1's complement */
sum = ~sum;
-
-   /* set computation result */
-   sum = (sum == 0x0) ? 0x : sum;
-
-   return sum;
+   /* Return checksum in BE endianness */
+   return (sum == 0x0) ? 0x : sum;
 }
 
 /** @internal Compile time assert */

[lng-odp] [PATCHv8] helper : Fix UDP checksum computation

2016-01-04 Thread ion.grigore
From: Grigore Ion 

This patch fixes the following problems:
- checksum computation for LE platforms
- checksum computation for packets having the UDP length not a
multiple of 2
- checksum computation in the test and the example applications

Signed-off-by: Grigore Ion 
---
v8:
- Checksum in BE endianness (Ilya Maximets)
v7:
- Make code simpler and more understandable as it was
sugessted by Ilya Maximets
v6:
- Make code more understandable. Not done as it was
sugessted by Ilya Maximets.
v5:
- Checksum in CPU endianness fix added (Ilya Maximets)
v4:
- Verify checksum in CPU endianness in the associated test
(Ilya Maximets)
v3:
- fix the UDP checksum computation in the associated test
(Maxim Uvarov)
v2:
- patch updated to the last master (Maxim Uvarov)
v1:
- Move variables declaration on top of block. (Maxim Uvarov)
- Check patch with checkpatch script.  (Maxim Uvarov)
- L3 header presence is tested twice. (Alexandru Badicioiu)
- Remove unnecessary check for L3 header presence. (Bill Fischofer)

 example/generator/odp_generator.c |  2 +-
 helper/include/odp/helper/udp.h   | 65 ---
 helper/test/odp_chksum.c  |  4 +--
 test/validation/pktio/pktio.c |  2 +-
 4 files changed, 37 insertions(+), 36 deletions(-)

diff --git a/example/generator/odp_generator.c 
b/example/generator/odp_generator.c
index cdbc761..757dc54 100644
--- a/example/generator/odp_generator.c
+++ b/example/generator/odp_generator.c
@@ -242,7 +242,7 @@ static odp_packet_t pack_udp_pkt(odp_pool_t pool)
udp->dst_port = 0;
udp->length = odp_cpu_to_be_16(args->appl.payload + ODPH_UDPHDR_LEN);
udp->chksum = 0;
-   udp->chksum = odp_cpu_to_be_16(odph_ipv4_udp_chksum(pkt));
+   udp->chksum = odph_ipv4_udp_chksum(pkt);
 
return pkt;
 }
diff --git a/helper/include/odp/helper/udp.h b/helper/include/odp/helper/udp.h
index 06c439b..afdb4fc 100644
--- a/helper/include/odp/helper/udp.h
+++ b/helper/include/odp/helper/udp.h
@@ -4,7 +4,6 @@
  * SPDX-License-Identifier: BSD-3-Clause
  */
 
-
 /**
  * @file
  *
@@ -22,7 +21,6 @@ extern "C" {
 #include 
 #include 
 
-
 /** @addtogroup odph_header ODPH HEADER
  *  @{
  */
@@ -44,46 +42,49 @@ typedef struct ODP_PACKED {
  * This function uses odp packet to calc checksum
  *
  * @param pkt  calculate chksum for pkt
- * @return  checksum value
+ * @return  checksum value in BE endianness
  */
 static inline uint16_t odph_ipv4_udp_chksum(odp_packet_t pkt)
 {
-   uint32_t sum = 0;
-   odph_udphdr_t *udph;
-   odph_ipv4hdr_t *iph;
-   uint16_t udplen;
-   uint8_t *buf;
-
-   if (!odp_packet_l3_offset(pkt))
+   odph_ipv4hdr_t  *iph;
+   odph_udphdr_t   *udph;
+   uint32_tsum;
+   uint16_tudplen, *buf;
+   union {
+   uint8_t v8[2];
+   uint16_t v16;
+   } val;
+
+   if (odp_packet_l4_offset(pkt) == ODP_PACKET_OFFSET_INVALID)
return 0;
-
-   if (!odp_packet_l4_offset(pkt))
-   return 0;
-
iph = (odph_ipv4hdr_t *)odp_packet_l3_ptr(pkt, NULL);
udph = (odph_udphdr_t *)odp_packet_l4_ptr(pkt, NULL);
-   udplen = odp_be_to_cpu_16(udph->length);
-
-   /* 32-bit sum of all 16-bit words covered by UDP chksum */
+   /* 32-bit sum of UDP pseudo-header */
sum = (iph->src_addr & 0x) + (iph->src_addr >> 16) +
- (iph->dst_addr & 0x) + (iph->dst_addr >> 16) +
- (uint16_t)iph->proto + udplen;
-   for (buf = (uint8_t *)udph; udplen > 1; udplen -= 2) {
-   sum += ((*buf << 8) + *(buf + 1));
-   buf += 2;
+   (iph->dst_addr & 0x) + (iph->dst_addr >> 16) +
+   udph->length;
+   val.v8[0] = 0;
+   val.v8[1] = iph->proto;
+   sum += val.v16;
+   /* 32-bit sum of UDP header (checksum field cleared) and UDP data */
+   udplen = odp_be_to_cpu_16(udph->length);
+   buf = (uint16_t *)((void *)udph);
+   for ( ; udplen > 1; udplen -= 2)
+   sum += *buf++;
+   /* Length is not a multiple of 2 bytes */
+   if (udplen) {
+   val.v8[0] = *buf;
+   val.v8[1] = 0;
+   sum += val.v16;
}
-
-   /* Fold sum to 16 bits: add carrier to result */
-   while (sum >> 16)
-   sum = (sum & 0x) + (sum >> 16);
-
+   /* Fold sum to 16 bits */
+   sum = (sum & 0x) + (sum >> 16);
+   /* Add carrier (0/1) to result */
+   sum += (sum >> 16);
/* 1's complement */
sum = ~sum;
-
-   /* set computation result */
-   sum = (sum == 0x0) ? 0x : sum;
-
-   return sum;
+   /* Return checksum in BE endianness */
+   return (sum == 0x0) ? 0x : sum;
 }
 
 /** @internal Compile time assert */
diff --git a/helper/test/odp_chksum.c b/helper/test/odp_chksum.c
index 1d417a8..b71fabc 100644
--- 

[lng-odp] [PATCHv7] helper : Fix UDP checksum computation

2015-12-14 Thread ion.grigore
From: Grigore Ion 

This patch fixes the following problems:
- checksum computation for LE platforms
- checksum is computed in the CPU endianness. The returned result
must be converted to the BE ordering when it is used to update
the UDP checksum in a packet.
- checksum computation for packets having the UDP length not a
multiple of 2
- fixes the UDP checksum associated validation test

Signed-off-by: Grigore Ion 
---
 v7:
 - Make code simpler and more understandable as it was
 sugessted by Ilya Maximets
 v6:
 - Make code more understandable. Not done as it was
 sugessted by Ilya Maximets.
 v5:
 - Checksum in CPU endianness fix added (Ilya Maximets)
 v4:
 - Verify checksum in CPU endianness in the associated test
 (Ilya Maximets)
 v3:
 - fix the UDP checksum computation in the associated test
 (Maxim Uvarov)
 v2:
 - patch updated to the last master (Maxim Uvarov)
 v1:
 - Move variables declaration on top of block. (Maxim Uvarov)
 - Check patch with checkpatch script.  (Maxim Uvarov)
 - L3 header presence is tested twice. (Alexandru Badicioiu)
 - Remove unnecessary check for L3 header presence. (Bill Fischofer)
 - Modify check of odp_packet_l4_offset() return. (Bill Fischofer)

 helper/include/odp/helper/udp.h | 65 +
 helper/test/odp_chksum.c|  4 +--
 2 files changed, 35 insertions(+), 34 deletions(-)

diff --git a/helper/include/odp/helper/udp.h b/helper/include/odp/helper/udp.h
index 06c439b..f43fa54 100644
--- a/helper/include/odp/helper/udp.h
+++ b/helper/include/odp/helper/udp.h
@@ -4,7 +4,6 @@
  * SPDX-License-Identifier: BSD-3-Clause
  */
 
-
 /**
  * @file
  *
@@ -22,7 +21,6 @@ extern "C" {
 #include 
 #include 
 
-
 /** @addtogroup odph_header ODPH HEADER
  *  @{
  */
@@ -44,46 +42,49 @@ typedef struct ODP_PACKED {
  * This function uses odp packet to calc checksum
  *
  * @param pkt  calculate chksum for pkt
- * @return  checksum value
+ * @return  checksum value in CPU endianness
  */
 static inline uint16_t odph_ipv4_udp_chksum(odp_packet_t pkt)
 {
-   uint32_t sum = 0;
-   odph_udphdr_t *udph;
-   odph_ipv4hdr_t *iph;
-   uint16_t udplen;
-   uint8_t *buf;
-
-   if (!odp_packet_l3_offset(pkt))
+   odph_ipv4hdr_t  *iph;
+   odph_udphdr_t   *udph;
+   uint32_tsum;
+   uint16_tudplen, *buf;
+   union {
+   uint8_t v8[2];
+   uint16_t v16;
+   } val;
+
+   if (odp_packet_l4_offset(pkt) == ODP_PACKET_OFFSET_INVALID)
return 0;
-
-   if (!odp_packet_l4_offset(pkt))
-   return 0;
-
iph = (odph_ipv4hdr_t *)odp_packet_l3_ptr(pkt, NULL);
udph = (odph_udphdr_t *)odp_packet_l4_ptr(pkt, NULL);
-   udplen = odp_be_to_cpu_16(udph->length);
-
-   /* 32-bit sum of all 16-bit words covered by UDP chksum */
+   /* 32-bit sum of UDP pseudo-header */
sum = (iph->src_addr & 0x) + (iph->src_addr >> 16) +
- (iph->dst_addr & 0x) + (iph->dst_addr >> 16) +
- (uint16_t)iph->proto + udplen;
-   for (buf = (uint8_t *)udph; udplen > 1; udplen -= 2) {
-   sum += ((*buf << 8) + *(buf + 1));
-   buf += 2;
+   (iph->dst_addr & 0x) + (iph->dst_addr >> 16) +
+   udph->length;
+   val.v8[0] = 0;
+   val.v8[1] = iph->proto;
+   sum += val.v16;
+   /* 32-bit sum of UDP header (checksum field cleared) and UDP data */
+   udplen = odp_be_to_cpu_16(udph->length);
+   buf = (uint16_t *)((void *)udph);
+   for ( ; udplen > 1; udplen -= 2)
+   sum += *buf++;
+   /* Length is not a multiple of 2 bytes */
+   if (udplen) {
+   val.v8[0] = *buf;
+   val.v8[1] = 0;
+   sum += val.v16;
}
-
-   /* Fold sum to 16 bits: add carrier to result */
-   while (sum >> 16)
-   sum = (sum & 0x) + (sum >> 16);
-
+   /* Fold sum to 16 bits */
+   sum = (sum & 0x) + (sum >> 16);
+   /* Add carrier (0/1) to result */
+   sum += (sum >> 16);
/* 1's complement */
sum = ~sum;
-
-   /* set computation result */
-   sum = (sum == 0x0) ? 0x : sum;
-
-   return sum;
+   /* Return checksum in CPU endianness */
+   return (sum == 0x0) ? 0x : odp_be_to_cpu_16(sum);
 }
 
 /** @internal Compile time assert */
diff --git a/helper/test/odp_chksum.c b/helper/test/odp_chksum.c
index 1d417a8..152018a 100644
--- a/helper/test/odp_chksum.c
+++ b/helper/test/odp_chksum.c
@@ -189,14 +189,14 @@ int main(int argc TEST_UNUSED, char *argv[] TEST_UNUSED)
udp->dst_port = 0;
udp->length = odp_cpu_to_be_16(udat_size + ODPH_UDPHDR_LEN);
udp->chksum = 0;
-   udp->chksum = odph_ipv4_udp_chksum(test_packet);
+   udp->chksum = odp_cpu_to_be_16(odph_ipv4_udp_chksum(test_packet));
 
if (udp->chksum == 0)

[lng-odp] [PATCHv6] helper : Fix UDP checksum computation

2015-12-10 Thread ion.grigore
From: Grigore Ion 

This patch fixes the following problems:
- checksum computation for LE platforms
- checksum is computed in the CPU endianness. The returned result
must be converted to the BE ordering when it is used to update
the UDP checksum in a packet.
- checksum computation for packets having the UDP length not a
multiple of 2
- fixes the UDP checksum associated validation test

Signed-off-by: Grigore Ion 
---
 v6:
 - Make code more understandable (Ilya Maximets)
 v5:
 - Checksum in CPU endianness fix added (Ilya Maximets)
 v4:
 - Verify checksum in CPU endianness in the associated test
 (Ilya Maximets)
 v3:
 - fix the UDP checksum computation in the associated test
 (Maxim Uvarov)
 v2:
 - patch updated to the last master (Maxim Uvarov)
 v1:
 - Move variables declaration on top of block. (Maxim Uvarov)
 - Check patch with checkpatch script.  (Maxim Uvarov)
 - L3 header presence is tested twice. (Alexandru Badicioiu)
 - Remove unnecessary check for L3 header presence. (Bill Fischofer)
 - Modify check of odp_packet_l4_offset() return. (Bill Fischofer)

 helper/include/odp/helper/udp.h | 81 +
 helper/test/odp_chksum.c|  4 +-
 2 files changed, 51 insertions(+), 34 deletions(-)

diff --git a/helper/include/odp/helper/udp.h b/helper/include/odp/helper/udp.h
index 06c439b..d0599b1 100644
--- a/helper/include/odp/helper/udp.h
+++ b/helper/include/odp/helper/udp.h
@@ -4,7 +4,6 @@
  * SPDX-License-Identifier: BSD-3-Clause
  */
 
-
 /**
  * @file
  *
@@ -22,7 +21,6 @@ extern "C" {
 #include 
 #include 
 
-
 /** @addtogroup odph_header ODPH HEADER
  *  @{
  */
@@ -39,51 +37,70 @@ typedef struct ODP_PACKED {
 } odph_udphdr_t;
 
 /**
+ * Perform byte swap required by UDP checksum computation algorithm
+ */
+static inline uint16_t csum_bswap(uint16_t val)
+{
+#if ODP_BYTE_ORDER == ODP_LITTLE_ENDIAN
+   val = __odp_builtin_bswap16((__odp_force uint16_t)val);
+#endif
+   return val;
+}
+
+/**
+ * Pad a byte value to the left or to the right as required by UDP checksum
+ * computation algorithm and convert the result to CPU native uint16_t.
+ * Left padding is performed for the IP protocol field in the UDP
+ * pseudo-header (RFC 768). Right padding is performed in the case of the odd
+ * byte in a UDP packet having the length not a 2 multiple.
+ */
+static inline uint16_t u8_pad_to_u16(uint8_t val, odp_bool_t left)
+{
+   uint16_tret;
+
+   ret = (left) ? val : val << 8;
+   return csum_bswap(ret);
+}
+
+/**
  * UDP checksum
  *
  * This function uses odp packet to calc checksum
  *
  * @param pkt  calculate chksum for pkt
- * @return  checksum value
+ * @return  checksum value in CPU endianness
  */
 static inline uint16_t odph_ipv4_udp_chksum(odp_packet_t pkt)
 {
-   uint32_t sum = 0;
-   odph_udphdr_t *udph;
-   odph_ipv4hdr_t *iph;
-   uint16_t udplen;
-   uint8_t *buf;
-
-   if (!odp_packet_l3_offset(pkt))
-   return 0;
+   odph_ipv4hdr_t  *iph;
+   odph_udphdr_t   *udph;
+   uint32_tsum;
+   uint16_tudplen, *buf;
 
-   if (!odp_packet_l4_offset(pkt))
+   if (odp_packet_l4_offset(pkt) == ODP_PACKET_OFFSET_INVALID)
return 0;
-
iph = (odph_ipv4hdr_t *)odp_packet_l3_ptr(pkt, NULL);
udph = (odph_udphdr_t *)odp_packet_l4_ptr(pkt, NULL);
-   udplen = odp_be_to_cpu_16(udph->length);
-
-   /* 32-bit sum of all 16-bit words covered by UDP chksum */
+   /* 32-bit sum of UDP pseudo-header */
sum = (iph->src_addr & 0x) + (iph->src_addr >> 16) +
- (iph->dst_addr & 0x) + (iph->dst_addr >> 16) +
- (uint16_t)iph->proto + udplen;
-   for (buf = (uint8_t *)udph; udplen > 1; udplen -= 2) {
-   sum += ((*buf << 8) + *(buf + 1));
-   buf += 2;
-   }
-
-   /* Fold sum to 16 bits: add carrier to result */
-   while (sum >> 16)
-   sum = (sum & 0x) + (sum >> 16);
-
+   (iph->dst_addr & 0x) + (iph->dst_addr >> 16) +
+   u8_pad_to_u16(iph->proto, 1) + udph->length;
+   udplen = odp_be_to_cpu_16(udph->length);
+   buf = (uint16_t *)((void *)udph);
+   /* 32-bit sum of UDP header (checksum field cleared) and UDP data */
+   for ( ; udplen > 1; udplen -= 2)
+   sum += *buf++;
+   /* Length is not a multiple of 2 bytes */
+   if (udplen)
+   sum += u8_pad_to_u16(*buf, 0);
+   /* Fold sum to 16 bits */
+   sum = (sum & 0x) + (sum >> 16);
+   /* Add carrier (0/1) to result */
+   sum += (sum >> 16);
/* 1's complement */
sum = ~sum;
-
-   /* set computation result */
-   sum = (sum == 0x0) ? 0x : sum;
-
-   return sum;
+   /* Set computation result in CPU endianness */
+   return (sum == 0x0) ? 0x : csum_bswap(sum);
 }
 
 /** @internal Compile 

[lng-odp] [PATCHv5] helper : Fix UDP checksum computation

2015-12-09 Thread ion.grigore
From: Grigore Ion 

This patch fixes the following problems:
- checksum computation for LE platforms
- checksum is computed in the CPU endianness. The returned result
must be converted to the BE ordering when it is used to update
the UDP checksum in a packet.
- checksum computation for packets having the UDP length not a
multiple of 2
- fixes the UDP checksum associated validation test

Signed-off-by: Grigore Ion 
---
v5:
- Checksum in CPU endianness fix added (Ilya Maximets)
v4:
- Verify checksum in CPU endianness in the associated test
(Ilya Maximets)
v3:
- fix the UDP checksum computation in the associated test
(Maxim Uvarov)
v2:
- patch updated to the last master (Maxim Uvarov)
v1:
- Move variables declaration on top of block. (Maxim Uvarov)
- Check patch with checkpatch script.  (Maxim Uvarov)
- L3 header presence is tested twice. (Alexandru Badicioiu)
- Remove unnecessary check for L3 header presence. (Bill Fischofer)
- Modify check of odp_packet_l4_offset() return. (Bill Fischofer)

 helper/include/odp/helper/udp.h | 55 +
 helper/test/odp_chksum.c|  4 +--
 2 files changed, 25 insertions(+), 34 deletions(-)

diff --git a/helper/include/odp/helper/udp.h b/helper/include/odp/helper/udp.h
index 06c439b..9e7256d 100644
--- a/helper/include/odp/helper/udp.h
+++ b/helper/include/odp/helper/udp.h
@@ -4,7 +4,6 @@
  * SPDX-License-Identifier: BSD-3-Clause
  */
 
-
 /**
  * @file
  *
@@ -22,7 +21,6 @@ extern "C" {
 #include 
 #include 
 
-
 /** @addtogroup odph_header ODPH HEADER
  *  @{
  */
@@ -44,46 +42,39 @@ typedef struct ODP_PACKED {
  * This function uses odp packet to calc checksum
  *
  * @param pkt  calculate chksum for pkt
- * @return  checksum value
+ * @return  checksum value in CPU endianness
  */
 static inline uint16_t odph_ipv4_udp_chksum(odp_packet_t pkt)
 {
-   uint32_t sum = 0;
-   odph_udphdr_t *udph;
-   odph_ipv4hdr_t *iph;
-   uint16_t udplen;
-   uint8_t *buf;
-
-   if (!odp_packet_l3_offset(pkt))
-   return 0;
+   odph_ipv4hdr_t  *iph;
+   odph_udphdr_t   *udph;
+   uint32_tsum;
+   uint16_tudplen, *buf;
 
-   if (!odp_packet_l4_offset(pkt))
+   if (odp_packet_l4_offset(pkt) == ODP_PACKET_OFFSET_INVALID)
return 0;
-
iph = (odph_ipv4hdr_t *)odp_packet_l3_ptr(pkt, NULL);
udph = (odph_udphdr_t *)odp_packet_l4_ptr(pkt, NULL);
-   udplen = odp_be_to_cpu_16(udph->length);
-
-   /* 32-bit sum of all 16-bit words covered by UDP chksum */
+   /* 32-bit sum of UDP pseudo-header */
sum = (iph->src_addr & 0x) + (iph->src_addr >> 16) +
- (iph->dst_addr & 0x) + (iph->dst_addr >> 16) +
- (uint16_t)iph->proto + udplen;
-   for (buf = (uint8_t *)udph; udplen > 1; udplen -= 2) {
-   sum += ((*buf << 8) + *(buf + 1));
-   buf += 2;
-   }
-
-   /* Fold sum to 16 bits: add carrier to result */
-   while (sum >> 16)
-   sum = (sum & 0x) + (sum >> 16);
-
+   (iph->dst_addr & 0x) + (iph->dst_addr >> 16) +
+   odp_be_to_cpu_16(iph->proto) + udph->length;
+   udplen = odp_be_to_cpu_16(udph->length);
+   buf = (uint16_t *)((void *)udph);
+   /* 32-bit sum of UDP header (checksum field cleared) and UDP data */
+   for ( ; udplen > 1; udplen -= 2)
+   sum += *buf++;
+   /* Length is not a multiple of 2 bytes */
+   if (udplen)
+   sum += odp_be_to_cpu_16(*((uint8_t *)buf) << 8);
+   /* Fold sum to 16 bits */
+   sum = (sum & 0x) + (sum >> 16);
+   /* Add carrier (0/1) to result */
+   sum += (sum >> 16);
/* 1's complement */
sum = ~sum;
-
-   /* set computation result */
-   sum = (sum == 0x0) ? 0x : sum;
-
-   return sum;
+   /* Set computation result in CPU endianness */
+   return (sum == 0x0) ? 0x : odp_be_to_cpu_16(sum);
 }
 
 /** @internal Compile time assert */
diff --git a/helper/test/odp_chksum.c b/helper/test/odp_chksum.c
index 1d417a8..152018a 100644
--- a/helper/test/odp_chksum.c
+++ b/helper/test/odp_chksum.c
@@ -189,14 +189,14 @@ int main(int argc TEST_UNUSED, char *argv[] TEST_UNUSED)
udp->dst_port = 0;
udp->length = odp_cpu_to_be_16(udat_size + ODPH_UDPHDR_LEN);
udp->chksum = 0;
-   udp->chksum = odph_ipv4_udp_chksum(test_packet);
+   udp->chksum = odp_cpu_to_be_16(odph_ipv4_udp_chksum(test_packet));
 
if (udp->chksum == 0)
return -1;
 
printf("chksum = 0x%x\n", udp->chksum);
 
-   if (udp->chksum != 0xab2d)
+   if (odp_be_to_cpu_16(udp->chksum) != 0x7e5a)
status = -1;
 
odp_packet_free(test_packet);
-- 
1.9.3

___
lng-odp mailing list
lng-odp@lists.linaro.org

[lng-odp] [PATCHv4] helper : Fix UDP checksum computation

2015-12-08 Thread ion.grigore
From: Grigore Ion 

This patch fixes the following problems:
- checksum computation for LE platforms
- checksum is computed in the CPU endianness. The returned result
must be converted to the BE ordering when it is used to update
the UDP checksum in a packet.
- checksum computation for packets having the UDP length not a
multiple of 2
- fixes the UDP checksum associated validation test

Signed-off-by: Grigore Ion 
---
v4:
- Verify checksum in CPU endianness in the associated test
(Ilya Maximets)
v3:
- fix the UDP checksum computation in the associated test
(Maxim Uvarov)
v2:
- patch updated to the last master (Maxim Uvarov)
v1:
- Move variables declaration on top of block. (Maxim Uvarov)
- Check patch with checkpatch script.  (Maxim Uvarov)
- L3 header presence is tested twice. (Alexandru Badicioiu)
- Remove unnecessary check for L3 header presence. (Bill Fischofer)
- Modify check of odp_packet_l4_offset() return. (Bill Fischofer)

 helper/include/odp/helper/udp.h | 55 +
 helper/test/odp_chksum.c|  4 +--
 2 files changed, 25 insertions(+), 34 deletions(-)

diff --git a/helper/include/odp/helper/udp.h b/helper/include/odp/helper/udp.h
index 06c439b..9e7256d 100644
--- a/helper/include/odp/helper/udp.h
+++ b/helper/include/odp/helper/udp.h
@@ -4,7 +4,6 @@
  * SPDX-License-Identifier: BSD-3-Clause
  */
 
-
 /**
  * @file
  *
@@ -22,7 +21,6 @@ extern "C" {
 #include 
 #include 
 
-
 /** @addtogroup odph_header ODPH HEADER
  *  @{
  */
@@ -44,46 +42,39 @@ typedef struct ODP_PACKED {
  * This function uses odp packet to calc checksum
  *
  * @param pkt  calculate chksum for pkt
- * @return  checksum value
+ * @return  checksum value in CPU endianness
  */
 static inline uint16_t odph_ipv4_udp_chksum(odp_packet_t pkt)
 {
-   uint32_t sum = 0;
-   odph_udphdr_t *udph;
-   odph_ipv4hdr_t *iph;
-   uint16_t udplen;
-   uint8_t *buf;
-
-   if (!odp_packet_l3_offset(pkt))
-   return 0;
+   odph_ipv4hdr_t  *iph;
+   odph_udphdr_t   *udph;
+   uint32_tsum;
+   uint16_tudplen, *buf;
 
-   if (!odp_packet_l4_offset(pkt))
+   if (odp_packet_l4_offset(pkt) == ODP_PACKET_OFFSET_INVALID)
return 0;
-
iph = (odph_ipv4hdr_t *)odp_packet_l3_ptr(pkt, NULL);
udph = (odph_udphdr_t *)odp_packet_l4_ptr(pkt, NULL);
-   udplen = odp_be_to_cpu_16(udph->length);
-
-   /* 32-bit sum of all 16-bit words covered by UDP chksum */
+   /* 32-bit sum of UDP pseudo-header */
sum = (iph->src_addr & 0x) + (iph->src_addr >> 16) +
- (iph->dst_addr & 0x) + (iph->dst_addr >> 16) +
- (uint16_t)iph->proto + udplen;
-   for (buf = (uint8_t *)udph; udplen > 1; udplen -= 2) {
-   sum += ((*buf << 8) + *(buf + 1));
-   buf += 2;
-   }
-
-   /* Fold sum to 16 bits: add carrier to result */
-   while (sum >> 16)
-   sum = (sum & 0x) + (sum >> 16);
-
+   (iph->dst_addr & 0x) + (iph->dst_addr >> 16) +
+   odp_be_to_cpu_16(iph->proto) + udph->length;
+   udplen = odp_be_to_cpu_16(udph->length);
+   buf = (uint16_t *)((void *)udph);
+   /* 32-bit sum of UDP header (checksum field cleared) and UDP data */
+   for ( ; udplen > 1; udplen -= 2)
+   sum += *buf++;
+   /* Length is not a multiple of 2 bytes */
+   if (udplen)
+   sum += odp_be_to_cpu_16(*((uint8_t *)buf) << 8);
+   /* Fold sum to 16 bits */
+   sum = (sum & 0x) + (sum >> 16);
+   /* Add carrier (0/1) to result */
+   sum += (sum >> 16);
/* 1's complement */
sum = ~sum;
-
-   /* set computation result */
-   sum = (sum == 0x0) ? 0x : sum;
-
-   return sum;
+   /* Set computation result in CPU endianness */
+   return (sum == 0x0) ? 0x : odp_be_to_cpu_16(sum);
 }
 
 /** @internal Compile time assert */
diff --git a/helper/test/odp_chksum.c b/helper/test/odp_chksum.c
index 1d417a8..2b32111 100644
--- a/helper/test/odp_chksum.c
+++ b/helper/test/odp_chksum.c
@@ -189,14 +189,14 @@ int main(int argc TEST_UNUSED, char *argv[] TEST_UNUSED)
udp->dst_port = 0;
udp->length = odp_cpu_to_be_16(udat_size + ODPH_UDPHDR_LEN);
udp->chksum = 0;
-   udp->chksum = odph_ipv4_udp_chksum(test_packet);
+   udp->chksum = odp_cpu_to_be_16(odph_ipv4_udp_chksum(test_packet));
 
if (udp->chksum == 0)
return -1;
 
printf("chksum = 0x%x\n", udp->chksum);
 
-   if (udp->chksum != 0xab2d)
+   if (udp->chksum != odp_be_to_cpu_16(0x7e5a))
status = -1;
 
odp_packet_free(test_packet);
-- 
1.9.3

___
lng-odp mailing list
lng-odp@lists.linaro.org
https://lists.linaro.org/mailman/listinfo/lng-odp


[lng-odp] [PATCHv3] helper : Fix UDP checksum computation

2015-12-07 Thread ion.grigore
From: Grigore Ion 

This patch fixes the following problems:
- checksum computation for LE platforms
- checksum is computed in the CPU endianness. The returned result
must be converted to the BE ordering when it is used to update
the UDP checksum in a packet.
- checksum computation for packets having the UDP length not a
multiple of 2
- fix the UDP checksum computation in the associated test

Signed-off-by: Grigore Ion 
---
 v3:
 - fix the UDP checksum computation in the associated test
 v2:
 - patch updated to the last master (Maxim Uvarov)
 v1:
 - Move variables declaration on top of block. (Maxim Uvarov)
 - Check patch with checkpatch script.  (Maxim Uvarov)
 - L3 header presence is tested twice. (Alexandru Badicioiu)
 - Remove unnecessary check for L3 header presence. (Bill Fischofer)
 - Modify check of odp_packet_l4_offset() return. (Bill Fischofer)
 
 helper/include/odp/helper/udp.h | 55 +
 helper/test/odp_chksum.c|  4 +--
 2 files changed, 25 insertions(+), 34 deletions(-)

diff --git a/helper/include/odp/helper/udp.h b/helper/include/odp/helper/udp.h
index 06c439b..9e7256d 100644
--- a/helper/include/odp/helper/udp.h
+++ b/helper/include/odp/helper/udp.h
@@ -4,7 +4,6 @@
  * SPDX-License-Identifier: BSD-3-Clause
  */
 
-
 /**
  * @file
  *
@@ -22,7 +21,6 @@ extern "C" {
 #include 
 #include 
 
-
 /** @addtogroup odph_header ODPH HEADER
  *  @{
  */
@@ -44,46 +42,39 @@ typedef struct ODP_PACKED {
  * This function uses odp packet to calc checksum
  *
  * @param pkt  calculate chksum for pkt
- * @return  checksum value
+ * @return  checksum value in CPU endianness
  */
 static inline uint16_t odph_ipv4_udp_chksum(odp_packet_t pkt)
 {
-   uint32_t sum = 0;
-   odph_udphdr_t *udph;
-   odph_ipv4hdr_t *iph;
-   uint16_t udplen;
-   uint8_t *buf;
-
-   if (!odp_packet_l3_offset(pkt))
-   return 0;
+   odph_ipv4hdr_t  *iph;
+   odph_udphdr_t   *udph;
+   uint32_tsum;
+   uint16_tudplen, *buf;
 
-   if (!odp_packet_l4_offset(pkt))
+   if (odp_packet_l4_offset(pkt) == ODP_PACKET_OFFSET_INVALID)
return 0;
-
iph = (odph_ipv4hdr_t *)odp_packet_l3_ptr(pkt, NULL);
udph = (odph_udphdr_t *)odp_packet_l4_ptr(pkt, NULL);
-   udplen = odp_be_to_cpu_16(udph->length);
-
-   /* 32-bit sum of all 16-bit words covered by UDP chksum */
+   /* 32-bit sum of UDP pseudo-header */
sum = (iph->src_addr & 0x) + (iph->src_addr >> 16) +
- (iph->dst_addr & 0x) + (iph->dst_addr >> 16) +
- (uint16_t)iph->proto + udplen;
-   for (buf = (uint8_t *)udph; udplen > 1; udplen -= 2) {
-   sum += ((*buf << 8) + *(buf + 1));
-   buf += 2;
-   }
-
-   /* Fold sum to 16 bits: add carrier to result */
-   while (sum >> 16)
-   sum = (sum & 0x) + (sum >> 16);
-
+   (iph->dst_addr & 0x) + (iph->dst_addr >> 16) +
+   odp_be_to_cpu_16(iph->proto) + udph->length;
+   udplen = odp_be_to_cpu_16(udph->length);
+   buf = (uint16_t *)((void *)udph);
+   /* 32-bit sum of UDP header (checksum field cleared) and UDP data */
+   for ( ; udplen > 1; udplen -= 2)
+   sum += *buf++;
+   /* Length is not a multiple of 2 bytes */
+   if (udplen)
+   sum += odp_be_to_cpu_16(*((uint8_t *)buf) << 8);
+   /* Fold sum to 16 bits */
+   sum = (sum & 0x) + (sum >> 16);
+   /* Add carrier (0/1) to result */
+   sum += (sum >> 16);
/* 1's complement */
sum = ~sum;
-
-   /* set computation result */
-   sum = (sum == 0x0) ? 0x : sum;
-
-   return sum;
+   /* Set computation result in CPU endianness */
+   return (sum == 0x0) ? 0x : odp_be_to_cpu_16(sum);
 }
 
 /** @internal Compile time assert */
diff --git a/helper/test/odp_chksum.c b/helper/test/odp_chksum.c
index 1d417a8..2b32111 100644
--- a/helper/test/odp_chksum.c
+++ b/helper/test/odp_chksum.c
@@ -189,14 +189,14 @@ int main(int argc TEST_UNUSED, char *argv[] TEST_UNUSED)
udp->dst_port = 0;
udp->length = odp_cpu_to_be_16(udat_size + ODPH_UDPHDR_LEN);
udp->chksum = 0;
-   udp->chksum = odph_ipv4_udp_chksum(test_packet);
+   udp->chksum = odp_cpu_to_be_16(odph_ipv4_udp_chksum(test_packet));
 
if (udp->chksum == 0)
return -1;
 
printf("chksum = 0x%x\n", udp->chksum);
 
-   if (udp->chksum != 0xab2d)
+   if (udp->chksum != odp_be_to_cpu_16(0x7e5a))
status = -1;
 
odp_packet_free(test_packet);
-- 
1.9.3

___
lng-odp mailing list
lng-odp@lists.linaro.org
https://lists.linaro.org/mailman/listinfo/lng-odp


[lng-odp] [PATCHv1] helper:test: Fix UDP checksum computation

2015-12-07 Thread ion.grigore
From: Grigore Ion 

The UDP checksum is computed in the CPU endianness. The returned result
must be converted to the BE ordering when it is used to update the UDP
checksum in a packet.

Signed-off-by: Grigore Ion 
---
v1:
Fix UDP checksum computation

 helper/test/odp_chksum.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/helper/test/odp_chksum.c b/helper/test/odp_chksum.c
index 1d417a8..2b32111 100644
--- a/helper/test/odp_chksum.c
+++ b/helper/test/odp_chksum.c
@@ -189,14 +189,14 @@ int main(int argc TEST_UNUSED, char *argv[] TEST_UNUSED)
udp->dst_port = 0;
udp->length = odp_cpu_to_be_16(udat_size + ODPH_UDPHDR_LEN);
udp->chksum = 0;
-   udp->chksum = odph_ipv4_udp_chksum(test_packet);
+   udp->chksum = odp_cpu_to_be_16(odph_ipv4_udp_chksum(test_packet));
 
if (udp->chksum == 0)
return -1;
 
printf("chksum = 0x%x\n", udp->chksum);
 
-   if (udp->chksum != 0xab2d)
+   if (udp->chksum != odp_be_to_cpu_16(0x7e5a))
status = -1;
 
odp_packet_free(test_packet);
-- 
1.9.3

___
lng-odp mailing list
lng-odp@lists.linaro.org
https://lists.linaro.org/mailman/listinfo/lng-odp


[lng-odp] [PATCHv1] example:generator : Fix statistics print

2015-10-22 Thread ion.grigore
From: Grigore Ion 

The statistics are displayed at a fixed time interval. If the configured
number of packets is processed before this interval expires, no statistic
is shown. If many packets are processed it is very possible the last
statistic is not displayed.

Signed-off-by: Grigore Ion 
---
 example/generator/odp_generator.c |   61 +++--
 1 files changed, 38 insertions(+), 23 deletions(-)

diff --git a/example/generator/odp_generator.c 
b/example/generator/odp_generator.c
index 34fb226..ab592bd 100644
--- a/example/generator/odp_generator.c
+++ b/example/generator/odp_generator.c
@@ -103,6 +103,7 @@ static void usage(char *progname);
 static int scan_ip(char *buf, unsigned int *paddr);
 static int scan_mac(char *in, odph_ethaddr_t *des);
 static void tv_sub(struct timeval *recvtime, struct timeval *sendtime);
+static void print_on_time_expire_stats(int verbose_interval);
 static void print_global_stats(int num_workers);
 
 /**
@@ -581,13 +582,45 @@ static void *gen_recv_thread(void *arg)
 }
 
 /**
+ * printing on time interval expiration statistics
+ *
+ */
+static void print_on_time_expire_stats(int verbose_interval)
+{
+   uint64_tpkts, pps;
+   static uint64_t pkts_prev, maximum_pps;
+
+   if (args->appl.mode == APPL_MODE_RCV) {
+   pkts = odp_atomic_load_u64();
+   printf(" total receive(UDP: %" PRIu64 ")\n", pkts);
+   return;
+   }
+
+   if (args->appl.mode == APPL_MODE_PING) {
+   pkts = odp_atomic_load_u64();
+   printf(" total receive(ICMP: %" PRIu64 ")\n", pkts);
+   }
+
+   pkts = odp_atomic_load_u64();
+   printf(" total sent: %" PRIu64 "\n", pkts);
+
+   if (args->appl.mode == APPL_MODE_UDP) {
+   pps = (pkts - pkts_prev) / verbose_interval;
+   if (pps > maximum_pps)
+   maximum_pps = pps;
+   printf(" %" PRIu64 " pps, %" PRIu64 " max pps\n",
+  pps, maximum_pps);
+   pkts_prev = pkts;
+   }
+}
+
+/**
  * printing verbose statistics
  *
  */
 static void print_global_stats(int num_workers)
 {
uint64_t start, now, diff;
-   uint64_t pkts, pkts_prev = 0, pps, maximum_pps = 0;
int verbose_interval = 20;
odp_thrmask_t thrd_mask;
 
@@ -612,29 +645,11 @@ static void print_global_stats(int num_workers)
 
start = odp_time_cycles();
 
-   if (args->appl.mode == APPL_MODE_RCV) {
-   pkts = odp_atomic_load_u64();
-   printf(" total receive(UDP: %" PRIu64 ")\n", pkts);
-   continue;
-   }
-
-   if (args->appl.mode == APPL_MODE_PING) {
-   pkts = odp_atomic_load_u64();
-   printf(" total receive(ICMP: %" PRIu64 ")\n", pkts);
-   }
-
-   pkts = odp_atomic_load_u64();
-   printf(" total sent: %" PRIu64 "\n", pkts);
-
-   if (args->appl.mode == APPL_MODE_UDP) {
-   pps = (pkts - pkts_prev) / verbose_interval;
-   if (pps > maximum_pps)
-   maximum_pps = pps;
-   printf(" %" PRIu64 " pps, %" PRIu64 " max pps\n",
-  pps, maximum_pps);
-   pkts_prev = pkts;
-   }
+   print_on_time_expire_stats(verbose_interval);
}
+   /* Print remaining statistics */
+   if (odp_time_cycles_to_ns(diff) < verbose_interval * ODP_TIME_SEC)
+   print_on_time_expire_stats(verbose_interval);
 }
 
 /**
-- 
1.7.3.4

___
lng-odp mailing list
lng-odp@lists.linaro.org
https://lists.linaro.org/mailman/listinfo/lng-odp


[lng-odp] [PATCHv2] helper : Fix UDP checksum computation

2015-10-22 Thread ion.grigore
From: Grigore Ion 

This patch fixes the following problems:
- checksum computation for LE platforms
- checksum is computed in the CPU endianness. The returned result
must be converted to the BE ordering when it is used to update the
UDP checksum in a packet.
- checksum computation for packets having the UDP length not a
multiple of 2.

Signed-off-by: Grigore Ion 
---
 v2:
 - patch updated to the last master (Maxim Uvarov)
 v1:
 - Move variables declaration on top of block. (Maxim Uvarov)
 - Check patch with checkpatch script.  (Maxim Uvarov) 
 - L3 header presence is tested twice. (Alexandru Badicioiu)
 - Remove unnecessary check for L3 header presence. (Bill Fischofer)
 - Modify check of odp_packet_l4_offset() return. (Bill Fischofer)

 helper/include/odp/helper/udp.h |   32 +---
 1 files changed, 13 insertions(+), 19 deletions(-)

diff --git a/helper/include/odp/helper/udp.h b/helper/include/odp/helper/udp.h
index 06c439b..6fce3f2 100644
--- a/helper/include/odp/helper/udp.h
+++ b/helper/include/odp/helper/udp.h
@@ -44,20 +44,16 @@ typedef struct ODP_PACKED {
  * This function uses odp packet to calc checksum
  *
  * @param pkt  calculate chksum for pkt
- * @return  checksum value
+ * @return  checksum value in CPU endianness
  */
 static inline uint16_t odph_ipv4_udp_chksum(odp_packet_t pkt)
 {
-   uint32_t sum = 0;
+   uint32_t sum;
odph_udphdr_t *udph;
odph_ipv4hdr_t *iph;
-   uint16_t udplen;
-   uint8_t *buf;
+   uint16_t udplen, *buf;
 
-   if (!odp_packet_l3_offset(pkt))
-   return 0;
-
-   if (!odp_packet_l4_offset(pkt))
+   if (odp_packet_l4_offset(pkt) == ODP_PACKET_OFFSET_INVALID)
return 0;
 
iph = (odph_ipv4hdr_t *)odp_packet_l3_ptr(pkt, NULL);
@@ -67,23 +63,21 @@ static inline uint16_t odph_ipv4_udp_chksum(odp_packet_t 
pkt)
/* 32-bit sum of all 16-bit words covered by UDP chksum */
sum = (iph->src_addr & 0x) + (iph->src_addr >> 16) +
  (iph->dst_addr & 0x) + (iph->dst_addr >> 16) +
- (uint16_t)iph->proto + udplen;
-   for (buf = (uint8_t *)udph; udplen > 1; udplen -= 2) {
-   sum += ((*buf << 8) + *(buf + 1));
-   buf += 2;
-   }
+ odp_be_to_cpu_16(iph->proto) + udph->length;
+   for (buf = (uint16_t *)((void *)udph); udplen > 1; udplen -= 2)
+   sum += *buf++;
+   if (udplen) /* If length is not a multiple of 2 bytes */
+   sum += odp_be_to_cpu_16(*((uint8_t *)buf) << 8);
 
/* Fold sum to 16 bits: add carrier to result */
-   while (sum >> 16)
-   sum = (sum & 0x) + (sum >> 16);
+   sum = (sum & 0x) + (sum >> 16);
+   sum += (sum >> 16);
 
/* 1's complement */
sum = ~sum;
 
-   /* set computation result */
-   sum = (sum == 0x0) ? 0x : sum;
-
-   return sum;
+   /* set computation result in CPU endianness*/
+   return (sum == 0x0) ? 0x : odp_be_to_cpu_16(sum);
 }
 
 /** @internal Compile time assert */
-- 
1.7.3.4

___
lng-odp mailing list
lng-odp@lists.linaro.org
https://lists.linaro.org/mailman/listinfo/lng-odp


[lng-odp] [PATCHv3] example:generator : Fix data race condition

2015-10-22 Thread ion.grigore
From: Grigore Ion 

The counters.seq counter is used to check if the configured number of
packets was processed. There is a race condition between the counter
incrementation time and its value testing time. If code is running on
multiple CPUs it is possible the application send more packets than
expected (with number of CPUs - 1). A separate counter must be used
for the processed packets.

Signed-off-by: Grigore Ion 
---
 v2:
 - Add PATCH version information (Maxim Uvarov)
 - Check patch with checkpatch script. (Bill Fischofer)
 v3:
 - patch updated to the last master (Maxim Uvarov)

 example/generator/odp_generator.c |   14 --
 1 files changed, 8 insertions(+), 6 deletions(-)

diff --git a/example/generator/odp_generator.c 
b/example/generator/odp_generator.c
index 085902b..34fb226 100644
--- a/example/generator/odp_generator.c
+++ b/example/generator/odp_generator.c
@@ -68,6 +68,7 @@ static struct {
odp_atomic_u64_t ip;/**< ip packets */
odp_atomic_u64_t udp;   /**< udp packets */
odp_atomic_u64_t icmp;  /**< icmp packets */
+   odp_atomic_u64_t cnt;   /**< sent packets*/
 } counters;
 
 /** * Thread specific arguments
@@ -407,6 +408,11 @@ static void *gen_send_thread(void *arg)
for (;;) {
int err;
 
+   if (args->appl.number != -1 &&
+   odp_atomic_fetch_add_u64(, 1) >=
+   (unsigned int)args->appl.number)
+   break;
+
if (args->appl.mode == APPL_MODE_UDP)
pkt = pack_udp_pkt(thr_args->pool);
else if (args->appl.mode == APPL_MODE_PING)
@@ -438,11 +444,6 @@ static void *gen_send_thread(void *arg)
   thr_args->tmo_ev);
 
}
-   if (args->appl.number != -1 &&
-   odp_atomic_load_u64()
-   >= (unsigned int)args->appl.number) {
-   break;
-   }
}
 
/* receive number of reply pks until timeout */
@@ -597,7 +598,7 @@ static void print_global_stats(int num_workers)
 
while (odp_thrmask_worker(_mask) == num_workers) {
if (args->appl.number != -1 &&
-   odp_atomic_load_u64() >=
+   odp_atomic_load_u64() >=
(unsigned int)args->appl.number) {
break;
}
@@ -669,6 +670,7 @@ int main(int argc, char *argv[])
odp_atomic_init_u64(, 0);
odp_atomic_init_u64(, 0);
odp_atomic_init_u64(, 0);
+   odp_atomic_init_u64(, 0);
 
/* Reserve memory for args from shared mem */
shm = odp_shm_reserve("shm_args", sizeof(args_t),
-- 
1.7.3.4

___
lng-odp mailing list
lng-odp@lists.linaro.org
https://lists.linaro.org/mailman/listinfo/lng-odp


[lng-odp] [PATCHv1] validation:classification: Add fix for classification tests

2015-10-22 Thread ion.grigore
From: Grigore Ion 

odph_ipv4_csum_update should be used to update the checksum inside a pkt,
as it is used in all the other examples and tests different from
classification. Thus the prototype of the function should return void,
because the intention was to update a value not to return something. These
being said it is wrong(on LE platforms) to do a cpu_to_be conversion
and an assignment operation in classification_test(this is already done
inside).

Signed-off-by: Grigore Ion 
---
 v1:
 - patch updated to the last master (Maxim Uvarov)

 .../classification/odp_classification_tests.c  |8 
 1 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/test/validation/classification/odp_classification_tests.c 
b/test/validation/classification/odp_classification_tests.c
index ca81c51..da8d90c 100644
--- a/test/validation/classification/odp_classification_tests.c
+++ b/test/validation/classification/odp_classification_tests.c
@@ -252,7 +252,7 @@ odp_packet_t create_packet(bool vlan)
seqno = odp_atomic_fetch_inc_u32();
ip->id = odp_cpu_to_be_16(seqno);
ip->chksum = 0;
-   ip->chksum = odp_cpu_to_be_16(odph_ipv4_csum_update(pkt));
+   ip->chksum = odph_ipv4_csum_update(pkt);
offset += ODPH_IPV4HDR_LEN;
 
/* udp */
@@ -458,7 +458,7 @@ void test_cls_pmr_chain(void)
parse_ipv4_string(CLS_PMR_CHAIN_SADDR, , );
ip->src_addr = odp_cpu_to_be_32(addr);
ip->chksum = 0;
-   ip->chksum = odp_cpu_to_be_16(odph_ipv4_csum_update(pkt));
+   ip->chksum = odph_ipv4_csum_update(pkt);
 
udp = (odph_udphdr_t *)odp_packet_l4_ptr(pkt, NULL);
udp->src_port = odp_cpu_to_be_16(CLS_PMR_CHAIN_SPORT);
@@ -476,7 +476,7 @@ void test_cls_pmr_chain(void)
parse_ipv4_string(CLS_PMR_CHAIN_SADDR, , );
ip->src_addr = odp_cpu_to_be_32(addr);
ip->chksum = 0;
-   ip->chksum = odp_cpu_to_be_16(odph_ipv4_csum_update(pkt));
+   ip->chksum = odph_ipv4_csum_update(pkt);
 
enqueue_loop_interface(pkt);
pkt = receive_packet(, ODP_TIME_SEC);
@@ -796,7 +796,7 @@ void test_pktio_pmr_match_set_cos(void)
parse_ipv4_string(CLS_PMR_SET_SADDR, , );
ip->src_addr = odp_cpu_to_be_32(addr);
ip->chksum = 0;
-   ip->chksum = odp_cpu_to_be_16(odph_ipv4_csum_update(pkt));
+   ip->chksum = odph_ipv4_csum_update(pkt);
 
udp = (odph_udphdr_t *)odp_packet_l4_ptr(pkt, NULL);
udp->src_port = odp_cpu_to_be_16(CLS_PMR_SET_SPORT);
-- 
1.7.3.4

___
lng-odp mailing list
lng-odp@lists.linaro.org
https://lists.linaro.org/mailman/listinfo/lng-odp


[lng-odp] [PATCHv2 2/2] example:generator : Fix UDP checksum computation

2015-10-02 Thread ion.grigore
From: Grigore Ion 

The UDP checksum is computed in the CPU endianness. The returned result
must be converted to the BE ordering when it is used to update the UDP
checksum in a packet.

Signed-off-by: Grigore Ion 
---
 v2:
 - Add PATCH version information (Maxim Uvarov)
 - Check patch with checkpatch script. (Bill Fischofer)

 example/generator/odp_generator.c |2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/example/generator/odp_generator.c 
b/example/generator/odp_generator.c
index 4af82a9..443df8b 100644
--- a/example/generator/odp_generator.c
+++ b/example/generator/odp_generator.c
@@ -239,7 +239,7 @@ static odp_packet_t pack_udp_pkt(odp_pool_t pool)
udp->dst_port = 0;
udp->length = odp_cpu_to_be_16(args->appl.payload + ODPH_UDPHDR_LEN);
udp->chksum = 0;
-   udp->chksum = odph_ipv4_udp_chksum(pkt);
+   udp->chksum = odp_cpu_to_be_16(odph_ipv4_udp_chksum(pkt));
 
return pkt;
 }
-- 
1.7.3.4

___
lng-odp mailing list
lng-odp@lists.linaro.org
https://lists.linaro.org/mailman/listinfo/lng-odp


[lng-odp] [PATCHv2 1/2] example:generator : Fix data race condition

2015-10-02 Thread ion.grigore
From: Grigore Ion 

The counters.seq counter is used to check if the configured number of
packets was processed. There is a race condition between the counter
incrementation time and its value testing time. If code is running on
multiple CPUs it is possible the application send more packets than
expected (with number of CPUs - 1). A separate counter must be used
for the processed packets.

Signed-off-by: Grigore Ion 
---
 v2:
 - Add PATCH version information (Maxim Uvarov)
 - Check patch with checkpatch script. (Bill Fischofer)

 example/generator/odp_generator.c |   19 ++-
 1 files changed, 10 insertions(+), 9 deletions(-)

diff --git a/example/generator/odp_generator.c 
b/example/generator/odp_generator.c
index d6ec758..4af82a9 100644
--- a/example/generator/odp_generator.c
+++ b/example/generator/odp_generator.c
@@ -66,6 +66,7 @@ static struct {
odp_atomic_u64_t ip;/**< ip packets */
odp_atomic_u64_t udp;   /**< udp packets */
odp_atomic_u64_t icmp;  /**< icmp packets */
+   odp_atomic_u64_t cnt;   /**< sent packets*/
 } counters;
 
 /** * Thread specific arguments
@@ -395,6 +396,11 @@ static void *gen_send_thread(void *arg)
for (;;) {
int err;
 
+   if (args->appl.number != -1 &&
+   odp_atomic_fetch_add_u64(, 1) >=
+   (unsigned int)args->appl.number)
+   break;
+
if (args->appl.mode == APPL_MODE_UDP)
pkt = pack_udp_pkt(thr_args->pool);
else if (args->appl.mode == APPL_MODE_PING)
@@ -426,11 +432,6 @@ static void *gen_send_thread(void *arg)
   thr_args->tmo_ev);
 
}
-   if (args->appl.number != -1 &&
-   odp_atomic_load_u64()
-   >= (unsigned int)args->appl.number) {
-   break;
-   }
}
 
/* receive number of reply pks until timeout */
@@ -450,11 +451,10 @@ static void *gen_send_thread(void *arg)
 
/* print info */
if (args->appl.mode == APPL_MODE_UDP) {
-   printf("  [%02i] total send: %ju\n",
-  thr, odp_atomic_load_u64());
+   printf("  [%02i] total send: %d\n", thr, args->appl.number);
} else if (args->appl.mode == APPL_MODE_PING) {
-   printf("  [%02i] total send: %ju total receive: %ju\n",
-  thr, odp_atomic_load_u64(),
+   printf("  [%02i] total send: %d total receive: %ju\n",
+  thr, args->appl.number,
   odp_atomic_load_u64());
}
return arg;
@@ -610,6 +610,7 @@ int main(int argc, char *argv[])
odp_atomic_init_u64(, 0);
odp_atomic_init_u64(, 0);
odp_atomic_init_u64(, 0);
+   odp_atomic_init_u64(, 0);
 
/* Reserve memory for args from shared mem */
shm = odp_shm_reserve("shm_args", sizeof(args_t),
-- 
1.7.3.4

___
lng-odp mailing list
lng-odp@lists.linaro.org
https://lists.linaro.org/mailman/listinfo/lng-odp


[lng-odp] [PATCHv1] example:generator : Fix data race condition

2015-10-02 Thread ion.grigore
From: Grigore Ion 

The counters.seq counter is used to check if the configured number of
packets was processed. There is a race condition between the counter
incrementation time and its value testing time. If code is running on
multiple CPUs it is possible the application send more packets than
expected (with number of CPUs - 1). A separate counter must be used
for the processed packets.

Signed-off-by: Grigore Ion 
---
v1:
- Remove empty line (Maxim Uvarov)
- Add PATCH version information (Maxim Uvarov)
- Check patch with checkpatch script. (Bill Fischofer)
- Remove unnecessary parentheses

 example/generator/odp_generator.c |   19 ++-
 1 files changed, 10 insertions(+), 9 deletions(-)

diff --git a/example/generator/odp_generator.c 
b/example/generator/odp_generator.c
index e281b27..443df8b 100644
--- a/example/generator/odp_generator.c
+++ b/example/generator/odp_generator.c
@@ -66,6 +66,7 @@ static struct {
odp_atomic_u64_t ip;/**< ip packets */
odp_atomic_u64_t udp;   /**< udp packets */
odp_atomic_u64_t icmp;  /**< icmp packets */
+   odp_atomic_u64_t cnt;   /**< sent packets*/
 } counters;
 
 /** * Thread specific arguments
@@ -395,6 +396,11 @@ static void *gen_send_thread(void *arg)
for (;;) {
int err;
 
+   if (args->appl.number != -1 &&
+   odp_atomic_fetch_add_u64(, 1) >=
+   (unsigned int)args->appl.number)
+   break;
+
if (args->appl.mode == APPL_MODE_UDP)
pkt = pack_udp_pkt(thr_args->pool);
else if (args->appl.mode == APPL_MODE_PING)
@@ -426,11 +432,6 @@ static void *gen_send_thread(void *arg)
   thr_args->tmo_ev);
 
}
-   if (args->appl.number != -1 &&
-   odp_atomic_load_u64()
-   >= (unsigned int)args->appl.number) {
-   break;
-   }
}
 
/* receive number of reply pks until timeout */
@@ -450,11 +451,10 @@ static void *gen_send_thread(void *arg)
 
/* print info */
if (args->appl.mode == APPL_MODE_UDP) {
-   printf("  [%02i] total send: %ju\n",
-  thr, odp_atomic_load_u64());
+   printf("  [%02i] total send: %d\n", thr, args->appl.number);
} else if (args->appl.mode == APPL_MODE_PING) {
-   printf("  [%02i] total send: %ju total receive: %ju\n",
-  thr, odp_atomic_load_u64(),
+   printf("  [%02i] total send: %d total receive: %ju\n",
+  thr, args->appl.number,
   odp_atomic_load_u64());
}
return arg;
@@ -610,6 +610,7 @@ int main(int argc, char *argv[])
odp_atomic_init_u64(, 0);
odp_atomic_init_u64(, 0);
odp_atomic_init_u64(, 0);
+   odp_atomic_init_u64(, 0);
 
/* Reserve memory for args from shared mem */
shm = odp_shm_reserve("shm_args", sizeof(args_t),
-- 
1.7.3.4

___
lng-odp mailing list
lng-odp@lists.linaro.org
https://lists.linaro.org/mailman/listinfo/lng-odp


[lng-odp] [PATCHv1] validation:pktio : Fix UDP checksum computation

2015-10-02 Thread ion.grigore
From: Grigore Ion 

The UDP checksum is computed in the CPU endianness. The returned result
must be converted to the BE ordering when it is used to update the UDP
checksum in a packet.

Signed-off-by: Grigore Ion 
---
 v1:
 - Add PATCH version information (Maxim Uvarov)
 - Check patch with checkpatch script. (Bill Fischofer)

 test/validation/pktio/pktio.c |2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/test/validation/pktio/pktio.c b/test/validation/pktio/pktio.c
index d62f18d..604ac89 100644
--- a/test/validation/pktio/pktio.c
+++ b/test/validation/pktio/pktio.c
@@ -195,7 +195,7 @@ static int pktio_fixup_checksums(odp_packet_t pkt)
ip->chksum = 0;
odph_ipv4_csum_update(pkt);
udp->chksum = 0;
-   udp->chksum = odph_ipv4_udp_chksum(pkt);
+   udp->chksum = odp_cpu_to_be_16(odph_ipv4_udp_chksum(pkt));
 
return 0;
 }
-- 
1.7.3.4

___
lng-odp mailing list
lng-odp@lists.linaro.org
https://lists.linaro.org/mailman/listinfo/lng-odp


[lng-odp] [PATCHv1] helper : Fix UDP checksum computation

2015-10-02 Thread ion.grigore
From: Grigore Ion 

This patch fixes the following problems:
- checksum computation for LE platforms
- checksum is computed in the CPU endianness. The returned result
must be converted to the BE ordering when it is used to update the
UDP checksum in a packet.
- checksum computation for packets having the UDP length not a
multiple of 2.

Signed-off-by: Grigore Ion 
---
v1: 
- Move variables declaration on top of block. (Maxim Uvarov)
- Check patch with checkpatch script.  (Maxim Uvarov) 
- L3 header presence is tested twice. (Alexandru Badicioiu)
- Remove unnecessary check for L3 header presence. (Bill Fischofer)
- Modify check of odp_packet_l4_offset() return. (Bill Fischofer)

 helper/include/odp/helper/udp.h |   55 --
 1 files changed, 23 insertions(+), 32 deletions(-)

diff --git a/helper/include/odp/helper/udp.h b/helper/include/odp/helper/udp.h
index 06c439b..99392c5 100644
--- a/helper/include/odp/helper/udp.h
+++ b/helper/include/odp/helper/udp.h
@@ -4,7 +4,6 @@
  * SPDX-License-Identifier: BSD-3-Clause
  */
 
-
 /**
  * @file
  *
@@ -22,7 +21,6 @@ extern "C" {
 #include 
 #include 
 
-
 /** @addtogroup odph_header ODPH HEADER
  *  @{
  */
@@ -44,46 +42,39 @@ typedef struct ODP_PACKED {
  * This function uses odp packet to calc checksum
  *
  * @param pkt  calculate chksum for pkt
- * @return  checksum value
+ * @return  checksum value in CPU endianness
  */
 static inline uint16_t odph_ipv4_udp_chksum(odp_packet_t pkt)
 {
-   uint32_t sum = 0;
-   odph_udphdr_t *udph;
-   odph_ipv4hdr_t *iph;
-   uint16_t udplen;
-   uint8_t *buf;
-
-   if (!odp_packet_l3_offset(pkt))
-   return 0;
+   odph_ipv4hdr_t  *iph;
+   odph_udphdr_t   *udph;
+   uint32_tsum;
+   uint16_tudplen, *buf;
 
-   if (!odp_packet_l4_offset(pkt))
+   if (odp_packet_l4_offset(pkt) == ODP_PACKET_OFFSET_INVALID)
return 0;
-
iph = (odph_ipv4hdr_t *)odp_packet_l3_ptr(pkt, NULL);
udph = (odph_udphdr_t *)odp_packet_l4_ptr(pkt, NULL);
-   udplen = odp_be_to_cpu_16(udph->length);
-
-   /* 32-bit sum of all 16-bit words covered by UDP chksum */
+   /* 32-bit sum of UDP pseudo-header */
sum = (iph->src_addr & 0x) + (iph->src_addr >> 16) +
- (iph->dst_addr & 0x) + (iph->dst_addr >> 16) +
- (uint16_t)iph->proto + udplen;
-   for (buf = (uint8_t *)udph; udplen > 1; udplen -= 2) {
-   sum += ((*buf << 8) + *(buf + 1));
-   buf += 2;
-   }
-
-   /* Fold sum to 16 bits: add carrier to result */
-   while (sum >> 16)
-   sum = (sum & 0x) + (sum >> 16);
-
+   (iph->dst_addr & 0x) + (iph->dst_addr >> 16) +
+   odp_be_to_cpu_16(iph->proto) + udph->length;
+   udplen = odp_be_to_cpu_16(udph->length);
+   buf = (uint16_t *)((void *)udph);
+   /* 32-bit sum of UDP header (checksum field cleared) and UDP data */
+   for ( ; udplen > 1; udplen -= 2)
+   sum += *buf++;
+   /* Length is not a multiple of 2 bytes */
+   if (udplen)
+   sum += odp_be_to_cpu_16(*((uint8_t *)buf) << 8);
+   /* Fold sum to 16 bits */
+   sum = (sum & 0x) + (sum >> 16);
+   /* Add carrier (0/1) to result */
+   sum += (sum >> 16);
/* 1's complement */
sum = ~sum;
-
-   /* set computation result */
-   sum = (sum == 0x0) ? 0x : sum;
-
-   return sum;
+   /* Set computation result */
+   return (sum == 0x0) ? 0x : odp_be_to_cpu_16(sum);
 }
 
 /** @internal Compile time assert */
-- 
1.7.3.4

___
lng-odp mailing list
lng-odp@lists.linaro.org
https://lists.linaro.org/mailman/listinfo/lng-odp


[lng-odp] [PATCH] example:generator : Fix data race condition

2015-10-01 Thread ion.grigore
From: Grigore Ion 

The counters.seq counter is used to check if the configured number of
packets was processed. There is a race condition between the counter
incrementation time and its value testing time. If code is running on
multiple CPUs it is possible the application send more packets than
expected (with number of CPUs - 1). A separate counter must be used
for the processed packets.

Signed-off-by: Grigore Ion 
---
 example/generator/odp_generator.c |   20 +++-
 1 files changed, 11 insertions(+), 9 deletions(-)

diff --git a/example/generator/odp_generator.c 
b/example/generator/odp_generator.c
index e281b27..34df8b3 100644
--- a/example/generator/odp_generator.c
+++ b/example/generator/odp_generator.c
@@ -66,6 +66,7 @@ static struct {
odp_atomic_u64_t ip;/**< ip packets */
odp_atomic_u64_t udp;   /**< udp packets */
odp_atomic_u64_t icmp;  /**< icmp packets */
+   odp_atomic_u64_t cnt;   /**< sent packets*/
 } counters;
 
 /** * Thread specific arguments
@@ -395,6 +396,12 @@ static void *gen_send_thread(void *arg)
for (;;) {
int err;
 
+   if (args->appl.number != -1 &&
+   odp_atomic_fetch_add_u64(, 1) >=
+   (unsigned int)args->appl.number) {
+   break;
+   }
+
if (args->appl.mode == APPL_MODE_UDP)
pkt = pack_udp_pkt(thr_args->pool);
else if (args->appl.mode == APPL_MODE_PING)
@@ -426,11 +433,6 @@ static void *gen_send_thread(void *arg)
   thr_args->tmo_ev);
 
}
-   if (args->appl.number != -1 &&
-   odp_atomic_load_u64()
-   >= (unsigned int)args->appl.number) {
-   break;
-   }
}
 
/* receive number of reply pks until timeout */
@@ -450,11 +452,10 @@ static void *gen_send_thread(void *arg)
 
/* print info */
if (args->appl.mode == APPL_MODE_UDP) {
-   printf("  [%02i] total send: %ju\n",
-  thr, odp_atomic_load_u64());
+   printf("  [%02i] total send: %d\n", thr, args->appl.number);
} else if (args->appl.mode == APPL_MODE_PING) {
-   printf("  [%02i] total send: %ju total receive: %ju\n",
-  thr, odp_atomic_load_u64(),
+   printf("  [%02i] total send: %d total receive: %ju\n",
+  thr, args->appl.number,
   odp_atomic_load_u64());
}
return arg;
@@ -610,6 +611,7 @@ int main(int argc, char *argv[])
odp_atomic_init_u64(, 0);
odp_atomic_init_u64(, 0);
odp_atomic_init_u64(, 0);
+   odp_atomic_init_u64(, 0);
 
/* Reserve memory for args from shared mem */
shm = odp_shm_reserve("shm_args", sizeof(args_t),
-- 
1.7.3.4

___
lng-odp mailing list
lng-odp@lists.linaro.org
https://lists.linaro.org/mailman/listinfo/lng-odp


[lng-odp] [PATCH] helper : Fix UDP checksum computation

2015-10-01 Thread ion.grigore
From: Grigore Ion 

This patch fixes the following problems:
- checksum computation for LE platforms
- checksum is computed in the CPU endianness. The returned result
must be converted to the BE ordering when it is used to update the
UDP checksum in a packet.
- checksum computation for packets having the UDP length not a
multiple of 2.

Signed-off-by: Grigore Ion 
---
 helper/include/odp/helper/udp.h |   55 --
 1 files changed, 23 insertions(+), 32 deletions(-)

diff --git a/helper/include/odp/helper/udp.h b/helper/include/odp/helper/udp.h
index 06c439b..f56b310 100644
--- a/helper/include/odp/helper/udp.h
+++ b/helper/include/odp/helper/udp.h
@@ -4,7 +4,6 @@
  * SPDX-License-Identifier: BSD-3-Clause
  */
 
-
 /**
  * @file
  *
@@ -22,7 +21,6 @@ extern "C" {
 #include 
 #include 
 
-
 /** @addtogroup odph_header ODPH HEADER
  *  @{
  */
@@ -44,46 +42,39 @@ typedef struct ODP_PACKED {
  * This function uses odp packet to calc checksum
  *
  * @param pkt  calculate chksum for pkt
- * @return  checksum value
+ * @return  checksum value in CPU endianness
  */
 static inline uint16_t odph_ipv4_udp_chksum(odp_packet_t pkt)
 {
-   uint32_t sum = 0;
-   odph_udphdr_t *udph;
-   odph_ipv4hdr_t *iph;
-   uint16_t udplen;
-   uint8_t *buf;
-
-   if (!odp_packet_l3_offset(pkt))
-   return 0;
+   odph_ipv4hdr_t  *iph;
+   odph_udphdr_t   *udph;
+   uint32_tsum;
+   uint16_tudplen, *buf;
 
-   if (!odp_packet_l4_offset(pkt))
+   if (!odp_packet_l3_offset(pkt) || !odp_packet_l3_offset(pkt))
return 0;
-
iph = (odph_ipv4hdr_t *)odp_packet_l3_ptr(pkt, NULL);
udph = (odph_udphdr_t *)odp_packet_l4_ptr(pkt, NULL);
-   udplen = odp_be_to_cpu_16(udph->length);
-
-   /* 32-bit sum of all 16-bit words covered by UDP chksum */
+   /* 32-bit sum of UDP pseudo-header */
sum = (iph->src_addr & 0x) + (iph->src_addr >> 16) +
- (iph->dst_addr & 0x) + (iph->dst_addr >> 16) +
- (uint16_t)iph->proto + udplen;
-   for (buf = (uint8_t *)udph; udplen > 1; udplen -= 2) {
-   sum += ((*buf << 8) + *(buf + 1));
-   buf += 2;
-   }
-
-   /* Fold sum to 16 bits: add carrier to result */
-   while (sum >> 16)
-   sum = (sum & 0x) + (sum >> 16);
-
+   (iph->dst_addr & 0x) + (iph->dst_addr >> 16) +
+   odp_be_to_cpu_16(iph->proto) + udph->length;
+   udplen = odp_be_to_cpu_16(udph->length);
+   buf = (uint16_t *)((void *)udph);
+   /* 32-bit sum of UDP header (checksum field cleared) and UDP data */
+   for ( ; udplen > 1; udplen -= 2)
+   sum += *buf++;
+   /* Length is not a multiple of 2 bytes */
+   if (udplen)
+   sum += odp_be_to_cpu_16(*((uint8_t *)buf) << 8);
+   /* Fold sum to 16 bits */
+   sum = (sum & 0x) + (sum >> 16);
+   /* Add carrier (0/1) to result */
+   sum += (sum >> 16);
/* 1's complement */
sum = ~sum;
-
-   /* set computation result */
-   sum = (sum == 0x0) ? 0x : sum;
-
-   return sum;
+   /* Set computation result */
+   return (sum == 0x0) ? 0x : odp_be_to_cpu_16(sum);
 }
 
 /** @internal Compile time assert */
-- 
1.7.3.4

___
lng-odp mailing list
lng-odp@lists.linaro.org
https://lists.linaro.org/mailman/listinfo/lng-odp


[lng-odp] [PATCH] helper : Fix UDP checksum computation

2015-10-01 Thread ion.grigore
From: Grigore Ion 

This patch fixes the following problems:
- checksum computation for LE platforms
- checksum is computed in the CPU endianness. The returned result
must be converted to the BE ordering when it is used to update the
UDP checksum in a packet.
- checksum computation for packets having the UDP length not a
multiple of 2.

Signed-off-by: Grigore Ion 
---
 helper/include/odp/helper/udp.h |   55 --
 1 files changed, 23 insertions(+), 32 deletions(-)

diff --git a/helper/include/odp/helper/udp.h b/helper/include/odp/helper/udp.h
index 06c439b..5d6154f 100644
--- a/helper/include/odp/helper/udp.h
+++ b/helper/include/odp/helper/udp.h
@@ -4,7 +4,6 @@
  * SPDX-License-Identifier: BSD-3-Clause
  */
 
-
 /**
  * @file
  *
@@ -22,7 +21,6 @@ extern "C" {
 #include 
 #include 
 
-
 /** @addtogroup odph_header ODPH HEADER
  *  @{
  */
@@ -44,46 +42,39 @@ typedef struct ODP_PACKED {
  * This function uses odp packet to calc checksum
  *
  * @param pkt  calculate chksum for pkt
- * @return  checksum value
+ * @return  checksum value in CPU endianness
  */
 static inline uint16_t odph_ipv4_udp_chksum(odp_packet_t pkt)
 {
-   uint32_t sum = 0;
-   odph_udphdr_t *udph;
-   odph_ipv4hdr_t *iph;
-   uint16_t udplen;
-   uint8_t *buf;
-
-   if (!odp_packet_l3_offset(pkt))
-   return 0;
+   odph_ipv4hdr_t  *iph;
+   odph_udphdr_t   *udph;
+   uint32_tsum;
+   uint16_tudplen, *buf;
 
-   if (!odp_packet_l4_offset(pkt))
+   if (!odp_packet_l3_offset(pkt) || !odp_packet_l4_offset(pkt))
return 0;
-
iph = (odph_ipv4hdr_t *)odp_packet_l3_ptr(pkt, NULL);
udph = (odph_udphdr_t *)odp_packet_l4_ptr(pkt, NULL);
-   udplen = odp_be_to_cpu_16(udph->length);
-
-   /* 32-bit sum of all 16-bit words covered by UDP chksum */
+   /* 32-bit sum of UDP pseudo-header */
sum = (iph->src_addr & 0x) + (iph->src_addr >> 16) +
- (iph->dst_addr & 0x) + (iph->dst_addr >> 16) +
- (uint16_t)iph->proto + udplen;
-   for (buf = (uint8_t *)udph; udplen > 1; udplen -= 2) {
-   sum += ((*buf << 8) + *(buf + 1));
-   buf += 2;
-   }
-
-   /* Fold sum to 16 bits: add carrier to result */
-   while (sum >> 16)
-   sum = (sum & 0x) + (sum >> 16);
-
+   (iph->dst_addr & 0x) + (iph->dst_addr >> 16) +
+   odp_be_to_cpu_16(iph->proto) + udph->length;
+   udplen = odp_be_to_cpu_16(udph->length);
+   buf = (uint16_t *)((void *)udph);
+   /* 32-bit sum of UDP header (checksum field cleared) and UDP data */
+   for ( ; udplen > 1; udplen -= 2)
+   sum += *buf++;
+   /* Length is not a multiple of 2 bytes */
+   if (udplen)
+   sum += odp_be_to_cpu_16(*((uint8_t *)buf) << 8);
+   /* Fold sum to 16 bits */
+   sum = (sum & 0x) + (sum >> 16);
+   /* Add carrier (0/1) to result */
+   sum += (sum >> 16);
/* 1's complement */
sum = ~sum;
-
-   /* set computation result */
-   sum = (sum == 0x0) ? 0x : sum;
-
-   return sum;
+   /* Set computation result */
+   return (sum == 0x0) ? 0x : odp_be_to_cpu_16(sum);
 }
 
 /** @internal Compile time assert */
-- 
1.7.3.4

___
lng-odp mailing list
lng-odp@lists.linaro.org
https://lists.linaro.org/mailman/listinfo/lng-odp


[lng-odp] [PATCH] example:generator : Fix data race condition

2015-09-22 Thread ion.grigore
From: Grigore Ion 

The counters.seq counter is used to check if the configured number of
packets was processed. There is a race condition between the counter
incrementation time and its value testing time. If code is running on
multiple CPUs it is possible the application send more packets than
expected (with number of CPUs - 1). A separate counter must be used
for the processed packets.

Signed-off-by: Grigore Ion 
---
 example/generator/odp_generator.c |   21 -
 1 files changed, 12 insertions(+), 9 deletions(-)

diff --git a/example/generator/odp_generator.c 
b/example/generator/odp_generator.c
index e281b27..2dc1801 100644
--- a/example/generator/odp_generator.c
+++ b/example/generator/odp_generator.c
@@ -66,6 +66,7 @@ static struct {
odp_atomic_u64_t ip;/**< ip packets */
odp_atomic_u64_t udp;   /**< udp packets */
odp_atomic_u64_t icmp;  /**< icmp packets */
+   odp_atomic_u64_t cnt;   /**< sent packets*/
 } counters;
 
 /** * Thread specific arguments
@@ -228,6 +229,7 @@ static odp_packet_t pack_udp_pkt(odp_pool_t pool)
   ODPH_IPV4HDR_LEN);
ip->proto = ODPH_IPPROTO_UDP;
seq = odp_atomic_fetch_add_u64(, 1) % 0x;
+
ip->id = odp_cpu_to_be_16(seq);
ip->chksum = 0;
odph_ipv4_csum_update(pkt);
@@ -395,6 +397,12 @@ static void *gen_send_thread(void *arg)
for (;;) {
int err;
 
+   if (args->appl.number != -1 &&
+   odp_atomic_fetch_add_u64(, 1) >=
+   (unsigned int)args->appl.number) {
+   break;
+   }
+
if (args->appl.mode == APPL_MODE_UDP)
pkt = pack_udp_pkt(thr_args->pool);
else if (args->appl.mode == APPL_MODE_PING)
@@ -426,11 +434,6 @@ static void *gen_send_thread(void *arg)
   thr_args->tmo_ev);
 
}
-   if (args->appl.number != -1 &&
-   odp_atomic_load_u64()
-   >= (unsigned int)args->appl.number) {
-   break;
-   }
}
 
/* receive number of reply pks until timeout */
@@ -450,11 +453,10 @@ static void *gen_send_thread(void *arg)
 
/* print info */
if (args->appl.mode == APPL_MODE_UDP) {
-   printf("  [%02i] total send: %ju\n",
-  thr, odp_atomic_load_u64());
+   printf("  [%02i] total send: %d\n", thr, args->appl.number);
} else if (args->appl.mode == APPL_MODE_PING) {
-   printf("  [%02i] total send: %ju total receive: %ju\n",
-  thr, odp_atomic_load_u64(),
+   printf("  [%02i] total send: %d total receive: %ju\n",
+  thr, args->appl.number,
   odp_atomic_load_u64());
}
return arg;
@@ -610,6 +612,7 @@ int main(int argc, char *argv[])
odp_atomic_init_u64(, 0);
odp_atomic_init_u64(, 0);
odp_atomic_init_u64(, 0);
+   odp_atomic_init_u64(, 0);
 
/* Reserve memory for args from shared mem */
shm = odp_shm_reserve("shm_args", sizeof(args_t),
-- 
1.7.3.4

___
lng-odp mailing list
lng-odp@lists.linaro.org
https://lists.linaro.org/mailman/listinfo/lng-odp


[lng-odp] [PATCH] validation:pktio : Fix UDP checksum computation

2015-09-21 Thread ion.grigore
From: Grigore Ion 

The UDP checksum is computed in the CPU endianess. The returned result must be 
converted
to the BE ordering when it is used to update the UDP checksum in a packet.

Signed-off-by: Grigore Ion 
---
 test/validation/pktio/pktio.c |2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/test/validation/pktio/pktio.c b/test/validation/pktio/pktio.c
index d62f18d..604ac89 100644
--- a/test/validation/pktio/pktio.c
+++ b/test/validation/pktio/pktio.c
@@ -195,7 +195,7 @@ static int pktio_fixup_checksums(odp_packet_t pkt)
ip->chksum = 0;
odph_ipv4_csum_update(pkt);
udp->chksum = 0;
-   udp->chksum = odph_ipv4_udp_chksum(pkt);
+   udp->chksum = odp_cpu_to_be_16(odph_ipv4_udp_chksum(pkt));
 
return 0;
 }
-- 
1.7.3.4

___
lng-odp mailing list
lng-odp@lists.linaro.org
https://lists.linaro.org/mailman/listinfo/lng-odp


[lng-odp] [PATCH] helper : Fix UDP checksum computation

2015-09-21 Thread ion.grigore
From: Grigore Ion 

This patch fixes the following problems:
- checksum computation for LE platforms
- checksum is computed in the CPU endianess. The returned result must be 
converted
to the BE ordering when it is used to update the UDP checksum in a packet.
- checksum computation for packets having the UDP length not a multiple of 2.

Signed-off-by: Grigore Ion 
---
 helper/include/odp/helper/udp.h |   54 ++-
 1 files changed, 25 insertions(+), 29 deletions(-)

diff --git a/helper/include/odp/helper/udp.h b/helper/include/odp/helper/udp.h
index 06c439b..74fad3c 100644
--- a/helper/include/odp/helper/udp.h
+++ b/helper/include/odp/helper/udp.h
@@ -22,7 +22,6 @@ extern "C" {
 #include 
 #include 
 
-
 /** @addtogroup odph_header ODPH HEADER
  *  @{
  */
@@ -44,46 +43,43 @@ typedef struct ODP_PACKED {
  * This function uses odp packet to calc checksum
  *
  * @param pkt  calculate chksum for pkt
- * @return  checksum value
+ * @return  checksum value in CPU endianess
  */
 static inline uint16_t odph_ipv4_udp_chksum(odp_packet_t pkt)
 {
-   uint32_t sum = 0;
-   odph_udphdr_t *udph;
-   odph_ipv4hdr_t *iph;
-   uint16_t udplen;
-   uint8_t *buf;
-
-   if (!odp_packet_l3_offset(pkt))
+   if (!odp_packet_l3_offset(pkt) || !odp_packet_l3_offset(pkt))
return 0;
 
-   if (!odp_packet_l4_offset(pkt))
-   return 0;
+   odph_ipv4hdr_t *iph = (odph_ipv4hdr_t *)odp_packet_l3_ptr(pkt, NULL);
+   odph_udphdr_t *udph = (odph_udphdr_t *)odp_packet_l4_ptr(pkt, NULL);
+
+   /* 32-bit sum of UDP pseudo-header */
+   uint32_t sum = (iph->src_addr & 0x) + (iph->src_addr >> 16) +
+   (iph->dst_addr & 0x) + (iph->dst_addr >> 16) +
+   odp_be_to_cpu_16(iph->proto) + udph->length;
 
-   iph = (odph_ipv4hdr_t *)odp_packet_l3_ptr(pkt, NULL);
-   udph = (odph_udphdr_t *)odp_packet_l4_ptr(pkt, NULL);
-   udplen = odp_be_to_cpu_16(udph->length);
+   uint16_t udplen = odp_be_to_cpu_16(udph->length);
+   uint16_t *buf = (uint16_t *)((void *)udph);
 
-   /* 32-bit sum of all 16-bit words covered by UDP chksum */
-   sum = (iph->src_addr & 0x) + (iph->src_addr >> 16) +
- (iph->dst_addr & 0x) + (iph->dst_addr >> 16) +
- (uint16_t)iph->proto + udplen;
-   for (buf = (uint8_t *)udph; udplen > 1; udplen -= 2) {
-   sum += ((*buf << 8) + *(buf + 1));
-   buf += 2;
-   }
+   /* 32-bit sum of UDP header (checksum field cleared) and UDP data */
+   for ( ; udplen > 1; udplen -= 2)
+   sum += *buf++;
 
-   /* Fold sum to 16 bits: add carrier to result */
-   while (sum >> 16)
-   sum = (sum & 0x) + (sum >> 16);
+   /* Length is not a multiple of 2 bytes */
+   if (udplen)
+   sum += odp_be_to_cpu_16(*((uint8_t *)buf) << 8);
+
+   /* Fold sum to 16 bits */
+   sum = (sum & 0x) + (sum >> 16);
+
+   /* Add carrier (0/1) to result */
+   sum += (sum >> 16);
 
/* 1's complement */
sum = ~sum;
 
-   /* set computation result */
-   sum = (sum == 0x0) ? 0x : sum;
-
-   return sum;
+   /* Set computation result */
+   return (sum == 0x0) ? 0x : odp_be_to_cpu_16(sum);
 }
 
 /** @internal Compile time assert */
-- 
1.7.3.4

___
lng-odp mailing list
lng-odp@lists.linaro.org
https://lists.linaro.org/mailman/listinfo/lng-odp


[lng-odp] [PATCH] example:generator : Fix UDP checksum computation

2015-09-21 Thread ion.grigore
From: Grigore Ion 

The UDP checksum is computed in the CPU endianess. The returned result must be 
converted
to the BE ordering when it is used to update the UDP checksum in a packet.

Signed-off-by: Grigore Ion 
---
 example/generator/odp_generator.c |2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/example/generator/odp_generator.c 
b/example/generator/odp_generator.c
index d6ec758..e281b27 100644
--- a/example/generator/odp_generator.c
+++ b/example/generator/odp_generator.c
@@ -238,7 +238,7 @@ static odp_packet_t pack_udp_pkt(odp_pool_t pool)
udp->dst_port = 0;
udp->length = odp_cpu_to_be_16(args->appl.payload + ODPH_UDPHDR_LEN);
udp->chksum = 0;
-   udp->chksum = odph_ipv4_udp_chksum(pkt);
+   udp->chksum = odp_cpu_to_be_16(odph_ipv4_udp_chksum(pkt));
 
return pkt;
 }
-- 
1.7.3.4

___
lng-odp mailing list
lng-odp@lists.linaro.org
https://lists.linaro.org/mailman/listinfo/lng-odp


[lng-odp] [PATCH] validation:classification: Add fix for classification tests

2015-09-18 Thread ion.grigore
From: Grigore Ion 

odph_ipv4_csum_update should be used to update the checksum inside a pkt,
as it is used in all the other examples and tests different from
classification. Thus the prototype of the function should return void,
because the intention was to update a value not to return something. These
being said it is wrong(on LE platforms) to do a cpu_to_be conversion
and an assignment operation in classification_test(this is
already done inside)

Signed-off-by: Grigore Ion 
---
 .../classification/odp_classification_tests.c  |8 
 1 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/test/validation/classification/odp_classification_tests.c 
b/test/validation/classification/odp_classification_tests.c
index a4072c4..1c944b2 100644
--- a/test/validation/classification/odp_classification_tests.c
+++ b/test/validation/classification/odp_classification_tests.c
@@ -251,7 +251,7 @@ odp_packet_t create_packet(bool vlan)
seqno = odp_atomic_fetch_inc_u32();
ip->id = odp_cpu_to_be_16(seqno);
ip->chksum = 0;
-   ip->chksum = odp_cpu_to_be_16(odph_ipv4_csum_update(pkt));
+   odph_ipv4_csum_update(pkt);
offset += ODPH_IPV4HDR_LEN;
 
/* udp */
@@ -444,7 +444,7 @@ void test_cls_pmr_chain(void)
parse_ipv4_string(CLS_PMR_CHAIN_SADDR, , );
ip->src_addr = odp_cpu_to_be_32(addr);
ip->chksum = 0;
-   ip->chksum = odp_cpu_to_be_16(odph_ipv4_csum_update(pkt));
+   odph_ipv4_csum_update(pkt);
 
udp = (odph_udphdr_t *)odp_packet_l4_ptr(pkt, NULL);
udp->src_port = odp_cpu_to_be_16(CLS_PMR_CHAIN_SPORT);
@@ -462,7 +462,7 @@ void test_cls_pmr_chain(void)
parse_ipv4_string(CLS_PMR_CHAIN_SADDR, , );
ip->src_addr = odp_cpu_to_be_32(addr);
ip->chksum = 0;
-   ip->chksum = odp_cpu_to_be_16(odph_ipv4_csum_update(pkt));
+   odph_ipv4_csum_update(pkt);
 
enqueue_loop_interface(pkt);
pkt = receive_packet(, ODP_TIME_SEC);
@@ -782,7 +782,7 @@ void test_pktio_pmr_match_set_cos(void)
parse_ipv4_string(CLS_PMR_SET_SADDR, , );
ip->src_addr = odp_cpu_to_be_32(addr);
ip->chksum = 0;
-   ip->chksum = odp_cpu_to_be_16(odph_ipv4_csum_update(pkt));
+   odph_ipv4_csum_update(pkt);
 
udp = (odph_udphdr_t *)odp_packet_l4_ptr(pkt, NULL);
udp->src_port = odp_cpu_to_be_16(CLS_PMR_SET_SPORT);
-- 
1.7.3.4

___
lng-odp mailing list
lng-odp@lists.linaro.org
https://lists.linaro.org/mailman/listinfo/lng-odp