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

Exp 4

Download as pdf or txt
Download as pdf or txt
Download as pdf or txt
You are on page 1/ 4

EXPERIMENT NO – 4 ANAND JHA (2K21/EE/42)

Aim: Write a program to implement STOP and WAIT protocol.


Theory:

Stop and Wait Protocol is


• Used in Connection-oriented communication.
• It offers error and flow control.
• It is used in Data links and Transport Layers.
• Stop and Wait ARQ mainly implements the Sliding Window Protocol concept with Window Size 1.

Sender:
1. Send one data packet at a time.
2. Send the next packet only after receiving acknowledgment for the previous one.

Receiver:
1. Send acknowledgment after receiving and consuming of the data packet.
2. After consuming packet acknowledgment need to be sent (Flow Control).

Problems:

1. Lost Data

2. Lost Acknowledgement
3. Delayed Acknowledgement/Data: After a timeout on the sender side, a long-delayed acknowledgment might be
wrongly considered as acknowledgment of some other recent packet.

1. Time Out

2. Sequence Number (Data)

3. Delayed Acknowledgement This is resolved by introducing sequence number for acknowledgement also.
Algorithm:

At the sender (Node A)


1. Accept packet from higher layer when available.
2. Assign number SN to it.
3. Transmit packet SN in frame with sequence #SN.
4. Wait for an error-free frame from B:
a. is received and it contains RN greater than SN in the request #field, set SN 2 RN and go to 1
b. if not received within the given time go to 2 (with initial condition SN equal to zero)

At the receiver (Node B)


1. Whenever an error-free frame is received from a with a sequence # equal to RN release the received packet to
higher layers and increment RN.
2. At arbitrary times, but within bounded delay after receiving an error-free frame from A, transmit a frame to A
containing RN in the request # field(with initial condition RN equal to zero).

Program:

#include <iostream>
using namespace std;
void srq(int s[], int ack, int packets, int td, int pd, int rtt, int to)
{
int x = 0, delay_for_data = 0, delay_for_ack = 0;
for (int i = 0; i < packets; i++)
{
if (i % 2 == 0)
{
ack = 1;
}
else
ack = 0;
// delay_for_data=0;
// delay_for_ack=0;
if (i == 3)
delay_for_data = delay_for_data + 8;
x = x + td + delay_for_data;
if (td + delay_for_data < to)
{
cout << "packet " << i << " is sent at " << x << "sec \n";
x = x + rtt + delay_for_ack;
if (rtt + delay_for_ack < to)
cout << "Acknowledgment " << ack << " is received at " << x << " sec\n";
else
{
cout << "Acknowledgment " << ack << " lost\n";
i = i - 1;
delay_for_data = delay_for_data - 16;
}
}
else
{
cout << "packet " << i << " lost \n";
cout << "Acknowledgment " << ack << " lost\n";
i = i - 1;
delay_for_data = delay_for_data - 16;
}
}
}
int main()
{
int packets;
cout << "Enter the no of packets: ";
cin >> packets;
int a[packets]; // array of packets
int ack = 1;
int td, pd, rtt, to;
cout << "Enter transmission & Propagation Delay: ";
cin >> td >> pd;
rtt = 2 * pd;
to = 2 * rtt;
srq(a, ack, packets, td, pd, rtt, to);
return 0;
}

Output

Conclusion

The Stop and Wait protocol was discussed and implemented, and the outputs were verified.

You might also like