Intermediate · Routing: static routes and OSPF · topic 33 of 57 · 35 min
OSPF concepts: link state, areas and neighbours
Explanation
Why dynamic routing?
Static routes are fine for five networks. With 50 routers and hundreds of subnets, typing routes by hand is slow, error-prone, and nothing reroutes traffic when a link fails. A dynamic routing protocol lets routers tell each other about networks, and recalculate paths by themselves when something changes. The time it takes all routers to agree on the new paths is called convergence.
Distance vector versus link state
A distance vector protocol, such as RIP, works by rumour: each router tells its neighbours "I can reach these networks at this distance". A router knows only what its neighbours told it, not the real map. RIP uses hop count as its metric, with 15 as the maximum, so it suits only small networks.
A link-state protocol, such as OSPF, works with a map: every router describes its own links (its interfaces, their networks and costs) and floods that description to all routers in the area. Each router collects all the descriptions into the same database and calculates the best paths itself.
LSAs, the LSDB and SPF
- LSA (link-state advertisement): a small message that describes part of the network. A Type 1 (router) LSA is made by every router and lists its links. A Type 2 (network) LSA is made by the DR of an Ethernet segment and lists the routers on that segment.
- LSDB (link-state database): the collection of all LSAs. Every router in the same area has an identical LSDB.
- SPF: the shortest path first algorithm, invented by Edsger Dijkstra. Each router puts itself at the root of a tree and finds the lowest-cost path to every network. The results go into the routing table as O routes.
Areas and the backbone
An area is a group of routers that share the same LSDB. Big networks are split into areas so that each router keeps a smaller map and a link flapping in one area does not make every router recalculate. Area 0 is the backbone: every other area must connect to it. A router with interfaces in area 0 and another area is an ABR (area border router). For the CCNA you mainly configure single-area OSPF, with everything in area 0.
Router ID
Every OSPF router needs a router ID (RID): a 32-bit number written like an IPv4 address, unique in the OSPF domain. It is chosen in this order:
- The router-id command, if configured (best practice).
- Otherwise, the highest IP address on an up loopback interface.
- Otherwise, the highest IP address on an active (up/up) physical interface.
The RID is chosen when the OSPF process starts. If you change it later, it takes effect only after clear ip ospf process or a reload.
Cost: the OSPF metric
Cost = reference bandwidth / interface bandwidth, rounded down, with a minimum of 1. The default reference bandwidth is 100 Mbps. The cost of a path is the sum of the costs of the outgoing interfaces along the way.
| Interface | Bandwidth | Cost (reference 100 Mbps) | Cost (reference 100,000 Mbps) |
|---|---|---|---|
| Ethernet | 10 Mbps | 10 | 10000 |
| FastEthernet | 100 Mbps | 1 | 1000 |
| GigabitEthernet | 1 Gbps | 1 | 100 |
| 10 Gigabit Ethernet | 10 Gbps | 1 | 10 |
With the default, every link of 100 Mbps or more costs 1, so OSPF cannot tell a 100 Mbps link from a 10 Gbps one. Fix it with auto-cost reference-bandwidth 100000 under router ospf (the value is in Mbps). Set the same value on every router, or paths will be calculated inconsistently.
Hellos and neighbour states
OSPF routers find each other by sending hello packets to multicast 224.0.0.5 (OSPF runs directly over IP as protocol 89). On broadcast (Ethernet) and point-to-point links, hellos go every 10 seconds and the dead interval is 40 seconds: if no hello arrives for 40 seconds, the neighbour is declared down. Two routers become neighbours only if key settings match, such as area, subnet and timers.
| State | What is happening |
|---|---|
| Down | No hello received yet. |
| Init | A hello arrived, but it does not list my RID yet. |
| 2-Way | Each router sees its own RID in the other's hello. DR/BDR election happens here. |
| ExStart | The two agree who leads the database exchange. |
| Exchange | They send summaries of their LSDBs (DBD packets). |
| Loading | They ask for and receive the LSAs they are missing. |
| Full | Databases are in sync. This is the goal. |
DR and BDR on Ethernet
On a shared Ethernet segment with many routers, if every router became fully adjacent with every other, the flooding would multiply. Instead, the routers elect a DR (designated router) and a BDR (backup DR). Every router becomes Full only with the DR and BDR; the others (DROTHERs) stay in 2-Way with each other, and that is normal. The highest OSPF interface priority wins (default 1, range 0 to 255); a tie goes to the highest RID. Priority 0 means the router never becomes DR or BDR. The election does not preempt: a new router with a higher priority does not take over from a working DR.
Need help?
Stuck on a word or an idea? Search this course, or every course, and jump straight to the explanation or a worked question.
Try:
Watch the lesson
OSPF concepts: link state, areas and neighbours · 1/9
In this lesson you will understand how OSPF learns the network by itself.
Prefer a video by a teacher? Find free videos on “ospf explained ccna link state lsa dr bdr neighbor states” on YouTube ↗
In real life: A university campus network
A university in Hyderabad has a core of four routers and one router per building: hostels, library, labs and the administration block. With OSPF, when a fibre between the library and the core is cut during road work, the routers flood the change, rerun SPF and move traffic to the other path within seconds. Nobody has to log in and change static routes. The network team set the reference bandwidth to 100000 on every router so that the 10 Gbps core links are preferred over 1 Gbps building links.
Practice (0/3 done)
Write ospf_cost(ref_mbps, bw_mbps) that returns the OSPF cost of an interface: reference bandwidth divided by interface bandwidth, rounded DOWN to a whole number, but never less than 1.
Write spf(graph, source), a small version of what OSPF runs. graph maps each router to a dict of {neighbour: cost of the outgoing link}. Return a dict with the lowest total cost from source to every router it can reach (source itself is 0). Use Dijkstra's algorithm with heapq.
show ip ospf neighbor on R3 shows R4 as "2WAY/DROTHER" on an Ethernet segment where R1 is DR and R2 is BDR. What does this mean?
Quick quiz
Read more (free)
Related help
Before this, learn
This topic builds on these. If something here feels new, open them first.
Related topics
- Configuring and verifying single-area OSPFRouting: static routes and OSPF · same module
- Pages and client-side routingFull-Stack Development · Building the frontend
- Shortest paths: Dijkstra and friendsData Structures and Algorithms (DSA) for interviews · Graphs
- Troubleshooting tools and common faultsTroubleshooting and the CCNA exam
- Routing: sending each request to the right codeBackend Development · APIs and request handling
- Routing with go_routerFlutter and Dart · Lists, navigation and forms
Questions people ask about this
Open a question to see the answer and why. The first ones are this topic's own quiz, so try the quiz above before you peek.
What is the default OSPF reference bandwidth on Cisco routers?
Answer: 100 Mbps
The default is 100 Mbps, which is why every link of 100 Mbps or faster costs 1.
No router-id is configured. The router has Loopback0 1.1.1.1 and G0/0 192.168.1.1 (both up). What is the router ID?
Answer: 1.1.1.1
An up loopback is preferred over physical interfaces, even with a lower address.
Which neighbour state is the goal of an OSPF adjacency?
Answer: Full
Full means the two databases are synchronised.
What are the default hello and dead intervals on an OSPF Ethernet link?
Answer: 10 and 40 seconds
On broadcast and point-to-point links, hellos are every 10 seconds and the dead interval is 40.
An interface has OSPF priority 0. What does that mean?
Answer: It can never become DR or BDR
Priority 0 removes the router from the DR/BDR election. The default is 1.
Which LSA type does every OSPF router create to describe its own links?
Answer: Type 1 (router)
Every router floods a Type 1 router LSA in its area. Type 2 is made only by a DR.
Which command quickly lists each OSPF interface with its area, cost, state and neighbour count?Related
Answer: show ip ospf interface brief
show ip ospf interface brief gives one line per OSPF interface with cost, state and full/total neighbours.
What is the default administrative distance of OSPF?Related
The main path is learnt by OSPF. Which AD makes a static route a correct floating backup?Related
Answer: 130
The backup must have a higher AD than OSPF's 110, so 130 works. The others would beat OSPF.
What is the short STP cost of a 100 Mbps link?Related
Answer: 19
With short costs, 100 Mbps is 19, 1 Gbps is 4 and 10 Gbps is 2.
Pass the quiz (60% or more) or mark this topic as done when you are ready.
Your progress is saved on this device only.
Next steps
- 2 more topics in “Routing: static routes and OSPF” before its exam: Configuring and verifying single-area OSPF, First hop redundancy: HSRP, VRRP and GLBP.
- Module 7 exam: static routes, OSPF and HSRP · 14 questions · 25 min, without help. 5 topics of this module still to finish first.
- Then the next module, IP services: DHCP, DNS, NAT and more. 57 topics left in the course before the final exam.