Updated on 2024-04-29 GMT+08:00

AS_Path List Overview

Introduction

An AS_Path list is a collection of filters that are used to filter BGP routes based on AS_Path attributes contained in BGP routes. AS_Path attributes record the number of each AS that BGP routes pass through from the source to the destination in distance-vector order.

If two AS_Paths both can enable communications, the AS_Path with a smaller ASN is preferred because it uses a shorter path.

AS_Path attributes are private attributes of BGP and AS_Path filters take effect only on BGP routes.

Match Rules

An AS_Path attribute can be regarded as a string containing spaces and is used to match routes through a regular expression.

As shown in Figure 1, the ASN of ER-A is 100. If a BGP route from the peer passes through ER-A, the ASN 100 of ER-A is automatically added to the left of AS_Path.

Figure 1 ASNs in AS_Paths

A regular expression is a string that describes a characteristic and verifies whether another string conforms to this characteristic. An AS_Path filter defines an AS_Path regular expression to match AS_Path attributes for filtering BGP routes.

An AS_Path list can contain multiple AS_Path filters for route filtering. As shown in Figure 2, routes to be filtered are matched against an AS_Path list by AS_Path filter in ascending order.
  • If a route matches an AS_Path filter with Action set to Allow, the route is allowed. If the AS_Path filter has Action set to Deny, the route is denied.
  • If a route does not match any AS_Path filter in an AS_Path list, the route is denied.
Figure 2 Match process

An AS_Path list filters routes by sequential match, unique match, or deny by default.

  • Sequential match: An AS_Path filter with a smaller number is matched first. AS_Path filters in an AS_Path list can be sorted by sequence number in different orders, leading to different filtering results.
  • Unique match: If a route matches an AS_Path filter, it no longer tries to match other AS_Path filters.
  • Deny by default: By default, routes that do not match any AS_Path filter in an AS_Path list are denied. If an AS_Path list has one or more deny filters, you need to create an AS_Path filter to allow all other routes.

AS_Path Regular Expressions

An AS_Path filter is essentially a regular expression. The content of a regular expression is complex. The following describes the AS_Path filter.

An AS_Path filter uses a regular expression to define matching rules. A regular expression consists of the following parts:

  • Metacharacter: defines matching rules.
  • General character: defines match objects.

Table 1 lists the metacharacters supported by BGP AS_Path regular expressions.

Table 1 AS_Path metacharacters

Metacharacter

Description

Example

.

Matches AS_Paths with any single character except "\n", including spaces.

.* matches any AS_Path or route.

NOTE:

If an AS_Path list has one or more deny filters, you need to create an AS_Path filter to allow all other routes.

*

Matches AS_Paths with 0 or more sequences of the character before the asterisk "*".

See the preceding example.

+

Matches AS_Paths with 1 or more sequences of the character before the plus "+".

65+ matches AS_Paths that begin with 6 and include one 5 or consecutive 5.
  • AS_Path examples that 65+ matches: 65, 655, 6559, 65259, and 65529
  • AS_Path examples that 65+ does not match: 56, 556, 5669, 55269, and 56259

|

Matches any AS_Path with characters on either side of the vertical bar "|".

100|65002|65003 matches 100, 65002, or 65003.

AS_Path examples that 100|65002|65003 matches:
  • 100, 655, 6559
  • 65, 655, 65002
  • 65, 65003, 100

^

Matches AS_Paths beginning with the characters that follow the caret "^".

^65 matches AS_Paths beginning with 65.
  • AS_Path examples that ^65 matches: 65, 651, 6501, and 65001
  • AS_Path examples that 65+ does not match: 165, 1650, 6650, and 60065

$

Matches AS_Paths ending with the characters before the dollar sign "$".

65$ matches AS_Paths ending with 65.
  • AS_Path examples that 65$ matches: 65, 165, 1065, 10065, and 60065
  • AS_Path examples that 65$ does not match: 651, 1650, 6650, 60650, and 65001
NOTE:

^$ matches null character strings (null AS_Path) and can be used to match the locally originated routes.

( )

Defines a subexpression. Both the expression and the subexpression must match.

100(200)+ matches AS_Paths that begin with 100 and include one 200 or consecutive 200.

AS_Path examples that 100(200)+ matches:
  • 100200
  • 100200200
  • 100200200200

[ ]

Matches AS_Paths with any character in the brackets "[ ]".

  • [896] matches AS_Paths with 8, 9, or 6.
  • [2-4] matches AS_Paths with 2, 3, or 4.
  • [0-9] matches AS_Paths with numbers from 0 to 9.
NOTE:

The characters in the brackets "[ ]" can only be numbers 0 to 9. To match AS_Paths within the range of 735 to 907, use (73[5-9]|7[4-9][0-9]|8[0-9][0-9]|90[0-7]).

[^ ]

Matches AS_Paths without any character within the range specified in the brackets "[ ]".

  • [^2-4] matches AS_Paths without 2, 3, or 4.
  • [^0-9] matches AS_Paths without numbers 0 to 9.
  • [^896] matches AS_Paths with any character except 8, 9, and 6.

_

Matches AS_Paths with a sign, such as a comma ",", left brace "{", right brace "}", left parenthesis "(", right parenthesis ")", or space. The underscore "_" can be used at the beginning of a regular expression with the same function as the caret "^" or at the end of a regular expression with the same function as the dollar sign "$".

  • ^65001_ matches AS_Paths that begin with 65001 followed by a sign. Specifically, ^65001_ matches AS_Paths with 65001 as the leftmost ASN (the number of the last AS through which a route passes) or matches the routes sent by peers in AS 65001.
  • _65001_ matches AS_Paths with 65001 or matches routes that pass through AS 65001.
  • _65001$ matches AS_Paths that end with a sign followed by 65001. Specifically, _65001$ matches AS_Paths with 65001 as the rightmost ASN (the number of the first AS through which a route passes) or matches the routes that are originated in AS 65001.

\

Indicates an escape character.

A backslash "\" is used to disable special functions of signs in regular expressions, such as the left parenthesis "(" and right parenthesis ")" in an AS_Confed_Sequence, the left bracket "[" and right bracket "]" in an AS_Confed_Set, and the left brace "{" and right brace "}" in an AS_Set.

  • \(65002_ matches AS_Confed_Sequences that begin with (65002 followed by a sign. Specifically, \(65002_ matches AS_Confed_Sequences with 65002 as the leftmost ASN (the number of the last AS through which a route passes) or matches the routes sent by peers in AS 65002.
  • \(.*_65003_.*\) matches AS_Confed_Sequences with 65003 or matches the routes that pass through AS 65003.
  • _65004\) matches AS_Confed_Sequences that end with a sign followed by 65004). Specifically, _65004\) matches AS_Confed_Sequences with 65004 as the rightmost ASN (the number of the first AS through which a route passes) or matches the routes that are originated in AS 65004.

Notes and Constraints

  • By default, an account can have up to five AS_Path lists.
  • By default, each AS_Path list can have up to 100 AS_Path filters.
  • Changing an AS_Path list will also change the associated routes and traffic routing. To reduce the impact on network performance, an AS_Path list can only be changed once within 40 seconds.