CCIE Pursuit Blog

March 27, 2008

Cool Command 2: Verify Your BGP Regular Expressions

Here’s a great command for verifying (or just practicing) your BGP regular expression filters.  In the example below, I want to only see the routes where AS54 is the last AS in the AS path*.  I’m pretty sure that my regular expression is correct, but I want to verify it by running it against my BGP database.

Here’s the full BGP database:

r6(config)#do sh ip bgp | b Netw
   Network          Next Hop            Metric LocPrf Weight Path
*> 28.119.16.0/24   204.12.1.254             0             0 54 i
*> 28.119.17.0/24   204.12.1.254             0             0 54 i
*> 112.0.0.0        54.1.3.254               0             0 54 50 60 i
*> 113.0.0.0        54.1.3.254               0             0 54 50 60 i
*> 114.0.0.0        54.1.3.254               0             0 54 i
*> 115.0.0.0        54.1.3.254               0             0 54 i
*> 116.0.0.0        54.1.3.254               0             0 54 i
*> 117.0.0.0        54.1.3.254               0             0 54 i
*> 118.0.0.0        54.1.3.254               0             0 54 i
*> 119.0.0.0        54.1.3.254               0             0 54 i
*> 205.90.31.0      204.12.1.3                             0 200 254 ?
*> 220.20.3.0       204.12.1.3                             0 200 254 ?
*> 222.22.2.0       204.12.1.3                             0 200 254 ?

Here’s the results of filtering with ^54_ :

r6(config)#do sh ip bgp regex ^54_
BGP table version is 14, local router ID is 150.1.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
*> 28.119.16.0/24   204.12.1.254             0             0 54 i
*> 28.119.17.0/24   204.12.1.254             0             0 54 i
*> 112.0.0.0        54.1.3.254               0             0 54 50 60 i
*> 113.0.0.0        54.1.3.254               0             0 54 50 60 i
*> 114.0.0.0        54.1.3.254               0             0 54 i
*> 115.0.0.0        54.1.3.254               0             0 54 i
*> 116.0.0.0        54.1.3.254               0             0 54 i
*> 117.0.0.0        54.1.3.254               0             0 54 i
*> 118.0.0.0        54.1.3.254               0             0 54 i
*> 119.0.0.0        54.1.3.254               0             0 54 i

show ip bgp regexp

*Thanks to apep for the correction.  See comment section for details.

January 9, 2008

Using Regular Expressions With Show Commands

Here’s a nice article showing some interesting uses of regular expressions with show commands.  I’ve posted part of it below, you can read the rest here.   The article looks like it comes from OneTrain, but I couldn’t find it on their site.

*****Updated 10 January*****

David Bombal contacted me and provided the link to the original article (rather than the reposting in the forum):

Hi,

I am glad that you found my article to be useful. This is a copy of an article from my monthly newsletter.

You can find the original article here: http://www.configureterminal.com/newsletters/2.html

Please would you update your links to point to the original article?

Your readers will be able to access more information like this by registering on our website.

Regards,
David Bombal
CCIE #11023, CCSP, CCIP, CCSI, CCNP, CCDP, CCVP
http://www.ConfigureTerminal.com

I have updated the links to point to that article. 

Using the power of regular expressions with Show commands
By David Bombal

This is an advanced topic, so get your ready…

We have covered some basic regular expressions in our “Cool IOS Commands” EBook. Here I want to show you more complicated examples of how to use the power of regular expressions to filter output. This will allow the router to do the searching for text, rather than us doing it manually.

Regular expressions are used in many places in the IOS including BGP AS paths and Voice number translations. They are also used in other languages like Perl and TCL. Here however, we are going to concentrate on regular expressions with IOS show commands. We are going to use them to search for specific sets of strings.

A regular expression is a pattern (for example a phrase or a number) that can be used very effectively to filter output. Regular expressions are case-sensitive and allow for complex matching requirements.

I start with some simple examples so that you can learn each regular expression character individually and then we will combine them into complicated strings. As always with programming, there are many ways to do things, so use your imagination:

^ Regular Expression
Use this to look for text at the beginning of a string.

For Example: ^123 matches 1234, but not 01234 or 91234

On a router we can demonstrate this as follows: (without any regular expressions)

Router#show run | include ip
ip cef
no ip dhcp use vrf connected
ip dhcp pool ITS
option 150 ip 10.1.1.1
no ip domain lookup
voice service voip
allow-connections h323 to sip
allow-connections sip to h323
allow-connections sip to sip
ip address 192.168.10.1 255.255.255.0
ip address 192.168.11.1 255.255.255.0
ip address 192.168.12.1 255.255.255.0
ip address 192.168.13.1 255.255.255.0
ip address 192.168.14.1 255.255.255.0
<MORE>

However, if we use the following:
Router#show run | include ^ip

The output is:
Router#show run | include ^ip
ip cef
ip dhcp pool ITS
ip http server

Note – as expected, every line begins with “ip”, string we matched on
$ Regular Expression:
Use this to look for text at the end of a string

For Example123$ matches 0123, but not 1234

On a router we can demonstrate this as follows: (without any regular expressions)

Router#show run | include 1
Current configuration : 5174 bytes
! Last configuration change at 15:27:21 UTC Wed Jan 24 2007
! NVRAM config last updated at 14:25:01 UTC Wed Jan 24 2007
version 12.4
network 10.1.1.0 255.255.255.0
option 150 ip 10.1.1.1
default-router 10.1.1.1
source-address 10.1.1.1 port 5060
create profile sync 0002381328447096
voice register dn 1
number 1100
number 1101
voice register pool 1
id mac 0003.6B8B.174A
number 1 dn 1
codec g711ulaw
ip address 192.168.10.1 255.255.255.0
interface Loopback1
ip address 192.168.11.1 255.255.255.0
ip address 192.168.12.1 255.255.255.0
ip address 192.168.13.1 255.255.255.0

but if we change it to
Router#show run | include 1$

The output is:
Router#show run | include 1$
voice register dn 1
number 1101
voice register pool 1
number 1 dn 1
interface Loopback1
interface Loopback11
interface Loopback21
interface FastEthernet0/1
session target ipv4:10.1.1.1
session target ipv4:10.1.1.11
session target ipv4:10.1.1.21
session target ipv4:10.1.1.31
session target ipv4:10.1.1.41
session target ipv4:10.1.1.51
session target ipv4:10.1.1.61
number 1001
ephone 1
button 1:1

Note – as expected, every line ends “1”, string we matched on.

Read the rest here.

Blog at WordPress.com.