Simulate TCP and UDP behaviour
Inject loss, reordering and retransmission into a bounded simulation, then separate transport arrival from application acceptance.

Packet Pat: I want you to trace arrival, ordering, retry and application acceptance as separate decisions.
Predict the reading, then compare it with the measurement.
Python 3 in your browser (JupyterLite)
Python · no installInject loss, reordering and retransmission into a bounded simulation, then separate transport arrival from application acceptance.
Open the notebook in your browser and run each Python cell; no install or account is needed.
Three ways to run: use JupyterLite here with no install; run main.py locally from the downloadable lab folder; or open the same notebook in Google Colab.
Steps
Step 1
- Do
- Run the setup and freeze the five-message logical-time experiment.
- You will see
- The notebook states the seed, message count, simulation boundary and application acceptance rule.
- Why it matters
- Explicit assumptions keep simulated behavior separate from a packet capture.

Step 1 · Python 3 in your browser (JupyterLite); numbered callout added to a real capture. Enlarge screenshot (new tab) Step 2
- Do
- Inject one UDP loss and one reorder event.
- You will see
- The arrival table shows D4 missing and D3 arriving before D2.
- Why it matters
- UDP preserves datagram boundaries but does not promise delivery or order.

Step 2 · Python 3 in your browser (JupyterLite); numbered callout added to a real capture. Enlarge screenshot (new tab) Step 3
- Do
- Apply a sequence gate to the UDP arrivals.
- You will see
- D3 is held until D2 arrives, while D5 remains held because D4 is absent.
- Why it matters
- Transport receipt and application acceptance are different events.

Step 3 · Python 3 in your browser (JupyterLite); numbered callout added to a real capture. Enlarge screenshot (new tab) Step 4
- Do
- Model TCP recovery of the missing fourth message.
- You will see
- The table delivers all five messages and records one retransmission.
- Why it matters
- TCP repairs the ordered byte stream before exposing later bytes.

Step 4 · Python 3 in your browser (JupyterLite); numbered callout added to a real capture. Enlarge screenshot (new tab) Step 5
- Do
- Measure head-of-line delay for D5.
- You will see
- D5 waits 48 logical milliseconds behind retransmitted D4.
- Why it matters
- Ordered delivery can add latency even when later bytes already arrived.

Step 5 · Python 3 in your browser (JupyterLite); numbered callout added to a real capture. Enlarge screenshot (new tab) Step 6
- Do
- Run a bounded CoAP-style confirmable retry.
- You will see
- Two attempts produce one accepted action through a duplicate cache.
- Why it matters
- Retry ownership and idempotency are application concerns above UDP.

Step 6 · Python 3 in your browser (JupyterLite); numbered callout added to a real capture. Enlarge screenshot (new tab) Step 7
- Do
- Review the model limits and deployment decision.
- You will see
- The final trace names omitted kernel, congestion, radio and timing behavior.
- Why it matters
- A simulation explains mechanisms but cannot replace testing the actual path.

Step 7 · Python 3 in your browser (JupyterLite); numbered callout added to a real capture. Enlarge screenshot (new tab)
Chapter checks
These questions refer to the chapter’s examples. Use the return links to review their answers.
A learner says TCP is like a phone call, so the receiver must understand every application message. What should the reviewer clarify?
Return to the chapter’s knowledge checkA cold-room cloud service opens a TCP connection to the gateway and sends a compressor-setpoint command, then claims the compressor accepted the new state. What is the best review response?
Return to the chapter’s knowledge check