The worksheetDownload the PDF
Answers

F10.8 Layers

Networks · GCSE · OCR J277 1.3.2, AQA 8525 3.5, Edexcel 1CP2 4.1.7 · about 15 min

BugBotLab

What this lesson is about

The four-layer TCP/IP model, encapsulation, and why layers are used.

Questions 5 marks in all

  1. [1 mark]Put the TCP/IP layers in order, from the top.

    Number the lines 1 to 4 to put them in the right order.

    1. Application
    2. Transport
    3. Link
    4. Internet
    Answer:
    Application
    Transport
    Internet
    Link

    Data goes down these layers to be sent, and up them when received.

  2. [1 mark]At which layer does HTTP work?

    1. AApplication
    2. BTransport
    3. CInternet
    4. DLink
    Answer: A. HTTP is used by applications such as browsers.
  3. [1 mark]Which layer adds IP addresses and routes packets between networks?

    1. AInternet
    2. BApplication
    3. CTransport
    4. DLink
    Answer: A. IP works at the internet layer.
  4. [1 mark]Which is an advantage of using layers?

    1. AOne layer can be changed without changing the others
    2. BData is sent without headers
    3. CIt removes the need for protocols
    4. DOnly one company can make network software
    Answer: A. Each layer is self-contained, with standard rules between them.
  5. [1 mark]What does this program print?

    frame = "IP 1>2 | TCP 80 | hello"
    for n in range(2):
        frame = frame.split(" | ", 1)[1]
    print(frame)
    Answer:
    hello

    Each split removes the header at the front.

The task: wrap and unwrap

Write wrap(data, headers) and unwrap(frame). wrap adds each header in headers, in order, in front of the data with | between, printing <layer>: <data so far> after each (starting with application: GET /battery before any header). Send the finished frame by radio. Then unwrap removes the three headers, and you print received by application: <data>.

# the two lines every program starts with: the commands, then the robot
from bugbot import *
connect()

data = "GET /battery"
names = ["transport", "internet", "link"]
headers = ["TCP 80", "IP 10.0.0.2>10.0.0.9", "WIFI 3C-02>3C-09"]

The hint students can ask for: Going down, each layer puts its header in front of what it was given, and you report the result at each step. Coming back up, take one header off the front at a time.

A solution

from bugbot import *
connect()
data = "GET /battery"
names = ["transport", "internet", "link"]
headers = ["TCP 80", "IP 10.0.0.2>10.0.0.9", "WIFI 3C-02>3C-09"]

def wrap(data, headers):
    print("application:", data)
    for i in range(len(headers)):
        data = headers[i] + " | " + data
        print(names[i] + ":", data)
    return data

def unwrap(frame):
    for header in headers:
        frame = frame.split(" | ", 1)[1]
    return frame

frame = wrap(data, headers)
send(frame)
print("received by application:", unwrap(frame))

Any program that meets the task's checks is marked correct in the simulator; this is one way, not the only way.