Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
138 views8 pages

CNSL-Assignment - 4

Ok

Uploaded by

suyashghotekar59
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)
138 views8 pages

CNSL-Assignment - 4

Ok

Uploaded by

suyashghotekar59
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/ 8

310247 -Computer Networks & Security Lab (2019 Course) -SEM- V

Assignment: 4

Aim : Write a program to simulate Go back N and Selective Repeat Modes of Sliding
Window Protocol in Peer-to-Peer mode.

Outcome: Understand the concepts of how Go Back n and Selective repeat modes
of Sliding window protocol works in peer-to-peer mode.

S/W packages and hardware used : C++

Introduction:

Here is a simple Go-Back-N Sliding Window Protocol in Peer-to-Peer mode:

Sender:

1. Initialize the next sequence number to 0.


2. Send the next frame.
3. Increment the next sequence number.
4. Wait for an acknowledgment (ACK) from the receiver.
5. If an ACK is received for frame N, continue sending frames from N+1.
6. If an ACK is not received within a timeout period, retransmit all frames from
the next sequence number.
7. Repeat steps 2-6 until all frames have been sent and acknowledged.

Receiver:

1. Initialize the expected sequence number to 0.


2. Receive the next frame.
3. If the frame's sequence number is equal to the expected sequence number,
process the frame and increment the expected sequence number.
4. If the frame's sequence number is not equal to the expected sequence
number, discard the frame and send a negative acknowledgment (NACK) for
the expected sequence number.
5. Repeat steps 2-4 until all frames have been received and processed.

This protocol is called Go-Back-N because the sender goes back to retransmitting all
frames from the next sequence number if an ACK is not received for a frame. This
protocol is simple to implement, but it is not very efficient because it can waste
bandwidth retransmitting frames that have already been received by the receiver.

Here is an example of how the Go-Back-N Sliding Window Protocol might be used to
transfer a file from one computer to another:

Department of Computer Engineering, GES’s R H Sapat COEMSR, Nashik -5


310247 -Computer Networks & Security Lab (2019 Course) -SEM- V

1. The sender sends the first frame of the file to the receiver.
2. The receiver receives the frame and sends an ACK to the sender.
3. The sender sends the next frame of the file to the receiver.
4. The receiver receives the frame and sends an ACK to the sender.
5. The sender continues sending frames and the receiver continues sending
ACKs until the entire file has been transferred.

If a frame is lost or corrupted, the receiver will not send an ACK for that frame. The
sender will timeout and retransmit all frames from the next sequence number. This
ensures that the receiver will eventually receive all of the frames in the file.

Fig. Go-Back-N Protocol of Sliding window protocol

Selective Repeat is a more efficient version of the Go-Back-N Sliding Window


Protocol. Instead of retransmitting all frames from the next sequence number if an
ACK is not received for a frame, the sender only retransmits the frame that was not
acknowledged. This can save a lot of bandwidth on unreliable networks.

Here is a simple Selective Repeat Sliding Window Protocol in Peer-to-Peer mode:

Sender:

1. Initialize the next sequence number to 0.


2. Send the next frame.
3. Increment the next sequence number.
4. Wait for an acknowledgment (ACK) from the receiver.
5. If an ACK is received for frame N, remove frame N from the list of
unacknowledged frames.

Department of Computer Engineering, GES’s R H Sapat COEMSR, Nashik -5


310247 -Computer Networks & Security Lab (2019 Course) -SEM- V

6. If an ACK is not received for frame N within a timeout period, retransmit frame
N.
7. Repeat steps 2-6 until all frames have been sent and acknowledged.

Receiver:

1. Initialize the expected sequence number to 0.


2. Receive the next frame.
3. If the frame's sequence number is equal to the expected sequence number,
process the frame and increment the expected sequence number.
4. If the frame's sequence number is not equal to the expected sequence
number, buffer the frame and send a negative acknowledgment (NACK) for
the expected sequence number.
5. When an ACK is received for frame N, remove frame N from the buffer and
process it.
6. Repeat steps 2-5 until all frames have been received and processed.

This protocol is called Selective Repeat because the sender only retransmits the
frames that have not been acknowledged. This is more efficient than the Go-Back-N
Protocol because it does not waste bandwidth retransmitting frames that have
already been received by the receiver.

Here is an example of how the Selective Repeat Sliding Window Protocol might be
used to transfer a file from one computer to another:

1. The sender sends the first frame of the file to the receiver.
2. The receiver receives the frame and sends an ACK to the sender.
3. The sender sends the next frame of the file to the receiver.
4. The receiver loses the second frame.
5. The receiver times out and sends a NACK for the second frame.
6. The sender retransmits only the second frame.
7. The receiver receives the second frame and sends an ACK to the sender.
8. The sender sends the next frame of the file to the receiver.
9. The receiver continues receiving and processing frames until the entire file
has been transferred.

In this example, the sender only had to retransmit one frame because of the
Selective Repeat Protocol. If the Go-Back-N Protocol had been used, the sender
would have had to retransmit all frames from the next sequence number, which
would have wasted a lot of bandwidth.

Department of Computer Engineering, GES’s R H Sapat COEMSR, Nashik -5


310247 -Computer Networks & Security Lab (2019 Course) -SEM- V

Fig. Selective Repeat Protocol of Sliding window protocol

Program using C++:


#include <iostream>
#include <vector>
#include <string>

using namespace std;

enum class Mode {


GoBackN,
SelectiveRepeat
};

class Frame {
public:
int sequence_number;
string data;

Frame(int sequence_number, string data) : sequence_number(sequence_number),


data(data) {}
};

class SlidingWindowProtocol {
public:
SlidingWindowProtocol(int window_size, Mode mode) : window_size(window_size),
mode(mode), next_sequence_number(0), expected_sequence_number(0) {}

void send_frame(Frame frame) {

Department of Computer Engineering, GES’s R H Sapat COEMSR, Nashik -5


310247 -Computer Networks & Security Lab (2019 Course) -SEM- V

// Send the frame to the receiver.


cout << "Sending frame " << frame.sequence_number << endl;

// If the mode is Go-Back-N, increment the next sequence number.


if (mode == Mode::GoBackN) {
next_sequence_number++;
}
}

void receive_frame(Frame frame) {


// If the mode is Selective Repeat, check if the frame is expected.
if (mode == Mode::SelectiveRepeat && frame.sequence_number !=
expected_sequence_number) {
// If the frame is not expected, send a NACK.
cout << "Sending NACK for frame " << frame.sequence_number << endl;
return;
}

// If the frame is expected, process it.


cout << "Received frame " << frame.sequence_number << endl;
expected_sequence_number++;

// If the mode is Go-Back-N, retransmit all frames from the next sequence number
up to the expected sequence number.
if (mode == Mode::GoBackN) {
for (int i = next_sequence_number; i < expected_sequence_number; i++) {
Frame retransmitted_frame(i, "Retransmitted frame");
send_frame(retransmitted_frame);
}
}
}

private:
int window_size;
Mode mode;
int next_sequence_number;
int expected_sequence_number;
};

int main() {
// Create a sliding window protocol with a window size of 3 and Selective Repeat
mode.
SlidingWindowProtocol protocol(3, Mode::SelectiveRepeat);

Department of Computer Engineering, GES’s R H Sapat COEMSR, Nashik -5


310247 -Computer Networks & Security Lab (2019 Course) -SEM- V

// Send 5 frames.
for (int i = 0; i < 5; i++) {
Frame frame(i, "Frame " + to_string(i));
protocol.send_frame(frame);
}

// Receive a frame.
Frame received_frame(0, "Received frame");
protocol.receive_frame(received_frame);

// Receive another frame.


received_frame = Frame(2, "Received frame");
protocol.receive_frame(received_frame);

// Receive the last frame.


received_frame = Frame(4, "Received frame");
protocol.receive_frame(received_frame);

return 0;
}

Conclusion:

The Go-Back-N Sliding Window Protocol is a reliable way to transfer data between
two computers, but it is not the most efficient protocol. There are other protocols,
such as Selective Repeat, that are more efficient but more complex to implement.

Selective Repeat is a more efficient and reliable way to transfer data between two
computers than the Go-Back-N Protocol. It is the most commonly used Sliding
Window Protocol in TCP/IP networks.

References:
1. Kurose, Ross Computer Networking a Top Down Approach Featuring the Internet
Pearson
2. Computer Networks by Andrew S. Tanenbaum
3. Data Communications and Networking by Behrouz A. Forouzan

Department of Computer Engineering, GES’s R H Sapat COEMSR, Nashik -5


310247 -Computer Networks & Security Lab (2019 Course) -SEM- V

Oral Questions:
Here are some oral questions on the Go-Back-N Sliding Window Protocol:

● What is the Go-Back-N Sliding Window Protocol?


● What are the advantages and disadvantages of the Go-Back-N Sliding
Window Protocol?
● How does the Go-Back-N Sliding Window Protocol ensure reliable data
transfer?
● What is the difference between the Go-Back-N Sliding Window Protocol and
the Selective Repeat Sliding Window Protocol?
● Which protocol is more efficient, Go-Back-N or Selective Repeat?
● What are some examples of where the Go-Back-N Sliding Window Protocol is
used?

Here are some more specific oral questions:

● What happens if the sender does not receive an ACK for a frame?
● What happens if the receiver receives a frame out of order?
● What happens if the receiver loses a frame?
● How does the Go-Back-N Sliding Window Protocol handle flow control?
● What is the window size in the Go-Back-N Sliding Window Protocol?

Here are some oral questions on the Selective Repeat Mode of Sliding Window
Protocol:

General

● What is the Selective Repeat Mode of Sliding Window Protocol?


● What are the advantages and disadvantages of the Selective Repeat Mode of
Sliding Window Protocol?
● How does the Selective Repeat Mode of Sliding Window Protocol ensure
reliable data transfer?
● What is the difference between the Selective Repeat Mode of Sliding Window
Protocol and the Go-Back-N Sliding Window Protocol?
● Which protocol is more efficient, Selective Repeat or Go-Back-N?

Department of Computer Engineering, GES’s R H Sapat COEMSR, Nashik -5


310247 -Computer Networks & Security Lab (2019 Course) -SEM- V

● What are some examples of where the Selective Repeat Mode of Sliding
Window Protocol is used?

Specific

● What happens if the sender does not receive an ACK for a frame?
● What happens if the receiver receives a frame out of order?
● What happens if the receiver loses a frame?
● How does the Selective Repeat Mode of Sliding Window Protocol handle flow
control?
● What is the window size in the Selective Repeat Mode of Sliding Window
Protocol?
● How does the Selective Repeat Mode of Sliding Window Protocol improve the
efficiency of the Go-Back-N Sliding Window Protocol?

Here are some additional oral questions that you can ask:

● What is the relationship between the Selective Repeat Mode of Sliding


Window Protocol and the Cumulative ACK?
● How does the Selective Repeat Mode of Sliding Window Protocol handle
NAKs?
● How does the Selective Repeat Mode of Sliding Window Protocol prevent
duplicate ACKs?
● How does the Selective Repeat Mode of Sliding Window Protocol handle
congestion?
● What are some of the challenges in implementing the Selective Repeat Mode
of Sliding Window Protocol?

Department of Computer Engineering, GES’s R H Sapat COEMSR, Nashik -5

You might also like