Template Class EthRxTx

Template Parameter Order

  1. class opts

Class Documentation

template<class opts>
class EthRxTx

This class is responsible for transmitting and receiving packets from the NIC.

The network card specified by device_name is initialized in the constructor.

Template Parameters:

opts – is used to pass compilation options to the class, see eth_rxtx_opts.h

Public Functions

EthRxTx(const EthRxTx&) = delete
EthRxTx &operator=(const EthRxTx&) = delete
EthRxTx &operator=(EthRxTx &&other) = delete
inline EthRxTx(EthRxTx &&other)
~EthRxTx()

Destroy the Eth Rx Tx object.

template<typename Elem, size_t Size>
inline std::pair<uint16_t, RTEMbufArray<Elem, Size, MbufType::Pkt>> SendPackets(const uint16_t queue_id, RTEMbufArray<Elem, Size, MbufType::Pkt> &&pkts)

Send packets to a specific TX queue.

This function transmits a maximum of num_pkts, can be less. InsertPktOlFlags and PreparePackets must be called on all packets first

Parameters:
  • queue_id – The TX queue id to transmit packets on

  • pkts – An array of rte_mbuf pointers that contain the packets to be transmitted

  • num_pkts – Number of packets to send

Returns:

uint16_t Number of packets transmitted

template<typename Elem>
inline uint16_t SendPacket(const uint16_t queue_id, RTEMbufElement<Elem, MbufType::Pkt> &&pkt)
template<size_t Size>
inline RTEMbufArray<DefaultPacket, Size, MbufType::Pkt> RcvPackets(const uint16_t queue_id)

Receive packets from a specified RX queue.

Receive as much packets as possible from the specified RX queue. On a RX IP checksum error RTE_MBUF_F_TX_IP_CKSUM will be set in the packet ol_flags, on an invalid UDP checksum RTE_MBUF_F_TX_UDP_CKSUM will be set.

Parameters:
  • queue_id – The RX queue to receive packets from

  • pkts – An array of rte_mbuf pointers that will contain the pointers to the received packets

  • max_rcv – The maximum number of packets to receive

Returns:

uint16_t

template<typename Elem, size_t Size>
inline void PreparePackets(const uint16_t queue_id, RTEMbufArray<Elem, Size, MbufType::Pkt> &to_prepare)

Prepares the packets for transmit.

Parameters:
  • queue_id – The TX queue id to transmit packets on

  • pkts – An array of rte_mbuf pointers that contain the packets to be transmitted

  • num_pkts – Number of packets to send

Returns:

uint16_t Number of packets prepared, equal to num_pkts without errors

inline rte_ether_addr GetMacAddr()

Get the Mac address of the interface.

Returns:

rte_ether_addr

tl::expected<void, std::string> GenerateDNSFlow(uint16_t queue_id, uint16_t src_port, uint16_t src_mask, uint16_t dst_port, uint16_t dst_mask, uint16_t dns_id, uint16_t dns_id_mask)

Generates a receive queue flow based on UDP src/dst ports and DNS id for both Ipv4 and Ipv6.

This function uses rte_flow to direct packets that match the specified UDP src/dest ports and the specified DNS id.

The mask for the UDP ports can either be 0x0000 or 0xFFFF and cannot be set per bit. 0xFFFF matches the exact UDP port in this case, 0x0000 ignores the port setting

The DNS id can be matched per bit based on the mask and id settings

Parameters:
  • queue_id – The RX queue id to direct packets to

  • src_port – UDP source port to match based on src_mask

  • src_mask – Mask for UDP source port (either 0 or 0xFFFF)

  • dst_port – UDP destination port to match based on src_mask

  • dst_mask – Mask for UDP destination port (either 0 or 0xFFFF)

  • dns_id – DNS id to match based on dns_id_mask

  • dns_id_mask – DNS id mask, can be set per bit

void PrintStats()

Print the total statistics of the ethernet device.

inline uint16_t GetPortId() const

Public Static Functions

static tl::expected<EthRxTx, std::string> init(const EthDevConf &config, std::string_view device_name, rte_mempool *mempool)

Construct a new Eth Rx Tx object and initialize the device.

The constructor will throw an exception when the device initialisation cannot be completed or any of the rx/tx offloads is not available

Parameters:
  • config – Configuration structure for the class

  • device_name – PCI device name, 0000:06:00.0 for example

  • pool_size – Size of the mempool backing the device

template<typename Elem, L3Type l3_type, L4Type l4_type>
static inline void PreparePktCksums(RTEMbuf<Elem> &pkt)

Prepares the packets with correct checksum data.

Inserts the correct offload flags into the packet based on opts, the required flags are calculated in compile-time When the offload is not assigned to hardware the

Template Parameters:
  • l3_type – Specify the layer 3 type of the packet, see L3Type

  • l4_type – Specify the layer 4 type of the packet, see L4Type

Parameters:

pkt