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);
322 this->
function =
function;
340 snprintf(pciString, 15,
"%04x:%02x:%02x.%x", domain, bus, devid,
function);
341 return std::string(pciString);
349 return (domain == other.
domain && bus == other.
bus && devid == other.
devid &&
function == other.
function);
503 uint16_t transmitDescriptorsNumber = 512,
504 uint16_t flushTxBufferTimeout = 100,
506 uint8_t* rssKey = DpdkDevice::m_RSSKey,
507 uint8_t rssKeyLength = 40)
619 inline uint16_t
getMtu() {
return m_DeviceMtu; }
626 bool setMtu(uint16_t newMtu);
671 uint16_t
receivePackets(MBufRawPacketVector& rawPacketsArr, uint16_t rxQueueId);
718 uint16_t
sendPackets(
MBufRawPacket** rawPacketsArr, uint16_t arrLength, uint16_t txQueueId = 0,
bool useTxBuffer =
false);
740 uint16_t
sendPackets(
Packet** packetsArr, uint16_t arrLength, uint16_t txQueueId = 0,
bool useTxBuffer =
false);
758 uint16_t
sendPackets(MBufRawPacketVector& rawPacketsVec, uint16_t txQueueId = 0,
bool useTxBuffer =
false);
827 bool sendPacket(
Packet& packet, uint16_t txQueueId = 0,
bool useTxBuffer =
false);
839 bool setFilter(std::string filterAsString);
851 bool openMultiQueues(uint16_t numOfRxQueuesToOpen, uint16_t numOfTxQueuesToOpen,
const DpdkDeviceConfiguration& config = DpdkDeviceConfiguration());
948 uint16_t
flushTxBuffer(
bool flushOnlyIfTimeoutExpired =
false, uint16_t txQueueId = 0);
972 struct DpdkCoreConfiguration
977 void clear() { RxQueueId = -1; IsCoreInUse =
false; }
979 DpdkCoreConfiguration() : RxQueueId(-1), IsCoreInUse(false) {}
982 DpdkDevice(
int port, uint32_t mBufPoolSize);
983 bool initMemPool(
struct rte_mempool*& memPool,
const char* mempoolName, uint32_t mBufPoolSize);
985 bool configurePort(uint8_t numOfRxQueues, uint8_t numOfTxQueues);
986 bool initQueues(uint8_t numOfRxQueuesToInit, uint8_t numOfTxQueuesToInit);
989 static int dpdkCaptureThreadMain(
void *ptr);
991 void clearCoreConfiguration();
992 bool initCoreConfigurationByCoreMask(CoreMask coreMask);
993 int getCoresInUseCount();
995 void setDeviceInfo();
997 typedef rte_mbuf* (*PacketIterator)(
void* packetStorage,
int index);
998 uint16_t sendPacketsInner(uint16_t txQueueId,
void* packetStorage, PacketIterator iter,
int arrLength,
bool useTxBuffer);
1000 uint64_t convertRssHfToDpdkRssHf(uint64_t rssHF);
1001 uint64_t convertDpdkRssHfToRssHf(uint64_t dpdkRssHF);
1003 char m_DeviceName[30];
1005 std::string m_PMDName;
1006 PciAddress m_PciAddress;
1008 DpdkDeviceConfiguration m_Config;
1011 MacAddress m_MacAddress;
1012 uint16_t m_DeviceMtu;
1013 struct rte_mempool* m_MBufMempool;
1014 struct rte_eth_dev_tx_buffer** m_TxBuffers;
1015 uint64_t m_TxBufferDrainTsc;
1016 uint64_t* m_TxBufferLastDrainTsc;
1017 DpdkCoreConfiguration m_CoreConfiguration[MAX_NUM_OF_CORES];
1018 uint16_t m_TotalAvailableRxQueues;
1019 uint16_t m_TotalAvailableTxQueues;
1020 uint16_t m_NumOfRxQueuesOpened;
1021 uint16_t m_NumOfTxQueuesOpened;
1023 void* m_OnPacketsArriveUserCookie;
1029 static uint8_t m_RSSKey[40];
1031 DpdkDeviceStats m_PrevStats;
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:502
uint64_t bytesPerSec
Definition: DpdkDevice.h:554
LinkDuplex
Definition: DpdkDevice.h:525
uint16_t domain
Definition: DpdkDevice.h:326
int getAmountOfMbufsInUse()
DpdkRssHashFunction
Definition: DpdkDevice.h:399
bool openMultiQueues(uint16_t numOfRxQueuesToOpen, uint16_t numOfTxQueuesToOpen, const DpdkDeviceConfiguration &config=DpdkDeviceConfiguration())
Definition: DpdkDevice.h:404
Definition: DpdkDevice.h:80
Definition: DpdkDevice.h:561
Definition: DpdkDevice.h:402
int getDeviceId()
Definition: DpdkDevice.h:588
timespec timestamp
Definition: DpdkDevice.h:566
Definition: DpdkDevice.h:84
PointerVector< MBufRawPacket > MBufRawPacketVector
Definition: DpdkDevice.h:296
Definition: DpdkDevice.h:434
Definition: DpdkDevice.h:414
bool setMtu(uint16_t newMtu)
uint16_t receiveDescriptorsNumber
Definition: DpdkDevice.h:454
void(* OnDpdkPacketsArriveCallback)(MBufRawPacket *packets, uint32_t numOfPackets, uint8_t threadId, DpdkDevice *device, void *userCookie)
Definition: DpdkDevice.h:290
Definition: DpdkDeviceList.h:70
uint8_t devId
Definition: DpdkDevice.h:564
Definition: DpdkDevice.h:110
Definition: DpdkDevice.h:424
bool isDeviceSupportRssHashFunction(DpdkRssHashFunction rssHF)
RxTxStats aggregatedTxStats
Definition: DpdkDevice.h:574
uint64_t bytes
Definition: DpdkDevice.h:550
Definition: DpdkDevice.h:112
Definition: RawPacket.h:30
Definition: DpdkDevice.h:90
bool init(DpdkDevice *device)
Definition: RawPacket.h:220
uint64_t rxPacketsDropeedByHW
Definition: DpdkDevice.h:576
Definition: PcapDevice.h:38
rte_mbuf * getMBuf()
Definition: DpdkDevice.h:199
bool linkUp
Definition: DpdkDevice.h:534
Definition: DpdkDevice.h:530
Definition: DpdkDevice.h:422
bool setRawData(const uint8_t *pRawData, int rawDataLen, timeval timestamp, LinkLayerType layerType=LINKTYPE_ETHERNET, int frameLength=-1)
uint64_t packets
Definition: DpdkDevice.h:548
The main namespace for the PcapPlusPlus lib.
Definition: DpdkDevice.h:448
Definition: DpdkDevice.h:440
Definition: DpdkDevice.h:143
LinkLayerType
Definition: RawPacket.h:25
Definition: PcapFilter.h:72
Definition: DpdkDevice.h:98
Definition: DpdkDevice.h:430
uint16_t getMtu()
Definition: DpdkDevice.h:619
PciAddress(uint16_t domain, uint8_t bus, uint8_t devid, uint8_t function)
Definition: DpdkDevice.h:317
PciAddress()
Definition: DpdkDevice.h:308
Definition: DpdkDevice.h:102
uint16_t getTotalNumOfRxQueues()
Definition: DpdkDevice.h:657
uint16_t getNumOfOpenedTxQueues()
Definition: DpdkDevice.h:652
Definition: DpdkDevice.h:545
Definition: DpdkDevice.h:438
Definition: DpdkDevice.h:389
Definition: PointerVector.h:24
uint64_t rxErroneousPackets
Definition: DpdkDevice.h:578
Definition: DpdkDevice.h:96
Definition: DpdkDevice.h:106
bool sendPacket(RawPacket &rawPacket, uint16_t txQueueId=0, bool useTxBuffer=false)
Definition: DpdkDevice.h:100
DpdkPMDType
Definition: DpdkDevice.h:78
uint8_t function
Definition: DpdkDevice.h:332
uint16_t getTotalNumOfTxQueues()
Definition: DpdkDevice.h:662
MBufRawPacket & operator=(const MBufRawPacket &other)
uint64_t rxMbufAlocFailed
Definition: DpdkDevice.h:580
Definition: DpdkDevice.h:522
bool startCaptureSingleThread(OnDpdkPacketsArriveCallback onPacketsArrive, void *onPacketsArriveUserCookie)
DpdkPMDType getPMDType()
Definition: DpdkDevice.h:609
Definition: DpdkDevice.h:88
MacAddress getMacAddress()
Definition: DpdkDevice.h:597
Definition: DpdkDevice.h:94
Definition: DpdkDevice.h:116
uint8_t devid
Definition: DpdkDevice.h:330
Definition: DpdkDevice.h:114
uint8_t rssKeyLength
Definition: DpdkDevice.h:480
Definition: DpdkDevice.h:104
Definition: MacAddress.h:21
Definition: DpdkDevice.h:436
uint64_t rssHashFunction
Definition: DpdkDevice.h:487
uint64_t packetsPerSec
Definition: DpdkDevice.h:552
Definition: DpdkDevice.h:108
Definition: DpdkDevice.h:412
Definition: DpdkDevice.h:432
void getStatistics(pcap_stat &stats)
RxTxStats aggregatedRxStats
Definition: DpdkDevice.h:572
Definition: DpdkDevice.h:82
void setFreeMbuf(bool val=true)
Definition: DpdkDevice.h:278
uint32_t getCurrentCoreId()
LinkDuplex linkDuplex
Definition: DpdkDevice.h:538
uint16_t getNumOfOpenedRxQueues()
Definition: DpdkDevice.h:647
RxTxStats rxStats[16]
Definition: DpdkDevice.h:568
Definition: DpdkDevice.h:428
Definition: DpdkDevice.h:86
Definition: DpdkDevice.h:426
bool initFromRawPacket(const RawPacket *rawPacket, DpdkDevice *device)
uint8_t bus
Definition: DpdkDevice.h:328
PciAddress getPciAddress()
Definition: DpdkDevice.h:614
bool setFilter(GeneralFilter &filter)
RxTxStats txStats[16]
Definition: DpdkDevice.h:570
int linkSpeedMbps
Definition: DpdkDevice.h:536
void insertData(int atIndex, const uint8_t *dataToInsert, size_t dataToInsertLen)
Definition: DpdkDevice.h:406
uint16_t flushTxBufferTimeout
Definition: DpdkDevice.h:466
void appendData(const uint8_t *dataToAppend, size_t dataToAppendLen)
MBufRawPacket()
Definition: DpdkDevice.h:160
void getLinkStatus(LinkStatus &linkStatus)
bool removeData(int atIndex, size_t numOfBytesToRemove)
Definition: DpdkDevice.h:418
std::string toString()
Definition: DpdkDevice.h:337
bool operator==(const PciAddress &other) const
Definition: DpdkDevice.h:347
bool startCaptureMultiThreads(OnDpdkPacketsArriveCallback onPacketsArrive, void *onPacketsArriveUserCookie, CoreMask coreMask)
bool open()
Definition: DpdkDevice.h:911
uint8_t * rssKey
Definition: DpdkDevice.h:474
int getAmountOfFreeMbufs()
bool reallocateData(size_t newBufferLength)
Definition: DpdkDevice.h:410
Definition: DpdkDevice.h:408
Definition: DpdkDevice.h:528
uint64_t getSupportedRssHashFunctions()
uint16_t transmitDescriptorsNumber
Definition: DpdkDevice.h:460
uint16_t receivePackets(MBufRawPacketVector &rawPacketsArr, uint16_t rxQueueId)
Definition: DpdkDevice.h:92
virtual uint8_t getObjectType() const
Definition: DpdkDevice.h:206
Definition: DpdkDevice.h:420
std::string getDeviceName()
Definition: DpdkDevice.h:592
uint16_t sendPackets(MBufRawPacket **rawPacketsArr, uint16_t arrLength, uint16_t txQueueId=0, bool useTxBuffer=false)
uint16_t flushTxBuffer(bool flushOnlyIfTimeoutExpired=false, uint16_t txQueueId=0)
std::string getPMDName()
Definition: DpdkDevice.h:603
Definition: DpdkDevice.h:302
Definition: DpdkDevice.h:416