Skip to content
GATEiit

GATE CSE · Computer Networks

Distance vector and link state routing

How routers build forwarding tables: flooding, distance vector routing with the Bellman-Ford update and its count-to-infinity problem, and link state routing with LSP flooding and Dijkstra, compared side by side.

Before you start

This topic comes before: IPv4: fragmentation, CIDR notation and network address translation (NAT)

Concept notes

1. Routing vs forwarding; flooding

Forwarding is the per-packet action inside one router: look up the destination in the forwarding table and send the packet out of the right interface. Routing is the network-wide process that builds those tables. A routing algorithm models the network as a weighted graph (routers are nodes, links have costs) and finds least-cost paths.

Flooding needs no table: a router sends every incoming packet out on every link except the one it arrived on. It always finds the shortest path (some copy takes it) and is very robust, but it creates a huge number of duplicates. Ways to limit it:

  • a hop count (TTL) in the packet, decremented at every hop; the packet is dropped at 0;
  • sequence numbers: each router remembers (source, sequence number) pairs it has seen and drops repeats;
  • selective flooding: send only on links going roughly the right way.

Flooding is used where robustness matters most, and to spread link state packets in link state routing.

Routing algorithms are either global (every router knows the whole topology: link state) or decentralised (each router knows only its neighbours and their reports: distance vector). Inside one organisation (an autonomous system), RIP uses distance vector and OSPF uses link state.

2. Distance vector routing

Each router x keeps a distance vector Dx(y): its current estimate of the least cost to every destination y, plus the next hop. It knows the cost c(x,v) to each directly connected neighbour v.

Periodically, and whenever its vector changes, each router sends its whole vector to its neighbours only. On receiving vectors, x applies the Bellman-Ford equation:

Dx(y)=min⁡v∈neighbours(x){c(x,v)+Dv(y)}

and records the minimising v as the next hop for y.

Working a GATE table:

  1. Write one column per neighbour: link cost to that neighbour plus that neighbour's reported distance.
  2. Take the minimum in each row. Ignore x's own old table: only the new neighbour vectors and current link costs matter.
  3. The distance from x to itself is 0.

The algorithm is iterative, asynchronous and distributed. If nothing changes it converges to the true least costs. Good news travels fast: a cost decrease spreads one hop per exchange. Bad news does not (next concept).

RIP uses hop count as cost, sends updates every 30 s, and treats 16 as infinity, so the longest usable path is 15 hops.

Example network for routing2637241ABCDEThick edges: shortest-path tree from A
Example network used in the worked examples. Thick edges form the least-cost tree from A.

3. Count to infinity and its fixes

Take a line A — B — C with every link cost 1. B reaches C at cost 1; A reaches C at cost 2 via B. Now the B–C link fails.

B no longer has a direct route, but A still advertises "C at 2". B does not know that A's route goes through B itself, so B sets DB(C)=1+2=3 via A. A then hears "3" from B and sets DA(C)=4. They keep bouncing, each time adding 2, until the cost reaches infinity (16 in RIP). Meanwhile packets for C loop between A and B. This is the count-to-infinity problem: bad news travels slowly.

Fixes:

  • Split horizon: never advertise a route back over the link it was learned from. A does not tell B about C at all, so B immediately sees C as unreachable.
  • Poisoned reverse: advertise it back, but with cost infinity. Same effect, stated explicitly.
  • Hold-down timers and triggered updates reduce the window for wrong information.

Split horizon and poisoned reverse solve loops between two routers but not loops of three or more routers.

Link state routing has no count-to-infinity problem because every router computes routes from the full map.

4. Link state routing

Each router:

  1. Discovers its neighbours (HELLO packets) and measures the cost of each link.
  2. Builds a link state packet (LSP): its identity, a sequence number, an age, and the list of its neighbours with costs.
  3. Floods the LSP to every router in the area. A router forwards an LSP only if its sequence number is newer than the one it has stored; the age field removes stale LSPs.
  4. With every router's LSP it has the complete topology, and runs Dijkstra's algorithm with itself as source to get least-cost paths and next hops.

Dijkstra by hand: keep a set of finalised nodes. Start with the source at 0. Repeatedly finalise the unfinalised node with the smallest tentative distance, then relax its edges: d(v)=min⁡(d(v),d(u)+c(u,v)). The next hop to v is the first edge on its path from the source. With n routers and E links, the cost is O(n2) simply, or O(Elog⁡n) with a heap.

OSPF is the standard link state protocol.

5. Distance vector vs link state

Distance vector Link state
What a router knows Neighbours' vectors only Whole topology
What it sends Its full table Its own links (LSP)
Sent to Neighbours only All routers (flooding)
Algorithm Bellman-Ford (distributed) Dijkstra (local)
Convergence Slow; count to infinity possible Fast; no count to infinity
Memory and CPU Low Higher (stores the map)
Effect of one bad router Wrong costs spread to everyone Mostly limited to its own links
Example RIP OSPF

Messages: in link state, flooding one router's LSP sends it over each link about once, so O(E) messages per LSP and O(nE) to flood all n LSPs. Distance vector talks only to neighbours but may need many rounds to converge.

Both find the same least-cost paths when they have converged and costs are positive. Exam questions test: which one uses neighbours only, which one floods, which one suffers count to infinity, and how to compute one update step of each.

Formulas to remember

Bellman-Ford (distance vector) updatev ranges over the neighbours of x
Dx(y)=min⁡v{c(x,v)+Dv(y)}
Dijkstra relaxation
d(v)←min⁡(d(v), d(u)+c(u,v))
Dijkstra running time
O(n2) (array),O(Elog⁡n) (heap)
Flooding on a complete graphNo duplicate suppression; the source sends n−1, each receiver forwards n−2
(n−1)+(n−1)(n−2) transmissions for hop count 2

Common mistakes

  • Keeping the router's old entry as a candidate in a distance vector update; only link cost plus neighbour reports count.
  • Forgetting to add the link cost to the neighbour's reported distance.
  • Giving the direct neighbour as next hop even when a cheaper path leaves through a different neighbour.
  • Saying link state sends the routing table to neighbours; it floods each router's own link costs to all routers.
  • Believing split horizon removes count to infinity in all cases; loops of three or more routers can still count up.
  • Taking 16 as a valid RIP distance; it means unreachable.

Worked examples

Try each step yourself, then reveal the working.

Example 1: Dijkstra from A

numerical

In the network shown (A–B 2, A–C 6, B–C 3, B–D 7, C–D 2, C–E 4, D–E 1), find the least cost from A to every router and A's next hop for each.

  1. Step 1: Initialise and finalise the source.

    Try it on paper first.

Example 2: One distance vector update

numerical

Router X has neighbours A (link cost 3), B (cost 1) and C (cost 6). It receives these vectors for destinations P, Q, R: from A (4, 7, 2), from B (8, 3, 6), from C (2, 2, 9). Find X's new distances and next hops.

  1. Step 1: Destination P: add link cost to each neighbour's report.

    Try it on paper first.

Example 3: Watching count to infinity

conceptual

Routers A — B — C, all links cost 1, running plain distance vector. The B–C link fails. Describe the first few updates for destination C, and say what split horizon changes.

  1. Step 1: What does B have just after the failure?

    Try it on paper first.

Previous year questions

5 official GATE CSE questions on this topic, newest first.

Practise these 5 PYQs →

Topic test

10 questions: up to 4 official PYQs and original practice questions, with GATE marking (MCQ wrong answers lose marks). Score 60% or more to pass. A new set is drawn each time.

Mark as mastered

Loading your progress…

My revision notes

Notes written by the GATEiit team against the official GATE CSE syllabus; being checked by a reviewer. Updated 2026-11-21. Spotted a mistake? Use Report an issue on any question, or contact us.