Sub topic 10
Data Units and Devices at Each Layer
This chapter assumes you know the seven OSI layers by name, understand encapsulation, and can run simple terminal commands. Here you will connect each layer to its data unit (the name for the chunk of data at that layer) and to the devices that work at that layer.
Why the names matter
Each layer wraps the data it receives from above and gives the result a new name. That result is the protocol data unit, or PDU. Using the right name tells a colleague exactly where you are looking. "The frame is corrupt" points at Layer 2. "The segment is retransmitted" points at Layer 4.
The table to remember
| Layer | Name | PDU | Typical devices | Addressing |
|---|---|---|---|---|
| 7 | Application | Data (message) | Application gateways, proxies, load balancers (L7) | Hostnames, URLs |
| 6 | Presentation | Data | Usually software, not a device | None |
| 5 | Session | Data | Usually software, not a device | Session identifiers |
| 4 | Transport | Segment (TCP) or datagram (UDP) | Firewalls (stateful), L4 load balancers | Port numbers |
| 3 | Network | Packet | Routers, Layer 3 switches | IP addresses |
| 2 | Data Link | Frame | Switches, bridges, wireless access points, NICs | MAC addresses |
| 1 | Physical | Bits | Hubs, repeaters, cables, media converters | None |
Layers 5 to 7 all handle plain "data" in the OSI naming. In practice, people call the unit at these layers a message, a request, or just data.
How a unit changes as it moves down
Suppose a browser sends an HTTP request. The units change at each step:
- The application produces the request. This is data.
- TCP adds a header with source and destination ports. The result is a segment.
- IP adds a header with source and destination IP addresses. The result is a packet.
- Ethernet adds a header and a trailer with MAC addresses and a checksum. The result is a frame.
- The network card turns the frame into bits on the wire or radio waves.
The receiver reverses the steps. Each layer strips its own header and passes the contents upward.
Devices and the layer they inspect
A device is said to "work at" a layer when it reads headers up to that layer and makes decisions from them. It does not need to understand anything above it.
- Hub or repeater (Layer 1). It copies electrical signals to other ports. It does not read frames, so every connected device sees all traffic.
- Switch (Layer 2). It reads the destination MAC address in each frame. It keeps a table of which MAC address is on which port and forwards the frame only to that port.
- Router (Layer 3). It reads the destination IP address in each packet and picks the next hop from its routing table. It rewrites the Layer 2 header at every hop, but the IP addresses normally stay the same.
- Firewall (Layer 3 to 7). A basic packet filter checks IP addresses and ports. A stateful firewall also tracks TCP connections. An application firewall reads the content, such as HTTP paths.
import struct
# A frame's Layer 2 header changes at each router hop. The IP addresses inside do not.
def describe(frame_hex):
raw = bytes.fromhex(frame_hex)
dst, src, ethertype = struct.unpack("!6s6sH", raw[:14])
fmt = lambda b: ":".join(f"{x:02x}" for x in b)
return f"L2 dst={fmt(dst)} src={fmt(src)} type={ethertype:#06x}"
print(describe("aabbccddeeff" "001122334455" "0800"))
# L2 dst=aa:bb:cc:dd:ee:ff src=00:11:22:33:44:55 type=0x0800The EtherType 0x0800 says the payload is an IPv4 packet. That field is how Layer 2 tells the receiver which Layer 3 protocol to hand the data to.
Common mistakes
- Calling every unit a packet. In casual speech this is common, but in troubleshooting reports it hides which layer has the fault. A TCP retransmission is a segment problem. A bad checksum on the wire is a frame problem.
- Thinking a switch changes IP addresses. A switch only reads the Layer 2 header. Only a router (or a NAT device) changes Layer 3 information.
- Assuming MAC addresses travel end to end. They are valid only on one link. Across the internet, the MAC addresses are replaced at every router.
- Looking for a Layer 5 or 6 device. These functions, such as TLS and session handling, live in software on the endpoints.
Exercise
A packet travels from your laptop through two routers to a web server. Which of these change at each router: the source MAC address, the destination MAC address, the source IP address, the destination TCP port? Assume no NAT.
Show answer
The source MAC address and the destination MAC address change at each router, because each router builds a new frame for the next link. The source IP address and the destination TCP port stay the same, because Layer 3 and Layer 4 headers are not rewritten when a router simply forwards the packet.
Exercise
Name the PDU and a typical device for each of Layers 1, 2, 3, and 4.
Show answer
Layer 1: bits, hub or repeater. Layer 2: frame, switch. Layer 3: packet, router. Layer 4: segment (TCP) or datagram (UDP), stateful firewall or L4 load balancer.