Skip to content

Commit

Permalink
test: fix segment length in packet generator
Browse files Browse the repository at this point in the history
[ upstream commit b88b8af25e7cbb267584bd4c36d3615c4b20109f ]

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: a9c9e96 ("app/test: allow to create packets of different sizes")

Signed-off-by: Zhuobin Huang <zobin1999@gmail.com>
Reviewed-by: David Marchand <david.marchand@redhat.com>
  • Loading branch information
zobinHuang authored and kevintraynor committed Mar 21, 2023
1 parent b71a128 commit 988dc26
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 10 deletions.
1 change: 1 addition & 0 deletions .mailmap
Original file line number Diff line number Diff line change
Expand Up @@ -1584,6 +1584,7 @@ Zhipeng Lu <luzhipeng@cestc.cn>
Zhirun Yan <zhirun.yan@intel.com>
Zhiwei He <zhiwei.he@intel.com>
Zhiyong Yang <zhiyong.yang@intel.com>
Zhuobin Huang <zobin1999@gmail.com>
Zi Hu <huzilucky@gmail.com>
Zijie Pan <zijie.pan@6wind.com>
Ziyang Xuan <xuanziyang2@huawei.com>
Expand Down
26 changes: 16 additions & 10 deletions app/test/packet_burst_generator.c
Original file line number Diff line number Diff line change
Expand Up @@ -262,11 +262,11 @@ generate_packet_burst(struct rte_mempool *mp, struct rte_mbuf **pkts_burst,
void *ip_hdr, uint8_t ipv4, struct rte_udp_hdr *udp_hdr,
int nb_pkt_per_burst, uint8_t pkt_len, uint8_t nb_pkt_segs)
{
int i, nb_pkt = 0;
size_t eth_hdr_size;

const uint8_t pkt_seg_data_len = pkt_len / nb_pkt_segs;
struct rte_mbuf *pkt_seg;
struct rte_mbuf *pkt;
size_t eth_hdr_size;
int i, nb_pkt = 0;

for (nb_pkt = 0; nb_pkt < nb_pkt_per_burst; nb_pkt++) {
pkt = rte_pktmbuf_alloc(mp);
Expand All @@ -277,7 +277,7 @@ generate_packet_burst(struct rte_mempool *mp, struct rte_mbuf **pkts_burst,
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);
Expand All @@ -287,7 +287,10 @@ generate_packet_burst(struct rte_mempool *mp, struct rte_mbuf **pkts_burst,
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. */

Expand Down Expand Up @@ -343,11 +346,11 @@ generate_packet_burst_proto(struct rte_mempool *mp,
uint8_t ipv4, uint8_t proto, void *proto_hdr,
int nb_pkt_per_burst, uint8_t pkt_len, uint8_t nb_pkt_segs)
{
int i, nb_pkt = 0;
size_t eth_hdr_size;

const uint8_t pkt_seg_data_len = pkt_len / nb_pkt_segs;
struct rte_mbuf *pkt_seg;
struct rte_mbuf *pkt;
size_t eth_hdr_size;
int i, nb_pkt = 0;

for (nb_pkt = 0; nb_pkt < nb_pkt_per_burst; nb_pkt++) {
pkt = rte_pktmbuf_alloc(mp);
Expand All @@ -358,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);
Expand All @@ -368,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. */

Expand Down

0 comments on commit 988dc26

Please sign in to comment.