Routing Examples
In computer networks, routing algorithms play a critical role in determining the best path for data packets to travel from a source to a destination. Here we will elaborate on two widely used routing algorithms: Distance Vector (Bellman-Ford) and Link-State (Dijkstra’s Algorithm). These methods differ in how they manage network topology information and how they calculate the best routes.
1. Distance Vector Routing (Bellman-Ford Algorithm)
Distance Vector Routing is a decentralized approach where each router only has information about its direct neighbors. Over time, routers exchange this information, building up a complete view of the network’s best paths.
Key Concepts:
- Distance Vector: A table maintained by each router that contains the distance to every destination.
- Next-Hop: In addition to the distance, each router stores the next-hop neighbor to forward packets to, for each destination.
Bellman-Ford Algorithm:
The algorithm is based on the idea that the shortest path from node to node can be recursively determined if node knows the shortest path from one of its neighbors to , plus the direct cost between and .
- The formula for this recursive calculation is:
Where:
- is the distance from node to destination ,
- is the link cost from node to its neighbor ,
- is the distance from to , as known by neighbor .
Example:
Consider the following network with five nodes and the following link costs:
A — 7 — B
| |
1 2
| |
E — 1 — D
| |
8 3
| |
C —————
-
Initial Distance Values:
- Node A:
- (distance to itself),
- (direct link),
- (not connected directly),
- (not connected directly),
- (direct link).
- Node A:
-
After Iteration 1:
- Node A exchanges distance vectors with its neighbors (B, E).
- A learns that and updates via E (since ).
- Updated distance vector for A: .
-
After Iteration 2:
- Further exchanges result in an update of to 8, as A learns from E that .
- Updated distance vector for A: .
-
Convergence:
- After further iterations, the algorithm converges, and the final shortest paths are calculated, such as , , and so on.
Problems:
- Count-to-Infinity Problem: When a link fails, incorrect distance values may propagate slowly, leading to incorrect paths being used for a long time.
- Poisoned Reverse: A method to prevent loops by marking routes as “infinite” to neighbors, signaling that the route should not be used.
2. Link-State Routing (Dijkstra’s Algorithm)
In Link-State Routing, each router has a complete view of the network’s topology. This is achieved by routers exchanging link-state advertisements (LSAs), which describe the status of their links. Once all routers have this information, they each compute the shortest path to every destination independently using Dijkstra’s algorithm.
Key Concepts:
- Link-State Database: Each router stores a map of the entire network, including the status (cost, availability) of each link.
- Shortest Path Tree (SPT): Using Dijkstra’s algorithm, each router computes the shortest path to every other router, which forms a tree structure rooted at itself.
Dijkstra’s Algorithm:
The algorithm finds the shortest path from a source node to every other node in the network. It works by progressively expanding the shortest known path from the source node, updating distances to other nodes along the way.
Steps:
- Initialize: Set the distance to the source node to 0 and all other nodes to infinity. Mark all nodes as unvisited.
- Visit Neighbors: Start at the source node. For each unvisited neighbor, calculate the tentative distance (current distance + link cost).
- Update: If the new tentative distance is smaller than the previously known distance, update the distance.
- Move to Next Node: Select the unvisited node with the smallest tentative distance, mark it as visited, and repeat the process until all nodes are visited.
Example:
Using the same network as before:
A — 7 — B
| |
1 2
| |
E — 1 — D
| |
8 3
| |
C —————
-
Initialization:
- Start from node A. Initialize distances: .
- Set , , and .
-
Step 1:
- Visit node E (the neighbor with the smallest tentative distance, 1).
- Update distances: .
-
Step 2:
- Visit node D (tentative distance 3).
- Update distances: .
-
Step 3:
- Visit node C (tentative distance 6).
- Update distances: No further updates are needed since C has no new neighbors.
-
Final Shortest Paths:
- From A: D(A,E) = 1 D(A,D) = 3 D(A,C) = 6 D(A,B) = 6$.
Advantages:
- Fast Convergence: Since all routers have a consistent view of the network, routes can be recalculated quickly when the topology changes.
- Optimal Path: The algorithm guarantees that the computed paths are the shortest in terms of cost.
Drawbacks:
- High Resource Usage: Requires more memory and processing power, as each router must maintain a full map of the network.
- Frequent Updates: Network-wide updates may consume significant bandwidth, especially in large and dynamic networks.