Distance Vector Routing Protocol

Program to Simulate And Implement Distance Vector Routing Algorithm.

Simulate and Implement Distance Vector Routing Algorithm Program Using C++.


Program: 

/*----------------------------------------------------------------------------------------- SIMULATE AND IMPLEMENT DISTANCE VECTOR ROUTING ALGORITHM Program Using C++ -----------------------------------------------------------------------------------------*/ #include<stdio.h> #include<iostream> using namespace std; struct node { unsigned dist[6]; unsigned from[6]; }DVR[10]; int main() {     cout<<"\n ---------------------------------------------------------"; cout<<"\n PROGRAM TO SIMULATE DISTANCE VECTOR ROUTING ALGORITHM "; cout<<"\n ---------------------------------------------------------"; int costmat[6][6]; int nodes, i, j, k; cout<<"\n Enter the number of nodes : "; cin>>nodes; //Enter the nodes cout<<"\n Enter the cost matrix : \n" ; for(i = 0; i < nodes; i++) { for(j = 0; j < nodes; j++) { cin>>costmat[i][j]; costmat[i][i] = 0; DVR[i].dist[j] = costmat[i][j]; DVR[i].from[j] = j; } } for(i = 0; i < nodes; i++) for(j = i+1; j < nodes; j++) for(k = 0; k < nodes; k++) if(DVR[i].dist[j] > costmat[i][k] + DVR[k].dist[j]) { DVR[i].dist[j] = DVR[i].dist[k] + DVR[k].dist[j]; DVR[j].dist[i] = DVR[i].dist[j]; DVR[i].from[j] = k; DVR[j].from[i] = k; } for(i = 0; i < nodes; i++) { cout<<"\n\n For router: "<<i+1; for(j = 0; j < nodes; j++) cout<<"\t\n node "<<j+1<<" via "<<DVR[i].from[j]+1<<" Distance "<<DVR[i].dist[j]; } cout<<" \n "; return 0; }
Output

  --------------------------------------------------------- PROGRAM TO SIMULATE DISTANCE VECTOR ROUTING ALGORITHM --------------------------------------------------------- Enter the number of nodes : 3 Enter the cost matrix : 0 5 8 3 8 6 2 9 7 For router: 1 node 1 via 1 Distance 0 node 2 via 2 Distance 5 node 3 via 3 Distance 8 For router: 2 node 1 via 1 Distance 3 node 2 via 2 Distance 0 node 3 via 3 Distance 6 For router: 3 node 1 via 1 Distance 2 node 2 via 2 Distance 9 node 3 via 3 Distance 0


Disqus Comments

Download YouTube videos in Python

     We can use the package Pytube to download YouTube videos in a Python script. It’s a free tool you can install from the PyPI repository....