Cambridge AS & A Level · Part 3 · Chapter 17
Communication and Internet Technologies
How a message actually crosses the Internet: circuits and packets, protocols stacked in layers, TCP/IP and Ethernet working together, and the application protocols you use every day, from HTTP and email to BitTorrent. Every figure, question and exam-style question from the chapter is here, with labs to try each idea.
Guru Jazzy🎯 Learning objectives
By the end of this chapter you should be able to show understanding of:
- Circuit switching
- Packet switching
- why a protocol is essential for communication between computers
- how protocol implementation can be viewed as a stack, where each layer has its own functionality
- the TCP/IP protocol suite
- the protocols HTTP, FTP, POP3, IMAP, SMTP and BitTorrent and their purposes
🔀 17.01 Transmission modes
To send data across an internetwork (a network of networks) there are two possible approaches: circuit switching or packet switching.
Circuit switching
Circuit switching is how the traditional telephone system works. Public Switched Telephone Networks (PSTNs) are now mostly digital, so the same method that carried voice calls can also carry data. Chapter 2 (Section 2.06) showed how a PSTN supports Internet use, typically as a leased line service.
In Figure 17.01 each end-system is connected to a local exchange that has a switching function, and the exchanges are linked through several intermediate switching nodes. For data transfer to take place:
- The sender provides the identity of the intended receiver.
- The system checks whether or not the receiver is ready to accept data.
- If the receiver is available, a sequence of links is established across the network.
- The data is transferred.
- The links are removed.
The links between nodes are dedicated channels in shared transmission media, so transmission is guaranteed to be unimpeded. A phone call has a definite end, when the links are removed. A leased-line data connection, on the other hand, may keep a permanent circuit.
Packet switching
Packet switching sends data without setting up a circuit. Data cannot go as one continuous stream. Instead it is split into portions carried inside packets. A packet has a header, which holds the delivery instructions, and a data body. It is rather like the postal service, only more complex.
The diagram in Figure 17.01 still works for packet switching, with two differences: the links are not fixed when the sender transmits a packet, and the nodes do much more work than in a circuit-switched network. Section 17.04 explains how a router acts as one of these nodes.
🔬 Lab: circuit switching vs packet switching
Send the message HELLO, WORLD! from end-system A to end-system B. Then cut links during the transfer (click a link, or use the button) and watch what each method does.
Receiver B's buffer (slots in sequence-number order):
| Circuit switching | Packet switching | |
|---|---|---|
| Set-up | A circuit (sequence of links) must be established first | No circuit; each packet is sent when ready |
| Route | Every bit follows the same, fixed route | Each packet's route is decided at each node, so packets may take different routes |
| Order of arrival | Always in order, as a stream | Can arrive out of order; sequence numbers let the receiver reassemble them |
| Use of the links | Links are reserved for one conversation, even when nothing is being sent | Links are shared by many users' packets, so capacity is used efficiently |
| If a link fails | The transfer fails and the circuit must be set up again | Nodes route later packets round the failure |
| Best for | Real-time, continuous traffic: phone calls, live video | Bursty data that can wait a moment: email, files, web pages |
📜 17.02 Protocols
The basic definition of a protocol is simple: it is a set of rules. Before asking what the rules are about, note three complications:
- We often say "a protocol" when we really mean a protocol suite that contains several individual protocols, because networking is complex enough to need many of them.
- A protocol may exist in several different versions.
- Some protocols are used to complement another protocol.
The rules have to be agreed by the sender and the receiver for any communication over a network. At the simplest level a protocol could say that a positive voltage represents a bit with value 1. It might set a maximum transmission speed. Many rules are about the format of a message or part of one, for example what the first 40 bytes of a packet must contain.
🥞 17.03 A protocol stack
The protocols in a suite can be viewed as layers in a protocol stack:
- Each layer can only accept input from the next higher layer or the next lower layer.
- A defined interface between adjacent layers is the only interaction allowed between them.
- A layer is serviced by the actions of the layers below it.
- Apart, possibly, from the lowest layer, each layer's functions are provided by installed software.
- A layer may be made up of sub-layers.
- Any user interaction uses protocols from the highest layer in the stack.
- Any direct access to hardware is confined to the lowest layer.
🧩 Build the five-layer stack
Put the layers of the network model (Figure 17.02) in order, top layer first.
🎮 Which layer does this protocol belong to?
🌐 17.04 The TCP/IP protocol suite
TCP/IP is the protocol suite that underpins Internet use. It can be explained using the network model in Figure 17.02: TCP/IP only occupies the top three layers.
The diagram shows two end-systems and the logical connections between matching layers. An application running on one end-system behaves as though it had a direct connection to an application on the other. In reality:
- The application-layer protocol on the sender sends a "message" to the transport-layer protocol on the same system.
- The transport layer starts a process that delivers the identical "message" to the receiver end-system.
- On the receiver, the transport layer hands the "message" up to the application-layer protocol.
The TCP/IP suite includes many protocols, for example:
| Layer | Example protocols |
|---|---|
| Application | HTTP, SMTP, DNS, FTP, POP3, IMAP |
| Transport | TCP, UDP, SCTP |
| Network | IP, IGMP, ICMP, ARP |
The list shows how wide, and still evolving, the suite is. Only some of these protocols are studied further.
TCP (Transmission Control Protocol)
When an application on one end-system has a "message" for another end-system, an application-layer protocol passes the user data to the transport layer. TCP, working in the transport layer, is then responsible for the safe delivery of the message. It creates enough packets to hold all of the data; each packet is a header plus user data.
A TCP packet is usually called a segment. Its header is at least 20 bytes and contains:
- source port and destination port (16 bits each)
- sequence number (32 bits): the position of this segment's first byte in the whole stream, used to reassemble
- acknowledgement number (32 bits): the next byte the sender expects to receive
- header length (data offset), and control flags such as SYN (start a connection), ACK, FIN (finish) and RST (reset)
- window size: how much data the receiver can accept before it must acknowledge (flow control)
- a checksum to detect corrupted segments, and an urgent pointer and optional fields
The user data follows the header. Notice there are no IP addresses here: those are added by IP in the layer below.
As well as safe delivery, TCP makes sure any response is directed back to the right application protocol. So the header carries a port number that identifies the application-layer protocol (for HTTP the port is 80), and the port number for the application at the receiving end-system. TCP is not concerned with the address of the receiving end-system. If the packet is one of a sequence, a sequence number is included so that the user data can be reassembled correctly.
TCP is connection-oriented. As in Section 17.01, only one packet of the sequence is sent to the network layer at first. When the network layer returns an acknowledgement that the connection has been established, TCP sends the other packets and receives response packets containing acknowledgements. That lets missing packets be identified and re-sent.
IP (Internet Protocol)
The job of the network layer, and of IP in particular, is to make sure of correct routing over the Internet. IP takes the packet from the transport layer and adds another header containing the IP addresses of both sender and receiver. To find the receiver's IP address it will very likely use the DNS service to look up the URL in the user data (Chapter 2, Section 2.09).
The IP packet, usually called a datagram, goes to the data-link layer, which belongs to a different protocol suite. The data-link layer puts datagrams into frames (see the next section). After that, IP has no further duty. IP is a connectionless service: once a packet has gone, IP does not know whether it arrived. If IP receives a packet containing an acknowledgement of an earlier packet, it simply passes it on to TCP without looking at the content.
The router
As Figure 17.02 shows, a frame sent by the data-link layer will arrive at a router during transmission, and more likely at several. There, the datagram inside the frame is handed back to IP. The router software then chooses the next target host, using a routing table for that router. The Internet is too big and complex for any router to hold a global routing table. Once the right address has been put into the datagram, IP passes it back down to the router's data-link layer.
Each router's routing table records any current problems with the possible next steps, so packets reach their destination in the shortest time available.
🔬 Lab: follow a message down the stack, across a router and up again
Type a short message to send to a web server, then step through the journey. Watch which headers are added and removed, and notice which addresses change at the router and which do not.
🎮 Switch or router?
🔌 17.05 The Ethernet protocol stack
Chapter 2 (Section 2.05) introduced Ethernet as a protocol suite for a local area network (LAN). It can run in an isolated LAN with no outside connection, but nowadays a LAN is almost always connected to the Internet, so the LAN's protocol suite has to support the suite used for the Internet.
Look at the stack for one end-system in Figure 17.02. TCP/IP occupies the top three layers of the five-layer stack, so it is supported by the lower two layers. TCP/IP does not care how those two layers work: it is designed to run on whatever protocols are available.
Some sources show only a four-layer stack for an end-system. Either they leave out layers handled entirely by hardware rather than software, or they merge all of the support for TCP/IP into one layer.
Ethernet is the most likely protocol to provide the lower two layers. It can be seen as having two sub-layers for each of the Data link and Physical layers:
MAC addresses
Both addresses in the Ethernet frame are physical or MAC addresses. A MAC address uniquely identifies one network interface card (NIC), as in Chapter 2 (Section 2.04).
Addresses have stayed unique so far because the 48 bits used give enough different addresses. A 64-bit alternative is already used occasionally and is ready for when 48 bits run out. The 48-bit address is usually written in hexadecimal, for example:
4A:30:12:24:1A:10
In one version of the scheme, the first three bytes identify the manufacturer.
🔬 Lab: inside a MAC address
Generate an address, or type your own (six pairs of hex digits separated by : or -).
⚡ Byte challenge
| MAC address | IP address | |
|---|---|---|
| Layer | Data link (Ethernet) | Network (IP) |
| Identifies | One NIC: a physical device | A host's position on the Internet |
| Size | 48 bits (or 64), in hex | 32 bits (IPv4) or 128 bits (IPv6) |
| Set by | The manufacturer | The network (e.g. by a DHCP server) |
| On a journey | Changes at every hop: each frame only crosses one link | Source and destination stay the same end to end |
📨 17.06 Application-layer protocols associated with TCP/IP
There are very many application-layer protocols. These are some of the most used.
HTTP (HyperText Transfer Protocol)
HTTP underpins the World Wide Web, which makes it the most important application-layer protocol. Every time a user opens a website in a browser, HTTP is used, though you never see it working.
HTTP is a transaction-oriented, client–server protocol. The client sends a request message and the server sends back a response. HTTP defines the format of these messages. The first line of a request is the request line, which can be followed by header lines. All of it uses ASCII coding. The request line has the format:
<Method> <URL> <Version>CRLF
CR and LF are the ASCII carriage return and line feed characters. The method is usually GET, but there are several alternatives, which makes HTTP useful for much more than fetching web pages. The version must be given because HTTP has evolved and more than one version is in use.
🔬 Lab: build an HTTP request line
Every character as ASCII (hex code underneath). The two red cells are CR and LF.
Email protocols
The traditional way of sending and receiving email (Figure 17.04) involves three separate client–server interactions. The sender, acting as a client, connects to a mail server. That server then acts as a client when it sends the email on to the receiver's mail server. The receiver then collects it, acting as a client.
A more recent alternative to POP3 is IMAP (Internet Message Access Protocol):
- With POP3 emails are downloaded onto the client computer. You could argue this is safer from cyber-attack because the emails are stored locally, but a server is backed up regularly while a local client might not be. POP3 emails can only be read on that one client system.
- With IMAP the emails are not downloaded: they stay on the server but are accessible from the client. The big advantage is that the server can be reached from any client, which suits people on the move or using a different system from usual.
SMTP has largely been replaced by web-based mail. A browser is used to reach the email application, so the protocol used is HTTP. SMTP is still used to transfer email between the mail servers.
🔬 Lab: POP3 vs IMAP with two devices
Three emails are waiting on your mail server. Check mail on your laptop, then on your phone, and compare the two protocols.
🗄️ Mail server
💻 Laptop
📱 Phone
🔬 Lab: which protocol is used at each hop?
Tap each hop of the journey in Figure 17.04 to see its protocol. Switch on webmail to see what changes.
If you read mail in a browser (Gmail, Outlook.com and the like), your device uses HTTP (really HTTPS) to reach the mail service, and the providers' servers use SMTP between them. If you use a mail app, look in its account settings: you will find an incoming server that is either IMAP or POP3, and an outgoing SMTP server. Most providers let you choose IMAP or POP3. Choose IMAP if you read mail on several devices; POP3 if you want the mail kept only on one computer.
FTP (File Transfer Protocol)
For a routine file transfer from one user to another, the most likely method is attaching the file to an email. That is not always suitable. FTP is the application-layer protocol that can handle any file transfer between two end-systems. Transfer is not simple if the end-systems have different operating systems with different file systems. FTP handles this by separating the control process from the data-transfer process.
Install an FTP client (FileZilla and WinSCP are free), or use one built into a code editor. Enter the host name, user name and password your web host gives you, and the port (21 for FTP, or 22 for its secure replacement, SFTP). The client shows your local files on one side and the server's on the other, and you drag files across to upload. On the command line, ftp or sftp followed by the host name does the same job with commands such as put and get. Many hosts now insist on SFTP or FTPS, because plain FTP sends the password unencrypted.
🎮 Pick the protocol
🧲 17.07 Peer-to-peer (P2P) file sharing
The traffic generated by peer-to-peer (P2P) file sharing is a major part of Internet use. P2P is an architecture with no structure and no controlling mechanism. Peers act as both clients and servers, and each peer is just one end-system. When a peer acts as a server it is called a seed.
The BitTorrent protocol is the most used, because it allows fast sharing of files. It has to solve three basic problems.
- How does a peer find others that have the wanted content?
Every content provider supplies a content description called a torrent. This is a file containing the name of the tracker (a server that leads peers to the content) and a list of the chunks that make up the content. The torrent file is at least three orders of magnitude smaller than the content, so it transfers quickly. The tracker keeps a list of all the other peers, called the swarm, that are actively downloading and uploading the content. - How do peers replicate content to give high-speed downloads for everyone?
Peers download and upload chunks at the same time. They exchange lists of chunks and aim to download rare chunks first. Every time a rare chunk is downloaded, it automatically becomes less rare. - How do peers encourage others to provide content, rather than just download for themselves?
This means dealing with free-riders or "leechers" who only download. A peer at first tries other peers at random, but then only keeps uploading to peers that provide regular downloads in return. A peer that does not upload, or uploads only slowly, will eventually be isolated or "choked".
BitTorrent has its own unusual vocabulary, and there are other terms not covered here. Fortunately, the principles are straightforward.
🔬 Lab: a BitTorrent swarm
A 12-chunk file starts on one seed (S). Peers P1–P3 share fairly; L is a leecher that never uploads. Each round, every uploader can send at most 2 chunks. Compare rarest-first with random order, and try making the seed leave after round 6: by then it has uploaded only 12 chunks, so the swarm survives only if all 12 were different.
A tracker can be run by anyone: the person or organisation publishing the content (a Linux distribution tracks its own downloads, for example), a torrent website, or volunteers running public trackers. A torrent can list several trackers in case one is down.
Alternatives remove the need for a central tracker. With a distributed hash table (DHT), the peers themselves share the job of remembering who has which content ("trackerless" torrents). Peer exchange (PEX) lets connected peers pass on lists of other peers they know. A magnet link identifies the content by a hash, so a client can find peers through DHT without first downloading a torrent file.
📌 Summary
- Circuit switching requires a dedicated circuit to be established between sender and receiver before transmission can start.
- In packet switching, packets can be transmitted without any circuit being created.
- Packet switching can use connectionless or connection-oriented transmission.
- A protocol suite is implemented as a layered stack.
- The TCP/IP protocol suite supports usage of the Internet.
- Ethernet is the most likely option for use in the Data link and Physical layers.
- Examples of application-layer protocols are HTTP, SMTP, POP3, IMAP and FTP.
- Peer-to-peer file sharing on the Internet uses the BitTorrent protocol.
🃏 Key-term flashcards
Tap a card to flip it.
✅ Quick quiz
📝 Exam-style questions
Write your answer first, then open the model answer. These are my mark-scheme-style points, not official mark schemes.
Try it here first: choose a part for each item.
Answers: (a) IP (b) IP (c) TCP (d) TCP (e) TCP (f) TCP. Addresses belong to the network layer (IP); ports, sequence numbers and acknowledgements belong to the transport layer (TCP).
A labelled stack, for example:
Application ┐
Transport ├ TCP/IP suite
Network ┘
Data link ┐ LLC sub-layer
│ MAC sub-layer
Physical │ PCS sub-layer
┘ PMA sub-layer ← Ethernet suite
↕ transmission medium ↕ - A five-layer stack with the layers named in the correct order. [1]
- Application, Transport and Network shown as the TCP/IP suite. [1]
- Data link and Physical shown as the Ethernet suite. [1]
- Sub-layers: LLC and MAC in Data link; PCS and PMA in Physical. [1]
- Arrows showing each layer only passes data to the layer above or below it (down at the sender, across the medium, up at the receiver). [1]
- A physical address that uniquely identifies a network interface card (NIC).
- It is 48 bits (sometimes 64), usually written as 12 hex digits, e.g. 4A:30:12:24:1A:10.
- It is set by the manufacturer; the first three bytes can identify the manufacturer.
- It is used in the Ethernet frame (data-link layer) as the transmitter and receiver address.
(a) Any three:
- Email attachment: the owner attaches the file to an email sent to the user.
- FTP: the file is put on (or fetched from) an FTP server, and the user downloads it with an FTP client.
- Web download: the file is placed on a web server and the user downloads it through a browser link.
- Peer-to-peer: the file is shared as a torrent; the user's BitTorrent client downloads chunks from the swarm.
(b)
- Email: SMTP pushes the email from the sender's client to its mail server and on to the receiver's mail server; POP3 or IMAP lets the receiver pull it from the server (or HTTP if webmail is used).
- FTP: the FTP protocol, which uses a separate control connection for commands and a data connection for the transfer, coping with different file systems.
- Web download: HTTP: the browser sends a GET request for the file's URL and the server's response contains the file.
- P2P: the BitTorrent protocol: the torrent file names the tracker, the tracker supplies the swarm, and chunks are exchanged between peers.
- SMTP: a push protocol. It sends the email from the sender's email client to the sender's mail server, then from that mail server (acting as a client) to the receiver's mail server. Even with webmail, SMTP is still used between servers.
- POP3: a pull protocol used by the receiver's email client to fetch mail from its mail server. The emails are downloaded to the client and usually removed from the server, so they can only be read on that one device. Locally stored mail may be safer from online attack, but it may not be backed up.
- IMAP: an alternative to POP3 for receiving. The emails stay on the server and the client just accesses them, so they can be read from any device and stay in sync. The server is regularly backed up.
- HTTP: used for web-based email. The user reaches the email application through a browser, which uses HTTP requests and responses to send and read mail, instead of using SMTP and POP3/IMAP directly from the device.
A diagram like Figure 17.04 (client → SMTP → mail server → SMTP → mail server → POP3/IMAP → client) earns credit.
Answers: client downloads from server → POP3; server to server → SMTP; client sends to server → SMTP; browser requests a web page → HTTP.
Peer-to-peer (P2P).
- (i) Tracker: a server named in the torrent file that keeps a list of the peers (the swarm) sharing the content, and tells a new peer which peers to connect to.
- (ii) Seed: a peer that has the complete file (all the chunks) and acts as a server, uploading chunks to other peers.
- (iii) Swarm: all the peers currently downloading and/or uploading chunks of the same content; peers in the swarm swap chunks with each other.
Cambridge International AS & A Level Computer Science 9608, Paper 31 Q6, June 2015
Any two: the destination IP address; the source IP address; the packet's sequence number; the source/destination port numbers; a checksum; the hop count/time to live; the packet size.
- A router receives each packet and reads its destination IP address.
- It looks up its routing table to choose the next router (hop) on the way to the destination…
- …taking account of current traffic and faulty links, to give the fastest route available.
- It forwards the packet; different packets of the same email may be sent along different routes.
- An email is not real-time: a small delay, or packets arriving out of order, does not matter, because the packets are reassembled using sequence numbers before the email is read.
- Missing packets can be detected and re-sent; and no dedicated circuit is needed, so the network's capacity is shared efficiently.
Circuit switching.
Application: a (video) phone call or a live video conference. [1]
- It is real-time, so the data must arrive with no delay and in the correct order.
- A dedicated circuit gives a guaranteed, unimpeded channel for the whole call: the same route, so no packets out of order and no reassembly delay.
- The transfer is continuous for the length of the call, so reserving the links is not wasteful.
Cambridge International AS & A Level Computer Science 9608, Paper 31 Q3, November 2015
Guru Jazzy · Cambridge AS & A Level Computer Science · Chapter 17 Communication and Internet Technologies · Figures from the Cambridge coursebook (Langfield & Duddell)