[EXT] Re: [RFC PATCH] graph: add support for pcap trace for graph

Amit Prakash Shukla amitprakashs at marvell.com
Tue Jan 10 12:26:37 CET 2023


Thanks Stephen for the pointers. I will post next version of the patch with the change.


> -----Original Message-----
> From: Stephen Hemminger <stephen at networkplumber.org>
> Sent: Saturday, January 7, 2023 12:27 AM
> To: Amit Prakash Shukla <amitprakashs at marvell.com>
> Cc: Jerin Jacob Kollanukkaran <jerinj at marvell.com>; Kiran Kumar
> Kokkilagadda <kirankumark at marvell.com>; Nithin Kumar Dabilpuram
> <ndabilpuram at marvell.com>; dev at dpdk.org
> Subject: Re: [EXT] Re: [RFC PATCH] graph: add support for pcap trace for
> graph
> 
> On Fri, 6 Jan 2023 10:40:30 +0000
> Amit Prakash Shukla <amitprakashs at marvell.com> wrote:
> 
> > Thanks Stephen for the review. Sure, will use lib/pcapng.
> >
> > I see dpdk libpcapng adds most of the debugging data, however I would
> like to add a node name to the packets which I am thinking of adding using
> 'comment' option under 'Enhanced Packet Block' .
> >
> > Please let me know if that's fine.
> >
> > Thanks,
> > Amit Shukla
> >
> > > -----Original Message-----
> > > From: Stephen Hemminger <stephen at networkplumber.org>
> > > Sent: Friday, December 23, 2022 10:17 PM
> > > To: Amit Prakash Shukla <amitprakashs at marvell.com>
> > > Cc: Jerin Jacob Kollanukkaran <jerinj at marvell.com>; Kiran Kumar
> > > Kokkilagadda <kirankumark at marvell.com>; Nithin Kumar Dabilpuram
> > > <ndabilpuram at marvell.com>; dev at dpdk.org
> > > Subject: [EXT] Re: [RFC PATCH] graph: add support for pcap trace for
> > > graph
> > >
> > > External Email
> > >
> > > --------------------------------------------------------------------
> > > --
> > > On Fri, 23 Dec 2022 17:32:35 +0530
> > > Amit Prakash Shukla <amitprakashs at marvell.com> wrote:
> > >
> > > > +
> > > > +	pcap_trace.file_descriptor = open(pcap_trace.file_name,
> > > > +					  O_CREAT | O_TRUNC | O_WRONLY,
> > > 0664);
> > > > +	if (pcap_trace.file_descriptor < 0) {
> > > > +		ret = 1;
> > > > +		goto done;
> > > > +	}
> > > > +	pcap_trace.n_pcap_data_written = 0;
> > > > +
> > > > +	/* Write file header. */
> > > > +	memset(&file_hdr, 0, sizeof(file_hdr));
> > > > +	file_hdr.magic = 0xa1b2c3d4;
> > > > +	file_hdr.major_version = 2;
> > > > +	file_hdr.minor_version = 4;
> > > > +	file_hdr.time_zone = 0;
> > > > +	file_hdr.max_packet_size_in_bytes = ((1 << 16) - 1);
> > > > +	file_hdr.packet_type = pcap_trace.packet_type;
> > > > +	n = write(pcap_trace.file_descriptor, &file_hdr, sizeof(file_hdr));
> > > > +	if (n != sizeof(file_hdr)) {
> > > > +		ret = 1;
> > > > +		goto done;
> > > > +	}
> > > > +
> > > > +	while (pcap_trace.n_bytes > pcap_trace.n_pcap_data_written) {
> > > > +		int n = pcap_trace.n_bytes -
> > > pcap_trace.n_pcap_data_written;
> > > > +
> > > > +		n = write(pcap_trace.file_descriptor,
> > >
> > > NAK please use lib/pcapng rather than rolling your own pcap format
> > > code
> 
> Something like this:
> 
> diff --git a/lib/pcapng/rte_pcapng.c b/lib/pcapng/rte_pcapng.c index
> cb590ea0096c..216ad80f7ed6 100644
> --- a/lib/pcapng/rte_pcapng.c
> +++ b/lib/pcapng/rte_pcapng.c
> @@ -492,7 +492,8 @@ rte_pcapng_copy(uint16_t port_id, uint32_t queue,
>  		const struct rte_mbuf *md,
>  		struct rte_mempool *mp,
>  		uint32_t length, uint64_t cycles,
> -		enum rte_pcapng_direction direction)
> +		enum rte_pcapng_direction direction,
> +		const char *comment)
>  {
>  	struct pcapng_enhance_packet_block *epb;
>  	uint32_t orig_len, data_len, padding, flags; @@ -552,6 +553,8 @@
> rte_pcapng_copy(uint16_t port_id, uint32_t queue,
>  	optlen += pcapng_optlen(sizeof(queue));
>  	if (rss_hash)
>  		optlen += pcapng_optlen(sizeof(uint8_t) + sizeof(uint32_t));
> +	if (comment)
> +		optlen += pcapng_optlen(strlen(comment));
> 
>  	/* reserve trailing options and block length */
>  	opt = (struct pcapng_option *)
> @@ -590,6 +593,10 @@ rte_pcapng_copy(uint16_t port_id, uint32_t queue,
>  					&hash_opt, sizeof(hash_opt));
>  	}
> 
> +	if (comment)
> +		opt = pcapng_add_option(opt, PCAPNG_OPT_COMMENT,
> +					comment, strlen(comment));
> +
>  	/* Note: END_OPT necessary here. Wireshark doesn't do it. */
> 
>  	/* Add PCAPNG packet header */
> diff --git a/lib/pcapng/rte_pcapng.h b/lib/pcapng/rte_pcapng.h index
> 6b8aaffc6e0f..98f35e8ea177 100644
> --- a/lib/pcapng/rte_pcapng.h
> +++ b/lib/pcapng/rte_pcapng.h
> @@ -126,6 +126,8 @@ enum rte_pcapng_direction {
>   *   The timestamp in TSC cycles.
>   * @param direction
>   *   The direction of the packer: receive, transmit or unknown.
> + * @param comment
> + *  Optional: comment on packet
>   *
>   * @return
>   *   - The pointer to the new mbuf formatted for pcapng_write
> @@ -137,7 +139,8 @@ struct rte_mbuf *
>  rte_pcapng_copy(uint16_t port_id, uint32_t queue,
>  		const struct rte_mbuf *m, struct rte_mempool *mp,
>  		uint32_t length, uint64_t timestamp,
> -		enum rte_pcapng_direction direction);
> +		enum rte_pcapng_direction direction,
> +		const char *comment);
> 
> 
>  /**


More information about the dev mailing list