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

Lab 8 - Ospf - 20mis1115

The document describes an experiment on implementing the Open Shortest Path First (OSPF) routing protocol. It includes code to calculate the shortest paths between routers using Dijkstra's algorithm. The code takes a cost matrix and source router as input and outputs the shortest paths and costs to each router.

Uploaded by

Sam
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
0% found this document useful (0 votes)
31 views4 pages

Lab 8 - Ospf - 20mis1115

The document describes an experiment on implementing the Open Shortest Path First (OSPF) routing protocol. It includes code to calculate the shortest paths between routers using Dijkstra's algorithm. The code takes a cost matrix and source router as input and outputs the shortest paths and costs to each router.

Uploaded by

Sam
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
You are on page 1/ 4

SWE2002 – Computer Networks

Laboratory Manual

Lab - 08

Student Name Sam Prince Franklin


Reg Number 20MIS1115
Subject Code SWE2002
Slot L57,58
Faculty Dr. Noel Jeygar Robert
SWE2002 – Computer Networks
Lab Manual - Experiment – 08
OSPF

#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("\n Enter the no of routers");
scanf("%d", &count);
printf("\n Enter 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 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("\n Shortest path cost:%d", dist[i]);
}
}

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy