Distance Vector Routing protocol Algorithm CS1305- NETWORK LAB

Step by step DVR Algorithm
The number of nodes is obtained and stored in a variable
The distance between all nodes are accepted in adjacency matrix
Each nod is estimated and displayed using estimate table
According to the input node the shortest distance between the neighbors route is calculated
For given node the shortest estimated between each node is displayed
Finally the stop Distance Vector routing Protocol algorithm

Source code in C language programming DVR CS1305- NETWORK LAB
#include<stdio.h>
#include<ctype.h>
int graph[12][12];
int e[12][12];
int ad[12];
int no,id,adc,small,chosen;
char nodes[12]={“a b c d e f g h i j k l”};
int main()
{
int i,j,k,ch1,ch2=0;
adc=0;
printf("enter the no nodes");
scanf("%d",&no);
printf("enter the value for adjacency matrix");
for(i=0;i<no;i++)
{
for(j=0;j<no;j++)
{
printf(" enter values for %d,%d position:",(i+1),(j+1));
scanf("%d",&graph[i][j]);
}
}
printf("enter initial estimates");
for(i=0;i<no;i++)
{
printf("estimate for node %c \n",nodes[i]);
for(j=0;j<no;j++)
{
printf("to node%c",nodes[j]);
scanf("%d",&e[i][j]);
}
}
do
{
printf("\n menu:\n 1.routing info for node");
printf("2.estimated table\n ");
scanf("%d",&ch1);
switch(ch1)
{
case 1:
printf("\n which node should routing table be built(1-a)(2-b)...");
scanf("%d",&id);
id--;
adc=0;
printf("neighbours for particular node");
for(i=0;i<no;i++)
{
if(graph[id][i]==1)
{
ad[adc]=i;
adc++;
printf("%c",nodes[i]);
}
}
for(i=0;i<no;i++)
{
if(id!=i)
{
small=100;
chosen=-1;
for(j=0;j<adc;j++)
{
int total=e[ad[j]][i]+e[id][ad[j]];
if(total<small)
{
small=total;
chosen=j;
} }
e[id][i]=small;
printf("\n shortest estimate to %c is %d",nodes[i],small);
printf("\n next hop is %c",nodes[ad[chosen]]);
} else
e[id][i]=0;
}
break;
case 2:
printf("\n");
for(i=0;i<no;i++)
{ for(j=0;j<no;j++)
printf("%d",e[i][j]);
printf("\n");
} break;
}
printf("\n do u want to continue (1-yes,2-no)");
scanf("%d",&ch2);
}
while(ch2==1);
return 0; }

Output for Distance Vector Routing Protocol CS1305- NETWORK LAB
[it28@localhost studentwebsite]$ cc distancevector.c
[it28@localhost studentwebsite]$ ./a.out
Enter the no of nodes 4
Enter the values for adjacency matrix:
Enter the value for 1,1 position:0
Enter the value for 1,2 position:1
Enter the value for 1,3 position:1
Enter the value for 1,4 position:0
Enter the value for 2,1 position:1
Enter the value for 2,2 position:0
Enter the value for 2,3 position:0
Enter the value for 2,4 position:1
Enter the value for 3,1 position:1
Enter the value for 3,2 position:0
Enter the value for 3,3 position:0
Enter the value for 3,4 position:1
Enter the value for 4,1 position:0
Enter the value for 4,2 position:1
Enter the value for 4,3 position:1
Enter the value for 4,4 position:0
Enter the initial estimates for node a
To node a 0
To node b 32
To node c 25
To node d 66
Estimate for node b
To node a 10
To node b 0
To node c 23
To node d 56
Enter the initial estimates for node c
To node a 12
To node b 23
To node c 0
To node d 41
Enter the initial estimates for node d
To node a 13
To node b 53
To node c 62
To node d 0
Menu
1.Routing Information for a node
2.Estimate table
Enter the choice(1,2):1
Which node should routing table be built(1-a)(2-b)…1
The neighbors for the particular node b c
Shortest estimate to b is 32
Next hop is b
Shortest estimate to c is 25
Shortest estimate to d is 66
Nest hop is c
Do you want to continue (1-yes,2-no)
Menu
1. Routing Information for a node
2. Estimate table
Enter the choice(1,2):2
0 32 25 66
10 0 23 56
12 23 0 41
13 53 62 0

Related post