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

The BgpUpdateMessage class. More...

#include <bgp-update-message.h>

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

Public Member Functions

 BgpUpdateMessage (BgpLogHandler *logger, bool use_4b_asn)
 Construct a new Bgp Update Message:: Bgp Update Message object. More...
 
BgpPathAttribgetAttrib (uint8_t type)
 Get mutable reference to attribute by typecode. More...
 
const BgpPathAttribgetAttrib (uint8_t type) const
 Get const reference to attribute by typecode. More...
 
bool hasAttrib (uint8_t type) const
 Test if update message has an attribute. More...
 
bool addAttrib (const BgpPathAttrib &attrib)
 Add an attribute to the update message. More...
 
bool setAttribs (const std::vector< std::shared_ptr< BgpPathAttrib >> &attrs)
 Replace the attributes list with another attribute list. More...
 
bool dropAttrib (uint8_t type)
 Drop (remove) an attribute from the update message. More...
 
bool updateAttribute (const BgpPathAttrib &attrib)
 Add/Update an attribute. More...
 
bool dropNonTransitive ()
 Drop all non-transitive attributes from the update message. More...
 
bool setNextHop (uint32_t nexthop)
 Set/Create nexthop attribtue. More...
 
bool prepend (uint32_t asn)
 Prepend ASN to AS_PATH and AS4_PATH (if in 2b-mode ans AS4_PATH exists) More...
 
bool restoreAsPath ()
 Restore the AS_PATH attribute to four octets ASN flavor. More...
 
bool downgradeAsPath ()
 Downgrade the AS_PATH to two octets flavor. More...
 
bool restoreAggregator ()
 Restore aggregator attribute from as4_aggregator. More...
 
bool downgradeAggregator ()
 Downgrade aggregator to two octets. More...
 
bool setWithdrawn4 (const std::vector< Prefix4 > &routes)
 Set withdrawn routes. More...
 
bool addWithdrawn4 (uint32_t prefix, uint8_t length)
 Add withdrawn route. More...
 
bool addWithdrawn4 (const Prefix4 &route)
 Add withdrawn route. More...
 
bool setNlri4 (const std::vector< Prefix4 > &routes)
 Set NLRIs. More...
 
bool addNlri4 (uint32_t prefix, uint8_t length)
 Add NLRI route. More...
 
bool addNlri4 (const Prefix4 &route)
 Add NLRI route. More...
 
bool setWithdrawn6 (const std::vector< Prefix6 > &routes)
 
bool setNlri6 (const std::vector< Prefix6 > &routes, const uint8_t nexthop_global[16], const uint8_t nexthop_linklocal[16])
 
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)
 Deserialize a BGP message body. More...
 
ssize_t write (uint8_t *to, size_t buf_sz) const
 Serialize a BGP message body. 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

std::vector< Prefix4withdrawn_routes
 
std::vector< std::shared_ptr< BgpPathAttrib > > path_attribute
 
std::vector< Prefix4nlri
 
- 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 BgpUpdateMessage class.

This is deserializer/serializer for BGP update 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 28 of file bgp-update-message.h.

Constructor & Destructor Documentation

◆ BgpUpdateMessage()

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

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

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

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

Member Function Documentation

◆ addAttrib()

bool libbgp::BgpUpdateMessage::addAttrib ( const BgpPathAttrib attrib)

Add an attribute to the update message.

Parameters
attribThe attribute.
Returns
true Attribute added.
false Failed to add attribute. Likely because another attribute with same type code already exists.

Definition at line 83 of file bgp-update-message.cc.

References libbgp::BgpPathAttrib::clone(), hasAttrib(), and libbgp::BgpPathAttrib::type_code.

Referenced by updateAttribute().

◆ addNlri4() [1/2]

bool libbgp::BgpUpdateMessage::addNlri4 ( uint32_t  prefix,
uint8_t  length 
)

Add NLRI route.

Parameters
prefixRoute prefix in network byte order.
lengthRoute netmask in CIDR notation.
Returns
true Route added.
false Failed to add route.

Definition at line 491 of file bgp-update-message.cc.

◆ addNlri4() [2/2]

bool libbgp::BgpUpdateMessage::addNlri4 ( const Prefix4 route)

Add NLRI route.

Parameters
routeThe route.
Returns
true Route added.
false Failed to add route.

Definition at line 504 of file bgp-update-message.cc.

◆ addWithdrawn4() [1/2]

bool libbgp::BgpUpdateMessage::addWithdrawn4 ( uint32_t  prefix,
uint8_t  length 
)

Add withdrawn route.

Parameters
prefixWithdrawn route prefix in network byte order.
lengthWithdrawn route netmask in CIDR notation.
Returns
true Withdrawn route added.
false Failed to add withdrawn route.

Definition at line 453 of file bgp-update-message.cc.

◆ addWithdrawn4() [2/2]

bool libbgp::BgpUpdateMessage::addWithdrawn4 ( const Prefix4 route)

Add withdrawn route.

Parameters
routeThe withdrawn route.
Returns
true Withdrawn route added.
false Failed to add withdrawn route.

Definition at line 466 of file bgp-update-message.cc.

◆ doPrint()

ssize_t libbgp::BgpUpdateMessage::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 798 of file bgp-update-message.cc.

References libbgp::Serializable::_print().

◆ downgradeAggregator()

bool libbgp::BgpUpdateMessage::downgradeAggregator ( )

Downgrade aggregator to two octets.

Returns
true Aggregator downgraded.
false Failed to downgrade aggregator.

Definition at line 417 of file bgp-update-message.cc.

References hasAttrib().

◆ downgradeAsPath()

bool libbgp::BgpUpdateMessage::downgradeAsPath ( )

Downgrade the AS_PATH to two octets flavor.

Create/Update AS_PATH and make four octets ASNs in AS_PATH AS_TRANS.

Returns
true AS_PATH downgraded.
false Failed to downgrade AS_PATH. error may be written to stderr with log handler.

Definition at line 359 of file bgp-update-message.cc.

References hasAttrib().

◆ dropAttrib()

bool libbgp::BgpUpdateMessage::dropAttrib ( uint8_t  type)

Drop (remove) an attribute from the update message.

Parameters
typeThe attribute typecode.
Returns
true Attribute removed.
false Failed to remove attribute. Likely becuase such attribute does not exist.

Definition at line 113 of file bgp-update-message.cc.

Referenced by updateAttribute().

◆ dropNonTransitive()

bool libbgp::BgpUpdateMessage::dropNonTransitive ( )

Drop all non-transitive attributes from the update message.

Returns
true Some attributes dropped.
false No attribute dropped.

Definition at line 130 of file bgp-update-message.cc.

◆ getAttrib() [1/2]

BgpPathAttrib & libbgp::BgpUpdateMessage::getAttrib ( uint8_t  type)

Get mutable reference to attribute by typecode.

Parameters
typeAttribute typecode.
Returns
BgpPathAttrib& The attribute.
Exceptions
no such attributeif attribute does not exist.

Definition at line 37 of file bgp-update-message.cc.

◆ getAttrib() [2/2]

const BgpPathAttrib & libbgp::BgpUpdateMessage::getAttrib ( uint8_t  type) const

Get const reference to attribute by typecode.

Parameters
typeAttribute typecode.
Returns
const BgpPathAttrib& The attribute.
Exceptions
no such attributeif attribute does not exist.

Definition at line 52 of file bgp-update-message.cc.

◆ hasAttrib()

bool libbgp::BgpUpdateMessage::hasAttrib ( uint8_t  type) const

Test if update message has an attribute.

Parameters
typeAttribute typecode.
Returns
true Attribute avaliable.
false Attribute not avaliable.

Definition at line 67 of file bgp-update-message.cc.

Referenced by addAttrib(), downgradeAggregator(), downgradeAsPath(), prepend(), restoreAggregator(), and restoreAsPath().

◆ parse()

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

Deserialize a BGP message body.

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

Parameters
fromPointer to message body buffer.
msg_szSize of message.
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.

Implements libbgp::BgpMessage.

Definition at line 564 of file bgp-update-message.cc.

References libbgp::Serializable::setError().

◆ prepend()

bool libbgp::BgpUpdateMessage::prepend ( uint32_t  asn)

Prepend ASN to AS_PATH and AS4_PATH (if in 2b-mode ans AS4_PATH exists)

Prepend an ASN to AS_PATH. Depends on the setup, the given ASN may be prepended to AS4_PATH too.

Parameters
asnThr ASN.
Returns
true ASN appended.
false Failed to append ASN. error may be written to stderr with log handler.

Definition at line 180 of file bgp-update-message.cc.

References hasAttrib().

◆ restoreAggregator()

bool libbgp::BgpUpdateMessage::restoreAggregator ( )

Restore aggregator attribute from as4_aggregator.

Returns
true Aggregator restored.
false Failed to restore aggregator.

Definition at line 396 of file bgp-update-message.cc.

References hasAttrib().

◆ restoreAsPath()

bool libbgp::BgpUpdateMessage::restoreAsPath ( )

Restore the AS_PATH attribute to four octets ASN flavor.

Try to restore AS_TRANS in AS_PATH attribute with AS4_PATH.

Returns
true Path restored.
false Failed to restore path. error may be written to stderr with log handler.

Definition at line 245 of file bgp-update-message.cc.

References hasAttrib().

◆ setAttribs()

bool libbgp::BgpUpdateMessage::setAttribs ( const std::vector< std::shared_ptr< BgpPathAttrib >> &  attrs)

Replace the attributes list with another attribute list.

Parameters
attrsList of attributes.
Returns
true List replaced.
false Failed to replace list.

Definition at line 97 of file bgp-update-message.cc.

◆ setNextHop()

bool libbgp::BgpUpdateMessage::setNextHop ( uint32_t  nexthop)

Set/Create nexthop attribtue.

Parameters
nexthopNexthop in network byte order.
Returns
true Nexthop set.
false Failed to set nexthop.

Definition at line 162 of file bgp-update-message.cc.

References libbgp::BgpPathAttribNexthop::next_hop, and updateAttribute().

◆ setNlri4()

bool libbgp::BgpUpdateMessage::setNlri4 ( const std::vector< Prefix4 > &  routes)

Set NLRIs.

Parameters
routesRoutes.
Returns
true Routes set.
false Failed to set routes.

Definition at line 478 of file bgp-update-message.cc.

◆ setWithdrawn4()

bool libbgp::BgpUpdateMessage::setWithdrawn4 ( const std::vector< Prefix4 > &  routes)

Set withdrawn routes.

Parameters
routesWithdrawn routes.
Returns
true Withdrawn routes set.
false Failed to set withdrawn routes.

Definition at line 440 of file bgp-update-message.cc.

◆ updateAttribute()

bool libbgp::BgpUpdateMessage::updateAttribute ( const BgpPathAttrib attrib)

Add/Update an attribute.

Parameters
attribThe attribute.
Returns
true attribute added/updated.
false Failed to update attribute.

Definition at line 150 of file bgp-update-message.cc.

References addAttrib(), dropAttrib(), and libbgp::BgpPathAttrib::type_code.

Referenced by setNextHop().

◆ write()

ssize_t libbgp::BgpUpdateMessage::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 720 of file bgp-update-message.cc.

References libbgp::BgpLogHandler::log().


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