TCP/IP Exercises: Analyzing TCP Connections, Losses and Performance
Twelve graded exercises on real TCP traces: handshake RTT, window scaling, bandwidth-delay product, slow start, throughput, a lost segment with SACK and fast retransmit, ss -ti, the RTO, receive-window limits, a zero window and an RST abort.
kvi5hnuCode Sprout team member16 min readOn this page
The last exercise set is about TCP performance: reading real traces to find out why a transfer was as fast or as slow as it was. It practices Parts 10 to 12 of the course: the handshake and options, retransmission, flow control and congestion control.
All the traces come from one lab setup. The server (198.51.100.10) sends 1,000,000 bytes to the client (192.0.2.10) on each connection. The router between them adds 20 ms of delay in each direction, for a 40 ms round-trip time, and limits the path toward the client to 20 Mbit/s. Both hosts run Linux with CUBIC congestion control and offloads turned off, so the captures show real on-the-wire segments. Captures were taken on the server, the sending side. Four transfers were captured:
- clean: nothing goes wrong.
- loss: the router drops exactly one full-size data segment.
- zwin: the client reads slowly, 8 KB every 50 ms, with a 64 KB receive buffer.
- rst: the client reads 1,000 bytes and then closes the socket.
Here's how long each took, as measured by the client:
port 9000: received 1000000 bytes in 0.568 s
port 9001: received 1000000 bytes in 0.889 s
port 9002: received 1000000 bytes in 6.532 s
Each transfer used its own server port: 9000 is clean, 9001 is loss and 9002 is zwin. The rst transfer never completed, so it has no line here.
If you repeat this on your own machines, the times and frame numbers will differ, and on a busy host the RTT will come out a little higher than the emulated 40 ms (as it did in places here). The shapes are what to look for. Every calculation in the solutions was checked in the lab with Python.
Level 1: the connection and the path
Exercise 1: the handshake
1 0.000000 192.0.2.10 → 198.51.100.10 TCP 74 33230 → 9000 [SYN] Seq=0 Win=64240 Len=0 MSS=1460 SACK_PERM TSval=3383509744 TSecr=0 WS=128
2 0.000038 198.51.100.10 → 192.0.2.10 TCP 74 9000 → 33230 [SYN, ACK] Seq=0 Ack=1 Win=65160 Len=0 MSS=1460 SACK_PERM TSval=1068162984
3 0.055604 192.0.2.10 → 198.51.100.10 TCP 66 33230 → 9000 [ACK] Seq=1 Ack=1 Win=64256 Len=0 TSval=3383509861 TSecr=1068162984
- The capture was taken on the server. Why does the SYN-ACK follow the SYN after only microseconds, while the ACK arrives tens of milliseconds later?
- What does that gap measure?
Solution
- The server answers a SYN immediately, so the SYN-ACK leaves microseconds after the SYN arrives. The SYN-ACK then has to travel to the client and the ACK back, which is a full round trip.
- On the server, SYN-ACK to ACK is one round-trip time, here about 55 ms: the 40 ms of emulated delay plus processing time on a busy lab host. On the client, the same measurement is SYN to SYN-ACK. The general rule: measure RTT as the time from a packet you can see leaving to the reply that it caused, from the point of view of the capture (article 64).
Exercise 2: window scaling
Both SYNs carry WS=128 (the SYN-ACK's listing above is cut short before its timestamp echo and window scale options). The client's ACK in frame 3 shows Win=64256. What value is actually in the 16-bit window field of that ACK?
Solution
WS=128 means a shift count of 7 (2⁷ = 128). After the handshake, every window field is multiplied by 128. tshark shows the result of that multiplication, so the raw field is 64256 / 128:
raw window field = 502 ; 502 x 2^7 = 64256
That's why a capture that misses the handshake shows tiny, wrong windows: without the SYNs, tshark can't know the scale factor (article 60). Wireshark marks those windows "window size scaling factor: -1 (unknown)".
Exercise 3: the bandwidth-delay product
What's the bandwidth-delay product of this path, in bytes and in full-size segments (MSS 1,448 bytes, because both sides use timestamps)? What does it mean for the sender's congestion window?
Solution
BDP = 20 Mbit/s x 40 ms = 100000 bytes = 69.1 full-size segments
About 100 KB, or 69 segments, must be in flight to keep the 20 Mbit/s link busy for a whole round trip (article 70). With a smaller window, the link sits idle part of each round trip. With a larger window, the extra segments can't go any faster; they wait in the router's queue and make the RTT longer.
Level 2: the clean transfer
Exercise 4: slow start, round by round
This counts the data segments the server sent in each 40 ms interval after its first data segment:
round trip 1: 10 data segments sent
round trip 2: 20 data segments sent
round trip 3: 40 data segments sent
round trip 4: 70 data segments sent
round trip 5: 56 data segments sent
round trip 6: 134 data segments sent
- What's the initial congestion window?
- What pattern do rounds 1 to 4 follow, and why?
- Why does the pattern break after round 4?
Solution
- 10 segments, the standard initial window on Linux (RFC 6928).
- Doubling: 10, 20, 40, then about 80. In slow start, each ACK lets the sender increase its window by one segment, so the window doubles every round trip (article 72):
round 1: cwnd 10 segments, 10 segments sent so far
round 2: cwnd 20 segments, 30 segments sent so far
round 3: cwnd 40 segments, 70 segments sent so far
round 4: cwnd 80 segments, 150 segments sent so far
- Round 4 is where the window passes the path's BDP of about 69 segments (exercise 3). From then on the link is full: the sender's segments queue at the router, ACKs come back at the bottleneck rate, and the counting intervals no longer line up with the sender's rounds. The counts get uneven because ACKs arrive in bursts. Once the queue makes the RTT rise, CUBIC's HyStart can end slow start on its own, and a full queue eventually causes loss; either way the window stops doubling. Counting per round trip is only meaningful while the window is smaller than the BDP.
Exercise 5: throughput
data bytes 1000000, first data 0.0577 s, last data 0.4192 s, average 22.1 Mbit/s
The bottleneck is 20 Mbit/s. Why does the average come out slightly above it? And why did the whole transfer take the time the client measured, rather than 1,000,000 bytes at 20 Mbit/s, which is 0.4 s?
Solution
The average is computed on the server, from its first data segment to its last. In that time it pushed all 1,000,000 bytes into the network, but the last ones were still in the router's queue and on the wire when it finished. The data took longer than that to arrive at the client. Throughput measured at the sender over a short transfer is always a little optimistic.
The client's total time adds the handshake (one RTT), the slow start rounds during which the link isn't yet full, and the final segments' trip to the client. For short transfers, these round trips are a large share of the total, which is why latency, not bandwidth, usually decides how fast a web page loads.
Exercise 6: reading ss -ti
This snapshot of another 1 MB transfer was taken on the server while it was running:
ESTAB 0 102808 198.51.100.10:9000 192.0.2.10:52548
cubic wscale:7,7 rto:250 rtt:49.598/0.85 mss:1448 pmtu:1500 rcvmss:536 advmss:1448 cwnd:33
ssthresh:28 bytes_sent:220096 bytes_acked:172312 segs_out:152 segs_in:114 data_segs_out:152 send 7707408bps
lastrcv:258 pacing_rate 9248840bps delivery_rate 7092704bps delivered:120 busy:256ms unacked:33
rcv_space:14480 rcv_ssthresh:64088 notsent:55024 minrtt:43.18 snd_wnd:321792 rcv_wnd:65280
The first line is the state (ESTAB), the receive queue (0 bytes waiting for the application) and the send queue (102,808 bytes the application has written but the peer hasn't yet acknowledged), then the two endpoints. Below it, wscale:7,7 is the window scale in each direction, cwnd and ssthresh are in segments, unacked counts segments in flight, notsent is data still waiting to be sent, and snd_wnd is the window the receiver last advertised, in bytes.
- What are the smoothed RTT and the minimum RTT? What does the difference mean?
- Check the
sendrate fromcwnd,mssandrtt. ssthreshis set, but there's noretransfield. What happened?- Explain
rto:250.
Solution
rtt:49.598/0.85is the smoothed RTT and its mean deviation;minrtt:43.18is the lowest RTT seen. The extra 6 ms or so is queueing at the router: some of this connection's own segments are waiting there.sendis the rate the congestion window allows: cwnd × MSS / RTT.
cwnd x mss / srtt = 33 x 1448 x 8 / 0.049598 s = 7.71 Mbit/s
That matches send 7707408bps. delivery_rate (about 7.1 Mbit/s) is what's actually being delivered. Both are well below 20 Mbit/s, so at this moment the connection was limited by its congestion window, not by the link.
3. ss shows a retrans counter only when there have been retransmissions. Without one, ssthresh was set by HyStart, CUBIC's delay-based exit from slow start, which sets ssthresh to the current window when the RTT starts rising. HyStart can exit early, as here (ssthresh:28 with cwnd:33): the window then grows only in congestion avoidance, which is why this snapshot shows a much smaller window than the clean transfer reached.
4. Linux computes the RTO as the smoothed RTT plus a variance term with a floor of 200 ms (tcp_rto_min), so with a steady RTT it's about srtt + 200 ms (article 64):
srtt + 200 ms floor = 249.6 ms
Level 3: problems in the trace
Exercise 7: one lost segment
During the loss transfer, the router dropped one data segment. Here's tshark's analysis summary for that capture:
tcp.analysis.retransmission 1 frames
tcp.analysis.fast_retransmission 1 frames
tcp.analysis.spurious_retransmission 0 frames
tcp.analysis.duplicate_ack 18 frames
tcp.analysis.lost_segment 0 frames
And the key frames. Columns: frame, time, source port, sequence number, acknowledgment number, length, SACK left edge, SACK right edge, and tshark's summary:
# retransmitted segment starts at relative seq 56473
73 0.1704 9001 56473 1 1448 [PSH, ACK] Seq=56473 Ack=1 Win=65280 Len=1448 TSval=1068166335 TSecr=3383513160
133 0.2187 48280 1 56473 0 57921 60817 [TCP Dup ACK 128#1] 48280 → 9001 [ACK] Seq=1 Ack=56473 Win=113280 Len=0 TSval=3383513210 TSecr=1068166335
134 0.2187 48280 1 56473 0 57921 62265 [TCP Dup ACK 128#2] 48280 → 9001 [ACK] Seq=1 Ack=56473 Win=113280 Len=0 TSval=3383513211 TSecr=1068166335
135 0.2187 48280 1 56473 0 57921 63713 [TCP Dup ACK 128#3] 48280 → 9001 [ACK] Seq=1 Ack=56473 Win=113280 Len=0 TSval=3383513211 TSecr=1068166335
136 0.2187 9001 56473 1 1448 [TCP Fast Retransmission] 9001 → 48280 [ACK] Seq=56473 Ack=1 Win=65280 Len=1448 TSval=1068166383 TSecr=3383513211
138 0.2237 48280 1 56473 0 57921 68057 [TCP Dup ACK 128#4] 48280 → 9001 [ACK] Seq=1 Ack=56473 Win=113280 Len=0 TSval=3383513213 TSecr=1068166335
- Which segment was lost, and how long after it was sent did the first duplicate ACK arrive?
- What do the SACK blocks tell the server?
- Why did the server retransmit after the third duplicate ACK, and not wait for its retransmission timer?
- Why is
tcp.analysis.lost_segmentzero?
Solution
- The segment starting at relative sequence 56473 (frame 73). The client kept acknowledging 56473, "I still need the byte at 56473", from frame 133 on:
first dup ACK - original send = 48.3 ms; SACK left edge = 57921
48 ms is one round trip: the time for later segments to reach the client and its ACKs to come back. 2. Each duplicate ACK carries a SACK block whose left edge is 57921, the segment just after the missing one, and whose right edge grows as more segments arrive. Together they say exactly which data the client has, so the server knows only one segment is missing (article 66). 3. Three duplicate ACKs (or, with SACK and RACK, the evidence that later data was delivered) make the sender infer a loss and fast retransmit at once (frame 136), about one RTT after the original. Waiting for the RTO would have cost at least 200 ms more. After the loss, CUBIC also cut its congestion window by 30% and had to grow it back. That, plus the round trip spent on recovery, is why this transfer took about 0.3 s longer than the clean one. 4. The capture was on the sender. The lost segment was sent and captured before the router dropped it, so tshark saw no gap in the sequence numbers. In a capture on the receiver, the same loss would show "previous segment not captured" before the later segments. Capture location changes what the analysis flags mean.
Exercise 8: a receive-window limit
The zwin client used a 64 KB receive buffer. Even if it had read fast enough, what's the highest throughput a 64 KiB (64 × 1,024 = 65,536 bytes) window allows on a 40 ms path?
Solution
TCP can't have more unacknowledged data in flight than the receiver's window, so throughput is at most window / RTT:
64 KiB window / 40 ms RTT = 13.1 Mbit/s
That's below the 20 Mbit/s link, so a fast reader with this buffer would still be limited by the window. This is why receive-buffer auto-tuning exists (article 70), and why setting SO_RCVBUF by hand, which turns auto-tuning off for that socket, often makes transfers slower.
Exercise 9: a zero window
Around the first zero window in the zwin capture. Columns: frame, time, source port (9002 is the server), payload length, advertised window, tshark's flag:
231 1.039 9002 len=1448 win=65280
232 1.039 9002 len=1448 win=65280
233 1.039 9002 len=1336 win=65280 [TCP Window Full]
234 1.093 39680 len=0 win=0 [TCP ZeroWindow]
235 1.145 39680 len=0 win=17372 [TCP Window Update]
236 1.145 9002 len=1448 win=65280
237 1.145 9002 len=1448 win=65280
238 1.145 9002 len=1448 win=65280
And how often each event appears in the whole capture:
zero_window 2
zero_window_probe 0
window_update 17
window_full 44
- What do "Window Full" and "ZeroWindow" mean, and who sends each?
- How long did the window stay closed, and what reopened it?
- Why are there no zero window probes?
- Where is the bottleneck in this transfer, and does the measured time fit?
Solution
- Window Full is tshark's note on a sender's segment that fills the receiver's last advertised window: the server can't send more until the window moves. ZeroWindow is a receiver's ACK advertising a window of 0: the client's buffer is full because the application isn't reading fast enough (article 69).
- About 50 ms, from frame 234 to the window update in frame 235. That's the reader's 50 ms sleep: when it read the next 8 KB, the kernel advertised the freed space, and the server immediately sent more.
- The sender starts probing a zero window only when its persist timer expires, which takes at least the RTO, about 200 ms or more. Here the window reopened after 50 ms, before the first probe was due. A reader stalled for seconds would show regular "ZeroWindowProbe" segments with growing intervals.
- The receiving application. It drains 8,192 bytes every 50 ms:
reader drains 163840 bytes/s, so 1,000,000 bytes take at least 6.10 s
The measured time is a little longer, because of the sleeps and the round trips needed to reopen the window. When you see many Window Full and ZeroWindow events, don't tune the network: look at why the receiving program reads slowly.
Level 4: putting it together
Exercise 10: an abort with RST
In the rst trace, the client read 1,000 bytes and then called close():
1 0.000000 192.0.2.10 → 198.51.100.10 TCP 74 52538 → 9000 [SYN] Seq=0 Win=64240 Len=0 MSS=1460 SACK_PERM
2 0.000057 198.51.100.10 → 192.0.2.10 TCP 74 9000 → 52538 [SYN, ACK] Seq=0 Ack=1 Win=65160 Len=0 MSS=1460 SACK_PERM
115 0.401583 192.0.2.10 → 198.51.100.10 TCP 66 52538 → 9000 [RST, ACK] Seq=1 Ack=119497 Win=75904 Len=0
116 0.430941 192.0.2.10 → 198.51.100.10 TCP 54 52538 → 9000 [RST] Seq=1 Win=0 Len=0
117 0.430977 192.0.2.10 → 198.51.100.10 TCP 54 52538 → 9000 [RST] Seq=1 Win=0 Len=0
- Why did the client send a RST instead of a FIN?
- What does
Ack=in the RST, ACK tell you about how much data arrived? - Why are there more RSTs, without the ACK flag, after it?
- What does the server application see?
Solution
- When an application closes a socket with unread data in its receive buffer, Linux sends a RST instead of a FIN (as RFC 1122 and RFC 2525 recommend), because that data can never be delivered (article 62).
- The client acknowledged everything up to that number, so its kernel had received about 119 KB: 1,000 bytes read by the application, the rest discarded with the socket.
- The server had more segments in flight when the RST was sent. They arrive at a connection that no longer exists, and the client's kernel answers each with a bare RST, which has no ACK because there's no connection state left to acknowledge from.
- Its next
send()orrecv()fails with "Connection reset by peer" (ECONNRESET). In this lab, the server's handler catches that error and closes the connection. A server log full of resets often just means clients gave up early, as browsers do when the user navigates away.
Exercise 11: diagnose the slow transfer
A user reports that a 1 MB download from a nearby server takes about 6.5 s, while iperf3 between the same hosts reaches 20 Mbit/s. A capture on the server shows no retransmissions, many "Window Full" events and some "ZeroWindow" ACKs from the client. What's wrong, and what wouldn't help?
Solution
The receiving application is slow (exercise 9): the network and the sender are fine, which iperf3 already proved, and the client's own window tells the server to wait. Tuning the server, changing congestion control or upgrading the link wouldn't help. Look at the client program: does it read in small chunks with delays, write each chunk synchronously to slow storage, or set a small SO_RCVBUF? Fixing that, or letting auto-tuning choose the buffer, fixes the transfer.
Exercise 12: compare the three transfers
Use the timings at the top of the article and what you found in the exercises. Order clean, loss and zwin from fastest to slowest, and name the limiting factor of each.
Solution
- clean, the fastest: limited by latency at first (handshake and slow start) and then by the 20 Mbit/s bottleneck link, which it filled (exercises 4 and 5).
- loss, about 0.3 s slower: limited by congestion control after the drop. Fast retransmit repaired the hole in one RTT, but CUBIC's reduced window took time to grow back (exercise 7).
- zwin, far slower: limited by the receiving application through flow control (exercises 8 and 9).
That's the three-way question to ask of any slow TCP transfer: is it the path (bandwidth and RTT), the sender's congestion window, or the receiver's window? ss -ti on the sender answers it: compare send, delivery_rate, cwnd, snd_wnd and the retransmission counters.
Common questions
Which side should I capture on?
Both if you can. The sender's capture shows what it sent and when it reacted; the receiver's capture shows what actually arrived. A loss appears as a retransmission on the sender's side and as a gap ("previous segment not captured") on the receiver's side. Captures in the middle show which part of the path lost it.
Is a duplicate ACK always a sign of loss?
No. Reordering also causes duplicate ACKs, and a few are normal on paths that reorder. Loss is likely when several duplicate ACKs are followed by a retransmission. If the retransmission later turns out to be unnecessary, Linux detects it with DSACK and undoes the window reduction (article 67).
What's the quickest way to see TCP problems in a big capture?
tshark -q -z expert or Wireshark's Analyze → Expert Information lists retransmissions, duplicate ACKs, zero windows and resets with counts. Wireshark's Statistics → TCP Stream Graphs (the time-sequence and throughput graphs) show the shape of a transfer at a glance.
Summary
- Measure RTT from a packet leaving the capture point to the reply it caused; on the server, that's SYN-ACK to ACK.
- Window fields are scaled by the factor from the SYNs; without the handshake, a capture can't interpret them.
- The bandwidth-delay product is the window needed to fill the path; slow start doubles the window each round trip until it passes the BDP or HyStart ends it.
- One loss with SACK costs about one round trip plus a congestion-window reduction; the RTO is only a fallback.
ss -tigives the sender's view:rttandminrtt,cwnd,ssthresh,send,delivery_rateandretrans.- Window Full and ZeroWindow point at a slow receiving application; RST after
close()means it closed with unread data.
Practice questions
1. A path has a 100 ms RTT and a 50 Mbit/s bottleneck. How large a window is needed to fill it?
Answer
50,000,000 × 0.1 / 8 = 625,000 bytes, about 610 KiB. The receiver's buffer and the sender's congestion window both have to reach that size.
2. A capture on a client shows "TCP previous segment not captured" followed by duplicate ACKs from the client. Was a packet lost, and where?
Answer
Very likely, somewhere between the sender and the client's capture point: the client never received that segment, so it sent duplicate ACKs. A capture on the sender would show whether it was sent; a retransmission should follow shortly.
3. ss -ti on a sender shows cwnd:400, snd_wnd:65536 and rtt:80. What's limiting the transfer?
Answer
The receiver's window. 400 segments is about 580 KB, far more than the 64 KiB the receiver allows, so the sender can only have 64 KiB in flight: at most about 6.5 Mbit/s at 80 ms RTT, whatever the congestion window.
Where to go next
This is the last article of the course. Go back to the course outline to revisit any topic, or try the exercises again on captures from your own network: they're the best way to keep these skills sharp.
Previous: TCP/IP Exercises: Reading Packet Captures From ARP to DNS
Next: TCP/IP Course Outline: From Ethernet Frames to TCP, DNS, TLS and QUIC

More in TCP/IP Course
Quiz: TCP/IP Delicate Details
Twenty-five questions on the details that catch out experienced engineers: sequence numbers for SYN and FIN, TIME_WAIT versus tcp_fin_timeout, Karn's algorithm, socket buffer doubling, even and odd ephemeral ports, IPv6 checksums and fragmentation, negative DNS caching, and capture filter traps.
Quiz: TCP/IP Interview Questions
Thirty-three networking questions of the kind asked in developer, SRE and network engineering interviews: what happens when you load a URL, TCP versus UDP, handshakes, closing and TIME_WAIT, subnetting, NAT, DNS, MTU problems, congestion, TLS and QUIC, and debugging slow or failing connections.
Quiz: TCP/IP Course Final Exam (All Parts)
The final exam for the TCP/IP course: thirty questions across all fourteen parts, from packets and addressing through Ethernet, ARP, IP, DHCP, NAT, ICMP, UDP, DNS, TCP connections, reliability, congestion control, security, QUIC and troubleshooting.
Quiz: Modern Transports and Troubleshooting (TCP/IP Part 14)
Review modern transports and troubleshooting: QUIC packets, handshakes, 0-RTT, streams and connection migration, HTTP/3, Multipath TCP, SCTP multihoming, and a layered method for diagnosing real network faults.
Discussion
Sign in to ask a question or share what you learned.