From: Panu Matilainen <pmatilai@redhat.com>
To: Fan Zhang <roy.fan.zhang@intel.com>, dev@dpdk.org
Subject: Re: [PATCH 3/4] lib/librte_port: add packet dumping to PCAP file support in sink port
Date: Thu, 28 Jan 2016 13:43:23 +0200 [thread overview]
Message-ID: <56A9FEDB.9000102@redhat.com> (raw)
In-Reply-To: <1453916363-26709-4-git-send-email-roy.fan.zhang@intel.com>
On 01/27/2016 07:39 PM, Fan Zhang wrote:
> Originally, sink ports in librte_port releases received mbufs back to
> mempool. This patch adds optional packet dumping to PCAP feature in sink
> port: the packets will be dumped to user defined PCAP file for storage or
> debugging. The user may also choose the sink port's activity: either it
> continuously dump the packets to the file, or stops at certain dumping
>
> This feature shares same CONFIG_RTE_PORT_PCAP compiler option as source
> port PCAP file support feature. Users can enable or disable this feature
> by setting CONFIG_RTE_PORT_PCAP compiler option "y" or "n".
>
> Signed-off-by: Fan Zhang <roy.fan.zhang@intel.com>
> Acked-by: Cristian Dumitrescu <cristian.dumitrescu@intel.com>
> ---
> lib/librte_port/rte_port_source_sink.c | 268 +++++++++++++++++++++++++++++++--
> lib/librte_port/rte_port_source_sink.h | 11 +-
> 2 files changed, 263 insertions(+), 16 deletions(-)
>
[...]
> +#ifdef RTE_PORT_PCAP
> +
> +/**
> + * Open PCAP file for dumping packets to the file later
> + *
> + * @param port
> + * Handle to sink port
> + * @param p
> + * Sink port parameter
> + * @return
> + * 0 on SUCCESS
> + * error code otherwise
> + */
[...]
> +
> +#else
> +
> +static int
> +pcap_sink_open(struct rte_port_sink *port,
> + __rte_unused struct rte_port_sink_params *p)
> +{
> + port->dumper = NULL;
> + port->max_pkts = 0;
> + port->pkt_index = 0;
> + port->dump_finish = 0;
> +
> + return 0;
> +}
Shouldn't this just return -ENOTSUP instead of success when the pcap
feature is not built in?
> +
> +static void
> +pcap_sink_dump_pkt(__rte_unused struct rte_port_sink *port,
> + __rte_unused struct rte_mbuf *mbuf) {}
> +
> +static void
> +pcap_sink_flush_pkt(__rte_unused void *dumper) {}
> +
> +static void
> +pcap_sink_close(__rte_unused void *dumper) {}
> +
> +#endif
> +
> static void *
> rte_port_sink_create(__rte_unused void *params, int socket_id)
> {
> struct rte_port_sink *port;
> + struct rte_port_sink_params *p = params;
> + int status;
>
> /* Memory allocation */
> port = rte_zmalloc_socket("PORT", sizeof(*port),
> @@ -360,6 +532,19 @@ rte_port_sink_create(__rte_unused void *params, int socket_id)
> return NULL;
> }
>
> + /* Try to open PCAP file for dumping, if possible */
> + status = pcap_sink_open(port, p);
> + if (status < 0) {
> + RTE_LOG(ERR, PORT, "%s: Failed to enable PCAP support "
> + "support\n", __func__);
> + rte_free(port);
> + port = NULL;
> + } else {
> + if (port->dumper != NULL)
> + RTE_LOG(INFO, PORT, "Ready to dump packets to file "
> + "%s\n", p->file_name);
> + }
> +
> return port;
> }
>
> @@ -369,6 +554,8 @@ rte_port_sink_tx(void *port, struct rte_mbuf *pkt)
> __rte_unused struct rte_port_sink *p = (struct rte_port_sink *) port;
>
> RTE_PORT_SINK_STATS_PKTS_IN_ADD(p, 1);
> + if (p->dumper != NULL)
> + pcap_sink_dump_pkt(p, pkt);
> rte_pktmbuf_free(pkt);
> RTE_PORT_SINK_STATS_PKTS_DROP_ADD(p, 1);
>
> @@ -387,21 +574,44 @@ rte_port_sink_tx_bulk(void *port, struct rte_mbuf **pkts,
>
> RTE_PORT_SINK_STATS_PKTS_IN_ADD(p, n_pkts);
> RTE_PORT_SINK_STATS_PKTS_DROP_ADD(p, n_pkts);
> - for (i = 0; i < n_pkts; i++) {
> - struct rte_mbuf *pkt = pkts[i];
> -
> - rte_pktmbuf_free(pkt);
> + if (p->dumper) {
> + for (i = 0; i < n_pkts; i++) {
> + struct rte_mbuf *pkt = pkts[i];
> +
> + pcap_sink_dump_pkt(p, pkt);
> + rte_pktmbuf_free(pkt);
> + }
> + } else {
> + for (i = 0; i < n_pkts; i++) {
> + struct rte_mbuf *pkt = pkts[i];
> +
> + rte_pktmbuf_free(pkt);
> + }
> }
> } else {
> - for ( ; pkts_mask; ) {
> - uint32_t pkt_index = __builtin_ctzll(pkts_mask);
> - uint64_t pkt_mask = 1LLU << pkt_index;
> - struct rte_mbuf *pkt = pkts[pkt_index];
> -
> - RTE_PORT_SINK_STATS_PKTS_IN_ADD(p, 1);
> - RTE_PORT_SINK_STATS_PKTS_DROP_ADD(p, 1);
> - rte_pktmbuf_free(pkt);
> - pkts_mask &= ~pkt_mask;
> + if (p->dumper) {
> + for ( ; pkts_mask; ) {
> + uint32_t pkt_index = __builtin_ctzll(pkts_mask);
> + uint64_t pkt_mask = 1LLU << pkt_index;
> + struct rte_mbuf *pkt = pkts[pkt_index];
> +
> + RTE_PORT_SINK_STATS_PKTS_IN_ADD(p, 1);
> + RTE_PORT_SINK_STATS_PKTS_DROP_ADD(p, 1);
> + pcap_sink_dump_pkt(p, pkt);
> + rte_pktmbuf_free(pkt);
> + pkts_mask &= ~pkt_mask;
> + }
> + } else {
> + for ( ; pkts_mask; ) {
> + uint32_t pkt_index = __builtin_ctzll(pkts_mask);
> + uint64_t pkt_mask = 1LLU << pkt_index;
> + struct rte_mbuf *pkt = pkts[pkt_index];
> +
> + RTE_PORT_SINK_STATS_PKTS_IN_ADD(p, 1);
> + RTE_PORT_SINK_STATS_PKTS_DROP_ADD(p, 1);
> + rte_pktmbuf_free(pkt);
> + pkts_mask &= ~pkt_mask;
> + }
These add quite a fair chunk of nearly identical duplicate code, which
could be easily avoided with an _ops-style function pointer between say,
null_sink_dump_pkt() which is a no-op function and pcap_sink_dump_pkt().
- Panu -
next prev parent reply other threads:[~2016-01-28 11:43 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-01-27 17:39 [PATCH 0/4] Add PCAP support to source and sink port Fan Zhang
2016-01-27 17:39 ` [PATCH 1/4] lib/librte_port: add PCAP file support to source port Fan Zhang
2016-01-28 11:54 ` Panu Matilainen
2016-01-29 15:10 ` Zhang, Roy Fan
2016-01-27 17:39 ` [PATCH 2/4] examples/ip_pipeline: add PCAP file support Fan Zhang
2016-01-27 17:39 ` [PATCH 3/4] lib/librte_port: add packet dumping to PCAP file support in sink port Fan Zhang
2016-01-28 11:43 ` Panu Matilainen [this message]
2016-01-29 15:34 ` Zhang, Roy Fan
2016-01-27 17:39 ` [PATCH 4/4] examples/ip_pipeline: add packets dumping to PCAP file support Fan Zhang
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=56A9FEDB.9000102@redhat.com \
--to=pmatilai@redhat.com \
--cc=dev@dpdk.org \
--cc=roy.fan.zhang@intel.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.