Escolar Documentos
Profissional Documentos
Cultura Documentos
CPSC 641
WINTER 2011
application
writes data
TCP
send buffer
application
reads data
TCP
receive buffer
data segment
socket
layer
ACK segment
WINTER 2011
head not
UA P R S F
len used
checksum
CPSC 641
WINTER 2011
client
connect()
SYN (
(
SYN
server
Y) +
X)
(X
ACK
A CK (
time
listen()
port 80
+1)
Y+1)
accept()
read()
CPSC 641
WINTER 2011
SENDING DATA
socket
layer
application
writes data
TCP
send buffer
application
reads data
data segment
TCP
receive buffer
ACK segment
socket
layer
WINTER 2011
PREVENTING CONGESTION
Sender may not only overrun receiver, but
may also overrun intermediate routers:
No way to explicitly know router buffer occupancy,
so we need to infer it from packet losses
Assumption is that losses stem from congestion, namely,
that intermediate routers have no available buffers
WINTER 2011
CPSC 641
WINTER 2011
SLOW START
Loss occurs OR
CW > slow start threshold
sender receiver
one segm
ent
RTT
Initial CW = 1.
After each ACK, CW += 1;
Continue until:
two segm
ents
Then switch to
congestion avoidance
If we detect loss, cut CW
in half
Exponential increase in
window size per RTT
four segm
ents
time
CPSC 641
WINTER 2011
CONGESTION AVOIDANCE
Until (loss) {
after CW packets ACKed:
CW += 1;
}
ssthresh = CW/2;
Depending on loss type:
SACK/Fast Retransmit:
CW/= 2; continue;
Course grained timeout:
CW = 1; go to slow start.
(This is for TCP Reno/SACK: TCP
CPSC 641
WINTER 2011
10
Coarse-grained Timeout:
timeout
Seq=9
2, 8 b
ytes d
ata
=100
ACK
loss
Seq=9
2,
8 byte
AC K
s data
=100
time
lost ACK scenario
CPSC 641
WINTER 2011
11
FAST RETRANSMIT
Receiver expects N, gets N+1:
sender receiver
ACK 3000
SEQ=300
0, size=10
SEQ=400 X
0
00
SEQ=500
0
SEQ=600
0
ACK 3000
ACK 3000
ACK 3000
SEQ=300
0, size=10
00
time
CPSC 641
WINTER 2011
12
WINTER 2011
13
CONNECTION TERMINATION
Either side may terminate
a connection. ( In fact,
connection can stay
half-closed.) Let's say
the server closes
(typical in WWW)
close()
X)
FIN(
close()
ACK(X
+1)
FIN(Y
)
time
AC K
)
(Y+1
server
timed wait
client
closed
CPSC 641
WINTER 2011
14
WINTER 2011
15
server application
calls listen()
client application
calls connect()
send SYN
LISTEN
SYN_SENT
receive SYN
send SYN + ACK
receive SYN
send ACK
SYN_RCVD
receive ACK
ESTABLISHED
CPSC 641
WINTER 2011
16
close() called
send FIN
receive FIN
send ACK
FIN_WAIT_1
receive ACK
of FIN
receive FIN
send ACK
FIN_WAIT_2
receive FIN
send ACK
CLOSE_WAIT
close() called
send FIN
CLOSING
receive ACK
of FIN
LAST_ACK
TIME_WAIT
receive ACK
wait 2*MSL
(240 seconds)
CLOSED
CPSC 641
WINTER 2011
17
CPSC 641
WINTER 2011
18