10. Link-State Routing & OSPF

How routers flood a description of their own links until every one of them holds the same map, then each works out its own shortest paths with Dijkstra

In the last article, the villages of a county kept their fingerposts up to date by copying from each other: "the next village says Ashby is 9 miles, the road there is 3, so put up Ashby 12." It worked until a bridge washed away and the villages spent the afternoon repainting each other's stale numbers.

Here's a different arrangement. Every village sends a surveyor out along its own roads, and the surveyor writes one short, signed note: "From Barton: a road to Ashby, 3 miles; a road to Colby, 5 miles. Note number 17." A copy of every village's note goes to every other village, pinned up on the board in the village hall. Nobody passes on conclusions any more, only facts about their own roads, straight from the source. Each village can lay all the notes out and draw the whole county map, then work out its own fingerposts from it. When the bridge washes away, the two villages at either end send out new notes, number 18, and within the hour every hall has the new map and every village has redrawn its signs. There is nothing stale to count up from.

That's link-state routing. Every router describes its own links in a small message, a link-state advertisement, and those messages are flooded to every router in the network. Every router ends up with the same link-state database, which is a map of the whole network, and runs Dijkstra's shortest-path algorithm on it to fill in its routing table. In this article we'll follow the ISP's four routers as they switch from RIP to OSPF, the most widely used link-state protocol, and cut the same fibre as last time.

Why Link-State: Facts, Not Conclusions

The trouble with distance-vector routing, as we saw in Good News Travels Fast, Bad News Travels Slowly, is that each router only hears its neighbours' conclusions: "I can reach the street at cost 2." When the street disappears, a router can't tell whether that "2" is still true or an echo of its own old route. So the routers count upwards together, in RIP's case to 16, while packets loop between them.

Link-state routing removes the guesswork by changing what is sent:

Distance vector: pass on conclusions

"Here is how far I am from everything." Each router's table is built from its neighbours' tables, which were built from their neighbours' tables. Nobody knows the paths, only the distances, and a stale distance can circulate for minutes.

Link state: pass on facts

"Here are my own links and what each one costs." Every router gets every other router's description, unchanged, straight from its author. Each one then assembles the same map and computes the paths itself. A description can only be replaced by a newer one from the same author.

The price is memory and computation: every router stores the whole map and runs a shortest-path algorithm on it. In 1969 that was a lot to ask of a packet switch. By the end of the 1970s it wasn't.

Where it comes from

  • ARPANET, 1979. The ARPANET's first routing algorithm was distance-vector, and it suffered from exactly the loops and slow reactions of the last article. In May 1979 BBN replaced it with a "new routing algorithm" by John McQuillan, Ira Richer and Eric Rosen, published in IEEE Transactions on Communications in May 1980. Each packet switch measured the delay on each of its lines, averaged over 10 seconds, and when it changed significantly, flooded an update to every other switch. Every switch kept the whole map and computed its routes with Dijkstra's algorithm: the first link-state routing protocol.
  • IS-IS. At Digital Equipment Corporation, Radia Perlman (also the inventor of spanning tree) designed the link-state routing for DECnet Phase V. It was adopted by ISO as IS-IS, "Intermediate System to Intermediate System" (ISO for "router to router"), published by the IETF as RFC 1142 in 1990 and standardised as ISO 10589 in 1992. RFC 1195 (December 1990) extended it to carry IP routes too: Integrated IS-IS.
  • OSPF. The IETF designed its own link-state protocol for IP, Open Shortest Path First: "open" because it was a public, non-proprietary standard. John Moy edited the specifications. OSPF version 1 was RFC 1131 in October 1989; version 2, RFC 1247 in July 1991, replaced it; and the current OSPFv2 standard is RFC 2328, from April 1998. OSPFv3, for IPv6, was RFC 2740 in 1999 and is now RFC 5340 (July 2008).

The ISP Moves to OSPF

The ISP from the last article outgrew RIP, and when it did, it switched to OSPF. Same four routers, same five links, same addresses as in The ISP's Network. Two things change.

The costs. OSPF costs are 16-bit numbers on each router interface, and there's a convention for choosing them: divide a reference bandwidth by the interface's bandwidth. The ISP's fibre links run at 10 Gb/s, and it sets the reference to 100 Gb/s (more on why later), so each fibre costs 100 / 10 = 10. The microwave link between R2 and R5 runs at 2 Gb/s, so it costs 100 / 2 = 50. The R3–R5 link is leased fibre, 10 Gb/s, but the ISP pays for every bit that crosses it, so an engineer sets its cost to 30 by hand. Every cost is exactly ten times the RIP cost, which will make the two articles easy to compare. The customer-facing links, to the street, the business park and the next town, are 10 Gb/s too, so each costs 10.

The names. Every OSPF router has a router ID, a 32-bit number written like an IPv4 address that names the router in every message it sends. It doesn't have to be an address the router owns. Many networks use a loopback address; our ISP simply numbers its routers: 0.0.0.2 for R2, 0.0.0.3 for R3, 0.0.0.5 for R5 and 0.0.0.6 for R6.

10 10 10 Our street · 198.51.100.0/24 R4, transit, DC-2 (not OSPF) Business park · 192.0.2.96/27 Next town · 192.0.2.128/25 R2 ID 0.0.0.2 R3 ID 0.0.0.3 R5 ID 0.0.0.5 R6 ID 0.0.0.6 10 50 10 10 30
Link Subnet (first router, second router) Cost
R2–R3 192.0.2.0/30 (.1 / .2) 10
R2–R5 192.0.2.16/30 (.17 / .18) 50
R3–R5 192.0.2.20/30 (.21 / .22) 30
R3–R6 192.0.2.24/30 (.25 / .26) 10
R5–R6 192.0.2.28/30 (.29 / .30) 10

R3's route in Routing Basics, 198.51.100.0/24 via 192.0.2.1, OSPF (110), metric 20, comes from this OSPF network. By the end of this article we'll have worked out where that 20 comes from. (R5 and R6 have since been retired, which is why R3's present-day table has no routes through them; the R2–R3 link and the street still cost 10 each, so the metric didn't change.)

The Recipe in Three Steps

Every link-state protocol, from the 1979 ARPANET to OSPF and IS-IS today, does the same three things:

  1. Meet the neighbours

    Each router sends small Hello packets on every link, and listens for them. When two routers hear each other, and each can see that the other has heard it, they become neighbours, and they make sure they hold the same database.

  2. Describe your links, and flood the description

    Each router writes a link-state advertisement (LSA) listing its working links, the neighbour or network at the end of each, and its cost. It sends the LSA to every neighbour, who pass it on to theirs, until every router has a copy. Sequence numbers and acknowledgements make the flooding reliable, and make sure a newer LSA always replaces an older one.

  3. Compute shortest paths

    Every router now holds the same set of LSAs: the link-state database (LSDB). Each runs Dijkstra's algorithm on it, with itself as the source, to build a shortest-path tree, and reads its routing table off the tree.

Whenever something changes, a link failing or a cost being edited, only step 2 and step 3 happen again: the routers at the ends of the changed link issue new LSAs, those LSAs are flooded, and everyone recomputes. Let's take the steps one at a time.

Step 1: Hellos and Neighbours

An OSPF router sends a Hello out of every interface where OSPF is enabled, every HelloInterval: 10 seconds by default on Ethernet and point-to-point links. The Hello is sent to the multicast address 224.0.0.5, AllSPFRouters, so only OSPF routers listen to it, with an IP TTL of 1, so it never leaves the link. Among other things it carries:

  • the sender's router ID and the area the link belongs to (areas come later),
  • the link's HelloInterval and RouterDeadInterval (40 seconds by default: four missed Hellos), which both ends must agree on,
  • and the list of router IDs the sender has heard Hellos from on this link recently.

That last list is the clever part. It's how a router knows the link works in both directions. If R2 hears R3's Hello and R3's Hello lists 0.0.0.2, then R3 has heard R2 too, and the two are in 2-Way state. A link that only works one way, a fibre with one dead strand say, never gets past "I can hear you, but you don't mention me", so it never gets used.

If a router hears nothing from a neighbour for the RouterDeadInterval, it declares the neighbour down. On a fibre link, though, a router usually doesn't wait 40 seconds: when the light goes out, the interface goes down at once, and the neighbour goes with it. For failures the interface can't see, many networks run BFD alongside OSPF to detect a dead neighbour in well under a second.

Hellos are also where configuration mistakes show up. Two routers whose Hellos disagree on the area or the intervals (or, on a shared segment, the subnet mask) simply ignore each other, and "why won't these two become neighbours?" is the most common OSPF question there is.

From neighbour to adjacency

Before two neighbours can trust each other's flooding, they must hold the same LSDB. A router that has just booted knows nothing, so the two routers compare databases and copy across whatever is missing. When they've finished, they are fully adjacent, and only then does each one add the link between them to its own LSA. OSPF tracks this with a neighbour state machine:

State What it means
Down Nothing heard from this neighbour recently
Init Heard its Hello, but it doesn't list me yet
2-Way Its Hello lists me: the link works both ways
ExStart Deciding who leads the database exchange: the higher router ID is master
Exchange Swapping Database Description packets: a list of every LSA's header, with no contents
Loading Requesting the LSAs I'm missing or have older copies of, and receiving them
Full Our databases match. The adjacency is up, and goes into both routers' LSAs

(There's one more, Attempt, used only on old NBMA networks.) Here is R2 meeting R3 for the first time, both freshly booted, each holding nothing but its own first LSA:

R2 · 0.0.0.2 R3 · 0.0.0.3 R2's state R3's state Hello · I've heard: nobody Init Hello · I've heard: 0.0.0.2 2-Way → ExStart Hello · I've heard: 0.0.0.3 2-Way → ExStart DD · I'll be master DD · No: 0.0.0.3 is higher, I'm master Exchange (slave) DD · I have: R2's LSA #1 Exchange (master) DD · I have: R3's LSA #1 DD · nothing more Loading Loading LS Request · send me R3's LSA LS Request · send me R2's LSA LS Update · R2's LSA #1 Full LS Update · R3's LSA #1 Full Simplified: acknowledgements and DD sequence numbers are left out. Hellos carry on every 10 s in the background, for as long as the link is up.

The Database Description step is what makes this cheap. Instead of sending each other their entire databases, which in a big network is thousands of LSAs, the two routers send only the 20-byte header of each LSA, and request just the ones they need. Two routers that already hold almost the same LSDB, because they were both up a minute ago, exchange almost nothing.

As soon as R2 and R3 reach Full, both of their LSAs are out of date, because neither mentions the other. So each issues a new one, LSA #2, with the new link in it, and floods it.

Step 2: Describing Your Links

An OSPF router describes itself in a router-LSA. Once all its adjacencies are up, R2's says:

R2's router-LSA

LS type 1 (router-LSA)       Link State ID 0.0.0.2      Advertising router 0.0.0.2
LS sequence number 0x80000003                           LS age 0 when issued
  Link                  To                         Link data          Cost
  point-to-point        router 0.0.0.3 (R3)        192.0.2.1          10
  stub network          192.0.2.0/30                                  10
  point-to-point        router 0.0.0.5 (R5)        192.0.2.17         50
  stub network          192.0.2.16/30                                 50
  stub network          198.51.100.0/24 (street)                      10

Two kinds of entry. A point-to-point link names the router at the other end, by router ID; these are the edges of the map. A stub network is a prefix that leads to no other OSPF router; these are the destinations hanging off the map. Each point-to-point link also has a stub for its own /30, and the street is a stub because R2 runs no OSPF towards its customers.

The cost on each line is the cost of leaving R2 on that interface. OSPF costs are directional: R3's LSA carries its own cost for the R3–R2 direction, which could differ (ours don't). The street's cost of 10 is the cost of R2 sending into the street, which is what anyone routing to the street will add on at the end.

Every LSA starts with the same 20-byte header, and three of its fields make flooding work:

  • Advertising router, LS type and Link State ID together name the LSA. There is exactly one router-LSA from 0.0.0.2 at any time; a new version replaces the old one.
  • LS sequence number. Each new version gets the next number. The first is 0x80000001, and the numbers go up to 0x7fffffff. They're compared as signed 32-bit integers, so 0x80000001 is the most negative, and the space is a straight line with no wrap-around. A higher number always means a newer LSA. (We'll see below why a straight line rather than a circle.)
  • LS age. Seconds since the LSA was issued. It goes up while the LSA sits in a database and by at least a second on each hop. The author re-issues every LSA every 30 minutes even if nothing has changed, with a new sequence number, and an LSA that reaches one hour (MaxAge) without being refreshed is flushed from every database. That's how the LSAs of a router that has vanished for good eventually disappear.

There's also a checksum, a Fletcher checksum over the whole LSA except the age, which changes in transit. Our R2 is at sequence number 0x80000003 because it has issued three versions: one when it booted, which held only stub networks, and one each time an adjacency came up, first to R3, then to R5. R3 and R5 each came up with three neighbours, so they're at 0x80000004; R6 has two, so it's at 0x80000003.

Flooding, Reliably

A new LSA has to reach every router, intact, in order, and over links that occasionally drop packets. OSPF's flooding rule is short:

# When an LSA arrives from neighbour n inside a Link State Update:
on receiving lsa from n:
    mine = lsdb.lookup(lsa.adv_router, lsa.type, lsa.id)
    if mine is none or lsa is newer than mine:        # higher seq (then checksum, then age)
        lsdb.install(lsa)                             # and schedule an SPF run
        send an acknowledgement to n
        for each other neighbour m (not n):
            send lsa to m;  remember to resend it every 5 s until m acknowledges
    else if lsa is the same instance as mine:         # a duplicate
        if I'm waiting for n to acknowledge it:
            treat this copy as n's acknowledgement     # an "implied acknowledgement"
        else:
            send an acknowledgement to n
    else:                                             # older than mine
        send mine back to n                           # n is out of date: catch it up

Three properties fall out of it:

  • Every router gets the LSA. Each router passes a new LSA to everyone except the neighbour it came from, so it spreads along every link, like a rumour that everybody repeats exactly once.
  • It stops. A router passes on only LSAs that are newer than its own copy. The second time an LSA reaches a router, it's a duplicate, and the flood ends there. That's why flooding can't loop, even though the network is full of loops.
  • It's reliable. Every copy must be acknowledged, explicitly or implicitly, and the sender retransmits it every 5 seconds (the default RxmtInterval) until it is. Several LSAs can share one Link State Update packet, and several acknowledgements one Link State Acknowledgment packet.

Why sequence numbers matter so much

The flooding rule relies on one comparison: is this LSA newer than mine? If a router could mistake an old LSA for a new one, it would install stale information and flood it everywhere. If it couldn't tell which of two LSAs was newer at all, flooding might never stop. The ARPANET found this out the hard way.

27 October 1980: the day the ARPANET's routing updates wouldn't die

The ARPANET's new routing algorithm numbered each switch's updates with a 6-bit sequence number that counted up modulo 64, and a circular rule decided which of two updates was later: n is later than m if it's ahead by at most 32 steps going round the circle. That day, three updates from one switch, IMP 50, were circulating at once, identical except for their sequence numbers: 8, 40 and 44. In binary those are 001000, 101000 and 101100, which suggests a single update, 44, whose number lost a bit and then another. IMP 50 had been malfunctioning just before the outage, and its neighbour IMP 29 was suffering hardware faults, in particular dropping bits.

By the circular rule, 44 is later than 40, 40 is later than 8, and 8 is later than 44. Each copy replaced one of the others wherever it went, so all three circulated forever, and the switches spent nearly all their time and buffers processing them. For several hours the network was effectively unusable. BBN recovered by patching every switch to ignore IMP 50's updates (IMP 50 was down by then anyway); with the network in that state, distributing a patch could take as long as 3 or 4 hours. Eric Rosen, one of the algorithm's authors, wrote it up as RFC 789.

Later link-state protocols were designed with that day in mind. OSPF's sequence numbers are 32 bits wide and run in a straight line, so "newer" is a simple comparison that can never go round in a circle. When an LSA does reach 0x7fffffff, its author must first flush the old version from every database, by flooding it with its age set to MaxAge, before starting again at 0x80000001. (At one new version every 5 seconds, the most OSPF allows, that would take about 680 years.) Every LSA has a checksum, so a corrupted one is thrown away rather than flooded, and the age means that even a bad LSA can only live for an hour. The flooding Perlman designed for IS-IS was described as self-stabilising for the same reason: whatever corrupt information gets into the network, it is eventually flushed out.

Our routers' databases

Once flooding has finished, every router holds the same four router-LSAs. This is the whole map:

Adv. router    Seq          Links (neighbour: cost)        Stub networks (cost)
0.0.0.2  R2    0x80000003   R3: 10   R5: 50                 192.0.2.0/30 (10), 192.0.2.16/30 (50),
                                                            198.51.100.0/24 (10)
0.0.0.3  R3    0x80000004   R2: 10   R5: 30   R6: 10        192.0.2.0/30 (10), 192.0.2.20/30 (30),
                                                            192.0.2.24/30 (10)
0.0.0.5  R5    0x80000004   R2: 50   R3: 30   R6: 10        192.0.2.16/30 (50), 192.0.2.20/30 (30),
                                                            192.0.2.28/30 (10), 192.0.2.96/27 (10)
0.0.0.6  R6    0x80000003   R3: 10   R5: 10                 192.0.2.24/30 (10), 192.0.2.28/30 (10),
                                                            192.0.2.128/25 (10)

Notice that every link appears twice, once in each end's LSA. That's deliberate. When Dijkstra's algorithm walks across a link, it checks that the router at the far end lists the link too. A link only counts if both ends agree it's up: the same two-way check as the Hellos, applied to the map.

Step 3: Dijkstra, Run by Every Router

With the map in hand, each router computes the shortest path from itself to every other router. The tool is Dijkstra's algorithm, published by Edsger Dijkstra in 1959. The Dijkstra's Shortest Path article in the Algorithms series explains it from first principles; here's the version OSPF calls the SPF (shortest path first) calculation, run by R2.

The algorithm keeps two sets of routers:

  • Confirmed: routers whose shortest distance is known for certain. They form the shortest-path tree.
  • Tentative: routers we've found a path to, with the best distance so far and the first hop. (RFC 2328 calls this the candidate list.)

At each step it confirms the tentative router with the smallest distance, and then relaxes each of its links: if going through the newly confirmed router u gives a neighbour v a shorter path, update v:

d(v)←min⁡{ d(v), d(u)+c(u,v) }d(v) \leftarrow \min\{\,d(v),\ d(u) + c(u,v)\,\}

Why can the smallest tentative router be confirmed? Because every other route to it would have to pass through some other tentative router, which is already at least as far away, and costs are never negative. That's the one assumption Dijkstra needs, and the one Bellman–Ford, from the last article, doesn't.

R2 computes its routes

  1. Start: confirm R2 itself, at 0

    R2 reads its own LSA. Its links lead to R3 at cost 10 and R5 at cost 50, so both go on the tentative list. Each is a direct neighbour, so each is its own first hop. Tentative: R3 10 via R3, R5 50 via R5.

  2. Confirm R3, at 10

    R3 is the smallest tentative entry, so its distance is final. Now read R3's LSA. Its link to R6 offers 10 + 10 = 20, the first path to R6. Its link to R5 offers 10 + 30 = 40, better than the 50 we had, so R5 is updated. Both inherit R3's first hop: anything that travels through R3 leaves R2 on the R3 link. Tentative: R6 20 via R3, R5 40 via R3.

  3. Confirm R6, at 20

    R6's link to R5 offers 20 + 10 = 30, better than 40. Its link back to R3 leads to a confirmed router, so it's skipped. Tentative: R5 30 via R3.

  4. Confirm R5, at 30

    All of R5's neighbours are confirmed already. The tentative list is empty, and R2 is done.

R5's distance was improved twice, from 50 to 40 to 30, like R2's RIP route to R5 in the last article (5, 4, 3). Here is step 2's update in symbols:

d(R5)=min⁡{ 50, 10+30 }=40d(\text{R5}) = \min\{\,50,\ 10 + 30\,\} = 40

And the whole run as a table. Each row shows the tentative list after that router's links have been relaxed:

Step Confirm Tentative afterwards Changed
0 R2, 0 R3 10 via R3 · R5 50 via R5 R3, R5 found
1 R3, 10 via R3 R6 20 via R3 · R5 40 via R3 R6 found; R5 50 → 40
2 R6, 20 via R3 R5 30 via R3 R5 40 → 30
3 R5, 30 via R3 (empty)

The confirmed routers and the links that last improved each one form R2's shortest-path tree:

R2 · source 0 R3 10 · confirmed 2nd R5 30 · confirmed 4th R6 20 · confirmed 3rd 10 50 10 10 30 Green links form R2's shortest-path tree; every branch leaves R2 through R3. The dashed links are on the map, but on no shortest path from R2.

From the tree to a routing table

The tree gives R2 a distance and a first hop for every router. Routes are for prefixes, so there's a second stage: for every router in the tree, take each stub network in its LSA and offer a route at the router's distance plus the stub's cost, via the router's first hop. Where several routers advertise the same prefix (each /30 is advertised by both of its ends), the cheapest offer wins:

R2's OSPF routes                   Cost   Next hop
192.0.2.0/30      (R2–R3 link)     connected
192.0.2.16/30     (R2–R5 link)     connected
192.0.2.20/30     (R3–R5 link)     40     192.0.2.2 (R3), eth1     R3's 10 + 30
192.0.2.24/30     (R3–R6 link)     20     192.0.2.2 (R3), eth1     R3's 10 + 10
192.0.2.28/30     (R5–R6 link)     30     192.0.2.2 (R3), eth1     R6's 20 + 10
192.0.2.96/27     (business park)  40     192.0.2.2 (R3), eth1     R5's 30 + 10
192.0.2.128/25    (next town)      30     192.0.2.2 (R3), eth1     R6's 20 + 10
198.51.100.0/24   (our street)     connected

R2's own prefixes are in its LSA too, but its connected routes (administrative distance 0) beat OSPF's (110) for the same prefix, as in Routing Basics. The OSPF routes go into R2's RIB, and the winners into its FIB, exactly as described in Control Plane and Data Plane.

The pseudocode, with the two-way check, the second stage, and ties:

function spf(lsdb, me):
    dist[me] = 0;  first_hop[me] = {}
    tentative = {me};  confirmed = {}                  # tentative is a priority queue
    while tentative is not empty:
        u = tentative.pop_smallest()
        confirmed.add(u)
        for each link (u, v, cost) in lsdb[u]:         # u's own router-LSA
            if v in confirmed: continue
            if lsdb[v] has no link back to u: continue # two-way check
            d = dist[u] + cost
            hop = {v} if u == me else first_hop[u]     # neighbours are their own first hop
            if v not in tentative or d < dist[v]:
                dist[v] = d;  first_hop[v] = hop;  tentative.add(v)
            else if d == dist[v]:
                first_hop[v] = first_hop[v] ∪ hop      # equal cost: keep both (ECMP)
    for each router r in confirmed:                    # stage 2: the leaves
        for each stub (prefix, cost) in lsdb[r]:
            offer prefix at dist[r] + cost via first_hop[r]   # cheapest offer wins

That else if handles ties. When two paths to a router cost the same, OSPF keeps both first hops and installs both routes, splitting traffic between them with ECMP. Our network has one already: R6 can reach the R3–R5 link's /30 through R3 (10 + 30) or through R5 (10 + 30), so it gets two next hops for 192.0.2.20/30. If the ISP lowered the leased link's cost to 20, R3 would have two equal paths to R5 as well, directly and via R6.

Every router does the same

R3, R5 and R6 run exactly the same algorithm on exactly the same map, each from its own point of view:

Router To R2 To R3 To R5 / R6
R2 (itself) 10 via R3 30 via R3 / 20 via R3
R3 10 via R2 (itself) 20 via R6 / 10 via R6
R5 30 via R6 20 via R6 (itself) / 10 via R6
R6 20 via R3 10 via R3 10 via R5 / (itself)

Compare that with the RIP tables at the end of Worked Example: Four Routers Converge: every distance is ten times larger and every next hop is identical. Two completely different algorithms, one distributed and one centralised, agree, as they must: there's only one set of shortest paths.

And here is the route from Routing Basics. R3's distance to R2 is 10, and R2 advertises the street at cost 10, so R3's route is 198.51.100.0/24 via 192.0.2.1, cost 10 + 10 = 20. That's the metric 20 in R3's table.

Why the routes are loop-free

Every router computes shortest paths on the same map. If R3's shortest path to the street goes through R2, then R2's shortest path to the street is the rest of R3's path: any shortcut from R2 would be a shortcut for R3 too. So following next hops always moves a packet strictly closer to its destination, and it can never come back to a router it has visited. As long as the databases agree, there are no loops. When they briefly don't, there can be, as we'll see in Microloops.

The map

One link per line as from to cost, optionally followed by the link’s subnet. A line like R2 stub 198.51.100.0/24 10 hangs a stub network off a router. Up to 8 routers; OSPF costs are whole numbers from 1 to 65535.

Green: confirmed, and the shortest-path tree. Blue dashed: the best path so far to a tentative router. Amber arrows: links just relaxed that improved a distance; grey: relaxed, no improvement. Tap a router to make it the source.

Tentative list

RouterDistFirst hop

Confirmed, in order

StepConfirmTentative afterwardsChanged

Log

Routing table

DestinationCostNext hop

The Street's Fibre Is Cut, Again

Time to repeat the experiment that made RIP count to 16. A digger cuts the fibre between R2 and our street. In the last article the routers then spent 14 rounds, about 7 minutes, agreeing that the street was gone. Here's what OSPF does.

R2's street interface goes down. R2 is the only router that knows, and it's also the author of the only LSA that mentions the street. So it issues a new version of its router-LSA, sequence number 0x80000004, identical to the old one except that the stub network 198.51.100.0/24 is gone, and floods it. Each hop takes a moment; call it one tick:

Tick Copy What the receiver does
0 R2 installs its own 0x80000004 and sends it to R3 and R5
1 R2 → R3 Newer than R3's 0x80000003: install, acknowledge to R2, send on to R5 and R6
1 R2 → R5 Newer: install, acknowledge to R2, send on to R3 and R6
2 R3 → R5 Same as R5's copy. R5 sent R3 this LSA too, so it counts as R3's acknowledgement
2 R5 → R3 Same as R3's copy; counts as R5's acknowledgement
2 R3 → R6 Newer: install, acknowledge to R3, send on to R5
2 R5 → R6 Same as R6's copy, which R6 has just sent to R5: counts as R5's acknowledgement
3 R6 → R5 Same as R5's copy; counts as R6's acknowledgement. The flood is over

Seven copies of the LSA crossed the network, and three explicit acknowledgements (R3 and R5 to R2, R6 to R3); the other four copies were acknowledged by the crossing copies themselves. Each router, as soon as it installed the new LSA, scheduled an SPF run. The tree is unchanged, since no link between routers has changed, but in the second stage the street's stub network is no longer in R2's LSA, so every router simply drops its route to 198.51.100.0/24.

There's nothing to count. R3 can't hear "street: 30" from R6 and believe it, because R6 never says anything about the street. Only R2 ever describes the street, and R2's newest LSA says it isn't there. In real time a tick is milliseconds, and routers wait a few tens of milliseconds before running SPF (see below), so the whole network agrees in well under a second, against minutes for RIP.

A harder failure: the R2–R3 link

Losing a destination is easy. Losing a link that routes run over is more interesting, because the routers have to find new paths. Start again from the settled network, with the street connected and R2's LSA at 0x80000003, and this time cut the fibre between R2 and R3.

Both ends notice, so both issue new LSAs at once: R2's 0x80000004 without the link to R3 or its /30, and R3's 0x80000005 without the link to R2. Each floods its own. The two-way check means a router needs only one of the two LSAs to stop using the link: as soon as R6 has R3's new LSA, R3 no longer lists R2, so the R2–R3 link fails the check, whatever R2's old LSA says.

With the link gone, the map has changed, so every router's tree changes. R2's run now goes: confirm R2; R5 50 via R5; confirm R5; R6 60 and R3 80, both via R5; confirm R6; R3 improves to 70 via R5; confirm R3. The new routes to the street:

Router Before the cut After the cut
R2 connected connected
R3 20 via R2 80 via R6 (R3 → R6 → R5 → R2)
R5 40 via R6 60 via R2 (the microwave link)
R6 30 via R3 70 via R5

The microwave link, unused while the fibre was up, now carries all of the street's traffic. Nobody had to configure a backup route: it was on the map all along.

Microloops: When the Maps Briefly Disagree

Link-state routing is loop-free when every router has the same database and has finished its SPF run. In between, they don't all switch at the same instant. Look at the table above: R3 changes its route to the street to go via R6, and R6 changes its own to go via R5. R3 detected the failure itself, so it has the news first and usually recomputes first. For a moment, R3 sends street traffic to R6, and R6, still running on the old map, sends it straight back to R3:

Our street · 198.51.100.0/24 50 R2 connected R3 · updated 80 via R6 R5 · old map 40 via R6 R6 · old map 30 via R3 10 30 R3 has run SPF; R6 hasn't yet. Street traffic bounces between R3 and R6 until R6 recomputes, a moment later, and starts sending it to R5.

That's a microloop: a forwarding loop that lasts only as long as the routers' SPF runs and FIB updates are out of step, typically tens to hundreds of milliseconds. It isn't count to infinity: nobody believes anything false, and it ends by itself as soon as the slowest router catches up. If R6 updated next but R5 lagged further behind, there'd be a second loop between R6 (now via R5) and R5 (still via R6). Packets caught in a microloop either escape when it ends or run out of TTL, and for a voice call or a trading system even 100 milliseconds of loss matters. We'll see what can be done about it below.

Scenario

Links

Tap a link on the diagram to cut or restore it, or the street’s link to cut or repair its fibre. Pick a link here to change its cost; every change to a working link makes both ends issue new LSAs.

Link-state databases

Neighbours

Routing table

PrefixCostNext hop

Next hop, tick by tick

Log

R2’s Hello to R3, live

OSPF in Detail

Everything so far applies to any link-state protocol. Here's what's specific to OSPFv2, the version for IPv4.

On the wire

OSPF runs directly on IP, as IP protocol 89, with no TCP or UDP underneath; it does its own acknowledgements and retransmissions. There are five packet types: Hello (1), Database Description (2), Link State Request (3), Link State Update (4) and Link State Acknowledgment (5). Packets go to 224.0.0.5 (AllSPFRouters) or, on shared segments, 224.0.0.6 (AllDRouters, see the next section), always with TTL 1 and the IP precedence bits set to "internetwork control", so routers can prioritise them over ordinary traffic. OSPFv3 uses ff02::5 and ff02::6, the IPv6 equivalents.

Every packet starts with a 24-byte header. A Hello adds 20 bytes, plus 4 for each neighbour it has heard:

0 8 16 24 31 Version (1) Type (1) Packet length (2) Router ID (4) Area ID (4) Checksum (2) AuType (2) Authentication (8) Network mask (4) HelloInterval (2) Options (1) Rtr Pri (1) RouterDeadInterval (4) Designated Router (4) Backup Designated Router (4) Neighbor (4), repeated for each router heard OSPF header: 24 bytes, the same for all five packet types. Hello body: 20 bytes, plus 4 bytes per neighbour.

Here's R2's Hello on its link to R3, once it has heard R3. It goes out of eth1 from 192.0.2.1 to 224.0.0.5, inside an IPv4 header with protocol 89 and TTL 1, inside an Ethernet frame to the multicast MAC 01:00:5e:00:00:05:

R2's Hello to R3: 48 bytes of OSPF

0000  02 01 00 30 00 00 00 02 00 00 00 00 fb 99 00 00
0010  00 00 00 00 00 00 00 00 ff ff ff fc 00 0a 02 01
0020  00 00 00 28 00 00 00 00 00 00 00 00 00 00 00 03

 OSPF header  ·  Hello body  ·  neighbour heard: 0.0.0.3 

Bytes Field: value here
02 Version: OSPFv2
01 Type: Hello
00 30 Packet length: 48 bytes
00 00 00 02 Router ID: 0.0.0.2, R2
00 00 00 00 Area ID: 0.0.0.0, the backbone
fb 99 Checksum: see below
00 00 AuType: 0, no authentication
00 × 8 Authentication: unused with AuType 0
ff ff ff fc Network mask: 255.255.255.252, the link's /30
00 0a HelloInterval: 10 s
02 Options: E bit (external routes OK)
01 Router priority: 1
00 00 00 28 RouterDeadInterval: 40 s
00 00 00 00 Designated Router: none (a point-to-point link has no DR)
00 00 00 00 Backup DR: none
00 00 00 03 Neighbor: R3, so the link is two-way

The checksum is the same one's-complement sum as the IPv4 header checksum, over the whole OSPF packet except the 8 authentication bytes, with the checksum field set to zero:

The twenty 16-bit words 0201+0030+0000+0002+⋯+0000+0003\texttt{0201} + \texttt{0030} + \texttt{0000} + \texttt{0002} + \dots + \texttt{0000} + \texttt{0003} add up to 20464\texttt{20464}. Fold the carry: 0464+2=0466\texttt{0464} + \texttt{2} = \texttt{0466}, and flip the bits: ¬ 0466=fb99\lnot\,\texttt{0466} = \texttt{fb99}.

The ones that do the work are the header's 0201, 0030 and 0002, the mask's ffff and fffc, 000a, 0201 (options and priority), 0028 and the neighbour's 0003; the rest are zero. Notice there's no pseudo-header, unlike UDP's checksum in the last article: OSPF's checksum covers only the OSPF packet.

Designated routers on shared segments

Our links are point-to-point: one router at each end. But OSPF can also run on a shared Ethernet segment with many routers on it, and there the obvious approach scales badly. With n routers each adjacent to every other, there are n(n−1)/2n(n-1)/2 adjacencies, every router describes the segment in its LSA, and every change is flooded across the segment by everybody.

OSPF's fix is to elect a Designated Router (DR) and a Backup Designated Router (BDR) on each such segment. Every other router (a DROther) forms a full adjacency only with the DR and the BDR: 2n−32n-3 adjacencies in all, so 17 rather than 45 with ten routers. DROthers send their LSAs to 224.0.0.6, which only the DR and BDR listen to, and the DR refloods them to everyone on 224.0.0.5. The DR also issues a network-LSA (type 2) on behalf of the segment, listing every router attached to it, so that on the map the segment appears as one node with a spoke to each router, rather than a full mesh of links. The BDR listens to everything, ready to take over if the DR fails.

The election uses the Hellos. The router with the highest priority (default 1, 0 means "never") wins, ties going to the highest router ID. If our four routers shared one segment, R6 (0.0.0.6) would become DR and R5 the BDR. The election is deliberately not pre-emptive: a router that joins a segment that already has a DR accepts it, whatever its own priority, because changing DR means rebuilding every adjacency on the segment.

On an Ethernet interface OSPF assumes a shared segment by default, so it would elect a DR even on a link with only two routers, after waiting 40 seconds to see who else turns up. That's why our ISP configures its fibre links as point-to-point: no election, no network-LSA, and the adjacency starts forming straight away.

Costs and the reference bandwidth

The OSPF RFC leaves the choice of costs to the network operator. Implementations calculate a default from the interface's bandwidth:

cost=⌊reference bandwidthinterface bandwidth⌋\text{cost} = \left\lfloor \frac{\text{reference bandwidth}}{\text{interface bandwidth}} \right\rfloor

with a minimum of 1. The traditional reference bandwidth, still the default in Cisco IOS and FRR, is 100 Mb/s, chosen when 100 Mb/s Ethernet was fast. So Fast Ethernet costs 1, and so does gigabit, 10-gigabit and 100-gigabit Ethernet: everything from 100 Mb/s up looks the same, and OSPF would happily send traffic over a 100 Mb/s link instead of a 100 Gb/s one if the hop count was lower. That's why almost everyone raises it. Our ISP uses 100 Gb/s, so a 10 Gb/s link costs 10 and a 1 Gb/s link would cost 100, leaving room for faster links later. It must be the same on every router, or they'll disagree about which links are expensive.

Many operators go further and set every cost by hand, to encode things a bandwidth can't express: the leased link's price, a link's latency, or which of two equal paths should carry the traffic. OSPF doesn't care where the numbers come from, only that each interface has one.

The main LSA types

The router-LSA is one of several LSA types, each with its own author and its own reach:

Type Name Issued by Describes
1 Router-LSA Every router Its links and stub networks within one area
2 Network-LSA The DR of a shared segment The routers attached to the segment
3 Summary-LSA An area border router A prefix in another area, and the cost to it
5 AS-external-LSA An AS boundary router A route from outside OSPF: static, BGP, or a default

Type 4 tells routers how to reach an AS boundary router in another area, and type 7 carries external routes inside a special kind of area called an NSSA (RFC 3101). Types 1, 2 and 3 are flooded within one area; type 5 goes everywhere. If R3 had been configured to announce a default route into OSPF, rather than R2, R5 and R6 each having a static one, it would have issued a type 5 LSA for 0.0.0.0/0, and become an ASBR.

Configuring it

Here's R2's OSPF configuration in FRR, matching the RIP one from the last article. The street interface is passive: it's advertised in R2's LSA as a stub, but R2 sends no Hellos to customers and won't form adjacencies there:

interface eth0
 ip ospf area 0
 ip ospf passive
!
interface eth1
 ip ospf area 0
 ip ospf network point-to-point
!
interface eth2
 ip ospf area 0
 ip ospf network point-to-point
 ip ospf cost 50
!
router ospf
 ospf router-id 0.0.0.2
 auto-cost reference-bandwidth 100000

The reference bandwidth is in Mb/s, so 100000 is 100 Gb/s; eth1, a 10 Gb/s fibre, gets cost 10 from it automatically. The microwave link's cost is set explicitly, because Linux can't see the radio's real speed. On R3, the leased link's interface has ip ospf cost 30.

Areas: Splitting the Map

Every router in our network holds the whole map, and reruns SPF whenever anything changes. With four routers that's nothing. With a few thousand, every router would hold a big LSDB, every flap anywhere would make every router recompute, and every LSA would be flooded everywhere. OSPF's answer is areas.

  • An area is a group of routers and links with its own LSDB. Router-LSAs and network-LSAs are flooded only within their area, so a router knows the detailed map of its own area and nothing more.
  • Area 0, the backbone, connects all the others. Every other area must attach to it, so traffic between two areas always crosses the backbone.
  • An area border router (ABR) sits in two or more areas, one of them the backbone, and holds an LSDB for each. Into each area it injects summary-LSAs (type 3): "prefix p, at cost c from me". Inside the area, routers treat those like stubs hanging off the ABR. That's distance-vector thinking, used deliberately between areas, which is why areas must form a star around the backbone, so that summaries can never chase each other in a loop.
  • An ABR can summarise a whole block of prefixes into one summary-LSA, exactly the aggregation from the addressing article.

Suppose the next town grows into a network of its own, with routers R7 and R8 behind R6. The ISP makes it area 1, and R6 becomes an ABR:

Area 0 · backbone Area 1 · next town R2 R3 R5 R6 ABR R7 192.0.2.128/26 R8 192.0.2.192/26 R6 advertises one type 3 LSA: 192.0.2.128/25 Area 1's router-LSAs stay in area 1; area 0 sees only R6's summary.

Inside area 1, R6, R7 and R8 flood router-LSAs to each other and run SPF on their own small map. Into area 0, R6 advertises a single summary-LSA, 192.0.2.128/25, the same prefix the next town always had. R2, R3 and R5 don't know or care how many routers or links area 1 has. A link flapping inside area 1 causes no new LSAs and no SPF runs in area 0 at all, because the summary doesn't change. And the routers in area 1 can be configured as a stub area, which keeps type 5 external routes out entirely and gives them a default route instead.

The price is the usual price of summarising: R2 no longer knows the exact cost to each of the town's subnets, only R6's cost to the whole block, so the route it picks may be slightly less than optimal. For a large network, that's a good trade. (If an ASBR brings in routes from outside, it marks itself in its router-LSA, and ABRs tell other areas how to reach it with type 4 LSAs.)

OSPFv3 for IPv6

OSPFv3 (RFC 5340) is OSPF rebuilt for IPv6, and it takes the chance to tidy up:

  • Topology and prefixes are separated. Router-LSAs and network-LSAs describe only the graph: which routers connect to which, at what cost. Prefixes travel in a new intra-area-prefix-LSA. Adding a prefix no longer changes the topology LSAs, so it doesn't need a full SPF run.
  • It runs per link. OSPFv3 routers talk to each other from their link-local addresses, and neighbours are always identified by router ID, which stays a 32-bit number.
  • No built-in authentication. OSPFv3 originally relied on IPsec (RFC 4552); RFC 7166 later added an authentication trailer like OSPFv2's.

The flooding, the neighbour states, the DR election, the areas and Dijkstra are all the same. That's why R3's IPv6 routes in Routing Basics had link-local next hops like fe80::ff:fee2:1: they came from OSPFv3.

IS-IS: The Other Link-State Protocol

IS-IS does the same job as OSPF, with the same three steps and the same algorithm, but it grew up in a different world and it shows:

  • It doesn't run on IP. IS-IS was an OSI protocol, so its packets go straight into Ethernet frames, with an LLC header whose SAPs are 0xFE, rather than inside IP packets. That makes it independent of the address family: one IS-IS instance carries IPv4 and IPv6 routes side by side, and it's hard to attack from somewhere that can only send IP packets.
  • Everything is a TLV. Every piece of information in an IS-IS packet is a TLV. IPv6 support, wider metrics, traffic-engineering data and segment routing were all added by defining new TLVs, without changing the protocol around them. (IS-IS's original metrics were just 6 bits, 0 to 63 per link; RFC 5305's "wide" metrics are 24 bits.)
  • Levels instead of areas. Level 1 routing happens inside an area and Level 2 between areas, with Level 1/2 routers doing both. Area boundaries run along links, not through routers as in OSPF.
  • Its own names. Routers are intermediate systems, LSAs are LSPs (link-state PDUs), the DR is the DIS (with no backup, and pre-emptive), and the database exchange uses complete and partial sequence-number PDUs instead of DD packets.

Many of the largest ISPs run IS-IS rather than OSPF, partly for those reasons and partly for history: when they built out their networks in the 1990s, the IS-IS implementations in their routers were mature and well trusted. IS-IS has also left the IP world altogether: TRILL and Shortest Path Bridging, the link-state replacements for spanning tree from Beyond Spanning Tree, both use it to route Ethernet frames.

Convergence in Practice

"Every router recomputes" makes link-state convergence sound instant, and compared with RIP it is. But between the fibre being cut and the last router forwarding on its new route there are several steps, and each one takes time:

  1. Detect the failure

    Instant for loss of light on a fibre; up to the 40-second dead interval if the link fails silently; tens of milliseconds with BFD.

  2. Originate and flood the LSA

    Milliseconds per hop. OSPF won't issue a new version of an LSA more often than every 5 seconds by default (MinLSInterval), and modern implementations make that a back-off timer that starts much lower.

  3. Wait, then run SPF

    A router doesn't run SPF the instant an LSA arrives: one failure usually produces several LSAs (both ends of a link, at least), so it waits a little to collect them.

  4. Update the FIB

    Writing thousands of changed routes into the forwarding hardware can take longer than SPF itself. Routers usually update the most important prefixes first.

SPF throttling

The wait before SPF is a trade-off. Run immediately, and a burst of LSAs from one failure means a burst of SPF runs. Wait too long, and traffic is lost for longer. Most implementations use an exponential back-off: run quickly after the first event, then wait longer and longer if events keep coming, and relax back once things are quiet. RFC 8405 (2018) standardised one algorithm, so that routers from different vendors back off in the same way, which also keeps their SPF runs in step and shortens microloops. Its suggested defaults are 50 ms for an isolated event, 200 ms while a burst is being learned, and 5 seconds if the network keeps churning, returning to 50 ms after 10 seconds of quiet.

Incremental and partial SPF

Rerunning Dijkstra from scratch for every change is wasteful when a change touches only a corner of the tree. Incremental SPF recomputes only the part of the tree below the changed link; the 1979 ARPANET algorithm already worked this way. And when only a prefix has changed, as when our street was cut, the tree hasn't changed at all, and a router only needs to redo the second stage. IS-IS calls that a partial route calculation. In OSPFv2, prefixes live in the router-LSAs, so the standard says any router-LSA change means recalculating the whole routing table; OSPFv3's separate prefix LSAs avoid that.

Fast reroute: a backup ready in advance

Even 200 ms of loss is too much for some traffic. IP fast reroute has each router precompute a backup next hop for each destination, before anything fails, so that when a link dies the router can switch to the backup in the forwarding plane, within tens of milliseconds, while the protocol converges in the background. The simplest kind is the loop-free alternate (LFA, RFC 5286): a neighbour N is a safe backup for router S to reach destination D if N's own shortest path to D doesn't come back through S:

d(N,D)<d(N,S)+d(S,D)d(N, D) < d(N, S) + d(S, D)

Check it on our network. For R2, protecting its link to R3, could R5 carry traffic to R6? R5's distance to R6 is 10, and 10 < 30 + 20, so yes: R5 would deliver it directly rather than send it back. R2 has a ready-made backup. Now R3, protecting its link to R2, for traffic to the street. R6's path to R2 runs through R3 (20, not less than 10 + 10), and so does R5's (30, not less than 20 + 10). R3 has no LFA, and that's exactly the router at the centre of the microloop above. If those numbers look familiar, they should: it's the same answer EIGRP's feasibility condition gave in Loop-Free Distance Vector, for the same reason.

Where plain LFA finds nothing, later techniques tunnel the packet past the trouble: remote LFA (RFC 7490) to a router from which the normal path is safe, and TI-LFA ("topology-independent", RFC 9855, 2025) with segment routing, which can steer R3's packets "to R5, then across the R5–R2 link" with a short list of labels.

Avoiding microloops

Microloops come from routers updating in an unlucky order. In our failure, R3 updating first is the problem; if R6 and R5 updated before R3, there'd be no loop. Several mechanisms exploit that. RFC 8333 has the router next to a failure, here R3, delay its own update for a moment, protecting its traffic with fast reroute in the meantime, so the rest of the network converges first. Other schemes order the updates across the whole network, and RFC 5715 surveys them. Many networks simply accept microloops: they're short, rare, and end by themselves.

Security

Every router believes every LSA, so a router that can inject LSAs can redraw everyone's map: pull traffic towards itself to read or drop it, or black-hole a prefix. Defences come in layers.

  • Don't talk to strangers. Customer-facing interfaces are passive, like R2's street interface, so no Hello sent from a customer's machine will ever be answered. OSPF packets have TTL 1 and are only accepted from directly connected neighbours.
  • Authenticate the packets. OSPFv2 has three authentication types in the header's AuType field: 0, none; 1, a plain-text password that anyone on the link can read; and 2, cryptographic. RFC 2328 defined cryptographic authentication with keyed MD5, appending a digest computed from the packet and a shared key, plus a sequence number to stop old packets being replayed. (With it, the header checksum is left at zero; the digest does the job.) RFC 5709 (2009) added HMAC-SHA-1 and the SHA-2 family, and RFC 7474 (2015) closed replay holes that remained after a router restarts and extended the digest to cover the source IP address. OSPFv3 got the equivalent authentication trailer in RFC 7166. MD5 should be retired wherever HMAC-SHA is available.
  • Fight back. If a router receives a copy of its own LSA that's newer than the one it issued, something is wrong, so it immediately issues an even newer correct version, which overwrites the forgery everywhere.

Authentication only proves a packet came from someone with the key. A compromised router inside the network still has the key, and research such as Nakibly, Kirshon, Gonikman and Boneh's Persistent OSPF Attacks (2012) showed ways for such an insider to plant false LSAs that the fight-back mechanism doesn't catch. That's one reason operators watch their LSDBs for changes nobody planned, and why the attack surface is kept as small as possible: OSPF runs only on the links between the operator's own routers.

Beyond One Network

OSPF and IS-IS are interior gateway protocols (IGPs): they route inside one organisation's network, an autonomous system. They're perfect there, because everyone shares one goal, shortest paths, and everyone trusts everyone else's LSAs. Neither is true between networks.

  • Scale. A link-state protocol needs every router to hold the whole map. The Internet has around a million prefixes and tens of thousands of networks, changing constantly. No router could hold, flood and rerun Dijkstra on that.
  • Privacy. Our ISP doesn't want to publish its internal topology to its competitors, which is what flooding its LSAs to them would mean.
  • Policy. Between networks, the best route is often not the shortest. Our ISP pays its transit provider for traffic but exchanges traffic with a neighbouring ISP for free, so it prefers the free path even if it's longer, and it will carry its customers' traffic but not a competitor's. Shortest-path routing has no way to say any of that.

So between networks, the Internet uses BGP, a path-vector protocol: each route carries the list of networks it passes through, and every network applies its own policy to choose and pass on routes. Inside the ISP, OSPF still tells R3 how to reach R2; BGP tells it which networks are reachable through R4, DC-2 and the peer ISP. It's how R3 learned 203.0.113.0/24, and it's the next article.

Link-state routing has one more trick, which has become the basis of modern ISP backbones. Segment routing (RFC 8402, 2018) builds on the fact that every router already knows the whole map and computes the same shortest paths. Each router advertises a label, a segment identifier, in its LSAs, and a router sending a packet can attach a short list of them: "go to R5 by the shortest path, then take the R5–R2 link". Routers in the middle just follow the shortest path to the next segment, with no extra signalling and no extra state. It's how TI-LFA's backup paths are built, and how operators steer traffic around congestion without leaving the comfort of their IGP.

Where to Go Next

  • BGP: how the Internet's networks exchange routes between themselves, where policy matters more than distance.
  • Distance-Vector Routing: the approach link-state replaced, its count to infinity, and EIGRP's loop-free alternative.
  • Dijkstra's Shortest Path: the algorithm at the heart of SPF, step by step, with priority queues and complexity.
  • Routing Basics: what a router does with the routes once it has them: longest-prefix match, administrative distance, the RIB and the FIB.
  • Spanning Tree: Radia Perlman's other famous protocol, and the IS-IS-based bridging that replaced it in data centres.

Key Takeaways

  • In link-state routing every router describes its own links in an LSA, the LSAs are flooded to every router, every router builds the same link-state database, and each runs Dijkstra on it with itself as the source. Routers share facts about links, never conclusions about distances, so there is nothing stale to count to infinity from.
  • The ARPANET switched to link-state routing in May 1979 (McQuillan, Richer and Rosen). IS-IS came from DEC and ISO (ISO 10589, 1992); OSPF from the IETF (RFC 1131 in 1989, OSPFv2 now RFC 2328 from 1998, OSPFv3 RFC 5340 from 2008).
  • Hellos (every 10 s, dead after 40 s) discover neighbours and confirm two-way contact. Neighbours go Down, Init, 2-Way, ExStart, Exchange, Loading, Full, synchronising their databases with header-only Database Description packets before they become adjacent.
  • Flooding is reliable: each new LSA is passed on to every neighbour except its source and acknowledged, explicitly or by a crossing copy. Sequence numbers decide which LSA is newer. OSPF's run in a straight line from 0x80000001; the ARPANET's circular 6-bit numbers let three corrupted copies of one update circulate for hours in 1980. LSAs are refreshed every 30 minutes and expire at one hour.
  • On our ISP's network, with costs 10, 50, 30, 10, 10, R2's SPF confirmed R3 (10), R6 (20) and R5 (30), all via R3. R3's route to the street is 10 + 10 = 20 via R2, the metric in Routing Basics. Cutting the street's fibre took one new LSA, seven copies and three ticks, and no counting.
  • OSPF is IP protocol 89, multicast to 224.0.0.5 and 224.0.0.6 (ff02::5 and ff02::6). Shared segments elect a DR and BDR by priority, then router ID; costs default, in Cisco IOS and FRR, to 100 Mb/s divided by the interface bandwidth, which is why the reference is usually raised. Router, network, summary and external LSAs are types 1, 2, 3 and 5.
  • Areas keep LSDBs and SPF runs small: area 0 is the backbone, ABRs inject (and can summarise) type 3 LSAs, ASBRs bring in external routes. IS-IS does the same job with levels, TLVs, and packets that run directly on layer 2.
  • Convergence takes detection, flooding, a throttled SPF run and a FIB update. Routers that update at different moments can form short microloops; loop-free alternates and TI-LFA protect traffic while that happens. OSPF should be authenticated with HMAC-SHA (RFC 5709, RFC 7474).

Inside one network, every router can see the whole map, and the best route is simply the shortest. Between networks, nobody shares their map, and the "best" route depends on who is paying whom. Next: BGP, the protocol that holds the Internet together on trust, policy and a list of the networks each route has passed through.