3.7.g Implement and troubleshoot AS path manipulations

3.7.g [iii] Regexp

at first these seem difficult, but the nice thing here is that you can test an as-path filter first by issuing a test regexp first… ie:

bgp_aspath_1

note in the above output of sh ip bgp, 8 out of the 14 routes pass through AS 2… to filter output that shows only those routes that pass through AS 2 use:

sh ip bgp regexp _2_

r4#sh ip bgp regexp _2_
BGP table version is 11, local router ID is 44.44.44.44
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
*  1.1.1.0/24       192.168.34.3                           0 3 2 1 i
*  2.2.2.0/24       192.168.14.1                           0 1 2 i
*>                  192.168.34.3                           0 3 2 i
*  3.3.3.0/24       192.168.14.1                           0 1 2 3 i
*  11.11.11.0/24    192.168.34.3                           0 3 2 1 i
*  22.22.22.0/24    192.168.14.1                           0 1 2 i
*>                  192.168.34.3                           0 3 2 i
*  33.33.33.0/24    192.168.14.1                           0 1 2 3 i

now build the filter list that will deny the routes that pass through AS 2:

r4(config)#ip as-path access-list 1 deny _2_
r4(config)#ip as-path access-list 1 permit .*

this list denies all routes that pass through AS 2 and permits all others…

then add the filter list to the neighbors, and clear bgp…

r4(config-router)#neigh 192.168.14.1 filter-list 1 in
r4(config-router)#neigh 192.168.34.3 filter-list 1 in

bgp_aspath_2

here is a list from cisco that covers some of the operators…

http://www.cisco.com/en/US/tech/tk365/technologies_tech_note09186a00800c95bb.shtml#asregexp

Here are some examples of regular expressions:

a*
  • This expression indicates any occurrence of the letter “a”, which includes none.
a+
  • This expression indicates that at least one occurrence of the letter “a” must be present.
ab?a
  • This expression matches “aa” or “aba”.
_100_
  • This expression means via AS100.
_100$
  • This expression indicates an origin of AS100.
^100 .*
  • This expression indicates transmission from AS100.
^$
  • This expression indicates origination from this AS.