Sub topic 14
The link-state database
This chapter assumes you know what a link-state advertisement (LSA) is, how hello packets form adjacencies, and how flooding spreads LSAs. It also assumes you can read a weighted graph. Here you will see what a router stores after flooding, how it decides whether a received LSA is new, and how the stored records become the graph that Dijkstra's algorithm runs on.
What the database holds
The link-state database (LSDB) is the set of the newest LSAs received from every router in a flooding scope. In OSPF the scope is an area. In IS-IS it is a level. Each LSA describes only the originating router's own links and their costs. No single record is a map. The map exists only when you combine all the records.
The central property is that every router in the scope holds the same LSDB. Each router runs the same algorithm on the same input, so the results are consistent. A router never trusts a neighbor's computed routes. It trusts only the neighbor's raw facts.
An LSDB entry is identified by a key and carries three fields that control freshness:
| Field | Purpose | OSPFv2 | IS-IS |
|---|---|---|---|
| Key | Which record this is | LS type, link-state ID, advertising router | LSP ID (system ID, pseudonode, fragment) |
| Sequence number | Which instance is newer | 32-bit signed, starts at 0x80000001 | 32-bit unsigned |
| Age or lifetime | Removes dead records | Counts up to MaxAge, 3600 s | Counts down from 1200 s by default |
| Checksum | Detects corruption in memory or transit | Fletcher checksum | Fletcher checksum |
The originating router refreshes its own records before they expire. OSPF refreshes every 30 minutes. IS-IS refreshes every 15 minutes by default. If a router disappears, its records stop being refreshed and age out everywhere.
Deciding which instance is newer
A router can receive the same LSA many times through flooding, and it can receive old instances after a delay. For each arriving LSA it compares against the stored copy:
- If no copy exists, install it, then flood it onward.
- If the arriving sequence number is higher, it replaces the stored copy, and the router floods it.
- If the sequence number is lower, the arriving copy is stale. The router discards it and may send its newer copy back to the sender.
- If the sequence numbers are equal, the copies are duplicates. The router acknowledges the arriving one and does not flood it again.
OSPF adds tie-breakers. It compares the checksum if sequence numbers are equal. It then compares age, and an instance that is more than MaxAgeDiff (15 minutes) younger counts as newer. IS-IS compares sequence numbers first, and a zero remaining lifetime marks a purge.
Building the graph from the database
Installing a record does not by itself change routing. The router schedules a shortest-path computation, and that computation first converts the LSDB into a graph.
One rule matters here: the two-way connectivity check. A link from A to B is usable only if B's LSA also lists A. If only one side advertises the link, it may be half-failed, or one router may have stale information. The router ignores such a link.
The following program implements the install rule and the two-way check:
from dataclasses import dataclass
@dataclass(frozen=True)
class Lsa:
origin: str
seq: int
links: tuple # tuple of (neighbor, cost) pairs
class Lsdb:
def __init__(self):
self.lsas = {}
def install(self, lsa):
"""Return True if the LSA is new and should be flooded onward."""
cur = self.lsas.get(lsa.origin)
if cur is None or lsa.seq > cur.seq:
self.lsas[lsa.origin] = lsa
return True
return False
def graph(self):
"""Build node -> {neighbor: cost}, keeping only two-way links."""
adv = {o: dict(l.links) for o, l in self.lsas.items()}
g = {o: {} for o in adv}
for o, nbrs in adv.items():
for n, cost in nbrs.items():
if o in adv.get(n, {}):
g[o][n] = cost
return g
db = Lsdb()
print(db.install(Lsa("R1", 2, (("R2", 10), ("R3", 5))))) # True: new
print(db.install(Lsa("R1", 1, (("R2", 10),)))) # False: stale
print(db.install(Lsa("R1", 2, (("R2", 10), ("R3", 5))))) # False: duplicate
db.install(Lsa("R2", 1, (("R1", 10),)))
print(db.graph()) # R1-R3 is dropped because R3 has not advertised yet
db.install(Lsa("R3", 1, (("R1", 5),)))
print(db.graph()) # now R1-R3 appears in both directionsThe first graph() call prints {'R1': {'R2': 10}, 'R2': {'R1': 10}}. The second prints {'R1': {'R2': 10, 'R3': 5}, 'R2': {'R1': 10}, 'R3': {'R1': 5}}. You can pass this dictionary directly to the spf function from the Dijkstra chapter.
Synchronizing a new neighbor
Flooding only spreads changes. When two routers form a new adjacency, they must first copy each other's existing records. OSPF does this in the ExStart and Exchange states. The routers swap database description packets that list LSA headers (key, sequence number, age, checksum). Each router then requests any LSA it lacks or holds only in an older version. The adjacency reaches Full only when this exchange finishes. IS-IS does the same job with complete sequence number packets (CSNPs) and partial sequence number packets (PSNPs).
Operating the database
You can inspect the LSDB on a Cisco IOS router:
show ip ospf database
show ip ospf database router 1.1.1.1In a healthy area, the LSA count and the sequence numbers should match on every router. Sequence numbers that climb quickly point to a flapping link or a duplicate router ID. Two routers with the same router ID keep overwriting each other's LSAs, so the area never settles.
Memory and CPU grow with the LSDB size, so area and level boundaries exist to cap it. Every router in an area stores every router's LSA, which means a change anywhere makes all of them rerun SPF. Most implementations delay and batch SPF runs to avoid recomputing for every flap.
Exercise
Router R1 holds an LSA from R4 with sequence number 7. It receives an LSA from R4 with sequence number 6, and a minute later an LSA from R4 with sequence number 8. What does R1 do with each, and what does R1 do with a link R1-R4 that R1 advertises but R4's LSA no longer lists?
Show answer
R1 discards the sequence 6 LSA as stale. It may send its own sequence 7 copy back to the sender. It installs the sequence 8 LSA, floods it to its other neighbors, and schedules an SPF run. During graph construction, R1 fails the two-way check on the R1-R4 link because R4's LSA no longer lists R1, so it excludes that link from the shortest-path computation.