Вы находитесь на странице: 1из 3

5.

Take an example subnet graph with weights indicating delay between


nodes. Now obtain routing table art each node using distance vector
routing algorithm:
#include<stdio.h>
void main()
{
int i,j,d[20],dt[50][50],min=0,mini=0,p,q,y=0,nd[30];
char r[30],n[30],l[30],x;
printf("enter number of nodes\n");
scanf("%d",&p);
printf("enter nodes\n");
for(i=1;i<=p;i++)
scanf(" %c",&r[i]);
printf("enter node for which you want to calculate routing table\n");
scanf(" %c",&x);
for(i=1;i<=p;i++)
{
if( x==r[i])
y=i;
}
nd[y]=0;
l[y]='-';
printf("enter number of neighbours are there for %c node\n",x);
scanf("%d",&q);
printf("enter neighbours of %c node\n",x);
for(i=1;i<=q;i++)
scanf(" %c",&n[i]);
printf("enter delays table\n");
for(i=1;i<=p;i++)
{
for(j=1;j<=q;j++)
{
scanf("%d",&dt[i][j]);
}
}
printf("enter delay from %c to each of its neighbour\n",x);
for(i=1;i<=q;i++)
scanf("%d",&d[i]);
for(i=1;i<=p;i++)

{
if(i!=y)
{
j=1;
min=dt[i][j]+d[j];
mini=j;
for(j=2;j<=q;j++)
{
if(min>(dt[i][j]+d[j]))
{
min=dt[i][j]+d[j];
mini=j;
}
}
nd[i]=min;
l[i]=n[mini];
}
}
printf(" routing vector table for %c is\n",x);
for(i=1;i<=p;i++)
{
printf("%d\t%c\n",nd[i],l[i]);
}
getch();
}
OUTPUT:
Enter number of nodes: 5
Enter nodes:
A
B
C
D
E
Enter node for which you want to calculate routing table: A
Enter number of neighbours are there for A nod: 4
Enter neighbours of A node
B
C
D
E
Enter delays table
2
5
8
4
8
5
4
2
6
1
3
4
2
3
5
4
5
9
2
7
Enter delay from A to each of its neighbour

5
8
4
6
routing vector table for A is
0 8 D
7 D
7 B
6 D

Вам также может понравиться