An AS_path attribute is a well-known mandatory
attribute (type code 2). It is the sequence of AS numbers a route
has traversed to reach a destination. The AS that originates the
route adds its own AS number when sending the route to its external
BGP peers. Thereafter, each AS that receives the route and passes it
on to other BGP peers will prepend its own AS number to the list.
Prepending is the act of adding the AS number to the beginning of
the list. The final list represents all the AS numbers that a route
has traversed with the AS number of the AS that originated the route
all the way at the end of the list. This type of AS_path list is
called an AS_sequence, because all the AS numbers are ordered
sequentially.
BGP uses the AS_path attribute as part of the
routing updates (UPDATE packet) to ensure a loop-free topology on
the Internet. Each route that gets passed between BGP peers will
carry a list of all AS numbers that the route has already been
through. If the route is advertised to the AS that originated it,
that AS will see itself as part of the AS_path attribute list and
will not accept the route. BGP speakers prepend their AS numbers
when advertising routing updates to other
ASs (external peers). When the route is passed to a BGP speaker
within the same AS, the AS_path information is left intact.
The Figure illustrates the AS_path attribute at
each instance of the route 172.16.10.0/24, originating in AS1 and
passed to AS2 then AS3 and AS4 and back to AS1. Note how each AS
that passes the route to other external peers adds its own AS number
to the beginning of the list. When the route gets back to AS1, the
BGP border router will realize that this route has already been
through its AS (AS number 1 appears in the list) and would not
accept the route.
AS_path information is one of the attributes BGP
looks at to determine the best route to take to get to a
destination. In comparing two or more different routes, given that
all other attributes are identical, a shorter path is always
preferred. In case of a tie in AS path length, other attributes are
used to make the decision.