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

The BgpPacket class. More...

#include <bgp-packet.h>

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

Public Member Functions

 BgpPacket (BgpLogHandler *logger, bool is_4b, const BgpMessage *msg)
 Construct a new BgpPacket object for serializing BGP message. More...
 
 BgpPacket (BgpLogHandler *logger, bool is_4b)
 Construct a new BgpPacket object for deserializing BGP message. 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 buf_sz)
 Deserialize a BGP message. More...
 
ssize_t write (uint8_t *to, size_t buf_sz) const
 Serialize a BGP message. More...
 
const BgpMessagegetMessage () const
 Get pointer to the contained message. 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...
 

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 BgpPacket class.

BgpPacket class is the top level deserialization/serialization entry point for BGP messages. This is what you should use if you wish to serialize/deserialize a BGP message.

Examples:
deserialize-and-serialize.cc.

Definition at line 26 of file bgp-packet.h.

Constructor & Destructor Documentation

◆ BgpPacket() [1/2]

libbgp::BgpPacket::BgpPacket ( BgpLogHandler logger,
bool  is_4b,
const BgpMessage msg 
)

Construct a new BgpPacket object for serializing BGP message.

Parameters
loggerPointer to logger object for error logging.
is_4bEnable four octets ASN support.
msgThe message to be serialized

Definition at line 39 of file bgp-packet.cc.

◆ BgpPacket() [2/2]

libbgp::BgpPacket::BgpPacket ( BgpLogHandler logger,
bool  is_4b 
)

Construct a new BgpPacket object for deserializing BGP message.

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

Definition at line 25 of file bgp-packet.cc.

Member Function Documentation

◆ doPrint()

ssize_t libbgp::BgpPacket::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 50 of file bgp-packet.cc.

References libbgp::Serializable::print().

◆ getMessage()

const BgpMessage * libbgp::BgpPacket::getMessage ( ) const

Get pointer to the contained message.

Returns
const BgpMessage* Pointer to the message.
Examples:
deserialize-and-serialize.cc.

Definition at line 172 of file bgp-packet.cc.

◆ parse()

ssize_t libbgp::BgpPacket::parse ( const uint8_t *  from,
size_t  buf_sz 
)
virtual

Deserialize a BGP message.

Parameters
fromPointer to packet buffer.
msg_szSize of packet.
Returns
ssize_t Bytes read.
Return values
-1Deserialization error. Error may be logged.
>=0Bytes read.
Exceptions
bad_parseInternal deserialization error.
bad_typeThe type of message/field member in buffer does not match the attribute type of container.
invalid_opInvalid operation.

Implements libbgp::Serializable.

Examples:
deserialize-and-serialize.cc.

Definition at line 75 of file bgp-packet.cc.

References libbgp::BgpLogHandler::log().

◆ write()

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

Serialize a BGP message.

Parameters
fromPointer to packet buffer.
msg_szSize of packet.
Returns
ssize_t Bytes written.
Return values
-1Serialization error. Error may be logged.
>=0Bytes written.
Exceptions
invalid_opInvalid operation.

Implements libbgp::Serializable.

Examples:
deserialize-and-serialize.cc.

Definition at line 128 of file bgp-packet.cc.

References libbgp::BgpLogHandler::log().


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