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 
12 
15 namespace pcpp
16 {
27  {
28  public:
30  virtual ~DpdkWorkerThread() = default;
31 
36  virtual bool run(uint32_t coreId) = 0;
37 
40  virtual void stop() = 0;
41 
45  virtual uint32_t getCoreId() const = 0;
46  };
47 
48  class KniDeviceList;
49 
58  {
59  friend class KniDeviceList;
60 
61  private:
62  bool m_IsInitialized;
63  static bool m_IsDpdkInitialized;
64  static uint32_t m_MBufPoolSizePerDevice;
65  static uint16_t m_MBufDataSize;
66  static CoreMask m_CoreMask;
67  std::vector<DpdkDevice*> m_DpdkDeviceList;
68  std::vector<DpdkWorkerThread*> m_WorkerThreads;
69 
71 
72  bool isInitialized() const
73  {
74  return (m_IsInitialized && m_IsDpdkInitialized);
75  }
76  bool initDpdkDevices(uint32_t mBufPoolSizePerDevice, uint16_t mMbufDataSize);
77  static bool verifyHugePagesAndDpdkDriver();
78 
79  static int dpdkWorkerThreadStart(void* ptr);
80 
81  public:
82  ~DpdkDeviceList();
83 
89  {
90  static DpdkDeviceList instance;
91  if (!instance.isInitialized())
92  instance.initDpdkDevices(DpdkDeviceList::m_MBufPoolSizePerDevice, DpdkDeviceList::m_MBufDataSize);
93 
94  return instance;
95  }
96 
125  static bool initDpdk(CoreMask coreMask, uint32_t mBufPoolSizePerDevice, uint16_t mBufDataSize = 0,
126  uint8_t masterCore = 0, uint32_t initDpdkArgc = 0, char** initDpdkArgv = nullptr,
127  const std::string& appName = "pcapplusplusapp", bool verifyHugePagesAndDriver = true);
128 
132  DpdkDevice* getDeviceByPort(int portId) const;
133 
137  DpdkDevice* getDeviceByPciAddress(const std::string& pciAddr) const;
138 
140  const std::vector<DpdkDevice*>& getDpdkDeviceList() const
141  {
142  return m_DpdkDeviceList;
143  }
144 
147 
151 
155 
159  bool writeDpdkLogToFile(FILE* logFile);
160 
179  bool startDpdkWorkerThreads(CoreMask coreMask, std::vector<DpdkWorkerThread*>& workerThreadsVec);
180 
184  };
185 
186 } // namespace pcpp
187 
188 // GCOVR_EXCL_STOP
Definition: DpdkDevice.h:169
Definition: DpdkDeviceList.h:58
SystemCore getDpdkMasterCore() const
const std::vector< DpdkDevice * > & getDpdkDeviceList() const
Definition: DpdkDeviceList.h:140
DpdkDevice * getDeviceByPort(int portId) const
bool startDpdkWorkerThreads(CoreMask coreMask, std::vector< DpdkWorkerThread * > &workerThreadsVec)
static DpdkDeviceList & getInstance()
Definition: DpdkDeviceList.h:88
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:27
virtual uint32_t getCoreId() const =0
virtual void stop()=0
virtual ~DpdkWorkerThread()=default
A virtual d'tor. Can be overridden by child class if needed.
virtual bool run(uint32_t coreId)=0
Definition: KniDeviceList.h:19
LogLevel
Definition: Logger.h:139
The main namespace for the PcapPlusPlus lib.
Definition: SystemUtils.h:23