The difference between SR and GBN

Go-Back-N protocol and Selective-Repeat protocol are two important protocols used by computer network to realize reliable data transmission in transport layer and link layer. The TCP protocol of the Internet draws on the basic ideas of the above two protocols in design.

Go Back N Steps (GBN)

The Go Back N Step (GBN) protocol is also called == sliding window protocol ==, by controlling the size of the window to control the sending rate of the sender, and under the premise of the sliding window mechanism, it can make reliable data transmission ensure

Why is it called the "back N steps" agreement?

The name of the protocol "Go Back N Steps" comes from the sender's behavior in the event of lost and overly delayed packets. For these cases, the sender may resend the corresponding packet

We know that in order to distinguish different groups, we number these data groups.

In the GBN protocol, some special locations are named according to the current transmission situation of the sender:

  • Base sequence number (base): defines the sequence number of the earliest unconfirmed packet

  • Next sequence number (nextseqnum): defines the smallest unused sequence number

    The figure below is the serial number seen by the sender in GBN:

    [External link picture transfer failed, the source site may have an anti-theft link mechanism, it is recommended to save the picture and upload it directly (img-aLFHGj48-1660904058540) (D:\note\note warehouse\picture\20200220164803465.png)]

As shown in the figure above, the serial number range is divided into four segments:

  • [0, base - 1]: packets that have been sent and confirmed
  • [base, nextseqnum - 1]: packets that have been sent but not acknowledged
  • [nextseqnum, base + N - 1]: the packet to be sent
  • [base + N, ---------]: groups that are not yet available

The above-mentioned packets that have been sent but not confirmed and the == allowable range == of the packets to be sent can be regarded as a window with a length of N within the sequence number range. It is what we often call a sliding window. This window will continuously slide forward in the serial number space as the protocol runs.

The window length can be set based on the receiver's ability to receive and buffer messages, the level of congestion in the network, or both

Knowledge points that are conducive to understanding: In practice, the sequence number of the packet is carried in a fixed-length field in the header of the packet. Therefore, the size of the serial number is limited. If the field length is k, the range of the serial number is [0, 2 k - 1]. Therefore, for some serial numbers that are too long, a modulo 2 k operation must be performed

The following is the flow of the sender and receiver in the GBN protocol:

Three types of events to which a GBN sender must respond

  • Upper-layer call: When uploading calls to send data events, it will first check whether the sending window is full:
    • The window is not full: generate a packet and send it, and update the variable nextseqnum
    • The window is full: the sender only needs to return the data to the upper layer, implicitly indicating that the window is full, and then the upper layer may try again later. In a real implementation, it is more likely that the sender will cache this data and try to send it later. Or just use the synchronization mechanism directly . Only when the window is not full, the upper layer can call and send the event.
  • Received an ACK: In the GBN protocol (different from the SR protocol), the acknowledgment of the packet with the sequence number n adopts == cumulative confirmation ==, which means that after receiving the packet acknowledgment with the sequence number n, the receiver indicates that All packets including n before sequence number n have been sent to the receiver normally
  • Timeout event: If a timeout occurs, the sender will retransmit all sent but unacknowledged packets. (Note here that there is only one corresponding timeout retransmission timer)

GBN Receiver Responsive Events

  • If a packet with sequence number n is received correctly, andin order(That is, the serial number of the data delivered to the upper layer last time is n - 1), then the receiver sends an ACK for packet n, and delivers the data part to the upper layer.In all other cases (such as sequence numbers out of order) the packet will be lost( This is different from the SR protocol )

    Thinking, as long as the received packets are not in order, they will be lost, will the efficiency be too low?

    If a packet with a sequence number of 1...n, n+1 is sent now, if the packet of n+1 is received before the packet of n, then the packet with the sequence number of n + 1 will be discarded according to the above, so The efficiency is too low✖

    In this regard, the receiver of the GBN protocol may cache packet n + 1, wait until packet n is received and delivered, and then deliver the packet to the upper layer. However, if the packets with sequence number n are lost, they can only be retransmitted according to the retransmission rules of GBN. .

In the GBN protocol, the sender needs to maintain the upper and lower boundaries of the window and the position of nextsequnum in the window.

The only information that the receiver needs to maintain is the sequence number of the next packet received in sequence, which is stored in the expectedseqnum variable

The following picture shows the operation of the GBN protocol with a window length of 4 packets (picture found on the Internet):

It can be found that the No. 2 packet is lost during the sending process. When sending packets 4 and 5 later, the receiver finds that the sequence numbers are not in order, and all the received messages are discarded. It was not until the sender retransmitted the No. 2 packet that the subsequent packets were received normally.

For the GBN protocol, although it solves the problem that the channel utilization rate of the stop-and-wait protocol is too low, it still has certain performance problems. For example the following scenario:

When the window length and the bandwidth-delay product are large, or there are many packets in the pipeline. A single packet error may cause a large number of GBN retransmissions.


Selective Retransmission (SR)

In order to solve the situation that a large number of retransmissions may be caused when some single packet errors occur in the GBN protocol.The SR protocol only retransmits those packets that the sender believes have errors at the receiver, avoiding unnecessary retransmissions and greatly improving efficiency.

In addition to the above differences, the SR protocol is also different from GBN when receiving out-of-order packets:

  • SR receivers will acknowledge a correctly received packet regardless of its order(GBN must be ordered), out-of-order packets will be cachedUntil all the missing packets (that is, packets with lower sequence numbers) are received, this batch of packets can be delivered to the upper layer in sequence.

The following picture shows the operation of SR:

[External link picture transfer failed, the source site may have an anti-theft link mechanism, it is recommended to save the picture and upload it directly (img-xp9J5wPv-1660904058542)(D:\note\note warehouse\picture\image-20220819170344465.png)]

As shown in the above figure: packet 2 was lost when it was sent for the first time, but the receiver accepted packets 3, 4, and 5, but noticed thatAt this time, the receiver does not deliver data to the upper layer, until the sender times out and retransmits packet 2, and the receiver successfully receives it, then all packets are delivered to the upper layer.

After understanding the general process, let's talk about the events and actions of the SR receiver and sender in detail:

Events and actions of the SR sender

  1. Receive data from the upper layer : Similar to GBN, the SR sender will first check whether the next sequence number for the group is within the sliding window, and if so, pack it directly. If not, either cache or return the data to the upper layer, and then transmit it after a period of time
  2. Timeout : Timeout will retransmit the corresponding packet. (The main reason here is to transmit packets separately, so each packet has its own logical timer)
  3. Received ACK : There are two possible positions of the received ACK:
    1. The packet sequence number is within the window, and the SR sender marks the acknowledged packet as received
    2. If the packet sequence number is equal to send_base, the window base sequence number is moved to the unconfirmed packet with the smallest sequence number. If the sequence number falls within the window of unsent packets during the movement, send these packets

Events and Actions of the SR Receiver

  1. Packets with sequence numbers within [rcv_base, rcv_base + N - 1] are received correctly. If it falls within the receiving window, an ACK will be returned. If the packet has not been received before, the packet will be buffered.If the sequence number is equal to the base sequence number of the receive window, then the current cached packet sequence number will be delivered upwards,Then the receiving window slides forward. For example, after receiving packet 2 in the above figure, the packets 3, 4, and 5 in the cache before delivery are upward
  2. If the packet whose sequence number is in [rcv_base - N, rcv_base - 1] is received (it means that the packet has already been received), then an ACK will be returned. (The specific reason is that the windows of the receiver and the sender are not always consistent. If the ACK is not sent to the receiver, the window of the sender may not be able to move forward. It is easy to understand here and I will explain in detail)
  3. In other cases, ignore the grouping

The following are the dynamic diagrams of GBN and SR protocols losing packets

Mainly observe the differences in the following two aspects: the difference in how the receiver handles out-of-order packets after receiving them , and the difference in how the sender retransmits after timeout

  • Back N steps
    insert image description here

  • choose to retransmit

insert image description here

main difference

  • The GBN protocol uses cumulative confirmations, whereThe sender has a buffer and the receiver does not; The sender simultaneously times the encapsulated packet.

  • The receiver of the SR protocol sends a separate ACK for each packet, and both the sender and receiver have a buffer,The sender maintains a timer for each unencapsulated packet

1 receive buffer

  • For the GBN protocol, due toIt discards all out-of-order packets within the receiver window, so there is no need to have a buffer to store out-of-order packets within the receiver window. The receiver window size is 1.
  • For the SR protocol, since many unnecessary data packets are avoided from being retransmitted, the receiving endNeed to buffer out-of-order packets, where the window size is N.

2 Complexity of Implementation

  • The GBN protocol adopts a cumulative confirmation method. Because the receiver receives packets in order, any packets that arrive in error will be discarded by the receiver.
  • The SR protocol avoids the GBN protocol from retransmitting the correct data packets arriving at the receiver at the cost of simultaneously setting the sender window and the receiver window to have the same size. So basically, the SR protocol is more complicated than GBN, because the receiver of the SR protocol needs a buffer to confirm whether the packet is received correctly, whether it is in order or not.

3 Network Efficiency

The SR protocol is more efficient than the GBN protocol. In the GBN protocol, when the product delay of the window size and the bandwidth is large, an error in a data packet may cause GBN to resend a large number of data packets, while in the SR protocol, the order of many correct data packets does not need to be retransmitted during the process.

  • List the differences between the two protocols in the form of a table:
protocol sender buffer Receiver buffer packet timing Whether to receive the correct out-of-order package Cumulative Confirmation
GBN yes no synchronous timing no yes
SR yes yes independent timing yes no

This article refers to: "Computer Network Top-Down Method"
GBR backs N-step demo website
SR selects the retransmission demo website
Go-back-N (GBN) protocol & the difference between selective repeat (SR) protocol

Guess you like

Origin blog.csdn.net/qq_53578500/article/details/126429954