Building network automation solutions

9 module online course

Start now!

Display interfaces belonging to a single OSPF process

I’m constantly receiving interesting OSPF-related queries. Obviously the many hidden details of the OSPF specs result in slightly unexpected behavior and constant amazement of engineers studying OSPF. During this week, I’ll focus on a few interesting OSPF intricacies.

Let’s start with an easy one: you can use the show ip ospf interface brief command if you want to display the OSPF interface status (including the interface area, OSPF cost, link type and router status on broadcast links). Unfortunately, this command does not allow you to specify the OSPF process ID and displays interfaces belonging to all OSPF processes (if you run multiple OSPF processes on the router).

Here is a sample printout taken from a router running OSPF processes #2 and #13:

C1#show ip ospf interface brief
Interface PID Area IP Address/Mask Cost State Nbrs F/C
Lo102 2 22 10.2.2.2/32 1 LOOP 0/0
Fa0/0 13 0 10.0.1.1/24 10 BDR 1/1
Lo0 13 0 10.0.0.11/32 1 LOOP 0/0
Se1/0.101 13 1 0.0.0.0/0 64 P2P 1/1
Se1/0.100 13 1 0.0.0.0/0 64 P2P 1/1

You can use an output filter to display the interfaces belonging to a single OSPF process. The filter is quite convoluted …

C1#show ip ospf interface brief | include ^[^ ]+ +13
Fa0/0 13 0 10.0.1.1/24 10 BDR 1/1
Lo0 13 0 10.0.0.11/32 1 LOOP 0/0
Se1/0.101 13 1 0.0.0.0/0 64 P2P 1/1
Se1/0.100 13 1 0.0.0.0/0 64 P2P 1/1

… and works like this:

  • The initial caret (^) matches the beginning of the line, ensuring that our filter will match exactly what it needs to match. Without the initial caret, the filter could generate a match anywhere in the line, potentially resulting in false positives.
  • The [^ ]+ pattern matches any non-empty (the + sign) string of non-space characters (the [^ ] expression matches anything but the whitespace). This part of the pattern matches the interface name.
  • The  + pattern matches the string of spaces between the interface name and the process ID.
  • The final part of the pattern (13) matches the OSPF process ID.

You can transform this complex output filter into an easy Tcl script. See the “Simple extensions to exec-mode CLI” and “Simple CLI extensions: handling special characters” posts.

4 comments:

  1. The example you gave for filter output shows processes with PID 1, instead of PID 13.
  2. thank u r information

    it very useful

    u r blog Is very nice
  3. @Vladimir: Thanks. That's the danger of notepad post-processing :) Fixed.
  4. This was the key post I needed to figure out how to grab interfaces names. Thanks
Add comment
Sidebar