Skip to content

Intermediate · Routing: static routes and OSPF · topic 33 of 57 · 35 min

OSPF concepts: link state, areas and neighbours

Explanation

OSPF (Open Shortest Path First) is a link-state routing protocol: every router learns a full map of the area and runs the SPF (Dijkstra) algorithm to find the cheapest path to every network. The cost of a link is reference bandwidth divided by interface bandwidth. Routers become neighbours by exchanging hellos and move through states up to Full. On Ethernet, a DR and BDR reduce the flooding.

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.

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.

Think of it like this: Distance vector is like asking for directions at every corner: "go straight, the station is 3 km". You trust the person and never see the map. Link state is like everyone sharing their part of the map until each driver holds the full Google Maps view and plans the route alone.

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:

  1. The router-id command, if configured (best practice).
  2. Otherwise, the highest IP address on an up loopback interface.
  3. 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.

InterfaceBandwidthCost (reference 100 Mbps)Cost (reference 100,000 Mbps)
Ethernet10 Mbps1010000
FastEthernet100 Mbps11000
GigabitEthernet1 Gbps1100
10 Gigabit Ethernet10 Gbps110

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.

StateWhat is happening
DownNo hello received yet.
InitA hello arrived, but it does not list my RID yet.
2-WayEach router sees its own RID in the other's hello. DR/BDR election happens here.
ExStartThe two agree who leads the database exchange.
ExchangeThey send summaries of their LSDBs (DBD packets).
LoadingThey ask for and receive the LSAs they are missing.
FullDatabases 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.

Careful: Common mistakes: (1) leaving the reference bandwidth at 100 so all fast links cost 1; (2) changing the router ID and expecting it to apply at once; (3) thinking 2-Way between two DROTHERs is a fault; (4) expecting the router with the highest priority to become DR immediately, when the election is not preemptive.

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

OSPF concepts

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)

Task 1 · Code · Python

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.

Task 2 · Code · Python

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.

Task 3 · Question

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

Question 1

1.What is the default OSPF reference bandwidth on Cisco routers?

Question 2

2.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?

Question 3

3.Which neighbour state is the goal of an OSPF adjacency?

Question 4

4.What are the default hello and dead intervals on an OSPF Ethernet link?

Question 5

5.An interface has OSPF priority 0. What does that mean?

Question 6

6.Which LSA type does every OSPF router create to describe its own links?

Read more (free)

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.

From Configuring and verifying single-area OSPF

What is the default administrative distance of OSPF?Related

Answer: 110

OSPF is 110. EIGRP is 90, RIP is 120.

From How a router forwards: the routing table

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.

From Static and default routes

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.

From Root bridge election, root ports and designated ports

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

  1. 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.
  2. Module 7 exam: static routes, OSPF and HSRP · 14 questions · 25 min, without help. 5 topics of this module still to finish first.
  3. Then the next module, IP services: DHCP, DNS, NAT and more. 57 topics left in the course before the final exam.

← Previous: Static and default routes