[Computer Network] Speak clearly "Data Link Layer" in more than 10,000 words

data link layer

Preface

The channels used by the data link layer are mainly of the following two types:

  1. Point-to-point channel. This channel uses a point-to-point approach.
  2. Broadcast channel. This channel uses one-to-many broadcast communication, so the process is more complicated. There are many connected hosts on the broadcast channel, so a dedicated shared channel protocol must be used to coordinate the data transmission of these hosts, that is, the protocol is used to resolve conflicts.

3.1 Data link layer using point-to-point channels

  • Data link and frame

    First, it is clear that the concept of a "link" and "data link" are two different concepts, a "link" refers to a node to another node physical route section, and the "data link" sucked The hardware and software that implement the transmission protocol are added to the link.

    The protocol data unit of the data link layer of the point-to-point channel is called a frame.

    The main steps of the data link layer of the point-to-point channel during communication:

    1. The IP datagram handed over by the network layer is encapsulated into a data frame by adding a header and a tail. (Encapsulated into a frame)
    2. Send the assembled frame to the next node. (Transparent transmission)
    3. The node receiving the frame performs error checking. (Error detection)
  • Three basic questions

    No matter it is any protocol, it faces the problems of encapsulation into framing, transparent transmission, and error detection.

    1. Encapsulated and framed

      Add the header and tail to the data handed over by the network layer, and the node that receives the frame can judge the start and end of the frame based on the header and tail. The data part of each frame does not exceed the length of MTU. The MTU should not be too large or too small. Too small will lead to a waste of efficiency. If it is too large, it will be refused to send. It may be understood that once the error is lost, the retransmitted data will be Much.

      When the data is a text file composed of ASCII, a special frame delimiter can be used for frame delimitation. You can add SOH and EOT control characters at the beginning and end of the frame, so that the receiving end can clearly determine the various situations of the frame and make corresponding processing.

    2. Transparent transmission

      "Transparency" means that something that actually exists looks like it doesn't exist. During transmission, if the ascii text file is being transmitted, the frame delimitation control characters such as SOH and EOT will not appear in its data part. However, when transmitting binary files, it is inevitable that the binary code is the same as the binary code of the frame delimitation flag, which will cause wrong judgments at the receiving end. The general method is to appear "SOH" and "EOT" in the ** data. Add an escape character before **, and the receiving end will remove the transfer character after receiving it. For data, the data is invisible to the data link layer that hinders its transmission, so the data link layer is transparent to the data. Transparent transmission can be understood as that there are no restrictions on the transmitted data; in contrast, non-transparent transmission has restrictions on the requirements for data transmission. In short, transparent transmission means everything can be transmitted.

    3. Error check

      The actual communication link is not ideal, and it is inevitable that there will be bit errors when transmitting data, which is called bit errors. In order to avoid data errors, an error check mechanism is used when transmitting data. Currently, CRC technology (required) is widely used . See P75 in the book. After each frame received at the receiving end is checked by CRC, if the remainder is 0, then the frame is accepted, if the remainder is not 0, then the frame is discarded.

      OSI's point of view is that the data link layer must provide reliable transmission upwards. Obviously, the use of CRC only ensures that the bits are not error-free, and there is still the possibility of transmission errors, such as frame duplication, frame out of sequence, etc. Therefore, the data link layer adds a frame numbering, confirmation, and retransmission mechanism on the basis, which ensures reliability.

      For the wired transmission link with good communication quality, the data link layer protocol does not enable the confirmation and retransmission mechanism; for the poor transmission link, the confirmation and retransmission mechanism is turned on. Practice has proved that this can improve communication efficiency.

3.2 Point to Point Protocol (PPP)

  • Features of the agreement

    The PPP protocol is the protocol of the data link layer when the user computer and the ISP communicate.

    The following requirements were considered when designing the PPP protocol:

    1. Simple, put the most complicated part in the TCP protocol, the IP protocol is relatively simple, so the data link layer does not need to implement more functions than IP, so the transmission is unreliable.
    2. Encapsulate into frames.
    3. Transparent transmission, transparent transmission means to solve the problem of data transmission transparency, see the previous explanation of transparency.
    4. A variety of network layer protocols are suitable for a variety of scenarios, regardless of whether it is connected to a local area network or a router.
    5. Various types of links.
    6. Error detection, discarding error frames, so as not to waste subsequent network resources.
    7. Check the connection status.
    8. Maximum transmission unit.
    9. Network layer address negotiation.
    10. Data compression negotiation.

    PPP does not need: 1, error correction (simple feature) 2, serial number (simple feature) 3, flow control (simple feature) 4, multipoint line 5, half-duplex or simplex link (there will be negotiation between two points ?)

  • The composition of the agreement

    Divided into 3 components:

    1. The data part does not exceed the length of MTU.
    2. The link control protocol LCP used to establish, configure, and test data link connections.
    3. A set of network control protocol NCP, each of which supports different network layer protocols.
  • Frame format of PPP protocol

    1. The meaning of each field

      The main attention here is that the flag field uses hexadecimal 7E to indicate the beginning and the end. Two consecutive 7Es indicate an empty frame.

    2. Transparent transmission related

      Byte padding: In asynchronous transmission, in order to avoid the same combination of fields as the flag field, a method such as byte padding will be adopted. His byte filling method is to convert the start mark into two escape characters, and then convert again if there is a conflict. In short, it is such a process. Use the same method to switch back on the receiving end.

      Zero-bit padding: When using a series of bit transmission, PPP will adopt zero-bit padding. If you spray 5 1s, a 0 will be added at the end, because there are 6 1s in the middle of 7E (01111110). Avoid 6 1s in the data, and add 0s when 5 1s appear. After the receiving end receives it, remove 0.

      Transparent transmission is achieved through the above two methods

  • Working status of PPP protocol

Insert picture description here

The state diagram of the PPP protocol is as above. I think there are two points that need to be understood:

  1. Establish a connection with the ISP, and initiate the connection by transmitting LCP packets to the ISP.
  2. The PPP protocol adapts to different network layer protocols. After the connection is established, the network layer configuration must be performed according to the NCP protocol. The network layers at both ends of the PPP protocol can use different protocols, but they can still communicate using PPP.

3.3 Data link layer using broadcast channel

The local area network uses the broadcast channel, so the local area network is used for discussion.

  • Data link layer of the local area network

    The main advantages of LAN:

    1. With broadcasting function, you can easily visit the whole network from one site.
    2. With the expansion and evolution of the system, the location of each device can be flexibly adjusted and changed.
    3. Improve the availability, reliability and survivability of the system.

    An important issue to be considered when sharing channels is that users can share media resources reasonably and conveniently. There are two methods technically:

    1. Channels are divided statically. As long as the user is assigned to the channel, it will not conflict with other users.
    2. Dynamic media access control, also known as "multipoint access". This is divided into random access (collision may occur) and controlled access (using polling, one by one).
    • The role of the adapter

      The communication between the computer and the external LAN is carried out through an adapter. The communication between the adapter and the local area network is carried out in a serial manner through cables and twisted pairs, and the communication between the adapter and the computer is carried out in a parallel manner through the I/O bus. The data rate on the network is very different from the data rate on the computer bus, so a chip for data caching is installed in the adapter. When installing the adapter on the motherboard, the driver must be installed on the computer simultaneously, so that the driver will tell the adapter from which location to fetch the data for transmission, or where to place the obtained data. The adapter does not use the computer's CPU when receiving and sending frames, which means that the CPU can do other tasks. When the adapter receives the correct frame, it generates an interrupt to notify the computer and deliver it to the network layer. When sending an IP datagram, the datagram is handed over to the adapter to assemble into a frame and then sent to the LAN.

  • CSMA/CD protocol

    In order to facilitate communication, Ethernet has adopted the following two measures:

    1. Using a connectionless working method, ** does not number the data frame, and does not require the other party to confirm the return, it is to do its best to deliver, which is an unreliable interaction. **The retransmission of error frames is determined by the upper layer. When a computer is sending data, the transmission resources of the bus are occupied. Therefore, only one computer can send data at the same time. There will be conflicts. To solve the conflicts, the agreement CSMA/CD is required.
    2. The data sent by Ethernet uses Manchester-encoded signals. In short, the receiving end needs to detect the bit synchronization signal, and the detection needs to obtain the edge transition on the data. If the transmission of 0 or 1 is carried out for a long time, the edge cannot jump and the synchronization signal cannot be obtained, so Manchester encoding is required.

    The essence of the CSMA/CD protocol is "carrier monitoring" (each station must continuously detect the channel before or during transmission) and "collision detection" (monitoring while transmitting).

It can be seen from the figure that the longest time for A to find a conflict is 2 τ \tauτ time. It can also be seen that when using the CSMA/CD protocol, a station cannot send and receive at the same time. Therefore, the Ethernet using this protocol cannot perform full-duplex communication, but can only perform two-way alternate communication. For station A, at most 2τ \tauAfter τ , you can find out if there is any conflict, which is called the contention period. After the expropriation period, there is no collision, which means that there will be no collision during this period.

Ethernet uses a truncated binary exponential backoff algorithm to handle retransmissions. After the conflict occurs, in order to avoid the recurrence of the conflict, instead of immediately transmitting the data again, but first waiting for a random number to transmit, this algorithm is to generate this waiting random number, see book P88 for details.

There is a situation when a conflict occurs. If the transmitted frame data is too short, even if a collision occurs, the receiving end receives an error frame and discards it. The sender cannot detect it because it is too short, so the sender does not know Retransmission is required. Therefore, the minimum frame length is specified to be 64 bytes. Any bytes with a length less than 64 are invalid frames that are abnormally terminated due to conflicts. Such frames are immediately discarded when they are received.

After a collision occurs, in addition to immediately stopping sending data, it is necessary to send man-made interference signals to let all users know that a collision has occurred.

Ethernet also stipulates that the minimum frame interval is 96 bit time, which is used to clean up the buffer of the receiving station and prepare for receiving the next frame.

The key points of the CSMA/CD agreement are summarized as follows:

  1. Ready to send: Check the channel before sending the Ethernet frame.
  2. Channel detection: if the channel is detected to be busy, it will wait until it is idle. If it is detected that the channel is idle and it is still idle within 96 bits, the frame will be sent.
  3. The channel is still detected during the sending process, and the channel is monitored while sending. If there is no collision, it means that the transmission is successful. If a collision occurs, the avoidance algorithm is executed, and the transmission is waited.

After the Ethernet sends a frame, it will temporarily reserve the frame to avoid collisions and use it when retransmitting.

Guess you like

Origin blog.csdn.net/weixin_54707168/article/details/115023596