Open Shortest Path First version 2 (OSPFv2)
Lesson Overview
OSPFv2 is a link-state interior gateway protocol (IGP) used to exchange IPv4 routes inside an autonomous system. Rather than advertising a complete routing table to neighbors, OSPF routers describe their local links as link-state information, flood that information reliably, build a synchronized link-state database (LSDB), and independently run the Shortest Path First (SPF) algorithm to calculate best paths.
After this module, the student should be able to: Explain OSPF link-state operation and the relationship between LSAs, the LSDB, SPF, and the routing table.
Lesson Objectives
By the end of this lesson, learners will be able to:
Understand OSPF packet types and neighbor states from Down to Full.
Explain DR/BDR election and adjacency formation on multiaccess networks.
Differentiate OSPF broadcast and point-to-point network types.
Understand multi-area OSPF, Area 0, ABRs, LSAs, and SPF calculations.
Configure OSPF topology, DR/BDR priorities, and passive interfaces.
Verify OSPF neighbors, interfaces, LSDB, and routing tables.
Troubleshoot OSPF adjacency failures, MTU mismatches, duplicate router IDs, network-type mismatches, and passive-interface issues.
|
Protocol facts: OSPF uses IP protocol number 89. The All-SPF Routers multicast address is 224.0.0.5; DR/BDR-related traffic on multiaccess networks also uses 224.0.0.6 (All DRouters). |
1. Introduction to OSPF
Open Shortest Path First (OSPF) is a link-state Interior Gateway Protocol (IGP) used to exchange routing information between routers within an Autonomous System (AS).
OSPF is an open-standard routing protocol defined by the Internet Engineering Task Force (IETF). It uses the Shortest Path First (SPF) algorithm, also known as Dijkstra's algorithm, to calculate the shortest and most efficient path toward destination networks.
OSPFv2 is primarily used for IPv4 routing and is defined in RFC 2328.
Unlike distance-vector routing protocols, OSPF routers exchange link-state information to build a logical representation of the network topology. Each router uses this information to calculate optimal routes.
OSPF is widely deployed in enterprise networks, service-provider environments, and large-scale IP infrastructures because of its scalability, fast convergence, hierarchical design, and vendor interoperability.
1.2 Why Do We Need OSPF?
In enterprise networks, multiple routers connect different LANs, data centers, branches, and WAN locations.
Static routing becomes difficult to maintain when the network grows because routes must be manually configured and updated.
OSPF addresses these challenges through automatic route discovery, topology awareness, and dynamic path calculation.
Key Benefits of OSPF:
Dynamic Routing: Automatically learns and advertises IPv4 network prefixes.
Fast Convergence: Recalculates routes when network changes occur.
Loop-Free Routing: Uses SPF calculations to construct a shortest-path tree.
Scalability: Supports hierarchical routing through multiple OSPF areas.
Open Standard: Operates across compatible network vendors.
Equal-Cost Multipath (ECMP): Supports multiple equal-cost paths.
Route Summarization: Supports summarization at appropriate area and external route boundaries.
Authentication: Supports authenticated OSPF exchanges to protect routing information.
Efficient Updates: Floods link-state changes instead of periodically transmitting the complete routing table.
1.2 OSPF Key Characteristics
Feature | Description |
|---|---|
Protocol Name | Open Shortest Path First |
Version | OSPFv2 |
Protocol Type | Link-State IGP |
Standard | RFC 2328 |
Algorithm | Dijkstra SPF |
IP Protocol Number | 89 |
Multicast Address | 224.0.0.5 — AllSPFRouters |
DR/BDR Multicast | 224.0.0.6 — AllDRouters |
Administrative Distance | 110 on Cisco IOS |
Metric | OSPF Cost |
Hierarchical Routing | Multiple areas |
Backbone Area | Area 0 |
Load Balancing | Equal-cost paths |
Routing Support | IPv4 |
Classless Routing | CIDR and VLSM |
1.3 Why Dynamic Routing Is Required
Consider an enterprise network with three routers connected through redundant links.
R1, R2, and R3 connect different network segments.If static routes are configured manually, administrators must maintain route entries and account for network failures.
With OSPF:
Routers discover neighboring OSPF devices.
Routers exchange link-state information.
Each router builds an LSDB for its area.
SPF calculates the lowest-cost paths.
Best routes are installed in the routing table.
When a link fails, OSPF updates the topology and recalculates affected paths.
This process allows the network to adapt dynamically without requiring manual route updates for every topology change.
2. Understanding Link-State Routing
OSPF is classified as a link-state routing protocol because routers describe their directly connected topology and exchange that information throughout the OSPF area.
Each router maintains a Link-State Database containing information about the network topology.
Routers in the same area maintain logically consistent LSDBs for that area after synchronization.
2.1 How Link-State Routing Works
OSPF operates through the following process:
Step 1 - Neighbor Discovery
Routers send Hello packets to discover neighboring OSPF routers.
Step 2 - Neighbor Relationship Formation
Routers verify OSPF parameters and establish neighbor relationships.
Step 3 - Adjacency Formation
Eligible neighbors synchronize link-state databases through the OSPF database exchange process.
Step 4 - Link-State Advertisement Exchange
Routers exchange LSAs containing topology information.
Step 5 - LSDB Synchronization
Adjacent routers synchronize their link-state information.
Step 6 - SPF Calculation
Each router runs Dijkstra's SPF algorithm to calculate shortest paths from itself to destinations represented in the topology.
Step 7 - Routing Table Installation
OSPF selects eligible routes for installation in the IP routing table.
Step 8 - Topology Change Handling
When network topology changes, OSPF floods updated LSAs and recalculates affected routes.
2.2 OSPF Routing Process
2.3 Link-State Database (LSDB)
The LSDB contains LSAs describing the topology visible within the relevant OSPF area.
Each router uses this information to calculate routes.
Important characteristics:
An OSPF router maintains separate LSDB information for each area to which it belongs.
Routers in the same area synchronize their area-specific LSAs.
LSAs are flooded according to their defined scope.
SPF calculations use the relevant area's topology information.
Inter-area destinations are learned through area-boundary advertisements rather than through a single network-wide LSDB.
Verification Command
show ip ospf database
This command displays LSAs stored in the OSPF database.
3. OSPF Core Terminology
3.1 OSPF Router ID
The OSPF Router ID (RID) is a unique 32-bit identifier used to identify an OSPF router within the OSPF routing domain.
It is represented using IPv4 dotted-decimal notation.
Example:
router-id 1.1.1.1
The Router ID does not necessarily need to be an active interface IP address.
OSPF Router ID Selection
On Cisco IOS, when a Router ID is not explicitly configured, the normal selection order is:
Manually configured OSPF Router ID.
Highest IPv4 address on an operational loopback interface.
Highest IPv4 address on an operational non-loopback interface.
Example
Assume R1 has:
|
GigabitEthernet0/0: 10.12.12.1 GigabitEthernet0/1: 10.13.13.1 Loopback0: 192.168.10.1 |
If no Router ID is manually configured, R1 normally selects: 192.168.10.1 because an operational loopback interface is preferred.
Manual Router ID Configuration
|
router ospf 100 router-id 1.1.1.1 |
|
Important: Changing the Router ID of an already running OSPF process may require restarting the OSPF process before the new ID takes effect. Such a restart disrupts adjacencies and must be planned carefully in production. |
3.2 OSPF Process ID
The Process ID identifies an OSPF process locally on a Cisco router.
Example:
router ospf 100
The Process ID does not need to match between neighboring routers.
For example, R1 can use Process ID 100 while R2 uses Process ID 200 and still establish an adjacency if their other required parameters match.
3.3 OSPF Area
An OSPF area is a logical grouping of routers sharing area-specific topology information.
Examples:
Area 0
Area 10
Area 20
Area 0 is the backbone area.
3.4 Link-State Advertisement (LSA)
An LSA is an OSPF information structure used to describe topology or routing information.
LSAs are distributed through OSPF flooding.
3.5 Link-State Database (LSDB)
The LSDB contains the LSAs known by a router for an OSPF area.
Routers within the same area synchronize the applicable area-scoped LSAs.
3.6 Shortest Path First (SPF)
SPF is Dijkstra's algorithm used to calculate the shortest paths through an OSPF area's topology.
3.7 OSPF Cost
Cost is the metric OSPF uses to determine the preferred route.
Lower total cost is generally preferred among otherwise comparable OSPF paths.
3.8 Adjacency
An adjacency is a synchronized OSPF neighbor relationship.
A Full adjacency indicates that the required database exchange has completed.
4. OSPF Packet Types
Open Shortest Path First (OSPF) uses five packet types to discover neighboring routers, establish adjacencies, synchronize Link-State Databases (LSDBs), and maintain accurate network topology information.
OSPF packets are carried directly over IP using protocol number 89, rather than TCP or UDP.
OSPFv2 commonly uses two multicast addresses:
- 224.0.0.5 (AllSPFRouters): Communicates with OSPF routers on the local network.
- 224.0.0.6 (AllDRouters): Communicates with the DR and BDR on broadcast multiaccess networks.
4.1 OSPF uses five packet types.
| Packet Type | Name | Function |
|---|---|---|
| 1 | Hello | Discover and maintain neighbors |
| 2 | Database Description (DBD) | Describe LSDB contents |
| 3 | Link-State Request (LSR) | Request specific LSAs |
| 4 | Link-State Update (LSU) | Deliver LSAs |
| 5 | Link-State Acknowledgment (LSAck) | Acknowledge received LSAs |
1. Hello Packet
Hello packets are used to discover neighbors and maintain established relationships.
Important Hello information includes:
- Router ID
- Area-related interface context
- Hello Interval
- Dead Interval
- Router Priority
- Designated Router
- Backup Designated Router
- Known neighbors
- OSPF Options
Authentication and area information are also validated as part of OSPF packet processing.
2. Database Description Packet
DBD packets summarize LSAs stored in a router's LSDB.
During database synchronization, neighbors exchange DBD packets to identify missing or outdated information.
3. Link-State Request Packet
An LSR requests specific LSA information from a neighbor.
4. Link-State Update Packet
An LSU transports one or more LSAs.
LSUs are used during initial database synchronization and subsequent topology updates.
5. Link-State Acknowledgment Packet
LSAck packets acknowledge received LSAs and support reliable flooding.
Simplified Packet Exchange
Figure 4 - OSPF packet types and exchange
Actual database synchronization may involve several bidirectional exchanges of DBD, LSR, LSU, and acknowledgment packets.
4.2 OSPF Cost and SPF
SPF calculates the least cumulative OSPF cost from the local router to each reachable topology element. Interface cost is derived from interface bandwidth and the configured OSPF reference bandwidth. On many Cisco platforms, the historical default reference bandwidth is 100 Mbps, so high-speed interfaces can all appear as cost 1 unless the reference bandwidth is increased consistently on every OSPF router.
|
router ospf 10 auto-cost reference-bandwidth 100000 ! 100000 Mbps = 100 Gbps reference bandwidth ! Configure the SAME value on every OSPF router in the domain. |
4.3 OSPF Cost Calculation and Path Selection
OSPF chooses the path with the lowest total cost. The total path cost is the sum of the outgoing OSPF interface costs along the path from the calculating router to the destination.
Cisco derives interface cost from reference bandwidth divided by interface bandwidth. Historically the default reference bandwidth is 100 Mbps, which makes FastEthernet, GigabitEthernet, and faster links all collapse to cost 1. In modern enterprise designs, configure a larger common reference bandwidth on every OSPF router.
Use auto-cost reference-bandwidth under router ospf to change the calculation domain-wide. The value is specified in Mbps. Every router should use the same value so all routers evaluate link speeds consistently.
Use ip ospf cost <value> under an interface when the design requires an explicit metric. A manually configured OSPF cost overrides the automatically calculated cost for that interface.
Changing OSPF cost does not break the neighbor adjacency. It changes SPF results and can move traffic to another valid path after SPF recalculation.
If two paths have the same route type and total cost, OSPF can install them as equal-cost paths. OSPF does not normally perform unequal-cost load balancing.
|
Reference bandwidth example |
Interface bandwidth |
Calculated OSPF cost |
|
100 Mbps (legacy default) |
100 Mbps |
1 |
|
100 Mbps (legacy default) |
1 Gbps |
1 (cannot distinguish from 100 Mbps) |
|
100,000 Mbps |
1 Gbps |
100 |
|
100,000 Mbps |
10 Gbps |
10 |
|
100,000 Mbps |
100 Gbps |
1 |
|
R1(config)# router ospf 10 R1(config-router)# auto-cost reference-bandwidth 100000 R1(config-router)# exit R1(config)# interface GigabitEthernet0/0 R1(config-if)# ip ospf cost 25 R1(config-if)# end R1# show ip ospf interface GigabitEthernet0/0 Process ID 10, Router ID 1.1.1.1, Network Type BROADCAST, Cost: 25 |
|
VERIFY / LOOK FOR: Confirm the interface cost shown by show ip ospf interface. For automatic-cost designs, verify the same reference bandwidth is configured throughout the OSPF domain; for manual-cost designs, verify the configured value on every intended path. |
5. OSPF Neighbor Relationships
Figure 5 - OSPF neighbor-state progression
1. Down State
Down is the initial OSPF neighbor state.
A router is in the Down state when it has not received valid Hello packets from a neighbor or when an established neighbor relationship has been lost.
On an active broadcast interface, a neighbor that has not yet been discovered may not appear in the neighbor table at all.
How It Works
- OSPF is enabled on an interface.
- The router begins sending Hello packets.
- It waits for Hello packets from neighboring routers.
- When a valid Hello is received, the neighbor normally moves to Init.
Example
2. Attempt State (for P2P)
Attempt is primarily used on certain NBMA network types where neighbors are manually configured.
During Attempt, the router actively sends Hello packets toward a configured neighbor but has not received a valid Hello response.
How It Works
A neighbor is configured manually.
OSPF sends unicast Hello packets toward the neighbor.
The router waits for a response.
A valid received Hello moves the relationship toward Init.
A neighbor enters Init when an OSPF router receives a valid Hello packet but does not find its own Router ID in the received Hello packet's neighbor list.
This indicates that the local router has heard from its neighbor, but bidirectional discovery has not yet been confirmed.
How It Works
Consider two routers:
R1 Router
ID: 1.1.1.1
R2 Router ID: 2.2.2.2
R1 receives a Hello packet from R2.
However, R2's Hello does not yet contain Router ID 1.1.1.1 in its neighbor list.
R1 records R2 in the Init state.
Packet Flow
4. 2-Way State
The 2-Way state confirms bidirectional OSPF neighbor communication.
The local router has received a Hello packet containing its own Router ID in the neighbor list.
At this stage, both routers recognize each other as OSPF neighbors.
How It Works
R1 receives a Hello from R2.
R1 includes R2's Router ID in its next Hello.
R2 receives that Hello and recognizes its own Router ID.
Both routers establish bidirectional communication.
OSPF determines whether a full adjacency is required.
Packet Flow
DR/BDR Election
On broadcast Ethernet networks, OSPF elects a Designated Router (DR) and Backup Designated Router (BDR).
DROTHER routers normally establish Full adjacencies with the DR and BDR.
Two DROTHER routers normally remain in the 2-Way state with each other.
5. ExStart State
ExStart is the state where OSPF routers begin preparing to synchronize their LSDBs.
Routers negotiate which device will act as master and which will act as slave for the Database Description (DBD) exchange.
Key Activities
Master/slave negotiation.
Initial DBD sequence-number selection.
Preparation for LSDB summary exchange.
Database exchange session establishment.
Master/Slave Election
The router with the higher…
