cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
1829
Views
18
Helpful
16
Replies

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

dogfugitive
Level 1
Level 1

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

Pavel Bykov
Level 5
Level 5

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.

View solution in original post

16 Replies 16

Pavel Bykov
Level 5
Level 5

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.

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

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

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.

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

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

Still interested?

Hi, yes, still interested.

hritter described a solution using quote-regexp.

Do you know something else?

Thanks,

Milan

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

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

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

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

Hi,

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

(I'm a Unix beginner.)

BR,

Milan

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

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
Getting Started

Find answers to your questions by entering keywords or phrases in the Search bar above. New here? Use these resources to familiarize yourself with the community:

Innovations in Cisco Full Stack Observability - A new webinar from Cisco