PcapPlusPlus  24.09
MBufRawPacket.h
1 #pragma once
2 
3 // GCOVR_EXCL_START
4 
5 #include <time.h>
6 #include "Packet.h"
7 #include "PointerVector.h"
8 
9 struct rte_mbuf;
10 struct rte_mempool;
11 
16 namespace pcpp
17 {
18 
19  class DpdkDevice;
20 #ifdef USE_DPDK_KNI
21  class KniDevice;
22 #endif
23 
24 #define MBUFRAWPACKET_OBJECT_TYPE 1
25 
48  class MBufRawPacket : public RawPacket
49  {
50  friend class DpdkDevice;
51 #ifdef USE_DPDK_KNI
52  friend class KniDevice;
53 #endif
54 
55  protected:
56  struct rte_mbuf* m_MBuf;
57  struct rte_mempool* m_Mempool;
58  uint16_t m_MbufDataSize;
59  bool m_FreeMbuf;
60 
61  void setMBuf(struct rte_mbuf* mBuf, timespec timestamp);
62  bool init(struct rte_mempool* mempool);
63  bool initFromRawPacket(const RawPacket* rawPacket, struct rte_mempool* mempool);
64 
65  public:
72  MBufRawPacket() : RawPacket(), m_MBuf(nullptr), m_Mempool(nullptr), m_MbufDataSize(0), m_FreeMbuf(true)
73  {
74  m_DeleteRawDataAtDestructor = false;
75  }
76 
81  virtual ~MBufRawPacket();
82 
90 
100  bool init(DpdkDevice* device);
101 
102 #ifdef USE_DPDK_KNI
112  bool init(KniDevice* device);
113 #endif
114 
126  bool initFromRawPacket(const RawPacket* rawPacket, DpdkDevice* device);
127 
128 #ifdef USE_DPDK_KNI
140  bool initFromRawPacket(const RawPacket* rawPacket, KniDevice* device);
141 #endif
142 
146  inline rte_mbuf* getMBuf()
147  {
148  return m_MBuf;
149  }
150 
151  // overridden methods
152 
156  inline uint8_t getObjectType() const override
157  {
158  return MBUFRAWPACKET_OBJECT_TYPE;
159  }
160 
168 
186  bool setRawData(const uint8_t* pRawData, int rawDataLen, timespec timestamp,
187  LinkLayerType layerType = LINKTYPE_ETHERNET, int frameLength = -1);
188 
192  void clear();
193 
201  void appendData(const uint8_t* dataToAppend, size_t dataToAppendLen);
202 
212  void insertData(int atIndex, const uint8_t* dataToInsert, size_t dataToInsertLen);
213 
223  bool removeData(int atIndex, size_t numOfBytesToRemove);
224 
232  bool reallocateData(size_t newBufferLength);
233 
239  inline void setFreeMbuf(bool val = true)
240  {
241  m_FreeMbuf = val;
242  }
243  };
244 
250 
251 } // namespace pcpp
252 
253 // GCOVR_EXCL_STOP
Definition: DpdkDevice.h:179
Definition: KniDevice.h:125
Definition: MBufRawPacket.h:49
bool initFromRawPacket(const RawPacket *rawPacket, DpdkDevice *device)
Initialize an instance of this class and copies the content of a RawPacket object....
MBufRawPacket(const MBufRawPacket &other)
void insertData(int atIndex, const uint8_t *dataToInsert, size_t dataToInsertLen)
rte_mbuf * getMBuf()
Definition: MBufRawPacket.h:146
bool removeData(int atIndex, size_t numOfBytesToRemove)
virtual ~MBufRawPacket()
void setFreeMbuf(bool val=true)
Definition: MBufRawPacket.h:239
uint8_t getObjectType() const override
Definition: MBufRawPacket.h:156
bool init(DpdkDevice *device)
Initialize an instance of this class from DpdkDevice. Initialization includes allocating an mbuf from...
MBufRawPacket()
Definition: MBufRawPacket.h:72
MBufRawPacket & operator=(const MBufRawPacket &other)
bool setRawData(const uint8_t *pRawData, int rawDataLen, timespec timestamp, LinkLayerType layerType=LINKTYPE_ETHERNET, int frameLength=-1)
bool reallocateData(size_t newBufferLength)
void appendData(const uint8_t *dataToAppend, size_t dataToAppendLen)
Definition: PointerVector.h:29
Definition: RawPacket.h:269
The main namespace for the PcapPlusPlus lib.
PointerVector< MBufRawPacket > MBufRawPacketVector
Definition: MBufRawPacket.h:249
LinkLayerType
Definition: RawPacket.h:25
@ LINKTYPE_ETHERNET
Definition: RawPacket.h:29