Sliding window is an interesting concept. In terms of TCP, receiver’s window represents the amount of data that the receiver is willing to accept.
The Sliding window is a problem-solving technique for problems that involve arrays/lists. These problems are easy to solve using a brute force approach in O(n^2) or O(n^3). Using the 'sliding window' technique, we can reduce the time complexity to O(n). SIMULATE AND IMPLEMENT SELECTIVE REPEAT SLIDING WINDOW PROTOCOL PROGRAM IN DEV C-//ducslectures.blogspot.in #include using namespace std; #include #include #include #include #define TOTFRAMES 500. 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. Here you will get a sliding window protocol program in C. In PC systems sliding window, the protocol is a technique to transmit information on a system. Sliding window protocol is applied to the Data Link Layer of the OSI model. At information connection layer information is as edges.
In this article, we will cover TCP sliding window concept and aspects related to it.
Quick Sender, Slow Receiver
Before learning the sliding window concept, lets first discuss a scenario where sender is quick to send data while receiver is a bit slow to accept it. Suppose sender sends three data segments (seg1, seg2 and seg3) each of 4096 bytes and starts waiting for the acknowledgement from the receiver.
Now, if these 3 segments fill up all the TCP buffers of the receiver then receiver will advertise a window size of 0. The window size zero means that receiver cannot accept any more data at this moment. Whenever buffers are available, a non zero window size would be advertised by the receiver.
TCP Sliding Window
The process described in last section is good on receiver’s part but sender has to maintain a window on its side too. This window covers unacknowledged data and the data it can send keeping in mind the window size advertised by the receiver.
Following figure should give you an idea about how a sliding window looks like :
In the figure shown above :
- The available window advertised by the receiver is 6. This means that receiver can accept 6 bytes as of now.
- The window at sender side covers bytes ranging from 13 to 18 (I.e. 6 bytes in total).
- Out of this range, 13-15 are the bytes which have been sent but no acknowledgement is yet received for them.
- Bytes 16-18 are the bytes that sender can send as soon as possible.
- If sender starts receiving acknowledgement for bytes 13 to 15, the left end of the window starts closing in.
- The right end starts opening up as more and more window size is advertised by the receiver.
- This window slides towards right depending upon how fast receiver consumes data and sends acknowledgement and hence known as sliding window.
On a related note, it is also helpful for you to understand how TCP attacks and ARP cache poisoning works.
Some more points related to sliding windows :
- The receiver can send acknowledgement even before its window fills up completely.
- The left edge of the window can move towards right.
- Neither left edge should move towards left nor right edge should move towards left.
If you enjoyed this article, you might also like..
Next post: How to Enable RabbitMQ Management Plugin and Create New User
Previous post: How to Remove Files Older than N days using tmpreaper in Linux
- Related Questions & Answers
- Selected Reading
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. Sliding window method is also known as windowing.
Working Principle
In these protocols, the sender has a buffer called the sending window and the receiver has buffer called the receiving window.
The size of the sending window determines the sequence number of the outbound frames. If the sequence number of the frames is an n-bit field, then the range of sequence numbers that can be assigned is 0 to 2𝑛−1. Consequently, the size of the sending window is 2𝑛−1. Thus in order to accommodate a sending window size of 2𝑛−1, a n-bit sequence number is chosen.
The sequence numbers are numbered as modulo-n. For example, if the sending window size is 4, then the sequence numbers will be 0, 1, 2, 3, 0, 1, 2, 3, 0, 1, and so on. The number of bits in the sequence number is 2 to generate the binary sequence 00, 01, 10, 11.
The size of the receiving window is the maximum number of frames that the receiver can accept at a time. It determines the maximum number of frames that the sender can send before receiving acknowledgment.
Example
Suppose that we have sender window and receiver window each of size 4. So the sequence numbering of both the windows will be 0,1,2,3,0,1,2 and so on. The following diagram shows the positions of the windows after sending the frames and receiving acknowledgments.
Types of Sliding Window Protocols
Sliding Window Protocol In C
The Sliding Window ARQ (Automatic Repeat reQuest) protocols are of two categories −
Sliding Window Protocol In Computer Network In Hindi
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.
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.