bmv2
Designing your own switch target with bmv2
Public Member Functions | List of all members
bm::PacketBuffer Class Reference

Public Member Functions

 PacketBuffer (size_t size, const char *data, size_t data_size)
 

Detailed Description

This acts as a recipient for the packet data. A PacketBuffer instance will belong to a Packet instance and the same PacketBuffer is used to hold 1) the unparsed packet when the packet is first received 2) the packet payload (i.e. data that was not extracted) while the packet is being processed by the match-action tables 3) the deparsed packet ready to be transmitted. As a target switch programmer, you will only encounter PacketBuffer when creating a new Packet instance:

// A new packet was received on port_num, its ingress length is len, we
// assign pkt_id as its packet id (and increment the counter for the next
// incoming packet). We provide a PacketBuffer with capacity 2048 and
// initialize it with the incoming packet data.
auto packet = new_packet_ptr(port_num, pkt_id++, len,
PacketBuffer(2048, buffer, len));

Constructor & Destructor Documentation

◆ PacketBuffer()

bm::PacketBuffer::PacketBuffer ( size_t  size,
const char *  data,
size_t  data_size 
)
inline

Construct a PacketBuffer instance with capacity size, and copy the bytes [data; data + data_size) to the new buffer. The data is actually copied to the end of the buffer. This is because while we never need to append data at the end of a packet, the header size of the outgoing packet may be larger than the header size of the incoming packet. By copying the initial data at the end of the buffer, we preserve space at the beginning of the buffer for potential new headers.

The capacity size of the PacketBuffer needs to be at least as big as data_size. If new headers are going to be added to the pakcet during processing, size needs to be at least as big as the size of the outgoing packet.


The documentation for this class was generated from the following file: