PcapPlusPlus  20.08
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 
50  virtual void stop() = 0;
51 
57  virtual uint32_t getCoreId() const = 0;
58  };
59 
60  class KniDeviceList;
61 
72  {
73  friend class KniDeviceList;
74  private:
75  bool m_IsInitialized;
76  static bool m_IsDpdkInitialized;
77  static uint32_t m_MBufPoolSizePerDevice;
78  static CoreMask m_CoreMask;
79  std::vector<DpdkDevice*> m_DpdkDeviceList;
80  std::vector<DpdkWorkerThread*> m_WorkerThreads;
81 
83 
84  bool isInitialized() const { return (m_IsInitialized && m_IsDpdkInitialized); }
85  bool initDpdkDevices(uint32_t mBufPoolSizePerDevice);
86  static bool verifyHugePagesAndDpdkDriver();
87 
88  static int dpdkWorkerThreadStart(void* ptr);
89  public:
90 
91  ~DpdkDeviceList();
92 
99  {
100  static DpdkDeviceList instance;
101  if (!instance.isInitialized())
102  instance.initDpdkDevices(DpdkDeviceList::m_MBufPoolSizePerDevice);
103 
104  return instance;
105  }
106 
127  static bool initDpdk(CoreMask coreMask, uint32_t mBufPoolSizePerDevice, uint8_t masterCore = 0);
128 
134  DpdkDevice* getDeviceByPort(int portId) const;
135 
141  DpdkDevice* getDeviceByPciAddress(const std::string& pciAddr) const;
142 
146  const std::vector<DpdkDevice*>& getDpdkDeviceList() const { return m_DpdkDeviceList; }
147 
151  SystemCore getDpdkMasterCore() const;
152 
157  void setDpdkLogLevel(LoggerPP::LogLevel logLevel);
158 
163  LoggerPP::LogLevel getDpdkLogLevel() const;
164 
170  bool writeDpdkLogToFile(FILE* logFile);
171 
190  bool startDpdkWorkerThreads(CoreMask coreMask, std::vector<DpdkWorkerThread*>& workerThreadsVec);
191 
196  void stopDpdkWorkerThreads();
197  };
198 
199 } // namespace pcpp
200 
201 #endif /* PCAPPP_DPDK_DEVICE_LIST */
The main namespace for the PcapPlusPlus lib.
virtual ~DpdkWorkerThread()
Definition: DpdkDeviceList.h:37
virtual void stop()=0
Definition: SystemUtils.h:32
static DpdkDeviceList & getInstance()
Definition: DpdkDeviceList.h:98
LogLevel
Definition: Logger.h:89
Definition: DpdkDeviceList.h:31
Definition: DpdkDevice.h:164
virtual uint32_t getCoreId() const =0
virtual bool run(uint32_t coreId)=0
Definition: KniDeviceList.h:22
Definition: DpdkDeviceList.h:71
const std::vector< DpdkDevice * > & getDpdkDeviceList() const
Definition: DpdkDeviceList.h:146