libbgp  0.6
A C++ BGP Library.
bgp-open-message.h
Go to the documentation of this file.
1 
11 #ifndef BGP_OPEN_MSG_H_
12 #define BGP_OPEN_MSG_H_
13 #include <vector>
14 #include <memory>
15 #include <unistd.h>
16 #include "bgp-message.h"
17 #include "bgp-capability.h"
18 
19 namespace libbgp {
20 
27 class BgpOpenMessage : public BgpMessage {
28 public:
29  BgpOpenMessage(BgpLogHandler *logger, bool use_4b_asn);
30  BgpOpenMessage(BgpLogHandler *logger, bool use_4b_asn, uint16_t my_asn, uint16_t hold_time, uint32_t bgp_id);
31  BgpOpenMessage(BgpLogHandler *logger, bool use_4b_asn, uint16_t my_asn, uint16_t hold_time, const char* bgp_id);
32  ~BgpOpenMessage();
33 
34  uint8_t version;
35  uint16_t my_asn;
36  uint16_t hold_time;
37 
38  // bgp-id is in network-byte
39  uint32_t bgp_id;
40 
41  // utility function for setting ASN. will add/edit BgpCapability if in 4b
42  // mode
43  bool setAsn(uint32_t my_asn);
44 
45  // utility function for getting ASN.
46  uint32_t getAsn() const;
47 
48  // utility function for testing capability
49  bool hasCapability(uint8_t code) const;
50 
51  bool addCapability(std::shared_ptr<BgpCapability> capability);
52 
53  ssize_t doPrint(size_t indent, uint8_t **to, size_t *buf_sz) const;
54 
55  ssize_t parse(const uint8_t *from, size_t msg_sz);
56 
57  ssize_t write(uint8_t *to, size_t buf_sz) const;
58 
59  // bgp-fsm only supports 4-bytes asn capability. getCapabilities() allows
60  // you to get a full, read-only list of cpabilities.
61  const std::vector<std::shared_ptr<BgpCapability>>& getCapabilities() const;
62 private:
63  std::vector<std::shared_ptr<BgpCapability>> capabilities;
64  bool use_4b_asn;
65 };
66 
67 }
68 #endif // BGP_OPEN_MSG_H_
ssize_t parse(const uint8_t *from, size_t msg_sz)
Parse a BGP open message body.
bool setAsn(uint32_t my_asn)
Set ASN.
The BgpOpenMessage class.
The BGP Message base.
BgpOpenMessage(BgpLogHandler *logger, bool use_4b_asn)
Construct a new Bgp Open Message:: Bgp Open Message object.
BGP Capabilities.
const std::vector< std::shared_ptr< BgpCapability > > & getCapabilities() const
Get capabilities list.
The BgpMessage base class.
Definition: bgp-message.h:35
Definition: bgp-afi.h:14
The BgpLogHandler class.
ssize_t write(uint8_t *to, size_t buf_sz) const
Serialize a BGP message body.
bool hasCapability(uint8_t code) const
Check if open message has a capability.
ssize_t doPrint(size_t indent, uint8_t **to, size_t *buf_sz) const
Print implementation.
uint32_t getAsn() const
Get ASN.
bool addCapability(std::shared_ptr< BgpCapability > capability)
Add a capability.