Skip to contentSkip to conversation

app/test: fix data length of each packet segment

PATCH Superseded Zhuobin Huang 1 participant 1 message Mar 5, 2023

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 app/test: fix data length of each packet segment

Assign correct data length to each segments according to the given pkt_len and nb_pkt_segs, instead of using pkt_len as the data_len of every packet segment

Fixes a9c9e9698d5e ("app/test: allow to create packets of different sizes")
---
 app/test/packet_burst_generator.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)
app/test/packet_burst_generator.c +7 -2
index 6b42b9b83b..c2e51a3bf1 100644
@@ -350,6 +350,8 @@ generate_packet_burst_proto(struct rte_mempool *mp,
 	struct rte_mbuf *pkt_seg;
 	struct rte_mbuf *pkt;
 
+	const uint8_t pkt_seg_data_len = pkt_len / nb_pkt_segs;
+
 	for (nb_pkt = 0; nb_pkt < nb_pkt_per_burst; nb_pkt++) {
 		pkt = rte_pktmbuf_alloc(mp);
 		if (pkt == NULL) {
@@ -359,7 +361,7 @@ generate_packet_burst_proto(struct rte_mempool *mp,
 			break;
 		}
 
-		pkt->data_len = pkt_len;
+		pkt->data_len = pkt_seg_data_len;
 		pkt_seg = pkt;
 		for (i = 1; i < nb_pkt_segs; i++) {
 			pkt_seg->next = rte_pktmbuf_alloc(mp);
@@ -369,7 +371,10 @@ generate_packet_burst_proto(struct rte_mempool *mp,
 				goto nomore_mbuf;
 			}
 			pkt_seg = pkt_seg->next;
-			pkt_seg->data_len = pkt_len;
+			if(i != nb_pkt_segs - 1)
+				pkt_seg->data_len = pkt_seg_data_len;
+			else
+				pkt_seg->data_len = pkt_seg_data_len + pkt_len % nb_pkt_segs;
 		}
 		pkt_seg->next = NULL; /* Last segment of packet. */
 
Signature · 1 line
2.34.1