DELHI TECHNOLOGICAL UNIVERSITY
(Formerly Delhi College of Engineering)
Bawana Road, Delhi, 110042
Computer Network Lab File
SUBMITTED IN PARTIAL FULFILLMENT OF THE REQUIREMENTS FOR
THE AWARD OF PRACTICAL COMPONENT EVALUATION, SEMESTER-6
OF
BACHELOR OF TECHNOLOGY
IN
COMPUTER SCIENCE ENGINEERING
Submitted by: Asif Siyad, 2K19/CO/093
Under the Supervision of: Miss Shanu Bhardwaj
Index
S No. Date Experiment Signature
1 1/01/22 To implement different framing techniques using
C/C++:
Bit stuffing
Byte stuffing
2 1/02/22 Write a program to implement CRC (Cyclic
Redundancy Check).
3 8/02/22 Write a program to implement STOP and WAIT
protocol.
4 22/02/22 Write a program to implement sliding window
protocol.
5 8/03/22 Write a program to implement and find the class,
network and host ID from a given IPv4 address.
6 22/03/22 Write a program to implement the distance vector
routing algorithm.
7. 5/04/22 Write a program to implement the link-state
routing algorithm.
Program 1: To implement different framing techniques using C/C++:
Bit stuffing
Byte stuffing
Aim:
Programs To Implement bit and byte stuffing.
Theory:
Byte – Stuffing − A byte is stuffed in the message to differentiate from the delimiter. This is
also called character-oriented framing.
Bit – Stuffing − A pattern of bits of arbitrary length is stuffed in the message to differentiate
from the delimiter. This is also called bit – oriented framing.
Algo:
1) Start.
2) Read the bit sequence/ stream from user.
3) Measure the length of entered sequence.
4) Check each bit and count for consecutive 1’s in the bit pattern using
counter. 5) If the number if 1’s is exactly equal to 5 then attach bit 0
immediately after current position of bits.
6) Reset the counter.
7) Go to step 3 to repeat the steps till completion for remaining sequence.
8) Display the result by inserting bits “01111110” at source and destination
as a flags.
9) Stop.
Code:
Byte Stuffing:
#include<stdio.h>
#include<string.h>
int main(){
char frame[50][50],str[50][50];
char flag[10];
strcpy(flag,"flag");
char esc[10];
strcpy(esc,"esc");
int i,j,k=0,n;
strcpy(frame[k++],"flag");
printf("Enter no.of String :\t");
scanf("%d",&n);
printf("Enter String \n");
for(i=0;i<=n;i++)
gets(str[i]);
printf("You entered :\n");
for(i=0;i<=n;i++)
puts(str[i]);
printf("\n");
for(i=1;i<=n;i++)
if(strcmp(str[i],flag)!=0 && strcmp(str[i],esc)!=0)
{
strcpy(frame[k++],str[i]);
else
strcpy(frame[k++],"esc");
strcpy(frame[k++],str[i]); }
strcpy(frame[k++],"flag");
printf("After Byte stuffing:\n\n") ;
for(i=0;i<k;i++)
printf("%s\t",frame[i]);
return 0;
Bit Stuffing:
#include <bits/stdc++.h>
#include <iostream>
using namespace std;
void bitStuffing(int N, int arr[])
int brr[30];
int i, j, k;
i = 0;
j = 0;
int count = 1;
while (i < N)
if (arr[i] == 1)
brr[j] = arr[i];
for(k = i + 1; arr[k] == 1 && k < N && count < 5;
k++)
j++;
brr[j] = arr[k];
count++;
if (count == 5)
j++;
brr[j] = 0;
i = k;
}
else
brr[j] = arr[i];
i++;
j++;
for(i = 0; i < j; i++)
cout << brr[i];
}
int main()
int N = 6;
int arr[] = { 1, 1, 1, 1, 1, 1 };
bitStuffing(N, arr);;
return 0;
Output:
Byte Stuffing:
Bit Stuffing:
Discussion:
Writing efficient code for the required programs while maintaining readability and good logic
for the code.
Finding and Learning:
We have learnt what framing is, how framing works and the common approaches used to
tackle problems in framing: character-oriented protocols, where we learnt about byte
stuffing and bit oriented protocols, where we learnt about bit stuffing.
Program 2: Write a program to implement CRC (Cyclic Redundancy
Check).
Aim:
Program to Implement cyclic redundancy check.
Theory:
A cyclic redundancy check (CRC) is an error-detecting code commonly used in digital networks
and storage devices to detect accidental changes to raw data. Blocks of data entering these
systems get a short check value attached, based on the remainder of a polynomial division of
their contents. On retrieval, the calculation is repeated and, in the event the check values do
not match, corrective action can be taken against data corruption. CRCs can be used for error
correction.
Algo:
1) A string of n as is appended to the data unit. The length of predetermined divisor is n+
1. 2) The newly formed data unit i.e., original data + string of n as are divided by the
divisor using binary division and remainder is obtained. This remainder is called CRC.
3) Now, string of n 0’s appended to data unit is replaced by the CRC remainder (which is
also of n bit).
4) The data unit + CRC is then transmitted to receiver.
5) The receiver on receiving it divides data unit + CRC by the same divisor & checks
the remainder.
6) If the remainder of division is zero, receiver assumes that there is no error in data
and it accepts it.
7) If remainder is non-zero then there is an error in data and receiver rejects it.
Code:
#include <iostream>
#include <conio.h>
using namespace std;
int main()
{
int i, j, k, l;
//Get Frame
int fs;
cout << “\n Enter length of the data: “;
cin >> fs;
if (fs > 8)
cout << “Invalid Input”;
return 0;
int f[20];
cout << “\n Enter the data:”;
for (i = 0; i < fs; i++)
cin >> f[i];
//Get Generator
int gs;
cout << “\n Enter the length of Generator(Divisor):
“; cin >> gs;
int g[20];
cout << “\n Enter the
Generator(Divisor):”; for (i = 0; i < gs; i++)
{
cin >> g[i];
cout << “\n Sender Side:”;
//Append 0’s
int rs = gs – 1;
cout << “\n Number of 0’s to be appended: ” <<
rs; for (i = fs; i < fs + rs; i++)
f[i] = 0;
int temp[20];
for (i = 0; i < 20; i++)
temp[i] = f[i];
cout << “\n Message after appending 0’s :”;
for (i = 0; i < fs + rs; i++)
cout << temp[i];
//Division
for (i = 0; i < fs; i++)
j = 0;
k = i;
//check whether it is divisible or not
if (temp[k] >= g[j])
{
for (j = 0, k = i; j < gs; j++, k++)
if ((temp[k] == 1 && g[j] == 1) || (temp[k] == 0 && g[j] ==
0)) {
temp[k] = 0;
else
{
temp[k] = 1;
//CRC
int crc[15];
for (i = 0, j = fs; i < rs; i++, j++)
crc[i] = temp[j];
cout << “\n CRC bits: “;
for (i = 0; i < rs; i++)
cout << crc[i];
cout << “\n Transmitted Data: “;
int tf[15];
for (i = 0; i < fs; i++)
tf[i] = f[i];
for (i = fs, j = 0; i < fs + rs; i++, j++)
tf[i] = crc[j];
for (i = 0; i < fs + rs; i++)
cout << tf[i];
cout << “\n Receiver side : “;
cout << “\n Received Data: “;
for (i = 0; i < fs + rs; i++)
cout << tf[i];
for (i = 0; i < fs + rs; i++)
temp[i] = tf[i];
//Division
for (i = 0; i < fs; i++)
j = 0;
k = i;
if (temp[k] >= g[j])
for (j = 0, k = i; j < gs; j++, k++)
if ((temp[k] == 1 && g[j] == 1) || (temp[k] == 0 && g[j] ==
0)) {
temp[k] = 0;
else
temp[k] = 1;
cout << “\n Remainder: “;
int rrem[15];
for (i = fs, j = 0; i < fs + rs; i++, j++)
rrem[j] = temp[i];
for (i = 0; i < rs; i++)
cout << rrem[i];
int flag = 0;
for (i = 0; i < rs; i++)
{
if (rrem[i] != 0)
flag = 1;
if (flag == 0)
cout << “\n Since Remainder is 0, hence the”
” Message Transmitted from Sender to Receiver is
Correct”; }
else
cout << “\n Since Remainder is not 0,”
” hence the Message Transmitted from Sender to Receiver contains
Error”; }
getch();
}
Output:
Discussion:
Developing the various functions required for our task was challenging and required lots of
further study to be able to implement them efficiently and tweak the functionality of the
functions to meet the specific needs of the CRC program.
Finding and Learning:
We have learnt that CRC is mainly designed and used to protect against common errors on
communication channels and is not suitable for protection against intentional alteration of
data.
Program 3: Write a program to implement STOP and WAIT protocol.
Aim:
Program to Implement stop and wait protocol.
Theory:
Stop and wait protocol is the simplest flow control method. In this, the sender will
transmit one frame at a time to the receiver. The sender will stop and wait for the
acknowledgement from the receiver.
Algo:
Step 1: Start the program.
Step 2: Generate a random that gives the total number of frames to be transmitted.
Step 3: Transmit the first frame.
Step 4: Receive the acknowledgement for the first frame.
Step 5: Transmit the next frame
Step 6: Find the remaining frames to be sent.
Step 7: If an acknowledgement is not received for a particular frame retransmit that frame
alone again.
Step 8: Repeat the steps 5 to 7 till the number of remaining frames to be send becomes
zero.
Step 9: Stop the program.
Code:
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
void main()
int i,j,noframes,x,x1=10,x2;
clrscr();
for(i=0;i<200;i++)
rand();
noframes=rand()/200;
i=1;
j=1;
noframes = noframes / 8;
printf("\n number of frames is %d",noframes); getch();
while(noframes>0)
printf("\nsending frame %d",i);
srand(x1++);
x = rand()%10;
if(x%2 == 0)
for (x2=1; x2<2; x2++)
printf("waiting for %d seconds\n", x2);
sleep(x2);
}
printf("\nsending frame %d",i);
srand(x1++);
x = rand()%10;
printf("\nack for frame %d",j);
noframes-=1;
i++;
j++;
printf("\n end of stop and wait protocol"); getch();
Output:
No of frames is 6
Sending frame 1
Acknowledgement for frame 1
Sending frame 2
Acknowledgement for frame 2
Sending frame 3
Acknowledgement for frame 3
Sending frame 4
Acknowledgement for frame 4
Sending frame 5
Waiting for 1 second
Retransmitting frame 5
Acknowledgement for frame 5
Sending frame 6
Waiting for 1 second
Sending frame 6
Acknowledgement for frame 6
End of stop and wait protocol
Discussion:
The features of Stop and Wait Protocol are as follows −
• It is used in Connection-oriented communication.
• It offers error and flows control.
• It can be used in data Link and transport Layers.
• Stop and Wait ARQ executes Sliding Window Protocol with Window Size
Finding and Learning:
1. For noisy link, pure stop and wait protocol will break down, and solution is to
incorporate someerror control mechanism.
2. The main shortcoming of the stop-and-wait algorithm is that it allows the sender to
have only one outstanding frame on the link at a time. The sender should wait till it
gets an ACK of previous frame before it sends next frame. As a result, it wastes a
substantial amount of network bandwidth.
3. Stop and Wait ARQ may work fine where propagation delay is very less for example
LAN connections, but performs badly for distant connections like satellite
connection
Program 4: Write a program to implement sliding window protocol.
Aim:
To implement program for sliding window protocol.
Theory:
The sliding window is a technique for sending multiple frames at a time. It
controls the data packets between the two devices where reliable and gradual
delivery of data frames is needed. It is also used in TCP (Transmission Control
Protocol).
In this technique, each frame has sent from the sequence number. The
sequence numbers are used to find the missing data in the receiver end. The
purpose of the sliding window technique is to avoid duplicate data, so it uses
the sequence number.
Algo:
Go back n:
Step 1: Start the program.
Step 2: Generate a random that gives the total number of frames to be
transmitted.
Step 3: Set the size of the window.
Step 4: Generate a random number less than or equal to the size of the current
window
and identify the number of frames to be transmitted at a given time.
Step 5: Transmit the frames and receive the acknowledgement for the frames
sent.
Step 6: Find the remaining frames to be sent.
Step 7: Find the current window size.
Step 8: If an acknowledgement is not received for a particular frame retransmit
the
frames from that frame again.
Step 9: Repeat the steps 4 to 8 till the number of remaining frames to be send
becomes
zero.
Step 10: Stop the program.
Selective repeat:
Step 1: Start the program.
Step 2: Generate a random that gives the total number of frames to be
transmitted.
Step 3: Set the size of the window.
Step 4: Generate a random number less than or equal to the size of the current
window
and identify the number of frames to be transmitted at a given time.
Step 5: Transmit the frames and receive the acknowledgement for the frames
sent.
Step 6: Find the remaining frames to be sent.
Step 7: Find the current window size.
Step 8: If an acknowledgement is not received for a particular frame retransmit
that frame
alone again.
Step 9: Repeat the steps 4 to 8 till the number of remaining frames to be send
becomes
zero.
Step 10: Stop the program.
Code:
Go back n:
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
void main()
int temp1,temp2,temp3,temp4,i,winsize=8,noframes,moreframes;
char c;
int reciever(int);
int simulate(int);
clrscr();
temp4=0,temp1=0,temp2=0,temp3=0;
for(i=0;i<200;i++)
rand();
noframes=rand()/200;
printf("\n number of frames is %d",noframes);
getch();
moreframes=noframes;
while(moreframes>=0)
temp1=simulate(winsize);
winsize-=temp1;
temp4+=temp1;
if(temp4 >noframes)
temp4 = noframes;
for(i=temp3+1;i<=temp4;i++)
printf("\nsending frame %d",i);
getch();
temp2=reciever(temp1);
temp3+=temp2;
if(temp3 > noframes)
temp3 = noframes;
printf("\n acknowledgement for the frames up to %d",temp3);
getch();
moreframes-=temp2;
temp4=temp3;
if(winsize<=0)
winsize=8;
printf("\n end of sliding window protocol");
getch();
int reciever(int temp1)
int i;
for(i=1;i<100;i++)
rand();
i=rand()%temp1;
return i;
}
int simulate(int winsize)
int temp1,i;
for(i=1;i<50;i++)
temp1=rand();
if(temp1==0)
temp1=simulate(winsize);
i = temp1%winsize;
if(i==0)
return winsize;
else
return temp1%winsize;
Selective repeat:
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
void main()
int temp1,temp2,temp3,temp4,temp5,i,winsize=8,noframes,moreframes;
char c;
int reciever(int);
int simulate(int);
int nack(int);
clrscr();
temp4=0,temp1=0,temp2=0,temp3=0,temp5 = 0;
for(i=0;i<200;i++)
rand();
noframes=rand()/200;
printf("\n number of frames is %d",noframes);
getch();
moreframes=noframes;
while(moreframes>=0)
temp1=simulate(winsize);
winsize-=temp1;
temp4+=temp1;
if(temp4 >noframes)
temp4 = noframes;
for(i=noframes - moreframes;i<=temp4;i++)
printf("\nsending frame %d",i);
getch();
temp2=reciever(temp1);
temp3+=temp2;
if(temp3 > noframes)
temp3 = noframes;
temp2 = nack(temp1);
temp5+=temp2;
if (temp5 !=0)
printf("\n No acknowledgement for the frame %d",temp5);
getch();
for(i=1;i<temp5;i++)
printf("\n Retransmitting frame %d",temp5);
getch();
moreframes-=temp1;
if(winsize<=0)
winsize=8;
printf("\n end of sliding window protocol Selective Reject");
getch();
int reciever(int temp1)
int i;
for(i=1;i<100;i++)
rand();
i=rand()%temp1;
return i;
int nack(int temp1)
int i;
for(i=1;i<100;i++)
rand();
i=rand()%temp1;
return i;
int simulate(int winsize)
int temp1,i;
for(i=1;i<50;i++)
temp1=rand();
if(temp1==0)
temp1=simulate(winsize);
i = temp1%winsize;
if(i==0)
return winsize;
else
return temp1%winsize;
}
Output:
Go back n:
Number of frames: 55
Sending frame 1
Sending frame 2
Sending frame 3
Acknowledgement for the frames upto 0
Sending frame 1
Acknowledgement for the frames upto 0
Sending frame 1
Sending frame 3Sending frame 4
Acknowledgement for the frames upto 4
Acknowledgement for the frames upto 54
Sending frame 55
Acknowledgement for the frames upto 55
End of sliding window protocol
Selective repeat:
Number of frames: 55
Sending frame 1
Sending frame 2
Sending frame 3
Sending frame 4
No Acknowledgement for the frame 2
Retransmitting frame 2
Sending frame 5
Sending frame 6
No Acknowledgement for the frame 2
Retransmitting frame 2
Sending frame 3
Sending frame 4
No Acknowledgement for the frame 4
Sending frame 54
Sending frame 55
End of sliding window protocol
Discussions:
A sliding window protocol ensures a balanced approach to packet delivery by
controlling and optimising packet flow between a sender and receiver. The
protocol requires the receiver to acknowledge receipt of each data packet and
allows the receiver to confirm the delivery of several packets with a single
acknowledgement (ACK).
To handle the flow of data packets, the receiver keeps a buffer. The receive
buffer stores packets that have been sent but not yet processed by the sender.
The sender is informed of the amount of free space in the receive buffer by the
receiver during data transmission. This area is known as the receive window,
and it is defined as the buffer size minus the quantity of unprocessed data.
The sender cannot send more data packets than the amount of space available
in the receive window.
Findings and Learnings:
Retransmitting frames costs a lot of bandwidth on mediums with high error
rates, when packet sizes are exceedingly high, substantial buffers on the
sender side may be required to hold them and on mediums with low
transmission delays, one works nicely.
Program 5: Write a program to implement and find the class,
network and host ID from a given IPv4 address.
Aim:
To implement and find the class, network and host ID from a given IPv4 address.
Theory:
Given a valid IPv4 address in the form of string and it follows Class Full addressing. The task
is to determine the class of the given IPv4 address as well as separate the Network and
Host ID parts from it.
Algo:
1. For determining the class: The idea is to check the first octet of the IP addresses. As
we know, for class A first octet will range from 1 – 126, for class B first octet will
range from 128 – 191, for class C first octet will range from 192- 223, for class D first
octet will range from 224 – 239, for class E first octet will range from 240 – 255.
2. For determining the Network and Host ID: We know that Subnet Mask for Class A is
8, for Class B is 16 and for Class C is 24 whereas Class D and E are not divided into
Network and Host ID.
Code:
#include<stdio.h>
#include<string.h>
char findClass(char str[])
char arr[4];
int i = 0;
while (str[i] != '.')
arr[i] = str[i];
i++;
i--;
int ip = 0, j = 1;
while (i >= 0)
ip = ip + (str[i] - '0') * j;
j = j * 10;
i--;
if (ip >=1 && ip <= 126)
return 'A';
else if (ip >= 128 && ip <= 191)
return 'B';
else if (ip >= 192 && ip <= 223)
return 'C';
else if (ip >= 224 && ip <= 239)
return 'D';
else
return 'E';
void separate(char str[], char ipClass)
char network[12], host[12];
for (int k = 0; k < 12; k++)
network[k] = host[k] = '\0';
if (ipClass == 'A')
int i = 0, j = 0;
while (str[j] != '.')
network[i++] = str[j++];
i = 0;
j++;
while (str[j] != '\0')
host[i++] = str[j++];
printf("Network ID is %s\n", network);
printf("Host ID is %s\n", host);
else if (ipClass == 'B')
int i = 0, j = 0, dotCount = 0;
while (dotCount < 2)
network[i++] = str[j++];
if (str[j] == '.')
dotCount++;
i = 0;
j++;
while (str[j] != '\0')
host[i++] = str[j++];
printf("Network ID is %s\n", network);
printf("Host ID is %s\n", host);
else if (ipClass == 'C')
int i = 0, j = 0, dotCount = 0;
while (dotCount < 3)
network[i++] = str[j++];
if (str[j] == '.')
dotCount++;
i = 0;
j++;
while (str[j] != '\0')
host[i++] = str[j++];
printf("Network ID is %s\n", network);
printf("Host ID is %s\n", host);
}
else
printf("In this Class, IP address is not"
" divided into Network and Host ID\n");
int main()
char str[] = "192.226.12.11";
char ipClass = findClass(str);
printf("Given IP address belongs to Class %c\n",
ipClass);
separate(str, ipClass);
return 0;
Output:
Findings and learnings:
1. IPv4 is a connectionless protocol for use on packet-switched networks. It operates on a
best effort delivery model, in that it does not guarantee delivery, nor does it assure proper
sequencing or avoidance of duplicate delivery.
2. IPv4 addresses may be represented in any notation expressing a 32-bit integer value.
They are most often written in the dot-decimal notation, which consists of four octets of
the address expressed individually in decimal numbers and separated by periods.
3. To overcome under utilization of IP addresses in class based systems, classless addresses
have been proposed.
Program 6: Write a program to implement the distance vector
routing algorithm.
Aim:
To implement the distance vector routing algorithm.
Theory:
In this algorithm, each router evaluates the distance between itself and every achievable
destination. This is accomplished by assessing the distance between a router and all of its
immediate router neighbours and adding each neighbouring routers computations for the
distance between that neighbour and its close neighbours.
Algo:
At each node x,
Initialization
for all destinations y in N:
Dx(y) = c(x,y) // If y is not a neighbor then c(x,y) = ∞
for each neighbor w
Dw(y) = ? for all destination y in N.
for each neighbor w
send distance vector Dx = [ Dx(y) : y in N ] to w
loop
wait(until I receive any distance vector from some neighbor w)
for each y in N:
Dx(y) = minv{c(x,v)+Dv(y)}
If Dx(y) is changed for any destination y
Send distance vector Dx = [ Dx(y) : y in N ] to all neighbors
forever
Code:
#include<stdio.h>
struct node
unsigned dist[20];
unsigned from[20];
}rt[10];
int main()
int costmat[20][20];
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:
Discussions:
In Distance Vector Routing: 1. Only distance vectors are exchanged. 2. “Next hop”values are
not exchanged. This is because it results in exchanging the large amount of data which
consumes more bandwidth. 3. While preparing a new routing tableA router takes into
consideration only the distance vectors it has obtained from its neighboring routers. 4. It
does not take into consideration its old routing table. The algorithm keeps on repeating
periodically and never stops. This is to update the shortest path in case any link goes down
or topology changes. Routing tables are prepared total (n-1) times if there are n routers in
the given network. This is because shortest path between any 2 nodes contains at most n-
1 edges if there are n nodes in the graph
Findings and learnings:
We learnt about distance vector routing algorithm and its implementation and significance
in computer networks.
Program 7: Write a program to implement the link-state routing
algorithm.
Aim:
To implement the link-state routing algorithm.
Theory:
Initialization
N = {A} // A is a root node.
for all nodes v
if v adjacent to A
then D(v) = c(A,v)
else D(v) = infinity
loop
find w not in N such that D(w) is a minimum.
Add w to N
Update D(v) for all v adjacent to w and not in N:
D(v) = min(D(v) , D(w) + c(w,v))
Until all nodes in N
Code:
#include<iostream>
#define ll long long int #define pb push_back #define ff first
#define ss second #define mod 1000000007
using namespace std;
int main()
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int count,src_router,i,j,w,v,min;
int cost_matrix[100][100],dist[100],last[100];
int flag[100];
cout<<"\nEnter the no of routers : "; cin>>count;
cout<<"\nEnter the cost matrix values :\n";
for(i=0;i<count;i++)
for(j=0;j<count;j++)
cin>>cost_matrix[i][j]; if(cost_matrix[i][j]<0)
{
cost_matrix[i][j]=1000;
cout<<"\nEnter the source router : ";
cin>>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] && 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++)
cout<<"\n"<<src_router<<"==> "<<i<<" :\nPath taken : "<<i; w=i;
while(w!=src_router)
cout<<"<--"<<last[w]; w=last[w];
cout<<"\nShortest path cost : "<<dist[i];
}
return 0;
Output:
Discussions:
Link State protocols in comparison to Distance Vector protocols have:
1. It requires large amount of memory.
2. Shortest path computations require many CPU circles.
3. If network use the little bandwidth ; it quickly reacts to topology changes.
4. All items in the database must be sent to neighbors to form link state packets.
5. All neighbors must be trusted in the topology.
6. Authentication mechanisms can be used to avoid undesired adjacency and problems.
7. No split horizon techniques are possible in the link state routing.
Findings and learnings:
We learnt about link state routing protocol and its implementation and significance in
computer networks.