libbgp
0.6
A C++ BGP Library.
|
The serializable base class. More...
#include <serializable.h>
Public Member Functions | |
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 | parse (const uint8_t *from, size_t msg_sz)=0 |
Deserialize the object from buffer. More... | |
virtual ssize_t | write (uint8_t *to, size_t buf_sz) const =0 |
Serialize the object and write to buffer. 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... | |
Protected Member Functions | |
virtual ssize_t | doPrint (size_t indent, uint8_t **to, size_t *buf_sz) const =0 |
Print implementation. More... | |
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 | |
static ssize_t | _print (size_t indent, uint8_t **to, size_t *buf_left, const char *format,...) |
Print helper. More... | |
Protected Attributes | |
uint8_t | err_code |
uint8_t | err_subcode |
size_t | err_len |
uint8_t * | err_data |
BgpLogHandler * | logger |
The serializable base class.
Definition at line 26 of file serializable.h.
libbgp::Serializable::Serializable | ( | BgpLogHandler * | logger | ) |
Construct a new Serializable:: Serializable object.
logger | Logger for serializer/deserializer errors. |
Definition at line 23 of file serializable.cc.
|
staticprotected |
Print helper.
Print helper prints string to buffer with printf format, increment the buffer pointer and decrease the available buffer pointer.
indent | indent level. |
to | The pointer to the pointer to the string buffer. |
buf_left | The pointer to the counter of avaliable buffer space. |
format | The printf format string. |
... |
-1 | Failed to print. |
>=0 | Bytes written. |
Definition at line 144 of file serializable.cc.
Referenced by libbgp::BgpBadMessage::doPrint(), libbgp::BgpKeepaliveMessage::doPrint(), libbgp::BgpOpenMessage::doPrint(), libbgp::BgpNotificationMessage::doPrint(), libbgp::BgpPathAttrib::doPrint(), libbgp::BgpCapability4BytesAsn::doPrint(), libbgp::BgpUpdateMessage::doPrint(), libbgp::BgpCapabilityMpBgp::doPrint(), libbgp::BgpCapabilityUnknow::doPrint(), libbgp::BgpPathAttribOrigin::doPrint(), libbgp::BgpPathAttribAsPath::doPrint(), libbgp::BgpPathAttribNexthop::doPrint(), libbgp::BgpPathAttribMed::doPrint(), libbgp::BgpPathAttribLocalPref::doPrint(), libbgp::BgpPathAttribAtomicAggregate::doPrint(), libbgp::BgpPathAttribAggregator::doPrint(), libbgp::BgpPathAttribAs4Path::doPrint(), libbgp::BgpPathAttribAs4Aggregator::doPrint(), libbgp::BgpPathAttribCommunity::doPrint(), libbgp::BgpPathAttribMpReachNlriIpv6::doPrint(), libbgp::BgpPathAttribMpReachNlriUnknow::doPrint(), libbgp::BgpPathAttribMpUnreachNlriIpv6::doPrint(), libbgp::BgpPathAttribMpUnreachNlriUnknow::doPrint(), and libbgp::BgpPathAttrib::printFlags().
|
protectedpure virtual |
Print implementation.
indent | indent level. |
to | The pointer to the pointer to the string buffer. |
buf_sz | The pointer to the counter of avaliable buffer space. |
-1 | Failed to print. |
>= | 0 Bytes written. |
Implemented in libbgp::BgpPathAttribMpUnreachNlriUnknow, libbgp::BgpPathAttribMpUnreachNlriIpv6, libbgp::BgpPathAttribMpReachNlriUnknow, libbgp::BgpPathAttribMpReachNlriIpv6, libbgp::BgpPathAttribCommunity, libbgp::BgpPathAttribAs4Aggregator, libbgp::BgpPathAttribAs4Path, libbgp::BgpPathAttribAggregator, libbgp::BgpPathAttribAtomicAggregate, libbgp::BgpPathAttribLocalPref, libbgp::BgpPathAttribMed, libbgp::BgpPathAttribNexthop, libbgp::BgpPathAttribAsPath, libbgp::BgpPathAttribOrigin, libbgp::BgpCapabilityUnknow, libbgp::BgpCapabilityMpBgp, libbgp::BgpUpdateMessage, libbgp::BgpCapability4BytesAsn, libbgp::BgpPathAttrib, libbgp::BgpNotificationMessage, libbgp::BgpOpenMessage, libbgp::BgpKeepaliveMessage, libbgp::BgpPacket, and libbgp::BgpBadMessage.
Referenced by print().
|
protected |
Forward error information from other Serializable object.
other | The other Serializable object. |
Definition at line 97 of file serializable.cc.
References setError().
bool libbgp::Serializable::hasError | ( | ) | const |
Check if error information available.
Definition at line 45 of file serializable.cc.
Referenced by libbgp::BgpPathAttrib::clone(), libbgp::BgpPathAttribOrigin::clone(), libbgp::BgpPathAttribAsPath::clone(), libbgp::BgpPathAttribNexthop::clone(), libbgp::BgpPathAttribMed::clone(), libbgp::BgpPathAttribLocalPref::clone(), libbgp::BgpPathAttribAtomicAggregate::clone(), libbgp::BgpPathAttribAggregator::clone(), libbgp::BgpPathAttribAs4Path::clone(), libbgp::BgpPathAttribAs4Aggregator::clone(), libbgp::BgpPathAttribCommunity::clone(), libbgp::BgpPathAttribMpReachNlriIpv6::clone(), libbgp::BgpPathAttribMpReachNlriUnknow::clone(), libbgp::BgpPathAttribMpUnreachNlriIpv6::clone(), and libbgp::BgpPathAttribMpUnreachNlriUnknow::clone().
|
virtual |
Get size in bytes required to serialize the object.
-1 | Failed to get size. |
>=0 | Size in btyes. |
Reimplemented in libbgp::BgpPathAttribMpUnreachNlriUnknow, libbgp::BgpPathAttribMpUnreachNlriIpv6, libbgp::BgpPathAttribMpReachNlriUnknow, libbgp::BgpPathAttribMpReachNlriIpv6, libbgp::BgpPathAttribCommunity, libbgp::BgpPathAttribAs4Aggregator, libbgp::BgpPathAttribAs4Path, libbgp::BgpPathAttribAggregator, libbgp::BgpPathAttribAtomicAggregate, libbgp::BgpPathAttribLocalPref, libbgp::BgpPathAttribMed, libbgp::BgpPathAttribNexthop, libbgp::BgpPathAttribAsPath, libbgp::BgpPathAttribOrigin, and libbgp::BgpPathAttrib.
Definition at line 176 of file serializable.cc.
References libbgp::BgpLogHandler::log().
Referenced by libbgp::BgpCapability::BgpCapability(), libbgp::BgpCapabilityUnknow::parse(), libbgp::BgpCapabilityUnknow::write(), and libbgp::BgpCapabilityUnknow::~BgpCapabilityUnknow().
|
pure virtual |
Deserialize the object from buffer.
from | The pointer to buffer. |
msg_sz | The max read length of deserializer. |
-1 | Deserialization failed. error may be written to stderr with log handler. |
>=0 | Bytes read. |
Implemented in libbgp::BgpPathAttribMpUnreachNlriUnknow, libbgp::BgpPathAttribMpUnreachNlriIpv6, libbgp::BgpPathAttribMpReachNlriUnknow, libbgp::BgpPathAttribMpReachNlriIpv6, libbgp::BgpPathAttribCommunity, libbgp::BgpPathAttribAs4Aggregator, libbgp::BgpPathAttribAs4Path, libbgp::BgpPathAttribAggregator, libbgp::BgpPathAttribAtomicAggregate, libbgp::BgpPathAttribLocalPref, libbgp::BgpPathAttribMed, libbgp::BgpPathAttribNexthop, libbgp::BgpPathAttribAsPath, libbgp::BgpPathAttribOrigin, libbgp::BgpCapabilityUnknow, libbgp::BgpCapabilityMpBgp, libbgp::BgpUpdateMessage, libbgp::BgpPathAttrib, libbgp::BgpCapability4BytesAsn, libbgp::BgpCapability, libbgp::BgpMessage, libbgp::BgpNotificationMessage, libbgp::BgpOpenMessage, libbgp::BgpPacket, libbgp::BgpKeepaliveMessage, and libbgp::BgpBadMessage.
ssize_t libbgp::Serializable::print | ( | uint8_t * | to, |
size_t | buf_sz | ||
) | const |
Print the Serializable object as human readable string.
to | The pointer to the string buffer. |
buf_sz | The length of string buffer. |
-1 | Failed to print. |
>= | 0 Bytes written. |
Definition at line 110 of file serializable.cc.
References doPrint().
Referenced by libbgp::BgpPacket::doPrint(), and libbgp::BgpLogHandler::log().
ssize_t libbgp::Serializable::print | ( | size_t | indent, |
uint8_t * | to, | ||
size_t | buf_sz | ||
) | const |
Print the Serializable object as human readable string, with indentation.
indent | indent level. |
to | The pointer to the string buffer. |
buf_sz | The length of string buffer. |
-1 | Failed to print. |
>= | 0 Bytes written. |
Definition at line 125 of file serializable.cc.
References doPrint().
|
protected |
Set the error information.
Set the error information. The information is used by BgpFsm to send NOTIFICATION
message to the peer.
err | The error code. |
suberr | The error subcode. |
data | The error data buffer. |
data_len | The length of error data buffer. |
err_exist | Error already set. |
Definition at line 61 of file serializable.cc.
References libbgp::BgpLogHandler::log().
Referenced by forwardParseError(), libbgp::BgpKeepaliveMessage::parse(), libbgp::BgpOpenMessage::parse(), libbgp::BgpNotificationMessage::parse(), libbgp::BgpPathAttrib::parse(), libbgp::BgpUpdateMessage::parse(), libbgp::BgpCapability::parseHeader(), and libbgp::BgpPathAttrib::parseHeader().
void libbgp::Serializable::setLogger | ( | BgpLogHandler * | logger | ) |
Replace logger for this object.
logger | The new logger. |
Definition at line 187 of file serializable.cc.
Referenced by libbgp::BgpPathAttrib::clone().
|
pure virtual |
Serialize the object and write to buffer.
to | The pointer to buffer. |
buf_sz | The max write size of serializer. |
-1 | Serialization failed. error may be written to stderr with log handler. |
>=0 | Bytes written. |
Implemented in libbgp::BgpPathAttribMpUnreachNlriUnknow, libbgp::BgpPathAttribMpUnreachNlriIpv6, libbgp::BgpPathAttribMpReachNlriUnknow, libbgp::BgpPathAttribMpReachNlriIpv6, libbgp::BgpPathAttribCommunity, libbgp::BgpPathAttribAs4Aggregator, libbgp::BgpPathAttribAs4Path, libbgp::BgpPathAttribAggregator, libbgp::BgpPathAttribAtomicAggregate, libbgp::BgpPathAttribLocalPref, libbgp::BgpPathAttribMed, libbgp::BgpPathAttribNexthop, libbgp::BgpPathAttribAsPath, libbgp::BgpPathAttribOrigin, libbgp::BgpCapabilityUnknow, libbgp::BgpCapabilityMpBgp, libbgp::BgpPathAttrib, libbgp::BgpUpdateMessage, libbgp::BgpCapability4BytesAsn, libbgp::BgpMessage, libbgp::BgpCapability, libbgp::BgpNotificationMessage, libbgp::BgpOpenMessage, libbgp::BgpPacket, libbgp::BgpKeepaliveMessage, and libbgp::BgpBadMessage.