Rules:
Table 7: Regular Expression Operators Operator Match...
{m,n} At least m and at most n repetitions of term. Both m and n must be positive
integers, and m must be smaller than n.
{m} Exactly m repetitions of term. m must be a positive integer.
{m,} m or more repetitions of term. m must be a positive integer.
* Zero or more repetitions of term. This is equivalent to {0,}.
+ One or more repetitions of term. This is equivalent to {1,}.
? Zero or one repetition of term. This is equivalent to {0,1}.
| One of the two terms on either side of the pipe.
^ Character at the beginning of a BGP community name. You cannot use this
operator in AS path regular expressions.
$ Character at the end of a BGP community name. You cannot use this operator
in AS path regular expressions.
[ ] Range of letters or digits. To separate the start and end of a range, use a hyphen (-).
You cannot use this operator in AS path regular expressions.
( ) A group of terms.
Table 8: Examples of Defining AS Path Regular Expressions AS Path to Match Regular
Expression Example Matches
Exactly one occurrence of AS number 1234 in the path 1234 1234
Zero or more occurrences of AS number 1234 1234* 1234
1234 1234
1234 1234 1234
nothing
Zero or one occurrence of AS number 1234 1234?
or
1234{0,1} 1234
nothing
One through four occurrences of AS number 1234 1234{1,4} or 1234 {1,4} 1234
1234 1234
1234 1234 1234
1234 1234 1234 1234
One through four occurrences of AS number 12 followed by one occurrence
of AS number 34 12{1,4}34 12 34
12 12 34
12 12 12 12 34
Range of AS numbers to match a single AS number 123-125 123 or 124 or 125
Path whose second AS number must be 56 or 78 . 56 | . 78 or . (56|78) 1234 56
34 78
Path whose second AS number might be 56 or 78 . (56|78)? 1234
1234 56
34 78
Path of any length whose second AS number can be anything, including
nonexistent 1234 ..* or 1234 ..{0,} 1234
1234 5678
1234 5 6 7 8
One occurrence of the AS path 1, 2, 3 1 2 3 1 2 3
One occurrence of the AS numbers 1 and 2, followed by one or more
occurrences of the number 3 1 2 3+; 1 2 3
1 2 3 3
1 2 3 3 3
One or more occurrences of AS number 1, followed by one or more
occurrences of AS number 2, followed by one or more occurrences
of AS number 3 1+ 2+ 3+ 1 2 3
1 1 2 3
1 1 2 2 3
1 1 2 2 3 3
Path of any length that begins with AS numbers 4, 5, 6 4 5 6 .* 4 5 6
4 5 6 7 8 9
Path of any length that ends with AS numbers 4, 5, 6 .* 4 5 6 4 5 6
1 2 3 4 5 6
Examples: Create AS Path Regular Expressions in Routing Policies
Exactly match routes with the AS path 1234 56 78 9 and accept them:
[edit]
policy-options {
as-path 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:
[edit]
policy-options {
as-path wellington-alternate "1234{1,6} (56|47)? (78|101|112)* 9+";
policy-statement from-wellington {
from as-path wellington-alternate;
then preference 200;
}
}
Match a route with an AS-path of 123, 124, or 125:
[edit]
policy-options {
as-path wellington "123-125";
}
***************************************************
Chris' regexp's
***************************************************
To list all routes from an AS...
show route protocol bgp aspath-regex ".* 6350 .*" | match "(^[1-9]+)"
66.54.52.0/24 *[BGP/170] 4d 18:26:11, MED 99, localpref 80, from 130.81.254.1
129.174.0.0/16 *[BGP/170] 4d 18:24:48, MED 99, localpref 80, from 130.81.254.1
131.158.0.0/16 *[BGP/170] 4d 18:25:59, MED 99, localpref 80, from 130.81.254.1
136.242.0.0/16 *[BGP/170] 4d 18:24:46, MED 99, localpref 80, from 130.81.254.1
138.88.0.0/16 *[BGP/170] 4d 18:24:46, MED 99, localpref 80, from 130.81.254.1
138.144.0.0/16 *[BGP/170] 4d 18:24:47, MED 99, localpref 80, from 130.81.254.1
138.145.0.0/16 *[BGP/170] 4d 18:24:47, MED 99, localpref 80, from 130.81.254.1
141.156.0.0/16 *[BGP/170] 1w4d 05:22:18, MED 100, localpref 80, from 130.81.254.1
141.161.0.0/16 *[BGP/170] 4d 18:24:46, MED 99, localpref 80, from 130.81.254.1
143.247.24.0/23 *[BGP/170] 4d 18:24:46, MED 99, localpref 80, from 130.81.254.1
148.129.0.0/16 *[BGP/170] 4d 18:24:45, MED 99, localpref 80, from 130.81.254.1
148.129.64.0/20 *[BGP/170] 4d 18:24:46, MED 99, localpref 80, from 130.81.254.1
148.129.128.0/19 *[BGP/170] 4d 18:24:45, MED 99, localpref 80, from 130.81.254.1
151.188.0.0/16 *[BGP/170] 4d 18:24:46, MED 99, localpref 80, from 130.81.254.1
151.200.0.0/16 *[BGP/170] 4d 18:24:46, MED 99, localpref 80, from 130.81.254.1
151.207.0.0/16 *[BGP/170] 4d 18:24:46, MED 99, localpref 80, from 130.81.254.1
152.119.0.0/16 *[BGP/170] 1d 14:25:35, MED 100, localpref 80, from 130.81.254.1
159.40.0.0/16 *[BGP/170] 4d 18:24:46, MED 99, localpref 80, from 130.81.254.1
162.6.128.0/19 *[BGP/170] 2d 01:26:38, MED 100, localpref 80, from 130.81.254.1
162.6.160.0/19 *[BGP/170] 2d 01:26:38, MED 100, localpref 80, from 130.81.254.1
162.6.192.0/19 *[BGP/170] 2d 01:26:38, MED 100, localpref 80, from 130.81.254.1
162.6.224.0/19 *[BGP/170] 2d 01:26:38, MED 100, localpref 80, from 130.81.254.1
163.240.0.0/16 *[BGP/170] 4d 18:24:48, MED 99, localpref 80, from 130.81.254.1
166.91.0.0/16 *[BGP/170] 4d 18:24:47, MED 99, localpref 80, from 130.81.254.1
169.135.0.0/16 *[BGP/170] 1d 14:25:36, MED 100, localpref 80, from 130.81.254.1
170.97.0.0/16 *[BGP/170] 4d 18:24:46, MED 99, localpref 80, from 130.81.254.1
192.5.215.0/24 *[BGP/170] 4d 18:24:47, MED 99, localpref 80, from 130.81.254.1
192.52.179.0/24 *[BGP/170] 1w4d 05:22:19, MED 100, localpref 80, from 130.81.254.1
192.207.212.0/24 *[BGP/170] 4d 18:25:21, MED 99, localpref 80, from 130.81.254.1
198.100.0.0/22 *[BGP/170] 4d 18:24:48, MED 99, localpref 80, from 130.81.254.1
198.200.153.0/24 *[BGP/170] 2w4d 08:49:35, MED 100, localpref 80, from 130.81.254.1
199.10.146.0/24 *[BGP/170] 4d 18:24:57, MED 99, localpref 80, from 130.81.254.1
199.26.254.0/24 *[BGP/170] 4d 18:24:48, MED 99, localpref 80, from 130.81.254.1
199.45.32.0/19 *[BGP/170] 4d 18:24:48, MED 99, localpref 80, from 130.81.254.1
199.79.176.0/22 *[BGP/170] 1d 14:25:37, MED 100, localpref 80, from 130.81.254.1
199.79.180.0/24 *[BGP/170] 1d 14:25:37, MED 100, localpref 80, from 130.81.254.1
199.79.206.0/24 *[BGP/170] 4d 18:24:56, MED 99, localpref 80, from 130.81.254.1
199.98.253.0/24 *[BGP/170] 4d 18:24:48, MED 99, localpref 80, from 130.81.254.1
199.111.96.0/22 *[BGP/170] 4d 18:24:48, MED 99, localpref 80, from 130.81.254.1
199.244.139.0/24 *[BGP/170] 4d 18:24:45, MED 99, localpref 80, from 130.81.254.1
204.69.249.0/24 *[BGP/170] 1d 14:25:38, MED 100, localpref 80, from 130.81.254.1
204.69.250.0/24 *[BGP/170] 1d 14:25:38, MED 100, localpref 80, from 130.81.254.1
204.69.252.0/24 *[BGP/170] 1d 14:25:38, MED 100, localpref 80, from 130.81.254.1
204.86.184.0/21 *[BGP/170] 1d 14:25:38, MED 100, localpref 80, from 130.81.254.1
204.86.192.0/23 *[BGP/170] 1d 14:25:38, MED 100, localpref 80, from 130.81.254.1
204.152.44.0/23 *[BGP/170] 1d 14:25:38, MED 100, localpref 80, from 130.81.254.1
204.238.227.0/24 *[BGP/170] 2d 22:42:11, MED 100, localpref 80, from 130.81.254.1
204.245.103.0/24 *[BGP/170] 4d 18:23:00, MED 99, localpref 80, from 130.81.254.1
204.245.104.0/24 *[BGP/170] 4d 18:23:00, MED 99, localpref 80, from 130.81.254.1
204.245.105.0/24 *[BGP/170] 4d 18:23:00, MED 99, localpref 80, from 130.81.254.1
204.245.106.0/24 *[BGP/170] 4d 18:23:00, MED 99, localpref 80, from 130.81.254.1
205.153.36.0/22 *[BGP/170] 4d 18:22:54, MED 99, localpref 80, from 130.81.254.1
207.159.103.0/24 *[BGP/170] 4d 18:20:20, MED 99, localpref 80, from 130.81.254.1
207.159.104.0/24 *[BGP/170] 4d 18:20:20, MED 99, localpref 80, from 130.81.254.1
209.158.134.0/23 *[BGP/170] 4d 18:20:03, MED 99, localpref 80, from 130.81.254.1
209.158.136.0/24 *[BGP/170] 4d 18:20:03, MED 99, localpref 80, from 130.81.254.1
To list all routes local to the local AS...
show route protocol bgp aspath-regex "()"
inet.0: 103315 destinations, 103315 routes (103315 active, 0 holddown, 0 hidden)
+ = Active Route, - = Last Active, * = Both
130.81.0.0/16 [BGP/170] 2w4d 08:59:34, localpref 200, from 130.81.254.6
AS path: I
> to 130.81.4.101 via so-3/0/0.0
[BGP/170] 2w4d 08:59:48, localpref 200, from 130.81.254.2
AS path: I
to 130.81.4.101 via so-3/0/0.0
> to 130.81.4.69 via so-4/0/0.0
130.81.16.0/23 *[BGP/170] 3d 17:39:47, MED 100, localpref 200, from 130.81.254.11
AS path: I
> to 130.81.4.82 via so-0/1/0.0
[BGP/170] 3d 17:39:47, MED 100, localpref 200, from 130.81.254.12
AS path: I
> to 130.81.4.82 via so-0/1/0.0
130.81.240.0/30 *[BGP/170] 3d 17:39:47, MED 100, localpref 200, from 130.81.254.11
AS path: I
> to 130.81.4.82 via so-0/1/0.0
[BGP/170] 3d 17:39:47, MED 100, localpref 200, from 130.81.254.12
AS path: I
> to 130.81.4.82 via so-0/1/0.0
130.81.240.32/30 *[BGP/170] 2w4d 08:59:51, MED 100, localpref 200, from 130.81.254.13
AS path: I
> to 130.81.4.86 via so-0/1/1.0
[BGP/170] 2w4d 08:59:03, MED 100, localpref 200, from 130.81.254.14
AS path: I
> to 130.81.4.86 via so-0/1/1.0
All routes announced by VZGNI
show route protocol bgp aspath-regex ".* (13661-13669|13670-13675|6350|6995|7192-7193|7021|8016-8017|10719|11145-11149|8112-8115) .*" | match "(^[0-9]+)"
Very long list (1121 routes including 700+ /24s that need aggregation!"