All of lore.kernel.org
 help / color / mirror / Atom feed
* Packet crafting....
@ 2014-03-14  9:31 sabu kurian
       [not found] ` <CAJ2bnfDNNGkWW01TmHeWY370diEhCTPJb8aP+EKB5xB71tL3aA-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
  0 siblings, 1 reply; 7+ messages in thread
From: sabu kurian @ 2014-03-14  9:31 UTC (permalink / raw)
  To: dev-VfR2kkLFssw

Hello friends,

As of now... I know on how to create an ipv4 header using the 'struct
ipv4_hdr'.
My requirement is to craft a packet and sent it via 'rte_eth_tx_burst'.
I know that there should be an 'ether_hdr' created before, the packet could
be sent.
Could someone help me on how to set the address fields and type in
'ether_hdr' and how to put the ipv4 header as the payload for ether_hdr.

Thanks in advance

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Packet crafting....
       [not found] ` <CAJ2bnfDNNGkWW01TmHeWY370diEhCTPJb8aP+EKB5xB71tL3aA-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
@ 2014-03-14  9:57   ` Richardson, Bruce
       [not found]     ` <59AF69C657FD0841A61C55336867B5B01A9C4436-kPTMFJFq+rELt2AQoY/u9bfspsVTdybXVpNB7YpNyf8@public.gmane.org>
  0 siblings, 1 reply; 7+ messages in thread
From: Richardson, Bruce @ 2014-03-14  9:57 UTC (permalink / raw)
  To: sabu kurian, dev-VfR2kkLFssw

> Hello friends,
> 
> As of now... I know on how to create an ipv4 header using the 'struct
> ipv4_hdr'.
> My requirement is to craft a packet and sent it via 'rte_eth_tx_burst'.
> I know that there should be an 'ether_hdr' created before, the packet could
> be sent.
> Could someone help me on how to set the address fields and type in
> 'ether_hdr' and how to put the ipv4 header as the payload for ether_hdr.
> 

You probably want to do something like this to craft a full packet. First allocate an mbuf, then get it's data pointer as a ether_hdr structure, then an ip_hdr beyond that and then any L4 headers, e.g. udp, beyond that. For example, assuming mempool variable p:

    struct rte_mbuf *buf = rte_pktmbuf_alloc(p);
    struct ether_hdr *ehdr = rte_pktmbuf_mtod(buf, struct ether_hdr *);
/* set ether_hdr fields here e.g. */
    ehdr->ether_type = rte_bswap16(ETHER_TYPE_IPv4);
    struct ipv4_hdr *iphdr = (struct ipv4_hdr *)(&ehdr[1]);
/* set ipv4 header fields here */
    struct udp_hdr *uhdr = (struct udp_hdr *)(&iphdr[1]);
/* set udp header fields here, e.g. */
    uhdr->src_port = rte_bswap16(0x5000);

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Packet crafting....
       [not found]     ` <59AF69C657FD0841A61C55336867B5B01A9C4436-kPTMFJFq+rELt2AQoY/u9bfspsVTdybXVpNB7YpNyf8@public.gmane.org>
@ 2014-03-14 10:09       ` sabu kurian
       [not found]         ` <CAJ2bnfA8a3_uwiQD5ZxFT9pU-0cv0RB4qRdTfY3xZt_TbcgAfA-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
  0 siblings, 1 reply; 7+ messages in thread
From: sabu kurian @ 2014-03-14 10:09 UTC (permalink / raw)
  To: Richardson, Bruce; +Cc: dev-VfR2kkLFssw

Thank you very much Richardson for your valuable reply. But is there
another way of doing it using the rte_pktmbuf_append / rte_pktmbuf_prepend ?
Can you please tell me on how to do that ?

Regards


On Fri, Mar 14, 2014 at 3:27 PM, Richardson, Bruce <
bruce.richardson-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org> wrote:

> > Hello friends,
> >
> > As of now... I know on how to create an ipv4 header using the 'struct
> > ipv4_hdr'.
> > My requirement is to craft a packet and sent it via 'rte_eth_tx_burst'.
> > I know that there should be an 'ether_hdr' created before, the packet
> could
> > be sent.
> > Could someone help me on how to set the address fields and type in
> > 'ether_hdr' and how to put the ipv4 header as the payload for ether_hdr.
> >
>
> You probably want to do something like this to craft a full packet. First
> allocate an mbuf, then get it's data pointer as a ether_hdr structure, then
> an ip_hdr beyond that and then any L4 headers, e.g. udp, beyond that. For
> example, assuming mempool variable p:
>
>     struct rte_mbuf *buf = rte_pktmbuf_alloc(p);
>     struct ether_hdr *ehdr = rte_pktmbuf_mtod(buf, struct ether_hdr *);
> /* set ether_hdr fields here e.g. */
>     ehdr->ether_type = rte_bswap16(ETHER_TYPE_IPv4);
>     struct ipv4_hdr *iphdr = (struct ipv4_hdr *)(&ehdr[1]);
> /* set ipv4 header fields here */
>     struct udp_hdr *uhdr = (struct udp_hdr *)(&iphdr[1]);
> /* set udp header fields here, e.g. */
>     uhdr->src_port = rte_bswap16(0x5000);
>

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Packet crafting....
       [not found]         ` <CAJ2bnfA8a3_uwiQD5ZxFT9pU-0cv0RB4qRdTfY3xZt_TbcgAfA-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
@ 2014-03-14 11:08           ` Richardson, Bruce
       [not found]             ` <59AF69C657FD0841A61C55336867B5B01A9C452F-kPTMFJFq+rELt2AQoY/u9bfspsVTdybXVpNB7YpNyf8@public.gmane.org>
  0 siblings, 1 reply; 7+ messages in thread
From: Richardson, Bruce @ 2014-03-14 11:08 UTC (permalink / raw)
  To: sabu kurian; +Cc: dev-VfR2kkLFssw


> From: sabu kurian [mailto:sabu2kurian-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org] 
> Sent: Friday, March 14, 2014 10:09 AM
> To: Richardson, Bruce
> Cc: dev-VfR2kkLFssw@public.gmane.org
> Subject: Re: [dpdk-dev] Packet crafting....
>
> Thank you very much Richardson for your valuable reply. But is there another way of doing it using the rte_pktmbuf_append / rte_pktmbuf_prepend ? Can you please tell me on how to do that ?

You could use pktmbuf_append and pktmbuf_prepend, but they are primarily designed to add headers/footers on to an existing packet that already has headers, so that you don't need to move the existing data. In the case of having to craft a packet from scratch, there is no existing data in the mbuf, so the whole packet can just be filled in sequentially. [Don't forget that when you get the mbuf from rte_pktmbuf_alloc, you also need to set the length value to the appropriate size.]

However, if you first write the data to the mbuf and then want to add the headers in order, like a packet moving down through layers of a stack,  you can use prepend to add udp, then ip, then your ethernet header, but this will be no faster than just writing the data directly to the mbuf space, and may be slightly slower as each prepend call has to just the length values and data pointer values in the mbuf. Each header prepended also uses up headroom in the mbuf, so you can only add 128-bytes of headers by default to each packet.

In short, if you are creating a single packet, I'd recommend just getting the data pointer from the returned mbuf and writing directly to that. 

Regards,
/Bruce

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Packet crafting....
       [not found]             ` <59AF69C657FD0841A61C55336867B5B01A9C452F-kPTMFJFq+rELt2AQoY/u9bfspsVTdybXVpNB7YpNyf8@public.gmane.org>
@ 2014-03-14 11:38               ` sabu kurian
       [not found]                 ` <CAJ2bnfBgJiGQ+VumJY6f6R8ecmvEnQ4D24TyiXWmBwQxR6jZJg-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
  0 siblings, 1 reply; 7+ messages in thread
From: sabu kurian @ 2014-03-14 11:38 UTC (permalink / raw)
  To: Richardson, Bruce; +Cc: dev-VfR2kkLFssw

Thanks on the reply Richardson. You did mention something like "Don't
forget that when you get the mbuf from rte_pktmbuf_alloc, you also need to
set the length value to the appropriate size." .

 Like I'm allocating the mbuf using rte_mbuf . The rte_mempool_create has
already set the maximum packet size for a mbuf and the number of mbuf's and
all. So do I really need to use rte_pktmbuf_alloc ?


On Fri, Mar 14, 2014 at 4:38 PM, Richardson, Bruce <
bruce.richardson-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org> wrote:

>
> > From: sabu kurian [mailto:sabu2kurian-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org]
> > Sent: Friday, March 14, 2014 10:09 AM
> > To: Richardson, Bruce
> > Cc: dev-VfR2kkLFssw@public.gmane.org
> > Subject: Re: [dpdk-dev] Packet crafting....
> >
> > Thank you very much Richardson for your valuable reply. But is there
> another way of doing it using the rte_pktmbuf_append / rte_pktmbuf_prepend
> ? Can you please tell me on how to do that ?
>
> You could use pktmbuf_append and pktmbuf_prepend, but they are primarily
> designed to add headers/footers on to an existing packet that already has
> headers, so that you don't need to move the existing data. In the case of
> having to craft a packet from scratch, there is no existing data in the
> mbuf, so the whole packet can just be filled in sequentially. [Don't forget
> that when you get the mbuf from rte_pktmbuf_alloc, you also need to set the
> length value to the appropriate size.]
>
> However, if you first write the data to the mbuf and then want to add the
> headers in order, like a packet moving down through layers of a stack,  you
> can use prepend to add udp, then ip, then your ethernet header, but this
> will be no faster than just writing the data directly to the mbuf space,
> and may be slightly slower as each prepend call has to just the length
> values and data pointer values in the mbuf. Each header prepended also uses
> up headroom in the mbuf, so you can only add 128-bytes of headers by
> default to each packet.
>
> In short, if you are creating a single packet, I'd recommend just getting
> the data pointer from the returned mbuf and writing directly to that.
>
> Regards,
> /Bruce
>

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Packet crafting....
       [not found]                 ` <CAJ2bnfBgJiGQ+VumJY6f6R8ecmvEnQ4D24TyiXWmBwQxR6jZJg-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
@ 2014-03-14 11:49                   ` Richardson, Bruce
       [not found]                     ` <59AF69C657FD0841A61C55336867B5B01A9C4588-kPTMFJFq+rELt2AQoY/u9bfspsVTdybXVpNB7YpNyf8@public.gmane.org>
  0 siblings, 1 reply; 7+ messages in thread
From: Richardson, Bruce @ 2014-03-14 11:49 UTC (permalink / raw)
  To: sabu kurian; +Cc: dev-VfR2kkLFssw


> From: sabu kurian [mailto:sabu2kurian-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org] 
> Sent: Friday, March 14, 2014 11:38 AM
> To: Richardson, Bruce
> Cc: dev-VfR2kkLFssw@public.gmane.org
> Subject: Re: [dpdk-dev] Packet crafting....
> 
> Thanks on the reply Richardson. You did mention something like "Don't forget that when you get the mbuf from 
> rte_pktmbuf_alloc, you also need to set the length value to the appropriate size." .
>
> Like I'm allocating the mbuf using rte_mbuf . The rte_mempool_create has already set the maximum packet size 
> for a mbuf and the number of mbuf's and all. So do I really need to use rte_pktmbuf_alloc ?

How are you getting an mbuf from the pool, if not using rte_pktmbuf_alloc?
When you have an mbuf, that buffer has a maximum size, generally around 2k. However, the packet inside that buffer is generally smaller than the overall buffer size and you must configure that size, otherwise the PMD, and therefore the NIC, has no idea how much data out of that 2k buffer needs to be transmitted.

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Packet crafting....
       [not found]                     ` <59AF69C657FD0841A61C55336867B5B01A9C4588-kPTMFJFq+rELt2AQoY/u9bfspsVTdybXVpNB7YpNyf8@public.gmane.org>
@ 2014-03-14 12:04                       ` sabu kurian
  0 siblings, 0 replies; 7+ messages in thread
From: sabu kurian @ 2014-03-14 12:04 UTC (permalink / raw)
  To: Richardson, Bruce; +Cc: dev-VfR2kkLFssw

Ok thanks a lot Richardson. I got your point. What confused me was that the
size of MBUF and the maximum size are all passed to
'rte_mempool_create' . rte_pktmbuf_alloc
has only one parameter , a pointer to the mbuf pool.  I got it cleared now.
Thanks for your valuable time. Can you answer my other question ?... like I
get a segmentation fault when I try to print the ether_type for a packet.
This is the print statement:  printf("\n Type is %" PRIu16 , *((uint16_t
*)eth_type));

Regards


On Fri, Mar 14, 2014 at 5:19 PM, Richardson, Bruce <
bruce.richardson-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org> wrote:

>
> > From: sabu kurian [mailto:sabu2kurian-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org]
> > Sent: Friday, March 14, 2014 11:38 AM
> > To: Richardson, Bruce
> > Cc: dev-VfR2kkLFssw@public.gmane.org
> > Subject: Re: [dpdk-dev] Packet crafting....
> >
> > Thanks on the reply Richardson. You did mention something like "Don't
> forget that when you get the mbuf from
> > rte_pktmbuf_alloc, you also need to set the length value to the
> appropriate size." .
> >
> > Like I'm allocating the mbuf using rte_mbuf . The rte_mempool_create has
> already set the maximum packet size
> > for a mbuf and the number of mbuf's and all. So do I really need to
> use rte_pktmbuf_alloc ?
>
> How are you getting an mbuf from the pool, if not using rte_pktmbuf_alloc?
> When you have an mbuf, that buffer has a maximum size, generally around
> 2k. However, the packet inside that buffer is generally smaller than the
> overall buffer size and you must configure that size, otherwise the PMD,
> and therefore the NIC, has no idea how much data out of that 2k buffer
> needs to be transmitted.
>

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2014-03-14 12:04 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-03-14  9:31 Packet crafting sabu kurian
     [not found] ` <CAJ2bnfDNNGkWW01TmHeWY370diEhCTPJb8aP+EKB5xB71tL3aA-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2014-03-14  9:57   ` Richardson, Bruce
     [not found]     ` <59AF69C657FD0841A61C55336867B5B01A9C4436-kPTMFJFq+rELt2AQoY/u9bfspsVTdybXVpNB7YpNyf8@public.gmane.org>
2014-03-14 10:09       ` sabu kurian
     [not found]         ` <CAJ2bnfA8a3_uwiQD5ZxFT9pU-0cv0RB4qRdTfY3xZt_TbcgAfA-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2014-03-14 11:08           ` Richardson, Bruce
     [not found]             ` <59AF69C657FD0841A61C55336867B5B01A9C452F-kPTMFJFq+rELt2AQoY/u9bfspsVTdybXVpNB7YpNyf8@public.gmane.org>
2014-03-14 11:38               ` sabu kurian
     [not found]                 ` <CAJ2bnfBgJiGQ+VumJY6f6R8ecmvEnQ4D24TyiXWmBwQxR6jZJg-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2014-03-14 11:49                   ` Richardson, Bruce
     [not found]                     ` <59AF69C657FD0841A61C55336867B5B01A9C4588-kPTMFJFq+rELt2AQoY/u9bfspsVTdybXVpNB7YpNyf8@public.gmane.org>
2014-03-14 12:04                       ` sabu kurian

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.