OpenSDN source code
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
packet_buffer.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2014 Juniper Networks, Inc. All rights reserved.
3  */
4 
5 #ifndef vnsw_agent_pkt_packet_buffer_hpp
6 #define vnsw_agent_pkt_packet_buffer_hpp
7 
8 #include <string>
9 #include <stdint.h>
10 #include <boost/shared_ptr.hpp>
11 #include <boost/shared_array.hpp>
12 #include <base/util.h>
13 
14 class PacketBuffer;
16 struct AgentHdr;
17 class PktHandler;
18 class PktModule;
19 
20 typedef boost::shared_ptr<PacketBuffer> PacketBufferPtr;
21 class PacketBuffer {
22 public:
23  static const uint32_t kDefaultBufferLen = 1024;
24  virtual ~PacketBuffer();
25 
26  uint8_t *buffer() const { return buffer_.get(); }
27  uint16_t buffer_len() const { return buffer_len_; }
28 
29  uint8_t *data() const;
30  uint16_t data_len() const;
31 
32  uint32_t module() const { return module_; }
33  void set_module(uint32_t module) { module_ = module; }
34 
35  void set_len(uint32_t len);
36  bool SetOffset(uint16_t offset);
37 private:
38  friend class PacketBufferManager;
39  PacketBuffer(PacketBufferManager *mgr, uint32_t module, uint16_t len,
40  uint32_t mdata);
41 
42  // Create PacketBuffer from existing memory
43  PacketBuffer(PacketBufferManager *mgr, uint32_t module, uint8_t *buff,
44  uint16_t len, uint16_t data_offset, uint16_t data_len,
45  uint32_t mdata);
46 
47  boost::shared_array<uint8_t> buffer_;
48  uint16_t buffer_len_;
49 
50  uint8_t *data_;
51  uint16_t data_len_;
52 
53  uint32_t module_;
54  uint32_t mdata_;
57 };
58 
60 public:
61  PacketBufferManager(PktModule *pkt_module);
62  virtual ~PacketBufferManager();
63 
64  PacketBufferPtr Allocate(uint32_t module, uint16_t len, uint32_t mdata);
65 
66  PacketBufferPtr Allocate(uint32_t module, uint8_t *buff, uint16_t len,
67  uint16_t data_offset, uint16_t data_len,
68  uint32_t mdata);
69 private:
70  friend class PacketBuffer;
72 
73  uint64_t alloc_;
74  uint64_t free_;
76 
78 };
79 
80 #endif // vnsw_agent_pkt_packet_buffer_hpp
virtual ~PacketBuffer()
boost::shared_ptr< PacketBuffer > PacketBufferPtr
Definition: packet_buffer.h:18
void set_len(uint32_t len)
static const uint32_t kDefaultBufferLen
Definition: packet_buffer.h:23
uint8_t * data_
Definition: packet_buffer.h:50
uint32_t module() const
Definition: packet_buffer.h:32
uint16_t buffer_len_
Definition: packet_buffer.h:48
PacketBuffer(PacketBufferManager *mgr, uint32_t module, uint16_t len, uint32_t mdata)
uint8_t * buffer() const
Definition: packet_buffer.h:26
boost::shared_array< uint8_t > buffer_
Definition: packet_buffer.h:47
PktModule * pkt_module_
Definition: packet_buffer.h:75
uint16_t data_len_
Definition: packet_buffer.h:51
uint32_t module_
Definition: packet_buffer.h:53
uint16_t buffer_len() const
Definition: packet_buffer.h:27
uint8_t * data() const
virtual ~PacketBufferManager()
PacketBufferManager * mgr_
Definition: packet_buffer.h:55
DISALLOW_COPY_AND_ASSIGN(PacketBuffer)
PacketBufferManager(PktModule *pkt_module)
Definition: packet_buffer.cc:9
uint16_t data_len() const
PacketBufferPtr Allocate(uint32_t module, uint16_t len, uint32_t mdata)
void FreeIndication(PacketBuffer *)
uint32_t mdata_
Definition: packet_buffer.h:54
bool SetOffset(uint16_t offset)
void set_module(uint32_t module)
Definition: packet_buffer.h:33
DISALLOW_COPY_AND_ASSIGN(PacketBufferManager)