Cisco Support Community
cancel
Showing results for 
Search instead for 
Did you mean: 
New Member

A regular expression to find equal length paths (or unequal)

Hi all.

Has anyone got a clue as to whether it is possible to construct a regular expression to show only those prefixes who have an equal (or unequal) number of AS hops in their paths. These prefixes are coming from 2 different ISPs so may differ in terms of actual AS path, but that doesn't matter, it's the number of AS traversed I care about.

Thanks in advance, kind regards.

1 ACCEPTED SOLUTION

Accepted Solutions
Silver

Re: A regular expression to find equal length paths (or unequal)

RegExp always evaluates prefixes one by one.

You can match prefixes of the specific length. E.g.:

^[0-9]+_[0-9]+_[0-9]+$ Would match all prefixes with AS PATH length of 3.

16 REPLIES
Silver

Re: A regular expression to find equal length paths (or unequal)

RegExp always evaluates prefixes one by one.

You can match prefixes of the specific length. E.g.:

^[0-9]+_[0-9]+_[0-9]+$ Would match all prefixes with AS PATH length of 3.

New Member

Re: A regular expression to find equal length paths (or unequal)

Hi. Once I replaced the "+" with "*" this does the job perfectly. Thanks very much for your assistance.

Re: A regular expression to find equal length paths (or unequal)

Hi do you also know how to filter only the best paths displayed by sh ip bgp regexp?

Something like

sh ip bgp regexp .... | include >

(which doesn't work unfortunately)?

Thanks,

Milan

Silver

Re: A regular expression to find equal length paths (or unequal)

Well, that's the problem. whole line is fed into REGEXP for evaluation, so it does not matter if there is a pipe "|" or anything. It will just look for that exression in AS PATH...

I tried it with unix double pipe, like "more `show ip bgp regexp ...`, but it doesn't work.

If it is possible, than it will be with some unix trick.

Re: A regular expression to find equal length paths (or unequal)

Yes, and in some cases piping would even lose some info: if the best path is not the first one for particular prefix, the subnet info would be lost.

So the only way I found was to capture the show ip bgp regexp ... output, put it to an Excel sheet and make some data sorting manually :-(

BR,

Milan

Silver

Re: A regular expression to find equal length paths (or unequal)

Ok, i have found out how to do it right in the command line :)

Still interested?

Re: A regular expression to find equal length paths (or unequal)

Hi, yes, still interested.

hritter described a solution using quote-regexp.

Do you know something else?

Thanks,

Milan

Cisco Employee

Re: A regular expression to find equal length paths (or unequal)

Milan,

You can use show ip bgp quoted-regexp instead of regexp to allow the use of the pipe statement on the IOS cli.

route-server>sh ip bgp quote-regexp "23456" | incl >

Status codes: s suppressed, d damped, h history, * valid, > best, i - internal

*>i 66.59.190.224 0 110 0 6461 12654 23456 i

*>i145.125.0.0/20 66.59.190.228 0 100 0 2914 3549 1103 1125

23456 i

*>i192.26.93.0 66.59.190.228 0 100 0 2914 4697 23456 i

*>i 66.59.190.227 0 110 0 13237 5539 23456 i

route-server>

Hope this helps,

Harold Ritter
Sr. Technical Leader
CCIE 4168 (R&S, SP)
harold@cisco.com
México móvil: +52 1 55 8312 4915
Cisco México
Paseo de la Reforma 222
Piso 19
Cuauhtémoc, Juárez
Ciudad de México, 06600
México

Re: A regular expression to find equal length paths (or unequal)

Hi Harold,

yes, it works, thanks!

One additional question:

Using this pipe, I'm losing the subnet info sometimes:

route-server.ams2>sh ip bgp quote-regexp "_80$"

BGP table version is 77002010, local router ID is 67.17.81.187

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

* i3.0.0.0 67.17.64.73 600 199 0 701 703 80 i

* i 67.17.64.73 600 199 0 701 703 80 i

* i 67.17.64.73 600 199 0 701 703 80 i

* i 67.17.64.73 600 199 0 701 703 80 i

* i 67.17.64.73 600 199 0 701 703 80 i

* i 67.17.64.73 600 199 0 701 703 80 i

*>i 67.17.64.73 600 199 0 701 703 80 i

* i 67.17.64.73 600 199 0 701 703 80 i

* i 67.17.64.73 600 199 0 701 703 80 i

* i 67.17.64.73 600 199 0 701 703 80 i

* i 67.17.64.73 600 199 0 701 703 80 i

* i 67.17.64.73 600 199 0 701 703 80 i

* i205.173.92.0 67.17.64.73 600 199 0 701 703 80 i

* i 67.17.64.73 600 199 0 701 703 80 i

* i 67.17.64.73 600 199 0 701 703 80 i

* i 67.17.64.73 600 199 0 701 703 80 i

* i 67.17.64.73 600 199 0 701 703 80 i

* i 67.17.64.73 600 199 0 701 703 80 i

* i 67.17.64.73 600 199 0 701 703 80 i

* i 67.17.64.73 600 199 0 701 703 80 i

* i 67.17.64.73 600 199 0 701 703 80 i

*>i 67.17.64.73 600 199 0 701 703 80 i

* i 67.17.64.73 600 199 0 701 703 80 i

* i 67.17.64.73 600 199 0 701 703 80 i

* i 67.17.64.73 600 199 0 701 703 80 i

* i208.234.185.0 67.17.64.73 600 199 0 701 703 80 i

* i 67.17.64.73 600 199 0 701 703 80 i

* i 67.17.64.73 600 199 0 701 703 80 i

* i 67.17.64.73 600 199 0 701 703 80 i

* i 67.17.64.73 600 199 0 701 703 80 i

* i 67.17.64.73 600 199 0 701 703 80 i

* i 67.17.64.73 600 199 0 701 703 80 i

*>i 67.17.64.73 600 199 0 701 703 80 i

* i 67.17.64.73 600 199 0 701 703 80 i

* i 67.17.64.73 600 199 0 701 703 80 i

* i 67.17.64.73 600 199 0 701 703 80 i

* i 67.17.64.73 600 199 0 701 703 80 i

* i 67.17.64.73 600 199 0 701 703 80 i

route-server.ams2>

route-server.ams2>

route-server.ams2>

route-server.ams2>sh ip bgp quote-regexp "_80$" | include >

Status codes: s suppressed, d damped, h history, * valid, > best, i - internal,

*>i 67.17.64.73 600 199 0 701 703 80 i

*>i 67.17.64.73 600 199 0 701 703 80 i

*>i 67.17.64.73 600 199 0 701 703 80 i

route-server.ams2>

Do you now some way how to keep the subnets in the output?

Thanks a lot,

Milan

Silver

Re: A regular expression to find equal length paths (or unequal)

My way is using UNIX trick.

Basically, you execute normal regexp command, without pipe, and hit enter.

Afterwards (after first screen of output)

type +>

and press enter. Afterwards, you can use spacebar.

If you adjust your terminal screen to only sever lines long, then use the +> trick, then adjust the terminal screen again, you would get only the best routes. Otherwise you will get one screen of mixed routes, and rest of the screens best routes

Silver

Re: A regular expression to find equal length paths (or unequal)

P.S.: typing "/word" in an output takes you to the next occurence of "word"

Re: A regular expression to find equal length paths (or unequal)

Hi,

I know /word from vi editor, but where is the + word coming from?

(I'm a Unix beginner.)

BR,

Milan

Silver

Re: A regular expression to find equal length paths (or unequal)

In linux MORE command the +/ option specifies a string that will be searched for before each file is displayed.

In MORE the + doesn't actually work when already displaying a file, but it does in ios

Cisco Employee

Re: A regular expression to find equal length paths (or unequal)

Milan,

This is an additional challenge since the > is not necessarely beside the first path, which is the only path that gets the prefix information in the output.

The best I could come up with is the following:

sh ip bgp quote "regexp" | incl i[0-9]+|>

In the case the first path is not the best path (doesn't have the ">"), you need to print both the first path and the best path resulting into two lines in the output. If the first path and the best path happen to be the same then only one line is generated for this prefix. Here's an example:

route-server>sh ip bgp quote "23456" | incl i[0-9]+|>

Status codes: s suppressed, d damped, h history, * valid, > best, i - internal

* i84.205.88.0/24 66.59.190.229 0 110 0 6461 12654 23456 i

*>i 66.59.190.224 0 110 0 6461 12654 23456 i

*>i145.125.0.0/20 66.59.190.228 0 100 0 2914 3549 1103 1125

23456 i

*>i192.26.93.0 66.59.190.228 0 100 0 2914 4697 23456 i

* i193.31.7.0 66.59.190.229 0 110 0 1273 5539 23456 i

*>i 66.59.190.227 0 110 0 13237 5539 23456 i

* i202.255.47.0 66.59.190.229 0 110 0 2516 7667 23456 i

*>i 66.59.190.224 0 110 0 2516 7667 23456 i

route-server>

Hope this helps,

Harold Ritter
Sr. Technical Leader
CCIE 4168 (R&S, SP)
harold@cisco.com
México móvil: +52 1 55 8312 4915
Cisco México
Paseo de la Reforma 222
Piso 19
Cuauhtémoc, Juárez
Ciudad de México, 06600
México
Cisco Employee

Re: A regular expression to find equal length paths (or unequal)

My previous regexp was only taking into account ibgp learnt prefixes ("i").

This one will cope with both eBGP and iBGP learnt prefixes:

sh ip bgp quote-regexp "23456" | incl \* [i, ][0-9]+|>

Hope this helps,

Harold Ritter
Sr. Technical Leader
CCIE 4168 (R&S, SP)
harold@cisco.com
México móvil: +52 1 55 8312 4915
Cisco México
Paseo de la Reforma 222
Piso 19
Cuauhtémoc, Juárez
Ciudad de México, 06600
México

Re: A regular expression to find equal length paths (or unequal)

Hi Harold,

THANKS!

That's exactly what I need!

I see I have to learn a lot how to work with the regular expessions...

BR,

Milan

332
Views
18
Helpful
16
Replies
CreatePlease to create content