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

IPv4 Route/Prefix related utilities. More...

#include <prefix4.h>

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

Public Member Functions

 Prefix4 ()
 Construct a new Prefix4 object.
 
 Prefix4 (uint32_t prefix, uint8_t length)
 Construct a new Prefix4 object. More...
 
 Prefix4 (const char *prefix, uint8_t length)
 Construct a new Prefix4:: Prefix4 object. More...
 
ssize_t parse (const uint8_t *buffer, size_t buf_sz)
 Parse a IPv4 NLRI prefix from buffer. More...
 
ssize_t write (uint8_t *buffer, size_t buf_sz) const
 Write a IPv4 prefix to NLRI buffer. More...
 
bool includes (uint32_t address) const
 Test if an address is inside this prefix. More...
 
bool includes (const char *address) const
 Test if an address is inside this prefix. More...
 
bool includes (const Prefix &other) const
 Test if another prefix is inside this prefix. More...
 
bool includes (uint32_t prefix, uint8_t length) const
 Test if another prefix is inside this prefix. More...
 
bool includes (const char *prefix, uint8_t length) const
 Test if another prefix is inside this prefix. More...
 
bool operator== (const Prefix &other) const
 Test if two routes are equals. More...
 
bool operator> (const Prefix &other) const
 
bool operator< (const Prefix &other) const
 
bool operator>= (const Prefix &other) const
 
bool operator<= (const Prefix &other) const
 
bool operator!= (const Prefix &other) const
 
bool set (uint32_t prefix, uint8_t length)
 Set Prefix4. More...
 
bool setPrefix (uint32_t prefix)
 Set prefix. More...
 
bool setLength (uint8_t length)
 Set netmask. More...
 
uint32_t getPrefix () const
 Get prefix. More...
 
uint8_t getLength () const
 Get netmask. More...
 
uint32_t getMask () const
 Get netmask. More...
 

Static Public Member Functions

static bool Includes (uint32_t prefix, uint8_t length, uint32_t address)
 Test if an address is inside a prefix. More...
 
static bool Includes (uint32_t prefix_a, uint8_t length_a, uint32_t prefix_b, uint8_t length_b)
 Test if a prefix is inside another prefix. More...
 

Additional Inherited Members

- Public Attributes inherited from libbgp::Prefix
Afi afi
 

Detailed Description

IPv4 Route/Prefix related utilities.

Examples:
route-event-bus.cc, route-filter.cc, and route-server.cc.

Definition at line 25 of file prefix4.h.

Constructor & Destructor Documentation

◆ Prefix4() [1/2]

libbgp::Prefix4::Prefix4 ( uint32_t  prefix,
uint8_t  length 
)

Construct a new Prefix4 object.

Parameters
prefixPrefix in network bytes order.
lengthNetmask in CIDR notation.
Exceptions
bad_route_lengthNetmask invalid.

Definition at line 54 of file prefix4.cc.

◆ Prefix4() [2/2]

libbgp::Prefix4::Prefix4 ( const char *  prefix,
uint8_t  length 
)

Construct a new Prefix4:: Prefix4 object.

Parameters
prefixPrefix in dotted string notation.
lengthNetmask in CIDR notation.
Exceptions
bad_route_lengthNetmask invalid.

Definition at line 68 of file prefix4.cc.

Member Function Documentation

◆ getLength()

uint8_t libbgp::Prefix4::getLength ( ) const

Get netmask.

Returns
uint8_t The netmask in CIDR notation.

Definition at line 297 of file prefix4.cc.

◆ getMask()

uint32_t libbgp::Prefix4::getMask ( ) const

Get netmask.

Returns
uint32_t The netmask in network byte order.
Exceptions
bad_route_lengthNetmask invalid.

Definition at line 307 of file prefix4.cc.

◆ getPrefix()

uint32_t libbgp::Prefix4::getPrefix ( ) const

Get prefix.

Returns
uint32_t The prefix in network byte order.

Definition at line 288 of file prefix4.cc.

◆ Includes() [1/2]

bool libbgp::Prefix4::Includes ( uint32_t  prefix,
uint8_t  length,
uint32_t  address 
)
static

Test if an address is inside a prefix.

Parameters
prefixThe prefix in network bytes order.
lengthThe netmask of prefix in CIDR notation.
addressThe address in network bytes order.
Returns
true The address is in the prefix.
false The address in not in the prefix.

Definition at line 120 of file prefix4.cc.

◆ Includes() [2/2]

bool libbgp::Prefix4::Includes ( uint32_t  prefix_a,
uint8_t  length_a,
uint32_t  prefix_b,
uint8_t  length_b 
)
static

Test if a prefix is inside another prefix.

Parameters
prefix_aThe prefix in network bytes order.
length_aThe netmask of prefix in CIDR notation.
prefix_bThe prefix to test against.
length_bThe netmask of prefix to test against in CIDR notation.
Returns
true prefix_b is in prefix_a.
false prefix_b is not in prefix_a.

Definition at line 135 of file prefix4.cc.

◆ includes() [1/5]

bool libbgp::Prefix4::includes ( uint32_t  address) const

Test if an address is inside this prefix.

Parameters
addressThe address in network bytes order.
Returns
true The address is in the prefix.
false The address in not in the prefix.

Definition at line 148 of file prefix4.cc.

Referenced by includes().

◆ includes() [2/5]

bool libbgp::Prefix4::includes ( const char *  address) const

Test if an address is inside this prefix.

Parameters
addressThe address in dotted string notation.
Returns
true The address is in the prefix.
false The address in not in the prefix.

Definition at line 159 of file prefix4.cc.

References includes().

◆ includes() [3/5]

bool libbgp::Prefix4::includes ( const Prefix other) const
virtual

Test if another prefix is inside this prefix.

Parameters
otherThe other prefix.
Returns
true The other prefix is in this prefix.
false The other prefix is not in this prefix.

Implements libbgp::Prefix.

Definition at line 186 of file prefix4.cc.

◆ includes() [4/5]

bool libbgp::Prefix4::includes ( uint32_t  prefix,
uint8_t  length 
) const

Test if another prefix is inside this prefix.

Parameters
prefixThe prefix in network bytes order.
lengthThe netmask of prefix in CIDR notation.
Returns
true The other prefix is in this prefix.
false The other prefix is not in this prefix.

Definition at line 173 of file prefix4.cc.

◆ includes() [5/5]

bool libbgp::Prefix4::includes ( const char *  prefix,
uint8_t  length 
) const

Test if another prefix is inside this prefix.

Parameters
prefixThe prefix in dotted string notation.
lengthThe netmask of prefix in CIDR notation.
Returns
true The other prefix is in this prefix.
false The other prefix is not in this prefix.

Definition at line 200 of file prefix4.cc.

References includes().

◆ operator==()

bool libbgp::Prefix4::operator== ( const Prefix other) const
virtual

Test if two routes are equals.

Parameters
otherThe other route object.
Returns
true The routes are equal.
false The routes are different.

Implements libbgp::Prefix.

Definition at line 213 of file prefix4.cc.

◆ parse()

ssize_t libbgp::Prefix4::parse ( const uint8_t *  buffer,
size_t  buf_sz 
)
virtual

Parse a IPv4 NLRI prefix from buffer.

Parameters
bufferBuffer to parse from.
buf_szSize of the buffer.
Returns
ssize_t Bytes read.
Return values
-1Failed to parse prefix.
>=0Bytes read.

Implements libbgp::Prefix.

Definition at line 84 of file prefix4.cc.

◆ set()

bool libbgp::Prefix4::set ( uint32_t  prefix,
uint8_t  length 
)

Set Prefix4.

Parameters
prefixThe prefix in netowkr byte order.
lengthThe netmask in CIDR notation.
Returns
true Prefix4 set.
false Failed to set route.

Definition at line 251 of file prefix4.cc.

◆ setLength()

bool libbgp::Prefix4::setLength ( uint8_t  length)

Set netmask.

Parameters
lengthThe netmask in CIDR notation.
Returns
true Netmask set.
false Failed to set netmask.

Definition at line 277 of file prefix4.cc.

◆ setPrefix()

bool libbgp::Prefix4::setPrefix ( uint32_t  prefix)

Set prefix.

Parameters
prefixThe prefix to set in network byte order.
Returns
true Prefix set.
false Failed to set prefix.

Definition at line 265 of file prefix4.cc.

◆ write()

ssize_t libbgp::Prefix4::write ( uint8_t *  buffer,
size_t  buf_sz 
) const
virtual

Write a IPv4 prefix to NLRI buffer.

Parameters
bufferBuffer to write to.
buf_szSize of the buffer (max write size).
Returns
ssize_t Bytes written.
Return values
-1Failed to write.
>=0Bytes written.

Implements libbgp::Prefix.

Definition at line 103 of file prefix4.cc.


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