Link-State Routing and Dijkstra's Algorithm
Routing Algorithms
Routers forward packets using routing tables, and routing tables are produced by various algorithms. Routing algorithms are divided into static and dynamic routing algorithms.
In a static (non-adaptive) routing algorithm, the network administrator configures routing information manually. When the network topology or link states change, the static routes in the routing tables must be modified by hand. Such an algorithm cannot adapt to network changes in time, so it is used only in simple, small networks.
A dynamic (adaptive) routing algorithm is an automated routing algorithm that adapts automatically to changes in the network state and the routing tables. Its routing information is continually updated at regular intervals to obtain the best routes at all times.
Routing algorithms are usually studied on a weighted graph : the nodes are routers, the edges are links, and each edge has a cost that may represent link length, delay, or monetary cost. A path's cost is the sum of the costs of its edges, and routing aims to find the least-cost path between a source and a destination.
Depending on what each node knows, dynamic algorithms fall into two groups. A global algorithm requires every node to know the complete topology and every link cost. In a decentralized algorithm, each node knows only the costs of links to its direct neighbors and gradually computes least-cost paths by exchanging information with them. The link-state algorithm below is global; the distance-vector algorithm in Section 4.9 is decentralized.
Link-State Routing
A link-state algorithm is a global routing algorithm: all network topology information is known, and Dijkstra's algorithm gives the shortest paths from the source to every node.
To give every node the complete topology, each router places the costs of all its directly attached links in a link-state advertisement (LSA) and floods it through the network. When a router receives an LSA it has not seen, it stores it in its link-state database and forwards it to every neighbor except the one it came from; duplicate copies are discarded. LSAs carry sequence numbers, and an LSA with a higher sequence number replaces an older one. When flooding is complete, every router holds the same network map.
Flood link-state advertisements until every map agrees
Unlock the complete interactive lab, deeper explanations, and curated reference answers.
KNOWLEDGE QUIZ
Dijkstra's Algorithm
With source node , the algorithm uses this notation: is the least cost from to known in the current iteration; is the node before on that path; and is the set of nodes whose least-cost paths are definitively known.
Initialization:
N' = {u}
for all nodes v:
if v is a neighbor of u: D(v) = c(u, v)
else: D(v) = ∞
Loop:
find w not in N' such that D(w) is a minimum; add w to N'
for each neighbor v of w not in N':
D(v) = min(D(v), D(w) + c(w, v))
until N' contains all nodesEach iteration adds one node to and can only lower the costs of its neighbors:
The table shows the computation with source on the network used in the lab (ties are broken alphabetically):
| Step | N' | D(v), p(v) | D(w), p(w) | D(x), p(x) | D(y), p(y) | D(z), p(z) |
|---|---|---|---|---|---|---|
| 0 | u | 2, u | 5, u | 1, u | ∞ | ∞ |
| 1 | ux | 2, u | 4, x | 2, x | ∞ | |
| 2 | uxv | 4, x | 2, x | ∞ | ||
| 3 | uxvy | 3, y | 4, y | |||
| 4 | uxvyw | 4, y | ||||
| 5 | uxvywz |
When the algorithm terminates, each node has its predecessor along its least-cost path from the source. Each predecessor in turn has its own predecessor, and in this way the complete path from the source to every destination can be constructed.
For example, 's predecessor is , 's is , and 's is , so the least-cost path from to is with cost 4. Keeping only the first hop of each path gives 's forwarding table: packets for use link , and packets for , , , and all use link .
For nodes, a plain implementation scans every node outside in each iteration, for total; a heap (priority queue) lowers this to , where is the number of links.
If link costs depend on the traffic carried, link-state routing can oscillate: all routers move traffic onto the currently cheap path at the same time, congesting it, and then all move away again in the next round. Having routers send LSAs at randomized times mitigates this.
Run Dijkstra yourself: pick the next node
Unlock the complete interactive lab, deeper explanations, and curated reference answers.
KNOWLEDGE QUIZ
Build Dijkstra's table and A's forwarding table
Run Dijkstra's algorithm from source A on the network below. Write the table of N', D(·), and p(·) for each step, the least-cost path and cost to every destination, and A's forwarding table.
Implement Dijkstra with a priority queue in Python
Store the network below as a Python dictionary of dictionaries. Implement Dijkstra's algorithm with heapq, then print, for each destination in alphabetical order, its cost, the path, and A's next hop.