Sub topic 1
Why Networks Are Modeled in Layers
Prerequisites
You should know what a computer network, an IP address, a web server, and a router are. You should also be comfortable running simple terminal commands.
Why Networks Are Modeled in Layers
A network is easier to design and troubleshoot when its work is divided into layers. Each layer has a focused responsibility and provides a service to the layer above it. A change in one layer, such as replacing copper cable with fiber, does not require rewriting application software.
The Open Systems Interconnection (OSI) model is a seven-layer reference model:
| Layer | Main responsibility |
|---|---|
| 1. Physical | Sends raw bits across a medium |
| 2. Data Link | Delivers frames across one local network |
| 3. Network | Routes packets between networks |
| 4. Transport | Provides host-to-host delivery |
| 5–7 | Manages sessions, data format, and applications |
The OSI model is a way to reason about networking. Real protocols do not always fit one layer perfectly.
How Data Is Wrapped and Unwrapped
When an application sends data, the data moves down the stack. Each layer adds control information in a process called encapsulation. For example, Layer 4 may add TCP information, Layer 3 adds an IP header, and Layer 2 adds an Ethernet header and trailer.
At the receiving computer, the process reverses. Each layer removes and interprets its own information. This is decapsulation.
Layer 1: Physical, Bits on the Medium
The physical layer sends bits, which are zeros and ones, as signals. The medium can be copper wire, fiber-optic cable, or radio. Connectors, electrical levels, light pulses, radio frequencies, and transmission speed belong here.
A damaged cable or disabled network interface can prevent communication before any address or protocol is involved.
Layer 2: Data Link, Frames and MAC Addresses
The data link layer moves data across one local network. Its protocol data unit is a frame. On Ethernet, a frame includes a source and destination MAC address. A MAC address identifies a network interface on the local link. An EtherType field identifies the protocol carried inside, such as ARP or IPv4.
import struct
header = bytes.fromhex("ffffffffffff0011223344550806")
dst, src, ethertype = struct.unpack("!6s6sH", header)
print(":".join(f"{b:02x}" for b in dst))
print(":".join(f"{b:02x}" for b in src))
print(hex(ethertype))Switches primarily forward frames using MAC addresses. Routers operate at Layer 3 to move packets between different networks.
Exercise
A host has a working link light but cannot reach a device on the same LAN. Which layer should you check next, and why?
Show answer
Check Layer 2. Inspect the interface's MAC address, switch connection, VLAN, and local frame delivery before investigating routing.