Unit 6 · The Internet & Computing Systems · Lesson 6.5 · Lab 6.5

Lab: Packet Simulation

Today you build the packetizer yourself. Split a message into numbered packets, send them across a network that loses some on purpose, put them back together, and resend what’s missing.

Big Idea 4 — Computer Systems & NetworksCED 4.1 · 3.17 random · Lab 6.5 · 10 pts

Before this lab

No reading — build. Keep 6.4 (packets and TCP), 3.6–3.8 (lists and traversal), and 3.17 (random values) open. Your teacher hands out the Lab 6.5 spec today.

1

Where We Are

People→ Bits→ Programs→ Internet→ Security→ Big Data→ Impact

Internet, in code. Your simulation will behave like the real thing: lost packets, retries, and a delivery time that climbs as the network gets worse.

2

What You’re Building

Lab 6.5 — Packet Simulation

1. Split. Turn a message string into a list of numbered packets.

2. Send. Write a procedure with a parameter (the loss rate) that randomly decides whether each packet survives.

3. Reassemble. Put the survivors in order and find which numbers are missing.

4. Resend. Keep resending missing packets until the message is complete. Count every retransmission.

5. Measure. Run it at several loss rates and chart loss rate vs. retransmissions.

AP connection. List, student-developed procedure with a parameter, selection, iteration — the four things every Create PT program needs. This lab is Create PT rehearsal in a networking costume.
3

The Model

Here is the one new move — a procedure that succeeds some percent of the time — in a different costume: free throws. Your lab uses the same shape for packets.

Python

import random

def shot_made(percent):
    return random.randint(1, 100) <= percent

makes = 0
for i in range(10):
    if shot_made(70):
        makes = makes + 1
print(makes)

AP Pseudocode

PROCEDURE shotMade(percent)
{
   RETURN (RANDOM(1, 100) ≤ percent)
}

makes ← 0
REPEAT 10 TIMES
{
   IF (shotMade(70))
   {
      makes ← makes + 1
   }
}
DISPLAY(makes)
Read it as English. RANDOM(1, 100) ≤ 70 is true for 70 of the 100 equally likely values — a 70% chance. For a packet that’s lost 20% of the time, which comparison would you write? Decide before you code.
4

Try It — Watch One Message Cross

A network with a loss rate you choose. Each round, every packet not yet delivered is sent; some get lost. Run it several times at the same rate — random means the count changes.

loss rate: packets: 10

This is a sanity check, not your lab. Your program should behave the same way — 0% loss means zero retransmissions, and higher rates mean more rounds.

5

What You Turn In

Turn inWhat it must show
Your programA list of packets; a procedure with a loss-rate parameter that uses a random value; selection; iteration; retransmission until complete.
Your chartLoss rate on the x-axis, retransmissions on the y-axis, at least four rates. y-axis starts at zero (5.8).
One sentenceWhat the chart shows — and only what it shows. One run per rate is noisy; say so if that’s what you did.
Challenge tier. Add a checksum — a number computed from a packet’s data and sent with it — so the receiver can detect a packet that arrived damaged, not just missing.
6

Check

Four questions on the patterns you’re about to code.

0 of 4 answered
7

Connections

Came from 3.17 — random values. Here they do real work: they model an unreliable network.
Came from 4.10 — simulation — a simplified model you can run many times. Same idea, new system.
Came from 5.8 — your chart follows the honest-axis rule.
Next in 6.6 — where do packets actually go? Routers, one hop at a time.
← 6.4 Packets and TCP