SIMULATION OF ROUTING PROTOCOL (OSPF)

Program

#include<stdio.h>
#include<string.h>
int main()
{
int count,src_router,i,j,k,w,v,min;
int cost_matrix[100][100],dist[100],last[100];
int flag[100];
printf("\nENTER THE NO OF ROUTERS:");
scanf("%d",&count);
printf("\nENTER THE COST MATRIX VALUES:");
for(i=0;i<count;i++)
{
 for(j=0;j<count;j++)
{
printf("\n%d->%d:",i,j);
scanf("%d",&cost_matrix[i][j]);
if(cost_matrix[i][j]<0)
cost_matrix[i][j]=1000;
}
}


printf("\n\t The COST MATRIX is : \n ");
for(i=0;i<count;i++)
  {
 for(j=0;j<count;j++)
  printf("%d\t",cost_matrix[i][j]);
  printf("\n");
   }
printf("\n ENTER THE SOURCE ROUTER:");
scanf("%d",&src_router);
for(v=0;v<count;v++)
  {
flag[v]=0;
last[v]=src_router;
dist[v]=cost_matrix[src_router][v];
  }
 flag[src_router]=1;
for(i=0;i<count;i++)
{
min=1000;
for(w=0;w<count;w++)
      {
if(!flag[w])
if(dist[w]<min)
{
v=w;
min=dist[w];
      }
  }
flag[v]=1;
for(w=0;w<count;w++)
            {
if(!flag[w])
if((min+cost_matrix[v][w])<dist[w])
{
dist[w]=min+cost_matrix[v][w];
last[w]=v;
  }    }   }
for(i=0;i<count;i++)
{
printf("\n%d==>%d:PATH TAKEN:%d",src_router,i,i);
w=i;
while(w!=src_router)
{
printf("\n<--%d",last[w]);
w=last[w];
}
printf("\nSHORTEST PATH COST:%d\n",dist[i]);
}
return(0);
}











OUTPUT
[11ca013@mcalinux network]$ cc 16ospf.c
[11ca013@mcalinux network]$  ./a.out

ENTER THE NO OF ROUTERS:3

ENTER THE COST MATRIX VALUES:
0->0:100

0->1:1

0->2:3

1->0:1

1->1:100

1->2:1

2->0:1

2->1:1

2->2:100

         The COST MATRIX is :
 100    1       3
1       100     1
1       1       100

 ENTER THE SOURCE ROUTER:2

2==>0:PATH TAKEN:0
<--2
SHORTEST PATH COST:1

2==>1:PATH TAKEN:1
<--2
SHORTEST PATH COST:1

2==>2:PATH TAKEN:2

SHORTEST PATH COST:100

0 Response to "SIMULATION OF ROUTING PROTOCOL (OSPF)"

Post a Comment



Your IP Address is:

Browser: