Professional Documents
Culture Documents
p Networks (CN)
( )
Chapter 3: TCP
Dr Ahmad Al-Zubi
application application
writes data reads data
socket socket
door door
TCP TCP
send buffer receive buffer
segment
ACKs:
– seq # of next byte expected from other side
– cumulative ACK
hostt ACKs
h ACK
receipt
of echoed
‘C’
simple
p telnet scenario
wait
wait
event: timer timeout for • no flow, congestion
segment with seq # y
for
for control
event
event retransmit segment
transfer (II) 16
17
18
cancel all timers for segments with sequence numbers < y
sendbase = y
}
19 else { /* a duplicate ACK for already ACKed segment */
20 increment number of duplicate ACKs received for y
21 if (number of duplicate ACKS received for y == 3) {
Simplified 22 /* TCP fast retransmit */
23 resend segment with sequence number y
TCP
C 24
25 }
restart timer for segment y
Seq=92 timeout
eout
out
timeo
eq=100 time
X
loss
Se
time
time ost ACK
lost K scenario
sc nar o premature timeout,,
p
cumulative ACKs
King Saud University - Dr Ahmad Al-Zubi 13
TCP Flow Control
flow control receiver: explicitly
sender won’t overrun informs sender of
receiver’s
receiver s buffers by free buffer space
transmitting too much,
too fast
– RcvWindow
field in TCP
RcvBuffer = size or TCP Receive Buffer segmentt
RcvWindow = amount of spare room in Buffer sender: keeps the
amount of
transmitted,
unACKed data less
tthan
a most
ost recently
ece t y
received
RcvWindow
receiver buffering
King Saud University - Dr Ahmad Al-Zubi 14
Timeout and RTT Estimation
• Timeout: for robust detection of
packet loss
• Problem: How long should timeout
be ?
– Too long =>> underutilization
– Too short => wasteful
retransmissions
– Solution: adaptive timeout: based on
estimate
ti t off max RTT
King Saud University - Dr Ahmad Al-Zubi 15
How to estimate max RTT?
• RTT = prop + queuing delay
– Queuing delay highly variable
– So, different samples of RTTs will give
different random values of q
queuingg delay
y
• Chebyshev’s
y Theorem:
– MaxRTT = Avg RTT + k*Deviation
– Error probability is less than 1/(k**2)
– Result true for ANY distribution of
samples
Closing a connection:
client closes socket: clientSocket.close();
()
St 2:
Step 2 server receives FIN, replies with
ACK. Closes connection, sends FIN.
close
close
timed wait
closed
d
King Saud University - Dr Ahmad Al-Zubi 22
TCP Connection Management - 5
TCP client
li t lifecycle
lif l
King Saud University - Dr Ahmad Al-Zubi 24
TCP Connection Management - 7
1.5 Mbs
B
queue of packets 45 Mbs
Mb
waiting for output
link
D E
Cost: self-descriptive header per-packet,
buffering and delays for applications.
Need to either reserve resources or
dynamically detect/adapt to overload for stability
King Saud University - Dr Ahmad Al-Zubi 27
The
λ
Congestion Problem
i μi
•Problem:
P bl d λ d outstrips
demand t t iμ available
il bl capacity
it
λ1
Demand Capacity
λn
• If information about λi , λ and μ is
known in a central location where
control of λi or μ can be effected
with zero time delays,
– the
h congestion
i problem
bl is
i solved!
l d!
King Saud University - Dr Ahmad Al-Zubi 28
The Congestion Problem
(Continued)
• Problems:
– Incomplete information (eg: loss
indications)
– Distributed solution required
– Congestion
g and
control/measurement locations
different
– Time-varying, heterogeneous time-
delay
King Saud University - Dr Ahmad Al-Zubi 29
The Congestion Problem
• Static fixes may not solve congestion
– a)) Memory
y becomes cheap
p (infinite
( memory)
y)
S S S S S S S S
File Transfer time = 5 mins File Transfer Time = 7 hours
King Saud University - Dr Ahmad Al-Zubi 30
The Congestion Problem
(Continued)
• c) Processors become cheap
(fast routers & switches)
A C
S
B D
Scenario: All links 1 Gb/s.
A & B send to C
=> “high-speed” congestion!!
(lose more packets faster!)
King Saud University - Dr Ahmad Al-Zubi 31
Principles of Congestion Control
Congestion:
• informally: “too many sources sending too
much data too fast for network to handle”
• different
diff t from
f flow
fl control
t l (receiver
( i overload)!
l d)!
• manifestations:
– lost packets (buffer overflow at routers)
– long delays (queuing in router buffers)
• a top-10 problem!
“Costs” of congestion:
• More work (retrans) for given “goodput”
goodput
• Unneeded retransmissions: link carries
multiple
p copies
p of pkt
p due to spurious
p
timeouts
King Saud University - Dr Ahmad Al-Zubi 35
Causes/costs of congestion:
scenario 3
Network-assisted congestion
control:
• routers provide feedback to end
systems
– single bit indicating congestion
(SNA DECbit,
(SNA, DECbit TCP/IP ECN,
ECN ATM)
– explicit rate sender should send at
time
King Saud University - Dr Ahmad Al-Zubi 42
Fairness
Fairness g
goal: if N TCP sessions
share same bottleneck link, each
should get 1/N of link capacity
TCP connection 1
bottleneck
TCP
router
connection 2
capacity R
RTT
time
Router
Q
Receiver Window
Congestion Timeout
Window Idle
ssthresh
(cwnd) Interval
1
Time (units of RTTs)
Notation, assumptions:
• Assume one link between client and
server of rate R
• Assume: fixed congestion window, W
segments
• S: MSS (bits)
• O: object size (bits)
• no retransmissions
t i i (no
( loss,
l no
corruption)
K = O/WS
R ⎣ R⎦ R
where
h P is
i the
th number
b off times
ti TCP stalls
t ll att
server:
P = min{Q, K − 1}
- where Q is the number of times the server
would stall if the object
j were of infinite
size.
- andd K is
i the
h number
b off windows
i d that
h cover
the object.
Example:
request
object
first window
= S/R
O/S = 15 segments RTT
second window
= 2S/R
Q=2
fourth window
= 8S/R
P = min{K-1,Q}
min{K 1 Q} = 2
complete
object transmission
Server stalls P=2 times. delivered
time at
time at server
client
k −1 S
2 = time to transmit the kth window
R
+
⎡S k −1 S ⎤
⎢⎣ R + RTT − 2 R ⎥⎦ = stall time after the kth window
P
O
latency = + 2 RTT + ∑ stallTimep
R p =1
P
O S k −1 S
= + 2 RTT + ∑ [ + RTT − 2 ]
R k =1 R R
O S S
= + 2 RTT + P[ RTT + ] − (2 − 1)
P
R R R