We
are going to use the above topology to demonstrate some regular expressions
examples using Cisco IOS software
Configurations
Each
router will be configured with two loopback interfaces that will be advertised into
BGP, all BGP relations are eBGP
R1
interface
Loopback1
ip address 192.168.1.1 255.255.255.0
interface
Loopback2
ip address 172.16.1.1 255.255.255.0
interface
FastEthernet0/0
ip address 192.168.12.1 255.255.255.0
speed 100
full-duplex
no shut
interface
FastEthernet0/1
ip address 192.168.13.1 255.255.255.0
speed 100
full-duplex
no shut
interface
FastEthernet1/0
ip address 192.168.14.1 255.255.255.0
speed 100
full-duplex
no shut
router
bgp 9038
no bgp default ipv4-unicast
bgp log-neighbor-changes
neighbor 192.168.12.2 remote-as 3356
neighbor 192.168.13.3 remote-as 47887
neighbor 192.168.14.4 remote-as 44666
address-family ipv4
neighbor 192.168.12.2 activate
neighbor 192.168.13.3 activate
neighbor 192.168.14.4 activate
no auto-summary
no synchronization
network 172.16.1.0 mask 255.255.255.0
network 192.168.1.0
exit-address-family
R2
interface
Loopback1
ip address 192.168.2.2 255.255.255.0
interface
Loopback2
ip address 172.16.2.2 255.255.255.0
interface
FastEthernet0/0
ip address 192.168.12.2 255.255.255.0
speed 100
full-duplex
no shut
interface
FastEthernet0/1
ip address 192.168.25.2 255.255.255.0
speed 100
full-duplex
no shut
router
bgp 3356
no bgp default ipv4-unicast
bgp log-neighbor-changes
neighbor 192.168.12.1 remote-as 9038
neighbor 192.168.25.5 remote-as 8966
address-family ipv4
neighbor 192.168.12.1 activate
neighbor 192.168.25.5 activate
no auto-summary
no synchronization
network 172.16.2.0 mask 255.255.255.0
network 192.168.2.0
exit-address-family
R3
interface
Loopback1
ip address 192.168.3.3 255.255.255.0
interface
Loopback2
ip address 172.16.3.3 255.255.255.0
interface
FastEthernet0/0
ip address 192.168.13.3 255.255.255.0
speed 100
full-duplex
no shut
interface
FastEthernet0/1
ip address 192.168.35.3 255.255.255.0
speed 100
full-duplex
no shut
router
bgp 47887
no bgp default ipv4-unicast
bgp log-neighbor-changes
neighbor 192.168.13.1 remote-as 9038
neighbor 192.168.35.5 remote-as 8966
address-family ipv4
neighbor 192.168.13.1 activate
neighbor 192.168.35.5 activate
no auto-summary
no synchronization
network 172.16.3.0 mask 255.255.255.0
network 192.168.3.0
exit-address-family
R4
interface
Loopback1
ip address 192.168.4.4 255.255.255.0
interface
Loopback2
ip address 172.16.4.4 255.255.255.0
interface
FastEthernet0/0
ip address 192.168.14.4 255.255.255.0
speed 100
full-duplex
no shut
interface
FastEthernet0/1
ip address 192.168.46.4 255.255.255.0
speed 100
full-duplex
no shut
router
bgp 44666
no bgp default ipv4-unicast
bgp log-neighbor-changes
neighbor 192.168.14.1 remote-as 9038
neighbor 192.168.46.6 remote-as 7922
address-family ipv4
neighbor 192.168.14.1 activate
neighbor 192.168.46.6 activate
no auto-summary
no synchronization
network 172.16.4.0 mask 255.255.255.0
network 192.168.4.0
exit-address-family
R5
interface
Loopback1
ip address 192.168.5.5 255.255.255.0
interface
Loopback2
ip address 172.16.5.5 255.255.255.0
interface
FastEthernet0/0
ip address 192.168.25.5 255.255.255.0
speed 100
full-duplex
no shut
interface
FastEthernet0/1
ip address 192.168.56.5 255.255.255.0
speed 100
full-duplex
no shut
interface
FastEthernet1/0
ip address 192.168.35.5 255.255.255.0
speed 100
full-duplex
no shut
router
bgp 8966
no bgp default ipv4-unicast
bgp log-neighbor-changes
neighbor 192.168.25.2 remote-as 3356
neighbor 192.168.35.3 remote-as 47887
neighbor 192.168.56.6 remote-as 7922
address-family ipv4
neighbor 192.168.25.2 activate
neighbor 192.168.35.3 activate
neighbor 192.168.56.6 activate
no auto-summary
no synchronization
network 172.16.5.0 mask 255.255.255.0
network 192.168.5.0
exit-address-family
R6
interface
Loopback1
ip address 192.168.6.6 255.255.255.0
interface
Loopback2
ip address 172.16.6.6 255.255.255.0
interface
FastEthernet0/0
ip address 192.168.56.6 255.255.255.0
speed 100
full-duplex
no shut
interface
FastEthernet0/1
ip address 192.168.46.6 255.255.255.0
speed 100
full-duplex
no shut
router
bgp 7922
no bgp default ipv4-unicast
bgp log-neighbor-changes
neighbor 192.168.46.4 remote-as 44666
neighbor 192.168.56.5 remote-as 8966
!
address-family ipv4
neighbor 192.168.46.4 activate
neighbor 192.168.56.5 activate
no auto-summary
no synchronization
network 172.16.6.0 mask 255.255.255.0
network 192.168.6.0
exit-address-family
Characters
Below
is the characters used in the BGP regular expressions configuration
?
|
repeats
the previous character one or zero times.
|
*
|
repeats
the previous character zero or many times.
|
+
|
repeats
the previous character one or more times.
|
^
|
matches
the beginning of a string.
|
$
|
matches
the end of a string.
|
[]
|
is
a range.
|
_
|
matches
the space between AS numbers or the end of the AS PATH list.
|
\\
|
is
an escape character. You’ll need this for BGP confederations.
|
Outputs
Before
we start manipulating with regular expressions, let us check the BGP table on
R1
R1#sh
ip bgp
BGP
table version is 15, local router ID is 192.168.14.1
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
*>
172.16.1.0/24 0.0.0.0 0 32768 i
*>
172.16.2.0/24 192.168.12.2 0 0 3356 i
*>
172.16.3.0/24 192.168.13.3 0 0 47887 i
*>
172.16.4.0/24 192.168.14.4 0 0 44666 i
* 172.16.5.0/24 192.168.14.4 0 44666 7922 8966 i
* 192.168.13.3 0 47887 8966 i
*> 192.168.12.2 0 3356 8966 i
*>
172.16.6.0/24 192.168.14.4 0 44666 7922 i
* 192.168.13.3 0 47887 8966 7922 i
* 192.168.12.2 0 3356 8966 7922 i
*>
192.168.1.0 0.0.0.0 0 32768 i
*>
192.168.2.0 192.168.12.2 0 0 3356 i
*>
192.168.3.0 192.168.13.3 0 0 47887 i
*>
192.168.4.0 192.168.14.4 0 0 44666 i
* 192.168.5.0 192.168.14.4 0 44666 7922 8966 i
* 192.168.13.3 0 47887 8966 i
*> 192.168.12.2 0 3356 8966 i
Network Next Hop Metric LocPrf Weight Path
*>
192.168.6.0 192.168.14.4 0 44666 7922 i
* 192.168.13.3 0 47887 8966 7922 i
* 192.168.12.2 0 3356 8966 7922 i
As
well, let us dive deeply in the output above as a review for the BGP attributes
and best path selection criteria
The
prefixes 192.168.1.0 and 172.16.1.0/24 have a next-hop value of 0.0.0.0, which
means that these prefixes were locally originated (either using network or
redistribution), the 172.16.1.0 appears attached with its subnet mask because
it’s a class B prefix and we configured the mask to be /24 in the network
statement, 192.168.1.0 is already class C prefix and we did not change the
classful boundary, as well, the as-path is empty because again these prefixes
are locally originated
Let
us check now the prefix 172.16.5.0/24 , it has been learned through three
different paths , as we did not manipulate any attributes , the as-path will
play a role according to the selection criteria , so the path 44666 7922
8966 will be discarded compared to the
other two paths which are shorter , the tie will be between the 47887 8966
and 3356 8966 which are equal in the
as-path and both are eBGP , so going down the list , the oldest one learned
will be installed in the RIB (routing table)
Regular Expressions Examples
Locally Originated Routes
As
mentioned above, the locally originated routes have a next-hop value of 0.0.0.0
and can be shown using the regular expression of ^$
R1#sh
ip bgp regexp ^$
BGP
table version is 15, local router ID is 192.168.14.1
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
*>
172.16.1.0/24 0.0.0.0 0 32768 i
*>
192.168.1.0 0.0.0.0 0 32768 i
R2#sh
ip bgp regexp ^$
BGP
table version is 13, local router ID is 192.168.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
*>
172.16.2.0/24 0.0.0.0 0 32768 i
*>
192.168.2.0 0.0.0.0 0 32768 i
R3#sh
ip bgp regexp ^$
BGP
table version is 13, local router ID is 192.168.3.3
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
*>
172.16.3.0/24 0.0.0.0 0 32768 i
*>
192.168.3.0 0.0.0.0 0 32768 i
R4#sh
ip bgp regexp ^$
BGP
table version is 15, local router ID is 192.168.4.4
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
*>
172.16.4.0/24 0.0.0.0 0 32768 i
*>
192.168.4.0 0.0.0.0 0 32768 i
R5#sh
ip bgp regexp ^$
BGP
table version is 15, local router ID is 192.168.5.5
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
*>
172.16.5.0/24 0.0.0.0 0 32768 i
*>
192.168.5.0 0.0.0.0 0 32768 i
R6#sh
ip bgp regexp ^$
BGP
table version is 13, local router ID is 192.168.6.6
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
*>
172.16.6.0/24 0.0.0.0 0 32768 i
*>
192.168.6.0 0.0.0.0 0 32768 i
Anything to Match
This
will match any route, i.e. it will show the BGP table
R1#sh
ip bgp regexp .*
BGP
table version is 15, local router ID is 192.168.14.1
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
*>
172.16.1.0/24 0.0.0.0 0 32768 i
*>
172.16.2.0/24 192.168.12.2 0 0 3356 i
*>
172.16.3.0/24 192.168.13.3 0 0 47887 i
*>
172.16.4.0/24 192.168.14.4 0 0 44666 i
* 172.16.5.0/24 192.168.14.4 0 44666 7922 8966 i
* 192.168.13.3 0 47887 8966 i
*> 192.168.12.2 0 3356 8966 i
*>
172.16.6.0/24 192.168.14.4 0 44666 7922 i
* 192.168.13.3 0 47887 8966 7922 i
* 192.168.12.2 0 3356 8966 7922 i
*>
192.168.1.0 0.0.0.0 0 32768 i
*>
192.168.2.0 192.168.12.2 0 0 3356 i
*>
192.168.3.0 192.168.13.3 0 0 47887 i
*>
192.168.4.0 192.168.14.4 0 0 44666 i
* 192.168.5.0 192.168.14.4 0 44666 7922 8966 i
* 192.168.13.3 0 47887 8966 i
*> 192.168.12.2 0 3356 8966 i
Network Next Hop Metric LocPrf Weight Path
*>
192.168.6.0 192.168.14.4 0 44666 7922 i
* 192.168.13.3 0 47887 8966 7922 i
* 192.168.12.2 0 3356 8966 7922 i
Routes originated in a specific AS
To
check routes originated in a specific AS #, we will be using the pattern _AS#$
R1#sh
ip bgp regexp _3356$
BGP
table version is 15, local router ID is 192.168.14.1
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
*>
172.16.2.0/24 192.168.12.2 0 0 3356 i
*>
192.168.2.0 192.168.12.2 0 0 3356 i
R1#sh
ip bgp regexp _47887$
BGP
table version is 15, local router ID is 192.168.14.1
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
*>
172.16.3.0/24 192.168.13.3 0 0 47887 i
*>
192.168.3.0 192.168.13.3 0 0 47887 i
R1#sh
ip bgp regexp _44666$
BGP
table version is 15, local router ID is 192.168.14.1
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
*>
172.16.4.0/24 192.168.14.4 0 0 44666 i
*>
192.168.4.0 192.168.14.4 0 0 44666 i
R1#sh
ip bgp regexp _8966$
BGP
table version is 15, local router ID is 192.168.14.1
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
* 172.16.5.0/24 192.168.14.4 0 44666 7922 8966 i
* 192.168.13.3 0 47887 8966 i
*> 192.168.12.2 0 3356 8966 i
* 192.168.5.0 192.168.14.4 0 44666 7922 8966 i
* 192.168.13.3 0 47887 8966 i
*> 192.168.12.2 0 3356 8966 i
R1#sh
ip bgp regexp _7922$
BGP
table version is 15, local router ID is 192.168.14.1
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
*>
172.16.6.0/24 192.168.14.4 0 44666 7922 i
* 192.168.13.3 0 47887 8966 7922 i
* 192.168.12.2 0 3356 8966 7922 i
*>
192.168.6.0 192.168.14.4 0 44666 7922 i
* 192.168.13.3 0 47887 8966 7922 i
* 192.168.12.2 0 3356 8966 7922 i
Routes learned from specific AS (the AS-PATH starts with that AS)
To
match these kind of routes we will using the regular expression ^AS_
R1#sh
ip bgp regexp .*
BGP
table version is 15, local router ID is 192.168.14.1
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
*>
172.16.1.0/24 0.0.0.0 0 32768 i
*>
172.16.2.0/24 192.168.12.2 0 0 3356 i
*>
172.16.3.0/24 192.168.13.3 0 0 47887 i
*>
172.16.4.0/24 192.168.14.4 0 0 44666 i
* 172.16.5.0/24 192.168.14.4 0 44666 7922 8966 i
* 192.168.13.3 0 47887 8966 i
*> 192.168.12.2 0 3356 8966 i
*>
172.16.6.0/24 192.168.14.4 0 44666 7922 i
* 192.168.13.3 0 47887 8966 7922 i
* 192.168.12.2 0 3356 8966 7922 i
*>
192.168.1.0 0.0.0.0 0 32768 i
*> 192.168.2.0
192.168.12.2 0 0 3356 i
*>
192.168.3.0 192.168.13.3 0 0 47887 i
*>
192.168.4.0 192.168.14.4 0 0 44666 i
* 192.168.5.0 192.168.14.4 0 44666 7922 8966 i
* 192.168.13.3 0 47887 8966 i
*> 192.168.12.2 0 3356 8966 i
Network Next Hop Metric LocPrf Weight Path
*>
192.168.6.0 192.168.14.4 0 44666 7922 i
* 192.168.13.3 0 47887 8966 7922 i
* 192.168.12.2 0 3356 8966 7922 i
R1#sh
ip bgp regexp ^3356_
BGP
table version is 15, local router ID is 192.168.14.1
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
*>
172.16.2.0/24 192.168.12.2 0 0 3356 i
*> 172.16.5.0/24
192.168.12.2
0 3356 8966 i
* 172.16.6.0/24 192.168.12.2 0 3356 8966 7922 i
*> 192.168.2.0
192.168.12.2 0 0 3356 i
*> 192.168.5.0
192.168.12.2 0 3356 8966 i
* 192.168.6.0 192.168.12.2 0 3356 8966 7922 i
R1#sh
ip bgp regexp ^47887_
BGP
table version is 15, local router ID is 192.168.14.1
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
*>
172.16.3.0/24 192.168.13.3 0 0 47887 i
* 172.16.5.0/24 192.168.13.3 0 47887 8966 i
* 172.16.6.0/24 192.168.13.3 0 47887 8966 7922 i
*>
192.168.3.0 192.168.13.3 0 0 47887 i
* 192.168.5.0 192.168.13.3 0 47887 8966 i
* 192.168.6.0 192.168.13.3 0 47887 8966 7922 i
Match any instance of a specific AS (from or through)
To
match these kinds of routes we will be using the pattern _AS_
R1#sh
ip bgp regexp _3356_
BGP
table version is 15, local router ID is 192.168.14.1
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
*>
172.16.2.0/24 192.168.12.2 0 0 3356 i
*>
172.16.5.0/24 192.168.12.2 0 3356 8966 i
* 172.16.6.0/24 192.168.12.2 0 3356 8966 7922 i
*>
192.168.2.0 192.168.12.2 0 0 3356 i
*>
192.168.5.0 192.168.12.2 0 3356 8966 i
* 192.168.6.0 192.168.12.2 0 3356 8966 7922 i
R1#sh
ip bgp regexp _47887_
BGP
table version is 15, local router ID is 192.168.14.1
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
*>
172.16.3.0/24 192.168.13.3 0 0 47887 i
* 172.16.5.0/24 192.168.13.3 0 47887 8966 i
* 172.16.6.0/24 192.168.13.3 0 47887 8966 7922 i
*>
192.168.3.0 192.168.13.3 0 0 47887 i
* 192.168.5.0 192.168.13.3 0 47887 8966 i
* 192.168.6.0 192.168.13.3 0 47887 8966 7922 i
R1#sh
ip bgp regexp _44666_
BGP
table version is 15, local router ID is 192.168.14.1
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
*>
172.16.4.0/24 192.168.14.4 0 0 44666 i
* 172.16.5.0/24 192.168.14.4 0 44666 7922 8966 i
*>
172.16.6.0/24 192.168.14.4 0 44666 7922 i
*>
192.168.4.0 192.168.14.4 0 0 44666 i
* 192.168.5.0 192.168.14.4 0 44666 7922 8966 i
*>
192.168.6.0 192.168.14.4 0 44666 7922 i
R1#sh
ip bgp regexp _8966_
BGP
table version is 15, local router ID is 192.168.14.1
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
* 172.16.5.0/24 192.168.14.4 0 44666 7922 8966 i
* 192.168.13.3 0 47887 8966 i
*> 192.168.12.2 0 3356 8966 i
* 172.16.6.0/24 192.168.13.3 0 47887 8966 7922 i
* 192.168.12.2 0 3356 8966 7922 i
* 192.168.5.0 192.168.14.4 0 44666 7922 8966 i
* 192.168.13.3 0 47887 8966 i
*> 192.168.12.2 0 3356 8966 i
* 192.168.6.0 192.168.13.3 0 47887 8966 7922 i
* 192.168.12.2 0 3356 8966 7922 i
R1#sh
ip bgp regexp _7922_
BGP
table version is 15, local router ID is 192.168.14.1
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
* 172.16.5.0/24 192.168.14.4 0 44666 7922 8966 i
*>
172.16.6.0/24 192.168.14.4 0 44666 7922 i
* 192.168.13.3 0 47887 8966 7922 i
* 192.168.12.2 0 3356 8966 7922 i
* 192.168.5.0 192.168.14.4 0 44666 7922 8966 i
*>
192.168.6.0 192.168.14.4 0 44666 7922 i
* 192.168.13.3 0 47887 8966 7922 i
* 192.168.12.2 0 3356 8966 7922 i
Routes learned from my directly connected ASes
As
can be seen from the topology, AS# 9038 has three directly connected ASes, we
will be using the expression ^[0-9]+$ to match these routes
R1#sh
ip bgp summary
BGP
router identifier 192.168.14.1, local AS number 9038
BGP
table version is 15, main routing table version 15
12
network entries using 1440 bytes of memory
20
path entries using 1040 bytes of memory
11/6
BGP path/bestpath attribute entries using 1364 bytes of memory
9
BGP AS-PATH entries using 216 bytes of memory
0
BGP route-map cache entries using 0 bytes of memory
0
BGP filter-list cache entries using 0 bytes of memory
Bitfield
cache entries: current 1 (at peak 1) using 32 bytes of memory
BGP
using 4092 total bytes of memory
BGP
activity 12/0 prefixes, 20/0 paths, scan interval 60 secs
Neighbor V
AS MsgRcvd MsgSent TblVer InQ OutQ Up/Down State/PfxRcd
192.168.12.2 4
3356 40 41
15 0 0 00:31:25 6
192.168.13.3 4 47887
39 40 15
0 0 00:29:33 6
192.168.14.4 4 44666
38 38 15
0 0 00:27:34 6
R1#sh
ip bgp regexp ^[0-9]+$
BGP
table version is 15, local router ID is 192.168.14.1
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
*>
172.16.2.0/24 192.168.12.2 0 0 3356 i
*>
172.16.3.0/24 192.168.13.3 0 0 47887 i
*>
172.16.4.0/24 192.168.14.4 0 0 44666 i
*>
192.168.2.0 192.168.12.2 0 0 3356 i
*>
192.168.3.0 192.168.13.3 0
0 47887 i
*>
192.168.4.0 192.168.14.4 0 0 44666 i
Quote-regexp
If
we wanted to filter the output more , we can use quote-regexp instead , for
example if we wanted to show all routes originated in AS #9038 that starts with
192 , we can use the below command
R3#sh
ip bgp quote-regexp "_9038$" | include ^. 192\.
* 192.168.1.0 192.168.35.5 0 8966 3356 9038 i
R3#sh
ip bgp quote-regexp "_9038$" | include ^. 172\.
* 172.16.1.0/24 192.168.35.5 0 8966 3356 9038 i
R5#sh
ip bgp quote-regexp "_9038$" | include ^. 192\.
* 192.168.1.0 192.168.56.6 0 7922 44666 9038 i
R5#sh
ip bgp quote-regexp "_9038$" | include ^. 172\.
* 172.16.1.0/24 192.168.56.6 0 7922 44666 9038 i
Brackets
The
below output will match routes from AS that start with 4, 5, 6, 7 or 8 and have
6 more 6s in the as-path
R2#sh
ip bgp regexp [4-8]6+$
BGP
table version is 13, local router ID is 192.168.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
* 172.16.4.0/24 192.168.25.5 0 8966 7922 44666 i
*> 192.168.12.1 0 9038 44666 i
* 172.16.5.0/24 192.168.12.1 0 9038 47887 8966 i
*> 192.168.25.5 0 0 8966 i
* 192.168.4.0 192.168.25.5 0 8966 7922 44666 i
*> 192.168.12.1 0 9038 44666 i
* 192.168.5.0 192.168.12.1 0 9038 47887 8966 i
*> 192.168.25.5 0 0 8966 i
R3#sh
ip bgp regexp _3*[5-6]+[1-9]$
BGP
table version is 13, local router ID is 192.168.3.3
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
* 172.16.2.0/24 192.168.35.5 0 8966 3356 i
*> 192.168.13.1 0 9038 3356 i
* 192.168.2.0 192.168.35.5 0 8966 3356 i
*> 192.168.13.1 0 9038 3356 i
.
matches any character, so we if we applied the output below, we can see that 9
will be matched as the rest of the command contains 038
R3#sh
ip bgp regexp ^.038
BGP
table version is 13, local router ID is 192.168.3.3
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
*>
172.16.1.0/24 192.168.13.1 0 0 9038 i
*>
172.16.2.0/24 192.168.13.1 0 9038 3356 i
*>
172.16.4.0/24 192.168.13.1 0 9038 44666 i
* 172.16.6.0/24 192.168.13.1 0 9038 44666 7922 i
*>
192.168.1.0 192.168.13.1 0 0 9038 i
*>
192.168.2.0 192.168.13.1 0 9038 3356 i
*>
192.168.4.0 192.168.13.1 0 9038 44666 i
* 192.168.6.0 192.168.13.1 0 9038 44666 7922 i
The
below matches the routes from my directly connected neighbors, but not all
neighbors only 3356
R1#sh
ip bgp regexp ^[3356]+$
BGP
table version is 15, local router ID is 192.168.1.1
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
*>
172.16.2.0/24 192.168.12.2 0 0 3356 i
*>
192.168.2.0 192.168.12.2 0 0 3356 i
The
below matches the routes that starts from 3356 and passes through the direct AS
8966 (following each other in the as-path)
R1#show
ip bgp regexp ^3356_8966$
BGP
table version is 15, local router ID is 192.168.1.1
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
* 172.16.5.0/24 192.168.12.2 0 3356 8966 i
* 192.168.5.0 192.168.12.2 0 3356 8966 i
Filtering
We
can use regular expressions to filter routes and modify attributes instead of
matching the same prefixes
Let
us change the local preference value for a specific routes matched based on a
specific regular expression
R2#sh
ip bgp
BGP
table version is 13, local router ID is 192.168.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
*>
172.16.1.0/24 192.168.12.1 0 0 9038 i
*>
172.16.2.0/24 0.0.0.0 0 32768 i
* 172.16.3.0/24 192.168.25.5 0 8966 47887 i
*> 192.168.12.1 0 9038 47887 i
* 172.16.4.0/24 192.168.25.5 0 8966 7922 44666 i
*> 192.168.12.1 0 9038 44666 i
* 172.16.5.0/24 192.168.12.1 0 9038 47887 8966 i
*> 192.168.25.5 0 0 8966 i
* 172.16.6.0/24 192.168.12.1 0 9038 44666 7922 i
*> 192.168.25.5 0 8966 7922 i
*>
192.168.1.0 192.168.12.1 0 0 9038 i
*>
192.168.2.0 0.0.0.0 0 32768 i
* 192.168.3.0 192.168.25.5 0 8966 47887 i
*> 192.168.12.1 0 9038 47887 i
* 192.168.4.0 192.168.25.5 0 8966 7922 44666 i
*> 192.168.12.1 0 9038 44666 i
* 192.168.5.0 192.168.12.1 0 9038 47887 8966 i
Network Next Hop Metric LocPrf Weight Path
*> 192.168.25.5 0 0 8966 i
* 192.168.6.0 192.168.12.1 0 9038 44666 7922 i
*> 192.168.25.5 0 8966 7922 i
R2
ip
as-path access-list 10 permit ^9038_44666$
route-map
LP permit 10
match
as-path 10
set
local-preference 300
route-map
LP permit 20
router
bgp 3356
address-family
ipv4 unicast
neighbor
192.168.12.1 route-map LP in
R2#sho
ip bgp regexp ^9038_44666$
BGP
table version is 15, local router ID is 192.168.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
*>
172.16.4.0/24 192.168.12.1 300 0 9038
44666 i
*>
192.168.4.0 192.168.12.1 300 0 9038
44666 i
Now,
let us try to change the origin code for specific routes matched based on a
specific regular expression
R1#sh
ip bgp regexp _47887$
BGP
table version is 15, local router ID is 192.168.1.1
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
*>
172.16.3.0/24 192.168.13.3 0 0 47887 i
*>
192.168.3.0 192.168.13.3 0 0 47887 i
R1
ip
as-path access-list 14 permit _47887$
route-map
ORIGIN permit 10
match
as-path 14
set
origin incomplete
route-map
ORIGIN permit 20
router
bgp 9038
address-family
ipv4 unicast
neighbor
192.168.13.3 route-map ORIGIN in
R1#sh
ip bgp regexp _47887$
BGP
table version is 17, local router ID is 192.168.1.1
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
*>
172.16.3.0/24 192.168.13.3 0 0 47887 ?
*>
192.168.3.0 192.168.13.3 0 0 47887 ?
IOS vs IOS XR
As
we know, the syntax is somehow different between the IOS and IOS XR, we will go
the same examples we listed above and convert them to IOS XR syntax
IOS
Command
|
IOS XR
Command
|
show ip bgp regexp {Regular-Expression)
|
show bgp regexp {Regular-Expression}
|
ip as-path access-list 10 permit ^9038_44666$
|
as-path-set
SET1
ios-regex '^9038_44666$'
end-set
|
ip as-path access-list 11 permit _9038$
|
as-path-set SET2
ios-regex
'_9038$'
end-set
or
as-path-set SET2
originates-from '9038'
end-set
|
ip as-path access-list 12 permit _3356_
|
as-path-set SET3
ios-regex
'_3356_'
end-set
or
as-path-set SET2
passes-through '3356'
end-set
|
ip as-path access-list 14 permit _47887$
route-map ORIGIN permit 10
match as-path 14
set origin incomplete
route-map ORIGIN permit 20
router bgp 9038
address-family ipv4 unicast
neighbor 192.168.13.3 route-map ORIGIN in
|
as-path-set SET4
ios-regex
'_47887$'
end-set
route-policy ORIGIN
if as-path in
SET4 then
set origin
incomplete
else
pass
endif
end-policy
router bgp 9038
neighbor 192.168.13.3
address-family ipv4 unicast
route-policy ORIGIN in
|
ip as-path access-list 10 permit ^9038_44666$
route-map LP permit 10
match as-path 10
set local-preference 300
route-map LP permit 20
router bgp 3356
address-family ipv4 unicast
neighbor 192.168.12.1 route-map LP in
|
as-path-set SET5
ios-regex
'^9038_44666$'
end-set
route-policy LP
if as-path in
SET5 then
set
local-preference 300
else
pass
endif
end-policy
router bgp 9038
neighbor 192.168.12.1
address-family ipv4 unicast
route-policy LP in
|