AS-path Lists
You can use regular expressions when you define AS-path access lists and community lists to more easily filter routes. A regular expression uses special characters—often referred to as metacharacters—to define a pattern that is compared with an input string.
For an AS-path access list, the input string is the AS path of the routes to which the list is applied with the route-map or neighbor filter-list commands. If the AS path matches the regular expression in the access list, the route matches the access list.
Example
The following commands apply access list 1 to routes inbound from BGP peer 10.5.5.2. Access list 1 uses a regular expression to deny routes that originate in autonomous system 32.
- host1(config-router)#neighbor 10.5.5.2 remote-as 32
- host1(config-router)#neighbor 10.5.5.2 filter-list 1 in
- host1(config-router)#exit
- host1(config)#ip as-path access-list 1 deny 32$
Community Lists
For a community list, the input string is the community attribute of the routes to which the list is applied using a route-map command. If the community attribute matches the regular expression in the community list, the route matches the community list.
Example
The following commands apply route map 5 to routes forwarded to BGP peer 10.5.5.4. Route map 5 uses a regular expression to match community numbers ending with 305, setting the weight of matching routes to 150.
- host1(config-router)#neighbor 10.5.5.4 remote-as 425
- host1(config-router)#neighbor 10.5.5.4 route-map 5 out
- host1(config-router)#exit
- host1(config)#route-map 5 permit 10
- host1(config-route-map)#match community 305$
- host1(config-route-map)#set weight 150
Community Numbers
When you use a regular expression to match a community number, use the appropriate format for the community number in the community list. If you issue the ip bgp-community new-format command, the community number has the format AA:NN where AA is a number that identifies the autonomous system, and NN is a number that identifies the community within the autonomous system. Otherwise, the community number is an integer in the range 1–4294967295.
Metacharacters
Each regular expression consists of one or more metacharacters and zero or more complete or partial AS or community numbers. Table 6 describes the metacharacters supported for regular expression pattern-matching.
Table 6: Supported Regular Expression Metacharacters
Using Metacharacters as Literal Tokens
You can remove the special meaning of a metacharacter by preceding it with a backslash (\). Such a construction denotes that the metacharacter is not treated as a metacharacter for that regular expression. It is simply a character or token with no special meaning, just as a numeral has no special meaning. The backslash applies only to the character immediately following it in the regular expression.
On an E-series router, you are likely to use the backslash only for the parentheses characters, ( or ). BGP indicates a segment of an AS path that is of type AS-confed-set or AS-confed-seq by enclosing that segment with parentheses.
Example
The following AS-path access list uses a regular expression to match routes that have an AS-path attribute that begins with any AS-confed-set or AS-confed-seq:
- host1(config)#ip as-path access-list 1 permit ^\(
The following AS-path access list uses a regular expression to match routes that have an AS-path attribute that ends with any AS-confed-set or AS-confed-seq:
- host1(config)#ip as-path access-list 1 permit \)$
The following AS-path access list uses a regular expression to match routes that have an AS-path attribute that includes the specific AS-confed-set or AS-confed-seq, (100 200):
- host1(config)#ip as-path access-list 1 permit \(100 200\)
Regular Expression Examples
Table 7 lists some representative regular expressions that you might use in an AS-path access list or community list, along with sample attribute values that match or do not match the regular expression.
Table 7: Sample Regular Expressions
No comments:
Post a Comment