Watch on Instagram

Network Bytes · Episode 46 · CCNA 3.4

OSPF in 60 seconds

OSPF lets routers learn the whole network on their own. They say hello to their neighbors, share their links, pass that news along until every router in the area has the same map, then each one picks the path with the lowest total cost.

Posted · About a 1 minute watch, 3 minute read · Take the quiz

Too many routes to type

A static route is a route someone types in by hand. That's fine for a few routers. With a hundred routers, typing every route on every router (and fixing them all whenever a link goes down) is hopeless. So routers use a dynamic routing protocol to work routes out themselves. OSPF is an open standard (OSPFv2 is defined in RFC 2328), so routers from different vendors can speak it together.

First, each router sends hello packets out of its OSPF interfaces to find its neighbors (every 10 seconds by default on Ethernet). Once two routers are neighbors, each one describes its own links in a link-state advertisement (LSA): which networks it's connected to, and the cost of each link. That's why OSPF is called a link-state protocol: routers share facts about links, not finished routes.

Everyone gets the same map

Neighbors pass each LSA along unchanged, router to router, until every router in the area has a copy. This is called flooding, and it's reliable: each LSA is acknowledged. The result is that every router in the area holds an identical link-state database (LSDB), the same full map of the network.

Lowest total cost wins

With the map in hand, each router runs the shortest path first (SPF) algorithm, also known as Dijkstra's algorithm, with itself at the root. Every link has a cost, and faster links cost less. On Cisco routers the default cost is the reference bandwidth (100 Mbps) divided by the interface bandwidth: a 10 Mbps link costs 10, and a 100 Mbps link costs 1. The router adds up the costs along each path to a network, and the path with the lowest total goes into its routing table. Fewer hops doesn't matter by itself; only the total cost does.

Try it yourself

In Cisco Packet Tracer (free with a Cisco Networking Academy account), connect three routers in a triangle and turn on OSPF on each with router ospf 1 and network <network> <wildcard> area 0. Run show ip ospf neighbor to see the hellos at work, then show ip route ospf: each learned route shows [110/<cost>], the administrative distance and the total cost. Now raise the cost on one link with ip ospf cost 100 on its interface and run show ip route ospf again to watch the router switch to the other way around the triangle.

Good to know

  • OSPF (OSPFv2, RFC 2328) is an open-standard link-state protocol.
  • Routers form neighbor relationships with hellos, sent every 10 seconds by default on Ethernet.
  • LSAs are flooded unchanged within an area, so every router builds an identical link-state database; then each runs the SPF (Dijkstra) algorithm for itself.
  • Cisco's default interface cost is reference bandwidth (100 Mbps) divided by interface bandwidth, so every link of 100 Mbps or faster costs 1 unless the reference bandwidth is raised (auto-cost reference-bandwidth). The costs in the video's question are illustrative.
  • "Gossip" is an analogy: LSAs are reliably flooded and acknowledged, not passed on casually.
  • Multi-area design and the different LSA types are beyond this short.
  • OSPF's administrative distance is 110 (see EP44).

For CCNA learners

This lines up with CCNA 200-301 exam topic 3.4, configure and verify single area OSPFv2: know that OSPF is link-state, that routers in an area share an identical database, and that the route with the lowest total cost is chosen.

Answer to the comment question

Path A. OSPF adds up the cost of every link on a path: Path A is 10 + 10 + 10 = 30, and Path B is a single link costing 50. 30 is lower than 50, so OSPF picks Path A, even though it has more hops.

Test your knowledge

Quick quiz: OSPF in 60 seconds

4 multiple-choice questions. Pick one answer for each, then check how you did.

1What do OSPF routers share with their neighbors?
2After flooding finishes, what is true of every router in an OSPF area?
3With Cisco's default reference bandwidth of 100 Mbps, what is the OSPF cost of a 10 Mbps link?
4A router has two paths to a network: one with a total cost of 4, one with a total cost of 12. Which goes into the routing table?

Sources

Video transcript

How do routers learn the whole network without anyone typing it in?

Static routes work for a few routers. With a hundred, typing every route by hand is hopeless. So routers gossip instead, using OSPF: Open Shortest Path First.

First, each router says hello to its neighbors. Then it tells them about its own links: which networks it has, and how fast each link is.

Neighbors pass that news along, unchanged, until every router in the area holds the same full map of the network.

Then each router works out its own shortest path to every network, adding up a cost for each link. Faster links cost less. The lowest total wins.

Path A has three links costing 10 each. Path B is one link costing 50. Which path does OSPF pick? Comment your answer below!

That's your byte.

More from Network Bytes

All Network Bytes lessons