PcapPlusPlus  23.09
DpdkDeviceList.h
Go to the documentation of this file.
1 #ifndef PCAPPP_DPDK_DEVICE_LIST
2 #define PCAPPP_DPDK_DEVICE_LIST
3 
4 // GCOVR_EXCL_START
5 
6 #include "SystemUtils.h"
7 #include "DpdkDevice.h"
8 #include "Logger.h"
9 #include <vector>
10 
20 namespace pcpp
21 {
22 
34  {
35  public:
39  virtual ~DpdkWorkerThread() {}
40 
46  virtual bool run(uint32_t coreId) = 0;
47 
52  virtual void stop() = 0;
53 
59  virtual uint32_t getCoreId() const = 0;
60  };
61 
62  class KniDeviceList;
63 
74  {
75  friend class KniDeviceList;
76  private:
77  bool m_IsInitialized;
78  static bool m_IsDpdkInitialized;
79  static uint32_t m_MBufPoolSizePerDevice;
80  static CoreMask m_CoreMask;
81  std::vector<DpdkDevice*> m_DpdkDeviceList;
82  std::vector<DpdkWorkerThread*> m_WorkerThreads;
83 
85 
86  bool isInitialized() const { return (m_IsInitialized && m_IsDpdkInitialized); }
87  bool initDpdkDevices(uint32_t mBufPoolSizePerDevice);
88  static bool verifyHugePagesAndDpdkDriver();
89 
90  static int dpdkWorkerThreadStart(void* ptr);
91  public:
92 
93  ~DpdkDeviceList();
94 
101  {
102  static DpdkDeviceList instance;
103  if (!instance.isInitialized())
104  instance.initDpdkDevices(DpdkDeviceList::m_MBufPoolSizePerDevice);
105 
106  return instance;
107  }
108 
132  static bool initDpdk(CoreMask coreMask, uint32_t mBufPoolSizePerDevice, uint8_t masterCore = 0, uint32_t initDpdkArgc = 0, char **initDpdkArgv = NULL, const std::string& appName = "pcapplusplusapp");
133 
139  DpdkDevice* getDeviceByPort(int portId) const;
140 
146  DpdkDevice* getDeviceByPciAddress(const std::string& pciAddr) const;
147 
151  const std::vector<DpdkDevice*>& getDpdkDeviceList() const { return m_DpdkDeviceList; }
152 
156  SystemCore getDpdkMasterCore() const;
157 
162  void setDpdkLogLevel(Logger::LogLevel logLevel);
163 
168  Logger::LogLevel getDpdkLogLevel() const;
169 
175  bool writeDpdkLogToFile(FILE* logFile);
176 
195  bool startDpdkWorkerThreads(CoreMask coreMask, std::vector<DpdkWorkerThread*>& workerThreadsVec);
196 
201  void stopDpdkWorkerThreads();
202  };
203 
204 } // namespace pcpp
205 
206 // GCOVR_EXCL_STOP
207 
208 #endif /* PCAPPP_DPDK_DEVICE_LIST */
The main namespace for the PcapPlusPlus lib.
LogLevel
Definition: Logger.h:112
virtual ~DpdkWorkerThread()
Definition: DpdkDeviceList.h:39
virtual void stop()=0
Definition: SystemUtils.h:27
static DpdkDeviceList & getInstance()
Definition: DpdkDeviceList.h:100
Definition: DpdkDeviceList.h:33
Definition: DpdkDevice.h:169
virtual uint32_t getCoreId() const =0
virtual bool run(uint32_t coreId)=0
Definition: KniDeviceList.h:24
Definition: DpdkDeviceList.h:73
const std::vector< DpdkDevice * > & getDpdkDeviceList() const
Definition: DpdkDeviceList.h:151