Link state routing
Link state routing: every router measures the cost to its neighbours, floods a link state packet through the network, so that every router holds the same map (the link state database), and runs Dijkstra's algorithm on it to build a shortest path tree and a forwarding table; the number of copies transmitted when a packet is flooded (2E - (N - 1)), sequence numbers, comparison with distance vector routing (information, convergence, loops, message cost) and OSPF as the example; Dijkstra, forwarding tables and flooding counts were checked against Floyd-Warshall and Bellman-Ford on random networks.
Why it exists
With distance vector routing no router knows the network, only what its neighbours say, and bad news spreads slowly. Link state routing takes the opposite approach: every router learns the whole map of the network and computes the best paths itself. It converges faster and has no count to infinity, at the price of more memory and flooding. It is the basis of OSPF.
Prerequisites
You need Dijkstra's algorithm (Dijkstra) and the way destinations are given as prefixes (CIDR).
Precise definitions
Link state routing has five steps in every router (quoted from the textbooks):
- Discover the neighbours by sending hello packets on each link and learning their identities.
- Measure the cost of each link (delay, bandwidth based, or a configured number).
- Build a link state packet (LSP) (called an LSA in OSPF) containing the router's identity, a sequence number, an age and the list of neighbours with the costs.
- Flood the LSP to all routers: a router that receives a new LSP (higher sequence number than the stored one from the same origin) stores it and forwards it on every link except the one it came from; old or duplicate copies are discarded.
- Compute routes: each router now holds the same link state database (the complete graph) and runs Dijkstra's algorithm with itself as the source. The result is a shortest path tree; for each destination the router keeps only the next hop (the first router on the path) in its forwarding table.
Every router computes from the same map, so the routes are consistent and loop-free. When a link changes, the router at its end floods a new LSP and all routers recompute.
How it works
Dijkstra at one router
Dijkstra's algorithm at router A (link state routing): start
Computed by a script, not typed| router | distance from A | previous router | status |
|---|---|---|---|
| A | |||
| B | |||
| C | |||
| D | |||
| E | |||
| F |
Step 0
Every router has the full map (all link costs) from flooding and runs Dijkstra. Link costs: A-B 7, A-C 9, A-F 14, B-C 10, B-D 15, C-D 11, C-F 2, D-E 6, E-F 9.
Router A holds the map of six routers with the link costs A-B , A-C , A-F , B-C , B-D , C-D , C-F , D-E , E-F . Dijkstra settles routers in order of distance: B (), C (), then F (, reached through C: , better than the direct ), D ( through C: , better than through B) and E ( through F). From the previous router column the tree is read off backwards. For E: previous F, previous C, previous A: path A-C-F-E.
Forwarding table of router A built from the shortest paths: start
Computed by a script, not typed| destination | cost | next hop | path |
|---|---|---|---|
| to B | |||
| to C | |||
| to D | |||
| to E | |||
| to F |
Step 0
From the tree of shortest paths the router keeps, for each destination, only the next hop.
The forwarding table keeps only the next hop: to D, E and F the packet goes to C first. This table together with the same computation at every other router gives hop-by-hop forwarding that follows exactly the shortest paths (checked by following the tables from every router to every other on random networks).
Flooding
Flooding link state packets: start
Computed by a script, not typed| origin | copies transmitted | order in which routers first receive it |
|---|---|---|
| link state packet of A | ||
| link state packet of B | ||
| link state packet of C | ||
| link state packet of D | ||
| link state packet of E | ||
| link state packet of F | ||
| all six routers |
Step 0
The network has N = 6 routers and E = 9 links. One flooded packet is transmitted 2E - (N - 1) times.
The network has routers and links. When a router floods its LSP: it sends it on all its links; every other router forwards the first copy on all links except the one it arrived on, and ignores later copies. The number of transmissions is
here per LSP and in all if every router floods its own LSP. The formula counts every link twice, once in each direction, minus the links on which a router's first copy arrived (those are not sent back). Sequence numbers prevent the same LSP from circulating forever and tell a router whether a packet is newer than what it stores.
Distance vector against link state
| distance vector | link state | |
|---|---|---|
| a router knows | its neighbours' vectors (costs to all destinations) | the whole map |
| information sent | its vector, to neighbours only | its own links, to all routers (flooding) |
| algorithm | Bellman-Ford, distributed | Dijkstra, local |
| convergence | slow when bad news, count to infinity | fast |
| loops during convergence | possible | only briefly, from different maps |
| memory and computing | small | larger ( map and Dijkstra) |
| protocol | RIP | OSPF |
(The table is the textbook comparison, quoted; the points on convergence were confirmed by the simulations of both pages.)
OSPF
The OSPF protocol is the standard link state protocol inside an autonomous system. It runs directly over IP, divides large networks into areas to limit the flooding, and may use equal-cost multipath (all of this is quoted; see protocols overview).
Worked examples
EX 1Flooding count
EasyA network with routers and links: one LSP is transmitted times. If each of the routers floods once, transmissions.
EX 2Reading the shortest path tree
MediumFrom the Dijkstra table of router A: previous(F) C, previous(C) A, so the path to F is A-C-F with cost and the next hop is C. Router C, which computes its own tree, has F itself as the next hop for F (cost ): each router has its own table, built from the same map.
EX 3A link cost changes
MediumThe cost of C-F rises from to . The router at the end of the link floods a new LSP with a higher sequence number; every router updates its map and reruns Dijkstra. For A the best path to F is then the direct link (), and to E the path A-F-E costs against A-C-D-E , so the next hop to E becomes F.
EX 4Typical questions
GATE level(a) "Which algorithm is used in link state routing?" Dijkstra. (b) "What is flooded, and to whom?" Each router's link state packet to all routers. (c) "Which of distance vector and link state suffers from count to infinity?" Distance vector. (d) "What does a router keep after running Dijkstra?" The next hop for each destination (it knows the whole tree). (e) "Name an intra-domain protocol of each type." RIP (distance vector), OSPF (link state). (f) "What is the purpose of the sequence number in an LSP?" To tell new information from old and stop duplicates from circulating.
Cheat box
Cheat box
- Each router: hello, measure cost, build LSP, flood, run Dijkstra on the full map.
- Flooding one LSP over routers and links costs transmissions; sequence numbers stop duplicates.
- Forwarding table keeps only the next hop from the shortest path tree.
- Faster convergence, no count to infinity; more memory and flooding than distance vector. OSPF vs RIP.
Traps and GATE patterns
Connections
Across subjects
The computation is single-source shortest paths (Dijkstra); the alternative using only neighbours' vectors is distance vector routing. The two types of protocol, and the path-vector protocol between networks, are surveyed on the protocols overview page.
PYQs
3 previous year questions from your book. I re-solved each one myself (0 by running or simulating, 3 by reasoning only); the book's key is shown next to my answer. All PYQs
Consider the routing protocols given in List-I and the names given in List-II: List-I List-II (i) Distance vector routing (a) Bellman-Ford (ii) Link state routing (b) Dijkstra For matching of items in List-I with those in List-II, which ONE of the following options is CORRECT?
- (a)(i) - (a) and (ii) - (b)
- (b)(i) - (a) and (ii) - (a)
- (c)(i) - (b) and (ii) - (a)
- (d)(i) - (b) and (ii) - (b) COMPUTER NETWORK
Which of the following statements is/are INCORRECT about the OSPF (Open Shortest Path First) routing protocol used in the Internet?
- (a)OSPF implements Bellman-Ford algorithm to find shortest paths.
- (b)OSPF uses Dijkstra's shortest path algorithm to implement least-cost path routing.
- (c)OSPF is used as an inter-domain routing protocol.
- (d)OSPF implements hierarchical routing.
Consider the following three statements about link state and distance vector routing protocols for a large network with 500 network nodes and 4000 links. S1: The computational overhead in link state protocols is higher than in distance vector protocols. S2: A distance vector protocol (with split horizon) avoids persistent routing loops, but not a link state protocol. S3: After a topology change, a link state protocol will converge faster than a distance vector protocol. Which one of the following is correct about S1, S2, and S3?
- (a)S1, S2, and S3 are all true.
- (b)S1, S2, and S3 are all false.
- (c)S1 and S2 are true, but S3 is false.
- (d)S1 and S3 are true, but S2 is false COMPUTER NETWORK
Self-check
Question 1
How many copies of one LSP are transmitted in a network of routers and links?
Show answerHide
.
Question 2
Why do all routers get consistent routes in link state routing?
Show answerHide
They hold the same database and run the same deterministic algorithm on it.
Question 3
What is the next hop at A for destination D in the example?
Show answerHide
C (path A-C-D, cost ).
Revision card
One-screen revision
- Flood LSPs, build the full map, run Dijkstra, keep next hops.
- Flooding cost ; sequence numbers; OSPF.
- Faster convergence than distance vector; more state.
References
- ·Kurose, Ross, Computer Networking: A Top-Down Approach (8th edition), Chapter 5, Section 5.2.1 (The link-state routing algorithm) and Section 5.3 (OSPF)
- ·Tanenbaum, Wetherall, Computer Networks (5th edition), Chapter 5, Section 5.2.5 (Link state routing)
Verification
scripts/enum-checks/cn_route_check.py on 600 random connected graphs of 3 to 8 routers: Dijkstra (scripts/cn_route.py), Floyd-Warshall and Bellman-Ford agree for every source; forwarding tables built from the shortest path trees, followed hop by hop from every source to every destination with each router using its OWN table, always reach the destination along a loop-free path whose cost equals the shortest distance; flooding one link state packet (each router forwards the first copy on all links except the one it came from, later copies are ignored) transmits exactly 2E - (N - 1) copies and reaches every router. The Dijkstra graph of the page is the classical six-router example (A to E at distance 20 via A-C-F-E; D at 20 via C). MODEL: all routers have identical, correct maps; ties are broken by the order in which nodes are found (real OSPF may keep several equal-cost paths); no link failures are simulated during flooding. QUOTED, not verified here: the five steps of link state routing as listed by the textbooks (discover neighbours with hello packets, measure costs, build a link state packet, flood, compute), sequence numbers and age fields in the LSP, OSPF facts (areas, designated router, runs over IP with protocol number 89, cost based on bandwidth), and the comparison of message complexity of the two methods. Textbook chapter references are from memory. SECOND PASS (2026-11-02, done by the assistant, not a human check): every Self-check question was solved before the printed answer was read and all agreed; the definitions, worked examples, cheat box and traps were read claim by claim and the numbers re-derived by hand or by a small script (CRC remainders, binomial tail, checksums); long C programs were not re-read line by line (they are compiled and compared by npm run verify:c, and their printed outputs were checked against the prose). No defect found. Status raised to self-checked; verified needs a textbook or human check.
last verified: never
My notes (saved in this browser)