8/7/2019 TCP aimd
1/64
COM210: Com uter Networks CNCOM210: Com uter Networks CN
Dr Ahmad Al-Zubi
Dr Ahmad Al-Zubi
King Saud University - Dr Ahmad Al-Zubi 1
8/7/2019 TCP aimd
2/64
TCP: Overview
Point-to-point:
,
Reliable, in-order byte steam:
But TCP chops it up into segments for
Pipelined (window) flow control:
network
Send & receive buffers
King Saud University - Dr Ahmad Al-Zubi 2
8/7/2019 TCP aimd
3/64
TCP: Overview
application
writes dataapplication
doorTCP
send buffer
TCP
receive buffer
socketdoor
King Saud University - Dr Ahmad Al-Zubi 3
8/7/2019 TCP aimd
4/64
TCP: Overview
Full duplex data: -
MSS: maximum segment size
-
handshaking (exchange of control msgs)
exchange
Flow & Con estion Control:sender will not overwhelm receiver or the
network
King Saud University - Dr Ahmad Al-Zubi 4
8/7/2019 TCP aimd
5/64
TCP segment structure
source port # dest port #
32 bits
URG: urgent data(generally not used)
countingby bytes
acknowledgement number
rcvr window sizeFSRPAUheadlen
notused
ACK: ACK #valid
PSH: ush data now
of data
(not segments!)
ptr urgent datachecksum
Options (variable length)
(generally not used)
RST, SYN, FIN:
ytesrcvr willing
to accept
application
(setup, teardowncommands)
(variable length)nternetchecksum(as in UDP)
King Saud University - Dr Ahmad Al-Zubi 5
8/7/2019 TCP aimd
6/64
TCP seq. #s and ACKs (I)
Sequence Numbers:
b te stream number of first b te in
segments data
ACKs:
seq # of next byte expected from other sidecumulative ACK
Q: how receiver handles out-of-order segmentsA: TCP spec doesnt say, - up to
King Saud University - Dr Ahmad Al-Zubi 6
8/7/2019 TCP aimd
7/64
TCP Seq. #s and ACKs (II)
Host A Host B
Usertypes
Chost ACKsreceipt of
C, echoesback C
ost sreceipt
of echoedC
sim le telnet scenario
King Saud University - Dr Ahmad Al-Zubi 7
8/7/2019 TCP aimd
8/64
Temporal Redundancy Model
Packets Sequence Numbers CRC or Checksum
Status Reports ACKs
Timeout
, SACKs
Bitmaps
Packets
Retransmissions
n orma on
King Saud University - Dr Ahmad Al-Zubi 8
8/7/2019 TCP aimd
9/64
Status Report Design
Cumulativeacks:
Can work with go-back-Nretransmission
lost
because the receiver would generatedu licate acks
King Saud University - Dr Ahmad Al-Zubi 9
8/7/2019 TCP aimd
10/64
TCP: reliable data transfer (I)event: data received
from application above
create, send segment one way data transfer
waitforwait
event: timer timeout for
segment with seq # y
no flow, congestion
event
event retransmit segment
event: ACK received,with ACK # y
King Saud University - Dr Ahmad Al-Zubi 10
ACK processing
8/7/2019 TCP aimd
11/64
00 sendbase = initial_sequence number01 nextseqnum = initial_sequence number02
TCP:
oop orever 04 switch(event)05 event: data received from application above06 create TCP segment with sequence number nextseqnum07 start timer for segment nextseqnum
reliable09 nextseqnum = nextseqnum + length(data)10 event: timer timeout for segment with sequence number y11 retransmit segment with sequence number y12 compute new timeout interval for segment y
transfer (II)
14 event: ACK received, with ACK field value of y15 if (y > sendbase) { /* cumulative ACK of all data up to y */16 cancel all timers for segments with sequence numbers < y
17 sendbase = y
19 else { /* a duplicate ACK for already ACKed segment */20 increment number of duplicate ACKs received for y21 if (number of duplicate ACKS received for y == 3) {22 /* TCP fast retransmit */Simplified
24 restart timer for segment y25 }26 } /* end of loop forever */
TCPsender
King Saud University - Dr Ahmad Al-Zubi 11
8/7/2019 TCP aimd
12/64
TCP ACK generation
Event TCP Receiver action
in-order segment arrival,no gaps,
delayed ACK. Wait up to 500msfor next segment. If no next segment,
in-order segment arrival,
no gaps,
immediately send single
cumulative ACKone delayed ACK pending
out-of-order segment arrival- -
send duplicate ACK, indicating seq. #
.
gap detected!
arrival of segment that
immediate ACK if segment starts
King Saud University - Dr Ahmad Al-Zubi 12
part a y or comp ete y s gap at ower en o gap
8/7/2019 TCP aimd
13/64
TCP: retransmission scenariosHost A Host B Host A Host B
ut
timeout
out
losstime
XSeq=92
q=100
tim
S
time lost AC scenariotime remature timeout,
King Saud University - Dr Ahmad Al-Zubi 13
cumulative ACKs
8/7/2019 TCP aimd
14/64
TCP Flow Control
receiver: explicitlyinforms sender ofsender wont overrun
receivers buffers b
flow control
RcvWindowfield in TCP
transmitting too much,too fast
segmen
sender: keeps theamount of
RcvBuffer = size or TCP Receive Buffer
RcvWindow = amount of spare room in Buffer
transmitted,unACKed data lessthan most recentl
receivedRcvWindow
King Saud University - Dr Ahmad Al-Zubi 14
receiver buffering
8/7/2019 TCP aimd
15/64
Timeout and RTT Estimation
Timeout: for robust detection of
Problem: How long should timeoutbe ?
=
Too short => wasteful
Solution: adaptive timeout:based on
King Saud University - Dr Ahmad Al-Zubi 15
es ma e o max
8/7/2019 TCP aimd
16/64
How to estimate max RTT?
RTT = prop + queuing delay
So, different samples of RTTs will givedifferent random values of ueuin dela
Cheb shevs Theorem:MaxRTT = Avg RTT + k*Deviation
Error probability is less than 1/(k**2)
Result true for ANY distribution ofsamples
King Saud University - Dr Ahmad Al-Zubi 16
8/7/2019 TCP aimd
17/64
Round Trip Time and Timeout (II)
Q: how to estimate RTT?
SampleRTT: measured time from segmenttransmission until ACK receipt
ignore retransmissions, cumulatively
ACKed segments amp e w vary w y => wan
estimated RTT smoother
,just current SampleRTT to calculate
King Saud University - Dr Ahmad Al-Zubi 17
8/7/2019 TCP aimd
18/64
TCP Round Trip Time and
Avera eRTT = 1-x *Avera eRTT + x*Sam leRTT
Exponential weighted moving average (EWMA) influence of iven sam le decreases
exponentially fast; x = 0.1
Setting the timeout
AverageRTT plus safety margin proportional tovariation
Timeout = AverageRTT + 4*Deviation
Deviation = (1-x)*Deviation + x*|SampleRTT- AverageRTT|
King Saud University - Dr Ahmad Al-Zubi 18
8/7/2019 TCP aimd
19/64
TCP Connection Management - 1
Recall: TCP sender, receiver establishconnection before exchan in data se ments
initialize TCP variables:seq. #s
buffers, flow control info (e.g. RcvWindow) c ent :connect on n t ator
Socket clientSocket = new Socket("hostname","port
" server:contacted by client
King Saud University - Dr Ahmad Al-Zubi 19
.
8/7/2019 TCP aimd
20/64
TCP Connection Management - 2
Three way handshake:
Step 1: client end system sends TCP SYNcontrol segment to serverspecifies initial seq #
,replies with SYNACK control segment
allocates buffers
-
King Saud University - Dr Ahmad Al-Zubi 20
.
8/7/2019 TCP aimd
21/64
TCP Connection Management - 3
client closes socket: clientSocket.close();
Step 1: client end system sends TCPFIN control segment to server
ep : server receives FIN, replies withACK. Closes connection, sends FIN.
King Saud University - Dr Ahmad Al-Zubi 21
8/7/2019 TCP aimd
22/64
TCP Connection Management - 4
Fddfdf
close
close
wait
closedtimed
King Saud University - Dr Ahmad Al-Zubi 22
8/7/2019 TCP aimd
23/64
TCP Connection Management - 5
, .
Enters timed wait - will respond witho rece ve s
closed.
ote: with small modification, can handlesimultaneous FINs.
King Saud University - Dr Ahmad Al-Zubi 23
8/7/2019 TCP aimd
24/64
TCP Connection Management - 6
King Saud University - Dr Ahmad Al-Zubi 24
c en ecyc e
8/7/2019 TCP aimd
25/64
TCP Connection Management - 7
King Saud University - Dr Ahmad Al-Zubi 25
8/7/2019 TCP aimd
26/64
Recap: Stability of a Multiplexed System
Average Input Rate > Average Output Rate=> system is unstable!
How to ensure stability ?1. Reserve enough capacity so that
eman s ess an reserve capac y2. Dynamically detect overload and adapt
King Saud University - Dr Ahmad Al-Zubi 26
overload
8/7/2019 TCP aimd
27/64
Congestion Problem in Packet Switching
A C10 MbsEthernet
statistical multiplexing
B 1.5 Mbs
swaiting for output
link
D E Cost: self-descriptive header per-packet,
buffering and delays for applications.
Need to either reserve resources or
King Saud University - Dr Ahmad Al-Zubi 27
dynamically detect/adapt to overload for stability
8/7/2019 TCP aimd
28/64
iThe Congestion Problem
1 ro em: eman ou s r ps ava a e capac y
CapacityDemand
If information about and isn
known in a central location where
i with zero time delays,King Saud University - Dr Ahmad Al-Zubi 28
the congestion problem is solved!
8/7/2019 TCP aimd
29/64
The Congestion Problem
Problems:
Incomplete information (eg: lossindications)
Distributed solution required
Con estion andcontrol/measurement locationsdifferent
Time-varying, heterogeneous time-delay
King Saud University - Dr Ahmad Al-Zubi 29
8/7/2019 TCP aimd
30/64
The Congestion Problem
Static fixes may notsolve congestion
a Memor becomes chea infinite memor
No buffer Too late
All links 19.2 kb/s Replace with 1 Mb/s
b)Linksbecome cheap (high speed links)?
S S S S S S S S
=
King Saud University - Dr Ahmad Al-Zubi 30
8/7/2019 TCP aimd
31/64
The Congestion Problem
(fast routers & switches)
A
SS
C
Scenario: All links 1 Gb/s.
=> high-speed congestion!!(lose more packets faster!)
King Saud University - Dr Ahmad Al-Zubi 31
8/7/2019 TCP aimd
32/64
Principles of Congestion Control
Congestion: informally: too many sources sending too
much data too fast for networkto handle
erent rom ow contro rece verover oa
manifestations:lost packets (buffer overflow at routers)
long delays (queuing in router buffers)
a top-10 problem!
King Saud University - Dr Ahmad Al-Zubi 32
8/7/2019 TCP aimd
33/64
Causes/costs of congestion:
two senders, tworece vers
one router,
no
retransmission large delays
when
maximumachievable
King Saud University - Dr Ahmad Al-Zubi 33
throughput
C / f i
8/7/2019 TCP aimd
34/64
Causes/costs of congestion:
one router, finitebuffers
sender retransmission of lost packet
King Saud University - Dr Ahmad Al-Zubi 34
C / t f ti
8/7/2019 TCP aimd
35/64
Causes/costs of congestion:
Costs of congestion:
Unneeded retransmissions: link carriesmulti le co ies of kt due to s urious
King Saud University - Dr Ahmad Al-Zubi 35
timeouts
C / t f ti
8/7/2019 TCP aimd
36/64
Causes/costs of congestion:
Another cost of congestion:
when packet dropped, any upstreamtransmission capacity used for that packet
King Saud University - Dr Ahmad Al-Zubi 36
A h t d
8/7/2019 TCP aimd
37/64
Approaches towards
Two broad approaches towardscon estion control:
End-endcongestion control:
no exp c ee ac rom ne wor
congestion inferred from end-system
observed loss, delay a roach taken b TCP
King Saud University - Dr Ahmad Al-Zubi 37
A h t d
8/7/2019 TCP aimd
38/64
Approaches towards
Network assistedcongestioncontrol:
routers provide feedback to end
single bit indicating congestion, , ,
explicit rate sender should send at
King Saud University - Dr Ahmad Al-Zubi 38
8/7/2019 TCP aimd
39/64
TCP congestion control - 1
end-end control no network assistance
transmission rate limited by congestionwindow size, Congwin, over segments:
King Saud University - Dr Ahmad Al-Zubi 39
8/7/2019 TCP aimd
40/64
TCP congestion control - 2
w segments, each with MSS
w * MSSt roug put =RTT
Bytes/sec
King Saud University - Dr Ahmad Al-Zubi 40
8/7/2019 TCP aimd
41/64
TCP congestion control - 3
Probing for usable bandwidth:
overrun
avoid/control network overrun
IncreaseCongwin until loss (congestion)
,probing (increasing) again
King Saud University - Dr Ahmad Al-Zubi 41
Additive Increase/Multiplicative
8/7/2019 TCP aimd
42/64
Additive Increase/Multiplicative
For stability:
- - - -
Decrease performed enough times as
AIMD policy satisfies this condition,
provided packet loss is congestionindicator
window
King Saud University - Dr Ahmad Al-Zubi 42time
8/7/2019 TCP aimd
43/64
Fairness
Fairness oal: if N TCP sessions
share same bottleneck link, each
TCP connection 1
bottleneckrouter
capacity R
TCPconnection 2
King Saud University - Dr Ahmad Al-Zubi 43
8/7/2019 TCP aimd
44/64
Fairness Analysis
King Saud University - Dr Ahmad Al-Zubi 44
8/7/2019 TCP aimd
45/64
AIMD Converges to Fairness
King Saud University - Dr Ahmad Al-Zubi 45
8/7/2019 TCP aimd
46/64
TCP congestion control - 4
TCP uses AIMD policy in steady state
Transient phase: aka Slow start
Important variables:
threshold: defines threshold between twoslow start hase con estion avoidance
phase
King Saud University - Dr Ahmad Al-Zubi 46
8/7/2019 TCP aimd
47/64
TCP Slowstart - 1
Slowstart algorithm
n a ze: ongw n =
for (each segment ACKed)Congwin++
until (loss event ORCongWin > threshold)
Exponential increase (per RTT)in windowsize (not so slow!)
Loss event:timeout (Tahoe TCP) and/orthree duplicate ACKs (Reno TCP)
King Saud University - Dr Ahmad Al-Zubi 47
8/7/2019 TCP aimd
48/64
TCP Slowstart - 2
asdf Host A Host B
RTT
time
King Saud University - Dr Ahmad Al-Zubi 48
TCP D i
8/7/2019 TCP aimd
49/64
TCP Dynamics
1st RTT 2nd RTT 3rd RTT 4th RTT
Rate of acks determines rate of .
100 Mbps 10 Mbps
RouterQ
King Saud University - Dr Ahmad Al-Zubi 49
TCP C i A id 1
8/7/2019 TCP aimd
50/64
TCP Congestion Avoidance - 1
/* slowstart is over */
Congestion avoidance
/* Congwin > threshold */
Until (loss event) {ever w se ments ACKed:
Congwin++}
=Congwin = 1perform slowstart
1
1: TCP Reno ski s slowstart aka fast recover after
King Saud University - Dr Ahmad Al-Zubi 50
three duplicate ACKs and performs close to AIMD
TCP C ti A id 2
8/7/2019 TCP aimd
51/64
TCP Congestion Avoidance - 2
King Saud University - Dr Ahmad Al-Zubi 51
TCP i d d i ( )
8/7/2019 TCP aimd
52/64
TCP window dynamics (more)
Receiver Window
Window
(cwnd)
Idle
Interval
ssthresh
1
me un s o s
King Saud University - Dr Ahmad Al-Zubi 52
TCP l t d li 1
8/7/2019 TCP aimd
53/64
TCP latency modeling - 1
Q: How long does it take to
server after sending a request?
connec on es a s men
data transfer delay
King Saud University - Dr Ahmad Al-Zubi 53
TCP latency modeling 2
8/7/2019 TCP aimd
54/64
TCP latency modeling - 2
Assume one link between client andserver of rate R
Assume: fixed congestion window, Wsegments
S: MSS (bits)
O: object size (bits)
no re ransm ss ons no oss, nocorruption)
King Saud University - Dr Ahmad Al-Zubi 54
TCP latency modeling 3
8/7/2019 TCP aimd
55/64
TCP latency modeling - 3
Two cases to consider:
segment in window returns
sent
WS/R < RTT + S/R: wait for ACK
after sending windows worth ofdata sent
King Saud University - Dr Ahmad Al-Zubi 55
TCP latency modeling 4
8/7/2019 TCP aimd
56/64
TCP latency modeling - 4
King Saud University - Dr Ahmad Al-Zubi 56
= +
TCP latency modeling 5
8/7/2019 TCP aimd
57/64
TCP latency modeling - 5
K = O/WS
Case 2: latency = 2RTT + O/R
King Saud University - Dr Ahmad Al-Zubi 57
+ - + -
TCP latency modeling:
8/7/2019 TCP aimd
58/64
slow start. Will show that the latenc of one ob ect of
size O is:
RRRTTP
RRTTLatency )12(2
+++=
w ere s e num er o mes s a s aserver:
King Saud University - Dr Ahmad Al-Zubi 58
TCP latency modeling:
8/7/2019 TCP aimd
59/64
}1,{min = KQP
- where Q is the number of times the server
would stall if the ob ect were of infinitesize.
- an s t e num er o w n ows t at coverthe object.
King Saud University - Dr Ahmad Al-Zubi 59
TCP latency modeling:
8/7/2019 TCP aimd
60/64
initiate TCPconnection
O/S = 15 segments
requestobject
first window= S/R
K = 4 windows
second window= 2S/R
third window= 4S/R
Q = 2fourth window
= 8S/R
= - , =
Server stalls P=2 times.complete
transmissionobjectdelivered
King Saud University - Dr Ahmad Al-Zubi 60
time atclient
server
TCP latency modeling:
8/7/2019 TCP aimd
61/64
S=
until server receives acknowledgement
R
1
= Sk
R
windowthafter thetimestall2 1 kRSRTT
RS k = +
King Saud University - Dr Ahmad Al-Zubi 61
TCP latency modeling:
8/7/2019 TCP aimd
62/64
stallTimeRTTOP
2latency ++=
SRTT
SRTT
O kP
p
221
1
+++=
=
SSO
RRR
P
k 1
=
=
RRR
King Saud University - Dr Ahmad Al-Zubi 62
Sample Results
8/7/2019 TCP aimd
63/64
Sample Results
R O/R P Minimum Latency:O/R + 2 RTT
Latency with slowstart
28 Kbps 28.6 sec 1 28.8 sec 28.9 sec
100 Kbps 8 sec 2 8.2 sec 8.4 sec
1 Mbps 800msec
5 1 sec 1.5 sec
10 Mb s 80 msec 7 0.28 sec 0.98 sec
King Saud University - Dr Ahmad Al-Zubi 63
Summary: Chapter 3
8/7/2019 TCP aimd
64/64
Su a y C apte 3
Principles behind transport layer services:
reliable data transfer
congestion control
ns an a on an mp emen a on n eInternet
King Saud University - Dr Ahmad Al-Zubi 64
,