G27
Self-checkedTier 1 7 min readcn.routing-link-state

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):

  1. Discover the neighbours by sending hello packets on each link and learning their identities.
  2. Measure the cost of each link (delay, bandwidth based, or a configured number).
  3. 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.
  4. 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.
  5. 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
routerdistance from Aprevious routerstatus
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.

0 / 6
computed by script: fragments are cut and reassembled, routing tables are computed round by round, flooding is simulated. python3 scripts/gen-cn3-traces.py

Router A holds the map of six routers with the link costs A-B 77, A-C 99, A-F 1414, B-C 1010, B-D 1515, C-D 1111, C-F 22, D-E 66, E-F 99. Dijkstra settles routers in order of distance: B (77), C (99), then F (1111, reached through C: 9+29 + 2, better than the direct 1414), D (2020 through C: 9+119 + 11, better than 2222 through B) and E (2020 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
destinationcostnext hoppath
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.

0 / 5
computed by script: fragments are cut and reassembled, routing tables are computed round by round, flooding is simulated. python3 scripts/gen-cn3-traces.py

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
origincopies transmittedorder 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.

0 / 7
computed by script: fragments are cut and reassembled, routing tables are computed round by round, flooding is simulated. python3 scripts/gen-cn3-traces.py

The network has N=6N = 6 routers and E=9E = 9 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

deg⁡(origin)+∑v≠origin(deg⁡(v)−1)  =  2E−(N−1),\deg(\text{origin}) + \sum_{v \ne \text{origin}} (\deg(v) - 1) \;=\; 2E - (N - 1),

here 2×9−5=132 \times 9 - 5 = 13 per LSP and 6×13=786 \times 13 = 78 in all if every router floods its own LSP. The formula counts every link twice, once in each direction, minus the N−1N - 1 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 vectorlink state
a router knowsits neighbours' vectors (costs to all destinations)the whole map
information sentits vector, to neighbours onlyits own links, to all routers (flooding)
algorithmBellman-Ford, distributedDijkstra, local
convergenceslow when bad news, count to infinityfast
loops during convergencepossibleonly briefly, from different maps
memory and computingsmalllarger (O(N+E)O(N + E) map and Dijkstra)
protocolRIPOSPF

(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

Easy

A network with 55 routers and 77 links: one LSP is transmitted 2×7−(5−1)=102 \times 7 - (5 - 1) = 10 times. If each of the 55 routers floods once, 5050 transmissions.

EX 2Reading the shortest path tree

Medium

From the Dijkstra table of router A: previous(F) == C, previous(C) == A, so the path to F is A-C-F with cost 1111 and the next hop is C. Router C, which computes its own tree, has F itself as the next hop for F (cost 22): each router has its own table, built from the same map.

EX 3A link cost changes

Medium

The cost of C-F rises from 22 to 2020. 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 (1414), and to E the path A-F-E costs 14+9=2314 + 9 = 23 against A-C-D-E 9+11+6=269 + 11 + 6 = 26, 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 NN routers and EE links costs 2E−(N−1)2E - (N - 1) 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

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

GATE 2025 · MCQQ11 · page 548 of the book
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
GATE 2023 · MSQ · 1 markQ24 · page 551 of the book
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.
GATE 2014 · MCQQ62 · page 557 of the book
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 88 routers and 1212 links?

Show answer

2×12−7=172 \times 12 - 7 = 17.

Question 2

Why do all routers get consistent routes in link state routing?

Show answer

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 answer

C (path A-C-D, cost 2020).

Revision card

One-screen revision

  • Flood LSPs, build the full map, run Dijkstra, keep next hops.
  • Flooding cost 2E−(N−1)2E - (N - 1); 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