0% found this document useful (0 votes)
15 views4 pages

Exp 7

The document outlines a program that implements link state/distance vector routing protocols to determine the optimal path for data transmission. It includes a cost matrix input for nodes and calculates the shortest distances using a modified algorithm. The program outputs the routing information for each node, showing the next hop and distance to each destination node.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views4 pages

Exp 7

The document outlines a program that implements link state/distance vector routing protocols to determine the optimal path for data transmission. It includes a cost matrix input for nodes and calculates the shortest distances using a modified algorithm. The program outputs the routing information for each node, showing the next hop and distance to each destination node.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

Experiment No : 07

 Write a program to implement link state


/Distance vector routing protocol to find suitable
path for transmission.

#include<stdio.h>
struct node
{
unsigned dist[20];
unsigned from[20];

}
rt[10]; //memory location where it will save
int main()
{
int costmat[20][20];//two dimensional array
int nodes,i,j,k,count=0;
printf("\nEnter the number of nodes : ");
scanf("%d",&nodes);//Enter the nodes
printf("\nEnter the cost matrix :\n");
for(i=0;i<nodes;i++)
{
for(j=0;j<nodes;j++)
{
scanf("%d",&costmat[i][j]);
costmat[i][i]=0;
rt[i].dist[j]=costmat[i][j];//initialise the distance equal to cost
matrix
rt[i].from[j]=j;

}
do
{
count=0;
for(i=0;i<nodes;i++)

//We choose arbitary vertex k and we calculate the direct distance


from the node i to k using the cost matrix and add the distance from k
to node j

for(j=0;j<nodes;j++)
for(k=0;k<nodes;k++);
if(rt[i].dist[j]>costmat[i][k]+rt[k].dist[j])
{//We calculate the minimum distance
rt[i].dist[j]=rt[i].dist[k]+rt[k].dist[j];
rt[i].from[j]=k;
count++;

}
while(count!=0);
for(i=0;i<nodes;i++)
{
printf("\n\n For router %d\n",i+1);
for(j=0;j<nodes;j++)
{
printf("\t\nnode %d via %d Distance %d ",j+1,rt[i].from[j]
+1,rt[i].dist[j]);

}
printf("\n\n");
getch();

OUTPUT:
structure used to defined different data types

You might also like