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 Table 14). To create a named AS path regular expression, include the as-path statement:
- as-path name regular-expression;
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:
- as-path-group group-name {
-
name [ regular-expressions ];
- }
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 have both as-path and as-path-group 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:
-
term <operator>
Beginning with JUNOS Release 9.1, the range for AS numbers has
been extended to provide BGP support for 4-byte AS numbers as defined
in
RFC 4893, BGP Support for Four-octet
AS Number Space. You can now configure a value that is
from 1 through 4,294,967,295. The JUNOS software continues to support
2-byte AS numbers. For more information about configuring the AS number
for the local router and the Border Gateway Protocol (BGP), see the JUNOS Routing Protocols Configuration Guide.
You can specify one or more term–operator pairs in a single regular expression.
Table 20 shows examples of how to define regular expressions to match AS paths.
Table 19: AS Path Regular Expression Operators
Table 20: Examples of Defining 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:
- “()"
AS 1 and AS 3 are connected to AS 2, which you administrate. AS 3 advertises its routes to your AS, but you do not want to advertise AS 3 routes to AS 1 and thereby begin routing traffic from AS 1 to AS 3 through your AS. To prevent this situation from occurring, you can configure an export policy for AS 1 (1.2.2.6) that allows routes for your AS to be advertised to AS 1 but does not allow routes for AS 3 or routes for any other connected AS to be advertised 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;
- }
- }
- }