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 
125  static bool initDpdk(CoreMask coreMask, uint32_t mBufPoolSizePerDevice, uint8_t masterCore = 0);
126 
132  DpdkDevice* getDeviceByPort(int portId);
133 
140 
144  inline const std::vector<DpdkDevice*>& getDpdkDeviceList() { return m_DpdkDeviceList; }
145 
150 
155  void setDpdkLogLevel(LoggerPP::LogLevel logLevel);
156 
162 
168  bool writeDpdkLogToFile(FILE* logFile);
169 
188  bool startDpdkWorkerThreads(CoreMask coreMask, std::vector<DpdkWorkerThread*>& workerThreadsVec);
189 
194  void stopDpdkWorkerThreads();
195  };
196 
197 } // namespace pcpp
198 
199 #endif /* PCAPPP_DPDK_DEVICE_LIST */
const std::vector< DpdkDevice * > & getDpdkDeviceList()
Definition: DpdkDeviceList.h:144
Definition: DpdkDeviceList.h:70
virtual bool run(uint32_t coreId)=0
The main namespace for the PcapPlusPlus lib.
DpdkDevice * getDeviceByPort(int portId)
Definition: SystemUtils.h:32
Definition: DpdkDeviceList.h:31
Definition: DpdkDevice.h:389
virtual ~DpdkWorkerThread()
Definition: DpdkDeviceList.h:37
bool writeDpdkLogToFile(FILE *logFile)
LogLevel
Definition: Logger.h:83
void setDpdkLogLevel(LoggerPP::LogLevel logLevel)
static DpdkDeviceList & getInstance()
Definition: DpdkDeviceList.h:96
LoggerPP::LogLevel getDpdkLogLevel()
virtual uint32_t getCoreId()=0
DpdkDevice * getDeviceByPciAddress(const PciAddress &pciAddr)
bool startDpdkWorkerThreads(CoreMask coreMask, std::vector< DpdkWorkerThread *> &workerThreadsVec)
virtual void stop()=0
static bool initDpdk(CoreMask coreMask, uint32_t mBufPoolSizePerDevice, uint8_t masterCore=0)
SystemCore getDpdkMasterCore()
Definition: DpdkDevice.h:302