Professional Documents
Culture Documents
URG
Window Size
SYN
ACK
PSH
RST
FIN
segments and placed 4 6
TCP Data
Host A
Host B
– Client’s ISN = x
– Server’s ISN = y
• Send a special segment
with SYN bit set
(“synchronize”)
• SYN takes up one “byte”
Shutdown
• Either side can iniRate FIN
SEQ = v
shutdown
• Can shutdown only one
side of connecRon, if
desired
• TIME_WAIT state to
handle case of whether
last ACK was lost
Sockets and TCP
socket, bind socket, bind
SYN
listen
SYN/ACK
connect
ACK accept
send/recv … send/recv
FIN
ACK
shutdown shutdown
FIN
(SHUT_RDWR) (SHUT_RDWR)
ACK
Sender Window
• Window size: maximum Sender
amount of unacked Round Trip Time
bytes/segments Window Size Window Size
• Usually dynamically
adjusted in response to
congesRon
• Must be smaller than
receiver window ACK ACK ACK
• Local state maintained Receiver
at sender
Sender
Receiver
ACK ACK ACK ACK
halved
Src
D A D D A A D D D A A A
Dest
Credit: CS244A Handout 8
OpRmizaRons
• Slow start iniRalizaRon
– Increase cwnd by MSS for every ack (doubles cwnd for every RTT)
– Suppose we detect first loss at window size W
• Set ssthresh := W/2
• Set cwnd := 1
• Use slow start unRl our window size is ssthresh
• Then use AIMD (congesRon avoidance mode)
• Fast retransmit and fast recovery if we get three duplicate acks
during slow start
– Suppose we send 1, 2, 3, 4, 5, … , 8, 9, 10
– Get acks 1, 2, 3, 4, 5, …, 8, 8, 8
– Probably 9th segment has been lost, so:
• Resend it before retransmit Rmer expires (fast retransmit)
• Set cwnd := ssthresh rather than 1 and go into AIMD (fast recovery)
TCP Sawtooth With OpRmizaRons
Loss
Window Size
halved
Client Server
handle_ack
STDIN STDOUT
handle_pkt
Send Receiver
Buffer State
Rmer handle_pkt
Data packets