1 #ifndef PCAPPP_DPDK_DEVICE 2 #define PCAPPP_DPDK_DEVICE 59 struct rte_eth_dev_tx_buffer;
68 #define DPDK_MAX_RX_QUEUES 16 69 #define DPDK_MAX_TX_QUEUES 16 121 #define MBUFRAWPACKET_OBJECT_TYPE 1 148 struct rte_mbuf* m_MBuf;
152 void setMBuf(
struct rte_mbuf* mBuf, timeval timestamp);
206 virtual inline uint8_t
getObjectType()
const {
return MBUFRAWPACKET_OBJECT_TYPE; }
243 void appendData(
const uint8_t* dataToAppend,
size_t dataToAppendLen);
253 void insertData(
int atIndex,
const uint8_t* dataToInsert,
size_t dataToInsertLen);
263 bool removeData(
int atIndex,
size_t numOfBytesToRemove);
448 uint16_t transmitDescriptorsNumber = 512,
449 uint16_t flushTxBufferTimeout = 100,
451 uint8_t* rssKey = DpdkDevice::m_RSSKey,
452 uint8_t rssKeyLength = 40)
564 inline uint16_t
getMtu() {
return m_DeviceMtu; }
571 bool setMtu(uint16_t newMtu);
616 uint16_t
receivePackets(MBufRawPacketVector& rawPacketsArr, uint16_t rxQueueId);
663 uint16_t
sendPackets(
MBufRawPacket** rawPacketsArr, uint16_t arrLength, uint16_t txQueueId = 0,
bool useTxBuffer =
false);
685 uint16_t
sendPackets(
Packet** packetsArr, uint16_t arrLength, uint16_t txQueueId = 0,
bool useTxBuffer =
false);
703 uint16_t
sendPackets(MBufRawPacketVector& rawPacketsVec, uint16_t txQueueId = 0,
bool useTxBuffer =
false);
772 bool sendPacket(
Packet& packet, uint16_t txQueueId = 0,
bool useTxBuffer =
false);
784 bool setFilter(std::string filterAsString);
796 bool openMultiQueues(uint16_t numOfRxQueuesToOpen, uint16_t numOfTxQueuesToOpen,
const DpdkDeviceConfiguration& config = DpdkDeviceConfiguration());
872 uint16_t
flushTxBuffer(
bool flushOnlyIfTimeoutExpired =
false, uint16_t txQueueId = 0);
912 struct DpdkCoreConfiguration
917 void clear() { RxQueueId = -1; IsCoreInUse =
false; }
919 DpdkCoreConfiguration() : RxQueueId(-1), IsCoreInUse(false) {}
922 DpdkDevice(
int port, uint32_t mBufPoolSize);
923 bool initMemPool(
struct rte_mempool*& memPool,
const char* mempoolName, uint32_t mBufPoolSize);
925 bool configurePort(uint8_t numOfRxQueues, uint8_t numOfTxQueues);
926 bool initQueues(uint8_t numOfRxQueuesToInit, uint8_t numOfTxQueuesToInit);
929 static int dpdkCaptureThreadMain(
void *ptr);
931 void clearCoreConfiguration();
932 bool initCoreConfigurationByCoreMask(CoreMask coreMask);
933 int getCoresInUseCount();
935 void setDeviceInfo();
937 typedef rte_mbuf* (*PacketIterator)(
void* packetStorage,
int index);
938 uint16_t sendPacketsInner(uint16_t txQueueId,
void* packetStorage, PacketIterator iter,
int arrLength,
bool useTxBuffer);
940 uint64_t convertRssHfToDpdkRssHf(uint64_t rssHF);
941 uint64_t convertDpdkRssHfToRssHf(uint64_t dpdkRssHF);
943 char m_DeviceName[30];
945 std::string m_PMDName;
946 std::string m_PciAddress;
948 DpdkDeviceConfiguration m_Config;
951 MacAddress m_MacAddress;
952 uint16_t m_DeviceMtu;
953 struct rte_mempool* m_MBufMempool;
954 struct rte_eth_dev_tx_buffer** m_TxBuffers;
955 uint64_t m_TxBufferDrainTsc;
956 uint64_t* m_TxBufferLastDrainTsc;
957 DpdkCoreConfiguration m_CoreConfiguration[MAX_NUM_OF_CORES];
958 uint16_t m_TotalAvailableRxQueues;
959 uint16_t m_TotalAvailableTxQueues;
960 uint16_t m_NumOfRxQueuesOpened;
961 uint16_t m_NumOfTxQueuesOpened;
963 void* m_OnPacketsArriveUserCookie;
969 static uint8_t m_RSSKey[40];
971 DpdkDeviceStats m_PrevStats;
Definition: DpdkDevice.h:100
Definition: DpdkDevice.h:116
bool init(DpdkDevice *device)
uint64_t rssHashFunction
Definition: DpdkDevice.h:432
bool reallocateData(size_t newBufferLength)
MBufRawPacket & operator=(const MBufRawPacket &other)
int getDeviceId()
Definition: DpdkDevice.h:533
DpdkPMDType getPMDType()
Definition: DpdkDevice.h:554
uint16_t receivePackets(MBufRawPacketVector &rawPacketsArr, uint16_t rxQueueId)
Definition: DpdkDevice.h:381
DpdkPMDType
Definition: DpdkDevice.h:78
uint64_t rxMbufAlocFailed
Definition: DpdkDevice.h:525
Definition: DpdkDevice.h:94
uint16_t getTotalNumOfRxQueues()
Definition: DpdkDevice.h:602
uint16_t getNumOfOpenedTxQueues()
Definition: DpdkDevice.h:597
uint16_t flushTxBuffer(bool flushOnlyIfTimeoutExpired=false, uint16_t txQueueId=0)
Definition: DpdkDevice.h:393
uint16_t getMtu()
Definition: DpdkDevice.h:564
uint16_t flushTxBufferTimeout
Definition: DpdkDevice.h:411
uint64_t packetsPerSec
Definition: DpdkDevice.h:497
void(* OnDpdkPacketsArriveCallback)(MBufRawPacket *packets, uint32_t numOfPackets, uint8_t threadId, DpdkDevice *device, void *userCookie)
Definition: DpdkDevice.h:290
Definition: DpdkDevice.h:86
Definition: DpdkDevice.h:377
Definition: DpdkDevice.h:98
bool isDeviceSupportRssHashFunction(DpdkRssHashFunction rssHF)
RxTxStats aggregatedRxStats
Definition: DpdkDevice.h:517
Definition: DpdkDevice.h:371
uint16_t receiveDescriptorsNumber
Definition: DpdkDevice.h:399
int linkSpeedMbps
Definition: DpdkDevice.h:481
uint16_t sendPackets(MBufRawPacket **rawPacketsArr, uint16_t arrLength, uint16_t txQueueId=0, bool useTxBuffer=false)
bool startCaptureMultiThreads(OnDpdkPacketsArriveCallback onPacketsArrive, void *onPacketsArriveUserCookie, CoreMask coreMask)
Definition: DpdkDevice.h:373
Definition: DpdkDevice.h:490
Definition: PointerVector.h:24
uint8_t * rssKey
Definition: DpdkDevice.h:419
uint16_t getNumOfOpenedRxQueues()
Definition: DpdkDevice.h:592
uint64_t bytesPerSec
Definition: DpdkDevice.h:499
bool sendPacket(RawPacket &rawPacket, uint16_t txQueueId=0, bool useTxBuffer=false)
Definition: DpdkDevice.h:104
MacAddress getMacAddress()
Definition: DpdkDevice.h:542
void appendData(const uint8_t *dataToAppend, size_t dataToAppendLen)
Definition: DpdkDevice.h:357
Definition: DpdkDevice.h:353
Definition: DpdkDevice.h:351
bool openMultiQueues(uint16_t numOfRxQueuesToOpen, uint16_t numOfTxQueuesToOpen, const DpdkDeviceConfiguration &config=DpdkDeviceConfiguration())
int getAmountOfFreeMbufs()
Definition: DpdkDevice.h:355
bool startCaptureSingleThread(OnDpdkPacketsArriveCallback onPacketsArrive, void *onPacketsArriveUserCookie)
Definition: DpdkDevice.h:80
Definition: MacAddress.h:21
Definition: DpdkDevice.h:363
Definition: DpdkDevice.h:361
Definition: DpdkDevice.h:114
PointerVector< MBufRawPacket > MBufRawPacketVector
Definition: DpdkDevice.h:296
RxTxStats txStats[16]
Definition: DpdkDevice.h:515
Definition: DpdkDevice.h:334
uint32_t getCurrentCoreId()
uint16_t transmitDescriptorsNumber
Definition: DpdkDevice.h:405
Definition: RawPacket.h:219
Definition: DpdkDevice.h:473
bool removeData(int atIndex, size_t numOfBytesToRemove)
bool open()
Definition: DpdkDevice.h:903
LinkDuplex
Definition: DpdkDevice.h:470
Definition: DpdkDevice.h:379
Definition: DpdkDevice.h:110
Definition: DpdkDevice.h:467
Definition: DpdkDevice.h:365
Definition: DpdkDevice.h:84
Definition: DpdkDevice.h:96
Definition: DpdkDevice.h:349
bool initFromRawPacket(const RawPacket *rawPacket, DpdkDevice *device)
std::string getPMDName()
Definition: DpdkDevice.h:548
Definition: DpdkDevice.h:143
bool setRawData(const uint8_t *pRawData, int rawDataLen, timeval timestamp, LinkLayerType layerType=LINKTYPE_ETHERNET, int frameLength=-1)
Definition: PcapFilter.h:72
Definition: DpdkDevice.h:347
uint64_t rxPacketsDropeedByHW
Definition: DpdkDevice.h:521
RxTxStats rxStats[16]
Definition: DpdkDevice.h:513
Definition: DpdkDevice.h:369
void getLinkStatus(LinkStatus &linkStatus)
Definition: DpdkDeviceList.h:70
Definition: DpdkDevice.h:359
Definition: DpdkDevice.h:90
void setFreeMbuf(bool val=true)
Definition: DpdkDevice.h:278
Definition: DpdkDevice.h:506
std::string getPciAddress()
Definition: DpdkDevice.h:559
Definition: DpdkDevice.h:88
Definition: DpdkDevice.h:102
Definition: DpdkDevice.h:112
Definition: RawPacket.h:29
Definition: DpdkDevice.h:367
MBufRawPacket()
Definition: DpdkDevice.h:160
Definition: DpdkDevice.h:92
Definition: DpdkDevice.h:475
uint64_t rxErroneousPackets
Definition: DpdkDevice.h:523
bool setMtu(uint16_t newMtu)
Definition: DpdkDevice.h:375
Definition: DpdkDevice.h:108
timespec timestamp
Definition: DpdkDevice.h:511
Definition: DpdkDevice.h:385
bool setFilter(GeneralFilter &filter)
virtual uint8_t getObjectType() const
Definition: DpdkDevice.h:206
void insertData(int atIndex, const uint8_t *dataToInsert, size_t dataToInsertLen)
bool linkUp
Definition: DpdkDevice.h:479
int getAmountOfMbufsInUse()
void getStatistics(DpdkDeviceStats &stats)
DpdkRssHashFunction
Definition: DpdkDevice.h:344
std::string getDeviceName()
Definition: DpdkDevice.h:537
RxTxStats aggregatedTxStats
Definition: DpdkDevice.h:519
uint8_t devId
Definition: DpdkDevice.h:509
uint64_t getSupportedRssHashFunctions()
Definition: DpdkDevice.h:106
uint64_t bytes
Definition: DpdkDevice.h:495
Definition: DpdkDevice.h:383
DpdkDeviceConfiguration(uint16_t receiveDescriptorsNumber=128, uint16_t transmitDescriptorsNumber=512, uint16_t flushTxBufferTimeout=100, uint64_t rssHashFunction=RSS_IPV4|RSS_IPV6, uint8_t *rssKey=DpdkDevice::m_RSSKey, uint8_t rssKeyLength=40)
Definition: DpdkDevice.h:447
The main namespace for the PcapPlusPlus lib.
LinkDuplex linkDuplex
Definition: DpdkDevice.h:483
uint16_t getTotalNumOfTxQueues()
Definition: DpdkDevice.h:607
LinkLayerType
Definition: RawPacket.h:24
uint8_t rssKeyLength
Definition: DpdkDevice.h:425
Definition: DpdkDevice.h:82
rte_mbuf * getMBuf()
Definition: DpdkDevice.h:199
uint64_t packets
Definition: DpdkDevice.h:493