0% found this document useful (0 votes)
3 views3 pages

Exp 5

experiment 5
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views3 pages

Exp 5

experiment 5
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

EXPERIMENT NO – 5

ANAND JHA (2K21/EE/42)

Aim: Write a program to implement sliding window protocol.


Theory:

Sliding window protocols are data link layer protocols for reliable and sequential delivery of data frames. The sliding
window is also used in Transmission Control Protocol. In this protocol, multiple frames can be sent by a sender at a
time before receiving an acknowledgment from the receiver. The term sliding window refers to the imaginary boxes to
hold frames. The sliding window method is also known as windowing. The Sliding Window ARQ (Automatic Repeat
Request) protocols are of two categories:

1. Go – Back – N ARQ: Go – Back – N ARQ provides for sending multiple frames before receiving the
acknowledgment for the first frame. It uses the concept of sliding window, and so is also called sliding window
protocol. The frames are sequentially numbered and a finite number of frames are sent. If the acknowledgment of a
frame is not received within the time period, all frames starting from that frame are retransmitted.
2. Selective Repeat ARQ: This protocol also provides for sending multiple frames before receiving the
acknowledgment for the first frame. However, here only the erroneous or lost frames are retransmitted, while the good
frames are received and buffered

Algorithm:

Step 1: Start the program.


Step 2: Open the input file in read mode.
Step 3: Read the size of the window.
Step 4: Select randomly the number of packets to be transferred.
Step 5: Read the content of the input file.
Step 6: Transfer the packet until it reaches the maximum defined size.
Step 7: Resume the window size and repeat the above two steps until the packets are in.
Step 8: Close the file.
Step 9: Stop the program.

Program:

include <bits/stdc++.h>
using namespace std;
int reciever(int temp1)
{
int i;
for (i = 1; i < 100; i++)
rand();
i = rand() % temp1;
return i;
}
int nack(int templ)
{
int i;
for (i = 1; i < 100; i++)
rand();
i = rand() % templ;
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;
}
int main()
{
int temp1, temp2, temp3, temp4, temp5, i, winsize = 8,noframes, moreframes;
char c;
temp4 = 0, temp1 = 0, temp2 = 0, temp3 = 0, temp5 = 0;

// noframes = 14000 / 200;


noframes=10;
cout << "No of frame is: " << noframes << endl;
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);
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);
for (i = 1; i < temp5; i++)
printf("\n Retransmitting frame %d", temp5);
}
moreframes -= temp1;
if (winsize <= 0)
winsize = 8;
}
printf("\n End of sliding window protocol Selective Reject");
}
Output

Conclusion

The Sliding Window protocol was discussed and implemented, and the outputs were verified.

You might also like