A class that represents an RX/TX Enso Pipe. More...
#include <pipe.h>
Public Member Functions | |
RxTxPipe (const RxTxPipe &)=delete | |
RxTxPipe & | operator= (const RxTxPipe &)=delete |
RxTxPipe (RxTxPipe &&)=delete | |
RxTxPipe & | operator= (RxTxPipe &&)=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. | |
void | ConfirmBytes (uint32_t nb_bytes) |
Confirms a certain number of bytes have been received. | |
template<typename T > | |
RxPipe::MessageBatch< T > | RecvMessages (int32_t max_nb_messages=-1) |
Receives a batch of generic messages. | |
RxPipe::MessageBatch< PktIterator > | RecvPkts (int32_t max_nb_pkts=-1) |
Receives a batch of packets. | |
RxPipe::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 RxTxPipe. | |
void | SendAndFree (uint32_t nb_bytes) |
Sends and deallocates a given number of bytes. | |
void | ProcessCompletions () |
Process completions for this pipe, potentially freeing up space to receive more data. | |
uint8_t * | buf () const |
Returns the pipe's internal buffer. | |
enso_pipe_id_t | rx_id () const |
Return the pipe's RX ID. | |
enso_pipe_id_t | tx_id () const |
Return the pipe's TX 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 = RxPipe::kQuantumSize |
static constexpr uint32_t | kMaxCapacity = RxPipe::kMaxCapacity |
Friends | |
class | Device |
A class that represents an RX/TX Enso Pipe.
This is suitable for applications that need to modify data in place and send them back. Should be instantiated using a Device object.
Different from a TxPipe, an RxTxPipe can only be used to send data that has been received, after potentially modifying it in place. Therefore, it lacks most of the methods that are available in TxPipe.
Example:
|
inline |
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 |
|
inline |
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::NextRxTxPipeToRecv(), the application may use the context to retrieve application data associated with the returned pipe.
|
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. |
|
inline |
Prefetches the next batch of bytes to be received on the RxTxPipe.
NextRxPipeToRecv
and NextRxTxPipeToRecv
functions. These functions only support implicit prefetching, which can be enabled by compiling the library with -Dlatency_opt=true
(the default).
|
inline |
|
inline |
|
inline |
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 |
|
inline |
|
inline |
Sends and deallocates a given number of bytes.
You can only send bytes that have been received and confirmed. Such as using Recv
or a combination of Peek
and ConfirmBytes
, as well as the equivalent methods for raw packets and messages.
nb_bytes | The number of bytes to send. |
|
inline |
Sets the context associated with the pipe.
|
inline |
|
staticconstexpr |
|
staticconstexpr |