210 int waitForTxCompletionTimeoutMS = 5000);
223 int waitForTxCompletionTimeoutMS = 5000);
238 explicit XdpUmem(uint16_t numFrames, uint16_t frameSize, uint32_t fillRingSize,
239 uint32_t completionRingSize);
243 inline uint16_t getFrameSize()
const
247 inline uint16_t getFrameCount()
const
252 std::pair<bool, std::vector<uint64_t>> allocateFrames(uint32_t count);
254 void freeFrame(uint64_t addr);
256 const uint8_t* getDataPtr(uint64_t addr)
const;
258 void setData(uint64_t addr,
const uint8_t* data,
size_t dataLen);
260 inline size_t getFreeFrameCount()
262 return m_FreeFrames.size();
265 inline void* getInfo()
273 uint16_t m_FrameSize;
274 uint16_t m_FrameCount;
275 std::vector<uint64_t> m_FreeFrames;
278 struct XdpPrevDeviceStats
283 uint64_t txSentPackets;
284 uint64_t txSentBytes;
285 uint64_t txCompletedPackets;
288 std::string m_InterfaceName;
289 XdpDeviceConfiguration* m_Config;
290 bool m_ReceivingPackets;
293 XdpDeviceStats m_Stats;
294 XdpPrevDeviceStats m_PrevStats;
296 bool sendPackets(
const std::function<RawPacket(uint32_t)>& getPacketAt,
297 const std::function<uint32_t()>& getPacketCount,
bool waitForTxCompletion =
false,
298 int waitForTxCompletionTimeoutMS = 5000);
299 bool populateFillRing(uint32_t count, uint32_t rxId = 0);
300 bool populateFillRing(
const std::vector<uint64_t>& addresses, uint32_t rxId);
301 uint32_t checkCompletionRing();
302 bool configureSocket();
305 bool getSocketStats();
Definition: PointerVector.h:50
Definition: RawPacket.h:269
Definition: XdpDevice.h:20
bool receivePackets(OnPacketsArrive onPacketsArrive, void *onPacketsArriveUserCookie, int timeoutMS=5000)
XdpDeviceStats getStatistics()
bool open(const XdpDeviceConfiguration &config)
void close() override
Close the device. This method closes the AF_XDP socket and frees the UMEM that was allocated for it.
bool sendPackets(const RawPacketVector &packets, bool waitForTxCompletion=false, int waitForTxCompletionTimeoutMS=5000)
void stopReceivePackets()
bool sendPackets(RawPacket packets[], size_t packetCount, bool waitForTxCompletion=false, int waitForTxCompletionTimeoutMS=5000)
void(* OnPacketsArrive)(RawPacket packets[], uint32_t packetCount, XdpDevice *device, void *userCookie)
Definition: XdpDevice.h:28
XdpDevice(std::string interfaceName)
XdpDeviceConfiguration * getConfig() const
Definition: XdpDevice.h:226
~XdpDevice() override
A d'tor for this class. It closes the device if it's open.
The main namespace for the PcapPlusPlus lib.
Definition: XdpDevice.h:33
uint16_t umemNumFrames
Definition: XdpDevice.h:52
uint32_t fillRingSize
Definition: XdpDevice.h:61
uint16_t umemFrameSize
Definition: XdpDevice.h:57
AttachMode
Definition: XdpDevice.h:37
@ DriverMode
Use this mode if the network driver has support for XDP.
Definition: XdpDevice.h:42
@ SkbMode
Definition: XdpDevice.h:40
@ AutoMode
Automatically detect whether driver mode is supported, otherwise fallback to SKB mode.
Definition: XdpDevice.h:44
uint32_t txSize
Definition: XdpDevice.h:73
XdpDeviceConfiguration(AttachMode attachMode=AutoMode, uint16_t umemNumFrames=0, uint16_t umemFrameSize=0, uint32_t fillRingSize=0, uint32_t completionRingSize=0, uint32_t rxSize=0, uint32_t txSize=0, uint16_t rxTxBatchSize=0)
Definition: XdpDevice.h:89
uint32_t completionRingSize
Definition: XdpDevice.h:65
uint16_t rxTxBatchSize
The max number of packets to be received or sent in one batch.
Definition: XdpDevice.h:76
uint32_t rxSize
Definition: XdpDevice.h:69
AttachMode attachMode
AF_XDP operation mode.
Definition: XdpDevice.h:48
Definition: XdpDevice.h:108
uint64_t rxDroppedInvalidPackets
RX packets dropped due to invalid descriptor.
Definition: XdpDevice.h:122
timespec timestamp
The timestamp when the stats were collected.
Definition: XdpDevice.h:110
uint64_t rxPackets
Number of packets received.
Definition: XdpDevice.h:112
uint64_t txSentBytes
Number of bytes sent from the application.
Definition: XdpDevice.h:134
uint64_t txRingId
Current TX ring ID.
Definition: XdpDevice.h:146
uint64_t rxRingId
Current RX ring ID.
Definition: XdpDevice.h:144
uint64_t umemAllocatedFrames
Number of UMEM frames that are currently in-use (allocated)
Definition: XdpDevice.h:152
uint64_t txSentBytesPerSec
Bytes per second sent from the app. Measured from to the previous time stats were collected.
Definition: XdpDevice.h:136
uint64_t txDroppedInvalidPackets
TX packets dropped due to invalid descriptor.
Definition: XdpDevice.h:142
uint64_t fqRingId
Current fill ring ID.
Definition: XdpDevice.h:148
uint64_t rxDroppedTotalPackets
Total number of dropped RX packets.
Definition: XdpDevice.h:120
uint64_t rxPacketsPerSec
Packets received per second. Measured from to the previous time stats were collected.
Definition: XdpDevice.h:114
uint64_t rxDroppedRxRingFullPackets
RX packets dropped due to RX ring being full.
Definition: XdpDevice.h:124
uint64_t txCompletedPackets
Number of completed sent packets, meaning packets that were confirmed as sent by the kernel.
Definition: XdpDevice.h:138
uint64_t rxDroppedFillRingPackets
Failed RX packets to retrieve item from fill ring.
Definition: XdpDevice.h:126
uint64_t txCompletedPacketsPerSec
Completed sent packets per second. Measured from to the previous time stats were collected.
Definition: XdpDevice.h:140
uint64_t rxBytesPerSec
Bytes per second received. Measured from to the previous time stats were collected.
Definition: XdpDevice.h:118
uint64_t cqRingId
Current completion ring ID.
Definition: XdpDevice.h:150
uint64_t umemFreeFrames
Number of UMEM frames that are currently free (not allocated)
Definition: XdpDevice.h:154
uint64_t rxBytes
Number of bytes received.
Definition: XdpDevice.h:116
uint64_t txSentPackets
Number of packets sent from the application.
Definition: XdpDevice.h:130
uint64_t rxPollTimeout
Number of poll() timeouts.
Definition: XdpDevice.h:128
uint64_t txSentPacketsPerSec
Packets sent from the app per second. Measured from to the previous time stats were collected.
Definition: XdpDevice.h:132