← all topics

3 · TCP flow control and connection management

Slides 3-57 → 3-64 · K&R 3.5.5, 3.5.6 · HW4 P43 · Sample midterm 1.3

The problem flow control solves (3-57)

How TCP does it: rwnd (3-58, 3-59)

The rwnd = 0 corner case (K&R 3.5.5)

Flow control vs congestion control in one line (3-65): flow control = one sender too fast for one receiver (protect the receiver's buffer, uses rwnd); congestion control = too many senders sending too fast for the network (protect router buffers, uses cwnd).

Connection management: why handshake at all (3-60)

Why a 2-way handshake fails (3-61, 3-62)

TCP 3-way handshake (3-63)

#SegmentFieldsWhat it means
1Client → server: SYNSYNbit=1, Seq=xClient picks an initial seq # x. No app data. Client goes SYN_SENT.
2Server → client: SYNACKSYNbit=1, Seq=y, ACKbit=1, ACKnum=x+1Server picks its own ISN y, ACKs the SYN, allocates buffers. Server goes SYN_RCVD.
3Client → server: ACKACKbit=1, ACKnum=y+1 (Seq=x+1)"Server is live." Client goes ESTAB. May carry client-to-server data. On receipt the server knows the client is live and goes ESTAB.

Closing a connection (3-64)

State machines (K&R Fig. 3.41, 3.42)

Client:  CLOSED --send SYN--> SYN_SENT --rcv SYNACK, send ACK--> ESTABLISHED
         ESTABLISHED --send FIN--> FIN_WAIT_1 --rcv ACK--> FIN_WAIT_2
         FIN_WAIT_2 --rcv FIN, send ACK--> TIME_WAIT --wait--> CLOSED

Server:  CLOSED --listen()--> LISTEN --rcv SYN, send SYNACK--> SYN_RCVD
         SYN_RCVD --rcv ACK--> ESTABLISHED
         ESTABLISHED --rcv FIN, send ACK--> CLOSE_WAIT --send FIN--> LAST_ACK
         LAST_ACK --rcv ACK--> CLOSED

The six flag bits, and RST

How to solve: compute rwnd and how much the sender may still send

  1. Buffered (unread) bytes = LastByteRcvd − LastByteRead.
  2. rwnd = RcvBuffer − buffered.
  3. At the sender: in-flight = LastByteSent − LastByteAcked.
  4. Bytes the sender may still send now = rwnd − in-flight (0 if negative).

Example (default RcvBuffer from 3-58): RcvBuffer = 4096. LastByteRcvd = 3000, LastByteRead = 1000. Sender has LastByteAcked = 3000, LastByteSent = 3800.

buffered   = 3000 − 1000         = 2000 bytes
rwnd       = 4096 − 2000         = 2096 bytes
in-flight  = 3800 − 3000         =  800 bytes
may send   = 2096 − 800          = 1296 more bytes

How to solve: fill in a handshake

  1. SYN: Seq = client ISN, no ACKnum.
  2. SYNACK: Seq = server ISN, ACKnum = client ISN + 1.
  3. ACK: Seq = client ISN + 1, ACKnum = server ISN + 1.
  4. First data byte from the client has seq client ISN + 1; from the server, server ISN + 1.

Example: client ISN x = 100, server ISN y = 500.

SYN     : SYNbit=1, Seq=100
SYNACK  : SYNbit=1, Seq=500, ACKbit=1, ACKnum=101
ACK     : ACKbit=1, Seq=101, ACKnum=501

HW4 P43: what throttles the sending process?

Q (HW4 P43): Host A is sending an enormous file to Host B over a TCP connection. On this connection there is never any packet loss and the timers never expire. The link connecting Host A to the Internet transmits at R bps. The process in Host A can send data into its TCP socket at S bps, where S = 10R. The TCP receive buffer is large enough to hold the entire file, and the send buffer can hold only 1% of the file. What would prevent the process in Host A from continuously passing data to its TCP socket at rate S bps? TCP flow control? TCP congestion control? Or something else? Elaborate.

Traps
• rwnd is the receiver's free space, not its total buffer. Subtract the unread bytes.
• Subtract LastByteRead, not LastByteAcked. The ACKed-but-unread bytes still occupy the buffer.
• SYNACK's ACKnum is x+1, the ACK's ACKnum is y+1. The SYN eats a seq number though it has no data.
• The third handshake segment can carry data; the SYN cannot.
• Disconnect = FIN, not RST. RST is an abort / "no such socket".
• Flow control is about the receiver; congestion is about the network. In P43, it's neither: the local send buffer.
• With rwnd = 0 the sender doesn't go silent; it sends 1-byte probes.
• TIME_WAIT is on the side that sent the first FIN.

Quick check

1. In the TCP header, which bit is set to 1 to represent a disconnect? (sample 1.3) The FIN bit. Each side sends a FIN to close its direction; the other side ACKs it.
2. What prevents a TCP sender from overflowing the receiver's buffer? Flow control: the receiver advertises free space in the rwnd (receive window) field, and the sender keeps LastByteSent − LastByteAcked ≤ rwnd.
3. RcvBuffer = 8192 bytes, LastByteRcvd = 6000, LastByteRead = 2500. What rwnd does the receiver advertise?
buffered = 6000 − 2500 = 3500
rwnd     = 8192 − 3500 = 4692 bytes
4. Using the rwnd from Q3, the sender has LastByteAcked = 6000 and LastByteSent = 8000. How many more bytes may it send right now?
in-flight = 8000 − 6000 = 2000
may send  = 4692 − 2000 = 2692 bytes
5. Client ISN = 3000, server ISN = 7200. Fill in Seq and ACKnum for all three handshake segments. If the third segment carries 100 bytes of data, what is the client's next seq #?
SYN    : SYNbit=1, Seq=3000
SYNACK : SYNbit=1, Seq=7200, ACKbit=1, ACKnum=3001
ACK    : ACKbit=1, Seq=3001, ACKnum=7201   (+100 data bytes)
Next client seq = 3001 + 100 = 3101.
6. A RcvBuffer of 4096 is completely full and the app is busy. What does B advertise, and what does A do? B advertises rwnd = 0. A keeps sending 1-byte segments; B ACKs them, and once the app reads, an ACK reports a nonzero rwnd and A resumes.
7. Give one way a 2-way handshake fails. A delayed, retransmitted req_conn(x) arrives after the client's connection has finished and the client is gone. The server goes ESTAB with no client: a half-open connection. (Or a stale data(x+1) is then accepted as new data.)
8. Flow control vs congestion control, one line. Flow control: one sender too fast for one receiver (rwnd). Congestion control: too many senders too fast for the network (cwnd).
9. HW4 P43 variant: S = 5R, receive buffer holds the whole file, no loss. What limits the process's write rate, and to what? The send buffer fills (in at 5R, out at R), so the process's writes block and it averages R. Not flow control (huge receive buffer), not congestion control (no loss).
10. Which side ends up in TIME_WAIT, and why wait? The side that sent the first FIN (usually the client). It waits so it can resend the final ACK if that ACK was lost, and so old segments die out before the port pair is reused.
11. What does an RST segment mean? Reset: the host has no socket matching the segment (e.g. a SYN to a closed port), or is aborting the connection. Not a graceful close.
12. Which handshake segment may carry application data? The third one (client's ACK). The SYN and SYNACK carry none.

← prev · all topics · next →