When we look at data in a network we can look ‘horizontally’ at a single layer in the network stack or ‘vertically’ as data moves up and down the stack between adjacent layers.
Same layer interaction is when we look at communication between two devices using a single protocol at a single layer. It allows us to abstract away higher and lower layers to focus on the services provided by the given layer.
For example, we might look at same-layer interaction between a web browser and a web server at the application layer, ignoring how the lower layers are transporting the data. Another example is looking at the route an IP packet takes across a network – addresses and routing – without needing to know what physical media is used or what application layer protocol is being transported.
On a given network device, it will likely provide some form of network stack. On a switch, this could just support the Link Layer, whereas on a router it could be the Link Layer and the Internet Layer. A computer supports all layers of the TCP/IP network stack. Each layer provides a service to the layer above it. Adjacent-layer interaction is the service provided from one layer to the layer above and the passing of data between these layers in the network stack. It allows us to abstract away different parts of the network so that someone writing an application doesn't have to reimplement the low-level networking technology every time.
For example at the transport layer, TCP provides data sequencing to the layer above. Data received by the transport layer can then be passed to the application layer program without that program having to worry about the order in which the data was received.
When sending an email, you might use SMTP (Simple Mail Transfer Protocol) which enables a sender to communicate with a receiver using a command/reply sequence.
SMTP is an application layer protocol which relies on TCP at the adjacent layer below (the transport layer) to ensure that the email data is sent and then received, error-free, and in the correct order by the recipient.
This provides a useful level of abstraction so that SMTP can focus on the email commands and not have to worry about lower-level details like error checking or sequence numbers.
As data is passed to a lower adjacent layer, that layer will add a header (and possibly also a trailer) before passing it to the layer below. This process of wrapping up higher layer data in a header and/or trailer is called encapsulation. The higher-layer data being encapsulated is often referred to as the payload or 'client data'.
When the data is passed back up the stack, each layer pops off its respective header/trailer – this is called decapsulation or de-encapsulation.
At each layer, we refer to the combination of header/trailer and the data being encapsulated as a Protocol Data Unit (PDU).
In TCP/IP, each layer has specific terminology for a PDU:
Transport Layer: Segment
Internet Layer: Packet
Link Layer: Frame
When sending an email with SMTP, the data goes through a process of encapsulation and de-encapsulation.
The SMTP data will be encapsulated in a TCP segment which will add a header with some extra information for sequencing and error checking (amongst other things).
The data provided by the transport layer (the full TCP segment) has an IP header added as it is encapsulated in an IP packet. This adds information like the source and destination IP addresses.
The IP packet is encapsulated by an Ethernet header and trailer to become a frame.
When the frame reaches its final destination, the process is reversed:
The computer de-encapsulates the IP packet from the frame.
It checks the destination IP address belongs to this computer and then de-encapsulates the data in the IP packet and passes it up to the transport layer.
The transport layer de-encapsulates the SMTP data from the TCP segment.
The application layer receives the SMTP data and presents it to the user as an email.