PcapPlusPlus
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() = 0;
58  };
59 
60 
71  {
72  private:
73  bool m_IsInitialized;
74  static bool m_IsDpdkInitialized;
75  static uint32_t m_MBufPoolSizePerDevice;
76  static CoreMask m_CoreMask;
77  std::vector<DpdkDevice*> m_DpdkDeviceList;
78  std::vector<DpdkWorkerThread*> m_WorkerThreads;
79 
81 
82  inline bool isInitialized() { return (m_IsInitialized && m_IsDpdkInitialized); }
83  bool initDpdkDevices(uint32_t mBufPoolSizePerDevice);
84  static bool verifyHugePagesAndDpdkDriver();
85 
86  static int dpdkWorkerThreadStart(void *ptr);
87  public:
88 
89  ~DpdkDeviceList();
90 
96  static inline DpdkDeviceList& getInstance()
97  {
98  static DpdkDeviceList instance;
99  if (!instance.isInitialized())
100  instance.initDpdkDevices(DpdkDeviceList::m_MBufPoolSizePerDevice);
101 
102  return instance;
103  }
104 
124  static bool initDpdk(CoreMask coreMask, uint32_t mBufPoolSizePerDevice);
125 
131  DpdkDevice* getDeviceByPort(int portId);
132 
139 
143  inline const std::vector<DpdkDevice*>& getDpdkDeviceList() { return m_DpdkDeviceList; }
144 
149 
154  void setDpdkLogLevel(LoggerPP::LogLevel logLevel);
155 
161 
167  bool writeDpdkLogToFile(FILE* logFile);
168 
187  bool startDpdkWorkerThreads(CoreMask coreMask, std::vector<DpdkWorkerThread*>& workerThreadsVec);
188 
193  void stopDpdkWorkerThreads();
194  };
195 
196 } // namespace pcpp
197 
198 #endif /* PCAPPP_DPDK_DEVICE_LIST */
LoggerPP::LogLevel getDpdkLogLevel()
Definition: DpdkDevice.h:340
LogLevel
Definition: Logger.h:81
virtual bool run(uint32_t coreId)=0
Definition: DpdkDevice.h:255
bool startDpdkWorkerThreads(CoreMask coreMask, std::vector< DpdkWorkerThread * > &workerThreadsVec)
void setDpdkLogLevel(LoggerPP::LogLevel logLevel)
const std::vector< DpdkDevice * > & getDpdkDeviceList()
Definition: DpdkDeviceList.h:143
Definition: SystemUtils.h:32
Definition: DpdkDeviceList.h:31
DpdkDevice * getDeviceByPort(int portId)
static DpdkDeviceList & getInstance()
Definition: DpdkDeviceList.h:96
DpdkDevice * getDeviceByPciAddress(const PciAddress &pciAddr)
Definition: DpdkDeviceList.h:70
static bool initDpdk(CoreMask coreMask, uint32_t mBufPoolSizePerDevice)
bool writeDpdkLogToFile(FILE *logFile)
virtual void stop()=0
virtual uint32_t getCoreId()=0
SystemCore getDpdkMasterCore()
The main namespace for the PcapPlusPlus lib.
virtual ~DpdkWorkerThread()
Definition: DpdkDeviceList.h:37