PcapPlusPlus  Next
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 
14 namespace pcpp
15 {
16 
17  class DpdkDevice;
18 #ifdef USE_DPDK_KNI
19  class KniDevice;
20 #endif
21 
22 #define MBUFRAWPACKET_OBJECT_TYPE 1
23 
44  class MBufRawPacket : public RawPacket
45  {
46  friend class DpdkDevice;
47 #ifdef USE_DPDK_KNI
48  friend class KniDevice;
49 #endif
50 
51  protected:
52  struct rte_mbuf* m_MBuf;
53  struct rte_mempool* m_Mempool;
54  uint16_t m_MbufDataSize;
55  bool m_FreeMbuf;
56 
57  void setMBuf(struct rte_mbuf* mBuf, timespec timestamp);
58  bool init(struct rte_mempool* mempool);
59  bool initFromRawPacket(const RawPacket* rawPacket, struct rte_mempool* mempool);
60 
61  public:
66  MBufRawPacket() : RawPacket(), m_MBuf(nullptr), m_Mempool(nullptr), m_MbufDataSize(0), m_FreeMbuf(true)
67  {
68  m_DeleteRawDataAtDestructor = false;
69  }
70 
73  virtual ~MBufRawPacket();
74 
80 
88  bool init(DpdkDevice* device);
89 
90 #ifdef USE_DPDK_KNI
98  bool init(KniDevice* device);
99 #endif
100 
110  bool initFromRawPacket(const RawPacket* rawPacket, DpdkDevice* device);
111 
112 #ifdef USE_DPDK_KNI
122  bool initFromRawPacket(const RawPacket* rawPacket, KniDevice* device);
123 #endif
124 
126  inline rte_mbuf* getMBuf()
127  {
128  return m_MBuf;
129  }
130 
131  // overridden methods
132 
134  inline uint8_t getObjectType() const override
135  {
136  return MBUFRAWPACKET_OBJECT_TYPE;
137  }
138 
144 
148  MBufRawPacket* clone() const override;
149 
165  bool setRawData(const uint8_t* pRawData, int rawDataLen, timespec timestamp,
166  LinkLayerType layerType = LINKTYPE_ETHERNET, int frameLength = -1);
167 
169  void clear();
170 
176  void appendData(const uint8_t* dataToAppend, size_t dataToAppendLen);
177 
185  void insertData(int atIndex, const uint8_t* dataToInsert, size_t dataToInsertLen);
186 
194  bool removeData(int atIndex, size_t numOfBytesToRemove);
195 
201  bool reallocateData(size_t newBufferLength);
202 
206  inline void setFreeMbuf(bool val = true)
207  {
208  m_FreeMbuf = val;
209  }
210  };
211 
215 
216 } // namespace pcpp
217 
218 // GCOVR_EXCL_STOP
Definition: DpdkDevice.h:169
Definition: KniDevice.h:116
Definition: MBufRawPacket.h:45
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:126
void clear()
Clears the object and frees the mbuf.
bool removeData(int atIndex, size_t numOfBytesToRemove)
virtual ~MBufRawPacket()
void setFreeMbuf(bool val=true)
Definition: MBufRawPacket.h:206
MBufRawPacket * clone() const override
Clone this MBufRawPacket object. See copy constructor for details. The caller is responsible for the ...
uint8_t getObjectType() const override
Definition: MBufRawPacket.h:134
bool init(DpdkDevice *device)
Initialize an instance of this class from DpdkDevice. Initialization includes allocating an mbuf from...
MBufRawPacket()
Definition: MBufRawPacket.h:66
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:50
Definition: RawPacket.h:269
The main namespace for the PcapPlusPlus lib.
PointerVector< MBufRawPacket > MBufRawPacketVector
Definition: MBufRawPacket.h:214
LinkLayerType
Definition: RawPacket.h:25
@ LINKTYPE_ETHERNET
Definition: RawPacket.h:29