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 
46  class MBufRawPacket : public RawPacket
47  {
48  friend class DpdkDevice;
49 #ifdef USE_DPDK_KNI
50  friend class KniDevice;
51 #endif
52 
53  protected:
54  struct rte_mbuf* m_MBuf;
55  struct rte_mempool* m_Mempool;
56  uint16_t m_MbufDataSize;
57  bool m_FreeMbuf;
58 
59  void setMBuf(struct rte_mbuf* mBuf, timespec timestamp);
60  bool init(struct rte_mempool* mempool);
61  bool initFromRawPacket(const RawPacket* rawPacket, struct rte_mempool* mempool);
62 
63  public:
68  MBufRawPacket() : RawPacket(), m_MBuf(nullptr), m_Mempool(nullptr), m_MbufDataSize(0), m_FreeMbuf(true)
69  {
70  m_OwnsRawData = false;
71  }
72 
75  virtual ~MBufRawPacket();
76 
82 
90  bool init(DpdkDevice* device);
91 
92 #ifdef USE_DPDK_KNI
100  bool init(KniDevice* device);
101 #endif
102 
112  bool initFromRawPacket(const RawPacket* rawPacket, DpdkDevice* device);
113 
114 #ifdef USE_DPDK_KNI
124  bool initFromRawPacket(const RawPacket* rawPacket, KniDevice* device);
125 #endif
126 
128  inline rte_mbuf* getMBuf()
129  {
130  return m_MBuf;
131  }
132 
133  // overridden methods
134 
136  inline uint8_t getObjectType() const override
137  {
138  return MBUFRAWPACKET_OBJECT_TYPE;
139  }
140 
146 
150  MBufRawPacket* clone() const override;
151 
153  void clear() override;
154 
160  void appendData(const uint8_t* dataToAppend, size_t dataToAppendLen) override;
161 
169  void insertData(int atIndex, const uint8_t* dataToInsert, size_t dataToInsertLen) override;
170 
178  bool removeData(int atIndex, size_t numOfBytesToRemove) override;
179 
185  bool reallocateData(size_t newBufferLength) override;
186 
190  inline void setFreeMbuf(bool val = true)
191  {
192  m_FreeMbuf = val;
193  }
194 
195  protected:
213  bool doSetRawData(const uint8_t* pRawData, int rawDataLen, bool takeOwnership, timespec timestamp,
214  LinkLayerType layerType, int frameLength) override;
215  };
216 
220 
221 } // namespace pcpp
222 
223 // GCOVR_EXCL_STOP
Definition: DpdkDevice.h:168
Definition: KniDevice.h:116
Definition: MBufRawPacket.h:47
bool doSetRawData(const uint8_t *pRawData, int rawDataLen, bool takeOwnership, timespec timestamp, LinkLayerType layerType, int frameLength) override
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)
rte_mbuf * getMBuf()
Definition: MBufRawPacket.h:128
bool removeData(int atIndex, size_t numOfBytesToRemove) override
bool reallocateData(size_t newBufferLength) override
virtual ~MBufRawPacket()
void setFreeMbuf(bool val=true)
Definition: MBufRawPacket.h:190
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:136
void appendData(const uint8_t *dataToAppend, size_t dataToAppendLen) override
bool init(DpdkDevice *device)
Initialize an instance of this class from DpdkDevice. Initialization includes allocating an mbuf from...
MBufRawPacket()
Definition: MBufRawPacket.h:68
MBufRawPacket & operator=(const MBufRawPacket &other)
void insertData(int atIndex, const uint8_t *dataToInsert, size_t dataToInsertLen) override
void clear() override
Clears the object and frees the mbuf.
Definition: PointerVector.h:50
Definition: RawPacket.h:261
The main namespace for the PcapPlusPlus lib.
Definition: AssertionUtils.h:19
LinkLayerType
An enum describing all known link layer type. Taken from: http://www.tcpdump.org/linktypes....
Definition: RawPacket.h:22