PcapPlusPlus
Next
|
#include <DpdkDeviceList.h>
Public Member Functions | |
DpdkDevice * | getDeviceByPort (int portId) const |
DpdkDevice * | getDeviceByPciAddress (const std::string &pciAddr) const |
const std::vector< DpdkDevice * > & | getDpdkDeviceList () const |
SystemCore | getDpdkMasterCore () const |
void | setDpdkLogLevel (Logger::LogLevel logLevel) |
Logger::LogLevel | getDpdkLogLevel () const |
bool | writeDpdkLogToFile (FILE *logFile) |
bool | startDpdkWorkerThreads (CoreMask coreMask, std::vector< DpdkWorkerThread * > &workerThreadsVec) |
void | stopDpdkWorkerThreads () |
Static Public Member Functions | |
static DpdkDeviceList & | getInstance () |
static bool | initDpdk (CoreMask coreMask, uint32_t mBufPoolSizePerDevice, uint16_t mBufDataSize=0, uint8_t masterCore=0, uint32_t initDpdkArgc=0, char **initDpdkArgv=nullptr, const std::string &appName="pcapplusplusapp", bool verifyHugePagesAndDriver=true) |
A singleton class that encapsulates DPDK initialization and holds the list of DpdkDevice instances. As it's a singleton, it has only one active instance doesn't have a public c'tor. This class has several main uses:
DpdkDevice* pcpp::DpdkDeviceList::getDeviceByPciAddress | ( | const std::string & | pciAddr | ) | const |
Get a DpdkDevice by port PCI address
[in] | pciAddr | The port PCI address |
DpdkDevice* pcpp::DpdkDeviceList::getDeviceByPort | ( | int | portId | ) | const |
Get a DpdkDevice by port ID
[in] | portId | The port ID |
|
inline |
Logger::LogLevel pcpp::DpdkDeviceList::getDpdkLogLevel | ( | ) | const |
SystemCore pcpp::DpdkDeviceList::getDpdkMasterCore | ( | ) | const |
|
inlinestatic |
As DpdkDeviceList is a singleton, this is the static getter to retrieve its instance. Note that if the static method initDpdk() was not called or returned false this instance won't be initialized and DpdkDevices won't be initialized either
|
static |
A static method that has to be called once at the startup of every application that uses DPDK. It does several things:
[in] | coreMask | The cores to initialize DPDK with. After initialization, DPDK will only be able to use these cores for its work. The core mask should have a bit set for every core to use. For example: if the user want to use cores 1,2 the core mask should be 6 (binary: 110) |
[in] | mBufPoolSizePerDevice | The mbuf pool size each DpdkDevice will have. This has to be a number which is a power of 2 minus 1, for example: 1023 (= 2^10-1) or 4,294,967,295 (= 2^32-1), etc. This is a DPDK limitation, not PcapPlusPlus. The size of the mbuf pool size dictates how many packets can be handled by the application at the same time. For example: if pool size is 1023 it means that no more than 1023 packets can be handled or stored in application memory at every point in time |
[in] | mBufDataSize | The size of data buffer in each mbuf. If this value is less than 1, we will use RTE_MBUF_DEFAULT_BUF_SIZE. |
[in] | masterCore | The core DPDK will use as master to control all worker thread. The default, unless set otherwise, is 0 |
[in] | initDpdkArgc | Number of optional arguments |
[in] | initDpdkArgv | Optional arguments |
[in] | appName | Program name to be provided for the DPDK |
[in] | verifyHugePagesAndDriver | Verify huge-pages are set and DPDK kernel module is loaded. The default value it true |
void pcpp::DpdkDeviceList::setDpdkLogLevel | ( | Logger::LogLevel | logLevel | ) |
Change the log level of all modules of DPDK
[in] | logLevel | The log level to set. Logger::Info is RTE_LOG_NOTICE and Logger::Debug is RTE_LOG_DEBUG |
bool pcpp::DpdkDeviceList::startDpdkWorkerThreads | ( | CoreMask | coreMask, |
std::vector< DpdkWorkerThread * > & | workerThreadsVec | ||
) |
There are two ways to capture packets using DpdkDevice: one of them is using worker threads and the other way is setting a callback which is invoked each time a burst of packets is captured (see DpdkDevice::startCaptureSingleThread() ). This method implements the first way. See a detailed description of workers in DpdkWorkerThread class description. This method gets a vector of workers (classes that implement the DpdkWorkerThread interface) and a core mask and starts a worker thread on each core (meaning - call the worker's DpdkWorkerThread::run() method). Workers usually run in an endless loop and will be ordered to stop by calling stopDpdkWorkerThreads().
Note that number of cores in the core mask must be equal to the number of workers. In addition it's impossible to run a worker thread on DPDK master core, so the core mask shouldn't include the master core (you can find the master core by calling getDpdkMasterCore() ).
[in] | coreMask | The bitmask of cores to run worker threads on. This list shouldn't include DPDK master core |
[in] | workerThreadsVec | A vector of worker instances to run (classes who implement the DpdkWorkerThread interface). Number of workers in this vector must be equal to the number of cores in the core mask. Notice that the instances of DpdkWorkerThread shouldn't be freed until calling stopDpdkWorkerThreads() as these instances are running |
void pcpp::DpdkDeviceList::stopDpdkWorkerThreads | ( | ) |
Assuming worker threads are running, this method orders them to stop by calling DpdkWorkerThread::stop(). Then it waits until they stop running
bool pcpp::DpdkDeviceList::writeDpdkLogToFile | ( | FILE * | logFile | ) |
Order DPDK to write all its logs to a file
[in] | logFile | The file to write to |