Add cn/dvr: Distance Vector Routing simulator with count-to-infinity demos and captured output
Co-Authored-By: Claude Sonnet 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_017ic4b6V3xQR5XUmTbjaYAK
This commit is contained in:
@@ -0,0 +1 @@
|
||||
build/
|
||||
@@ -0,0 +1,9 @@
|
||||
# Distance Vector Routing (DVR) simulator in C++
|
||||
|
||||
Companion code for the post <https://ankurm.com/implementation-of-distance-vector-routing-dvr-algorithm-in-c/>.
|
||||
Everything else (explanation, walkthroughs, count-to-infinity) lives in that post.
|
||||
|
||||
./scripts/run-all.sh # builds and regenerates every file in output/
|
||||
build/dvr --trace < input/four-node.txt
|
||||
|
||||
`dvr.cpp` is the simulator; `legacy/` holds the two older programs from this site, kept only so the post can show what they get wrong.
|
||||
+207
@@ -0,0 +1,207 @@
|
||||
// dvr.cpp - Distance Vector Routing (DVR) simulator.
|
||||
//
|
||||
// Every router keeps ONE table: for each destination, (distance, next hop).
|
||||
// Time moves in synchronous rounds. In each round every router reads the
|
||||
// tables its neighbours had at the END of the previous round and applies the
|
||||
// Bellman-Ford equation
|
||||
//
|
||||
// D_x(y) = min over neighbours v of [ c(x,v) + D_v(y) ]
|
||||
//
|
||||
// The next hop for y is the neighbour v that gave the minimum. The simulation
|
||||
// stops when a whole round changes nothing: that is convergence.
|
||||
//
|
||||
// Build: g++ -std=c++17 -Wall -Wextra -O2 -o build/dvr dvr.cpp
|
||||
// Run: build/dvr [--trace] [--watch X] [--poison] [--infinity N] < input/four-node.txt
|
||||
//
|
||||
// Input (whitespace separated, '#' starts a comment):
|
||||
// n number of routers, named A, B, C, ...
|
||||
// n*(n-1)/2 numbers link costs in the order A-B, A-C, ..., B-C, B-D, ...; -1 = no link
|
||||
// fail X Y (optional, repeatable) remove link X-Y, then re-converge
|
||||
// cost X Y c (optional, repeatable) change link X-Y to cost c, then re-converge
|
||||
|
||||
#include <algorithm>
|
||||
#include <cstdlib>
|
||||
#include <iomanip>
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
using namespace std;
|
||||
|
||||
static int INF = 16; // RIP-style "infinity": a distance >= INF means unreachable
|
||||
static bool trace = false; // print every router's full table after every round
|
||||
static bool poison = false; // split horizon with poison reverse
|
||||
static int watchDest = -1; // print one column (distance to this router) every round
|
||||
|
||||
struct Network {
|
||||
int n = 0;
|
||||
vector<vector<int>> cost; // cost[x][y] = direct link cost, -1 = no link, 0 on the diagonal
|
||||
vector<vector<int>> dist; // dist[x][y] = router x's current estimate to y
|
||||
vector<vector<int>> next; // next[x][y] = neighbour x forwards to for y, -1 = none/self
|
||||
};
|
||||
|
||||
static char name(int i) { return static_cast<char>('A' + i); }
|
||||
|
||||
static void initTables(Network& g) {
|
||||
g.dist.assign(g.n, vector<int>(g.n, INF));
|
||||
g.next.assign(g.n, vector<int>(g.n, -1));
|
||||
for (int x = 0; x < g.n; x++) {
|
||||
g.dist[x][x] = 0;
|
||||
for (int y = 0; y < g.n; y++)
|
||||
if (x != y && g.cost[x][y] >= 0) {
|
||||
g.dist[x][y] = min(g.cost[x][y], INF);
|
||||
g.next[x][y] = y;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void printTable(const Network& g, int x) {
|
||||
cout << name(x) << " Routing Table\n";
|
||||
cout << "Dest Dist Next hop\n";
|
||||
for (int y = 0; y < g.n; y++) {
|
||||
cout << name(y) << " ";
|
||||
if (g.dist[x][y] >= INF) cout << left << setw(6) << "INF" << "-\n";
|
||||
else {
|
||||
cout << left << setw(6) << g.dist[x][y];
|
||||
cout << (g.next[x][y] < 0 ? '-' : name(g.next[x][y])) << "\n";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void printAll(const Network& g) {
|
||||
for (int x = 0; x < g.n; x++) { printTable(g, x); if (x + 1 < g.n) cout << "\n"; }
|
||||
}
|
||||
|
||||
static void printWatch(const Network& g, int round) {
|
||||
cout << "round " << setw(2) << right << round << " | to " << name(watchDest) << ":";
|
||||
for (int x = 0; x < g.n; x++) {
|
||||
if (x == watchDest) continue;
|
||||
cout << " " << name(x) << "=";
|
||||
if (g.dist[x][watchDest] >= INF) cout << "INF";
|
||||
else cout << g.dist[x][watchDest] << "(" << name(g.next[x][watchDest]) << ")";
|
||||
}
|
||||
cout << "\n";
|
||||
}
|
||||
|
||||
// One synchronous round. Returns true if any entry changed.
|
||||
static bool exchangeRound(Network& g) {
|
||||
const auto snapDist = g.dist; // what neighbours advertised at the end of the last round
|
||||
const auto snapNext = g.next;
|
||||
bool changed = false;
|
||||
for (int x = 0; x < g.n; x++) {
|
||||
for (int y = 0; y < g.n; y++) {
|
||||
if (x == y) continue;
|
||||
int best = INF, hop = -1;
|
||||
for (int v = 0; v < g.n; v++) {
|
||||
if (v == x || g.cost[x][v] < 0) continue; // v must be a neighbour
|
||||
int advertised = snapDist[v][y];
|
||||
if (poison && snapNext[v][y] == x) advertised = INF; // poison reverse
|
||||
int cand = min(INF, g.cost[x][v] + advertised);
|
||||
// strict '<' keeps the lowest-lettered neighbour on a tie, unless the
|
||||
// current next hop ties, in which case we keep it (avoids route flapping)
|
||||
if (cand < best || (cand == best && cand < INF && v == snapNext[x][y])) { best = cand; hop = v; }
|
||||
}
|
||||
if (best != g.dist[x][y] || hop != g.next[x][y]) changed = true;
|
||||
g.dist[x][y] = best;
|
||||
g.next[x][y] = (best >= INF) ? -1 : hop;
|
||||
}
|
||||
}
|
||||
return changed;
|
||||
}
|
||||
|
||||
// Independent check: Floyd-Warshall on the current links, with the same INF cap.
|
||||
static bool matchesFloydWarshall(const Network& g) {
|
||||
vector<vector<int>> d(g.n, vector<int>(g.n, INF));
|
||||
for (int x = 0; x < g.n; x++)
|
||||
for (int y = 0; y < g.n; y++)
|
||||
d[x][y] = (x == y) ? 0 : (g.cost[x][y] >= 0 ? min(g.cost[x][y], INF) : INF);
|
||||
for (int k = 0; k < g.n; k++)
|
||||
for (int i = 0; i < g.n; i++)
|
||||
for (int j = 0; j < g.n; j++)
|
||||
d[i][j] = min(d[i][j], min(INF, d[i][k] + d[k][j]));
|
||||
for (int x = 0; x < g.n; x++)
|
||||
for (int y = 0; y < g.n; y++)
|
||||
if (d[x][y] != g.dist[x][y]) return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
static void converge(Network& g, const string& label) {
|
||||
cout << "== " << label << " ==\n";
|
||||
if (trace) { cout << "\n-- round 0 (direct links only) --\n"; printAll(g); cout << "\n"; }
|
||||
if (watchDest >= 0) printWatch(g, 0);
|
||||
int r = 0;
|
||||
const int maxRounds = 200;
|
||||
while (r < maxRounds) {
|
||||
bool changed = exchangeRound(g);
|
||||
if (!changed) break;
|
||||
r++;
|
||||
if (trace) { cout << "-- after round " << r << " --\n"; printAll(g); cout << "\n"; }
|
||||
if (watchDest >= 0) printWatch(g, r);
|
||||
}
|
||||
cout << (r >= maxRounds ? "stopped at the round limit\n" : "converged: round " + to_string(r + 1) + " changed nothing\n");
|
||||
cout << "rounds that changed something: " << r << "\n";
|
||||
cout << "check vs Floyd-Warshall: " << (matchesFloydWarshall(g) ? "match" : "MISMATCH") << "\n";
|
||||
if (!trace) { cout << "\n"; printAll(g); }
|
||||
}
|
||||
|
||||
static int routerIndex(const string& s, int n) {
|
||||
if (s.size() != 1 || s[0] < 'A' || s[0] >= 'A' + n) { cerr << "bad router name: " << s << "\n"; exit(2); }
|
||||
return s[0] - 'A';
|
||||
}
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
for (int i = 1; i < argc; i++) {
|
||||
string a = argv[i];
|
||||
if (a == "--trace") trace = true;
|
||||
else if (a == "--poison") poison = true;
|
||||
else if (a == "--infinity" && i + 1 < argc) INF = atoi(argv[++i]);
|
||||
else if (a == "--watch" && i + 1 < argc) watchDest = argv[++i][0] - 'A';
|
||||
else { cerr << "usage: dvr [--trace] [--watch X] [--poison] [--infinity N] < input\n"; return 2; }
|
||||
}
|
||||
|
||||
// read all of stdin, dropping '#' comments
|
||||
string all, line;
|
||||
while (getline(cin, line)) { all += line.substr(0, line.find('#')); all += '\n'; }
|
||||
istringstream in(all);
|
||||
|
||||
Network g;
|
||||
if (!(in >> g.n) || g.n < 2 || g.n > 26) { cerr << "need 2..26 routers\n"; return 2; }
|
||||
if (watchDest >= g.n) { cerr << "--watch router is outside the network\n"; return 2; }
|
||||
g.cost.assign(g.n, vector<int>(g.n, -1));
|
||||
for (int x = 0; x < g.n; x++) g.cost[x][x] = 0;
|
||||
for (int x = 0; x < g.n; x++)
|
||||
for (int y = x + 1; y < g.n; y++) {
|
||||
int c;
|
||||
if (!(in >> c)) { cerr << "missing link cost " << name(x) << "-" << name(y) << "\n"; return 2; }
|
||||
if (c >= 0) g.cost[x][y] = g.cost[y][x] = c;
|
||||
}
|
||||
|
||||
cout << "routers: " << g.n << ", infinity = " << INF << ", poison reverse = " << (poison ? "on" : "off") << "\nlinks:";
|
||||
for (int x = 0; x < g.n; x++)
|
||||
for (int y = x + 1; y < g.n; y++)
|
||||
if (g.cost[x][y] >= 0) cout << " " << name(x) << "-" << name(y) << "=" << g.cost[x][y];
|
||||
cout << "\n\n";
|
||||
|
||||
initTables(g);
|
||||
converge(g, "initial convergence");
|
||||
|
||||
string cmd;
|
||||
while (in >> cmd) {
|
||||
string a, b;
|
||||
if (cmd == "fail") {
|
||||
in >> a >> b;
|
||||
int x = routerIndex(a, g.n), y = routerIndex(b, g.n);
|
||||
g.cost[x][y] = g.cost[y][x] = -1;
|
||||
cout << "\n";
|
||||
converge(g, "link " + a + "-" + b + " fails");
|
||||
} else if (cmd == "cost") {
|
||||
int c; in >> a >> b >> c;
|
||||
int x = routerIndex(a, g.n), y = routerIndex(b, g.n);
|
||||
g.cost[x][y] = g.cost[y][x] = c;
|
||||
cout << "\n";
|
||||
converge(g, "link " + a + "-" + b + " cost becomes " + to_string(c));
|
||||
} else { cerr << "unknown command: " << cmd << "\n"; return 2; }
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
5
|
||||
1
|
||||
-1
|
||||
-1
|
||||
-1
|
||||
1
|
||||
-1
|
||||
-1
|
||||
1
|
||||
-1
|
||||
1
|
||||
@@ -0,0 +1,6 @@
|
||||
# A - B - C - D - E in a line, every link cost 1.
|
||||
5
|
||||
1 -1 -1 -1
|
||||
1 -1 -1
|
||||
1 -1
|
||||
1
|
||||
@@ -0,0 +1,5 @@
|
||||
# A - B - C in a line, every link cost 1, then the B-C link breaks.
|
||||
3
|
||||
1 -1 # A-B A-C
|
||||
1 # B-C
|
||||
fail B C
|
||||
@@ -0,0 +1,6 @@
|
||||
# Five routers, the 2015 post's example: A-B=5 A-C=2 A-D=3 B-C=4 B-E=3 C-E=4
|
||||
5
|
||||
5 2 3 -1 # A-B A-C A-D A-E
|
||||
4 -1 3 # B-C B-D B-E
|
||||
-1 4 # C-D C-E
|
||||
-1 # D-E
|
||||
@@ -0,0 +1,7 @@
|
||||
4
|
||||
1
|
||||
-1
|
||||
4
|
||||
2
|
||||
-1
|
||||
3
|
||||
@@ -0,0 +1,5 @@
|
||||
# Four routers. Links: A-B=1, A-D=4, B-C=2, C-D=3 (the example from the earlier post)
|
||||
4
|
||||
1 -1 4 # A-B A-C A-D
|
||||
2 -1 # B-C B-D
|
||||
3 # C-D
|
||||
@@ -0,0 +1,6 @@
|
||||
# A - B - C - D in a line; the middle link B-C breaks and the network splits in two.
|
||||
4
|
||||
1 -1 -1
|
||||
1 -1
|
||||
1
|
||||
fail B C
|
||||
@@ -0,0 +1,436 @@
|
||||
#include<iostream.h>
|
||||
#include<conio.h>
|
||||
|
||||
void main()
|
||||
{
|
||||
int graph[50][50];
|
||||
int i,j,k,t;
|
||||
int nn;
|
||||
|
||||
cout<<"\n Enter Number of Nodes:";
|
||||
cin>>nn;
|
||||
|
||||
/* Initialize graph*/
|
||||
for (i=0;i<nn;i++)
|
||||
{
|
||||
for(j=0;j<nn;j++)
|
||||
{
|
||||
graph[i][j]=-1;
|
||||
}
|
||||
}
|
||||
|
||||
/* Vertex names */
|
||||
char ch[7]={'A','B','C','D','E','F','G'};
|
||||
|
||||
/* Get input */
|
||||
for (i=0;i<nn;i++)
|
||||
{
|
||||
for(j=0;j<nn;j++)
|
||||
{
|
||||
if(i==j)
|
||||
{
|
||||
graph[i][j]=0;
|
||||
}
|
||||
if(graph[i][j]==-1)
|
||||
{
|
||||
cout<<"\n Enter Distance between "<<ch[i]<<" - "<<ch[j]<<" : ";
|
||||
cin>>t;
|
||||
graph[i][j]=graph[j][i]=t;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Initializing via */
|
||||
int via[50][50];
|
||||
for (i=0;i<nn;i++)
|
||||
{
|
||||
for(j=0;j<nn;j++)
|
||||
{
|
||||
via[i][j]=-1;
|
||||
}
|
||||
}
|
||||
|
||||
cout<<"\n After Initialization";
|
||||
/* Display table initialization */
|
||||
for (i=0;i<nn;i++)
|
||||
{
|
||||
cout<<"\n"<<ch[i]<<" Table";
|
||||
cout<<"\nNode\tDist\tVia";
|
||||
for(j=0;j<nn;j++)
|
||||
{
|
||||
cout<<"\n"<<ch[j]<<"\t"<<graph[i][j]<<"\t"<<via[i][j];
|
||||
}
|
||||
}
|
||||
|
||||
//sharing table
|
||||
int sh[50][50][50];
|
||||
for(i=0;i<nn;i++)
|
||||
{
|
||||
for(j=0;j<nn;j++)
|
||||
{
|
||||
for (k=0;k<nn;k++)
|
||||
{
|
||||
/* Check if edge is present or not*/
|
||||
if((graph[i][j]>-1)&&(graph[j][k]>-1))
|
||||
{
|
||||
sh[i][j][k]=graph[j][k]+graph[i][j];
|
||||
}
|
||||
else
|
||||
{
|
||||
sh[i][j][k]=-1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*displaying shared table */
|
||||
for(i=0;i<nn;i++)
|
||||
{
|
||||
cout<<"\n\n For "<<ch[i];
|
||||
for (j=0;j<nn;j++)
|
||||
{
|
||||
cout<<"\n From "<<ch[j];
|
||||
for(k=0;k<nn;k++)
|
||||
{
|
||||
cout<<"\n "<<ch[k]<<" "<<sh[i][j][k];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Updating */
|
||||
int final[50][50];
|
||||
for(i=0;i<nn;i++)
|
||||
{
|
||||
for(j=0;j<nn;j++)
|
||||
{
|
||||
/* Copy initial value from input graph*/
|
||||
final[i][j]=graph[i][j];
|
||||
via[i][j]=i;
|
||||
|
||||
/*Update them*/
|
||||
/* Check condition a - b - c */
|
||||
for(k=0;k<nn;k++)
|
||||
{
|
||||
|
||||
if((final[i][j]>sh[i][k][j]) || (final[i][j] == -1))
|
||||
{
|
||||
if(sh[i][k][j]>-1)
|
||||
{
|
||||
final[i][j]=sh[i][k][j];
|
||||
via[i][j]=k;
|
||||
}
|
||||
}
|
||||
}
|
||||
/* After considering three vertex if final not found
|
||||
consider 4th
|
||||
a- b- c- d
|
||||
*/
|
||||
|
||||
if(final[i][j]==-1)
|
||||
{
|
||||
for(k=0;k<nn;k++)
|
||||
{
|
||||
|
||||
if((final[i][k]!=-1)&&(final[k][j]!=-1))
|
||||
{
|
||||
if((final[i][j]==-1) || ((final[i][j]!=-1) &&(final[i][j]>final[i][k]+final[k][j])))
|
||||
{
|
||||
if(final[i][k]+final[k][j]>-1)
|
||||
{
|
||||
final[i][j]=final[i][k]+final[k][j];
|
||||
via[i][j]=k;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
cout<<"\n After Update :";
|
||||
/* Display table Updation */
|
||||
for (i=0;i<nn;i++)
|
||||
{
|
||||
cout<<"\n"<<ch[i]<<" Table";
|
||||
cout<<"\nNode\tDist\tVia";
|
||||
for(j=0;j<nn;j++)
|
||||
{
|
||||
cout<<"\n"<<ch[j]<<"\t"<<final[i][j]<<"\t";
|
||||
if(i==via[i][j])
|
||||
cout<<"-";
|
||||
else
|
||||
cout<<ch[via[i][j]];
|
||||
}
|
||||
}
|
||||
|
||||
getch();
|
||||
}
|
||||
|
||||
/* OUTPUT
|
||||
|
||||
|
||||
Enter Number of Nodes:5
|
||||
|
||||
Enter Distance between A - B : 5
|
||||
|
||||
Enter Distance between A - C : 2
|
||||
|
||||
Enter Distance between A - D : 3
|
||||
|
||||
Enter Distance between A - E : -1
|
||||
|
||||
Enter Distance between B - C : 4
|
||||
|
||||
Enter Distance between B - D : -1
|
||||
|
||||
Enter Distance between B - E : 3
|
||||
|
||||
Enter Distance between C - D : -1
|
||||
|
||||
Enter Distance between C - E : 4
|
||||
|
||||
Enter Distance between D - B : -1
|
||||
|
||||
Enter Distance between D - C : -1
|
||||
|
||||
Enter Distance between D - E : -1
|
||||
|
||||
Enter Distance between E - A : -1
|
||||
|
||||
Enter Distance between E - D : -1
|
||||
|
||||
After Initialization
|
||||
A Table
|
||||
Node Dist Via
|
||||
A 0 -1
|
||||
B 5 -1
|
||||
C 2 -1
|
||||
D 3 -1
|
||||
E -1 -1
|
||||
B Table
|
||||
Node Dist Via
|
||||
A 5 -1
|
||||
B 0 -1
|
||||
C 4 -1
|
||||
D -1 -1
|
||||
E 3 -1
|
||||
C Table
|
||||
Node Dist Via
|
||||
A 2 -1
|
||||
B 4 -1
|
||||
C 0 -1
|
||||
D -1 -1
|
||||
E 4 -1
|
||||
D Table
|
||||
Node Dist Via
|
||||
A 3 -1
|
||||
B -1 -1
|
||||
C -1 -1
|
||||
D 0 -1
|
||||
E -1 -1
|
||||
E Table
|
||||
Node Dist Via
|
||||
A -1 -1
|
||||
B 3 -1
|
||||
C 4 -1
|
||||
D -1 -1
|
||||
E 0 -1
|
||||
|
||||
For A
|
||||
From A
|
||||
A 0
|
||||
B 5
|
||||
C 2
|
||||
D 3
|
||||
E -1
|
||||
From B
|
||||
A 10
|
||||
B 5
|
||||
C 9
|
||||
D -1
|
||||
E 8
|
||||
From C
|
||||
A 4
|
||||
B 6
|
||||
C 2
|
||||
D -1
|
||||
E 6
|
||||
From D
|
||||
A 6
|
||||
B -1
|
||||
C -1
|
||||
D 3
|
||||
E -1
|
||||
From E
|
||||
A -1
|
||||
B -1
|
||||
C -1
|
||||
D -1
|
||||
E -1
|
||||
|
||||
For B
|
||||
From A
|
||||
A 5
|
||||
B 10
|
||||
C 7
|
||||
D 8
|
||||
E -1
|
||||
From B
|
||||
A 5
|
||||
B 0
|
||||
C 4
|
||||
D -1
|
||||
E 3
|
||||
From C
|
||||
A 6
|
||||
B 8
|
||||
C 4
|
||||
D -1
|
||||
E 8
|
||||
From D
|
||||
A -1
|
||||
B -1
|
||||
C -1
|
||||
D -1
|
||||
E -1
|
||||
From E
|
||||
A -1
|
||||
B 6
|
||||
C 7
|
||||
D -1
|
||||
E 3
|
||||
|
||||
For C
|
||||
From A
|
||||
A 2
|
||||
B 7
|
||||
C 4
|
||||
D 5
|
||||
E -1
|
||||
From B
|
||||
A 9
|
||||
B 4
|
||||
C 8
|
||||
D -1
|
||||
E 7
|
||||
From C
|
||||
A 2
|
||||
B 4
|
||||
C 0
|
||||
D -1
|
||||
E 4
|
||||
From D
|
||||
A -1
|
||||
B -1
|
||||
C -1
|
||||
D -1
|
||||
E -1
|
||||
From E
|
||||
A -1
|
||||
B 7
|
||||
C 8
|
||||
D -1
|
||||
E 4
|
||||
|
||||
For D
|
||||
From A
|
||||
A 3
|
||||
B 8
|
||||
C 5
|
||||
D 6
|
||||
E -1
|
||||
From B
|
||||
A -1
|
||||
B -1
|
||||
C -1
|
||||
D -1
|
||||
E -1
|
||||
From C
|
||||
A -1
|
||||
B -1
|
||||
C -1
|
||||
D -1
|
||||
E -1
|
||||
From D
|
||||
A 3
|
||||
B -1
|
||||
C -1
|
||||
D 0
|
||||
E -1
|
||||
From E
|
||||
A -1
|
||||
B -1
|
||||
C -1
|
||||
D -1
|
||||
E -1
|
||||
|
||||
For E
|
||||
From A
|
||||
A -1
|
||||
B -1
|
||||
C -1
|
||||
D -1
|
||||
E -1
|
||||
From B
|
||||
A 8
|
||||
B 3
|
||||
C 7
|
||||
D -1
|
||||
E 6
|
||||
From C
|
||||
A 6
|
||||
B 8
|
||||
C 4
|
||||
D -1
|
||||
E 8
|
||||
From D
|
||||
A -1
|
||||
B -1
|
||||
C -1
|
||||
D -1
|
||||
E -1
|
||||
From E
|
||||
A -1
|
||||
B 3
|
||||
C 4
|
||||
D -1
|
||||
E 0
|
||||
After Update :
|
||||
A Table
|
||||
Node Dist Via
|
||||
A 0 -
|
||||
B 5 -
|
||||
C 2 -
|
||||
D 3 -
|
||||
E 6 C
|
||||
B Table
|
||||
Node Dist Via
|
||||
A 5 -
|
||||
B 0 -
|
||||
C 4 -
|
||||
D 8 A
|
||||
E 3 -
|
||||
C Table
|
||||
Node Dist Via
|
||||
A 2 -
|
||||
B 4 -
|
||||
C 0 -
|
||||
D 5 A
|
||||
E 4 -
|
||||
D Table
|
||||
Node Dist Via
|
||||
A 3 -
|
||||
B 8 A
|
||||
C 5 A
|
||||
D 0 -
|
||||
E 9 A
|
||||
E Table
|
||||
Node Dist Via
|
||||
A 6 C
|
||||
B 3 -
|
||||
C 4 -
|
||||
D 9 A
|
||||
E 0 -
|
||||
|
||||
*/
|
||||
@@ -0,0 +1,118 @@
|
||||
#include <iostream>
|
||||
#include <limits>
|
||||
|
||||
using namespace std;
|
||||
|
||||
const int INF = numeric_limits<int>::max(); // Represents no known path
|
||||
|
||||
int main()
|
||||
{
|
||||
int nodeCount;
|
||||
cout << "\n Enter Number of Nodes: ";
|
||||
cin >> nodeCount;
|
||||
|
||||
// directDist[src][dst] = direct link cost between src and dst (INF if no direct link)
|
||||
int directDist[50][50];
|
||||
for (int src = 0; src < nodeCount; src++)
|
||||
{
|
||||
for (int dst = 0; dst < nodeCount; dst++)
|
||||
{
|
||||
directDist[src][dst] = (src == dst) ? 0 : INF;
|
||||
}
|
||||
}
|
||||
|
||||
// Assign node labels A, B, C, D, ...
|
||||
char nodeName[50];
|
||||
for (int nodeIndex = 0; nodeIndex < nodeCount; nodeIndex++)
|
||||
{
|
||||
nodeName[nodeIndex] = 'A' + nodeIndex;
|
||||
}
|
||||
|
||||
// Read direct link distances between each pair of nodes
|
||||
for (int src = 0; src < nodeCount; src++)
|
||||
{
|
||||
for (int dst = src + 1; dst < nodeCount; dst++)
|
||||
{
|
||||
int linkCost;
|
||||
cout << "\n Enter Distance between "
|
||||
<< nodeName[src] << " - " << nodeName[dst]
|
||||
<< " (use -1 for no connection): ";
|
||||
cin >> linkCost;
|
||||
if (linkCost != -1)
|
||||
{
|
||||
directDist[src][dst] = linkCost;
|
||||
directDist[dst][src] = linkCost; // Assume symmetric (undirected) links
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// viaNode[src][dst] = intermediate node used on the current best path from src to dst
|
||||
int viaNode[50][50];
|
||||
for (int src = 0; src < nodeCount; src++)
|
||||
for (int dst = 0; dst < nodeCount; dst++)
|
||||
viaNode[src][dst] = -1;
|
||||
|
||||
// bestDist[src][dst] = best known shortest distance from src to dst
|
||||
int bestDist[50][50];
|
||||
|
||||
// --- Iterative Distance Vector update loop ---
|
||||
bool updated;
|
||||
do
|
||||
{
|
||||
updated = false;
|
||||
|
||||
for (int src = 0; src < nodeCount; src++)
|
||||
{
|
||||
for (int dst = 0; dst < nodeCount; dst++)
|
||||
{
|
||||
bestDist[src][dst] = directDist[src][dst];
|
||||
viaNode[src][dst] = src; // Default: reach dst directly from src
|
||||
|
||||
// Try routing through each intermediate node k
|
||||
for (int via = 0; via < nodeCount; via++)
|
||||
{
|
||||
if (directDist[src][via] != INF && directDist[via][dst] != INF)
|
||||
{
|
||||
int candidateDist = directDist[src][via] + directDist[via][dst];
|
||||
if (candidateDist < bestDist[src][dst])
|
||||
{
|
||||
bestDist[src][dst] = candidateDist;
|
||||
viaNode[src][dst] = via;
|
||||
updated = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Propagate the improved distances back into directDist for the next iteration
|
||||
for (int src = 0; src < nodeCount; src++)
|
||||
for (int dst = 0; dst < nodeCount; dst++)
|
||||
directDist[src][dst] = bestDist[src][dst];
|
||||
|
||||
} while (updated); // Repeat until no further improvements (convergence)
|
||||
|
||||
// --- Print final routing tables ---
|
||||
cout << "\n After Convergence:";
|
||||
for (int src = 0; src < nodeCount; src++)
|
||||
{
|
||||
cout << "\n\n" << nodeName[src] << " Routing Table";
|
||||
cout << "\n Node\tDist\tVia";
|
||||
for (int dst = 0; dst < nodeCount; dst++)
|
||||
{
|
||||
cout << "\n" << nodeName[dst] << "\t";
|
||||
if (bestDist[src][dst] == INF)
|
||||
cout << "INF";
|
||||
else
|
||||
cout << bestDist[src][dst];
|
||||
cout << "\t";
|
||||
if (src == viaNode[src][dst])
|
||||
cout << "-"; // Direct connection, no intermediate hop
|
||||
else
|
||||
cout << nodeName[viaNode[src][dst]];
|
||||
}
|
||||
}
|
||||
cout << "\n";
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,66 @@
|
||||
routers: 4, infinity = 16, poison reverse = off
|
||||
links: A-B=1 A-D=4 B-C=2 C-D=3
|
||||
|
||||
== initial convergence ==
|
||||
|
||||
-- round 0 (direct links only) --
|
||||
A Routing Table
|
||||
Dest Dist Next hop
|
||||
A 0 -
|
||||
B 1 B
|
||||
C INF -
|
||||
D 4 D
|
||||
|
||||
B Routing Table
|
||||
Dest Dist Next hop
|
||||
A 1 A
|
||||
B 0 -
|
||||
C 2 C
|
||||
D INF -
|
||||
|
||||
C Routing Table
|
||||
Dest Dist Next hop
|
||||
A INF -
|
||||
B 2 B
|
||||
C 0 -
|
||||
D 3 D
|
||||
|
||||
D Routing Table
|
||||
Dest Dist Next hop
|
||||
A 4 A
|
||||
B INF -
|
||||
C 3 C
|
||||
D 0 -
|
||||
|
||||
-- after round 1 --
|
||||
A Routing Table
|
||||
Dest Dist Next hop
|
||||
A 0 -
|
||||
B 1 B
|
||||
C 3 B
|
||||
D 4 D
|
||||
|
||||
B Routing Table
|
||||
Dest Dist Next hop
|
||||
A 1 A
|
||||
B 0 -
|
||||
C 2 C
|
||||
D 5 A
|
||||
|
||||
C Routing Table
|
||||
Dest Dist Next hop
|
||||
A 3 B
|
||||
B 2 B
|
||||
C 0 -
|
||||
D 3 D
|
||||
|
||||
D Routing Table
|
||||
Dest Dist Next hop
|
||||
A 4 A
|
||||
B 5 A
|
||||
C 3 C
|
||||
D 0 -
|
||||
|
||||
converged: round 2 changed nothing
|
||||
rounds that changed something: 1
|
||||
check vs Floyd-Warshall: match
|
||||
@@ -0,0 +1,131 @@
|
||||
routers: 5, infinity = 16, poison reverse = off
|
||||
links: A-B=5 A-C=2 A-D=3 B-C=4 B-E=3 C-E=4
|
||||
|
||||
== initial convergence ==
|
||||
|
||||
-- round 0 (direct links only) --
|
||||
A Routing Table
|
||||
Dest Dist Next hop
|
||||
A 0 -
|
||||
B 5 B
|
||||
C 2 C
|
||||
D 3 D
|
||||
E INF -
|
||||
|
||||
B Routing Table
|
||||
Dest Dist Next hop
|
||||
A 5 A
|
||||
B 0 -
|
||||
C 4 C
|
||||
D INF -
|
||||
E 3 E
|
||||
|
||||
C Routing Table
|
||||
Dest Dist Next hop
|
||||
A 2 A
|
||||
B 4 B
|
||||
C 0 -
|
||||
D INF -
|
||||
E 4 E
|
||||
|
||||
D Routing Table
|
||||
Dest Dist Next hop
|
||||
A 3 A
|
||||
B INF -
|
||||
C INF -
|
||||
D 0 -
|
||||
E INF -
|
||||
|
||||
E Routing Table
|
||||
Dest Dist Next hop
|
||||
A INF -
|
||||
B 3 B
|
||||
C 4 C
|
||||
D INF -
|
||||
E 0 -
|
||||
|
||||
-- after round 1 --
|
||||
A Routing Table
|
||||
Dest Dist Next hop
|
||||
A 0 -
|
||||
B 5 B
|
||||
C 2 C
|
||||
D 3 D
|
||||
E 6 C
|
||||
|
||||
B Routing Table
|
||||
Dest Dist Next hop
|
||||
A 5 A
|
||||
B 0 -
|
||||
C 4 C
|
||||
D 8 A
|
||||
E 3 E
|
||||
|
||||
C Routing Table
|
||||
Dest Dist Next hop
|
||||
A 2 A
|
||||
B 4 B
|
||||
C 0 -
|
||||
D 5 A
|
||||
E 4 E
|
||||
|
||||
D Routing Table
|
||||
Dest Dist Next hop
|
||||
A 3 A
|
||||
B 8 A
|
||||
C 5 A
|
||||
D 0 -
|
||||
E INF -
|
||||
|
||||
E Routing Table
|
||||
Dest Dist Next hop
|
||||
A 6 C
|
||||
B 3 B
|
||||
C 4 C
|
||||
D INF -
|
||||
E 0 -
|
||||
|
||||
-- after round 2 --
|
||||
A Routing Table
|
||||
Dest Dist Next hop
|
||||
A 0 -
|
||||
B 5 B
|
||||
C 2 C
|
||||
D 3 D
|
||||
E 6 C
|
||||
|
||||
B Routing Table
|
||||
Dest Dist Next hop
|
||||
A 5 A
|
||||
B 0 -
|
||||
C 4 C
|
||||
D 8 A
|
||||
E 3 E
|
||||
|
||||
C Routing Table
|
||||
Dest Dist Next hop
|
||||
A 2 A
|
||||
B 4 B
|
||||
C 0 -
|
||||
D 5 A
|
||||
E 4 E
|
||||
|
||||
D Routing Table
|
||||
Dest Dist Next hop
|
||||
A 3 A
|
||||
B 8 A
|
||||
C 5 A
|
||||
D 0 -
|
||||
E 9 A
|
||||
|
||||
E Routing Table
|
||||
Dest Dist Next hop
|
||||
A 6 C
|
||||
B 3 B
|
||||
C 4 C
|
||||
D 9 C
|
||||
E 0 -
|
||||
|
||||
converged: round 3 changed nothing
|
||||
rounds that changed something: 2
|
||||
check vs Floyd-Warshall: match
|
||||
@@ -0,0 +1,66 @@
|
||||
routers: 3, infinity = 16, poison reverse = off
|
||||
links: A-B=1 B-C=1
|
||||
|
||||
== initial convergence ==
|
||||
round 0 | to C: A=INF B=1(C)
|
||||
round 1 | to C: A=2(B) B=1(C)
|
||||
converged: round 2 changed nothing
|
||||
rounds that changed something: 1
|
||||
check vs Floyd-Warshall: match
|
||||
|
||||
A Routing Table
|
||||
Dest Dist Next hop
|
||||
A 0 -
|
||||
B 1 B
|
||||
C 2 B
|
||||
|
||||
B Routing Table
|
||||
Dest Dist Next hop
|
||||
A 1 A
|
||||
B 0 -
|
||||
C 1 C
|
||||
|
||||
C Routing Table
|
||||
Dest Dist Next hop
|
||||
A 2 B
|
||||
B 1 B
|
||||
C 0 -
|
||||
|
||||
== link B-C fails ==
|
||||
round 0 | to C: A=2(B) B=1(C)
|
||||
round 1 | to C: A=2(B) B=3(A)
|
||||
round 2 | to C: A=4(B) B=3(A)
|
||||
round 3 | to C: A=4(B) B=5(A)
|
||||
round 4 | to C: A=6(B) B=5(A)
|
||||
round 5 | to C: A=6(B) B=7(A)
|
||||
round 6 | to C: A=8(B) B=7(A)
|
||||
round 7 | to C: A=8(B) B=9(A)
|
||||
round 8 | to C: A=10(B) B=9(A)
|
||||
round 9 | to C: A=10(B) B=11(A)
|
||||
round 10 | to C: A=12(B) B=11(A)
|
||||
round 11 | to C: A=12(B) B=13(A)
|
||||
round 12 | to C: A=14(B) B=13(A)
|
||||
round 13 | to C: A=14(B) B=15(A)
|
||||
round 14 | to C: A=INF B=15(A)
|
||||
round 15 | to C: A=INF B=INF
|
||||
converged: round 16 changed nothing
|
||||
rounds that changed something: 15
|
||||
check vs Floyd-Warshall: match
|
||||
|
||||
A Routing Table
|
||||
Dest Dist Next hop
|
||||
A 0 -
|
||||
B 1 B
|
||||
C INF -
|
||||
|
||||
B Routing Table
|
||||
Dest Dist Next hop
|
||||
A 1 A
|
||||
B 0 -
|
||||
C INF -
|
||||
|
||||
C Routing Table
|
||||
Dest Dist Next hop
|
||||
A INF -
|
||||
B INF -
|
||||
C 0 -
|
||||
@@ -0,0 +1,53 @@
|
||||
routers: 3, infinity = 16, poison reverse = on
|
||||
links: A-B=1 B-C=1
|
||||
|
||||
== initial convergence ==
|
||||
round 0 | to C: A=INF B=1(C)
|
||||
round 1 | to C: A=2(B) B=1(C)
|
||||
converged: round 2 changed nothing
|
||||
rounds that changed something: 1
|
||||
check vs Floyd-Warshall: match
|
||||
|
||||
A Routing Table
|
||||
Dest Dist Next hop
|
||||
A 0 -
|
||||
B 1 B
|
||||
C 2 B
|
||||
|
||||
B Routing Table
|
||||
Dest Dist Next hop
|
||||
A 1 A
|
||||
B 0 -
|
||||
C 1 C
|
||||
|
||||
C Routing Table
|
||||
Dest Dist Next hop
|
||||
A 2 B
|
||||
B 1 B
|
||||
C 0 -
|
||||
|
||||
== link B-C fails ==
|
||||
round 0 | to C: A=2(B) B=1(C)
|
||||
round 1 | to C: A=2(B) B=INF
|
||||
round 2 | to C: A=INF B=INF
|
||||
converged: round 3 changed nothing
|
||||
rounds that changed something: 2
|
||||
check vs Floyd-Warshall: match
|
||||
|
||||
A Routing Table
|
||||
Dest Dist Next hop
|
||||
A 0 -
|
||||
B 1 B
|
||||
C INF -
|
||||
|
||||
B Routing Table
|
||||
Dest Dist Next hop
|
||||
A 1 A
|
||||
B 0 -
|
||||
C INF -
|
||||
|
||||
C Routing Table
|
||||
Dest Dist Next hop
|
||||
A INF -
|
||||
B INF -
|
||||
C 0 -
|
||||
@@ -0,0 +1,74 @@
|
||||
routers: 4, infinity = 16, poison reverse = on
|
||||
links: A-B=1 B-C=1 C-D=1
|
||||
|
||||
== initial convergence ==
|
||||
round 0 | to D: A=INF B=INF C=1(D)
|
||||
round 1 | to D: A=INF B=2(C) C=1(D)
|
||||
round 2 | to D: A=3(B) B=2(C) C=1(D)
|
||||
converged: round 3 changed nothing
|
||||
rounds that changed something: 2
|
||||
check vs Floyd-Warshall: match
|
||||
|
||||
A Routing Table
|
||||
Dest Dist Next hop
|
||||
A 0 -
|
||||
B 1 B
|
||||
C 2 B
|
||||
D 3 B
|
||||
|
||||
B Routing Table
|
||||
Dest Dist Next hop
|
||||
A 1 A
|
||||
B 0 -
|
||||
C 1 C
|
||||
D 2 C
|
||||
|
||||
C Routing Table
|
||||
Dest Dist Next hop
|
||||
A 2 B
|
||||
B 1 B
|
||||
C 0 -
|
||||
D 1 D
|
||||
|
||||
D Routing Table
|
||||
Dest Dist Next hop
|
||||
A 3 C
|
||||
B 2 C
|
||||
C 1 C
|
||||
D 0 -
|
||||
|
||||
== link B-C fails ==
|
||||
round 0 | to D: A=3(B) B=2(C) C=1(D)
|
||||
round 1 | to D: A=3(B) B=INF C=1(D)
|
||||
round 2 | to D: A=INF B=INF C=1(D)
|
||||
converged: round 3 changed nothing
|
||||
rounds that changed something: 2
|
||||
check vs Floyd-Warshall: match
|
||||
|
||||
A Routing Table
|
||||
Dest Dist Next hop
|
||||
A 0 -
|
||||
B 1 B
|
||||
C INF -
|
||||
D INF -
|
||||
|
||||
B Routing Table
|
||||
Dest Dist Next hop
|
||||
A 1 A
|
||||
B 0 -
|
||||
C INF -
|
||||
D INF -
|
||||
|
||||
C Routing Table
|
||||
Dest Dist Next hop
|
||||
A INF -
|
||||
B INF -
|
||||
C 0 -
|
||||
D 1 D
|
||||
|
||||
D Routing Table
|
||||
Dest Dist Next hop
|
||||
A INF -
|
||||
B INF -
|
||||
C 1 C
|
||||
D 0 -
|
||||
@@ -0,0 +1,87 @@
|
||||
routers: 4, infinity = 16, poison reverse = off
|
||||
links: A-B=1 B-C=1 C-D=1
|
||||
|
||||
== initial convergence ==
|
||||
round 0 | to D: A=INF B=INF C=1(D)
|
||||
round 1 | to D: A=INF B=2(C) C=1(D)
|
||||
round 2 | to D: A=3(B) B=2(C) C=1(D)
|
||||
converged: round 3 changed nothing
|
||||
rounds that changed something: 2
|
||||
check vs Floyd-Warshall: match
|
||||
|
||||
A Routing Table
|
||||
Dest Dist Next hop
|
||||
A 0 -
|
||||
B 1 B
|
||||
C 2 B
|
||||
D 3 B
|
||||
|
||||
B Routing Table
|
||||
Dest Dist Next hop
|
||||
A 1 A
|
||||
B 0 -
|
||||
C 1 C
|
||||
D 2 C
|
||||
|
||||
C Routing Table
|
||||
Dest Dist Next hop
|
||||
A 2 B
|
||||
B 1 B
|
||||
C 0 -
|
||||
D 1 D
|
||||
|
||||
D Routing Table
|
||||
Dest Dist Next hop
|
||||
A 3 C
|
||||
B 2 C
|
||||
C 1 C
|
||||
D 0 -
|
||||
|
||||
== link B-C fails ==
|
||||
round 0 | to D: A=3(B) B=2(C) C=1(D)
|
||||
round 1 | to D: A=3(B) B=4(A) C=1(D)
|
||||
round 2 | to D: A=5(B) B=4(A) C=1(D)
|
||||
round 3 | to D: A=5(B) B=6(A) C=1(D)
|
||||
round 4 | to D: A=7(B) B=6(A) C=1(D)
|
||||
round 5 | to D: A=7(B) B=8(A) C=1(D)
|
||||
round 6 | to D: A=9(B) B=8(A) C=1(D)
|
||||
round 7 | to D: A=9(B) B=10(A) C=1(D)
|
||||
round 8 | to D: A=11(B) B=10(A) C=1(D)
|
||||
round 9 | to D: A=11(B) B=12(A) C=1(D)
|
||||
round 10 | to D: A=13(B) B=12(A) C=1(D)
|
||||
round 11 | to D: A=13(B) B=14(A) C=1(D)
|
||||
round 12 | to D: A=15(B) B=14(A) C=1(D)
|
||||
round 13 | to D: A=15(B) B=INF C=1(D)
|
||||
round 14 | to D: A=INF B=INF C=1(D)
|
||||
round 15 | to D: A=INF B=INF C=1(D)
|
||||
converged: round 16 changed nothing
|
||||
rounds that changed something: 15
|
||||
check vs Floyd-Warshall: match
|
||||
|
||||
A Routing Table
|
||||
Dest Dist Next hop
|
||||
A 0 -
|
||||
B 1 B
|
||||
C INF -
|
||||
D INF -
|
||||
|
||||
B Routing Table
|
||||
Dest Dist Next hop
|
||||
A 1 A
|
||||
B 0 -
|
||||
C INF -
|
||||
D INF -
|
||||
|
||||
C Routing Table
|
||||
Dest Dist Next hop
|
||||
A INF -
|
||||
B INF -
|
||||
C 0 -
|
||||
D 1 D
|
||||
|
||||
D Routing Table
|
||||
Dest Dist Next hop
|
||||
A INF -
|
||||
B INF -
|
||||
C 1 C
|
||||
D 0 -
|
||||
@@ -0,0 +1,47 @@
|
||||
routers: 5, infinity = 16, poison reverse = off
|
||||
links: A-B=1 B-C=1 C-D=1 D-E=1
|
||||
|
||||
== initial convergence ==
|
||||
converged: round 4 changed nothing
|
||||
rounds that changed something: 3
|
||||
check vs Floyd-Warshall: match
|
||||
|
||||
A Routing Table
|
||||
Dest Dist Next hop
|
||||
A 0 -
|
||||
B 1 B
|
||||
C 2 B
|
||||
D 3 B
|
||||
E 4 B
|
||||
|
||||
B Routing Table
|
||||
Dest Dist Next hop
|
||||
A 1 A
|
||||
B 0 -
|
||||
C 1 C
|
||||
D 2 C
|
||||
E 3 C
|
||||
|
||||
C Routing Table
|
||||
Dest Dist Next hop
|
||||
A 2 B
|
||||
B 1 B
|
||||
C 0 -
|
||||
D 1 D
|
||||
E 2 D
|
||||
|
||||
D Routing Table
|
||||
Dest Dist Next hop
|
||||
A 3 C
|
||||
B 2 C
|
||||
C 1 C
|
||||
D 0 -
|
||||
E 1 E
|
||||
|
||||
E Routing Table
|
||||
Dest Dist Next hop
|
||||
A 4 D
|
||||
B 3 D
|
||||
C 2 D
|
||||
D 1 D
|
||||
E 0 -
|
||||
@@ -0,0 +1,41 @@
|
||||
After Convergence:
|
||||
|
||||
A Routing Table
|
||||
Node Dist Via
|
||||
A 0 -
|
||||
B 1 -
|
||||
C 2 -
|
||||
D 3 -
|
||||
E 4 -
|
||||
|
||||
B Routing Table
|
||||
Node Dist Via
|
||||
A 1 -
|
||||
B 0 -
|
||||
C 1 -
|
||||
D 2 -
|
||||
E 3 -
|
||||
|
||||
C Routing Table
|
||||
Node Dist Via
|
||||
A 2 -
|
||||
B 1 -
|
||||
C 0 -
|
||||
D 1 -
|
||||
E 2 -
|
||||
|
||||
D Routing Table
|
||||
Node Dist Via
|
||||
A 3 -
|
||||
B 2 -
|
||||
C 1 -
|
||||
D 0 -
|
||||
E 1 -
|
||||
|
||||
E Routing Table
|
||||
Node Dist Via
|
||||
A 4 -
|
||||
B 3 -
|
||||
C 2 -
|
||||
D 1 -
|
||||
E 0 -
|
||||
@@ -0,0 +1,4 @@
|
||||
legacy/old_dvr_2015_turbocpp.cpp:1:9: fatal error: iostream.h: No such file or directory
|
||||
1 | #include<iostream.h>
|
||||
| ^~~~~~~~~~~~
|
||||
compilation terminated.
|
||||
@@ -0,0 +1,29 @@
|
||||
After Convergence:
|
||||
|
||||
A Routing Table
|
||||
Node Dist Via
|
||||
A 0 -
|
||||
B 1 -
|
||||
C 3 -
|
||||
D 4 -
|
||||
|
||||
B Routing Table
|
||||
Node Dist Via
|
||||
A 1 -
|
||||
B 0 -
|
||||
C 2 -
|
||||
D 5 -
|
||||
|
||||
C Routing Table
|
||||
Node Dist Via
|
||||
A 3 -
|
||||
B 2 -
|
||||
C 0 -
|
||||
D 3 -
|
||||
|
||||
D Routing Table
|
||||
Node Dist Via
|
||||
A 4 -
|
||||
B 5 -
|
||||
C 3 -
|
||||
D 0 -
|
||||
Executable
+21
@@ -0,0 +1,21 @@
|
||||
#!/usr/bin/env bash
|
||||
# Rebuilds every program and regenerates every file in output/.
|
||||
set -euo pipefail
|
||||
cd "$(dirname "$0")/.."
|
||||
mkdir -p output build
|
||||
CXX=${CXX:-g++}
|
||||
$CXX -std=c++17 -Wall -Wextra -O2 -o build/dvr dvr.cpp
|
||||
$CXX -std=c++17 -o build/old_global legacy/old_dvr_global_matrix.cpp
|
||||
|
||||
build/dvr --trace < input/four-node.txt > output/01-four-node-trace.txt
|
||||
build/dvr --trace < input/five-node.txt > output/02-five-node-trace.txt
|
||||
build/dvr --watch C < input/chain-three.txt > output/03-count-to-infinity.txt
|
||||
build/dvr --watch C --poison < input/chain-three.txt > output/04-poison-reverse.txt
|
||||
build/dvr --watch D --poison < input/partition.txt > output/05-partition-poison.txt
|
||||
build/dvr --watch D < input/partition.txt > output/06-partition-plain.txt
|
||||
build/dvr < input/chain-five.txt > output/07-chain-five-dvr.txt
|
||||
build/old_global < input/chain-five-legacy.txt | sed -n '/After/,$p' > output/08-legacy-wrong-next-hop.txt
|
||||
build/old_global < input/four-node-legacy.txt | sed -n '/After/,$p' > output/10-legacy-four-node-via-column.txt
|
||||
# The 2015 program no longer compiles; keep the compiler's own message.
|
||||
{ $CXX -std=c++17 -o /dev/null legacy/old_dvr_2015_turbocpp.cpp 2>&1 || true; } | head -4 > output/09-legacy-2015-compile-error.txt
|
||||
echo "done: $(ls output | wc -l) files in output/"
|
||||
Reference in New Issue
Block a user