11 #include "MBufRawPacket.h"
62 struct rte_eth_dev_tx_buffer;
69 #define DPDK_MAX_RX_QUEUES 16
70 #define DPDK_MAX_TX_QUEUES 16
71 #define PCPP_RSS_HASH_MAGIC_NUMBER 0x123456
416 return m_NumOfRxQueuesOpened;
422 return m_NumOfTxQueuesOpened;
428 return m_TotalAvailableRxQueues;
434 return m_TotalAvailableTxQueues;
491 bool useTxBuffer =
false);
515 uint16_t
sendPackets(
Packet** packetsArr, uint16_t arrLength, uint16_t txQueueId = 0,
bool useTxBuffer =
false);
694 uint16_t
flushTxBuffer(
bool flushOnlyIfTimeoutExpired =
false, uint16_t txQueueId = 0);
735 struct DpdkCoreConfiguration
746 DpdkCoreConfiguration() : RxQueueId(-1), IsCoreInUse(false)
750 DpdkDevice(
int port, uint32_t mBufPoolSize, uint16_t mMbufDataSize);
751 bool initMemPool(
struct rte_mempool*& memPool,
const char* mempoolName, uint32_t mBufPoolSize);
753 bool configurePort(uint8_t numOfRxQueues, uint8_t numOfTxQueues);
754 bool initQueues(uint8_t numOfRxQueuesToInit, uint8_t numOfTxQueuesToInit);
757 static int dpdkCaptureThreadMain(
void* ptr);
759 void clearCoreConfiguration();
760 bool initCoreConfigurationByCoreMask(CoreMask coreMask);
761 int getCoresInUseCount()
const;
763 void setDeviceInfo();
765 typedef rte_mbuf* (*PacketIterator)(
void* packetStorage,
int index);
766 uint16_t sendPacketsInner(uint16_t txQueueId,
void* packetStorage, PacketIterator iter,
int arrLength,
769 uint64_t convertRssHfToDpdkRssHf(uint64_t rssHF)
const;
770 uint64_t convertDpdkRssHfToRssHf(uint64_t dpdkRssHF)
const;
772 std::string m_DeviceName;
774 std::string m_PMDName;
775 std::string m_PciAddress;
777 DpdkDeviceConfiguration m_Config;
780 MacAddress m_MacAddress;
781 int16_t m_DeviceSocketId;
782 uint16_t m_DeviceMtu;
783 uint16_t m_MBufDataSize;
784 struct rte_mempool* m_MBufMempool;
785 struct rte_eth_dev_tx_buffer** m_TxBuffers;
786 uint64_t m_TxBufferDrainTsc;
787 uint64_t* m_TxBufferLastDrainTsc;
788 DpdkCoreConfiguration m_CoreConfiguration[MAX_NUM_OF_CORES];
789 uint16_t m_TotalAvailableRxQueues;
790 uint16_t m_TotalAvailableTxQueues;
791 uint16_t m_NumOfRxQueuesOpened;
792 uint16_t m_NumOfTxQueuesOpened;
794 void* m_OnPacketsArriveUserCookie;
800 static uint8_t m_RSSKey[40];
802 mutable DpdkDeviceStats m_PrevStats;
Definition: DpdkDevice.h:169
bool setFilter(std::string filterAsString)
bool startCaptureMultiThreads(OnDpdkPacketsArriveCallback onPacketsArrive, void *onPacketsArriveUserCookie, CoreMask coreMask)
uint16_t getTotalNumOfRxQueues() const
Definition: DpdkDevice.h:426
int getAmountOfMbufsInUse() const
uint16_t getMtu() const
Definition: DpdkDevice.h:391
bool sendPacket(RawPacket &rawPacket, uint16_t txQueueId=0, bool useTxBuffer=false)
int getDeviceId() const
Definition: DpdkDevice.h:354
uint16_t receivePackets(Packet **packetsArr, uint16_t packetsArrLength, uint16_t rxQueueId) const
bool open() override
Definition: DpdkDevice.h:726
bool sendPacket(MBufRawPacket &rawPacket, uint16_t txQueueId=0, bool useTxBuffer=false)
std::string getPciAddress() const
Definition: DpdkDevice.h:385
bool sendPacket(Packet &packet, uint16_t txQueueId=0, bool useTxBuffer=false)
uint64_t getConfiguredRssHashFunction() const
void getLinkStatus(LinkStatus &linkStatus) const
MacAddress getMacAddress() const
Definition: DpdkDevice.h:365
int getAmountOfFreeMbufs() const
void close() override
Close the DpdkDevice. When device is closed it's not possible work with it.
uint16_t receivePackets(MBufRawPacket **rawPacketsArr, uint16_t rawPacketArrLength, uint16_t rxQueueId) const
uint16_t sendPackets(Packet **packetsArr, uint16_t arrLength, uint16_t txQueueId=0, bool useTxBuffer=false)
void clearStatistics()
Clear device statistics.
bool setFilter(GeneralFilter &filter)
uint16_t sendPackets(MBufRawPacketVector &rawPacketsVec, uint16_t txQueueId=0, bool useTxBuffer=false)
uint64_t getSupportedRssHashFunctions() const
std::string getPMDName() const
Definition: DpdkDevice.h:372
uint16_t sendPackets(RawPacketVector &rawPacketsVec, uint16_t txQueueId=0, bool useTxBuffer=false)
bool isDeviceSupportRssHashFunction(uint64_t rssHFMask) const
bool setMtu(uint16_t newMtu)
uint16_t getNumOfOpenedRxQueues() const
Definition: DpdkDevice.h:414
DpdkRssHashFunction
Definition: DpdkDevice.h:177
@ RSS_NVGRE
NVGRE protocol based flow.
Definition: DpdkDevice.h:219
@ RSS_IPV4
IPv4 based flow.
Definition: DpdkDevice.h:181
@ RSS_ALL_SUPPORTED
All RSS functions supported by the device.
Definition: DpdkDevice.h:221
@ RSS_NONE
No RSS.
Definition: DpdkDevice.h:179
@ RSS_PORT
Consider device port number as a flow differentiator.
Definition: DpdkDevice.h:213
@ RSS_IPV6_TCP_EX
IPv6 + TCP Ex based flow.
Definition: DpdkDevice.h:209
@ RSS_GENEVE
GENEVE protocol based flow.
Definition: DpdkDevice.h:217
@ RSS_NONFRAG_IPV4_OTHER
Non-fragmented IPv4 + non TCP/UDP/SCTP flow.
Definition: DpdkDevice.h:191
@ RSS_FRAG_IPV6
Fragmented IPv6 based flow.
Definition: DpdkDevice.h:195
@ RSS_IPV6_EX
IPv6 Ex based flow.
Definition: DpdkDevice.h:207
@ RSS_IPV6_UDP_EX
IPv6 + UDP Ex based flow.
Definition: DpdkDevice.h:211
@ RSS_NONFRAG_IPV6_UDP
Non-fragmented IPv6 + UDP flow.
Definition: DpdkDevice.h:199
@ RSS_NONFRAG_IPV4_SCTP
Non-fragmented IPv4 + SCTP flow.
Definition: DpdkDevice.h:189
@ RSS_NONFRAG_IPV4_UDP
Non-fragmented IPv4 + UDP flow.
Definition: DpdkDevice.h:187
@ RSS_NONFRAG_IPV6_OTHER
Non-fragmented IPv6 + non TCP/UDP/SCTP flow.
Definition: DpdkDevice.h:203
@ RSS_NONFRAG_IPV6_TCP
Non-fragmented IPv6 + TCP flow.
Definition: DpdkDevice.h:197
@ RSS_L2_PAYLOAD
L2 payload based flow.
Definition: DpdkDevice.h:205
@ RSS_FRAG_IPV4
Fragmented IPv4 based flow.
Definition: DpdkDevice.h:183
@ RSS_DEFAULT
A default set of RSS functions supported by the device.
Definition: DpdkDevice.h:223
@ RSS_IPV6
IPv6 based flow.
Definition: DpdkDevice.h:193
@ RSS_NONFRAG_IPV6_SCTP
Non-fragmented IPv6 + SCTP flow.
Definition: DpdkDevice.h:201
@ RSS_NONFRAG_IPV4_TCP
Non-fragmented IPv4 + TCP flow.
Definition: DpdkDevice.h:185
@ RSS_VXLAN
VXLAN protocol based flow.
Definition: DpdkDevice.h:215
uint16_t flushTxBuffer(bool flushOnlyIfTimeoutExpired=false, uint16_t txQueueId=0)
uint16_t getNumOfOpenedTxQueues() const
Definition: DpdkDevice.h:420
uint16_t sendPackets(MBufRawPacket **rawPacketsArr, uint16_t arrLength, uint16_t txQueueId=0, bool useTxBuffer=false)
void getStatistics(DpdkDeviceStats &stats) const
uint16_t getTotalNumOfTxQueues() const
Definition: DpdkDevice.h:432
bool isDeviceSupportRssHashFunction(DpdkRssHashFunction rssHF) const
DpdkPMDType getPMDType() const
Definition: DpdkDevice.h:379
uint16_t receivePackets(MBufRawPacketVector &rawPacketsArr, uint16_t rxQueueId) const
uint32_t getCurrentCoreId() const
bool startCaptureSingleThread(OnDpdkPacketsArriveCallback onPacketsArrive, void *onPacketsArriveUserCookie)
std::vector< std::string > rssHashFunctionMaskToString(uint64_t rssHFMask) const
std::string getDeviceName() const
Definition: DpdkDevice.h:359
bool openMultiQueues(uint16_t numOfRxQueuesToOpen, uint16_t numOfTxQueuesToOpen, const DpdkDeviceConfiguration &config=DpdkDeviceConfiguration())
Definition: DpdkDeviceList.h:58
Definition: PcapFilter.h:134
Definition: MBufRawPacket.h:45
Definition: MacAddress.h:21
Definition: PointerVector.h:50
Definition: RawPacket.h:269
The main namespace for the PcapPlusPlus lib.
DpdkPMDType
Definition: DpdkDevice.h:79
@ PMD_IGB
Intel 1GbE PMD.
Definition: DpdkDevice.h:88
@ PMD_MLX4
Mellanox ConnectX-3, ConnectX-3 Pro PMD.
Definition: DpdkDevice.h:104
@ PMD_RING
ring-based (memory) PMD
Definition: DpdkDevice.h:110
@ PMD_IXGBEVF
Intel 10GbE virtual function PMD.
Definition: DpdkDevice.h:102
@ PMD_BOND
Definition: DpdkDevice.h:84
@ PMD_AF_PACKET
AF_PACKET PMD.
Definition: DpdkDevice.h:118
@ PMD_I40EVF
Intel 40GbE virtual function PMD.
Definition: DpdkDevice.h:98
@ PMD_UNKNOWN
Unknown PMD type.
Definition: DpdkDevice.h:81
@ PMD_I40E
Intel 40GbE PMD.
Definition: DpdkDevice.h:96
@ PMD_E1000EM
Intel E1000 PMD.
Definition: DpdkDevice.h:86
@ PMD_PCAP
pcap file PMD
Definition: DpdkDevice.h:108
@ PMD_FM10K
Intel fm10k PMD.
Definition: DpdkDevice.h:94
@ PMD_XENVIRT
Xen Project PMD.
Definition: DpdkDevice.h:116
@ PMD_IXGBE
Intel 10GbE PMD.
Definition: DpdkDevice.h:100
@ PMD_VMXNET3
VMWare VMXNET3 PMD.
Definition: DpdkDevice.h:114
@ PMD_ENIC
Cisco enic (UCS Virtual Interface Card) PMD.
Definition: DpdkDevice.h:92
@ PMD_IGBVF
Intel 1GbE virtual function PMD.
Definition: DpdkDevice.h:90
@ PMD_VIRTIO
VirtIO PMD.
Definition: DpdkDevice.h:112
@ PMD_NULL
Null PMD.
Definition: DpdkDevice.h:106
void(* OnDpdkPacketsArriveCallback)(MBufRawPacket *packets, uint32_t numOfPackets, uint8_t threadId, DpdkDevice *device, void *userCookie)
Definition: DpdkDevice.h:129
Definition: DpdkDevice.h:230
uint16_t flushTxBufferTimeout
Definition: DpdkDevice.h:243
DpdkDeviceConfiguration(uint16_t receiveDescriptorsNumber=128, uint16_t transmitDescriptorsNumber=512, uint16_t flushTxBufferTimeout=100, uint64_t rssHashFunction=RSS_DEFAULT, uint8_t *rssKey=DpdkDevice::m_RSSKey, uint8_t rssKeyLength=40)
Definition: DpdkDevice.h:276
uint16_t transmitDescriptorsNumber
Definition: DpdkDevice.h:239
uint8_t * rssKey
Definition: DpdkDevice.h:250
uint8_t rssKeyLength
Definition: DpdkDevice.h:254
uint64_t rssHashFunction
Definition: DpdkDevice.h:260
uint16_t receiveDescriptorsNumber
Definition: DpdkDevice.h:234
Definition: DpdkDevice.h:329
uint64_t rxMbufAlocFailed
Total number of RX mbuf allocation failures.
Definition: DpdkDevice.h:348
uint8_t devId
DpdkDevice ID.
Definition: DpdkDevice.h:331
RxTxStats aggregatedRxStats
RX statistics, aggregated for all RX queues.
Definition: DpdkDevice.h:339
timespec timestamp
The timestamp of when the stats were written.
Definition: DpdkDevice.h:333
uint64_t rxPacketsDroppedByHW
Definition: DpdkDevice.h:344
RxTxStats txStats[16]
TX statistics per TX queue.
Definition: DpdkDevice.h:337
RxTxStats aggregatedTxStats
TX statistics, aggregated for all TX queues.
Definition: DpdkDevice.h:341
RxTxStats rxStats[16]
RX statistics per RX queue.
Definition: DpdkDevice.h:335
uint64_t rxErroneousPackets
Total number of erroneous packets.
Definition: DpdkDevice.h:346
Definition: DpdkDevice.h:294
int linkSpeedMbps
Link speed in Mbps (for example: 10Gbe will show 10000)
Definition: DpdkDevice.h:307
LinkDuplex linkDuplex
Link duplex (half/full duplex)
Definition: DpdkDevice.h:309
LinkDuplex
Enum for describing link duplex.
Definition: DpdkDevice.h:297
@ FULL_DUPLEX
Full duplex.
Definition: DpdkDevice.h:299
@ HALF_DUPLEX
Half duplex.
Definition: DpdkDevice.h:301
bool linkUp
True if link is up, false if it's down.
Definition: DpdkDevice.h:305
Definition: DpdkDevice.h:315
uint64_t packetsPerSec
Packets per second.
Definition: DpdkDevice.h:321
uint64_t bytesPerSec
Bytes per second.
Definition: DpdkDevice.h:323
uint64_t packets
Total number of packets.
Definition: DpdkDevice.h:317
uint64_t bytes
Total number of successfully received bytes.
Definition: DpdkDevice.h:319