E ExamMaster

CS Core & Software Engineering · Computer Networks

How a Packet Finds a Path

Routes as next hops, distance-vector Bellman-Ford, count-to-infinity, and link-state Dijkstra.

The phone and the shop are on different networks, so an address is not enough. This lesson is the walk: a route is a next hop for a prefix, distance-vector routers believe neighbours, and link-state routers flood a map and run Dijkstra. The tea-page packet is forwarded one hop at a time.

  • CS Core & Software Engineering
  • Medium level
  • 4 concepts
  • 1 practice questions

1A route is a next hop, not an address

An IP address names a host. A route says what to do with a packet whose destination is not on this network. Meera's phone is 192.168.1.42/24. The shop is 203.0.113.10, which is not in 192.168.1.0/24. So the phone does not ARP for the shop. It sends the packet to its default gateway 192.168.1.1 — 'if the destination is not on my prefix, give it to this next hop.'

The home router looks in its routing table: a list of prefixes and next hops. One row says 203.0.113.0/28 via the ISP. The ISP has its own row toward the shop. Each hop only needs the next hop, not the whole path. Addressing named the two ends. Routing chooses the walk between them.

Figure. The phone never ARPs for the shop. Each box only knows the next hop toward 203.0.113.0/28.

How the tea-page packet leaves home

  1. Same prefix?Shop 203.0.113.10 is not in 192.168.1.0/24, so the phone will not ARP for the shop.
  2. Default gatewayThe phone sends the packet to 192.168.1.1, the next hop off the home network.
  3. Router rowThe home router matches 203.0.113.0/28 and forwards to the ISP. Each hop repeats.
Meera's phone is 192.168.1.42/24 and wants 203.0.113.10. What does it do first?
  1. ARP for 203.0.113.10 on the home Wi-Fi
  2. Send the packet to the default gateway 192.168.1.1
  3. Rewrite its own address to 203.0.113.10

203.0.113.10 is not in 192.168.1.0/24, so the phone sends to its gateway. ARP for the shop would only work if the shop were on the same LAN. Rewriting the phone's address is NAT, later, on the router.

2Distance vector and Bellman-Ford

A distance-vector router does not hold a map of the whole Internet. It holds a table of distances — estimated costs — to prefixes, and it hears those distances only from its neighbours. Bellman-Ford is the update rule: for destination y, router x sets D_x(y) = \min_v\{c(x,v)+D_v(y)\}. c(x,v) is the cost of the link from x to neighbour v. D_v(y) is what v claims y costs from v. x adds the link cost to each neighbour's claim and keeps the cheapest.

RIP is the classic protocol that speaks this way: tell your neighbours your whole distance table. The shop's packets reach Meera because some router on the path chose a neighbour with a smaller claimed cost, not because it ran a map of every link.

Figure. x only sees neighbor costs and each neighbor's advertised distance to y — not a full map. Here via v wins at cost 5.

How an update runs

  1. Hear neighborsEach neighbor v advertises its current D_v(y) for destination y.
  2. Add link costForm c(x,v) + D_v(y) for every neighbor v.
  3. Take the minStore the smallest sum as D_x(y) and the next hop that achieved it.

One Bellman-Ford update at x

Router x reaches destination y via two neighbors. Neighbor v: c(x,v)=2, D_v(y)=3. Neighbor w: c(x,w)=5, D_w(y)=1. What does x install for D_x(y)?

  • Cost via v = c(x,v) + D_v(y) = 2 + 35
  • Cost via w = c(x,w) + D_w(y) = 5 + 16
  • D_x(y) = min{5, 6}5 (next hop v)

Pro tip. The neighbor with the smaller advertised distance is not always best — here w advertises 1 but the link to w costs 5, so v wins.

Distance-vector routing updates distances using which style of equation?
  1. Dijkstra on a full topology map flooded by every router
  2. Bellman-Ford: min over neighbors of link cost plus neighbor's distance
  3. Only the hop count of the longest path

Distance vector is the distributed Bellman-Ford update from neighbors. Dijkstra on a flooded map is link state.

3Count-to-infinity and mitigations

Distance vector can lie to itself after a failure. Suppose the cheap path to the shop dies. A neighbour may still advertise an old, small cost that secretly depended on the dead link. The router believes the neighbour, raises its own cost a little, and advertises that. The neighbour believes it back. The numbers climb — count-to-infinity — while packets loop.

Split horizon (do not advertise a route back to the neighbour you learned it from) and poison reverse (advertise that route as infinite to that neighbour) shrink the problem. They do not erase every loop. Link-state routing avoids this pattern by flooding the links and computing on a full map instead of trusting a neighbour's distance.

Figure. Distance-vector loops when a neighbour's stale route is trusted after a link fails — metric climbs toward infinity.

How the failure mode appears

  1. Link breaksThe true path to y is gone, but a neighbor still advertises a finite distance.
  2. Believe the neighborYou adopt that distance plus one hop — now you are part of the loop.
  3. MitigateSplit horizon / poison reverse stop advertising the route back toward the learner that fed it.
Which routing family is classically associated with the count-to-infinity problem?
  1. Link state (e.g. OSPF with Dijkstra)
  2. Distance vector (e.g. RIP with Bellman-Ford)
  3. Neither — only circuit switching counts to infinity

Count-to-infinity is the classic distance-vector failure mode with stale neighbor distances. Link state floods topology and recomputes locally, avoiding that loop pattern.

Notes

  • A route is a next hop for a prefix, not another name for an IP address.
  • Distance vector (Bellman-Ford, RIP) shares distance tables with neighbours and can count to infinity.
  • Link state (Dijkstra, OSPF) floods link costs so each router computes on a full map.

Formulas

  • D_x(y)=\min_v\{c(x,v)+D_v(y)\}.
  • Dijkstra shortest path with a heap is O(E\log V).

Exam traps & shortcuts

  • Different prefix → send to the default gateway; do not ARP for a remote host.
  • Distance vector: tell neighbours about the world. Link state: tell the world about your neighbours.

Reference tables

Who you tell, what you compute, and what breaks — the two ways a router learns a path.

Distance vector vs link state
PropertyDistance vectorLink state
What you advertiseWhole distance table to neighborsOwn link costs to everyone (flood)
AlgorithmBellman-FordDijkstra on local map
Classic protocolRIPOSPF
Failure modeCount-to-infinityFaster reconvergence; no DV loop pattern
SloganTell neighbors about the worldTell the world about your neighbors

Recap

The shop is not on 192.168.1.0/24, so the packet needs a next hop.

Route
Address names the end. Route names the next hop for a prefix. Phone sends to 192.168.1.1.
Distance vector
D_x(y)=\min_v\{c(x,v)+D_v(y)\}. RIP. Can count to infinity.
Link state
Flood links, run Dijkstra. OSPF. A→B→C cost 3 beats direct 4.

Practise How a Packet Finds a Path

Reading is free and needs no account. Practice, mocks and progress live in the app.

  • 1 exam-style questions on this topic, with explanations
  • A 3-question practice set that ends the chapter
  • Timed mocks scored with the real marking scheme
  • Readiness tracked per topic, kept on your device
Continue with Google — freeNo card, no trial. Works offline once installed.