libbgp  0.6
A C++ BGP Library.
bgp-packet.h
Go to the documentation of this file.
1 
11 #ifndef BGP_PACKET_H_
12 #define BGP_PACKET_H_
13 #include "serializable.h"
14 #include "bgp-message.h"
15 
16 namespace libbgp {
17 
26 class BgpPacket : public Serializable {
27 public:
28  BgpPacket(BgpLogHandler *logger, bool is_4b, const BgpMessage *msg);
29  BgpPacket(BgpLogHandler *logger, bool is_4b);
30  virtual ~BgpPacket();
31  ssize_t doPrint(size_t indent, uint8_t **to, size_t *buf_sz) const;
32 
33  // notice: BgpPacket::parse assume the buffer contains one valid bgp message
34  // (i.e.) poured from bgp-sink. in other words, BgpPacket::parse assume
35  // the length field in message header is valid and bgp marker is correct.
36  ssize_t parse(const uint8_t *from, size_t buf_sz);
37  ssize_t write(uint8_t *to, size_t buf_sz) const;
38  const BgpMessage *getMessage() const;
39 private:
40  BgpMessage *m_msg;
41  const BgpMessage *msg;
42 
43  // is the BgpMessage owned by us? (i.e. created by parse())
44  // we will need to delete the object if this is the case.
45  bool is_message_owner;
46 
47  bool is_4b;
48 };
49 
57 }
58 #endif // BGP_PACKET_H_
BgpPacket(BgpLogHandler *logger, bool is_4b, const BgpMessage *msg)
Construct a new BgpPacket object for serializing BGP message.
Definition: bgp-packet.cc:39
ssize_t doPrint(size_t indent, uint8_t **to, size_t *buf_sz) const
Print implementation.
Definition: bgp-packet.cc:50
The BGP Message base.
The serializable base class.
Definition: serializable.h:26
const BgpMessage * getMessage() const
Get pointer to the contained message.
Definition: bgp-packet.cc:172
ssize_t parse(const uint8_t *from, size_t buf_sz)
Deserialize a BGP message.
Definition: bgp-packet.cc:75
The BgpMessage base class.
Definition: bgp-message.h:35
Definition: bgp-afi.h:14
The BgpLogHandler class.
The BgpPacket class.
Definition: bgp-packet.h:26
The serializable base.
ssize_t write(uint8_t *to, size_t buf_sz) const
Serialize a BGP message.
Definition: bgp-packet.cc:128