This project implements Distance Vector Routing (DVR) and Link State Routing (LSR) algorithms in C++, reading an adjacency‑matrix from a file and printing per‑node routing tables. It demonstrates how routers compute optimal paths via iterative table exchanges (DVR) and Dijkstra’s algorithm (LSR).
-
Distance Vector Routing (DVR):
- Initializes each node’s table with direct link metrics
- Iteratively exchanges tables with neighbors until convergence
- Computes and prints final “Dest Metric Next Hop” table for each node
-
Link State Routing (LSR):
- Reads full network topology at every node
- Runs Dijkstra’s algorithm per node to find shortest paths
- Prints “Dest Metric Next Hop” table for each source router
- Dynamic Updates:
- No support for link cost changes after convergence
- Loop Prevention Techniques:
- Basic DVR without split‐horizon or poison‐reverse
- Real Networking Stack:
- Pure simulation; does not open sockets or send real packets
- Simple square matrix format allows arbitrary cost metrics
- Zero ⇒ no link (converted internally to
INF
for non‑diagonal entries)
- Uniform table heading “Metric” used in both DVR and LSR for clarity
- DVR: repeat until no distance updates in a full pass
- LSR: single invocation of Dijkstra’s algorithm per source
-
readGraphFromFile(filename)
- Parses first line as
n
, then readsn×n
matrix - Converts zeros off‑diagonal to
INF = 9999
- Parses first line as
-
simulateDVR(graph)
dist = graph
;nextHop[i][j] = j
if direct link- Triple‑nested loops to relax via all intermediate
k
until no change - Calls
printDVRTable(node, dist, nextHop)
for each node
-
simulateLSR(graph)
- For each
src
: run Dijkstra withdist[src]=0
,prev[]
array - Calls
printLSRTable(src, dist, prev)
for each source node
- For each
-
printDVRTable(...)
/printLSRTable(...)
- Formats “Dest Metric Next Hop” rows, with “–” for self or unreachable
- Compile
make
- Run
./routing_sim input.txt
- Observe
- First, all DVR tables appear under
--- Distance Vector Routing Simulation ---
- Then, all LSR tables under
--- Link State Routing Simulation ---
- First, all DVR tables appear under
- Language: C++
- Infinite Cost: Represented by
const int INF = 9999
- Data Structures:
vector<vector<int>> dist, nextHop
for DVRvector<int> dist, prev
;vector<bool> visited
for LSR
- Algorithm Complexity:
- DVR: O(n³) per iteration, converges in ≤n iterations
- LSR: O(n²) per source (simple array‑based Dijkstra)
👤 Palagiri Tousif Ahamad (220744): 100% Contribution
- Kurose & Ross, Computer Networking: A Top-Down Approach
- RFC 2453: RIP Version 2 (Distance Vector Example)
- Dijkstra’s Original Paper, 1959