【408 Computer Network】Data Link Layer


First, the function of the data link layer

Improve the original, error-prone physical lines into logically error-free data links, thereby providing high-quality services to the network layer.
Specifically, the main functions of the data link layer are as follows:
1) Link management : responsible for the establishment, maintenance, and release of data links (mainly used for connection-oriented services)
2) Frame synchronization : the receiver determines the received bits The start position and end position of a frame in the stream
3) Error control : used to make the receiver determine that the received data is the data sent by the sender
4) Transparent transmission : Transparent transmission means that no matter what kind of bit combination the data is, it should be Can be transmitted on the data link (for example: if there is a frame delimiter 01111110 in the data to be sent, if there is no transparent transmission function, then the computer network will think that this is a terminator and truncate it, resulting in receiving wrong data)
data The link layer provides three basic services:
1. Connectionless service without confirmation
2. Connectionless service with confirmation
3. Connection service with confirmation

2. Framing

2.1 Why framing? Wouldn't it be better to send the bitstream directly?

The advantage of framing is that if something goes wrong, you only need to send the wrong frame, so as not to retransmit all the bit streams, which is worthwhile compared to the problems of frame synchronization, frame delimitation, and transparent transmission.

2.2 Why is it necessary to add both a header and a tail when forming a frame, but only need to add a header when cutting a message into groups?

Because the frame is the smallest unit of transmission in the network , to receive the frame correctly, it must be clear where the frame starts and ends in a series of bit streams . The packet is only included in the data part of the frame, so there is no need to add a tail.

2.3 Four framing methods

2.3.1 Character Counting Method

Use a count field to indicate the number of bytes contained in the frame. If there is an error in the count field during transmission, the frame synchronization will not be possible, so this is rarely used

2.3.2 Head and tail delimiter method for byte filling

The beginning and end delimiter method: the frame starts with SOH (a special character in ASCII) as the sign of the start of the frame, and the end of the frame uses EOT as the end of the frame. The beginning and end delimiter method: if the transmitted data
contains SOH, EOT, Then convert SOH into ESC+x two characters, EOT into ESC+y, ESC into ESC+z

2.3.3 Head and tail marking method of bit stuffing

This method is also called the zero-bit stuffing method. In the data part of the frame, every time five 1s are encountered, a 0 is added at the end, and then 01111110 is used as the frame delimiter.

2.3.4 Physical coding violations

In Manchester encoding, high and low levels represent 1, and low and high levels represent 0, so high, high and low and low levels can be used for frame delimitation

3. Error Control

3.1 Error detection coding

3.1.1 Parity code

Predetermine whether to use odd parity or even parity, add a 0 or 1 to the last bit of the data, so that the number of 1s in the data is an odd number or an even number.
For example, use odd parity: if the information data is 1100010, then add a 0 at the end to get 11000100. After the receiver receives it, it finds that there are an odd number of 1s in the whole, then the data is considered correct.
Defect: After the two bits of data change, it cannot be detected.

3.1.2 CRC Cyclic Redundancy Code

The information to be sent is 101001, and the generation formula is G(x)=x^3 + x^2+1
Step 1: Construct the dividend
and add (highest degree of polynomial or divisor—1 digit) 0s to the end of the data to be sent , to get 101001000
Step 2: Construct a divisor
to convert the polynomial into a 01 string, such as G(x)=x^3 + x^2+1 to get 1101 Step 3
: Do division (use XOR operation for ± operation)
and use 101001000 Divide by 1101 to get 1.
Step 4: Process the remainder.
The number of digits of the remainder should be the same as the highest number of production expressions. If not, add 0 to get 001.
Step 5: Send data
Send data 101001001 to the receiver
Step 6: Check After receiving the data, the receiving
party divides the data by 1101, if it is 0, the transmission is correct, otherwise it is incorrect

3.2 Error Correction Coding

Hamming code is more complicated. And it is not easy to express in words.

4. Flow control and reliable transmission mechanism

Flow control and reliable transmission mechanism are the functions of the transport layer, understand in advance

4.1 Flow Control

Flow control is to control the rate at which the sender sends data so that the receiver can receive it in time.
A basic approach is for the receiver to control the flow of data from the sender. There are two common ways: stop-wait flow control and sliding window flow control
1) Stop waiting for flow control
The sender sends a frame, and then waits for the response signal to arrive before sending the next frame. The receiver returns an acknowledgment signal after receiving each frame, indicating that the next frame can be accepted. If the receiver does not return an acknowledgment, the sender must wait forever.
2) Sliding window flow control The concept of sliding window flow control can be understood in 4.2 Reliable Transmission Mechanism
without detailed explanation here

4.2 Reliable transmission mechanism

Note: Only reliable transmission mechanism is mentioned here, not unreliable transmission mechanism, which does not mean that each layer only has reliable transmission mechanism.
Reliable transmission service: find a way to realize what the sender sends, and the receiver receives what.
Unreliable transport service: just drop frames with errors and do nothing else.
Generally, 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 problem of reliable transmission is handed over to its upper layer. Louis is subject to interference and the bit error rate is high, so the data link layer is required to provide reliable transmission services. The
above are only bit errors, and there are also transmission errors, including packet loss, packet out-of-order, and packet repetition.
The implementation of reliable transmission is more complicated, and the overhead is relatively large, so whether reliable transmission is required depends on actual needs.
Three reliable transmission protocols: stop waiting protocol, back N frame protocol, and select retransmission protocol

4.3 Stop and wait protocol

insert image description here

4.4 Go Back N Frame Protocol

The basic principle of the Back N frame protocol: After sending a data frame, the sender stops from time to time to wait for the confirmation frame, and the second is that it can continuously send several data frames. If the receiver's acknowledgment frame is received at this time, then the data frame can also be sent. If a frame is corrupted, the receiver can simply discard that frame and all subsequent frames . After the timeout, the sender needs to resend the error frame and all subsequent frames. Due to the reduced waiting time, the Go Back N frame protocol improves the throughput of the entire communication, but once the receiver finds an error frame, it will no longer accept subsequent frames, resulting in a certain waste. Based on this improvement, a selective retransmission protocol is obtained.
insert image description here

insert image description here

4.5 Select retransmission protocol

The receiving window size Wr of the fallback N-frame protocol can only be equal to 1, so the receiver can only receive correctly arrived data packets in sequence.
The bit error of a data packet will cause its subsequent multiple data packets to be discarded by the receiver because they cannot be received in order (although they have no out-of-sequence or bit error). This will inevitably cause the sender to retransmit these data packets over time, which is obviously a great waste of communication resources.
In order to further improve performance, it is possible to try to retransmit only errored data packets. Therefore, the size Wr of the receiving window should no longer be equal to 1, but should be greater than 1, so that the receiving side first accepts those data packets that arrive out of order but have no error codes and whose sequence numbers fall within the receiving window, and wait until all missing packets are collected before proceeding. And send it to the upper layer, this is the selection retransmission protocol.
Note: In order to select the retransmission protocol, in order to make the sender retransmit only the packets with errors, the receiver can no longer use cumulative confirmation, but needs to confirm each correctly received data packet one by one!
Detailed animation demonstration process: Recommend station b up master Lake University of Science and Technology teaching craftsman computer network micro-classroom Lecture 027 The realization mechanism of reliable transmission - select the retransmission protocol
insert image description here

insert image description here

4.6 Send buffer and receive buffer

When two processes of a computer (in the same machine or in two different machines) communicate, if the sending process sends data directly to the receiving process, then the two actions (one is sending, the other is receiving) ) is very difficult to coordinate well. This is because the action of the computer is very fast. If the receiving process starts to perform the receiving action at a certain moment, but the sending action of the sending process is a little earlier or a little later (in the case that the sending and receiving parties have not synchronized in advance, the sending The time cannot coincide exactly with the receiving time), which will cause the receiving to fail. Therefore, during the communication between computer processes, caching is widely used.
A cache is a space set in the computer's memory to temporarily store data. The sending process writes the data to be sent into the cache first, and then the receiving process reads out the data at an appropriate time.
A cache is a bit like the mailboxes that the post office sets up on the street. We can drop the letters we want to send in the mailbox at our convenience. The postman of the post office opens the mailbox at the appropriate time according to his plan, takes away the letters put in by everyone, and delivers them to the post office for further processing.
The cache can well solve the contradiction between the inconsistency of the sending rate and the receiving rate, and can also perform serial-to-parallel conversion very conveniently, that is, the bit stream is written serially and read out in parallel, or written in parallel and read out serially.

5. Media Access Control

5.1 Classification of Media Access Control

In the local area network, if the use of the shared channel creates competition, how to better allocate the right to use the channel is a very important issue, and the medium access control is born to solve this problem. The medium access control required by the postgraduate entrance examination is divided
into The following three categories
1) Channel partitioning media access control
2) Random access media access control
3) Polling access media access control

5.2 Channel partitioning media access control

Channel division and medium access control use multiplexing technology. Multiplexing technology can combine multiple signals on one physical channel for transmission, so that multiple computers or terminal devices can share channel resources, thereby improving channel utilization. .
Channel division technology is divided into the following four types:
1. Frequency division multiplexing: divide a channel into multiple channels of different frequencies
2. Time division multiplexing: allocate channels to different users according to time, traditional time division multiplexing Multiplexing (also called synchronous time-division multiplexing) has a defect. The defect is that even if the user is idle, it will be allocated to a time slot, resulting in waste. The solution: statistical time-division multiplexing (also called asynchronous time-division multiplexing) 3. Wavelength division insert image description here
insert image description here
multiplexing: In layman's terms, it is frequency division multiplexing of light, changing the frequency to wavelength
4. Code division multiplexing: also called code division multiple access (CSMA) , It not only shares the frequency of the channel, but also shares the time, which is a real dynamic multiplexing technology.
Concept: Each site maintains a chip sequence belonging to the site and is fixed. If the chip sequence of station A is 00011011, station A sends 00011011 to indicate sending bit 1; and inverts every bit of 00011011, that is, sending 11100100 indicates sending bit 0. It is customary to write 0 in the chip sequence as -1, and 1 as +1, so the chip sequence of station A is (-1 -1 -1 +1 +1 -1 +1 +1), generally this vector is called the The chip vector for the station. The chip vectors of any two different stations are orthogonal, that is, the normalized inner product of the chip vectors of any two stations must be 0. The normalized inner product of the chip vector of any site and the chip vector itself must be 1; the normalized inner product of the chip vector of any site and the inverse code vector of the chip must be -1.
Classic example:
insert image description here
insert image description here

5.3 Random Access Media Access Control

When several computers use one channel to send data, they need to share this channel, and one of the most important considerations for sharing a channel is how to enable many users to share it reasonably and conveniently without conflicts, so the following occurs: There are two ways to divide channels:
the first is to divide channels statically: that is, frequency division multiplexing, time division multiplexing, etc. This method will not conflict with other users as long as the user is allocated to the channel. But the cost of this kind of channel division is quite high ,
it is not suitable in a small LAN

  • Random access: All users can send messages randomly according to their own wishes, which will cause conflicts, which will cause all conflicting users to fail to send data. In order to solve the collision that occurs in random access, protocols such as CSMA/CD are introduced.
  • Controlled access: You cannot send data randomly, you must get something before you have the right to send data.

Random access needs to master four kinds in the postgraduate entrance examination: ALOHA protocol, CSMA protocol, CSMA/CD protocol, and CSMA/CA protocol. The core idea of ​​these four protocols is that only the winner can obtain the channel through contention, so as to obtain information. right to send. Therefore, random access media access control has another nickname called: "contention protocol"

5.3.1 ALOHA protocol

ALOHA protocol: Send it when you want to send it without any detection. If you don’t receive confirmation for a period of time, it will be considered that there is a conflict and wait for a random time before sending it.
Time-division ALOHA protocol: The time of all nodes is divided into the same time interval, and each node is stipulated to wait until the next time slot arrives before sending.

5.3.2 CSMA protocol (Carrier Sense Multiple Access Protocol)

Before sending data, each node uses carrier sense technology to judge whether the channel is idle. Common CSMA has three strategies:

  1. 1- Persist in CSMA: send data immediately when listening to idle, otherwise continue to listen
  2. p-Persist CSMA: When listening to idle, p probability to send data, 1-p probability to delay for a random period of time to listen again
  3. Non-persisting CSMA: When listening to idle, send data immediately, otherwise listen again after a random period of time

5.3.3 CSMA/CD Protocol (Carrier Sense Multiple Access Protocol with Collision Detection)

Workflow of CSMA/CD:
listen before sending : before sending data, each station checks whether there are other computers sending data on the line. If there is, it will not send data temporarily to avoid conflicts
. Listening and sending : (reflected by the improvement of CSMA) When the computer is sending data, it will always detect whether there is a conflict in the channel Stop sending
: (reflected by the improvement of CSMA) If a conflict is detected, it will stop sending data and
resend randomly : Use a truncated binary exponential type backoff algorithm to wait for a random period of time before retransmitting.
insert image description here
insert image description here
Four important data in CSMA/CD: end-to-end length, data transmission rate, contention period, minimum frame length
When a certain item changes, remember that the minimum frame length remains unchanged , it must be 512bit=64B
. 10Mbit/s, 1000m, contention period 51.2us, minimum frame length 64B in the network, now plan to change 10mbit/s to 100Mbit/s, so how will the items change?

  • Transfer rate 10Mbit/s–>100Mbit/s
  • End-to-end length 1000m–>100m [reason: minimum frame length (unchanged) = transmission rate (expanded by 10 times) x end-to-end length ( reduced by 10 times ) / signal propagation speed*2]
  • Contention period 51.2us–>5.12us [reason: minimum frame length (unchanged) = transmission rate (expanded by 10 times) x contention period ( reduced by 10 times )]

The most important thing is to understand the CSMA/CD process. The video explanation is recommended. The computer network micro-classroom Lecture 031, Random Access — CSMA/CD Protocol

5.3.4 CSMA/CA protocol

CSMA/CA is mainly used in wireless local area networks , defined by the IEEE802.11 standard, which adds the function of conflict avoidance on the basis of CSMA. Collision avoidance requires each node to listen to the channel before sending data. If the channel is free, send data. After sending a frame, the sending node must wait for a period of time (called the interframe interval) to check whether the receiver sends back an acknowledgment of the frame. If an acknowledgment is received, it indicates that no conflict has occurred. If no acknowledgment is received within the specified time, it indicates a conflict and the frame is resent.

5.4 Polling Access Media Access Control

Polling media access control is mainly used in Token Ring LAN , and it is rarely used at present. In the polling access media access control, the user cannot send information immediately, but decides the allocation of the channel after a polling process through a centralized control monitoring station.

6. Introduction to LAN

7. Introduction to WAN

Eight, data link layer equipment

Guess you like

Origin blog.csdn.net/qq_42425551/article/details/121871907