One photo, many small jobs
You send a photo to a group chat. Your phone finds the Wi-Fi, picks a route to the server and splits the photo into pieces.
At the far end the pieces are checked and put back in order. Nobody wrote one huge program for all of that.
Instead, the work is shared out in layers. Each layer does one job.
By the end of this lesson
Note
I can place a protocol in its layer.
Key words
| Word | What it means | Example |
|---|---|---|
| Protocol | an agreed set of rules for talking over a network | |
| Layer | one level of the network that does one job | |
| Header | extra information a layer adds to the front of the data | |
| Packet | one small piece of data with its headers | |
| Encapsulation | wrapping data inside the header of each layer in turn | |
| Port | a number that says which program on a device gets the data | 80 |
The cells students fill in are left blank in this preview.
Four layers, each with one job
The internet uses a model called TCP/IP. It has four layers.
The application layer is the program you use, such as a browser. The transport layer splits the data and checks it arrives. The internet layer puts an address on each packet and finds a route. The link layer moves bits across one cable or one Wi-Fi hop.
Worked example: the layers and their protocols
| Layer | Its job | Protocols you will meet |
|---|---|---|
| Application | The program's own messages | HTTP, HTTPS, DNS, SMTP |
| Transport | Which program, in order, checked | TCP, UDP |
| Internet | Addresses and routes across networks | IP, ICMP |
| Link | One hop on one cable or Wi-Fi | Ethernet, Wi-Fi |
The cells students fill in are left blank in this preview.
Each layer wraps the one above
When you load a web page, the browser writes an HTTP message. The transport layer puts a TCP header in front. It holds the port numbers.
The internet layer adds an IP header with the two addresses. The link layer adds an Ethernet header for the next hop. This wrapping is encapsulation.
At the other end, each layer takes off its own header and passes the rest up.
Worked example: one web request, wrapped
| Order on the wire | Header | What it holds |
|---|---|---|
| First | Ethernet | The hardware address of the next hop |
| Second | IP | From 192.168.1.20 to 198.51.100.7 |
| Third | TCP | From port 51000 to port 443 |
| Last | HTTPS data | The request for the page |
The cells students fill in are left blank in this preview.
Meet the machines in the lab
netlab statusShown here, not run. Create a free account to press Run and type it into your own lab’s terminal.
Ping the router next to h1
sudo ip netns exec h1 ping -c 2 -W 1 10.0.1.1Shown here, not run. Create a free account to press Run and type it into your own lab’s terminal.
See the router's hardware address
sudo ip netns exec h1 ip neighShown here, not run. Create a free account to press Run and type it into your own lab’s terminal.
What the three Runs show
The first Run lists five machines. The host h1 has one cable, to-r1, with the address 10.0.1.2/24.
The ping uses ICMP, an internet layer protocol. Two replies come back from 10.0.1.1.
The third Run shows the link layer. It prints one line: the router's IP address, then lladdr and its hardware address, then REACHABLE.
See which ports a router listens on
sudo ip netns exec r1 ss -ltnShown here, not run. Create a free account to press Run and type it into your own lab’s terminal.
Ports belong to the transport layer
This Run lists TCP ports that are waiting for a connection. There are three LISTEN lines, on ports 2601, 2616 and 2623.
Each port leads to one small program inside the router. All three only listen on 127.0.0.1, the router talking to itself.
A common mistake
Warning
Many people think the Ethernet header travels all the way to the far end. It only lasts one hop. Each router takes it off and puts on a new one for the next cable. The IP header is the one that crosses the whole trip.
Going further: a packet with no transport header
A ping packet is Ethernet IP ICMP. It has no TCP or UDP header at all.
Add a function has_transport(packet) to your assignment. It returns True when one header is TCP or UDP. Try it on a web request and on a ping. Then say why a ping needs no port number.