PcapPlusPlus  Next
DpdkDeviceList.h
Go to the documentation of this file.
1 #pragma once
2 
3 // GCOVR_EXCL_START
4 
5 #include "SystemUtils.h"
6 #include "DpdkDevice.h"
7 #include "DeviceListBase.h"
8 #include "Logger.h"
9 #include <vector>
10 
13 
16 namespace pcpp
17 {
28  {
29  public:
31  virtual ~DpdkWorkerThread() = default;
32 
37  virtual bool run(uint32_t coreId) = 0;
38 
41  virtual void stop() = 0;
42 
46  virtual uint32_t getCoreId() const = 0;
47  };
48 
49  class KniDeviceList;
50 
59  {
60  friend class KniDeviceList;
61 
62  private:
64 
65  bool m_IsInitialized;
66  static bool m_IsDpdkInitialized;
67  static uint32_t m_MBufPoolSizePerDevice;
68  static uint16_t m_MBufDataSize;
69  static CoreMask m_CoreMask;
70  std::vector<DpdkDevice*> m_DpdkDeviceListView;
71  std::vector<DpdkWorkerThread*> m_WorkerThreads;
72 
74 
75  bool isInitialized() const
76  {
77  return (m_IsInitialized && m_IsDpdkInitialized);
78  }
79  bool initDpdkDevices(uint32_t mBufPoolSizePerDevice, uint16_t mMbufDataSize);
80  static bool verifyHugePagesAndDpdkDriver();
81 
82  static int dpdkWorkerThreadStart(void* ptr);
83 
84  public:
85  ~DpdkDeviceList();
86 
92  {
93  static DpdkDeviceList instance;
94  if (!instance.isInitialized())
95  instance.initDpdkDevices(DpdkDeviceList::m_MBufPoolSizePerDevice, DpdkDeviceList::m_MBufDataSize);
96 
97  return instance;
98  }
99 
128  static bool initDpdk(CoreMask coreMask, uint32_t mBufPoolSizePerDevice, uint16_t mBufDataSize = 0,
129  uint8_t masterCore = 0, uint32_t initDpdkArgc = 0, char** initDpdkArgv = nullptr,
130  const std::string& appName = "pcapplusplusapp", bool verifyHugePagesAndDriver = true);
131 
135  DpdkDevice* getDeviceByPort(int portId) const;
136 
140  DpdkDevice* getDeviceByPciAddress(const std::string& pciAddr) const;
141 
143  const std::vector<DpdkDevice*>& getDpdkDeviceList() const
144  {
145  return m_DpdkDeviceListView;
146  }
147 
150 
154 
158 
162  bool writeDpdkLogToFile(FILE* logFile);
163 
182  bool startDpdkWorkerThreads(CoreMask coreMask, std::vector<DpdkWorkerThread*>& workerThreadsVec);
183 
187  };
188 
189 } // namespace pcpp
190 
191 // GCOVR_EXCL_STOP
Definition: DpdkDevice.h:168
Definition: DpdkDeviceList.h:59
SystemCore getDpdkMasterCore() const
const std::vector< DpdkDevice * > & getDpdkDeviceList() const
Definition: DpdkDeviceList.h:143
DpdkDevice * getDeviceByPort(int portId) const
bool startDpdkWorkerThreads(CoreMask coreMask, std::vector< DpdkWorkerThread * > &workerThreadsVec)
static DpdkDeviceList & getInstance()
Definition: DpdkDeviceList.h:91
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)
Logger::LogLevel getDpdkLogLevel() const
DpdkDevice * getDeviceByPciAddress(const std::string &pciAddr) const
void setDpdkLogLevel(Logger::LogLevel logLevel)
bool writeDpdkLogToFile(FILE *logFile)
Definition: DpdkDeviceList.h:28
virtual uint32_t getCoreId() const =0
virtual void stop()=0
virtual ~DpdkWorkerThread()=default
A virtual d'tor. Can be overridden by child class if needed.
virtual bool run(uint32_t coreId)=0
Definition: KniDeviceList.h:19
A base class for device lists, providing common functionality for managing a list of devices.
Definition: DeviceListBase.h:10
The main namespace for the PcapPlusPlus lib.
LogLevel
Definition: Logger.h:146
Definition: SystemUtils.h:29