网络数据传输中的封装与解封装详解

注:机翻,未校对。

The goal of networks is to transmit data from one host to another.
网络的目标是将数据从一个主机传输到另一个主机。

在这里插入图片描述

Encapsulation 封装

To achieve this goal, each layer adds its own header to the data. A header contains information specific for that layer, and it precedes the data itself.
为了实现此目标,每一层都会向数据添加自己的标头。标头包含特定于该层的信息,并且位于数据本身之前
在这里插入图片描述
Consider a case where we have a lookup service, used in order to find a person’s phone number, given the person’s name. The data consists of the person’s first and last name.
考虑一个案例,我们有一个查找服务,用于查找一个人的电话号码,给定这个人的名字。数据由此人的名字和姓氏组成。

Before the packet is sent, the fifth layer might add its own header, describing that this is a REQUEST packet. The header might also specify that this is a request to map from a person’s name to a phone number, and not vice versa.
在发送数据包之前,第五层可能会添加自己的标头,描述这是一个 REQUEST 数据包。标头还可以指定这是从人员姓名映射到电话号码的请求,反之亦然。

image-64

Header of the 5th layer, with data

Then, the fifth layer passes the data to the fourth layer. Note, that the fourth layer regards everything as data – ones and zeroes. It doesn’t care if the fifth layer added a header, or what is written inside that header.
然后,第五层将数据传递到第四层。请注意,第四层将所有内容视为数据——1 和 0。它不在乎第五层是否添加了标题,也不在乎该标题中写了什么。

The fourth layer then adds its own header. For instance, it might specify that the requested service is the names-and-phones service. It may also include a sequential number for the packet, so it can be identified later.
然后,第四层添加自己的标题。例如,它可能指定请求的服务是姓名和电话服务。它还可能包括数据包的序列号,以便以后可以识别。

image-65

Header of the 4th layer, with data which includes the 5th layer’s header

Afterwards, the fourth layer will pass the packet to the third layer. Again, the third layer will regard everything it has received – including the data itself, the header added by the fifth layer, and the header added by the fourth layer – simply as a chunk of data.
之后,第四层将数据包传递到第三层。同样,第三层将它收到的所有内容(包括数据本身、第五层添加的标头和第四层添加的标头)简单地视为数据块。

Then, the third layer will add its own header. For instance, it may include the source address and destination address of the packet.
然后,第三层将添加自己的标题。例如,它可能包括数据包的源地址和目标地址。

image-66

Header of the 4th layer, with data which includes the 4th layer’s header and data

This process goes on. So, each layer adds its own header to the packet*. This process is called encapsulation.*
这个过程还在继续。因此,每一层都会向数据包*添加自己的标头。此过程称为封装。

On the other end, the receiver gets the packet and needs to read and remove the headers.
在另一端,接收方获取数据包,需要读取和删除标头。

* The second layer may also include a trailer – an additional chunk of bits following the data, with some information.
* 第二层也可包括一个“尾部” —— 一组附加在数据后面的比特块,包含一些信息。

Putting it All Together 把它们放在一起

Now that we have covered the five layers, let’s have one example using all of them together.
现在我们已经介绍了这五个层,让我们举一个例子来同时使用它们。

在这里插入图片描述

Let’s say we would like to send a video file to our friend who lives in France, while we are enjoying a trip in Argentina. For that, we are using an email service.
假设我们想向住在法国的朋友发送一个视频文件,而我们正在阿根廷旅行。为此,我们正在使用电子邮件服务。

The fifth layer defines how the email will be transmitted. For example, it includes the email address of the sender, as well as the receiver. It contains a title, and the body of the message. It requires that we follow a specific template of an email address, that will be included in the header of this layer.
第五层定义了电子邮件的传输方式。例如,它包括发件人和收件人的电子邮件地址。它包含标题和邮件正文。它要求我们遵循电子邮件地址的特定模板,该模板将包含在此图层的标题中。

image-63

The five layers model, with an example of sending an email

Then, the fifth layer uses the fourth layer in order to split the email into chunks. Of course, each chunk will also carry the fourth layer’s header. It is also used in order to specify that we are currently using an email service.
然后,第五层使用第四层将电子邮件拆分为块。当然,每个块也将携带第四层的标题。它还用于指定我们当前正在使用电子邮件服务。

In this case, we definitely want the connection to be reliable – so the receiver will be able to play our video file correctly. Thus, the fourth layer will also handle reliability. On the receiver’s end, it might send an acknowledgment packet for every packet it receives.
在这种情况下,我们绝对希望连接可靠——这样接收器才能正确播放我们的视频文件。因此,第四层也将处理可靠性。在接收方端,它可能会为接收的每个数据包发送一个确认数据包。

The third layer will define the best route for every packet to be sent. It might choose different routes for different packets. Among other things, its header will contain the source and destination addresses for the packet.
第三层将为要发送的每个数据包定义最佳路由。它可能会为不同的数据包选择不同的路由。除其他事项外,其标头将包含数据包的源地址和目标地址。

The second layer will be responsible for every link between two directly connected devices. Its header will include the MAC addresses for each device.
第二层将负责两个直接连接的设备之间的每个链接。其标头将包括每个设备的 MAC 地址。

The first layer is responsible for encoding all the ones and zeros, and to pass them over the line. And then, decoding and reading those ones and zeroes on the other end. On this layer, we don’t really have a header, as it consists of single bits only.
第一层负责对所有 1 和 0 进行编码,并将它们传递到行上。然后,解码并读取另一端的 1 和 0。在这个层上,我们实际上没有标头,因为它只由单个位组成。
在这里插入图片描述

Summary 总结

This way, every layer uses the services provided by the lower layers, and the huge problem of transmitting data over the network becomes doable. How amazing is that?
这样一来,每一层都使用下层提供的服务,通过网络传输数据的巨大问题就变得可行了。


via: Omer Rosenbaum OCTOBER, 2022

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值