Networks · GCSE · OCR J277 1.3.2, AQA 8525 3.5, Edexcel 1CP2 4.1.3 · about 15 min
MAC and IP addresses, IPv4 and IPv6, and packet switching.
[1 mark]Which of these is a valid IPv4 address?
[1 mark]What is a MAC address used for?
[1 mark]How many bits is an IPv6 address?
[1 mark]Why do packets have sequence numbers?
[1 mark]Which is in a packet header?
[1 mark]What does this program print?
packets = ["2/2:Bot", "1/2:Bug"]
packets.sort()
print("".join(p[4:] for p in packets))BugBot
Sorted into order, the pieces join to BugBot.
Write make_packets(message, size), which splits message into pieces of size characters and returns them as packets in the form <number>/<total>:<piece>. Make the packets for message with a size of 10, print each one, and send each by radio. The packets arrive in the order [packets[2], packets[0], packets[1]]: sort them back into order by their sequence numbers, and print reassembled: <message> and matches: True (or False).
# the two lines every program starts with: the commands, then the robot from bugbot import * connect() message = "robot 7 at 25,40 battery 87%"
The hint students can ask for: Slice the message into equal pieces and label each one with its number and how many there are in total. To reassemble, sort by the number at the front of each packet, then join the pieces back together.
from bugbot import *
connect()
message = "robot 7 at 25,40 battery 87%"
def make_packets(message, size):
pieces = [message[i:i + size] for i in range(0, len(message), size)]
return [f"{n + 1}/{len(pieces)}:{piece}" for n, piece in enumerate(pieces)]
packets = make_packets(message, 10)
for packet in packets:
print(packet)
send(packet)
arrived = [packets[2], packets[0], packets[1]]
arrived.sort(key=lambda packet: int(packet.split("/")[0]))
text = "".join(packet.split(":", 1)[1] for packet in arrived)
print("reassembled:", text)
print("matches:", text == message)
Any program that meets the task's checks is marked correct in the simulator; this is one way, not the only way.