A BGP AS path is a path to a destination. An AS path consists of the AS numbers of networks that a packet traverses if it takes the associated route to a destination. The AS numbers are assembled in a sequence, or path, that is read from right to left. For example, for a packet to reach a destination using a route with an AS path 5 4 3 2 1, the packet first traverses AS 1 and so on until it reaches AS 5, which is the last AS before its destination.
You can define a match condition based on all or portions of the AS path. To do this, you create a named AS path regular expression and then include it in a routing policy.
The following sections discuss the following tasks for configuring AS path regular expressions and provides the following examples:
You can create a named AS path regular expression and then include it in a routing policy with the as-path match condition (described in Configuring Match Conditions in Routing Policy Terms). To create a named AS path regular expression, include the as-path statement:
You can include this statement at the following hierarchy levels:
To include the AS path regular expression in a routing policy, include the as-path match condition in the from statement:
- as-path name regular-expression;
- policy-statement policy-name {
-
- term term-name {
-
- from {
- names;
- }
- }
- }
Additionally, you can create a named AS path group made up of AS path regular expressions and then include it in a routing policy with the as-path-group match condition. To create a named AS path group, include the as-path-group statement:
You can include this statement at the following hierarchy levels:
To include the AS path regular expressions within the AS path group in a routing policy, include the as-path-group match condition in the from statement:
- as-path-group group-name {
- name [ regular-expressions ];
- }
- policy-statement policy-name {
-
- term term-name {
-
- from {
- as-path-group group-name;
- }
- }
- }
![]() |
Note: You cannot include both of the as-path and as-path-group statements in the same policy term. |
![]() |
Note: You can include the names of multiple AS path regular expressions in the as-path match condition in the from statement. If you do this, only one AS path regular expression needs to match for a match to occur. The AS path regular expression matching is effectively a logical OR operation. |
The AS path name identifies the regular expression. It can contain letters, numbers, and hyphens (-), and can be up to 255 characters. To include spaces in the name, enclose the entire name in quotation marks (“ ”).
The regular expression is used to match all or portions of the AS path. It consists of two components, which you specify in the following format:
In JUNOS Release 9.1 and later, you can specify 4-byte AS numbers as defined in RFC 4893, BGP Support for Four-octet AS Number Space, as well as the 2-byte AS numbers that are supported in earlier releases of the JUNOS software. You can configure a value in the range from 1 through 4,294,967,295. For more information about configuring AS numbers, see the JUNOS Routing Protocols Configuration Guide.
You can specify one or more term–operator pairs in a single regular expression.
Table 17 shows examples of how to define regular expressions to match AS paths.
Table 16: AS Path Regular Expression Operators
Table 17: Examples of AS Path Regular Expressions
You can use AS path regular expressions to create a null AS path that matches routes (prefixes) that have originated in your AS. These routes have not been advertised to your AS by any external peers. To create a null AS path, use the parentheses operator enclosed in quotation marks with no intervening spaces:
In the following example, locally administered AS 2 is connected to AS 1 (10.2.2.6) and AS 3. AS 3 advertises its routes to AS 2, but the administrator for AS 2 does not want to advertise AS 3 routes to AS 1 and thereby allow transit traffic from AS 1 to AS 3 through AS 2. To prevent transit traffic, the export policy only-my-routes is applied to AS 1. It permits advertisement of routes from AS 2 to AS 1 but prevents advertisement of routes for AS 3 (or routes for any other connected AS) to AS 1:
- [edit policy-options]
- null-as "()";
- policy-statement only-my-routes {
-
- term just-my-as {
-
- from {
- protocol bgp;
- as-path null-as;
- }
- then accept;
- }
-
- term nothing-else {
- then reject;
- }
- }
- protocol {
-
- bgp {
-
- neighbor 10.2.2.6 {
- export only-my-routes;
- }
- }
- }
AS path regular expressions implement the extended (modern) regular expressions as defined in POSIX 1003.2. They are identical to the UNIX regular expressions with the following exceptions:
Exactly match routes with the AS path 1234 56 78 9 and accept them:
- [edit]
- policy-options {
- wellington "1234 56 78 9";
-
- policy-statement from-wellington {
-
- term term1 {
- from as-path wellington;
- }
-
- then {
- preference 200;
- accept;
- }
-
- term term2 {
- then reject;
- }
- }
- }
Match alternate paths to an AS and accept them after modifying the preference:
- [edit]
- policy-options {
- wellington-alternate “1234{1,6} (56|47)? (78|101|112)*
9+”;
-
- policy-statement from-wellington {
- from as-path wellington-alternate;
- }
-
- then {
- preference 200;
- accept;
- }
- }
- }
Match routes with an AS path of 123, 124, or 125 and accept them after modifying the preference:
- [edit]
- policy-options {
- addison "123–125";
-
- policy-statement from-addison {
- from as-path addison;
- }
-
- then {
- preference 200;
- accept;
- }
- }
- }