xorp

AsNum Class Reference

A class for storing an AS number used by protocols such as BGP. More...

#include <asnum.hh>

List of all members.

Public Member Functions

 AsNum (const uint32_t value)
 Constructor.
 AsNum (const uint16_t value)
 AsNum (int value)
 AsNum (const uint8_t *d)
 construct from a 2-byte buffer in memory
 AsNum (const uint8_t *d, bool fourbyte)
 construct from a 2-byte buffer in memory or a 4 byte buffer (in net byte order).
 AsNum (const string &as_str) throw (InvalidString)
 construct from a string, either as a decimal number in the range 1-65535, or as two decimal numbers x.y, where x and y are in the range 0-65535
uint16_t as () const
 Get the non-extended AS number value.
uint32_t as4 () const
 Get the extended AS number value.
void copy_out (uint8_t *d) const
 copy the 16-bit value into a 2-byte memory buffer
void copy_out4 (uint8_t *d) const
 copy the 32-bit value into a 4-byte network byte order memory buffer
bool extended () const
 Test if this is an extended AS number.
bool operator== (const AsNum &x) const
 Equality Operator.
bool operator< (const AsNum &x) const
 Less-Than Operator.
string str () const
 Convert this AS number from binary form to presentation format.
string short_str () const
string fourbyte_str () const

Static Public Attributes

static const uint16_t AS_INVALID = 0
static const uint16_t AS_TRAN = 23456

Private Attributes

uint32_t _as

Detailed Description

A class for storing an AS number used by protocols such as BGP.

This class can be used to store an AS number that can be either 16 or 32 bits. Originally, the AS numbers were defined as 16-bit unsigned numbers. Later the "extended" AS numbers were introduced, which are unsigned 32-bit numbers. Conventional terminology refers to the 32-bit version as 4-byte AS numbers rather than 32-bit AS numbers, so we'll try and stick with that where it makes sense.

2-byte numbers are expanded to 32-bits by extending them with 0's in front. 4-byte numbers are represented in a 2-byte AS path, by a special 16-bit value, AS_TRAN, which will be allocated by IANA. Together with any AsPath containing AS_TRAN, we will always see a AS4_PATH attribute which contains the full 32-bit representation of the path. So there is no loss of information.

IANA refers to NEW_AS_PATH, but the latest internet drafts refer to AS4_PATH. They're the same thing, but I the latter is preferred so we'll use that.

The internal representation of an AsNum is 32-bit in host order.

The canonical string form of a 4-byte AS number is <high>.<low>, so decimal 65536 ends up being printed as "1.0".

An AsNum must always be initialized, so the default constructor is never called.


Constructor & Destructor Documentation

AsNum::AsNum ( const uint32_t  value) [inline, explicit]

Constructor.

Parameters:
valuethe value to assign to this AS number.
AsNum::AsNum ( const uint8_t *  d,
bool  fourbyte 
) [inline, explicit]

construct from a 2-byte buffer in memory or a 4 byte buffer (in net byte order).

The 4byte parameter is mostly to distinguish this from the 2-byte constructor above.


Member Function Documentation

uint16_t AsNum::as ( ) const [inline]

Get the non-extended AS number value.

Returns:
the non-extended AS number value.
uint32_t AsNum::as4 ( ) const [inline]

Get the extended AS number value.

Returns:
the extended AS number value.
bool AsNum::extended ( ) const [inline]

Test if this is an extended AS number.

Returns:
true if this is an extended AS number.
bool AsNum::operator< ( const AsNum x) const [inline]

Less-Than Operator.

Returns:
true if the left-hand operand is numerically smaller than the right-hand operand.
bool AsNum::operator== ( const AsNum x) const [inline]

Equality Operator.

Parameters:
otherthe right-hand operand to compare against.
Returns:
true if the left-hand operand is numerically same as the right-hand operand.
string AsNum::str ( ) const [inline]

Convert this AS number from binary form to presentation format.

Returns:
C++ string with the human-readable ASCII representation of the AS number.

The documentation for this class was generated from the following file:
 All Classes Namespaces Functions Variables Typedefs Enumerations