PcapPlusPlus
Next
|
#include <XdpDevice.h>
Classes | |
struct | XdpDeviceConfiguration |
struct | XdpDeviceStats |
Public Types | |
typedef void(* | OnPacketsArrive) (RawPacket packets[], uint32_t packetCount, XdpDevice *device, void *userCookie) |
Public Member Functions | |
XdpDevice (std::string interfaceName) | |
~XdpDevice () override | |
bool | open () override |
bool | open (const XdpDeviceConfiguration &config) |
void | close () override |
bool | receivePackets (OnPacketsArrive onPacketsArrive, void *onPacketsArriveUserCookie, int timeoutMS=5000) |
void | stopReceivePackets () |
bool | sendPackets (const RawPacketVector &packets, bool waitForTxCompletion=false, int waitForTxCompletionTimeoutMS=5000) |
bool | sendPackets (RawPacket packets[], size_t packetCount, bool waitForTxCompletion=false, int waitForTxCompletionTimeoutMS=5000) |
XdpDeviceConfiguration * | getConfig () const |
XdpDeviceStats | getStatistics () |
Public Member Functions inherited from pcpp::IDevice | |
bool | isOpened () |
A class wrapping the main functionality of using AF_XDP (XSK) sockets which are optimized for high performance packet processing.
It provides methods for configuring and initializing an AF_XDP socket, and then send and receive packets through it. It also provides a method for gathering statistics from the socket.
pcpp::XdpDevice::OnPacketsArrive |
The callback that is called whenever packets are received on the socket
[in] | packets | An array of the raw packets received |
[in] | packetCount | The number of packets received |
[in] | device | The XdpDevice packets are received from (represents the AF_XDP socket) |
[in] | userCookie | A pointer to an object set by the user when receivePackets() started |
|
explicit |
A c'tor for this class. Please note that calling this c'tor doesn't initialize the AF_XDP socket. In order to set up the socket call open().
[in] | interfaceName | The interface name to open the AF_XDP socket on |
|
override |
A d'tor for this class. It closes the device if it's open.
|
overridevirtual |
Close the device. This method closes the AF_XDP socket and frees the UMEM that was allocated for it.
Implements pcpp::IDevice.
|
inline |
XdpDeviceStats pcpp::XdpDevice::getStatistics | ( | ) |
|
overridevirtual |
Open the device with default configuration. Call getConfig() after opening the device to get the current configuration. This method initializes the UMEM, and then creates and configures the AF_XDP socket. If it succeeds the socket is ready to receive and send packets.
Implements pcpp::IDevice.
bool pcpp::XdpDevice::open | ( | const XdpDeviceConfiguration & | config | ) |
Open the device with custom configuration set by the user. This method initializes the UMEM, and then creates and configures the AF_XDP socket. If it succeeds the socket is ready to receive and send packets.
[in] | config | The configuration to use for opening the device |
bool pcpp::XdpDevice::receivePackets | ( | OnPacketsArrive | onPacketsArrive, |
void * | onPacketsArriveUserCookie, | ||
int | timeoutMS = 5000 |
||
) |
Start receiving packets. In order to use this method the device should be open. Note that this method is blocking and will return if:
[in] | onPacketsArrive | A callback to be called when packets are received |
[in] | onPacketsArriveUserCookie | The callback is invoked with this cookie as a parameter. It can be used to pass information from the user application to the callback |
[in] | timeoutMS | Timeout in milliseconds to stop if no packets are received. The default value is 5000 ms |
bool pcpp::XdpDevice::sendPackets | ( | const RawPacketVector & | packets, |
bool | waitForTxCompletion = false , |
||
int | waitForTxCompletionTimeoutMS = 5000 |
||
) |
Send a vector of packet pointers.
[in] | packets | A vector of packet pointers to send |
[in] | waitForTxCompletion | Wait for confirmation from the kernel that packets were sent. If set to true this method will wait until the number of packets in the completion ring is equal or greater to the number of packets that were sent. The default value is false |
[in] | waitForTxCompletionTimeoutMS | If waitForTxCompletion is set to true, poll the completion ring with this timeout. The default value is 5000 ms |
bool pcpp::XdpDevice::sendPackets | ( | RawPacket | packets[], |
size_t | packetCount, | ||
bool | waitForTxCompletion = false , |
||
int | waitForTxCompletionTimeoutMS = 5000 |
||
) |
Send an array of packets.
[in] | packets | An array of raw packets to send |
[in] | packetCount | The length of the packet array |
[in] | waitForTxCompletion | Wait for confirmation from the kernel that packets were sent. If set to true this method will wait until the number of packets in the completion ring is equal or greater to the number of packets sent. The default value is false |
[in] | waitForTxCompletionTimeoutMS | If waitForTxCompletion is set to true, poll the completion ring with this timeout. The default value is 5000 ms |
void pcpp::XdpDevice::stopReceivePackets | ( | ) |
Stop receiving packets. Call this method from within the callback passed to receivePackets() whenever you want to stop receiving packets.