Defining AS Path Regular Expressions
You can create a named AS path regular expression and then include it in a routing policy with the
as-pathmatch condition (described in Table 12). To create a named AS path regular expression, include theas-pathstatement:as-pathname 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-pathmatch condition in thefromstatement:as-pathname regular-expression;policy-statementpolicy-name{termterm-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-groupmatch condition. To create a named AS path group, include theas-path-groupstatement:as-path-groupgroup-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-groupmatch condition in thefromstatement:as-path-groupgroup-name{name[regular-expressions];}policy-statementpolicy-name{termterm-name{from {as-path-groupgroup-name;}}}
NOTE: You cannot have both
as-pathandas-path-groupin the same policy term.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 (double quotes).
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>
- AS number—The entire AS number composes one
term. You cannot reference individual characters within an AS number, which differs from regular expressions as defined in POSIX 1003.2.- Wildcard character—Matches any single AS number. The wildcard character is a period (.). You can specify multiple wildcard characters.
- AS path—A single AS number or a group of AS numbers enclosed in parentheses. Grouping the regular expression in this way allows you to perform a common operation on the group as a whole and to give the group precedence. The grouped path can itself include operators.
operator—(Optional) An operator specifying how the term must match. Most operators describe how many times the term must be found to be considered a match (for example, any number of occurrences, or zero or one occurrence). Table 17 lists the regular expression operators supported for AS paths. You place operators immediately aftertermwith no intervening space, except for the pipe ( | ) and dash (-) operators, which you place between two terms, and parentheses, with which you enclose terms.You can specify one or more term-operator pairs in a single regular expression.
Table 18 shows examples of how to define regular expressions to match AS paths.
Null AS Path
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:
"()"Example: Null AS Path
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;}}}