The Network Layer: Routing

a routing algorithm

Imagine you are planning a road trip across a country with thousands of towns and roads. Before you drive anywhere, you need a map and a way to decide which roads to take to reach each destination cheaply. A routing algorithm is exactly that planning step for a network: it is the procedure routers use to figure out good paths from one part of the network to another, before any data actually travels.

It helps to separate two jobs that sound similar but are different. Forwarding is the fast, local action a router takes for each arriving packet: look at the destination address, consult a table, and shove the packet out the right port. Routing is the slower, network-wide thinking that fills in that table in the first place — computing which next hop leads toward each destination. A routing algorithm is the brain (the control plane); forwarding is the reflex (the data plane). The algorithm runs occasionally, when links change; forwarding happens for every single packet.

Routing algorithms take a description of the network — usually a graph of routers, links, and link costs — and produce, for each router, a least-cost path to every destination. The two classic families are link-state (every router learns the whole map and computes paths itself, using Dijkstra's algorithm) and distance-vector (routers learn only by gossiping distance estimates with their neighbors, the Bellman-Ford idea). Real protocols like OSPF and RIP are concrete implementations of these ideas.

An honest caveat: 'good' paths are not always literally shortest. Operators assign link costs to reflect bandwidth, money, or policy, so the algorithm optimizes whatever those numbers say — and inside one network that is usually about efficiency, while routing between networks (BGP) is dominated by business policy rather than pure shortest path.

A network has routers A, B, C, D. Direct links: A-B cost 1, B-C cost 1, A-C cost 5, C-D cost 1. A routing algorithm computes that A's cheapest path to D is A -> B -> C -> D (cost 3), not A -> C -> D (cost 6), even though A-C is a single direct link.

Fewer hops is not the same as lower cost — the algorithm minimizes total link cost, not hop count.

Routing computes paths; forwarding follows them. People often blur the two, but they run on different timescales — paths are recomputed only when topology changes, while forwarding happens per packet.

Also called
route computationpath selection algorithm選路演算法