Computer Network Chapter 3 (Data Link Layer) [Part 1]

Reference tutorial:3.1 Overview of data link layer_bilibili_bilibili

1. Overview of the data link layer

1. The position of the data link layer in the network architecture

(1) Each device is interconnected through the transmission media below the physical layer. As shown in the figure below, host H1 sends data to H2:

① After host H1 encapsulates the data to be sent layer by layer, it converts each bit that constitutes the data packet into an electrical signal through the physical layer and sends it to the transmission medium.

② After the data packet enters the router, it is decapsulated layer by layer from bottom to top to the network layer. Then the router determines the forwarding port of the data packet based on the destination network address of the data packet and its own forwarding table, and then encapsulates the data packet layer by layer from the network layer downward and Send packets through the physical layer to the transport medium.

③When the data packet finally reaches host H2, it must be decapsulated layer by layer from bottom to top, and finally the data sent by host H1 is decapsulated.

(2) When studying the data link layer, you can imagine that data packets are only transmitted horizontally from left to right in the data link layer.

(3) From the perspective of the data link layer, the communication from host H1 to H2 can be seen as consisting of communication on four different links ( link It is a physical link from one node to an adjacent node, without any other switching nodes in the middle). To transmit data on the link, the link alone is not enough, and some Communication protocols are used to control the transmission of these data. Ifthe hardware and software that implement these protocols are added to the link, it constitutes< a i=5>Data Link.

(4)The data packets transmitted on the data link layer are also called "frames", which means that the data link layer transmits and processes data in units of frames< /span>.

2. Problems that need to be solved when using the data link layer of point-to-point channels

(1) Encapsulation into frame:

① As shown in the figure below, two hosts are interconnected through a link. Both hosts will encapsulate or decapsulate the data packets sent or received at five levels. The sender will encapsulate the data to be sent. It is encapsulated into an application layer protocol data unit through the application layer, and then delivered to the transport layer. The transport layer adds a transport layer protocol header to it, making it a transport layer protocol data unit, and then delivers it to the network layer, which adds a network layer protocol to it. header, making it a network layer protocol data unit, and then delivering it to the data link layer. The data link layer adds a data link layer protocol header (referred to as a frame) to the network layer protocol data unit. header) and trailer (referred to as frame trailer), the operation of adding frame headers and frame trailers to the protocol data units delivered by the data link layer to the network layer is called "encapsulation into frames".

The purpose of adding frame headers and frame trailers is to transmit data on the link in frame units, that is, to Implement the functions of the data link layer itself.

(2) Error detection:

① The sender sends the encapsulated frame to the transmission medium through the physical layer. The frame may encounter interference during the transmission process and cause bit errors, that is, bit 0 may become bit 1, and vice versa.

Before sending the frame, the sender calculates the error detection code based on the data to be sent and the error detection algorithm, and encapsulates it at the end of the frame. The receiving host receives After the frame is received, the error detection code and error detection algorithm can be used to determine whether the frame has errors during transmission.

(3) Reliable transmission:

①The receiving host will discard the frame after receiving the frame with errors. If the data link layer provides unreliable services to its upper layers, then there will be no remedial measures after discarding the frame;If the data link layer provides reliable services to its upper layers , then after the frame is discarded, other measures will be taken to ensure that the receiving host can re-receive the correct copy of the discarded frame.

Although bit errors cannot be completely avoided, if the sender can receive what the receiver sends, it is called reliable transmission< a i=2>.

3. Problems that need to be solved in the data link layer using broadcast channels

(1) The data link layer using broadcast channels also needs to solve the three problems of encapsulation and framing, error detection and reliable transmission.

(2) Host addressing:

① As shown in the figure below, host A wants to send a frame to host C. At this time, the signal representing the frame will be transmitted to other hosts on the bus through the bus. How does host C know that the data is what it should receive? Hosts B, D, How does E know that it should reject the data? This leads to the problem of how to identify each host in the network, that is, the host addressing problem.

②In order to implement host addressing, host A will add the destination address of the frame (that is, host C) to the frame and transmit it together.

(3) Signal collision:

① When multiple hosts on the bus use the bus to transmit data frames at the same time, the transmission signals will collide. This is a broadcast channel.Shared LAN Unavoidable problem, therefore,How to coordinate the competition between hosts for the bus is also a problem that must be solved. The coordination method used by Ethernet is to use a special protocol CSMA/CD (that is, Carrier Sense Multipoint Access/Collision Detection).

② With the development of technology, switched LANs with higher performance using point-to-point links and link layer switches have completely replaced shared LANs in the wired (local area network) field. However, due to the limitations of wireless channels Broadcasting in nature, wireless LANs still use shared channel technology. For switched LAN, the problem that needs to be solved is how the switches in the network forward data frames< a i=4>.

2. Encapsulation into frames

1. Frame header and frame end

(1)Encapsulation into framing means that the data link layer adds a frame header and frame trailer to the protocol data unit delivered by the upper layer to make it a frame, The frame header and frame tail contain important control information.

(2) One of the functions of the frame header and frame trailer isframe delimitation. After the data link layer of the sender encapsulates the protocol data unit delivered by the upper layer into a frame, it also converts the bits constituting the frame into electrical signals through the physical layer and sends them to the transmission medium, then How does the data link layer of the receiver extract frames one by one from the bit stream delivered by the physical layer? Taking the format of the PPP frame as an example, the frame header and frame tail each contain a flag field with a length of 1 byte, which is used to delimit the frame. Assuming that the sender sends a PPP frame, the bit stream in the figure below The red part is the frame delimitation mark.The data link layer of the receiver can extract frames one by one from the bit stream delivered by the physical layer based on the frame delimitation mark.

(3)Not every frame of the data link layer protocol contains a frame delimitation flag. For example, the MAC frame format of Ethernet version 2 does not contain frame delimitation marks in the frame header and frame trailer. The Ethernet data link layer encapsulates the MAC frame and delivers it to the physical layer. The physical layer will An 8-byte preamble is added in front of the MAC frame, and then the bit stream is converted into an electrical signal for transmission. The first seven bytes of the preamble are the preamble, which is used to synchronize the receiver's clock. The following 1 byte is The frame start delimiter indicates that it is followed by the MAC frame. In addition, Ethernet also stipulates that the inter-frame interval is a 96-bit sending time, so the MAC frame does not require the frame end delimiter (it is worth mentioning Yes, the interframe spacing has other effects).

2. Transparent transmission

(1) Transparent transmission means thatthe data link layer has no restrictions on the transmission data delivered by the upper layer, just like the data link layer It's the same as not existing.

(2)The byte-oriented physical link uses byte stuffing (or character stuffing) to achieve transparent transmission:< /span>

①For the sender's data link layer to receive the protocol data unit delivered by its upper layer, add a frame header and frame trailer to it to make it a frame,If it is delivered by the upper layer The protocol data unit happens to also contain the frame delimitation flag, and the receiver cannot receive the frame correctly. When the receiver receives the first frame delimitation flag, it thinks it is the beginning of the frame, but when the receiver receives it again The frame delimiter flag (in the protocol data unit delivered by the upper layer) is mistaken for the end of the frame.

② If the data link layer does not take other measures to avoid the receiver's misjudgment of whether the frame ends, it cannot be called transparent transmission. That is to say, the data link layer has restrictions on the protocol data units delivered by the upper layer, and its content cannot contain Frame delimiter, obviously such a data link layer has no use value.

③In fact, various data link layer protocols will definitely find ways to solve the problem of misjudgment of the end of the frame.For example, scanning the data part of the frame before sending the frame, Each time a frame delimiter appears, an escape character is inserted in front of it (the escape character is a special control character with a length of 1 byte), The receiving data link layer extracts the frame from the bit stream delivered by the physical layer. When it encounters the first frame delimiter, it considers it to be the beginning of the frame. When it encounters the escape character, it knows what is behind it. Although the one byte is the same as the frame delimiter, it is data instead of a delimiter. After removing the escape character, the content following it will be extracted as data.

④If the protocol data unit delivered to the data link layer by the upper layer contains both a frame delimiter and an escape character, then When the data part of the frame is scanned, every time a frame delimiter or escape character appears, an escape character is inserted in front of it , receiver data The link layer extracts the frame from the bit stream delivered by the physical layer. When it encounters the first frame delimiter, it considers it to be the beginning of the frame. When it encounters the escape character, it knows that the following byte is not related to the frame delimiter. The delimiter or escape character is the same, but it is data instead of the delimiter or escape character. After removing the escape character, the content following it will be extracted as data.

(3)The bit-oriented physical link uses bit stuffing to achieve transparent transmission:

① The figure below shows a frame of a certain point-to-point protocol. Two frame delimitation flags appear in the data part of the frame (0x7E in this example, converted to binary is 01111110), but they are actually data rather than frame delimitation. .

Before sending, you can use the zero bit filling method to scan the data part. In this example, a bit 0 is inserted after every 5 consecutive bits 1, so that It can ensure the uniqueness of frame delimitation in the entire frame, and can achieve transparent transmission. When the data link layer of the receiver extracts the frame from the bit stream delivered by the physical layer, it only needs to remove the bit 0 after every 5 consecutive bits 1 in the data part of the frame.

(4) From the perspective of the data link layer only, the data part of the frame is the actual data to be transmitted. The frame header and frame tail are additionally added to realize the data link layer function, so. In order to improve the transmission efficiency of the frame, the length of the data part of the frame should be much longer than the length of the frame header and frame tail

(5) Taking into account various factors such as error control, Each data link layer protocol specifies the upper limit of the length of the data part of the frame, which is the maximum transfer unit MTU (Maximum Transfer Uint).

3. Error detection

1. Bit error

(1) Actual communication links are not ideal. Bits may cause errors during transmission. 1 may become 0, and 0 may become 1. This is called bit error. Within a period of time, the ratio of transmitted erroneous bits to the total number of transmitted bits is called the bit error rate BER (Bit Error Rate).

(2) Use error detection code to detect whether bit errors have occurred during data transmission, which is what the data link layer needs to solve one of the important issues.

① Take the MAC frame format of Ethernet version 2 as an example. The frame tail contains a 4-byte frame check sequence FCS field. Its function is to allow the data link layer of the receiver to check whether the frame is transmitted during transmission. A bit error occurred.

② Another example is the frame format of the point-to-point protocol PPP. The frame tail contains a 2-byte frame check sequence FCS field. Its function is also to allow the data link layer of the receiver to check whether errors have occurred during the transmission of the frame. code.

2. Parity check

(1) Add 1 parity bit after the data to be sent, The number of "1"s in the entire data (including the added parity bit) is an odd number (odd parity) or an even number (even parity).

① Assuming that the sending and receiving parties agree to useodd parity, then the check bit added after the data "101101" should be bit 1, Making the total number of bit 1s an odd number:

[1] Assume that a 1-bit error occurs during the transmission process (the error is represented by red in the figure below). The receiver performs an odd check on the received bit stream and finds that the total number of bit 1 is an even number and If it is not an odd number, you know that a bit error occurred during the transmission process. In other words, uses odd parity. If the parity of the number of bits 1 changes, the error can be detected< a i=2>.

[2] Assume that a 2-bit error occurs during the transmission process (the error is represented by red in the figure below). The receiver performs an odd check on the received bit stream and finds that the total number of bit 1 is an odd number. It will be mistakenly believed that no bit errors occurred during the transmission process. In other words, uses odd parity. If the parity of the number of bits 1 does not change, the error cannot be detected .

② Assuming that the sending and receiving parties agree to use even parity, then the check bit added after the data "101101" should be bit 0, Makes the total number of bit 1s an even number:

[1] Assume that a 1-bit error occurs during the transmission process (the error is represented by red in the figure below). The receiver performs an odd check on the received bit stream and finds that the total number of bits 1 is an odd number. If it is not an even number, you know that a bit error occurred during the transmission process. In other words, uses odd parity. If the parity of the number of bits 1 changes, an error can be detected< a i=2>.

[2] Assume that a 2-bit error occurs during the transmission process (the error is represented by red in the figure below). The receiver performs an odd check on the received bit stream and finds that the total number of bit 1 is an even number. It will be mistakenly believed that no bit errors occurred during the transmission process. In other words, uses odd parity. If the parity of the number of bits 1 does not change, the error cannot be detected .

(2) If there are odd number of bit errors, the parity changes, Bit errors can be checked; if there are even number of bit errors, the parity will not change , cannot detect code errors, which is called missed detection.

(3) Since the missed detection rate of parity check is relatively high, this detection method is generally not used in the data link layer of computer networks.

3. Cyclic Redundancy Check (CRC, Cyclic Redundancy Check)

(1) The sending and receiving parties agree on agenerating polynomialG(x), and the sender calculates it based on the data to be sent and the generating polynomial The error detection code (redundant code) is added to the data to be transmitted and transmitted together. The receiver calculates whether the received data is generated by generating polynomials. Error occurred.

(2) Processing by the sender:

The data to be sent is used as part of the dividend, followed by adding the highest degree 0 of the generated polynomial (In the following generator polynomial example, the highest degree 0 bit of the generator polynomial is 4 0s) to form the dividend, generates a bit string composed of the coefficients of the polynomial as Divisor, perform division operation to obtain the quotient and remainder.

The remainder is the calculated redundant code, which is added to the back of the data to be sent and sent together.

The length of the redundant code is the same as the highest degree of the generating polynomial, and the quotient is only used as a mark to prevent misalignment during the calculation process.

(3) Processing by the receiver:

①Use to use the received data as the dividend. The divisor is still the bit string composed of the coefficients of the generated polynomial, and perform division operation. Get the quotient and remainder.

If the remainder is 0, it can be determined that no bit errors occurred during the transmission process; if the remainder is not 0, it can be determined that a bit error occurred during the transmission process< a i=2>.

(4) Each coefficient of the generating polynomial can only be 0 or 1; the CRC algorithm requires that the generating polynomial must contain the lowest-order term.

(6) Cyclic Redundancy CheckCRC has good error detection capabilities ( leaks The detection rate is very low). Although the calculation is complicated, it is veryeasy to implement in hardware, so is widely used in the data link layer.

(7)Error detection code can only detect whether there is an error in the frame during transmission, but cannot locate the error, so it cannot To correct errors, if you want to correct errors in transmission, you can use error-correcting codes with more redundant information Forward error correction, but the error correction code is relatively expensive and is rarely used in computer networks.

(8) In computer networks, usually error detection and retransmission are used to correct errors in transmission, Or just discard the frame with detected error, depending on whether the data link layer provides reliable transmission service or unreliable transmission service to its upper layer.

4. Reliable transmission

1. Basic concepts of reliable transmission

(1) Using error detection technology, the data link layer of the receiver can detect whether the frame is generated during transmission. Error code. If a bit error does occur, error detection and retransmission are usually used in computer networks to correct errors in transmission,Or just discard the frame with detected error, depending on whether the data link layer provides reliable transmission service or unreliable transmission service to its upper layer.

① Unreliable transmission service: only discard frames with errors and do not take any other measures.

② Reliable transmission service: What the sender sends, the receiver receives.

(2) To achieve the imagined reliable transmission, the receiver can send a notification frame to the sender, informing the sender that the previously sent frame has a bit error and asking the sender to resend the frame. However, in fact, reliable transmission is not possible. The implementation is not that simple. If the notification frame also suffers from errors or losses, it is still not a reliable transmission.

(3) Generally speaking, the bit error rate ofwired link is relatively low. In order to reduce the overhead, and The data link layer is not required to provide reliable transmission services upwards. Even if bit errors occur, the problem of reliable transmission can be handled by its upper layer; andWireless links are susceptible to interference and have relatively high bit error rates, sorequires the data link layer to provide reliable transmission services to the upper layers .

(4) The previously introducedbit error is just one type of transmission error. From the perspective of the entire computer network architecture, transmission error Also includes packet loss, packet out of order, and Group repetition (The name of the frame is changed to grouping here).

① If host H6 wants to send a packet to host H5, the packet sent by host H6 reaches router R5 during the sending process. If the input queue of R5 is full at this time, R5 will discard the packet according to its own packet discarding policy. , which will cause packet loss transmission error.

② If host H6 sends three packets to host H2 in sequence, they may not arrive at H2 in the order they are sent. That is to say, the packet sent first may not arrive first, which will cause transmission error. Packet out of order

③ If host H6 sends packets to host H2 in sequence, the packets sent by host H6 may stay in network N10 for some reasons and fail to reach H2 in time. This may cause H6 to Timeout retransmission, the retransmitted packet reaches H2, and then the packet staying in network N10 also reaches H2, which will cause repeated packet transmission error.

(5) The three types of transmission errors, packet loss, packet out-of-order and packet duplication, generally do not appear in the data link layer, but in the upper layer, so reliable transmission Services are not limited to the data link layer, and other layers can choose to implement reliable transmission (The three reliable transmission implementation mechanisms introduced below can be applied to Among the protocols at each layer of the computer network architecture). In addition, the implementation of reliable transmission is relatively complex and expensive. Whether to use reliable transmission depends on the application requirements.

2. Stop-wait protocol (SW)

(1) bit errors may occur during data transmission. As shown in the figure below, the sender and receiver communicate based on the Internet, rather than being limited to a point-to-point data link. The ordinate is time.

①The sender sends a data packet to the receiver, and the receiver detects errors after receiving it. If there is no error, it receives the data packet and sends it to the sender Acknowledgment packet (ACK for short), the sender can only send the next data packet after receiving the acknowledgment packet for the sent data packet.

② Assume that the next data packet has a bit error during transmission. After the receiver receives it and detects the error, it will find the bit error, then discard the data packet and send it to the sender Negative Packet (NAK for short), after the sender receives the negative packet for the sent data packet, it knows that the previously sent data packet has an error and was rejected by the receiver. , so the sender will immediately retransmit the data packet.

③The sender cannot delete the data packet from the cache immediately after sending a data packet. It can only delete it from the cache after receiving a confirmation packet for the data packet.

After each data packet is sent, the sender stops sending the next data packet and waits for the confirmation packet or denial packet from the receiver. If the confirmation packet is received, it can Continue to send the next data packet, and if a denial packet is received, resend the previously sent data packet. This seems to be able to achieve reliable transmission, but the actual situation is far more complicated than this.

(2) During the data transmission process, packet loss may occur. As shown in the figure below, the sending and receiving parties communicate based on the Internet, and the ordinate is time. (For data link layer point-to-point channels, packet loss is less likely to occur)

①The sender sends a data packet to the receiver,If the data packet is lost during transmission, the receiver will not receive the data packet and will not send ACK or NAK, if no other measures are taken, the sender will always be waiting for ACK or NAK from the receiver.

②In order to solve the problem that the sender is always waiting for the receiver's ACK or NAK state, a timeout timer can be started when the sender completes sending a data packet. ,If the retransmission time set by the timeout timer is reached and the sender still cannot receive If there is any ACK or NAK to the receiver, the original data packet will be retransmitted, which is called timeout retransmission .

③Generally, the retransmission time can be selected to be slightly larger than the "average round trip time from the sender to the receiver".

(3) During the data transmission process, packet duplication (ACK or NAK loss) may occur. As shown in the figure below, the sending and receiving parties communicate based on the Internet, and the ordinate is time.

① The sender sends a data packet to the receiver, and the receiver correctly receives the data packet and sends a confirmation packet to the sender. However, the confirmation packet is lost during the transmission process, which will inevitably cause the sender to timeout the previously sent data packet. Retransmission, if the retransmitted data packet also reaches the receiver correctly, it will cause the problem of packet duplication.

② In order to avoid transmission errors such as repeated packets, each packet must be given a sequence number. For the stop-and-wait protocol, since the wait is stopped every time a data packet is sent, as long as ensures that the sending sequence number of each new data packet sent is different from the sequence number of the last data packet sent > is enough, so numbering with one bit is enough (i.e. serial numbers 0 and 1).

③According to the sequence number of the data packet, the receiver can determine whether the data packet is repeated. If it is repeated, the duplicate data packet will be discarded and a confirmation packet for the data packet will be sent to the sender to prevent the sender from mistaking the data packet. timeout and retransmit again.

④After the sender receives the confirmation packet for data packet No. 0, it sends the next data packet to the receiver, whose sequence number is 1. After the receiver correctly receives the data packet No. 1, it sends a confirmation packet to the sender.

(4) During the data transmission process, repeated confirmation (late confirmation) may occur. As shown in the figure below, the sending and receiving parties communicate based on the Internet, and the ordinate is time.

① The sender sends data packet No. 0 to the receiver. After receiving it correctly, the receiver sends a confirmation packet to the sender. However, the confirmation packet may be delayed due to some reasons. Arrives at the sender. At this time, the sender may timeout retransmit the No. 0 data packet. During the transmission of the retransmitted No. 0 data packet, the sender receives a late acknowledgment packet. , so data packet No. 1 is sent to the receiver. After receiving the retransmitted data packet No. 0, the receiver finds that it is a duplicate data packet and discards it, and sends a confirmation packet to the sender for the data packet. At this time The sender will face the problem of repeated confirmation of data packet No. 0. If no other measures are taken, the sender will mistakenly think that this is data packet No. 1. Group confirmation.

②In order to avoid transmission errors such as repeated confirmations, it is necessary to also number the confirmation packets, so that the sender can avoid such misjudgments.

③The sender receives the confirmation packet with sequence number 0.The sender can know whether this is a duplicate confirmation packet by the sequence number of the confirmation packet. If it is a duplicate, it will be ignored a>.

④ After receiving the data packet No. 1, the receiver sends the sender an acknowledgment packet for the data packet, with the sequence number being 1. After the sender receives the acknowledgment packet, it sends the next data packet, with the sequence number being 0.

(5) Notes:

① When the receiving end detects that the data packet has a bit error, it discards it and waits for the sender's timeout retransmission. However, for point-to-point links with a high bit error rate, in order to make the sender< a i=1>Retransmit as early as possible, orsend a NAK packet to the sender.

② In order for the receiver to determine whether the received data packets are duplicates, it is necessary tonumber the data packets. Due to the stop-and-wait characteristic of the stop-wait protocol, only needs 1 bit number, that is, numbers 0 and 1.

③In order for the sender to determine whether the received ACK packet is a duplicate, it is necessary tonumber the ACK packet, the number of bits used The same number of bits as the data packet number. The data link layer generally does not have the situation where ACK packets are late, so the stop-wait protocol can be implemented in the data link layer without numbering ACK packets.

④The retransmission time set by the timeout timer should be chosen carefully. Generally, the retransmission time can be selected as Slightly larger than the "average round trip time from sender to receiver".

[1] At the data link layer, the point-to-point round-trip time is relatively certain, and the retransmission time is relatively easy to set.

[2] At the transport layer, setting an appropriate retransmission time is sometimes not easy as the end-to-end round-trip time is very uncertain.

(6) Channel utilization of stop-wait protocol:

①As shown in the figure below, T_{D} is the sending delay consumed by the sender to send data packets, RTT is the round-trip time between the sender and the receiver, T_{A} is the sending delay spent by the receiver to send the confirmation packet, ignoring the receiver's processing delay of the data packet and the sender's processing delay of the confirmation packet,< a i=4>+RTT+ is the total time elapsed by the sender using the stop-and-wait protocol from sending a data packet until the next data packet can be sent. T_{D}T_{A}

② Really useful data is transmitted only within the time T_{D}, so the channel utilization U can be calculated by the following formula:

When the round-trip delay RTT is much larger than the data frame sending delay TD (for example Using a satellite link), the channel utilization will be very low; if retransmission occurs, the channel utilization will be even lower for transmitting useful data information.

④In order to overcome the shortcomings of the stop-wait protocol's low channel utilization, two other protocols were produced, namely the back-off N-frame protocol GBN and the selective retransmission protocol SR.

(7) A reliable transmission protocol implemented through acknowledgment and retransmission mechanisms like the stop-and-wait protocol is often called the Automatic Request Repeat Protocol (ARQ).

3. Fallback N frame protocol (GBN)

(1) Based on the stop-and-wait protocol,If the sender can continuously send multiple data packets before receiving the acknowledgment packet from the receiver< a i=2>, the channel utilization can be greatly improved, which is a pipeline-type transmission. As shown in the figure below, under the same conditions and within the same time, the sender using the stop-wait protocol can only send one data packet, while the sender using pipeline transmission can send 5 data packets.

(2) Fallback N-frame protocolUse the sending window to limit the number of data packets that the sender can send continuously on the basis of pipeline transmission.

①As shown in the figure below, assuming that 3 bits are used to number the packets, the sequence number ranges from 0 to 7 (2 minus 1 to the third power of 0 starts.

② The sender must maintain a sending window. Data packets whose sequence numbers fall within the sending window can be sent continuously without waiting for the corresponding confirmation packet from the receiver. Send, data packets whose sequence number falls outside the sending window are not allowed to be sent.

[1]The size of the sending window is recorded asW_{T}. For this example, its value range is 1~7 (2 times 3 minus 1, where 3 is the number of bits that constitute the packet sequence number ), in this example W_{T} = 5.

[2]IfW_{T} = 1, it is equivalent to the stop-wait protocol; if the value of W_{T} Exceeding the upper limit of the value range will cause serious errors.

[3] Five data packets whose sequence numbers fall within the sending window can be sent continuously, while data packets whose sequence numbers fall outside the sending window are not allowed to be sent.

③The receiver must maintain a receiving window.Data packets with sequence numbers falling within the receiving window are allowed to be received, while data packets with sequence numbers falling outside the receiving window are not allowed to be received. . The size of the receiving window is recorded as W_{R}. For the rollback N-frame protocol, its value can only be 1.

(3) No error situation:

The sender continuously sends the data packets 0~4 whose sequence numbers fall within the sending window in sequence, and they are transmitted through the Internet Reach the receiver correctly, that is, there is no out-of-sequence or bit error.

The receiver receives them in order. Each time a data packet is received, the receiving window moves forward one position and sends an acknowledgment packet for the received packet to the sender② a>.

③No. 0~4 confirmation packets have correctly reached the sender through Internet transmission. Every time the sender receives a confirmation packet, the sending window moves forward one position, so that there is The new sequence number falls into the sending window.

④The sender can delete the confirmed data packets from the cache, and the receiver can choose an opportunity to deliver the received data packets to the upper layer for processing.

(4) Cumulative acknowledgment: The receiver using the fallback N frame protocol does not necessarily need to group the received data. indicates that all data packets with sequence number n and before have been received correctly. nThe acknowledgment packet is also numbered. ACK. The last data packet is sent acknowledgment, but after receiving several data packets (depending on the specific implementation)Send acknowledgments one by one

① As shown in the figure below, the sender continuously sends data packets 0 to 4 whose sequence numbers fall within the sending window, and they arrive at the receiver correctly through Internet transmission.

②The receiver receives them in order. After receiving data packets No. 0~1, the receiver sends a cumulative acknowledgment ACK1 to the sender. After receiving data packets No. 2~4, the receiver sends a cumulative acknowledgment to the sender. ACK4.

③ Assume that ACK1 is lost during the transmission process, and ACK4 reaches the sender correctly. After receiving ACK4, the sender knows that the data packets with sequence number 4 and before have been correctly received by the receiver, so it will The sending window moves forward 5 positions, so that a new sequence number falls into the sending window. (Using cumulative acknowledgment, even if the acknowledgment packet is lost, the sender may not have to retransmit it. It can also reduce the overhead of the receiver and reduce the occupation of network resources. However, using cumulative acknowledgment cannot send the message to the sender. Timely reflect the data packet information that the receiver has correctly received)

④The sender can delete the confirmed data packets from the cache, and the receiver can choose an opportunity to deliver the received data packets to the upper layer for processing.

(5) In case of errors:

The sender sends the data packets No. 5~1 whose sequence numbers fall within the sending window in sequence., they are transmitted through the Internet Arriving at the receiving end, assuming they were interfered with during transmission, there was a bit error in data packet No. 5.

②The receiver discovers the error through the error detection code in the data packet, so the receiver discards data packet No. 5. However, the sequence numbers of the subsequent four data packets that arrive do not match the sequence numbers in the receiving window, and the receiver will also discard them. , and confirm the last data packet received in sequence, that is, send ACK4. Every time a data packet is discarded, one ACK4 is sent. In this example, 4 ACK4s are sent.

③4 ACK4s reach the receiver through Internet transmission. Since the sender has received ACK4 before, when receives these duplicate ACK4s, the sender can know the previous sent There is an error in the data packet, so you can start retransmitting immediately without waiting for the timeout timer to expire. As for retransmitting immediately after receiving several duplicate confirmations, it is determined by the specific implementation.

④In this example, it is assumed that receiving these four repeated confirmations will not trigger the sender to retransmit immediately. After a period of time, the timeout timer will time out, and the sender will group the data that has been sent within the sending window. Retransmit all.

⑤ In this example, although the data packets with sequence numbers 6, 7, 0, and 1 arrived at the receiver correctly, the data packet No. 5 was not accepted due to bit errors, and they were "implicated" and were not accepted. Upon acceptance, the sender also retransmits these data packets, which is called Go-back-N (go back N frames). It can be seen that when the communication line quality is poor, the channel utilization rate of the fallback N-frame protocol is not higher than that of the stop-and-wait protocol.

(6) As shown in the figure below, the maximum value of W_{T} is 7, if the value of W_{T} exceeds The upper limit of the value range , for example W_{T} = 8.

① The sender sends the eight data packets from 0 to 7 whose sequence numbers fall within the sending window in sequence, and they arrive at the receiver correctly through Internet transmission.

②After the receiver receives them in order, the receiving window moves forward by a total of 8 positions, and the receiver sends back the accumulated confirmation ACK7 to the sender. If ACK7 is lost during the transmission, this will cause the sender to timeout and retransmit.

③The retransmitted data packets No. 0~7 arrive at the receiver. The receiver will receive these 8 data packets in order according to the sequence number in the current receiving window, but the receiver has already received these 8 data before. Grouped, now it is being received repeatedly, that is to saythe receiver cannot distinguish between new and old packets, thus causing Repeat questions in groups.

(7) Summary:

①The fallback N frame protocol uses the transmission window to limit the number of data packets sent continuously by the sender based on pipeline transmission. It is a continuous ARQ protocol.

② During the working process of the protocol, the sending window and receiving window continue to slide forward, so this type of protocol is called a sliding window protocol.

③Due to the characteristics of the fallback N-frame protocol, when the communication line quality is poor, its channel utilization is not higher than that of the stop-and-wait protocol.

4. Select retransmission protocol (SR)

(1) The fallback N frame protocol is improved to the selective retransmission protocol:

Fallback N-frame protocol The receiving window size of can only be equal to 1 , therefore the receiver can only receive correctly arrived data packets in order. W_{R}

② A bit error in a data packet will cause its subsequent data packets to be discarded because they cannot be received in order by the receiver (although they are not out of order or have bit errors), which will inevitably cause the sender to timeout and retransmit these data packets. , obviously this is a huge waste of communication resources.

③ In order to further improve performance, you can try to retransmit only the data packets with errors. Therefore, the size of the receive window should no longer be equal to 1 ( but should be greater than 1) , so that the receiver first receives those data packets that arrive out of sequence but have no errors and whose sequence numbers fall within the reception window, and wait until the missing ones After a> together. This is the retransmission protocol. is collected, it is sent to the upper layer dataW_{R}

Select a retransmission protocolIn order for the sender to retransmit only the packets with errors, the receiverCumulative acknowledgment is no longer used, but each correctly received data packet needs to be acknowledgedone by one.

(2) Select the retransmission protocolUse the sending window to limit the number of data packets that the sender can send continuously on the basis of pipeline transmission.

①As shown in the figure below, assuming that 3 bits are used to number the packets, the sequence number ranges from 0 to 7 (2 minus 1 to the third power of 0 starts.

② The sender must maintain a sending window. Data packets whose sequence numbers fall within the sending window can be sent continuously without waiting for the corresponding confirmation packet from the receiver. Send, data packets whose sequence number falls outside the sending window are not allowed to be sent.

[1]The size of the sending window is recorded asW_{T}. For this example, its value range is 1~4 (2 of 3- 1 power, where 3 is the number of bits that constitute the packet sequence number ), in this example, W_{T} = 4.

[2]IfW_{T} = 1, it is equivalent to the stop-wait protocol; if the value of W_{T} Exceeding the upper limit of the value range will cause serious errors.

[3] Five data packets whose sequence numbers fall within the sending window can be sent continuously, while data packets whose sequence numbers fall outside the sending window are not allowed to be sent.

③The receiver must maintain a receiving window.Data packets with sequence numbers falling within the receiving window are allowed to be received, while data packets with sequence numbers falling outside the receiving window are not allowed to be received. .

[1]The size of the receiving window is recorded asW_{R}. For the selected retransmission protocol, it can generally be the same as the size of the sending window ( That is W_{R}=W_{T}).

[2] Four data packets whose sequence numbers fall within the reception window are allowed to be received, while data packets whose sequence numbers fall outside the reception window are not allowed to be received.

(3) In case of errors:

The sender continuously sends the data packets 0~3 whose sequence numbers fall within the sending window in sequence, and they are transmitted through the Internet Reached the receiver, but data packet No. 2 was lost.

As long as the sequence number falls within the receiving window and there are no error-coded data packets, the receiver will receive them. In this example, the receiver receives 0 No. and No. 1 data packets are sent, and confirmation packets No. 0 and No. 1 are sent. At the same time, the receiving window moves forward by 2 positions, and the two new sequence numbers 4 and 5 fall into the receiving window.

③Then the receiver receives data packet No. 3 and sends confirmation packet No. 3, but the receiving window does not move forward because 3 Data packet number is not a data packet arriving in order.

④Confirmation packets No. 0, 1, and 3 arrive at the sender one after another through Internet transmission. When the sender receives the confirmation packet No. 0 and No. 1, the sending window moves forward 2 positions, and the two new sequence numbers 4 and 5 fall into the sending window. window, the sender sends the data packets No. 4 and No. 5 whose sequence numbers fall into the sending window, and deletes the data packets No. 0 and No. 1 that have received confirmation from the sending buffer, and the receiver can choose the opportunity to send the data packets No. 0 and No. 1 that have received confirmation. The received data packets No. 0 and No. 1 are delivered to the upper layer for processing.

⑤The sender receives confirmation packet No. 3, butthe sending window cannot slide forward because the sender has not received its previous Confirmation packet No. 2, Confirmation packet No. 3 is an acknowledgment packet that arrives out of order, but the sender still needs to record that data packet No. 3 has been received. Confirm to prevent data packet No. 3 from being retransmitted after timeout.

⑥Data packets No. 4 and 5 arrive at the receiver. The receiver receives the two data packets and sends confirmation packets No. 4 and 5. However, the receiving window does not slide forward because they are data packets that arrive out of sequence. The receiver still No. 2 data packets before them have been received.

⑦ Assume that during the transmission of confirmation packets No. 4 and 5, the sender's retransmission timer for data packet No. 2 times out, the sender will retransmit the No. 2 data packet.

⑧Then confirmation packets No. 4 and 5 arrive at the sender one after another, and the sender receives them, but the sending window does not slide forward because they are confirmation packets that arrive out of order, and the receiver has not yet received their previous confirmation No. 2. group, but the sender still needs to record the confirmation that data packets No. 4 and 5 have been received to prevent data packets No. 4 and No. 5 from being retransmitted over time.

⑨The No. 2 data packet previously retransmitted by the sender reaches the receiver. The receiver receives the data packet and sends the No. 2 confirmation packet. At the same time, the receiving window slides forward 4 positions, and the sequence numbers 6~1 fall into the receiving window.

⑩Confirmation packet No. 2 reaches the sender through Internet transmission. The sender receives the confirmation packet and slides the sending window forward 4 positions. Serial numbers 6~1 fall into the sending window. The sender can now send the data of these 4 serial numbers. The packets are sent out in sequence, and the data packets No. 2, No. 3, No. 4, and No. 5 that have received confirmation are deleted from the sending buffer, and the receiver can choose the opportunity to send No. 2, No. 3, and No. 4 that have been received in sequence. , No. 5 data packet is delivered to the upper layer for processing.

(4) Window size problem:

①Restrictions on sending window size and receiving window size:

② If 3 bits are used to sequence the packet, then the maximum value of the sending window size is 4, and the maximum value of the receiving window size is determined by the sending window size, If the value of W_{T} exceeds the upper limit of the value range, for example, if the sending window size is deliberately set to 5, the receiving window size is also set to 5 accordingly: < /span>

[1] The sender sends the five data packets from 0 to 4 whose sequence numbers fall within the sending window in sequence, and they arrive at the receiver in sequence through Internet transmission.

[2] The receiver receives them and sends confirmation packets No. 0~4. At the same time, the receiving window slides forward 5 positions, and sequence numbers 5~1 fall into the receiving window.

[3] Confirmation packets No. 0 to 4 arrive at the sender one after another through Internet transmission. If the confirmation packet No. 0 is lost, the sender can only receive confirmation packets No. 1 to 4 and record that the packets No. 1 to 4 have been received. to confirm, but the sending window cannot move forward.

[4] After a period of time, the sender's retransmission timer for data packet No. 0 times out, and the sender retransmits data packet No. 0. The data packet reaches the receiver through Internet transmission. If the sequence number 0 falls within the receive window, the receiver will receive the data packet, but the receiver has previously received the data packet correctly, so this causes packet duplication< a i=2> problem.

(5) Summary:

5. Point-to-Point Protocol PPP

1. Overview of Point-to-Point Protocol PPP

(1) Point-to-Point Protocol PPP (Point-to-Point Protocol) is currently the most widely used point-to-point data link layer protocol.

(2) When the user's computer communicates with the ISP, the data link layer protocol used is usually the PPP protocol.

(3) Point-to-point protocol PPP is also widely used in dedicated lines between WAN routers.

(4) The PPP protocol was developed by the Internet Engineering Task Force IETF in 1992. After revisions in 1993 and 1994, the current PPP protocol has become the official standard of the Internet [RFC1661, RFC1662].

(5) The PPP protocol provides a standard method for transmitting various protocol datagrams on point-to-point links. It mainly consists of the following three parts:

① Encapsulation methods for various protocol datagrams (i.e. encapsulation into frames).

②Link Control Protocol LCP (used to establish, configure and test data link connections).

③A set of network control protocols NCPs (each of which supports different network layer protocols).

(6) From the perspective of network architecture:

① PPP is a data link layer protocol, which encapsulates the protocol data units delivered by the upper layer into PPP frames.

② In order to support different network layer protocols, the PPP protocol includes a set of network control protocols NCPs, each of which supports different network layer protocols, such as IP in TCP/IP, IPX in Novell Netware network operating system, etc.

③ Link control protocol LCP is used to establish, configure and test data link connections. The PPP protocol can run on multiple types of point-to-point links, such as byte-oriented asynchronous links and bit-oriented synchronous links.

2. Frame format of PPP protocol

(1) The frame header consists of 4 fields, and the frame tail consists of 2 fields. The length of each field and the maximum length of the data part of the frame are as shown in the figure below.

(2) The Flag field in the frame header and frame tail is the delimiter of the PPP frame, and its value is 7E in hexadecimal.

(3) The value of the Address field in the frame header is hexadecimal FF (reserved, currently of no use).

(4) The value of the Control field in the frame header is 03 in hexadecimal (reserved, currently has no effect).

(5) The Protocol field in the frame header indicates which protocol the data part of the frame should be sent to for processing.

①The value is 0x0021, indicating that the data part of the frame is an IP datagram.

②The value is 0xC021, indicating that the data part of the frame is the packet of the link control protocol LCP.

③The value is 0x8021, indicating that the data part of the frame is the packet of the Network Control Protocol NCP.

(6) The Frame Check Sequence field at the end of the frame, whose value is the check bit calculated using the cyclic redundancy check CRC, is used to check whether there are bit errors in the PPP frame.

3. PPP protocol realizes transparent transmission

(1) When the flag field in the frame header and frame tail appears in the data part of the PPP frame, if no measures are taken, the receiver will misjudge whether the PPP frame ends, because the flag field is the delimiter of the PPP frame. , the value is 0x7E.

(2) The method of PPP protocol to achieve transparent transmission depends on the type of link used:

① If it is a byte-oriented asynchronous link, use byte filling method, that is, insert escape characters.

② If it is a bit-oriented synchronization link, the bit filling method is used, that is, bit 0 is inserted.

(3) Byte filling method:

①The sender converts each 0x7E byte that appears in the data part into a 2-byte sequence [0x7D,0x5E], which is equivalent to inserting the escape byte0x7D< before the 0x7E byte /span>, and subtract 0x20 from the 0x7E byte.

②The sender converts each 0x7D byte that appears in the data part into a 2-byte sequence [0x7D,0x5D], which is equivalent to inserting the escape byte0x7D< before the 0x7D byte /span>, and subtract 0x20 from the 0x7D byte.

③The sender inserts a0x7D before each ASCII code control character (a character with a value less than 0x20) that appears in the data part a> to the encoding of the character. adds 0x20, and bytes

④The receiver performs the above three transformationsinverse transformation on the received data frame to restore the original frame.

(4) Bit stuffing method:

① Use 0x7E (01111110 when converted to binary) as the delimiter of the PPP frame. As shown in the figure below, the data part added to the frame contains two frame delimiters.

②The sender scans the data part of the frame (usually implemented by hardware),As long as 5 consecutive bits of 1 are found, it will immediately fill in 1 bit with 0 .

③The receiver scans the data part of the received frame (usually implemented by hardware),As long as 5 consecutive bits of 1 are found, the following bit will be 0 Delete.

4. PPP protocol implements error detection

(1) The tail of the PPP frame contains a 2-byte frame check sequence FCS field. The cyclic redundancy check CRC is used to calculate the value of this field. The generator polynomial used is shown in the figure below.

(2) The appendix of RFC1662 provides the C language implementation of the FCS calculation method (look-up table method). In order to reduce CPU usage, the calculation of FCS is implemented using the look-up table method; the calculation range of FCS is shown in the figure.

(3) Each time the receiver receives a PPP frame, it performs a CRC check. If the CRC check is correct, it will accept the frame, otherwise it will discard the frame. The data link layer using the PPP protocol does not provide reliable transmission services upward.

5. Working status of PPP protocol (taking dial-up access as an example, the slightly more complicated version will be introduced)

(1)The start and end status of the PPP link are both "quiescent" states, and there is no physical layer connection at this time .

(2) When detects the modem’s carrier signal and establishes the physical layer connection. the link control protocol LCP begins negotiating some configuration options, then enters the "established" state, the PPP link

(3)If the negotiation is successful, the PPP link enters the "identification" state; if the negotiation fails, the PPP link returns to "quiescent" state. The negotiated configuration options include maximum frame length, authentication protocol, etc. Authentication may not be used, Password Authentication Protocol PAP or Challenge Handshake Authentication Protocol CHAP may be used.

(4)If the communicating parties do not need to authenticate or the identity authentication is successful, it will enter the "network" state; if the authentication fails, it will enter the "network" state. terminated" status.

(5)Configure NCP after entering the "Network" state. After the configuration is completed, it enters the "Open" state. Both ends of a PPP link perform NCP configuration by exchanging network layer-specific NCP packets with each other. If the IP protocol is running on the PPP link, use the IP control protocol IPCP to configure the IP module on each end of the PPP link, such as assigning IP addresses.

(6)Data communication is possible as long as the link is "open".

(7) When a failure occurs or one end of the link issues a termination request, it enters the "termination" state.

(8) When the carrier stops, it returns to the "quiescent" state.

6. Working status of PPP protocol (taking dial-up access as an example to briefly introduce the version)

(1) Initialization process of PPP link:

① When the user dials up to access the ISP, a physical connection is established from the user's personal computer to the ISP. At this time, the user's personal computer sends a series of links to the ISP Control protocol LCP packet (encapsulated into multiple PPP frames) in order to establish the LCP connection. The LCP packet and its response select some PPP parameters that will be used< /span>.

② Then proceed network layer configuration, Network Control Protocol NCP to newly accessed users The computer is assigned a temporary IP address, so that the user's personal computer becomes a host with an IP address on the Internet.

(2)When the user communication is completed, NCP releases the network layer connection and takes back the originally assigned IP address. Then LCP releases the data link layer connection and finally releases the physical layer. Connection.

(3) The starting and ending status of the PPP link is always the "Link is still" state, At this time, there is no physical layer connection between the user's personal computer and the ISP's router.

Guess you like

Origin blog.csdn.net/Zevalin/article/details/134976319