Layers
Sending a message across a network is split into layers, and each layer has one job. On the way out, each layer wraps the message in a small label of its own. On the way in, each layer reads its label and hands what is inside to the next layer up.
Five layers, five jobs
| Layer | Its job | What it uses | Where you met it |
|---|---|---|---|
| 1 Physical | Carry bits as signals | Cables, light, radio waves | What is a network? |
| 2 Link | Reach the next device on the same local network | Frames, hardware addresses, switches, Ethernet, ARP | Switches |
| 3 Network | Reach a device on any network, one hop at a time | Packets, IP addresses, routers, ICMP | Routers and the gateway |
| 4 Transport | Reach the right program, and with TCP, check every piece arrived | Ports, TCP, and UDP | Ports and protocols |
| 5 Application | Say what the program wants | Web pages, DNS questions | DNS |
Each layer uses only the layer under it, and does not care how that layer works. A web browser does not know if the page came over a cable or over Wi-Fi. A switch does not know if a frame holds a web page or a DNS question. So you can change one layer without touching the others, and you can look for a problem one layer at a time.
Wrapping on the way down
Each layer adds a A few bytes at the front of a message that say where it goes and how to handle it. Each layer adds its own. in front of whatever the layer over it hands down. The finished bundle, one header inside another, is like a letter in an envelope inside another envelope. This wrapping is called Wrapping a message in one header per layer on the way down, so each layer can read its own header on the way up..
Add the headers in the order the laptop adds them, starting with the one closest to the question.
The headers are not free. On this small question they add 46 bytes: 8 for UDP, 20 for IP, and 18 for the frame. That is why a network always carries a little less than its cable's speed.
Who opens which layer
The devices in the middle of the trip open only as many layers as their job needs:
- A switch works at layer 2. It reads the hardware address in the frame header, sends the frame out of the right port, and changes nothing.
- A router works at layer 3. It takes off the frame header, reads the IP address, lowers the TTL, and wraps the packet in a new frame for the next hop.
- The device at the end opens every layer, up to the program the message is for.
| Layer | At the laptop |
|---|---|
| 5 Application | Added Writes the question: what is the address of circuit.tako.id? |
| 4 Transport | Added Adds a UDP header: from port 51000 to port 53 |
| 3 Network | Added Adds an IP header: from 192.168.20.10 to 192.168.30.53, TTL 64 |
| 2 Link | Added Adds a frame header: from 3c:22:fb:0a:91:7e to 00:00:5e:00:53:01, the router |
| 1 Physical | Added Sends every bit as signals on the cable |
Step 1 of 4
The laptop wraps the question
The frame is addressed to the router, because the server is on another network.
The IP addresses stay the same from the laptop to the server, and only the frame changes at each hop. This is the envelope inside an envelope from Addresses.
Layer 2, layer 3, and the OSI model
People often say "layer 2" or "layer 3". The numbers come from an older model called Open Systems Interconnection: a model from the 1980s that splits networking into seven layers. People still use its layer numbers., which has seven layers instead of five. Its bottom four are the same as in this lesson. Its top three are all part of the application layer here:
| This lesson | OSI | What people say |
|---|---|---|
| Application | 5 Session, 6 Presentation, 7 Application | "layer 7" |
| Transport | 4 Transport | "layer 4" |
| Network | 3 Network | "layer 3" |
| Link | 2 Data link | "layer 2" |
| Physical | 1 Physical | "layer 1" |
So a "layer 2 problem" is about frames, hardware addresses, and switches. A "layer 3 problem" is about IP addresses and routes. A "layer 3 switch" is a switch that can also route, as many bigger switches can.
Layers in a Circuit file
The fields of a Circuit device file follow the layers too:
| Layer | In a Circuit device file | Lesson |
|---|---|---|
| 1 Physical | interfaces.ethernet, a port's speed, and link: where the cable goes | Trunks |
| 2 Link | switching.vlans, and a port's access_vlan or trunk_vlans | VLANs |
| 3 Network | addresses on a port or interface, and routing | DHCP |
| 4 Transport | protocol and dst_port in a firewall rule | Firewalls |
| 7 Application | system.dns, and management.ssh: programs the device itself runs | Writing a network down |
Here is part of a router's file, with the layer of each line in its comment.
system: { dns: { servers: ["203.0.113.53"] } }, // 7: the DNS server this router asks
interfaces: {
ethernet: {
"1g-1": { description: "Internet provider", addresses: ["203.0.113.2/30"] }, // 1: a port, and 3: its IP address
},
},
routing: { static_routes: [{ prefix: "0.0.0.0/0", next_hop: "203.0.113.1" }] }, // 3: everything else goes to the providerCircuit Studio draws your network one layer at a time too: the cables, the VLANs on each cable, and which devices share an address range.