CNDP  22.08.0
txbuff.h File Reference
#include <stdint.h>
#include <cne_common.h>
#include <pktmbuf.h>

Go to the source code of this file.

Data Structures

struct  txbuff
 

Macros

#define TXBUFF_SIZE(sz)   (sizeof(txbuff_t) + (sz) * sizeof(pktmbuf_t *))
 

Typedefs

typedef void(* txbuff_error_fn) (struct txbuff *buffer, uint16_t unsent, uint16_t sent)
 
typedef struct txbuff txbuff_t
 

Enumerations

enum  
 

Functions

CNDP_API txbuff_ttxbuff_pktdev_create (uint16_t size, txbuff_error_fn cbfn, void *cb_arg, uint16_t lport_id)
 
CNDP_API txbuff_ttxbuff_xskdev_create (uint16_t size, txbuff_error_fn cbfn, void *cb_arg, void *xinfo)
 
CNDP_API void txbuff_free (txbuff_t *buffer)
 
CNDP_API int txbuff_set_err_callback (txbuff_t *buffer, txbuff_error_fn callback, void *userdata)
 
CNDP_API void txbuff_drop_callback (txbuff_t *buffer, uint16_t sent, uint16_t unsent)
 
CNDP_API void txbuff_count_callback (txbuff_t *buffer, uint16_t sent, uint16_t unsent)
 
CNDP_API uint16_t txbuff_flush (txbuff_t *buffer)
 
CNDP_API uint16_t txbuff_add (txbuff_t *buffer, pktmbuf_t *tx_pkt)
 
static int txbuff_count (txbuff_t *buffer)
 

Detailed Description

Routines and structures to allow an application to send single mbufs or packets while enqueuing the packets to an array and flush the packets to the output port when the number of packets fills the array.

Using this method allows for buffered packet to be sent in bulk and not one at a time.

Definition in file txbuff.h.

Macro Definition Documentation

◆ TXBUFF_SIZE

#define TXBUFF_SIZE (   sz)    (sizeof(txbuff_t) + (sz) * sizeof(pktmbuf_t *))

Calculate the size of the tx buffer.

Parameters
szNumber of stored packets.

Definition at line 69 of file txbuff.h.

Typedef Documentation

◆ txbuff_error_fn

typedef void(* txbuff_error_fn) (struct txbuff *buffer, uint16_t unsent, uint16_t sent)

Error callback function for txbuff sends.

Parameters
bufferThe txbuff_t pointer.
unsentThe number of unsent packets on a flush call.
sentThe number of sent packets on a flush call.

Definition at line 38 of file txbuff.h.

◆ txbuff_t

typedef struct txbuff txbuff_t

Structure used to buffer packets for future TX Used by APIs txbuff_add and txbuff_flush

Enumeration Type Documentation

◆ anonymous enum

anonymous enum

Types of txbuff transmit routines

Definition at line 61 of file txbuff.h.

Function Documentation

◆ txbuff_pktdev_create()

CNDP_API txbuff_t* txbuff_pktdev_create ( uint16_t  size,
txbuff_error_fn  cbfn,
void *  cb_arg,
uint16_t  lport_id 
)

Initialize default values for buffered transmitting and return txbuff pointer for pktdev

Parameters
sizeBuffer size
cbfnCallback on error function, if null use txbuff_drop_callback().
cb_argArgument for callback function.
lport_idThe lport ID to be used with pktdev_tx_burst() call.
Returns
NULL on error or pointer to structure txbuff
Examples
examples/cndpfwd/main.c, and examples/dlb_test/dlb_test.c.

◆ txbuff_xskdev_create()

CNDP_API txbuff_t* txbuff_xskdev_create ( uint16_t  size,
txbuff_error_fn  cbfn,
void *  cb_arg,
void *  xinfo 
)

Initialize default values for buffered transmitting and return txbuff pointer for xskdev

Parameters
sizeBuffer size
cbfnCallback on error function, if null use txbuff_drop_callback().
cb_argArgument for callback function.
xinfoThe xskdev info pointer, used with xskdev_tx_burst() function
Returns
NULL on error or pointer to structure txbuff
Examples
examples/cndpfwd/main.c.

◆ txbuff_free()

CNDP_API void txbuff_free ( txbuff_t buffer)

Free memory (and any buffered packets) associated with a txbuff

Parameters
bufferPointer to the txbuff structure
Examples
examples/cndpfwd/main.c, and examples/dlb_test/dlb_test.c.

◆ txbuff_set_err_callback()

CNDP_API int txbuff_set_err_callback ( txbuff_t buffer,
txbuff_error_fn  callback,
void *  userdata 
)

Configure a callback for buffered packets which cannot be sent

Register a specific callback to be called when an attempt is made to send all packets buffered on an ethernet lport, but not all packets can successfully be sent. The callback registered here will be called only from calls to txbuff_add() and txbuff_flush() APIs. The callback configured by default just frees the packets back to the original mempool. If additional behaviour is required, for example, to count dropped packets, or to retry transmission of packets which cannot be sent, this function should be used to register a suitable callback function to implement the desired behaviour.

Parameters
bufferPointer to the txbuff structure
callbackThe function to be used as the callback
userdataArbitrary parameter to be passed to the callback function
Returns
0 on success, or -1 on error

◆ txbuff_drop_callback()

CNDP_API void txbuff_drop_callback ( txbuff_t buffer,
uint16_t  sent,
uint16_t  unsent 
)

Callback function for silently dropping unsent buffered packets.

This function can be passed to txbuff_set_err_callback() to adjust the default behavior when buffered packets cannot be sent. This function drops any unsent packets silently and is used by txbuff operations as default behavior.

NOTE: this function should not be called directly, instead it should be used as a callback for packet buffering.

Parameters
bufferPointer to the txbuff structure
sentThe number of sent packets in the pkts array
unsentThe number of unsent packets in the pkts array

◆ txbuff_count_callback()

CNDP_API void txbuff_count_callback ( txbuff_t buffer,
uint16_t  sent,
uint16_t  unsent 
)

Callback function for counting unsent buffered packets.

This function can be passed to txbuff_set_err_callback() to adjust the default behavior when buffered packets cannot be sent. This function drops any unsent packets, but also updates a user-supplied counter to track the overall number of packets dropped. The counter should be an uint64_t variable.

NOTE: this function should not be called directly, instead it should be used as a callback for packet buffering.

NOTE: when configuring this function as a callback with txbuff_set_err_callback(), the final userdata parameter should point to an uint64_t value.

Parameters
bufferPointer to the txbuff structure
sentThe number of sent packets in the pkts array
unsentThe number of unsent packets in the pkts array
Examples
examples/cndpfwd/main.c.

◆ txbuff_flush()

CNDP_API uint16_t txbuff_flush ( txbuff_t buffer)

Send any packets queued up for transmission on a lport and HW queue

This causes an explicit flush of packets previously buffered via the txbuff_add() function. It returns the number of packets successfully sent to the NIC, and calls the error callback for any unsent packets. Unless explicitly set up otherwise, the default callback simply frees the unsent packets back to the original mempool.

Parameters
bufferBuffer of packets to be transmit.
Returns
The number of packets successfully sent to the Ethernet device. The error callback is called for any packets which could not be sent.
Examples
examples/cndpfwd/acl-func.c, and examples/cndpfwd/main.c.

◆ txbuff_add()

CNDP_API uint16_t txbuff_add ( txbuff_t buffer,
pktmbuf_t tx_pkt 
)

Buffer a single packet for future transmission on a lport

This function takes a single mbuf/packet and buffers it for later transmission on the particular lport specified. Once the buffer is full of packets, an attempt will be made to transmit all the buffered packets. In case of error, where not all packets can be transmitted, a callback is called with the unsent packets as a parameter. If no callback is explicitly set up, the unsent packets are just freed back to the owning mempool. The function returns the number of packets actually sent i.e. 0 if no buffer flush occurred, otherwise the number of packets successfully flushed

Parameters
bufferBuffer used to collect packets to be sent.
tx_pktPointer to the packet mbuf to be sent.
Returns
0 = packet has been buffered for later transmission or packets were flushed, but none were transmitted N > 0 = packet has been buffered, and the buffer was subsequently flushed, causing N packets to be sent, and the error callback to be called for the rest.
Examples
examples/cndpfwd/acl-func.c, examples/cndpfwd/main.c, and examples/dlb_test/dlb_test.c.

◆ txbuff_count()

static int txbuff_count ( txbuff_t buffer)
inlinestatic

Return the number of pkts in the txbuff list.

Parameters
bufferThe txbuff_t pointer
Returns
-1 on buffer being NULL or the number of pkts in the list.
Examples
examples/cndpfwd/acl-func.c, and examples/cndpfwd/main.c.

Definition at line 234 of file txbuff.h.