OSPF Concepts
Exam topics covered
3.4 Configure and verify single area OSPFv2 (3.4.a Neighbor adjacencies, 3.4.b Point-to-point, 3.4.c Broadcast (DR/BDR selection), 3.4.d Router ID): the concepts behind each item
3.2.c Routing protocol metric (OSPF cost)
Foundation. Open Shortest Path First (OSPF) is the most widely deployed interior routing protocol in enterprise networks and the only dynamic routing protocol you must configure on the CCNA exam. Before typing a single command, you need a clear mental model of how OSPF works: how routers discover each other, what they exchange, how they agree on a map of the network, and how each one computes its best paths. This chapter builds that model. Chapter 22 then puts it into practice with configuration, verification and troubleshooting. Everything here refers to OSPF version 2 (OSPFv2, RFC 2328), which routes IPv4.
21.1 Link-State Routing
Chapter 19 contrasted distance vector protocols, which share their conclusions ("I can reach 10.9.0.0 at distance 3"), with link-state protocols, which share raw facts. An OSPF router describes its own links: which interfaces it has, which subnets they connect to, what each link costs, and which neighbours are attached. That description is packaged in a link-state advertisement (LSA) and flooded to every router in the area. The process has four stages:
- 1. Discover neighbours by exchanging Hello packets on each OSPF-enabled interface.
- 2. Flood LSAs so that every router in the area receives an identical copy of every LSA.
- 3. Build the link-state database (LSDB), the collection of all LSAs. Every router in an area has the same LSDB, so every router has the same map.
- 4. Run the SPF algorithm (Dijkstra's Shortest Path First) on the LSDB, with itself as the root, to find the lowest-cost path to every subnet, and place those routes in the routing table.
- 1 Hellos
- discover and keep
- neighbours
- 2 Flood LSAs
Dbd, lsr, lsu,
LSAck packets
3 lsdb
identical map on
every router in area
4 spf
best paths into the
routing table
A topology change triggers a new LSA, which is flooded; every router reruns SPF.
Figure 21-1 The four stages of link-state routing in OSPF.
Because every router has the full map, OSPF converges quickly and never forms loops from stale rumours. OSPF also sends updates only when something changes (plus a periodic refresh of each LSA every 30 minutes), unlike RIP's full-table broadcast every 30 seconds. The price is memory for the LSDB and CPU for SPF, which is why large networks are divided into areas.
21.1.1 A worked SPF example
Dijkstra's algorithm grows a shortest-path tree outwards from the root router. At each step it confirms the closest not-yet-confirmed router, then updates the tentative costs of that router's neighbours. Figure 21-2 shows five routers and the OSPF cost of each link; we run SPF from R1.
Figure 21-2 Left: link costs in the LSDB. Right: the resulting tree from R1 (blue), with total cost to each router. Grey dashed links are not used by R1.
Table 21-1 Running SPF from R1, step by step
- Step
- Confirm (cheapest
- tentative)
- Tentative list after examining its links
- 1 R1, cost 0 (the root) R2 = 10 (direct), R3 = 5 (direct)
2 R3, cost 5 R2 = 5 + 3 = 8 (better than 10, replace); R5 = 5 + 9 = 14; R4 = 5 + 20 = 25
3 R2, cost 8 R4 = 8 + 1 = 9 (better than 25, replace); R5 stays 14 4 R4, cost 9 R5 = 9 + 4 = 13 (better than 14, replace)
5 R5, cost 13 Empty: all routers confirmed
The result is surprising at first glance: R1 never uses its direct cost-10 link to R2, because the path through R3 costs only 8. Every destination is reached via R3, so R3 is the next hop for every route R1 installs from this tree. The cost of a route to a subnet is the cost to reach the router attached to it plus the cost of that router's interface into the subnet. Remember the core rule: OSPF cost is the sum of the outgoing interface costs along the path, counted in the direction the packets travel.
21.2 OSPF Areas
In a very large single area, every router would hold every LSA and rerun SPF for every flap anywhere in the network. OSPF solves this with areas: groups of routers and links that share an LSDB. Detailed topology (type 1 and type 2 LSAs) stays inside an area; other areas see only a summary of its subnets. A change in one area therefore causes SPF to run only in that area. Backbone area (area 0): every multi-area design has one, and every other area must connect to it. Traffic between non-backbone areas passes through area 0.
Internal router: all interfaces in one area.
Backbone router: at least one interface in area 0.
Area border router (ABR): interfaces in area 0 and at least one other area; it keeps a separate LSDB per area and advertises summaries between them.
Autonomous system boundary router (ASBR): injects external routes (for example a default route to the Internet or routes from another protocol) into OSPF.
- Area 1 Area 0 (backbone) Area 2
- Internal ABR
- Backbone router
- ABR Internal
Asbr
to Internet / other protocol
Figure 21-3 A multi-area OSPF design. ABRs sit on the boundary between area 0 and another area; the ASBR connects to the outside world.
The CCNA blueprint asks only for single-area OSPF, normally area 0. In a single area every router is an internal (and backbone) router, there are no ABRs, and all routers share one LSDB. You still need to know the multi-area vocabulary, because it explains the LSA types in Section 21.8 and appears in exam distractors.
Exam alert
An interface belongs to exactly one area, but a router can have interfaces in several areas. Area membership is a property of the interface (and its link), not of the router. Two neighbours must put their shared link in the same area.
21.3 The OSPF Router ID
Every OSPF router is identified by a 32-bit router ID (RID), written like an IPv4 address. The RID names the router in Hellos, LSAs and neighbour tables, and breaks ties in the DR election. When the OSPF process starts, IOS chooses the RID in this order:
- 1. The value set with the router-id command under router ospf .
- 2. Otherwise, the highest IPv4 address of any up loopback interface.
- 3. Otherwise, the highest IPv4 address of any up (non-loopback) interface. The interfaces considered need not have OSPF enabled on them. The RID must be unique in the OSPF domain; duplicates cause neighbour and LSDB problems. Once chosen, the RID does not change just because an interface address changes; a manually changed router-id takes effect only after clear ip ospf process or a reload. Best practice is to set it explicitly, often to match a loopback address.
R1 — console
R1# show ip protocols
- *** IP Routing is NSF aware ***
- Routing Protocol is "ospf 1"
- Outgoing update filter list for all interfaces is not set
- Incoming update filter list for all interfaces is not set
- Router ID 1.1.1.1
- Number of areas in this router is 1. 1 normal 0 stub 0 nssa
- Maximum path: 4
- Routing for Networks:
- 10.10.10.0 0.0.0.255 area 0
- Routing Information Sources:
- Gateway Distance Last Update
- 4.4.4.4 110 00:06:12
- 3.3.3.3 110 00:06:12
- Distance: (default is 110)
R1(config)# router ospf 1 R1(config-router)# router-id 11.11.11.11
% OSPF: Reload or use "clear ip ospf process" command, for this to take effect
Figure 21-4 Viewing the router ID. A new manual RID waits until the process is restarted. Output is illustrative of Cisco IOS 15 /
Ios xe.
21.4 OSPF Packets
OSPF runs directly over IP as IP protocol number 89 (not TCP or UDP), so it provides its own reliability with acknowledgements. There are five packet types, all sharing a common 24- byte header that carries the version, type, router ID, area ID, checksum and authentication fields.
Table 21-2 The five OSPF packet types
Type Name Purpose
1 Hello Discovers neighbours, checks parameters, elects DR/BDR, acts as keepalive
- 2 Database Description (DBD or
- DD)
- Lists summaries (headers) of the LSAs in the sender's LSDB
- during adjacency formation
3 Link-State Request (LSR) Asks the neighbour for complete copies of LSAs that are missing or newer
4 Link-State Update (LSU) Carries one or more complete LSAs, in reply to an LSR or when flooding a change
- 5 Link-State Acknowledgement
- (LSAck)
- Confirms receipt of LSUs, making flooding reliable
OSPF uses two reserved multicast addresses. 224.0.0.5 (AllSPFRouters) reaches every OSPF router on the link; Hellos are sent here. 224.0.0.6 (AllDRouters) reaches only the DR and BDR. Both are link-local multicasts (TTL 1) that routers never forward. OSPFv3 for IPv6 uses FF02::5 and FF02::6.
21.4.1 The Hello packet
0 8 16 31
Ospf
* must match between neighbours (Router ID must be different). The E bit carries the area's stub flag.
Figure 21-5 OSPFv2 header and Hello packet fields. Fields marked * must agree for an adjacency to form.
Hellos are sent every hello interval: 10 seconds by default on broadcast and point-to-point networks. If no Hello arrives from a neighbour within the dead interval (default 40 seconds, four times the hello), the neighbour is declared down. The neighbor list is how two-way communication is confirmed: when R1 sees its own RID listed in R2's Hello, R1 knows R2 can hear it.
21.5 Neighbor States and Adjacency Formation
OSPF draws a careful distinction between a neighbor (a router whose Hellos you receive and accept) and an adjacency (a neighbour with which you have fully synchronized your LSDB). Each neighbour relationship moves through a series of states:
Hello packets: Down / Init / 2-Way. DBD: ExStart / Exchange. LSR, LSU, LSAck: Loading.
Figure 21-6 The OSPF neighbor state machine. Point-to-point neighbours and any pair involving a DR or BDR continue to Full.
Table 21-3 OSPF neighbor states
State What is happening
Down No Hellos received from this neighbour in the last dead interval.
Init A Hello has arrived, but it does not yet list this router's RID. Communication is one-way so far.
2-Way Each router sees its own RID in the other's Hello. On broadcast links, DR/BDR election happens now. Two DROthers stop here permanently.
ExStart The pair decides who is master (higher RID) and agrees on the starting DBD sequence number.
Exchange DBD packets describe every LSA each router holds (headers only).
Loading Each router requests (LSR) the LSAs it lacks; they arrive in LSUs and are acknowledged. Full LSDBs are identical; the routers are fully adjacent.
Watch out
Neighbours stuck in ExStart/Exchange almost always have an MTU mismatch: Hellos are small and work, but large DBD packets are rejected. Neighbours stuck in Init suggest one-way communication (for example an ACL blocking OSPF in one direction). Two DROthers showing 2WAY/DROTHER is normal, not a fault.
21.5.1 Adjacency requirements
Two routers become neighbours only if the parameters in their Hellos agree. Memorise this list; the exam and real-world troubleshooting both depend on it.
Table 21-4 What must match (and what must differ) for OSPF neighbours Parameter Requirement If wrong
Area ID Same area on the shared link No neighbour; "mismatched area" log
Stub area flag Both agree whether the area is a stub No neighbour MTU Same IP MTU Stuck in ExStart/Exchange
Router ID Must be unique Duplicate RID errors; no
adjacency
Network type Should match (e.g. both point-to-point) May reach Full but routes are missing
Passive interface Must not be passive No Hellos sent, so no
neighbour
Note what does not need to match: the OSPF process ID (the number in router ospf 1 ) is locally significant only, and interface costs and priorities may differ.
Exam alert
A favourite question shows two routers' show ip ospf interface outputs and asks why they are not neighbours. Compare area, subnet/mask, hello/dead timers and router IDs first. Different process IDs are never the reason.
21.6 Designated Router and Backup Designated Router
On a multi-access segment such as an Ethernet LAN, full adjacency between every pair of routers would be wasteful: n routers would form n(n−1)/2 adjacencies (10 routers = 45 adjacencies) and every change would be flooded many times over. OSPF therefore elects a designated router (DR) to act as the hub for the segment and a backup designated router (BDR) to take over if the DR fails. All other routers are DROthers.
Every router forms a Full adjacency with the DR and the BDR.
DROthers remain in the 2-Way state with each other.
A DROther that detects a change sends its LSU to 224.0.0.6 (DR and BDR only). The DR then refloods it to 224.0.0.5 (all OSPF routers).
The DR originates the type 2 (network) LSA that describes the segment.
R1 • rid 1.1.1.1
DROther,
priority 1
R4 • rid 4.4.4.4
DR
R2 • rid 2.2.2.2
DROther,
priority 1
R3 • rid 3.3.3.3
10.10.10.0/24 bdr
Figure 21-7 DR/BDR on a broadcast segment. R4 has the highest RID and becomes DR; R3 becomes BDR. R1 and R2 are DROthers and stay in 2-Way with each other.
21.6.1 The election
The DR and BDR are elected per segment (per interface), during the 2-Way state, using values from the Hellos:
- 1. The highest interface priority wins (range 0–255, default 1, set with ip ospf priority ). A priority of 0 means the router can never become DR or BDR.
- 2. If priorities tie, the highest router ID wins.
The election is not preemptive. Once a DR is elected, a new router with a higher priority or RID that joins the segment does not take over. If the DR fails, the BDR is promoted to DR and a new BDR is elected. To force a particular router to become DR, set priorities and then restart OSPF on the segment (for example with clear ip ospf process ). Because the DR role belongs to an interface, a router can be DR on one LAN and DROther on another.
R1# show ip ospf neighbor
- Neighbor ID Pri State Dead Time Address Interface
- 2.2.2.2 1 2WAY/DROTHER 00:00:35 10.10.10.2 GigabitEthernet0/0
- 3.3.3.3 1 FULL/BDR 00:00:33 10.10.10.3 GigabitEthernet0/0
- 4.4.4.4 1 FULL/DR 00:00:38 10.10.10.4 GigabitEthernet0/0
R1# show ip ospf interface GigabitEthernet0/0
GigabitEthernet0/0 is up, line protocol is up
Internet Address 10.10.10.1/24, Area 0, Attached via Network Statement Process ID 1, Router ID 1.1.1.1, Network Type BROADCAST, Cost: 1 Transmit Delay is 1 sec, State DROTHER, Priority 1
Designated Router (ID) 4.4.4.4, Interface address 10.10.10.4
Backup Designated router (ID) 3.3.3.3, Interface address 10.10.10.3 Timer intervals configured, Hello 10, Dead 40, Wait 40, Retransmit 5 Hello due in 00:00:07
- Neighbor Count is 3, Adjacent neighbor count is 2
- Adjacent with neighbor 4.4.4.4 (Designated Router)
- Adjacent with neighbor 3.3.3.3 (Backup Designated Router)
Figure 21-8 R1's view: three neighbours, but only two adjacencies (with the DR and BDR).
Exam alert
In show ip ospf neighbor , the role after the slash is the neighbour's role, not the local router's. FULL/DR on R1 means "my neighbour 4.4.4.4 is the DR". To see your own role, use show ip ospf interface .
21.7 OSPF Network Types
The OSPF network type of an interface controls whether a DR is elected, how neighbours are found and the default timers. The two types on the CCNA blueprint are broadcast and point-to-point.
Table 21-5 Broadcast and point-to-point network types
Feature Broadcast Point-to-point
Default on Ethernet interfaces Serial (HDLC, PPP) interfaces, GRE tunnels
Full/dr , full/bdr ,
2way/drother
Full/ -
Type 2 LSA Created by the DR None
Many router-to-router links today are Ethernet with only two routers on them. Leaving them as broadcast works, but it wastes the time of a DR election (the wait timer delays adjacency by up to 40 seconds) and generates an unnecessary type 2 LSA. Configuring ip ospf network point-to-point on both ends removes the DR/BDR and speeds up convergence. Chapter 22 shows the configuration.
21.8 LSA Types 1, 2 and 3
OSPF defines many LSA types; the CCNA expects you to know the first three.
Table 21-6 Common OSPFv2 LSA types
Type Name Originated by Describes Flooded
1 Router
Lsa
- Every router The router's own links in the area: interfaces,
- costs, attached stub subnets and point-to-point neighbours
- Within its
- area
- 2 Network
Lsa
Lsa
Abr 172.16.1.0/24
Figure 21-9 Type 1 and 2 LSAs describe topology inside an area; the ABR summarises area 1's subnets into area 0 as type 3 LSAs.
R1# show ip ospf database
- OSPF Router with ID (1.1.1.1) (Process ID 1)
- Router Link States (Area 0)
- Link ID ADV Router Age Seq# Checksum Link count
- 1.1.1.1 1.1.1.1 412 0x80000004 0x00A1B2 1
- 2.2.2.2 2.2.2.2 398 0x80000003 0x003C4D 1
- 3.3.3.3 3.3.3.3 377 0x80000005 0x00D1E9 1
- 4.4.4.4 4.4.4.4 401 0x80000003 0x0056F0 2
- Net Link States (Area 0)
- Link ID ADV Router Age Seq# Checksum
- 10.10.10.4 4.4.4.4 401 0x80000002 0x00E5F6
- Summary Net Link States (Area 0)
- Link ID ADV Router Age Seq# Checksum
- 172.16.1.0 3.3.3.3 350 0x80000001 0x0078AB
Figure 21-10 The LSDB grouped by LSA type: four router LSAs (type 1), one network LSA from the DR (type 2) and one summary LSA from ABR 3.3.3.3 (type 3).
In the database the Link ID of a type 1 LSA is the originating router's RID; for a type 2 it is the DR's interface IP address; for a type 3 it is the summarised subnet. Routes built from type 1 and 2 LSAs appear with code O (intra-area); routes from type 3 LSAs appear as O IA (inter-area).
21.9 The OSPF Cost Metric
OSPF's metric is cost, a value from 1 to 65,535 assigned to each interface. A route's metric is the sum of the costs of the outgoing interfaces along the path. By default IOS derives the cost from the interface bandwidth:
cost = reference bandwidth ÷ interface bandwidth (rounded down, minimum 1) The default reference bandwidth is 100 Mbps, chosen in the days when Fast Ethernet was fast. With that default, every interface of 100 Mbps or faster gets cost 1, so OSPF cannot tell a 100 Mbps link from a 10 Gbps link. The fix is to raise the reference bandwidth with auto-cost reference-bandwidth (value in Mbps) on every router in the domain, so that costs stay consistent.
Table 21-7 OSPF interface cost by bandwidth
Interface Bandwidth Cost (ref 100 Mbps, default) Cost (ref 100,000 Mbps)
- Serial T1 1.544 Mbps 64 64,766
- Ethernet 10 Mbps 10 10,000
- Fast Ethernet 100 Mbps 1 1,000
- Gigabit Ethernet 1 Gbps 1 100
- 10 Gigabit Ethernet 10 Gbps 1 10
- 100 Gigabit Ethernet 100 Gbps 1 1
There are three ways to influence an interface's cost, in order of precedence:
- 1. ip ospf cost value on the interface sets the cost directly and overrides any calculation.
- 2. bandwidth kbps on the interface changes the bandwidth used in the formula (it does not change the real link speed).
- 3. auto-cost reference-bandwidth mbps under router ospf changes the numerator for all interfaces on that router.
Worked example. R1 reaches subnet 10.50.0.0/24 through two paths. Path A crosses a Gigabit link and then a Fast Ethernet link; path B crosses two Gigabit links and then a 10 Gbps link. With the default reference bandwidth, path A costs 1 + 1 = 2 plus the destination interface, and path B costs 1 + 1 + 1 = 3 plus the same, so OSPF prefers the slower path A because it has fewer hops. With a reference bandwidth of 100,000 Mbps, path A costs 100 + 1,000 = 1,100 and path B costs 100 + 100 + 10 = 210, and OSPF correctly prefers path B. This is exactly why modern designs raise the reference bandwidth.
Tip
When IOS accepts auto-cost reference-bandwidth it reminds you: "Please ensure reference bandwidth is consistent across all routers." Mismatched reference bandwidths do not break adjacencies, but they produce asymmetric, suboptimal paths that are hard to spot. Chapter review
Abr
Asbr
- 1. A router has no router-id command, loopbacks 10.1.1.1 and 10.9.9.9, and a GigabitEthernet interface 192.168.50.1. What is its OSPF router ID?
- A. 10.1.1.1
- B. 10.9.9.9
- C. 192.168.50.1
- D. 0.0.0.0
- 2. Which two parameters must match for two OSPF routers to become neighbours? (Choose two.)
- A. Process ID
- B. Hello and dead intervals
- C. Router ID
- D. Area ID
- E. Interface priority
- 3. Which OSPF neighbor state is normal between two DROthers on an Ethernet segment?
- A. Init
- B. 2-Way
- C. ExStart
- D. Full
- 4. Four routers on a LAN have default priorities and RIDs 1.1.1.1, 2.2.2.2, 3.3.3.3 and 4.4.4.4. Which router becomes the BDR?
- A. 1.1.1.1
- B. 2.2.2.2
- C. 3.3.3.3
- D. 4.4.4.4
- 5. To which address does a DROther send an LSU to notify the DR and BDR of a change?
- A. 224.0.0.5
- B. 224.0.0.6
- C. 224.0.0.9
- D. 255.255.255.255
- 6. Two OSPF neighbours are stuck in the ExStart state. What is the most likely cause?
- A. Area mismatch
- B. Hello timer mismatch
- C. MTU mismatch
- D. Different process IDs
- 7. Which OSPF packet type carries complete LSAs?
- A. Hello
- B. DBD
- C. LSR
- D. LSU
- 8. With the default reference bandwidth, what is the OSPF cost of a 10 Mbps Ethernet interface?
- A. 1
- B. 10
- C. 100
- D. 1000
- 9. Which LSA type is generated by the DR to describe a multi-access segment?
- A. Type 1
- B. Type 2
- C. Type 3
- D. Type 5
- 10. Which two statements about OSPF point-to-point networks are true? (Choose two.)
- A. No DR or BDR is elected
- B. Neighbours must be configured manually
- C. The default hello interval is 10 seconds
- D. A type 2 LSA is generated for the link
- E. They are the default on Ethernet interfaces
- 11. A new router with priority 255 joins a LAN where a DR has already been elected. What happens?
- A. It immediately becomes the DR
- B. It becomes the BDR immediately
- C. The existing DR keeps its role, because the election is not preemptive
- D. All routers re-run the election
- 12. What does an ABR do?
- A. Connects OSPF to an external routing domain
- B. Connects area 0 to another area and advertises type 3 summaries between them
- C. Acts as DR for every segment in area 0
- D. Floods type 1 LSAs into every area
- 13. In the shortest-path tree of Figure 21-2, what is R1's total cost to R5?
- A. 13
- B. 14
- C. 15
- D. 25
- 14. An OSPF interface has priority 0. What does this mean?
- A. The interface will not send Hellos
- B. The router will always be DR
- C. The router can never become DR or BDR on that segment
- D. The interface is passive
- 15. Which two actions change the OSPF cost of a GigabitEthernet interface? (Choose two.)
- A. ip ospf cost 50
- B. ip ospf priority 50
- C. auto-cost reference-bandwidth 10000
- D. ip ospf hello-interval 5
- E. router-id 5.5.5.5
Answers
- 1. B. With no manual RID, the highest up loopback address wins, even if a physical interface is higher.
- 2. B and D. Timers and area must match. Process ID is local; router IDs must differ; priority may differ.
- 3. B. DROthers form only 2-Way with each other and Full with the DR and BDR.
- 4. C. With equal priorities the highest RID (4.4.4.4) is DR and the next highest (3.3.3.3) is
Bdr.
- 5. B. 224.0.0.6 is AllDRouters. The DR then refloods to 224.0.0.5.
- 6. C. An MTU mismatch lets Hellos through but breaks DBD exchange. Area and timer mismatches prevent the neighbour forming at all.
- 7. D. Link-State Updates carry full LSAs; DBDs carry only headers; LSRs request LSAs.
- 8. B. 100 Mbps ÷ 10 Mbps = 10.
- 9. B. The DR originates the network (type 2) LSA.
- 10. A and C. Point-to-point networks elect no DR, discover neighbours automatically and use 10/40 timers. No type 2 LSA; Ethernet defaults to broadcast.
- 11. C. DR election is not preemptive; the newcomer waits until the DR and BDR fail or OSPF is restarted.
- 12. B. ABRs link areas to the backbone and generate type 3 LSAs. Connecting to external domains is the ASBR's role.
- 13. A. R1–R3 (5) + R3–R2 (3) + R2–R4 (1) + R4–R5 (4) = 13, cheaper than R1–R3–R5 (14).
- 14. C. Priority 0 removes the router from DR/BDR election on that interface; it still forms neighbours.
- 15. A and C. A manual cost overrides the calculation; raising the reference bandwidth to 10,000 Mbps gives a 1 Gbps interface cost 10. Priority, hello interval and RID do not affect cost.