Encapsulation and decapsulation, cross-layer encapsulation

Encapsulation and decapsulation
We generally call the process of data processing from the application layer to the data link layer as encapsulation, and the reverse process is called decapsulation and encapsulation
—adding the most important data of each layer to the original data to realize this layer function.

Application layer —The application needs to be encapsulated, but the encapsulation method depends on different applications (for example, if you log in to three QQ numbers on the computer at the same time, if you want to send a message to one of them, you must rely on the QQ number to distinguish (not Use the port number to distinguish, because the port number is to distinguish different applications, so it is necessary to rely on the QQ number to serve as the address of the session layer to distinguish the information between different QQ numbers), WeChat relies on the WeChat ID to distinguish, this is encapsulation The method depends on different applications)
Transport layer - encapsulates the port number (encapsulates the port number by the protocol working at the transport layer) - relies on TCP and UDP protocols to encapsulate the
network layer - encapsulates the IP address (encapsulates the protocol by working at the network layer IP address) - rely on IP protocol for encapsulation
Data link layer
- encapsulate MAC address (encapsulate MAC address by protocol working in data link layer) - rely on Ethernet protocol for encapsulation
Physical layer - no encapsulation (electrical signal cannot encapsulation, it can only be transported and processed)

insert image description here
The type field is very important. It can judge which module to send the data to after decapsulation according to the protocol used. For example, if the Ethernet type judges that the data is an IPV4 network type, the data packet will be handed over to the IPV4 module for processing. The protocol used for type judgment is the TCP protocol, and the data segment will be handed over to the TCP module for processing. If there is no type field, the data will not know where to go.

There are two main forms of cross-layer encapsulation:
1. Cross-four-layer encapsulation—OSPF ​​protocol (directly connected between routers (routers are layer-3 devices, only look at IP addresses; switches are layer-2 devices, generally only look at MAC addresses)) ( No need to encapsulate the source port number and destination port number of the fourth layer, and directly encapsulate IP from the session layer to the network layer)
2. Cross-three and four-layer encapsulation-the communication between direct-connected switches can cross three and four-layer encapsulation

Layer 3 IP header:
insert image description here

The third layer protocol can replace the fourth layer port number, so it can cross the four layer
protocol number:
TCP — 6 stands for TCP (6 is the protocol number)
UDP — 17 stands for UDP
protocol number — consists of 8-bit binary — 0 - 255 - --- It can be used to calibrate the upper layer protocol
OSPF of cross-layer encapsulation ---- The corresponding protocol number is — 89

Data frame structure diagram:
insert image description here
the type field of the second layer can mark the field of the fourth layer, instead of marking the upper layer application of the fourth layer, so as to cross the fourth layer
and the second layer should also be able to segment the data to complete the function of the third layer, but In ordinary Ethernet (Ethernet) layer 2 frames, the second layer cannot complete the function of data fragmentation, but the second layer of IEEE 802.3 frames can complete the function of data fragmentation, so in cross-layer 3 and layer 4, IEEE 802.3 frames are used

Preamble—The first 8 and 7 characters of Ethernet and IEEE 802.3 are used to activate the corresponding program
SOF—the frame delimiter (the official start of the calibration frame)
Length----refers to the following data part (802.2 Header and Data )
The length of
the data link layer is divided into two sublayers:
MAC - Media Access Control Layer (access and control of hardware)
LLC - Logical Link Control Layer - provides fragmentation and the role of marking data type numbers

insert image description here
DSAP--occupies a byte length, refers to the physical upper layer protocol type of a frame
SSAP----indicates the type of the upper layer protocol of the frame (which protocol the frame is generated by)
Control field-----control field, can Realize two functions: ①Reliable transmission ②Sharding and sorting

Guess you like

Origin blog.csdn.net/xiaoxiaoxyxz/article/details/128540969