The transport layer delivers application data reliably over a channel that is
not. Today's sender and receiver are that layer in miniature: the rdt protocols of
Chapter 3, not TCP.
Today
Today
GivenRun rdt1.0, paste its failing line into Q0.
BuildImplement rdt2.0.
BreakSee what a corrupted reply does to it.
FixRepair rdt2.1.
First: accept, clone, python3 check.py.
After you push submit/1, you can leave.
Recap
rdt1.0
Questiond2 arrives corrupted. What happens?
Recap
rdt2.0
In colour: the four arrows you write in rdt2.py. Corrupt → NAK,
intact → deliver and ACK; NAK → resend, ACK → next segment.
Recap
rdt2.0: corrupted data
Recap
rdt2.0: corrupted reply
QuestionShould the sender resend, or move on?
rdt2.0 has no arrow for a corrupted reply. Suppose it guesses.
Recap
rdt2.0: corrupted reply, guess ACK
Recap
rdt2.0: corrupted reply, guess NAK
Neither guess is safe. The receiver cannot tell a copy from new data.
Recap
Sequence numbers
the number it expects
New data: deliver it, send ACK, expect the other number.
the other number
A copy: send ACK again, do not deliver it.
corrupted
Send NAK, as in rdt2.0.
Recap
rdt2.1: corrupted reply
Every byte delivered, once. Resending is safe now: the receiver can tell a copy from new data.
Recap
Which protocol survives which channel
The channel…
rdt1.0
rdt2.0
rdt2.1
delivers everything intact
yes
yes
yes
corrupts data packets
no
yes
yes
corrupts ACKs and NAKs too
no
no
yes
Every cell is one command: python3 test.py <protocol> <channel>
The lab
The simulator
You write the sender and the receiver. The simulator delays and corrupts;
no real network, and the same seed always gives the same run.
The lab
The API
On the worksheet
In the code
event rdt_send(data)
on_tick(self, now), when state == WAIT_FOR_CALL
given
event rdt_rcv(rcvpkt)
rdt_rcv(self, rcvpkt, now), in Sender and in Receiver
you write
the state bubbles
self.state: WAIT_FOR_CALL or WAIT_FOR_ACK_OR_NAK
the actions
the same names: make_pkt, udt_send, extract, deliver_data
make_pkt(seq, flags, data) # build a packet; seq = 0 until rdt2.1
self.udt_send(pkt) # put it on the channel
corrupt(rcvpkt) # failed its checksum? notcorrupt(rcvpkt): the opposite
extract(rcvpkt) # -> (seq, flags, data)
isACK(rcvpkt) isNAK(rcvpkt) # an intact ACK / NAK?
self.deliver_data(data) # receiver only: hand data to the application
self.sndpkt # sender: the packet in flight
self.segments, self.index # sender: the data, chopped; which segment you are on
self.state # sender: WAIT_FOR_CALL or WAIT_FOR_ACK_OR_NAK
The lab
Testing and debugging
test.py
python3 test.py rdt2 corrupt-data — the packets. Use it to see what went wrong.
check.py
python3 check.py 2 — pass or fail per case. The same checks the grader runs.
editrdt2.py→checkpython3 check.py 2→readthe test.py line under the FAIL→fixthe first packet that is not what you meant→repeatuntil every case is ok
$ python3 check.py 2
Part 2 — rdt2.0 — packets get corrupted [10 points]
ok clean channel
ok 20% of packets corrupted
FAIL 40% corrupted: never finished — stuck waiting for a reply
see the packets: python3 test.py rdt2 corrupt-data --rate 0.4 --seed 16 --bytes 1000
…
-> 2/5 cases, 4/10 points
Reference
Reference
The rest is for later, while you work.
rdt1.0, rdt2.0, rdt2.1: the complete state machines
What a packet capture can and cannot tell you
Reading a test.py timeline
Submitting
Reference
rdt1.0: the complete machines
Assumes the channel delivers every packet intact: no checksum, no reply, nothing to
resend. One state each.
Reference
rdt2.0: the complete machines
Receiver: corrupt → NAK; intact → deliver, ACK. Sender: NAK → resend;
ACK → next segment. Its limit: a corrupted reply has no arrow, so the sender can only guess.
Reference
rdt2.1 sender
Four states: which number it is sending, and whether it is waiting. Corrupted reply or
NAK: always resend. Intact ACK: the other row.
Reference
rdt2.1 receiver
Two states: which number it expects. The expected number is new data: deliver, ACK,
switch. The other number is a copy: ACK it again, do not deliver it. Corrupted: NAK.
Reference
Reading the timeline
$ python3 test.py rdt21 corrupt-replies --rate 0.2 --seed 19 --bytes 1000
rdt2.1 on corrupt-replies: 20% of all packets are corrupted — ACKs and NAKs too
seed 19: LOST DATA — the application received 800 of 1000 bytes; the rest was lost, silently
time direction bytes what happened
5 sender -> receiver 217 delivered at 30 ms DATA seq=0 len=200
30 receiver -> sender 17 delivered at 55 ms ACK seq=0
55 sender -> receiver 217 delivered at 80 ms DATA seq=1 len=200
80 receiver -> sender 17 delivered at 105 ms ACK seq=1
105 sender -> receiver 217 corrupted, delivered at 130 ms DATA seq=0 len=200
130 receiver -> sender 17 corrupted, delivered at 155 ms NAK seq=0
155 sender -> receiver 217 delivered at 180 ms DATA seq=1 len=200 ← moved on
Line 130: a garbled NAK, and the sender moves on. DATA 0 is lost.
Verdicts: ok · CORRUPTED DATA · LOST DATA · DUPLICATED
· STALLED · CRASHED
Reference
What can a packet capture tell us?
one capture shows
which packets, in what order, when
DATA, ACK, NAK, and their sequence numbers
a resend, if the numbers show it
both captures show
whether a packet arrived, and how long it took
whether its bytes changed on the way
whether your ACK reached the sender intact
no capture shows
whether the receiver called deliver_data
whether the application got every byte, or a byte twice
what the sender or receiver decided inside
QuestionThe same DATA packet appears twice in a capture. Did the application receive it twice?
No. A receiver that recognises the resend discards it without delivering; one that does not
delivers it again. The capture is identical either way. Captures show what happened on the wire, not what happened inside the application.
Submitting
Submitting
$ python3 check.py
…
What you hand in from test.py [10 points]
ok answers.md Q0: the rdt1.0 LOST DATA line is there 2/2
ok rdt2-flaw.txt: the output of test.py rdt2 corrupt-replies 2/2
ok answers.md Q1: written (36 words) 3/3
FAIL answers.md Q2: 4 words — write at least 15 0/3
-- answers.md Q3: written (read by hand)
Score: 22 / 25 — the same checks run when you push submit/N
Hand in
rdt2.py · rdt21.py
· rdt2-flaw.txt · answers.md
Given 2 · Build 10 · Break 8 · Fix 5 = 25. Q3 is read by hand.