3.7g Implement and troubleshoot AS path manipulations
3.7g(iii) Regexp
Regular expressions use special character definitions to search and find character patterns. Within the scope of BGP, regular expressions can be used in show commands and as-path access-lists to match BGP prefixes based on the information contained in the AS_PATH attribute.
The character definitions in IOS:
Some commonly used regular expressions:
+-------------+---------------------------+
| EXPRESSION | MEANING |
|-------------+---------------------------|
| .* | Anything |
|-------------+---------------------------|
| ^$ | Locally originated routes |
|-------------+---------------------------|
| ^100_ | Learned from AS 100 |
|-------------+---------------------------|
| _100$ | Originated in AS 100 |
|-------------+---------------------------|
| _100_ | Any instance of AS 100 |
|-------------+---------------------------|
| ^[0-9]+$ | Directly connected ASes |
+-------------+---------------------------+
Example: Permit only locally originated routes on R2. Ignore the private AS stuff, using an example from a previous post.
+----------+ +--------+ +--------+
| | | | | |
| AS 65001 | --- | AS 200 | --- | AS 300 |
| R1 | | R2 | | R3 |
+----------+ +--------+ +--------+
R2#
interface FastEthernet0/1
ip address 155.1.23.2 255.255.255.0
!
interface Loopback200
ip address 200.2.2.2 255.255.255.0
!
interface Loopback201
ip address 200.22.22.2 255.255.255.0
!
ip as-path access-list 1 permit ^$
!
route-map LOCAL-ONLY permit 10
match as-path 1
!
router bgp 200
no synchronization
bgp log-neighbor-changes
network 200.2.2.0
network 200.22.22.0
neighbor 155.1.12.1 remote-as 65001
neighbor 155.1.23.3 remote-as 300
neighbor 155.1.23.3 remove-private-as
neighbor 155.1.23.3 route-map LOCAL-ONLY out
no auto-summary
R2 is originating two routes: 200.2.2.0/24 and 200.22.22.0/24. R2 is also learning routes from R1.
R2#show ip bgp
BGP table version is 9, local router ID is 150.1.2.2
Status codes: s suppressed, d damped, h history, * valid, > best, i - internal,
r RIB-failure, S Stale
Origin codes: i - IGP, e - EGP, ? - incomplete
Network Next Hop Metric LocPrf Weight Path
*> 100.1.1.0/24 155.1.12.1 0 0 65001 i
*> 100.11.11.0/24 155.1.12.1 0 0 65001 i
*> 150.1.1.1/32 155.1.12.1 0 0 65001 i
*> 200.2.2.0 0.0.0.0 0 32768 i
*> 200.22.22.0 0.0.0.0 0 32768 i
Regular expression can also be applied to show commands to filter the output. The show ip bgp regexp ^$ displays locally originated routes.
R2#show ip bgp regexp ^$
BGP table version is 9, local router ID is 150.1.2.2
Status codes: s suppressed, d damped, h history, * valid, > best, i - internal,
r RIB-failure, S Stale
Origin codes: i - IGP, e - EGP, ? - incomplete
Network Next Hop Metric LocPrf Weight Path
*> 200.2.2.0 0.0.0.0 0 32768 i
*> 200.22.22.0 0.0.0.0 0 32768 i
However, only the locally originated routes are propaged to R3.
R2#show ip bgp neighbors 155.1.23.3 advertised-routes
BGP table version is 9, local router ID is 150.1.2.2
Status codes: s suppressed, d damped, h history, * valid, > best, i - internal,
r RIB-failure, S Stale
Origin codes: i - IGP, e - EGP, ? - incomplete
Network Next Hop Metric LocPrf Weight Path
*> 200.2.2.0 0.0.0.0 0 32768 i
*> 200.22.22.0 0.0.0.0 0 32768 i
Total number of prefixes 2
No comments:
Post a Comment