185 return m_DeviceOpened;
216 int waitForTxCompletionTimeoutMS = 5000);
229 int waitForTxCompletionTimeoutMS = 5000);
235 return m_Config.get();
245 explicit XdpUmem(uint16_t numFrames, uint16_t frameSize, uint32_t fillRingSize,
246 uint32_t completionRingSize);
250 inline uint16_t getFrameSize()
const
254 inline uint16_t getFrameCount()
const
259 std::pair<bool, std::vector<uint64_t>> allocateFrames(uint32_t count);
261 void freeFrame(uint64_t addr);
263 const uint8_t* getDataPtr(uint64_t addr)
const;
265 void setData(uint64_t addr,
const uint8_t* data,
size_t dataLen);
267 inline size_t getFreeFrameCount()
269 return m_FreeFrames.size();
272 inline void* getInfo()
280 uint16_t m_FrameSize;
281 uint16_t m_FrameCount;
282 std::vector<uint64_t> m_FreeFrames;
285 struct XdpPrevDeviceStats
290 uint64_t txSentPackets;
291 uint64_t txSentBytes;
292 uint64_t txCompletedPackets;
295 bool m_DeviceOpened =
false;
297 std::string m_InterfaceName;
298 std::unique_ptr<XdpDeviceConfiguration> m_Config;
299 bool m_ReceivingPackets;
302 XdpDeviceStats m_Stats;
303 XdpPrevDeviceStats m_PrevStats;
305 bool sendPackets(
const std::function<RawPacket(uint32_t)>& getPacketAt,
306 const std::function<uint32_t()>& getPacketCount,
bool waitForTxCompletion =
false,
307 int waitForTxCompletionTimeoutMS = 5000);
308 bool populateFillRing(uint32_t count, uint32_t rxId = 0);
309 bool populateFillRing(
const std::vector<uint64_t>& addresses, uint32_t rxId);
310 uint32_t checkCompletionRing();
311 bool configureSocket();
313 bool populateConfigDefaults(XdpDeviceConfiguration& config)
const;
314 bool getSocketStats();
Definition: PointerVector.h:50
Definition: RawPacket.h:259
Definition: XdpDevice.h:21
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 isOpened() const override
Definition: XdpDevice.h:183
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:29
XdpDevice(std::string interfaceName)
XdpDeviceConfiguration * getConfig() const
Definition: XdpDevice.h:232
~XdpDevice() override
A d'tor for this class. It closes the device if it's open.
The main namespace for the PcapPlusPlus lib.
Definition: AssertionUtils.h:19
Definition: XdpDevice.h:34
uint16_t umemNumFrames
Definition: XdpDevice.h:53
uint32_t fillRingSize
Definition: XdpDevice.h:62
uint16_t umemFrameSize
Definition: XdpDevice.h:58
AttachMode
Definition: XdpDevice.h:38
@ DriverMode
Use this mode if the network driver has support for XDP.
Definition: XdpDevice.h:43
@ SkbMode
Definition: XdpDevice.h:41
@ AutoMode
Automatically detect whether driver mode is supported, otherwise fallback to SKB mode.
Definition: XdpDevice.h:45
uint32_t txSize
Definition: XdpDevice.h:74
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:90
uint32_t completionRingSize
Definition: XdpDevice.h:66
uint16_t rxTxBatchSize
The max number of packets to be received or sent in one batch.
Definition: XdpDevice.h:77
uint32_t rxSize
Definition: XdpDevice.h:70
AttachMode attachMode
AF_XDP operation mode.
Definition: XdpDevice.h:49
Definition: XdpDevice.h:109
uint64_t rxDroppedInvalidPackets
RX packets dropped due to invalid descriptor.
Definition: XdpDevice.h:123
timespec timestamp
The timestamp when the stats were collected.
Definition: XdpDevice.h:111
uint64_t rxPackets
Number of packets received.
Definition: XdpDevice.h:113
uint64_t txSentBytes
Number of bytes sent from the application.
Definition: XdpDevice.h:135
uint64_t txRingId
Current TX ring ID.
Definition: XdpDevice.h:147
uint64_t rxRingId
Current RX ring ID.
Definition: XdpDevice.h:145
uint64_t umemAllocatedFrames
Number of UMEM frames that are currently in-use (allocated)
Definition: XdpDevice.h:153
uint64_t txSentBytesPerSec
Bytes per second sent from the app. Measured from to the previous time stats were collected.
Definition: XdpDevice.h:137
uint64_t txDroppedInvalidPackets
TX packets dropped due to invalid descriptor.
Definition: XdpDevice.h:143
uint64_t fqRingId
Current fill ring ID.
Definition: XdpDevice.h:149
uint64_t rxDroppedTotalPackets
Total number of dropped RX packets.
Definition: XdpDevice.h:121
uint64_t rxPacketsPerSec
Packets received per second. Measured from to the previous time stats were collected.
Definition: XdpDevice.h:115
uint64_t rxDroppedRxRingFullPackets
RX packets dropped due to RX ring being full.
Definition: XdpDevice.h:125
uint64_t txCompletedPackets
Number of completed sent packets, meaning packets that were confirmed as sent by the kernel.
Definition: XdpDevice.h:139
uint64_t rxDroppedFillRingPackets
Failed RX packets to retrieve item from fill ring.
Definition: XdpDevice.h:127
uint64_t txCompletedPacketsPerSec
Completed sent packets per second. Measured from to the previous time stats were collected.
Definition: XdpDevice.h:141
uint64_t rxBytesPerSec
Bytes per second received. Measured from to the previous time stats were collected.
Definition: XdpDevice.h:119
uint64_t cqRingId
Current completion ring ID.
Definition: XdpDevice.h:151
uint64_t umemFreeFrames
Number of UMEM frames that are currently free (not allocated)
Definition: XdpDevice.h:155
uint64_t rxBytes
Number of bytes received.
Definition: XdpDevice.h:117
uint64_t txSentPackets
Number of packets sent from the application.
Definition: XdpDevice.h:131
uint64_t rxPollTimeout
Number of poll() timeouts.
Definition: XdpDevice.h:129
uint64_t txSentPacketsPerSec
Packets sent from the app per second. Measured from to the previous time stats were collected.
Definition: XdpDevice.h:133