Mailing List Archive

Regular expressions in CLI.
Hello. I'm trying to count all the active prefixes from one particular AS.
Aside from the quantity of time spent doing the query, I cannot set up a
proper regexp for filtering the active prefixes:

ender@dub1> show route aspath-regex ^1299.*
inet.0: 114313 destinations, 226204 routes (114302 active, 11 holddown, 0
hidden)
+ = Active Route, - = Last Active, * = Both

3.0.0.0/8 [BGP/150] 1w4d 09:56:52, localpref 100, from
130.206.206.249
AS path: 1299 1239 80 I
> to 130.206.220.1 via ge-1/1/0.0
3.210.36.0/24 [BGP/150] 1w4d 09:56:48, localpref 100, from
130.206.206.249
AS path: 1299 3549 I
> to 130.206.220.1 via ge-1/1/0.0
4.0.0.0/8 [BGP/150] 1w4d 09:56:48, localpref 100, from
130.206.206.249
AS path: 1299 1 I
> to 130.206.220.1 via ge-1/1/0.0
4.22.240.0/21 [BGP/150] 1w4d 09:56:50, localpref 100, from
130.206.206.249
AS path: 1299 1 7843 I
> to 130.206.220.1 via ge-1/1/0.0
[blablabla]

But active prefixes _have_ * or + before the [BGP/... string, so with a
'match':

ender@dub1> show route aspath-regex ^1299.* | match (\+|\*)
^
syntax error.

Nice error. I've tried nearly all the possible combinations of \ and (\). But
something is happening with the supposed regular expression, because a simple

whatever | match '(A|B)'

or

whatever | match (A|B)

gives errors as well.

http://www.juniper.net/techpubs/software/junos52/swcmdref52/html/cli-overview-cmdref9.html#1014458
claims that match accepts extended (modern) regular expressions. The above
one works with perl, but not in the router.


And another problem: the amount of time that the above command spends is not
negligible. In fact, is terribly _big_ (I'm trying to get periodic stats of
active prefixes per AS). Is there any other way to do it? I've not seen any
MIB for doing that with SNMP, and don't think that JunOScript makes much
better (thinking about XML overhead, for example). Am I wrong?

Thanks in advance for your help,


David.

PS: For the Juniper guys in the list: I've found a bug in JunOS with the copy
between REs, should I open a PR, or go directly to support@juniper.net, or
contact with my equipment provider for opening the case through them?
--
Why is a cow? Mu. (Ommmmmmmmmm)
--
Servicios de red - Network services
Centro de Comunicaciones CSIC/RedIRIS
Spanish Academic Network for Research and Development
Madrid (Spain)
Tlf (+34) 91.585.49.05
Regular expressions in CLI. [ In reply to ]
--Apple-Mail-6--1002971344
Content-Transfer-Encoding: 7bit
Content-Type: text/plain;
charset=US-ASCII;
format=flowed

Double-quotes around the match expression will take care of the syntax
error. I agree that "syntax error" is a bit cryptic, I can only assume
that the developer was making an ironic reference to the days of
FORTRAN IV. ;-)

It's no consolation, but the documentation does state

"If the regular-expression contains any spaces, operators, or wildcard
characters, enclose it in quotation marks."

Robert.

On Monday, September 2, 2002, at 09:46 AM, David Martinez CSIC RedIRIS
wrote:

> show route aspath-regex ^1299.* | match (\+|\*)
--Apple-Mail-6--1002971344
Content-Transfer-Encoding: 7bit
Content-Type: text/enriched;
charset=US-ASCII

Double-quotes around the match expression will take care of the syntax
error. I agree that "syntax error" is a bit cryptic, I can only
assume that the developer was making an ironic reference to the days
of FORTRAN IV. ;-)


It's no consolation, but the documentation does state


<fontfamily><param>Arial</param>"If the
</fontfamily><italic><fixed><fontfamily><param>Courier New</param><smaller><smaller>regular-expression
</smaller></smaller></fontfamily></fixed></italic><fontfamily><param>Arial</param>contains
any spaces, operators, or wildcard characters, enclose it in quotation
marks."</fontfamily><bigger><bigger>

</bigger></bigger>

Robert.


On Monday, September 2, 2002, at 09:46 AM, David Martinez CSIC RedIRIS
wrote:


<excerpt>show route aspath-regex ^1299.* | match (\+|\*)</excerpt>
--Apple-Mail-6--1002971344--
Regular expressions in CLI. [ In reply to ]
I replied off-list, but in case anyone else needs this answer, I've
found the following to work in this situation (5.4R1.4):

show route as-path-regex "1299 [1-64511]{1,20}" | match \*

This shows all prefixes that start with 1299 and then have 1 through 20
instances of any non-reserved ASN after that. =20

This seems to work in my case...if anyone sees anything wrong with this,
please let us know.

evt

-----Original Message-----
From: David Martinez CSIC RedIRIS [mailto:david.martinez@rediris.es]=20
Sent: Monday, September 02, 2002 12:46 PM
To: juniper-nsp@puck.nether.net
Subject: [j-nsp] Regular expressions in CLI.


Hello. I'm trying to count all the active prefixes from one
particular AS.=20
Aside from the quantity of time spent doing the query, I cannot set up a

proper regexp for filtering the active prefixes:

ender@dub1> show route aspath-regex ^1299.*
inet.0: 114313 destinations, 226204 routes (114302 active, 11 holddown,
0=20
hidden)
+ =3D Active Route, - =3D Last Active, * =3D Both

3.0.0.0/8 [BGP/150] 1w4d 09:56:52, localpref 100, from=20
130.206.206.249
AS path: 1299 1239 80 I
> to 130.206.220.1 via ge-1/1/0.0
3.210.36.0/24 [BGP/150] 1w4d 09:56:48, localpref 100, from=20
130.206.206.249
AS path: 1299 3549 I
> to 130.206.220.1 via ge-1/1/0.0
4.0.0.0/8 [BGP/150] 1w4d 09:56:48, localpref 100, from=20
130.206.206.249
AS path: 1299 1 I
> to 130.206.220.1 via ge-1/1/0.0
4.22.240.0/21 [BGP/150] 1w4d 09:56:50, localpref 100, from=20
130.206.206.249
AS path: 1299 1 7843 I
> to 130.206.220.1 via ge-1/1/0.0
[blablabla]

But active prefixes _have_ * or + before the [BGP/... string, so
with a=20
'match':

ender@dub1> show route aspath-regex ^1299.* | match (\+|\*)
^
syntax error.

Nice error. I've tried nearly all the possible combinations of \
and (\). But=20
something is happening with the supposed regular expression, because a
simple

whatever | match '(A|B)'

or=20

whatever | match (A|B)

gives errors as well.

http://www.juniper.net/techpubs/software/junos52/swcmdref52/html/cli-ove
rview-cmdref9.html#1014458=20
claims that match accepts extended (modern) regular expressions. The
above=20
one works with perl, but not in the router.


And another problem: the amount of time that the above command
spends is not=20
negligible. In fact, is terribly _big_ (I'm trying to get periodic stats
of=20
active prefixes per AS). Is there any other way to do it? I've not seen
any=20
MIB for doing that with SNMP, and don't think that JunOScript makes much

better (thinking about XML overhead, for example). Am I wrong?

Thanks in advance for your help,


David.

PS: For the Juniper guys in the list: I've found a bug in JunOS with the
copy=20
between REs, should I open a PR, or go directly to support@juniper.net,
or=20
contact with my equipment provider for opening the case through them?
--
Why is a cow? Mu. (Ommmmmmmmmm)
--
Servicios de red - Network services
Centro de Comunicaciones CSIC/RedIRIS
Spanish Academic Network for Research and Development
Madrid (Spain)
Tlf (+34) 91.585.49.05

_______________________________________________
juniper-nsp mailing list juniper-nsp@puck.nether.net
http://puck.nether.net/mailman/listinfo/juniper-nsp
Regular expressions in CLI. [ In reply to ]
Hello David,

Yes, as others have stated, the "" will do it for you. Also, here's a
slightly simpler regex using character classes that gives you the same:

<blah> | match "[+*]"


As for XML vs. CLI performance, most command output is rendered in XML
internally, and transformed to CLI format afterwards. Strictly
speaking, the XML output will be "faster" if you don't include your own
XML processing in the equation. However, it's unlikely that the
formatting is the limiting factor in the performance of the command
you're having trouble with.

You can easily measure the difference like this:

> start shell
% time "cli show route as-path-regex ^1299.* | save /dev/null"
% time "cli show route as-path-regex ^1299.* | display xml | save
/dev/null"

the /dev/null will remove the actual terminal display overhead from the
equation.

while you're at it, try timing "show route | /dev/null" to see how long
that takes. Except for transmission time of the actual result, this
will necessarily be faster than your as-path-regex. This will help you
see whether the regex is the time sink, or just the show route. If it
is the as-path-regex, then perhaps leave it out, and use the match's
regex. Just a guess, I can't really claim to know whether this will be
any faster.

As for the bug, open a case w/ support@juniper.net; they'll determine
if it's known, and has been fixed in a later release, or the
in-development code.

-Avram Dorfman
Pro Services

p.s. sorry if this is a double post; having trouble with my email
client...
Regular expressions in CLI. [ In reply to ]
David Martinez CSIC RedIRIS writes:
>ender@dub1> show route aspath-regex ^1299.* | match (\+|\*)
> ^
>syntax error.
> Nice error.

Yup, the UI is parsing this command line as:

the command:
show route aspath-regex ^1299.*
piped through:
match (\+
piped through:
\*)

which should have given you a message like:

ender@dub1> show route aspath-regex ^1299.* | match (\+|\*)
^
syntax error, expecting <command>.

since the command '\*)' is not valid. Not sure this would
have been much more helpful though.

Thanks,
Phil