PcapPlusPlus  21.05
pcpp::DpdkDeviceList Class Reference

#include <DpdkDeviceList.h>

Public Member Functions

DpdkDevicegetDeviceByPort (int portId) const
 
DpdkDevicegetDeviceByPciAddress (const std::string &pciAddr) const
 
const std::vector< DpdkDevice * > & getDpdkDeviceList () const
 
SystemCore getDpdkMasterCore () const
 
void setDpdkLogLevel (LoggerPP::LogLevel logLevel)
 
LoggerPP::LogLevel getDpdkLogLevel () const
 
bool writeDpdkLogToFile (FILE *logFile)
 
bool startDpdkWorkerThreads (CoreMask coreMask, std::vector< DpdkWorkerThread *> &workerThreadsVec)
 
void stopDpdkWorkerThreads ()
 

Static Public Member Functions

static DpdkDeviceListgetInstance ()
 
static bool initDpdk (CoreMask coreMask, uint32_t mBufPoolSizePerDevice, uint8_t masterCore=0)
 

Detailed Description

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:

  • it contains the initDpdk() static method which initializes the DPDK infrastructure. It should be called once in every application at its startup process
  • it contains the list of DpdkDevice instances and enables access to them
  • it has methods to start and stop worker threads. See more details in startDpdkWorkerThreads()

Member Function Documentation

◆ getDeviceByPciAddress()

DpdkDevice* pcpp::DpdkDeviceList::getDeviceByPciAddress ( const std::string &  pciAddr) const

Get a DpdkDevice by port PCI address

Parameters
[in]pciAddrThe port PCI address
Returns
A pointer to the DpdkDevice or NULL if no such device is found

◆ getDeviceByPort()

DpdkDevice* pcpp::DpdkDeviceList::getDeviceByPort ( int  portId) const

Get a DpdkDevice by port ID

Parameters
[in]portIdThe port ID
Returns
A pointer to the DpdkDevice or NULL if no such device is found

◆ getDpdkDeviceList()

const std::vector<DpdkDevice*>& pcpp::DpdkDeviceList::getDpdkDeviceList ( ) const
inline
Returns
A vector of all DpdkDevice instances

◆ getDpdkLogLevel()

LoggerPP::LogLevel pcpp::DpdkDeviceList::getDpdkLogLevel ( ) const
Returns
The current DPDK log level. RTE_LOG_NOTICE and lower are considered as LoggerPP::Normal. RTE_LOG_INFO or RTE_LOG_DEBUG are considered as LoggerPP::Debug

◆ getDpdkMasterCore()

SystemCore pcpp::DpdkDeviceList::getDpdkMasterCore ( ) const
Returns
DPDK master core which is the core that initializes the application

◆ getInstance()

static DpdkDeviceList& pcpp::DpdkDeviceList::getInstance ( )
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

Returns
The singleton instance of DpdkDeviceList

◆ initDpdk()

static bool pcpp::DpdkDeviceList::initDpdk ( CoreMask  coreMask,
uint32_t  mBufPoolSizePerDevice,
uint8_t  masterCore = 0 
)
static

A static method that has to be called once at the startup of every application that uses DPDK. It does several things:

  • verifies huge-pages are set and DPDK kernel module is loaded (these are set by the setup-dpdk.sh external script that has to be run before application is started)
  • initializes the DPDK infrastructure
  • creates DpdkDevice instances for all ports available for DPDK
Parameters
[in]coreMaskThe 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]mBufPoolSizePerDeviceThe 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]masterCoreThe core DPDK will use as master to control all worker thread. The default, unless set otherwise, is 0
Returns
True if initialization succeeded or false if huge-pages or DPDK kernel driver are not loaded, if mBufPoolSizePerDevice isn't power of 2 minus 1, if DPDK infra initialization failed or if DpdkDevice initialization failed. Anyway, if this method returned false it's impossible to use DPDK with PcapPlusPlus. You can get some more details about mbufs and pools in DpdkDevice.h file description or in DPDK web site

◆ setDpdkLogLevel()

void pcpp::DpdkDeviceList::setDpdkLogLevel ( LoggerPP::LogLevel  logLevel)

Change the log level of all modules of DPDK

Parameters
[in]logLevelThe log level to set. LoggerPP::Normal is RTE_LOG_NOTICE and LoggerPP::Debug is RTE_LOG_DEBUG

◆ startDpdkWorkerThreads()

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() ).

Parameters
[in]coreMaskThe bitmask of cores to run worker threads on. This list shouldn't include DPDK master core
[in]workerThreadsVecA 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
Returns
True if all worker threads started successfully or false if: DPDK isn't initialized (initDpdk() wasn't called or returned false), number of cores differs from number of workers, core mask includes DPDK master core or if one of the worker threads couldn't be run

◆ stopDpdkWorkerThreads()

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

◆ writeDpdkLogToFile()

bool pcpp::DpdkDeviceList::writeDpdkLogToFile ( FILE *  logFile)

Order DPDK to write all its logs to a file

Parameters
[in]logFileThe file to write to
Returns
True if action succeeded, false otherwise