A long letter in many envelopes
You must post a long essay, but each envelope holds only one page. So you number the pages and put each in its own envelope, with the address.
The envelopes go by different routes. Some arrive late. The other person puts the pages back in order using the numbers. A network is a group of computers joined together. Networks send data in the same way. A packet is a small piece of data with an address on it. Each envelope is a packet.
Key words
| Word | What it means | Example |
|---|---|---|
| Packet | A small, addressed piece of data sent over a network. | One envelope |
| Header | The front part of a packet, with addresses and numbers for delivery. | The address on the envelope |
| Payload | The part of a packet that carries the real data. | The page inside |
| Trailer | The end part of a packet, with a check value. | A check number written on the back of the envelope |
| Packet switching | Sending data as packets that may each take a different route. | Envelopes on different roads |
| Sequence number | A number that puts packets back in the right order. | Page 3 of 5 |
| Hop | One step of a packet from one router to the next. | 3 hops to the server |
| TTL | Time to live: a count that drops at each router, and at zero the packet is thrown away. | TTL 64 |
| Protocol | A set of rules computers follow to talk to each other. | HTTP |
| Redundancy | Extra data added on purpose to help find mistakes. | A check value |
| CRC | Cyclic redundancy check: a value that shows if data was damaged on the way. | A number in the trailer |
| IP address | A number that names a device on a network. | 10.0.12.1 |
| Router | A device that joins networks and sends packets on the right way. | A home router |
| Network | Computers joined to share data. | The college network |
The cells students fill in are left blank in this preview.
Match each packet part to its role
Have a go
Loading…
Your answers are marked here and are not kept. A college account keeps every student’s marks.
What is in a packet?
| Part | What it holds | Role |
|---|---|---|
| Header | Source address, destination address, sequence number | Gets the packet to the right place, in the right order |
| Payload | A piece of the data | The reason the packet exists |
| Trailer | An error check value such as a CRC | Lets the receiver spot damaged data |
The cells students fill in are left blank in this preview.
A packet from front to back
flowchart LR
h["Header: source, destination, sequence number"] --> p["Payload: a piece of the data"] --> t["Trailer: CRC check value"]
Each packet can take its own route
Data is cut into packets. Each router reads the destination address and sends the packet on to the next router. Two packets of the same message can take different routes.
At the end, the receiver uses the sequence numbers to put the packets back in order. This helps: if one route is busy or broken, packets take another. Many people can share the same cables.
Try it: put the packets in order
# Five packets arrive in the wrong order. Each has a sequence number.
arrived = {3: "my", 1: "I", 5: "phone", 2: "lost", 4: "new"}
for number in range(1, 6):
if number in arrived:
print(number, arrived[number])
else:
print(number, "is missing")
# Now delete one packet from the dictionary and run it again.
# The message has a gap: that is packet loss.
Make a free account to save your work and track your progress.
Extra: More in a real header
| Part | What it does |
|---|---|
| TTL (time to live) | Goes down by one at each hop. At zero the packet is thrown away, so a lost packet cannot travel for ever. |
| Protocol | Says which set of rules the payload follows, such as TCP. |
| Where the parts really are | The IP header holds the addresses and the TTL. The sequence number is in the TCP header. The CRC is in the trailer of the frame. |
| Two more causes of loss | The TTL reaches zero, for example when packets go round in a circle. Or a router has no route to the network. |
The cells students fill in are left blank in this preview.
Two routes, one message
flowchart LR
s["Sender"] --> r1["Router 1"]
r1 -->|"packets 1 and 3"| r2["Router 2"]
r1 -->|"packets 2 and 4"| r3["Router 3"]
r2 --> d["Receiver puts them in order"]
r3 --> d
Extra: Send four packets and read them
sudo ip netns exec h1 ping -c 4 -W 1 10.0.12.1A command for the lesson’s lab terminal. It is shown here and not run.
Extra: Send two packets that are lost
sudo ip netns exec h1 ping -c 2 -W 1 10.0.3.2A command for the lesson’s lab terminal. It is shown here and not run.
Extra: What ping showed
Note
In the first output each line has icmp_seq. This is the sequence number of the packet. Each line also has ttl, the time to live. The second output says every packet was lost, because the router has no route to that network.
Why packets are lost
There are two main causes of packet loss.
The first is congestion. Too many packets arrive and a router has no room, so it throws some away.
The second is errors. A cable or a device is faulty. Wi-Fi has interference (other signals that make yours worse). A damaged packet fails its check and is thrown away.
A lost packet is not always a big problem. The sender can send it again.
Match the cause of packet loss
Have a go
Loading…
Your answers are marked here and are not kept. A college account keeps every student’s marks.
A check value finds damaged data
How does the receiver know the data is not damaged? The sender works out a check value from the data and sends it too. The receiver works it out again. If the two values differ, the data changed.
Here is a simple check. Add up the digits. A real CRC is a stronger kind of check that computers work out very fast. You do not need to know how it works inside. You need to know that it finds damaged data.
Worked example: add the digits
| Step | Sender | Receiver (good) | Receiver (damaged) |
|---|---|---|---|
| Data | 4 7 2 | 4 7 2 | 4 8 2 |
| Add the digits | 4 + 7 + 2 = 13 | 4 + 7 + 2 = 13 | 4 + 8 + 2 = 14 |
| Check value sent | 13 | 13 | 13 |
| Same? | not needed | Yes: accept it | No: 14 is not 13, so throw it away or ask again |
The cells students fill in are left blank in this preview.
Worked example: the check for "Hi"
| Step | What to do | Result |
|---|---|---|
| 1 | Find the code of each letter. H is 72 and i is 105. | 72 and 105 |
| 2 | Add them: 72 + 105 | Check value 177 |
| 3 | The receiver gets "Ho". The code of o is 111. 72 + 111 = 183. | 183 is not 177: damaged |
The cells students fill in are left blank in this preview.
Try it: a toy check
data = "Hi"
check = 0
for letter in data:
check = check + ord(letter)
print("Check value sent:", check)
received = "Ho" # one letter changed on the way
again = 0
for letter in received:
again = again + ord(letter)
print("Receiver works out:", again)
print("Damaged?", again != check)
Make a free account to save your work and track your progress.
Your turn: write the check
Write two functions. checksum(text) adds up the code of every character and gives back the total. In Python, ord("A") gives the code of a character, 65. is_damaged(text, check) gives back True when the text no longer matches the check number it came with. Press Run Tests to check.
def checksum(text):
# Give back a check number for the text.
# Add up the code of every character.
# Python gives you the code of a character with ord("A"), which is 65.
return 0
def is_damaged(text, check):
# Give back True if the text no longer matches the check number it came with.
return False
Make a free account to save your work, or press Start lab to work through the whole lesson.
Extra: Keeping the check value small
A long message gives a very big total. A real check value has a fixed size, so it fits in the trailer.
One simple way: divide the total by 256 and keep only the remainder. Say the total is 366. 366 - 256 = 110, so the check value is 110. In Python the remainder is the % symbol: 366 % 256 is 110.
A real CRC also uses a special kind of division, on the bits.
Extra: Your turn: a check that stays small
Write the function small_checksum(text). It adds up the code of every character, like checksum. Then it gives back the remainder after dividing the total by 256. The symbol for the remainder is %. Press Run Tests to check.
def small_checksum(text):
# Add up the code of every character, with ord().
# Then give back the remainder after dividing the total by 256.
return 0
Make a free account to save your work, or press Start lab to work through the whole lesson.
Key words crossword
Have a go
Loading…
Your answers are marked here and are not kept. A college account keeps every student’s marks.
Final check
Have a go