A class that represents an RX Enso Pipe. More...
#include <pipe.h>
Classes | |
class | MessageBatch |
A class that represents a batch of messages. More... | |
Public Member Functions | |
RxPipe (const RxPipe &)=delete | |
RxPipe & | operator= (const RxPipe &)=delete |
RxPipe (RxPipe &&)=delete | |
RxPipe & | operator= (RxPipe &&)=delete |
int | Bind (uint16_t dst_port, uint16_t src_port, uint32_t dst_ip, uint32_t src_ip, uint32_t protocol) |
Binds the pipe to a given flow entry. Can be called multiple times to bind to multiple flows. | |
uint32_t | Recv (uint8_t **buf, uint32_t max_nb_bytes) |
Receives a batch of bytes. | |
uint32_t | Peek (uint8_t **buf, uint32_t max_nb_bytes) |
Receives a batch of bytes without removing them from the queue. | |
constexpr void | ConfirmBytes (uint32_t nb_bytes) |
Confirms a certain number of bytes have been received. | |
constexpr uint32_t | capacity () const |
Returns the number of bytes allocated in the pipe, i.e., the number of bytes owned by the application. | |
template<typename T > | |
constexpr MessageBatch< T > | RecvMessages (int32_t max_nb_messages=-1) |
Receives a batch of generic messages. | |
MessageBatch< PktIterator > | RecvPkts (int32_t max_nb_pkts=-1) |
Receives a batch of packets. | |
MessageBatch< PeekPktIterator > | PeekPkts (int32_t max_nb_pkts=-1) |
Receives a batch of packets without removing them from the queue. | |
void | Prefetch () |
Prefetches the next batch of bytes to be received on the RxPipe. | |
void | Free (uint32_t nb_bytes) |
Frees a given number of bytes previously received on the RxPipe. | |
void | Clear () |
Frees all bytes previously received on the RxPipe. | |
uint8_t * | buf () const |
Returns the pipe's internal buffer. | |
enso_pipe_id_t | id () const |
Returns the pipe's ID. | |
void * | context () const |
Returns the context associated with the pipe. | |
void | set_context (void *new_context) |
Sets the context associated with the pipe. | |
Static Public Attributes | |
static constexpr uint32_t | kQuantumSize = 64 |
static constexpr uint32_t | kMaxCapacity = kEnsoPipeSize * 64 - kQuantumSize |
Friends | |
class | Device |
A class that represents an RX Enso Pipe.
Should be instantiated using a Device object.
Example:
int enso::RxPipe::Bind | ( | uint16_t | dst_port, |
uint16_t | src_port, | ||
uint32_t | dst_ip, | ||
uint32_t | src_ip, | ||
uint32_t | protocol | ||
) |
Binds the pipe to a given flow entry. Can be called multiple times to bind to multiple flows.
While binding semantics will vary for different NIC implementations, here we describe how the NIC implementation that accompanies Enso behaves.
Every call to Bind()
will result in a new flow entry being created on the NIC using all the fields specified in the function arguments (5-tuple). For every incoming packet, the NIC will try to find a matching flow entry. If it does, it will steer the packet to the corresponding RX pipe. If it does not, it will steer the packet to one of the fallback pipes, or dropped if there are no fallback pipes.
The fields that are used to find a matching entry depend on the incoming packet:
6
):17
), the NIC will use only dst IP, dst port, and protocol when looking for a matching flow entry. All the other fields will be set to 0.Therefore, if you want to listen for new TCP connections, you should bind to the destination IP and port and set all the other fields to 0. If you want to receive packets from an open TCP connection, you should bind to all the fields, i.e., dst IP, dst port, src IP, src port, and protocol. If you want to receive UDP packets, you should bind to the destination IP and port and set all the other fields to 0.
dst_port | Destination port (little-endian). |
src_port | Source port (little-endian). |
dst_ip | Destination IP (little-endian). |
src_ip | Source IP (little-endian). |
protocol | Protocol (little-endian). |
|
inline |
|
inlineconstexpr |
void enso::RxPipe::Clear | ( | ) |
|
inlineconstexpr |
Confirms a certain number of bytes have been received.
This will make sure that the next call to Recv
or Peek
will return a buffer that starts at the next byte after the last confirmed byte.
When using Recv
, this is not necessary, as Recv
will automatically confirm the bytes received. You may use this to confirm bytes received by Peek
.
nb_bytes | The number of bytes to confirm (must be a multiple of 64). |
|
inline |
Returns the context associated with the pipe.
Applications can use context to associate arbitrary pointers with a given pipe that can later be retrieved in a different point. For instance, when using Device::NextRxPipeToRecv(), the application may use the context to retrieve application data associated with the returned pipe.
void enso::RxPipe::Free | ( | uint32_t | nb_bytes | ) |
|
inline |
|
inline |
|
inline |
Receives a batch of packets without removing them from the queue.
max_nb_pkts | The maximum number of packets to receive. If set to -1, all packets in the pipe will be received. |
void enso::RxPipe::Prefetch | ( | ) |
Prefetches the next batch of bytes to be received on the RxPipe.
NextRxPipeToRecv
and NextRxTxPipeToRecv
functions. These functions only support implicit prefetching, which can be enabled by compiling the library with -Dlatency_opt=true
(the default). uint32_t enso::RxPipe::Recv | ( | uint8_t ** | buf, |
uint32_t | max_nb_bytes | ||
) |
|
inlineconstexpr |
Receives a batch of generic messages.
T | An iterator for the particular message type. Refer to enso::PktIterator for an example of a raw packet iterator. |
max_nb_messages | The maximum number of messages to receive. If set to -1, all messages in the pipe will be received. |
|
inline |
Receives a batch of packets.
max_nb_pkts | The maximum number of packets to receive. If set to -1, all packets in the pipe will be received. |
|
inline |
Sets the context associated with the pipe.
|
staticconstexpr |
|
staticconstexpr |