[PATCH 05/12] gen: add raw packet data API and tests

Jerin Jacob jerinjacobk at gmail.com
Wed Dec 15 13:40:36 CET 2021


On Tue, Dec 14, 2021 at 7:43 PM Ronan Randles <ronan.randles at intel.com> wrote:
>
> From: Harry van Haaren <harry.van.haaren at intel.com>
>
> This commit adds a new API to gen, allowing the caller to set
> raw packet data with a size. Tests are added to test the new
> API with randomized packet data.
>
> Signed-off-by: Harry van Haaren <harry.van.haaren at intel.com>
> ---
>  }
>
> @@ -32,9 +53,37 @@ rte_gen_create(struct rte_mempool *mempool)
>  void
>  rte_gen_destroy(struct rte_gen *gen)
>  {
> +       rte_pktmbuf_free(gen->base_pkt);
>         rte_free(gen);
>  }
>

> +
>  uint16_t
>  rte_gen_rx_burst(struct rte_gen *gen,
>                  struct rte_mbuf **rx_pkts,
> @@ -45,17 +94,20 @@ rte_gen_rx_burst(struct rte_gen *gen,
>         if (err)
>                 return 0;
>
> -       const uint32_t pkt_len = 64;
> +       if (!gen->base_pkt)
> +               return 0;
> +
> +       const uint32_t base_size = gen->base_pkt->pkt_len;
> +       const uint8_t *base_data = rte_pktmbuf_mtod(gen->base_pkt, uint8_t *);

I think, the very next feature will be generating packets for
incrementing IP addresses or so. In this case, one packet-based
template will not work.
May we worth consider that use case into API framework first and add support
later for implementation as it may change the complete land space of API to have
better performance. Options like struct rte_gen logical object can have
N templates instead of one is an option on the table. :-)


>
>         uint32_t i;
>         for (i = 0; i < nb_pkts; i++) {
>                 struct rte_mbuf *m = rx_pkts[i];
>                 uint8_t *pkt_data = rte_pktmbuf_mtod(m, uint8_t *);
>
> -               memset(pkt_data, 0, pkt_len);
> -
> -               m->pkt_len  = pkt_len;
> -               m->data_len = pkt_len;
> +               rte_memcpy(pkt_data, base_data, base_size);
> +               m->pkt_len = base_size;
> +               m->data_len = base_size;
>         }
>


More information about the dev mailing list