Information that is transmitted over a network must undergo a process of conversion at the sending and receiving ends of the communication. The conversion process is known as encapsulation and de-encapsulation of data. Both processes provide means for implementation of the concept of horizontal communication where the layer on the transmitting side is communicating with the corresponding layer on the receiving side.
透過網路傳送的資訊,必須在通訊的發送端與接收端經過一道轉換程序。這個轉換程序稱為資料的封裝與解封裝。這兩個程序提供了實現水平通訊概念的方法,也就是發送端的某一層與接收端的對應層進行通訊。
Have you ever opened a very large present and found a smaller box inside? And then an even smaller box inside that one, until you got to the smallest box and, finally, to your present? The process of encapsulation operates similarly in the TCP/IP model. The application layer receives the user data and adds to it its information in the form of a header. It then sends it to the transport layer. This process corresponds to putting a present (user data) into the first box (a header), and adding some information on the box (application layer data). The transport layer also adds its own header before sending the package to the internet layer, placing the first box into the second box and writing some transport-related information on it. This second box must be larger than the first one to fit the content. This process continues at each layer. The link layer adds a trailer in addition to the header. The data is then sent across the physical media.
你是否曾經打開一個很大的禮物盒,發現裡面還有一個較小的盒子?然後那個盒子裡又有一個更小的盒子,直到打開最小的盒子,才終於拿到禮物?在 TCP/IP 模型中,封裝的過程也是類似的。應用層接收使用者資料,並以標頭的形式加入自己的資訊,然後送到傳輸層。這個過程相當於把禮物(使用者資料)放進第一個盒子(標頭),並在盒子上寫一些資訊(應用層資料)。傳輸層在把包裹送往網際網路層之前,也會加入自己的標頭,也就是把第一個盒子放進第二個盒子,並在上面寫一些與傳輸有關的資訊。第二個盒子必須比第一個大,才裝得下內容。這個過程在每一層持續進行。鏈結層除了標頭之外,還會加上尾端。最後,資料經由實體媒介傳送出去。
The figure represents the encapsulation process. It shows how data passes through the layers down the stack. The data is encapsulated as follows:
圖中呈現封裝的過程,顯示資料如何沿堆疊向下通過各層。資料的封裝方式如下:
- The user data is sent from a user application to the application layer, where the application layer protocol adds its header. The PDU is now called data.使用者資料從使用者應用程式送到應用層,由應用層協定加入其標頭。此時 PDU 稱為資料。
- The transport layer adds the transport layer header to the data. This header includes its own information, indicating which application layer protocol has sent the data. The new data unit is now called a segment. The segment will be further treated by the Internet layer, which is the next to process it.傳輸層在資料前加入傳輸層標頭。這個標頭包含傳輸層自己的資訊,用來指出是哪一個應用層協定送出這些資料。新的資料單元現在稱為區段。區段接著由網際網路層處理,它是下一個處理者。
- The Internet layer encapsulates the received segment and adds its own header to the data. The header and the previous data become a packet. The Internet layer adds the information used to send the encapsulated data from the source of the message across one or more networks to the final destination. The packet is then passed down to the Link layer.網際網路層封裝收到的區段,並在資料前加入自己的標頭。這個標頭與先前的資料合起來就成為封包。網際網路層加入的資訊,用來將封裝後的資料從訊息來源跨越一個或多個網路送到最終目的地。封包接著往下交給鏈結層。
- The link layer adds its own header and also a trailer to form a frame. The trailer is usually a data-dependent sequence, which is used to check for transmission errors. An example of such a sequence is a Frame Check Sequence (FCS.) The receiver will use it to detect errors. This layer also converts the frame to a physical signal and sends it across the network using physical media.鏈結層加入自己的標頭以及尾端,形成框架。尾端通常是一段依資料內容計算出的序列,用來檢查傳輸錯誤,例如框架檢查序列(Frame Check Sequence,FCS)。接收端會用它來偵測錯誤。這一層也會將框架轉換成實體訊號,並透過實體媒介送到網路上。
At the destination, each layer looks at the information in the header added by its counterpart layer at the source. Based on this information, each layer performs its functions and removes the header before passing it up the stack. This process is equivalent to unpacking a box. In networking, this process is called de-encapsulation.
在目的端,每一層會查看來源端對應層所加入的標頭資訊。每一層根據這些資訊執行自己的功能,並在往上傳遞之前移除該標頭。這個過程就像拆開盒子一樣。在網路領域中,這個過程稱為解封裝。
The de-encapsulation process is like reading the address on a package to see if it is addressed to you and then, if you are the recipient, opening the package and removing the contents of the package.
解封裝的過程就像先閱讀包裹上的地址,確認是否是寄給你的;如果你是收件人,就打開包裹並取出裡面的內容。
The following is an example of how the destination device de-encapsulates a sequence of bits:
以下是目的裝置如何解封裝一連串位元的範例:
- The link layer reads the whole frame and looks at both the frame header and the trailer to check if the data has any errors. Typically, if an error is detected, the frame is discarded, and other layers may ask for the data to be retransmitted. If the data has no errors, the link layer reads and interprets the information in the frame header. The frame header contains information relevant for further processing, such as the type of encapsulated protocol. If the frame header information indicates that the frame should be passed to upper layers, the link layer strips the frame header and trailer and then passes the remaining data up to the Internet layer to the appropriate protocol.鏈結層讀取整個框架,並檢查框架標頭與尾端,以確認資料是否有錯誤。通常,若偵測到錯誤,框架會被丟棄,其他層可能會要求重新傳送資料。若資料沒有錯誤,鏈結層便讀取並解讀框架標頭中的資訊。框架標頭包含後續處理所需的資訊,例如所封裝的協定類型。若框架標頭資訊指出該框架應交給上層,鏈結層就會移除框架標頭與尾端,再將剩下的資料往上交給網際網路層中適當的協定。
- The internet layer examines the internet header in the packet received from the link layer. Based on the information it finds in the header, it decides either to process the packet at the same layer or to pass it up to the transport layer. Before the internet layer passes the message to the appropriate protocol on the transport layer, it first removes the packet header.網際網路層檢查從鏈結層收到的封包中的網際網路標頭。根據標頭中的資訊,它決定在同一層處理該封包,或是往上交給傳輸層。在網際網路層把訊息交給傳輸層中適當的協定之前,會先移除封包標頭。
- The transport layer examines the segment header of the received segment. The information included in the segment header indicates which application layer protocol should receive the data. The transport layer strips the segment header from the segment and hands over data to the appropriate application layer protocol.傳輸層檢查所收到區段的區段標頭。區段標頭中的資訊指出應由哪一個應用層協定接收這些資料。傳輸層從區段中移除區段標頭,並將資料交給適當的應用層協定。
- The application layer protocol strips the data header. It uses the information in the header to process the data before passing it to the user application.應用層協定移除資料標頭,並利用標頭中的資訊處理資料,然後再交給使用者應用程式。
Not all devices process PDUs at all layers. For instance, a switch might only process a PDU at the link layer, meaning that it will "read" only frame information that is contained in the frame header and trailer. Based on the information found in the frame header and trailer, the switch will either forward the frame unchanged out of a specific port, forward it out all ports except for the incoming port, or discard the frame if it detects errors. Routers might look "deeper" into the PDU. A router de-encapsulates the frame header and trailer and relies on the information contained in the packet header to make their forwarding decisions. If the router is filtering the packets, it may also look even deeper, into the information contained in the segment header before it decides on what to do with the packet.
並非所有裝置都會在每一層處理 PDU。例如,交換器可能只在鏈結層處理 PDU,也就是說它只會「讀取」框架標頭與尾端中所包含的框架資訊。根據框架標頭與尾端中的資訊,交換器會將框架原封不動地從特定連接埠轉送出去、從除了進入埠以外的所有連接埠轉送出去,或在偵測到錯誤時丟棄該框架。路由器則可能「更深入」地查看 PDU。路由器會解封裝框架標頭與尾端,並依據封包標頭中的資訊做出轉送決策。若路由器正在過濾封包,它可能會看得更深,在決定如何處理該封包之前先檢查區段標頭中的資訊。
A host performs encapsulation as it sends data and performs de-encapsulation as it receives it; it can perform both functions simultaneously as part of multiple communications it maintains.
主機在送出資料時執行封裝,在接收資料時執行解封裝;由於主機同時維持多個通訊,它可以同時執行這兩種功能。

