Edexcel International Advanced Level Computer Science, point 12.1.3
Definition
Packet switching is a method of sending data across a network by splitting it into small units called packets, which are sent independently, may take different routes, and are reassembled at the destination. (Circuit switching, which reserves a dedicated path for a whole call, isn't required.)
Function and why needed
- It makes efficient use of network links: many users' packets share the same lines, instead of each reserving a line.
- It is robust: if a link or router fails, packets are sent another way.
- It allows fair sharing and scales to the whole Internet.
a. Packet components
A packet has three parts:
| Part | Contents |
|---|---|
| Header | Source IP address, destination IP address, sequence (packet) number (to put them back in order), total number of packets, time to live (TTL) (a hop limit), protocol in use, packet length |
| Payload | The piece of data being carried (often a few hundred to about 1500 bytes) |
| Trailer (footer) | Error checking (a checksum or CRC, 12.3.3), to detect corruption |
- The TTL decreases by 1 at each router. If it reaches 0, the packet is discarded. This stops packets circulating forever.
- The sequence number is needed because packets may arrive out of order.
Operation
- The sender splits the data (for example an email or web page) into packets.
- Each packet gets a header (addresses, sequence number) and a trailer.
- Each packet is sent independently into the network.
- Routers forward each packet towards the destination, choosing the best route at that moment.
- Packets may take different routes, and arrive out of order, late or not at all.
- The destination checks each packet for errors, requests any missing or damaged ones to be resent (TCP), puts the packets in order by sequence number, and reassembles the data.
b. The Internet router
A router is a device that connects networks and forwards packets between them.
- It reads the destination IP address in each packet's header.
- It looks it up in its routing table, a list of networks and the next hop (the next router) to use.
- It forwards the packet through the correct interface, decreasing the TTL.
- It builds its routing table by exchanging information with other routers (using routing protocols), and chooses the best route (shortest, fastest, least congested). Dijkstra's algorithm (15.2.3) is used in some routing protocols.
- If a link fails or is congested, the router updates its table and sends packets another way.
Routers are different from switches: a switch forwards frames within a network using MAC addresses, but a router forwards packets between networks using IP addresses (3.1.1).
c. Protocols
| Protocol | Job in packet switching |
|---|---|
| IP (Internet Protocol) | Addresses packets and routes them between networks (best-effort delivery: no guarantee) |
| TCP | Splits data into segments, numbers them, checks for loss, requests resends and reassembles in order (reliable) |
| UDP | Sends datagrams with no checks (fast) |
| ICMP | Error and status messages (for example "destination unreachable", ping) |
| Routing protocols (OSPF, BGP) | Routers share information to build routing tables |
| Ethernet / Wi-Fi | Carry the packet over each individual link |
Benefits of packet switching
- Efficient: links are shared and not left idle.
- Resilient: packets are rerouted around faults.
- Cheaper than a dedicated line for each connection.
- Allows error recovery: only lost packets are resent, not the whole message.
- Can prioritise certain packets (quality of service).
- Supports many users at once.
Drawbacks
- Variable delay (latency and jitter) and packets can arrive out of order, which is a problem for real-time voice and video.
- Packets can be lost (congestion), needing retransmission.
- Overhead: headers add extra data to every packet.
- Reassembly takes processing.
- Security: packets may be intercepted on the way, so encryption (3.2, TLS in 12.1.2) is needed.
Worked example
Task: a 3000-byte file is sent using packets with a 20-byte header and a maximum payload of 500 bytes. How many packets are needed, and what is the total data sent?
- Packets: packets.
- Header overhead: bytes.
- Total sent: bytes.
- Overhead percentage: .
What if packet 4 is lost? The receiver notices a gap in the sequence numbers (1, 2, 3, 5, 6) and TCP asks for packet 4 to be sent again. Only that one packet is resent, not the whole file.
What if packets 5 and 6 arrive before packet 4? The receiver holds them and puts them in order using the sequence numbers, then passes the complete file to the application.
Exam tip: name the three packet parts and give examples of the header contents (source and destination address, sequence number, TTL). Say what a router does: reads the destination address, uses its routing table, forwards to the next hop. Mention different routes and reassembly by sequence number. You aren't required to study circuit switching.
Check yourself
Give three items found in a packet header
Any three of: source address; destination address; sequence number; total packets; time to live; protocol; length.
Why do packets have sequence numbers?
They may arrive out of order, so the destination uses the numbers to reassemble the data correctly and to spot missing packets.
What does a router do with a packet?
It reads the destination IP address, looks it up in its routing table and forwards the packet to the next hop, reducing the TTL.
What is the purpose of the time to live (TTL) field?
It limits how many routers a packet may pass through; it is decreased at each hop and the packet is discarded at 0, so packets can't circulate forever.
Give one advantage and one disadvantage of packet switching
Advantage: efficient sharing of links and rerouting around faults. Disadvantage: variable delay and out-of-order or lost packets, which affect real-time use.