Network models · Fundamentals · Module 2
Encapsulation and decapsulation
Show topologyHide topology
Four devices in a column, joined by three cables. At the top the host H1: its eth0, address ending .10, is cabled to the switch SW1’s Et0/1. SW1’s Et0/0 is cabled to the router R1’s Et0/0, address ending .1. Both of SW1’s cables are one network, 10.0.1.0/24, written on each of them; SW1 itself has no address. R1’s Et0/1, address ending .1, is cabled to the host H2 at the bottom, its eth0 ending .20, in the network 10.0.2.0/24, written on that cable. A legend explains the short forms.
What encapsulation is
The headers data gets on the way down
Three layers, three headers
R1 sends “hello from R1” down its layers to H2. What do they leave on it?
Three of them, the transport, network and data link layers, each put a header in front of what they got from above, so a TCP header and its data travel inside an IP packet (Figure 2.1). This is encapsulation. Your phone does the same with what it sends.
The unit one layer hands down is its PDU (protocol data unit), that layer’s header plus the data it carries. The whole PDU of one layer becomes the payload of the layer below.
The receiver undoes this from the bottom up. Each of the three reads its own header, removes it and passes the rest up. This is decapsulation. In the model, a header is meant only for the same layer on the other device.
Five rows from top to bottom, each a label over a strip of parts. The first row, “data”: one part, data. The second, “segment = TCP header + data”: TCP, then data. The third, “packet = IP header + segment”: IP, TCP, data. The fourth, “frame = Ethernet header + packet + trailer”: Ethernet, IP, TCP, data, trailer; the Ethernet part is drawn in the accent color. The last row, “bits: the frame, one bit at a time”, is one strip across the width that reads “one bit after another”. The data part stays in the same place in every row, and each new header appears to its left. Not to scale: real headers differ in size.
R1’s “hello from R1” leaves with three headers, not only the IP header.
The frame, the data link layer’s unit, holds the whole packet, because the data link layer works after the network layer (Figure 2.1).
One name per layer
Each layer’s PDU has its own name. Why not call them all packets?
A name tells you which header is the outermost, and so which layer you mean.
R1’s “hello from R1” becomes a segment once the transport layer puts a TCP header in front, and a packet, an IP header and data that standards also call an IP datagram, once the network layer puts an IP header in front of that.
The data link layer makes the packet into a frame, a link-layer header followed by the packet. On Ethernet it also adds a trailer behind the packet. The trailer holds the frame check sequence, a check value from the sender. The receiver calculates the value again from the frame it got and compares the two. R1 counts frames that fail this check: show interfaces Ethernet0/1 reads 0 CRC.
The physical layer sends the frame as bits on the cable, each bit a single binary digit. In the OSI model it adds no header of its own.
| Layer (OSI) | PDU | Its header holds | For R1’s text |
|---|---|---|---|
| 7 Application | data | — | — |
| 4 Transport | segment | the ports | to port 2001 on H2 |
| 3 Network | packet | the IP addresses | 10.0.2.1 to 10.0.2.20 |
| 2 Data link | frame | the two interfaces’ addresses | R1’s interface to H2’s |
| 1 Physical | bits | — | — |
How it works
R1 adds the headers, H2 removes them
R1 sends “hello from R1”
The IP header already names both ends. Why does the frame need addresses of its own?
The frame has to reach only the next device on the link, and for that the data link layer uses a MAC address. It names one interface within one network (devices with no router between them) and is 48 bits long. The Ethernet header carries a destination MAC address, a source MAC address and a type, which names what is inside.
Where does R1 get the two MAC addresses? Its own belongs to its interface. H2’s comes from a list R1 keeps, with its own addresses and its neighbors’. A protocol called ARP finds the neighbors’ MAC addresses behind their IP addresses.
You can watch R1 build the packet. With debug ip packet detail on, R1 prints lines for each packet it sends or receives itself. For a TCP packet it prints the IP header’s line first and the TCP header’s line under it, indented, though the TCP header was added first. It prints no line for the Ethernet header. On a busy router this debug can load the processor, so keep it short and switch it off with undebug all.
Step 1 of 8
R1’s telnet program hands the data, “hello from R1”, down to the transport layer.
Step 2 of 8
The transport layer puts a TCP header in front, to port 2001: now it is a segment.
Step 3 of 8
The network layer adds an IP header, 10.0.2.1 to 10.0.2.20, and picks the way out, the interface it leaves by, Ethernet0/1: now it is a packet.
Step 4 of 8
The data link layer adds an Ethernet header, R1’s MAC address to H2’s, and a trailer: now it is a frame.
Step 5 of 8
The physical layer sends the frame out of Ethernet0/1 as bits, onto the cable to H2.
The bits reach H2. Which header does H2 read first?
- The Ethernet header, the outermost part. (Correct): Decapsulation starts at the bottom: the physical layer hands the bits up, and the data link layer is the first to read a header. It reads only its own, the one in front of everything else.
- The TCP header, to find the program first.: The TCP header is deep inside the frame; its turn comes after the two layers below it.
- The IP header, to check the address first.: The IP header lies inside the frame and is read only after the data link layer has removed the frame header.
- All three headers at once.: The layers work one after the other, from the bottom, not all at once.
Step 6 of 8
H2’s data link layer: the frame is for its MAC address. It checks the trailer, removes the header and the trailer, and passes the packet up.
Step 7 of 8
H2’s network layer: 10.0.2.20 is its own address. It removes the IP header and passes the segment up.
Step 8 of 8
H2’s transport layer: port 2001 belongs to a program of its own. It removes the TCP header; the program gets “hello from R1”.
Two columns of layers: R1 on the left, H2 on the right, each with Application, Transport, Network, Data link and Physical from top to bottom, joined by a cable between the two physical layers. Under them, a strip labeled “the PDU:” shows the PDU as it is now, apart from both columns. At each step the layer at work is drawn in the accent color, and the layers the PDU has already passed are dimmed; the device names and the layers still ahead stay at full strength. At the first step R1’s Application layer is at work and the strip holds only “data”. In the next three steps arrows go down R1’s column to Transport, Network and Data link, and the strip gains a TCP part, then an IP part, then an Ethernet part in front and a trailer behind. Then R1’s Physical layer sends the frame on as bits: an arrow labeled “bits” beside the cable points to H2. In the last three steps arrows go up H2’s column to Data link, Network and Transport, and the strip loses the Ethernet part and the trailer, then the IP part, then the TCP part, until only “data” is left for the program.
telnet program hands the data, “hello from R1”, down to the transport layer.Debug line at this step TCP src=44091, dst=2001, seq=1635525117, ack=1936174744, win=32764 ACK PSHThe transport layer puts a TCP header in front, to port 2001: now it is a segment.Debug line at this stepIP: s=10.0.2.1 (local), d=10.0.2.20 (Ethernet0/1), len 55, sendingThe network layer adds an IP header, 10.0.2.1 to 10.0.2.20, and picks the way out, the interface it leaves by, Ethernet0/1: now it is a packet.The data link layer adds an Ethernet header, R1’s MAC address to H2’s, and a trailer: now it is a frame.Debug line at this stepIP: s=10.0.2.1 (local), d=10.0.2.20 (Ethernet0/1), len 55, sending full packetThe physical layer sends the frame out of Ethernet0/1 as bits, onto the cable to H2.H2’s data link layer: the frame is for its MAC address. It checks the trailer, removes the header and the trailer, and passes the packet up.H2’s network layer: 10.0.2.20 is its own address. It removes the IP header and passes the segment up.H2’s transport layer: port 2001 belongs to a program of its own. It removes the TCP header; the program gets “hello from R1”.Answer here to see step 6, or tap “Skip, show me”.
Three of R1’s lines for the one packet that carries “hello from R1”. The number beside each line is the step it belongs to:
Lines appear as you step through.
R1#show logging… 85 more lines (see Full output)3IP: s=10.0.2.1 (local), d=10.0.2.20 (Ethernet0/1), len 55, sending2 TCP src=44091, dst=2001, seq=1635525117, ack=1936174744, win=32764 ACK PSH5IP: s=10.0.2.1 (local), d=10.0.2.20 (Ethernet0/1), len 55, sending full packet… 51 more lines (see Full output)
Full output · 139 lines
R1#show loggingSyslog logging: enabled (0 messages dropped, 2 messages rate-limited, 0 flushes, 0 overruns, xml disabled, filtering disabled) No Active Message Discriminator. No Inactive Message Discriminator. Console logging: disabled Monitor logging: level debugging, 0 messages logged, xml disabled, filtering disabled Buffer logging: level debugging, 563 messages logged, xml disabled, filtering disabled Exception Logging: size (4096 bytes) Count and timestamp logging messages: disabled Persistent logging: disabled Trap logging: level informational, 65 message lines logged Logging Source-Interface: VRF Name: Log Buffer (128000 bytes): Nov 25 21:12:20.680: %SYS-4-LOG_CLEARED: Logging buffer was cleared by user UnknownFIBipv4-packet-proc: route packet from (local) src 10.0.2.1 dst 10.0.2.20FIBfwd-proc: packet routed by adj to Ethernet0/1 10.0.2.20FIBipv4-packet-proc: packet routing succeededIP: tableid=0, s=10.0.2.1 (local), d=10.0.2.20 (Ethernet0/1) nexthop=10.0.2.20, routed via FIBIP: s=10.0.2.1 (local), d=10.0.2.20 (Ethernet0/1), len 52, sending TCP src=44091, dst=2001, seq=1635525116, ack=0, win=65535 SYNIP: s=10.0.2.1 (local), d=10.0.2.20 (Ethernet0/1), len 52, sending full packet TCP src=44091, dst=2001, seq=1635525116, ack=0, win=65535 SYNIP: s=10.0.2.20 (Ethernet0/1), d=10.0.2.1 (nil), len 52, input feature TCP src=2001, dst=44091, seq=1936174729, ack=1635525117, win=64240 ACK SYN, MCI Check(110), rtype 0, forus FALSE, sendself FALSE, mtu 0, fwdchk FALSEFIBipv4-packet-proc: route packet from Ethernet0/1 src 10.0.2.20 dst 10.0.2.1FIBfwd-proc: Default:10.0.2.1/32 receive entryFIBipv4-packet-proc: packet routing failedIP: s=10.0.2.20 (Ethernet0/1), d=10.0.2.1 (nil), len 52, rcvd 2 TCP src=2001, dst=44091, seq=1936174729, ack=1635525117, win=64240 ACK SYNIP: s=10.0.2.20 (Ethernet0/1), d=10.0.2.1 (nil), len 52, stop process pak for forus packet TCP src=2001, dst=44091, seq=1936174729, ack=1635525117, win=64240 ACK SYNFIBipv4-packet-proc: route packet from Ethernet0/1 src 10.0.2.20 dst 10.0.2.1FIBfwd-proc: Default:10.0.2.1/32 receive entryFIBipv4-packet-proc: packet routing failedIP: tableid=0, s=10.0.2.20 (Ethernet0/1), d=10.0.2.1 (Ethernet0/1) nexthop=10.0.2.1, routed via RIBFIBipv4-packet-proc: route packet from (local) src 10.0.2.1 dst 10.0.2.20FIBfwd-proc: packet routed by adj to Ethernet0/1 10.0.2.20FIBipv4-packet-proc: packet routing succeededIP: tableid=0, s=10.0.2.1 (local), d=10.0.2.20 (Ethernet0/1) nexthop=10.0.2.20, routed via FIBIP: s=10.0.2.1 (local), d=10.0.2.20 (Ethernet0/1), len 40, sending TCP src=44091, dst=2001, seq=1635525117, ack=1936174730, win=32768 ACKIP: s=10.0.2.1 (local), d=10.0.2.20 (Ethernet0/1), len 40, sending full packet TCP src=44091, dst=2001, seq=1635525117, ack=1936174730, win=32768 ACKFIBipv4-packet-proc: route packet from (local) src 10.0.2.1 dst 10.0.2.20FIBfwd-proc: packet routed by adj to Ethernet0/1 10.0.2.20FIBipv4-packet-proc: packet routing succeededIP: tableid=0, s=10.0.2.1 (local), d=10.0.2.20 (Ethernet0/1) nexthop=10.0.2.20, routed via FIBIP: s=10.0.2.1 (local), d=10.0.2.20 (Ethernet0/1), len 40, sending TCP src=44091, dst=2001, seq=1635525117, ack=1936174730, win=32768 ACKIP: s=10.0.2.1 (local), d=10.0.2.20 (Ethernet0/1), len 40, sending full packet TCP src=44091, dst=2001, seq=1635525117, ack=1936174730, win=32768 ACKIP: s=10.0.2.20 (Ethernet0/1), d=10.0.2.1 (nil), len 54, input feature TCP src=2001, dst=44091, seq=1936174730, ack=1635525117, win=502 ACK PSH, MCI Check(110), rtype 0, forus FALSE, sendself FALSE, mtu 0, fwdchk FALSEFIBipv4-packet-proc: route packet from Ethernet0/1 src 10.0.2.20 dst 10.0.2.1FIBfwd-proc: Default:10.0.2.1/32 receive entryFIBipv4-packet-proc: packet routing failedIP: s=10.0.2.20 (Ethernet0/1), d=10.0.2.1 (nil), len 54, rcvd 2 TCP src=2001, dst=44091, seq=1936174730, ack=1635525117, win=502 ACK PSHIP: s=10.0.2.20 (Ethernet0/1), d=10.0.2.1 (nil), len 54, stop process pak for forus packet TCP src=2001, dst=44091, seq=1936174730, ack=1635525117, win=502 ACK PSHFIBipv4-packet-proc: route packet from Ethernet0/1 src 10.0.2.20 dst 10.0.2.1FIBfwd-proc: Default:10.0.2.1/32 receive entryFIBipv4-packet-proc: packet routing failedIP: tableid=0, s=10.0.2.20 (Ethernet0/1), d=10.0.2.1 (Ethernet0/1) nexthop=10.0.2.1, routed via RIBFIBipv4-packet-proc: route packet from (local) src 10.0.2.1 dst 10.0.2.20FIBfwd-proc: packet routed by adj to Ethernet0/1 10.0.2.20FIBipv4-packet-proc: packet routing succeededIP: tableid=0, s=10.0.2.1 (local), d=10.0.2.20 (Ethernet0/1) nexthop=10.0.2.20, routed via FIBIP: s=10.0.2.1 (local), d=10.0.2.20 (Ethernet0/1), len 40, sending TCP src=44091, dst=2001, seq=1635525117, ack=1936174744, win=32764 ACKIP: s=10.0.2.1 (local), d=10.0.2.20 (Ethernet0/1), len 40, sending full packet TCP src=44091, dst=2001, seq=1635525117, ack=1936174744, win=32764 ACKFIBipv4-packet-proc: route packet from (local) src 10.0.2.1 dst 10.0.2.20FIBfwd-proc: packet routed by adj to Ethernet0/1 10.0.2.20FIBipv4-packet-proc: packet routing succeededIP: tableid=0, s=10.0.2.1 (local), d=10.0.2.20 (Ethernet0/1) nexthop=10.0.2.20, routed via FIBIP: s=10.0.2.1 (local), d=10.0.2.20 (Ethernet0/1), len 55, sending TCP src=44091, dst=2001, seq=1635525117, ack=1936174744, win=32764 ACK PSHIP: s=10.0.2.1 (local), d=10.0.2.20 (Ethernet0/1), len 55, sending full packet TCP src=44091, dst=2001, seq=1635525117, ack=1936174744, win=32764 ACK PSHIP: s=10.0.2.20 (Ethernet0/1), d=10.0.2.1 (nil), len 40, input feature TCP src=2001, dst=44091, seq=1936174744, ack=1635525132, win=502 ACK, MCI Check(110), rtype 0, forus FALSE, sendself FALSE, mtu 0, fwdchk FALSEFIBipv4-packet-proc: route packet from Ethernet0/1 src 10.0.2.20 dst 10.0.2.1FIBfwd-proc: Default:10.0.2.1/32 receive entryFIBipv4-packet-proc: packet routing failedIP: s=10.0.2.20 (Ethernet0/1), d=10.0.2.1 (nil), len 40, rcvd 2 TCP src=2001, dst=44091, seq=1936174744, ack=1635525132, win=502 ACKIP: s=10.0.2.20 (Ethernet0/1), d=10.0.2.1 (nil), len 40, stop process pak for forus packet TCP src=2001, dst=44091, seq=1936174744, ack=1635525132, win=502 ACKFIBipv4-packet-proc: route packet from Ethernet0/1 src 10.0.2.20 dst 10.0.2.1FIBfwd-proc: Default:10.0.2.1/32 receive entryFIBipv4-packet-proc: packet routing failedIP: tableid=0, s=10.0.2.20 (Ethernet0/1), d=10.0.2.1 (Ethernet0/1) nexthop=10.0.2.1, routed via RIBFIBipv4-packet-proc: route packet from (local) src 10.0.2.1 dst 10.0.2.20FIBfwd-proc: packet routed by adj to Ethernet0/1 10.0.2.20FIBipv4-packet-proc: packet routing succeededIP: tableid=0, s=10.0.2.1 (local), d=10.0.2.20 (Ethernet0/1) nexthop=10.0.2.20, routed via FIBIP: s=10.0.2.1 (local), d=10.0.2.20 (Ethernet0/1), len 40, sending TCP src=44091, dst=2001, seq=1635525132, ack=1936174744, win=32768 ACKIP: s=10.0.2.1 (local), d=10.0.2.20 (Ethernet0/1), len 40, sending full packet TCP src=44091, dst=2001, seq=1635525132, ack=1936174744, win=32768 ACKFIBipv4-packet-proc: route packet from (local) src 10.0.2.1 dst 10.0.2.20FIBfwd-proc: packet routed by adj to Ethernet0/1 10.0.2.20FIBipv4-packet-proc: packet routing succeededIP: tableid=0, s=10.0.2.1 (local), d=10.0.2.20 (Ethernet0/1) nexthop=10.0.2.20, routed via FIBIP: s=10.0.2.1 (local), d=10.0.2.20 (Ethernet0/1), len 40, sending TCP src=44091, dst=2001, seq=1635525132, ack=1936174744, win=32768 ACK PSH FINIP: s=10.0.2.1 (local), d=10.0.2.20 (Ethernet0/1), len 40, sending full packet TCP src=44091, dst=2001, seq=1635525132, ack=1936174744, win=32768 ACK PSH FINIP: s=10.0.2.20 (Ethernet0/1), d=10.0.2.1 (nil), len 40, input feature TCP src=2001, dst=44091, seq=1936174744, ack=1635525133, win=502 ACK FIN, MCI Check(110), rtype 0, forus FALSE, sendself FALSE, mtu 0, fwdchk FALSEFIBipv4-packet-proc: route packet from Ethernet0/1 src 10.0.2.20 dst 10.0.2.1FIBfwd-proc: Default:10.0.2.1/32 receive entryFIBipv4-packet-proc: packet routing failedIP: s=10.0.2.20 (Ethernet0/1), d=10.0.2.1 (nil), len 40, rcvd 2 TCP src=2001, dst=44091, seq=1936174744, ack=1635525133, win=502 ACK FINIP: s=10.0.2.20 (Ethernet0/1), d=10.0.2.1 (nil), len 40, stop process pak for forus packet TCP src=2001, dst=44091, seq=1936174744, ack=1635525133, win=502 ACK FINFIBipv4-packet-proc: route packet from Ethernet0/1 src 10.0.2.20 dst 10.0.2.1FIBfwd-proc: Default:10.0.2.1/32 receive entryFIBipv4-packet-proc: packet routing failedIP: tableid=0, s=10.0.2.20 (Ethernet0/1), d=10.0.2.1 (Ethernet0/1) nexthop=10.0.2.1, routed via RIBFIBipv4-packet-proc: route packet from (local) src 10.0.2.1 dst 10.0.2.20FIBfwd-proc: packet routed by adj to Ethernet0/1 10.0.2.20FIBipv4-packet-proc: packet routing succeededIP: tableid=0, s=10.0.2.1 (local), d=10.0.2.20 (Ethernet0/1) nexthop=10.0.2.20, routed via FIBIP: s=10.0.2.1 (local), d=10.0.2.20 (Ethernet0/1), len 40, sending TCP src=44091, dst=2001, seq=1635525133, ack=1936174745, win=32768 ACKIP: s=10.0.2.1 (local), d=10.0.2.20 (Ethernet0/1), len 40, sending full packet TCP src=44091, dst=2001, seq=1635525133, ack=1936174745, win=32768 ACK
The step 5 line, sending full packet, is the line R1 prints for a packet that went out. seq, ack and win are TCP header fields, and len an IP header field.
R1’s address list is its ARP table, and show arp prints it:
- R1’s own row, Age
-and Hardware Addr aabb.cc00.0910. - 10.0.2.20 on Ethernet0/1: Hardware Addr 5254.0000.0220, the frame’s destination.
Full output · 5 lines
R1#show arpProtocol Address Age (min) Hardware Addr Type InterfaceInternet 10.0.1.1 - aabb.cc00.0900 ARPA Ethernet0/0Internet 10.0.1.10 4 5254.0000.0110 ARPA Ethernet0/0Internet 10.0.2.1 - aabb.cc00.0910 ARPA Ethernet0/1Internet 10.0.2.20 0 5254.0000.0220 ARPA Ethernet0/1
Scroll sideways to see the whole output
show interfaces Ethernet0/1 | include address|Encapsulation|MTU prints R1’s own MAC address on the Hardware line, after the hardware type:
R1#show interfaces Ethernet0/1 | include address|Encapsulation|MTU1 Hardware is AmdP2, address is aabb.cc00.0910 (bia aabb.cc00.0910)… 2 more lines (see Full output)2 Encapsulation ARPA, loopback not set
address isaabb.cc00.0910: the source of the frame header.Encapsulation ARPA: the way this interface puts packets into frames. ARPA is the standard encapsulation of an Ethernet interface, the default setting, the same word as in the Type column ofshow arp.
Full output · 4 lines
R1#show interfaces Ethernet0/1 | include address|Encapsulation|MTU Hardware is AmdP2, address is aabb.cc00.0910 (bia aabb.cc00.0910) Internet address is 10.0.2.1/24 MTU 1500 bytes, BW 10000 Kbit/sec, DLY 1000 usec, Encapsulation ARPA, loopback not set
Use the rule: going down, each layer hands its whole PDU to the layer below.
How H2 finds which part gets the rest
At each step up, H2 removes a header. Which field tells it which layer, and which program, gets what is left?
These three headers each have a field that names what is inside. The layer that removes a header reads that field and passes the rest to the one it names.
In the frame header it is the type: type 0800 means an IPv4 packet is inside. In the IP header it is the protocol field, which names the protocol of the data inside; number 6 is TCP. In the TCP header it is the destination port, which names the program (Figure 2.3).
Four parts in a column, from the outside in: Ethernet header, IP header, TCP header and the program. Beside each, the part of H2 that reads it: the data link layer, the network layer, the transport layer, and for the program, port 2001. An arrow goes from each part to the next, labeled with the field that points there. From the Ethernet header, “type 0800: IPv4 inside”, the packet goes up to the network layer; from the IP header, “protocol 6: TCP inside”, the segment goes up to the transport layer; from the TCP header, “destination port 2001”, the data goes to the program waiting on that port.
Reading the port at once might look quicker. In the model, though, a layer does not read the part it carries for the layer above. H2’s network layer reads the IP header, whose protocol field names TCP, and leaves the port to the transport layer.