Data link layer (top)

@TOC

Table of contents

1. Links, data links and frames

1.Link

2.Data link

3. Frame

2. Three important issues in the data link layer

1. Encapsulation into framing and transparent transmission

1.1 Encapsulation into framing

1.2 Transparent transmission

1.2.1 Byte padding

1.2.2 bit padding

2. Error detection

2.1 Parity effect

2.2 Cyclic redundancy check

3. Reliable transmission

3.1 Basic concepts

3.2 Implementation mechanism of reliable transmission——stop-wait coordination SW

3.3 Fallback n-frame protocol

3.3.1 Features

3.3.2 Specific process

3.3.3 Advantages

3.3.4 Disadvantages

3.4 Select retransmission protocol

3. Point-to-point protocol

PPP frame format

PPP transparent transmission

Transparent transmission of PPP frames

PPP frame error detection

PPP working status


1. Links, data links and frames

1.Link

       A link is a physical line (wired or wireless) from one node to an adjacent node without any other switching nodes in between.

2.Data link

        When data is transmitted on a link, not only the link itself is needed, but also some necessary communication protocols are needed to control the transmission of these data. Adding the hardware and software that implements these protocols to the link forms a data link. .

3. Frame

       A frame is a protocol data unit (PDU) for logical communication in the horizontal direction between data link layer peer entities.

  (Note: An entity refers to any hardware or software process that can send or receive signals.

              Peer entities refer to entities at the same level of communication parties. )

2. Three important issues in the data link layer

1. Encapsulation into framing and transparent transmission

1.1 Encapsulation into framing

Encapsulation into frames means that the data link layer adds a frame header and a frame trailer to the protocol data unit PDU delivered by the upper layer to form a frame.

The header and trailer of the frame contain some important control information.

How does the receiver's data link layer extract frames from the bit stream delivered by the physical layer?

Answer:The function of frame header and frame trailer is frame delimitation

        The picture above is the format of the PPP protocol frame. There will be a 1B mark at the beginning and end of the frame. But not all frames have frame delimitation flags at the beginning and at the end. As shown in the picture:

        After Ethernet encapsulates the MACz frame, it will be delivered to the physical layer. The physical layer will add an 8-byte preamble to the frame, and then It is converted into an electrical signal and transmitted. It should be noted that in the 8-byte preamble,the first 7 bytes are the preamble. The purpose In order to synchronize the receiver's clock, is the delimiter for the beginning of the 1-byte frame< /span>. Ethernet specifies an inter-frame spacing of 96 bits, MAC frames do not require an end-of-frame delimiter, indicating that it is followed by a MAC frame. Because

        In order to improve the efficiency of transmitting frames at the data link layer, the length of the data payload of the frame should be as large as possible greater than the length of the header and tail.

        Considering the demand for cache space and error control and many other factors, each data link layer protocol specifies the upper limit of the length of the data load of the frame, that is, the Maximum Transfer Unit (MTU).

1.2 Transparent transmission

 Transparent transmission means that the data link layer does not have any restrictions on the transmission data delivered by the upper layer, as if the data link layer does not exist.

       As shown in the figure, the sender sends a frame, but the data part of the frame contains a string of data that is the same as the frame delimiter. In order to prevent the receiver from mistaking the string of data for the frame delimiter when receiving data, you can pass There are two methods for transparent transmission.

1.2.1 Byte padding

When using a byte-oriented physical link, use the byte stuffing method to achieve transparent transmission. Before sending the frame, the frame should be scanned before transmission. When the data load appears with data consistent with the frame delimiter, It is modified by an escape character (hexadecimal value is 1B). At the same time, if the same data as the escape character appears, the escape character should be added in front of the data.

1.2.2 bit padding

       When using a bit-oriented physical link, the bit stuffing method is used to achieve transparent transmission. For example, when a data link layer protocol uses a specific bit string of 8 bits 0111 1110 as the frame delimiter, the sender scans the data load of the frame before sending the frame. Once 5 consecutive bits of 1 appear, Just add bit 0 after it to ensure it does not contain a frame delimiter.

When the data link layer of the receiver scans the data before delivering the data load upward to the network layer, every time five consecutive bits of 1 appear, it deletes the next 0 to restore the original data load. .

2. Error detection

No actual communication link is ideal, and bits may suffer errors during transmission (called bit errors).

That is: bit 1 may become bit 0

       Bit 0 may become bit 1

2.1 Parity effect

       Odd parity is to add a check digit after the data to be sent, so that the number of 1 bits in the entire data after adding the check digit is an odd number;

       Even parity is to add a check digit after the data to be sent, so that the number of bits 1 in the entire data after adding the check digit is an even number.

        If an odd number of bits having errors occur in the transmitted data, the parity of the number of bits 1 included change and the bit error can be detected.

        In the transmitted data, if an even number of bit errors occur, the parity of the number of bits 1 contained will not change, and the error cannot be detected (missed detection).

Obviously, the parity check method is too limited, so it is rare. Cyclic redundancy check error checking technology with extremely low miss detection rate is widely used in the actual data link layer.

2.2 Cyclic redundancy check

       The sending and receiving parties agree on a generating polynomial G(x); 

       The sender calculates the error detection code (redundant code) based on the data to be sent and the generating polynomial, and adds it to the back of the data to be transmitted and transmits it together;

        The receiver calculates whether the received data has errors by generating a polynomial.

Give a simple example:

The data to be sent is 101001, generate polynomial G(x) = x^3 + x^ 2 + 1, and calculate the redundant code

Step 1: Construct the dividend. After the data to be sent, add the highest degree of the generating polynomial, 0, which is 101001000.

Step 2: Construct the divisor and generate a bit string composed of the coefficients of the polynomial as the divisor, that is, 1101

Step 3: Do "binary modulo 2 division": equivalent to performing logical XOR operation on the corresponding bits

Step 4: Check the "remainder". The number of digits in the remainder should be the same as the highest degree of the generator polynomial. If there are not enough digits, add 0 in front of the remainder to make up the number of digits.

The received information is 101101001, and the generating polynomial is G(X)=

The first three steps of the calculation are the same for both the receiver and the sender, but the fourth step is different.

The fourth step of the receiver: the remainder is 0, which means there is no error in the transmission process.

                             The remainder is not 0, it can be considered that a bit error has occurred during the transmission process

Note: Error checking can only detect errors during frame transmission, but it cannot locate the error, so it cannot correct the error.

3. Reliable transmission

3.1 Basic concepts

        Using error detection technology, the data link layer of the receiver can detect whether the frame has bit errors during transmission. Next, according to the type of service provided by the data link layer to the upper layer, it is divided into two types of transmission services:

  (1) Unreliable transmission service: just discard frames with errors and do nothing else

  (2) Reliable transmission service: Find a way to achieve what the sender sends and what the receiver receives.

       Generally speaking, the bit error rate of wired links is relatively low. In order to reduce overhead, the data link layer is not required to provide reliable transmission services upwards. Even if bit errors occur, the issue of reliable transmission is handled by its upper layers.

       The wireless link is prone to interference and has a relatively high bit error rate, so the data link layer is required to provide reliable transmission services to the upper layers.

   Note: Reliable transmission service is not limited to the data link layer. All other layers can choose to achieve reliable transmission.

3.2 Implementation mechanism of reliable transmission——stop-wait coordination SW

Implementation principle of stop waiting protocol

(1) If the sender’s data encounters bit errors during transmission

    

(2) If the sender’s data does not reach the receiver (timeout retransmission)

       If the receiver cannot receive the data packet, it will not transmit the corresponding ACK for no reason. If no measures are taken, the sender will always be waiting for the receiver's ACK.

      In order to solve this problem, the sender can start a timeout timer after sending a data packet. If the timeout timer reaches The set time, but does not receive the confirmation packet ACK from the receiver, then the sender will retransmit the sent grouped data

(3) The receiver’s confirmation packet information is lost (confirmation loss)

        ​ ​ Here it is confirmed that the packet is lost. When the time set by the timeout timer is exceeded, the sender will resend the packet, but how does the receiver know whether this packet is the same as the one it received before? At this time, the data packets must be numbered. Only one bit is needed to indicate whether this packet is the same as the previous packet. The sequence numbers only need 0 and 1.

(4) Confirm that the group is late

Precautions:

1. After using the timeout retransmission mechanism, you no longer need to use the denial mechanism, which makes the protocol implementation simpler. However, if the bit error rate of the point-to-point link is high, using the acknowledgment mechanism can allow the sender to retransmit as soon as possible before the timeout timer expires.

2. In order for the receiver to determine whether the received data packets are duplicates, the data packets need to be numbered. Due to the characteristics of the stop-wait protocol, only 1 bit is needed to number the sequence, that is, sequence number 0 and sequence number 1.

3. In order for the sender to determine whether the received acknowledgment packet is a duplicate, the acknowledgment packet needs to be numbered. The number of bits used is the same as the number of bits used in the data packet.

(1) The data link layer generally does not have late confirmation packets, so the stop-and-wait protocol does not need to number the confirmation packets in the data link layer.

4.The timeout retransmission time RTO set for the timeout timer should be carefully selected. Generally, the RTO is set to be slightly larger than the average round trip time RTT of both the sender and the receiver.

5. The stop-wait protocol belongs to the automatic request retransmission protocol. That is, the request for retransmission is automatically made by the sender, rather than the receiver requesting the sender to retransmit an error-coded data packet.

3.3 Fallback n-frame protocol

3.3.1 Features

       The sender needs to maintain a sending window W_T. In the absence of receiving a confirmation packet from the receiver, the sender can continuously send out all data packets whose sequence numbers fall within W_T. Use n bits to sequence the packets. Then the value of W_T is The value range is 1<W_T≤(2^n−1).

     The receiver needs to maintain a receiving window Wr. Only data packets that arrive at the receiver correctly (without errors) and whose sequence number falls within Wr can be received by the receiver.

Note: This Wr can only be 1, which is the same as the stop and wait protocol.

3.3.2 Specific process

       Every time the receiver correctly receives a data packet whose sequence number falls into the receiver's window, it slides the receiving window forward one position, so that a new sequence number falls into the receiving window. At the same time, the receiver also needs to send a message to the sender. Send an acknowledgment packet for this data packet.

       Every time the sender receives an acknowledgment packet of a data packet, the sending window will slide forward by one position, so that a new sequence number will enter the sending window, and the sequence number can be sent when it enters the sending window.

       In the fallback N-frame protocol, the sender's sending window and the receiver's receiving window keep sliding forward according to the above rules. Therefore, this type of protocol becomes a sliding window protocol.

3.3.3 Advantages

1. Reduce the number of confirmation packets injected into the network

2. Even if the packet is confirmed to be lost, it may not be necessary to retransmit the data packet

       Because the receiver of the fallback N-frame protocol adopts the cumulative acknowledgment method, the receiver does not need to send an acknowledgment packet for every array packet received. Instead, after receiving several data packets with consecutive sequence numbers, the receiver will A data packet is sent with an acknowledgment packet. The acknowledgment packet ACKn indicates that sequence number n and the previous data were received correctly.

3.3.4 Disadvantages

Unable to promptly and accurately reflect to the sender the number of all data packets that the receiver has correctly received

        This creates an uncomfortable problem, that is, when I transmit a series of array packets, if there is a bit error in the packet with serial number 5, then it will be discarded. The other data packets do not match the data in the receiving window, then All these packets will be discarded, and n ACK5s will be sent to request retransmission. An error in one data packet may cause the retransmission of a large number of data packets.        

       When the channel quality is poor (bit errors are prone to occur), the channel utilization of the fallback N-frame protocol is not higher than that of the stop-and-wait protocol.

Note: The size of the sending window W_T cannot exceed the value range. Once an error occurs, it is difficult to judge.

       The sender sends packets No. 0 to 7, and the receiver receives and sends the ACK7 confirmation packet, moving the receiving window forward 8 bits, pointing to the next 0, but ACK7 is lost during the transmission process, and the sending window does not receive the confirmation packet, it will Timeout retransmission starts from packet No. 0. But at this time, the receiving window happens to be at the position of packet 0, so it is impossible to determine whether the packet is a new packet or a packet resent by the previous supermarket.

3.4 Select retransmission protocol

       The retransmission protocol is optimized to be more efficient than the fallback N-frame protocol when dealing with packet errors. The receiving window will directly skip the error packets to receive other packets and send their acknowledgment packets in sequence. When the acknowledgment packet of the packet is not received, the receiving window will not move forward, but will skip the packet and confirm other packets in the window. If the error packet sequence number is not received for too long, the acknowledgment packet will be Causes timeout retransmission. At this time, the packet will be sent separately. The receiving window will not be retransmitted until the receiver receives and receives the confirmation sublease sent by the receiver.

3. Point-to-point protocol

The Point-Point Protocol [PPP] protocol is currently the most widely used point-to-point data link layer protocol.

PPP frame format

PPP transparent transmission

       Flag field: It is the delimiter of the PPP frame. The value is: from a byte perspective, the value is 0x7E, and from a bit perspective, the value is 01111110.

Sender's processing:

(1) Subtract 0x20 from each 0x7E that appears in the data payload (equivalent to XOR 0x20), and then insert the escape character 0x7D in front of it.

(2) If the data load originally contains 0x7D, subtract 0x20 from each 0x7D, and then insert the escape character 0x7D in front of it.

(3) Add 0x20 (equivalent to XOR 0x20 to convert it into a non-control character) for each ASCII code control character that appears in the data load (that is, a character with a value less than 0x20), and then insert an escape in front of it. Character 0x7D.

Receiver's processing:

By performing the reverse transformation of the sender, the original data payload without byte padding can be correctly recovered.

Transparent transmission of PPP frames

When talking about common problems at the data link layer, we are taking the PPP frame as an example. Every time 5 consecutive bits of 1 appear, a bit of 0 is filled behind it.

PPP frame error detection

The knowledge here is mentioned in the previous error detection. It is important to see that the calculation range of FCS is within the calculation range of FCS except for the frame delimiter and frame detection sequence.

PPP working status

Illustrations for this article come from:

The personal space of the teacher of Hu University of Science and Technology - Personal homepage of the teacher of Hu University of Science and Technology - Bilibili Video (bilibili.com)

Reproduction is authorized

Guess you like

Origin blog.csdn.net/m0_62812354/article/details/133755149
Recommended