Skip to content
Published on

[Computer Networking] 13. Routing Algorithms: Link-State and Distance-Vector

Authors

Routing algorithms determine the optimal path from a sending host to a receiving host. The key is to model the network as a graph and compute the least-cost path between nodes.

In this post, we cover two representative routing algorithms: the Link-State (LS) algorithm and the Distance-Vector (DV) algorithm, analyzing each one's strengths, weaknesses, and potential issues.


1. Graph Model of a Network

A network is modeled as a weighted graph consisting of nodes (routers) and edges (links).

Network Graph Example
======================

        2
  (u) -------> (v)
  |  \          |
 1|   \5        |3
  |    \        |
  v     v       v
 (x)---(w)---->(y)---->(z)
    3      1        2

c(u,v) = 2, c(u,x) = 1, c(u,w) = 5
c(v,y) = 3, c(x,w) = 3, c(w,y) = 1
c(y,z) = 2

Goal: Find the least-cost path from a source node to all other nodes.


2. Classification of Routing Algorithms

Routing Algorithm Classification
==================================

1. By information scope:
   - Global: Knows all node information, then computes --> Link-State
   - Decentralized: Iterative computation using only neighbor info --> Distance-Vector

2. By operation mode:
   - Static: Routes rarely change
   - Dynamic: Periodically recalculated as network changes

3. By load sensitivity:
   - Load-Sensitive: Reflects link congestion in cost
   - Load-Insensitive: Current Internet routing approach

3.1 Basic Principle

The Link-State algorithm operates based on complete topology information of the network. Each node broadcasts its link state information to the entire network, and once all nodes have the same information, they compute shortest paths using Dijkstra's algorithm.

3.2 Algorithm Operation

Dijkstra's Algorithm
======================

Initialization:
  N' = source node u
  D(v) = c(u,v) (cost of directly connected neighbors)
         infinity (nodes not directly connected)

Loop:
  1. Select node w not in N' with minimum D(w)
  2. Add w to N'
  3. For each neighbor v of w:
     D(v) = min(D(v), D(w) + c(w,v))
  4. Repeat until all nodes are in N'

3.3 Execution Example

Running Dijkstra's algorithm from node u on the graph above:

Dijkstra Execution (Source: u)
================================

Step | N'        | D(v) | D(w) | D(x) | D(y) | D(z)
-----+-----------+------+------+------+------+------
  0  | u         |  2   |  5   |  1   |  inf |  inf
  1  | u,x       |  2   |  4   |  1   |  inf |  inf
  2  | u,x,v     |  2   |  4   |  1   |  5   |  inf
  3  | u,x,v,w   |  2   |  4   |  1   |  5   |  inf
  4  | u,x,v,w,y |  2   |  4   |  1   |  5   |  7
  5  | all nodes  |  2   |  4   |  1   |  5   |  7

Shortest path tree:
  u -> v: cost 2 (direct)
  u -> x: cost 1 (direct)
  u -> w: cost 4 (u -> x -> w)
  u -> y: cost 5 (u -> v -> y or u -> x -> w -> y)
  u -> z: cost 7 (u -> ... -> y -> z)

3.4 Time Complexity

The basic implementation has O(n^2) time complexity, which can be improved to O(n log n) using a priority queue (heap).

3.5 Oscillation Problem

When link costs change based on traffic load, routing can oscillate.

LS Oscillation Problem Example
================================

Time 1: Most traffic flows via A -> B path
  --> A -> B link cost increases

Time 2: All nodes switch to A -> C -> D -> B path
  --> A -> C link cost increases

Time 3: Switch back to A -> B path (oscillation repeats)

Solution: Randomize routing update timing

4. Distance-Vector Algorithm (Bellman-Ford)

4.1 Basic Principle

The Distance-Vector algorithm operates in a decentralized manner. Each node only sends its distance vector (estimated costs to all destinations) to its neighbors, and updates its own distance vector based on neighbors' information.

4.2 Bellman-Ford Equation

The minimum cost d(x,y) from node x to destination y is computed as follows:

Bellman-Ford Equation
======================

d(x, y) = min { c(x, v) + d(v, y) }
           v

where v ranges over all neighbors of x

Meaning: The minimum cost from x to y is
  = cost from x to neighbor v + minimum cost from v to y
  Travel via the neighbor v that minimizes this value

4.3 Algorithm Operation

DV Algorithm Operation
========================

Each node x maintains:
  - c(x,v): link cost to neighbor v
  - Dx: distance vector of x (estimated cost to all destinations)
  - Dv: distance vector of each neighbor v

Operation:
  1. Initialize: link cost for directly connected neighbors, infinity for the rest
  2. When receiving a distance vector from a neighbor:
     Dx(y) = min { c(x,v) + Dv(y) } (for all neighbors v)
  3. If own distance vector changed, send to all neighbors
  4. Repeat until no changes

4.4 Execution Example

DV Algorithm Execution (3-node example)
=========================================

Topology:
  x ---7--- y
  |       / |
  1     /   1
  |   2     |
  z --------+

Initial distance vectors:
  Dx = [0, 7, 1]  (x->x, x->y, x->z)
  Dy = [7, 0, 1]  (y->x, y->y, y->z)
  Dz = [1, 1, 0]  (z->x, z->y, z->z)

Step 1: Each node receives neighbors' DV and updates

  Node x update:
    Dx(y) = min(c(x,y)+Dy(y), c(x,z)+Dz(y))
          = min(7+0, 1+1) = 2
    Dx(z) = min(c(x,y)+Dy(z), c(x,z)+Dz(z))
          = min(7+1, 1+0) = 1

  Updated Dx = [0, 2, 1]  (x->y changed from 7 to 2)

Step 2: Propagate changed DV to neighbors, terminate when no more changes

5. Count-to-Infinity Problem

5.1 Problem Scenario

The biggest problem with the DV algorithm is that bad news travels slowly -- convergence is very slow when link costs increase.

Count-to-Infinity Example
===========================

Topology: x ---4--- y ---1--- z

Initial distance vectors:
  Dy(x) = 4, Dz(x) = 5 (z -> y -> x)

Link change: c(x,y) = 4 --> 60

y update: Dy(x) = min(60, 1+Dz(x)) = min(60, 1+5) = 6
  (thinks going via z costs 6, but z also goes via y!)

z update: Dz(x) = min(1+Dy(x)) = 1+6 = 7

y update: Dy(x) = min(60, 1+7) = 8

z update: Dz(x) = 1+8 = 9

... keeps incrementing by 1, converges only after 44 iterations!

5.2 Solution: Poisoned Reverse

Poisoned Reverse is a technique to prevent routing loops. If z reaches x via y, then z tells y that its distance to x is infinity.

Poisoned Reverse Operation
============================

z reaches x via y (z -> y -> x)

Information z tells y:
  Dz(x) = infinity  (actually 5, but reports infinity to y)

Reason: Since z goes via y, prevent loop where y goes via z

When link change c(x,y) = 60 occurs:
  y update: Dy(x) = min(60, 1+infinity) = 60
  y sends Dy(x)=60 to z
  z update: Dz(x) = min(1+60) = 61

  --> Converges to correct value immediately!

5.3 Limitations of Poisoned Reverse

Poisoned Reverse can only prevent loops between two nodes. It is ineffective for loops involving three or more nodes.


6. Comparing LS and DV Algorithms

Link-State vs Distance-Vector
================================

Item               | Link-State (LS)       | Distance-Vector (DV)
-------------------+-----------------------+------------------------
Information Scope  | Full network topology | Only neighbor DVs
Message Complexity | O(N x E) messages     | Variable until convergence
Convergence Speed  | O(N^2) fast           | Slow (loops possible)
Robustness         | Independent computation| Errors can propagate
                   | (limited error impact) | (wrong DV propagation)
Memory Requirement | Store full topology   | Store only neighbor DVs
Practical Use      | OSPF, IS-IS           | RIP, BGP (path vector)

6.1 Message Complexity

  • LS: Each node broadcasts link state to all nodes. O(N x E) messages for N nodes and E links
  • DV: Exchanged only between neighbors, but total messages until convergence is uncertain

6.2 Convergence Speed

  • LS: Converges in O(N^2) or O(N log N)
  • DV: Convergence speed is uncertain, count-to-infinity problem possible

6.3 Robustness

  • LS: Even if one node advertises incorrect link costs, other nodes compute shortest paths independently, limiting the impact
  • DV: An incorrect distance vector from one node can propagate across the entire network

7. Practical Application of Routing Algorithms

Protocols and Algorithms in Practice
======================================

Routing Protocol  | Algorithm      | Scope
------------------+----------------+------------------
RIP               | DV             | Small AS interior
OSPF              | LS             | Large AS interior
IS-IS             | LS             | ISP networks
BGP               | Path Vector    | Inter-AS (entire Internet)
EIGRP             | Enhanced DV    | Cisco networks

8. Key Summary

ConceptKey Points
Link-StateBased on full topology, uses Dijkstra's algorithm
Distance-VectorUses only neighbor info, based on Bellman-Ford
Bellman-Ford Eq.d(x,y) = min over v of c(x,v) + d(v,y)
Count-to-infinityDV convergence delay when link cost increases
Poisoned ReverseReports infinity cost to transit node to prevent loops
LS OscillationRoute oscillation with load-sensitive costs, solved by randomization

In the next post, we will see how these routing algorithms are applied in the real Internet through OSPF and BGP protocols.


References

  • James F. Kurose, Keith W. Ross, "Computer Networking: A Top-Down Approach", 6th Edition, Chapter 4
  • E. W. Dijkstra, "A Note on Two Problems in Connexion with Graphs", 1959
  • R. Bellman, "On a Routing Problem", 1958