class AsNum

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

 Annotated List  Files  Globals  Hierarchy  Index  Top

Public Methods

Public Members

Detailed Description

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.

static const uint16_t AS_INVALID


static const uint16_t AS_TRAN


explicit  AsNum (const uint32_t value)




valuethe value to assign to this AS number.
explicit  AsNum (const uint16_t value)


explicit  AsNum (int value)


explicit  AsNum (const uint8_t *d)


construct from a 2-byte buffer in memory

explicit  AsNum (const uint8_t *d, bool fourbyte)


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.

explicit  AsNum (const string& as_str)


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 ()



Get the non-extended AS number value.

Returns: the non-extended AS number value.

uint32_t  as4 ()



Get the extended AS number value.

Returns: the extended AS number value.

void  copy_out (uint8_t *d)



copy the 16-bit value into a 2-byte memory buffer

void  copy_out4 (uint8_t *d)



copy the 32-bit value into a 4-byte network byte order memory buffer

bool  extended ()



Test if this is an extended AS number.

Returns: true if this is an extended AS number.

bool  operator== (const AsNum& x)



Equality Operator


otherthe right-hand operand to compare against.

Returns: true if the left-hand operand is numerically same as the right-hand operand.

bool  operator< (const AsNum& x)



Less-Than Operator

Returns: true if the left-hand operand is numerically smaller than the right-hand operand.

string  str ()



Convert this AS number from binary form to presentation format.

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

string  short_str ()



string  fourbyte_str ()



Generated by: pavlin on on Wed Jan 7 19:10:36 2009, using kdoc 2.0a54+XORP.