PcapPlusPlus  22.11
DpdkDeviceList.h
Go to the documentation of this file.
1 #ifndef PCAPPP_DPDK_DEVICE_LIST
2 #define PCAPPP_DPDK_DEVICE_LIST
3 
4 #include "SystemUtils.h"
5 #include "DpdkDevice.h"
6 #include "Logger.h"
7 #include <vector>
8 
18 namespace pcpp
19 {
20 
32  {
33  public:
37  virtual ~DpdkWorkerThread() {}
38 
44  virtual bool run(uint32_t coreId) = 0;
45 
51  virtual void stop() = 0;
52 
58  virtual uint32_t getCoreId() const = 0;
59  };
60 
61  class KniDeviceList;
62 
73  {
74  friend class KniDeviceList;
75  private:
76  bool m_IsInitialized;
77  static bool m_IsDpdkInitialized;
78  static uint32_t m_MBufPoolSizePerDevice;
79  static CoreMask m_CoreMask;
80  std::vector<DpdkDevice*> m_DpdkDeviceList;
81  std::vector<DpdkWorkerThread*> m_WorkerThreads;
82 
84 
85  bool isInitialized() const { return (m_IsInitialized && m_IsDpdkInitialized); }
86  bool initDpdkDevices(uint32_t mBufPoolSizePerDevice);
87  static bool verifyHugePagesAndDpdkDriver();
88 
89  static int dpdkWorkerThreadStart(void* ptr);
90  public:
91 
92  ~DpdkDeviceList();
93 
100  {
101  static DpdkDeviceList instance;
102  if (!instance.isInitialized())
103  instance.initDpdkDevices(DpdkDeviceList::m_MBufPoolSizePerDevice);
104 
105  return instance;
106  }
107 
130  static bool initDpdk(CoreMask coreMask, uint32_t mBufPoolSizePerDevice, uint8_t masterCore = 0, uint32_t initDpdkArgc = 0, char **initDpdkArgv = NULL);
131 
137  DpdkDevice* getDeviceByPort(int portId) const;
138 
144  DpdkDevice* getDeviceByPciAddress(const std::string& pciAddr) const;
145 
149  const std::vector<DpdkDevice*>& getDpdkDeviceList() const { return m_DpdkDeviceList; }
150 
154  SystemCore getDpdkMasterCore() const;
155 
160  void setDpdkLogLevel(Logger::LogLevel logLevel);
161 
166  Logger::LogLevel getDpdkLogLevel() const;
167 
173  bool writeDpdkLogToFile(FILE* logFile);
174 
193  bool startDpdkWorkerThreads(CoreMask coreMask, std::vector<DpdkWorkerThread*>& workerThreadsVec);
194 
199  void stopDpdkWorkerThreads();
200  };
201 
202 } // namespace pcpp
203 
204 #endif /* PCAPPP_DPDK_DEVICE_LIST */
The main namespace for the PcapPlusPlus lib.
LogLevel
Definition: Logger.h:110
virtual ~DpdkWorkerThread()
Definition: DpdkDeviceList.h:37
virtual void stop()=0
Definition: SystemUtils.h:27
static DpdkDeviceList & getInstance()
Definition: DpdkDeviceList.h:99
Definition: DpdkDeviceList.h:31
Definition: DpdkDevice.h:167
virtual uint32_t getCoreId() const =0
virtual bool run(uint32_t coreId)=0
Definition: KniDeviceList.h:22
Definition: DpdkDeviceList.h:72
const std::vector< DpdkDevice * > & getDpdkDeviceList() const
Definition: DpdkDeviceList.h:149