libbgp  0.6
A C++ BGP Library.
Public Member Functions | Public Attributes | List of all members
libbgp::BgpOpenMessage Class Reference

The BgpOpenMessage class. More...

#include <bgp-open-message.h>

Inheritance diagram for libbgp::BgpOpenMessage:
Inheritance graph
[legend]
Collaboration diagram for libbgp::BgpOpenMessage:
Collaboration graph
[legend]

Public Member Functions

 BgpOpenMessage (BgpLogHandler *logger, bool use_4b_asn)
 Construct a new Bgp Open Message:: Bgp Open Message object. More...
 
 BgpOpenMessage (BgpLogHandler *logger, bool use_4b_asn, uint16_t my_asn, uint16_t hold_time, uint32_t bgp_id)
 Construct a new Bgp Open Message:: Bgp Open Message object. More...
 
 BgpOpenMessage (BgpLogHandler *logger, bool use_4b_asn, uint16_t my_asn, uint16_t hold_time, const char *bgp_id)
 Construct a new Bgp Open Message:: Bgp Open Message object. More...
 
bool setAsn (uint32_t my_asn)
 Set ASN. More...
 
uint32_t getAsn () const
 Get ASN. More...
 
bool hasCapability (uint8_t code) const
 Check if open message has a capability. More...
 
bool addCapability (std::shared_ptr< BgpCapability > capability)
 Add a capability. More...
 
ssize_t doPrint (size_t indent, uint8_t **to, size_t *buf_sz) const
 Print implementation. More...
 
ssize_t parse (const uint8_t *from, size_t msg_sz)
 Parse a BGP open message body. More...
 
ssize_t write (uint8_t *to, size_t buf_sz) const
 Serialize a BGP message body. More...
 
const std::vector< std::shared_ptr< BgpCapability > > & getCapabilities () const
 Get capabilities list. More...
 
- Public Member Functions inherited from libbgp::BgpMessage
 BgpMessage (BgpLogHandler *logger)
 Construct a new Bgp Message object. More...
 
- Public Member Functions inherited from libbgp::Serializable
 Serializable (BgpLogHandler *logger)
 Construct a new Serializable:: Serializable object. More...
 
 ~Serializable ()
 Destroy the Serializable:: Serializable object.
 
ssize_t print (uint8_t *to, size_t buf_sz) const
 Print the Serializable object as human readable string. More...
 
ssize_t print (size_t indent, uint8_t *to, size_t buf_sz) const
 Print the Serializable object as human readable string, with indentation. More...
 
virtual ssize_t length () const
 Get size in bytes required to serialize the object. More...
 
bool hasError () const
 Check if error information available. More...
 
uint8_t getErrorCode () const
 
uint8_t getErrorSubCode () const
 
const uint8_t * getError () const
 
size_t getErrorLength () const
 
void setLogger (BgpLogHandler *logger)
 Replace logger for this object. More...
 

Public Attributes

uint8_t version
 
uint16_t my_asn
 
uint16_t hold_time
 
uint32_t bgp_id
 
- Public Attributes inherited from libbgp::BgpMessage
uint8_t type
 

Additional Inherited Members

- Protected Member Functions inherited from libbgp::Serializable
void setError (uint8_t err, uint8_t suberr, const uint8_t *data, size_t data_len)
 Set the error information. More...
 
void forwardParseError (const Serializable &other)
 Forward error information from other Serializable object. More...
 
- Static Protected Member Functions inherited from libbgp::Serializable
static ssize_t _print (size_t indent, uint8_t **to, size_t *buf_left, const char *format,...)
 Print helper. More...
 
- Protected Attributes inherited from libbgp::Serializable
uint8_t err_code
 
uint8_t err_subcode
 
size_t err_len
 
uint8_t * err_data
 
BgpLogHandlerlogger
 

Detailed Description

The BgpOpenMessage class.

This is deserializer/serializer for BGP open message body. If you want to deserializer/serializer a full BGP message. Take a look at BgpPacket class.

Examples:
deserialize-and-serialize.cc.

Definition at line 27 of file bgp-open-message.h.

Constructor & Destructor Documentation

◆ BgpOpenMessage() [1/3]

libbgp::BgpOpenMessage::BgpOpenMessage ( BgpLogHandler logger,
bool  use_4b_asn 
)

Construct a new Bgp Open Message:: Bgp Open Message object.

Parameters
loggerPointer to logger object for error logging.
use_4b_asnEnable four octets ASN support.

Definition at line 25 of file bgp-open-message.cc.

◆ BgpOpenMessage() [2/3]

libbgp::BgpOpenMessage::BgpOpenMessage ( BgpLogHandler logger,
bool  use_4b_asn,
uint16_t  my_asn,
uint16_t  hold_time,
uint32_t  bgp_id 
)

Construct a new Bgp Open Message:: Bgp Open Message object.

Parameters
use_4b_asnEnable four octets ASN support.
my_asnLocal ASN (2 octets). If you want to set a four octets ASN, make sure use_4b_asn is true and use BgpOpenMessage::setAsn(uint32_t my_asn)
hold_timeHold timer.
bgp_idLocal BGP ID in network byte order

Definition at line 43 of file bgp-open-message.cc.

References setAsn().

◆ BgpOpenMessage() [3/3]

libbgp::BgpOpenMessage::BgpOpenMessage ( BgpLogHandler logger,
bool  use_4b_asn,
uint16_t  my_asn,
uint16_t  hold_time,
const char *  bgp_id 
)

Construct a new Bgp Open Message:: Bgp Open Message object.

Parameters
use_4b_asnEnable four octets ASN support.
my_asnLocal ASN (2 octets). If you want to set a four octets ASN, make sure use_4b_asn is true and use BgpOpenMessage::setAsn(uint32_t my_asn)
hold_timeHold timer.
bgp_idLocal BGP ID in dotted string notation

Definition at line 61 of file bgp-open-message.cc.

References setAsn().

Member Function Documentation

◆ addCapability()

bool libbgp::BgpOpenMessage::addCapability ( std::shared_ptr< BgpCapability capability)

Add a capability.

Parameters
capabilityThe capability.
Returns
true Capability added.
false Failed to add capability.

Definition at line 371 of file bgp-open-message.cc.

◆ doPrint()

ssize_t libbgp::BgpOpenMessage::doPrint ( size_t  indent,
uint8_t **  to,
size_t *  buf_sz 
) const
virtual

Print implementation.

Parameters
indentindent level.
toThe pointer to the pointer to the string buffer.
buf_szThe pointer to the counter of avaliable buffer space.
Returns
ssize_t ssize_t Bytes written.
Return values
-1Failed to print.
>=0 Bytes written.

Implements libbgp::Serializable.

Definition at line 258 of file bgp-open-message.cc.

References libbgp::Serializable::_print().

◆ getAsn()

uint32_t libbgp::BgpOpenMessage::getAsn ( ) const

Get ASN.

Get ASN of the open message. Will check Capabilities for four octets ASN if four octets ASN support is enabled.

Returns
uint32_t ASN

Definition at line 296 of file bgp-open-message.cc.

◆ getCapabilities()

const std::vector< std::shared_ptr< BgpCapability > > & libbgp::BgpOpenMessage::getCapabilities ( ) const

Get capabilities list.

Returns
const std::vector<std::shared_ptr<BgpCapability>>& Capabilities.

Definition at line 360 of file bgp-open-message.cc.

◆ hasCapability()

bool libbgp::BgpOpenMessage::hasCapability ( uint8_t  code) const

Check if open message has a capability.

Parameters
codeCapability code
Returns
true open message has capability
false open message does not have capability.

Definition at line 347 of file bgp-open-message.cc.

◆ parse()

ssize_t libbgp::BgpOpenMessage::parse ( const uint8_t *  from,
size_t  msg_sz 
)
virtual

Parse a BGP open message body.

Parameters
fromPointer to message body buffer.
msg_szSize of message.
Returns
ssize_t Bytes read.
Return values
-1Parse error. Error may be logged.
>=0Bytes read.
Exceptions
bad_parseInternal parser error.

Implements libbgp::BgpMessage.

Definition at line 79 of file bgp-open-message.cc.

References libbgp::Serializable::setError().

◆ setAsn()

bool libbgp::BgpOpenMessage::setAsn ( uint32_t  my_asn)

Set ASN.

Set ASN of the open message. Will update/create four octets ASN capability if four octets ASN support is enabled.

Parameters
my_asnASN
Returns
true ASN set
false Failed to set ASN
Examples:
deserialize-and-serialize.cc.

Definition at line 319 of file bgp-open-message.cc.

Referenced by BgpOpenMessage().

◆ write()

ssize_t libbgp::BgpOpenMessage::write ( uint8_t *  to,
size_t  buf_sz 
) const
virtual

Serialize a BGP message body.

BgpMessage serializer only serialize message body. (i.e. message without BGP marker and message length field) To serialize a BGP packet, use BgpPacket.

Parameters
toPointer to destination buffer.
buf_szMax write size.
Returns
ssize_t Bytes written.
Return values
-1Serialization error. Error may be logged.
>=0Bytes written.

Implements libbgp::BgpMessage.

Definition at line 205 of file bgp-open-message.cc.

References libbgp::BgpLogHandler::log().


The documentation for this class was generated from the following files: