Thanks a bunch Dave !
The vlib_buffer_add_data(...) does the trick for me ! All that I
really had to do was to just set up the following fields in the
vlib_buffer_t for the buffer index created by the function
 vnet_buffer (b)->sw_if_index[VLIB_RX]
 vnet_buffer (b)->sw_if_index[VLIB_TX]

What a nice function !



On Mon, Oct 29, 2018 at 4:50 AM Dave Barach (dbarach) <dbar...@cisco.com> wrote:
>
> Look at .../src/vnet/ipfix-export/flow_report.c : send_template_packet(...) 
> for a decent example of most of the mechanics involved. Also look at 
> .../src/vlib/buffer.c : vlib_buffer_add_data(...).
>
> If you're going to send lots of such packets, it may well improve performance 
> to allocate a fair number of buffers at a time, and maintain a private buffer 
> cache. See ../src/vnet/tcp/tcp_output.c : tcp_alloc_tx_buffers(...).
>
> HTH... Dave
>
> -----Original Message-----
> From: vpp-dev@lists.fd.io <vpp-dev@lists.fd.io> On Behalf Of Prashant 
> Upadhyaya
> Sent: Sunday, October 28, 2018 3:13 AM
> To: vpp-dev@lists.fd.io
> Subject: [vpp-dev] Regarding vlib_buffer_t construction for tx of a self-made 
> packet
>
> Hi,
>
> I have a situation where one of my plugins needs to construct an l2 packet 
> (containing an ip datagram inside).
> So I have a local buffer which contains the following bytes laid out -- dst 
> mac src mac ethertype ip header + payload
>
> Assume for the sake of generality that the above buffer is 4K bytes (because 
> I have an ip payload of that much size) Assume further that I magically 
> already know the sw if indices of the RX and TX.
> It is also ensured that the l2 paylod size is lesser than or equal to the MTU 
> of the TX interface
>
> Now once I have all of the above information, I need to create a 
> vlib_buffer_t (possibly a chained set) So I need some guidelines/best 
> practices of how to go about it flawlessly so that once the vlib_buffer_t is 
> constructed, I can simply send it to the "interface-output" and accomplish 
> the act of transmission.
>
> The high level set of things that I can think of is --
>
> 1. Allocate a vlib_buffer_t (or a chained flavour of those) 2. Start 
> appending data to those buffers 3. What about the various control fields to 
> be set in the above buffers ?
> . I suppose I will have to do the following --
>   vnet_buffer (b0)->sw_if_index[VLIB_RX] = <My known index>;
>                 vnet_buffer (b0)->sw_if_index[VLIB_TX] = <My known index>; Do 
> I need to do anything with b0->buffer_pool_index ?
> What to do with b0->current_data ?
> What to do with b0->flags ?
> What to do with b->current_length ?
> And if it is a chained set, what is to be done on individual vlib_buffer_t of 
> the chain and what on the first one of the chain ?
>
> I suppose I need a convenience function like the following
>
> vlib_buffer_t* foo(char* myl2packet, int lengthOfMyL2Packet, u32 
> mySwIfRxIndex, u32 mySwIfTxIndex)
>
> The above should return to me a nice little vlib_buffer_t (possibly
> chained) which I can then ship to interface output.
> I am willing to write such a function by all means but want to find out if 
> anything like this (or closer) already exists.
> If it doesn't exist, what idioms can I follow from the functions which 
> already exist and what I have to be careful about.
>
> Regards
> -Prashant
-=-=-=-=-=-=-=-=-=-=-=-
Links: You receive all messages sent to this group.

View/Reply Online (#11017): https://lists.fd.io/g/vpp-dev/message/11017
Mute This Topic: https://lists.fd.io/mt/27770677/21656
Group Owner: vpp-dev+ow...@lists.fd.io
Unsubscribe: https://lists.fd.io/g/vpp-dev/unsub  [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-

Reply via email to