Open Shortest Path First Protocol

Introduction

The Open Shortest Path First (OSPF) protocol is a dynamic routing protocol. Utilization of a dynamic routing protocol can help simplifying configuration, since there is no need to for manual configuration of static routes. Further, it also helps improving the robustness of the network, by automatically being able to adapt the routing based on changes in the network topology.

OSPF is a protocol that falls within the group of interior gateway protocols (IGPs). OSPF is an example of a link-state routing protocol. An advantage that link-state routing protocols, like OSPF, have over distance vector routing protocols, such as RIP, is the fast convergence after a topology change and increased scalability.

For example use-cases and example setups, refer to:

Overview

As mentioned OSPF is an example of what is known as a link-state protocol. In a link-state protocol each individual router announce information about their identity (router-id), along with their directly connected networks, and other neighbouring routers. All this information is flooded throughout the OSPF domain, this ensures that each router will gain complete knowledge about every router and link in the entire topology. This is necessary in order to be able to compute the best path (the least cost path) to reach every destination.

   Net-A                               Net-B
  .--.-.                              .--.-.
 ( (    )__                          ( (    )__
(_,  \ ) ,_)                        (_,  \ ) ,_)
  '-'--`--'                           '-'--`--'
     |                                   |
     |                                   |
     |                                   |
.----+-----.                        .----+-----.
|          |                        |          |
| Router-A +------------------------+ Router-B |
|          |                        |          |
'----+-----'                        '----+-----'
     |                                   |
     |                                   |
     |                                   |
.----+-----.                        .----+-----.
|          |                        |          |
| Router-C +------------------------+ Router-D |
|          |                        |          |
'----+-----'                        '----+-----'
     |                                   |
     |                                   |
     |                                   |
  .--.-.                              .--.-.
 ( (    )__                          ( (    )__
(_,  \ ) ,_)                        (_,  \ ) ,_)
  '-'--`--'                           '-'--`--'
   Net-C                               Net-D

Figure 1: Simple network topology with interconnected routers and networks.

As an example, Router-A in Figure 1 would send out OSPF messages informing other routers about its router-id, its connected networks, i.e., Net-A and the links towards the routers B and C. The other routers would also do the same thing.

OSPF Hierarchy and Areas

Being a link-state protocol OSPF requires routers ti keep a lot of routing information in their database:

  • Routers will keep a database with information of every router and in link in the entire OSPF domain.

  • OSPF routers can also redistribute and keep routing information learnt from external sources (static routes, routes learnt via other routing protocols, etc.).

Therefore, to reduce the burden of keeping state information about the entire OSPF domain on every single router, the domain can be split into OSPF areas. An example is presented in Figure 2, here the routers have been divided into four different areas. When an OSPF network is split into multiple areas, each router will only have full knowledge of the topology within the area it is part of. Routers will also keep summary information about destinations outside their own are, but no additional information on the topologies of other areas.

                . . . . . . . . . . . . . . . . . . . . . . . .
                .               Area 0.0.0.0                  .
                .   .---.      (Backbone area)        .---.   .
                .   | R |                             | R |   .
                .   '---'            .---.            '---'   .
                .                    | R |                    .
                .                    '---'                    .
                .                                             .
            .-------.              .-------.              .-------.
            |       | . . . . . . .|       |. . . . . . . |       |
            |  ABR  |              |  ABR  |              |  ABR  |
. . . . . . |       |   . . . . . .|       |. . . . . .   |       | . . . . . .
.  .---.    '-------'   .  .---.   '-------'   .---.  .   '-------'    .---.  .
.  | R |        .       .  | R |               | R |  .       .        | R |  .
.  '---' .---.  .       .  '---'     .---.     '---'  .       .  .---. '---'  .
.        | R |  .       .            | R |            .       .  | R |        .
.        '---'  .       .            '---'            .       .  '---'        .
.               .       .                             .       .               .
. Area 0.0.0.1  .       .       Area 0.0.0.2          .       . Area 0.0.0.3  .
. . . . . . . . .       . . . . . . . . . . . . . . . .       . . . . . . . . .

Figure 2: Sample OSPF hierarchy with a backbone area and three other areas.

Every network that an OSPF router should be aware of must always be associated with an area. If multiple areas are not necessary they will belong to the backbone, area 0.0.0.0.

Areas are organised in a two-level hierarchy. The top of this hierarchy will always be constituted by the backbone, area 0. Since it is limited to two levels all other areas must be connected to the backbone area. Any router that serve networks that are part of different areas are known as an Area Border Router (ABR). Direct connections between areas that do not traverse through the backbone is prohibited.

Even though all areas must be connected directly to the backbone (area 0), situations could present themselves where it is not physically possible to connect an area directly to the backbone. Because of this OSPF provides a feature referred to as virtual links, that can allow an area to establish a connection to the backbone through a non-backbone area.

Note

Virtual links are currently NOT supported.

. . . . . . . . . . . .    . . . . . . . . . . . .     . . . . . . . . . . . .
.    Area 0.0.0.0     .    .    Area 0.0.0.1     .     .    Area 0.0.0.2     .
.                     .    .                     .     .                     .
.        .---.        .    .        .---.        .     .        .---.        .
.        | R |        .    .        | R |        .     .        | R |        .
.        '---'        .    .        '---'        .     .        '---'        .
.                    .-------.                  .-------.                    .
.  .---.       .---. |       |   Virtual Link   |       | .---.       .---.  .
.  | R |       | R | |  ABR  +==================+  ABR  | | R |       | R |  .
.  '---'       '---' |       |                  |       | '---'       '---'  .
.                    '-------'                  '-------'                    .
.        .---.        .    .        .---.        .     .        .---.        .
.        | R |        .    .        | R |        .     .        | R |        .
.        '---'        .    .        '---'        .     .        '---'        .
. . . . . . . . . . . .    . . . . . . . . . . . .     . . . . . . . . . . . .

Figure 3: An example of a virtual link between area 2 and the backbone, going through area 1.

Area Types

Areas in OSPF can be designated a number of specific area types. The purpose for this is to allow for an even increased amount of control on the routing information that is distributed throughout the OSPF network. The different area types allow to more specifically decide what type of routing information is allowed. Being able to configure the OSPF network to reduce the amount of routing information that is passed to specific areas, can help reduce the size of the link state database and routing table, that is maintained by each individual router. The following area types can be configured:

  • Standard area: This is the default type of all areas added to the OSPF domain, except for area 0. This area type will accept any link update, summary routes, and external routes.

  • Backbone area (area 0): The main area of an OSPF network, all other areas must be connected to this backbone area. All other areas that wants to communicate with each other must do so through this area. Otherwise, it has the same functionality as a standard area.

  • Stub area: This area type do not accept any external network routes outside of the OSPF domain. Hence, the routers inside the area will not store any routing information to external destinations outside of the OSPF network. Instead, the router connected to the backbone (ABR) will advertise a default route,towards itself, into the area so that external network destinations are reachable. Also, no router inside the area is allowed to redistribute routing information learnt from external sources, no autonomous system border router (ASBR) is allowed.

  • Totally stubby area: Behaves in the same manner as a stub area, and in addition this area type does not allow summary routes from other ares inside the OSPF network. Meaning that the routers in the area will not store any routing information to destinations within the OSPF network. Like a regular stub area the ABR will advertise a default route towards itself, so that both destinations external to OSPF and external to the area within the OSPF network, can be reached.

  • Not so stubby area (NSSA): This type of area is very similar to a stub area, with the difference being that it allows ASBR routers inside its area. This makes it possible to advertise external routes through a stubby area.

  • NSSA totally stub area: Is a combination of a Totally stubby area and a NSSA area.

Tip

For some example use-cases on different OSPF areas refer to here.

Router Types

Within an OSPF domain, routers can be divided into a number of different types. Their role and position, within the OSPF domain, will decide what kind of type it will become. The following are the different router classifications that are used within an OSPF network:

  • Internal Router (IR): Are routers where all of their connections belong to the same area.

  • Backbone Router (BR): Are routers that has at least one interface connected to the backbone area. ABR routers are always backbone routers. Routers that only have interfaces connected to the backbone, are also backbone routers.

  • Area Border Router (ABR): Are routers which are attached to multiple different areas. These routers must also be connected to the backbone area (area 0). An ABR summarize topology information of its attached areas and distribute it to the backbone area.

  • Autonomous System Boundary Router (ASBR): Routers that are attached to routers, part of other Autonomous Systems, running a different routing protocol. ASBRs distribute this external routing information into the OSPF domain.

. . . . . . . . . . .   . . . . . . .   . . . . . . . . . . .
.       Area 1      .   .  Area 0   .   .       Area 2      .
.                   .   .           .   .                   .
. .-------.       .-------.       .-------.       .-------. .
. |       |       |       |       |       |       |       | .
. |  IR   +-------+  ABR  +---+---+  ABR  +-------+  IR   | .
. |       |       |  BR   |   |   |  BR   |       |       | .
. '---+---'       '-------'   |   '-------'       '---+---' .
.     |             .   .     |     .   .             |     .
. .---+---.         .   . .---+---. .   .         .---+---. .       .--.-.
. |       |         .   . |       | .   .         |       | .      ( (    )__
. |  IR   |         .   . |  BR   | .   .         | ASBR  +-------(_,  \ ) ,_)
. |       |         .   . |       | .   .         |       | .       '-'--`--'
. '-------'         .   . '-------' .   .         '-------' .   External Network
. . . . . . . . . . .   . . . . . . .   . . . . . . . . . . .

Figure 4: A small network of a number of routers in different areas, with the purpose to show different OSPF router types.

In Figure 4 above a simple example example is provided to show how the different router types are assigned.

Configuration

The configuration of OSPF is separated into two different parts. The actual router configuration and OSPF related settings for each individual interface.

Router

OSPF is configured under the router section of the global configuration context:

example:/#> configure
example:/config/#> router
example:/config/router/#> ospf
example:/config/router/ospf/#>
[no] router-id <ID>

Set the OSFP router identifier, which must be unique within the OSPF domain.

The router ID is a 32-bit value, given in a dotted decimal form , where a-d are numbers in the range 0-255. Commonly the router ID is set equal to one of the router’s IP addresses.

Default: Auto (no router-id)

no

Use automatically assigned router-id. The router-id will automatically try to be assigned based on the following selection processes:

  1. If the lo interface have a statically configured address (other than 127.0.0.1) that address will be used as the router-id.

  2. The current highest statically configured ip address for any of the interfaces used by OSPF.

  3. If no static address has been configured the first available address, on any of the interfaces used by OSPF, will be selected as the router-id.

ID
ID in a dotted decimal form , where a-d are numbers in the range 0-255.

Note

The router-id will not be sticky if set to auto. If any configuration changes are made the mentioned selection process will be performed again, so it could result in a new router-id to be selected. In order to be sure what the router-id will be set to in any situation, simply specify it manually.

[no] distance <1-255>

Set the administrative distance to be used for all routes the are learnt via OSPF.

For additional information on routing distance, see this.

Default: 110

no
Reset the distance to the default value.
[no] passive-interface

Enable/Disable passive-interface, that control if OSPF should be passive on all interfaces by default.

Whether a specific interface should be passive or not, is configurable for each interface.

Default: Active (no passive-interface)

no
Set to active, not passive.
[no] neighbor <IPADDR[,IPADDR,...]>

Manually define OSPF neighbours.

This may be useful when intermediate switches do not propagate IP multicast, or when using OSPF in NBMA (non-broadcast multiple access) networks.

Note

Remember to set the network type of each interface to non-broadcast if you want OSPF to send unicast Hello messages on NBMA links.

Default: Disabled

no
Remove configured neighbour.
IPADDR
IP address in standard quad-dotted notation, e.g. 192.168.1.1.
[no] network <NETWORK> [area <AREA-ID>]

Specify a network to announce and an OSPF area the network belongs to.

Default: Disabled, no network entries have been configured when first activating OSPF. The backbone area (0.0.0.0) is used as default area.

no
Remove any configured network.
NETWORK
IP address in standard quad-dotted notation including netmask, e.g. 192.168.1.1/24.
AREA-ID
The area ID is a 32-bit number, and is entered in dotted decimal form, or as an integer (0..2 32 − 1).
[no] area <AREA-ID>

Manage area specific settings: stub, route summarization, etc.

Note

Enters a sub-configuration context for area specific settings.

no
Remove custom area settings.
AREA-ID
The area ID is a 32-bit number, and is entered in dotted decimal form, or as an integer (0..2 32 − 1).
[no] redistribute <connected|static|rip> [metric <0-16777214>] [metric-type <1|2>]

Redistribute external routing information into the OSPF domain.

Default: Disabled

no
Remove redistribution of external routing information.
connected
Redistribute routes to directly attached networks, which have not been defined to belong to any OSPF area in the “network” command.
static
Redistribute static routes set with the ip route command.
rip
Redistribute routes set by RIP.
metric
The cost of reaching the external AS (autonomous system).
metric-type 1
External type 1 routes, E1 in the routing table, include the cost of the ASBR itself in the LSA.
metric-type 2
External type 2 routes, E2 in the routing table, do NOT include the cost of the ASBR, this is the default.
[no] distribute-default [always] [metric <0-16777214>] [metric-type <1|2>]

Introduce a default route into the OSPF domain, I.e., announce that this router can reach network 0.0.0.0/0.

Default: Disabled

no
Disable distribution of a default route.
always
Always advertise the default route, regardless if one exist or not. Otherwise, it will only be advertised if it exist.
metric
The cost of reaching the external AS (autonomous system).
metric-type 1
External type 1 routes, E1 in the routing table, include the cost of the ASBR itself in the LSA.
metric-type 2
External type 2 routes, E2 in the routing table, do NOT include the cost of the ASBR, this is the default.

Area Settings

OSPF area specific settings can be configured from a sub-context under the router OSPF configuration:

example:/config/router/ospf/#> area 1
example:/config/router/ospf/area-0.0.0.1/#>
[no] default-cost <0-16777215>

Set the cost of the default route injected into a stub area. This setting only applies to the ABRs of a stub or NSSA area.

Default: 1

no
Reset to the default value.
[no] range <NETWORK> [advertise|not-advertise|substitute <NETWORK>] [cost 0-16777215]

Configure inter-area route summarisation, route filtering or route substitution.

Default: Disabled

no
Remove configuration.
NETWORK
IP address in standard quad-dotted notation including netmask, e.g. 192.168.1.1/24.
advertise
Use to aggregate routes (within the area) that match the specified NETWORK range, before distributing the routes outside the area. Thus, all routes within the provided range are summarised as a single route, when advertised outside the area.
not-advertise
Use to prohibit routes (within the area) matching the specified NETWORK range, to be distributed outside the area. Thus, all routes within the provided range are filtered.
substitute
Use to substitute routes (within the area) matching the specified NETWORK range, with another specified NETWORK before distributing the routes outside the area. Thus, all routes within the provided range are substituted with another NETWORK.
[no] stub [no-summary]

Configure an area as a stub area.

To create a stub area, all routers in the area (ABRs as well as internal routers) must declare the area as stub.

Default: Disabled (i.e., areas are regular OSPF areas by default)

no
Reset to a regular OSPF area.
no-summary
Configure the area as a totally stubby area, this should be done for all ABRs in the area.
[no] nssa [no-summary]

Configure an area as a not so stubby area.

To create a nssa area, all routers in the area (ABRs as well as internal routers) must declare the area as nssa.

Default: Disabled (i.e., areas are regular OSPF areas by default)

no
Reset to a regular OSPF area.
no-summary
Configure the area as a NSSA totally stub area, this should be done for all ABRs in the area.

Interface Specific Settings

Interface settings that concern OSPF can be found in the ospf sub-context located under the individual iface configuration context:

example:/#> configure
example:/config/#> iface vlan1
example:/config/iface-vlan1/#> ospf
example:/config/iface-vlan1/ospf/#>
[no] passive [auto]

Control passive-interface setting for OSPF on this interface.

Default: Auto (Follows router ospf passive-interface setting)

no
Set to active, not passive.
auto
Follow router ospf passive-interface setting.
[no] priority <0-255>

Configure the designated Router (DR) election priority for this interface. A higher value increases the chance to be elected the designated router.

A priority of 0 indicates that the device is not eligible for election.

Default: 1

no
Reset to the default value.
[no] cost <1-65535>

Configure the interface OSPF cost.

Default: 10

no
Reset to the default value.
[no] hello-interval <1-65535>

Configure OSPF hello interval (in seconds) for this interface.

Note

The hello interval setting must be the same on neighbour routers.

Default: 10 (seconds)

no
Reset to the default value.
[no] dead-interval <1-65535>

Configure OSPF dead interval (in seconds) for this interface.

Note

The dead interval setting must be the same on neighbour routers.

Default: 40 (seconds)

no
Reset to the default value.
[no] network [broadcast|non-broadcast|point-to-point]

Explicitly set the OSPF network type.

This setting is useful if the OSPF network type for the specific interface needs to be explicitly set. The network type can be set to any of the following explicit modes:

  • auto
  • broadcast
  • non-broadcast
  • point-to-point

By default no explicit network type will be selected and the selection performed automatically. This selection is performed separately for each individual interface, based on the type of the interface.

Default: auto (no network)

no
Reset to the default value.
broadcast

Used when multiple routers are connected to the same broadcast domain, e.g an ethernet LAN network. This network type is useful when all the routers on the network need to be able to communicate with one another.

In auto mode, this will generally be the default for essentially all interface types on the device. The exception to this being any point-to-point interface or loopback.

non-broadcast
If selected it must also be used together with the neighbor setting in the OSPF router context, i.e, on NBMA links this should be set to send unicast Hello.
point-to-point

This is a network type where the interface is a link between exactly two routers. A packet sent from one router will always have just one recipient.

In auto mode, this will be the default for any point-to-point interface type, e.g. GRE tunnel interfaces.

[no] auth <md5 KEYID | plain> [hash] <SECRET>

Configure authentication of OSPF messages for this interface.

Two different authentication methods can be selected:

  • MD5: Uses a KEYID of 0-255 and a SECRET text string of 8-16 characters (Both the SECRET and the KEYID must be the same on neighbour routers).

  • Plain: Uses a SECRET text string of 4-8 characters (The SECRET must be the same on neighbour routers).

Note

Please note, only one MD5 key currently supported.

Default: Disabled

no
Disable authentication of OSPF messages on the interface.

Status

The current status of a OSPF configured router can be observed in the exec context in the following manner:

 OSPF Routing Process, Router ID: 20.0.0.2
 Supports only single TOS (TOS0) routes
 This implementation conforms to RFC2328
 RFC1583Compatibility flag is disabled
 OpaqueCapability flag is disabled
 Initial SPF scheduling delay 0 millisec(s)
 Minimum hold time between consecutive SPFs 50 millisec(s)
 Maximum hold time between consecutive SPFs 5000 millisec(s)
 Hold time multiplier is currently 1
 SPF algorithm last executed 7m31s ago
 Last SPF duration 24 usecs
 SPF timer is inactive
 LSA minimum interval 5000 msecs
 LSA minimum arrival 1000 msecs
 Write Multiplier set to 20
 Refresh timer 10 secs
 This router is an ASBR (injecting external routing information)
 Number of external LSA 1. Checksum Sum 0x0000eba6
 Number of opaque AS LSA 0. Checksum Sum 0x00000000
 Number of areas attached to this router: 1
 Area ID: 0.0.0.0 (Backbone)
   Number of interfaces in this area: Total: 2, Active: 2
   Number of fully adjacent neighbors in this area: 2
   Area has no authentication
   SPF algorithm executed 7 times
   Number of LSA 8
   Number of router LSA 4. Checksum Sum 0x00016360
   Number of network LSA 4. Checksum Sum 0x00024d06
   Number of summary LSA 0. Checksum Sum 0x00000000
   Number of ASBR summary LSA 0. Checksum Sum 0x00000000
   Number of NSSA LSA 0. Checksum Sum 0x00000000
   Number of opaque link LSA 0. Checksum Sum 0x00000000
   Number of opaque area LSA 0. Checksum Sum 0x00000000

In addition we could also check the OSPF neighbors:

Router-A:/#> show ip ospf neighbor

Neighbor ID   Pri State        Dead Time Address    Interface       RXmtL RqstL DBsmL
10.0.14.1       1 Full/Backup    36.044s 10.0.1.2   vlan1:10.0.1.1  0     0     0
10.0.12.1       1 Full/DR        37.909s 10.0.2.1   vlan2:10.0.2.2  0     0     0

We can also check the OSPF database in the following way:

Router-A:/#> show ip ospf database

       OSPF Router with ID (10.0.11.1)

                Router Link States (Area 0.0.0.0)

Link ID         ADV Router      Age  Seq#       CkSum  Link count
10.0.11.1       10.0.11.1       1434 0x8000000c 0x3463 3
10.0.12.1       10.0.12.1       1675 0x8000000c 0x8709 3
10.0.13.1       10.0.13.1       1406 0x8000000b 0xf296 3
10.0.14.1       10.0.14.1       1425 0x80000011 0xbdc6 3

                Net Link States (Area 0.0.0.0)

Link ID         ADV Router      Age  Seq#       CkSum
10.0.1.1        10.0.11.1       1444 0x80000004 0x1de8
10.0.2.1        10.0.12.1       1675 0x80000004 0xec19
10.0.3.1        10.0.13.1       1666 0x80000004 0xf011
10.0.4.2        10.0.13.1       1436 0x80000004 0xf10c

Routes

The purpose of OSPF is to ensure that we learn routes to reach all of our intended destinations. To check the routes that the are known and what routes are active we can use the show ip route command as such:

example:/#> show ip route
S - Static | C - Connected | K - Kernel route  | > - Selected route
O - OSPF   | R - RIP       | [Distance/Metric] | * - FIB route

O   10.0.1.0/24 [110/10] is directly connected, vlan1, 19:45:35
C>* 10.0.1.0/24 is directly connected, vlan1
O   10.0.2.0/24 [110/10] is directly connected, vlan2, 19:45:35
C>* 10.0.2.0/24 is directly connected, vlan2
O>* 10.0.3.0/24 [110/20] via 10.0.2.1, vlan2, 19:44:55
O>* 10.0.4.0/24 [110/20] via 10.0.1.2, vlan1, 19:41:00
O   10.0.11.0/24 [110/10] is directly connected, vlan3, 19:45:35
C>* 10.0.11.0/24 is directly connected, vlan3
O>* 10.0.12.0/24 [110/20] via 10.0.2.1, vlan2, 19:44:55
O>* 10.0.13.0/24 [110/30] via 10.0.1.2, vlan1, 19:41:00
  *                       via 10.0.2.1, vlan2, 19:41:00
O>* 10.0.14.0/24 [110/20] via 10.0.1.2, vlan1, 19:41:00

Any route denoted with an “O” is a route that has been learnt by OSPF. In this case we can see that some routes that OSPF have learnt are not used. The reason for this is that in this case also have connected routes to the same destination. A connected route has a lower administrative distance and will be selected over the OSPF route.

If we are interested in isolating the routes that OSPF have knowledge of we can use the show ip ospf route command:

Router-A:/#> show ip ospf route
============ OSPF network routing table ============
N    10.0.1.0/24           [10] area: 0.0.0.0
                           directly attached to vlan1
N    10.0.2.0/24           [10] area: 0.0.0.0
                           directly attached to vlan2
N    10.0.3.0/24           [20] area: 0.0.0.0
                           via 10.0.2.1, vlan2
N    10.0.4.0/24           [20] area: 0.0.0.0
                           via 10.0.1.2, vlan1
N    10.0.11.0/24          [10] area: 0.0.0.0
                           directly attached to vlan3
N    10.0.12.0/24          [20] area: 0.0.0.0
                           via 10.0.2.1, vlan2
N    10.0.13.0/24          [30] area: 0.0.0.0
                           via 10.0.1.2, vlan1
                           via 10.0.2.1, vlan2
N    10.0.14.0/24          [20] area: 0.0.0.0
                           via 10.0.1.2, vlan1

============ OSPF router routing table =============

============ OSPF external routing table ===========