Kahibaro
Discord Login Register

10.4 OSPF

Overview

Open Shortest Path First, OSPF, is a link state routing protocol that routers use to share information about the network and to calculate efficient paths to every destination. It is widely used in enterprise networks and is standardized as an open protocol, so equipment from different vendors can interoperate. OSPF belongs to the family of link state protocols, which are covered separately, so here the focus is on what makes OSPF itself special and how it behaves in practice.

OSPF works by discovering neighbors, building a detailed map of the network topology, then running an algorithm to compute the shortest path to each destination. It does all of this within an OSPF domain that is called an Autonomous System or more precisely an OSPF routing domain.

Link State and the SPF Algorithm in OSPF

OSPF treats the network as a graph, where routers are nodes and links between them are edges. Each link has a cost, which is a numeric value that represents how “expensive” it is to use that link. OSPF uses the Shortest Path First algorithm, often called Dijkstra’s algorithm, to find the lowest cost path to each destination network.

Each router collects link state information from all other routers in its area. This information describes which routers are connected and with what costs. The full set of this information is called the Link State Database, LSDB. Because the LSDB is the same on all routers in the same area, each router runs the SPF calculation locally and produces the same view of shortest paths.

The SPF algorithm behaves as follows, conceptually. The router selects itself as the root and then builds a tree of paths outward. It always chooses the next link that results in the lowest total accumulated cost. Once a path is confirmed as the shortest, it is not changed until the topology itself changes. When links go up or down or their cost changes, the router triggers a new SPF calculation to recompute paths.

In OSPF, the best path is the one with the lowest total cost, which is the sum of the costs of each link along the path:
$$
\text{OSPF\ path\ cost} = \sum_{i=1}^{n} \text{cost of link}_i
$$
OSPF does not use hop count for its primary path selection.

OSPF Metrics and Cost

OSPF uses a single metric called cost to compare paths. Cost is a dimensionless number, but it is usually related to interface bandwidth. By default in many implementations, the cost of a link is derived from a reference bandwidth divided by the actual interface bandwidth, then rounded.

For example, a common default formula is:

Default OSPF interface cost (Cisco style):
$$
\text{cost} = \left\lfloor \frac{\text{reference bandwidth}}{\text{interface bandwidth}} \right\rfloor
$$
with a typical reference bandwidth of 100 Mbps.

This produces lower costs for faster links, so OSPF naturally prefers higher bandwidth paths. The reference bandwidth is configurable, and modern networks often increase it so that very fast interfaces do not all end up with the same cost. Besides bandwidth based automatic costs, administrators can manually set interface costs to influence path selection deliberately.

OSPF Areas and Hierarchy

A fundamental feature of OSPF is its hierarchical design based on areas. An area is a logical grouping of routers that share the same LSDB. Within an area, each router knows the full topology. Between areas, OSPF shares only summarized and abstracted information, not every detail.

At the center of an OSPF network is Area 0, also called the backbone area. All other areas must logically connect to Area 0. Traffic that goes from one non backbone area to another must pass through the backbone. This hierarchy helps limit the size of LSDBs and reduces how often routers must run SPF, which improves scalability and performance.

Routers that exist in multiple areas at the same time are called Area Border Routers, ABRs. An ABR has a separate LSDB for each area it participates in and is responsible for exchanging summarized route information between those areas. There are also settings for how much summarization occurs, but the concept of ABRs and areas is the key to understanding OSPF hierarchy.

OSPF also supports special area types, which optimize what information is carried inside the area by controlling which external or summary routes appear. Examples, such as stub areas or not so stubby areas, are variations of the core concept and mainly affect what LSAs are allowed. The details of those types extend from the basic idea that areas can be tuned to scale better or restrict information.

OSPF Router Roles and Types

Different routers in an OSPF domain have different roles based on where they sit and what they connect.

An internal router belongs to only one area and has all of its interfaces inside that single area. It holds a single LSDB and participates fully inside that area only.

An Area Border Router, ABR, connects two or more OSPF areas, typically Area 0 and a non backbone area. ABRs maintain one LSDB per area and summarize or translate LSAs when passing routing information between them.

An Autonomous System Boundary Router, ASBR, is an OSPF router that redistributes routes from another routing domain into OSPF. This might mean importing static routes, RIP routes, or BGP routes, then advertising them to OSPF neighbors as external routes. A single router can be both an ABR and an ASBR if it connects multiple OSPF areas and also redistributes from outside.

When OSPF runs over broadcast multiaccess networks like Ethernet, OSPF also uses the concepts of a Designated Router, DR, and a Backup Designated Router, BDR. These roles exist only on those shared networks and are described more later when discussing network types. They do not change the global role of the router, which might still be internal, ABR, or ASBR.

OSPF Network Types and DR/BDR

OSPF behaves differently depending on the type of network it runs on. The network type describes how routers on that link discover neighbors and exchange LSAs.

On broadcast multiaccess networks such as Ethernet, many routers can share the same link. If each router tried to form a full adjacency with every other router, the amount of OSPF traffic would grow very quickly as routers were added. To prevent this, OSPF elects a Designated Router, DR, and a Backup Designated Router, BDR, on each such network segment.

All other routers on the segment, called DROthers, form full adjacencies only with the DR and BDR. They do not form full adjacencies with each other. The DR acts as a central point to collect LSAs and then redistributes them to others on that segment. The BDR is a hot standby that takes over if the DR fails, which helps maintain stability.

The election of the DR and BDR is based on OSPF priority and router ID. Routers with higher priority are preferred. If priorities tie, the router ID is used as a tie breaker. The first DR and BDR are selected when the segment becomes active, and they typically stay in place unless conditions cause a new election.

On point to point links that connect exactly two routers, such as a direct WAN link, there is no need for DR or BDR. The two routers simply become neighbors and exchange LSAs directly. This keeps OSPF signaling simple and efficient for those link types.

OSPF Neighbor Discovery and States

Before OSPF can exchange full routing information, routers must first discover each other and agree to form an adjacency. OSPF uses a series of well defined neighbor states to manage this process on each interface.

Routers use OSPF Hello packets, sent to a multicast address on most links, to discover neighbors. Each Hello packet includes key settings, such as the OSPF area, network type, timers, and authentication parameters. Routers only form adjacencies if these settings match. This prevents misconfigured routers from joining the wrong OSPF domain.

When a router first sees another router’s Hello packet, it enters an initial state where it knows of the neighbor but has not yet received its view of the LSDB. Step by step, routers exchange special OSPF messages to describe which LSAs they have and to request any that are missing. This process goes through several intermediate states until both routers have synchronized LSDBs. At that point, the adjacency reaches the Full state.

The existence of these states allows OSPF to carefully control synchronization and to recover if partial failures occur. For example, if a link flaps, routers can detect that an adjacency dropped from Full and restart the synchronization procedure. Debugging tools often show these states, so understanding that OSPF adjacencies move through a lifecycle is important.

OSPF LSAs and LSDB

OSPF does not flood complete routing tables. Instead it uses small pieces of information called Link State Advertisements, LSAs, which together describe the network topology and reachable networks. Each LSA type has a specific purpose and scope, and combining them produces the LSDB.

Some LSA types are used inside a single area. These describe the routers, their links, and the networks in that area. Other LSAs are used to carry summary routes between areas, and still others carry external routes that have been learned from outside OSPF by an ASBR.

The LSDB is the structured collection of all LSAs that are valid in a particular area. Because OSPF is a link state protocol, every router in the same area must have the same LSDB. OSPF achieves this by reliable flooding. When a router receives a new or changed LSA, it forwards it to all neighbors except the one it received it from. Each LSA includes sequence numbers and ages so routers can tell which version is current and can discard old information.

Within a given OSPF area, all routers must have an identical LSDB for OSPF to compute correct and consistent routes.

LSAs age out if they are not refreshed within a specific time, which ensures that stale information eventually disappears. Routers periodically regenerate LSAs they own to keep the data fresh. This mechanism avoids permanent loops caused by outdated topology information.

OSPF Route Types: Intra, Inter, and External

The OSPF database contains not only topology but also information that becomes routing entries. OSPF classifies routes based on where they come from in the OSPF hierarchy.

An intra area route is a route to a destination network that is inside the same OSPF area as the router. These routes come from the area’s own LSAs and are considered the most trustworthy inside that area.

An inter area route is a route to a network located in a different OSPF area. These routes are typically learned from an ABR. The ABR takes routes from one area, summarizes them if configured, and advertises them into another area as inter area summaries.

External routes originate from outside the OSPF domain itself, for example from static routes, another IGP such as RIP, or from BGP. These are learned via an ASBR and are grouped into two main external types, often called Type 1 and Type 2 in OSPF terminology. The main difference relates to how the cost is calculated and whether the internal OSPF cost to reach the ASBR is combined with the external metric.

When OSPF has multiple possible routes to the same destination, it prefers intra area routes over inter area routes, and inter area routes over external routes, assuming the protocol is the same. Within the same category, it still selects the lowest cost path.

OSPF Timers and Convergence

OSPF uses several timers to control how often it sends Hello packets, how long it waits before declaring a neighbor down, and how quickly it can flood LSAs. Typical OSPF Hello intervals on broadcast networks are several seconds, and the dead interval is usually a multiple of the Hello interval. These values are configurable and must match between neighbors.

Convergence in OSPF refers to how long it takes the network to react to changes, such as link failures, and for all routers to agree on the new topology and paths. When a link goes down, OSPF quickly detects the loss of adjacency and generates updated LSAs. These LSAs are flooded, LSDBs are updated, and each router reruns the SPF algorithm to compute new routes.

Because OSPF maintains a detailed view of topology, convergence can often be very fast, especially within smaller areas. However, design choices like area size, LSA flooding scope, and SPF throttling parameters affect the actual convergence time. Careful tuning and area planning are essential in large networks to avoid excessive CPU use or instability from constant recalculation.

Authentication and Security in OSPF

OSPF includes built in support for authenticating neighbors, which helps prevent unauthorized devices from participating in the routing domain. Routers on the same segment can be configured to use a shared password or more advanced methods. All routers on a given interface must agree on the authentication method and keys before they can become neighbors and form adjacencies.

Authentication focuses on verifying that LSAs and Hello packets come from trusted sources, not on encrypting the content itself. Because of this, OSPF authentication is often combined with other security measures when routing over untrusted paths, such as using tunnels that add encryption. Still, OSPF’s own authentication is a critical line of defense against accidental or malicious injection of routes from inside a network.

Summary

OSPF is a hierarchical, link state routing protocol that uses cost based metrics and the SPF algorithm to compute efficient paths. It builds a synchronized LSDB of LSAs in each area and uses ABRs and ASBRs to scale across areas and connect to other routing domains. Features such as DR/BDR on multiaccess networks, structured neighbor states, and route classification into intra, inter, and external types help OSPF run reliably in networks of many sizes.

Views: 50

Comments

Please login to add a comment.

Don't have an account? Register now!