1 · TCP segment, sequence and ACK numbers, retransmission ★
Slides 3-44 → 3-56 · HW4 P26, P27 · Sample midterm 1.3, Problem 2
TCP overview (3-44)
- Point-to-point: one sender, one receiver. No multicast.
- Reliable, in-order byte stream: no "message boundaries". TCP numbers bytes, not messages.
- Full duplex: data flows both ways in the same connection. MSS = maximum segment size (application data per segment, header not counted).
- Cumulative ACKs and pipelining: many segments in flight. Congestion control and flow control set the window size.
- Connection-oriented: handshaking (exchange of control messages) sets up sender and receiver state before any data.
- Flow controlled: the sender will not overwhelm the receiver.
Segment structure (3-45)
|<------------------- 32 bits ------------------->| | source port # (16) | dest port # (16) | | sequence number (32) | | acknowledgement number (32) | |hlen(4)|unused|C|E|U|A|P|R|S|F| receive window(16)| | checksum (16) | urg data pointer (16) | | options (variable length) | | application data (variable length) |
| Field | Size | Meaning |
|---|---|---|
| Source / dest port | 16 bits each | Multiplexing / demultiplexing |
| Sequence number | 32 bits | Byte-stream number of the first data byte in this segment |
| Acknowledgement number | 32 bits | Seq # of the next byte expected from the other side (valid when A = 1) |
| Header length | 4 bits | Header length in 32-bit words. 5 words = 20 bytes minimum; max 15 words = 60 bytes |
| C, E | 1 bit each | Congestion notification (ECN) |
| U (URG) | 1 bit | Urgent data present; urg pointer marks its end (rarely used) |
| A (ACK) | 1 bit | "This is an ACK": the ACK field is valid |
| P (PSH) | 1 bit | Push data up to the app now (rarely used) |
| R (RST), S (SYN), F (FIN) | 1 bit each | Connection management: reset, setup, teardown |
| Receive window (rwnd) | 16 bits | Flow control: # bytes the receiver is willing to accept |
| Checksum | 16 bits | Internet checksum, same as UDP |
| Urg data pointer | 16 bits | Last byte of urgent data |
| Options | variable | MSS negotiation, window scale, timestamps |
- Header size: 2+2+4+4+2+2+2+2 = 20 bytes without options. Compare UDP's 8 bytes.
- Disconnect bit (sample 1.3): set FIN = 1 to close a connection.
Sequence numbers and ACKs (3-46, 3-47)
- Sequence number = byte-stream "number" of the first byte in the segment's data (3-46). It counts bytes, not segments.
- Next seq # = this seq # + number of data bytes in this segment.
- ACK number = seq # of the next byte expected from the other side.
- Cumulative ACK: ACK = n means "I have every byte up through n − 1".
- Piggybacking: an ACK can ride on a data segment going the other way, as in the telnet example.
- Initial sequence number is chosen randomly at connection setup, not 0. Problems give you a starting number.
- Out-of-order segments: the TCP spec doesn't say what the receiver does with them; it's up to the implementor. In practice the receiver buffers them and keeps ACKing the first missing byte.
Simple telnet scenario (3-47)
Host A Host B
user types 'C'
---- Seq=42, ACK=79, data='C' ---->
B ACKs 'C', echoes 'C' back
<--- Seq=79, ACK=43, data='C' -----
A ACKs the echo
---- Seq=43, ACK=80 (no data) ---->
- B's seq = the ACK A just sent (79): the byte A expects next from B.
- B's ACK = A's seq + 1 byte = 43.
TCP sender, simplified (3-51, 3-52)
- Data from app: make a segment with seq # = NextSeqNum, send it, NextSeqNum += length(data). Start the timer if it isn't already running.
- One timer, conceptually for the oldest unACKed segment. Expiration interval = TimeoutInterval.
- Timeout: retransmit only the not-yet-ACKed segment with the smallest seq #, then restart the timer.
- ACK y received: if y > SendBase, set SendBase = y. Restart the timer if unACKed segments remain, else stop it.
Three retransmission scenarios (3-53, 3-54)
| Scenario | What happens | Outcome |
|---|---|---|
| Lost ACK | A sends Seq=92, 8 bytes. B's ACK=100 is lost. A times out. | A resends Seq=92, 8 bytes. B already has it, discards the duplicate data and resends ACK=100. SendBase = 100. |
| Premature timeout | A sends Seq=92 (8 B) and Seq=100 (20 B). ACK=100 and ACK=120 are both on their way, but A's timer for 92 fires first. | A resends Seq=92 only. B replies with cumulative ACK=120. A does not resend Seq=100: ACK=120 covers it. |
| Cumulative ACK covers lost ACK | A sends Seq=92 (8 B) and Seq=100 (20 B). ACK=100 is lost; ACK=120 arrives before the timeout. | No retransmission. ACK=120 confirms bytes 92–119. A goes on to send Seq=120, 15 bytes. |
TCP ACK generation (3-55, RFC 1122, RFC 2581 → RFC 5681)
| Event at receiver | Receiver action |
|---|---|
| In-order segment with expected seq #. All earlier data already ACKed. | Delayed ACK: wait up to 500 ms for the next segment. If none comes, send the ACK. |
| In-order segment with expected seq #. One other in-order segment has an ACK pending. | Immediately send one cumulative ACK covering both. |
| Out-of-order segment, seq # higher than expected. Gap detected. | Immediately send a duplicate ACK carrying the seq # of the next expected byte. |
| Segment that partially or completely fills the gap. | Immediately send an ACK, if the segment starts at the lower end of the gap. |
Fast retransmit (3-56)
- If the sender gets 3 additional ACKs for the same data ("triple duplicate ACKs"), it resends the unACKed segment with the smallest seq # right away.
- Why: duplicate ACKs mean later segments arrived but one is missing, so that segment is likely lost. Don't wait for the timeout.
- Counting: the original ACK plus 3 duplicates = 4 identical ACKs in total.
How to solve: max file size and transmit time (HW4 P26)
- Max bytes = number of distinct sequence numbers = 2(bits in seq field). MSS doesn't matter: seq numbers count bytes.
- # segments = ⌈L / MSS⌉ (round up: the last segment can be partial).
- Header bytes = # segments × header bytes per segment.
- Total bytes on the wire = L + header bytes. Time = total bits / link rate.
Q (HW4 P26): Host A transfers an enormous file of L bytes to Host B. Assume an MSS of 536 bytes. The TCP sequence number field is 4 bytes.
- (a) What is the maximum value of L such that TCP sequence numbers are not exhausted?
- (b) For the L from (a), how long does it take to transmit the file? A total of 66 bytes of transport, network and data-link header is added to each segment before it goes out over a 155 Mbps link. Ignore flow and congestion control, so A sends segments back to back, continuously.
(a) L_max = 2^32 = 4,294,967,296 bytes ≈ 4.29 GB (4 GB also accepted)
(b) segments = ⌈4,294,967,296 / 536⌉ = ⌈8,012,998.69⌉ = 8,012,999
headers = 8,012,999 × 66 = 528,857,934 bytes
total = 4,294,967,296 + 528,857,934 = 4,823,825,230 bytes ≈ 4.824 × 10^9 bytes
bits = 4,823,825,230 × 8 = 38,590,601,840 bits
time = 38,590,601,840 / 155 × 10^6 ≈ 249 s
Answer: (a) 232 ≈ 4.29 GB. (b) ≈ 249 seconds. Matches the official solution.
How to solve: seq/ACK/ports in an exchange (HW4 P27)
- Next segment's seq # = previous seq # + previous segment's data bytes.
- Ports on data segments: as given. On ACKs: swap source and destination.
- ACK # = first byte B still needs. In order: last seq + its length. Out of order (gap): the start of the gap, which is the ACK B already sent.
- Lost ACK followed by a timeout: A resends the oldest unACKed segment only. A later cumulative ACK covers everything before it.
Q (HW4 P27): Host A and B are communicating over TCP. B has received all bytes from A through byte 126. A sends two segments back to back, with 80 and then 40 bytes of data. First segment: seq 127, source port 302, dest port 80. B sends an ACK whenever it receives a segment from A.
- (a) In the second segment from A to B, what are the seq #, source port and dest port?
- (b) If the first segment arrives before the second, what are the ACK #, source port and dest port in the ACK of the first arriving segment?
- (c) If the second segment arrives before the first, what is the ACK # in the ACK of the first arriving segment?
- (d) The two segments arrive in order. The first ACK is lost and the second ACK arrives after the first timeout interval. Draw a timing diagram showing these segments and all other segments and ACKs sent (no further loss). Give the seq # and data bytes of each segment and the ACK # of each ACK you add.
(a) 2nd segment: seq = 127 + 80 = 207, source port 302, dest port 80
(b) 1st segment arrives first → ACK = 127 + 80 = 207,
source port 80, dest port 302 (swapped)
(c) 2nd segment (bytes 207–246) arrives first → gap at 127
→ ACK = 127 (still waiting for byte 127 onwards)
(d) Both arrive in order. The first ACK is lost. The second ACK arrives after the first timeout.
Host A Host B
| --- Seq=127, 80 bytes --------------> |
| --- Seq=207, 40 bytes --------------> |
timeout | X<------------- ACK=207 ---- | (lost)
interval | ...ACK=247 ------------ | (sent, still in transit)
expires | --- Seq=127, 80 bytes --------------> | (retransmit oldest unACKed)
| <-- ACK=247 arrives (after timeout) - |
| <-- ACK=247 ------------------------- | (B already has 127–246, re-ACKs 247)
- A retransmits only Seq=127, the oldest unACKed segment. It does not resend Seq=207.
- The late ACK=247 covers bytes 127–246, so nothing else is resent.
- B's reply to the duplicate is ACK=247, not 207: it already holds both segments.
How to solve: echo reply seq/ACK (sample Problem 2)
- Reply seq = the ACK number in the packet you are answering.
- Reply ACK = their seq + their data length in bytes.
Q (sample midterm Problem 2): In a simple TCP-based application, the client sends a TCP packet (seq=20, ACK=46, data='c') to the server, and the server sends the reply (seq = ?, ACK = ?, data='c').
- Fill in the sequence number and ACK number of the server's reply.
reply seq = client's ACK = 46 reply ACK = client's seq + 1 byte = 20 + 1 = 21 → (seq = 46, ACK = 21, data = 'c')
Same pattern as the telnet slide (42/79 → 79/43).
• ACK = next byte expected, not the last byte received. Bytes 127–206 received → ACK 207.
• Seq numbers count bytes. Seq 127 + 80 bytes → next seq 207, not 128.
• Swap the ports on the ACK direction. The ACK from B has source 80, dest 302.
• Out-of-order arrival: the ACK is the start of the gap, which repeats the last ACK. Don't ACK past a hole.
• On timeout TCP resends one segment (smallest unACKed seq #), not the whole window like GBN.
• Fast retransmit needs 3 duplicate ACKs, which is 4 identical ACKs in total.
• P26: MSS is a distractor for part (a). In part (b), round segments up and convert bytes to bits (×8).
• Header minimum is 20 bytes. Header length is counted in 32-bit words.
Quick check
1. How big are the seq #, ACK #, and receive window fields? What's the minimum TCP header size?
Seq # 32 bits, ACK # 32 bits, receive window 16 bits. Minimum header = 20 bytes (no options).2. Which bit is set to 1 to disconnect? (sample 1.3) Which bit opens a connection?
FIN closes the connection. SYN opens it. RST aborts it.3. P27 variant: B has bytes through 300. A sends 50 bytes then 70 bytes. First seq 301, source port 4000, dest port 443. (a) Seq/ports of segment 2? (b) ACK # and ports if segment 1 arrives first? (c) ACK # if segment 2 arrives first?
(a) seq = 301 + 50 = 351, source 4000, dest 443.(b) ACK = 301 + 50 = 351, source 443, dest 4000.
(c) Gap at 301 → ACK = 301.
4. Same setup as #3. Both arrive in order, the first ACK is lost, and the second ACK arrives after the first timeout. List everything sent.
A→B Seq=301, 50 bytes A→B Seq=351, 70 bytes B→A ACK=351 (lost) B→A ACK=421 (arrives after the timeout) timeout → A→B Seq=301, 50 bytes (oldest unACKed only) B→A ACK=421 (B already has 301–420)
5. A sends three 100-byte segments starting at seq 500. The second is lost. Which ACKs does B send, and when does A resend?
Seg 500 arrives → ACK 600. Seg 700 arrives out of order (gap) → duplicate ACK 600 immediately. Only one duplicate, so no fast retransmit; A resends Seq=600 when the timer expires. When Seq=600 arrives it fills the gap → immediate ACK 800.6. Sample P2 variant: client sends (seq=100, ACK=300, data='x'). Server echoes 'x'. Fill in the reply.
seq = client's ACK = 300. ACK = 100 + 1 = 101. Reply: (seq=300, ACK=101, data='x').7. Client sends (seq=70, ACK=12, data='hello'). Server echoes 'hello'. Give the reply, then the client's next pure ACK.
Reply: seq = 12, ACK = 70 + 5 = 75. Client's ACK of the echo: seq = 75, ACK = 12 + 5 = 17.8. P26 variant: 4-byte seq field, MSS = 1460 bytes, 40 bytes of headers per segment, 1 Gbps link. Max file size and transmit time?
L_max = 2^32 = 4,294,967,296 bytes (MSS irrelevant) segments = ⌈4,294,967,296 / 1460⌉ = ⌈2,941,758.42⌉ = 2,941,759 headers = 2,941,759 × 40 = 117,670,360 bytes total = 4,412,637,656 bytes × 8 = 35,301,101,248 bits time = 35,301,101,248 / 10^9 ≈ 35.3 s
9. If the seq field were only 16 bits, what's the largest file before seq numbers wrap?
216 = 65,536 bytes, whatever the MSS.10. A sends Seq=92 (8 B) and Seq=100 (20 B). ACK=100 is lost, ACK=120 arrives before the timer expires. What does A retransmit?
Nothing. ACK=120 is cumulative and confirms bytes 92–119. (Cumulative ACK covers the lost ACK, 3-54.)11. An in-order segment arrives and all earlier data is already ACKed. What does the receiver do?
Delayed ACK: wait up to 500 ms for the next in-order segment. If it arrives, send one cumulative ACK for both right away. If not, send the ACK when the 500 ms is up.12. What triggers fast retransmit, and what gets resent?
3 duplicate ACKs (4 identical ACKs). Resend the unACKed segment with the smallest seq # without waiting for the timeout.← prev · all topics · next →