Implementation of Distance Vector Routing Algorithm
This program implements the distance vector routing algorithm using Bellman-Ford equation to calculate the shortest paths between all network nodes and display routing tables for each router.
Algorithms
Step 1: Read the number of nodes n.
Step 2: Read the distance matrix dm[n][n] which represents the direct cost between each pair of nodes.
Step 3: Initialize routing table for each router:
- Set
rt[i].dist[j] = dm[i][j]for all i,j - Set
rt[i].next[j] = jfor all i,j - Set
dm[i][i] = 0(distance to self is zero)
Step 4: Perform Bellman-Ford relaxation for n-1 iterations:
- For
iter = 0ton-2 - For each router
i = 0ton-1 - For each destination
j = 0ton-1 - For each intermediate node
k = 0ton-1 - If
rt[i].dist[j] > rt[i].dist[k] + rt[k].dist[j]then- Update
rt[i].dist[j] = rt[i].dist[k] + rt[k].dist[j] - Update
rt[i].next[j] = rt[i].next[k]
- Update
Step 5: Display the final routing table for each router showing destination node, next hop, and distance.