Networks — quick review
Agree on a message format
Two friends pass notes across a room through other people's hands.
A protocol is an agreed set of rules. In this unit's card protocol every data card holds, in order, To, From, Piece (a number of a total) and Data (from 1 to 4 characters); a card that breaks the format is not used.
List the fields the protocol requires, in order.
For each data card, check that every field is there.
Check that the fields are in the agreed order: To, From, Piece, Data.
Check the Piece field: a number from 1 up to the total, written as a number of the total.
Check the Data field: at least 1 and no more than 4 characters.
Mark the card as following the protocol only when every check passes.
A card that leaves out the total, Piece 2 instead of Piece 2 of 3, breaks the protocol, and the receiver cannot learn the total from that card. Keep both numbers.
A format that only one side knows is not a protocol. If Ana changes the data length to 5 characters without telling Kai, Kai's checks reject her cards.
Split a message into numbered pieces
A long freight train blocks a line for a whole day.
To send a message with the card protocol, cut it into pieces of 4 characters from the left, the last piece holding the 1 to 4 characters left over, and number the pieces from 1 to N, where N is the length divided by 4 and rounded up. Every card carries To, From, its number of N and its data.
Count the characters of the message, spaces and punctuation included.
Count the full groups of 4 characters, and add one more card if any characters are left over: that is N, the number of pieces.
Cut the message into pieces of 4 characters from the left; the last piece takes what is left.
Write one card for each piece, with To, From, its number of N and its data.
Check that joining the data of cards 1 to N in order gives back the message.
Leaving spaces and punctuation out of the count can give the wrong number of pieces: MEET-AT-NOON. counted without its period has 12 characters and gets 3 cards instead of 4. Every character is part of the message.
Numbering from 0 on some cards and from 1 on others breaks the agreement. The card protocol numbers from 1 to N.
Reassemble pieces arriving out of order
Printed pages that say Page 2 of 11 can be put back in order however the pile was dropped.
The receiver places each usable card in the slot of its piece number when that slot is empty, whatever the order of arrival, and reads the data of slots 1 to N in order once all N slots are filled; an empty slot means no usable card for that piece has arrived yet.
Check each arriving card against the protocol. Read the total on the first usable data card and lay out that many empty slots.
Put each usable card into the slot of its piece number if that slot is empty; put a card that fails the check aside.
After each card, list the slots still empty.
When no slot is empty, read the data of the slots from 1 to N.
If a slot stays empty, the message is not complete; do not guess its data.
Joining pieces in the order they arrive gives NOONMEET-AT- for the arrivals 3, 1, 2. Place by number.
Reading the message while a slot is empty gives a message with a hole in it. Wait for every slot; the next lesson shows how the sender sends a missing piece again.
Use acknowledgments in a paper protocol
A teacher who gets no answer says a name again.
In the card protocol, which carries one message at a time, the receiver sends ACK n for each usable piece n, and the sender keeps a list of pieces not yet acknowledged, removes a piece when its acknowledgment arrives, and sends a piece again when its time runs out. The sender knows every piece has arrived when every piece has been sent and its list is empty; the receiver may hold them all sooner.
Write each piece on the sender's list of pieces sent and not yet acknowledged, then send it and start its wait.
On the receiver's side, check each card against the protocol, place it in its slot as in the last lesson (a slot already filled keeps its first card, as the next lesson shows), and send
ACK nfor each usable card.For each acknowledgment that reaches the sender, cross its piece off the list.
When a piece's wait runs out and the piece is still on the list, send it again and start its wait again.
Stop when every piece has been sent and the sender's list is empty.
Waiting forever for an answer stalls the whole message. Without a timeout, a lost piece is never sent again.
Acknowledging a card before checking it defeats the purpose. An acknowledgment says the piece arrived and is usable; a card that fails the format checks is not acknowledged. The checks cannot catch every change: NOON turned into SOON on the way still passes them.
Explain a duplicate request
A reply can be lost on the way, as a request can.
When a lost acknowledgment leaves a piece on the sender's list as its wait runs out, the sender sends it again; if that copy arrives, the receiver gets a duplicate. In the card protocol the receiver recognizes a duplicate because the slot of its number is already filled, keeps the copy it has, and sends the acknowledgment again.
When a card arrives, check it against the protocol; a card that breaks it is put aside without an acknowledgment.
For a usable card, look at the slot of its number.
If the slot is empty, place the card there and send
ACK n.If the slot is filled, the card is a duplicate: leave the slot as it is and send
ACK nagain.On the sender's side, cross the piece off at the first
ACK nand ignore any later one.
Treating a duplicate as a new piece breaks the message. Appending the second -AT- would give MEET-AT-NOON-AT-. Place by number, and a filled slot stays as it is.
Ignoring a duplicate without acknowledging it again can leave the sender waiting: if no acknowledgment reaches it, its time runs out again and it keeps resending. Answer every usable copy.