Skip to content

Commit

Permalink
[Bug Fix] Fix Speed Tester NF Generated Packets Counter (#96)
Browse files Browse the repository at this point in the history
This PR fixes packet generation the Speed Tester NF, with this change
if we can't generate the X requested packets and we only generate Z
packets we will enqueue Z packets. Before we enqueued X packets,
causing a SEGFAULT because some packets would be NULL.

Commit log:

* Packet number bug fix

* Suggested fixes for review

* Had to fix both conditionals

* More code style fixes

* Fixed placement of counter initialization

* Check for uninitialized packets

* Fix style, add space

* Style nit, I need to train my eyes
  • Loading branch information
kevindweb authored and koolzz committed Apr 10, 2019
1 parent 7ce06fd commit 5a78515
Showing 1 changed file with 20 additions and 5 deletions.
25 changes: 20 additions & 5 deletions examples/speed_tester/speed_tester.c
Original file line number Diff line number Diff line change
Expand Up @@ -375,8 +375,10 @@ run_advanced_rings(struct onvm_nf_info *nf_info) {
void
nf_setup(struct onvm_nf_info *nf_info) {
uint32_t i;
uint32_t pkts_generated;
struct rte_mempool *pktmbuf_pool;

pkts_generated = 0;
pktmbuf_pool = rte_mempool_lookup(PKTMBUF_POOL_NAME);
if (pktmbuf_pool == NULL) {
onvm_nflib_stop(nf_info);
Expand All @@ -399,10 +401,12 @@ nf_setup(struct onvm_nf_info *nf_info) {
rte_exit(EXIT_FAILURE, "Cannot open pcap file\n");
}

packet_number = (packet_number ? packet_number : MAX_PKT_NUM);
packet_number = (use_custom_pkt_count ? packet_number : MAX_PKT_NUM);
struct rte_mbuf *pkts[packet_number];

i = 0;

while (((packet = pcap_next(pcap, &header)) != NULL) && (i++ < packet_number)) {
while (((packet = pcap_next(pcap, &header)) != NULL) && (i < packet_number)) {
struct onvm_pkt_meta *pmeta;
struct onvm_ft_ipv4_5tuple key;

Expand All @@ -424,16 +428,19 @@ nf_setup(struct onvm_nf_info *nf_info) {
onvm_ft_fill_key(&key, pkt);
pkt->hash.rss = onvm_softrss(&key);

onvm_nflib_return_pkt(nf_info, pkt);
/* Add packet to batch, and update counter */
pkts[i++] = pkt;
pkts_generated++;
}
onvm_nflib_return_pkt_bulk(nf_info, pkts, pkts_generated);
} else {
#endif
/* use default number of initial packets if -c has not been used */
packet_number = (use_custom_pkt_count ? packet_number : DEFAULT_PKT_NUM);
struct rte_mbuf *pkts[packet_number];

printf("Creating %u packets to send to %u\n", packet_number, destination);

struct rte_mbuf *pkts[packet_number];
for (i = 0; i < packet_number; ++i) {
struct onvm_pkt_meta *pmeta;
struct ether_hdr *ehdr;
Expand Down Expand Up @@ -470,12 +477,20 @@ nf_setup(struct onvm_nf_info *nf_info) {
uint64_t *ts = (uint64_t *)rte_pktmbuf_append(pkt, sizeof(uint64_t));
*ts = 0;
}

/* New packet generated successfully */
pkts[i] = pkt;
pkts_generated++;
}
onvm_nflib_return_pkt_bulk(nf_info, pkts, packet_number);
onvm_nflib_return_pkt_bulk(nf_info, pkts, pkts_generated);
#ifdef LIBPCAP
}
#endif
/* Exit if packets were unexpectedly not created */
if (pkts_generated == 0 && packet_number > 0)
rte_exit(EXIT_FAILURE, "Failed to create packets\n");

packet_number = pkts_generated;
}

int
Expand Down

0 comments on commit 5a78515

Please sign in to comment.