PcapPlusPlus  21.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 
128  static bool initDpdk(CoreMask coreMask, uint32_t mBufPoolSizePerDevice, uint8_t masterCore = 0);
129 
135  DpdkDevice* getDeviceByPort(int portId) const;
136 
142  DpdkDevice* getDeviceByPciAddress(const std::string& pciAddr) const;
143 
147  const std::vector<DpdkDevice*>& getDpdkDeviceList() const { return m_DpdkDeviceList; }
148 
152  SystemCore getDpdkMasterCore() const;
153 
158  void setDpdkLogLevel(Logger::LogLevel logLevel);
159 
164  Logger::LogLevel getDpdkLogLevel() const;
165 
171  bool writeDpdkLogToFile(FILE* logFile);
172 
191  bool startDpdkWorkerThreads(CoreMask coreMask, std::vector<DpdkWorkerThread*>& workerThreadsVec);
192 
197  void stopDpdkWorkerThreads();
198  };
199 
200 } // namespace pcpp
201 
202 #endif /* PCAPPP_DPDK_DEVICE_LIST */
The main namespace for the PcapPlusPlus lib.
LogLevel
Definition: Logger.h:100
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:165
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:147