Reordering packets at the destination

Tip: Choose Save as PDF in the print dialog to download. Use A4 paper size.

Reordering packets at the destination

Name:
Date:
Class:

Quick Questions

Shade in the A or B circle for each question.

1. When does the receiving device put the packets back into the correct order?
A As soon as the first packet arrives
B Once the last packet has arrived
2. What does the receiving device use to decide the correct order of the packets?
A The packet numbers in the headers
B The order in which the packets arrived
3. Packet 3 arrives before packet 2. What happens at the destination?
A Packet 3 is treated as the second part of the message because it arrived second
B Packet 3 is kept until all packets arrive, then the packets are sorted by number
4. After the packets are in the correct order, what is joined together to rebuild the message?
A The payloads
B The routers
5. Which statement about reordering packets is correct?
A The packet number is read from the packet header
B The packet number is read from the packet trailer

Match the Pairs

Draw a line connecting each item on the left to its match on the right.

Left columnRight column
1reordering packets Amessage = payload1 + payload2 + payload3
2packet number (in header) Bif all_packets_arrived: reorder(packets)
3The receiving device waits until the last packet has arrived before it puts the packets in order CReordering happens once the last packet has arrived, not while packets are still arriving, because the device cannot sort the full set until it has all of them.
4Once the packets are in order, the payloads are joined together to rebuild the original message DThe value the receiving device reads to decide where each packet belongs in the sequence
5Packets arrive as 3, 1, 2 so the message is rebuilt as 3, 1, 2 EAfter the last packet arrives, the receiving device puts the packets back into the correct order and rebuilds the message
6Reorder each packet the moment it arrives, before the last packet FThe packets were joined in the order they arrived, but they should be reordered by packet number first (1, 2, 3).

Definitions

reordering packets

Fill in the Blanks

Complete each line of code by filling in the missing parts.

1.
IF lastPacketArrived = TRUE THEN ____ packets BY packetNumber ENDIF
2.
IF lastPacketArrived = TRUE THEN SORT packets BY ____________ ENDIF
3.
WHILE lastPacketArrived = _____ RECEIVE packet ENDWHILE
4.
FOR EACH packet IN sortedPackets message ← message + packet._______ NEXT packet
5.
IF packet1.number _ packet2.number THEN SWAP packet1, packet2 ENDIF

Spot the Error

Shade in the letter of the line that contains an error.

Question 1
A REORDER as each packet arrives
B READ number from each header
C SORT packets BY number
D JOIN payloads into message
Question 2
A WHILE lastPacketArrived
B STORE packet
C ENDWHILE
D SORT packets BY packetNumber
Question 3
A WAIT for last packet
B SORT packets BY packetNumber
C FOR EACH p IN packets
D ADD p.header TO message
E NEXT p
Question 4
A RECEIVE all packets
B READ number from each payload
C SORT packets BY number
D JOIN payloads into message
Question 5
A Packets arrive as 2, 3, 1
B Last packet has now arrived
C Sorted order is 2, 3, 1
D Message can now be rebuilt

Answer Key

Reordering packets at the destination
Section A: Quick Questions
Q1
B — Once the last packet has arrived
Q2
A — The packet numbers in the headers
Q3
B — Packet 3 is kept until all packets arrive, then the packets are sorted by number
Q4
A — The payloads
Q5
A — The packet number is read from the packet header
Section B: Match the Pairs
Q1
reordering packets → After the last packet arrives, the receiving device puts the packets back into the correct order and rebuilds the message
Q2
packet number (in header) → The value the receiving device reads to decide where each packet belongs in the sequence
Q3
The receiving device waits until the last packet has arrived before it puts the packets in order → if all_packets_arrived: reorder(packets)
Q4
Once the packets are in order, the payloads are joined together to rebuild the original message → message = payload1 + payload2 + payload3
Q5
Packets arrive as 3, 1, 2 so the message is rebuilt as 3, 1, 2 → The packets were joined in the order they arrived, but they should be reordered by packet number first (1, 2, 3).
Q6
Reorder each packet the moment it arrives, before the last packet → Reordering happens once the last packet has arrived, not while packets are still arriving, because the device cannot sort the full set until it has all of them.
Section C: Definitions
Q1
reordering packets — After the last packet arrives, the receiving device uses the packet numbers in the headers to put the packets in the right order and joins the payloads to rebuild the message.
Section D: Fill in the Blanks
Q1
IF lastPacketArrived = TRUE THEN SORT packets BY packetNumber ENDIF
Q2
IF lastPacketArrived = TRUE THEN SORT packets BY packetNumber ENDIF
Q3
WHILE lastPacketArrived = FALSE RECEIVE packet ENDWHILE
Q4
FOR EACH packet IN sortedPackets message ← message + packet.payload NEXT packet
Q5
IF packet1.number > packet2.number THEN SWAP packet1, packet2 ENDIF
Section E: Spot the Error
Q1
A — The packets are only put in order after the last packet has arrived, not as each one arrives. Line 1 should wait until the last packet arrives.
Q2
A — The loop should keep storing packets while the last packet has NOT yet arrived. Without NOT, it would not collect the packets properly.
Q3
D — The message is rebuilt by joining the payloads, which hold the actual data. The header only holds information such as the packet number. It should be p.payload.
Q4
B — The packet number is stored in the packet header, not in the payload. The payload holds the data. It should read the number from each header.
Q5
C — Sorting by packet number puts the packets in the order 1, 2, 3. The line 2, 3, 1 is just the order they arrived in.