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 "Logger.h"
8 #include <vector>
9 
19 namespace pcpp
20 {
21 
34  {
35  public:
40  {}
41 
48  virtual bool run(uint32_t coreId) = 0;
49 
54  virtual void stop() = 0;
55 
61  virtual uint32_t getCoreId() const = 0;
62  };
63 
64  class KniDeviceList;
65 
76  {
77  friend class KniDeviceList;
78 
79  private:
80  bool m_IsInitialized;
81  static bool m_IsDpdkInitialized;
82  static uint32_t m_MBufPoolSizePerDevice;
83  static uint16_t m_MBufDataSize;
84  static CoreMask m_CoreMask;
85  std::vector<DpdkDevice*> m_DpdkDeviceList;
86  std::vector<DpdkWorkerThread*> m_WorkerThreads;
87 
89 
90  bool isInitialized() const
91  {
92  return (m_IsInitialized && m_IsDpdkInitialized);
93  }
94  bool initDpdkDevices(uint32_t mBufPoolSizePerDevice, uint16_t mMbufDataSize);
95  static bool verifyHugePagesAndDpdkDriver();
96 
97  static int dpdkWorkerThreadStart(void* ptr);
98 
99  public:
100  ~DpdkDeviceList();
101 
109  {
110  static DpdkDeviceList instance;
111  if (!instance.isInitialized())
112  instance.initDpdkDevices(DpdkDeviceList::m_MBufPoolSizePerDevice, DpdkDeviceList::m_MBufDataSize);
113 
114  return instance;
115  }
116 
147  static bool initDpdk(CoreMask coreMask, uint32_t mBufPoolSizePerDevice, uint16_t mBufDataSize = 0,
148  uint8_t masterCore = 0, uint32_t initDpdkArgc = 0, char** initDpdkArgv = nullptr,
149  const std::string& appName = "pcapplusplusapp", bool verifyHugePagesAndDriver = true);
150 
156  DpdkDevice* getDeviceByPort(int portId) const;
157 
163  DpdkDevice* getDeviceByPciAddress(const std::string& pciAddr) const;
164 
168  const std::vector<DpdkDevice*>& getDpdkDeviceList() const
169  {
170  return m_DpdkDeviceList;
171  }
172 
177 
183 
189 
195  bool writeDpdkLogToFile(FILE* logFile);
196 
217  bool startDpdkWorkerThreads(CoreMask coreMask, std::vector<DpdkWorkerThread*>& workerThreadsVec);
218 
224  };
225 
226 } // namespace pcpp
227 
228 // GCOVR_EXCL_STOP
Definition: DpdkDevice.h:179
Definition: DpdkDeviceList.h:76
SystemCore getDpdkMasterCore() const
const std::vector< DpdkDevice * > & getDpdkDeviceList() const
Definition: DpdkDeviceList.h:168
DpdkDevice * getDeviceByPort(int portId) const
bool startDpdkWorkerThreads(CoreMask coreMask, std::vector< DpdkWorkerThread * > &workerThreadsVec)
static DpdkDeviceList & getInstance()
Definition: DpdkDeviceList.h:108
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:34
virtual uint32_t getCoreId() const =0
virtual void stop()=0
virtual bool run(uint32_t coreId)=0
virtual ~DpdkWorkerThread()
Definition: DpdkDeviceList.h:39
Definition: KniDeviceList.h:24
LogLevel
Definition: Logger.h:147
The main namespace for the PcapPlusPlus lib.
Definition: SystemUtils.h:27