Encapsulation and decapsulation basics for OSI layer

layer1layer2layer3layer4osi

I have read that encapsulation takes place down the layers while decapsulation takes place up the layers. In essence, the encapsulation starts at Application layer all the way upto Physical layer.
Assume we have a sender A and receiver B.Sender A wants to http to a server B.
So for the encapsulation down the layers on A side we would have,

Application(http)-Presentation-Session-Transport(TCP port 80)-Network(IP address of A)-Data link(Mac)-Physical(Bits 0 and 1).

From above, we can say that PDU(Protocol data unit) of upper layer(say Network Layer) becomes the data of the lower layer(say Data link layer).

Essentially,(Data+control Info )of Network layer =( Data ) of data link layer

Now coming to the receiver side B(decapsulation process)
Step 1: The Physical layer header is stripped off

Step 2: The data link layer header is stripped off

Step 3: The network layer header is stripped off and so on

Q1: is the above understanding correct?

Q2: I am getting confused as to why data link layer info is stripped off first? I mean, when we do ARP, we first look at IP address(layer 3) and request for mac address(layer 2 info).

I understand that there is a value called Ethertype, that tells what upper layer protocol is being used(e.g mpls or IPv4 or IPv6) ?

Best Answer

You seem to have the general idea.

First, there really is no Physical Layer header. The Physical Layer simply takes what the Data-Link Layer gives it, and it encodes the Data-Link frame (encoding) for the interface and places that on the "wire" (signalling), or it performs the opposite when receiving data.

When layer-3 sends a packet to layer-2, layer-2 needs to encapsulate that with a layer-2 header. Part of the layer-2 header may include a MAC address for layer-2 protocols that use MAC addresses (not all do, and of those that do, some use 48-bit MAC addresses, and some use 64-bit MAC addresses).

In order to put a destination MAC address in the layer-2 frame, the destination layer-3 address must be resolved to a layer-2 address. Layer-2 needs the destination layer-2 MAC address in order to build the layer-2 frame to encapsulate the layer-3 packet. That is where ARP (Address Resolution Protocol) comes in.

ARP has to do with data leaving the host, not coming into the host where the headers are stripped. Depending on the network stack implementation, as a layer-2 frame come into a host, the MAC address may get saved in the host's ARP cache as the frame is stripped from the packet. Layer-2 will inspect the layer-2 frame to determine to which layer-3 protocol in the network stack the frame payload (layer-3 packet) should be sent.

The Ethertype field is a field in ethernet frame headers. Other layer-2 protocols have other ways of doing this. Remember, ethernet may be the most used layer-2 protocol, but it is not the only layer-2 protocol, and each have their own frame headers. Layer-3 protocols can have the the same type of thing. For instance, IPv4 has the Protocol field, and IPv6 has the Next Header field, to tell layer-3 to which layer-4 protocol the payload of the layer-3 packet should be sent.