A road closes and nobody phones round
A courier firm has a depot in every town. When a road closes, the manager does not phone every depot.
Each depot tells its neighbours what changed on its own roads. Within a minute, every depot has the same map.
OSPF lets routers do exactly that.
By the end of this lesson
Note
I can say how OSPF routers learn the network.
Key words
| Word | What it means | Example |
|---|---|---|
| Neighbour | a router on the same link that also runs OSPF | |
| Hello packet | a short message sent to find and keep neighbours | |
| Link-state database | the map of every router and link that a router holds | |
| Cost | a number for how much a link is worth avoiding; lower is better | |
| Area | a group of routers that share one map | area 0 |
| Shortest path | the route with the lowest total cost |
The cells students fill in are left blank in this preview.
Static routes do not scale
A static route is typed once and never changes. If a link fails, the route stays, and packets are lost.
In a network of fifty routers nobody wants to type the lines. A routing protocol lets the routers share what they know.
OSPF is one such protocol. With it, every router builds a full map of the network.
Routers meet with hello packets
A router sends hello packets out of each interface that runs OSPF. A router that hears one on the same link replies.
Two routers that hear each other become neighbours. They swap their maps. When both hold the same map the state reads Full.
OSPF runs directly on IP, as protocol number 89.
Worked example: neighbour states
| State | What it means |
|---|---|
| Down | No hello has been heard |
| Init | A hello was heard, but it does not list us yet |
| 2-Way | Both sides hear each other |
| ExStart | The two agree which of them leads the swap |
| Exchange | The two swap summaries of their maps |
| Loading | The two fetch the parts they lack |
| Full | The maps match: the neighbour is ready to use |
The cells students fill in are left blank in this preview.
See which programs each router runs
netlab statusShown here, not run. Create a free account to press Run and type it into your own lab’s terminal.
Ask r2 for its OSPF neighbours
sudo vtysh -N r2 -c "show ip ospf neighbor"Shown here, not run. Create a free account to press Run and type it into your own lab’s terminal.
Read r2's table without OSPF
sudo vtysh -N r2 -c "show ip route"Shown here, not run. Create a free account to press Run and type it into your own lab’s terminal.
What the three answers say
netlab status ends each router's entry with a daemons: line. A daemon is a program that runs in the background, and ospfd is the OSPF one.
Asking for neighbours prints % OSPF is not enabled in vrf default. The program is running, but nobody has told it which interfaces to use.
The table lists only connected lines, C, and the router's own addresses, L. No line starts with O, the code for a route learned from OSPF.
Every router builds the same map
Each router describes its own links in a message called a link-state advertisement. It sends the message to its neighbours, and they pass it on.
Soon every router holds the same link-state database: a map of every router and every link in the area.
Each router then works out its own routes from that map.
Cost decides which path is best
Every link has a cost. By default it comes from the link speed: a faster link costs less. A person can also set it by hand.
The router divides a reference speed, 100 Mbit/s unless changed, by the link speed. The cost is never below 1.
The cost of a path is the sum of the costs of its links. OSPF chooses the shortest path, which means the lowest total cost, not the fewest routers.
Read an interface the router can use
sudo vtysh -N r2 -c "show interface to-r1"Shown here, not run. Create a free account to press Run and type it into your own lab’s terminal.
A common mistake
Warning
Many people think OSPF picks the path with the fewest routers. It adds up the cost of every link. A path of three cheap links can beat a path of one dear link.
Each router runs the shortest path calculation
A router starts from itself with cost 0. It then looks at the closest router it has not settled yet and adds the cost of each link from it.
It repeats until every router is settled. The result is the cheapest cost to every router, and the first hop to use.
Worked example: r1 settles each router
| Step | Settled | Cost from r1 | Reason |
|---|---|---|---|
| 1 | r1 | 0 | The start |
| 2 | r4 | 5 | The link r1 to r4 costs 5 |
| 3 | r2 | 10 | The link r1 to r2 costs 10 |
| 4 | r3 | 20 | Through r2: 10 plus 10 beats 5 plus 30 |
| 5 | r5 | 21 | Through r3: 20 plus 1 |
The cells students fill in are left blank in this preview.
Going further: a cheaper link changes everything
In the worked table, change the cost of the link from r4 to r3 from 30 to 12. Settle every router again from r1, on paper.
Which first hop does r1 now use to reach r3 and r5, and what does each cost? Check your answer by changing that line in LINKS and calling your shortest_path.