chapter 3: transport layer - bilkent...
TRANSCRIPT
Transport Layer 3-1
Chapter 3 Transport LayerOur goals
understand principles behind transport layer services
multiplexingdemultiplexing
reliable data transferflow controlcongestion control
learn about transport layer protocols in the Internet
UDP connectionless transportTCP connection-oriented transportTCP congestion control
Transport Layer 3-2
Transport services and protocolsprovide logical communicationbetween app processes running on different hoststransport protocols run in end systems
send side breaks app messages into segments passes to network layerrcv side reassembles segments into messages passes to app layer
more than one transport protocol available to apps
Internet TCP and UDP
applicationtransportnetworkdata linkphysical
applicationtransportnetworkdata linkphysical
networkdata linkphysical
networkdata linkphysical
networkdata linkphysical
networkdata linkphysicalnetwork
data linkphysical
logical end-end transport
Transport Layer 3-3
Transport vs network layer
network layer logical communication between hoststransport layer logical communication between processes
relies on enhances network layer services
Household analogy12 kids sending letters
to 12 kidsprocesses = kidsapp messages = letters in envelopeshosts = housestransport protocol = Ayşe and Buumllentnetwork-layer protocol = postal service
Transport Layer 3-4
Internet transport-layer protocols
reliable in-order delivery (TCP)
congestion control flow controlconnection setup
unreliable unordered delivery UDP
no-frills extension of ldquobest-effortrdquo IP
services not available delay guaranteesbandwidth guarantees
applicationtransportnetworkdata linkphysical
applicationtransportnetworkdata linkphysical
networkdata linkphysical
networkdata linkphysical
networkdata linkphysical
networkdata linkphysicalnetwork
data linkphysical
logical end-end transport
Transport Layer 3-5
Multiplexingdemultiplexing
application
transport
network
link
physical
P1 application
transport
network
link
physical
application
transport
network
link
physical
P2P3 P4P1
host 1 host 2 host 3
= process= socket
delivering received segmentsto correct socket
Demultiplexing at rcv hostgathering data from multiplesockets enveloping data with header (later used for demultiplexing)
Multiplexing at send host
Transport Layer 3-6
How demultiplexing workshost receives IP datagrams
each datagram has source IP address destination IP addresseach datagram carries 1 transport-layer segmenteach segment has source destination port number (recall well-known port numbers for specific applications)
host uses IP addresses amp port numbers to direct segment to appropriate socket
source port dest port
32 bits
applicationdata
(message)
other header fields
TCPUDP segment format
Transport Layer 3-7
Connectionless demultiplexing
Create sockets with port numbers
DatagramSocket mySocket1 = new DatagramSocket(9111)
DatagramSocket mySocket2 = new DatagramSocket(9222)
UDP socket identified by two-tuple
(dest IP address dest port number)
When host receives UDP segment
checks destination port number in segmentdirects UDP segment to socket with that port number
IP datagrams with different source IP addresses andor source port numbers directed to same socket
Transport Layer 3-8
Connection-oriented demux
TCP socket identified by 4-tuple
source IP addresssource port numberdest IP addressdest port number
recv host uses all four values to direct segment to appropriate socket
Server host may support many simultaneous TCP sockets
each socket identified by its own 4-tuple
Web servers have different sockets for each connecting client
non-persistent HTTP will have different socket for each request
Transport Layer 3-9
Connection-oriented demux(cont)
ClientIPB
P1
clientIP A
P1P2P4
serverIP C
SP 9157DP 80
SP 9157DP 80
P5 P6 P3
D-IPCS-IP AD-IPC
S-IP B
SP 5775DP 80
D-IPCS-IP B
Transport Layer 3-10
Connection-oriented demuxThreaded Web Server
ClientIPB
P1
clientIP A
P1P2P4
serverIP C
SP 9157DP 80
SP 9157DP 80
P5 P6 P3
D-IPCS-IP AD-IPC
S-IP B
SP 5775DP 80
D-IPCS-IP B
P4
Transport Layer 3-11
UDP User Datagram Protocol [RFC 768]
ldquono frillsrdquo ldquobare bonesrdquoInternet transport protocolldquobest effortrdquo service UDP segments may be
lostdelivered out of order to app
connectionlessno handshaking between UDP sender receivereach UDP segment handled independently of others
Why is there a UDPno connection establishment (which can add delay)simple no connection state at sender receiversmall segment headerno congestion control UDP can blast away as fast as desired
Transport Layer 3-12
UDP moreoften used for streaming multimedia apps
loss tolerantrate sensitive
other UDP usesDNSSNMP
reliable transfer over UDP add reliability at application layer
application-specific error recovery
source port dest port
32 bits
Applicationdata
(message)
UDP segment format
length checksumLength in
bytes of UDPsegmentincluding
header
Transport Layer 3-13
UDP checksum
Sendertreat segment contents as sequence of 16-bit integerschecksum addition (1rsquos complement sum) of segment contents with wraparound of carry out bitsender puts checksum value into UDP checksum field
Receivercompute checksum of received segmentcheck if computed checksum equals checksum field value
NO - error detectedYES - no error detected
Goal detect ldquoerrorsrdquo (eg flipped bits) in transmitted segment
Transport Layer 3-14
Principles of Reliable data transferimportant in app transport link layerstop-10 list of important networking topics
characteristics of unreliable channel will determine complexity of reliable data transfer protocol (rdt)
netw
ork
laye
r
Transport Layer 3-15
Reliable data transfer getting started
sendside
receiveside
rdt_send() called from above (eg by app) Passed data to
deliver to receiver upper layer
udt_send() called by rdtto transfer packet over
unreliable channel to receiver
rdt_rcv() called when packet arrives on rcv-side of channel
deliver_data() called by rdt to deliver data to upper
Transport Layer 3-16
Reliable data transfer getting startedWersquoll
incrementally develop sender receiver sides of reliable data transfer protocol (rdt)consider only unidirectional data transfer
but control info will flow on both directionsuse finite state machines (FSM) to specify sender receiver
state1
state2
event causing state transitionactions taken on state transition
state when in this ldquostaterdquo next state
uniquely determined by next event
eventactions
Transport Layer 3-17
Rdt10 reliable transfer over a reliable channel
underlying channel perfectly reliableno bit errorsno loss of packets
separate FSMs for sender receiversender sends data into underlying channelreceiver read data from underlying channel
Wait for call from above packet = make_pkt(data)
udt_send(packet)
rdt_send(data)extract (packetdata)deliver_data(data)
Wait for call from
below
rdt_rcv(packet)
sender receiver
Transport Layer 3-18
Rdt20 channel with bit errors
underlying channel may flip bits in packetrecall checksum to detect bit errors
the question how to recover from errorsacknowledgements (ACKs) receiver explicitly tells sender that pkt received OKnegative acknowledgements (NAKs) receiver explicitly tells sender that pkt had errorssender retransmits pkt on receipt of NAK
new mechanisms in rdt20 (beyond rdt10)error detectionreceiver feedback control msgs (ACKNAK) rcvr-gtsender
Transport Layer 3-19
rdt20 FSM specification
Wait for call from above
snkpkt = make_pkt(data checksum)udt_send(sndpkt)
extract(rcvpktdata)deliver_data(data)udt_send(ACK)
rdt_rcv(rcvpkt) ampamp notcorrupt(rcvpkt)
rdt_rcv(rcvpkt) ampamp isACK(rcvpkt)
udt_send(sndpkt)
rdt_rcv(rcvpkt) ampampisNAK(rcvpkt)
udt_send(NAK)
rdt_rcv(rcvpkt) ampamp corrupt(rcvpkt)
Wait for ACK or
NAK
Wait for call from
belowsender
receiverrdt_send(data)
Λ
Transport Layer 3-20
rdt20 operation with no errors
Wait for call from above
snkpkt = make_pkt(data checksum)udt_send(sndpkt)
extract(rcvpktdata)deliver_data(data)udt_send(ACK)
rdt_rcv(rcvpkt) ampamp notcorrupt(rcvpkt)
rdt_rcv(rcvpkt) ampamp isACK(rcvpkt)
udt_send(sndpkt)
rdt_rcv(rcvpkt) ampampisNAK(rcvpkt)
udt_send(NAK)
rdt_rcv(rcvpkt) ampamp corrupt(rcvpkt)
Wait for ACK or
NAK
Wait for call from
below
rdt_send(data)
Λ
Transport Layer 3-21
rdt20 error scenario
Wait for call from above
snkpkt = make_pkt(data checksum)udt_send(sndpkt)
extract(rcvpktdata)deliver_data(data)udt_send(ACK)
rdt_rcv(rcvpkt) ampamp notcorrupt(rcvpkt)
rdt_rcv(rcvpkt) ampamp isACK(rcvpkt)
udt_send(sndpkt)
rdt_rcv(rcvpkt) ampampisNAK(rcvpkt)
udt_send(NAK)
rdt_rcv(rcvpkt) ampamp corrupt(rcvpkt)
Wait for ACK or
NAK
Wait for call from
below
rdt_send(data)
Λ
Transport Layer 3-22
rdt20 has a fatal flaw
What happens if ACKNAK corruptedsender doesnrsquot know what happened at receivercanrsquot just retransmit possible duplicate
What to dosender ACKsNAKs receiverrsquos ACKNAK What if sender ACKNAK lostretransmit but this might cause retransmission of correctly received pkt
Handling duplicates sender adds sequence number to each pktsender retransmits current pkt if ACKNAK garbledreceiver discards (doesnrsquot deliver up) duplicate pkt
Sender sends one packet then waits for receiver response
stop and wait
Transport Layer 3-23
rdt21 sender handles garbled ACKNAKs
Wait for call 0 from
above
sndpkt = make_pkt(0 data checksum)udt_send(sndpkt)
rdt_send(data)
Wait for ACK or NAK 0 udt_send(sndpkt)
rdt_rcv(rcvpkt) ampamp ( corrupt(rcvpkt) ||isNAK(rcvpkt) )
sndpkt = make_pkt(1 data checksum)udt_send(sndpkt)
rdt_send(data)
rdt_rcv(rcvpkt) ampamp notcorrupt(rcvpkt) ampamp isACK(rcvpkt)
udt_send(sndpkt)
rdt_rcv(rcvpkt) ampamp ( corrupt(rcvpkt) ||isNAK(rcvpkt) )
rdt_rcv(rcvpkt) ampamp notcorrupt(rcvpkt) ampamp isACK(rcvpkt)
Wait forcall 1 from
above
Wait for ACK or NAK 1
ΛΛ
Transport Layer 3-24
rdt21 receiver handles garbled ACKNAKs
Wait for 0 from below
sndpkt = make_pkt(NAK chksum)udt_send(sndpkt)
rdt_rcv(rcvpkt) ampamp not corrupt(rcvpkt) ampamphas_seq0(rcvpkt)
rdt_rcv(rcvpkt) ampamp notcorrupt(rcvpkt) ampamp has_seq1(rcvpkt)
extract(rcvpktdata)deliver_data(data)sndpkt = make_pkt(ACK chksum)udt_send(sndpkt)
Wait for 1 from below
rdt_rcv(rcvpkt) ampamp notcorrupt(rcvpkt) ampamp has_seq0(rcvpkt)
extract(rcvpktdata)deliver_data(data)sndpkt = make_pkt(ACK chksum)udt_send(sndpkt)
rdt_rcv(rcvpkt) ampamp (corrupt(rcvpkt)
sndpkt = make_pkt(ACK chksum)udt_send(sndpkt)
rdt_rcv(rcvpkt) ampamp not corrupt(rcvpkt) ampamphas_seq1(rcvpkt)
rdt_rcv(rcvpkt) ampamp (corrupt(rcvpkt)
sndpkt = make_pkt(ACK chksum)udt_send(sndpkt)
sndpkt = make_pkt(NAK chksum)udt_send(sndpkt)
Transport Layer 3-25
rdt21 discussion
Senderseq added to pkttwo seq rsquos (01) will suffice Whymust check if received ACKNAK corrupted twice as many states
state must ldquorememberrdquowhether ldquocurrentrdquo pkt has 0 or 1 seq
Receivermust check if received packet is duplicate
state indicates whether 0 or 1 is expected pkt seq
note receiver can notknow if its last ACKNAK received OK at sender
Transport Layer 3-26
rdt22 a NAK-free protocol
same functionality as rdt21 using ACKs onlyinstead of NAK receiver sends ACK for last pkt received OK
receiver must explicitly include seq of pkt being ACKed duplicate ACK at sender results in same action as NAK retransmit current pkt
Transport Layer 3-27
rdt22 sender receiver fragments
Wait for call 0 from
above
sndpkt = make_pkt(0 data checksum)udt_send(sndpkt)
rdt_send(data)
udt_send(sndpkt)
rdt_rcv(rcvpkt) ampamp ( corrupt(rcvpkt) ||
isACK(rcvpkt1) )
rdt_rcv(rcvpkt) ampamp notcorrupt(rcvpkt) ampamp isACK(rcvpkt0)
Wait for ACK
0sender FSM
fragment
Wait for 0 from below
rdt_rcv(rcvpkt) ampamp notcorrupt(rcvpkt) ampamp has_seq1(rcvpkt)
extract(rcvpktdata)deliver_data(data)sndpkt = make_pkt(ACK1 chksum)udt_send(sndpkt)
rdt_rcv(rcvpkt) ampamp (corrupt(rcvpkt) ||
has_seq1(rcvpkt))
udt_send(sndpkt)receiver FSM
fragment
Λ
Transport Layer 3-28
rdt30 channels with errors and loss
New assumptionunderlying channel can also lose packets (data or ACKs)
checksum seq ACKs retransmissions will be of help but not enough
Q how to deal with losssender waits until certain data or ACK lost then retransmitsdrawbacks
Approach sender waits ldquoreasonablerdquo amount of time for ACK retransmits if no ACK received in this timeif pkt (or ACK) just delayed (not lost)
retransmission will be duplicate but use of seq rsquos already handles thisreceiver must specify seq of pkt being ACKed
requires countdown timer
Transport Layer 3-29
rdt30 sendersndpkt = make_pkt(0 data checksum)udt_send(sndpkt)start_timer
rdt_send(data)
Wait for
ACK0
rdt_rcv(rcvpkt) ampamp ( corrupt(rcvpkt) ||isACK(rcvpkt1) )
Wait for call 1 from
above
sndpkt = make_pkt(1 data checksum)udt_send(sndpkt)start_timer
rdt_send(data)
rdt_rcv(rcvpkt) ampamp notcorrupt(rcvpkt) ampamp isACK(rcvpkt0)
rdt_rcv(rcvpkt) ampamp ( corrupt(rcvpkt) ||isACK(rcvpkt0) )
rdt_rcv(rcvpkt) ampamp notcorrupt(rcvpkt) ampamp isACK(rcvpkt1)
stop_timerstop_timer
udt_send(sndpkt)start_timer
timeout
udt_send(sndpkt)start_timer
timeout
rdt_rcv(rcvpkt)
Wait for call 0from
above
Wait for
ACK1
Λrdt_rcv(rcvpkt)
ΛΛ
Λ
Transport Layer 3-30
rdt30 in action
Transport Layer 3-31
rdt30 in action
Transport Layer 3-32
Performance of rdt30
rdt30 works but performance stinksexample 1 Gbps link 15 ms e-e prop delay 1KB packet
Ttransmit = 8kbpkt109 bsec = 8 microsec
U sender utilization ndash fraction of time sender busy sending1KB pkt every 30 msec -gt 33kBsec thruput over 1 Gbps linknetwork protocol limits use of physical resources
U sender=
008 30008
= 000027 L RRTT + L R
=
L (packet length in bits)R (transmission rate bps) =
Transport Layer 3-33
rdt30 stop-and-wait operation
first packet bit transmitted t = 0
sender receiver
RTT
last packet bit transmitted t = L R
first packet bit arriveslast packet bit arrives send ACK
ACK arrives send next packet t = RTT + L R
U sender=
00830008
= 000027 L RRTT + L R
=
Transport Layer 3-34
Pipelined protocolsPipelining sender allows multiple ldquoin-flightrdquo yet-to-
be-acknowledged pktsrange of sequence numbers must be increasedbuffering at sender andor receiver
Two generic forms of pipelined protocols go-Back-N selective repeat
Transport Layer 3-35
Pipelining increased utilization
first packet bit transmitted t = 0
sender receiver
RTT
last bit transmitted t = L R
first packet bit arriveslast packet bit arrives send ACK
ACK arrives send next packet t = RTT + L R
last bit of 2nd packet arrives send ACKlast bit of 3rd packet arrives send ACK
U sender=
024 30008
= 000083 L RRTT + L R
=
Increase utilizationby a factor of 3
Transport Layer 3-36
Utilization=N(LR)(RTT+LR) if NLRltRTT+LR Utilization=1 if and the sender pauses after it transmits a window NLRgtRTT+LR and the of packets until it receives first ACK sender does not pause
Transport Layer 3-37
Go-Back-NSender
k-bit seq in pkt headerldquowindowrdquo of up to N consecutive unackrsquoed pkts allowed
ACK(n) ACKs all pkts up to including seq n - ldquocumulative ACKrdquomay receive duplicate ACKs (see receiver)
timer for the entire windowtimeout(n) retransmit pkt n and all higher seq pkts in window
Transport Layer 3-38
GBN sender extended FSM
Wait start_timerudt_send(sndpkt[base])udt_send(sndpkt[base+1])hellipudt_send(sndpkt[nextseqnum-1])
timeout
rdt_send(data)
if (nextseqnum lt base+N) sndpkt[nextseqnum] = make_pkt(nextseqnumdatachksum)udt_send(sndpkt[nextseqnum])if (base == nextseqnum)
start_timernextseqnum++
elserefuse_data(data)
base = getacknum(rcvpkt)+1If (base == nextseqnum)
stop_timerelse
start_timer
rdt_rcv(rcvpkt) ampamp notcorrupt(rcvpkt)
base=1nextseqnum=1
rdt_rcv(rcvpkt) ampamp corrupt(rcvpkt)
Λ
Λ
Transport Layer 3-39
GBN receiver extended FSM
ACK-only always send ACK for correctly-received pktwith highest in-order seq
may generate duplicate ACKsneed only remember expectedseqnum
out-of-order pkt discard (donrsquot buffer) -gt no receiver bufferingRe-ACK pkt with highest in-order seq
Wait
udt_send(sndpkt)default
rdt_rcv(rcvpkt)ampamp notcurrupt(rcvpkt)ampamp hasseqnum(rcvpktexpectedseqnum)
extract(rcvpktdata)deliver_data(data)sndpkt = make_pkt(expectedseqnumACKchksum)udt_send(sndpkt)expectedseqnum++
expectedseqnum=1sndpkt =
make_pkt(0ACKchksum)
Λ
Transport Layer 3-40
GBN inaction
Transport Layer 3-41
Selective Repeat
receiver individually acknowledges all correctly received pkts
buffers pkts as needed for eventual in-order delivery to upper layer
sender only resends pkts for which ACK not received
sender timer for each unACKed pktsender window
N consecutive seq rsquosagain limits seq s of sent unACKed pkts
Transport Layer 3-42
Selective repeat sender receiver windows
Transport Layer 3-43
Selective repeat
data from above if next available seq in window send pkt
timeout(n)resend pkt n restart timer
ACK(n) in [sendbasesendbase+N-1]
mark pkt n as receivedif n smallest unACKed pkt advance window base to next unACKed seq
senderpkt n in [rcvbase rcvbase+N-1]
send ACK(n)out-of-order bufferin-order deliver (also deliver buffered in-order pkts) advance window to next not-yet-received pkt
pkt n in [rcvbase-Nrcvbase-1]
ACK(n)otherwise
ignore
receiver
Transport Layer 3-44
Selective repeat in action
Transport Layer 3-45
Selective repeatdilemma
Example seq rsquos 0 1 2 3window size=3
receiver sees no difference in two scenariosincorrectly passes duplicate data as new in (a)
Q what relationship between seq size and window size
Transport Layer 3-46
Sequence Number vs Window SizeSuppose we use k bits to represent SNQuestion Whatrsquos the minimum number of bits k necessary for a window size of N
sender
receiver
Go-Back-N
expectedSN
snd_base=expectedSN
Q For a given expectedSN whatrsquos the largest possible value for snd_baseA If all the last N ACKs sent by the receiver are received
snd_base = expectedSNexpectedSN+N-1
senderrsquos window
Transport Layer 3-47
Sequence Number vs Window SizeSuppose we use k bits to represent SNQuestion Whatrsquos the minimum number of bits k necessary for a window size of N
sender
receiver
Go-Back-N
expectedSN
snd_base=expectedSN-N
Q For a given expectedSN whatrsquos the smallest possible value for snd_baseA If all the last N ACKs sent by the receiver are not received
snd_base = expectedSN-NexpectedSN-1
senderrsquos window
Transport Layer 3-48
Sequence Number vs Window Size
sender
receiver
Go-Back-N
expectedSN
snd_base=expectedSN-N
All SNs in the interval [expectedSN-NexpectedSN+N-1] (an interval of size 2N) can be received by the receiver Since the receiver accepts on the packet with SN=expectedSN there should be no other packet within this interval with SN=expectedSN Therefore
2k ge N+1expectedSN+N-1
Transport Layer 3-49
Sequence Number vs Window SizeSuppose we use k bits to represent SNQuestion Whatrsquos the minimum number of bits k necessary for a window size of N
sender
receiver
Selective Repeat
rcv_base
snd_base=rcv_base
Q For a given rcv_base whatrsquos the largest possible value for snd_baseA If all the last N ACKs sent by the receiver are received
snd_base = rcv_base (same as go_back-N)rcv_base+N-1
senderrsquos window
receiverrsquos window
rcv_base+N-1
Transport Layer 3-50
Sequence Number vs Window SizeSuppose we use k bits to represent SNQuestion Whatrsquos the minimum number of bits k necessary for a window size of N
sender
receiver
Selective Repeat
rcv_base
snd_base=rcv_base-N
Q For a given rcv_base whatrsquos the smallest possible value for snd_baseA If all the last N ACKs sent by the receiver are not received
snd_base = rcv_base-N (same as Go-Back-N)rcv_base-1
senderrsquos window
rcv_base
receiverrsquos window
rcv_base+N-1
Transport Layer 3-51
Sequence Number vs Window Size
sender
receiver
Selective Repeat
snd_base=rcv_base-N
All SNs in the interval [rcv_base-Nrcv_base+N-1] (an interval of size 2N) can be received by the receiver Since the receiver should be able to distinguish between all packets in this interval and take corresponding action there should be no two packets within thisinterval having the same SN Therefore
2k ge 2Nrcv_base+N-1
rcv_basercv_base
receiverrsquos window
rcv_base+N-1
Transport Layer 3-52
TCP Overview RFCs 793 1122 1323 2018 2581
full duplex databi-directional data flow in same connectionMSS maximum segment size
connection-orientedhandshaking (exchange of control msgs) initrsquossender receiver state before data exchange
flow controlledsender will not overwhelm receiver
point-to-pointone sender one receiver
reliable in-order byte stream
no ldquomessage boundariesrdquopipelined
TCP congestion and flow control set window size
send amp receive buffers
socketdoor
TCPsend buffer
TCPreceive buffer
socketdoor
segment
applicationwrites data
applicationreads data
Transport Layer 3-53
TCP segment structure
source port dest port
32 bits
applicationdata
(variable length)
sequence numberacknowledgement number
Receive windowUrg data pnterchecksum
FSRPAUheadlen
notused
Options (variable length)
URG urgent data (generally not used)
ACK ACK valid
PSH push data now(generally not used)
RST SYN FINconnection estab(setup teardown
commands)
bytes rcvr willingto accept
Internetchecksum
(as in UDP)
countingby bytes of data(not segments)
Transport Layer 3-54
TCP seq rsquos and ACKsSeq rsquos
byte stream ldquonumberrdquo of first byte in segmentrsquos dataACKs
seq of next byte expected from other sidecumulative ACK
Q how receiver handles out-of-order segmentsA TCP spec doesnrsquot say - up to implementationWidely used implementations of TCP buffer out-of-order segments
Transport Layer 3-55
TCP Round Trip Time and Timeout
Q how to set TCP timeout valuelonger than RTT
but RTT variestoo short premature timeout
unnecessary retransmissions
too long slow reaction to segment loss
Q how to estimate RTTSampleRTT measured time from segment transmission until ACK receipt
ignore retransmissionsSampleRTT will vary want estimated RTT ldquosmootherrdquo
average several recent measurements not just current SampleRTT
Transport Layer 3-56
TCP Round Trip Time and Timeout
EstimatedRTT = (1- α)EstimatedRTT + αSampleRTT
Exponential weighted moving averageinfluence of past sample decreases exponentially fasttypical value α = 0125
Transport Layer 3-57
Example RTT estimationRTT gaiacsumassedu to fantasiaeurecomfr
100
150
200
250
300
350
1 8 15 22 29 36 43 50 57 64 71 78 85 92 99 106
time (seconnds)
RTT
(mill
iseco
nds)
SampleRTT Estimated RTT
Transport Layer 3-58
TCP Round Trip Time and TimeoutSetting the timeout
EstimatedRTT plus ldquosafety marginrdquolarge variation in EstimatedRTT -gt larger safety margin
first estimate of how much SampleRTT deviates from EstimatedRTT
TimeoutInterval = EstimatedRTT + 4DevRTT
DevRTT = (1-β)DevRTT +β|SampleRTT-EstimatedRTT|
(typically β = 025)
Then set timeout interval
Transport Layer 3-59
TCP reliable data transfer
TCP creates rdtservice on top of IPrsquos unreliable servicePipelined segmentsCumulative acksTCP uses single retransmission timer however it just retransmits the first segment in the window
Retransmissions are triggered by
timeout eventsduplicate acks
Initially consider simplified TCP sender
ignore duplicate acksignore flow control congestion control
Transport Layer 3-60
TCP sender eventsdata rcvd from app
Create segment with seq seq is byte-stream number of first data byte in segmentstart timer if not already running (think of timer as for oldest unacked segment)expiration interval TimeOutInterval
timeoutretransmit segment that caused timeout (first segment in the window)restart timer
Ack rcvdIf acknowledges previously unacked segments
update what is known to be ackedstart timer if there are outstanding segments
Transport Layer 3-61
TCP sender(simplified)
NextSeqNum = InitialSeqNumSendBase = InitialSeqNum
loop (forever) switch(event)
event data received from application above create TCP segment with sequence number NextSeqNumif (timer currently not running)
start timerpass segment to IP NextSeqNum = NextSeqNum + length(data)
event timer timeoutretransmit not-yet-acknowledged segment with
smallest sequence numberstart timer
event ACK received with ACK field value of y if (y gt SendBase)
SendBase = yif (there are currently not-yet-acknowledged segments)
start timer
end of loop forever
Commentbull SendBase-1 last cumulatively ackrsquoed byteExamplebull SendBase-1 = 71y= 73 so the rcvrwants 73+ y gt SendBase sothat new data is acked
Transport Layer 3-62
TCP retransmission scenariosHost A
Seq=100 20 bytes data
ACK=100
timepremature timeout
Host B
Seq=92 8 bytes data
ACK=120
Seq=92 8 bytes data
Seq=
92 t
imeo
ut
ACK=120
Host A
Seq=92 8 bytes data
ACK=100
loss
tim
eout
lost ACK scenario
Host B
X
Seq=92 8 bytes data
ACK=100
time
Seq=
92 t
imeo
utSendBase
= 100
SendBase= 120
SendBase= 120
Sendbase= 100
Transport Layer 3-63
TCP retransmission scenarios (more)Host A
Seq=92 8 bytes data
ACK=100
loss
tim
eout
Cumulative ACK scenario
Host B
X
Seq=100 20 bytes data
ACK=120
time
SendBase= 120
Transport Layer 3-64
TCP ACK generation [RFC 1122 RFC 2581]
Event at Receiver
Arrival of in-order segment withexpected seq All data up toexpected seq already ACKed
Arrival of in-order segment withexpected seq One other segment has ACK pending
Arrival of out-of-order segmenthigher-than-expect seq Gap detected
Arrival of segment that partially or completely fills gap
TCP Receiver action
Delayed ACK Wait up to 500msfor next segment If no next segmentsend ACK
Immediately send single cumulative ACK ACKing both in-order segments
Immediately send duplicate ACK indicating seq of next expected byte
Immediate send ACK provided thatsegment startsat lower end of gap
Transport Layer 3-65
Fast Retransmit
Time-out period often relatively long
long delay before resending lost packet
Detect lost segments via duplicate ACKs
Sender often sends many segments back-to-backIf segment is lost there will likely be many duplicate ACKs
If sender receives 3 ACKs for the same data it supposes that segment after ACKeddata was lost
fast retransmit resend segment before timer expires
Transport Layer 3-66
Fast RetransmitResend a segment after 3 duplicate ACKs since a duplicate ACK means that an out-of sequence segment was receivedduplicate ACKs due to packet reorderingif window is small donrsquot get duplicate ACKs
Host A
tim
eout
Host B
time
X
resend seq X2
seq x1seq x2seq x3seq x4seq x5
ACK x1
ACK x1ACK x1ACK x1
tripleduplicate
ACKs
Transport Layer 3-67
event ACK received with ACK field value of y if (y gt SendBase)
SendBase = yif (there are currently not-yet-acknowledged segments)
start timer
else increment count of dup ACKs received for yif (count of dup ACKs received for y = 3)
resend segment with sequence number y
Fast retransmit algorithm
a duplicate ACK for already ACKed segment
fast retransmit
Transport Layer 3-68
TCP Flow Control
receive side of TCP connection has a receive buffer
speed-matching service matching the send rate to the receiving apprsquos drain rate
app process may be slow at reading from buffer
sender wonrsquot overflowreceiverrsquos buffer by
transmitting too muchtoo fast
flow control
Transport Layer 3-69
TCP Flow control how it works
(Suppose TCP receiver discards out-of-order segments)spare room in buffer
= RcvWin
= RcvBuffer-[LastByteRcvd -LastByteRead]
Rcvr advertises spare room by including value of RcvWin in segmentsSender limits unACKeddata to RcvWin
guarantees receive buffer doesnrsquot overflow
Transport Layer 3-70
Sliding Window Flow Control Example
3K
2K SeqNo=0
ReceiverBuffer
0 4KSendersends 2Kof data
2K
AckNo=2048 RcvWin=2048Sendersends 2Kof data 2K SeqNo=2048
4K
AckNo=4096 RcvWin=0
AckNo=4096 RcvWin=1024
Sender blocked
Transport Layer 3-71
Principles of Congestion Control
Congestioninformally ldquotoo many sources sending too much data too fast for network to handlerdquodifferent from flow controlmanifestations
lost packets (buffer overflow at routers)long delays (queueing in router buffers)
a top-10 problem
Transport Layer 3-72
Causescosts of congestion scenario 1
two senders two receiversone router infinite buffers no retransmission
large delays when congestedmaximum achievable throughput
unlimited shared output link buffers
Host Aλin original data
Host B
λout
Transport Layer 3-73
Causescosts of congestion scenario 2
one router finite buffers sender retransmission of lost packet
finite shared output link buffers
Host A λin original data
Host B
λout
λin original data plus retransmitted data
Transport Layer 3-74
Causescosts of congestion scenario 2always (goodput)ldquoperfectrdquo retransmission only when loss
retransmission of delayed (not lost) packet makes larger(than perfect case) for same
λin
λout=
λin
λoutgtλ
inλout
ldquocostsrdquo of congestionmore work (retrans) for given ldquogoodputrdquounneeded retransmissions link carries multiple copies of pkt
R2
R2λin
λ out
b
R2
R2λin
λ out
a
R2
R2λin
λ out
c
R4
R3
Transport Layer 3-75
Causescosts of congestion scenario 3four sendersmultihop pathstimeoutretransmit
λin
Q what happens as and increase λ
in
finite shared output link buffers
Host Aλin original data
Host B
λout
λin original data plus retransmitted data
Transport Layer 3-76
Causescosts of congestion scenario 3
another ldquocostrdquo of congestionwhen packet dropped any ldquoupstream transmission capacity used for that packet was wasted
Host A
Host B
λou
t
Transport Layer 3-77
Approaches towards congestion control
End-end congestion controlno explicit feedback from networkcongestion inferred from end-system observed loss delayapproach taken by TCP
Network-assisted congestion controlrouters provide feedback to end systems
single bit indicating congestion (SNA DECbit TCPIP ECN ATM)explicit rate sender should send at
Two broad approaches towards congestion control
Transport Layer 3-78
TCP Congestion Control
end-end control (no network assistance)sender limits transmissionLastByteSent-LastByteAcked
le CongWin
CongWin is dynamic function of perceived network congestion
How does sender perceive congestionloss event = timeout or3 duplicate acksTCP sender reduces rate (CongWin) after loss event
two modes of operationSlow Start (SS)Congestion avoidance (CA) or Additive Increase Multiplicative Decrease (AIMD)
Transport Layer 3-79
TCP congestion control bandwidth probing
ldquoprobing for bandwidthrdquo increase transmission rate on receipt of ACK until eventually loss occurs then decrease transmission rate
continue to increase on ACK decrease on loss (since available bandwidth is changing depending on other connections in network)
ACKs being received so increase rate
X
X
XX
X loss so decrease rate
send
ing
rate
time
Q how fast to increasedecreasedetails to follow
TCPrsquosldquosawtoothrdquobehavior
Transport Layer 3-80
TCP Congestion Control details
sender limits rate by limiting number of unACKed bytes ldquoin pipelinerdquo
cwnd differs from rwnd (how why)sender limited by min(cwndrwnd)
roughly
cwnd is dynamic function of perceived network congestion
rate = cwndRTT bytessec
LastByteSent-LastByteAcked le cwnd
cwndbytes
RTT
ACK(s)
Transport Layer 3-81
TCP Congestion Control more details
segment loss event reducing cwndtimeout no response from receiver
cut cwnd to 13 duplicate ACKs at least some segments getting through (recall fast retransmit)
cut cwnd in half less aggressively than on timeout
ACK received increase cwndTwo modes of operation
slowstart phase bull increase exponentially
fast (despite name) at connection start or following timeout
congestion avoidance bull increase linearly
Transport Layer 3-82
TCP Slow Start Phasewhen connection begins cwnd = 1 MSS
example MSS = 500 bytes amp RTT = 200 msecinitial rate = 20 kbps
available bandwidth may be gtgt MSSRTT
desirable to quickly ramp up to respectable rate
increase rate exponentially until first loss event or when threshold reached
double cwnd every RTTdone by incrementing cwnd by 1 for every ACK received
Host A
one segment
RTT
Host B
time
two segments
four segments
Transport Layer 3-83
Slow Start ExampleThe congestion window size grows very rapidly
For every ACK we increase CongWin by 1 irrespective of the number of segments ACKrsquoeddouble CongWinevery RTTinitial rate is slow but ramps up exponentially fast
TCP slows down the increase of CongWinwhen CongWin gt ssthresh
segment 1
ACK for segment 1
cwnd = 1
cwnd = 2 segment 2segment 3
ACK for segments 2
cwnd = 4 segment 4segment 5segment 6
ACK for segments 4
cwnd = 7
ACK for segments 3
ACK for segments 5
ACK for segments 6
cwnd = 3
cwnd = 5
cwnd = 6ACK for segments 7
cwnd = 8
segment 7
Transport Layer 3-84
TCP Congestion Avoidance Phase
when cwnd gt ssthreshgrow cwnd linearly
increase cwnd by 1 MSS per RTT approach possible congestion slower than in slowstartimplementation cwnd= cwnd + MSScwndfor each ACK received
ACKs increase cwndby 1 MSS per RTT additive increaseloss cut cwnd in half (non-timeout-detected loss ) multiplicative decrease
AIMD
AIMD Additive IncreaseMultiplicative Decrease
Transport Layer 3-85
Congestion AvoidanceCongestion avoidance phase is started if CongWin has reached the slow-start threshold value
If CongWin gt= ssthresh then each time an ACK is received increment CongWin as follows
bull CongWin = CongWin + 1CongWin (CongWin in segments)
bull In actual TCP implementation CongWin is in BytesCongWin = CongWin + MSS (MSSCongWin)
So CongWin is increased by one only if all CongWinsegments have been acknowledged
Transport Layer 3-86
Example Slow StartCongestion AvoidanceAssume that
ssthresh = 8
cwnd = 1
cwnd = 2
cwnd = 4
cwnd = 8
cwnd = 9
cwnd = 10
02468
101214
t=0
t=2
t=4
t=6
Roundtrip times
Cw
nd(in
seg
men
ts)
ssthresh
cwnd = 3
cwnd = 5cwnd = 6cwnd = 7
Transport Layer 3-87
Slow Start Congestion AvoidanceA typical plot of CongWin for a TCP connection
(MSS = 1500 bytes) with TCP Tahoe
SS
CA
ssthresh
Transport Layer 3-88
Responses to CongestionTCP assumes there is congestion if it detects a packet lossA TCP sender can detect lost packets via loss events
bull Timeout of a retransmission timerbull Receipt of 3 duplicate ACKs (fast retransmit)
TCP interprets a Timeout as a binary congestion signal When a timeout occurs the sender performs
ssthresh is set to half the current size of the congestion window
ssthresh = CongWin 2CongWin is reset to one
CongWin = 1and slow-start is entered
Transport Layer 3-89
Fast Recovery (differentiation btwn two loss events) After 3 dup ACKs (fast Retransmit)
ssthresh = CongWin2CongWin = CongWin2window then grows linearly
But after timeout eventCongWin = 1 MSS window then grows exponentiallyto the threshold then grows linearly
bull 3 dup ACKs indicates network capable of delivering some segmentsbull timeout before 3 dup ACKs is ldquomore alarmingrdquo
Philosophy
3-90
TCP Congestion ControlInitially
CongWin = 1ssthresh = advertised window size
New Ack receivedif (CongWin lt ssthresh) Slow Start
CongWin = CongWin + 1else Congestion Avoidance
CongWin = CongWin + 1CongWinTimeout
ssthresh = CongWin2CongWin = 1
Fast Retransmissionssthresh = CongWin2CongWin = CongWin2
Slow Start (exponential increase phase) is continued until CongWin reaches half of the level where the loss event occurred last time CongWin is increased slowly after (linear increase in Congestion Avoidance phase)
Transport Layer 3-91
Popular ldquoflavorsrdquo of TCP
ssthresh
ssthresh
TCP Tahoe
TCP Reno
Transmission round
cwnd
win
dow
siz
e (in
seg
men
ts)
Transport Layer 3-92
Summary TCP Congestion ControlWhen CongWin is below Threshold sender in slow-start phase window grows exponentiallyWhen CongWin is above Threshold sender is in congestion-avoidance phase window grows linearlyWhen a triple duplicate ACK occurs Threshold set to CongWin2 and CongWin set to ThresholdWhen timeout occurs Threshold set to CongWin2 and CongWin is set to 1 MSS The actual sender window size is determined based on the congestion and flow control algorithms
SenderWin=min(RcvWinCongWin)
Transport Layer 3-93
TCP Congestion Control SummaryEvent State TCP Sender Action Commentary
ACK receipt for previously unackeddata
Slow Start (SS)
CongWin = CongWin + MSS If (CongWin gt Threshold)
set state to ldquoCongestion Avoidancerdquo
Resulting in a doubling of CongWin every RTT
ACK receipt for previously unackeddata
CongestionAvoidance (CA)
CongWin = CongWin+MSS (MSSCongWin)
Additive increase resulting in increase of CongWin by 1 MSS every RTT
Loss event detected by triple duplicate ACK
SS or CA Threshold = CongWin2 CongWin = ThresholdSet state to ldquoCongestion Avoidancerdquo
Fast recovery implementing multiplicative decrease CongWin will not drop below 1 MSS
Timeout SS or CA Threshold = CongWin2 CongWin = 1 MSSSet state to ldquoSlow Startrdquo
Enter slow start
Duplicate ACK
SS or CA Increment duplicate ACK count for segment being acked
CongWin and Threshold not changed
Transport Layer 3-94
TCP throughput
Q whatrsquos average throughout of TCP as function of window size RTT
ignoring slow startlet W be window size when loss occurs
when window is W throughput is WRTTjust after loss window drops to W2 throughput to W2RTT average throughout 75 WRTT
Transport Layer 3-95
TCP Futures TCP over ldquolong fat pipesrdquo
example 1500 byte segments 100ms RTT want 10 Gbps throughputrequires window size W = 83333 in-flight segmentsthroughput in terms of loss rate
L = 210-10 Wownew versions of TCP for high-speed
LRTTMSSsdot221
Transport Layer 3-96
Fairness goal if K TCP sessions share same bottleneck link of bandwidth R each should have average rate of RK
TCP connection 1
bottleneckrouter
capacity R
TCP connection 2
TCP Fairness
Transport Layer 3-97
Why is TCP fairTwo competing sessions
Additive increase gives slope of 1 as throughout increasesmultiplicative decrease decreases throughput proportionally
R
R
equal bandwidth share
Connection 1 throughput
Conn
ecti
on 2
thr
ough
p ut
congestion avoidance additive increaseloss decrease window by factor of 2
congestion avoidance additive increaseloss decrease window by factor of 2
Transport Layer 3-98
Fairness (more)Fairness and UDP
Multimedia apps often do not use TCP
do not want rate throttled by congestion control
Instead use UDPpump audiovideo at constant rate tolerate packet loss
Research area TCP friendly
Fairness and parallel TCP connectionsnothing prevents app from opening parallel cnctionsbetween 2 hostsWeb browsers do this Example link of rate R supporting 9 cnctions
new app asks for 1 TCP gets rate R10new app asks for 11 TCPs gets R2
Transport Layer 3-99
TCP Connection ManagementRecall TCP sender receiver
establish ldquoconnectionrdquobefore exchanging data segmentsinitialize TCP variables
seq sbuffers flow control info (eg RcvWindow)
client connection initiatorSocket clientSocket = new Socket(hostnameport
number)
server contacted by clientSocket connectionSocket = welcomeSocketaccept()
Three way handshakeStep 1 client host sends TCP
SYN segment to serverspecifies initial seq no data
Step 2 server host receives SYN replies with SYNACK segment
server allocates buffersspecifies server initial seq
Step 3 client receives SYNACK replies with ACK segment which may contain data
Transport Layer 3-100
TCP Connection Management (cont)
Closing a connection
client closes socketclientSocketclose()
Step 1 client end system sends TCP FIN control segment to server
Step 2 server receives FIN replies with ACK Closes connection sends FIN
client
FIN
server
ACK
ACK
FIN
close
close
closed
tim
ed w
ait
Transport Layer 3-101
TCP Connection Management (cont)
Step 3 client receives FIN replies with ACK
Enters ldquotimed waitrdquo -will respond with ACK to received FINs
Step 4 server receives ACK Connection closed
client
FIN
server
ACK
ACK
FIN
closing
closing
closed
tim
ed w
ait
closed
Transport Layer 3-102
TCP Connection Management (cont)
TCP clientlifecycle
TCP serverlifecycle
Transport Layer 3-103
Tuning TCPIP Parameters TCPIP parameters
A set of default values may not be optimal for all applicationsThe network administrator may wish to turn on or off some TCPIP functions for performance or security considerations
Many Unix and Linux systems provide some flexibility in tuning the TCPIP kernelsbinsysctl is used to configure the Linux kernel parameters at runtime
Default kernel configuration file is sbinsysctlconfFrequently used sysctl options
bull sysctl ndasha or sysctl ndashA list all current valuesbull sysctl ndashp file_name load the sysctl setting from a configuration
filebull sysctl ndashw variable=value change the value of the parameter
Transport Layer 3-104
SomeTCP Parameters in Linux Kerneltcp_syn_retries
Number of SYN packets the kernel will send before giving up on the new connection
tcp_synack_retriesnumber of SYN+ACK packets sent before the kernel gives up on the connection
tcp_window_scalingMaximum window size of 65535 bytes not enough for for really fast networks The window scaling options allows for almost gigabyte windows which is good for connections with large delay-bandwidth product
tcp_max_syn_backlogMaximal number of remembered connection requests which still did not receive an acknowledgment from connecting client
tcp_fin_timeoutHow many seconds to wait for a final FIN packet before the socket is closed required to prevent denial-of-service (DoS) attacks Default value is 60 seconds
Transport Layer 3-105
SomeTCP Parameters in Linux Kerneltcp_rmem
This is a vector of 3 integers [min default max] These parameters are used by TCP to dynamically adjust receive buffer sizesmin - minimum size of the receive buffer used by each TCP socket The default value is 4K default - the default size of the receive buffer for a TCP socket The default value is 87380 bytes and is lowered to 43689 in low memory systems If larger receive buffer sizes are desired this value should be increased max - the maximum size of the receive buffer used by each TCP socket The default value of 873802 bytes is lowered to 87380 in low memory systems
tcp_smemSend buffer parameters [min default max] similar to tcp_rmem
- Chapter 3 Transport Layer
- Transport services and protocols
- Transport vs network layer
- Internet transport-layer protocols
- Multiplexingdemultiplexing
- How demultiplexing works
- Connectionless demultiplexing
- Connection-oriented demux
- Connection-oriented demux (cont)
- Connection-oriented demux Threaded Web Server
- UDP User Datagram Protocol [RFC 768]
- UDP more
- UDP checksum
- Principles of Reliable data transfer
- Reliable data transfer getting started
- Reliable data transfer getting started
- Rdt10 reliable transfer over a reliable channel
- Rdt20 channel with bit errors
- rdt20 FSM specification
- rdt20 operation with no errors
- rdt20 error scenario
- rdt20 has a fatal flaw
- rdt21 sender handles garbled ACKNAKs
- rdt21 receiver handles garbled ACKNAKs
- rdt21 discussion
- rdt22 a NAK-free protocol
- rdt22 sender receiver fragments
- rdt30 channels with errors and loss
- rdt30 sender
- rdt30 in action
- rdt30 in action
- Performance of rdt30
- rdt30 stop-and-wait operation
- Pipelined protocols
- Pipelining increased utilization
- Go-Back-N
- GBN sender extended FSM
- GBN receiver extended FSM
- GBN inaction
- Selective Repeat
- Selective repeat sender receiver windows
- Selective repeat
- Selective repeat in action
- Selective repeat dilemma
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- TCP Overview RFCs 793 1122 1323 2018 2581
- TCP segment structure
- TCP seq rsquos and ACKs
- TCP Round Trip Time and Timeout
- TCP Round Trip Time and Timeout
- Example RTT estimation
- TCP Round Trip Time and Timeout
- TCP reliable data transfer
- TCP sender events
- TCP sender(simplified)
- TCP retransmission scenarios
- TCP retransmission scenarios (more)
- TCP ACK generation [RFC 1122 RFC 2581]
- Fast Retransmit
- Fast Retransmit
- Fast retransmit algorithm
- TCP Flow Control
- TCP Flow control how it works
- Sliding Window Flow Control Example
- Principles of Congestion Control
- Causescosts of congestion scenario 1
- Causescosts of congestion scenario 2
- Causescosts of congestion scenario 2
- Causescosts of congestion scenario 3
- Causescosts of congestion scenario 3
- Approaches towards congestion control
- TCP Congestion Control
- TCP congestion control bandwidth probing
- TCP Congestion Control details
- TCP Congestion Control more details
- TCP Slow Start Phase
- Slow Start Example
- TCP Congestion Avoidance Phase
- Congestion Avoidance
- Example Slow StartCongestion Avoidance
- Slow Start Congestion Avoidance
- Responses to Congestion
- Fast Recovery (differentiation btwn two loss events)
- TCP Congestion Control
- Popular ldquoflavorsrdquo of TCP
- Summary TCP Congestion Control
- TCP Congestion Control Summary
- TCP throughput
- TCP Futures TCP over ldquolong fat pipesrdquo
- TCP Fairness
- Why is TCP fair
- Fairness (more)
- TCP Connection Management
- TCP Connection Management (cont)
- TCP Connection Management (cont)
- TCP Connection Management (cont)
- Tuning TCPIP Parameters
- SomeTCP Parameters in Linux Kernel
- SomeTCP Parameters in Linux Kernel
-
Transport Layer 3-2
Transport services and protocolsprovide logical communicationbetween app processes running on different hoststransport protocols run in end systems
send side breaks app messages into segments passes to network layerrcv side reassembles segments into messages passes to app layer
more than one transport protocol available to apps
Internet TCP and UDP
applicationtransportnetworkdata linkphysical
applicationtransportnetworkdata linkphysical
networkdata linkphysical
networkdata linkphysical
networkdata linkphysical
networkdata linkphysicalnetwork
data linkphysical
logical end-end transport
Transport Layer 3-3
Transport vs network layer
network layer logical communication between hoststransport layer logical communication between processes
relies on enhances network layer services
Household analogy12 kids sending letters
to 12 kidsprocesses = kidsapp messages = letters in envelopeshosts = housestransport protocol = Ayşe and Buumllentnetwork-layer protocol = postal service
Transport Layer 3-4
Internet transport-layer protocols
reliable in-order delivery (TCP)
congestion control flow controlconnection setup
unreliable unordered delivery UDP
no-frills extension of ldquobest-effortrdquo IP
services not available delay guaranteesbandwidth guarantees
applicationtransportnetworkdata linkphysical
applicationtransportnetworkdata linkphysical
networkdata linkphysical
networkdata linkphysical
networkdata linkphysical
networkdata linkphysicalnetwork
data linkphysical
logical end-end transport
Transport Layer 3-5
Multiplexingdemultiplexing
application
transport
network
link
physical
P1 application
transport
network
link
physical
application
transport
network
link
physical
P2P3 P4P1
host 1 host 2 host 3
= process= socket
delivering received segmentsto correct socket
Demultiplexing at rcv hostgathering data from multiplesockets enveloping data with header (later used for demultiplexing)
Multiplexing at send host
Transport Layer 3-6
How demultiplexing workshost receives IP datagrams
each datagram has source IP address destination IP addresseach datagram carries 1 transport-layer segmenteach segment has source destination port number (recall well-known port numbers for specific applications)
host uses IP addresses amp port numbers to direct segment to appropriate socket
source port dest port
32 bits
applicationdata
(message)
other header fields
TCPUDP segment format
Transport Layer 3-7
Connectionless demultiplexing
Create sockets with port numbers
DatagramSocket mySocket1 = new DatagramSocket(9111)
DatagramSocket mySocket2 = new DatagramSocket(9222)
UDP socket identified by two-tuple
(dest IP address dest port number)
When host receives UDP segment
checks destination port number in segmentdirects UDP segment to socket with that port number
IP datagrams with different source IP addresses andor source port numbers directed to same socket
Transport Layer 3-8
Connection-oriented demux
TCP socket identified by 4-tuple
source IP addresssource port numberdest IP addressdest port number
recv host uses all four values to direct segment to appropriate socket
Server host may support many simultaneous TCP sockets
each socket identified by its own 4-tuple
Web servers have different sockets for each connecting client
non-persistent HTTP will have different socket for each request
Transport Layer 3-9
Connection-oriented demux(cont)
ClientIPB
P1
clientIP A
P1P2P4
serverIP C
SP 9157DP 80
SP 9157DP 80
P5 P6 P3
D-IPCS-IP AD-IPC
S-IP B
SP 5775DP 80
D-IPCS-IP B
Transport Layer 3-10
Connection-oriented demuxThreaded Web Server
ClientIPB
P1
clientIP A
P1P2P4
serverIP C
SP 9157DP 80
SP 9157DP 80
P5 P6 P3
D-IPCS-IP AD-IPC
S-IP B
SP 5775DP 80
D-IPCS-IP B
P4
Transport Layer 3-11
UDP User Datagram Protocol [RFC 768]
ldquono frillsrdquo ldquobare bonesrdquoInternet transport protocolldquobest effortrdquo service UDP segments may be
lostdelivered out of order to app
connectionlessno handshaking between UDP sender receivereach UDP segment handled independently of others
Why is there a UDPno connection establishment (which can add delay)simple no connection state at sender receiversmall segment headerno congestion control UDP can blast away as fast as desired
Transport Layer 3-12
UDP moreoften used for streaming multimedia apps
loss tolerantrate sensitive
other UDP usesDNSSNMP
reliable transfer over UDP add reliability at application layer
application-specific error recovery
source port dest port
32 bits
Applicationdata
(message)
UDP segment format
length checksumLength in
bytes of UDPsegmentincluding
header
Transport Layer 3-13
UDP checksum
Sendertreat segment contents as sequence of 16-bit integerschecksum addition (1rsquos complement sum) of segment contents with wraparound of carry out bitsender puts checksum value into UDP checksum field
Receivercompute checksum of received segmentcheck if computed checksum equals checksum field value
NO - error detectedYES - no error detected
Goal detect ldquoerrorsrdquo (eg flipped bits) in transmitted segment
Transport Layer 3-14
Principles of Reliable data transferimportant in app transport link layerstop-10 list of important networking topics
characteristics of unreliable channel will determine complexity of reliable data transfer protocol (rdt)
netw
ork
laye
r
Transport Layer 3-15
Reliable data transfer getting started
sendside
receiveside
rdt_send() called from above (eg by app) Passed data to
deliver to receiver upper layer
udt_send() called by rdtto transfer packet over
unreliable channel to receiver
rdt_rcv() called when packet arrives on rcv-side of channel
deliver_data() called by rdt to deliver data to upper
Transport Layer 3-16
Reliable data transfer getting startedWersquoll
incrementally develop sender receiver sides of reliable data transfer protocol (rdt)consider only unidirectional data transfer
but control info will flow on both directionsuse finite state machines (FSM) to specify sender receiver
state1
state2
event causing state transitionactions taken on state transition
state when in this ldquostaterdquo next state
uniquely determined by next event
eventactions
Transport Layer 3-17
Rdt10 reliable transfer over a reliable channel
underlying channel perfectly reliableno bit errorsno loss of packets
separate FSMs for sender receiversender sends data into underlying channelreceiver read data from underlying channel
Wait for call from above packet = make_pkt(data)
udt_send(packet)
rdt_send(data)extract (packetdata)deliver_data(data)
Wait for call from
below
rdt_rcv(packet)
sender receiver
Transport Layer 3-18
Rdt20 channel with bit errors
underlying channel may flip bits in packetrecall checksum to detect bit errors
the question how to recover from errorsacknowledgements (ACKs) receiver explicitly tells sender that pkt received OKnegative acknowledgements (NAKs) receiver explicitly tells sender that pkt had errorssender retransmits pkt on receipt of NAK
new mechanisms in rdt20 (beyond rdt10)error detectionreceiver feedback control msgs (ACKNAK) rcvr-gtsender
Transport Layer 3-19
rdt20 FSM specification
Wait for call from above
snkpkt = make_pkt(data checksum)udt_send(sndpkt)
extract(rcvpktdata)deliver_data(data)udt_send(ACK)
rdt_rcv(rcvpkt) ampamp notcorrupt(rcvpkt)
rdt_rcv(rcvpkt) ampamp isACK(rcvpkt)
udt_send(sndpkt)
rdt_rcv(rcvpkt) ampampisNAK(rcvpkt)
udt_send(NAK)
rdt_rcv(rcvpkt) ampamp corrupt(rcvpkt)
Wait for ACK or
NAK
Wait for call from
belowsender
receiverrdt_send(data)
Λ
Transport Layer 3-20
rdt20 operation with no errors
Wait for call from above
snkpkt = make_pkt(data checksum)udt_send(sndpkt)
extract(rcvpktdata)deliver_data(data)udt_send(ACK)
rdt_rcv(rcvpkt) ampamp notcorrupt(rcvpkt)
rdt_rcv(rcvpkt) ampamp isACK(rcvpkt)
udt_send(sndpkt)
rdt_rcv(rcvpkt) ampampisNAK(rcvpkt)
udt_send(NAK)
rdt_rcv(rcvpkt) ampamp corrupt(rcvpkt)
Wait for ACK or
NAK
Wait for call from
below
rdt_send(data)
Λ
Transport Layer 3-21
rdt20 error scenario
Wait for call from above
snkpkt = make_pkt(data checksum)udt_send(sndpkt)
extract(rcvpktdata)deliver_data(data)udt_send(ACK)
rdt_rcv(rcvpkt) ampamp notcorrupt(rcvpkt)
rdt_rcv(rcvpkt) ampamp isACK(rcvpkt)
udt_send(sndpkt)
rdt_rcv(rcvpkt) ampampisNAK(rcvpkt)
udt_send(NAK)
rdt_rcv(rcvpkt) ampamp corrupt(rcvpkt)
Wait for ACK or
NAK
Wait for call from
below
rdt_send(data)
Λ
Transport Layer 3-22
rdt20 has a fatal flaw
What happens if ACKNAK corruptedsender doesnrsquot know what happened at receivercanrsquot just retransmit possible duplicate
What to dosender ACKsNAKs receiverrsquos ACKNAK What if sender ACKNAK lostretransmit but this might cause retransmission of correctly received pkt
Handling duplicates sender adds sequence number to each pktsender retransmits current pkt if ACKNAK garbledreceiver discards (doesnrsquot deliver up) duplicate pkt
Sender sends one packet then waits for receiver response
stop and wait
Transport Layer 3-23
rdt21 sender handles garbled ACKNAKs
Wait for call 0 from
above
sndpkt = make_pkt(0 data checksum)udt_send(sndpkt)
rdt_send(data)
Wait for ACK or NAK 0 udt_send(sndpkt)
rdt_rcv(rcvpkt) ampamp ( corrupt(rcvpkt) ||isNAK(rcvpkt) )
sndpkt = make_pkt(1 data checksum)udt_send(sndpkt)
rdt_send(data)
rdt_rcv(rcvpkt) ampamp notcorrupt(rcvpkt) ampamp isACK(rcvpkt)
udt_send(sndpkt)
rdt_rcv(rcvpkt) ampamp ( corrupt(rcvpkt) ||isNAK(rcvpkt) )
rdt_rcv(rcvpkt) ampamp notcorrupt(rcvpkt) ampamp isACK(rcvpkt)
Wait forcall 1 from
above
Wait for ACK or NAK 1
ΛΛ
Transport Layer 3-24
rdt21 receiver handles garbled ACKNAKs
Wait for 0 from below
sndpkt = make_pkt(NAK chksum)udt_send(sndpkt)
rdt_rcv(rcvpkt) ampamp not corrupt(rcvpkt) ampamphas_seq0(rcvpkt)
rdt_rcv(rcvpkt) ampamp notcorrupt(rcvpkt) ampamp has_seq1(rcvpkt)
extract(rcvpktdata)deliver_data(data)sndpkt = make_pkt(ACK chksum)udt_send(sndpkt)
Wait for 1 from below
rdt_rcv(rcvpkt) ampamp notcorrupt(rcvpkt) ampamp has_seq0(rcvpkt)
extract(rcvpktdata)deliver_data(data)sndpkt = make_pkt(ACK chksum)udt_send(sndpkt)
rdt_rcv(rcvpkt) ampamp (corrupt(rcvpkt)
sndpkt = make_pkt(ACK chksum)udt_send(sndpkt)
rdt_rcv(rcvpkt) ampamp not corrupt(rcvpkt) ampamphas_seq1(rcvpkt)
rdt_rcv(rcvpkt) ampamp (corrupt(rcvpkt)
sndpkt = make_pkt(ACK chksum)udt_send(sndpkt)
sndpkt = make_pkt(NAK chksum)udt_send(sndpkt)
Transport Layer 3-25
rdt21 discussion
Senderseq added to pkttwo seq rsquos (01) will suffice Whymust check if received ACKNAK corrupted twice as many states
state must ldquorememberrdquowhether ldquocurrentrdquo pkt has 0 or 1 seq
Receivermust check if received packet is duplicate
state indicates whether 0 or 1 is expected pkt seq
note receiver can notknow if its last ACKNAK received OK at sender
Transport Layer 3-26
rdt22 a NAK-free protocol
same functionality as rdt21 using ACKs onlyinstead of NAK receiver sends ACK for last pkt received OK
receiver must explicitly include seq of pkt being ACKed duplicate ACK at sender results in same action as NAK retransmit current pkt
Transport Layer 3-27
rdt22 sender receiver fragments
Wait for call 0 from
above
sndpkt = make_pkt(0 data checksum)udt_send(sndpkt)
rdt_send(data)
udt_send(sndpkt)
rdt_rcv(rcvpkt) ampamp ( corrupt(rcvpkt) ||
isACK(rcvpkt1) )
rdt_rcv(rcvpkt) ampamp notcorrupt(rcvpkt) ampamp isACK(rcvpkt0)
Wait for ACK
0sender FSM
fragment
Wait for 0 from below
rdt_rcv(rcvpkt) ampamp notcorrupt(rcvpkt) ampamp has_seq1(rcvpkt)
extract(rcvpktdata)deliver_data(data)sndpkt = make_pkt(ACK1 chksum)udt_send(sndpkt)
rdt_rcv(rcvpkt) ampamp (corrupt(rcvpkt) ||
has_seq1(rcvpkt))
udt_send(sndpkt)receiver FSM
fragment
Λ
Transport Layer 3-28
rdt30 channels with errors and loss
New assumptionunderlying channel can also lose packets (data or ACKs)
checksum seq ACKs retransmissions will be of help but not enough
Q how to deal with losssender waits until certain data or ACK lost then retransmitsdrawbacks
Approach sender waits ldquoreasonablerdquo amount of time for ACK retransmits if no ACK received in this timeif pkt (or ACK) just delayed (not lost)
retransmission will be duplicate but use of seq rsquos already handles thisreceiver must specify seq of pkt being ACKed
requires countdown timer
Transport Layer 3-29
rdt30 sendersndpkt = make_pkt(0 data checksum)udt_send(sndpkt)start_timer
rdt_send(data)
Wait for
ACK0
rdt_rcv(rcvpkt) ampamp ( corrupt(rcvpkt) ||isACK(rcvpkt1) )
Wait for call 1 from
above
sndpkt = make_pkt(1 data checksum)udt_send(sndpkt)start_timer
rdt_send(data)
rdt_rcv(rcvpkt) ampamp notcorrupt(rcvpkt) ampamp isACK(rcvpkt0)
rdt_rcv(rcvpkt) ampamp ( corrupt(rcvpkt) ||isACK(rcvpkt0) )
rdt_rcv(rcvpkt) ampamp notcorrupt(rcvpkt) ampamp isACK(rcvpkt1)
stop_timerstop_timer
udt_send(sndpkt)start_timer
timeout
udt_send(sndpkt)start_timer
timeout
rdt_rcv(rcvpkt)
Wait for call 0from
above
Wait for
ACK1
Λrdt_rcv(rcvpkt)
ΛΛ
Λ
Transport Layer 3-30
rdt30 in action
Transport Layer 3-31
rdt30 in action
Transport Layer 3-32
Performance of rdt30
rdt30 works but performance stinksexample 1 Gbps link 15 ms e-e prop delay 1KB packet
Ttransmit = 8kbpkt109 bsec = 8 microsec
U sender utilization ndash fraction of time sender busy sending1KB pkt every 30 msec -gt 33kBsec thruput over 1 Gbps linknetwork protocol limits use of physical resources
U sender=
008 30008
= 000027 L RRTT + L R
=
L (packet length in bits)R (transmission rate bps) =
Transport Layer 3-33
rdt30 stop-and-wait operation
first packet bit transmitted t = 0
sender receiver
RTT
last packet bit transmitted t = L R
first packet bit arriveslast packet bit arrives send ACK
ACK arrives send next packet t = RTT + L R
U sender=
00830008
= 000027 L RRTT + L R
=
Transport Layer 3-34
Pipelined protocolsPipelining sender allows multiple ldquoin-flightrdquo yet-to-
be-acknowledged pktsrange of sequence numbers must be increasedbuffering at sender andor receiver
Two generic forms of pipelined protocols go-Back-N selective repeat
Transport Layer 3-35
Pipelining increased utilization
first packet bit transmitted t = 0
sender receiver
RTT
last bit transmitted t = L R
first packet bit arriveslast packet bit arrives send ACK
ACK arrives send next packet t = RTT + L R
last bit of 2nd packet arrives send ACKlast bit of 3rd packet arrives send ACK
U sender=
024 30008
= 000083 L RRTT + L R
=
Increase utilizationby a factor of 3
Transport Layer 3-36
Utilization=N(LR)(RTT+LR) if NLRltRTT+LR Utilization=1 if and the sender pauses after it transmits a window NLRgtRTT+LR and the of packets until it receives first ACK sender does not pause
Transport Layer 3-37
Go-Back-NSender
k-bit seq in pkt headerldquowindowrdquo of up to N consecutive unackrsquoed pkts allowed
ACK(n) ACKs all pkts up to including seq n - ldquocumulative ACKrdquomay receive duplicate ACKs (see receiver)
timer for the entire windowtimeout(n) retransmit pkt n and all higher seq pkts in window
Transport Layer 3-38
GBN sender extended FSM
Wait start_timerudt_send(sndpkt[base])udt_send(sndpkt[base+1])hellipudt_send(sndpkt[nextseqnum-1])
timeout
rdt_send(data)
if (nextseqnum lt base+N) sndpkt[nextseqnum] = make_pkt(nextseqnumdatachksum)udt_send(sndpkt[nextseqnum])if (base == nextseqnum)
start_timernextseqnum++
elserefuse_data(data)
base = getacknum(rcvpkt)+1If (base == nextseqnum)
stop_timerelse
start_timer
rdt_rcv(rcvpkt) ampamp notcorrupt(rcvpkt)
base=1nextseqnum=1
rdt_rcv(rcvpkt) ampamp corrupt(rcvpkt)
Λ
Λ
Transport Layer 3-39
GBN receiver extended FSM
ACK-only always send ACK for correctly-received pktwith highest in-order seq
may generate duplicate ACKsneed only remember expectedseqnum
out-of-order pkt discard (donrsquot buffer) -gt no receiver bufferingRe-ACK pkt with highest in-order seq
Wait
udt_send(sndpkt)default
rdt_rcv(rcvpkt)ampamp notcurrupt(rcvpkt)ampamp hasseqnum(rcvpktexpectedseqnum)
extract(rcvpktdata)deliver_data(data)sndpkt = make_pkt(expectedseqnumACKchksum)udt_send(sndpkt)expectedseqnum++
expectedseqnum=1sndpkt =
make_pkt(0ACKchksum)
Λ
Transport Layer 3-40
GBN inaction
Transport Layer 3-41
Selective Repeat
receiver individually acknowledges all correctly received pkts
buffers pkts as needed for eventual in-order delivery to upper layer
sender only resends pkts for which ACK not received
sender timer for each unACKed pktsender window
N consecutive seq rsquosagain limits seq s of sent unACKed pkts
Transport Layer 3-42
Selective repeat sender receiver windows
Transport Layer 3-43
Selective repeat
data from above if next available seq in window send pkt
timeout(n)resend pkt n restart timer
ACK(n) in [sendbasesendbase+N-1]
mark pkt n as receivedif n smallest unACKed pkt advance window base to next unACKed seq
senderpkt n in [rcvbase rcvbase+N-1]
send ACK(n)out-of-order bufferin-order deliver (also deliver buffered in-order pkts) advance window to next not-yet-received pkt
pkt n in [rcvbase-Nrcvbase-1]
ACK(n)otherwise
ignore
receiver
Transport Layer 3-44
Selective repeat in action
Transport Layer 3-45
Selective repeatdilemma
Example seq rsquos 0 1 2 3window size=3
receiver sees no difference in two scenariosincorrectly passes duplicate data as new in (a)
Q what relationship between seq size and window size
Transport Layer 3-46
Sequence Number vs Window SizeSuppose we use k bits to represent SNQuestion Whatrsquos the minimum number of bits k necessary for a window size of N
sender
receiver
Go-Back-N
expectedSN
snd_base=expectedSN
Q For a given expectedSN whatrsquos the largest possible value for snd_baseA If all the last N ACKs sent by the receiver are received
snd_base = expectedSNexpectedSN+N-1
senderrsquos window
Transport Layer 3-47
Sequence Number vs Window SizeSuppose we use k bits to represent SNQuestion Whatrsquos the minimum number of bits k necessary for a window size of N
sender
receiver
Go-Back-N
expectedSN
snd_base=expectedSN-N
Q For a given expectedSN whatrsquos the smallest possible value for snd_baseA If all the last N ACKs sent by the receiver are not received
snd_base = expectedSN-NexpectedSN-1
senderrsquos window
Transport Layer 3-48
Sequence Number vs Window Size
sender
receiver
Go-Back-N
expectedSN
snd_base=expectedSN-N
All SNs in the interval [expectedSN-NexpectedSN+N-1] (an interval of size 2N) can be received by the receiver Since the receiver accepts on the packet with SN=expectedSN there should be no other packet within this interval with SN=expectedSN Therefore
2k ge N+1expectedSN+N-1
Transport Layer 3-49
Sequence Number vs Window SizeSuppose we use k bits to represent SNQuestion Whatrsquos the minimum number of bits k necessary for a window size of N
sender
receiver
Selective Repeat
rcv_base
snd_base=rcv_base
Q For a given rcv_base whatrsquos the largest possible value for snd_baseA If all the last N ACKs sent by the receiver are received
snd_base = rcv_base (same as go_back-N)rcv_base+N-1
senderrsquos window
receiverrsquos window
rcv_base+N-1
Transport Layer 3-50
Sequence Number vs Window SizeSuppose we use k bits to represent SNQuestion Whatrsquos the minimum number of bits k necessary for a window size of N
sender
receiver
Selective Repeat
rcv_base
snd_base=rcv_base-N
Q For a given rcv_base whatrsquos the smallest possible value for snd_baseA If all the last N ACKs sent by the receiver are not received
snd_base = rcv_base-N (same as Go-Back-N)rcv_base-1
senderrsquos window
rcv_base
receiverrsquos window
rcv_base+N-1
Transport Layer 3-51
Sequence Number vs Window Size
sender
receiver
Selective Repeat
snd_base=rcv_base-N
All SNs in the interval [rcv_base-Nrcv_base+N-1] (an interval of size 2N) can be received by the receiver Since the receiver should be able to distinguish between all packets in this interval and take corresponding action there should be no two packets within thisinterval having the same SN Therefore
2k ge 2Nrcv_base+N-1
rcv_basercv_base
receiverrsquos window
rcv_base+N-1
Transport Layer 3-52
TCP Overview RFCs 793 1122 1323 2018 2581
full duplex databi-directional data flow in same connectionMSS maximum segment size
connection-orientedhandshaking (exchange of control msgs) initrsquossender receiver state before data exchange
flow controlledsender will not overwhelm receiver
point-to-pointone sender one receiver
reliable in-order byte stream
no ldquomessage boundariesrdquopipelined
TCP congestion and flow control set window size
send amp receive buffers
socketdoor
TCPsend buffer
TCPreceive buffer
socketdoor
segment
applicationwrites data
applicationreads data
Transport Layer 3-53
TCP segment structure
source port dest port
32 bits
applicationdata
(variable length)
sequence numberacknowledgement number
Receive windowUrg data pnterchecksum
FSRPAUheadlen
notused
Options (variable length)
URG urgent data (generally not used)
ACK ACK valid
PSH push data now(generally not used)
RST SYN FINconnection estab(setup teardown
commands)
bytes rcvr willingto accept
Internetchecksum
(as in UDP)
countingby bytes of data(not segments)
Transport Layer 3-54
TCP seq rsquos and ACKsSeq rsquos
byte stream ldquonumberrdquo of first byte in segmentrsquos dataACKs
seq of next byte expected from other sidecumulative ACK
Q how receiver handles out-of-order segmentsA TCP spec doesnrsquot say - up to implementationWidely used implementations of TCP buffer out-of-order segments
Transport Layer 3-55
TCP Round Trip Time and Timeout
Q how to set TCP timeout valuelonger than RTT
but RTT variestoo short premature timeout
unnecessary retransmissions
too long slow reaction to segment loss
Q how to estimate RTTSampleRTT measured time from segment transmission until ACK receipt
ignore retransmissionsSampleRTT will vary want estimated RTT ldquosmootherrdquo
average several recent measurements not just current SampleRTT
Transport Layer 3-56
TCP Round Trip Time and Timeout
EstimatedRTT = (1- α)EstimatedRTT + αSampleRTT
Exponential weighted moving averageinfluence of past sample decreases exponentially fasttypical value α = 0125
Transport Layer 3-57
Example RTT estimationRTT gaiacsumassedu to fantasiaeurecomfr
100
150
200
250
300
350
1 8 15 22 29 36 43 50 57 64 71 78 85 92 99 106
time (seconnds)
RTT
(mill
iseco
nds)
SampleRTT Estimated RTT
Transport Layer 3-58
TCP Round Trip Time and TimeoutSetting the timeout
EstimatedRTT plus ldquosafety marginrdquolarge variation in EstimatedRTT -gt larger safety margin
first estimate of how much SampleRTT deviates from EstimatedRTT
TimeoutInterval = EstimatedRTT + 4DevRTT
DevRTT = (1-β)DevRTT +β|SampleRTT-EstimatedRTT|
(typically β = 025)
Then set timeout interval
Transport Layer 3-59
TCP reliable data transfer
TCP creates rdtservice on top of IPrsquos unreliable servicePipelined segmentsCumulative acksTCP uses single retransmission timer however it just retransmits the first segment in the window
Retransmissions are triggered by
timeout eventsduplicate acks
Initially consider simplified TCP sender
ignore duplicate acksignore flow control congestion control
Transport Layer 3-60
TCP sender eventsdata rcvd from app
Create segment with seq seq is byte-stream number of first data byte in segmentstart timer if not already running (think of timer as for oldest unacked segment)expiration interval TimeOutInterval
timeoutretransmit segment that caused timeout (first segment in the window)restart timer
Ack rcvdIf acknowledges previously unacked segments
update what is known to be ackedstart timer if there are outstanding segments
Transport Layer 3-61
TCP sender(simplified)
NextSeqNum = InitialSeqNumSendBase = InitialSeqNum
loop (forever) switch(event)
event data received from application above create TCP segment with sequence number NextSeqNumif (timer currently not running)
start timerpass segment to IP NextSeqNum = NextSeqNum + length(data)
event timer timeoutretransmit not-yet-acknowledged segment with
smallest sequence numberstart timer
event ACK received with ACK field value of y if (y gt SendBase)
SendBase = yif (there are currently not-yet-acknowledged segments)
start timer
end of loop forever
Commentbull SendBase-1 last cumulatively ackrsquoed byteExamplebull SendBase-1 = 71y= 73 so the rcvrwants 73+ y gt SendBase sothat new data is acked
Transport Layer 3-62
TCP retransmission scenariosHost A
Seq=100 20 bytes data
ACK=100
timepremature timeout
Host B
Seq=92 8 bytes data
ACK=120
Seq=92 8 bytes data
Seq=
92 t
imeo
ut
ACK=120
Host A
Seq=92 8 bytes data
ACK=100
loss
tim
eout
lost ACK scenario
Host B
X
Seq=92 8 bytes data
ACK=100
time
Seq=
92 t
imeo
utSendBase
= 100
SendBase= 120
SendBase= 120
Sendbase= 100
Transport Layer 3-63
TCP retransmission scenarios (more)Host A
Seq=92 8 bytes data
ACK=100
loss
tim
eout
Cumulative ACK scenario
Host B
X
Seq=100 20 bytes data
ACK=120
time
SendBase= 120
Transport Layer 3-64
TCP ACK generation [RFC 1122 RFC 2581]
Event at Receiver
Arrival of in-order segment withexpected seq All data up toexpected seq already ACKed
Arrival of in-order segment withexpected seq One other segment has ACK pending
Arrival of out-of-order segmenthigher-than-expect seq Gap detected
Arrival of segment that partially or completely fills gap
TCP Receiver action
Delayed ACK Wait up to 500msfor next segment If no next segmentsend ACK
Immediately send single cumulative ACK ACKing both in-order segments
Immediately send duplicate ACK indicating seq of next expected byte
Immediate send ACK provided thatsegment startsat lower end of gap
Transport Layer 3-65
Fast Retransmit
Time-out period often relatively long
long delay before resending lost packet
Detect lost segments via duplicate ACKs
Sender often sends many segments back-to-backIf segment is lost there will likely be many duplicate ACKs
If sender receives 3 ACKs for the same data it supposes that segment after ACKeddata was lost
fast retransmit resend segment before timer expires
Transport Layer 3-66
Fast RetransmitResend a segment after 3 duplicate ACKs since a duplicate ACK means that an out-of sequence segment was receivedduplicate ACKs due to packet reorderingif window is small donrsquot get duplicate ACKs
Host A
tim
eout
Host B
time
X
resend seq X2
seq x1seq x2seq x3seq x4seq x5
ACK x1
ACK x1ACK x1ACK x1
tripleduplicate
ACKs
Transport Layer 3-67
event ACK received with ACK field value of y if (y gt SendBase)
SendBase = yif (there are currently not-yet-acknowledged segments)
start timer
else increment count of dup ACKs received for yif (count of dup ACKs received for y = 3)
resend segment with sequence number y
Fast retransmit algorithm
a duplicate ACK for already ACKed segment
fast retransmit
Transport Layer 3-68
TCP Flow Control
receive side of TCP connection has a receive buffer
speed-matching service matching the send rate to the receiving apprsquos drain rate
app process may be slow at reading from buffer
sender wonrsquot overflowreceiverrsquos buffer by
transmitting too muchtoo fast
flow control
Transport Layer 3-69
TCP Flow control how it works
(Suppose TCP receiver discards out-of-order segments)spare room in buffer
= RcvWin
= RcvBuffer-[LastByteRcvd -LastByteRead]
Rcvr advertises spare room by including value of RcvWin in segmentsSender limits unACKeddata to RcvWin
guarantees receive buffer doesnrsquot overflow
Transport Layer 3-70
Sliding Window Flow Control Example
3K
2K SeqNo=0
ReceiverBuffer
0 4KSendersends 2Kof data
2K
AckNo=2048 RcvWin=2048Sendersends 2Kof data 2K SeqNo=2048
4K
AckNo=4096 RcvWin=0
AckNo=4096 RcvWin=1024
Sender blocked
Transport Layer 3-71
Principles of Congestion Control
Congestioninformally ldquotoo many sources sending too much data too fast for network to handlerdquodifferent from flow controlmanifestations
lost packets (buffer overflow at routers)long delays (queueing in router buffers)
a top-10 problem
Transport Layer 3-72
Causescosts of congestion scenario 1
two senders two receiversone router infinite buffers no retransmission
large delays when congestedmaximum achievable throughput
unlimited shared output link buffers
Host Aλin original data
Host B
λout
Transport Layer 3-73
Causescosts of congestion scenario 2
one router finite buffers sender retransmission of lost packet
finite shared output link buffers
Host A λin original data
Host B
λout
λin original data plus retransmitted data
Transport Layer 3-74
Causescosts of congestion scenario 2always (goodput)ldquoperfectrdquo retransmission only when loss
retransmission of delayed (not lost) packet makes larger(than perfect case) for same
λin
λout=
λin
λoutgtλ
inλout
ldquocostsrdquo of congestionmore work (retrans) for given ldquogoodputrdquounneeded retransmissions link carries multiple copies of pkt
R2
R2λin
λ out
b
R2
R2λin
λ out
a
R2
R2λin
λ out
c
R4
R3
Transport Layer 3-75
Causescosts of congestion scenario 3four sendersmultihop pathstimeoutretransmit
λin
Q what happens as and increase λ
in
finite shared output link buffers
Host Aλin original data
Host B
λout
λin original data plus retransmitted data
Transport Layer 3-76
Causescosts of congestion scenario 3
another ldquocostrdquo of congestionwhen packet dropped any ldquoupstream transmission capacity used for that packet was wasted
Host A
Host B
λou
t
Transport Layer 3-77
Approaches towards congestion control
End-end congestion controlno explicit feedback from networkcongestion inferred from end-system observed loss delayapproach taken by TCP
Network-assisted congestion controlrouters provide feedback to end systems
single bit indicating congestion (SNA DECbit TCPIP ECN ATM)explicit rate sender should send at
Two broad approaches towards congestion control
Transport Layer 3-78
TCP Congestion Control
end-end control (no network assistance)sender limits transmissionLastByteSent-LastByteAcked
le CongWin
CongWin is dynamic function of perceived network congestion
How does sender perceive congestionloss event = timeout or3 duplicate acksTCP sender reduces rate (CongWin) after loss event
two modes of operationSlow Start (SS)Congestion avoidance (CA) or Additive Increase Multiplicative Decrease (AIMD)
Transport Layer 3-79
TCP congestion control bandwidth probing
ldquoprobing for bandwidthrdquo increase transmission rate on receipt of ACK until eventually loss occurs then decrease transmission rate
continue to increase on ACK decrease on loss (since available bandwidth is changing depending on other connections in network)
ACKs being received so increase rate
X
X
XX
X loss so decrease rate
send
ing
rate
time
Q how fast to increasedecreasedetails to follow
TCPrsquosldquosawtoothrdquobehavior
Transport Layer 3-80
TCP Congestion Control details
sender limits rate by limiting number of unACKed bytes ldquoin pipelinerdquo
cwnd differs from rwnd (how why)sender limited by min(cwndrwnd)
roughly
cwnd is dynamic function of perceived network congestion
rate = cwndRTT bytessec
LastByteSent-LastByteAcked le cwnd
cwndbytes
RTT
ACK(s)
Transport Layer 3-81
TCP Congestion Control more details
segment loss event reducing cwndtimeout no response from receiver
cut cwnd to 13 duplicate ACKs at least some segments getting through (recall fast retransmit)
cut cwnd in half less aggressively than on timeout
ACK received increase cwndTwo modes of operation
slowstart phase bull increase exponentially
fast (despite name) at connection start or following timeout
congestion avoidance bull increase linearly
Transport Layer 3-82
TCP Slow Start Phasewhen connection begins cwnd = 1 MSS
example MSS = 500 bytes amp RTT = 200 msecinitial rate = 20 kbps
available bandwidth may be gtgt MSSRTT
desirable to quickly ramp up to respectable rate
increase rate exponentially until first loss event or when threshold reached
double cwnd every RTTdone by incrementing cwnd by 1 for every ACK received
Host A
one segment
RTT
Host B
time
two segments
four segments
Transport Layer 3-83
Slow Start ExampleThe congestion window size grows very rapidly
For every ACK we increase CongWin by 1 irrespective of the number of segments ACKrsquoeddouble CongWinevery RTTinitial rate is slow but ramps up exponentially fast
TCP slows down the increase of CongWinwhen CongWin gt ssthresh
segment 1
ACK for segment 1
cwnd = 1
cwnd = 2 segment 2segment 3
ACK for segments 2
cwnd = 4 segment 4segment 5segment 6
ACK for segments 4
cwnd = 7
ACK for segments 3
ACK for segments 5
ACK for segments 6
cwnd = 3
cwnd = 5
cwnd = 6ACK for segments 7
cwnd = 8
segment 7
Transport Layer 3-84
TCP Congestion Avoidance Phase
when cwnd gt ssthreshgrow cwnd linearly
increase cwnd by 1 MSS per RTT approach possible congestion slower than in slowstartimplementation cwnd= cwnd + MSScwndfor each ACK received
ACKs increase cwndby 1 MSS per RTT additive increaseloss cut cwnd in half (non-timeout-detected loss ) multiplicative decrease
AIMD
AIMD Additive IncreaseMultiplicative Decrease
Transport Layer 3-85
Congestion AvoidanceCongestion avoidance phase is started if CongWin has reached the slow-start threshold value
If CongWin gt= ssthresh then each time an ACK is received increment CongWin as follows
bull CongWin = CongWin + 1CongWin (CongWin in segments)
bull In actual TCP implementation CongWin is in BytesCongWin = CongWin + MSS (MSSCongWin)
So CongWin is increased by one only if all CongWinsegments have been acknowledged
Transport Layer 3-86
Example Slow StartCongestion AvoidanceAssume that
ssthresh = 8
cwnd = 1
cwnd = 2
cwnd = 4
cwnd = 8
cwnd = 9
cwnd = 10
02468
101214
t=0
t=2
t=4
t=6
Roundtrip times
Cw
nd(in
seg
men
ts)
ssthresh
cwnd = 3
cwnd = 5cwnd = 6cwnd = 7
Transport Layer 3-87
Slow Start Congestion AvoidanceA typical plot of CongWin for a TCP connection
(MSS = 1500 bytes) with TCP Tahoe
SS
CA
ssthresh
Transport Layer 3-88
Responses to CongestionTCP assumes there is congestion if it detects a packet lossA TCP sender can detect lost packets via loss events
bull Timeout of a retransmission timerbull Receipt of 3 duplicate ACKs (fast retransmit)
TCP interprets a Timeout as a binary congestion signal When a timeout occurs the sender performs
ssthresh is set to half the current size of the congestion window
ssthresh = CongWin 2CongWin is reset to one
CongWin = 1and slow-start is entered
Transport Layer 3-89
Fast Recovery (differentiation btwn two loss events) After 3 dup ACKs (fast Retransmit)
ssthresh = CongWin2CongWin = CongWin2window then grows linearly
But after timeout eventCongWin = 1 MSS window then grows exponentiallyto the threshold then grows linearly
bull 3 dup ACKs indicates network capable of delivering some segmentsbull timeout before 3 dup ACKs is ldquomore alarmingrdquo
Philosophy
3-90
TCP Congestion ControlInitially
CongWin = 1ssthresh = advertised window size
New Ack receivedif (CongWin lt ssthresh) Slow Start
CongWin = CongWin + 1else Congestion Avoidance
CongWin = CongWin + 1CongWinTimeout
ssthresh = CongWin2CongWin = 1
Fast Retransmissionssthresh = CongWin2CongWin = CongWin2
Slow Start (exponential increase phase) is continued until CongWin reaches half of the level where the loss event occurred last time CongWin is increased slowly after (linear increase in Congestion Avoidance phase)
Transport Layer 3-91
Popular ldquoflavorsrdquo of TCP
ssthresh
ssthresh
TCP Tahoe
TCP Reno
Transmission round
cwnd
win
dow
siz
e (in
seg
men
ts)
Transport Layer 3-92
Summary TCP Congestion ControlWhen CongWin is below Threshold sender in slow-start phase window grows exponentiallyWhen CongWin is above Threshold sender is in congestion-avoidance phase window grows linearlyWhen a triple duplicate ACK occurs Threshold set to CongWin2 and CongWin set to ThresholdWhen timeout occurs Threshold set to CongWin2 and CongWin is set to 1 MSS The actual sender window size is determined based on the congestion and flow control algorithms
SenderWin=min(RcvWinCongWin)
Transport Layer 3-93
TCP Congestion Control SummaryEvent State TCP Sender Action Commentary
ACK receipt for previously unackeddata
Slow Start (SS)
CongWin = CongWin + MSS If (CongWin gt Threshold)
set state to ldquoCongestion Avoidancerdquo
Resulting in a doubling of CongWin every RTT
ACK receipt for previously unackeddata
CongestionAvoidance (CA)
CongWin = CongWin+MSS (MSSCongWin)
Additive increase resulting in increase of CongWin by 1 MSS every RTT
Loss event detected by triple duplicate ACK
SS or CA Threshold = CongWin2 CongWin = ThresholdSet state to ldquoCongestion Avoidancerdquo
Fast recovery implementing multiplicative decrease CongWin will not drop below 1 MSS
Timeout SS or CA Threshold = CongWin2 CongWin = 1 MSSSet state to ldquoSlow Startrdquo
Enter slow start
Duplicate ACK
SS or CA Increment duplicate ACK count for segment being acked
CongWin and Threshold not changed
Transport Layer 3-94
TCP throughput
Q whatrsquos average throughout of TCP as function of window size RTT
ignoring slow startlet W be window size when loss occurs
when window is W throughput is WRTTjust after loss window drops to W2 throughput to W2RTT average throughout 75 WRTT
Transport Layer 3-95
TCP Futures TCP over ldquolong fat pipesrdquo
example 1500 byte segments 100ms RTT want 10 Gbps throughputrequires window size W = 83333 in-flight segmentsthroughput in terms of loss rate
L = 210-10 Wownew versions of TCP for high-speed
LRTTMSSsdot221
Transport Layer 3-96
Fairness goal if K TCP sessions share same bottleneck link of bandwidth R each should have average rate of RK
TCP connection 1
bottleneckrouter
capacity R
TCP connection 2
TCP Fairness
Transport Layer 3-97
Why is TCP fairTwo competing sessions
Additive increase gives slope of 1 as throughout increasesmultiplicative decrease decreases throughput proportionally
R
R
equal bandwidth share
Connection 1 throughput
Conn
ecti
on 2
thr
ough
p ut
congestion avoidance additive increaseloss decrease window by factor of 2
congestion avoidance additive increaseloss decrease window by factor of 2
Transport Layer 3-98
Fairness (more)Fairness and UDP
Multimedia apps often do not use TCP
do not want rate throttled by congestion control
Instead use UDPpump audiovideo at constant rate tolerate packet loss
Research area TCP friendly
Fairness and parallel TCP connectionsnothing prevents app from opening parallel cnctionsbetween 2 hostsWeb browsers do this Example link of rate R supporting 9 cnctions
new app asks for 1 TCP gets rate R10new app asks for 11 TCPs gets R2
Transport Layer 3-99
TCP Connection ManagementRecall TCP sender receiver
establish ldquoconnectionrdquobefore exchanging data segmentsinitialize TCP variables
seq sbuffers flow control info (eg RcvWindow)
client connection initiatorSocket clientSocket = new Socket(hostnameport
number)
server contacted by clientSocket connectionSocket = welcomeSocketaccept()
Three way handshakeStep 1 client host sends TCP
SYN segment to serverspecifies initial seq no data
Step 2 server host receives SYN replies with SYNACK segment
server allocates buffersspecifies server initial seq
Step 3 client receives SYNACK replies with ACK segment which may contain data
Transport Layer 3-100
TCP Connection Management (cont)
Closing a connection
client closes socketclientSocketclose()
Step 1 client end system sends TCP FIN control segment to server
Step 2 server receives FIN replies with ACK Closes connection sends FIN
client
FIN
server
ACK
ACK
FIN
close
close
closed
tim
ed w
ait
Transport Layer 3-101
TCP Connection Management (cont)
Step 3 client receives FIN replies with ACK
Enters ldquotimed waitrdquo -will respond with ACK to received FINs
Step 4 server receives ACK Connection closed
client
FIN
server
ACK
ACK
FIN
closing
closing
closed
tim
ed w
ait
closed
Transport Layer 3-102
TCP Connection Management (cont)
TCP clientlifecycle
TCP serverlifecycle
Transport Layer 3-103
Tuning TCPIP Parameters TCPIP parameters
A set of default values may not be optimal for all applicationsThe network administrator may wish to turn on or off some TCPIP functions for performance or security considerations
Many Unix and Linux systems provide some flexibility in tuning the TCPIP kernelsbinsysctl is used to configure the Linux kernel parameters at runtime
Default kernel configuration file is sbinsysctlconfFrequently used sysctl options
bull sysctl ndasha or sysctl ndashA list all current valuesbull sysctl ndashp file_name load the sysctl setting from a configuration
filebull sysctl ndashw variable=value change the value of the parameter
Transport Layer 3-104
SomeTCP Parameters in Linux Kerneltcp_syn_retries
Number of SYN packets the kernel will send before giving up on the new connection
tcp_synack_retriesnumber of SYN+ACK packets sent before the kernel gives up on the connection
tcp_window_scalingMaximum window size of 65535 bytes not enough for for really fast networks The window scaling options allows for almost gigabyte windows which is good for connections with large delay-bandwidth product
tcp_max_syn_backlogMaximal number of remembered connection requests which still did not receive an acknowledgment from connecting client
tcp_fin_timeoutHow many seconds to wait for a final FIN packet before the socket is closed required to prevent denial-of-service (DoS) attacks Default value is 60 seconds
Transport Layer 3-105
SomeTCP Parameters in Linux Kerneltcp_rmem
This is a vector of 3 integers [min default max] These parameters are used by TCP to dynamically adjust receive buffer sizesmin - minimum size of the receive buffer used by each TCP socket The default value is 4K default - the default size of the receive buffer for a TCP socket The default value is 87380 bytes and is lowered to 43689 in low memory systems If larger receive buffer sizes are desired this value should be increased max - the maximum size of the receive buffer used by each TCP socket The default value of 873802 bytes is lowered to 87380 in low memory systems
tcp_smemSend buffer parameters [min default max] similar to tcp_rmem
- Chapter 3 Transport Layer
- Transport services and protocols
- Transport vs network layer
- Internet transport-layer protocols
- Multiplexingdemultiplexing
- How demultiplexing works
- Connectionless demultiplexing
- Connection-oriented demux
- Connection-oriented demux (cont)
- Connection-oriented demux Threaded Web Server
- UDP User Datagram Protocol [RFC 768]
- UDP more
- UDP checksum
- Principles of Reliable data transfer
- Reliable data transfer getting started
- Reliable data transfer getting started
- Rdt10 reliable transfer over a reliable channel
- Rdt20 channel with bit errors
- rdt20 FSM specification
- rdt20 operation with no errors
- rdt20 error scenario
- rdt20 has a fatal flaw
- rdt21 sender handles garbled ACKNAKs
- rdt21 receiver handles garbled ACKNAKs
- rdt21 discussion
- rdt22 a NAK-free protocol
- rdt22 sender receiver fragments
- rdt30 channels with errors and loss
- rdt30 sender
- rdt30 in action
- rdt30 in action
- Performance of rdt30
- rdt30 stop-and-wait operation
- Pipelined protocols
- Pipelining increased utilization
- Go-Back-N
- GBN sender extended FSM
- GBN receiver extended FSM
- GBN inaction
- Selective Repeat
- Selective repeat sender receiver windows
- Selective repeat
- Selective repeat in action
- Selective repeat dilemma
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- TCP Overview RFCs 793 1122 1323 2018 2581
- TCP segment structure
- TCP seq rsquos and ACKs
- TCP Round Trip Time and Timeout
- TCP Round Trip Time and Timeout
- Example RTT estimation
- TCP Round Trip Time and Timeout
- TCP reliable data transfer
- TCP sender events
- TCP sender(simplified)
- TCP retransmission scenarios
- TCP retransmission scenarios (more)
- TCP ACK generation [RFC 1122 RFC 2581]
- Fast Retransmit
- Fast Retransmit
- Fast retransmit algorithm
- TCP Flow Control
- TCP Flow control how it works
- Sliding Window Flow Control Example
- Principles of Congestion Control
- Causescosts of congestion scenario 1
- Causescosts of congestion scenario 2
- Causescosts of congestion scenario 2
- Causescosts of congestion scenario 3
- Causescosts of congestion scenario 3
- Approaches towards congestion control
- TCP Congestion Control
- TCP congestion control bandwidth probing
- TCP Congestion Control details
- TCP Congestion Control more details
- TCP Slow Start Phase
- Slow Start Example
- TCP Congestion Avoidance Phase
- Congestion Avoidance
- Example Slow StartCongestion Avoidance
- Slow Start Congestion Avoidance
- Responses to Congestion
- Fast Recovery (differentiation btwn two loss events)
- TCP Congestion Control
- Popular ldquoflavorsrdquo of TCP
- Summary TCP Congestion Control
- TCP Congestion Control Summary
- TCP throughput
- TCP Futures TCP over ldquolong fat pipesrdquo
- TCP Fairness
- Why is TCP fair
- Fairness (more)
- TCP Connection Management
- TCP Connection Management (cont)
- TCP Connection Management (cont)
- TCP Connection Management (cont)
- Tuning TCPIP Parameters
- SomeTCP Parameters in Linux Kernel
- SomeTCP Parameters in Linux Kernel
-
Transport Layer 3-3
Transport vs network layer
network layer logical communication between hoststransport layer logical communication between processes
relies on enhances network layer services
Household analogy12 kids sending letters
to 12 kidsprocesses = kidsapp messages = letters in envelopeshosts = housestransport protocol = Ayşe and Buumllentnetwork-layer protocol = postal service
Transport Layer 3-4
Internet transport-layer protocols
reliable in-order delivery (TCP)
congestion control flow controlconnection setup
unreliable unordered delivery UDP
no-frills extension of ldquobest-effortrdquo IP
services not available delay guaranteesbandwidth guarantees
applicationtransportnetworkdata linkphysical
applicationtransportnetworkdata linkphysical
networkdata linkphysical
networkdata linkphysical
networkdata linkphysical
networkdata linkphysicalnetwork
data linkphysical
logical end-end transport
Transport Layer 3-5
Multiplexingdemultiplexing
application
transport
network
link
physical
P1 application
transport
network
link
physical
application
transport
network
link
physical
P2P3 P4P1
host 1 host 2 host 3
= process= socket
delivering received segmentsto correct socket
Demultiplexing at rcv hostgathering data from multiplesockets enveloping data with header (later used for demultiplexing)
Multiplexing at send host
Transport Layer 3-6
How demultiplexing workshost receives IP datagrams
each datagram has source IP address destination IP addresseach datagram carries 1 transport-layer segmenteach segment has source destination port number (recall well-known port numbers for specific applications)
host uses IP addresses amp port numbers to direct segment to appropriate socket
source port dest port
32 bits
applicationdata
(message)
other header fields
TCPUDP segment format
Transport Layer 3-7
Connectionless demultiplexing
Create sockets with port numbers
DatagramSocket mySocket1 = new DatagramSocket(9111)
DatagramSocket mySocket2 = new DatagramSocket(9222)
UDP socket identified by two-tuple
(dest IP address dest port number)
When host receives UDP segment
checks destination port number in segmentdirects UDP segment to socket with that port number
IP datagrams with different source IP addresses andor source port numbers directed to same socket
Transport Layer 3-8
Connection-oriented demux
TCP socket identified by 4-tuple
source IP addresssource port numberdest IP addressdest port number
recv host uses all four values to direct segment to appropriate socket
Server host may support many simultaneous TCP sockets
each socket identified by its own 4-tuple
Web servers have different sockets for each connecting client
non-persistent HTTP will have different socket for each request
Transport Layer 3-9
Connection-oriented demux(cont)
ClientIPB
P1
clientIP A
P1P2P4
serverIP C
SP 9157DP 80
SP 9157DP 80
P5 P6 P3
D-IPCS-IP AD-IPC
S-IP B
SP 5775DP 80
D-IPCS-IP B
Transport Layer 3-10
Connection-oriented demuxThreaded Web Server
ClientIPB
P1
clientIP A
P1P2P4
serverIP C
SP 9157DP 80
SP 9157DP 80
P5 P6 P3
D-IPCS-IP AD-IPC
S-IP B
SP 5775DP 80
D-IPCS-IP B
P4
Transport Layer 3-11
UDP User Datagram Protocol [RFC 768]
ldquono frillsrdquo ldquobare bonesrdquoInternet transport protocolldquobest effortrdquo service UDP segments may be
lostdelivered out of order to app
connectionlessno handshaking between UDP sender receivereach UDP segment handled independently of others
Why is there a UDPno connection establishment (which can add delay)simple no connection state at sender receiversmall segment headerno congestion control UDP can blast away as fast as desired
Transport Layer 3-12
UDP moreoften used for streaming multimedia apps
loss tolerantrate sensitive
other UDP usesDNSSNMP
reliable transfer over UDP add reliability at application layer
application-specific error recovery
source port dest port
32 bits
Applicationdata
(message)
UDP segment format
length checksumLength in
bytes of UDPsegmentincluding
header
Transport Layer 3-13
UDP checksum
Sendertreat segment contents as sequence of 16-bit integerschecksum addition (1rsquos complement sum) of segment contents with wraparound of carry out bitsender puts checksum value into UDP checksum field
Receivercompute checksum of received segmentcheck if computed checksum equals checksum field value
NO - error detectedYES - no error detected
Goal detect ldquoerrorsrdquo (eg flipped bits) in transmitted segment
Transport Layer 3-14
Principles of Reliable data transferimportant in app transport link layerstop-10 list of important networking topics
characteristics of unreliable channel will determine complexity of reliable data transfer protocol (rdt)
netw
ork
laye
r
Transport Layer 3-15
Reliable data transfer getting started
sendside
receiveside
rdt_send() called from above (eg by app) Passed data to
deliver to receiver upper layer
udt_send() called by rdtto transfer packet over
unreliable channel to receiver
rdt_rcv() called when packet arrives on rcv-side of channel
deliver_data() called by rdt to deliver data to upper
Transport Layer 3-16
Reliable data transfer getting startedWersquoll
incrementally develop sender receiver sides of reliable data transfer protocol (rdt)consider only unidirectional data transfer
but control info will flow on both directionsuse finite state machines (FSM) to specify sender receiver
state1
state2
event causing state transitionactions taken on state transition
state when in this ldquostaterdquo next state
uniquely determined by next event
eventactions
Transport Layer 3-17
Rdt10 reliable transfer over a reliable channel
underlying channel perfectly reliableno bit errorsno loss of packets
separate FSMs for sender receiversender sends data into underlying channelreceiver read data from underlying channel
Wait for call from above packet = make_pkt(data)
udt_send(packet)
rdt_send(data)extract (packetdata)deliver_data(data)
Wait for call from
below
rdt_rcv(packet)
sender receiver
Transport Layer 3-18
Rdt20 channel with bit errors
underlying channel may flip bits in packetrecall checksum to detect bit errors
the question how to recover from errorsacknowledgements (ACKs) receiver explicitly tells sender that pkt received OKnegative acknowledgements (NAKs) receiver explicitly tells sender that pkt had errorssender retransmits pkt on receipt of NAK
new mechanisms in rdt20 (beyond rdt10)error detectionreceiver feedback control msgs (ACKNAK) rcvr-gtsender
Transport Layer 3-19
rdt20 FSM specification
Wait for call from above
snkpkt = make_pkt(data checksum)udt_send(sndpkt)
extract(rcvpktdata)deliver_data(data)udt_send(ACK)
rdt_rcv(rcvpkt) ampamp notcorrupt(rcvpkt)
rdt_rcv(rcvpkt) ampamp isACK(rcvpkt)
udt_send(sndpkt)
rdt_rcv(rcvpkt) ampampisNAK(rcvpkt)
udt_send(NAK)
rdt_rcv(rcvpkt) ampamp corrupt(rcvpkt)
Wait for ACK or
NAK
Wait for call from
belowsender
receiverrdt_send(data)
Λ
Transport Layer 3-20
rdt20 operation with no errors
Wait for call from above
snkpkt = make_pkt(data checksum)udt_send(sndpkt)
extract(rcvpktdata)deliver_data(data)udt_send(ACK)
rdt_rcv(rcvpkt) ampamp notcorrupt(rcvpkt)
rdt_rcv(rcvpkt) ampamp isACK(rcvpkt)
udt_send(sndpkt)
rdt_rcv(rcvpkt) ampampisNAK(rcvpkt)
udt_send(NAK)
rdt_rcv(rcvpkt) ampamp corrupt(rcvpkt)
Wait for ACK or
NAK
Wait for call from
below
rdt_send(data)
Λ
Transport Layer 3-21
rdt20 error scenario
Wait for call from above
snkpkt = make_pkt(data checksum)udt_send(sndpkt)
extract(rcvpktdata)deliver_data(data)udt_send(ACK)
rdt_rcv(rcvpkt) ampamp notcorrupt(rcvpkt)
rdt_rcv(rcvpkt) ampamp isACK(rcvpkt)
udt_send(sndpkt)
rdt_rcv(rcvpkt) ampampisNAK(rcvpkt)
udt_send(NAK)
rdt_rcv(rcvpkt) ampamp corrupt(rcvpkt)
Wait for ACK or
NAK
Wait for call from
below
rdt_send(data)
Λ
Transport Layer 3-22
rdt20 has a fatal flaw
What happens if ACKNAK corruptedsender doesnrsquot know what happened at receivercanrsquot just retransmit possible duplicate
What to dosender ACKsNAKs receiverrsquos ACKNAK What if sender ACKNAK lostretransmit but this might cause retransmission of correctly received pkt
Handling duplicates sender adds sequence number to each pktsender retransmits current pkt if ACKNAK garbledreceiver discards (doesnrsquot deliver up) duplicate pkt
Sender sends one packet then waits for receiver response
stop and wait
Transport Layer 3-23
rdt21 sender handles garbled ACKNAKs
Wait for call 0 from
above
sndpkt = make_pkt(0 data checksum)udt_send(sndpkt)
rdt_send(data)
Wait for ACK or NAK 0 udt_send(sndpkt)
rdt_rcv(rcvpkt) ampamp ( corrupt(rcvpkt) ||isNAK(rcvpkt) )
sndpkt = make_pkt(1 data checksum)udt_send(sndpkt)
rdt_send(data)
rdt_rcv(rcvpkt) ampamp notcorrupt(rcvpkt) ampamp isACK(rcvpkt)
udt_send(sndpkt)
rdt_rcv(rcvpkt) ampamp ( corrupt(rcvpkt) ||isNAK(rcvpkt) )
rdt_rcv(rcvpkt) ampamp notcorrupt(rcvpkt) ampamp isACK(rcvpkt)
Wait forcall 1 from
above
Wait for ACK or NAK 1
ΛΛ
Transport Layer 3-24
rdt21 receiver handles garbled ACKNAKs
Wait for 0 from below
sndpkt = make_pkt(NAK chksum)udt_send(sndpkt)
rdt_rcv(rcvpkt) ampamp not corrupt(rcvpkt) ampamphas_seq0(rcvpkt)
rdt_rcv(rcvpkt) ampamp notcorrupt(rcvpkt) ampamp has_seq1(rcvpkt)
extract(rcvpktdata)deliver_data(data)sndpkt = make_pkt(ACK chksum)udt_send(sndpkt)
Wait for 1 from below
rdt_rcv(rcvpkt) ampamp notcorrupt(rcvpkt) ampamp has_seq0(rcvpkt)
extract(rcvpktdata)deliver_data(data)sndpkt = make_pkt(ACK chksum)udt_send(sndpkt)
rdt_rcv(rcvpkt) ampamp (corrupt(rcvpkt)
sndpkt = make_pkt(ACK chksum)udt_send(sndpkt)
rdt_rcv(rcvpkt) ampamp not corrupt(rcvpkt) ampamphas_seq1(rcvpkt)
rdt_rcv(rcvpkt) ampamp (corrupt(rcvpkt)
sndpkt = make_pkt(ACK chksum)udt_send(sndpkt)
sndpkt = make_pkt(NAK chksum)udt_send(sndpkt)
Transport Layer 3-25
rdt21 discussion
Senderseq added to pkttwo seq rsquos (01) will suffice Whymust check if received ACKNAK corrupted twice as many states
state must ldquorememberrdquowhether ldquocurrentrdquo pkt has 0 or 1 seq
Receivermust check if received packet is duplicate
state indicates whether 0 or 1 is expected pkt seq
note receiver can notknow if its last ACKNAK received OK at sender
Transport Layer 3-26
rdt22 a NAK-free protocol
same functionality as rdt21 using ACKs onlyinstead of NAK receiver sends ACK for last pkt received OK
receiver must explicitly include seq of pkt being ACKed duplicate ACK at sender results in same action as NAK retransmit current pkt
Transport Layer 3-27
rdt22 sender receiver fragments
Wait for call 0 from
above
sndpkt = make_pkt(0 data checksum)udt_send(sndpkt)
rdt_send(data)
udt_send(sndpkt)
rdt_rcv(rcvpkt) ampamp ( corrupt(rcvpkt) ||
isACK(rcvpkt1) )
rdt_rcv(rcvpkt) ampamp notcorrupt(rcvpkt) ampamp isACK(rcvpkt0)
Wait for ACK
0sender FSM
fragment
Wait for 0 from below
rdt_rcv(rcvpkt) ampamp notcorrupt(rcvpkt) ampamp has_seq1(rcvpkt)
extract(rcvpktdata)deliver_data(data)sndpkt = make_pkt(ACK1 chksum)udt_send(sndpkt)
rdt_rcv(rcvpkt) ampamp (corrupt(rcvpkt) ||
has_seq1(rcvpkt))
udt_send(sndpkt)receiver FSM
fragment
Λ
Transport Layer 3-28
rdt30 channels with errors and loss
New assumptionunderlying channel can also lose packets (data or ACKs)
checksum seq ACKs retransmissions will be of help but not enough
Q how to deal with losssender waits until certain data or ACK lost then retransmitsdrawbacks
Approach sender waits ldquoreasonablerdquo amount of time for ACK retransmits if no ACK received in this timeif pkt (or ACK) just delayed (not lost)
retransmission will be duplicate but use of seq rsquos already handles thisreceiver must specify seq of pkt being ACKed
requires countdown timer
Transport Layer 3-29
rdt30 sendersndpkt = make_pkt(0 data checksum)udt_send(sndpkt)start_timer
rdt_send(data)
Wait for
ACK0
rdt_rcv(rcvpkt) ampamp ( corrupt(rcvpkt) ||isACK(rcvpkt1) )
Wait for call 1 from
above
sndpkt = make_pkt(1 data checksum)udt_send(sndpkt)start_timer
rdt_send(data)
rdt_rcv(rcvpkt) ampamp notcorrupt(rcvpkt) ampamp isACK(rcvpkt0)
rdt_rcv(rcvpkt) ampamp ( corrupt(rcvpkt) ||isACK(rcvpkt0) )
rdt_rcv(rcvpkt) ampamp notcorrupt(rcvpkt) ampamp isACK(rcvpkt1)
stop_timerstop_timer
udt_send(sndpkt)start_timer
timeout
udt_send(sndpkt)start_timer
timeout
rdt_rcv(rcvpkt)
Wait for call 0from
above
Wait for
ACK1
Λrdt_rcv(rcvpkt)
ΛΛ
Λ
Transport Layer 3-30
rdt30 in action
Transport Layer 3-31
rdt30 in action
Transport Layer 3-32
Performance of rdt30
rdt30 works but performance stinksexample 1 Gbps link 15 ms e-e prop delay 1KB packet
Ttransmit = 8kbpkt109 bsec = 8 microsec
U sender utilization ndash fraction of time sender busy sending1KB pkt every 30 msec -gt 33kBsec thruput over 1 Gbps linknetwork protocol limits use of physical resources
U sender=
008 30008
= 000027 L RRTT + L R
=
L (packet length in bits)R (transmission rate bps) =
Transport Layer 3-33
rdt30 stop-and-wait operation
first packet bit transmitted t = 0
sender receiver
RTT
last packet bit transmitted t = L R
first packet bit arriveslast packet bit arrives send ACK
ACK arrives send next packet t = RTT + L R
U sender=
00830008
= 000027 L RRTT + L R
=
Transport Layer 3-34
Pipelined protocolsPipelining sender allows multiple ldquoin-flightrdquo yet-to-
be-acknowledged pktsrange of sequence numbers must be increasedbuffering at sender andor receiver
Two generic forms of pipelined protocols go-Back-N selective repeat
Transport Layer 3-35
Pipelining increased utilization
first packet bit transmitted t = 0
sender receiver
RTT
last bit transmitted t = L R
first packet bit arriveslast packet bit arrives send ACK
ACK arrives send next packet t = RTT + L R
last bit of 2nd packet arrives send ACKlast bit of 3rd packet arrives send ACK
U sender=
024 30008
= 000083 L RRTT + L R
=
Increase utilizationby a factor of 3
Transport Layer 3-36
Utilization=N(LR)(RTT+LR) if NLRltRTT+LR Utilization=1 if and the sender pauses after it transmits a window NLRgtRTT+LR and the of packets until it receives first ACK sender does not pause
Transport Layer 3-37
Go-Back-NSender
k-bit seq in pkt headerldquowindowrdquo of up to N consecutive unackrsquoed pkts allowed
ACK(n) ACKs all pkts up to including seq n - ldquocumulative ACKrdquomay receive duplicate ACKs (see receiver)
timer for the entire windowtimeout(n) retransmit pkt n and all higher seq pkts in window
Transport Layer 3-38
GBN sender extended FSM
Wait start_timerudt_send(sndpkt[base])udt_send(sndpkt[base+1])hellipudt_send(sndpkt[nextseqnum-1])
timeout
rdt_send(data)
if (nextseqnum lt base+N) sndpkt[nextseqnum] = make_pkt(nextseqnumdatachksum)udt_send(sndpkt[nextseqnum])if (base == nextseqnum)
start_timernextseqnum++
elserefuse_data(data)
base = getacknum(rcvpkt)+1If (base == nextseqnum)
stop_timerelse
start_timer
rdt_rcv(rcvpkt) ampamp notcorrupt(rcvpkt)
base=1nextseqnum=1
rdt_rcv(rcvpkt) ampamp corrupt(rcvpkt)
Λ
Λ
Transport Layer 3-39
GBN receiver extended FSM
ACK-only always send ACK for correctly-received pktwith highest in-order seq
may generate duplicate ACKsneed only remember expectedseqnum
out-of-order pkt discard (donrsquot buffer) -gt no receiver bufferingRe-ACK pkt with highest in-order seq
Wait
udt_send(sndpkt)default
rdt_rcv(rcvpkt)ampamp notcurrupt(rcvpkt)ampamp hasseqnum(rcvpktexpectedseqnum)
extract(rcvpktdata)deliver_data(data)sndpkt = make_pkt(expectedseqnumACKchksum)udt_send(sndpkt)expectedseqnum++
expectedseqnum=1sndpkt =
make_pkt(0ACKchksum)
Λ
Transport Layer 3-40
GBN inaction
Transport Layer 3-41
Selective Repeat
receiver individually acknowledges all correctly received pkts
buffers pkts as needed for eventual in-order delivery to upper layer
sender only resends pkts for which ACK not received
sender timer for each unACKed pktsender window
N consecutive seq rsquosagain limits seq s of sent unACKed pkts
Transport Layer 3-42
Selective repeat sender receiver windows
Transport Layer 3-43
Selective repeat
data from above if next available seq in window send pkt
timeout(n)resend pkt n restart timer
ACK(n) in [sendbasesendbase+N-1]
mark pkt n as receivedif n smallest unACKed pkt advance window base to next unACKed seq
senderpkt n in [rcvbase rcvbase+N-1]
send ACK(n)out-of-order bufferin-order deliver (also deliver buffered in-order pkts) advance window to next not-yet-received pkt
pkt n in [rcvbase-Nrcvbase-1]
ACK(n)otherwise
ignore
receiver
Transport Layer 3-44
Selective repeat in action
Transport Layer 3-45
Selective repeatdilemma
Example seq rsquos 0 1 2 3window size=3
receiver sees no difference in two scenariosincorrectly passes duplicate data as new in (a)
Q what relationship between seq size and window size
Transport Layer 3-46
Sequence Number vs Window SizeSuppose we use k bits to represent SNQuestion Whatrsquos the minimum number of bits k necessary for a window size of N
sender
receiver
Go-Back-N
expectedSN
snd_base=expectedSN
Q For a given expectedSN whatrsquos the largest possible value for snd_baseA If all the last N ACKs sent by the receiver are received
snd_base = expectedSNexpectedSN+N-1
senderrsquos window
Transport Layer 3-47
Sequence Number vs Window SizeSuppose we use k bits to represent SNQuestion Whatrsquos the minimum number of bits k necessary for a window size of N
sender
receiver
Go-Back-N
expectedSN
snd_base=expectedSN-N
Q For a given expectedSN whatrsquos the smallest possible value for snd_baseA If all the last N ACKs sent by the receiver are not received
snd_base = expectedSN-NexpectedSN-1
senderrsquos window
Transport Layer 3-48
Sequence Number vs Window Size
sender
receiver
Go-Back-N
expectedSN
snd_base=expectedSN-N
All SNs in the interval [expectedSN-NexpectedSN+N-1] (an interval of size 2N) can be received by the receiver Since the receiver accepts on the packet with SN=expectedSN there should be no other packet within this interval with SN=expectedSN Therefore
2k ge N+1expectedSN+N-1
Transport Layer 3-49
Sequence Number vs Window SizeSuppose we use k bits to represent SNQuestion Whatrsquos the minimum number of bits k necessary for a window size of N
sender
receiver
Selective Repeat
rcv_base
snd_base=rcv_base
Q For a given rcv_base whatrsquos the largest possible value for snd_baseA If all the last N ACKs sent by the receiver are received
snd_base = rcv_base (same as go_back-N)rcv_base+N-1
senderrsquos window
receiverrsquos window
rcv_base+N-1
Transport Layer 3-50
Sequence Number vs Window SizeSuppose we use k bits to represent SNQuestion Whatrsquos the minimum number of bits k necessary for a window size of N
sender
receiver
Selective Repeat
rcv_base
snd_base=rcv_base-N
Q For a given rcv_base whatrsquos the smallest possible value for snd_baseA If all the last N ACKs sent by the receiver are not received
snd_base = rcv_base-N (same as Go-Back-N)rcv_base-1
senderrsquos window
rcv_base
receiverrsquos window
rcv_base+N-1
Transport Layer 3-51
Sequence Number vs Window Size
sender
receiver
Selective Repeat
snd_base=rcv_base-N
All SNs in the interval [rcv_base-Nrcv_base+N-1] (an interval of size 2N) can be received by the receiver Since the receiver should be able to distinguish between all packets in this interval and take corresponding action there should be no two packets within thisinterval having the same SN Therefore
2k ge 2Nrcv_base+N-1
rcv_basercv_base
receiverrsquos window
rcv_base+N-1
Transport Layer 3-52
TCP Overview RFCs 793 1122 1323 2018 2581
full duplex databi-directional data flow in same connectionMSS maximum segment size
connection-orientedhandshaking (exchange of control msgs) initrsquossender receiver state before data exchange
flow controlledsender will not overwhelm receiver
point-to-pointone sender one receiver
reliable in-order byte stream
no ldquomessage boundariesrdquopipelined
TCP congestion and flow control set window size
send amp receive buffers
socketdoor
TCPsend buffer
TCPreceive buffer
socketdoor
segment
applicationwrites data
applicationreads data
Transport Layer 3-53
TCP segment structure
source port dest port
32 bits
applicationdata
(variable length)
sequence numberacknowledgement number
Receive windowUrg data pnterchecksum
FSRPAUheadlen
notused
Options (variable length)
URG urgent data (generally not used)
ACK ACK valid
PSH push data now(generally not used)
RST SYN FINconnection estab(setup teardown
commands)
bytes rcvr willingto accept
Internetchecksum
(as in UDP)
countingby bytes of data(not segments)
Transport Layer 3-54
TCP seq rsquos and ACKsSeq rsquos
byte stream ldquonumberrdquo of first byte in segmentrsquos dataACKs
seq of next byte expected from other sidecumulative ACK
Q how receiver handles out-of-order segmentsA TCP spec doesnrsquot say - up to implementationWidely used implementations of TCP buffer out-of-order segments
Transport Layer 3-55
TCP Round Trip Time and Timeout
Q how to set TCP timeout valuelonger than RTT
but RTT variestoo short premature timeout
unnecessary retransmissions
too long slow reaction to segment loss
Q how to estimate RTTSampleRTT measured time from segment transmission until ACK receipt
ignore retransmissionsSampleRTT will vary want estimated RTT ldquosmootherrdquo
average several recent measurements not just current SampleRTT
Transport Layer 3-56
TCP Round Trip Time and Timeout
EstimatedRTT = (1- α)EstimatedRTT + αSampleRTT
Exponential weighted moving averageinfluence of past sample decreases exponentially fasttypical value α = 0125
Transport Layer 3-57
Example RTT estimationRTT gaiacsumassedu to fantasiaeurecomfr
100
150
200
250
300
350
1 8 15 22 29 36 43 50 57 64 71 78 85 92 99 106
time (seconnds)
RTT
(mill
iseco
nds)
SampleRTT Estimated RTT
Transport Layer 3-58
TCP Round Trip Time and TimeoutSetting the timeout
EstimatedRTT plus ldquosafety marginrdquolarge variation in EstimatedRTT -gt larger safety margin
first estimate of how much SampleRTT deviates from EstimatedRTT
TimeoutInterval = EstimatedRTT + 4DevRTT
DevRTT = (1-β)DevRTT +β|SampleRTT-EstimatedRTT|
(typically β = 025)
Then set timeout interval
Transport Layer 3-59
TCP reliable data transfer
TCP creates rdtservice on top of IPrsquos unreliable servicePipelined segmentsCumulative acksTCP uses single retransmission timer however it just retransmits the first segment in the window
Retransmissions are triggered by
timeout eventsduplicate acks
Initially consider simplified TCP sender
ignore duplicate acksignore flow control congestion control
Transport Layer 3-60
TCP sender eventsdata rcvd from app
Create segment with seq seq is byte-stream number of first data byte in segmentstart timer if not already running (think of timer as for oldest unacked segment)expiration interval TimeOutInterval
timeoutretransmit segment that caused timeout (first segment in the window)restart timer
Ack rcvdIf acknowledges previously unacked segments
update what is known to be ackedstart timer if there are outstanding segments
Transport Layer 3-61
TCP sender(simplified)
NextSeqNum = InitialSeqNumSendBase = InitialSeqNum
loop (forever) switch(event)
event data received from application above create TCP segment with sequence number NextSeqNumif (timer currently not running)
start timerpass segment to IP NextSeqNum = NextSeqNum + length(data)
event timer timeoutretransmit not-yet-acknowledged segment with
smallest sequence numberstart timer
event ACK received with ACK field value of y if (y gt SendBase)
SendBase = yif (there are currently not-yet-acknowledged segments)
start timer
end of loop forever
Commentbull SendBase-1 last cumulatively ackrsquoed byteExamplebull SendBase-1 = 71y= 73 so the rcvrwants 73+ y gt SendBase sothat new data is acked
Transport Layer 3-62
TCP retransmission scenariosHost A
Seq=100 20 bytes data
ACK=100
timepremature timeout
Host B
Seq=92 8 bytes data
ACK=120
Seq=92 8 bytes data
Seq=
92 t
imeo
ut
ACK=120
Host A
Seq=92 8 bytes data
ACK=100
loss
tim
eout
lost ACK scenario
Host B
X
Seq=92 8 bytes data
ACK=100
time
Seq=
92 t
imeo
utSendBase
= 100
SendBase= 120
SendBase= 120
Sendbase= 100
Transport Layer 3-63
TCP retransmission scenarios (more)Host A
Seq=92 8 bytes data
ACK=100
loss
tim
eout
Cumulative ACK scenario
Host B
X
Seq=100 20 bytes data
ACK=120
time
SendBase= 120
Transport Layer 3-64
TCP ACK generation [RFC 1122 RFC 2581]
Event at Receiver
Arrival of in-order segment withexpected seq All data up toexpected seq already ACKed
Arrival of in-order segment withexpected seq One other segment has ACK pending
Arrival of out-of-order segmenthigher-than-expect seq Gap detected
Arrival of segment that partially or completely fills gap
TCP Receiver action
Delayed ACK Wait up to 500msfor next segment If no next segmentsend ACK
Immediately send single cumulative ACK ACKing both in-order segments
Immediately send duplicate ACK indicating seq of next expected byte
Immediate send ACK provided thatsegment startsat lower end of gap
Transport Layer 3-65
Fast Retransmit
Time-out period often relatively long
long delay before resending lost packet
Detect lost segments via duplicate ACKs
Sender often sends many segments back-to-backIf segment is lost there will likely be many duplicate ACKs
If sender receives 3 ACKs for the same data it supposes that segment after ACKeddata was lost
fast retransmit resend segment before timer expires
Transport Layer 3-66
Fast RetransmitResend a segment after 3 duplicate ACKs since a duplicate ACK means that an out-of sequence segment was receivedduplicate ACKs due to packet reorderingif window is small donrsquot get duplicate ACKs
Host A
tim
eout
Host B
time
X
resend seq X2
seq x1seq x2seq x3seq x4seq x5
ACK x1
ACK x1ACK x1ACK x1
tripleduplicate
ACKs
Transport Layer 3-67
event ACK received with ACK field value of y if (y gt SendBase)
SendBase = yif (there are currently not-yet-acknowledged segments)
start timer
else increment count of dup ACKs received for yif (count of dup ACKs received for y = 3)
resend segment with sequence number y
Fast retransmit algorithm
a duplicate ACK for already ACKed segment
fast retransmit
Transport Layer 3-68
TCP Flow Control
receive side of TCP connection has a receive buffer
speed-matching service matching the send rate to the receiving apprsquos drain rate
app process may be slow at reading from buffer
sender wonrsquot overflowreceiverrsquos buffer by
transmitting too muchtoo fast
flow control
Transport Layer 3-69
TCP Flow control how it works
(Suppose TCP receiver discards out-of-order segments)spare room in buffer
= RcvWin
= RcvBuffer-[LastByteRcvd -LastByteRead]
Rcvr advertises spare room by including value of RcvWin in segmentsSender limits unACKeddata to RcvWin
guarantees receive buffer doesnrsquot overflow
Transport Layer 3-70
Sliding Window Flow Control Example
3K
2K SeqNo=0
ReceiverBuffer
0 4KSendersends 2Kof data
2K
AckNo=2048 RcvWin=2048Sendersends 2Kof data 2K SeqNo=2048
4K
AckNo=4096 RcvWin=0
AckNo=4096 RcvWin=1024
Sender blocked
Transport Layer 3-71
Principles of Congestion Control
Congestioninformally ldquotoo many sources sending too much data too fast for network to handlerdquodifferent from flow controlmanifestations
lost packets (buffer overflow at routers)long delays (queueing in router buffers)
a top-10 problem
Transport Layer 3-72
Causescosts of congestion scenario 1
two senders two receiversone router infinite buffers no retransmission
large delays when congestedmaximum achievable throughput
unlimited shared output link buffers
Host Aλin original data
Host B
λout
Transport Layer 3-73
Causescosts of congestion scenario 2
one router finite buffers sender retransmission of lost packet
finite shared output link buffers
Host A λin original data
Host B
λout
λin original data plus retransmitted data
Transport Layer 3-74
Causescosts of congestion scenario 2always (goodput)ldquoperfectrdquo retransmission only when loss
retransmission of delayed (not lost) packet makes larger(than perfect case) for same
λin
λout=
λin
λoutgtλ
inλout
ldquocostsrdquo of congestionmore work (retrans) for given ldquogoodputrdquounneeded retransmissions link carries multiple copies of pkt
R2
R2λin
λ out
b
R2
R2λin
λ out
a
R2
R2λin
λ out
c
R4
R3
Transport Layer 3-75
Causescosts of congestion scenario 3four sendersmultihop pathstimeoutretransmit
λin
Q what happens as and increase λ
in
finite shared output link buffers
Host Aλin original data
Host B
λout
λin original data plus retransmitted data
Transport Layer 3-76
Causescosts of congestion scenario 3
another ldquocostrdquo of congestionwhen packet dropped any ldquoupstream transmission capacity used for that packet was wasted
Host A
Host B
λou
t
Transport Layer 3-77
Approaches towards congestion control
End-end congestion controlno explicit feedback from networkcongestion inferred from end-system observed loss delayapproach taken by TCP
Network-assisted congestion controlrouters provide feedback to end systems
single bit indicating congestion (SNA DECbit TCPIP ECN ATM)explicit rate sender should send at
Two broad approaches towards congestion control
Transport Layer 3-78
TCP Congestion Control
end-end control (no network assistance)sender limits transmissionLastByteSent-LastByteAcked
le CongWin
CongWin is dynamic function of perceived network congestion
How does sender perceive congestionloss event = timeout or3 duplicate acksTCP sender reduces rate (CongWin) after loss event
two modes of operationSlow Start (SS)Congestion avoidance (CA) or Additive Increase Multiplicative Decrease (AIMD)
Transport Layer 3-79
TCP congestion control bandwidth probing
ldquoprobing for bandwidthrdquo increase transmission rate on receipt of ACK until eventually loss occurs then decrease transmission rate
continue to increase on ACK decrease on loss (since available bandwidth is changing depending on other connections in network)
ACKs being received so increase rate
X
X
XX
X loss so decrease rate
send
ing
rate
time
Q how fast to increasedecreasedetails to follow
TCPrsquosldquosawtoothrdquobehavior
Transport Layer 3-80
TCP Congestion Control details
sender limits rate by limiting number of unACKed bytes ldquoin pipelinerdquo
cwnd differs from rwnd (how why)sender limited by min(cwndrwnd)
roughly
cwnd is dynamic function of perceived network congestion
rate = cwndRTT bytessec
LastByteSent-LastByteAcked le cwnd
cwndbytes
RTT
ACK(s)
Transport Layer 3-81
TCP Congestion Control more details
segment loss event reducing cwndtimeout no response from receiver
cut cwnd to 13 duplicate ACKs at least some segments getting through (recall fast retransmit)
cut cwnd in half less aggressively than on timeout
ACK received increase cwndTwo modes of operation
slowstart phase bull increase exponentially
fast (despite name) at connection start or following timeout
congestion avoidance bull increase linearly
Transport Layer 3-82
TCP Slow Start Phasewhen connection begins cwnd = 1 MSS
example MSS = 500 bytes amp RTT = 200 msecinitial rate = 20 kbps
available bandwidth may be gtgt MSSRTT
desirable to quickly ramp up to respectable rate
increase rate exponentially until first loss event or when threshold reached
double cwnd every RTTdone by incrementing cwnd by 1 for every ACK received
Host A
one segment
RTT
Host B
time
two segments
four segments
Transport Layer 3-83
Slow Start ExampleThe congestion window size grows very rapidly
For every ACK we increase CongWin by 1 irrespective of the number of segments ACKrsquoeddouble CongWinevery RTTinitial rate is slow but ramps up exponentially fast
TCP slows down the increase of CongWinwhen CongWin gt ssthresh
segment 1
ACK for segment 1
cwnd = 1
cwnd = 2 segment 2segment 3
ACK for segments 2
cwnd = 4 segment 4segment 5segment 6
ACK for segments 4
cwnd = 7
ACK for segments 3
ACK for segments 5
ACK for segments 6
cwnd = 3
cwnd = 5
cwnd = 6ACK for segments 7
cwnd = 8
segment 7
Transport Layer 3-84
TCP Congestion Avoidance Phase
when cwnd gt ssthreshgrow cwnd linearly
increase cwnd by 1 MSS per RTT approach possible congestion slower than in slowstartimplementation cwnd= cwnd + MSScwndfor each ACK received
ACKs increase cwndby 1 MSS per RTT additive increaseloss cut cwnd in half (non-timeout-detected loss ) multiplicative decrease
AIMD
AIMD Additive IncreaseMultiplicative Decrease
Transport Layer 3-85
Congestion AvoidanceCongestion avoidance phase is started if CongWin has reached the slow-start threshold value
If CongWin gt= ssthresh then each time an ACK is received increment CongWin as follows
bull CongWin = CongWin + 1CongWin (CongWin in segments)
bull In actual TCP implementation CongWin is in BytesCongWin = CongWin + MSS (MSSCongWin)
So CongWin is increased by one only if all CongWinsegments have been acknowledged
Transport Layer 3-86
Example Slow StartCongestion AvoidanceAssume that
ssthresh = 8
cwnd = 1
cwnd = 2
cwnd = 4
cwnd = 8
cwnd = 9
cwnd = 10
02468
101214
t=0
t=2
t=4
t=6
Roundtrip times
Cw
nd(in
seg
men
ts)
ssthresh
cwnd = 3
cwnd = 5cwnd = 6cwnd = 7
Transport Layer 3-87
Slow Start Congestion AvoidanceA typical plot of CongWin for a TCP connection
(MSS = 1500 bytes) with TCP Tahoe
SS
CA
ssthresh
Transport Layer 3-88
Responses to CongestionTCP assumes there is congestion if it detects a packet lossA TCP sender can detect lost packets via loss events
bull Timeout of a retransmission timerbull Receipt of 3 duplicate ACKs (fast retransmit)
TCP interprets a Timeout as a binary congestion signal When a timeout occurs the sender performs
ssthresh is set to half the current size of the congestion window
ssthresh = CongWin 2CongWin is reset to one
CongWin = 1and slow-start is entered
Transport Layer 3-89
Fast Recovery (differentiation btwn two loss events) After 3 dup ACKs (fast Retransmit)
ssthresh = CongWin2CongWin = CongWin2window then grows linearly
But after timeout eventCongWin = 1 MSS window then grows exponentiallyto the threshold then grows linearly
bull 3 dup ACKs indicates network capable of delivering some segmentsbull timeout before 3 dup ACKs is ldquomore alarmingrdquo
Philosophy
3-90
TCP Congestion ControlInitially
CongWin = 1ssthresh = advertised window size
New Ack receivedif (CongWin lt ssthresh) Slow Start
CongWin = CongWin + 1else Congestion Avoidance
CongWin = CongWin + 1CongWinTimeout
ssthresh = CongWin2CongWin = 1
Fast Retransmissionssthresh = CongWin2CongWin = CongWin2
Slow Start (exponential increase phase) is continued until CongWin reaches half of the level where the loss event occurred last time CongWin is increased slowly after (linear increase in Congestion Avoidance phase)
Transport Layer 3-91
Popular ldquoflavorsrdquo of TCP
ssthresh
ssthresh
TCP Tahoe
TCP Reno
Transmission round
cwnd
win
dow
siz
e (in
seg
men
ts)
Transport Layer 3-92
Summary TCP Congestion ControlWhen CongWin is below Threshold sender in slow-start phase window grows exponentiallyWhen CongWin is above Threshold sender is in congestion-avoidance phase window grows linearlyWhen a triple duplicate ACK occurs Threshold set to CongWin2 and CongWin set to ThresholdWhen timeout occurs Threshold set to CongWin2 and CongWin is set to 1 MSS The actual sender window size is determined based on the congestion and flow control algorithms
SenderWin=min(RcvWinCongWin)
Transport Layer 3-93
TCP Congestion Control SummaryEvent State TCP Sender Action Commentary
ACK receipt for previously unackeddata
Slow Start (SS)
CongWin = CongWin + MSS If (CongWin gt Threshold)
set state to ldquoCongestion Avoidancerdquo
Resulting in a doubling of CongWin every RTT
ACK receipt for previously unackeddata
CongestionAvoidance (CA)
CongWin = CongWin+MSS (MSSCongWin)
Additive increase resulting in increase of CongWin by 1 MSS every RTT
Loss event detected by triple duplicate ACK
SS or CA Threshold = CongWin2 CongWin = ThresholdSet state to ldquoCongestion Avoidancerdquo
Fast recovery implementing multiplicative decrease CongWin will not drop below 1 MSS
Timeout SS or CA Threshold = CongWin2 CongWin = 1 MSSSet state to ldquoSlow Startrdquo
Enter slow start
Duplicate ACK
SS or CA Increment duplicate ACK count for segment being acked
CongWin and Threshold not changed
Transport Layer 3-94
TCP throughput
Q whatrsquos average throughout of TCP as function of window size RTT
ignoring slow startlet W be window size when loss occurs
when window is W throughput is WRTTjust after loss window drops to W2 throughput to W2RTT average throughout 75 WRTT
Transport Layer 3-95
TCP Futures TCP over ldquolong fat pipesrdquo
example 1500 byte segments 100ms RTT want 10 Gbps throughputrequires window size W = 83333 in-flight segmentsthroughput in terms of loss rate
L = 210-10 Wownew versions of TCP for high-speed
LRTTMSSsdot221
Transport Layer 3-96
Fairness goal if K TCP sessions share same bottleneck link of bandwidth R each should have average rate of RK
TCP connection 1
bottleneckrouter
capacity R
TCP connection 2
TCP Fairness
Transport Layer 3-97
Why is TCP fairTwo competing sessions
Additive increase gives slope of 1 as throughout increasesmultiplicative decrease decreases throughput proportionally
R
R
equal bandwidth share
Connection 1 throughput
Conn
ecti
on 2
thr
ough
p ut
congestion avoidance additive increaseloss decrease window by factor of 2
congestion avoidance additive increaseloss decrease window by factor of 2
Transport Layer 3-98
Fairness (more)Fairness and UDP
Multimedia apps often do not use TCP
do not want rate throttled by congestion control
Instead use UDPpump audiovideo at constant rate tolerate packet loss
Research area TCP friendly
Fairness and parallel TCP connectionsnothing prevents app from opening parallel cnctionsbetween 2 hostsWeb browsers do this Example link of rate R supporting 9 cnctions
new app asks for 1 TCP gets rate R10new app asks for 11 TCPs gets R2
Transport Layer 3-99
TCP Connection ManagementRecall TCP sender receiver
establish ldquoconnectionrdquobefore exchanging data segmentsinitialize TCP variables
seq sbuffers flow control info (eg RcvWindow)
client connection initiatorSocket clientSocket = new Socket(hostnameport
number)
server contacted by clientSocket connectionSocket = welcomeSocketaccept()
Three way handshakeStep 1 client host sends TCP
SYN segment to serverspecifies initial seq no data
Step 2 server host receives SYN replies with SYNACK segment
server allocates buffersspecifies server initial seq
Step 3 client receives SYNACK replies with ACK segment which may contain data
Transport Layer 3-100
TCP Connection Management (cont)
Closing a connection
client closes socketclientSocketclose()
Step 1 client end system sends TCP FIN control segment to server
Step 2 server receives FIN replies with ACK Closes connection sends FIN
client
FIN
server
ACK
ACK
FIN
close
close
closed
tim
ed w
ait
Transport Layer 3-101
TCP Connection Management (cont)
Step 3 client receives FIN replies with ACK
Enters ldquotimed waitrdquo -will respond with ACK to received FINs
Step 4 server receives ACK Connection closed
client
FIN
server
ACK
ACK
FIN
closing
closing
closed
tim
ed w
ait
closed
Transport Layer 3-102
TCP Connection Management (cont)
TCP clientlifecycle
TCP serverlifecycle
Transport Layer 3-103
Tuning TCPIP Parameters TCPIP parameters
A set of default values may not be optimal for all applicationsThe network administrator may wish to turn on or off some TCPIP functions for performance or security considerations
Many Unix and Linux systems provide some flexibility in tuning the TCPIP kernelsbinsysctl is used to configure the Linux kernel parameters at runtime
Default kernel configuration file is sbinsysctlconfFrequently used sysctl options
bull sysctl ndasha or sysctl ndashA list all current valuesbull sysctl ndashp file_name load the sysctl setting from a configuration
filebull sysctl ndashw variable=value change the value of the parameter
Transport Layer 3-104
SomeTCP Parameters in Linux Kerneltcp_syn_retries
Number of SYN packets the kernel will send before giving up on the new connection
tcp_synack_retriesnumber of SYN+ACK packets sent before the kernel gives up on the connection
tcp_window_scalingMaximum window size of 65535 bytes not enough for for really fast networks The window scaling options allows for almost gigabyte windows which is good for connections with large delay-bandwidth product
tcp_max_syn_backlogMaximal number of remembered connection requests which still did not receive an acknowledgment from connecting client
tcp_fin_timeoutHow many seconds to wait for a final FIN packet before the socket is closed required to prevent denial-of-service (DoS) attacks Default value is 60 seconds
Transport Layer 3-105
SomeTCP Parameters in Linux Kerneltcp_rmem
This is a vector of 3 integers [min default max] These parameters are used by TCP to dynamically adjust receive buffer sizesmin - minimum size of the receive buffer used by each TCP socket The default value is 4K default - the default size of the receive buffer for a TCP socket The default value is 87380 bytes and is lowered to 43689 in low memory systems If larger receive buffer sizes are desired this value should be increased max - the maximum size of the receive buffer used by each TCP socket The default value of 873802 bytes is lowered to 87380 in low memory systems
tcp_smemSend buffer parameters [min default max] similar to tcp_rmem
- Chapter 3 Transport Layer
- Transport services and protocols
- Transport vs network layer
- Internet transport-layer protocols
- Multiplexingdemultiplexing
- How demultiplexing works
- Connectionless demultiplexing
- Connection-oriented demux
- Connection-oriented demux (cont)
- Connection-oriented demux Threaded Web Server
- UDP User Datagram Protocol [RFC 768]
- UDP more
- UDP checksum
- Principles of Reliable data transfer
- Reliable data transfer getting started
- Reliable data transfer getting started
- Rdt10 reliable transfer over a reliable channel
- Rdt20 channel with bit errors
- rdt20 FSM specification
- rdt20 operation with no errors
- rdt20 error scenario
- rdt20 has a fatal flaw
- rdt21 sender handles garbled ACKNAKs
- rdt21 receiver handles garbled ACKNAKs
- rdt21 discussion
- rdt22 a NAK-free protocol
- rdt22 sender receiver fragments
- rdt30 channels with errors and loss
- rdt30 sender
- rdt30 in action
- rdt30 in action
- Performance of rdt30
- rdt30 stop-and-wait operation
- Pipelined protocols
- Pipelining increased utilization
- Go-Back-N
- GBN sender extended FSM
- GBN receiver extended FSM
- GBN inaction
- Selective Repeat
- Selective repeat sender receiver windows
- Selective repeat
- Selective repeat in action
- Selective repeat dilemma
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- TCP Overview RFCs 793 1122 1323 2018 2581
- TCP segment structure
- TCP seq rsquos and ACKs
- TCP Round Trip Time and Timeout
- TCP Round Trip Time and Timeout
- Example RTT estimation
- TCP Round Trip Time and Timeout
- TCP reliable data transfer
- TCP sender events
- TCP sender(simplified)
- TCP retransmission scenarios
- TCP retransmission scenarios (more)
- TCP ACK generation [RFC 1122 RFC 2581]
- Fast Retransmit
- Fast Retransmit
- Fast retransmit algorithm
- TCP Flow Control
- TCP Flow control how it works
- Sliding Window Flow Control Example
- Principles of Congestion Control
- Causescosts of congestion scenario 1
- Causescosts of congestion scenario 2
- Causescosts of congestion scenario 2
- Causescosts of congestion scenario 3
- Causescosts of congestion scenario 3
- Approaches towards congestion control
- TCP Congestion Control
- TCP congestion control bandwidth probing
- TCP Congestion Control details
- TCP Congestion Control more details
- TCP Slow Start Phase
- Slow Start Example
- TCP Congestion Avoidance Phase
- Congestion Avoidance
- Example Slow StartCongestion Avoidance
- Slow Start Congestion Avoidance
- Responses to Congestion
- Fast Recovery (differentiation btwn two loss events)
- TCP Congestion Control
- Popular ldquoflavorsrdquo of TCP
- Summary TCP Congestion Control
- TCP Congestion Control Summary
- TCP throughput
- TCP Futures TCP over ldquolong fat pipesrdquo
- TCP Fairness
- Why is TCP fair
- Fairness (more)
- TCP Connection Management
- TCP Connection Management (cont)
- TCP Connection Management (cont)
- TCP Connection Management (cont)
- Tuning TCPIP Parameters
- SomeTCP Parameters in Linux Kernel
- SomeTCP Parameters in Linux Kernel
-
Transport Layer 3-4
Internet transport-layer protocols
reliable in-order delivery (TCP)
congestion control flow controlconnection setup
unreliable unordered delivery UDP
no-frills extension of ldquobest-effortrdquo IP
services not available delay guaranteesbandwidth guarantees
applicationtransportnetworkdata linkphysical
applicationtransportnetworkdata linkphysical
networkdata linkphysical
networkdata linkphysical
networkdata linkphysical
networkdata linkphysicalnetwork
data linkphysical
logical end-end transport
Transport Layer 3-5
Multiplexingdemultiplexing
application
transport
network
link
physical
P1 application
transport
network
link
physical
application
transport
network
link
physical
P2P3 P4P1
host 1 host 2 host 3
= process= socket
delivering received segmentsto correct socket
Demultiplexing at rcv hostgathering data from multiplesockets enveloping data with header (later used for demultiplexing)
Multiplexing at send host
Transport Layer 3-6
How demultiplexing workshost receives IP datagrams
each datagram has source IP address destination IP addresseach datagram carries 1 transport-layer segmenteach segment has source destination port number (recall well-known port numbers for specific applications)
host uses IP addresses amp port numbers to direct segment to appropriate socket
source port dest port
32 bits
applicationdata
(message)
other header fields
TCPUDP segment format
Transport Layer 3-7
Connectionless demultiplexing
Create sockets with port numbers
DatagramSocket mySocket1 = new DatagramSocket(9111)
DatagramSocket mySocket2 = new DatagramSocket(9222)
UDP socket identified by two-tuple
(dest IP address dest port number)
When host receives UDP segment
checks destination port number in segmentdirects UDP segment to socket with that port number
IP datagrams with different source IP addresses andor source port numbers directed to same socket
Transport Layer 3-8
Connection-oriented demux
TCP socket identified by 4-tuple
source IP addresssource port numberdest IP addressdest port number
recv host uses all four values to direct segment to appropriate socket
Server host may support many simultaneous TCP sockets
each socket identified by its own 4-tuple
Web servers have different sockets for each connecting client
non-persistent HTTP will have different socket for each request
Transport Layer 3-9
Connection-oriented demux(cont)
ClientIPB
P1
clientIP A
P1P2P4
serverIP C
SP 9157DP 80
SP 9157DP 80
P5 P6 P3
D-IPCS-IP AD-IPC
S-IP B
SP 5775DP 80
D-IPCS-IP B
Transport Layer 3-10
Connection-oriented demuxThreaded Web Server
ClientIPB
P1
clientIP A
P1P2P4
serverIP C
SP 9157DP 80
SP 9157DP 80
P5 P6 P3
D-IPCS-IP AD-IPC
S-IP B
SP 5775DP 80
D-IPCS-IP B
P4
Transport Layer 3-11
UDP User Datagram Protocol [RFC 768]
ldquono frillsrdquo ldquobare bonesrdquoInternet transport protocolldquobest effortrdquo service UDP segments may be
lostdelivered out of order to app
connectionlessno handshaking between UDP sender receivereach UDP segment handled independently of others
Why is there a UDPno connection establishment (which can add delay)simple no connection state at sender receiversmall segment headerno congestion control UDP can blast away as fast as desired
Transport Layer 3-12
UDP moreoften used for streaming multimedia apps
loss tolerantrate sensitive
other UDP usesDNSSNMP
reliable transfer over UDP add reliability at application layer
application-specific error recovery
source port dest port
32 bits
Applicationdata
(message)
UDP segment format
length checksumLength in
bytes of UDPsegmentincluding
header
Transport Layer 3-13
UDP checksum
Sendertreat segment contents as sequence of 16-bit integerschecksum addition (1rsquos complement sum) of segment contents with wraparound of carry out bitsender puts checksum value into UDP checksum field
Receivercompute checksum of received segmentcheck if computed checksum equals checksum field value
NO - error detectedYES - no error detected
Goal detect ldquoerrorsrdquo (eg flipped bits) in transmitted segment
Transport Layer 3-14
Principles of Reliable data transferimportant in app transport link layerstop-10 list of important networking topics
characteristics of unreliable channel will determine complexity of reliable data transfer protocol (rdt)
netw
ork
laye
r
Transport Layer 3-15
Reliable data transfer getting started
sendside
receiveside
rdt_send() called from above (eg by app) Passed data to
deliver to receiver upper layer
udt_send() called by rdtto transfer packet over
unreliable channel to receiver
rdt_rcv() called when packet arrives on rcv-side of channel
deliver_data() called by rdt to deliver data to upper
Transport Layer 3-16
Reliable data transfer getting startedWersquoll
incrementally develop sender receiver sides of reliable data transfer protocol (rdt)consider only unidirectional data transfer
but control info will flow on both directionsuse finite state machines (FSM) to specify sender receiver
state1
state2
event causing state transitionactions taken on state transition
state when in this ldquostaterdquo next state
uniquely determined by next event
eventactions
Transport Layer 3-17
Rdt10 reliable transfer over a reliable channel
underlying channel perfectly reliableno bit errorsno loss of packets
separate FSMs for sender receiversender sends data into underlying channelreceiver read data from underlying channel
Wait for call from above packet = make_pkt(data)
udt_send(packet)
rdt_send(data)extract (packetdata)deliver_data(data)
Wait for call from
below
rdt_rcv(packet)
sender receiver
Transport Layer 3-18
Rdt20 channel with bit errors
underlying channel may flip bits in packetrecall checksum to detect bit errors
the question how to recover from errorsacknowledgements (ACKs) receiver explicitly tells sender that pkt received OKnegative acknowledgements (NAKs) receiver explicitly tells sender that pkt had errorssender retransmits pkt on receipt of NAK
new mechanisms in rdt20 (beyond rdt10)error detectionreceiver feedback control msgs (ACKNAK) rcvr-gtsender
Transport Layer 3-19
rdt20 FSM specification
Wait for call from above
snkpkt = make_pkt(data checksum)udt_send(sndpkt)
extract(rcvpktdata)deliver_data(data)udt_send(ACK)
rdt_rcv(rcvpkt) ampamp notcorrupt(rcvpkt)
rdt_rcv(rcvpkt) ampamp isACK(rcvpkt)
udt_send(sndpkt)
rdt_rcv(rcvpkt) ampampisNAK(rcvpkt)
udt_send(NAK)
rdt_rcv(rcvpkt) ampamp corrupt(rcvpkt)
Wait for ACK or
NAK
Wait for call from
belowsender
receiverrdt_send(data)
Λ
Transport Layer 3-20
rdt20 operation with no errors
Wait for call from above
snkpkt = make_pkt(data checksum)udt_send(sndpkt)
extract(rcvpktdata)deliver_data(data)udt_send(ACK)
rdt_rcv(rcvpkt) ampamp notcorrupt(rcvpkt)
rdt_rcv(rcvpkt) ampamp isACK(rcvpkt)
udt_send(sndpkt)
rdt_rcv(rcvpkt) ampampisNAK(rcvpkt)
udt_send(NAK)
rdt_rcv(rcvpkt) ampamp corrupt(rcvpkt)
Wait for ACK or
NAK
Wait for call from
below
rdt_send(data)
Λ
Transport Layer 3-21
rdt20 error scenario
Wait for call from above
snkpkt = make_pkt(data checksum)udt_send(sndpkt)
extract(rcvpktdata)deliver_data(data)udt_send(ACK)
rdt_rcv(rcvpkt) ampamp notcorrupt(rcvpkt)
rdt_rcv(rcvpkt) ampamp isACK(rcvpkt)
udt_send(sndpkt)
rdt_rcv(rcvpkt) ampampisNAK(rcvpkt)
udt_send(NAK)
rdt_rcv(rcvpkt) ampamp corrupt(rcvpkt)
Wait for ACK or
NAK
Wait for call from
below
rdt_send(data)
Λ
Transport Layer 3-22
rdt20 has a fatal flaw
What happens if ACKNAK corruptedsender doesnrsquot know what happened at receivercanrsquot just retransmit possible duplicate
What to dosender ACKsNAKs receiverrsquos ACKNAK What if sender ACKNAK lostretransmit but this might cause retransmission of correctly received pkt
Handling duplicates sender adds sequence number to each pktsender retransmits current pkt if ACKNAK garbledreceiver discards (doesnrsquot deliver up) duplicate pkt
Sender sends one packet then waits for receiver response
stop and wait
Transport Layer 3-23
rdt21 sender handles garbled ACKNAKs
Wait for call 0 from
above
sndpkt = make_pkt(0 data checksum)udt_send(sndpkt)
rdt_send(data)
Wait for ACK or NAK 0 udt_send(sndpkt)
rdt_rcv(rcvpkt) ampamp ( corrupt(rcvpkt) ||isNAK(rcvpkt) )
sndpkt = make_pkt(1 data checksum)udt_send(sndpkt)
rdt_send(data)
rdt_rcv(rcvpkt) ampamp notcorrupt(rcvpkt) ampamp isACK(rcvpkt)
udt_send(sndpkt)
rdt_rcv(rcvpkt) ampamp ( corrupt(rcvpkt) ||isNAK(rcvpkt) )
rdt_rcv(rcvpkt) ampamp notcorrupt(rcvpkt) ampamp isACK(rcvpkt)
Wait forcall 1 from
above
Wait for ACK or NAK 1
ΛΛ
Transport Layer 3-24
rdt21 receiver handles garbled ACKNAKs
Wait for 0 from below
sndpkt = make_pkt(NAK chksum)udt_send(sndpkt)
rdt_rcv(rcvpkt) ampamp not corrupt(rcvpkt) ampamphas_seq0(rcvpkt)
rdt_rcv(rcvpkt) ampamp notcorrupt(rcvpkt) ampamp has_seq1(rcvpkt)
extract(rcvpktdata)deliver_data(data)sndpkt = make_pkt(ACK chksum)udt_send(sndpkt)
Wait for 1 from below
rdt_rcv(rcvpkt) ampamp notcorrupt(rcvpkt) ampamp has_seq0(rcvpkt)
extract(rcvpktdata)deliver_data(data)sndpkt = make_pkt(ACK chksum)udt_send(sndpkt)
rdt_rcv(rcvpkt) ampamp (corrupt(rcvpkt)
sndpkt = make_pkt(ACK chksum)udt_send(sndpkt)
rdt_rcv(rcvpkt) ampamp not corrupt(rcvpkt) ampamphas_seq1(rcvpkt)
rdt_rcv(rcvpkt) ampamp (corrupt(rcvpkt)
sndpkt = make_pkt(ACK chksum)udt_send(sndpkt)
sndpkt = make_pkt(NAK chksum)udt_send(sndpkt)
Transport Layer 3-25
rdt21 discussion
Senderseq added to pkttwo seq rsquos (01) will suffice Whymust check if received ACKNAK corrupted twice as many states
state must ldquorememberrdquowhether ldquocurrentrdquo pkt has 0 or 1 seq
Receivermust check if received packet is duplicate
state indicates whether 0 or 1 is expected pkt seq
note receiver can notknow if its last ACKNAK received OK at sender
Transport Layer 3-26
rdt22 a NAK-free protocol
same functionality as rdt21 using ACKs onlyinstead of NAK receiver sends ACK for last pkt received OK
receiver must explicitly include seq of pkt being ACKed duplicate ACK at sender results in same action as NAK retransmit current pkt
Transport Layer 3-27
rdt22 sender receiver fragments
Wait for call 0 from
above
sndpkt = make_pkt(0 data checksum)udt_send(sndpkt)
rdt_send(data)
udt_send(sndpkt)
rdt_rcv(rcvpkt) ampamp ( corrupt(rcvpkt) ||
isACK(rcvpkt1) )
rdt_rcv(rcvpkt) ampamp notcorrupt(rcvpkt) ampamp isACK(rcvpkt0)
Wait for ACK
0sender FSM
fragment
Wait for 0 from below
rdt_rcv(rcvpkt) ampamp notcorrupt(rcvpkt) ampamp has_seq1(rcvpkt)
extract(rcvpktdata)deliver_data(data)sndpkt = make_pkt(ACK1 chksum)udt_send(sndpkt)
rdt_rcv(rcvpkt) ampamp (corrupt(rcvpkt) ||
has_seq1(rcvpkt))
udt_send(sndpkt)receiver FSM
fragment
Λ
Transport Layer 3-28
rdt30 channels with errors and loss
New assumptionunderlying channel can also lose packets (data or ACKs)
checksum seq ACKs retransmissions will be of help but not enough
Q how to deal with losssender waits until certain data or ACK lost then retransmitsdrawbacks
Approach sender waits ldquoreasonablerdquo amount of time for ACK retransmits if no ACK received in this timeif pkt (or ACK) just delayed (not lost)
retransmission will be duplicate but use of seq rsquos already handles thisreceiver must specify seq of pkt being ACKed
requires countdown timer
Transport Layer 3-29
rdt30 sendersndpkt = make_pkt(0 data checksum)udt_send(sndpkt)start_timer
rdt_send(data)
Wait for
ACK0
rdt_rcv(rcvpkt) ampamp ( corrupt(rcvpkt) ||isACK(rcvpkt1) )
Wait for call 1 from
above
sndpkt = make_pkt(1 data checksum)udt_send(sndpkt)start_timer
rdt_send(data)
rdt_rcv(rcvpkt) ampamp notcorrupt(rcvpkt) ampamp isACK(rcvpkt0)
rdt_rcv(rcvpkt) ampamp ( corrupt(rcvpkt) ||isACK(rcvpkt0) )
rdt_rcv(rcvpkt) ampamp notcorrupt(rcvpkt) ampamp isACK(rcvpkt1)
stop_timerstop_timer
udt_send(sndpkt)start_timer
timeout
udt_send(sndpkt)start_timer
timeout
rdt_rcv(rcvpkt)
Wait for call 0from
above
Wait for
ACK1
Λrdt_rcv(rcvpkt)
ΛΛ
Λ
Transport Layer 3-30
rdt30 in action
Transport Layer 3-31
rdt30 in action
Transport Layer 3-32
Performance of rdt30
rdt30 works but performance stinksexample 1 Gbps link 15 ms e-e prop delay 1KB packet
Ttransmit = 8kbpkt109 bsec = 8 microsec
U sender utilization ndash fraction of time sender busy sending1KB pkt every 30 msec -gt 33kBsec thruput over 1 Gbps linknetwork protocol limits use of physical resources
U sender=
008 30008
= 000027 L RRTT + L R
=
L (packet length in bits)R (transmission rate bps) =
Transport Layer 3-33
rdt30 stop-and-wait operation
first packet bit transmitted t = 0
sender receiver
RTT
last packet bit transmitted t = L R
first packet bit arriveslast packet bit arrives send ACK
ACK arrives send next packet t = RTT + L R
U sender=
00830008
= 000027 L RRTT + L R
=
Transport Layer 3-34
Pipelined protocolsPipelining sender allows multiple ldquoin-flightrdquo yet-to-
be-acknowledged pktsrange of sequence numbers must be increasedbuffering at sender andor receiver
Two generic forms of pipelined protocols go-Back-N selective repeat
Transport Layer 3-35
Pipelining increased utilization
first packet bit transmitted t = 0
sender receiver
RTT
last bit transmitted t = L R
first packet bit arriveslast packet bit arrives send ACK
ACK arrives send next packet t = RTT + L R
last bit of 2nd packet arrives send ACKlast bit of 3rd packet arrives send ACK
U sender=
024 30008
= 000083 L RRTT + L R
=
Increase utilizationby a factor of 3
Transport Layer 3-36
Utilization=N(LR)(RTT+LR) if NLRltRTT+LR Utilization=1 if and the sender pauses after it transmits a window NLRgtRTT+LR and the of packets until it receives first ACK sender does not pause
Transport Layer 3-37
Go-Back-NSender
k-bit seq in pkt headerldquowindowrdquo of up to N consecutive unackrsquoed pkts allowed
ACK(n) ACKs all pkts up to including seq n - ldquocumulative ACKrdquomay receive duplicate ACKs (see receiver)
timer for the entire windowtimeout(n) retransmit pkt n and all higher seq pkts in window
Transport Layer 3-38
GBN sender extended FSM
Wait start_timerudt_send(sndpkt[base])udt_send(sndpkt[base+1])hellipudt_send(sndpkt[nextseqnum-1])
timeout
rdt_send(data)
if (nextseqnum lt base+N) sndpkt[nextseqnum] = make_pkt(nextseqnumdatachksum)udt_send(sndpkt[nextseqnum])if (base == nextseqnum)
start_timernextseqnum++
elserefuse_data(data)
base = getacknum(rcvpkt)+1If (base == nextseqnum)
stop_timerelse
start_timer
rdt_rcv(rcvpkt) ampamp notcorrupt(rcvpkt)
base=1nextseqnum=1
rdt_rcv(rcvpkt) ampamp corrupt(rcvpkt)
Λ
Λ
Transport Layer 3-39
GBN receiver extended FSM
ACK-only always send ACK for correctly-received pktwith highest in-order seq
may generate duplicate ACKsneed only remember expectedseqnum
out-of-order pkt discard (donrsquot buffer) -gt no receiver bufferingRe-ACK pkt with highest in-order seq
Wait
udt_send(sndpkt)default
rdt_rcv(rcvpkt)ampamp notcurrupt(rcvpkt)ampamp hasseqnum(rcvpktexpectedseqnum)
extract(rcvpktdata)deliver_data(data)sndpkt = make_pkt(expectedseqnumACKchksum)udt_send(sndpkt)expectedseqnum++
expectedseqnum=1sndpkt =
make_pkt(0ACKchksum)
Λ
Transport Layer 3-40
GBN inaction
Transport Layer 3-41
Selective Repeat
receiver individually acknowledges all correctly received pkts
buffers pkts as needed for eventual in-order delivery to upper layer
sender only resends pkts for which ACK not received
sender timer for each unACKed pktsender window
N consecutive seq rsquosagain limits seq s of sent unACKed pkts
Transport Layer 3-42
Selective repeat sender receiver windows
Transport Layer 3-43
Selective repeat
data from above if next available seq in window send pkt
timeout(n)resend pkt n restart timer
ACK(n) in [sendbasesendbase+N-1]
mark pkt n as receivedif n smallest unACKed pkt advance window base to next unACKed seq
senderpkt n in [rcvbase rcvbase+N-1]
send ACK(n)out-of-order bufferin-order deliver (also deliver buffered in-order pkts) advance window to next not-yet-received pkt
pkt n in [rcvbase-Nrcvbase-1]
ACK(n)otherwise
ignore
receiver
Transport Layer 3-44
Selective repeat in action
Transport Layer 3-45
Selective repeatdilemma
Example seq rsquos 0 1 2 3window size=3
receiver sees no difference in two scenariosincorrectly passes duplicate data as new in (a)
Q what relationship between seq size and window size
Transport Layer 3-46
Sequence Number vs Window SizeSuppose we use k bits to represent SNQuestion Whatrsquos the minimum number of bits k necessary for a window size of N
sender
receiver
Go-Back-N
expectedSN
snd_base=expectedSN
Q For a given expectedSN whatrsquos the largest possible value for snd_baseA If all the last N ACKs sent by the receiver are received
snd_base = expectedSNexpectedSN+N-1
senderrsquos window
Transport Layer 3-47
Sequence Number vs Window SizeSuppose we use k bits to represent SNQuestion Whatrsquos the minimum number of bits k necessary for a window size of N
sender
receiver
Go-Back-N
expectedSN
snd_base=expectedSN-N
Q For a given expectedSN whatrsquos the smallest possible value for snd_baseA If all the last N ACKs sent by the receiver are not received
snd_base = expectedSN-NexpectedSN-1
senderrsquos window
Transport Layer 3-48
Sequence Number vs Window Size
sender
receiver
Go-Back-N
expectedSN
snd_base=expectedSN-N
All SNs in the interval [expectedSN-NexpectedSN+N-1] (an interval of size 2N) can be received by the receiver Since the receiver accepts on the packet with SN=expectedSN there should be no other packet within this interval with SN=expectedSN Therefore
2k ge N+1expectedSN+N-1
Transport Layer 3-49
Sequence Number vs Window SizeSuppose we use k bits to represent SNQuestion Whatrsquos the minimum number of bits k necessary for a window size of N
sender
receiver
Selective Repeat
rcv_base
snd_base=rcv_base
Q For a given rcv_base whatrsquos the largest possible value for snd_baseA If all the last N ACKs sent by the receiver are received
snd_base = rcv_base (same as go_back-N)rcv_base+N-1
senderrsquos window
receiverrsquos window
rcv_base+N-1
Transport Layer 3-50
Sequence Number vs Window SizeSuppose we use k bits to represent SNQuestion Whatrsquos the minimum number of bits k necessary for a window size of N
sender
receiver
Selective Repeat
rcv_base
snd_base=rcv_base-N
Q For a given rcv_base whatrsquos the smallest possible value for snd_baseA If all the last N ACKs sent by the receiver are not received
snd_base = rcv_base-N (same as Go-Back-N)rcv_base-1
senderrsquos window
rcv_base
receiverrsquos window
rcv_base+N-1
Transport Layer 3-51
Sequence Number vs Window Size
sender
receiver
Selective Repeat
snd_base=rcv_base-N
All SNs in the interval [rcv_base-Nrcv_base+N-1] (an interval of size 2N) can be received by the receiver Since the receiver should be able to distinguish between all packets in this interval and take corresponding action there should be no two packets within thisinterval having the same SN Therefore
2k ge 2Nrcv_base+N-1
rcv_basercv_base
receiverrsquos window
rcv_base+N-1
Transport Layer 3-52
TCP Overview RFCs 793 1122 1323 2018 2581
full duplex databi-directional data flow in same connectionMSS maximum segment size
connection-orientedhandshaking (exchange of control msgs) initrsquossender receiver state before data exchange
flow controlledsender will not overwhelm receiver
point-to-pointone sender one receiver
reliable in-order byte stream
no ldquomessage boundariesrdquopipelined
TCP congestion and flow control set window size
send amp receive buffers
socketdoor
TCPsend buffer
TCPreceive buffer
socketdoor
segment
applicationwrites data
applicationreads data
Transport Layer 3-53
TCP segment structure
source port dest port
32 bits
applicationdata
(variable length)
sequence numberacknowledgement number
Receive windowUrg data pnterchecksum
FSRPAUheadlen
notused
Options (variable length)
URG urgent data (generally not used)
ACK ACK valid
PSH push data now(generally not used)
RST SYN FINconnection estab(setup teardown
commands)
bytes rcvr willingto accept
Internetchecksum
(as in UDP)
countingby bytes of data(not segments)
Transport Layer 3-54
TCP seq rsquos and ACKsSeq rsquos
byte stream ldquonumberrdquo of first byte in segmentrsquos dataACKs
seq of next byte expected from other sidecumulative ACK
Q how receiver handles out-of-order segmentsA TCP spec doesnrsquot say - up to implementationWidely used implementations of TCP buffer out-of-order segments
Transport Layer 3-55
TCP Round Trip Time and Timeout
Q how to set TCP timeout valuelonger than RTT
but RTT variestoo short premature timeout
unnecessary retransmissions
too long slow reaction to segment loss
Q how to estimate RTTSampleRTT measured time from segment transmission until ACK receipt
ignore retransmissionsSampleRTT will vary want estimated RTT ldquosmootherrdquo
average several recent measurements not just current SampleRTT
Transport Layer 3-56
TCP Round Trip Time and Timeout
EstimatedRTT = (1- α)EstimatedRTT + αSampleRTT
Exponential weighted moving averageinfluence of past sample decreases exponentially fasttypical value α = 0125
Transport Layer 3-57
Example RTT estimationRTT gaiacsumassedu to fantasiaeurecomfr
100
150
200
250
300
350
1 8 15 22 29 36 43 50 57 64 71 78 85 92 99 106
time (seconnds)
RTT
(mill
iseco
nds)
SampleRTT Estimated RTT
Transport Layer 3-58
TCP Round Trip Time and TimeoutSetting the timeout
EstimatedRTT plus ldquosafety marginrdquolarge variation in EstimatedRTT -gt larger safety margin
first estimate of how much SampleRTT deviates from EstimatedRTT
TimeoutInterval = EstimatedRTT + 4DevRTT
DevRTT = (1-β)DevRTT +β|SampleRTT-EstimatedRTT|
(typically β = 025)
Then set timeout interval
Transport Layer 3-59
TCP reliable data transfer
TCP creates rdtservice on top of IPrsquos unreliable servicePipelined segmentsCumulative acksTCP uses single retransmission timer however it just retransmits the first segment in the window
Retransmissions are triggered by
timeout eventsduplicate acks
Initially consider simplified TCP sender
ignore duplicate acksignore flow control congestion control
Transport Layer 3-60
TCP sender eventsdata rcvd from app
Create segment with seq seq is byte-stream number of first data byte in segmentstart timer if not already running (think of timer as for oldest unacked segment)expiration interval TimeOutInterval
timeoutretransmit segment that caused timeout (first segment in the window)restart timer
Ack rcvdIf acknowledges previously unacked segments
update what is known to be ackedstart timer if there are outstanding segments
Transport Layer 3-61
TCP sender(simplified)
NextSeqNum = InitialSeqNumSendBase = InitialSeqNum
loop (forever) switch(event)
event data received from application above create TCP segment with sequence number NextSeqNumif (timer currently not running)
start timerpass segment to IP NextSeqNum = NextSeqNum + length(data)
event timer timeoutretransmit not-yet-acknowledged segment with
smallest sequence numberstart timer
event ACK received with ACK field value of y if (y gt SendBase)
SendBase = yif (there are currently not-yet-acknowledged segments)
start timer
end of loop forever
Commentbull SendBase-1 last cumulatively ackrsquoed byteExamplebull SendBase-1 = 71y= 73 so the rcvrwants 73+ y gt SendBase sothat new data is acked
Transport Layer 3-62
TCP retransmission scenariosHost A
Seq=100 20 bytes data
ACK=100
timepremature timeout
Host B
Seq=92 8 bytes data
ACK=120
Seq=92 8 bytes data
Seq=
92 t
imeo
ut
ACK=120
Host A
Seq=92 8 bytes data
ACK=100
loss
tim
eout
lost ACK scenario
Host B
X
Seq=92 8 bytes data
ACK=100
time
Seq=
92 t
imeo
utSendBase
= 100
SendBase= 120
SendBase= 120
Sendbase= 100
Transport Layer 3-63
TCP retransmission scenarios (more)Host A
Seq=92 8 bytes data
ACK=100
loss
tim
eout
Cumulative ACK scenario
Host B
X
Seq=100 20 bytes data
ACK=120
time
SendBase= 120
Transport Layer 3-64
TCP ACK generation [RFC 1122 RFC 2581]
Event at Receiver
Arrival of in-order segment withexpected seq All data up toexpected seq already ACKed
Arrival of in-order segment withexpected seq One other segment has ACK pending
Arrival of out-of-order segmenthigher-than-expect seq Gap detected
Arrival of segment that partially or completely fills gap
TCP Receiver action
Delayed ACK Wait up to 500msfor next segment If no next segmentsend ACK
Immediately send single cumulative ACK ACKing both in-order segments
Immediately send duplicate ACK indicating seq of next expected byte
Immediate send ACK provided thatsegment startsat lower end of gap
Transport Layer 3-65
Fast Retransmit
Time-out period often relatively long
long delay before resending lost packet
Detect lost segments via duplicate ACKs
Sender often sends many segments back-to-backIf segment is lost there will likely be many duplicate ACKs
If sender receives 3 ACKs for the same data it supposes that segment after ACKeddata was lost
fast retransmit resend segment before timer expires
Transport Layer 3-66
Fast RetransmitResend a segment after 3 duplicate ACKs since a duplicate ACK means that an out-of sequence segment was receivedduplicate ACKs due to packet reorderingif window is small donrsquot get duplicate ACKs
Host A
tim
eout
Host B
time
X
resend seq X2
seq x1seq x2seq x3seq x4seq x5
ACK x1
ACK x1ACK x1ACK x1
tripleduplicate
ACKs
Transport Layer 3-67
event ACK received with ACK field value of y if (y gt SendBase)
SendBase = yif (there are currently not-yet-acknowledged segments)
start timer
else increment count of dup ACKs received for yif (count of dup ACKs received for y = 3)
resend segment with sequence number y
Fast retransmit algorithm
a duplicate ACK for already ACKed segment
fast retransmit
Transport Layer 3-68
TCP Flow Control
receive side of TCP connection has a receive buffer
speed-matching service matching the send rate to the receiving apprsquos drain rate
app process may be slow at reading from buffer
sender wonrsquot overflowreceiverrsquos buffer by
transmitting too muchtoo fast
flow control
Transport Layer 3-69
TCP Flow control how it works
(Suppose TCP receiver discards out-of-order segments)spare room in buffer
= RcvWin
= RcvBuffer-[LastByteRcvd -LastByteRead]
Rcvr advertises spare room by including value of RcvWin in segmentsSender limits unACKeddata to RcvWin
guarantees receive buffer doesnrsquot overflow
Transport Layer 3-70
Sliding Window Flow Control Example
3K
2K SeqNo=0
ReceiverBuffer
0 4KSendersends 2Kof data
2K
AckNo=2048 RcvWin=2048Sendersends 2Kof data 2K SeqNo=2048
4K
AckNo=4096 RcvWin=0
AckNo=4096 RcvWin=1024
Sender blocked
Transport Layer 3-71
Principles of Congestion Control
Congestioninformally ldquotoo many sources sending too much data too fast for network to handlerdquodifferent from flow controlmanifestations
lost packets (buffer overflow at routers)long delays (queueing in router buffers)
a top-10 problem
Transport Layer 3-72
Causescosts of congestion scenario 1
two senders two receiversone router infinite buffers no retransmission
large delays when congestedmaximum achievable throughput
unlimited shared output link buffers
Host Aλin original data
Host B
λout
Transport Layer 3-73
Causescosts of congestion scenario 2
one router finite buffers sender retransmission of lost packet
finite shared output link buffers
Host A λin original data
Host B
λout
λin original data plus retransmitted data
Transport Layer 3-74
Causescosts of congestion scenario 2always (goodput)ldquoperfectrdquo retransmission only when loss
retransmission of delayed (not lost) packet makes larger(than perfect case) for same
λin
λout=
λin
λoutgtλ
inλout
ldquocostsrdquo of congestionmore work (retrans) for given ldquogoodputrdquounneeded retransmissions link carries multiple copies of pkt
R2
R2λin
λ out
b
R2
R2λin
λ out
a
R2
R2λin
λ out
c
R4
R3
Transport Layer 3-75
Causescosts of congestion scenario 3four sendersmultihop pathstimeoutretransmit
λin
Q what happens as and increase λ
in
finite shared output link buffers
Host Aλin original data
Host B
λout
λin original data plus retransmitted data
Transport Layer 3-76
Causescosts of congestion scenario 3
another ldquocostrdquo of congestionwhen packet dropped any ldquoupstream transmission capacity used for that packet was wasted
Host A
Host B
λou
t
Transport Layer 3-77
Approaches towards congestion control
End-end congestion controlno explicit feedback from networkcongestion inferred from end-system observed loss delayapproach taken by TCP
Network-assisted congestion controlrouters provide feedback to end systems
single bit indicating congestion (SNA DECbit TCPIP ECN ATM)explicit rate sender should send at
Two broad approaches towards congestion control
Transport Layer 3-78
TCP Congestion Control
end-end control (no network assistance)sender limits transmissionLastByteSent-LastByteAcked
le CongWin
CongWin is dynamic function of perceived network congestion
How does sender perceive congestionloss event = timeout or3 duplicate acksTCP sender reduces rate (CongWin) after loss event
two modes of operationSlow Start (SS)Congestion avoidance (CA) or Additive Increase Multiplicative Decrease (AIMD)
Transport Layer 3-79
TCP congestion control bandwidth probing
ldquoprobing for bandwidthrdquo increase transmission rate on receipt of ACK until eventually loss occurs then decrease transmission rate
continue to increase on ACK decrease on loss (since available bandwidth is changing depending on other connections in network)
ACKs being received so increase rate
X
X
XX
X loss so decrease rate
send
ing
rate
time
Q how fast to increasedecreasedetails to follow
TCPrsquosldquosawtoothrdquobehavior
Transport Layer 3-80
TCP Congestion Control details
sender limits rate by limiting number of unACKed bytes ldquoin pipelinerdquo
cwnd differs from rwnd (how why)sender limited by min(cwndrwnd)
roughly
cwnd is dynamic function of perceived network congestion
rate = cwndRTT bytessec
LastByteSent-LastByteAcked le cwnd
cwndbytes
RTT
ACK(s)
Transport Layer 3-81
TCP Congestion Control more details
segment loss event reducing cwndtimeout no response from receiver
cut cwnd to 13 duplicate ACKs at least some segments getting through (recall fast retransmit)
cut cwnd in half less aggressively than on timeout
ACK received increase cwndTwo modes of operation
slowstart phase bull increase exponentially
fast (despite name) at connection start or following timeout
congestion avoidance bull increase linearly
Transport Layer 3-82
TCP Slow Start Phasewhen connection begins cwnd = 1 MSS
example MSS = 500 bytes amp RTT = 200 msecinitial rate = 20 kbps
available bandwidth may be gtgt MSSRTT
desirable to quickly ramp up to respectable rate
increase rate exponentially until first loss event or when threshold reached
double cwnd every RTTdone by incrementing cwnd by 1 for every ACK received
Host A
one segment
RTT
Host B
time
two segments
four segments
Transport Layer 3-83
Slow Start ExampleThe congestion window size grows very rapidly
For every ACK we increase CongWin by 1 irrespective of the number of segments ACKrsquoeddouble CongWinevery RTTinitial rate is slow but ramps up exponentially fast
TCP slows down the increase of CongWinwhen CongWin gt ssthresh
segment 1
ACK for segment 1
cwnd = 1
cwnd = 2 segment 2segment 3
ACK for segments 2
cwnd = 4 segment 4segment 5segment 6
ACK for segments 4
cwnd = 7
ACK for segments 3
ACK for segments 5
ACK for segments 6
cwnd = 3
cwnd = 5
cwnd = 6ACK for segments 7
cwnd = 8
segment 7
Transport Layer 3-84
TCP Congestion Avoidance Phase
when cwnd gt ssthreshgrow cwnd linearly
increase cwnd by 1 MSS per RTT approach possible congestion slower than in slowstartimplementation cwnd= cwnd + MSScwndfor each ACK received
ACKs increase cwndby 1 MSS per RTT additive increaseloss cut cwnd in half (non-timeout-detected loss ) multiplicative decrease
AIMD
AIMD Additive IncreaseMultiplicative Decrease
Transport Layer 3-85
Congestion AvoidanceCongestion avoidance phase is started if CongWin has reached the slow-start threshold value
If CongWin gt= ssthresh then each time an ACK is received increment CongWin as follows
bull CongWin = CongWin + 1CongWin (CongWin in segments)
bull In actual TCP implementation CongWin is in BytesCongWin = CongWin + MSS (MSSCongWin)
So CongWin is increased by one only if all CongWinsegments have been acknowledged
Transport Layer 3-86
Example Slow StartCongestion AvoidanceAssume that
ssthresh = 8
cwnd = 1
cwnd = 2
cwnd = 4
cwnd = 8
cwnd = 9
cwnd = 10
02468
101214
t=0
t=2
t=4
t=6
Roundtrip times
Cw
nd(in
seg
men
ts)
ssthresh
cwnd = 3
cwnd = 5cwnd = 6cwnd = 7
Transport Layer 3-87
Slow Start Congestion AvoidanceA typical plot of CongWin for a TCP connection
(MSS = 1500 bytes) with TCP Tahoe
SS
CA
ssthresh
Transport Layer 3-88
Responses to CongestionTCP assumes there is congestion if it detects a packet lossA TCP sender can detect lost packets via loss events
bull Timeout of a retransmission timerbull Receipt of 3 duplicate ACKs (fast retransmit)
TCP interprets a Timeout as a binary congestion signal When a timeout occurs the sender performs
ssthresh is set to half the current size of the congestion window
ssthresh = CongWin 2CongWin is reset to one
CongWin = 1and slow-start is entered
Transport Layer 3-89
Fast Recovery (differentiation btwn two loss events) After 3 dup ACKs (fast Retransmit)
ssthresh = CongWin2CongWin = CongWin2window then grows linearly
But after timeout eventCongWin = 1 MSS window then grows exponentiallyto the threshold then grows linearly
bull 3 dup ACKs indicates network capable of delivering some segmentsbull timeout before 3 dup ACKs is ldquomore alarmingrdquo
Philosophy
3-90
TCP Congestion ControlInitially
CongWin = 1ssthresh = advertised window size
New Ack receivedif (CongWin lt ssthresh) Slow Start
CongWin = CongWin + 1else Congestion Avoidance
CongWin = CongWin + 1CongWinTimeout
ssthresh = CongWin2CongWin = 1
Fast Retransmissionssthresh = CongWin2CongWin = CongWin2
Slow Start (exponential increase phase) is continued until CongWin reaches half of the level where the loss event occurred last time CongWin is increased slowly after (linear increase in Congestion Avoidance phase)
Transport Layer 3-91
Popular ldquoflavorsrdquo of TCP
ssthresh
ssthresh
TCP Tahoe
TCP Reno
Transmission round
cwnd
win
dow
siz
e (in
seg
men
ts)
Transport Layer 3-92
Summary TCP Congestion ControlWhen CongWin is below Threshold sender in slow-start phase window grows exponentiallyWhen CongWin is above Threshold sender is in congestion-avoidance phase window grows linearlyWhen a triple duplicate ACK occurs Threshold set to CongWin2 and CongWin set to ThresholdWhen timeout occurs Threshold set to CongWin2 and CongWin is set to 1 MSS The actual sender window size is determined based on the congestion and flow control algorithms
SenderWin=min(RcvWinCongWin)
Transport Layer 3-93
TCP Congestion Control SummaryEvent State TCP Sender Action Commentary
ACK receipt for previously unackeddata
Slow Start (SS)
CongWin = CongWin + MSS If (CongWin gt Threshold)
set state to ldquoCongestion Avoidancerdquo
Resulting in a doubling of CongWin every RTT
ACK receipt for previously unackeddata
CongestionAvoidance (CA)
CongWin = CongWin+MSS (MSSCongWin)
Additive increase resulting in increase of CongWin by 1 MSS every RTT
Loss event detected by triple duplicate ACK
SS or CA Threshold = CongWin2 CongWin = ThresholdSet state to ldquoCongestion Avoidancerdquo
Fast recovery implementing multiplicative decrease CongWin will not drop below 1 MSS
Timeout SS or CA Threshold = CongWin2 CongWin = 1 MSSSet state to ldquoSlow Startrdquo
Enter slow start
Duplicate ACK
SS or CA Increment duplicate ACK count for segment being acked
CongWin and Threshold not changed
Transport Layer 3-94
TCP throughput
Q whatrsquos average throughout of TCP as function of window size RTT
ignoring slow startlet W be window size when loss occurs
when window is W throughput is WRTTjust after loss window drops to W2 throughput to W2RTT average throughout 75 WRTT
Transport Layer 3-95
TCP Futures TCP over ldquolong fat pipesrdquo
example 1500 byte segments 100ms RTT want 10 Gbps throughputrequires window size W = 83333 in-flight segmentsthroughput in terms of loss rate
L = 210-10 Wownew versions of TCP for high-speed
LRTTMSSsdot221
Transport Layer 3-96
Fairness goal if K TCP sessions share same bottleneck link of bandwidth R each should have average rate of RK
TCP connection 1
bottleneckrouter
capacity R
TCP connection 2
TCP Fairness
Transport Layer 3-97
Why is TCP fairTwo competing sessions
Additive increase gives slope of 1 as throughout increasesmultiplicative decrease decreases throughput proportionally
R
R
equal bandwidth share
Connection 1 throughput
Conn
ecti
on 2
thr
ough
p ut
congestion avoidance additive increaseloss decrease window by factor of 2
congestion avoidance additive increaseloss decrease window by factor of 2
Transport Layer 3-98
Fairness (more)Fairness and UDP
Multimedia apps often do not use TCP
do not want rate throttled by congestion control
Instead use UDPpump audiovideo at constant rate tolerate packet loss
Research area TCP friendly
Fairness and parallel TCP connectionsnothing prevents app from opening parallel cnctionsbetween 2 hostsWeb browsers do this Example link of rate R supporting 9 cnctions
new app asks for 1 TCP gets rate R10new app asks for 11 TCPs gets R2
Transport Layer 3-99
TCP Connection ManagementRecall TCP sender receiver
establish ldquoconnectionrdquobefore exchanging data segmentsinitialize TCP variables
seq sbuffers flow control info (eg RcvWindow)
client connection initiatorSocket clientSocket = new Socket(hostnameport
number)
server contacted by clientSocket connectionSocket = welcomeSocketaccept()
Three way handshakeStep 1 client host sends TCP
SYN segment to serverspecifies initial seq no data
Step 2 server host receives SYN replies with SYNACK segment
server allocates buffersspecifies server initial seq
Step 3 client receives SYNACK replies with ACK segment which may contain data
Transport Layer 3-100
TCP Connection Management (cont)
Closing a connection
client closes socketclientSocketclose()
Step 1 client end system sends TCP FIN control segment to server
Step 2 server receives FIN replies with ACK Closes connection sends FIN
client
FIN
server
ACK
ACK
FIN
close
close
closed
tim
ed w
ait
Transport Layer 3-101
TCP Connection Management (cont)
Step 3 client receives FIN replies with ACK
Enters ldquotimed waitrdquo -will respond with ACK to received FINs
Step 4 server receives ACK Connection closed
client
FIN
server
ACK
ACK
FIN
closing
closing
closed
tim
ed w
ait
closed
Transport Layer 3-102
TCP Connection Management (cont)
TCP clientlifecycle
TCP serverlifecycle
Transport Layer 3-103
Tuning TCPIP Parameters TCPIP parameters
A set of default values may not be optimal for all applicationsThe network administrator may wish to turn on or off some TCPIP functions for performance or security considerations
Many Unix and Linux systems provide some flexibility in tuning the TCPIP kernelsbinsysctl is used to configure the Linux kernel parameters at runtime
Default kernel configuration file is sbinsysctlconfFrequently used sysctl options
bull sysctl ndasha or sysctl ndashA list all current valuesbull sysctl ndashp file_name load the sysctl setting from a configuration
filebull sysctl ndashw variable=value change the value of the parameter
Transport Layer 3-104
SomeTCP Parameters in Linux Kerneltcp_syn_retries
Number of SYN packets the kernel will send before giving up on the new connection
tcp_synack_retriesnumber of SYN+ACK packets sent before the kernel gives up on the connection
tcp_window_scalingMaximum window size of 65535 bytes not enough for for really fast networks The window scaling options allows for almost gigabyte windows which is good for connections with large delay-bandwidth product
tcp_max_syn_backlogMaximal number of remembered connection requests which still did not receive an acknowledgment from connecting client
tcp_fin_timeoutHow many seconds to wait for a final FIN packet before the socket is closed required to prevent denial-of-service (DoS) attacks Default value is 60 seconds
Transport Layer 3-105
SomeTCP Parameters in Linux Kerneltcp_rmem
This is a vector of 3 integers [min default max] These parameters are used by TCP to dynamically adjust receive buffer sizesmin - minimum size of the receive buffer used by each TCP socket The default value is 4K default - the default size of the receive buffer for a TCP socket The default value is 87380 bytes and is lowered to 43689 in low memory systems If larger receive buffer sizes are desired this value should be increased max - the maximum size of the receive buffer used by each TCP socket The default value of 873802 bytes is lowered to 87380 in low memory systems
tcp_smemSend buffer parameters [min default max] similar to tcp_rmem
- Chapter 3 Transport Layer
- Transport services and protocols
- Transport vs network layer
- Internet transport-layer protocols
- Multiplexingdemultiplexing
- How demultiplexing works
- Connectionless demultiplexing
- Connection-oriented demux
- Connection-oriented demux (cont)
- Connection-oriented demux Threaded Web Server
- UDP User Datagram Protocol [RFC 768]
- UDP more
- UDP checksum
- Principles of Reliable data transfer
- Reliable data transfer getting started
- Reliable data transfer getting started
- Rdt10 reliable transfer over a reliable channel
- Rdt20 channel with bit errors
- rdt20 FSM specification
- rdt20 operation with no errors
- rdt20 error scenario
- rdt20 has a fatal flaw
- rdt21 sender handles garbled ACKNAKs
- rdt21 receiver handles garbled ACKNAKs
- rdt21 discussion
- rdt22 a NAK-free protocol
- rdt22 sender receiver fragments
- rdt30 channels with errors and loss
- rdt30 sender
- rdt30 in action
- rdt30 in action
- Performance of rdt30
- rdt30 stop-and-wait operation
- Pipelined protocols
- Pipelining increased utilization
- Go-Back-N
- GBN sender extended FSM
- GBN receiver extended FSM
- GBN inaction
- Selective Repeat
- Selective repeat sender receiver windows
- Selective repeat
- Selective repeat in action
- Selective repeat dilemma
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- TCP Overview RFCs 793 1122 1323 2018 2581
- TCP segment structure
- TCP seq rsquos and ACKs
- TCP Round Trip Time and Timeout
- TCP Round Trip Time and Timeout
- Example RTT estimation
- TCP Round Trip Time and Timeout
- TCP reliable data transfer
- TCP sender events
- TCP sender(simplified)
- TCP retransmission scenarios
- TCP retransmission scenarios (more)
- TCP ACK generation [RFC 1122 RFC 2581]
- Fast Retransmit
- Fast Retransmit
- Fast retransmit algorithm
- TCP Flow Control
- TCP Flow control how it works
- Sliding Window Flow Control Example
- Principles of Congestion Control
- Causescosts of congestion scenario 1
- Causescosts of congestion scenario 2
- Causescosts of congestion scenario 2
- Causescosts of congestion scenario 3
- Causescosts of congestion scenario 3
- Approaches towards congestion control
- TCP Congestion Control
- TCP congestion control bandwidth probing
- TCP Congestion Control details
- TCP Congestion Control more details
- TCP Slow Start Phase
- Slow Start Example
- TCP Congestion Avoidance Phase
- Congestion Avoidance
- Example Slow StartCongestion Avoidance
- Slow Start Congestion Avoidance
- Responses to Congestion
- Fast Recovery (differentiation btwn two loss events)
- TCP Congestion Control
- Popular ldquoflavorsrdquo of TCP
- Summary TCP Congestion Control
- TCP Congestion Control Summary
- TCP throughput
- TCP Futures TCP over ldquolong fat pipesrdquo
- TCP Fairness
- Why is TCP fair
- Fairness (more)
- TCP Connection Management
- TCP Connection Management (cont)
- TCP Connection Management (cont)
- TCP Connection Management (cont)
- Tuning TCPIP Parameters
- SomeTCP Parameters in Linux Kernel
- SomeTCP Parameters in Linux Kernel
-
Transport Layer 3-5
Multiplexingdemultiplexing
application
transport
network
link
physical
P1 application
transport
network
link
physical
application
transport
network
link
physical
P2P3 P4P1
host 1 host 2 host 3
= process= socket
delivering received segmentsto correct socket
Demultiplexing at rcv hostgathering data from multiplesockets enveloping data with header (later used for demultiplexing)
Multiplexing at send host
Transport Layer 3-6
How demultiplexing workshost receives IP datagrams
each datagram has source IP address destination IP addresseach datagram carries 1 transport-layer segmenteach segment has source destination port number (recall well-known port numbers for specific applications)
host uses IP addresses amp port numbers to direct segment to appropriate socket
source port dest port
32 bits
applicationdata
(message)
other header fields
TCPUDP segment format
Transport Layer 3-7
Connectionless demultiplexing
Create sockets with port numbers
DatagramSocket mySocket1 = new DatagramSocket(9111)
DatagramSocket mySocket2 = new DatagramSocket(9222)
UDP socket identified by two-tuple
(dest IP address dest port number)
When host receives UDP segment
checks destination port number in segmentdirects UDP segment to socket with that port number
IP datagrams with different source IP addresses andor source port numbers directed to same socket
Transport Layer 3-8
Connection-oriented demux
TCP socket identified by 4-tuple
source IP addresssource port numberdest IP addressdest port number
recv host uses all four values to direct segment to appropriate socket
Server host may support many simultaneous TCP sockets
each socket identified by its own 4-tuple
Web servers have different sockets for each connecting client
non-persistent HTTP will have different socket for each request
Transport Layer 3-9
Connection-oriented demux(cont)
ClientIPB
P1
clientIP A
P1P2P4
serverIP C
SP 9157DP 80
SP 9157DP 80
P5 P6 P3
D-IPCS-IP AD-IPC
S-IP B
SP 5775DP 80
D-IPCS-IP B
Transport Layer 3-10
Connection-oriented demuxThreaded Web Server
ClientIPB
P1
clientIP A
P1P2P4
serverIP C
SP 9157DP 80
SP 9157DP 80
P5 P6 P3
D-IPCS-IP AD-IPC
S-IP B
SP 5775DP 80
D-IPCS-IP B
P4
Transport Layer 3-11
UDP User Datagram Protocol [RFC 768]
ldquono frillsrdquo ldquobare bonesrdquoInternet transport protocolldquobest effortrdquo service UDP segments may be
lostdelivered out of order to app
connectionlessno handshaking between UDP sender receivereach UDP segment handled independently of others
Why is there a UDPno connection establishment (which can add delay)simple no connection state at sender receiversmall segment headerno congestion control UDP can blast away as fast as desired
Transport Layer 3-12
UDP moreoften used for streaming multimedia apps
loss tolerantrate sensitive
other UDP usesDNSSNMP
reliable transfer over UDP add reliability at application layer
application-specific error recovery
source port dest port
32 bits
Applicationdata
(message)
UDP segment format
length checksumLength in
bytes of UDPsegmentincluding
header
Transport Layer 3-13
UDP checksum
Sendertreat segment contents as sequence of 16-bit integerschecksum addition (1rsquos complement sum) of segment contents with wraparound of carry out bitsender puts checksum value into UDP checksum field
Receivercompute checksum of received segmentcheck if computed checksum equals checksum field value
NO - error detectedYES - no error detected
Goal detect ldquoerrorsrdquo (eg flipped bits) in transmitted segment
Transport Layer 3-14
Principles of Reliable data transferimportant in app transport link layerstop-10 list of important networking topics
characteristics of unreliable channel will determine complexity of reliable data transfer protocol (rdt)
netw
ork
laye
r
Transport Layer 3-15
Reliable data transfer getting started
sendside
receiveside
rdt_send() called from above (eg by app) Passed data to
deliver to receiver upper layer
udt_send() called by rdtto transfer packet over
unreliable channel to receiver
rdt_rcv() called when packet arrives on rcv-side of channel
deliver_data() called by rdt to deliver data to upper
Transport Layer 3-16
Reliable data transfer getting startedWersquoll
incrementally develop sender receiver sides of reliable data transfer protocol (rdt)consider only unidirectional data transfer
but control info will flow on both directionsuse finite state machines (FSM) to specify sender receiver
state1
state2
event causing state transitionactions taken on state transition
state when in this ldquostaterdquo next state
uniquely determined by next event
eventactions
Transport Layer 3-17
Rdt10 reliable transfer over a reliable channel
underlying channel perfectly reliableno bit errorsno loss of packets
separate FSMs for sender receiversender sends data into underlying channelreceiver read data from underlying channel
Wait for call from above packet = make_pkt(data)
udt_send(packet)
rdt_send(data)extract (packetdata)deliver_data(data)
Wait for call from
below
rdt_rcv(packet)
sender receiver
Transport Layer 3-18
Rdt20 channel with bit errors
underlying channel may flip bits in packetrecall checksum to detect bit errors
the question how to recover from errorsacknowledgements (ACKs) receiver explicitly tells sender that pkt received OKnegative acknowledgements (NAKs) receiver explicitly tells sender that pkt had errorssender retransmits pkt on receipt of NAK
new mechanisms in rdt20 (beyond rdt10)error detectionreceiver feedback control msgs (ACKNAK) rcvr-gtsender
Transport Layer 3-19
rdt20 FSM specification
Wait for call from above
snkpkt = make_pkt(data checksum)udt_send(sndpkt)
extract(rcvpktdata)deliver_data(data)udt_send(ACK)
rdt_rcv(rcvpkt) ampamp notcorrupt(rcvpkt)
rdt_rcv(rcvpkt) ampamp isACK(rcvpkt)
udt_send(sndpkt)
rdt_rcv(rcvpkt) ampampisNAK(rcvpkt)
udt_send(NAK)
rdt_rcv(rcvpkt) ampamp corrupt(rcvpkt)
Wait for ACK or
NAK
Wait for call from
belowsender
receiverrdt_send(data)
Λ
Transport Layer 3-20
rdt20 operation with no errors
Wait for call from above
snkpkt = make_pkt(data checksum)udt_send(sndpkt)
extract(rcvpktdata)deliver_data(data)udt_send(ACK)
rdt_rcv(rcvpkt) ampamp notcorrupt(rcvpkt)
rdt_rcv(rcvpkt) ampamp isACK(rcvpkt)
udt_send(sndpkt)
rdt_rcv(rcvpkt) ampampisNAK(rcvpkt)
udt_send(NAK)
rdt_rcv(rcvpkt) ampamp corrupt(rcvpkt)
Wait for ACK or
NAK
Wait for call from
below
rdt_send(data)
Λ
Transport Layer 3-21
rdt20 error scenario
Wait for call from above
snkpkt = make_pkt(data checksum)udt_send(sndpkt)
extract(rcvpktdata)deliver_data(data)udt_send(ACK)
rdt_rcv(rcvpkt) ampamp notcorrupt(rcvpkt)
rdt_rcv(rcvpkt) ampamp isACK(rcvpkt)
udt_send(sndpkt)
rdt_rcv(rcvpkt) ampampisNAK(rcvpkt)
udt_send(NAK)
rdt_rcv(rcvpkt) ampamp corrupt(rcvpkt)
Wait for ACK or
NAK
Wait for call from
below
rdt_send(data)
Λ
Transport Layer 3-22
rdt20 has a fatal flaw
What happens if ACKNAK corruptedsender doesnrsquot know what happened at receivercanrsquot just retransmit possible duplicate
What to dosender ACKsNAKs receiverrsquos ACKNAK What if sender ACKNAK lostretransmit but this might cause retransmission of correctly received pkt
Handling duplicates sender adds sequence number to each pktsender retransmits current pkt if ACKNAK garbledreceiver discards (doesnrsquot deliver up) duplicate pkt
Sender sends one packet then waits for receiver response
stop and wait
Transport Layer 3-23
rdt21 sender handles garbled ACKNAKs
Wait for call 0 from
above
sndpkt = make_pkt(0 data checksum)udt_send(sndpkt)
rdt_send(data)
Wait for ACK or NAK 0 udt_send(sndpkt)
rdt_rcv(rcvpkt) ampamp ( corrupt(rcvpkt) ||isNAK(rcvpkt) )
sndpkt = make_pkt(1 data checksum)udt_send(sndpkt)
rdt_send(data)
rdt_rcv(rcvpkt) ampamp notcorrupt(rcvpkt) ampamp isACK(rcvpkt)
udt_send(sndpkt)
rdt_rcv(rcvpkt) ampamp ( corrupt(rcvpkt) ||isNAK(rcvpkt) )
rdt_rcv(rcvpkt) ampamp notcorrupt(rcvpkt) ampamp isACK(rcvpkt)
Wait forcall 1 from
above
Wait for ACK or NAK 1
ΛΛ
Transport Layer 3-24
rdt21 receiver handles garbled ACKNAKs
Wait for 0 from below
sndpkt = make_pkt(NAK chksum)udt_send(sndpkt)
rdt_rcv(rcvpkt) ampamp not corrupt(rcvpkt) ampamphas_seq0(rcvpkt)
rdt_rcv(rcvpkt) ampamp notcorrupt(rcvpkt) ampamp has_seq1(rcvpkt)
extract(rcvpktdata)deliver_data(data)sndpkt = make_pkt(ACK chksum)udt_send(sndpkt)
Wait for 1 from below
rdt_rcv(rcvpkt) ampamp notcorrupt(rcvpkt) ampamp has_seq0(rcvpkt)
extract(rcvpktdata)deliver_data(data)sndpkt = make_pkt(ACK chksum)udt_send(sndpkt)
rdt_rcv(rcvpkt) ampamp (corrupt(rcvpkt)
sndpkt = make_pkt(ACK chksum)udt_send(sndpkt)
rdt_rcv(rcvpkt) ampamp not corrupt(rcvpkt) ampamphas_seq1(rcvpkt)
rdt_rcv(rcvpkt) ampamp (corrupt(rcvpkt)
sndpkt = make_pkt(ACK chksum)udt_send(sndpkt)
sndpkt = make_pkt(NAK chksum)udt_send(sndpkt)
Transport Layer 3-25
rdt21 discussion
Senderseq added to pkttwo seq rsquos (01) will suffice Whymust check if received ACKNAK corrupted twice as many states
state must ldquorememberrdquowhether ldquocurrentrdquo pkt has 0 or 1 seq
Receivermust check if received packet is duplicate
state indicates whether 0 or 1 is expected pkt seq
note receiver can notknow if its last ACKNAK received OK at sender
Transport Layer 3-26
rdt22 a NAK-free protocol
same functionality as rdt21 using ACKs onlyinstead of NAK receiver sends ACK for last pkt received OK
receiver must explicitly include seq of pkt being ACKed duplicate ACK at sender results in same action as NAK retransmit current pkt
Transport Layer 3-27
rdt22 sender receiver fragments
Wait for call 0 from
above
sndpkt = make_pkt(0 data checksum)udt_send(sndpkt)
rdt_send(data)
udt_send(sndpkt)
rdt_rcv(rcvpkt) ampamp ( corrupt(rcvpkt) ||
isACK(rcvpkt1) )
rdt_rcv(rcvpkt) ampamp notcorrupt(rcvpkt) ampamp isACK(rcvpkt0)
Wait for ACK
0sender FSM
fragment
Wait for 0 from below
rdt_rcv(rcvpkt) ampamp notcorrupt(rcvpkt) ampamp has_seq1(rcvpkt)
extract(rcvpktdata)deliver_data(data)sndpkt = make_pkt(ACK1 chksum)udt_send(sndpkt)
rdt_rcv(rcvpkt) ampamp (corrupt(rcvpkt) ||
has_seq1(rcvpkt))
udt_send(sndpkt)receiver FSM
fragment
Λ
Transport Layer 3-28
rdt30 channels with errors and loss
New assumptionunderlying channel can also lose packets (data or ACKs)
checksum seq ACKs retransmissions will be of help but not enough
Q how to deal with losssender waits until certain data or ACK lost then retransmitsdrawbacks
Approach sender waits ldquoreasonablerdquo amount of time for ACK retransmits if no ACK received in this timeif pkt (or ACK) just delayed (not lost)
retransmission will be duplicate but use of seq rsquos already handles thisreceiver must specify seq of pkt being ACKed
requires countdown timer
Transport Layer 3-29
rdt30 sendersndpkt = make_pkt(0 data checksum)udt_send(sndpkt)start_timer
rdt_send(data)
Wait for
ACK0
rdt_rcv(rcvpkt) ampamp ( corrupt(rcvpkt) ||isACK(rcvpkt1) )
Wait for call 1 from
above
sndpkt = make_pkt(1 data checksum)udt_send(sndpkt)start_timer
rdt_send(data)
rdt_rcv(rcvpkt) ampamp notcorrupt(rcvpkt) ampamp isACK(rcvpkt0)
rdt_rcv(rcvpkt) ampamp ( corrupt(rcvpkt) ||isACK(rcvpkt0) )
rdt_rcv(rcvpkt) ampamp notcorrupt(rcvpkt) ampamp isACK(rcvpkt1)
stop_timerstop_timer
udt_send(sndpkt)start_timer
timeout
udt_send(sndpkt)start_timer
timeout
rdt_rcv(rcvpkt)
Wait for call 0from
above
Wait for
ACK1
Λrdt_rcv(rcvpkt)
ΛΛ
Λ
Transport Layer 3-30
rdt30 in action
Transport Layer 3-31
rdt30 in action
Transport Layer 3-32
Performance of rdt30
rdt30 works but performance stinksexample 1 Gbps link 15 ms e-e prop delay 1KB packet
Ttransmit = 8kbpkt109 bsec = 8 microsec
U sender utilization ndash fraction of time sender busy sending1KB pkt every 30 msec -gt 33kBsec thruput over 1 Gbps linknetwork protocol limits use of physical resources
U sender=
008 30008
= 000027 L RRTT + L R
=
L (packet length in bits)R (transmission rate bps) =
Transport Layer 3-33
rdt30 stop-and-wait operation
first packet bit transmitted t = 0
sender receiver
RTT
last packet bit transmitted t = L R
first packet bit arriveslast packet bit arrives send ACK
ACK arrives send next packet t = RTT + L R
U sender=
00830008
= 000027 L RRTT + L R
=
Transport Layer 3-34
Pipelined protocolsPipelining sender allows multiple ldquoin-flightrdquo yet-to-
be-acknowledged pktsrange of sequence numbers must be increasedbuffering at sender andor receiver
Two generic forms of pipelined protocols go-Back-N selective repeat
Transport Layer 3-35
Pipelining increased utilization
first packet bit transmitted t = 0
sender receiver
RTT
last bit transmitted t = L R
first packet bit arriveslast packet bit arrives send ACK
ACK arrives send next packet t = RTT + L R
last bit of 2nd packet arrives send ACKlast bit of 3rd packet arrives send ACK
U sender=
024 30008
= 000083 L RRTT + L R
=
Increase utilizationby a factor of 3
Transport Layer 3-36
Utilization=N(LR)(RTT+LR) if NLRltRTT+LR Utilization=1 if and the sender pauses after it transmits a window NLRgtRTT+LR and the of packets until it receives first ACK sender does not pause
Transport Layer 3-37
Go-Back-NSender
k-bit seq in pkt headerldquowindowrdquo of up to N consecutive unackrsquoed pkts allowed
ACK(n) ACKs all pkts up to including seq n - ldquocumulative ACKrdquomay receive duplicate ACKs (see receiver)
timer for the entire windowtimeout(n) retransmit pkt n and all higher seq pkts in window
Transport Layer 3-38
GBN sender extended FSM
Wait start_timerudt_send(sndpkt[base])udt_send(sndpkt[base+1])hellipudt_send(sndpkt[nextseqnum-1])
timeout
rdt_send(data)
if (nextseqnum lt base+N) sndpkt[nextseqnum] = make_pkt(nextseqnumdatachksum)udt_send(sndpkt[nextseqnum])if (base == nextseqnum)
start_timernextseqnum++
elserefuse_data(data)
base = getacknum(rcvpkt)+1If (base == nextseqnum)
stop_timerelse
start_timer
rdt_rcv(rcvpkt) ampamp notcorrupt(rcvpkt)
base=1nextseqnum=1
rdt_rcv(rcvpkt) ampamp corrupt(rcvpkt)
Λ
Λ
Transport Layer 3-39
GBN receiver extended FSM
ACK-only always send ACK for correctly-received pktwith highest in-order seq
may generate duplicate ACKsneed only remember expectedseqnum
out-of-order pkt discard (donrsquot buffer) -gt no receiver bufferingRe-ACK pkt with highest in-order seq
Wait
udt_send(sndpkt)default
rdt_rcv(rcvpkt)ampamp notcurrupt(rcvpkt)ampamp hasseqnum(rcvpktexpectedseqnum)
extract(rcvpktdata)deliver_data(data)sndpkt = make_pkt(expectedseqnumACKchksum)udt_send(sndpkt)expectedseqnum++
expectedseqnum=1sndpkt =
make_pkt(0ACKchksum)
Λ
Transport Layer 3-40
GBN inaction
Transport Layer 3-41
Selective Repeat
receiver individually acknowledges all correctly received pkts
buffers pkts as needed for eventual in-order delivery to upper layer
sender only resends pkts for which ACK not received
sender timer for each unACKed pktsender window
N consecutive seq rsquosagain limits seq s of sent unACKed pkts
Transport Layer 3-42
Selective repeat sender receiver windows
Transport Layer 3-43
Selective repeat
data from above if next available seq in window send pkt
timeout(n)resend pkt n restart timer
ACK(n) in [sendbasesendbase+N-1]
mark pkt n as receivedif n smallest unACKed pkt advance window base to next unACKed seq
senderpkt n in [rcvbase rcvbase+N-1]
send ACK(n)out-of-order bufferin-order deliver (also deliver buffered in-order pkts) advance window to next not-yet-received pkt
pkt n in [rcvbase-Nrcvbase-1]
ACK(n)otherwise
ignore
receiver
Transport Layer 3-44
Selective repeat in action
Transport Layer 3-45
Selective repeatdilemma
Example seq rsquos 0 1 2 3window size=3
receiver sees no difference in two scenariosincorrectly passes duplicate data as new in (a)
Q what relationship between seq size and window size
Transport Layer 3-46
Sequence Number vs Window SizeSuppose we use k bits to represent SNQuestion Whatrsquos the minimum number of bits k necessary for a window size of N
sender
receiver
Go-Back-N
expectedSN
snd_base=expectedSN
Q For a given expectedSN whatrsquos the largest possible value for snd_baseA If all the last N ACKs sent by the receiver are received
snd_base = expectedSNexpectedSN+N-1
senderrsquos window
Transport Layer 3-47
Sequence Number vs Window SizeSuppose we use k bits to represent SNQuestion Whatrsquos the minimum number of bits k necessary for a window size of N
sender
receiver
Go-Back-N
expectedSN
snd_base=expectedSN-N
Q For a given expectedSN whatrsquos the smallest possible value for snd_baseA If all the last N ACKs sent by the receiver are not received
snd_base = expectedSN-NexpectedSN-1
senderrsquos window
Transport Layer 3-48
Sequence Number vs Window Size
sender
receiver
Go-Back-N
expectedSN
snd_base=expectedSN-N
All SNs in the interval [expectedSN-NexpectedSN+N-1] (an interval of size 2N) can be received by the receiver Since the receiver accepts on the packet with SN=expectedSN there should be no other packet within this interval with SN=expectedSN Therefore
2k ge N+1expectedSN+N-1
Transport Layer 3-49
Sequence Number vs Window SizeSuppose we use k bits to represent SNQuestion Whatrsquos the minimum number of bits k necessary for a window size of N
sender
receiver
Selective Repeat
rcv_base
snd_base=rcv_base
Q For a given rcv_base whatrsquos the largest possible value for snd_baseA If all the last N ACKs sent by the receiver are received
snd_base = rcv_base (same as go_back-N)rcv_base+N-1
senderrsquos window
receiverrsquos window
rcv_base+N-1
Transport Layer 3-50
Sequence Number vs Window SizeSuppose we use k bits to represent SNQuestion Whatrsquos the minimum number of bits k necessary for a window size of N
sender
receiver
Selective Repeat
rcv_base
snd_base=rcv_base-N
Q For a given rcv_base whatrsquos the smallest possible value for snd_baseA If all the last N ACKs sent by the receiver are not received
snd_base = rcv_base-N (same as Go-Back-N)rcv_base-1
senderrsquos window
rcv_base
receiverrsquos window
rcv_base+N-1
Transport Layer 3-51
Sequence Number vs Window Size
sender
receiver
Selective Repeat
snd_base=rcv_base-N
All SNs in the interval [rcv_base-Nrcv_base+N-1] (an interval of size 2N) can be received by the receiver Since the receiver should be able to distinguish between all packets in this interval and take corresponding action there should be no two packets within thisinterval having the same SN Therefore
2k ge 2Nrcv_base+N-1
rcv_basercv_base
receiverrsquos window
rcv_base+N-1
Transport Layer 3-52
TCP Overview RFCs 793 1122 1323 2018 2581
full duplex databi-directional data flow in same connectionMSS maximum segment size
connection-orientedhandshaking (exchange of control msgs) initrsquossender receiver state before data exchange
flow controlledsender will not overwhelm receiver
point-to-pointone sender one receiver
reliable in-order byte stream
no ldquomessage boundariesrdquopipelined
TCP congestion and flow control set window size
send amp receive buffers
socketdoor
TCPsend buffer
TCPreceive buffer
socketdoor
segment
applicationwrites data
applicationreads data
Transport Layer 3-53
TCP segment structure
source port dest port
32 bits
applicationdata
(variable length)
sequence numberacknowledgement number
Receive windowUrg data pnterchecksum
FSRPAUheadlen
notused
Options (variable length)
URG urgent data (generally not used)
ACK ACK valid
PSH push data now(generally not used)
RST SYN FINconnection estab(setup teardown
commands)
bytes rcvr willingto accept
Internetchecksum
(as in UDP)
countingby bytes of data(not segments)
Transport Layer 3-54
TCP seq rsquos and ACKsSeq rsquos
byte stream ldquonumberrdquo of first byte in segmentrsquos dataACKs
seq of next byte expected from other sidecumulative ACK
Q how receiver handles out-of-order segmentsA TCP spec doesnrsquot say - up to implementationWidely used implementations of TCP buffer out-of-order segments
Transport Layer 3-55
TCP Round Trip Time and Timeout
Q how to set TCP timeout valuelonger than RTT
but RTT variestoo short premature timeout
unnecessary retransmissions
too long slow reaction to segment loss
Q how to estimate RTTSampleRTT measured time from segment transmission until ACK receipt
ignore retransmissionsSampleRTT will vary want estimated RTT ldquosmootherrdquo
average several recent measurements not just current SampleRTT
Transport Layer 3-56
TCP Round Trip Time and Timeout
EstimatedRTT = (1- α)EstimatedRTT + αSampleRTT
Exponential weighted moving averageinfluence of past sample decreases exponentially fasttypical value α = 0125
Transport Layer 3-57
Example RTT estimationRTT gaiacsumassedu to fantasiaeurecomfr
100
150
200
250
300
350
1 8 15 22 29 36 43 50 57 64 71 78 85 92 99 106
time (seconnds)
RTT
(mill
iseco
nds)
SampleRTT Estimated RTT
Transport Layer 3-58
TCP Round Trip Time and TimeoutSetting the timeout
EstimatedRTT plus ldquosafety marginrdquolarge variation in EstimatedRTT -gt larger safety margin
first estimate of how much SampleRTT deviates from EstimatedRTT
TimeoutInterval = EstimatedRTT + 4DevRTT
DevRTT = (1-β)DevRTT +β|SampleRTT-EstimatedRTT|
(typically β = 025)
Then set timeout interval
Transport Layer 3-59
TCP reliable data transfer
TCP creates rdtservice on top of IPrsquos unreliable servicePipelined segmentsCumulative acksTCP uses single retransmission timer however it just retransmits the first segment in the window
Retransmissions are triggered by
timeout eventsduplicate acks
Initially consider simplified TCP sender
ignore duplicate acksignore flow control congestion control
Transport Layer 3-60
TCP sender eventsdata rcvd from app
Create segment with seq seq is byte-stream number of first data byte in segmentstart timer if not already running (think of timer as for oldest unacked segment)expiration interval TimeOutInterval
timeoutretransmit segment that caused timeout (first segment in the window)restart timer
Ack rcvdIf acknowledges previously unacked segments
update what is known to be ackedstart timer if there are outstanding segments
Transport Layer 3-61
TCP sender(simplified)
NextSeqNum = InitialSeqNumSendBase = InitialSeqNum
loop (forever) switch(event)
event data received from application above create TCP segment with sequence number NextSeqNumif (timer currently not running)
start timerpass segment to IP NextSeqNum = NextSeqNum + length(data)
event timer timeoutretransmit not-yet-acknowledged segment with
smallest sequence numberstart timer
event ACK received with ACK field value of y if (y gt SendBase)
SendBase = yif (there are currently not-yet-acknowledged segments)
start timer
end of loop forever
Commentbull SendBase-1 last cumulatively ackrsquoed byteExamplebull SendBase-1 = 71y= 73 so the rcvrwants 73+ y gt SendBase sothat new data is acked
Transport Layer 3-62
TCP retransmission scenariosHost A
Seq=100 20 bytes data
ACK=100
timepremature timeout
Host B
Seq=92 8 bytes data
ACK=120
Seq=92 8 bytes data
Seq=
92 t
imeo
ut
ACK=120
Host A
Seq=92 8 bytes data
ACK=100
loss
tim
eout
lost ACK scenario
Host B
X
Seq=92 8 bytes data
ACK=100
time
Seq=
92 t
imeo
utSendBase
= 100
SendBase= 120
SendBase= 120
Sendbase= 100
Transport Layer 3-63
TCP retransmission scenarios (more)Host A
Seq=92 8 bytes data
ACK=100
loss
tim
eout
Cumulative ACK scenario
Host B
X
Seq=100 20 bytes data
ACK=120
time
SendBase= 120
Transport Layer 3-64
TCP ACK generation [RFC 1122 RFC 2581]
Event at Receiver
Arrival of in-order segment withexpected seq All data up toexpected seq already ACKed
Arrival of in-order segment withexpected seq One other segment has ACK pending
Arrival of out-of-order segmenthigher-than-expect seq Gap detected
Arrival of segment that partially or completely fills gap
TCP Receiver action
Delayed ACK Wait up to 500msfor next segment If no next segmentsend ACK
Immediately send single cumulative ACK ACKing both in-order segments
Immediately send duplicate ACK indicating seq of next expected byte
Immediate send ACK provided thatsegment startsat lower end of gap
Transport Layer 3-65
Fast Retransmit
Time-out period often relatively long
long delay before resending lost packet
Detect lost segments via duplicate ACKs
Sender often sends many segments back-to-backIf segment is lost there will likely be many duplicate ACKs
If sender receives 3 ACKs for the same data it supposes that segment after ACKeddata was lost
fast retransmit resend segment before timer expires
Transport Layer 3-66
Fast RetransmitResend a segment after 3 duplicate ACKs since a duplicate ACK means that an out-of sequence segment was receivedduplicate ACKs due to packet reorderingif window is small donrsquot get duplicate ACKs
Host A
tim
eout
Host B
time
X
resend seq X2
seq x1seq x2seq x3seq x4seq x5
ACK x1
ACK x1ACK x1ACK x1
tripleduplicate
ACKs
Transport Layer 3-67
event ACK received with ACK field value of y if (y gt SendBase)
SendBase = yif (there are currently not-yet-acknowledged segments)
start timer
else increment count of dup ACKs received for yif (count of dup ACKs received for y = 3)
resend segment with sequence number y
Fast retransmit algorithm
a duplicate ACK for already ACKed segment
fast retransmit
Transport Layer 3-68
TCP Flow Control
receive side of TCP connection has a receive buffer
speed-matching service matching the send rate to the receiving apprsquos drain rate
app process may be slow at reading from buffer
sender wonrsquot overflowreceiverrsquos buffer by
transmitting too muchtoo fast
flow control
Transport Layer 3-69
TCP Flow control how it works
(Suppose TCP receiver discards out-of-order segments)spare room in buffer
= RcvWin
= RcvBuffer-[LastByteRcvd -LastByteRead]
Rcvr advertises spare room by including value of RcvWin in segmentsSender limits unACKeddata to RcvWin
guarantees receive buffer doesnrsquot overflow
Transport Layer 3-70
Sliding Window Flow Control Example
3K
2K SeqNo=0
ReceiverBuffer
0 4KSendersends 2Kof data
2K
AckNo=2048 RcvWin=2048Sendersends 2Kof data 2K SeqNo=2048
4K
AckNo=4096 RcvWin=0
AckNo=4096 RcvWin=1024
Sender blocked
Transport Layer 3-71
Principles of Congestion Control
Congestioninformally ldquotoo many sources sending too much data too fast for network to handlerdquodifferent from flow controlmanifestations
lost packets (buffer overflow at routers)long delays (queueing in router buffers)
a top-10 problem
Transport Layer 3-72
Causescosts of congestion scenario 1
two senders two receiversone router infinite buffers no retransmission
large delays when congestedmaximum achievable throughput
unlimited shared output link buffers
Host Aλin original data
Host B
λout
Transport Layer 3-73
Causescosts of congestion scenario 2
one router finite buffers sender retransmission of lost packet
finite shared output link buffers
Host A λin original data
Host B
λout
λin original data plus retransmitted data
Transport Layer 3-74
Causescosts of congestion scenario 2always (goodput)ldquoperfectrdquo retransmission only when loss
retransmission of delayed (not lost) packet makes larger(than perfect case) for same
λin
λout=
λin
λoutgtλ
inλout
ldquocostsrdquo of congestionmore work (retrans) for given ldquogoodputrdquounneeded retransmissions link carries multiple copies of pkt
R2
R2λin
λ out
b
R2
R2λin
λ out
a
R2
R2λin
λ out
c
R4
R3
Transport Layer 3-75
Causescosts of congestion scenario 3four sendersmultihop pathstimeoutretransmit
λin
Q what happens as and increase λ
in
finite shared output link buffers
Host Aλin original data
Host B
λout
λin original data plus retransmitted data
Transport Layer 3-76
Causescosts of congestion scenario 3
another ldquocostrdquo of congestionwhen packet dropped any ldquoupstream transmission capacity used for that packet was wasted
Host A
Host B
λou
t
Transport Layer 3-77
Approaches towards congestion control
End-end congestion controlno explicit feedback from networkcongestion inferred from end-system observed loss delayapproach taken by TCP
Network-assisted congestion controlrouters provide feedback to end systems
single bit indicating congestion (SNA DECbit TCPIP ECN ATM)explicit rate sender should send at
Two broad approaches towards congestion control
Transport Layer 3-78
TCP Congestion Control
end-end control (no network assistance)sender limits transmissionLastByteSent-LastByteAcked
le CongWin
CongWin is dynamic function of perceived network congestion
How does sender perceive congestionloss event = timeout or3 duplicate acksTCP sender reduces rate (CongWin) after loss event
two modes of operationSlow Start (SS)Congestion avoidance (CA) or Additive Increase Multiplicative Decrease (AIMD)
Transport Layer 3-79
TCP congestion control bandwidth probing
ldquoprobing for bandwidthrdquo increase transmission rate on receipt of ACK until eventually loss occurs then decrease transmission rate
continue to increase on ACK decrease on loss (since available bandwidth is changing depending on other connections in network)
ACKs being received so increase rate
X
X
XX
X loss so decrease rate
send
ing
rate
time
Q how fast to increasedecreasedetails to follow
TCPrsquosldquosawtoothrdquobehavior
Transport Layer 3-80
TCP Congestion Control details
sender limits rate by limiting number of unACKed bytes ldquoin pipelinerdquo
cwnd differs from rwnd (how why)sender limited by min(cwndrwnd)
roughly
cwnd is dynamic function of perceived network congestion
rate = cwndRTT bytessec
LastByteSent-LastByteAcked le cwnd
cwndbytes
RTT
ACK(s)
Transport Layer 3-81
TCP Congestion Control more details
segment loss event reducing cwndtimeout no response from receiver
cut cwnd to 13 duplicate ACKs at least some segments getting through (recall fast retransmit)
cut cwnd in half less aggressively than on timeout
ACK received increase cwndTwo modes of operation
slowstart phase bull increase exponentially
fast (despite name) at connection start or following timeout
congestion avoidance bull increase linearly
Transport Layer 3-82
TCP Slow Start Phasewhen connection begins cwnd = 1 MSS
example MSS = 500 bytes amp RTT = 200 msecinitial rate = 20 kbps
available bandwidth may be gtgt MSSRTT
desirable to quickly ramp up to respectable rate
increase rate exponentially until first loss event or when threshold reached
double cwnd every RTTdone by incrementing cwnd by 1 for every ACK received
Host A
one segment
RTT
Host B
time
two segments
four segments
Transport Layer 3-83
Slow Start ExampleThe congestion window size grows very rapidly
For every ACK we increase CongWin by 1 irrespective of the number of segments ACKrsquoeddouble CongWinevery RTTinitial rate is slow but ramps up exponentially fast
TCP slows down the increase of CongWinwhen CongWin gt ssthresh
segment 1
ACK for segment 1
cwnd = 1
cwnd = 2 segment 2segment 3
ACK for segments 2
cwnd = 4 segment 4segment 5segment 6
ACK for segments 4
cwnd = 7
ACK for segments 3
ACK for segments 5
ACK for segments 6
cwnd = 3
cwnd = 5
cwnd = 6ACK for segments 7
cwnd = 8
segment 7
Transport Layer 3-84
TCP Congestion Avoidance Phase
when cwnd gt ssthreshgrow cwnd linearly
increase cwnd by 1 MSS per RTT approach possible congestion slower than in slowstartimplementation cwnd= cwnd + MSScwndfor each ACK received
ACKs increase cwndby 1 MSS per RTT additive increaseloss cut cwnd in half (non-timeout-detected loss ) multiplicative decrease
AIMD
AIMD Additive IncreaseMultiplicative Decrease
Transport Layer 3-85
Congestion AvoidanceCongestion avoidance phase is started if CongWin has reached the slow-start threshold value
If CongWin gt= ssthresh then each time an ACK is received increment CongWin as follows
bull CongWin = CongWin + 1CongWin (CongWin in segments)
bull In actual TCP implementation CongWin is in BytesCongWin = CongWin + MSS (MSSCongWin)
So CongWin is increased by one only if all CongWinsegments have been acknowledged
Transport Layer 3-86
Example Slow StartCongestion AvoidanceAssume that
ssthresh = 8
cwnd = 1
cwnd = 2
cwnd = 4
cwnd = 8
cwnd = 9
cwnd = 10
02468
101214
t=0
t=2
t=4
t=6
Roundtrip times
Cw
nd(in
seg
men
ts)
ssthresh
cwnd = 3
cwnd = 5cwnd = 6cwnd = 7
Transport Layer 3-87
Slow Start Congestion AvoidanceA typical plot of CongWin for a TCP connection
(MSS = 1500 bytes) with TCP Tahoe
SS
CA
ssthresh
Transport Layer 3-88
Responses to CongestionTCP assumes there is congestion if it detects a packet lossA TCP sender can detect lost packets via loss events
bull Timeout of a retransmission timerbull Receipt of 3 duplicate ACKs (fast retransmit)
TCP interprets a Timeout as a binary congestion signal When a timeout occurs the sender performs
ssthresh is set to half the current size of the congestion window
ssthresh = CongWin 2CongWin is reset to one
CongWin = 1and slow-start is entered
Transport Layer 3-89
Fast Recovery (differentiation btwn two loss events) After 3 dup ACKs (fast Retransmit)
ssthresh = CongWin2CongWin = CongWin2window then grows linearly
But after timeout eventCongWin = 1 MSS window then grows exponentiallyto the threshold then grows linearly
bull 3 dup ACKs indicates network capable of delivering some segmentsbull timeout before 3 dup ACKs is ldquomore alarmingrdquo
Philosophy
3-90
TCP Congestion ControlInitially
CongWin = 1ssthresh = advertised window size
New Ack receivedif (CongWin lt ssthresh) Slow Start
CongWin = CongWin + 1else Congestion Avoidance
CongWin = CongWin + 1CongWinTimeout
ssthresh = CongWin2CongWin = 1
Fast Retransmissionssthresh = CongWin2CongWin = CongWin2
Slow Start (exponential increase phase) is continued until CongWin reaches half of the level where the loss event occurred last time CongWin is increased slowly after (linear increase in Congestion Avoidance phase)
Transport Layer 3-91
Popular ldquoflavorsrdquo of TCP
ssthresh
ssthresh
TCP Tahoe
TCP Reno
Transmission round
cwnd
win
dow
siz
e (in
seg
men
ts)
Transport Layer 3-92
Summary TCP Congestion ControlWhen CongWin is below Threshold sender in slow-start phase window grows exponentiallyWhen CongWin is above Threshold sender is in congestion-avoidance phase window grows linearlyWhen a triple duplicate ACK occurs Threshold set to CongWin2 and CongWin set to ThresholdWhen timeout occurs Threshold set to CongWin2 and CongWin is set to 1 MSS The actual sender window size is determined based on the congestion and flow control algorithms
SenderWin=min(RcvWinCongWin)
Transport Layer 3-93
TCP Congestion Control SummaryEvent State TCP Sender Action Commentary
ACK receipt for previously unackeddata
Slow Start (SS)
CongWin = CongWin + MSS If (CongWin gt Threshold)
set state to ldquoCongestion Avoidancerdquo
Resulting in a doubling of CongWin every RTT
ACK receipt for previously unackeddata
CongestionAvoidance (CA)
CongWin = CongWin+MSS (MSSCongWin)
Additive increase resulting in increase of CongWin by 1 MSS every RTT
Loss event detected by triple duplicate ACK
SS or CA Threshold = CongWin2 CongWin = ThresholdSet state to ldquoCongestion Avoidancerdquo
Fast recovery implementing multiplicative decrease CongWin will not drop below 1 MSS
Timeout SS or CA Threshold = CongWin2 CongWin = 1 MSSSet state to ldquoSlow Startrdquo
Enter slow start
Duplicate ACK
SS or CA Increment duplicate ACK count for segment being acked
CongWin and Threshold not changed
Transport Layer 3-94
TCP throughput
Q whatrsquos average throughout of TCP as function of window size RTT
ignoring slow startlet W be window size when loss occurs
when window is W throughput is WRTTjust after loss window drops to W2 throughput to W2RTT average throughout 75 WRTT
Transport Layer 3-95
TCP Futures TCP over ldquolong fat pipesrdquo
example 1500 byte segments 100ms RTT want 10 Gbps throughputrequires window size W = 83333 in-flight segmentsthroughput in terms of loss rate
L = 210-10 Wownew versions of TCP for high-speed
LRTTMSSsdot221
Transport Layer 3-96
Fairness goal if K TCP sessions share same bottleneck link of bandwidth R each should have average rate of RK
TCP connection 1
bottleneckrouter
capacity R
TCP connection 2
TCP Fairness
Transport Layer 3-97
Why is TCP fairTwo competing sessions
Additive increase gives slope of 1 as throughout increasesmultiplicative decrease decreases throughput proportionally
R
R
equal bandwidth share
Connection 1 throughput
Conn
ecti
on 2
thr
ough
p ut
congestion avoidance additive increaseloss decrease window by factor of 2
congestion avoidance additive increaseloss decrease window by factor of 2
Transport Layer 3-98
Fairness (more)Fairness and UDP
Multimedia apps often do not use TCP
do not want rate throttled by congestion control
Instead use UDPpump audiovideo at constant rate tolerate packet loss
Research area TCP friendly
Fairness and parallel TCP connectionsnothing prevents app from opening parallel cnctionsbetween 2 hostsWeb browsers do this Example link of rate R supporting 9 cnctions
new app asks for 1 TCP gets rate R10new app asks for 11 TCPs gets R2
Transport Layer 3-99
TCP Connection ManagementRecall TCP sender receiver
establish ldquoconnectionrdquobefore exchanging data segmentsinitialize TCP variables
seq sbuffers flow control info (eg RcvWindow)
client connection initiatorSocket clientSocket = new Socket(hostnameport
number)
server contacted by clientSocket connectionSocket = welcomeSocketaccept()
Three way handshakeStep 1 client host sends TCP
SYN segment to serverspecifies initial seq no data
Step 2 server host receives SYN replies with SYNACK segment
server allocates buffersspecifies server initial seq
Step 3 client receives SYNACK replies with ACK segment which may contain data
Transport Layer 3-100
TCP Connection Management (cont)
Closing a connection
client closes socketclientSocketclose()
Step 1 client end system sends TCP FIN control segment to server
Step 2 server receives FIN replies with ACK Closes connection sends FIN
client
FIN
server
ACK
ACK
FIN
close
close
closed
tim
ed w
ait
Transport Layer 3-101
TCP Connection Management (cont)
Step 3 client receives FIN replies with ACK
Enters ldquotimed waitrdquo -will respond with ACK to received FINs
Step 4 server receives ACK Connection closed
client
FIN
server
ACK
ACK
FIN
closing
closing
closed
tim
ed w
ait
closed
Transport Layer 3-102
TCP Connection Management (cont)
TCP clientlifecycle
TCP serverlifecycle
Transport Layer 3-103
Tuning TCPIP Parameters TCPIP parameters
A set of default values may not be optimal for all applicationsThe network administrator may wish to turn on or off some TCPIP functions for performance or security considerations
Many Unix and Linux systems provide some flexibility in tuning the TCPIP kernelsbinsysctl is used to configure the Linux kernel parameters at runtime
Default kernel configuration file is sbinsysctlconfFrequently used sysctl options
bull sysctl ndasha or sysctl ndashA list all current valuesbull sysctl ndashp file_name load the sysctl setting from a configuration
filebull sysctl ndashw variable=value change the value of the parameter
Transport Layer 3-104
SomeTCP Parameters in Linux Kerneltcp_syn_retries
Number of SYN packets the kernel will send before giving up on the new connection
tcp_synack_retriesnumber of SYN+ACK packets sent before the kernel gives up on the connection
tcp_window_scalingMaximum window size of 65535 bytes not enough for for really fast networks The window scaling options allows for almost gigabyte windows which is good for connections with large delay-bandwidth product
tcp_max_syn_backlogMaximal number of remembered connection requests which still did not receive an acknowledgment from connecting client
tcp_fin_timeoutHow many seconds to wait for a final FIN packet before the socket is closed required to prevent denial-of-service (DoS) attacks Default value is 60 seconds
Transport Layer 3-105
SomeTCP Parameters in Linux Kerneltcp_rmem
This is a vector of 3 integers [min default max] These parameters are used by TCP to dynamically adjust receive buffer sizesmin - minimum size of the receive buffer used by each TCP socket The default value is 4K default - the default size of the receive buffer for a TCP socket The default value is 87380 bytes and is lowered to 43689 in low memory systems If larger receive buffer sizes are desired this value should be increased max - the maximum size of the receive buffer used by each TCP socket The default value of 873802 bytes is lowered to 87380 in low memory systems
tcp_smemSend buffer parameters [min default max] similar to tcp_rmem
- Chapter 3 Transport Layer
- Transport services and protocols
- Transport vs network layer
- Internet transport-layer protocols
- Multiplexingdemultiplexing
- How demultiplexing works
- Connectionless demultiplexing
- Connection-oriented demux
- Connection-oriented demux (cont)
- Connection-oriented demux Threaded Web Server
- UDP User Datagram Protocol [RFC 768]
- UDP more
- UDP checksum
- Principles of Reliable data transfer
- Reliable data transfer getting started
- Reliable data transfer getting started
- Rdt10 reliable transfer over a reliable channel
- Rdt20 channel with bit errors
- rdt20 FSM specification
- rdt20 operation with no errors
- rdt20 error scenario
- rdt20 has a fatal flaw
- rdt21 sender handles garbled ACKNAKs
- rdt21 receiver handles garbled ACKNAKs
- rdt21 discussion
- rdt22 a NAK-free protocol
- rdt22 sender receiver fragments
- rdt30 channels with errors and loss
- rdt30 sender
- rdt30 in action
- rdt30 in action
- Performance of rdt30
- rdt30 stop-and-wait operation
- Pipelined protocols
- Pipelining increased utilization
- Go-Back-N
- GBN sender extended FSM
- GBN receiver extended FSM
- GBN inaction
- Selective Repeat
- Selective repeat sender receiver windows
- Selective repeat
- Selective repeat in action
- Selective repeat dilemma
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- TCP Overview RFCs 793 1122 1323 2018 2581
- TCP segment structure
- TCP seq rsquos and ACKs
- TCP Round Trip Time and Timeout
- TCP Round Trip Time and Timeout
- Example RTT estimation
- TCP Round Trip Time and Timeout
- TCP reliable data transfer
- TCP sender events
- TCP sender(simplified)
- TCP retransmission scenarios
- TCP retransmission scenarios (more)
- TCP ACK generation [RFC 1122 RFC 2581]
- Fast Retransmit
- Fast Retransmit
- Fast retransmit algorithm
- TCP Flow Control
- TCP Flow control how it works
- Sliding Window Flow Control Example
- Principles of Congestion Control
- Causescosts of congestion scenario 1
- Causescosts of congestion scenario 2
- Causescosts of congestion scenario 2
- Causescosts of congestion scenario 3
- Causescosts of congestion scenario 3
- Approaches towards congestion control
- TCP Congestion Control
- TCP congestion control bandwidth probing
- TCP Congestion Control details
- TCP Congestion Control more details
- TCP Slow Start Phase
- Slow Start Example
- TCP Congestion Avoidance Phase
- Congestion Avoidance
- Example Slow StartCongestion Avoidance
- Slow Start Congestion Avoidance
- Responses to Congestion
- Fast Recovery (differentiation btwn two loss events)
- TCP Congestion Control
- Popular ldquoflavorsrdquo of TCP
- Summary TCP Congestion Control
- TCP Congestion Control Summary
- TCP throughput
- TCP Futures TCP over ldquolong fat pipesrdquo
- TCP Fairness
- Why is TCP fair
- Fairness (more)
- TCP Connection Management
- TCP Connection Management (cont)
- TCP Connection Management (cont)
- TCP Connection Management (cont)
- Tuning TCPIP Parameters
- SomeTCP Parameters in Linux Kernel
- SomeTCP Parameters in Linux Kernel
-
Transport Layer 3-6
How demultiplexing workshost receives IP datagrams
each datagram has source IP address destination IP addresseach datagram carries 1 transport-layer segmenteach segment has source destination port number (recall well-known port numbers for specific applications)
host uses IP addresses amp port numbers to direct segment to appropriate socket
source port dest port
32 bits
applicationdata
(message)
other header fields
TCPUDP segment format
Transport Layer 3-7
Connectionless demultiplexing
Create sockets with port numbers
DatagramSocket mySocket1 = new DatagramSocket(9111)
DatagramSocket mySocket2 = new DatagramSocket(9222)
UDP socket identified by two-tuple
(dest IP address dest port number)
When host receives UDP segment
checks destination port number in segmentdirects UDP segment to socket with that port number
IP datagrams with different source IP addresses andor source port numbers directed to same socket
Transport Layer 3-8
Connection-oriented demux
TCP socket identified by 4-tuple
source IP addresssource port numberdest IP addressdest port number
recv host uses all four values to direct segment to appropriate socket
Server host may support many simultaneous TCP sockets
each socket identified by its own 4-tuple
Web servers have different sockets for each connecting client
non-persistent HTTP will have different socket for each request
Transport Layer 3-9
Connection-oriented demux(cont)
ClientIPB
P1
clientIP A
P1P2P4
serverIP C
SP 9157DP 80
SP 9157DP 80
P5 P6 P3
D-IPCS-IP AD-IPC
S-IP B
SP 5775DP 80
D-IPCS-IP B
Transport Layer 3-10
Connection-oriented demuxThreaded Web Server
ClientIPB
P1
clientIP A
P1P2P4
serverIP C
SP 9157DP 80
SP 9157DP 80
P5 P6 P3
D-IPCS-IP AD-IPC
S-IP B
SP 5775DP 80
D-IPCS-IP B
P4
Transport Layer 3-11
UDP User Datagram Protocol [RFC 768]
ldquono frillsrdquo ldquobare bonesrdquoInternet transport protocolldquobest effortrdquo service UDP segments may be
lostdelivered out of order to app
connectionlessno handshaking between UDP sender receivereach UDP segment handled independently of others
Why is there a UDPno connection establishment (which can add delay)simple no connection state at sender receiversmall segment headerno congestion control UDP can blast away as fast as desired
Transport Layer 3-12
UDP moreoften used for streaming multimedia apps
loss tolerantrate sensitive
other UDP usesDNSSNMP
reliable transfer over UDP add reliability at application layer
application-specific error recovery
source port dest port
32 bits
Applicationdata
(message)
UDP segment format
length checksumLength in
bytes of UDPsegmentincluding
header
Transport Layer 3-13
UDP checksum
Sendertreat segment contents as sequence of 16-bit integerschecksum addition (1rsquos complement sum) of segment contents with wraparound of carry out bitsender puts checksum value into UDP checksum field
Receivercompute checksum of received segmentcheck if computed checksum equals checksum field value
NO - error detectedYES - no error detected
Goal detect ldquoerrorsrdquo (eg flipped bits) in transmitted segment
Transport Layer 3-14
Principles of Reliable data transferimportant in app transport link layerstop-10 list of important networking topics
characteristics of unreliable channel will determine complexity of reliable data transfer protocol (rdt)
netw
ork
laye
r
Transport Layer 3-15
Reliable data transfer getting started
sendside
receiveside
rdt_send() called from above (eg by app) Passed data to
deliver to receiver upper layer
udt_send() called by rdtto transfer packet over
unreliable channel to receiver
rdt_rcv() called when packet arrives on rcv-side of channel
deliver_data() called by rdt to deliver data to upper
Transport Layer 3-16
Reliable data transfer getting startedWersquoll
incrementally develop sender receiver sides of reliable data transfer protocol (rdt)consider only unidirectional data transfer
but control info will flow on both directionsuse finite state machines (FSM) to specify sender receiver
state1
state2
event causing state transitionactions taken on state transition
state when in this ldquostaterdquo next state
uniquely determined by next event
eventactions
Transport Layer 3-17
Rdt10 reliable transfer over a reliable channel
underlying channel perfectly reliableno bit errorsno loss of packets
separate FSMs for sender receiversender sends data into underlying channelreceiver read data from underlying channel
Wait for call from above packet = make_pkt(data)
udt_send(packet)
rdt_send(data)extract (packetdata)deliver_data(data)
Wait for call from
below
rdt_rcv(packet)
sender receiver
Transport Layer 3-18
Rdt20 channel with bit errors
underlying channel may flip bits in packetrecall checksum to detect bit errors
the question how to recover from errorsacknowledgements (ACKs) receiver explicitly tells sender that pkt received OKnegative acknowledgements (NAKs) receiver explicitly tells sender that pkt had errorssender retransmits pkt on receipt of NAK
new mechanisms in rdt20 (beyond rdt10)error detectionreceiver feedback control msgs (ACKNAK) rcvr-gtsender
Transport Layer 3-19
rdt20 FSM specification
Wait for call from above
snkpkt = make_pkt(data checksum)udt_send(sndpkt)
extract(rcvpktdata)deliver_data(data)udt_send(ACK)
rdt_rcv(rcvpkt) ampamp notcorrupt(rcvpkt)
rdt_rcv(rcvpkt) ampamp isACK(rcvpkt)
udt_send(sndpkt)
rdt_rcv(rcvpkt) ampampisNAK(rcvpkt)
udt_send(NAK)
rdt_rcv(rcvpkt) ampamp corrupt(rcvpkt)
Wait for ACK or
NAK
Wait for call from
belowsender
receiverrdt_send(data)
Λ
Transport Layer 3-20
rdt20 operation with no errors
Wait for call from above
snkpkt = make_pkt(data checksum)udt_send(sndpkt)
extract(rcvpktdata)deliver_data(data)udt_send(ACK)
rdt_rcv(rcvpkt) ampamp notcorrupt(rcvpkt)
rdt_rcv(rcvpkt) ampamp isACK(rcvpkt)
udt_send(sndpkt)
rdt_rcv(rcvpkt) ampampisNAK(rcvpkt)
udt_send(NAK)
rdt_rcv(rcvpkt) ampamp corrupt(rcvpkt)
Wait for ACK or
NAK
Wait for call from
below
rdt_send(data)
Λ
Transport Layer 3-21
rdt20 error scenario
Wait for call from above
snkpkt = make_pkt(data checksum)udt_send(sndpkt)
extract(rcvpktdata)deliver_data(data)udt_send(ACK)
rdt_rcv(rcvpkt) ampamp notcorrupt(rcvpkt)
rdt_rcv(rcvpkt) ampamp isACK(rcvpkt)
udt_send(sndpkt)
rdt_rcv(rcvpkt) ampampisNAK(rcvpkt)
udt_send(NAK)
rdt_rcv(rcvpkt) ampamp corrupt(rcvpkt)
Wait for ACK or
NAK
Wait for call from
below
rdt_send(data)
Λ
Transport Layer 3-22
rdt20 has a fatal flaw
What happens if ACKNAK corruptedsender doesnrsquot know what happened at receivercanrsquot just retransmit possible duplicate
What to dosender ACKsNAKs receiverrsquos ACKNAK What if sender ACKNAK lostretransmit but this might cause retransmission of correctly received pkt
Handling duplicates sender adds sequence number to each pktsender retransmits current pkt if ACKNAK garbledreceiver discards (doesnrsquot deliver up) duplicate pkt
Sender sends one packet then waits for receiver response
stop and wait
Transport Layer 3-23
rdt21 sender handles garbled ACKNAKs
Wait for call 0 from
above
sndpkt = make_pkt(0 data checksum)udt_send(sndpkt)
rdt_send(data)
Wait for ACK or NAK 0 udt_send(sndpkt)
rdt_rcv(rcvpkt) ampamp ( corrupt(rcvpkt) ||isNAK(rcvpkt) )
sndpkt = make_pkt(1 data checksum)udt_send(sndpkt)
rdt_send(data)
rdt_rcv(rcvpkt) ampamp notcorrupt(rcvpkt) ampamp isACK(rcvpkt)
udt_send(sndpkt)
rdt_rcv(rcvpkt) ampamp ( corrupt(rcvpkt) ||isNAK(rcvpkt) )
rdt_rcv(rcvpkt) ampamp notcorrupt(rcvpkt) ampamp isACK(rcvpkt)
Wait forcall 1 from
above
Wait for ACK or NAK 1
ΛΛ
Transport Layer 3-24
rdt21 receiver handles garbled ACKNAKs
Wait for 0 from below
sndpkt = make_pkt(NAK chksum)udt_send(sndpkt)
rdt_rcv(rcvpkt) ampamp not corrupt(rcvpkt) ampamphas_seq0(rcvpkt)
rdt_rcv(rcvpkt) ampamp notcorrupt(rcvpkt) ampamp has_seq1(rcvpkt)
extract(rcvpktdata)deliver_data(data)sndpkt = make_pkt(ACK chksum)udt_send(sndpkt)
Wait for 1 from below
rdt_rcv(rcvpkt) ampamp notcorrupt(rcvpkt) ampamp has_seq0(rcvpkt)
extract(rcvpktdata)deliver_data(data)sndpkt = make_pkt(ACK chksum)udt_send(sndpkt)
rdt_rcv(rcvpkt) ampamp (corrupt(rcvpkt)
sndpkt = make_pkt(ACK chksum)udt_send(sndpkt)
rdt_rcv(rcvpkt) ampamp not corrupt(rcvpkt) ampamphas_seq1(rcvpkt)
rdt_rcv(rcvpkt) ampamp (corrupt(rcvpkt)
sndpkt = make_pkt(ACK chksum)udt_send(sndpkt)
sndpkt = make_pkt(NAK chksum)udt_send(sndpkt)
Transport Layer 3-25
rdt21 discussion
Senderseq added to pkttwo seq rsquos (01) will suffice Whymust check if received ACKNAK corrupted twice as many states
state must ldquorememberrdquowhether ldquocurrentrdquo pkt has 0 or 1 seq
Receivermust check if received packet is duplicate
state indicates whether 0 or 1 is expected pkt seq
note receiver can notknow if its last ACKNAK received OK at sender
Transport Layer 3-26
rdt22 a NAK-free protocol
same functionality as rdt21 using ACKs onlyinstead of NAK receiver sends ACK for last pkt received OK
receiver must explicitly include seq of pkt being ACKed duplicate ACK at sender results in same action as NAK retransmit current pkt
Transport Layer 3-27
rdt22 sender receiver fragments
Wait for call 0 from
above
sndpkt = make_pkt(0 data checksum)udt_send(sndpkt)
rdt_send(data)
udt_send(sndpkt)
rdt_rcv(rcvpkt) ampamp ( corrupt(rcvpkt) ||
isACK(rcvpkt1) )
rdt_rcv(rcvpkt) ampamp notcorrupt(rcvpkt) ampamp isACK(rcvpkt0)
Wait for ACK
0sender FSM
fragment
Wait for 0 from below
rdt_rcv(rcvpkt) ampamp notcorrupt(rcvpkt) ampamp has_seq1(rcvpkt)
extract(rcvpktdata)deliver_data(data)sndpkt = make_pkt(ACK1 chksum)udt_send(sndpkt)
rdt_rcv(rcvpkt) ampamp (corrupt(rcvpkt) ||
has_seq1(rcvpkt))
udt_send(sndpkt)receiver FSM
fragment
Λ
Transport Layer 3-28
rdt30 channels with errors and loss
New assumptionunderlying channel can also lose packets (data or ACKs)
checksum seq ACKs retransmissions will be of help but not enough
Q how to deal with losssender waits until certain data or ACK lost then retransmitsdrawbacks
Approach sender waits ldquoreasonablerdquo amount of time for ACK retransmits if no ACK received in this timeif pkt (or ACK) just delayed (not lost)
retransmission will be duplicate but use of seq rsquos already handles thisreceiver must specify seq of pkt being ACKed
requires countdown timer
Transport Layer 3-29
rdt30 sendersndpkt = make_pkt(0 data checksum)udt_send(sndpkt)start_timer
rdt_send(data)
Wait for
ACK0
rdt_rcv(rcvpkt) ampamp ( corrupt(rcvpkt) ||isACK(rcvpkt1) )
Wait for call 1 from
above
sndpkt = make_pkt(1 data checksum)udt_send(sndpkt)start_timer
rdt_send(data)
rdt_rcv(rcvpkt) ampamp notcorrupt(rcvpkt) ampamp isACK(rcvpkt0)
rdt_rcv(rcvpkt) ampamp ( corrupt(rcvpkt) ||isACK(rcvpkt0) )
rdt_rcv(rcvpkt) ampamp notcorrupt(rcvpkt) ampamp isACK(rcvpkt1)
stop_timerstop_timer
udt_send(sndpkt)start_timer
timeout
udt_send(sndpkt)start_timer
timeout
rdt_rcv(rcvpkt)
Wait for call 0from
above
Wait for
ACK1
Λrdt_rcv(rcvpkt)
ΛΛ
Λ
Transport Layer 3-30
rdt30 in action
Transport Layer 3-31
rdt30 in action
Transport Layer 3-32
Performance of rdt30
rdt30 works but performance stinksexample 1 Gbps link 15 ms e-e prop delay 1KB packet
Ttransmit = 8kbpkt109 bsec = 8 microsec
U sender utilization ndash fraction of time sender busy sending1KB pkt every 30 msec -gt 33kBsec thruput over 1 Gbps linknetwork protocol limits use of physical resources
U sender=
008 30008
= 000027 L RRTT + L R
=
L (packet length in bits)R (transmission rate bps) =
Transport Layer 3-33
rdt30 stop-and-wait operation
first packet bit transmitted t = 0
sender receiver
RTT
last packet bit transmitted t = L R
first packet bit arriveslast packet bit arrives send ACK
ACK arrives send next packet t = RTT + L R
U sender=
00830008
= 000027 L RRTT + L R
=
Transport Layer 3-34
Pipelined protocolsPipelining sender allows multiple ldquoin-flightrdquo yet-to-
be-acknowledged pktsrange of sequence numbers must be increasedbuffering at sender andor receiver
Two generic forms of pipelined protocols go-Back-N selective repeat
Transport Layer 3-35
Pipelining increased utilization
first packet bit transmitted t = 0
sender receiver
RTT
last bit transmitted t = L R
first packet bit arriveslast packet bit arrives send ACK
ACK arrives send next packet t = RTT + L R
last bit of 2nd packet arrives send ACKlast bit of 3rd packet arrives send ACK
U sender=
024 30008
= 000083 L RRTT + L R
=
Increase utilizationby a factor of 3
Transport Layer 3-36
Utilization=N(LR)(RTT+LR) if NLRltRTT+LR Utilization=1 if and the sender pauses after it transmits a window NLRgtRTT+LR and the of packets until it receives first ACK sender does not pause
Transport Layer 3-37
Go-Back-NSender
k-bit seq in pkt headerldquowindowrdquo of up to N consecutive unackrsquoed pkts allowed
ACK(n) ACKs all pkts up to including seq n - ldquocumulative ACKrdquomay receive duplicate ACKs (see receiver)
timer for the entire windowtimeout(n) retransmit pkt n and all higher seq pkts in window
Transport Layer 3-38
GBN sender extended FSM
Wait start_timerudt_send(sndpkt[base])udt_send(sndpkt[base+1])hellipudt_send(sndpkt[nextseqnum-1])
timeout
rdt_send(data)
if (nextseqnum lt base+N) sndpkt[nextseqnum] = make_pkt(nextseqnumdatachksum)udt_send(sndpkt[nextseqnum])if (base == nextseqnum)
start_timernextseqnum++
elserefuse_data(data)
base = getacknum(rcvpkt)+1If (base == nextseqnum)
stop_timerelse
start_timer
rdt_rcv(rcvpkt) ampamp notcorrupt(rcvpkt)
base=1nextseqnum=1
rdt_rcv(rcvpkt) ampamp corrupt(rcvpkt)
Λ
Λ
Transport Layer 3-39
GBN receiver extended FSM
ACK-only always send ACK for correctly-received pktwith highest in-order seq
may generate duplicate ACKsneed only remember expectedseqnum
out-of-order pkt discard (donrsquot buffer) -gt no receiver bufferingRe-ACK pkt with highest in-order seq
Wait
udt_send(sndpkt)default
rdt_rcv(rcvpkt)ampamp notcurrupt(rcvpkt)ampamp hasseqnum(rcvpktexpectedseqnum)
extract(rcvpktdata)deliver_data(data)sndpkt = make_pkt(expectedseqnumACKchksum)udt_send(sndpkt)expectedseqnum++
expectedseqnum=1sndpkt =
make_pkt(0ACKchksum)
Λ
Transport Layer 3-40
GBN inaction
Transport Layer 3-41
Selective Repeat
receiver individually acknowledges all correctly received pkts
buffers pkts as needed for eventual in-order delivery to upper layer
sender only resends pkts for which ACK not received
sender timer for each unACKed pktsender window
N consecutive seq rsquosagain limits seq s of sent unACKed pkts
Transport Layer 3-42
Selective repeat sender receiver windows
Transport Layer 3-43
Selective repeat
data from above if next available seq in window send pkt
timeout(n)resend pkt n restart timer
ACK(n) in [sendbasesendbase+N-1]
mark pkt n as receivedif n smallest unACKed pkt advance window base to next unACKed seq
senderpkt n in [rcvbase rcvbase+N-1]
send ACK(n)out-of-order bufferin-order deliver (also deliver buffered in-order pkts) advance window to next not-yet-received pkt
pkt n in [rcvbase-Nrcvbase-1]
ACK(n)otherwise
ignore
receiver
Transport Layer 3-44
Selective repeat in action
Transport Layer 3-45
Selective repeatdilemma
Example seq rsquos 0 1 2 3window size=3
receiver sees no difference in two scenariosincorrectly passes duplicate data as new in (a)
Q what relationship between seq size and window size
Transport Layer 3-46
Sequence Number vs Window SizeSuppose we use k bits to represent SNQuestion Whatrsquos the minimum number of bits k necessary for a window size of N
sender
receiver
Go-Back-N
expectedSN
snd_base=expectedSN
Q For a given expectedSN whatrsquos the largest possible value for snd_baseA If all the last N ACKs sent by the receiver are received
snd_base = expectedSNexpectedSN+N-1
senderrsquos window
Transport Layer 3-47
Sequence Number vs Window SizeSuppose we use k bits to represent SNQuestion Whatrsquos the minimum number of bits k necessary for a window size of N
sender
receiver
Go-Back-N
expectedSN
snd_base=expectedSN-N
Q For a given expectedSN whatrsquos the smallest possible value for snd_baseA If all the last N ACKs sent by the receiver are not received
snd_base = expectedSN-NexpectedSN-1
senderrsquos window
Transport Layer 3-48
Sequence Number vs Window Size
sender
receiver
Go-Back-N
expectedSN
snd_base=expectedSN-N
All SNs in the interval [expectedSN-NexpectedSN+N-1] (an interval of size 2N) can be received by the receiver Since the receiver accepts on the packet with SN=expectedSN there should be no other packet within this interval with SN=expectedSN Therefore
2k ge N+1expectedSN+N-1
Transport Layer 3-49
Sequence Number vs Window SizeSuppose we use k bits to represent SNQuestion Whatrsquos the minimum number of bits k necessary for a window size of N
sender
receiver
Selective Repeat
rcv_base
snd_base=rcv_base
Q For a given rcv_base whatrsquos the largest possible value for snd_baseA If all the last N ACKs sent by the receiver are received
snd_base = rcv_base (same as go_back-N)rcv_base+N-1
senderrsquos window
receiverrsquos window
rcv_base+N-1
Transport Layer 3-50
Sequence Number vs Window SizeSuppose we use k bits to represent SNQuestion Whatrsquos the minimum number of bits k necessary for a window size of N
sender
receiver
Selective Repeat
rcv_base
snd_base=rcv_base-N
Q For a given rcv_base whatrsquos the smallest possible value for snd_baseA If all the last N ACKs sent by the receiver are not received
snd_base = rcv_base-N (same as Go-Back-N)rcv_base-1
senderrsquos window
rcv_base
receiverrsquos window
rcv_base+N-1
Transport Layer 3-51
Sequence Number vs Window Size
sender
receiver
Selective Repeat
snd_base=rcv_base-N
All SNs in the interval [rcv_base-Nrcv_base+N-1] (an interval of size 2N) can be received by the receiver Since the receiver should be able to distinguish between all packets in this interval and take corresponding action there should be no two packets within thisinterval having the same SN Therefore
2k ge 2Nrcv_base+N-1
rcv_basercv_base
receiverrsquos window
rcv_base+N-1
Transport Layer 3-52
TCP Overview RFCs 793 1122 1323 2018 2581
full duplex databi-directional data flow in same connectionMSS maximum segment size
connection-orientedhandshaking (exchange of control msgs) initrsquossender receiver state before data exchange
flow controlledsender will not overwhelm receiver
point-to-pointone sender one receiver
reliable in-order byte stream
no ldquomessage boundariesrdquopipelined
TCP congestion and flow control set window size
send amp receive buffers
socketdoor
TCPsend buffer
TCPreceive buffer
socketdoor
segment
applicationwrites data
applicationreads data
Transport Layer 3-53
TCP segment structure
source port dest port
32 bits
applicationdata
(variable length)
sequence numberacknowledgement number
Receive windowUrg data pnterchecksum
FSRPAUheadlen
notused
Options (variable length)
URG urgent data (generally not used)
ACK ACK valid
PSH push data now(generally not used)
RST SYN FINconnection estab(setup teardown
commands)
bytes rcvr willingto accept
Internetchecksum
(as in UDP)
countingby bytes of data(not segments)
Transport Layer 3-54
TCP seq rsquos and ACKsSeq rsquos
byte stream ldquonumberrdquo of first byte in segmentrsquos dataACKs
seq of next byte expected from other sidecumulative ACK
Q how receiver handles out-of-order segmentsA TCP spec doesnrsquot say - up to implementationWidely used implementations of TCP buffer out-of-order segments
Transport Layer 3-55
TCP Round Trip Time and Timeout
Q how to set TCP timeout valuelonger than RTT
but RTT variestoo short premature timeout
unnecessary retransmissions
too long slow reaction to segment loss
Q how to estimate RTTSampleRTT measured time from segment transmission until ACK receipt
ignore retransmissionsSampleRTT will vary want estimated RTT ldquosmootherrdquo
average several recent measurements not just current SampleRTT
Transport Layer 3-56
TCP Round Trip Time and Timeout
EstimatedRTT = (1- α)EstimatedRTT + αSampleRTT
Exponential weighted moving averageinfluence of past sample decreases exponentially fasttypical value α = 0125
Transport Layer 3-57
Example RTT estimationRTT gaiacsumassedu to fantasiaeurecomfr
100
150
200
250
300
350
1 8 15 22 29 36 43 50 57 64 71 78 85 92 99 106
time (seconnds)
RTT
(mill
iseco
nds)
SampleRTT Estimated RTT
Transport Layer 3-58
TCP Round Trip Time and TimeoutSetting the timeout
EstimatedRTT plus ldquosafety marginrdquolarge variation in EstimatedRTT -gt larger safety margin
first estimate of how much SampleRTT deviates from EstimatedRTT
TimeoutInterval = EstimatedRTT + 4DevRTT
DevRTT = (1-β)DevRTT +β|SampleRTT-EstimatedRTT|
(typically β = 025)
Then set timeout interval
Transport Layer 3-59
TCP reliable data transfer
TCP creates rdtservice on top of IPrsquos unreliable servicePipelined segmentsCumulative acksTCP uses single retransmission timer however it just retransmits the first segment in the window
Retransmissions are triggered by
timeout eventsduplicate acks
Initially consider simplified TCP sender
ignore duplicate acksignore flow control congestion control
Transport Layer 3-60
TCP sender eventsdata rcvd from app
Create segment with seq seq is byte-stream number of first data byte in segmentstart timer if not already running (think of timer as for oldest unacked segment)expiration interval TimeOutInterval
timeoutretransmit segment that caused timeout (first segment in the window)restart timer
Ack rcvdIf acknowledges previously unacked segments
update what is known to be ackedstart timer if there are outstanding segments
Transport Layer 3-61
TCP sender(simplified)
NextSeqNum = InitialSeqNumSendBase = InitialSeqNum
loop (forever) switch(event)
event data received from application above create TCP segment with sequence number NextSeqNumif (timer currently not running)
start timerpass segment to IP NextSeqNum = NextSeqNum + length(data)
event timer timeoutretransmit not-yet-acknowledged segment with
smallest sequence numberstart timer
event ACK received with ACK field value of y if (y gt SendBase)
SendBase = yif (there are currently not-yet-acknowledged segments)
start timer
end of loop forever
Commentbull SendBase-1 last cumulatively ackrsquoed byteExamplebull SendBase-1 = 71y= 73 so the rcvrwants 73+ y gt SendBase sothat new data is acked
Transport Layer 3-62
TCP retransmission scenariosHost A
Seq=100 20 bytes data
ACK=100
timepremature timeout
Host B
Seq=92 8 bytes data
ACK=120
Seq=92 8 bytes data
Seq=
92 t
imeo
ut
ACK=120
Host A
Seq=92 8 bytes data
ACK=100
loss
tim
eout
lost ACK scenario
Host B
X
Seq=92 8 bytes data
ACK=100
time
Seq=
92 t
imeo
utSendBase
= 100
SendBase= 120
SendBase= 120
Sendbase= 100
Transport Layer 3-63
TCP retransmission scenarios (more)Host A
Seq=92 8 bytes data
ACK=100
loss
tim
eout
Cumulative ACK scenario
Host B
X
Seq=100 20 bytes data
ACK=120
time
SendBase= 120
Transport Layer 3-64
TCP ACK generation [RFC 1122 RFC 2581]
Event at Receiver
Arrival of in-order segment withexpected seq All data up toexpected seq already ACKed
Arrival of in-order segment withexpected seq One other segment has ACK pending
Arrival of out-of-order segmenthigher-than-expect seq Gap detected
Arrival of segment that partially or completely fills gap
TCP Receiver action
Delayed ACK Wait up to 500msfor next segment If no next segmentsend ACK
Immediately send single cumulative ACK ACKing both in-order segments
Immediately send duplicate ACK indicating seq of next expected byte
Immediate send ACK provided thatsegment startsat lower end of gap
Transport Layer 3-65
Fast Retransmit
Time-out period often relatively long
long delay before resending lost packet
Detect lost segments via duplicate ACKs
Sender often sends many segments back-to-backIf segment is lost there will likely be many duplicate ACKs
If sender receives 3 ACKs for the same data it supposes that segment after ACKeddata was lost
fast retransmit resend segment before timer expires
Transport Layer 3-66
Fast RetransmitResend a segment after 3 duplicate ACKs since a duplicate ACK means that an out-of sequence segment was receivedduplicate ACKs due to packet reorderingif window is small donrsquot get duplicate ACKs
Host A
tim
eout
Host B
time
X
resend seq X2
seq x1seq x2seq x3seq x4seq x5
ACK x1
ACK x1ACK x1ACK x1
tripleduplicate
ACKs
Transport Layer 3-67
event ACK received with ACK field value of y if (y gt SendBase)
SendBase = yif (there are currently not-yet-acknowledged segments)
start timer
else increment count of dup ACKs received for yif (count of dup ACKs received for y = 3)
resend segment with sequence number y
Fast retransmit algorithm
a duplicate ACK for already ACKed segment
fast retransmit
Transport Layer 3-68
TCP Flow Control
receive side of TCP connection has a receive buffer
speed-matching service matching the send rate to the receiving apprsquos drain rate
app process may be slow at reading from buffer
sender wonrsquot overflowreceiverrsquos buffer by
transmitting too muchtoo fast
flow control
Transport Layer 3-69
TCP Flow control how it works
(Suppose TCP receiver discards out-of-order segments)spare room in buffer
= RcvWin
= RcvBuffer-[LastByteRcvd -LastByteRead]
Rcvr advertises spare room by including value of RcvWin in segmentsSender limits unACKeddata to RcvWin
guarantees receive buffer doesnrsquot overflow
Transport Layer 3-70
Sliding Window Flow Control Example
3K
2K SeqNo=0
ReceiverBuffer
0 4KSendersends 2Kof data
2K
AckNo=2048 RcvWin=2048Sendersends 2Kof data 2K SeqNo=2048
4K
AckNo=4096 RcvWin=0
AckNo=4096 RcvWin=1024
Sender blocked
Transport Layer 3-71
Principles of Congestion Control
Congestioninformally ldquotoo many sources sending too much data too fast for network to handlerdquodifferent from flow controlmanifestations
lost packets (buffer overflow at routers)long delays (queueing in router buffers)
a top-10 problem
Transport Layer 3-72
Causescosts of congestion scenario 1
two senders two receiversone router infinite buffers no retransmission
large delays when congestedmaximum achievable throughput
unlimited shared output link buffers
Host Aλin original data
Host B
λout
Transport Layer 3-73
Causescosts of congestion scenario 2
one router finite buffers sender retransmission of lost packet
finite shared output link buffers
Host A λin original data
Host B
λout
λin original data plus retransmitted data
Transport Layer 3-74
Causescosts of congestion scenario 2always (goodput)ldquoperfectrdquo retransmission only when loss
retransmission of delayed (not lost) packet makes larger(than perfect case) for same
λin
λout=
λin
λoutgtλ
inλout
ldquocostsrdquo of congestionmore work (retrans) for given ldquogoodputrdquounneeded retransmissions link carries multiple copies of pkt
R2
R2λin
λ out
b
R2
R2λin
λ out
a
R2
R2λin
λ out
c
R4
R3
Transport Layer 3-75
Causescosts of congestion scenario 3four sendersmultihop pathstimeoutretransmit
λin
Q what happens as and increase λ
in
finite shared output link buffers
Host Aλin original data
Host B
λout
λin original data plus retransmitted data
Transport Layer 3-76
Causescosts of congestion scenario 3
another ldquocostrdquo of congestionwhen packet dropped any ldquoupstream transmission capacity used for that packet was wasted
Host A
Host B
λou
t
Transport Layer 3-77
Approaches towards congestion control
End-end congestion controlno explicit feedback from networkcongestion inferred from end-system observed loss delayapproach taken by TCP
Network-assisted congestion controlrouters provide feedback to end systems
single bit indicating congestion (SNA DECbit TCPIP ECN ATM)explicit rate sender should send at
Two broad approaches towards congestion control
Transport Layer 3-78
TCP Congestion Control
end-end control (no network assistance)sender limits transmissionLastByteSent-LastByteAcked
le CongWin
CongWin is dynamic function of perceived network congestion
How does sender perceive congestionloss event = timeout or3 duplicate acksTCP sender reduces rate (CongWin) after loss event
two modes of operationSlow Start (SS)Congestion avoidance (CA) or Additive Increase Multiplicative Decrease (AIMD)
Transport Layer 3-79
TCP congestion control bandwidth probing
ldquoprobing for bandwidthrdquo increase transmission rate on receipt of ACK until eventually loss occurs then decrease transmission rate
continue to increase on ACK decrease on loss (since available bandwidth is changing depending on other connections in network)
ACKs being received so increase rate
X
X
XX
X loss so decrease rate
send
ing
rate
time
Q how fast to increasedecreasedetails to follow
TCPrsquosldquosawtoothrdquobehavior
Transport Layer 3-80
TCP Congestion Control details
sender limits rate by limiting number of unACKed bytes ldquoin pipelinerdquo
cwnd differs from rwnd (how why)sender limited by min(cwndrwnd)
roughly
cwnd is dynamic function of perceived network congestion
rate = cwndRTT bytessec
LastByteSent-LastByteAcked le cwnd
cwndbytes
RTT
ACK(s)
Transport Layer 3-81
TCP Congestion Control more details
segment loss event reducing cwndtimeout no response from receiver
cut cwnd to 13 duplicate ACKs at least some segments getting through (recall fast retransmit)
cut cwnd in half less aggressively than on timeout
ACK received increase cwndTwo modes of operation
slowstart phase bull increase exponentially
fast (despite name) at connection start or following timeout
congestion avoidance bull increase linearly
Transport Layer 3-82
TCP Slow Start Phasewhen connection begins cwnd = 1 MSS
example MSS = 500 bytes amp RTT = 200 msecinitial rate = 20 kbps
available bandwidth may be gtgt MSSRTT
desirable to quickly ramp up to respectable rate
increase rate exponentially until first loss event or when threshold reached
double cwnd every RTTdone by incrementing cwnd by 1 for every ACK received
Host A
one segment
RTT
Host B
time
two segments
four segments
Transport Layer 3-83
Slow Start ExampleThe congestion window size grows very rapidly
For every ACK we increase CongWin by 1 irrespective of the number of segments ACKrsquoeddouble CongWinevery RTTinitial rate is slow but ramps up exponentially fast
TCP slows down the increase of CongWinwhen CongWin gt ssthresh
segment 1
ACK for segment 1
cwnd = 1
cwnd = 2 segment 2segment 3
ACK for segments 2
cwnd = 4 segment 4segment 5segment 6
ACK for segments 4
cwnd = 7
ACK for segments 3
ACK for segments 5
ACK for segments 6
cwnd = 3
cwnd = 5
cwnd = 6ACK for segments 7
cwnd = 8
segment 7
Transport Layer 3-84
TCP Congestion Avoidance Phase
when cwnd gt ssthreshgrow cwnd linearly
increase cwnd by 1 MSS per RTT approach possible congestion slower than in slowstartimplementation cwnd= cwnd + MSScwndfor each ACK received
ACKs increase cwndby 1 MSS per RTT additive increaseloss cut cwnd in half (non-timeout-detected loss ) multiplicative decrease
AIMD
AIMD Additive IncreaseMultiplicative Decrease
Transport Layer 3-85
Congestion AvoidanceCongestion avoidance phase is started if CongWin has reached the slow-start threshold value
If CongWin gt= ssthresh then each time an ACK is received increment CongWin as follows
bull CongWin = CongWin + 1CongWin (CongWin in segments)
bull In actual TCP implementation CongWin is in BytesCongWin = CongWin + MSS (MSSCongWin)
So CongWin is increased by one only if all CongWinsegments have been acknowledged
Transport Layer 3-86
Example Slow StartCongestion AvoidanceAssume that
ssthresh = 8
cwnd = 1
cwnd = 2
cwnd = 4
cwnd = 8
cwnd = 9
cwnd = 10
02468
101214
t=0
t=2
t=4
t=6
Roundtrip times
Cw
nd(in
seg
men
ts)
ssthresh
cwnd = 3
cwnd = 5cwnd = 6cwnd = 7
Transport Layer 3-87
Slow Start Congestion AvoidanceA typical plot of CongWin for a TCP connection
(MSS = 1500 bytes) with TCP Tahoe
SS
CA
ssthresh
Transport Layer 3-88
Responses to CongestionTCP assumes there is congestion if it detects a packet lossA TCP sender can detect lost packets via loss events
bull Timeout of a retransmission timerbull Receipt of 3 duplicate ACKs (fast retransmit)
TCP interprets a Timeout as a binary congestion signal When a timeout occurs the sender performs
ssthresh is set to half the current size of the congestion window
ssthresh = CongWin 2CongWin is reset to one
CongWin = 1and slow-start is entered
Transport Layer 3-89
Fast Recovery (differentiation btwn two loss events) After 3 dup ACKs (fast Retransmit)
ssthresh = CongWin2CongWin = CongWin2window then grows linearly
But after timeout eventCongWin = 1 MSS window then grows exponentiallyto the threshold then grows linearly
bull 3 dup ACKs indicates network capable of delivering some segmentsbull timeout before 3 dup ACKs is ldquomore alarmingrdquo
Philosophy
3-90
TCP Congestion ControlInitially
CongWin = 1ssthresh = advertised window size
New Ack receivedif (CongWin lt ssthresh) Slow Start
CongWin = CongWin + 1else Congestion Avoidance
CongWin = CongWin + 1CongWinTimeout
ssthresh = CongWin2CongWin = 1
Fast Retransmissionssthresh = CongWin2CongWin = CongWin2
Slow Start (exponential increase phase) is continued until CongWin reaches half of the level where the loss event occurred last time CongWin is increased slowly after (linear increase in Congestion Avoidance phase)
Transport Layer 3-91
Popular ldquoflavorsrdquo of TCP
ssthresh
ssthresh
TCP Tahoe
TCP Reno
Transmission round
cwnd
win
dow
siz
e (in
seg
men
ts)
Transport Layer 3-92
Summary TCP Congestion ControlWhen CongWin is below Threshold sender in slow-start phase window grows exponentiallyWhen CongWin is above Threshold sender is in congestion-avoidance phase window grows linearlyWhen a triple duplicate ACK occurs Threshold set to CongWin2 and CongWin set to ThresholdWhen timeout occurs Threshold set to CongWin2 and CongWin is set to 1 MSS The actual sender window size is determined based on the congestion and flow control algorithms
SenderWin=min(RcvWinCongWin)
Transport Layer 3-93
TCP Congestion Control SummaryEvent State TCP Sender Action Commentary
ACK receipt for previously unackeddata
Slow Start (SS)
CongWin = CongWin + MSS If (CongWin gt Threshold)
set state to ldquoCongestion Avoidancerdquo
Resulting in a doubling of CongWin every RTT
ACK receipt for previously unackeddata
CongestionAvoidance (CA)
CongWin = CongWin+MSS (MSSCongWin)
Additive increase resulting in increase of CongWin by 1 MSS every RTT
Loss event detected by triple duplicate ACK
SS or CA Threshold = CongWin2 CongWin = ThresholdSet state to ldquoCongestion Avoidancerdquo
Fast recovery implementing multiplicative decrease CongWin will not drop below 1 MSS
Timeout SS or CA Threshold = CongWin2 CongWin = 1 MSSSet state to ldquoSlow Startrdquo
Enter slow start
Duplicate ACK
SS or CA Increment duplicate ACK count for segment being acked
CongWin and Threshold not changed
Transport Layer 3-94
TCP throughput
Q whatrsquos average throughout of TCP as function of window size RTT
ignoring slow startlet W be window size when loss occurs
when window is W throughput is WRTTjust after loss window drops to W2 throughput to W2RTT average throughout 75 WRTT
Transport Layer 3-95
TCP Futures TCP over ldquolong fat pipesrdquo
example 1500 byte segments 100ms RTT want 10 Gbps throughputrequires window size W = 83333 in-flight segmentsthroughput in terms of loss rate
L = 210-10 Wownew versions of TCP for high-speed
LRTTMSSsdot221
Transport Layer 3-96
Fairness goal if K TCP sessions share same bottleneck link of bandwidth R each should have average rate of RK
TCP connection 1
bottleneckrouter
capacity R
TCP connection 2
TCP Fairness
Transport Layer 3-97
Why is TCP fairTwo competing sessions
Additive increase gives slope of 1 as throughout increasesmultiplicative decrease decreases throughput proportionally
R
R
equal bandwidth share
Connection 1 throughput
Conn
ecti
on 2
thr
ough
p ut
congestion avoidance additive increaseloss decrease window by factor of 2
congestion avoidance additive increaseloss decrease window by factor of 2
Transport Layer 3-98
Fairness (more)Fairness and UDP
Multimedia apps often do not use TCP
do not want rate throttled by congestion control
Instead use UDPpump audiovideo at constant rate tolerate packet loss
Research area TCP friendly
Fairness and parallel TCP connectionsnothing prevents app from opening parallel cnctionsbetween 2 hostsWeb browsers do this Example link of rate R supporting 9 cnctions
new app asks for 1 TCP gets rate R10new app asks for 11 TCPs gets R2
Transport Layer 3-99
TCP Connection ManagementRecall TCP sender receiver
establish ldquoconnectionrdquobefore exchanging data segmentsinitialize TCP variables
seq sbuffers flow control info (eg RcvWindow)
client connection initiatorSocket clientSocket = new Socket(hostnameport
number)
server contacted by clientSocket connectionSocket = welcomeSocketaccept()
Three way handshakeStep 1 client host sends TCP
SYN segment to serverspecifies initial seq no data
Step 2 server host receives SYN replies with SYNACK segment
server allocates buffersspecifies server initial seq
Step 3 client receives SYNACK replies with ACK segment which may contain data
Transport Layer 3-100
TCP Connection Management (cont)
Closing a connection
client closes socketclientSocketclose()
Step 1 client end system sends TCP FIN control segment to server
Step 2 server receives FIN replies with ACK Closes connection sends FIN
client
FIN
server
ACK
ACK
FIN
close
close
closed
tim
ed w
ait
Transport Layer 3-101
TCP Connection Management (cont)
Step 3 client receives FIN replies with ACK
Enters ldquotimed waitrdquo -will respond with ACK to received FINs
Step 4 server receives ACK Connection closed
client
FIN
server
ACK
ACK
FIN
closing
closing
closed
tim
ed w
ait
closed
Transport Layer 3-102
TCP Connection Management (cont)
TCP clientlifecycle
TCP serverlifecycle
Transport Layer 3-103
Tuning TCPIP Parameters TCPIP parameters
A set of default values may not be optimal for all applicationsThe network administrator may wish to turn on or off some TCPIP functions for performance or security considerations
Many Unix and Linux systems provide some flexibility in tuning the TCPIP kernelsbinsysctl is used to configure the Linux kernel parameters at runtime
Default kernel configuration file is sbinsysctlconfFrequently used sysctl options
bull sysctl ndasha or sysctl ndashA list all current valuesbull sysctl ndashp file_name load the sysctl setting from a configuration
filebull sysctl ndashw variable=value change the value of the parameter
Transport Layer 3-104
SomeTCP Parameters in Linux Kerneltcp_syn_retries
Number of SYN packets the kernel will send before giving up on the new connection
tcp_synack_retriesnumber of SYN+ACK packets sent before the kernel gives up on the connection
tcp_window_scalingMaximum window size of 65535 bytes not enough for for really fast networks The window scaling options allows for almost gigabyte windows which is good for connections with large delay-bandwidth product
tcp_max_syn_backlogMaximal number of remembered connection requests which still did not receive an acknowledgment from connecting client
tcp_fin_timeoutHow many seconds to wait for a final FIN packet before the socket is closed required to prevent denial-of-service (DoS) attacks Default value is 60 seconds
Transport Layer 3-105
SomeTCP Parameters in Linux Kerneltcp_rmem
This is a vector of 3 integers [min default max] These parameters are used by TCP to dynamically adjust receive buffer sizesmin - minimum size of the receive buffer used by each TCP socket The default value is 4K default - the default size of the receive buffer for a TCP socket The default value is 87380 bytes and is lowered to 43689 in low memory systems If larger receive buffer sizes are desired this value should be increased max - the maximum size of the receive buffer used by each TCP socket The default value of 873802 bytes is lowered to 87380 in low memory systems
tcp_smemSend buffer parameters [min default max] similar to tcp_rmem
- Chapter 3 Transport Layer
- Transport services and protocols
- Transport vs network layer
- Internet transport-layer protocols
- Multiplexingdemultiplexing
- How demultiplexing works
- Connectionless demultiplexing
- Connection-oriented demux
- Connection-oriented demux (cont)
- Connection-oriented demux Threaded Web Server
- UDP User Datagram Protocol [RFC 768]
- UDP more
- UDP checksum
- Principles of Reliable data transfer
- Reliable data transfer getting started
- Reliable data transfer getting started
- Rdt10 reliable transfer over a reliable channel
- Rdt20 channel with bit errors
- rdt20 FSM specification
- rdt20 operation with no errors
- rdt20 error scenario
- rdt20 has a fatal flaw
- rdt21 sender handles garbled ACKNAKs
- rdt21 receiver handles garbled ACKNAKs
- rdt21 discussion
- rdt22 a NAK-free protocol
- rdt22 sender receiver fragments
- rdt30 channels with errors and loss
- rdt30 sender
- rdt30 in action
- rdt30 in action
- Performance of rdt30
- rdt30 stop-and-wait operation
- Pipelined protocols
- Pipelining increased utilization
- Go-Back-N
- GBN sender extended FSM
- GBN receiver extended FSM
- GBN inaction
- Selective Repeat
- Selective repeat sender receiver windows
- Selective repeat
- Selective repeat in action
- Selective repeat dilemma
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- TCP Overview RFCs 793 1122 1323 2018 2581
- TCP segment structure
- TCP seq rsquos and ACKs
- TCP Round Trip Time and Timeout
- TCP Round Trip Time and Timeout
- Example RTT estimation
- TCP Round Trip Time and Timeout
- TCP reliable data transfer
- TCP sender events
- TCP sender(simplified)
- TCP retransmission scenarios
- TCP retransmission scenarios (more)
- TCP ACK generation [RFC 1122 RFC 2581]
- Fast Retransmit
- Fast Retransmit
- Fast retransmit algorithm
- TCP Flow Control
- TCP Flow control how it works
- Sliding Window Flow Control Example
- Principles of Congestion Control
- Causescosts of congestion scenario 1
- Causescosts of congestion scenario 2
- Causescosts of congestion scenario 2
- Causescosts of congestion scenario 3
- Causescosts of congestion scenario 3
- Approaches towards congestion control
- TCP Congestion Control
- TCP congestion control bandwidth probing
- TCP Congestion Control details
- TCP Congestion Control more details
- TCP Slow Start Phase
- Slow Start Example
- TCP Congestion Avoidance Phase
- Congestion Avoidance
- Example Slow StartCongestion Avoidance
- Slow Start Congestion Avoidance
- Responses to Congestion
- Fast Recovery (differentiation btwn two loss events)
- TCP Congestion Control
- Popular ldquoflavorsrdquo of TCP
- Summary TCP Congestion Control
- TCP Congestion Control Summary
- TCP throughput
- TCP Futures TCP over ldquolong fat pipesrdquo
- TCP Fairness
- Why is TCP fair
- Fairness (more)
- TCP Connection Management
- TCP Connection Management (cont)
- TCP Connection Management (cont)
- TCP Connection Management (cont)
- Tuning TCPIP Parameters
- SomeTCP Parameters in Linux Kernel
- SomeTCP Parameters in Linux Kernel
-
Transport Layer 3-7
Connectionless demultiplexing
Create sockets with port numbers
DatagramSocket mySocket1 = new DatagramSocket(9111)
DatagramSocket mySocket2 = new DatagramSocket(9222)
UDP socket identified by two-tuple
(dest IP address dest port number)
When host receives UDP segment
checks destination port number in segmentdirects UDP segment to socket with that port number
IP datagrams with different source IP addresses andor source port numbers directed to same socket
Transport Layer 3-8
Connection-oriented demux
TCP socket identified by 4-tuple
source IP addresssource port numberdest IP addressdest port number
recv host uses all four values to direct segment to appropriate socket
Server host may support many simultaneous TCP sockets
each socket identified by its own 4-tuple
Web servers have different sockets for each connecting client
non-persistent HTTP will have different socket for each request
Transport Layer 3-9
Connection-oriented demux(cont)
ClientIPB
P1
clientIP A
P1P2P4
serverIP C
SP 9157DP 80
SP 9157DP 80
P5 P6 P3
D-IPCS-IP AD-IPC
S-IP B
SP 5775DP 80
D-IPCS-IP B
Transport Layer 3-10
Connection-oriented demuxThreaded Web Server
ClientIPB
P1
clientIP A
P1P2P4
serverIP C
SP 9157DP 80
SP 9157DP 80
P5 P6 P3
D-IPCS-IP AD-IPC
S-IP B
SP 5775DP 80
D-IPCS-IP B
P4
Transport Layer 3-11
UDP User Datagram Protocol [RFC 768]
ldquono frillsrdquo ldquobare bonesrdquoInternet transport protocolldquobest effortrdquo service UDP segments may be
lostdelivered out of order to app
connectionlessno handshaking between UDP sender receivereach UDP segment handled independently of others
Why is there a UDPno connection establishment (which can add delay)simple no connection state at sender receiversmall segment headerno congestion control UDP can blast away as fast as desired
Transport Layer 3-12
UDP moreoften used for streaming multimedia apps
loss tolerantrate sensitive
other UDP usesDNSSNMP
reliable transfer over UDP add reliability at application layer
application-specific error recovery
source port dest port
32 bits
Applicationdata
(message)
UDP segment format
length checksumLength in
bytes of UDPsegmentincluding
header
Transport Layer 3-13
UDP checksum
Sendertreat segment contents as sequence of 16-bit integerschecksum addition (1rsquos complement sum) of segment contents with wraparound of carry out bitsender puts checksum value into UDP checksum field
Receivercompute checksum of received segmentcheck if computed checksum equals checksum field value
NO - error detectedYES - no error detected
Goal detect ldquoerrorsrdquo (eg flipped bits) in transmitted segment
Transport Layer 3-14
Principles of Reliable data transferimportant in app transport link layerstop-10 list of important networking topics
characteristics of unreliable channel will determine complexity of reliable data transfer protocol (rdt)
netw
ork
laye
r
Transport Layer 3-15
Reliable data transfer getting started
sendside
receiveside
rdt_send() called from above (eg by app) Passed data to
deliver to receiver upper layer
udt_send() called by rdtto transfer packet over
unreliable channel to receiver
rdt_rcv() called when packet arrives on rcv-side of channel
deliver_data() called by rdt to deliver data to upper
Transport Layer 3-16
Reliable data transfer getting startedWersquoll
incrementally develop sender receiver sides of reliable data transfer protocol (rdt)consider only unidirectional data transfer
but control info will flow on both directionsuse finite state machines (FSM) to specify sender receiver
state1
state2
event causing state transitionactions taken on state transition
state when in this ldquostaterdquo next state
uniquely determined by next event
eventactions
Transport Layer 3-17
Rdt10 reliable transfer over a reliable channel
underlying channel perfectly reliableno bit errorsno loss of packets
separate FSMs for sender receiversender sends data into underlying channelreceiver read data from underlying channel
Wait for call from above packet = make_pkt(data)
udt_send(packet)
rdt_send(data)extract (packetdata)deliver_data(data)
Wait for call from
below
rdt_rcv(packet)
sender receiver
Transport Layer 3-18
Rdt20 channel with bit errors
underlying channel may flip bits in packetrecall checksum to detect bit errors
the question how to recover from errorsacknowledgements (ACKs) receiver explicitly tells sender that pkt received OKnegative acknowledgements (NAKs) receiver explicitly tells sender that pkt had errorssender retransmits pkt on receipt of NAK
new mechanisms in rdt20 (beyond rdt10)error detectionreceiver feedback control msgs (ACKNAK) rcvr-gtsender
Transport Layer 3-19
rdt20 FSM specification
Wait for call from above
snkpkt = make_pkt(data checksum)udt_send(sndpkt)
extract(rcvpktdata)deliver_data(data)udt_send(ACK)
rdt_rcv(rcvpkt) ampamp notcorrupt(rcvpkt)
rdt_rcv(rcvpkt) ampamp isACK(rcvpkt)
udt_send(sndpkt)
rdt_rcv(rcvpkt) ampampisNAK(rcvpkt)
udt_send(NAK)
rdt_rcv(rcvpkt) ampamp corrupt(rcvpkt)
Wait for ACK or
NAK
Wait for call from
belowsender
receiverrdt_send(data)
Λ
Transport Layer 3-20
rdt20 operation with no errors
Wait for call from above
snkpkt = make_pkt(data checksum)udt_send(sndpkt)
extract(rcvpktdata)deliver_data(data)udt_send(ACK)
rdt_rcv(rcvpkt) ampamp notcorrupt(rcvpkt)
rdt_rcv(rcvpkt) ampamp isACK(rcvpkt)
udt_send(sndpkt)
rdt_rcv(rcvpkt) ampampisNAK(rcvpkt)
udt_send(NAK)
rdt_rcv(rcvpkt) ampamp corrupt(rcvpkt)
Wait for ACK or
NAK
Wait for call from
below
rdt_send(data)
Λ
Transport Layer 3-21
rdt20 error scenario
Wait for call from above
snkpkt = make_pkt(data checksum)udt_send(sndpkt)
extract(rcvpktdata)deliver_data(data)udt_send(ACK)
rdt_rcv(rcvpkt) ampamp notcorrupt(rcvpkt)
rdt_rcv(rcvpkt) ampamp isACK(rcvpkt)
udt_send(sndpkt)
rdt_rcv(rcvpkt) ampampisNAK(rcvpkt)
udt_send(NAK)
rdt_rcv(rcvpkt) ampamp corrupt(rcvpkt)
Wait for ACK or
NAK
Wait for call from
below
rdt_send(data)
Λ
Transport Layer 3-22
rdt20 has a fatal flaw
What happens if ACKNAK corruptedsender doesnrsquot know what happened at receivercanrsquot just retransmit possible duplicate
What to dosender ACKsNAKs receiverrsquos ACKNAK What if sender ACKNAK lostretransmit but this might cause retransmission of correctly received pkt
Handling duplicates sender adds sequence number to each pktsender retransmits current pkt if ACKNAK garbledreceiver discards (doesnrsquot deliver up) duplicate pkt
Sender sends one packet then waits for receiver response
stop and wait
Transport Layer 3-23
rdt21 sender handles garbled ACKNAKs
Wait for call 0 from
above
sndpkt = make_pkt(0 data checksum)udt_send(sndpkt)
rdt_send(data)
Wait for ACK or NAK 0 udt_send(sndpkt)
rdt_rcv(rcvpkt) ampamp ( corrupt(rcvpkt) ||isNAK(rcvpkt) )
sndpkt = make_pkt(1 data checksum)udt_send(sndpkt)
rdt_send(data)
rdt_rcv(rcvpkt) ampamp notcorrupt(rcvpkt) ampamp isACK(rcvpkt)
udt_send(sndpkt)
rdt_rcv(rcvpkt) ampamp ( corrupt(rcvpkt) ||isNAK(rcvpkt) )
rdt_rcv(rcvpkt) ampamp notcorrupt(rcvpkt) ampamp isACK(rcvpkt)
Wait forcall 1 from
above
Wait for ACK or NAK 1
ΛΛ
Transport Layer 3-24
rdt21 receiver handles garbled ACKNAKs
Wait for 0 from below
sndpkt = make_pkt(NAK chksum)udt_send(sndpkt)
rdt_rcv(rcvpkt) ampamp not corrupt(rcvpkt) ampamphas_seq0(rcvpkt)
rdt_rcv(rcvpkt) ampamp notcorrupt(rcvpkt) ampamp has_seq1(rcvpkt)
extract(rcvpktdata)deliver_data(data)sndpkt = make_pkt(ACK chksum)udt_send(sndpkt)
Wait for 1 from below
rdt_rcv(rcvpkt) ampamp notcorrupt(rcvpkt) ampamp has_seq0(rcvpkt)
extract(rcvpktdata)deliver_data(data)sndpkt = make_pkt(ACK chksum)udt_send(sndpkt)
rdt_rcv(rcvpkt) ampamp (corrupt(rcvpkt)
sndpkt = make_pkt(ACK chksum)udt_send(sndpkt)
rdt_rcv(rcvpkt) ampamp not corrupt(rcvpkt) ampamphas_seq1(rcvpkt)
rdt_rcv(rcvpkt) ampamp (corrupt(rcvpkt)
sndpkt = make_pkt(ACK chksum)udt_send(sndpkt)
sndpkt = make_pkt(NAK chksum)udt_send(sndpkt)
Transport Layer 3-25
rdt21 discussion
Senderseq added to pkttwo seq rsquos (01) will suffice Whymust check if received ACKNAK corrupted twice as many states
state must ldquorememberrdquowhether ldquocurrentrdquo pkt has 0 or 1 seq
Receivermust check if received packet is duplicate
state indicates whether 0 or 1 is expected pkt seq
note receiver can notknow if its last ACKNAK received OK at sender
Transport Layer 3-26
rdt22 a NAK-free protocol
same functionality as rdt21 using ACKs onlyinstead of NAK receiver sends ACK for last pkt received OK
receiver must explicitly include seq of pkt being ACKed duplicate ACK at sender results in same action as NAK retransmit current pkt
Transport Layer 3-27
rdt22 sender receiver fragments
Wait for call 0 from
above
sndpkt = make_pkt(0 data checksum)udt_send(sndpkt)
rdt_send(data)
udt_send(sndpkt)
rdt_rcv(rcvpkt) ampamp ( corrupt(rcvpkt) ||
isACK(rcvpkt1) )
rdt_rcv(rcvpkt) ampamp notcorrupt(rcvpkt) ampamp isACK(rcvpkt0)
Wait for ACK
0sender FSM
fragment
Wait for 0 from below
rdt_rcv(rcvpkt) ampamp notcorrupt(rcvpkt) ampamp has_seq1(rcvpkt)
extract(rcvpktdata)deliver_data(data)sndpkt = make_pkt(ACK1 chksum)udt_send(sndpkt)
rdt_rcv(rcvpkt) ampamp (corrupt(rcvpkt) ||
has_seq1(rcvpkt))
udt_send(sndpkt)receiver FSM
fragment
Λ
Transport Layer 3-28
rdt30 channels with errors and loss
New assumptionunderlying channel can also lose packets (data or ACKs)
checksum seq ACKs retransmissions will be of help but not enough
Q how to deal with losssender waits until certain data or ACK lost then retransmitsdrawbacks
Approach sender waits ldquoreasonablerdquo amount of time for ACK retransmits if no ACK received in this timeif pkt (or ACK) just delayed (not lost)
retransmission will be duplicate but use of seq rsquos already handles thisreceiver must specify seq of pkt being ACKed
requires countdown timer
Transport Layer 3-29
rdt30 sendersndpkt = make_pkt(0 data checksum)udt_send(sndpkt)start_timer
rdt_send(data)
Wait for
ACK0
rdt_rcv(rcvpkt) ampamp ( corrupt(rcvpkt) ||isACK(rcvpkt1) )
Wait for call 1 from
above
sndpkt = make_pkt(1 data checksum)udt_send(sndpkt)start_timer
rdt_send(data)
rdt_rcv(rcvpkt) ampamp notcorrupt(rcvpkt) ampamp isACK(rcvpkt0)
rdt_rcv(rcvpkt) ampamp ( corrupt(rcvpkt) ||isACK(rcvpkt0) )
rdt_rcv(rcvpkt) ampamp notcorrupt(rcvpkt) ampamp isACK(rcvpkt1)
stop_timerstop_timer
udt_send(sndpkt)start_timer
timeout
udt_send(sndpkt)start_timer
timeout
rdt_rcv(rcvpkt)
Wait for call 0from
above
Wait for
ACK1
Λrdt_rcv(rcvpkt)
ΛΛ
Λ
Transport Layer 3-30
rdt30 in action
Transport Layer 3-31
rdt30 in action
Transport Layer 3-32
Performance of rdt30
rdt30 works but performance stinksexample 1 Gbps link 15 ms e-e prop delay 1KB packet
Ttransmit = 8kbpkt109 bsec = 8 microsec
U sender utilization ndash fraction of time sender busy sending1KB pkt every 30 msec -gt 33kBsec thruput over 1 Gbps linknetwork protocol limits use of physical resources
U sender=
008 30008
= 000027 L RRTT + L R
=
L (packet length in bits)R (transmission rate bps) =
Transport Layer 3-33
rdt30 stop-and-wait operation
first packet bit transmitted t = 0
sender receiver
RTT
last packet bit transmitted t = L R
first packet bit arriveslast packet bit arrives send ACK
ACK arrives send next packet t = RTT + L R
U sender=
00830008
= 000027 L RRTT + L R
=
Transport Layer 3-34
Pipelined protocolsPipelining sender allows multiple ldquoin-flightrdquo yet-to-
be-acknowledged pktsrange of sequence numbers must be increasedbuffering at sender andor receiver
Two generic forms of pipelined protocols go-Back-N selective repeat
Transport Layer 3-35
Pipelining increased utilization
first packet bit transmitted t = 0
sender receiver
RTT
last bit transmitted t = L R
first packet bit arriveslast packet bit arrives send ACK
ACK arrives send next packet t = RTT + L R
last bit of 2nd packet arrives send ACKlast bit of 3rd packet arrives send ACK
U sender=
024 30008
= 000083 L RRTT + L R
=
Increase utilizationby a factor of 3
Transport Layer 3-36
Utilization=N(LR)(RTT+LR) if NLRltRTT+LR Utilization=1 if and the sender pauses after it transmits a window NLRgtRTT+LR and the of packets until it receives first ACK sender does not pause
Transport Layer 3-37
Go-Back-NSender
k-bit seq in pkt headerldquowindowrdquo of up to N consecutive unackrsquoed pkts allowed
ACK(n) ACKs all pkts up to including seq n - ldquocumulative ACKrdquomay receive duplicate ACKs (see receiver)
timer for the entire windowtimeout(n) retransmit pkt n and all higher seq pkts in window
Transport Layer 3-38
GBN sender extended FSM
Wait start_timerudt_send(sndpkt[base])udt_send(sndpkt[base+1])hellipudt_send(sndpkt[nextseqnum-1])
timeout
rdt_send(data)
if (nextseqnum lt base+N) sndpkt[nextseqnum] = make_pkt(nextseqnumdatachksum)udt_send(sndpkt[nextseqnum])if (base == nextseqnum)
start_timernextseqnum++
elserefuse_data(data)
base = getacknum(rcvpkt)+1If (base == nextseqnum)
stop_timerelse
start_timer
rdt_rcv(rcvpkt) ampamp notcorrupt(rcvpkt)
base=1nextseqnum=1
rdt_rcv(rcvpkt) ampamp corrupt(rcvpkt)
Λ
Λ
Transport Layer 3-39
GBN receiver extended FSM
ACK-only always send ACK for correctly-received pktwith highest in-order seq
may generate duplicate ACKsneed only remember expectedseqnum
out-of-order pkt discard (donrsquot buffer) -gt no receiver bufferingRe-ACK pkt with highest in-order seq
Wait
udt_send(sndpkt)default
rdt_rcv(rcvpkt)ampamp notcurrupt(rcvpkt)ampamp hasseqnum(rcvpktexpectedseqnum)
extract(rcvpktdata)deliver_data(data)sndpkt = make_pkt(expectedseqnumACKchksum)udt_send(sndpkt)expectedseqnum++
expectedseqnum=1sndpkt =
make_pkt(0ACKchksum)
Λ
Transport Layer 3-40
GBN inaction
Transport Layer 3-41
Selective Repeat
receiver individually acknowledges all correctly received pkts
buffers pkts as needed for eventual in-order delivery to upper layer
sender only resends pkts for which ACK not received
sender timer for each unACKed pktsender window
N consecutive seq rsquosagain limits seq s of sent unACKed pkts
Transport Layer 3-42
Selective repeat sender receiver windows
Transport Layer 3-43
Selective repeat
data from above if next available seq in window send pkt
timeout(n)resend pkt n restart timer
ACK(n) in [sendbasesendbase+N-1]
mark pkt n as receivedif n smallest unACKed pkt advance window base to next unACKed seq
senderpkt n in [rcvbase rcvbase+N-1]
send ACK(n)out-of-order bufferin-order deliver (also deliver buffered in-order pkts) advance window to next not-yet-received pkt
pkt n in [rcvbase-Nrcvbase-1]
ACK(n)otherwise
ignore
receiver
Transport Layer 3-44
Selective repeat in action
Transport Layer 3-45
Selective repeatdilemma
Example seq rsquos 0 1 2 3window size=3
receiver sees no difference in two scenariosincorrectly passes duplicate data as new in (a)
Q what relationship between seq size and window size
Transport Layer 3-46
Sequence Number vs Window SizeSuppose we use k bits to represent SNQuestion Whatrsquos the minimum number of bits k necessary for a window size of N
sender
receiver
Go-Back-N
expectedSN
snd_base=expectedSN
Q For a given expectedSN whatrsquos the largest possible value for snd_baseA If all the last N ACKs sent by the receiver are received
snd_base = expectedSNexpectedSN+N-1
senderrsquos window
Transport Layer 3-47
Sequence Number vs Window SizeSuppose we use k bits to represent SNQuestion Whatrsquos the minimum number of bits k necessary for a window size of N
sender
receiver
Go-Back-N
expectedSN
snd_base=expectedSN-N
Q For a given expectedSN whatrsquos the smallest possible value for snd_baseA If all the last N ACKs sent by the receiver are not received
snd_base = expectedSN-NexpectedSN-1
senderrsquos window
Transport Layer 3-48
Sequence Number vs Window Size
sender
receiver
Go-Back-N
expectedSN
snd_base=expectedSN-N
All SNs in the interval [expectedSN-NexpectedSN+N-1] (an interval of size 2N) can be received by the receiver Since the receiver accepts on the packet with SN=expectedSN there should be no other packet within this interval with SN=expectedSN Therefore
2k ge N+1expectedSN+N-1
Transport Layer 3-49
Sequence Number vs Window SizeSuppose we use k bits to represent SNQuestion Whatrsquos the minimum number of bits k necessary for a window size of N
sender
receiver
Selective Repeat
rcv_base
snd_base=rcv_base
Q For a given rcv_base whatrsquos the largest possible value for snd_baseA If all the last N ACKs sent by the receiver are received
snd_base = rcv_base (same as go_back-N)rcv_base+N-1
senderrsquos window
receiverrsquos window
rcv_base+N-1
Transport Layer 3-50
Sequence Number vs Window SizeSuppose we use k bits to represent SNQuestion Whatrsquos the minimum number of bits k necessary for a window size of N
sender
receiver
Selective Repeat
rcv_base
snd_base=rcv_base-N
Q For a given rcv_base whatrsquos the smallest possible value for snd_baseA If all the last N ACKs sent by the receiver are not received
snd_base = rcv_base-N (same as Go-Back-N)rcv_base-1
senderrsquos window
rcv_base
receiverrsquos window
rcv_base+N-1
Transport Layer 3-51
Sequence Number vs Window Size
sender
receiver
Selective Repeat
snd_base=rcv_base-N
All SNs in the interval [rcv_base-Nrcv_base+N-1] (an interval of size 2N) can be received by the receiver Since the receiver should be able to distinguish between all packets in this interval and take corresponding action there should be no two packets within thisinterval having the same SN Therefore
2k ge 2Nrcv_base+N-1
rcv_basercv_base
receiverrsquos window
rcv_base+N-1
Transport Layer 3-52
TCP Overview RFCs 793 1122 1323 2018 2581
full duplex databi-directional data flow in same connectionMSS maximum segment size
connection-orientedhandshaking (exchange of control msgs) initrsquossender receiver state before data exchange
flow controlledsender will not overwhelm receiver
point-to-pointone sender one receiver
reliable in-order byte stream
no ldquomessage boundariesrdquopipelined
TCP congestion and flow control set window size
send amp receive buffers
socketdoor
TCPsend buffer
TCPreceive buffer
socketdoor
segment
applicationwrites data
applicationreads data
Transport Layer 3-53
TCP segment structure
source port dest port
32 bits
applicationdata
(variable length)
sequence numberacknowledgement number
Receive windowUrg data pnterchecksum
FSRPAUheadlen
notused
Options (variable length)
URG urgent data (generally not used)
ACK ACK valid
PSH push data now(generally not used)
RST SYN FINconnection estab(setup teardown
commands)
bytes rcvr willingto accept
Internetchecksum
(as in UDP)
countingby bytes of data(not segments)
Transport Layer 3-54
TCP seq rsquos and ACKsSeq rsquos
byte stream ldquonumberrdquo of first byte in segmentrsquos dataACKs
seq of next byte expected from other sidecumulative ACK
Q how receiver handles out-of-order segmentsA TCP spec doesnrsquot say - up to implementationWidely used implementations of TCP buffer out-of-order segments
Transport Layer 3-55
TCP Round Trip Time and Timeout
Q how to set TCP timeout valuelonger than RTT
but RTT variestoo short premature timeout
unnecessary retransmissions
too long slow reaction to segment loss
Q how to estimate RTTSampleRTT measured time from segment transmission until ACK receipt
ignore retransmissionsSampleRTT will vary want estimated RTT ldquosmootherrdquo
average several recent measurements not just current SampleRTT
Transport Layer 3-56
TCP Round Trip Time and Timeout
EstimatedRTT = (1- α)EstimatedRTT + αSampleRTT
Exponential weighted moving averageinfluence of past sample decreases exponentially fasttypical value α = 0125
Transport Layer 3-57
Example RTT estimationRTT gaiacsumassedu to fantasiaeurecomfr
100
150
200
250
300
350
1 8 15 22 29 36 43 50 57 64 71 78 85 92 99 106
time (seconnds)
RTT
(mill
iseco
nds)
SampleRTT Estimated RTT
Transport Layer 3-58
TCP Round Trip Time and TimeoutSetting the timeout
EstimatedRTT plus ldquosafety marginrdquolarge variation in EstimatedRTT -gt larger safety margin
first estimate of how much SampleRTT deviates from EstimatedRTT
TimeoutInterval = EstimatedRTT + 4DevRTT
DevRTT = (1-β)DevRTT +β|SampleRTT-EstimatedRTT|
(typically β = 025)
Then set timeout interval
Transport Layer 3-59
TCP reliable data transfer
TCP creates rdtservice on top of IPrsquos unreliable servicePipelined segmentsCumulative acksTCP uses single retransmission timer however it just retransmits the first segment in the window
Retransmissions are triggered by
timeout eventsduplicate acks
Initially consider simplified TCP sender
ignore duplicate acksignore flow control congestion control
Transport Layer 3-60
TCP sender eventsdata rcvd from app
Create segment with seq seq is byte-stream number of first data byte in segmentstart timer if not already running (think of timer as for oldest unacked segment)expiration interval TimeOutInterval
timeoutretransmit segment that caused timeout (first segment in the window)restart timer
Ack rcvdIf acknowledges previously unacked segments
update what is known to be ackedstart timer if there are outstanding segments
Transport Layer 3-61
TCP sender(simplified)
NextSeqNum = InitialSeqNumSendBase = InitialSeqNum
loop (forever) switch(event)
event data received from application above create TCP segment with sequence number NextSeqNumif (timer currently not running)
start timerpass segment to IP NextSeqNum = NextSeqNum + length(data)
event timer timeoutretransmit not-yet-acknowledged segment with
smallest sequence numberstart timer
event ACK received with ACK field value of y if (y gt SendBase)
SendBase = yif (there are currently not-yet-acknowledged segments)
start timer
end of loop forever
Commentbull SendBase-1 last cumulatively ackrsquoed byteExamplebull SendBase-1 = 71y= 73 so the rcvrwants 73+ y gt SendBase sothat new data is acked
Transport Layer 3-62
TCP retransmission scenariosHost A
Seq=100 20 bytes data
ACK=100
timepremature timeout
Host B
Seq=92 8 bytes data
ACK=120
Seq=92 8 bytes data
Seq=
92 t
imeo
ut
ACK=120
Host A
Seq=92 8 bytes data
ACK=100
loss
tim
eout
lost ACK scenario
Host B
X
Seq=92 8 bytes data
ACK=100
time
Seq=
92 t
imeo
utSendBase
= 100
SendBase= 120
SendBase= 120
Sendbase= 100
Transport Layer 3-63
TCP retransmission scenarios (more)Host A
Seq=92 8 bytes data
ACK=100
loss
tim
eout
Cumulative ACK scenario
Host B
X
Seq=100 20 bytes data
ACK=120
time
SendBase= 120
Transport Layer 3-64
TCP ACK generation [RFC 1122 RFC 2581]
Event at Receiver
Arrival of in-order segment withexpected seq All data up toexpected seq already ACKed
Arrival of in-order segment withexpected seq One other segment has ACK pending
Arrival of out-of-order segmenthigher-than-expect seq Gap detected
Arrival of segment that partially or completely fills gap
TCP Receiver action
Delayed ACK Wait up to 500msfor next segment If no next segmentsend ACK
Immediately send single cumulative ACK ACKing both in-order segments
Immediately send duplicate ACK indicating seq of next expected byte
Immediate send ACK provided thatsegment startsat lower end of gap
Transport Layer 3-65
Fast Retransmit
Time-out period often relatively long
long delay before resending lost packet
Detect lost segments via duplicate ACKs
Sender often sends many segments back-to-backIf segment is lost there will likely be many duplicate ACKs
If sender receives 3 ACKs for the same data it supposes that segment after ACKeddata was lost
fast retransmit resend segment before timer expires
Transport Layer 3-66
Fast RetransmitResend a segment after 3 duplicate ACKs since a duplicate ACK means that an out-of sequence segment was receivedduplicate ACKs due to packet reorderingif window is small donrsquot get duplicate ACKs
Host A
tim
eout
Host B
time
X
resend seq X2
seq x1seq x2seq x3seq x4seq x5
ACK x1
ACK x1ACK x1ACK x1
tripleduplicate
ACKs
Transport Layer 3-67
event ACK received with ACK field value of y if (y gt SendBase)
SendBase = yif (there are currently not-yet-acknowledged segments)
start timer
else increment count of dup ACKs received for yif (count of dup ACKs received for y = 3)
resend segment with sequence number y
Fast retransmit algorithm
a duplicate ACK for already ACKed segment
fast retransmit
Transport Layer 3-68
TCP Flow Control
receive side of TCP connection has a receive buffer
speed-matching service matching the send rate to the receiving apprsquos drain rate
app process may be slow at reading from buffer
sender wonrsquot overflowreceiverrsquos buffer by
transmitting too muchtoo fast
flow control
Transport Layer 3-69
TCP Flow control how it works
(Suppose TCP receiver discards out-of-order segments)spare room in buffer
= RcvWin
= RcvBuffer-[LastByteRcvd -LastByteRead]
Rcvr advertises spare room by including value of RcvWin in segmentsSender limits unACKeddata to RcvWin
guarantees receive buffer doesnrsquot overflow
Transport Layer 3-70
Sliding Window Flow Control Example
3K
2K SeqNo=0
ReceiverBuffer
0 4KSendersends 2Kof data
2K
AckNo=2048 RcvWin=2048Sendersends 2Kof data 2K SeqNo=2048
4K
AckNo=4096 RcvWin=0
AckNo=4096 RcvWin=1024
Sender blocked
Transport Layer 3-71
Principles of Congestion Control
Congestioninformally ldquotoo many sources sending too much data too fast for network to handlerdquodifferent from flow controlmanifestations
lost packets (buffer overflow at routers)long delays (queueing in router buffers)
a top-10 problem
Transport Layer 3-72
Causescosts of congestion scenario 1
two senders two receiversone router infinite buffers no retransmission
large delays when congestedmaximum achievable throughput
unlimited shared output link buffers
Host Aλin original data
Host B
λout
Transport Layer 3-73
Causescosts of congestion scenario 2
one router finite buffers sender retransmission of lost packet
finite shared output link buffers
Host A λin original data
Host B
λout
λin original data plus retransmitted data
Transport Layer 3-74
Causescosts of congestion scenario 2always (goodput)ldquoperfectrdquo retransmission only when loss
retransmission of delayed (not lost) packet makes larger(than perfect case) for same
λin
λout=
λin
λoutgtλ
inλout
ldquocostsrdquo of congestionmore work (retrans) for given ldquogoodputrdquounneeded retransmissions link carries multiple copies of pkt
R2
R2λin
λ out
b
R2
R2λin
λ out
a
R2
R2λin
λ out
c
R4
R3
Transport Layer 3-75
Causescosts of congestion scenario 3four sendersmultihop pathstimeoutretransmit
λin
Q what happens as and increase λ
in
finite shared output link buffers
Host Aλin original data
Host B
λout
λin original data plus retransmitted data
Transport Layer 3-76
Causescosts of congestion scenario 3
another ldquocostrdquo of congestionwhen packet dropped any ldquoupstream transmission capacity used for that packet was wasted
Host A
Host B
λou
t
Transport Layer 3-77
Approaches towards congestion control
End-end congestion controlno explicit feedback from networkcongestion inferred from end-system observed loss delayapproach taken by TCP
Network-assisted congestion controlrouters provide feedback to end systems
single bit indicating congestion (SNA DECbit TCPIP ECN ATM)explicit rate sender should send at
Two broad approaches towards congestion control
Transport Layer 3-78
TCP Congestion Control
end-end control (no network assistance)sender limits transmissionLastByteSent-LastByteAcked
le CongWin
CongWin is dynamic function of perceived network congestion
How does sender perceive congestionloss event = timeout or3 duplicate acksTCP sender reduces rate (CongWin) after loss event
two modes of operationSlow Start (SS)Congestion avoidance (CA) or Additive Increase Multiplicative Decrease (AIMD)
Transport Layer 3-79
TCP congestion control bandwidth probing
ldquoprobing for bandwidthrdquo increase transmission rate on receipt of ACK until eventually loss occurs then decrease transmission rate
continue to increase on ACK decrease on loss (since available bandwidth is changing depending on other connections in network)
ACKs being received so increase rate
X
X
XX
X loss so decrease rate
send
ing
rate
time
Q how fast to increasedecreasedetails to follow
TCPrsquosldquosawtoothrdquobehavior
Transport Layer 3-80
TCP Congestion Control details
sender limits rate by limiting number of unACKed bytes ldquoin pipelinerdquo
cwnd differs from rwnd (how why)sender limited by min(cwndrwnd)
roughly
cwnd is dynamic function of perceived network congestion
rate = cwndRTT bytessec
LastByteSent-LastByteAcked le cwnd
cwndbytes
RTT
ACK(s)
Transport Layer 3-81
TCP Congestion Control more details
segment loss event reducing cwndtimeout no response from receiver
cut cwnd to 13 duplicate ACKs at least some segments getting through (recall fast retransmit)
cut cwnd in half less aggressively than on timeout
ACK received increase cwndTwo modes of operation
slowstart phase bull increase exponentially
fast (despite name) at connection start or following timeout
congestion avoidance bull increase linearly
Transport Layer 3-82
TCP Slow Start Phasewhen connection begins cwnd = 1 MSS
example MSS = 500 bytes amp RTT = 200 msecinitial rate = 20 kbps
available bandwidth may be gtgt MSSRTT
desirable to quickly ramp up to respectable rate
increase rate exponentially until first loss event or when threshold reached
double cwnd every RTTdone by incrementing cwnd by 1 for every ACK received
Host A
one segment
RTT
Host B
time
two segments
four segments
Transport Layer 3-83
Slow Start ExampleThe congestion window size grows very rapidly
For every ACK we increase CongWin by 1 irrespective of the number of segments ACKrsquoeddouble CongWinevery RTTinitial rate is slow but ramps up exponentially fast
TCP slows down the increase of CongWinwhen CongWin gt ssthresh
segment 1
ACK for segment 1
cwnd = 1
cwnd = 2 segment 2segment 3
ACK for segments 2
cwnd = 4 segment 4segment 5segment 6
ACK for segments 4
cwnd = 7
ACK for segments 3
ACK for segments 5
ACK for segments 6
cwnd = 3
cwnd = 5
cwnd = 6ACK for segments 7
cwnd = 8
segment 7
Transport Layer 3-84
TCP Congestion Avoidance Phase
when cwnd gt ssthreshgrow cwnd linearly
increase cwnd by 1 MSS per RTT approach possible congestion slower than in slowstartimplementation cwnd= cwnd + MSScwndfor each ACK received
ACKs increase cwndby 1 MSS per RTT additive increaseloss cut cwnd in half (non-timeout-detected loss ) multiplicative decrease
AIMD
AIMD Additive IncreaseMultiplicative Decrease
Transport Layer 3-85
Congestion AvoidanceCongestion avoidance phase is started if CongWin has reached the slow-start threshold value
If CongWin gt= ssthresh then each time an ACK is received increment CongWin as follows
bull CongWin = CongWin + 1CongWin (CongWin in segments)
bull In actual TCP implementation CongWin is in BytesCongWin = CongWin + MSS (MSSCongWin)
So CongWin is increased by one only if all CongWinsegments have been acknowledged
Transport Layer 3-86
Example Slow StartCongestion AvoidanceAssume that
ssthresh = 8
cwnd = 1
cwnd = 2
cwnd = 4
cwnd = 8
cwnd = 9
cwnd = 10
02468
101214
t=0
t=2
t=4
t=6
Roundtrip times
Cw
nd(in
seg
men
ts)
ssthresh
cwnd = 3
cwnd = 5cwnd = 6cwnd = 7
Transport Layer 3-87
Slow Start Congestion AvoidanceA typical plot of CongWin for a TCP connection
(MSS = 1500 bytes) with TCP Tahoe
SS
CA
ssthresh
Transport Layer 3-88
Responses to CongestionTCP assumes there is congestion if it detects a packet lossA TCP sender can detect lost packets via loss events
bull Timeout of a retransmission timerbull Receipt of 3 duplicate ACKs (fast retransmit)
TCP interprets a Timeout as a binary congestion signal When a timeout occurs the sender performs
ssthresh is set to half the current size of the congestion window
ssthresh = CongWin 2CongWin is reset to one
CongWin = 1and slow-start is entered
Transport Layer 3-89
Fast Recovery (differentiation btwn two loss events) After 3 dup ACKs (fast Retransmit)
ssthresh = CongWin2CongWin = CongWin2window then grows linearly
But after timeout eventCongWin = 1 MSS window then grows exponentiallyto the threshold then grows linearly
bull 3 dup ACKs indicates network capable of delivering some segmentsbull timeout before 3 dup ACKs is ldquomore alarmingrdquo
Philosophy
3-90
TCP Congestion ControlInitially
CongWin = 1ssthresh = advertised window size
New Ack receivedif (CongWin lt ssthresh) Slow Start
CongWin = CongWin + 1else Congestion Avoidance
CongWin = CongWin + 1CongWinTimeout
ssthresh = CongWin2CongWin = 1
Fast Retransmissionssthresh = CongWin2CongWin = CongWin2
Slow Start (exponential increase phase) is continued until CongWin reaches half of the level where the loss event occurred last time CongWin is increased slowly after (linear increase in Congestion Avoidance phase)
Transport Layer 3-91
Popular ldquoflavorsrdquo of TCP
ssthresh
ssthresh
TCP Tahoe
TCP Reno
Transmission round
cwnd
win
dow
siz
e (in
seg
men
ts)
Transport Layer 3-92
Summary TCP Congestion ControlWhen CongWin is below Threshold sender in slow-start phase window grows exponentiallyWhen CongWin is above Threshold sender is in congestion-avoidance phase window grows linearlyWhen a triple duplicate ACK occurs Threshold set to CongWin2 and CongWin set to ThresholdWhen timeout occurs Threshold set to CongWin2 and CongWin is set to 1 MSS The actual sender window size is determined based on the congestion and flow control algorithms
SenderWin=min(RcvWinCongWin)
Transport Layer 3-93
TCP Congestion Control SummaryEvent State TCP Sender Action Commentary
ACK receipt for previously unackeddata
Slow Start (SS)
CongWin = CongWin + MSS If (CongWin gt Threshold)
set state to ldquoCongestion Avoidancerdquo
Resulting in a doubling of CongWin every RTT
ACK receipt for previously unackeddata
CongestionAvoidance (CA)
CongWin = CongWin+MSS (MSSCongWin)
Additive increase resulting in increase of CongWin by 1 MSS every RTT
Loss event detected by triple duplicate ACK
SS or CA Threshold = CongWin2 CongWin = ThresholdSet state to ldquoCongestion Avoidancerdquo
Fast recovery implementing multiplicative decrease CongWin will not drop below 1 MSS
Timeout SS or CA Threshold = CongWin2 CongWin = 1 MSSSet state to ldquoSlow Startrdquo
Enter slow start
Duplicate ACK
SS or CA Increment duplicate ACK count for segment being acked
CongWin and Threshold not changed
Transport Layer 3-94
TCP throughput
Q whatrsquos average throughout of TCP as function of window size RTT
ignoring slow startlet W be window size when loss occurs
when window is W throughput is WRTTjust after loss window drops to W2 throughput to W2RTT average throughout 75 WRTT
Transport Layer 3-95
TCP Futures TCP over ldquolong fat pipesrdquo
example 1500 byte segments 100ms RTT want 10 Gbps throughputrequires window size W = 83333 in-flight segmentsthroughput in terms of loss rate
L = 210-10 Wownew versions of TCP for high-speed
LRTTMSSsdot221
Transport Layer 3-96
Fairness goal if K TCP sessions share same bottleneck link of bandwidth R each should have average rate of RK
TCP connection 1
bottleneckrouter
capacity R
TCP connection 2
TCP Fairness
Transport Layer 3-97
Why is TCP fairTwo competing sessions
Additive increase gives slope of 1 as throughout increasesmultiplicative decrease decreases throughput proportionally
R
R
equal bandwidth share
Connection 1 throughput
Conn
ecti
on 2
thr
ough
p ut
congestion avoidance additive increaseloss decrease window by factor of 2
congestion avoidance additive increaseloss decrease window by factor of 2
Transport Layer 3-98
Fairness (more)Fairness and UDP
Multimedia apps often do not use TCP
do not want rate throttled by congestion control
Instead use UDPpump audiovideo at constant rate tolerate packet loss
Research area TCP friendly
Fairness and parallel TCP connectionsnothing prevents app from opening parallel cnctionsbetween 2 hostsWeb browsers do this Example link of rate R supporting 9 cnctions
new app asks for 1 TCP gets rate R10new app asks for 11 TCPs gets R2
Transport Layer 3-99
TCP Connection ManagementRecall TCP sender receiver
establish ldquoconnectionrdquobefore exchanging data segmentsinitialize TCP variables
seq sbuffers flow control info (eg RcvWindow)
client connection initiatorSocket clientSocket = new Socket(hostnameport
number)
server contacted by clientSocket connectionSocket = welcomeSocketaccept()
Three way handshakeStep 1 client host sends TCP
SYN segment to serverspecifies initial seq no data
Step 2 server host receives SYN replies with SYNACK segment
server allocates buffersspecifies server initial seq
Step 3 client receives SYNACK replies with ACK segment which may contain data
Transport Layer 3-100
TCP Connection Management (cont)
Closing a connection
client closes socketclientSocketclose()
Step 1 client end system sends TCP FIN control segment to server
Step 2 server receives FIN replies with ACK Closes connection sends FIN
client
FIN
server
ACK
ACK
FIN
close
close
closed
tim
ed w
ait
Transport Layer 3-101
TCP Connection Management (cont)
Step 3 client receives FIN replies with ACK
Enters ldquotimed waitrdquo -will respond with ACK to received FINs
Step 4 server receives ACK Connection closed
client
FIN
server
ACK
ACK
FIN
closing
closing
closed
tim
ed w
ait
closed
Transport Layer 3-102
TCP Connection Management (cont)
TCP clientlifecycle
TCP serverlifecycle
Transport Layer 3-103
Tuning TCPIP Parameters TCPIP parameters
A set of default values may not be optimal for all applicationsThe network administrator may wish to turn on or off some TCPIP functions for performance or security considerations
Many Unix and Linux systems provide some flexibility in tuning the TCPIP kernelsbinsysctl is used to configure the Linux kernel parameters at runtime
Default kernel configuration file is sbinsysctlconfFrequently used sysctl options
bull sysctl ndasha or sysctl ndashA list all current valuesbull sysctl ndashp file_name load the sysctl setting from a configuration
filebull sysctl ndashw variable=value change the value of the parameter
Transport Layer 3-104
SomeTCP Parameters in Linux Kerneltcp_syn_retries
Number of SYN packets the kernel will send before giving up on the new connection
tcp_synack_retriesnumber of SYN+ACK packets sent before the kernel gives up on the connection
tcp_window_scalingMaximum window size of 65535 bytes not enough for for really fast networks The window scaling options allows for almost gigabyte windows which is good for connections with large delay-bandwidth product
tcp_max_syn_backlogMaximal number of remembered connection requests which still did not receive an acknowledgment from connecting client
tcp_fin_timeoutHow many seconds to wait for a final FIN packet before the socket is closed required to prevent denial-of-service (DoS) attacks Default value is 60 seconds
Transport Layer 3-105
SomeTCP Parameters in Linux Kerneltcp_rmem
This is a vector of 3 integers [min default max] These parameters are used by TCP to dynamically adjust receive buffer sizesmin - minimum size of the receive buffer used by each TCP socket The default value is 4K default - the default size of the receive buffer for a TCP socket The default value is 87380 bytes and is lowered to 43689 in low memory systems If larger receive buffer sizes are desired this value should be increased max - the maximum size of the receive buffer used by each TCP socket The default value of 873802 bytes is lowered to 87380 in low memory systems
tcp_smemSend buffer parameters [min default max] similar to tcp_rmem
- Chapter 3 Transport Layer
- Transport services and protocols
- Transport vs network layer
- Internet transport-layer protocols
- Multiplexingdemultiplexing
- How demultiplexing works
- Connectionless demultiplexing
- Connection-oriented demux
- Connection-oriented demux (cont)
- Connection-oriented demux Threaded Web Server
- UDP User Datagram Protocol [RFC 768]
- UDP more
- UDP checksum
- Principles of Reliable data transfer
- Reliable data transfer getting started
- Reliable data transfer getting started
- Rdt10 reliable transfer over a reliable channel
- Rdt20 channel with bit errors
- rdt20 FSM specification
- rdt20 operation with no errors
- rdt20 error scenario
- rdt20 has a fatal flaw
- rdt21 sender handles garbled ACKNAKs
- rdt21 receiver handles garbled ACKNAKs
- rdt21 discussion
- rdt22 a NAK-free protocol
- rdt22 sender receiver fragments
- rdt30 channels with errors and loss
- rdt30 sender
- rdt30 in action
- rdt30 in action
- Performance of rdt30
- rdt30 stop-and-wait operation
- Pipelined protocols
- Pipelining increased utilization
- Go-Back-N
- GBN sender extended FSM
- GBN receiver extended FSM
- GBN inaction
- Selective Repeat
- Selective repeat sender receiver windows
- Selective repeat
- Selective repeat in action
- Selective repeat dilemma
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- TCP Overview RFCs 793 1122 1323 2018 2581
- TCP segment structure
- TCP seq rsquos and ACKs
- TCP Round Trip Time and Timeout
- TCP Round Trip Time and Timeout
- Example RTT estimation
- TCP Round Trip Time and Timeout
- TCP reliable data transfer
- TCP sender events
- TCP sender(simplified)
- TCP retransmission scenarios
- TCP retransmission scenarios (more)
- TCP ACK generation [RFC 1122 RFC 2581]
- Fast Retransmit
- Fast Retransmit
- Fast retransmit algorithm
- TCP Flow Control
- TCP Flow control how it works
- Sliding Window Flow Control Example
- Principles of Congestion Control
- Causescosts of congestion scenario 1
- Causescosts of congestion scenario 2
- Causescosts of congestion scenario 2
- Causescosts of congestion scenario 3
- Causescosts of congestion scenario 3
- Approaches towards congestion control
- TCP Congestion Control
- TCP congestion control bandwidth probing
- TCP Congestion Control details
- TCP Congestion Control more details
- TCP Slow Start Phase
- Slow Start Example
- TCP Congestion Avoidance Phase
- Congestion Avoidance
- Example Slow StartCongestion Avoidance
- Slow Start Congestion Avoidance
- Responses to Congestion
- Fast Recovery (differentiation btwn two loss events)
- TCP Congestion Control
- Popular ldquoflavorsrdquo of TCP
- Summary TCP Congestion Control
- TCP Congestion Control Summary
- TCP throughput
- TCP Futures TCP over ldquolong fat pipesrdquo
- TCP Fairness
- Why is TCP fair
- Fairness (more)
- TCP Connection Management
- TCP Connection Management (cont)
- TCP Connection Management (cont)
- TCP Connection Management (cont)
- Tuning TCPIP Parameters
- SomeTCP Parameters in Linux Kernel
- SomeTCP Parameters in Linux Kernel
-
Transport Layer 3-8
Connection-oriented demux
TCP socket identified by 4-tuple
source IP addresssource port numberdest IP addressdest port number
recv host uses all four values to direct segment to appropriate socket
Server host may support many simultaneous TCP sockets
each socket identified by its own 4-tuple
Web servers have different sockets for each connecting client
non-persistent HTTP will have different socket for each request
Transport Layer 3-9
Connection-oriented demux(cont)
ClientIPB
P1
clientIP A
P1P2P4
serverIP C
SP 9157DP 80
SP 9157DP 80
P5 P6 P3
D-IPCS-IP AD-IPC
S-IP B
SP 5775DP 80
D-IPCS-IP B
Transport Layer 3-10
Connection-oriented demuxThreaded Web Server
ClientIPB
P1
clientIP A
P1P2P4
serverIP C
SP 9157DP 80
SP 9157DP 80
P5 P6 P3
D-IPCS-IP AD-IPC
S-IP B
SP 5775DP 80
D-IPCS-IP B
P4
Transport Layer 3-11
UDP User Datagram Protocol [RFC 768]
ldquono frillsrdquo ldquobare bonesrdquoInternet transport protocolldquobest effortrdquo service UDP segments may be
lostdelivered out of order to app
connectionlessno handshaking between UDP sender receivereach UDP segment handled independently of others
Why is there a UDPno connection establishment (which can add delay)simple no connection state at sender receiversmall segment headerno congestion control UDP can blast away as fast as desired
Transport Layer 3-12
UDP moreoften used for streaming multimedia apps
loss tolerantrate sensitive
other UDP usesDNSSNMP
reliable transfer over UDP add reliability at application layer
application-specific error recovery
source port dest port
32 bits
Applicationdata
(message)
UDP segment format
length checksumLength in
bytes of UDPsegmentincluding
header
Transport Layer 3-13
UDP checksum
Sendertreat segment contents as sequence of 16-bit integerschecksum addition (1rsquos complement sum) of segment contents with wraparound of carry out bitsender puts checksum value into UDP checksum field
Receivercompute checksum of received segmentcheck if computed checksum equals checksum field value
NO - error detectedYES - no error detected
Goal detect ldquoerrorsrdquo (eg flipped bits) in transmitted segment
Transport Layer 3-14
Principles of Reliable data transferimportant in app transport link layerstop-10 list of important networking topics
characteristics of unreliable channel will determine complexity of reliable data transfer protocol (rdt)
netw
ork
laye
r
Transport Layer 3-15
Reliable data transfer getting started
sendside
receiveside
rdt_send() called from above (eg by app) Passed data to
deliver to receiver upper layer
udt_send() called by rdtto transfer packet over
unreliable channel to receiver
rdt_rcv() called when packet arrives on rcv-side of channel
deliver_data() called by rdt to deliver data to upper
Transport Layer 3-16
Reliable data transfer getting startedWersquoll
incrementally develop sender receiver sides of reliable data transfer protocol (rdt)consider only unidirectional data transfer
but control info will flow on both directionsuse finite state machines (FSM) to specify sender receiver
state1
state2
event causing state transitionactions taken on state transition
state when in this ldquostaterdquo next state
uniquely determined by next event
eventactions
Transport Layer 3-17
Rdt10 reliable transfer over a reliable channel
underlying channel perfectly reliableno bit errorsno loss of packets
separate FSMs for sender receiversender sends data into underlying channelreceiver read data from underlying channel
Wait for call from above packet = make_pkt(data)
udt_send(packet)
rdt_send(data)extract (packetdata)deliver_data(data)
Wait for call from
below
rdt_rcv(packet)
sender receiver
Transport Layer 3-18
Rdt20 channel with bit errors
underlying channel may flip bits in packetrecall checksum to detect bit errors
the question how to recover from errorsacknowledgements (ACKs) receiver explicitly tells sender that pkt received OKnegative acknowledgements (NAKs) receiver explicitly tells sender that pkt had errorssender retransmits pkt on receipt of NAK
new mechanisms in rdt20 (beyond rdt10)error detectionreceiver feedback control msgs (ACKNAK) rcvr-gtsender
Transport Layer 3-19
rdt20 FSM specification
Wait for call from above
snkpkt = make_pkt(data checksum)udt_send(sndpkt)
extract(rcvpktdata)deliver_data(data)udt_send(ACK)
rdt_rcv(rcvpkt) ampamp notcorrupt(rcvpkt)
rdt_rcv(rcvpkt) ampamp isACK(rcvpkt)
udt_send(sndpkt)
rdt_rcv(rcvpkt) ampampisNAK(rcvpkt)
udt_send(NAK)
rdt_rcv(rcvpkt) ampamp corrupt(rcvpkt)
Wait for ACK or
NAK
Wait for call from
belowsender
receiverrdt_send(data)
Λ
Transport Layer 3-20
rdt20 operation with no errors
Wait for call from above
snkpkt = make_pkt(data checksum)udt_send(sndpkt)
extract(rcvpktdata)deliver_data(data)udt_send(ACK)
rdt_rcv(rcvpkt) ampamp notcorrupt(rcvpkt)
rdt_rcv(rcvpkt) ampamp isACK(rcvpkt)
udt_send(sndpkt)
rdt_rcv(rcvpkt) ampampisNAK(rcvpkt)
udt_send(NAK)
rdt_rcv(rcvpkt) ampamp corrupt(rcvpkt)
Wait for ACK or
NAK
Wait for call from
below
rdt_send(data)
Λ
Transport Layer 3-21
rdt20 error scenario
Wait for call from above
snkpkt = make_pkt(data checksum)udt_send(sndpkt)
extract(rcvpktdata)deliver_data(data)udt_send(ACK)
rdt_rcv(rcvpkt) ampamp notcorrupt(rcvpkt)
rdt_rcv(rcvpkt) ampamp isACK(rcvpkt)
udt_send(sndpkt)
rdt_rcv(rcvpkt) ampampisNAK(rcvpkt)
udt_send(NAK)
rdt_rcv(rcvpkt) ampamp corrupt(rcvpkt)
Wait for ACK or
NAK
Wait for call from
below
rdt_send(data)
Λ
Transport Layer 3-22
rdt20 has a fatal flaw
What happens if ACKNAK corruptedsender doesnrsquot know what happened at receivercanrsquot just retransmit possible duplicate
What to dosender ACKsNAKs receiverrsquos ACKNAK What if sender ACKNAK lostretransmit but this might cause retransmission of correctly received pkt
Handling duplicates sender adds sequence number to each pktsender retransmits current pkt if ACKNAK garbledreceiver discards (doesnrsquot deliver up) duplicate pkt
Sender sends one packet then waits for receiver response
stop and wait
Transport Layer 3-23
rdt21 sender handles garbled ACKNAKs
Wait for call 0 from
above
sndpkt = make_pkt(0 data checksum)udt_send(sndpkt)
rdt_send(data)
Wait for ACK or NAK 0 udt_send(sndpkt)
rdt_rcv(rcvpkt) ampamp ( corrupt(rcvpkt) ||isNAK(rcvpkt) )
sndpkt = make_pkt(1 data checksum)udt_send(sndpkt)
rdt_send(data)
rdt_rcv(rcvpkt) ampamp notcorrupt(rcvpkt) ampamp isACK(rcvpkt)
udt_send(sndpkt)
rdt_rcv(rcvpkt) ampamp ( corrupt(rcvpkt) ||isNAK(rcvpkt) )
rdt_rcv(rcvpkt) ampamp notcorrupt(rcvpkt) ampamp isACK(rcvpkt)
Wait forcall 1 from
above
Wait for ACK or NAK 1
ΛΛ
Transport Layer 3-24
rdt21 receiver handles garbled ACKNAKs
Wait for 0 from below
sndpkt = make_pkt(NAK chksum)udt_send(sndpkt)
rdt_rcv(rcvpkt) ampamp not corrupt(rcvpkt) ampamphas_seq0(rcvpkt)
rdt_rcv(rcvpkt) ampamp notcorrupt(rcvpkt) ampamp has_seq1(rcvpkt)
extract(rcvpktdata)deliver_data(data)sndpkt = make_pkt(ACK chksum)udt_send(sndpkt)
Wait for 1 from below
rdt_rcv(rcvpkt) ampamp notcorrupt(rcvpkt) ampamp has_seq0(rcvpkt)
extract(rcvpktdata)deliver_data(data)sndpkt = make_pkt(ACK chksum)udt_send(sndpkt)
rdt_rcv(rcvpkt) ampamp (corrupt(rcvpkt)
sndpkt = make_pkt(ACK chksum)udt_send(sndpkt)
rdt_rcv(rcvpkt) ampamp not corrupt(rcvpkt) ampamphas_seq1(rcvpkt)
rdt_rcv(rcvpkt) ampamp (corrupt(rcvpkt)
sndpkt = make_pkt(ACK chksum)udt_send(sndpkt)
sndpkt = make_pkt(NAK chksum)udt_send(sndpkt)
Transport Layer 3-25
rdt21 discussion
Senderseq added to pkttwo seq rsquos (01) will suffice Whymust check if received ACKNAK corrupted twice as many states
state must ldquorememberrdquowhether ldquocurrentrdquo pkt has 0 or 1 seq
Receivermust check if received packet is duplicate
state indicates whether 0 or 1 is expected pkt seq
note receiver can notknow if its last ACKNAK received OK at sender
Transport Layer 3-26
rdt22 a NAK-free protocol
same functionality as rdt21 using ACKs onlyinstead of NAK receiver sends ACK for last pkt received OK
receiver must explicitly include seq of pkt being ACKed duplicate ACK at sender results in same action as NAK retransmit current pkt
Transport Layer 3-27
rdt22 sender receiver fragments
Wait for call 0 from
above
sndpkt = make_pkt(0 data checksum)udt_send(sndpkt)
rdt_send(data)
udt_send(sndpkt)
rdt_rcv(rcvpkt) ampamp ( corrupt(rcvpkt) ||
isACK(rcvpkt1) )
rdt_rcv(rcvpkt) ampamp notcorrupt(rcvpkt) ampamp isACK(rcvpkt0)
Wait for ACK
0sender FSM
fragment
Wait for 0 from below
rdt_rcv(rcvpkt) ampamp notcorrupt(rcvpkt) ampamp has_seq1(rcvpkt)
extract(rcvpktdata)deliver_data(data)sndpkt = make_pkt(ACK1 chksum)udt_send(sndpkt)
rdt_rcv(rcvpkt) ampamp (corrupt(rcvpkt) ||
has_seq1(rcvpkt))
udt_send(sndpkt)receiver FSM
fragment
Λ
Transport Layer 3-28
rdt30 channels with errors and loss
New assumptionunderlying channel can also lose packets (data or ACKs)
checksum seq ACKs retransmissions will be of help but not enough
Q how to deal with losssender waits until certain data or ACK lost then retransmitsdrawbacks
Approach sender waits ldquoreasonablerdquo amount of time for ACK retransmits if no ACK received in this timeif pkt (or ACK) just delayed (not lost)
retransmission will be duplicate but use of seq rsquos already handles thisreceiver must specify seq of pkt being ACKed
requires countdown timer
Transport Layer 3-29
rdt30 sendersndpkt = make_pkt(0 data checksum)udt_send(sndpkt)start_timer
rdt_send(data)
Wait for
ACK0
rdt_rcv(rcvpkt) ampamp ( corrupt(rcvpkt) ||isACK(rcvpkt1) )
Wait for call 1 from
above
sndpkt = make_pkt(1 data checksum)udt_send(sndpkt)start_timer
rdt_send(data)
rdt_rcv(rcvpkt) ampamp notcorrupt(rcvpkt) ampamp isACK(rcvpkt0)
rdt_rcv(rcvpkt) ampamp ( corrupt(rcvpkt) ||isACK(rcvpkt0) )
rdt_rcv(rcvpkt) ampamp notcorrupt(rcvpkt) ampamp isACK(rcvpkt1)
stop_timerstop_timer
udt_send(sndpkt)start_timer
timeout
udt_send(sndpkt)start_timer
timeout
rdt_rcv(rcvpkt)
Wait for call 0from
above
Wait for
ACK1
Λrdt_rcv(rcvpkt)
ΛΛ
Λ
Transport Layer 3-30
rdt30 in action
Transport Layer 3-31
rdt30 in action
Transport Layer 3-32
Performance of rdt30
rdt30 works but performance stinksexample 1 Gbps link 15 ms e-e prop delay 1KB packet
Ttransmit = 8kbpkt109 bsec = 8 microsec
U sender utilization ndash fraction of time sender busy sending1KB pkt every 30 msec -gt 33kBsec thruput over 1 Gbps linknetwork protocol limits use of physical resources
U sender=
008 30008
= 000027 L RRTT + L R
=
L (packet length in bits)R (transmission rate bps) =
Transport Layer 3-33
rdt30 stop-and-wait operation
first packet bit transmitted t = 0
sender receiver
RTT
last packet bit transmitted t = L R
first packet bit arriveslast packet bit arrives send ACK
ACK arrives send next packet t = RTT + L R
U sender=
00830008
= 000027 L RRTT + L R
=
Transport Layer 3-34
Pipelined protocolsPipelining sender allows multiple ldquoin-flightrdquo yet-to-
be-acknowledged pktsrange of sequence numbers must be increasedbuffering at sender andor receiver
Two generic forms of pipelined protocols go-Back-N selective repeat
Transport Layer 3-35
Pipelining increased utilization
first packet bit transmitted t = 0
sender receiver
RTT
last bit transmitted t = L R
first packet bit arriveslast packet bit arrives send ACK
ACK arrives send next packet t = RTT + L R
last bit of 2nd packet arrives send ACKlast bit of 3rd packet arrives send ACK
U sender=
024 30008
= 000083 L RRTT + L R
=
Increase utilizationby a factor of 3
Transport Layer 3-36
Utilization=N(LR)(RTT+LR) if NLRltRTT+LR Utilization=1 if and the sender pauses after it transmits a window NLRgtRTT+LR and the of packets until it receives first ACK sender does not pause
Transport Layer 3-37
Go-Back-NSender
k-bit seq in pkt headerldquowindowrdquo of up to N consecutive unackrsquoed pkts allowed
ACK(n) ACKs all pkts up to including seq n - ldquocumulative ACKrdquomay receive duplicate ACKs (see receiver)
timer for the entire windowtimeout(n) retransmit pkt n and all higher seq pkts in window
Transport Layer 3-38
GBN sender extended FSM
Wait start_timerudt_send(sndpkt[base])udt_send(sndpkt[base+1])hellipudt_send(sndpkt[nextseqnum-1])
timeout
rdt_send(data)
if (nextseqnum lt base+N) sndpkt[nextseqnum] = make_pkt(nextseqnumdatachksum)udt_send(sndpkt[nextseqnum])if (base == nextseqnum)
start_timernextseqnum++
elserefuse_data(data)
base = getacknum(rcvpkt)+1If (base == nextseqnum)
stop_timerelse
start_timer
rdt_rcv(rcvpkt) ampamp notcorrupt(rcvpkt)
base=1nextseqnum=1
rdt_rcv(rcvpkt) ampamp corrupt(rcvpkt)
Λ
Λ
Transport Layer 3-39
GBN receiver extended FSM
ACK-only always send ACK for correctly-received pktwith highest in-order seq
may generate duplicate ACKsneed only remember expectedseqnum
out-of-order pkt discard (donrsquot buffer) -gt no receiver bufferingRe-ACK pkt with highest in-order seq
Wait
udt_send(sndpkt)default
rdt_rcv(rcvpkt)ampamp notcurrupt(rcvpkt)ampamp hasseqnum(rcvpktexpectedseqnum)
extract(rcvpktdata)deliver_data(data)sndpkt = make_pkt(expectedseqnumACKchksum)udt_send(sndpkt)expectedseqnum++
expectedseqnum=1sndpkt =
make_pkt(0ACKchksum)
Λ
Transport Layer 3-40
GBN inaction
Transport Layer 3-41
Selective Repeat
receiver individually acknowledges all correctly received pkts
buffers pkts as needed for eventual in-order delivery to upper layer
sender only resends pkts for which ACK not received
sender timer for each unACKed pktsender window
N consecutive seq rsquosagain limits seq s of sent unACKed pkts
Transport Layer 3-42
Selective repeat sender receiver windows
Transport Layer 3-43
Selective repeat
data from above if next available seq in window send pkt
timeout(n)resend pkt n restart timer
ACK(n) in [sendbasesendbase+N-1]
mark pkt n as receivedif n smallest unACKed pkt advance window base to next unACKed seq
senderpkt n in [rcvbase rcvbase+N-1]
send ACK(n)out-of-order bufferin-order deliver (also deliver buffered in-order pkts) advance window to next not-yet-received pkt
pkt n in [rcvbase-Nrcvbase-1]
ACK(n)otherwise
ignore
receiver
Transport Layer 3-44
Selective repeat in action
Transport Layer 3-45
Selective repeatdilemma
Example seq rsquos 0 1 2 3window size=3
receiver sees no difference in two scenariosincorrectly passes duplicate data as new in (a)
Q what relationship between seq size and window size
Transport Layer 3-46
Sequence Number vs Window SizeSuppose we use k bits to represent SNQuestion Whatrsquos the minimum number of bits k necessary for a window size of N
sender
receiver
Go-Back-N
expectedSN
snd_base=expectedSN
Q For a given expectedSN whatrsquos the largest possible value for snd_baseA If all the last N ACKs sent by the receiver are received
snd_base = expectedSNexpectedSN+N-1
senderrsquos window
Transport Layer 3-47
Sequence Number vs Window SizeSuppose we use k bits to represent SNQuestion Whatrsquos the minimum number of bits k necessary for a window size of N
sender
receiver
Go-Back-N
expectedSN
snd_base=expectedSN-N
Q For a given expectedSN whatrsquos the smallest possible value for snd_baseA If all the last N ACKs sent by the receiver are not received
snd_base = expectedSN-NexpectedSN-1
senderrsquos window
Transport Layer 3-48
Sequence Number vs Window Size
sender
receiver
Go-Back-N
expectedSN
snd_base=expectedSN-N
All SNs in the interval [expectedSN-NexpectedSN+N-1] (an interval of size 2N) can be received by the receiver Since the receiver accepts on the packet with SN=expectedSN there should be no other packet within this interval with SN=expectedSN Therefore
2k ge N+1expectedSN+N-1
Transport Layer 3-49
Sequence Number vs Window SizeSuppose we use k bits to represent SNQuestion Whatrsquos the minimum number of bits k necessary for a window size of N
sender
receiver
Selective Repeat
rcv_base
snd_base=rcv_base
Q For a given rcv_base whatrsquos the largest possible value for snd_baseA If all the last N ACKs sent by the receiver are received
snd_base = rcv_base (same as go_back-N)rcv_base+N-1
senderrsquos window
receiverrsquos window
rcv_base+N-1
Transport Layer 3-50
Sequence Number vs Window SizeSuppose we use k bits to represent SNQuestion Whatrsquos the minimum number of bits k necessary for a window size of N
sender
receiver
Selective Repeat
rcv_base
snd_base=rcv_base-N
Q For a given rcv_base whatrsquos the smallest possible value for snd_baseA If all the last N ACKs sent by the receiver are not received
snd_base = rcv_base-N (same as Go-Back-N)rcv_base-1
senderrsquos window
rcv_base
receiverrsquos window
rcv_base+N-1
Transport Layer 3-51
Sequence Number vs Window Size
sender
receiver
Selective Repeat
snd_base=rcv_base-N
All SNs in the interval [rcv_base-Nrcv_base+N-1] (an interval of size 2N) can be received by the receiver Since the receiver should be able to distinguish between all packets in this interval and take corresponding action there should be no two packets within thisinterval having the same SN Therefore
2k ge 2Nrcv_base+N-1
rcv_basercv_base
receiverrsquos window
rcv_base+N-1
Transport Layer 3-52
TCP Overview RFCs 793 1122 1323 2018 2581
full duplex databi-directional data flow in same connectionMSS maximum segment size
connection-orientedhandshaking (exchange of control msgs) initrsquossender receiver state before data exchange
flow controlledsender will not overwhelm receiver
point-to-pointone sender one receiver
reliable in-order byte stream
no ldquomessage boundariesrdquopipelined
TCP congestion and flow control set window size
send amp receive buffers
socketdoor
TCPsend buffer
TCPreceive buffer
socketdoor
segment
applicationwrites data
applicationreads data
Transport Layer 3-53
TCP segment structure
source port dest port
32 bits
applicationdata
(variable length)
sequence numberacknowledgement number
Receive windowUrg data pnterchecksum
FSRPAUheadlen
notused
Options (variable length)
URG urgent data (generally not used)
ACK ACK valid
PSH push data now(generally not used)
RST SYN FINconnection estab(setup teardown
commands)
bytes rcvr willingto accept
Internetchecksum
(as in UDP)
countingby bytes of data(not segments)
Transport Layer 3-54
TCP seq rsquos and ACKsSeq rsquos
byte stream ldquonumberrdquo of first byte in segmentrsquos dataACKs
seq of next byte expected from other sidecumulative ACK
Q how receiver handles out-of-order segmentsA TCP spec doesnrsquot say - up to implementationWidely used implementations of TCP buffer out-of-order segments
Transport Layer 3-55
TCP Round Trip Time and Timeout
Q how to set TCP timeout valuelonger than RTT
but RTT variestoo short premature timeout
unnecessary retransmissions
too long slow reaction to segment loss
Q how to estimate RTTSampleRTT measured time from segment transmission until ACK receipt
ignore retransmissionsSampleRTT will vary want estimated RTT ldquosmootherrdquo
average several recent measurements not just current SampleRTT
Transport Layer 3-56
TCP Round Trip Time and Timeout
EstimatedRTT = (1- α)EstimatedRTT + αSampleRTT
Exponential weighted moving averageinfluence of past sample decreases exponentially fasttypical value α = 0125
Transport Layer 3-57
Example RTT estimationRTT gaiacsumassedu to fantasiaeurecomfr
100
150
200
250
300
350
1 8 15 22 29 36 43 50 57 64 71 78 85 92 99 106
time (seconnds)
RTT
(mill
iseco
nds)
SampleRTT Estimated RTT
Transport Layer 3-58
TCP Round Trip Time and TimeoutSetting the timeout
EstimatedRTT plus ldquosafety marginrdquolarge variation in EstimatedRTT -gt larger safety margin
first estimate of how much SampleRTT deviates from EstimatedRTT
TimeoutInterval = EstimatedRTT + 4DevRTT
DevRTT = (1-β)DevRTT +β|SampleRTT-EstimatedRTT|
(typically β = 025)
Then set timeout interval
Transport Layer 3-59
TCP reliable data transfer
TCP creates rdtservice on top of IPrsquos unreliable servicePipelined segmentsCumulative acksTCP uses single retransmission timer however it just retransmits the first segment in the window
Retransmissions are triggered by
timeout eventsduplicate acks
Initially consider simplified TCP sender
ignore duplicate acksignore flow control congestion control
Transport Layer 3-60
TCP sender eventsdata rcvd from app
Create segment with seq seq is byte-stream number of first data byte in segmentstart timer if not already running (think of timer as for oldest unacked segment)expiration interval TimeOutInterval
timeoutretransmit segment that caused timeout (first segment in the window)restart timer
Ack rcvdIf acknowledges previously unacked segments
update what is known to be ackedstart timer if there are outstanding segments
Transport Layer 3-61
TCP sender(simplified)
NextSeqNum = InitialSeqNumSendBase = InitialSeqNum
loop (forever) switch(event)
event data received from application above create TCP segment with sequence number NextSeqNumif (timer currently not running)
start timerpass segment to IP NextSeqNum = NextSeqNum + length(data)
event timer timeoutretransmit not-yet-acknowledged segment with
smallest sequence numberstart timer
event ACK received with ACK field value of y if (y gt SendBase)
SendBase = yif (there are currently not-yet-acknowledged segments)
start timer
end of loop forever
Commentbull SendBase-1 last cumulatively ackrsquoed byteExamplebull SendBase-1 = 71y= 73 so the rcvrwants 73+ y gt SendBase sothat new data is acked
Transport Layer 3-62
TCP retransmission scenariosHost A
Seq=100 20 bytes data
ACK=100
timepremature timeout
Host B
Seq=92 8 bytes data
ACK=120
Seq=92 8 bytes data
Seq=
92 t
imeo
ut
ACK=120
Host A
Seq=92 8 bytes data
ACK=100
loss
tim
eout
lost ACK scenario
Host B
X
Seq=92 8 bytes data
ACK=100
time
Seq=
92 t
imeo
utSendBase
= 100
SendBase= 120
SendBase= 120
Sendbase= 100
Transport Layer 3-63
TCP retransmission scenarios (more)Host A
Seq=92 8 bytes data
ACK=100
loss
tim
eout
Cumulative ACK scenario
Host B
X
Seq=100 20 bytes data
ACK=120
time
SendBase= 120
Transport Layer 3-64
TCP ACK generation [RFC 1122 RFC 2581]
Event at Receiver
Arrival of in-order segment withexpected seq All data up toexpected seq already ACKed
Arrival of in-order segment withexpected seq One other segment has ACK pending
Arrival of out-of-order segmenthigher-than-expect seq Gap detected
Arrival of segment that partially or completely fills gap
TCP Receiver action
Delayed ACK Wait up to 500msfor next segment If no next segmentsend ACK
Immediately send single cumulative ACK ACKing both in-order segments
Immediately send duplicate ACK indicating seq of next expected byte
Immediate send ACK provided thatsegment startsat lower end of gap
Transport Layer 3-65
Fast Retransmit
Time-out period often relatively long
long delay before resending lost packet
Detect lost segments via duplicate ACKs
Sender often sends many segments back-to-backIf segment is lost there will likely be many duplicate ACKs
If sender receives 3 ACKs for the same data it supposes that segment after ACKeddata was lost
fast retransmit resend segment before timer expires
Transport Layer 3-66
Fast RetransmitResend a segment after 3 duplicate ACKs since a duplicate ACK means that an out-of sequence segment was receivedduplicate ACKs due to packet reorderingif window is small donrsquot get duplicate ACKs
Host A
tim
eout
Host B
time
X
resend seq X2
seq x1seq x2seq x3seq x4seq x5
ACK x1
ACK x1ACK x1ACK x1
tripleduplicate
ACKs
Transport Layer 3-67
event ACK received with ACK field value of y if (y gt SendBase)
SendBase = yif (there are currently not-yet-acknowledged segments)
start timer
else increment count of dup ACKs received for yif (count of dup ACKs received for y = 3)
resend segment with sequence number y
Fast retransmit algorithm
a duplicate ACK for already ACKed segment
fast retransmit
Transport Layer 3-68
TCP Flow Control
receive side of TCP connection has a receive buffer
speed-matching service matching the send rate to the receiving apprsquos drain rate
app process may be slow at reading from buffer
sender wonrsquot overflowreceiverrsquos buffer by
transmitting too muchtoo fast
flow control
Transport Layer 3-69
TCP Flow control how it works
(Suppose TCP receiver discards out-of-order segments)spare room in buffer
= RcvWin
= RcvBuffer-[LastByteRcvd -LastByteRead]
Rcvr advertises spare room by including value of RcvWin in segmentsSender limits unACKeddata to RcvWin
guarantees receive buffer doesnrsquot overflow
Transport Layer 3-70
Sliding Window Flow Control Example
3K
2K SeqNo=0
ReceiverBuffer
0 4KSendersends 2Kof data
2K
AckNo=2048 RcvWin=2048Sendersends 2Kof data 2K SeqNo=2048
4K
AckNo=4096 RcvWin=0
AckNo=4096 RcvWin=1024
Sender blocked
Transport Layer 3-71
Principles of Congestion Control
Congestioninformally ldquotoo many sources sending too much data too fast for network to handlerdquodifferent from flow controlmanifestations
lost packets (buffer overflow at routers)long delays (queueing in router buffers)
a top-10 problem
Transport Layer 3-72
Causescosts of congestion scenario 1
two senders two receiversone router infinite buffers no retransmission
large delays when congestedmaximum achievable throughput
unlimited shared output link buffers
Host Aλin original data
Host B
λout
Transport Layer 3-73
Causescosts of congestion scenario 2
one router finite buffers sender retransmission of lost packet
finite shared output link buffers
Host A λin original data
Host B
λout
λin original data plus retransmitted data
Transport Layer 3-74
Causescosts of congestion scenario 2always (goodput)ldquoperfectrdquo retransmission only when loss
retransmission of delayed (not lost) packet makes larger(than perfect case) for same
λin
λout=
λin
λoutgtλ
inλout
ldquocostsrdquo of congestionmore work (retrans) for given ldquogoodputrdquounneeded retransmissions link carries multiple copies of pkt
R2
R2λin
λ out
b
R2
R2λin
λ out
a
R2
R2λin
λ out
c
R4
R3
Transport Layer 3-75
Causescosts of congestion scenario 3four sendersmultihop pathstimeoutretransmit
λin
Q what happens as and increase λ
in
finite shared output link buffers
Host Aλin original data
Host B
λout
λin original data plus retransmitted data
Transport Layer 3-76
Causescosts of congestion scenario 3
another ldquocostrdquo of congestionwhen packet dropped any ldquoupstream transmission capacity used for that packet was wasted
Host A
Host B
λou
t
Transport Layer 3-77
Approaches towards congestion control
End-end congestion controlno explicit feedback from networkcongestion inferred from end-system observed loss delayapproach taken by TCP
Network-assisted congestion controlrouters provide feedback to end systems
single bit indicating congestion (SNA DECbit TCPIP ECN ATM)explicit rate sender should send at
Two broad approaches towards congestion control
Transport Layer 3-78
TCP Congestion Control
end-end control (no network assistance)sender limits transmissionLastByteSent-LastByteAcked
le CongWin
CongWin is dynamic function of perceived network congestion
How does sender perceive congestionloss event = timeout or3 duplicate acksTCP sender reduces rate (CongWin) after loss event
two modes of operationSlow Start (SS)Congestion avoidance (CA) or Additive Increase Multiplicative Decrease (AIMD)
Transport Layer 3-79
TCP congestion control bandwidth probing
ldquoprobing for bandwidthrdquo increase transmission rate on receipt of ACK until eventually loss occurs then decrease transmission rate
continue to increase on ACK decrease on loss (since available bandwidth is changing depending on other connections in network)
ACKs being received so increase rate
X
X
XX
X loss so decrease rate
send
ing
rate
time
Q how fast to increasedecreasedetails to follow
TCPrsquosldquosawtoothrdquobehavior
Transport Layer 3-80
TCP Congestion Control details
sender limits rate by limiting number of unACKed bytes ldquoin pipelinerdquo
cwnd differs from rwnd (how why)sender limited by min(cwndrwnd)
roughly
cwnd is dynamic function of perceived network congestion
rate = cwndRTT bytessec
LastByteSent-LastByteAcked le cwnd
cwndbytes
RTT
ACK(s)
Transport Layer 3-81
TCP Congestion Control more details
segment loss event reducing cwndtimeout no response from receiver
cut cwnd to 13 duplicate ACKs at least some segments getting through (recall fast retransmit)
cut cwnd in half less aggressively than on timeout
ACK received increase cwndTwo modes of operation
slowstart phase bull increase exponentially
fast (despite name) at connection start or following timeout
congestion avoidance bull increase linearly
Transport Layer 3-82
TCP Slow Start Phasewhen connection begins cwnd = 1 MSS
example MSS = 500 bytes amp RTT = 200 msecinitial rate = 20 kbps
available bandwidth may be gtgt MSSRTT
desirable to quickly ramp up to respectable rate
increase rate exponentially until first loss event or when threshold reached
double cwnd every RTTdone by incrementing cwnd by 1 for every ACK received
Host A
one segment
RTT
Host B
time
two segments
four segments
Transport Layer 3-83
Slow Start ExampleThe congestion window size grows very rapidly
For every ACK we increase CongWin by 1 irrespective of the number of segments ACKrsquoeddouble CongWinevery RTTinitial rate is slow but ramps up exponentially fast
TCP slows down the increase of CongWinwhen CongWin gt ssthresh
segment 1
ACK for segment 1
cwnd = 1
cwnd = 2 segment 2segment 3
ACK for segments 2
cwnd = 4 segment 4segment 5segment 6
ACK for segments 4
cwnd = 7
ACK for segments 3
ACK for segments 5
ACK for segments 6
cwnd = 3
cwnd = 5
cwnd = 6ACK for segments 7
cwnd = 8
segment 7
Transport Layer 3-84
TCP Congestion Avoidance Phase
when cwnd gt ssthreshgrow cwnd linearly
increase cwnd by 1 MSS per RTT approach possible congestion slower than in slowstartimplementation cwnd= cwnd + MSScwndfor each ACK received
ACKs increase cwndby 1 MSS per RTT additive increaseloss cut cwnd in half (non-timeout-detected loss ) multiplicative decrease
AIMD
AIMD Additive IncreaseMultiplicative Decrease
Transport Layer 3-85
Congestion AvoidanceCongestion avoidance phase is started if CongWin has reached the slow-start threshold value
If CongWin gt= ssthresh then each time an ACK is received increment CongWin as follows
bull CongWin = CongWin + 1CongWin (CongWin in segments)
bull In actual TCP implementation CongWin is in BytesCongWin = CongWin + MSS (MSSCongWin)
So CongWin is increased by one only if all CongWinsegments have been acknowledged
Transport Layer 3-86
Example Slow StartCongestion AvoidanceAssume that
ssthresh = 8
cwnd = 1
cwnd = 2
cwnd = 4
cwnd = 8
cwnd = 9
cwnd = 10
02468
101214
t=0
t=2
t=4
t=6
Roundtrip times
Cw
nd(in
seg
men
ts)
ssthresh
cwnd = 3
cwnd = 5cwnd = 6cwnd = 7
Transport Layer 3-87
Slow Start Congestion AvoidanceA typical plot of CongWin for a TCP connection
(MSS = 1500 bytes) with TCP Tahoe
SS
CA
ssthresh
Transport Layer 3-88
Responses to CongestionTCP assumes there is congestion if it detects a packet lossA TCP sender can detect lost packets via loss events
bull Timeout of a retransmission timerbull Receipt of 3 duplicate ACKs (fast retransmit)
TCP interprets a Timeout as a binary congestion signal When a timeout occurs the sender performs
ssthresh is set to half the current size of the congestion window
ssthresh = CongWin 2CongWin is reset to one
CongWin = 1and slow-start is entered
Transport Layer 3-89
Fast Recovery (differentiation btwn two loss events) After 3 dup ACKs (fast Retransmit)
ssthresh = CongWin2CongWin = CongWin2window then grows linearly
But after timeout eventCongWin = 1 MSS window then grows exponentiallyto the threshold then grows linearly
bull 3 dup ACKs indicates network capable of delivering some segmentsbull timeout before 3 dup ACKs is ldquomore alarmingrdquo
Philosophy
3-90
TCP Congestion ControlInitially
CongWin = 1ssthresh = advertised window size
New Ack receivedif (CongWin lt ssthresh) Slow Start
CongWin = CongWin + 1else Congestion Avoidance
CongWin = CongWin + 1CongWinTimeout
ssthresh = CongWin2CongWin = 1
Fast Retransmissionssthresh = CongWin2CongWin = CongWin2
Slow Start (exponential increase phase) is continued until CongWin reaches half of the level where the loss event occurred last time CongWin is increased slowly after (linear increase in Congestion Avoidance phase)
Transport Layer 3-91
Popular ldquoflavorsrdquo of TCP
ssthresh
ssthresh
TCP Tahoe
TCP Reno
Transmission round
cwnd
win
dow
siz
e (in
seg
men
ts)
Transport Layer 3-92
Summary TCP Congestion ControlWhen CongWin is below Threshold sender in slow-start phase window grows exponentiallyWhen CongWin is above Threshold sender is in congestion-avoidance phase window grows linearlyWhen a triple duplicate ACK occurs Threshold set to CongWin2 and CongWin set to ThresholdWhen timeout occurs Threshold set to CongWin2 and CongWin is set to 1 MSS The actual sender window size is determined based on the congestion and flow control algorithms
SenderWin=min(RcvWinCongWin)
Transport Layer 3-93
TCP Congestion Control SummaryEvent State TCP Sender Action Commentary
ACK receipt for previously unackeddata
Slow Start (SS)
CongWin = CongWin + MSS If (CongWin gt Threshold)
set state to ldquoCongestion Avoidancerdquo
Resulting in a doubling of CongWin every RTT
ACK receipt for previously unackeddata
CongestionAvoidance (CA)
CongWin = CongWin+MSS (MSSCongWin)
Additive increase resulting in increase of CongWin by 1 MSS every RTT
Loss event detected by triple duplicate ACK
SS or CA Threshold = CongWin2 CongWin = ThresholdSet state to ldquoCongestion Avoidancerdquo
Fast recovery implementing multiplicative decrease CongWin will not drop below 1 MSS
Timeout SS or CA Threshold = CongWin2 CongWin = 1 MSSSet state to ldquoSlow Startrdquo
Enter slow start
Duplicate ACK
SS or CA Increment duplicate ACK count for segment being acked
CongWin and Threshold not changed
Transport Layer 3-94
TCP throughput
Q whatrsquos average throughout of TCP as function of window size RTT
ignoring slow startlet W be window size when loss occurs
when window is W throughput is WRTTjust after loss window drops to W2 throughput to W2RTT average throughout 75 WRTT
Transport Layer 3-95
TCP Futures TCP over ldquolong fat pipesrdquo
example 1500 byte segments 100ms RTT want 10 Gbps throughputrequires window size W = 83333 in-flight segmentsthroughput in terms of loss rate
L = 210-10 Wownew versions of TCP for high-speed
LRTTMSSsdot221
Transport Layer 3-96
Fairness goal if K TCP sessions share same bottleneck link of bandwidth R each should have average rate of RK
TCP connection 1
bottleneckrouter
capacity R
TCP connection 2
TCP Fairness
Transport Layer 3-97
Why is TCP fairTwo competing sessions
Additive increase gives slope of 1 as throughout increasesmultiplicative decrease decreases throughput proportionally
R
R
equal bandwidth share
Connection 1 throughput
Conn
ecti
on 2
thr
ough
p ut
congestion avoidance additive increaseloss decrease window by factor of 2
congestion avoidance additive increaseloss decrease window by factor of 2
Transport Layer 3-98
Fairness (more)Fairness and UDP
Multimedia apps often do not use TCP
do not want rate throttled by congestion control
Instead use UDPpump audiovideo at constant rate tolerate packet loss
Research area TCP friendly
Fairness and parallel TCP connectionsnothing prevents app from opening parallel cnctionsbetween 2 hostsWeb browsers do this Example link of rate R supporting 9 cnctions
new app asks for 1 TCP gets rate R10new app asks for 11 TCPs gets R2
Transport Layer 3-99
TCP Connection ManagementRecall TCP sender receiver
establish ldquoconnectionrdquobefore exchanging data segmentsinitialize TCP variables
seq sbuffers flow control info (eg RcvWindow)
client connection initiatorSocket clientSocket = new Socket(hostnameport
number)
server contacted by clientSocket connectionSocket = welcomeSocketaccept()
Three way handshakeStep 1 client host sends TCP
SYN segment to serverspecifies initial seq no data
Step 2 server host receives SYN replies with SYNACK segment
server allocates buffersspecifies server initial seq
Step 3 client receives SYNACK replies with ACK segment which may contain data
Transport Layer 3-100
TCP Connection Management (cont)
Closing a connection
client closes socketclientSocketclose()
Step 1 client end system sends TCP FIN control segment to server
Step 2 server receives FIN replies with ACK Closes connection sends FIN
client
FIN
server
ACK
ACK
FIN
close
close
closed
tim
ed w
ait
Transport Layer 3-101
TCP Connection Management (cont)
Step 3 client receives FIN replies with ACK
Enters ldquotimed waitrdquo -will respond with ACK to received FINs
Step 4 server receives ACK Connection closed
client
FIN
server
ACK
ACK
FIN
closing
closing
closed
tim
ed w
ait
closed
Transport Layer 3-102
TCP Connection Management (cont)
TCP clientlifecycle
TCP serverlifecycle
Transport Layer 3-103
Tuning TCPIP Parameters TCPIP parameters
A set of default values may not be optimal for all applicationsThe network administrator may wish to turn on or off some TCPIP functions for performance or security considerations
Many Unix and Linux systems provide some flexibility in tuning the TCPIP kernelsbinsysctl is used to configure the Linux kernel parameters at runtime
Default kernel configuration file is sbinsysctlconfFrequently used sysctl options
bull sysctl ndasha or sysctl ndashA list all current valuesbull sysctl ndashp file_name load the sysctl setting from a configuration
filebull sysctl ndashw variable=value change the value of the parameter
Transport Layer 3-104
SomeTCP Parameters in Linux Kerneltcp_syn_retries
Number of SYN packets the kernel will send before giving up on the new connection
tcp_synack_retriesnumber of SYN+ACK packets sent before the kernel gives up on the connection
tcp_window_scalingMaximum window size of 65535 bytes not enough for for really fast networks The window scaling options allows for almost gigabyte windows which is good for connections with large delay-bandwidth product
tcp_max_syn_backlogMaximal number of remembered connection requests which still did not receive an acknowledgment from connecting client
tcp_fin_timeoutHow many seconds to wait for a final FIN packet before the socket is closed required to prevent denial-of-service (DoS) attacks Default value is 60 seconds
Transport Layer 3-105
SomeTCP Parameters in Linux Kerneltcp_rmem
This is a vector of 3 integers [min default max] These parameters are used by TCP to dynamically adjust receive buffer sizesmin - minimum size of the receive buffer used by each TCP socket The default value is 4K default - the default size of the receive buffer for a TCP socket The default value is 87380 bytes and is lowered to 43689 in low memory systems If larger receive buffer sizes are desired this value should be increased max - the maximum size of the receive buffer used by each TCP socket The default value of 873802 bytes is lowered to 87380 in low memory systems
tcp_smemSend buffer parameters [min default max] similar to tcp_rmem
- Chapter 3 Transport Layer
- Transport services and protocols
- Transport vs network layer
- Internet transport-layer protocols
- Multiplexingdemultiplexing
- How demultiplexing works
- Connectionless demultiplexing
- Connection-oriented demux
- Connection-oriented demux (cont)
- Connection-oriented demux Threaded Web Server
- UDP User Datagram Protocol [RFC 768]
- UDP more
- UDP checksum
- Principles of Reliable data transfer
- Reliable data transfer getting started
- Reliable data transfer getting started
- Rdt10 reliable transfer over a reliable channel
- Rdt20 channel with bit errors
- rdt20 FSM specification
- rdt20 operation with no errors
- rdt20 error scenario
- rdt20 has a fatal flaw
- rdt21 sender handles garbled ACKNAKs
- rdt21 receiver handles garbled ACKNAKs
- rdt21 discussion
- rdt22 a NAK-free protocol
- rdt22 sender receiver fragments
- rdt30 channels with errors and loss
- rdt30 sender
- rdt30 in action
- rdt30 in action
- Performance of rdt30
- rdt30 stop-and-wait operation
- Pipelined protocols
- Pipelining increased utilization
- Go-Back-N
- GBN sender extended FSM
- GBN receiver extended FSM
- GBN inaction
- Selective Repeat
- Selective repeat sender receiver windows
- Selective repeat
- Selective repeat in action
- Selective repeat dilemma
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- TCP Overview RFCs 793 1122 1323 2018 2581
- TCP segment structure
- TCP seq rsquos and ACKs
- TCP Round Trip Time and Timeout
- TCP Round Trip Time and Timeout
- Example RTT estimation
- TCP Round Trip Time and Timeout
- TCP reliable data transfer
- TCP sender events
- TCP sender(simplified)
- TCP retransmission scenarios
- TCP retransmission scenarios (more)
- TCP ACK generation [RFC 1122 RFC 2581]
- Fast Retransmit
- Fast Retransmit
- Fast retransmit algorithm
- TCP Flow Control
- TCP Flow control how it works
- Sliding Window Flow Control Example
- Principles of Congestion Control
- Causescosts of congestion scenario 1
- Causescosts of congestion scenario 2
- Causescosts of congestion scenario 2
- Causescosts of congestion scenario 3
- Causescosts of congestion scenario 3
- Approaches towards congestion control
- TCP Congestion Control
- TCP congestion control bandwidth probing
- TCP Congestion Control details
- TCP Congestion Control more details
- TCP Slow Start Phase
- Slow Start Example
- TCP Congestion Avoidance Phase
- Congestion Avoidance
- Example Slow StartCongestion Avoidance
- Slow Start Congestion Avoidance
- Responses to Congestion
- Fast Recovery (differentiation btwn two loss events)
- TCP Congestion Control
- Popular ldquoflavorsrdquo of TCP
- Summary TCP Congestion Control
- TCP Congestion Control Summary
- TCP throughput
- TCP Futures TCP over ldquolong fat pipesrdquo
- TCP Fairness
- Why is TCP fair
- Fairness (more)
- TCP Connection Management
- TCP Connection Management (cont)
- TCP Connection Management (cont)
- TCP Connection Management (cont)
- Tuning TCPIP Parameters
- SomeTCP Parameters in Linux Kernel
- SomeTCP Parameters in Linux Kernel
-
Transport Layer 3-9
Connection-oriented demux(cont)
ClientIPB
P1
clientIP A
P1P2P4
serverIP C
SP 9157DP 80
SP 9157DP 80
P5 P6 P3
D-IPCS-IP AD-IPC
S-IP B
SP 5775DP 80
D-IPCS-IP B
Transport Layer 3-10
Connection-oriented demuxThreaded Web Server
ClientIPB
P1
clientIP A
P1P2P4
serverIP C
SP 9157DP 80
SP 9157DP 80
P5 P6 P3
D-IPCS-IP AD-IPC
S-IP B
SP 5775DP 80
D-IPCS-IP B
P4
Transport Layer 3-11
UDP User Datagram Protocol [RFC 768]
ldquono frillsrdquo ldquobare bonesrdquoInternet transport protocolldquobest effortrdquo service UDP segments may be
lostdelivered out of order to app
connectionlessno handshaking between UDP sender receivereach UDP segment handled independently of others
Why is there a UDPno connection establishment (which can add delay)simple no connection state at sender receiversmall segment headerno congestion control UDP can blast away as fast as desired
Transport Layer 3-12
UDP moreoften used for streaming multimedia apps
loss tolerantrate sensitive
other UDP usesDNSSNMP
reliable transfer over UDP add reliability at application layer
application-specific error recovery
source port dest port
32 bits
Applicationdata
(message)
UDP segment format
length checksumLength in
bytes of UDPsegmentincluding
header
Transport Layer 3-13
UDP checksum
Sendertreat segment contents as sequence of 16-bit integerschecksum addition (1rsquos complement sum) of segment contents with wraparound of carry out bitsender puts checksum value into UDP checksum field
Receivercompute checksum of received segmentcheck if computed checksum equals checksum field value
NO - error detectedYES - no error detected
Goal detect ldquoerrorsrdquo (eg flipped bits) in transmitted segment
Transport Layer 3-14
Principles of Reliable data transferimportant in app transport link layerstop-10 list of important networking topics
characteristics of unreliable channel will determine complexity of reliable data transfer protocol (rdt)
netw
ork
laye
r
Transport Layer 3-15
Reliable data transfer getting started
sendside
receiveside
rdt_send() called from above (eg by app) Passed data to
deliver to receiver upper layer
udt_send() called by rdtto transfer packet over
unreliable channel to receiver
rdt_rcv() called when packet arrives on rcv-side of channel
deliver_data() called by rdt to deliver data to upper
Transport Layer 3-16
Reliable data transfer getting startedWersquoll
incrementally develop sender receiver sides of reliable data transfer protocol (rdt)consider only unidirectional data transfer
but control info will flow on both directionsuse finite state machines (FSM) to specify sender receiver
state1
state2
event causing state transitionactions taken on state transition
state when in this ldquostaterdquo next state
uniquely determined by next event
eventactions
Transport Layer 3-17
Rdt10 reliable transfer over a reliable channel
underlying channel perfectly reliableno bit errorsno loss of packets
separate FSMs for sender receiversender sends data into underlying channelreceiver read data from underlying channel
Wait for call from above packet = make_pkt(data)
udt_send(packet)
rdt_send(data)extract (packetdata)deliver_data(data)
Wait for call from
below
rdt_rcv(packet)
sender receiver
Transport Layer 3-18
Rdt20 channel with bit errors
underlying channel may flip bits in packetrecall checksum to detect bit errors
the question how to recover from errorsacknowledgements (ACKs) receiver explicitly tells sender that pkt received OKnegative acknowledgements (NAKs) receiver explicitly tells sender that pkt had errorssender retransmits pkt on receipt of NAK
new mechanisms in rdt20 (beyond rdt10)error detectionreceiver feedback control msgs (ACKNAK) rcvr-gtsender
Transport Layer 3-19
rdt20 FSM specification
Wait for call from above
snkpkt = make_pkt(data checksum)udt_send(sndpkt)
extract(rcvpktdata)deliver_data(data)udt_send(ACK)
rdt_rcv(rcvpkt) ampamp notcorrupt(rcvpkt)
rdt_rcv(rcvpkt) ampamp isACK(rcvpkt)
udt_send(sndpkt)
rdt_rcv(rcvpkt) ampampisNAK(rcvpkt)
udt_send(NAK)
rdt_rcv(rcvpkt) ampamp corrupt(rcvpkt)
Wait for ACK or
NAK
Wait for call from
belowsender
receiverrdt_send(data)
Λ
Transport Layer 3-20
rdt20 operation with no errors
Wait for call from above
snkpkt = make_pkt(data checksum)udt_send(sndpkt)
extract(rcvpktdata)deliver_data(data)udt_send(ACK)
rdt_rcv(rcvpkt) ampamp notcorrupt(rcvpkt)
rdt_rcv(rcvpkt) ampamp isACK(rcvpkt)
udt_send(sndpkt)
rdt_rcv(rcvpkt) ampampisNAK(rcvpkt)
udt_send(NAK)
rdt_rcv(rcvpkt) ampamp corrupt(rcvpkt)
Wait for ACK or
NAK
Wait for call from
below
rdt_send(data)
Λ
Transport Layer 3-21
rdt20 error scenario
Wait for call from above
snkpkt = make_pkt(data checksum)udt_send(sndpkt)
extract(rcvpktdata)deliver_data(data)udt_send(ACK)
rdt_rcv(rcvpkt) ampamp notcorrupt(rcvpkt)
rdt_rcv(rcvpkt) ampamp isACK(rcvpkt)
udt_send(sndpkt)
rdt_rcv(rcvpkt) ampampisNAK(rcvpkt)
udt_send(NAK)
rdt_rcv(rcvpkt) ampamp corrupt(rcvpkt)
Wait for ACK or
NAK
Wait for call from
below
rdt_send(data)
Λ
Transport Layer 3-22
rdt20 has a fatal flaw
What happens if ACKNAK corruptedsender doesnrsquot know what happened at receivercanrsquot just retransmit possible duplicate
What to dosender ACKsNAKs receiverrsquos ACKNAK What if sender ACKNAK lostretransmit but this might cause retransmission of correctly received pkt
Handling duplicates sender adds sequence number to each pktsender retransmits current pkt if ACKNAK garbledreceiver discards (doesnrsquot deliver up) duplicate pkt
Sender sends one packet then waits for receiver response
stop and wait
Transport Layer 3-23
rdt21 sender handles garbled ACKNAKs
Wait for call 0 from
above
sndpkt = make_pkt(0 data checksum)udt_send(sndpkt)
rdt_send(data)
Wait for ACK or NAK 0 udt_send(sndpkt)
rdt_rcv(rcvpkt) ampamp ( corrupt(rcvpkt) ||isNAK(rcvpkt) )
sndpkt = make_pkt(1 data checksum)udt_send(sndpkt)
rdt_send(data)
rdt_rcv(rcvpkt) ampamp notcorrupt(rcvpkt) ampamp isACK(rcvpkt)
udt_send(sndpkt)
rdt_rcv(rcvpkt) ampamp ( corrupt(rcvpkt) ||isNAK(rcvpkt) )
rdt_rcv(rcvpkt) ampamp notcorrupt(rcvpkt) ampamp isACK(rcvpkt)
Wait forcall 1 from
above
Wait for ACK or NAK 1
ΛΛ
Transport Layer 3-24
rdt21 receiver handles garbled ACKNAKs
Wait for 0 from below
sndpkt = make_pkt(NAK chksum)udt_send(sndpkt)
rdt_rcv(rcvpkt) ampamp not corrupt(rcvpkt) ampamphas_seq0(rcvpkt)
rdt_rcv(rcvpkt) ampamp notcorrupt(rcvpkt) ampamp has_seq1(rcvpkt)
extract(rcvpktdata)deliver_data(data)sndpkt = make_pkt(ACK chksum)udt_send(sndpkt)
Wait for 1 from below
rdt_rcv(rcvpkt) ampamp notcorrupt(rcvpkt) ampamp has_seq0(rcvpkt)
extract(rcvpktdata)deliver_data(data)sndpkt = make_pkt(ACK chksum)udt_send(sndpkt)
rdt_rcv(rcvpkt) ampamp (corrupt(rcvpkt)
sndpkt = make_pkt(ACK chksum)udt_send(sndpkt)
rdt_rcv(rcvpkt) ampamp not corrupt(rcvpkt) ampamphas_seq1(rcvpkt)
rdt_rcv(rcvpkt) ampamp (corrupt(rcvpkt)
sndpkt = make_pkt(ACK chksum)udt_send(sndpkt)
sndpkt = make_pkt(NAK chksum)udt_send(sndpkt)
Transport Layer 3-25
rdt21 discussion
Senderseq added to pkttwo seq rsquos (01) will suffice Whymust check if received ACKNAK corrupted twice as many states
state must ldquorememberrdquowhether ldquocurrentrdquo pkt has 0 or 1 seq
Receivermust check if received packet is duplicate
state indicates whether 0 or 1 is expected pkt seq
note receiver can notknow if its last ACKNAK received OK at sender
Transport Layer 3-26
rdt22 a NAK-free protocol
same functionality as rdt21 using ACKs onlyinstead of NAK receiver sends ACK for last pkt received OK
receiver must explicitly include seq of pkt being ACKed duplicate ACK at sender results in same action as NAK retransmit current pkt
Transport Layer 3-27
rdt22 sender receiver fragments
Wait for call 0 from
above
sndpkt = make_pkt(0 data checksum)udt_send(sndpkt)
rdt_send(data)
udt_send(sndpkt)
rdt_rcv(rcvpkt) ampamp ( corrupt(rcvpkt) ||
isACK(rcvpkt1) )
rdt_rcv(rcvpkt) ampamp notcorrupt(rcvpkt) ampamp isACK(rcvpkt0)
Wait for ACK
0sender FSM
fragment
Wait for 0 from below
rdt_rcv(rcvpkt) ampamp notcorrupt(rcvpkt) ampamp has_seq1(rcvpkt)
extract(rcvpktdata)deliver_data(data)sndpkt = make_pkt(ACK1 chksum)udt_send(sndpkt)
rdt_rcv(rcvpkt) ampamp (corrupt(rcvpkt) ||
has_seq1(rcvpkt))
udt_send(sndpkt)receiver FSM
fragment
Λ
Transport Layer 3-28
rdt30 channels with errors and loss
New assumptionunderlying channel can also lose packets (data or ACKs)
checksum seq ACKs retransmissions will be of help but not enough
Q how to deal with losssender waits until certain data or ACK lost then retransmitsdrawbacks
Approach sender waits ldquoreasonablerdquo amount of time for ACK retransmits if no ACK received in this timeif pkt (or ACK) just delayed (not lost)
retransmission will be duplicate but use of seq rsquos already handles thisreceiver must specify seq of pkt being ACKed
requires countdown timer
Transport Layer 3-29
rdt30 sendersndpkt = make_pkt(0 data checksum)udt_send(sndpkt)start_timer
rdt_send(data)
Wait for
ACK0
rdt_rcv(rcvpkt) ampamp ( corrupt(rcvpkt) ||isACK(rcvpkt1) )
Wait for call 1 from
above
sndpkt = make_pkt(1 data checksum)udt_send(sndpkt)start_timer
rdt_send(data)
rdt_rcv(rcvpkt) ampamp notcorrupt(rcvpkt) ampamp isACK(rcvpkt0)
rdt_rcv(rcvpkt) ampamp ( corrupt(rcvpkt) ||isACK(rcvpkt0) )
rdt_rcv(rcvpkt) ampamp notcorrupt(rcvpkt) ampamp isACK(rcvpkt1)
stop_timerstop_timer
udt_send(sndpkt)start_timer
timeout
udt_send(sndpkt)start_timer
timeout
rdt_rcv(rcvpkt)
Wait for call 0from
above
Wait for
ACK1
Λrdt_rcv(rcvpkt)
ΛΛ
Λ
Transport Layer 3-30
rdt30 in action
Transport Layer 3-31
rdt30 in action
Transport Layer 3-32
Performance of rdt30
rdt30 works but performance stinksexample 1 Gbps link 15 ms e-e prop delay 1KB packet
Ttransmit = 8kbpkt109 bsec = 8 microsec
U sender utilization ndash fraction of time sender busy sending1KB pkt every 30 msec -gt 33kBsec thruput over 1 Gbps linknetwork protocol limits use of physical resources
U sender=
008 30008
= 000027 L RRTT + L R
=
L (packet length in bits)R (transmission rate bps) =
Transport Layer 3-33
rdt30 stop-and-wait operation
first packet bit transmitted t = 0
sender receiver
RTT
last packet bit transmitted t = L R
first packet bit arriveslast packet bit arrives send ACK
ACK arrives send next packet t = RTT + L R
U sender=
00830008
= 000027 L RRTT + L R
=
Transport Layer 3-34
Pipelined protocolsPipelining sender allows multiple ldquoin-flightrdquo yet-to-
be-acknowledged pktsrange of sequence numbers must be increasedbuffering at sender andor receiver
Two generic forms of pipelined protocols go-Back-N selective repeat
Transport Layer 3-35
Pipelining increased utilization
first packet bit transmitted t = 0
sender receiver
RTT
last bit transmitted t = L R
first packet bit arriveslast packet bit arrives send ACK
ACK arrives send next packet t = RTT + L R
last bit of 2nd packet arrives send ACKlast bit of 3rd packet arrives send ACK
U sender=
024 30008
= 000083 L RRTT + L R
=
Increase utilizationby a factor of 3
Transport Layer 3-36
Utilization=N(LR)(RTT+LR) if NLRltRTT+LR Utilization=1 if and the sender pauses after it transmits a window NLRgtRTT+LR and the of packets until it receives first ACK sender does not pause
Transport Layer 3-37
Go-Back-NSender
k-bit seq in pkt headerldquowindowrdquo of up to N consecutive unackrsquoed pkts allowed
ACK(n) ACKs all pkts up to including seq n - ldquocumulative ACKrdquomay receive duplicate ACKs (see receiver)
timer for the entire windowtimeout(n) retransmit pkt n and all higher seq pkts in window
Transport Layer 3-38
GBN sender extended FSM
Wait start_timerudt_send(sndpkt[base])udt_send(sndpkt[base+1])hellipudt_send(sndpkt[nextseqnum-1])
timeout
rdt_send(data)
if (nextseqnum lt base+N) sndpkt[nextseqnum] = make_pkt(nextseqnumdatachksum)udt_send(sndpkt[nextseqnum])if (base == nextseqnum)
start_timernextseqnum++
elserefuse_data(data)
base = getacknum(rcvpkt)+1If (base == nextseqnum)
stop_timerelse
start_timer
rdt_rcv(rcvpkt) ampamp notcorrupt(rcvpkt)
base=1nextseqnum=1
rdt_rcv(rcvpkt) ampamp corrupt(rcvpkt)
Λ
Λ
Transport Layer 3-39
GBN receiver extended FSM
ACK-only always send ACK for correctly-received pktwith highest in-order seq
may generate duplicate ACKsneed only remember expectedseqnum
out-of-order pkt discard (donrsquot buffer) -gt no receiver bufferingRe-ACK pkt with highest in-order seq
Wait
udt_send(sndpkt)default
rdt_rcv(rcvpkt)ampamp notcurrupt(rcvpkt)ampamp hasseqnum(rcvpktexpectedseqnum)
extract(rcvpktdata)deliver_data(data)sndpkt = make_pkt(expectedseqnumACKchksum)udt_send(sndpkt)expectedseqnum++
expectedseqnum=1sndpkt =
make_pkt(0ACKchksum)
Λ
Transport Layer 3-40
GBN inaction
Transport Layer 3-41
Selective Repeat
receiver individually acknowledges all correctly received pkts
buffers pkts as needed for eventual in-order delivery to upper layer
sender only resends pkts for which ACK not received
sender timer for each unACKed pktsender window
N consecutive seq rsquosagain limits seq s of sent unACKed pkts
Transport Layer 3-42
Selective repeat sender receiver windows
Transport Layer 3-43
Selective repeat
data from above if next available seq in window send pkt
timeout(n)resend pkt n restart timer
ACK(n) in [sendbasesendbase+N-1]
mark pkt n as receivedif n smallest unACKed pkt advance window base to next unACKed seq
senderpkt n in [rcvbase rcvbase+N-1]
send ACK(n)out-of-order bufferin-order deliver (also deliver buffered in-order pkts) advance window to next not-yet-received pkt
pkt n in [rcvbase-Nrcvbase-1]
ACK(n)otherwise
ignore
receiver
Transport Layer 3-44
Selective repeat in action
Transport Layer 3-45
Selective repeatdilemma
Example seq rsquos 0 1 2 3window size=3
receiver sees no difference in two scenariosincorrectly passes duplicate data as new in (a)
Q what relationship between seq size and window size
Transport Layer 3-46
Sequence Number vs Window SizeSuppose we use k bits to represent SNQuestion Whatrsquos the minimum number of bits k necessary for a window size of N
sender
receiver
Go-Back-N
expectedSN
snd_base=expectedSN
Q For a given expectedSN whatrsquos the largest possible value for snd_baseA If all the last N ACKs sent by the receiver are received
snd_base = expectedSNexpectedSN+N-1
senderrsquos window
Transport Layer 3-47
Sequence Number vs Window SizeSuppose we use k bits to represent SNQuestion Whatrsquos the minimum number of bits k necessary for a window size of N
sender
receiver
Go-Back-N
expectedSN
snd_base=expectedSN-N
Q For a given expectedSN whatrsquos the smallest possible value for snd_baseA If all the last N ACKs sent by the receiver are not received
snd_base = expectedSN-NexpectedSN-1
senderrsquos window
Transport Layer 3-48
Sequence Number vs Window Size
sender
receiver
Go-Back-N
expectedSN
snd_base=expectedSN-N
All SNs in the interval [expectedSN-NexpectedSN+N-1] (an interval of size 2N) can be received by the receiver Since the receiver accepts on the packet with SN=expectedSN there should be no other packet within this interval with SN=expectedSN Therefore
2k ge N+1expectedSN+N-1
Transport Layer 3-49
Sequence Number vs Window SizeSuppose we use k bits to represent SNQuestion Whatrsquos the minimum number of bits k necessary for a window size of N
sender
receiver
Selective Repeat
rcv_base
snd_base=rcv_base
Q For a given rcv_base whatrsquos the largest possible value for snd_baseA If all the last N ACKs sent by the receiver are received
snd_base = rcv_base (same as go_back-N)rcv_base+N-1
senderrsquos window
receiverrsquos window
rcv_base+N-1
Transport Layer 3-50
Sequence Number vs Window SizeSuppose we use k bits to represent SNQuestion Whatrsquos the minimum number of bits k necessary for a window size of N
sender
receiver
Selective Repeat
rcv_base
snd_base=rcv_base-N
Q For a given rcv_base whatrsquos the smallest possible value for snd_baseA If all the last N ACKs sent by the receiver are not received
snd_base = rcv_base-N (same as Go-Back-N)rcv_base-1
senderrsquos window
rcv_base
receiverrsquos window
rcv_base+N-1
Transport Layer 3-51
Sequence Number vs Window Size
sender
receiver
Selective Repeat
snd_base=rcv_base-N
All SNs in the interval [rcv_base-Nrcv_base+N-1] (an interval of size 2N) can be received by the receiver Since the receiver should be able to distinguish between all packets in this interval and take corresponding action there should be no two packets within thisinterval having the same SN Therefore
2k ge 2Nrcv_base+N-1
rcv_basercv_base
receiverrsquos window
rcv_base+N-1
Transport Layer 3-52
TCP Overview RFCs 793 1122 1323 2018 2581
full duplex databi-directional data flow in same connectionMSS maximum segment size
connection-orientedhandshaking (exchange of control msgs) initrsquossender receiver state before data exchange
flow controlledsender will not overwhelm receiver
point-to-pointone sender one receiver
reliable in-order byte stream
no ldquomessage boundariesrdquopipelined
TCP congestion and flow control set window size
send amp receive buffers
socketdoor
TCPsend buffer
TCPreceive buffer
socketdoor
segment
applicationwrites data
applicationreads data
Transport Layer 3-53
TCP segment structure
source port dest port
32 bits
applicationdata
(variable length)
sequence numberacknowledgement number
Receive windowUrg data pnterchecksum
FSRPAUheadlen
notused
Options (variable length)
URG urgent data (generally not used)
ACK ACK valid
PSH push data now(generally not used)
RST SYN FINconnection estab(setup teardown
commands)
bytes rcvr willingto accept
Internetchecksum
(as in UDP)
countingby bytes of data(not segments)
Transport Layer 3-54
TCP seq rsquos and ACKsSeq rsquos
byte stream ldquonumberrdquo of first byte in segmentrsquos dataACKs
seq of next byte expected from other sidecumulative ACK
Q how receiver handles out-of-order segmentsA TCP spec doesnrsquot say - up to implementationWidely used implementations of TCP buffer out-of-order segments
Transport Layer 3-55
TCP Round Trip Time and Timeout
Q how to set TCP timeout valuelonger than RTT
but RTT variestoo short premature timeout
unnecessary retransmissions
too long slow reaction to segment loss
Q how to estimate RTTSampleRTT measured time from segment transmission until ACK receipt
ignore retransmissionsSampleRTT will vary want estimated RTT ldquosmootherrdquo
average several recent measurements not just current SampleRTT
Transport Layer 3-56
TCP Round Trip Time and Timeout
EstimatedRTT = (1- α)EstimatedRTT + αSampleRTT
Exponential weighted moving averageinfluence of past sample decreases exponentially fasttypical value α = 0125
Transport Layer 3-57
Example RTT estimationRTT gaiacsumassedu to fantasiaeurecomfr
100
150
200
250
300
350
1 8 15 22 29 36 43 50 57 64 71 78 85 92 99 106
time (seconnds)
RTT
(mill
iseco
nds)
SampleRTT Estimated RTT
Transport Layer 3-58
TCP Round Trip Time and TimeoutSetting the timeout
EstimatedRTT plus ldquosafety marginrdquolarge variation in EstimatedRTT -gt larger safety margin
first estimate of how much SampleRTT deviates from EstimatedRTT
TimeoutInterval = EstimatedRTT + 4DevRTT
DevRTT = (1-β)DevRTT +β|SampleRTT-EstimatedRTT|
(typically β = 025)
Then set timeout interval
Transport Layer 3-59
TCP reliable data transfer
TCP creates rdtservice on top of IPrsquos unreliable servicePipelined segmentsCumulative acksTCP uses single retransmission timer however it just retransmits the first segment in the window
Retransmissions are triggered by
timeout eventsduplicate acks
Initially consider simplified TCP sender
ignore duplicate acksignore flow control congestion control
Transport Layer 3-60
TCP sender eventsdata rcvd from app
Create segment with seq seq is byte-stream number of first data byte in segmentstart timer if not already running (think of timer as for oldest unacked segment)expiration interval TimeOutInterval
timeoutretransmit segment that caused timeout (first segment in the window)restart timer
Ack rcvdIf acknowledges previously unacked segments
update what is known to be ackedstart timer if there are outstanding segments
Transport Layer 3-61
TCP sender(simplified)
NextSeqNum = InitialSeqNumSendBase = InitialSeqNum
loop (forever) switch(event)
event data received from application above create TCP segment with sequence number NextSeqNumif (timer currently not running)
start timerpass segment to IP NextSeqNum = NextSeqNum + length(data)
event timer timeoutretransmit not-yet-acknowledged segment with
smallest sequence numberstart timer
event ACK received with ACK field value of y if (y gt SendBase)
SendBase = yif (there are currently not-yet-acknowledged segments)
start timer
end of loop forever
Commentbull SendBase-1 last cumulatively ackrsquoed byteExamplebull SendBase-1 = 71y= 73 so the rcvrwants 73+ y gt SendBase sothat new data is acked
Transport Layer 3-62
TCP retransmission scenariosHost A
Seq=100 20 bytes data
ACK=100
timepremature timeout
Host B
Seq=92 8 bytes data
ACK=120
Seq=92 8 bytes data
Seq=
92 t
imeo
ut
ACK=120
Host A
Seq=92 8 bytes data
ACK=100
loss
tim
eout
lost ACK scenario
Host B
X
Seq=92 8 bytes data
ACK=100
time
Seq=
92 t
imeo
utSendBase
= 100
SendBase= 120
SendBase= 120
Sendbase= 100
Transport Layer 3-63
TCP retransmission scenarios (more)Host A
Seq=92 8 bytes data
ACK=100
loss
tim
eout
Cumulative ACK scenario
Host B
X
Seq=100 20 bytes data
ACK=120
time
SendBase= 120
Transport Layer 3-64
TCP ACK generation [RFC 1122 RFC 2581]
Event at Receiver
Arrival of in-order segment withexpected seq All data up toexpected seq already ACKed
Arrival of in-order segment withexpected seq One other segment has ACK pending
Arrival of out-of-order segmenthigher-than-expect seq Gap detected
Arrival of segment that partially or completely fills gap
TCP Receiver action
Delayed ACK Wait up to 500msfor next segment If no next segmentsend ACK
Immediately send single cumulative ACK ACKing both in-order segments
Immediately send duplicate ACK indicating seq of next expected byte
Immediate send ACK provided thatsegment startsat lower end of gap
Transport Layer 3-65
Fast Retransmit
Time-out period often relatively long
long delay before resending lost packet
Detect lost segments via duplicate ACKs
Sender often sends many segments back-to-backIf segment is lost there will likely be many duplicate ACKs
If sender receives 3 ACKs for the same data it supposes that segment after ACKeddata was lost
fast retransmit resend segment before timer expires
Transport Layer 3-66
Fast RetransmitResend a segment after 3 duplicate ACKs since a duplicate ACK means that an out-of sequence segment was receivedduplicate ACKs due to packet reorderingif window is small donrsquot get duplicate ACKs
Host A
tim
eout
Host B
time
X
resend seq X2
seq x1seq x2seq x3seq x4seq x5
ACK x1
ACK x1ACK x1ACK x1
tripleduplicate
ACKs
Transport Layer 3-67
event ACK received with ACK field value of y if (y gt SendBase)
SendBase = yif (there are currently not-yet-acknowledged segments)
start timer
else increment count of dup ACKs received for yif (count of dup ACKs received for y = 3)
resend segment with sequence number y
Fast retransmit algorithm
a duplicate ACK for already ACKed segment
fast retransmit
Transport Layer 3-68
TCP Flow Control
receive side of TCP connection has a receive buffer
speed-matching service matching the send rate to the receiving apprsquos drain rate
app process may be slow at reading from buffer
sender wonrsquot overflowreceiverrsquos buffer by
transmitting too muchtoo fast
flow control
Transport Layer 3-69
TCP Flow control how it works
(Suppose TCP receiver discards out-of-order segments)spare room in buffer
= RcvWin
= RcvBuffer-[LastByteRcvd -LastByteRead]
Rcvr advertises spare room by including value of RcvWin in segmentsSender limits unACKeddata to RcvWin
guarantees receive buffer doesnrsquot overflow
Transport Layer 3-70
Sliding Window Flow Control Example
3K
2K SeqNo=0
ReceiverBuffer
0 4KSendersends 2Kof data
2K
AckNo=2048 RcvWin=2048Sendersends 2Kof data 2K SeqNo=2048
4K
AckNo=4096 RcvWin=0
AckNo=4096 RcvWin=1024
Sender blocked
Transport Layer 3-71
Principles of Congestion Control
Congestioninformally ldquotoo many sources sending too much data too fast for network to handlerdquodifferent from flow controlmanifestations
lost packets (buffer overflow at routers)long delays (queueing in router buffers)
a top-10 problem
Transport Layer 3-72
Causescosts of congestion scenario 1
two senders two receiversone router infinite buffers no retransmission
large delays when congestedmaximum achievable throughput
unlimited shared output link buffers
Host Aλin original data
Host B
λout
Transport Layer 3-73
Causescosts of congestion scenario 2
one router finite buffers sender retransmission of lost packet
finite shared output link buffers
Host A λin original data
Host B
λout
λin original data plus retransmitted data
Transport Layer 3-74
Causescosts of congestion scenario 2always (goodput)ldquoperfectrdquo retransmission only when loss
retransmission of delayed (not lost) packet makes larger(than perfect case) for same
λin
λout=
λin
λoutgtλ
inλout
ldquocostsrdquo of congestionmore work (retrans) for given ldquogoodputrdquounneeded retransmissions link carries multiple copies of pkt
R2
R2λin
λ out
b
R2
R2λin
λ out
a
R2
R2λin
λ out
c
R4
R3
Transport Layer 3-75
Causescosts of congestion scenario 3four sendersmultihop pathstimeoutretransmit
λin
Q what happens as and increase λ
in
finite shared output link buffers
Host Aλin original data
Host B
λout
λin original data plus retransmitted data
Transport Layer 3-76
Causescosts of congestion scenario 3
another ldquocostrdquo of congestionwhen packet dropped any ldquoupstream transmission capacity used for that packet was wasted
Host A
Host B
λou
t
Transport Layer 3-77
Approaches towards congestion control
End-end congestion controlno explicit feedback from networkcongestion inferred from end-system observed loss delayapproach taken by TCP
Network-assisted congestion controlrouters provide feedback to end systems
single bit indicating congestion (SNA DECbit TCPIP ECN ATM)explicit rate sender should send at
Two broad approaches towards congestion control
Transport Layer 3-78
TCP Congestion Control
end-end control (no network assistance)sender limits transmissionLastByteSent-LastByteAcked
le CongWin
CongWin is dynamic function of perceived network congestion
How does sender perceive congestionloss event = timeout or3 duplicate acksTCP sender reduces rate (CongWin) after loss event
two modes of operationSlow Start (SS)Congestion avoidance (CA) or Additive Increase Multiplicative Decrease (AIMD)
Transport Layer 3-79
TCP congestion control bandwidth probing
ldquoprobing for bandwidthrdquo increase transmission rate on receipt of ACK until eventually loss occurs then decrease transmission rate
continue to increase on ACK decrease on loss (since available bandwidth is changing depending on other connections in network)
ACKs being received so increase rate
X
X
XX
X loss so decrease rate
send
ing
rate
time
Q how fast to increasedecreasedetails to follow
TCPrsquosldquosawtoothrdquobehavior
Transport Layer 3-80
TCP Congestion Control details
sender limits rate by limiting number of unACKed bytes ldquoin pipelinerdquo
cwnd differs from rwnd (how why)sender limited by min(cwndrwnd)
roughly
cwnd is dynamic function of perceived network congestion
rate = cwndRTT bytessec
LastByteSent-LastByteAcked le cwnd
cwndbytes
RTT
ACK(s)
Transport Layer 3-81
TCP Congestion Control more details
segment loss event reducing cwndtimeout no response from receiver
cut cwnd to 13 duplicate ACKs at least some segments getting through (recall fast retransmit)
cut cwnd in half less aggressively than on timeout
ACK received increase cwndTwo modes of operation
slowstart phase bull increase exponentially
fast (despite name) at connection start or following timeout
congestion avoidance bull increase linearly
Transport Layer 3-82
TCP Slow Start Phasewhen connection begins cwnd = 1 MSS
example MSS = 500 bytes amp RTT = 200 msecinitial rate = 20 kbps
available bandwidth may be gtgt MSSRTT
desirable to quickly ramp up to respectable rate
increase rate exponentially until first loss event or when threshold reached
double cwnd every RTTdone by incrementing cwnd by 1 for every ACK received
Host A
one segment
RTT
Host B
time
two segments
four segments
Transport Layer 3-83
Slow Start ExampleThe congestion window size grows very rapidly
For every ACK we increase CongWin by 1 irrespective of the number of segments ACKrsquoeddouble CongWinevery RTTinitial rate is slow but ramps up exponentially fast
TCP slows down the increase of CongWinwhen CongWin gt ssthresh
segment 1
ACK for segment 1
cwnd = 1
cwnd = 2 segment 2segment 3
ACK for segments 2
cwnd = 4 segment 4segment 5segment 6
ACK for segments 4
cwnd = 7
ACK for segments 3
ACK for segments 5
ACK for segments 6
cwnd = 3
cwnd = 5
cwnd = 6ACK for segments 7
cwnd = 8
segment 7
Transport Layer 3-84
TCP Congestion Avoidance Phase
when cwnd gt ssthreshgrow cwnd linearly
increase cwnd by 1 MSS per RTT approach possible congestion slower than in slowstartimplementation cwnd= cwnd + MSScwndfor each ACK received
ACKs increase cwndby 1 MSS per RTT additive increaseloss cut cwnd in half (non-timeout-detected loss ) multiplicative decrease
AIMD
AIMD Additive IncreaseMultiplicative Decrease
Transport Layer 3-85
Congestion AvoidanceCongestion avoidance phase is started if CongWin has reached the slow-start threshold value
If CongWin gt= ssthresh then each time an ACK is received increment CongWin as follows
bull CongWin = CongWin + 1CongWin (CongWin in segments)
bull In actual TCP implementation CongWin is in BytesCongWin = CongWin + MSS (MSSCongWin)
So CongWin is increased by one only if all CongWinsegments have been acknowledged
Transport Layer 3-86
Example Slow StartCongestion AvoidanceAssume that
ssthresh = 8
cwnd = 1
cwnd = 2
cwnd = 4
cwnd = 8
cwnd = 9
cwnd = 10
02468
101214
t=0
t=2
t=4
t=6
Roundtrip times
Cw
nd(in
seg
men
ts)
ssthresh
cwnd = 3
cwnd = 5cwnd = 6cwnd = 7
Transport Layer 3-87
Slow Start Congestion AvoidanceA typical plot of CongWin for a TCP connection
(MSS = 1500 bytes) with TCP Tahoe
SS
CA
ssthresh
Transport Layer 3-88
Responses to CongestionTCP assumes there is congestion if it detects a packet lossA TCP sender can detect lost packets via loss events
bull Timeout of a retransmission timerbull Receipt of 3 duplicate ACKs (fast retransmit)
TCP interprets a Timeout as a binary congestion signal When a timeout occurs the sender performs
ssthresh is set to half the current size of the congestion window
ssthresh = CongWin 2CongWin is reset to one
CongWin = 1and slow-start is entered
Transport Layer 3-89
Fast Recovery (differentiation btwn two loss events) After 3 dup ACKs (fast Retransmit)
ssthresh = CongWin2CongWin = CongWin2window then grows linearly
But after timeout eventCongWin = 1 MSS window then grows exponentiallyto the threshold then grows linearly
bull 3 dup ACKs indicates network capable of delivering some segmentsbull timeout before 3 dup ACKs is ldquomore alarmingrdquo
Philosophy
3-90
TCP Congestion ControlInitially
CongWin = 1ssthresh = advertised window size
New Ack receivedif (CongWin lt ssthresh) Slow Start
CongWin = CongWin + 1else Congestion Avoidance
CongWin = CongWin + 1CongWinTimeout
ssthresh = CongWin2CongWin = 1
Fast Retransmissionssthresh = CongWin2CongWin = CongWin2
Slow Start (exponential increase phase) is continued until CongWin reaches half of the level where the loss event occurred last time CongWin is increased slowly after (linear increase in Congestion Avoidance phase)
Transport Layer 3-91
Popular ldquoflavorsrdquo of TCP
ssthresh
ssthresh
TCP Tahoe
TCP Reno
Transmission round
cwnd
win
dow
siz
e (in
seg
men
ts)
Transport Layer 3-92
Summary TCP Congestion ControlWhen CongWin is below Threshold sender in slow-start phase window grows exponentiallyWhen CongWin is above Threshold sender is in congestion-avoidance phase window grows linearlyWhen a triple duplicate ACK occurs Threshold set to CongWin2 and CongWin set to ThresholdWhen timeout occurs Threshold set to CongWin2 and CongWin is set to 1 MSS The actual sender window size is determined based on the congestion and flow control algorithms
SenderWin=min(RcvWinCongWin)
Transport Layer 3-93
TCP Congestion Control SummaryEvent State TCP Sender Action Commentary
ACK receipt for previously unackeddata
Slow Start (SS)
CongWin = CongWin + MSS If (CongWin gt Threshold)
set state to ldquoCongestion Avoidancerdquo
Resulting in a doubling of CongWin every RTT
ACK receipt for previously unackeddata
CongestionAvoidance (CA)
CongWin = CongWin+MSS (MSSCongWin)
Additive increase resulting in increase of CongWin by 1 MSS every RTT
Loss event detected by triple duplicate ACK
SS or CA Threshold = CongWin2 CongWin = ThresholdSet state to ldquoCongestion Avoidancerdquo
Fast recovery implementing multiplicative decrease CongWin will not drop below 1 MSS
Timeout SS or CA Threshold = CongWin2 CongWin = 1 MSSSet state to ldquoSlow Startrdquo
Enter slow start
Duplicate ACK
SS or CA Increment duplicate ACK count for segment being acked
CongWin and Threshold not changed
Transport Layer 3-94
TCP throughput
Q whatrsquos average throughout of TCP as function of window size RTT
ignoring slow startlet W be window size when loss occurs
when window is W throughput is WRTTjust after loss window drops to W2 throughput to W2RTT average throughout 75 WRTT
Transport Layer 3-95
TCP Futures TCP over ldquolong fat pipesrdquo
example 1500 byte segments 100ms RTT want 10 Gbps throughputrequires window size W = 83333 in-flight segmentsthroughput in terms of loss rate
L = 210-10 Wownew versions of TCP for high-speed
LRTTMSSsdot221
Transport Layer 3-96
Fairness goal if K TCP sessions share same bottleneck link of bandwidth R each should have average rate of RK
TCP connection 1
bottleneckrouter
capacity R
TCP connection 2
TCP Fairness
Transport Layer 3-97
Why is TCP fairTwo competing sessions
Additive increase gives slope of 1 as throughout increasesmultiplicative decrease decreases throughput proportionally
R
R
equal bandwidth share
Connection 1 throughput
Conn
ecti
on 2
thr
ough
p ut
congestion avoidance additive increaseloss decrease window by factor of 2
congestion avoidance additive increaseloss decrease window by factor of 2
Transport Layer 3-98
Fairness (more)Fairness and UDP
Multimedia apps often do not use TCP
do not want rate throttled by congestion control
Instead use UDPpump audiovideo at constant rate tolerate packet loss
Research area TCP friendly
Fairness and parallel TCP connectionsnothing prevents app from opening parallel cnctionsbetween 2 hostsWeb browsers do this Example link of rate R supporting 9 cnctions
new app asks for 1 TCP gets rate R10new app asks for 11 TCPs gets R2
Transport Layer 3-99
TCP Connection ManagementRecall TCP sender receiver
establish ldquoconnectionrdquobefore exchanging data segmentsinitialize TCP variables
seq sbuffers flow control info (eg RcvWindow)
client connection initiatorSocket clientSocket = new Socket(hostnameport
number)
server contacted by clientSocket connectionSocket = welcomeSocketaccept()
Three way handshakeStep 1 client host sends TCP
SYN segment to serverspecifies initial seq no data
Step 2 server host receives SYN replies with SYNACK segment
server allocates buffersspecifies server initial seq
Step 3 client receives SYNACK replies with ACK segment which may contain data
Transport Layer 3-100
TCP Connection Management (cont)
Closing a connection
client closes socketclientSocketclose()
Step 1 client end system sends TCP FIN control segment to server
Step 2 server receives FIN replies with ACK Closes connection sends FIN
client
FIN
server
ACK
ACK
FIN
close
close
closed
tim
ed w
ait
Transport Layer 3-101
TCP Connection Management (cont)
Step 3 client receives FIN replies with ACK
Enters ldquotimed waitrdquo -will respond with ACK to received FINs
Step 4 server receives ACK Connection closed
client
FIN
server
ACK
ACK
FIN
closing
closing
closed
tim
ed w
ait
closed
Transport Layer 3-102
TCP Connection Management (cont)
TCP clientlifecycle
TCP serverlifecycle
Transport Layer 3-103
Tuning TCPIP Parameters TCPIP parameters
A set of default values may not be optimal for all applicationsThe network administrator may wish to turn on or off some TCPIP functions for performance or security considerations
Many Unix and Linux systems provide some flexibility in tuning the TCPIP kernelsbinsysctl is used to configure the Linux kernel parameters at runtime
Default kernel configuration file is sbinsysctlconfFrequently used sysctl options
bull sysctl ndasha or sysctl ndashA list all current valuesbull sysctl ndashp file_name load the sysctl setting from a configuration
filebull sysctl ndashw variable=value change the value of the parameter
Transport Layer 3-104
SomeTCP Parameters in Linux Kerneltcp_syn_retries
Number of SYN packets the kernel will send before giving up on the new connection
tcp_synack_retriesnumber of SYN+ACK packets sent before the kernel gives up on the connection
tcp_window_scalingMaximum window size of 65535 bytes not enough for for really fast networks The window scaling options allows for almost gigabyte windows which is good for connections with large delay-bandwidth product
tcp_max_syn_backlogMaximal number of remembered connection requests which still did not receive an acknowledgment from connecting client
tcp_fin_timeoutHow many seconds to wait for a final FIN packet before the socket is closed required to prevent denial-of-service (DoS) attacks Default value is 60 seconds
Transport Layer 3-105
SomeTCP Parameters in Linux Kerneltcp_rmem
This is a vector of 3 integers [min default max] These parameters are used by TCP to dynamically adjust receive buffer sizesmin - minimum size of the receive buffer used by each TCP socket The default value is 4K default - the default size of the receive buffer for a TCP socket The default value is 87380 bytes and is lowered to 43689 in low memory systems If larger receive buffer sizes are desired this value should be increased max - the maximum size of the receive buffer used by each TCP socket The default value of 873802 bytes is lowered to 87380 in low memory systems
tcp_smemSend buffer parameters [min default max] similar to tcp_rmem
- Chapter 3 Transport Layer
- Transport services and protocols
- Transport vs network layer
- Internet transport-layer protocols
- Multiplexingdemultiplexing
- How demultiplexing works
- Connectionless demultiplexing
- Connection-oriented demux
- Connection-oriented demux (cont)
- Connection-oriented demux Threaded Web Server
- UDP User Datagram Protocol [RFC 768]
- UDP more
- UDP checksum
- Principles of Reliable data transfer
- Reliable data transfer getting started
- Reliable data transfer getting started
- Rdt10 reliable transfer over a reliable channel
- Rdt20 channel with bit errors
- rdt20 FSM specification
- rdt20 operation with no errors
- rdt20 error scenario
- rdt20 has a fatal flaw
- rdt21 sender handles garbled ACKNAKs
- rdt21 receiver handles garbled ACKNAKs
- rdt21 discussion
- rdt22 a NAK-free protocol
- rdt22 sender receiver fragments
- rdt30 channels with errors and loss
- rdt30 sender
- rdt30 in action
- rdt30 in action
- Performance of rdt30
- rdt30 stop-and-wait operation
- Pipelined protocols
- Pipelining increased utilization
- Go-Back-N
- GBN sender extended FSM
- GBN receiver extended FSM
- GBN inaction
- Selective Repeat
- Selective repeat sender receiver windows
- Selective repeat
- Selective repeat in action
- Selective repeat dilemma
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- TCP Overview RFCs 793 1122 1323 2018 2581
- TCP segment structure
- TCP seq rsquos and ACKs
- TCP Round Trip Time and Timeout
- TCP Round Trip Time and Timeout
- Example RTT estimation
- TCP Round Trip Time and Timeout
- TCP reliable data transfer
- TCP sender events
- TCP sender(simplified)
- TCP retransmission scenarios
- TCP retransmission scenarios (more)
- TCP ACK generation [RFC 1122 RFC 2581]
- Fast Retransmit
- Fast Retransmit
- Fast retransmit algorithm
- TCP Flow Control
- TCP Flow control how it works
- Sliding Window Flow Control Example
- Principles of Congestion Control
- Causescosts of congestion scenario 1
- Causescosts of congestion scenario 2
- Causescosts of congestion scenario 2
- Causescosts of congestion scenario 3
- Causescosts of congestion scenario 3
- Approaches towards congestion control
- TCP Congestion Control
- TCP congestion control bandwidth probing
- TCP Congestion Control details
- TCP Congestion Control more details
- TCP Slow Start Phase
- Slow Start Example
- TCP Congestion Avoidance Phase
- Congestion Avoidance
- Example Slow StartCongestion Avoidance
- Slow Start Congestion Avoidance
- Responses to Congestion
- Fast Recovery (differentiation btwn two loss events)
- TCP Congestion Control
- Popular ldquoflavorsrdquo of TCP
- Summary TCP Congestion Control
- TCP Congestion Control Summary
- TCP throughput
- TCP Futures TCP over ldquolong fat pipesrdquo
- TCP Fairness
- Why is TCP fair
- Fairness (more)
- TCP Connection Management
- TCP Connection Management (cont)
- TCP Connection Management (cont)
- TCP Connection Management (cont)
- Tuning TCPIP Parameters
- SomeTCP Parameters in Linux Kernel
- SomeTCP Parameters in Linux Kernel
-
Transport Layer 3-10
Connection-oriented demuxThreaded Web Server
ClientIPB
P1
clientIP A
P1P2P4
serverIP C
SP 9157DP 80
SP 9157DP 80
P5 P6 P3
D-IPCS-IP AD-IPC
S-IP B
SP 5775DP 80
D-IPCS-IP B
P4
Transport Layer 3-11
UDP User Datagram Protocol [RFC 768]
ldquono frillsrdquo ldquobare bonesrdquoInternet transport protocolldquobest effortrdquo service UDP segments may be
lostdelivered out of order to app
connectionlessno handshaking between UDP sender receivereach UDP segment handled independently of others
Why is there a UDPno connection establishment (which can add delay)simple no connection state at sender receiversmall segment headerno congestion control UDP can blast away as fast as desired
Transport Layer 3-12
UDP moreoften used for streaming multimedia apps
loss tolerantrate sensitive
other UDP usesDNSSNMP
reliable transfer over UDP add reliability at application layer
application-specific error recovery
source port dest port
32 bits
Applicationdata
(message)
UDP segment format
length checksumLength in
bytes of UDPsegmentincluding
header
Transport Layer 3-13
UDP checksum
Sendertreat segment contents as sequence of 16-bit integerschecksum addition (1rsquos complement sum) of segment contents with wraparound of carry out bitsender puts checksum value into UDP checksum field
Receivercompute checksum of received segmentcheck if computed checksum equals checksum field value
NO - error detectedYES - no error detected
Goal detect ldquoerrorsrdquo (eg flipped bits) in transmitted segment
Transport Layer 3-14
Principles of Reliable data transferimportant in app transport link layerstop-10 list of important networking topics
characteristics of unreliable channel will determine complexity of reliable data transfer protocol (rdt)
netw
ork
laye
r
Transport Layer 3-15
Reliable data transfer getting started
sendside
receiveside
rdt_send() called from above (eg by app) Passed data to
deliver to receiver upper layer
udt_send() called by rdtto transfer packet over
unreliable channel to receiver
rdt_rcv() called when packet arrives on rcv-side of channel
deliver_data() called by rdt to deliver data to upper
Transport Layer 3-16
Reliable data transfer getting startedWersquoll
incrementally develop sender receiver sides of reliable data transfer protocol (rdt)consider only unidirectional data transfer
but control info will flow on both directionsuse finite state machines (FSM) to specify sender receiver
state1
state2
event causing state transitionactions taken on state transition
state when in this ldquostaterdquo next state
uniquely determined by next event
eventactions
Transport Layer 3-17
Rdt10 reliable transfer over a reliable channel
underlying channel perfectly reliableno bit errorsno loss of packets
separate FSMs for sender receiversender sends data into underlying channelreceiver read data from underlying channel
Wait for call from above packet = make_pkt(data)
udt_send(packet)
rdt_send(data)extract (packetdata)deliver_data(data)
Wait for call from
below
rdt_rcv(packet)
sender receiver
Transport Layer 3-18
Rdt20 channel with bit errors
underlying channel may flip bits in packetrecall checksum to detect bit errors
the question how to recover from errorsacknowledgements (ACKs) receiver explicitly tells sender that pkt received OKnegative acknowledgements (NAKs) receiver explicitly tells sender that pkt had errorssender retransmits pkt on receipt of NAK
new mechanisms in rdt20 (beyond rdt10)error detectionreceiver feedback control msgs (ACKNAK) rcvr-gtsender
Transport Layer 3-19
rdt20 FSM specification
Wait for call from above
snkpkt = make_pkt(data checksum)udt_send(sndpkt)
extract(rcvpktdata)deliver_data(data)udt_send(ACK)
rdt_rcv(rcvpkt) ampamp notcorrupt(rcvpkt)
rdt_rcv(rcvpkt) ampamp isACK(rcvpkt)
udt_send(sndpkt)
rdt_rcv(rcvpkt) ampampisNAK(rcvpkt)
udt_send(NAK)
rdt_rcv(rcvpkt) ampamp corrupt(rcvpkt)
Wait for ACK or
NAK
Wait for call from
belowsender
receiverrdt_send(data)
Λ
Transport Layer 3-20
rdt20 operation with no errors
Wait for call from above
snkpkt = make_pkt(data checksum)udt_send(sndpkt)
extract(rcvpktdata)deliver_data(data)udt_send(ACK)
rdt_rcv(rcvpkt) ampamp notcorrupt(rcvpkt)
rdt_rcv(rcvpkt) ampamp isACK(rcvpkt)
udt_send(sndpkt)
rdt_rcv(rcvpkt) ampampisNAK(rcvpkt)
udt_send(NAK)
rdt_rcv(rcvpkt) ampamp corrupt(rcvpkt)
Wait for ACK or
NAK
Wait for call from
below
rdt_send(data)
Λ
Transport Layer 3-21
rdt20 error scenario
Wait for call from above
snkpkt = make_pkt(data checksum)udt_send(sndpkt)
extract(rcvpktdata)deliver_data(data)udt_send(ACK)
rdt_rcv(rcvpkt) ampamp notcorrupt(rcvpkt)
rdt_rcv(rcvpkt) ampamp isACK(rcvpkt)
udt_send(sndpkt)
rdt_rcv(rcvpkt) ampampisNAK(rcvpkt)
udt_send(NAK)
rdt_rcv(rcvpkt) ampamp corrupt(rcvpkt)
Wait for ACK or
NAK
Wait for call from
below
rdt_send(data)
Λ
Transport Layer 3-22
rdt20 has a fatal flaw
What happens if ACKNAK corruptedsender doesnrsquot know what happened at receivercanrsquot just retransmit possible duplicate
What to dosender ACKsNAKs receiverrsquos ACKNAK What if sender ACKNAK lostretransmit but this might cause retransmission of correctly received pkt
Handling duplicates sender adds sequence number to each pktsender retransmits current pkt if ACKNAK garbledreceiver discards (doesnrsquot deliver up) duplicate pkt
Sender sends one packet then waits for receiver response
stop and wait
Transport Layer 3-23
rdt21 sender handles garbled ACKNAKs
Wait for call 0 from
above
sndpkt = make_pkt(0 data checksum)udt_send(sndpkt)
rdt_send(data)
Wait for ACK or NAK 0 udt_send(sndpkt)
rdt_rcv(rcvpkt) ampamp ( corrupt(rcvpkt) ||isNAK(rcvpkt) )
sndpkt = make_pkt(1 data checksum)udt_send(sndpkt)
rdt_send(data)
rdt_rcv(rcvpkt) ampamp notcorrupt(rcvpkt) ampamp isACK(rcvpkt)
udt_send(sndpkt)
rdt_rcv(rcvpkt) ampamp ( corrupt(rcvpkt) ||isNAK(rcvpkt) )
rdt_rcv(rcvpkt) ampamp notcorrupt(rcvpkt) ampamp isACK(rcvpkt)
Wait forcall 1 from
above
Wait for ACK or NAK 1
ΛΛ
Transport Layer 3-24
rdt21 receiver handles garbled ACKNAKs
Wait for 0 from below
sndpkt = make_pkt(NAK chksum)udt_send(sndpkt)
rdt_rcv(rcvpkt) ampamp not corrupt(rcvpkt) ampamphas_seq0(rcvpkt)
rdt_rcv(rcvpkt) ampamp notcorrupt(rcvpkt) ampamp has_seq1(rcvpkt)
extract(rcvpktdata)deliver_data(data)sndpkt = make_pkt(ACK chksum)udt_send(sndpkt)
Wait for 1 from below
rdt_rcv(rcvpkt) ampamp notcorrupt(rcvpkt) ampamp has_seq0(rcvpkt)
extract(rcvpktdata)deliver_data(data)sndpkt = make_pkt(ACK chksum)udt_send(sndpkt)
rdt_rcv(rcvpkt) ampamp (corrupt(rcvpkt)
sndpkt = make_pkt(ACK chksum)udt_send(sndpkt)
rdt_rcv(rcvpkt) ampamp not corrupt(rcvpkt) ampamphas_seq1(rcvpkt)
rdt_rcv(rcvpkt) ampamp (corrupt(rcvpkt)
sndpkt = make_pkt(ACK chksum)udt_send(sndpkt)
sndpkt = make_pkt(NAK chksum)udt_send(sndpkt)
Transport Layer 3-25
rdt21 discussion
Senderseq added to pkttwo seq rsquos (01) will suffice Whymust check if received ACKNAK corrupted twice as many states
state must ldquorememberrdquowhether ldquocurrentrdquo pkt has 0 or 1 seq
Receivermust check if received packet is duplicate
state indicates whether 0 or 1 is expected pkt seq
note receiver can notknow if its last ACKNAK received OK at sender
Transport Layer 3-26
rdt22 a NAK-free protocol
same functionality as rdt21 using ACKs onlyinstead of NAK receiver sends ACK for last pkt received OK
receiver must explicitly include seq of pkt being ACKed duplicate ACK at sender results in same action as NAK retransmit current pkt
Transport Layer 3-27
rdt22 sender receiver fragments
Wait for call 0 from
above
sndpkt = make_pkt(0 data checksum)udt_send(sndpkt)
rdt_send(data)
udt_send(sndpkt)
rdt_rcv(rcvpkt) ampamp ( corrupt(rcvpkt) ||
isACK(rcvpkt1) )
rdt_rcv(rcvpkt) ampamp notcorrupt(rcvpkt) ampamp isACK(rcvpkt0)
Wait for ACK
0sender FSM
fragment
Wait for 0 from below
rdt_rcv(rcvpkt) ampamp notcorrupt(rcvpkt) ampamp has_seq1(rcvpkt)
extract(rcvpktdata)deliver_data(data)sndpkt = make_pkt(ACK1 chksum)udt_send(sndpkt)
rdt_rcv(rcvpkt) ampamp (corrupt(rcvpkt) ||
has_seq1(rcvpkt))
udt_send(sndpkt)receiver FSM
fragment
Λ
Transport Layer 3-28
rdt30 channels with errors and loss
New assumptionunderlying channel can also lose packets (data or ACKs)
checksum seq ACKs retransmissions will be of help but not enough
Q how to deal with losssender waits until certain data or ACK lost then retransmitsdrawbacks
Approach sender waits ldquoreasonablerdquo amount of time for ACK retransmits if no ACK received in this timeif pkt (or ACK) just delayed (not lost)
retransmission will be duplicate but use of seq rsquos already handles thisreceiver must specify seq of pkt being ACKed
requires countdown timer
Transport Layer 3-29
rdt30 sendersndpkt = make_pkt(0 data checksum)udt_send(sndpkt)start_timer
rdt_send(data)
Wait for
ACK0
rdt_rcv(rcvpkt) ampamp ( corrupt(rcvpkt) ||isACK(rcvpkt1) )
Wait for call 1 from
above
sndpkt = make_pkt(1 data checksum)udt_send(sndpkt)start_timer
rdt_send(data)
rdt_rcv(rcvpkt) ampamp notcorrupt(rcvpkt) ampamp isACK(rcvpkt0)
rdt_rcv(rcvpkt) ampamp ( corrupt(rcvpkt) ||isACK(rcvpkt0) )
rdt_rcv(rcvpkt) ampamp notcorrupt(rcvpkt) ampamp isACK(rcvpkt1)
stop_timerstop_timer
udt_send(sndpkt)start_timer
timeout
udt_send(sndpkt)start_timer
timeout
rdt_rcv(rcvpkt)
Wait for call 0from
above
Wait for
ACK1
Λrdt_rcv(rcvpkt)
ΛΛ
Λ
Transport Layer 3-30
rdt30 in action
Transport Layer 3-31
rdt30 in action
Transport Layer 3-32
Performance of rdt30
rdt30 works but performance stinksexample 1 Gbps link 15 ms e-e prop delay 1KB packet
Ttransmit = 8kbpkt109 bsec = 8 microsec
U sender utilization ndash fraction of time sender busy sending1KB pkt every 30 msec -gt 33kBsec thruput over 1 Gbps linknetwork protocol limits use of physical resources
U sender=
008 30008
= 000027 L RRTT + L R
=
L (packet length in bits)R (transmission rate bps) =
Transport Layer 3-33
rdt30 stop-and-wait operation
first packet bit transmitted t = 0
sender receiver
RTT
last packet bit transmitted t = L R
first packet bit arriveslast packet bit arrives send ACK
ACK arrives send next packet t = RTT + L R
U sender=
00830008
= 000027 L RRTT + L R
=
Transport Layer 3-34
Pipelined protocolsPipelining sender allows multiple ldquoin-flightrdquo yet-to-
be-acknowledged pktsrange of sequence numbers must be increasedbuffering at sender andor receiver
Two generic forms of pipelined protocols go-Back-N selective repeat
Transport Layer 3-35
Pipelining increased utilization
first packet bit transmitted t = 0
sender receiver
RTT
last bit transmitted t = L R
first packet bit arriveslast packet bit arrives send ACK
ACK arrives send next packet t = RTT + L R
last bit of 2nd packet arrives send ACKlast bit of 3rd packet arrives send ACK
U sender=
024 30008
= 000083 L RRTT + L R
=
Increase utilizationby a factor of 3
Transport Layer 3-36
Utilization=N(LR)(RTT+LR) if NLRltRTT+LR Utilization=1 if and the sender pauses after it transmits a window NLRgtRTT+LR and the of packets until it receives first ACK sender does not pause
Transport Layer 3-37
Go-Back-NSender
k-bit seq in pkt headerldquowindowrdquo of up to N consecutive unackrsquoed pkts allowed
ACK(n) ACKs all pkts up to including seq n - ldquocumulative ACKrdquomay receive duplicate ACKs (see receiver)
timer for the entire windowtimeout(n) retransmit pkt n and all higher seq pkts in window
Transport Layer 3-38
GBN sender extended FSM
Wait start_timerudt_send(sndpkt[base])udt_send(sndpkt[base+1])hellipudt_send(sndpkt[nextseqnum-1])
timeout
rdt_send(data)
if (nextseqnum lt base+N) sndpkt[nextseqnum] = make_pkt(nextseqnumdatachksum)udt_send(sndpkt[nextseqnum])if (base == nextseqnum)
start_timernextseqnum++
elserefuse_data(data)
base = getacknum(rcvpkt)+1If (base == nextseqnum)
stop_timerelse
start_timer
rdt_rcv(rcvpkt) ampamp notcorrupt(rcvpkt)
base=1nextseqnum=1
rdt_rcv(rcvpkt) ampamp corrupt(rcvpkt)
Λ
Λ
Transport Layer 3-39
GBN receiver extended FSM
ACK-only always send ACK for correctly-received pktwith highest in-order seq
may generate duplicate ACKsneed only remember expectedseqnum
out-of-order pkt discard (donrsquot buffer) -gt no receiver bufferingRe-ACK pkt with highest in-order seq
Wait
udt_send(sndpkt)default
rdt_rcv(rcvpkt)ampamp notcurrupt(rcvpkt)ampamp hasseqnum(rcvpktexpectedseqnum)
extract(rcvpktdata)deliver_data(data)sndpkt = make_pkt(expectedseqnumACKchksum)udt_send(sndpkt)expectedseqnum++
expectedseqnum=1sndpkt =
make_pkt(0ACKchksum)
Λ
Transport Layer 3-40
GBN inaction
Transport Layer 3-41
Selective Repeat
receiver individually acknowledges all correctly received pkts
buffers pkts as needed for eventual in-order delivery to upper layer
sender only resends pkts for which ACK not received
sender timer for each unACKed pktsender window
N consecutive seq rsquosagain limits seq s of sent unACKed pkts
Transport Layer 3-42
Selective repeat sender receiver windows
Transport Layer 3-43
Selective repeat
data from above if next available seq in window send pkt
timeout(n)resend pkt n restart timer
ACK(n) in [sendbasesendbase+N-1]
mark pkt n as receivedif n smallest unACKed pkt advance window base to next unACKed seq
senderpkt n in [rcvbase rcvbase+N-1]
send ACK(n)out-of-order bufferin-order deliver (also deliver buffered in-order pkts) advance window to next not-yet-received pkt
pkt n in [rcvbase-Nrcvbase-1]
ACK(n)otherwise
ignore
receiver
Transport Layer 3-44
Selective repeat in action
Transport Layer 3-45
Selective repeatdilemma
Example seq rsquos 0 1 2 3window size=3
receiver sees no difference in two scenariosincorrectly passes duplicate data as new in (a)
Q what relationship between seq size and window size
Transport Layer 3-46
Sequence Number vs Window SizeSuppose we use k bits to represent SNQuestion Whatrsquos the minimum number of bits k necessary for a window size of N
sender
receiver
Go-Back-N
expectedSN
snd_base=expectedSN
Q For a given expectedSN whatrsquos the largest possible value for snd_baseA If all the last N ACKs sent by the receiver are received
snd_base = expectedSNexpectedSN+N-1
senderrsquos window
Transport Layer 3-47
Sequence Number vs Window SizeSuppose we use k bits to represent SNQuestion Whatrsquos the minimum number of bits k necessary for a window size of N
sender
receiver
Go-Back-N
expectedSN
snd_base=expectedSN-N
Q For a given expectedSN whatrsquos the smallest possible value for snd_baseA If all the last N ACKs sent by the receiver are not received
snd_base = expectedSN-NexpectedSN-1
senderrsquos window
Transport Layer 3-48
Sequence Number vs Window Size
sender
receiver
Go-Back-N
expectedSN
snd_base=expectedSN-N
All SNs in the interval [expectedSN-NexpectedSN+N-1] (an interval of size 2N) can be received by the receiver Since the receiver accepts on the packet with SN=expectedSN there should be no other packet within this interval with SN=expectedSN Therefore
2k ge N+1expectedSN+N-1
Transport Layer 3-49
Sequence Number vs Window SizeSuppose we use k bits to represent SNQuestion Whatrsquos the minimum number of bits k necessary for a window size of N
sender
receiver
Selective Repeat
rcv_base
snd_base=rcv_base
Q For a given rcv_base whatrsquos the largest possible value for snd_baseA If all the last N ACKs sent by the receiver are received
snd_base = rcv_base (same as go_back-N)rcv_base+N-1
senderrsquos window
receiverrsquos window
rcv_base+N-1
Transport Layer 3-50
Sequence Number vs Window SizeSuppose we use k bits to represent SNQuestion Whatrsquos the minimum number of bits k necessary for a window size of N
sender
receiver
Selective Repeat
rcv_base
snd_base=rcv_base-N
Q For a given rcv_base whatrsquos the smallest possible value for snd_baseA If all the last N ACKs sent by the receiver are not received
snd_base = rcv_base-N (same as Go-Back-N)rcv_base-1
senderrsquos window
rcv_base
receiverrsquos window
rcv_base+N-1
Transport Layer 3-51
Sequence Number vs Window Size
sender
receiver
Selective Repeat
snd_base=rcv_base-N
All SNs in the interval [rcv_base-Nrcv_base+N-1] (an interval of size 2N) can be received by the receiver Since the receiver should be able to distinguish between all packets in this interval and take corresponding action there should be no two packets within thisinterval having the same SN Therefore
2k ge 2Nrcv_base+N-1
rcv_basercv_base
receiverrsquos window
rcv_base+N-1
Transport Layer 3-52
TCP Overview RFCs 793 1122 1323 2018 2581
full duplex databi-directional data flow in same connectionMSS maximum segment size
connection-orientedhandshaking (exchange of control msgs) initrsquossender receiver state before data exchange
flow controlledsender will not overwhelm receiver
point-to-pointone sender one receiver
reliable in-order byte stream
no ldquomessage boundariesrdquopipelined
TCP congestion and flow control set window size
send amp receive buffers
socketdoor
TCPsend buffer
TCPreceive buffer
socketdoor
segment
applicationwrites data
applicationreads data
Transport Layer 3-53
TCP segment structure
source port dest port
32 bits
applicationdata
(variable length)
sequence numberacknowledgement number
Receive windowUrg data pnterchecksum
FSRPAUheadlen
notused
Options (variable length)
URG urgent data (generally not used)
ACK ACK valid
PSH push data now(generally not used)
RST SYN FINconnection estab(setup teardown
commands)
bytes rcvr willingto accept
Internetchecksum
(as in UDP)
countingby bytes of data(not segments)
Transport Layer 3-54
TCP seq rsquos and ACKsSeq rsquos
byte stream ldquonumberrdquo of first byte in segmentrsquos dataACKs
seq of next byte expected from other sidecumulative ACK
Q how receiver handles out-of-order segmentsA TCP spec doesnrsquot say - up to implementationWidely used implementations of TCP buffer out-of-order segments
Transport Layer 3-55
TCP Round Trip Time and Timeout
Q how to set TCP timeout valuelonger than RTT
but RTT variestoo short premature timeout
unnecessary retransmissions
too long slow reaction to segment loss
Q how to estimate RTTSampleRTT measured time from segment transmission until ACK receipt
ignore retransmissionsSampleRTT will vary want estimated RTT ldquosmootherrdquo
average several recent measurements not just current SampleRTT
Transport Layer 3-56
TCP Round Trip Time and Timeout
EstimatedRTT = (1- α)EstimatedRTT + αSampleRTT
Exponential weighted moving averageinfluence of past sample decreases exponentially fasttypical value α = 0125
Transport Layer 3-57
Example RTT estimationRTT gaiacsumassedu to fantasiaeurecomfr
100
150
200
250
300
350
1 8 15 22 29 36 43 50 57 64 71 78 85 92 99 106
time (seconnds)
RTT
(mill
iseco
nds)
SampleRTT Estimated RTT
Transport Layer 3-58
TCP Round Trip Time and TimeoutSetting the timeout
EstimatedRTT plus ldquosafety marginrdquolarge variation in EstimatedRTT -gt larger safety margin
first estimate of how much SampleRTT deviates from EstimatedRTT
TimeoutInterval = EstimatedRTT + 4DevRTT
DevRTT = (1-β)DevRTT +β|SampleRTT-EstimatedRTT|
(typically β = 025)
Then set timeout interval
Transport Layer 3-59
TCP reliable data transfer
TCP creates rdtservice on top of IPrsquos unreliable servicePipelined segmentsCumulative acksTCP uses single retransmission timer however it just retransmits the first segment in the window
Retransmissions are triggered by
timeout eventsduplicate acks
Initially consider simplified TCP sender
ignore duplicate acksignore flow control congestion control
Transport Layer 3-60
TCP sender eventsdata rcvd from app
Create segment with seq seq is byte-stream number of first data byte in segmentstart timer if not already running (think of timer as for oldest unacked segment)expiration interval TimeOutInterval
timeoutretransmit segment that caused timeout (first segment in the window)restart timer
Ack rcvdIf acknowledges previously unacked segments
update what is known to be ackedstart timer if there are outstanding segments
Transport Layer 3-61
TCP sender(simplified)
NextSeqNum = InitialSeqNumSendBase = InitialSeqNum
loop (forever) switch(event)
event data received from application above create TCP segment with sequence number NextSeqNumif (timer currently not running)
start timerpass segment to IP NextSeqNum = NextSeqNum + length(data)
event timer timeoutretransmit not-yet-acknowledged segment with
smallest sequence numberstart timer
event ACK received with ACK field value of y if (y gt SendBase)
SendBase = yif (there are currently not-yet-acknowledged segments)
start timer
end of loop forever
Commentbull SendBase-1 last cumulatively ackrsquoed byteExamplebull SendBase-1 = 71y= 73 so the rcvrwants 73+ y gt SendBase sothat new data is acked
Transport Layer 3-62
TCP retransmission scenariosHost A
Seq=100 20 bytes data
ACK=100
timepremature timeout
Host B
Seq=92 8 bytes data
ACK=120
Seq=92 8 bytes data
Seq=
92 t
imeo
ut
ACK=120
Host A
Seq=92 8 bytes data
ACK=100
loss
tim
eout
lost ACK scenario
Host B
X
Seq=92 8 bytes data
ACK=100
time
Seq=
92 t
imeo
utSendBase
= 100
SendBase= 120
SendBase= 120
Sendbase= 100
Transport Layer 3-63
TCP retransmission scenarios (more)Host A
Seq=92 8 bytes data
ACK=100
loss
tim
eout
Cumulative ACK scenario
Host B
X
Seq=100 20 bytes data
ACK=120
time
SendBase= 120
Transport Layer 3-64
TCP ACK generation [RFC 1122 RFC 2581]
Event at Receiver
Arrival of in-order segment withexpected seq All data up toexpected seq already ACKed
Arrival of in-order segment withexpected seq One other segment has ACK pending
Arrival of out-of-order segmenthigher-than-expect seq Gap detected
Arrival of segment that partially or completely fills gap
TCP Receiver action
Delayed ACK Wait up to 500msfor next segment If no next segmentsend ACK
Immediately send single cumulative ACK ACKing both in-order segments
Immediately send duplicate ACK indicating seq of next expected byte
Immediate send ACK provided thatsegment startsat lower end of gap
Transport Layer 3-65
Fast Retransmit
Time-out period often relatively long
long delay before resending lost packet
Detect lost segments via duplicate ACKs
Sender often sends many segments back-to-backIf segment is lost there will likely be many duplicate ACKs
If sender receives 3 ACKs for the same data it supposes that segment after ACKeddata was lost
fast retransmit resend segment before timer expires
Transport Layer 3-66
Fast RetransmitResend a segment after 3 duplicate ACKs since a duplicate ACK means that an out-of sequence segment was receivedduplicate ACKs due to packet reorderingif window is small donrsquot get duplicate ACKs
Host A
tim
eout
Host B
time
X
resend seq X2
seq x1seq x2seq x3seq x4seq x5
ACK x1
ACK x1ACK x1ACK x1
tripleduplicate
ACKs
Transport Layer 3-67
event ACK received with ACK field value of y if (y gt SendBase)
SendBase = yif (there are currently not-yet-acknowledged segments)
start timer
else increment count of dup ACKs received for yif (count of dup ACKs received for y = 3)
resend segment with sequence number y
Fast retransmit algorithm
a duplicate ACK for already ACKed segment
fast retransmit
Transport Layer 3-68
TCP Flow Control
receive side of TCP connection has a receive buffer
speed-matching service matching the send rate to the receiving apprsquos drain rate
app process may be slow at reading from buffer
sender wonrsquot overflowreceiverrsquos buffer by
transmitting too muchtoo fast
flow control
Transport Layer 3-69
TCP Flow control how it works
(Suppose TCP receiver discards out-of-order segments)spare room in buffer
= RcvWin
= RcvBuffer-[LastByteRcvd -LastByteRead]
Rcvr advertises spare room by including value of RcvWin in segmentsSender limits unACKeddata to RcvWin
guarantees receive buffer doesnrsquot overflow
Transport Layer 3-70
Sliding Window Flow Control Example
3K
2K SeqNo=0
ReceiverBuffer
0 4KSendersends 2Kof data
2K
AckNo=2048 RcvWin=2048Sendersends 2Kof data 2K SeqNo=2048
4K
AckNo=4096 RcvWin=0
AckNo=4096 RcvWin=1024
Sender blocked
Transport Layer 3-71
Principles of Congestion Control
Congestioninformally ldquotoo many sources sending too much data too fast for network to handlerdquodifferent from flow controlmanifestations
lost packets (buffer overflow at routers)long delays (queueing in router buffers)
a top-10 problem
Transport Layer 3-72
Causescosts of congestion scenario 1
two senders two receiversone router infinite buffers no retransmission
large delays when congestedmaximum achievable throughput
unlimited shared output link buffers
Host Aλin original data
Host B
λout
Transport Layer 3-73
Causescosts of congestion scenario 2
one router finite buffers sender retransmission of lost packet
finite shared output link buffers
Host A λin original data
Host B
λout
λin original data plus retransmitted data
Transport Layer 3-74
Causescosts of congestion scenario 2always (goodput)ldquoperfectrdquo retransmission only when loss
retransmission of delayed (not lost) packet makes larger(than perfect case) for same
λin
λout=
λin
λoutgtλ
inλout
ldquocostsrdquo of congestionmore work (retrans) for given ldquogoodputrdquounneeded retransmissions link carries multiple copies of pkt
R2
R2λin
λ out
b
R2
R2λin
λ out
a
R2
R2λin
λ out
c
R4
R3
Transport Layer 3-75
Causescosts of congestion scenario 3four sendersmultihop pathstimeoutretransmit
λin
Q what happens as and increase λ
in
finite shared output link buffers
Host Aλin original data
Host B
λout
λin original data plus retransmitted data
Transport Layer 3-76
Causescosts of congestion scenario 3
another ldquocostrdquo of congestionwhen packet dropped any ldquoupstream transmission capacity used for that packet was wasted
Host A
Host B
λou
t
Transport Layer 3-77
Approaches towards congestion control
End-end congestion controlno explicit feedback from networkcongestion inferred from end-system observed loss delayapproach taken by TCP
Network-assisted congestion controlrouters provide feedback to end systems
single bit indicating congestion (SNA DECbit TCPIP ECN ATM)explicit rate sender should send at
Two broad approaches towards congestion control
Transport Layer 3-78
TCP Congestion Control
end-end control (no network assistance)sender limits transmissionLastByteSent-LastByteAcked
le CongWin
CongWin is dynamic function of perceived network congestion
How does sender perceive congestionloss event = timeout or3 duplicate acksTCP sender reduces rate (CongWin) after loss event
two modes of operationSlow Start (SS)Congestion avoidance (CA) or Additive Increase Multiplicative Decrease (AIMD)
Transport Layer 3-79
TCP congestion control bandwidth probing
ldquoprobing for bandwidthrdquo increase transmission rate on receipt of ACK until eventually loss occurs then decrease transmission rate
continue to increase on ACK decrease on loss (since available bandwidth is changing depending on other connections in network)
ACKs being received so increase rate
X
X
XX
X loss so decrease rate
send
ing
rate
time
Q how fast to increasedecreasedetails to follow
TCPrsquosldquosawtoothrdquobehavior
Transport Layer 3-80
TCP Congestion Control details
sender limits rate by limiting number of unACKed bytes ldquoin pipelinerdquo
cwnd differs from rwnd (how why)sender limited by min(cwndrwnd)
roughly
cwnd is dynamic function of perceived network congestion
rate = cwndRTT bytessec
LastByteSent-LastByteAcked le cwnd
cwndbytes
RTT
ACK(s)
Transport Layer 3-81
TCP Congestion Control more details
segment loss event reducing cwndtimeout no response from receiver
cut cwnd to 13 duplicate ACKs at least some segments getting through (recall fast retransmit)
cut cwnd in half less aggressively than on timeout
ACK received increase cwndTwo modes of operation
slowstart phase bull increase exponentially
fast (despite name) at connection start or following timeout
congestion avoidance bull increase linearly
Transport Layer 3-82
TCP Slow Start Phasewhen connection begins cwnd = 1 MSS
example MSS = 500 bytes amp RTT = 200 msecinitial rate = 20 kbps
available bandwidth may be gtgt MSSRTT
desirable to quickly ramp up to respectable rate
increase rate exponentially until first loss event or when threshold reached
double cwnd every RTTdone by incrementing cwnd by 1 for every ACK received
Host A
one segment
RTT
Host B
time
two segments
four segments
Transport Layer 3-83
Slow Start ExampleThe congestion window size grows very rapidly
For every ACK we increase CongWin by 1 irrespective of the number of segments ACKrsquoeddouble CongWinevery RTTinitial rate is slow but ramps up exponentially fast
TCP slows down the increase of CongWinwhen CongWin gt ssthresh
segment 1
ACK for segment 1
cwnd = 1
cwnd = 2 segment 2segment 3
ACK for segments 2
cwnd = 4 segment 4segment 5segment 6
ACK for segments 4
cwnd = 7
ACK for segments 3
ACK for segments 5
ACK for segments 6
cwnd = 3
cwnd = 5
cwnd = 6ACK for segments 7
cwnd = 8
segment 7
Transport Layer 3-84
TCP Congestion Avoidance Phase
when cwnd gt ssthreshgrow cwnd linearly
increase cwnd by 1 MSS per RTT approach possible congestion slower than in slowstartimplementation cwnd= cwnd + MSScwndfor each ACK received
ACKs increase cwndby 1 MSS per RTT additive increaseloss cut cwnd in half (non-timeout-detected loss ) multiplicative decrease
AIMD
AIMD Additive IncreaseMultiplicative Decrease
Transport Layer 3-85
Congestion AvoidanceCongestion avoidance phase is started if CongWin has reached the slow-start threshold value
If CongWin gt= ssthresh then each time an ACK is received increment CongWin as follows
bull CongWin = CongWin + 1CongWin (CongWin in segments)
bull In actual TCP implementation CongWin is in BytesCongWin = CongWin + MSS (MSSCongWin)
So CongWin is increased by one only if all CongWinsegments have been acknowledged
Transport Layer 3-86
Example Slow StartCongestion AvoidanceAssume that
ssthresh = 8
cwnd = 1
cwnd = 2
cwnd = 4
cwnd = 8
cwnd = 9
cwnd = 10
02468
101214
t=0
t=2
t=4
t=6
Roundtrip times
Cw
nd(in
seg
men
ts)
ssthresh
cwnd = 3
cwnd = 5cwnd = 6cwnd = 7
Transport Layer 3-87
Slow Start Congestion AvoidanceA typical plot of CongWin for a TCP connection
(MSS = 1500 bytes) with TCP Tahoe
SS
CA
ssthresh
Transport Layer 3-88
Responses to CongestionTCP assumes there is congestion if it detects a packet lossA TCP sender can detect lost packets via loss events
bull Timeout of a retransmission timerbull Receipt of 3 duplicate ACKs (fast retransmit)
TCP interprets a Timeout as a binary congestion signal When a timeout occurs the sender performs
ssthresh is set to half the current size of the congestion window
ssthresh = CongWin 2CongWin is reset to one
CongWin = 1and slow-start is entered
Transport Layer 3-89
Fast Recovery (differentiation btwn two loss events) After 3 dup ACKs (fast Retransmit)
ssthresh = CongWin2CongWin = CongWin2window then grows linearly
But after timeout eventCongWin = 1 MSS window then grows exponentiallyto the threshold then grows linearly
bull 3 dup ACKs indicates network capable of delivering some segmentsbull timeout before 3 dup ACKs is ldquomore alarmingrdquo
Philosophy
3-90
TCP Congestion ControlInitially
CongWin = 1ssthresh = advertised window size
New Ack receivedif (CongWin lt ssthresh) Slow Start
CongWin = CongWin + 1else Congestion Avoidance
CongWin = CongWin + 1CongWinTimeout
ssthresh = CongWin2CongWin = 1
Fast Retransmissionssthresh = CongWin2CongWin = CongWin2
Slow Start (exponential increase phase) is continued until CongWin reaches half of the level where the loss event occurred last time CongWin is increased slowly after (linear increase in Congestion Avoidance phase)
Transport Layer 3-91
Popular ldquoflavorsrdquo of TCP
ssthresh
ssthresh
TCP Tahoe
TCP Reno
Transmission round
cwnd
win
dow
siz
e (in
seg
men
ts)
Transport Layer 3-92
Summary TCP Congestion ControlWhen CongWin is below Threshold sender in slow-start phase window grows exponentiallyWhen CongWin is above Threshold sender is in congestion-avoidance phase window grows linearlyWhen a triple duplicate ACK occurs Threshold set to CongWin2 and CongWin set to ThresholdWhen timeout occurs Threshold set to CongWin2 and CongWin is set to 1 MSS The actual sender window size is determined based on the congestion and flow control algorithms
SenderWin=min(RcvWinCongWin)
Transport Layer 3-93
TCP Congestion Control SummaryEvent State TCP Sender Action Commentary
ACK receipt for previously unackeddata
Slow Start (SS)
CongWin = CongWin + MSS If (CongWin gt Threshold)
set state to ldquoCongestion Avoidancerdquo
Resulting in a doubling of CongWin every RTT
ACK receipt for previously unackeddata
CongestionAvoidance (CA)
CongWin = CongWin+MSS (MSSCongWin)
Additive increase resulting in increase of CongWin by 1 MSS every RTT
Loss event detected by triple duplicate ACK
SS or CA Threshold = CongWin2 CongWin = ThresholdSet state to ldquoCongestion Avoidancerdquo
Fast recovery implementing multiplicative decrease CongWin will not drop below 1 MSS
Timeout SS or CA Threshold = CongWin2 CongWin = 1 MSSSet state to ldquoSlow Startrdquo
Enter slow start
Duplicate ACK
SS or CA Increment duplicate ACK count for segment being acked
CongWin and Threshold not changed
Transport Layer 3-94
TCP throughput
Q whatrsquos average throughout of TCP as function of window size RTT
ignoring slow startlet W be window size when loss occurs
when window is W throughput is WRTTjust after loss window drops to W2 throughput to W2RTT average throughout 75 WRTT
Transport Layer 3-95
TCP Futures TCP over ldquolong fat pipesrdquo
example 1500 byte segments 100ms RTT want 10 Gbps throughputrequires window size W = 83333 in-flight segmentsthroughput in terms of loss rate
L = 210-10 Wownew versions of TCP for high-speed
LRTTMSSsdot221
Transport Layer 3-96
Fairness goal if K TCP sessions share same bottleneck link of bandwidth R each should have average rate of RK
TCP connection 1
bottleneckrouter
capacity R
TCP connection 2
TCP Fairness
Transport Layer 3-97
Why is TCP fairTwo competing sessions
Additive increase gives slope of 1 as throughout increasesmultiplicative decrease decreases throughput proportionally
R
R
equal bandwidth share
Connection 1 throughput
Conn
ecti
on 2
thr
ough
p ut
congestion avoidance additive increaseloss decrease window by factor of 2
congestion avoidance additive increaseloss decrease window by factor of 2
Transport Layer 3-98
Fairness (more)Fairness and UDP
Multimedia apps often do not use TCP
do not want rate throttled by congestion control
Instead use UDPpump audiovideo at constant rate tolerate packet loss
Research area TCP friendly
Fairness and parallel TCP connectionsnothing prevents app from opening parallel cnctionsbetween 2 hostsWeb browsers do this Example link of rate R supporting 9 cnctions
new app asks for 1 TCP gets rate R10new app asks for 11 TCPs gets R2
Transport Layer 3-99
TCP Connection ManagementRecall TCP sender receiver
establish ldquoconnectionrdquobefore exchanging data segmentsinitialize TCP variables
seq sbuffers flow control info (eg RcvWindow)
client connection initiatorSocket clientSocket = new Socket(hostnameport
number)
server contacted by clientSocket connectionSocket = welcomeSocketaccept()
Three way handshakeStep 1 client host sends TCP
SYN segment to serverspecifies initial seq no data
Step 2 server host receives SYN replies with SYNACK segment
server allocates buffersspecifies server initial seq
Step 3 client receives SYNACK replies with ACK segment which may contain data
Transport Layer 3-100
TCP Connection Management (cont)
Closing a connection
client closes socketclientSocketclose()
Step 1 client end system sends TCP FIN control segment to server
Step 2 server receives FIN replies with ACK Closes connection sends FIN
client
FIN
server
ACK
ACK
FIN
close
close
closed
tim
ed w
ait
Transport Layer 3-101
TCP Connection Management (cont)
Step 3 client receives FIN replies with ACK
Enters ldquotimed waitrdquo -will respond with ACK to received FINs
Step 4 server receives ACK Connection closed
client
FIN
server
ACK
ACK
FIN
closing
closing
closed
tim
ed w
ait
closed
Transport Layer 3-102
TCP Connection Management (cont)
TCP clientlifecycle
TCP serverlifecycle
Transport Layer 3-103
Tuning TCPIP Parameters TCPIP parameters
A set of default values may not be optimal for all applicationsThe network administrator may wish to turn on or off some TCPIP functions for performance or security considerations
Many Unix and Linux systems provide some flexibility in tuning the TCPIP kernelsbinsysctl is used to configure the Linux kernel parameters at runtime
Default kernel configuration file is sbinsysctlconfFrequently used sysctl options
bull sysctl ndasha or sysctl ndashA list all current valuesbull sysctl ndashp file_name load the sysctl setting from a configuration
filebull sysctl ndashw variable=value change the value of the parameter
Transport Layer 3-104
SomeTCP Parameters in Linux Kerneltcp_syn_retries
Number of SYN packets the kernel will send before giving up on the new connection
tcp_synack_retriesnumber of SYN+ACK packets sent before the kernel gives up on the connection
tcp_window_scalingMaximum window size of 65535 bytes not enough for for really fast networks The window scaling options allows for almost gigabyte windows which is good for connections with large delay-bandwidth product
tcp_max_syn_backlogMaximal number of remembered connection requests which still did not receive an acknowledgment from connecting client
tcp_fin_timeoutHow many seconds to wait for a final FIN packet before the socket is closed required to prevent denial-of-service (DoS) attacks Default value is 60 seconds
Transport Layer 3-105
SomeTCP Parameters in Linux Kerneltcp_rmem
This is a vector of 3 integers [min default max] These parameters are used by TCP to dynamically adjust receive buffer sizesmin - minimum size of the receive buffer used by each TCP socket The default value is 4K default - the default size of the receive buffer for a TCP socket The default value is 87380 bytes and is lowered to 43689 in low memory systems If larger receive buffer sizes are desired this value should be increased max - the maximum size of the receive buffer used by each TCP socket The default value of 873802 bytes is lowered to 87380 in low memory systems
tcp_smemSend buffer parameters [min default max] similar to tcp_rmem
- Chapter 3 Transport Layer
- Transport services and protocols
- Transport vs network layer
- Internet transport-layer protocols
- Multiplexingdemultiplexing
- How demultiplexing works
- Connectionless demultiplexing
- Connection-oriented demux
- Connection-oriented demux (cont)
- Connection-oriented demux Threaded Web Server
- UDP User Datagram Protocol [RFC 768]
- UDP more
- UDP checksum
- Principles of Reliable data transfer
- Reliable data transfer getting started
- Reliable data transfer getting started
- Rdt10 reliable transfer over a reliable channel
- Rdt20 channel with bit errors
- rdt20 FSM specification
- rdt20 operation with no errors
- rdt20 error scenario
- rdt20 has a fatal flaw
- rdt21 sender handles garbled ACKNAKs
- rdt21 receiver handles garbled ACKNAKs
- rdt21 discussion
- rdt22 a NAK-free protocol
- rdt22 sender receiver fragments
- rdt30 channels with errors and loss
- rdt30 sender
- rdt30 in action
- rdt30 in action
- Performance of rdt30
- rdt30 stop-and-wait operation
- Pipelined protocols
- Pipelining increased utilization
- Go-Back-N
- GBN sender extended FSM
- GBN receiver extended FSM
- GBN inaction
- Selective Repeat
- Selective repeat sender receiver windows
- Selective repeat
- Selective repeat in action
- Selective repeat dilemma
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- TCP Overview RFCs 793 1122 1323 2018 2581
- TCP segment structure
- TCP seq rsquos and ACKs
- TCP Round Trip Time and Timeout
- TCP Round Trip Time and Timeout
- Example RTT estimation
- TCP Round Trip Time and Timeout
- TCP reliable data transfer
- TCP sender events
- TCP sender(simplified)
- TCP retransmission scenarios
- TCP retransmission scenarios (more)
- TCP ACK generation [RFC 1122 RFC 2581]
- Fast Retransmit
- Fast Retransmit
- Fast retransmit algorithm
- TCP Flow Control
- TCP Flow control how it works
- Sliding Window Flow Control Example
- Principles of Congestion Control
- Causescosts of congestion scenario 1
- Causescosts of congestion scenario 2
- Causescosts of congestion scenario 2
- Causescosts of congestion scenario 3
- Causescosts of congestion scenario 3
- Approaches towards congestion control
- TCP Congestion Control
- TCP congestion control bandwidth probing
- TCP Congestion Control details
- TCP Congestion Control more details
- TCP Slow Start Phase
- Slow Start Example
- TCP Congestion Avoidance Phase
- Congestion Avoidance
- Example Slow StartCongestion Avoidance
- Slow Start Congestion Avoidance
- Responses to Congestion
- Fast Recovery (differentiation btwn two loss events)
- TCP Congestion Control
- Popular ldquoflavorsrdquo of TCP
- Summary TCP Congestion Control
- TCP Congestion Control Summary
- TCP throughput
- TCP Futures TCP over ldquolong fat pipesrdquo
- TCP Fairness
- Why is TCP fair
- Fairness (more)
- TCP Connection Management
- TCP Connection Management (cont)
- TCP Connection Management (cont)
- TCP Connection Management (cont)
- Tuning TCPIP Parameters
- SomeTCP Parameters in Linux Kernel
- SomeTCP Parameters in Linux Kernel
-
Transport Layer 3-11
UDP User Datagram Protocol [RFC 768]
ldquono frillsrdquo ldquobare bonesrdquoInternet transport protocolldquobest effortrdquo service UDP segments may be
lostdelivered out of order to app
connectionlessno handshaking between UDP sender receivereach UDP segment handled independently of others
Why is there a UDPno connection establishment (which can add delay)simple no connection state at sender receiversmall segment headerno congestion control UDP can blast away as fast as desired
Transport Layer 3-12
UDP moreoften used for streaming multimedia apps
loss tolerantrate sensitive
other UDP usesDNSSNMP
reliable transfer over UDP add reliability at application layer
application-specific error recovery
source port dest port
32 bits
Applicationdata
(message)
UDP segment format
length checksumLength in
bytes of UDPsegmentincluding
header
Transport Layer 3-13
UDP checksum
Sendertreat segment contents as sequence of 16-bit integerschecksum addition (1rsquos complement sum) of segment contents with wraparound of carry out bitsender puts checksum value into UDP checksum field
Receivercompute checksum of received segmentcheck if computed checksum equals checksum field value
NO - error detectedYES - no error detected
Goal detect ldquoerrorsrdquo (eg flipped bits) in transmitted segment
Transport Layer 3-14
Principles of Reliable data transferimportant in app transport link layerstop-10 list of important networking topics
characteristics of unreliable channel will determine complexity of reliable data transfer protocol (rdt)
netw
ork
laye
r
Transport Layer 3-15
Reliable data transfer getting started
sendside
receiveside
rdt_send() called from above (eg by app) Passed data to
deliver to receiver upper layer
udt_send() called by rdtto transfer packet over
unreliable channel to receiver
rdt_rcv() called when packet arrives on rcv-side of channel
deliver_data() called by rdt to deliver data to upper
Transport Layer 3-16
Reliable data transfer getting startedWersquoll
incrementally develop sender receiver sides of reliable data transfer protocol (rdt)consider only unidirectional data transfer
but control info will flow on both directionsuse finite state machines (FSM) to specify sender receiver
state1
state2
event causing state transitionactions taken on state transition
state when in this ldquostaterdquo next state
uniquely determined by next event
eventactions
Transport Layer 3-17
Rdt10 reliable transfer over a reliable channel
underlying channel perfectly reliableno bit errorsno loss of packets
separate FSMs for sender receiversender sends data into underlying channelreceiver read data from underlying channel
Wait for call from above packet = make_pkt(data)
udt_send(packet)
rdt_send(data)extract (packetdata)deliver_data(data)
Wait for call from
below
rdt_rcv(packet)
sender receiver
Transport Layer 3-18
Rdt20 channel with bit errors
underlying channel may flip bits in packetrecall checksum to detect bit errors
the question how to recover from errorsacknowledgements (ACKs) receiver explicitly tells sender that pkt received OKnegative acknowledgements (NAKs) receiver explicitly tells sender that pkt had errorssender retransmits pkt on receipt of NAK
new mechanisms in rdt20 (beyond rdt10)error detectionreceiver feedback control msgs (ACKNAK) rcvr-gtsender
Transport Layer 3-19
rdt20 FSM specification
Wait for call from above
snkpkt = make_pkt(data checksum)udt_send(sndpkt)
extract(rcvpktdata)deliver_data(data)udt_send(ACK)
rdt_rcv(rcvpkt) ampamp notcorrupt(rcvpkt)
rdt_rcv(rcvpkt) ampamp isACK(rcvpkt)
udt_send(sndpkt)
rdt_rcv(rcvpkt) ampampisNAK(rcvpkt)
udt_send(NAK)
rdt_rcv(rcvpkt) ampamp corrupt(rcvpkt)
Wait for ACK or
NAK
Wait for call from
belowsender
receiverrdt_send(data)
Λ
Transport Layer 3-20
rdt20 operation with no errors
Wait for call from above
snkpkt = make_pkt(data checksum)udt_send(sndpkt)
extract(rcvpktdata)deliver_data(data)udt_send(ACK)
rdt_rcv(rcvpkt) ampamp notcorrupt(rcvpkt)
rdt_rcv(rcvpkt) ampamp isACK(rcvpkt)
udt_send(sndpkt)
rdt_rcv(rcvpkt) ampampisNAK(rcvpkt)
udt_send(NAK)
rdt_rcv(rcvpkt) ampamp corrupt(rcvpkt)
Wait for ACK or
NAK
Wait for call from
below
rdt_send(data)
Λ
Transport Layer 3-21
rdt20 error scenario
Wait for call from above
snkpkt = make_pkt(data checksum)udt_send(sndpkt)
extract(rcvpktdata)deliver_data(data)udt_send(ACK)
rdt_rcv(rcvpkt) ampamp notcorrupt(rcvpkt)
rdt_rcv(rcvpkt) ampamp isACK(rcvpkt)
udt_send(sndpkt)
rdt_rcv(rcvpkt) ampampisNAK(rcvpkt)
udt_send(NAK)
rdt_rcv(rcvpkt) ampamp corrupt(rcvpkt)
Wait for ACK or
NAK
Wait for call from
below
rdt_send(data)
Λ
Transport Layer 3-22
rdt20 has a fatal flaw
What happens if ACKNAK corruptedsender doesnrsquot know what happened at receivercanrsquot just retransmit possible duplicate
What to dosender ACKsNAKs receiverrsquos ACKNAK What if sender ACKNAK lostretransmit but this might cause retransmission of correctly received pkt
Handling duplicates sender adds sequence number to each pktsender retransmits current pkt if ACKNAK garbledreceiver discards (doesnrsquot deliver up) duplicate pkt
Sender sends one packet then waits for receiver response
stop and wait
Transport Layer 3-23
rdt21 sender handles garbled ACKNAKs
Wait for call 0 from
above
sndpkt = make_pkt(0 data checksum)udt_send(sndpkt)
rdt_send(data)
Wait for ACK or NAK 0 udt_send(sndpkt)
rdt_rcv(rcvpkt) ampamp ( corrupt(rcvpkt) ||isNAK(rcvpkt) )
sndpkt = make_pkt(1 data checksum)udt_send(sndpkt)
rdt_send(data)
rdt_rcv(rcvpkt) ampamp notcorrupt(rcvpkt) ampamp isACK(rcvpkt)
udt_send(sndpkt)
rdt_rcv(rcvpkt) ampamp ( corrupt(rcvpkt) ||isNAK(rcvpkt) )
rdt_rcv(rcvpkt) ampamp notcorrupt(rcvpkt) ampamp isACK(rcvpkt)
Wait forcall 1 from
above
Wait for ACK or NAK 1
ΛΛ
Transport Layer 3-24
rdt21 receiver handles garbled ACKNAKs
Wait for 0 from below
sndpkt = make_pkt(NAK chksum)udt_send(sndpkt)
rdt_rcv(rcvpkt) ampamp not corrupt(rcvpkt) ampamphas_seq0(rcvpkt)
rdt_rcv(rcvpkt) ampamp notcorrupt(rcvpkt) ampamp has_seq1(rcvpkt)
extract(rcvpktdata)deliver_data(data)sndpkt = make_pkt(ACK chksum)udt_send(sndpkt)
Wait for 1 from below
rdt_rcv(rcvpkt) ampamp notcorrupt(rcvpkt) ampamp has_seq0(rcvpkt)
extract(rcvpktdata)deliver_data(data)sndpkt = make_pkt(ACK chksum)udt_send(sndpkt)
rdt_rcv(rcvpkt) ampamp (corrupt(rcvpkt)
sndpkt = make_pkt(ACK chksum)udt_send(sndpkt)
rdt_rcv(rcvpkt) ampamp not corrupt(rcvpkt) ampamphas_seq1(rcvpkt)
rdt_rcv(rcvpkt) ampamp (corrupt(rcvpkt)
sndpkt = make_pkt(ACK chksum)udt_send(sndpkt)
sndpkt = make_pkt(NAK chksum)udt_send(sndpkt)
Transport Layer 3-25
rdt21 discussion
Senderseq added to pkttwo seq rsquos (01) will suffice Whymust check if received ACKNAK corrupted twice as many states
state must ldquorememberrdquowhether ldquocurrentrdquo pkt has 0 or 1 seq
Receivermust check if received packet is duplicate
state indicates whether 0 or 1 is expected pkt seq
note receiver can notknow if its last ACKNAK received OK at sender
Transport Layer 3-26
rdt22 a NAK-free protocol
same functionality as rdt21 using ACKs onlyinstead of NAK receiver sends ACK for last pkt received OK
receiver must explicitly include seq of pkt being ACKed duplicate ACK at sender results in same action as NAK retransmit current pkt
Transport Layer 3-27
rdt22 sender receiver fragments
Wait for call 0 from
above
sndpkt = make_pkt(0 data checksum)udt_send(sndpkt)
rdt_send(data)
udt_send(sndpkt)
rdt_rcv(rcvpkt) ampamp ( corrupt(rcvpkt) ||
isACK(rcvpkt1) )
rdt_rcv(rcvpkt) ampamp notcorrupt(rcvpkt) ampamp isACK(rcvpkt0)
Wait for ACK
0sender FSM
fragment
Wait for 0 from below
rdt_rcv(rcvpkt) ampamp notcorrupt(rcvpkt) ampamp has_seq1(rcvpkt)
extract(rcvpktdata)deliver_data(data)sndpkt = make_pkt(ACK1 chksum)udt_send(sndpkt)
rdt_rcv(rcvpkt) ampamp (corrupt(rcvpkt) ||
has_seq1(rcvpkt))
udt_send(sndpkt)receiver FSM
fragment
Λ
Transport Layer 3-28
rdt30 channels with errors and loss
New assumptionunderlying channel can also lose packets (data or ACKs)
checksum seq ACKs retransmissions will be of help but not enough
Q how to deal with losssender waits until certain data or ACK lost then retransmitsdrawbacks
Approach sender waits ldquoreasonablerdquo amount of time for ACK retransmits if no ACK received in this timeif pkt (or ACK) just delayed (not lost)
retransmission will be duplicate but use of seq rsquos already handles thisreceiver must specify seq of pkt being ACKed
requires countdown timer
Transport Layer 3-29
rdt30 sendersndpkt = make_pkt(0 data checksum)udt_send(sndpkt)start_timer
rdt_send(data)
Wait for
ACK0
rdt_rcv(rcvpkt) ampamp ( corrupt(rcvpkt) ||isACK(rcvpkt1) )
Wait for call 1 from
above
sndpkt = make_pkt(1 data checksum)udt_send(sndpkt)start_timer
rdt_send(data)
rdt_rcv(rcvpkt) ampamp notcorrupt(rcvpkt) ampamp isACK(rcvpkt0)
rdt_rcv(rcvpkt) ampamp ( corrupt(rcvpkt) ||isACK(rcvpkt0) )
rdt_rcv(rcvpkt) ampamp notcorrupt(rcvpkt) ampamp isACK(rcvpkt1)
stop_timerstop_timer
udt_send(sndpkt)start_timer
timeout
udt_send(sndpkt)start_timer
timeout
rdt_rcv(rcvpkt)
Wait for call 0from
above
Wait for
ACK1
Λrdt_rcv(rcvpkt)
ΛΛ
Λ
Transport Layer 3-30
rdt30 in action
Transport Layer 3-31
rdt30 in action
Transport Layer 3-32
Performance of rdt30
rdt30 works but performance stinksexample 1 Gbps link 15 ms e-e prop delay 1KB packet
Ttransmit = 8kbpkt109 bsec = 8 microsec
U sender utilization ndash fraction of time sender busy sending1KB pkt every 30 msec -gt 33kBsec thruput over 1 Gbps linknetwork protocol limits use of physical resources
U sender=
008 30008
= 000027 L RRTT + L R
=
L (packet length in bits)R (transmission rate bps) =
Transport Layer 3-33
rdt30 stop-and-wait operation
first packet bit transmitted t = 0
sender receiver
RTT
last packet bit transmitted t = L R
first packet bit arriveslast packet bit arrives send ACK
ACK arrives send next packet t = RTT + L R
U sender=
00830008
= 000027 L RRTT + L R
=
Transport Layer 3-34
Pipelined protocolsPipelining sender allows multiple ldquoin-flightrdquo yet-to-
be-acknowledged pktsrange of sequence numbers must be increasedbuffering at sender andor receiver
Two generic forms of pipelined protocols go-Back-N selective repeat
Transport Layer 3-35
Pipelining increased utilization
first packet bit transmitted t = 0
sender receiver
RTT
last bit transmitted t = L R
first packet bit arriveslast packet bit arrives send ACK
ACK arrives send next packet t = RTT + L R
last bit of 2nd packet arrives send ACKlast bit of 3rd packet arrives send ACK
U sender=
024 30008
= 000083 L RRTT + L R
=
Increase utilizationby a factor of 3
Transport Layer 3-36
Utilization=N(LR)(RTT+LR) if NLRltRTT+LR Utilization=1 if and the sender pauses after it transmits a window NLRgtRTT+LR and the of packets until it receives first ACK sender does not pause
Transport Layer 3-37
Go-Back-NSender
k-bit seq in pkt headerldquowindowrdquo of up to N consecutive unackrsquoed pkts allowed
ACK(n) ACKs all pkts up to including seq n - ldquocumulative ACKrdquomay receive duplicate ACKs (see receiver)
timer for the entire windowtimeout(n) retransmit pkt n and all higher seq pkts in window
Transport Layer 3-38
GBN sender extended FSM
Wait start_timerudt_send(sndpkt[base])udt_send(sndpkt[base+1])hellipudt_send(sndpkt[nextseqnum-1])
timeout
rdt_send(data)
if (nextseqnum lt base+N) sndpkt[nextseqnum] = make_pkt(nextseqnumdatachksum)udt_send(sndpkt[nextseqnum])if (base == nextseqnum)
start_timernextseqnum++
elserefuse_data(data)
base = getacknum(rcvpkt)+1If (base == nextseqnum)
stop_timerelse
start_timer
rdt_rcv(rcvpkt) ampamp notcorrupt(rcvpkt)
base=1nextseqnum=1
rdt_rcv(rcvpkt) ampamp corrupt(rcvpkt)
Λ
Λ
Transport Layer 3-39
GBN receiver extended FSM
ACK-only always send ACK for correctly-received pktwith highest in-order seq
may generate duplicate ACKsneed only remember expectedseqnum
out-of-order pkt discard (donrsquot buffer) -gt no receiver bufferingRe-ACK pkt with highest in-order seq
Wait
udt_send(sndpkt)default
rdt_rcv(rcvpkt)ampamp notcurrupt(rcvpkt)ampamp hasseqnum(rcvpktexpectedseqnum)
extract(rcvpktdata)deliver_data(data)sndpkt = make_pkt(expectedseqnumACKchksum)udt_send(sndpkt)expectedseqnum++
expectedseqnum=1sndpkt =
make_pkt(0ACKchksum)
Λ
Transport Layer 3-40
GBN inaction
Transport Layer 3-41
Selective Repeat
receiver individually acknowledges all correctly received pkts
buffers pkts as needed for eventual in-order delivery to upper layer
sender only resends pkts for which ACK not received
sender timer for each unACKed pktsender window
N consecutive seq rsquosagain limits seq s of sent unACKed pkts
Transport Layer 3-42
Selective repeat sender receiver windows
Transport Layer 3-43
Selective repeat
data from above if next available seq in window send pkt
timeout(n)resend pkt n restart timer
ACK(n) in [sendbasesendbase+N-1]
mark pkt n as receivedif n smallest unACKed pkt advance window base to next unACKed seq
senderpkt n in [rcvbase rcvbase+N-1]
send ACK(n)out-of-order bufferin-order deliver (also deliver buffered in-order pkts) advance window to next not-yet-received pkt
pkt n in [rcvbase-Nrcvbase-1]
ACK(n)otherwise
ignore
receiver
Transport Layer 3-44
Selective repeat in action
Transport Layer 3-45
Selective repeatdilemma
Example seq rsquos 0 1 2 3window size=3
receiver sees no difference in two scenariosincorrectly passes duplicate data as new in (a)
Q what relationship between seq size and window size
Transport Layer 3-46
Sequence Number vs Window SizeSuppose we use k bits to represent SNQuestion Whatrsquos the minimum number of bits k necessary for a window size of N
sender
receiver
Go-Back-N
expectedSN
snd_base=expectedSN
Q For a given expectedSN whatrsquos the largest possible value for snd_baseA If all the last N ACKs sent by the receiver are received
snd_base = expectedSNexpectedSN+N-1
senderrsquos window
Transport Layer 3-47
Sequence Number vs Window SizeSuppose we use k bits to represent SNQuestion Whatrsquos the minimum number of bits k necessary for a window size of N
sender
receiver
Go-Back-N
expectedSN
snd_base=expectedSN-N
Q For a given expectedSN whatrsquos the smallest possible value for snd_baseA If all the last N ACKs sent by the receiver are not received
snd_base = expectedSN-NexpectedSN-1
senderrsquos window
Transport Layer 3-48
Sequence Number vs Window Size
sender
receiver
Go-Back-N
expectedSN
snd_base=expectedSN-N
All SNs in the interval [expectedSN-NexpectedSN+N-1] (an interval of size 2N) can be received by the receiver Since the receiver accepts on the packet with SN=expectedSN there should be no other packet within this interval with SN=expectedSN Therefore
2k ge N+1expectedSN+N-1
Transport Layer 3-49
Sequence Number vs Window SizeSuppose we use k bits to represent SNQuestion Whatrsquos the minimum number of bits k necessary for a window size of N
sender
receiver
Selective Repeat
rcv_base
snd_base=rcv_base
Q For a given rcv_base whatrsquos the largest possible value for snd_baseA If all the last N ACKs sent by the receiver are received
snd_base = rcv_base (same as go_back-N)rcv_base+N-1
senderrsquos window
receiverrsquos window
rcv_base+N-1
Transport Layer 3-50
Sequence Number vs Window SizeSuppose we use k bits to represent SNQuestion Whatrsquos the minimum number of bits k necessary for a window size of N
sender
receiver
Selective Repeat
rcv_base
snd_base=rcv_base-N
Q For a given rcv_base whatrsquos the smallest possible value for snd_baseA If all the last N ACKs sent by the receiver are not received
snd_base = rcv_base-N (same as Go-Back-N)rcv_base-1
senderrsquos window
rcv_base
receiverrsquos window
rcv_base+N-1
Transport Layer 3-51
Sequence Number vs Window Size
sender
receiver
Selective Repeat
snd_base=rcv_base-N
All SNs in the interval [rcv_base-Nrcv_base+N-1] (an interval of size 2N) can be received by the receiver Since the receiver should be able to distinguish between all packets in this interval and take corresponding action there should be no two packets within thisinterval having the same SN Therefore
2k ge 2Nrcv_base+N-1
rcv_basercv_base
receiverrsquos window
rcv_base+N-1
Transport Layer 3-52
TCP Overview RFCs 793 1122 1323 2018 2581
full duplex databi-directional data flow in same connectionMSS maximum segment size
connection-orientedhandshaking (exchange of control msgs) initrsquossender receiver state before data exchange
flow controlledsender will not overwhelm receiver
point-to-pointone sender one receiver
reliable in-order byte stream
no ldquomessage boundariesrdquopipelined
TCP congestion and flow control set window size
send amp receive buffers
socketdoor
TCPsend buffer
TCPreceive buffer
socketdoor
segment
applicationwrites data
applicationreads data
Transport Layer 3-53
TCP segment structure
source port dest port
32 bits
applicationdata
(variable length)
sequence numberacknowledgement number
Receive windowUrg data pnterchecksum
FSRPAUheadlen
notused
Options (variable length)
URG urgent data (generally not used)
ACK ACK valid
PSH push data now(generally not used)
RST SYN FINconnection estab(setup teardown
commands)
bytes rcvr willingto accept
Internetchecksum
(as in UDP)
countingby bytes of data(not segments)
Transport Layer 3-54
TCP seq rsquos and ACKsSeq rsquos
byte stream ldquonumberrdquo of first byte in segmentrsquos dataACKs
seq of next byte expected from other sidecumulative ACK
Q how receiver handles out-of-order segmentsA TCP spec doesnrsquot say - up to implementationWidely used implementations of TCP buffer out-of-order segments
Transport Layer 3-55
TCP Round Trip Time and Timeout
Q how to set TCP timeout valuelonger than RTT
but RTT variestoo short premature timeout
unnecessary retransmissions
too long slow reaction to segment loss
Q how to estimate RTTSampleRTT measured time from segment transmission until ACK receipt
ignore retransmissionsSampleRTT will vary want estimated RTT ldquosmootherrdquo
average several recent measurements not just current SampleRTT
Transport Layer 3-56
TCP Round Trip Time and Timeout
EstimatedRTT = (1- α)EstimatedRTT + αSampleRTT
Exponential weighted moving averageinfluence of past sample decreases exponentially fasttypical value α = 0125
Transport Layer 3-57
Example RTT estimationRTT gaiacsumassedu to fantasiaeurecomfr
100
150
200
250
300
350
1 8 15 22 29 36 43 50 57 64 71 78 85 92 99 106
time (seconnds)
RTT
(mill
iseco
nds)
SampleRTT Estimated RTT
Transport Layer 3-58
TCP Round Trip Time and TimeoutSetting the timeout
EstimatedRTT plus ldquosafety marginrdquolarge variation in EstimatedRTT -gt larger safety margin
first estimate of how much SampleRTT deviates from EstimatedRTT
TimeoutInterval = EstimatedRTT + 4DevRTT
DevRTT = (1-β)DevRTT +β|SampleRTT-EstimatedRTT|
(typically β = 025)
Then set timeout interval
Transport Layer 3-59
TCP reliable data transfer
TCP creates rdtservice on top of IPrsquos unreliable servicePipelined segmentsCumulative acksTCP uses single retransmission timer however it just retransmits the first segment in the window
Retransmissions are triggered by
timeout eventsduplicate acks
Initially consider simplified TCP sender
ignore duplicate acksignore flow control congestion control
Transport Layer 3-60
TCP sender eventsdata rcvd from app
Create segment with seq seq is byte-stream number of first data byte in segmentstart timer if not already running (think of timer as for oldest unacked segment)expiration interval TimeOutInterval
timeoutretransmit segment that caused timeout (first segment in the window)restart timer
Ack rcvdIf acknowledges previously unacked segments
update what is known to be ackedstart timer if there are outstanding segments
Transport Layer 3-61
TCP sender(simplified)
NextSeqNum = InitialSeqNumSendBase = InitialSeqNum
loop (forever) switch(event)
event data received from application above create TCP segment with sequence number NextSeqNumif (timer currently not running)
start timerpass segment to IP NextSeqNum = NextSeqNum + length(data)
event timer timeoutretransmit not-yet-acknowledged segment with
smallest sequence numberstart timer
event ACK received with ACK field value of y if (y gt SendBase)
SendBase = yif (there are currently not-yet-acknowledged segments)
start timer
end of loop forever
Commentbull SendBase-1 last cumulatively ackrsquoed byteExamplebull SendBase-1 = 71y= 73 so the rcvrwants 73+ y gt SendBase sothat new data is acked
Transport Layer 3-62
TCP retransmission scenariosHost A
Seq=100 20 bytes data
ACK=100
timepremature timeout
Host B
Seq=92 8 bytes data
ACK=120
Seq=92 8 bytes data
Seq=
92 t
imeo
ut
ACK=120
Host A
Seq=92 8 bytes data
ACK=100
loss
tim
eout
lost ACK scenario
Host B
X
Seq=92 8 bytes data
ACK=100
time
Seq=
92 t
imeo
utSendBase
= 100
SendBase= 120
SendBase= 120
Sendbase= 100
Transport Layer 3-63
TCP retransmission scenarios (more)Host A
Seq=92 8 bytes data
ACK=100
loss
tim
eout
Cumulative ACK scenario
Host B
X
Seq=100 20 bytes data
ACK=120
time
SendBase= 120
Transport Layer 3-64
TCP ACK generation [RFC 1122 RFC 2581]
Event at Receiver
Arrival of in-order segment withexpected seq All data up toexpected seq already ACKed
Arrival of in-order segment withexpected seq One other segment has ACK pending
Arrival of out-of-order segmenthigher-than-expect seq Gap detected
Arrival of segment that partially or completely fills gap
TCP Receiver action
Delayed ACK Wait up to 500msfor next segment If no next segmentsend ACK
Immediately send single cumulative ACK ACKing both in-order segments
Immediately send duplicate ACK indicating seq of next expected byte
Immediate send ACK provided thatsegment startsat lower end of gap
Transport Layer 3-65
Fast Retransmit
Time-out period often relatively long
long delay before resending lost packet
Detect lost segments via duplicate ACKs
Sender often sends many segments back-to-backIf segment is lost there will likely be many duplicate ACKs
If sender receives 3 ACKs for the same data it supposes that segment after ACKeddata was lost
fast retransmit resend segment before timer expires
Transport Layer 3-66
Fast RetransmitResend a segment after 3 duplicate ACKs since a duplicate ACK means that an out-of sequence segment was receivedduplicate ACKs due to packet reorderingif window is small donrsquot get duplicate ACKs
Host A
tim
eout
Host B
time
X
resend seq X2
seq x1seq x2seq x3seq x4seq x5
ACK x1
ACK x1ACK x1ACK x1
tripleduplicate
ACKs
Transport Layer 3-67
event ACK received with ACK field value of y if (y gt SendBase)
SendBase = yif (there are currently not-yet-acknowledged segments)
start timer
else increment count of dup ACKs received for yif (count of dup ACKs received for y = 3)
resend segment with sequence number y
Fast retransmit algorithm
a duplicate ACK for already ACKed segment
fast retransmit
Transport Layer 3-68
TCP Flow Control
receive side of TCP connection has a receive buffer
speed-matching service matching the send rate to the receiving apprsquos drain rate
app process may be slow at reading from buffer
sender wonrsquot overflowreceiverrsquos buffer by
transmitting too muchtoo fast
flow control
Transport Layer 3-69
TCP Flow control how it works
(Suppose TCP receiver discards out-of-order segments)spare room in buffer
= RcvWin
= RcvBuffer-[LastByteRcvd -LastByteRead]
Rcvr advertises spare room by including value of RcvWin in segmentsSender limits unACKeddata to RcvWin
guarantees receive buffer doesnrsquot overflow
Transport Layer 3-70
Sliding Window Flow Control Example
3K
2K SeqNo=0
ReceiverBuffer
0 4KSendersends 2Kof data
2K
AckNo=2048 RcvWin=2048Sendersends 2Kof data 2K SeqNo=2048
4K
AckNo=4096 RcvWin=0
AckNo=4096 RcvWin=1024
Sender blocked
Transport Layer 3-71
Principles of Congestion Control
Congestioninformally ldquotoo many sources sending too much data too fast for network to handlerdquodifferent from flow controlmanifestations
lost packets (buffer overflow at routers)long delays (queueing in router buffers)
a top-10 problem
Transport Layer 3-72
Causescosts of congestion scenario 1
two senders two receiversone router infinite buffers no retransmission
large delays when congestedmaximum achievable throughput
unlimited shared output link buffers
Host Aλin original data
Host B
λout
Transport Layer 3-73
Causescosts of congestion scenario 2
one router finite buffers sender retransmission of lost packet
finite shared output link buffers
Host A λin original data
Host B
λout
λin original data plus retransmitted data
Transport Layer 3-74
Causescosts of congestion scenario 2always (goodput)ldquoperfectrdquo retransmission only when loss
retransmission of delayed (not lost) packet makes larger(than perfect case) for same
λin
λout=
λin
λoutgtλ
inλout
ldquocostsrdquo of congestionmore work (retrans) for given ldquogoodputrdquounneeded retransmissions link carries multiple copies of pkt
R2
R2λin
λ out
b
R2
R2λin
λ out
a
R2
R2λin
λ out
c
R4
R3
Transport Layer 3-75
Causescosts of congestion scenario 3four sendersmultihop pathstimeoutretransmit
λin
Q what happens as and increase λ
in
finite shared output link buffers
Host Aλin original data
Host B
λout
λin original data plus retransmitted data
Transport Layer 3-76
Causescosts of congestion scenario 3
another ldquocostrdquo of congestionwhen packet dropped any ldquoupstream transmission capacity used for that packet was wasted
Host A
Host B
λou
t
Transport Layer 3-77
Approaches towards congestion control
End-end congestion controlno explicit feedback from networkcongestion inferred from end-system observed loss delayapproach taken by TCP
Network-assisted congestion controlrouters provide feedback to end systems
single bit indicating congestion (SNA DECbit TCPIP ECN ATM)explicit rate sender should send at
Two broad approaches towards congestion control
Transport Layer 3-78
TCP Congestion Control
end-end control (no network assistance)sender limits transmissionLastByteSent-LastByteAcked
le CongWin
CongWin is dynamic function of perceived network congestion
How does sender perceive congestionloss event = timeout or3 duplicate acksTCP sender reduces rate (CongWin) after loss event
two modes of operationSlow Start (SS)Congestion avoidance (CA) or Additive Increase Multiplicative Decrease (AIMD)
Transport Layer 3-79
TCP congestion control bandwidth probing
ldquoprobing for bandwidthrdquo increase transmission rate on receipt of ACK until eventually loss occurs then decrease transmission rate
continue to increase on ACK decrease on loss (since available bandwidth is changing depending on other connections in network)
ACKs being received so increase rate
X
X
XX
X loss so decrease rate
send
ing
rate
time
Q how fast to increasedecreasedetails to follow
TCPrsquosldquosawtoothrdquobehavior
Transport Layer 3-80
TCP Congestion Control details
sender limits rate by limiting number of unACKed bytes ldquoin pipelinerdquo
cwnd differs from rwnd (how why)sender limited by min(cwndrwnd)
roughly
cwnd is dynamic function of perceived network congestion
rate = cwndRTT bytessec
LastByteSent-LastByteAcked le cwnd
cwndbytes
RTT
ACK(s)
Transport Layer 3-81
TCP Congestion Control more details
segment loss event reducing cwndtimeout no response from receiver
cut cwnd to 13 duplicate ACKs at least some segments getting through (recall fast retransmit)
cut cwnd in half less aggressively than on timeout
ACK received increase cwndTwo modes of operation
slowstart phase bull increase exponentially
fast (despite name) at connection start or following timeout
congestion avoidance bull increase linearly
Transport Layer 3-82
TCP Slow Start Phasewhen connection begins cwnd = 1 MSS
example MSS = 500 bytes amp RTT = 200 msecinitial rate = 20 kbps
available bandwidth may be gtgt MSSRTT
desirable to quickly ramp up to respectable rate
increase rate exponentially until first loss event or when threshold reached
double cwnd every RTTdone by incrementing cwnd by 1 for every ACK received
Host A
one segment
RTT
Host B
time
two segments
four segments
Transport Layer 3-83
Slow Start ExampleThe congestion window size grows very rapidly
For every ACK we increase CongWin by 1 irrespective of the number of segments ACKrsquoeddouble CongWinevery RTTinitial rate is slow but ramps up exponentially fast
TCP slows down the increase of CongWinwhen CongWin gt ssthresh
segment 1
ACK for segment 1
cwnd = 1
cwnd = 2 segment 2segment 3
ACK for segments 2
cwnd = 4 segment 4segment 5segment 6
ACK for segments 4
cwnd = 7
ACK for segments 3
ACK for segments 5
ACK for segments 6
cwnd = 3
cwnd = 5
cwnd = 6ACK for segments 7
cwnd = 8
segment 7
Transport Layer 3-84
TCP Congestion Avoidance Phase
when cwnd gt ssthreshgrow cwnd linearly
increase cwnd by 1 MSS per RTT approach possible congestion slower than in slowstartimplementation cwnd= cwnd + MSScwndfor each ACK received
ACKs increase cwndby 1 MSS per RTT additive increaseloss cut cwnd in half (non-timeout-detected loss ) multiplicative decrease
AIMD
AIMD Additive IncreaseMultiplicative Decrease
Transport Layer 3-85
Congestion AvoidanceCongestion avoidance phase is started if CongWin has reached the slow-start threshold value
If CongWin gt= ssthresh then each time an ACK is received increment CongWin as follows
bull CongWin = CongWin + 1CongWin (CongWin in segments)
bull In actual TCP implementation CongWin is in BytesCongWin = CongWin + MSS (MSSCongWin)
So CongWin is increased by one only if all CongWinsegments have been acknowledged
Transport Layer 3-86
Example Slow StartCongestion AvoidanceAssume that
ssthresh = 8
cwnd = 1
cwnd = 2
cwnd = 4
cwnd = 8
cwnd = 9
cwnd = 10
02468
101214
t=0
t=2
t=4
t=6
Roundtrip times
Cw
nd(in
seg
men
ts)
ssthresh
cwnd = 3
cwnd = 5cwnd = 6cwnd = 7
Transport Layer 3-87
Slow Start Congestion AvoidanceA typical plot of CongWin for a TCP connection
(MSS = 1500 bytes) with TCP Tahoe
SS
CA
ssthresh
Transport Layer 3-88
Responses to CongestionTCP assumes there is congestion if it detects a packet lossA TCP sender can detect lost packets via loss events
bull Timeout of a retransmission timerbull Receipt of 3 duplicate ACKs (fast retransmit)
TCP interprets a Timeout as a binary congestion signal When a timeout occurs the sender performs
ssthresh is set to half the current size of the congestion window
ssthresh = CongWin 2CongWin is reset to one
CongWin = 1and slow-start is entered
Transport Layer 3-89
Fast Recovery (differentiation btwn two loss events) After 3 dup ACKs (fast Retransmit)
ssthresh = CongWin2CongWin = CongWin2window then grows linearly
But after timeout eventCongWin = 1 MSS window then grows exponentiallyto the threshold then grows linearly
bull 3 dup ACKs indicates network capable of delivering some segmentsbull timeout before 3 dup ACKs is ldquomore alarmingrdquo
Philosophy
3-90
TCP Congestion ControlInitially
CongWin = 1ssthresh = advertised window size
New Ack receivedif (CongWin lt ssthresh) Slow Start
CongWin = CongWin + 1else Congestion Avoidance
CongWin = CongWin + 1CongWinTimeout
ssthresh = CongWin2CongWin = 1
Fast Retransmissionssthresh = CongWin2CongWin = CongWin2
Slow Start (exponential increase phase) is continued until CongWin reaches half of the level where the loss event occurred last time CongWin is increased slowly after (linear increase in Congestion Avoidance phase)
Transport Layer 3-91
Popular ldquoflavorsrdquo of TCP
ssthresh
ssthresh
TCP Tahoe
TCP Reno
Transmission round
cwnd
win
dow
siz
e (in
seg
men
ts)
Transport Layer 3-92
Summary TCP Congestion ControlWhen CongWin is below Threshold sender in slow-start phase window grows exponentiallyWhen CongWin is above Threshold sender is in congestion-avoidance phase window grows linearlyWhen a triple duplicate ACK occurs Threshold set to CongWin2 and CongWin set to ThresholdWhen timeout occurs Threshold set to CongWin2 and CongWin is set to 1 MSS The actual sender window size is determined based on the congestion and flow control algorithms
SenderWin=min(RcvWinCongWin)
Transport Layer 3-93
TCP Congestion Control SummaryEvent State TCP Sender Action Commentary
ACK receipt for previously unackeddata
Slow Start (SS)
CongWin = CongWin + MSS If (CongWin gt Threshold)
set state to ldquoCongestion Avoidancerdquo
Resulting in a doubling of CongWin every RTT
ACK receipt for previously unackeddata
CongestionAvoidance (CA)
CongWin = CongWin+MSS (MSSCongWin)
Additive increase resulting in increase of CongWin by 1 MSS every RTT
Loss event detected by triple duplicate ACK
SS or CA Threshold = CongWin2 CongWin = ThresholdSet state to ldquoCongestion Avoidancerdquo
Fast recovery implementing multiplicative decrease CongWin will not drop below 1 MSS
Timeout SS or CA Threshold = CongWin2 CongWin = 1 MSSSet state to ldquoSlow Startrdquo
Enter slow start
Duplicate ACK
SS or CA Increment duplicate ACK count for segment being acked
CongWin and Threshold not changed
Transport Layer 3-94
TCP throughput
Q whatrsquos average throughout of TCP as function of window size RTT
ignoring slow startlet W be window size when loss occurs
when window is W throughput is WRTTjust after loss window drops to W2 throughput to W2RTT average throughout 75 WRTT
Transport Layer 3-95
TCP Futures TCP over ldquolong fat pipesrdquo
example 1500 byte segments 100ms RTT want 10 Gbps throughputrequires window size W = 83333 in-flight segmentsthroughput in terms of loss rate
L = 210-10 Wownew versions of TCP for high-speed
LRTTMSSsdot221
Transport Layer 3-96
Fairness goal if K TCP sessions share same bottleneck link of bandwidth R each should have average rate of RK
TCP connection 1
bottleneckrouter
capacity R
TCP connection 2
TCP Fairness
Transport Layer 3-97
Why is TCP fairTwo competing sessions
Additive increase gives slope of 1 as throughout increasesmultiplicative decrease decreases throughput proportionally
R
R
equal bandwidth share
Connection 1 throughput
Conn
ecti
on 2
thr
ough
p ut
congestion avoidance additive increaseloss decrease window by factor of 2
congestion avoidance additive increaseloss decrease window by factor of 2
Transport Layer 3-98
Fairness (more)Fairness and UDP
Multimedia apps often do not use TCP
do not want rate throttled by congestion control
Instead use UDPpump audiovideo at constant rate tolerate packet loss
Research area TCP friendly
Fairness and parallel TCP connectionsnothing prevents app from opening parallel cnctionsbetween 2 hostsWeb browsers do this Example link of rate R supporting 9 cnctions
new app asks for 1 TCP gets rate R10new app asks for 11 TCPs gets R2
Transport Layer 3-99
TCP Connection ManagementRecall TCP sender receiver
establish ldquoconnectionrdquobefore exchanging data segmentsinitialize TCP variables
seq sbuffers flow control info (eg RcvWindow)
client connection initiatorSocket clientSocket = new Socket(hostnameport
number)
server contacted by clientSocket connectionSocket = welcomeSocketaccept()
Three way handshakeStep 1 client host sends TCP
SYN segment to serverspecifies initial seq no data
Step 2 server host receives SYN replies with SYNACK segment
server allocates buffersspecifies server initial seq
Step 3 client receives SYNACK replies with ACK segment which may contain data
Transport Layer 3-100
TCP Connection Management (cont)
Closing a connection
client closes socketclientSocketclose()
Step 1 client end system sends TCP FIN control segment to server
Step 2 server receives FIN replies with ACK Closes connection sends FIN
client
FIN
server
ACK
ACK
FIN
close
close
closed
tim
ed w
ait
Transport Layer 3-101
TCP Connection Management (cont)
Step 3 client receives FIN replies with ACK
Enters ldquotimed waitrdquo -will respond with ACK to received FINs
Step 4 server receives ACK Connection closed
client
FIN
server
ACK
ACK
FIN
closing
closing
closed
tim
ed w
ait
closed
Transport Layer 3-102
TCP Connection Management (cont)
TCP clientlifecycle
TCP serverlifecycle
Transport Layer 3-103
Tuning TCPIP Parameters TCPIP parameters
A set of default values may not be optimal for all applicationsThe network administrator may wish to turn on or off some TCPIP functions for performance or security considerations
Many Unix and Linux systems provide some flexibility in tuning the TCPIP kernelsbinsysctl is used to configure the Linux kernel parameters at runtime
Default kernel configuration file is sbinsysctlconfFrequently used sysctl options
bull sysctl ndasha or sysctl ndashA list all current valuesbull sysctl ndashp file_name load the sysctl setting from a configuration
filebull sysctl ndashw variable=value change the value of the parameter
Transport Layer 3-104
SomeTCP Parameters in Linux Kerneltcp_syn_retries
Number of SYN packets the kernel will send before giving up on the new connection
tcp_synack_retriesnumber of SYN+ACK packets sent before the kernel gives up on the connection
tcp_window_scalingMaximum window size of 65535 bytes not enough for for really fast networks The window scaling options allows for almost gigabyte windows which is good for connections with large delay-bandwidth product
tcp_max_syn_backlogMaximal number of remembered connection requests which still did not receive an acknowledgment from connecting client
tcp_fin_timeoutHow many seconds to wait for a final FIN packet before the socket is closed required to prevent denial-of-service (DoS) attacks Default value is 60 seconds
Transport Layer 3-105
SomeTCP Parameters in Linux Kerneltcp_rmem
This is a vector of 3 integers [min default max] These parameters are used by TCP to dynamically adjust receive buffer sizesmin - minimum size of the receive buffer used by each TCP socket The default value is 4K default - the default size of the receive buffer for a TCP socket The default value is 87380 bytes and is lowered to 43689 in low memory systems If larger receive buffer sizes are desired this value should be increased max - the maximum size of the receive buffer used by each TCP socket The default value of 873802 bytes is lowered to 87380 in low memory systems
tcp_smemSend buffer parameters [min default max] similar to tcp_rmem
- Chapter 3 Transport Layer
- Transport services and protocols
- Transport vs network layer
- Internet transport-layer protocols
- Multiplexingdemultiplexing
- How demultiplexing works
- Connectionless demultiplexing
- Connection-oriented demux
- Connection-oriented demux (cont)
- Connection-oriented demux Threaded Web Server
- UDP User Datagram Protocol [RFC 768]
- UDP more
- UDP checksum
- Principles of Reliable data transfer
- Reliable data transfer getting started
- Reliable data transfer getting started
- Rdt10 reliable transfer over a reliable channel
- Rdt20 channel with bit errors
- rdt20 FSM specification
- rdt20 operation with no errors
- rdt20 error scenario
- rdt20 has a fatal flaw
- rdt21 sender handles garbled ACKNAKs
- rdt21 receiver handles garbled ACKNAKs
- rdt21 discussion
- rdt22 a NAK-free protocol
- rdt22 sender receiver fragments
- rdt30 channels with errors and loss
- rdt30 sender
- rdt30 in action
- rdt30 in action
- Performance of rdt30
- rdt30 stop-and-wait operation
- Pipelined protocols
- Pipelining increased utilization
- Go-Back-N
- GBN sender extended FSM
- GBN receiver extended FSM
- GBN inaction
- Selective Repeat
- Selective repeat sender receiver windows
- Selective repeat
- Selective repeat in action
- Selective repeat dilemma
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- TCP Overview RFCs 793 1122 1323 2018 2581
- TCP segment structure
- TCP seq rsquos and ACKs
- TCP Round Trip Time and Timeout
- TCP Round Trip Time and Timeout
- Example RTT estimation
- TCP Round Trip Time and Timeout
- TCP reliable data transfer
- TCP sender events
- TCP sender(simplified)
- TCP retransmission scenarios
- TCP retransmission scenarios (more)
- TCP ACK generation [RFC 1122 RFC 2581]
- Fast Retransmit
- Fast Retransmit
- Fast retransmit algorithm
- TCP Flow Control
- TCP Flow control how it works
- Sliding Window Flow Control Example
- Principles of Congestion Control
- Causescosts of congestion scenario 1
- Causescosts of congestion scenario 2
- Causescosts of congestion scenario 2
- Causescosts of congestion scenario 3
- Causescosts of congestion scenario 3
- Approaches towards congestion control
- TCP Congestion Control
- TCP congestion control bandwidth probing
- TCP Congestion Control details
- TCP Congestion Control more details
- TCP Slow Start Phase
- Slow Start Example
- TCP Congestion Avoidance Phase
- Congestion Avoidance
- Example Slow StartCongestion Avoidance
- Slow Start Congestion Avoidance
- Responses to Congestion
- Fast Recovery (differentiation btwn two loss events)
- TCP Congestion Control
- Popular ldquoflavorsrdquo of TCP
- Summary TCP Congestion Control
- TCP Congestion Control Summary
- TCP throughput
- TCP Futures TCP over ldquolong fat pipesrdquo
- TCP Fairness
- Why is TCP fair
- Fairness (more)
- TCP Connection Management
- TCP Connection Management (cont)
- TCP Connection Management (cont)
- TCP Connection Management (cont)
- Tuning TCPIP Parameters
- SomeTCP Parameters in Linux Kernel
- SomeTCP Parameters in Linux Kernel
-
Transport Layer 3-12
UDP moreoften used for streaming multimedia apps
loss tolerantrate sensitive
other UDP usesDNSSNMP
reliable transfer over UDP add reliability at application layer
application-specific error recovery
source port dest port
32 bits
Applicationdata
(message)
UDP segment format
length checksumLength in
bytes of UDPsegmentincluding
header
Transport Layer 3-13
UDP checksum
Sendertreat segment contents as sequence of 16-bit integerschecksum addition (1rsquos complement sum) of segment contents with wraparound of carry out bitsender puts checksum value into UDP checksum field
Receivercompute checksum of received segmentcheck if computed checksum equals checksum field value
NO - error detectedYES - no error detected
Goal detect ldquoerrorsrdquo (eg flipped bits) in transmitted segment
Transport Layer 3-14
Principles of Reliable data transferimportant in app transport link layerstop-10 list of important networking topics
characteristics of unreliable channel will determine complexity of reliable data transfer protocol (rdt)
netw
ork
laye
r
Transport Layer 3-15
Reliable data transfer getting started
sendside
receiveside
rdt_send() called from above (eg by app) Passed data to
deliver to receiver upper layer
udt_send() called by rdtto transfer packet over
unreliable channel to receiver
rdt_rcv() called when packet arrives on rcv-side of channel
deliver_data() called by rdt to deliver data to upper
Transport Layer 3-16
Reliable data transfer getting startedWersquoll
incrementally develop sender receiver sides of reliable data transfer protocol (rdt)consider only unidirectional data transfer
but control info will flow on both directionsuse finite state machines (FSM) to specify sender receiver
state1
state2
event causing state transitionactions taken on state transition
state when in this ldquostaterdquo next state
uniquely determined by next event
eventactions
Transport Layer 3-17
Rdt10 reliable transfer over a reliable channel
underlying channel perfectly reliableno bit errorsno loss of packets
separate FSMs for sender receiversender sends data into underlying channelreceiver read data from underlying channel
Wait for call from above packet = make_pkt(data)
udt_send(packet)
rdt_send(data)extract (packetdata)deliver_data(data)
Wait for call from
below
rdt_rcv(packet)
sender receiver
Transport Layer 3-18
Rdt20 channel with bit errors
underlying channel may flip bits in packetrecall checksum to detect bit errors
the question how to recover from errorsacknowledgements (ACKs) receiver explicitly tells sender that pkt received OKnegative acknowledgements (NAKs) receiver explicitly tells sender that pkt had errorssender retransmits pkt on receipt of NAK
new mechanisms in rdt20 (beyond rdt10)error detectionreceiver feedback control msgs (ACKNAK) rcvr-gtsender
Transport Layer 3-19
rdt20 FSM specification
Wait for call from above
snkpkt = make_pkt(data checksum)udt_send(sndpkt)
extract(rcvpktdata)deliver_data(data)udt_send(ACK)
rdt_rcv(rcvpkt) ampamp notcorrupt(rcvpkt)
rdt_rcv(rcvpkt) ampamp isACK(rcvpkt)
udt_send(sndpkt)
rdt_rcv(rcvpkt) ampampisNAK(rcvpkt)
udt_send(NAK)
rdt_rcv(rcvpkt) ampamp corrupt(rcvpkt)
Wait for ACK or
NAK
Wait for call from
belowsender
receiverrdt_send(data)
Λ
Transport Layer 3-20
rdt20 operation with no errors
Wait for call from above
snkpkt = make_pkt(data checksum)udt_send(sndpkt)
extract(rcvpktdata)deliver_data(data)udt_send(ACK)
rdt_rcv(rcvpkt) ampamp notcorrupt(rcvpkt)
rdt_rcv(rcvpkt) ampamp isACK(rcvpkt)
udt_send(sndpkt)
rdt_rcv(rcvpkt) ampampisNAK(rcvpkt)
udt_send(NAK)
rdt_rcv(rcvpkt) ampamp corrupt(rcvpkt)
Wait for ACK or
NAK
Wait for call from
below
rdt_send(data)
Λ
Transport Layer 3-21
rdt20 error scenario
Wait for call from above
snkpkt = make_pkt(data checksum)udt_send(sndpkt)
extract(rcvpktdata)deliver_data(data)udt_send(ACK)
rdt_rcv(rcvpkt) ampamp notcorrupt(rcvpkt)
rdt_rcv(rcvpkt) ampamp isACK(rcvpkt)
udt_send(sndpkt)
rdt_rcv(rcvpkt) ampampisNAK(rcvpkt)
udt_send(NAK)
rdt_rcv(rcvpkt) ampamp corrupt(rcvpkt)
Wait for ACK or
NAK
Wait for call from
below
rdt_send(data)
Λ
Transport Layer 3-22
rdt20 has a fatal flaw
What happens if ACKNAK corruptedsender doesnrsquot know what happened at receivercanrsquot just retransmit possible duplicate
What to dosender ACKsNAKs receiverrsquos ACKNAK What if sender ACKNAK lostretransmit but this might cause retransmission of correctly received pkt
Handling duplicates sender adds sequence number to each pktsender retransmits current pkt if ACKNAK garbledreceiver discards (doesnrsquot deliver up) duplicate pkt
Sender sends one packet then waits for receiver response
stop and wait
Transport Layer 3-23
rdt21 sender handles garbled ACKNAKs
Wait for call 0 from
above
sndpkt = make_pkt(0 data checksum)udt_send(sndpkt)
rdt_send(data)
Wait for ACK or NAK 0 udt_send(sndpkt)
rdt_rcv(rcvpkt) ampamp ( corrupt(rcvpkt) ||isNAK(rcvpkt) )
sndpkt = make_pkt(1 data checksum)udt_send(sndpkt)
rdt_send(data)
rdt_rcv(rcvpkt) ampamp notcorrupt(rcvpkt) ampamp isACK(rcvpkt)
udt_send(sndpkt)
rdt_rcv(rcvpkt) ampamp ( corrupt(rcvpkt) ||isNAK(rcvpkt) )
rdt_rcv(rcvpkt) ampamp notcorrupt(rcvpkt) ampamp isACK(rcvpkt)
Wait forcall 1 from
above
Wait for ACK or NAK 1
ΛΛ
Transport Layer 3-24
rdt21 receiver handles garbled ACKNAKs
Wait for 0 from below
sndpkt = make_pkt(NAK chksum)udt_send(sndpkt)
rdt_rcv(rcvpkt) ampamp not corrupt(rcvpkt) ampamphas_seq0(rcvpkt)
rdt_rcv(rcvpkt) ampamp notcorrupt(rcvpkt) ampamp has_seq1(rcvpkt)
extract(rcvpktdata)deliver_data(data)sndpkt = make_pkt(ACK chksum)udt_send(sndpkt)
Wait for 1 from below
rdt_rcv(rcvpkt) ampamp notcorrupt(rcvpkt) ampamp has_seq0(rcvpkt)
extract(rcvpktdata)deliver_data(data)sndpkt = make_pkt(ACK chksum)udt_send(sndpkt)
rdt_rcv(rcvpkt) ampamp (corrupt(rcvpkt)
sndpkt = make_pkt(ACK chksum)udt_send(sndpkt)
rdt_rcv(rcvpkt) ampamp not corrupt(rcvpkt) ampamphas_seq1(rcvpkt)
rdt_rcv(rcvpkt) ampamp (corrupt(rcvpkt)
sndpkt = make_pkt(ACK chksum)udt_send(sndpkt)
sndpkt = make_pkt(NAK chksum)udt_send(sndpkt)
Transport Layer 3-25
rdt21 discussion
Senderseq added to pkttwo seq rsquos (01) will suffice Whymust check if received ACKNAK corrupted twice as many states
state must ldquorememberrdquowhether ldquocurrentrdquo pkt has 0 or 1 seq
Receivermust check if received packet is duplicate
state indicates whether 0 or 1 is expected pkt seq
note receiver can notknow if its last ACKNAK received OK at sender
Transport Layer 3-26
rdt22 a NAK-free protocol
same functionality as rdt21 using ACKs onlyinstead of NAK receiver sends ACK for last pkt received OK
receiver must explicitly include seq of pkt being ACKed duplicate ACK at sender results in same action as NAK retransmit current pkt
Transport Layer 3-27
rdt22 sender receiver fragments
Wait for call 0 from
above
sndpkt = make_pkt(0 data checksum)udt_send(sndpkt)
rdt_send(data)
udt_send(sndpkt)
rdt_rcv(rcvpkt) ampamp ( corrupt(rcvpkt) ||
isACK(rcvpkt1) )
rdt_rcv(rcvpkt) ampamp notcorrupt(rcvpkt) ampamp isACK(rcvpkt0)
Wait for ACK
0sender FSM
fragment
Wait for 0 from below
rdt_rcv(rcvpkt) ampamp notcorrupt(rcvpkt) ampamp has_seq1(rcvpkt)
extract(rcvpktdata)deliver_data(data)sndpkt = make_pkt(ACK1 chksum)udt_send(sndpkt)
rdt_rcv(rcvpkt) ampamp (corrupt(rcvpkt) ||
has_seq1(rcvpkt))
udt_send(sndpkt)receiver FSM
fragment
Λ
Transport Layer 3-28
rdt30 channels with errors and loss
New assumptionunderlying channel can also lose packets (data or ACKs)
checksum seq ACKs retransmissions will be of help but not enough
Q how to deal with losssender waits until certain data or ACK lost then retransmitsdrawbacks
Approach sender waits ldquoreasonablerdquo amount of time for ACK retransmits if no ACK received in this timeif pkt (or ACK) just delayed (not lost)
retransmission will be duplicate but use of seq rsquos already handles thisreceiver must specify seq of pkt being ACKed
requires countdown timer
Transport Layer 3-29
rdt30 sendersndpkt = make_pkt(0 data checksum)udt_send(sndpkt)start_timer
rdt_send(data)
Wait for
ACK0
rdt_rcv(rcvpkt) ampamp ( corrupt(rcvpkt) ||isACK(rcvpkt1) )
Wait for call 1 from
above
sndpkt = make_pkt(1 data checksum)udt_send(sndpkt)start_timer
rdt_send(data)
rdt_rcv(rcvpkt) ampamp notcorrupt(rcvpkt) ampamp isACK(rcvpkt0)
rdt_rcv(rcvpkt) ampamp ( corrupt(rcvpkt) ||isACK(rcvpkt0) )
rdt_rcv(rcvpkt) ampamp notcorrupt(rcvpkt) ampamp isACK(rcvpkt1)
stop_timerstop_timer
udt_send(sndpkt)start_timer
timeout
udt_send(sndpkt)start_timer
timeout
rdt_rcv(rcvpkt)
Wait for call 0from
above
Wait for
ACK1
Λrdt_rcv(rcvpkt)
ΛΛ
Λ
Transport Layer 3-30
rdt30 in action
Transport Layer 3-31
rdt30 in action
Transport Layer 3-32
Performance of rdt30
rdt30 works but performance stinksexample 1 Gbps link 15 ms e-e prop delay 1KB packet
Ttransmit = 8kbpkt109 bsec = 8 microsec
U sender utilization ndash fraction of time sender busy sending1KB pkt every 30 msec -gt 33kBsec thruput over 1 Gbps linknetwork protocol limits use of physical resources
U sender=
008 30008
= 000027 L RRTT + L R
=
L (packet length in bits)R (transmission rate bps) =
Transport Layer 3-33
rdt30 stop-and-wait operation
first packet bit transmitted t = 0
sender receiver
RTT
last packet bit transmitted t = L R
first packet bit arriveslast packet bit arrives send ACK
ACK arrives send next packet t = RTT + L R
U sender=
00830008
= 000027 L RRTT + L R
=
Transport Layer 3-34
Pipelined protocolsPipelining sender allows multiple ldquoin-flightrdquo yet-to-
be-acknowledged pktsrange of sequence numbers must be increasedbuffering at sender andor receiver
Two generic forms of pipelined protocols go-Back-N selective repeat
Transport Layer 3-35
Pipelining increased utilization
first packet bit transmitted t = 0
sender receiver
RTT
last bit transmitted t = L R
first packet bit arriveslast packet bit arrives send ACK
ACK arrives send next packet t = RTT + L R
last bit of 2nd packet arrives send ACKlast bit of 3rd packet arrives send ACK
U sender=
024 30008
= 000083 L RRTT + L R
=
Increase utilizationby a factor of 3
Transport Layer 3-36
Utilization=N(LR)(RTT+LR) if NLRltRTT+LR Utilization=1 if and the sender pauses after it transmits a window NLRgtRTT+LR and the of packets until it receives first ACK sender does not pause
Transport Layer 3-37
Go-Back-NSender
k-bit seq in pkt headerldquowindowrdquo of up to N consecutive unackrsquoed pkts allowed
ACK(n) ACKs all pkts up to including seq n - ldquocumulative ACKrdquomay receive duplicate ACKs (see receiver)
timer for the entire windowtimeout(n) retransmit pkt n and all higher seq pkts in window
Transport Layer 3-38
GBN sender extended FSM
Wait start_timerudt_send(sndpkt[base])udt_send(sndpkt[base+1])hellipudt_send(sndpkt[nextseqnum-1])
timeout
rdt_send(data)
if (nextseqnum lt base+N) sndpkt[nextseqnum] = make_pkt(nextseqnumdatachksum)udt_send(sndpkt[nextseqnum])if (base == nextseqnum)
start_timernextseqnum++
elserefuse_data(data)
base = getacknum(rcvpkt)+1If (base == nextseqnum)
stop_timerelse
start_timer
rdt_rcv(rcvpkt) ampamp notcorrupt(rcvpkt)
base=1nextseqnum=1
rdt_rcv(rcvpkt) ampamp corrupt(rcvpkt)
Λ
Λ
Transport Layer 3-39
GBN receiver extended FSM
ACK-only always send ACK for correctly-received pktwith highest in-order seq
may generate duplicate ACKsneed only remember expectedseqnum
out-of-order pkt discard (donrsquot buffer) -gt no receiver bufferingRe-ACK pkt with highest in-order seq
Wait
udt_send(sndpkt)default
rdt_rcv(rcvpkt)ampamp notcurrupt(rcvpkt)ampamp hasseqnum(rcvpktexpectedseqnum)
extract(rcvpktdata)deliver_data(data)sndpkt = make_pkt(expectedseqnumACKchksum)udt_send(sndpkt)expectedseqnum++
expectedseqnum=1sndpkt =
make_pkt(0ACKchksum)
Λ
Transport Layer 3-40
GBN inaction
Transport Layer 3-41
Selective Repeat
receiver individually acknowledges all correctly received pkts
buffers pkts as needed for eventual in-order delivery to upper layer
sender only resends pkts for which ACK not received
sender timer for each unACKed pktsender window
N consecutive seq rsquosagain limits seq s of sent unACKed pkts
Transport Layer 3-42
Selective repeat sender receiver windows
Transport Layer 3-43
Selective repeat
data from above if next available seq in window send pkt
timeout(n)resend pkt n restart timer
ACK(n) in [sendbasesendbase+N-1]
mark pkt n as receivedif n smallest unACKed pkt advance window base to next unACKed seq
senderpkt n in [rcvbase rcvbase+N-1]
send ACK(n)out-of-order bufferin-order deliver (also deliver buffered in-order pkts) advance window to next not-yet-received pkt
pkt n in [rcvbase-Nrcvbase-1]
ACK(n)otherwise
ignore
receiver
Transport Layer 3-44
Selective repeat in action
Transport Layer 3-45
Selective repeatdilemma
Example seq rsquos 0 1 2 3window size=3
receiver sees no difference in two scenariosincorrectly passes duplicate data as new in (a)
Q what relationship between seq size and window size
Transport Layer 3-46
Sequence Number vs Window SizeSuppose we use k bits to represent SNQuestion Whatrsquos the minimum number of bits k necessary for a window size of N
sender
receiver
Go-Back-N
expectedSN
snd_base=expectedSN
Q For a given expectedSN whatrsquos the largest possible value for snd_baseA If all the last N ACKs sent by the receiver are received
snd_base = expectedSNexpectedSN+N-1
senderrsquos window
Transport Layer 3-47
Sequence Number vs Window SizeSuppose we use k bits to represent SNQuestion Whatrsquos the minimum number of bits k necessary for a window size of N
sender
receiver
Go-Back-N
expectedSN
snd_base=expectedSN-N
Q For a given expectedSN whatrsquos the smallest possible value for snd_baseA If all the last N ACKs sent by the receiver are not received
snd_base = expectedSN-NexpectedSN-1
senderrsquos window
Transport Layer 3-48
Sequence Number vs Window Size
sender
receiver
Go-Back-N
expectedSN
snd_base=expectedSN-N
All SNs in the interval [expectedSN-NexpectedSN+N-1] (an interval of size 2N) can be received by the receiver Since the receiver accepts on the packet with SN=expectedSN there should be no other packet within this interval with SN=expectedSN Therefore
2k ge N+1expectedSN+N-1
Transport Layer 3-49
Sequence Number vs Window SizeSuppose we use k bits to represent SNQuestion Whatrsquos the minimum number of bits k necessary for a window size of N
sender
receiver
Selective Repeat
rcv_base
snd_base=rcv_base
Q For a given rcv_base whatrsquos the largest possible value for snd_baseA If all the last N ACKs sent by the receiver are received
snd_base = rcv_base (same as go_back-N)rcv_base+N-1
senderrsquos window
receiverrsquos window
rcv_base+N-1
Transport Layer 3-50
Sequence Number vs Window SizeSuppose we use k bits to represent SNQuestion Whatrsquos the minimum number of bits k necessary for a window size of N
sender
receiver
Selective Repeat
rcv_base
snd_base=rcv_base-N
Q For a given rcv_base whatrsquos the smallest possible value for snd_baseA If all the last N ACKs sent by the receiver are not received
snd_base = rcv_base-N (same as Go-Back-N)rcv_base-1
senderrsquos window
rcv_base
receiverrsquos window
rcv_base+N-1
Transport Layer 3-51
Sequence Number vs Window Size
sender
receiver
Selective Repeat
snd_base=rcv_base-N
All SNs in the interval [rcv_base-Nrcv_base+N-1] (an interval of size 2N) can be received by the receiver Since the receiver should be able to distinguish between all packets in this interval and take corresponding action there should be no two packets within thisinterval having the same SN Therefore
2k ge 2Nrcv_base+N-1
rcv_basercv_base
receiverrsquos window
rcv_base+N-1
Transport Layer 3-52
TCP Overview RFCs 793 1122 1323 2018 2581
full duplex databi-directional data flow in same connectionMSS maximum segment size
connection-orientedhandshaking (exchange of control msgs) initrsquossender receiver state before data exchange
flow controlledsender will not overwhelm receiver
point-to-pointone sender one receiver
reliable in-order byte stream
no ldquomessage boundariesrdquopipelined
TCP congestion and flow control set window size
send amp receive buffers
socketdoor
TCPsend buffer
TCPreceive buffer
socketdoor
segment
applicationwrites data
applicationreads data
Transport Layer 3-53
TCP segment structure
source port dest port
32 bits
applicationdata
(variable length)
sequence numberacknowledgement number
Receive windowUrg data pnterchecksum
FSRPAUheadlen
notused
Options (variable length)
URG urgent data (generally not used)
ACK ACK valid
PSH push data now(generally not used)
RST SYN FINconnection estab(setup teardown
commands)
bytes rcvr willingto accept
Internetchecksum
(as in UDP)
countingby bytes of data(not segments)
Transport Layer 3-54
TCP seq rsquos and ACKsSeq rsquos
byte stream ldquonumberrdquo of first byte in segmentrsquos dataACKs
seq of next byte expected from other sidecumulative ACK
Q how receiver handles out-of-order segmentsA TCP spec doesnrsquot say - up to implementationWidely used implementations of TCP buffer out-of-order segments
Transport Layer 3-55
TCP Round Trip Time and Timeout
Q how to set TCP timeout valuelonger than RTT
but RTT variestoo short premature timeout
unnecessary retransmissions
too long slow reaction to segment loss
Q how to estimate RTTSampleRTT measured time from segment transmission until ACK receipt
ignore retransmissionsSampleRTT will vary want estimated RTT ldquosmootherrdquo
average several recent measurements not just current SampleRTT
Transport Layer 3-56
TCP Round Trip Time and Timeout
EstimatedRTT = (1- α)EstimatedRTT + αSampleRTT
Exponential weighted moving averageinfluence of past sample decreases exponentially fasttypical value α = 0125
Transport Layer 3-57
Example RTT estimationRTT gaiacsumassedu to fantasiaeurecomfr
100
150
200
250
300
350
1 8 15 22 29 36 43 50 57 64 71 78 85 92 99 106
time (seconnds)
RTT
(mill
iseco
nds)
SampleRTT Estimated RTT
Transport Layer 3-58
TCP Round Trip Time and TimeoutSetting the timeout
EstimatedRTT plus ldquosafety marginrdquolarge variation in EstimatedRTT -gt larger safety margin
first estimate of how much SampleRTT deviates from EstimatedRTT
TimeoutInterval = EstimatedRTT + 4DevRTT
DevRTT = (1-β)DevRTT +β|SampleRTT-EstimatedRTT|
(typically β = 025)
Then set timeout interval
Transport Layer 3-59
TCP reliable data transfer
TCP creates rdtservice on top of IPrsquos unreliable servicePipelined segmentsCumulative acksTCP uses single retransmission timer however it just retransmits the first segment in the window
Retransmissions are triggered by
timeout eventsduplicate acks
Initially consider simplified TCP sender
ignore duplicate acksignore flow control congestion control
Transport Layer 3-60
TCP sender eventsdata rcvd from app
Create segment with seq seq is byte-stream number of first data byte in segmentstart timer if not already running (think of timer as for oldest unacked segment)expiration interval TimeOutInterval
timeoutretransmit segment that caused timeout (first segment in the window)restart timer
Ack rcvdIf acknowledges previously unacked segments
update what is known to be ackedstart timer if there are outstanding segments
Transport Layer 3-61
TCP sender(simplified)
NextSeqNum = InitialSeqNumSendBase = InitialSeqNum
loop (forever) switch(event)
event data received from application above create TCP segment with sequence number NextSeqNumif (timer currently not running)
start timerpass segment to IP NextSeqNum = NextSeqNum + length(data)
event timer timeoutretransmit not-yet-acknowledged segment with
smallest sequence numberstart timer
event ACK received with ACK field value of y if (y gt SendBase)
SendBase = yif (there are currently not-yet-acknowledged segments)
start timer
end of loop forever
Commentbull SendBase-1 last cumulatively ackrsquoed byteExamplebull SendBase-1 = 71y= 73 so the rcvrwants 73+ y gt SendBase sothat new data is acked
Transport Layer 3-62
TCP retransmission scenariosHost A
Seq=100 20 bytes data
ACK=100
timepremature timeout
Host B
Seq=92 8 bytes data
ACK=120
Seq=92 8 bytes data
Seq=
92 t
imeo
ut
ACK=120
Host A
Seq=92 8 bytes data
ACK=100
loss
tim
eout
lost ACK scenario
Host B
X
Seq=92 8 bytes data
ACK=100
time
Seq=
92 t
imeo
utSendBase
= 100
SendBase= 120
SendBase= 120
Sendbase= 100
Transport Layer 3-63
TCP retransmission scenarios (more)Host A
Seq=92 8 bytes data
ACK=100
loss
tim
eout
Cumulative ACK scenario
Host B
X
Seq=100 20 bytes data
ACK=120
time
SendBase= 120
Transport Layer 3-64
TCP ACK generation [RFC 1122 RFC 2581]
Event at Receiver
Arrival of in-order segment withexpected seq All data up toexpected seq already ACKed
Arrival of in-order segment withexpected seq One other segment has ACK pending
Arrival of out-of-order segmenthigher-than-expect seq Gap detected
Arrival of segment that partially or completely fills gap
TCP Receiver action
Delayed ACK Wait up to 500msfor next segment If no next segmentsend ACK
Immediately send single cumulative ACK ACKing both in-order segments
Immediately send duplicate ACK indicating seq of next expected byte
Immediate send ACK provided thatsegment startsat lower end of gap
Transport Layer 3-65
Fast Retransmit
Time-out period often relatively long
long delay before resending lost packet
Detect lost segments via duplicate ACKs
Sender often sends many segments back-to-backIf segment is lost there will likely be many duplicate ACKs
If sender receives 3 ACKs for the same data it supposes that segment after ACKeddata was lost
fast retransmit resend segment before timer expires
Transport Layer 3-66
Fast RetransmitResend a segment after 3 duplicate ACKs since a duplicate ACK means that an out-of sequence segment was receivedduplicate ACKs due to packet reorderingif window is small donrsquot get duplicate ACKs
Host A
tim
eout
Host B
time
X
resend seq X2
seq x1seq x2seq x3seq x4seq x5
ACK x1
ACK x1ACK x1ACK x1
tripleduplicate
ACKs
Transport Layer 3-67
event ACK received with ACK field value of y if (y gt SendBase)
SendBase = yif (there are currently not-yet-acknowledged segments)
start timer
else increment count of dup ACKs received for yif (count of dup ACKs received for y = 3)
resend segment with sequence number y
Fast retransmit algorithm
a duplicate ACK for already ACKed segment
fast retransmit
Transport Layer 3-68
TCP Flow Control
receive side of TCP connection has a receive buffer
speed-matching service matching the send rate to the receiving apprsquos drain rate
app process may be slow at reading from buffer
sender wonrsquot overflowreceiverrsquos buffer by
transmitting too muchtoo fast
flow control
Transport Layer 3-69
TCP Flow control how it works
(Suppose TCP receiver discards out-of-order segments)spare room in buffer
= RcvWin
= RcvBuffer-[LastByteRcvd -LastByteRead]
Rcvr advertises spare room by including value of RcvWin in segmentsSender limits unACKeddata to RcvWin
guarantees receive buffer doesnrsquot overflow
Transport Layer 3-70
Sliding Window Flow Control Example
3K
2K SeqNo=0
ReceiverBuffer
0 4KSendersends 2Kof data
2K
AckNo=2048 RcvWin=2048Sendersends 2Kof data 2K SeqNo=2048
4K
AckNo=4096 RcvWin=0
AckNo=4096 RcvWin=1024
Sender blocked
Transport Layer 3-71
Principles of Congestion Control
Congestioninformally ldquotoo many sources sending too much data too fast for network to handlerdquodifferent from flow controlmanifestations
lost packets (buffer overflow at routers)long delays (queueing in router buffers)
a top-10 problem
Transport Layer 3-72
Causescosts of congestion scenario 1
two senders two receiversone router infinite buffers no retransmission
large delays when congestedmaximum achievable throughput
unlimited shared output link buffers
Host Aλin original data
Host B
λout
Transport Layer 3-73
Causescosts of congestion scenario 2
one router finite buffers sender retransmission of lost packet
finite shared output link buffers
Host A λin original data
Host B
λout
λin original data plus retransmitted data
Transport Layer 3-74
Causescosts of congestion scenario 2always (goodput)ldquoperfectrdquo retransmission only when loss
retransmission of delayed (not lost) packet makes larger(than perfect case) for same
λin
λout=
λin
λoutgtλ
inλout
ldquocostsrdquo of congestionmore work (retrans) for given ldquogoodputrdquounneeded retransmissions link carries multiple copies of pkt
R2
R2λin
λ out
b
R2
R2λin
λ out
a
R2
R2λin
λ out
c
R4
R3
Transport Layer 3-75
Causescosts of congestion scenario 3four sendersmultihop pathstimeoutretransmit
λin
Q what happens as and increase λ
in
finite shared output link buffers
Host Aλin original data
Host B
λout
λin original data plus retransmitted data
Transport Layer 3-76
Causescosts of congestion scenario 3
another ldquocostrdquo of congestionwhen packet dropped any ldquoupstream transmission capacity used for that packet was wasted
Host A
Host B
λou
t
Transport Layer 3-77
Approaches towards congestion control
End-end congestion controlno explicit feedback from networkcongestion inferred from end-system observed loss delayapproach taken by TCP
Network-assisted congestion controlrouters provide feedback to end systems
single bit indicating congestion (SNA DECbit TCPIP ECN ATM)explicit rate sender should send at
Two broad approaches towards congestion control
Transport Layer 3-78
TCP Congestion Control
end-end control (no network assistance)sender limits transmissionLastByteSent-LastByteAcked
le CongWin
CongWin is dynamic function of perceived network congestion
How does sender perceive congestionloss event = timeout or3 duplicate acksTCP sender reduces rate (CongWin) after loss event
two modes of operationSlow Start (SS)Congestion avoidance (CA) or Additive Increase Multiplicative Decrease (AIMD)
Transport Layer 3-79
TCP congestion control bandwidth probing
ldquoprobing for bandwidthrdquo increase transmission rate on receipt of ACK until eventually loss occurs then decrease transmission rate
continue to increase on ACK decrease on loss (since available bandwidth is changing depending on other connections in network)
ACKs being received so increase rate
X
X
XX
X loss so decrease rate
send
ing
rate
time
Q how fast to increasedecreasedetails to follow
TCPrsquosldquosawtoothrdquobehavior
Transport Layer 3-80
TCP Congestion Control details
sender limits rate by limiting number of unACKed bytes ldquoin pipelinerdquo
cwnd differs from rwnd (how why)sender limited by min(cwndrwnd)
roughly
cwnd is dynamic function of perceived network congestion
rate = cwndRTT bytessec
LastByteSent-LastByteAcked le cwnd
cwndbytes
RTT
ACK(s)
Transport Layer 3-81
TCP Congestion Control more details
segment loss event reducing cwndtimeout no response from receiver
cut cwnd to 13 duplicate ACKs at least some segments getting through (recall fast retransmit)
cut cwnd in half less aggressively than on timeout
ACK received increase cwndTwo modes of operation
slowstart phase bull increase exponentially
fast (despite name) at connection start or following timeout
congestion avoidance bull increase linearly
Transport Layer 3-82
TCP Slow Start Phasewhen connection begins cwnd = 1 MSS
example MSS = 500 bytes amp RTT = 200 msecinitial rate = 20 kbps
available bandwidth may be gtgt MSSRTT
desirable to quickly ramp up to respectable rate
increase rate exponentially until first loss event or when threshold reached
double cwnd every RTTdone by incrementing cwnd by 1 for every ACK received
Host A
one segment
RTT
Host B
time
two segments
four segments
Transport Layer 3-83
Slow Start ExampleThe congestion window size grows very rapidly
For every ACK we increase CongWin by 1 irrespective of the number of segments ACKrsquoeddouble CongWinevery RTTinitial rate is slow but ramps up exponentially fast
TCP slows down the increase of CongWinwhen CongWin gt ssthresh
segment 1
ACK for segment 1
cwnd = 1
cwnd = 2 segment 2segment 3
ACK for segments 2
cwnd = 4 segment 4segment 5segment 6
ACK for segments 4
cwnd = 7
ACK for segments 3
ACK for segments 5
ACK for segments 6
cwnd = 3
cwnd = 5
cwnd = 6ACK for segments 7
cwnd = 8
segment 7
Transport Layer 3-84
TCP Congestion Avoidance Phase
when cwnd gt ssthreshgrow cwnd linearly
increase cwnd by 1 MSS per RTT approach possible congestion slower than in slowstartimplementation cwnd= cwnd + MSScwndfor each ACK received
ACKs increase cwndby 1 MSS per RTT additive increaseloss cut cwnd in half (non-timeout-detected loss ) multiplicative decrease
AIMD
AIMD Additive IncreaseMultiplicative Decrease
Transport Layer 3-85
Congestion AvoidanceCongestion avoidance phase is started if CongWin has reached the slow-start threshold value
If CongWin gt= ssthresh then each time an ACK is received increment CongWin as follows
bull CongWin = CongWin + 1CongWin (CongWin in segments)
bull In actual TCP implementation CongWin is in BytesCongWin = CongWin + MSS (MSSCongWin)
So CongWin is increased by one only if all CongWinsegments have been acknowledged
Transport Layer 3-86
Example Slow StartCongestion AvoidanceAssume that
ssthresh = 8
cwnd = 1
cwnd = 2
cwnd = 4
cwnd = 8
cwnd = 9
cwnd = 10
02468
101214
t=0
t=2
t=4
t=6
Roundtrip times
Cw
nd(in
seg
men
ts)
ssthresh
cwnd = 3
cwnd = 5cwnd = 6cwnd = 7
Transport Layer 3-87
Slow Start Congestion AvoidanceA typical plot of CongWin for a TCP connection
(MSS = 1500 bytes) with TCP Tahoe
SS
CA
ssthresh
Transport Layer 3-88
Responses to CongestionTCP assumes there is congestion if it detects a packet lossA TCP sender can detect lost packets via loss events
bull Timeout of a retransmission timerbull Receipt of 3 duplicate ACKs (fast retransmit)
TCP interprets a Timeout as a binary congestion signal When a timeout occurs the sender performs
ssthresh is set to half the current size of the congestion window
ssthresh = CongWin 2CongWin is reset to one
CongWin = 1and slow-start is entered
Transport Layer 3-89
Fast Recovery (differentiation btwn two loss events) After 3 dup ACKs (fast Retransmit)
ssthresh = CongWin2CongWin = CongWin2window then grows linearly
But after timeout eventCongWin = 1 MSS window then grows exponentiallyto the threshold then grows linearly
bull 3 dup ACKs indicates network capable of delivering some segmentsbull timeout before 3 dup ACKs is ldquomore alarmingrdquo
Philosophy
3-90
TCP Congestion ControlInitially
CongWin = 1ssthresh = advertised window size
New Ack receivedif (CongWin lt ssthresh) Slow Start
CongWin = CongWin + 1else Congestion Avoidance
CongWin = CongWin + 1CongWinTimeout
ssthresh = CongWin2CongWin = 1
Fast Retransmissionssthresh = CongWin2CongWin = CongWin2
Slow Start (exponential increase phase) is continued until CongWin reaches half of the level where the loss event occurred last time CongWin is increased slowly after (linear increase in Congestion Avoidance phase)
Transport Layer 3-91
Popular ldquoflavorsrdquo of TCP
ssthresh
ssthresh
TCP Tahoe
TCP Reno
Transmission round
cwnd
win
dow
siz
e (in
seg
men
ts)
Transport Layer 3-92
Summary TCP Congestion ControlWhen CongWin is below Threshold sender in slow-start phase window grows exponentiallyWhen CongWin is above Threshold sender is in congestion-avoidance phase window grows linearlyWhen a triple duplicate ACK occurs Threshold set to CongWin2 and CongWin set to ThresholdWhen timeout occurs Threshold set to CongWin2 and CongWin is set to 1 MSS The actual sender window size is determined based on the congestion and flow control algorithms
SenderWin=min(RcvWinCongWin)
Transport Layer 3-93
TCP Congestion Control SummaryEvent State TCP Sender Action Commentary
ACK receipt for previously unackeddata
Slow Start (SS)
CongWin = CongWin + MSS If (CongWin gt Threshold)
set state to ldquoCongestion Avoidancerdquo
Resulting in a doubling of CongWin every RTT
ACK receipt for previously unackeddata
CongestionAvoidance (CA)
CongWin = CongWin+MSS (MSSCongWin)
Additive increase resulting in increase of CongWin by 1 MSS every RTT
Loss event detected by triple duplicate ACK
SS or CA Threshold = CongWin2 CongWin = ThresholdSet state to ldquoCongestion Avoidancerdquo
Fast recovery implementing multiplicative decrease CongWin will not drop below 1 MSS
Timeout SS or CA Threshold = CongWin2 CongWin = 1 MSSSet state to ldquoSlow Startrdquo
Enter slow start
Duplicate ACK
SS or CA Increment duplicate ACK count for segment being acked
CongWin and Threshold not changed
Transport Layer 3-94
TCP throughput
Q whatrsquos average throughout of TCP as function of window size RTT
ignoring slow startlet W be window size when loss occurs
when window is W throughput is WRTTjust after loss window drops to W2 throughput to W2RTT average throughout 75 WRTT
Transport Layer 3-95
TCP Futures TCP over ldquolong fat pipesrdquo
example 1500 byte segments 100ms RTT want 10 Gbps throughputrequires window size W = 83333 in-flight segmentsthroughput in terms of loss rate
L = 210-10 Wownew versions of TCP for high-speed
LRTTMSSsdot221
Transport Layer 3-96
Fairness goal if K TCP sessions share same bottleneck link of bandwidth R each should have average rate of RK
TCP connection 1
bottleneckrouter
capacity R
TCP connection 2
TCP Fairness
Transport Layer 3-97
Why is TCP fairTwo competing sessions
Additive increase gives slope of 1 as throughout increasesmultiplicative decrease decreases throughput proportionally
R
R
equal bandwidth share
Connection 1 throughput
Conn
ecti
on 2
thr
ough
p ut
congestion avoidance additive increaseloss decrease window by factor of 2
congestion avoidance additive increaseloss decrease window by factor of 2
Transport Layer 3-98
Fairness (more)Fairness and UDP
Multimedia apps often do not use TCP
do not want rate throttled by congestion control
Instead use UDPpump audiovideo at constant rate tolerate packet loss
Research area TCP friendly
Fairness and parallel TCP connectionsnothing prevents app from opening parallel cnctionsbetween 2 hostsWeb browsers do this Example link of rate R supporting 9 cnctions
new app asks for 1 TCP gets rate R10new app asks for 11 TCPs gets R2
Transport Layer 3-99
TCP Connection ManagementRecall TCP sender receiver
establish ldquoconnectionrdquobefore exchanging data segmentsinitialize TCP variables
seq sbuffers flow control info (eg RcvWindow)
client connection initiatorSocket clientSocket = new Socket(hostnameport
number)
server contacted by clientSocket connectionSocket = welcomeSocketaccept()
Three way handshakeStep 1 client host sends TCP
SYN segment to serverspecifies initial seq no data
Step 2 server host receives SYN replies with SYNACK segment
server allocates buffersspecifies server initial seq
Step 3 client receives SYNACK replies with ACK segment which may contain data
Transport Layer 3-100
TCP Connection Management (cont)
Closing a connection
client closes socketclientSocketclose()
Step 1 client end system sends TCP FIN control segment to server
Step 2 server receives FIN replies with ACK Closes connection sends FIN
client
FIN
server
ACK
ACK
FIN
close
close
closed
tim
ed w
ait
Transport Layer 3-101
TCP Connection Management (cont)
Step 3 client receives FIN replies with ACK
Enters ldquotimed waitrdquo -will respond with ACK to received FINs
Step 4 server receives ACK Connection closed
client
FIN
server
ACK
ACK
FIN
closing
closing
closed
tim
ed w
ait
closed
Transport Layer 3-102
TCP Connection Management (cont)
TCP clientlifecycle
TCP serverlifecycle
Transport Layer 3-103
Tuning TCPIP Parameters TCPIP parameters
A set of default values may not be optimal for all applicationsThe network administrator may wish to turn on or off some TCPIP functions for performance or security considerations
Many Unix and Linux systems provide some flexibility in tuning the TCPIP kernelsbinsysctl is used to configure the Linux kernel parameters at runtime
Default kernel configuration file is sbinsysctlconfFrequently used sysctl options
bull sysctl ndasha or sysctl ndashA list all current valuesbull sysctl ndashp file_name load the sysctl setting from a configuration
filebull sysctl ndashw variable=value change the value of the parameter
Transport Layer 3-104
SomeTCP Parameters in Linux Kerneltcp_syn_retries
Number of SYN packets the kernel will send before giving up on the new connection
tcp_synack_retriesnumber of SYN+ACK packets sent before the kernel gives up on the connection
tcp_window_scalingMaximum window size of 65535 bytes not enough for for really fast networks The window scaling options allows for almost gigabyte windows which is good for connections with large delay-bandwidth product
tcp_max_syn_backlogMaximal number of remembered connection requests which still did not receive an acknowledgment from connecting client
tcp_fin_timeoutHow many seconds to wait for a final FIN packet before the socket is closed required to prevent denial-of-service (DoS) attacks Default value is 60 seconds
Transport Layer 3-105
SomeTCP Parameters in Linux Kerneltcp_rmem
This is a vector of 3 integers [min default max] These parameters are used by TCP to dynamically adjust receive buffer sizesmin - minimum size of the receive buffer used by each TCP socket The default value is 4K default - the default size of the receive buffer for a TCP socket The default value is 87380 bytes and is lowered to 43689 in low memory systems If larger receive buffer sizes are desired this value should be increased max - the maximum size of the receive buffer used by each TCP socket The default value of 873802 bytes is lowered to 87380 in low memory systems
tcp_smemSend buffer parameters [min default max] similar to tcp_rmem
- Chapter 3 Transport Layer
- Transport services and protocols
- Transport vs network layer
- Internet transport-layer protocols
- Multiplexingdemultiplexing
- How demultiplexing works
- Connectionless demultiplexing
- Connection-oriented demux
- Connection-oriented demux (cont)
- Connection-oriented demux Threaded Web Server
- UDP User Datagram Protocol [RFC 768]
- UDP more
- UDP checksum
- Principles of Reliable data transfer
- Reliable data transfer getting started
- Reliable data transfer getting started
- Rdt10 reliable transfer over a reliable channel
- Rdt20 channel with bit errors
- rdt20 FSM specification
- rdt20 operation with no errors
- rdt20 error scenario
- rdt20 has a fatal flaw
- rdt21 sender handles garbled ACKNAKs
- rdt21 receiver handles garbled ACKNAKs
- rdt21 discussion
- rdt22 a NAK-free protocol
- rdt22 sender receiver fragments
- rdt30 channels with errors and loss
- rdt30 sender
- rdt30 in action
- rdt30 in action
- Performance of rdt30
- rdt30 stop-and-wait operation
- Pipelined protocols
- Pipelining increased utilization
- Go-Back-N
- GBN sender extended FSM
- GBN receiver extended FSM
- GBN inaction
- Selective Repeat
- Selective repeat sender receiver windows
- Selective repeat
- Selective repeat in action
- Selective repeat dilemma
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- TCP Overview RFCs 793 1122 1323 2018 2581
- TCP segment structure
- TCP seq rsquos and ACKs
- TCP Round Trip Time and Timeout
- TCP Round Trip Time and Timeout
- Example RTT estimation
- TCP Round Trip Time and Timeout
- TCP reliable data transfer
- TCP sender events
- TCP sender(simplified)
- TCP retransmission scenarios
- TCP retransmission scenarios (more)
- TCP ACK generation [RFC 1122 RFC 2581]
- Fast Retransmit
- Fast Retransmit
- Fast retransmit algorithm
- TCP Flow Control
- TCP Flow control how it works
- Sliding Window Flow Control Example
- Principles of Congestion Control
- Causescosts of congestion scenario 1
- Causescosts of congestion scenario 2
- Causescosts of congestion scenario 2
- Causescosts of congestion scenario 3
- Causescosts of congestion scenario 3
- Approaches towards congestion control
- TCP Congestion Control
- TCP congestion control bandwidth probing
- TCP Congestion Control details
- TCP Congestion Control more details
- TCP Slow Start Phase
- Slow Start Example
- TCP Congestion Avoidance Phase
- Congestion Avoidance
- Example Slow StartCongestion Avoidance
- Slow Start Congestion Avoidance
- Responses to Congestion
- Fast Recovery (differentiation btwn two loss events)
- TCP Congestion Control
- Popular ldquoflavorsrdquo of TCP
- Summary TCP Congestion Control
- TCP Congestion Control Summary
- TCP throughput
- TCP Futures TCP over ldquolong fat pipesrdquo
- TCP Fairness
- Why is TCP fair
- Fairness (more)
- TCP Connection Management
- TCP Connection Management (cont)
- TCP Connection Management (cont)
- TCP Connection Management (cont)
- Tuning TCPIP Parameters
- SomeTCP Parameters in Linux Kernel
- SomeTCP Parameters in Linux Kernel
-
Transport Layer 3-13
UDP checksum
Sendertreat segment contents as sequence of 16-bit integerschecksum addition (1rsquos complement sum) of segment contents with wraparound of carry out bitsender puts checksum value into UDP checksum field
Receivercompute checksum of received segmentcheck if computed checksum equals checksum field value
NO - error detectedYES - no error detected
Goal detect ldquoerrorsrdquo (eg flipped bits) in transmitted segment
Transport Layer 3-14
Principles of Reliable data transferimportant in app transport link layerstop-10 list of important networking topics
characteristics of unreliable channel will determine complexity of reliable data transfer protocol (rdt)
netw
ork
laye
r
Transport Layer 3-15
Reliable data transfer getting started
sendside
receiveside
rdt_send() called from above (eg by app) Passed data to
deliver to receiver upper layer
udt_send() called by rdtto transfer packet over
unreliable channel to receiver
rdt_rcv() called when packet arrives on rcv-side of channel
deliver_data() called by rdt to deliver data to upper
Transport Layer 3-16
Reliable data transfer getting startedWersquoll
incrementally develop sender receiver sides of reliable data transfer protocol (rdt)consider only unidirectional data transfer
but control info will flow on both directionsuse finite state machines (FSM) to specify sender receiver
state1
state2
event causing state transitionactions taken on state transition
state when in this ldquostaterdquo next state
uniquely determined by next event
eventactions
Transport Layer 3-17
Rdt10 reliable transfer over a reliable channel
underlying channel perfectly reliableno bit errorsno loss of packets
separate FSMs for sender receiversender sends data into underlying channelreceiver read data from underlying channel
Wait for call from above packet = make_pkt(data)
udt_send(packet)
rdt_send(data)extract (packetdata)deliver_data(data)
Wait for call from
below
rdt_rcv(packet)
sender receiver
Transport Layer 3-18
Rdt20 channel with bit errors
underlying channel may flip bits in packetrecall checksum to detect bit errors
the question how to recover from errorsacknowledgements (ACKs) receiver explicitly tells sender that pkt received OKnegative acknowledgements (NAKs) receiver explicitly tells sender that pkt had errorssender retransmits pkt on receipt of NAK
new mechanisms in rdt20 (beyond rdt10)error detectionreceiver feedback control msgs (ACKNAK) rcvr-gtsender
Transport Layer 3-19
rdt20 FSM specification
Wait for call from above
snkpkt = make_pkt(data checksum)udt_send(sndpkt)
extract(rcvpktdata)deliver_data(data)udt_send(ACK)
rdt_rcv(rcvpkt) ampamp notcorrupt(rcvpkt)
rdt_rcv(rcvpkt) ampamp isACK(rcvpkt)
udt_send(sndpkt)
rdt_rcv(rcvpkt) ampampisNAK(rcvpkt)
udt_send(NAK)
rdt_rcv(rcvpkt) ampamp corrupt(rcvpkt)
Wait for ACK or
NAK
Wait for call from
belowsender
receiverrdt_send(data)
Λ
Transport Layer 3-20
rdt20 operation with no errors
Wait for call from above
snkpkt = make_pkt(data checksum)udt_send(sndpkt)
extract(rcvpktdata)deliver_data(data)udt_send(ACK)
rdt_rcv(rcvpkt) ampamp notcorrupt(rcvpkt)
rdt_rcv(rcvpkt) ampamp isACK(rcvpkt)
udt_send(sndpkt)
rdt_rcv(rcvpkt) ampampisNAK(rcvpkt)
udt_send(NAK)
rdt_rcv(rcvpkt) ampamp corrupt(rcvpkt)
Wait for ACK or
NAK
Wait for call from
below
rdt_send(data)
Λ
Transport Layer 3-21
rdt20 error scenario
Wait for call from above
snkpkt = make_pkt(data checksum)udt_send(sndpkt)
extract(rcvpktdata)deliver_data(data)udt_send(ACK)
rdt_rcv(rcvpkt) ampamp notcorrupt(rcvpkt)
rdt_rcv(rcvpkt) ampamp isACK(rcvpkt)
udt_send(sndpkt)
rdt_rcv(rcvpkt) ampampisNAK(rcvpkt)
udt_send(NAK)
rdt_rcv(rcvpkt) ampamp corrupt(rcvpkt)
Wait for ACK or
NAK
Wait for call from
below
rdt_send(data)
Λ
Transport Layer 3-22
rdt20 has a fatal flaw
What happens if ACKNAK corruptedsender doesnrsquot know what happened at receivercanrsquot just retransmit possible duplicate
What to dosender ACKsNAKs receiverrsquos ACKNAK What if sender ACKNAK lostretransmit but this might cause retransmission of correctly received pkt
Handling duplicates sender adds sequence number to each pktsender retransmits current pkt if ACKNAK garbledreceiver discards (doesnrsquot deliver up) duplicate pkt
Sender sends one packet then waits for receiver response
stop and wait
Transport Layer 3-23
rdt21 sender handles garbled ACKNAKs
Wait for call 0 from
above
sndpkt = make_pkt(0 data checksum)udt_send(sndpkt)
rdt_send(data)
Wait for ACK or NAK 0 udt_send(sndpkt)
rdt_rcv(rcvpkt) ampamp ( corrupt(rcvpkt) ||isNAK(rcvpkt) )
sndpkt = make_pkt(1 data checksum)udt_send(sndpkt)
rdt_send(data)
rdt_rcv(rcvpkt) ampamp notcorrupt(rcvpkt) ampamp isACK(rcvpkt)
udt_send(sndpkt)
rdt_rcv(rcvpkt) ampamp ( corrupt(rcvpkt) ||isNAK(rcvpkt) )
rdt_rcv(rcvpkt) ampamp notcorrupt(rcvpkt) ampamp isACK(rcvpkt)
Wait forcall 1 from
above
Wait for ACK or NAK 1
ΛΛ
Transport Layer 3-24
rdt21 receiver handles garbled ACKNAKs
Wait for 0 from below
sndpkt = make_pkt(NAK chksum)udt_send(sndpkt)
rdt_rcv(rcvpkt) ampamp not corrupt(rcvpkt) ampamphas_seq0(rcvpkt)
rdt_rcv(rcvpkt) ampamp notcorrupt(rcvpkt) ampamp has_seq1(rcvpkt)
extract(rcvpktdata)deliver_data(data)sndpkt = make_pkt(ACK chksum)udt_send(sndpkt)
Wait for 1 from below
rdt_rcv(rcvpkt) ampamp notcorrupt(rcvpkt) ampamp has_seq0(rcvpkt)
extract(rcvpktdata)deliver_data(data)sndpkt = make_pkt(ACK chksum)udt_send(sndpkt)
rdt_rcv(rcvpkt) ampamp (corrupt(rcvpkt)
sndpkt = make_pkt(ACK chksum)udt_send(sndpkt)
rdt_rcv(rcvpkt) ampamp not corrupt(rcvpkt) ampamphas_seq1(rcvpkt)
rdt_rcv(rcvpkt) ampamp (corrupt(rcvpkt)
sndpkt = make_pkt(ACK chksum)udt_send(sndpkt)
sndpkt = make_pkt(NAK chksum)udt_send(sndpkt)
Transport Layer 3-25
rdt21 discussion
Senderseq added to pkttwo seq rsquos (01) will suffice Whymust check if received ACKNAK corrupted twice as many states
state must ldquorememberrdquowhether ldquocurrentrdquo pkt has 0 or 1 seq
Receivermust check if received packet is duplicate
state indicates whether 0 or 1 is expected pkt seq
note receiver can notknow if its last ACKNAK received OK at sender
Transport Layer 3-26
rdt22 a NAK-free protocol
same functionality as rdt21 using ACKs onlyinstead of NAK receiver sends ACK for last pkt received OK
receiver must explicitly include seq of pkt being ACKed duplicate ACK at sender results in same action as NAK retransmit current pkt
Transport Layer 3-27
rdt22 sender receiver fragments
Wait for call 0 from
above
sndpkt = make_pkt(0 data checksum)udt_send(sndpkt)
rdt_send(data)
udt_send(sndpkt)
rdt_rcv(rcvpkt) ampamp ( corrupt(rcvpkt) ||
isACK(rcvpkt1) )
rdt_rcv(rcvpkt) ampamp notcorrupt(rcvpkt) ampamp isACK(rcvpkt0)
Wait for ACK
0sender FSM
fragment
Wait for 0 from below
rdt_rcv(rcvpkt) ampamp notcorrupt(rcvpkt) ampamp has_seq1(rcvpkt)
extract(rcvpktdata)deliver_data(data)sndpkt = make_pkt(ACK1 chksum)udt_send(sndpkt)
rdt_rcv(rcvpkt) ampamp (corrupt(rcvpkt) ||
has_seq1(rcvpkt))
udt_send(sndpkt)receiver FSM
fragment
Λ
Transport Layer 3-28
rdt30 channels with errors and loss
New assumptionunderlying channel can also lose packets (data or ACKs)
checksum seq ACKs retransmissions will be of help but not enough
Q how to deal with losssender waits until certain data or ACK lost then retransmitsdrawbacks
Approach sender waits ldquoreasonablerdquo amount of time for ACK retransmits if no ACK received in this timeif pkt (or ACK) just delayed (not lost)
retransmission will be duplicate but use of seq rsquos already handles thisreceiver must specify seq of pkt being ACKed
requires countdown timer
Transport Layer 3-29
rdt30 sendersndpkt = make_pkt(0 data checksum)udt_send(sndpkt)start_timer
rdt_send(data)
Wait for
ACK0
rdt_rcv(rcvpkt) ampamp ( corrupt(rcvpkt) ||isACK(rcvpkt1) )
Wait for call 1 from
above
sndpkt = make_pkt(1 data checksum)udt_send(sndpkt)start_timer
rdt_send(data)
rdt_rcv(rcvpkt) ampamp notcorrupt(rcvpkt) ampamp isACK(rcvpkt0)
rdt_rcv(rcvpkt) ampamp ( corrupt(rcvpkt) ||isACK(rcvpkt0) )
rdt_rcv(rcvpkt) ampamp notcorrupt(rcvpkt) ampamp isACK(rcvpkt1)
stop_timerstop_timer
udt_send(sndpkt)start_timer
timeout
udt_send(sndpkt)start_timer
timeout
rdt_rcv(rcvpkt)
Wait for call 0from
above
Wait for
ACK1
Λrdt_rcv(rcvpkt)
ΛΛ
Λ
Transport Layer 3-30
rdt30 in action
Transport Layer 3-31
rdt30 in action
Transport Layer 3-32
Performance of rdt30
rdt30 works but performance stinksexample 1 Gbps link 15 ms e-e prop delay 1KB packet
Ttransmit = 8kbpkt109 bsec = 8 microsec
U sender utilization ndash fraction of time sender busy sending1KB pkt every 30 msec -gt 33kBsec thruput over 1 Gbps linknetwork protocol limits use of physical resources
U sender=
008 30008
= 000027 L RRTT + L R
=
L (packet length in bits)R (transmission rate bps) =
Transport Layer 3-33
rdt30 stop-and-wait operation
first packet bit transmitted t = 0
sender receiver
RTT
last packet bit transmitted t = L R
first packet bit arriveslast packet bit arrives send ACK
ACK arrives send next packet t = RTT + L R
U sender=
00830008
= 000027 L RRTT + L R
=
Transport Layer 3-34
Pipelined protocolsPipelining sender allows multiple ldquoin-flightrdquo yet-to-
be-acknowledged pktsrange of sequence numbers must be increasedbuffering at sender andor receiver
Two generic forms of pipelined protocols go-Back-N selective repeat
Transport Layer 3-35
Pipelining increased utilization
first packet bit transmitted t = 0
sender receiver
RTT
last bit transmitted t = L R
first packet bit arriveslast packet bit arrives send ACK
ACK arrives send next packet t = RTT + L R
last bit of 2nd packet arrives send ACKlast bit of 3rd packet arrives send ACK
U sender=
024 30008
= 000083 L RRTT + L R
=
Increase utilizationby a factor of 3
Transport Layer 3-36
Utilization=N(LR)(RTT+LR) if NLRltRTT+LR Utilization=1 if and the sender pauses after it transmits a window NLRgtRTT+LR and the of packets until it receives first ACK sender does not pause
Transport Layer 3-37
Go-Back-NSender
k-bit seq in pkt headerldquowindowrdquo of up to N consecutive unackrsquoed pkts allowed
ACK(n) ACKs all pkts up to including seq n - ldquocumulative ACKrdquomay receive duplicate ACKs (see receiver)
timer for the entire windowtimeout(n) retransmit pkt n and all higher seq pkts in window
Transport Layer 3-38
GBN sender extended FSM
Wait start_timerudt_send(sndpkt[base])udt_send(sndpkt[base+1])hellipudt_send(sndpkt[nextseqnum-1])
timeout
rdt_send(data)
if (nextseqnum lt base+N) sndpkt[nextseqnum] = make_pkt(nextseqnumdatachksum)udt_send(sndpkt[nextseqnum])if (base == nextseqnum)
start_timernextseqnum++
elserefuse_data(data)
base = getacknum(rcvpkt)+1If (base == nextseqnum)
stop_timerelse
start_timer
rdt_rcv(rcvpkt) ampamp notcorrupt(rcvpkt)
base=1nextseqnum=1
rdt_rcv(rcvpkt) ampamp corrupt(rcvpkt)
Λ
Λ
Transport Layer 3-39
GBN receiver extended FSM
ACK-only always send ACK for correctly-received pktwith highest in-order seq
may generate duplicate ACKsneed only remember expectedseqnum
out-of-order pkt discard (donrsquot buffer) -gt no receiver bufferingRe-ACK pkt with highest in-order seq
Wait
udt_send(sndpkt)default
rdt_rcv(rcvpkt)ampamp notcurrupt(rcvpkt)ampamp hasseqnum(rcvpktexpectedseqnum)
extract(rcvpktdata)deliver_data(data)sndpkt = make_pkt(expectedseqnumACKchksum)udt_send(sndpkt)expectedseqnum++
expectedseqnum=1sndpkt =
make_pkt(0ACKchksum)
Λ
Transport Layer 3-40
GBN inaction
Transport Layer 3-41
Selective Repeat
receiver individually acknowledges all correctly received pkts
buffers pkts as needed for eventual in-order delivery to upper layer
sender only resends pkts for which ACK not received
sender timer for each unACKed pktsender window
N consecutive seq rsquosagain limits seq s of sent unACKed pkts
Transport Layer 3-42
Selective repeat sender receiver windows
Transport Layer 3-43
Selective repeat
data from above if next available seq in window send pkt
timeout(n)resend pkt n restart timer
ACK(n) in [sendbasesendbase+N-1]
mark pkt n as receivedif n smallest unACKed pkt advance window base to next unACKed seq
senderpkt n in [rcvbase rcvbase+N-1]
send ACK(n)out-of-order bufferin-order deliver (also deliver buffered in-order pkts) advance window to next not-yet-received pkt
pkt n in [rcvbase-Nrcvbase-1]
ACK(n)otherwise
ignore
receiver
Transport Layer 3-44
Selective repeat in action
Transport Layer 3-45
Selective repeatdilemma
Example seq rsquos 0 1 2 3window size=3
receiver sees no difference in two scenariosincorrectly passes duplicate data as new in (a)
Q what relationship between seq size and window size
Transport Layer 3-46
Sequence Number vs Window SizeSuppose we use k bits to represent SNQuestion Whatrsquos the minimum number of bits k necessary for a window size of N
sender
receiver
Go-Back-N
expectedSN
snd_base=expectedSN
Q For a given expectedSN whatrsquos the largest possible value for snd_baseA If all the last N ACKs sent by the receiver are received
snd_base = expectedSNexpectedSN+N-1
senderrsquos window
Transport Layer 3-47
Sequence Number vs Window SizeSuppose we use k bits to represent SNQuestion Whatrsquos the minimum number of bits k necessary for a window size of N
sender
receiver
Go-Back-N
expectedSN
snd_base=expectedSN-N
Q For a given expectedSN whatrsquos the smallest possible value for snd_baseA If all the last N ACKs sent by the receiver are not received
snd_base = expectedSN-NexpectedSN-1
senderrsquos window
Transport Layer 3-48
Sequence Number vs Window Size
sender
receiver
Go-Back-N
expectedSN
snd_base=expectedSN-N
All SNs in the interval [expectedSN-NexpectedSN+N-1] (an interval of size 2N) can be received by the receiver Since the receiver accepts on the packet with SN=expectedSN there should be no other packet within this interval with SN=expectedSN Therefore
2k ge N+1expectedSN+N-1
Transport Layer 3-49
Sequence Number vs Window SizeSuppose we use k bits to represent SNQuestion Whatrsquos the minimum number of bits k necessary for a window size of N
sender
receiver
Selective Repeat
rcv_base
snd_base=rcv_base
Q For a given rcv_base whatrsquos the largest possible value for snd_baseA If all the last N ACKs sent by the receiver are received
snd_base = rcv_base (same as go_back-N)rcv_base+N-1
senderrsquos window
receiverrsquos window
rcv_base+N-1
Transport Layer 3-50
Sequence Number vs Window SizeSuppose we use k bits to represent SNQuestion Whatrsquos the minimum number of bits k necessary for a window size of N
sender
receiver
Selective Repeat
rcv_base
snd_base=rcv_base-N
Q For a given rcv_base whatrsquos the smallest possible value for snd_baseA If all the last N ACKs sent by the receiver are not received
snd_base = rcv_base-N (same as Go-Back-N)rcv_base-1
senderrsquos window
rcv_base
receiverrsquos window
rcv_base+N-1
Transport Layer 3-51
Sequence Number vs Window Size
sender
receiver
Selective Repeat
snd_base=rcv_base-N
All SNs in the interval [rcv_base-Nrcv_base+N-1] (an interval of size 2N) can be received by the receiver Since the receiver should be able to distinguish between all packets in this interval and take corresponding action there should be no two packets within thisinterval having the same SN Therefore
2k ge 2Nrcv_base+N-1
rcv_basercv_base
receiverrsquos window
rcv_base+N-1
Transport Layer 3-52
TCP Overview RFCs 793 1122 1323 2018 2581
full duplex databi-directional data flow in same connectionMSS maximum segment size
connection-orientedhandshaking (exchange of control msgs) initrsquossender receiver state before data exchange
flow controlledsender will not overwhelm receiver
point-to-pointone sender one receiver
reliable in-order byte stream
no ldquomessage boundariesrdquopipelined
TCP congestion and flow control set window size
send amp receive buffers
socketdoor
TCPsend buffer
TCPreceive buffer
socketdoor
segment
applicationwrites data
applicationreads data
Transport Layer 3-53
TCP segment structure
source port dest port
32 bits
applicationdata
(variable length)
sequence numberacknowledgement number
Receive windowUrg data pnterchecksum
FSRPAUheadlen
notused
Options (variable length)
URG urgent data (generally not used)
ACK ACK valid
PSH push data now(generally not used)
RST SYN FINconnection estab(setup teardown
commands)
bytes rcvr willingto accept
Internetchecksum
(as in UDP)
countingby bytes of data(not segments)
Transport Layer 3-54
TCP seq rsquos and ACKsSeq rsquos
byte stream ldquonumberrdquo of first byte in segmentrsquos dataACKs
seq of next byte expected from other sidecumulative ACK
Q how receiver handles out-of-order segmentsA TCP spec doesnrsquot say - up to implementationWidely used implementations of TCP buffer out-of-order segments
Transport Layer 3-55
TCP Round Trip Time and Timeout
Q how to set TCP timeout valuelonger than RTT
but RTT variestoo short premature timeout
unnecessary retransmissions
too long slow reaction to segment loss
Q how to estimate RTTSampleRTT measured time from segment transmission until ACK receipt
ignore retransmissionsSampleRTT will vary want estimated RTT ldquosmootherrdquo
average several recent measurements not just current SampleRTT
Transport Layer 3-56
TCP Round Trip Time and Timeout
EstimatedRTT = (1- α)EstimatedRTT + αSampleRTT
Exponential weighted moving averageinfluence of past sample decreases exponentially fasttypical value α = 0125
Transport Layer 3-57
Example RTT estimationRTT gaiacsumassedu to fantasiaeurecomfr
100
150
200
250
300
350
1 8 15 22 29 36 43 50 57 64 71 78 85 92 99 106
time (seconnds)
RTT
(mill
iseco
nds)
SampleRTT Estimated RTT
Transport Layer 3-58
TCP Round Trip Time and TimeoutSetting the timeout
EstimatedRTT plus ldquosafety marginrdquolarge variation in EstimatedRTT -gt larger safety margin
first estimate of how much SampleRTT deviates from EstimatedRTT
TimeoutInterval = EstimatedRTT + 4DevRTT
DevRTT = (1-β)DevRTT +β|SampleRTT-EstimatedRTT|
(typically β = 025)
Then set timeout interval
Transport Layer 3-59
TCP reliable data transfer
TCP creates rdtservice on top of IPrsquos unreliable servicePipelined segmentsCumulative acksTCP uses single retransmission timer however it just retransmits the first segment in the window
Retransmissions are triggered by
timeout eventsduplicate acks
Initially consider simplified TCP sender
ignore duplicate acksignore flow control congestion control
Transport Layer 3-60
TCP sender eventsdata rcvd from app
Create segment with seq seq is byte-stream number of first data byte in segmentstart timer if not already running (think of timer as for oldest unacked segment)expiration interval TimeOutInterval
timeoutretransmit segment that caused timeout (first segment in the window)restart timer
Ack rcvdIf acknowledges previously unacked segments
update what is known to be ackedstart timer if there are outstanding segments
Transport Layer 3-61
TCP sender(simplified)
NextSeqNum = InitialSeqNumSendBase = InitialSeqNum
loop (forever) switch(event)
event data received from application above create TCP segment with sequence number NextSeqNumif (timer currently not running)
start timerpass segment to IP NextSeqNum = NextSeqNum + length(data)
event timer timeoutretransmit not-yet-acknowledged segment with
smallest sequence numberstart timer
event ACK received with ACK field value of y if (y gt SendBase)
SendBase = yif (there are currently not-yet-acknowledged segments)
start timer
end of loop forever
Commentbull SendBase-1 last cumulatively ackrsquoed byteExamplebull SendBase-1 = 71y= 73 so the rcvrwants 73+ y gt SendBase sothat new data is acked
Transport Layer 3-62
TCP retransmission scenariosHost A
Seq=100 20 bytes data
ACK=100
timepremature timeout
Host B
Seq=92 8 bytes data
ACK=120
Seq=92 8 bytes data
Seq=
92 t
imeo
ut
ACK=120
Host A
Seq=92 8 bytes data
ACK=100
loss
tim
eout
lost ACK scenario
Host B
X
Seq=92 8 bytes data
ACK=100
time
Seq=
92 t
imeo
utSendBase
= 100
SendBase= 120
SendBase= 120
Sendbase= 100
Transport Layer 3-63
TCP retransmission scenarios (more)Host A
Seq=92 8 bytes data
ACK=100
loss
tim
eout
Cumulative ACK scenario
Host B
X
Seq=100 20 bytes data
ACK=120
time
SendBase= 120
Transport Layer 3-64
TCP ACK generation [RFC 1122 RFC 2581]
Event at Receiver
Arrival of in-order segment withexpected seq All data up toexpected seq already ACKed
Arrival of in-order segment withexpected seq One other segment has ACK pending
Arrival of out-of-order segmenthigher-than-expect seq Gap detected
Arrival of segment that partially or completely fills gap
TCP Receiver action
Delayed ACK Wait up to 500msfor next segment If no next segmentsend ACK
Immediately send single cumulative ACK ACKing both in-order segments
Immediately send duplicate ACK indicating seq of next expected byte
Immediate send ACK provided thatsegment startsat lower end of gap
Transport Layer 3-65
Fast Retransmit
Time-out period often relatively long
long delay before resending lost packet
Detect lost segments via duplicate ACKs
Sender often sends many segments back-to-backIf segment is lost there will likely be many duplicate ACKs
If sender receives 3 ACKs for the same data it supposes that segment after ACKeddata was lost
fast retransmit resend segment before timer expires
Transport Layer 3-66
Fast RetransmitResend a segment after 3 duplicate ACKs since a duplicate ACK means that an out-of sequence segment was receivedduplicate ACKs due to packet reorderingif window is small donrsquot get duplicate ACKs
Host A
tim
eout
Host B
time
X
resend seq X2
seq x1seq x2seq x3seq x4seq x5
ACK x1
ACK x1ACK x1ACK x1
tripleduplicate
ACKs
Transport Layer 3-67
event ACK received with ACK field value of y if (y gt SendBase)
SendBase = yif (there are currently not-yet-acknowledged segments)
start timer
else increment count of dup ACKs received for yif (count of dup ACKs received for y = 3)
resend segment with sequence number y
Fast retransmit algorithm
a duplicate ACK for already ACKed segment
fast retransmit
Transport Layer 3-68
TCP Flow Control
receive side of TCP connection has a receive buffer
speed-matching service matching the send rate to the receiving apprsquos drain rate
app process may be slow at reading from buffer
sender wonrsquot overflowreceiverrsquos buffer by
transmitting too muchtoo fast
flow control
Transport Layer 3-69
TCP Flow control how it works
(Suppose TCP receiver discards out-of-order segments)spare room in buffer
= RcvWin
= RcvBuffer-[LastByteRcvd -LastByteRead]
Rcvr advertises spare room by including value of RcvWin in segmentsSender limits unACKeddata to RcvWin
guarantees receive buffer doesnrsquot overflow
Transport Layer 3-70
Sliding Window Flow Control Example
3K
2K SeqNo=0
ReceiverBuffer
0 4KSendersends 2Kof data
2K
AckNo=2048 RcvWin=2048Sendersends 2Kof data 2K SeqNo=2048
4K
AckNo=4096 RcvWin=0
AckNo=4096 RcvWin=1024
Sender blocked
Transport Layer 3-71
Principles of Congestion Control
Congestioninformally ldquotoo many sources sending too much data too fast for network to handlerdquodifferent from flow controlmanifestations
lost packets (buffer overflow at routers)long delays (queueing in router buffers)
a top-10 problem
Transport Layer 3-72
Causescosts of congestion scenario 1
two senders two receiversone router infinite buffers no retransmission
large delays when congestedmaximum achievable throughput
unlimited shared output link buffers
Host Aλin original data
Host B
λout
Transport Layer 3-73
Causescosts of congestion scenario 2
one router finite buffers sender retransmission of lost packet
finite shared output link buffers
Host A λin original data
Host B
λout
λin original data plus retransmitted data
Transport Layer 3-74
Causescosts of congestion scenario 2always (goodput)ldquoperfectrdquo retransmission only when loss
retransmission of delayed (not lost) packet makes larger(than perfect case) for same
λin
λout=
λin
λoutgtλ
inλout
ldquocostsrdquo of congestionmore work (retrans) for given ldquogoodputrdquounneeded retransmissions link carries multiple copies of pkt
R2
R2λin
λ out
b
R2
R2λin
λ out
a
R2
R2λin
λ out
c
R4
R3
Transport Layer 3-75
Causescosts of congestion scenario 3four sendersmultihop pathstimeoutretransmit
λin
Q what happens as and increase λ
in
finite shared output link buffers
Host Aλin original data
Host B
λout
λin original data plus retransmitted data
Transport Layer 3-76
Causescosts of congestion scenario 3
another ldquocostrdquo of congestionwhen packet dropped any ldquoupstream transmission capacity used for that packet was wasted
Host A
Host B
λou
t
Transport Layer 3-77
Approaches towards congestion control
End-end congestion controlno explicit feedback from networkcongestion inferred from end-system observed loss delayapproach taken by TCP
Network-assisted congestion controlrouters provide feedback to end systems
single bit indicating congestion (SNA DECbit TCPIP ECN ATM)explicit rate sender should send at
Two broad approaches towards congestion control
Transport Layer 3-78
TCP Congestion Control
end-end control (no network assistance)sender limits transmissionLastByteSent-LastByteAcked
le CongWin
CongWin is dynamic function of perceived network congestion
How does sender perceive congestionloss event = timeout or3 duplicate acksTCP sender reduces rate (CongWin) after loss event
two modes of operationSlow Start (SS)Congestion avoidance (CA) or Additive Increase Multiplicative Decrease (AIMD)
Transport Layer 3-79
TCP congestion control bandwidth probing
ldquoprobing for bandwidthrdquo increase transmission rate on receipt of ACK until eventually loss occurs then decrease transmission rate
continue to increase on ACK decrease on loss (since available bandwidth is changing depending on other connections in network)
ACKs being received so increase rate
X
X
XX
X loss so decrease rate
send
ing
rate
time
Q how fast to increasedecreasedetails to follow
TCPrsquosldquosawtoothrdquobehavior
Transport Layer 3-80
TCP Congestion Control details
sender limits rate by limiting number of unACKed bytes ldquoin pipelinerdquo
cwnd differs from rwnd (how why)sender limited by min(cwndrwnd)
roughly
cwnd is dynamic function of perceived network congestion
rate = cwndRTT bytessec
LastByteSent-LastByteAcked le cwnd
cwndbytes
RTT
ACK(s)
Transport Layer 3-81
TCP Congestion Control more details
segment loss event reducing cwndtimeout no response from receiver
cut cwnd to 13 duplicate ACKs at least some segments getting through (recall fast retransmit)
cut cwnd in half less aggressively than on timeout
ACK received increase cwndTwo modes of operation
slowstart phase bull increase exponentially
fast (despite name) at connection start or following timeout
congestion avoidance bull increase linearly
Transport Layer 3-82
TCP Slow Start Phasewhen connection begins cwnd = 1 MSS
example MSS = 500 bytes amp RTT = 200 msecinitial rate = 20 kbps
available bandwidth may be gtgt MSSRTT
desirable to quickly ramp up to respectable rate
increase rate exponentially until first loss event or when threshold reached
double cwnd every RTTdone by incrementing cwnd by 1 for every ACK received
Host A
one segment
RTT
Host B
time
two segments
four segments
Transport Layer 3-83
Slow Start ExampleThe congestion window size grows very rapidly
For every ACK we increase CongWin by 1 irrespective of the number of segments ACKrsquoeddouble CongWinevery RTTinitial rate is slow but ramps up exponentially fast
TCP slows down the increase of CongWinwhen CongWin gt ssthresh
segment 1
ACK for segment 1
cwnd = 1
cwnd = 2 segment 2segment 3
ACK for segments 2
cwnd = 4 segment 4segment 5segment 6
ACK for segments 4
cwnd = 7
ACK for segments 3
ACK for segments 5
ACK for segments 6
cwnd = 3
cwnd = 5
cwnd = 6ACK for segments 7
cwnd = 8
segment 7
Transport Layer 3-84
TCP Congestion Avoidance Phase
when cwnd gt ssthreshgrow cwnd linearly
increase cwnd by 1 MSS per RTT approach possible congestion slower than in slowstartimplementation cwnd= cwnd + MSScwndfor each ACK received
ACKs increase cwndby 1 MSS per RTT additive increaseloss cut cwnd in half (non-timeout-detected loss ) multiplicative decrease
AIMD
AIMD Additive IncreaseMultiplicative Decrease
Transport Layer 3-85
Congestion AvoidanceCongestion avoidance phase is started if CongWin has reached the slow-start threshold value
If CongWin gt= ssthresh then each time an ACK is received increment CongWin as follows
bull CongWin = CongWin + 1CongWin (CongWin in segments)
bull In actual TCP implementation CongWin is in BytesCongWin = CongWin + MSS (MSSCongWin)
So CongWin is increased by one only if all CongWinsegments have been acknowledged
Transport Layer 3-86
Example Slow StartCongestion AvoidanceAssume that
ssthresh = 8
cwnd = 1
cwnd = 2
cwnd = 4
cwnd = 8
cwnd = 9
cwnd = 10
02468
101214
t=0
t=2
t=4
t=6
Roundtrip times
Cw
nd(in
seg
men
ts)
ssthresh
cwnd = 3
cwnd = 5cwnd = 6cwnd = 7
Transport Layer 3-87
Slow Start Congestion AvoidanceA typical plot of CongWin for a TCP connection
(MSS = 1500 bytes) with TCP Tahoe
SS
CA
ssthresh
Transport Layer 3-88
Responses to CongestionTCP assumes there is congestion if it detects a packet lossA TCP sender can detect lost packets via loss events
bull Timeout of a retransmission timerbull Receipt of 3 duplicate ACKs (fast retransmit)
TCP interprets a Timeout as a binary congestion signal When a timeout occurs the sender performs
ssthresh is set to half the current size of the congestion window
ssthresh = CongWin 2CongWin is reset to one
CongWin = 1and slow-start is entered
Transport Layer 3-89
Fast Recovery (differentiation btwn two loss events) After 3 dup ACKs (fast Retransmit)
ssthresh = CongWin2CongWin = CongWin2window then grows linearly
But after timeout eventCongWin = 1 MSS window then grows exponentiallyto the threshold then grows linearly
bull 3 dup ACKs indicates network capable of delivering some segmentsbull timeout before 3 dup ACKs is ldquomore alarmingrdquo
Philosophy
3-90
TCP Congestion ControlInitially
CongWin = 1ssthresh = advertised window size
New Ack receivedif (CongWin lt ssthresh) Slow Start
CongWin = CongWin + 1else Congestion Avoidance
CongWin = CongWin + 1CongWinTimeout
ssthresh = CongWin2CongWin = 1
Fast Retransmissionssthresh = CongWin2CongWin = CongWin2
Slow Start (exponential increase phase) is continued until CongWin reaches half of the level where the loss event occurred last time CongWin is increased slowly after (linear increase in Congestion Avoidance phase)
Transport Layer 3-91
Popular ldquoflavorsrdquo of TCP
ssthresh
ssthresh
TCP Tahoe
TCP Reno
Transmission round
cwnd
win
dow
siz
e (in
seg
men
ts)
Transport Layer 3-92
Summary TCP Congestion ControlWhen CongWin is below Threshold sender in slow-start phase window grows exponentiallyWhen CongWin is above Threshold sender is in congestion-avoidance phase window grows linearlyWhen a triple duplicate ACK occurs Threshold set to CongWin2 and CongWin set to ThresholdWhen timeout occurs Threshold set to CongWin2 and CongWin is set to 1 MSS The actual sender window size is determined based on the congestion and flow control algorithms
SenderWin=min(RcvWinCongWin)
Transport Layer 3-93
TCP Congestion Control SummaryEvent State TCP Sender Action Commentary
ACK receipt for previously unackeddata
Slow Start (SS)
CongWin = CongWin + MSS If (CongWin gt Threshold)
set state to ldquoCongestion Avoidancerdquo
Resulting in a doubling of CongWin every RTT
ACK receipt for previously unackeddata
CongestionAvoidance (CA)
CongWin = CongWin+MSS (MSSCongWin)
Additive increase resulting in increase of CongWin by 1 MSS every RTT
Loss event detected by triple duplicate ACK
SS or CA Threshold = CongWin2 CongWin = ThresholdSet state to ldquoCongestion Avoidancerdquo
Fast recovery implementing multiplicative decrease CongWin will not drop below 1 MSS
Timeout SS or CA Threshold = CongWin2 CongWin = 1 MSSSet state to ldquoSlow Startrdquo
Enter slow start
Duplicate ACK
SS or CA Increment duplicate ACK count for segment being acked
CongWin and Threshold not changed
Transport Layer 3-94
TCP throughput
Q whatrsquos average throughout of TCP as function of window size RTT
ignoring slow startlet W be window size when loss occurs
when window is W throughput is WRTTjust after loss window drops to W2 throughput to W2RTT average throughout 75 WRTT
Transport Layer 3-95
TCP Futures TCP over ldquolong fat pipesrdquo
example 1500 byte segments 100ms RTT want 10 Gbps throughputrequires window size W = 83333 in-flight segmentsthroughput in terms of loss rate
L = 210-10 Wownew versions of TCP for high-speed
LRTTMSSsdot221
Transport Layer 3-96
Fairness goal if K TCP sessions share same bottleneck link of bandwidth R each should have average rate of RK
TCP connection 1
bottleneckrouter
capacity R
TCP connection 2
TCP Fairness
Transport Layer 3-97
Why is TCP fairTwo competing sessions
Additive increase gives slope of 1 as throughout increasesmultiplicative decrease decreases throughput proportionally
R
R
equal bandwidth share
Connection 1 throughput
Conn
ecti
on 2
thr
ough
p ut
congestion avoidance additive increaseloss decrease window by factor of 2
congestion avoidance additive increaseloss decrease window by factor of 2
Transport Layer 3-98
Fairness (more)Fairness and UDP
Multimedia apps often do not use TCP
do not want rate throttled by congestion control
Instead use UDPpump audiovideo at constant rate tolerate packet loss
Research area TCP friendly
Fairness and parallel TCP connectionsnothing prevents app from opening parallel cnctionsbetween 2 hostsWeb browsers do this Example link of rate R supporting 9 cnctions
new app asks for 1 TCP gets rate R10new app asks for 11 TCPs gets R2
Transport Layer 3-99
TCP Connection ManagementRecall TCP sender receiver
establish ldquoconnectionrdquobefore exchanging data segmentsinitialize TCP variables
seq sbuffers flow control info (eg RcvWindow)
client connection initiatorSocket clientSocket = new Socket(hostnameport
number)
server contacted by clientSocket connectionSocket = welcomeSocketaccept()
Three way handshakeStep 1 client host sends TCP
SYN segment to serverspecifies initial seq no data
Step 2 server host receives SYN replies with SYNACK segment
server allocates buffersspecifies server initial seq
Step 3 client receives SYNACK replies with ACK segment which may contain data
Transport Layer 3-100
TCP Connection Management (cont)
Closing a connection
client closes socketclientSocketclose()
Step 1 client end system sends TCP FIN control segment to server
Step 2 server receives FIN replies with ACK Closes connection sends FIN
client
FIN
server
ACK
ACK
FIN
close
close
closed
tim
ed w
ait
Transport Layer 3-101
TCP Connection Management (cont)
Step 3 client receives FIN replies with ACK
Enters ldquotimed waitrdquo -will respond with ACK to received FINs
Step 4 server receives ACK Connection closed
client
FIN
server
ACK
ACK
FIN
closing
closing
closed
tim
ed w
ait
closed
Transport Layer 3-102
TCP Connection Management (cont)
TCP clientlifecycle
TCP serverlifecycle
Transport Layer 3-103
Tuning TCPIP Parameters TCPIP parameters
A set of default values may not be optimal for all applicationsThe network administrator may wish to turn on or off some TCPIP functions for performance or security considerations
Many Unix and Linux systems provide some flexibility in tuning the TCPIP kernelsbinsysctl is used to configure the Linux kernel parameters at runtime
Default kernel configuration file is sbinsysctlconfFrequently used sysctl options
bull sysctl ndasha or sysctl ndashA list all current valuesbull sysctl ndashp file_name load the sysctl setting from a configuration
filebull sysctl ndashw variable=value change the value of the parameter
Transport Layer 3-104
SomeTCP Parameters in Linux Kerneltcp_syn_retries
Number of SYN packets the kernel will send before giving up on the new connection
tcp_synack_retriesnumber of SYN+ACK packets sent before the kernel gives up on the connection
tcp_window_scalingMaximum window size of 65535 bytes not enough for for really fast networks The window scaling options allows for almost gigabyte windows which is good for connections with large delay-bandwidth product
tcp_max_syn_backlogMaximal number of remembered connection requests which still did not receive an acknowledgment from connecting client
tcp_fin_timeoutHow many seconds to wait for a final FIN packet before the socket is closed required to prevent denial-of-service (DoS) attacks Default value is 60 seconds
Transport Layer 3-105
SomeTCP Parameters in Linux Kerneltcp_rmem
This is a vector of 3 integers [min default max] These parameters are used by TCP to dynamically adjust receive buffer sizesmin - minimum size of the receive buffer used by each TCP socket The default value is 4K default - the default size of the receive buffer for a TCP socket The default value is 87380 bytes and is lowered to 43689 in low memory systems If larger receive buffer sizes are desired this value should be increased max - the maximum size of the receive buffer used by each TCP socket The default value of 873802 bytes is lowered to 87380 in low memory systems
tcp_smemSend buffer parameters [min default max] similar to tcp_rmem
- Chapter 3 Transport Layer
- Transport services and protocols
- Transport vs network layer
- Internet transport-layer protocols
- Multiplexingdemultiplexing
- How demultiplexing works
- Connectionless demultiplexing
- Connection-oriented demux
- Connection-oriented demux (cont)
- Connection-oriented demux Threaded Web Server
- UDP User Datagram Protocol [RFC 768]
- UDP more
- UDP checksum
- Principles of Reliable data transfer
- Reliable data transfer getting started
- Reliable data transfer getting started
- Rdt10 reliable transfer over a reliable channel
- Rdt20 channel with bit errors
- rdt20 FSM specification
- rdt20 operation with no errors
- rdt20 error scenario
- rdt20 has a fatal flaw
- rdt21 sender handles garbled ACKNAKs
- rdt21 receiver handles garbled ACKNAKs
- rdt21 discussion
- rdt22 a NAK-free protocol
- rdt22 sender receiver fragments
- rdt30 channels with errors and loss
- rdt30 sender
- rdt30 in action
- rdt30 in action
- Performance of rdt30
- rdt30 stop-and-wait operation
- Pipelined protocols
- Pipelining increased utilization
- Go-Back-N
- GBN sender extended FSM
- GBN receiver extended FSM
- GBN inaction
- Selective Repeat
- Selective repeat sender receiver windows
- Selective repeat
- Selective repeat in action
- Selective repeat dilemma
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- TCP Overview RFCs 793 1122 1323 2018 2581
- TCP segment structure
- TCP seq rsquos and ACKs
- TCP Round Trip Time and Timeout
- TCP Round Trip Time and Timeout
- Example RTT estimation
- TCP Round Trip Time and Timeout
- TCP reliable data transfer
- TCP sender events
- TCP sender(simplified)
- TCP retransmission scenarios
- TCP retransmission scenarios (more)
- TCP ACK generation [RFC 1122 RFC 2581]
- Fast Retransmit
- Fast Retransmit
- Fast retransmit algorithm
- TCP Flow Control
- TCP Flow control how it works
- Sliding Window Flow Control Example
- Principles of Congestion Control
- Causescosts of congestion scenario 1
- Causescosts of congestion scenario 2
- Causescosts of congestion scenario 2
- Causescosts of congestion scenario 3
- Causescosts of congestion scenario 3
- Approaches towards congestion control
- TCP Congestion Control
- TCP congestion control bandwidth probing
- TCP Congestion Control details
- TCP Congestion Control more details
- TCP Slow Start Phase
- Slow Start Example
- TCP Congestion Avoidance Phase
- Congestion Avoidance
- Example Slow StartCongestion Avoidance
- Slow Start Congestion Avoidance
- Responses to Congestion
- Fast Recovery (differentiation btwn two loss events)
- TCP Congestion Control
- Popular ldquoflavorsrdquo of TCP
- Summary TCP Congestion Control
- TCP Congestion Control Summary
- TCP throughput
- TCP Futures TCP over ldquolong fat pipesrdquo
- TCP Fairness
- Why is TCP fair
- Fairness (more)
- TCP Connection Management
- TCP Connection Management (cont)
- TCP Connection Management (cont)
- TCP Connection Management (cont)
- Tuning TCPIP Parameters
- SomeTCP Parameters in Linux Kernel
- SomeTCP Parameters in Linux Kernel
-
Transport Layer 3-14
Principles of Reliable data transferimportant in app transport link layerstop-10 list of important networking topics
characteristics of unreliable channel will determine complexity of reliable data transfer protocol (rdt)
netw
ork
laye
r
Transport Layer 3-15
Reliable data transfer getting started
sendside
receiveside
rdt_send() called from above (eg by app) Passed data to
deliver to receiver upper layer
udt_send() called by rdtto transfer packet over
unreliable channel to receiver
rdt_rcv() called when packet arrives on rcv-side of channel
deliver_data() called by rdt to deliver data to upper
Transport Layer 3-16
Reliable data transfer getting startedWersquoll
incrementally develop sender receiver sides of reliable data transfer protocol (rdt)consider only unidirectional data transfer
but control info will flow on both directionsuse finite state machines (FSM) to specify sender receiver
state1
state2
event causing state transitionactions taken on state transition
state when in this ldquostaterdquo next state
uniquely determined by next event
eventactions
Transport Layer 3-17
Rdt10 reliable transfer over a reliable channel
underlying channel perfectly reliableno bit errorsno loss of packets
separate FSMs for sender receiversender sends data into underlying channelreceiver read data from underlying channel
Wait for call from above packet = make_pkt(data)
udt_send(packet)
rdt_send(data)extract (packetdata)deliver_data(data)
Wait for call from
below
rdt_rcv(packet)
sender receiver
Transport Layer 3-18
Rdt20 channel with bit errors
underlying channel may flip bits in packetrecall checksum to detect bit errors
the question how to recover from errorsacknowledgements (ACKs) receiver explicitly tells sender that pkt received OKnegative acknowledgements (NAKs) receiver explicitly tells sender that pkt had errorssender retransmits pkt on receipt of NAK
new mechanisms in rdt20 (beyond rdt10)error detectionreceiver feedback control msgs (ACKNAK) rcvr-gtsender
Transport Layer 3-19
rdt20 FSM specification
Wait for call from above
snkpkt = make_pkt(data checksum)udt_send(sndpkt)
extract(rcvpktdata)deliver_data(data)udt_send(ACK)
rdt_rcv(rcvpkt) ampamp notcorrupt(rcvpkt)
rdt_rcv(rcvpkt) ampamp isACK(rcvpkt)
udt_send(sndpkt)
rdt_rcv(rcvpkt) ampampisNAK(rcvpkt)
udt_send(NAK)
rdt_rcv(rcvpkt) ampamp corrupt(rcvpkt)
Wait for ACK or
NAK
Wait for call from
belowsender
receiverrdt_send(data)
Λ
Transport Layer 3-20
rdt20 operation with no errors
Wait for call from above
snkpkt = make_pkt(data checksum)udt_send(sndpkt)
extract(rcvpktdata)deliver_data(data)udt_send(ACK)
rdt_rcv(rcvpkt) ampamp notcorrupt(rcvpkt)
rdt_rcv(rcvpkt) ampamp isACK(rcvpkt)
udt_send(sndpkt)
rdt_rcv(rcvpkt) ampampisNAK(rcvpkt)
udt_send(NAK)
rdt_rcv(rcvpkt) ampamp corrupt(rcvpkt)
Wait for ACK or
NAK
Wait for call from
below
rdt_send(data)
Λ
Transport Layer 3-21
rdt20 error scenario
Wait for call from above
snkpkt = make_pkt(data checksum)udt_send(sndpkt)
extract(rcvpktdata)deliver_data(data)udt_send(ACK)
rdt_rcv(rcvpkt) ampamp notcorrupt(rcvpkt)
rdt_rcv(rcvpkt) ampamp isACK(rcvpkt)
udt_send(sndpkt)
rdt_rcv(rcvpkt) ampampisNAK(rcvpkt)
udt_send(NAK)
rdt_rcv(rcvpkt) ampamp corrupt(rcvpkt)
Wait for ACK or
NAK
Wait for call from
below
rdt_send(data)
Λ
Transport Layer 3-22
rdt20 has a fatal flaw
What happens if ACKNAK corruptedsender doesnrsquot know what happened at receivercanrsquot just retransmit possible duplicate
What to dosender ACKsNAKs receiverrsquos ACKNAK What if sender ACKNAK lostretransmit but this might cause retransmission of correctly received pkt
Handling duplicates sender adds sequence number to each pktsender retransmits current pkt if ACKNAK garbledreceiver discards (doesnrsquot deliver up) duplicate pkt
Sender sends one packet then waits for receiver response
stop and wait
Transport Layer 3-23
rdt21 sender handles garbled ACKNAKs
Wait for call 0 from
above
sndpkt = make_pkt(0 data checksum)udt_send(sndpkt)
rdt_send(data)
Wait for ACK or NAK 0 udt_send(sndpkt)
rdt_rcv(rcvpkt) ampamp ( corrupt(rcvpkt) ||isNAK(rcvpkt) )
sndpkt = make_pkt(1 data checksum)udt_send(sndpkt)
rdt_send(data)
rdt_rcv(rcvpkt) ampamp notcorrupt(rcvpkt) ampamp isACK(rcvpkt)
udt_send(sndpkt)
rdt_rcv(rcvpkt) ampamp ( corrupt(rcvpkt) ||isNAK(rcvpkt) )
rdt_rcv(rcvpkt) ampamp notcorrupt(rcvpkt) ampamp isACK(rcvpkt)
Wait forcall 1 from
above
Wait for ACK or NAK 1
ΛΛ
Transport Layer 3-24
rdt21 receiver handles garbled ACKNAKs
Wait for 0 from below
sndpkt = make_pkt(NAK chksum)udt_send(sndpkt)
rdt_rcv(rcvpkt) ampamp not corrupt(rcvpkt) ampamphas_seq0(rcvpkt)
rdt_rcv(rcvpkt) ampamp notcorrupt(rcvpkt) ampamp has_seq1(rcvpkt)
extract(rcvpktdata)deliver_data(data)sndpkt = make_pkt(ACK chksum)udt_send(sndpkt)
Wait for 1 from below
rdt_rcv(rcvpkt) ampamp notcorrupt(rcvpkt) ampamp has_seq0(rcvpkt)
extract(rcvpktdata)deliver_data(data)sndpkt = make_pkt(ACK chksum)udt_send(sndpkt)
rdt_rcv(rcvpkt) ampamp (corrupt(rcvpkt)
sndpkt = make_pkt(ACK chksum)udt_send(sndpkt)
rdt_rcv(rcvpkt) ampamp not corrupt(rcvpkt) ampamphas_seq1(rcvpkt)
rdt_rcv(rcvpkt) ampamp (corrupt(rcvpkt)
sndpkt = make_pkt(ACK chksum)udt_send(sndpkt)
sndpkt = make_pkt(NAK chksum)udt_send(sndpkt)
Transport Layer 3-25
rdt21 discussion
Senderseq added to pkttwo seq rsquos (01) will suffice Whymust check if received ACKNAK corrupted twice as many states
state must ldquorememberrdquowhether ldquocurrentrdquo pkt has 0 or 1 seq
Receivermust check if received packet is duplicate
state indicates whether 0 or 1 is expected pkt seq
note receiver can notknow if its last ACKNAK received OK at sender
Transport Layer 3-26
rdt22 a NAK-free protocol
same functionality as rdt21 using ACKs onlyinstead of NAK receiver sends ACK for last pkt received OK
receiver must explicitly include seq of pkt being ACKed duplicate ACK at sender results in same action as NAK retransmit current pkt
Transport Layer 3-27
rdt22 sender receiver fragments
Wait for call 0 from
above
sndpkt = make_pkt(0 data checksum)udt_send(sndpkt)
rdt_send(data)
udt_send(sndpkt)
rdt_rcv(rcvpkt) ampamp ( corrupt(rcvpkt) ||
isACK(rcvpkt1) )
rdt_rcv(rcvpkt) ampamp notcorrupt(rcvpkt) ampamp isACK(rcvpkt0)
Wait for ACK
0sender FSM
fragment
Wait for 0 from below
rdt_rcv(rcvpkt) ampamp notcorrupt(rcvpkt) ampamp has_seq1(rcvpkt)
extract(rcvpktdata)deliver_data(data)sndpkt = make_pkt(ACK1 chksum)udt_send(sndpkt)
rdt_rcv(rcvpkt) ampamp (corrupt(rcvpkt) ||
has_seq1(rcvpkt))
udt_send(sndpkt)receiver FSM
fragment
Λ
Transport Layer 3-28
rdt30 channels with errors and loss
New assumptionunderlying channel can also lose packets (data or ACKs)
checksum seq ACKs retransmissions will be of help but not enough
Q how to deal with losssender waits until certain data or ACK lost then retransmitsdrawbacks
Approach sender waits ldquoreasonablerdquo amount of time for ACK retransmits if no ACK received in this timeif pkt (or ACK) just delayed (not lost)
retransmission will be duplicate but use of seq rsquos already handles thisreceiver must specify seq of pkt being ACKed
requires countdown timer
Transport Layer 3-29
rdt30 sendersndpkt = make_pkt(0 data checksum)udt_send(sndpkt)start_timer
rdt_send(data)
Wait for
ACK0
rdt_rcv(rcvpkt) ampamp ( corrupt(rcvpkt) ||isACK(rcvpkt1) )
Wait for call 1 from
above
sndpkt = make_pkt(1 data checksum)udt_send(sndpkt)start_timer
rdt_send(data)
rdt_rcv(rcvpkt) ampamp notcorrupt(rcvpkt) ampamp isACK(rcvpkt0)
rdt_rcv(rcvpkt) ampamp ( corrupt(rcvpkt) ||isACK(rcvpkt0) )
rdt_rcv(rcvpkt) ampamp notcorrupt(rcvpkt) ampamp isACK(rcvpkt1)
stop_timerstop_timer
udt_send(sndpkt)start_timer
timeout
udt_send(sndpkt)start_timer
timeout
rdt_rcv(rcvpkt)
Wait for call 0from
above
Wait for
ACK1
Λrdt_rcv(rcvpkt)
ΛΛ
Λ
Transport Layer 3-30
rdt30 in action
Transport Layer 3-31
rdt30 in action
Transport Layer 3-32
Performance of rdt30
rdt30 works but performance stinksexample 1 Gbps link 15 ms e-e prop delay 1KB packet
Ttransmit = 8kbpkt109 bsec = 8 microsec
U sender utilization ndash fraction of time sender busy sending1KB pkt every 30 msec -gt 33kBsec thruput over 1 Gbps linknetwork protocol limits use of physical resources
U sender=
008 30008
= 000027 L RRTT + L R
=
L (packet length in bits)R (transmission rate bps) =
Transport Layer 3-33
rdt30 stop-and-wait operation
first packet bit transmitted t = 0
sender receiver
RTT
last packet bit transmitted t = L R
first packet bit arriveslast packet bit arrives send ACK
ACK arrives send next packet t = RTT + L R
U sender=
00830008
= 000027 L RRTT + L R
=
Transport Layer 3-34
Pipelined protocolsPipelining sender allows multiple ldquoin-flightrdquo yet-to-
be-acknowledged pktsrange of sequence numbers must be increasedbuffering at sender andor receiver
Two generic forms of pipelined protocols go-Back-N selective repeat
Transport Layer 3-35
Pipelining increased utilization
first packet bit transmitted t = 0
sender receiver
RTT
last bit transmitted t = L R
first packet bit arriveslast packet bit arrives send ACK
ACK arrives send next packet t = RTT + L R
last bit of 2nd packet arrives send ACKlast bit of 3rd packet arrives send ACK
U sender=
024 30008
= 000083 L RRTT + L R
=
Increase utilizationby a factor of 3
Transport Layer 3-36
Utilization=N(LR)(RTT+LR) if NLRltRTT+LR Utilization=1 if and the sender pauses after it transmits a window NLRgtRTT+LR and the of packets until it receives first ACK sender does not pause
Transport Layer 3-37
Go-Back-NSender
k-bit seq in pkt headerldquowindowrdquo of up to N consecutive unackrsquoed pkts allowed
ACK(n) ACKs all pkts up to including seq n - ldquocumulative ACKrdquomay receive duplicate ACKs (see receiver)
timer for the entire windowtimeout(n) retransmit pkt n and all higher seq pkts in window
Transport Layer 3-38
GBN sender extended FSM
Wait start_timerudt_send(sndpkt[base])udt_send(sndpkt[base+1])hellipudt_send(sndpkt[nextseqnum-1])
timeout
rdt_send(data)
if (nextseqnum lt base+N) sndpkt[nextseqnum] = make_pkt(nextseqnumdatachksum)udt_send(sndpkt[nextseqnum])if (base == nextseqnum)
start_timernextseqnum++
elserefuse_data(data)
base = getacknum(rcvpkt)+1If (base == nextseqnum)
stop_timerelse
start_timer
rdt_rcv(rcvpkt) ampamp notcorrupt(rcvpkt)
base=1nextseqnum=1
rdt_rcv(rcvpkt) ampamp corrupt(rcvpkt)
Λ
Λ
Transport Layer 3-39
GBN receiver extended FSM
ACK-only always send ACK for correctly-received pktwith highest in-order seq
may generate duplicate ACKsneed only remember expectedseqnum
out-of-order pkt discard (donrsquot buffer) -gt no receiver bufferingRe-ACK pkt with highest in-order seq
Wait
udt_send(sndpkt)default
rdt_rcv(rcvpkt)ampamp notcurrupt(rcvpkt)ampamp hasseqnum(rcvpktexpectedseqnum)
extract(rcvpktdata)deliver_data(data)sndpkt = make_pkt(expectedseqnumACKchksum)udt_send(sndpkt)expectedseqnum++
expectedseqnum=1sndpkt =
make_pkt(0ACKchksum)
Λ
Transport Layer 3-40
GBN inaction
Transport Layer 3-41
Selective Repeat
receiver individually acknowledges all correctly received pkts
buffers pkts as needed for eventual in-order delivery to upper layer
sender only resends pkts for which ACK not received
sender timer for each unACKed pktsender window
N consecutive seq rsquosagain limits seq s of sent unACKed pkts
Transport Layer 3-42
Selective repeat sender receiver windows
Transport Layer 3-43
Selective repeat
data from above if next available seq in window send pkt
timeout(n)resend pkt n restart timer
ACK(n) in [sendbasesendbase+N-1]
mark pkt n as receivedif n smallest unACKed pkt advance window base to next unACKed seq
senderpkt n in [rcvbase rcvbase+N-1]
send ACK(n)out-of-order bufferin-order deliver (also deliver buffered in-order pkts) advance window to next not-yet-received pkt
pkt n in [rcvbase-Nrcvbase-1]
ACK(n)otherwise
ignore
receiver
Transport Layer 3-44
Selective repeat in action
Transport Layer 3-45
Selective repeatdilemma
Example seq rsquos 0 1 2 3window size=3
receiver sees no difference in two scenariosincorrectly passes duplicate data as new in (a)
Q what relationship between seq size and window size
Transport Layer 3-46
Sequence Number vs Window SizeSuppose we use k bits to represent SNQuestion Whatrsquos the minimum number of bits k necessary for a window size of N
sender
receiver
Go-Back-N
expectedSN
snd_base=expectedSN
Q For a given expectedSN whatrsquos the largest possible value for snd_baseA If all the last N ACKs sent by the receiver are received
snd_base = expectedSNexpectedSN+N-1
senderrsquos window
Transport Layer 3-47
Sequence Number vs Window SizeSuppose we use k bits to represent SNQuestion Whatrsquos the minimum number of bits k necessary for a window size of N
sender
receiver
Go-Back-N
expectedSN
snd_base=expectedSN-N
Q For a given expectedSN whatrsquos the smallest possible value for snd_baseA If all the last N ACKs sent by the receiver are not received
snd_base = expectedSN-NexpectedSN-1
senderrsquos window
Transport Layer 3-48
Sequence Number vs Window Size
sender
receiver
Go-Back-N
expectedSN
snd_base=expectedSN-N
All SNs in the interval [expectedSN-NexpectedSN+N-1] (an interval of size 2N) can be received by the receiver Since the receiver accepts on the packet with SN=expectedSN there should be no other packet within this interval with SN=expectedSN Therefore
2k ge N+1expectedSN+N-1
Transport Layer 3-49
Sequence Number vs Window SizeSuppose we use k bits to represent SNQuestion Whatrsquos the minimum number of bits k necessary for a window size of N
sender
receiver
Selective Repeat
rcv_base
snd_base=rcv_base
Q For a given rcv_base whatrsquos the largest possible value for snd_baseA If all the last N ACKs sent by the receiver are received
snd_base = rcv_base (same as go_back-N)rcv_base+N-1
senderrsquos window
receiverrsquos window
rcv_base+N-1
Transport Layer 3-50
Sequence Number vs Window SizeSuppose we use k bits to represent SNQuestion Whatrsquos the minimum number of bits k necessary for a window size of N
sender
receiver
Selective Repeat
rcv_base
snd_base=rcv_base-N
Q For a given rcv_base whatrsquos the smallest possible value for snd_baseA If all the last N ACKs sent by the receiver are not received
snd_base = rcv_base-N (same as Go-Back-N)rcv_base-1
senderrsquos window
rcv_base
receiverrsquos window
rcv_base+N-1
Transport Layer 3-51
Sequence Number vs Window Size
sender
receiver
Selective Repeat
snd_base=rcv_base-N
All SNs in the interval [rcv_base-Nrcv_base+N-1] (an interval of size 2N) can be received by the receiver Since the receiver should be able to distinguish between all packets in this interval and take corresponding action there should be no two packets within thisinterval having the same SN Therefore
2k ge 2Nrcv_base+N-1
rcv_basercv_base
receiverrsquos window
rcv_base+N-1
Transport Layer 3-52
TCP Overview RFCs 793 1122 1323 2018 2581
full duplex databi-directional data flow in same connectionMSS maximum segment size
connection-orientedhandshaking (exchange of control msgs) initrsquossender receiver state before data exchange
flow controlledsender will not overwhelm receiver
point-to-pointone sender one receiver
reliable in-order byte stream
no ldquomessage boundariesrdquopipelined
TCP congestion and flow control set window size
send amp receive buffers
socketdoor
TCPsend buffer
TCPreceive buffer
socketdoor
segment
applicationwrites data
applicationreads data
Transport Layer 3-53
TCP segment structure
source port dest port
32 bits
applicationdata
(variable length)
sequence numberacknowledgement number
Receive windowUrg data pnterchecksum
FSRPAUheadlen
notused
Options (variable length)
URG urgent data (generally not used)
ACK ACK valid
PSH push data now(generally not used)
RST SYN FINconnection estab(setup teardown
commands)
bytes rcvr willingto accept
Internetchecksum
(as in UDP)
countingby bytes of data(not segments)
Transport Layer 3-54
TCP seq rsquos and ACKsSeq rsquos
byte stream ldquonumberrdquo of first byte in segmentrsquos dataACKs
seq of next byte expected from other sidecumulative ACK
Q how receiver handles out-of-order segmentsA TCP spec doesnrsquot say - up to implementationWidely used implementations of TCP buffer out-of-order segments
Transport Layer 3-55
TCP Round Trip Time and Timeout
Q how to set TCP timeout valuelonger than RTT
but RTT variestoo short premature timeout
unnecessary retransmissions
too long slow reaction to segment loss
Q how to estimate RTTSampleRTT measured time from segment transmission until ACK receipt
ignore retransmissionsSampleRTT will vary want estimated RTT ldquosmootherrdquo
average several recent measurements not just current SampleRTT
Transport Layer 3-56
TCP Round Trip Time and Timeout
EstimatedRTT = (1- α)EstimatedRTT + αSampleRTT
Exponential weighted moving averageinfluence of past sample decreases exponentially fasttypical value α = 0125
Transport Layer 3-57
Example RTT estimationRTT gaiacsumassedu to fantasiaeurecomfr
100
150
200
250
300
350
1 8 15 22 29 36 43 50 57 64 71 78 85 92 99 106
time (seconnds)
RTT
(mill
iseco
nds)
SampleRTT Estimated RTT
Transport Layer 3-58
TCP Round Trip Time and TimeoutSetting the timeout
EstimatedRTT plus ldquosafety marginrdquolarge variation in EstimatedRTT -gt larger safety margin
first estimate of how much SampleRTT deviates from EstimatedRTT
TimeoutInterval = EstimatedRTT + 4DevRTT
DevRTT = (1-β)DevRTT +β|SampleRTT-EstimatedRTT|
(typically β = 025)
Then set timeout interval
Transport Layer 3-59
TCP reliable data transfer
TCP creates rdtservice on top of IPrsquos unreliable servicePipelined segmentsCumulative acksTCP uses single retransmission timer however it just retransmits the first segment in the window
Retransmissions are triggered by
timeout eventsduplicate acks
Initially consider simplified TCP sender
ignore duplicate acksignore flow control congestion control
Transport Layer 3-60
TCP sender eventsdata rcvd from app
Create segment with seq seq is byte-stream number of first data byte in segmentstart timer if not already running (think of timer as for oldest unacked segment)expiration interval TimeOutInterval
timeoutretransmit segment that caused timeout (first segment in the window)restart timer
Ack rcvdIf acknowledges previously unacked segments
update what is known to be ackedstart timer if there are outstanding segments
Transport Layer 3-61
TCP sender(simplified)
NextSeqNum = InitialSeqNumSendBase = InitialSeqNum
loop (forever) switch(event)
event data received from application above create TCP segment with sequence number NextSeqNumif (timer currently not running)
start timerpass segment to IP NextSeqNum = NextSeqNum + length(data)
event timer timeoutretransmit not-yet-acknowledged segment with
smallest sequence numberstart timer
event ACK received with ACK field value of y if (y gt SendBase)
SendBase = yif (there are currently not-yet-acknowledged segments)
start timer
end of loop forever
Commentbull SendBase-1 last cumulatively ackrsquoed byteExamplebull SendBase-1 = 71y= 73 so the rcvrwants 73+ y gt SendBase sothat new data is acked
Transport Layer 3-62
TCP retransmission scenariosHost A
Seq=100 20 bytes data
ACK=100
timepremature timeout
Host B
Seq=92 8 bytes data
ACK=120
Seq=92 8 bytes data
Seq=
92 t
imeo
ut
ACK=120
Host A
Seq=92 8 bytes data
ACK=100
loss
tim
eout
lost ACK scenario
Host B
X
Seq=92 8 bytes data
ACK=100
time
Seq=
92 t
imeo
utSendBase
= 100
SendBase= 120
SendBase= 120
Sendbase= 100
Transport Layer 3-63
TCP retransmission scenarios (more)Host A
Seq=92 8 bytes data
ACK=100
loss
tim
eout
Cumulative ACK scenario
Host B
X
Seq=100 20 bytes data
ACK=120
time
SendBase= 120
Transport Layer 3-64
TCP ACK generation [RFC 1122 RFC 2581]
Event at Receiver
Arrival of in-order segment withexpected seq All data up toexpected seq already ACKed
Arrival of in-order segment withexpected seq One other segment has ACK pending
Arrival of out-of-order segmenthigher-than-expect seq Gap detected
Arrival of segment that partially or completely fills gap
TCP Receiver action
Delayed ACK Wait up to 500msfor next segment If no next segmentsend ACK
Immediately send single cumulative ACK ACKing both in-order segments
Immediately send duplicate ACK indicating seq of next expected byte
Immediate send ACK provided thatsegment startsat lower end of gap
Transport Layer 3-65
Fast Retransmit
Time-out period often relatively long
long delay before resending lost packet
Detect lost segments via duplicate ACKs
Sender often sends many segments back-to-backIf segment is lost there will likely be many duplicate ACKs
If sender receives 3 ACKs for the same data it supposes that segment after ACKeddata was lost
fast retransmit resend segment before timer expires
Transport Layer 3-66
Fast RetransmitResend a segment after 3 duplicate ACKs since a duplicate ACK means that an out-of sequence segment was receivedduplicate ACKs due to packet reorderingif window is small donrsquot get duplicate ACKs
Host A
tim
eout
Host B
time
X
resend seq X2
seq x1seq x2seq x3seq x4seq x5
ACK x1
ACK x1ACK x1ACK x1
tripleduplicate
ACKs
Transport Layer 3-67
event ACK received with ACK field value of y if (y gt SendBase)
SendBase = yif (there are currently not-yet-acknowledged segments)
start timer
else increment count of dup ACKs received for yif (count of dup ACKs received for y = 3)
resend segment with sequence number y
Fast retransmit algorithm
a duplicate ACK for already ACKed segment
fast retransmit
Transport Layer 3-68
TCP Flow Control
receive side of TCP connection has a receive buffer
speed-matching service matching the send rate to the receiving apprsquos drain rate
app process may be slow at reading from buffer
sender wonrsquot overflowreceiverrsquos buffer by
transmitting too muchtoo fast
flow control
Transport Layer 3-69
TCP Flow control how it works
(Suppose TCP receiver discards out-of-order segments)spare room in buffer
= RcvWin
= RcvBuffer-[LastByteRcvd -LastByteRead]
Rcvr advertises spare room by including value of RcvWin in segmentsSender limits unACKeddata to RcvWin
guarantees receive buffer doesnrsquot overflow
Transport Layer 3-70
Sliding Window Flow Control Example
3K
2K SeqNo=0
ReceiverBuffer
0 4KSendersends 2Kof data
2K
AckNo=2048 RcvWin=2048Sendersends 2Kof data 2K SeqNo=2048
4K
AckNo=4096 RcvWin=0
AckNo=4096 RcvWin=1024
Sender blocked
Transport Layer 3-71
Principles of Congestion Control
Congestioninformally ldquotoo many sources sending too much data too fast for network to handlerdquodifferent from flow controlmanifestations
lost packets (buffer overflow at routers)long delays (queueing in router buffers)
a top-10 problem
Transport Layer 3-72
Causescosts of congestion scenario 1
two senders two receiversone router infinite buffers no retransmission
large delays when congestedmaximum achievable throughput
unlimited shared output link buffers
Host Aλin original data
Host B
λout
Transport Layer 3-73
Causescosts of congestion scenario 2
one router finite buffers sender retransmission of lost packet
finite shared output link buffers
Host A λin original data
Host B
λout
λin original data plus retransmitted data
Transport Layer 3-74
Causescosts of congestion scenario 2always (goodput)ldquoperfectrdquo retransmission only when loss
retransmission of delayed (not lost) packet makes larger(than perfect case) for same
λin
λout=
λin
λoutgtλ
inλout
ldquocostsrdquo of congestionmore work (retrans) for given ldquogoodputrdquounneeded retransmissions link carries multiple copies of pkt
R2
R2λin
λ out
b
R2
R2λin
λ out
a
R2
R2λin
λ out
c
R4
R3
Transport Layer 3-75
Causescosts of congestion scenario 3four sendersmultihop pathstimeoutretransmit
λin
Q what happens as and increase λ
in
finite shared output link buffers
Host Aλin original data
Host B
λout
λin original data plus retransmitted data
Transport Layer 3-76
Causescosts of congestion scenario 3
another ldquocostrdquo of congestionwhen packet dropped any ldquoupstream transmission capacity used for that packet was wasted
Host A
Host B
λou
t
Transport Layer 3-77
Approaches towards congestion control
End-end congestion controlno explicit feedback from networkcongestion inferred from end-system observed loss delayapproach taken by TCP
Network-assisted congestion controlrouters provide feedback to end systems
single bit indicating congestion (SNA DECbit TCPIP ECN ATM)explicit rate sender should send at
Two broad approaches towards congestion control
Transport Layer 3-78
TCP Congestion Control
end-end control (no network assistance)sender limits transmissionLastByteSent-LastByteAcked
le CongWin
CongWin is dynamic function of perceived network congestion
How does sender perceive congestionloss event = timeout or3 duplicate acksTCP sender reduces rate (CongWin) after loss event
two modes of operationSlow Start (SS)Congestion avoidance (CA) or Additive Increase Multiplicative Decrease (AIMD)
Transport Layer 3-79
TCP congestion control bandwidth probing
ldquoprobing for bandwidthrdquo increase transmission rate on receipt of ACK until eventually loss occurs then decrease transmission rate
continue to increase on ACK decrease on loss (since available bandwidth is changing depending on other connections in network)
ACKs being received so increase rate
X
X
XX
X loss so decrease rate
send
ing
rate
time
Q how fast to increasedecreasedetails to follow
TCPrsquosldquosawtoothrdquobehavior
Transport Layer 3-80
TCP Congestion Control details
sender limits rate by limiting number of unACKed bytes ldquoin pipelinerdquo
cwnd differs from rwnd (how why)sender limited by min(cwndrwnd)
roughly
cwnd is dynamic function of perceived network congestion
rate = cwndRTT bytessec
LastByteSent-LastByteAcked le cwnd
cwndbytes
RTT
ACK(s)
Transport Layer 3-81
TCP Congestion Control more details
segment loss event reducing cwndtimeout no response from receiver
cut cwnd to 13 duplicate ACKs at least some segments getting through (recall fast retransmit)
cut cwnd in half less aggressively than on timeout
ACK received increase cwndTwo modes of operation
slowstart phase bull increase exponentially
fast (despite name) at connection start or following timeout
congestion avoidance bull increase linearly
Transport Layer 3-82
TCP Slow Start Phasewhen connection begins cwnd = 1 MSS
example MSS = 500 bytes amp RTT = 200 msecinitial rate = 20 kbps
available bandwidth may be gtgt MSSRTT
desirable to quickly ramp up to respectable rate
increase rate exponentially until first loss event or when threshold reached
double cwnd every RTTdone by incrementing cwnd by 1 for every ACK received
Host A
one segment
RTT
Host B
time
two segments
four segments
Transport Layer 3-83
Slow Start ExampleThe congestion window size grows very rapidly
For every ACK we increase CongWin by 1 irrespective of the number of segments ACKrsquoeddouble CongWinevery RTTinitial rate is slow but ramps up exponentially fast
TCP slows down the increase of CongWinwhen CongWin gt ssthresh
segment 1
ACK for segment 1
cwnd = 1
cwnd = 2 segment 2segment 3
ACK for segments 2
cwnd = 4 segment 4segment 5segment 6
ACK for segments 4
cwnd = 7
ACK for segments 3
ACK for segments 5
ACK for segments 6
cwnd = 3
cwnd = 5
cwnd = 6ACK for segments 7
cwnd = 8
segment 7
Transport Layer 3-84
TCP Congestion Avoidance Phase
when cwnd gt ssthreshgrow cwnd linearly
increase cwnd by 1 MSS per RTT approach possible congestion slower than in slowstartimplementation cwnd= cwnd + MSScwndfor each ACK received
ACKs increase cwndby 1 MSS per RTT additive increaseloss cut cwnd in half (non-timeout-detected loss ) multiplicative decrease
AIMD
AIMD Additive IncreaseMultiplicative Decrease
Transport Layer 3-85
Congestion AvoidanceCongestion avoidance phase is started if CongWin has reached the slow-start threshold value
If CongWin gt= ssthresh then each time an ACK is received increment CongWin as follows
bull CongWin = CongWin + 1CongWin (CongWin in segments)
bull In actual TCP implementation CongWin is in BytesCongWin = CongWin + MSS (MSSCongWin)
So CongWin is increased by one only if all CongWinsegments have been acknowledged
Transport Layer 3-86
Example Slow StartCongestion AvoidanceAssume that
ssthresh = 8
cwnd = 1
cwnd = 2
cwnd = 4
cwnd = 8
cwnd = 9
cwnd = 10
02468
101214
t=0
t=2
t=4
t=6
Roundtrip times
Cw
nd(in
seg
men
ts)
ssthresh
cwnd = 3
cwnd = 5cwnd = 6cwnd = 7
Transport Layer 3-87
Slow Start Congestion AvoidanceA typical plot of CongWin for a TCP connection
(MSS = 1500 bytes) with TCP Tahoe
SS
CA
ssthresh
Transport Layer 3-88
Responses to CongestionTCP assumes there is congestion if it detects a packet lossA TCP sender can detect lost packets via loss events
bull Timeout of a retransmission timerbull Receipt of 3 duplicate ACKs (fast retransmit)
TCP interprets a Timeout as a binary congestion signal When a timeout occurs the sender performs
ssthresh is set to half the current size of the congestion window
ssthresh = CongWin 2CongWin is reset to one
CongWin = 1and slow-start is entered
Transport Layer 3-89
Fast Recovery (differentiation btwn two loss events) After 3 dup ACKs (fast Retransmit)
ssthresh = CongWin2CongWin = CongWin2window then grows linearly
But after timeout eventCongWin = 1 MSS window then grows exponentiallyto the threshold then grows linearly
bull 3 dup ACKs indicates network capable of delivering some segmentsbull timeout before 3 dup ACKs is ldquomore alarmingrdquo
Philosophy
3-90
TCP Congestion ControlInitially
CongWin = 1ssthresh = advertised window size
New Ack receivedif (CongWin lt ssthresh) Slow Start
CongWin = CongWin + 1else Congestion Avoidance
CongWin = CongWin + 1CongWinTimeout
ssthresh = CongWin2CongWin = 1
Fast Retransmissionssthresh = CongWin2CongWin = CongWin2
Slow Start (exponential increase phase) is continued until CongWin reaches half of the level where the loss event occurred last time CongWin is increased slowly after (linear increase in Congestion Avoidance phase)
Transport Layer 3-91
Popular ldquoflavorsrdquo of TCP
ssthresh
ssthresh
TCP Tahoe
TCP Reno
Transmission round
cwnd
win
dow
siz
e (in
seg
men
ts)
Transport Layer 3-92
Summary TCP Congestion ControlWhen CongWin is below Threshold sender in slow-start phase window grows exponentiallyWhen CongWin is above Threshold sender is in congestion-avoidance phase window grows linearlyWhen a triple duplicate ACK occurs Threshold set to CongWin2 and CongWin set to ThresholdWhen timeout occurs Threshold set to CongWin2 and CongWin is set to 1 MSS The actual sender window size is determined based on the congestion and flow control algorithms
SenderWin=min(RcvWinCongWin)
Transport Layer 3-93
TCP Congestion Control SummaryEvent State TCP Sender Action Commentary
ACK receipt for previously unackeddata
Slow Start (SS)
CongWin = CongWin + MSS If (CongWin gt Threshold)
set state to ldquoCongestion Avoidancerdquo
Resulting in a doubling of CongWin every RTT
ACK receipt for previously unackeddata
CongestionAvoidance (CA)
CongWin = CongWin+MSS (MSSCongWin)
Additive increase resulting in increase of CongWin by 1 MSS every RTT
Loss event detected by triple duplicate ACK
SS or CA Threshold = CongWin2 CongWin = ThresholdSet state to ldquoCongestion Avoidancerdquo
Fast recovery implementing multiplicative decrease CongWin will not drop below 1 MSS
Timeout SS or CA Threshold = CongWin2 CongWin = 1 MSSSet state to ldquoSlow Startrdquo
Enter slow start
Duplicate ACK
SS or CA Increment duplicate ACK count for segment being acked
CongWin and Threshold not changed
Transport Layer 3-94
TCP throughput
Q whatrsquos average throughout of TCP as function of window size RTT
ignoring slow startlet W be window size when loss occurs
when window is W throughput is WRTTjust after loss window drops to W2 throughput to W2RTT average throughout 75 WRTT
Transport Layer 3-95
TCP Futures TCP over ldquolong fat pipesrdquo
example 1500 byte segments 100ms RTT want 10 Gbps throughputrequires window size W = 83333 in-flight segmentsthroughput in terms of loss rate
L = 210-10 Wownew versions of TCP for high-speed
LRTTMSSsdot221
Transport Layer 3-96
Fairness goal if K TCP sessions share same bottleneck link of bandwidth R each should have average rate of RK
TCP connection 1
bottleneckrouter
capacity R
TCP connection 2
TCP Fairness
Transport Layer 3-97
Why is TCP fairTwo competing sessions
Additive increase gives slope of 1 as throughout increasesmultiplicative decrease decreases throughput proportionally
R
R
equal bandwidth share
Connection 1 throughput
Conn
ecti
on 2
thr
ough
p ut
congestion avoidance additive increaseloss decrease window by factor of 2
congestion avoidance additive increaseloss decrease window by factor of 2
Transport Layer 3-98
Fairness (more)Fairness and UDP
Multimedia apps often do not use TCP
do not want rate throttled by congestion control
Instead use UDPpump audiovideo at constant rate tolerate packet loss
Research area TCP friendly
Fairness and parallel TCP connectionsnothing prevents app from opening parallel cnctionsbetween 2 hostsWeb browsers do this Example link of rate R supporting 9 cnctions
new app asks for 1 TCP gets rate R10new app asks for 11 TCPs gets R2
Transport Layer 3-99
TCP Connection ManagementRecall TCP sender receiver
establish ldquoconnectionrdquobefore exchanging data segmentsinitialize TCP variables
seq sbuffers flow control info (eg RcvWindow)
client connection initiatorSocket clientSocket = new Socket(hostnameport
number)
server contacted by clientSocket connectionSocket = welcomeSocketaccept()
Three way handshakeStep 1 client host sends TCP
SYN segment to serverspecifies initial seq no data
Step 2 server host receives SYN replies with SYNACK segment
server allocates buffersspecifies server initial seq
Step 3 client receives SYNACK replies with ACK segment which may contain data
Transport Layer 3-100
TCP Connection Management (cont)
Closing a connection
client closes socketclientSocketclose()
Step 1 client end system sends TCP FIN control segment to server
Step 2 server receives FIN replies with ACK Closes connection sends FIN
client
FIN
server
ACK
ACK
FIN
close
close
closed
tim
ed w
ait
Transport Layer 3-101
TCP Connection Management (cont)
Step 3 client receives FIN replies with ACK
Enters ldquotimed waitrdquo -will respond with ACK to received FINs
Step 4 server receives ACK Connection closed
client
FIN
server
ACK
ACK
FIN
closing
closing
closed
tim
ed w
ait
closed
Transport Layer 3-102
TCP Connection Management (cont)
TCP clientlifecycle
TCP serverlifecycle
Transport Layer 3-103
Tuning TCPIP Parameters TCPIP parameters
A set of default values may not be optimal for all applicationsThe network administrator may wish to turn on or off some TCPIP functions for performance or security considerations
Many Unix and Linux systems provide some flexibility in tuning the TCPIP kernelsbinsysctl is used to configure the Linux kernel parameters at runtime
Default kernel configuration file is sbinsysctlconfFrequently used sysctl options
bull sysctl ndasha or sysctl ndashA list all current valuesbull sysctl ndashp file_name load the sysctl setting from a configuration
filebull sysctl ndashw variable=value change the value of the parameter
Transport Layer 3-104
SomeTCP Parameters in Linux Kerneltcp_syn_retries
Number of SYN packets the kernel will send before giving up on the new connection
tcp_synack_retriesnumber of SYN+ACK packets sent before the kernel gives up on the connection
tcp_window_scalingMaximum window size of 65535 bytes not enough for for really fast networks The window scaling options allows for almost gigabyte windows which is good for connections with large delay-bandwidth product
tcp_max_syn_backlogMaximal number of remembered connection requests which still did not receive an acknowledgment from connecting client
tcp_fin_timeoutHow many seconds to wait for a final FIN packet before the socket is closed required to prevent denial-of-service (DoS) attacks Default value is 60 seconds
Transport Layer 3-105
SomeTCP Parameters in Linux Kerneltcp_rmem
This is a vector of 3 integers [min default max] These parameters are used by TCP to dynamically adjust receive buffer sizesmin - minimum size of the receive buffer used by each TCP socket The default value is 4K default - the default size of the receive buffer for a TCP socket The default value is 87380 bytes and is lowered to 43689 in low memory systems If larger receive buffer sizes are desired this value should be increased max - the maximum size of the receive buffer used by each TCP socket The default value of 873802 bytes is lowered to 87380 in low memory systems
tcp_smemSend buffer parameters [min default max] similar to tcp_rmem
- Chapter 3 Transport Layer
- Transport services and protocols
- Transport vs network layer
- Internet transport-layer protocols
- Multiplexingdemultiplexing
- How demultiplexing works
- Connectionless demultiplexing
- Connection-oriented demux
- Connection-oriented demux (cont)
- Connection-oriented demux Threaded Web Server
- UDP User Datagram Protocol [RFC 768]
- UDP more
- UDP checksum
- Principles of Reliable data transfer
- Reliable data transfer getting started
- Reliable data transfer getting started
- Rdt10 reliable transfer over a reliable channel
- Rdt20 channel with bit errors
- rdt20 FSM specification
- rdt20 operation with no errors
- rdt20 error scenario
- rdt20 has a fatal flaw
- rdt21 sender handles garbled ACKNAKs
- rdt21 receiver handles garbled ACKNAKs
- rdt21 discussion
- rdt22 a NAK-free protocol
- rdt22 sender receiver fragments
- rdt30 channels with errors and loss
- rdt30 sender
- rdt30 in action
- rdt30 in action
- Performance of rdt30
- rdt30 stop-and-wait operation
- Pipelined protocols
- Pipelining increased utilization
- Go-Back-N
- GBN sender extended FSM
- GBN receiver extended FSM
- GBN inaction
- Selective Repeat
- Selective repeat sender receiver windows
- Selective repeat
- Selective repeat in action
- Selective repeat dilemma
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- TCP Overview RFCs 793 1122 1323 2018 2581
- TCP segment structure
- TCP seq rsquos and ACKs
- TCP Round Trip Time and Timeout
- TCP Round Trip Time and Timeout
- Example RTT estimation
- TCP Round Trip Time and Timeout
- TCP reliable data transfer
- TCP sender events
- TCP sender(simplified)
- TCP retransmission scenarios
- TCP retransmission scenarios (more)
- TCP ACK generation [RFC 1122 RFC 2581]
- Fast Retransmit
- Fast Retransmit
- Fast retransmit algorithm
- TCP Flow Control
- TCP Flow control how it works
- Sliding Window Flow Control Example
- Principles of Congestion Control
- Causescosts of congestion scenario 1
- Causescosts of congestion scenario 2
- Causescosts of congestion scenario 2
- Causescosts of congestion scenario 3
- Causescosts of congestion scenario 3
- Approaches towards congestion control
- TCP Congestion Control
- TCP congestion control bandwidth probing
- TCP Congestion Control details
- TCP Congestion Control more details
- TCP Slow Start Phase
- Slow Start Example
- TCP Congestion Avoidance Phase
- Congestion Avoidance
- Example Slow StartCongestion Avoidance
- Slow Start Congestion Avoidance
- Responses to Congestion
- Fast Recovery (differentiation btwn two loss events)
- TCP Congestion Control
- Popular ldquoflavorsrdquo of TCP
- Summary TCP Congestion Control
- TCP Congestion Control Summary
- TCP throughput
- TCP Futures TCP over ldquolong fat pipesrdquo
- TCP Fairness
- Why is TCP fair
- Fairness (more)
- TCP Connection Management
- TCP Connection Management (cont)
- TCP Connection Management (cont)
- TCP Connection Management (cont)
- Tuning TCPIP Parameters
- SomeTCP Parameters in Linux Kernel
- SomeTCP Parameters in Linux Kernel
-
Transport Layer 3-15
Reliable data transfer getting started
sendside
receiveside
rdt_send() called from above (eg by app) Passed data to
deliver to receiver upper layer
udt_send() called by rdtto transfer packet over
unreliable channel to receiver
rdt_rcv() called when packet arrives on rcv-side of channel
deliver_data() called by rdt to deliver data to upper
Transport Layer 3-16
Reliable data transfer getting startedWersquoll
incrementally develop sender receiver sides of reliable data transfer protocol (rdt)consider only unidirectional data transfer
but control info will flow on both directionsuse finite state machines (FSM) to specify sender receiver
state1
state2
event causing state transitionactions taken on state transition
state when in this ldquostaterdquo next state
uniquely determined by next event
eventactions
Transport Layer 3-17
Rdt10 reliable transfer over a reliable channel
underlying channel perfectly reliableno bit errorsno loss of packets
separate FSMs for sender receiversender sends data into underlying channelreceiver read data from underlying channel
Wait for call from above packet = make_pkt(data)
udt_send(packet)
rdt_send(data)extract (packetdata)deliver_data(data)
Wait for call from
below
rdt_rcv(packet)
sender receiver
Transport Layer 3-18
Rdt20 channel with bit errors
underlying channel may flip bits in packetrecall checksum to detect bit errors
the question how to recover from errorsacknowledgements (ACKs) receiver explicitly tells sender that pkt received OKnegative acknowledgements (NAKs) receiver explicitly tells sender that pkt had errorssender retransmits pkt on receipt of NAK
new mechanisms in rdt20 (beyond rdt10)error detectionreceiver feedback control msgs (ACKNAK) rcvr-gtsender
Transport Layer 3-19
rdt20 FSM specification
Wait for call from above
snkpkt = make_pkt(data checksum)udt_send(sndpkt)
extract(rcvpktdata)deliver_data(data)udt_send(ACK)
rdt_rcv(rcvpkt) ampamp notcorrupt(rcvpkt)
rdt_rcv(rcvpkt) ampamp isACK(rcvpkt)
udt_send(sndpkt)
rdt_rcv(rcvpkt) ampampisNAK(rcvpkt)
udt_send(NAK)
rdt_rcv(rcvpkt) ampamp corrupt(rcvpkt)
Wait for ACK or
NAK
Wait for call from
belowsender
receiverrdt_send(data)
Λ
Transport Layer 3-20
rdt20 operation with no errors
Wait for call from above
snkpkt = make_pkt(data checksum)udt_send(sndpkt)
extract(rcvpktdata)deliver_data(data)udt_send(ACK)
rdt_rcv(rcvpkt) ampamp notcorrupt(rcvpkt)
rdt_rcv(rcvpkt) ampamp isACK(rcvpkt)
udt_send(sndpkt)
rdt_rcv(rcvpkt) ampampisNAK(rcvpkt)
udt_send(NAK)
rdt_rcv(rcvpkt) ampamp corrupt(rcvpkt)
Wait for ACK or
NAK
Wait for call from
below
rdt_send(data)
Λ
Transport Layer 3-21
rdt20 error scenario
Wait for call from above
snkpkt = make_pkt(data checksum)udt_send(sndpkt)
extract(rcvpktdata)deliver_data(data)udt_send(ACK)
rdt_rcv(rcvpkt) ampamp notcorrupt(rcvpkt)
rdt_rcv(rcvpkt) ampamp isACK(rcvpkt)
udt_send(sndpkt)
rdt_rcv(rcvpkt) ampampisNAK(rcvpkt)
udt_send(NAK)
rdt_rcv(rcvpkt) ampamp corrupt(rcvpkt)
Wait for ACK or
NAK
Wait for call from
below
rdt_send(data)
Λ
Transport Layer 3-22
rdt20 has a fatal flaw
What happens if ACKNAK corruptedsender doesnrsquot know what happened at receivercanrsquot just retransmit possible duplicate
What to dosender ACKsNAKs receiverrsquos ACKNAK What if sender ACKNAK lostretransmit but this might cause retransmission of correctly received pkt
Handling duplicates sender adds sequence number to each pktsender retransmits current pkt if ACKNAK garbledreceiver discards (doesnrsquot deliver up) duplicate pkt
Sender sends one packet then waits for receiver response
stop and wait
Transport Layer 3-23
rdt21 sender handles garbled ACKNAKs
Wait for call 0 from
above
sndpkt = make_pkt(0 data checksum)udt_send(sndpkt)
rdt_send(data)
Wait for ACK or NAK 0 udt_send(sndpkt)
rdt_rcv(rcvpkt) ampamp ( corrupt(rcvpkt) ||isNAK(rcvpkt) )
sndpkt = make_pkt(1 data checksum)udt_send(sndpkt)
rdt_send(data)
rdt_rcv(rcvpkt) ampamp notcorrupt(rcvpkt) ampamp isACK(rcvpkt)
udt_send(sndpkt)
rdt_rcv(rcvpkt) ampamp ( corrupt(rcvpkt) ||isNAK(rcvpkt) )
rdt_rcv(rcvpkt) ampamp notcorrupt(rcvpkt) ampamp isACK(rcvpkt)
Wait forcall 1 from
above
Wait for ACK or NAK 1
ΛΛ
Transport Layer 3-24
rdt21 receiver handles garbled ACKNAKs
Wait for 0 from below
sndpkt = make_pkt(NAK chksum)udt_send(sndpkt)
rdt_rcv(rcvpkt) ampamp not corrupt(rcvpkt) ampamphas_seq0(rcvpkt)
rdt_rcv(rcvpkt) ampamp notcorrupt(rcvpkt) ampamp has_seq1(rcvpkt)
extract(rcvpktdata)deliver_data(data)sndpkt = make_pkt(ACK chksum)udt_send(sndpkt)
Wait for 1 from below
rdt_rcv(rcvpkt) ampamp notcorrupt(rcvpkt) ampamp has_seq0(rcvpkt)
extract(rcvpktdata)deliver_data(data)sndpkt = make_pkt(ACK chksum)udt_send(sndpkt)
rdt_rcv(rcvpkt) ampamp (corrupt(rcvpkt)
sndpkt = make_pkt(ACK chksum)udt_send(sndpkt)
rdt_rcv(rcvpkt) ampamp not corrupt(rcvpkt) ampamphas_seq1(rcvpkt)
rdt_rcv(rcvpkt) ampamp (corrupt(rcvpkt)
sndpkt = make_pkt(ACK chksum)udt_send(sndpkt)
sndpkt = make_pkt(NAK chksum)udt_send(sndpkt)
Transport Layer 3-25
rdt21 discussion
Senderseq added to pkttwo seq rsquos (01) will suffice Whymust check if received ACKNAK corrupted twice as many states
state must ldquorememberrdquowhether ldquocurrentrdquo pkt has 0 or 1 seq
Receivermust check if received packet is duplicate
state indicates whether 0 or 1 is expected pkt seq
note receiver can notknow if its last ACKNAK received OK at sender
Transport Layer 3-26
rdt22 a NAK-free protocol
same functionality as rdt21 using ACKs onlyinstead of NAK receiver sends ACK for last pkt received OK
receiver must explicitly include seq of pkt being ACKed duplicate ACK at sender results in same action as NAK retransmit current pkt
Transport Layer 3-27
rdt22 sender receiver fragments
Wait for call 0 from
above
sndpkt = make_pkt(0 data checksum)udt_send(sndpkt)
rdt_send(data)
udt_send(sndpkt)
rdt_rcv(rcvpkt) ampamp ( corrupt(rcvpkt) ||
isACK(rcvpkt1) )
rdt_rcv(rcvpkt) ampamp notcorrupt(rcvpkt) ampamp isACK(rcvpkt0)
Wait for ACK
0sender FSM
fragment
Wait for 0 from below
rdt_rcv(rcvpkt) ampamp notcorrupt(rcvpkt) ampamp has_seq1(rcvpkt)
extract(rcvpktdata)deliver_data(data)sndpkt = make_pkt(ACK1 chksum)udt_send(sndpkt)
rdt_rcv(rcvpkt) ampamp (corrupt(rcvpkt) ||
has_seq1(rcvpkt))
udt_send(sndpkt)receiver FSM
fragment
Λ
Transport Layer 3-28
rdt30 channels with errors and loss
New assumptionunderlying channel can also lose packets (data or ACKs)
checksum seq ACKs retransmissions will be of help but not enough
Q how to deal with losssender waits until certain data or ACK lost then retransmitsdrawbacks
Approach sender waits ldquoreasonablerdquo amount of time for ACK retransmits if no ACK received in this timeif pkt (or ACK) just delayed (not lost)
retransmission will be duplicate but use of seq rsquos already handles thisreceiver must specify seq of pkt being ACKed
requires countdown timer
Transport Layer 3-29
rdt30 sendersndpkt = make_pkt(0 data checksum)udt_send(sndpkt)start_timer
rdt_send(data)
Wait for
ACK0
rdt_rcv(rcvpkt) ampamp ( corrupt(rcvpkt) ||isACK(rcvpkt1) )
Wait for call 1 from
above
sndpkt = make_pkt(1 data checksum)udt_send(sndpkt)start_timer
rdt_send(data)
rdt_rcv(rcvpkt) ampamp notcorrupt(rcvpkt) ampamp isACK(rcvpkt0)
rdt_rcv(rcvpkt) ampamp ( corrupt(rcvpkt) ||isACK(rcvpkt0) )
rdt_rcv(rcvpkt) ampamp notcorrupt(rcvpkt) ampamp isACK(rcvpkt1)
stop_timerstop_timer
udt_send(sndpkt)start_timer
timeout
udt_send(sndpkt)start_timer
timeout
rdt_rcv(rcvpkt)
Wait for call 0from
above
Wait for
ACK1
Λrdt_rcv(rcvpkt)
ΛΛ
Λ
Transport Layer 3-30
rdt30 in action
Transport Layer 3-31
rdt30 in action
Transport Layer 3-32
Performance of rdt30
rdt30 works but performance stinksexample 1 Gbps link 15 ms e-e prop delay 1KB packet
Ttransmit = 8kbpkt109 bsec = 8 microsec
U sender utilization ndash fraction of time sender busy sending1KB pkt every 30 msec -gt 33kBsec thruput over 1 Gbps linknetwork protocol limits use of physical resources
U sender=
008 30008
= 000027 L RRTT + L R
=
L (packet length in bits)R (transmission rate bps) =
Transport Layer 3-33
rdt30 stop-and-wait operation
first packet bit transmitted t = 0
sender receiver
RTT
last packet bit transmitted t = L R
first packet bit arriveslast packet bit arrives send ACK
ACK arrives send next packet t = RTT + L R
U sender=
00830008
= 000027 L RRTT + L R
=
Transport Layer 3-34
Pipelined protocolsPipelining sender allows multiple ldquoin-flightrdquo yet-to-
be-acknowledged pktsrange of sequence numbers must be increasedbuffering at sender andor receiver
Two generic forms of pipelined protocols go-Back-N selective repeat
Transport Layer 3-35
Pipelining increased utilization
first packet bit transmitted t = 0
sender receiver
RTT
last bit transmitted t = L R
first packet bit arriveslast packet bit arrives send ACK
ACK arrives send next packet t = RTT + L R
last bit of 2nd packet arrives send ACKlast bit of 3rd packet arrives send ACK
U sender=
024 30008
= 000083 L RRTT + L R
=
Increase utilizationby a factor of 3
Transport Layer 3-36
Utilization=N(LR)(RTT+LR) if NLRltRTT+LR Utilization=1 if and the sender pauses after it transmits a window NLRgtRTT+LR and the of packets until it receives first ACK sender does not pause
Transport Layer 3-37
Go-Back-NSender
k-bit seq in pkt headerldquowindowrdquo of up to N consecutive unackrsquoed pkts allowed
ACK(n) ACKs all pkts up to including seq n - ldquocumulative ACKrdquomay receive duplicate ACKs (see receiver)
timer for the entire windowtimeout(n) retransmit pkt n and all higher seq pkts in window
Transport Layer 3-38
GBN sender extended FSM
Wait start_timerudt_send(sndpkt[base])udt_send(sndpkt[base+1])hellipudt_send(sndpkt[nextseqnum-1])
timeout
rdt_send(data)
if (nextseqnum lt base+N) sndpkt[nextseqnum] = make_pkt(nextseqnumdatachksum)udt_send(sndpkt[nextseqnum])if (base == nextseqnum)
start_timernextseqnum++
elserefuse_data(data)
base = getacknum(rcvpkt)+1If (base == nextseqnum)
stop_timerelse
start_timer
rdt_rcv(rcvpkt) ampamp notcorrupt(rcvpkt)
base=1nextseqnum=1
rdt_rcv(rcvpkt) ampamp corrupt(rcvpkt)
Λ
Λ
Transport Layer 3-39
GBN receiver extended FSM
ACK-only always send ACK for correctly-received pktwith highest in-order seq
may generate duplicate ACKsneed only remember expectedseqnum
out-of-order pkt discard (donrsquot buffer) -gt no receiver bufferingRe-ACK pkt with highest in-order seq
Wait
udt_send(sndpkt)default
rdt_rcv(rcvpkt)ampamp notcurrupt(rcvpkt)ampamp hasseqnum(rcvpktexpectedseqnum)
extract(rcvpktdata)deliver_data(data)sndpkt = make_pkt(expectedseqnumACKchksum)udt_send(sndpkt)expectedseqnum++
expectedseqnum=1sndpkt =
make_pkt(0ACKchksum)
Λ
Transport Layer 3-40
GBN inaction
Transport Layer 3-41
Selective Repeat
receiver individually acknowledges all correctly received pkts
buffers pkts as needed for eventual in-order delivery to upper layer
sender only resends pkts for which ACK not received
sender timer for each unACKed pktsender window
N consecutive seq rsquosagain limits seq s of sent unACKed pkts
Transport Layer 3-42
Selective repeat sender receiver windows
Transport Layer 3-43
Selective repeat
data from above if next available seq in window send pkt
timeout(n)resend pkt n restart timer
ACK(n) in [sendbasesendbase+N-1]
mark pkt n as receivedif n smallest unACKed pkt advance window base to next unACKed seq
senderpkt n in [rcvbase rcvbase+N-1]
send ACK(n)out-of-order bufferin-order deliver (also deliver buffered in-order pkts) advance window to next not-yet-received pkt
pkt n in [rcvbase-Nrcvbase-1]
ACK(n)otherwise
ignore
receiver
Transport Layer 3-44
Selective repeat in action
Transport Layer 3-45
Selective repeatdilemma
Example seq rsquos 0 1 2 3window size=3
receiver sees no difference in two scenariosincorrectly passes duplicate data as new in (a)
Q what relationship between seq size and window size
Transport Layer 3-46
Sequence Number vs Window SizeSuppose we use k bits to represent SNQuestion Whatrsquos the minimum number of bits k necessary for a window size of N
sender
receiver
Go-Back-N
expectedSN
snd_base=expectedSN
Q For a given expectedSN whatrsquos the largest possible value for snd_baseA If all the last N ACKs sent by the receiver are received
snd_base = expectedSNexpectedSN+N-1
senderrsquos window
Transport Layer 3-47
Sequence Number vs Window SizeSuppose we use k bits to represent SNQuestion Whatrsquos the minimum number of bits k necessary for a window size of N
sender
receiver
Go-Back-N
expectedSN
snd_base=expectedSN-N
Q For a given expectedSN whatrsquos the smallest possible value for snd_baseA If all the last N ACKs sent by the receiver are not received
snd_base = expectedSN-NexpectedSN-1
senderrsquos window
Transport Layer 3-48
Sequence Number vs Window Size
sender
receiver
Go-Back-N
expectedSN
snd_base=expectedSN-N
All SNs in the interval [expectedSN-NexpectedSN+N-1] (an interval of size 2N) can be received by the receiver Since the receiver accepts on the packet with SN=expectedSN there should be no other packet within this interval with SN=expectedSN Therefore
2k ge N+1expectedSN+N-1
Transport Layer 3-49
Sequence Number vs Window SizeSuppose we use k bits to represent SNQuestion Whatrsquos the minimum number of bits k necessary for a window size of N
sender
receiver
Selective Repeat
rcv_base
snd_base=rcv_base
Q For a given rcv_base whatrsquos the largest possible value for snd_baseA If all the last N ACKs sent by the receiver are received
snd_base = rcv_base (same as go_back-N)rcv_base+N-1
senderrsquos window
receiverrsquos window
rcv_base+N-1
Transport Layer 3-50
Sequence Number vs Window SizeSuppose we use k bits to represent SNQuestion Whatrsquos the minimum number of bits k necessary for a window size of N
sender
receiver
Selective Repeat
rcv_base
snd_base=rcv_base-N
Q For a given rcv_base whatrsquos the smallest possible value for snd_baseA If all the last N ACKs sent by the receiver are not received
snd_base = rcv_base-N (same as Go-Back-N)rcv_base-1
senderrsquos window
rcv_base
receiverrsquos window
rcv_base+N-1
Transport Layer 3-51
Sequence Number vs Window Size
sender
receiver
Selective Repeat
snd_base=rcv_base-N
All SNs in the interval [rcv_base-Nrcv_base+N-1] (an interval of size 2N) can be received by the receiver Since the receiver should be able to distinguish between all packets in this interval and take corresponding action there should be no two packets within thisinterval having the same SN Therefore
2k ge 2Nrcv_base+N-1
rcv_basercv_base
receiverrsquos window
rcv_base+N-1
Transport Layer 3-52
TCP Overview RFCs 793 1122 1323 2018 2581
full duplex databi-directional data flow in same connectionMSS maximum segment size
connection-orientedhandshaking (exchange of control msgs) initrsquossender receiver state before data exchange
flow controlledsender will not overwhelm receiver
point-to-pointone sender one receiver
reliable in-order byte stream
no ldquomessage boundariesrdquopipelined
TCP congestion and flow control set window size
send amp receive buffers
socketdoor
TCPsend buffer
TCPreceive buffer
socketdoor
segment
applicationwrites data
applicationreads data
Transport Layer 3-53
TCP segment structure
source port dest port
32 bits
applicationdata
(variable length)
sequence numberacknowledgement number
Receive windowUrg data pnterchecksum
FSRPAUheadlen
notused
Options (variable length)
URG urgent data (generally not used)
ACK ACK valid
PSH push data now(generally not used)
RST SYN FINconnection estab(setup teardown
commands)
bytes rcvr willingto accept
Internetchecksum
(as in UDP)
countingby bytes of data(not segments)
Transport Layer 3-54
TCP seq rsquos and ACKsSeq rsquos
byte stream ldquonumberrdquo of first byte in segmentrsquos dataACKs
seq of next byte expected from other sidecumulative ACK
Q how receiver handles out-of-order segmentsA TCP spec doesnrsquot say - up to implementationWidely used implementations of TCP buffer out-of-order segments
Transport Layer 3-55
TCP Round Trip Time and Timeout
Q how to set TCP timeout valuelonger than RTT
but RTT variestoo short premature timeout
unnecessary retransmissions
too long slow reaction to segment loss
Q how to estimate RTTSampleRTT measured time from segment transmission until ACK receipt
ignore retransmissionsSampleRTT will vary want estimated RTT ldquosmootherrdquo
average several recent measurements not just current SampleRTT
Transport Layer 3-56
TCP Round Trip Time and Timeout
EstimatedRTT = (1- α)EstimatedRTT + αSampleRTT
Exponential weighted moving averageinfluence of past sample decreases exponentially fasttypical value α = 0125
Transport Layer 3-57
Example RTT estimationRTT gaiacsumassedu to fantasiaeurecomfr
100
150
200
250
300
350
1 8 15 22 29 36 43 50 57 64 71 78 85 92 99 106
time (seconnds)
RTT
(mill
iseco
nds)
SampleRTT Estimated RTT
Transport Layer 3-58
TCP Round Trip Time and TimeoutSetting the timeout
EstimatedRTT plus ldquosafety marginrdquolarge variation in EstimatedRTT -gt larger safety margin
first estimate of how much SampleRTT deviates from EstimatedRTT
TimeoutInterval = EstimatedRTT + 4DevRTT
DevRTT = (1-β)DevRTT +β|SampleRTT-EstimatedRTT|
(typically β = 025)
Then set timeout interval
Transport Layer 3-59
TCP reliable data transfer
TCP creates rdtservice on top of IPrsquos unreliable servicePipelined segmentsCumulative acksTCP uses single retransmission timer however it just retransmits the first segment in the window
Retransmissions are triggered by
timeout eventsduplicate acks
Initially consider simplified TCP sender
ignore duplicate acksignore flow control congestion control
Transport Layer 3-60
TCP sender eventsdata rcvd from app
Create segment with seq seq is byte-stream number of first data byte in segmentstart timer if not already running (think of timer as for oldest unacked segment)expiration interval TimeOutInterval
timeoutretransmit segment that caused timeout (first segment in the window)restart timer
Ack rcvdIf acknowledges previously unacked segments
update what is known to be ackedstart timer if there are outstanding segments
Transport Layer 3-61
TCP sender(simplified)
NextSeqNum = InitialSeqNumSendBase = InitialSeqNum
loop (forever) switch(event)
event data received from application above create TCP segment with sequence number NextSeqNumif (timer currently not running)
start timerpass segment to IP NextSeqNum = NextSeqNum + length(data)
event timer timeoutretransmit not-yet-acknowledged segment with
smallest sequence numberstart timer
event ACK received with ACK field value of y if (y gt SendBase)
SendBase = yif (there are currently not-yet-acknowledged segments)
start timer
end of loop forever
Commentbull SendBase-1 last cumulatively ackrsquoed byteExamplebull SendBase-1 = 71y= 73 so the rcvrwants 73+ y gt SendBase sothat new data is acked
Transport Layer 3-62
TCP retransmission scenariosHost A
Seq=100 20 bytes data
ACK=100
timepremature timeout
Host B
Seq=92 8 bytes data
ACK=120
Seq=92 8 bytes data
Seq=
92 t
imeo
ut
ACK=120
Host A
Seq=92 8 bytes data
ACK=100
loss
tim
eout
lost ACK scenario
Host B
X
Seq=92 8 bytes data
ACK=100
time
Seq=
92 t
imeo
utSendBase
= 100
SendBase= 120
SendBase= 120
Sendbase= 100
Transport Layer 3-63
TCP retransmission scenarios (more)Host A
Seq=92 8 bytes data
ACK=100
loss
tim
eout
Cumulative ACK scenario
Host B
X
Seq=100 20 bytes data
ACK=120
time
SendBase= 120
Transport Layer 3-64
TCP ACK generation [RFC 1122 RFC 2581]
Event at Receiver
Arrival of in-order segment withexpected seq All data up toexpected seq already ACKed
Arrival of in-order segment withexpected seq One other segment has ACK pending
Arrival of out-of-order segmenthigher-than-expect seq Gap detected
Arrival of segment that partially or completely fills gap
TCP Receiver action
Delayed ACK Wait up to 500msfor next segment If no next segmentsend ACK
Immediately send single cumulative ACK ACKing both in-order segments
Immediately send duplicate ACK indicating seq of next expected byte
Immediate send ACK provided thatsegment startsat lower end of gap
Transport Layer 3-65
Fast Retransmit
Time-out period often relatively long
long delay before resending lost packet
Detect lost segments via duplicate ACKs
Sender often sends many segments back-to-backIf segment is lost there will likely be many duplicate ACKs
If sender receives 3 ACKs for the same data it supposes that segment after ACKeddata was lost
fast retransmit resend segment before timer expires
Transport Layer 3-66
Fast RetransmitResend a segment after 3 duplicate ACKs since a duplicate ACK means that an out-of sequence segment was receivedduplicate ACKs due to packet reorderingif window is small donrsquot get duplicate ACKs
Host A
tim
eout
Host B
time
X
resend seq X2
seq x1seq x2seq x3seq x4seq x5
ACK x1
ACK x1ACK x1ACK x1
tripleduplicate
ACKs
Transport Layer 3-67
event ACK received with ACK field value of y if (y gt SendBase)
SendBase = yif (there are currently not-yet-acknowledged segments)
start timer
else increment count of dup ACKs received for yif (count of dup ACKs received for y = 3)
resend segment with sequence number y
Fast retransmit algorithm
a duplicate ACK for already ACKed segment
fast retransmit
Transport Layer 3-68
TCP Flow Control
receive side of TCP connection has a receive buffer
speed-matching service matching the send rate to the receiving apprsquos drain rate
app process may be slow at reading from buffer
sender wonrsquot overflowreceiverrsquos buffer by
transmitting too muchtoo fast
flow control
Transport Layer 3-69
TCP Flow control how it works
(Suppose TCP receiver discards out-of-order segments)spare room in buffer
= RcvWin
= RcvBuffer-[LastByteRcvd -LastByteRead]
Rcvr advertises spare room by including value of RcvWin in segmentsSender limits unACKeddata to RcvWin
guarantees receive buffer doesnrsquot overflow
Transport Layer 3-70
Sliding Window Flow Control Example
3K
2K SeqNo=0
ReceiverBuffer
0 4KSendersends 2Kof data
2K
AckNo=2048 RcvWin=2048Sendersends 2Kof data 2K SeqNo=2048
4K
AckNo=4096 RcvWin=0
AckNo=4096 RcvWin=1024
Sender blocked
Transport Layer 3-71
Principles of Congestion Control
Congestioninformally ldquotoo many sources sending too much data too fast for network to handlerdquodifferent from flow controlmanifestations
lost packets (buffer overflow at routers)long delays (queueing in router buffers)
a top-10 problem
Transport Layer 3-72
Causescosts of congestion scenario 1
two senders two receiversone router infinite buffers no retransmission
large delays when congestedmaximum achievable throughput
unlimited shared output link buffers
Host Aλin original data
Host B
λout
Transport Layer 3-73
Causescosts of congestion scenario 2
one router finite buffers sender retransmission of lost packet
finite shared output link buffers
Host A λin original data
Host B
λout
λin original data plus retransmitted data
Transport Layer 3-74
Causescosts of congestion scenario 2always (goodput)ldquoperfectrdquo retransmission only when loss
retransmission of delayed (not lost) packet makes larger(than perfect case) for same
λin
λout=
λin
λoutgtλ
inλout
ldquocostsrdquo of congestionmore work (retrans) for given ldquogoodputrdquounneeded retransmissions link carries multiple copies of pkt
R2
R2λin
λ out
b
R2
R2λin
λ out
a
R2
R2λin
λ out
c
R4
R3
Transport Layer 3-75
Causescosts of congestion scenario 3four sendersmultihop pathstimeoutretransmit
λin
Q what happens as and increase λ
in
finite shared output link buffers
Host Aλin original data
Host B
λout
λin original data plus retransmitted data
Transport Layer 3-76
Causescosts of congestion scenario 3
another ldquocostrdquo of congestionwhen packet dropped any ldquoupstream transmission capacity used for that packet was wasted
Host A
Host B
λou
t
Transport Layer 3-77
Approaches towards congestion control
End-end congestion controlno explicit feedback from networkcongestion inferred from end-system observed loss delayapproach taken by TCP
Network-assisted congestion controlrouters provide feedback to end systems
single bit indicating congestion (SNA DECbit TCPIP ECN ATM)explicit rate sender should send at
Two broad approaches towards congestion control
Transport Layer 3-78
TCP Congestion Control
end-end control (no network assistance)sender limits transmissionLastByteSent-LastByteAcked
le CongWin
CongWin is dynamic function of perceived network congestion
How does sender perceive congestionloss event = timeout or3 duplicate acksTCP sender reduces rate (CongWin) after loss event
two modes of operationSlow Start (SS)Congestion avoidance (CA) or Additive Increase Multiplicative Decrease (AIMD)
Transport Layer 3-79
TCP congestion control bandwidth probing
ldquoprobing for bandwidthrdquo increase transmission rate on receipt of ACK until eventually loss occurs then decrease transmission rate
continue to increase on ACK decrease on loss (since available bandwidth is changing depending on other connections in network)
ACKs being received so increase rate
X
X
XX
X loss so decrease rate
send
ing
rate
time
Q how fast to increasedecreasedetails to follow
TCPrsquosldquosawtoothrdquobehavior
Transport Layer 3-80
TCP Congestion Control details
sender limits rate by limiting number of unACKed bytes ldquoin pipelinerdquo
cwnd differs from rwnd (how why)sender limited by min(cwndrwnd)
roughly
cwnd is dynamic function of perceived network congestion
rate = cwndRTT bytessec
LastByteSent-LastByteAcked le cwnd
cwndbytes
RTT
ACK(s)
Transport Layer 3-81
TCP Congestion Control more details
segment loss event reducing cwndtimeout no response from receiver
cut cwnd to 13 duplicate ACKs at least some segments getting through (recall fast retransmit)
cut cwnd in half less aggressively than on timeout
ACK received increase cwndTwo modes of operation
slowstart phase bull increase exponentially
fast (despite name) at connection start or following timeout
congestion avoidance bull increase linearly
Transport Layer 3-82
TCP Slow Start Phasewhen connection begins cwnd = 1 MSS
example MSS = 500 bytes amp RTT = 200 msecinitial rate = 20 kbps
available bandwidth may be gtgt MSSRTT
desirable to quickly ramp up to respectable rate
increase rate exponentially until first loss event or when threshold reached
double cwnd every RTTdone by incrementing cwnd by 1 for every ACK received
Host A
one segment
RTT
Host B
time
two segments
four segments
Transport Layer 3-83
Slow Start ExampleThe congestion window size grows very rapidly
For every ACK we increase CongWin by 1 irrespective of the number of segments ACKrsquoeddouble CongWinevery RTTinitial rate is slow but ramps up exponentially fast
TCP slows down the increase of CongWinwhen CongWin gt ssthresh
segment 1
ACK for segment 1
cwnd = 1
cwnd = 2 segment 2segment 3
ACK for segments 2
cwnd = 4 segment 4segment 5segment 6
ACK for segments 4
cwnd = 7
ACK for segments 3
ACK for segments 5
ACK for segments 6
cwnd = 3
cwnd = 5
cwnd = 6ACK for segments 7
cwnd = 8
segment 7
Transport Layer 3-84
TCP Congestion Avoidance Phase
when cwnd gt ssthreshgrow cwnd linearly
increase cwnd by 1 MSS per RTT approach possible congestion slower than in slowstartimplementation cwnd= cwnd + MSScwndfor each ACK received
ACKs increase cwndby 1 MSS per RTT additive increaseloss cut cwnd in half (non-timeout-detected loss ) multiplicative decrease
AIMD
AIMD Additive IncreaseMultiplicative Decrease
Transport Layer 3-85
Congestion AvoidanceCongestion avoidance phase is started if CongWin has reached the slow-start threshold value
If CongWin gt= ssthresh then each time an ACK is received increment CongWin as follows
bull CongWin = CongWin + 1CongWin (CongWin in segments)
bull In actual TCP implementation CongWin is in BytesCongWin = CongWin + MSS (MSSCongWin)
So CongWin is increased by one only if all CongWinsegments have been acknowledged
Transport Layer 3-86
Example Slow StartCongestion AvoidanceAssume that
ssthresh = 8
cwnd = 1
cwnd = 2
cwnd = 4
cwnd = 8
cwnd = 9
cwnd = 10
02468
101214
t=0
t=2
t=4
t=6
Roundtrip times
Cw
nd(in
seg
men
ts)
ssthresh
cwnd = 3
cwnd = 5cwnd = 6cwnd = 7
Transport Layer 3-87
Slow Start Congestion AvoidanceA typical plot of CongWin for a TCP connection
(MSS = 1500 bytes) with TCP Tahoe
SS
CA
ssthresh
Transport Layer 3-88
Responses to CongestionTCP assumes there is congestion if it detects a packet lossA TCP sender can detect lost packets via loss events
bull Timeout of a retransmission timerbull Receipt of 3 duplicate ACKs (fast retransmit)
TCP interprets a Timeout as a binary congestion signal When a timeout occurs the sender performs
ssthresh is set to half the current size of the congestion window
ssthresh = CongWin 2CongWin is reset to one
CongWin = 1and slow-start is entered
Transport Layer 3-89
Fast Recovery (differentiation btwn two loss events) After 3 dup ACKs (fast Retransmit)
ssthresh = CongWin2CongWin = CongWin2window then grows linearly
But after timeout eventCongWin = 1 MSS window then grows exponentiallyto the threshold then grows linearly
bull 3 dup ACKs indicates network capable of delivering some segmentsbull timeout before 3 dup ACKs is ldquomore alarmingrdquo
Philosophy
3-90
TCP Congestion ControlInitially
CongWin = 1ssthresh = advertised window size
New Ack receivedif (CongWin lt ssthresh) Slow Start
CongWin = CongWin + 1else Congestion Avoidance
CongWin = CongWin + 1CongWinTimeout
ssthresh = CongWin2CongWin = 1
Fast Retransmissionssthresh = CongWin2CongWin = CongWin2
Slow Start (exponential increase phase) is continued until CongWin reaches half of the level where the loss event occurred last time CongWin is increased slowly after (linear increase in Congestion Avoidance phase)
Transport Layer 3-91
Popular ldquoflavorsrdquo of TCP
ssthresh
ssthresh
TCP Tahoe
TCP Reno
Transmission round
cwnd
win
dow
siz
e (in
seg
men
ts)
Transport Layer 3-92
Summary TCP Congestion ControlWhen CongWin is below Threshold sender in slow-start phase window grows exponentiallyWhen CongWin is above Threshold sender is in congestion-avoidance phase window grows linearlyWhen a triple duplicate ACK occurs Threshold set to CongWin2 and CongWin set to ThresholdWhen timeout occurs Threshold set to CongWin2 and CongWin is set to 1 MSS The actual sender window size is determined based on the congestion and flow control algorithms
SenderWin=min(RcvWinCongWin)
Transport Layer 3-93
TCP Congestion Control SummaryEvent State TCP Sender Action Commentary
ACK receipt for previously unackeddata
Slow Start (SS)
CongWin = CongWin + MSS If (CongWin gt Threshold)
set state to ldquoCongestion Avoidancerdquo
Resulting in a doubling of CongWin every RTT
ACK receipt for previously unackeddata
CongestionAvoidance (CA)
CongWin = CongWin+MSS (MSSCongWin)
Additive increase resulting in increase of CongWin by 1 MSS every RTT
Loss event detected by triple duplicate ACK
SS or CA Threshold = CongWin2 CongWin = ThresholdSet state to ldquoCongestion Avoidancerdquo
Fast recovery implementing multiplicative decrease CongWin will not drop below 1 MSS
Timeout SS or CA Threshold = CongWin2 CongWin = 1 MSSSet state to ldquoSlow Startrdquo
Enter slow start
Duplicate ACK
SS or CA Increment duplicate ACK count for segment being acked
CongWin and Threshold not changed
Transport Layer 3-94
TCP throughput
Q whatrsquos average throughout of TCP as function of window size RTT
ignoring slow startlet W be window size when loss occurs
when window is W throughput is WRTTjust after loss window drops to W2 throughput to W2RTT average throughout 75 WRTT
Transport Layer 3-95
TCP Futures TCP over ldquolong fat pipesrdquo
example 1500 byte segments 100ms RTT want 10 Gbps throughputrequires window size W = 83333 in-flight segmentsthroughput in terms of loss rate
L = 210-10 Wownew versions of TCP for high-speed
LRTTMSSsdot221
Transport Layer 3-96
Fairness goal if K TCP sessions share same bottleneck link of bandwidth R each should have average rate of RK
TCP connection 1
bottleneckrouter
capacity R
TCP connection 2
TCP Fairness
Transport Layer 3-97
Why is TCP fairTwo competing sessions
Additive increase gives slope of 1 as throughout increasesmultiplicative decrease decreases throughput proportionally
R
R
equal bandwidth share
Connection 1 throughput
Conn
ecti
on 2
thr
ough
p ut
congestion avoidance additive increaseloss decrease window by factor of 2
congestion avoidance additive increaseloss decrease window by factor of 2
Transport Layer 3-98
Fairness (more)Fairness and UDP
Multimedia apps often do not use TCP
do not want rate throttled by congestion control
Instead use UDPpump audiovideo at constant rate tolerate packet loss
Research area TCP friendly
Fairness and parallel TCP connectionsnothing prevents app from opening parallel cnctionsbetween 2 hostsWeb browsers do this Example link of rate R supporting 9 cnctions
new app asks for 1 TCP gets rate R10new app asks for 11 TCPs gets R2
Transport Layer 3-99
TCP Connection ManagementRecall TCP sender receiver
establish ldquoconnectionrdquobefore exchanging data segmentsinitialize TCP variables
seq sbuffers flow control info (eg RcvWindow)
client connection initiatorSocket clientSocket = new Socket(hostnameport
number)
server contacted by clientSocket connectionSocket = welcomeSocketaccept()
Three way handshakeStep 1 client host sends TCP
SYN segment to serverspecifies initial seq no data
Step 2 server host receives SYN replies with SYNACK segment
server allocates buffersspecifies server initial seq
Step 3 client receives SYNACK replies with ACK segment which may contain data
Transport Layer 3-100
TCP Connection Management (cont)
Closing a connection
client closes socketclientSocketclose()
Step 1 client end system sends TCP FIN control segment to server
Step 2 server receives FIN replies with ACK Closes connection sends FIN
client
FIN
server
ACK
ACK
FIN
close
close
closed
tim
ed w
ait
Transport Layer 3-101
TCP Connection Management (cont)
Step 3 client receives FIN replies with ACK
Enters ldquotimed waitrdquo -will respond with ACK to received FINs
Step 4 server receives ACK Connection closed
client
FIN
server
ACK
ACK
FIN
closing
closing
closed
tim
ed w
ait
closed
Transport Layer 3-102
TCP Connection Management (cont)
TCP clientlifecycle
TCP serverlifecycle
Transport Layer 3-103
Tuning TCPIP Parameters TCPIP parameters
A set of default values may not be optimal for all applicationsThe network administrator may wish to turn on or off some TCPIP functions for performance or security considerations
Many Unix and Linux systems provide some flexibility in tuning the TCPIP kernelsbinsysctl is used to configure the Linux kernel parameters at runtime
Default kernel configuration file is sbinsysctlconfFrequently used sysctl options
bull sysctl ndasha or sysctl ndashA list all current valuesbull sysctl ndashp file_name load the sysctl setting from a configuration
filebull sysctl ndashw variable=value change the value of the parameter
Transport Layer 3-104
SomeTCP Parameters in Linux Kerneltcp_syn_retries
Number of SYN packets the kernel will send before giving up on the new connection
tcp_synack_retriesnumber of SYN+ACK packets sent before the kernel gives up on the connection
tcp_window_scalingMaximum window size of 65535 bytes not enough for for really fast networks The window scaling options allows for almost gigabyte windows which is good for connections with large delay-bandwidth product
tcp_max_syn_backlogMaximal number of remembered connection requests which still did not receive an acknowledgment from connecting client
tcp_fin_timeoutHow many seconds to wait for a final FIN packet before the socket is closed required to prevent denial-of-service (DoS) attacks Default value is 60 seconds
Transport Layer 3-105
SomeTCP Parameters in Linux Kerneltcp_rmem
This is a vector of 3 integers [min default max] These parameters are used by TCP to dynamically adjust receive buffer sizesmin - minimum size of the receive buffer used by each TCP socket The default value is 4K default - the default size of the receive buffer for a TCP socket The default value is 87380 bytes and is lowered to 43689 in low memory systems If larger receive buffer sizes are desired this value should be increased max - the maximum size of the receive buffer used by each TCP socket The default value of 873802 bytes is lowered to 87380 in low memory systems
tcp_smemSend buffer parameters [min default max] similar to tcp_rmem
- Chapter 3 Transport Layer
- Transport services and protocols
- Transport vs network layer
- Internet transport-layer protocols
- Multiplexingdemultiplexing
- How demultiplexing works
- Connectionless demultiplexing
- Connection-oriented demux
- Connection-oriented demux (cont)
- Connection-oriented demux Threaded Web Server
- UDP User Datagram Protocol [RFC 768]
- UDP more
- UDP checksum
- Principles of Reliable data transfer
- Reliable data transfer getting started
- Reliable data transfer getting started
- Rdt10 reliable transfer over a reliable channel
- Rdt20 channel with bit errors
- rdt20 FSM specification
- rdt20 operation with no errors
- rdt20 error scenario
- rdt20 has a fatal flaw
- rdt21 sender handles garbled ACKNAKs
- rdt21 receiver handles garbled ACKNAKs
- rdt21 discussion
- rdt22 a NAK-free protocol
- rdt22 sender receiver fragments
- rdt30 channels with errors and loss
- rdt30 sender
- rdt30 in action
- rdt30 in action
- Performance of rdt30
- rdt30 stop-and-wait operation
- Pipelined protocols
- Pipelining increased utilization
- Go-Back-N
- GBN sender extended FSM
- GBN receiver extended FSM
- GBN inaction
- Selective Repeat
- Selective repeat sender receiver windows
- Selective repeat
- Selective repeat in action
- Selective repeat dilemma
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- TCP Overview RFCs 793 1122 1323 2018 2581
- TCP segment structure
- TCP seq rsquos and ACKs
- TCP Round Trip Time and Timeout
- TCP Round Trip Time and Timeout
- Example RTT estimation
- TCP Round Trip Time and Timeout
- TCP reliable data transfer
- TCP sender events
- TCP sender(simplified)
- TCP retransmission scenarios
- TCP retransmission scenarios (more)
- TCP ACK generation [RFC 1122 RFC 2581]
- Fast Retransmit
- Fast Retransmit
- Fast retransmit algorithm
- TCP Flow Control
- TCP Flow control how it works
- Sliding Window Flow Control Example
- Principles of Congestion Control
- Causescosts of congestion scenario 1
- Causescosts of congestion scenario 2
- Causescosts of congestion scenario 2
- Causescosts of congestion scenario 3
- Causescosts of congestion scenario 3
- Approaches towards congestion control
- TCP Congestion Control
- TCP congestion control bandwidth probing
- TCP Congestion Control details
- TCP Congestion Control more details
- TCP Slow Start Phase
- Slow Start Example
- TCP Congestion Avoidance Phase
- Congestion Avoidance
- Example Slow StartCongestion Avoidance
- Slow Start Congestion Avoidance
- Responses to Congestion
- Fast Recovery (differentiation btwn two loss events)
- TCP Congestion Control
- Popular ldquoflavorsrdquo of TCP
- Summary TCP Congestion Control
- TCP Congestion Control Summary
- TCP throughput
- TCP Futures TCP over ldquolong fat pipesrdquo
- TCP Fairness
- Why is TCP fair
- Fairness (more)
- TCP Connection Management
- TCP Connection Management (cont)
- TCP Connection Management (cont)
- TCP Connection Management (cont)
- Tuning TCPIP Parameters
- SomeTCP Parameters in Linux Kernel
- SomeTCP Parameters in Linux Kernel
-
Transport Layer 3-16
Reliable data transfer getting startedWersquoll
incrementally develop sender receiver sides of reliable data transfer protocol (rdt)consider only unidirectional data transfer
but control info will flow on both directionsuse finite state machines (FSM) to specify sender receiver
state1
state2
event causing state transitionactions taken on state transition
state when in this ldquostaterdquo next state
uniquely determined by next event
eventactions
Transport Layer 3-17
Rdt10 reliable transfer over a reliable channel
underlying channel perfectly reliableno bit errorsno loss of packets
separate FSMs for sender receiversender sends data into underlying channelreceiver read data from underlying channel
Wait for call from above packet = make_pkt(data)
udt_send(packet)
rdt_send(data)extract (packetdata)deliver_data(data)
Wait for call from
below
rdt_rcv(packet)
sender receiver
Transport Layer 3-18
Rdt20 channel with bit errors
underlying channel may flip bits in packetrecall checksum to detect bit errors
the question how to recover from errorsacknowledgements (ACKs) receiver explicitly tells sender that pkt received OKnegative acknowledgements (NAKs) receiver explicitly tells sender that pkt had errorssender retransmits pkt on receipt of NAK
new mechanisms in rdt20 (beyond rdt10)error detectionreceiver feedback control msgs (ACKNAK) rcvr-gtsender
Transport Layer 3-19
rdt20 FSM specification
Wait for call from above
snkpkt = make_pkt(data checksum)udt_send(sndpkt)
extract(rcvpktdata)deliver_data(data)udt_send(ACK)
rdt_rcv(rcvpkt) ampamp notcorrupt(rcvpkt)
rdt_rcv(rcvpkt) ampamp isACK(rcvpkt)
udt_send(sndpkt)
rdt_rcv(rcvpkt) ampampisNAK(rcvpkt)
udt_send(NAK)
rdt_rcv(rcvpkt) ampamp corrupt(rcvpkt)
Wait for ACK or
NAK
Wait for call from
belowsender
receiverrdt_send(data)
Λ
Transport Layer 3-20
rdt20 operation with no errors
Wait for call from above
snkpkt = make_pkt(data checksum)udt_send(sndpkt)
extract(rcvpktdata)deliver_data(data)udt_send(ACK)
rdt_rcv(rcvpkt) ampamp notcorrupt(rcvpkt)
rdt_rcv(rcvpkt) ampamp isACK(rcvpkt)
udt_send(sndpkt)
rdt_rcv(rcvpkt) ampampisNAK(rcvpkt)
udt_send(NAK)
rdt_rcv(rcvpkt) ampamp corrupt(rcvpkt)
Wait for ACK or
NAK
Wait for call from
below
rdt_send(data)
Λ
Transport Layer 3-21
rdt20 error scenario
Wait for call from above
snkpkt = make_pkt(data checksum)udt_send(sndpkt)
extract(rcvpktdata)deliver_data(data)udt_send(ACK)
rdt_rcv(rcvpkt) ampamp notcorrupt(rcvpkt)
rdt_rcv(rcvpkt) ampamp isACK(rcvpkt)
udt_send(sndpkt)
rdt_rcv(rcvpkt) ampampisNAK(rcvpkt)
udt_send(NAK)
rdt_rcv(rcvpkt) ampamp corrupt(rcvpkt)
Wait for ACK or
NAK
Wait for call from
below
rdt_send(data)
Λ
Transport Layer 3-22
rdt20 has a fatal flaw
What happens if ACKNAK corruptedsender doesnrsquot know what happened at receivercanrsquot just retransmit possible duplicate
What to dosender ACKsNAKs receiverrsquos ACKNAK What if sender ACKNAK lostretransmit but this might cause retransmission of correctly received pkt
Handling duplicates sender adds sequence number to each pktsender retransmits current pkt if ACKNAK garbledreceiver discards (doesnrsquot deliver up) duplicate pkt
Sender sends one packet then waits for receiver response
stop and wait
Transport Layer 3-23
rdt21 sender handles garbled ACKNAKs
Wait for call 0 from
above
sndpkt = make_pkt(0 data checksum)udt_send(sndpkt)
rdt_send(data)
Wait for ACK or NAK 0 udt_send(sndpkt)
rdt_rcv(rcvpkt) ampamp ( corrupt(rcvpkt) ||isNAK(rcvpkt) )
sndpkt = make_pkt(1 data checksum)udt_send(sndpkt)
rdt_send(data)
rdt_rcv(rcvpkt) ampamp notcorrupt(rcvpkt) ampamp isACK(rcvpkt)
udt_send(sndpkt)
rdt_rcv(rcvpkt) ampamp ( corrupt(rcvpkt) ||isNAK(rcvpkt) )
rdt_rcv(rcvpkt) ampamp notcorrupt(rcvpkt) ampamp isACK(rcvpkt)
Wait forcall 1 from
above
Wait for ACK or NAK 1
ΛΛ
Transport Layer 3-24
rdt21 receiver handles garbled ACKNAKs
Wait for 0 from below
sndpkt = make_pkt(NAK chksum)udt_send(sndpkt)
rdt_rcv(rcvpkt) ampamp not corrupt(rcvpkt) ampamphas_seq0(rcvpkt)
rdt_rcv(rcvpkt) ampamp notcorrupt(rcvpkt) ampamp has_seq1(rcvpkt)
extract(rcvpktdata)deliver_data(data)sndpkt = make_pkt(ACK chksum)udt_send(sndpkt)
Wait for 1 from below
rdt_rcv(rcvpkt) ampamp notcorrupt(rcvpkt) ampamp has_seq0(rcvpkt)
extract(rcvpktdata)deliver_data(data)sndpkt = make_pkt(ACK chksum)udt_send(sndpkt)
rdt_rcv(rcvpkt) ampamp (corrupt(rcvpkt)
sndpkt = make_pkt(ACK chksum)udt_send(sndpkt)
rdt_rcv(rcvpkt) ampamp not corrupt(rcvpkt) ampamphas_seq1(rcvpkt)
rdt_rcv(rcvpkt) ampamp (corrupt(rcvpkt)
sndpkt = make_pkt(ACK chksum)udt_send(sndpkt)
sndpkt = make_pkt(NAK chksum)udt_send(sndpkt)
Transport Layer 3-25
rdt21 discussion
Senderseq added to pkttwo seq rsquos (01) will suffice Whymust check if received ACKNAK corrupted twice as many states
state must ldquorememberrdquowhether ldquocurrentrdquo pkt has 0 or 1 seq
Receivermust check if received packet is duplicate
state indicates whether 0 or 1 is expected pkt seq
note receiver can notknow if its last ACKNAK received OK at sender
Transport Layer 3-26
rdt22 a NAK-free protocol
same functionality as rdt21 using ACKs onlyinstead of NAK receiver sends ACK for last pkt received OK
receiver must explicitly include seq of pkt being ACKed duplicate ACK at sender results in same action as NAK retransmit current pkt
Transport Layer 3-27
rdt22 sender receiver fragments
Wait for call 0 from
above
sndpkt = make_pkt(0 data checksum)udt_send(sndpkt)
rdt_send(data)
udt_send(sndpkt)
rdt_rcv(rcvpkt) ampamp ( corrupt(rcvpkt) ||
isACK(rcvpkt1) )
rdt_rcv(rcvpkt) ampamp notcorrupt(rcvpkt) ampamp isACK(rcvpkt0)
Wait for ACK
0sender FSM
fragment
Wait for 0 from below
rdt_rcv(rcvpkt) ampamp notcorrupt(rcvpkt) ampamp has_seq1(rcvpkt)
extract(rcvpktdata)deliver_data(data)sndpkt = make_pkt(ACK1 chksum)udt_send(sndpkt)
rdt_rcv(rcvpkt) ampamp (corrupt(rcvpkt) ||
has_seq1(rcvpkt))
udt_send(sndpkt)receiver FSM
fragment
Λ
Transport Layer 3-28
rdt30 channels with errors and loss
New assumptionunderlying channel can also lose packets (data or ACKs)
checksum seq ACKs retransmissions will be of help but not enough
Q how to deal with losssender waits until certain data or ACK lost then retransmitsdrawbacks
Approach sender waits ldquoreasonablerdquo amount of time for ACK retransmits if no ACK received in this timeif pkt (or ACK) just delayed (not lost)
retransmission will be duplicate but use of seq rsquos already handles thisreceiver must specify seq of pkt being ACKed
requires countdown timer
Transport Layer 3-29
rdt30 sendersndpkt = make_pkt(0 data checksum)udt_send(sndpkt)start_timer
rdt_send(data)
Wait for
ACK0
rdt_rcv(rcvpkt) ampamp ( corrupt(rcvpkt) ||isACK(rcvpkt1) )
Wait for call 1 from
above
sndpkt = make_pkt(1 data checksum)udt_send(sndpkt)start_timer
rdt_send(data)
rdt_rcv(rcvpkt) ampamp notcorrupt(rcvpkt) ampamp isACK(rcvpkt0)
rdt_rcv(rcvpkt) ampamp ( corrupt(rcvpkt) ||isACK(rcvpkt0) )
rdt_rcv(rcvpkt) ampamp notcorrupt(rcvpkt) ampamp isACK(rcvpkt1)
stop_timerstop_timer
udt_send(sndpkt)start_timer
timeout
udt_send(sndpkt)start_timer
timeout
rdt_rcv(rcvpkt)
Wait for call 0from
above
Wait for
ACK1
Λrdt_rcv(rcvpkt)
ΛΛ
Λ
Transport Layer 3-30
rdt30 in action
Transport Layer 3-31
rdt30 in action
Transport Layer 3-32
Performance of rdt30
rdt30 works but performance stinksexample 1 Gbps link 15 ms e-e prop delay 1KB packet
Ttransmit = 8kbpkt109 bsec = 8 microsec
U sender utilization ndash fraction of time sender busy sending1KB pkt every 30 msec -gt 33kBsec thruput over 1 Gbps linknetwork protocol limits use of physical resources
U sender=
008 30008
= 000027 L RRTT + L R
=
L (packet length in bits)R (transmission rate bps) =
Transport Layer 3-33
rdt30 stop-and-wait operation
first packet bit transmitted t = 0
sender receiver
RTT
last packet bit transmitted t = L R
first packet bit arriveslast packet bit arrives send ACK
ACK arrives send next packet t = RTT + L R
U sender=
00830008
= 000027 L RRTT + L R
=
Transport Layer 3-34
Pipelined protocolsPipelining sender allows multiple ldquoin-flightrdquo yet-to-
be-acknowledged pktsrange of sequence numbers must be increasedbuffering at sender andor receiver
Two generic forms of pipelined protocols go-Back-N selective repeat
Transport Layer 3-35
Pipelining increased utilization
first packet bit transmitted t = 0
sender receiver
RTT
last bit transmitted t = L R
first packet bit arriveslast packet bit arrives send ACK
ACK arrives send next packet t = RTT + L R
last bit of 2nd packet arrives send ACKlast bit of 3rd packet arrives send ACK
U sender=
024 30008
= 000083 L RRTT + L R
=
Increase utilizationby a factor of 3
Transport Layer 3-36
Utilization=N(LR)(RTT+LR) if NLRltRTT+LR Utilization=1 if and the sender pauses after it transmits a window NLRgtRTT+LR and the of packets until it receives first ACK sender does not pause
Transport Layer 3-37
Go-Back-NSender
k-bit seq in pkt headerldquowindowrdquo of up to N consecutive unackrsquoed pkts allowed
ACK(n) ACKs all pkts up to including seq n - ldquocumulative ACKrdquomay receive duplicate ACKs (see receiver)
timer for the entire windowtimeout(n) retransmit pkt n and all higher seq pkts in window
Transport Layer 3-38
GBN sender extended FSM
Wait start_timerudt_send(sndpkt[base])udt_send(sndpkt[base+1])hellipudt_send(sndpkt[nextseqnum-1])
timeout
rdt_send(data)
if (nextseqnum lt base+N) sndpkt[nextseqnum] = make_pkt(nextseqnumdatachksum)udt_send(sndpkt[nextseqnum])if (base == nextseqnum)
start_timernextseqnum++
elserefuse_data(data)
base = getacknum(rcvpkt)+1If (base == nextseqnum)
stop_timerelse
start_timer
rdt_rcv(rcvpkt) ampamp notcorrupt(rcvpkt)
base=1nextseqnum=1
rdt_rcv(rcvpkt) ampamp corrupt(rcvpkt)
Λ
Λ
Transport Layer 3-39
GBN receiver extended FSM
ACK-only always send ACK for correctly-received pktwith highest in-order seq
may generate duplicate ACKsneed only remember expectedseqnum
out-of-order pkt discard (donrsquot buffer) -gt no receiver bufferingRe-ACK pkt with highest in-order seq
Wait
udt_send(sndpkt)default
rdt_rcv(rcvpkt)ampamp notcurrupt(rcvpkt)ampamp hasseqnum(rcvpktexpectedseqnum)
extract(rcvpktdata)deliver_data(data)sndpkt = make_pkt(expectedseqnumACKchksum)udt_send(sndpkt)expectedseqnum++
expectedseqnum=1sndpkt =
make_pkt(0ACKchksum)
Λ
Transport Layer 3-40
GBN inaction
Transport Layer 3-41
Selective Repeat
receiver individually acknowledges all correctly received pkts
buffers pkts as needed for eventual in-order delivery to upper layer
sender only resends pkts for which ACK not received
sender timer for each unACKed pktsender window
N consecutive seq rsquosagain limits seq s of sent unACKed pkts
Transport Layer 3-42
Selective repeat sender receiver windows
Transport Layer 3-43
Selective repeat
data from above if next available seq in window send pkt
timeout(n)resend pkt n restart timer
ACK(n) in [sendbasesendbase+N-1]
mark pkt n as receivedif n smallest unACKed pkt advance window base to next unACKed seq
senderpkt n in [rcvbase rcvbase+N-1]
send ACK(n)out-of-order bufferin-order deliver (also deliver buffered in-order pkts) advance window to next not-yet-received pkt
pkt n in [rcvbase-Nrcvbase-1]
ACK(n)otherwise
ignore
receiver
Transport Layer 3-44
Selective repeat in action
Transport Layer 3-45
Selective repeatdilemma
Example seq rsquos 0 1 2 3window size=3
receiver sees no difference in two scenariosincorrectly passes duplicate data as new in (a)
Q what relationship between seq size and window size
Transport Layer 3-46
Sequence Number vs Window SizeSuppose we use k bits to represent SNQuestion Whatrsquos the minimum number of bits k necessary for a window size of N
sender
receiver
Go-Back-N
expectedSN
snd_base=expectedSN
Q For a given expectedSN whatrsquos the largest possible value for snd_baseA If all the last N ACKs sent by the receiver are received
snd_base = expectedSNexpectedSN+N-1
senderrsquos window
Transport Layer 3-47
Sequence Number vs Window SizeSuppose we use k bits to represent SNQuestion Whatrsquos the minimum number of bits k necessary for a window size of N
sender
receiver
Go-Back-N
expectedSN
snd_base=expectedSN-N
Q For a given expectedSN whatrsquos the smallest possible value for snd_baseA If all the last N ACKs sent by the receiver are not received
snd_base = expectedSN-NexpectedSN-1
senderrsquos window
Transport Layer 3-48
Sequence Number vs Window Size
sender
receiver
Go-Back-N
expectedSN
snd_base=expectedSN-N
All SNs in the interval [expectedSN-NexpectedSN+N-1] (an interval of size 2N) can be received by the receiver Since the receiver accepts on the packet with SN=expectedSN there should be no other packet within this interval with SN=expectedSN Therefore
2k ge N+1expectedSN+N-1
Transport Layer 3-49
Sequence Number vs Window SizeSuppose we use k bits to represent SNQuestion Whatrsquos the minimum number of bits k necessary for a window size of N
sender
receiver
Selective Repeat
rcv_base
snd_base=rcv_base
Q For a given rcv_base whatrsquos the largest possible value for snd_baseA If all the last N ACKs sent by the receiver are received
snd_base = rcv_base (same as go_back-N)rcv_base+N-1
senderrsquos window
receiverrsquos window
rcv_base+N-1
Transport Layer 3-50
Sequence Number vs Window SizeSuppose we use k bits to represent SNQuestion Whatrsquos the minimum number of bits k necessary for a window size of N
sender
receiver
Selective Repeat
rcv_base
snd_base=rcv_base-N
Q For a given rcv_base whatrsquos the smallest possible value for snd_baseA If all the last N ACKs sent by the receiver are not received
snd_base = rcv_base-N (same as Go-Back-N)rcv_base-1
senderrsquos window
rcv_base
receiverrsquos window
rcv_base+N-1
Transport Layer 3-51
Sequence Number vs Window Size
sender
receiver
Selective Repeat
snd_base=rcv_base-N
All SNs in the interval [rcv_base-Nrcv_base+N-1] (an interval of size 2N) can be received by the receiver Since the receiver should be able to distinguish between all packets in this interval and take corresponding action there should be no two packets within thisinterval having the same SN Therefore
2k ge 2Nrcv_base+N-1
rcv_basercv_base
receiverrsquos window
rcv_base+N-1
Transport Layer 3-52
TCP Overview RFCs 793 1122 1323 2018 2581
full duplex databi-directional data flow in same connectionMSS maximum segment size
connection-orientedhandshaking (exchange of control msgs) initrsquossender receiver state before data exchange
flow controlledsender will not overwhelm receiver
point-to-pointone sender one receiver
reliable in-order byte stream
no ldquomessage boundariesrdquopipelined
TCP congestion and flow control set window size
send amp receive buffers
socketdoor
TCPsend buffer
TCPreceive buffer
socketdoor
segment
applicationwrites data
applicationreads data
Transport Layer 3-53
TCP segment structure
source port dest port
32 bits
applicationdata
(variable length)
sequence numberacknowledgement number
Receive windowUrg data pnterchecksum
FSRPAUheadlen
notused
Options (variable length)
URG urgent data (generally not used)
ACK ACK valid
PSH push data now(generally not used)
RST SYN FINconnection estab(setup teardown
commands)
bytes rcvr willingto accept
Internetchecksum
(as in UDP)
countingby bytes of data(not segments)
Transport Layer 3-54
TCP seq rsquos and ACKsSeq rsquos
byte stream ldquonumberrdquo of first byte in segmentrsquos dataACKs
seq of next byte expected from other sidecumulative ACK
Q how receiver handles out-of-order segmentsA TCP spec doesnrsquot say - up to implementationWidely used implementations of TCP buffer out-of-order segments
Transport Layer 3-55
TCP Round Trip Time and Timeout
Q how to set TCP timeout valuelonger than RTT
but RTT variestoo short premature timeout
unnecessary retransmissions
too long slow reaction to segment loss
Q how to estimate RTTSampleRTT measured time from segment transmission until ACK receipt
ignore retransmissionsSampleRTT will vary want estimated RTT ldquosmootherrdquo
average several recent measurements not just current SampleRTT
Transport Layer 3-56
TCP Round Trip Time and Timeout
EstimatedRTT = (1- α)EstimatedRTT + αSampleRTT
Exponential weighted moving averageinfluence of past sample decreases exponentially fasttypical value α = 0125
Transport Layer 3-57
Example RTT estimationRTT gaiacsumassedu to fantasiaeurecomfr
100
150
200
250
300
350
1 8 15 22 29 36 43 50 57 64 71 78 85 92 99 106
time (seconnds)
RTT
(mill
iseco
nds)
SampleRTT Estimated RTT
Transport Layer 3-58
TCP Round Trip Time and TimeoutSetting the timeout
EstimatedRTT plus ldquosafety marginrdquolarge variation in EstimatedRTT -gt larger safety margin
first estimate of how much SampleRTT deviates from EstimatedRTT
TimeoutInterval = EstimatedRTT + 4DevRTT
DevRTT = (1-β)DevRTT +β|SampleRTT-EstimatedRTT|
(typically β = 025)
Then set timeout interval
Transport Layer 3-59
TCP reliable data transfer
TCP creates rdtservice on top of IPrsquos unreliable servicePipelined segmentsCumulative acksTCP uses single retransmission timer however it just retransmits the first segment in the window
Retransmissions are triggered by
timeout eventsduplicate acks
Initially consider simplified TCP sender
ignore duplicate acksignore flow control congestion control
Transport Layer 3-60
TCP sender eventsdata rcvd from app
Create segment with seq seq is byte-stream number of first data byte in segmentstart timer if not already running (think of timer as for oldest unacked segment)expiration interval TimeOutInterval
timeoutretransmit segment that caused timeout (first segment in the window)restart timer
Ack rcvdIf acknowledges previously unacked segments
update what is known to be ackedstart timer if there are outstanding segments
Transport Layer 3-61
TCP sender(simplified)
NextSeqNum = InitialSeqNumSendBase = InitialSeqNum
loop (forever) switch(event)
event data received from application above create TCP segment with sequence number NextSeqNumif (timer currently not running)
start timerpass segment to IP NextSeqNum = NextSeqNum + length(data)
event timer timeoutretransmit not-yet-acknowledged segment with
smallest sequence numberstart timer
event ACK received with ACK field value of y if (y gt SendBase)
SendBase = yif (there are currently not-yet-acknowledged segments)
start timer
end of loop forever
Commentbull SendBase-1 last cumulatively ackrsquoed byteExamplebull SendBase-1 = 71y= 73 so the rcvrwants 73+ y gt SendBase sothat new data is acked
Transport Layer 3-62
TCP retransmission scenariosHost A
Seq=100 20 bytes data
ACK=100
timepremature timeout
Host B
Seq=92 8 bytes data
ACK=120
Seq=92 8 bytes data
Seq=
92 t
imeo
ut
ACK=120
Host A
Seq=92 8 bytes data
ACK=100
loss
tim
eout
lost ACK scenario
Host B
X
Seq=92 8 bytes data
ACK=100
time
Seq=
92 t
imeo
utSendBase
= 100
SendBase= 120
SendBase= 120
Sendbase= 100
Transport Layer 3-63
TCP retransmission scenarios (more)Host A
Seq=92 8 bytes data
ACK=100
loss
tim
eout
Cumulative ACK scenario
Host B
X
Seq=100 20 bytes data
ACK=120
time
SendBase= 120
Transport Layer 3-64
TCP ACK generation [RFC 1122 RFC 2581]
Event at Receiver
Arrival of in-order segment withexpected seq All data up toexpected seq already ACKed
Arrival of in-order segment withexpected seq One other segment has ACK pending
Arrival of out-of-order segmenthigher-than-expect seq Gap detected
Arrival of segment that partially or completely fills gap
TCP Receiver action
Delayed ACK Wait up to 500msfor next segment If no next segmentsend ACK
Immediately send single cumulative ACK ACKing both in-order segments
Immediately send duplicate ACK indicating seq of next expected byte
Immediate send ACK provided thatsegment startsat lower end of gap
Transport Layer 3-65
Fast Retransmit
Time-out period often relatively long
long delay before resending lost packet
Detect lost segments via duplicate ACKs
Sender often sends many segments back-to-backIf segment is lost there will likely be many duplicate ACKs
If sender receives 3 ACKs for the same data it supposes that segment after ACKeddata was lost
fast retransmit resend segment before timer expires
Transport Layer 3-66
Fast RetransmitResend a segment after 3 duplicate ACKs since a duplicate ACK means that an out-of sequence segment was receivedduplicate ACKs due to packet reorderingif window is small donrsquot get duplicate ACKs
Host A
tim
eout
Host B
time
X
resend seq X2
seq x1seq x2seq x3seq x4seq x5
ACK x1
ACK x1ACK x1ACK x1
tripleduplicate
ACKs
Transport Layer 3-67
event ACK received with ACK field value of y if (y gt SendBase)
SendBase = yif (there are currently not-yet-acknowledged segments)
start timer
else increment count of dup ACKs received for yif (count of dup ACKs received for y = 3)
resend segment with sequence number y
Fast retransmit algorithm
a duplicate ACK for already ACKed segment
fast retransmit
Transport Layer 3-68
TCP Flow Control
receive side of TCP connection has a receive buffer
speed-matching service matching the send rate to the receiving apprsquos drain rate
app process may be slow at reading from buffer
sender wonrsquot overflowreceiverrsquos buffer by
transmitting too muchtoo fast
flow control
Transport Layer 3-69
TCP Flow control how it works
(Suppose TCP receiver discards out-of-order segments)spare room in buffer
= RcvWin
= RcvBuffer-[LastByteRcvd -LastByteRead]
Rcvr advertises spare room by including value of RcvWin in segmentsSender limits unACKeddata to RcvWin
guarantees receive buffer doesnrsquot overflow
Transport Layer 3-70
Sliding Window Flow Control Example
3K
2K SeqNo=0
ReceiverBuffer
0 4KSendersends 2Kof data
2K
AckNo=2048 RcvWin=2048Sendersends 2Kof data 2K SeqNo=2048
4K
AckNo=4096 RcvWin=0
AckNo=4096 RcvWin=1024
Sender blocked
Transport Layer 3-71
Principles of Congestion Control
Congestioninformally ldquotoo many sources sending too much data too fast for network to handlerdquodifferent from flow controlmanifestations
lost packets (buffer overflow at routers)long delays (queueing in router buffers)
a top-10 problem
Transport Layer 3-72
Causescosts of congestion scenario 1
two senders two receiversone router infinite buffers no retransmission
large delays when congestedmaximum achievable throughput
unlimited shared output link buffers
Host Aλin original data
Host B
λout
Transport Layer 3-73
Causescosts of congestion scenario 2
one router finite buffers sender retransmission of lost packet
finite shared output link buffers
Host A λin original data
Host B
λout
λin original data plus retransmitted data
Transport Layer 3-74
Causescosts of congestion scenario 2always (goodput)ldquoperfectrdquo retransmission only when loss
retransmission of delayed (not lost) packet makes larger(than perfect case) for same
λin
λout=
λin
λoutgtλ
inλout
ldquocostsrdquo of congestionmore work (retrans) for given ldquogoodputrdquounneeded retransmissions link carries multiple copies of pkt
R2
R2λin
λ out
b
R2
R2λin
λ out
a
R2
R2λin
λ out
c
R4
R3
Transport Layer 3-75
Causescosts of congestion scenario 3four sendersmultihop pathstimeoutretransmit
λin
Q what happens as and increase λ
in
finite shared output link buffers
Host Aλin original data
Host B
λout
λin original data plus retransmitted data
Transport Layer 3-76
Causescosts of congestion scenario 3
another ldquocostrdquo of congestionwhen packet dropped any ldquoupstream transmission capacity used for that packet was wasted
Host A
Host B
λou
t
Transport Layer 3-77
Approaches towards congestion control
End-end congestion controlno explicit feedback from networkcongestion inferred from end-system observed loss delayapproach taken by TCP
Network-assisted congestion controlrouters provide feedback to end systems
single bit indicating congestion (SNA DECbit TCPIP ECN ATM)explicit rate sender should send at
Two broad approaches towards congestion control
Transport Layer 3-78
TCP Congestion Control
end-end control (no network assistance)sender limits transmissionLastByteSent-LastByteAcked
le CongWin
CongWin is dynamic function of perceived network congestion
How does sender perceive congestionloss event = timeout or3 duplicate acksTCP sender reduces rate (CongWin) after loss event
two modes of operationSlow Start (SS)Congestion avoidance (CA) or Additive Increase Multiplicative Decrease (AIMD)
Transport Layer 3-79
TCP congestion control bandwidth probing
ldquoprobing for bandwidthrdquo increase transmission rate on receipt of ACK until eventually loss occurs then decrease transmission rate
continue to increase on ACK decrease on loss (since available bandwidth is changing depending on other connections in network)
ACKs being received so increase rate
X
X
XX
X loss so decrease rate
send
ing
rate
time
Q how fast to increasedecreasedetails to follow
TCPrsquosldquosawtoothrdquobehavior
Transport Layer 3-80
TCP Congestion Control details
sender limits rate by limiting number of unACKed bytes ldquoin pipelinerdquo
cwnd differs from rwnd (how why)sender limited by min(cwndrwnd)
roughly
cwnd is dynamic function of perceived network congestion
rate = cwndRTT bytessec
LastByteSent-LastByteAcked le cwnd
cwndbytes
RTT
ACK(s)
Transport Layer 3-81
TCP Congestion Control more details
segment loss event reducing cwndtimeout no response from receiver
cut cwnd to 13 duplicate ACKs at least some segments getting through (recall fast retransmit)
cut cwnd in half less aggressively than on timeout
ACK received increase cwndTwo modes of operation
slowstart phase bull increase exponentially
fast (despite name) at connection start or following timeout
congestion avoidance bull increase linearly
Transport Layer 3-82
TCP Slow Start Phasewhen connection begins cwnd = 1 MSS
example MSS = 500 bytes amp RTT = 200 msecinitial rate = 20 kbps
available bandwidth may be gtgt MSSRTT
desirable to quickly ramp up to respectable rate
increase rate exponentially until first loss event or when threshold reached
double cwnd every RTTdone by incrementing cwnd by 1 for every ACK received
Host A
one segment
RTT
Host B
time
two segments
four segments
Transport Layer 3-83
Slow Start ExampleThe congestion window size grows very rapidly
For every ACK we increase CongWin by 1 irrespective of the number of segments ACKrsquoeddouble CongWinevery RTTinitial rate is slow but ramps up exponentially fast
TCP slows down the increase of CongWinwhen CongWin gt ssthresh
segment 1
ACK for segment 1
cwnd = 1
cwnd = 2 segment 2segment 3
ACK for segments 2
cwnd = 4 segment 4segment 5segment 6
ACK for segments 4
cwnd = 7
ACK for segments 3
ACK for segments 5
ACK for segments 6
cwnd = 3
cwnd = 5
cwnd = 6ACK for segments 7
cwnd = 8
segment 7
Transport Layer 3-84
TCP Congestion Avoidance Phase
when cwnd gt ssthreshgrow cwnd linearly
increase cwnd by 1 MSS per RTT approach possible congestion slower than in slowstartimplementation cwnd= cwnd + MSScwndfor each ACK received
ACKs increase cwndby 1 MSS per RTT additive increaseloss cut cwnd in half (non-timeout-detected loss ) multiplicative decrease
AIMD
AIMD Additive IncreaseMultiplicative Decrease
Transport Layer 3-85
Congestion AvoidanceCongestion avoidance phase is started if CongWin has reached the slow-start threshold value
If CongWin gt= ssthresh then each time an ACK is received increment CongWin as follows
bull CongWin = CongWin + 1CongWin (CongWin in segments)
bull In actual TCP implementation CongWin is in BytesCongWin = CongWin + MSS (MSSCongWin)
So CongWin is increased by one only if all CongWinsegments have been acknowledged
Transport Layer 3-86
Example Slow StartCongestion AvoidanceAssume that
ssthresh = 8
cwnd = 1
cwnd = 2
cwnd = 4
cwnd = 8
cwnd = 9
cwnd = 10
02468
101214
t=0
t=2
t=4
t=6
Roundtrip times
Cw
nd(in
seg
men
ts)
ssthresh
cwnd = 3
cwnd = 5cwnd = 6cwnd = 7
Transport Layer 3-87
Slow Start Congestion AvoidanceA typical plot of CongWin for a TCP connection
(MSS = 1500 bytes) with TCP Tahoe
SS
CA
ssthresh
Transport Layer 3-88
Responses to CongestionTCP assumes there is congestion if it detects a packet lossA TCP sender can detect lost packets via loss events
bull Timeout of a retransmission timerbull Receipt of 3 duplicate ACKs (fast retransmit)
TCP interprets a Timeout as a binary congestion signal When a timeout occurs the sender performs
ssthresh is set to half the current size of the congestion window
ssthresh = CongWin 2CongWin is reset to one
CongWin = 1and slow-start is entered
Transport Layer 3-89
Fast Recovery (differentiation btwn two loss events) After 3 dup ACKs (fast Retransmit)
ssthresh = CongWin2CongWin = CongWin2window then grows linearly
But after timeout eventCongWin = 1 MSS window then grows exponentiallyto the threshold then grows linearly
bull 3 dup ACKs indicates network capable of delivering some segmentsbull timeout before 3 dup ACKs is ldquomore alarmingrdquo
Philosophy
3-90
TCP Congestion ControlInitially
CongWin = 1ssthresh = advertised window size
New Ack receivedif (CongWin lt ssthresh) Slow Start
CongWin = CongWin + 1else Congestion Avoidance
CongWin = CongWin + 1CongWinTimeout
ssthresh = CongWin2CongWin = 1
Fast Retransmissionssthresh = CongWin2CongWin = CongWin2
Slow Start (exponential increase phase) is continued until CongWin reaches half of the level where the loss event occurred last time CongWin is increased slowly after (linear increase in Congestion Avoidance phase)
Transport Layer 3-91
Popular ldquoflavorsrdquo of TCP
ssthresh
ssthresh
TCP Tahoe
TCP Reno
Transmission round
cwnd
win
dow
siz
e (in
seg
men
ts)
Transport Layer 3-92
Summary TCP Congestion ControlWhen CongWin is below Threshold sender in slow-start phase window grows exponentiallyWhen CongWin is above Threshold sender is in congestion-avoidance phase window grows linearlyWhen a triple duplicate ACK occurs Threshold set to CongWin2 and CongWin set to ThresholdWhen timeout occurs Threshold set to CongWin2 and CongWin is set to 1 MSS The actual sender window size is determined based on the congestion and flow control algorithms
SenderWin=min(RcvWinCongWin)
Transport Layer 3-93
TCP Congestion Control SummaryEvent State TCP Sender Action Commentary
ACK receipt for previously unackeddata
Slow Start (SS)
CongWin = CongWin + MSS If (CongWin gt Threshold)
set state to ldquoCongestion Avoidancerdquo
Resulting in a doubling of CongWin every RTT
ACK receipt for previously unackeddata
CongestionAvoidance (CA)
CongWin = CongWin+MSS (MSSCongWin)
Additive increase resulting in increase of CongWin by 1 MSS every RTT
Loss event detected by triple duplicate ACK
SS or CA Threshold = CongWin2 CongWin = ThresholdSet state to ldquoCongestion Avoidancerdquo
Fast recovery implementing multiplicative decrease CongWin will not drop below 1 MSS
Timeout SS or CA Threshold = CongWin2 CongWin = 1 MSSSet state to ldquoSlow Startrdquo
Enter slow start
Duplicate ACK
SS or CA Increment duplicate ACK count for segment being acked
CongWin and Threshold not changed
Transport Layer 3-94
TCP throughput
Q whatrsquos average throughout of TCP as function of window size RTT
ignoring slow startlet W be window size when loss occurs
when window is W throughput is WRTTjust after loss window drops to W2 throughput to W2RTT average throughout 75 WRTT
Transport Layer 3-95
TCP Futures TCP over ldquolong fat pipesrdquo
example 1500 byte segments 100ms RTT want 10 Gbps throughputrequires window size W = 83333 in-flight segmentsthroughput in terms of loss rate
L = 210-10 Wownew versions of TCP for high-speed
LRTTMSSsdot221
Transport Layer 3-96
Fairness goal if K TCP sessions share same bottleneck link of bandwidth R each should have average rate of RK
TCP connection 1
bottleneckrouter
capacity R
TCP connection 2
TCP Fairness
Transport Layer 3-97
Why is TCP fairTwo competing sessions
Additive increase gives slope of 1 as throughout increasesmultiplicative decrease decreases throughput proportionally
R
R
equal bandwidth share
Connection 1 throughput
Conn
ecti
on 2
thr
ough
p ut
congestion avoidance additive increaseloss decrease window by factor of 2
congestion avoidance additive increaseloss decrease window by factor of 2
Transport Layer 3-98
Fairness (more)Fairness and UDP
Multimedia apps often do not use TCP
do not want rate throttled by congestion control
Instead use UDPpump audiovideo at constant rate tolerate packet loss
Research area TCP friendly
Fairness and parallel TCP connectionsnothing prevents app from opening parallel cnctionsbetween 2 hostsWeb browsers do this Example link of rate R supporting 9 cnctions
new app asks for 1 TCP gets rate R10new app asks for 11 TCPs gets R2
Transport Layer 3-99
TCP Connection ManagementRecall TCP sender receiver
establish ldquoconnectionrdquobefore exchanging data segmentsinitialize TCP variables
seq sbuffers flow control info (eg RcvWindow)
client connection initiatorSocket clientSocket = new Socket(hostnameport
number)
server contacted by clientSocket connectionSocket = welcomeSocketaccept()
Three way handshakeStep 1 client host sends TCP
SYN segment to serverspecifies initial seq no data
Step 2 server host receives SYN replies with SYNACK segment
server allocates buffersspecifies server initial seq
Step 3 client receives SYNACK replies with ACK segment which may contain data
Transport Layer 3-100
TCP Connection Management (cont)
Closing a connection
client closes socketclientSocketclose()
Step 1 client end system sends TCP FIN control segment to server
Step 2 server receives FIN replies with ACK Closes connection sends FIN
client
FIN
server
ACK
ACK
FIN
close
close
closed
tim
ed w
ait
Transport Layer 3-101
TCP Connection Management (cont)
Step 3 client receives FIN replies with ACK
Enters ldquotimed waitrdquo -will respond with ACK to received FINs
Step 4 server receives ACK Connection closed
client
FIN
server
ACK
ACK
FIN
closing
closing
closed
tim
ed w
ait
closed
Transport Layer 3-102
TCP Connection Management (cont)
TCP clientlifecycle
TCP serverlifecycle
Transport Layer 3-103
Tuning TCPIP Parameters TCPIP parameters
A set of default values may not be optimal for all applicationsThe network administrator may wish to turn on or off some TCPIP functions for performance or security considerations
Many Unix and Linux systems provide some flexibility in tuning the TCPIP kernelsbinsysctl is used to configure the Linux kernel parameters at runtime
Default kernel configuration file is sbinsysctlconfFrequently used sysctl options
bull sysctl ndasha or sysctl ndashA list all current valuesbull sysctl ndashp file_name load the sysctl setting from a configuration
filebull sysctl ndashw variable=value change the value of the parameter
Transport Layer 3-104
SomeTCP Parameters in Linux Kerneltcp_syn_retries
Number of SYN packets the kernel will send before giving up on the new connection
tcp_synack_retriesnumber of SYN+ACK packets sent before the kernel gives up on the connection
tcp_window_scalingMaximum window size of 65535 bytes not enough for for really fast networks The window scaling options allows for almost gigabyte windows which is good for connections with large delay-bandwidth product
tcp_max_syn_backlogMaximal number of remembered connection requests which still did not receive an acknowledgment from connecting client
tcp_fin_timeoutHow many seconds to wait for a final FIN packet before the socket is closed required to prevent denial-of-service (DoS) attacks Default value is 60 seconds
Transport Layer 3-105
SomeTCP Parameters in Linux Kerneltcp_rmem
This is a vector of 3 integers [min default max] These parameters are used by TCP to dynamically adjust receive buffer sizesmin - minimum size of the receive buffer used by each TCP socket The default value is 4K default - the default size of the receive buffer for a TCP socket The default value is 87380 bytes and is lowered to 43689 in low memory systems If larger receive buffer sizes are desired this value should be increased max - the maximum size of the receive buffer used by each TCP socket The default value of 873802 bytes is lowered to 87380 in low memory systems
tcp_smemSend buffer parameters [min default max] similar to tcp_rmem
- Chapter 3 Transport Layer
- Transport services and protocols
- Transport vs network layer
- Internet transport-layer protocols
- Multiplexingdemultiplexing
- How demultiplexing works
- Connectionless demultiplexing
- Connection-oriented demux
- Connection-oriented demux (cont)
- Connection-oriented demux Threaded Web Server
- UDP User Datagram Protocol [RFC 768]
- UDP more
- UDP checksum
- Principles of Reliable data transfer
- Reliable data transfer getting started
- Reliable data transfer getting started
- Rdt10 reliable transfer over a reliable channel
- Rdt20 channel with bit errors
- rdt20 FSM specification
- rdt20 operation with no errors
- rdt20 error scenario
- rdt20 has a fatal flaw
- rdt21 sender handles garbled ACKNAKs
- rdt21 receiver handles garbled ACKNAKs
- rdt21 discussion
- rdt22 a NAK-free protocol
- rdt22 sender receiver fragments
- rdt30 channels with errors and loss
- rdt30 sender
- rdt30 in action
- rdt30 in action
- Performance of rdt30
- rdt30 stop-and-wait operation
- Pipelined protocols
- Pipelining increased utilization
- Go-Back-N
- GBN sender extended FSM
- GBN receiver extended FSM
- GBN inaction
- Selective Repeat
- Selective repeat sender receiver windows
- Selective repeat
- Selective repeat in action
- Selective repeat dilemma
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- TCP Overview RFCs 793 1122 1323 2018 2581
- TCP segment structure
- TCP seq rsquos and ACKs
- TCP Round Trip Time and Timeout
- TCP Round Trip Time and Timeout
- Example RTT estimation
- TCP Round Trip Time and Timeout
- TCP reliable data transfer
- TCP sender events
- TCP sender(simplified)
- TCP retransmission scenarios
- TCP retransmission scenarios (more)
- TCP ACK generation [RFC 1122 RFC 2581]
- Fast Retransmit
- Fast Retransmit
- Fast retransmit algorithm
- TCP Flow Control
- TCP Flow control how it works
- Sliding Window Flow Control Example
- Principles of Congestion Control
- Causescosts of congestion scenario 1
- Causescosts of congestion scenario 2
- Causescosts of congestion scenario 2
- Causescosts of congestion scenario 3
- Causescosts of congestion scenario 3
- Approaches towards congestion control
- TCP Congestion Control
- TCP congestion control bandwidth probing
- TCP Congestion Control details
- TCP Congestion Control more details
- TCP Slow Start Phase
- Slow Start Example
- TCP Congestion Avoidance Phase
- Congestion Avoidance
- Example Slow StartCongestion Avoidance
- Slow Start Congestion Avoidance
- Responses to Congestion
- Fast Recovery (differentiation btwn two loss events)
- TCP Congestion Control
- Popular ldquoflavorsrdquo of TCP
- Summary TCP Congestion Control
- TCP Congestion Control Summary
- TCP throughput
- TCP Futures TCP over ldquolong fat pipesrdquo
- TCP Fairness
- Why is TCP fair
- Fairness (more)
- TCP Connection Management
- TCP Connection Management (cont)
- TCP Connection Management (cont)
- TCP Connection Management (cont)
- Tuning TCPIP Parameters
- SomeTCP Parameters in Linux Kernel
- SomeTCP Parameters in Linux Kernel
-
Transport Layer 3-17
Rdt10 reliable transfer over a reliable channel
underlying channel perfectly reliableno bit errorsno loss of packets
separate FSMs for sender receiversender sends data into underlying channelreceiver read data from underlying channel
Wait for call from above packet = make_pkt(data)
udt_send(packet)
rdt_send(data)extract (packetdata)deliver_data(data)
Wait for call from
below
rdt_rcv(packet)
sender receiver
Transport Layer 3-18
Rdt20 channel with bit errors
underlying channel may flip bits in packetrecall checksum to detect bit errors
the question how to recover from errorsacknowledgements (ACKs) receiver explicitly tells sender that pkt received OKnegative acknowledgements (NAKs) receiver explicitly tells sender that pkt had errorssender retransmits pkt on receipt of NAK
new mechanisms in rdt20 (beyond rdt10)error detectionreceiver feedback control msgs (ACKNAK) rcvr-gtsender
Transport Layer 3-19
rdt20 FSM specification
Wait for call from above
snkpkt = make_pkt(data checksum)udt_send(sndpkt)
extract(rcvpktdata)deliver_data(data)udt_send(ACK)
rdt_rcv(rcvpkt) ampamp notcorrupt(rcvpkt)
rdt_rcv(rcvpkt) ampamp isACK(rcvpkt)
udt_send(sndpkt)
rdt_rcv(rcvpkt) ampampisNAK(rcvpkt)
udt_send(NAK)
rdt_rcv(rcvpkt) ampamp corrupt(rcvpkt)
Wait for ACK or
NAK
Wait for call from
belowsender
receiverrdt_send(data)
Λ
Transport Layer 3-20
rdt20 operation with no errors
Wait for call from above
snkpkt = make_pkt(data checksum)udt_send(sndpkt)
extract(rcvpktdata)deliver_data(data)udt_send(ACK)
rdt_rcv(rcvpkt) ampamp notcorrupt(rcvpkt)
rdt_rcv(rcvpkt) ampamp isACK(rcvpkt)
udt_send(sndpkt)
rdt_rcv(rcvpkt) ampampisNAK(rcvpkt)
udt_send(NAK)
rdt_rcv(rcvpkt) ampamp corrupt(rcvpkt)
Wait for ACK or
NAK
Wait for call from
below
rdt_send(data)
Λ
Transport Layer 3-21
rdt20 error scenario
Wait for call from above
snkpkt = make_pkt(data checksum)udt_send(sndpkt)
extract(rcvpktdata)deliver_data(data)udt_send(ACK)
rdt_rcv(rcvpkt) ampamp notcorrupt(rcvpkt)
rdt_rcv(rcvpkt) ampamp isACK(rcvpkt)
udt_send(sndpkt)
rdt_rcv(rcvpkt) ampampisNAK(rcvpkt)
udt_send(NAK)
rdt_rcv(rcvpkt) ampamp corrupt(rcvpkt)
Wait for ACK or
NAK
Wait for call from
below
rdt_send(data)
Λ
Transport Layer 3-22
rdt20 has a fatal flaw
What happens if ACKNAK corruptedsender doesnrsquot know what happened at receivercanrsquot just retransmit possible duplicate
What to dosender ACKsNAKs receiverrsquos ACKNAK What if sender ACKNAK lostretransmit but this might cause retransmission of correctly received pkt
Handling duplicates sender adds sequence number to each pktsender retransmits current pkt if ACKNAK garbledreceiver discards (doesnrsquot deliver up) duplicate pkt
Sender sends one packet then waits for receiver response
stop and wait
Transport Layer 3-23
rdt21 sender handles garbled ACKNAKs
Wait for call 0 from
above
sndpkt = make_pkt(0 data checksum)udt_send(sndpkt)
rdt_send(data)
Wait for ACK or NAK 0 udt_send(sndpkt)
rdt_rcv(rcvpkt) ampamp ( corrupt(rcvpkt) ||isNAK(rcvpkt) )
sndpkt = make_pkt(1 data checksum)udt_send(sndpkt)
rdt_send(data)
rdt_rcv(rcvpkt) ampamp notcorrupt(rcvpkt) ampamp isACK(rcvpkt)
udt_send(sndpkt)
rdt_rcv(rcvpkt) ampamp ( corrupt(rcvpkt) ||isNAK(rcvpkt) )
rdt_rcv(rcvpkt) ampamp notcorrupt(rcvpkt) ampamp isACK(rcvpkt)
Wait forcall 1 from
above
Wait for ACK or NAK 1
ΛΛ
Transport Layer 3-24
rdt21 receiver handles garbled ACKNAKs
Wait for 0 from below
sndpkt = make_pkt(NAK chksum)udt_send(sndpkt)
rdt_rcv(rcvpkt) ampamp not corrupt(rcvpkt) ampamphas_seq0(rcvpkt)
rdt_rcv(rcvpkt) ampamp notcorrupt(rcvpkt) ampamp has_seq1(rcvpkt)
extract(rcvpktdata)deliver_data(data)sndpkt = make_pkt(ACK chksum)udt_send(sndpkt)
Wait for 1 from below
rdt_rcv(rcvpkt) ampamp notcorrupt(rcvpkt) ampamp has_seq0(rcvpkt)
extract(rcvpktdata)deliver_data(data)sndpkt = make_pkt(ACK chksum)udt_send(sndpkt)
rdt_rcv(rcvpkt) ampamp (corrupt(rcvpkt)
sndpkt = make_pkt(ACK chksum)udt_send(sndpkt)
rdt_rcv(rcvpkt) ampamp not corrupt(rcvpkt) ampamphas_seq1(rcvpkt)
rdt_rcv(rcvpkt) ampamp (corrupt(rcvpkt)
sndpkt = make_pkt(ACK chksum)udt_send(sndpkt)
sndpkt = make_pkt(NAK chksum)udt_send(sndpkt)
Transport Layer 3-25
rdt21 discussion
Senderseq added to pkttwo seq rsquos (01) will suffice Whymust check if received ACKNAK corrupted twice as many states
state must ldquorememberrdquowhether ldquocurrentrdquo pkt has 0 or 1 seq
Receivermust check if received packet is duplicate
state indicates whether 0 or 1 is expected pkt seq
note receiver can notknow if its last ACKNAK received OK at sender
Transport Layer 3-26
rdt22 a NAK-free protocol
same functionality as rdt21 using ACKs onlyinstead of NAK receiver sends ACK for last pkt received OK
receiver must explicitly include seq of pkt being ACKed duplicate ACK at sender results in same action as NAK retransmit current pkt
Transport Layer 3-27
rdt22 sender receiver fragments
Wait for call 0 from
above
sndpkt = make_pkt(0 data checksum)udt_send(sndpkt)
rdt_send(data)
udt_send(sndpkt)
rdt_rcv(rcvpkt) ampamp ( corrupt(rcvpkt) ||
isACK(rcvpkt1) )
rdt_rcv(rcvpkt) ampamp notcorrupt(rcvpkt) ampamp isACK(rcvpkt0)
Wait for ACK
0sender FSM
fragment
Wait for 0 from below
rdt_rcv(rcvpkt) ampamp notcorrupt(rcvpkt) ampamp has_seq1(rcvpkt)
extract(rcvpktdata)deliver_data(data)sndpkt = make_pkt(ACK1 chksum)udt_send(sndpkt)
rdt_rcv(rcvpkt) ampamp (corrupt(rcvpkt) ||
has_seq1(rcvpkt))
udt_send(sndpkt)receiver FSM
fragment
Λ
Transport Layer 3-28
rdt30 channels with errors and loss
New assumptionunderlying channel can also lose packets (data or ACKs)
checksum seq ACKs retransmissions will be of help but not enough
Q how to deal with losssender waits until certain data or ACK lost then retransmitsdrawbacks
Approach sender waits ldquoreasonablerdquo amount of time for ACK retransmits if no ACK received in this timeif pkt (or ACK) just delayed (not lost)
retransmission will be duplicate but use of seq rsquos already handles thisreceiver must specify seq of pkt being ACKed
requires countdown timer
Transport Layer 3-29
rdt30 sendersndpkt = make_pkt(0 data checksum)udt_send(sndpkt)start_timer
rdt_send(data)
Wait for
ACK0
rdt_rcv(rcvpkt) ampamp ( corrupt(rcvpkt) ||isACK(rcvpkt1) )
Wait for call 1 from
above
sndpkt = make_pkt(1 data checksum)udt_send(sndpkt)start_timer
rdt_send(data)
rdt_rcv(rcvpkt) ampamp notcorrupt(rcvpkt) ampamp isACK(rcvpkt0)
rdt_rcv(rcvpkt) ampamp ( corrupt(rcvpkt) ||isACK(rcvpkt0) )
rdt_rcv(rcvpkt) ampamp notcorrupt(rcvpkt) ampamp isACK(rcvpkt1)
stop_timerstop_timer
udt_send(sndpkt)start_timer
timeout
udt_send(sndpkt)start_timer
timeout
rdt_rcv(rcvpkt)
Wait for call 0from
above
Wait for
ACK1
Λrdt_rcv(rcvpkt)
ΛΛ
Λ
Transport Layer 3-30
rdt30 in action
Transport Layer 3-31
rdt30 in action
Transport Layer 3-32
Performance of rdt30
rdt30 works but performance stinksexample 1 Gbps link 15 ms e-e prop delay 1KB packet
Ttransmit = 8kbpkt109 bsec = 8 microsec
U sender utilization ndash fraction of time sender busy sending1KB pkt every 30 msec -gt 33kBsec thruput over 1 Gbps linknetwork protocol limits use of physical resources
U sender=
008 30008
= 000027 L RRTT + L R
=
L (packet length in bits)R (transmission rate bps) =
Transport Layer 3-33
rdt30 stop-and-wait operation
first packet bit transmitted t = 0
sender receiver
RTT
last packet bit transmitted t = L R
first packet bit arriveslast packet bit arrives send ACK
ACK arrives send next packet t = RTT + L R
U sender=
00830008
= 000027 L RRTT + L R
=
Transport Layer 3-34
Pipelined protocolsPipelining sender allows multiple ldquoin-flightrdquo yet-to-
be-acknowledged pktsrange of sequence numbers must be increasedbuffering at sender andor receiver
Two generic forms of pipelined protocols go-Back-N selective repeat
Transport Layer 3-35
Pipelining increased utilization
first packet bit transmitted t = 0
sender receiver
RTT
last bit transmitted t = L R
first packet bit arriveslast packet bit arrives send ACK
ACK arrives send next packet t = RTT + L R
last bit of 2nd packet arrives send ACKlast bit of 3rd packet arrives send ACK
U sender=
024 30008
= 000083 L RRTT + L R
=
Increase utilizationby a factor of 3
Transport Layer 3-36
Utilization=N(LR)(RTT+LR) if NLRltRTT+LR Utilization=1 if and the sender pauses after it transmits a window NLRgtRTT+LR and the of packets until it receives first ACK sender does not pause
Transport Layer 3-37
Go-Back-NSender
k-bit seq in pkt headerldquowindowrdquo of up to N consecutive unackrsquoed pkts allowed
ACK(n) ACKs all pkts up to including seq n - ldquocumulative ACKrdquomay receive duplicate ACKs (see receiver)
timer for the entire windowtimeout(n) retransmit pkt n and all higher seq pkts in window
Transport Layer 3-38
GBN sender extended FSM
Wait start_timerudt_send(sndpkt[base])udt_send(sndpkt[base+1])hellipudt_send(sndpkt[nextseqnum-1])
timeout
rdt_send(data)
if (nextseqnum lt base+N) sndpkt[nextseqnum] = make_pkt(nextseqnumdatachksum)udt_send(sndpkt[nextseqnum])if (base == nextseqnum)
start_timernextseqnum++
elserefuse_data(data)
base = getacknum(rcvpkt)+1If (base == nextseqnum)
stop_timerelse
start_timer
rdt_rcv(rcvpkt) ampamp notcorrupt(rcvpkt)
base=1nextseqnum=1
rdt_rcv(rcvpkt) ampamp corrupt(rcvpkt)
Λ
Λ
Transport Layer 3-39
GBN receiver extended FSM
ACK-only always send ACK for correctly-received pktwith highest in-order seq
may generate duplicate ACKsneed only remember expectedseqnum
out-of-order pkt discard (donrsquot buffer) -gt no receiver bufferingRe-ACK pkt with highest in-order seq
Wait
udt_send(sndpkt)default
rdt_rcv(rcvpkt)ampamp notcurrupt(rcvpkt)ampamp hasseqnum(rcvpktexpectedseqnum)
extract(rcvpktdata)deliver_data(data)sndpkt = make_pkt(expectedseqnumACKchksum)udt_send(sndpkt)expectedseqnum++
expectedseqnum=1sndpkt =
make_pkt(0ACKchksum)
Λ
Transport Layer 3-40
GBN inaction
Transport Layer 3-41
Selective Repeat
receiver individually acknowledges all correctly received pkts
buffers pkts as needed for eventual in-order delivery to upper layer
sender only resends pkts for which ACK not received
sender timer for each unACKed pktsender window
N consecutive seq rsquosagain limits seq s of sent unACKed pkts
Transport Layer 3-42
Selective repeat sender receiver windows
Transport Layer 3-43
Selective repeat
data from above if next available seq in window send pkt
timeout(n)resend pkt n restart timer
ACK(n) in [sendbasesendbase+N-1]
mark pkt n as receivedif n smallest unACKed pkt advance window base to next unACKed seq
senderpkt n in [rcvbase rcvbase+N-1]
send ACK(n)out-of-order bufferin-order deliver (also deliver buffered in-order pkts) advance window to next not-yet-received pkt
pkt n in [rcvbase-Nrcvbase-1]
ACK(n)otherwise
ignore
receiver
Transport Layer 3-44
Selective repeat in action
Transport Layer 3-45
Selective repeatdilemma
Example seq rsquos 0 1 2 3window size=3
receiver sees no difference in two scenariosincorrectly passes duplicate data as new in (a)
Q what relationship between seq size and window size
Transport Layer 3-46
Sequence Number vs Window SizeSuppose we use k bits to represent SNQuestion Whatrsquos the minimum number of bits k necessary for a window size of N
sender
receiver
Go-Back-N
expectedSN
snd_base=expectedSN
Q For a given expectedSN whatrsquos the largest possible value for snd_baseA If all the last N ACKs sent by the receiver are received
snd_base = expectedSNexpectedSN+N-1
senderrsquos window
Transport Layer 3-47
Sequence Number vs Window SizeSuppose we use k bits to represent SNQuestion Whatrsquos the minimum number of bits k necessary for a window size of N
sender
receiver
Go-Back-N
expectedSN
snd_base=expectedSN-N
Q For a given expectedSN whatrsquos the smallest possible value for snd_baseA If all the last N ACKs sent by the receiver are not received
snd_base = expectedSN-NexpectedSN-1
senderrsquos window
Transport Layer 3-48
Sequence Number vs Window Size
sender
receiver
Go-Back-N
expectedSN
snd_base=expectedSN-N
All SNs in the interval [expectedSN-NexpectedSN+N-1] (an interval of size 2N) can be received by the receiver Since the receiver accepts on the packet with SN=expectedSN there should be no other packet within this interval with SN=expectedSN Therefore
2k ge N+1expectedSN+N-1
Transport Layer 3-49
Sequence Number vs Window SizeSuppose we use k bits to represent SNQuestion Whatrsquos the minimum number of bits k necessary for a window size of N
sender
receiver
Selective Repeat
rcv_base
snd_base=rcv_base
Q For a given rcv_base whatrsquos the largest possible value for snd_baseA If all the last N ACKs sent by the receiver are received
snd_base = rcv_base (same as go_back-N)rcv_base+N-1
senderrsquos window
receiverrsquos window
rcv_base+N-1
Transport Layer 3-50
Sequence Number vs Window SizeSuppose we use k bits to represent SNQuestion Whatrsquos the minimum number of bits k necessary for a window size of N
sender
receiver
Selective Repeat
rcv_base
snd_base=rcv_base-N
Q For a given rcv_base whatrsquos the smallest possible value for snd_baseA If all the last N ACKs sent by the receiver are not received
snd_base = rcv_base-N (same as Go-Back-N)rcv_base-1
senderrsquos window
rcv_base
receiverrsquos window
rcv_base+N-1
Transport Layer 3-51
Sequence Number vs Window Size
sender
receiver
Selective Repeat
snd_base=rcv_base-N
All SNs in the interval [rcv_base-Nrcv_base+N-1] (an interval of size 2N) can be received by the receiver Since the receiver should be able to distinguish between all packets in this interval and take corresponding action there should be no two packets within thisinterval having the same SN Therefore
2k ge 2Nrcv_base+N-1
rcv_basercv_base
receiverrsquos window
rcv_base+N-1
Transport Layer 3-52
TCP Overview RFCs 793 1122 1323 2018 2581
full duplex databi-directional data flow in same connectionMSS maximum segment size
connection-orientedhandshaking (exchange of control msgs) initrsquossender receiver state before data exchange
flow controlledsender will not overwhelm receiver
point-to-pointone sender one receiver
reliable in-order byte stream
no ldquomessage boundariesrdquopipelined
TCP congestion and flow control set window size
send amp receive buffers
socketdoor
TCPsend buffer
TCPreceive buffer
socketdoor
segment
applicationwrites data
applicationreads data
Transport Layer 3-53
TCP segment structure
source port dest port
32 bits
applicationdata
(variable length)
sequence numberacknowledgement number
Receive windowUrg data pnterchecksum
FSRPAUheadlen
notused
Options (variable length)
URG urgent data (generally not used)
ACK ACK valid
PSH push data now(generally not used)
RST SYN FINconnection estab(setup teardown
commands)
bytes rcvr willingto accept
Internetchecksum
(as in UDP)
countingby bytes of data(not segments)
Transport Layer 3-54
TCP seq rsquos and ACKsSeq rsquos
byte stream ldquonumberrdquo of first byte in segmentrsquos dataACKs
seq of next byte expected from other sidecumulative ACK
Q how receiver handles out-of-order segmentsA TCP spec doesnrsquot say - up to implementationWidely used implementations of TCP buffer out-of-order segments
Transport Layer 3-55
TCP Round Trip Time and Timeout
Q how to set TCP timeout valuelonger than RTT
but RTT variestoo short premature timeout
unnecessary retransmissions
too long slow reaction to segment loss
Q how to estimate RTTSampleRTT measured time from segment transmission until ACK receipt
ignore retransmissionsSampleRTT will vary want estimated RTT ldquosmootherrdquo
average several recent measurements not just current SampleRTT
Transport Layer 3-56
TCP Round Trip Time and Timeout
EstimatedRTT = (1- α)EstimatedRTT + αSampleRTT
Exponential weighted moving averageinfluence of past sample decreases exponentially fasttypical value α = 0125
Transport Layer 3-57
Example RTT estimationRTT gaiacsumassedu to fantasiaeurecomfr
100
150
200
250
300
350
1 8 15 22 29 36 43 50 57 64 71 78 85 92 99 106
time (seconnds)
RTT
(mill
iseco
nds)
SampleRTT Estimated RTT
Transport Layer 3-58
TCP Round Trip Time and TimeoutSetting the timeout
EstimatedRTT plus ldquosafety marginrdquolarge variation in EstimatedRTT -gt larger safety margin
first estimate of how much SampleRTT deviates from EstimatedRTT
TimeoutInterval = EstimatedRTT + 4DevRTT
DevRTT = (1-β)DevRTT +β|SampleRTT-EstimatedRTT|
(typically β = 025)
Then set timeout interval
Transport Layer 3-59
TCP reliable data transfer
TCP creates rdtservice on top of IPrsquos unreliable servicePipelined segmentsCumulative acksTCP uses single retransmission timer however it just retransmits the first segment in the window
Retransmissions are triggered by
timeout eventsduplicate acks
Initially consider simplified TCP sender
ignore duplicate acksignore flow control congestion control
Transport Layer 3-60
TCP sender eventsdata rcvd from app
Create segment with seq seq is byte-stream number of first data byte in segmentstart timer if not already running (think of timer as for oldest unacked segment)expiration interval TimeOutInterval
timeoutretransmit segment that caused timeout (first segment in the window)restart timer
Ack rcvdIf acknowledges previously unacked segments
update what is known to be ackedstart timer if there are outstanding segments
Transport Layer 3-61
TCP sender(simplified)
NextSeqNum = InitialSeqNumSendBase = InitialSeqNum
loop (forever) switch(event)
event data received from application above create TCP segment with sequence number NextSeqNumif (timer currently not running)
start timerpass segment to IP NextSeqNum = NextSeqNum + length(data)
event timer timeoutretransmit not-yet-acknowledged segment with
smallest sequence numberstart timer
event ACK received with ACK field value of y if (y gt SendBase)
SendBase = yif (there are currently not-yet-acknowledged segments)
start timer
end of loop forever
Commentbull SendBase-1 last cumulatively ackrsquoed byteExamplebull SendBase-1 = 71y= 73 so the rcvrwants 73+ y gt SendBase sothat new data is acked
Transport Layer 3-62
TCP retransmission scenariosHost A
Seq=100 20 bytes data
ACK=100
timepremature timeout
Host B
Seq=92 8 bytes data
ACK=120
Seq=92 8 bytes data
Seq=
92 t
imeo
ut
ACK=120
Host A
Seq=92 8 bytes data
ACK=100
loss
tim
eout
lost ACK scenario
Host B
X
Seq=92 8 bytes data
ACK=100
time
Seq=
92 t
imeo
utSendBase
= 100
SendBase= 120
SendBase= 120
Sendbase= 100
Transport Layer 3-63
TCP retransmission scenarios (more)Host A
Seq=92 8 bytes data
ACK=100
loss
tim
eout
Cumulative ACK scenario
Host B
X
Seq=100 20 bytes data
ACK=120
time
SendBase= 120
Transport Layer 3-64
TCP ACK generation [RFC 1122 RFC 2581]
Event at Receiver
Arrival of in-order segment withexpected seq All data up toexpected seq already ACKed
Arrival of in-order segment withexpected seq One other segment has ACK pending
Arrival of out-of-order segmenthigher-than-expect seq Gap detected
Arrival of segment that partially or completely fills gap
TCP Receiver action
Delayed ACK Wait up to 500msfor next segment If no next segmentsend ACK
Immediately send single cumulative ACK ACKing both in-order segments
Immediately send duplicate ACK indicating seq of next expected byte
Immediate send ACK provided thatsegment startsat lower end of gap
Transport Layer 3-65
Fast Retransmit
Time-out period often relatively long
long delay before resending lost packet
Detect lost segments via duplicate ACKs
Sender often sends many segments back-to-backIf segment is lost there will likely be many duplicate ACKs
If sender receives 3 ACKs for the same data it supposes that segment after ACKeddata was lost
fast retransmit resend segment before timer expires
Transport Layer 3-66
Fast RetransmitResend a segment after 3 duplicate ACKs since a duplicate ACK means that an out-of sequence segment was receivedduplicate ACKs due to packet reorderingif window is small donrsquot get duplicate ACKs
Host A
tim
eout
Host B
time
X
resend seq X2
seq x1seq x2seq x3seq x4seq x5
ACK x1
ACK x1ACK x1ACK x1
tripleduplicate
ACKs
Transport Layer 3-67
event ACK received with ACK field value of y if (y gt SendBase)
SendBase = yif (there are currently not-yet-acknowledged segments)
start timer
else increment count of dup ACKs received for yif (count of dup ACKs received for y = 3)
resend segment with sequence number y
Fast retransmit algorithm
a duplicate ACK for already ACKed segment
fast retransmit
Transport Layer 3-68
TCP Flow Control
receive side of TCP connection has a receive buffer
speed-matching service matching the send rate to the receiving apprsquos drain rate
app process may be slow at reading from buffer
sender wonrsquot overflowreceiverrsquos buffer by
transmitting too muchtoo fast
flow control
Transport Layer 3-69
TCP Flow control how it works
(Suppose TCP receiver discards out-of-order segments)spare room in buffer
= RcvWin
= RcvBuffer-[LastByteRcvd -LastByteRead]
Rcvr advertises spare room by including value of RcvWin in segmentsSender limits unACKeddata to RcvWin
guarantees receive buffer doesnrsquot overflow
Transport Layer 3-70
Sliding Window Flow Control Example
3K
2K SeqNo=0
ReceiverBuffer
0 4KSendersends 2Kof data
2K
AckNo=2048 RcvWin=2048Sendersends 2Kof data 2K SeqNo=2048
4K
AckNo=4096 RcvWin=0
AckNo=4096 RcvWin=1024
Sender blocked
Transport Layer 3-71
Principles of Congestion Control
Congestioninformally ldquotoo many sources sending too much data too fast for network to handlerdquodifferent from flow controlmanifestations
lost packets (buffer overflow at routers)long delays (queueing in router buffers)
a top-10 problem
Transport Layer 3-72
Causescosts of congestion scenario 1
two senders two receiversone router infinite buffers no retransmission
large delays when congestedmaximum achievable throughput
unlimited shared output link buffers
Host Aλin original data
Host B
λout
Transport Layer 3-73
Causescosts of congestion scenario 2
one router finite buffers sender retransmission of lost packet
finite shared output link buffers
Host A λin original data
Host B
λout
λin original data plus retransmitted data
Transport Layer 3-74
Causescosts of congestion scenario 2always (goodput)ldquoperfectrdquo retransmission only when loss
retransmission of delayed (not lost) packet makes larger(than perfect case) for same
λin
λout=
λin
λoutgtλ
inλout
ldquocostsrdquo of congestionmore work (retrans) for given ldquogoodputrdquounneeded retransmissions link carries multiple copies of pkt
R2
R2λin
λ out
b
R2
R2λin
λ out
a
R2
R2λin
λ out
c
R4
R3
Transport Layer 3-75
Causescosts of congestion scenario 3four sendersmultihop pathstimeoutretransmit
λin
Q what happens as and increase λ
in
finite shared output link buffers
Host Aλin original data
Host B
λout
λin original data plus retransmitted data
Transport Layer 3-76
Causescosts of congestion scenario 3
another ldquocostrdquo of congestionwhen packet dropped any ldquoupstream transmission capacity used for that packet was wasted
Host A
Host B
λou
t
Transport Layer 3-77
Approaches towards congestion control
End-end congestion controlno explicit feedback from networkcongestion inferred from end-system observed loss delayapproach taken by TCP
Network-assisted congestion controlrouters provide feedback to end systems
single bit indicating congestion (SNA DECbit TCPIP ECN ATM)explicit rate sender should send at
Two broad approaches towards congestion control
Transport Layer 3-78
TCP Congestion Control
end-end control (no network assistance)sender limits transmissionLastByteSent-LastByteAcked
le CongWin
CongWin is dynamic function of perceived network congestion
How does sender perceive congestionloss event = timeout or3 duplicate acksTCP sender reduces rate (CongWin) after loss event
two modes of operationSlow Start (SS)Congestion avoidance (CA) or Additive Increase Multiplicative Decrease (AIMD)
Transport Layer 3-79
TCP congestion control bandwidth probing
ldquoprobing for bandwidthrdquo increase transmission rate on receipt of ACK until eventually loss occurs then decrease transmission rate
continue to increase on ACK decrease on loss (since available bandwidth is changing depending on other connections in network)
ACKs being received so increase rate
X
X
XX
X loss so decrease rate
send
ing
rate
time
Q how fast to increasedecreasedetails to follow
TCPrsquosldquosawtoothrdquobehavior
Transport Layer 3-80
TCP Congestion Control details
sender limits rate by limiting number of unACKed bytes ldquoin pipelinerdquo
cwnd differs from rwnd (how why)sender limited by min(cwndrwnd)
roughly
cwnd is dynamic function of perceived network congestion
rate = cwndRTT bytessec
LastByteSent-LastByteAcked le cwnd
cwndbytes
RTT
ACK(s)
Transport Layer 3-81
TCP Congestion Control more details
segment loss event reducing cwndtimeout no response from receiver
cut cwnd to 13 duplicate ACKs at least some segments getting through (recall fast retransmit)
cut cwnd in half less aggressively than on timeout
ACK received increase cwndTwo modes of operation
slowstart phase bull increase exponentially
fast (despite name) at connection start or following timeout
congestion avoidance bull increase linearly
Transport Layer 3-82
TCP Slow Start Phasewhen connection begins cwnd = 1 MSS
example MSS = 500 bytes amp RTT = 200 msecinitial rate = 20 kbps
available bandwidth may be gtgt MSSRTT
desirable to quickly ramp up to respectable rate
increase rate exponentially until first loss event or when threshold reached
double cwnd every RTTdone by incrementing cwnd by 1 for every ACK received
Host A
one segment
RTT
Host B
time
two segments
four segments
Transport Layer 3-83
Slow Start ExampleThe congestion window size grows very rapidly
For every ACK we increase CongWin by 1 irrespective of the number of segments ACKrsquoeddouble CongWinevery RTTinitial rate is slow but ramps up exponentially fast
TCP slows down the increase of CongWinwhen CongWin gt ssthresh
segment 1
ACK for segment 1
cwnd = 1
cwnd = 2 segment 2segment 3
ACK for segments 2
cwnd = 4 segment 4segment 5segment 6
ACK for segments 4
cwnd = 7
ACK for segments 3
ACK for segments 5
ACK for segments 6
cwnd = 3
cwnd = 5
cwnd = 6ACK for segments 7
cwnd = 8
segment 7
Transport Layer 3-84
TCP Congestion Avoidance Phase
when cwnd gt ssthreshgrow cwnd linearly
increase cwnd by 1 MSS per RTT approach possible congestion slower than in slowstartimplementation cwnd= cwnd + MSScwndfor each ACK received
ACKs increase cwndby 1 MSS per RTT additive increaseloss cut cwnd in half (non-timeout-detected loss ) multiplicative decrease
AIMD
AIMD Additive IncreaseMultiplicative Decrease
Transport Layer 3-85
Congestion AvoidanceCongestion avoidance phase is started if CongWin has reached the slow-start threshold value
If CongWin gt= ssthresh then each time an ACK is received increment CongWin as follows
bull CongWin = CongWin + 1CongWin (CongWin in segments)
bull In actual TCP implementation CongWin is in BytesCongWin = CongWin + MSS (MSSCongWin)
So CongWin is increased by one only if all CongWinsegments have been acknowledged
Transport Layer 3-86
Example Slow StartCongestion AvoidanceAssume that
ssthresh = 8
cwnd = 1
cwnd = 2
cwnd = 4
cwnd = 8
cwnd = 9
cwnd = 10
02468
101214
t=0
t=2
t=4
t=6
Roundtrip times
Cw
nd(in
seg
men
ts)
ssthresh
cwnd = 3
cwnd = 5cwnd = 6cwnd = 7
Transport Layer 3-87
Slow Start Congestion AvoidanceA typical plot of CongWin for a TCP connection
(MSS = 1500 bytes) with TCP Tahoe
SS
CA
ssthresh
Transport Layer 3-88
Responses to CongestionTCP assumes there is congestion if it detects a packet lossA TCP sender can detect lost packets via loss events
bull Timeout of a retransmission timerbull Receipt of 3 duplicate ACKs (fast retransmit)
TCP interprets a Timeout as a binary congestion signal When a timeout occurs the sender performs
ssthresh is set to half the current size of the congestion window
ssthresh = CongWin 2CongWin is reset to one
CongWin = 1and slow-start is entered
Transport Layer 3-89
Fast Recovery (differentiation btwn two loss events) After 3 dup ACKs (fast Retransmit)
ssthresh = CongWin2CongWin = CongWin2window then grows linearly
But after timeout eventCongWin = 1 MSS window then grows exponentiallyto the threshold then grows linearly
bull 3 dup ACKs indicates network capable of delivering some segmentsbull timeout before 3 dup ACKs is ldquomore alarmingrdquo
Philosophy
3-90
TCP Congestion ControlInitially
CongWin = 1ssthresh = advertised window size
New Ack receivedif (CongWin lt ssthresh) Slow Start
CongWin = CongWin + 1else Congestion Avoidance
CongWin = CongWin + 1CongWinTimeout
ssthresh = CongWin2CongWin = 1
Fast Retransmissionssthresh = CongWin2CongWin = CongWin2
Slow Start (exponential increase phase) is continued until CongWin reaches half of the level where the loss event occurred last time CongWin is increased slowly after (linear increase in Congestion Avoidance phase)
Transport Layer 3-91
Popular ldquoflavorsrdquo of TCP
ssthresh
ssthresh
TCP Tahoe
TCP Reno
Transmission round
cwnd
win
dow
siz
e (in
seg
men
ts)
Transport Layer 3-92
Summary TCP Congestion ControlWhen CongWin is below Threshold sender in slow-start phase window grows exponentiallyWhen CongWin is above Threshold sender is in congestion-avoidance phase window grows linearlyWhen a triple duplicate ACK occurs Threshold set to CongWin2 and CongWin set to ThresholdWhen timeout occurs Threshold set to CongWin2 and CongWin is set to 1 MSS The actual sender window size is determined based on the congestion and flow control algorithms
SenderWin=min(RcvWinCongWin)
Transport Layer 3-93
TCP Congestion Control SummaryEvent State TCP Sender Action Commentary
ACK receipt for previously unackeddata
Slow Start (SS)
CongWin = CongWin + MSS If (CongWin gt Threshold)
set state to ldquoCongestion Avoidancerdquo
Resulting in a doubling of CongWin every RTT
ACK receipt for previously unackeddata
CongestionAvoidance (CA)
CongWin = CongWin+MSS (MSSCongWin)
Additive increase resulting in increase of CongWin by 1 MSS every RTT
Loss event detected by triple duplicate ACK
SS or CA Threshold = CongWin2 CongWin = ThresholdSet state to ldquoCongestion Avoidancerdquo
Fast recovery implementing multiplicative decrease CongWin will not drop below 1 MSS
Timeout SS or CA Threshold = CongWin2 CongWin = 1 MSSSet state to ldquoSlow Startrdquo
Enter slow start
Duplicate ACK
SS or CA Increment duplicate ACK count for segment being acked
CongWin and Threshold not changed
Transport Layer 3-94
TCP throughput
Q whatrsquos average throughout of TCP as function of window size RTT
ignoring slow startlet W be window size when loss occurs
when window is W throughput is WRTTjust after loss window drops to W2 throughput to W2RTT average throughout 75 WRTT
Transport Layer 3-95
TCP Futures TCP over ldquolong fat pipesrdquo
example 1500 byte segments 100ms RTT want 10 Gbps throughputrequires window size W = 83333 in-flight segmentsthroughput in terms of loss rate
L = 210-10 Wownew versions of TCP for high-speed
LRTTMSSsdot221
Transport Layer 3-96
Fairness goal if K TCP sessions share same bottleneck link of bandwidth R each should have average rate of RK
TCP connection 1
bottleneckrouter
capacity R
TCP connection 2
TCP Fairness
Transport Layer 3-97
Why is TCP fairTwo competing sessions
Additive increase gives slope of 1 as throughout increasesmultiplicative decrease decreases throughput proportionally
R
R
equal bandwidth share
Connection 1 throughput
Conn
ecti
on 2
thr
ough
p ut
congestion avoidance additive increaseloss decrease window by factor of 2
congestion avoidance additive increaseloss decrease window by factor of 2
Transport Layer 3-98
Fairness (more)Fairness and UDP
Multimedia apps often do not use TCP
do not want rate throttled by congestion control
Instead use UDPpump audiovideo at constant rate tolerate packet loss
Research area TCP friendly
Fairness and parallel TCP connectionsnothing prevents app from opening parallel cnctionsbetween 2 hostsWeb browsers do this Example link of rate R supporting 9 cnctions
new app asks for 1 TCP gets rate R10new app asks for 11 TCPs gets R2
Transport Layer 3-99
TCP Connection ManagementRecall TCP sender receiver
establish ldquoconnectionrdquobefore exchanging data segmentsinitialize TCP variables
seq sbuffers flow control info (eg RcvWindow)
client connection initiatorSocket clientSocket = new Socket(hostnameport
number)
server contacted by clientSocket connectionSocket = welcomeSocketaccept()
Three way handshakeStep 1 client host sends TCP
SYN segment to serverspecifies initial seq no data
Step 2 server host receives SYN replies with SYNACK segment
server allocates buffersspecifies server initial seq
Step 3 client receives SYNACK replies with ACK segment which may contain data
Transport Layer 3-100
TCP Connection Management (cont)
Closing a connection
client closes socketclientSocketclose()
Step 1 client end system sends TCP FIN control segment to server
Step 2 server receives FIN replies with ACK Closes connection sends FIN
client
FIN
server
ACK
ACK
FIN
close
close
closed
tim
ed w
ait
Transport Layer 3-101
TCP Connection Management (cont)
Step 3 client receives FIN replies with ACK
Enters ldquotimed waitrdquo -will respond with ACK to received FINs
Step 4 server receives ACK Connection closed
client
FIN
server
ACK
ACK
FIN
closing
closing
closed
tim
ed w
ait
closed
Transport Layer 3-102
TCP Connection Management (cont)
TCP clientlifecycle
TCP serverlifecycle
Transport Layer 3-103
Tuning TCPIP Parameters TCPIP parameters
A set of default values may not be optimal for all applicationsThe network administrator may wish to turn on or off some TCPIP functions for performance or security considerations
Many Unix and Linux systems provide some flexibility in tuning the TCPIP kernelsbinsysctl is used to configure the Linux kernel parameters at runtime
Default kernel configuration file is sbinsysctlconfFrequently used sysctl options
bull sysctl ndasha or sysctl ndashA list all current valuesbull sysctl ndashp file_name load the sysctl setting from a configuration
filebull sysctl ndashw variable=value change the value of the parameter
Transport Layer 3-104
SomeTCP Parameters in Linux Kerneltcp_syn_retries
Number of SYN packets the kernel will send before giving up on the new connection
tcp_synack_retriesnumber of SYN+ACK packets sent before the kernel gives up on the connection
tcp_window_scalingMaximum window size of 65535 bytes not enough for for really fast networks The window scaling options allows for almost gigabyte windows which is good for connections with large delay-bandwidth product
tcp_max_syn_backlogMaximal number of remembered connection requests which still did not receive an acknowledgment from connecting client
tcp_fin_timeoutHow many seconds to wait for a final FIN packet before the socket is closed required to prevent denial-of-service (DoS) attacks Default value is 60 seconds
Transport Layer 3-105
SomeTCP Parameters in Linux Kerneltcp_rmem
This is a vector of 3 integers [min default max] These parameters are used by TCP to dynamically adjust receive buffer sizesmin - minimum size of the receive buffer used by each TCP socket The default value is 4K default - the default size of the receive buffer for a TCP socket The default value is 87380 bytes and is lowered to 43689 in low memory systems If larger receive buffer sizes are desired this value should be increased max - the maximum size of the receive buffer used by each TCP socket The default value of 873802 bytes is lowered to 87380 in low memory systems
tcp_smemSend buffer parameters [min default max] similar to tcp_rmem
- Chapter 3 Transport Layer
- Transport services and protocols
- Transport vs network layer
- Internet transport-layer protocols
- Multiplexingdemultiplexing
- How demultiplexing works
- Connectionless demultiplexing
- Connection-oriented demux
- Connection-oriented demux (cont)
- Connection-oriented demux Threaded Web Server
- UDP User Datagram Protocol [RFC 768]
- UDP more
- UDP checksum
- Principles of Reliable data transfer
- Reliable data transfer getting started
- Reliable data transfer getting started
- Rdt10 reliable transfer over a reliable channel
- Rdt20 channel with bit errors
- rdt20 FSM specification
- rdt20 operation with no errors
- rdt20 error scenario
- rdt20 has a fatal flaw
- rdt21 sender handles garbled ACKNAKs
- rdt21 receiver handles garbled ACKNAKs
- rdt21 discussion
- rdt22 a NAK-free protocol
- rdt22 sender receiver fragments
- rdt30 channels with errors and loss
- rdt30 sender
- rdt30 in action
- rdt30 in action
- Performance of rdt30
- rdt30 stop-and-wait operation
- Pipelined protocols
- Pipelining increased utilization
- Go-Back-N
- GBN sender extended FSM
- GBN receiver extended FSM
- GBN inaction
- Selective Repeat
- Selective repeat sender receiver windows
- Selective repeat
- Selective repeat in action
- Selective repeat dilemma
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- TCP Overview RFCs 793 1122 1323 2018 2581
- TCP segment structure
- TCP seq rsquos and ACKs
- TCP Round Trip Time and Timeout
- TCP Round Trip Time and Timeout
- Example RTT estimation
- TCP Round Trip Time and Timeout
- TCP reliable data transfer
- TCP sender events
- TCP sender(simplified)
- TCP retransmission scenarios
- TCP retransmission scenarios (more)
- TCP ACK generation [RFC 1122 RFC 2581]
- Fast Retransmit
- Fast Retransmit
- Fast retransmit algorithm
- TCP Flow Control
- TCP Flow control how it works
- Sliding Window Flow Control Example
- Principles of Congestion Control
- Causescosts of congestion scenario 1
- Causescosts of congestion scenario 2
- Causescosts of congestion scenario 2
- Causescosts of congestion scenario 3
- Causescosts of congestion scenario 3
- Approaches towards congestion control
- TCP Congestion Control
- TCP congestion control bandwidth probing
- TCP Congestion Control details
- TCP Congestion Control more details
- TCP Slow Start Phase
- Slow Start Example
- TCP Congestion Avoidance Phase
- Congestion Avoidance
- Example Slow StartCongestion Avoidance
- Slow Start Congestion Avoidance
- Responses to Congestion
- Fast Recovery (differentiation btwn two loss events)
- TCP Congestion Control
- Popular ldquoflavorsrdquo of TCP
- Summary TCP Congestion Control
- TCP Congestion Control Summary
- TCP throughput
- TCP Futures TCP over ldquolong fat pipesrdquo
- TCP Fairness
- Why is TCP fair
- Fairness (more)
- TCP Connection Management
- TCP Connection Management (cont)
- TCP Connection Management (cont)
- TCP Connection Management (cont)
- Tuning TCPIP Parameters
- SomeTCP Parameters in Linux Kernel
- SomeTCP Parameters in Linux Kernel
-
Transport Layer 3-18
Rdt20 channel with bit errors
underlying channel may flip bits in packetrecall checksum to detect bit errors
the question how to recover from errorsacknowledgements (ACKs) receiver explicitly tells sender that pkt received OKnegative acknowledgements (NAKs) receiver explicitly tells sender that pkt had errorssender retransmits pkt on receipt of NAK
new mechanisms in rdt20 (beyond rdt10)error detectionreceiver feedback control msgs (ACKNAK) rcvr-gtsender
Transport Layer 3-19
rdt20 FSM specification
Wait for call from above
snkpkt = make_pkt(data checksum)udt_send(sndpkt)
extract(rcvpktdata)deliver_data(data)udt_send(ACK)
rdt_rcv(rcvpkt) ampamp notcorrupt(rcvpkt)
rdt_rcv(rcvpkt) ampamp isACK(rcvpkt)
udt_send(sndpkt)
rdt_rcv(rcvpkt) ampampisNAK(rcvpkt)
udt_send(NAK)
rdt_rcv(rcvpkt) ampamp corrupt(rcvpkt)
Wait for ACK or
NAK
Wait for call from
belowsender
receiverrdt_send(data)
Λ
Transport Layer 3-20
rdt20 operation with no errors
Wait for call from above
snkpkt = make_pkt(data checksum)udt_send(sndpkt)
extract(rcvpktdata)deliver_data(data)udt_send(ACK)
rdt_rcv(rcvpkt) ampamp notcorrupt(rcvpkt)
rdt_rcv(rcvpkt) ampamp isACK(rcvpkt)
udt_send(sndpkt)
rdt_rcv(rcvpkt) ampampisNAK(rcvpkt)
udt_send(NAK)
rdt_rcv(rcvpkt) ampamp corrupt(rcvpkt)
Wait for ACK or
NAK
Wait for call from
below
rdt_send(data)
Λ
Transport Layer 3-21
rdt20 error scenario
Wait for call from above
snkpkt = make_pkt(data checksum)udt_send(sndpkt)
extract(rcvpktdata)deliver_data(data)udt_send(ACK)
rdt_rcv(rcvpkt) ampamp notcorrupt(rcvpkt)
rdt_rcv(rcvpkt) ampamp isACK(rcvpkt)
udt_send(sndpkt)
rdt_rcv(rcvpkt) ampampisNAK(rcvpkt)
udt_send(NAK)
rdt_rcv(rcvpkt) ampamp corrupt(rcvpkt)
Wait for ACK or
NAK
Wait for call from
below
rdt_send(data)
Λ
Transport Layer 3-22
rdt20 has a fatal flaw
What happens if ACKNAK corruptedsender doesnrsquot know what happened at receivercanrsquot just retransmit possible duplicate
What to dosender ACKsNAKs receiverrsquos ACKNAK What if sender ACKNAK lostretransmit but this might cause retransmission of correctly received pkt
Handling duplicates sender adds sequence number to each pktsender retransmits current pkt if ACKNAK garbledreceiver discards (doesnrsquot deliver up) duplicate pkt
Sender sends one packet then waits for receiver response
stop and wait
Transport Layer 3-23
rdt21 sender handles garbled ACKNAKs
Wait for call 0 from
above
sndpkt = make_pkt(0 data checksum)udt_send(sndpkt)
rdt_send(data)
Wait for ACK or NAK 0 udt_send(sndpkt)
rdt_rcv(rcvpkt) ampamp ( corrupt(rcvpkt) ||isNAK(rcvpkt) )
sndpkt = make_pkt(1 data checksum)udt_send(sndpkt)
rdt_send(data)
rdt_rcv(rcvpkt) ampamp notcorrupt(rcvpkt) ampamp isACK(rcvpkt)
udt_send(sndpkt)
rdt_rcv(rcvpkt) ampamp ( corrupt(rcvpkt) ||isNAK(rcvpkt) )
rdt_rcv(rcvpkt) ampamp notcorrupt(rcvpkt) ampamp isACK(rcvpkt)
Wait forcall 1 from
above
Wait for ACK or NAK 1
ΛΛ
Transport Layer 3-24
rdt21 receiver handles garbled ACKNAKs
Wait for 0 from below
sndpkt = make_pkt(NAK chksum)udt_send(sndpkt)
rdt_rcv(rcvpkt) ampamp not corrupt(rcvpkt) ampamphas_seq0(rcvpkt)
rdt_rcv(rcvpkt) ampamp notcorrupt(rcvpkt) ampamp has_seq1(rcvpkt)
extract(rcvpktdata)deliver_data(data)sndpkt = make_pkt(ACK chksum)udt_send(sndpkt)
Wait for 1 from below
rdt_rcv(rcvpkt) ampamp notcorrupt(rcvpkt) ampamp has_seq0(rcvpkt)
extract(rcvpktdata)deliver_data(data)sndpkt = make_pkt(ACK chksum)udt_send(sndpkt)
rdt_rcv(rcvpkt) ampamp (corrupt(rcvpkt)
sndpkt = make_pkt(ACK chksum)udt_send(sndpkt)
rdt_rcv(rcvpkt) ampamp not corrupt(rcvpkt) ampamphas_seq1(rcvpkt)
rdt_rcv(rcvpkt) ampamp (corrupt(rcvpkt)
sndpkt = make_pkt(ACK chksum)udt_send(sndpkt)
sndpkt = make_pkt(NAK chksum)udt_send(sndpkt)
Transport Layer 3-25
rdt21 discussion
Senderseq added to pkttwo seq rsquos (01) will suffice Whymust check if received ACKNAK corrupted twice as many states
state must ldquorememberrdquowhether ldquocurrentrdquo pkt has 0 or 1 seq
Receivermust check if received packet is duplicate
state indicates whether 0 or 1 is expected pkt seq
note receiver can notknow if its last ACKNAK received OK at sender
Transport Layer 3-26
rdt22 a NAK-free protocol
same functionality as rdt21 using ACKs onlyinstead of NAK receiver sends ACK for last pkt received OK
receiver must explicitly include seq of pkt being ACKed duplicate ACK at sender results in same action as NAK retransmit current pkt
Transport Layer 3-27
rdt22 sender receiver fragments
Wait for call 0 from
above
sndpkt = make_pkt(0 data checksum)udt_send(sndpkt)
rdt_send(data)
udt_send(sndpkt)
rdt_rcv(rcvpkt) ampamp ( corrupt(rcvpkt) ||
isACK(rcvpkt1) )
rdt_rcv(rcvpkt) ampamp notcorrupt(rcvpkt) ampamp isACK(rcvpkt0)
Wait for ACK
0sender FSM
fragment
Wait for 0 from below
rdt_rcv(rcvpkt) ampamp notcorrupt(rcvpkt) ampamp has_seq1(rcvpkt)
extract(rcvpktdata)deliver_data(data)sndpkt = make_pkt(ACK1 chksum)udt_send(sndpkt)
rdt_rcv(rcvpkt) ampamp (corrupt(rcvpkt) ||
has_seq1(rcvpkt))
udt_send(sndpkt)receiver FSM
fragment
Λ
Transport Layer 3-28
rdt30 channels with errors and loss
New assumptionunderlying channel can also lose packets (data or ACKs)
checksum seq ACKs retransmissions will be of help but not enough
Q how to deal with losssender waits until certain data or ACK lost then retransmitsdrawbacks
Approach sender waits ldquoreasonablerdquo amount of time for ACK retransmits if no ACK received in this timeif pkt (or ACK) just delayed (not lost)
retransmission will be duplicate but use of seq rsquos already handles thisreceiver must specify seq of pkt being ACKed
requires countdown timer
Transport Layer 3-29
rdt30 sendersndpkt = make_pkt(0 data checksum)udt_send(sndpkt)start_timer
rdt_send(data)
Wait for
ACK0
rdt_rcv(rcvpkt) ampamp ( corrupt(rcvpkt) ||isACK(rcvpkt1) )
Wait for call 1 from
above
sndpkt = make_pkt(1 data checksum)udt_send(sndpkt)start_timer
rdt_send(data)
rdt_rcv(rcvpkt) ampamp notcorrupt(rcvpkt) ampamp isACK(rcvpkt0)
rdt_rcv(rcvpkt) ampamp ( corrupt(rcvpkt) ||isACK(rcvpkt0) )
rdt_rcv(rcvpkt) ampamp notcorrupt(rcvpkt) ampamp isACK(rcvpkt1)
stop_timerstop_timer
udt_send(sndpkt)start_timer
timeout
udt_send(sndpkt)start_timer
timeout
rdt_rcv(rcvpkt)
Wait for call 0from
above
Wait for
ACK1
Λrdt_rcv(rcvpkt)
ΛΛ
Λ
Transport Layer 3-30
rdt30 in action
Transport Layer 3-31
rdt30 in action
Transport Layer 3-32
Performance of rdt30
rdt30 works but performance stinksexample 1 Gbps link 15 ms e-e prop delay 1KB packet
Ttransmit = 8kbpkt109 bsec = 8 microsec
U sender utilization ndash fraction of time sender busy sending1KB pkt every 30 msec -gt 33kBsec thruput over 1 Gbps linknetwork protocol limits use of physical resources
U sender=
008 30008
= 000027 L RRTT + L R
=
L (packet length in bits)R (transmission rate bps) =
Transport Layer 3-33
rdt30 stop-and-wait operation
first packet bit transmitted t = 0
sender receiver
RTT
last packet bit transmitted t = L R
first packet bit arriveslast packet bit arrives send ACK
ACK arrives send next packet t = RTT + L R
U sender=
00830008
= 000027 L RRTT + L R
=
Transport Layer 3-34
Pipelined protocolsPipelining sender allows multiple ldquoin-flightrdquo yet-to-
be-acknowledged pktsrange of sequence numbers must be increasedbuffering at sender andor receiver
Two generic forms of pipelined protocols go-Back-N selective repeat
Transport Layer 3-35
Pipelining increased utilization
first packet bit transmitted t = 0
sender receiver
RTT
last bit transmitted t = L R
first packet bit arriveslast packet bit arrives send ACK
ACK arrives send next packet t = RTT + L R
last bit of 2nd packet arrives send ACKlast bit of 3rd packet arrives send ACK
U sender=
024 30008
= 000083 L RRTT + L R
=
Increase utilizationby a factor of 3
Transport Layer 3-36
Utilization=N(LR)(RTT+LR) if NLRltRTT+LR Utilization=1 if and the sender pauses after it transmits a window NLRgtRTT+LR and the of packets until it receives first ACK sender does not pause
Transport Layer 3-37
Go-Back-NSender
k-bit seq in pkt headerldquowindowrdquo of up to N consecutive unackrsquoed pkts allowed
ACK(n) ACKs all pkts up to including seq n - ldquocumulative ACKrdquomay receive duplicate ACKs (see receiver)
timer for the entire windowtimeout(n) retransmit pkt n and all higher seq pkts in window
Transport Layer 3-38
GBN sender extended FSM
Wait start_timerudt_send(sndpkt[base])udt_send(sndpkt[base+1])hellipudt_send(sndpkt[nextseqnum-1])
timeout
rdt_send(data)
if (nextseqnum lt base+N) sndpkt[nextseqnum] = make_pkt(nextseqnumdatachksum)udt_send(sndpkt[nextseqnum])if (base == nextseqnum)
start_timernextseqnum++
elserefuse_data(data)
base = getacknum(rcvpkt)+1If (base == nextseqnum)
stop_timerelse
start_timer
rdt_rcv(rcvpkt) ampamp notcorrupt(rcvpkt)
base=1nextseqnum=1
rdt_rcv(rcvpkt) ampamp corrupt(rcvpkt)
Λ
Λ
Transport Layer 3-39
GBN receiver extended FSM
ACK-only always send ACK for correctly-received pktwith highest in-order seq
may generate duplicate ACKsneed only remember expectedseqnum
out-of-order pkt discard (donrsquot buffer) -gt no receiver bufferingRe-ACK pkt with highest in-order seq
Wait
udt_send(sndpkt)default
rdt_rcv(rcvpkt)ampamp notcurrupt(rcvpkt)ampamp hasseqnum(rcvpktexpectedseqnum)
extract(rcvpktdata)deliver_data(data)sndpkt = make_pkt(expectedseqnumACKchksum)udt_send(sndpkt)expectedseqnum++
expectedseqnum=1sndpkt =
make_pkt(0ACKchksum)
Λ
Transport Layer 3-40
GBN inaction
Transport Layer 3-41
Selective Repeat
receiver individually acknowledges all correctly received pkts
buffers pkts as needed for eventual in-order delivery to upper layer
sender only resends pkts for which ACK not received
sender timer for each unACKed pktsender window
N consecutive seq rsquosagain limits seq s of sent unACKed pkts
Transport Layer 3-42
Selective repeat sender receiver windows
Transport Layer 3-43
Selective repeat
data from above if next available seq in window send pkt
timeout(n)resend pkt n restart timer
ACK(n) in [sendbasesendbase+N-1]
mark pkt n as receivedif n smallest unACKed pkt advance window base to next unACKed seq
senderpkt n in [rcvbase rcvbase+N-1]
send ACK(n)out-of-order bufferin-order deliver (also deliver buffered in-order pkts) advance window to next not-yet-received pkt
pkt n in [rcvbase-Nrcvbase-1]
ACK(n)otherwise
ignore
receiver
Transport Layer 3-44
Selective repeat in action
Transport Layer 3-45
Selective repeatdilemma
Example seq rsquos 0 1 2 3window size=3
receiver sees no difference in two scenariosincorrectly passes duplicate data as new in (a)
Q what relationship between seq size and window size
Transport Layer 3-46
Sequence Number vs Window SizeSuppose we use k bits to represent SNQuestion Whatrsquos the minimum number of bits k necessary for a window size of N
sender
receiver
Go-Back-N
expectedSN
snd_base=expectedSN
Q For a given expectedSN whatrsquos the largest possible value for snd_baseA If all the last N ACKs sent by the receiver are received
snd_base = expectedSNexpectedSN+N-1
senderrsquos window
Transport Layer 3-47
Sequence Number vs Window SizeSuppose we use k bits to represent SNQuestion Whatrsquos the minimum number of bits k necessary for a window size of N
sender
receiver
Go-Back-N
expectedSN
snd_base=expectedSN-N
Q For a given expectedSN whatrsquos the smallest possible value for snd_baseA If all the last N ACKs sent by the receiver are not received
snd_base = expectedSN-NexpectedSN-1
senderrsquos window
Transport Layer 3-48
Sequence Number vs Window Size
sender
receiver
Go-Back-N
expectedSN
snd_base=expectedSN-N
All SNs in the interval [expectedSN-NexpectedSN+N-1] (an interval of size 2N) can be received by the receiver Since the receiver accepts on the packet with SN=expectedSN there should be no other packet within this interval with SN=expectedSN Therefore
2k ge N+1expectedSN+N-1
Transport Layer 3-49
Sequence Number vs Window SizeSuppose we use k bits to represent SNQuestion Whatrsquos the minimum number of bits k necessary for a window size of N
sender
receiver
Selective Repeat
rcv_base
snd_base=rcv_base
Q For a given rcv_base whatrsquos the largest possible value for snd_baseA If all the last N ACKs sent by the receiver are received
snd_base = rcv_base (same as go_back-N)rcv_base+N-1
senderrsquos window
receiverrsquos window
rcv_base+N-1
Transport Layer 3-50
Sequence Number vs Window SizeSuppose we use k bits to represent SNQuestion Whatrsquos the minimum number of bits k necessary for a window size of N
sender
receiver
Selective Repeat
rcv_base
snd_base=rcv_base-N
Q For a given rcv_base whatrsquos the smallest possible value for snd_baseA If all the last N ACKs sent by the receiver are not received
snd_base = rcv_base-N (same as Go-Back-N)rcv_base-1
senderrsquos window
rcv_base
receiverrsquos window
rcv_base+N-1
Transport Layer 3-51
Sequence Number vs Window Size
sender
receiver
Selective Repeat
snd_base=rcv_base-N
All SNs in the interval [rcv_base-Nrcv_base+N-1] (an interval of size 2N) can be received by the receiver Since the receiver should be able to distinguish between all packets in this interval and take corresponding action there should be no two packets within thisinterval having the same SN Therefore
2k ge 2Nrcv_base+N-1
rcv_basercv_base
receiverrsquos window
rcv_base+N-1
Transport Layer 3-52
TCP Overview RFCs 793 1122 1323 2018 2581
full duplex databi-directional data flow in same connectionMSS maximum segment size
connection-orientedhandshaking (exchange of control msgs) initrsquossender receiver state before data exchange
flow controlledsender will not overwhelm receiver
point-to-pointone sender one receiver
reliable in-order byte stream
no ldquomessage boundariesrdquopipelined
TCP congestion and flow control set window size
send amp receive buffers
socketdoor
TCPsend buffer
TCPreceive buffer
socketdoor
segment
applicationwrites data
applicationreads data
Transport Layer 3-53
TCP segment structure
source port dest port
32 bits
applicationdata
(variable length)
sequence numberacknowledgement number
Receive windowUrg data pnterchecksum
FSRPAUheadlen
notused
Options (variable length)
URG urgent data (generally not used)
ACK ACK valid
PSH push data now(generally not used)
RST SYN FINconnection estab(setup teardown
commands)
bytes rcvr willingto accept
Internetchecksum
(as in UDP)
countingby bytes of data(not segments)
Transport Layer 3-54
TCP seq rsquos and ACKsSeq rsquos
byte stream ldquonumberrdquo of first byte in segmentrsquos dataACKs
seq of next byte expected from other sidecumulative ACK
Q how receiver handles out-of-order segmentsA TCP spec doesnrsquot say - up to implementationWidely used implementations of TCP buffer out-of-order segments
Transport Layer 3-55
TCP Round Trip Time and Timeout
Q how to set TCP timeout valuelonger than RTT
but RTT variestoo short premature timeout
unnecessary retransmissions
too long slow reaction to segment loss
Q how to estimate RTTSampleRTT measured time from segment transmission until ACK receipt
ignore retransmissionsSampleRTT will vary want estimated RTT ldquosmootherrdquo
average several recent measurements not just current SampleRTT
Transport Layer 3-56
TCP Round Trip Time and Timeout
EstimatedRTT = (1- α)EstimatedRTT + αSampleRTT
Exponential weighted moving averageinfluence of past sample decreases exponentially fasttypical value α = 0125
Transport Layer 3-57
Example RTT estimationRTT gaiacsumassedu to fantasiaeurecomfr
100
150
200
250
300
350
1 8 15 22 29 36 43 50 57 64 71 78 85 92 99 106
time (seconnds)
RTT
(mill
iseco
nds)
SampleRTT Estimated RTT
Transport Layer 3-58
TCP Round Trip Time and TimeoutSetting the timeout
EstimatedRTT plus ldquosafety marginrdquolarge variation in EstimatedRTT -gt larger safety margin
first estimate of how much SampleRTT deviates from EstimatedRTT
TimeoutInterval = EstimatedRTT + 4DevRTT
DevRTT = (1-β)DevRTT +β|SampleRTT-EstimatedRTT|
(typically β = 025)
Then set timeout interval
Transport Layer 3-59
TCP reliable data transfer
TCP creates rdtservice on top of IPrsquos unreliable servicePipelined segmentsCumulative acksTCP uses single retransmission timer however it just retransmits the first segment in the window
Retransmissions are triggered by
timeout eventsduplicate acks
Initially consider simplified TCP sender
ignore duplicate acksignore flow control congestion control
Transport Layer 3-60
TCP sender eventsdata rcvd from app
Create segment with seq seq is byte-stream number of first data byte in segmentstart timer if not already running (think of timer as for oldest unacked segment)expiration interval TimeOutInterval
timeoutretransmit segment that caused timeout (first segment in the window)restart timer
Ack rcvdIf acknowledges previously unacked segments
update what is known to be ackedstart timer if there are outstanding segments
Transport Layer 3-61
TCP sender(simplified)
NextSeqNum = InitialSeqNumSendBase = InitialSeqNum
loop (forever) switch(event)
event data received from application above create TCP segment with sequence number NextSeqNumif (timer currently not running)
start timerpass segment to IP NextSeqNum = NextSeqNum + length(data)
event timer timeoutretransmit not-yet-acknowledged segment with
smallest sequence numberstart timer
event ACK received with ACK field value of y if (y gt SendBase)
SendBase = yif (there are currently not-yet-acknowledged segments)
start timer
end of loop forever
Commentbull SendBase-1 last cumulatively ackrsquoed byteExamplebull SendBase-1 = 71y= 73 so the rcvrwants 73+ y gt SendBase sothat new data is acked
Transport Layer 3-62
TCP retransmission scenariosHost A
Seq=100 20 bytes data
ACK=100
timepremature timeout
Host B
Seq=92 8 bytes data
ACK=120
Seq=92 8 bytes data
Seq=
92 t
imeo
ut
ACK=120
Host A
Seq=92 8 bytes data
ACK=100
loss
tim
eout
lost ACK scenario
Host B
X
Seq=92 8 bytes data
ACK=100
time
Seq=
92 t
imeo
utSendBase
= 100
SendBase= 120
SendBase= 120
Sendbase= 100
Transport Layer 3-63
TCP retransmission scenarios (more)Host A
Seq=92 8 bytes data
ACK=100
loss
tim
eout
Cumulative ACK scenario
Host B
X
Seq=100 20 bytes data
ACK=120
time
SendBase= 120
Transport Layer 3-64
TCP ACK generation [RFC 1122 RFC 2581]
Event at Receiver
Arrival of in-order segment withexpected seq All data up toexpected seq already ACKed
Arrival of in-order segment withexpected seq One other segment has ACK pending
Arrival of out-of-order segmenthigher-than-expect seq Gap detected
Arrival of segment that partially or completely fills gap
TCP Receiver action
Delayed ACK Wait up to 500msfor next segment If no next segmentsend ACK
Immediately send single cumulative ACK ACKing both in-order segments
Immediately send duplicate ACK indicating seq of next expected byte
Immediate send ACK provided thatsegment startsat lower end of gap
Transport Layer 3-65
Fast Retransmit
Time-out period often relatively long
long delay before resending lost packet
Detect lost segments via duplicate ACKs
Sender often sends many segments back-to-backIf segment is lost there will likely be many duplicate ACKs
If sender receives 3 ACKs for the same data it supposes that segment after ACKeddata was lost
fast retransmit resend segment before timer expires
Transport Layer 3-66
Fast RetransmitResend a segment after 3 duplicate ACKs since a duplicate ACK means that an out-of sequence segment was receivedduplicate ACKs due to packet reorderingif window is small donrsquot get duplicate ACKs
Host A
tim
eout
Host B
time
X
resend seq X2
seq x1seq x2seq x3seq x4seq x5
ACK x1
ACK x1ACK x1ACK x1
tripleduplicate
ACKs
Transport Layer 3-67
event ACK received with ACK field value of y if (y gt SendBase)
SendBase = yif (there are currently not-yet-acknowledged segments)
start timer
else increment count of dup ACKs received for yif (count of dup ACKs received for y = 3)
resend segment with sequence number y
Fast retransmit algorithm
a duplicate ACK for already ACKed segment
fast retransmit
Transport Layer 3-68
TCP Flow Control
receive side of TCP connection has a receive buffer
speed-matching service matching the send rate to the receiving apprsquos drain rate
app process may be slow at reading from buffer
sender wonrsquot overflowreceiverrsquos buffer by
transmitting too muchtoo fast
flow control
Transport Layer 3-69
TCP Flow control how it works
(Suppose TCP receiver discards out-of-order segments)spare room in buffer
= RcvWin
= RcvBuffer-[LastByteRcvd -LastByteRead]
Rcvr advertises spare room by including value of RcvWin in segmentsSender limits unACKeddata to RcvWin
guarantees receive buffer doesnrsquot overflow
Transport Layer 3-70
Sliding Window Flow Control Example
3K
2K SeqNo=0
ReceiverBuffer
0 4KSendersends 2Kof data
2K
AckNo=2048 RcvWin=2048Sendersends 2Kof data 2K SeqNo=2048
4K
AckNo=4096 RcvWin=0
AckNo=4096 RcvWin=1024
Sender blocked
Transport Layer 3-71
Principles of Congestion Control
Congestioninformally ldquotoo many sources sending too much data too fast for network to handlerdquodifferent from flow controlmanifestations
lost packets (buffer overflow at routers)long delays (queueing in router buffers)
a top-10 problem
Transport Layer 3-72
Causescosts of congestion scenario 1
two senders two receiversone router infinite buffers no retransmission
large delays when congestedmaximum achievable throughput
unlimited shared output link buffers
Host Aλin original data
Host B
λout
Transport Layer 3-73
Causescosts of congestion scenario 2
one router finite buffers sender retransmission of lost packet
finite shared output link buffers
Host A λin original data
Host B
λout
λin original data plus retransmitted data
Transport Layer 3-74
Causescosts of congestion scenario 2always (goodput)ldquoperfectrdquo retransmission only when loss
retransmission of delayed (not lost) packet makes larger(than perfect case) for same
λin
λout=
λin
λoutgtλ
inλout
ldquocostsrdquo of congestionmore work (retrans) for given ldquogoodputrdquounneeded retransmissions link carries multiple copies of pkt
R2
R2λin
λ out
b
R2
R2λin
λ out
a
R2
R2λin
λ out
c
R4
R3
Transport Layer 3-75
Causescosts of congestion scenario 3four sendersmultihop pathstimeoutretransmit
λin
Q what happens as and increase λ
in
finite shared output link buffers
Host Aλin original data
Host B
λout
λin original data plus retransmitted data
Transport Layer 3-76
Causescosts of congestion scenario 3
another ldquocostrdquo of congestionwhen packet dropped any ldquoupstream transmission capacity used for that packet was wasted
Host A
Host B
λou
t
Transport Layer 3-77
Approaches towards congestion control
End-end congestion controlno explicit feedback from networkcongestion inferred from end-system observed loss delayapproach taken by TCP
Network-assisted congestion controlrouters provide feedback to end systems
single bit indicating congestion (SNA DECbit TCPIP ECN ATM)explicit rate sender should send at
Two broad approaches towards congestion control
Transport Layer 3-78
TCP Congestion Control
end-end control (no network assistance)sender limits transmissionLastByteSent-LastByteAcked
le CongWin
CongWin is dynamic function of perceived network congestion
How does sender perceive congestionloss event = timeout or3 duplicate acksTCP sender reduces rate (CongWin) after loss event
two modes of operationSlow Start (SS)Congestion avoidance (CA) or Additive Increase Multiplicative Decrease (AIMD)
Transport Layer 3-79
TCP congestion control bandwidth probing
ldquoprobing for bandwidthrdquo increase transmission rate on receipt of ACK until eventually loss occurs then decrease transmission rate
continue to increase on ACK decrease on loss (since available bandwidth is changing depending on other connections in network)
ACKs being received so increase rate
X
X
XX
X loss so decrease rate
send
ing
rate
time
Q how fast to increasedecreasedetails to follow
TCPrsquosldquosawtoothrdquobehavior
Transport Layer 3-80
TCP Congestion Control details
sender limits rate by limiting number of unACKed bytes ldquoin pipelinerdquo
cwnd differs from rwnd (how why)sender limited by min(cwndrwnd)
roughly
cwnd is dynamic function of perceived network congestion
rate = cwndRTT bytessec
LastByteSent-LastByteAcked le cwnd
cwndbytes
RTT
ACK(s)
Transport Layer 3-81
TCP Congestion Control more details
segment loss event reducing cwndtimeout no response from receiver
cut cwnd to 13 duplicate ACKs at least some segments getting through (recall fast retransmit)
cut cwnd in half less aggressively than on timeout
ACK received increase cwndTwo modes of operation
slowstart phase bull increase exponentially
fast (despite name) at connection start or following timeout
congestion avoidance bull increase linearly
Transport Layer 3-82
TCP Slow Start Phasewhen connection begins cwnd = 1 MSS
example MSS = 500 bytes amp RTT = 200 msecinitial rate = 20 kbps
available bandwidth may be gtgt MSSRTT
desirable to quickly ramp up to respectable rate
increase rate exponentially until first loss event or when threshold reached
double cwnd every RTTdone by incrementing cwnd by 1 for every ACK received
Host A
one segment
RTT
Host B
time
two segments
four segments
Transport Layer 3-83
Slow Start ExampleThe congestion window size grows very rapidly
For every ACK we increase CongWin by 1 irrespective of the number of segments ACKrsquoeddouble CongWinevery RTTinitial rate is slow but ramps up exponentially fast
TCP slows down the increase of CongWinwhen CongWin gt ssthresh
segment 1
ACK for segment 1
cwnd = 1
cwnd = 2 segment 2segment 3
ACK for segments 2
cwnd = 4 segment 4segment 5segment 6
ACK for segments 4
cwnd = 7
ACK for segments 3
ACK for segments 5
ACK for segments 6
cwnd = 3
cwnd = 5
cwnd = 6ACK for segments 7
cwnd = 8
segment 7
Transport Layer 3-84
TCP Congestion Avoidance Phase
when cwnd gt ssthreshgrow cwnd linearly
increase cwnd by 1 MSS per RTT approach possible congestion slower than in slowstartimplementation cwnd= cwnd + MSScwndfor each ACK received
ACKs increase cwndby 1 MSS per RTT additive increaseloss cut cwnd in half (non-timeout-detected loss ) multiplicative decrease
AIMD
AIMD Additive IncreaseMultiplicative Decrease
Transport Layer 3-85
Congestion AvoidanceCongestion avoidance phase is started if CongWin has reached the slow-start threshold value
If CongWin gt= ssthresh then each time an ACK is received increment CongWin as follows
bull CongWin = CongWin + 1CongWin (CongWin in segments)
bull In actual TCP implementation CongWin is in BytesCongWin = CongWin + MSS (MSSCongWin)
So CongWin is increased by one only if all CongWinsegments have been acknowledged
Transport Layer 3-86
Example Slow StartCongestion AvoidanceAssume that
ssthresh = 8
cwnd = 1
cwnd = 2
cwnd = 4
cwnd = 8
cwnd = 9
cwnd = 10
02468
101214
t=0
t=2
t=4
t=6
Roundtrip times
Cw
nd(in
seg
men
ts)
ssthresh
cwnd = 3
cwnd = 5cwnd = 6cwnd = 7
Transport Layer 3-87
Slow Start Congestion AvoidanceA typical plot of CongWin for a TCP connection
(MSS = 1500 bytes) with TCP Tahoe
SS
CA
ssthresh
Transport Layer 3-88
Responses to CongestionTCP assumes there is congestion if it detects a packet lossA TCP sender can detect lost packets via loss events
bull Timeout of a retransmission timerbull Receipt of 3 duplicate ACKs (fast retransmit)
TCP interprets a Timeout as a binary congestion signal When a timeout occurs the sender performs
ssthresh is set to half the current size of the congestion window
ssthresh = CongWin 2CongWin is reset to one
CongWin = 1and slow-start is entered
Transport Layer 3-89
Fast Recovery (differentiation btwn two loss events) After 3 dup ACKs (fast Retransmit)
ssthresh = CongWin2CongWin = CongWin2window then grows linearly
But after timeout eventCongWin = 1 MSS window then grows exponentiallyto the threshold then grows linearly
bull 3 dup ACKs indicates network capable of delivering some segmentsbull timeout before 3 dup ACKs is ldquomore alarmingrdquo
Philosophy
3-90
TCP Congestion ControlInitially
CongWin = 1ssthresh = advertised window size
New Ack receivedif (CongWin lt ssthresh) Slow Start
CongWin = CongWin + 1else Congestion Avoidance
CongWin = CongWin + 1CongWinTimeout
ssthresh = CongWin2CongWin = 1
Fast Retransmissionssthresh = CongWin2CongWin = CongWin2
Slow Start (exponential increase phase) is continued until CongWin reaches half of the level where the loss event occurred last time CongWin is increased slowly after (linear increase in Congestion Avoidance phase)
Transport Layer 3-91
Popular ldquoflavorsrdquo of TCP
ssthresh
ssthresh
TCP Tahoe
TCP Reno
Transmission round
cwnd
win
dow
siz
e (in
seg
men
ts)
Transport Layer 3-92
Summary TCP Congestion ControlWhen CongWin is below Threshold sender in slow-start phase window grows exponentiallyWhen CongWin is above Threshold sender is in congestion-avoidance phase window grows linearlyWhen a triple duplicate ACK occurs Threshold set to CongWin2 and CongWin set to ThresholdWhen timeout occurs Threshold set to CongWin2 and CongWin is set to 1 MSS The actual sender window size is determined based on the congestion and flow control algorithms
SenderWin=min(RcvWinCongWin)
Transport Layer 3-93
TCP Congestion Control SummaryEvent State TCP Sender Action Commentary
ACK receipt for previously unackeddata
Slow Start (SS)
CongWin = CongWin + MSS If (CongWin gt Threshold)
set state to ldquoCongestion Avoidancerdquo
Resulting in a doubling of CongWin every RTT
ACK receipt for previously unackeddata
CongestionAvoidance (CA)
CongWin = CongWin+MSS (MSSCongWin)
Additive increase resulting in increase of CongWin by 1 MSS every RTT
Loss event detected by triple duplicate ACK
SS or CA Threshold = CongWin2 CongWin = ThresholdSet state to ldquoCongestion Avoidancerdquo
Fast recovery implementing multiplicative decrease CongWin will not drop below 1 MSS
Timeout SS or CA Threshold = CongWin2 CongWin = 1 MSSSet state to ldquoSlow Startrdquo
Enter slow start
Duplicate ACK
SS or CA Increment duplicate ACK count for segment being acked
CongWin and Threshold not changed
Transport Layer 3-94
TCP throughput
Q whatrsquos average throughout of TCP as function of window size RTT
ignoring slow startlet W be window size when loss occurs
when window is W throughput is WRTTjust after loss window drops to W2 throughput to W2RTT average throughout 75 WRTT
Transport Layer 3-95
TCP Futures TCP over ldquolong fat pipesrdquo
example 1500 byte segments 100ms RTT want 10 Gbps throughputrequires window size W = 83333 in-flight segmentsthroughput in terms of loss rate
L = 210-10 Wownew versions of TCP for high-speed
LRTTMSSsdot221
Transport Layer 3-96
Fairness goal if K TCP sessions share same bottleneck link of bandwidth R each should have average rate of RK
TCP connection 1
bottleneckrouter
capacity R
TCP connection 2
TCP Fairness
Transport Layer 3-97
Why is TCP fairTwo competing sessions
Additive increase gives slope of 1 as throughout increasesmultiplicative decrease decreases throughput proportionally
R
R
equal bandwidth share
Connection 1 throughput
Conn
ecti
on 2
thr
ough
p ut
congestion avoidance additive increaseloss decrease window by factor of 2
congestion avoidance additive increaseloss decrease window by factor of 2
Transport Layer 3-98
Fairness (more)Fairness and UDP
Multimedia apps often do not use TCP
do not want rate throttled by congestion control
Instead use UDPpump audiovideo at constant rate tolerate packet loss
Research area TCP friendly
Fairness and parallel TCP connectionsnothing prevents app from opening parallel cnctionsbetween 2 hostsWeb browsers do this Example link of rate R supporting 9 cnctions
new app asks for 1 TCP gets rate R10new app asks for 11 TCPs gets R2
Transport Layer 3-99
TCP Connection ManagementRecall TCP sender receiver
establish ldquoconnectionrdquobefore exchanging data segmentsinitialize TCP variables
seq sbuffers flow control info (eg RcvWindow)
client connection initiatorSocket clientSocket = new Socket(hostnameport
number)
server contacted by clientSocket connectionSocket = welcomeSocketaccept()
Three way handshakeStep 1 client host sends TCP
SYN segment to serverspecifies initial seq no data
Step 2 server host receives SYN replies with SYNACK segment
server allocates buffersspecifies server initial seq
Step 3 client receives SYNACK replies with ACK segment which may contain data
Transport Layer 3-100
TCP Connection Management (cont)
Closing a connection
client closes socketclientSocketclose()
Step 1 client end system sends TCP FIN control segment to server
Step 2 server receives FIN replies with ACK Closes connection sends FIN
client
FIN
server
ACK
ACK
FIN
close
close
closed
tim
ed w
ait
Transport Layer 3-101
TCP Connection Management (cont)
Step 3 client receives FIN replies with ACK
Enters ldquotimed waitrdquo -will respond with ACK to received FINs
Step 4 server receives ACK Connection closed
client
FIN
server
ACK
ACK
FIN
closing
closing
closed
tim
ed w
ait
closed
Transport Layer 3-102
TCP Connection Management (cont)
TCP clientlifecycle
TCP serverlifecycle
Transport Layer 3-103
Tuning TCPIP Parameters TCPIP parameters
A set of default values may not be optimal for all applicationsThe network administrator may wish to turn on or off some TCPIP functions for performance or security considerations
Many Unix and Linux systems provide some flexibility in tuning the TCPIP kernelsbinsysctl is used to configure the Linux kernel parameters at runtime
Default kernel configuration file is sbinsysctlconfFrequently used sysctl options
bull sysctl ndasha or sysctl ndashA list all current valuesbull sysctl ndashp file_name load the sysctl setting from a configuration
filebull sysctl ndashw variable=value change the value of the parameter
Transport Layer 3-104
SomeTCP Parameters in Linux Kerneltcp_syn_retries
Number of SYN packets the kernel will send before giving up on the new connection
tcp_synack_retriesnumber of SYN+ACK packets sent before the kernel gives up on the connection
tcp_window_scalingMaximum window size of 65535 bytes not enough for for really fast networks The window scaling options allows for almost gigabyte windows which is good for connections with large delay-bandwidth product
tcp_max_syn_backlogMaximal number of remembered connection requests which still did not receive an acknowledgment from connecting client
tcp_fin_timeoutHow many seconds to wait for a final FIN packet before the socket is closed required to prevent denial-of-service (DoS) attacks Default value is 60 seconds
Transport Layer 3-105
SomeTCP Parameters in Linux Kerneltcp_rmem
This is a vector of 3 integers [min default max] These parameters are used by TCP to dynamically adjust receive buffer sizesmin - minimum size of the receive buffer used by each TCP socket The default value is 4K default - the default size of the receive buffer for a TCP socket The default value is 87380 bytes and is lowered to 43689 in low memory systems If larger receive buffer sizes are desired this value should be increased max - the maximum size of the receive buffer used by each TCP socket The default value of 873802 bytes is lowered to 87380 in low memory systems
tcp_smemSend buffer parameters [min default max] similar to tcp_rmem
- Chapter 3 Transport Layer
- Transport services and protocols
- Transport vs network layer
- Internet transport-layer protocols
- Multiplexingdemultiplexing
- How demultiplexing works
- Connectionless demultiplexing
- Connection-oriented demux
- Connection-oriented demux (cont)
- Connection-oriented demux Threaded Web Server
- UDP User Datagram Protocol [RFC 768]
- UDP more
- UDP checksum
- Principles of Reliable data transfer
- Reliable data transfer getting started
- Reliable data transfer getting started
- Rdt10 reliable transfer over a reliable channel
- Rdt20 channel with bit errors
- rdt20 FSM specification
- rdt20 operation with no errors
- rdt20 error scenario
- rdt20 has a fatal flaw
- rdt21 sender handles garbled ACKNAKs
- rdt21 receiver handles garbled ACKNAKs
- rdt21 discussion
- rdt22 a NAK-free protocol
- rdt22 sender receiver fragments
- rdt30 channels with errors and loss
- rdt30 sender
- rdt30 in action
- rdt30 in action
- Performance of rdt30
- rdt30 stop-and-wait operation
- Pipelined protocols
- Pipelining increased utilization
- Go-Back-N
- GBN sender extended FSM
- GBN receiver extended FSM
- GBN inaction
- Selective Repeat
- Selective repeat sender receiver windows
- Selective repeat
- Selective repeat in action
- Selective repeat dilemma
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- TCP Overview RFCs 793 1122 1323 2018 2581
- TCP segment structure
- TCP seq rsquos and ACKs
- TCP Round Trip Time and Timeout
- TCP Round Trip Time and Timeout
- Example RTT estimation
- TCP Round Trip Time and Timeout
- TCP reliable data transfer
- TCP sender events
- TCP sender(simplified)
- TCP retransmission scenarios
- TCP retransmission scenarios (more)
- TCP ACK generation [RFC 1122 RFC 2581]
- Fast Retransmit
- Fast Retransmit
- Fast retransmit algorithm
- TCP Flow Control
- TCP Flow control how it works
- Sliding Window Flow Control Example
- Principles of Congestion Control
- Causescosts of congestion scenario 1
- Causescosts of congestion scenario 2
- Causescosts of congestion scenario 2
- Causescosts of congestion scenario 3
- Causescosts of congestion scenario 3
- Approaches towards congestion control
- TCP Congestion Control
- TCP congestion control bandwidth probing
- TCP Congestion Control details
- TCP Congestion Control more details
- TCP Slow Start Phase
- Slow Start Example
- TCP Congestion Avoidance Phase
- Congestion Avoidance
- Example Slow StartCongestion Avoidance
- Slow Start Congestion Avoidance
- Responses to Congestion
- Fast Recovery (differentiation btwn two loss events)
- TCP Congestion Control
- Popular ldquoflavorsrdquo of TCP
- Summary TCP Congestion Control
- TCP Congestion Control Summary
- TCP throughput
- TCP Futures TCP over ldquolong fat pipesrdquo
- TCP Fairness
- Why is TCP fair
- Fairness (more)
- TCP Connection Management
- TCP Connection Management (cont)
- TCP Connection Management (cont)
- TCP Connection Management (cont)
- Tuning TCPIP Parameters
- SomeTCP Parameters in Linux Kernel
- SomeTCP Parameters in Linux Kernel
-
Transport Layer 3-19
rdt20 FSM specification
Wait for call from above
snkpkt = make_pkt(data checksum)udt_send(sndpkt)
extract(rcvpktdata)deliver_data(data)udt_send(ACK)
rdt_rcv(rcvpkt) ampamp notcorrupt(rcvpkt)
rdt_rcv(rcvpkt) ampamp isACK(rcvpkt)
udt_send(sndpkt)
rdt_rcv(rcvpkt) ampampisNAK(rcvpkt)
udt_send(NAK)
rdt_rcv(rcvpkt) ampamp corrupt(rcvpkt)
Wait for ACK or
NAK
Wait for call from
belowsender
receiverrdt_send(data)
Λ
Transport Layer 3-20
rdt20 operation with no errors
Wait for call from above
snkpkt = make_pkt(data checksum)udt_send(sndpkt)
extract(rcvpktdata)deliver_data(data)udt_send(ACK)
rdt_rcv(rcvpkt) ampamp notcorrupt(rcvpkt)
rdt_rcv(rcvpkt) ampamp isACK(rcvpkt)
udt_send(sndpkt)
rdt_rcv(rcvpkt) ampampisNAK(rcvpkt)
udt_send(NAK)
rdt_rcv(rcvpkt) ampamp corrupt(rcvpkt)
Wait for ACK or
NAK
Wait for call from
below
rdt_send(data)
Λ
Transport Layer 3-21
rdt20 error scenario
Wait for call from above
snkpkt = make_pkt(data checksum)udt_send(sndpkt)
extract(rcvpktdata)deliver_data(data)udt_send(ACK)
rdt_rcv(rcvpkt) ampamp notcorrupt(rcvpkt)
rdt_rcv(rcvpkt) ampamp isACK(rcvpkt)
udt_send(sndpkt)
rdt_rcv(rcvpkt) ampampisNAK(rcvpkt)
udt_send(NAK)
rdt_rcv(rcvpkt) ampamp corrupt(rcvpkt)
Wait for ACK or
NAK
Wait for call from
below
rdt_send(data)
Λ
Transport Layer 3-22
rdt20 has a fatal flaw
What happens if ACKNAK corruptedsender doesnrsquot know what happened at receivercanrsquot just retransmit possible duplicate
What to dosender ACKsNAKs receiverrsquos ACKNAK What if sender ACKNAK lostretransmit but this might cause retransmission of correctly received pkt
Handling duplicates sender adds sequence number to each pktsender retransmits current pkt if ACKNAK garbledreceiver discards (doesnrsquot deliver up) duplicate pkt
Sender sends one packet then waits for receiver response
stop and wait
Transport Layer 3-23
rdt21 sender handles garbled ACKNAKs
Wait for call 0 from
above
sndpkt = make_pkt(0 data checksum)udt_send(sndpkt)
rdt_send(data)
Wait for ACK or NAK 0 udt_send(sndpkt)
rdt_rcv(rcvpkt) ampamp ( corrupt(rcvpkt) ||isNAK(rcvpkt) )
sndpkt = make_pkt(1 data checksum)udt_send(sndpkt)
rdt_send(data)
rdt_rcv(rcvpkt) ampamp notcorrupt(rcvpkt) ampamp isACK(rcvpkt)
udt_send(sndpkt)
rdt_rcv(rcvpkt) ampamp ( corrupt(rcvpkt) ||isNAK(rcvpkt) )
rdt_rcv(rcvpkt) ampamp notcorrupt(rcvpkt) ampamp isACK(rcvpkt)
Wait forcall 1 from
above
Wait for ACK or NAK 1
ΛΛ
Transport Layer 3-24
rdt21 receiver handles garbled ACKNAKs
Wait for 0 from below
sndpkt = make_pkt(NAK chksum)udt_send(sndpkt)
rdt_rcv(rcvpkt) ampamp not corrupt(rcvpkt) ampamphas_seq0(rcvpkt)
rdt_rcv(rcvpkt) ampamp notcorrupt(rcvpkt) ampamp has_seq1(rcvpkt)
extract(rcvpktdata)deliver_data(data)sndpkt = make_pkt(ACK chksum)udt_send(sndpkt)
Wait for 1 from below
rdt_rcv(rcvpkt) ampamp notcorrupt(rcvpkt) ampamp has_seq0(rcvpkt)
extract(rcvpktdata)deliver_data(data)sndpkt = make_pkt(ACK chksum)udt_send(sndpkt)
rdt_rcv(rcvpkt) ampamp (corrupt(rcvpkt)
sndpkt = make_pkt(ACK chksum)udt_send(sndpkt)
rdt_rcv(rcvpkt) ampamp not corrupt(rcvpkt) ampamphas_seq1(rcvpkt)
rdt_rcv(rcvpkt) ampamp (corrupt(rcvpkt)
sndpkt = make_pkt(ACK chksum)udt_send(sndpkt)
sndpkt = make_pkt(NAK chksum)udt_send(sndpkt)
Transport Layer 3-25
rdt21 discussion
Senderseq added to pkttwo seq rsquos (01) will suffice Whymust check if received ACKNAK corrupted twice as many states
state must ldquorememberrdquowhether ldquocurrentrdquo pkt has 0 or 1 seq
Receivermust check if received packet is duplicate
state indicates whether 0 or 1 is expected pkt seq
note receiver can notknow if its last ACKNAK received OK at sender
Transport Layer 3-26
rdt22 a NAK-free protocol
same functionality as rdt21 using ACKs onlyinstead of NAK receiver sends ACK for last pkt received OK
receiver must explicitly include seq of pkt being ACKed duplicate ACK at sender results in same action as NAK retransmit current pkt
Transport Layer 3-27
rdt22 sender receiver fragments
Wait for call 0 from
above
sndpkt = make_pkt(0 data checksum)udt_send(sndpkt)
rdt_send(data)
udt_send(sndpkt)
rdt_rcv(rcvpkt) ampamp ( corrupt(rcvpkt) ||
isACK(rcvpkt1) )
rdt_rcv(rcvpkt) ampamp notcorrupt(rcvpkt) ampamp isACK(rcvpkt0)
Wait for ACK
0sender FSM
fragment
Wait for 0 from below
rdt_rcv(rcvpkt) ampamp notcorrupt(rcvpkt) ampamp has_seq1(rcvpkt)
extract(rcvpktdata)deliver_data(data)sndpkt = make_pkt(ACK1 chksum)udt_send(sndpkt)
rdt_rcv(rcvpkt) ampamp (corrupt(rcvpkt) ||
has_seq1(rcvpkt))
udt_send(sndpkt)receiver FSM
fragment
Λ
Transport Layer 3-28
rdt30 channels with errors and loss
New assumptionunderlying channel can also lose packets (data or ACKs)
checksum seq ACKs retransmissions will be of help but not enough
Q how to deal with losssender waits until certain data or ACK lost then retransmitsdrawbacks
Approach sender waits ldquoreasonablerdquo amount of time for ACK retransmits if no ACK received in this timeif pkt (or ACK) just delayed (not lost)
retransmission will be duplicate but use of seq rsquos already handles thisreceiver must specify seq of pkt being ACKed
requires countdown timer
Transport Layer 3-29
rdt30 sendersndpkt = make_pkt(0 data checksum)udt_send(sndpkt)start_timer
rdt_send(data)
Wait for
ACK0
rdt_rcv(rcvpkt) ampamp ( corrupt(rcvpkt) ||isACK(rcvpkt1) )
Wait for call 1 from
above
sndpkt = make_pkt(1 data checksum)udt_send(sndpkt)start_timer
rdt_send(data)
rdt_rcv(rcvpkt) ampamp notcorrupt(rcvpkt) ampamp isACK(rcvpkt0)
rdt_rcv(rcvpkt) ampamp ( corrupt(rcvpkt) ||isACK(rcvpkt0) )
rdt_rcv(rcvpkt) ampamp notcorrupt(rcvpkt) ampamp isACK(rcvpkt1)
stop_timerstop_timer
udt_send(sndpkt)start_timer
timeout
udt_send(sndpkt)start_timer
timeout
rdt_rcv(rcvpkt)
Wait for call 0from
above
Wait for
ACK1
Λrdt_rcv(rcvpkt)
ΛΛ
Λ
Transport Layer 3-30
rdt30 in action
Transport Layer 3-31
rdt30 in action
Transport Layer 3-32
Performance of rdt30
rdt30 works but performance stinksexample 1 Gbps link 15 ms e-e prop delay 1KB packet
Ttransmit = 8kbpkt109 bsec = 8 microsec
U sender utilization ndash fraction of time sender busy sending1KB pkt every 30 msec -gt 33kBsec thruput over 1 Gbps linknetwork protocol limits use of physical resources
U sender=
008 30008
= 000027 L RRTT + L R
=
L (packet length in bits)R (transmission rate bps) =
Transport Layer 3-33
rdt30 stop-and-wait operation
first packet bit transmitted t = 0
sender receiver
RTT
last packet bit transmitted t = L R
first packet bit arriveslast packet bit arrives send ACK
ACK arrives send next packet t = RTT + L R
U sender=
00830008
= 000027 L RRTT + L R
=
Transport Layer 3-34
Pipelined protocolsPipelining sender allows multiple ldquoin-flightrdquo yet-to-
be-acknowledged pktsrange of sequence numbers must be increasedbuffering at sender andor receiver
Two generic forms of pipelined protocols go-Back-N selective repeat
Transport Layer 3-35
Pipelining increased utilization
first packet bit transmitted t = 0
sender receiver
RTT
last bit transmitted t = L R
first packet bit arriveslast packet bit arrives send ACK
ACK arrives send next packet t = RTT + L R
last bit of 2nd packet arrives send ACKlast bit of 3rd packet arrives send ACK
U sender=
024 30008
= 000083 L RRTT + L R
=
Increase utilizationby a factor of 3
Transport Layer 3-36
Utilization=N(LR)(RTT+LR) if NLRltRTT+LR Utilization=1 if and the sender pauses after it transmits a window NLRgtRTT+LR and the of packets until it receives first ACK sender does not pause
Transport Layer 3-37
Go-Back-NSender
k-bit seq in pkt headerldquowindowrdquo of up to N consecutive unackrsquoed pkts allowed
ACK(n) ACKs all pkts up to including seq n - ldquocumulative ACKrdquomay receive duplicate ACKs (see receiver)
timer for the entire windowtimeout(n) retransmit pkt n and all higher seq pkts in window
Transport Layer 3-38
GBN sender extended FSM
Wait start_timerudt_send(sndpkt[base])udt_send(sndpkt[base+1])hellipudt_send(sndpkt[nextseqnum-1])
timeout
rdt_send(data)
if (nextseqnum lt base+N) sndpkt[nextseqnum] = make_pkt(nextseqnumdatachksum)udt_send(sndpkt[nextseqnum])if (base == nextseqnum)
start_timernextseqnum++
elserefuse_data(data)
base = getacknum(rcvpkt)+1If (base == nextseqnum)
stop_timerelse
start_timer
rdt_rcv(rcvpkt) ampamp notcorrupt(rcvpkt)
base=1nextseqnum=1
rdt_rcv(rcvpkt) ampamp corrupt(rcvpkt)
Λ
Λ
Transport Layer 3-39
GBN receiver extended FSM
ACK-only always send ACK for correctly-received pktwith highest in-order seq
may generate duplicate ACKsneed only remember expectedseqnum
out-of-order pkt discard (donrsquot buffer) -gt no receiver bufferingRe-ACK pkt with highest in-order seq
Wait
udt_send(sndpkt)default
rdt_rcv(rcvpkt)ampamp notcurrupt(rcvpkt)ampamp hasseqnum(rcvpktexpectedseqnum)
extract(rcvpktdata)deliver_data(data)sndpkt = make_pkt(expectedseqnumACKchksum)udt_send(sndpkt)expectedseqnum++
expectedseqnum=1sndpkt =
make_pkt(0ACKchksum)
Λ
Transport Layer 3-40
GBN inaction
Transport Layer 3-41
Selective Repeat
receiver individually acknowledges all correctly received pkts
buffers pkts as needed for eventual in-order delivery to upper layer
sender only resends pkts for which ACK not received
sender timer for each unACKed pktsender window
N consecutive seq rsquosagain limits seq s of sent unACKed pkts
Transport Layer 3-42
Selective repeat sender receiver windows
Transport Layer 3-43
Selective repeat
data from above if next available seq in window send pkt
timeout(n)resend pkt n restart timer
ACK(n) in [sendbasesendbase+N-1]
mark pkt n as receivedif n smallest unACKed pkt advance window base to next unACKed seq
senderpkt n in [rcvbase rcvbase+N-1]
send ACK(n)out-of-order bufferin-order deliver (also deliver buffered in-order pkts) advance window to next not-yet-received pkt
pkt n in [rcvbase-Nrcvbase-1]
ACK(n)otherwise
ignore
receiver
Transport Layer 3-44
Selective repeat in action
Transport Layer 3-45
Selective repeatdilemma
Example seq rsquos 0 1 2 3window size=3
receiver sees no difference in two scenariosincorrectly passes duplicate data as new in (a)
Q what relationship between seq size and window size
Transport Layer 3-46
Sequence Number vs Window SizeSuppose we use k bits to represent SNQuestion Whatrsquos the minimum number of bits k necessary for a window size of N
sender
receiver
Go-Back-N
expectedSN
snd_base=expectedSN
Q For a given expectedSN whatrsquos the largest possible value for snd_baseA If all the last N ACKs sent by the receiver are received
snd_base = expectedSNexpectedSN+N-1
senderrsquos window
Transport Layer 3-47
Sequence Number vs Window SizeSuppose we use k bits to represent SNQuestion Whatrsquos the minimum number of bits k necessary for a window size of N
sender
receiver
Go-Back-N
expectedSN
snd_base=expectedSN-N
Q For a given expectedSN whatrsquos the smallest possible value for snd_baseA If all the last N ACKs sent by the receiver are not received
snd_base = expectedSN-NexpectedSN-1
senderrsquos window
Transport Layer 3-48
Sequence Number vs Window Size
sender
receiver
Go-Back-N
expectedSN
snd_base=expectedSN-N
All SNs in the interval [expectedSN-NexpectedSN+N-1] (an interval of size 2N) can be received by the receiver Since the receiver accepts on the packet with SN=expectedSN there should be no other packet within this interval with SN=expectedSN Therefore
2k ge N+1expectedSN+N-1
Transport Layer 3-49
Sequence Number vs Window SizeSuppose we use k bits to represent SNQuestion Whatrsquos the minimum number of bits k necessary for a window size of N
sender
receiver
Selective Repeat
rcv_base
snd_base=rcv_base
Q For a given rcv_base whatrsquos the largest possible value for snd_baseA If all the last N ACKs sent by the receiver are received
snd_base = rcv_base (same as go_back-N)rcv_base+N-1
senderrsquos window
receiverrsquos window
rcv_base+N-1
Transport Layer 3-50
Sequence Number vs Window SizeSuppose we use k bits to represent SNQuestion Whatrsquos the minimum number of bits k necessary for a window size of N
sender
receiver
Selective Repeat
rcv_base
snd_base=rcv_base-N
Q For a given rcv_base whatrsquos the smallest possible value for snd_baseA If all the last N ACKs sent by the receiver are not received
snd_base = rcv_base-N (same as Go-Back-N)rcv_base-1
senderrsquos window
rcv_base
receiverrsquos window
rcv_base+N-1
Transport Layer 3-51
Sequence Number vs Window Size
sender
receiver
Selective Repeat
snd_base=rcv_base-N
All SNs in the interval [rcv_base-Nrcv_base+N-1] (an interval of size 2N) can be received by the receiver Since the receiver should be able to distinguish between all packets in this interval and take corresponding action there should be no two packets within thisinterval having the same SN Therefore
2k ge 2Nrcv_base+N-1
rcv_basercv_base
receiverrsquos window
rcv_base+N-1
Transport Layer 3-52
TCP Overview RFCs 793 1122 1323 2018 2581
full duplex databi-directional data flow in same connectionMSS maximum segment size
connection-orientedhandshaking (exchange of control msgs) initrsquossender receiver state before data exchange
flow controlledsender will not overwhelm receiver
point-to-pointone sender one receiver
reliable in-order byte stream
no ldquomessage boundariesrdquopipelined
TCP congestion and flow control set window size
send amp receive buffers
socketdoor
TCPsend buffer
TCPreceive buffer
socketdoor
segment
applicationwrites data
applicationreads data
Transport Layer 3-53
TCP segment structure
source port dest port
32 bits
applicationdata
(variable length)
sequence numberacknowledgement number
Receive windowUrg data pnterchecksum
FSRPAUheadlen
notused
Options (variable length)
URG urgent data (generally not used)
ACK ACK valid
PSH push data now(generally not used)
RST SYN FINconnection estab(setup teardown
commands)
bytes rcvr willingto accept
Internetchecksum
(as in UDP)
countingby bytes of data(not segments)
Transport Layer 3-54
TCP seq rsquos and ACKsSeq rsquos
byte stream ldquonumberrdquo of first byte in segmentrsquos dataACKs
seq of next byte expected from other sidecumulative ACK
Q how receiver handles out-of-order segmentsA TCP spec doesnrsquot say - up to implementationWidely used implementations of TCP buffer out-of-order segments
Transport Layer 3-55
TCP Round Trip Time and Timeout
Q how to set TCP timeout valuelonger than RTT
but RTT variestoo short premature timeout
unnecessary retransmissions
too long slow reaction to segment loss
Q how to estimate RTTSampleRTT measured time from segment transmission until ACK receipt
ignore retransmissionsSampleRTT will vary want estimated RTT ldquosmootherrdquo
average several recent measurements not just current SampleRTT
Transport Layer 3-56
TCP Round Trip Time and Timeout
EstimatedRTT = (1- α)EstimatedRTT + αSampleRTT
Exponential weighted moving averageinfluence of past sample decreases exponentially fasttypical value α = 0125
Transport Layer 3-57
Example RTT estimationRTT gaiacsumassedu to fantasiaeurecomfr
100
150
200
250
300
350
1 8 15 22 29 36 43 50 57 64 71 78 85 92 99 106
time (seconnds)
RTT
(mill
iseco
nds)
SampleRTT Estimated RTT
Transport Layer 3-58
TCP Round Trip Time and TimeoutSetting the timeout
EstimatedRTT plus ldquosafety marginrdquolarge variation in EstimatedRTT -gt larger safety margin
first estimate of how much SampleRTT deviates from EstimatedRTT
TimeoutInterval = EstimatedRTT + 4DevRTT
DevRTT = (1-β)DevRTT +β|SampleRTT-EstimatedRTT|
(typically β = 025)
Then set timeout interval
Transport Layer 3-59
TCP reliable data transfer
TCP creates rdtservice on top of IPrsquos unreliable servicePipelined segmentsCumulative acksTCP uses single retransmission timer however it just retransmits the first segment in the window
Retransmissions are triggered by
timeout eventsduplicate acks
Initially consider simplified TCP sender
ignore duplicate acksignore flow control congestion control
Transport Layer 3-60
TCP sender eventsdata rcvd from app
Create segment with seq seq is byte-stream number of first data byte in segmentstart timer if not already running (think of timer as for oldest unacked segment)expiration interval TimeOutInterval
timeoutretransmit segment that caused timeout (first segment in the window)restart timer
Ack rcvdIf acknowledges previously unacked segments
update what is known to be ackedstart timer if there are outstanding segments
Transport Layer 3-61
TCP sender(simplified)
NextSeqNum = InitialSeqNumSendBase = InitialSeqNum
loop (forever) switch(event)
event data received from application above create TCP segment with sequence number NextSeqNumif (timer currently not running)
start timerpass segment to IP NextSeqNum = NextSeqNum + length(data)
event timer timeoutretransmit not-yet-acknowledged segment with
smallest sequence numberstart timer
event ACK received with ACK field value of y if (y gt SendBase)
SendBase = yif (there are currently not-yet-acknowledged segments)
start timer
end of loop forever
Commentbull SendBase-1 last cumulatively ackrsquoed byteExamplebull SendBase-1 = 71y= 73 so the rcvrwants 73+ y gt SendBase sothat new data is acked
Transport Layer 3-62
TCP retransmission scenariosHost A
Seq=100 20 bytes data
ACK=100
timepremature timeout
Host B
Seq=92 8 bytes data
ACK=120
Seq=92 8 bytes data
Seq=
92 t
imeo
ut
ACK=120
Host A
Seq=92 8 bytes data
ACK=100
loss
tim
eout
lost ACK scenario
Host B
X
Seq=92 8 bytes data
ACK=100
time
Seq=
92 t
imeo
utSendBase
= 100
SendBase= 120
SendBase= 120
Sendbase= 100
Transport Layer 3-63
TCP retransmission scenarios (more)Host A
Seq=92 8 bytes data
ACK=100
loss
tim
eout
Cumulative ACK scenario
Host B
X
Seq=100 20 bytes data
ACK=120
time
SendBase= 120
Transport Layer 3-64
TCP ACK generation [RFC 1122 RFC 2581]
Event at Receiver
Arrival of in-order segment withexpected seq All data up toexpected seq already ACKed
Arrival of in-order segment withexpected seq One other segment has ACK pending
Arrival of out-of-order segmenthigher-than-expect seq Gap detected
Arrival of segment that partially or completely fills gap
TCP Receiver action
Delayed ACK Wait up to 500msfor next segment If no next segmentsend ACK
Immediately send single cumulative ACK ACKing both in-order segments
Immediately send duplicate ACK indicating seq of next expected byte
Immediate send ACK provided thatsegment startsat lower end of gap
Transport Layer 3-65
Fast Retransmit
Time-out period often relatively long
long delay before resending lost packet
Detect lost segments via duplicate ACKs
Sender often sends many segments back-to-backIf segment is lost there will likely be many duplicate ACKs
If sender receives 3 ACKs for the same data it supposes that segment after ACKeddata was lost
fast retransmit resend segment before timer expires
Transport Layer 3-66
Fast RetransmitResend a segment after 3 duplicate ACKs since a duplicate ACK means that an out-of sequence segment was receivedduplicate ACKs due to packet reorderingif window is small donrsquot get duplicate ACKs
Host A
tim
eout
Host B
time
X
resend seq X2
seq x1seq x2seq x3seq x4seq x5
ACK x1
ACK x1ACK x1ACK x1
tripleduplicate
ACKs
Transport Layer 3-67
event ACK received with ACK field value of y if (y gt SendBase)
SendBase = yif (there are currently not-yet-acknowledged segments)
start timer
else increment count of dup ACKs received for yif (count of dup ACKs received for y = 3)
resend segment with sequence number y
Fast retransmit algorithm
a duplicate ACK for already ACKed segment
fast retransmit
Transport Layer 3-68
TCP Flow Control
receive side of TCP connection has a receive buffer
speed-matching service matching the send rate to the receiving apprsquos drain rate
app process may be slow at reading from buffer
sender wonrsquot overflowreceiverrsquos buffer by
transmitting too muchtoo fast
flow control
Transport Layer 3-69
TCP Flow control how it works
(Suppose TCP receiver discards out-of-order segments)spare room in buffer
= RcvWin
= RcvBuffer-[LastByteRcvd -LastByteRead]
Rcvr advertises spare room by including value of RcvWin in segmentsSender limits unACKeddata to RcvWin
guarantees receive buffer doesnrsquot overflow
Transport Layer 3-70
Sliding Window Flow Control Example
3K
2K SeqNo=0
ReceiverBuffer
0 4KSendersends 2Kof data
2K
AckNo=2048 RcvWin=2048Sendersends 2Kof data 2K SeqNo=2048
4K
AckNo=4096 RcvWin=0
AckNo=4096 RcvWin=1024
Sender blocked
Transport Layer 3-71
Principles of Congestion Control
Congestioninformally ldquotoo many sources sending too much data too fast for network to handlerdquodifferent from flow controlmanifestations
lost packets (buffer overflow at routers)long delays (queueing in router buffers)
a top-10 problem
Transport Layer 3-72
Causescosts of congestion scenario 1
two senders two receiversone router infinite buffers no retransmission
large delays when congestedmaximum achievable throughput
unlimited shared output link buffers
Host Aλin original data
Host B
λout
Transport Layer 3-73
Causescosts of congestion scenario 2
one router finite buffers sender retransmission of lost packet
finite shared output link buffers
Host A λin original data
Host B
λout
λin original data plus retransmitted data
Transport Layer 3-74
Causescosts of congestion scenario 2always (goodput)ldquoperfectrdquo retransmission only when loss
retransmission of delayed (not lost) packet makes larger(than perfect case) for same
λin
λout=
λin
λoutgtλ
inλout
ldquocostsrdquo of congestionmore work (retrans) for given ldquogoodputrdquounneeded retransmissions link carries multiple copies of pkt
R2
R2λin
λ out
b
R2
R2λin
λ out
a
R2
R2λin
λ out
c
R4
R3
Transport Layer 3-75
Causescosts of congestion scenario 3four sendersmultihop pathstimeoutretransmit
λin
Q what happens as and increase λ
in
finite shared output link buffers
Host Aλin original data
Host B
λout
λin original data plus retransmitted data
Transport Layer 3-76
Causescosts of congestion scenario 3
another ldquocostrdquo of congestionwhen packet dropped any ldquoupstream transmission capacity used for that packet was wasted
Host A
Host B
λou
t
Transport Layer 3-77
Approaches towards congestion control
End-end congestion controlno explicit feedback from networkcongestion inferred from end-system observed loss delayapproach taken by TCP
Network-assisted congestion controlrouters provide feedback to end systems
single bit indicating congestion (SNA DECbit TCPIP ECN ATM)explicit rate sender should send at
Two broad approaches towards congestion control
Transport Layer 3-78
TCP Congestion Control
end-end control (no network assistance)sender limits transmissionLastByteSent-LastByteAcked
le CongWin
CongWin is dynamic function of perceived network congestion
How does sender perceive congestionloss event = timeout or3 duplicate acksTCP sender reduces rate (CongWin) after loss event
two modes of operationSlow Start (SS)Congestion avoidance (CA) or Additive Increase Multiplicative Decrease (AIMD)
Transport Layer 3-79
TCP congestion control bandwidth probing
ldquoprobing for bandwidthrdquo increase transmission rate on receipt of ACK until eventually loss occurs then decrease transmission rate
continue to increase on ACK decrease on loss (since available bandwidth is changing depending on other connections in network)
ACKs being received so increase rate
X
X
XX
X loss so decrease rate
send
ing
rate
time
Q how fast to increasedecreasedetails to follow
TCPrsquosldquosawtoothrdquobehavior
Transport Layer 3-80
TCP Congestion Control details
sender limits rate by limiting number of unACKed bytes ldquoin pipelinerdquo
cwnd differs from rwnd (how why)sender limited by min(cwndrwnd)
roughly
cwnd is dynamic function of perceived network congestion
rate = cwndRTT bytessec
LastByteSent-LastByteAcked le cwnd
cwndbytes
RTT
ACK(s)
Transport Layer 3-81
TCP Congestion Control more details
segment loss event reducing cwndtimeout no response from receiver
cut cwnd to 13 duplicate ACKs at least some segments getting through (recall fast retransmit)
cut cwnd in half less aggressively than on timeout
ACK received increase cwndTwo modes of operation
slowstart phase bull increase exponentially
fast (despite name) at connection start or following timeout
congestion avoidance bull increase linearly
Transport Layer 3-82
TCP Slow Start Phasewhen connection begins cwnd = 1 MSS
example MSS = 500 bytes amp RTT = 200 msecinitial rate = 20 kbps
available bandwidth may be gtgt MSSRTT
desirable to quickly ramp up to respectable rate
increase rate exponentially until first loss event or when threshold reached
double cwnd every RTTdone by incrementing cwnd by 1 for every ACK received
Host A
one segment
RTT
Host B
time
two segments
four segments
Transport Layer 3-83
Slow Start ExampleThe congestion window size grows very rapidly
For every ACK we increase CongWin by 1 irrespective of the number of segments ACKrsquoeddouble CongWinevery RTTinitial rate is slow but ramps up exponentially fast
TCP slows down the increase of CongWinwhen CongWin gt ssthresh
segment 1
ACK for segment 1
cwnd = 1
cwnd = 2 segment 2segment 3
ACK for segments 2
cwnd = 4 segment 4segment 5segment 6
ACK for segments 4
cwnd = 7
ACK for segments 3
ACK for segments 5
ACK for segments 6
cwnd = 3
cwnd = 5
cwnd = 6ACK for segments 7
cwnd = 8
segment 7
Transport Layer 3-84
TCP Congestion Avoidance Phase
when cwnd gt ssthreshgrow cwnd linearly
increase cwnd by 1 MSS per RTT approach possible congestion slower than in slowstartimplementation cwnd= cwnd + MSScwndfor each ACK received
ACKs increase cwndby 1 MSS per RTT additive increaseloss cut cwnd in half (non-timeout-detected loss ) multiplicative decrease
AIMD
AIMD Additive IncreaseMultiplicative Decrease
Transport Layer 3-85
Congestion AvoidanceCongestion avoidance phase is started if CongWin has reached the slow-start threshold value
If CongWin gt= ssthresh then each time an ACK is received increment CongWin as follows
bull CongWin = CongWin + 1CongWin (CongWin in segments)
bull In actual TCP implementation CongWin is in BytesCongWin = CongWin + MSS (MSSCongWin)
So CongWin is increased by one only if all CongWinsegments have been acknowledged
Transport Layer 3-86
Example Slow StartCongestion AvoidanceAssume that
ssthresh = 8
cwnd = 1
cwnd = 2
cwnd = 4
cwnd = 8
cwnd = 9
cwnd = 10
02468
101214
t=0
t=2
t=4
t=6
Roundtrip times
Cw
nd(in
seg
men
ts)
ssthresh
cwnd = 3
cwnd = 5cwnd = 6cwnd = 7
Transport Layer 3-87
Slow Start Congestion AvoidanceA typical plot of CongWin for a TCP connection
(MSS = 1500 bytes) with TCP Tahoe
SS
CA
ssthresh
Transport Layer 3-88
Responses to CongestionTCP assumes there is congestion if it detects a packet lossA TCP sender can detect lost packets via loss events
bull Timeout of a retransmission timerbull Receipt of 3 duplicate ACKs (fast retransmit)
TCP interprets a Timeout as a binary congestion signal When a timeout occurs the sender performs
ssthresh is set to half the current size of the congestion window
ssthresh = CongWin 2CongWin is reset to one
CongWin = 1and slow-start is entered
Transport Layer 3-89
Fast Recovery (differentiation btwn two loss events) After 3 dup ACKs (fast Retransmit)
ssthresh = CongWin2CongWin = CongWin2window then grows linearly
But after timeout eventCongWin = 1 MSS window then grows exponentiallyto the threshold then grows linearly
bull 3 dup ACKs indicates network capable of delivering some segmentsbull timeout before 3 dup ACKs is ldquomore alarmingrdquo
Philosophy
3-90
TCP Congestion ControlInitially
CongWin = 1ssthresh = advertised window size
New Ack receivedif (CongWin lt ssthresh) Slow Start
CongWin = CongWin + 1else Congestion Avoidance
CongWin = CongWin + 1CongWinTimeout
ssthresh = CongWin2CongWin = 1
Fast Retransmissionssthresh = CongWin2CongWin = CongWin2
Slow Start (exponential increase phase) is continued until CongWin reaches half of the level where the loss event occurred last time CongWin is increased slowly after (linear increase in Congestion Avoidance phase)
Transport Layer 3-91
Popular ldquoflavorsrdquo of TCP
ssthresh
ssthresh
TCP Tahoe
TCP Reno
Transmission round
cwnd
win
dow
siz
e (in
seg
men
ts)
Transport Layer 3-92
Summary TCP Congestion ControlWhen CongWin is below Threshold sender in slow-start phase window grows exponentiallyWhen CongWin is above Threshold sender is in congestion-avoidance phase window grows linearlyWhen a triple duplicate ACK occurs Threshold set to CongWin2 and CongWin set to ThresholdWhen timeout occurs Threshold set to CongWin2 and CongWin is set to 1 MSS The actual sender window size is determined based on the congestion and flow control algorithms
SenderWin=min(RcvWinCongWin)
Transport Layer 3-93
TCP Congestion Control SummaryEvent State TCP Sender Action Commentary
ACK receipt for previously unackeddata
Slow Start (SS)
CongWin = CongWin + MSS If (CongWin gt Threshold)
set state to ldquoCongestion Avoidancerdquo
Resulting in a doubling of CongWin every RTT
ACK receipt for previously unackeddata
CongestionAvoidance (CA)
CongWin = CongWin+MSS (MSSCongWin)
Additive increase resulting in increase of CongWin by 1 MSS every RTT
Loss event detected by triple duplicate ACK
SS or CA Threshold = CongWin2 CongWin = ThresholdSet state to ldquoCongestion Avoidancerdquo
Fast recovery implementing multiplicative decrease CongWin will not drop below 1 MSS
Timeout SS or CA Threshold = CongWin2 CongWin = 1 MSSSet state to ldquoSlow Startrdquo
Enter slow start
Duplicate ACK
SS or CA Increment duplicate ACK count for segment being acked
CongWin and Threshold not changed
Transport Layer 3-94
TCP throughput
Q whatrsquos average throughout of TCP as function of window size RTT
ignoring slow startlet W be window size when loss occurs
when window is W throughput is WRTTjust after loss window drops to W2 throughput to W2RTT average throughout 75 WRTT
Transport Layer 3-95
TCP Futures TCP over ldquolong fat pipesrdquo
example 1500 byte segments 100ms RTT want 10 Gbps throughputrequires window size W = 83333 in-flight segmentsthroughput in terms of loss rate
L = 210-10 Wownew versions of TCP for high-speed
LRTTMSSsdot221
Transport Layer 3-96
Fairness goal if K TCP sessions share same bottleneck link of bandwidth R each should have average rate of RK
TCP connection 1
bottleneckrouter
capacity R
TCP connection 2
TCP Fairness
Transport Layer 3-97
Why is TCP fairTwo competing sessions
Additive increase gives slope of 1 as throughout increasesmultiplicative decrease decreases throughput proportionally
R
R
equal bandwidth share
Connection 1 throughput
Conn
ecti
on 2
thr
ough
p ut
congestion avoidance additive increaseloss decrease window by factor of 2
congestion avoidance additive increaseloss decrease window by factor of 2
Transport Layer 3-98
Fairness (more)Fairness and UDP
Multimedia apps often do not use TCP
do not want rate throttled by congestion control
Instead use UDPpump audiovideo at constant rate tolerate packet loss
Research area TCP friendly
Fairness and parallel TCP connectionsnothing prevents app from opening parallel cnctionsbetween 2 hostsWeb browsers do this Example link of rate R supporting 9 cnctions
new app asks for 1 TCP gets rate R10new app asks for 11 TCPs gets R2
Transport Layer 3-99
TCP Connection ManagementRecall TCP sender receiver
establish ldquoconnectionrdquobefore exchanging data segmentsinitialize TCP variables
seq sbuffers flow control info (eg RcvWindow)
client connection initiatorSocket clientSocket = new Socket(hostnameport
number)
server contacted by clientSocket connectionSocket = welcomeSocketaccept()
Three way handshakeStep 1 client host sends TCP
SYN segment to serverspecifies initial seq no data
Step 2 server host receives SYN replies with SYNACK segment
server allocates buffersspecifies server initial seq
Step 3 client receives SYNACK replies with ACK segment which may contain data
Transport Layer 3-100
TCP Connection Management (cont)
Closing a connection
client closes socketclientSocketclose()
Step 1 client end system sends TCP FIN control segment to server
Step 2 server receives FIN replies with ACK Closes connection sends FIN
client
FIN
server
ACK
ACK
FIN
close
close
closed
tim
ed w
ait
Transport Layer 3-101
TCP Connection Management (cont)
Step 3 client receives FIN replies with ACK
Enters ldquotimed waitrdquo -will respond with ACK to received FINs
Step 4 server receives ACK Connection closed
client
FIN
server
ACK
ACK
FIN
closing
closing
closed
tim
ed w
ait
closed
Transport Layer 3-102
TCP Connection Management (cont)
TCP clientlifecycle
TCP serverlifecycle
Transport Layer 3-103
Tuning TCPIP Parameters TCPIP parameters
A set of default values may not be optimal for all applicationsThe network administrator may wish to turn on or off some TCPIP functions for performance or security considerations
Many Unix and Linux systems provide some flexibility in tuning the TCPIP kernelsbinsysctl is used to configure the Linux kernel parameters at runtime
Default kernel configuration file is sbinsysctlconfFrequently used sysctl options
bull sysctl ndasha or sysctl ndashA list all current valuesbull sysctl ndashp file_name load the sysctl setting from a configuration
filebull sysctl ndashw variable=value change the value of the parameter
Transport Layer 3-104
SomeTCP Parameters in Linux Kerneltcp_syn_retries
Number of SYN packets the kernel will send before giving up on the new connection
tcp_synack_retriesnumber of SYN+ACK packets sent before the kernel gives up on the connection
tcp_window_scalingMaximum window size of 65535 bytes not enough for for really fast networks The window scaling options allows for almost gigabyte windows which is good for connections with large delay-bandwidth product
tcp_max_syn_backlogMaximal number of remembered connection requests which still did not receive an acknowledgment from connecting client
tcp_fin_timeoutHow many seconds to wait for a final FIN packet before the socket is closed required to prevent denial-of-service (DoS) attacks Default value is 60 seconds
Transport Layer 3-105
SomeTCP Parameters in Linux Kerneltcp_rmem
This is a vector of 3 integers [min default max] These parameters are used by TCP to dynamically adjust receive buffer sizesmin - minimum size of the receive buffer used by each TCP socket The default value is 4K default - the default size of the receive buffer for a TCP socket The default value is 87380 bytes and is lowered to 43689 in low memory systems If larger receive buffer sizes are desired this value should be increased max - the maximum size of the receive buffer used by each TCP socket The default value of 873802 bytes is lowered to 87380 in low memory systems
tcp_smemSend buffer parameters [min default max] similar to tcp_rmem
- Chapter 3 Transport Layer
- Transport services and protocols
- Transport vs network layer
- Internet transport-layer protocols
- Multiplexingdemultiplexing
- How demultiplexing works
- Connectionless demultiplexing
- Connection-oriented demux
- Connection-oriented demux (cont)
- Connection-oriented demux Threaded Web Server
- UDP User Datagram Protocol [RFC 768]
- UDP more
- UDP checksum
- Principles of Reliable data transfer
- Reliable data transfer getting started
- Reliable data transfer getting started
- Rdt10 reliable transfer over a reliable channel
- Rdt20 channel with bit errors
- rdt20 FSM specification
- rdt20 operation with no errors
- rdt20 error scenario
- rdt20 has a fatal flaw
- rdt21 sender handles garbled ACKNAKs
- rdt21 receiver handles garbled ACKNAKs
- rdt21 discussion
- rdt22 a NAK-free protocol
- rdt22 sender receiver fragments
- rdt30 channels with errors and loss
- rdt30 sender
- rdt30 in action
- rdt30 in action
- Performance of rdt30
- rdt30 stop-and-wait operation
- Pipelined protocols
- Pipelining increased utilization
- Go-Back-N
- GBN sender extended FSM
- GBN receiver extended FSM
- GBN inaction
- Selective Repeat
- Selective repeat sender receiver windows
- Selective repeat
- Selective repeat in action
- Selective repeat dilemma
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- TCP Overview RFCs 793 1122 1323 2018 2581
- TCP segment structure
- TCP seq rsquos and ACKs
- TCP Round Trip Time and Timeout
- TCP Round Trip Time and Timeout
- Example RTT estimation
- TCP Round Trip Time and Timeout
- TCP reliable data transfer
- TCP sender events
- TCP sender(simplified)
- TCP retransmission scenarios
- TCP retransmission scenarios (more)
- TCP ACK generation [RFC 1122 RFC 2581]
- Fast Retransmit
- Fast Retransmit
- Fast retransmit algorithm
- TCP Flow Control
- TCP Flow control how it works
- Sliding Window Flow Control Example
- Principles of Congestion Control
- Causescosts of congestion scenario 1
- Causescosts of congestion scenario 2
- Causescosts of congestion scenario 2
- Causescosts of congestion scenario 3
- Causescosts of congestion scenario 3
- Approaches towards congestion control
- TCP Congestion Control
- TCP congestion control bandwidth probing
- TCP Congestion Control details
- TCP Congestion Control more details
- TCP Slow Start Phase
- Slow Start Example
- TCP Congestion Avoidance Phase
- Congestion Avoidance
- Example Slow StartCongestion Avoidance
- Slow Start Congestion Avoidance
- Responses to Congestion
- Fast Recovery (differentiation btwn two loss events)
- TCP Congestion Control
- Popular ldquoflavorsrdquo of TCP
- Summary TCP Congestion Control
- TCP Congestion Control Summary
- TCP throughput
- TCP Futures TCP over ldquolong fat pipesrdquo
- TCP Fairness
- Why is TCP fair
- Fairness (more)
- TCP Connection Management
- TCP Connection Management (cont)
- TCP Connection Management (cont)
- TCP Connection Management (cont)
- Tuning TCPIP Parameters
- SomeTCP Parameters in Linux Kernel
- SomeTCP Parameters in Linux Kernel
-
Transport Layer 3-20
rdt20 operation with no errors
Wait for call from above
snkpkt = make_pkt(data checksum)udt_send(sndpkt)
extract(rcvpktdata)deliver_data(data)udt_send(ACK)
rdt_rcv(rcvpkt) ampamp notcorrupt(rcvpkt)
rdt_rcv(rcvpkt) ampamp isACK(rcvpkt)
udt_send(sndpkt)
rdt_rcv(rcvpkt) ampampisNAK(rcvpkt)
udt_send(NAK)
rdt_rcv(rcvpkt) ampamp corrupt(rcvpkt)
Wait for ACK or
NAK
Wait for call from
below
rdt_send(data)
Λ
Transport Layer 3-21
rdt20 error scenario
Wait for call from above
snkpkt = make_pkt(data checksum)udt_send(sndpkt)
extract(rcvpktdata)deliver_data(data)udt_send(ACK)
rdt_rcv(rcvpkt) ampamp notcorrupt(rcvpkt)
rdt_rcv(rcvpkt) ampamp isACK(rcvpkt)
udt_send(sndpkt)
rdt_rcv(rcvpkt) ampampisNAK(rcvpkt)
udt_send(NAK)
rdt_rcv(rcvpkt) ampamp corrupt(rcvpkt)
Wait for ACK or
NAK
Wait for call from
below
rdt_send(data)
Λ
Transport Layer 3-22
rdt20 has a fatal flaw
What happens if ACKNAK corruptedsender doesnrsquot know what happened at receivercanrsquot just retransmit possible duplicate
What to dosender ACKsNAKs receiverrsquos ACKNAK What if sender ACKNAK lostretransmit but this might cause retransmission of correctly received pkt
Handling duplicates sender adds sequence number to each pktsender retransmits current pkt if ACKNAK garbledreceiver discards (doesnrsquot deliver up) duplicate pkt
Sender sends one packet then waits for receiver response
stop and wait
Transport Layer 3-23
rdt21 sender handles garbled ACKNAKs
Wait for call 0 from
above
sndpkt = make_pkt(0 data checksum)udt_send(sndpkt)
rdt_send(data)
Wait for ACK or NAK 0 udt_send(sndpkt)
rdt_rcv(rcvpkt) ampamp ( corrupt(rcvpkt) ||isNAK(rcvpkt) )
sndpkt = make_pkt(1 data checksum)udt_send(sndpkt)
rdt_send(data)
rdt_rcv(rcvpkt) ampamp notcorrupt(rcvpkt) ampamp isACK(rcvpkt)
udt_send(sndpkt)
rdt_rcv(rcvpkt) ampamp ( corrupt(rcvpkt) ||isNAK(rcvpkt) )
rdt_rcv(rcvpkt) ampamp notcorrupt(rcvpkt) ampamp isACK(rcvpkt)
Wait forcall 1 from
above
Wait for ACK or NAK 1
ΛΛ
Transport Layer 3-24
rdt21 receiver handles garbled ACKNAKs
Wait for 0 from below
sndpkt = make_pkt(NAK chksum)udt_send(sndpkt)
rdt_rcv(rcvpkt) ampamp not corrupt(rcvpkt) ampamphas_seq0(rcvpkt)
rdt_rcv(rcvpkt) ampamp notcorrupt(rcvpkt) ampamp has_seq1(rcvpkt)
extract(rcvpktdata)deliver_data(data)sndpkt = make_pkt(ACK chksum)udt_send(sndpkt)
Wait for 1 from below
rdt_rcv(rcvpkt) ampamp notcorrupt(rcvpkt) ampamp has_seq0(rcvpkt)
extract(rcvpktdata)deliver_data(data)sndpkt = make_pkt(ACK chksum)udt_send(sndpkt)
rdt_rcv(rcvpkt) ampamp (corrupt(rcvpkt)
sndpkt = make_pkt(ACK chksum)udt_send(sndpkt)
rdt_rcv(rcvpkt) ampamp not corrupt(rcvpkt) ampamphas_seq1(rcvpkt)
rdt_rcv(rcvpkt) ampamp (corrupt(rcvpkt)
sndpkt = make_pkt(ACK chksum)udt_send(sndpkt)
sndpkt = make_pkt(NAK chksum)udt_send(sndpkt)
Transport Layer 3-25
rdt21 discussion
Senderseq added to pkttwo seq rsquos (01) will suffice Whymust check if received ACKNAK corrupted twice as many states
state must ldquorememberrdquowhether ldquocurrentrdquo pkt has 0 or 1 seq
Receivermust check if received packet is duplicate
state indicates whether 0 or 1 is expected pkt seq
note receiver can notknow if its last ACKNAK received OK at sender
Transport Layer 3-26
rdt22 a NAK-free protocol
same functionality as rdt21 using ACKs onlyinstead of NAK receiver sends ACK for last pkt received OK
receiver must explicitly include seq of pkt being ACKed duplicate ACK at sender results in same action as NAK retransmit current pkt
Transport Layer 3-27
rdt22 sender receiver fragments
Wait for call 0 from
above
sndpkt = make_pkt(0 data checksum)udt_send(sndpkt)
rdt_send(data)
udt_send(sndpkt)
rdt_rcv(rcvpkt) ampamp ( corrupt(rcvpkt) ||
isACK(rcvpkt1) )
rdt_rcv(rcvpkt) ampamp notcorrupt(rcvpkt) ampamp isACK(rcvpkt0)
Wait for ACK
0sender FSM
fragment
Wait for 0 from below
rdt_rcv(rcvpkt) ampamp notcorrupt(rcvpkt) ampamp has_seq1(rcvpkt)
extract(rcvpktdata)deliver_data(data)sndpkt = make_pkt(ACK1 chksum)udt_send(sndpkt)
rdt_rcv(rcvpkt) ampamp (corrupt(rcvpkt) ||
has_seq1(rcvpkt))
udt_send(sndpkt)receiver FSM
fragment
Λ
Transport Layer 3-28
rdt30 channels with errors and loss
New assumptionunderlying channel can also lose packets (data or ACKs)
checksum seq ACKs retransmissions will be of help but not enough
Q how to deal with losssender waits until certain data or ACK lost then retransmitsdrawbacks
Approach sender waits ldquoreasonablerdquo amount of time for ACK retransmits if no ACK received in this timeif pkt (or ACK) just delayed (not lost)
retransmission will be duplicate but use of seq rsquos already handles thisreceiver must specify seq of pkt being ACKed
requires countdown timer
Transport Layer 3-29
rdt30 sendersndpkt = make_pkt(0 data checksum)udt_send(sndpkt)start_timer
rdt_send(data)
Wait for
ACK0
rdt_rcv(rcvpkt) ampamp ( corrupt(rcvpkt) ||isACK(rcvpkt1) )
Wait for call 1 from
above
sndpkt = make_pkt(1 data checksum)udt_send(sndpkt)start_timer
rdt_send(data)
rdt_rcv(rcvpkt) ampamp notcorrupt(rcvpkt) ampamp isACK(rcvpkt0)
rdt_rcv(rcvpkt) ampamp ( corrupt(rcvpkt) ||isACK(rcvpkt0) )
rdt_rcv(rcvpkt) ampamp notcorrupt(rcvpkt) ampamp isACK(rcvpkt1)
stop_timerstop_timer
udt_send(sndpkt)start_timer
timeout
udt_send(sndpkt)start_timer
timeout
rdt_rcv(rcvpkt)
Wait for call 0from
above
Wait for
ACK1
Λrdt_rcv(rcvpkt)
ΛΛ
Λ
Transport Layer 3-30
rdt30 in action
Transport Layer 3-31
rdt30 in action
Transport Layer 3-32
Performance of rdt30
rdt30 works but performance stinksexample 1 Gbps link 15 ms e-e prop delay 1KB packet
Ttransmit = 8kbpkt109 bsec = 8 microsec
U sender utilization ndash fraction of time sender busy sending1KB pkt every 30 msec -gt 33kBsec thruput over 1 Gbps linknetwork protocol limits use of physical resources
U sender=
008 30008
= 000027 L RRTT + L R
=
L (packet length in bits)R (transmission rate bps) =
Transport Layer 3-33
rdt30 stop-and-wait operation
first packet bit transmitted t = 0
sender receiver
RTT
last packet bit transmitted t = L R
first packet bit arriveslast packet bit arrives send ACK
ACK arrives send next packet t = RTT + L R
U sender=
00830008
= 000027 L RRTT + L R
=
Transport Layer 3-34
Pipelined protocolsPipelining sender allows multiple ldquoin-flightrdquo yet-to-
be-acknowledged pktsrange of sequence numbers must be increasedbuffering at sender andor receiver
Two generic forms of pipelined protocols go-Back-N selective repeat
Transport Layer 3-35
Pipelining increased utilization
first packet bit transmitted t = 0
sender receiver
RTT
last bit transmitted t = L R
first packet bit arriveslast packet bit arrives send ACK
ACK arrives send next packet t = RTT + L R
last bit of 2nd packet arrives send ACKlast bit of 3rd packet arrives send ACK
U sender=
024 30008
= 000083 L RRTT + L R
=
Increase utilizationby a factor of 3
Transport Layer 3-36
Utilization=N(LR)(RTT+LR) if NLRltRTT+LR Utilization=1 if and the sender pauses after it transmits a window NLRgtRTT+LR and the of packets until it receives first ACK sender does not pause
Transport Layer 3-37
Go-Back-NSender
k-bit seq in pkt headerldquowindowrdquo of up to N consecutive unackrsquoed pkts allowed
ACK(n) ACKs all pkts up to including seq n - ldquocumulative ACKrdquomay receive duplicate ACKs (see receiver)
timer for the entire windowtimeout(n) retransmit pkt n and all higher seq pkts in window
Transport Layer 3-38
GBN sender extended FSM
Wait start_timerudt_send(sndpkt[base])udt_send(sndpkt[base+1])hellipudt_send(sndpkt[nextseqnum-1])
timeout
rdt_send(data)
if (nextseqnum lt base+N) sndpkt[nextseqnum] = make_pkt(nextseqnumdatachksum)udt_send(sndpkt[nextseqnum])if (base == nextseqnum)
start_timernextseqnum++
elserefuse_data(data)
base = getacknum(rcvpkt)+1If (base == nextseqnum)
stop_timerelse
start_timer
rdt_rcv(rcvpkt) ampamp notcorrupt(rcvpkt)
base=1nextseqnum=1
rdt_rcv(rcvpkt) ampamp corrupt(rcvpkt)
Λ
Λ
Transport Layer 3-39
GBN receiver extended FSM
ACK-only always send ACK for correctly-received pktwith highest in-order seq
may generate duplicate ACKsneed only remember expectedseqnum
out-of-order pkt discard (donrsquot buffer) -gt no receiver bufferingRe-ACK pkt with highest in-order seq
Wait
udt_send(sndpkt)default
rdt_rcv(rcvpkt)ampamp notcurrupt(rcvpkt)ampamp hasseqnum(rcvpktexpectedseqnum)
extract(rcvpktdata)deliver_data(data)sndpkt = make_pkt(expectedseqnumACKchksum)udt_send(sndpkt)expectedseqnum++
expectedseqnum=1sndpkt =
make_pkt(0ACKchksum)
Λ
Transport Layer 3-40
GBN inaction
Transport Layer 3-41
Selective Repeat
receiver individually acknowledges all correctly received pkts
buffers pkts as needed for eventual in-order delivery to upper layer
sender only resends pkts for which ACK not received
sender timer for each unACKed pktsender window
N consecutive seq rsquosagain limits seq s of sent unACKed pkts
Transport Layer 3-42
Selective repeat sender receiver windows
Transport Layer 3-43
Selective repeat
data from above if next available seq in window send pkt
timeout(n)resend pkt n restart timer
ACK(n) in [sendbasesendbase+N-1]
mark pkt n as receivedif n smallest unACKed pkt advance window base to next unACKed seq
senderpkt n in [rcvbase rcvbase+N-1]
send ACK(n)out-of-order bufferin-order deliver (also deliver buffered in-order pkts) advance window to next not-yet-received pkt
pkt n in [rcvbase-Nrcvbase-1]
ACK(n)otherwise
ignore
receiver
Transport Layer 3-44
Selective repeat in action
Transport Layer 3-45
Selective repeatdilemma
Example seq rsquos 0 1 2 3window size=3
receiver sees no difference in two scenariosincorrectly passes duplicate data as new in (a)
Q what relationship between seq size and window size
Transport Layer 3-46
Sequence Number vs Window SizeSuppose we use k bits to represent SNQuestion Whatrsquos the minimum number of bits k necessary for a window size of N
sender
receiver
Go-Back-N
expectedSN
snd_base=expectedSN
Q For a given expectedSN whatrsquos the largest possible value for snd_baseA If all the last N ACKs sent by the receiver are received
snd_base = expectedSNexpectedSN+N-1
senderrsquos window
Transport Layer 3-47
Sequence Number vs Window SizeSuppose we use k bits to represent SNQuestion Whatrsquos the minimum number of bits k necessary for a window size of N
sender
receiver
Go-Back-N
expectedSN
snd_base=expectedSN-N
Q For a given expectedSN whatrsquos the smallest possible value for snd_baseA If all the last N ACKs sent by the receiver are not received
snd_base = expectedSN-NexpectedSN-1
senderrsquos window
Transport Layer 3-48
Sequence Number vs Window Size
sender
receiver
Go-Back-N
expectedSN
snd_base=expectedSN-N
All SNs in the interval [expectedSN-NexpectedSN+N-1] (an interval of size 2N) can be received by the receiver Since the receiver accepts on the packet with SN=expectedSN there should be no other packet within this interval with SN=expectedSN Therefore
2k ge N+1expectedSN+N-1
Transport Layer 3-49
Sequence Number vs Window SizeSuppose we use k bits to represent SNQuestion Whatrsquos the minimum number of bits k necessary for a window size of N
sender
receiver
Selective Repeat
rcv_base
snd_base=rcv_base
Q For a given rcv_base whatrsquos the largest possible value for snd_baseA If all the last N ACKs sent by the receiver are received
snd_base = rcv_base (same as go_back-N)rcv_base+N-1
senderrsquos window
receiverrsquos window
rcv_base+N-1
Transport Layer 3-50
Sequence Number vs Window SizeSuppose we use k bits to represent SNQuestion Whatrsquos the minimum number of bits k necessary for a window size of N
sender
receiver
Selective Repeat
rcv_base
snd_base=rcv_base-N
Q For a given rcv_base whatrsquos the smallest possible value for snd_baseA If all the last N ACKs sent by the receiver are not received
snd_base = rcv_base-N (same as Go-Back-N)rcv_base-1
senderrsquos window
rcv_base
receiverrsquos window
rcv_base+N-1
Transport Layer 3-51
Sequence Number vs Window Size
sender
receiver
Selective Repeat
snd_base=rcv_base-N
All SNs in the interval [rcv_base-Nrcv_base+N-1] (an interval of size 2N) can be received by the receiver Since the receiver should be able to distinguish between all packets in this interval and take corresponding action there should be no two packets within thisinterval having the same SN Therefore
2k ge 2Nrcv_base+N-1
rcv_basercv_base
receiverrsquos window
rcv_base+N-1
Transport Layer 3-52
TCP Overview RFCs 793 1122 1323 2018 2581
full duplex databi-directional data flow in same connectionMSS maximum segment size
connection-orientedhandshaking (exchange of control msgs) initrsquossender receiver state before data exchange
flow controlledsender will not overwhelm receiver
point-to-pointone sender one receiver
reliable in-order byte stream
no ldquomessage boundariesrdquopipelined
TCP congestion and flow control set window size
send amp receive buffers
socketdoor
TCPsend buffer
TCPreceive buffer
socketdoor
segment
applicationwrites data
applicationreads data
Transport Layer 3-53
TCP segment structure
source port dest port
32 bits
applicationdata
(variable length)
sequence numberacknowledgement number
Receive windowUrg data pnterchecksum
FSRPAUheadlen
notused
Options (variable length)
URG urgent data (generally not used)
ACK ACK valid
PSH push data now(generally not used)
RST SYN FINconnection estab(setup teardown
commands)
bytes rcvr willingto accept
Internetchecksum
(as in UDP)
countingby bytes of data(not segments)
Transport Layer 3-54
TCP seq rsquos and ACKsSeq rsquos
byte stream ldquonumberrdquo of first byte in segmentrsquos dataACKs
seq of next byte expected from other sidecumulative ACK
Q how receiver handles out-of-order segmentsA TCP spec doesnrsquot say - up to implementationWidely used implementations of TCP buffer out-of-order segments
Transport Layer 3-55
TCP Round Trip Time and Timeout
Q how to set TCP timeout valuelonger than RTT
but RTT variestoo short premature timeout
unnecessary retransmissions
too long slow reaction to segment loss
Q how to estimate RTTSampleRTT measured time from segment transmission until ACK receipt
ignore retransmissionsSampleRTT will vary want estimated RTT ldquosmootherrdquo
average several recent measurements not just current SampleRTT
Transport Layer 3-56
TCP Round Trip Time and Timeout
EstimatedRTT = (1- α)EstimatedRTT + αSampleRTT
Exponential weighted moving averageinfluence of past sample decreases exponentially fasttypical value α = 0125
Transport Layer 3-57
Example RTT estimationRTT gaiacsumassedu to fantasiaeurecomfr
100
150
200
250
300
350
1 8 15 22 29 36 43 50 57 64 71 78 85 92 99 106
time (seconnds)
RTT
(mill
iseco
nds)
SampleRTT Estimated RTT
Transport Layer 3-58
TCP Round Trip Time and TimeoutSetting the timeout
EstimatedRTT plus ldquosafety marginrdquolarge variation in EstimatedRTT -gt larger safety margin
first estimate of how much SampleRTT deviates from EstimatedRTT
TimeoutInterval = EstimatedRTT + 4DevRTT
DevRTT = (1-β)DevRTT +β|SampleRTT-EstimatedRTT|
(typically β = 025)
Then set timeout interval
Transport Layer 3-59
TCP reliable data transfer
TCP creates rdtservice on top of IPrsquos unreliable servicePipelined segmentsCumulative acksTCP uses single retransmission timer however it just retransmits the first segment in the window
Retransmissions are triggered by
timeout eventsduplicate acks
Initially consider simplified TCP sender
ignore duplicate acksignore flow control congestion control
Transport Layer 3-60
TCP sender eventsdata rcvd from app
Create segment with seq seq is byte-stream number of first data byte in segmentstart timer if not already running (think of timer as for oldest unacked segment)expiration interval TimeOutInterval
timeoutretransmit segment that caused timeout (first segment in the window)restart timer
Ack rcvdIf acknowledges previously unacked segments
update what is known to be ackedstart timer if there are outstanding segments
Transport Layer 3-61
TCP sender(simplified)
NextSeqNum = InitialSeqNumSendBase = InitialSeqNum
loop (forever) switch(event)
event data received from application above create TCP segment with sequence number NextSeqNumif (timer currently not running)
start timerpass segment to IP NextSeqNum = NextSeqNum + length(data)
event timer timeoutretransmit not-yet-acknowledged segment with
smallest sequence numberstart timer
event ACK received with ACK field value of y if (y gt SendBase)
SendBase = yif (there are currently not-yet-acknowledged segments)
start timer
end of loop forever
Commentbull SendBase-1 last cumulatively ackrsquoed byteExamplebull SendBase-1 = 71y= 73 so the rcvrwants 73+ y gt SendBase sothat new data is acked
Transport Layer 3-62
TCP retransmission scenariosHost A
Seq=100 20 bytes data
ACK=100
timepremature timeout
Host B
Seq=92 8 bytes data
ACK=120
Seq=92 8 bytes data
Seq=
92 t
imeo
ut
ACK=120
Host A
Seq=92 8 bytes data
ACK=100
loss
tim
eout
lost ACK scenario
Host B
X
Seq=92 8 bytes data
ACK=100
time
Seq=
92 t
imeo
utSendBase
= 100
SendBase= 120
SendBase= 120
Sendbase= 100
Transport Layer 3-63
TCP retransmission scenarios (more)Host A
Seq=92 8 bytes data
ACK=100
loss
tim
eout
Cumulative ACK scenario
Host B
X
Seq=100 20 bytes data
ACK=120
time
SendBase= 120
Transport Layer 3-64
TCP ACK generation [RFC 1122 RFC 2581]
Event at Receiver
Arrival of in-order segment withexpected seq All data up toexpected seq already ACKed
Arrival of in-order segment withexpected seq One other segment has ACK pending
Arrival of out-of-order segmenthigher-than-expect seq Gap detected
Arrival of segment that partially or completely fills gap
TCP Receiver action
Delayed ACK Wait up to 500msfor next segment If no next segmentsend ACK
Immediately send single cumulative ACK ACKing both in-order segments
Immediately send duplicate ACK indicating seq of next expected byte
Immediate send ACK provided thatsegment startsat lower end of gap
Transport Layer 3-65
Fast Retransmit
Time-out period often relatively long
long delay before resending lost packet
Detect lost segments via duplicate ACKs
Sender often sends many segments back-to-backIf segment is lost there will likely be many duplicate ACKs
If sender receives 3 ACKs for the same data it supposes that segment after ACKeddata was lost
fast retransmit resend segment before timer expires
Transport Layer 3-66
Fast RetransmitResend a segment after 3 duplicate ACKs since a duplicate ACK means that an out-of sequence segment was receivedduplicate ACKs due to packet reorderingif window is small donrsquot get duplicate ACKs
Host A
tim
eout
Host B
time
X
resend seq X2
seq x1seq x2seq x3seq x4seq x5
ACK x1
ACK x1ACK x1ACK x1
tripleduplicate
ACKs
Transport Layer 3-67
event ACK received with ACK field value of y if (y gt SendBase)
SendBase = yif (there are currently not-yet-acknowledged segments)
start timer
else increment count of dup ACKs received for yif (count of dup ACKs received for y = 3)
resend segment with sequence number y
Fast retransmit algorithm
a duplicate ACK for already ACKed segment
fast retransmit
Transport Layer 3-68
TCP Flow Control
receive side of TCP connection has a receive buffer
speed-matching service matching the send rate to the receiving apprsquos drain rate
app process may be slow at reading from buffer
sender wonrsquot overflowreceiverrsquos buffer by
transmitting too muchtoo fast
flow control
Transport Layer 3-69
TCP Flow control how it works
(Suppose TCP receiver discards out-of-order segments)spare room in buffer
= RcvWin
= RcvBuffer-[LastByteRcvd -LastByteRead]
Rcvr advertises spare room by including value of RcvWin in segmentsSender limits unACKeddata to RcvWin
guarantees receive buffer doesnrsquot overflow
Transport Layer 3-70
Sliding Window Flow Control Example
3K
2K SeqNo=0
ReceiverBuffer
0 4KSendersends 2Kof data
2K
AckNo=2048 RcvWin=2048Sendersends 2Kof data 2K SeqNo=2048
4K
AckNo=4096 RcvWin=0
AckNo=4096 RcvWin=1024
Sender blocked
Transport Layer 3-71
Principles of Congestion Control
Congestioninformally ldquotoo many sources sending too much data too fast for network to handlerdquodifferent from flow controlmanifestations
lost packets (buffer overflow at routers)long delays (queueing in router buffers)
a top-10 problem
Transport Layer 3-72
Causescosts of congestion scenario 1
two senders two receiversone router infinite buffers no retransmission
large delays when congestedmaximum achievable throughput
unlimited shared output link buffers
Host Aλin original data
Host B
λout
Transport Layer 3-73
Causescosts of congestion scenario 2
one router finite buffers sender retransmission of lost packet
finite shared output link buffers
Host A λin original data
Host B
λout
λin original data plus retransmitted data
Transport Layer 3-74
Causescosts of congestion scenario 2always (goodput)ldquoperfectrdquo retransmission only when loss
retransmission of delayed (not lost) packet makes larger(than perfect case) for same
λin
λout=
λin
λoutgtλ
inλout
ldquocostsrdquo of congestionmore work (retrans) for given ldquogoodputrdquounneeded retransmissions link carries multiple copies of pkt
R2
R2λin
λ out
b
R2
R2λin
λ out
a
R2
R2λin
λ out
c
R4
R3
Transport Layer 3-75
Causescosts of congestion scenario 3four sendersmultihop pathstimeoutretransmit
λin
Q what happens as and increase λ
in
finite shared output link buffers
Host Aλin original data
Host B
λout
λin original data plus retransmitted data
Transport Layer 3-76
Causescosts of congestion scenario 3
another ldquocostrdquo of congestionwhen packet dropped any ldquoupstream transmission capacity used for that packet was wasted
Host A
Host B
λou
t
Transport Layer 3-77
Approaches towards congestion control
End-end congestion controlno explicit feedback from networkcongestion inferred from end-system observed loss delayapproach taken by TCP
Network-assisted congestion controlrouters provide feedback to end systems
single bit indicating congestion (SNA DECbit TCPIP ECN ATM)explicit rate sender should send at
Two broad approaches towards congestion control
Transport Layer 3-78
TCP Congestion Control
end-end control (no network assistance)sender limits transmissionLastByteSent-LastByteAcked
le CongWin
CongWin is dynamic function of perceived network congestion
How does sender perceive congestionloss event = timeout or3 duplicate acksTCP sender reduces rate (CongWin) after loss event
two modes of operationSlow Start (SS)Congestion avoidance (CA) or Additive Increase Multiplicative Decrease (AIMD)
Transport Layer 3-79
TCP congestion control bandwidth probing
ldquoprobing for bandwidthrdquo increase transmission rate on receipt of ACK until eventually loss occurs then decrease transmission rate
continue to increase on ACK decrease on loss (since available bandwidth is changing depending on other connections in network)
ACKs being received so increase rate
X
X
XX
X loss so decrease rate
send
ing
rate
time
Q how fast to increasedecreasedetails to follow
TCPrsquosldquosawtoothrdquobehavior
Transport Layer 3-80
TCP Congestion Control details
sender limits rate by limiting number of unACKed bytes ldquoin pipelinerdquo
cwnd differs from rwnd (how why)sender limited by min(cwndrwnd)
roughly
cwnd is dynamic function of perceived network congestion
rate = cwndRTT bytessec
LastByteSent-LastByteAcked le cwnd
cwndbytes
RTT
ACK(s)
Transport Layer 3-81
TCP Congestion Control more details
segment loss event reducing cwndtimeout no response from receiver
cut cwnd to 13 duplicate ACKs at least some segments getting through (recall fast retransmit)
cut cwnd in half less aggressively than on timeout
ACK received increase cwndTwo modes of operation
slowstart phase bull increase exponentially
fast (despite name) at connection start or following timeout
congestion avoidance bull increase linearly
Transport Layer 3-82
TCP Slow Start Phasewhen connection begins cwnd = 1 MSS
example MSS = 500 bytes amp RTT = 200 msecinitial rate = 20 kbps
available bandwidth may be gtgt MSSRTT
desirable to quickly ramp up to respectable rate
increase rate exponentially until first loss event or when threshold reached
double cwnd every RTTdone by incrementing cwnd by 1 for every ACK received
Host A
one segment
RTT
Host B
time
two segments
four segments
Transport Layer 3-83
Slow Start ExampleThe congestion window size grows very rapidly
For every ACK we increase CongWin by 1 irrespective of the number of segments ACKrsquoeddouble CongWinevery RTTinitial rate is slow but ramps up exponentially fast
TCP slows down the increase of CongWinwhen CongWin gt ssthresh
segment 1
ACK for segment 1
cwnd = 1
cwnd = 2 segment 2segment 3
ACK for segments 2
cwnd = 4 segment 4segment 5segment 6
ACK for segments 4
cwnd = 7
ACK for segments 3
ACK for segments 5
ACK for segments 6
cwnd = 3
cwnd = 5
cwnd = 6ACK for segments 7
cwnd = 8
segment 7
Transport Layer 3-84
TCP Congestion Avoidance Phase
when cwnd gt ssthreshgrow cwnd linearly
increase cwnd by 1 MSS per RTT approach possible congestion slower than in slowstartimplementation cwnd= cwnd + MSScwndfor each ACK received
ACKs increase cwndby 1 MSS per RTT additive increaseloss cut cwnd in half (non-timeout-detected loss ) multiplicative decrease
AIMD
AIMD Additive IncreaseMultiplicative Decrease
Transport Layer 3-85
Congestion AvoidanceCongestion avoidance phase is started if CongWin has reached the slow-start threshold value
If CongWin gt= ssthresh then each time an ACK is received increment CongWin as follows
bull CongWin = CongWin + 1CongWin (CongWin in segments)
bull In actual TCP implementation CongWin is in BytesCongWin = CongWin + MSS (MSSCongWin)
So CongWin is increased by one only if all CongWinsegments have been acknowledged
Transport Layer 3-86
Example Slow StartCongestion AvoidanceAssume that
ssthresh = 8
cwnd = 1
cwnd = 2
cwnd = 4
cwnd = 8
cwnd = 9
cwnd = 10
02468
101214
t=0
t=2
t=4
t=6
Roundtrip times
Cw
nd(in
seg
men
ts)
ssthresh
cwnd = 3
cwnd = 5cwnd = 6cwnd = 7
Transport Layer 3-87
Slow Start Congestion AvoidanceA typical plot of CongWin for a TCP connection
(MSS = 1500 bytes) with TCP Tahoe
SS
CA
ssthresh
Transport Layer 3-88
Responses to CongestionTCP assumes there is congestion if it detects a packet lossA TCP sender can detect lost packets via loss events
bull Timeout of a retransmission timerbull Receipt of 3 duplicate ACKs (fast retransmit)
TCP interprets a Timeout as a binary congestion signal When a timeout occurs the sender performs
ssthresh is set to half the current size of the congestion window
ssthresh = CongWin 2CongWin is reset to one
CongWin = 1and slow-start is entered
Transport Layer 3-89
Fast Recovery (differentiation btwn two loss events) After 3 dup ACKs (fast Retransmit)
ssthresh = CongWin2CongWin = CongWin2window then grows linearly
But after timeout eventCongWin = 1 MSS window then grows exponentiallyto the threshold then grows linearly
bull 3 dup ACKs indicates network capable of delivering some segmentsbull timeout before 3 dup ACKs is ldquomore alarmingrdquo
Philosophy
3-90
TCP Congestion ControlInitially
CongWin = 1ssthresh = advertised window size
New Ack receivedif (CongWin lt ssthresh) Slow Start
CongWin = CongWin + 1else Congestion Avoidance
CongWin = CongWin + 1CongWinTimeout
ssthresh = CongWin2CongWin = 1
Fast Retransmissionssthresh = CongWin2CongWin = CongWin2
Slow Start (exponential increase phase) is continued until CongWin reaches half of the level where the loss event occurred last time CongWin is increased slowly after (linear increase in Congestion Avoidance phase)
Transport Layer 3-91
Popular ldquoflavorsrdquo of TCP
ssthresh
ssthresh
TCP Tahoe
TCP Reno
Transmission round
cwnd
win
dow
siz
e (in
seg
men
ts)
Transport Layer 3-92
Summary TCP Congestion ControlWhen CongWin is below Threshold sender in slow-start phase window grows exponentiallyWhen CongWin is above Threshold sender is in congestion-avoidance phase window grows linearlyWhen a triple duplicate ACK occurs Threshold set to CongWin2 and CongWin set to ThresholdWhen timeout occurs Threshold set to CongWin2 and CongWin is set to 1 MSS The actual sender window size is determined based on the congestion and flow control algorithms
SenderWin=min(RcvWinCongWin)
Transport Layer 3-93
TCP Congestion Control SummaryEvent State TCP Sender Action Commentary
ACK receipt for previously unackeddata
Slow Start (SS)
CongWin = CongWin + MSS If (CongWin gt Threshold)
set state to ldquoCongestion Avoidancerdquo
Resulting in a doubling of CongWin every RTT
ACK receipt for previously unackeddata
CongestionAvoidance (CA)
CongWin = CongWin+MSS (MSSCongWin)
Additive increase resulting in increase of CongWin by 1 MSS every RTT
Loss event detected by triple duplicate ACK
SS or CA Threshold = CongWin2 CongWin = ThresholdSet state to ldquoCongestion Avoidancerdquo
Fast recovery implementing multiplicative decrease CongWin will not drop below 1 MSS
Timeout SS or CA Threshold = CongWin2 CongWin = 1 MSSSet state to ldquoSlow Startrdquo
Enter slow start
Duplicate ACK
SS or CA Increment duplicate ACK count for segment being acked
CongWin and Threshold not changed
Transport Layer 3-94
TCP throughput
Q whatrsquos average throughout of TCP as function of window size RTT
ignoring slow startlet W be window size when loss occurs
when window is W throughput is WRTTjust after loss window drops to W2 throughput to W2RTT average throughout 75 WRTT
Transport Layer 3-95
TCP Futures TCP over ldquolong fat pipesrdquo
example 1500 byte segments 100ms RTT want 10 Gbps throughputrequires window size W = 83333 in-flight segmentsthroughput in terms of loss rate
L = 210-10 Wownew versions of TCP for high-speed
LRTTMSSsdot221
Transport Layer 3-96
Fairness goal if K TCP sessions share same bottleneck link of bandwidth R each should have average rate of RK
TCP connection 1
bottleneckrouter
capacity R
TCP connection 2
TCP Fairness
Transport Layer 3-97
Why is TCP fairTwo competing sessions
Additive increase gives slope of 1 as throughout increasesmultiplicative decrease decreases throughput proportionally
R
R
equal bandwidth share
Connection 1 throughput
Conn
ecti
on 2
thr
ough
p ut
congestion avoidance additive increaseloss decrease window by factor of 2
congestion avoidance additive increaseloss decrease window by factor of 2
Transport Layer 3-98
Fairness (more)Fairness and UDP
Multimedia apps often do not use TCP
do not want rate throttled by congestion control
Instead use UDPpump audiovideo at constant rate tolerate packet loss
Research area TCP friendly
Fairness and parallel TCP connectionsnothing prevents app from opening parallel cnctionsbetween 2 hostsWeb browsers do this Example link of rate R supporting 9 cnctions
new app asks for 1 TCP gets rate R10new app asks for 11 TCPs gets R2
Transport Layer 3-99
TCP Connection ManagementRecall TCP sender receiver
establish ldquoconnectionrdquobefore exchanging data segmentsinitialize TCP variables
seq sbuffers flow control info (eg RcvWindow)
client connection initiatorSocket clientSocket = new Socket(hostnameport
number)
server contacted by clientSocket connectionSocket = welcomeSocketaccept()
Three way handshakeStep 1 client host sends TCP
SYN segment to serverspecifies initial seq no data
Step 2 server host receives SYN replies with SYNACK segment
server allocates buffersspecifies server initial seq
Step 3 client receives SYNACK replies with ACK segment which may contain data
Transport Layer 3-100
TCP Connection Management (cont)
Closing a connection
client closes socketclientSocketclose()
Step 1 client end system sends TCP FIN control segment to server
Step 2 server receives FIN replies with ACK Closes connection sends FIN
client
FIN
server
ACK
ACK
FIN
close
close
closed
tim
ed w
ait
Transport Layer 3-101
TCP Connection Management (cont)
Step 3 client receives FIN replies with ACK
Enters ldquotimed waitrdquo -will respond with ACK to received FINs
Step 4 server receives ACK Connection closed
client
FIN
server
ACK
ACK
FIN
closing
closing
closed
tim
ed w
ait
closed
Transport Layer 3-102
TCP Connection Management (cont)
TCP clientlifecycle
TCP serverlifecycle
Transport Layer 3-103
Tuning TCPIP Parameters TCPIP parameters
A set of default values may not be optimal for all applicationsThe network administrator may wish to turn on or off some TCPIP functions for performance or security considerations
Many Unix and Linux systems provide some flexibility in tuning the TCPIP kernelsbinsysctl is used to configure the Linux kernel parameters at runtime
Default kernel configuration file is sbinsysctlconfFrequently used sysctl options
bull sysctl ndasha or sysctl ndashA list all current valuesbull sysctl ndashp file_name load the sysctl setting from a configuration
filebull sysctl ndashw variable=value change the value of the parameter
Transport Layer 3-104
SomeTCP Parameters in Linux Kerneltcp_syn_retries
Number of SYN packets the kernel will send before giving up on the new connection
tcp_synack_retriesnumber of SYN+ACK packets sent before the kernel gives up on the connection
tcp_window_scalingMaximum window size of 65535 bytes not enough for for really fast networks The window scaling options allows for almost gigabyte windows which is good for connections with large delay-bandwidth product
tcp_max_syn_backlogMaximal number of remembered connection requests which still did not receive an acknowledgment from connecting client
tcp_fin_timeoutHow many seconds to wait for a final FIN packet before the socket is closed required to prevent denial-of-service (DoS) attacks Default value is 60 seconds
Transport Layer 3-105
SomeTCP Parameters in Linux Kerneltcp_rmem
This is a vector of 3 integers [min default max] These parameters are used by TCP to dynamically adjust receive buffer sizesmin - minimum size of the receive buffer used by each TCP socket The default value is 4K default - the default size of the receive buffer for a TCP socket The default value is 87380 bytes and is lowered to 43689 in low memory systems If larger receive buffer sizes are desired this value should be increased max - the maximum size of the receive buffer used by each TCP socket The default value of 873802 bytes is lowered to 87380 in low memory systems
tcp_smemSend buffer parameters [min default max] similar to tcp_rmem
- Chapter 3 Transport Layer
- Transport services and protocols
- Transport vs network layer
- Internet transport-layer protocols
- Multiplexingdemultiplexing
- How demultiplexing works
- Connectionless demultiplexing
- Connection-oriented demux
- Connection-oriented demux (cont)
- Connection-oriented demux Threaded Web Server
- UDP User Datagram Protocol [RFC 768]
- UDP more
- UDP checksum
- Principles of Reliable data transfer
- Reliable data transfer getting started
- Reliable data transfer getting started
- Rdt10 reliable transfer over a reliable channel
- Rdt20 channel with bit errors
- rdt20 FSM specification
- rdt20 operation with no errors
- rdt20 error scenario
- rdt20 has a fatal flaw
- rdt21 sender handles garbled ACKNAKs
- rdt21 receiver handles garbled ACKNAKs
- rdt21 discussion
- rdt22 a NAK-free protocol
- rdt22 sender receiver fragments
- rdt30 channels with errors and loss
- rdt30 sender
- rdt30 in action
- rdt30 in action
- Performance of rdt30
- rdt30 stop-and-wait operation
- Pipelined protocols
- Pipelining increased utilization
- Go-Back-N
- GBN sender extended FSM
- GBN receiver extended FSM
- GBN inaction
- Selective Repeat
- Selective repeat sender receiver windows
- Selective repeat
- Selective repeat in action
- Selective repeat dilemma
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- TCP Overview RFCs 793 1122 1323 2018 2581
- TCP segment structure
- TCP seq rsquos and ACKs
- TCP Round Trip Time and Timeout
- TCP Round Trip Time and Timeout
- Example RTT estimation
- TCP Round Trip Time and Timeout
- TCP reliable data transfer
- TCP sender events
- TCP sender(simplified)
- TCP retransmission scenarios
- TCP retransmission scenarios (more)
- TCP ACK generation [RFC 1122 RFC 2581]
- Fast Retransmit
- Fast Retransmit
- Fast retransmit algorithm
- TCP Flow Control
- TCP Flow control how it works
- Sliding Window Flow Control Example
- Principles of Congestion Control
- Causescosts of congestion scenario 1
- Causescosts of congestion scenario 2
- Causescosts of congestion scenario 2
- Causescosts of congestion scenario 3
- Causescosts of congestion scenario 3
- Approaches towards congestion control
- TCP Congestion Control
- TCP congestion control bandwidth probing
- TCP Congestion Control details
- TCP Congestion Control more details
- TCP Slow Start Phase
- Slow Start Example
- TCP Congestion Avoidance Phase
- Congestion Avoidance
- Example Slow StartCongestion Avoidance
- Slow Start Congestion Avoidance
- Responses to Congestion
- Fast Recovery (differentiation btwn two loss events)
- TCP Congestion Control
- Popular ldquoflavorsrdquo of TCP
- Summary TCP Congestion Control
- TCP Congestion Control Summary
- TCP throughput
- TCP Futures TCP over ldquolong fat pipesrdquo
- TCP Fairness
- Why is TCP fair
- Fairness (more)
- TCP Connection Management
- TCP Connection Management (cont)
- TCP Connection Management (cont)
- TCP Connection Management (cont)
- Tuning TCPIP Parameters
- SomeTCP Parameters in Linux Kernel
- SomeTCP Parameters in Linux Kernel
-
Transport Layer 3-21
rdt20 error scenario
Wait for call from above
snkpkt = make_pkt(data checksum)udt_send(sndpkt)
extract(rcvpktdata)deliver_data(data)udt_send(ACK)
rdt_rcv(rcvpkt) ampamp notcorrupt(rcvpkt)
rdt_rcv(rcvpkt) ampamp isACK(rcvpkt)
udt_send(sndpkt)
rdt_rcv(rcvpkt) ampampisNAK(rcvpkt)
udt_send(NAK)
rdt_rcv(rcvpkt) ampamp corrupt(rcvpkt)
Wait for ACK or
NAK
Wait for call from
below
rdt_send(data)
Λ
Transport Layer 3-22
rdt20 has a fatal flaw
What happens if ACKNAK corruptedsender doesnrsquot know what happened at receivercanrsquot just retransmit possible duplicate
What to dosender ACKsNAKs receiverrsquos ACKNAK What if sender ACKNAK lostretransmit but this might cause retransmission of correctly received pkt
Handling duplicates sender adds sequence number to each pktsender retransmits current pkt if ACKNAK garbledreceiver discards (doesnrsquot deliver up) duplicate pkt
Sender sends one packet then waits for receiver response
stop and wait
Transport Layer 3-23
rdt21 sender handles garbled ACKNAKs
Wait for call 0 from
above
sndpkt = make_pkt(0 data checksum)udt_send(sndpkt)
rdt_send(data)
Wait for ACK or NAK 0 udt_send(sndpkt)
rdt_rcv(rcvpkt) ampamp ( corrupt(rcvpkt) ||isNAK(rcvpkt) )
sndpkt = make_pkt(1 data checksum)udt_send(sndpkt)
rdt_send(data)
rdt_rcv(rcvpkt) ampamp notcorrupt(rcvpkt) ampamp isACK(rcvpkt)
udt_send(sndpkt)
rdt_rcv(rcvpkt) ampamp ( corrupt(rcvpkt) ||isNAK(rcvpkt) )
rdt_rcv(rcvpkt) ampamp notcorrupt(rcvpkt) ampamp isACK(rcvpkt)
Wait forcall 1 from
above
Wait for ACK or NAK 1
ΛΛ
Transport Layer 3-24
rdt21 receiver handles garbled ACKNAKs
Wait for 0 from below
sndpkt = make_pkt(NAK chksum)udt_send(sndpkt)
rdt_rcv(rcvpkt) ampamp not corrupt(rcvpkt) ampamphas_seq0(rcvpkt)
rdt_rcv(rcvpkt) ampamp notcorrupt(rcvpkt) ampamp has_seq1(rcvpkt)
extract(rcvpktdata)deliver_data(data)sndpkt = make_pkt(ACK chksum)udt_send(sndpkt)
Wait for 1 from below
rdt_rcv(rcvpkt) ampamp notcorrupt(rcvpkt) ampamp has_seq0(rcvpkt)
extract(rcvpktdata)deliver_data(data)sndpkt = make_pkt(ACK chksum)udt_send(sndpkt)
rdt_rcv(rcvpkt) ampamp (corrupt(rcvpkt)
sndpkt = make_pkt(ACK chksum)udt_send(sndpkt)
rdt_rcv(rcvpkt) ampamp not corrupt(rcvpkt) ampamphas_seq1(rcvpkt)
rdt_rcv(rcvpkt) ampamp (corrupt(rcvpkt)
sndpkt = make_pkt(ACK chksum)udt_send(sndpkt)
sndpkt = make_pkt(NAK chksum)udt_send(sndpkt)
Transport Layer 3-25
rdt21 discussion
Senderseq added to pkttwo seq rsquos (01) will suffice Whymust check if received ACKNAK corrupted twice as many states
state must ldquorememberrdquowhether ldquocurrentrdquo pkt has 0 or 1 seq
Receivermust check if received packet is duplicate
state indicates whether 0 or 1 is expected pkt seq
note receiver can notknow if its last ACKNAK received OK at sender
Transport Layer 3-26
rdt22 a NAK-free protocol
same functionality as rdt21 using ACKs onlyinstead of NAK receiver sends ACK for last pkt received OK
receiver must explicitly include seq of pkt being ACKed duplicate ACK at sender results in same action as NAK retransmit current pkt
Transport Layer 3-27
rdt22 sender receiver fragments
Wait for call 0 from
above
sndpkt = make_pkt(0 data checksum)udt_send(sndpkt)
rdt_send(data)
udt_send(sndpkt)
rdt_rcv(rcvpkt) ampamp ( corrupt(rcvpkt) ||
isACK(rcvpkt1) )
rdt_rcv(rcvpkt) ampamp notcorrupt(rcvpkt) ampamp isACK(rcvpkt0)
Wait for ACK
0sender FSM
fragment
Wait for 0 from below
rdt_rcv(rcvpkt) ampamp notcorrupt(rcvpkt) ampamp has_seq1(rcvpkt)
extract(rcvpktdata)deliver_data(data)sndpkt = make_pkt(ACK1 chksum)udt_send(sndpkt)
rdt_rcv(rcvpkt) ampamp (corrupt(rcvpkt) ||
has_seq1(rcvpkt))
udt_send(sndpkt)receiver FSM
fragment
Λ
Transport Layer 3-28
rdt30 channels with errors and loss
New assumptionunderlying channel can also lose packets (data or ACKs)
checksum seq ACKs retransmissions will be of help but not enough
Q how to deal with losssender waits until certain data or ACK lost then retransmitsdrawbacks
Approach sender waits ldquoreasonablerdquo amount of time for ACK retransmits if no ACK received in this timeif pkt (or ACK) just delayed (not lost)
retransmission will be duplicate but use of seq rsquos already handles thisreceiver must specify seq of pkt being ACKed
requires countdown timer
Transport Layer 3-29
rdt30 sendersndpkt = make_pkt(0 data checksum)udt_send(sndpkt)start_timer
rdt_send(data)
Wait for
ACK0
rdt_rcv(rcvpkt) ampamp ( corrupt(rcvpkt) ||isACK(rcvpkt1) )
Wait for call 1 from
above
sndpkt = make_pkt(1 data checksum)udt_send(sndpkt)start_timer
rdt_send(data)
rdt_rcv(rcvpkt) ampamp notcorrupt(rcvpkt) ampamp isACK(rcvpkt0)
rdt_rcv(rcvpkt) ampamp ( corrupt(rcvpkt) ||isACK(rcvpkt0) )
rdt_rcv(rcvpkt) ampamp notcorrupt(rcvpkt) ampamp isACK(rcvpkt1)
stop_timerstop_timer
udt_send(sndpkt)start_timer
timeout
udt_send(sndpkt)start_timer
timeout
rdt_rcv(rcvpkt)
Wait for call 0from
above
Wait for
ACK1
Λrdt_rcv(rcvpkt)
ΛΛ
Λ
Transport Layer 3-30
rdt30 in action
Transport Layer 3-31
rdt30 in action
Transport Layer 3-32
Performance of rdt30
rdt30 works but performance stinksexample 1 Gbps link 15 ms e-e prop delay 1KB packet
Ttransmit = 8kbpkt109 bsec = 8 microsec
U sender utilization ndash fraction of time sender busy sending1KB pkt every 30 msec -gt 33kBsec thruput over 1 Gbps linknetwork protocol limits use of physical resources
U sender=
008 30008
= 000027 L RRTT + L R
=
L (packet length in bits)R (transmission rate bps) =
Transport Layer 3-33
rdt30 stop-and-wait operation
first packet bit transmitted t = 0
sender receiver
RTT
last packet bit transmitted t = L R
first packet bit arriveslast packet bit arrives send ACK
ACK arrives send next packet t = RTT + L R
U sender=
00830008
= 000027 L RRTT + L R
=
Transport Layer 3-34
Pipelined protocolsPipelining sender allows multiple ldquoin-flightrdquo yet-to-
be-acknowledged pktsrange of sequence numbers must be increasedbuffering at sender andor receiver
Two generic forms of pipelined protocols go-Back-N selective repeat
Transport Layer 3-35
Pipelining increased utilization
first packet bit transmitted t = 0
sender receiver
RTT
last bit transmitted t = L R
first packet bit arriveslast packet bit arrives send ACK
ACK arrives send next packet t = RTT + L R
last bit of 2nd packet arrives send ACKlast bit of 3rd packet arrives send ACK
U sender=
024 30008
= 000083 L RRTT + L R
=
Increase utilizationby a factor of 3
Transport Layer 3-36
Utilization=N(LR)(RTT+LR) if NLRltRTT+LR Utilization=1 if and the sender pauses after it transmits a window NLRgtRTT+LR and the of packets until it receives first ACK sender does not pause
Transport Layer 3-37
Go-Back-NSender
k-bit seq in pkt headerldquowindowrdquo of up to N consecutive unackrsquoed pkts allowed
ACK(n) ACKs all pkts up to including seq n - ldquocumulative ACKrdquomay receive duplicate ACKs (see receiver)
timer for the entire windowtimeout(n) retransmit pkt n and all higher seq pkts in window
Transport Layer 3-38
GBN sender extended FSM
Wait start_timerudt_send(sndpkt[base])udt_send(sndpkt[base+1])hellipudt_send(sndpkt[nextseqnum-1])
timeout
rdt_send(data)
if (nextseqnum lt base+N) sndpkt[nextseqnum] = make_pkt(nextseqnumdatachksum)udt_send(sndpkt[nextseqnum])if (base == nextseqnum)
start_timernextseqnum++
elserefuse_data(data)
base = getacknum(rcvpkt)+1If (base == nextseqnum)
stop_timerelse
start_timer
rdt_rcv(rcvpkt) ampamp notcorrupt(rcvpkt)
base=1nextseqnum=1
rdt_rcv(rcvpkt) ampamp corrupt(rcvpkt)
Λ
Λ
Transport Layer 3-39
GBN receiver extended FSM
ACK-only always send ACK for correctly-received pktwith highest in-order seq
may generate duplicate ACKsneed only remember expectedseqnum
out-of-order pkt discard (donrsquot buffer) -gt no receiver bufferingRe-ACK pkt with highest in-order seq
Wait
udt_send(sndpkt)default
rdt_rcv(rcvpkt)ampamp notcurrupt(rcvpkt)ampamp hasseqnum(rcvpktexpectedseqnum)
extract(rcvpktdata)deliver_data(data)sndpkt = make_pkt(expectedseqnumACKchksum)udt_send(sndpkt)expectedseqnum++
expectedseqnum=1sndpkt =
make_pkt(0ACKchksum)
Λ
Transport Layer 3-40
GBN inaction
Transport Layer 3-41
Selective Repeat
receiver individually acknowledges all correctly received pkts
buffers pkts as needed for eventual in-order delivery to upper layer
sender only resends pkts for which ACK not received
sender timer for each unACKed pktsender window
N consecutive seq rsquosagain limits seq s of sent unACKed pkts
Transport Layer 3-42
Selective repeat sender receiver windows
Transport Layer 3-43
Selective repeat
data from above if next available seq in window send pkt
timeout(n)resend pkt n restart timer
ACK(n) in [sendbasesendbase+N-1]
mark pkt n as receivedif n smallest unACKed pkt advance window base to next unACKed seq
senderpkt n in [rcvbase rcvbase+N-1]
send ACK(n)out-of-order bufferin-order deliver (also deliver buffered in-order pkts) advance window to next not-yet-received pkt
pkt n in [rcvbase-Nrcvbase-1]
ACK(n)otherwise
ignore
receiver
Transport Layer 3-44
Selective repeat in action
Transport Layer 3-45
Selective repeatdilemma
Example seq rsquos 0 1 2 3window size=3
receiver sees no difference in two scenariosincorrectly passes duplicate data as new in (a)
Q what relationship between seq size and window size
Transport Layer 3-46
Sequence Number vs Window SizeSuppose we use k bits to represent SNQuestion Whatrsquos the minimum number of bits k necessary for a window size of N
sender
receiver
Go-Back-N
expectedSN
snd_base=expectedSN
Q For a given expectedSN whatrsquos the largest possible value for snd_baseA If all the last N ACKs sent by the receiver are received
snd_base = expectedSNexpectedSN+N-1
senderrsquos window
Transport Layer 3-47
Sequence Number vs Window SizeSuppose we use k bits to represent SNQuestion Whatrsquos the minimum number of bits k necessary for a window size of N
sender
receiver
Go-Back-N
expectedSN
snd_base=expectedSN-N
Q For a given expectedSN whatrsquos the smallest possible value for snd_baseA If all the last N ACKs sent by the receiver are not received
snd_base = expectedSN-NexpectedSN-1
senderrsquos window
Transport Layer 3-48
Sequence Number vs Window Size
sender
receiver
Go-Back-N
expectedSN
snd_base=expectedSN-N
All SNs in the interval [expectedSN-NexpectedSN+N-1] (an interval of size 2N) can be received by the receiver Since the receiver accepts on the packet with SN=expectedSN there should be no other packet within this interval with SN=expectedSN Therefore
2k ge N+1expectedSN+N-1
Transport Layer 3-49
Sequence Number vs Window SizeSuppose we use k bits to represent SNQuestion Whatrsquos the minimum number of bits k necessary for a window size of N
sender
receiver
Selective Repeat
rcv_base
snd_base=rcv_base
Q For a given rcv_base whatrsquos the largest possible value for snd_baseA If all the last N ACKs sent by the receiver are received
snd_base = rcv_base (same as go_back-N)rcv_base+N-1
senderrsquos window
receiverrsquos window
rcv_base+N-1
Transport Layer 3-50
Sequence Number vs Window SizeSuppose we use k bits to represent SNQuestion Whatrsquos the minimum number of bits k necessary for a window size of N
sender
receiver
Selective Repeat
rcv_base
snd_base=rcv_base-N
Q For a given rcv_base whatrsquos the smallest possible value for snd_baseA If all the last N ACKs sent by the receiver are not received
snd_base = rcv_base-N (same as Go-Back-N)rcv_base-1
senderrsquos window
rcv_base
receiverrsquos window
rcv_base+N-1
Transport Layer 3-51
Sequence Number vs Window Size
sender
receiver
Selective Repeat
snd_base=rcv_base-N
All SNs in the interval [rcv_base-Nrcv_base+N-1] (an interval of size 2N) can be received by the receiver Since the receiver should be able to distinguish between all packets in this interval and take corresponding action there should be no two packets within thisinterval having the same SN Therefore
2k ge 2Nrcv_base+N-1
rcv_basercv_base
receiverrsquos window
rcv_base+N-1
Transport Layer 3-52
TCP Overview RFCs 793 1122 1323 2018 2581
full duplex databi-directional data flow in same connectionMSS maximum segment size
connection-orientedhandshaking (exchange of control msgs) initrsquossender receiver state before data exchange
flow controlledsender will not overwhelm receiver
point-to-pointone sender one receiver
reliable in-order byte stream
no ldquomessage boundariesrdquopipelined
TCP congestion and flow control set window size
send amp receive buffers
socketdoor
TCPsend buffer
TCPreceive buffer
socketdoor
segment
applicationwrites data
applicationreads data
Transport Layer 3-53
TCP segment structure
source port dest port
32 bits
applicationdata
(variable length)
sequence numberacknowledgement number
Receive windowUrg data pnterchecksum
FSRPAUheadlen
notused
Options (variable length)
URG urgent data (generally not used)
ACK ACK valid
PSH push data now(generally not used)
RST SYN FINconnection estab(setup teardown
commands)
bytes rcvr willingto accept
Internetchecksum
(as in UDP)
countingby bytes of data(not segments)
Transport Layer 3-54
TCP seq rsquos and ACKsSeq rsquos
byte stream ldquonumberrdquo of first byte in segmentrsquos dataACKs
seq of next byte expected from other sidecumulative ACK
Q how receiver handles out-of-order segmentsA TCP spec doesnrsquot say - up to implementationWidely used implementations of TCP buffer out-of-order segments
Transport Layer 3-55
TCP Round Trip Time and Timeout
Q how to set TCP timeout valuelonger than RTT
but RTT variestoo short premature timeout
unnecessary retransmissions
too long slow reaction to segment loss
Q how to estimate RTTSampleRTT measured time from segment transmission until ACK receipt
ignore retransmissionsSampleRTT will vary want estimated RTT ldquosmootherrdquo
average several recent measurements not just current SampleRTT
Transport Layer 3-56
TCP Round Trip Time and Timeout
EstimatedRTT = (1- α)EstimatedRTT + αSampleRTT
Exponential weighted moving averageinfluence of past sample decreases exponentially fasttypical value α = 0125
Transport Layer 3-57
Example RTT estimationRTT gaiacsumassedu to fantasiaeurecomfr
100
150
200
250
300
350
1 8 15 22 29 36 43 50 57 64 71 78 85 92 99 106
time (seconnds)
RTT
(mill
iseco
nds)
SampleRTT Estimated RTT
Transport Layer 3-58
TCP Round Trip Time and TimeoutSetting the timeout
EstimatedRTT plus ldquosafety marginrdquolarge variation in EstimatedRTT -gt larger safety margin
first estimate of how much SampleRTT deviates from EstimatedRTT
TimeoutInterval = EstimatedRTT + 4DevRTT
DevRTT = (1-β)DevRTT +β|SampleRTT-EstimatedRTT|
(typically β = 025)
Then set timeout interval
Transport Layer 3-59
TCP reliable data transfer
TCP creates rdtservice on top of IPrsquos unreliable servicePipelined segmentsCumulative acksTCP uses single retransmission timer however it just retransmits the first segment in the window
Retransmissions are triggered by
timeout eventsduplicate acks
Initially consider simplified TCP sender
ignore duplicate acksignore flow control congestion control
Transport Layer 3-60
TCP sender eventsdata rcvd from app
Create segment with seq seq is byte-stream number of first data byte in segmentstart timer if not already running (think of timer as for oldest unacked segment)expiration interval TimeOutInterval
timeoutretransmit segment that caused timeout (first segment in the window)restart timer
Ack rcvdIf acknowledges previously unacked segments
update what is known to be ackedstart timer if there are outstanding segments
Transport Layer 3-61
TCP sender(simplified)
NextSeqNum = InitialSeqNumSendBase = InitialSeqNum
loop (forever) switch(event)
event data received from application above create TCP segment with sequence number NextSeqNumif (timer currently not running)
start timerpass segment to IP NextSeqNum = NextSeqNum + length(data)
event timer timeoutretransmit not-yet-acknowledged segment with
smallest sequence numberstart timer
event ACK received with ACK field value of y if (y gt SendBase)
SendBase = yif (there are currently not-yet-acknowledged segments)
start timer
end of loop forever
Commentbull SendBase-1 last cumulatively ackrsquoed byteExamplebull SendBase-1 = 71y= 73 so the rcvrwants 73+ y gt SendBase sothat new data is acked
Transport Layer 3-62
TCP retransmission scenariosHost A
Seq=100 20 bytes data
ACK=100
timepremature timeout
Host B
Seq=92 8 bytes data
ACK=120
Seq=92 8 bytes data
Seq=
92 t
imeo
ut
ACK=120
Host A
Seq=92 8 bytes data
ACK=100
loss
tim
eout
lost ACK scenario
Host B
X
Seq=92 8 bytes data
ACK=100
time
Seq=
92 t
imeo
utSendBase
= 100
SendBase= 120
SendBase= 120
Sendbase= 100
Transport Layer 3-63
TCP retransmission scenarios (more)Host A
Seq=92 8 bytes data
ACK=100
loss
tim
eout
Cumulative ACK scenario
Host B
X
Seq=100 20 bytes data
ACK=120
time
SendBase= 120
Transport Layer 3-64
TCP ACK generation [RFC 1122 RFC 2581]
Event at Receiver
Arrival of in-order segment withexpected seq All data up toexpected seq already ACKed
Arrival of in-order segment withexpected seq One other segment has ACK pending
Arrival of out-of-order segmenthigher-than-expect seq Gap detected
Arrival of segment that partially or completely fills gap
TCP Receiver action
Delayed ACK Wait up to 500msfor next segment If no next segmentsend ACK
Immediately send single cumulative ACK ACKing both in-order segments
Immediately send duplicate ACK indicating seq of next expected byte
Immediate send ACK provided thatsegment startsat lower end of gap
Transport Layer 3-65
Fast Retransmit
Time-out period often relatively long
long delay before resending lost packet
Detect lost segments via duplicate ACKs
Sender often sends many segments back-to-backIf segment is lost there will likely be many duplicate ACKs
If sender receives 3 ACKs for the same data it supposes that segment after ACKeddata was lost
fast retransmit resend segment before timer expires
Transport Layer 3-66
Fast RetransmitResend a segment after 3 duplicate ACKs since a duplicate ACK means that an out-of sequence segment was receivedduplicate ACKs due to packet reorderingif window is small donrsquot get duplicate ACKs
Host A
tim
eout
Host B
time
X
resend seq X2
seq x1seq x2seq x3seq x4seq x5
ACK x1
ACK x1ACK x1ACK x1
tripleduplicate
ACKs
Transport Layer 3-67
event ACK received with ACK field value of y if (y gt SendBase)
SendBase = yif (there are currently not-yet-acknowledged segments)
start timer
else increment count of dup ACKs received for yif (count of dup ACKs received for y = 3)
resend segment with sequence number y
Fast retransmit algorithm
a duplicate ACK for already ACKed segment
fast retransmit
Transport Layer 3-68
TCP Flow Control
receive side of TCP connection has a receive buffer
speed-matching service matching the send rate to the receiving apprsquos drain rate
app process may be slow at reading from buffer
sender wonrsquot overflowreceiverrsquos buffer by
transmitting too muchtoo fast
flow control
Transport Layer 3-69
TCP Flow control how it works
(Suppose TCP receiver discards out-of-order segments)spare room in buffer
= RcvWin
= RcvBuffer-[LastByteRcvd -LastByteRead]
Rcvr advertises spare room by including value of RcvWin in segmentsSender limits unACKeddata to RcvWin
guarantees receive buffer doesnrsquot overflow
Transport Layer 3-70
Sliding Window Flow Control Example
3K
2K SeqNo=0
ReceiverBuffer
0 4KSendersends 2Kof data
2K
AckNo=2048 RcvWin=2048Sendersends 2Kof data 2K SeqNo=2048
4K
AckNo=4096 RcvWin=0
AckNo=4096 RcvWin=1024
Sender blocked
Transport Layer 3-71
Principles of Congestion Control
Congestioninformally ldquotoo many sources sending too much data too fast for network to handlerdquodifferent from flow controlmanifestations
lost packets (buffer overflow at routers)long delays (queueing in router buffers)
a top-10 problem
Transport Layer 3-72
Causescosts of congestion scenario 1
two senders two receiversone router infinite buffers no retransmission
large delays when congestedmaximum achievable throughput
unlimited shared output link buffers
Host Aλin original data
Host B
λout
Transport Layer 3-73
Causescosts of congestion scenario 2
one router finite buffers sender retransmission of lost packet
finite shared output link buffers
Host A λin original data
Host B
λout
λin original data plus retransmitted data
Transport Layer 3-74
Causescosts of congestion scenario 2always (goodput)ldquoperfectrdquo retransmission only when loss
retransmission of delayed (not lost) packet makes larger(than perfect case) for same
λin
λout=
λin
λoutgtλ
inλout
ldquocostsrdquo of congestionmore work (retrans) for given ldquogoodputrdquounneeded retransmissions link carries multiple copies of pkt
R2
R2λin
λ out
b
R2
R2λin
λ out
a
R2
R2λin
λ out
c
R4
R3
Transport Layer 3-75
Causescosts of congestion scenario 3four sendersmultihop pathstimeoutretransmit
λin
Q what happens as and increase λ
in
finite shared output link buffers
Host Aλin original data
Host B
λout
λin original data plus retransmitted data
Transport Layer 3-76
Causescosts of congestion scenario 3
another ldquocostrdquo of congestionwhen packet dropped any ldquoupstream transmission capacity used for that packet was wasted
Host A
Host B
λou
t
Transport Layer 3-77
Approaches towards congestion control
End-end congestion controlno explicit feedback from networkcongestion inferred from end-system observed loss delayapproach taken by TCP
Network-assisted congestion controlrouters provide feedback to end systems
single bit indicating congestion (SNA DECbit TCPIP ECN ATM)explicit rate sender should send at
Two broad approaches towards congestion control
Transport Layer 3-78
TCP Congestion Control
end-end control (no network assistance)sender limits transmissionLastByteSent-LastByteAcked
le CongWin
CongWin is dynamic function of perceived network congestion
How does sender perceive congestionloss event = timeout or3 duplicate acksTCP sender reduces rate (CongWin) after loss event
two modes of operationSlow Start (SS)Congestion avoidance (CA) or Additive Increase Multiplicative Decrease (AIMD)
Transport Layer 3-79
TCP congestion control bandwidth probing
ldquoprobing for bandwidthrdquo increase transmission rate on receipt of ACK until eventually loss occurs then decrease transmission rate
continue to increase on ACK decrease on loss (since available bandwidth is changing depending on other connections in network)
ACKs being received so increase rate
X
X
XX
X loss so decrease rate
send
ing
rate
time
Q how fast to increasedecreasedetails to follow
TCPrsquosldquosawtoothrdquobehavior
Transport Layer 3-80
TCP Congestion Control details
sender limits rate by limiting number of unACKed bytes ldquoin pipelinerdquo
cwnd differs from rwnd (how why)sender limited by min(cwndrwnd)
roughly
cwnd is dynamic function of perceived network congestion
rate = cwndRTT bytessec
LastByteSent-LastByteAcked le cwnd
cwndbytes
RTT
ACK(s)
Transport Layer 3-81
TCP Congestion Control more details
segment loss event reducing cwndtimeout no response from receiver
cut cwnd to 13 duplicate ACKs at least some segments getting through (recall fast retransmit)
cut cwnd in half less aggressively than on timeout
ACK received increase cwndTwo modes of operation
slowstart phase bull increase exponentially
fast (despite name) at connection start or following timeout
congestion avoidance bull increase linearly
Transport Layer 3-82
TCP Slow Start Phasewhen connection begins cwnd = 1 MSS
example MSS = 500 bytes amp RTT = 200 msecinitial rate = 20 kbps
available bandwidth may be gtgt MSSRTT
desirable to quickly ramp up to respectable rate
increase rate exponentially until first loss event or when threshold reached
double cwnd every RTTdone by incrementing cwnd by 1 for every ACK received
Host A
one segment
RTT
Host B
time
two segments
four segments
Transport Layer 3-83
Slow Start ExampleThe congestion window size grows very rapidly
For every ACK we increase CongWin by 1 irrespective of the number of segments ACKrsquoeddouble CongWinevery RTTinitial rate is slow but ramps up exponentially fast
TCP slows down the increase of CongWinwhen CongWin gt ssthresh
segment 1
ACK for segment 1
cwnd = 1
cwnd = 2 segment 2segment 3
ACK for segments 2
cwnd = 4 segment 4segment 5segment 6
ACK for segments 4
cwnd = 7
ACK for segments 3
ACK for segments 5
ACK for segments 6
cwnd = 3
cwnd = 5
cwnd = 6ACK for segments 7
cwnd = 8
segment 7
Transport Layer 3-84
TCP Congestion Avoidance Phase
when cwnd gt ssthreshgrow cwnd linearly
increase cwnd by 1 MSS per RTT approach possible congestion slower than in slowstartimplementation cwnd= cwnd + MSScwndfor each ACK received
ACKs increase cwndby 1 MSS per RTT additive increaseloss cut cwnd in half (non-timeout-detected loss ) multiplicative decrease
AIMD
AIMD Additive IncreaseMultiplicative Decrease
Transport Layer 3-85
Congestion AvoidanceCongestion avoidance phase is started if CongWin has reached the slow-start threshold value
If CongWin gt= ssthresh then each time an ACK is received increment CongWin as follows
bull CongWin = CongWin + 1CongWin (CongWin in segments)
bull In actual TCP implementation CongWin is in BytesCongWin = CongWin + MSS (MSSCongWin)
So CongWin is increased by one only if all CongWinsegments have been acknowledged
Transport Layer 3-86
Example Slow StartCongestion AvoidanceAssume that
ssthresh = 8
cwnd = 1
cwnd = 2
cwnd = 4
cwnd = 8
cwnd = 9
cwnd = 10
02468
101214
t=0
t=2
t=4
t=6
Roundtrip times
Cw
nd(in
seg
men
ts)
ssthresh
cwnd = 3
cwnd = 5cwnd = 6cwnd = 7
Transport Layer 3-87
Slow Start Congestion AvoidanceA typical plot of CongWin for a TCP connection
(MSS = 1500 bytes) with TCP Tahoe
SS
CA
ssthresh
Transport Layer 3-88
Responses to CongestionTCP assumes there is congestion if it detects a packet lossA TCP sender can detect lost packets via loss events
bull Timeout of a retransmission timerbull Receipt of 3 duplicate ACKs (fast retransmit)
TCP interprets a Timeout as a binary congestion signal When a timeout occurs the sender performs
ssthresh is set to half the current size of the congestion window
ssthresh = CongWin 2CongWin is reset to one
CongWin = 1and slow-start is entered
Transport Layer 3-89
Fast Recovery (differentiation btwn two loss events) After 3 dup ACKs (fast Retransmit)
ssthresh = CongWin2CongWin = CongWin2window then grows linearly
But after timeout eventCongWin = 1 MSS window then grows exponentiallyto the threshold then grows linearly
bull 3 dup ACKs indicates network capable of delivering some segmentsbull timeout before 3 dup ACKs is ldquomore alarmingrdquo
Philosophy
3-90
TCP Congestion ControlInitially
CongWin = 1ssthresh = advertised window size
New Ack receivedif (CongWin lt ssthresh) Slow Start
CongWin = CongWin + 1else Congestion Avoidance
CongWin = CongWin + 1CongWinTimeout
ssthresh = CongWin2CongWin = 1
Fast Retransmissionssthresh = CongWin2CongWin = CongWin2
Slow Start (exponential increase phase) is continued until CongWin reaches half of the level where the loss event occurred last time CongWin is increased slowly after (linear increase in Congestion Avoidance phase)
Transport Layer 3-91
Popular ldquoflavorsrdquo of TCP
ssthresh
ssthresh
TCP Tahoe
TCP Reno
Transmission round
cwnd
win
dow
siz
e (in
seg
men
ts)
Transport Layer 3-92
Summary TCP Congestion ControlWhen CongWin is below Threshold sender in slow-start phase window grows exponentiallyWhen CongWin is above Threshold sender is in congestion-avoidance phase window grows linearlyWhen a triple duplicate ACK occurs Threshold set to CongWin2 and CongWin set to ThresholdWhen timeout occurs Threshold set to CongWin2 and CongWin is set to 1 MSS The actual sender window size is determined based on the congestion and flow control algorithms
SenderWin=min(RcvWinCongWin)
Transport Layer 3-93
TCP Congestion Control SummaryEvent State TCP Sender Action Commentary
ACK receipt for previously unackeddata
Slow Start (SS)
CongWin = CongWin + MSS If (CongWin gt Threshold)
set state to ldquoCongestion Avoidancerdquo
Resulting in a doubling of CongWin every RTT
ACK receipt for previously unackeddata
CongestionAvoidance (CA)
CongWin = CongWin+MSS (MSSCongWin)
Additive increase resulting in increase of CongWin by 1 MSS every RTT
Loss event detected by triple duplicate ACK
SS or CA Threshold = CongWin2 CongWin = ThresholdSet state to ldquoCongestion Avoidancerdquo
Fast recovery implementing multiplicative decrease CongWin will not drop below 1 MSS
Timeout SS or CA Threshold = CongWin2 CongWin = 1 MSSSet state to ldquoSlow Startrdquo
Enter slow start
Duplicate ACK
SS or CA Increment duplicate ACK count for segment being acked
CongWin and Threshold not changed
Transport Layer 3-94
TCP throughput
Q whatrsquos average throughout of TCP as function of window size RTT
ignoring slow startlet W be window size when loss occurs
when window is W throughput is WRTTjust after loss window drops to W2 throughput to W2RTT average throughout 75 WRTT
Transport Layer 3-95
TCP Futures TCP over ldquolong fat pipesrdquo
example 1500 byte segments 100ms RTT want 10 Gbps throughputrequires window size W = 83333 in-flight segmentsthroughput in terms of loss rate
L = 210-10 Wownew versions of TCP for high-speed
LRTTMSSsdot221
Transport Layer 3-96
Fairness goal if K TCP sessions share same bottleneck link of bandwidth R each should have average rate of RK
TCP connection 1
bottleneckrouter
capacity R
TCP connection 2
TCP Fairness
Transport Layer 3-97
Why is TCP fairTwo competing sessions
Additive increase gives slope of 1 as throughout increasesmultiplicative decrease decreases throughput proportionally
R
R
equal bandwidth share
Connection 1 throughput
Conn
ecti
on 2
thr
ough
p ut
congestion avoidance additive increaseloss decrease window by factor of 2
congestion avoidance additive increaseloss decrease window by factor of 2
Transport Layer 3-98
Fairness (more)Fairness and UDP
Multimedia apps often do not use TCP
do not want rate throttled by congestion control
Instead use UDPpump audiovideo at constant rate tolerate packet loss
Research area TCP friendly
Fairness and parallel TCP connectionsnothing prevents app from opening parallel cnctionsbetween 2 hostsWeb browsers do this Example link of rate R supporting 9 cnctions
new app asks for 1 TCP gets rate R10new app asks for 11 TCPs gets R2
Transport Layer 3-99
TCP Connection ManagementRecall TCP sender receiver
establish ldquoconnectionrdquobefore exchanging data segmentsinitialize TCP variables
seq sbuffers flow control info (eg RcvWindow)
client connection initiatorSocket clientSocket = new Socket(hostnameport
number)
server contacted by clientSocket connectionSocket = welcomeSocketaccept()
Three way handshakeStep 1 client host sends TCP
SYN segment to serverspecifies initial seq no data
Step 2 server host receives SYN replies with SYNACK segment
server allocates buffersspecifies server initial seq
Step 3 client receives SYNACK replies with ACK segment which may contain data
Transport Layer 3-100
TCP Connection Management (cont)
Closing a connection
client closes socketclientSocketclose()
Step 1 client end system sends TCP FIN control segment to server
Step 2 server receives FIN replies with ACK Closes connection sends FIN
client
FIN
server
ACK
ACK
FIN
close
close
closed
tim
ed w
ait
Transport Layer 3-101
TCP Connection Management (cont)
Step 3 client receives FIN replies with ACK
Enters ldquotimed waitrdquo -will respond with ACK to received FINs
Step 4 server receives ACK Connection closed
client
FIN
server
ACK
ACK
FIN
closing
closing
closed
tim
ed w
ait
closed
Transport Layer 3-102
TCP Connection Management (cont)
TCP clientlifecycle
TCP serverlifecycle
Transport Layer 3-103
Tuning TCPIP Parameters TCPIP parameters
A set of default values may not be optimal for all applicationsThe network administrator may wish to turn on or off some TCPIP functions for performance or security considerations
Many Unix and Linux systems provide some flexibility in tuning the TCPIP kernelsbinsysctl is used to configure the Linux kernel parameters at runtime
Default kernel configuration file is sbinsysctlconfFrequently used sysctl options
bull sysctl ndasha or sysctl ndashA list all current valuesbull sysctl ndashp file_name load the sysctl setting from a configuration
filebull sysctl ndashw variable=value change the value of the parameter
Transport Layer 3-104
SomeTCP Parameters in Linux Kerneltcp_syn_retries
Number of SYN packets the kernel will send before giving up on the new connection
tcp_synack_retriesnumber of SYN+ACK packets sent before the kernel gives up on the connection
tcp_window_scalingMaximum window size of 65535 bytes not enough for for really fast networks The window scaling options allows for almost gigabyte windows which is good for connections with large delay-bandwidth product
tcp_max_syn_backlogMaximal number of remembered connection requests which still did not receive an acknowledgment from connecting client
tcp_fin_timeoutHow many seconds to wait for a final FIN packet before the socket is closed required to prevent denial-of-service (DoS) attacks Default value is 60 seconds
Transport Layer 3-105
SomeTCP Parameters in Linux Kerneltcp_rmem
This is a vector of 3 integers [min default max] These parameters are used by TCP to dynamically adjust receive buffer sizesmin - minimum size of the receive buffer used by each TCP socket The default value is 4K default - the default size of the receive buffer for a TCP socket The default value is 87380 bytes and is lowered to 43689 in low memory systems If larger receive buffer sizes are desired this value should be increased max - the maximum size of the receive buffer used by each TCP socket The default value of 873802 bytes is lowered to 87380 in low memory systems
tcp_smemSend buffer parameters [min default max] similar to tcp_rmem
- Chapter 3 Transport Layer
- Transport services and protocols
- Transport vs network layer
- Internet transport-layer protocols
- Multiplexingdemultiplexing
- How demultiplexing works
- Connectionless demultiplexing
- Connection-oriented demux
- Connection-oriented demux (cont)
- Connection-oriented demux Threaded Web Server
- UDP User Datagram Protocol [RFC 768]
- UDP more
- UDP checksum
- Principles of Reliable data transfer
- Reliable data transfer getting started
- Reliable data transfer getting started
- Rdt10 reliable transfer over a reliable channel
- Rdt20 channel with bit errors
- rdt20 FSM specification
- rdt20 operation with no errors
- rdt20 error scenario
- rdt20 has a fatal flaw
- rdt21 sender handles garbled ACKNAKs
- rdt21 receiver handles garbled ACKNAKs
- rdt21 discussion
- rdt22 a NAK-free protocol
- rdt22 sender receiver fragments
- rdt30 channels with errors and loss
- rdt30 sender
- rdt30 in action
- rdt30 in action
- Performance of rdt30
- rdt30 stop-and-wait operation
- Pipelined protocols
- Pipelining increased utilization
- Go-Back-N
- GBN sender extended FSM
- GBN receiver extended FSM
- GBN inaction
- Selective Repeat
- Selective repeat sender receiver windows
- Selective repeat
- Selective repeat in action
- Selective repeat dilemma
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- TCP Overview RFCs 793 1122 1323 2018 2581
- TCP segment structure
- TCP seq rsquos and ACKs
- TCP Round Trip Time and Timeout
- TCP Round Trip Time and Timeout
- Example RTT estimation
- TCP Round Trip Time and Timeout
- TCP reliable data transfer
- TCP sender events
- TCP sender(simplified)
- TCP retransmission scenarios
- TCP retransmission scenarios (more)
- TCP ACK generation [RFC 1122 RFC 2581]
- Fast Retransmit
- Fast Retransmit
- Fast retransmit algorithm
- TCP Flow Control
- TCP Flow control how it works
- Sliding Window Flow Control Example
- Principles of Congestion Control
- Causescosts of congestion scenario 1
- Causescosts of congestion scenario 2
- Causescosts of congestion scenario 2
- Causescosts of congestion scenario 3
- Causescosts of congestion scenario 3
- Approaches towards congestion control
- TCP Congestion Control
- TCP congestion control bandwidth probing
- TCP Congestion Control details
- TCP Congestion Control more details
- TCP Slow Start Phase
- Slow Start Example
- TCP Congestion Avoidance Phase
- Congestion Avoidance
- Example Slow StartCongestion Avoidance
- Slow Start Congestion Avoidance
- Responses to Congestion
- Fast Recovery (differentiation btwn two loss events)
- TCP Congestion Control
- Popular ldquoflavorsrdquo of TCP
- Summary TCP Congestion Control
- TCP Congestion Control Summary
- TCP throughput
- TCP Futures TCP over ldquolong fat pipesrdquo
- TCP Fairness
- Why is TCP fair
- Fairness (more)
- TCP Connection Management
- TCP Connection Management (cont)
- TCP Connection Management (cont)
- TCP Connection Management (cont)
- Tuning TCPIP Parameters
- SomeTCP Parameters in Linux Kernel
- SomeTCP Parameters in Linux Kernel
-
Transport Layer 3-22
rdt20 has a fatal flaw
What happens if ACKNAK corruptedsender doesnrsquot know what happened at receivercanrsquot just retransmit possible duplicate
What to dosender ACKsNAKs receiverrsquos ACKNAK What if sender ACKNAK lostretransmit but this might cause retransmission of correctly received pkt
Handling duplicates sender adds sequence number to each pktsender retransmits current pkt if ACKNAK garbledreceiver discards (doesnrsquot deliver up) duplicate pkt
Sender sends one packet then waits for receiver response
stop and wait
Transport Layer 3-23
rdt21 sender handles garbled ACKNAKs
Wait for call 0 from
above
sndpkt = make_pkt(0 data checksum)udt_send(sndpkt)
rdt_send(data)
Wait for ACK or NAK 0 udt_send(sndpkt)
rdt_rcv(rcvpkt) ampamp ( corrupt(rcvpkt) ||isNAK(rcvpkt) )
sndpkt = make_pkt(1 data checksum)udt_send(sndpkt)
rdt_send(data)
rdt_rcv(rcvpkt) ampamp notcorrupt(rcvpkt) ampamp isACK(rcvpkt)
udt_send(sndpkt)
rdt_rcv(rcvpkt) ampamp ( corrupt(rcvpkt) ||isNAK(rcvpkt) )
rdt_rcv(rcvpkt) ampamp notcorrupt(rcvpkt) ampamp isACK(rcvpkt)
Wait forcall 1 from
above
Wait for ACK or NAK 1
ΛΛ
Transport Layer 3-24
rdt21 receiver handles garbled ACKNAKs
Wait for 0 from below
sndpkt = make_pkt(NAK chksum)udt_send(sndpkt)
rdt_rcv(rcvpkt) ampamp not corrupt(rcvpkt) ampamphas_seq0(rcvpkt)
rdt_rcv(rcvpkt) ampamp notcorrupt(rcvpkt) ampamp has_seq1(rcvpkt)
extract(rcvpktdata)deliver_data(data)sndpkt = make_pkt(ACK chksum)udt_send(sndpkt)
Wait for 1 from below
rdt_rcv(rcvpkt) ampamp notcorrupt(rcvpkt) ampamp has_seq0(rcvpkt)
extract(rcvpktdata)deliver_data(data)sndpkt = make_pkt(ACK chksum)udt_send(sndpkt)
rdt_rcv(rcvpkt) ampamp (corrupt(rcvpkt)
sndpkt = make_pkt(ACK chksum)udt_send(sndpkt)
rdt_rcv(rcvpkt) ampamp not corrupt(rcvpkt) ampamphas_seq1(rcvpkt)
rdt_rcv(rcvpkt) ampamp (corrupt(rcvpkt)
sndpkt = make_pkt(ACK chksum)udt_send(sndpkt)
sndpkt = make_pkt(NAK chksum)udt_send(sndpkt)
Transport Layer 3-25
rdt21 discussion
Senderseq added to pkttwo seq rsquos (01) will suffice Whymust check if received ACKNAK corrupted twice as many states
state must ldquorememberrdquowhether ldquocurrentrdquo pkt has 0 or 1 seq
Receivermust check if received packet is duplicate
state indicates whether 0 or 1 is expected pkt seq
note receiver can notknow if its last ACKNAK received OK at sender
Transport Layer 3-26
rdt22 a NAK-free protocol
same functionality as rdt21 using ACKs onlyinstead of NAK receiver sends ACK for last pkt received OK
receiver must explicitly include seq of pkt being ACKed duplicate ACK at sender results in same action as NAK retransmit current pkt
Transport Layer 3-27
rdt22 sender receiver fragments
Wait for call 0 from
above
sndpkt = make_pkt(0 data checksum)udt_send(sndpkt)
rdt_send(data)
udt_send(sndpkt)
rdt_rcv(rcvpkt) ampamp ( corrupt(rcvpkt) ||
isACK(rcvpkt1) )
rdt_rcv(rcvpkt) ampamp notcorrupt(rcvpkt) ampamp isACK(rcvpkt0)
Wait for ACK
0sender FSM
fragment
Wait for 0 from below
rdt_rcv(rcvpkt) ampamp notcorrupt(rcvpkt) ampamp has_seq1(rcvpkt)
extract(rcvpktdata)deliver_data(data)sndpkt = make_pkt(ACK1 chksum)udt_send(sndpkt)
rdt_rcv(rcvpkt) ampamp (corrupt(rcvpkt) ||
has_seq1(rcvpkt))
udt_send(sndpkt)receiver FSM
fragment
Λ
Transport Layer 3-28
rdt30 channels with errors and loss
New assumptionunderlying channel can also lose packets (data or ACKs)
checksum seq ACKs retransmissions will be of help but not enough
Q how to deal with losssender waits until certain data or ACK lost then retransmitsdrawbacks
Approach sender waits ldquoreasonablerdquo amount of time for ACK retransmits if no ACK received in this timeif pkt (or ACK) just delayed (not lost)
retransmission will be duplicate but use of seq rsquos already handles thisreceiver must specify seq of pkt being ACKed
requires countdown timer
Transport Layer 3-29
rdt30 sendersndpkt = make_pkt(0 data checksum)udt_send(sndpkt)start_timer
rdt_send(data)
Wait for
ACK0
rdt_rcv(rcvpkt) ampamp ( corrupt(rcvpkt) ||isACK(rcvpkt1) )
Wait for call 1 from
above
sndpkt = make_pkt(1 data checksum)udt_send(sndpkt)start_timer
rdt_send(data)
rdt_rcv(rcvpkt) ampamp notcorrupt(rcvpkt) ampamp isACK(rcvpkt0)
rdt_rcv(rcvpkt) ampamp ( corrupt(rcvpkt) ||isACK(rcvpkt0) )
rdt_rcv(rcvpkt) ampamp notcorrupt(rcvpkt) ampamp isACK(rcvpkt1)
stop_timerstop_timer
udt_send(sndpkt)start_timer
timeout
udt_send(sndpkt)start_timer
timeout
rdt_rcv(rcvpkt)
Wait for call 0from
above
Wait for
ACK1
Λrdt_rcv(rcvpkt)
ΛΛ
Λ
Transport Layer 3-30
rdt30 in action
Transport Layer 3-31
rdt30 in action
Transport Layer 3-32
Performance of rdt30
rdt30 works but performance stinksexample 1 Gbps link 15 ms e-e prop delay 1KB packet
Ttransmit = 8kbpkt109 bsec = 8 microsec
U sender utilization ndash fraction of time sender busy sending1KB pkt every 30 msec -gt 33kBsec thruput over 1 Gbps linknetwork protocol limits use of physical resources
U sender=
008 30008
= 000027 L RRTT + L R
=
L (packet length in bits)R (transmission rate bps) =
Transport Layer 3-33
rdt30 stop-and-wait operation
first packet bit transmitted t = 0
sender receiver
RTT
last packet bit transmitted t = L R
first packet bit arriveslast packet bit arrives send ACK
ACK arrives send next packet t = RTT + L R
U sender=
00830008
= 000027 L RRTT + L R
=
Transport Layer 3-34
Pipelined protocolsPipelining sender allows multiple ldquoin-flightrdquo yet-to-
be-acknowledged pktsrange of sequence numbers must be increasedbuffering at sender andor receiver
Two generic forms of pipelined protocols go-Back-N selective repeat
Transport Layer 3-35
Pipelining increased utilization
first packet bit transmitted t = 0
sender receiver
RTT
last bit transmitted t = L R
first packet bit arriveslast packet bit arrives send ACK
ACK arrives send next packet t = RTT + L R
last bit of 2nd packet arrives send ACKlast bit of 3rd packet arrives send ACK
U sender=
024 30008
= 000083 L RRTT + L R
=
Increase utilizationby a factor of 3
Transport Layer 3-36
Utilization=N(LR)(RTT+LR) if NLRltRTT+LR Utilization=1 if and the sender pauses after it transmits a window NLRgtRTT+LR and the of packets until it receives first ACK sender does not pause
Transport Layer 3-37
Go-Back-NSender
k-bit seq in pkt headerldquowindowrdquo of up to N consecutive unackrsquoed pkts allowed
ACK(n) ACKs all pkts up to including seq n - ldquocumulative ACKrdquomay receive duplicate ACKs (see receiver)
timer for the entire windowtimeout(n) retransmit pkt n and all higher seq pkts in window
Transport Layer 3-38
GBN sender extended FSM
Wait start_timerudt_send(sndpkt[base])udt_send(sndpkt[base+1])hellipudt_send(sndpkt[nextseqnum-1])
timeout
rdt_send(data)
if (nextseqnum lt base+N) sndpkt[nextseqnum] = make_pkt(nextseqnumdatachksum)udt_send(sndpkt[nextseqnum])if (base == nextseqnum)
start_timernextseqnum++
elserefuse_data(data)
base = getacknum(rcvpkt)+1If (base == nextseqnum)
stop_timerelse
start_timer
rdt_rcv(rcvpkt) ampamp notcorrupt(rcvpkt)
base=1nextseqnum=1
rdt_rcv(rcvpkt) ampamp corrupt(rcvpkt)
Λ
Λ
Transport Layer 3-39
GBN receiver extended FSM
ACK-only always send ACK for correctly-received pktwith highest in-order seq
may generate duplicate ACKsneed only remember expectedseqnum
out-of-order pkt discard (donrsquot buffer) -gt no receiver bufferingRe-ACK pkt with highest in-order seq
Wait
udt_send(sndpkt)default
rdt_rcv(rcvpkt)ampamp notcurrupt(rcvpkt)ampamp hasseqnum(rcvpktexpectedseqnum)
extract(rcvpktdata)deliver_data(data)sndpkt = make_pkt(expectedseqnumACKchksum)udt_send(sndpkt)expectedseqnum++
expectedseqnum=1sndpkt =
make_pkt(0ACKchksum)
Λ
Transport Layer 3-40
GBN inaction
Transport Layer 3-41
Selective Repeat
receiver individually acknowledges all correctly received pkts
buffers pkts as needed for eventual in-order delivery to upper layer
sender only resends pkts for which ACK not received
sender timer for each unACKed pktsender window
N consecutive seq rsquosagain limits seq s of sent unACKed pkts
Transport Layer 3-42
Selective repeat sender receiver windows
Transport Layer 3-43
Selective repeat
data from above if next available seq in window send pkt
timeout(n)resend pkt n restart timer
ACK(n) in [sendbasesendbase+N-1]
mark pkt n as receivedif n smallest unACKed pkt advance window base to next unACKed seq
senderpkt n in [rcvbase rcvbase+N-1]
send ACK(n)out-of-order bufferin-order deliver (also deliver buffered in-order pkts) advance window to next not-yet-received pkt
pkt n in [rcvbase-Nrcvbase-1]
ACK(n)otherwise
ignore
receiver
Transport Layer 3-44
Selective repeat in action
Transport Layer 3-45
Selective repeatdilemma
Example seq rsquos 0 1 2 3window size=3
receiver sees no difference in two scenariosincorrectly passes duplicate data as new in (a)
Q what relationship between seq size and window size
Transport Layer 3-46
Sequence Number vs Window SizeSuppose we use k bits to represent SNQuestion Whatrsquos the minimum number of bits k necessary for a window size of N
sender
receiver
Go-Back-N
expectedSN
snd_base=expectedSN
Q For a given expectedSN whatrsquos the largest possible value for snd_baseA If all the last N ACKs sent by the receiver are received
snd_base = expectedSNexpectedSN+N-1
senderrsquos window
Transport Layer 3-47
Sequence Number vs Window SizeSuppose we use k bits to represent SNQuestion Whatrsquos the minimum number of bits k necessary for a window size of N
sender
receiver
Go-Back-N
expectedSN
snd_base=expectedSN-N
Q For a given expectedSN whatrsquos the smallest possible value for snd_baseA If all the last N ACKs sent by the receiver are not received
snd_base = expectedSN-NexpectedSN-1
senderrsquos window
Transport Layer 3-48
Sequence Number vs Window Size
sender
receiver
Go-Back-N
expectedSN
snd_base=expectedSN-N
All SNs in the interval [expectedSN-NexpectedSN+N-1] (an interval of size 2N) can be received by the receiver Since the receiver accepts on the packet with SN=expectedSN there should be no other packet within this interval with SN=expectedSN Therefore
2k ge N+1expectedSN+N-1
Transport Layer 3-49
Sequence Number vs Window SizeSuppose we use k bits to represent SNQuestion Whatrsquos the minimum number of bits k necessary for a window size of N
sender
receiver
Selective Repeat
rcv_base
snd_base=rcv_base
Q For a given rcv_base whatrsquos the largest possible value for snd_baseA If all the last N ACKs sent by the receiver are received
snd_base = rcv_base (same as go_back-N)rcv_base+N-1
senderrsquos window
receiverrsquos window
rcv_base+N-1
Transport Layer 3-50
Sequence Number vs Window SizeSuppose we use k bits to represent SNQuestion Whatrsquos the minimum number of bits k necessary for a window size of N
sender
receiver
Selective Repeat
rcv_base
snd_base=rcv_base-N
Q For a given rcv_base whatrsquos the smallest possible value for snd_baseA If all the last N ACKs sent by the receiver are not received
snd_base = rcv_base-N (same as Go-Back-N)rcv_base-1
senderrsquos window
rcv_base
receiverrsquos window
rcv_base+N-1
Transport Layer 3-51
Sequence Number vs Window Size
sender
receiver
Selective Repeat
snd_base=rcv_base-N
All SNs in the interval [rcv_base-Nrcv_base+N-1] (an interval of size 2N) can be received by the receiver Since the receiver should be able to distinguish between all packets in this interval and take corresponding action there should be no two packets within thisinterval having the same SN Therefore
2k ge 2Nrcv_base+N-1
rcv_basercv_base
receiverrsquos window
rcv_base+N-1
Transport Layer 3-52
TCP Overview RFCs 793 1122 1323 2018 2581
full duplex databi-directional data flow in same connectionMSS maximum segment size
connection-orientedhandshaking (exchange of control msgs) initrsquossender receiver state before data exchange
flow controlledsender will not overwhelm receiver
point-to-pointone sender one receiver
reliable in-order byte stream
no ldquomessage boundariesrdquopipelined
TCP congestion and flow control set window size
send amp receive buffers
socketdoor
TCPsend buffer
TCPreceive buffer
socketdoor
segment
applicationwrites data
applicationreads data
Transport Layer 3-53
TCP segment structure
source port dest port
32 bits
applicationdata
(variable length)
sequence numberacknowledgement number
Receive windowUrg data pnterchecksum
FSRPAUheadlen
notused
Options (variable length)
URG urgent data (generally not used)
ACK ACK valid
PSH push data now(generally not used)
RST SYN FINconnection estab(setup teardown
commands)
bytes rcvr willingto accept
Internetchecksum
(as in UDP)
countingby bytes of data(not segments)
Transport Layer 3-54
TCP seq rsquos and ACKsSeq rsquos
byte stream ldquonumberrdquo of first byte in segmentrsquos dataACKs
seq of next byte expected from other sidecumulative ACK
Q how receiver handles out-of-order segmentsA TCP spec doesnrsquot say - up to implementationWidely used implementations of TCP buffer out-of-order segments
Transport Layer 3-55
TCP Round Trip Time and Timeout
Q how to set TCP timeout valuelonger than RTT
but RTT variestoo short premature timeout
unnecessary retransmissions
too long slow reaction to segment loss
Q how to estimate RTTSampleRTT measured time from segment transmission until ACK receipt
ignore retransmissionsSampleRTT will vary want estimated RTT ldquosmootherrdquo
average several recent measurements not just current SampleRTT
Transport Layer 3-56
TCP Round Trip Time and Timeout
EstimatedRTT = (1- α)EstimatedRTT + αSampleRTT
Exponential weighted moving averageinfluence of past sample decreases exponentially fasttypical value α = 0125
Transport Layer 3-57
Example RTT estimationRTT gaiacsumassedu to fantasiaeurecomfr
100
150
200
250
300
350
1 8 15 22 29 36 43 50 57 64 71 78 85 92 99 106
time (seconnds)
RTT
(mill
iseco
nds)
SampleRTT Estimated RTT
Transport Layer 3-58
TCP Round Trip Time and TimeoutSetting the timeout
EstimatedRTT plus ldquosafety marginrdquolarge variation in EstimatedRTT -gt larger safety margin
first estimate of how much SampleRTT deviates from EstimatedRTT
TimeoutInterval = EstimatedRTT + 4DevRTT
DevRTT = (1-β)DevRTT +β|SampleRTT-EstimatedRTT|
(typically β = 025)
Then set timeout interval
Transport Layer 3-59
TCP reliable data transfer
TCP creates rdtservice on top of IPrsquos unreliable servicePipelined segmentsCumulative acksTCP uses single retransmission timer however it just retransmits the first segment in the window
Retransmissions are triggered by
timeout eventsduplicate acks
Initially consider simplified TCP sender
ignore duplicate acksignore flow control congestion control
Transport Layer 3-60
TCP sender eventsdata rcvd from app
Create segment with seq seq is byte-stream number of first data byte in segmentstart timer if not already running (think of timer as for oldest unacked segment)expiration interval TimeOutInterval
timeoutretransmit segment that caused timeout (first segment in the window)restart timer
Ack rcvdIf acknowledges previously unacked segments
update what is known to be ackedstart timer if there are outstanding segments
Transport Layer 3-61
TCP sender(simplified)
NextSeqNum = InitialSeqNumSendBase = InitialSeqNum
loop (forever) switch(event)
event data received from application above create TCP segment with sequence number NextSeqNumif (timer currently not running)
start timerpass segment to IP NextSeqNum = NextSeqNum + length(data)
event timer timeoutretransmit not-yet-acknowledged segment with
smallest sequence numberstart timer
event ACK received with ACK field value of y if (y gt SendBase)
SendBase = yif (there are currently not-yet-acknowledged segments)
start timer
end of loop forever
Commentbull SendBase-1 last cumulatively ackrsquoed byteExamplebull SendBase-1 = 71y= 73 so the rcvrwants 73+ y gt SendBase sothat new data is acked
Transport Layer 3-62
TCP retransmission scenariosHost A
Seq=100 20 bytes data
ACK=100
timepremature timeout
Host B
Seq=92 8 bytes data
ACK=120
Seq=92 8 bytes data
Seq=
92 t
imeo
ut
ACK=120
Host A
Seq=92 8 bytes data
ACK=100
loss
tim
eout
lost ACK scenario
Host B
X
Seq=92 8 bytes data
ACK=100
time
Seq=
92 t
imeo
utSendBase
= 100
SendBase= 120
SendBase= 120
Sendbase= 100
Transport Layer 3-63
TCP retransmission scenarios (more)Host A
Seq=92 8 bytes data
ACK=100
loss
tim
eout
Cumulative ACK scenario
Host B
X
Seq=100 20 bytes data
ACK=120
time
SendBase= 120
Transport Layer 3-64
TCP ACK generation [RFC 1122 RFC 2581]
Event at Receiver
Arrival of in-order segment withexpected seq All data up toexpected seq already ACKed
Arrival of in-order segment withexpected seq One other segment has ACK pending
Arrival of out-of-order segmenthigher-than-expect seq Gap detected
Arrival of segment that partially or completely fills gap
TCP Receiver action
Delayed ACK Wait up to 500msfor next segment If no next segmentsend ACK
Immediately send single cumulative ACK ACKing both in-order segments
Immediately send duplicate ACK indicating seq of next expected byte
Immediate send ACK provided thatsegment startsat lower end of gap
Transport Layer 3-65
Fast Retransmit
Time-out period often relatively long
long delay before resending lost packet
Detect lost segments via duplicate ACKs
Sender often sends many segments back-to-backIf segment is lost there will likely be many duplicate ACKs
If sender receives 3 ACKs for the same data it supposes that segment after ACKeddata was lost
fast retransmit resend segment before timer expires
Transport Layer 3-66
Fast RetransmitResend a segment after 3 duplicate ACKs since a duplicate ACK means that an out-of sequence segment was receivedduplicate ACKs due to packet reorderingif window is small donrsquot get duplicate ACKs
Host A
tim
eout
Host B
time
X
resend seq X2
seq x1seq x2seq x3seq x4seq x5
ACK x1
ACK x1ACK x1ACK x1
tripleduplicate
ACKs
Transport Layer 3-67
event ACK received with ACK field value of y if (y gt SendBase)
SendBase = yif (there are currently not-yet-acknowledged segments)
start timer
else increment count of dup ACKs received for yif (count of dup ACKs received for y = 3)
resend segment with sequence number y
Fast retransmit algorithm
a duplicate ACK for already ACKed segment
fast retransmit
Transport Layer 3-68
TCP Flow Control
receive side of TCP connection has a receive buffer
speed-matching service matching the send rate to the receiving apprsquos drain rate
app process may be slow at reading from buffer
sender wonrsquot overflowreceiverrsquos buffer by
transmitting too muchtoo fast
flow control
Transport Layer 3-69
TCP Flow control how it works
(Suppose TCP receiver discards out-of-order segments)spare room in buffer
= RcvWin
= RcvBuffer-[LastByteRcvd -LastByteRead]
Rcvr advertises spare room by including value of RcvWin in segmentsSender limits unACKeddata to RcvWin
guarantees receive buffer doesnrsquot overflow
Transport Layer 3-70
Sliding Window Flow Control Example
3K
2K SeqNo=0
ReceiverBuffer
0 4KSendersends 2Kof data
2K
AckNo=2048 RcvWin=2048Sendersends 2Kof data 2K SeqNo=2048
4K
AckNo=4096 RcvWin=0
AckNo=4096 RcvWin=1024
Sender blocked
Transport Layer 3-71
Principles of Congestion Control
Congestioninformally ldquotoo many sources sending too much data too fast for network to handlerdquodifferent from flow controlmanifestations
lost packets (buffer overflow at routers)long delays (queueing in router buffers)
a top-10 problem
Transport Layer 3-72
Causescosts of congestion scenario 1
two senders two receiversone router infinite buffers no retransmission
large delays when congestedmaximum achievable throughput
unlimited shared output link buffers
Host Aλin original data
Host B
λout
Transport Layer 3-73
Causescosts of congestion scenario 2
one router finite buffers sender retransmission of lost packet
finite shared output link buffers
Host A λin original data
Host B
λout
λin original data plus retransmitted data
Transport Layer 3-74
Causescosts of congestion scenario 2always (goodput)ldquoperfectrdquo retransmission only when loss
retransmission of delayed (not lost) packet makes larger(than perfect case) for same
λin
λout=
λin
λoutgtλ
inλout
ldquocostsrdquo of congestionmore work (retrans) for given ldquogoodputrdquounneeded retransmissions link carries multiple copies of pkt
R2
R2λin
λ out
b
R2
R2λin
λ out
a
R2
R2λin
λ out
c
R4
R3
Transport Layer 3-75
Causescosts of congestion scenario 3four sendersmultihop pathstimeoutretransmit
λin
Q what happens as and increase λ
in
finite shared output link buffers
Host Aλin original data
Host B
λout
λin original data plus retransmitted data
Transport Layer 3-76
Causescosts of congestion scenario 3
another ldquocostrdquo of congestionwhen packet dropped any ldquoupstream transmission capacity used for that packet was wasted
Host A
Host B
λou
t
Transport Layer 3-77
Approaches towards congestion control
End-end congestion controlno explicit feedback from networkcongestion inferred from end-system observed loss delayapproach taken by TCP
Network-assisted congestion controlrouters provide feedback to end systems
single bit indicating congestion (SNA DECbit TCPIP ECN ATM)explicit rate sender should send at
Two broad approaches towards congestion control
Transport Layer 3-78
TCP Congestion Control
end-end control (no network assistance)sender limits transmissionLastByteSent-LastByteAcked
le CongWin
CongWin is dynamic function of perceived network congestion
How does sender perceive congestionloss event = timeout or3 duplicate acksTCP sender reduces rate (CongWin) after loss event
two modes of operationSlow Start (SS)Congestion avoidance (CA) or Additive Increase Multiplicative Decrease (AIMD)
Transport Layer 3-79
TCP congestion control bandwidth probing
ldquoprobing for bandwidthrdquo increase transmission rate on receipt of ACK until eventually loss occurs then decrease transmission rate
continue to increase on ACK decrease on loss (since available bandwidth is changing depending on other connections in network)
ACKs being received so increase rate
X
X
XX
X loss so decrease rate
send
ing
rate
time
Q how fast to increasedecreasedetails to follow
TCPrsquosldquosawtoothrdquobehavior
Transport Layer 3-80
TCP Congestion Control details
sender limits rate by limiting number of unACKed bytes ldquoin pipelinerdquo
cwnd differs from rwnd (how why)sender limited by min(cwndrwnd)
roughly
cwnd is dynamic function of perceived network congestion
rate = cwndRTT bytessec
LastByteSent-LastByteAcked le cwnd
cwndbytes
RTT
ACK(s)
Transport Layer 3-81
TCP Congestion Control more details
segment loss event reducing cwndtimeout no response from receiver
cut cwnd to 13 duplicate ACKs at least some segments getting through (recall fast retransmit)
cut cwnd in half less aggressively than on timeout
ACK received increase cwndTwo modes of operation
slowstart phase bull increase exponentially
fast (despite name) at connection start or following timeout
congestion avoidance bull increase linearly
Transport Layer 3-82
TCP Slow Start Phasewhen connection begins cwnd = 1 MSS
example MSS = 500 bytes amp RTT = 200 msecinitial rate = 20 kbps
available bandwidth may be gtgt MSSRTT
desirable to quickly ramp up to respectable rate
increase rate exponentially until first loss event or when threshold reached
double cwnd every RTTdone by incrementing cwnd by 1 for every ACK received
Host A
one segment
RTT
Host B
time
two segments
four segments
Transport Layer 3-83
Slow Start ExampleThe congestion window size grows very rapidly
For every ACK we increase CongWin by 1 irrespective of the number of segments ACKrsquoeddouble CongWinevery RTTinitial rate is slow but ramps up exponentially fast
TCP slows down the increase of CongWinwhen CongWin gt ssthresh
segment 1
ACK for segment 1
cwnd = 1
cwnd = 2 segment 2segment 3
ACK for segments 2
cwnd = 4 segment 4segment 5segment 6
ACK for segments 4
cwnd = 7
ACK for segments 3
ACK for segments 5
ACK for segments 6
cwnd = 3
cwnd = 5
cwnd = 6ACK for segments 7
cwnd = 8
segment 7
Transport Layer 3-84
TCP Congestion Avoidance Phase
when cwnd gt ssthreshgrow cwnd linearly
increase cwnd by 1 MSS per RTT approach possible congestion slower than in slowstartimplementation cwnd= cwnd + MSScwndfor each ACK received
ACKs increase cwndby 1 MSS per RTT additive increaseloss cut cwnd in half (non-timeout-detected loss ) multiplicative decrease
AIMD
AIMD Additive IncreaseMultiplicative Decrease
Transport Layer 3-85
Congestion AvoidanceCongestion avoidance phase is started if CongWin has reached the slow-start threshold value
If CongWin gt= ssthresh then each time an ACK is received increment CongWin as follows
bull CongWin = CongWin + 1CongWin (CongWin in segments)
bull In actual TCP implementation CongWin is in BytesCongWin = CongWin + MSS (MSSCongWin)
So CongWin is increased by one only if all CongWinsegments have been acknowledged
Transport Layer 3-86
Example Slow StartCongestion AvoidanceAssume that
ssthresh = 8
cwnd = 1
cwnd = 2
cwnd = 4
cwnd = 8
cwnd = 9
cwnd = 10
02468
101214
t=0
t=2
t=4
t=6
Roundtrip times
Cw
nd(in
seg
men
ts)
ssthresh
cwnd = 3
cwnd = 5cwnd = 6cwnd = 7
Transport Layer 3-87
Slow Start Congestion AvoidanceA typical plot of CongWin for a TCP connection
(MSS = 1500 bytes) with TCP Tahoe
SS
CA
ssthresh
Transport Layer 3-88
Responses to CongestionTCP assumes there is congestion if it detects a packet lossA TCP sender can detect lost packets via loss events
bull Timeout of a retransmission timerbull Receipt of 3 duplicate ACKs (fast retransmit)
TCP interprets a Timeout as a binary congestion signal When a timeout occurs the sender performs
ssthresh is set to half the current size of the congestion window
ssthresh = CongWin 2CongWin is reset to one
CongWin = 1and slow-start is entered
Transport Layer 3-89
Fast Recovery (differentiation btwn two loss events) After 3 dup ACKs (fast Retransmit)
ssthresh = CongWin2CongWin = CongWin2window then grows linearly
But after timeout eventCongWin = 1 MSS window then grows exponentiallyto the threshold then grows linearly
bull 3 dup ACKs indicates network capable of delivering some segmentsbull timeout before 3 dup ACKs is ldquomore alarmingrdquo
Philosophy
3-90
TCP Congestion ControlInitially
CongWin = 1ssthresh = advertised window size
New Ack receivedif (CongWin lt ssthresh) Slow Start
CongWin = CongWin + 1else Congestion Avoidance
CongWin = CongWin + 1CongWinTimeout
ssthresh = CongWin2CongWin = 1
Fast Retransmissionssthresh = CongWin2CongWin = CongWin2
Slow Start (exponential increase phase) is continued until CongWin reaches half of the level where the loss event occurred last time CongWin is increased slowly after (linear increase in Congestion Avoidance phase)
Transport Layer 3-91
Popular ldquoflavorsrdquo of TCP
ssthresh
ssthresh
TCP Tahoe
TCP Reno
Transmission round
cwnd
win
dow
siz
e (in
seg
men
ts)
Transport Layer 3-92
Summary TCP Congestion ControlWhen CongWin is below Threshold sender in slow-start phase window grows exponentiallyWhen CongWin is above Threshold sender is in congestion-avoidance phase window grows linearlyWhen a triple duplicate ACK occurs Threshold set to CongWin2 and CongWin set to ThresholdWhen timeout occurs Threshold set to CongWin2 and CongWin is set to 1 MSS The actual sender window size is determined based on the congestion and flow control algorithms
SenderWin=min(RcvWinCongWin)
Transport Layer 3-93
TCP Congestion Control SummaryEvent State TCP Sender Action Commentary
ACK receipt for previously unackeddata
Slow Start (SS)
CongWin = CongWin + MSS If (CongWin gt Threshold)
set state to ldquoCongestion Avoidancerdquo
Resulting in a doubling of CongWin every RTT
ACK receipt for previously unackeddata
CongestionAvoidance (CA)
CongWin = CongWin+MSS (MSSCongWin)
Additive increase resulting in increase of CongWin by 1 MSS every RTT
Loss event detected by triple duplicate ACK
SS or CA Threshold = CongWin2 CongWin = ThresholdSet state to ldquoCongestion Avoidancerdquo
Fast recovery implementing multiplicative decrease CongWin will not drop below 1 MSS
Timeout SS or CA Threshold = CongWin2 CongWin = 1 MSSSet state to ldquoSlow Startrdquo
Enter slow start
Duplicate ACK
SS or CA Increment duplicate ACK count for segment being acked
CongWin and Threshold not changed
Transport Layer 3-94
TCP throughput
Q whatrsquos average throughout of TCP as function of window size RTT
ignoring slow startlet W be window size when loss occurs
when window is W throughput is WRTTjust after loss window drops to W2 throughput to W2RTT average throughout 75 WRTT
Transport Layer 3-95
TCP Futures TCP over ldquolong fat pipesrdquo
example 1500 byte segments 100ms RTT want 10 Gbps throughputrequires window size W = 83333 in-flight segmentsthroughput in terms of loss rate
L = 210-10 Wownew versions of TCP for high-speed
LRTTMSSsdot221
Transport Layer 3-96
Fairness goal if K TCP sessions share same bottleneck link of bandwidth R each should have average rate of RK
TCP connection 1
bottleneckrouter
capacity R
TCP connection 2
TCP Fairness
Transport Layer 3-97
Why is TCP fairTwo competing sessions
Additive increase gives slope of 1 as throughout increasesmultiplicative decrease decreases throughput proportionally
R
R
equal bandwidth share
Connection 1 throughput
Conn
ecti
on 2
thr
ough
p ut
congestion avoidance additive increaseloss decrease window by factor of 2
congestion avoidance additive increaseloss decrease window by factor of 2
Transport Layer 3-98
Fairness (more)Fairness and UDP
Multimedia apps often do not use TCP
do not want rate throttled by congestion control
Instead use UDPpump audiovideo at constant rate tolerate packet loss
Research area TCP friendly
Fairness and parallel TCP connectionsnothing prevents app from opening parallel cnctionsbetween 2 hostsWeb browsers do this Example link of rate R supporting 9 cnctions
new app asks for 1 TCP gets rate R10new app asks for 11 TCPs gets R2
Transport Layer 3-99
TCP Connection ManagementRecall TCP sender receiver
establish ldquoconnectionrdquobefore exchanging data segmentsinitialize TCP variables
seq sbuffers flow control info (eg RcvWindow)
client connection initiatorSocket clientSocket = new Socket(hostnameport
number)
server contacted by clientSocket connectionSocket = welcomeSocketaccept()
Three way handshakeStep 1 client host sends TCP
SYN segment to serverspecifies initial seq no data
Step 2 server host receives SYN replies with SYNACK segment
server allocates buffersspecifies server initial seq
Step 3 client receives SYNACK replies with ACK segment which may contain data
Transport Layer 3-100
TCP Connection Management (cont)
Closing a connection
client closes socketclientSocketclose()
Step 1 client end system sends TCP FIN control segment to server
Step 2 server receives FIN replies with ACK Closes connection sends FIN
client
FIN
server
ACK
ACK
FIN
close
close
closed
tim
ed w
ait
Transport Layer 3-101
TCP Connection Management (cont)
Step 3 client receives FIN replies with ACK
Enters ldquotimed waitrdquo -will respond with ACK to received FINs
Step 4 server receives ACK Connection closed
client
FIN
server
ACK
ACK
FIN
closing
closing
closed
tim
ed w
ait
closed
Transport Layer 3-102
TCP Connection Management (cont)
TCP clientlifecycle
TCP serverlifecycle
Transport Layer 3-103
Tuning TCPIP Parameters TCPIP parameters
A set of default values may not be optimal for all applicationsThe network administrator may wish to turn on or off some TCPIP functions for performance or security considerations
Many Unix and Linux systems provide some flexibility in tuning the TCPIP kernelsbinsysctl is used to configure the Linux kernel parameters at runtime
Default kernel configuration file is sbinsysctlconfFrequently used sysctl options
bull sysctl ndasha or sysctl ndashA list all current valuesbull sysctl ndashp file_name load the sysctl setting from a configuration
filebull sysctl ndashw variable=value change the value of the parameter
Transport Layer 3-104
SomeTCP Parameters in Linux Kerneltcp_syn_retries
Number of SYN packets the kernel will send before giving up on the new connection
tcp_synack_retriesnumber of SYN+ACK packets sent before the kernel gives up on the connection
tcp_window_scalingMaximum window size of 65535 bytes not enough for for really fast networks The window scaling options allows for almost gigabyte windows which is good for connections with large delay-bandwidth product
tcp_max_syn_backlogMaximal number of remembered connection requests which still did not receive an acknowledgment from connecting client
tcp_fin_timeoutHow many seconds to wait for a final FIN packet before the socket is closed required to prevent denial-of-service (DoS) attacks Default value is 60 seconds
Transport Layer 3-105
SomeTCP Parameters in Linux Kerneltcp_rmem
This is a vector of 3 integers [min default max] These parameters are used by TCP to dynamically adjust receive buffer sizesmin - minimum size of the receive buffer used by each TCP socket The default value is 4K default - the default size of the receive buffer for a TCP socket The default value is 87380 bytes and is lowered to 43689 in low memory systems If larger receive buffer sizes are desired this value should be increased max - the maximum size of the receive buffer used by each TCP socket The default value of 873802 bytes is lowered to 87380 in low memory systems
tcp_smemSend buffer parameters [min default max] similar to tcp_rmem
- Chapter 3 Transport Layer
- Transport services and protocols
- Transport vs network layer
- Internet transport-layer protocols
- Multiplexingdemultiplexing
- How demultiplexing works
- Connectionless demultiplexing
- Connection-oriented demux
- Connection-oriented demux (cont)
- Connection-oriented demux Threaded Web Server
- UDP User Datagram Protocol [RFC 768]
- UDP more
- UDP checksum
- Principles of Reliable data transfer
- Reliable data transfer getting started
- Reliable data transfer getting started
- Rdt10 reliable transfer over a reliable channel
- Rdt20 channel with bit errors
- rdt20 FSM specification
- rdt20 operation with no errors
- rdt20 error scenario
- rdt20 has a fatal flaw
- rdt21 sender handles garbled ACKNAKs
- rdt21 receiver handles garbled ACKNAKs
- rdt21 discussion
- rdt22 a NAK-free protocol
- rdt22 sender receiver fragments
- rdt30 channels with errors and loss
- rdt30 sender
- rdt30 in action
- rdt30 in action
- Performance of rdt30
- rdt30 stop-and-wait operation
- Pipelined protocols
- Pipelining increased utilization
- Go-Back-N
- GBN sender extended FSM
- GBN receiver extended FSM
- GBN inaction
- Selective Repeat
- Selective repeat sender receiver windows
- Selective repeat
- Selective repeat in action
- Selective repeat dilemma
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- TCP Overview RFCs 793 1122 1323 2018 2581
- TCP segment structure
- TCP seq rsquos and ACKs
- TCP Round Trip Time and Timeout
- TCP Round Trip Time and Timeout
- Example RTT estimation
- TCP Round Trip Time and Timeout
- TCP reliable data transfer
- TCP sender events
- TCP sender(simplified)
- TCP retransmission scenarios
- TCP retransmission scenarios (more)
- TCP ACK generation [RFC 1122 RFC 2581]
- Fast Retransmit
- Fast Retransmit
- Fast retransmit algorithm
- TCP Flow Control
- TCP Flow control how it works
- Sliding Window Flow Control Example
- Principles of Congestion Control
- Causescosts of congestion scenario 1
- Causescosts of congestion scenario 2
- Causescosts of congestion scenario 2
- Causescosts of congestion scenario 3
- Causescosts of congestion scenario 3
- Approaches towards congestion control
- TCP Congestion Control
- TCP congestion control bandwidth probing
- TCP Congestion Control details
- TCP Congestion Control more details
- TCP Slow Start Phase
- Slow Start Example
- TCP Congestion Avoidance Phase
- Congestion Avoidance
- Example Slow StartCongestion Avoidance
- Slow Start Congestion Avoidance
- Responses to Congestion
- Fast Recovery (differentiation btwn two loss events)
- TCP Congestion Control
- Popular ldquoflavorsrdquo of TCP
- Summary TCP Congestion Control
- TCP Congestion Control Summary
- TCP throughput
- TCP Futures TCP over ldquolong fat pipesrdquo
- TCP Fairness
- Why is TCP fair
- Fairness (more)
- TCP Connection Management
- TCP Connection Management (cont)
- TCP Connection Management (cont)
- TCP Connection Management (cont)
- Tuning TCPIP Parameters
- SomeTCP Parameters in Linux Kernel
- SomeTCP Parameters in Linux Kernel
-
Transport Layer 3-23
rdt21 sender handles garbled ACKNAKs
Wait for call 0 from
above
sndpkt = make_pkt(0 data checksum)udt_send(sndpkt)
rdt_send(data)
Wait for ACK or NAK 0 udt_send(sndpkt)
rdt_rcv(rcvpkt) ampamp ( corrupt(rcvpkt) ||isNAK(rcvpkt) )
sndpkt = make_pkt(1 data checksum)udt_send(sndpkt)
rdt_send(data)
rdt_rcv(rcvpkt) ampamp notcorrupt(rcvpkt) ampamp isACK(rcvpkt)
udt_send(sndpkt)
rdt_rcv(rcvpkt) ampamp ( corrupt(rcvpkt) ||isNAK(rcvpkt) )
rdt_rcv(rcvpkt) ampamp notcorrupt(rcvpkt) ampamp isACK(rcvpkt)
Wait forcall 1 from
above
Wait for ACK or NAK 1
ΛΛ
Transport Layer 3-24
rdt21 receiver handles garbled ACKNAKs
Wait for 0 from below
sndpkt = make_pkt(NAK chksum)udt_send(sndpkt)
rdt_rcv(rcvpkt) ampamp not corrupt(rcvpkt) ampamphas_seq0(rcvpkt)
rdt_rcv(rcvpkt) ampamp notcorrupt(rcvpkt) ampamp has_seq1(rcvpkt)
extract(rcvpktdata)deliver_data(data)sndpkt = make_pkt(ACK chksum)udt_send(sndpkt)
Wait for 1 from below
rdt_rcv(rcvpkt) ampamp notcorrupt(rcvpkt) ampamp has_seq0(rcvpkt)
extract(rcvpktdata)deliver_data(data)sndpkt = make_pkt(ACK chksum)udt_send(sndpkt)
rdt_rcv(rcvpkt) ampamp (corrupt(rcvpkt)
sndpkt = make_pkt(ACK chksum)udt_send(sndpkt)
rdt_rcv(rcvpkt) ampamp not corrupt(rcvpkt) ampamphas_seq1(rcvpkt)
rdt_rcv(rcvpkt) ampamp (corrupt(rcvpkt)
sndpkt = make_pkt(ACK chksum)udt_send(sndpkt)
sndpkt = make_pkt(NAK chksum)udt_send(sndpkt)
Transport Layer 3-25
rdt21 discussion
Senderseq added to pkttwo seq rsquos (01) will suffice Whymust check if received ACKNAK corrupted twice as many states
state must ldquorememberrdquowhether ldquocurrentrdquo pkt has 0 or 1 seq
Receivermust check if received packet is duplicate
state indicates whether 0 or 1 is expected pkt seq
note receiver can notknow if its last ACKNAK received OK at sender
Transport Layer 3-26
rdt22 a NAK-free protocol
same functionality as rdt21 using ACKs onlyinstead of NAK receiver sends ACK for last pkt received OK
receiver must explicitly include seq of pkt being ACKed duplicate ACK at sender results in same action as NAK retransmit current pkt
Transport Layer 3-27
rdt22 sender receiver fragments
Wait for call 0 from
above
sndpkt = make_pkt(0 data checksum)udt_send(sndpkt)
rdt_send(data)
udt_send(sndpkt)
rdt_rcv(rcvpkt) ampamp ( corrupt(rcvpkt) ||
isACK(rcvpkt1) )
rdt_rcv(rcvpkt) ampamp notcorrupt(rcvpkt) ampamp isACK(rcvpkt0)
Wait for ACK
0sender FSM
fragment
Wait for 0 from below
rdt_rcv(rcvpkt) ampamp notcorrupt(rcvpkt) ampamp has_seq1(rcvpkt)
extract(rcvpktdata)deliver_data(data)sndpkt = make_pkt(ACK1 chksum)udt_send(sndpkt)
rdt_rcv(rcvpkt) ampamp (corrupt(rcvpkt) ||
has_seq1(rcvpkt))
udt_send(sndpkt)receiver FSM
fragment
Λ
Transport Layer 3-28
rdt30 channels with errors and loss
New assumptionunderlying channel can also lose packets (data or ACKs)
checksum seq ACKs retransmissions will be of help but not enough
Q how to deal with losssender waits until certain data or ACK lost then retransmitsdrawbacks
Approach sender waits ldquoreasonablerdquo amount of time for ACK retransmits if no ACK received in this timeif pkt (or ACK) just delayed (not lost)
retransmission will be duplicate but use of seq rsquos already handles thisreceiver must specify seq of pkt being ACKed
requires countdown timer
Transport Layer 3-29
rdt30 sendersndpkt = make_pkt(0 data checksum)udt_send(sndpkt)start_timer
rdt_send(data)
Wait for
ACK0
rdt_rcv(rcvpkt) ampamp ( corrupt(rcvpkt) ||isACK(rcvpkt1) )
Wait for call 1 from
above
sndpkt = make_pkt(1 data checksum)udt_send(sndpkt)start_timer
rdt_send(data)
rdt_rcv(rcvpkt) ampamp notcorrupt(rcvpkt) ampamp isACK(rcvpkt0)
rdt_rcv(rcvpkt) ampamp ( corrupt(rcvpkt) ||isACK(rcvpkt0) )
rdt_rcv(rcvpkt) ampamp notcorrupt(rcvpkt) ampamp isACK(rcvpkt1)
stop_timerstop_timer
udt_send(sndpkt)start_timer
timeout
udt_send(sndpkt)start_timer
timeout
rdt_rcv(rcvpkt)
Wait for call 0from
above
Wait for
ACK1
Λrdt_rcv(rcvpkt)
ΛΛ
Λ
Transport Layer 3-30
rdt30 in action
Transport Layer 3-31
rdt30 in action
Transport Layer 3-32
Performance of rdt30
rdt30 works but performance stinksexample 1 Gbps link 15 ms e-e prop delay 1KB packet
Ttransmit = 8kbpkt109 bsec = 8 microsec
U sender utilization ndash fraction of time sender busy sending1KB pkt every 30 msec -gt 33kBsec thruput over 1 Gbps linknetwork protocol limits use of physical resources
U sender=
008 30008
= 000027 L RRTT + L R
=
L (packet length in bits)R (transmission rate bps) =
Transport Layer 3-33
rdt30 stop-and-wait operation
first packet bit transmitted t = 0
sender receiver
RTT
last packet bit transmitted t = L R
first packet bit arriveslast packet bit arrives send ACK
ACK arrives send next packet t = RTT + L R
U sender=
00830008
= 000027 L RRTT + L R
=
Transport Layer 3-34
Pipelined protocolsPipelining sender allows multiple ldquoin-flightrdquo yet-to-
be-acknowledged pktsrange of sequence numbers must be increasedbuffering at sender andor receiver
Two generic forms of pipelined protocols go-Back-N selective repeat
Transport Layer 3-35
Pipelining increased utilization
first packet bit transmitted t = 0
sender receiver
RTT
last bit transmitted t = L R
first packet bit arriveslast packet bit arrives send ACK
ACK arrives send next packet t = RTT + L R
last bit of 2nd packet arrives send ACKlast bit of 3rd packet arrives send ACK
U sender=
024 30008
= 000083 L RRTT + L R
=
Increase utilizationby a factor of 3
Transport Layer 3-36
Utilization=N(LR)(RTT+LR) if NLRltRTT+LR Utilization=1 if and the sender pauses after it transmits a window NLRgtRTT+LR and the of packets until it receives first ACK sender does not pause
Transport Layer 3-37
Go-Back-NSender
k-bit seq in pkt headerldquowindowrdquo of up to N consecutive unackrsquoed pkts allowed
ACK(n) ACKs all pkts up to including seq n - ldquocumulative ACKrdquomay receive duplicate ACKs (see receiver)
timer for the entire windowtimeout(n) retransmit pkt n and all higher seq pkts in window
Transport Layer 3-38
GBN sender extended FSM
Wait start_timerudt_send(sndpkt[base])udt_send(sndpkt[base+1])hellipudt_send(sndpkt[nextseqnum-1])
timeout
rdt_send(data)
if (nextseqnum lt base+N) sndpkt[nextseqnum] = make_pkt(nextseqnumdatachksum)udt_send(sndpkt[nextseqnum])if (base == nextseqnum)
start_timernextseqnum++
elserefuse_data(data)
base = getacknum(rcvpkt)+1If (base == nextseqnum)
stop_timerelse
start_timer
rdt_rcv(rcvpkt) ampamp notcorrupt(rcvpkt)
base=1nextseqnum=1
rdt_rcv(rcvpkt) ampamp corrupt(rcvpkt)
Λ
Λ
Transport Layer 3-39
GBN receiver extended FSM
ACK-only always send ACK for correctly-received pktwith highest in-order seq
may generate duplicate ACKsneed only remember expectedseqnum
out-of-order pkt discard (donrsquot buffer) -gt no receiver bufferingRe-ACK pkt with highest in-order seq
Wait
udt_send(sndpkt)default
rdt_rcv(rcvpkt)ampamp notcurrupt(rcvpkt)ampamp hasseqnum(rcvpktexpectedseqnum)
extract(rcvpktdata)deliver_data(data)sndpkt = make_pkt(expectedseqnumACKchksum)udt_send(sndpkt)expectedseqnum++
expectedseqnum=1sndpkt =
make_pkt(0ACKchksum)
Λ
Transport Layer 3-40
GBN inaction
Transport Layer 3-41
Selective Repeat
receiver individually acknowledges all correctly received pkts
buffers pkts as needed for eventual in-order delivery to upper layer
sender only resends pkts for which ACK not received
sender timer for each unACKed pktsender window
N consecutive seq rsquosagain limits seq s of sent unACKed pkts
Transport Layer 3-42
Selective repeat sender receiver windows
Transport Layer 3-43
Selective repeat
data from above if next available seq in window send pkt
timeout(n)resend pkt n restart timer
ACK(n) in [sendbasesendbase+N-1]
mark pkt n as receivedif n smallest unACKed pkt advance window base to next unACKed seq
senderpkt n in [rcvbase rcvbase+N-1]
send ACK(n)out-of-order bufferin-order deliver (also deliver buffered in-order pkts) advance window to next not-yet-received pkt
pkt n in [rcvbase-Nrcvbase-1]
ACK(n)otherwise
ignore
receiver
Transport Layer 3-44
Selective repeat in action
Transport Layer 3-45
Selective repeatdilemma
Example seq rsquos 0 1 2 3window size=3
receiver sees no difference in two scenariosincorrectly passes duplicate data as new in (a)
Q what relationship between seq size and window size
Transport Layer 3-46
Sequence Number vs Window SizeSuppose we use k bits to represent SNQuestion Whatrsquos the minimum number of bits k necessary for a window size of N
sender
receiver
Go-Back-N
expectedSN
snd_base=expectedSN
Q For a given expectedSN whatrsquos the largest possible value for snd_baseA If all the last N ACKs sent by the receiver are received
snd_base = expectedSNexpectedSN+N-1
senderrsquos window
Transport Layer 3-47
Sequence Number vs Window SizeSuppose we use k bits to represent SNQuestion Whatrsquos the minimum number of bits k necessary for a window size of N
sender
receiver
Go-Back-N
expectedSN
snd_base=expectedSN-N
Q For a given expectedSN whatrsquos the smallest possible value for snd_baseA If all the last N ACKs sent by the receiver are not received
snd_base = expectedSN-NexpectedSN-1
senderrsquos window
Transport Layer 3-48
Sequence Number vs Window Size
sender
receiver
Go-Back-N
expectedSN
snd_base=expectedSN-N
All SNs in the interval [expectedSN-NexpectedSN+N-1] (an interval of size 2N) can be received by the receiver Since the receiver accepts on the packet with SN=expectedSN there should be no other packet within this interval with SN=expectedSN Therefore
2k ge N+1expectedSN+N-1
Transport Layer 3-49
Sequence Number vs Window SizeSuppose we use k bits to represent SNQuestion Whatrsquos the minimum number of bits k necessary for a window size of N
sender
receiver
Selective Repeat
rcv_base
snd_base=rcv_base
Q For a given rcv_base whatrsquos the largest possible value for snd_baseA If all the last N ACKs sent by the receiver are received
snd_base = rcv_base (same as go_back-N)rcv_base+N-1
senderrsquos window
receiverrsquos window
rcv_base+N-1
Transport Layer 3-50
Sequence Number vs Window SizeSuppose we use k bits to represent SNQuestion Whatrsquos the minimum number of bits k necessary for a window size of N
sender
receiver
Selective Repeat
rcv_base
snd_base=rcv_base-N
Q For a given rcv_base whatrsquos the smallest possible value for snd_baseA If all the last N ACKs sent by the receiver are not received
snd_base = rcv_base-N (same as Go-Back-N)rcv_base-1
senderrsquos window
rcv_base
receiverrsquos window
rcv_base+N-1
Transport Layer 3-51
Sequence Number vs Window Size
sender
receiver
Selective Repeat
snd_base=rcv_base-N
All SNs in the interval [rcv_base-Nrcv_base+N-1] (an interval of size 2N) can be received by the receiver Since the receiver should be able to distinguish between all packets in this interval and take corresponding action there should be no two packets within thisinterval having the same SN Therefore
2k ge 2Nrcv_base+N-1
rcv_basercv_base
receiverrsquos window
rcv_base+N-1
Transport Layer 3-52
TCP Overview RFCs 793 1122 1323 2018 2581
full duplex databi-directional data flow in same connectionMSS maximum segment size
connection-orientedhandshaking (exchange of control msgs) initrsquossender receiver state before data exchange
flow controlledsender will not overwhelm receiver
point-to-pointone sender one receiver
reliable in-order byte stream
no ldquomessage boundariesrdquopipelined
TCP congestion and flow control set window size
send amp receive buffers
socketdoor
TCPsend buffer
TCPreceive buffer
socketdoor
segment
applicationwrites data
applicationreads data
Transport Layer 3-53
TCP segment structure
source port dest port
32 bits
applicationdata
(variable length)
sequence numberacknowledgement number
Receive windowUrg data pnterchecksum
FSRPAUheadlen
notused
Options (variable length)
URG urgent data (generally not used)
ACK ACK valid
PSH push data now(generally not used)
RST SYN FINconnection estab(setup teardown
commands)
bytes rcvr willingto accept
Internetchecksum
(as in UDP)
countingby bytes of data(not segments)
Transport Layer 3-54
TCP seq rsquos and ACKsSeq rsquos
byte stream ldquonumberrdquo of first byte in segmentrsquos dataACKs
seq of next byte expected from other sidecumulative ACK
Q how receiver handles out-of-order segmentsA TCP spec doesnrsquot say - up to implementationWidely used implementations of TCP buffer out-of-order segments
Transport Layer 3-55
TCP Round Trip Time and Timeout
Q how to set TCP timeout valuelonger than RTT
but RTT variestoo short premature timeout
unnecessary retransmissions
too long slow reaction to segment loss
Q how to estimate RTTSampleRTT measured time from segment transmission until ACK receipt
ignore retransmissionsSampleRTT will vary want estimated RTT ldquosmootherrdquo
average several recent measurements not just current SampleRTT
Transport Layer 3-56
TCP Round Trip Time and Timeout
EstimatedRTT = (1- α)EstimatedRTT + αSampleRTT
Exponential weighted moving averageinfluence of past sample decreases exponentially fasttypical value α = 0125
Transport Layer 3-57
Example RTT estimationRTT gaiacsumassedu to fantasiaeurecomfr
100
150
200
250
300
350
1 8 15 22 29 36 43 50 57 64 71 78 85 92 99 106
time (seconnds)
RTT
(mill
iseco
nds)
SampleRTT Estimated RTT
Transport Layer 3-58
TCP Round Trip Time and TimeoutSetting the timeout
EstimatedRTT plus ldquosafety marginrdquolarge variation in EstimatedRTT -gt larger safety margin
first estimate of how much SampleRTT deviates from EstimatedRTT
TimeoutInterval = EstimatedRTT + 4DevRTT
DevRTT = (1-β)DevRTT +β|SampleRTT-EstimatedRTT|
(typically β = 025)
Then set timeout interval
Transport Layer 3-59
TCP reliable data transfer
TCP creates rdtservice on top of IPrsquos unreliable servicePipelined segmentsCumulative acksTCP uses single retransmission timer however it just retransmits the first segment in the window
Retransmissions are triggered by
timeout eventsduplicate acks
Initially consider simplified TCP sender
ignore duplicate acksignore flow control congestion control
Transport Layer 3-60
TCP sender eventsdata rcvd from app
Create segment with seq seq is byte-stream number of first data byte in segmentstart timer if not already running (think of timer as for oldest unacked segment)expiration interval TimeOutInterval
timeoutretransmit segment that caused timeout (first segment in the window)restart timer
Ack rcvdIf acknowledges previously unacked segments
update what is known to be ackedstart timer if there are outstanding segments
Transport Layer 3-61
TCP sender(simplified)
NextSeqNum = InitialSeqNumSendBase = InitialSeqNum
loop (forever) switch(event)
event data received from application above create TCP segment with sequence number NextSeqNumif (timer currently not running)
start timerpass segment to IP NextSeqNum = NextSeqNum + length(data)
event timer timeoutretransmit not-yet-acknowledged segment with
smallest sequence numberstart timer
event ACK received with ACK field value of y if (y gt SendBase)
SendBase = yif (there are currently not-yet-acknowledged segments)
start timer
end of loop forever
Commentbull SendBase-1 last cumulatively ackrsquoed byteExamplebull SendBase-1 = 71y= 73 so the rcvrwants 73+ y gt SendBase sothat new data is acked
Transport Layer 3-62
TCP retransmission scenariosHost A
Seq=100 20 bytes data
ACK=100
timepremature timeout
Host B
Seq=92 8 bytes data
ACK=120
Seq=92 8 bytes data
Seq=
92 t
imeo
ut
ACK=120
Host A
Seq=92 8 bytes data
ACK=100
loss
tim
eout
lost ACK scenario
Host B
X
Seq=92 8 bytes data
ACK=100
time
Seq=
92 t
imeo
utSendBase
= 100
SendBase= 120
SendBase= 120
Sendbase= 100
Transport Layer 3-63
TCP retransmission scenarios (more)Host A
Seq=92 8 bytes data
ACK=100
loss
tim
eout
Cumulative ACK scenario
Host B
X
Seq=100 20 bytes data
ACK=120
time
SendBase= 120
Transport Layer 3-64
TCP ACK generation [RFC 1122 RFC 2581]
Event at Receiver
Arrival of in-order segment withexpected seq All data up toexpected seq already ACKed
Arrival of in-order segment withexpected seq One other segment has ACK pending
Arrival of out-of-order segmenthigher-than-expect seq Gap detected
Arrival of segment that partially or completely fills gap
TCP Receiver action
Delayed ACK Wait up to 500msfor next segment If no next segmentsend ACK
Immediately send single cumulative ACK ACKing both in-order segments
Immediately send duplicate ACK indicating seq of next expected byte
Immediate send ACK provided thatsegment startsat lower end of gap
Transport Layer 3-65
Fast Retransmit
Time-out period often relatively long
long delay before resending lost packet
Detect lost segments via duplicate ACKs
Sender often sends many segments back-to-backIf segment is lost there will likely be many duplicate ACKs
If sender receives 3 ACKs for the same data it supposes that segment after ACKeddata was lost
fast retransmit resend segment before timer expires
Transport Layer 3-66
Fast RetransmitResend a segment after 3 duplicate ACKs since a duplicate ACK means that an out-of sequence segment was receivedduplicate ACKs due to packet reorderingif window is small donrsquot get duplicate ACKs
Host A
tim
eout
Host B
time
X
resend seq X2
seq x1seq x2seq x3seq x4seq x5
ACK x1
ACK x1ACK x1ACK x1
tripleduplicate
ACKs
Transport Layer 3-67
event ACK received with ACK field value of y if (y gt SendBase)
SendBase = yif (there are currently not-yet-acknowledged segments)
start timer
else increment count of dup ACKs received for yif (count of dup ACKs received for y = 3)
resend segment with sequence number y
Fast retransmit algorithm
a duplicate ACK for already ACKed segment
fast retransmit
Transport Layer 3-68
TCP Flow Control
receive side of TCP connection has a receive buffer
speed-matching service matching the send rate to the receiving apprsquos drain rate
app process may be slow at reading from buffer
sender wonrsquot overflowreceiverrsquos buffer by
transmitting too muchtoo fast
flow control
Transport Layer 3-69
TCP Flow control how it works
(Suppose TCP receiver discards out-of-order segments)spare room in buffer
= RcvWin
= RcvBuffer-[LastByteRcvd -LastByteRead]
Rcvr advertises spare room by including value of RcvWin in segmentsSender limits unACKeddata to RcvWin
guarantees receive buffer doesnrsquot overflow
Transport Layer 3-70
Sliding Window Flow Control Example
3K
2K SeqNo=0
ReceiverBuffer
0 4KSendersends 2Kof data
2K
AckNo=2048 RcvWin=2048Sendersends 2Kof data 2K SeqNo=2048
4K
AckNo=4096 RcvWin=0
AckNo=4096 RcvWin=1024
Sender blocked
Transport Layer 3-71
Principles of Congestion Control
Congestioninformally ldquotoo many sources sending too much data too fast for network to handlerdquodifferent from flow controlmanifestations
lost packets (buffer overflow at routers)long delays (queueing in router buffers)
a top-10 problem
Transport Layer 3-72
Causescosts of congestion scenario 1
two senders two receiversone router infinite buffers no retransmission
large delays when congestedmaximum achievable throughput
unlimited shared output link buffers
Host Aλin original data
Host B
λout
Transport Layer 3-73
Causescosts of congestion scenario 2
one router finite buffers sender retransmission of lost packet
finite shared output link buffers
Host A λin original data
Host B
λout
λin original data plus retransmitted data
Transport Layer 3-74
Causescosts of congestion scenario 2always (goodput)ldquoperfectrdquo retransmission only when loss
retransmission of delayed (not lost) packet makes larger(than perfect case) for same
λin
λout=
λin
λoutgtλ
inλout
ldquocostsrdquo of congestionmore work (retrans) for given ldquogoodputrdquounneeded retransmissions link carries multiple copies of pkt
R2
R2λin
λ out
b
R2
R2λin
λ out
a
R2
R2λin
λ out
c
R4
R3
Transport Layer 3-75
Causescosts of congestion scenario 3four sendersmultihop pathstimeoutretransmit
λin
Q what happens as and increase λ
in
finite shared output link buffers
Host Aλin original data
Host B
λout
λin original data plus retransmitted data
Transport Layer 3-76
Causescosts of congestion scenario 3
another ldquocostrdquo of congestionwhen packet dropped any ldquoupstream transmission capacity used for that packet was wasted
Host A
Host B
λou
t
Transport Layer 3-77
Approaches towards congestion control
End-end congestion controlno explicit feedback from networkcongestion inferred from end-system observed loss delayapproach taken by TCP
Network-assisted congestion controlrouters provide feedback to end systems
single bit indicating congestion (SNA DECbit TCPIP ECN ATM)explicit rate sender should send at
Two broad approaches towards congestion control
Transport Layer 3-78
TCP Congestion Control
end-end control (no network assistance)sender limits transmissionLastByteSent-LastByteAcked
le CongWin
CongWin is dynamic function of perceived network congestion
How does sender perceive congestionloss event = timeout or3 duplicate acksTCP sender reduces rate (CongWin) after loss event
two modes of operationSlow Start (SS)Congestion avoidance (CA) or Additive Increase Multiplicative Decrease (AIMD)
Transport Layer 3-79
TCP congestion control bandwidth probing
ldquoprobing for bandwidthrdquo increase transmission rate on receipt of ACK until eventually loss occurs then decrease transmission rate
continue to increase on ACK decrease on loss (since available bandwidth is changing depending on other connections in network)
ACKs being received so increase rate
X
X
XX
X loss so decrease rate
send
ing
rate
time
Q how fast to increasedecreasedetails to follow
TCPrsquosldquosawtoothrdquobehavior
Transport Layer 3-80
TCP Congestion Control details
sender limits rate by limiting number of unACKed bytes ldquoin pipelinerdquo
cwnd differs from rwnd (how why)sender limited by min(cwndrwnd)
roughly
cwnd is dynamic function of perceived network congestion
rate = cwndRTT bytessec
LastByteSent-LastByteAcked le cwnd
cwndbytes
RTT
ACK(s)
Transport Layer 3-81
TCP Congestion Control more details
segment loss event reducing cwndtimeout no response from receiver
cut cwnd to 13 duplicate ACKs at least some segments getting through (recall fast retransmit)
cut cwnd in half less aggressively than on timeout
ACK received increase cwndTwo modes of operation
slowstart phase bull increase exponentially
fast (despite name) at connection start or following timeout
congestion avoidance bull increase linearly
Transport Layer 3-82
TCP Slow Start Phasewhen connection begins cwnd = 1 MSS
example MSS = 500 bytes amp RTT = 200 msecinitial rate = 20 kbps
available bandwidth may be gtgt MSSRTT
desirable to quickly ramp up to respectable rate
increase rate exponentially until first loss event or when threshold reached
double cwnd every RTTdone by incrementing cwnd by 1 for every ACK received
Host A
one segment
RTT
Host B
time
two segments
four segments
Transport Layer 3-83
Slow Start ExampleThe congestion window size grows very rapidly
For every ACK we increase CongWin by 1 irrespective of the number of segments ACKrsquoeddouble CongWinevery RTTinitial rate is slow but ramps up exponentially fast
TCP slows down the increase of CongWinwhen CongWin gt ssthresh
segment 1
ACK for segment 1
cwnd = 1
cwnd = 2 segment 2segment 3
ACK for segments 2
cwnd = 4 segment 4segment 5segment 6
ACK for segments 4
cwnd = 7
ACK for segments 3
ACK for segments 5
ACK for segments 6
cwnd = 3
cwnd = 5
cwnd = 6ACK for segments 7
cwnd = 8
segment 7
Transport Layer 3-84
TCP Congestion Avoidance Phase
when cwnd gt ssthreshgrow cwnd linearly
increase cwnd by 1 MSS per RTT approach possible congestion slower than in slowstartimplementation cwnd= cwnd + MSScwndfor each ACK received
ACKs increase cwndby 1 MSS per RTT additive increaseloss cut cwnd in half (non-timeout-detected loss ) multiplicative decrease
AIMD
AIMD Additive IncreaseMultiplicative Decrease
Transport Layer 3-85
Congestion AvoidanceCongestion avoidance phase is started if CongWin has reached the slow-start threshold value
If CongWin gt= ssthresh then each time an ACK is received increment CongWin as follows
bull CongWin = CongWin + 1CongWin (CongWin in segments)
bull In actual TCP implementation CongWin is in BytesCongWin = CongWin + MSS (MSSCongWin)
So CongWin is increased by one only if all CongWinsegments have been acknowledged
Transport Layer 3-86
Example Slow StartCongestion AvoidanceAssume that
ssthresh = 8
cwnd = 1
cwnd = 2
cwnd = 4
cwnd = 8
cwnd = 9
cwnd = 10
02468
101214
t=0
t=2
t=4
t=6
Roundtrip times
Cw
nd(in
seg
men
ts)
ssthresh
cwnd = 3
cwnd = 5cwnd = 6cwnd = 7
Transport Layer 3-87
Slow Start Congestion AvoidanceA typical plot of CongWin for a TCP connection
(MSS = 1500 bytes) with TCP Tahoe
SS
CA
ssthresh
Transport Layer 3-88
Responses to CongestionTCP assumes there is congestion if it detects a packet lossA TCP sender can detect lost packets via loss events
bull Timeout of a retransmission timerbull Receipt of 3 duplicate ACKs (fast retransmit)
TCP interprets a Timeout as a binary congestion signal When a timeout occurs the sender performs
ssthresh is set to half the current size of the congestion window
ssthresh = CongWin 2CongWin is reset to one
CongWin = 1and slow-start is entered
Transport Layer 3-89
Fast Recovery (differentiation btwn two loss events) After 3 dup ACKs (fast Retransmit)
ssthresh = CongWin2CongWin = CongWin2window then grows linearly
But after timeout eventCongWin = 1 MSS window then grows exponentiallyto the threshold then grows linearly
bull 3 dup ACKs indicates network capable of delivering some segmentsbull timeout before 3 dup ACKs is ldquomore alarmingrdquo
Philosophy
3-90
TCP Congestion ControlInitially
CongWin = 1ssthresh = advertised window size
New Ack receivedif (CongWin lt ssthresh) Slow Start
CongWin = CongWin + 1else Congestion Avoidance
CongWin = CongWin + 1CongWinTimeout
ssthresh = CongWin2CongWin = 1
Fast Retransmissionssthresh = CongWin2CongWin = CongWin2
Slow Start (exponential increase phase) is continued until CongWin reaches half of the level where the loss event occurred last time CongWin is increased slowly after (linear increase in Congestion Avoidance phase)
Transport Layer 3-91
Popular ldquoflavorsrdquo of TCP
ssthresh
ssthresh
TCP Tahoe
TCP Reno
Transmission round
cwnd
win
dow
siz
e (in
seg
men
ts)
Transport Layer 3-92
Summary TCP Congestion ControlWhen CongWin is below Threshold sender in slow-start phase window grows exponentiallyWhen CongWin is above Threshold sender is in congestion-avoidance phase window grows linearlyWhen a triple duplicate ACK occurs Threshold set to CongWin2 and CongWin set to ThresholdWhen timeout occurs Threshold set to CongWin2 and CongWin is set to 1 MSS The actual sender window size is determined based on the congestion and flow control algorithms
SenderWin=min(RcvWinCongWin)
Transport Layer 3-93
TCP Congestion Control SummaryEvent State TCP Sender Action Commentary
ACK receipt for previously unackeddata
Slow Start (SS)
CongWin = CongWin + MSS If (CongWin gt Threshold)
set state to ldquoCongestion Avoidancerdquo
Resulting in a doubling of CongWin every RTT
ACK receipt for previously unackeddata
CongestionAvoidance (CA)
CongWin = CongWin+MSS (MSSCongWin)
Additive increase resulting in increase of CongWin by 1 MSS every RTT
Loss event detected by triple duplicate ACK
SS or CA Threshold = CongWin2 CongWin = ThresholdSet state to ldquoCongestion Avoidancerdquo
Fast recovery implementing multiplicative decrease CongWin will not drop below 1 MSS
Timeout SS or CA Threshold = CongWin2 CongWin = 1 MSSSet state to ldquoSlow Startrdquo
Enter slow start
Duplicate ACK
SS or CA Increment duplicate ACK count for segment being acked
CongWin and Threshold not changed
Transport Layer 3-94
TCP throughput
Q whatrsquos average throughout of TCP as function of window size RTT
ignoring slow startlet W be window size when loss occurs
when window is W throughput is WRTTjust after loss window drops to W2 throughput to W2RTT average throughout 75 WRTT
Transport Layer 3-95
TCP Futures TCP over ldquolong fat pipesrdquo
example 1500 byte segments 100ms RTT want 10 Gbps throughputrequires window size W = 83333 in-flight segmentsthroughput in terms of loss rate
L = 210-10 Wownew versions of TCP for high-speed
LRTTMSSsdot221
Transport Layer 3-96
Fairness goal if K TCP sessions share same bottleneck link of bandwidth R each should have average rate of RK
TCP connection 1
bottleneckrouter
capacity R
TCP connection 2
TCP Fairness
Transport Layer 3-97
Why is TCP fairTwo competing sessions
Additive increase gives slope of 1 as throughout increasesmultiplicative decrease decreases throughput proportionally
R
R
equal bandwidth share
Connection 1 throughput
Conn
ecti
on 2
thr
ough
p ut
congestion avoidance additive increaseloss decrease window by factor of 2
congestion avoidance additive increaseloss decrease window by factor of 2
Transport Layer 3-98
Fairness (more)Fairness and UDP
Multimedia apps often do not use TCP
do not want rate throttled by congestion control
Instead use UDPpump audiovideo at constant rate tolerate packet loss
Research area TCP friendly
Fairness and parallel TCP connectionsnothing prevents app from opening parallel cnctionsbetween 2 hostsWeb browsers do this Example link of rate R supporting 9 cnctions
new app asks for 1 TCP gets rate R10new app asks for 11 TCPs gets R2
Transport Layer 3-99
TCP Connection ManagementRecall TCP sender receiver
establish ldquoconnectionrdquobefore exchanging data segmentsinitialize TCP variables
seq sbuffers flow control info (eg RcvWindow)
client connection initiatorSocket clientSocket = new Socket(hostnameport
number)
server contacted by clientSocket connectionSocket = welcomeSocketaccept()
Three way handshakeStep 1 client host sends TCP
SYN segment to serverspecifies initial seq no data
Step 2 server host receives SYN replies with SYNACK segment
server allocates buffersspecifies server initial seq
Step 3 client receives SYNACK replies with ACK segment which may contain data
Transport Layer 3-100
TCP Connection Management (cont)
Closing a connection
client closes socketclientSocketclose()
Step 1 client end system sends TCP FIN control segment to server
Step 2 server receives FIN replies with ACK Closes connection sends FIN
client
FIN
server
ACK
ACK
FIN
close
close
closed
tim
ed w
ait
Transport Layer 3-101
TCP Connection Management (cont)
Step 3 client receives FIN replies with ACK
Enters ldquotimed waitrdquo -will respond with ACK to received FINs
Step 4 server receives ACK Connection closed
client
FIN
server
ACK
ACK
FIN
closing
closing
closed
tim
ed w
ait
closed
Transport Layer 3-102
TCP Connection Management (cont)
TCP clientlifecycle
TCP serverlifecycle
Transport Layer 3-103
Tuning TCPIP Parameters TCPIP parameters
A set of default values may not be optimal for all applicationsThe network administrator may wish to turn on or off some TCPIP functions for performance or security considerations
Many Unix and Linux systems provide some flexibility in tuning the TCPIP kernelsbinsysctl is used to configure the Linux kernel parameters at runtime
Default kernel configuration file is sbinsysctlconfFrequently used sysctl options
bull sysctl ndasha or sysctl ndashA list all current valuesbull sysctl ndashp file_name load the sysctl setting from a configuration
filebull sysctl ndashw variable=value change the value of the parameter
Transport Layer 3-104
SomeTCP Parameters in Linux Kerneltcp_syn_retries
Number of SYN packets the kernel will send before giving up on the new connection
tcp_synack_retriesnumber of SYN+ACK packets sent before the kernel gives up on the connection
tcp_window_scalingMaximum window size of 65535 bytes not enough for for really fast networks The window scaling options allows for almost gigabyte windows which is good for connections with large delay-bandwidth product
tcp_max_syn_backlogMaximal number of remembered connection requests which still did not receive an acknowledgment from connecting client
tcp_fin_timeoutHow many seconds to wait for a final FIN packet before the socket is closed required to prevent denial-of-service (DoS) attacks Default value is 60 seconds
Transport Layer 3-105
SomeTCP Parameters in Linux Kerneltcp_rmem
This is a vector of 3 integers [min default max] These parameters are used by TCP to dynamically adjust receive buffer sizesmin - minimum size of the receive buffer used by each TCP socket The default value is 4K default - the default size of the receive buffer for a TCP socket The default value is 87380 bytes and is lowered to 43689 in low memory systems If larger receive buffer sizes are desired this value should be increased max - the maximum size of the receive buffer used by each TCP socket The default value of 873802 bytes is lowered to 87380 in low memory systems
tcp_smemSend buffer parameters [min default max] similar to tcp_rmem
- Chapter 3 Transport Layer
- Transport services and protocols
- Transport vs network layer
- Internet transport-layer protocols
- Multiplexingdemultiplexing
- How demultiplexing works
- Connectionless demultiplexing
- Connection-oriented demux
- Connection-oriented demux (cont)
- Connection-oriented demux Threaded Web Server
- UDP User Datagram Protocol [RFC 768]
- UDP more
- UDP checksum
- Principles of Reliable data transfer
- Reliable data transfer getting started
- Reliable data transfer getting started
- Rdt10 reliable transfer over a reliable channel
- Rdt20 channel with bit errors
- rdt20 FSM specification
- rdt20 operation with no errors
- rdt20 error scenario
- rdt20 has a fatal flaw
- rdt21 sender handles garbled ACKNAKs
- rdt21 receiver handles garbled ACKNAKs
- rdt21 discussion
- rdt22 a NAK-free protocol
- rdt22 sender receiver fragments
- rdt30 channels with errors and loss
- rdt30 sender
- rdt30 in action
- rdt30 in action
- Performance of rdt30
- rdt30 stop-and-wait operation
- Pipelined protocols
- Pipelining increased utilization
- Go-Back-N
- GBN sender extended FSM
- GBN receiver extended FSM
- GBN inaction
- Selective Repeat
- Selective repeat sender receiver windows
- Selective repeat
- Selective repeat in action
- Selective repeat dilemma
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- TCP Overview RFCs 793 1122 1323 2018 2581
- TCP segment structure
- TCP seq rsquos and ACKs
- TCP Round Trip Time and Timeout
- TCP Round Trip Time and Timeout
- Example RTT estimation
- TCP Round Trip Time and Timeout
- TCP reliable data transfer
- TCP sender events
- TCP sender(simplified)
- TCP retransmission scenarios
- TCP retransmission scenarios (more)
- TCP ACK generation [RFC 1122 RFC 2581]
- Fast Retransmit
- Fast Retransmit
- Fast retransmit algorithm
- TCP Flow Control
- TCP Flow control how it works
- Sliding Window Flow Control Example
- Principles of Congestion Control
- Causescosts of congestion scenario 1
- Causescosts of congestion scenario 2
- Causescosts of congestion scenario 2
- Causescosts of congestion scenario 3
- Causescosts of congestion scenario 3
- Approaches towards congestion control
- TCP Congestion Control
- TCP congestion control bandwidth probing
- TCP Congestion Control details
- TCP Congestion Control more details
- TCP Slow Start Phase
- Slow Start Example
- TCP Congestion Avoidance Phase
- Congestion Avoidance
- Example Slow StartCongestion Avoidance
- Slow Start Congestion Avoidance
- Responses to Congestion
- Fast Recovery (differentiation btwn two loss events)
- TCP Congestion Control
- Popular ldquoflavorsrdquo of TCP
- Summary TCP Congestion Control
- TCP Congestion Control Summary
- TCP throughput
- TCP Futures TCP over ldquolong fat pipesrdquo
- TCP Fairness
- Why is TCP fair
- Fairness (more)
- TCP Connection Management
- TCP Connection Management (cont)
- TCP Connection Management (cont)
- TCP Connection Management (cont)
- Tuning TCPIP Parameters
- SomeTCP Parameters in Linux Kernel
- SomeTCP Parameters in Linux Kernel
-
Transport Layer 3-24
rdt21 receiver handles garbled ACKNAKs
Wait for 0 from below
sndpkt = make_pkt(NAK chksum)udt_send(sndpkt)
rdt_rcv(rcvpkt) ampamp not corrupt(rcvpkt) ampamphas_seq0(rcvpkt)
rdt_rcv(rcvpkt) ampamp notcorrupt(rcvpkt) ampamp has_seq1(rcvpkt)
extract(rcvpktdata)deliver_data(data)sndpkt = make_pkt(ACK chksum)udt_send(sndpkt)
Wait for 1 from below
rdt_rcv(rcvpkt) ampamp notcorrupt(rcvpkt) ampamp has_seq0(rcvpkt)
extract(rcvpktdata)deliver_data(data)sndpkt = make_pkt(ACK chksum)udt_send(sndpkt)
rdt_rcv(rcvpkt) ampamp (corrupt(rcvpkt)
sndpkt = make_pkt(ACK chksum)udt_send(sndpkt)
rdt_rcv(rcvpkt) ampamp not corrupt(rcvpkt) ampamphas_seq1(rcvpkt)
rdt_rcv(rcvpkt) ampamp (corrupt(rcvpkt)
sndpkt = make_pkt(ACK chksum)udt_send(sndpkt)
sndpkt = make_pkt(NAK chksum)udt_send(sndpkt)
Transport Layer 3-25
rdt21 discussion
Senderseq added to pkttwo seq rsquos (01) will suffice Whymust check if received ACKNAK corrupted twice as many states
state must ldquorememberrdquowhether ldquocurrentrdquo pkt has 0 or 1 seq
Receivermust check if received packet is duplicate
state indicates whether 0 or 1 is expected pkt seq
note receiver can notknow if its last ACKNAK received OK at sender
Transport Layer 3-26
rdt22 a NAK-free protocol
same functionality as rdt21 using ACKs onlyinstead of NAK receiver sends ACK for last pkt received OK
receiver must explicitly include seq of pkt being ACKed duplicate ACK at sender results in same action as NAK retransmit current pkt
Transport Layer 3-27
rdt22 sender receiver fragments
Wait for call 0 from
above
sndpkt = make_pkt(0 data checksum)udt_send(sndpkt)
rdt_send(data)
udt_send(sndpkt)
rdt_rcv(rcvpkt) ampamp ( corrupt(rcvpkt) ||
isACK(rcvpkt1) )
rdt_rcv(rcvpkt) ampamp notcorrupt(rcvpkt) ampamp isACK(rcvpkt0)
Wait for ACK
0sender FSM
fragment
Wait for 0 from below
rdt_rcv(rcvpkt) ampamp notcorrupt(rcvpkt) ampamp has_seq1(rcvpkt)
extract(rcvpktdata)deliver_data(data)sndpkt = make_pkt(ACK1 chksum)udt_send(sndpkt)
rdt_rcv(rcvpkt) ampamp (corrupt(rcvpkt) ||
has_seq1(rcvpkt))
udt_send(sndpkt)receiver FSM
fragment
Λ
Transport Layer 3-28
rdt30 channels with errors and loss
New assumptionunderlying channel can also lose packets (data or ACKs)
checksum seq ACKs retransmissions will be of help but not enough
Q how to deal with losssender waits until certain data or ACK lost then retransmitsdrawbacks
Approach sender waits ldquoreasonablerdquo amount of time for ACK retransmits if no ACK received in this timeif pkt (or ACK) just delayed (not lost)
retransmission will be duplicate but use of seq rsquos already handles thisreceiver must specify seq of pkt being ACKed
requires countdown timer
Transport Layer 3-29
rdt30 sendersndpkt = make_pkt(0 data checksum)udt_send(sndpkt)start_timer
rdt_send(data)
Wait for
ACK0
rdt_rcv(rcvpkt) ampamp ( corrupt(rcvpkt) ||isACK(rcvpkt1) )
Wait for call 1 from
above
sndpkt = make_pkt(1 data checksum)udt_send(sndpkt)start_timer
rdt_send(data)
rdt_rcv(rcvpkt) ampamp notcorrupt(rcvpkt) ampamp isACK(rcvpkt0)
rdt_rcv(rcvpkt) ampamp ( corrupt(rcvpkt) ||isACK(rcvpkt0) )
rdt_rcv(rcvpkt) ampamp notcorrupt(rcvpkt) ampamp isACK(rcvpkt1)
stop_timerstop_timer
udt_send(sndpkt)start_timer
timeout
udt_send(sndpkt)start_timer
timeout
rdt_rcv(rcvpkt)
Wait for call 0from
above
Wait for
ACK1
Λrdt_rcv(rcvpkt)
ΛΛ
Λ
Transport Layer 3-30
rdt30 in action
Transport Layer 3-31
rdt30 in action
Transport Layer 3-32
Performance of rdt30
rdt30 works but performance stinksexample 1 Gbps link 15 ms e-e prop delay 1KB packet
Ttransmit = 8kbpkt109 bsec = 8 microsec
U sender utilization ndash fraction of time sender busy sending1KB pkt every 30 msec -gt 33kBsec thruput over 1 Gbps linknetwork protocol limits use of physical resources
U sender=
008 30008
= 000027 L RRTT + L R
=
L (packet length in bits)R (transmission rate bps) =
Transport Layer 3-33
rdt30 stop-and-wait operation
first packet bit transmitted t = 0
sender receiver
RTT
last packet bit transmitted t = L R
first packet bit arriveslast packet bit arrives send ACK
ACK arrives send next packet t = RTT + L R
U sender=
00830008
= 000027 L RRTT + L R
=
Transport Layer 3-34
Pipelined protocolsPipelining sender allows multiple ldquoin-flightrdquo yet-to-
be-acknowledged pktsrange of sequence numbers must be increasedbuffering at sender andor receiver
Two generic forms of pipelined protocols go-Back-N selective repeat
Transport Layer 3-35
Pipelining increased utilization
first packet bit transmitted t = 0
sender receiver
RTT
last bit transmitted t = L R
first packet bit arriveslast packet bit arrives send ACK
ACK arrives send next packet t = RTT + L R
last bit of 2nd packet arrives send ACKlast bit of 3rd packet arrives send ACK
U sender=
024 30008
= 000083 L RRTT + L R
=
Increase utilizationby a factor of 3
Transport Layer 3-36
Utilization=N(LR)(RTT+LR) if NLRltRTT+LR Utilization=1 if and the sender pauses after it transmits a window NLRgtRTT+LR and the of packets until it receives first ACK sender does not pause
Transport Layer 3-37
Go-Back-NSender
k-bit seq in pkt headerldquowindowrdquo of up to N consecutive unackrsquoed pkts allowed
ACK(n) ACKs all pkts up to including seq n - ldquocumulative ACKrdquomay receive duplicate ACKs (see receiver)
timer for the entire windowtimeout(n) retransmit pkt n and all higher seq pkts in window
Transport Layer 3-38
GBN sender extended FSM
Wait start_timerudt_send(sndpkt[base])udt_send(sndpkt[base+1])hellipudt_send(sndpkt[nextseqnum-1])
timeout
rdt_send(data)
if (nextseqnum lt base+N) sndpkt[nextseqnum] = make_pkt(nextseqnumdatachksum)udt_send(sndpkt[nextseqnum])if (base == nextseqnum)
start_timernextseqnum++
elserefuse_data(data)
base = getacknum(rcvpkt)+1If (base == nextseqnum)
stop_timerelse
start_timer
rdt_rcv(rcvpkt) ampamp notcorrupt(rcvpkt)
base=1nextseqnum=1
rdt_rcv(rcvpkt) ampamp corrupt(rcvpkt)
Λ
Λ
Transport Layer 3-39
GBN receiver extended FSM
ACK-only always send ACK for correctly-received pktwith highest in-order seq
may generate duplicate ACKsneed only remember expectedseqnum
out-of-order pkt discard (donrsquot buffer) -gt no receiver bufferingRe-ACK pkt with highest in-order seq
Wait
udt_send(sndpkt)default
rdt_rcv(rcvpkt)ampamp notcurrupt(rcvpkt)ampamp hasseqnum(rcvpktexpectedseqnum)
extract(rcvpktdata)deliver_data(data)sndpkt = make_pkt(expectedseqnumACKchksum)udt_send(sndpkt)expectedseqnum++
expectedseqnum=1sndpkt =
make_pkt(0ACKchksum)
Λ
Transport Layer 3-40
GBN inaction
Transport Layer 3-41
Selective Repeat
receiver individually acknowledges all correctly received pkts
buffers pkts as needed for eventual in-order delivery to upper layer
sender only resends pkts for which ACK not received
sender timer for each unACKed pktsender window
N consecutive seq rsquosagain limits seq s of sent unACKed pkts
Transport Layer 3-42
Selective repeat sender receiver windows
Transport Layer 3-43
Selective repeat
data from above if next available seq in window send pkt
timeout(n)resend pkt n restart timer
ACK(n) in [sendbasesendbase+N-1]
mark pkt n as receivedif n smallest unACKed pkt advance window base to next unACKed seq
senderpkt n in [rcvbase rcvbase+N-1]
send ACK(n)out-of-order bufferin-order deliver (also deliver buffered in-order pkts) advance window to next not-yet-received pkt
pkt n in [rcvbase-Nrcvbase-1]
ACK(n)otherwise
ignore
receiver
Transport Layer 3-44
Selective repeat in action
Transport Layer 3-45
Selective repeatdilemma
Example seq rsquos 0 1 2 3window size=3
receiver sees no difference in two scenariosincorrectly passes duplicate data as new in (a)
Q what relationship between seq size and window size
Transport Layer 3-46
Sequence Number vs Window SizeSuppose we use k bits to represent SNQuestion Whatrsquos the minimum number of bits k necessary for a window size of N
sender
receiver
Go-Back-N
expectedSN
snd_base=expectedSN
Q For a given expectedSN whatrsquos the largest possible value for snd_baseA If all the last N ACKs sent by the receiver are received
snd_base = expectedSNexpectedSN+N-1
senderrsquos window
Transport Layer 3-47
Sequence Number vs Window SizeSuppose we use k bits to represent SNQuestion Whatrsquos the minimum number of bits k necessary for a window size of N
sender
receiver
Go-Back-N
expectedSN
snd_base=expectedSN-N
Q For a given expectedSN whatrsquos the smallest possible value for snd_baseA If all the last N ACKs sent by the receiver are not received
snd_base = expectedSN-NexpectedSN-1
senderrsquos window
Transport Layer 3-48
Sequence Number vs Window Size
sender
receiver
Go-Back-N
expectedSN
snd_base=expectedSN-N
All SNs in the interval [expectedSN-NexpectedSN+N-1] (an interval of size 2N) can be received by the receiver Since the receiver accepts on the packet with SN=expectedSN there should be no other packet within this interval with SN=expectedSN Therefore
2k ge N+1expectedSN+N-1
Transport Layer 3-49
Sequence Number vs Window SizeSuppose we use k bits to represent SNQuestion Whatrsquos the minimum number of bits k necessary for a window size of N
sender
receiver
Selective Repeat
rcv_base
snd_base=rcv_base
Q For a given rcv_base whatrsquos the largest possible value for snd_baseA If all the last N ACKs sent by the receiver are received
snd_base = rcv_base (same as go_back-N)rcv_base+N-1
senderrsquos window
receiverrsquos window
rcv_base+N-1
Transport Layer 3-50
Sequence Number vs Window SizeSuppose we use k bits to represent SNQuestion Whatrsquos the minimum number of bits k necessary for a window size of N
sender
receiver
Selective Repeat
rcv_base
snd_base=rcv_base-N
Q For a given rcv_base whatrsquos the smallest possible value for snd_baseA If all the last N ACKs sent by the receiver are not received
snd_base = rcv_base-N (same as Go-Back-N)rcv_base-1
senderrsquos window
rcv_base
receiverrsquos window
rcv_base+N-1
Transport Layer 3-51
Sequence Number vs Window Size
sender
receiver
Selective Repeat
snd_base=rcv_base-N
All SNs in the interval [rcv_base-Nrcv_base+N-1] (an interval of size 2N) can be received by the receiver Since the receiver should be able to distinguish between all packets in this interval and take corresponding action there should be no two packets within thisinterval having the same SN Therefore
2k ge 2Nrcv_base+N-1
rcv_basercv_base
receiverrsquos window
rcv_base+N-1
Transport Layer 3-52
TCP Overview RFCs 793 1122 1323 2018 2581
full duplex databi-directional data flow in same connectionMSS maximum segment size
connection-orientedhandshaking (exchange of control msgs) initrsquossender receiver state before data exchange
flow controlledsender will not overwhelm receiver
point-to-pointone sender one receiver
reliable in-order byte stream
no ldquomessage boundariesrdquopipelined
TCP congestion and flow control set window size
send amp receive buffers
socketdoor
TCPsend buffer
TCPreceive buffer
socketdoor
segment
applicationwrites data
applicationreads data
Transport Layer 3-53
TCP segment structure
source port dest port
32 bits
applicationdata
(variable length)
sequence numberacknowledgement number
Receive windowUrg data pnterchecksum
FSRPAUheadlen
notused
Options (variable length)
URG urgent data (generally not used)
ACK ACK valid
PSH push data now(generally not used)
RST SYN FINconnection estab(setup teardown
commands)
bytes rcvr willingto accept
Internetchecksum
(as in UDP)
countingby bytes of data(not segments)
Transport Layer 3-54
TCP seq rsquos and ACKsSeq rsquos
byte stream ldquonumberrdquo of first byte in segmentrsquos dataACKs
seq of next byte expected from other sidecumulative ACK
Q how receiver handles out-of-order segmentsA TCP spec doesnrsquot say - up to implementationWidely used implementations of TCP buffer out-of-order segments
Transport Layer 3-55
TCP Round Trip Time and Timeout
Q how to set TCP timeout valuelonger than RTT
but RTT variestoo short premature timeout
unnecessary retransmissions
too long slow reaction to segment loss
Q how to estimate RTTSampleRTT measured time from segment transmission until ACK receipt
ignore retransmissionsSampleRTT will vary want estimated RTT ldquosmootherrdquo
average several recent measurements not just current SampleRTT
Transport Layer 3-56
TCP Round Trip Time and Timeout
EstimatedRTT = (1- α)EstimatedRTT + αSampleRTT
Exponential weighted moving averageinfluence of past sample decreases exponentially fasttypical value α = 0125
Transport Layer 3-57
Example RTT estimationRTT gaiacsumassedu to fantasiaeurecomfr
100
150
200
250
300
350
1 8 15 22 29 36 43 50 57 64 71 78 85 92 99 106
time (seconnds)
RTT
(mill
iseco
nds)
SampleRTT Estimated RTT
Transport Layer 3-58
TCP Round Trip Time and TimeoutSetting the timeout
EstimatedRTT plus ldquosafety marginrdquolarge variation in EstimatedRTT -gt larger safety margin
first estimate of how much SampleRTT deviates from EstimatedRTT
TimeoutInterval = EstimatedRTT + 4DevRTT
DevRTT = (1-β)DevRTT +β|SampleRTT-EstimatedRTT|
(typically β = 025)
Then set timeout interval
Transport Layer 3-59
TCP reliable data transfer
TCP creates rdtservice on top of IPrsquos unreliable servicePipelined segmentsCumulative acksTCP uses single retransmission timer however it just retransmits the first segment in the window
Retransmissions are triggered by
timeout eventsduplicate acks
Initially consider simplified TCP sender
ignore duplicate acksignore flow control congestion control
Transport Layer 3-60
TCP sender eventsdata rcvd from app
Create segment with seq seq is byte-stream number of first data byte in segmentstart timer if not already running (think of timer as for oldest unacked segment)expiration interval TimeOutInterval
timeoutretransmit segment that caused timeout (first segment in the window)restart timer
Ack rcvdIf acknowledges previously unacked segments
update what is known to be ackedstart timer if there are outstanding segments
Transport Layer 3-61
TCP sender(simplified)
NextSeqNum = InitialSeqNumSendBase = InitialSeqNum
loop (forever) switch(event)
event data received from application above create TCP segment with sequence number NextSeqNumif (timer currently not running)
start timerpass segment to IP NextSeqNum = NextSeqNum + length(data)
event timer timeoutretransmit not-yet-acknowledged segment with
smallest sequence numberstart timer
event ACK received with ACK field value of y if (y gt SendBase)
SendBase = yif (there are currently not-yet-acknowledged segments)
start timer
end of loop forever
Commentbull SendBase-1 last cumulatively ackrsquoed byteExamplebull SendBase-1 = 71y= 73 so the rcvrwants 73+ y gt SendBase sothat new data is acked
Transport Layer 3-62
TCP retransmission scenariosHost A
Seq=100 20 bytes data
ACK=100
timepremature timeout
Host B
Seq=92 8 bytes data
ACK=120
Seq=92 8 bytes data
Seq=
92 t
imeo
ut
ACK=120
Host A
Seq=92 8 bytes data
ACK=100
loss
tim
eout
lost ACK scenario
Host B
X
Seq=92 8 bytes data
ACK=100
time
Seq=
92 t
imeo
utSendBase
= 100
SendBase= 120
SendBase= 120
Sendbase= 100
Transport Layer 3-63
TCP retransmission scenarios (more)Host A
Seq=92 8 bytes data
ACK=100
loss
tim
eout
Cumulative ACK scenario
Host B
X
Seq=100 20 bytes data
ACK=120
time
SendBase= 120
Transport Layer 3-64
TCP ACK generation [RFC 1122 RFC 2581]
Event at Receiver
Arrival of in-order segment withexpected seq All data up toexpected seq already ACKed
Arrival of in-order segment withexpected seq One other segment has ACK pending
Arrival of out-of-order segmenthigher-than-expect seq Gap detected
Arrival of segment that partially or completely fills gap
TCP Receiver action
Delayed ACK Wait up to 500msfor next segment If no next segmentsend ACK
Immediately send single cumulative ACK ACKing both in-order segments
Immediately send duplicate ACK indicating seq of next expected byte
Immediate send ACK provided thatsegment startsat lower end of gap
Transport Layer 3-65
Fast Retransmit
Time-out period often relatively long
long delay before resending lost packet
Detect lost segments via duplicate ACKs
Sender often sends many segments back-to-backIf segment is lost there will likely be many duplicate ACKs
If sender receives 3 ACKs for the same data it supposes that segment after ACKeddata was lost
fast retransmit resend segment before timer expires
Transport Layer 3-66
Fast RetransmitResend a segment after 3 duplicate ACKs since a duplicate ACK means that an out-of sequence segment was receivedduplicate ACKs due to packet reorderingif window is small donrsquot get duplicate ACKs
Host A
tim
eout
Host B
time
X
resend seq X2
seq x1seq x2seq x3seq x4seq x5
ACK x1
ACK x1ACK x1ACK x1
tripleduplicate
ACKs
Transport Layer 3-67
event ACK received with ACK field value of y if (y gt SendBase)
SendBase = yif (there are currently not-yet-acknowledged segments)
start timer
else increment count of dup ACKs received for yif (count of dup ACKs received for y = 3)
resend segment with sequence number y
Fast retransmit algorithm
a duplicate ACK for already ACKed segment
fast retransmit
Transport Layer 3-68
TCP Flow Control
receive side of TCP connection has a receive buffer
speed-matching service matching the send rate to the receiving apprsquos drain rate
app process may be slow at reading from buffer
sender wonrsquot overflowreceiverrsquos buffer by
transmitting too muchtoo fast
flow control
Transport Layer 3-69
TCP Flow control how it works
(Suppose TCP receiver discards out-of-order segments)spare room in buffer
= RcvWin
= RcvBuffer-[LastByteRcvd -LastByteRead]
Rcvr advertises spare room by including value of RcvWin in segmentsSender limits unACKeddata to RcvWin
guarantees receive buffer doesnrsquot overflow
Transport Layer 3-70
Sliding Window Flow Control Example
3K
2K SeqNo=0
ReceiverBuffer
0 4KSendersends 2Kof data
2K
AckNo=2048 RcvWin=2048Sendersends 2Kof data 2K SeqNo=2048
4K
AckNo=4096 RcvWin=0
AckNo=4096 RcvWin=1024
Sender blocked
Transport Layer 3-71
Principles of Congestion Control
Congestioninformally ldquotoo many sources sending too much data too fast for network to handlerdquodifferent from flow controlmanifestations
lost packets (buffer overflow at routers)long delays (queueing in router buffers)
a top-10 problem
Transport Layer 3-72
Causescosts of congestion scenario 1
two senders two receiversone router infinite buffers no retransmission
large delays when congestedmaximum achievable throughput
unlimited shared output link buffers
Host Aλin original data
Host B
λout
Transport Layer 3-73
Causescosts of congestion scenario 2
one router finite buffers sender retransmission of lost packet
finite shared output link buffers
Host A λin original data
Host B
λout
λin original data plus retransmitted data
Transport Layer 3-74
Causescosts of congestion scenario 2always (goodput)ldquoperfectrdquo retransmission only when loss
retransmission of delayed (not lost) packet makes larger(than perfect case) for same
λin
λout=
λin
λoutgtλ
inλout
ldquocostsrdquo of congestionmore work (retrans) for given ldquogoodputrdquounneeded retransmissions link carries multiple copies of pkt
R2
R2λin
λ out
b
R2
R2λin
λ out
a
R2
R2λin
λ out
c
R4
R3
Transport Layer 3-75
Causescosts of congestion scenario 3four sendersmultihop pathstimeoutretransmit
λin
Q what happens as and increase λ
in
finite shared output link buffers
Host Aλin original data
Host B
λout
λin original data plus retransmitted data
Transport Layer 3-76
Causescosts of congestion scenario 3
another ldquocostrdquo of congestionwhen packet dropped any ldquoupstream transmission capacity used for that packet was wasted
Host A
Host B
λou
t
Transport Layer 3-77
Approaches towards congestion control
End-end congestion controlno explicit feedback from networkcongestion inferred from end-system observed loss delayapproach taken by TCP
Network-assisted congestion controlrouters provide feedback to end systems
single bit indicating congestion (SNA DECbit TCPIP ECN ATM)explicit rate sender should send at
Two broad approaches towards congestion control
Transport Layer 3-78
TCP Congestion Control
end-end control (no network assistance)sender limits transmissionLastByteSent-LastByteAcked
le CongWin
CongWin is dynamic function of perceived network congestion
How does sender perceive congestionloss event = timeout or3 duplicate acksTCP sender reduces rate (CongWin) after loss event
two modes of operationSlow Start (SS)Congestion avoidance (CA) or Additive Increase Multiplicative Decrease (AIMD)
Transport Layer 3-79
TCP congestion control bandwidth probing
ldquoprobing for bandwidthrdquo increase transmission rate on receipt of ACK until eventually loss occurs then decrease transmission rate
continue to increase on ACK decrease on loss (since available bandwidth is changing depending on other connections in network)
ACKs being received so increase rate
X
X
XX
X loss so decrease rate
send
ing
rate
time
Q how fast to increasedecreasedetails to follow
TCPrsquosldquosawtoothrdquobehavior
Transport Layer 3-80
TCP Congestion Control details
sender limits rate by limiting number of unACKed bytes ldquoin pipelinerdquo
cwnd differs from rwnd (how why)sender limited by min(cwndrwnd)
roughly
cwnd is dynamic function of perceived network congestion
rate = cwndRTT bytessec
LastByteSent-LastByteAcked le cwnd
cwndbytes
RTT
ACK(s)
Transport Layer 3-81
TCP Congestion Control more details
segment loss event reducing cwndtimeout no response from receiver
cut cwnd to 13 duplicate ACKs at least some segments getting through (recall fast retransmit)
cut cwnd in half less aggressively than on timeout
ACK received increase cwndTwo modes of operation
slowstart phase bull increase exponentially
fast (despite name) at connection start or following timeout
congestion avoidance bull increase linearly
Transport Layer 3-82
TCP Slow Start Phasewhen connection begins cwnd = 1 MSS
example MSS = 500 bytes amp RTT = 200 msecinitial rate = 20 kbps
available bandwidth may be gtgt MSSRTT
desirable to quickly ramp up to respectable rate
increase rate exponentially until first loss event or when threshold reached
double cwnd every RTTdone by incrementing cwnd by 1 for every ACK received
Host A
one segment
RTT
Host B
time
two segments
four segments
Transport Layer 3-83
Slow Start ExampleThe congestion window size grows very rapidly
For every ACK we increase CongWin by 1 irrespective of the number of segments ACKrsquoeddouble CongWinevery RTTinitial rate is slow but ramps up exponentially fast
TCP slows down the increase of CongWinwhen CongWin gt ssthresh
segment 1
ACK for segment 1
cwnd = 1
cwnd = 2 segment 2segment 3
ACK for segments 2
cwnd = 4 segment 4segment 5segment 6
ACK for segments 4
cwnd = 7
ACK for segments 3
ACK for segments 5
ACK for segments 6
cwnd = 3
cwnd = 5
cwnd = 6ACK for segments 7
cwnd = 8
segment 7
Transport Layer 3-84
TCP Congestion Avoidance Phase
when cwnd gt ssthreshgrow cwnd linearly
increase cwnd by 1 MSS per RTT approach possible congestion slower than in slowstartimplementation cwnd= cwnd + MSScwndfor each ACK received
ACKs increase cwndby 1 MSS per RTT additive increaseloss cut cwnd in half (non-timeout-detected loss ) multiplicative decrease
AIMD
AIMD Additive IncreaseMultiplicative Decrease
Transport Layer 3-85
Congestion AvoidanceCongestion avoidance phase is started if CongWin has reached the slow-start threshold value
If CongWin gt= ssthresh then each time an ACK is received increment CongWin as follows
bull CongWin = CongWin + 1CongWin (CongWin in segments)
bull In actual TCP implementation CongWin is in BytesCongWin = CongWin + MSS (MSSCongWin)
So CongWin is increased by one only if all CongWinsegments have been acknowledged
Transport Layer 3-86
Example Slow StartCongestion AvoidanceAssume that
ssthresh = 8
cwnd = 1
cwnd = 2
cwnd = 4
cwnd = 8
cwnd = 9
cwnd = 10
02468
101214
t=0
t=2
t=4
t=6
Roundtrip times
Cw
nd(in
seg
men
ts)
ssthresh
cwnd = 3
cwnd = 5cwnd = 6cwnd = 7
Transport Layer 3-87
Slow Start Congestion AvoidanceA typical plot of CongWin for a TCP connection
(MSS = 1500 bytes) with TCP Tahoe
SS
CA
ssthresh
Transport Layer 3-88
Responses to CongestionTCP assumes there is congestion if it detects a packet lossA TCP sender can detect lost packets via loss events
bull Timeout of a retransmission timerbull Receipt of 3 duplicate ACKs (fast retransmit)
TCP interprets a Timeout as a binary congestion signal When a timeout occurs the sender performs
ssthresh is set to half the current size of the congestion window
ssthresh = CongWin 2CongWin is reset to one
CongWin = 1and slow-start is entered
Transport Layer 3-89
Fast Recovery (differentiation btwn two loss events) After 3 dup ACKs (fast Retransmit)
ssthresh = CongWin2CongWin = CongWin2window then grows linearly
But after timeout eventCongWin = 1 MSS window then grows exponentiallyto the threshold then grows linearly
bull 3 dup ACKs indicates network capable of delivering some segmentsbull timeout before 3 dup ACKs is ldquomore alarmingrdquo
Philosophy
3-90
TCP Congestion ControlInitially
CongWin = 1ssthresh = advertised window size
New Ack receivedif (CongWin lt ssthresh) Slow Start
CongWin = CongWin + 1else Congestion Avoidance
CongWin = CongWin + 1CongWinTimeout
ssthresh = CongWin2CongWin = 1
Fast Retransmissionssthresh = CongWin2CongWin = CongWin2
Slow Start (exponential increase phase) is continued until CongWin reaches half of the level where the loss event occurred last time CongWin is increased slowly after (linear increase in Congestion Avoidance phase)
Transport Layer 3-91
Popular ldquoflavorsrdquo of TCP
ssthresh
ssthresh
TCP Tahoe
TCP Reno
Transmission round
cwnd
win
dow
siz
e (in
seg
men
ts)
Transport Layer 3-92
Summary TCP Congestion ControlWhen CongWin is below Threshold sender in slow-start phase window grows exponentiallyWhen CongWin is above Threshold sender is in congestion-avoidance phase window grows linearlyWhen a triple duplicate ACK occurs Threshold set to CongWin2 and CongWin set to ThresholdWhen timeout occurs Threshold set to CongWin2 and CongWin is set to 1 MSS The actual sender window size is determined based on the congestion and flow control algorithms
SenderWin=min(RcvWinCongWin)
Transport Layer 3-93
TCP Congestion Control SummaryEvent State TCP Sender Action Commentary
ACK receipt for previously unackeddata
Slow Start (SS)
CongWin = CongWin + MSS If (CongWin gt Threshold)
set state to ldquoCongestion Avoidancerdquo
Resulting in a doubling of CongWin every RTT
ACK receipt for previously unackeddata
CongestionAvoidance (CA)
CongWin = CongWin+MSS (MSSCongWin)
Additive increase resulting in increase of CongWin by 1 MSS every RTT
Loss event detected by triple duplicate ACK
SS or CA Threshold = CongWin2 CongWin = ThresholdSet state to ldquoCongestion Avoidancerdquo
Fast recovery implementing multiplicative decrease CongWin will not drop below 1 MSS
Timeout SS or CA Threshold = CongWin2 CongWin = 1 MSSSet state to ldquoSlow Startrdquo
Enter slow start
Duplicate ACK
SS or CA Increment duplicate ACK count for segment being acked
CongWin and Threshold not changed
Transport Layer 3-94
TCP throughput
Q whatrsquos average throughout of TCP as function of window size RTT
ignoring slow startlet W be window size when loss occurs
when window is W throughput is WRTTjust after loss window drops to W2 throughput to W2RTT average throughout 75 WRTT
Transport Layer 3-95
TCP Futures TCP over ldquolong fat pipesrdquo
example 1500 byte segments 100ms RTT want 10 Gbps throughputrequires window size W = 83333 in-flight segmentsthroughput in terms of loss rate
L = 210-10 Wownew versions of TCP for high-speed
LRTTMSSsdot221
Transport Layer 3-96
Fairness goal if K TCP sessions share same bottleneck link of bandwidth R each should have average rate of RK
TCP connection 1
bottleneckrouter
capacity R
TCP connection 2
TCP Fairness
Transport Layer 3-97
Why is TCP fairTwo competing sessions
Additive increase gives slope of 1 as throughout increasesmultiplicative decrease decreases throughput proportionally
R
R
equal bandwidth share
Connection 1 throughput
Conn
ecti
on 2
thr
ough
p ut
congestion avoidance additive increaseloss decrease window by factor of 2
congestion avoidance additive increaseloss decrease window by factor of 2
Transport Layer 3-98
Fairness (more)Fairness and UDP
Multimedia apps often do not use TCP
do not want rate throttled by congestion control
Instead use UDPpump audiovideo at constant rate tolerate packet loss
Research area TCP friendly
Fairness and parallel TCP connectionsnothing prevents app from opening parallel cnctionsbetween 2 hostsWeb browsers do this Example link of rate R supporting 9 cnctions
new app asks for 1 TCP gets rate R10new app asks for 11 TCPs gets R2
Transport Layer 3-99
TCP Connection ManagementRecall TCP sender receiver
establish ldquoconnectionrdquobefore exchanging data segmentsinitialize TCP variables
seq sbuffers flow control info (eg RcvWindow)
client connection initiatorSocket clientSocket = new Socket(hostnameport
number)
server contacted by clientSocket connectionSocket = welcomeSocketaccept()
Three way handshakeStep 1 client host sends TCP
SYN segment to serverspecifies initial seq no data
Step 2 server host receives SYN replies with SYNACK segment
server allocates buffersspecifies server initial seq
Step 3 client receives SYNACK replies with ACK segment which may contain data
Transport Layer 3-100
TCP Connection Management (cont)
Closing a connection
client closes socketclientSocketclose()
Step 1 client end system sends TCP FIN control segment to server
Step 2 server receives FIN replies with ACK Closes connection sends FIN
client
FIN
server
ACK
ACK
FIN
close
close
closed
tim
ed w
ait
Transport Layer 3-101
TCP Connection Management (cont)
Step 3 client receives FIN replies with ACK
Enters ldquotimed waitrdquo -will respond with ACK to received FINs
Step 4 server receives ACK Connection closed
client
FIN
server
ACK
ACK
FIN
closing
closing
closed
tim
ed w
ait
closed
Transport Layer 3-102
TCP Connection Management (cont)
TCP clientlifecycle
TCP serverlifecycle
Transport Layer 3-103
Tuning TCPIP Parameters TCPIP parameters
A set of default values may not be optimal for all applicationsThe network administrator may wish to turn on or off some TCPIP functions for performance or security considerations
Many Unix and Linux systems provide some flexibility in tuning the TCPIP kernelsbinsysctl is used to configure the Linux kernel parameters at runtime
Default kernel configuration file is sbinsysctlconfFrequently used sysctl options
bull sysctl ndasha or sysctl ndashA list all current valuesbull sysctl ndashp file_name load the sysctl setting from a configuration
filebull sysctl ndashw variable=value change the value of the parameter
Transport Layer 3-104
SomeTCP Parameters in Linux Kerneltcp_syn_retries
Number of SYN packets the kernel will send before giving up on the new connection
tcp_synack_retriesnumber of SYN+ACK packets sent before the kernel gives up on the connection
tcp_window_scalingMaximum window size of 65535 bytes not enough for for really fast networks The window scaling options allows for almost gigabyte windows which is good for connections with large delay-bandwidth product
tcp_max_syn_backlogMaximal number of remembered connection requests which still did not receive an acknowledgment from connecting client
tcp_fin_timeoutHow many seconds to wait for a final FIN packet before the socket is closed required to prevent denial-of-service (DoS) attacks Default value is 60 seconds
Transport Layer 3-105
SomeTCP Parameters in Linux Kerneltcp_rmem
This is a vector of 3 integers [min default max] These parameters are used by TCP to dynamically adjust receive buffer sizesmin - minimum size of the receive buffer used by each TCP socket The default value is 4K default - the default size of the receive buffer for a TCP socket The default value is 87380 bytes and is lowered to 43689 in low memory systems If larger receive buffer sizes are desired this value should be increased max - the maximum size of the receive buffer used by each TCP socket The default value of 873802 bytes is lowered to 87380 in low memory systems
tcp_smemSend buffer parameters [min default max] similar to tcp_rmem
- Chapter 3 Transport Layer
- Transport services and protocols
- Transport vs network layer
- Internet transport-layer protocols
- Multiplexingdemultiplexing
- How demultiplexing works
- Connectionless demultiplexing
- Connection-oriented demux
- Connection-oriented demux (cont)
- Connection-oriented demux Threaded Web Server
- UDP User Datagram Protocol [RFC 768]
- UDP more
- UDP checksum
- Principles of Reliable data transfer
- Reliable data transfer getting started
- Reliable data transfer getting started
- Rdt10 reliable transfer over a reliable channel
- Rdt20 channel with bit errors
- rdt20 FSM specification
- rdt20 operation with no errors
- rdt20 error scenario
- rdt20 has a fatal flaw
- rdt21 sender handles garbled ACKNAKs
- rdt21 receiver handles garbled ACKNAKs
- rdt21 discussion
- rdt22 a NAK-free protocol
- rdt22 sender receiver fragments
- rdt30 channels with errors and loss
- rdt30 sender
- rdt30 in action
- rdt30 in action
- Performance of rdt30
- rdt30 stop-and-wait operation
- Pipelined protocols
- Pipelining increased utilization
- Go-Back-N
- GBN sender extended FSM
- GBN receiver extended FSM
- GBN inaction
- Selective Repeat
- Selective repeat sender receiver windows
- Selective repeat
- Selective repeat in action
- Selective repeat dilemma
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- TCP Overview RFCs 793 1122 1323 2018 2581
- TCP segment structure
- TCP seq rsquos and ACKs
- TCP Round Trip Time and Timeout
- TCP Round Trip Time and Timeout
- Example RTT estimation
- TCP Round Trip Time and Timeout
- TCP reliable data transfer
- TCP sender events
- TCP sender(simplified)
- TCP retransmission scenarios
- TCP retransmission scenarios (more)
- TCP ACK generation [RFC 1122 RFC 2581]
- Fast Retransmit
- Fast Retransmit
- Fast retransmit algorithm
- TCP Flow Control
- TCP Flow control how it works
- Sliding Window Flow Control Example
- Principles of Congestion Control
- Causescosts of congestion scenario 1
- Causescosts of congestion scenario 2
- Causescosts of congestion scenario 2
- Causescosts of congestion scenario 3
- Causescosts of congestion scenario 3
- Approaches towards congestion control
- TCP Congestion Control
- TCP congestion control bandwidth probing
- TCP Congestion Control details
- TCP Congestion Control more details
- TCP Slow Start Phase
- Slow Start Example
- TCP Congestion Avoidance Phase
- Congestion Avoidance
- Example Slow StartCongestion Avoidance
- Slow Start Congestion Avoidance
- Responses to Congestion
- Fast Recovery (differentiation btwn two loss events)
- TCP Congestion Control
- Popular ldquoflavorsrdquo of TCP
- Summary TCP Congestion Control
- TCP Congestion Control Summary
- TCP throughput
- TCP Futures TCP over ldquolong fat pipesrdquo
- TCP Fairness
- Why is TCP fair
- Fairness (more)
- TCP Connection Management
- TCP Connection Management (cont)
- TCP Connection Management (cont)
- TCP Connection Management (cont)
- Tuning TCPIP Parameters
- SomeTCP Parameters in Linux Kernel
- SomeTCP Parameters in Linux Kernel
-
Transport Layer 3-25
rdt21 discussion
Senderseq added to pkttwo seq rsquos (01) will suffice Whymust check if received ACKNAK corrupted twice as many states
state must ldquorememberrdquowhether ldquocurrentrdquo pkt has 0 or 1 seq
Receivermust check if received packet is duplicate
state indicates whether 0 or 1 is expected pkt seq
note receiver can notknow if its last ACKNAK received OK at sender
Transport Layer 3-26
rdt22 a NAK-free protocol
same functionality as rdt21 using ACKs onlyinstead of NAK receiver sends ACK for last pkt received OK
receiver must explicitly include seq of pkt being ACKed duplicate ACK at sender results in same action as NAK retransmit current pkt
Transport Layer 3-27
rdt22 sender receiver fragments
Wait for call 0 from
above
sndpkt = make_pkt(0 data checksum)udt_send(sndpkt)
rdt_send(data)
udt_send(sndpkt)
rdt_rcv(rcvpkt) ampamp ( corrupt(rcvpkt) ||
isACK(rcvpkt1) )
rdt_rcv(rcvpkt) ampamp notcorrupt(rcvpkt) ampamp isACK(rcvpkt0)
Wait for ACK
0sender FSM
fragment
Wait for 0 from below
rdt_rcv(rcvpkt) ampamp notcorrupt(rcvpkt) ampamp has_seq1(rcvpkt)
extract(rcvpktdata)deliver_data(data)sndpkt = make_pkt(ACK1 chksum)udt_send(sndpkt)
rdt_rcv(rcvpkt) ampamp (corrupt(rcvpkt) ||
has_seq1(rcvpkt))
udt_send(sndpkt)receiver FSM
fragment
Λ
Transport Layer 3-28
rdt30 channels with errors and loss
New assumptionunderlying channel can also lose packets (data or ACKs)
checksum seq ACKs retransmissions will be of help but not enough
Q how to deal with losssender waits until certain data or ACK lost then retransmitsdrawbacks
Approach sender waits ldquoreasonablerdquo amount of time for ACK retransmits if no ACK received in this timeif pkt (or ACK) just delayed (not lost)
retransmission will be duplicate but use of seq rsquos already handles thisreceiver must specify seq of pkt being ACKed
requires countdown timer
Transport Layer 3-29
rdt30 sendersndpkt = make_pkt(0 data checksum)udt_send(sndpkt)start_timer
rdt_send(data)
Wait for
ACK0
rdt_rcv(rcvpkt) ampamp ( corrupt(rcvpkt) ||isACK(rcvpkt1) )
Wait for call 1 from
above
sndpkt = make_pkt(1 data checksum)udt_send(sndpkt)start_timer
rdt_send(data)
rdt_rcv(rcvpkt) ampamp notcorrupt(rcvpkt) ampamp isACK(rcvpkt0)
rdt_rcv(rcvpkt) ampamp ( corrupt(rcvpkt) ||isACK(rcvpkt0) )
rdt_rcv(rcvpkt) ampamp notcorrupt(rcvpkt) ampamp isACK(rcvpkt1)
stop_timerstop_timer
udt_send(sndpkt)start_timer
timeout
udt_send(sndpkt)start_timer
timeout
rdt_rcv(rcvpkt)
Wait for call 0from
above
Wait for
ACK1
Λrdt_rcv(rcvpkt)
ΛΛ
Λ
Transport Layer 3-30
rdt30 in action
Transport Layer 3-31
rdt30 in action
Transport Layer 3-32
Performance of rdt30
rdt30 works but performance stinksexample 1 Gbps link 15 ms e-e prop delay 1KB packet
Ttransmit = 8kbpkt109 bsec = 8 microsec
U sender utilization ndash fraction of time sender busy sending1KB pkt every 30 msec -gt 33kBsec thruput over 1 Gbps linknetwork protocol limits use of physical resources
U sender=
008 30008
= 000027 L RRTT + L R
=
L (packet length in bits)R (transmission rate bps) =
Transport Layer 3-33
rdt30 stop-and-wait operation
first packet bit transmitted t = 0
sender receiver
RTT
last packet bit transmitted t = L R
first packet bit arriveslast packet bit arrives send ACK
ACK arrives send next packet t = RTT + L R
U sender=
00830008
= 000027 L RRTT + L R
=
Transport Layer 3-34
Pipelined protocolsPipelining sender allows multiple ldquoin-flightrdquo yet-to-
be-acknowledged pktsrange of sequence numbers must be increasedbuffering at sender andor receiver
Two generic forms of pipelined protocols go-Back-N selective repeat
Transport Layer 3-35
Pipelining increased utilization
first packet bit transmitted t = 0
sender receiver
RTT
last bit transmitted t = L R
first packet bit arriveslast packet bit arrives send ACK
ACK arrives send next packet t = RTT + L R
last bit of 2nd packet arrives send ACKlast bit of 3rd packet arrives send ACK
U sender=
024 30008
= 000083 L RRTT + L R
=
Increase utilizationby a factor of 3
Transport Layer 3-36
Utilization=N(LR)(RTT+LR) if NLRltRTT+LR Utilization=1 if and the sender pauses after it transmits a window NLRgtRTT+LR and the of packets until it receives first ACK sender does not pause
Transport Layer 3-37
Go-Back-NSender
k-bit seq in pkt headerldquowindowrdquo of up to N consecutive unackrsquoed pkts allowed
ACK(n) ACKs all pkts up to including seq n - ldquocumulative ACKrdquomay receive duplicate ACKs (see receiver)
timer for the entire windowtimeout(n) retransmit pkt n and all higher seq pkts in window
Transport Layer 3-38
GBN sender extended FSM
Wait start_timerudt_send(sndpkt[base])udt_send(sndpkt[base+1])hellipudt_send(sndpkt[nextseqnum-1])
timeout
rdt_send(data)
if (nextseqnum lt base+N) sndpkt[nextseqnum] = make_pkt(nextseqnumdatachksum)udt_send(sndpkt[nextseqnum])if (base == nextseqnum)
start_timernextseqnum++
elserefuse_data(data)
base = getacknum(rcvpkt)+1If (base == nextseqnum)
stop_timerelse
start_timer
rdt_rcv(rcvpkt) ampamp notcorrupt(rcvpkt)
base=1nextseqnum=1
rdt_rcv(rcvpkt) ampamp corrupt(rcvpkt)
Λ
Λ
Transport Layer 3-39
GBN receiver extended FSM
ACK-only always send ACK for correctly-received pktwith highest in-order seq
may generate duplicate ACKsneed only remember expectedseqnum
out-of-order pkt discard (donrsquot buffer) -gt no receiver bufferingRe-ACK pkt with highest in-order seq
Wait
udt_send(sndpkt)default
rdt_rcv(rcvpkt)ampamp notcurrupt(rcvpkt)ampamp hasseqnum(rcvpktexpectedseqnum)
extract(rcvpktdata)deliver_data(data)sndpkt = make_pkt(expectedseqnumACKchksum)udt_send(sndpkt)expectedseqnum++
expectedseqnum=1sndpkt =
make_pkt(0ACKchksum)
Λ
Transport Layer 3-40
GBN inaction
Transport Layer 3-41
Selective Repeat
receiver individually acknowledges all correctly received pkts
buffers pkts as needed for eventual in-order delivery to upper layer
sender only resends pkts for which ACK not received
sender timer for each unACKed pktsender window
N consecutive seq rsquosagain limits seq s of sent unACKed pkts
Transport Layer 3-42
Selective repeat sender receiver windows
Transport Layer 3-43
Selective repeat
data from above if next available seq in window send pkt
timeout(n)resend pkt n restart timer
ACK(n) in [sendbasesendbase+N-1]
mark pkt n as receivedif n smallest unACKed pkt advance window base to next unACKed seq
senderpkt n in [rcvbase rcvbase+N-1]
send ACK(n)out-of-order bufferin-order deliver (also deliver buffered in-order pkts) advance window to next not-yet-received pkt
pkt n in [rcvbase-Nrcvbase-1]
ACK(n)otherwise
ignore
receiver
Transport Layer 3-44
Selective repeat in action
Transport Layer 3-45
Selective repeatdilemma
Example seq rsquos 0 1 2 3window size=3
receiver sees no difference in two scenariosincorrectly passes duplicate data as new in (a)
Q what relationship between seq size and window size
Transport Layer 3-46
Sequence Number vs Window SizeSuppose we use k bits to represent SNQuestion Whatrsquos the minimum number of bits k necessary for a window size of N
sender
receiver
Go-Back-N
expectedSN
snd_base=expectedSN
Q For a given expectedSN whatrsquos the largest possible value for snd_baseA If all the last N ACKs sent by the receiver are received
snd_base = expectedSNexpectedSN+N-1
senderrsquos window
Transport Layer 3-47
Sequence Number vs Window SizeSuppose we use k bits to represent SNQuestion Whatrsquos the minimum number of bits k necessary for a window size of N
sender
receiver
Go-Back-N
expectedSN
snd_base=expectedSN-N
Q For a given expectedSN whatrsquos the smallest possible value for snd_baseA If all the last N ACKs sent by the receiver are not received
snd_base = expectedSN-NexpectedSN-1
senderrsquos window
Transport Layer 3-48
Sequence Number vs Window Size
sender
receiver
Go-Back-N
expectedSN
snd_base=expectedSN-N
All SNs in the interval [expectedSN-NexpectedSN+N-1] (an interval of size 2N) can be received by the receiver Since the receiver accepts on the packet with SN=expectedSN there should be no other packet within this interval with SN=expectedSN Therefore
2k ge N+1expectedSN+N-1
Transport Layer 3-49
Sequence Number vs Window SizeSuppose we use k bits to represent SNQuestion Whatrsquos the minimum number of bits k necessary for a window size of N
sender
receiver
Selective Repeat
rcv_base
snd_base=rcv_base
Q For a given rcv_base whatrsquos the largest possible value for snd_baseA If all the last N ACKs sent by the receiver are received
snd_base = rcv_base (same as go_back-N)rcv_base+N-1
senderrsquos window
receiverrsquos window
rcv_base+N-1
Transport Layer 3-50
Sequence Number vs Window SizeSuppose we use k bits to represent SNQuestion Whatrsquos the minimum number of bits k necessary for a window size of N
sender
receiver
Selective Repeat
rcv_base
snd_base=rcv_base-N
Q For a given rcv_base whatrsquos the smallest possible value for snd_baseA If all the last N ACKs sent by the receiver are not received
snd_base = rcv_base-N (same as Go-Back-N)rcv_base-1
senderrsquos window
rcv_base
receiverrsquos window
rcv_base+N-1
Transport Layer 3-51
Sequence Number vs Window Size
sender
receiver
Selective Repeat
snd_base=rcv_base-N
All SNs in the interval [rcv_base-Nrcv_base+N-1] (an interval of size 2N) can be received by the receiver Since the receiver should be able to distinguish between all packets in this interval and take corresponding action there should be no two packets within thisinterval having the same SN Therefore
2k ge 2Nrcv_base+N-1
rcv_basercv_base
receiverrsquos window
rcv_base+N-1
Transport Layer 3-52
TCP Overview RFCs 793 1122 1323 2018 2581
full duplex databi-directional data flow in same connectionMSS maximum segment size
connection-orientedhandshaking (exchange of control msgs) initrsquossender receiver state before data exchange
flow controlledsender will not overwhelm receiver
point-to-pointone sender one receiver
reliable in-order byte stream
no ldquomessage boundariesrdquopipelined
TCP congestion and flow control set window size
send amp receive buffers
socketdoor
TCPsend buffer
TCPreceive buffer
socketdoor
segment
applicationwrites data
applicationreads data
Transport Layer 3-53
TCP segment structure
source port dest port
32 bits
applicationdata
(variable length)
sequence numberacknowledgement number
Receive windowUrg data pnterchecksum
FSRPAUheadlen
notused
Options (variable length)
URG urgent data (generally not used)
ACK ACK valid
PSH push data now(generally not used)
RST SYN FINconnection estab(setup teardown
commands)
bytes rcvr willingto accept
Internetchecksum
(as in UDP)
countingby bytes of data(not segments)
Transport Layer 3-54
TCP seq rsquos and ACKsSeq rsquos
byte stream ldquonumberrdquo of first byte in segmentrsquos dataACKs
seq of next byte expected from other sidecumulative ACK
Q how receiver handles out-of-order segmentsA TCP spec doesnrsquot say - up to implementationWidely used implementations of TCP buffer out-of-order segments
Transport Layer 3-55
TCP Round Trip Time and Timeout
Q how to set TCP timeout valuelonger than RTT
but RTT variestoo short premature timeout
unnecessary retransmissions
too long slow reaction to segment loss
Q how to estimate RTTSampleRTT measured time from segment transmission until ACK receipt
ignore retransmissionsSampleRTT will vary want estimated RTT ldquosmootherrdquo
average several recent measurements not just current SampleRTT
Transport Layer 3-56
TCP Round Trip Time and Timeout
EstimatedRTT = (1- α)EstimatedRTT + αSampleRTT
Exponential weighted moving averageinfluence of past sample decreases exponentially fasttypical value α = 0125
Transport Layer 3-57
Example RTT estimationRTT gaiacsumassedu to fantasiaeurecomfr
100
150
200
250
300
350
1 8 15 22 29 36 43 50 57 64 71 78 85 92 99 106
time (seconnds)
RTT
(mill
iseco
nds)
SampleRTT Estimated RTT
Transport Layer 3-58
TCP Round Trip Time and TimeoutSetting the timeout
EstimatedRTT plus ldquosafety marginrdquolarge variation in EstimatedRTT -gt larger safety margin
first estimate of how much SampleRTT deviates from EstimatedRTT
TimeoutInterval = EstimatedRTT + 4DevRTT
DevRTT = (1-β)DevRTT +β|SampleRTT-EstimatedRTT|
(typically β = 025)
Then set timeout interval
Transport Layer 3-59
TCP reliable data transfer
TCP creates rdtservice on top of IPrsquos unreliable servicePipelined segmentsCumulative acksTCP uses single retransmission timer however it just retransmits the first segment in the window
Retransmissions are triggered by
timeout eventsduplicate acks
Initially consider simplified TCP sender
ignore duplicate acksignore flow control congestion control
Transport Layer 3-60
TCP sender eventsdata rcvd from app
Create segment with seq seq is byte-stream number of first data byte in segmentstart timer if not already running (think of timer as for oldest unacked segment)expiration interval TimeOutInterval
timeoutretransmit segment that caused timeout (first segment in the window)restart timer
Ack rcvdIf acknowledges previously unacked segments
update what is known to be ackedstart timer if there are outstanding segments
Transport Layer 3-61
TCP sender(simplified)
NextSeqNum = InitialSeqNumSendBase = InitialSeqNum
loop (forever) switch(event)
event data received from application above create TCP segment with sequence number NextSeqNumif (timer currently not running)
start timerpass segment to IP NextSeqNum = NextSeqNum + length(data)
event timer timeoutretransmit not-yet-acknowledged segment with
smallest sequence numberstart timer
event ACK received with ACK field value of y if (y gt SendBase)
SendBase = yif (there are currently not-yet-acknowledged segments)
start timer
end of loop forever
Commentbull SendBase-1 last cumulatively ackrsquoed byteExamplebull SendBase-1 = 71y= 73 so the rcvrwants 73+ y gt SendBase sothat new data is acked
Transport Layer 3-62
TCP retransmission scenariosHost A
Seq=100 20 bytes data
ACK=100
timepremature timeout
Host B
Seq=92 8 bytes data
ACK=120
Seq=92 8 bytes data
Seq=
92 t
imeo
ut
ACK=120
Host A
Seq=92 8 bytes data
ACK=100
loss
tim
eout
lost ACK scenario
Host B
X
Seq=92 8 bytes data
ACK=100
time
Seq=
92 t
imeo
utSendBase
= 100
SendBase= 120
SendBase= 120
Sendbase= 100
Transport Layer 3-63
TCP retransmission scenarios (more)Host A
Seq=92 8 bytes data
ACK=100
loss
tim
eout
Cumulative ACK scenario
Host B
X
Seq=100 20 bytes data
ACK=120
time
SendBase= 120
Transport Layer 3-64
TCP ACK generation [RFC 1122 RFC 2581]
Event at Receiver
Arrival of in-order segment withexpected seq All data up toexpected seq already ACKed
Arrival of in-order segment withexpected seq One other segment has ACK pending
Arrival of out-of-order segmenthigher-than-expect seq Gap detected
Arrival of segment that partially or completely fills gap
TCP Receiver action
Delayed ACK Wait up to 500msfor next segment If no next segmentsend ACK
Immediately send single cumulative ACK ACKing both in-order segments
Immediately send duplicate ACK indicating seq of next expected byte
Immediate send ACK provided thatsegment startsat lower end of gap
Transport Layer 3-65
Fast Retransmit
Time-out period often relatively long
long delay before resending lost packet
Detect lost segments via duplicate ACKs
Sender often sends many segments back-to-backIf segment is lost there will likely be many duplicate ACKs
If sender receives 3 ACKs for the same data it supposes that segment after ACKeddata was lost
fast retransmit resend segment before timer expires
Transport Layer 3-66
Fast RetransmitResend a segment after 3 duplicate ACKs since a duplicate ACK means that an out-of sequence segment was receivedduplicate ACKs due to packet reorderingif window is small donrsquot get duplicate ACKs
Host A
tim
eout
Host B
time
X
resend seq X2
seq x1seq x2seq x3seq x4seq x5
ACK x1
ACK x1ACK x1ACK x1
tripleduplicate
ACKs
Transport Layer 3-67
event ACK received with ACK field value of y if (y gt SendBase)
SendBase = yif (there are currently not-yet-acknowledged segments)
start timer
else increment count of dup ACKs received for yif (count of dup ACKs received for y = 3)
resend segment with sequence number y
Fast retransmit algorithm
a duplicate ACK for already ACKed segment
fast retransmit
Transport Layer 3-68
TCP Flow Control
receive side of TCP connection has a receive buffer
speed-matching service matching the send rate to the receiving apprsquos drain rate
app process may be slow at reading from buffer
sender wonrsquot overflowreceiverrsquos buffer by
transmitting too muchtoo fast
flow control
Transport Layer 3-69
TCP Flow control how it works
(Suppose TCP receiver discards out-of-order segments)spare room in buffer
= RcvWin
= RcvBuffer-[LastByteRcvd -LastByteRead]
Rcvr advertises spare room by including value of RcvWin in segmentsSender limits unACKeddata to RcvWin
guarantees receive buffer doesnrsquot overflow
Transport Layer 3-70
Sliding Window Flow Control Example
3K
2K SeqNo=0
ReceiverBuffer
0 4KSendersends 2Kof data
2K
AckNo=2048 RcvWin=2048Sendersends 2Kof data 2K SeqNo=2048
4K
AckNo=4096 RcvWin=0
AckNo=4096 RcvWin=1024
Sender blocked
Transport Layer 3-71
Principles of Congestion Control
Congestioninformally ldquotoo many sources sending too much data too fast for network to handlerdquodifferent from flow controlmanifestations
lost packets (buffer overflow at routers)long delays (queueing in router buffers)
a top-10 problem
Transport Layer 3-72
Causescosts of congestion scenario 1
two senders two receiversone router infinite buffers no retransmission
large delays when congestedmaximum achievable throughput
unlimited shared output link buffers
Host Aλin original data
Host B
λout
Transport Layer 3-73
Causescosts of congestion scenario 2
one router finite buffers sender retransmission of lost packet
finite shared output link buffers
Host A λin original data
Host B
λout
λin original data plus retransmitted data
Transport Layer 3-74
Causescosts of congestion scenario 2always (goodput)ldquoperfectrdquo retransmission only when loss
retransmission of delayed (not lost) packet makes larger(than perfect case) for same
λin
λout=
λin
λoutgtλ
inλout
ldquocostsrdquo of congestionmore work (retrans) for given ldquogoodputrdquounneeded retransmissions link carries multiple copies of pkt
R2
R2λin
λ out
b
R2
R2λin
λ out
a
R2
R2λin
λ out
c
R4
R3
Transport Layer 3-75
Causescosts of congestion scenario 3four sendersmultihop pathstimeoutretransmit
λin
Q what happens as and increase λ
in
finite shared output link buffers
Host Aλin original data
Host B
λout
λin original data plus retransmitted data
Transport Layer 3-76
Causescosts of congestion scenario 3
another ldquocostrdquo of congestionwhen packet dropped any ldquoupstream transmission capacity used for that packet was wasted
Host A
Host B
λou
t
Transport Layer 3-77
Approaches towards congestion control
End-end congestion controlno explicit feedback from networkcongestion inferred from end-system observed loss delayapproach taken by TCP
Network-assisted congestion controlrouters provide feedback to end systems
single bit indicating congestion (SNA DECbit TCPIP ECN ATM)explicit rate sender should send at
Two broad approaches towards congestion control
Transport Layer 3-78
TCP Congestion Control
end-end control (no network assistance)sender limits transmissionLastByteSent-LastByteAcked
le CongWin
CongWin is dynamic function of perceived network congestion
How does sender perceive congestionloss event = timeout or3 duplicate acksTCP sender reduces rate (CongWin) after loss event
two modes of operationSlow Start (SS)Congestion avoidance (CA) or Additive Increase Multiplicative Decrease (AIMD)
Transport Layer 3-79
TCP congestion control bandwidth probing
ldquoprobing for bandwidthrdquo increase transmission rate on receipt of ACK until eventually loss occurs then decrease transmission rate
continue to increase on ACK decrease on loss (since available bandwidth is changing depending on other connections in network)
ACKs being received so increase rate
X
X
XX
X loss so decrease rate
send
ing
rate
time
Q how fast to increasedecreasedetails to follow
TCPrsquosldquosawtoothrdquobehavior
Transport Layer 3-80
TCP Congestion Control details
sender limits rate by limiting number of unACKed bytes ldquoin pipelinerdquo
cwnd differs from rwnd (how why)sender limited by min(cwndrwnd)
roughly
cwnd is dynamic function of perceived network congestion
rate = cwndRTT bytessec
LastByteSent-LastByteAcked le cwnd
cwndbytes
RTT
ACK(s)
Transport Layer 3-81
TCP Congestion Control more details
segment loss event reducing cwndtimeout no response from receiver
cut cwnd to 13 duplicate ACKs at least some segments getting through (recall fast retransmit)
cut cwnd in half less aggressively than on timeout
ACK received increase cwndTwo modes of operation
slowstart phase bull increase exponentially
fast (despite name) at connection start or following timeout
congestion avoidance bull increase linearly
Transport Layer 3-82
TCP Slow Start Phasewhen connection begins cwnd = 1 MSS
example MSS = 500 bytes amp RTT = 200 msecinitial rate = 20 kbps
available bandwidth may be gtgt MSSRTT
desirable to quickly ramp up to respectable rate
increase rate exponentially until first loss event or when threshold reached
double cwnd every RTTdone by incrementing cwnd by 1 for every ACK received
Host A
one segment
RTT
Host B
time
two segments
four segments
Transport Layer 3-83
Slow Start ExampleThe congestion window size grows very rapidly
For every ACK we increase CongWin by 1 irrespective of the number of segments ACKrsquoeddouble CongWinevery RTTinitial rate is slow but ramps up exponentially fast
TCP slows down the increase of CongWinwhen CongWin gt ssthresh
segment 1
ACK for segment 1
cwnd = 1
cwnd = 2 segment 2segment 3
ACK for segments 2
cwnd = 4 segment 4segment 5segment 6
ACK for segments 4
cwnd = 7
ACK for segments 3
ACK for segments 5
ACK for segments 6
cwnd = 3
cwnd = 5
cwnd = 6ACK for segments 7
cwnd = 8
segment 7
Transport Layer 3-84
TCP Congestion Avoidance Phase
when cwnd gt ssthreshgrow cwnd linearly
increase cwnd by 1 MSS per RTT approach possible congestion slower than in slowstartimplementation cwnd= cwnd + MSScwndfor each ACK received
ACKs increase cwndby 1 MSS per RTT additive increaseloss cut cwnd in half (non-timeout-detected loss ) multiplicative decrease
AIMD
AIMD Additive IncreaseMultiplicative Decrease
Transport Layer 3-85
Congestion AvoidanceCongestion avoidance phase is started if CongWin has reached the slow-start threshold value
If CongWin gt= ssthresh then each time an ACK is received increment CongWin as follows
bull CongWin = CongWin + 1CongWin (CongWin in segments)
bull In actual TCP implementation CongWin is in BytesCongWin = CongWin + MSS (MSSCongWin)
So CongWin is increased by one only if all CongWinsegments have been acknowledged
Transport Layer 3-86
Example Slow StartCongestion AvoidanceAssume that
ssthresh = 8
cwnd = 1
cwnd = 2
cwnd = 4
cwnd = 8
cwnd = 9
cwnd = 10
02468
101214
t=0
t=2
t=4
t=6
Roundtrip times
Cw
nd(in
seg
men
ts)
ssthresh
cwnd = 3
cwnd = 5cwnd = 6cwnd = 7
Transport Layer 3-87
Slow Start Congestion AvoidanceA typical plot of CongWin for a TCP connection
(MSS = 1500 bytes) with TCP Tahoe
SS
CA
ssthresh
Transport Layer 3-88
Responses to CongestionTCP assumes there is congestion if it detects a packet lossA TCP sender can detect lost packets via loss events
bull Timeout of a retransmission timerbull Receipt of 3 duplicate ACKs (fast retransmit)
TCP interprets a Timeout as a binary congestion signal When a timeout occurs the sender performs
ssthresh is set to half the current size of the congestion window
ssthresh = CongWin 2CongWin is reset to one
CongWin = 1and slow-start is entered
Transport Layer 3-89
Fast Recovery (differentiation btwn two loss events) After 3 dup ACKs (fast Retransmit)
ssthresh = CongWin2CongWin = CongWin2window then grows linearly
But after timeout eventCongWin = 1 MSS window then grows exponentiallyto the threshold then grows linearly
bull 3 dup ACKs indicates network capable of delivering some segmentsbull timeout before 3 dup ACKs is ldquomore alarmingrdquo
Philosophy
3-90
TCP Congestion ControlInitially
CongWin = 1ssthresh = advertised window size
New Ack receivedif (CongWin lt ssthresh) Slow Start
CongWin = CongWin + 1else Congestion Avoidance
CongWin = CongWin + 1CongWinTimeout
ssthresh = CongWin2CongWin = 1
Fast Retransmissionssthresh = CongWin2CongWin = CongWin2
Slow Start (exponential increase phase) is continued until CongWin reaches half of the level where the loss event occurred last time CongWin is increased slowly after (linear increase in Congestion Avoidance phase)
Transport Layer 3-91
Popular ldquoflavorsrdquo of TCP
ssthresh
ssthresh
TCP Tahoe
TCP Reno
Transmission round
cwnd
win
dow
siz
e (in
seg
men
ts)
Transport Layer 3-92
Summary TCP Congestion ControlWhen CongWin is below Threshold sender in slow-start phase window grows exponentiallyWhen CongWin is above Threshold sender is in congestion-avoidance phase window grows linearlyWhen a triple duplicate ACK occurs Threshold set to CongWin2 and CongWin set to ThresholdWhen timeout occurs Threshold set to CongWin2 and CongWin is set to 1 MSS The actual sender window size is determined based on the congestion and flow control algorithms
SenderWin=min(RcvWinCongWin)
Transport Layer 3-93
TCP Congestion Control SummaryEvent State TCP Sender Action Commentary
ACK receipt for previously unackeddata
Slow Start (SS)
CongWin = CongWin + MSS If (CongWin gt Threshold)
set state to ldquoCongestion Avoidancerdquo
Resulting in a doubling of CongWin every RTT
ACK receipt for previously unackeddata
CongestionAvoidance (CA)
CongWin = CongWin+MSS (MSSCongWin)
Additive increase resulting in increase of CongWin by 1 MSS every RTT
Loss event detected by triple duplicate ACK
SS or CA Threshold = CongWin2 CongWin = ThresholdSet state to ldquoCongestion Avoidancerdquo
Fast recovery implementing multiplicative decrease CongWin will not drop below 1 MSS
Timeout SS or CA Threshold = CongWin2 CongWin = 1 MSSSet state to ldquoSlow Startrdquo
Enter slow start
Duplicate ACK
SS or CA Increment duplicate ACK count for segment being acked
CongWin and Threshold not changed
Transport Layer 3-94
TCP throughput
Q whatrsquos average throughout of TCP as function of window size RTT
ignoring slow startlet W be window size when loss occurs
when window is W throughput is WRTTjust after loss window drops to W2 throughput to W2RTT average throughout 75 WRTT
Transport Layer 3-95
TCP Futures TCP over ldquolong fat pipesrdquo
example 1500 byte segments 100ms RTT want 10 Gbps throughputrequires window size W = 83333 in-flight segmentsthroughput in terms of loss rate
L = 210-10 Wownew versions of TCP for high-speed
LRTTMSSsdot221
Transport Layer 3-96
Fairness goal if K TCP sessions share same bottleneck link of bandwidth R each should have average rate of RK
TCP connection 1
bottleneckrouter
capacity R
TCP connection 2
TCP Fairness
Transport Layer 3-97
Why is TCP fairTwo competing sessions
Additive increase gives slope of 1 as throughout increasesmultiplicative decrease decreases throughput proportionally
R
R
equal bandwidth share
Connection 1 throughput
Conn
ecti
on 2
thr
ough
p ut
congestion avoidance additive increaseloss decrease window by factor of 2
congestion avoidance additive increaseloss decrease window by factor of 2
Transport Layer 3-98
Fairness (more)Fairness and UDP
Multimedia apps often do not use TCP
do not want rate throttled by congestion control
Instead use UDPpump audiovideo at constant rate tolerate packet loss
Research area TCP friendly
Fairness and parallel TCP connectionsnothing prevents app from opening parallel cnctionsbetween 2 hostsWeb browsers do this Example link of rate R supporting 9 cnctions
new app asks for 1 TCP gets rate R10new app asks for 11 TCPs gets R2
Transport Layer 3-99
TCP Connection ManagementRecall TCP sender receiver
establish ldquoconnectionrdquobefore exchanging data segmentsinitialize TCP variables
seq sbuffers flow control info (eg RcvWindow)
client connection initiatorSocket clientSocket = new Socket(hostnameport
number)
server contacted by clientSocket connectionSocket = welcomeSocketaccept()
Three way handshakeStep 1 client host sends TCP
SYN segment to serverspecifies initial seq no data
Step 2 server host receives SYN replies with SYNACK segment
server allocates buffersspecifies server initial seq
Step 3 client receives SYNACK replies with ACK segment which may contain data
Transport Layer 3-100
TCP Connection Management (cont)
Closing a connection
client closes socketclientSocketclose()
Step 1 client end system sends TCP FIN control segment to server
Step 2 server receives FIN replies with ACK Closes connection sends FIN
client
FIN
server
ACK
ACK
FIN
close
close
closed
tim
ed w
ait
Transport Layer 3-101
TCP Connection Management (cont)
Step 3 client receives FIN replies with ACK
Enters ldquotimed waitrdquo -will respond with ACK to received FINs
Step 4 server receives ACK Connection closed
client
FIN
server
ACK
ACK
FIN
closing
closing
closed
tim
ed w
ait
closed
Transport Layer 3-102
TCP Connection Management (cont)
TCP clientlifecycle
TCP serverlifecycle
Transport Layer 3-103
Tuning TCPIP Parameters TCPIP parameters
A set of default values may not be optimal for all applicationsThe network administrator may wish to turn on or off some TCPIP functions for performance or security considerations
Many Unix and Linux systems provide some flexibility in tuning the TCPIP kernelsbinsysctl is used to configure the Linux kernel parameters at runtime
Default kernel configuration file is sbinsysctlconfFrequently used sysctl options
bull sysctl ndasha or sysctl ndashA list all current valuesbull sysctl ndashp file_name load the sysctl setting from a configuration
filebull sysctl ndashw variable=value change the value of the parameter
Transport Layer 3-104
SomeTCP Parameters in Linux Kerneltcp_syn_retries
Number of SYN packets the kernel will send before giving up on the new connection
tcp_synack_retriesnumber of SYN+ACK packets sent before the kernel gives up on the connection
tcp_window_scalingMaximum window size of 65535 bytes not enough for for really fast networks The window scaling options allows for almost gigabyte windows which is good for connections with large delay-bandwidth product
tcp_max_syn_backlogMaximal number of remembered connection requests which still did not receive an acknowledgment from connecting client
tcp_fin_timeoutHow many seconds to wait for a final FIN packet before the socket is closed required to prevent denial-of-service (DoS) attacks Default value is 60 seconds
Transport Layer 3-105
SomeTCP Parameters in Linux Kerneltcp_rmem
This is a vector of 3 integers [min default max] These parameters are used by TCP to dynamically adjust receive buffer sizesmin - minimum size of the receive buffer used by each TCP socket The default value is 4K default - the default size of the receive buffer for a TCP socket The default value is 87380 bytes and is lowered to 43689 in low memory systems If larger receive buffer sizes are desired this value should be increased max - the maximum size of the receive buffer used by each TCP socket The default value of 873802 bytes is lowered to 87380 in low memory systems
tcp_smemSend buffer parameters [min default max] similar to tcp_rmem
- Chapter 3 Transport Layer
- Transport services and protocols
- Transport vs network layer
- Internet transport-layer protocols
- Multiplexingdemultiplexing
- How demultiplexing works
- Connectionless demultiplexing
- Connection-oriented demux
- Connection-oriented demux (cont)
- Connection-oriented demux Threaded Web Server
- UDP User Datagram Protocol [RFC 768]
- UDP more
- UDP checksum
- Principles of Reliable data transfer
- Reliable data transfer getting started
- Reliable data transfer getting started
- Rdt10 reliable transfer over a reliable channel
- Rdt20 channel with bit errors
- rdt20 FSM specification
- rdt20 operation with no errors
- rdt20 error scenario
- rdt20 has a fatal flaw
- rdt21 sender handles garbled ACKNAKs
- rdt21 receiver handles garbled ACKNAKs
- rdt21 discussion
- rdt22 a NAK-free protocol
- rdt22 sender receiver fragments
- rdt30 channels with errors and loss
- rdt30 sender
- rdt30 in action
- rdt30 in action
- Performance of rdt30
- rdt30 stop-and-wait operation
- Pipelined protocols
- Pipelining increased utilization
- Go-Back-N
- GBN sender extended FSM
- GBN receiver extended FSM
- GBN inaction
- Selective Repeat
- Selective repeat sender receiver windows
- Selective repeat
- Selective repeat in action
- Selective repeat dilemma
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- TCP Overview RFCs 793 1122 1323 2018 2581
- TCP segment structure
- TCP seq rsquos and ACKs
- TCP Round Trip Time and Timeout
- TCP Round Trip Time and Timeout
- Example RTT estimation
- TCP Round Trip Time and Timeout
- TCP reliable data transfer
- TCP sender events
- TCP sender(simplified)
- TCP retransmission scenarios
- TCP retransmission scenarios (more)
- TCP ACK generation [RFC 1122 RFC 2581]
- Fast Retransmit
- Fast Retransmit
- Fast retransmit algorithm
- TCP Flow Control
- TCP Flow control how it works
- Sliding Window Flow Control Example
- Principles of Congestion Control
- Causescosts of congestion scenario 1
- Causescosts of congestion scenario 2
- Causescosts of congestion scenario 2
- Causescosts of congestion scenario 3
- Causescosts of congestion scenario 3
- Approaches towards congestion control
- TCP Congestion Control
- TCP congestion control bandwidth probing
- TCP Congestion Control details
- TCP Congestion Control more details
- TCP Slow Start Phase
- Slow Start Example
- TCP Congestion Avoidance Phase
- Congestion Avoidance
- Example Slow StartCongestion Avoidance
- Slow Start Congestion Avoidance
- Responses to Congestion
- Fast Recovery (differentiation btwn two loss events)
- TCP Congestion Control
- Popular ldquoflavorsrdquo of TCP
- Summary TCP Congestion Control
- TCP Congestion Control Summary
- TCP throughput
- TCP Futures TCP over ldquolong fat pipesrdquo
- TCP Fairness
- Why is TCP fair
- Fairness (more)
- TCP Connection Management
- TCP Connection Management (cont)
- TCP Connection Management (cont)
- TCP Connection Management (cont)
- Tuning TCPIP Parameters
- SomeTCP Parameters in Linux Kernel
- SomeTCP Parameters in Linux Kernel
-
Transport Layer 3-26
rdt22 a NAK-free protocol
same functionality as rdt21 using ACKs onlyinstead of NAK receiver sends ACK for last pkt received OK
receiver must explicitly include seq of pkt being ACKed duplicate ACK at sender results in same action as NAK retransmit current pkt
Transport Layer 3-27
rdt22 sender receiver fragments
Wait for call 0 from
above
sndpkt = make_pkt(0 data checksum)udt_send(sndpkt)
rdt_send(data)
udt_send(sndpkt)
rdt_rcv(rcvpkt) ampamp ( corrupt(rcvpkt) ||
isACK(rcvpkt1) )
rdt_rcv(rcvpkt) ampamp notcorrupt(rcvpkt) ampamp isACK(rcvpkt0)
Wait for ACK
0sender FSM
fragment
Wait for 0 from below
rdt_rcv(rcvpkt) ampamp notcorrupt(rcvpkt) ampamp has_seq1(rcvpkt)
extract(rcvpktdata)deliver_data(data)sndpkt = make_pkt(ACK1 chksum)udt_send(sndpkt)
rdt_rcv(rcvpkt) ampamp (corrupt(rcvpkt) ||
has_seq1(rcvpkt))
udt_send(sndpkt)receiver FSM
fragment
Λ
Transport Layer 3-28
rdt30 channels with errors and loss
New assumptionunderlying channel can also lose packets (data or ACKs)
checksum seq ACKs retransmissions will be of help but not enough
Q how to deal with losssender waits until certain data or ACK lost then retransmitsdrawbacks
Approach sender waits ldquoreasonablerdquo amount of time for ACK retransmits if no ACK received in this timeif pkt (or ACK) just delayed (not lost)
retransmission will be duplicate but use of seq rsquos already handles thisreceiver must specify seq of pkt being ACKed
requires countdown timer
Transport Layer 3-29
rdt30 sendersndpkt = make_pkt(0 data checksum)udt_send(sndpkt)start_timer
rdt_send(data)
Wait for
ACK0
rdt_rcv(rcvpkt) ampamp ( corrupt(rcvpkt) ||isACK(rcvpkt1) )
Wait for call 1 from
above
sndpkt = make_pkt(1 data checksum)udt_send(sndpkt)start_timer
rdt_send(data)
rdt_rcv(rcvpkt) ampamp notcorrupt(rcvpkt) ampamp isACK(rcvpkt0)
rdt_rcv(rcvpkt) ampamp ( corrupt(rcvpkt) ||isACK(rcvpkt0) )
rdt_rcv(rcvpkt) ampamp notcorrupt(rcvpkt) ampamp isACK(rcvpkt1)
stop_timerstop_timer
udt_send(sndpkt)start_timer
timeout
udt_send(sndpkt)start_timer
timeout
rdt_rcv(rcvpkt)
Wait for call 0from
above
Wait for
ACK1
Λrdt_rcv(rcvpkt)
ΛΛ
Λ
Transport Layer 3-30
rdt30 in action
Transport Layer 3-31
rdt30 in action
Transport Layer 3-32
Performance of rdt30
rdt30 works but performance stinksexample 1 Gbps link 15 ms e-e prop delay 1KB packet
Ttransmit = 8kbpkt109 bsec = 8 microsec
U sender utilization ndash fraction of time sender busy sending1KB pkt every 30 msec -gt 33kBsec thruput over 1 Gbps linknetwork protocol limits use of physical resources
U sender=
008 30008
= 000027 L RRTT + L R
=
L (packet length in bits)R (transmission rate bps) =
Transport Layer 3-33
rdt30 stop-and-wait operation
first packet bit transmitted t = 0
sender receiver
RTT
last packet bit transmitted t = L R
first packet bit arriveslast packet bit arrives send ACK
ACK arrives send next packet t = RTT + L R
U sender=
00830008
= 000027 L RRTT + L R
=
Transport Layer 3-34
Pipelined protocolsPipelining sender allows multiple ldquoin-flightrdquo yet-to-
be-acknowledged pktsrange of sequence numbers must be increasedbuffering at sender andor receiver
Two generic forms of pipelined protocols go-Back-N selective repeat
Transport Layer 3-35
Pipelining increased utilization
first packet bit transmitted t = 0
sender receiver
RTT
last bit transmitted t = L R
first packet bit arriveslast packet bit arrives send ACK
ACK arrives send next packet t = RTT + L R
last bit of 2nd packet arrives send ACKlast bit of 3rd packet arrives send ACK
U sender=
024 30008
= 000083 L RRTT + L R
=
Increase utilizationby a factor of 3
Transport Layer 3-36
Utilization=N(LR)(RTT+LR) if NLRltRTT+LR Utilization=1 if and the sender pauses after it transmits a window NLRgtRTT+LR and the of packets until it receives first ACK sender does not pause
Transport Layer 3-37
Go-Back-NSender
k-bit seq in pkt headerldquowindowrdquo of up to N consecutive unackrsquoed pkts allowed
ACK(n) ACKs all pkts up to including seq n - ldquocumulative ACKrdquomay receive duplicate ACKs (see receiver)
timer for the entire windowtimeout(n) retransmit pkt n and all higher seq pkts in window
Transport Layer 3-38
GBN sender extended FSM
Wait start_timerudt_send(sndpkt[base])udt_send(sndpkt[base+1])hellipudt_send(sndpkt[nextseqnum-1])
timeout
rdt_send(data)
if (nextseqnum lt base+N) sndpkt[nextseqnum] = make_pkt(nextseqnumdatachksum)udt_send(sndpkt[nextseqnum])if (base == nextseqnum)
start_timernextseqnum++
elserefuse_data(data)
base = getacknum(rcvpkt)+1If (base == nextseqnum)
stop_timerelse
start_timer
rdt_rcv(rcvpkt) ampamp notcorrupt(rcvpkt)
base=1nextseqnum=1
rdt_rcv(rcvpkt) ampamp corrupt(rcvpkt)
Λ
Λ
Transport Layer 3-39
GBN receiver extended FSM
ACK-only always send ACK for correctly-received pktwith highest in-order seq
may generate duplicate ACKsneed only remember expectedseqnum
out-of-order pkt discard (donrsquot buffer) -gt no receiver bufferingRe-ACK pkt with highest in-order seq
Wait
udt_send(sndpkt)default
rdt_rcv(rcvpkt)ampamp notcurrupt(rcvpkt)ampamp hasseqnum(rcvpktexpectedseqnum)
extract(rcvpktdata)deliver_data(data)sndpkt = make_pkt(expectedseqnumACKchksum)udt_send(sndpkt)expectedseqnum++
expectedseqnum=1sndpkt =
make_pkt(0ACKchksum)
Λ
Transport Layer 3-40
GBN inaction
Transport Layer 3-41
Selective Repeat
receiver individually acknowledges all correctly received pkts
buffers pkts as needed for eventual in-order delivery to upper layer
sender only resends pkts for which ACK not received
sender timer for each unACKed pktsender window
N consecutive seq rsquosagain limits seq s of sent unACKed pkts
Transport Layer 3-42
Selective repeat sender receiver windows
Transport Layer 3-43
Selective repeat
data from above if next available seq in window send pkt
timeout(n)resend pkt n restart timer
ACK(n) in [sendbasesendbase+N-1]
mark pkt n as receivedif n smallest unACKed pkt advance window base to next unACKed seq
senderpkt n in [rcvbase rcvbase+N-1]
send ACK(n)out-of-order bufferin-order deliver (also deliver buffered in-order pkts) advance window to next not-yet-received pkt
pkt n in [rcvbase-Nrcvbase-1]
ACK(n)otherwise
ignore
receiver
Transport Layer 3-44
Selective repeat in action
Transport Layer 3-45
Selective repeatdilemma
Example seq rsquos 0 1 2 3window size=3
receiver sees no difference in two scenariosincorrectly passes duplicate data as new in (a)
Q what relationship between seq size and window size
Transport Layer 3-46
Sequence Number vs Window SizeSuppose we use k bits to represent SNQuestion Whatrsquos the minimum number of bits k necessary for a window size of N
sender
receiver
Go-Back-N
expectedSN
snd_base=expectedSN
Q For a given expectedSN whatrsquos the largest possible value for snd_baseA If all the last N ACKs sent by the receiver are received
snd_base = expectedSNexpectedSN+N-1
senderrsquos window
Transport Layer 3-47
Sequence Number vs Window SizeSuppose we use k bits to represent SNQuestion Whatrsquos the minimum number of bits k necessary for a window size of N
sender
receiver
Go-Back-N
expectedSN
snd_base=expectedSN-N
Q For a given expectedSN whatrsquos the smallest possible value for snd_baseA If all the last N ACKs sent by the receiver are not received
snd_base = expectedSN-NexpectedSN-1
senderrsquos window
Transport Layer 3-48
Sequence Number vs Window Size
sender
receiver
Go-Back-N
expectedSN
snd_base=expectedSN-N
All SNs in the interval [expectedSN-NexpectedSN+N-1] (an interval of size 2N) can be received by the receiver Since the receiver accepts on the packet with SN=expectedSN there should be no other packet within this interval with SN=expectedSN Therefore
2k ge N+1expectedSN+N-1
Transport Layer 3-49
Sequence Number vs Window SizeSuppose we use k bits to represent SNQuestion Whatrsquos the minimum number of bits k necessary for a window size of N
sender
receiver
Selective Repeat
rcv_base
snd_base=rcv_base
Q For a given rcv_base whatrsquos the largest possible value for snd_baseA If all the last N ACKs sent by the receiver are received
snd_base = rcv_base (same as go_back-N)rcv_base+N-1
senderrsquos window
receiverrsquos window
rcv_base+N-1
Transport Layer 3-50
Sequence Number vs Window SizeSuppose we use k bits to represent SNQuestion Whatrsquos the minimum number of bits k necessary for a window size of N
sender
receiver
Selective Repeat
rcv_base
snd_base=rcv_base-N
Q For a given rcv_base whatrsquos the smallest possible value for snd_baseA If all the last N ACKs sent by the receiver are not received
snd_base = rcv_base-N (same as Go-Back-N)rcv_base-1
senderrsquos window
rcv_base
receiverrsquos window
rcv_base+N-1
Transport Layer 3-51
Sequence Number vs Window Size
sender
receiver
Selective Repeat
snd_base=rcv_base-N
All SNs in the interval [rcv_base-Nrcv_base+N-1] (an interval of size 2N) can be received by the receiver Since the receiver should be able to distinguish between all packets in this interval and take corresponding action there should be no two packets within thisinterval having the same SN Therefore
2k ge 2Nrcv_base+N-1
rcv_basercv_base
receiverrsquos window
rcv_base+N-1
Transport Layer 3-52
TCP Overview RFCs 793 1122 1323 2018 2581
full duplex databi-directional data flow in same connectionMSS maximum segment size
connection-orientedhandshaking (exchange of control msgs) initrsquossender receiver state before data exchange
flow controlledsender will not overwhelm receiver
point-to-pointone sender one receiver
reliable in-order byte stream
no ldquomessage boundariesrdquopipelined
TCP congestion and flow control set window size
send amp receive buffers
socketdoor
TCPsend buffer
TCPreceive buffer
socketdoor
segment
applicationwrites data
applicationreads data
Transport Layer 3-53
TCP segment structure
source port dest port
32 bits
applicationdata
(variable length)
sequence numberacknowledgement number
Receive windowUrg data pnterchecksum
FSRPAUheadlen
notused
Options (variable length)
URG urgent data (generally not used)
ACK ACK valid
PSH push data now(generally not used)
RST SYN FINconnection estab(setup teardown
commands)
bytes rcvr willingto accept
Internetchecksum
(as in UDP)
countingby bytes of data(not segments)
Transport Layer 3-54
TCP seq rsquos and ACKsSeq rsquos
byte stream ldquonumberrdquo of first byte in segmentrsquos dataACKs
seq of next byte expected from other sidecumulative ACK
Q how receiver handles out-of-order segmentsA TCP spec doesnrsquot say - up to implementationWidely used implementations of TCP buffer out-of-order segments
Transport Layer 3-55
TCP Round Trip Time and Timeout
Q how to set TCP timeout valuelonger than RTT
but RTT variestoo short premature timeout
unnecessary retransmissions
too long slow reaction to segment loss
Q how to estimate RTTSampleRTT measured time from segment transmission until ACK receipt
ignore retransmissionsSampleRTT will vary want estimated RTT ldquosmootherrdquo
average several recent measurements not just current SampleRTT
Transport Layer 3-56
TCP Round Trip Time and Timeout
EstimatedRTT = (1- α)EstimatedRTT + αSampleRTT
Exponential weighted moving averageinfluence of past sample decreases exponentially fasttypical value α = 0125
Transport Layer 3-57
Example RTT estimationRTT gaiacsumassedu to fantasiaeurecomfr
100
150
200
250
300
350
1 8 15 22 29 36 43 50 57 64 71 78 85 92 99 106
time (seconnds)
RTT
(mill
iseco
nds)
SampleRTT Estimated RTT
Transport Layer 3-58
TCP Round Trip Time and TimeoutSetting the timeout
EstimatedRTT plus ldquosafety marginrdquolarge variation in EstimatedRTT -gt larger safety margin
first estimate of how much SampleRTT deviates from EstimatedRTT
TimeoutInterval = EstimatedRTT + 4DevRTT
DevRTT = (1-β)DevRTT +β|SampleRTT-EstimatedRTT|
(typically β = 025)
Then set timeout interval
Transport Layer 3-59
TCP reliable data transfer
TCP creates rdtservice on top of IPrsquos unreliable servicePipelined segmentsCumulative acksTCP uses single retransmission timer however it just retransmits the first segment in the window
Retransmissions are triggered by
timeout eventsduplicate acks
Initially consider simplified TCP sender
ignore duplicate acksignore flow control congestion control
Transport Layer 3-60
TCP sender eventsdata rcvd from app
Create segment with seq seq is byte-stream number of first data byte in segmentstart timer if not already running (think of timer as for oldest unacked segment)expiration interval TimeOutInterval
timeoutretransmit segment that caused timeout (first segment in the window)restart timer
Ack rcvdIf acknowledges previously unacked segments
update what is known to be ackedstart timer if there are outstanding segments
Transport Layer 3-61
TCP sender(simplified)
NextSeqNum = InitialSeqNumSendBase = InitialSeqNum
loop (forever) switch(event)
event data received from application above create TCP segment with sequence number NextSeqNumif (timer currently not running)
start timerpass segment to IP NextSeqNum = NextSeqNum + length(data)
event timer timeoutretransmit not-yet-acknowledged segment with
smallest sequence numberstart timer
event ACK received with ACK field value of y if (y gt SendBase)
SendBase = yif (there are currently not-yet-acknowledged segments)
start timer
end of loop forever
Commentbull SendBase-1 last cumulatively ackrsquoed byteExamplebull SendBase-1 = 71y= 73 so the rcvrwants 73+ y gt SendBase sothat new data is acked
Transport Layer 3-62
TCP retransmission scenariosHost A
Seq=100 20 bytes data
ACK=100
timepremature timeout
Host B
Seq=92 8 bytes data
ACK=120
Seq=92 8 bytes data
Seq=
92 t
imeo
ut
ACK=120
Host A
Seq=92 8 bytes data
ACK=100
loss
tim
eout
lost ACK scenario
Host B
X
Seq=92 8 bytes data
ACK=100
time
Seq=
92 t
imeo
utSendBase
= 100
SendBase= 120
SendBase= 120
Sendbase= 100
Transport Layer 3-63
TCP retransmission scenarios (more)Host A
Seq=92 8 bytes data
ACK=100
loss
tim
eout
Cumulative ACK scenario
Host B
X
Seq=100 20 bytes data
ACK=120
time
SendBase= 120
Transport Layer 3-64
TCP ACK generation [RFC 1122 RFC 2581]
Event at Receiver
Arrival of in-order segment withexpected seq All data up toexpected seq already ACKed
Arrival of in-order segment withexpected seq One other segment has ACK pending
Arrival of out-of-order segmenthigher-than-expect seq Gap detected
Arrival of segment that partially or completely fills gap
TCP Receiver action
Delayed ACK Wait up to 500msfor next segment If no next segmentsend ACK
Immediately send single cumulative ACK ACKing both in-order segments
Immediately send duplicate ACK indicating seq of next expected byte
Immediate send ACK provided thatsegment startsat lower end of gap
Transport Layer 3-65
Fast Retransmit
Time-out period often relatively long
long delay before resending lost packet
Detect lost segments via duplicate ACKs
Sender often sends many segments back-to-backIf segment is lost there will likely be many duplicate ACKs
If sender receives 3 ACKs for the same data it supposes that segment after ACKeddata was lost
fast retransmit resend segment before timer expires
Transport Layer 3-66
Fast RetransmitResend a segment after 3 duplicate ACKs since a duplicate ACK means that an out-of sequence segment was receivedduplicate ACKs due to packet reorderingif window is small donrsquot get duplicate ACKs
Host A
tim
eout
Host B
time
X
resend seq X2
seq x1seq x2seq x3seq x4seq x5
ACK x1
ACK x1ACK x1ACK x1
tripleduplicate
ACKs
Transport Layer 3-67
event ACK received with ACK field value of y if (y gt SendBase)
SendBase = yif (there are currently not-yet-acknowledged segments)
start timer
else increment count of dup ACKs received for yif (count of dup ACKs received for y = 3)
resend segment with sequence number y
Fast retransmit algorithm
a duplicate ACK for already ACKed segment
fast retransmit
Transport Layer 3-68
TCP Flow Control
receive side of TCP connection has a receive buffer
speed-matching service matching the send rate to the receiving apprsquos drain rate
app process may be slow at reading from buffer
sender wonrsquot overflowreceiverrsquos buffer by
transmitting too muchtoo fast
flow control
Transport Layer 3-69
TCP Flow control how it works
(Suppose TCP receiver discards out-of-order segments)spare room in buffer
= RcvWin
= RcvBuffer-[LastByteRcvd -LastByteRead]
Rcvr advertises spare room by including value of RcvWin in segmentsSender limits unACKeddata to RcvWin
guarantees receive buffer doesnrsquot overflow
Transport Layer 3-70
Sliding Window Flow Control Example
3K
2K SeqNo=0
ReceiverBuffer
0 4KSendersends 2Kof data
2K
AckNo=2048 RcvWin=2048Sendersends 2Kof data 2K SeqNo=2048
4K
AckNo=4096 RcvWin=0
AckNo=4096 RcvWin=1024
Sender blocked
Transport Layer 3-71
Principles of Congestion Control
Congestioninformally ldquotoo many sources sending too much data too fast for network to handlerdquodifferent from flow controlmanifestations
lost packets (buffer overflow at routers)long delays (queueing in router buffers)
a top-10 problem
Transport Layer 3-72
Causescosts of congestion scenario 1
two senders two receiversone router infinite buffers no retransmission
large delays when congestedmaximum achievable throughput
unlimited shared output link buffers
Host Aλin original data
Host B
λout
Transport Layer 3-73
Causescosts of congestion scenario 2
one router finite buffers sender retransmission of lost packet
finite shared output link buffers
Host A λin original data
Host B
λout
λin original data plus retransmitted data
Transport Layer 3-74
Causescosts of congestion scenario 2always (goodput)ldquoperfectrdquo retransmission only when loss
retransmission of delayed (not lost) packet makes larger(than perfect case) for same
λin
λout=
λin
λoutgtλ
inλout
ldquocostsrdquo of congestionmore work (retrans) for given ldquogoodputrdquounneeded retransmissions link carries multiple copies of pkt
R2
R2λin
λ out
b
R2
R2λin
λ out
a
R2
R2λin
λ out
c
R4
R3
Transport Layer 3-75
Causescosts of congestion scenario 3four sendersmultihop pathstimeoutretransmit
λin
Q what happens as and increase λ
in
finite shared output link buffers
Host Aλin original data
Host B
λout
λin original data plus retransmitted data
Transport Layer 3-76
Causescosts of congestion scenario 3
another ldquocostrdquo of congestionwhen packet dropped any ldquoupstream transmission capacity used for that packet was wasted
Host A
Host B
λou
t
Transport Layer 3-77
Approaches towards congestion control
End-end congestion controlno explicit feedback from networkcongestion inferred from end-system observed loss delayapproach taken by TCP
Network-assisted congestion controlrouters provide feedback to end systems
single bit indicating congestion (SNA DECbit TCPIP ECN ATM)explicit rate sender should send at
Two broad approaches towards congestion control
Transport Layer 3-78
TCP Congestion Control
end-end control (no network assistance)sender limits transmissionLastByteSent-LastByteAcked
le CongWin
CongWin is dynamic function of perceived network congestion
How does sender perceive congestionloss event = timeout or3 duplicate acksTCP sender reduces rate (CongWin) after loss event
two modes of operationSlow Start (SS)Congestion avoidance (CA) or Additive Increase Multiplicative Decrease (AIMD)
Transport Layer 3-79
TCP congestion control bandwidth probing
ldquoprobing for bandwidthrdquo increase transmission rate on receipt of ACK until eventually loss occurs then decrease transmission rate
continue to increase on ACK decrease on loss (since available bandwidth is changing depending on other connections in network)
ACKs being received so increase rate
X
X
XX
X loss so decrease rate
send
ing
rate
time
Q how fast to increasedecreasedetails to follow
TCPrsquosldquosawtoothrdquobehavior
Transport Layer 3-80
TCP Congestion Control details
sender limits rate by limiting number of unACKed bytes ldquoin pipelinerdquo
cwnd differs from rwnd (how why)sender limited by min(cwndrwnd)
roughly
cwnd is dynamic function of perceived network congestion
rate = cwndRTT bytessec
LastByteSent-LastByteAcked le cwnd
cwndbytes
RTT
ACK(s)
Transport Layer 3-81
TCP Congestion Control more details
segment loss event reducing cwndtimeout no response from receiver
cut cwnd to 13 duplicate ACKs at least some segments getting through (recall fast retransmit)
cut cwnd in half less aggressively than on timeout
ACK received increase cwndTwo modes of operation
slowstart phase bull increase exponentially
fast (despite name) at connection start or following timeout
congestion avoidance bull increase linearly
Transport Layer 3-82
TCP Slow Start Phasewhen connection begins cwnd = 1 MSS
example MSS = 500 bytes amp RTT = 200 msecinitial rate = 20 kbps
available bandwidth may be gtgt MSSRTT
desirable to quickly ramp up to respectable rate
increase rate exponentially until first loss event or when threshold reached
double cwnd every RTTdone by incrementing cwnd by 1 for every ACK received
Host A
one segment
RTT
Host B
time
two segments
four segments
Transport Layer 3-83
Slow Start ExampleThe congestion window size grows very rapidly
For every ACK we increase CongWin by 1 irrespective of the number of segments ACKrsquoeddouble CongWinevery RTTinitial rate is slow but ramps up exponentially fast
TCP slows down the increase of CongWinwhen CongWin gt ssthresh
segment 1
ACK for segment 1
cwnd = 1
cwnd = 2 segment 2segment 3
ACK for segments 2
cwnd = 4 segment 4segment 5segment 6
ACK for segments 4
cwnd = 7
ACK for segments 3
ACK for segments 5
ACK for segments 6
cwnd = 3
cwnd = 5
cwnd = 6ACK for segments 7
cwnd = 8
segment 7
Transport Layer 3-84
TCP Congestion Avoidance Phase
when cwnd gt ssthreshgrow cwnd linearly
increase cwnd by 1 MSS per RTT approach possible congestion slower than in slowstartimplementation cwnd= cwnd + MSScwndfor each ACK received
ACKs increase cwndby 1 MSS per RTT additive increaseloss cut cwnd in half (non-timeout-detected loss ) multiplicative decrease
AIMD
AIMD Additive IncreaseMultiplicative Decrease
Transport Layer 3-85
Congestion AvoidanceCongestion avoidance phase is started if CongWin has reached the slow-start threshold value
If CongWin gt= ssthresh then each time an ACK is received increment CongWin as follows
bull CongWin = CongWin + 1CongWin (CongWin in segments)
bull In actual TCP implementation CongWin is in BytesCongWin = CongWin + MSS (MSSCongWin)
So CongWin is increased by one only if all CongWinsegments have been acknowledged
Transport Layer 3-86
Example Slow StartCongestion AvoidanceAssume that
ssthresh = 8
cwnd = 1
cwnd = 2
cwnd = 4
cwnd = 8
cwnd = 9
cwnd = 10
02468
101214
t=0
t=2
t=4
t=6
Roundtrip times
Cw
nd(in
seg
men
ts)
ssthresh
cwnd = 3
cwnd = 5cwnd = 6cwnd = 7
Transport Layer 3-87
Slow Start Congestion AvoidanceA typical plot of CongWin for a TCP connection
(MSS = 1500 bytes) with TCP Tahoe
SS
CA
ssthresh
Transport Layer 3-88
Responses to CongestionTCP assumes there is congestion if it detects a packet lossA TCP sender can detect lost packets via loss events
bull Timeout of a retransmission timerbull Receipt of 3 duplicate ACKs (fast retransmit)
TCP interprets a Timeout as a binary congestion signal When a timeout occurs the sender performs
ssthresh is set to half the current size of the congestion window
ssthresh = CongWin 2CongWin is reset to one
CongWin = 1and slow-start is entered
Transport Layer 3-89
Fast Recovery (differentiation btwn two loss events) After 3 dup ACKs (fast Retransmit)
ssthresh = CongWin2CongWin = CongWin2window then grows linearly
But after timeout eventCongWin = 1 MSS window then grows exponentiallyto the threshold then grows linearly
bull 3 dup ACKs indicates network capable of delivering some segmentsbull timeout before 3 dup ACKs is ldquomore alarmingrdquo
Philosophy
3-90
TCP Congestion ControlInitially
CongWin = 1ssthresh = advertised window size
New Ack receivedif (CongWin lt ssthresh) Slow Start
CongWin = CongWin + 1else Congestion Avoidance
CongWin = CongWin + 1CongWinTimeout
ssthresh = CongWin2CongWin = 1
Fast Retransmissionssthresh = CongWin2CongWin = CongWin2
Slow Start (exponential increase phase) is continued until CongWin reaches half of the level where the loss event occurred last time CongWin is increased slowly after (linear increase in Congestion Avoidance phase)
Transport Layer 3-91
Popular ldquoflavorsrdquo of TCP
ssthresh
ssthresh
TCP Tahoe
TCP Reno
Transmission round
cwnd
win
dow
siz
e (in
seg
men
ts)
Transport Layer 3-92
Summary TCP Congestion ControlWhen CongWin is below Threshold sender in slow-start phase window grows exponentiallyWhen CongWin is above Threshold sender is in congestion-avoidance phase window grows linearlyWhen a triple duplicate ACK occurs Threshold set to CongWin2 and CongWin set to ThresholdWhen timeout occurs Threshold set to CongWin2 and CongWin is set to 1 MSS The actual sender window size is determined based on the congestion and flow control algorithms
SenderWin=min(RcvWinCongWin)
Transport Layer 3-93
TCP Congestion Control SummaryEvent State TCP Sender Action Commentary
ACK receipt for previously unackeddata
Slow Start (SS)
CongWin = CongWin + MSS If (CongWin gt Threshold)
set state to ldquoCongestion Avoidancerdquo
Resulting in a doubling of CongWin every RTT
ACK receipt for previously unackeddata
CongestionAvoidance (CA)
CongWin = CongWin+MSS (MSSCongWin)
Additive increase resulting in increase of CongWin by 1 MSS every RTT
Loss event detected by triple duplicate ACK
SS or CA Threshold = CongWin2 CongWin = ThresholdSet state to ldquoCongestion Avoidancerdquo
Fast recovery implementing multiplicative decrease CongWin will not drop below 1 MSS
Timeout SS or CA Threshold = CongWin2 CongWin = 1 MSSSet state to ldquoSlow Startrdquo
Enter slow start
Duplicate ACK
SS or CA Increment duplicate ACK count for segment being acked
CongWin and Threshold not changed
Transport Layer 3-94
TCP throughput
Q whatrsquos average throughout of TCP as function of window size RTT
ignoring slow startlet W be window size when loss occurs
when window is W throughput is WRTTjust after loss window drops to W2 throughput to W2RTT average throughout 75 WRTT
Transport Layer 3-95
TCP Futures TCP over ldquolong fat pipesrdquo
example 1500 byte segments 100ms RTT want 10 Gbps throughputrequires window size W = 83333 in-flight segmentsthroughput in terms of loss rate
L = 210-10 Wownew versions of TCP for high-speed
LRTTMSSsdot221
Transport Layer 3-96
Fairness goal if K TCP sessions share same bottleneck link of bandwidth R each should have average rate of RK
TCP connection 1
bottleneckrouter
capacity R
TCP connection 2
TCP Fairness
Transport Layer 3-97
Why is TCP fairTwo competing sessions
Additive increase gives slope of 1 as throughout increasesmultiplicative decrease decreases throughput proportionally
R
R
equal bandwidth share
Connection 1 throughput
Conn
ecti
on 2
thr
ough
p ut
congestion avoidance additive increaseloss decrease window by factor of 2
congestion avoidance additive increaseloss decrease window by factor of 2
Transport Layer 3-98
Fairness (more)Fairness and UDP
Multimedia apps often do not use TCP
do not want rate throttled by congestion control
Instead use UDPpump audiovideo at constant rate tolerate packet loss
Research area TCP friendly
Fairness and parallel TCP connectionsnothing prevents app from opening parallel cnctionsbetween 2 hostsWeb browsers do this Example link of rate R supporting 9 cnctions
new app asks for 1 TCP gets rate R10new app asks for 11 TCPs gets R2
Transport Layer 3-99
TCP Connection ManagementRecall TCP sender receiver
establish ldquoconnectionrdquobefore exchanging data segmentsinitialize TCP variables
seq sbuffers flow control info (eg RcvWindow)
client connection initiatorSocket clientSocket = new Socket(hostnameport
number)
server contacted by clientSocket connectionSocket = welcomeSocketaccept()
Three way handshakeStep 1 client host sends TCP
SYN segment to serverspecifies initial seq no data
Step 2 server host receives SYN replies with SYNACK segment
server allocates buffersspecifies server initial seq
Step 3 client receives SYNACK replies with ACK segment which may contain data
Transport Layer 3-100
TCP Connection Management (cont)
Closing a connection
client closes socketclientSocketclose()
Step 1 client end system sends TCP FIN control segment to server
Step 2 server receives FIN replies with ACK Closes connection sends FIN
client
FIN
server
ACK
ACK
FIN
close
close
closed
tim
ed w
ait
Transport Layer 3-101
TCP Connection Management (cont)
Step 3 client receives FIN replies with ACK
Enters ldquotimed waitrdquo -will respond with ACK to received FINs
Step 4 server receives ACK Connection closed
client
FIN
server
ACK
ACK
FIN
closing
closing
closed
tim
ed w
ait
closed
Transport Layer 3-102
TCP Connection Management (cont)
TCP clientlifecycle
TCP serverlifecycle
Transport Layer 3-103
Tuning TCPIP Parameters TCPIP parameters
A set of default values may not be optimal for all applicationsThe network administrator may wish to turn on or off some TCPIP functions for performance or security considerations
Many Unix and Linux systems provide some flexibility in tuning the TCPIP kernelsbinsysctl is used to configure the Linux kernel parameters at runtime
Default kernel configuration file is sbinsysctlconfFrequently used sysctl options
bull sysctl ndasha or sysctl ndashA list all current valuesbull sysctl ndashp file_name load the sysctl setting from a configuration
filebull sysctl ndashw variable=value change the value of the parameter
Transport Layer 3-104
SomeTCP Parameters in Linux Kerneltcp_syn_retries
Number of SYN packets the kernel will send before giving up on the new connection
tcp_synack_retriesnumber of SYN+ACK packets sent before the kernel gives up on the connection
tcp_window_scalingMaximum window size of 65535 bytes not enough for for really fast networks The window scaling options allows for almost gigabyte windows which is good for connections with large delay-bandwidth product
tcp_max_syn_backlogMaximal number of remembered connection requests which still did not receive an acknowledgment from connecting client
tcp_fin_timeoutHow many seconds to wait for a final FIN packet before the socket is closed required to prevent denial-of-service (DoS) attacks Default value is 60 seconds
Transport Layer 3-105
SomeTCP Parameters in Linux Kerneltcp_rmem
This is a vector of 3 integers [min default max] These parameters are used by TCP to dynamically adjust receive buffer sizesmin - minimum size of the receive buffer used by each TCP socket The default value is 4K default - the default size of the receive buffer for a TCP socket The default value is 87380 bytes and is lowered to 43689 in low memory systems If larger receive buffer sizes are desired this value should be increased max - the maximum size of the receive buffer used by each TCP socket The default value of 873802 bytes is lowered to 87380 in low memory systems
tcp_smemSend buffer parameters [min default max] similar to tcp_rmem
- Chapter 3 Transport Layer
- Transport services and protocols
- Transport vs network layer
- Internet transport-layer protocols
- Multiplexingdemultiplexing
- How demultiplexing works
- Connectionless demultiplexing
- Connection-oriented demux
- Connection-oriented demux (cont)
- Connection-oriented demux Threaded Web Server
- UDP User Datagram Protocol [RFC 768]
- UDP more
- UDP checksum
- Principles of Reliable data transfer
- Reliable data transfer getting started
- Reliable data transfer getting started
- Rdt10 reliable transfer over a reliable channel
- Rdt20 channel with bit errors
- rdt20 FSM specification
- rdt20 operation with no errors
- rdt20 error scenario
- rdt20 has a fatal flaw
- rdt21 sender handles garbled ACKNAKs
- rdt21 receiver handles garbled ACKNAKs
- rdt21 discussion
- rdt22 a NAK-free protocol
- rdt22 sender receiver fragments
- rdt30 channels with errors and loss
- rdt30 sender
- rdt30 in action
- rdt30 in action
- Performance of rdt30
- rdt30 stop-and-wait operation
- Pipelined protocols
- Pipelining increased utilization
- Go-Back-N
- GBN sender extended FSM
- GBN receiver extended FSM
- GBN inaction
- Selective Repeat
- Selective repeat sender receiver windows
- Selective repeat
- Selective repeat in action
- Selective repeat dilemma
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- TCP Overview RFCs 793 1122 1323 2018 2581
- TCP segment structure
- TCP seq rsquos and ACKs
- TCP Round Trip Time and Timeout
- TCP Round Trip Time and Timeout
- Example RTT estimation
- TCP Round Trip Time and Timeout
- TCP reliable data transfer
- TCP sender events
- TCP sender(simplified)
- TCP retransmission scenarios
- TCP retransmission scenarios (more)
- TCP ACK generation [RFC 1122 RFC 2581]
- Fast Retransmit
- Fast Retransmit
- Fast retransmit algorithm
- TCP Flow Control
- TCP Flow control how it works
- Sliding Window Flow Control Example
- Principles of Congestion Control
- Causescosts of congestion scenario 1
- Causescosts of congestion scenario 2
- Causescosts of congestion scenario 2
- Causescosts of congestion scenario 3
- Causescosts of congestion scenario 3
- Approaches towards congestion control
- TCP Congestion Control
- TCP congestion control bandwidth probing
- TCP Congestion Control details
- TCP Congestion Control more details
- TCP Slow Start Phase
- Slow Start Example
- TCP Congestion Avoidance Phase
- Congestion Avoidance
- Example Slow StartCongestion Avoidance
- Slow Start Congestion Avoidance
- Responses to Congestion
- Fast Recovery (differentiation btwn two loss events)
- TCP Congestion Control
- Popular ldquoflavorsrdquo of TCP
- Summary TCP Congestion Control
- TCP Congestion Control Summary
- TCP throughput
- TCP Futures TCP over ldquolong fat pipesrdquo
- TCP Fairness
- Why is TCP fair
- Fairness (more)
- TCP Connection Management
- TCP Connection Management (cont)
- TCP Connection Management (cont)
- TCP Connection Management (cont)
- Tuning TCPIP Parameters
- SomeTCP Parameters in Linux Kernel
- SomeTCP Parameters in Linux Kernel
-
Transport Layer 3-27
rdt22 sender receiver fragments
Wait for call 0 from
above
sndpkt = make_pkt(0 data checksum)udt_send(sndpkt)
rdt_send(data)
udt_send(sndpkt)
rdt_rcv(rcvpkt) ampamp ( corrupt(rcvpkt) ||
isACK(rcvpkt1) )
rdt_rcv(rcvpkt) ampamp notcorrupt(rcvpkt) ampamp isACK(rcvpkt0)
Wait for ACK
0sender FSM
fragment
Wait for 0 from below
rdt_rcv(rcvpkt) ampamp notcorrupt(rcvpkt) ampamp has_seq1(rcvpkt)
extract(rcvpktdata)deliver_data(data)sndpkt = make_pkt(ACK1 chksum)udt_send(sndpkt)
rdt_rcv(rcvpkt) ampamp (corrupt(rcvpkt) ||
has_seq1(rcvpkt))
udt_send(sndpkt)receiver FSM
fragment
Λ
Transport Layer 3-28
rdt30 channels with errors and loss
New assumptionunderlying channel can also lose packets (data or ACKs)
checksum seq ACKs retransmissions will be of help but not enough
Q how to deal with losssender waits until certain data or ACK lost then retransmitsdrawbacks
Approach sender waits ldquoreasonablerdquo amount of time for ACK retransmits if no ACK received in this timeif pkt (or ACK) just delayed (not lost)
retransmission will be duplicate but use of seq rsquos already handles thisreceiver must specify seq of pkt being ACKed
requires countdown timer
Transport Layer 3-29
rdt30 sendersndpkt = make_pkt(0 data checksum)udt_send(sndpkt)start_timer
rdt_send(data)
Wait for
ACK0
rdt_rcv(rcvpkt) ampamp ( corrupt(rcvpkt) ||isACK(rcvpkt1) )
Wait for call 1 from
above
sndpkt = make_pkt(1 data checksum)udt_send(sndpkt)start_timer
rdt_send(data)
rdt_rcv(rcvpkt) ampamp notcorrupt(rcvpkt) ampamp isACK(rcvpkt0)
rdt_rcv(rcvpkt) ampamp ( corrupt(rcvpkt) ||isACK(rcvpkt0) )
rdt_rcv(rcvpkt) ampamp notcorrupt(rcvpkt) ampamp isACK(rcvpkt1)
stop_timerstop_timer
udt_send(sndpkt)start_timer
timeout
udt_send(sndpkt)start_timer
timeout
rdt_rcv(rcvpkt)
Wait for call 0from
above
Wait for
ACK1
Λrdt_rcv(rcvpkt)
ΛΛ
Λ
Transport Layer 3-30
rdt30 in action
Transport Layer 3-31
rdt30 in action
Transport Layer 3-32
Performance of rdt30
rdt30 works but performance stinksexample 1 Gbps link 15 ms e-e prop delay 1KB packet
Ttransmit = 8kbpkt109 bsec = 8 microsec
U sender utilization ndash fraction of time sender busy sending1KB pkt every 30 msec -gt 33kBsec thruput over 1 Gbps linknetwork protocol limits use of physical resources
U sender=
008 30008
= 000027 L RRTT + L R
=
L (packet length in bits)R (transmission rate bps) =
Transport Layer 3-33
rdt30 stop-and-wait operation
first packet bit transmitted t = 0
sender receiver
RTT
last packet bit transmitted t = L R
first packet bit arriveslast packet bit arrives send ACK
ACK arrives send next packet t = RTT + L R
U sender=
00830008
= 000027 L RRTT + L R
=
Transport Layer 3-34
Pipelined protocolsPipelining sender allows multiple ldquoin-flightrdquo yet-to-
be-acknowledged pktsrange of sequence numbers must be increasedbuffering at sender andor receiver
Two generic forms of pipelined protocols go-Back-N selective repeat
Transport Layer 3-35
Pipelining increased utilization
first packet bit transmitted t = 0
sender receiver
RTT
last bit transmitted t = L R
first packet bit arriveslast packet bit arrives send ACK
ACK arrives send next packet t = RTT + L R
last bit of 2nd packet arrives send ACKlast bit of 3rd packet arrives send ACK
U sender=
024 30008
= 000083 L RRTT + L R
=
Increase utilizationby a factor of 3
Transport Layer 3-36
Utilization=N(LR)(RTT+LR) if NLRltRTT+LR Utilization=1 if and the sender pauses after it transmits a window NLRgtRTT+LR and the of packets until it receives first ACK sender does not pause
Transport Layer 3-37
Go-Back-NSender
k-bit seq in pkt headerldquowindowrdquo of up to N consecutive unackrsquoed pkts allowed
ACK(n) ACKs all pkts up to including seq n - ldquocumulative ACKrdquomay receive duplicate ACKs (see receiver)
timer for the entire windowtimeout(n) retransmit pkt n and all higher seq pkts in window
Transport Layer 3-38
GBN sender extended FSM
Wait start_timerudt_send(sndpkt[base])udt_send(sndpkt[base+1])hellipudt_send(sndpkt[nextseqnum-1])
timeout
rdt_send(data)
if (nextseqnum lt base+N) sndpkt[nextseqnum] = make_pkt(nextseqnumdatachksum)udt_send(sndpkt[nextseqnum])if (base == nextseqnum)
start_timernextseqnum++
elserefuse_data(data)
base = getacknum(rcvpkt)+1If (base == nextseqnum)
stop_timerelse
start_timer
rdt_rcv(rcvpkt) ampamp notcorrupt(rcvpkt)
base=1nextseqnum=1
rdt_rcv(rcvpkt) ampamp corrupt(rcvpkt)
Λ
Λ
Transport Layer 3-39
GBN receiver extended FSM
ACK-only always send ACK for correctly-received pktwith highest in-order seq
may generate duplicate ACKsneed only remember expectedseqnum
out-of-order pkt discard (donrsquot buffer) -gt no receiver bufferingRe-ACK pkt with highest in-order seq
Wait
udt_send(sndpkt)default
rdt_rcv(rcvpkt)ampamp notcurrupt(rcvpkt)ampamp hasseqnum(rcvpktexpectedseqnum)
extract(rcvpktdata)deliver_data(data)sndpkt = make_pkt(expectedseqnumACKchksum)udt_send(sndpkt)expectedseqnum++
expectedseqnum=1sndpkt =
make_pkt(0ACKchksum)
Λ
Transport Layer 3-40
GBN inaction
Transport Layer 3-41
Selective Repeat
receiver individually acknowledges all correctly received pkts
buffers pkts as needed for eventual in-order delivery to upper layer
sender only resends pkts for which ACK not received
sender timer for each unACKed pktsender window
N consecutive seq rsquosagain limits seq s of sent unACKed pkts
Transport Layer 3-42
Selective repeat sender receiver windows
Transport Layer 3-43
Selective repeat
data from above if next available seq in window send pkt
timeout(n)resend pkt n restart timer
ACK(n) in [sendbasesendbase+N-1]
mark pkt n as receivedif n smallest unACKed pkt advance window base to next unACKed seq
senderpkt n in [rcvbase rcvbase+N-1]
send ACK(n)out-of-order bufferin-order deliver (also deliver buffered in-order pkts) advance window to next not-yet-received pkt
pkt n in [rcvbase-Nrcvbase-1]
ACK(n)otherwise
ignore
receiver
Transport Layer 3-44
Selective repeat in action
Transport Layer 3-45
Selective repeatdilemma
Example seq rsquos 0 1 2 3window size=3
receiver sees no difference in two scenariosincorrectly passes duplicate data as new in (a)
Q what relationship between seq size and window size
Transport Layer 3-46
Sequence Number vs Window SizeSuppose we use k bits to represent SNQuestion Whatrsquos the minimum number of bits k necessary for a window size of N
sender
receiver
Go-Back-N
expectedSN
snd_base=expectedSN
Q For a given expectedSN whatrsquos the largest possible value for snd_baseA If all the last N ACKs sent by the receiver are received
snd_base = expectedSNexpectedSN+N-1
senderrsquos window
Transport Layer 3-47
Sequence Number vs Window SizeSuppose we use k bits to represent SNQuestion Whatrsquos the minimum number of bits k necessary for a window size of N
sender
receiver
Go-Back-N
expectedSN
snd_base=expectedSN-N
Q For a given expectedSN whatrsquos the smallest possible value for snd_baseA If all the last N ACKs sent by the receiver are not received
snd_base = expectedSN-NexpectedSN-1
senderrsquos window
Transport Layer 3-48
Sequence Number vs Window Size
sender
receiver
Go-Back-N
expectedSN
snd_base=expectedSN-N
All SNs in the interval [expectedSN-NexpectedSN+N-1] (an interval of size 2N) can be received by the receiver Since the receiver accepts on the packet with SN=expectedSN there should be no other packet within this interval with SN=expectedSN Therefore
2k ge N+1expectedSN+N-1
Transport Layer 3-49
Sequence Number vs Window SizeSuppose we use k bits to represent SNQuestion Whatrsquos the minimum number of bits k necessary for a window size of N
sender
receiver
Selective Repeat
rcv_base
snd_base=rcv_base
Q For a given rcv_base whatrsquos the largest possible value for snd_baseA If all the last N ACKs sent by the receiver are received
snd_base = rcv_base (same as go_back-N)rcv_base+N-1
senderrsquos window
receiverrsquos window
rcv_base+N-1
Transport Layer 3-50
Sequence Number vs Window SizeSuppose we use k bits to represent SNQuestion Whatrsquos the minimum number of bits k necessary for a window size of N
sender
receiver
Selective Repeat
rcv_base
snd_base=rcv_base-N
Q For a given rcv_base whatrsquos the smallest possible value for snd_baseA If all the last N ACKs sent by the receiver are not received
snd_base = rcv_base-N (same as Go-Back-N)rcv_base-1
senderrsquos window
rcv_base
receiverrsquos window
rcv_base+N-1
Transport Layer 3-51
Sequence Number vs Window Size
sender
receiver
Selective Repeat
snd_base=rcv_base-N
All SNs in the interval [rcv_base-Nrcv_base+N-1] (an interval of size 2N) can be received by the receiver Since the receiver should be able to distinguish between all packets in this interval and take corresponding action there should be no two packets within thisinterval having the same SN Therefore
2k ge 2Nrcv_base+N-1
rcv_basercv_base
receiverrsquos window
rcv_base+N-1
Transport Layer 3-52
TCP Overview RFCs 793 1122 1323 2018 2581
full duplex databi-directional data flow in same connectionMSS maximum segment size
connection-orientedhandshaking (exchange of control msgs) initrsquossender receiver state before data exchange
flow controlledsender will not overwhelm receiver
point-to-pointone sender one receiver
reliable in-order byte stream
no ldquomessage boundariesrdquopipelined
TCP congestion and flow control set window size
send amp receive buffers
socketdoor
TCPsend buffer
TCPreceive buffer
socketdoor
segment
applicationwrites data
applicationreads data
Transport Layer 3-53
TCP segment structure
source port dest port
32 bits
applicationdata
(variable length)
sequence numberacknowledgement number
Receive windowUrg data pnterchecksum
FSRPAUheadlen
notused
Options (variable length)
URG urgent data (generally not used)
ACK ACK valid
PSH push data now(generally not used)
RST SYN FINconnection estab(setup teardown
commands)
bytes rcvr willingto accept
Internetchecksum
(as in UDP)
countingby bytes of data(not segments)
Transport Layer 3-54
TCP seq rsquos and ACKsSeq rsquos
byte stream ldquonumberrdquo of first byte in segmentrsquos dataACKs
seq of next byte expected from other sidecumulative ACK
Q how receiver handles out-of-order segmentsA TCP spec doesnrsquot say - up to implementationWidely used implementations of TCP buffer out-of-order segments
Transport Layer 3-55
TCP Round Trip Time and Timeout
Q how to set TCP timeout valuelonger than RTT
but RTT variestoo short premature timeout
unnecessary retransmissions
too long slow reaction to segment loss
Q how to estimate RTTSampleRTT measured time from segment transmission until ACK receipt
ignore retransmissionsSampleRTT will vary want estimated RTT ldquosmootherrdquo
average several recent measurements not just current SampleRTT
Transport Layer 3-56
TCP Round Trip Time and Timeout
EstimatedRTT = (1- α)EstimatedRTT + αSampleRTT
Exponential weighted moving averageinfluence of past sample decreases exponentially fasttypical value α = 0125
Transport Layer 3-57
Example RTT estimationRTT gaiacsumassedu to fantasiaeurecomfr
100
150
200
250
300
350
1 8 15 22 29 36 43 50 57 64 71 78 85 92 99 106
time (seconnds)
RTT
(mill
iseco
nds)
SampleRTT Estimated RTT
Transport Layer 3-58
TCP Round Trip Time and TimeoutSetting the timeout
EstimatedRTT plus ldquosafety marginrdquolarge variation in EstimatedRTT -gt larger safety margin
first estimate of how much SampleRTT deviates from EstimatedRTT
TimeoutInterval = EstimatedRTT + 4DevRTT
DevRTT = (1-β)DevRTT +β|SampleRTT-EstimatedRTT|
(typically β = 025)
Then set timeout interval
Transport Layer 3-59
TCP reliable data transfer
TCP creates rdtservice on top of IPrsquos unreliable servicePipelined segmentsCumulative acksTCP uses single retransmission timer however it just retransmits the first segment in the window
Retransmissions are triggered by
timeout eventsduplicate acks
Initially consider simplified TCP sender
ignore duplicate acksignore flow control congestion control
Transport Layer 3-60
TCP sender eventsdata rcvd from app
Create segment with seq seq is byte-stream number of first data byte in segmentstart timer if not already running (think of timer as for oldest unacked segment)expiration interval TimeOutInterval
timeoutretransmit segment that caused timeout (first segment in the window)restart timer
Ack rcvdIf acknowledges previously unacked segments
update what is known to be ackedstart timer if there are outstanding segments
Transport Layer 3-61
TCP sender(simplified)
NextSeqNum = InitialSeqNumSendBase = InitialSeqNum
loop (forever) switch(event)
event data received from application above create TCP segment with sequence number NextSeqNumif (timer currently not running)
start timerpass segment to IP NextSeqNum = NextSeqNum + length(data)
event timer timeoutretransmit not-yet-acknowledged segment with
smallest sequence numberstart timer
event ACK received with ACK field value of y if (y gt SendBase)
SendBase = yif (there are currently not-yet-acknowledged segments)
start timer
end of loop forever
Commentbull SendBase-1 last cumulatively ackrsquoed byteExamplebull SendBase-1 = 71y= 73 so the rcvrwants 73+ y gt SendBase sothat new data is acked
Transport Layer 3-62
TCP retransmission scenariosHost A
Seq=100 20 bytes data
ACK=100
timepremature timeout
Host B
Seq=92 8 bytes data
ACK=120
Seq=92 8 bytes data
Seq=
92 t
imeo
ut
ACK=120
Host A
Seq=92 8 bytes data
ACK=100
loss
tim
eout
lost ACK scenario
Host B
X
Seq=92 8 bytes data
ACK=100
time
Seq=
92 t
imeo
utSendBase
= 100
SendBase= 120
SendBase= 120
Sendbase= 100
Transport Layer 3-63
TCP retransmission scenarios (more)Host A
Seq=92 8 bytes data
ACK=100
loss
tim
eout
Cumulative ACK scenario
Host B
X
Seq=100 20 bytes data
ACK=120
time
SendBase= 120
Transport Layer 3-64
TCP ACK generation [RFC 1122 RFC 2581]
Event at Receiver
Arrival of in-order segment withexpected seq All data up toexpected seq already ACKed
Arrival of in-order segment withexpected seq One other segment has ACK pending
Arrival of out-of-order segmenthigher-than-expect seq Gap detected
Arrival of segment that partially or completely fills gap
TCP Receiver action
Delayed ACK Wait up to 500msfor next segment If no next segmentsend ACK
Immediately send single cumulative ACK ACKing both in-order segments
Immediately send duplicate ACK indicating seq of next expected byte
Immediate send ACK provided thatsegment startsat lower end of gap
Transport Layer 3-65
Fast Retransmit
Time-out period often relatively long
long delay before resending lost packet
Detect lost segments via duplicate ACKs
Sender often sends many segments back-to-backIf segment is lost there will likely be many duplicate ACKs
If sender receives 3 ACKs for the same data it supposes that segment after ACKeddata was lost
fast retransmit resend segment before timer expires
Transport Layer 3-66
Fast RetransmitResend a segment after 3 duplicate ACKs since a duplicate ACK means that an out-of sequence segment was receivedduplicate ACKs due to packet reorderingif window is small donrsquot get duplicate ACKs
Host A
tim
eout
Host B
time
X
resend seq X2
seq x1seq x2seq x3seq x4seq x5
ACK x1
ACK x1ACK x1ACK x1
tripleduplicate
ACKs
Transport Layer 3-67
event ACK received with ACK field value of y if (y gt SendBase)
SendBase = yif (there are currently not-yet-acknowledged segments)
start timer
else increment count of dup ACKs received for yif (count of dup ACKs received for y = 3)
resend segment with sequence number y
Fast retransmit algorithm
a duplicate ACK for already ACKed segment
fast retransmit
Transport Layer 3-68
TCP Flow Control
receive side of TCP connection has a receive buffer
speed-matching service matching the send rate to the receiving apprsquos drain rate
app process may be slow at reading from buffer
sender wonrsquot overflowreceiverrsquos buffer by
transmitting too muchtoo fast
flow control
Transport Layer 3-69
TCP Flow control how it works
(Suppose TCP receiver discards out-of-order segments)spare room in buffer
= RcvWin
= RcvBuffer-[LastByteRcvd -LastByteRead]
Rcvr advertises spare room by including value of RcvWin in segmentsSender limits unACKeddata to RcvWin
guarantees receive buffer doesnrsquot overflow
Transport Layer 3-70
Sliding Window Flow Control Example
3K
2K SeqNo=0
ReceiverBuffer
0 4KSendersends 2Kof data
2K
AckNo=2048 RcvWin=2048Sendersends 2Kof data 2K SeqNo=2048
4K
AckNo=4096 RcvWin=0
AckNo=4096 RcvWin=1024
Sender blocked
Transport Layer 3-71
Principles of Congestion Control
Congestioninformally ldquotoo many sources sending too much data too fast for network to handlerdquodifferent from flow controlmanifestations
lost packets (buffer overflow at routers)long delays (queueing in router buffers)
a top-10 problem
Transport Layer 3-72
Causescosts of congestion scenario 1
two senders two receiversone router infinite buffers no retransmission
large delays when congestedmaximum achievable throughput
unlimited shared output link buffers
Host Aλin original data
Host B
λout
Transport Layer 3-73
Causescosts of congestion scenario 2
one router finite buffers sender retransmission of lost packet
finite shared output link buffers
Host A λin original data
Host B
λout
λin original data plus retransmitted data
Transport Layer 3-74
Causescosts of congestion scenario 2always (goodput)ldquoperfectrdquo retransmission only when loss
retransmission of delayed (not lost) packet makes larger(than perfect case) for same
λin
λout=
λin
λoutgtλ
inλout
ldquocostsrdquo of congestionmore work (retrans) for given ldquogoodputrdquounneeded retransmissions link carries multiple copies of pkt
R2
R2λin
λ out
b
R2
R2λin
λ out
a
R2
R2λin
λ out
c
R4
R3
Transport Layer 3-75
Causescosts of congestion scenario 3four sendersmultihop pathstimeoutretransmit
λin
Q what happens as and increase λ
in
finite shared output link buffers
Host Aλin original data
Host B
λout
λin original data plus retransmitted data
Transport Layer 3-76
Causescosts of congestion scenario 3
another ldquocostrdquo of congestionwhen packet dropped any ldquoupstream transmission capacity used for that packet was wasted
Host A
Host B
λou
t
Transport Layer 3-77
Approaches towards congestion control
End-end congestion controlno explicit feedback from networkcongestion inferred from end-system observed loss delayapproach taken by TCP
Network-assisted congestion controlrouters provide feedback to end systems
single bit indicating congestion (SNA DECbit TCPIP ECN ATM)explicit rate sender should send at
Two broad approaches towards congestion control
Transport Layer 3-78
TCP Congestion Control
end-end control (no network assistance)sender limits transmissionLastByteSent-LastByteAcked
le CongWin
CongWin is dynamic function of perceived network congestion
How does sender perceive congestionloss event = timeout or3 duplicate acksTCP sender reduces rate (CongWin) after loss event
two modes of operationSlow Start (SS)Congestion avoidance (CA) or Additive Increase Multiplicative Decrease (AIMD)
Transport Layer 3-79
TCP congestion control bandwidth probing
ldquoprobing for bandwidthrdquo increase transmission rate on receipt of ACK until eventually loss occurs then decrease transmission rate
continue to increase on ACK decrease on loss (since available bandwidth is changing depending on other connections in network)
ACKs being received so increase rate
X
X
XX
X loss so decrease rate
send
ing
rate
time
Q how fast to increasedecreasedetails to follow
TCPrsquosldquosawtoothrdquobehavior
Transport Layer 3-80
TCP Congestion Control details
sender limits rate by limiting number of unACKed bytes ldquoin pipelinerdquo
cwnd differs from rwnd (how why)sender limited by min(cwndrwnd)
roughly
cwnd is dynamic function of perceived network congestion
rate = cwndRTT bytessec
LastByteSent-LastByteAcked le cwnd
cwndbytes
RTT
ACK(s)
Transport Layer 3-81
TCP Congestion Control more details
segment loss event reducing cwndtimeout no response from receiver
cut cwnd to 13 duplicate ACKs at least some segments getting through (recall fast retransmit)
cut cwnd in half less aggressively than on timeout
ACK received increase cwndTwo modes of operation
slowstart phase bull increase exponentially
fast (despite name) at connection start or following timeout
congestion avoidance bull increase linearly
Transport Layer 3-82
TCP Slow Start Phasewhen connection begins cwnd = 1 MSS
example MSS = 500 bytes amp RTT = 200 msecinitial rate = 20 kbps
available bandwidth may be gtgt MSSRTT
desirable to quickly ramp up to respectable rate
increase rate exponentially until first loss event or when threshold reached
double cwnd every RTTdone by incrementing cwnd by 1 for every ACK received
Host A
one segment
RTT
Host B
time
two segments
four segments
Transport Layer 3-83
Slow Start ExampleThe congestion window size grows very rapidly
For every ACK we increase CongWin by 1 irrespective of the number of segments ACKrsquoeddouble CongWinevery RTTinitial rate is slow but ramps up exponentially fast
TCP slows down the increase of CongWinwhen CongWin gt ssthresh
segment 1
ACK for segment 1
cwnd = 1
cwnd = 2 segment 2segment 3
ACK for segments 2
cwnd = 4 segment 4segment 5segment 6
ACK for segments 4
cwnd = 7
ACK for segments 3
ACK for segments 5
ACK for segments 6
cwnd = 3
cwnd = 5
cwnd = 6ACK for segments 7
cwnd = 8
segment 7
Transport Layer 3-84
TCP Congestion Avoidance Phase
when cwnd gt ssthreshgrow cwnd linearly
increase cwnd by 1 MSS per RTT approach possible congestion slower than in slowstartimplementation cwnd= cwnd + MSScwndfor each ACK received
ACKs increase cwndby 1 MSS per RTT additive increaseloss cut cwnd in half (non-timeout-detected loss ) multiplicative decrease
AIMD
AIMD Additive IncreaseMultiplicative Decrease
Transport Layer 3-85
Congestion AvoidanceCongestion avoidance phase is started if CongWin has reached the slow-start threshold value
If CongWin gt= ssthresh then each time an ACK is received increment CongWin as follows
bull CongWin = CongWin + 1CongWin (CongWin in segments)
bull In actual TCP implementation CongWin is in BytesCongWin = CongWin + MSS (MSSCongWin)
So CongWin is increased by one only if all CongWinsegments have been acknowledged
Transport Layer 3-86
Example Slow StartCongestion AvoidanceAssume that
ssthresh = 8
cwnd = 1
cwnd = 2
cwnd = 4
cwnd = 8
cwnd = 9
cwnd = 10
02468
101214
t=0
t=2
t=4
t=6
Roundtrip times
Cw
nd(in
seg
men
ts)
ssthresh
cwnd = 3
cwnd = 5cwnd = 6cwnd = 7
Transport Layer 3-87
Slow Start Congestion AvoidanceA typical plot of CongWin for a TCP connection
(MSS = 1500 bytes) with TCP Tahoe
SS
CA
ssthresh
Transport Layer 3-88
Responses to CongestionTCP assumes there is congestion if it detects a packet lossA TCP sender can detect lost packets via loss events
bull Timeout of a retransmission timerbull Receipt of 3 duplicate ACKs (fast retransmit)
TCP interprets a Timeout as a binary congestion signal When a timeout occurs the sender performs
ssthresh is set to half the current size of the congestion window
ssthresh = CongWin 2CongWin is reset to one
CongWin = 1and slow-start is entered
Transport Layer 3-89
Fast Recovery (differentiation btwn two loss events) After 3 dup ACKs (fast Retransmit)
ssthresh = CongWin2CongWin = CongWin2window then grows linearly
But after timeout eventCongWin = 1 MSS window then grows exponentiallyto the threshold then grows linearly
bull 3 dup ACKs indicates network capable of delivering some segmentsbull timeout before 3 dup ACKs is ldquomore alarmingrdquo
Philosophy
3-90
TCP Congestion ControlInitially
CongWin = 1ssthresh = advertised window size
New Ack receivedif (CongWin lt ssthresh) Slow Start
CongWin = CongWin + 1else Congestion Avoidance
CongWin = CongWin + 1CongWinTimeout
ssthresh = CongWin2CongWin = 1
Fast Retransmissionssthresh = CongWin2CongWin = CongWin2
Slow Start (exponential increase phase) is continued until CongWin reaches half of the level where the loss event occurred last time CongWin is increased slowly after (linear increase in Congestion Avoidance phase)
Transport Layer 3-91
Popular ldquoflavorsrdquo of TCP
ssthresh
ssthresh
TCP Tahoe
TCP Reno
Transmission round
cwnd
win
dow
siz
e (in
seg
men
ts)
Transport Layer 3-92
Summary TCP Congestion ControlWhen CongWin is below Threshold sender in slow-start phase window grows exponentiallyWhen CongWin is above Threshold sender is in congestion-avoidance phase window grows linearlyWhen a triple duplicate ACK occurs Threshold set to CongWin2 and CongWin set to ThresholdWhen timeout occurs Threshold set to CongWin2 and CongWin is set to 1 MSS The actual sender window size is determined based on the congestion and flow control algorithms
SenderWin=min(RcvWinCongWin)
Transport Layer 3-93
TCP Congestion Control SummaryEvent State TCP Sender Action Commentary
ACK receipt for previously unackeddata
Slow Start (SS)
CongWin = CongWin + MSS If (CongWin gt Threshold)
set state to ldquoCongestion Avoidancerdquo
Resulting in a doubling of CongWin every RTT
ACK receipt for previously unackeddata
CongestionAvoidance (CA)
CongWin = CongWin+MSS (MSSCongWin)
Additive increase resulting in increase of CongWin by 1 MSS every RTT
Loss event detected by triple duplicate ACK
SS or CA Threshold = CongWin2 CongWin = ThresholdSet state to ldquoCongestion Avoidancerdquo
Fast recovery implementing multiplicative decrease CongWin will not drop below 1 MSS
Timeout SS or CA Threshold = CongWin2 CongWin = 1 MSSSet state to ldquoSlow Startrdquo
Enter slow start
Duplicate ACK
SS or CA Increment duplicate ACK count for segment being acked
CongWin and Threshold not changed
Transport Layer 3-94
TCP throughput
Q whatrsquos average throughout of TCP as function of window size RTT
ignoring slow startlet W be window size when loss occurs
when window is W throughput is WRTTjust after loss window drops to W2 throughput to W2RTT average throughout 75 WRTT
Transport Layer 3-95
TCP Futures TCP over ldquolong fat pipesrdquo
example 1500 byte segments 100ms RTT want 10 Gbps throughputrequires window size W = 83333 in-flight segmentsthroughput in terms of loss rate
L = 210-10 Wownew versions of TCP for high-speed
LRTTMSSsdot221
Transport Layer 3-96
Fairness goal if K TCP sessions share same bottleneck link of bandwidth R each should have average rate of RK
TCP connection 1
bottleneckrouter
capacity R
TCP connection 2
TCP Fairness
Transport Layer 3-97
Why is TCP fairTwo competing sessions
Additive increase gives slope of 1 as throughout increasesmultiplicative decrease decreases throughput proportionally
R
R
equal bandwidth share
Connection 1 throughput
Conn
ecti
on 2
thr
ough
p ut
congestion avoidance additive increaseloss decrease window by factor of 2
congestion avoidance additive increaseloss decrease window by factor of 2
Transport Layer 3-98
Fairness (more)Fairness and UDP
Multimedia apps often do not use TCP
do not want rate throttled by congestion control
Instead use UDPpump audiovideo at constant rate tolerate packet loss
Research area TCP friendly
Fairness and parallel TCP connectionsnothing prevents app from opening parallel cnctionsbetween 2 hostsWeb browsers do this Example link of rate R supporting 9 cnctions
new app asks for 1 TCP gets rate R10new app asks for 11 TCPs gets R2
Transport Layer 3-99
TCP Connection ManagementRecall TCP sender receiver
establish ldquoconnectionrdquobefore exchanging data segmentsinitialize TCP variables
seq sbuffers flow control info (eg RcvWindow)
client connection initiatorSocket clientSocket = new Socket(hostnameport
number)
server contacted by clientSocket connectionSocket = welcomeSocketaccept()
Three way handshakeStep 1 client host sends TCP
SYN segment to serverspecifies initial seq no data
Step 2 server host receives SYN replies with SYNACK segment
server allocates buffersspecifies server initial seq
Step 3 client receives SYNACK replies with ACK segment which may contain data
Transport Layer 3-100
TCP Connection Management (cont)
Closing a connection
client closes socketclientSocketclose()
Step 1 client end system sends TCP FIN control segment to server
Step 2 server receives FIN replies with ACK Closes connection sends FIN
client
FIN
server
ACK
ACK
FIN
close
close
closed
tim
ed w
ait
Transport Layer 3-101
TCP Connection Management (cont)
Step 3 client receives FIN replies with ACK
Enters ldquotimed waitrdquo -will respond with ACK to received FINs
Step 4 server receives ACK Connection closed
client
FIN
server
ACK
ACK
FIN
closing
closing
closed
tim
ed w
ait
closed
Transport Layer 3-102
TCP Connection Management (cont)
TCP clientlifecycle
TCP serverlifecycle
Transport Layer 3-103
Tuning TCPIP Parameters TCPIP parameters
A set of default values may not be optimal for all applicationsThe network administrator may wish to turn on or off some TCPIP functions for performance or security considerations
Many Unix and Linux systems provide some flexibility in tuning the TCPIP kernelsbinsysctl is used to configure the Linux kernel parameters at runtime
Default kernel configuration file is sbinsysctlconfFrequently used sysctl options
bull sysctl ndasha or sysctl ndashA list all current valuesbull sysctl ndashp file_name load the sysctl setting from a configuration
filebull sysctl ndashw variable=value change the value of the parameter
Transport Layer 3-104
SomeTCP Parameters in Linux Kerneltcp_syn_retries
Number of SYN packets the kernel will send before giving up on the new connection
tcp_synack_retriesnumber of SYN+ACK packets sent before the kernel gives up on the connection
tcp_window_scalingMaximum window size of 65535 bytes not enough for for really fast networks The window scaling options allows for almost gigabyte windows which is good for connections with large delay-bandwidth product
tcp_max_syn_backlogMaximal number of remembered connection requests which still did not receive an acknowledgment from connecting client
tcp_fin_timeoutHow many seconds to wait for a final FIN packet before the socket is closed required to prevent denial-of-service (DoS) attacks Default value is 60 seconds
Transport Layer 3-105
SomeTCP Parameters in Linux Kerneltcp_rmem
This is a vector of 3 integers [min default max] These parameters are used by TCP to dynamically adjust receive buffer sizesmin - minimum size of the receive buffer used by each TCP socket The default value is 4K default - the default size of the receive buffer for a TCP socket The default value is 87380 bytes and is lowered to 43689 in low memory systems If larger receive buffer sizes are desired this value should be increased max - the maximum size of the receive buffer used by each TCP socket The default value of 873802 bytes is lowered to 87380 in low memory systems
tcp_smemSend buffer parameters [min default max] similar to tcp_rmem
- Chapter 3 Transport Layer
- Transport services and protocols
- Transport vs network layer
- Internet transport-layer protocols
- Multiplexingdemultiplexing
- How demultiplexing works
- Connectionless demultiplexing
- Connection-oriented demux
- Connection-oriented demux (cont)
- Connection-oriented demux Threaded Web Server
- UDP User Datagram Protocol [RFC 768]
- UDP more
- UDP checksum
- Principles of Reliable data transfer
- Reliable data transfer getting started
- Reliable data transfer getting started
- Rdt10 reliable transfer over a reliable channel
- Rdt20 channel with bit errors
- rdt20 FSM specification
- rdt20 operation with no errors
- rdt20 error scenario
- rdt20 has a fatal flaw
- rdt21 sender handles garbled ACKNAKs
- rdt21 receiver handles garbled ACKNAKs
- rdt21 discussion
- rdt22 a NAK-free protocol
- rdt22 sender receiver fragments
- rdt30 channels with errors and loss
- rdt30 sender
- rdt30 in action
- rdt30 in action
- Performance of rdt30
- rdt30 stop-and-wait operation
- Pipelined protocols
- Pipelining increased utilization
- Go-Back-N
- GBN sender extended FSM
- GBN receiver extended FSM
- GBN inaction
- Selective Repeat
- Selective repeat sender receiver windows
- Selective repeat
- Selective repeat in action
- Selective repeat dilemma
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- TCP Overview RFCs 793 1122 1323 2018 2581
- TCP segment structure
- TCP seq rsquos and ACKs
- TCP Round Trip Time and Timeout
- TCP Round Trip Time and Timeout
- Example RTT estimation
- TCP Round Trip Time and Timeout
- TCP reliable data transfer
- TCP sender events
- TCP sender(simplified)
- TCP retransmission scenarios
- TCP retransmission scenarios (more)
- TCP ACK generation [RFC 1122 RFC 2581]
- Fast Retransmit
- Fast Retransmit
- Fast retransmit algorithm
- TCP Flow Control
- TCP Flow control how it works
- Sliding Window Flow Control Example
- Principles of Congestion Control
- Causescosts of congestion scenario 1
- Causescosts of congestion scenario 2
- Causescosts of congestion scenario 2
- Causescosts of congestion scenario 3
- Causescosts of congestion scenario 3
- Approaches towards congestion control
- TCP Congestion Control
- TCP congestion control bandwidth probing
- TCP Congestion Control details
- TCP Congestion Control more details
- TCP Slow Start Phase
- Slow Start Example
- TCP Congestion Avoidance Phase
- Congestion Avoidance
- Example Slow StartCongestion Avoidance
- Slow Start Congestion Avoidance
- Responses to Congestion
- Fast Recovery (differentiation btwn two loss events)
- TCP Congestion Control
- Popular ldquoflavorsrdquo of TCP
- Summary TCP Congestion Control
- TCP Congestion Control Summary
- TCP throughput
- TCP Futures TCP over ldquolong fat pipesrdquo
- TCP Fairness
- Why is TCP fair
- Fairness (more)
- TCP Connection Management
- TCP Connection Management (cont)
- TCP Connection Management (cont)
- TCP Connection Management (cont)
- Tuning TCPIP Parameters
- SomeTCP Parameters in Linux Kernel
- SomeTCP Parameters in Linux Kernel
-
Transport Layer 3-28
rdt30 channels with errors and loss
New assumptionunderlying channel can also lose packets (data or ACKs)
checksum seq ACKs retransmissions will be of help but not enough
Q how to deal with losssender waits until certain data or ACK lost then retransmitsdrawbacks
Approach sender waits ldquoreasonablerdquo amount of time for ACK retransmits if no ACK received in this timeif pkt (or ACK) just delayed (not lost)
retransmission will be duplicate but use of seq rsquos already handles thisreceiver must specify seq of pkt being ACKed
requires countdown timer
Transport Layer 3-29
rdt30 sendersndpkt = make_pkt(0 data checksum)udt_send(sndpkt)start_timer
rdt_send(data)
Wait for
ACK0
rdt_rcv(rcvpkt) ampamp ( corrupt(rcvpkt) ||isACK(rcvpkt1) )
Wait for call 1 from
above
sndpkt = make_pkt(1 data checksum)udt_send(sndpkt)start_timer
rdt_send(data)
rdt_rcv(rcvpkt) ampamp notcorrupt(rcvpkt) ampamp isACK(rcvpkt0)
rdt_rcv(rcvpkt) ampamp ( corrupt(rcvpkt) ||isACK(rcvpkt0) )
rdt_rcv(rcvpkt) ampamp notcorrupt(rcvpkt) ampamp isACK(rcvpkt1)
stop_timerstop_timer
udt_send(sndpkt)start_timer
timeout
udt_send(sndpkt)start_timer
timeout
rdt_rcv(rcvpkt)
Wait for call 0from
above
Wait for
ACK1
Λrdt_rcv(rcvpkt)
ΛΛ
Λ
Transport Layer 3-30
rdt30 in action
Transport Layer 3-31
rdt30 in action
Transport Layer 3-32
Performance of rdt30
rdt30 works but performance stinksexample 1 Gbps link 15 ms e-e prop delay 1KB packet
Ttransmit = 8kbpkt109 bsec = 8 microsec
U sender utilization ndash fraction of time sender busy sending1KB pkt every 30 msec -gt 33kBsec thruput over 1 Gbps linknetwork protocol limits use of physical resources
U sender=
008 30008
= 000027 L RRTT + L R
=
L (packet length in bits)R (transmission rate bps) =
Transport Layer 3-33
rdt30 stop-and-wait operation
first packet bit transmitted t = 0
sender receiver
RTT
last packet bit transmitted t = L R
first packet bit arriveslast packet bit arrives send ACK
ACK arrives send next packet t = RTT + L R
U sender=
00830008
= 000027 L RRTT + L R
=
Transport Layer 3-34
Pipelined protocolsPipelining sender allows multiple ldquoin-flightrdquo yet-to-
be-acknowledged pktsrange of sequence numbers must be increasedbuffering at sender andor receiver
Two generic forms of pipelined protocols go-Back-N selective repeat
Transport Layer 3-35
Pipelining increased utilization
first packet bit transmitted t = 0
sender receiver
RTT
last bit transmitted t = L R
first packet bit arriveslast packet bit arrives send ACK
ACK arrives send next packet t = RTT + L R
last bit of 2nd packet arrives send ACKlast bit of 3rd packet arrives send ACK
U sender=
024 30008
= 000083 L RRTT + L R
=
Increase utilizationby a factor of 3
Transport Layer 3-36
Utilization=N(LR)(RTT+LR) if NLRltRTT+LR Utilization=1 if and the sender pauses after it transmits a window NLRgtRTT+LR and the of packets until it receives first ACK sender does not pause
Transport Layer 3-37
Go-Back-NSender
k-bit seq in pkt headerldquowindowrdquo of up to N consecutive unackrsquoed pkts allowed
ACK(n) ACKs all pkts up to including seq n - ldquocumulative ACKrdquomay receive duplicate ACKs (see receiver)
timer for the entire windowtimeout(n) retransmit pkt n and all higher seq pkts in window
Transport Layer 3-38
GBN sender extended FSM
Wait start_timerudt_send(sndpkt[base])udt_send(sndpkt[base+1])hellipudt_send(sndpkt[nextseqnum-1])
timeout
rdt_send(data)
if (nextseqnum lt base+N) sndpkt[nextseqnum] = make_pkt(nextseqnumdatachksum)udt_send(sndpkt[nextseqnum])if (base == nextseqnum)
start_timernextseqnum++
elserefuse_data(data)
base = getacknum(rcvpkt)+1If (base == nextseqnum)
stop_timerelse
start_timer
rdt_rcv(rcvpkt) ampamp notcorrupt(rcvpkt)
base=1nextseqnum=1
rdt_rcv(rcvpkt) ampamp corrupt(rcvpkt)
Λ
Λ
Transport Layer 3-39
GBN receiver extended FSM
ACK-only always send ACK for correctly-received pktwith highest in-order seq
may generate duplicate ACKsneed only remember expectedseqnum
out-of-order pkt discard (donrsquot buffer) -gt no receiver bufferingRe-ACK pkt with highest in-order seq
Wait
udt_send(sndpkt)default
rdt_rcv(rcvpkt)ampamp notcurrupt(rcvpkt)ampamp hasseqnum(rcvpktexpectedseqnum)
extract(rcvpktdata)deliver_data(data)sndpkt = make_pkt(expectedseqnumACKchksum)udt_send(sndpkt)expectedseqnum++
expectedseqnum=1sndpkt =
make_pkt(0ACKchksum)
Λ
Transport Layer 3-40
GBN inaction
Transport Layer 3-41
Selective Repeat
receiver individually acknowledges all correctly received pkts
buffers pkts as needed for eventual in-order delivery to upper layer
sender only resends pkts for which ACK not received
sender timer for each unACKed pktsender window
N consecutive seq rsquosagain limits seq s of sent unACKed pkts
Transport Layer 3-42
Selective repeat sender receiver windows
Transport Layer 3-43
Selective repeat
data from above if next available seq in window send pkt
timeout(n)resend pkt n restart timer
ACK(n) in [sendbasesendbase+N-1]
mark pkt n as receivedif n smallest unACKed pkt advance window base to next unACKed seq
senderpkt n in [rcvbase rcvbase+N-1]
send ACK(n)out-of-order bufferin-order deliver (also deliver buffered in-order pkts) advance window to next not-yet-received pkt
pkt n in [rcvbase-Nrcvbase-1]
ACK(n)otherwise
ignore
receiver
Transport Layer 3-44
Selective repeat in action
Transport Layer 3-45
Selective repeatdilemma
Example seq rsquos 0 1 2 3window size=3
receiver sees no difference in two scenariosincorrectly passes duplicate data as new in (a)
Q what relationship between seq size and window size
Transport Layer 3-46
Sequence Number vs Window SizeSuppose we use k bits to represent SNQuestion Whatrsquos the minimum number of bits k necessary for a window size of N
sender
receiver
Go-Back-N
expectedSN
snd_base=expectedSN
Q For a given expectedSN whatrsquos the largest possible value for snd_baseA If all the last N ACKs sent by the receiver are received
snd_base = expectedSNexpectedSN+N-1
senderrsquos window
Transport Layer 3-47
Sequence Number vs Window SizeSuppose we use k bits to represent SNQuestion Whatrsquos the minimum number of bits k necessary for a window size of N
sender
receiver
Go-Back-N
expectedSN
snd_base=expectedSN-N
Q For a given expectedSN whatrsquos the smallest possible value for snd_baseA If all the last N ACKs sent by the receiver are not received
snd_base = expectedSN-NexpectedSN-1
senderrsquos window
Transport Layer 3-48
Sequence Number vs Window Size
sender
receiver
Go-Back-N
expectedSN
snd_base=expectedSN-N
All SNs in the interval [expectedSN-NexpectedSN+N-1] (an interval of size 2N) can be received by the receiver Since the receiver accepts on the packet with SN=expectedSN there should be no other packet within this interval with SN=expectedSN Therefore
2k ge N+1expectedSN+N-1
Transport Layer 3-49
Sequence Number vs Window SizeSuppose we use k bits to represent SNQuestion Whatrsquos the minimum number of bits k necessary for a window size of N
sender
receiver
Selective Repeat
rcv_base
snd_base=rcv_base
Q For a given rcv_base whatrsquos the largest possible value for snd_baseA If all the last N ACKs sent by the receiver are received
snd_base = rcv_base (same as go_back-N)rcv_base+N-1
senderrsquos window
receiverrsquos window
rcv_base+N-1
Transport Layer 3-50
Sequence Number vs Window SizeSuppose we use k bits to represent SNQuestion Whatrsquos the minimum number of bits k necessary for a window size of N
sender
receiver
Selective Repeat
rcv_base
snd_base=rcv_base-N
Q For a given rcv_base whatrsquos the smallest possible value for snd_baseA If all the last N ACKs sent by the receiver are not received
snd_base = rcv_base-N (same as Go-Back-N)rcv_base-1
senderrsquos window
rcv_base
receiverrsquos window
rcv_base+N-1
Transport Layer 3-51
Sequence Number vs Window Size
sender
receiver
Selective Repeat
snd_base=rcv_base-N
All SNs in the interval [rcv_base-Nrcv_base+N-1] (an interval of size 2N) can be received by the receiver Since the receiver should be able to distinguish between all packets in this interval and take corresponding action there should be no two packets within thisinterval having the same SN Therefore
2k ge 2Nrcv_base+N-1
rcv_basercv_base
receiverrsquos window
rcv_base+N-1
Transport Layer 3-52
TCP Overview RFCs 793 1122 1323 2018 2581
full duplex databi-directional data flow in same connectionMSS maximum segment size
connection-orientedhandshaking (exchange of control msgs) initrsquossender receiver state before data exchange
flow controlledsender will not overwhelm receiver
point-to-pointone sender one receiver
reliable in-order byte stream
no ldquomessage boundariesrdquopipelined
TCP congestion and flow control set window size
send amp receive buffers
socketdoor
TCPsend buffer
TCPreceive buffer
socketdoor
segment
applicationwrites data
applicationreads data
Transport Layer 3-53
TCP segment structure
source port dest port
32 bits
applicationdata
(variable length)
sequence numberacknowledgement number
Receive windowUrg data pnterchecksum
FSRPAUheadlen
notused
Options (variable length)
URG urgent data (generally not used)
ACK ACK valid
PSH push data now(generally not used)
RST SYN FINconnection estab(setup teardown
commands)
bytes rcvr willingto accept
Internetchecksum
(as in UDP)
countingby bytes of data(not segments)
Transport Layer 3-54
TCP seq rsquos and ACKsSeq rsquos
byte stream ldquonumberrdquo of first byte in segmentrsquos dataACKs
seq of next byte expected from other sidecumulative ACK
Q how receiver handles out-of-order segmentsA TCP spec doesnrsquot say - up to implementationWidely used implementations of TCP buffer out-of-order segments
Transport Layer 3-55
TCP Round Trip Time and Timeout
Q how to set TCP timeout valuelonger than RTT
but RTT variestoo short premature timeout
unnecessary retransmissions
too long slow reaction to segment loss
Q how to estimate RTTSampleRTT measured time from segment transmission until ACK receipt
ignore retransmissionsSampleRTT will vary want estimated RTT ldquosmootherrdquo
average several recent measurements not just current SampleRTT
Transport Layer 3-56
TCP Round Trip Time and Timeout
EstimatedRTT = (1- α)EstimatedRTT + αSampleRTT
Exponential weighted moving averageinfluence of past sample decreases exponentially fasttypical value α = 0125
Transport Layer 3-57
Example RTT estimationRTT gaiacsumassedu to fantasiaeurecomfr
100
150
200
250
300
350
1 8 15 22 29 36 43 50 57 64 71 78 85 92 99 106
time (seconnds)
RTT
(mill
iseco
nds)
SampleRTT Estimated RTT
Transport Layer 3-58
TCP Round Trip Time and TimeoutSetting the timeout
EstimatedRTT plus ldquosafety marginrdquolarge variation in EstimatedRTT -gt larger safety margin
first estimate of how much SampleRTT deviates from EstimatedRTT
TimeoutInterval = EstimatedRTT + 4DevRTT
DevRTT = (1-β)DevRTT +β|SampleRTT-EstimatedRTT|
(typically β = 025)
Then set timeout interval
Transport Layer 3-59
TCP reliable data transfer
TCP creates rdtservice on top of IPrsquos unreliable servicePipelined segmentsCumulative acksTCP uses single retransmission timer however it just retransmits the first segment in the window
Retransmissions are triggered by
timeout eventsduplicate acks
Initially consider simplified TCP sender
ignore duplicate acksignore flow control congestion control
Transport Layer 3-60
TCP sender eventsdata rcvd from app
Create segment with seq seq is byte-stream number of first data byte in segmentstart timer if not already running (think of timer as for oldest unacked segment)expiration interval TimeOutInterval
timeoutretransmit segment that caused timeout (first segment in the window)restart timer
Ack rcvdIf acknowledges previously unacked segments
update what is known to be ackedstart timer if there are outstanding segments
Transport Layer 3-61
TCP sender(simplified)
NextSeqNum = InitialSeqNumSendBase = InitialSeqNum
loop (forever) switch(event)
event data received from application above create TCP segment with sequence number NextSeqNumif (timer currently not running)
start timerpass segment to IP NextSeqNum = NextSeqNum + length(data)
event timer timeoutretransmit not-yet-acknowledged segment with
smallest sequence numberstart timer
event ACK received with ACK field value of y if (y gt SendBase)
SendBase = yif (there are currently not-yet-acknowledged segments)
start timer
end of loop forever
Commentbull SendBase-1 last cumulatively ackrsquoed byteExamplebull SendBase-1 = 71y= 73 so the rcvrwants 73+ y gt SendBase sothat new data is acked
Transport Layer 3-62
TCP retransmission scenariosHost A
Seq=100 20 bytes data
ACK=100
timepremature timeout
Host B
Seq=92 8 bytes data
ACK=120
Seq=92 8 bytes data
Seq=
92 t
imeo
ut
ACK=120
Host A
Seq=92 8 bytes data
ACK=100
loss
tim
eout
lost ACK scenario
Host B
X
Seq=92 8 bytes data
ACK=100
time
Seq=
92 t
imeo
utSendBase
= 100
SendBase= 120
SendBase= 120
Sendbase= 100
Transport Layer 3-63
TCP retransmission scenarios (more)Host A
Seq=92 8 bytes data
ACK=100
loss
tim
eout
Cumulative ACK scenario
Host B
X
Seq=100 20 bytes data
ACK=120
time
SendBase= 120
Transport Layer 3-64
TCP ACK generation [RFC 1122 RFC 2581]
Event at Receiver
Arrival of in-order segment withexpected seq All data up toexpected seq already ACKed
Arrival of in-order segment withexpected seq One other segment has ACK pending
Arrival of out-of-order segmenthigher-than-expect seq Gap detected
Arrival of segment that partially or completely fills gap
TCP Receiver action
Delayed ACK Wait up to 500msfor next segment If no next segmentsend ACK
Immediately send single cumulative ACK ACKing both in-order segments
Immediately send duplicate ACK indicating seq of next expected byte
Immediate send ACK provided thatsegment startsat lower end of gap
Transport Layer 3-65
Fast Retransmit
Time-out period often relatively long
long delay before resending lost packet
Detect lost segments via duplicate ACKs
Sender often sends many segments back-to-backIf segment is lost there will likely be many duplicate ACKs
If sender receives 3 ACKs for the same data it supposes that segment after ACKeddata was lost
fast retransmit resend segment before timer expires
Transport Layer 3-66
Fast RetransmitResend a segment after 3 duplicate ACKs since a duplicate ACK means that an out-of sequence segment was receivedduplicate ACKs due to packet reorderingif window is small donrsquot get duplicate ACKs
Host A
tim
eout
Host B
time
X
resend seq X2
seq x1seq x2seq x3seq x4seq x5
ACK x1
ACK x1ACK x1ACK x1
tripleduplicate
ACKs
Transport Layer 3-67
event ACK received with ACK field value of y if (y gt SendBase)
SendBase = yif (there are currently not-yet-acknowledged segments)
start timer
else increment count of dup ACKs received for yif (count of dup ACKs received for y = 3)
resend segment with sequence number y
Fast retransmit algorithm
a duplicate ACK for already ACKed segment
fast retransmit
Transport Layer 3-68
TCP Flow Control
receive side of TCP connection has a receive buffer
speed-matching service matching the send rate to the receiving apprsquos drain rate
app process may be slow at reading from buffer
sender wonrsquot overflowreceiverrsquos buffer by
transmitting too muchtoo fast
flow control
Transport Layer 3-69
TCP Flow control how it works
(Suppose TCP receiver discards out-of-order segments)spare room in buffer
= RcvWin
= RcvBuffer-[LastByteRcvd -LastByteRead]
Rcvr advertises spare room by including value of RcvWin in segmentsSender limits unACKeddata to RcvWin
guarantees receive buffer doesnrsquot overflow
Transport Layer 3-70
Sliding Window Flow Control Example
3K
2K SeqNo=0
ReceiverBuffer
0 4KSendersends 2Kof data
2K
AckNo=2048 RcvWin=2048Sendersends 2Kof data 2K SeqNo=2048
4K
AckNo=4096 RcvWin=0
AckNo=4096 RcvWin=1024
Sender blocked
Transport Layer 3-71
Principles of Congestion Control
Congestioninformally ldquotoo many sources sending too much data too fast for network to handlerdquodifferent from flow controlmanifestations
lost packets (buffer overflow at routers)long delays (queueing in router buffers)
a top-10 problem
Transport Layer 3-72
Causescosts of congestion scenario 1
two senders two receiversone router infinite buffers no retransmission
large delays when congestedmaximum achievable throughput
unlimited shared output link buffers
Host Aλin original data
Host B
λout
Transport Layer 3-73
Causescosts of congestion scenario 2
one router finite buffers sender retransmission of lost packet
finite shared output link buffers
Host A λin original data
Host B
λout
λin original data plus retransmitted data
Transport Layer 3-74
Causescosts of congestion scenario 2always (goodput)ldquoperfectrdquo retransmission only when loss
retransmission of delayed (not lost) packet makes larger(than perfect case) for same
λin
λout=
λin
λoutgtλ
inλout
ldquocostsrdquo of congestionmore work (retrans) for given ldquogoodputrdquounneeded retransmissions link carries multiple copies of pkt
R2
R2λin
λ out
b
R2
R2λin
λ out
a
R2
R2λin
λ out
c
R4
R3
Transport Layer 3-75
Causescosts of congestion scenario 3four sendersmultihop pathstimeoutretransmit
λin
Q what happens as and increase λ
in
finite shared output link buffers
Host Aλin original data
Host B
λout
λin original data plus retransmitted data
Transport Layer 3-76
Causescosts of congestion scenario 3
another ldquocostrdquo of congestionwhen packet dropped any ldquoupstream transmission capacity used for that packet was wasted
Host A
Host B
λou
t
Transport Layer 3-77
Approaches towards congestion control
End-end congestion controlno explicit feedback from networkcongestion inferred from end-system observed loss delayapproach taken by TCP
Network-assisted congestion controlrouters provide feedback to end systems
single bit indicating congestion (SNA DECbit TCPIP ECN ATM)explicit rate sender should send at
Two broad approaches towards congestion control
Transport Layer 3-78
TCP Congestion Control
end-end control (no network assistance)sender limits transmissionLastByteSent-LastByteAcked
le CongWin
CongWin is dynamic function of perceived network congestion
How does sender perceive congestionloss event = timeout or3 duplicate acksTCP sender reduces rate (CongWin) after loss event
two modes of operationSlow Start (SS)Congestion avoidance (CA) or Additive Increase Multiplicative Decrease (AIMD)
Transport Layer 3-79
TCP congestion control bandwidth probing
ldquoprobing for bandwidthrdquo increase transmission rate on receipt of ACK until eventually loss occurs then decrease transmission rate
continue to increase on ACK decrease on loss (since available bandwidth is changing depending on other connections in network)
ACKs being received so increase rate
X
X
XX
X loss so decrease rate
send
ing
rate
time
Q how fast to increasedecreasedetails to follow
TCPrsquosldquosawtoothrdquobehavior
Transport Layer 3-80
TCP Congestion Control details
sender limits rate by limiting number of unACKed bytes ldquoin pipelinerdquo
cwnd differs from rwnd (how why)sender limited by min(cwndrwnd)
roughly
cwnd is dynamic function of perceived network congestion
rate = cwndRTT bytessec
LastByteSent-LastByteAcked le cwnd
cwndbytes
RTT
ACK(s)
Transport Layer 3-81
TCP Congestion Control more details
segment loss event reducing cwndtimeout no response from receiver
cut cwnd to 13 duplicate ACKs at least some segments getting through (recall fast retransmit)
cut cwnd in half less aggressively than on timeout
ACK received increase cwndTwo modes of operation
slowstart phase bull increase exponentially
fast (despite name) at connection start or following timeout
congestion avoidance bull increase linearly
Transport Layer 3-82
TCP Slow Start Phasewhen connection begins cwnd = 1 MSS
example MSS = 500 bytes amp RTT = 200 msecinitial rate = 20 kbps
available bandwidth may be gtgt MSSRTT
desirable to quickly ramp up to respectable rate
increase rate exponentially until first loss event or when threshold reached
double cwnd every RTTdone by incrementing cwnd by 1 for every ACK received
Host A
one segment
RTT
Host B
time
two segments
four segments
Transport Layer 3-83
Slow Start ExampleThe congestion window size grows very rapidly
For every ACK we increase CongWin by 1 irrespective of the number of segments ACKrsquoeddouble CongWinevery RTTinitial rate is slow but ramps up exponentially fast
TCP slows down the increase of CongWinwhen CongWin gt ssthresh
segment 1
ACK for segment 1
cwnd = 1
cwnd = 2 segment 2segment 3
ACK for segments 2
cwnd = 4 segment 4segment 5segment 6
ACK for segments 4
cwnd = 7
ACK for segments 3
ACK for segments 5
ACK for segments 6
cwnd = 3
cwnd = 5
cwnd = 6ACK for segments 7
cwnd = 8
segment 7
Transport Layer 3-84
TCP Congestion Avoidance Phase
when cwnd gt ssthreshgrow cwnd linearly
increase cwnd by 1 MSS per RTT approach possible congestion slower than in slowstartimplementation cwnd= cwnd + MSScwndfor each ACK received
ACKs increase cwndby 1 MSS per RTT additive increaseloss cut cwnd in half (non-timeout-detected loss ) multiplicative decrease
AIMD
AIMD Additive IncreaseMultiplicative Decrease
Transport Layer 3-85
Congestion AvoidanceCongestion avoidance phase is started if CongWin has reached the slow-start threshold value
If CongWin gt= ssthresh then each time an ACK is received increment CongWin as follows
bull CongWin = CongWin + 1CongWin (CongWin in segments)
bull In actual TCP implementation CongWin is in BytesCongWin = CongWin + MSS (MSSCongWin)
So CongWin is increased by one only if all CongWinsegments have been acknowledged
Transport Layer 3-86
Example Slow StartCongestion AvoidanceAssume that
ssthresh = 8
cwnd = 1
cwnd = 2
cwnd = 4
cwnd = 8
cwnd = 9
cwnd = 10
02468
101214
t=0
t=2
t=4
t=6
Roundtrip times
Cw
nd(in
seg
men
ts)
ssthresh
cwnd = 3
cwnd = 5cwnd = 6cwnd = 7
Transport Layer 3-87
Slow Start Congestion AvoidanceA typical plot of CongWin for a TCP connection
(MSS = 1500 bytes) with TCP Tahoe
SS
CA
ssthresh
Transport Layer 3-88
Responses to CongestionTCP assumes there is congestion if it detects a packet lossA TCP sender can detect lost packets via loss events
bull Timeout of a retransmission timerbull Receipt of 3 duplicate ACKs (fast retransmit)
TCP interprets a Timeout as a binary congestion signal When a timeout occurs the sender performs
ssthresh is set to half the current size of the congestion window
ssthresh = CongWin 2CongWin is reset to one
CongWin = 1and slow-start is entered
Transport Layer 3-89
Fast Recovery (differentiation btwn two loss events) After 3 dup ACKs (fast Retransmit)
ssthresh = CongWin2CongWin = CongWin2window then grows linearly
But after timeout eventCongWin = 1 MSS window then grows exponentiallyto the threshold then grows linearly
bull 3 dup ACKs indicates network capable of delivering some segmentsbull timeout before 3 dup ACKs is ldquomore alarmingrdquo
Philosophy
3-90
TCP Congestion ControlInitially
CongWin = 1ssthresh = advertised window size
New Ack receivedif (CongWin lt ssthresh) Slow Start
CongWin = CongWin + 1else Congestion Avoidance
CongWin = CongWin + 1CongWinTimeout
ssthresh = CongWin2CongWin = 1
Fast Retransmissionssthresh = CongWin2CongWin = CongWin2
Slow Start (exponential increase phase) is continued until CongWin reaches half of the level where the loss event occurred last time CongWin is increased slowly after (linear increase in Congestion Avoidance phase)
Transport Layer 3-91
Popular ldquoflavorsrdquo of TCP
ssthresh
ssthresh
TCP Tahoe
TCP Reno
Transmission round
cwnd
win
dow
siz
e (in
seg
men
ts)
Transport Layer 3-92
Summary TCP Congestion ControlWhen CongWin is below Threshold sender in slow-start phase window grows exponentiallyWhen CongWin is above Threshold sender is in congestion-avoidance phase window grows linearlyWhen a triple duplicate ACK occurs Threshold set to CongWin2 and CongWin set to ThresholdWhen timeout occurs Threshold set to CongWin2 and CongWin is set to 1 MSS The actual sender window size is determined based on the congestion and flow control algorithms
SenderWin=min(RcvWinCongWin)
Transport Layer 3-93
TCP Congestion Control SummaryEvent State TCP Sender Action Commentary
ACK receipt for previously unackeddata
Slow Start (SS)
CongWin = CongWin + MSS If (CongWin gt Threshold)
set state to ldquoCongestion Avoidancerdquo
Resulting in a doubling of CongWin every RTT
ACK receipt for previously unackeddata
CongestionAvoidance (CA)
CongWin = CongWin+MSS (MSSCongWin)
Additive increase resulting in increase of CongWin by 1 MSS every RTT
Loss event detected by triple duplicate ACK
SS or CA Threshold = CongWin2 CongWin = ThresholdSet state to ldquoCongestion Avoidancerdquo
Fast recovery implementing multiplicative decrease CongWin will not drop below 1 MSS
Timeout SS or CA Threshold = CongWin2 CongWin = 1 MSSSet state to ldquoSlow Startrdquo
Enter slow start
Duplicate ACK
SS or CA Increment duplicate ACK count for segment being acked
CongWin and Threshold not changed
Transport Layer 3-94
TCP throughput
Q whatrsquos average throughout of TCP as function of window size RTT
ignoring slow startlet W be window size when loss occurs
when window is W throughput is WRTTjust after loss window drops to W2 throughput to W2RTT average throughout 75 WRTT
Transport Layer 3-95
TCP Futures TCP over ldquolong fat pipesrdquo
example 1500 byte segments 100ms RTT want 10 Gbps throughputrequires window size W = 83333 in-flight segmentsthroughput in terms of loss rate
L = 210-10 Wownew versions of TCP for high-speed
LRTTMSSsdot221
Transport Layer 3-96
Fairness goal if K TCP sessions share same bottleneck link of bandwidth R each should have average rate of RK
TCP connection 1
bottleneckrouter
capacity R
TCP connection 2
TCP Fairness
Transport Layer 3-97
Why is TCP fairTwo competing sessions
Additive increase gives slope of 1 as throughout increasesmultiplicative decrease decreases throughput proportionally
R
R
equal bandwidth share
Connection 1 throughput
Conn
ecti
on 2
thr
ough
p ut
congestion avoidance additive increaseloss decrease window by factor of 2
congestion avoidance additive increaseloss decrease window by factor of 2
Transport Layer 3-98
Fairness (more)Fairness and UDP
Multimedia apps often do not use TCP
do not want rate throttled by congestion control
Instead use UDPpump audiovideo at constant rate tolerate packet loss
Research area TCP friendly
Fairness and parallel TCP connectionsnothing prevents app from opening parallel cnctionsbetween 2 hostsWeb browsers do this Example link of rate R supporting 9 cnctions
new app asks for 1 TCP gets rate R10new app asks for 11 TCPs gets R2
Transport Layer 3-99
TCP Connection ManagementRecall TCP sender receiver
establish ldquoconnectionrdquobefore exchanging data segmentsinitialize TCP variables
seq sbuffers flow control info (eg RcvWindow)
client connection initiatorSocket clientSocket = new Socket(hostnameport
number)
server contacted by clientSocket connectionSocket = welcomeSocketaccept()
Three way handshakeStep 1 client host sends TCP
SYN segment to serverspecifies initial seq no data
Step 2 server host receives SYN replies with SYNACK segment
server allocates buffersspecifies server initial seq
Step 3 client receives SYNACK replies with ACK segment which may contain data
Transport Layer 3-100
TCP Connection Management (cont)
Closing a connection
client closes socketclientSocketclose()
Step 1 client end system sends TCP FIN control segment to server
Step 2 server receives FIN replies with ACK Closes connection sends FIN
client
FIN
server
ACK
ACK
FIN
close
close
closed
tim
ed w
ait
Transport Layer 3-101
TCP Connection Management (cont)
Step 3 client receives FIN replies with ACK
Enters ldquotimed waitrdquo -will respond with ACK to received FINs
Step 4 server receives ACK Connection closed
client
FIN
server
ACK
ACK
FIN
closing
closing
closed
tim
ed w
ait
closed
Transport Layer 3-102
TCP Connection Management (cont)
TCP clientlifecycle
TCP serverlifecycle
Transport Layer 3-103
Tuning TCPIP Parameters TCPIP parameters
A set of default values may not be optimal for all applicationsThe network administrator may wish to turn on or off some TCPIP functions for performance or security considerations
Many Unix and Linux systems provide some flexibility in tuning the TCPIP kernelsbinsysctl is used to configure the Linux kernel parameters at runtime
Default kernel configuration file is sbinsysctlconfFrequently used sysctl options
bull sysctl ndasha or sysctl ndashA list all current valuesbull sysctl ndashp file_name load the sysctl setting from a configuration
filebull sysctl ndashw variable=value change the value of the parameter
Transport Layer 3-104
SomeTCP Parameters in Linux Kerneltcp_syn_retries
Number of SYN packets the kernel will send before giving up on the new connection
tcp_synack_retriesnumber of SYN+ACK packets sent before the kernel gives up on the connection
tcp_window_scalingMaximum window size of 65535 bytes not enough for for really fast networks The window scaling options allows for almost gigabyte windows which is good for connections with large delay-bandwidth product
tcp_max_syn_backlogMaximal number of remembered connection requests which still did not receive an acknowledgment from connecting client
tcp_fin_timeoutHow many seconds to wait for a final FIN packet before the socket is closed required to prevent denial-of-service (DoS) attacks Default value is 60 seconds
Transport Layer 3-105
SomeTCP Parameters in Linux Kerneltcp_rmem
This is a vector of 3 integers [min default max] These parameters are used by TCP to dynamically adjust receive buffer sizesmin - minimum size of the receive buffer used by each TCP socket The default value is 4K default - the default size of the receive buffer for a TCP socket The default value is 87380 bytes and is lowered to 43689 in low memory systems If larger receive buffer sizes are desired this value should be increased max - the maximum size of the receive buffer used by each TCP socket The default value of 873802 bytes is lowered to 87380 in low memory systems
tcp_smemSend buffer parameters [min default max] similar to tcp_rmem
- Chapter 3 Transport Layer
- Transport services and protocols
- Transport vs network layer
- Internet transport-layer protocols
- Multiplexingdemultiplexing
- How demultiplexing works
- Connectionless demultiplexing
- Connection-oriented demux
- Connection-oriented demux (cont)
- Connection-oriented demux Threaded Web Server
- UDP User Datagram Protocol [RFC 768]
- UDP more
- UDP checksum
- Principles of Reliable data transfer
- Reliable data transfer getting started
- Reliable data transfer getting started
- Rdt10 reliable transfer over a reliable channel
- Rdt20 channel with bit errors
- rdt20 FSM specification
- rdt20 operation with no errors
- rdt20 error scenario
- rdt20 has a fatal flaw
- rdt21 sender handles garbled ACKNAKs
- rdt21 receiver handles garbled ACKNAKs
- rdt21 discussion
- rdt22 a NAK-free protocol
- rdt22 sender receiver fragments
- rdt30 channels with errors and loss
- rdt30 sender
- rdt30 in action
- rdt30 in action
- Performance of rdt30
- rdt30 stop-and-wait operation
- Pipelined protocols
- Pipelining increased utilization
- Go-Back-N
- GBN sender extended FSM
- GBN receiver extended FSM
- GBN inaction
- Selective Repeat
- Selective repeat sender receiver windows
- Selective repeat
- Selective repeat in action
- Selective repeat dilemma
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- TCP Overview RFCs 793 1122 1323 2018 2581
- TCP segment structure
- TCP seq rsquos and ACKs
- TCP Round Trip Time and Timeout
- TCP Round Trip Time and Timeout
- Example RTT estimation
- TCP Round Trip Time and Timeout
- TCP reliable data transfer
- TCP sender events
- TCP sender(simplified)
- TCP retransmission scenarios
- TCP retransmission scenarios (more)
- TCP ACK generation [RFC 1122 RFC 2581]
- Fast Retransmit
- Fast Retransmit
- Fast retransmit algorithm
- TCP Flow Control
- TCP Flow control how it works
- Sliding Window Flow Control Example
- Principles of Congestion Control
- Causescosts of congestion scenario 1
- Causescosts of congestion scenario 2
- Causescosts of congestion scenario 2
- Causescosts of congestion scenario 3
- Causescosts of congestion scenario 3
- Approaches towards congestion control
- TCP Congestion Control
- TCP congestion control bandwidth probing
- TCP Congestion Control details
- TCP Congestion Control more details
- TCP Slow Start Phase
- Slow Start Example
- TCP Congestion Avoidance Phase
- Congestion Avoidance
- Example Slow StartCongestion Avoidance
- Slow Start Congestion Avoidance
- Responses to Congestion
- Fast Recovery (differentiation btwn two loss events)
- TCP Congestion Control
- Popular ldquoflavorsrdquo of TCP
- Summary TCP Congestion Control
- TCP Congestion Control Summary
- TCP throughput
- TCP Futures TCP over ldquolong fat pipesrdquo
- TCP Fairness
- Why is TCP fair
- Fairness (more)
- TCP Connection Management
- TCP Connection Management (cont)
- TCP Connection Management (cont)
- TCP Connection Management (cont)
- Tuning TCPIP Parameters
- SomeTCP Parameters in Linux Kernel
- SomeTCP Parameters in Linux Kernel
-
Transport Layer 3-29
rdt30 sendersndpkt = make_pkt(0 data checksum)udt_send(sndpkt)start_timer
rdt_send(data)
Wait for
ACK0
rdt_rcv(rcvpkt) ampamp ( corrupt(rcvpkt) ||isACK(rcvpkt1) )
Wait for call 1 from
above
sndpkt = make_pkt(1 data checksum)udt_send(sndpkt)start_timer
rdt_send(data)
rdt_rcv(rcvpkt) ampamp notcorrupt(rcvpkt) ampamp isACK(rcvpkt0)
rdt_rcv(rcvpkt) ampamp ( corrupt(rcvpkt) ||isACK(rcvpkt0) )
rdt_rcv(rcvpkt) ampamp notcorrupt(rcvpkt) ampamp isACK(rcvpkt1)
stop_timerstop_timer
udt_send(sndpkt)start_timer
timeout
udt_send(sndpkt)start_timer
timeout
rdt_rcv(rcvpkt)
Wait for call 0from
above
Wait for
ACK1
Λrdt_rcv(rcvpkt)
ΛΛ
Λ
Transport Layer 3-30
rdt30 in action
Transport Layer 3-31
rdt30 in action
Transport Layer 3-32
Performance of rdt30
rdt30 works but performance stinksexample 1 Gbps link 15 ms e-e prop delay 1KB packet
Ttransmit = 8kbpkt109 bsec = 8 microsec
U sender utilization ndash fraction of time sender busy sending1KB pkt every 30 msec -gt 33kBsec thruput over 1 Gbps linknetwork protocol limits use of physical resources
U sender=
008 30008
= 000027 L RRTT + L R
=
L (packet length in bits)R (transmission rate bps) =
Transport Layer 3-33
rdt30 stop-and-wait operation
first packet bit transmitted t = 0
sender receiver
RTT
last packet bit transmitted t = L R
first packet bit arriveslast packet bit arrives send ACK
ACK arrives send next packet t = RTT + L R
U sender=
00830008
= 000027 L RRTT + L R
=
Transport Layer 3-34
Pipelined protocolsPipelining sender allows multiple ldquoin-flightrdquo yet-to-
be-acknowledged pktsrange of sequence numbers must be increasedbuffering at sender andor receiver
Two generic forms of pipelined protocols go-Back-N selective repeat
Transport Layer 3-35
Pipelining increased utilization
first packet bit transmitted t = 0
sender receiver
RTT
last bit transmitted t = L R
first packet bit arriveslast packet bit arrives send ACK
ACK arrives send next packet t = RTT + L R
last bit of 2nd packet arrives send ACKlast bit of 3rd packet arrives send ACK
U sender=
024 30008
= 000083 L RRTT + L R
=
Increase utilizationby a factor of 3
Transport Layer 3-36
Utilization=N(LR)(RTT+LR) if NLRltRTT+LR Utilization=1 if and the sender pauses after it transmits a window NLRgtRTT+LR and the of packets until it receives first ACK sender does not pause
Transport Layer 3-37
Go-Back-NSender
k-bit seq in pkt headerldquowindowrdquo of up to N consecutive unackrsquoed pkts allowed
ACK(n) ACKs all pkts up to including seq n - ldquocumulative ACKrdquomay receive duplicate ACKs (see receiver)
timer for the entire windowtimeout(n) retransmit pkt n and all higher seq pkts in window
Transport Layer 3-38
GBN sender extended FSM
Wait start_timerudt_send(sndpkt[base])udt_send(sndpkt[base+1])hellipudt_send(sndpkt[nextseqnum-1])
timeout
rdt_send(data)
if (nextseqnum lt base+N) sndpkt[nextseqnum] = make_pkt(nextseqnumdatachksum)udt_send(sndpkt[nextseqnum])if (base == nextseqnum)
start_timernextseqnum++
elserefuse_data(data)
base = getacknum(rcvpkt)+1If (base == nextseqnum)
stop_timerelse
start_timer
rdt_rcv(rcvpkt) ampamp notcorrupt(rcvpkt)
base=1nextseqnum=1
rdt_rcv(rcvpkt) ampamp corrupt(rcvpkt)
Λ
Λ
Transport Layer 3-39
GBN receiver extended FSM
ACK-only always send ACK for correctly-received pktwith highest in-order seq
may generate duplicate ACKsneed only remember expectedseqnum
out-of-order pkt discard (donrsquot buffer) -gt no receiver bufferingRe-ACK pkt with highest in-order seq
Wait
udt_send(sndpkt)default
rdt_rcv(rcvpkt)ampamp notcurrupt(rcvpkt)ampamp hasseqnum(rcvpktexpectedseqnum)
extract(rcvpktdata)deliver_data(data)sndpkt = make_pkt(expectedseqnumACKchksum)udt_send(sndpkt)expectedseqnum++
expectedseqnum=1sndpkt =
make_pkt(0ACKchksum)
Λ
Transport Layer 3-40
GBN inaction
Transport Layer 3-41
Selective Repeat
receiver individually acknowledges all correctly received pkts
buffers pkts as needed for eventual in-order delivery to upper layer
sender only resends pkts for which ACK not received
sender timer for each unACKed pktsender window
N consecutive seq rsquosagain limits seq s of sent unACKed pkts
Transport Layer 3-42
Selective repeat sender receiver windows
Transport Layer 3-43
Selective repeat
data from above if next available seq in window send pkt
timeout(n)resend pkt n restart timer
ACK(n) in [sendbasesendbase+N-1]
mark pkt n as receivedif n smallest unACKed pkt advance window base to next unACKed seq
senderpkt n in [rcvbase rcvbase+N-1]
send ACK(n)out-of-order bufferin-order deliver (also deliver buffered in-order pkts) advance window to next not-yet-received pkt
pkt n in [rcvbase-Nrcvbase-1]
ACK(n)otherwise
ignore
receiver
Transport Layer 3-44
Selective repeat in action
Transport Layer 3-45
Selective repeatdilemma
Example seq rsquos 0 1 2 3window size=3
receiver sees no difference in two scenariosincorrectly passes duplicate data as new in (a)
Q what relationship between seq size and window size
Transport Layer 3-46
Sequence Number vs Window SizeSuppose we use k bits to represent SNQuestion Whatrsquos the minimum number of bits k necessary for a window size of N
sender
receiver
Go-Back-N
expectedSN
snd_base=expectedSN
Q For a given expectedSN whatrsquos the largest possible value for snd_baseA If all the last N ACKs sent by the receiver are received
snd_base = expectedSNexpectedSN+N-1
senderrsquos window
Transport Layer 3-47
Sequence Number vs Window SizeSuppose we use k bits to represent SNQuestion Whatrsquos the minimum number of bits k necessary for a window size of N
sender
receiver
Go-Back-N
expectedSN
snd_base=expectedSN-N
Q For a given expectedSN whatrsquos the smallest possible value for snd_baseA If all the last N ACKs sent by the receiver are not received
snd_base = expectedSN-NexpectedSN-1
senderrsquos window
Transport Layer 3-48
Sequence Number vs Window Size
sender
receiver
Go-Back-N
expectedSN
snd_base=expectedSN-N
All SNs in the interval [expectedSN-NexpectedSN+N-1] (an interval of size 2N) can be received by the receiver Since the receiver accepts on the packet with SN=expectedSN there should be no other packet within this interval with SN=expectedSN Therefore
2k ge N+1expectedSN+N-1
Transport Layer 3-49
Sequence Number vs Window SizeSuppose we use k bits to represent SNQuestion Whatrsquos the minimum number of bits k necessary for a window size of N
sender
receiver
Selective Repeat
rcv_base
snd_base=rcv_base
Q For a given rcv_base whatrsquos the largest possible value for snd_baseA If all the last N ACKs sent by the receiver are received
snd_base = rcv_base (same as go_back-N)rcv_base+N-1
senderrsquos window
receiverrsquos window
rcv_base+N-1
Transport Layer 3-50
Sequence Number vs Window SizeSuppose we use k bits to represent SNQuestion Whatrsquos the minimum number of bits k necessary for a window size of N
sender
receiver
Selective Repeat
rcv_base
snd_base=rcv_base-N
Q For a given rcv_base whatrsquos the smallest possible value for snd_baseA If all the last N ACKs sent by the receiver are not received
snd_base = rcv_base-N (same as Go-Back-N)rcv_base-1
senderrsquos window
rcv_base
receiverrsquos window
rcv_base+N-1
Transport Layer 3-51
Sequence Number vs Window Size
sender
receiver
Selective Repeat
snd_base=rcv_base-N
All SNs in the interval [rcv_base-Nrcv_base+N-1] (an interval of size 2N) can be received by the receiver Since the receiver should be able to distinguish between all packets in this interval and take corresponding action there should be no two packets within thisinterval having the same SN Therefore
2k ge 2Nrcv_base+N-1
rcv_basercv_base
receiverrsquos window
rcv_base+N-1
Transport Layer 3-52
TCP Overview RFCs 793 1122 1323 2018 2581
full duplex databi-directional data flow in same connectionMSS maximum segment size
connection-orientedhandshaking (exchange of control msgs) initrsquossender receiver state before data exchange
flow controlledsender will not overwhelm receiver
point-to-pointone sender one receiver
reliable in-order byte stream
no ldquomessage boundariesrdquopipelined
TCP congestion and flow control set window size
send amp receive buffers
socketdoor
TCPsend buffer
TCPreceive buffer
socketdoor
segment
applicationwrites data
applicationreads data
Transport Layer 3-53
TCP segment structure
source port dest port
32 bits
applicationdata
(variable length)
sequence numberacknowledgement number
Receive windowUrg data pnterchecksum
FSRPAUheadlen
notused
Options (variable length)
URG urgent data (generally not used)
ACK ACK valid
PSH push data now(generally not used)
RST SYN FINconnection estab(setup teardown
commands)
bytes rcvr willingto accept
Internetchecksum
(as in UDP)
countingby bytes of data(not segments)
Transport Layer 3-54
TCP seq rsquos and ACKsSeq rsquos
byte stream ldquonumberrdquo of first byte in segmentrsquos dataACKs
seq of next byte expected from other sidecumulative ACK
Q how receiver handles out-of-order segmentsA TCP spec doesnrsquot say - up to implementationWidely used implementations of TCP buffer out-of-order segments
Transport Layer 3-55
TCP Round Trip Time and Timeout
Q how to set TCP timeout valuelonger than RTT
but RTT variestoo short premature timeout
unnecessary retransmissions
too long slow reaction to segment loss
Q how to estimate RTTSampleRTT measured time from segment transmission until ACK receipt
ignore retransmissionsSampleRTT will vary want estimated RTT ldquosmootherrdquo
average several recent measurements not just current SampleRTT
Transport Layer 3-56
TCP Round Trip Time and Timeout
EstimatedRTT = (1- α)EstimatedRTT + αSampleRTT
Exponential weighted moving averageinfluence of past sample decreases exponentially fasttypical value α = 0125
Transport Layer 3-57
Example RTT estimationRTT gaiacsumassedu to fantasiaeurecomfr
100
150
200
250
300
350
1 8 15 22 29 36 43 50 57 64 71 78 85 92 99 106
time (seconnds)
RTT
(mill
iseco
nds)
SampleRTT Estimated RTT
Transport Layer 3-58
TCP Round Trip Time and TimeoutSetting the timeout
EstimatedRTT plus ldquosafety marginrdquolarge variation in EstimatedRTT -gt larger safety margin
first estimate of how much SampleRTT deviates from EstimatedRTT
TimeoutInterval = EstimatedRTT + 4DevRTT
DevRTT = (1-β)DevRTT +β|SampleRTT-EstimatedRTT|
(typically β = 025)
Then set timeout interval
Transport Layer 3-59
TCP reliable data transfer
TCP creates rdtservice on top of IPrsquos unreliable servicePipelined segmentsCumulative acksTCP uses single retransmission timer however it just retransmits the first segment in the window
Retransmissions are triggered by
timeout eventsduplicate acks
Initially consider simplified TCP sender
ignore duplicate acksignore flow control congestion control
Transport Layer 3-60
TCP sender eventsdata rcvd from app
Create segment with seq seq is byte-stream number of first data byte in segmentstart timer if not already running (think of timer as for oldest unacked segment)expiration interval TimeOutInterval
timeoutretransmit segment that caused timeout (first segment in the window)restart timer
Ack rcvdIf acknowledges previously unacked segments
update what is known to be ackedstart timer if there are outstanding segments
Transport Layer 3-61
TCP sender(simplified)
NextSeqNum = InitialSeqNumSendBase = InitialSeqNum
loop (forever) switch(event)
event data received from application above create TCP segment with sequence number NextSeqNumif (timer currently not running)
start timerpass segment to IP NextSeqNum = NextSeqNum + length(data)
event timer timeoutretransmit not-yet-acknowledged segment with
smallest sequence numberstart timer
event ACK received with ACK field value of y if (y gt SendBase)
SendBase = yif (there are currently not-yet-acknowledged segments)
start timer
end of loop forever
Commentbull SendBase-1 last cumulatively ackrsquoed byteExamplebull SendBase-1 = 71y= 73 so the rcvrwants 73+ y gt SendBase sothat new data is acked
Transport Layer 3-62
TCP retransmission scenariosHost A
Seq=100 20 bytes data
ACK=100
timepremature timeout
Host B
Seq=92 8 bytes data
ACK=120
Seq=92 8 bytes data
Seq=
92 t
imeo
ut
ACK=120
Host A
Seq=92 8 bytes data
ACK=100
loss
tim
eout
lost ACK scenario
Host B
X
Seq=92 8 bytes data
ACK=100
time
Seq=
92 t
imeo
utSendBase
= 100
SendBase= 120
SendBase= 120
Sendbase= 100
Transport Layer 3-63
TCP retransmission scenarios (more)Host A
Seq=92 8 bytes data
ACK=100
loss
tim
eout
Cumulative ACK scenario
Host B
X
Seq=100 20 bytes data
ACK=120
time
SendBase= 120
Transport Layer 3-64
TCP ACK generation [RFC 1122 RFC 2581]
Event at Receiver
Arrival of in-order segment withexpected seq All data up toexpected seq already ACKed
Arrival of in-order segment withexpected seq One other segment has ACK pending
Arrival of out-of-order segmenthigher-than-expect seq Gap detected
Arrival of segment that partially or completely fills gap
TCP Receiver action
Delayed ACK Wait up to 500msfor next segment If no next segmentsend ACK
Immediately send single cumulative ACK ACKing both in-order segments
Immediately send duplicate ACK indicating seq of next expected byte
Immediate send ACK provided thatsegment startsat lower end of gap
Transport Layer 3-65
Fast Retransmit
Time-out period often relatively long
long delay before resending lost packet
Detect lost segments via duplicate ACKs
Sender often sends many segments back-to-backIf segment is lost there will likely be many duplicate ACKs
If sender receives 3 ACKs for the same data it supposes that segment after ACKeddata was lost
fast retransmit resend segment before timer expires
Transport Layer 3-66
Fast RetransmitResend a segment after 3 duplicate ACKs since a duplicate ACK means that an out-of sequence segment was receivedduplicate ACKs due to packet reorderingif window is small donrsquot get duplicate ACKs
Host A
tim
eout
Host B
time
X
resend seq X2
seq x1seq x2seq x3seq x4seq x5
ACK x1
ACK x1ACK x1ACK x1
tripleduplicate
ACKs
Transport Layer 3-67
event ACK received with ACK field value of y if (y gt SendBase)
SendBase = yif (there are currently not-yet-acknowledged segments)
start timer
else increment count of dup ACKs received for yif (count of dup ACKs received for y = 3)
resend segment with sequence number y
Fast retransmit algorithm
a duplicate ACK for already ACKed segment
fast retransmit
Transport Layer 3-68
TCP Flow Control
receive side of TCP connection has a receive buffer
speed-matching service matching the send rate to the receiving apprsquos drain rate
app process may be slow at reading from buffer
sender wonrsquot overflowreceiverrsquos buffer by
transmitting too muchtoo fast
flow control
Transport Layer 3-69
TCP Flow control how it works
(Suppose TCP receiver discards out-of-order segments)spare room in buffer
= RcvWin
= RcvBuffer-[LastByteRcvd -LastByteRead]
Rcvr advertises spare room by including value of RcvWin in segmentsSender limits unACKeddata to RcvWin
guarantees receive buffer doesnrsquot overflow
Transport Layer 3-70
Sliding Window Flow Control Example
3K
2K SeqNo=0
ReceiverBuffer
0 4KSendersends 2Kof data
2K
AckNo=2048 RcvWin=2048Sendersends 2Kof data 2K SeqNo=2048
4K
AckNo=4096 RcvWin=0
AckNo=4096 RcvWin=1024
Sender blocked
Transport Layer 3-71
Principles of Congestion Control
Congestioninformally ldquotoo many sources sending too much data too fast for network to handlerdquodifferent from flow controlmanifestations
lost packets (buffer overflow at routers)long delays (queueing in router buffers)
a top-10 problem
Transport Layer 3-72
Causescosts of congestion scenario 1
two senders two receiversone router infinite buffers no retransmission
large delays when congestedmaximum achievable throughput
unlimited shared output link buffers
Host Aλin original data
Host B
λout
Transport Layer 3-73
Causescosts of congestion scenario 2
one router finite buffers sender retransmission of lost packet
finite shared output link buffers
Host A λin original data
Host B
λout
λin original data plus retransmitted data
Transport Layer 3-74
Causescosts of congestion scenario 2always (goodput)ldquoperfectrdquo retransmission only when loss
retransmission of delayed (not lost) packet makes larger(than perfect case) for same
λin
λout=
λin
λoutgtλ
inλout
ldquocostsrdquo of congestionmore work (retrans) for given ldquogoodputrdquounneeded retransmissions link carries multiple copies of pkt
R2
R2λin
λ out
b
R2
R2λin
λ out
a
R2
R2λin
λ out
c
R4
R3
Transport Layer 3-75
Causescosts of congestion scenario 3four sendersmultihop pathstimeoutretransmit
λin
Q what happens as and increase λ
in
finite shared output link buffers
Host Aλin original data
Host B
λout
λin original data plus retransmitted data
Transport Layer 3-76
Causescosts of congestion scenario 3
another ldquocostrdquo of congestionwhen packet dropped any ldquoupstream transmission capacity used for that packet was wasted
Host A
Host B
λou
t
Transport Layer 3-77
Approaches towards congestion control
End-end congestion controlno explicit feedback from networkcongestion inferred from end-system observed loss delayapproach taken by TCP
Network-assisted congestion controlrouters provide feedback to end systems
single bit indicating congestion (SNA DECbit TCPIP ECN ATM)explicit rate sender should send at
Two broad approaches towards congestion control
Transport Layer 3-78
TCP Congestion Control
end-end control (no network assistance)sender limits transmissionLastByteSent-LastByteAcked
le CongWin
CongWin is dynamic function of perceived network congestion
How does sender perceive congestionloss event = timeout or3 duplicate acksTCP sender reduces rate (CongWin) after loss event
two modes of operationSlow Start (SS)Congestion avoidance (CA) or Additive Increase Multiplicative Decrease (AIMD)
Transport Layer 3-79
TCP congestion control bandwidth probing
ldquoprobing for bandwidthrdquo increase transmission rate on receipt of ACK until eventually loss occurs then decrease transmission rate
continue to increase on ACK decrease on loss (since available bandwidth is changing depending on other connections in network)
ACKs being received so increase rate
X
X
XX
X loss so decrease rate
send
ing
rate
time
Q how fast to increasedecreasedetails to follow
TCPrsquosldquosawtoothrdquobehavior
Transport Layer 3-80
TCP Congestion Control details
sender limits rate by limiting number of unACKed bytes ldquoin pipelinerdquo
cwnd differs from rwnd (how why)sender limited by min(cwndrwnd)
roughly
cwnd is dynamic function of perceived network congestion
rate = cwndRTT bytessec
LastByteSent-LastByteAcked le cwnd
cwndbytes
RTT
ACK(s)
Transport Layer 3-81
TCP Congestion Control more details
segment loss event reducing cwndtimeout no response from receiver
cut cwnd to 13 duplicate ACKs at least some segments getting through (recall fast retransmit)
cut cwnd in half less aggressively than on timeout
ACK received increase cwndTwo modes of operation
slowstart phase bull increase exponentially
fast (despite name) at connection start or following timeout
congestion avoidance bull increase linearly
Transport Layer 3-82
TCP Slow Start Phasewhen connection begins cwnd = 1 MSS
example MSS = 500 bytes amp RTT = 200 msecinitial rate = 20 kbps
available bandwidth may be gtgt MSSRTT
desirable to quickly ramp up to respectable rate
increase rate exponentially until first loss event or when threshold reached
double cwnd every RTTdone by incrementing cwnd by 1 for every ACK received
Host A
one segment
RTT
Host B
time
two segments
four segments
Transport Layer 3-83
Slow Start ExampleThe congestion window size grows very rapidly
For every ACK we increase CongWin by 1 irrespective of the number of segments ACKrsquoeddouble CongWinevery RTTinitial rate is slow but ramps up exponentially fast
TCP slows down the increase of CongWinwhen CongWin gt ssthresh
segment 1
ACK for segment 1
cwnd = 1
cwnd = 2 segment 2segment 3
ACK for segments 2
cwnd = 4 segment 4segment 5segment 6
ACK for segments 4
cwnd = 7
ACK for segments 3
ACK for segments 5
ACK for segments 6
cwnd = 3
cwnd = 5
cwnd = 6ACK for segments 7
cwnd = 8
segment 7
Transport Layer 3-84
TCP Congestion Avoidance Phase
when cwnd gt ssthreshgrow cwnd linearly
increase cwnd by 1 MSS per RTT approach possible congestion slower than in slowstartimplementation cwnd= cwnd + MSScwndfor each ACK received
ACKs increase cwndby 1 MSS per RTT additive increaseloss cut cwnd in half (non-timeout-detected loss ) multiplicative decrease
AIMD
AIMD Additive IncreaseMultiplicative Decrease
Transport Layer 3-85
Congestion AvoidanceCongestion avoidance phase is started if CongWin has reached the slow-start threshold value
If CongWin gt= ssthresh then each time an ACK is received increment CongWin as follows
bull CongWin = CongWin + 1CongWin (CongWin in segments)
bull In actual TCP implementation CongWin is in BytesCongWin = CongWin + MSS (MSSCongWin)
So CongWin is increased by one only if all CongWinsegments have been acknowledged
Transport Layer 3-86
Example Slow StartCongestion AvoidanceAssume that
ssthresh = 8
cwnd = 1
cwnd = 2
cwnd = 4
cwnd = 8
cwnd = 9
cwnd = 10
02468
101214
t=0
t=2
t=4
t=6
Roundtrip times
Cw
nd(in
seg
men
ts)
ssthresh
cwnd = 3
cwnd = 5cwnd = 6cwnd = 7
Transport Layer 3-87
Slow Start Congestion AvoidanceA typical plot of CongWin for a TCP connection
(MSS = 1500 bytes) with TCP Tahoe
SS
CA
ssthresh
Transport Layer 3-88
Responses to CongestionTCP assumes there is congestion if it detects a packet lossA TCP sender can detect lost packets via loss events
bull Timeout of a retransmission timerbull Receipt of 3 duplicate ACKs (fast retransmit)
TCP interprets a Timeout as a binary congestion signal When a timeout occurs the sender performs
ssthresh is set to half the current size of the congestion window
ssthresh = CongWin 2CongWin is reset to one
CongWin = 1and slow-start is entered
Transport Layer 3-89
Fast Recovery (differentiation btwn two loss events) After 3 dup ACKs (fast Retransmit)
ssthresh = CongWin2CongWin = CongWin2window then grows linearly
But after timeout eventCongWin = 1 MSS window then grows exponentiallyto the threshold then grows linearly
bull 3 dup ACKs indicates network capable of delivering some segmentsbull timeout before 3 dup ACKs is ldquomore alarmingrdquo
Philosophy
3-90
TCP Congestion ControlInitially
CongWin = 1ssthresh = advertised window size
New Ack receivedif (CongWin lt ssthresh) Slow Start
CongWin = CongWin + 1else Congestion Avoidance
CongWin = CongWin + 1CongWinTimeout
ssthresh = CongWin2CongWin = 1
Fast Retransmissionssthresh = CongWin2CongWin = CongWin2
Slow Start (exponential increase phase) is continued until CongWin reaches half of the level where the loss event occurred last time CongWin is increased slowly after (linear increase in Congestion Avoidance phase)
Transport Layer 3-91
Popular ldquoflavorsrdquo of TCP
ssthresh
ssthresh
TCP Tahoe
TCP Reno
Transmission round
cwnd
win
dow
siz
e (in
seg
men
ts)
Transport Layer 3-92
Summary TCP Congestion ControlWhen CongWin is below Threshold sender in slow-start phase window grows exponentiallyWhen CongWin is above Threshold sender is in congestion-avoidance phase window grows linearlyWhen a triple duplicate ACK occurs Threshold set to CongWin2 and CongWin set to ThresholdWhen timeout occurs Threshold set to CongWin2 and CongWin is set to 1 MSS The actual sender window size is determined based on the congestion and flow control algorithms
SenderWin=min(RcvWinCongWin)
Transport Layer 3-93
TCP Congestion Control SummaryEvent State TCP Sender Action Commentary
ACK receipt for previously unackeddata
Slow Start (SS)
CongWin = CongWin + MSS If (CongWin gt Threshold)
set state to ldquoCongestion Avoidancerdquo
Resulting in a doubling of CongWin every RTT
ACK receipt for previously unackeddata
CongestionAvoidance (CA)
CongWin = CongWin+MSS (MSSCongWin)
Additive increase resulting in increase of CongWin by 1 MSS every RTT
Loss event detected by triple duplicate ACK
SS or CA Threshold = CongWin2 CongWin = ThresholdSet state to ldquoCongestion Avoidancerdquo
Fast recovery implementing multiplicative decrease CongWin will not drop below 1 MSS
Timeout SS or CA Threshold = CongWin2 CongWin = 1 MSSSet state to ldquoSlow Startrdquo
Enter slow start
Duplicate ACK
SS or CA Increment duplicate ACK count for segment being acked
CongWin and Threshold not changed
Transport Layer 3-94
TCP throughput
Q whatrsquos average throughout of TCP as function of window size RTT
ignoring slow startlet W be window size when loss occurs
when window is W throughput is WRTTjust after loss window drops to W2 throughput to W2RTT average throughout 75 WRTT
Transport Layer 3-95
TCP Futures TCP over ldquolong fat pipesrdquo
example 1500 byte segments 100ms RTT want 10 Gbps throughputrequires window size W = 83333 in-flight segmentsthroughput in terms of loss rate
L = 210-10 Wownew versions of TCP for high-speed
LRTTMSSsdot221
Transport Layer 3-96
Fairness goal if K TCP sessions share same bottleneck link of bandwidth R each should have average rate of RK
TCP connection 1
bottleneckrouter
capacity R
TCP connection 2
TCP Fairness
Transport Layer 3-97
Why is TCP fairTwo competing sessions
Additive increase gives slope of 1 as throughout increasesmultiplicative decrease decreases throughput proportionally
R
R
equal bandwidth share
Connection 1 throughput
Conn
ecti
on 2
thr
ough
p ut
congestion avoidance additive increaseloss decrease window by factor of 2
congestion avoidance additive increaseloss decrease window by factor of 2
Transport Layer 3-98
Fairness (more)Fairness and UDP
Multimedia apps often do not use TCP
do not want rate throttled by congestion control
Instead use UDPpump audiovideo at constant rate tolerate packet loss
Research area TCP friendly
Fairness and parallel TCP connectionsnothing prevents app from opening parallel cnctionsbetween 2 hostsWeb browsers do this Example link of rate R supporting 9 cnctions
new app asks for 1 TCP gets rate R10new app asks for 11 TCPs gets R2
Transport Layer 3-99
TCP Connection ManagementRecall TCP sender receiver
establish ldquoconnectionrdquobefore exchanging data segmentsinitialize TCP variables
seq sbuffers flow control info (eg RcvWindow)
client connection initiatorSocket clientSocket = new Socket(hostnameport
number)
server contacted by clientSocket connectionSocket = welcomeSocketaccept()
Three way handshakeStep 1 client host sends TCP
SYN segment to serverspecifies initial seq no data
Step 2 server host receives SYN replies with SYNACK segment
server allocates buffersspecifies server initial seq
Step 3 client receives SYNACK replies with ACK segment which may contain data
Transport Layer 3-100
TCP Connection Management (cont)
Closing a connection
client closes socketclientSocketclose()
Step 1 client end system sends TCP FIN control segment to server
Step 2 server receives FIN replies with ACK Closes connection sends FIN
client
FIN
server
ACK
ACK
FIN
close
close
closed
tim
ed w
ait
Transport Layer 3-101
TCP Connection Management (cont)
Step 3 client receives FIN replies with ACK
Enters ldquotimed waitrdquo -will respond with ACK to received FINs
Step 4 server receives ACK Connection closed
client
FIN
server
ACK
ACK
FIN
closing
closing
closed
tim
ed w
ait
closed
Transport Layer 3-102
TCP Connection Management (cont)
TCP clientlifecycle
TCP serverlifecycle
Transport Layer 3-103
Tuning TCPIP Parameters TCPIP parameters
A set of default values may not be optimal for all applicationsThe network administrator may wish to turn on or off some TCPIP functions for performance or security considerations
Many Unix and Linux systems provide some flexibility in tuning the TCPIP kernelsbinsysctl is used to configure the Linux kernel parameters at runtime
Default kernel configuration file is sbinsysctlconfFrequently used sysctl options
bull sysctl ndasha or sysctl ndashA list all current valuesbull sysctl ndashp file_name load the sysctl setting from a configuration
filebull sysctl ndashw variable=value change the value of the parameter
Transport Layer 3-104
SomeTCP Parameters in Linux Kerneltcp_syn_retries
Number of SYN packets the kernel will send before giving up on the new connection
tcp_synack_retriesnumber of SYN+ACK packets sent before the kernel gives up on the connection
tcp_window_scalingMaximum window size of 65535 bytes not enough for for really fast networks The window scaling options allows for almost gigabyte windows which is good for connections with large delay-bandwidth product
tcp_max_syn_backlogMaximal number of remembered connection requests which still did not receive an acknowledgment from connecting client
tcp_fin_timeoutHow many seconds to wait for a final FIN packet before the socket is closed required to prevent denial-of-service (DoS) attacks Default value is 60 seconds
Transport Layer 3-105
SomeTCP Parameters in Linux Kerneltcp_rmem
This is a vector of 3 integers [min default max] These parameters are used by TCP to dynamically adjust receive buffer sizesmin - minimum size of the receive buffer used by each TCP socket The default value is 4K default - the default size of the receive buffer for a TCP socket The default value is 87380 bytes and is lowered to 43689 in low memory systems If larger receive buffer sizes are desired this value should be increased max - the maximum size of the receive buffer used by each TCP socket The default value of 873802 bytes is lowered to 87380 in low memory systems
tcp_smemSend buffer parameters [min default max] similar to tcp_rmem
- Chapter 3 Transport Layer
- Transport services and protocols
- Transport vs network layer
- Internet transport-layer protocols
- Multiplexingdemultiplexing
- How demultiplexing works
- Connectionless demultiplexing
- Connection-oriented demux
- Connection-oriented demux (cont)
- Connection-oriented demux Threaded Web Server
- UDP User Datagram Protocol [RFC 768]
- UDP more
- UDP checksum
- Principles of Reliable data transfer
- Reliable data transfer getting started
- Reliable data transfer getting started
- Rdt10 reliable transfer over a reliable channel
- Rdt20 channel with bit errors
- rdt20 FSM specification
- rdt20 operation with no errors
- rdt20 error scenario
- rdt20 has a fatal flaw
- rdt21 sender handles garbled ACKNAKs
- rdt21 receiver handles garbled ACKNAKs
- rdt21 discussion
- rdt22 a NAK-free protocol
- rdt22 sender receiver fragments
- rdt30 channels with errors and loss
- rdt30 sender
- rdt30 in action
- rdt30 in action
- Performance of rdt30
- rdt30 stop-and-wait operation
- Pipelined protocols
- Pipelining increased utilization
- Go-Back-N
- GBN sender extended FSM
- GBN receiver extended FSM
- GBN inaction
- Selective Repeat
- Selective repeat sender receiver windows
- Selective repeat
- Selective repeat in action
- Selective repeat dilemma
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- TCP Overview RFCs 793 1122 1323 2018 2581
- TCP segment structure
- TCP seq rsquos and ACKs
- TCP Round Trip Time and Timeout
- TCP Round Trip Time and Timeout
- Example RTT estimation
- TCP Round Trip Time and Timeout
- TCP reliable data transfer
- TCP sender events
- TCP sender(simplified)
- TCP retransmission scenarios
- TCP retransmission scenarios (more)
- TCP ACK generation [RFC 1122 RFC 2581]
- Fast Retransmit
- Fast Retransmit
- Fast retransmit algorithm
- TCP Flow Control
- TCP Flow control how it works
- Sliding Window Flow Control Example
- Principles of Congestion Control
- Causescosts of congestion scenario 1
- Causescosts of congestion scenario 2
- Causescosts of congestion scenario 2
- Causescosts of congestion scenario 3
- Causescosts of congestion scenario 3
- Approaches towards congestion control
- TCP Congestion Control
- TCP congestion control bandwidth probing
- TCP Congestion Control details
- TCP Congestion Control more details
- TCP Slow Start Phase
- Slow Start Example
- TCP Congestion Avoidance Phase
- Congestion Avoidance
- Example Slow StartCongestion Avoidance
- Slow Start Congestion Avoidance
- Responses to Congestion
- Fast Recovery (differentiation btwn two loss events)
- TCP Congestion Control
- Popular ldquoflavorsrdquo of TCP
- Summary TCP Congestion Control
- TCP Congestion Control Summary
- TCP throughput
- TCP Futures TCP over ldquolong fat pipesrdquo
- TCP Fairness
- Why is TCP fair
- Fairness (more)
- TCP Connection Management
- TCP Connection Management (cont)
- TCP Connection Management (cont)
- TCP Connection Management (cont)
- Tuning TCPIP Parameters
- SomeTCP Parameters in Linux Kernel
- SomeTCP Parameters in Linux Kernel
-
Transport Layer 3-30
rdt30 in action
Transport Layer 3-31
rdt30 in action
Transport Layer 3-32
Performance of rdt30
rdt30 works but performance stinksexample 1 Gbps link 15 ms e-e prop delay 1KB packet
Ttransmit = 8kbpkt109 bsec = 8 microsec
U sender utilization ndash fraction of time sender busy sending1KB pkt every 30 msec -gt 33kBsec thruput over 1 Gbps linknetwork protocol limits use of physical resources
U sender=
008 30008
= 000027 L RRTT + L R
=
L (packet length in bits)R (transmission rate bps) =
Transport Layer 3-33
rdt30 stop-and-wait operation
first packet bit transmitted t = 0
sender receiver
RTT
last packet bit transmitted t = L R
first packet bit arriveslast packet bit arrives send ACK
ACK arrives send next packet t = RTT + L R
U sender=
00830008
= 000027 L RRTT + L R
=
Transport Layer 3-34
Pipelined protocolsPipelining sender allows multiple ldquoin-flightrdquo yet-to-
be-acknowledged pktsrange of sequence numbers must be increasedbuffering at sender andor receiver
Two generic forms of pipelined protocols go-Back-N selective repeat
Transport Layer 3-35
Pipelining increased utilization
first packet bit transmitted t = 0
sender receiver
RTT
last bit transmitted t = L R
first packet bit arriveslast packet bit arrives send ACK
ACK arrives send next packet t = RTT + L R
last bit of 2nd packet arrives send ACKlast bit of 3rd packet arrives send ACK
U sender=
024 30008
= 000083 L RRTT + L R
=
Increase utilizationby a factor of 3
Transport Layer 3-36
Utilization=N(LR)(RTT+LR) if NLRltRTT+LR Utilization=1 if and the sender pauses after it transmits a window NLRgtRTT+LR and the of packets until it receives first ACK sender does not pause
Transport Layer 3-37
Go-Back-NSender
k-bit seq in pkt headerldquowindowrdquo of up to N consecutive unackrsquoed pkts allowed
ACK(n) ACKs all pkts up to including seq n - ldquocumulative ACKrdquomay receive duplicate ACKs (see receiver)
timer for the entire windowtimeout(n) retransmit pkt n and all higher seq pkts in window
Transport Layer 3-38
GBN sender extended FSM
Wait start_timerudt_send(sndpkt[base])udt_send(sndpkt[base+1])hellipudt_send(sndpkt[nextseqnum-1])
timeout
rdt_send(data)
if (nextseqnum lt base+N) sndpkt[nextseqnum] = make_pkt(nextseqnumdatachksum)udt_send(sndpkt[nextseqnum])if (base == nextseqnum)
start_timernextseqnum++
elserefuse_data(data)
base = getacknum(rcvpkt)+1If (base == nextseqnum)
stop_timerelse
start_timer
rdt_rcv(rcvpkt) ampamp notcorrupt(rcvpkt)
base=1nextseqnum=1
rdt_rcv(rcvpkt) ampamp corrupt(rcvpkt)
Λ
Λ
Transport Layer 3-39
GBN receiver extended FSM
ACK-only always send ACK for correctly-received pktwith highest in-order seq
may generate duplicate ACKsneed only remember expectedseqnum
out-of-order pkt discard (donrsquot buffer) -gt no receiver bufferingRe-ACK pkt with highest in-order seq
Wait
udt_send(sndpkt)default
rdt_rcv(rcvpkt)ampamp notcurrupt(rcvpkt)ampamp hasseqnum(rcvpktexpectedseqnum)
extract(rcvpktdata)deliver_data(data)sndpkt = make_pkt(expectedseqnumACKchksum)udt_send(sndpkt)expectedseqnum++
expectedseqnum=1sndpkt =
make_pkt(0ACKchksum)
Λ
Transport Layer 3-40
GBN inaction
Transport Layer 3-41
Selective Repeat
receiver individually acknowledges all correctly received pkts
buffers pkts as needed for eventual in-order delivery to upper layer
sender only resends pkts for which ACK not received
sender timer for each unACKed pktsender window
N consecutive seq rsquosagain limits seq s of sent unACKed pkts
Transport Layer 3-42
Selective repeat sender receiver windows
Transport Layer 3-43
Selective repeat
data from above if next available seq in window send pkt
timeout(n)resend pkt n restart timer
ACK(n) in [sendbasesendbase+N-1]
mark pkt n as receivedif n smallest unACKed pkt advance window base to next unACKed seq
senderpkt n in [rcvbase rcvbase+N-1]
send ACK(n)out-of-order bufferin-order deliver (also deliver buffered in-order pkts) advance window to next not-yet-received pkt
pkt n in [rcvbase-Nrcvbase-1]
ACK(n)otherwise
ignore
receiver
Transport Layer 3-44
Selective repeat in action
Transport Layer 3-45
Selective repeatdilemma
Example seq rsquos 0 1 2 3window size=3
receiver sees no difference in two scenariosincorrectly passes duplicate data as new in (a)
Q what relationship between seq size and window size
Transport Layer 3-46
Sequence Number vs Window SizeSuppose we use k bits to represent SNQuestion Whatrsquos the minimum number of bits k necessary for a window size of N
sender
receiver
Go-Back-N
expectedSN
snd_base=expectedSN
Q For a given expectedSN whatrsquos the largest possible value for snd_baseA If all the last N ACKs sent by the receiver are received
snd_base = expectedSNexpectedSN+N-1
senderrsquos window
Transport Layer 3-47
Sequence Number vs Window SizeSuppose we use k bits to represent SNQuestion Whatrsquos the minimum number of bits k necessary for a window size of N
sender
receiver
Go-Back-N
expectedSN
snd_base=expectedSN-N
Q For a given expectedSN whatrsquos the smallest possible value for snd_baseA If all the last N ACKs sent by the receiver are not received
snd_base = expectedSN-NexpectedSN-1
senderrsquos window
Transport Layer 3-48
Sequence Number vs Window Size
sender
receiver
Go-Back-N
expectedSN
snd_base=expectedSN-N
All SNs in the interval [expectedSN-NexpectedSN+N-1] (an interval of size 2N) can be received by the receiver Since the receiver accepts on the packet with SN=expectedSN there should be no other packet within this interval with SN=expectedSN Therefore
2k ge N+1expectedSN+N-1
Transport Layer 3-49
Sequence Number vs Window SizeSuppose we use k bits to represent SNQuestion Whatrsquos the minimum number of bits k necessary for a window size of N
sender
receiver
Selective Repeat
rcv_base
snd_base=rcv_base
Q For a given rcv_base whatrsquos the largest possible value for snd_baseA If all the last N ACKs sent by the receiver are received
snd_base = rcv_base (same as go_back-N)rcv_base+N-1
senderrsquos window
receiverrsquos window
rcv_base+N-1
Transport Layer 3-50
Sequence Number vs Window SizeSuppose we use k bits to represent SNQuestion Whatrsquos the minimum number of bits k necessary for a window size of N
sender
receiver
Selective Repeat
rcv_base
snd_base=rcv_base-N
Q For a given rcv_base whatrsquos the smallest possible value for snd_baseA If all the last N ACKs sent by the receiver are not received
snd_base = rcv_base-N (same as Go-Back-N)rcv_base-1
senderrsquos window
rcv_base
receiverrsquos window
rcv_base+N-1
Transport Layer 3-51
Sequence Number vs Window Size
sender
receiver
Selective Repeat
snd_base=rcv_base-N
All SNs in the interval [rcv_base-Nrcv_base+N-1] (an interval of size 2N) can be received by the receiver Since the receiver should be able to distinguish between all packets in this interval and take corresponding action there should be no two packets within thisinterval having the same SN Therefore
2k ge 2Nrcv_base+N-1
rcv_basercv_base
receiverrsquos window
rcv_base+N-1
Transport Layer 3-52
TCP Overview RFCs 793 1122 1323 2018 2581
full duplex databi-directional data flow in same connectionMSS maximum segment size
connection-orientedhandshaking (exchange of control msgs) initrsquossender receiver state before data exchange
flow controlledsender will not overwhelm receiver
point-to-pointone sender one receiver
reliable in-order byte stream
no ldquomessage boundariesrdquopipelined
TCP congestion and flow control set window size
send amp receive buffers
socketdoor
TCPsend buffer
TCPreceive buffer
socketdoor
segment
applicationwrites data
applicationreads data
Transport Layer 3-53
TCP segment structure
source port dest port
32 bits
applicationdata
(variable length)
sequence numberacknowledgement number
Receive windowUrg data pnterchecksum
FSRPAUheadlen
notused
Options (variable length)
URG urgent data (generally not used)
ACK ACK valid
PSH push data now(generally not used)
RST SYN FINconnection estab(setup teardown
commands)
bytes rcvr willingto accept
Internetchecksum
(as in UDP)
countingby bytes of data(not segments)
Transport Layer 3-54
TCP seq rsquos and ACKsSeq rsquos
byte stream ldquonumberrdquo of first byte in segmentrsquos dataACKs
seq of next byte expected from other sidecumulative ACK
Q how receiver handles out-of-order segmentsA TCP spec doesnrsquot say - up to implementationWidely used implementations of TCP buffer out-of-order segments
Transport Layer 3-55
TCP Round Trip Time and Timeout
Q how to set TCP timeout valuelonger than RTT
but RTT variestoo short premature timeout
unnecessary retransmissions
too long slow reaction to segment loss
Q how to estimate RTTSampleRTT measured time from segment transmission until ACK receipt
ignore retransmissionsSampleRTT will vary want estimated RTT ldquosmootherrdquo
average several recent measurements not just current SampleRTT
Transport Layer 3-56
TCP Round Trip Time and Timeout
EstimatedRTT = (1- α)EstimatedRTT + αSampleRTT
Exponential weighted moving averageinfluence of past sample decreases exponentially fasttypical value α = 0125
Transport Layer 3-57
Example RTT estimationRTT gaiacsumassedu to fantasiaeurecomfr
100
150
200
250
300
350
1 8 15 22 29 36 43 50 57 64 71 78 85 92 99 106
time (seconnds)
RTT
(mill
iseco
nds)
SampleRTT Estimated RTT
Transport Layer 3-58
TCP Round Trip Time and TimeoutSetting the timeout
EstimatedRTT plus ldquosafety marginrdquolarge variation in EstimatedRTT -gt larger safety margin
first estimate of how much SampleRTT deviates from EstimatedRTT
TimeoutInterval = EstimatedRTT + 4DevRTT
DevRTT = (1-β)DevRTT +β|SampleRTT-EstimatedRTT|
(typically β = 025)
Then set timeout interval
Transport Layer 3-59
TCP reliable data transfer
TCP creates rdtservice on top of IPrsquos unreliable servicePipelined segmentsCumulative acksTCP uses single retransmission timer however it just retransmits the first segment in the window
Retransmissions are triggered by
timeout eventsduplicate acks
Initially consider simplified TCP sender
ignore duplicate acksignore flow control congestion control
Transport Layer 3-60
TCP sender eventsdata rcvd from app
Create segment with seq seq is byte-stream number of first data byte in segmentstart timer if not already running (think of timer as for oldest unacked segment)expiration interval TimeOutInterval
timeoutretransmit segment that caused timeout (first segment in the window)restart timer
Ack rcvdIf acknowledges previously unacked segments
update what is known to be ackedstart timer if there are outstanding segments
Transport Layer 3-61
TCP sender(simplified)
NextSeqNum = InitialSeqNumSendBase = InitialSeqNum
loop (forever) switch(event)
event data received from application above create TCP segment with sequence number NextSeqNumif (timer currently not running)
start timerpass segment to IP NextSeqNum = NextSeqNum + length(data)
event timer timeoutretransmit not-yet-acknowledged segment with
smallest sequence numberstart timer
event ACK received with ACK field value of y if (y gt SendBase)
SendBase = yif (there are currently not-yet-acknowledged segments)
start timer
end of loop forever
Commentbull SendBase-1 last cumulatively ackrsquoed byteExamplebull SendBase-1 = 71y= 73 so the rcvrwants 73+ y gt SendBase sothat new data is acked
Transport Layer 3-62
TCP retransmission scenariosHost A
Seq=100 20 bytes data
ACK=100
timepremature timeout
Host B
Seq=92 8 bytes data
ACK=120
Seq=92 8 bytes data
Seq=
92 t
imeo
ut
ACK=120
Host A
Seq=92 8 bytes data
ACK=100
loss
tim
eout
lost ACK scenario
Host B
X
Seq=92 8 bytes data
ACK=100
time
Seq=
92 t
imeo
utSendBase
= 100
SendBase= 120
SendBase= 120
Sendbase= 100
Transport Layer 3-63
TCP retransmission scenarios (more)Host A
Seq=92 8 bytes data
ACK=100
loss
tim
eout
Cumulative ACK scenario
Host B
X
Seq=100 20 bytes data
ACK=120
time
SendBase= 120
Transport Layer 3-64
TCP ACK generation [RFC 1122 RFC 2581]
Event at Receiver
Arrival of in-order segment withexpected seq All data up toexpected seq already ACKed
Arrival of in-order segment withexpected seq One other segment has ACK pending
Arrival of out-of-order segmenthigher-than-expect seq Gap detected
Arrival of segment that partially or completely fills gap
TCP Receiver action
Delayed ACK Wait up to 500msfor next segment If no next segmentsend ACK
Immediately send single cumulative ACK ACKing both in-order segments
Immediately send duplicate ACK indicating seq of next expected byte
Immediate send ACK provided thatsegment startsat lower end of gap
Transport Layer 3-65
Fast Retransmit
Time-out period often relatively long
long delay before resending lost packet
Detect lost segments via duplicate ACKs
Sender often sends many segments back-to-backIf segment is lost there will likely be many duplicate ACKs
If sender receives 3 ACKs for the same data it supposes that segment after ACKeddata was lost
fast retransmit resend segment before timer expires
Transport Layer 3-66
Fast RetransmitResend a segment after 3 duplicate ACKs since a duplicate ACK means that an out-of sequence segment was receivedduplicate ACKs due to packet reorderingif window is small donrsquot get duplicate ACKs
Host A
tim
eout
Host B
time
X
resend seq X2
seq x1seq x2seq x3seq x4seq x5
ACK x1
ACK x1ACK x1ACK x1
tripleduplicate
ACKs
Transport Layer 3-67
event ACK received with ACK field value of y if (y gt SendBase)
SendBase = yif (there are currently not-yet-acknowledged segments)
start timer
else increment count of dup ACKs received for yif (count of dup ACKs received for y = 3)
resend segment with sequence number y
Fast retransmit algorithm
a duplicate ACK for already ACKed segment
fast retransmit
Transport Layer 3-68
TCP Flow Control
receive side of TCP connection has a receive buffer
speed-matching service matching the send rate to the receiving apprsquos drain rate
app process may be slow at reading from buffer
sender wonrsquot overflowreceiverrsquos buffer by
transmitting too muchtoo fast
flow control
Transport Layer 3-69
TCP Flow control how it works
(Suppose TCP receiver discards out-of-order segments)spare room in buffer
= RcvWin
= RcvBuffer-[LastByteRcvd -LastByteRead]
Rcvr advertises spare room by including value of RcvWin in segmentsSender limits unACKeddata to RcvWin
guarantees receive buffer doesnrsquot overflow
Transport Layer 3-70
Sliding Window Flow Control Example
3K
2K SeqNo=0
ReceiverBuffer
0 4KSendersends 2Kof data
2K
AckNo=2048 RcvWin=2048Sendersends 2Kof data 2K SeqNo=2048
4K
AckNo=4096 RcvWin=0
AckNo=4096 RcvWin=1024
Sender blocked
Transport Layer 3-71
Principles of Congestion Control
Congestioninformally ldquotoo many sources sending too much data too fast for network to handlerdquodifferent from flow controlmanifestations
lost packets (buffer overflow at routers)long delays (queueing in router buffers)
a top-10 problem
Transport Layer 3-72
Causescosts of congestion scenario 1
two senders two receiversone router infinite buffers no retransmission
large delays when congestedmaximum achievable throughput
unlimited shared output link buffers
Host Aλin original data
Host B
λout
Transport Layer 3-73
Causescosts of congestion scenario 2
one router finite buffers sender retransmission of lost packet
finite shared output link buffers
Host A λin original data
Host B
λout
λin original data plus retransmitted data
Transport Layer 3-74
Causescosts of congestion scenario 2always (goodput)ldquoperfectrdquo retransmission only when loss
retransmission of delayed (not lost) packet makes larger(than perfect case) for same
λin
λout=
λin
λoutgtλ
inλout
ldquocostsrdquo of congestionmore work (retrans) for given ldquogoodputrdquounneeded retransmissions link carries multiple copies of pkt
R2
R2λin
λ out
b
R2
R2λin
λ out
a
R2
R2λin
λ out
c
R4
R3
Transport Layer 3-75
Causescosts of congestion scenario 3four sendersmultihop pathstimeoutretransmit
λin
Q what happens as and increase λ
in
finite shared output link buffers
Host Aλin original data
Host B
λout
λin original data plus retransmitted data
Transport Layer 3-76
Causescosts of congestion scenario 3
another ldquocostrdquo of congestionwhen packet dropped any ldquoupstream transmission capacity used for that packet was wasted
Host A
Host B
λou
t
Transport Layer 3-77
Approaches towards congestion control
End-end congestion controlno explicit feedback from networkcongestion inferred from end-system observed loss delayapproach taken by TCP
Network-assisted congestion controlrouters provide feedback to end systems
single bit indicating congestion (SNA DECbit TCPIP ECN ATM)explicit rate sender should send at
Two broad approaches towards congestion control
Transport Layer 3-78
TCP Congestion Control
end-end control (no network assistance)sender limits transmissionLastByteSent-LastByteAcked
le CongWin
CongWin is dynamic function of perceived network congestion
How does sender perceive congestionloss event = timeout or3 duplicate acksTCP sender reduces rate (CongWin) after loss event
two modes of operationSlow Start (SS)Congestion avoidance (CA) or Additive Increase Multiplicative Decrease (AIMD)
Transport Layer 3-79
TCP congestion control bandwidth probing
ldquoprobing for bandwidthrdquo increase transmission rate on receipt of ACK until eventually loss occurs then decrease transmission rate
continue to increase on ACK decrease on loss (since available bandwidth is changing depending on other connections in network)
ACKs being received so increase rate
X
X
XX
X loss so decrease rate
send
ing
rate
time
Q how fast to increasedecreasedetails to follow
TCPrsquosldquosawtoothrdquobehavior
Transport Layer 3-80
TCP Congestion Control details
sender limits rate by limiting number of unACKed bytes ldquoin pipelinerdquo
cwnd differs from rwnd (how why)sender limited by min(cwndrwnd)
roughly
cwnd is dynamic function of perceived network congestion
rate = cwndRTT bytessec
LastByteSent-LastByteAcked le cwnd
cwndbytes
RTT
ACK(s)
Transport Layer 3-81
TCP Congestion Control more details
segment loss event reducing cwndtimeout no response from receiver
cut cwnd to 13 duplicate ACKs at least some segments getting through (recall fast retransmit)
cut cwnd in half less aggressively than on timeout
ACK received increase cwndTwo modes of operation
slowstart phase bull increase exponentially
fast (despite name) at connection start or following timeout
congestion avoidance bull increase linearly
Transport Layer 3-82
TCP Slow Start Phasewhen connection begins cwnd = 1 MSS
example MSS = 500 bytes amp RTT = 200 msecinitial rate = 20 kbps
available bandwidth may be gtgt MSSRTT
desirable to quickly ramp up to respectable rate
increase rate exponentially until first loss event or when threshold reached
double cwnd every RTTdone by incrementing cwnd by 1 for every ACK received
Host A
one segment
RTT
Host B
time
two segments
four segments
Transport Layer 3-83
Slow Start ExampleThe congestion window size grows very rapidly
For every ACK we increase CongWin by 1 irrespective of the number of segments ACKrsquoeddouble CongWinevery RTTinitial rate is slow but ramps up exponentially fast
TCP slows down the increase of CongWinwhen CongWin gt ssthresh
segment 1
ACK for segment 1
cwnd = 1
cwnd = 2 segment 2segment 3
ACK for segments 2
cwnd = 4 segment 4segment 5segment 6
ACK for segments 4
cwnd = 7
ACK for segments 3
ACK for segments 5
ACK for segments 6
cwnd = 3
cwnd = 5
cwnd = 6ACK for segments 7
cwnd = 8
segment 7
Transport Layer 3-84
TCP Congestion Avoidance Phase
when cwnd gt ssthreshgrow cwnd linearly
increase cwnd by 1 MSS per RTT approach possible congestion slower than in slowstartimplementation cwnd= cwnd + MSScwndfor each ACK received
ACKs increase cwndby 1 MSS per RTT additive increaseloss cut cwnd in half (non-timeout-detected loss ) multiplicative decrease
AIMD
AIMD Additive IncreaseMultiplicative Decrease
Transport Layer 3-85
Congestion AvoidanceCongestion avoidance phase is started if CongWin has reached the slow-start threshold value
If CongWin gt= ssthresh then each time an ACK is received increment CongWin as follows
bull CongWin = CongWin + 1CongWin (CongWin in segments)
bull In actual TCP implementation CongWin is in BytesCongWin = CongWin + MSS (MSSCongWin)
So CongWin is increased by one only if all CongWinsegments have been acknowledged
Transport Layer 3-86
Example Slow StartCongestion AvoidanceAssume that
ssthresh = 8
cwnd = 1
cwnd = 2
cwnd = 4
cwnd = 8
cwnd = 9
cwnd = 10
02468
101214
t=0
t=2
t=4
t=6
Roundtrip times
Cw
nd(in
seg
men
ts)
ssthresh
cwnd = 3
cwnd = 5cwnd = 6cwnd = 7
Transport Layer 3-87
Slow Start Congestion AvoidanceA typical plot of CongWin for a TCP connection
(MSS = 1500 bytes) with TCP Tahoe
SS
CA
ssthresh
Transport Layer 3-88
Responses to CongestionTCP assumes there is congestion if it detects a packet lossA TCP sender can detect lost packets via loss events
bull Timeout of a retransmission timerbull Receipt of 3 duplicate ACKs (fast retransmit)
TCP interprets a Timeout as a binary congestion signal When a timeout occurs the sender performs
ssthresh is set to half the current size of the congestion window
ssthresh = CongWin 2CongWin is reset to one
CongWin = 1and slow-start is entered
Transport Layer 3-89
Fast Recovery (differentiation btwn two loss events) After 3 dup ACKs (fast Retransmit)
ssthresh = CongWin2CongWin = CongWin2window then grows linearly
But after timeout eventCongWin = 1 MSS window then grows exponentiallyto the threshold then grows linearly
bull 3 dup ACKs indicates network capable of delivering some segmentsbull timeout before 3 dup ACKs is ldquomore alarmingrdquo
Philosophy
3-90
TCP Congestion ControlInitially
CongWin = 1ssthresh = advertised window size
New Ack receivedif (CongWin lt ssthresh) Slow Start
CongWin = CongWin + 1else Congestion Avoidance
CongWin = CongWin + 1CongWinTimeout
ssthresh = CongWin2CongWin = 1
Fast Retransmissionssthresh = CongWin2CongWin = CongWin2
Slow Start (exponential increase phase) is continued until CongWin reaches half of the level where the loss event occurred last time CongWin is increased slowly after (linear increase in Congestion Avoidance phase)
Transport Layer 3-91
Popular ldquoflavorsrdquo of TCP
ssthresh
ssthresh
TCP Tahoe
TCP Reno
Transmission round
cwnd
win
dow
siz
e (in
seg
men
ts)
Transport Layer 3-92
Summary TCP Congestion ControlWhen CongWin is below Threshold sender in slow-start phase window grows exponentiallyWhen CongWin is above Threshold sender is in congestion-avoidance phase window grows linearlyWhen a triple duplicate ACK occurs Threshold set to CongWin2 and CongWin set to ThresholdWhen timeout occurs Threshold set to CongWin2 and CongWin is set to 1 MSS The actual sender window size is determined based on the congestion and flow control algorithms
SenderWin=min(RcvWinCongWin)
Transport Layer 3-93
TCP Congestion Control SummaryEvent State TCP Sender Action Commentary
ACK receipt for previously unackeddata
Slow Start (SS)
CongWin = CongWin + MSS If (CongWin gt Threshold)
set state to ldquoCongestion Avoidancerdquo
Resulting in a doubling of CongWin every RTT
ACK receipt for previously unackeddata
CongestionAvoidance (CA)
CongWin = CongWin+MSS (MSSCongWin)
Additive increase resulting in increase of CongWin by 1 MSS every RTT
Loss event detected by triple duplicate ACK
SS or CA Threshold = CongWin2 CongWin = ThresholdSet state to ldquoCongestion Avoidancerdquo
Fast recovery implementing multiplicative decrease CongWin will not drop below 1 MSS
Timeout SS or CA Threshold = CongWin2 CongWin = 1 MSSSet state to ldquoSlow Startrdquo
Enter slow start
Duplicate ACK
SS or CA Increment duplicate ACK count for segment being acked
CongWin and Threshold not changed
Transport Layer 3-94
TCP throughput
Q whatrsquos average throughout of TCP as function of window size RTT
ignoring slow startlet W be window size when loss occurs
when window is W throughput is WRTTjust after loss window drops to W2 throughput to W2RTT average throughout 75 WRTT
Transport Layer 3-95
TCP Futures TCP over ldquolong fat pipesrdquo
example 1500 byte segments 100ms RTT want 10 Gbps throughputrequires window size W = 83333 in-flight segmentsthroughput in terms of loss rate
L = 210-10 Wownew versions of TCP for high-speed
LRTTMSSsdot221
Transport Layer 3-96
Fairness goal if K TCP sessions share same bottleneck link of bandwidth R each should have average rate of RK
TCP connection 1
bottleneckrouter
capacity R
TCP connection 2
TCP Fairness
Transport Layer 3-97
Why is TCP fairTwo competing sessions
Additive increase gives slope of 1 as throughout increasesmultiplicative decrease decreases throughput proportionally
R
R
equal bandwidth share
Connection 1 throughput
Conn
ecti
on 2
thr
ough
p ut
congestion avoidance additive increaseloss decrease window by factor of 2
congestion avoidance additive increaseloss decrease window by factor of 2
Transport Layer 3-98
Fairness (more)Fairness and UDP
Multimedia apps often do not use TCP
do not want rate throttled by congestion control
Instead use UDPpump audiovideo at constant rate tolerate packet loss
Research area TCP friendly
Fairness and parallel TCP connectionsnothing prevents app from opening parallel cnctionsbetween 2 hostsWeb browsers do this Example link of rate R supporting 9 cnctions
new app asks for 1 TCP gets rate R10new app asks for 11 TCPs gets R2
Transport Layer 3-99
TCP Connection ManagementRecall TCP sender receiver
establish ldquoconnectionrdquobefore exchanging data segmentsinitialize TCP variables
seq sbuffers flow control info (eg RcvWindow)
client connection initiatorSocket clientSocket = new Socket(hostnameport
number)
server contacted by clientSocket connectionSocket = welcomeSocketaccept()
Three way handshakeStep 1 client host sends TCP
SYN segment to serverspecifies initial seq no data
Step 2 server host receives SYN replies with SYNACK segment
server allocates buffersspecifies server initial seq
Step 3 client receives SYNACK replies with ACK segment which may contain data
Transport Layer 3-100
TCP Connection Management (cont)
Closing a connection
client closes socketclientSocketclose()
Step 1 client end system sends TCP FIN control segment to server
Step 2 server receives FIN replies with ACK Closes connection sends FIN
client
FIN
server
ACK
ACK
FIN
close
close
closed
tim
ed w
ait
Transport Layer 3-101
TCP Connection Management (cont)
Step 3 client receives FIN replies with ACK
Enters ldquotimed waitrdquo -will respond with ACK to received FINs
Step 4 server receives ACK Connection closed
client
FIN
server
ACK
ACK
FIN
closing
closing
closed
tim
ed w
ait
closed
Transport Layer 3-102
TCP Connection Management (cont)
TCP clientlifecycle
TCP serverlifecycle
Transport Layer 3-103
Tuning TCPIP Parameters TCPIP parameters
A set of default values may not be optimal for all applicationsThe network administrator may wish to turn on or off some TCPIP functions for performance or security considerations
Many Unix and Linux systems provide some flexibility in tuning the TCPIP kernelsbinsysctl is used to configure the Linux kernel parameters at runtime
Default kernel configuration file is sbinsysctlconfFrequently used sysctl options
bull sysctl ndasha or sysctl ndashA list all current valuesbull sysctl ndashp file_name load the sysctl setting from a configuration
filebull sysctl ndashw variable=value change the value of the parameter
Transport Layer 3-104
SomeTCP Parameters in Linux Kerneltcp_syn_retries
Number of SYN packets the kernel will send before giving up on the new connection
tcp_synack_retriesnumber of SYN+ACK packets sent before the kernel gives up on the connection
tcp_window_scalingMaximum window size of 65535 bytes not enough for for really fast networks The window scaling options allows for almost gigabyte windows which is good for connections with large delay-bandwidth product
tcp_max_syn_backlogMaximal number of remembered connection requests which still did not receive an acknowledgment from connecting client
tcp_fin_timeoutHow many seconds to wait for a final FIN packet before the socket is closed required to prevent denial-of-service (DoS) attacks Default value is 60 seconds
Transport Layer 3-105
SomeTCP Parameters in Linux Kerneltcp_rmem
This is a vector of 3 integers [min default max] These parameters are used by TCP to dynamically adjust receive buffer sizesmin - minimum size of the receive buffer used by each TCP socket The default value is 4K default - the default size of the receive buffer for a TCP socket The default value is 87380 bytes and is lowered to 43689 in low memory systems If larger receive buffer sizes are desired this value should be increased max - the maximum size of the receive buffer used by each TCP socket The default value of 873802 bytes is lowered to 87380 in low memory systems
tcp_smemSend buffer parameters [min default max] similar to tcp_rmem
- Chapter 3 Transport Layer
- Transport services and protocols
- Transport vs network layer
- Internet transport-layer protocols
- Multiplexingdemultiplexing
- How demultiplexing works
- Connectionless demultiplexing
- Connection-oriented demux
- Connection-oriented demux (cont)
- Connection-oriented demux Threaded Web Server
- UDP User Datagram Protocol [RFC 768]
- UDP more
- UDP checksum
- Principles of Reliable data transfer
- Reliable data transfer getting started
- Reliable data transfer getting started
- Rdt10 reliable transfer over a reliable channel
- Rdt20 channel with bit errors
- rdt20 FSM specification
- rdt20 operation with no errors
- rdt20 error scenario
- rdt20 has a fatal flaw
- rdt21 sender handles garbled ACKNAKs
- rdt21 receiver handles garbled ACKNAKs
- rdt21 discussion
- rdt22 a NAK-free protocol
- rdt22 sender receiver fragments
- rdt30 channels with errors and loss
- rdt30 sender
- rdt30 in action
- rdt30 in action
- Performance of rdt30
- rdt30 stop-and-wait operation
- Pipelined protocols
- Pipelining increased utilization
- Go-Back-N
- GBN sender extended FSM
- GBN receiver extended FSM
- GBN inaction
- Selective Repeat
- Selective repeat sender receiver windows
- Selective repeat
- Selective repeat in action
- Selective repeat dilemma
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- TCP Overview RFCs 793 1122 1323 2018 2581
- TCP segment structure
- TCP seq rsquos and ACKs
- TCP Round Trip Time and Timeout
- TCP Round Trip Time and Timeout
- Example RTT estimation
- TCP Round Trip Time and Timeout
- TCP reliable data transfer
- TCP sender events
- TCP sender(simplified)
- TCP retransmission scenarios
- TCP retransmission scenarios (more)
- TCP ACK generation [RFC 1122 RFC 2581]
- Fast Retransmit
- Fast Retransmit
- Fast retransmit algorithm
- TCP Flow Control
- TCP Flow control how it works
- Sliding Window Flow Control Example
- Principles of Congestion Control
- Causescosts of congestion scenario 1
- Causescosts of congestion scenario 2
- Causescosts of congestion scenario 2
- Causescosts of congestion scenario 3
- Causescosts of congestion scenario 3
- Approaches towards congestion control
- TCP Congestion Control
- TCP congestion control bandwidth probing
- TCP Congestion Control details
- TCP Congestion Control more details
- TCP Slow Start Phase
- Slow Start Example
- TCP Congestion Avoidance Phase
- Congestion Avoidance
- Example Slow StartCongestion Avoidance
- Slow Start Congestion Avoidance
- Responses to Congestion
- Fast Recovery (differentiation btwn two loss events)
- TCP Congestion Control
- Popular ldquoflavorsrdquo of TCP
- Summary TCP Congestion Control
- TCP Congestion Control Summary
- TCP throughput
- TCP Futures TCP over ldquolong fat pipesrdquo
- TCP Fairness
- Why is TCP fair
- Fairness (more)
- TCP Connection Management
- TCP Connection Management (cont)
- TCP Connection Management (cont)
- TCP Connection Management (cont)
- Tuning TCPIP Parameters
- SomeTCP Parameters in Linux Kernel
- SomeTCP Parameters in Linux Kernel
-
Transport Layer 3-31
rdt30 in action
Transport Layer 3-32
Performance of rdt30
rdt30 works but performance stinksexample 1 Gbps link 15 ms e-e prop delay 1KB packet
Ttransmit = 8kbpkt109 bsec = 8 microsec
U sender utilization ndash fraction of time sender busy sending1KB pkt every 30 msec -gt 33kBsec thruput over 1 Gbps linknetwork protocol limits use of physical resources
U sender=
008 30008
= 000027 L RRTT + L R
=
L (packet length in bits)R (transmission rate bps) =
Transport Layer 3-33
rdt30 stop-and-wait operation
first packet bit transmitted t = 0
sender receiver
RTT
last packet bit transmitted t = L R
first packet bit arriveslast packet bit arrives send ACK
ACK arrives send next packet t = RTT + L R
U sender=
00830008
= 000027 L RRTT + L R
=
Transport Layer 3-34
Pipelined protocolsPipelining sender allows multiple ldquoin-flightrdquo yet-to-
be-acknowledged pktsrange of sequence numbers must be increasedbuffering at sender andor receiver
Two generic forms of pipelined protocols go-Back-N selective repeat
Transport Layer 3-35
Pipelining increased utilization
first packet bit transmitted t = 0
sender receiver
RTT
last bit transmitted t = L R
first packet bit arriveslast packet bit arrives send ACK
ACK arrives send next packet t = RTT + L R
last bit of 2nd packet arrives send ACKlast bit of 3rd packet arrives send ACK
U sender=
024 30008
= 000083 L RRTT + L R
=
Increase utilizationby a factor of 3
Transport Layer 3-36
Utilization=N(LR)(RTT+LR) if NLRltRTT+LR Utilization=1 if and the sender pauses after it transmits a window NLRgtRTT+LR and the of packets until it receives first ACK sender does not pause
Transport Layer 3-37
Go-Back-NSender
k-bit seq in pkt headerldquowindowrdquo of up to N consecutive unackrsquoed pkts allowed
ACK(n) ACKs all pkts up to including seq n - ldquocumulative ACKrdquomay receive duplicate ACKs (see receiver)
timer for the entire windowtimeout(n) retransmit pkt n and all higher seq pkts in window
Transport Layer 3-38
GBN sender extended FSM
Wait start_timerudt_send(sndpkt[base])udt_send(sndpkt[base+1])hellipudt_send(sndpkt[nextseqnum-1])
timeout
rdt_send(data)
if (nextseqnum lt base+N) sndpkt[nextseqnum] = make_pkt(nextseqnumdatachksum)udt_send(sndpkt[nextseqnum])if (base == nextseqnum)
start_timernextseqnum++
elserefuse_data(data)
base = getacknum(rcvpkt)+1If (base == nextseqnum)
stop_timerelse
start_timer
rdt_rcv(rcvpkt) ampamp notcorrupt(rcvpkt)
base=1nextseqnum=1
rdt_rcv(rcvpkt) ampamp corrupt(rcvpkt)
Λ
Λ
Transport Layer 3-39
GBN receiver extended FSM
ACK-only always send ACK for correctly-received pktwith highest in-order seq
may generate duplicate ACKsneed only remember expectedseqnum
out-of-order pkt discard (donrsquot buffer) -gt no receiver bufferingRe-ACK pkt with highest in-order seq
Wait
udt_send(sndpkt)default
rdt_rcv(rcvpkt)ampamp notcurrupt(rcvpkt)ampamp hasseqnum(rcvpktexpectedseqnum)
extract(rcvpktdata)deliver_data(data)sndpkt = make_pkt(expectedseqnumACKchksum)udt_send(sndpkt)expectedseqnum++
expectedseqnum=1sndpkt =
make_pkt(0ACKchksum)
Λ
Transport Layer 3-40
GBN inaction
Transport Layer 3-41
Selective Repeat
receiver individually acknowledges all correctly received pkts
buffers pkts as needed for eventual in-order delivery to upper layer
sender only resends pkts for which ACK not received
sender timer for each unACKed pktsender window
N consecutive seq rsquosagain limits seq s of sent unACKed pkts
Transport Layer 3-42
Selective repeat sender receiver windows
Transport Layer 3-43
Selective repeat
data from above if next available seq in window send pkt
timeout(n)resend pkt n restart timer
ACK(n) in [sendbasesendbase+N-1]
mark pkt n as receivedif n smallest unACKed pkt advance window base to next unACKed seq
senderpkt n in [rcvbase rcvbase+N-1]
send ACK(n)out-of-order bufferin-order deliver (also deliver buffered in-order pkts) advance window to next not-yet-received pkt
pkt n in [rcvbase-Nrcvbase-1]
ACK(n)otherwise
ignore
receiver
Transport Layer 3-44
Selective repeat in action
Transport Layer 3-45
Selective repeatdilemma
Example seq rsquos 0 1 2 3window size=3
receiver sees no difference in two scenariosincorrectly passes duplicate data as new in (a)
Q what relationship between seq size and window size
Transport Layer 3-46
Sequence Number vs Window SizeSuppose we use k bits to represent SNQuestion Whatrsquos the minimum number of bits k necessary for a window size of N
sender
receiver
Go-Back-N
expectedSN
snd_base=expectedSN
Q For a given expectedSN whatrsquos the largest possible value for snd_baseA If all the last N ACKs sent by the receiver are received
snd_base = expectedSNexpectedSN+N-1
senderrsquos window
Transport Layer 3-47
Sequence Number vs Window SizeSuppose we use k bits to represent SNQuestion Whatrsquos the minimum number of bits k necessary for a window size of N
sender
receiver
Go-Back-N
expectedSN
snd_base=expectedSN-N
Q For a given expectedSN whatrsquos the smallest possible value for snd_baseA If all the last N ACKs sent by the receiver are not received
snd_base = expectedSN-NexpectedSN-1
senderrsquos window
Transport Layer 3-48
Sequence Number vs Window Size
sender
receiver
Go-Back-N
expectedSN
snd_base=expectedSN-N
All SNs in the interval [expectedSN-NexpectedSN+N-1] (an interval of size 2N) can be received by the receiver Since the receiver accepts on the packet with SN=expectedSN there should be no other packet within this interval with SN=expectedSN Therefore
2k ge N+1expectedSN+N-1
Transport Layer 3-49
Sequence Number vs Window SizeSuppose we use k bits to represent SNQuestion Whatrsquos the minimum number of bits k necessary for a window size of N
sender
receiver
Selective Repeat
rcv_base
snd_base=rcv_base
Q For a given rcv_base whatrsquos the largest possible value for snd_baseA If all the last N ACKs sent by the receiver are received
snd_base = rcv_base (same as go_back-N)rcv_base+N-1
senderrsquos window
receiverrsquos window
rcv_base+N-1
Transport Layer 3-50
Sequence Number vs Window SizeSuppose we use k bits to represent SNQuestion Whatrsquos the minimum number of bits k necessary for a window size of N
sender
receiver
Selective Repeat
rcv_base
snd_base=rcv_base-N
Q For a given rcv_base whatrsquos the smallest possible value for snd_baseA If all the last N ACKs sent by the receiver are not received
snd_base = rcv_base-N (same as Go-Back-N)rcv_base-1
senderrsquos window
rcv_base
receiverrsquos window
rcv_base+N-1
Transport Layer 3-51
Sequence Number vs Window Size
sender
receiver
Selective Repeat
snd_base=rcv_base-N
All SNs in the interval [rcv_base-Nrcv_base+N-1] (an interval of size 2N) can be received by the receiver Since the receiver should be able to distinguish between all packets in this interval and take corresponding action there should be no two packets within thisinterval having the same SN Therefore
2k ge 2Nrcv_base+N-1
rcv_basercv_base
receiverrsquos window
rcv_base+N-1
Transport Layer 3-52
TCP Overview RFCs 793 1122 1323 2018 2581
full duplex databi-directional data flow in same connectionMSS maximum segment size
connection-orientedhandshaking (exchange of control msgs) initrsquossender receiver state before data exchange
flow controlledsender will not overwhelm receiver
point-to-pointone sender one receiver
reliable in-order byte stream
no ldquomessage boundariesrdquopipelined
TCP congestion and flow control set window size
send amp receive buffers
socketdoor
TCPsend buffer
TCPreceive buffer
socketdoor
segment
applicationwrites data
applicationreads data
Transport Layer 3-53
TCP segment structure
source port dest port
32 bits
applicationdata
(variable length)
sequence numberacknowledgement number
Receive windowUrg data pnterchecksum
FSRPAUheadlen
notused
Options (variable length)
URG urgent data (generally not used)
ACK ACK valid
PSH push data now(generally not used)
RST SYN FINconnection estab(setup teardown
commands)
bytes rcvr willingto accept
Internetchecksum
(as in UDP)
countingby bytes of data(not segments)
Transport Layer 3-54
TCP seq rsquos and ACKsSeq rsquos
byte stream ldquonumberrdquo of first byte in segmentrsquos dataACKs
seq of next byte expected from other sidecumulative ACK
Q how receiver handles out-of-order segmentsA TCP spec doesnrsquot say - up to implementationWidely used implementations of TCP buffer out-of-order segments
Transport Layer 3-55
TCP Round Trip Time and Timeout
Q how to set TCP timeout valuelonger than RTT
but RTT variestoo short premature timeout
unnecessary retransmissions
too long slow reaction to segment loss
Q how to estimate RTTSampleRTT measured time from segment transmission until ACK receipt
ignore retransmissionsSampleRTT will vary want estimated RTT ldquosmootherrdquo
average several recent measurements not just current SampleRTT
Transport Layer 3-56
TCP Round Trip Time and Timeout
EstimatedRTT = (1- α)EstimatedRTT + αSampleRTT
Exponential weighted moving averageinfluence of past sample decreases exponentially fasttypical value α = 0125
Transport Layer 3-57
Example RTT estimationRTT gaiacsumassedu to fantasiaeurecomfr
100
150
200
250
300
350
1 8 15 22 29 36 43 50 57 64 71 78 85 92 99 106
time (seconnds)
RTT
(mill
iseco
nds)
SampleRTT Estimated RTT
Transport Layer 3-58
TCP Round Trip Time and TimeoutSetting the timeout
EstimatedRTT plus ldquosafety marginrdquolarge variation in EstimatedRTT -gt larger safety margin
first estimate of how much SampleRTT deviates from EstimatedRTT
TimeoutInterval = EstimatedRTT + 4DevRTT
DevRTT = (1-β)DevRTT +β|SampleRTT-EstimatedRTT|
(typically β = 025)
Then set timeout interval
Transport Layer 3-59
TCP reliable data transfer
TCP creates rdtservice on top of IPrsquos unreliable servicePipelined segmentsCumulative acksTCP uses single retransmission timer however it just retransmits the first segment in the window
Retransmissions are triggered by
timeout eventsduplicate acks
Initially consider simplified TCP sender
ignore duplicate acksignore flow control congestion control
Transport Layer 3-60
TCP sender eventsdata rcvd from app
Create segment with seq seq is byte-stream number of first data byte in segmentstart timer if not already running (think of timer as for oldest unacked segment)expiration interval TimeOutInterval
timeoutretransmit segment that caused timeout (first segment in the window)restart timer
Ack rcvdIf acknowledges previously unacked segments
update what is known to be ackedstart timer if there are outstanding segments
Transport Layer 3-61
TCP sender(simplified)
NextSeqNum = InitialSeqNumSendBase = InitialSeqNum
loop (forever) switch(event)
event data received from application above create TCP segment with sequence number NextSeqNumif (timer currently not running)
start timerpass segment to IP NextSeqNum = NextSeqNum + length(data)
event timer timeoutretransmit not-yet-acknowledged segment with
smallest sequence numberstart timer
event ACK received with ACK field value of y if (y gt SendBase)
SendBase = yif (there are currently not-yet-acknowledged segments)
start timer
end of loop forever
Commentbull SendBase-1 last cumulatively ackrsquoed byteExamplebull SendBase-1 = 71y= 73 so the rcvrwants 73+ y gt SendBase sothat new data is acked
Transport Layer 3-62
TCP retransmission scenariosHost A
Seq=100 20 bytes data
ACK=100
timepremature timeout
Host B
Seq=92 8 bytes data
ACK=120
Seq=92 8 bytes data
Seq=
92 t
imeo
ut
ACK=120
Host A
Seq=92 8 bytes data
ACK=100
loss
tim
eout
lost ACK scenario
Host B
X
Seq=92 8 bytes data
ACK=100
time
Seq=
92 t
imeo
utSendBase
= 100
SendBase= 120
SendBase= 120
Sendbase= 100
Transport Layer 3-63
TCP retransmission scenarios (more)Host A
Seq=92 8 bytes data
ACK=100
loss
tim
eout
Cumulative ACK scenario
Host B
X
Seq=100 20 bytes data
ACK=120
time
SendBase= 120
Transport Layer 3-64
TCP ACK generation [RFC 1122 RFC 2581]
Event at Receiver
Arrival of in-order segment withexpected seq All data up toexpected seq already ACKed
Arrival of in-order segment withexpected seq One other segment has ACK pending
Arrival of out-of-order segmenthigher-than-expect seq Gap detected
Arrival of segment that partially or completely fills gap
TCP Receiver action
Delayed ACK Wait up to 500msfor next segment If no next segmentsend ACK
Immediately send single cumulative ACK ACKing both in-order segments
Immediately send duplicate ACK indicating seq of next expected byte
Immediate send ACK provided thatsegment startsat lower end of gap
Transport Layer 3-65
Fast Retransmit
Time-out period often relatively long
long delay before resending lost packet
Detect lost segments via duplicate ACKs
Sender often sends many segments back-to-backIf segment is lost there will likely be many duplicate ACKs
If sender receives 3 ACKs for the same data it supposes that segment after ACKeddata was lost
fast retransmit resend segment before timer expires
Transport Layer 3-66
Fast RetransmitResend a segment after 3 duplicate ACKs since a duplicate ACK means that an out-of sequence segment was receivedduplicate ACKs due to packet reorderingif window is small donrsquot get duplicate ACKs
Host A
tim
eout
Host B
time
X
resend seq X2
seq x1seq x2seq x3seq x4seq x5
ACK x1
ACK x1ACK x1ACK x1
tripleduplicate
ACKs
Transport Layer 3-67
event ACK received with ACK field value of y if (y gt SendBase)
SendBase = yif (there are currently not-yet-acknowledged segments)
start timer
else increment count of dup ACKs received for yif (count of dup ACKs received for y = 3)
resend segment with sequence number y
Fast retransmit algorithm
a duplicate ACK for already ACKed segment
fast retransmit
Transport Layer 3-68
TCP Flow Control
receive side of TCP connection has a receive buffer
speed-matching service matching the send rate to the receiving apprsquos drain rate
app process may be slow at reading from buffer
sender wonrsquot overflowreceiverrsquos buffer by
transmitting too muchtoo fast
flow control
Transport Layer 3-69
TCP Flow control how it works
(Suppose TCP receiver discards out-of-order segments)spare room in buffer
= RcvWin
= RcvBuffer-[LastByteRcvd -LastByteRead]
Rcvr advertises spare room by including value of RcvWin in segmentsSender limits unACKeddata to RcvWin
guarantees receive buffer doesnrsquot overflow
Transport Layer 3-70
Sliding Window Flow Control Example
3K
2K SeqNo=0
ReceiverBuffer
0 4KSendersends 2Kof data
2K
AckNo=2048 RcvWin=2048Sendersends 2Kof data 2K SeqNo=2048
4K
AckNo=4096 RcvWin=0
AckNo=4096 RcvWin=1024
Sender blocked
Transport Layer 3-71
Principles of Congestion Control
Congestioninformally ldquotoo many sources sending too much data too fast for network to handlerdquodifferent from flow controlmanifestations
lost packets (buffer overflow at routers)long delays (queueing in router buffers)
a top-10 problem
Transport Layer 3-72
Causescosts of congestion scenario 1
two senders two receiversone router infinite buffers no retransmission
large delays when congestedmaximum achievable throughput
unlimited shared output link buffers
Host Aλin original data
Host B
λout
Transport Layer 3-73
Causescosts of congestion scenario 2
one router finite buffers sender retransmission of lost packet
finite shared output link buffers
Host A λin original data
Host B
λout
λin original data plus retransmitted data
Transport Layer 3-74
Causescosts of congestion scenario 2always (goodput)ldquoperfectrdquo retransmission only when loss
retransmission of delayed (not lost) packet makes larger(than perfect case) for same
λin
λout=
λin
λoutgtλ
inλout
ldquocostsrdquo of congestionmore work (retrans) for given ldquogoodputrdquounneeded retransmissions link carries multiple copies of pkt
R2
R2λin
λ out
b
R2
R2λin
λ out
a
R2
R2λin
λ out
c
R4
R3
Transport Layer 3-75
Causescosts of congestion scenario 3four sendersmultihop pathstimeoutretransmit
λin
Q what happens as and increase λ
in
finite shared output link buffers
Host Aλin original data
Host B
λout
λin original data plus retransmitted data
Transport Layer 3-76
Causescosts of congestion scenario 3
another ldquocostrdquo of congestionwhen packet dropped any ldquoupstream transmission capacity used for that packet was wasted
Host A
Host B
λou
t
Transport Layer 3-77
Approaches towards congestion control
End-end congestion controlno explicit feedback from networkcongestion inferred from end-system observed loss delayapproach taken by TCP
Network-assisted congestion controlrouters provide feedback to end systems
single bit indicating congestion (SNA DECbit TCPIP ECN ATM)explicit rate sender should send at
Two broad approaches towards congestion control
Transport Layer 3-78
TCP Congestion Control
end-end control (no network assistance)sender limits transmissionLastByteSent-LastByteAcked
le CongWin
CongWin is dynamic function of perceived network congestion
How does sender perceive congestionloss event = timeout or3 duplicate acksTCP sender reduces rate (CongWin) after loss event
two modes of operationSlow Start (SS)Congestion avoidance (CA) or Additive Increase Multiplicative Decrease (AIMD)
Transport Layer 3-79
TCP congestion control bandwidth probing
ldquoprobing for bandwidthrdquo increase transmission rate on receipt of ACK until eventually loss occurs then decrease transmission rate
continue to increase on ACK decrease on loss (since available bandwidth is changing depending on other connections in network)
ACKs being received so increase rate
X
X
XX
X loss so decrease rate
send
ing
rate
time
Q how fast to increasedecreasedetails to follow
TCPrsquosldquosawtoothrdquobehavior
Transport Layer 3-80
TCP Congestion Control details
sender limits rate by limiting number of unACKed bytes ldquoin pipelinerdquo
cwnd differs from rwnd (how why)sender limited by min(cwndrwnd)
roughly
cwnd is dynamic function of perceived network congestion
rate = cwndRTT bytessec
LastByteSent-LastByteAcked le cwnd
cwndbytes
RTT
ACK(s)
Transport Layer 3-81
TCP Congestion Control more details
segment loss event reducing cwndtimeout no response from receiver
cut cwnd to 13 duplicate ACKs at least some segments getting through (recall fast retransmit)
cut cwnd in half less aggressively than on timeout
ACK received increase cwndTwo modes of operation
slowstart phase bull increase exponentially
fast (despite name) at connection start or following timeout
congestion avoidance bull increase linearly
Transport Layer 3-82
TCP Slow Start Phasewhen connection begins cwnd = 1 MSS
example MSS = 500 bytes amp RTT = 200 msecinitial rate = 20 kbps
available bandwidth may be gtgt MSSRTT
desirable to quickly ramp up to respectable rate
increase rate exponentially until first loss event or when threshold reached
double cwnd every RTTdone by incrementing cwnd by 1 for every ACK received
Host A
one segment
RTT
Host B
time
two segments
four segments
Transport Layer 3-83
Slow Start ExampleThe congestion window size grows very rapidly
For every ACK we increase CongWin by 1 irrespective of the number of segments ACKrsquoeddouble CongWinevery RTTinitial rate is slow but ramps up exponentially fast
TCP slows down the increase of CongWinwhen CongWin gt ssthresh
segment 1
ACK for segment 1
cwnd = 1
cwnd = 2 segment 2segment 3
ACK for segments 2
cwnd = 4 segment 4segment 5segment 6
ACK for segments 4
cwnd = 7
ACK for segments 3
ACK for segments 5
ACK for segments 6
cwnd = 3
cwnd = 5
cwnd = 6ACK for segments 7
cwnd = 8
segment 7
Transport Layer 3-84
TCP Congestion Avoidance Phase
when cwnd gt ssthreshgrow cwnd linearly
increase cwnd by 1 MSS per RTT approach possible congestion slower than in slowstartimplementation cwnd= cwnd + MSScwndfor each ACK received
ACKs increase cwndby 1 MSS per RTT additive increaseloss cut cwnd in half (non-timeout-detected loss ) multiplicative decrease
AIMD
AIMD Additive IncreaseMultiplicative Decrease
Transport Layer 3-85
Congestion AvoidanceCongestion avoidance phase is started if CongWin has reached the slow-start threshold value
If CongWin gt= ssthresh then each time an ACK is received increment CongWin as follows
bull CongWin = CongWin + 1CongWin (CongWin in segments)
bull In actual TCP implementation CongWin is in BytesCongWin = CongWin + MSS (MSSCongWin)
So CongWin is increased by one only if all CongWinsegments have been acknowledged
Transport Layer 3-86
Example Slow StartCongestion AvoidanceAssume that
ssthresh = 8
cwnd = 1
cwnd = 2
cwnd = 4
cwnd = 8
cwnd = 9
cwnd = 10
02468
101214
t=0
t=2
t=4
t=6
Roundtrip times
Cw
nd(in
seg
men
ts)
ssthresh
cwnd = 3
cwnd = 5cwnd = 6cwnd = 7
Transport Layer 3-87
Slow Start Congestion AvoidanceA typical plot of CongWin for a TCP connection
(MSS = 1500 bytes) with TCP Tahoe
SS
CA
ssthresh
Transport Layer 3-88
Responses to CongestionTCP assumes there is congestion if it detects a packet lossA TCP sender can detect lost packets via loss events
bull Timeout of a retransmission timerbull Receipt of 3 duplicate ACKs (fast retransmit)
TCP interprets a Timeout as a binary congestion signal When a timeout occurs the sender performs
ssthresh is set to half the current size of the congestion window
ssthresh = CongWin 2CongWin is reset to one
CongWin = 1and slow-start is entered
Transport Layer 3-89
Fast Recovery (differentiation btwn two loss events) After 3 dup ACKs (fast Retransmit)
ssthresh = CongWin2CongWin = CongWin2window then grows linearly
But after timeout eventCongWin = 1 MSS window then grows exponentiallyto the threshold then grows linearly
bull 3 dup ACKs indicates network capable of delivering some segmentsbull timeout before 3 dup ACKs is ldquomore alarmingrdquo
Philosophy
3-90
TCP Congestion ControlInitially
CongWin = 1ssthresh = advertised window size
New Ack receivedif (CongWin lt ssthresh) Slow Start
CongWin = CongWin + 1else Congestion Avoidance
CongWin = CongWin + 1CongWinTimeout
ssthresh = CongWin2CongWin = 1
Fast Retransmissionssthresh = CongWin2CongWin = CongWin2
Slow Start (exponential increase phase) is continued until CongWin reaches half of the level where the loss event occurred last time CongWin is increased slowly after (linear increase in Congestion Avoidance phase)
Transport Layer 3-91
Popular ldquoflavorsrdquo of TCP
ssthresh
ssthresh
TCP Tahoe
TCP Reno
Transmission round
cwnd
win
dow
siz
e (in
seg
men
ts)
Transport Layer 3-92
Summary TCP Congestion ControlWhen CongWin is below Threshold sender in slow-start phase window grows exponentiallyWhen CongWin is above Threshold sender is in congestion-avoidance phase window grows linearlyWhen a triple duplicate ACK occurs Threshold set to CongWin2 and CongWin set to ThresholdWhen timeout occurs Threshold set to CongWin2 and CongWin is set to 1 MSS The actual sender window size is determined based on the congestion and flow control algorithms
SenderWin=min(RcvWinCongWin)
Transport Layer 3-93
TCP Congestion Control SummaryEvent State TCP Sender Action Commentary
ACK receipt for previously unackeddata
Slow Start (SS)
CongWin = CongWin + MSS If (CongWin gt Threshold)
set state to ldquoCongestion Avoidancerdquo
Resulting in a doubling of CongWin every RTT
ACK receipt for previously unackeddata
CongestionAvoidance (CA)
CongWin = CongWin+MSS (MSSCongWin)
Additive increase resulting in increase of CongWin by 1 MSS every RTT
Loss event detected by triple duplicate ACK
SS or CA Threshold = CongWin2 CongWin = ThresholdSet state to ldquoCongestion Avoidancerdquo
Fast recovery implementing multiplicative decrease CongWin will not drop below 1 MSS
Timeout SS or CA Threshold = CongWin2 CongWin = 1 MSSSet state to ldquoSlow Startrdquo
Enter slow start
Duplicate ACK
SS or CA Increment duplicate ACK count for segment being acked
CongWin and Threshold not changed
Transport Layer 3-94
TCP throughput
Q whatrsquos average throughout of TCP as function of window size RTT
ignoring slow startlet W be window size when loss occurs
when window is W throughput is WRTTjust after loss window drops to W2 throughput to W2RTT average throughout 75 WRTT
Transport Layer 3-95
TCP Futures TCP over ldquolong fat pipesrdquo
example 1500 byte segments 100ms RTT want 10 Gbps throughputrequires window size W = 83333 in-flight segmentsthroughput in terms of loss rate
L = 210-10 Wownew versions of TCP for high-speed
LRTTMSSsdot221
Transport Layer 3-96
Fairness goal if K TCP sessions share same bottleneck link of bandwidth R each should have average rate of RK
TCP connection 1
bottleneckrouter
capacity R
TCP connection 2
TCP Fairness
Transport Layer 3-97
Why is TCP fairTwo competing sessions
Additive increase gives slope of 1 as throughout increasesmultiplicative decrease decreases throughput proportionally
R
R
equal bandwidth share
Connection 1 throughput
Conn
ecti
on 2
thr
ough
p ut
congestion avoidance additive increaseloss decrease window by factor of 2
congestion avoidance additive increaseloss decrease window by factor of 2
Transport Layer 3-98
Fairness (more)Fairness and UDP
Multimedia apps often do not use TCP
do not want rate throttled by congestion control
Instead use UDPpump audiovideo at constant rate tolerate packet loss
Research area TCP friendly
Fairness and parallel TCP connectionsnothing prevents app from opening parallel cnctionsbetween 2 hostsWeb browsers do this Example link of rate R supporting 9 cnctions
new app asks for 1 TCP gets rate R10new app asks for 11 TCPs gets R2
Transport Layer 3-99
TCP Connection ManagementRecall TCP sender receiver
establish ldquoconnectionrdquobefore exchanging data segmentsinitialize TCP variables
seq sbuffers flow control info (eg RcvWindow)
client connection initiatorSocket clientSocket = new Socket(hostnameport
number)
server contacted by clientSocket connectionSocket = welcomeSocketaccept()
Three way handshakeStep 1 client host sends TCP
SYN segment to serverspecifies initial seq no data
Step 2 server host receives SYN replies with SYNACK segment
server allocates buffersspecifies server initial seq
Step 3 client receives SYNACK replies with ACK segment which may contain data
Transport Layer 3-100
TCP Connection Management (cont)
Closing a connection
client closes socketclientSocketclose()
Step 1 client end system sends TCP FIN control segment to server
Step 2 server receives FIN replies with ACK Closes connection sends FIN
client
FIN
server
ACK
ACK
FIN
close
close
closed
tim
ed w
ait
Transport Layer 3-101
TCP Connection Management (cont)
Step 3 client receives FIN replies with ACK
Enters ldquotimed waitrdquo -will respond with ACK to received FINs
Step 4 server receives ACK Connection closed
client
FIN
server
ACK
ACK
FIN
closing
closing
closed
tim
ed w
ait
closed
Transport Layer 3-102
TCP Connection Management (cont)
TCP clientlifecycle
TCP serverlifecycle
Transport Layer 3-103
Tuning TCPIP Parameters TCPIP parameters
A set of default values may not be optimal for all applicationsThe network administrator may wish to turn on or off some TCPIP functions for performance or security considerations
Many Unix and Linux systems provide some flexibility in tuning the TCPIP kernelsbinsysctl is used to configure the Linux kernel parameters at runtime
Default kernel configuration file is sbinsysctlconfFrequently used sysctl options
bull sysctl ndasha or sysctl ndashA list all current valuesbull sysctl ndashp file_name load the sysctl setting from a configuration
filebull sysctl ndashw variable=value change the value of the parameter
Transport Layer 3-104
SomeTCP Parameters in Linux Kerneltcp_syn_retries
Number of SYN packets the kernel will send before giving up on the new connection
tcp_synack_retriesnumber of SYN+ACK packets sent before the kernel gives up on the connection
tcp_window_scalingMaximum window size of 65535 bytes not enough for for really fast networks The window scaling options allows for almost gigabyte windows which is good for connections with large delay-bandwidth product
tcp_max_syn_backlogMaximal number of remembered connection requests which still did not receive an acknowledgment from connecting client
tcp_fin_timeoutHow many seconds to wait for a final FIN packet before the socket is closed required to prevent denial-of-service (DoS) attacks Default value is 60 seconds
Transport Layer 3-105
SomeTCP Parameters in Linux Kerneltcp_rmem
This is a vector of 3 integers [min default max] These parameters are used by TCP to dynamically adjust receive buffer sizesmin - minimum size of the receive buffer used by each TCP socket The default value is 4K default - the default size of the receive buffer for a TCP socket The default value is 87380 bytes and is lowered to 43689 in low memory systems If larger receive buffer sizes are desired this value should be increased max - the maximum size of the receive buffer used by each TCP socket The default value of 873802 bytes is lowered to 87380 in low memory systems
tcp_smemSend buffer parameters [min default max] similar to tcp_rmem
- Chapter 3 Transport Layer
- Transport services and protocols
- Transport vs network layer
- Internet transport-layer protocols
- Multiplexingdemultiplexing
- How demultiplexing works
- Connectionless demultiplexing
- Connection-oriented demux
- Connection-oriented demux (cont)
- Connection-oriented demux Threaded Web Server
- UDP User Datagram Protocol [RFC 768]
- UDP more
- UDP checksum
- Principles of Reliable data transfer
- Reliable data transfer getting started
- Reliable data transfer getting started
- Rdt10 reliable transfer over a reliable channel
- Rdt20 channel with bit errors
- rdt20 FSM specification
- rdt20 operation with no errors
- rdt20 error scenario
- rdt20 has a fatal flaw
- rdt21 sender handles garbled ACKNAKs
- rdt21 receiver handles garbled ACKNAKs
- rdt21 discussion
- rdt22 a NAK-free protocol
- rdt22 sender receiver fragments
- rdt30 channels with errors and loss
- rdt30 sender
- rdt30 in action
- rdt30 in action
- Performance of rdt30
- rdt30 stop-and-wait operation
- Pipelined protocols
- Pipelining increased utilization
- Go-Back-N
- GBN sender extended FSM
- GBN receiver extended FSM
- GBN inaction
- Selective Repeat
- Selective repeat sender receiver windows
- Selective repeat
- Selective repeat in action
- Selective repeat dilemma
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- TCP Overview RFCs 793 1122 1323 2018 2581
- TCP segment structure
- TCP seq rsquos and ACKs
- TCP Round Trip Time and Timeout
- TCP Round Trip Time and Timeout
- Example RTT estimation
- TCP Round Trip Time and Timeout
- TCP reliable data transfer
- TCP sender events
- TCP sender(simplified)
- TCP retransmission scenarios
- TCP retransmission scenarios (more)
- TCP ACK generation [RFC 1122 RFC 2581]
- Fast Retransmit
- Fast Retransmit
- Fast retransmit algorithm
- TCP Flow Control
- TCP Flow control how it works
- Sliding Window Flow Control Example
- Principles of Congestion Control
- Causescosts of congestion scenario 1
- Causescosts of congestion scenario 2
- Causescosts of congestion scenario 2
- Causescosts of congestion scenario 3
- Causescosts of congestion scenario 3
- Approaches towards congestion control
- TCP Congestion Control
- TCP congestion control bandwidth probing
- TCP Congestion Control details
- TCP Congestion Control more details
- TCP Slow Start Phase
- Slow Start Example
- TCP Congestion Avoidance Phase
- Congestion Avoidance
- Example Slow StartCongestion Avoidance
- Slow Start Congestion Avoidance
- Responses to Congestion
- Fast Recovery (differentiation btwn two loss events)
- TCP Congestion Control
- Popular ldquoflavorsrdquo of TCP
- Summary TCP Congestion Control
- TCP Congestion Control Summary
- TCP throughput
- TCP Futures TCP over ldquolong fat pipesrdquo
- TCP Fairness
- Why is TCP fair
- Fairness (more)
- TCP Connection Management
- TCP Connection Management (cont)
- TCP Connection Management (cont)
- TCP Connection Management (cont)
- Tuning TCPIP Parameters
- SomeTCP Parameters in Linux Kernel
- SomeTCP Parameters in Linux Kernel
-
Transport Layer 3-32
Performance of rdt30
rdt30 works but performance stinksexample 1 Gbps link 15 ms e-e prop delay 1KB packet
Ttransmit = 8kbpkt109 bsec = 8 microsec
U sender utilization ndash fraction of time sender busy sending1KB pkt every 30 msec -gt 33kBsec thruput over 1 Gbps linknetwork protocol limits use of physical resources
U sender=
008 30008
= 000027 L RRTT + L R
=
L (packet length in bits)R (transmission rate bps) =
Transport Layer 3-33
rdt30 stop-and-wait operation
first packet bit transmitted t = 0
sender receiver
RTT
last packet bit transmitted t = L R
first packet bit arriveslast packet bit arrives send ACK
ACK arrives send next packet t = RTT + L R
U sender=
00830008
= 000027 L RRTT + L R
=
Transport Layer 3-34
Pipelined protocolsPipelining sender allows multiple ldquoin-flightrdquo yet-to-
be-acknowledged pktsrange of sequence numbers must be increasedbuffering at sender andor receiver
Two generic forms of pipelined protocols go-Back-N selective repeat
Transport Layer 3-35
Pipelining increased utilization
first packet bit transmitted t = 0
sender receiver
RTT
last bit transmitted t = L R
first packet bit arriveslast packet bit arrives send ACK
ACK arrives send next packet t = RTT + L R
last bit of 2nd packet arrives send ACKlast bit of 3rd packet arrives send ACK
U sender=
024 30008
= 000083 L RRTT + L R
=
Increase utilizationby a factor of 3
Transport Layer 3-36
Utilization=N(LR)(RTT+LR) if NLRltRTT+LR Utilization=1 if and the sender pauses after it transmits a window NLRgtRTT+LR and the of packets until it receives first ACK sender does not pause
Transport Layer 3-37
Go-Back-NSender
k-bit seq in pkt headerldquowindowrdquo of up to N consecutive unackrsquoed pkts allowed
ACK(n) ACKs all pkts up to including seq n - ldquocumulative ACKrdquomay receive duplicate ACKs (see receiver)
timer for the entire windowtimeout(n) retransmit pkt n and all higher seq pkts in window
Transport Layer 3-38
GBN sender extended FSM
Wait start_timerudt_send(sndpkt[base])udt_send(sndpkt[base+1])hellipudt_send(sndpkt[nextseqnum-1])
timeout
rdt_send(data)
if (nextseqnum lt base+N) sndpkt[nextseqnum] = make_pkt(nextseqnumdatachksum)udt_send(sndpkt[nextseqnum])if (base == nextseqnum)
start_timernextseqnum++
elserefuse_data(data)
base = getacknum(rcvpkt)+1If (base == nextseqnum)
stop_timerelse
start_timer
rdt_rcv(rcvpkt) ampamp notcorrupt(rcvpkt)
base=1nextseqnum=1
rdt_rcv(rcvpkt) ampamp corrupt(rcvpkt)
Λ
Λ
Transport Layer 3-39
GBN receiver extended FSM
ACK-only always send ACK for correctly-received pktwith highest in-order seq
may generate duplicate ACKsneed only remember expectedseqnum
out-of-order pkt discard (donrsquot buffer) -gt no receiver bufferingRe-ACK pkt with highest in-order seq
Wait
udt_send(sndpkt)default
rdt_rcv(rcvpkt)ampamp notcurrupt(rcvpkt)ampamp hasseqnum(rcvpktexpectedseqnum)
extract(rcvpktdata)deliver_data(data)sndpkt = make_pkt(expectedseqnumACKchksum)udt_send(sndpkt)expectedseqnum++
expectedseqnum=1sndpkt =
make_pkt(0ACKchksum)
Λ
Transport Layer 3-40
GBN inaction
Transport Layer 3-41
Selective Repeat
receiver individually acknowledges all correctly received pkts
buffers pkts as needed for eventual in-order delivery to upper layer
sender only resends pkts for which ACK not received
sender timer for each unACKed pktsender window
N consecutive seq rsquosagain limits seq s of sent unACKed pkts
Transport Layer 3-42
Selective repeat sender receiver windows
Transport Layer 3-43
Selective repeat
data from above if next available seq in window send pkt
timeout(n)resend pkt n restart timer
ACK(n) in [sendbasesendbase+N-1]
mark pkt n as receivedif n smallest unACKed pkt advance window base to next unACKed seq
senderpkt n in [rcvbase rcvbase+N-1]
send ACK(n)out-of-order bufferin-order deliver (also deliver buffered in-order pkts) advance window to next not-yet-received pkt
pkt n in [rcvbase-Nrcvbase-1]
ACK(n)otherwise
ignore
receiver
Transport Layer 3-44
Selective repeat in action
Transport Layer 3-45
Selective repeatdilemma
Example seq rsquos 0 1 2 3window size=3
receiver sees no difference in two scenariosincorrectly passes duplicate data as new in (a)
Q what relationship between seq size and window size
Transport Layer 3-46
Sequence Number vs Window SizeSuppose we use k bits to represent SNQuestion Whatrsquos the minimum number of bits k necessary for a window size of N
sender
receiver
Go-Back-N
expectedSN
snd_base=expectedSN
Q For a given expectedSN whatrsquos the largest possible value for snd_baseA If all the last N ACKs sent by the receiver are received
snd_base = expectedSNexpectedSN+N-1
senderrsquos window
Transport Layer 3-47
Sequence Number vs Window SizeSuppose we use k bits to represent SNQuestion Whatrsquos the minimum number of bits k necessary for a window size of N
sender
receiver
Go-Back-N
expectedSN
snd_base=expectedSN-N
Q For a given expectedSN whatrsquos the smallest possible value for snd_baseA If all the last N ACKs sent by the receiver are not received
snd_base = expectedSN-NexpectedSN-1
senderrsquos window
Transport Layer 3-48
Sequence Number vs Window Size
sender
receiver
Go-Back-N
expectedSN
snd_base=expectedSN-N
All SNs in the interval [expectedSN-NexpectedSN+N-1] (an interval of size 2N) can be received by the receiver Since the receiver accepts on the packet with SN=expectedSN there should be no other packet within this interval with SN=expectedSN Therefore
2k ge N+1expectedSN+N-1
Transport Layer 3-49
Sequence Number vs Window SizeSuppose we use k bits to represent SNQuestion Whatrsquos the minimum number of bits k necessary for a window size of N
sender
receiver
Selective Repeat
rcv_base
snd_base=rcv_base
Q For a given rcv_base whatrsquos the largest possible value for snd_baseA If all the last N ACKs sent by the receiver are received
snd_base = rcv_base (same as go_back-N)rcv_base+N-1
senderrsquos window
receiverrsquos window
rcv_base+N-1
Transport Layer 3-50
Sequence Number vs Window SizeSuppose we use k bits to represent SNQuestion Whatrsquos the minimum number of bits k necessary for a window size of N
sender
receiver
Selective Repeat
rcv_base
snd_base=rcv_base-N
Q For a given rcv_base whatrsquos the smallest possible value for snd_baseA If all the last N ACKs sent by the receiver are not received
snd_base = rcv_base-N (same as Go-Back-N)rcv_base-1
senderrsquos window
rcv_base
receiverrsquos window
rcv_base+N-1
Transport Layer 3-51
Sequence Number vs Window Size
sender
receiver
Selective Repeat
snd_base=rcv_base-N
All SNs in the interval [rcv_base-Nrcv_base+N-1] (an interval of size 2N) can be received by the receiver Since the receiver should be able to distinguish between all packets in this interval and take corresponding action there should be no two packets within thisinterval having the same SN Therefore
2k ge 2Nrcv_base+N-1
rcv_basercv_base
receiverrsquos window
rcv_base+N-1
Transport Layer 3-52
TCP Overview RFCs 793 1122 1323 2018 2581
full duplex databi-directional data flow in same connectionMSS maximum segment size
connection-orientedhandshaking (exchange of control msgs) initrsquossender receiver state before data exchange
flow controlledsender will not overwhelm receiver
point-to-pointone sender one receiver
reliable in-order byte stream
no ldquomessage boundariesrdquopipelined
TCP congestion and flow control set window size
send amp receive buffers
socketdoor
TCPsend buffer
TCPreceive buffer
socketdoor
segment
applicationwrites data
applicationreads data
Transport Layer 3-53
TCP segment structure
source port dest port
32 bits
applicationdata
(variable length)
sequence numberacknowledgement number
Receive windowUrg data pnterchecksum
FSRPAUheadlen
notused
Options (variable length)
URG urgent data (generally not used)
ACK ACK valid
PSH push data now(generally not used)
RST SYN FINconnection estab(setup teardown
commands)
bytes rcvr willingto accept
Internetchecksum
(as in UDP)
countingby bytes of data(not segments)
Transport Layer 3-54
TCP seq rsquos and ACKsSeq rsquos
byte stream ldquonumberrdquo of first byte in segmentrsquos dataACKs
seq of next byte expected from other sidecumulative ACK
Q how receiver handles out-of-order segmentsA TCP spec doesnrsquot say - up to implementationWidely used implementations of TCP buffer out-of-order segments
Transport Layer 3-55
TCP Round Trip Time and Timeout
Q how to set TCP timeout valuelonger than RTT
but RTT variestoo short premature timeout
unnecessary retransmissions
too long slow reaction to segment loss
Q how to estimate RTTSampleRTT measured time from segment transmission until ACK receipt
ignore retransmissionsSampleRTT will vary want estimated RTT ldquosmootherrdquo
average several recent measurements not just current SampleRTT
Transport Layer 3-56
TCP Round Trip Time and Timeout
EstimatedRTT = (1- α)EstimatedRTT + αSampleRTT
Exponential weighted moving averageinfluence of past sample decreases exponentially fasttypical value α = 0125
Transport Layer 3-57
Example RTT estimationRTT gaiacsumassedu to fantasiaeurecomfr
100
150
200
250
300
350
1 8 15 22 29 36 43 50 57 64 71 78 85 92 99 106
time (seconnds)
RTT
(mill
iseco
nds)
SampleRTT Estimated RTT
Transport Layer 3-58
TCP Round Trip Time and TimeoutSetting the timeout
EstimatedRTT plus ldquosafety marginrdquolarge variation in EstimatedRTT -gt larger safety margin
first estimate of how much SampleRTT deviates from EstimatedRTT
TimeoutInterval = EstimatedRTT + 4DevRTT
DevRTT = (1-β)DevRTT +β|SampleRTT-EstimatedRTT|
(typically β = 025)
Then set timeout interval
Transport Layer 3-59
TCP reliable data transfer
TCP creates rdtservice on top of IPrsquos unreliable servicePipelined segmentsCumulative acksTCP uses single retransmission timer however it just retransmits the first segment in the window
Retransmissions are triggered by
timeout eventsduplicate acks
Initially consider simplified TCP sender
ignore duplicate acksignore flow control congestion control
Transport Layer 3-60
TCP sender eventsdata rcvd from app
Create segment with seq seq is byte-stream number of first data byte in segmentstart timer if not already running (think of timer as for oldest unacked segment)expiration interval TimeOutInterval
timeoutretransmit segment that caused timeout (first segment in the window)restart timer
Ack rcvdIf acknowledges previously unacked segments
update what is known to be ackedstart timer if there are outstanding segments
Transport Layer 3-61
TCP sender(simplified)
NextSeqNum = InitialSeqNumSendBase = InitialSeqNum
loop (forever) switch(event)
event data received from application above create TCP segment with sequence number NextSeqNumif (timer currently not running)
start timerpass segment to IP NextSeqNum = NextSeqNum + length(data)
event timer timeoutretransmit not-yet-acknowledged segment with
smallest sequence numberstart timer
event ACK received with ACK field value of y if (y gt SendBase)
SendBase = yif (there are currently not-yet-acknowledged segments)
start timer
end of loop forever
Commentbull SendBase-1 last cumulatively ackrsquoed byteExamplebull SendBase-1 = 71y= 73 so the rcvrwants 73+ y gt SendBase sothat new data is acked
Transport Layer 3-62
TCP retransmission scenariosHost A
Seq=100 20 bytes data
ACK=100
timepremature timeout
Host B
Seq=92 8 bytes data
ACK=120
Seq=92 8 bytes data
Seq=
92 t
imeo
ut
ACK=120
Host A
Seq=92 8 bytes data
ACK=100
loss
tim
eout
lost ACK scenario
Host B
X
Seq=92 8 bytes data
ACK=100
time
Seq=
92 t
imeo
utSendBase
= 100
SendBase= 120
SendBase= 120
Sendbase= 100
Transport Layer 3-63
TCP retransmission scenarios (more)Host A
Seq=92 8 bytes data
ACK=100
loss
tim
eout
Cumulative ACK scenario
Host B
X
Seq=100 20 bytes data
ACK=120
time
SendBase= 120
Transport Layer 3-64
TCP ACK generation [RFC 1122 RFC 2581]
Event at Receiver
Arrival of in-order segment withexpected seq All data up toexpected seq already ACKed
Arrival of in-order segment withexpected seq One other segment has ACK pending
Arrival of out-of-order segmenthigher-than-expect seq Gap detected
Arrival of segment that partially or completely fills gap
TCP Receiver action
Delayed ACK Wait up to 500msfor next segment If no next segmentsend ACK
Immediately send single cumulative ACK ACKing both in-order segments
Immediately send duplicate ACK indicating seq of next expected byte
Immediate send ACK provided thatsegment startsat lower end of gap
Transport Layer 3-65
Fast Retransmit
Time-out period often relatively long
long delay before resending lost packet
Detect lost segments via duplicate ACKs
Sender often sends many segments back-to-backIf segment is lost there will likely be many duplicate ACKs
If sender receives 3 ACKs for the same data it supposes that segment after ACKeddata was lost
fast retransmit resend segment before timer expires
Transport Layer 3-66
Fast RetransmitResend a segment after 3 duplicate ACKs since a duplicate ACK means that an out-of sequence segment was receivedduplicate ACKs due to packet reorderingif window is small donrsquot get duplicate ACKs
Host A
tim
eout
Host B
time
X
resend seq X2
seq x1seq x2seq x3seq x4seq x5
ACK x1
ACK x1ACK x1ACK x1
tripleduplicate
ACKs
Transport Layer 3-67
event ACK received with ACK field value of y if (y gt SendBase)
SendBase = yif (there are currently not-yet-acknowledged segments)
start timer
else increment count of dup ACKs received for yif (count of dup ACKs received for y = 3)
resend segment with sequence number y
Fast retransmit algorithm
a duplicate ACK for already ACKed segment
fast retransmit
Transport Layer 3-68
TCP Flow Control
receive side of TCP connection has a receive buffer
speed-matching service matching the send rate to the receiving apprsquos drain rate
app process may be slow at reading from buffer
sender wonrsquot overflowreceiverrsquos buffer by
transmitting too muchtoo fast
flow control
Transport Layer 3-69
TCP Flow control how it works
(Suppose TCP receiver discards out-of-order segments)spare room in buffer
= RcvWin
= RcvBuffer-[LastByteRcvd -LastByteRead]
Rcvr advertises spare room by including value of RcvWin in segmentsSender limits unACKeddata to RcvWin
guarantees receive buffer doesnrsquot overflow
Transport Layer 3-70
Sliding Window Flow Control Example
3K
2K SeqNo=0
ReceiverBuffer
0 4KSendersends 2Kof data
2K
AckNo=2048 RcvWin=2048Sendersends 2Kof data 2K SeqNo=2048
4K
AckNo=4096 RcvWin=0
AckNo=4096 RcvWin=1024
Sender blocked
Transport Layer 3-71
Principles of Congestion Control
Congestioninformally ldquotoo many sources sending too much data too fast for network to handlerdquodifferent from flow controlmanifestations
lost packets (buffer overflow at routers)long delays (queueing in router buffers)
a top-10 problem
Transport Layer 3-72
Causescosts of congestion scenario 1
two senders two receiversone router infinite buffers no retransmission
large delays when congestedmaximum achievable throughput
unlimited shared output link buffers
Host Aλin original data
Host B
λout
Transport Layer 3-73
Causescosts of congestion scenario 2
one router finite buffers sender retransmission of lost packet
finite shared output link buffers
Host A λin original data
Host B
λout
λin original data plus retransmitted data
Transport Layer 3-74
Causescosts of congestion scenario 2always (goodput)ldquoperfectrdquo retransmission only when loss
retransmission of delayed (not lost) packet makes larger(than perfect case) for same
λin
λout=
λin
λoutgtλ
inλout
ldquocostsrdquo of congestionmore work (retrans) for given ldquogoodputrdquounneeded retransmissions link carries multiple copies of pkt
R2
R2λin
λ out
b
R2
R2λin
λ out
a
R2
R2λin
λ out
c
R4
R3
Transport Layer 3-75
Causescosts of congestion scenario 3four sendersmultihop pathstimeoutretransmit
λin
Q what happens as and increase λ
in
finite shared output link buffers
Host Aλin original data
Host B
λout
λin original data plus retransmitted data
Transport Layer 3-76
Causescosts of congestion scenario 3
another ldquocostrdquo of congestionwhen packet dropped any ldquoupstream transmission capacity used for that packet was wasted
Host A
Host B
λou
t
Transport Layer 3-77
Approaches towards congestion control
End-end congestion controlno explicit feedback from networkcongestion inferred from end-system observed loss delayapproach taken by TCP
Network-assisted congestion controlrouters provide feedback to end systems
single bit indicating congestion (SNA DECbit TCPIP ECN ATM)explicit rate sender should send at
Two broad approaches towards congestion control
Transport Layer 3-78
TCP Congestion Control
end-end control (no network assistance)sender limits transmissionLastByteSent-LastByteAcked
le CongWin
CongWin is dynamic function of perceived network congestion
How does sender perceive congestionloss event = timeout or3 duplicate acksTCP sender reduces rate (CongWin) after loss event
two modes of operationSlow Start (SS)Congestion avoidance (CA) or Additive Increase Multiplicative Decrease (AIMD)
Transport Layer 3-79
TCP congestion control bandwidth probing
ldquoprobing for bandwidthrdquo increase transmission rate on receipt of ACK until eventually loss occurs then decrease transmission rate
continue to increase on ACK decrease on loss (since available bandwidth is changing depending on other connections in network)
ACKs being received so increase rate
X
X
XX
X loss so decrease rate
send
ing
rate
time
Q how fast to increasedecreasedetails to follow
TCPrsquosldquosawtoothrdquobehavior
Transport Layer 3-80
TCP Congestion Control details
sender limits rate by limiting number of unACKed bytes ldquoin pipelinerdquo
cwnd differs from rwnd (how why)sender limited by min(cwndrwnd)
roughly
cwnd is dynamic function of perceived network congestion
rate = cwndRTT bytessec
LastByteSent-LastByteAcked le cwnd
cwndbytes
RTT
ACK(s)
Transport Layer 3-81
TCP Congestion Control more details
segment loss event reducing cwndtimeout no response from receiver
cut cwnd to 13 duplicate ACKs at least some segments getting through (recall fast retransmit)
cut cwnd in half less aggressively than on timeout
ACK received increase cwndTwo modes of operation
slowstart phase bull increase exponentially
fast (despite name) at connection start or following timeout
congestion avoidance bull increase linearly
Transport Layer 3-82
TCP Slow Start Phasewhen connection begins cwnd = 1 MSS
example MSS = 500 bytes amp RTT = 200 msecinitial rate = 20 kbps
available bandwidth may be gtgt MSSRTT
desirable to quickly ramp up to respectable rate
increase rate exponentially until first loss event or when threshold reached
double cwnd every RTTdone by incrementing cwnd by 1 for every ACK received
Host A
one segment
RTT
Host B
time
two segments
four segments
Transport Layer 3-83
Slow Start ExampleThe congestion window size grows very rapidly
For every ACK we increase CongWin by 1 irrespective of the number of segments ACKrsquoeddouble CongWinevery RTTinitial rate is slow but ramps up exponentially fast
TCP slows down the increase of CongWinwhen CongWin gt ssthresh
segment 1
ACK for segment 1
cwnd = 1
cwnd = 2 segment 2segment 3
ACK for segments 2
cwnd = 4 segment 4segment 5segment 6
ACK for segments 4
cwnd = 7
ACK for segments 3
ACK for segments 5
ACK for segments 6
cwnd = 3
cwnd = 5
cwnd = 6ACK for segments 7
cwnd = 8
segment 7
Transport Layer 3-84
TCP Congestion Avoidance Phase
when cwnd gt ssthreshgrow cwnd linearly
increase cwnd by 1 MSS per RTT approach possible congestion slower than in slowstartimplementation cwnd= cwnd + MSScwndfor each ACK received
ACKs increase cwndby 1 MSS per RTT additive increaseloss cut cwnd in half (non-timeout-detected loss ) multiplicative decrease
AIMD
AIMD Additive IncreaseMultiplicative Decrease
Transport Layer 3-85
Congestion AvoidanceCongestion avoidance phase is started if CongWin has reached the slow-start threshold value
If CongWin gt= ssthresh then each time an ACK is received increment CongWin as follows
bull CongWin = CongWin + 1CongWin (CongWin in segments)
bull In actual TCP implementation CongWin is in BytesCongWin = CongWin + MSS (MSSCongWin)
So CongWin is increased by one only if all CongWinsegments have been acknowledged
Transport Layer 3-86
Example Slow StartCongestion AvoidanceAssume that
ssthresh = 8
cwnd = 1
cwnd = 2
cwnd = 4
cwnd = 8
cwnd = 9
cwnd = 10
02468
101214
t=0
t=2
t=4
t=6
Roundtrip times
Cw
nd(in
seg
men
ts)
ssthresh
cwnd = 3
cwnd = 5cwnd = 6cwnd = 7
Transport Layer 3-87
Slow Start Congestion AvoidanceA typical plot of CongWin for a TCP connection
(MSS = 1500 bytes) with TCP Tahoe
SS
CA
ssthresh
Transport Layer 3-88
Responses to CongestionTCP assumes there is congestion if it detects a packet lossA TCP sender can detect lost packets via loss events
bull Timeout of a retransmission timerbull Receipt of 3 duplicate ACKs (fast retransmit)
TCP interprets a Timeout as a binary congestion signal When a timeout occurs the sender performs
ssthresh is set to half the current size of the congestion window
ssthresh = CongWin 2CongWin is reset to one
CongWin = 1and slow-start is entered
Transport Layer 3-89
Fast Recovery (differentiation btwn two loss events) After 3 dup ACKs (fast Retransmit)
ssthresh = CongWin2CongWin = CongWin2window then grows linearly
But after timeout eventCongWin = 1 MSS window then grows exponentiallyto the threshold then grows linearly
bull 3 dup ACKs indicates network capable of delivering some segmentsbull timeout before 3 dup ACKs is ldquomore alarmingrdquo
Philosophy
3-90
TCP Congestion ControlInitially
CongWin = 1ssthresh = advertised window size
New Ack receivedif (CongWin lt ssthresh) Slow Start
CongWin = CongWin + 1else Congestion Avoidance
CongWin = CongWin + 1CongWinTimeout
ssthresh = CongWin2CongWin = 1
Fast Retransmissionssthresh = CongWin2CongWin = CongWin2
Slow Start (exponential increase phase) is continued until CongWin reaches half of the level where the loss event occurred last time CongWin is increased slowly after (linear increase in Congestion Avoidance phase)
Transport Layer 3-91
Popular ldquoflavorsrdquo of TCP
ssthresh
ssthresh
TCP Tahoe
TCP Reno
Transmission round
cwnd
win
dow
siz
e (in
seg
men
ts)
Transport Layer 3-92
Summary TCP Congestion ControlWhen CongWin is below Threshold sender in slow-start phase window grows exponentiallyWhen CongWin is above Threshold sender is in congestion-avoidance phase window grows linearlyWhen a triple duplicate ACK occurs Threshold set to CongWin2 and CongWin set to ThresholdWhen timeout occurs Threshold set to CongWin2 and CongWin is set to 1 MSS The actual sender window size is determined based on the congestion and flow control algorithms
SenderWin=min(RcvWinCongWin)
Transport Layer 3-93
TCP Congestion Control SummaryEvent State TCP Sender Action Commentary
ACK receipt for previously unackeddata
Slow Start (SS)
CongWin = CongWin + MSS If (CongWin gt Threshold)
set state to ldquoCongestion Avoidancerdquo
Resulting in a doubling of CongWin every RTT
ACK receipt for previously unackeddata
CongestionAvoidance (CA)
CongWin = CongWin+MSS (MSSCongWin)
Additive increase resulting in increase of CongWin by 1 MSS every RTT
Loss event detected by triple duplicate ACK
SS or CA Threshold = CongWin2 CongWin = ThresholdSet state to ldquoCongestion Avoidancerdquo
Fast recovery implementing multiplicative decrease CongWin will not drop below 1 MSS
Timeout SS or CA Threshold = CongWin2 CongWin = 1 MSSSet state to ldquoSlow Startrdquo
Enter slow start
Duplicate ACK
SS or CA Increment duplicate ACK count for segment being acked
CongWin and Threshold not changed
Transport Layer 3-94
TCP throughput
Q whatrsquos average throughout of TCP as function of window size RTT
ignoring slow startlet W be window size when loss occurs
when window is W throughput is WRTTjust after loss window drops to W2 throughput to W2RTT average throughout 75 WRTT
Transport Layer 3-95
TCP Futures TCP over ldquolong fat pipesrdquo
example 1500 byte segments 100ms RTT want 10 Gbps throughputrequires window size W = 83333 in-flight segmentsthroughput in terms of loss rate
L = 210-10 Wownew versions of TCP for high-speed
LRTTMSSsdot221
Transport Layer 3-96
Fairness goal if K TCP sessions share same bottleneck link of bandwidth R each should have average rate of RK
TCP connection 1
bottleneckrouter
capacity R
TCP connection 2
TCP Fairness
Transport Layer 3-97
Why is TCP fairTwo competing sessions
Additive increase gives slope of 1 as throughout increasesmultiplicative decrease decreases throughput proportionally
R
R
equal bandwidth share
Connection 1 throughput
Conn
ecti
on 2
thr
ough
p ut
congestion avoidance additive increaseloss decrease window by factor of 2
congestion avoidance additive increaseloss decrease window by factor of 2
Transport Layer 3-98
Fairness (more)Fairness and UDP
Multimedia apps often do not use TCP
do not want rate throttled by congestion control
Instead use UDPpump audiovideo at constant rate tolerate packet loss
Research area TCP friendly
Fairness and parallel TCP connectionsnothing prevents app from opening parallel cnctionsbetween 2 hostsWeb browsers do this Example link of rate R supporting 9 cnctions
new app asks for 1 TCP gets rate R10new app asks for 11 TCPs gets R2
Transport Layer 3-99
TCP Connection ManagementRecall TCP sender receiver
establish ldquoconnectionrdquobefore exchanging data segmentsinitialize TCP variables
seq sbuffers flow control info (eg RcvWindow)
client connection initiatorSocket clientSocket = new Socket(hostnameport
number)
server contacted by clientSocket connectionSocket = welcomeSocketaccept()
Three way handshakeStep 1 client host sends TCP
SYN segment to serverspecifies initial seq no data
Step 2 server host receives SYN replies with SYNACK segment
server allocates buffersspecifies server initial seq
Step 3 client receives SYNACK replies with ACK segment which may contain data
Transport Layer 3-100
TCP Connection Management (cont)
Closing a connection
client closes socketclientSocketclose()
Step 1 client end system sends TCP FIN control segment to server
Step 2 server receives FIN replies with ACK Closes connection sends FIN
client
FIN
server
ACK
ACK
FIN
close
close
closed
tim
ed w
ait
Transport Layer 3-101
TCP Connection Management (cont)
Step 3 client receives FIN replies with ACK
Enters ldquotimed waitrdquo -will respond with ACK to received FINs
Step 4 server receives ACK Connection closed
client
FIN
server
ACK
ACK
FIN
closing
closing
closed
tim
ed w
ait
closed
Transport Layer 3-102
TCP Connection Management (cont)
TCP clientlifecycle
TCP serverlifecycle
Transport Layer 3-103
Tuning TCPIP Parameters TCPIP parameters
A set of default values may not be optimal for all applicationsThe network administrator may wish to turn on or off some TCPIP functions for performance or security considerations
Many Unix and Linux systems provide some flexibility in tuning the TCPIP kernelsbinsysctl is used to configure the Linux kernel parameters at runtime
Default kernel configuration file is sbinsysctlconfFrequently used sysctl options
bull sysctl ndasha or sysctl ndashA list all current valuesbull sysctl ndashp file_name load the sysctl setting from a configuration
filebull sysctl ndashw variable=value change the value of the parameter
Transport Layer 3-104
SomeTCP Parameters in Linux Kerneltcp_syn_retries
Number of SYN packets the kernel will send before giving up on the new connection
tcp_synack_retriesnumber of SYN+ACK packets sent before the kernel gives up on the connection
tcp_window_scalingMaximum window size of 65535 bytes not enough for for really fast networks The window scaling options allows for almost gigabyte windows which is good for connections with large delay-bandwidth product
tcp_max_syn_backlogMaximal number of remembered connection requests which still did not receive an acknowledgment from connecting client
tcp_fin_timeoutHow many seconds to wait for a final FIN packet before the socket is closed required to prevent denial-of-service (DoS) attacks Default value is 60 seconds
Transport Layer 3-105
SomeTCP Parameters in Linux Kerneltcp_rmem
This is a vector of 3 integers [min default max] These parameters are used by TCP to dynamically adjust receive buffer sizesmin - minimum size of the receive buffer used by each TCP socket The default value is 4K default - the default size of the receive buffer for a TCP socket The default value is 87380 bytes and is lowered to 43689 in low memory systems If larger receive buffer sizes are desired this value should be increased max - the maximum size of the receive buffer used by each TCP socket The default value of 873802 bytes is lowered to 87380 in low memory systems
tcp_smemSend buffer parameters [min default max] similar to tcp_rmem
- Chapter 3 Transport Layer
- Transport services and protocols
- Transport vs network layer
- Internet transport-layer protocols
- Multiplexingdemultiplexing
- How demultiplexing works
- Connectionless demultiplexing
- Connection-oriented demux
- Connection-oriented demux (cont)
- Connection-oriented demux Threaded Web Server
- UDP User Datagram Protocol [RFC 768]
- UDP more
- UDP checksum
- Principles of Reliable data transfer
- Reliable data transfer getting started
- Reliable data transfer getting started
- Rdt10 reliable transfer over a reliable channel
- Rdt20 channel with bit errors
- rdt20 FSM specification
- rdt20 operation with no errors
- rdt20 error scenario
- rdt20 has a fatal flaw
- rdt21 sender handles garbled ACKNAKs
- rdt21 receiver handles garbled ACKNAKs
- rdt21 discussion
- rdt22 a NAK-free protocol
- rdt22 sender receiver fragments
- rdt30 channels with errors and loss
- rdt30 sender
- rdt30 in action
- rdt30 in action
- Performance of rdt30
- rdt30 stop-and-wait operation
- Pipelined protocols
- Pipelining increased utilization
- Go-Back-N
- GBN sender extended FSM
- GBN receiver extended FSM
- GBN inaction
- Selective Repeat
- Selective repeat sender receiver windows
- Selective repeat
- Selective repeat in action
- Selective repeat dilemma
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- TCP Overview RFCs 793 1122 1323 2018 2581
- TCP segment structure
- TCP seq rsquos and ACKs
- TCP Round Trip Time and Timeout
- TCP Round Trip Time and Timeout
- Example RTT estimation
- TCP Round Trip Time and Timeout
- TCP reliable data transfer
- TCP sender events
- TCP sender(simplified)
- TCP retransmission scenarios
- TCP retransmission scenarios (more)
- TCP ACK generation [RFC 1122 RFC 2581]
- Fast Retransmit
- Fast Retransmit
- Fast retransmit algorithm
- TCP Flow Control
- TCP Flow control how it works
- Sliding Window Flow Control Example
- Principles of Congestion Control
- Causescosts of congestion scenario 1
- Causescosts of congestion scenario 2
- Causescosts of congestion scenario 2
- Causescosts of congestion scenario 3
- Causescosts of congestion scenario 3
- Approaches towards congestion control
- TCP Congestion Control
- TCP congestion control bandwidth probing
- TCP Congestion Control details
- TCP Congestion Control more details
- TCP Slow Start Phase
- Slow Start Example
- TCP Congestion Avoidance Phase
- Congestion Avoidance
- Example Slow StartCongestion Avoidance
- Slow Start Congestion Avoidance
- Responses to Congestion
- Fast Recovery (differentiation btwn two loss events)
- TCP Congestion Control
- Popular ldquoflavorsrdquo of TCP
- Summary TCP Congestion Control
- TCP Congestion Control Summary
- TCP throughput
- TCP Futures TCP over ldquolong fat pipesrdquo
- TCP Fairness
- Why is TCP fair
- Fairness (more)
- TCP Connection Management
- TCP Connection Management (cont)
- TCP Connection Management (cont)
- TCP Connection Management (cont)
- Tuning TCPIP Parameters
- SomeTCP Parameters in Linux Kernel
- SomeTCP Parameters in Linux Kernel
-
Transport Layer 3-33
rdt30 stop-and-wait operation
first packet bit transmitted t = 0
sender receiver
RTT
last packet bit transmitted t = L R
first packet bit arriveslast packet bit arrives send ACK
ACK arrives send next packet t = RTT + L R
U sender=
00830008
= 000027 L RRTT + L R
=
Transport Layer 3-34
Pipelined protocolsPipelining sender allows multiple ldquoin-flightrdquo yet-to-
be-acknowledged pktsrange of sequence numbers must be increasedbuffering at sender andor receiver
Two generic forms of pipelined protocols go-Back-N selective repeat
Transport Layer 3-35
Pipelining increased utilization
first packet bit transmitted t = 0
sender receiver
RTT
last bit transmitted t = L R
first packet bit arriveslast packet bit arrives send ACK
ACK arrives send next packet t = RTT + L R
last bit of 2nd packet arrives send ACKlast bit of 3rd packet arrives send ACK
U sender=
024 30008
= 000083 L RRTT + L R
=
Increase utilizationby a factor of 3
Transport Layer 3-36
Utilization=N(LR)(RTT+LR) if NLRltRTT+LR Utilization=1 if and the sender pauses after it transmits a window NLRgtRTT+LR and the of packets until it receives first ACK sender does not pause
Transport Layer 3-37
Go-Back-NSender
k-bit seq in pkt headerldquowindowrdquo of up to N consecutive unackrsquoed pkts allowed
ACK(n) ACKs all pkts up to including seq n - ldquocumulative ACKrdquomay receive duplicate ACKs (see receiver)
timer for the entire windowtimeout(n) retransmit pkt n and all higher seq pkts in window
Transport Layer 3-38
GBN sender extended FSM
Wait start_timerudt_send(sndpkt[base])udt_send(sndpkt[base+1])hellipudt_send(sndpkt[nextseqnum-1])
timeout
rdt_send(data)
if (nextseqnum lt base+N) sndpkt[nextseqnum] = make_pkt(nextseqnumdatachksum)udt_send(sndpkt[nextseqnum])if (base == nextseqnum)
start_timernextseqnum++
elserefuse_data(data)
base = getacknum(rcvpkt)+1If (base == nextseqnum)
stop_timerelse
start_timer
rdt_rcv(rcvpkt) ampamp notcorrupt(rcvpkt)
base=1nextseqnum=1
rdt_rcv(rcvpkt) ampamp corrupt(rcvpkt)
Λ
Λ
Transport Layer 3-39
GBN receiver extended FSM
ACK-only always send ACK for correctly-received pktwith highest in-order seq
may generate duplicate ACKsneed only remember expectedseqnum
out-of-order pkt discard (donrsquot buffer) -gt no receiver bufferingRe-ACK pkt with highest in-order seq
Wait
udt_send(sndpkt)default
rdt_rcv(rcvpkt)ampamp notcurrupt(rcvpkt)ampamp hasseqnum(rcvpktexpectedseqnum)
extract(rcvpktdata)deliver_data(data)sndpkt = make_pkt(expectedseqnumACKchksum)udt_send(sndpkt)expectedseqnum++
expectedseqnum=1sndpkt =
make_pkt(0ACKchksum)
Λ
Transport Layer 3-40
GBN inaction
Transport Layer 3-41
Selective Repeat
receiver individually acknowledges all correctly received pkts
buffers pkts as needed for eventual in-order delivery to upper layer
sender only resends pkts for which ACK not received
sender timer for each unACKed pktsender window
N consecutive seq rsquosagain limits seq s of sent unACKed pkts
Transport Layer 3-42
Selective repeat sender receiver windows
Transport Layer 3-43
Selective repeat
data from above if next available seq in window send pkt
timeout(n)resend pkt n restart timer
ACK(n) in [sendbasesendbase+N-1]
mark pkt n as receivedif n smallest unACKed pkt advance window base to next unACKed seq
senderpkt n in [rcvbase rcvbase+N-1]
send ACK(n)out-of-order bufferin-order deliver (also deliver buffered in-order pkts) advance window to next not-yet-received pkt
pkt n in [rcvbase-Nrcvbase-1]
ACK(n)otherwise
ignore
receiver
Transport Layer 3-44
Selective repeat in action
Transport Layer 3-45
Selective repeatdilemma
Example seq rsquos 0 1 2 3window size=3
receiver sees no difference in two scenariosincorrectly passes duplicate data as new in (a)
Q what relationship between seq size and window size
Transport Layer 3-46
Sequence Number vs Window SizeSuppose we use k bits to represent SNQuestion Whatrsquos the minimum number of bits k necessary for a window size of N
sender
receiver
Go-Back-N
expectedSN
snd_base=expectedSN
Q For a given expectedSN whatrsquos the largest possible value for snd_baseA If all the last N ACKs sent by the receiver are received
snd_base = expectedSNexpectedSN+N-1
senderrsquos window
Transport Layer 3-47
Sequence Number vs Window SizeSuppose we use k bits to represent SNQuestion Whatrsquos the minimum number of bits k necessary for a window size of N
sender
receiver
Go-Back-N
expectedSN
snd_base=expectedSN-N
Q For a given expectedSN whatrsquos the smallest possible value for snd_baseA If all the last N ACKs sent by the receiver are not received
snd_base = expectedSN-NexpectedSN-1
senderrsquos window
Transport Layer 3-48
Sequence Number vs Window Size
sender
receiver
Go-Back-N
expectedSN
snd_base=expectedSN-N
All SNs in the interval [expectedSN-NexpectedSN+N-1] (an interval of size 2N) can be received by the receiver Since the receiver accepts on the packet with SN=expectedSN there should be no other packet within this interval with SN=expectedSN Therefore
2k ge N+1expectedSN+N-1
Transport Layer 3-49
Sequence Number vs Window SizeSuppose we use k bits to represent SNQuestion Whatrsquos the minimum number of bits k necessary for a window size of N
sender
receiver
Selective Repeat
rcv_base
snd_base=rcv_base
Q For a given rcv_base whatrsquos the largest possible value for snd_baseA If all the last N ACKs sent by the receiver are received
snd_base = rcv_base (same as go_back-N)rcv_base+N-1
senderrsquos window
receiverrsquos window
rcv_base+N-1
Transport Layer 3-50
Sequence Number vs Window SizeSuppose we use k bits to represent SNQuestion Whatrsquos the minimum number of bits k necessary for a window size of N
sender
receiver
Selective Repeat
rcv_base
snd_base=rcv_base-N
Q For a given rcv_base whatrsquos the smallest possible value for snd_baseA If all the last N ACKs sent by the receiver are not received
snd_base = rcv_base-N (same as Go-Back-N)rcv_base-1
senderrsquos window
rcv_base
receiverrsquos window
rcv_base+N-1
Transport Layer 3-51
Sequence Number vs Window Size
sender
receiver
Selective Repeat
snd_base=rcv_base-N
All SNs in the interval [rcv_base-Nrcv_base+N-1] (an interval of size 2N) can be received by the receiver Since the receiver should be able to distinguish between all packets in this interval and take corresponding action there should be no two packets within thisinterval having the same SN Therefore
2k ge 2Nrcv_base+N-1
rcv_basercv_base
receiverrsquos window
rcv_base+N-1
Transport Layer 3-52
TCP Overview RFCs 793 1122 1323 2018 2581
full duplex databi-directional data flow in same connectionMSS maximum segment size
connection-orientedhandshaking (exchange of control msgs) initrsquossender receiver state before data exchange
flow controlledsender will not overwhelm receiver
point-to-pointone sender one receiver
reliable in-order byte stream
no ldquomessage boundariesrdquopipelined
TCP congestion and flow control set window size
send amp receive buffers
socketdoor
TCPsend buffer
TCPreceive buffer
socketdoor
segment
applicationwrites data
applicationreads data
Transport Layer 3-53
TCP segment structure
source port dest port
32 bits
applicationdata
(variable length)
sequence numberacknowledgement number
Receive windowUrg data pnterchecksum
FSRPAUheadlen
notused
Options (variable length)
URG urgent data (generally not used)
ACK ACK valid
PSH push data now(generally not used)
RST SYN FINconnection estab(setup teardown
commands)
bytes rcvr willingto accept
Internetchecksum
(as in UDP)
countingby bytes of data(not segments)
Transport Layer 3-54
TCP seq rsquos and ACKsSeq rsquos
byte stream ldquonumberrdquo of first byte in segmentrsquos dataACKs
seq of next byte expected from other sidecumulative ACK
Q how receiver handles out-of-order segmentsA TCP spec doesnrsquot say - up to implementationWidely used implementations of TCP buffer out-of-order segments
Transport Layer 3-55
TCP Round Trip Time and Timeout
Q how to set TCP timeout valuelonger than RTT
but RTT variestoo short premature timeout
unnecessary retransmissions
too long slow reaction to segment loss
Q how to estimate RTTSampleRTT measured time from segment transmission until ACK receipt
ignore retransmissionsSampleRTT will vary want estimated RTT ldquosmootherrdquo
average several recent measurements not just current SampleRTT
Transport Layer 3-56
TCP Round Trip Time and Timeout
EstimatedRTT = (1- α)EstimatedRTT + αSampleRTT
Exponential weighted moving averageinfluence of past sample decreases exponentially fasttypical value α = 0125
Transport Layer 3-57
Example RTT estimationRTT gaiacsumassedu to fantasiaeurecomfr
100
150
200
250
300
350
1 8 15 22 29 36 43 50 57 64 71 78 85 92 99 106
time (seconnds)
RTT
(mill
iseco
nds)
SampleRTT Estimated RTT
Transport Layer 3-58
TCP Round Trip Time and TimeoutSetting the timeout
EstimatedRTT plus ldquosafety marginrdquolarge variation in EstimatedRTT -gt larger safety margin
first estimate of how much SampleRTT deviates from EstimatedRTT
TimeoutInterval = EstimatedRTT + 4DevRTT
DevRTT = (1-β)DevRTT +β|SampleRTT-EstimatedRTT|
(typically β = 025)
Then set timeout interval
Transport Layer 3-59
TCP reliable data transfer
TCP creates rdtservice on top of IPrsquos unreliable servicePipelined segmentsCumulative acksTCP uses single retransmission timer however it just retransmits the first segment in the window
Retransmissions are triggered by
timeout eventsduplicate acks
Initially consider simplified TCP sender
ignore duplicate acksignore flow control congestion control
Transport Layer 3-60
TCP sender eventsdata rcvd from app
Create segment with seq seq is byte-stream number of first data byte in segmentstart timer if not already running (think of timer as for oldest unacked segment)expiration interval TimeOutInterval
timeoutretransmit segment that caused timeout (first segment in the window)restart timer
Ack rcvdIf acknowledges previously unacked segments
update what is known to be ackedstart timer if there are outstanding segments
Transport Layer 3-61
TCP sender(simplified)
NextSeqNum = InitialSeqNumSendBase = InitialSeqNum
loop (forever) switch(event)
event data received from application above create TCP segment with sequence number NextSeqNumif (timer currently not running)
start timerpass segment to IP NextSeqNum = NextSeqNum + length(data)
event timer timeoutretransmit not-yet-acknowledged segment with
smallest sequence numberstart timer
event ACK received with ACK field value of y if (y gt SendBase)
SendBase = yif (there are currently not-yet-acknowledged segments)
start timer
end of loop forever
Commentbull SendBase-1 last cumulatively ackrsquoed byteExamplebull SendBase-1 = 71y= 73 so the rcvrwants 73+ y gt SendBase sothat new data is acked
Transport Layer 3-62
TCP retransmission scenariosHost A
Seq=100 20 bytes data
ACK=100
timepremature timeout
Host B
Seq=92 8 bytes data
ACK=120
Seq=92 8 bytes data
Seq=
92 t
imeo
ut
ACK=120
Host A
Seq=92 8 bytes data
ACK=100
loss
tim
eout
lost ACK scenario
Host B
X
Seq=92 8 bytes data
ACK=100
time
Seq=
92 t
imeo
utSendBase
= 100
SendBase= 120
SendBase= 120
Sendbase= 100
Transport Layer 3-63
TCP retransmission scenarios (more)Host A
Seq=92 8 bytes data
ACK=100
loss
tim
eout
Cumulative ACK scenario
Host B
X
Seq=100 20 bytes data
ACK=120
time
SendBase= 120
Transport Layer 3-64
TCP ACK generation [RFC 1122 RFC 2581]
Event at Receiver
Arrival of in-order segment withexpected seq All data up toexpected seq already ACKed
Arrival of in-order segment withexpected seq One other segment has ACK pending
Arrival of out-of-order segmenthigher-than-expect seq Gap detected
Arrival of segment that partially or completely fills gap
TCP Receiver action
Delayed ACK Wait up to 500msfor next segment If no next segmentsend ACK
Immediately send single cumulative ACK ACKing both in-order segments
Immediately send duplicate ACK indicating seq of next expected byte
Immediate send ACK provided thatsegment startsat lower end of gap
Transport Layer 3-65
Fast Retransmit
Time-out period often relatively long
long delay before resending lost packet
Detect lost segments via duplicate ACKs
Sender often sends many segments back-to-backIf segment is lost there will likely be many duplicate ACKs
If sender receives 3 ACKs for the same data it supposes that segment after ACKeddata was lost
fast retransmit resend segment before timer expires
Transport Layer 3-66
Fast RetransmitResend a segment after 3 duplicate ACKs since a duplicate ACK means that an out-of sequence segment was receivedduplicate ACKs due to packet reorderingif window is small donrsquot get duplicate ACKs
Host A
tim
eout
Host B
time
X
resend seq X2
seq x1seq x2seq x3seq x4seq x5
ACK x1
ACK x1ACK x1ACK x1
tripleduplicate
ACKs
Transport Layer 3-67
event ACK received with ACK field value of y if (y gt SendBase)
SendBase = yif (there are currently not-yet-acknowledged segments)
start timer
else increment count of dup ACKs received for yif (count of dup ACKs received for y = 3)
resend segment with sequence number y
Fast retransmit algorithm
a duplicate ACK for already ACKed segment
fast retransmit
Transport Layer 3-68
TCP Flow Control
receive side of TCP connection has a receive buffer
speed-matching service matching the send rate to the receiving apprsquos drain rate
app process may be slow at reading from buffer
sender wonrsquot overflowreceiverrsquos buffer by
transmitting too muchtoo fast
flow control
Transport Layer 3-69
TCP Flow control how it works
(Suppose TCP receiver discards out-of-order segments)spare room in buffer
= RcvWin
= RcvBuffer-[LastByteRcvd -LastByteRead]
Rcvr advertises spare room by including value of RcvWin in segmentsSender limits unACKeddata to RcvWin
guarantees receive buffer doesnrsquot overflow
Transport Layer 3-70
Sliding Window Flow Control Example
3K
2K SeqNo=0
ReceiverBuffer
0 4KSendersends 2Kof data
2K
AckNo=2048 RcvWin=2048Sendersends 2Kof data 2K SeqNo=2048
4K
AckNo=4096 RcvWin=0
AckNo=4096 RcvWin=1024
Sender blocked
Transport Layer 3-71
Principles of Congestion Control
Congestioninformally ldquotoo many sources sending too much data too fast for network to handlerdquodifferent from flow controlmanifestations
lost packets (buffer overflow at routers)long delays (queueing in router buffers)
a top-10 problem
Transport Layer 3-72
Causescosts of congestion scenario 1
two senders two receiversone router infinite buffers no retransmission
large delays when congestedmaximum achievable throughput
unlimited shared output link buffers
Host Aλin original data
Host B
λout
Transport Layer 3-73
Causescosts of congestion scenario 2
one router finite buffers sender retransmission of lost packet
finite shared output link buffers
Host A λin original data
Host B
λout
λin original data plus retransmitted data
Transport Layer 3-74
Causescosts of congestion scenario 2always (goodput)ldquoperfectrdquo retransmission only when loss
retransmission of delayed (not lost) packet makes larger(than perfect case) for same
λin
λout=
λin
λoutgtλ
inλout
ldquocostsrdquo of congestionmore work (retrans) for given ldquogoodputrdquounneeded retransmissions link carries multiple copies of pkt
R2
R2λin
λ out
b
R2
R2λin
λ out
a
R2
R2λin
λ out
c
R4
R3
Transport Layer 3-75
Causescosts of congestion scenario 3four sendersmultihop pathstimeoutretransmit
λin
Q what happens as and increase λ
in
finite shared output link buffers
Host Aλin original data
Host B
λout
λin original data plus retransmitted data
Transport Layer 3-76
Causescosts of congestion scenario 3
another ldquocostrdquo of congestionwhen packet dropped any ldquoupstream transmission capacity used for that packet was wasted
Host A
Host B
λou
t
Transport Layer 3-77
Approaches towards congestion control
End-end congestion controlno explicit feedback from networkcongestion inferred from end-system observed loss delayapproach taken by TCP
Network-assisted congestion controlrouters provide feedback to end systems
single bit indicating congestion (SNA DECbit TCPIP ECN ATM)explicit rate sender should send at
Two broad approaches towards congestion control
Transport Layer 3-78
TCP Congestion Control
end-end control (no network assistance)sender limits transmissionLastByteSent-LastByteAcked
le CongWin
CongWin is dynamic function of perceived network congestion
How does sender perceive congestionloss event = timeout or3 duplicate acksTCP sender reduces rate (CongWin) after loss event
two modes of operationSlow Start (SS)Congestion avoidance (CA) or Additive Increase Multiplicative Decrease (AIMD)
Transport Layer 3-79
TCP congestion control bandwidth probing
ldquoprobing for bandwidthrdquo increase transmission rate on receipt of ACK until eventually loss occurs then decrease transmission rate
continue to increase on ACK decrease on loss (since available bandwidth is changing depending on other connections in network)
ACKs being received so increase rate
X
X
XX
X loss so decrease rate
send
ing
rate
time
Q how fast to increasedecreasedetails to follow
TCPrsquosldquosawtoothrdquobehavior
Transport Layer 3-80
TCP Congestion Control details
sender limits rate by limiting number of unACKed bytes ldquoin pipelinerdquo
cwnd differs from rwnd (how why)sender limited by min(cwndrwnd)
roughly
cwnd is dynamic function of perceived network congestion
rate = cwndRTT bytessec
LastByteSent-LastByteAcked le cwnd
cwndbytes
RTT
ACK(s)
Transport Layer 3-81
TCP Congestion Control more details
segment loss event reducing cwndtimeout no response from receiver
cut cwnd to 13 duplicate ACKs at least some segments getting through (recall fast retransmit)
cut cwnd in half less aggressively than on timeout
ACK received increase cwndTwo modes of operation
slowstart phase bull increase exponentially
fast (despite name) at connection start or following timeout
congestion avoidance bull increase linearly
Transport Layer 3-82
TCP Slow Start Phasewhen connection begins cwnd = 1 MSS
example MSS = 500 bytes amp RTT = 200 msecinitial rate = 20 kbps
available bandwidth may be gtgt MSSRTT
desirable to quickly ramp up to respectable rate
increase rate exponentially until first loss event or when threshold reached
double cwnd every RTTdone by incrementing cwnd by 1 for every ACK received
Host A
one segment
RTT
Host B
time
two segments
four segments
Transport Layer 3-83
Slow Start ExampleThe congestion window size grows very rapidly
For every ACK we increase CongWin by 1 irrespective of the number of segments ACKrsquoeddouble CongWinevery RTTinitial rate is slow but ramps up exponentially fast
TCP slows down the increase of CongWinwhen CongWin gt ssthresh
segment 1
ACK for segment 1
cwnd = 1
cwnd = 2 segment 2segment 3
ACK for segments 2
cwnd = 4 segment 4segment 5segment 6
ACK for segments 4
cwnd = 7
ACK for segments 3
ACK for segments 5
ACK for segments 6
cwnd = 3
cwnd = 5
cwnd = 6ACK for segments 7
cwnd = 8
segment 7
Transport Layer 3-84
TCP Congestion Avoidance Phase
when cwnd gt ssthreshgrow cwnd linearly
increase cwnd by 1 MSS per RTT approach possible congestion slower than in slowstartimplementation cwnd= cwnd + MSScwndfor each ACK received
ACKs increase cwndby 1 MSS per RTT additive increaseloss cut cwnd in half (non-timeout-detected loss ) multiplicative decrease
AIMD
AIMD Additive IncreaseMultiplicative Decrease
Transport Layer 3-85
Congestion AvoidanceCongestion avoidance phase is started if CongWin has reached the slow-start threshold value
If CongWin gt= ssthresh then each time an ACK is received increment CongWin as follows
bull CongWin = CongWin + 1CongWin (CongWin in segments)
bull In actual TCP implementation CongWin is in BytesCongWin = CongWin + MSS (MSSCongWin)
So CongWin is increased by one only if all CongWinsegments have been acknowledged
Transport Layer 3-86
Example Slow StartCongestion AvoidanceAssume that
ssthresh = 8
cwnd = 1
cwnd = 2
cwnd = 4
cwnd = 8
cwnd = 9
cwnd = 10
02468
101214
t=0
t=2
t=4
t=6
Roundtrip times
Cw
nd(in
seg
men
ts)
ssthresh
cwnd = 3
cwnd = 5cwnd = 6cwnd = 7
Transport Layer 3-87
Slow Start Congestion AvoidanceA typical plot of CongWin for a TCP connection
(MSS = 1500 bytes) with TCP Tahoe
SS
CA
ssthresh
Transport Layer 3-88
Responses to CongestionTCP assumes there is congestion if it detects a packet lossA TCP sender can detect lost packets via loss events
bull Timeout of a retransmission timerbull Receipt of 3 duplicate ACKs (fast retransmit)
TCP interprets a Timeout as a binary congestion signal When a timeout occurs the sender performs
ssthresh is set to half the current size of the congestion window
ssthresh = CongWin 2CongWin is reset to one
CongWin = 1and slow-start is entered
Transport Layer 3-89
Fast Recovery (differentiation btwn two loss events) After 3 dup ACKs (fast Retransmit)
ssthresh = CongWin2CongWin = CongWin2window then grows linearly
But after timeout eventCongWin = 1 MSS window then grows exponentiallyto the threshold then grows linearly
bull 3 dup ACKs indicates network capable of delivering some segmentsbull timeout before 3 dup ACKs is ldquomore alarmingrdquo
Philosophy
3-90
TCP Congestion ControlInitially
CongWin = 1ssthresh = advertised window size
New Ack receivedif (CongWin lt ssthresh) Slow Start
CongWin = CongWin + 1else Congestion Avoidance
CongWin = CongWin + 1CongWinTimeout
ssthresh = CongWin2CongWin = 1
Fast Retransmissionssthresh = CongWin2CongWin = CongWin2
Slow Start (exponential increase phase) is continued until CongWin reaches half of the level where the loss event occurred last time CongWin is increased slowly after (linear increase in Congestion Avoidance phase)
Transport Layer 3-91
Popular ldquoflavorsrdquo of TCP
ssthresh
ssthresh
TCP Tahoe
TCP Reno
Transmission round
cwnd
win
dow
siz
e (in
seg
men
ts)
Transport Layer 3-92
Summary TCP Congestion ControlWhen CongWin is below Threshold sender in slow-start phase window grows exponentiallyWhen CongWin is above Threshold sender is in congestion-avoidance phase window grows linearlyWhen a triple duplicate ACK occurs Threshold set to CongWin2 and CongWin set to ThresholdWhen timeout occurs Threshold set to CongWin2 and CongWin is set to 1 MSS The actual sender window size is determined based on the congestion and flow control algorithms
SenderWin=min(RcvWinCongWin)
Transport Layer 3-93
TCP Congestion Control SummaryEvent State TCP Sender Action Commentary
ACK receipt for previously unackeddata
Slow Start (SS)
CongWin = CongWin + MSS If (CongWin gt Threshold)
set state to ldquoCongestion Avoidancerdquo
Resulting in a doubling of CongWin every RTT
ACK receipt for previously unackeddata
CongestionAvoidance (CA)
CongWin = CongWin+MSS (MSSCongWin)
Additive increase resulting in increase of CongWin by 1 MSS every RTT
Loss event detected by triple duplicate ACK
SS or CA Threshold = CongWin2 CongWin = ThresholdSet state to ldquoCongestion Avoidancerdquo
Fast recovery implementing multiplicative decrease CongWin will not drop below 1 MSS
Timeout SS or CA Threshold = CongWin2 CongWin = 1 MSSSet state to ldquoSlow Startrdquo
Enter slow start
Duplicate ACK
SS or CA Increment duplicate ACK count for segment being acked
CongWin and Threshold not changed
Transport Layer 3-94
TCP throughput
Q whatrsquos average throughout of TCP as function of window size RTT
ignoring slow startlet W be window size when loss occurs
when window is W throughput is WRTTjust after loss window drops to W2 throughput to W2RTT average throughout 75 WRTT
Transport Layer 3-95
TCP Futures TCP over ldquolong fat pipesrdquo
example 1500 byte segments 100ms RTT want 10 Gbps throughputrequires window size W = 83333 in-flight segmentsthroughput in terms of loss rate
L = 210-10 Wownew versions of TCP for high-speed
LRTTMSSsdot221
Transport Layer 3-96
Fairness goal if K TCP sessions share same bottleneck link of bandwidth R each should have average rate of RK
TCP connection 1
bottleneckrouter
capacity R
TCP connection 2
TCP Fairness
Transport Layer 3-97
Why is TCP fairTwo competing sessions
Additive increase gives slope of 1 as throughout increasesmultiplicative decrease decreases throughput proportionally
R
R
equal bandwidth share
Connection 1 throughput
Conn
ecti
on 2
thr
ough
p ut
congestion avoidance additive increaseloss decrease window by factor of 2
congestion avoidance additive increaseloss decrease window by factor of 2
Transport Layer 3-98
Fairness (more)Fairness and UDP
Multimedia apps often do not use TCP
do not want rate throttled by congestion control
Instead use UDPpump audiovideo at constant rate tolerate packet loss
Research area TCP friendly
Fairness and parallel TCP connectionsnothing prevents app from opening parallel cnctionsbetween 2 hostsWeb browsers do this Example link of rate R supporting 9 cnctions
new app asks for 1 TCP gets rate R10new app asks for 11 TCPs gets R2
Transport Layer 3-99
TCP Connection ManagementRecall TCP sender receiver
establish ldquoconnectionrdquobefore exchanging data segmentsinitialize TCP variables
seq sbuffers flow control info (eg RcvWindow)
client connection initiatorSocket clientSocket = new Socket(hostnameport
number)
server contacted by clientSocket connectionSocket = welcomeSocketaccept()
Three way handshakeStep 1 client host sends TCP
SYN segment to serverspecifies initial seq no data
Step 2 server host receives SYN replies with SYNACK segment
server allocates buffersspecifies server initial seq
Step 3 client receives SYNACK replies with ACK segment which may contain data
Transport Layer 3-100
TCP Connection Management (cont)
Closing a connection
client closes socketclientSocketclose()
Step 1 client end system sends TCP FIN control segment to server
Step 2 server receives FIN replies with ACK Closes connection sends FIN
client
FIN
server
ACK
ACK
FIN
close
close
closed
tim
ed w
ait
Transport Layer 3-101
TCP Connection Management (cont)
Step 3 client receives FIN replies with ACK
Enters ldquotimed waitrdquo -will respond with ACK to received FINs
Step 4 server receives ACK Connection closed
client
FIN
server
ACK
ACK
FIN
closing
closing
closed
tim
ed w
ait
closed
Transport Layer 3-102
TCP Connection Management (cont)
TCP clientlifecycle
TCP serverlifecycle
Transport Layer 3-103
Tuning TCPIP Parameters TCPIP parameters
A set of default values may not be optimal for all applicationsThe network administrator may wish to turn on or off some TCPIP functions for performance or security considerations
Many Unix and Linux systems provide some flexibility in tuning the TCPIP kernelsbinsysctl is used to configure the Linux kernel parameters at runtime
Default kernel configuration file is sbinsysctlconfFrequently used sysctl options
bull sysctl ndasha or sysctl ndashA list all current valuesbull sysctl ndashp file_name load the sysctl setting from a configuration
filebull sysctl ndashw variable=value change the value of the parameter
Transport Layer 3-104
SomeTCP Parameters in Linux Kerneltcp_syn_retries
Number of SYN packets the kernel will send before giving up on the new connection
tcp_synack_retriesnumber of SYN+ACK packets sent before the kernel gives up on the connection
tcp_window_scalingMaximum window size of 65535 bytes not enough for for really fast networks The window scaling options allows for almost gigabyte windows which is good for connections with large delay-bandwidth product
tcp_max_syn_backlogMaximal number of remembered connection requests which still did not receive an acknowledgment from connecting client
tcp_fin_timeoutHow many seconds to wait for a final FIN packet before the socket is closed required to prevent denial-of-service (DoS) attacks Default value is 60 seconds
Transport Layer 3-105
SomeTCP Parameters in Linux Kerneltcp_rmem
This is a vector of 3 integers [min default max] These parameters are used by TCP to dynamically adjust receive buffer sizesmin - minimum size of the receive buffer used by each TCP socket The default value is 4K default - the default size of the receive buffer for a TCP socket The default value is 87380 bytes and is lowered to 43689 in low memory systems If larger receive buffer sizes are desired this value should be increased max - the maximum size of the receive buffer used by each TCP socket The default value of 873802 bytes is lowered to 87380 in low memory systems
tcp_smemSend buffer parameters [min default max] similar to tcp_rmem
- Chapter 3 Transport Layer
- Transport services and protocols
- Transport vs network layer
- Internet transport-layer protocols
- Multiplexingdemultiplexing
- How demultiplexing works
- Connectionless demultiplexing
- Connection-oriented demux
- Connection-oriented demux (cont)
- Connection-oriented demux Threaded Web Server
- UDP User Datagram Protocol [RFC 768]
- UDP more
- UDP checksum
- Principles of Reliable data transfer
- Reliable data transfer getting started
- Reliable data transfer getting started
- Rdt10 reliable transfer over a reliable channel
- Rdt20 channel with bit errors
- rdt20 FSM specification
- rdt20 operation with no errors
- rdt20 error scenario
- rdt20 has a fatal flaw
- rdt21 sender handles garbled ACKNAKs
- rdt21 receiver handles garbled ACKNAKs
- rdt21 discussion
- rdt22 a NAK-free protocol
- rdt22 sender receiver fragments
- rdt30 channels with errors and loss
- rdt30 sender
- rdt30 in action
- rdt30 in action
- Performance of rdt30
- rdt30 stop-and-wait operation
- Pipelined protocols
- Pipelining increased utilization
- Go-Back-N
- GBN sender extended FSM
- GBN receiver extended FSM
- GBN inaction
- Selective Repeat
- Selective repeat sender receiver windows
- Selective repeat
- Selective repeat in action
- Selective repeat dilemma
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- TCP Overview RFCs 793 1122 1323 2018 2581
- TCP segment structure
- TCP seq rsquos and ACKs
- TCP Round Trip Time and Timeout
- TCP Round Trip Time and Timeout
- Example RTT estimation
- TCP Round Trip Time and Timeout
- TCP reliable data transfer
- TCP sender events
- TCP sender(simplified)
- TCP retransmission scenarios
- TCP retransmission scenarios (more)
- TCP ACK generation [RFC 1122 RFC 2581]
- Fast Retransmit
- Fast Retransmit
- Fast retransmit algorithm
- TCP Flow Control
- TCP Flow control how it works
- Sliding Window Flow Control Example
- Principles of Congestion Control
- Causescosts of congestion scenario 1
- Causescosts of congestion scenario 2
- Causescosts of congestion scenario 2
- Causescosts of congestion scenario 3
- Causescosts of congestion scenario 3
- Approaches towards congestion control
- TCP Congestion Control
- TCP congestion control bandwidth probing
- TCP Congestion Control details
- TCP Congestion Control more details
- TCP Slow Start Phase
- Slow Start Example
- TCP Congestion Avoidance Phase
- Congestion Avoidance
- Example Slow StartCongestion Avoidance
- Slow Start Congestion Avoidance
- Responses to Congestion
- Fast Recovery (differentiation btwn two loss events)
- TCP Congestion Control
- Popular ldquoflavorsrdquo of TCP
- Summary TCP Congestion Control
- TCP Congestion Control Summary
- TCP throughput
- TCP Futures TCP over ldquolong fat pipesrdquo
- TCP Fairness
- Why is TCP fair
- Fairness (more)
- TCP Connection Management
- TCP Connection Management (cont)
- TCP Connection Management (cont)
- TCP Connection Management (cont)
- Tuning TCPIP Parameters
- SomeTCP Parameters in Linux Kernel
- SomeTCP Parameters in Linux Kernel
-
Transport Layer 3-34
Pipelined protocolsPipelining sender allows multiple ldquoin-flightrdquo yet-to-
be-acknowledged pktsrange of sequence numbers must be increasedbuffering at sender andor receiver
Two generic forms of pipelined protocols go-Back-N selective repeat
Transport Layer 3-35
Pipelining increased utilization
first packet bit transmitted t = 0
sender receiver
RTT
last bit transmitted t = L R
first packet bit arriveslast packet bit arrives send ACK
ACK arrives send next packet t = RTT + L R
last bit of 2nd packet arrives send ACKlast bit of 3rd packet arrives send ACK
U sender=
024 30008
= 000083 L RRTT + L R
=
Increase utilizationby a factor of 3
Transport Layer 3-36
Utilization=N(LR)(RTT+LR) if NLRltRTT+LR Utilization=1 if and the sender pauses after it transmits a window NLRgtRTT+LR and the of packets until it receives first ACK sender does not pause
Transport Layer 3-37
Go-Back-NSender
k-bit seq in pkt headerldquowindowrdquo of up to N consecutive unackrsquoed pkts allowed
ACK(n) ACKs all pkts up to including seq n - ldquocumulative ACKrdquomay receive duplicate ACKs (see receiver)
timer for the entire windowtimeout(n) retransmit pkt n and all higher seq pkts in window
Transport Layer 3-38
GBN sender extended FSM
Wait start_timerudt_send(sndpkt[base])udt_send(sndpkt[base+1])hellipudt_send(sndpkt[nextseqnum-1])
timeout
rdt_send(data)
if (nextseqnum lt base+N) sndpkt[nextseqnum] = make_pkt(nextseqnumdatachksum)udt_send(sndpkt[nextseqnum])if (base == nextseqnum)
start_timernextseqnum++
elserefuse_data(data)
base = getacknum(rcvpkt)+1If (base == nextseqnum)
stop_timerelse
start_timer
rdt_rcv(rcvpkt) ampamp notcorrupt(rcvpkt)
base=1nextseqnum=1
rdt_rcv(rcvpkt) ampamp corrupt(rcvpkt)
Λ
Λ
Transport Layer 3-39
GBN receiver extended FSM
ACK-only always send ACK for correctly-received pktwith highest in-order seq
may generate duplicate ACKsneed only remember expectedseqnum
out-of-order pkt discard (donrsquot buffer) -gt no receiver bufferingRe-ACK pkt with highest in-order seq
Wait
udt_send(sndpkt)default
rdt_rcv(rcvpkt)ampamp notcurrupt(rcvpkt)ampamp hasseqnum(rcvpktexpectedseqnum)
extract(rcvpktdata)deliver_data(data)sndpkt = make_pkt(expectedseqnumACKchksum)udt_send(sndpkt)expectedseqnum++
expectedseqnum=1sndpkt =
make_pkt(0ACKchksum)
Λ
Transport Layer 3-40
GBN inaction
Transport Layer 3-41
Selective Repeat
receiver individually acknowledges all correctly received pkts
buffers pkts as needed for eventual in-order delivery to upper layer
sender only resends pkts for which ACK not received
sender timer for each unACKed pktsender window
N consecutive seq rsquosagain limits seq s of sent unACKed pkts
Transport Layer 3-42
Selective repeat sender receiver windows
Transport Layer 3-43
Selective repeat
data from above if next available seq in window send pkt
timeout(n)resend pkt n restart timer
ACK(n) in [sendbasesendbase+N-1]
mark pkt n as receivedif n smallest unACKed pkt advance window base to next unACKed seq
senderpkt n in [rcvbase rcvbase+N-1]
send ACK(n)out-of-order bufferin-order deliver (also deliver buffered in-order pkts) advance window to next not-yet-received pkt
pkt n in [rcvbase-Nrcvbase-1]
ACK(n)otherwise
ignore
receiver
Transport Layer 3-44
Selective repeat in action
Transport Layer 3-45
Selective repeatdilemma
Example seq rsquos 0 1 2 3window size=3
receiver sees no difference in two scenariosincorrectly passes duplicate data as new in (a)
Q what relationship between seq size and window size
Transport Layer 3-46
Sequence Number vs Window SizeSuppose we use k bits to represent SNQuestion Whatrsquos the minimum number of bits k necessary for a window size of N
sender
receiver
Go-Back-N
expectedSN
snd_base=expectedSN
Q For a given expectedSN whatrsquos the largest possible value for snd_baseA If all the last N ACKs sent by the receiver are received
snd_base = expectedSNexpectedSN+N-1
senderrsquos window
Transport Layer 3-47
Sequence Number vs Window SizeSuppose we use k bits to represent SNQuestion Whatrsquos the minimum number of bits k necessary for a window size of N
sender
receiver
Go-Back-N
expectedSN
snd_base=expectedSN-N
Q For a given expectedSN whatrsquos the smallest possible value for snd_baseA If all the last N ACKs sent by the receiver are not received
snd_base = expectedSN-NexpectedSN-1
senderrsquos window
Transport Layer 3-48
Sequence Number vs Window Size
sender
receiver
Go-Back-N
expectedSN
snd_base=expectedSN-N
All SNs in the interval [expectedSN-NexpectedSN+N-1] (an interval of size 2N) can be received by the receiver Since the receiver accepts on the packet with SN=expectedSN there should be no other packet within this interval with SN=expectedSN Therefore
2k ge N+1expectedSN+N-1
Transport Layer 3-49
Sequence Number vs Window SizeSuppose we use k bits to represent SNQuestion Whatrsquos the minimum number of bits k necessary for a window size of N
sender
receiver
Selective Repeat
rcv_base
snd_base=rcv_base
Q For a given rcv_base whatrsquos the largest possible value for snd_baseA If all the last N ACKs sent by the receiver are received
snd_base = rcv_base (same as go_back-N)rcv_base+N-1
senderrsquos window
receiverrsquos window
rcv_base+N-1
Transport Layer 3-50
Sequence Number vs Window SizeSuppose we use k bits to represent SNQuestion Whatrsquos the minimum number of bits k necessary for a window size of N
sender
receiver
Selective Repeat
rcv_base
snd_base=rcv_base-N
Q For a given rcv_base whatrsquos the smallest possible value for snd_baseA If all the last N ACKs sent by the receiver are not received
snd_base = rcv_base-N (same as Go-Back-N)rcv_base-1
senderrsquos window
rcv_base
receiverrsquos window
rcv_base+N-1
Transport Layer 3-51
Sequence Number vs Window Size
sender
receiver
Selective Repeat
snd_base=rcv_base-N
All SNs in the interval [rcv_base-Nrcv_base+N-1] (an interval of size 2N) can be received by the receiver Since the receiver should be able to distinguish between all packets in this interval and take corresponding action there should be no two packets within thisinterval having the same SN Therefore
2k ge 2Nrcv_base+N-1
rcv_basercv_base
receiverrsquos window
rcv_base+N-1
Transport Layer 3-52
TCP Overview RFCs 793 1122 1323 2018 2581
full duplex databi-directional data flow in same connectionMSS maximum segment size
connection-orientedhandshaking (exchange of control msgs) initrsquossender receiver state before data exchange
flow controlledsender will not overwhelm receiver
point-to-pointone sender one receiver
reliable in-order byte stream
no ldquomessage boundariesrdquopipelined
TCP congestion and flow control set window size
send amp receive buffers
socketdoor
TCPsend buffer
TCPreceive buffer
socketdoor
segment
applicationwrites data
applicationreads data
Transport Layer 3-53
TCP segment structure
source port dest port
32 bits
applicationdata
(variable length)
sequence numberacknowledgement number
Receive windowUrg data pnterchecksum
FSRPAUheadlen
notused
Options (variable length)
URG urgent data (generally not used)
ACK ACK valid
PSH push data now(generally not used)
RST SYN FINconnection estab(setup teardown
commands)
bytes rcvr willingto accept
Internetchecksum
(as in UDP)
countingby bytes of data(not segments)
Transport Layer 3-54
TCP seq rsquos and ACKsSeq rsquos
byte stream ldquonumberrdquo of first byte in segmentrsquos dataACKs
seq of next byte expected from other sidecumulative ACK
Q how receiver handles out-of-order segmentsA TCP spec doesnrsquot say - up to implementationWidely used implementations of TCP buffer out-of-order segments
Transport Layer 3-55
TCP Round Trip Time and Timeout
Q how to set TCP timeout valuelonger than RTT
but RTT variestoo short premature timeout
unnecessary retransmissions
too long slow reaction to segment loss
Q how to estimate RTTSampleRTT measured time from segment transmission until ACK receipt
ignore retransmissionsSampleRTT will vary want estimated RTT ldquosmootherrdquo
average several recent measurements not just current SampleRTT
Transport Layer 3-56
TCP Round Trip Time and Timeout
EstimatedRTT = (1- α)EstimatedRTT + αSampleRTT
Exponential weighted moving averageinfluence of past sample decreases exponentially fasttypical value α = 0125
Transport Layer 3-57
Example RTT estimationRTT gaiacsumassedu to fantasiaeurecomfr
100
150
200
250
300
350
1 8 15 22 29 36 43 50 57 64 71 78 85 92 99 106
time (seconnds)
RTT
(mill
iseco
nds)
SampleRTT Estimated RTT
Transport Layer 3-58
TCP Round Trip Time and TimeoutSetting the timeout
EstimatedRTT plus ldquosafety marginrdquolarge variation in EstimatedRTT -gt larger safety margin
first estimate of how much SampleRTT deviates from EstimatedRTT
TimeoutInterval = EstimatedRTT + 4DevRTT
DevRTT = (1-β)DevRTT +β|SampleRTT-EstimatedRTT|
(typically β = 025)
Then set timeout interval
Transport Layer 3-59
TCP reliable data transfer
TCP creates rdtservice on top of IPrsquos unreliable servicePipelined segmentsCumulative acksTCP uses single retransmission timer however it just retransmits the first segment in the window
Retransmissions are triggered by
timeout eventsduplicate acks
Initially consider simplified TCP sender
ignore duplicate acksignore flow control congestion control
Transport Layer 3-60
TCP sender eventsdata rcvd from app
Create segment with seq seq is byte-stream number of first data byte in segmentstart timer if not already running (think of timer as for oldest unacked segment)expiration interval TimeOutInterval
timeoutretransmit segment that caused timeout (first segment in the window)restart timer
Ack rcvdIf acknowledges previously unacked segments
update what is known to be ackedstart timer if there are outstanding segments
Transport Layer 3-61
TCP sender(simplified)
NextSeqNum = InitialSeqNumSendBase = InitialSeqNum
loop (forever) switch(event)
event data received from application above create TCP segment with sequence number NextSeqNumif (timer currently not running)
start timerpass segment to IP NextSeqNum = NextSeqNum + length(data)
event timer timeoutretransmit not-yet-acknowledged segment with
smallest sequence numberstart timer
event ACK received with ACK field value of y if (y gt SendBase)
SendBase = yif (there are currently not-yet-acknowledged segments)
start timer
end of loop forever
Commentbull SendBase-1 last cumulatively ackrsquoed byteExamplebull SendBase-1 = 71y= 73 so the rcvrwants 73+ y gt SendBase sothat new data is acked
Transport Layer 3-62
TCP retransmission scenariosHost A
Seq=100 20 bytes data
ACK=100
timepremature timeout
Host B
Seq=92 8 bytes data
ACK=120
Seq=92 8 bytes data
Seq=
92 t
imeo
ut
ACK=120
Host A
Seq=92 8 bytes data
ACK=100
loss
tim
eout
lost ACK scenario
Host B
X
Seq=92 8 bytes data
ACK=100
time
Seq=
92 t
imeo
utSendBase
= 100
SendBase= 120
SendBase= 120
Sendbase= 100
Transport Layer 3-63
TCP retransmission scenarios (more)Host A
Seq=92 8 bytes data
ACK=100
loss
tim
eout
Cumulative ACK scenario
Host B
X
Seq=100 20 bytes data
ACK=120
time
SendBase= 120
Transport Layer 3-64
TCP ACK generation [RFC 1122 RFC 2581]
Event at Receiver
Arrival of in-order segment withexpected seq All data up toexpected seq already ACKed
Arrival of in-order segment withexpected seq One other segment has ACK pending
Arrival of out-of-order segmenthigher-than-expect seq Gap detected
Arrival of segment that partially or completely fills gap
TCP Receiver action
Delayed ACK Wait up to 500msfor next segment If no next segmentsend ACK
Immediately send single cumulative ACK ACKing both in-order segments
Immediately send duplicate ACK indicating seq of next expected byte
Immediate send ACK provided thatsegment startsat lower end of gap
Transport Layer 3-65
Fast Retransmit
Time-out period often relatively long
long delay before resending lost packet
Detect lost segments via duplicate ACKs
Sender often sends many segments back-to-backIf segment is lost there will likely be many duplicate ACKs
If sender receives 3 ACKs for the same data it supposes that segment after ACKeddata was lost
fast retransmit resend segment before timer expires
Transport Layer 3-66
Fast RetransmitResend a segment after 3 duplicate ACKs since a duplicate ACK means that an out-of sequence segment was receivedduplicate ACKs due to packet reorderingif window is small donrsquot get duplicate ACKs
Host A
tim
eout
Host B
time
X
resend seq X2
seq x1seq x2seq x3seq x4seq x5
ACK x1
ACK x1ACK x1ACK x1
tripleduplicate
ACKs
Transport Layer 3-67
event ACK received with ACK field value of y if (y gt SendBase)
SendBase = yif (there are currently not-yet-acknowledged segments)
start timer
else increment count of dup ACKs received for yif (count of dup ACKs received for y = 3)
resend segment with sequence number y
Fast retransmit algorithm
a duplicate ACK for already ACKed segment
fast retransmit
Transport Layer 3-68
TCP Flow Control
receive side of TCP connection has a receive buffer
speed-matching service matching the send rate to the receiving apprsquos drain rate
app process may be slow at reading from buffer
sender wonrsquot overflowreceiverrsquos buffer by
transmitting too muchtoo fast
flow control
Transport Layer 3-69
TCP Flow control how it works
(Suppose TCP receiver discards out-of-order segments)spare room in buffer
= RcvWin
= RcvBuffer-[LastByteRcvd -LastByteRead]
Rcvr advertises spare room by including value of RcvWin in segmentsSender limits unACKeddata to RcvWin
guarantees receive buffer doesnrsquot overflow
Transport Layer 3-70
Sliding Window Flow Control Example
3K
2K SeqNo=0
ReceiverBuffer
0 4KSendersends 2Kof data
2K
AckNo=2048 RcvWin=2048Sendersends 2Kof data 2K SeqNo=2048
4K
AckNo=4096 RcvWin=0
AckNo=4096 RcvWin=1024
Sender blocked
Transport Layer 3-71
Principles of Congestion Control
Congestioninformally ldquotoo many sources sending too much data too fast for network to handlerdquodifferent from flow controlmanifestations
lost packets (buffer overflow at routers)long delays (queueing in router buffers)
a top-10 problem
Transport Layer 3-72
Causescosts of congestion scenario 1
two senders two receiversone router infinite buffers no retransmission
large delays when congestedmaximum achievable throughput
unlimited shared output link buffers
Host Aλin original data
Host B
λout
Transport Layer 3-73
Causescosts of congestion scenario 2
one router finite buffers sender retransmission of lost packet
finite shared output link buffers
Host A λin original data
Host B
λout
λin original data plus retransmitted data
Transport Layer 3-74
Causescosts of congestion scenario 2always (goodput)ldquoperfectrdquo retransmission only when loss
retransmission of delayed (not lost) packet makes larger(than perfect case) for same
λin
λout=
λin
λoutgtλ
inλout
ldquocostsrdquo of congestionmore work (retrans) for given ldquogoodputrdquounneeded retransmissions link carries multiple copies of pkt
R2
R2λin
λ out
b
R2
R2λin
λ out
a
R2
R2λin
λ out
c
R4
R3
Transport Layer 3-75
Causescosts of congestion scenario 3four sendersmultihop pathstimeoutretransmit
λin
Q what happens as and increase λ
in
finite shared output link buffers
Host Aλin original data
Host B
λout
λin original data plus retransmitted data
Transport Layer 3-76
Causescosts of congestion scenario 3
another ldquocostrdquo of congestionwhen packet dropped any ldquoupstream transmission capacity used for that packet was wasted
Host A
Host B
λou
t
Transport Layer 3-77
Approaches towards congestion control
End-end congestion controlno explicit feedback from networkcongestion inferred from end-system observed loss delayapproach taken by TCP
Network-assisted congestion controlrouters provide feedback to end systems
single bit indicating congestion (SNA DECbit TCPIP ECN ATM)explicit rate sender should send at
Two broad approaches towards congestion control
Transport Layer 3-78
TCP Congestion Control
end-end control (no network assistance)sender limits transmissionLastByteSent-LastByteAcked
le CongWin
CongWin is dynamic function of perceived network congestion
How does sender perceive congestionloss event = timeout or3 duplicate acksTCP sender reduces rate (CongWin) after loss event
two modes of operationSlow Start (SS)Congestion avoidance (CA) or Additive Increase Multiplicative Decrease (AIMD)
Transport Layer 3-79
TCP congestion control bandwidth probing
ldquoprobing for bandwidthrdquo increase transmission rate on receipt of ACK until eventually loss occurs then decrease transmission rate
continue to increase on ACK decrease on loss (since available bandwidth is changing depending on other connections in network)
ACKs being received so increase rate
X
X
XX
X loss so decrease rate
send
ing
rate
time
Q how fast to increasedecreasedetails to follow
TCPrsquosldquosawtoothrdquobehavior
Transport Layer 3-80
TCP Congestion Control details
sender limits rate by limiting number of unACKed bytes ldquoin pipelinerdquo
cwnd differs from rwnd (how why)sender limited by min(cwndrwnd)
roughly
cwnd is dynamic function of perceived network congestion
rate = cwndRTT bytessec
LastByteSent-LastByteAcked le cwnd
cwndbytes
RTT
ACK(s)
Transport Layer 3-81
TCP Congestion Control more details
segment loss event reducing cwndtimeout no response from receiver
cut cwnd to 13 duplicate ACKs at least some segments getting through (recall fast retransmit)
cut cwnd in half less aggressively than on timeout
ACK received increase cwndTwo modes of operation
slowstart phase bull increase exponentially
fast (despite name) at connection start or following timeout
congestion avoidance bull increase linearly
Transport Layer 3-82
TCP Slow Start Phasewhen connection begins cwnd = 1 MSS
example MSS = 500 bytes amp RTT = 200 msecinitial rate = 20 kbps
available bandwidth may be gtgt MSSRTT
desirable to quickly ramp up to respectable rate
increase rate exponentially until first loss event or when threshold reached
double cwnd every RTTdone by incrementing cwnd by 1 for every ACK received
Host A
one segment
RTT
Host B
time
two segments
four segments
Transport Layer 3-83
Slow Start ExampleThe congestion window size grows very rapidly
For every ACK we increase CongWin by 1 irrespective of the number of segments ACKrsquoeddouble CongWinevery RTTinitial rate is slow but ramps up exponentially fast
TCP slows down the increase of CongWinwhen CongWin gt ssthresh
segment 1
ACK for segment 1
cwnd = 1
cwnd = 2 segment 2segment 3
ACK for segments 2
cwnd = 4 segment 4segment 5segment 6
ACK for segments 4
cwnd = 7
ACK for segments 3
ACK for segments 5
ACK for segments 6
cwnd = 3
cwnd = 5
cwnd = 6ACK for segments 7
cwnd = 8
segment 7
Transport Layer 3-84
TCP Congestion Avoidance Phase
when cwnd gt ssthreshgrow cwnd linearly
increase cwnd by 1 MSS per RTT approach possible congestion slower than in slowstartimplementation cwnd= cwnd + MSScwndfor each ACK received
ACKs increase cwndby 1 MSS per RTT additive increaseloss cut cwnd in half (non-timeout-detected loss ) multiplicative decrease
AIMD
AIMD Additive IncreaseMultiplicative Decrease
Transport Layer 3-85
Congestion AvoidanceCongestion avoidance phase is started if CongWin has reached the slow-start threshold value
If CongWin gt= ssthresh then each time an ACK is received increment CongWin as follows
bull CongWin = CongWin + 1CongWin (CongWin in segments)
bull In actual TCP implementation CongWin is in BytesCongWin = CongWin + MSS (MSSCongWin)
So CongWin is increased by one only if all CongWinsegments have been acknowledged
Transport Layer 3-86
Example Slow StartCongestion AvoidanceAssume that
ssthresh = 8
cwnd = 1
cwnd = 2
cwnd = 4
cwnd = 8
cwnd = 9
cwnd = 10
02468
101214
t=0
t=2
t=4
t=6
Roundtrip times
Cw
nd(in
seg
men
ts)
ssthresh
cwnd = 3
cwnd = 5cwnd = 6cwnd = 7
Transport Layer 3-87
Slow Start Congestion AvoidanceA typical plot of CongWin for a TCP connection
(MSS = 1500 bytes) with TCP Tahoe
SS
CA
ssthresh
Transport Layer 3-88
Responses to CongestionTCP assumes there is congestion if it detects a packet lossA TCP sender can detect lost packets via loss events
bull Timeout of a retransmission timerbull Receipt of 3 duplicate ACKs (fast retransmit)
TCP interprets a Timeout as a binary congestion signal When a timeout occurs the sender performs
ssthresh is set to half the current size of the congestion window
ssthresh = CongWin 2CongWin is reset to one
CongWin = 1and slow-start is entered
Transport Layer 3-89
Fast Recovery (differentiation btwn two loss events) After 3 dup ACKs (fast Retransmit)
ssthresh = CongWin2CongWin = CongWin2window then grows linearly
But after timeout eventCongWin = 1 MSS window then grows exponentiallyto the threshold then grows linearly
bull 3 dup ACKs indicates network capable of delivering some segmentsbull timeout before 3 dup ACKs is ldquomore alarmingrdquo
Philosophy
3-90
TCP Congestion ControlInitially
CongWin = 1ssthresh = advertised window size
New Ack receivedif (CongWin lt ssthresh) Slow Start
CongWin = CongWin + 1else Congestion Avoidance
CongWin = CongWin + 1CongWinTimeout
ssthresh = CongWin2CongWin = 1
Fast Retransmissionssthresh = CongWin2CongWin = CongWin2
Slow Start (exponential increase phase) is continued until CongWin reaches half of the level where the loss event occurred last time CongWin is increased slowly after (linear increase in Congestion Avoidance phase)
Transport Layer 3-91
Popular ldquoflavorsrdquo of TCP
ssthresh
ssthresh
TCP Tahoe
TCP Reno
Transmission round
cwnd
win
dow
siz
e (in
seg
men
ts)
Transport Layer 3-92
Summary TCP Congestion ControlWhen CongWin is below Threshold sender in slow-start phase window grows exponentiallyWhen CongWin is above Threshold sender is in congestion-avoidance phase window grows linearlyWhen a triple duplicate ACK occurs Threshold set to CongWin2 and CongWin set to ThresholdWhen timeout occurs Threshold set to CongWin2 and CongWin is set to 1 MSS The actual sender window size is determined based on the congestion and flow control algorithms
SenderWin=min(RcvWinCongWin)
Transport Layer 3-93
TCP Congestion Control SummaryEvent State TCP Sender Action Commentary
ACK receipt for previously unackeddata
Slow Start (SS)
CongWin = CongWin + MSS If (CongWin gt Threshold)
set state to ldquoCongestion Avoidancerdquo
Resulting in a doubling of CongWin every RTT
ACK receipt for previously unackeddata
CongestionAvoidance (CA)
CongWin = CongWin+MSS (MSSCongWin)
Additive increase resulting in increase of CongWin by 1 MSS every RTT
Loss event detected by triple duplicate ACK
SS or CA Threshold = CongWin2 CongWin = ThresholdSet state to ldquoCongestion Avoidancerdquo
Fast recovery implementing multiplicative decrease CongWin will not drop below 1 MSS
Timeout SS or CA Threshold = CongWin2 CongWin = 1 MSSSet state to ldquoSlow Startrdquo
Enter slow start
Duplicate ACK
SS or CA Increment duplicate ACK count for segment being acked
CongWin and Threshold not changed
Transport Layer 3-94
TCP throughput
Q whatrsquos average throughout of TCP as function of window size RTT
ignoring slow startlet W be window size when loss occurs
when window is W throughput is WRTTjust after loss window drops to W2 throughput to W2RTT average throughout 75 WRTT
Transport Layer 3-95
TCP Futures TCP over ldquolong fat pipesrdquo
example 1500 byte segments 100ms RTT want 10 Gbps throughputrequires window size W = 83333 in-flight segmentsthroughput in terms of loss rate
L = 210-10 Wownew versions of TCP for high-speed
LRTTMSSsdot221
Transport Layer 3-96
Fairness goal if K TCP sessions share same bottleneck link of bandwidth R each should have average rate of RK
TCP connection 1
bottleneckrouter
capacity R
TCP connection 2
TCP Fairness
Transport Layer 3-97
Why is TCP fairTwo competing sessions
Additive increase gives slope of 1 as throughout increasesmultiplicative decrease decreases throughput proportionally
R
R
equal bandwidth share
Connection 1 throughput
Conn
ecti
on 2
thr
ough
p ut
congestion avoidance additive increaseloss decrease window by factor of 2
congestion avoidance additive increaseloss decrease window by factor of 2
Transport Layer 3-98
Fairness (more)Fairness and UDP
Multimedia apps often do not use TCP
do not want rate throttled by congestion control
Instead use UDPpump audiovideo at constant rate tolerate packet loss
Research area TCP friendly
Fairness and parallel TCP connectionsnothing prevents app from opening parallel cnctionsbetween 2 hostsWeb browsers do this Example link of rate R supporting 9 cnctions
new app asks for 1 TCP gets rate R10new app asks for 11 TCPs gets R2
Transport Layer 3-99
TCP Connection ManagementRecall TCP sender receiver
establish ldquoconnectionrdquobefore exchanging data segmentsinitialize TCP variables
seq sbuffers flow control info (eg RcvWindow)
client connection initiatorSocket clientSocket = new Socket(hostnameport
number)
server contacted by clientSocket connectionSocket = welcomeSocketaccept()
Three way handshakeStep 1 client host sends TCP
SYN segment to serverspecifies initial seq no data
Step 2 server host receives SYN replies with SYNACK segment
server allocates buffersspecifies server initial seq
Step 3 client receives SYNACK replies with ACK segment which may contain data
Transport Layer 3-100
TCP Connection Management (cont)
Closing a connection
client closes socketclientSocketclose()
Step 1 client end system sends TCP FIN control segment to server
Step 2 server receives FIN replies with ACK Closes connection sends FIN
client
FIN
server
ACK
ACK
FIN
close
close
closed
tim
ed w
ait
Transport Layer 3-101
TCP Connection Management (cont)
Step 3 client receives FIN replies with ACK
Enters ldquotimed waitrdquo -will respond with ACK to received FINs
Step 4 server receives ACK Connection closed
client
FIN
server
ACK
ACK
FIN
closing
closing
closed
tim
ed w
ait
closed
Transport Layer 3-102
TCP Connection Management (cont)
TCP clientlifecycle
TCP serverlifecycle
Transport Layer 3-103
Tuning TCPIP Parameters TCPIP parameters
A set of default values may not be optimal for all applicationsThe network administrator may wish to turn on or off some TCPIP functions for performance or security considerations
Many Unix and Linux systems provide some flexibility in tuning the TCPIP kernelsbinsysctl is used to configure the Linux kernel parameters at runtime
Default kernel configuration file is sbinsysctlconfFrequently used sysctl options
bull sysctl ndasha or sysctl ndashA list all current valuesbull sysctl ndashp file_name load the sysctl setting from a configuration
filebull sysctl ndashw variable=value change the value of the parameter
Transport Layer 3-104
SomeTCP Parameters in Linux Kerneltcp_syn_retries
Number of SYN packets the kernel will send before giving up on the new connection
tcp_synack_retriesnumber of SYN+ACK packets sent before the kernel gives up on the connection
tcp_window_scalingMaximum window size of 65535 bytes not enough for for really fast networks The window scaling options allows for almost gigabyte windows which is good for connections with large delay-bandwidth product
tcp_max_syn_backlogMaximal number of remembered connection requests which still did not receive an acknowledgment from connecting client
tcp_fin_timeoutHow many seconds to wait for a final FIN packet before the socket is closed required to prevent denial-of-service (DoS) attacks Default value is 60 seconds
Transport Layer 3-105
SomeTCP Parameters in Linux Kerneltcp_rmem
This is a vector of 3 integers [min default max] These parameters are used by TCP to dynamically adjust receive buffer sizesmin - minimum size of the receive buffer used by each TCP socket The default value is 4K default - the default size of the receive buffer for a TCP socket The default value is 87380 bytes and is lowered to 43689 in low memory systems If larger receive buffer sizes are desired this value should be increased max - the maximum size of the receive buffer used by each TCP socket The default value of 873802 bytes is lowered to 87380 in low memory systems
tcp_smemSend buffer parameters [min default max] similar to tcp_rmem
- Chapter 3 Transport Layer
- Transport services and protocols
- Transport vs network layer
- Internet transport-layer protocols
- Multiplexingdemultiplexing
- How demultiplexing works
- Connectionless demultiplexing
- Connection-oriented demux
- Connection-oriented demux (cont)
- Connection-oriented demux Threaded Web Server
- UDP User Datagram Protocol [RFC 768]
- UDP more
- UDP checksum
- Principles of Reliable data transfer
- Reliable data transfer getting started
- Reliable data transfer getting started
- Rdt10 reliable transfer over a reliable channel
- Rdt20 channel with bit errors
- rdt20 FSM specification
- rdt20 operation with no errors
- rdt20 error scenario
- rdt20 has a fatal flaw
- rdt21 sender handles garbled ACKNAKs
- rdt21 receiver handles garbled ACKNAKs
- rdt21 discussion
- rdt22 a NAK-free protocol
- rdt22 sender receiver fragments
- rdt30 channels with errors and loss
- rdt30 sender
- rdt30 in action
- rdt30 in action
- Performance of rdt30
- rdt30 stop-and-wait operation
- Pipelined protocols
- Pipelining increased utilization
- Go-Back-N
- GBN sender extended FSM
- GBN receiver extended FSM
- GBN inaction
- Selective Repeat
- Selective repeat sender receiver windows
- Selective repeat
- Selective repeat in action
- Selective repeat dilemma
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- TCP Overview RFCs 793 1122 1323 2018 2581
- TCP segment structure
- TCP seq rsquos and ACKs
- TCP Round Trip Time and Timeout
- TCP Round Trip Time and Timeout
- Example RTT estimation
- TCP Round Trip Time and Timeout
- TCP reliable data transfer
- TCP sender events
- TCP sender(simplified)
- TCP retransmission scenarios
- TCP retransmission scenarios (more)
- TCP ACK generation [RFC 1122 RFC 2581]
- Fast Retransmit
- Fast Retransmit
- Fast retransmit algorithm
- TCP Flow Control
- TCP Flow control how it works
- Sliding Window Flow Control Example
- Principles of Congestion Control
- Causescosts of congestion scenario 1
- Causescosts of congestion scenario 2
- Causescosts of congestion scenario 2
- Causescosts of congestion scenario 3
- Causescosts of congestion scenario 3
- Approaches towards congestion control
- TCP Congestion Control
- TCP congestion control bandwidth probing
- TCP Congestion Control details
- TCP Congestion Control more details
- TCP Slow Start Phase
- Slow Start Example
- TCP Congestion Avoidance Phase
- Congestion Avoidance
- Example Slow StartCongestion Avoidance
- Slow Start Congestion Avoidance
- Responses to Congestion
- Fast Recovery (differentiation btwn two loss events)
- TCP Congestion Control
- Popular ldquoflavorsrdquo of TCP
- Summary TCP Congestion Control
- TCP Congestion Control Summary
- TCP throughput
- TCP Futures TCP over ldquolong fat pipesrdquo
- TCP Fairness
- Why is TCP fair
- Fairness (more)
- TCP Connection Management
- TCP Connection Management (cont)
- TCP Connection Management (cont)
- TCP Connection Management (cont)
- Tuning TCPIP Parameters
- SomeTCP Parameters in Linux Kernel
- SomeTCP Parameters in Linux Kernel
-
Transport Layer 3-35
Pipelining increased utilization
first packet bit transmitted t = 0
sender receiver
RTT
last bit transmitted t = L R
first packet bit arriveslast packet bit arrives send ACK
ACK arrives send next packet t = RTT + L R
last bit of 2nd packet arrives send ACKlast bit of 3rd packet arrives send ACK
U sender=
024 30008
= 000083 L RRTT + L R
=
Increase utilizationby a factor of 3
Transport Layer 3-36
Utilization=N(LR)(RTT+LR) if NLRltRTT+LR Utilization=1 if and the sender pauses after it transmits a window NLRgtRTT+LR and the of packets until it receives first ACK sender does not pause
Transport Layer 3-37
Go-Back-NSender
k-bit seq in pkt headerldquowindowrdquo of up to N consecutive unackrsquoed pkts allowed
ACK(n) ACKs all pkts up to including seq n - ldquocumulative ACKrdquomay receive duplicate ACKs (see receiver)
timer for the entire windowtimeout(n) retransmit pkt n and all higher seq pkts in window
Transport Layer 3-38
GBN sender extended FSM
Wait start_timerudt_send(sndpkt[base])udt_send(sndpkt[base+1])hellipudt_send(sndpkt[nextseqnum-1])
timeout
rdt_send(data)
if (nextseqnum lt base+N) sndpkt[nextseqnum] = make_pkt(nextseqnumdatachksum)udt_send(sndpkt[nextseqnum])if (base == nextseqnum)
start_timernextseqnum++
elserefuse_data(data)
base = getacknum(rcvpkt)+1If (base == nextseqnum)
stop_timerelse
start_timer
rdt_rcv(rcvpkt) ampamp notcorrupt(rcvpkt)
base=1nextseqnum=1
rdt_rcv(rcvpkt) ampamp corrupt(rcvpkt)
Λ
Λ
Transport Layer 3-39
GBN receiver extended FSM
ACK-only always send ACK for correctly-received pktwith highest in-order seq
may generate duplicate ACKsneed only remember expectedseqnum
out-of-order pkt discard (donrsquot buffer) -gt no receiver bufferingRe-ACK pkt with highest in-order seq
Wait
udt_send(sndpkt)default
rdt_rcv(rcvpkt)ampamp notcurrupt(rcvpkt)ampamp hasseqnum(rcvpktexpectedseqnum)
extract(rcvpktdata)deliver_data(data)sndpkt = make_pkt(expectedseqnumACKchksum)udt_send(sndpkt)expectedseqnum++
expectedseqnum=1sndpkt =
make_pkt(0ACKchksum)
Λ
Transport Layer 3-40
GBN inaction
Transport Layer 3-41
Selective Repeat
receiver individually acknowledges all correctly received pkts
buffers pkts as needed for eventual in-order delivery to upper layer
sender only resends pkts for which ACK not received
sender timer for each unACKed pktsender window
N consecutive seq rsquosagain limits seq s of sent unACKed pkts
Transport Layer 3-42
Selective repeat sender receiver windows
Transport Layer 3-43
Selective repeat
data from above if next available seq in window send pkt
timeout(n)resend pkt n restart timer
ACK(n) in [sendbasesendbase+N-1]
mark pkt n as receivedif n smallest unACKed pkt advance window base to next unACKed seq
senderpkt n in [rcvbase rcvbase+N-1]
send ACK(n)out-of-order bufferin-order deliver (also deliver buffered in-order pkts) advance window to next not-yet-received pkt
pkt n in [rcvbase-Nrcvbase-1]
ACK(n)otherwise
ignore
receiver
Transport Layer 3-44
Selective repeat in action
Transport Layer 3-45
Selective repeatdilemma
Example seq rsquos 0 1 2 3window size=3
receiver sees no difference in two scenariosincorrectly passes duplicate data as new in (a)
Q what relationship between seq size and window size
Transport Layer 3-46
Sequence Number vs Window SizeSuppose we use k bits to represent SNQuestion Whatrsquos the minimum number of bits k necessary for a window size of N
sender
receiver
Go-Back-N
expectedSN
snd_base=expectedSN
Q For a given expectedSN whatrsquos the largest possible value for snd_baseA If all the last N ACKs sent by the receiver are received
snd_base = expectedSNexpectedSN+N-1
senderrsquos window
Transport Layer 3-47
Sequence Number vs Window SizeSuppose we use k bits to represent SNQuestion Whatrsquos the minimum number of bits k necessary for a window size of N
sender
receiver
Go-Back-N
expectedSN
snd_base=expectedSN-N
Q For a given expectedSN whatrsquos the smallest possible value for snd_baseA If all the last N ACKs sent by the receiver are not received
snd_base = expectedSN-NexpectedSN-1
senderrsquos window
Transport Layer 3-48
Sequence Number vs Window Size
sender
receiver
Go-Back-N
expectedSN
snd_base=expectedSN-N
All SNs in the interval [expectedSN-NexpectedSN+N-1] (an interval of size 2N) can be received by the receiver Since the receiver accepts on the packet with SN=expectedSN there should be no other packet within this interval with SN=expectedSN Therefore
2k ge N+1expectedSN+N-1
Transport Layer 3-49
Sequence Number vs Window SizeSuppose we use k bits to represent SNQuestion Whatrsquos the minimum number of bits k necessary for a window size of N
sender
receiver
Selective Repeat
rcv_base
snd_base=rcv_base
Q For a given rcv_base whatrsquos the largest possible value for snd_baseA If all the last N ACKs sent by the receiver are received
snd_base = rcv_base (same as go_back-N)rcv_base+N-1
senderrsquos window
receiverrsquos window
rcv_base+N-1
Transport Layer 3-50
Sequence Number vs Window SizeSuppose we use k bits to represent SNQuestion Whatrsquos the minimum number of bits k necessary for a window size of N
sender
receiver
Selective Repeat
rcv_base
snd_base=rcv_base-N
Q For a given rcv_base whatrsquos the smallest possible value for snd_baseA If all the last N ACKs sent by the receiver are not received
snd_base = rcv_base-N (same as Go-Back-N)rcv_base-1
senderrsquos window
rcv_base
receiverrsquos window
rcv_base+N-1
Transport Layer 3-51
Sequence Number vs Window Size
sender
receiver
Selective Repeat
snd_base=rcv_base-N
All SNs in the interval [rcv_base-Nrcv_base+N-1] (an interval of size 2N) can be received by the receiver Since the receiver should be able to distinguish between all packets in this interval and take corresponding action there should be no two packets within thisinterval having the same SN Therefore
2k ge 2Nrcv_base+N-1
rcv_basercv_base
receiverrsquos window
rcv_base+N-1
Transport Layer 3-52
TCP Overview RFCs 793 1122 1323 2018 2581
full duplex databi-directional data flow in same connectionMSS maximum segment size
connection-orientedhandshaking (exchange of control msgs) initrsquossender receiver state before data exchange
flow controlledsender will not overwhelm receiver
point-to-pointone sender one receiver
reliable in-order byte stream
no ldquomessage boundariesrdquopipelined
TCP congestion and flow control set window size
send amp receive buffers
socketdoor
TCPsend buffer
TCPreceive buffer
socketdoor
segment
applicationwrites data
applicationreads data
Transport Layer 3-53
TCP segment structure
source port dest port
32 bits
applicationdata
(variable length)
sequence numberacknowledgement number
Receive windowUrg data pnterchecksum
FSRPAUheadlen
notused
Options (variable length)
URG urgent data (generally not used)
ACK ACK valid
PSH push data now(generally not used)
RST SYN FINconnection estab(setup teardown
commands)
bytes rcvr willingto accept
Internetchecksum
(as in UDP)
countingby bytes of data(not segments)
Transport Layer 3-54
TCP seq rsquos and ACKsSeq rsquos
byte stream ldquonumberrdquo of first byte in segmentrsquos dataACKs
seq of next byte expected from other sidecumulative ACK
Q how receiver handles out-of-order segmentsA TCP spec doesnrsquot say - up to implementationWidely used implementations of TCP buffer out-of-order segments
Transport Layer 3-55
TCP Round Trip Time and Timeout
Q how to set TCP timeout valuelonger than RTT
but RTT variestoo short premature timeout
unnecessary retransmissions
too long slow reaction to segment loss
Q how to estimate RTTSampleRTT measured time from segment transmission until ACK receipt
ignore retransmissionsSampleRTT will vary want estimated RTT ldquosmootherrdquo
average several recent measurements not just current SampleRTT
Transport Layer 3-56
TCP Round Trip Time and Timeout
EstimatedRTT = (1- α)EstimatedRTT + αSampleRTT
Exponential weighted moving averageinfluence of past sample decreases exponentially fasttypical value α = 0125
Transport Layer 3-57
Example RTT estimationRTT gaiacsumassedu to fantasiaeurecomfr
100
150
200
250
300
350
1 8 15 22 29 36 43 50 57 64 71 78 85 92 99 106
time (seconnds)
RTT
(mill
iseco
nds)
SampleRTT Estimated RTT
Transport Layer 3-58
TCP Round Trip Time and TimeoutSetting the timeout
EstimatedRTT plus ldquosafety marginrdquolarge variation in EstimatedRTT -gt larger safety margin
first estimate of how much SampleRTT deviates from EstimatedRTT
TimeoutInterval = EstimatedRTT + 4DevRTT
DevRTT = (1-β)DevRTT +β|SampleRTT-EstimatedRTT|
(typically β = 025)
Then set timeout interval
Transport Layer 3-59
TCP reliable data transfer
TCP creates rdtservice on top of IPrsquos unreliable servicePipelined segmentsCumulative acksTCP uses single retransmission timer however it just retransmits the first segment in the window
Retransmissions are triggered by
timeout eventsduplicate acks
Initially consider simplified TCP sender
ignore duplicate acksignore flow control congestion control
Transport Layer 3-60
TCP sender eventsdata rcvd from app
Create segment with seq seq is byte-stream number of first data byte in segmentstart timer if not already running (think of timer as for oldest unacked segment)expiration interval TimeOutInterval
timeoutretransmit segment that caused timeout (first segment in the window)restart timer
Ack rcvdIf acknowledges previously unacked segments
update what is known to be ackedstart timer if there are outstanding segments
Transport Layer 3-61
TCP sender(simplified)
NextSeqNum = InitialSeqNumSendBase = InitialSeqNum
loop (forever) switch(event)
event data received from application above create TCP segment with sequence number NextSeqNumif (timer currently not running)
start timerpass segment to IP NextSeqNum = NextSeqNum + length(data)
event timer timeoutretransmit not-yet-acknowledged segment with
smallest sequence numberstart timer
event ACK received with ACK field value of y if (y gt SendBase)
SendBase = yif (there are currently not-yet-acknowledged segments)
start timer
end of loop forever
Commentbull SendBase-1 last cumulatively ackrsquoed byteExamplebull SendBase-1 = 71y= 73 so the rcvrwants 73+ y gt SendBase sothat new data is acked
Transport Layer 3-62
TCP retransmission scenariosHost A
Seq=100 20 bytes data
ACK=100
timepremature timeout
Host B
Seq=92 8 bytes data
ACK=120
Seq=92 8 bytes data
Seq=
92 t
imeo
ut
ACK=120
Host A
Seq=92 8 bytes data
ACK=100
loss
tim
eout
lost ACK scenario
Host B
X
Seq=92 8 bytes data
ACK=100
time
Seq=
92 t
imeo
utSendBase
= 100
SendBase= 120
SendBase= 120
Sendbase= 100
Transport Layer 3-63
TCP retransmission scenarios (more)Host A
Seq=92 8 bytes data
ACK=100
loss
tim
eout
Cumulative ACK scenario
Host B
X
Seq=100 20 bytes data
ACK=120
time
SendBase= 120
Transport Layer 3-64
TCP ACK generation [RFC 1122 RFC 2581]
Event at Receiver
Arrival of in-order segment withexpected seq All data up toexpected seq already ACKed
Arrival of in-order segment withexpected seq One other segment has ACK pending
Arrival of out-of-order segmenthigher-than-expect seq Gap detected
Arrival of segment that partially or completely fills gap
TCP Receiver action
Delayed ACK Wait up to 500msfor next segment If no next segmentsend ACK
Immediately send single cumulative ACK ACKing both in-order segments
Immediately send duplicate ACK indicating seq of next expected byte
Immediate send ACK provided thatsegment startsat lower end of gap
Transport Layer 3-65
Fast Retransmit
Time-out period often relatively long
long delay before resending lost packet
Detect lost segments via duplicate ACKs
Sender often sends many segments back-to-backIf segment is lost there will likely be many duplicate ACKs
If sender receives 3 ACKs for the same data it supposes that segment after ACKeddata was lost
fast retransmit resend segment before timer expires
Transport Layer 3-66
Fast RetransmitResend a segment after 3 duplicate ACKs since a duplicate ACK means that an out-of sequence segment was receivedduplicate ACKs due to packet reorderingif window is small donrsquot get duplicate ACKs
Host A
tim
eout
Host B
time
X
resend seq X2
seq x1seq x2seq x3seq x4seq x5
ACK x1
ACK x1ACK x1ACK x1
tripleduplicate
ACKs
Transport Layer 3-67
event ACK received with ACK field value of y if (y gt SendBase)
SendBase = yif (there are currently not-yet-acknowledged segments)
start timer
else increment count of dup ACKs received for yif (count of dup ACKs received for y = 3)
resend segment with sequence number y
Fast retransmit algorithm
a duplicate ACK for already ACKed segment
fast retransmit
Transport Layer 3-68
TCP Flow Control
receive side of TCP connection has a receive buffer
speed-matching service matching the send rate to the receiving apprsquos drain rate
app process may be slow at reading from buffer
sender wonrsquot overflowreceiverrsquos buffer by
transmitting too muchtoo fast
flow control
Transport Layer 3-69
TCP Flow control how it works
(Suppose TCP receiver discards out-of-order segments)spare room in buffer
= RcvWin
= RcvBuffer-[LastByteRcvd -LastByteRead]
Rcvr advertises spare room by including value of RcvWin in segmentsSender limits unACKeddata to RcvWin
guarantees receive buffer doesnrsquot overflow
Transport Layer 3-70
Sliding Window Flow Control Example
3K
2K SeqNo=0
ReceiverBuffer
0 4KSendersends 2Kof data
2K
AckNo=2048 RcvWin=2048Sendersends 2Kof data 2K SeqNo=2048
4K
AckNo=4096 RcvWin=0
AckNo=4096 RcvWin=1024
Sender blocked
Transport Layer 3-71
Principles of Congestion Control
Congestioninformally ldquotoo many sources sending too much data too fast for network to handlerdquodifferent from flow controlmanifestations
lost packets (buffer overflow at routers)long delays (queueing in router buffers)
a top-10 problem
Transport Layer 3-72
Causescosts of congestion scenario 1
two senders two receiversone router infinite buffers no retransmission
large delays when congestedmaximum achievable throughput
unlimited shared output link buffers
Host Aλin original data
Host B
λout
Transport Layer 3-73
Causescosts of congestion scenario 2
one router finite buffers sender retransmission of lost packet
finite shared output link buffers
Host A λin original data
Host B
λout
λin original data plus retransmitted data
Transport Layer 3-74
Causescosts of congestion scenario 2always (goodput)ldquoperfectrdquo retransmission only when loss
retransmission of delayed (not lost) packet makes larger(than perfect case) for same
λin
λout=
λin
λoutgtλ
inλout
ldquocostsrdquo of congestionmore work (retrans) for given ldquogoodputrdquounneeded retransmissions link carries multiple copies of pkt
R2
R2λin
λ out
b
R2
R2λin
λ out
a
R2
R2λin
λ out
c
R4
R3
Transport Layer 3-75
Causescosts of congestion scenario 3four sendersmultihop pathstimeoutretransmit
λin
Q what happens as and increase λ
in
finite shared output link buffers
Host Aλin original data
Host B
λout
λin original data plus retransmitted data
Transport Layer 3-76
Causescosts of congestion scenario 3
another ldquocostrdquo of congestionwhen packet dropped any ldquoupstream transmission capacity used for that packet was wasted
Host A
Host B
λou
t
Transport Layer 3-77
Approaches towards congestion control
End-end congestion controlno explicit feedback from networkcongestion inferred from end-system observed loss delayapproach taken by TCP
Network-assisted congestion controlrouters provide feedback to end systems
single bit indicating congestion (SNA DECbit TCPIP ECN ATM)explicit rate sender should send at
Two broad approaches towards congestion control
Transport Layer 3-78
TCP Congestion Control
end-end control (no network assistance)sender limits transmissionLastByteSent-LastByteAcked
le CongWin
CongWin is dynamic function of perceived network congestion
How does sender perceive congestionloss event = timeout or3 duplicate acksTCP sender reduces rate (CongWin) after loss event
two modes of operationSlow Start (SS)Congestion avoidance (CA) or Additive Increase Multiplicative Decrease (AIMD)
Transport Layer 3-79
TCP congestion control bandwidth probing
ldquoprobing for bandwidthrdquo increase transmission rate on receipt of ACK until eventually loss occurs then decrease transmission rate
continue to increase on ACK decrease on loss (since available bandwidth is changing depending on other connections in network)
ACKs being received so increase rate
X
X
XX
X loss so decrease rate
send
ing
rate
time
Q how fast to increasedecreasedetails to follow
TCPrsquosldquosawtoothrdquobehavior
Transport Layer 3-80
TCP Congestion Control details
sender limits rate by limiting number of unACKed bytes ldquoin pipelinerdquo
cwnd differs from rwnd (how why)sender limited by min(cwndrwnd)
roughly
cwnd is dynamic function of perceived network congestion
rate = cwndRTT bytessec
LastByteSent-LastByteAcked le cwnd
cwndbytes
RTT
ACK(s)
Transport Layer 3-81
TCP Congestion Control more details
segment loss event reducing cwndtimeout no response from receiver
cut cwnd to 13 duplicate ACKs at least some segments getting through (recall fast retransmit)
cut cwnd in half less aggressively than on timeout
ACK received increase cwndTwo modes of operation
slowstart phase bull increase exponentially
fast (despite name) at connection start or following timeout
congestion avoidance bull increase linearly
Transport Layer 3-82
TCP Slow Start Phasewhen connection begins cwnd = 1 MSS
example MSS = 500 bytes amp RTT = 200 msecinitial rate = 20 kbps
available bandwidth may be gtgt MSSRTT
desirable to quickly ramp up to respectable rate
increase rate exponentially until first loss event or when threshold reached
double cwnd every RTTdone by incrementing cwnd by 1 for every ACK received
Host A
one segment
RTT
Host B
time
two segments
four segments
Transport Layer 3-83
Slow Start ExampleThe congestion window size grows very rapidly
For every ACK we increase CongWin by 1 irrespective of the number of segments ACKrsquoeddouble CongWinevery RTTinitial rate is slow but ramps up exponentially fast
TCP slows down the increase of CongWinwhen CongWin gt ssthresh
segment 1
ACK for segment 1
cwnd = 1
cwnd = 2 segment 2segment 3
ACK for segments 2
cwnd = 4 segment 4segment 5segment 6
ACK for segments 4
cwnd = 7
ACK for segments 3
ACK for segments 5
ACK for segments 6
cwnd = 3
cwnd = 5
cwnd = 6ACK for segments 7
cwnd = 8
segment 7
Transport Layer 3-84
TCP Congestion Avoidance Phase
when cwnd gt ssthreshgrow cwnd linearly
increase cwnd by 1 MSS per RTT approach possible congestion slower than in slowstartimplementation cwnd= cwnd + MSScwndfor each ACK received
ACKs increase cwndby 1 MSS per RTT additive increaseloss cut cwnd in half (non-timeout-detected loss ) multiplicative decrease
AIMD
AIMD Additive IncreaseMultiplicative Decrease
Transport Layer 3-85
Congestion AvoidanceCongestion avoidance phase is started if CongWin has reached the slow-start threshold value
If CongWin gt= ssthresh then each time an ACK is received increment CongWin as follows
bull CongWin = CongWin + 1CongWin (CongWin in segments)
bull In actual TCP implementation CongWin is in BytesCongWin = CongWin + MSS (MSSCongWin)
So CongWin is increased by one only if all CongWinsegments have been acknowledged
Transport Layer 3-86
Example Slow StartCongestion AvoidanceAssume that
ssthresh = 8
cwnd = 1
cwnd = 2
cwnd = 4
cwnd = 8
cwnd = 9
cwnd = 10
02468
101214
t=0
t=2
t=4
t=6
Roundtrip times
Cw
nd(in
seg
men
ts)
ssthresh
cwnd = 3
cwnd = 5cwnd = 6cwnd = 7
Transport Layer 3-87
Slow Start Congestion AvoidanceA typical plot of CongWin for a TCP connection
(MSS = 1500 bytes) with TCP Tahoe
SS
CA
ssthresh
Transport Layer 3-88
Responses to CongestionTCP assumes there is congestion if it detects a packet lossA TCP sender can detect lost packets via loss events
bull Timeout of a retransmission timerbull Receipt of 3 duplicate ACKs (fast retransmit)
TCP interprets a Timeout as a binary congestion signal When a timeout occurs the sender performs
ssthresh is set to half the current size of the congestion window
ssthresh = CongWin 2CongWin is reset to one
CongWin = 1and slow-start is entered
Transport Layer 3-89
Fast Recovery (differentiation btwn two loss events) After 3 dup ACKs (fast Retransmit)
ssthresh = CongWin2CongWin = CongWin2window then grows linearly
But after timeout eventCongWin = 1 MSS window then grows exponentiallyto the threshold then grows linearly
bull 3 dup ACKs indicates network capable of delivering some segmentsbull timeout before 3 dup ACKs is ldquomore alarmingrdquo
Philosophy
3-90
TCP Congestion ControlInitially
CongWin = 1ssthresh = advertised window size
New Ack receivedif (CongWin lt ssthresh) Slow Start
CongWin = CongWin + 1else Congestion Avoidance
CongWin = CongWin + 1CongWinTimeout
ssthresh = CongWin2CongWin = 1
Fast Retransmissionssthresh = CongWin2CongWin = CongWin2
Slow Start (exponential increase phase) is continued until CongWin reaches half of the level where the loss event occurred last time CongWin is increased slowly after (linear increase in Congestion Avoidance phase)
Transport Layer 3-91
Popular ldquoflavorsrdquo of TCP
ssthresh
ssthresh
TCP Tahoe
TCP Reno
Transmission round
cwnd
win
dow
siz
e (in
seg
men
ts)
Transport Layer 3-92
Summary TCP Congestion ControlWhen CongWin is below Threshold sender in slow-start phase window grows exponentiallyWhen CongWin is above Threshold sender is in congestion-avoidance phase window grows linearlyWhen a triple duplicate ACK occurs Threshold set to CongWin2 and CongWin set to ThresholdWhen timeout occurs Threshold set to CongWin2 and CongWin is set to 1 MSS The actual sender window size is determined based on the congestion and flow control algorithms
SenderWin=min(RcvWinCongWin)
Transport Layer 3-93
TCP Congestion Control SummaryEvent State TCP Sender Action Commentary
ACK receipt for previously unackeddata
Slow Start (SS)
CongWin = CongWin + MSS If (CongWin gt Threshold)
set state to ldquoCongestion Avoidancerdquo
Resulting in a doubling of CongWin every RTT
ACK receipt for previously unackeddata
CongestionAvoidance (CA)
CongWin = CongWin+MSS (MSSCongWin)
Additive increase resulting in increase of CongWin by 1 MSS every RTT
Loss event detected by triple duplicate ACK
SS or CA Threshold = CongWin2 CongWin = ThresholdSet state to ldquoCongestion Avoidancerdquo
Fast recovery implementing multiplicative decrease CongWin will not drop below 1 MSS
Timeout SS or CA Threshold = CongWin2 CongWin = 1 MSSSet state to ldquoSlow Startrdquo
Enter slow start
Duplicate ACK
SS or CA Increment duplicate ACK count for segment being acked
CongWin and Threshold not changed
Transport Layer 3-94
TCP throughput
Q whatrsquos average throughout of TCP as function of window size RTT
ignoring slow startlet W be window size when loss occurs
when window is W throughput is WRTTjust after loss window drops to W2 throughput to W2RTT average throughout 75 WRTT
Transport Layer 3-95
TCP Futures TCP over ldquolong fat pipesrdquo
example 1500 byte segments 100ms RTT want 10 Gbps throughputrequires window size W = 83333 in-flight segmentsthroughput in terms of loss rate
L = 210-10 Wownew versions of TCP for high-speed
LRTTMSSsdot221
Transport Layer 3-96
Fairness goal if K TCP sessions share same bottleneck link of bandwidth R each should have average rate of RK
TCP connection 1
bottleneckrouter
capacity R
TCP connection 2
TCP Fairness
Transport Layer 3-97
Why is TCP fairTwo competing sessions
Additive increase gives slope of 1 as throughout increasesmultiplicative decrease decreases throughput proportionally
R
R
equal bandwidth share
Connection 1 throughput
Conn
ecti
on 2
thr
ough
p ut
congestion avoidance additive increaseloss decrease window by factor of 2
congestion avoidance additive increaseloss decrease window by factor of 2
Transport Layer 3-98
Fairness (more)Fairness and UDP
Multimedia apps often do not use TCP
do not want rate throttled by congestion control
Instead use UDPpump audiovideo at constant rate tolerate packet loss
Research area TCP friendly
Fairness and parallel TCP connectionsnothing prevents app from opening parallel cnctionsbetween 2 hostsWeb browsers do this Example link of rate R supporting 9 cnctions
new app asks for 1 TCP gets rate R10new app asks for 11 TCPs gets R2
Transport Layer 3-99
TCP Connection ManagementRecall TCP sender receiver
establish ldquoconnectionrdquobefore exchanging data segmentsinitialize TCP variables
seq sbuffers flow control info (eg RcvWindow)
client connection initiatorSocket clientSocket = new Socket(hostnameport
number)
server contacted by clientSocket connectionSocket = welcomeSocketaccept()
Three way handshakeStep 1 client host sends TCP
SYN segment to serverspecifies initial seq no data
Step 2 server host receives SYN replies with SYNACK segment
server allocates buffersspecifies server initial seq
Step 3 client receives SYNACK replies with ACK segment which may contain data
Transport Layer 3-100
TCP Connection Management (cont)
Closing a connection
client closes socketclientSocketclose()
Step 1 client end system sends TCP FIN control segment to server
Step 2 server receives FIN replies with ACK Closes connection sends FIN
client
FIN
server
ACK
ACK
FIN
close
close
closed
tim
ed w
ait
Transport Layer 3-101
TCP Connection Management (cont)
Step 3 client receives FIN replies with ACK
Enters ldquotimed waitrdquo -will respond with ACK to received FINs
Step 4 server receives ACK Connection closed
client
FIN
server
ACK
ACK
FIN
closing
closing
closed
tim
ed w
ait
closed
Transport Layer 3-102
TCP Connection Management (cont)
TCP clientlifecycle
TCP serverlifecycle
Transport Layer 3-103
Tuning TCPIP Parameters TCPIP parameters
A set of default values may not be optimal for all applicationsThe network administrator may wish to turn on or off some TCPIP functions for performance or security considerations
Many Unix and Linux systems provide some flexibility in tuning the TCPIP kernelsbinsysctl is used to configure the Linux kernel parameters at runtime
Default kernel configuration file is sbinsysctlconfFrequently used sysctl options
bull sysctl ndasha or sysctl ndashA list all current valuesbull sysctl ndashp file_name load the sysctl setting from a configuration
filebull sysctl ndashw variable=value change the value of the parameter
Transport Layer 3-104
SomeTCP Parameters in Linux Kerneltcp_syn_retries
Number of SYN packets the kernel will send before giving up on the new connection
tcp_synack_retriesnumber of SYN+ACK packets sent before the kernel gives up on the connection
tcp_window_scalingMaximum window size of 65535 bytes not enough for for really fast networks The window scaling options allows for almost gigabyte windows which is good for connections with large delay-bandwidth product
tcp_max_syn_backlogMaximal number of remembered connection requests which still did not receive an acknowledgment from connecting client
tcp_fin_timeoutHow many seconds to wait for a final FIN packet before the socket is closed required to prevent denial-of-service (DoS) attacks Default value is 60 seconds
Transport Layer 3-105
SomeTCP Parameters in Linux Kerneltcp_rmem
This is a vector of 3 integers [min default max] These parameters are used by TCP to dynamically adjust receive buffer sizesmin - minimum size of the receive buffer used by each TCP socket The default value is 4K default - the default size of the receive buffer for a TCP socket The default value is 87380 bytes and is lowered to 43689 in low memory systems If larger receive buffer sizes are desired this value should be increased max - the maximum size of the receive buffer used by each TCP socket The default value of 873802 bytes is lowered to 87380 in low memory systems
tcp_smemSend buffer parameters [min default max] similar to tcp_rmem
- Chapter 3 Transport Layer
- Transport services and protocols
- Transport vs network layer
- Internet transport-layer protocols
- Multiplexingdemultiplexing
- How demultiplexing works
- Connectionless demultiplexing
- Connection-oriented demux
- Connection-oriented demux (cont)
- Connection-oriented demux Threaded Web Server
- UDP User Datagram Protocol [RFC 768]
- UDP more
- UDP checksum
- Principles of Reliable data transfer
- Reliable data transfer getting started
- Reliable data transfer getting started
- Rdt10 reliable transfer over a reliable channel
- Rdt20 channel with bit errors
- rdt20 FSM specification
- rdt20 operation with no errors
- rdt20 error scenario
- rdt20 has a fatal flaw
- rdt21 sender handles garbled ACKNAKs
- rdt21 receiver handles garbled ACKNAKs
- rdt21 discussion
- rdt22 a NAK-free protocol
- rdt22 sender receiver fragments
- rdt30 channels with errors and loss
- rdt30 sender
- rdt30 in action
- rdt30 in action
- Performance of rdt30
- rdt30 stop-and-wait operation
- Pipelined protocols
- Pipelining increased utilization
- Go-Back-N
- GBN sender extended FSM
- GBN receiver extended FSM
- GBN inaction
- Selective Repeat
- Selective repeat sender receiver windows
- Selective repeat
- Selective repeat in action
- Selective repeat dilemma
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- TCP Overview RFCs 793 1122 1323 2018 2581
- TCP segment structure
- TCP seq rsquos and ACKs
- TCP Round Trip Time and Timeout
- TCP Round Trip Time and Timeout
- Example RTT estimation
- TCP Round Trip Time and Timeout
- TCP reliable data transfer
- TCP sender events
- TCP sender(simplified)
- TCP retransmission scenarios
- TCP retransmission scenarios (more)
- TCP ACK generation [RFC 1122 RFC 2581]
- Fast Retransmit
- Fast Retransmit
- Fast retransmit algorithm
- TCP Flow Control
- TCP Flow control how it works
- Sliding Window Flow Control Example
- Principles of Congestion Control
- Causescosts of congestion scenario 1
- Causescosts of congestion scenario 2
- Causescosts of congestion scenario 2
- Causescosts of congestion scenario 3
- Causescosts of congestion scenario 3
- Approaches towards congestion control
- TCP Congestion Control
- TCP congestion control bandwidth probing
- TCP Congestion Control details
- TCP Congestion Control more details
- TCP Slow Start Phase
- Slow Start Example
- TCP Congestion Avoidance Phase
- Congestion Avoidance
- Example Slow StartCongestion Avoidance
- Slow Start Congestion Avoidance
- Responses to Congestion
- Fast Recovery (differentiation btwn two loss events)
- TCP Congestion Control
- Popular ldquoflavorsrdquo of TCP
- Summary TCP Congestion Control
- TCP Congestion Control Summary
- TCP throughput
- TCP Futures TCP over ldquolong fat pipesrdquo
- TCP Fairness
- Why is TCP fair
- Fairness (more)
- TCP Connection Management
- TCP Connection Management (cont)
- TCP Connection Management (cont)
- TCP Connection Management (cont)
- Tuning TCPIP Parameters
- SomeTCP Parameters in Linux Kernel
- SomeTCP Parameters in Linux Kernel
-
Transport Layer 3-36
Utilization=N(LR)(RTT+LR) if NLRltRTT+LR Utilization=1 if and the sender pauses after it transmits a window NLRgtRTT+LR and the of packets until it receives first ACK sender does not pause
Transport Layer 3-37
Go-Back-NSender
k-bit seq in pkt headerldquowindowrdquo of up to N consecutive unackrsquoed pkts allowed
ACK(n) ACKs all pkts up to including seq n - ldquocumulative ACKrdquomay receive duplicate ACKs (see receiver)
timer for the entire windowtimeout(n) retransmit pkt n and all higher seq pkts in window
Transport Layer 3-38
GBN sender extended FSM
Wait start_timerudt_send(sndpkt[base])udt_send(sndpkt[base+1])hellipudt_send(sndpkt[nextseqnum-1])
timeout
rdt_send(data)
if (nextseqnum lt base+N) sndpkt[nextseqnum] = make_pkt(nextseqnumdatachksum)udt_send(sndpkt[nextseqnum])if (base == nextseqnum)
start_timernextseqnum++
elserefuse_data(data)
base = getacknum(rcvpkt)+1If (base == nextseqnum)
stop_timerelse
start_timer
rdt_rcv(rcvpkt) ampamp notcorrupt(rcvpkt)
base=1nextseqnum=1
rdt_rcv(rcvpkt) ampamp corrupt(rcvpkt)
Λ
Λ
Transport Layer 3-39
GBN receiver extended FSM
ACK-only always send ACK for correctly-received pktwith highest in-order seq
may generate duplicate ACKsneed only remember expectedseqnum
out-of-order pkt discard (donrsquot buffer) -gt no receiver bufferingRe-ACK pkt with highest in-order seq
Wait
udt_send(sndpkt)default
rdt_rcv(rcvpkt)ampamp notcurrupt(rcvpkt)ampamp hasseqnum(rcvpktexpectedseqnum)
extract(rcvpktdata)deliver_data(data)sndpkt = make_pkt(expectedseqnumACKchksum)udt_send(sndpkt)expectedseqnum++
expectedseqnum=1sndpkt =
make_pkt(0ACKchksum)
Λ
Transport Layer 3-40
GBN inaction
Transport Layer 3-41
Selective Repeat
receiver individually acknowledges all correctly received pkts
buffers pkts as needed for eventual in-order delivery to upper layer
sender only resends pkts for which ACK not received
sender timer for each unACKed pktsender window
N consecutive seq rsquosagain limits seq s of sent unACKed pkts
Transport Layer 3-42
Selective repeat sender receiver windows
Transport Layer 3-43
Selective repeat
data from above if next available seq in window send pkt
timeout(n)resend pkt n restart timer
ACK(n) in [sendbasesendbase+N-1]
mark pkt n as receivedif n smallest unACKed pkt advance window base to next unACKed seq
senderpkt n in [rcvbase rcvbase+N-1]
send ACK(n)out-of-order bufferin-order deliver (also deliver buffered in-order pkts) advance window to next not-yet-received pkt
pkt n in [rcvbase-Nrcvbase-1]
ACK(n)otherwise
ignore
receiver
Transport Layer 3-44
Selective repeat in action
Transport Layer 3-45
Selective repeatdilemma
Example seq rsquos 0 1 2 3window size=3
receiver sees no difference in two scenariosincorrectly passes duplicate data as new in (a)
Q what relationship between seq size and window size
Transport Layer 3-46
Sequence Number vs Window SizeSuppose we use k bits to represent SNQuestion Whatrsquos the minimum number of bits k necessary for a window size of N
sender
receiver
Go-Back-N
expectedSN
snd_base=expectedSN
Q For a given expectedSN whatrsquos the largest possible value for snd_baseA If all the last N ACKs sent by the receiver are received
snd_base = expectedSNexpectedSN+N-1
senderrsquos window
Transport Layer 3-47
Sequence Number vs Window SizeSuppose we use k bits to represent SNQuestion Whatrsquos the minimum number of bits k necessary for a window size of N
sender
receiver
Go-Back-N
expectedSN
snd_base=expectedSN-N
Q For a given expectedSN whatrsquos the smallest possible value for snd_baseA If all the last N ACKs sent by the receiver are not received
snd_base = expectedSN-NexpectedSN-1
senderrsquos window
Transport Layer 3-48
Sequence Number vs Window Size
sender
receiver
Go-Back-N
expectedSN
snd_base=expectedSN-N
All SNs in the interval [expectedSN-NexpectedSN+N-1] (an interval of size 2N) can be received by the receiver Since the receiver accepts on the packet with SN=expectedSN there should be no other packet within this interval with SN=expectedSN Therefore
2k ge N+1expectedSN+N-1
Transport Layer 3-49
Sequence Number vs Window SizeSuppose we use k bits to represent SNQuestion Whatrsquos the minimum number of bits k necessary for a window size of N
sender
receiver
Selective Repeat
rcv_base
snd_base=rcv_base
Q For a given rcv_base whatrsquos the largest possible value for snd_baseA If all the last N ACKs sent by the receiver are received
snd_base = rcv_base (same as go_back-N)rcv_base+N-1
senderrsquos window
receiverrsquos window
rcv_base+N-1
Transport Layer 3-50
Sequence Number vs Window SizeSuppose we use k bits to represent SNQuestion Whatrsquos the minimum number of bits k necessary for a window size of N
sender
receiver
Selective Repeat
rcv_base
snd_base=rcv_base-N
Q For a given rcv_base whatrsquos the smallest possible value for snd_baseA If all the last N ACKs sent by the receiver are not received
snd_base = rcv_base-N (same as Go-Back-N)rcv_base-1
senderrsquos window
rcv_base
receiverrsquos window
rcv_base+N-1
Transport Layer 3-51
Sequence Number vs Window Size
sender
receiver
Selective Repeat
snd_base=rcv_base-N
All SNs in the interval [rcv_base-Nrcv_base+N-1] (an interval of size 2N) can be received by the receiver Since the receiver should be able to distinguish between all packets in this interval and take corresponding action there should be no two packets within thisinterval having the same SN Therefore
2k ge 2Nrcv_base+N-1
rcv_basercv_base
receiverrsquos window
rcv_base+N-1
Transport Layer 3-52
TCP Overview RFCs 793 1122 1323 2018 2581
full duplex databi-directional data flow in same connectionMSS maximum segment size
connection-orientedhandshaking (exchange of control msgs) initrsquossender receiver state before data exchange
flow controlledsender will not overwhelm receiver
point-to-pointone sender one receiver
reliable in-order byte stream
no ldquomessage boundariesrdquopipelined
TCP congestion and flow control set window size
send amp receive buffers
socketdoor
TCPsend buffer
TCPreceive buffer
socketdoor
segment
applicationwrites data
applicationreads data
Transport Layer 3-53
TCP segment structure
source port dest port
32 bits
applicationdata
(variable length)
sequence numberacknowledgement number
Receive windowUrg data pnterchecksum
FSRPAUheadlen
notused
Options (variable length)
URG urgent data (generally not used)
ACK ACK valid
PSH push data now(generally not used)
RST SYN FINconnection estab(setup teardown
commands)
bytes rcvr willingto accept
Internetchecksum
(as in UDP)
countingby bytes of data(not segments)
Transport Layer 3-54
TCP seq rsquos and ACKsSeq rsquos
byte stream ldquonumberrdquo of first byte in segmentrsquos dataACKs
seq of next byte expected from other sidecumulative ACK
Q how receiver handles out-of-order segmentsA TCP spec doesnrsquot say - up to implementationWidely used implementations of TCP buffer out-of-order segments
Transport Layer 3-55
TCP Round Trip Time and Timeout
Q how to set TCP timeout valuelonger than RTT
but RTT variestoo short premature timeout
unnecessary retransmissions
too long slow reaction to segment loss
Q how to estimate RTTSampleRTT measured time from segment transmission until ACK receipt
ignore retransmissionsSampleRTT will vary want estimated RTT ldquosmootherrdquo
average several recent measurements not just current SampleRTT
Transport Layer 3-56
TCP Round Trip Time and Timeout
EstimatedRTT = (1- α)EstimatedRTT + αSampleRTT
Exponential weighted moving averageinfluence of past sample decreases exponentially fasttypical value α = 0125
Transport Layer 3-57
Example RTT estimationRTT gaiacsumassedu to fantasiaeurecomfr
100
150
200
250
300
350
1 8 15 22 29 36 43 50 57 64 71 78 85 92 99 106
time (seconnds)
RTT
(mill
iseco
nds)
SampleRTT Estimated RTT
Transport Layer 3-58
TCP Round Trip Time and TimeoutSetting the timeout
EstimatedRTT plus ldquosafety marginrdquolarge variation in EstimatedRTT -gt larger safety margin
first estimate of how much SampleRTT deviates from EstimatedRTT
TimeoutInterval = EstimatedRTT + 4DevRTT
DevRTT = (1-β)DevRTT +β|SampleRTT-EstimatedRTT|
(typically β = 025)
Then set timeout interval
Transport Layer 3-59
TCP reliable data transfer
TCP creates rdtservice on top of IPrsquos unreliable servicePipelined segmentsCumulative acksTCP uses single retransmission timer however it just retransmits the first segment in the window
Retransmissions are triggered by
timeout eventsduplicate acks
Initially consider simplified TCP sender
ignore duplicate acksignore flow control congestion control
Transport Layer 3-60
TCP sender eventsdata rcvd from app
Create segment with seq seq is byte-stream number of first data byte in segmentstart timer if not already running (think of timer as for oldest unacked segment)expiration interval TimeOutInterval
timeoutretransmit segment that caused timeout (first segment in the window)restart timer
Ack rcvdIf acknowledges previously unacked segments
update what is known to be ackedstart timer if there are outstanding segments
Transport Layer 3-61
TCP sender(simplified)
NextSeqNum = InitialSeqNumSendBase = InitialSeqNum
loop (forever) switch(event)
event data received from application above create TCP segment with sequence number NextSeqNumif (timer currently not running)
start timerpass segment to IP NextSeqNum = NextSeqNum + length(data)
event timer timeoutretransmit not-yet-acknowledged segment with
smallest sequence numberstart timer
event ACK received with ACK field value of y if (y gt SendBase)
SendBase = yif (there are currently not-yet-acknowledged segments)
start timer
end of loop forever
Commentbull SendBase-1 last cumulatively ackrsquoed byteExamplebull SendBase-1 = 71y= 73 so the rcvrwants 73+ y gt SendBase sothat new data is acked
Transport Layer 3-62
TCP retransmission scenariosHost A
Seq=100 20 bytes data
ACK=100
timepremature timeout
Host B
Seq=92 8 bytes data
ACK=120
Seq=92 8 bytes data
Seq=
92 t
imeo
ut
ACK=120
Host A
Seq=92 8 bytes data
ACK=100
loss
tim
eout
lost ACK scenario
Host B
X
Seq=92 8 bytes data
ACK=100
time
Seq=
92 t
imeo
utSendBase
= 100
SendBase= 120
SendBase= 120
Sendbase= 100
Transport Layer 3-63
TCP retransmission scenarios (more)Host A
Seq=92 8 bytes data
ACK=100
loss
tim
eout
Cumulative ACK scenario
Host B
X
Seq=100 20 bytes data
ACK=120
time
SendBase= 120
Transport Layer 3-64
TCP ACK generation [RFC 1122 RFC 2581]
Event at Receiver
Arrival of in-order segment withexpected seq All data up toexpected seq already ACKed
Arrival of in-order segment withexpected seq One other segment has ACK pending
Arrival of out-of-order segmenthigher-than-expect seq Gap detected
Arrival of segment that partially or completely fills gap
TCP Receiver action
Delayed ACK Wait up to 500msfor next segment If no next segmentsend ACK
Immediately send single cumulative ACK ACKing both in-order segments
Immediately send duplicate ACK indicating seq of next expected byte
Immediate send ACK provided thatsegment startsat lower end of gap
Transport Layer 3-65
Fast Retransmit
Time-out period often relatively long
long delay before resending lost packet
Detect lost segments via duplicate ACKs
Sender often sends many segments back-to-backIf segment is lost there will likely be many duplicate ACKs
If sender receives 3 ACKs for the same data it supposes that segment after ACKeddata was lost
fast retransmit resend segment before timer expires
Transport Layer 3-66
Fast RetransmitResend a segment after 3 duplicate ACKs since a duplicate ACK means that an out-of sequence segment was receivedduplicate ACKs due to packet reorderingif window is small donrsquot get duplicate ACKs
Host A
tim
eout
Host B
time
X
resend seq X2
seq x1seq x2seq x3seq x4seq x5
ACK x1
ACK x1ACK x1ACK x1
tripleduplicate
ACKs
Transport Layer 3-67
event ACK received with ACK field value of y if (y gt SendBase)
SendBase = yif (there are currently not-yet-acknowledged segments)
start timer
else increment count of dup ACKs received for yif (count of dup ACKs received for y = 3)
resend segment with sequence number y
Fast retransmit algorithm
a duplicate ACK for already ACKed segment
fast retransmit
Transport Layer 3-68
TCP Flow Control
receive side of TCP connection has a receive buffer
speed-matching service matching the send rate to the receiving apprsquos drain rate
app process may be slow at reading from buffer
sender wonrsquot overflowreceiverrsquos buffer by
transmitting too muchtoo fast
flow control
Transport Layer 3-69
TCP Flow control how it works
(Suppose TCP receiver discards out-of-order segments)spare room in buffer
= RcvWin
= RcvBuffer-[LastByteRcvd -LastByteRead]
Rcvr advertises spare room by including value of RcvWin in segmentsSender limits unACKeddata to RcvWin
guarantees receive buffer doesnrsquot overflow
Transport Layer 3-70
Sliding Window Flow Control Example
3K
2K SeqNo=0
ReceiverBuffer
0 4KSendersends 2Kof data
2K
AckNo=2048 RcvWin=2048Sendersends 2Kof data 2K SeqNo=2048
4K
AckNo=4096 RcvWin=0
AckNo=4096 RcvWin=1024
Sender blocked
Transport Layer 3-71
Principles of Congestion Control
Congestioninformally ldquotoo many sources sending too much data too fast for network to handlerdquodifferent from flow controlmanifestations
lost packets (buffer overflow at routers)long delays (queueing in router buffers)
a top-10 problem
Transport Layer 3-72
Causescosts of congestion scenario 1
two senders two receiversone router infinite buffers no retransmission
large delays when congestedmaximum achievable throughput
unlimited shared output link buffers
Host Aλin original data
Host B
λout
Transport Layer 3-73
Causescosts of congestion scenario 2
one router finite buffers sender retransmission of lost packet
finite shared output link buffers
Host A λin original data
Host B
λout
λin original data plus retransmitted data
Transport Layer 3-74
Causescosts of congestion scenario 2always (goodput)ldquoperfectrdquo retransmission only when loss
retransmission of delayed (not lost) packet makes larger(than perfect case) for same
λin
λout=
λin
λoutgtλ
inλout
ldquocostsrdquo of congestionmore work (retrans) for given ldquogoodputrdquounneeded retransmissions link carries multiple copies of pkt
R2
R2λin
λ out
b
R2
R2λin
λ out
a
R2
R2λin
λ out
c
R4
R3
Transport Layer 3-75
Causescosts of congestion scenario 3four sendersmultihop pathstimeoutretransmit
λin
Q what happens as and increase λ
in
finite shared output link buffers
Host Aλin original data
Host B
λout
λin original data plus retransmitted data
Transport Layer 3-76
Causescosts of congestion scenario 3
another ldquocostrdquo of congestionwhen packet dropped any ldquoupstream transmission capacity used for that packet was wasted
Host A
Host B
λou
t
Transport Layer 3-77
Approaches towards congestion control
End-end congestion controlno explicit feedback from networkcongestion inferred from end-system observed loss delayapproach taken by TCP
Network-assisted congestion controlrouters provide feedback to end systems
single bit indicating congestion (SNA DECbit TCPIP ECN ATM)explicit rate sender should send at
Two broad approaches towards congestion control
Transport Layer 3-78
TCP Congestion Control
end-end control (no network assistance)sender limits transmissionLastByteSent-LastByteAcked
le CongWin
CongWin is dynamic function of perceived network congestion
How does sender perceive congestionloss event = timeout or3 duplicate acksTCP sender reduces rate (CongWin) after loss event
two modes of operationSlow Start (SS)Congestion avoidance (CA) or Additive Increase Multiplicative Decrease (AIMD)
Transport Layer 3-79
TCP congestion control bandwidth probing
ldquoprobing for bandwidthrdquo increase transmission rate on receipt of ACK until eventually loss occurs then decrease transmission rate
continue to increase on ACK decrease on loss (since available bandwidth is changing depending on other connections in network)
ACKs being received so increase rate
X
X
XX
X loss so decrease rate
send
ing
rate
time
Q how fast to increasedecreasedetails to follow
TCPrsquosldquosawtoothrdquobehavior
Transport Layer 3-80
TCP Congestion Control details
sender limits rate by limiting number of unACKed bytes ldquoin pipelinerdquo
cwnd differs from rwnd (how why)sender limited by min(cwndrwnd)
roughly
cwnd is dynamic function of perceived network congestion
rate = cwndRTT bytessec
LastByteSent-LastByteAcked le cwnd
cwndbytes
RTT
ACK(s)
Transport Layer 3-81
TCP Congestion Control more details
segment loss event reducing cwndtimeout no response from receiver
cut cwnd to 13 duplicate ACKs at least some segments getting through (recall fast retransmit)
cut cwnd in half less aggressively than on timeout
ACK received increase cwndTwo modes of operation
slowstart phase bull increase exponentially
fast (despite name) at connection start or following timeout
congestion avoidance bull increase linearly
Transport Layer 3-82
TCP Slow Start Phasewhen connection begins cwnd = 1 MSS
example MSS = 500 bytes amp RTT = 200 msecinitial rate = 20 kbps
available bandwidth may be gtgt MSSRTT
desirable to quickly ramp up to respectable rate
increase rate exponentially until first loss event or when threshold reached
double cwnd every RTTdone by incrementing cwnd by 1 for every ACK received
Host A
one segment
RTT
Host B
time
two segments
four segments
Transport Layer 3-83
Slow Start ExampleThe congestion window size grows very rapidly
For every ACK we increase CongWin by 1 irrespective of the number of segments ACKrsquoeddouble CongWinevery RTTinitial rate is slow but ramps up exponentially fast
TCP slows down the increase of CongWinwhen CongWin gt ssthresh
segment 1
ACK for segment 1
cwnd = 1
cwnd = 2 segment 2segment 3
ACK for segments 2
cwnd = 4 segment 4segment 5segment 6
ACK for segments 4
cwnd = 7
ACK for segments 3
ACK for segments 5
ACK for segments 6
cwnd = 3
cwnd = 5
cwnd = 6ACK for segments 7
cwnd = 8
segment 7
Transport Layer 3-84
TCP Congestion Avoidance Phase
when cwnd gt ssthreshgrow cwnd linearly
increase cwnd by 1 MSS per RTT approach possible congestion slower than in slowstartimplementation cwnd= cwnd + MSScwndfor each ACK received
ACKs increase cwndby 1 MSS per RTT additive increaseloss cut cwnd in half (non-timeout-detected loss ) multiplicative decrease
AIMD
AIMD Additive IncreaseMultiplicative Decrease
Transport Layer 3-85
Congestion AvoidanceCongestion avoidance phase is started if CongWin has reached the slow-start threshold value
If CongWin gt= ssthresh then each time an ACK is received increment CongWin as follows
bull CongWin = CongWin + 1CongWin (CongWin in segments)
bull In actual TCP implementation CongWin is in BytesCongWin = CongWin + MSS (MSSCongWin)
So CongWin is increased by one only if all CongWinsegments have been acknowledged
Transport Layer 3-86
Example Slow StartCongestion AvoidanceAssume that
ssthresh = 8
cwnd = 1
cwnd = 2
cwnd = 4
cwnd = 8
cwnd = 9
cwnd = 10
02468
101214
t=0
t=2
t=4
t=6
Roundtrip times
Cw
nd(in
seg
men
ts)
ssthresh
cwnd = 3
cwnd = 5cwnd = 6cwnd = 7
Transport Layer 3-87
Slow Start Congestion AvoidanceA typical plot of CongWin for a TCP connection
(MSS = 1500 bytes) with TCP Tahoe
SS
CA
ssthresh
Transport Layer 3-88
Responses to CongestionTCP assumes there is congestion if it detects a packet lossA TCP sender can detect lost packets via loss events
bull Timeout of a retransmission timerbull Receipt of 3 duplicate ACKs (fast retransmit)
TCP interprets a Timeout as a binary congestion signal When a timeout occurs the sender performs
ssthresh is set to half the current size of the congestion window
ssthresh = CongWin 2CongWin is reset to one
CongWin = 1and slow-start is entered
Transport Layer 3-89
Fast Recovery (differentiation btwn two loss events) After 3 dup ACKs (fast Retransmit)
ssthresh = CongWin2CongWin = CongWin2window then grows linearly
But after timeout eventCongWin = 1 MSS window then grows exponentiallyto the threshold then grows linearly
bull 3 dup ACKs indicates network capable of delivering some segmentsbull timeout before 3 dup ACKs is ldquomore alarmingrdquo
Philosophy
3-90
TCP Congestion ControlInitially
CongWin = 1ssthresh = advertised window size
New Ack receivedif (CongWin lt ssthresh) Slow Start
CongWin = CongWin + 1else Congestion Avoidance
CongWin = CongWin + 1CongWinTimeout
ssthresh = CongWin2CongWin = 1
Fast Retransmissionssthresh = CongWin2CongWin = CongWin2
Slow Start (exponential increase phase) is continued until CongWin reaches half of the level where the loss event occurred last time CongWin is increased slowly after (linear increase in Congestion Avoidance phase)
Transport Layer 3-91
Popular ldquoflavorsrdquo of TCP
ssthresh
ssthresh
TCP Tahoe
TCP Reno
Transmission round
cwnd
win
dow
siz
e (in
seg
men
ts)
Transport Layer 3-92
Summary TCP Congestion ControlWhen CongWin is below Threshold sender in slow-start phase window grows exponentiallyWhen CongWin is above Threshold sender is in congestion-avoidance phase window grows linearlyWhen a triple duplicate ACK occurs Threshold set to CongWin2 and CongWin set to ThresholdWhen timeout occurs Threshold set to CongWin2 and CongWin is set to 1 MSS The actual sender window size is determined based on the congestion and flow control algorithms
SenderWin=min(RcvWinCongWin)
Transport Layer 3-93
TCP Congestion Control SummaryEvent State TCP Sender Action Commentary
ACK receipt for previously unackeddata
Slow Start (SS)
CongWin = CongWin + MSS If (CongWin gt Threshold)
set state to ldquoCongestion Avoidancerdquo
Resulting in a doubling of CongWin every RTT
ACK receipt for previously unackeddata
CongestionAvoidance (CA)
CongWin = CongWin+MSS (MSSCongWin)
Additive increase resulting in increase of CongWin by 1 MSS every RTT
Loss event detected by triple duplicate ACK
SS or CA Threshold = CongWin2 CongWin = ThresholdSet state to ldquoCongestion Avoidancerdquo
Fast recovery implementing multiplicative decrease CongWin will not drop below 1 MSS
Timeout SS or CA Threshold = CongWin2 CongWin = 1 MSSSet state to ldquoSlow Startrdquo
Enter slow start
Duplicate ACK
SS or CA Increment duplicate ACK count for segment being acked
CongWin and Threshold not changed
Transport Layer 3-94
TCP throughput
Q whatrsquos average throughout of TCP as function of window size RTT
ignoring slow startlet W be window size when loss occurs
when window is W throughput is WRTTjust after loss window drops to W2 throughput to W2RTT average throughout 75 WRTT
Transport Layer 3-95
TCP Futures TCP over ldquolong fat pipesrdquo
example 1500 byte segments 100ms RTT want 10 Gbps throughputrequires window size W = 83333 in-flight segmentsthroughput in terms of loss rate
L = 210-10 Wownew versions of TCP for high-speed
LRTTMSSsdot221
Transport Layer 3-96
Fairness goal if K TCP sessions share same bottleneck link of bandwidth R each should have average rate of RK
TCP connection 1
bottleneckrouter
capacity R
TCP connection 2
TCP Fairness
Transport Layer 3-97
Why is TCP fairTwo competing sessions
Additive increase gives slope of 1 as throughout increasesmultiplicative decrease decreases throughput proportionally
R
R
equal bandwidth share
Connection 1 throughput
Conn
ecti
on 2
thr
ough
p ut
congestion avoidance additive increaseloss decrease window by factor of 2
congestion avoidance additive increaseloss decrease window by factor of 2
Transport Layer 3-98
Fairness (more)Fairness and UDP
Multimedia apps often do not use TCP
do not want rate throttled by congestion control
Instead use UDPpump audiovideo at constant rate tolerate packet loss
Research area TCP friendly
Fairness and parallel TCP connectionsnothing prevents app from opening parallel cnctionsbetween 2 hostsWeb browsers do this Example link of rate R supporting 9 cnctions
new app asks for 1 TCP gets rate R10new app asks for 11 TCPs gets R2
Transport Layer 3-99
TCP Connection ManagementRecall TCP sender receiver
establish ldquoconnectionrdquobefore exchanging data segmentsinitialize TCP variables
seq sbuffers flow control info (eg RcvWindow)
client connection initiatorSocket clientSocket = new Socket(hostnameport
number)
server contacted by clientSocket connectionSocket = welcomeSocketaccept()
Three way handshakeStep 1 client host sends TCP
SYN segment to serverspecifies initial seq no data
Step 2 server host receives SYN replies with SYNACK segment
server allocates buffersspecifies server initial seq
Step 3 client receives SYNACK replies with ACK segment which may contain data
Transport Layer 3-100
TCP Connection Management (cont)
Closing a connection
client closes socketclientSocketclose()
Step 1 client end system sends TCP FIN control segment to server
Step 2 server receives FIN replies with ACK Closes connection sends FIN
client
FIN
server
ACK
ACK
FIN
close
close
closed
tim
ed w
ait
Transport Layer 3-101
TCP Connection Management (cont)
Step 3 client receives FIN replies with ACK
Enters ldquotimed waitrdquo -will respond with ACK to received FINs
Step 4 server receives ACK Connection closed
client
FIN
server
ACK
ACK
FIN
closing
closing
closed
tim
ed w
ait
closed
Transport Layer 3-102
TCP Connection Management (cont)
TCP clientlifecycle
TCP serverlifecycle
Transport Layer 3-103
Tuning TCPIP Parameters TCPIP parameters
A set of default values may not be optimal for all applicationsThe network administrator may wish to turn on or off some TCPIP functions for performance or security considerations
Many Unix and Linux systems provide some flexibility in tuning the TCPIP kernelsbinsysctl is used to configure the Linux kernel parameters at runtime
Default kernel configuration file is sbinsysctlconfFrequently used sysctl options
bull sysctl ndasha or sysctl ndashA list all current valuesbull sysctl ndashp file_name load the sysctl setting from a configuration
filebull sysctl ndashw variable=value change the value of the parameter
Transport Layer 3-104
SomeTCP Parameters in Linux Kerneltcp_syn_retries
Number of SYN packets the kernel will send before giving up on the new connection
tcp_synack_retriesnumber of SYN+ACK packets sent before the kernel gives up on the connection
tcp_window_scalingMaximum window size of 65535 bytes not enough for for really fast networks The window scaling options allows for almost gigabyte windows which is good for connections with large delay-bandwidth product
tcp_max_syn_backlogMaximal number of remembered connection requests which still did not receive an acknowledgment from connecting client
tcp_fin_timeoutHow many seconds to wait for a final FIN packet before the socket is closed required to prevent denial-of-service (DoS) attacks Default value is 60 seconds
Transport Layer 3-105
SomeTCP Parameters in Linux Kerneltcp_rmem
This is a vector of 3 integers [min default max] These parameters are used by TCP to dynamically adjust receive buffer sizesmin - minimum size of the receive buffer used by each TCP socket The default value is 4K default - the default size of the receive buffer for a TCP socket The default value is 87380 bytes and is lowered to 43689 in low memory systems If larger receive buffer sizes are desired this value should be increased max - the maximum size of the receive buffer used by each TCP socket The default value of 873802 bytes is lowered to 87380 in low memory systems
tcp_smemSend buffer parameters [min default max] similar to tcp_rmem
- Chapter 3 Transport Layer
- Transport services and protocols
- Transport vs network layer
- Internet transport-layer protocols
- Multiplexingdemultiplexing
- How demultiplexing works
- Connectionless demultiplexing
- Connection-oriented demux
- Connection-oriented demux (cont)
- Connection-oriented demux Threaded Web Server
- UDP User Datagram Protocol [RFC 768]
- UDP more
- UDP checksum
- Principles of Reliable data transfer
- Reliable data transfer getting started
- Reliable data transfer getting started
- Rdt10 reliable transfer over a reliable channel
- Rdt20 channel with bit errors
- rdt20 FSM specification
- rdt20 operation with no errors
- rdt20 error scenario
- rdt20 has a fatal flaw
- rdt21 sender handles garbled ACKNAKs
- rdt21 receiver handles garbled ACKNAKs
- rdt21 discussion
- rdt22 a NAK-free protocol
- rdt22 sender receiver fragments
- rdt30 channels with errors and loss
- rdt30 sender
- rdt30 in action
- rdt30 in action
- Performance of rdt30
- rdt30 stop-and-wait operation
- Pipelined protocols
- Pipelining increased utilization
- Go-Back-N
- GBN sender extended FSM
- GBN receiver extended FSM
- GBN inaction
- Selective Repeat
- Selective repeat sender receiver windows
- Selective repeat
- Selective repeat in action
- Selective repeat dilemma
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- TCP Overview RFCs 793 1122 1323 2018 2581
- TCP segment structure
- TCP seq rsquos and ACKs
- TCP Round Trip Time and Timeout
- TCP Round Trip Time and Timeout
- Example RTT estimation
- TCP Round Trip Time and Timeout
- TCP reliable data transfer
- TCP sender events
- TCP sender(simplified)
- TCP retransmission scenarios
- TCP retransmission scenarios (more)
- TCP ACK generation [RFC 1122 RFC 2581]
- Fast Retransmit
- Fast Retransmit
- Fast retransmit algorithm
- TCP Flow Control
- TCP Flow control how it works
- Sliding Window Flow Control Example
- Principles of Congestion Control
- Causescosts of congestion scenario 1
- Causescosts of congestion scenario 2
- Causescosts of congestion scenario 2
- Causescosts of congestion scenario 3
- Causescosts of congestion scenario 3
- Approaches towards congestion control
- TCP Congestion Control
- TCP congestion control bandwidth probing
- TCP Congestion Control details
- TCP Congestion Control more details
- TCP Slow Start Phase
- Slow Start Example
- TCP Congestion Avoidance Phase
- Congestion Avoidance
- Example Slow StartCongestion Avoidance
- Slow Start Congestion Avoidance
- Responses to Congestion
- Fast Recovery (differentiation btwn two loss events)
- TCP Congestion Control
- Popular ldquoflavorsrdquo of TCP
- Summary TCP Congestion Control
- TCP Congestion Control Summary
- TCP throughput
- TCP Futures TCP over ldquolong fat pipesrdquo
- TCP Fairness
- Why is TCP fair
- Fairness (more)
- TCP Connection Management
- TCP Connection Management (cont)
- TCP Connection Management (cont)
- TCP Connection Management (cont)
- Tuning TCPIP Parameters
- SomeTCP Parameters in Linux Kernel
- SomeTCP Parameters in Linux Kernel
-
Transport Layer 3-37
Go-Back-NSender
k-bit seq in pkt headerldquowindowrdquo of up to N consecutive unackrsquoed pkts allowed
ACK(n) ACKs all pkts up to including seq n - ldquocumulative ACKrdquomay receive duplicate ACKs (see receiver)
timer for the entire windowtimeout(n) retransmit pkt n and all higher seq pkts in window
Transport Layer 3-38
GBN sender extended FSM
Wait start_timerudt_send(sndpkt[base])udt_send(sndpkt[base+1])hellipudt_send(sndpkt[nextseqnum-1])
timeout
rdt_send(data)
if (nextseqnum lt base+N) sndpkt[nextseqnum] = make_pkt(nextseqnumdatachksum)udt_send(sndpkt[nextseqnum])if (base == nextseqnum)
start_timernextseqnum++
elserefuse_data(data)
base = getacknum(rcvpkt)+1If (base == nextseqnum)
stop_timerelse
start_timer
rdt_rcv(rcvpkt) ampamp notcorrupt(rcvpkt)
base=1nextseqnum=1
rdt_rcv(rcvpkt) ampamp corrupt(rcvpkt)
Λ
Λ
Transport Layer 3-39
GBN receiver extended FSM
ACK-only always send ACK for correctly-received pktwith highest in-order seq
may generate duplicate ACKsneed only remember expectedseqnum
out-of-order pkt discard (donrsquot buffer) -gt no receiver bufferingRe-ACK pkt with highest in-order seq
Wait
udt_send(sndpkt)default
rdt_rcv(rcvpkt)ampamp notcurrupt(rcvpkt)ampamp hasseqnum(rcvpktexpectedseqnum)
extract(rcvpktdata)deliver_data(data)sndpkt = make_pkt(expectedseqnumACKchksum)udt_send(sndpkt)expectedseqnum++
expectedseqnum=1sndpkt =
make_pkt(0ACKchksum)
Λ
Transport Layer 3-40
GBN inaction
Transport Layer 3-41
Selective Repeat
receiver individually acknowledges all correctly received pkts
buffers pkts as needed for eventual in-order delivery to upper layer
sender only resends pkts for which ACK not received
sender timer for each unACKed pktsender window
N consecutive seq rsquosagain limits seq s of sent unACKed pkts
Transport Layer 3-42
Selective repeat sender receiver windows
Transport Layer 3-43
Selective repeat
data from above if next available seq in window send pkt
timeout(n)resend pkt n restart timer
ACK(n) in [sendbasesendbase+N-1]
mark pkt n as receivedif n smallest unACKed pkt advance window base to next unACKed seq
senderpkt n in [rcvbase rcvbase+N-1]
send ACK(n)out-of-order bufferin-order deliver (also deliver buffered in-order pkts) advance window to next not-yet-received pkt
pkt n in [rcvbase-Nrcvbase-1]
ACK(n)otherwise
ignore
receiver
Transport Layer 3-44
Selective repeat in action
Transport Layer 3-45
Selective repeatdilemma
Example seq rsquos 0 1 2 3window size=3
receiver sees no difference in two scenariosincorrectly passes duplicate data as new in (a)
Q what relationship between seq size and window size
Transport Layer 3-46
Sequence Number vs Window SizeSuppose we use k bits to represent SNQuestion Whatrsquos the minimum number of bits k necessary for a window size of N
sender
receiver
Go-Back-N
expectedSN
snd_base=expectedSN
Q For a given expectedSN whatrsquos the largest possible value for snd_baseA If all the last N ACKs sent by the receiver are received
snd_base = expectedSNexpectedSN+N-1
senderrsquos window
Transport Layer 3-47
Sequence Number vs Window SizeSuppose we use k bits to represent SNQuestion Whatrsquos the minimum number of bits k necessary for a window size of N
sender
receiver
Go-Back-N
expectedSN
snd_base=expectedSN-N
Q For a given expectedSN whatrsquos the smallest possible value for snd_baseA If all the last N ACKs sent by the receiver are not received
snd_base = expectedSN-NexpectedSN-1
senderrsquos window
Transport Layer 3-48
Sequence Number vs Window Size
sender
receiver
Go-Back-N
expectedSN
snd_base=expectedSN-N
All SNs in the interval [expectedSN-NexpectedSN+N-1] (an interval of size 2N) can be received by the receiver Since the receiver accepts on the packet with SN=expectedSN there should be no other packet within this interval with SN=expectedSN Therefore
2k ge N+1expectedSN+N-1
Transport Layer 3-49
Sequence Number vs Window SizeSuppose we use k bits to represent SNQuestion Whatrsquos the minimum number of bits k necessary for a window size of N
sender
receiver
Selective Repeat
rcv_base
snd_base=rcv_base
Q For a given rcv_base whatrsquos the largest possible value for snd_baseA If all the last N ACKs sent by the receiver are received
snd_base = rcv_base (same as go_back-N)rcv_base+N-1
senderrsquos window
receiverrsquos window
rcv_base+N-1
Transport Layer 3-50
Sequence Number vs Window SizeSuppose we use k bits to represent SNQuestion Whatrsquos the minimum number of bits k necessary for a window size of N
sender
receiver
Selective Repeat
rcv_base
snd_base=rcv_base-N
Q For a given rcv_base whatrsquos the smallest possible value for snd_baseA If all the last N ACKs sent by the receiver are not received
snd_base = rcv_base-N (same as Go-Back-N)rcv_base-1
senderrsquos window
rcv_base
receiverrsquos window
rcv_base+N-1
Transport Layer 3-51
Sequence Number vs Window Size
sender
receiver
Selective Repeat
snd_base=rcv_base-N
All SNs in the interval [rcv_base-Nrcv_base+N-1] (an interval of size 2N) can be received by the receiver Since the receiver should be able to distinguish between all packets in this interval and take corresponding action there should be no two packets within thisinterval having the same SN Therefore
2k ge 2Nrcv_base+N-1
rcv_basercv_base
receiverrsquos window
rcv_base+N-1
Transport Layer 3-52
TCP Overview RFCs 793 1122 1323 2018 2581
full duplex databi-directional data flow in same connectionMSS maximum segment size
connection-orientedhandshaking (exchange of control msgs) initrsquossender receiver state before data exchange
flow controlledsender will not overwhelm receiver
point-to-pointone sender one receiver
reliable in-order byte stream
no ldquomessage boundariesrdquopipelined
TCP congestion and flow control set window size
send amp receive buffers
socketdoor
TCPsend buffer
TCPreceive buffer
socketdoor
segment
applicationwrites data
applicationreads data
Transport Layer 3-53
TCP segment structure
source port dest port
32 bits
applicationdata
(variable length)
sequence numberacknowledgement number
Receive windowUrg data pnterchecksum
FSRPAUheadlen
notused
Options (variable length)
URG urgent data (generally not used)
ACK ACK valid
PSH push data now(generally not used)
RST SYN FINconnection estab(setup teardown
commands)
bytes rcvr willingto accept
Internetchecksum
(as in UDP)
countingby bytes of data(not segments)
Transport Layer 3-54
TCP seq rsquos and ACKsSeq rsquos
byte stream ldquonumberrdquo of first byte in segmentrsquos dataACKs
seq of next byte expected from other sidecumulative ACK
Q how receiver handles out-of-order segmentsA TCP spec doesnrsquot say - up to implementationWidely used implementations of TCP buffer out-of-order segments
Transport Layer 3-55
TCP Round Trip Time and Timeout
Q how to set TCP timeout valuelonger than RTT
but RTT variestoo short premature timeout
unnecessary retransmissions
too long slow reaction to segment loss
Q how to estimate RTTSampleRTT measured time from segment transmission until ACK receipt
ignore retransmissionsSampleRTT will vary want estimated RTT ldquosmootherrdquo
average several recent measurements not just current SampleRTT
Transport Layer 3-56
TCP Round Trip Time and Timeout
EstimatedRTT = (1- α)EstimatedRTT + αSampleRTT
Exponential weighted moving averageinfluence of past sample decreases exponentially fasttypical value α = 0125
Transport Layer 3-57
Example RTT estimationRTT gaiacsumassedu to fantasiaeurecomfr
100
150
200
250
300
350
1 8 15 22 29 36 43 50 57 64 71 78 85 92 99 106
time (seconnds)
RTT
(mill
iseco
nds)
SampleRTT Estimated RTT
Transport Layer 3-58
TCP Round Trip Time and TimeoutSetting the timeout
EstimatedRTT plus ldquosafety marginrdquolarge variation in EstimatedRTT -gt larger safety margin
first estimate of how much SampleRTT deviates from EstimatedRTT
TimeoutInterval = EstimatedRTT + 4DevRTT
DevRTT = (1-β)DevRTT +β|SampleRTT-EstimatedRTT|
(typically β = 025)
Then set timeout interval
Transport Layer 3-59
TCP reliable data transfer
TCP creates rdtservice on top of IPrsquos unreliable servicePipelined segmentsCumulative acksTCP uses single retransmission timer however it just retransmits the first segment in the window
Retransmissions are triggered by
timeout eventsduplicate acks
Initially consider simplified TCP sender
ignore duplicate acksignore flow control congestion control
Transport Layer 3-60
TCP sender eventsdata rcvd from app
Create segment with seq seq is byte-stream number of first data byte in segmentstart timer if not already running (think of timer as for oldest unacked segment)expiration interval TimeOutInterval
timeoutretransmit segment that caused timeout (first segment in the window)restart timer
Ack rcvdIf acknowledges previously unacked segments
update what is known to be ackedstart timer if there are outstanding segments
Transport Layer 3-61
TCP sender(simplified)
NextSeqNum = InitialSeqNumSendBase = InitialSeqNum
loop (forever) switch(event)
event data received from application above create TCP segment with sequence number NextSeqNumif (timer currently not running)
start timerpass segment to IP NextSeqNum = NextSeqNum + length(data)
event timer timeoutretransmit not-yet-acknowledged segment with
smallest sequence numberstart timer
event ACK received with ACK field value of y if (y gt SendBase)
SendBase = yif (there are currently not-yet-acknowledged segments)
start timer
end of loop forever
Commentbull SendBase-1 last cumulatively ackrsquoed byteExamplebull SendBase-1 = 71y= 73 so the rcvrwants 73+ y gt SendBase sothat new data is acked
Transport Layer 3-62
TCP retransmission scenariosHost A
Seq=100 20 bytes data
ACK=100
timepremature timeout
Host B
Seq=92 8 bytes data
ACK=120
Seq=92 8 bytes data
Seq=
92 t
imeo
ut
ACK=120
Host A
Seq=92 8 bytes data
ACK=100
loss
tim
eout
lost ACK scenario
Host B
X
Seq=92 8 bytes data
ACK=100
time
Seq=
92 t
imeo
utSendBase
= 100
SendBase= 120
SendBase= 120
Sendbase= 100
Transport Layer 3-63
TCP retransmission scenarios (more)Host A
Seq=92 8 bytes data
ACK=100
loss
tim
eout
Cumulative ACK scenario
Host B
X
Seq=100 20 bytes data
ACK=120
time
SendBase= 120
Transport Layer 3-64
TCP ACK generation [RFC 1122 RFC 2581]
Event at Receiver
Arrival of in-order segment withexpected seq All data up toexpected seq already ACKed
Arrival of in-order segment withexpected seq One other segment has ACK pending
Arrival of out-of-order segmenthigher-than-expect seq Gap detected
Arrival of segment that partially or completely fills gap
TCP Receiver action
Delayed ACK Wait up to 500msfor next segment If no next segmentsend ACK
Immediately send single cumulative ACK ACKing both in-order segments
Immediately send duplicate ACK indicating seq of next expected byte
Immediate send ACK provided thatsegment startsat lower end of gap
Transport Layer 3-65
Fast Retransmit
Time-out period often relatively long
long delay before resending lost packet
Detect lost segments via duplicate ACKs
Sender often sends many segments back-to-backIf segment is lost there will likely be many duplicate ACKs
If sender receives 3 ACKs for the same data it supposes that segment after ACKeddata was lost
fast retransmit resend segment before timer expires
Transport Layer 3-66
Fast RetransmitResend a segment after 3 duplicate ACKs since a duplicate ACK means that an out-of sequence segment was receivedduplicate ACKs due to packet reorderingif window is small donrsquot get duplicate ACKs
Host A
tim
eout
Host B
time
X
resend seq X2
seq x1seq x2seq x3seq x4seq x5
ACK x1
ACK x1ACK x1ACK x1
tripleduplicate
ACKs
Transport Layer 3-67
event ACK received with ACK field value of y if (y gt SendBase)
SendBase = yif (there are currently not-yet-acknowledged segments)
start timer
else increment count of dup ACKs received for yif (count of dup ACKs received for y = 3)
resend segment with sequence number y
Fast retransmit algorithm
a duplicate ACK for already ACKed segment
fast retransmit
Transport Layer 3-68
TCP Flow Control
receive side of TCP connection has a receive buffer
speed-matching service matching the send rate to the receiving apprsquos drain rate
app process may be slow at reading from buffer
sender wonrsquot overflowreceiverrsquos buffer by
transmitting too muchtoo fast
flow control
Transport Layer 3-69
TCP Flow control how it works
(Suppose TCP receiver discards out-of-order segments)spare room in buffer
= RcvWin
= RcvBuffer-[LastByteRcvd -LastByteRead]
Rcvr advertises spare room by including value of RcvWin in segmentsSender limits unACKeddata to RcvWin
guarantees receive buffer doesnrsquot overflow
Transport Layer 3-70
Sliding Window Flow Control Example
3K
2K SeqNo=0
ReceiverBuffer
0 4KSendersends 2Kof data
2K
AckNo=2048 RcvWin=2048Sendersends 2Kof data 2K SeqNo=2048
4K
AckNo=4096 RcvWin=0
AckNo=4096 RcvWin=1024
Sender blocked
Transport Layer 3-71
Principles of Congestion Control
Congestioninformally ldquotoo many sources sending too much data too fast for network to handlerdquodifferent from flow controlmanifestations
lost packets (buffer overflow at routers)long delays (queueing in router buffers)
a top-10 problem
Transport Layer 3-72
Causescosts of congestion scenario 1
two senders two receiversone router infinite buffers no retransmission
large delays when congestedmaximum achievable throughput
unlimited shared output link buffers
Host Aλin original data
Host B
λout
Transport Layer 3-73
Causescosts of congestion scenario 2
one router finite buffers sender retransmission of lost packet
finite shared output link buffers
Host A λin original data
Host B
λout
λin original data plus retransmitted data
Transport Layer 3-74
Causescosts of congestion scenario 2always (goodput)ldquoperfectrdquo retransmission only when loss
retransmission of delayed (not lost) packet makes larger(than perfect case) for same
λin
λout=
λin
λoutgtλ
inλout
ldquocostsrdquo of congestionmore work (retrans) for given ldquogoodputrdquounneeded retransmissions link carries multiple copies of pkt
R2
R2λin
λ out
b
R2
R2λin
λ out
a
R2
R2λin
λ out
c
R4
R3
Transport Layer 3-75
Causescosts of congestion scenario 3four sendersmultihop pathstimeoutretransmit
λin
Q what happens as and increase λ
in
finite shared output link buffers
Host Aλin original data
Host B
λout
λin original data plus retransmitted data
Transport Layer 3-76
Causescosts of congestion scenario 3
another ldquocostrdquo of congestionwhen packet dropped any ldquoupstream transmission capacity used for that packet was wasted
Host A
Host B
λou
t
Transport Layer 3-77
Approaches towards congestion control
End-end congestion controlno explicit feedback from networkcongestion inferred from end-system observed loss delayapproach taken by TCP
Network-assisted congestion controlrouters provide feedback to end systems
single bit indicating congestion (SNA DECbit TCPIP ECN ATM)explicit rate sender should send at
Two broad approaches towards congestion control
Transport Layer 3-78
TCP Congestion Control
end-end control (no network assistance)sender limits transmissionLastByteSent-LastByteAcked
le CongWin
CongWin is dynamic function of perceived network congestion
How does sender perceive congestionloss event = timeout or3 duplicate acksTCP sender reduces rate (CongWin) after loss event
two modes of operationSlow Start (SS)Congestion avoidance (CA) or Additive Increase Multiplicative Decrease (AIMD)
Transport Layer 3-79
TCP congestion control bandwidth probing
ldquoprobing for bandwidthrdquo increase transmission rate on receipt of ACK until eventually loss occurs then decrease transmission rate
continue to increase on ACK decrease on loss (since available bandwidth is changing depending on other connections in network)
ACKs being received so increase rate
X
X
XX
X loss so decrease rate
send
ing
rate
time
Q how fast to increasedecreasedetails to follow
TCPrsquosldquosawtoothrdquobehavior
Transport Layer 3-80
TCP Congestion Control details
sender limits rate by limiting number of unACKed bytes ldquoin pipelinerdquo
cwnd differs from rwnd (how why)sender limited by min(cwndrwnd)
roughly
cwnd is dynamic function of perceived network congestion
rate = cwndRTT bytessec
LastByteSent-LastByteAcked le cwnd
cwndbytes
RTT
ACK(s)
Transport Layer 3-81
TCP Congestion Control more details
segment loss event reducing cwndtimeout no response from receiver
cut cwnd to 13 duplicate ACKs at least some segments getting through (recall fast retransmit)
cut cwnd in half less aggressively than on timeout
ACK received increase cwndTwo modes of operation
slowstart phase bull increase exponentially
fast (despite name) at connection start or following timeout
congestion avoidance bull increase linearly
Transport Layer 3-82
TCP Slow Start Phasewhen connection begins cwnd = 1 MSS
example MSS = 500 bytes amp RTT = 200 msecinitial rate = 20 kbps
available bandwidth may be gtgt MSSRTT
desirable to quickly ramp up to respectable rate
increase rate exponentially until first loss event or when threshold reached
double cwnd every RTTdone by incrementing cwnd by 1 for every ACK received
Host A
one segment
RTT
Host B
time
two segments
four segments
Transport Layer 3-83
Slow Start ExampleThe congestion window size grows very rapidly
For every ACK we increase CongWin by 1 irrespective of the number of segments ACKrsquoeddouble CongWinevery RTTinitial rate is slow but ramps up exponentially fast
TCP slows down the increase of CongWinwhen CongWin gt ssthresh
segment 1
ACK for segment 1
cwnd = 1
cwnd = 2 segment 2segment 3
ACK for segments 2
cwnd = 4 segment 4segment 5segment 6
ACK for segments 4
cwnd = 7
ACK for segments 3
ACK for segments 5
ACK for segments 6
cwnd = 3
cwnd = 5
cwnd = 6ACK for segments 7
cwnd = 8
segment 7
Transport Layer 3-84
TCP Congestion Avoidance Phase
when cwnd gt ssthreshgrow cwnd linearly
increase cwnd by 1 MSS per RTT approach possible congestion slower than in slowstartimplementation cwnd= cwnd + MSScwndfor each ACK received
ACKs increase cwndby 1 MSS per RTT additive increaseloss cut cwnd in half (non-timeout-detected loss ) multiplicative decrease
AIMD
AIMD Additive IncreaseMultiplicative Decrease
Transport Layer 3-85
Congestion AvoidanceCongestion avoidance phase is started if CongWin has reached the slow-start threshold value
If CongWin gt= ssthresh then each time an ACK is received increment CongWin as follows
bull CongWin = CongWin + 1CongWin (CongWin in segments)
bull In actual TCP implementation CongWin is in BytesCongWin = CongWin + MSS (MSSCongWin)
So CongWin is increased by one only if all CongWinsegments have been acknowledged
Transport Layer 3-86
Example Slow StartCongestion AvoidanceAssume that
ssthresh = 8
cwnd = 1
cwnd = 2
cwnd = 4
cwnd = 8
cwnd = 9
cwnd = 10
02468
101214
t=0
t=2
t=4
t=6
Roundtrip times
Cw
nd(in
seg
men
ts)
ssthresh
cwnd = 3
cwnd = 5cwnd = 6cwnd = 7
Transport Layer 3-87
Slow Start Congestion AvoidanceA typical plot of CongWin for a TCP connection
(MSS = 1500 bytes) with TCP Tahoe
SS
CA
ssthresh
Transport Layer 3-88
Responses to CongestionTCP assumes there is congestion if it detects a packet lossA TCP sender can detect lost packets via loss events
bull Timeout of a retransmission timerbull Receipt of 3 duplicate ACKs (fast retransmit)
TCP interprets a Timeout as a binary congestion signal When a timeout occurs the sender performs
ssthresh is set to half the current size of the congestion window
ssthresh = CongWin 2CongWin is reset to one
CongWin = 1and slow-start is entered
Transport Layer 3-89
Fast Recovery (differentiation btwn two loss events) After 3 dup ACKs (fast Retransmit)
ssthresh = CongWin2CongWin = CongWin2window then grows linearly
But after timeout eventCongWin = 1 MSS window then grows exponentiallyto the threshold then grows linearly
bull 3 dup ACKs indicates network capable of delivering some segmentsbull timeout before 3 dup ACKs is ldquomore alarmingrdquo
Philosophy
3-90
TCP Congestion ControlInitially
CongWin = 1ssthresh = advertised window size
New Ack receivedif (CongWin lt ssthresh) Slow Start
CongWin = CongWin + 1else Congestion Avoidance
CongWin = CongWin + 1CongWinTimeout
ssthresh = CongWin2CongWin = 1
Fast Retransmissionssthresh = CongWin2CongWin = CongWin2
Slow Start (exponential increase phase) is continued until CongWin reaches half of the level where the loss event occurred last time CongWin is increased slowly after (linear increase in Congestion Avoidance phase)
Transport Layer 3-91
Popular ldquoflavorsrdquo of TCP
ssthresh
ssthresh
TCP Tahoe
TCP Reno
Transmission round
cwnd
win
dow
siz
e (in
seg
men
ts)
Transport Layer 3-92
Summary TCP Congestion ControlWhen CongWin is below Threshold sender in slow-start phase window grows exponentiallyWhen CongWin is above Threshold sender is in congestion-avoidance phase window grows linearlyWhen a triple duplicate ACK occurs Threshold set to CongWin2 and CongWin set to ThresholdWhen timeout occurs Threshold set to CongWin2 and CongWin is set to 1 MSS The actual sender window size is determined based on the congestion and flow control algorithms
SenderWin=min(RcvWinCongWin)
Transport Layer 3-93
TCP Congestion Control SummaryEvent State TCP Sender Action Commentary
ACK receipt for previously unackeddata
Slow Start (SS)
CongWin = CongWin + MSS If (CongWin gt Threshold)
set state to ldquoCongestion Avoidancerdquo
Resulting in a doubling of CongWin every RTT
ACK receipt for previously unackeddata
CongestionAvoidance (CA)
CongWin = CongWin+MSS (MSSCongWin)
Additive increase resulting in increase of CongWin by 1 MSS every RTT
Loss event detected by triple duplicate ACK
SS or CA Threshold = CongWin2 CongWin = ThresholdSet state to ldquoCongestion Avoidancerdquo
Fast recovery implementing multiplicative decrease CongWin will not drop below 1 MSS
Timeout SS or CA Threshold = CongWin2 CongWin = 1 MSSSet state to ldquoSlow Startrdquo
Enter slow start
Duplicate ACK
SS or CA Increment duplicate ACK count for segment being acked
CongWin and Threshold not changed
Transport Layer 3-94
TCP throughput
Q whatrsquos average throughout of TCP as function of window size RTT
ignoring slow startlet W be window size when loss occurs
when window is W throughput is WRTTjust after loss window drops to W2 throughput to W2RTT average throughout 75 WRTT
Transport Layer 3-95
TCP Futures TCP over ldquolong fat pipesrdquo
example 1500 byte segments 100ms RTT want 10 Gbps throughputrequires window size W = 83333 in-flight segmentsthroughput in terms of loss rate
L = 210-10 Wownew versions of TCP for high-speed
LRTTMSSsdot221
Transport Layer 3-96
Fairness goal if K TCP sessions share same bottleneck link of bandwidth R each should have average rate of RK
TCP connection 1
bottleneckrouter
capacity R
TCP connection 2
TCP Fairness
Transport Layer 3-97
Why is TCP fairTwo competing sessions
Additive increase gives slope of 1 as throughout increasesmultiplicative decrease decreases throughput proportionally
R
R
equal bandwidth share
Connection 1 throughput
Conn
ecti
on 2
thr
ough
p ut
congestion avoidance additive increaseloss decrease window by factor of 2
congestion avoidance additive increaseloss decrease window by factor of 2
Transport Layer 3-98
Fairness (more)Fairness and UDP
Multimedia apps often do not use TCP
do not want rate throttled by congestion control
Instead use UDPpump audiovideo at constant rate tolerate packet loss
Research area TCP friendly
Fairness and parallel TCP connectionsnothing prevents app from opening parallel cnctionsbetween 2 hostsWeb browsers do this Example link of rate R supporting 9 cnctions
new app asks for 1 TCP gets rate R10new app asks for 11 TCPs gets R2
Transport Layer 3-99
TCP Connection ManagementRecall TCP sender receiver
establish ldquoconnectionrdquobefore exchanging data segmentsinitialize TCP variables
seq sbuffers flow control info (eg RcvWindow)
client connection initiatorSocket clientSocket = new Socket(hostnameport
number)
server contacted by clientSocket connectionSocket = welcomeSocketaccept()
Three way handshakeStep 1 client host sends TCP
SYN segment to serverspecifies initial seq no data
Step 2 server host receives SYN replies with SYNACK segment
server allocates buffersspecifies server initial seq
Step 3 client receives SYNACK replies with ACK segment which may contain data
Transport Layer 3-100
TCP Connection Management (cont)
Closing a connection
client closes socketclientSocketclose()
Step 1 client end system sends TCP FIN control segment to server
Step 2 server receives FIN replies with ACK Closes connection sends FIN
client
FIN
server
ACK
ACK
FIN
close
close
closed
tim
ed w
ait
Transport Layer 3-101
TCP Connection Management (cont)
Step 3 client receives FIN replies with ACK
Enters ldquotimed waitrdquo -will respond with ACK to received FINs
Step 4 server receives ACK Connection closed
client
FIN
server
ACK
ACK
FIN
closing
closing
closed
tim
ed w
ait
closed
Transport Layer 3-102
TCP Connection Management (cont)
TCP clientlifecycle
TCP serverlifecycle
Transport Layer 3-103
Tuning TCPIP Parameters TCPIP parameters
A set of default values may not be optimal for all applicationsThe network administrator may wish to turn on or off some TCPIP functions for performance or security considerations
Many Unix and Linux systems provide some flexibility in tuning the TCPIP kernelsbinsysctl is used to configure the Linux kernel parameters at runtime
Default kernel configuration file is sbinsysctlconfFrequently used sysctl options
bull sysctl ndasha or sysctl ndashA list all current valuesbull sysctl ndashp file_name load the sysctl setting from a configuration
filebull sysctl ndashw variable=value change the value of the parameter
Transport Layer 3-104
SomeTCP Parameters in Linux Kerneltcp_syn_retries
Number of SYN packets the kernel will send before giving up on the new connection
tcp_synack_retriesnumber of SYN+ACK packets sent before the kernel gives up on the connection
tcp_window_scalingMaximum window size of 65535 bytes not enough for for really fast networks The window scaling options allows for almost gigabyte windows which is good for connections with large delay-bandwidth product
tcp_max_syn_backlogMaximal number of remembered connection requests which still did not receive an acknowledgment from connecting client
tcp_fin_timeoutHow many seconds to wait for a final FIN packet before the socket is closed required to prevent denial-of-service (DoS) attacks Default value is 60 seconds
Transport Layer 3-105
SomeTCP Parameters in Linux Kerneltcp_rmem
This is a vector of 3 integers [min default max] These parameters are used by TCP to dynamically adjust receive buffer sizesmin - minimum size of the receive buffer used by each TCP socket The default value is 4K default - the default size of the receive buffer for a TCP socket The default value is 87380 bytes and is lowered to 43689 in low memory systems If larger receive buffer sizes are desired this value should be increased max - the maximum size of the receive buffer used by each TCP socket The default value of 873802 bytes is lowered to 87380 in low memory systems
tcp_smemSend buffer parameters [min default max] similar to tcp_rmem
- Chapter 3 Transport Layer
- Transport services and protocols
- Transport vs network layer
- Internet transport-layer protocols
- Multiplexingdemultiplexing
- How demultiplexing works
- Connectionless demultiplexing
- Connection-oriented demux
- Connection-oriented demux (cont)
- Connection-oriented demux Threaded Web Server
- UDP User Datagram Protocol [RFC 768]
- UDP more
- UDP checksum
- Principles of Reliable data transfer
- Reliable data transfer getting started
- Reliable data transfer getting started
- Rdt10 reliable transfer over a reliable channel
- Rdt20 channel with bit errors
- rdt20 FSM specification
- rdt20 operation with no errors
- rdt20 error scenario
- rdt20 has a fatal flaw
- rdt21 sender handles garbled ACKNAKs
- rdt21 receiver handles garbled ACKNAKs
- rdt21 discussion
- rdt22 a NAK-free protocol
- rdt22 sender receiver fragments
- rdt30 channels with errors and loss
- rdt30 sender
- rdt30 in action
- rdt30 in action
- Performance of rdt30
- rdt30 stop-and-wait operation
- Pipelined protocols
- Pipelining increased utilization
- Go-Back-N
- GBN sender extended FSM
- GBN receiver extended FSM
- GBN inaction
- Selective Repeat
- Selective repeat sender receiver windows
- Selective repeat
- Selective repeat in action
- Selective repeat dilemma
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- TCP Overview RFCs 793 1122 1323 2018 2581
- TCP segment structure
- TCP seq rsquos and ACKs
- TCP Round Trip Time and Timeout
- TCP Round Trip Time and Timeout
- Example RTT estimation
- TCP Round Trip Time and Timeout
- TCP reliable data transfer
- TCP sender events
- TCP sender(simplified)
- TCP retransmission scenarios
- TCP retransmission scenarios (more)
- TCP ACK generation [RFC 1122 RFC 2581]
- Fast Retransmit
- Fast Retransmit
- Fast retransmit algorithm
- TCP Flow Control
- TCP Flow control how it works
- Sliding Window Flow Control Example
- Principles of Congestion Control
- Causescosts of congestion scenario 1
- Causescosts of congestion scenario 2
- Causescosts of congestion scenario 2
- Causescosts of congestion scenario 3
- Causescosts of congestion scenario 3
- Approaches towards congestion control
- TCP Congestion Control
- TCP congestion control bandwidth probing
- TCP Congestion Control details
- TCP Congestion Control more details
- TCP Slow Start Phase
- Slow Start Example
- TCP Congestion Avoidance Phase
- Congestion Avoidance
- Example Slow StartCongestion Avoidance
- Slow Start Congestion Avoidance
- Responses to Congestion
- Fast Recovery (differentiation btwn two loss events)
- TCP Congestion Control
- Popular ldquoflavorsrdquo of TCP
- Summary TCP Congestion Control
- TCP Congestion Control Summary
- TCP throughput
- TCP Futures TCP over ldquolong fat pipesrdquo
- TCP Fairness
- Why is TCP fair
- Fairness (more)
- TCP Connection Management
- TCP Connection Management (cont)
- TCP Connection Management (cont)
- TCP Connection Management (cont)
- Tuning TCPIP Parameters
- SomeTCP Parameters in Linux Kernel
- SomeTCP Parameters in Linux Kernel
-
Transport Layer 3-38
GBN sender extended FSM
Wait start_timerudt_send(sndpkt[base])udt_send(sndpkt[base+1])hellipudt_send(sndpkt[nextseqnum-1])
timeout
rdt_send(data)
if (nextseqnum lt base+N) sndpkt[nextseqnum] = make_pkt(nextseqnumdatachksum)udt_send(sndpkt[nextseqnum])if (base == nextseqnum)
start_timernextseqnum++
elserefuse_data(data)
base = getacknum(rcvpkt)+1If (base == nextseqnum)
stop_timerelse
start_timer
rdt_rcv(rcvpkt) ampamp notcorrupt(rcvpkt)
base=1nextseqnum=1
rdt_rcv(rcvpkt) ampamp corrupt(rcvpkt)
Λ
Λ
Transport Layer 3-39
GBN receiver extended FSM
ACK-only always send ACK for correctly-received pktwith highest in-order seq
may generate duplicate ACKsneed only remember expectedseqnum
out-of-order pkt discard (donrsquot buffer) -gt no receiver bufferingRe-ACK pkt with highest in-order seq
Wait
udt_send(sndpkt)default
rdt_rcv(rcvpkt)ampamp notcurrupt(rcvpkt)ampamp hasseqnum(rcvpktexpectedseqnum)
extract(rcvpktdata)deliver_data(data)sndpkt = make_pkt(expectedseqnumACKchksum)udt_send(sndpkt)expectedseqnum++
expectedseqnum=1sndpkt =
make_pkt(0ACKchksum)
Λ
Transport Layer 3-40
GBN inaction
Transport Layer 3-41
Selective Repeat
receiver individually acknowledges all correctly received pkts
buffers pkts as needed for eventual in-order delivery to upper layer
sender only resends pkts for which ACK not received
sender timer for each unACKed pktsender window
N consecutive seq rsquosagain limits seq s of sent unACKed pkts
Transport Layer 3-42
Selective repeat sender receiver windows
Transport Layer 3-43
Selective repeat
data from above if next available seq in window send pkt
timeout(n)resend pkt n restart timer
ACK(n) in [sendbasesendbase+N-1]
mark pkt n as receivedif n smallest unACKed pkt advance window base to next unACKed seq
senderpkt n in [rcvbase rcvbase+N-1]
send ACK(n)out-of-order bufferin-order deliver (also deliver buffered in-order pkts) advance window to next not-yet-received pkt
pkt n in [rcvbase-Nrcvbase-1]
ACK(n)otherwise
ignore
receiver
Transport Layer 3-44
Selective repeat in action
Transport Layer 3-45
Selective repeatdilemma
Example seq rsquos 0 1 2 3window size=3
receiver sees no difference in two scenariosincorrectly passes duplicate data as new in (a)
Q what relationship between seq size and window size
Transport Layer 3-46
Sequence Number vs Window SizeSuppose we use k bits to represent SNQuestion Whatrsquos the minimum number of bits k necessary for a window size of N
sender
receiver
Go-Back-N
expectedSN
snd_base=expectedSN
Q For a given expectedSN whatrsquos the largest possible value for snd_baseA If all the last N ACKs sent by the receiver are received
snd_base = expectedSNexpectedSN+N-1
senderrsquos window
Transport Layer 3-47
Sequence Number vs Window SizeSuppose we use k bits to represent SNQuestion Whatrsquos the minimum number of bits k necessary for a window size of N
sender
receiver
Go-Back-N
expectedSN
snd_base=expectedSN-N
Q For a given expectedSN whatrsquos the smallest possible value for snd_baseA If all the last N ACKs sent by the receiver are not received
snd_base = expectedSN-NexpectedSN-1
senderrsquos window
Transport Layer 3-48
Sequence Number vs Window Size
sender
receiver
Go-Back-N
expectedSN
snd_base=expectedSN-N
All SNs in the interval [expectedSN-NexpectedSN+N-1] (an interval of size 2N) can be received by the receiver Since the receiver accepts on the packet with SN=expectedSN there should be no other packet within this interval with SN=expectedSN Therefore
2k ge N+1expectedSN+N-1
Transport Layer 3-49
Sequence Number vs Window SizeSuppose we use k bits to represent SNQuestion Whatrsquos the minimum number of bits k necessary for a window size of N
sender
receiver
Selective Repeat
rcv_base
snd_base=rcv_base
Q For a given rcv_base whatrsquos the largest possible value for snd_baseA If all the last N ACKs sent by the receiver are received
snd_base = rcv_base (same as go_back-N)rcv_base+N-1
senderrsquos window
receiverrsquos window
rcv_base+N-1
Transport Layer 3-50
Sequence Number vs Window SizeSuppose we use k bits to represent SNQuestion Whatrsquos the minimum number of bits k necessary for a window size of N
sender
receiver
Selective Repeat
rcv_base
snd_base=rcv_base-N
Q For a given rcv_base whatrsquos the smallest possible value for snd_baseA If all the last N ACKs sent by the receiver are not received
snd_base = rcv_base-N (same as Go-Back-N)rcv_base-1
senderrsquos window
rcv_base
receiverrsquos window
rcv_base+N-1
Transport Layer 3-51
Sequence Number vs Window Size
sender
receiver
Selective Repeat
snd_base=rcv_base-N
All SNs in the interval [rcv_base-Nrcv_base+N-1] (an interval of size 2N) can be received by the receiver Since the receiver should be able to distinguish between all packets in this interval and take corresponding action there should be no two packets within thisinterval having the same SN Therefore
2k ge 2Nrcv_base+N-1
rcv_basercv_base
receiverrsquos window
rcv_base+N-1
Transport Layer 3-52
TCP Overview RFCs 793 1122 1323 2018 2581
full duplex databi-directional data flow in same connectionMSS maximum segment size
connection-orientedhandshaking (exchange of control msgs) initrsquossender receiver state before data exchange
flow controlledsender will not overwhelm receiver
point-to-pointone sender one receiver
reliable in-order byte stream
no ldquomessage boundariesrdquopipelined
TCP congestion and flow control set window size
send amp receive buffers
socketdoor
TCPsend buffer
TCPreceive buffer
socketdoor
segment
applicationwrites data
applicationreads data
Transport Layer 3-53
TCP segment structure
source port dest port
32 bits
applicationdata
(variable length)
sequence numberacknowledgement number
Receive windowUrg data pnterchecksum
FSRPAUheadlen
notused
Options (variable length)
URG urgent data (generally not used)
ACK ACK valid
PSH push data now(generally not used)
RST SYN FINconnection estab(setup teardown
commands)
bytes rcvr willingto accept
Internetchecksum
(as in UDP)
countingby bytes of data(not segments)
Transport Layer 3-54
TCP seq rsquos and ACKsSeq rsquos
byte stream ldquonumberrdquo of first byte in segmentrsquos dataACKs
seq of next byte expected from other sidecumulative ACK
Q how receiver handles out-of-order segmentsA TCP spec doesnrsquot say - up to implementationWidely used implementations of TCP buffer out-of-order segments
Transport Layer 3-55
TCP Round Trip Time and Timeout
Q how to set TCP timeout valuelonger than RTT
but RTT variestoo short premature timeout
unnecessary retransmissions
too long slow reaction to segment loss
Q how to estimate RTTSampleRTT measured time from segment transmission until ACK receipt
ignore retransmissionsSampleRTT will vary want estimated RTT ldquosmootherrdquo
average several recent measurements not just current SampleRTT
Transport Layer 3-56
TCP Round Trip Time and Timeout
EstimatedRTT = (1- α)EstimatedRTT + αSampleRTT
Exponential weighted moving averageinfluence of past sample decreases exponentially fasttypical value α = 0125
Transport Layer 3-57
Example RTT estimationRTT gaiacsumassedu to fantasiaeurecomfr
100
150
200
250
300
350
1 8 15 22 29 36 43 50 57 64 71 78 85 92 99 106
time (seconnds)
RTT
(mill
iseco
nds)
SampleRTT Estimated RTT
Transport Layer 3-58
TCP Round Trip Time and TimeoutSetting the timeout
EstimatedRTT plus ldquosafety marginrdquolarge variation in EstimatedRTT -gt larger safety margin
first estimate of how much SampleRTT deviates from EstimatedRTT
TimeoutInterval = EstimatedRTT + 4DevRTT
DevRTT = (1-β)DevRTT +β|SampleRTT-EstimatedRTT|
(typically β = 025)
Then set timeout interval
Transport Layer 3-59
TCP reliable data transfer
TCP creates rdtservice on top of IPrsquos unreliable servicePipelined segmentsCumulative acksTCP uses single retransmission timer however it just retransmits the first segment in the window
Retransmissions are triggered by
timeout eventsduplicate acks
Initially consider simplified TCP sender
ignore duplicate acksignore flow control congestion control
Transport Layer 3-60
TCP sender eventsdata rcvd from app
Create segment with seq seq is byte-stream number of first data byte in segmentstart timer if not already running (think of timer as for oldest unacked segment)expiration interval TimeOutInterval
timeoutretransmit segment that caused timeout (first segment in the window)restart timer
Ack rcvdIf acknowledges previously unacked segments
update what is known to be ackedstart timer if there are outstanding segments
Transport Layer 3-61
TCP sender(simplified)
NextSeqNum = InitialSeqNumSendBase = InitialSeqNum
loop (forever) switch(event)
event data received from application above create TCP segment with sequence number NextSeqNumif (timer currently not running)
start timerpass segment to IP NextSeqNum = NextSeqNum + length(data)
event timer timeoutretransmit not-yet-acknowledged segment with
smallest sequence numberstart timer
event ACK received with ACK field value of y if (y gt SendBase)
SendBase = yif (there are currently not-yet-acknowledged segments)
start timer
end of loop forever
Commentbull SendBase-1 last cumulatively ackrsquoed byteExamplebull SendBase-1 = 71y= 73 so the rcvrwants 73+ y gt SendBase sothat new data is acked
Transport Layer 3-62
TCP retransmission scenariosHost A
Seq=100 20 bytes data
ACK=100
timepremature timeout
Host B
Seq=92 8 bytes data
ACK=120
Seq=92 8 bytes data
Seq=
92 t
imeo
ut
ACK=120
Host A
Seq=92 8 bytes data
ACK=100
loss
tim
eout
lost ACK scenario
Host B
X
Seq=92 8 bytes data
ACK=100
time
Seq=
92 t
imeo
utSendBase
= 100
SendBase= 120
SendBase= 120
Sendbase= 100
Transport Layer 3-63
TCP retransmission scenarios (more)Host A
Seq=92 8 bytes data
ACK=100
loss
tim
eout
Cumulative ACK scenario
Host B
X
Seq=100 20 bytes data
ACK=120
time
SendBase= 120
Transport Layer 3-64
TCP ACK generation [RFC 1122 RFC 2581]
Event at Receiver
Arrival of in-order segment withexpected seq All data up toexpected seq already ACKed
Arrival of in-order segment withexpected seq One other segment has ACK pending
Arrival of out-of-order segmenthigher-than-expect seq Gap detected
Arrival of segment that partially or completely fills gap
TCP Receiver action
Delayed ACK Wait up to 500msfor next segment If no next segmentsend ACK
Immediately send single cumulative ACK ACKing both in-order segments
Immediately send duplicate ACK indicating seq of next expected byte
Immediate send ACK provided thatsegment startsat lower end of gap
Transport Layer 3-65
Fast Retransmit
Time-out period often relatively long
long delay before resending lost packet
Detect lost segments via duplicate ACKs
Sender often sends many segments back-to-backIf segment is lost there will likely be many duplicate ACKs
If sender receives 3 ACKs for the same data it supposes that segment after ACKeddata was lost
fast retransmit resend segment before timer expires
Transport Layer 3-66
Fast RetransmitResend a segment after 3 duplicate ACKs since a duplicate ACK means that an out-of sequence segment was receivedduplicate ACKs due to packet reorderingif window is small donrsquot get duplicate ACKs
Host A
tim
eout
Host B
time
X
resend seq X2
seq x1seq x2seq x3seq x4seq x5
ACK x1
ACK x1ACK x1ACK x1
tripleduplicate
ACKs
Transport Layer 3-67
event ACK received with ACK field value of y if (y gt SendBase)
SendBase = yif (there are currently not-yet-acknowledged segments)
start timer
else increment count of dup ACKs received for yif (count of dup ACKs received for y = 3)
resend segment with sequence number y
Fast retransmit algorithm
a duplicate ACK for already ACKed segment
fast retransmit
Transport Layer 3-68
TCP Flow Control
receive side of TCP connection has a receive buffer
speed-matching service matching the send rate to the receiving apprsquos drain rate
app process may be slow at reading from buffer
sender wonrsquot overflowreceiverrsquos buffer by
transmitting too muchtoo fast
flow control
Transport Layer 3-69
TCP Flow control how it works
(Suppose TCP receiver discards out-of-order segments)spare room in buffer
= RcvWin
= RcvBuffer-[LastByteRcvd -LastByteRead]
Rcvr advertises spare room by including value of RcvWin in segmentsSender limits unACKeddata to RcvWin
guarantees receive buffer doesnrsquot overflow
Transport Layer 3-70
Sliding Window Flow Control Example
3K
2K SeqNo=0
ReceiverBuffer
0 4KSendersends 2Kof data
2K
AckNo=2048 RcvWin=2048Sendersends 2Kof data 2K SeqNo=2048
4K
AckNo=4096 RcvWin=0
AckNo=4096 RcvWin=1024
Sender blocked
Transport Layer 3-71
Principles of Congestion Control
Congestioninformally ldquotoo many sources sending too much data too fast for network to handlerdquodifferent from flow controlmanifestations
lost packets (buffer overflow at routers)long delays (queueing in router buffers)
a top-10 problem
Transport Layer 3-72
Causescosts of congestion scenario 1
two senders two receiversone router infinite buffers no retransmission
large delays when congestedmaximum achievable throughput
unlimited shared output link buffers
Host Aλin original data
Host B
λout
Transport Layer 3-73
Causescosts of congestion scenario 2
one router finite buffers sender retransmission of lost packet
finite shared output link buffers
Host A λin original data
Host B
λout
λin original data plus retransmitted data
Transport Layer 3-74
Causescosts of congestion scenario 2always (goodput)ldquoperfectrdquo retransmission only when loss
retransmission of delayed (not lost) packet makes larger(than perfect case) for same
λin
λout=
λin
λoutgtλ
inλout
ldquocostsrdquo of congestionmore work (retrans) for given ldquogoodputrdquounneeded retransmissions link carries multiple copies of pkt
R2
R2λin
λ out
b
R2
R2λin
λ out
a
R2
R2λin
λ out
c
R4
R3
Transport Layer 3-75
Causescosts of congestion scenario 3four sendersmultihop pathstimeoutretransmit
λin
Q what happens as and increase λ
in
finite shared output link buffers
Host Aλin original data
Host B
λout
λin original data plus retransmitted data
Transport Layer 3-76
Causescosts of congestion scenario 3
another ldquocostrdquo of congestionwhen packet dropped any ldquoupstream transmission capacity used for that packet was wasted
Host A
Host B
λou
t
Transport Layer 3-77
Approaches towards congestion control
End-end congestion controlno explicit feedback from networkcongestion inferred from end-system observed loss delayapproach taken by TCP
Network-assisted congestion controlrouters provide feedback to end systems
single bit indicating congestion (SNA DECbit TCPIP ECN ATM)explicit rate sender should send at
Two broad approaches towards congestion control
Transport Layer 3-78
TCP Congestion Control
end-end control (no network assistance)sender limits transmissionLastByteSent-LastByteAcked
le CongWin
CongWin is dynamic function of perceived network congestion
How does sender perceive congestionloss event = timeout or3 duplicate acksTCP sender reduces rate (CongWin) after loss event
two modes of operationSlow Start (SS)Congestion avoidance (CA) or Additive Increase Multiplicative Decrease (AIMD)
Transport Layer 3-79
TCP congestion control bandwidth probing
ldquoprobing for bandwidthrdquo increase transmission rate on receipt of ACK until eventually loss occurs then decrease transmission rate
continue to increase on ACK decrease on loss (since available bandwidth is changing depending on other connections in network)
ACKs being received so increase rate
X
X
XX
X loss so decrease rate
send
ing
rate
time
Q how fast to increasedecreasedetails to follow
TCPrsquosldquosawtoothrdquobehavior
Transport Layer 3-80
TCP Congestion Control details
sender limits rate by limiting number of unACKed bytes ldquoin pipelinerdquo
cwnd differs from rwnd (how why)sender limited by min(cwndrwnd)
roughly
cwnd is dynamic function of perceived network congestion
rate = cwndRTT bytessec
LastByteSent-LastByteAcked le cwnd
cwndbytes
RTT
ACK(s)
Transport Layer 3-81
TCP Congestion Control more details
segment loss event reducing cwndtimeout no response from receiver
cut cwnd to 13 duplicate ACKs at least some segments getting through (recall fast retransmit)
cut cwnd in half less aggressively than on timeout
ACK received increase cwndTwo modes of operation
slowstart phase bull increase exponentially
fast (despite name) at connection start or following timeout
congestion avoidance bull increase linearly
Transport Layer 3-82
TCP Slow Start Phasewhen connection begins cwnd = 1 MSS
example MSS = 500 bytes amp RTT = 200 msecinitial rate = 20 kbps
available bandwidth may be gtgt MSSRTT
desirable to quickly ramp up to respectable rate
increase rate exponentially until first loss event or when threshold reached
double cwnd every RTTdone by incrementing cwnd by 1 for every ACK received
Host A
one segment
RTT
Host B
time
two segments
four segments
Transport Layer 3-83
Slow Start ExampleThe congestion window size grows very rapidly
For every ACK we increase CongWin by 1 irrespective of the number of segments ACKrsquoeddouble CongWinevery RTTinitial rate is slow but ramps up exponentially fast
TCP slows down the increase of CongWinwhen CongWin gt ssthresh
segment 1
ACK for segment 1
cwnd = 1
cwnd = 2 segment 2segment 3
ACK for segments 2
cwnd = 4 segment 4segment 5segment 6
ACK for segments 4
cwnd = 7
ACK for segments 3
ACK for segments 5
ACK for segments 6
cwnd = 3
cwnd = 5
cwnd = 6ACK for segments 7
cwnd = 8
segment 7
Transport Layer 3-84
TCP Congestion Avoidance Phase
when cwnd gt ssthreshgrow cwnd linearly
increase cwnd by 1 MSS per RTT approach possible congestion slower than in slowstartimplementation cwnd= cwnd + MSScwndfor each ACK received
ACKs increase cwndby 1 MSS per RTT additive increaseloss cut cwnd in half (non-timeout-detected loss ) multiplicative decrease
AIMD
AIMD Additive IncreaseMultiplicative Decrease
Transport Layer 3-85
Congestion AvoidanceCongestion avoidance phase is started if CongWin has reached the slow-start threshold value
If CongWin gt= ssthresh then each time an ACK is received increment CongWin as follows
bull CongWin = CongWin + 1CongWin (CongWin in segments)
bull In actual TCP implementation CongWin is in BytesCongWin = CongWin + MSS (MSSCongWin)
So CongWin is increased by one only if all CongWinsegments have been acknowledged
Transport Layer 3-86
Example Slow StartCongestion AvoidanceAssume that
ssthresh = 8
cwnd = 1
cwnd = 2
cwnd = 4
cwnd = 8
cwnd = 9
cwnd = 10
02468
101214
t=0
t=2
t=4
t=6
Roundtrip times
Cw
nd(in
seg
men
ts)
ssthresh
cwnd = 3
cwnd = 5cwnd = 6cwnd = 7
Transport Layer 3-87
Slow Start Congestion AvoidanceA typical plot of CongWin for a TCP connection
(MSS = 1500 bytes) with TCP Tahoe
SS
CA
ssthresh
Transport Layer 3-88
Responses to CongestionTCP assumes there is congestion if it detects a packet lossA TCP sender can detect lost packets via loss events
bull Timeout of a retransmission timerbull Receipt of 3 duplicate ACKs (fast retransmit)
TCP interprets a Timeout as a binary congestion signal When a timeout occurs the sender performs
ssthresh is set to half the current size of the congestion window
ssthresh = CongWin 2CongWin is reset to one
CongWin = 1and slow-start is entered
Transport Layer 3-89
Fast Recovery (differentiation btwn two loss events) After 3 dup ACKs (fast Retransmit)
ssthresh = CongWin2CongWin = CongWin2window then grows linearly
But after timeout eventCongWin = 1 MSS window then grows exponentiallyto the threshold then grows linearly
bull 3 dup ACKs indicates network capable of delivering some segmentsbull timeout before 3 dup ACKs is ldquomore alarmingrdquo
Philosophy
3-90
TCP Congestion ControlInitially
CongWin = 1ssthresh = advertised window size
New Ack receivedif (CongWin lt ssthresh) Slow Start
CongWin = CongWin + 1else Congestion Avoidance
CongWin = CongWin + 1CongWinTimeout
ssthresh = CongWin2CongWin = 1
Fast Retransmissionssthresh = CongWin2CongWin = CongWin2
Slow Start (exponential increase phase) is continued until CongWin reaches half of the level where the loss event occurred last time CongWin is increased slowly after (linear increase in Congestion Avoidance phase)
Transport Layer 3-91
Popular ldquoflavorsrdquo of TCP
ssthresh
ssthresh
TCP Tahoe
TCP Reno
Transmission round
cwnd
win
dow
siz
e (in
seg
men
ts)
Transport Layer 3-92
Summary TCP Congestion ControlWhen CongWin is below Threshold sender in slow-start phase window grows exponentiallyWhen CongWin is above Threshold sender is in congestion-avoidance phase window grows linearlyWhen a triple duplicate ACK occurs Threshold set to CongWin2 and CongWin set to ThresholdWhen timeout occurs Threshold set to CongWin2 and CongWin is set to 1 MSS The actual sender window size is determined based on the congestion and flow control algorithms
SenderWin=min(RcvWinCongWin)
Transport Layer 3-93
TCP Congestion Control SummaryEvent State TCP Sender Action Commentary
ACK receipt for previously unackeddata
Slow Start (SS)
CongWin = CongWin + MSS If (CongWin gt Threshold)
set state to ldquoCongestion Avoidancerdquo
Resulting in a doubling of CongWin every RTT
ACK receipt for previously unackeddata
CongestionAvoidance (CA)
CongWin = CongWin+MSS (MSSCongWin)
Additive increase resulting in increase of CongWin by 1 MSS every RTT
Loss event detected by triple duplicate ACK
SS or CA Threshold = CongWin2 CongWin = ThresholdSet state to ldquoCongestion Avoidancerdquo
Fast recovery implementing multiplicative decrease CongWin will not drop below 1 MSS
Timeout SS or CA Threshold = CongWin2 CongWin = 1 MSSSet state to ldquoSlow Startrdquo
Enter slow start
Duplicate ACK
SS or CA Increment duplicate ACK count for segment being acked
CongWin and Threshold not changed
Transport Layer 3-94
TCP throughput
Q whatrsquos average throughout of TCP as function of window size RTT
ignoring slow startlet W be window size when loss occurs
when window is W throughput is WRTTjust after loss window drops to W2 throughput to W2RTT average throughout 75 WRTT
Transport Layer 3-95
TCP Futures TCP over ldquolong fat pipesrdquo
example 1500 byte segments 100ms RTT want 10 Gbps throughputrequires window size W = 83333 in-flight segmentsthroughput in terms of loss rate
L = 210-10 Wownew versions of TCP for high-speed
LRTTMSSsdot221
Transport Layer 3-96
Fairness goal if K TCP sessions share same bottleneck link of bandwidth R each should have average rate of RK
TCP connection 1
bottleneckrouter
capacity R
TCP connection 2
TCP Fairness
Transport Layer 3-97
Why is TCP fairTwo competing sessions
Additive increase gives slope of 1 as throughout increasesmultiplicative decrease decreases throughput proportionally
R
R
equal bandwidth share
Connection 1 throughput
Conn
ecti
on 2
thr
ough
p ut
congestion avoidance additive increaseloss decrease window by factor of 2
congestion avoidance additive increaseloss decrease window by factor of 2
Transport Layer 3-98
Fairness (more)Fairness and UDP
Multimedia apps often do not use TCP
do not want rate throttled by congestion control
Instead use UDPpump audiovideo at constant rate tolerate packet loss
Research area TCP friendly
Fairness and parallel TCP connectionsnothing prevents app from opening parallel cnctionsbetween 2 hostsWeb browsers do this Example link of rate R supporting 9 cnctions
new app asks for 1 TCP gets rate R10new app asks for 11 TCPs gets R2
Transport Layer 3-99
TCP Connection ManagementRecall TCP sender receiver
establish ldquoconnectionrdquobefore exchanging data segmentsinitialize TCP variables
seq sbuffers flow control info (eg RcvWindow)
client connection initiatorSocket clientSocket = new Socket(hostnameport
number)
server contacted by clientSocket connectionSocket = welcomeSocketaccept()
Three way handshakeStep 1 client host sends TCP
SYN segment to serverspecifies initial seq no data
Step 2 server host receives SYN replies with SYNACK segment
server allocates buffersspecifies server initial seq
Step 3 client receives SYNACK replies with ACK segment which may contain data
Transport Layer 3-100
TCP Connection Management (cont)
Closing a connection
client closes socketclientSocketclose()
Step 1 client end system sends TCP FIN control segment to server
Step 2 server receives FIN replies with ACK Closes connection sends FIN
client
FIN
server
ACK
ACK
FIN
close
close
closed
tim
ed w
ait
Transport Layer 3-101
TCP Connection Management (cont)
Step 3 client receives FIN replies with ACK
Enters ldquotimed waitrdquo -will respond with ACK to received FINs
Step 4 server receives ACK Connection closed
client
FIN
server
ACK
ACK
FIN
closing
closing
closed
tim
ed w
ait
closed
Transport Layer 3-102
TCP Connection Management (cont)
TCP clientlifecycle
TCP serverlifecycle
Transport Layer 3-103
Tuning TCPIP Parameters TCPIP parameters
A set of default values may not be optimal for all applicationsThe network administrator may wish to turn on or off some TCPIP functions for performance or security considerations
Many Unix and Linux systems provide some flexibility in tuning the TCPIP kernelsbinsysctl is used to configure the Linux kernel parameters at runtime
Default kernel configuration file is sbinsysctlconfFrequently used sysctl options
bull sysctl ndasha or sysctl ndashA list all current valuesbull sysctl ndashp file_name load the sysctl setting from a configuration
filebull sysctl ndashw variable=value change the value of the parameter
Transport Layer 3-104
SomeTCP Parameters in Linux Kerneltcp_syn_retries
Number of SYN packets the kernel will send before giving up on the new connection
tcp_synack_retriesnumber of SYN+ACK packets sent before the kernel gives up on the connection
tcp_window_scalingMaximum window size of 65535 bytes not enough for for really fast networks The window scaling options allows for almost gigabyte windows which is good for connections with large delay-bandwidth product
tcp_max_syn_backlogMaximal number of remembered connection requests which still did not receive an acknowledgment from connecting client
tcp_fin_timeoutHow many seconds to wait for a final FIN packet before the socket is closed required to prevent denial-of-service (DoS) attacks Default value is 60 seconds
Transport Layer 3-105
SomeTCP Parameters in Linux Kerneltcp_rmem
This is a vector of 3 integers [min default max] These parameters are used by TCP to dynamically adjust receive buffer sizesmin - minimum size of the receive buffer used by each TCP socket The default value is 4K default - the default size of the receive buffer for a TCP socket The default value is 87380 bytes and is lowered to 43689 in low memory systems If larger receive buffer sizes are desired this value should be increased max - the maximum size of the receive buffer used by each TCP socket The default value of 873802 bytes is lowered to 87380 in low memory systems
tcp_smemSend buffer parameters [min default max] similar to tcp_rmem
- Chapter 3 Transport Layer
- Transport services and protocols
- Transport vs network layer
- Internet transport-layer protocols
- Multiplexingdemultiplexing
- How demultiplexing works
- Connectionless demultiplexing
- Connection-oriented demux
- Connection-oriented demux (cont)
- Connection-oriented demux Threaded Web Server
- UDP User Datagram Protocol [RFC 768]
- UDP more
- UDP checksum
- Principles of Reliable data transfer
- Reliable data transfer getting started
- Reliable data transfer getting started
- Rdt10 reliable transfer over a reliable channel
- Rdt20 channel with bit errors
- rdt20 FSM specification
- rdt20 operation with no errors
- rdt20 error scenario
- rdt20 has a fatal flaw
- rdt21 sender handles garbled ACKNAKs
- rdt21 receiver handles garbled ACKNAKs
- rdt21 discussion
- rdt22 a NAK-free protocol
- rdt22 sender receiver fragments
- rdt30 channels with errors and loss
- rdt30 sender
- rdt30 in action
- rdt30 in action
- Performance of rdt30
- rdt30 stop-and-wait operation
- Pipelined protocols
- Pipelining increased utilization
- Go-Back-N
- GBN sender extended FSM
- GBN receiver extended FSM
- GBN inaction
- Selective Repeat
- Selective repeat sender receiver windows
- Selective repeat
- Selective repeat in action
- Selective repeat dilemma
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- TCP Overview RFCs 793 1122 1323 2018 2581
- TCP segment structure
- TCP seq rsquos and ACKs
- TCP Round Trip Time and Timeout
- TCP Round Trip Time and Timeout
- Example RTT estimation
- TCP Round Trip Time and Timeout
- TCP reliable data transfer
- TCP sender events
- TCP sender(simplified)
- TCP retransmission scenarios
- TCP retransmission scenarios (more)
- TCP ACK generation [RFC 1122 RFC 2581]
- Fast Retransmit
- Fast Retransmit
- Fast retransmit algorithm
- TCP Flow Control
- TCP Flow control how it works
- Sliding Window Flow Control Example
- Principles of Congestion Control
- Causescosts of congestion scenario 1
- Causescosts of congestion scenario 2
- Causescosts of congestion scenario 2
- Causescosts of congestion scenario 3
- Causescosts of congestion scenario 3
- Approaches towards congestion control
- TCP Congestion Control
- TCP congestion control bandwidth probing
- TCP Congestion Control details
- TCP Congestion Control more details
- TCP Slow Start Phase
- Slow Start Example
- TCP Congestion Avoidance Phase
- Congestion Avoidance
- Example Slow StartCongestion Avoidance
- Slow Start Congestion Avoidance
- Responses to Congestion
- Fast Recovery (differentiation btwn two loss events)
- TCP Congestion Control
- Popular ldquoflavorsrdquo of TCP
- Summary TCP Congestion Control
- TCP Congestion Control Summary
- TCP throughput
- TCP Futures TCP over ldquolong fat pipesrdquo
- TCP Fairness
- Why is TCP fair
- Fairness (more)
- TCP Connection Management
- TCP Connection Management (cont)
- TCP Connection Management (cont)
- TCP Connection Management (cont)
- Tuning TCPIP Parameters
- SomeTCP Parameters in Linux Kernel
- SomeTCP Parameters in Linux Kernel
-
Transport Layer 3-39
GBN receiver extended FSM
ACK-only always send ACK for correctly-received pktwith highest in-order seq
may generate duplicate ACKsneed only remember expectedseqnum
out-of-order pkt discard (donrsquot buffer) -gt no receiver bufferingRe-ACK pkt with highest in-order seq
Wait
udt_send(sndpkt)default
rdt_rcv(rcvpkt)ampamp notcurrupt(rcvpkt)ampamp hasseqnum(rcvpktexpectedseqnum)
extract(rcvpktdata)deliver_data(data)sndpkt = make_pkt(expectedseqnumACKchksum)udt_send(sndpkt)expectedseqnum++
expectedseqnum=1sndpkt =
make_pkt(0ACKchksum)
Λ
Transport Layer 3-40
GBN inaction
Transport Layer 3-41
Selective Repeat
receiver individually acknowledges all correctly received pkts
buffers pkts as needed for eventual in-order delivery to upper layer
sender only resends pkts for which ACK not received
sender timer for each unACKed pktsender window
N consecutive seq rsquosagain limits seq s of sent unACKed pkts
Transport Layer 3-42
Selective repeat sender receiver windows
Transport Layer 3-43
Selective repeat
data from above if next available seq in window send pkt
timeout(n)resend pkt n restart timer
ACK(n) in [sendbasesendbase+N-1]
mark pkt n as receivedif n smallest unACKed pkt advance window base to next unACKed seq
senderpkt n in [rcvbase rcvbase+N-1]
send ACK(n)out-of-order bufferin-order deliver (also deliver buffered in-order pkts) advance window to next not-yet-received pkt
pkt n in [rcvbase-Nrcvbase-1]
ACK(n)otherwise
ignore
receiver
Transport Layer 3-44
Selective repeat in action
Transport Layer 3-45
Selective repeatdilemma
Example seq rsquos 0 1 2 3window size=3
receiver sees no difference in two scenariosincorrectly passes duplicate data as new in (a)
Q what relationship between seq size and window size
Transport Layer 3-46
Sequence Number vs Window SizeSuppose we use k bits to represent SNQuestion Whatrsquos the minimum number of bits k necessary for a window size of N
sender
receiver
Go-Back-N
expectedSN
snd_base=expectedSN
Q For a given expectedSN whatrsquos the largest possible value for snd_baseA If all the last N ACKs sent by the receiver are received
snd_base = expectedSNexpectedSN+N-1
senderrsquos window
Transport Layer 3-47
Sequence Number vs Window SizeSuppose we use k bits to represent SNQuestion Whatrsquos the minimum number of bits k necessary for a window size of N
sender
receiver
Go-Back-N
expectedSN
snd_base=expectedSN-N
Q For a given expectedSN whatrsquos the smallest possible value for snd_baseA If all the last N ACKs sent by the receiver are not received
snd_base = expectedSN-NexpectedSN-1
senderrsquos window
Transport Layer 3-48
Sequence Number vs Window Size
sender
receiver
Go-Back-N
expectedSN
snd_base=expectedSN-N
All SNs in the interval [expectedSN-NexpectedSN+N-1] (an interval of size 2N) can be received by the receiver Since the receiver accepts on the packet with SN=expectedSN there should be no other packet within this interval with SN=expectedSN Therefore
2k ge N+1expectedSN+N-1
Transport Layer 3-49
Sequence Number vs Window SizeSuppose we use k bits to represent SNQuestion Whatrsquos the minimum number of bits k necessary for a window size of N
sender
receiver
Selective Repeat
rcv_base
snd_base=rcv_base
Q For a given rcv_base whatrsquos the largest possible value for snd_baseA If all the last N ACKs sent by the receiver are received
snd_base = rcv_base (same as go_back-N)rcv_base+N-1
senderrsquos window
receiverrsquos window
rcv_base+N-1
Transport Layer 3-50
Sequence Number vs Window SizeSuppose we use k bits to represent SNQuestion Whatrsquos the minimum number of bits k necessary for a window size of N
sender
receiver
Selective Repeat
rcv_base
snd_base=rcv_base-N
Q For a given rcv_base whatrsquos the smallest possible value for snd_baseA If all the last N ACKs sent by the receiver are not received
snd_base = rcv_base-N (same as Go-Back-N)rcv_base-1
senderrsquos window
rcv_base
receiverrsquos window
rcv_base+N-1
Transport Layer 3-51
Sequence Number vs Window Size
sender
receiver
Selective Repeat
snd_base=rcv_base-N
All SNs in the interval [rcv_base-Nrcv_base+N-1] (an interval of size 2N) can be received by the receiver Since the receiver should be able to distinguish between all packets in this interval and take corresponding action there should be no two packets within thisinterval having the same SN Therefore
2k ge 2Nrcv_base+N-1
rcv_basercv_base
receiverrsquos window
rcv_base+N-1
Transport Layer 3-52
TCP Overview RFCs 793 1122 1323 2018 2581
full duplex databi-directional data flow in same connectionMSS maximum segment size
connection-orientedhandshaking (exchange of control msgs) initrsquossender receiver state before data exchange
flow controlledsender will not overwhelm receiver
point-to-pointone sender one receiver
reliable in-order byte stream
no ldquomessage boundariesrdquopipelined
TCP congestion and flow control set window size
send amp receive buffers
socketdoor
TCPsend buffer
TCPreceive buffer
socketdoor
segment
applicationwrites data
applicationreads data
Transport Layer 3-53
TCP segment structure
source port dest port
32 bits
applicationdata
(variable length)
sequence numberacknowledgement number
Receive windowUrg data pnterchecksum
FSRPAUheadlen
notused
Options (variable length)
URG urgent data (generally not used)
ACK ACK valid
PSH push data now(generally not used)
RST SYN FINconnection estab(setup teardown
commands)
bytes rcvr willingto accept
Internetchecksum
(as in UDP)
countingby bytes of data(not segments)
Transport Layer 3-54
TCP seq rsquos and ACKsSeq rsquos
byte stream ldquonumberrdquo of first byte in segmentrsquos dataACKs
seq of next byte expected from other sidecumulative ACK
Q how receiver handles out-of-order segmentsA TCP spec doesnrsquot say - up to implementationWidely used implementations of TCP buffer out-of-order segments
Transport Layer 3-55
TCP Round Trip Time and Timeout
Q how to set TCP timeout valuelonger than RTT
but RTT variestoo short premature timeout
unnecessary retransmissions
too long slow reaction to segment loss
Q how to estimate RTTSampleRTT measured time from segment transmission until ACK receipt
ignore retransmissionsSampleRTT will vary want estimated RTT ldquosmootherrdquo
average several recent measurements not just current SampleRTT
Transport Layer 3-56
TCP Round Trip Time and Timeout
EstimatedRTT = (1- α)EstimatedRTT + αSampleRTT
Exponential weighted moving averageinfluence of past sample decreases exponentially fasttypical value α = 0125
Transport Layer 3-57
Example RTT estimationRTT gaiacsumassedu to fantasiaeurecomfr
100
150
200
250
300
350
1 8 15 22 29 36 43 50 57 64 71 78 85 92 99 106
time (seconnds)
RTT
(mill
iseco
nds)
SampleRTT Estimated RTT
Transport Layer 3-58
TCP Round Trip Time and TimeoutSetting the timeout
EstimatedRTT plus ldquosafety marginrdquolarge variation in EstimatedRTT -gt larger safety margin
first estimate of how much SampleRTT deviates from EstimatedRTT
TimeoutInterval = EstimatedRTT + 4DevRTT
DevRTT = (1-β)DevRTT +β|SampleRTT-EstimatedRTT|
(typically β = 025)
Then set timeout interval
Transport Layer 3-59
TCP reliable data transfer
TCP creates rdtservice on top of IPrsquos unreliable servicePipelined segmentsCumulative acksTCP uses single retransmission timer however it just retransmits the first segment in the window
Retransmissions are triggered by
timeout eventsduplicate acks
Initially consider simplified TCP sender
ignore duplicate acksignore flow control congestion control
Transport Layer 3-60
TCP sender eventsdata rcvd from app
Create segment with seq seq is byte-stream number of first data byte in segmentstart timer if not already running (think of timer as for oldest unacked segment)expiration interval TimeOutInterval
timeoutretransmit segment that caused timeout (first segment in the window)restart timer
Ack rcvdIf acknowledges previously unacked segments
update what is known to be ackedstart timer if there are outstanding segments
Transport Layer 3-61
TCP sender(simplified)
NextSeqNum = InitialSeqNumSendBase = InitialSeqNum
loop (forever) switch(event)
event data received from application above create TCP segment with sequence number NextSeqNumif (timer currently not running)
start timerpass segment to IP NextSeqNum = NextSeqNum + length(data)
event timer timeoutretransmit not-yet-acknowledged segment with
smallest sequence numberstart timer
event ACK received with ACK field value of y if (y gt SendBase)
SendBase = yif (there are currently not-yet-acknowledged segments)
start timer
end of loop forever
Commentbull SendBase-1 last cumulatively ackrsquoed byteExamplebull SendBase-1 = 71y= 73 so the rcvrwants 73+ y gt SendBase sothat new data is acked
Transport Layer 3-62
TCP retransmission scenariosHost A
Seq=100 20 bytes data
ACK=100
timepremature timeout
Host B
Seq=92 8 bytes data
ACK=120
Seq=92 8 bytes data
Seq=
92 t
imeo
ut
ACK=120
Host A
Seq=92 8 bytes data
ACK=100
loss
tim
eout
lost ACK scenario
Host B
X
Seq=92 8 bytes data
ACK=100
time
Seq=
92 t
imeo
utSendBase
= 100
SendBase= 120
SendBase= 120
Sendbase= 100
Transport Layer 3-63
TCP retransmission scenarios (more)Host A
Seq=92 8 bytes data
ACK=100
loss
tim
eout
Cumulative ACK scenario
Host B
X
Seq=100 20 bytes data
ACK=120
time
SendBase= 120
Transport Layer 3-64
TCP ACK generation [RFC 1122 RFC 2581]
Event at Receiver
Arrival of in-order segment withexpected seq All data up toexpected seq already ACKed
Arrival of in-order segment withexpected seq One other segment has ACK pending
Arrival of out-of-order segmenthigher-than-expect seq Gap detected
Arrival of segment that partially or completely fills gap
TCP Receiver action
Delayed ACK Wait up to 500msfor next segment If no next segmentsend ACK
Immediately send single cumulative ACK ACKing both in-order segments
Immediately send duplicate ACK indicating seq of next expected byte
Immediate send ACK provided thatsegment startsat lower end of gap
Transport Layer 3-65
Fast Retransmit
Time-out period often relatively long
long delay before resending lost packet
Detect lost segments via duplicate ACKs
Sender often sends many segments back-to-backIf segment is lost there will likely be many duplicate ACKs
If sender receives 3 ACKs for the same data it supposes that segment after ACKeddata was lost
fast retransmit resend segment before timer expires
Transport Layer 3-66
Fast RetransmitResend a segment after 3 duplicate ACKs since a duplicate ACK means that an out-of sequence segment was receivedduplicate ACKs due to packet reorderingif window is small donrsquot get duplicate ACKs
Host A
tim
eout
Host B
time
X
resend seq X2
seq x1seq x2seq x3seq x4seq x5
ACK x1
ACK x1ACK x1ACK x1
tripleduplicate
ACKs
Transport Layer 3-67
event ACK received with ACK field value of y if (y gt SendBase)
SendBase = yif (there are currently not-yet-acknowledged segments)
start timer
else increment count of dup ACKs received for yif (count of dup ACKs received for y = 3)
resend segment with sequence number y
Fast retransmit algorithm
a duplicate ACK for already ACKed segment
fast retransmit
Transport Layer 3-68
TCP Flow Control
receive side of TCP connection has a receive buffer
speed-matching service matching the send rate to the receiving apprsquos drain rate
app process may be slow at reading from buffer
sender wonrsquot overflowreceiverrsquos buffer by
transmitting too muchtoo fast
flow control
Transport Layer 3-69
TCP Flow control how it works
(Suppose TCP receiver discards out-of-order segments)spare room in buffer
= RcvWin
= RcvBuffer-[LastByteRcvd -LastByteRead]
Rcvr advertises spare room by including value of RcvWin in segmentsSender limits unACKeddata to RcvWin
guarantees receive buffer doesnrsquot overflow
Transport Layer 3-70
Sliding Window Flow Control Example
3K
2K SeqNo=0
ReceiverBuffer
0 4KSendersends 2Kof data
2K
AckNo=2048 RcvWin=2048Sendersends 2Kof data 2K SeqNo=2048
4K
AckNo=4096 RcvWin=0
AckNo=4096 RcvWin=1024
Sender blocked
Transport Layer 3-71
Principles of Congestion Control
Congestioninformally ldquotoo many sources sending too much data too fast for network to handlerdquodifferent from flow controlmanifestations
lost packets (buffer overflow at routers)long delays (queueing in router buffers)
a top-10 problem
Transport Layer 3-72
Causescosts of congestion scenario 1
two senders two receiversone router infinite buffers no retransmission
large delays when congestedmaximum achievable throughput
unlimited shared output link buffers
Host Aλin original data
Host B
λout
Transport Layer 3-73
Causescosts of congestion scenario 2
one router finite buffers sender retransmission of lost packet
finite shared output link buffers
Host A λin original data
Host B
λout
λin original data plus retransmitted data
Transport Layer 3-74
Causescosts of congestion scenario 2always (goodput)ldquoperfectrdquo retransmission only when loss
retransmission of delayed (not lost) packet makes larger(than perfect case) for same
λin
λout=
λin
λoutgtλ
inλout
ldquocostsrdquo of congestionmore work (retrans) for given ldquogoodputrdquounneeded retransmissions link carries multiple copies of pkt
R2
R2λin
λ out
b
R2
R2λin
λ out
a
R2
R2λin
λ out
c
R4
R3
Transport Layer 3-75
Causescosts of congestion scenario 3four sendersmultihop pathstimeoutretransmit
λin
Q what happens as and increase λ
in
finite shared output link buffers
Host Aλin original data
Host B
λout
λin original data plus retransmitted data
Transport Layer 3-76
Causescosts of congestion scenario 3
another ldquocostrdquo of congestionwhen packet dropped any ldquoupstream transmission capacity used for that packet was wasted
Host A
Host B
λou
t
Transport Layer 3-77
Approaches towards congestion control
End-end congestion controlno explicit feedback from networkcongestion inferred from end-system observed loss delayapproach taken by TCP
Network-assisted congestion controlrouters provide feedback to end systems
single bit indicating congestion (SNA DECbit TCPIP ECN ATM)explicit rate sender should send at
Two broad approaches towards congestion control
Transport Layer 3-78
TCP Congestion Control
end-end control (no network assistance)sender limits transmissionLastByteSent-LastByteAcked
le CongWin
CongWin is dynamic function of perceived network congestion
How does sender perceive congestionloss event = timeout or3 duplicate acksTCP sender reduces rate (CongWin) after loss event
two modes of operationSlow Start (SS)Congestion avoidance (CA) or Additive Increase Multiplicative Decrease (AIMD)
Transport Layer 3-79
TCP congestion control bandwidth probing
ldquoprobing for bandwidthrdquo increase transmission rate on receipt of ACK until eventually loss occurs then decrease transmission rate
continue to increase on ACK decrease on loss (since available bandwidth is changing depending on other connections in network)
ACKs being received so increase rate
X
X
XX
X loss so decrease rate
send
ing
rate
time
Q how fast to increasedecreasedetails to follow
TCPrsquosldquosawtoothrdquobehavior
Transport Layer 3-80
TCP Congestion Control details
sender limits rate by limiting number of unACKed bytes ldquoin pipelinerdquo
cwnd differs from rwnd (how why)sender limited by min(cwndrwnd)
roughly
cwnd is dynamic function of perceived network congestion
rate = cwndRTT bytessec
LastByteSent-LastByteAcked le cwnd
cwndbytes
RTT
ACK(s)
Transport Layer 3-81
TCP Congestion Control more details
segment loss event reducing cwndtimeout no response from receiver
cut cwnd to 13 duplicate ACKs at least some segments getting through (recall fast retransmit)
cut cwnd in half less aggressively than on timeout
ACK received increase cwndTwo modes of operation
slowstart phase bull increase exponentially
fast (despite name) at connection start or following timeout
congestion avoidance bull increase linearly
Transport Layer 3-82
TCP Slow Start Phasewhen connection begins cwnd = 1 MSS
example MSS = 500 bytes amp RTT = 200 msecinitial rate = 20 kbps
available bandwidth may be gtgt MSSRTT
desirable to quickly ramp up to respectable rate
increase rate exponentially until first loss event or when threshold reached
double cwnd every RTTdone by incrementing cwnd by 1 for every ACK received
Host A
one segment
RTT
Host B
time
two segments
four segments
Transport Layer 3-83
Slow Start ExampleThe congestion window size grows very rapidly
For every ACK we increase CongWin by 1 irrespective of the number of segments ACKrsquoeddouble CongWinevery RTTinitial rate is slow but ramps up exponentially fast
TCP slows down the increase of CongWinwhen CongWin gt ssthresh
segment 1
ACK for segment 1
cwnd = 1
cwnd = 2 segment 2segment 3
ACK for segments 2
cwnd = 4 segment 4segment 5segment 6
ACK for segments 4
cwnd = 7
ACK for segments 3
ACK for segments 5
ACK for segments 6
cwnd = 3
cwnd = 5
cwnd = 6ACK for segments 7
cwnd = 8
segment 7
Transport Layer 3-84
TCP Congestion Avoidance Phase
when cwnd gt ssthreshgrow cwnd linearly
increase cwnd by 1 MSS per RTT approach possible congestion slower than in slowstartimplementation cwnd= cwnd + MSScwndfor each ACK received
ACKs increase cwndby 1 MSS per RTT additive increaseloss cut cwnd in half (non-timeout-detected loss ) multiplicative decrease
AIMD
AIMD Additive IncreaseMultiplicative Decrease
Transport Layer 3-85
Congestion AvoidanceCongestion avoidance phase is started if CongWin has reached the slow-start threshold value
If CongWin gt= ssthresh then each time an ACK is received increment CongWin as follows
bull CongWin = CongWin + 1CongWin (CongWin in segments)
bull In actual TCP implementation CongWin is in BytesCongWin = CongWin + MSS (MSSCongWin)
So CongWin is increased by one only if all CongWinsegments have been acknowledged
Transport Layer 3-86
Example Slow StartCongestion AvoidanceAssume that
ssthresh = 8
cwnd = 1
cwnd = 2
cwnd = 4
cwnd = 8
cwnd = 9
cwnd = 10
02468
101214
t=0
t=2
t=4
t=6
Roundtrip times
Cw
nd(in
seg
men
ts)
ssthresh
cwnd = 3
cwnd = 5cwnd = 6cwnd = 7
Transport Layer 3-87
Slow Start Congestion AvoidanceA typical plot of CongWin for a TCP connection
(MSS = 1500 bytes) with TCP Tahoe
SS
CA
ssthresh
Transport Layer 3-88
Responses to CongestionTCP assumes there is congestion if it detects a packet lossA TCP sender can detect lost packets via loss events
bull Timeout of a retransmission timerbull Receipt of 3 duplicate ACKs (fast retransmit)
TCP interprets a Timeout as a binary congestion signal When a timeout occurs the sender performs
ssthresh is set to half the current size of the congestion window
ssthresh = CongWin 2CongWin is reset to one
CongWin = 1and slow-start is entered
Transport Layer 3-89
Fast Recovery (differentiation btwn two loss events) After 3 dup ACKs (fast Retransmit)
ssthresh = CongWin2CongWin = CongWin2window then grows linearly
But after timeout eventCongWin = 1 MSS window then grows exponentiallyto the threshold then grows linearly
bull 3 dup ACKs indicates network capable of delivering some segmentsbull timeout before 3 dup ACKs is ldquomore alarmingrdquo
Philosophy
3-90
TCP Congestion ControlInitially
CongWin = 1ssthresh = advertised window size
New Ack receivedif (CongWin lt ssthresh) Slow Start
CongWin = CongWin + 1else Congestion Avoidance
CongWin = CongWin + 1CongWinTimeout
ssthresh = CongWin2CongWin = 1
Fast Retransmissionssthresh = CongWin2CongWin = CongWin2
Slow Start (exponential increase phase) is continued until CongWin reaches half of the level where the loss event occurred last time CongWin is increased slowly after (linear increase in Congestion Avoidance phase)
Transport Layer 3-91
Popular ldquoflavorsrdquo of TCP
ssthresh
ssthresh
TCP Tahoe
TCP Reno
Transmission round
cwnd
win
dow
siz
e (in
seg
men
ts)
Transport Layer 3-92
Summary TCP Congestion ControlWhen CongWin is below Threshold sender in slow-start phase window grows exponentiallyWhen CongWin is above Threshold sender is in congestion-avoidance phase window grows linearlyWhen a triple duplicate ACK occurs Threshold set to CongWin2 and CongWin set to ThresholdWhen timeout occurs Threshold set to CongWin2 and CongWin is set to 1 MSS The actual sender window size is determined based on the congestion and flow control algorithms
SenderWin=min(RcvWinCongWin)
Transport Layer 3-93
TCP Congestion Control SummaryEvent State TCP Sender Action Commentary
ACK receipt for previously unackeddata
Slow Start (SS)
CongWin = CongWin + MSS If (CongWin gt Threshold)
set state to ldquoCongestion Avoidancerdquo
Resulting in a doubling of CongWin every RTT
ACK receipt for previously unackeddata
CongestionAvoidance (CA)
CongWin = CongWin+MSS (MSSCongWin)
Additive increase resulting in increase of CongWin by 1 MSS every RTT
Loss event detected by triple duplicate ACK
SS or CA Threshold = CongWin2 CongWin = ThresholdSet state to ldquoCongestion Avoidancerdquo
Fast recovery implementing multiplicative decrease CongWin will not drop below 1 MSS
Timeout SS or CA Threshold = CongWin2 CongWin = 1 MSSSet state to ldquoSlow Startrdquo
Enter slow start
Duplicate ACK
SS or CA Increment duplicate ACK count for segment being acked
CongWin and Threshold not changed
Transport Layer 3-94
TCP throughput
Q whatrsquos average throughout of TCP as function of window size RTT
ignoring slow startlet W be window size when loss occurs
when window is W throughput is WRTTjust after loss window drops to W2 throughput to W2RTT average throughout 75 WRTT
Transport Layer 3-95
TCP Futures TCP over ldquolong fat pipesrdquo
example 1500 byte segments 100ms RTT want 10 Gbps throughputrequires window size W = 83333 in-flight segmentsthroughput in terms of loss rate
L = 210-10 Wownew versions of TCP for high-speed
LRTTMSSsdot221
Transport Layer 3-96
Fairness goal if K TCP sessions share same bottleneck link of bandwidth R each should have average rate of RK
TCP connection 1
bottleneckrouter
capacity R
TCP connection 2
TCP Fairness
Transport Layer 3-97
Why is TCP fairTwo competing sessions
Additive increase gives slope of 1 as throughout increasesmultiplicative decrease decreases throughput proportionally
R
R
equal bandwidth share
Connection 1 throughput
Conn
ecti
on 2
thr
ough
p ut
congestion avoidance additive increaseloss decrease window by factor of 2
congestion avoidance additive increaseloss decrease window by factor of 2
Transport Layer 3-98
Fairness (more)Fairness and UDP
Multimedia apps often do not use TCP
do not want rate throttled by congestion control
Instead use UDPpump audiovideo at constant rate tolerate packet loss
Research area TCP friendly
Fairness and parallel TCP connectionsnothing prevents app from opening parallel cnctionsbetween 2 hostsWeb browsers do this Example link of rate R supporting 9 cnctions
new app asks for 1 TCP gets rate R10new app asks for 11 TCPs gets R2
Transport Layer 3-99
TCP Connection ManagementRecall TCP sender receiver
establish ldquoconnectionrdquobefore exchanging data segmentsinitialize TCP variables
seq sbuffers flow control info (eg RcvWindow)
client connection initiatorSocket clientSocket = new Socket(hostnameport
number)
server contacted by clientSocket connectionSocket = welcomeSocketaccept()
Three way handshakeStep 1 client host sends TCP
SYN segment to serverspecifies initial seq no data
Step 2 server host receives SYN replies with SYNACK segment
server allocates buffersspecifies server initial seq
Step 3 client receives SYNACK replies with ACK segment which may contain data
Transport Layer 3-100
TCP Connection Management (cont)
Closing a connection
client closes socketclientSocketclose()
Step 1 client end system sends TCP FIN control segment to server
Step 2 server receives FIN replies with ACK Closes connection sends FIN
client
FIN
server
ACK
ACK
FIN
close
close
closed
tim
ed w
ait
Transport Layer 3-101
TCP Connection Management (cont)
Step 3 client receives FIN replies with ACK
Enters ldquotimed waitrdquo -will respond with ACK to received FINs
Step 4 server receives ACK Connection closed
client
FIN
server
ACK
ACK
FIN
closing
closing
closed
tim
ed w
ait
closed
Transport Layer 3-102
TCP Connection Management (cont)
TCP clientlifecycle
TCP serverlifecycle
Transport Layer 3-103
Tuning TCPIP Parameters TCPIP parameters
A set of default values may not be optimal for all applicationsThe network administrator may wish to turn on or off some TCPIP functions for performance or security considerations
Many Unix and Linux systems provide some flexibility in tuning the TCPIP kernelsbinsysctl is used to configure the Linux kernel parameters at runtime
Default kernel configuration file is sbinsysctlconfFrequently used sysctl options
bull sysctl ndasha or sysctl ndashA list all current valuesbull sysctl ndashp file_name load the sysctl setting from a configuration
filebull sysctl ndashw variable=value change the value of the parameter
Transport Layer 3-104
SomeTCP Parameters in Linux Kerneltcp_syn_retries
Number of SYN packets the kernel will send before giving up on the new connection
tcp_synack_retriesnumber of SYN+ACK packets sent before the kernel gives up on the connection
tcp_window_scalingMaximum window size of 65535 bytes not enough for for really fast networks The window scaling options allows for almost gigabyte windows which is good for connections with large delay-bandwidth product
tcp_max_syn_backlogMaximal number of remembered connection requests which still did not receive an acknowledgment from connecting client
tcp_fin_timeoutHow many seconds to wait for a final FIN packet before the socket is closed required to prevent denial-of-service (DoS) attacks Default value is 60 seconds
Transport Layer 3-105
SomeTCP Parameters in Linux Kerneltcp_rmem
This is a vector of 3 integers [min default max] These parameters are used by TCP to dynamically adjust receive buffer sizesmin - minimum size of the receive buffer used by each TCP socket The default value is 4K default - the default size of the receive buffer for a TCP socket The default value is 87380 bytes and is lowered to 43689 in low memory systems If larger receive buffer sizes are desired this value should be increased max - the maximum size of the receive buffer used by each TCP socket The default value of 873802 bytes is lowered to 87380 in low memory systems
tcp_smemSend buffer parameters [min default max] similar to tcp_rmem
- Chapter 3 Transport Layer
- Transport services and protocols
- Transport vs network layer
- Internet transport-layer protocols
- Multiplexingdemultiplexing
- How demultiplexing works
- Connectionless demultiplexing
- Connection-oriented demux
- Connection-oriented demux (cont)
- Connection-oriented demux Threaded Web Server
- UDP User Datagram Protocol [RFC 768]
- UDP more
- UDP checksum
- Principles of Reliable data transfer
- Reliable data transfer getting started
- Reliable data transfer getting started
- Rdt10 reliable transfer over a reliable channel
- Rdt20 channel with bit errors
- rdt20 FSM specification
- rdt20 operation with no errors
- rdt20 error scenario
- rdt20 has a fatal flaw
- rdt21 sender handles garbled ACKNAKs
- rdt21 receiver handles garbled ACKNAKs
- rdt21 discussion
- rdt22 a NAK-free protocol
- rdt22 sender receiver fragments
- rdt30 channels with errors and loss
- rdt30 sender
- rdt30 in action
- rdt30 in action
- Performance of rdt30
- rdt30 stop-and-wait operation
- Pipelined protocols
- Pipelining increased utilization
- Go-Back-N
- GBN sender extended FSM
- GBN receiver extended FSM
- GBN inaction
- Selective Repeat
- Selective repeat sender receiver windows
- Selective repeat
- Selective repeat in action
- Selective repeat dilemma
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- TCP Overview RFCs 793 1122 1323 2018 2581
- TCP segment structure
- TCP seq rsquos and ACKs
- TCP Round Trip Time and Timeout
- TCP Round Trip Time and Timeout
- Example RTT estimation
- TCP Round Trip Time and Timeout
- TCP reliable data transfer
- TCP sender events
- TCP sender(simplified)
- TCP retransmission scenarios
- TCP retransmission scenarios (more)
- TCP ACK generation [RFC 1122 RFC 2581]
- Fast Retransmit
- Fast Retransmit
- Fast retransmit algorithm
- TCP Flow Control
- TCP Flow control how it works
- Sliding Window Flow Control Example
- Principles of Congestion Control
- Causescosts of congestion scenario 1
- Causescosts of congestion scenario 2
- Causescosts of congestion scenario 2
- Causescosts of congestion scenario 3
- Causescosts of congestion scenario 3
- Approaches towards congestion control
- TCP Congestion Control
- TCP congestion control bandwidth probing
- TCP Congestion Control details
- TCP Congestion Control more details
- TCP Slow Start Phase
- Slow Start Example
- TCP Congestion Avoidance Phase
- Congestion Avoidance
- Example Slow StartCongestion Avoidance
- Slow Start Congestion Avoidance
- Responses to Congestion
- Fast Recovery (differentiation btwn two loss events)
- TCP Congestion Control
- Popular ldquoflavorsrdquo of TCP
- Summary TCP Congestion Control
- TCP Congestion Control Summary
- TCP throughput
- TCP Futures TCP over ldquolong fat pipesrdquo
- TCP Fairness
- Why is TCP fair
- Fairness (more)
- TCP Connection Management
- TCP Connection Management (cont)
- TCP Connection Management (cont)
- TCP Connection Management (cont)
- Tuning TCPIP Parameters
- SomeTCP Parameters in Linux Kernel
- SomeTCP Parameters in Linux Kernel
-
Transport Layer 3-40
GBN inaction
Transport Layer 3-41
Selective Repeat
receiver individually acknowledges all correctly received pkts
buffers pkts as needed for eventual in-order delivery to upper layer
sender only resends pkts for which ACK not received
sender timer for each unACKed pktsender window
N consecutive seq rsquosagain limits seq s of sent unACKed pkts
Transport Layer 3-42
Selective repeat sender receiver windows
Transport Layer 3-43
Selective repeat
data from above if next available seq in window send pkt
timeout(n)resend pkt n restart timer
ACK(n) in [sendbasesendbase+N-1]
mark pkt n as receivedif n smallest unACKed pkt advance window base to next unACKed seq
senderpkt n in [rcvbase rcvbase+N-1]
send ACK(n)out-of-order bufferin-order deliver (also deliver buffered in-order pkts) advance window to next not-yet-received pkt
pkt n in [rcvbase-Nrcvbase-1]
ACK(n)otherwise
ignore
receiver
Transport Layer 3-44
Selective repeat in action
Transport Layer 3-45
Selective repeatdilemma
Example seq rsquos 0 1 2 3window size=3
receiver sees no difference in two scenariosincorrectly passes duplicate data as new in (a)
Q what relationship between seq size and window size
Transport Layer 3-46
Sequence Number vs Window SizeSuppose we use k bits to represent SNQuestion Whatrsquos the minimum number of bits k necessary for a window size of N
sender
receiver
Go-Back-N
expectedSN
snd_base=expectedSN
Q For a given expectedSN whatrsquos the largest possible value for snd_baseA If all the last N ACKs sent by the receiver are received
snd_base = expectedSNexpectedSN+N-1
senderrsquos window
Transport Layer 3-47
Sequence Number vs Window SizeSuppose we use k bits to represent SNQuestion Whatrsquos the minimum number of bits k necessary for a window size of N
sender
receiver
Go-Back-N
expectedSN
snd_base=expectedSN-N
Q For a given expectedSN whatrsquos the smallest possible value for snd_baseA If all the last N ACKs sent by the receiver are not received
snd_base = expectedSN-NexpectedSN-1
senderrsquos window
Transport Layer 3-48
Sequence Number vs Window Size
sender
receiver
Go-Back-N
expectedSN
snd_base=expectedSN-N
All SNs in the interval [expectedSN-NexpectedSN+N-1] (an interval of size 2N) can be received by the receiver Since the receiver accepts on the packet with SN=expectedSN there should be no other packet within this interval with SN=expectedSN Therefore
2k ge N+1expectedSN+N-1
Transport Layer 3-49
Sequence Number vs Window SizeSuppose we use k bits to represent SNQuestion Whatrsquos the minimum number of bits k necessary for a window size of N
sender
receiver
Selective Repeat
rcv_base
snd_base=rcv_base
Q For a given rcv_base whatrsquos the largest possible value for snd_baseA If all the last N ACKs sent by the receiver are received
snd_base = rcv_base (same as go_back-N)rcv_base+N-1
senderrsquos window
receiverrsquos window
rcv_base+N-1
Transport Layer 3-50
Sequence Number vs Window SizeSuppose we use k bits to represent SNQuestion Whatrsquos the minimum number of bits k necessary for a window size of N
sender
receiver
Selective Repeat
rcv_base
snd_base=rcv_base-N
Q For a given rcv_base whatrsquos the smallest possible value for snd_baseA If all the last N ACKs sent by the receiver are not received
snd_base = rcv_base-N (same as Go-Back-N)rcv_base-1
senderrsquos window
rcv_base
receiverrsquos window
rcv_base+N-1
Transport Layer 3-51
Sequence Number vs Window Size
sender
receiver
Selective Repeat
snd_base=rcv_base-N
All SNs in the interval [rcv_base-Nrcv_base+N-1] (an interval of size 2N) can be received by the receiver Since the receiver should be able to distinguish between all packets in this interval and take corresponding action there should be no two packets within thisinterval having the same SN Therefore
2k ge 2Nrcv_base+N-1
rcv_basercv_base
receiverrsquos window
rcv_base+N-1
Transport Layer 3-52
TCP Overview RFCs 793 1122 1323 2018 2581
full duplex databi-directional data flow in same connectionMSS maximum segment size
connection-orientedhandshaking (exchange of control msgs) initrsquossender receiver state before data exchange
flow controlledsender will not overwhelm receiver
point-to-pointone sender one receiver
reliable in-order byte stream
no ldquomessage boundariesrdquopipelined
TCP congestion and flow control set window size
send amp receive buffers
socketdoor
TCPsend buffer
TCPreceive buffer
socketdoor
segment
applicationwrites data
applicationreads data
Transport Layer 3-53
TCP segment structure
source port dest port
32 bits
applicationdata
(variable length)
sequence numberacknowledgement number
Receive windowUrg data pnterchecksum
FSRPAUheadlen
notused
Options (variable length)
URG urgent data (generally not used)
ACK ACK valid
PSH push data now(generally not used)
RST SYN FINconnection estab(setup teardown
commands)
bytes rcvr willingto accept
Internetchecksum
(as in UDP)
countingby bytes of data(not segments)
Transport Layer 3-54
TCP seq rsquos and ACKsSeq rsquos
byte stream ldquonumberrdquo of first byte in segmentrsquos dataACKs
seq of next byte expected from other sidecumulative ACK
Q how receiver handles out-of-order segmentsA TCP spec doesnrsquot say - up to implementationWidely used implementations of TCP buffer out-of-order segments
Transport Layer 3-55
TCP Round Trip Time and Timeout
Q how to set TCP timeout valuelonger than RTT
but RTT variestoo short premature timeout
unnecessary retransmissions
too long slow reaction to segment loss
Q how to estimate RTTSampleRTT measured time from segment transmission until ACK receipt
ignore retransmissionsSampleRTT will vary want estimated RTT ldquosmootherrdquo
average several recent measurements not just current SampleRTT
Transport Layer 3-56
TCP Round Trip Time and Timeout
EstimatedRTT = (1- α)EstimatedRTT + αSampleRTT
Exponential weighted moving averageinfluence of past sample decreases exponentially fasttypical value α = 0125
Transport Layer 3-57
Example RTT estimationRTT gaiacsumassedu to fantasiaeurecomfr
100
150
200
250
300
350
1 8 15 22 29 36 43 50 57 64 71 78 85 92 99 106
time (seconnds)
RTT
(mill
iseco
nds)
SampleRTT Estimated RTT
Transport Layer 3-58
TCP Round Trip Time and TimeoutSetting the timeout
EstimatedRTT plus ldquosafety marginrdquolarge variation in EstimatedRTT -gt larger safety margin
first estimate of how much SampleRTT deviates from EstimatedRTT
TimeoutInterval = EstimatedRTT + 4DevRTT
DevRTT = (1-β)DevRTT +β|SampleRTT-EstimatedRTT|
(typically β = 025)
Then set timeout interval
Transport Layer 3-59
TCP reliable data transfer
TCP creates rdtservice on top of IPrsquos unreliable servicePipelined segmentsCumulative acksTCP uses single retransmission timer however it just retransmits the first segment in the window
Retransmissions are triggered by
timeout eventsduplicate acks
Initially consider simplified TCP sender
ignore duplicate acksignore flow control congestion control
Transport Layer 3-60
TCP sender eventsdata rcvd from app
Create segment with seq seq is byte-stream number of first data byte in segmentstart timer if not already running (think of timer as for oldest unacked segment)expiration interval TimeOutInterval
timeoutretransmit segment that caused timeout (first segment in the window)restart timer
Ack rcvdIf acknowledges previously unacked segments
update what is known to be ackedstart timer if there are outstanding segments
Transport Layer 3-61
TCP sender(simplified)
NextSeqNum = InitialSeqNumSendBase = InitialSeqNum
loop (forever) switch(event)
event data received from application above create TCP segment with sequence number NextSeqNumif (timer currently not running)
start timerpass segment to IP NextSeqNum = NextSeqNum + length(data)
event timer timeoutretransmit not-yet-acknowledged segment with
smallest sequence numberstart timer
event ACK received with ACK field value of y if (y gt SendBase)
SendBase = yif (there are currently not-yet-acknowledged segments)
start timer
end of loop forever
Commentbull SendBase-1 last cumulatively ackrsquoed byteExamplebull SendBase-1 = 71y= 73 so the rcvrwants 73+ y gt SendBase sothat new data is acked
Transport Layer 3-62
TCP retransmission scenariosHost A
Seq=100 20 bytes data
ACK=100
timepremature timeout
Host B
Seq=92 8 bytes data
ACK=120
Seq=92 8 bytes data
Seq=
92 t
imeo
ut
ACK=120
Host A
Seq=92 8 bytes data
ACK=100
loss
tim
eout
lost ACK scenario
Host B
X
Seq=92 8 bytes data
ACK=100
time
Seq=
92 t
imeo
utSendBase
= 100
SendBase= 120
SendBase= 120
Sendbase= 100
Transport Layer 3-63
TCP retransmission scenarios (more)Host A
Seq=92 8 bytes data
ACK=100
loss
tim
eout
Cumulative ACK scenario
Host B
X
Seq=100 20 bytes data
ACK=120
time
SendBase= 120
Transport Layer 3-64
TCP ACK generation [RFC 1122 RFC 2581]
Event at Receiver
Arrival of in-order segment withexpected seq All data up toexpected seq already ACKed
Arrival of in-order segment withexpected seq One other segment has ACK pending
Arrival of out-of-order segmenthigher-than-expect seq Gap detected
Arrival of segment that partially or completely fills gap
TCP Receiver action
Delayed ACK Wait up to 500msfor next segment If no next segmentsend ACK
Immediately send single cumulative ACK ACKing both in-order segments
Immediately send duplicate ACK indicating seq of next expected byte
Immediate send ACK provided thatsegment startsat lower end of gap
Transport Layer 3-65
Fast Retransmit
Time-out period often relatively long
long delay before resending lost packet
Detect lost segments via duplicate ACKs
Sender often sends many segments back-to-backIf segment is lost there will likely be many duplicate ACKs
If sender receives 3 ACKs for the same data it supposes that segment after ACKeddata was lost
fast retransmit resend segment before timer expires
Transport Layer 3-66
Fast RetransmitResend a segment after 3 duplicate ACKs since a duplicate ACK means that an out-of sequence segment was receivedduplicate ACKs due to packet reorderingif window is small donrsquot get duplicate ACKs
Host A
tim
eout
Host B
time
X
resend seq X2
seq x1seq x2seq x3seq x4seq x5
ACK x1
ACK x1ACK x1ACK x1
tripleduplicate
ACKs
Transport Layer 3-67
event ACK received with ACK field value of y if (y gt SendBase)
SendBase = yif (there are currently not-yet-acknowledged segments)
start timer
else increment count of dup ACKs received for yif (count of dup ACKs received for y = 3)
resend segment with sequence number y
Fast retransmit algorithm
a duplicate ACK for already ACKed segment
fast retransmit
Transport Layer 3-68
TCP Flow Control
receive side of TCP connection has a receive buffer
speed-matching service matching the send rate to the receiving apprsquos drain rate
app process may be slow at reading from buffer
sender wonrsquot overflowreceiverrsquos buffer by
transmitting too muchtoo fast
flow control
Transport Layer 3-69
TCP Flow control how it works
(Suppose TCP receiver discards out-of-order segments)spare room in buffer
= RcvWin
= RcvBuffer-[LastByteRcvd -LastByteRead]
Rcvr advertises spare room by including value of RcvWin in segmentsSender limits unACKeddata to RcvWin
guarantees receive buffer doesnrsquot overflow
Transport Layer 3-70
Sliding Window Flow Control Example
3K
2K SeqNo=0
ReceiverBuffer
0 4KSendersends 2Kof data
2K
AckNo=2048 RcvWin=2048Sendersends 2Kof data 2K SeqNo=2048
4K
AckNo=4096 RcvWin=0
AckNo=4096 RcvWin=1024
Sender blocked
Transport Layer 3-71
Principles of Congestion Control
Congestioninformally ldquotoo many sources sending too much data too fast for network to handlerdquodifferent from flow controlmanifestations
lost packets (buffer overflow at routers)long delays (queueing in router buffers)
a top-10 problem
Transport Layer 3-72
Causescosts of congestion scenario 1
two senders two receiversone router infinite buffers no retransmission
large delays when congestedmaximum achievable throughput
unlimited shared output link buffers
Host Aλin original data
Host B
λout
Transport Layer 3-73
Causescosts of congestion scenario 2
one router finite buffers sender retransmission of lost packet
finite shared output link buffers
Host A λin original data
Host B
λout
λin original data plus retransmitted data
Transport Layer 3-74
Causescosts of congestion scenario 2always (goodput)ldquoperfectrdquo retransmission only when loss
retransmission of delayed (not lost) packet makes larger(than perfect case) for same
λin
λout=
λin
λoutgtλ
inλout
ldquocostsrdquo of congestionmore work (retrans) for given ldquogoodputrdquounneeded retransmissions link carries multiple copies of pkt
R2
R2λin
λ out
b
R2
R2λin
λ out
a
R2
R2λin
λ out
c
R4
R3
Transport Layer 3-75
Causescosts of congestion scenario 3four sendersmultihop pathstimeoutretransmit
λin
Q what happens as and increase λ
in
finite shared output link buffers
Host Aλin original data
Host B
λout
λin original data plus retransmitted data
Transport Layer 3-76
Causescosts of congestion scenario 3
another ldquocostrdquo of congestionwhen packet dropped any ldquoupstream transmission capacity used for that packet was wasted
Host A
Host B
λou
t
Transport Layer 3-77
Approaches towards congestion control
End-end congestion controlno explicit feedback from networkcongestion inferred from end-system observed loss delayapproach taken by TCP
Network-assisted congestion controlrouters provide feedback to end systems
single bit indicating congestion (SNA DECbit TCPIP ECN ATM)explicit rate sender should send at
Two broad approaches towards congestion control
Transport Layer 3-78
TCP Congestion Control
end-end control (no network assistance)sender limits transmissionLastByteSent-LastByteAcked
le CongWin
CongWin is dynamic function of perceived network congestion
How does sender perceive congestionloss event = timeout or3 duplicate acksTCP sender reduces rate (CongWin) after loss event
two modes of operationSlow Start (SS)Congestion avoidance (CA) or Additive Increase Multiplicative Decrease (AIMD)
Transport Layer 3-79
TCP congestion control bandwidth probing
ldquoprobing for bandwidthrdquo increase transmission rate on receipt of ACK until eventually loss occurs then decrease transmission rate
continue to increase on ACK decrease on loss (since available bandwidth is changing depending on other connections in network)
ACKs being received so increase rate
X
X
XX
X loss so decrease rate
send
ing
rate
time
Q how fast to increasedecreasedetails to follow
TCPrsquosldquosawtoothrdquobehavior
Transport Layer 3-80
TCP Congestion Control details
sender limits rate by limiting number of unACKed bytes ldquoin pipelinerdquo
cwnd differs from rwnd (how why)sender limited by min(cwndrwnd)
roughly
cwnd is dynamic function of perceived network congestion
rate = cwndRTT bytessec
LastByteSent-LastByteAcked le cwnd
cwndbytes
RTT
ACK(s)
Transport Layer 3-81
TCP Congestion Control more details
segment loss event reducing cwndtimeout no response from receiver
cut cwnd to 13 duplicate ACKs at least some segments getting through (recall fast retransmit)
cut cwnd in half less aggressively than on timeout
ACK received increase cwndTwo modes of operation
slowstart phase bull increase exponentially
fast (despite name) at connection start or following timeout
congestion avoidance bull increase linearly
Transport Layer 3-82
TCP Slow Start Phasewhen connection begins cwnd = 1 MSS
example MSS = 500 bytes amp RTT = 200 msecinitial rate = 20 kbps
available bandwidth may be gtgt MSSRTT
desirable to quickly ramp up to respectable rate
increase rate exponentially until first loss event or when threshold reached
double cwnd every RTTdone by incrementing cwnd by 1 for every ACK received
Host A
one segment
RTT
Host B
time
two segments
four segments
Transport Layer 3-83
Slow Start ExampleThe congestion window size grows very rapidly
For every ACK we increase CongWin by 1 irrespective of the number of segments ACKrsquoeddouble CongWinevery RTTinitial rate is slow but ramps up exponentially fast
TCP slows down the increase of CongWinwhen CongWin gt ssthresh
segment 1
ACK for segment 1
cwnd = 1
cwnd = 2 segment 2segment 3
ACK for segments 2
cwnd = 4 segment 4segment 5segment 6
ACK for segments 4
cwnd = 7
ACK for segments 3
ACK for segments 5
ACK for segments 6
cwnd = 3
cwnd = 5
cwnd = 6ACK for segments 7
cwnd = 8
segment 7
Transport Layer 3-84
TCP Congestion Avoidance Phase
when cwnd gt ssthreshgrow cwnd linearly
increase cwnd by 1 MSS per RTT approach possible congestion slower than in slowstartimplementation cwnd= cwnd + MSScwndfor each ACK received
ACKs increase cwndby 1 MSS per RTT additive increaseloss cut cwnd in half (non-timeout-detected loss ) multiplicative decrease
AIMD
AIMD Additive IncreaseMultiplicative Decrease
Transport Layer 3-85
Congestion AvoidanceCongestion avoidance phase is started if CongWin has reached the slow-start threshold value
If CongWin gt= ssthresh then each time an ACK is received increment CongWin as follows
bull CongWin = CongWin + 1CongWin (CongWin in segments)
bull In actual TCP implementation CongWin is in BytesCongWin = CongWin + MSS (MSSCongWin)
So CongWin is increased by one only if all CongWinsegments have been acknowledged
Transport Layer 3-86
Example Slow StartCongestion AvoidanceAssume that
ssthresh = 8
cwnd = 1
cwnd = 2
cwnd = 4
cwnd = 8
cwnd = 9
cwnd = 10
02468
101214
t=0
t=2
t=4
t=6
Roundtrip times
Cw
nd(in
seg
men
ts)
ssthresh
cwnd = 3
cwnd = 5cwnd = 6cwnd = 7
Transport Layer 3-87
Slow Start Congestion AvoidanceA typical plot of CongWin for a TCP connection
(MSS = 1500 bytes) with TCP Tahoe
SS
CA
ssthresh
Transport Layer 3-88
Responses to CongestionTCP assumes there is congestion if it detects a packet lossA TCP sender can detect lost packets via loss events
bull Timeout of a retransmission timerbull Receipt of 3 duplicate ACKs (fast retransmit)
TCP interprets a Timeout as a binary congestion signal When a timeout occurs the sender performs
ssthresh is set to half the current size of the congestion window
ssthresh = CongWin 2CongWin is reset to one
CongWin = 1and slow-start is entered
Transport Layer 3-89
Fast Recovery (differentiation btwn two loss events) After 3 dup ACKs (fast Retransmit)
ssthresh = CongWin2CongWin = CongWin2window then grows linearly
But after timeout eventCongWin = 1 MSS window then grows exponentiallyto the threshold then grows linearly
bull 3 dup ACKs indicates network capable of delivering some segmentsbull timeout before 3 dup ACKs is ldquomore alarmingrdquo
Philosophy
3-90
TCP Congestion ControlInitially
CongWin = 1ssthresh = advertised window size
New Ack receivedif (CongWin lt ssthresh) Slow Start
CongWin = CongWin + 1else Congestion Avoidance
CongWin = CongWin + 1CongWinTimeout
ssthresh = CongWin2CongWin = 1
Fast Retransmissionssthresh = CongWin2CongWin = CongWin2
Slow Start (exponential increase phase) is continued until CongWin reaches half of the level where the loss event occurred last time CongWin is increased slowly after (linear increase in Congestion Avoidance phase)
Transport Layer 3-91
Popular ldquoflavorsrdquo of TCP
ssthresh
ssthresh
TCP Tahoe
TCP Reno
Transmission round
cwnd
win
dow
siz
e (in
seg
men
ts)
Transport Layer 3-92
Summary TCP Congestion ControlWhen CongWin is below Threshold sender in slow-start phase window grows exponentiallyWhen CongWin is above Threshold sender is in congestion-avoidance phase window grows linearlyWhen a triple duplicate ACK occurs Threshold set to CongWin2 and CongWin set to ThresholdWhen timeout occurs Threshold set to CongWin2 and CongWin is set to 1 MSS The actual sender window size is determined based on the congestion and flow control algorithms
SenderWin=min(RcvWinCongWin)
Transport Layer 3-93
TCP Congestion Control SummaryEvent State TCP Sender Action Commentary
ACK receipt for previously unackeddata
Slow Start (SS)
CongWin = CongWin + MSS If (CongWin gt Threshold)
set state to ldquoCongestion Avoidancerdquo
Resulting in a doubling of CongWin every RTT
ACK receipt for previously unackeddata
CongestionAvoidance (CA)
CongWin = CongWin+MSS (MSSCongWin)
Additive increase resulting in increase of CongWin by 1 MSS every RTT
Loss event detected by triple duplicate ACK
SS or CA Threshold = CongWin2 CongWin = ThresholdSet state to ldquoCongestion Avoidancerdquo
Fast recovery implementing multiplicative decrease CongWin will not drop below 1 MSS
Timeout SS or CA Threshold = CongWin2 CongWin = 1 MSSSet state to ldquoSlow Startrdquo
Enter slow start
Duplicate ACK
SS or CA Increment duplicate ACK count for segment being acked
CongWin and Threshold not changed
Transport Layer 3-94
TCP throughput
Q whatrsquos average throughout of TCP as function of window size RTT
ignoring slow startlet W be window size when loss occurs
when window is W throughput is WRTTjust after loss window drops to W2 throughput to W2RTT average throughout 75 WRTT
Transport Layer 3-95
TCP Futures TCP over ldquolong fat pipesrdquo
example 1500 byte segments 100ms RTT want 10 Gbps throughputrequires window size W = 83333 in-flight segmentsthroughput in terms of loss rate
L = 210-10 Wownew versions of TCP for high-speed
LRTTMSSsdot221
Transport Layer 3-96
Fairness goal if K TCP sessions share same bottleneck link of bandwidth R each should have average rate of RK
TCP connection 1
bottleneckrouter
capacity R
TCP connection 2
TCP Fairness
Transport Layer 3-97
Why is TCP fairTwo competing sessions
Additive increase gives slope of 1 as throughout increasesmultiplicative decrease decreases throughput proportionally
R
R
equal bandwidth share
Connection 1 throughput
Conn
ecti
on 2
thr
ough
p ut
congestion avoidance additive increaseloss decrease window by factor of 2
congestion avoidance additive increaseloss decrease window by factor of 2
Transport Layer 3-98
Fairness (more)Fairness and UDP
Multimedia apps often do not use TCP
do not want rate throttled by congestion control
Instead use UDPpump audiovideo at constant rate tolerate packet loss
Research area TCP friendly
Fairness and parallel TCP connectionsnothing prevents app from opening parallel cnctionsbetween 2 hostsWeb browsers do this Example link of rate R supporting 9 cnctions
new app asks for 1 TCP gets rate R10new app asks for 11 TCPs gets R2
Transport Layer 3-99
TCP Connection ManagementRecall TCP sender receiver
establish ldquoconnectionrdquobefore exchanging data segmentsinitialize TCP variables
seq sbuffers flow control info (eg RcvWindow)
client connection initiatorSocket clientSocket = new Socket(hostnameport
number)
server contacted by clientSocket connectionSocket = welcomeSocketaccept()
Three way handshakeStep 1 client host sends TCP
SYN segment to serverspecifies initial seq no data
Step 2 server host receives SYN replies with SYNACK segment
server allocates buffersspecifies server initial seq
Step 3 client receives SYNACK replies with ACK segment which may contain data
Transport Layer 3-100
TCP Connection Management (cont)
Closing a connection
client closes socketclientSocketclose()
Step 1 client end system sends TCP FIN control segment to server
Step 2 server receives FIN replies with ACK Closes connection sends FIN
client
FIN
server
ACK
ACK
FIN
close
close
closed
tim
ed w
ait
Transport Layer 3-101
TCP Connection Management (cont)
Step 3 client receives FIN replies with ACK
Enters ldquotimed waitrdquo -will respond with ACK to received FINs
Step 4 server receives ACK Connection closed
client
FIN
server
ACK
ACK
FIN
closing
closing
closed
tim
ed w
ait
closed
Transport Layer 3-102
TCP Connection Management (cont)
TCP clientlifecycle
TCP serverlifecycle
Transport Layer 3-103
Tuning TCPIP Parameters TCPIP parameters
A set of default values may not be optimal for all applicationsThe network administrator may wish to turn on or off some TCPIP functions for performance or security considerations
Many Unix and Linux systems provide some flexibility in tuning the TCPIP kernelsbinsysctl is used to configure the Linux kernel parameters at runtime
Default kernel configuration file is sbinsysctlconfFrequently used sysctl options
bull sysctl ndasha or sysctl ndashA list all current valuesbull sysctl ndashp file_name load the sysctl setting from a configuration
filebull sysctl ndashw variable=value change the value of the parameter
Transport Layer 3-104
SomeTCP Parameters in Linux Kerneltcp_syn_retries
Number of SYN packets the kernel will send before giving up on the new connection
tcp_synack_retriesnumber of SYN+ACK packets sent before the kernel gives up on the connection
tcp_window_scalingMaximum window size of 65535 bytes not enough for for really fast networks The window scaling options allows for almost gigabyte windows which is good for connections with large delay-bandwidth product
tcp_max_syn_backlogMaximal number of remembered connection requests which still did not receive an acknowledgment from connecting client
tcp_fin_timeoutHow many seconds to wait for a final FIN packet before the socket is closed required to prevent denial-of-service (DoS) attacks Default value is 60 seconds
Transport Layer 3-105
SomeTCP Parameters in Linux Kerneltcp_rmem
This is a vector of 3 integers [min default max] These parameters are used by TCP to dynamically adjust receive buffer sizesmin - minimum size of the receive buffer used by each TCP socket The default value is 4K default - the default size of the receive buffer for a TCP socket The default value is 87380 bytes and is lowered to 43689 in low memory systems If larger receive buffer sizes are desired this value should be increased max - the maximum size of the receive buffer used by each TCP socket The default value of 873802 bytes is lowered to 87380 in low memory systems
tcp_smemSend buffer parameters [min default max] similar to tcp_rmem
- Chapter 3 Transport Layer
- Transport services and protocols
- Transport vs network layer
- Internet transport-layer protocols
- Multiplexingdemultiplexing
- How demultiplexing works
- Connectionless demultiplexing
- Connection-oriented demux
- Connection-oriented demux (cont)
- Connection-oriented demux Threaded Web Server
- UDP User Datagram Protocol [RFC 768]
- UDP more
- UDP checksum
- Principles of Reliable data transfer
- Reliable data transfer getting started
- Reliable data transfer getting started
- Rdt10 reliable transfer over a reliable channel
- Rdt20 channel with bit errors
- rdt20 FSM specification
- rdt20 operation with no errors
- rdt20 error scenario
- rdt20 has a fatal flaw
- rdt21 sender handles garbled ACKNAKs
- rdt21 receiver handles garbled ACKNAKs
- rdt21 discussion
- rdt22 a NAK-free protocol
- rdt22 sender receiver fragments
- rdt30 channels with errors and loss
- rdt30 sender
- rdt30 in action
- rdt30 in action
- Performance of rdt30
- rdt30 stop-and-wait operation
- Pipelined protocols
- Pipelining increased utilization
- Go-Back-N
- GBN sender extended FSM
- GBN receiver extended FSM
- GBN inaction
- Selective Repeat
- Selective repeat sender receiver windows
- Selective repeat
- Selective repeat in action
- Selective repeat dilemma
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- TCP Overview RFCs 793 1122 1323 2018 2581
- TCP segment structure
- TCP seq rsquos and ACKs
- TCP Round Trip Time and Timeout
- TCP Round Trip Time and Timeout
- Example RTT estimation
- TCP Round Trip Time and Timeout
- TCP reliable data transfer
- TCP sender events
- TCP sender(simplified)
- TCP retransmission scenarios
- TCP retransmission scenarios (more)
- TCP ACK generation [RFC 1122 RFC 2581]
- Fast Retransmit
- Fast Retransmit
- Fast retransmit algorithm
- TCP Flow Control
- TCP Flow control how it works
- Sliding Window Flow Control Example
- Principles of Congestion Control
- Causescosts of congestion scenario 1
- Causescosts of congestion scenario 2
- Causescosts of congestion scenario 2
- Causescosts of congestion scenario 3
- Causescosts of congestion scenario 3
- Approaches towards congestion control
- TCP Congestion Control
- TCP congestion control bandwidth probing
- TCP Congestion Control details
- TCP Congestion Control more details
- TCP Slow Start Phase
- Slow Start Example
- TCP Congestion Avoidance Phase
- Congestion Avoidance
- Example Slow StartCongestion Avoidance
- Slow Start Congestion Avoidance
- Responses to Congestion
- Fast Recovery (differentiation btwn two loss events)
- TCP Congestion Control
- Popular ldquoflavorsrdquo of TCP
- Summary TCP Congestion Control
- TCP Congestion Control Summary
- TCP throughput
- TCP Futures TCP over ldquolong fat pipesrdquo
- TCP Fairness
- Why is TCP fair
- Fairness (more)
- TCP Connection Management
- TCP Connection Management (cont)
- TCP Connection Management (cont)
- TCP Connection Management (cont)
- Tuning TCPIP Parameters
- SomeTCP Parameters in Linux Kernel
- SomeTCP Parameters in Linux Kernel
-
Transport Layer 3-41
Selective Repeat
receiver individually acknowledges all correctly received pkts
buffers pkts as needed for eventual in-order delivery to upper layer
sender only resends pkts for which ACK not received
sender timer for each unACKed pktsender window
N consecutive seq rsquosagain limits seq s of sent unACKed pkts
Transport Layer 3-42
Selective repeat sender receiver windows
Transport Layer 3-43
Selective repeat
data from above if next available seq in window send pkt
timeout(n)resend pkt n restart timer
ACK(n) in [sendbasesendbase+N-1]
mark pkt n as receivedif n smallest unACKed pkt advance window base to next unACKed seq
senderpkt n in [rcvbase rcvbase+N-1]
send ACK(n)out-of-order bufferin-order deliver (also deliver buffered in-order pkts) advance window to next not-yet-received pkt
pkt n in [rcvbase-Nrcvbase-1]
ACK(n)otherwise
ignore
receiver
Transport Layer 3-44
Selective repeat in action
Transport Layer 3-45
Selective repeatdilemma
Example seq rsquos 0 1 2 3window size=3
receiver sees no difference in two scenariosincorrectly passes duplicate data as new in (a)
Q what relationship between seq size and window size
Transport Layer 3-46
Sequence Number vs Window SizeSuppose we use k bits to represent SNQuestion Whatrsquos the minimum number of bits k necessary for a window size of N
sender
receiver
Go-Back-N
expectedSN
snd_base=expectedSN
Q For a given expectedSN whatrsquos the largest possible value for snd_baseA If all the last N ACKs sent by the receiver are received
snd_base = expectedSNexpectedSN+N-1
senderrsquos window
Transport Layer 3-47
Sequence Number vs Window SizeSuppose we use k bits to represent SNQuestion Whatrsquos the minimum number of bits k necessary for a window size of N
sender
receiver
Go-Back-N
expectedSN
snd_base=expectedSN-N
Q For a given expectedSN whatrsquos the smallest possible value for snd_baseA If all the last N ACKs sent by the receiver are not received
snd_base = expectedSN-NexpectedSN-1
senderrsquos window
Transport Layer 3-48
Sequence Number vs Window Size
sender
receiver
Go-Back-N
expectedSN
snd_base=expectedSN-N
All SNs in the interval [expectedSN-NexpectedSN+N-1] (an interval of size 2N) can be received by the receiver Since the receiver accepts on the packet with SN=expectedSN there should be no other packet within this interval with SN=expectedSN Therefore
2k ge N+1expectedSN+N-1
Transport Layer 3-49
Sequence Number vs Window SizeSuppose we use k bits to represent SNQuestion Whatrsquos the minimum number of bits k necessary for a window size of N
sender
receiver
Selective Repeat
rcv_base
snd_base=rcv_base
Q For a given rcv_base whatrsquos the largest possible value for snd_baseA If all the last N ACKs sent by the receiver are received
snd_base = rcv_base (same as go_back-N)rcv_base+N-1
senderrsquos window
receiverrsquos window
rcv_base+N-1
Transport Layer 3-50
Sequence Number vs Window SizeSuppose we use k bits to represent SNQuestion Whatrsquos the minimum number of bits k necessary for a window size of N
sender
receiver
Selective Repeat
rcv_base
snd_base=rcv_base-N
Q For a given rcv_base whatrsquos the smallest possible value for snd_baseA If all the last N ACKs sent by the receiver are not received
snd_base = rcv_base-N (same as Go-Back-N)rcv_base-1
senderrsquos window
rcv_base
receiverrsquos window
rcv_base+N-1
Transport Layer 3-51
Sequence Number vs Window Size
sender
receiver
Selective Repeat
snd_base=rcv_base-N
All SNs in the interval [rcv_base-Nrcv_base+N-1] (an interval of size 2N) can be received by the receiver Since the receiver should be able to distinguish between all packets in this interval and take corresponding action there should be no two packets within thisinterval having the same SN Therefore
2k ge 2Nrcv_base+N-1
rcv_basercv_base
receiverrsquos window
rcv_base+N-1
Transport Layer 3-52
TCP Overview RFCs 793 1122 1323 2018 2581
full duplex databi-directional data flow in same connectionMSS maximum segment size
connection-orientedhandshaking (exchange of control msgs) initrsquossender receiver state before data exchange
flow controlledsender will not overwhelm receiver
point-to-pointone sender one receiver
reliable in-order byte stream
no ldquomessage boundariesrdquopipelined
TCP congestion and flow control set window size
send amp receive buffers
socketdoor
TCPsend buffer
TCPreceive buffer
socketdoor
segment
applicationwrites data
applicationreads data
Transport Layer 3-53
TCP segment structure
source port dest port
32 bits
applicationdata
(variable length)
sequence numberacknowledgement number
Receive windowUrg data pnterchecksum
FSRPAUheadlen
notused
Options (variable length)
URG urgent data (generally not used)
ACK ACK valid
PSH push data now(generally not used)
RST SYN FINconnection estab(setup teardown
commands)
bytes rcvr willingto accept
Internetchecksum
(as in UDP)
countingby bytes of data(not segments)
Transport Layer 3-54
TCP seq rsquos and ACKsSeq rsquos
byte stream ldquonumberrdquo of first byte in segmentrsquos dataACKs
seq of next byte expected from other sidecumulative ACK
Q how receiver handles out-of-order segmentsA TCP spec doesnrsquot say - up to implementationWidely used implementations of TCP buffer out-of-order segments
Transport Layer 3-55
TCP Round Trip Time and Timeout
Q how to set TCP timeout valuelonger than RTT
but RTT variestoo short premature timeout
unnecessary retransmissions
too long slow reaction to segment loss
Q how to estimate RTTSampleRTT measured time from segment transmission until ACK receipt
ignore retransmissionsSampleRTT will vary want estimated RTT ldquosmootherrdquo
average several recent measurements not just current SampleRTT
Transport Layer 3-56
TCP Round Trip Time and Timeout
EstimatedRTT = (1- α)EstimatedRTT + αSampleRTT
Exponential weighted moving averageinfluence of past sample decreases exponentially fasttypical value α = 0125
Transport Layer 3-57
Example RTT estimationRTT gaiacsumassedu to fantasiaeurecomfr
100
150
200
250
300
350
1 8 15 22 29 36 43 50 57 64 71 78 85 92 99 106
time (seconnds)
RTT
(mill
iseco
nds)
SampleRTT Estimated RTT
Transport Layer 3-58
TCP Round Trip Time and TimeoutSetting the timeout
EstimatedRTT plus ldquosafety marginrdquolarge variation in EstimatedRTT -gt larger safety margin
first estimate of how much SampleRTT deviates from EstimatedRTT
TimeoutInterval = EstimatedRTT + 4DevRTT
DevRTT = (1-β)DevRTT +β|SampleRTT-EstimatedRTT|
(typically β = 025)
Then set timeout interval
Transport Layer 3-59
TCP reliable data transfer
TCP creates rdtservice on top of IPrsquos unreliable servicePipelined segmentsCumulative acksTCP uses single retransmission timer however it just retransmits the first segment in the window
Retransmissions are triggered by
timeout eventsduplicate acks
Initially consider simplified TCP sender
ignore duplicate acksignore flow control congestion control
Transport Layer 3-60
TCP sender eventsdata rcvd from app
Create segment with seq seq is byte-stream number of first data byte in segmentstart timer if not already running (think of timer as for oldest unacked segment)expiration interval TimeOutInterval
timeoutretransmit segment that caused timeout (first segment in the window)restart timer
Ack rcvdIf acknowledges previously unacked segments
update what is known to be ackedstart timer if there are outstanding segments
Transport Layer 3-61
TCP sender(simplified)
NextSeqNum = InitialSeqNumSendBase = InitialSeqNum
loop (forever) switch(event)
event data received from application above create TCP segment with sequence number NextSeqNumif (timer currently not running)
start timerpass segment to IP NextSeqNum = NextSeqNum + length(data)
event timer timeoutretransmit not-yet-acknowledged segment with
smallest sequence numberstart timer
event ACK received with ACK field value of y if (y gt SendBase)
SendBase = yif (there are currently not-yet-acknowledged segments)
start timer
end of loop forever
Commentbull SendBase-1 last cumulatively ackrsquoed byteExamplebull SendBase-1 = 71y= 73 so the rcvrwants 73+ y gt SendBase sothat new data is acked
Transport Layer 3-62
TCP retransmission scenariosHost A
Seq=100 20 bytes data
ACK=100
timepremature timeout
Host B
Seq=92 8 bytes data
ACK=120
Seq=92 8 bytes data
Seq=
92 t
imeo
ut
ACK=120
Host A
Seq=92 8 bytes data
ACK=100
loss
tim
eout
lost ACK scenario
Host B
X
Seq=92 8 bytes data
ACK=100
time
Seq=
92 t
imeo
utSendBase
= 100
SendBase= 120
SendBase= 120
Sendbase= 100
Transport Layer 3-63
TCP retransmission scenarios (more)Host A
Seq=92 8 bytes data
ACK=100
loss
tim
eout
Cumulative ACK scenario
Host B
X
Seq=100 20 bytes data
ACK=120
time
SendBase= 120
Transport Layer 3-64
TCP ACK generation [RFC 1122 RFC 2581]
Event at Receiver
Arrival of in-order segment withexpected seq All data up toexpected seq already ACKed
Arrival of in-order segment withexpected seq One other segment has ACK pending
Arrival of out-of-order segmenthigher-than-expect seq Gap detected
Arrival of segment that partially or completely fills gap
TCP Receiver action
Delayed ACK Wait up to 500msfor next segment If no next segmentsend ACK
Immediately send single cumulative ACK ACKing both in-order segments
Immediately send duplicate ACK indicating seq of next expected byte
Immediate send ACK provided thatsegment startsat lower end of gap
Transport Layer 3-65
Fast Retransmit
Time-out period often relatively long
long delay before resending lost packet
Detect lost segments via duplicate ACKs
Sender often sends many segments back-to-backIf segment is lost there will likely be many duplicate ACKs
If sender receives 3 ACKs for the same data it supposes that segment after ACKeddata was lost
fast retransmit resend segment before timer expires
Transport Layer 3-66
Fast RetransmitResend a segment after 3 duplicate ACKs since a duplicate ACK means that an out-of sequence segment was receivedduplicate ACKs due to packet reorderingif window is small donrsquot get duplicate ACKs
Host A
tim
eout
Host B
time
X
resend seq X2
seq x1seq x2seq x3seq x4seq x5
ACK x1
ACK x1ACK x1ACK x1
tripleduplicate
ACKs
Transport Layer 3-67
event ACK received with ACK field value of y if (y gt SendBase)
SendBase = yif (there are currently not-yet-acknowledged segments)
start timer
else increment count of dup ACKs received for yif (count of dup ACKs received for y = 3)
resend segment with sequence number y
Fast retransmit algorithm
a duplicate ACK for already ACKed segment
fast retransmit
Transport Layer 3-68
TCP Flow Control
receive side of TCP connection has a receive buffer
speed-matching service matching the send rate to the receiving apprsquos drain rate
app process may be slow at reading from buffer
sender wonrsquot overflowreceiverrsquos buffer by
transmitting too muchtoo fast
flow control
Transport Layer 3-69
TCP Flow control how it works
(Suppose TCP receiver discards out-of-order segments)spare room in buffer
= RcvWin
= RcvBuffer-[LastByteRcvd -LastByteRead]
Rcvr advertises spare room by including value of RcvWin in segmentsSender limits unACKeddata to RcvWin
guarantees receive buffer doesnrsquot overflow
Transport Layer 3-70
Sliding Window Flow Control Example
3K
2K SeqNo=0
ReceiverBuffer
0 4KSendersends 2Kof data
2K
AckNo=2048 RcvWin=2048Sendersends 2Kof data 2K SeqNo=2048
4K
AckNo=4096 RcvWin=0
AckNo=4096 RcvWin=1024
Sender blocked
Transport Layer 3-71
Principles of Congestion Control
Congestioninformally ldquotoo many sources sending too much data too fast for network to handlerdquodifferent from flow controlmanifestations
lost packets (buffer overflow at routers)long delays (queueing in router buffers)
a top-10 problem
Transport Layer 3-72
Causescosts of congestion scenario 1
two senders two receiversone router infinite buffers no retransmission
large delays when congestedmaximum achievable throughput
unlimited shared output link buffers
Host Aλin original data
Host B
λout
Transport Layer 3-73
Causescosts of congestion scenario 2
one router finite buffers sender retransmission of lost packet
finite shared output link buffers
Host A λin original data
Host B
λout
λin original data plus retransmitted data
Transport Layer 3-74
Causescosts of congestion scenario 2always (goodput)ldquoperfectrdquo retransmission only when loss
retransmission of delayed (not lost) packet makes larger(than perfect case) for same
λin
λout=
λin
λoutgtλ
inλout
ldquocostsrdquo of congestionmore work (retrans) for given ldquogoodputrdquounneeded retransmissions link carries multiple copies of pkt
R2
R2λin
λ out
b
R2
R2λin
λ out
a
R2
R2λin
λ out
c
R4
R3
Transport Layer 3-75
Causescosts of congestion scenario 3four sendersmultihop pathstimeoutretransmit
λin
Q what happens as and increase λ
in
finite shared output link buffers
Host Aλin original data
Host B
λout
λin original data plus retransmitted data
Transport Layer 3-76
Causescosts of congestion scenario 3
another ldquocostrdquo of congestionwhen packet dropped any ldquoupstream transmission capacity used for that packet was wasted
Host A
Host B
λou
t
Transport Layer 3-77
Approaches towards congestion control
End-end congestion controlno explicit feedback from networkcongestion inferred from end-system observed loss delayapproach taken by TCP
Network-assisted congestion controlrouters provide feedback to end systems
single bit indicating congestion (SNA DECbit TCPIP ECN ATM)explicit rate sender should send at
Two broad approaches towards congestion control
Transport Layer 3-78
TCP Congestion Control
end-end control (no network assistance)sender limits transmissionLastByteSent-LastByteAcked
le CongWin
CongWin is dynamic function of perceived network congestion
How does sender perceive congestionloss event = timeout or3 duplicate acksTCP sender reduces rate (CongWin) after loss event
two modes of operationSlow Start (SS)Congestion avoidance (CA) or Additive Increase Multiplicative Decrease (AIMD)
Transport Layer 3-79
TCP congestion control bandwidth probing
ldquoprobing for bandwidthrdquo increase transmission rate on receipt of ACK until eventually loss occurs then decrease transmission rate
continue to increase on ACK decrease on loss (since available bandwidth is changing depending on other connections in network)
ACKs being received so increase rate
X
X
XX
X loss so decrease rate
send
ing
rate
time
Q how fast to increasedecreasedetails to follow
TCPrsquosldquosawtoothrdquobehavior
Transport Layer 3-80
TCP Congestion Control details
sender limits rate by limiting number of unACKed bytes ldquoin pipelinerdquo
cwnd differs from rwnd (how why)sender limited by min(cwndrwnd)
roughly
cwnd is dynamic function of perceived network congestion
rate = cwndRTT bytessec
LastByteSent-LastByteAcked le cwnd
cwndbytes
RTT
ACK(s)
Transport Layer 3-81
TCP Congestion Control more details
segment loss event reducing cwndtimeout no response from receiver
cut cwnd to 13 duplicate ACKs at least some segments getting through (recall fast retransmit)
cut cwnd in half less aggressively than on timeout
ACK received increase cwndTwo modes of operation
slowstart phase bull increase exponentially
fast (despite name) at connection start or following timeout
congestion avoidance bull increase linearly
Transport Layer 3-82
TCP Slow Start Phasewhen connection begins cwnd = 1 MSS
example MSS = 500 bytes amp RTT = 200 msecinitial rate = 20 kbps
available bandwidth may be gtgt MSSRTT
desirable to quickly ramp up to respectable rate
increase rate exponentially until first loss event or when threshold reached
double cwnd every RTTdone by incrementing cwnd by 1 for every ACK received
Host A
one segment
RTT
Host B
time
two segments
four segments
Transport Layer 3-83
Slow Start ExampleThe congestion window size grows very rapidly
For every ACK we increase CongWin by 1 irrespective of the number of segments ACKrsquoeddouble CongWinevery RTTinitial rate is slow but ramps up exponentially fast
TCP slows down the increase of CongWinwhen CongWin gt ssthresh
segment 1
ACK for segment 1
cwnd = 1
cwnd = 2 segment 2segment 3
ACK for segments 2
cwnd = 4 segment 4segment 5segment 6
ACK for segments 4
cwnd = 7
ACK for segments 3
ACK for segments 5
ACK for segments 6
cwnd = 3
cwnd = 5
cwnd = 6ACK for segments 7
cwnd = 8
segment 7
Transport Layer 3-84
TCP Congestion Avoidance Phase
when cwnd gt ssthreshgrow cwnd linearly
increase cwnd by 1 MSS per RTT approach possible congestion slower than in slowstartimplementation cwnd= cwnd + MSScwndfor each ACK received
ACKs increase cwndby 1 MSS per RTT additive increaseloss cut cwnd in half (non-timeout-detected loss ) multiplicative decrease
AIMD
AIMD Additive IncreaseMultiplicative Decrease
Transport Layer 3-85
Congestion AvoidanceCongestion avoidance phase is started if CongWin has reached the slow-start threshold value
If CongWin gt= ssthresh then each time an ACK is received increment CongWin as follows
bull CongWin = CongWin + 1CongWin (CongWin in segments)
bull In actual TCP implementation CongWin is in BytesCongWin = CongWin + MSS (MSSCongWin)
So CongWin is increased by one only if all CongWinsegments have been acknowledged
Transport Layer 3-86
Example Slow StartCongestion AvoidanceAssume that
ssthresh = 8
cwnd = 1
cwnd = 2
cwnd = 4
cwnd = 8
cwnd = 9
cwnd = 10
02468
101214
t=0
t=2
t=4
t=6
Roundtrip times
Cw
nd(in
seg
men
ts)
ssthresh
cwnd = 3
cwnd = 5cwnd = 6cwnd = 7
Transport Layer 3-87
Slow Start Congestion AvoidanceA typical plot of CongWin for a TCP connection
(MSS = 1500 bytes) with TCP Tahoe
SS
CA
ssthresh
Transport Layer 3-88
Responses to CongestionTCP assumes there is congestion if it detects a packet lossA TCP sender can detect lost packets via loss events
bull Timeout of a retransmission timerbull Receipt of 3 duplicate ACKs (fast retransmit)
TCP interprets a Timeout as a binary congestion signal When a timeout occurs the sender performs
ssthresh is set to half the current size of the congestion window
ssthresh = CongWin 2CongWin is reset to one
CongWin = 1and slow-start is entered
Transport Layer 3-89
Fast Recovery (differentiation btwn two loss events) After 3 dup ACKs (fast Retransmit)
ssthresh = CongWin2CongWin = CongWin2window then grows linearly
But after timeout eventCongWin = 1 MSS window then grows exponentiallyto the threshold then grows linearly
bull 3 dup ACKs indicates network capable of delivering some segmentsbull timeout before 3 dup ACKs is ldquomore alarmingrdquo
Philosophy
3-90
TCP Congestion ControlInitially
CongWin = 1ssthresh = advertised window size
New Ack receivedif (CongWin lt ssthresh) Slow Start
CongWin = CongWin + 1else Congestion Avoidance
CongWin = CongWin + 1CongWinTimeout
ssthresh = CongWin2CongWin = 1
Fast Retransmissionssthresh = CongWin2CongWin = CongWin2
Slow Start (exponential increase phase) is continued until CongWin reaches half of the level where the loss event occurred last time CongWin is increased slowly after (linear increase in Congestion Avoidance phase)
Transport Layer 3-91
Popular ldquoflavorsrdquo of TCP
ssthresh
ssthresh
TCP Tahoe
TCP Reno
Transmission round
cwnd
win
dow
siz
e (in
seg
men
ts)
Transport Layer 3-92
Summary TCP Congestion ControlWhen CongWin is below Threshold sender in slow-start phase window grows exponentiallyWhen CongWin is above Threshold sender is in congestion-avoidance phase window grows linearlyWhen a triple duplicate ACK occurs Threshold set to CongWin2 and CongWin set to ThresholdWhen timeout occurs Threshold set to CongWin2 and CongWin is set to 1 MSS The actual sender window size is determined based on the congestion and flow control algorithms
SenderWin=min(RcvWinCongWin)
Transport Layer 3-93
TCP Congestion Control SummaryEvent State TCP Sender Action Commentary
ACK receipt for previously unackeddata
Slow Start (SS)
CongWin = CongWin + MSS If (CongWin gt Threshold)
set state to ldquoCongestion Avoidancerdquo
Resulting in a doubling of CongWin every RTT
ACK receipt for previously unackeddata
CongestionAvoidance (CA)
CongWin = CongWin+MSS (MSSCongWin)
Additive increase resulting in increase of CongWin by 1 MSS every RTT
Loss event detected by triple duplicate ACK
SS or CA Threshold = CongWin2 CongWin = ThresholdSet state to ldquoCongestion Avoidancerdquo
Fast recovery implementing multiplicative decrease CongWin will not drop below 1 MSS
Timeout SS or CA Threshold = CongWin2 CongWin = 1 MSSSet state to ldquoSlow Startrdquo
Enter slow start
Duplicate ACK
SS or CA Increment duplicate ACK count for segment being acked
CongWin and Threshold not changed
Transport Layer 3-94
TCP throughput
Q whatrsquos average throughout of TCP as function of window size RTT
ignoring slow startlet W be window size when loss occurs
when window is W throughput is WRTTjust after loss window drops to W2 throughput to W2RTT average throughout 75 WRTT
Transport Layer 3-95
TCP Futures TCP over ldquolong fat pipesrdquo
example 1500 byte segments 100ms RTT want 10 Gbps throughputrequires window size W = 83333 in-flight segmentsthroughput in terms of loss rate
L = 210-10 Wownew versions of TCP for high-speed
LRTTMSSsdot221
Transport Layer 3-96
Fairness goal if K TCP sessions share same bottleneck link of bandwidth R each should have average rate of RK
TCP connection 1
bottleneckrouter
capacity R
TCP connection 2
TCP Fairness
Transport Layer 3-97
Why is TCP fairTwo competing sessions
Additive increase gives slope of 1 as throughout increasesmultiplicative decrease decreases throughput proportionally
R
R
equal bandwidth share
Connection 1 throughput
Conn
ecti
on 2
thr
ough
p ut
congestion avoidance additive increaseloss decrease window by factor of 2
congestion avoidance additive increaseloss decrease window by factor of 2
Transport Layer 3-98
Fairness (more)Fairness and UDP
Multimedia apps often do not use TCP
do not want rate throttled by congestion control
Instead use UDPpump audiovideo at constant rate tolerate packet loss
Research area TCP friendly
Fairness and parallel TCP connectionsnothing prevents app from opening parallel cnctionsbetween 2 hostsWeb browsers do this Example link of rate R supporting 9 cnctions
new app asks for 1 TCP gets rate R10new app asks for 11 TCPs gets R2
Transport Layer 3-99
TCP Connection ManagementRecall TCP sender receiver
establish ldquoconnectionrdquobefore exchanging data segmentsinitialize TCP variables
seq sbuffers flow control info (eg RcvWindow)
client connection initiatorSocket clientSocket = new Socket(hostnameport
number)
server contacted by clientSocket connectionSocket = welcomeSocketaccept()
Three way handshakeStep 1 client host sends TCP
SYN segment to serverspecifies initial seq no data
Step 2 server host receives SYN replies with SYNACK segment
server allocates buffersspecifies server initial seq
Step 3 client receives SYNACK replies with ACK segment which may contain data
Transport Layer 3-100
TCP Connection Management (cont)
Closing a connection
client closes socketclientSocketclose()
Step 1 client end system sends TCP FIN control segment to server
Step 2 server receives FIN replies with ACK Closes connection sends FIN
client
FIN
server
ACK
ACK
FIN
close
close
closed
tim
ed w
ait
Transport Layer 3-101
TCP Connection Management (cont)
Step 3 client receives FIN replies with ACK
Enters ldquotimed waitrdquo -will respond with ACK to received FINs
Step 4 server receives ACK Connection closed
client
FIN
server
ACK
ACK
FIN
closing
closing
closed
tim
ed w
ait
closed
Transport Layer 3-102
TCP Connection Management (cont)
TCP clientlifecycle
TCP serverlifecycle
Transport Layer 3-103
Tuning TCPIP Parameters TCPIP parameters
A set of default values may not be optimal for all applicationsThe network administrator may wish to turn on or off some TCPIP functions for performance or security considerations
Many Unix and Linux systems provide some flexibility in tuning the TCPIP kernelsbinsysctl is used to configure the Linux kernel parameters at runtime
Default kernel configuration file is sbinsysctlconfFrequently used sysctl options
bull sysctl ndasha or sysctl ndashA list all current valuesbull sysctl ndashp file_name load the sysctl setting from a configuration
filebull sysctl ndashw variable=value change the value of the parameter
Transport Layer 3-104
SomeTCP Parameters in Linux Kerneltcp_syn_retries
Number of SYN packets the kernel will send before giving up on the new connection
tcp_synack_retriesnumber of SYN+ACK packets sent before the kernel gives up on the connection
tcp_window_scalingMaximum window size of 65535 bytes not enough for for really fast networks The window scaling options allows for almost gigabyte windows which is good for connections with large delay-bandwidth product
tcp_max_syn_backlogMaximal number of remembered connection requests which still did not receive an acknowledgment from connecting client
tcp_fin_timeoutHow many seconds to wait for a final FIN packet before the socket is closed required to prevent denial-of-service (DoS) attacks Default value is 60 seconds
Transport Layer 3-105
SomeTCP Parameters in Linux Kerneltcp_rmem
This is a vector of 3 integers [min default max] These parameters are used by TCP to dynamically adjust receive buffer sizesmin - minimum size of the receive buffer used by each TCP socket The default value is 4K default - the default size of the receive buffer for a TCP socket The default value is 87380 bytes and is lowered to 43689 in low memory systems If larger receive buffer sizes are desired this value should be increased max - the maximum size of the receive buffer used by each TCP socket The default value of 873802 bytes is lowered to 87380 in low memory systems
tcp_smemSend buffer parameters [min default max] similar to tcp_rmem
- Chapter 3 Transport Layer
- Transport services and protocols
- Transport vs network layer
- Internet transport-layer protocols
- Multiplexingdemultiplexing
- How demultiplexing works
- Connectionless demultiplexing
- Connection-oriented demux
- Connection-oriented demux (cont)
- Connection-oriented demux Threaded Web Server
- UDP User Datagram Protocol [RFC 768]
- UDP more
- UDP checksum
- Principles of Reliable data transfer
- Reliable data transfer getting started
- Reliable data transfer getting started
- Rdt10 reliable transfer over a reliable channel
- Rdt20 channel with bit errors
- rdt20 FSM specification
- rdt20 operation with no errors
- rdt20 error scenario
- rdt20 has a fatal flaw
- rdt21 sender handles garbled ACKNAKs
- rdt21 receiver handles garbled ACKNAKs
- rdt21 discussion
- rdt22 a NAK-free protocol
- rdt22 sender receiver fragments
- rdt30 channels with errors and loss
- rdt30 sender
- rdt30 in action
- rdt30 in action
- Performance of rdt30
- rdt30 stop-and-wait operation
- Pipelined protocols
- Pipelining increased utilization
- Go-Back-N
- GBN sender extended FSM
- GBN receiver extended FSM
- GBN inaction
- Selective Repeat
- Selective repeat sender receiver windows
- Selective repeat
- Selective repeat in action
- Selective repeat dilemma
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- TCP Overview RFCs 793 1122 1323 2018 2581
- TCP segment structure
- TCP seq rsquos and ACKs
- TCP Round Trip Time and Timeout
- TCP Round Trip Time and Timeout
- Example RTT estimation
- TCP Round Trip Time and Timeout
- TCP reliable data transfer
- TCP sender events
- TCP sender(simplified)
- TCP retransmission scenarios
- TCP retransmission scenarios (more)
- TCP ACK generation [RFC 1122 RFC 2581]
- Fast Retransmit
- Fast Retransmit
- Fast retransmit algorithm
- TCP Flow Control
- TCP Flow control how it works
- Sliding Window Flow Control Example
- Principles of Congestion Control
- Causescosts of congestion scenario 1
- Causescosts of congestion scenario 2
- Causescosts of congestion scenario 2
- Causescosts of congestion scenario 3
- Causescosts of congestion scenario 3
- Approaches towards congestion control
- TCP Congestion Control
- TCP congestion control bandwidth probing
- TCP Congestion Control details
- TCP Congestion Control more details
- TCP Slow Start Phase
- Slow Start Example
- TCP Congestion Avoidance Phase
- Congestion Avoidance
- Example Slow StartCongestion Avoidance
- Slow Start Congestion Avoidance
- Responses to Congestion
- Fast Recovery (differentiation btwn two loss events)
- TCP Congestion Control
- Popular ldquoflavorsrdquo of TCP
- Summary TCP Congestion Control
- TCP Congestion Control Summary
- TCP throughput
- TCP Futures TCP over ldquolong fat pipesrdquo
- TCP Fairness
- Why is TCP fair
- Fairness (more)
- TCP Connection Management
- TCP Connection Management (cont)
- TCP Connection Management (cont)
- TCP Connection Management (cont)
- Tuning TCPIP Parameters
- SomeTCP Parameters in Linux Kernel
- SomeTCP Parameters in Linux Kernel
-
Transport Layer 3-42
Selective repeat sender receiver windows
Transport Layer 3-43
Selective repeat
data from above if next available seq in window send pkt
timeout(n)resend pkt n restart timer
ACK(n) in [sendbasesendbase+N-1]
mark pkt n as receivedif n smallest unACKed pkt advance window base to next unACKed seq
senderpkt n in [rcvbase rcvbase+N-1]
send ACK(n)out-of-order bufferin-order deliver (also deliver buffered in-order pkts) advance window to next not-yet-received pkt
pkt n in [rcvbase-Nrcvbase-1]
ACK(n)otherwise
ignore
receiver
Transport Layer 3-44
Selective repeat in action
Transport Layer 3-45
Selective repeatdilemma
Example seq rsquos 0 1 2 3window size=3
receiver sees no difference in two scenariosincorrectly passes duplicate data as new in (a)
Q what relationship between seq size and window size
Transport Layer 3-46
Sequence Number vs Window SizeSuppose we use k bits to represent SNQuestion Whatrsquos the minimum number of bits k necessary for a window size of N
sender
receiver
Go-Back-N
expectedSN
snd_base=expectedSN
Q For a given expectedSN whatrsquos the largest possible value for snd_baseA If all the last N ACKs sent by the receiver are received
snd_base = expectedSNexpectedSN+N-1
senderrsquos window
Transport Layer 3-47
Sequence Number vs Window SizeSuppose we use k bits to represent SNQuestion Whatrsquos the minimum number of bits k necessary for a window size of N
sender
receiver
Go-Back-N
expectedSN
snd_base=expectedSN-N
Q For a given expectedSN whatrsquos the smallest possible value for snd_baseA If all the last N ACKs sent by the receiver are not received
snd_base = expectedSN-NexpectedSN-1
senderrsquos window
Transport Layer 3-48
Sequence Number vs Window Size
sender
receiver
Go-Back-N
expectedSN
snd_base=expectedSN-N
All SNs in the interval [expectedSN-NexpectedSN+N-1] (an interval of size 2N) can be received by the receiver Since the receiver accepts on the packet with SN=expectedSN there should be no other packet within this interval with SN=expectedSN Therefore
2k ge N+1expectedSN+N-1
Transport Layer 3-49
Sequence Number vs Window SizeSuppose we use k bits to represent SNQuestion Whatrsquos the minimum number of bits k necessary for a window size of N
sender
receiver
Selective Repeat
rcv_base
snd_base=rcv_base
Q For a given rcv_base whatrsquos the largest possible value for snd_baseA If all the last N ACKs sent by the receiver are received
snd_base = rcv_base (same as go_back-N)rcv_base+N-1
senderrsquos window
receiverrsquos window
rcv_base+N-1
Transport Layer 3-50
Sequence Number vs Window SizeSuppose we use k bits to represent SNQuestion Whatrsquos the minimum number of bits k necessary for a window size of N
sender
receiver
Selective Repeat
rcv_base
snd_base=rcv_base-N
Q For a given rcv_base whatrsquos the smallest possible value for snd_baseA If all the last N ACKs sent by the receiver are not received
snd_base = rcv_base-N (same as Go-Back-N)rcv_base-1
senderrsquos window
rcv_base
receiverrsquos window
rcv_base+N-1
Transport Layer 3-51
Sequence Number vs Window Size
sender
receiver
Selective Repeat
snd_base=rcv_base-N
All SNs in the interval [rcv_base-Nrcv_base+N-1] (an interval of size 2N) can be received by the receiver Since the receiver should be able to distinguish between all packets in this interval and take corresponding action there should be no two packets within thisinterval having the same SN Therefore
2k ge 2Nrcv_base+N-1
rcv_basercv_base
receiverrsquos window
rcv_base+N-1
Transport Layer 3-52
TCP Overview RFCs 793 1122 1323 2018 2581
full duplex databi-directional data flow in same connectionMSS maximum segment size
connection-orientedhandshaking (exchange of control msgs) initrsquossender receiver state before data exchange
flow controlledsender will not overwhelm receiver
point-to-pointone sender one receiver
reliable in-order byte stream
no ldquomessage boundariesrdquopipelined
TCP congestion and flow control set window size
send amp receive buffers
socketdoor
TCPsend buffer
TCPreceive buffer
socketdoor
segment
applicationwrites data
applicationreads data
Transport Layer 3-53
TCP segment structure
source port dest port
32 bits
applicationdata
(variable length)
sequence numberacknowledgement number
Receive windowUrg data pnterchecksum
FSRPAUheadlen
notused
Options (variable length)
URG urgent data (generally not used)
ACK ACK valid
PSH push data now(generally not used)
RST SYN FINconnection estab(setup teardown
commands)
bytes rcvr willingto accept
Internetchecksum
(as in UDP)
countingby bytes of data(not segments)
Transport Layer 3-54
TCP seq rsquos and ACKsSeq rsquos
byte stream ldquonumberrdquo of first byte in segmentrsquos dataACKs
seq of next byte expected from other sidecumulative ACK
Q how receiver handles out-of-order segmentsA TCP spec doesnrsquot say - up to implementationWidely used implementations of TCP buffer out-of-order segments
Transport Layer 3-55
TCP Round Trip Time and Timeout
Q how to set TCP timeout valuelonger than RTT
but RTT variestoo short premature timeout
unnecessary retransmissions
too long slow reaction to segment loss
Q how to estimate RTTSampleRTT measured time from segment transmission until ACK receipt
ignore retransmissionsSampleRTT will vary want estimated RTT ldquosmootherrdquo
average several recent measurements not just current SampleRTT
Transport Layer 3-56
TCP Round Trip Time and Timeout
EstimatedRTT = (1- α)EstimatedRTT + αSampleRTT
Exponential weighted moving averageinfluence of past sample decreases exponentially fasttypical value α = 0125
Transport Layer 3-57
Example RTT estimationRTT gaiacsumassedu to fantasiaeurecomfr
100
150
200
250
300
350
1 8 15 22 29 36 43 50 57 64 71 78 85 92 99 106
time (seconnds)
RTT
(mill
iseco
nds)
SampleRTT Estimated RTT
Transport Layer 3-58
TCP Round Trip Time and TimeoutSetting the timeout
EstimatedRTT plus ldquosafety marginrdquolarge variation in EstimatedRTT -gt larger safety margin
first estimate of how much SampleRTT deviates from EstimatedRTT
TimeoutInterval = EstimatedRTT + 4DevRTT
DevRTT = (1-β)DevRTT +β|SampleRTT-EstimatedRTT|
(typically β = 025)
Then set timeout interval
Transport Layer 3-59
TCP reliable data transfer
TCP creates rdtservice on top of IPrsquos unreliable servicePipelined segmentsCumulative acksTCP uses single retransmission timer however it just retransmits the first segment in the window
Retransmissions are triggered by
timeout eventsduplicate acks
Initially consider simplified TCP sender
ignore duplicate acksignore flow control congestion control
Transport Layer 3-60
TCP sender eventsdata rcvd from app
Create segment with seq seq is byte-stream number of first data byte in segmentstart timer if not already running (think of timer as for oldest unacked segment)expiration interval TimeOutInterval
timeoutretransmit segment that caused timeout (first segment in the window)restart timer
Ack rcvdIf acknowledges previously unacked segments
update what is known to be ackedstart timer if there are outstanding segments
Transport Layer 3-61
TCP sender(simplified)
NextSeqNum = InitialSeqNumSendBase = InitialSeqNum
loop (forever) switch(event)
event data received from application above create TCP segment with sequence number NextSeqNumif (timer currently not running)
start timerpass segment to IP NextSeqNum = NextSeqNum + length(data)
event timer timeoutretransmit not-yet-acknowledged segment with
smallest sequence numberstart timer
event ACK received with ACK field value of y if (y gt SendBase)
SendBase = yif (there are currently not-yet-acknowledged segments)
start timer
end of loop forever
Commentbull SendBase-1 last cumulatively ackrsquoed byteExamplebull SendBase-1 = 71y= 73 so the rcvrwants 73+ y gt SendBase sothat new data is acked
Transport Layer 3-62
TCP retransmission scenariosHost A
Seq=100 20 bytes data
ACK=100
timepremature timeout
Host B
Seq=92 8 bytes data
ACK=120
Seq=92 8 bytes data
Seq=
92 t
imeo
ut
ACK=120
Host A
Seq=92 8 bytes data
ACK=100
loss
tim
eout
lost ACK scenario
Host B
X
Seq=92 8 bytes data
ACK=100
time
Seq=
92 t
imeo
utSendBase
= 100
SendBase= 120
SendBase= 120
Sendbase= 100
Transport Layer 3-63
TCP retransmission scenarios (more)Host A
Seq=92 8 bytes data
ACK=100
loss
tim
eout
Cumulative ACK scenario
Host B
X
Seq=100 20 bytes data
ACK=120
time
SendBase= 120
Transport Layer 3-64
TCP ACK generation [RFC 1122 RFC 2581]
Event at Receiver
Arrival of in-order segment withexpected seq All data up toexpected seq already ACKed
Arrival of in-order segment withexpected seq One other segment has ACK pending
Arrival of out-of-order segmenthigher-than-expect seq Gap detected
Arrival of segment that partially or completely fills gap
TCP Receiver action
Delayed ACK Wait up to 500msfor next segment If no next segmentsend ACK
Immediately send single cumulative ACK ACKing both in-order segments
Immediately send duplicate ACK indicating seq of next expected byte
Immediate send ACK provided thatsegment startsat lower end of gap
Transport Layer 3-65
Fast Retransmit
Time-out period often relatively long
long delay before resending lost packet
Detect lost segments via duplicate ACKs
Sender often sends many segments back-to-backIf segment is lost there will likely be many duplicate ACKs
If sender receives 3 ACKs for the same data it supposes that segment after ACKeddata was lost
fast retransmit resend segment before timer expires
Transport Layer 3-66
Fast RetransmitResend a segment after 3 duplicate ACKs since a duplicate ACK means that an out-of sequence segment was receivedduplicate ACKs due to packet reorderingif window is small donrsquot get duplicate ACKs
Host A
tim
eout
Host B
time
X
resend seq X2
seq x1seq x2seq x3seq x4seq x5
ACK x1
ACK x1ACK x1ACK x1
tripleduplicate
ACKs
Transport Layer 3-67
event ACK received with ACK field value of y if (y gt SendBase)
SendBase = yif (there are currently not-yet-acknowledged segments)
start timer
else increment count of dup ACKs received for yif (count of dup ACKs received for y = 3)
resend segment with sequence number y
Fast retransmit algorithm
a duplicate ACK for already ACKed segment
fast retransmit
Transport Layer 3-68
TCP Flow Control
receive side of TCP connection has a receive buffer
speed-matching service matching the send rate to the receiving apprsquos drain rate
app process may be slow at reading from buffer
sender wonrsquot overflowreceiverrsquos buffer by
transmitting too muchtoo fast
flow control
Transport Layer 3-69
TCP Flow control how it works
(Suppose TCP receiver discards out-of-order segments)spare room in buffer
= RcvWin
= RcvBuffer-[LastByteRcvd -LastByteRead]
Rcvr advertises spare room by including value of RcvWin in segmentsSender limits unACKeddata to RcvWin
guarantees receive buffer doesnrsquot overflow
Transport Layer 3-70
Sliding Window Flow Control Example
3K
2K SeqNo=0
ReceiverBuffer
0 4KSendersends 2Kof data
2K
AckNo=2048 RcvWin=2048Sendersends 2Kof data 2K SeqNo=2048
4K
AckNo=4096 RcvWin=0
AckNo=4096 RcvWin=1024
Sender blocked
Transport Layer 3-71
Principles of Congestion Control
Congestioninformally ldquotoo many sources sending too much data too fast for network to handlerdquodifferent from flow controlmanifestations
lost packets (buffer overflow at routers)long delays (queueing in router buffers)
a top-10 problem
Transport Layer 3-72
Causescosts of congestion scenario 1
two senders two receiversone router infinite buffers no retransmission
large delays when congestedmaximum achievable throughput
unlimited shared output link buffers
Host Aλin original data
Host B
λout
Transport Layer 3-73
Causescosts of congestion scenario 2
one router finite buffers sender retransmission of lost packet
finite shared output link buffers
Host A λin original data
Host B
λout
λin original data plus retransmitted data
Transport Layer 3-74
Causescosts of congestion scenario 2always (goodput)ldquoperfectrdquo retransmission only when loss
retransmission of delayed (not lost) packet makes larger(than perfect case) for same
λin
λout=
λin
λoutgtλ
inλout
ldquocostsrdquo of congestionmore work (retrans) for given ldquogoodputrdquounneeded retransmissions link carries multiple copies of pkt
R2
R2λin
λ out
b
R2
R2λin
λ out
a
R2
R2λin
λ out
c
R4
R3
Transport Layer 3-75
Causescosts of congestion scenario 3four sendersmultihop pathstimeoutretransmit
λin
Q what happens as and increase λ
in
finite shared output link buffers
Host Aλin original data
Host B
λout
λin original data plus retransmitted data
Transport Layer 3-76
Causescosts of congestion scenario 3
another ldquocostrdquo of congestionwhen packet dropped any ldquoupstream transmission capacity used for that packet was wasted
Host A
Host B
λou
t
Transport Layer 3-77
Approaches towards congestion control
End-end congestion controlno explicit feedback from networkcongestion inferred from end-system observed loss delayapproach taken by TCP
Network-assisted congestion controlrouters provide feedback to end systems
single bit indicating congestion (SNA DECbit TCPIP ECN ATM)explicit rate sender should send at
Two broad approaches towards congestion control
Transport Layer 3-78
TCP Congestion Control
end-end control (no network assistance)sender limits transmissionLastByteSent-LastByteAcked
le CongWin
CongWin is dynamic function of perceived network congestion
How does sender perceive congestionloss event = timeout or3 duplicate acksTCP sender reduces rate (CongWin) after loss event
two modes of operationSlow Start (SS)Congestion avoidance (CA) or Additive Increase Multiplicative Decrease (AIMD)
Transport Layer 3-79
TCP congestion control bandwidth probing
ldquoprobing for bandwidthrdquo increase transmission rate on receipt of ACK until eventually loss occurs then decrease transmission rate
continue to increase on ACK decrease on loss (since available bandwidth is changing depending on other connections in network)
ACKs being received so increase rate
X
X
XX
X loss so decrease rate
send
ing
rate
time
Q how fast to increasedecreasedetails to follow
TCPrsquosldquosawtoothrdquobehavior
Transport Layer 3-80
TCP Congestion Control details
sender limits rate by limiting number of unACKed bytes ldquoin pipelinerdquo
cwnd differs from rwnd (how why)sender limited by min(cwndrwnd)
roughly
cwnd is dynamic function of perceived network congestion
rate = cwndRTT bytessec
LastByteSent-LastByteAcked le cwnd
cwndbytes
RTT
ACK(s)
Transport Layer 3-81
TCP Congestion Control more details
segment loss event reducing cwndtimeout no response from receiver
cut cwnd to 13 duplicate ACKs at least some segments getting through (recall fast retransmit)
cut cwnd in half less aggressively than on timeout
ACK received increase cwndTwo modes of operation
slowstart phase bull increase exponentially
fast (despite name) at connection start or following timeout
congestion avoidance bull increase linearly
Transport Layer 3-82
TCP Slow Start Phasewhen connection begins cwnd = 1 MSS
example MSS = 500 bytes amp RTT = 200 msecinitial rate = 20 kbps
available bandwidth may be gtgt MSSRTT
desirable to quickly ramp up to respectable rate
increase rate exponentially until first loss event or when threshold reached
double cwnd every RTTdone by incrementing cwnd by 1 for every ACK received
Host A
one segment
RTT
Host B
time
two segments
four segments
Transport Layer 3-83
Slow Start ExampleThe congestion window size grows very rapidly
For every ACK we increase CongWin by 1 irrespective of the number of segments ACKrsquoeddouble CongWinevery RTTinitial rate is slow but ramps up exponentially fast
TCP slows down the increase of CongWinwhen CongWin gt ssthresh
segment 1
ACK for segment 1
cwnd = 1
cwnd = 2 segment 2segment 3
ACK for segments 2
cwnd = 4 segment 4segment 5segment 6
ACK for segments 4
cwnd = 7
ACK for segments 3
ACK for segments 5
ACK for segments 6
cwnd = 3
cwnd = 5
cwnd = 6ACK for segments 7
cwnd = 8
segment 7
Transport Layer 3-84
TCP Congestion Avoidance Phase
when cwnd gt ssthreshgrow cwnd linearly
increase cwnd by 1 MSS per RTT approach possible congestion slower than in slowstartimplementation cwnd= cwnd + MSScwndfor each ACK received
ACKs increase cwndby 1 MSS per RTT additive increaseloss cut cwnd in half (non-timeout-detected loss ) multiplicative decrease
AIMD
AIMD Additive IncreaseMultiplicative Decrease
Transport Layer 3-85
Congestion AvoidanceCongestion avoidance phase is started if CongWin has reached the slow-start threshold value
If CongWin gt= ssthresh then each time an ACK is received increment CongWin as follows
bull CongWin = CongWin + 1CongWin (CongWin in segments)
bull In actual TCP implementation CongWin is in BytesCongWin = CongWin + MSS (MSSCongWin)
So CongWin is increased by one only if all CongWinsegments have been acknowledged
Transport Layer 3-86
Example Slow StartCongestion AvoidanceAssume that
ssthresh = 8
cwnd = 1
cwnd = 2
cwnd = 4
cwnd = 8
cwnd = 9
cwnd = 10
02468
101214
t=0
t=2
t=4
t=6
Roundtrip times
Cw
nd(in
seg
men
ts)
ssthresh
cwnd = 3
cwnd = 5cwnd = 6cwnd = 7
Transport Layer 3-87
Slow Start Congestion AvoidanceA typical plot of CongWin for a TCP connection
(MSS = 1500 bytes) with TCP Tahoe
SS
CA
ssthresh
Transport Layer 3-88
Responses to CongestionTCP assumes there is congestion if it detects a packet lossA TCP sender can detect lost packets via loss events
bull Timeout of a retransmission timerbull Receipt of 3 duplicate ACKs (fast retransmit)
TCP interprets a Timeout as a binary congestion signal When a timeout occurs the sender performs
ssthresh is set to half the current size of the congestion window
ssthresh = CongWin 2CongWin is reset to one
CongWin = 1and slow-start is entered
Transport Layer 3-89
Fast Recovery (differentiation btwn two loss events) After 3 dup ACKs (fast Retransmit)
ssthresh = CongWin2CongWin = CongWin2window then grows linearly
But after timeout eventCongWin = 1 MSS window then grows exponentiallyto the threshold then grows linearly
bull 3 dup ACKs indicates network capable of delivering some segmentsbull timeout before 3 dup ACKs is ldquomore alarmingrdquo
Philosophy
3-90
TCP Congestion ControlInitially
CongWin = 1ssthresh = advertised window size
New Ack receivedif (CongWin lt ssthresh) Slow Start
CongWin = CongWin + 1else Congestion Avoidance
CongWin = CongWin + 1CongWinTimeout
ssthresh = CongWin2CongWin = 1
Fast Retransmissionssthresh = CongWin2CongWin = CongWin2
Slow Start (exponential increase phase) is continued until CongWin reaches half of the level where the loss event occurred last time CongWin is increased slowly after (linear increase in Congestion Avoidance phase)
Transport Layer 3-91
Popular ldquoflavorsrdquo of TCP
ssthresh
ssthresh
TCP Tahoe
TCP Reno
Transmission round
cwnd
win
dow
siz
e (in
seg
men
ts)
Transport Layer 3-92
Summary TCP Congestion ControlWhen CongWin is below Threshold sender in slow-start phase window grows exponentiallyWhen CongWin is above Threshold sender is in congestion-avoidance phase window grows linearlyWhen a triple duplicate ACK occurs Threshold set to CongWin2 and CongWin set to ThresholdWhen timeout occurs Threshold set to CongWin2 and CongWin is set to 1 MSS The actual sender window size is determined based on the congestion and flow control algorithms
SenderWin=min(RcvWinCongWin)
Transport Layer 3-93
TCP Congestion Control SummaryEvent State TCP Sender Action Commentary
ACK receipt for previously unackeddata
Slow Start (SS)
CongWin = CongWin + MSS If (CongWin gt Threshold)
set state to ldquoCongestion Avoidancerdquo
Resulting in a doubling of CongWin every RTT
ACK receipt for previously unackeddata
CongestionAvoidance (CA)
CongWin = CongWin+MSS (MSSCongWin)
Additive increase resulting in increase of CongWin by 1 MSS every RTT
Loss event detected by triple duplicate ACK
SS or CA Threshold = CongWin2 CongWin = ThresholdSet state to ldquoCongestion Avoidancerdquo
Fast recovery implementing multiplicative decrease CongWin will not drop below 1 MSS
Timeout SS or CA Threshold = CongWin2 CongWin = 1 MSSSet state to ldquoSlow Startrdquo
Enter slow start
Duplicate ACK
SS or CA Increment duplicate ACK count for segment being acked
CongWin and Threshold not changed
Transport Layer 3-94
TCP throughput
Q whatrsquos average throughout of TCP as function of window size RTT
ignoring slow startlet W be window size when loss occurs
when window is W throughput is WRTTjust after loss window drops to W2 throughput to W2RTT average throughout 75 WRTT
Transport Layer 3-95
TCP Futures TCP over ldquolong fat pipesrdquo
example 1500 byte segments 100ms RTT want 10 Gbps throughputrequires window size W = 83333 in-flight segmentsthroughput in terms of loss rate
L = 210-10 Wownew versions of TCP for high-speed
LRTTMSSsdot221
Transport Layer 3-96
Fairness goal if K TCP sessions share same bottleneck link of bandwidth R each should have average rate of RK
TCP connection 1
bottleneckrouter
capacity R
TCP connection 2
TCP Fairness
Transport Layer 3-97
Why is TCP fairTwo competing sessions
Additive increase gives slope of 1 as throughout increasesmultiplicative decrease decreases throughput proportionally
R
R
equal bandwidth share
Connection 1 throughput
Conn
ecti
on 2
thr
ough
p ut
congestion avoidance additive increaseloss decrease window by factor of 2
congestion avoidance additive increaseloss decrease window by factor of 2
Transport Layer 3-98
Fairness (more)Fairness and UDP
Multimedia apps often do not use TCP
do not want rate throttled by congestion control
Instead use UDPpump audiovideo at constant rate tolerate packet loss
Research area TCP friendly
Fairness and parallel TCP connectionsnothing prevents app from opening parallel cnctionsbetween 2 hostsWeb browsers do this Example link of rate R supporting 9 cnctions
new app asks for 1 TCP gets rate R10new app asks for 11 TCPs gets R2
Transport Layer 3-99
TCP Connection ManagementRecall TCP sender receiver
establish ldquoconnectionrdquobefore exchanging data segmentsinitialize TCP variables
seq sbuffers flow control info (eg RcvWindow)
client connection initiatorSocket clientSocket = new Socket(hostnameport
number)
server contacted by clientSocket connectionSocket = welcomeSocketaccept()
Three way handshakeStep 1 client host sends TCP
SYN segment to serverspecifies initial seq no data
Step 2 server host receives SYN replies with SYNACK segment
server allocates buffersspecifies server initial seq
Step 3 client receives SYNACK replies with ACK segment which may contain data
Transport Layer 3-100
TCP Connection Management (cont)
Closing a connection
client closes socketclientSocketclose()
Step 1 client end system sends TCP FIN control segment to server
Step 2 server receives FIN replies with ACK Closes connection sends FIN
client
FIN
server
ACK
ACK
FIN
close
close
closed
tim
ed w
ait
Transport Layer 3-101
TCP Connection Management (cont)
Step 3 client receives FIN replies with ACK
Enters ldquotimed waitrdquo -will respond with ACK to received FINs
Step 4 server receives ACK Connection closed
client
FIN
server
ACK
ACK
FIN
closing
closing
closed
tim
ed w
ait
closed
Transport Layer 3-102
TCP Connection Management (cont)
TCP clientlifecycle
TCP serverlifecycle
Transport Layer 3-103
Tuning TCPIP Parameters TCPIP parameters
A set of default values may not be optimal for all applicationsThe network administrator may wish to turn on or off some TCPIP functions for performance or security considerations
Many Unix and Linux systems provide some flexibility in tuning the TCPIP kernelsbinsysctl is used to configure the Linux kernel parameters at runtime
Default kernel configuration file is sbinsysctlconfFrequently used sysctl options
bull sysctl ndasha or sysctl ndashA list all current valuesbull sysctl ndashp file_name load the sysctl setting from a configuration
filebull sysctl ndashw variable=value change the value of the parameter
Transport Layer 3-104
SomeTCP Parameters in Linux Kerneltcp_syn_retries
Number of SYN packets the kernel will send before giving up on the new connection
tcp_synack_retriesnumber of SYN+ACK packets sent before the kernel gives up on the connection
tcp_window_scalingMaximum window size of 65535 bytes not enough for for really fast networks The window scaling options allows for almost gigabyte windows which is good for connections with large delay-bandwidth product
tcp_max_syn_backlogMaximal number of remembered connection requests which still did not receive an acknowledgment from connecting client
tcp_fin_timeoutHow many seconds to wait for a final FIN packet before the socket is closed required to prevent denial-of-service (DoS) attacks Default value is 60 seconds
Transport Layer 3-105
SomeTCP Parameters in Linux Kerneltcp_rmem
This is a vector of 3 integers [min default max] These parameters are used by TCP to dynamically adjust receive buffer sizesmin - minimum size of the receive buffer used by each TCP socket The default value is 4K default - the default size of the receive buffer for a TCP socket The default value is 87380 bytes and is lowered to 43689 in low memory systems If larger receive buffer sizes are desired this value should be increased max - the maximum size of the receive buffer used by each TCP socket The default value of 873802 bytes is lowered to 87380 in low memory systems
tcp_smemSend buffer parameters [min default max] similar to tcp_rmem
- Chapter 3 Transport Layer
- Transport services and protocols
- Transport vs network layer
- Internet transport-layer protocols
- Multiplexingdemultiplexing
- How demultiplexing works
- Connectionless demultiplexing
- Connection-oriented demux
- Connection-oriented demux (cont)
- Connection-oriented demux Threaded Web Server
- UDP User Datagram Protocol [RFC 768]
- UDP more
- UDP checksum
- Principles of Reliable data transfer
- Reliable data transfer getting started
- Reliable data transfer getting started
- Rdt10 reliable transfer over a reliable channel
- Rdt20 channel with bit errors
- rdt20 FSM specification
- rdt20 operation with no errors
- rdt20 error scenario
- rdt20 has a fatal flaw
- rdt21 sender handles garbled ACKNAKs
- rdt21 receiver handles garbled ACKNAKs
- rdt21 discussion
- rdt22 a NAK-free protocol
- rdt22 sender receiver fragments
- rdt30 channels with errors and loss
- rdt30 sender
- rdt30 in action
- rdt30 in action
- Performance of rdt30
- rdt30 stop-and-wait operation
- Pipelined protocols
- Pipelining increased utilization
- Go-Back-N
- GBN sender extended FSM
- GBN receiver extended FSM
- GBN inaction
- Selective Repeat
- Selective repeat sender receiver windows
- Selective repeat
- Selective repeat in action
- Selective repeat dilemma
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- TCP Overview RFCs 793 1122 1323 2018 2581
- TCP segment structure
- TCP seq rsquos and ACKs
- TCP Round Trip Time and Timeout
- TCP Round Trip Time and Timeout
- Example RTT estimation
- TCP Round Trip Time and Timeout
- TCP reliable data transfer
- TCP sender events
- TCP sender(simplified)
- TCP retransmission scenarios
- TCP retransmission scenarios (more)
- TCP ACK generation [RFC 1122 RFC 2581]
- Fast Retransmit
- Fast Retransmit
- Fast retransmit algorithm
- TCP Flow Control
- TCP Flow control how it works
- Sliding Window Flow Control Example
- Principles of Congestion Control
- Causescosts of congestion scenario 1
- Causescosts of congestion scenario 2
- Causescosts of congestion scenario 2
- Causescosts of congestion scenario 3
- Causescosts of congestion scenario 3
- Approaches towards congestion control
- TCP Congestion Control
- TCP congestion control bandwidth probing
- TCP Congestion Control details
- TCP Congestion Control more details
- TCP Slow Start Phase
- Slow Start Example
- TCP Congestion Avoidance Phase
- Congestion Avoidance
- Example Slow StartCongestion Avoidance
- Slow Start Congestion Avoidance
- Responses to Congestion
- Fast Recovery (differentiation btwn two loss events)
- TCP Congestion Control
- Popular ldquoflavorsrdquo of TCP
- Summary TCP Congestion Control
- TCP Congestion Control Summary
- TCP throughput
- TCP Futures TCP over ldquolong fat pipesrdquo
- TCP Fairness
- Why is TCP fair
- Fairness (more)
- TCP Connection Management
- TCP Connection Management (cont)
- TCP Connection Management (cont)
- TCP Connection Management (cont)
- Tuning TCPIP Parameters
- SomeTCP Parameters in Linux Kernel
- SomeTCP Parameters in Linux Kernel
-
Transport Layer 3-43
Selective repeat
data from above if next available seq in window send pkt
timeout(n)resend pkt n restart timer
ACK(n) in [sendbasesendbase+N-1]
mark pkt n as receivedif n smallest unACKed pkt advance window base to next unACKed seq
senderpkt n in [rcvbase rcvbase+N-1]
send ACK(n)out-of-order bufferin-order deliver (also deliver buffered in-order pkts) advance window to next not-yet-received pkt
pkt n in [rcvbase-Nrcvbase-1]
ACK(n)otherwise
ignore
receiver
Transport Layer 3-44
Selective repeat in action
Transport Layer 3-45
Selective repeatdilemma
Example seq rsquos 0 1 2 3window size=3
receiver sees no difference in two scenariosincorrectly passes duplicate data as new in (a)
Q what relationship between seq size and window size
Transport Layer 3-46
Sequence Number vs Window SizeSuppose we use k bits to represent SNQuestion Whatrsquos the minimum number of bits k necessary for a window size of N
sender
receiver
Go-Back-N
expectedSN
snd_base=expectedSN
Q For a given expectedSN whatrsquos the largest possible value for snd_baseA If all the last N ACKs sent by the receiver are received
snd_base = expectedSNexpectedSN+N-1
senderrsquos window
Transport Layer 3-47
Sequence Number vs Window SizeSuppose we use k bits to represent SNQuestion Whatrsquos the minimum number of bits k necessary for a window size of N
sender
receiver
Go-Back-N
expectedSN
snd_base=expectedSN-N
Q For a given expectedSN whatrsquos the smallest possible value for snd_baseA If all the last N ACKs sent by the receiver are not received
snd_base = expectedSN-NexpectedSN-1
senderrsquos window
Transport Layer 3-48
Sequence Number vs Window Size
sender
receiver
Go-Back-N
expectedSN
snd_base=expectedSN-N
All SNs in the interval [expectedSN-NexpectedSN+N-1] (an interval of size 2N) can be received by the receiver Since the receiver accepts on the packet with SN=expectedSN there should be no other packet within this interval with SN=expectedSN Therefore
2k ge N+1expectedSN+N-1
Transport Layer 3-49
Sequence Number vs Window SizeSuppose we use k bits to represent SNQuestion Whatrsquos the minimum number of bits k necessary for a window size of N
sender
receiver
Selective Repeat
rcv_base
snd_base=rcv_base
Q For a given rcv_base whatrsquos the largest possible value for snd_baseA If all the last N ACKs sent by the receiver are received
snd_base = rcv_base (same as go_back-N)rcv_base+N-1
senderrsquos window
receiverrsquos window
rcv_base+N-1
Transport Layer 3-50
Sequence Number vs Window SizeSuppose we use k bits to represent SNQuestion Whatrsquos the minimum number of bits k necessary for a window size of N
sender
receiver
Selective Repeat
rcv_base
snd_base=rcv_base-N
Q For a given rcv_base whatrsquos the smallest possible value for snd_baseA If all the last N ACKs sent by the receiver are not received
snd_base = rcv_base-N (same as Go-Back-N)rcv_base-1
senderrsquos window
rcv_base
receiverrsquos window
rcv_base+N-1
Transport Layer 3-51
Sequence Number vs Window Size
sender
receiver
Selective Repeat
snd_base=rcv_base-N
All SNs in the interval [rcv_base-Nrcv_base+N-1] (an interval of size 2N) can be received by the receiver Since the receiver should be able to distinguish between all packets in this interval and take corresponding action there should be no two packets within thisinterval having the same SN Therefore
2k ge 2Nrcv_base+N-1
rcv_basercv_base
receiverrsquos window
rcv_base+N-1
Transport Layer 3-52
TCP Overview RFCs 793 1122 1323 2018 2581
full duplex databi-directional data flow in same connectionMSS maximum segment size
connection-orientedhandshaking (exchange of control msgs) initrsquossender receiver state before data exchange
flow controlledsender will not overwhelm receiver
point-to-pointone sender one receiver
reliable in-order byte stream
no ldquomessage boundariesrdquopipelined
TCP congestion and flow control set window size
send amp receive buffers
socketdoor
TCPsend buffer
TCPreceive buffer
socketdoor
segment
applicationwrites data
applicationreads data
Transport Layer 3-53
TCP segment structure
source port dest port
32 bits
applicationdata
(variable length)
sequence numberacknowledgement number
Receive windowUrg data pnterchecksum
FSRPAUheadlen
notused
Options (variable length)
URG urgent data (generally not used)
ACK ACK valid
PSH push data now(generally not used)
RST SYN FINconnection estab(setup teardown
commands)
bytes rcvr willingto accept
Internetchecksum
(as in UDP)
countingby bytes of data(not segments)
Transport Layer 3-54
TCP seq rsquos and ACKsSeq rsquos
byte stream ldquonumberrdquo of first byte in segmentrsquos dataACKs
seq of next byte expected from other sidecumulative ACK
Q how receiver handles out-of-order segmentsA TCP spec doesnrsquot say - up to implementationWidely used implementations of TCP buffer out-of-order segments
Transport Layer 3-55
TCP Round Trip Time and Timeout
Q how to set TCP timeout valuelonger than RTT
but RTT variestoo short premature timeout
unnecessary retransmissions
too long slow reaction to segment loss
Q how to estimate RTTSampleRTT measured time from segment transmission until ACK receipt
ignore retransmissionsSampleRTT will vary want estimated RTT ldquosmootherrdquo
average several recent measurements not just current SampleRTT
Transport Layer 3-56
TCP Round Trip Time and Timeout
EstimatedRTT = (1- α)EstimatedRTT + αSampleRTT
Exponential weighted moving averageinfluence of past sample decreases exponentially fasttypical value α = 0125
Transport Layer 3-57
Example RTT estimationRTT gaiacsumassedu to fantasiaeurecomfr
100
150
200
250
300
350
1 8 15 22 29 36 43 50 57 64 71 78 85 92 99 106
time (seconnds)
RTT
(mill
iseco
nds)
SampleRTT Estimated RTT
Transport Layer 3-58
TCP Round Trip Time and TimeoutSetting the timeout
EstimatedRTT plus ldquosafety marginrdquolarge variation in EstimatedRTT -gt larger safety margin
first estimate of how much SampleRTT deviates from EstimatedRTT
TimeoutInterval = EstimatedRTT + 4DevRTT
DevRTT = (1-β)DevRTT +β|SampleRTT-EstimatedRTT|
(typically β = 025)
Then set timeout interval
Transport Layer 3-59
TCP reliable data transfer
TCP creates rdtservice on top of IPrsquos unreliable servicePipelined segmentsCumulative acksTCP uses single retransmission timer however it just retransmits the first segment in the window
Retransmissions are triggered by
timeout eventsduplicate acks
Initially consider simplified TCP sender
ignore duplicate acksignore flow control congestion control
Transport Layer 3-60
TCP sender eventsdata rcvd from app
Create segment with seq seq is byte-stream number of first data byte in segmentstart timer if not already running (think of timer as for oldest unacked segment)expiration interval TimeOutInterval
timeoutretransmit segment that caused timeout (first segment in the window)restart timer
Ack rcvdIf acknowledges previously unacked segments
update what is known to be ackedstart timer if there are outstanding segments
Transport Layer 3-61
TCP sender(simplified)
NextSeqNum = InitialSeqNumSendBase = InitialSeqNum
loop (forever) switch(event)
event data received from application above create TCP segment with sequence number NextSeqNumif (timer currently not running)
start timerpass segment to IP NextSeqNum = NextSeqNum + length(data)
event timer timeoutretransmit not-yet-acknowledged segment with
smallest sequence numberstart timer
event ACK received with ACK field value of y if (y gt SendBase)
SendBase = yif (there are currently not-yet-acknowledged segments)
start timer
end of loop forever
Commentbull SendBase-1 last cumulatively ackrsquoed byteExamplebull SendBase-1 = 71y= 73 so the rcvrwants 73+ y gt SendBase sothat new data is acked
Transport Layer 3-62
TCP retransmission scenariosHost A
Seq=100 20 bytes data
ACK=100
timepremature timeout
Host B
Seq=92 8 bytes data
ACK=120
Seq=92 8 bytes data
Seq=
92 t
imeo
ut
ACK=120
Host A
Seq=92 8 bytes data
ACK=100
loss
tim
eout
lost ACK scenario
Host B
X
Seq=92 8 bytes data
ACK=100
time
Seq=
92 t
imeo
utSendBase
= 100
SendBase= 120
SendBase= 120
Sendbase= 100
Transport Layer 3-63
TCP retransmission scenarios (more)Host A
Seq=92 8 bytes data
ACK=100
loss
tim
eout
Cumulative ACK scenario
Host B
X
Seq=100 20 bytes data
ACK=120
time
SendBase= 120
Transport Layer 3-64
TCP ACK generation [RFC 1122 RFC 2581]
Event at Receiver
Arrival of in-order segment withexpected seq All data up toexpected seq already ACKed
Arrival of in-order segment withexpected seq One other segment has ACK pending
Arrival of out-of-order segmenthigher-than-expect seq Gap detected
Arrival of segment that partially or completely fills gap
TCP Receiver action
Delayed ACK Wait up to 500msfor next segment If no next segmentsend ACK
Immediately send single cumulative ACK ACKing both in-order segments
Immediately send duplicate ACK indicating seq of next expected byte
Immediate send ACK provided thatsegment startsat lower end of gap
Transport Layer 3-65
Fast Retransmit
Time-out period often relatively long
long delay before resending lost packet
Detect lost segments via duplicate ACKs
Sender often sends many segments back-to-backIf segment is lost there will likely be many duplicate ACKs
If sender receives 3 ACKs for the same data it supposes that segment after ACKeddata was lost
fast retransmit resend segment before timer expires
Transport Layer 3-66
Fast RetransmitResend a segment after 3 duplicate ACKs since a duplicate ACK means that an out-of sequence segment was receivedduplicate ACKs due to packet reorderingif window is small donrsquot get duplicate ACKs
Host A
tim
eout
Host B
time
X
resend seq X2
seq x1seq x2seq x3seq x4seq x5
ACK x1
ACK x1ACK x1ACK x1
tripleduplicate
ACKs
Transport Layer 3-67
event ACK received with ACK field value of y if (y gt SendBase)
SendBase = yif (there are currently not-yet-acknowledged segments)
start timer
else increment count of dup ACKs received for yif (count of dup ACKs received for y = 3)
resend segment with sequence number y
Fast retransmit algorithm
a duplicate ACK for already ACKed segment
fast retransmit
Transport Layer 3-68
TCP Flow Control
receive side of TCP connection has a receive buffer
speed-matching service matching the send rate to the receiving apprsquos drain rate
app process may be slow at reading from buffer
sender wonrsquot overflowreceiverrsquos buffer by
transmitting too muchtoo fast
flow control
Transport Layer 3-69
TCP Flow control how it works
(Suppose TCP receiver discards out-of-order segments)spare room in buffer
= RcvWin
= RcvBuffer-[LastByteRcvd -LastByteRead]
Rcvr advertises spare room by including value of RcvWin in segmentsSender limits unACKeddata to RcvWin
guarantees receive buffer doesnrsquot overflow
Transport Layer 3-70
Sliding Window Flow Control Example
3K
2K SeqNo=0
ReceiverBuffer
0 4KSendersends 2Kof data
2K
AckNo=2048 RcvWin=2048Sendersends 2Kof data 2K SeqNo=2048
4K
AckNo=4096 RcvWin=0
AckNo=4096 RcvWin=1024
Sender blocked
Transport Layer 3-71
Principles of Congestion Control
Congestioninformally ldquotoo many sources sending too much data too fast for network to handlerdquodifferent from flow controlmanifestations
lost packets (buffer overflow at routers)long delays (queueing in router buffers)
a top-10 problem
Transport Layer 3-72
Causescosts of congestion scenario 1
two senders two receiversone router infinite buffers no retransmission
large delays when congestedmaximum achievable throughput
unlimited shared output link buffers
Host Aλin original data
Host B
λout
Transport Layer 3-73
Causescosts of congestion scenario 2
one router finite buffers sender retransmission of lost packet
finite shared output link buffers
Host A λin original data
Host B
λout
λin original data plus retransmitted data
Transport Layer 3-74
Causescosts of congestion scenario 2always (goodput)ldquoperfectrdquo retransmission only when loss
retransmission of delayed (not lost) packet makes larger(than perfect case) for same
λin
λout=
λin
λoutgtλ
inλout
ldquocostsrdquo of congestionmore work (retrans) for given ldquogoodputrdquounneeded retransmissions link carries multiple copies of pkt
R2
R2λin
λ out
b
R2
R2λin
λ out
a
R2
R2λin
λ out
c
R4
R3
Transport Layer 3-75
Causescosts of congestion scenario 3four sendersmultihop pathstimeoutretransmit
λin
Q what happens as and increase λ
in
finite shared output link buffers
Host Aλin original data
Host B
λout
λin original data plus retransmitted data
Transport Layer 3-76
Causescosts of congestion scenario 3
another ldquocostrdquo of congestionwhen packet dropped any ldquoupstream transmission capacity used for that packet was wasted
Host A
Host B
λou
t
Transport Layer 3-77
Approaches towards congestion control
End-end congestion controlno explicit feedback from networkcongestion inferred from end-system observed loss delayapproach taken by TCP
Network-assisted congestion controlrouters provide feedback to end systems
single bit indicating congestion (SNA DECbit TCPIP ECN ATM)explicit rate sender should send at
Two broad approaches towards congestion control
Transport Layer 3-78
TCP Congestion Control
end-end control (no network assistance)sender limits transmissionLastByteSent-LastByteAcked
le CongWin
CongWin is dynamic function of perceived network congestion
How does sender perceive congestionloss event = timeout or3 duplicate acksTCP sender reduces rate (CongWin) after loss event
two modes of operationSlow Start (SS)Congestion avoidance (CA) or Additive Increase Multiplicative Decrease (AIMD)
Transport Layer 3-79
TCP congestion control bandwidth probing
ldquoprobing for bandwidthrdquo increase transmission rate on receipt of ACK until eventually loss occurs then decrease transmission rate
continue to increase on ACK decrease on loss (since available bandwidth is changing depending on other connections in network)
ACKs being received so increase rate
X
X
XX
X loss so decrease rate
send
ing
rate
time
Q how fast to increasedecreasedetails to follow
TCPrsquosldquosawtoothrdquobehavior
Transport Layer 3-80
TCP Congestion Control details
sender limits rate by limiting number of unACKed bytes ldquoin pipelinerdquo
cwnd differs from rwnd (how why)sender limited by min(cwndrwnd)
roughly
cwnd is dynamic function of perceived network congestion
rate = cwndRTT bytessec
LastByteSent-LastByteAcked le cwnd
cwndbytes
RTT
ACK(s)
Transport Layer 3-81
TCP Congestion Control more details
segment loss event reducing cwndtimeout no response from receiver
cut cwnd to 13 duplicate ACKs at least some segments getting through (recall fast retransmit)
cut cwnd in half less aggressively than on timeout
ACK received increase cwndTwo modes of operation
slowstart phase bull increase exponentially
fast (despite name) at connection start or following timeout
congestion avoidance bull increase linearly
Transport Layer 3-82
TCP Slow Start Phasewhen connection begins cwnd = 1 MSS
example MSS = 500 bytes amp RTT = 200 msecinitial rate = 20 kbps
available bandwidth may be gtgt MSSRTT
desirable to quickly ramp up to respectable rate
increase rate exponentially until first loss event or when threshold reached
double cwnd every RTTdone by incrementing cwnd by 1 for every ACK received
Host A
one segment
RTT
Host B
time
two segments
four segments
Transport Layer 3-83
Slow Start ExampleThe congestion window size grows very rapidly
For every ACK we increase CongWin by 1 irrespective of the number of segments ACKrsquoeddouble CongWinevery RTTinitial rate is slow but ramps up exponentially fast
TCP slows down the increase of CongWinwhen CongWin gt ssthresh
segment 1
ACK for segment 1
cwnd = 1
cwnd = 2 segment 2segment 3
ACK for segments 2
cwnd = 4 segment 4segment 5segment 6
ACK for segments 4
cwnd = 7
ACK for segments 3
ACK for segments 5
ACK for segments 6
cwnd = 3
cwnd = 5
cwnd = 6ACK for segments 7
cwnd = 8
segment 7
Transport Layer 3-84
TCP Congestion Avoidance Phase
when cwnd gt ssthreshgrow cwnd linearly
increase cwnd by 1 MSS per RTT approach possible congestion slower than in slowstartimplementation cwnd= cwnd + MSScwndfor each ACK received
ACKs increase cwndby 1 MSS per RTT additive increaseloss cut cwnd in half (non-timeout-detected loss ) multiplicative decrease
AIMD
AIMD Additive IncreaseMultiplicative Decrease
Transport Layer 3-85
Congestion AvoidanceCongestion avoidance phase is started if CongWin has reached the slow-start threshold value
If CongWin gt= ssthresh then each time an ACK is received increment CongWin as follows
bull CongWin = CongWin + 1CongWin (CongWin in segments)
bull In actual TCP implementation CongWin is in BytesCongWin = CongWin + MSS (MSSCongWin)
So CongWin is increased by one only if all CongWinsegments have been acknowledged
Transport Layer 3-86
Example Slow StartCongestion AvoidanceAssume that
ssthresh = 8
cwnd = 1
cwnd = 2
cwnd = 4
cwnd = 8
cwnd = 9
cwnd = 10
02468
101214
t=0
t=2
t=4
t=6
Roundtrip times
Cw
nd(in
seg
men
ts)
ssthresh
cwnd = 3
cwnd = 5cwnd = 6cwnd = 7
Transport Layer 3-87
Slow Start Congestion AvoidanceA typical plot of CongWin for a TCP connection
(MSS = 1500 bytes) with TCP Tahoe
SS
CA
ssthresh
Transport Layer 3-88
Responses to CongestionTCP assumes there is congestion if it detects a packet lossA TCP sender can detect lost packets via loss events
bull Timeout of a retransmission timerbull Receipt of 3 duplicate ACKs (fast retransmit)
TCP interprets a Timeout as a binary congestion signal When a timeout occurs the sender performs
ssthresh is set to half the current size of the congestion window
ssthresh = CongWin 2CongWin is reset to one
CongWin = 1and slow-start is entered
Transport Layer 3-89
Fast Recovery (differentiation btwn two loss events) After 3 dup ACKs (fast Retransmit)
ssthresh = CongWin2CongWin = CongWin2window then grows linearly
But after timeout eventCongWin = 1 MSS window then grows exponentiallyto the threshold then grows linearly
bull 3 dup ACKs indicates network capable of delivering some segmentsbull timeout before 3 dup ACKs is ldquomore alarmingrdquo
Philosophy
3-90
TCP Congestion ControlInitially
CongWin = 1ssthresh = advertised window size
New Ack receivedif (CongWin lt ssthresh) Slow Start
CongWin = CongWin + 1else Congestion Avoidance
CongWin = CongWin + 1CongWinTimeout
ssthresh = CongWin2CongWin = 1
Fast Retransmissionssthresh = CongWin2CongWin = CongWin2
Slow Start (exponential increase phase) is continued until CongWin reaches half of the level where the loss event occurred last time CongWin is increased slowly after (linear increase in Congestion Avoidance phase)
Transport Layer 3-91
Popular ldquoflavorsrdquo of TCP
ssthresh
ssthresh
TCP Tahoe
TCP Reno
Transmission round
cwnd
win
dow
siz
e (in
seg
men
ts)
Transport Layer 3-92
Summary TCP Congestion ControlWhen CongWin is below Threshold sender in slow-start phase window grows exponentiallyWhen CongWin is above Threshold sender is in congestion-avoidance phase window grows linearlyWhen a triple duplicate ACK occurs Threshold set to CongWin2 and CongWin set to ThresholdWhen timeout occurs Threshold set to CongWin2 and CongWin is set to 1 MSS The actual sender window size is determined based on the congestion and flow control algorithms
SenderWin=min(RcvWinCongWin)
Transport Layer 3-93
TCP Congestion Control SummaryEvent State TCP Sender Action Commentary
ACK receipt for previously unackeddata
Slow Start (SS)
CongWin = CongWin + MSS If (CongWin gt Threshold)
set state to ldquoCongestion Avoidancerdquo
Resulting in a doubling of CongWin every RTT
ACK receipt for previously unackeddata
CongestionAvoidance (CA)
CongWin = CongWin+MSS (MSSCongWin)
Additive increase resulting in increase of CongWin by 1 MSS every RTT
Loss event detected by triple duplicate ACK
SS or CA Threshold = CongWin2 CongWin = ThresholdSet state to ldquoCongestion Avoidancerdquo
Fast recovery implementing multiplicative decrease CongWin will not drop below 1 MSS
Timeout SS or CA Threshold = CongWin2 CongWin = 1 MSSSet state to ldquoSlow Startrdquo
Enter slow start
Duplicate ACK
SS or CA Increment duplicate ACK count for segment being acked
CongWin and Threshold not changed
Transport Layer 3-94
TCP throughput
Q whatrsquos average throughout of TCP as function of window size RTT
ignoring slow startlet W be window size when loss occurs
when window is W throughput is WRTTjust after loss window drops to W2 throughput to W2RTT average throughout 75 WRTT
Transport Layer 3-95
TCP Futures TCP over ldquolong fat pipesrdquo
example 1500 byte segments 100ms RTT want 10 Gbps throughputrequires window size W = 83333 in-flight segmentsthroughput in terms of loss rate
L = 210-10 Wownew versions of TCP for high-speed
LRTTMSSsdot221
Transport Layer 3-96
Fairness goal if K TCP sessions share same bottleneck link of bandwidth R each should have average rate of RK
TCP connection 1
bottleneckrouter
capacity R
TCP connection 2
TCP Fairness
Transport Layer 3-97
Why is TCP fairTwo competing sessions
Additive increase gives slope of 1 as throughout increasesmultiplicative decrease decreases throughput proportionally
R
R
equal bandwidth share
Connection 1 throughput
Conn
ecti
on 2
thr
ough
p ut
congestion avoidance additive increaseloss decrease window by factor of 2
congestion avoidance additive increaseloss decrease window by factor of 2
Transport Layer 3-98
Fairness (more)Fairness and UDP
Multimedia apps often do not use TCP
do not want rate throttled by congestion control
Instead use UDPpump audiovideo at constant rate tolerate packet loss
Research area TCP friendly
Fairness and parallel TCP connectionsnothing prevents app from opening parallel cnctionsbetween 2 hostsWeb browsers do this Example link of rate R supporting 9 cnctions
new app asks for 1 TCP gets rate R10new app asks for 11 TCPs gets R2
Transport Layer 3-99
TCP Connection ManagementRecall TCP sender receiver
establish ldquoconnectionrdquobefore exchanging data segmentsinitialize TCP variables
seq sbuffers flow control info (eg RcvWindow)
client connection initiatorSocket clientSocket = new Socket(hostnameport
number)
server contacted by clientSocket connectionSocket = welcomeSocketaccept()
Three way handshakeStep 1 client host sends TCP
SYN segment to serverspecifies initial seq no data
Step 2 server host receives SYN replies with SYNACK segment
server allocates buffersspecifies server initial seq
Step 3 client receives SYNACK replies with ACK segment which may contain data
Transport Layer 3-100
TCP Connection Management (cont)
Closing a connection
client closes socketclientSocketclose()
Step 1 client end system sends TCP FIN control segment to server
Step 2 server receives FIN replies with ACK Closes connection sends FIN
client
FIN
server
ACK
ACK
FIN
close
close
closed
tim
ed w
ait
Transport Layer 3-101
TCP Connection Management (cont)
Step 3 client receives FIN replies with ACK
Enters ldquotimed waitrdquo -will respond with ACK to received FINs
Step 4 server receives ACK Connection closed
client
FIN
server
ACK
ACK
FIN
closing
closing
closed
tim
ed w
ait
closed
Transport Layer 3-102
TCP Connection Management (cont)
TCP clientlifecycle
TCP serverlifecycle
Transport Layer 3-103
Tuning TCPIP Parameters TCPIP parameters
A set of default values may not be optimal for all applicationsThe network administrator may wish to turn on or off some TCPIP functions for performance or security considerations
Many Unix and Linux systems provide some flexibility in tuning the TCPIP kernelsbinsysctl is used to configure the Linux kernel parameters at runtime
Default kernel configuration file is sbinsysctlconfFrequently used sysctl options
bull sysctl ndasha or sysctl ndashA list all current valuesbull sysctl ndashp file_name load the sysctl setting from a configuration
filebull sysctl ndashw variable=value change the value of the parameter
Transport Layer 3-104
SomeTCP Parameters in Linux Kerneltcp_syn_retries
Number of SYN packets the kernel will send before giving up on the new connection
tcp_synack_retriesnumber of SYN+ACK packets sent before the kernel gives up on the connection
tcp_window_scalingMaximum window size of 65535 bytes not enough for for really fast networks The window scaling options allows for almost gigabyte windows which is good for connections with large delay-bandwidth product
tcp_max_syn_backlogMaximal number of remembered connection requests which still did not receive an acknowledgment from connecting client
tcp_fin_timeoutHow many seconds to wait for a final FIN packet before the socket is closed required to prevent denial-of-service (DoS) attacks Default value is 60 seconds
Transport Layer 3-105
SomeTCP Parameters in Linux Kerneltcp_rmem
This is a vector of 3 integers [min default max] These parameters are used by TCP to dynamically adjust receive buffer sizesmin - minimum size of the receive buffer used by each TCP socket The default value is 4K default - the default size of the receive buffer for a TCP socket The default value is 87380 bytes and is lowered to 43689 in low memory systems If larger receive buffer sizes are desired this value should be increased max - the maximum size of the receive buffer used by each TCP socket The default value of 873802 bytes is lowered to 87380 in low memory systems
tcp_smemSend buffer parameters [min default max] similar to tcp_rmem
- Chapter 3 Transport Layer
- Transport services and protocols
- Transport vs network layer
- Internet transport-layer protocols
- Multiplexingdemultiplexing
- How demultiplexing works
- Connectionless demultiplexing
- Connection-oriented demux
- Connection-oriented demux (cont)
- Connection-oriented demux Threaded Web Server
- UDP User Datagram Protocol [RFC 768]
- UDP more
- UDP checksum
- Principles of Reliable data transfer
- Reliable data transfer getting started
- Reliable data transfer getting started
- Rdt10 reliable transfer over a reliable channel
- Rdt20 channel with bit errors
- rdt20 FSM specification
- rdt20 operation with no errors
- rdt20 error scenario
- rdt20 has a fatal flaw
- rdt21 sender handles garbled ACKNAKs
- rdt21 receiver handles garbled ACKNAKs
- rdt21 discussion
- rdt22 a NAK-free protocol
- rdt22 sender receiver fragments
- rdt30 channels with errors and loss
- rdt30 sender
- rdt30 in action
- rdt30 in action
- Performance of rdt30
- rdt30 stop-and-wait operation
- Pipelined protocols
- Pipelining increased utilization
- Go-Back-N
- GBN sender extended FSM
- GBN receiver extended FSM
- GBN inaction
- Selective Repeat
- Selective repeat sender receiver windows
- Selective repeat
- Selective repeat in action
- Selective repeat dilemma
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- TCP Overview RFCs 793 1122 1323 2018 2581
- TCP segment structure
- TCP seq rsquos and ACKs
- TCP Round Trip Time and Timeout
- TCP Round Trip Time and Timeout
- Example RTT estimation
- TCP Round Trip Time and Timeout
- TCP reliable data transfer
- TCP sender events
- TCP sender(simplified)
- TCP retransmission scenarios
- TCP retransmission scenarios (more)
- TCP ACK generation [RFC 1122 RFC 2581]
- Fast Retransmit
- Fast Retransmit
- Fast retransmit algorithm
- TCP Flow Control
- TCP Flow control how it works
- Sliding Window Flow Control Example
- Principles of Congestion Control
- Causescosts of congestion scenario 1
- Causescosts of congestion scenario 2
- Causescosts of congestion scenario 2
- Causescosts of congestion scenario 3
- Causescosts of congestion scenario 3
- Approaches towards congestion control
- TCP Congestion Control
- TCP congestion control bandwidth probing
- TCP Congestion Control details
- TCP Congestion Control more details
- TCP Slow Start Phase
- Slow Start Example
- TCP Congestion Avoidance Phase
- Congestion Avoidance
- Example Slow StartCongestion Avoidance
- Slow Start Congestion Avoidance
- Responses to Congestion
- Fast Recovery (differentiation btwn two loss events)
- TCP Congestion Control
- Popular ldquoflavorsrdquo of TCP
- Summary TCP Congestion Control
- TCP Congestion Control Summary
- TCP throughput
- TCP Futures TCP over ldquolong fat pipesrdquo
- TCP Fairness
- Why is TCP fair
- Fairness (more)
- TCP Connection Management
- TCP Connection Management (cont)
- TCP Connection Management (cont)
- TCP Connection Management (cont)
- Tuning TCPIP Parameters
- SomeTCP Parameters in Linux Kernel
- SomeTCP Parameters in Linux Kernel
-
Transport Layer 3-44
Selective repeat in action
Transport Layer 3-45
Selective repeatdilemma
Example seq rsquos 0 1 2 3window size=3
receiver sees no difference in two scenariosincorrectly passes duplicate data as new in (a)
Q what relationship between seq size and window size
Transport Layer 3-46
Sequence Number vs Window SizeSuppose we use k bits to represent SNQuestion Whatrsquos the minimum number of bits k necessary for a window size of N
sender
receiver
Go-Back-N
expectedSN
snd_base=expectedSN
Q For a given expectedSN whatrsquos the largest possible value for snd_baseA If all the last N ACKs sent by the receiver are received
snd_base = expectedSNexpectedSN+N-1
senderrsquos window
Transport Layer 3-47
Sequence Number vs Window SizeSuppose we use k bits to represent SNQuestion Whatrsquos the minimum number of bits k necessary for a window size of N
sender
receiver
Go-Back-N
expectedSN
snd_base=expectedSN-N
Q For a given expectedSN whatrsquos the smallest possible value for snd_baseA If all the last N ACKs sent by the receiver are not received
snd_base = expectedSN-NexpectedSN-1
senderrsquos window
Transport Layer 3-48
Sequence Number vs Window Size
sender
receiver
Go-Back-N
expectedSN
snd_base=expectedSN-N
All SNs in the interval [expectedSN-NexpectedSN+N-1] (an interval of size 2N) can be received by the receiver Since the receiver accepts on the packet with SN=expectedSN there should be no other packet within this interval with SN=expectedSN Therefore
2k ge N+1expectedSN+N-1
Transport Layer 3-49
Sequence Number vs Window SizeSuppose we use k bits to represent SNQuestion Whatrsquos the minimum number of bits k necessary for a window size of N
sender
receiver
Selective Repeat
rcv_base
snd_base=rcv_base
Q For a given rcv_base whatrsquos the largest possible value for snd_baseA If all the last N ACKs sent by the receiver are received
snd_base = rcv_base (same as go_back-N)rcv_base+N-1
senderrsquos window
receiverrsquos window
rcv_base+N-1
Transport Layer 3-50
Sequence Number vs Window SizeSuppose we use k bits to represent SNQuestion Whatrsquos the minimum number of bits k necessary for a window size of N
sender
receiver
Selective Repeat
rcv_base
snd_base=rcv_base-N
Q For a given rcv_base whatrsquos the smallest possible value for snd_baseA If all the last N ACKs sent by the receiver are not received
snd_base = rcv_base-N (same as Go-Back-N)rcv_base-1
senderrsquos window
rcv_base
receiverrsquos window
rcv_base+N-1
Transport Layer 3-51
Sequence Number vs Window Size
sender
receiver
Selective Repeat
snd_base=rcv_base-N
All SNs in the interval [rcv_base-Nrcv_base+N-1] (an interval of size 2N) can be received by the receiver Since the receiver should be able to distinguish between all packets in this interval and take corresponding action there should be no two packets within thisinterval having the same SN Therefore
2k ge 2Nrcv_base+N-1
rcv_basercv_base
receiverrsquos window
rcv_base+N-1
Transport Layer 3-52
TCP Overview RFCs 793 1122 1323 2018 2581
full duplex databi-directional data flow in same connectionMSS maximum segment size
connection-orientedhandshaking (exchange of control msgs) initrsquossender receiver state before data exchange
flow controlledsender will not overwhelm receiver
point-to-pointone sender one receiver
reliable in-order byte stream
no ldquomessage boundariesrdquopipelined
TCP congestion and flow control set window size
send amp receive buffers
socketdoor
TCPsend buffer
TCPreceive buffer
socketdoor
segment
applicationwrites data
applicationreads data
Transport Layer 3-53
TCP segment structure
source port dest port
32 bits
applicationdata
(variable length)
sequence numberacknowledgement number
Receive windowUrg data pnterchecksum
FSRPAUheadlen
notused
Options (variable length)
URG urgent data (generally not used)
ACK ACK valid
PSH push data now(generally not used)
RST SYN FINconnection estab(setup teardown
commands)
bytes rcvr willingto accept
Internetchecksum
(as in UDP)
countingby bytes of data(not segments)
Transport Layer 3-54
TCP seq rsquos and ACKsSeq rsquos
byte stream ldquonumberrdquo of first byte in segmentrsquos dataACKs
seq of next byte expected from other sidecumulative ACK
Q how receiver handles out-of-order segmentsA TCP spec doesnrsquot say - up to implementationWidely used implementations of TCP buffer out-of-order segments
Transport Layer 3-55
TCP Round Trip Time and Timeout
Q how to set TCP timeout valuelonger than RTT
but RTT variestoo short premature timeout
unnecessary retransmissions
too long slow reaction to segment loss
Q how to estimate RTTSampleRTT measured time from segment transmission until ACK receipt
ignore retransmissionsSampleRTT will vary want estimated RTT ldquosmootherrdquo
average several recent measurements not just current SampleRTT
Transport Layer 3-56
TCP Round Trip Time and Timeout
EstimatedRTT = (1- α)EstimatedRTT + αSampleRTT
Exponential weighted moving averageinfluence of past sample decreases exponentially fasttypical value α = 0125
Transport Layer 3-57
Example RTT estimationRTT gaiacsumassedu to fantasiaeurecomfr
100
150
200
250
300
350
1 8 15 22 29 36 43 50 57 64 71 78 85 92 99 106
time (seconnds)
RTT
(mill
iseco
nds)
SampleRTT Estimated RTT
Transport Layer 3-58
TCP Round Trip Time and TimeoutSetting the timeout
EstimatedRTT plus ldquosafety marginrdquolarge variation in EstimatedRTT -gt larger safety margin
first estimate of how much SampleRTT deviates from EstimatedRTT
TimeoutInterval = EstimatedRTT + 4DevRTT
DevRTT = (1-β)DevRTT +β|SampleRTT-EstimatedRTT|
(typically β = 025)
Then set timeout interval
Transport Layer 3-59
TCP reliable data transfer
TCP creates rdtservice on top of IPrsquos unreliable servicePipelined segmentsCumulative acksTCP uses single retransmission timer however it just retransmits the first segment in the window
Retransmissions are triggered by
timeout eventsduplicate acks
Initially consider simplified TCP sender
ignore duplicate acksignore flow control congestion control
Transport Layer 3-60
TCP sender eventsdata rcvd from app
Create segment with seq seq is byte-stream number of first data byte in segmentstart timer if not already running (think of timer as for oldest unacked segment)expiration interval TimeOutInterval
timeoutretransmit segment that caused timeout (first segment in the window)restart timer
Ack rcvdIf acknowledges previously unacked segments
update what is known to be ackedstart timer if there are outstanding segments
Transport Layer 3-61
TCP sender(simplified)
NextSeqNum = InitialSeqNumSendBase = InitialSeqNum
loop (forever) switch(event)
event data received from application above create TCP segment with sequence number NextSeqNumif (timer currently not running)
start timerpass segment to IP NextSeqNum = NextSeqNum + length(data)
event timer timeoutretransmit not-yet-acknowledged segment with
smallest sequence numberstart timer
event ACK received with ACK field value of y if (y gt SendBase)
SendBase = yif (there are currently not-yet-acknowledged segments)
start timer
end of loop forever
Commentbull SendBase-1 last cumulatively ackrsquoed byteExamplebull SendBase-1 = 71y= 73 so the rcvrwants 73+ y gt SendBase sothat new data is acked
Transport Layer 3-62
TCP retransmission scenariosHost A
Seq=100 20 bytes data
ACK=100
timepremature timeout
Host B
Seq=92 8 bytes data
ACK=120
Seq=92 8 bytes data
Seq=
92 t
imeo
ut
ACK=120
Host A
Seq=92 8 bytes data
ACK=100
loss
tim
eout
lost ACK scenario
Host B
X
Seq=92 8 bytes data
ACK=100
time
Seq=
92 t
imeo
utSendBase
= 100
SendBase= 120
SendBase= 120
Sendbase= 100
Transport Layer 3-63
TCP retransmission scenarios (more)Host A
Seq=92 8 bytes data
ACK=100
loss
tim
eout
Cumulative ACK scenario
Host B
X
Seq=100 20 bytes data
ACK=120
time
SendBase= 120
Transport Layer 3-64
TCP ACK generation [RFC 1122 RFC 2581]
Event at Receiver
Arrival of in-order segment withexpected seq All data up toexpected seq already ACKed
Arrival of in-order segment withexpected seq One other segment has ACK pending
Arrival of out-of-order segmenthigher-than-expect seq Gap detected
Arrival of segment that partially or completely fills gap
TCP Receiver action
Delayed ACK Wait up to 500msfor next segment If no next segmentsend ACK
Immediately send single cumulative ACK ACKing both in-order segments
Immediately send duplicate ACK indicating seq of next expected byte
Immediate send ACK provided thatsegment startsat lower end of gap
Transport Layer 3-65
Fast Retransmit
Time-out period often relatively long
long delay before resending lost packet
Detect lost segments via duplicate ACKs
Sender often sends many segments back-to-backIf segment is lost there will likely be many duplicate ACKs
If sender receives 3 ACKs for the same data it supposes that segment after ACKeddata was lost
fast retransmit resend segment before timer expires
Transport Layer 3-66
Fast RetransmitResend a segment after 3 duplicate ACKs since a duplicate ACK means that an out-of sequence segment was receivedduplicate ACKs due to packet reorderingif window is small donrsquot get duplicate ACKs
Host A
tim
eout
Host B
time
X
resend seq X2
seq x1seq x2seq x3seq x4seq x5
ACK x1
ACK x1ACK x1ACK x1
tripleduplicate
ACKs
Transport Layer 3-67
event ACK received with ACK field value of y if (y gt SendBase)
SendBase = yif (there are currently not-yet-acknowledged segments)
start timer
else increment count of dup ACKs received for yif (count of dup ACKs received for y = 3)
resend segment with sequence number y
Fast retransmit algorithm
a duplicate ACK for already ACKed segment
fast retransmit
Transport Layer 3-68
TCP Flow Control
receive side of TCP connection has a receive buffer
speed-matching service matching the send rate to the receiving apprsquos drain rate
app process may be slow at reading from buffer
sender wonrsquot overflowreceiverrsquos buffer by
transmitting too muchtoo fast
flow control
Transport Layer 3-69
TCP Flow control how it works
(Suppose TCP receiver discards out-of-order segments)spare room in buffer
= RcvWin
= RcvBuffer-[LastByteRcvd -LastByteRead]
Rcvr advertises spare room by including value of RcvWin in segmentsSender limits unACKeddata to RcvWin
guarantees receive buffer doesnrsquot overflow
Transport Layer 3-70
Sliding Window Flow Control Example
3K
2K SeqNo=0
ReceiverBuffer
0 4KSendersends 2Kof data
2K
AckNo=2048 RcvWin=2048Sendersends 2Kof data 2K SeqNo=2048
4K
AckNo=4096 RcvWin=0
AckNo=4096 RcvWin=1024
Sender blocked
Transport Layer 3-71
Principles of Congestion Control
Congestioninformally ldquotoo many sources sending too much data too fast for network to handlerdquodifferent from flow controlmanifestations
lost packets (buffer overflow at routers)long delays (queueing in router buffers)
a top-10 problem
Transport Layer 3-72
Causescosts of congestion scenario 1
two senders two receiversone router infinite buffers no retransmission
large delays when congestedmaximum achievable throughput
unlimited shared output link buffers
Host Aλin original data
Host B
λout
Transport Layer 3-73
Causescosts of congestion scenario 2
one router finite buffers sender retransmission of lost packet
finite shared output link buffers
Host A λin original data
Host B
λout
λin original data plus retransmitted data
Transport Layer 3-74
Causescosts of congestion scenario 2always (goodput)ldquoperfectrdquo retransmission only when loss
retransmission of delayed (not lost) packet makes larger(than perfect case) for same
λin
λout=
λin
λoutgtλ
inλout
ldquocostsrdquo of congestionmore work (retrans) for given ldquogoodputrdquounneeded retransmissions link carries multiple copies of pkt
R2
R2λin
λ out
b
R2
R2λin
λ out
a
R2
R2λin
λ out
c
R4
R3
Transport Layer 3-75
Causescosts of congestion scenario 3four sendersmultihop pathstimeoutretransmit
λin
Q what happens as and increase λ
in
finite shared output link buffers
Host Aλin original data
Host B
λout
λin original data plus retransmitted data
Transport Layer 3-76
Causescosts of congestion scenario 3
another ldquocostrdquo of congestionwhen packet dropped any ldquoupstream transmission capacity used for that packet was wasted
Host A
Host B
λou
t
Transport Layer 3-77
Approaches towards congestion control
End-end congestion controlno explicit feedback from networkcongestion inferred from end-system observed loss delayapproach taken by TCP
Network-assisted congestion controlrouters provide feedback to end systems
single bit indicating congestion (SNA DECbit TCPIP ECN ATM)explicit rate sender should send at
Two broad approaches towards congestion control
Transport Layer 3-78
TCP Congestion Control
end-end control (no network assistance)sender limits transmissionLastByteSent-LastByteAcked
le CongWin
CongWin is dynamic function of perceived network congestion
How does sender perceive congestionloss event = timeout or3 duplicate acksTCP sender reduces rate (CongWin) after loss event
two modes of operationSlow Start (SS)Congestion avoidance (CA) or Additive Increase Multiplicative Decrease (AIMD)
Transport Layer 3-79
TCP congestion control bandwidth probing
ldquoprobing for bandwidthrdquo increase transmission rate on receipt of ACK until eventually loss occurs then decrease transmission rate
continue to increase on ACK decrease on loss (since available bandwidth is changing depending on other connections in network)
ACKs being received so increase rate
X
X
XX
X loss so decrease rate
send
ing
rate
time
Q how fast to increasedecreasedetails to follow
TCPrsquosldquosawtoothrdquobehavior
Transport Layer 3-80
TCP Congestion Control details
sender limits rate by limiting number of unACKed bytes ldquoin pipelinerdquo
cwnd differs from rwnd (how why)sender limited by min(cwndrwnd)
roughly
cwnd is dynamic function of perceived network congestion
rate = cwndRTT bytessec
LastByteSent-LastByteAcked le cwnd
cwndbytes
RTT
ACK(s)
Transport Layer 3-81
TCP Congestion Control more details
segment loss event reducing cwndtimeout no response from receiver
cut cwnd to 13 duplicate ACKs at least some segments getting through (recall fast retransmit)
cut cwnd in half less aggressively than on timeout
ACK received increase cwndTwo modes of operation
slowstart phase bull increase exponentially
fast (despite name) at connection start or following timeout
congestion avoidance bull increase linearly
Transport Layer 3-82
TCP Slow Start Phasewhen connection begins cwnd = 1 MSS
example MSS = 500 bytes amp RTT = 200 msecinitial rate = 20 kbps
available bandwidth may be gtgt MSSRTT
desirable to quickly ramp up to respectable rate
increase rate exponentially until first loss event or when threshold reached
double cwnd every RTTdone by incrementing cwnd by 1 for every ACK received
Host A
one segment
RTT
Host B
time
two segments
four segments
Transport Layer 3-83
Slow Start ExampleThe congestion window size grows very rapidly
For every ACK we increase CongWin by 1 irrespective of the number of segments ACKrsquoeddouble CongWinevery RTTinitial rate is slow but ramps up exponentially fast
TCP slows down the increase of CongWinwhen CongWin gt ssthresh
segment 1
ACK for segment 1
cwnd = 1
cwnd = 2 segment 2segment 3
ACK for segments 2
cwnd = 4 segment 4segment 5segment 6
ACK for segments 4
cwnd = 7
ACK for segments 3
ACK for segments 5
ACK for segments 6
cwnd = 3
cwnd = 5
cwnd = 6ACK for segments 7
cwnd = 8
segment 7
Transport Layer 3-84
TCP Congestion Avoidance Phase
when cwnd gt ssthreshgrow cwnd linearly
increase cwnd by 1 MSS per RTT approach possible congestion slower than in slowstartimplementation cwnd= cwnd + MSScwndfor each ACK received
ACKs increase cwndby 1 MSS per RTT additive increaseloss cut cwnd in half (non-timeout-detected loss ) multiplicative decrease
AIMD
AIMD Additive IncreaseMultiplicative Decrease
Transport Layer 3-85
Congestion AvoidanceCongestion avoidance phase is started if CongWin has reached the slow-start threshold value
If CongWin gt= ssthresh then each time an ACK is received increment CongWin as follows
bull CongWin = CongWin + 1CongWin (CongWin in segments)
bull In actual TCP implementation CongWin is in BytesCongWin = CongWin + MSS (MSSCongWin)
So CongWin is increased by one only if all CongWinsegments have been acknowledged
Transport Layer 3-86
Example Slow StartCongestion AvoidanceAssume that
ssthresh = 8
cwnd = 1
cwnd = 2
cwnd = 4
cwnd = 8
cwnd = 9
cwnd = 10
02468
101214
t=0
t=2
t=4
t=6
Roundtrip times
Cw
nd(in
seg
men
ts)
ssthresh
cwnd = 3
cwnd = 5cwnd = 6cwnd = 7
Transport Layer 3-87
Slow Start Congestion AvoidanceA typical plot of CongWin for a TCP connection
(MSS = 1500 bytes) with TCP Tahoe
SS
CA
ssthresh
Transport Layer 3-88
Responses to CongestionTCP assumes there is congestion if it detects a packet lossA TCP sender can detect lost packets via loss events
bull Timeout of a retransmission timerbull Receipt of 3 duplicate ACKs (fast retransmit)
TCP interprets a Timeout as a binary congestion signal When a timeout occurs the sender performs
ssthresh is set to half the current size of the congestion window
ssthresh = CongWin 2CongWin is reset to one
CongWin = 1and slow-start is entered
Transport Layer 3-89
Fast Recovery (differentiation btwn two loss events) After 3 dup ACKs (fast Retransmit)
ssthresh = CongWin2CongWin = CongWin2window then grows linearly
But after timeout eventCongWin = 1 MSS window then grows exponentiallyto the threshold then grows linearly
bull 3 dup ACKs indicates network capable of delivering some segmentsbull timeout before 3 dup ACKs is ldquomore alarmingrdquo
Philosophy
3-90
TCP Congestion ControlInitially
CongWin = 1ssthresh = advertised window size
New Ack receivedif (CongWin lt ssthresh) Slow Start
CongWin = CongWin + 1else Congestion Avoidance
CongWin = CongWin + 1CongWinTimeout
ssthresh = CongWin2CongWin = 1
Fast Retransmissionssthresh = CongWin2CongWin = CongWin2
Slow Start (exponential increase phase) is continued until CongWin reaches half of the level where the loss event occurred last time CongWin is increased slowly after (linear increase in Congestion Avoidance phase)
Transport Layer 3-91
Popular ldquoflavorsrdquo of TCP
ssthresh
ssthresh
TCP Tahoe
TCP Reno
Transmission round
cwnd
win
dow
siz
e (in
seg
men
ts)
Transport Layer 3-92
Summary TCP Congestion ControlWhen CongWin is below Threshold sender in slow-start phase window grows exponentiallyWhen CongWin is above Threshold sender is in congestion-avoidance phase window grows linearlyWhen a triple duplicate ACK occurs Threshold set to CongWin2 and CongWin set to ThresholdWhen timeout occurs Threshold set to CongWin2 and CongWin is set to 1 MSS The actual sender window size is determined based on the congestion and flow control algorithms
SenderWin=min(RcvWinCongWin)
Transport Layer 3-93
TCP Congestion Control SummaryEvent State TCP Sender Action Commentary
ACK receipt for previously unackeddata
Slow Start (SS)
CongWin = CongWin + MSS If (CongWin gt Threshold)
set state to ldquoCongestion Avoidancerdquo
Resulting in a doubling of CongWin every RTT
ACK receipt for previously unackeddata
CongestionAvoidance (CA)
CongWin = CongWin+MSS (MSSCongWin)
Additive increase resulting in increase of CongWin by 1 MSS every RTT
Loss event detected by triple duplicate ACK
SS or CA Threshold = CongWin2 CongWin = ThresholdSet state to ldquoCongestion Avoidancerdquo
Fast recovery implementing multiplicative decrease CongWin will not drop below 1 MSS
Timeout SS or CA Threshold = CongWin2 CongWin = 1 MSSSet state to ldquoSlow Startrdquo
Enter slow start
Duplicate ACK
SS or CA Increment duplicate ACK count for segment being acked
CongWin and Threshold not changed
Transport Layer 3-94
TCP throughput
Q whatrsquos average throughout of TCP as function of window size RTT
ignoring slow startlet W be window size when loss occurs
when window is W throughput is WRTTjust after loss window drops to W2 throughput to W2RTT average throughout 75 WRTT
Transport Layer 3-95
TCP Futures TCP over ldquolong fat pipesrdquo
example 1500 byte segments 100ms RTT want 10 Gbps throughputrequires window size W = 83333 in-flight segmentsthroughput in terms of loss rate
L = 210-10 Wownew versions of TCP for high-speed
LRTTMSSsdot221
Transport Layer 3-96
Fairness goal if K TCP sessions share same bottleneck link of bandwidth R each should have average rate of RK
TCP connection 1
bottleneckrouter
capacity R
TCP connection 2
TCP Fairness
Transport Layer 3-97
Why is TCP fairTwo competing sessions
Additive increase gives slope of 1 as throughout increasesmultiplicative decrease decreases throughput proportionally
R
R
equal bandwidth share
Connection 1 throughput
Conn
ecti
on 2
thr
ough
p ut
congestion avoidance additive increaseloss decrease window by factor of 2
congestion avoidance additive increaseloss decrease window by factor of 2
Transport Layer 3-98
Fairness (more)Fairness and UDP
Multimedia apps often do not use TCP
do not want rate throttled by congestion control
Instead use UDPpump audiovideo at constant rate tolerate packet loss
Research area TCP friendly
Fairness and parallel TCP connectionsnothing prevents app from opening parallel cnctionsbetween 2 hostsWeb browsers do this Example link of rate R supporting 9 cnctions
new app asks for 1 TCP gets rate R10new app asks for 11 TCPs gets R2
Transport Layer 3-99
TCP Connection ManagementRecall TCP sender receiver
establish ldquoconnectionrdquobefore exchanging data segmentsinitialize TCP variables
seq sbuffers flow control info (eg RcvWindow)
client connection initiatorSocket clientSocket = new Socket(hostnameport
number)
server contacted by clientSocket connectionSocket = welcomeSocketaccept()
Three way handshakeStep 1 client host sends TCP
SYN segment to serverspecifies initial seq no data
Step 2 server host receives SYN replies with SYNACK segment
server allocates buffersspecifies server initial seq
Step 3 client receives SYNACK replies with ACK segment which may contain data
Transport Layer 3-100
TCP Connection Management (cont)
Closing a connection
client closes socketclientSocketclose()
Step 1 client end system sends TCP FIN control segment to server
Step 2 server receives FIN replies with ACK Closes connection sends FIN
client
FIN
server
ACK
ACK
FIN
close
close
closed
tim
ed w
ait
Transport Layer 3-101
TCP Connection Management (cont)
Step 3 client receives FIN replies with ACK
Enters ldquotimed waitrdquo -will respond with ACK to received FINs
Step 4 server receives ACK Connection closed
client
FIN
server
ACK
ACK
FIN
closing
closing
closed
tim
ed w
ait
closed
Transport Layer 3-102
TCP Connection Management (cont)
TCP clientlifecycle
TCP serverlifecycle
Transport Layer 3-103
Tuning TCPIP Parameters TCPIP parameters
A set of default values may not be optimal for all applicationsThe network administrator may wish to turn on or off some TCPIP functions for performance or security considerations
Many Unix and Linux systems provide some flexibility in tuning the TCPIP kernelsbinsysctl is used to configure the Linux kernel parameters at runtime
Default kernel configuration file is sbinsysctlconfFrequently used sysctl options
bull sysctl ndasha or sysctl ndashA list all current valuesbull sysctl ndashp file_name load the sysctl setting from a configuration
filebull sysctl ndashw variable=value change the value of the parameter
Transport Layer 3-104
SomeTCP Parameters in Linux Kerneltcp_syn_retries
Number of SYN packets the kernel will send before giving up on the new connection
tcp_synack_retriesnumber of SYN+ACK packets sent before the kernel gives up on the connection
tcp_window_scalingMaximum window size of 65535 bytes not enough for for really fast networks The window scaling options allows for almost gigabyte windows which is good for connections with large delay-bandwidth product
tcp_max_syn_backlogMaximal number of remembered connection requests which still did not receive an acknowledgment from connecting client
tcp_fin_timeoutHow many seconds to wait for a final FIN packet before the socket is closed required to prevent denial-of-service (DoS) attacks Default value is 60 seconds
Transport Layer 3-105
SomeTCP Parameters in Linux Kerneltcp_rmem
This is a vector of 3 integers [min default max] These parameters are used by TCP to dynamically adjust receive buffer sizesmin - minimum size of the receive buffer used by each TCP socket The default value is 4K default - the default size of the receive buffer for a TCP socket The default value is 87380 bytes and is lowered to 43689 in low memory systems If larger receive buffer sizes are desired this value should be increased max - the maximum size of the receive buffer used by each TCP socket The default value of 873802 bytes is lowered to 87380 in low memory systems
tcp_smemSend buffer parameters [min default max] similar to tcp_rmem
- Chapter 3 Transport Layer
- Transport services and protocols
- Transport vs network layer
- Internet transport-layer protocols
- Multiplexingdemultiplexing
- How demultiplexing works
- Connectionless demultiplexing
- Connection-oriented demux
- Connection-oriented demux (cont)
- Connection-oriented demux Threaded Web Server
- UDP User Datagram Protocol [RFC 768]
- UDP more
- UDP checksum
- Principles of Reliable data transfer
- Reliable data transfer getting started
- Reliable data transfer getting started
- Rdt10 reliable transfer over a reliable channel
- Rdt20 channel with bit errors
- rdt20 FSM specification
- rdt20 operation with no errors
- rdt20 error scenario
- rdt20 has a fatal flaw
- rdt21 sender handles garbled ACKNAKs
- rdt21 receiver handles garbled ACKNAKs
- rdt21 discussion
- rdt22 a NAK-free protocol
- rdt22 sender receiver fragments
- rdt30 channels with errors and loss
- rdt30 sender
- rdt30 in action
- rdt30 in action
- Performance of rdt30
- rdt30 stop-and-wait operation
- Pipelined protocols
- Pipelining increased utilization
- Go-Back-N
- GBN sender extended FSM
- GBN receiver extended FSM
- GBN inaction
- Selective Repeat
- Selective repeat sender receiver windows
- Selective repeat
- Selective repeat in action
- Selective repeat dilemma
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- TCP Overview RFCs 793 1122 1323 2018 2581
- TCP segment structure
- TCP seq rsquos and ACKs
- TCP Round Trip Time and Timeout
- TCP Round Trip Time and Timeout
- Example RTT estimation
- TCP Round Trip Time and Timeout
- TCP reliable data transfer
- TCP sender events
- TCP sender(simplified)
- TCP retransmission scenarios
- TCP retransmission scenarios (more)
- TCP ACK generation [RFC 1122 RFC 2581]
- Fast Retransmit
- Fast Retransmit
- Fast retransmit algorithm
- TCP Flow Control
- TCP Flow control how it works
- Sliding Window Flow Control Example
- Principles of Congestion Control
- Causescosts of congestion scenario 1
- Causescosts of congestion scenario 2
- Causescosts of congestion scenario 2
- Causescosts of congestion scenario 3
- Causescosts of congestion scenario 3
- Approaches towards congestion control
- TCP Congestion Control
- TCP congestion control bandwidth probing
- TCP Congestion Control details
- TCP Congestion Control more details
- TCP Slow Start Phase
- Slow Start Example
- TCP Congestion Avoidance Phase
- Congestion Avoidance
- Example Slow StartCongestion Avoidance
- Slow Start Congestion Avoidance
- Responses to Congestion
- Fast Recovery (differentiation btwn two loss events)
- TCP Congestion Control
- Popular ldquoflavorsrdquo of TCP
- Summary TCP Congestion Control
- TCP Congestion Control Summary
- TCP throughput
- TCP Futures TCP over ldquolong fat pipesrdquo
- TCP Fairness
- Why is TCP fair
- Fairness (more)
- TCP Connection Management
- TCP Connection Management (cont)
- TCP Connection Management (cont)
- TCP Connection Management (cont)
- Tuning TCPIP Parameters
- SomeTCP Parameters in Linux Kernel
- SomeTCP Parameters in Linux Kernel
-
Transport Layer 3-45
Selective repeatdilemma
Example seq rsquos 0 1 2 3window size=3
receiver sees no difference in two scenariosincorrectly passes duplicate data as new in (a)
Q what relationship between seq size and window size
Transport Layer 3-46
Sequence Number vs Window SizeSuppose we use k bits to represent SNQuestion Whatrsquos the minimum number of bits k necessary for a window size of N
sender
receiver
Go-Back-N
expectedSN
snd_base=expectedSN
Q For a given expectedSN whatrsquos the largest possible value for snd_baseA If all the last N ACKs sent by the receiver are received
snd_base = expectedSNexpectedSN+N-1
senderrsquos window
Transport Layer 3-47
Sequence Number vs Window SizeSuppose we use k bits to represent SNQuestion Whatrsquos the minimum number of bits k necessary for a window size of N
sender
receiver
Go-Back-N
expectedSN
snd_base=expectedSN-N
Q For a given expectedSN whatrsquos the smallest possible value for snd_baseA If all the last N ACKs sent by the receiver are not received
snd_base = expectedSN-NexpectedSN-1
senderrsquos window
Transport Layer 3-48
Sequence Number vs Window Size
sender
receiver
Go-Back-N
expectedSN
snd_base=expectedSN-N
All SNs in the interval [expectedSN-NexpectedSN+N-1] (an interval of size 2N) can be received by the receiver Since the receiver accepts on the packet with SN=expectedSN there should be no other packet within this interval with SN=expectedSN Therefore
2k ge N+1expectedSN+N-1
Transport Layer 3-49
Sequence Number vs Window SizeSuppose we use k bits to represent SNQuestion Whatrsquos the minimum number of bits k necessary for a window size of N
sender
receiver
Selective Repeat
rcv_base
snd_base=rcv_base
Q For a given rcv_base whatrsquos the largest possible value for snd_baseA If all the last N ACKs sent by the receiver are received
snd_base = rcv_base (same as go_back-N)rcv_base+N-1
senderrsquos window
receiverrsquos window
rcv_base+N-1
Transport Layer 3-50
Sequence Number vs Window SizeSuppose we use k bits to represent SNQuestion Whatrsquos the minimum number of bits k necessary for a window size of N
sender
receiver
Selective Repeat
rcv_base
snd_base=rcv_base-N
Q For a given rcv_base whatrsquos the smallest possible value for snd_baseA If all the last N ACKs sent by the receiver are not received
snd_base = rcv_base-N (same as Go-Back-N)rcv_base-1
senderrsquos window
rcv_base
receiverrsquos window
rcv_base+N-1
Transport Layer 3-51
Sequence Number vs Window Size
sender
receiver
Selective Repeat
snd_base=rcv_base-N
All SNs in the interval [rcv_base-Nrcv_base+N-1] (an interval of size 2N) can be received by the receiver Since the receiver should be able to distinguish between all packets in this interval and take corresponding action there should be no two packets within thisinterval having the same SN Therefore
2k ge 2Nrcv_base+N-1
rcv_basercv_base
receiverrsquos window
rcv_base+N-1
Transport Layer 3-52
TCP Overview RFCs 793 1122 1323 2018 2581
full duplex databi-directional data flow in same connectionMSS maximum segment size
connection-orientedhandshaking (exchange of control msgs) initrsquossender receiver state before data exchange
flow controlledsender will not overwhelm receiver
point-to-pointone sender one receiver
reliable in-order byte stream
no ldquomessage boundariesrdquopipelined
TCP congestion and flow control set window size
send amp receive buffers
socketdoor
TCPsend buffer
TCPreceive buffer
socketdoor
segment
applicationwrites data
applicationreads data
Transport Layer 3-53
TCP segment structure
source port dest port
32 bits
applicationdata
(variable length)
sequence numberacknowledgement number
Receive windowUrg data pnterchecksum
FSRPAUheadlen
notused
Options (variable length)
URG urgent data (generally not used)
ACK ACK valid
PSH push data now(generally not used)
RST SYN FINconnection estab(setup teardown
commands)
bytes rcvr willingto accept
Internetchecksum
(as in UDP)
countingby bytes of data(not segments)
Transport Layer 3-54
TCP seq rsquos and ACKsSeq rsquos
byte stream ldquonumberrdquo of first byte in segmentrsquos dataACKs
seq of next byte expected from other sidecumulative ACK
Q how receiver handles out-of-order segmentsA TCP spec doesnrsquot say - up to implementationWidely used implementations of TCP buffer out-of-order segments
Transport Layer 3-55
TCP Round Trip Time and Timeout
Q how to set TCP timeout valuelonger than RTT
but RTT variestoo short premature timeout
unnecessary retransmissions
too long slow reaction to segment loss
Q how to estimate RTTSampleRTT measured time from segment transmission until ACK receipt
ignore retransmissionsSampleRTT will vary want estimated RTT ldquosmootherrdquo
average several recent measurements not just current SampleRTT
Transport Layer 3-56
TCP Round Trip Time and Timeout
EstimatedRTT = (1- α)EstimatedRTT + αSampleRTT
Exponential weighted moving averageinfluence of past sample decreases exponentially fasttypical value α = 0125
Transport Layer 3-57
Example RTT estimationRTT gaiacsumassedu to fantasiaeurecomfr
100
150
200
250
300
350
1 8 15 22 29 36 43 50 57 64 71 78 85 92 99 106
time (seconnds)
RTT
(mill
iseco
nds)
SampleRTT Estimated RTT
Transport Layer 3-58
TCP Round Trip Time and TimeoutSetting the timeout
EstimatedRTT plus ldquosafety marginrdquolarge variation in EstimatedRTT -gt larger safety margin
first estimate of how much SampleRTT deviates from EstimatedRTT
TimeoutInterval = EstimatedRTT + 4DevRTT
DevRTT = (1-β)DevRTT +β|SampleRTT-EstimatedRTT|
(typically β = 025)
Then set timeout interval
Transport Layer 3-59
TCP reliable data transfer
TCP creates rdtservice on top of IPrsquos unreliable servicePipelined segmentsCumulative acksTCP uses single retransmission timer however it just retransmits the first segment in the window
Retransmissions are triggered by
timeout eventsduplicate acks
Initially consider simplified TCP sender
ignore duplicate acksignore flow control congestion control
Transport Layer 3-60
TCP sender eventsdata rcvd from app
Create segment with seq seq is byte-stream number of first data byte in segmentstart timer if not already running (think of timer as for oldest unacked segment)expiration interval TimeOutInterval
timeoutretransmit segment that caused timeout (first segment in the window)restart timer
Ack rcvdIf acknowledges previously unacked segments
update what is known to be ackedstart timer if there are outstanding segments
Transport Layer 3-61
TCP sender(simplified)
NextSeqNum = InitialSeqNumSendBase = InitialSeqNum
loop (forever) switch(event)
event data received from application above create TCP segment with sequence number NextSeqNumif (timer currently not running)
start timerpass segment to IP NextSeqNum = NextSeqNum + length(data)
event timer timeoutretransmit not-yet-acknowledged segment with
smallest sequence numberstart timer
event ACK received with ACK field value of y if (y gt SendBase)
SendBase = yif (there are currently not-yet-acknowledged segments)
start timer
end of loop forever
Commentbull SendBase-1 last cumulatively ackrsquoed byteExamplebull SendBase-1 = 71y= 73 so the rcvrwants 73+ y gt SendBase sothat new data is acked
Transport Layer 3-62
TCP retransmission scenariosHost A
Seq=100 20 bytes data
ACK=100
timepremature timeout
Host B
Seq=92 8 bytes data
ACK=120
Seq=92 8 bytes data
Seq=
92 t
imeo
ut
ACK=120
Host A
Seq=92 8 bytes data
ACK=100
loss
tim
eout
lost ACK scenario
Host B
X
Seq=92 8 bytes data
ACK=100
time
Seq=
92 t
imeo
utSendBase
= 100
SendBase= 120
SendBase= 120
Sendbase= 100
Transport Layer 3-63
TCP retransmission scenarios (more)Host A
Seq=92 8 bytes data
ACK=100
loss
tim
eout
Cumulative ACK scenario
Host B
X
Seq=100 20 bytes data
ACK=120
time
SendBase= 120
Transport Layer 3-64
TCP ACK generation [RFC 1122 RFC 2581]
Event at Receiver
Arrival of in-order segment withexpected seq All data up toexpected seq already ACKed
Arrival of in-order segment withexpected seq One other segment has ACK pending
Arrival of out-of-order segmenthigher-than-expect seq Gap detected
Arrival of segment that partially or completely fills gap
TCP Receiver action
Delayed ACK Wait up to 500msfor next segment If no next segmentsend ACK
Immediately send single cumulative ACK ACKing both in-order segments
Immediately send duplicate ACK indicating seq of next expected byte
Immediate send ACK provided thatsegment startsat lower end of gap
Transport Layer 3-65
Fast Retransmit
Time-out period often relatively long
long delay before resending lost packet
Detect lost segments via duplicate ACKs
Sender often sends many segments back-to-backIf segment is lost there will likely be many duplicate ACKs
If sender receives 3 ACKs for the same data it supposes that segment after ACKeddata was lost
fast retransmit resend segment before timer expires
Transport Layer 3-66
Fast RetransmitResend a segment after 3 duplicate ACKs since a duplicate ACK means that an out-of sequence segment was receivedduplicate ACKs due to packet reorderingif window is small donrsquot get duplicate ACKs
Host A
tim
eout
Host B
time
X
resend seq X2
seq x1seq x2seq x3seq x4seq x5
ACK x1
ACK x1ACK x1ACK x1
tripleduplicate
ACKs
Transport Layer 3-67
event ACK received with ACK field value of y if (y gt SendBase)
SendBase = yif (there are currently not-yet-acknowledged segments)
start timer
else increment count of dup ACKs received for yif (count of dup ACKs received for y = 3)
resend segment with sequence number y
Fast retransmit algorithm
a duplicate ACK for already ACKed segment
fast retransmit
Transport Layer 3-68
TCP Flow Control
receive side of TCP connection has a receive buffer
speed-matching service matching the send rate to the receiving apprsquos drain rate
app process may be slow at reading from buffer
sender wonrsquot overflowreceiverrsquos buffer by
transmitting too muchtoo fast
flow control
Transport Layer 3-69
TCP Flow control how it works
(Suppose TCP receiver discards out-of-order segments)spare room in buffer
= RcvWin
= RcvBuffer-[LastByteRcvd -LastByteRead]
Rcvr advertises spare room by including value of RcvWin in segmentsSender limits unACKeddata to RcvWin
guarantees receive buffer doesnrsquot overflow
Transport Layer 3-70
Sliding Window Flow Control Example
3K
2K SeqNo=0
ReceiverBuffer
0 4KSendersends 2Kof data
2K
AckNo=2048 RcvWin=2048Sendersends 2Kof data 2K SeqNo=2048
4K
AckNo=4096 RcvWin=0
AckNo=4096 RcvWin=1024
Sender blocked
Transport Layer 3-71
Principles of Congestion Control
Congestioninformally ldquotoo many sources sending too much data too fast for network to handlerdquodifferent from flow controlmanifestations
lost packets (buffer overflow at routers)long delays (queueing in router buffers)
a top-10 problem
Transport Layer 3-72
Causescosts of congestion scenario 1
two senders two receiversone router infinite buffers no retransmission
large delays when congestedmaximum achievable throughput
unlimited shared output link buffers
Host Aλin original data
Host B
λout
Transport Layer 3-73
Causescosts of congestion scenario 2
one router finite buffers sender retransmission of lost packet
finite shared output link buffers
Host A λin original data
Host B
λout
λin original data plus retransmitted data
Transport Layer 3-74
Causescosts of congestion scenario 2always (goodput)ldquoperfectrdquo retransmission only when loss
retransmission of delayed (not lost) packet makes larger(than perfect case) for same
λin
λout=
λin
λoutgtλ
inλout
ldquocostsrdquo of congestionmore work (retrans) for given ldquogoodputrdquounneeded retransmissions link carries multiple copies of pkt
R2
R2λin
λ out
b
R2
R2λin
λ out
a
R2
R2λin
λ out
c
R4
R3
Transport Layer 3-75
Causescosts of congestion scenario 3four sendersmultihop pathstimeoutretransmit
λin
Q what happens as and increase λ
in
finite shared output link buffers
Host Aλin original data
Host B
λout
λin original data plus retransmitted data
Transport Layer 3-76
Causescosts of congestion scenario 3
another ldquocostrdquo of congestionwhen packet dropped any ldquoupstream transmission capacity used for that packet was wasted
Host A
Host B
λou
t
Transport Layer 3-77
Approaches towards congestion control
End-end congestion controlno explicit feedback from networkcongestion inferred from end-system observed loss delayapproach taken by TCP
Network-assisted congestion controlrouters provide feedback to end systems
single bit indicating congestion (SNA DECbit TCPIP ECN ATM)explicit rate sender should send at
Two broad approaches towards congestion control
Transport Layer 3-78
TCP Congestion Control
end-end control (no network assistance)sender limits transmissionLastByteSent-LastByteAcked
le CongWin
CongWin is dynamic function of perceived network congestion
How does sender perceive congestionloss event = timeout or3 duplicate acksTCP sender reduces rate (CongWin) after loss event
two modes of operationSlow Start (SS)Congestion avoidance (CA) or Additive Increase Multiplicative Decrease (AIMD)
Transport Layer 3-79
TCP congestion control bandwidth probing
ldquoprobing for bandwidthrdquo increase transmission rate on receipt of ACK until eventually loss occurs then decrease transmission rate
continue to increase on ACK decrease on loss (since available bandwidth is changing depending on other connections in network)
ACKs being received so increase rate
X
X
XX
X loss so decrease rate
send
ing
rate
time
Q how fast to increasedecreasedetails to follow
TCPrsquosldquosawtoothrdquobehavior
Transport Layer 3-80
TCP Congestion Control details
sender limits rate by limiting number of unACKed bytes ldquoin pipelinerdquo
cwnd differs from rwnd (how why)sender limited by min(cwndrwnd)
roughly
cwnd is dynamic function of perceived network congestion
rate = cwndRTT bytessec
LastByteSent-LastByteAcked le cwnd
cwndbytes
RTT
ACK(s)
Transport Layer 3-81
TCP Congestion Control more details
segment loss event reducing cwndtimeout no response from receiver
cut cwnd to 13 duplicate ACKs at least some segments getting through (recall fast retransmit)
cut cwnd in half less aggressively than on timeout
ACK received increase cwndTwo modes of operation
slowstart phase bull increase exponentially
fast (despite name) at connection start or following timeout
congestion avoidance bull increase linearly
Transport Layer 3-82
TCP Slow Start Phasewhen connection begins cwnd = 1 MSS
example MSS = 500 bytes amp RTT = 200 msecinitial rate = 20 kbps
available bandwidth may be gtgt MSSRTT
desirable to quickly ramp up to respectable rate
increase rate exponentially until first loss event or when threshold reached
double cwnd every RTTdone by incrementing cwnd by 1 for every ACK received
Host A
one segment
RTT
Host B
time
two segments
four segments
Transport Layer 3-83
Slow Start ExampleThe congestion window size grows very rapidly
For every ACK we increase CongWin by 1 irrespective of the number of segments ACKrsquoeddouble CongWinevery RTTinitial rate is slow but ramps up exponentially fast
TCP slows down the increase of CongWinwhen CongWin gt ssthresh
segment 1
ACK for segment 1
cwnd = 1
cwnd = 2 segment 2segment 3
ACK for segments 2
cwnd = 4 segment 4segment 5segment 6
ACK for segments 4
cwnd = 7
ACK for segments 3
ACK for segments 5
ACK for segments 6
cwnd = 3
cwnd = 5
cwnd = 6ACK for segments 7
cwnd = 8
segment 7
Transport Layer 3-84
TCP Congestion Avoidance Phase
when cwnd gt ssthreshgrow cwnd linearly
increase cwnd by 1 MSS per RTT approach possible congestion slower than in slowstartimplementation cwnd= cwnd + MSScwndfor each ACK received
ACKs increase cwndby 1 MSS per RTT additive increaseloss cut cwnd in half (non-timeout-detected loss ) multiplicative decrease
AIMD
AIMD Additive IncreaseMultiplicative Decrease
Transport Layer 3-85
Congestion AvoidanceCongestion avoidance phase is started if CongWin has reached the slow-start threshold value
If CongWin gt= ssthresh then each time an ACK is received increment CongWin as follows
bull CongWin = CongWin + 1CongWin (CongWin in segments)
bull In actual TCP implementation CongWin is in BytesCongWin = CongWin + MSS (MSSCongWin)
So CongWin is increased by one only if all CongWinsegments have been acknowledged
Transport Layer 3-86
Example Slow StartCongestion AvoidanceAssume that
ssthresh = 8
cwnd = 1
cwnd = 2
cwnd = 4
cwnd = 8
cwnd = 9
cwnd = 10
02468
101214
t=0
t=2
t=4
t=6
Roundtrip times
Cw
nd(in
seg
men
ts)
ssthresh
cwnd = 3
cwnd = 5cwnd = 6cwnd = 7
Transport Layer 3-87
Slow Start Congestion AvoidanceA typical plot of CongWin for a TCP connection
(MSS = 1500 bytes) with TCP Tahoe
SS
CA
ssthresh
Transport Layer 3-88
Responses to CongestionTCP assumes there is congestion if it detects a packet lossA TCP sender can detect lost packets via loss events
bull Timeout of a retransmission timerbull Receipt of 3 duplicate ACKs (fast retransmit)
TCP interprets a Timeout as a binary congestion signal When a timeout occurs the sender performs
ssthresh is set to half the current size of the congestion window
ssthresh = CongWin 2CongWin is reset to one
CongWin = 1and slow-start is entered
Transport Layer 3-89
Fast Recovery (differentiation btwn two loss events) After 3 dup ACKs (fast Retransmit)
ssthresh = CongWin2CongWin = CongWin2window then grows linearly
But after timeout eventCongWin = 1 MSS window then grows exponentiallyto the threshold then grows linearly
bull 3 dup ACKs indicates network capable of delivering some segmentsbull timeout before 3 dup ACKs is ldquomore alarmingrdquo
Philosophy
3-90
TCP Congestion ControlInitially
CongWin = 1ssthresh = advertised window size
New Ack receivedif (CongWin lt ssthresh) Slow Start
CongWin = CongWin + 1else Congestion Avoidance
CongWin = CongWin + 1CongWinTimeout
ssthresh = CongWin2CongWin = 1
Fast Retransmissionssthresh = CongWin2CongWin = CongWin2
Slow Start (exponential increase phase) is continued until CongWin reaches half of the level where the loss event occurred last time CongWin is increased slowly after (linear increase in Congestion Avoidance phase)
Transport Layer 3-91
Popular ldquoflavorsrdquo of TCP
ssthresh
ssthresh
TCP Tahoe
TCP Reno
Transmission round
cwnd
win
dow
siz
e (in
seg
men
ts)
Transport Layer 3-92
Summary TCP Congestion ControlWhen CongWin is below Threshold sender in slow-start phase window grows exponentiallyWhen CongWin is above Threshold sender is in congestion-avoidance phase window grows linearlyWhen a triple duplicate ACK occurs Threshold set to CongWin2 and CongWin set to ThresholdWhen timeout occurs Threshold set to CongWin2 and CongWin is set to 1 MSS The actual sender window size is determined based on the congestion and flow control algorithms
SenderWin=min(RcvWinCongWin)
Transport Layer 3-93
TCP Congestion Control SummaryEvent State TCP Sender Action Commentary
ACK receipt for previously unackeddata
Slow Start (SS)
CongWin = CongWin + MSS If (CongWin gt Threshold)
set state to ldquoCongestion Avoidancerdquo
Resulting in a doubling of CongWin every RTT
ACK receipt for previously unackeddata
CongestionAvoidance (CA)
CongWin = CongWin+MSS (MSSCongWin)
Additive increase resulting in increase of CongWin by 1 MSS every RTT
Loss event detected by triple duplicate ACK
SS or CA Threshold = CongWin2 CongWin = ThresholdSet state to ldquoCongestion Avoidancerdquo
Fast recovery implementing multiplicative decrease CongWin will not drop below 1 MSS
Timeout SS or CA Threshold = CongWin2 CongWin = 1 MSSSet state to ldquoSlow Startrdquo
Enter slow start
Duplicate ACK
SS or CA Increment duplicate ACK count for segment being acked
CongWin and Threshold not changed
Transport Layer 3-94
TCP throughput
Q whatrsquos average throughout of TCP as function of window size RTT
ignoring slow startlet W be window size when loss occurs
when window is W throughput is WRTTjust after loss window drops to W2 throughput to W2RTT average throughout 75 WRTT
Transport Layer 3-95
TCP Futures TCP over ldquolong fat pipesrdquo
example 1500 byte segments 100ms RTT want 10 Gbps throughputrequires window size W = 83333 in-flight segmentsthroughput in terms of loss rate
L = 210-10 Wownew versions of TCP for high-speed
LRTTMSSsdot221
Transport Layer 3-96
Fairness goal if K TCP sessions share same bottleneck link of bandwidth R each should have average rate of RK
TCP connection 1
bottleneckrouter
capacity R
TCP connection 2
TCP Fairness
Transport Layer 3-97
Why is TCP fairTwo competing sessions
Additive increase gives slope of 1 as throughout increasesmultiplicative decrease decreases throughput proportionally
R
R
equal bandwidth share
Connection 1 throughput
Conn
ecti
on 2
thr
ough
p ut
congestion avoidance additive increaseloss decrease window by factor of 2
congestion avoidance additive increaseloss decrease window by factor of 2
Transport Layer 3-98
Fairness (more)Fairness and UDP
Multimedia apps often do not use TCP
do not want rate throttled by congestion control
Instead use UDPpump audiovideo at constant rate tolerate packet loss
Research area TCP friendly
Fairness and parallel TCP connectionsnothing prevents app from opening parallel cnctionsbetween 2 hostsWeb browsers do this Example link of rate R supporting 9 cnctions
new app asks for 1 TCP gets rate R10new app asks for 11 TCPs gets R2
Transport Layer 3-99
TCP Connection ManagementRecall TCP sender receiver
establish ldquoconnectionrdquobefore exchanging data segmentsinitialize TCP variables
seq sbuffers flow control info (eg RcvWindow)
client connection initiatorSocket clientSocket = new Socket(hostnameport
number)
server contacted by clientSocket connectionSocket = welcomeSocketaccept()
Three way handshakeStep 1 client host sends TCP
SYN segment to serverspecifies initial seq no data
Step 2 server host receives SYN replies with SYNACK segment
server allocates buffersspecifies server initial seq
Step 3 client receives SYNACK replies with ACK segment which may contain data
Transport Layer 3-100
TCP Connection Management (cont)
Closing a connection
client closes socketclientSocketclose()
Step 1 client end system sends TCP FIN control segment to server
Step 2 server receives FIN replies with ACK Closes connection sends FIN
client
FIN
server
ACK
ACK
FIN
close
close
closed
tim
ed w
ait
Transport Layer 3-101
TCP Connection Management (cont)
Step 3 client receives FIN replies with ACK
Enters ldquotimed waitrdquo -will respond with ACK to received FINs
Step 4 server receives ACK Connection closed
client
FIN
server
ACK
ACK
FIN
closing
closing
closed
tim
ed w
ait
closed
Transport Layer 3-102
TCP Connection Management (cont)
TCP clientlifecycle
TCP serverlifecycle
Transport Layer 3-103
Tuning TCPIP Parameters TCPIP parameters
A set of default values may not be optimal for all applicationsThe network administrator may wish to turn on or off some TCPIP functions for performance or security considerations
Many Unix and Linux systems provide some flexibility in tuning the TCPIP kernelsbinsysctl is used to configure the Linux kernel parameters at runtime
Default kernel configuration file is sbinsysctlconfFrequently used sysctl options
bull sysctl ndasha or sysctl ndashA list all current valuesbull sysctl ndashp file_name load the sysctl setting from a configuration
filebull sysctl ndashw variable=value change the value of the parameter
Transport Layer 3-104
SomeTCP Parameters in Linux Kerneltcp_syn_retries
Number of SYN packets the kernel will send before giving up on the new connection
tcp_synack_retriesnumber of SYN+ACK packets sent before the kernel gives up on the connection
tcp_window_scalingMaximum window size of 65535 bytes not enough for for really fast networks The window scaling options allows for almost gigabyte windows which is good for connections with large delay-bandwidth product
tcp_max_syn_backlogMaximal number of remembered connection requests which still did not receive an acknowledgment from connecting client
tcp_fin_timeoutHow many seconds to wait for a final FIN packet before the socket is closed required to prevent denial-of-service (DoS) attacks Default value is 60 seconds
Transport Layer 3-105
SomeTCP Parameters in Linux Kerneltcp_rmem
This is a vector of 3 integers [min default max] These parameters are used by TCP to dynamically adjust receive buffer sizesmin - minimum size of the receive buffer used by each TCP socket The default value is 4K default - the default size of the receive buffer for a TCP socket The default value is 87380 bytes and is lowered to 43689 in low memory systems If larger receive buffer sizes are desired this value should be increased max - the maximum size of the receive buffer used by each TCP socket The default value of 873802 bytes is lowered to 87380 in low memory systems
tcp_smemSend buffer parameters [min default max] similar to tcp_rmem
- Chapter 3 Transport Layer
- Transport services and protocols
- Transport vs network layer
- Internet transport-layer protocols
- Multiplexingdemultiplexing
- How demultiplexing works
- Connectionless demultiplexing
- Connection-oriented demux
- Connection-oriented demux (cont)
- Connection-oriented demux Threaded Web Server
- UDP User Datagram Protocol [RFC 768]
- UDP more
- UDP checksum
- Principles of Reliable data transfer
- Reliable data transfer getting started
- Reliable data transfer getting started
- Rdt10 reliable transfer over a reliable channel
- Rdt20 channel with bit errors
- rdt20 FSM specification
- rdt20 operation with no errors
- rdt20 error scenario
- rdt20 has a fatal flaw
- rdt21 sender handles garbled ACKNAKs
- rdt21 receiver handles garbled ACKNAKs
- rdt21 discussion
- rdt22 a NAK-free protocol
- rdt22 sender receiver fragments
- rdt30 channels with errors and loss
- rdt30 sender
- rdt30 in action
- rdt30 in action
- Performance of rdt30
- rdt30 stop-and-wait operation
- Pipelined protocols
- Pipelining increased utilization
- Go-Back-N
- GBN sender extended FSM
- GBN receiver extended FSM
- GBN inaction
- Selective Repeat
- Selective repeat sender receiver windows
- Selective repeat
- Selective repeat in action
- Selective repeat dilemma
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- TCP Overview RFCs 793 1122 1323 2018 2581
- TCP segment structure
- TCP seq rsquos and ACKs
- TCP Round Trip Time and Timeout
- TCP Round Trip Time and Timeout
- Example RTT estimation
- TCP Round Trip Time and Timeout
- TCP reliable data transfer
- TCP sender events
- TCP sender(simplified)
- TCP retransmission scenarios
- TCP retransmission scenarios (more)
- TCP ACK generation [RFC 1122 RFC 2581]
- Fast Retransmit
- Fast Retransmit
- Fast retransmit algorithm
- TCP Flow Control
- TCP Flow control how it works
- Sliding Window Flow Control Example
- Principles of Congestion Control
- Causescosts of congestion scenario 1
- Causescosts of congestion scenario 2
- Causescosts of congestion scenario 2
- Causescosts of congestion scenario 3
- Causescosts of congestion scenario 3
- Approaches towards congestion control
- TCP Congestion Control
- TCP congestion control bandwidth probing
- TCP Congestion Control details
- TCP Congestion Control more details
- TCP Slow Start Phase
- Slow Start Example
- TCP Congestion Avoidance Phase
- Congestion Avoidance
- Example Slow StartCongestion Avoidance
- Slow Start Congestion Avoidance
- Responses to Congestion
- Fast Recovery (differentiation btwn two loss events)
- TCP Congestion Control
- Popular ldquoflavorsrdquo of TCP
- Summary TCP Congestion Control
- TCP Congestion Control Summary
- TCP throughput
- TCP Futures TCP over ldquolong fat pipesrdquo
- TCP Fairness
- Why is TCP fair
- Fairness (more)
- TCP Connection Management
- TCP Connection Management (cont)
- TCP Connection Management (cont)
- TCP Connection Management (cont)
- Tuning TCPIP Parameters
- SomeTCP Parameters in Linux Kernel
- SomeTCP Parameters in Linux Kernel
-
Transport Layer 3-46
Sequence Number vs Window SizeSuppose we use k bits to represent SNQuestion Whatrsquos the minimum number of bits k necessary for a window size of N
sender
receiver
Go-Back-N
expectedSN
snd_base=expectedSN
Q For a given expectedSN whatrsquos the largest possible value for snd_baseA If all the last N ACKs sent by the receiver are received
snd_base = expectedSNexpectedSN+N-1
senderrsquos window
Transport Layer 3-47
Sequence Number vs Window SizeSuppose we use k bits to represent SNQuestion Whatrsquos the minimum number of bits k necessary for a window size of N
sender
receiver
Go-Back-N
expectedSN
snd_base=expectedSN-N
Q For a given expectedSN whatrsquos the smallest possible value for snd_baseA If all the last N ACKs sent by the receiver are not received
snd_base = expectedSN-NexpectedSN-1
senderrsquos window
Transport Layer 3-48
Sequence Number vs Window Size
sender
receiver
Go-Back-N
expectedSN
snd_base=expectedSN-N
All SNs in the interval [expectedSN-NexpectedSN+N-1] (an interval of size 2N) can be received by the receiver Since the receiver accepts on the packet with SN=expectedSN there should be no other packet within this interval with SN=expectedSN Therefore
2k ge N+1expectedSN+N-1
Transport Layer 3-49
Sequence Number vs Window SizeSuppose we use k bits to represent SNQuestion Whatrsquos the minimum number of bits k necessary for a window size of N
sender
receiver
Selective Repeat
rcv_base
snd_base=rcv_base
Q For a given rcv_base whatrsquos the largest possible value for snd_baseA If all the last N ACKs sent by the receiver are received
snd_base = rcv_base (same as go_back-N)rcv_base+N-1
senderrsquos window
receiverrsquos window
rcv_base+N-1
Transport Layer 3-50
Sequence Number vs Window SizeSuppose we use k bits to represent SNQuestion Whatrsquos the minimum number of bits k necessary for a window size of N
sender
receiver
Selective Repeat
rcv_base
snd_base=rcv_base-N
Q For a given rcv_base whatrsquos the smallest possible value for snd_baseA If all the last N ACKs sent by the receiver are not received
snd_base = rcv_base-N (same as Go-Back-N)rcv_base-1
senderrsquos window
rcv_base
receiverrsquos window
rcv_base+N-1
Transport Layer 3-51
Sequence Number vs Window Size
sender
receiver
Selective Repeat
snd_base=rcv_base-N
All SNs in the interval [rcv_base-Nrcv_base+N-1] (an interval of size 2N) can be received by the receiver Since the receiver should be able to distinguish between all packets in this interval and take corresponding action there should be no two packets within thisinterval having the same SN Therefore
2k ge 2Nrcv_base+N-1
rcv_basercv_base
receiverrsquos window
rcv_base+N-1
Transport Layer 3-52
TCP Overview RFCs 793 1122 1323 2018 2581
full duplex databi-directional data flow in same connectionMSS maximum segment size
connection-orientedhandshaking (exchange of control msgs) initrsquossender receiver state before data exchange
flow controlledsender will not overwhelm receiver
point-to-pointone sender one receiver
reliable in-order byte stream
no ldquomessage boundariesrdquopipelined
TCP congestion and flow control set window size
send amp receive buffers
socketdoor
TCPsend buffer
TCPreceive buffer
socketdoor
segment
applicationwrites data
applicationreads data
Transport Layer 3-53
TCP segment structure
source port dest port
32 bits
applicationdata
(variable length)
sequence numberacknowledgement number
Receive windowUrg data pnterchecksum
FSRPAUheadlen
notused
Options (variable length)
URG urgent data (generally not used)
ACK ACK valid
PSH push data now(generally not used)
RST SYN FINconnection estab(setup teardown
commands)
bytes rcvr willingto accept
Internetchecksum
(as in UDP)
countingby bytes of data(not segments)
Transport Layer 3-54
TCP seq rsquos and ACKsSeq rsquos
byte stream ldquonumberrdquo of first byte in segmentrsquos dataACKs
seq of next byte expected from other sidecumulative ACK
Q how receiver handles out-of-order segmentsA TCP spec doesnrsquot say - up to implementationWidely used implementations of TCP buffer out-of-order segments
Transport Layer 3-55
TCP Round Trip Time and Timeout
Q how to set TCP timeout valuelonger than RTT
but RTT variestoo short premature timeout
unnecessary retransmissions
too long slow reaction to segment loss
Q how to estimate RTTSampleRTT measured time from segment transmission until ACK receipt
ignore retransmissionsSampleRTT will vary want estimated RTT ldquosmootherrdquo
average several recent measurements not just current SampleRTT
Transport Layer 3-56
TCP Round Trip Time and Timeout
EstimatedRTT = (1- α)EstimatedRTT + αSampleRTT
Exponential weighted moving averageinfluence of past sample decreases exponentially fasttypical value α = 0125
Transport Layer 3-57
Example RTT estimationRTT gaiacsumassedu to fantasiaeurecomfr
100
150
200
250
300
350
1 8 15 22 29 36 43 50 57 64 71 78 85 92 99 106
time (seconnds)
RTT
(mill
iseco
nds)
SampleRTT Estimated RTT
Transport Layer 3-58
TCP Round Trip Time and TimeoutSetting the timeout
EstimatedRTT plus ldquosafety marginrdquolarge variation in EstimatedRTT -gt larger safety margin
first estimate of how much SampleRTT deviates from EstimatedRTT
TimeoutInterval = EstimatedRTT + 4DevRTT
DevRTT = (1-β)DevRTT +β|SampleRTT-EstimatedRTT|
(typically β = 025)
Then set timeout interval
Transport Layer 3-59
TCP reliable data transfer
TCP creates rdtservice on top of IPrsquos unreliable servicePipelined segmentsCumulative acksTCP uses single retransmission timer however it just retransmits the first segment in the window
Retransmissions are triggered by
timeout eventsduplicate acks
Initially consider simplified TCP sender
ignore duplicate acksignore flow control congestion control
Transport Layer 3-60
TCP sender eventsdata rcvd from app
Create segment with seq seq is byte-stream number of first data byte in segmentstart timer if not already running (think of timer as for oldest unacked segment)expiration interval TimeOutInterval
timeoutretransmit segment that caused timeout (first segment in the window)restart timer
Ack rcvdIf acknowledges previously unacked segments
update what is known to be ackedstart timer if there are outstanding segments
Transport Layer 3-61
TCP sender(simplified)
NextSeqNum = InitialSeqNumSendBase = InitialSeqNum
loop (forever) switch(event)
event data received from application above create TCP segment with sequence number NextSeqNumif (timer currently not running)
start timerpass segment to IP NextSeqNum = NextSeqNum + length(data)
event timer timeoutretransmit not-yet-acknowledged segment with
smallest sequence numberstart timer
event ACK received with ACK field value of y if (y gt SendBase)
SendBase = yif (there are currently not-yet-acknowledged segments)
start timer
end of loop forever
Commentbull SendBase-1 last cumulatively ackrsquoed byteExamplebull SendBase-1 = 71y= 73 so the rcvrwants 73+ y gt SendBase sothat new data is acked
Transport Layer 3-62
TCP retransmission scenariosHost A
Seq=100 20 bytes data
ACK=100
timepremature timeout
Host B
Seq=92 8 bytes data
ACK=120
Seq=92 8 bytes data
Seq=
92 t
imeo
ut
ACK=120
Host A
Seq=92 8 bytes data
ACK=100
loss
tim
eout
lost ACK scenario
Host B
X
Seq=92 8 bytes data
ACK=100
time
Seq=
92 t
imeo
utSendBase
= 100
SendBase= 120
SendBase= 120
Sendbase= 100
Transport Layer 3-63
TCP retransmission scenarios (more)Host A
Seq=92 8 bytes data
ACK=100
loss
tim
eout
Cumulative ACK scenario
Host B
X
Seq=100 20 bytes data
ACK=120
time
SendBase= 120
Transport Layer 3-64
TCP ACK generation [RFC 1122 RFC 2581]
Event at Receiver
Arrival of in-order segment withexpected seq All data up toexpected seq already ACKed
Arrival of in-order segment withexpected seq One other segment has ACK pending
Arrival of out-of-order segmenthigher-than-expect seq Gap detected
Arrival of segment that partially or completely fills gap
TCP Receiver action
Delayed ACK Wait up to 500msfor next segment If no next segmentsend ACK
Immediately send single cumulative ACK ACKing both in-order segments
Immediately send duplicate ACK indicating seq of next expected byte
Immediate send ACK provided thatsegment startsat lower end of gap
Transport Layer 3-65
Fast Retransmit
Time-out period often relatively long
long delay before resending lost packet
Detect lost segments via duplicate ACKs
Sender often sends many segments back-to-backIf segment is lost there will likely be many duplicate ACKs
If sender receives 3 ACKs for the same data it supposes that segment after ACKeddata was lost
fast retransmit resend segment before timer expires
Transport Layer 3-66
Fast RetransmitResend a segment after 3 duplicate ACKs since a duplicate ACK means that an out-of sequence segment was receivedduplicate ACKs due to packet reorderingif window is small donrsquot get duplicate ACKs
Host A
tim
eout
Host B
time
X
resend seq X2
seq x1seq x2seq x3seq x4seq x5
ACK x1
ACK x1ACK x1ACK x1
tripleduplicate
ACKs
Transport Layer 3-67
event ACK received with ACK field value of y if (y gt SendBase)
SendBase = yif (there are currently not-yet-acknowledged segments)
start timer
else increment count of dup ACKs received for yif (count of dup ACKs received for y = 3)
resend segment with sequence number y
Fast retransmit algorithm
a duplicate ACK for already ACKed segment
fast retransmit
Transport Layer 3-68
TCP Flow Control
receive side of TCP connection has a receive buffer
speed-matching service matching the send rate to the receiving apprsquos drain rate
app process may be slow at reading from buffer
sender wonrsquot overflowreceiverrsquos buffer by
transmitting too muchtoo fast
flow control
Transport Layer 3-69
TCP Flow control how it works
(Suppose TCP receiver discards out-of-order segments)spare room in buffer
= RcvWin
= RcvBuffer-[LastByteRcvd -LastByteRead]
Rcvr advertises spare room by including value of RcvWin in segmentsSender limits unACKeddata to RcvWin
guarantees receive buffer doesnrsquot overflow
Transport Layer 3-70
Sliding Window Flow Control Example
3K
2K SeqNo=0
ReceiverBuffer
0 4KSendersends 2Kof data
2K
AckNo=2048 RcvWin=2048Sendersends 2Kof data 2K SeqNo=2048
4K
AckNo=4096 RcvWin=0
AckNo=4096 RcvWin=1024
Sender blocked
Transport Layer 3-71
Principles of Congestion Control
Congestioninformally ldquotoo many sources sending too much data too fast for network to handlerdquodifferent from flow controlmanifestations
lost packets (buffer overflow at routers)long delays (queueing in router buffers)
a top-10 problem
Transport Layer 3-72
Causescosts of congestion scenario 1
two senders two receiversone router infinite buffers no retransmission
large delays when congestedmaximum achievable throughput
unlimited shared output link buffers
Host Aλin original data
Host B
λout
Transport Layer 3-73
Causescosts of congestion scenario 2
one router finite buffers sender retransmission of lost packet
finite shared output link buffers
Host A λin original data
Host B
λout
λin original data plus retransmitted data
Transport Layer 3-74
Causescosts of congestion scenario 2always (goodput)ldquoperfectrdquo retransmission only when loss
retransmission of delayed (not lost) packet makes larger(than perfect case) for same
λin
λout=
λin
λoutgtλ
inλout
ldquocostsrdquo of congestionmore work (retrans) for given ldquogoodputrdquounneeded retransmissions link carries multiple copies of pkt
R2
R2λin
λ out
b
R2
R2λin
λ out
a
R2
R2λin
λ out
c
R4
R3
Transport Layer 3-75
Causescosts of congestion scenario 3four sendersmultihop pathstimeoutretransmit
λin
Q what happens as and increase λ
in
finite shared output link buffers
Host Aλin original data
Host B
λout
λin original data plus retransmitted data
Transport Layer 3-76
Causescosts of congestion scenario 3
another ldquocostrdquo of congestionwhen packet dropped any ldquoupstream transmission capacity used for that packet was wasted
Host A
Host B
λou
t
Transport Layer 3-77
Approaches towards congestion control
End-end congestion controlno explicit feedback from networkcongestion inferred from end-system observed loss delayapproach taken by TCP
Network-assisted congestion controlrouters provide feedback to end systems
single bit indicating congestion (SNA DECbit TCPIP ECN ATM)explicit rate sender should send at
Two broad approaches towards congestion control
Transport Layer 3-78
TCP Congestion Control
end-end control (no network assistance)sender limits transmissionLastByteSent-LastByteAcked
le CongWin
CongWin is dynamic function of perceived network congestion
How does sender perceive congestionloss event = timeout or3 duplicate acksTCP sender reduces rate (CongWin) after loss event
two modes of operationSlow Start (SS)Congestion avoidance (CA) or Additive Increase Multiplicative Decrease (AIMD)
Transport Layer 3-79
TCP congestion control bandwidth probing
ldquoprobing for bandwidthrdquo increase transmission rate on receipt of ACK until eventually loss occurs then decrease transmission rate
continue to increase on ACK decrease on loss (since available bandwidth is changing depending on other connections in network)
ACKs being received so increase rate
X
X
XX
X loss so decrease rate
send
ing
rate
time
Q how fast to increasedecreasedetails to follow
TCPrsquosldquosawtoothrdquobehavior
Transport Layer 3-80
TCP Congestion Control details
sender limits rate by limiting number of unACKed bytes ldquoin pipelinerdquo
cwnd differs from rwnd (how why)sender limited by min(cwndrwnd)
roughly
cwnd is dynamic function of perceived network congestion
rate = cwndRTT bytessec
LastByteSent-LastByteAcked le cwnd
cwndbytes
RTT
ACK(s)
Transport Layer 3-81
TCP Congestion Control more details
segment loss event reducing cwndtimeout no response from receiver
cut cwnd to 13 duplicate ACKs at least some segments getting through (recall fast retransmit)
cut cwnd in half less aggressively than on timeout
ACK received increase cwndTwo modes of operation
slowstart phase bull increase exponentially
fast (despite name) at connection start or following timeout
congestion avoidance bull increase linearly
Transport Layer 3-82
TCP Slow Start Phasewhen connection begins cwnd = 1 MSS
example MSS = 500 bytes amp RTT = 200 msecinitial rate = 20 kbps
available bandwidth may be gtgt MSSRTT
desirable to quickly ramp up to respectable rate
increase rate exponentially until first loss event or when threshold reached
double cwnd every RTTdone by incrementing cwnd by 1 for every ACK received
Host A
one segment
RTT
Host B
time
two segments
four segments
Transport Layer 3-83
Slow Start ExampleThe congestion window size grows very rapidly
For every ACK we increase CongWin by 1 irrespective of the number of segments ACKrsquoeddouble CongWinevery RTTinitial rate is slow but ramps up exponentially fast
TCP slows down the increase of CongWinwhen CongWin gt ssthresh
segment 1
ACK for segment 1
cwnd = 1
cwnd = 2 segment 2segment 3
ACK for segments 2
cwnd = 4 segment 4segment 5segment 6
ACK for segments 4
cwnd = 7
ACK for segments 3
ACK for segments 5
ACK for segments 6
cwnd = 3
cwnd = 5
cwnd = 6ACK for segments 7
cwnd = 8
segment 7
Transport Layer 3-84
TCP Congestion Avoidance Phase
when cwnd gt ssthreshgrow cwnd linearly
increase cwnd by 1 MSS per RTT approach possible congestion slower than in slowstartimplementation cwnd= cwnd + MSScwndfor each ACK received
ACKs increase cwndby 1 MSS per RTT additive increaseloss cut cwnd in half (non-timeout-detected loss ) multiplicative decrease
AIMD
AIMD Additive IncreaseMultiplicative Decrease
Transport Layer 3-85
Congestion AvoidanceCongestion avoidance phase is started if CongWin has reached the slow-start threshold value
If CongWin gt= ssthresh then each time an ACK is received increment CongWin as follows
bull CongWin = CongWin + 1CongWin (CongWin in segments)
bull In actual TCP implementation CongWin is in BytesCongWin = CongWin + MSS (MSSCongWin)
So CongWin is increased by one only if all CongWinsegments have been acknowledged
Transport Layer 3-86
Example Slow StartCongestion AvoidanceAssume that
ssthresh = 8
cwnd = 1
cwnd = 2
cwnd = 4
cwnd = 8
cwnd = 9
cwnd = 10
02468
101214
t=0
t=2
t=4
t=6
Roundtrip times
Cw
nd(in
seg
men
ts)
ssthresh
cwnd = 3
cwnd = 5cwnd = 6cwnd = 7
Transport Layer 3-87
Slow Start Congestion AvoidanceA typical plot of CongWin for a TCP connection
(MSS = 1500 bytes) with TCP Tahoe
SS
CA
ssthresh
Transport Layer 3-88
Responses to CongestionTCP assumes there is congestion if it detects a packet lossA TCP sender can detect lost packets via loss events
bull Timeout of a retransmission timerbull Receipt of 3 duplicate ACKs (fast retransmit)
TCP interprets a Timeout as a binary congestion signal When a timeout occurs the sender performs
ssthresh is set to half the current size of the congestion window
ssthresh = CongWin 2CongWin is reset to one
CongWin = 1and slow-start is entered
Transport Layer 3-89
Fast Recovery (differentiation btwn two loss events) After 3 dup ACKs (fast Retransmit)
ssthresh = CongWin2CongWin = CongWin2window then grows linearly
But after timeout eventCongWin = 1 MSS window then grows exponentiallyto the threshold then grows linearly
bull 3 dup ACKs indicates network capable of delivering some segmentsbull timeout before 3 dup ACKs is ldquomore alarmingrdquo
Philosophy
3-90
TCP Congestion ControlInitially
CongWin = 1ssthresh = advertised window size
New Ack receivedif (CongWin lt ssthresh) Slow Start
CongWin = CongWin + 1else Congestion Avoidance
CongWin = CongWin + 1CongWinTimeout
ssthresh = CongWin2CongWin = 1
Fast Retransmissionssthresh = CongWin2CongWin = CongWin2
Slow Start (exponential increase phase) is continued until CongWin reaches half of the level where the loss event occurred last time CongWin is increased slowly after (linear increase in Congestion Avoidance phase)
Transport Layer 3-91
Popular ldquoflavorsrdquo of TCP
ssthresh
ssthresh
TCP Tahoe
TCP Reno
Transmission round
cwnd
win
dow
siz
e (in
seg
men
ts)
Transport Layer 3-92
Summary TCP Congestion ControlWhen CongWin is below Threshold sender in slow-start phase window grows exponentiallyWhen CongWin is above Threshold sender is in congestion-avoidance phase window grows linearlyWhen a triple duplicate ACK occurs Threshold set to CongWin2 and CongWin set to ThresholdWhen timeout occurs Threshold set to CongWin2 and CongWin is set to 1 MSS The actual sender window size is determined based on the congestion and flow control algorithms
SenderWin=min(RcvWinCongWin)
Transport Layer 3-93
TCP Congestion Control SummaryEvent State TCP Sender Action Commentary
ACK receipt for previously unackeddata
Slow Start (SS)
CongWin = CongWin + MSS If (CongWin gt Threshold)
set state to ldquoCongestion Avoidancerdquo
Resulting in a doubling of CongWin every RTT
ACK receipt for previously unackeddata
CongestionAvoidance (CA)
CongWin = CongWin+MSS (MSSCongWin)
Additive increase resulting in increase of CongWin by 1 MSS every RTT
Loss event detected by triple duplicate ACK
SS or CA Threshold = CongWin2 CongWin = ThresholdSet state to ldquoCongestion Avoidancerdquo
Fast recovery implementing multiplicative decrease CongWin will not drop below 1 MSS
Timeout SS or CA Threshold = CongWin2 CongWin = 1 MSSSet state to ldquoSlow Startrdquo
Enter slow start
Duplicate ACK
SS or CA Increment duplicate ACK count for segment being acked
CongWin and Threshold not changed
Transport Layer 3-94
TCP throughput
Q whatrsquos average throughout of TCP as function of window size RTT
ignoring slow startlet W be window size when loss occurs
when window is W throughput is WRTTjust after loss window drops to W2 throughput to W2RTT average throughout 75 WRTT
Transport Layer 3-95
TCP Futures TCP over ldquolong fat pipesrdquo
example 1500 byte segments 100ms RTT want 10 Gbps throughputrequires window size W = 83333 in-flight segmentsthroughput in terms of loss rate
L = 210-10 Wownew versions of TCP for high-speed
LRTTMSSsdot221
Transport Layer 3-96
Fairness goal if K TCP sessions share same bottleneck link of bandwidth R each should have average rate of RK
TCP connection 1
bottleneckrouter
capacity R
TCP connection 2
TCP Fairness
Transport Layer 3-97
Why is TCP fairTwo competing sessions
Additive increase gives slope of 1 as throughout increasesmultiplicative decrease decreases throughput proportionally
R
R
equal bandwidth share
Connection 1 throughput
Conn
ecti
on 2
thr
ough
p ut
congestion avoidance additive increaseloss decrease window by factor of 2
congestion avoidance additive increaseloss decrease window by factor of 2
Transport Layer 3-98
Fairness (more)Fairness and UDP
Multimedia apps often do not use TCP
do not want rate throttled by congestion control
Instead use UDPpump audiovideo at constant rate tolerate packet loss
Research area TCP friendly
Fairness and parallel TCP connectionsnothing prevents app from opening parallel cnctionsbetween 2 hostsWeb browsers do this Example link of rate R supporting 9 cnctions
new app asks for 1 TCP gets rate R10new app asks for 11 TCPs gets R2
Transport Layer 3-99
TCP Connection ManagementRecall TCP sender receiver
establish ldquoconnectionrdquobefore exchanging data segmentsinitialize TCP variables
seq sbuffers flow control info (eg RcvWindow)
client connection initiatorSocket clientSocket = new Socket(hostnameport
number)
server contacted by clientSocket connectionSocket = welcomeSocketaccept()
Three way handshakeStep 1 client host sends TCP
SYN segment to serverspecifies initial seq no data
Step 2 server host receives SYN replies with SYNACK segment
server allocates buffersspecifies server initial seq
Step 3 client receives SYNACK replies with ACK segment which may contain data
Transport Layer 3-100
TCP Connection Management (cont)
Closing a connection
client closes socketclientSocketclose()
Step 1 client end system sends TCP FIN control segment to server
Step 2 server receives FIN replies with ACK Closes connection sends FIN
client
FIN
server
ACK
ACK
FIN
close
close
closed
tim
ed w
ait
Transport Layer 3-101
TCP Connection Management (cont)
Step 3 client receives FIN replies with ACK
Enters ldquotimed waitrdquo -will respond with ACK to received FINs
Step 4 server receives ACK Connection closed
client
FIN
server
ACK
ACK
FIN
closing
closing
closed
tim
ed w
ait
closed
Transport Layer 3-102
TCP Connection Management (cont)
TCP clientlifecycle
TCP serverlifecycle
Transport Layer 3-103
Tuning TCPIP Parameters TCPIP parameters
A set of default values may not be optimal for all applicationsThe network administrator may wish to turn on or off some TCPIP functions for performance or security considerations
Many Unix and Linux systems provide some flexibility in tuning the TCPIP kernelsbinsysctl is used to configure the Linux kernel parameters at runtime
Default kernel configuration file is sbinsysctlconfFrequently used sysctl options
bull sysctl ndasha or sysctl ndashA list all current valuesbull sysctl ndashp file_name load the sysctl setting from a configuration
filebull sysctl ndashw variable=value change the value of the parameter
Transport Layer 3-104
SomeTCP Parameters in Linux Kerneltcp_syn_retries
Number of SYN packets the kernel will send before giving up on the new connection
tcp_synack_retriesnumber of SYN+ACK packets sent before the kernel gives up on the connection
tcp_window_scalingMaximum window size of 65535 bytes not enough for for really fast networks The window scaling options allows for almost gigabyte windows which is good for connections with large delay-bandwidth product
tcp_max_syn_backlogMaximal number of remembered connection requests which still did not receive an acknowledgment from connecting client
tcp_fin_timeoutHow many seconds to wait for a final FIN packet before the socket is closed required to prevent denial-of-service (DoS) attacks Default value is 60 seconds
Transport Layer 3-105
SomeTCP Parameters in Linux Kerneltcp_rmem
This is a vector of 3 integers [min default max] These parameters are used by TCP to dynamically adjust receive buffer sizesmin - minimum size of the receive buffer used by each TCP socket The default value is 4K default - the default size of the receive buffer for a TCP socket The default value is 87380 bytes and is lowered to 43689 in low memory systems If larger receive buffer sizes are desired this value should be increased max - the maximum size of the receive buffer used by each TCP socket The default value of 873802 bytes is lowered to 87380 in low memory systems
tcp_smemSend buffer parameters [min default max] similar to tcp_rmem
- Chapter 3 Transport Layer
- Transport services and protocols
- Transport vs network layer
- Internet transport-layer protocols
- Multiplexingdemultiplexing
- How demultiplexing works
- Connectionless demultiplexing
- Connection-oriented demux
- Connection-oriented demux (cont)
- Connection-oriented demux Threaded Web Server
- UDP User Datagram Protocol [RFC 768]
- UDP more
- UDP checksum
- Principles of Reliable data transfer
- Reliable data transfer getting started
- Reliable data transfer getting started
- Rdt10 reliable transfer over a reliable channel
- Rdt20 channel with bit errors
- rdt20 FSM specification
- rdt20 operation with no errors
- rdt20 error scenario
- rdt20 has a fatal flaw
- rdt21 sender handles garbled ACKNAKs
- rdt21 receiver handles garbled ACKNAKs
- rdt21 discussion
- rdt22 a NAK-free protocol
- rdt22 sender receiver fragments
- rdt30 channels with errors and loss
- rdt30 sender
- rdt30 in action
- rdt30 in action
- Performance of rdt30
- rdt30 stop-and-wait operation
- Pipelined protocols
- Pipelining increased utilization
- Go-Back-N
- GBN sender extended FSM
- GBN receiver extended FSM
- GBN inaction
- Selective Repeat
- Selective repeat sender receiver windows
- Selective repeat
- Selective repeat in action
- Selective repeat dilemma
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- TCP Overview RFCs 793 1122 1323 2018 2581
- TCP segment structure
- TCP seq rsquos and ACKs
- TCP Round Trip Time and Timeout
- TCP Round Trip Time and Timeout
- Example RTT estimation
- TCP Round Trip Time and Timeout
- TCP reliable data transfer
- TCP sender events
- TCP sender(simplified)
- TCP retransmission scenarios
- TCP retransmission scenarios (more)
- TCP ACK generation [RFC 1122 RFC 2581]
- Fast Retransmit
- Fast Retransmit
- Fast retransmit algorithm
- TCP Flow Control
- TCP Flow control how it works
- Sliding Window Flow Control Example
- Principles of Congestion Control
- Causescosts of congestion scenario 1
- Causescosts of congestion scenario 2
- Causescosts of congestion scenario 2
- Causescosts of congestion scenario 3
- Causescosts of congestion scenario 3
- Approaches towards congestion control
- TCP Congestion Control
- TCP congestion control bandwidth probing
- TCP Congestion Control details
- TCP Congestion Control more details
- TCP Slow Start Phase
- Slow Start Example
- TCP Congestion Avoidance Phase
- Congestion Avoidance
- Example Slow StartCongestion Avoidance
- Slow Start Congestion Avoidance
- Responses to Congestion
- Fast Recovery (differentiation btwn two loss events)
- TCP Congestion Control
- Popular ldquoflavorsrdquo of TCP
- Summary TCP Congestion Control
- TCP Congestion Control Summary
- TCP throughput
- TCP Futures TCP over ldquolong fat pipesrdquo
- TCP Fairness
- Why is TCP fair
- Fairness (more)
- TCP Connection Management
- TCP Connection Management (cont)
- TCP Connection Management (cont)
- TCP Connection Management (cont)
- Tuning TCPIP Parameters
- SomeTCP Parameters in Linux Kernel
- SomeTCP Parameters in Linux Kernel
-
Transport Layer 3-47
Sequence Number vs Window SizeSuppose we use k bits to represent SNQuestion Whatrsquos the minimum number of bits k necessary for a window size of N
sender
receiver
Go-Back-N
expectedSN
snd_base=expectedSN-N
Q For a given expectedSN whatrsquos the smallest possible value for snd_baseA If all the last N ACKs sent by the receiver are not received
snd_base = expectedSN-NexpectedSN-1
senderrsquos window
Transport Layer 3-48
Sequence Number vs Window Size
sender
receiver
Go-Back-N
expectedSN
snd_base=expectedSN-N
All SNs in the interval [expectedSN-NexpectedSN+N-1] (an interval of size 2N) can be received by the receiver Since the receiver accepts on the packet with SN=expectedSN there should be no other packet within this interval with SN=expectedSN Therefore
2k ge N+1expectedSN+N-1
Transport Layer 3-49
Sequence Number vs Window SizeSuppose we use k bits to represent SNQuestion Whatrsquos the minimum number of bits k necessary for a window size of N
sender
receiver
Selective Repeat
rcv_base
snd_base=rcv_base
Q For a given rcv_base whatrsquos the largest possible value for snd_baseA If all the last N ACKs sent by the receiver are received
snd_base = rcv_base (same as go_back-N)rcv_base+N-1
senderrsquos window
receiverrsquos window
rcv_base+N-1
Transport Layer 3-50
Sequence Number vs Window SizeSuppose we use k bits to represent SNQuestion Whatrsquos the minimum number of bits k necessary for a window size of N
sender
receiver
Selective Repeat
rcv_base
snd_base=rcv_base-N
Q For a given rcv_base whatrsquos the smallest possible value for snd_baseA If all the last N ACKs sent by the receiver are not received
snd_base = rcv_base-N (same as Go-Back-N)rcv_base-1
senderrsquos window
rcv_base
receiverrsquos window
rcv_base+N-1
Transport Layer 3-51
Sequence Number vs Window Size
sender
receiver
Selective Repeat
snd_base=rcv_base-N
All SNs in the interval [rcv_base-Nrcv_base+N-1] (an interval of size 2N) can be received by the receiver Since the receiver should be able to distinguish between all packets in this interval and take corresponding action there should be no two packets within thisinterval having the same SN Therefore
2k ge 2Nrcv_base+N-1
rcv_basercv_base
receiverrsquos window
rcv_base+N-1
Transport Layer 3-52
TCP Overview RFCs 793 1122 1323 2018 2581
full duplex databi-directional data flow in same connectionMSS maximum segment size
connection-orientedhandshaking (exchange of control msgs) initrsquossender receiver state before data exchange
flow controlledsender will not overwhelm receiver
point-to-pointone sender one receiver
reliable in-order byte stream
no ldquomessage boundariesrdquopipelined
TCP congestion and flow control set window size
send amp receive buffers
socketdoor
TCPsend buffer
TCPreceive buffer
socketdoor
segment
applicationwrites data
applicationreads data
Transport Layer 3-53
TCP segment structure
source port dest port
32 bits
applicationdata
(variable length)
sequence numberacknowledgement number
Receive windowUrg data pnterchecksum
FSRPAUheadlen
notused
Options (variable length)
URG urgent data (generally not used)
ACK ACK valid
PSH push data now(generally not used)
RST SYN FINconnection estab(setup teardown
commands)
bytes rcvr willingto accept
Internetchecksum
(as in UDP)
countingby bytes of data(not segments)
Transport Layer 3-54
TCP seq rsquos and ACKsSeq rsquos
byte stream ldquonumberrdquo of first byte in segmentrsquos dataACKs
seq of next byte expected from other sidecumulative ACK
Q how receiver handles out-of-order segmentsA TCP spec doesnrsquot say - up to implementationWidely used implementations of TCP buffer out-of-order segments
Transport Layer 3-55
TCP Round Trip Time and Timeout
Q how to set TCP timeout valuelonger than RTT
but RTT variestoo short premature timeout
unnecessary retransmissions
too long slow reaction to segment loss
Q how to estimate RTTSampleRTT measured time from segment transmission until ACK receipt
ignore retransmissionsSampleRTT will vary want estimated RTT ldquosmootherrdquo
average several recent measurements not just current SampleRTT
Transport Layer 3-56
TCP Round Trip Time and Timeout
EstimatedRTT = (1- α)EstimatedRTT + αSampleRTT
Exponential weighted moving averageinfluence of past sample decreases exponentially fasttypical value α = 0125
Transport Layer 3-57
Example RTT estimationRTT gaiacsumassedu to fantasiaeurecomfr
100
150
200
250
300
350
1 8 15 22 29 36 43 50 57 64 71 78 85 92 99 106
time (seconnds)
RTT
(mill
iseco
nds)
SampleRTT Estimated RTT
Transport Layer 3-58
TCP Round Trip Time and TimeoutSetting the timeout
EstimatedRTT plus ldquosafety marginrdquolarge variation in EstimatedRTT -gt larger safety margin
first estimate of how much SampleRTT deviates from EstimatedRTT
TimeoutInterval = EstimatedRTT + 4DevRTT
DevRTT = (1-β)DevRTT +β|SampleRTT-EstimatedRTT|
(typically β = 025)
Then set timeout interval
Transport Layer 3-59
TCP reliable data transfer
TCP creates rdtservice on top of IPrsquos unreliable servicePipelined segmentsCumulative acksTCP uses single retransmission timer however it just retransmits the first segment in the window
Retransmissions are triggered by
timeout eventsduplicate acks
Initially consider simplified TCP sender
ignore duplicate acksignore flow control congestion control
Transport Layer 3-60
TCP sender eventsdata rcvd from app
Create segment with seq seq is byte-stream number of first data byte in segmentstart timer if not already running (think of timer as for oldest unacked segment)expiration interval TimeOutInterval
timeoutretransmit segment that caused timeout (first segment in the window)restart timer
Ack rcvdIf acknowledges previously unacked segments
update what is known to be ackedstart timer if there are outstanding segments
Transport Layer 3-61
TCP sender(simplified)
NextSeqNum = InitialSeqNumSendBase = InitialSeqNum
loop (forever) switch(event)
event data received from application above create TCP segment with sequence number NextSeqNumif (timer currently not running)
start timerpass segment to IP NextSeqNum = NextSeqNum + length(data)
event timer timeoutretransmit not-yet-acknowledged segment with
smallest sequence numberstart timer
event ACK received with ACK field value of y if (y gt SendBase)
SendBase = yif (there are currently not-yet-acknowledged segments)
start timer
end of loop forever
Commentbull SendBase-1 last cumulatively ackrsquoed byteExamplebull SendBase-1 = 71y= 73 so the rcvrwants 73+ y gt SendBase sothat new data is acked
Transport Layer 3-62
TCP retransmission scenariosHost A
Seq=100 20 bytes data
ACK=100
timepremature timeout
Host B
Seq=92 8 bytes data
ACK=120
Seq=92 8 bytes data
Seq=
92 t
imeo
ut
ACK=120
Host A
Seq=92 8 bytes data
ACK=100
loss
tim
eout
lost ACK scenario
Host B
X
Seq=92 8 bytes data
ACK=100
time
Seq=
92 t
imeo
utSendBase
= 100
SendBase= 120
SendBase= 120
Sendbase= 100
Transport Layer 3-63
TCP retransmission scenarios (more)Host A
Seq=92 8 bytes data
ACK=100
loss
tim
eout
Cumulative ACK scenario
Host B
X
Seq=100 20 bytes data
ACK=120
time
SendBase= 120
Transport Layer 3-64
TCP ACK generation [RFC 1122 RFC 2581]
Event at Receiver
Arrival of in-order segment withexpected seq All data up toexpected seq already ACKed
Arrival of in-order segment withexpected seq One other segment has ACK pending
Arrival of out-of-order segmenthigher-than-expect seq Gap detected
Arrival of segment that partially or completely fills gap
TCP Receiver action
Delayed ACK Wait up to 500msfor next segment If no next segmentsend ACK
Immediately send single cumulative ACK ACKing both in-order segments
Immediately send duplicate ACK indicating seq of next expected byte
Immediate send ACK provided thatsegment startsat lower end of gap
Transport Layer 3-65
Fast Retransmit
Time-out period often relatively long
long delay before resending lost packet
Detect lost segments via duplicate ACKs
Sender often sends many segments back-to-backIf segment is lost there will likely be many duplicate ACKs
If sender receives 3 ACKs for the same data it supposes that segment after ACKeddata was lost
fast retransmit resend segment before timer expires
Transport Layer 3-66
Fast RetransmitResend a segment after 3 duplicate ACKs since a duplicate ACK means that an out-of sequence segment was receivedduplicate ACKs due to packet reorderingif window is small donrsquot get duplicate ACKs
Host A
tim
eout
Host B
time
X
resend seq X2
seq x1seq x2seq x3seq x4seq x5
ACK x1
ACK x1ACK x1ACK x1
tripleduplicate
ACKs
Transport Layer 3-67
event ACK received with ACK field value of y if (y gt SendBase)
SendBase = yif (there are currently not-yet-acknowledged segments)
start timer
else increment count of dup ACKs received for yif (count of dup ACKs received for y = 3)
resend segment with sequence number y
Fast retransmit algorithm
a duplicate ACK for already ACKed segment
fast retransmit
Transport Layer 3-68
TCP Flow Control
receive side of TCP connection has a receive buffer
speed-matching service matching the send rate to the receiving apprsquos drain rate
app process may be slow at reading from buffer
sender wonrsquot overflowreceiverrsquos buffer by
transmitting too muchtoo fast
flow control
Transport Layer 3-69
TCP Flow control how it works
(Suppose TCP receiver discards out-of-order segments)spare room in buffer
= RcvWin
= RcvBuffer-[LastByteRcvd -LastByteRead]
Rcvr advertises spare room by including value of RcvWin in segmentsSender limits unACKeddata to RcvWin
guarantees receive buffer doesnrsquot overflow
Transport Layer 3-70
Sliding Window Flow Control Example
3K
2K SeqNo=0
ReceiverBuffer
0 4KSendersends 2Kof data
2K
AckNo=2048 RcvWin=2048Sendersends 2Kof data 2K SeqNo=2048
4K
AckNo=4096 RcvWin=0
AckNo=4096 RcvWin=1024
Sender blocked
Transport Layer 3-71
Principles of Congestion Control
Congestioninformally ldquotoo many sources sending too much data too fast for network to handlerdquodifferent from flow controlmanifestations
lost packets (buffer overflow at routers)long delays (queueing in router buffers)
a top-10 problem
Transport Layer 3-72
Causescosts of congestion scenario 1
two senders two receiversone router infinite buffers no retransmission
large delays when congestedmaximum achievable throughput
unlimited shared output link buffers
Host Aλin original data
Host B
λout
Transport Layer 3-73
Causescosts of congestion scenario 2
one router finite buffers sender retransmission of lost packet
finite shared output link buffers
Host A λin original data
Host B
λout
λin original data plus retransmitted data
Transport Layer 3-74
Causescosts of congestion scenario 2always (goodput)ldquoperfectrdquo retransmission only when loss
retransmission of delayed (not lost) packet makes larger(than perfect case) for same
λin
λout=
λin
λoutgtλ
inλout
ldquocostsrdquo of congestionmore work (retrans) for given ldquogoodputrdquounneeded retransmissions link carries multiple copies of pkt
R2
R2λin
λ out
b
R2
R2λin
λ out
a
R2
R2λin
λ out
c
R4
R3
Transport Layer 3-75
Causescosts of congestion scenario 3four sendersmultihop pathstimeoutretransmit
λin
Q what happens as and increase λ
in
finite shared output link buffers
Host Aλin original data
Host B
λout
λin original data plus retransmitted data
Transport Layer 3-76
Causescosts of congestion scenario 3
another ldquocostrdquo of congestionwhen packet dropped any ldquoupstream transmission capacity used for that packet was wasted
Host A
Host B
λou
t
Transport Layer 3-77
Approaches towards congestion control
End-end congestion controlno explicit feedback from networkcongestion inferred from end-system observed loss delayapproach taken by TCP
Network-assisted congestion controlrouters provide feedback to end systems
single bit indicating congestion (SNA DECbit TCPIP ECN ATM)explicit rate sender should send at
Two broad approaches towards congestion control
Transport Layer 3-78
TCP Congestion Control
end-end control (no network assistance)sender limits transmissionLastByteSent-LastByteAcked
le CongWin
CongWin is dynamic function of perceived network congestion
How does sender perceive congestionloss event = timeout or3 duplicate acksTCP sender reduces rate (CongWin) after loss event
two modes of operationSlow Start (SS)Congestion avoidance (CA) or Additive Increase Multiplicative Decrease (AIMD)
Transport Layer 3-79
TCP congestion control bandwidth probing
ldquoprobing for bandwidthrdquo increase transmission rate on receipt of ACK until eventually loss occurs then decrease transmission rate
continue to increase on ACK decrease on loss (since available bandwidth is changing depending on other connections in network)
ACKs being received so increase rate
X
X
XX
X loss so decrease rate
send
ing
rate
time
Q how fast to increasedecreasedetails to follow
TCPrsquosldquosawtoothrdquobehavior
Transport Layer 3-80
TCP Congestion Control details
sender limits rate by limiting number of unACKed bytes ldquoin pipelinerdquo
cwnd differs from rwnd (how why)sender limited by min(cwndrwnd)
roughly
cwnd is dynamic function of perceived network congestion
rate = cwndRTT bytessec
LastByteSent-LastByteAcked le cwnd
cwndbytes
RTT
ACK(s)
Transport Layer 3-81
TCP Congestion Control more details
segment loss event reducing cwndtimeout no response from receiver
cut cwnd to 13 duplicate ACKs at least some segments getting through (recall fast retransmit)
cut cwnd in half less aggressively than on timeout
ACK received increase cwndTwo modes of operation
slowstart phase bull increase exponentially
fast (despite name) at connection start or following timeout
congestion avoidance bull increase linearly
Transport Layer 3-82
TCP Slow Start Phasewhen connection begins cwnd = 1 MSS
example MSS = 500 bytes amp RTT = 200 msecinitial rate = 20 kbps
available bandwidth may be gtgt MSSRTT
desirable to quickly ramp up to respectable rate
increase rate exponentially until first loss event or when threshold reached
double cwnd every RTTdone by incrementing cwnd by 1 for every ACK received
Host A
one segment
RTT
Host B
time
two segments
four segments
Transport Layer 3-83
Slow Start ExampleThe congestion window size grows very rapidly
For every ACK we increase CongWin by 1 irrespective of the number of segments ACKrsquoeddouble CongWinevery RTTinitial rate is slow but ramps up exponentially fast
TCP slows down the increase of CongWinwhen CongWin gt ssthresh
segment 1
ACK for segment 1
cwnd = 1
cwnd = 2 segment 2segment 3
ACK for segments 2
cwnd = 4 segment 4segment 5segment 6
ACK for segments 4
cwnd = 7
ACK for segments 3
ACK for segments 5
ACK for segments 6
cwnd = 3
cwnd = 5
cwnd = 6ACK for segments 7
cwnd = 8
segment 7
Transport Layer 3-84
TCP Congestion Avoidance Phase
when cwnd gt ssthreshgrow cwnd linearly
increase cwnd by 1 MSS per RTT approach possible congestion slower than in slowstartimplementation cwnd= cwnd + MSScwndfor each ACK received
ACKs increase cwndby 1 MSS per RTT additive increaseloss cut cwnd in half (non-timeout-detected loss ) multiplicative decrease
AIMD
AIMD Additive IncreaseMultiplicative Decrease
Transport Layer 3-85
Congestion AvoidanceCongestion avoidance phase is started if CongWin has reached the slow-start threshold value
If CongWin gt= ssthresh then each time an ACK is received increment CongWin as follows
bull CongWin = CongWin + 1CongWin (CongWin in segments)
bull In actual TCP implementation CongWin is in BytesCongWin = CongWin + MSS (MSSCongWin)
So CongWin is increased by one only if all CongWinsegments have been acknowledged
Transport Layer 3-86
Example Slow StartCongestion AvoidanceAssume that
ssthresh = 8
cwnd = 1
cwnd = 2
cwnd = 4
cwnd = 8
cwnd = 9
cwnd = 10
02468
101214
t=0
t=2
t=4
t=6
Roundtrip times
Cw
nd(in
seg
men
ts)
ssthresh
cwnd = 3
cwnd = 5cwnd = 6cwnd = 7
Transport Layer 3-87
Slow Start Congestion AvoidanceA typical plot of CongWin for a TCP connection
(MSS = 1500 bytes) with TCP Tahoe
SS
CA
ssthresh
Transport Layer 3-88
Responses to CongestionTCP assumes there is congestion if it detects a packet lossA TCP sender can detect lost packets via loss events
bull Timeout of a retransmission timerbull Receipt of 3 duplicate ACKs (fast retransmit)
TCP interprets a Timeout as a binary congestion signal When a timeout occurs the sender performs
ssthresh is set to half the current size of the congestion window
ssthresh = CongWin 2CongWin is reset to one
CongWin = 1and slow-start is entered
Transport Layer 3-89
Fast Recovery (differentiation btwn two loss events) After 3 dup ACKs (fast Retransmit)
ssthresh = CongWin2CongWin = CongWin2window then grows linearly
But after timeout eventCongWin = 1 MSS window then grows exponentiallyto the threshold then grows linearly
bull 3 dup ACKs indicates network capable of delivering some segmentsbull timeout before 3 dup ACKs is ldquomore alarmingrdquo
Philosophy
3-90
TCP Congestion ControlInitially
CongWin = 1ssthresh = advertised window size
New Ack receivedif (CongWin lt ssthresh) Slow Start
CongWin = CongWin + 1else Congestion Avoidance
CongWin = CongWin + 1CongWinTimeout
ssthresh = CongWin2CongWin = 1
Fast Retransmissionssthresh = CongWin2CongWin = CongWin2
Slow Start (exponential increase phase) is continued until CongWin reaches half of the level where the loss event occurred last time CongWin is increased slowly after (linear increase in Congestion Avoidance phase)
Transport Layer 3-91
Popular ldquoflavorsrdquo of TCP
ssthresh
ssthresh
TCP Tahoe
TCP Reno
Transmission round
cwnd
win
dow
siz
e (in
seg
men
ts)
Transport Layer 3-92
Summary TCP Congestion ControlWhen CongWin is below Threshold sender in slow-start phase window grows exponentiallyWhen CongWin is above Threshold sender is in congestion-avoidance phase window grows linearlyWhen a triple duplicate ACK occurs Threshold set to CongWin2 and CongWin set to ThresholdWhen timeout occurs Threshold set to CongWin2 and CongWin is set to 1 MSS The actual sender window size is determined based on the congestion and flow control algorithms
SenderWin=min(RcvWinCongWin)
Transport Layer 3-93
TCP Congestion Control SummaryEvent State TCP Sender Action Commentary
ACK receipt for previously unackeddata
Slow Start (SS)
CongWin = CongWin + MSS If (CongWin gt Threshold)
set state to ldquoCongestion Avoidancerdquo
Resulting in a doubling of CongWin every RTT
ACK receipt for previously unackeddata
CongestionAvoidance (CA)
CongWin = CongWin+MSS (MSSCongWin)
Additive increase resulting in increase of CongWin by 1 MSS every RTT
Loss event detected by triple duplicate ACK
SS or CA Threshold = CongWin2 CongWin = ThresholdSet state to ldquoCongestion Avoidancerdquo
Fast recovery implementing multiplicative decrease CongWin will not drop below 1 MSS
Timeout SS or CA Threshold = CongWin2 CongWin = 1 MSSSet state to ldquoSlow Startrdquo
Enter slow start
Duplicate ACK
SS or CA Increment duplicate ACK count for segment being acked
CongWin and Threshold not changed
Transport Layer 3-94
TCP throughput
Q whatrsquos average throughout of TCP as function of window size RTT
ignoring slow startlet W be window size when loss occurs
when window is W throughput is WRTTjust after loss window drops to W2 throughput to W2RTT average throughout 75 WRTT
Transport Layer 3-95
TCP Futures TCP over ldquolong fat pipesrdquo
example 1500 byte segments 100ms RTT want 10 Gbps throughputrequires window size W = 83333 in-flight segmentsthroughput in terms of loss rate
L = 210-10 Wownew versions of TCP for high-speed
LRTTMSSsdot221
Transport Layer 3-96
Fairness goal if K TCP sessions share same bottleneck link of bandwidth R each should have average rate of RK
TCP connection 1
bottleneckrouter
capacity R
TCP connection 2
TCP Fairness
Transport Layer 3-97
Why is TCP fairTwo competing sessions
Additive increase gives slope of 1 as throughout increasesmultiplicative decrease decreases throughput proportionally
R
R
equal bandwidth share
Connection 1 throughput
Conn
ecti
on 2
thr
ough
p ut
congestion avoidance additive increaseloss decrease window by factor of 2
congestion avoidance additive increaseloss decrease window by factor of 2
Transport Layer 3-98
Fairness (more)Fairness and UDP
Multimedia apps often do not use TCP
do not want rate throttled by congestion control
Instead use UDPpump audiovideo at constant rate tolerate packet loss
Research area TCP friendly
Fairness and parallel TCP connectionsnothing prevents app from opening parallel cnctionsbetween 2 hostsWeb browsers do this Example link of rate R supporting 9 cnctions
new app asks for 1 TCP gets rate R10new app asks for 11 TCPs gets R2
Transport Layer 3-99
TCP Connection ManagementRecall TCP sender receiver
establish ldquoconnectionrdquobefore exchanging data segmentsinitialize TCP variables
seq sbuffers flow control info (eg RcvWindow)
client connection initiatorSocket clientSocket = new Socket(hostnameport
number)
server contacted by clientSocket connectionSocket = welcomeSocketaccept()
Three way handshakeStep 1 client host sends TCP
SYN segment to serverspecifies initial seq no data
Step 2 server host receives SYN replies with SYNACK segment
server allocates buffersspecifies server initial seq
Step 3 client receives SYNACK replies with ACK segment which may contain data
Transport Layer 3-100
TCP Connection Management (cont)
Closing a connection
client closes socketclientSocketclose()
Step 1 client end system sends TCP FIN control segment to server
Step 2 server receives FIN replies with ACK Closes connection sends FIN
client
FIN
server
ACK
ACK
FIN
close
close
closed
tim
ed w
ait
Transport Layer 3-101
TCP Connection Management (cont)
Step 3 client receives FIN replies with ACK
Enters ldquotimed waitrdquo -will respond with ACK to received FINs
Step 4 server receives ACK Connection closed
client
FIN
server
ACK
ACK
FIN
closing
closing
closed
tim
ed w
ait
closed
Transport Layer 3-102
TCP Connection Management (cont)
TCP clientlifecycle
TCP serverlifecycle
Transport Layer 3-103
Tuning TCPIP Parameters TCPIP parameters
A set of default values may not be optimal for all applicationsThe network administrator may wish to turn on or off some TCPIP functions for performance or security considerations
Many Unix and Linux systems provide some flexibility in tuning the TCPIP kernelsbinsysctl is used to configure the Linux kernel parameters at runtime
Default kernel configuration file is sbinsysctlconfFrequently used sysctl options
bull sysctl ndasha or sysctl ndashA list all current valuesbull sysctl ndashp file_name load the sysctl setting from a configuration
filebull sysctl ndashw variable=value change the value of the parameter
Transport Layer 3-104
SomeTCP Parameters in Linux Kerneltcp_syn_retries
Number of SYN packets the kernel will send before giving up on the new connection
tcp_synack_retriesnumber of SYN+ACK packets sent before the kernel gives up on the connection
tcp_window_scalingMaximum window size of 65535 bytes not enough for for really fast networks The window scaling options allows for almost gigabyte windows which is good for connections with large delay-bandwidth product
tcp_max_syn_backlogMaximal number of remembered connection requests which still did not receive an acknowledgment from connecting client
tcp_fin_timeoutHow many seconds to wait for a final FIN packet before the socket is closed required to prevent denial-of-service (DoS) attacks Default value is 60 seconds
Transport Layer 3-105
SomeTCP Parameters in Linux Kerneltcp_rmem
This is a vector of 3 integers [min default max] These parameters are used by TCP to dynamically adjust receive buffer sizesmin - minimum size of the receive buffer used by each TCP socket The default value is 4K default - the default size of the receive buffer for a TCP socket The default value is 87380 bytes and is lowered to 43689 in low memory systems If larger receive buffer sizes are desired this value should be increased max - the maximum size of the receive buffer used by each TCP socket The default value of 873802 bytes is lowered to 87380 in low memory systems
tcp_smemSend buffer parameters [min default max] similar to tcp_rmem
- Chapter 3 Transport Layer
- Transport services and protocols
- Transport vs network layer
- Internet transport-layer protocols
- Multiplexingdemultiplexing
- How demultiplexing works
- Connectionless demultiplexing
- Connection-oriented demux
- Connection-oriented demux (cont)
- Connection-oriented demux Threaded Web Server
- UDP User Datagram Protocol [RFC 768]
- UDP more
- UDP checksum
- Principles of Reliable data transfer
- Reliable data transfer getting started
- Reliable data transfer getting started
- Rdt10 reliable transfer over a reliable channel
- Rdt20 channel with bit errors
- rdt20 FSM specification
- rdt20 operation with no errors
- rdt20 error scenario
- rdt20 has a fatal flaw
- rdt21 sender handles garbled ACKNAKs
- rdt21 receiver handles garbled ACKNAKs
- rdt21 discussion
- rdt22 a NAK-free protocol
- rdt22 sender receiver fragments
- rdt30 channels with errors and loss
- rdt30 sender
- rdt30 in action
- rdt30 in action
- Performance of rdt30
- rdt30 stop-and-wait operation
- Pipelined protocols
- Pipelining increased utilization
- Go-Back-N
- GBN sender extended FSM
- GBN receiver extended FSM
- GBN inaction
- Selective Repeat
- Selective repeat sender receiver windows
- Selective repeat
- Selective repeat in action
- Selective repeat dilemma
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- TCP Overview RFCs 793 1122 1323 2018 2581
- TCP segment structure
- TCP seq rsquos and ACKs
- TCP Round Trip Time and Timeout
- TCP Round Trip Time and Timeout
- Example RTT estimation
- TCP Round Trip Time and Timeout
- TCP reliable data transfer
- TCP sender events
- TCP sender(simplified)
- TCP retransmission scenarios
- TCP retransmission scenarios (more)
- TCP ACK generation [RFC 1122 RFC 2581]
- Fast Retransmit
- Fast Retransmit
- Fast retransmit algorithm
- TCP Flow Control
- TCP Flow control how it works
- Sliding Window Flow Control Example
- Principles of Congestion Control
- Causescosts of congestion scenario 1
- Causescosts of congestion scenario 2
- Causescosts of congestion scenario 2
- Causescosts of congestion scenario 3
- Causescosts of congestion scenario 3
- Approaches towards congestion control
- TCP Congestion Control
- TCP congestion control bandwidth probing
- TCP Congestion Control details
- TCP Congestion Control more details
- TCP Slow Start Phase
- Slow Start Example
- TCP Congestion Avoidance Phase
- Congestion Avoidance
- Example Slow StartCongestion Avoidance
- Slow Start Congestion Avoidance
- Responses to Congestion
- Fast Recovery (differentiation btwn two loss events)
- TCP Congestion Control
- Popular ldquoflavorsrdquo of TCP
- Summary TCP Congestion Control
- TCP Congestion Control Summary
- TCP throughput
- TCP Futures TCP over ldquolong fat pipesrdquo
- TCP Fairness
- Why is TCP fair
- Fairness (more)
- TCP Connection Management
- TCP Connection Management (cont)
- TCP Connection Management (cont)
- TCP Connection Management (cont)
- Tuning TCPIP Parameters
- SomeTCP Parameters in Linux Kernel
- SomeTCP Parameters in Linux Kernel
-
Transport Layer 3-48
Sequence Number vs Window Size
sender
receiver
Go-Back-N
expectedSN
snd_base=expectedSN-N
All SNs in the interval [expectedSN-NexpectedSN+N-1] (an interval of size 2N) can be received by the receiver Since the receiver accepts on the packet with SN=expectedSN there should be no other packet within this interval with SN=expectedSN Therefore
2k ge N+1expectedSN+N-1
Transport Layer 3-49
Sequence Number vs Window SizeSuppose we use k bits to represent SNQuestion Whatrsquos the minimum number of bits k necessary for a window size of N
sender
receiver
Selective Repeat
rcv_base
snd_base=rcv_base
Q For a given rcv_base whatrsquos the largest possible value for snd_baseA If all the last N ACKs sent by the receiver are received
snd_base = rcv_base (same as go_back-N)rcv_base+N-1
senderrsquos window
receiverrsquos window
rcv_base+N-1
Transport Layer 3-50
Sequence Number vs Window SizeSuppose we use k bits to represent SNQuestion Whatrsquos the minimum number of bits k necessary for a window size of N
sender
receiver
Selective Repeat
rcv_base
snd_base=rcv_base-N
Q For a given rcv_base whatrsquos the smallest possible value for snd_baseA If all the last N ACKs sent by the receiver are not received
snd_base = rcv_base-N (same as Go-Back-N)rcv_base-1
senderrsquos window
rcv_base
receiverrsquos window
rcv_base+N-1
Transport Layer 3-51
Sequence Number vs Window Size
sender
receiver
Selective Repeat
snd_base=rcv_base-N
All SNs in the interval [rcv_base-Nrcv_base+N-1] (an interval of size 2N) can be received by the receiver Since the receiver should be able to distinguish between all packets in this interval and take corresponding action there should be no two packets within thisinterval having the same SN Therefore
2k ge 2Nrcv_base+N-1
rcv_basercv_base
receiverrsquos window
rcv_base+N-1
Transport Layer 3-52
TCP Overview RFCs 793 1122 1323 2018 2581
full duplex databi-directional data flow in same connectionMSS maximum segment size
connection-orientedhandshaking (exchange of control msgs) initrsquossender receiver state before data exchange
flow controlledsender will not overwhelm receiver
point-to-pointone sender one receiver
reliable in-order byte stream
no ldquomessage boundariesrdquopipelined
TCP congestion and flow control set window size
send amp receive buffers
socketdoor
TCPsend buffer
TCPreceive buffer
socketdoor
segment
applicationwrites data
applicationreads data
Transport Layer 3-53
TCP segment structure
source port dest port
32 bits
applicationdata
(variable length)
sequence numberacknowledgement number
Receive windowUrg data pnterchecksum
FSRPAUheadlen
notused
Options (variable length)
URG urgent data (generally not used)
ACK ACK valid
PSH push data now(generally not used)
RST SYN FINconnection estab(setup teardown
commands)
bytes rcvr willingto accept
Internetchecksum
(as in UDP)
countingby bytes of data(not segments)
Transport Layer 3-54
TCP seq rsquos and ACKsSeq rsquos
byte stream ldquonumberrdquo of first byte in segmentrsquos dataACKs
seq of next byte expected from other sidecumulative ACK
Q how receiver handles out-of-order segmentsA TCP spec doesnrsquot say - up to implementationWidely used implementations of TCP buffer out-of-order segments
Transport Layer 3-55
TCP Round Trip Time and Timeout
Q how to set TCP timeout valuelonger than RTT
but RTT variestoo short premature timeout
unnecessary retransmissions
too long slow reaction to segment loss
Q how to estimate RTTSampleRTT measured time from segment transmission until ACK receipt
ignore retransmissionsSampleRTT will vary want estimated RTT ldquosmootherrdquo
average several recent measurements not just current SampleRTT
Transport Layer 3-56
TCP Round Trip Time and Timeout
EstimatedRTT = (1- α)EstimatedRTT + αSampleRTT
Exponential weighted moving averageinfluence of past sample decreases exponentially fasttypical value α = 0125
Transport Layer 3-57
Example RTT estimationRTT gaiacsumassedu to fantasiaeurecomfr
100
150
200
250
300
350
1 8 15 22 29 36 43 50 57 64 71 78 85 92 99 106
time (seconnds)
RTT
(mill
iseco
nds)
SampleRTT Estimated RTT
Transport Layer 3-58
TCP Round Trip Time and TimeoutSetting the timeout
EstimatedRTT plus ldquosafety marginrdquolarge variation in EstimatedRTT -gt larger safety margin
first estimate of how much SampleRTT deviates from EstimatedRTT
TimeoutInterval = EstimatedRTT + 4DevRTT
DevRTT = (1-β)DevRTT +β|SampleRTT-EstimatedRTT|
(typically β = 025)
Then set timeout interval
Transport Layer 3-59
TCP reliable data transfer
TCP creates rdtservice on top of IPrsquos unreliable servicePipelined segmentsCumulative acksTCP uses single retransmission timer however it just retransmits the first segment in the window
Retransmissions are triggered by
timeout eventsduplicate acks
Initially consider simplified TCP sender
ignore duplicate acksignore flow control congestion control
Transport Layer 3-60
TCP sender eventsdata rcvd from app
Create segment with seq seq is byte-stream number of first data byte in segmentstart timer if not already running (think of timer as for oldest unacked segment)expiration interval TimeOutInterval
timeoutretransmit segment that caused timeout (first segment in the window)restart timer
Ack rcvdIf acknowledges previously unacked segments
update what is known to be ackedstart timer if there are outstanding segments
Transport Layer 3-61
TCP sender(simplified)
NextSeqNum = InitialSeqNumSendBase = InitialSeqNum
loop (forever) switch(event)
event data received from application above create TCP segment with sequence number NextSeqNumif (timer currently not running)
start timerpass segment to IP NextSeqNum = NextSeqNum + length(data)
event timer timeoutretransmit not-yet-acknowledged segment with
smallest sequence numberstart timer
event ACK received with ACK field value of y if (y gt SendBase)
SendBase = yif (there are currently not-yet-acknowledged segments)
start timer
end of loop forever
Commentbull SendBase-1 last cumulatively ackrsquoed byteExamplebull SendBase-1 = 71y= 73 so the rcvrwants 73+ y gt SendBase sothat new data is acked
Transport Layer 3-62
TCP retransmission scenariosHost A
Seq=100 20 bytes data
ACK=100
timepremature timeout
Host B
Seq=92 8 bytes data
ACK=120
Seq=92 8 bytes data
Seq=
92 t
imeo
ut
ACK=120
Host A
Seq=92 8 bytes data
ACK=100
loss
tim
eout
lost ACK scenario
Host B
X
Seq=92 8 bytes data
ACK=100
time
Seq=
92 t
imeo
utSendBase
= 100
SendBase= 120
SendBase= 120
Sendbase= 100
Transport Layer 3-63
TCP retransmission scenarios (more)Host A
Seq=92 8 bytes data
ACK=100
loss
tim
eout
Cumulative ACK scenario
Host B
X
Seq=100 20 bytes data
ACK=120
time
SendBase= 120
Transport Layer 3-64
TCP ACK generation [RFC 1122 RFC 2581]
Event at Receiver
Arrival of in-order segment withexpected seq All data up toexpected seq already ACKed
Arrival of in-order segment withexpected seq One other segment has ACK pending
Arrival of out-of-order segmenthigher-than-expect seq Gap detected
Arrival of segment that partially or completely fills gap
TCP Receiver action
Delayed ACK Wait up to 500msfor next segment If no next segmentsend ACK
Immediately send single cumulative ACK ACKing both in-order segments
Immediately send duplicate ACK indicating seq of next expected byte
Immediate send ACK provided thatsegment startsat lower end of gap
Transport Layer 3-65
Fast Retransmit
Time-out period often relatively long
long delay before resending lost packet
Detect lost segments via duplicate ACKs
Sender often sends many segments back-to-backIf segment is lost there will likely be many duplicate ACKs
If sender receives 3 ACKs for the same data it supposes that segment after ACKeddata was lost
fast retransmit resend segment before timer expires
Transport Layer 3-66
Fast RetransmitResend a segment after 3 duplicate ACKs since a duplicate ACK means that an out-of sequence segment was receivedduplicate ACKs due to packet reorderingif window is small donrsquot get duplicate ACKs
Host A
tim
eout
Host B
time
X
resend seq X2
seq x1seq x2seq x3seq x4seq x5
ACK x1
ACK x1ACK x1ACK x1
tripleduplicate
ACKs
Transport Layer 3-67
event ACK received with ACK field value of y if (y gt SendBase)
SendBase = yif (there are currently not-yet-acknowledged segments)
start timer
else increment count of dup ACKs received for yif (count of dup ACKs received for y = 3)
resend segment with sequence number y
Fast retransmit algorithm
a duplicate ACK for already ACKed segment
fast retransmit
Transport Layer 3-68
TCP Flow Control
receive side of TCP connection has a receive buffer
speed-matching service matching the send rate to the receiving apprsquos drain rate
app process may be slow at reading from buffer
sender wonrsquot overflowreceiverrsquos buffer by
transmitting too muchtoo fast
flow control
Transport Layer 3-69
TCP Flow control how it works
(Suppose TCP receiver discards out-of-order segments)spare room in buffer
= RcvWin
= RcvBuffer-[LastByteRcvd -LastByteRead]
Rcvr advertises spare room by including value of RcvWin in segmentsSender limits unACKeddata to RcvWin
guarantees receive buffer doesnrsquot overflow
Transport Layer 3-70
Sliding Window Flow Control Example
3K
2K SeqNo=0
ReceiverBuffer
0 4KSendersends 2Kof data
2K
AckNo=2048 RcvWin=2048Sendersends 2Kof data 2K SeqNo=2048
4K
AckNo=4096 RcvWin=0
AckNo=4096 RcvWin=1024
Sender blocked
Transport Layer 3-71
Principles of Congestion Control
Congestioninformally ldquotoo many sources sending too much data too fast for network to handlerdquodifferent from flow controlmanifestations
lost packets (buffer overflow at routers)long delays (queueing in router buffers)
a top-10 problem
Transport Layer 3-72
Causescosts of congestion scenario 1
two senders two receiversone router infinite buffers no retransmission
large delays when congestedmaximum achievable throughput
unlimited shared output link buffers
Host Aλin original data
Host B
λout
Transport Layer 3-73
Causescosts of congestion scenario 2
one router finite buffers sender retransmission of lost packet
finite shared output link buffers
Host A λin original data
Host B
λout
λin original data plus retransmitted data
Transport Layer 3-74
Causescosts of congestion scenario 2always (goodput)ldquoperfectrdquo retransmission only when loss
retransmission of delayed (not lost) packet makes larger(than perfect case) for same
λin
λout=
λin
λoutgtλ
inλout
ldquocostsrdquo of congestionmore work (retrans) for given ldquogoodputrdquounneeded retransmissions link carries multiple copies of pkt
R2
R2λin
λ out
b
R2
R2λin
λ out
a
R2
R2λin
λ out
c
R4
R3
Transport Layer 3-75
Causescosts of congestion scenario 3four sendersmultihop pathstimeoutretransmit
λin
Q what happens as and increase λ
in
finite shared output link buffers
Host Aλin original data
Host B
λout
λin original data plus retransmitted data
Transport Layer 3-76
Causescosts of congestion scenario 3
another ldquocostrdquo of congestionwhen packet dropped any ldquoupstream transmission capacity used for that packet was wasted
Host A
Host B
λou
t
Transport Layer 3-77
Approaches towards congestion control
End-end congestion controlno explicit feedback from networkcongestion inferred from end-system observed loss delayapproach taken by TCP
Network-assisted congestion controlrouters provide feedback to end systems
single bit indicating congestion (SNA DECbit TCPIP ECN ATM)explicit rate sender should send at
Two broad approaches towards congestion control
Transport Layer 3-78
TCP Congestion Control
end-end control (no network assistance)sender limits transmissionLastByteSent-LastByteAcked
le CongWin
CongWin is dynamic function of perceived network congestion
How does sender perceive congestionloss event = timeout or3 duplicate acksTCP sender reduces rate (CongWin) after loss event
two modes of operationSlow Start (SS)Congestion avoidance (CA) or Additive Increase Multiplicative Decrease (AIMD)
Transport Layer 3-79
TCP congestion control bandwidth probing
ldquoprobing for bandwidthrdquo increase transmission rate on receipt of ACK until eventually loss occurs then decrease transmission rate
continue to increase on ACK decrease on loss (since available bandwidth is changing depending on other connections in network)
ACKs being received so increase rate
X
X
XX
X loss so decrease rate
send
ing
rate
time
Q how fast to increasedecreasedetails to follow
TCPrsquosldquosawtoothrdquobehavior
Transport Layer 3-80
TCP Congestion Control details
sender limits rate by limiting number of unACKed bytes ldquoin pipelinerdquo
cwnd differs from rwnd (how why)sender limited by min(cwndrwnd)
roughly
cwnd is dynamic function of perceived network congestion
rate = cwndRTT bytessec
LastByteSent-LastByteAcked le cwnd
cwndbytes
RTT
ACK(s)
Transport Layer 3-81
TCP Congestion Control more details
segment loss event reducing cwndtimeout no response from receiver
cut cwnd to 13 duplicate ACKs at least some segments getting through (recall fast retransmit)
cut cwnd in half less aggressively than on timeout
ACK received increase cwndTwo modes of operation
slowstart phase bull increase exponentially
fast (despite name) at connection start or following timeout
congestion avoidance bull increase linearly
Transport Layer 3-82
TCP Slow Start Phasewhen connection begins cwnd = 1 MSS
example MSS = 500 bytes amp RTT = 200 msecinitial rate = 20 kbps
available bandwidth may be gtgt MSSRTT
desirable to quickly ramp up to respectable rate
increase rate exponentially until first loss event or when threshold reached
double cwnd every RTTdone by incrementing cwnd by 1 for every ACK received
Host A
one segment
RTT
Host B
time
two segments
four segments
Transport Layer 3-83
Slow Start ExampleThe congestion window size grows very rapidly
For every ACK we increase CongWin by 1 irrespective of the number of segments ACKrsquoeddouble CongWinevery RTTinitial rate is slow but ramps up exponentially fast
TCP slows down the increase of CongWinwhen CongWin gt ssthresh
segment 1
ACK for segment 1
cwnd = 1
cwnd = 2 segment 2segment 3
ACK for segments 2
cwnd = 4 segment 4segment 5segment 6
ACK for segments 4
cwnd = 7
ACK for segments 3
ACK for segments 5
ACK for segments 6
cwnd = 3
cwnd = 5
cwnd = 6ACK for segments 7
cwnd = 8
segment 7
Transport Layer 3-84
TCP Congestion Avoidance Phase
when cwnd gt ssthreshgrow cwnd linearly
increase cwnd by 1 MSS per RTT approach possible congestion slower than in slowstartimplementation cwnd= cwnd + MSScwndfor each ACK received
ACKs increase cwndby 1 MSS per RTT additive increaseloss cut cwnd in half (non-timeout-detected loss ) multiplicative decrease
AIMD
AIMD Additive IncreaseMultiplicative Decrease
Transport Layer 3-85
Congestion AvoidanceCongestion avoidance phase is started if CongWin has reached the slow-start threshold value
If CongWin gt= ssthresh then each time an ACK is received increment CongWin as follows
bull CongWin = CongWin + 1CongWin (CongWin in segments)
bull In actual TCP implementation CongWin is in BytesCongWin = CongWin + MSS (MSSCongWin)
So CongWin is increased by one only if all CongWinsegments have been acknowledged
Transport Layer 3-86
Example Slow StartCongestion AvoidanceAssume that
ssthresh = 8
cwnd = 1
cwnd = 2
cwnd = 4
cwnd = 8
cwnd = 9
cwnd = 10
02468
101214
t=0
t=2
t=4
t=6
Roundtrip times
Cw
nd(in
seg
men
ts)
ssthresh
cwnd = 3
cwnd = 5cwnd = 6cwnd = 7
Transport Layer 3-87
Slow Start Congestion AvoidanceA typical plot of CongWin for a TCP connection
(MSS = 1500 bytes) with TCP Tahoe
SS
CA
ssthresh
Transport Layer 3-88
Responses to CongestionTCP assumes there is congestion if it detects a packet lossA TCP sender can detect lost packets via loss events
bull Timeout of a retransmission timerbull Receipt of 3 duplicate ACKs (fast retransmit)
TCP interprets a Timeout as a binary congestion signal When a timeout occurs the sender performs
ssthresh is set to half the current size of the congestion window
ssthresh = CongWin 2CongWin is reset to one
CongWin = 1and slow-start is entered
Transport Layer 3-89
Fast Recovery (differentiation btwn two loss events) After 3 dup ACKs (fast Retransmit)
ssthresh = CongWin2CongWin = CongWin2window then grows linearly
But after timeout eventCongWin = 1 MSS window then grows exponentiallyto the threshold then grows linearly
bull 3 dup ACKs indicates network capable of delivering some segmentsbull timeout before 3 dup ACKs is ldquomore alarmingrdquo
Philosophy
3-90
TCP Congestion ControlInitially
CongWin = 1ssthresh = advertised window size
New Ack receivedif (CongWin lt ssthresh) Slow Start
CongWin = CongWin + 1else Congestion Avoidance
CongWin = CongWin + 1CongWinTimeout
ssthresh = CongWin2CongWin = 1
Fast Retransmissionssthresh = CongWin2CongWin = CongWin2
Slow Start (exponential increase phase) is continued until CongWin reaches half of the level where the loss event occurred last time CongWin is increased slowly after (linear increase in Congestion Avoidance phase)
Transport Layer 3-91
Popular ldquoflavorsrdquo of TCP
ssthresh
ssthresh
TCP Tahoe
TCP Reno
Transmission round
cwnd
win
dow
siz
e (in
seg
men
ts)
Transport Layer 3-92
Summary TCP Congestion ControlWhen CongWin is below Threshold sender in slow-start phase window grows exponentiallyWhen CongWin is above Threshold sender is in congestion-avoidance phase window grows linearlyWhen a triple duplicate ACK occurs Threshold set to CongWin2 and CongWin set to ThresholdWhen timeout occurs Threshold set to CongWin2 and CongWin is set to 1 MSS The actual sender window size is determined based on the congestion and flow control algorithms
SenderWin=min(RcvWinCongWin)
Transport Layer 3-93
TCP Congestion Control SummaryEvent State TCP Sender Action Commentary
ACK receipt for previously unackeddata
Slow Start (SS)
CongWin = CongWin + MSS If (CongWin gt Threshold)
set state to ldquoCongestion Avoidancerdquo
Resulting in a doubling of CongWin every RTT
ACK receipt for previously unackeddata
CongestionAvoidance (CA)
CongWin = CongWin+MSS (MSSCongWin)
Additive increase resulting in increase of CongWin by 1 MSS every RTT
Loss event detected by triple duplicate ACK
SS or CA Threshold = CongWin2 CongWin = ThresholdSet state to ldquoCongestion Avoidancerdquo
Fast recovery implementing multiplicative decrease CongWin will not drop below 1 MSS
Timeout SS or CA Threshold = CongWin2 CongWin = 1 MSSSet state to ldquoSlow Startrdquo
Enter slow start
Duplicate ACK
SS or CA Increment duplicate ACK count for segment being acked
CongWin and Threshold not changed
Transport Layer 3-94
TCP throughput
Q whatrsquos average throughout of TCP as function of window size RTT
ignoring slow startlet W be window size when loss occurs
when window is W throughput is WRTTjust after loss window drops to W2 throughput to W2RTT average throughout 75 WRTT
Transport Layer 3-95
TCP Futures TCP over ldquolong fat pipesrdquo
example 1500 byte segments 100ms RTT want 10 Gbps throughputrequires window size W = 83333 in-flight segmentsthroughput in terms of loss rate
L = 210-10 Wownew versions of TCP for high-speed
LRTTMSSsdot221
Transport Layer 3-96
Fairness goal if K TCP sessions share same bottleneck link of bandwidth R each should have average rate of RK
TCP connection 1
bottleneckrouter
capacity R
TCP connection 2
TCP Fairness
Transport Layer 3-97
Why is TCP fairTwo competing sessions
Additive increase gives slope of 1 as throughout increasesmultiplicative decrease decreases throughput proportionally
R
R
equal bandwidth share
Connection 1 throughput
Conn
ecti
on 2
thr
ough
p ut
congestion avoidance additive increaseloss decrease window by factor of 2
congestion avoidance additive increaseloss decrease window by factor of 2
Transport Layer 3-98
Fairness (more)Fairness and UDP
Multimedia apps often do not use TCP
do not want rate throttled by congestion control
Instead use UDPpump audiovideo at constant rate tolerate packet loss
Research area TCP friendly
Fairness and parallel TCP connectionsnothing prevents app from opening parallel cnctionsbetween 2 hostsWeb browsers do this Example link of rate R supporting 9 cnctions
new app asks for 1 TCP gets rate R10new app asks for 11 TCPs gets R2
Transport Layer 3-99
TCP Connection ManagementRecall TCP sender receiver
establish ldquoconnectionrdquobefore exchanging data segmentsinitialize TCP variables
seq sbuffers flow control info (eg RcvWindow)
client connection initiatorSocket clientSocket = new Socket(hostnameport
number)
server contacted by clientSocket connectionSocket = welcomeSocketaccept()
Three way handshakeStep 1 client host sends TCP
SYN segment to serverspecifies initial seq no data
Step 2 server host receives SYN replies with SYNACK segment
server allocates buffersspecifies server initial seq
Step 3 client receives SYNACK replies with ACK segment which may contain data
Transport Layer 3-100
TCP Connection Management (cont)
Closing a connection
client closes socketclientSocketclose()
Step 1 client end system sends TCP FIN control segment to server
Step 2 server receives FIN replies with ACK Closes connection sends FIN
client
FIN
server
ACK
ACK
FIN
close
close
closed
tim
ed w
ait
Transport Layer 3-101
TCP Connection Management (cont)
Step 3 client receives FIN replies with ACK
Enters ldquotimed waitrdquo -will respond with ACK to received FINs
Step 4 server receives ACK Connection closed
client
FIN
server
ACK
ACK
FIN
closing
closing
closed
tim
ed w
ait
closed
Transport Layer 3-102
TCP Connection Management (cont)
TCP clientlifecycle
TCP serverlifecycle
Transport Layer 3-103
Tuning TCPIP Parameters TCPIP parameters
A set of default values may not be optimal for all applicationsThe network administrator may wish to turn on or off some TCPIP functions for performance or security considerations
Many Unix and Linux systems provide some flexibility in tuning the TCPIP kernelsbinsysctl is used to configure the Linux kernel parameters at runtime
Default kernel configuration file is sbinsysctlconfFrequently used sysctl options
bull sysctl ndasha or sysctl ndashA list all current valuesbull sysctl ndashp file_name load the sysctl setting from a configuration
filebull sysctl ndashw variable=value change the value of the parameter
Transport Layer 3-104
SomeTCP Parameters in Linux Kerneltcp_syn_retries
Number of SYN packets the kernel will send before giving up on the new connection
tcp_synack_retriesnumber of SYN+ACK packets sent before the kernel gives up on the connection
tcp_window_scalingMaximum window size of 65535 bytes not enough for for really fast networks The window scaling options allows for almost gigabyte windows which is good for connections with large delay-bandwidth product
tcp_max_syn_backlogMaximal number of remembered connection requests which still did not receive an acknowledgment from connecting client
tcp_fin_timeoutHow many seconds to wait for a final FIN packet before the socket is closed required to prevent denial-of-service (DoS) attacks Default value is 60 seconds
Transport Layer 3-105
SomeTCP Parameters in Linux Kerneltcp_rmem
This is a vector of 3 integers [min default max] These parameters are used by TCP to dynamically adjust receive buffer sizesmin - minimum size of the receive buffer used by each TCP socket The default value is 4K default - the default size of the receive buffer for a TCP socket The default value is 87380 bytes and is lowered to 43689 in low memory systems If larger receive buffer sizes are desired this value should be increased max - the maximum size of the receive buffer used by each TCP socket The default value of 873802 bytes is lowered to 87380 in low memory systems
tcp_smemSend buffer parameters [min default max] similar to tcp_rmem
- Chapter 3 Transport Layer
- Transport services and protocols
- Transport vs network layer
- Internet transport-layer protocols
- Multiplexingdemultiplexing
- How demultiplexing works
- Connectionless demultiplexing
- Connection-oriented demux
- Connection-oriented demux (cont)
- Connection-oriented demux Threaded Web Server
- UDP User Datagram Protocol [RFC 768]
- UDP more
- UDP checksum
- Principles of Reliable data transfer
- Reliable data transfer getting started
- Reliable data transfer getting started
- Rdt10 reliable transfer over a reliable channel
- Rdt20 channel with bit errors
- rdt20 FSM specification
- rdt20 operation with no errors
- rdt20 error scenario
- rdt20 has a fatal flaw
- rdt21 sender handles garbled ACKNAKs
- rdt21 receiver handles garbled ACKNAKs
- rdt21 discussion
- rdt22 a NAK-free protocol
- rdt22 sender receiver fragments
- rdt30 channels with errors and loss
- rdt30 sender
- rdt30 in action
- rdt30 in action
- Performance of rdt30
- rdt30 stop-and-wait operation
- Pipelined protocols
- Pipelining increased utilization
- Go-Back-N
- GBN sender extended FSM
- GBN receiver extended FSM
- GBN inaction
- Selective Repeat
- Selective repeat sender receiver windows
- Selective repeat
- Selective repeat in action
- Selective repeat dilemma
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- TCP Overview RFCs 793 1122 1323 2018 2581
- TCP segment structure
- TCP seq rsquos and ACKs
- TCP Round Trip Time and Timeout
- TCP Round Trip Time and Timeout
- Example RTT estimation
- TCP Round Trip Time and Timeout
- TCP reliable data transfer
- TCP sender events
- TCP sender(simplified)
- TCP retransmission scenarios
- TCP retransmission scenarios (more)
- TCP ACK generation [RFC 1122 RFC 2581]
- Fast Retransmit
- Fast Retransmit
- Fast retransmit algorithm
- TCP Flow Control
- TCP Flow control how it works
- Sliding Window Flow Control Example
- Principles of Congestion Control
- Causescosts of congestion scenario 1
- Causescosts of congestion scenario 2
- Causescosts of congestion scenario 2
- Causescosts of congestion scenario 3
- Causescosts of congestion scenario 3
- Approaches towards congestion control
- TCP Congestion Control
- TCP congestion control bandwidth probing
- TCP Congestion Control details
- TCP Congestion Control more details
- TCP Slow Start Phase
- Slow Start Example
- TCP Congestion Avoidance Phase
- Congestion Avoidance
- Example Slow StartCongestion Avoidance
- Slow Start Congestion Avoidance
- Responses to Congestion
- Fast Recovery (differentiation btwn two loss events)
- TCP Congestion Control
- Popular ldquoflavorsrdquo of TCP
- Summary TCP Congestion Control
- TCP Congestion Control Summary
- TCP throughput
- TCP Futures TCP over ldquolong fat pipesrdquo
- TCP Fairness
- Why is TCP fair
- Fairness (more)
- TCP Connection Management
- TCP Connection Management (cont)
- TCP Connection Management (cont)
- TCP Connection Management (cont)
- Tuning TCPIP Parameters
- SomeTCP Parameters in Linux Kernel
- SomeTCP Parameters in Linux Kernel
-
Transport Layer 3-49
Sequence Number vs Window SizeSuppose we use k bits to represent SNQuestion Whatrsquos the minimum number of bits k necessary for a window size of N
sender
receiver
Selective Repeat
rcv_base
snd_base=rcv_base
Q For a given rcv_base whatrsquos the largest possible value for snd_baseA If all the last N ACKs sent by the receiver are received
snd_base = rcv_base (same as go_back-N)rcv_base+N-1
senderrsquos window
receiverrsquos window
rcv_base+N-1
Transport Layer 3-50
Sequence Number vs Window SizeSuppose we use k bits to represent SNQuestion Whatrsquos the minimum number of bits k necessary for a window size of N
sender
receiver
Selective Repeat
rcv_base
snd_base=rcv_base-N
Q For a given rcv_base whatrsquos the smallest possible value for snd_baseA If all the last N ACKs sent by the receiver are not received
snd_base = rcv_base-N (same as Go-Back-N)rcv_base-1
senderrsquos window
rcv_base
receiverrsquos window
rcv_base+N-1
Transport Layer 3-51
Sequence Number vs Window Size
sender
receiver
Selective Repeat
snd_base=rcv_base-N
All SNs in the interval [rcv_base-Nrcv_base+N-1] (an interval of size 2N) can be received by the receiver Since the receiver should be able to distinguish between all packets in this interval and take corresponding action there should be no two packets within thisinterval having the same SN Therefore
2k ge 2Nrcv_base+N-1
rcv_basercv_base
receiverrsquos window
rcv_base+N-1
Transport Layer 3-52
TCP Overview RFCs 793 1122 1323 2018 2581
full duplex databi-directional data flow in same connectionMSS maximum segment size
connection-orientedhandshaking (exchange of control msgs) initrsquossender receiver state before data exchange
flow controlledsender will not overwhelm receiver
point-to-pointone sender one receiver
reliable in-order byte stream
no ldquomessage boundariesrdquopipelined
TCP congestion and flow control set window size
send amp receive buffers
socketdoor
TCPsend buffer
TCPreceive buffer
socketdoor
segment
applicationwrites data
applicationreads data
Transport Layer 3-53
TCP segment structure
source port dest port
32 bits
applicationdata
(variable length)
sequence numberacknowledgement number
Receive windowUrg data pnterchecksum
FSRPAUheadlen
notused
Options (variable length)
URG urgent data (generally not used)
ACK ACK valid
PSH push data now(generally not used)
RST SYN FINconnection estab(setup teardown
commands)
bytes rcvr willingto accept
Internetchecksum
(as in UDP)
countingby bytes of data(not segments)
Transport Layer 3-54
TCP seq rsquos and ACKsSeq rsquos
byte stream ldquonumberrdquo of first byte in segmentrsquos dataACKs
seq of next byte expected from other sidecumulative ACK
Q how receiver handles out-of-order segmentsA TCP spec doesnrsquot say - up to implementationWidely used implementations of TCP buffer out-of-order segments
Transport Layer 3-55
TCP Round Trip Time and Timeout
Q how to set TCP timeout valuelonger than RTT
but RTT variestoo short premature timeout
unnecessary retransmissions
too long slow reaction to segment loss
Q how to estimate RTTSampleRTT measured time from segment transmission until ACK receipt
ignore retransmissionsSampleRTT will vary want estimated RTT ldquosmootherrdquo
average several recent measurements not just current SampleRTT
Transport Layer 3-56
TCP Round Trip Time and Timeout
EstimatedRTT = (1- α)EstimatedRTT + αSampleRTT
Exponential weighted moving averageinfluence of past sample decreases exponentially fasttypical value α = 0125
Transport Layer 3-57
Example RTT estimationRTT gaiacsumassedu to fantasiaeurecomfr
100
150
200
250
300
350
1 8 15 22 29 36 43 50 57 64 71 78 85 92 99 106
time (seconnds)
RTT
(mill
iseco
nds)
SampleRTT Estimated RTT
Transport Layer 3-58
TCP Round Trip Time and TimeoutSetting the timeout
EstimatedRTT plus ldquosafety marginrdquolarge variation in EstimatedRTT -gt larger safety margin
first estimate of how much SampleRTT deviates from EstimatedRTT
TimeoutInterval = EstimatedRTT + 4DevRTT
DevRTT = (1-β)DevRTT +β|SampleRTT-EstimatedRTT|
(typically β = 025)
Then set timeout interval
Transport Layer 3-59
TCP reliable data transfer
TCP creates rdtservice on top of IPrsquos unreliable servicePipelined segmentsCumulative acksTCP uses single retransmission timer however it just retransmits the first segment in the window
Retransmissions are triggered by
timeout eventsduplicate acks
Initially consider simplified TCP sender
ignore duplicate acksignore flow control congestion control
Transport Layer 3-60
TCP sender eventsdata rcvd from app
Create segment with seq seq is byte-stream number of first data byte in segmentstart timer if not already running (think of timer as for oldest unacked segment)expiration interval TimeOutInterval
timeoutretransmit segment that caused timeout (first segment in the window)restart timer
Ack rcvdIf acknowledges previously unacked segments
update what is known to be ackedstart timer if there are outstanding segments
Transport Layer 3-61
TCP sender(simplified)
NextSeqNum = InitialSeqNumSendBase = InitialSeqNum
loop (forever) switch(event)
event data received from application above create TCP segment with sequence number NextSeqNumif (timer currently not running)
start timerpass segment to IP NextSeqNum = NextSeqNum + length(data)
event timer timeoutretransmit not-yet-acknowledged segment with
smallest sequence numberstart timer
event ACK received with ACK field value of y if (y gt SendBase)
SendBase = yif (there are currently not-yet-acknowledged segments)
start timer
end of loop forever
Commentbull SendBase-1 last cumulatively ackrsquoed byteExamplebull SendBase-1 = 71y= 73 so the rcvrwants 73+ y gt SendBase sothat new data is acked
Transport Layer 3-62
TCP retransmission scenariosHost A
Seq=100 20 bytes data
ACK=100
timepremature timeout
Host B
Seq=92 8 bytes data
ACK=120
Seq=92 8 bytes data
Seq=
92 t
imeo
ut
ACK=120
Host A
Seq=92 8 bytes data
ACK=100
loss
tim
eout
lost ACK scenario
Host B
X
Seq=92 8 bytes data
ACK=100
time
Seq=
92 t
imeo
utSendBase
= 100
SendBase= 120
SendBase= 120
Sendbase= 100
Transport Layer 3-63
TCP retransmission scenarios (more)Host A
Seq=92 8 bytes data
ACK=100
loss
tim
eout
Cumulative ACK scenario
Host B
X
Seq=100 20 bytes data
ACK=120
time
SendBase= 120
Transport Layer 3-64
TCP ACK generation [RFC 1122 RFC 2581]
Event at Receiver
Arrival of in-order segment withexpected seq All data up toexpected seq already ACKed
Arrival of in-order segment withexpected seq One other segment has ACK pending
Arrival of out-of-order segmenthigher-than-expect seq Gap detected
Arrival of segment that partially or completely fills gap
TCP Receiver action
Delayed ACK Wait up to 500msfor next segment If no next segmentsend ACK
Immediately send single cumulative ACK ACKing both in-order segments
Immediately send duplicate ACK indicating seq of next expected byte
Immediate send ACK provided thatsegment startsat lower end of gap
Transport Layer 3-65
Fast Retransmit
Time-out period often relatively long
long delay before resending lost packet
Detect lost segments via duplicate ACKs
Sender often sends many segments back-to-backIf segment is lost there will likely be many duplicate ACKs
If sender receives 3 ACKs for the same data it supposes that segment after ACKeddata was lost
fast retransmit resend segment before timer expires
Transport Layer 3-66
Fast RetransmitResend a segment after 3 duplicate ACKs since a duplicate ACK means that an out-of sequence segment was receivedduplicate ACKs due to packet reorderingif window is small donrsquot get duplicate ACKs
Host A
tim
eout
Host B
time
X
resend seq X2
seq x1seq x2seq x3seq x4seq x5
ACK x1
ACK x1ACK x1ACK x1
tripleduplicate
ACKs
Transport Layer 3-67
event ACK received with ACK field value of y if (y gt SendBase)
SendBase = yif (there are currently not-yet-acknowledged segments)
start timer
else increment count of dup ACKs received for yif (count of dup ACKs received for y = 3)
resend segment with sequence number y
Fast retransmit algorithm
a duplicate ACK for already ACKed segment
fast retransmit
Transport Layer 3-68
TCP Flow Control
receive side of TCP connection has a receive buffer
speed-matching service matching the send rate to the receiving apprsquos drain rate
app process may be slow at reading from buffer
sender wonrsquot overflowreceiverrsquos buffer by
transmitting too muchtoo fast
flow control
Transport Layer 3-69
TCP Flow control how it works
(Suppose TCP receiver discards out-of-order segments)spare room in buffer
= RcvWin
= RcvBuffer-[LastByteRcvd -LastByteRead]
Rcvr advertises spare room by including value of RcvWin in segmentsSender limits unACKeddata to RcvWin
guarantees receive buffer doesnrsquot overflow
Transport Layer 3-70
Sliding Window Flow Control Example
3K
2K SeqNo=0
ReceiverBuffer
0 4KSendersends 2Kof data
2K
AckNo=2048 RcvWin=2048Sendersends 2Kof data 2K SeqNo=2048
4K
AckNo=4096 RcvWin=0
AckNo=4096 RcvWin=1024
Sender blocked
Transport Layer 3-71
Principles of Congestion Control
Congestioninformally ldquotoo many sources sending too much data too fast for network to handlerdquodifferent from flow controlmanifestations
lost packets (buffer overflow at routers)long delays (queueing in router buffers)
a top-10 problem
Transport Layer 3-72
Causescosts of congestion scenario 1
two senders two receiversone router infinite buffers no retransmission
large delays when congestedmaximum achievable throughput
unlimited shared output link buffers
Host Aλin original data
Host B
λout
Transport Layer 3-73
Causescosts of congestion scenario 2
one router finite buffers sender retransmission of lost packet
finite shared output link buffers
Host A λin original data
Host B
λout
λin original data plus retransmitted data
Transport Layer 3-74
Causescosts of congestion scenario 2always (goodput)ldquoperfectrdquo retransmission only when loss
retransmission of delayed (not lost) packet makes larger(than perfect case) for same
λin
λout=
λin
λoutgtλ
inλout
ldquocostsrdquo of congestionmore work (retrans) for given ldquogoodputrdquounneeded retransmissions link carries multiple copies of pkt
R2
R2λin
λ out
b
R2
R2λin
λ out
a
R2
R2λin
λ out
c
R4
R3
Transport Layer 3-75
Causescosts of congestion scenario 3four sendersmultihop pathstimeoutretransmit
λin
Q what happens as and increase λ
in
finite shared output link buffers
Host Aλin original data
Host B
λout
λin original data plus retransmitted data
Transport Layer 3-76
Causescosts of congestion scenario 3
another ldquocostrdquo of congestionwhen packet dropped any ldquoupstream transmission capacity used for that packet was wasted
Host A
Host B
λou
t
Transport Layer 3-77
Approaches towards congestion control
End-end congestion controlno explicit feedback from networkcongestion inferred from end-system observed loss delayapproach taken by TCP
Network-assisted congestion controlrouters provide feedback to end systems
single bit indicating congestion (SNA DECbit TCPIP ECN ATM)explicit rate sender should send at
Two broad approaches towards congestion control
Transport Layer 3-78
TCP Congestion Control
end-end control (no network assistance)sender limits transmissionLastByteSent-LastByteAcked
le CongWin
CongWin is dynamic function of perceived network congestion
How does sender perceive congestionloss event = timeout or3 duplicate acksTCP sender reduces rate (CongWin) after loss event
two modes of operationSlow Start (SS)Congestion avoidance (CA) or Additive Increase Multiplicative Decrease (AIMD)
Transport Layer 3-79
TCP congestion control bandwidth probing
ldquoprobing for bandwidthrdquo increase transmission rate on receipt of ACK until eventually loss occurs then decrease transmission rate
continue to increase on ACK decrease on loss (since available bandwidth is changing depending on other connections in network)
ACKs being received so increase rate
X
X
XX
X loss so decrease rate
send
ing
rate
time
Q how fast to increasedecreasedetails to follow
TCPrsquosldquosawtoothrdquobehavior
Transport Layer 3-80
TCP Congestion Control details
sender limits rate by limiting number of unACKed bytes ldquoin pipelinerdquo
cwnd differs from rwnd (how why)sender limited by min(cwndrwnd)
roughly
cwnd is dynamic function of perceived network congestion
rate = cwndRTT bytessec
LastByteSent-LastByteAcked le cwnd
cwndbytes
RTT
ACK(s)
Transport Layer 3-81
TCP Congestion Control more details
segment loss event reducing cwndtimeout no response from receiver
cut cwnd to 13 duplicate ACKs at least some segments getting through (recall fast retransmit)
cut cwnd in half less aggressively than on timeout
ACK received increase cwndTwo modes of operation
slowstart phase bull increase exponentially
fast (despite name) at connection start or following timeout
congestion avoidance bull increase linearly
Transport Layer 3-82
TCP Slow Start Phasewhen connection begins cwnd = 1 MSS
example MSS = 500 bytes amp RTT = 200 msecinitial rate = 20 kbps
available bandwidth may be gtgt MSSRTT
desirable to quickly ramp up to respectable rate
increase rate exponentially until first loss event or when threshold reached
double cwnd every RTTdone by incrementing cwnd by 1 for every ACK received
Host A
one segment
RTT
Host B
time
two segments
four segments
Transport Layer 3-83
Slow Start ExampleThe congestion window size grows very rapidly
For every ACK we increase CongWin by 1 irrespective of the number of segments ACKrsquoeddouble CongWinevery RTTinitial rate is slow but ramps up exponentially fast
TCP slows down the increase of CongWinwhen CongWin gt ssthresh
segment 1
ACK for segment 1
cwnd = 1
cwnd = 2 segment 2segment 3
ACK for segments 2
cwnd = 4 segment 4segment 5segment 6
ACK for segments 4
cwnd = 7
ACK for segments 3
ACK for segments 5
ACK for segments 6
cwnd = 3
cwnd = 5
cwnd = 6ACK for segments 7
cwnd = 8
segment 7
Transport Layer 3-84
TCP Congestion Avoidance Phase
when cwnd gt ssthreshgrow cwnd linearly
increase cwnd by 1 MSS per RTT approach possible congestion slower than in slowstartimplementation cwnd= cwnd + MSScwndfor each ACK received
ACKs increase cwndby 1 MSS per RTT additive increaseloss cut cwnd in half (non-timeout-detected loss ) multiplicative decrease
AIMD
AIMD Additive IncreaseMultiplicative Decrease
Transport Layer 3-85
Congestion AvoidanceCongestion avoidance phase is started if CongWin has reached the slow-start threshold value
If CongWin gt= ssthresh then each time an ACK is received increment CongWin as follows
bull CongWin = CongWin + 1CongWin (CongWin in segments)
bull In actual TCP implementation CongWin is in BytesCongWin = CongWin + MSS (MSSCongWin)
So CongWin is increased by one only if all CongWinsegments have been acknowledged
Transport Layer 3-86
Example Slow StartCongestion AvoidanceAssume that
ssthresh = 8
cwnd = 1
cwnd = 2
cwnd = 4
cwnd = 8
cwnd = 9
cwnd = 10
02468
101214
t=0
t=2
t=4
t=6
Roundtrip times
Cw
nd(in
seg
men
ts)
ssthresh
cwnd = 3
cwnd = 5cwnd = 6cwnd = 7
Transport Layer 3-87
Slow Start Congestion AvoidanceA typical plot of CongWin for a TCP connection
(MSS = 1500 bytes) with TCP Tahoe
SS
CA
ssthresh
Transport Layer 3-88
Responses to CongestionTCP assumes there is congestion if it detects a packet lossA TCP sender can detect lost packets via loss events
bull Timeout of a retransmission timerbull Receipt of 3 duplicate ACKs (fast retransmit)
TCP interprets a Timeout as a binary congestion signal When a timeout occurs the sender performs
ssthresh is set to half the current size of the congestion window
ssthresh = CongWin 2CongWin is reset to one
CongWin = 1and slow-start is entered
Transport Layer 3-89
Fast Recovery (differentiation btwn two loss events) After 3 dup ACKs (fast Retransmit)
ssthresh = CongWin2CongWin = CongWin2window then grows linearly
But after timeout eventCongWin = 1 MSS window then grows exponentiallyto the threshold then grows linearly
bull 3 dup ACKs indicates network capable of delivering some segmentsbull timeout before 3 dup ACKs is ldquomore alarmingrdquo
Philosophy
3-90
TCP Congestion ControlInitially
CongWin = 1ssthresh = advertised window size
New Ack receivedif (CongWin lt ssthresh) Slow Start
CongWin = CongWin + 1else Congestion Avoidance
CongWin = CongWin + 1CongWinTimeout
ssthresh = CongWin2CongWin = 1
Fast Retransmissionssthresh = CongWin2CongWin = CongWin2
Slow Start (exponential increase phase) is continued until CongWin reaches half of the level where the loss event occurred last time CongWin is increased slowly after (linear increase in Congestion Avoidance phase)
Transport Layer 3-91
Popular ldquoflavorsrdquo of TCP
ssthresh
ssthresh
TCP Tahoe
TCP Reno
Transmission round
cwnd
win
dow
siz
e (in
seg
men
ts)
Transport Layer 3-92
Summary TCP Congestion ControlWhen CongWin is below Threshold sender in slow-start phase window grows exponentiallyWhen CongWin is above Threshold sender is in congestion-avoidance phase window grows linearlyWhen a triple duplicate ACK occurs Threshold set to CongWin2 and CongWin set to ThresholdWhen timeout occurs Threshold set to CongWin2 and CongWin is set to 1 MSS The actual sender window size is determined based on the congestion and flow control algorithms
SenderWin=min(RcvWinCongWin)
Transport Layer 3-93
TCP Congestion Control SummaryEvent State TCP Sender Action Commentary
ACK receipt for previously unackeddata
Slow Start (SS)
CongWin = CongWin + MSS If (CongWin gt Threshold)
set state to ldquoCongestion Avoidancerdquo
Resulting in a doubling of CongWin every RTT
ACK receipt for previously unackeddata
CongestionAvoidance (CA)
CongWin = CongWin+MSS (MSSCongWin)
Additive increase resulting in increase of CongWin by 1 MSS every RTT
Loss event detected by triple duplicate ACK
SS or CA Threshold = CongWin2 CongWin = ThresholdSet state to ldquoCongestion Avoidancerdquo
Fast recovery implementing multiplicative decrease CongWin will not drop below 1 MSS
Timeout SS or CA Threshold = CongWin2 CongWin = 1 MSSSet state to ldquoSlow Startrdquo
Enter slow start
Duplicate ACK
SS or CA Increment duplicate ACK count for segment being acked
CongWin and Threshold not changed
Transport Layer 3-94
TCP throughput
Q whatrsquos average throughout of TCP as function of window size RTT
ignoring slow startlet W be window size when loss occurs
when window is W throughput is WRTTjust after loss window drops to W2 throughput to W2RTT average throughout 75 WRTT
Transport Layer 3-95
TCP Futures TCP over ldquolong fat pipesrdquo
example 1500 byte segments 100ms RTT want 10 Gbps throughputrequires window size W = 83333 in-flight segmentsthroughput in terms of loss rate
L = 210-10 Wownew versions of TCP for high-speed
LRTTMSSsdot221
Transport Layer 3-96
Fairness goal if K TCP sessions share same bottleneck link of bandwidth R each should have average rate of RK
TCP connection 1
bottleneckrouter
capacity R
TCP connection 2
TCP Fairness
Transport Layer 3-97
Why is TCP fairTwo competing sessions
Additive increase gives slope of 1 as throughout increasesmultiplicative decrease decreases throughput proportionally
R
R
equal bandwidth share
Connection 1 throughput
Conn
ecti
on 2
thr
ough
p ut
congestion avoidance additive increaseloss decrease window by factor of 2
congestion avoidance additive increaseloss decrease window by factor of 2
Transport Layer 3-98
Fairness (more)Fairness and UDP
Multimedia apps often do not use TCP
do not want rate throttled by congestion control
Instead use UDPpump audiovideo at constant rate tolerate packet loss
Research area TCP friendly
Fairness and parallel TCP connectionsnothing prevents app from opening parallel cnctionsbetween 2 hostsWeb browsers do this Example link of rate R supporting 9 cnctions
new app asks for 1 TCP gets rate R10new app asks for 11 TCPs gets R2
Transport Layer 3-99
TCP Connection ManagementRecall TCP sender receiver
establish ldquoconnectionrdquobefore exchanging data segmentsinitialize TCP variables
seq sbuffers flow control info (eg RcvWindow)
client connection initiatorSocket clientSocket = new Socket(hostnameport
number)
server contacted by clientSocket connectionSocket = welcomeSocketaccept()
Three way handshakeStep 1 client host sends TCP
SYN segment to serverspecifies initial seq no data
Step 2 server host receives SYN replies with SYNACK segment
server allocates buffersspecifies server initial seq
Step 3 client receives SYNACK replies with ACK segment which may contain data
Transport Layer 3-100
TCP Connection Management (cont)
Closing a connection
client closes socketclientSocketclose()
Step 1 client end system sends TCP FIN control segment to server
Step 2 server receives FIN replies with ACK Closes connection sends FIN
client
FIN
server
ACK
ACK
FIN
close
close
closed
tim
ed w
ait
Transport Layer 3-101
TCP Connection Management (cont)
Step 3 client receives FIN replies with ACK
Enters ldquotimed waitrdquo -will respond with ACK to received FINs
Step 4 server receives ACK Connection closed
client
FIN
server
ACK
ACK
FIN
closing
closing
closed
tim
ed w
ait
closed
Transport Layer 3-102
TCP Connection Management (cont)
TCP clientlifecycle
TCP serverlifecycle
Transport Layer 3-103
Tuning TCPIP Parameters TCPIP parameters
A set of default values may not be optimal for all applicationsThe network administrator may wish to turn on or off some TCPIP functions for performance or security considerations
Many Unix and Linux systems provide some flexibility in tuning the TCPIP kernelsbinsysctl is used to configure the Linux kernel parameters at runtime
Default kernel configuration file is sbinsysctlconfFrequently used sysctl options
bull sysctl ndasha or sysctl ndashA list all current valuesbull sysctl ndashp file_name load the sysctl setting from a configuration
filebull sysctl ndashw variable=value change the value of the parameter
Transport Layer 3-104
SomeTCP Parameters in Linux Kerneltcp_syn_retries
Number of SYN packets the kernel will send before giving up on the new connection
tcp_synack_retriesnumber of SYN+ACK packets sent before the kernel gives up on the connection
tcp_window_scalingMaximum window size of 65535 bytes not enough for for really fast networks The window scaling options allows for almost gigabyte windows which is good for connections with large delay-bandwidth product
tcp_max_syn_backlogMaximal number of remembered connection requests which still did not receive an acknowledgment from connecting client
tcp_fin_timeoutHow many seconds to wait for a final FIN packet before the socket is closed required to prevent denial-of-service (DoS) attacks Default value is 60 seconds
Transport Layer 3-105
SomeTCP Parameters in Linux Kerneltcp_rmem
This is a vector of 3 integers [min default max] These parameters are used by TCP to dynamically adjust receive buffer sizesmin - minimum size of the receive buffer used by each TCP socket The default value is 4K default - the default size of the receive buffer for a TCP socket The default value is 87380 bytes and is lowered to 43689 in low memory systems If larger receive buffer sizes are desired this value should be increased max - the maximum size of the receive buffer used by each TCP socket The default value of 873802 bytes is lowered to 87380 in low memory systems
tcp_smemSend buffer parameters [min default max] similar to tcp_rmem
- Chapter 3 Transport Layer
- Transport services and protocols
- Transport vs network layer
- Internet transport-layer protocols
- Multiplexingdemultiplexing
- How demultiplexing works
- Connectionless demultiplexing
- Connection-oriented demux
- Connection-oriented demux (cont)
- Connection-oriented demux Threaded Web Server
- UDP User Datagram Protocol [RFC 768]
- UDP more
- UDP checksum
- Principles of Reliable data transfer
- Reliable data transfer getting started
- Reliable data transfer getting started
- Rdt10 reliable transfer over a reliable channel
- Rdt20 channel with bit errors
- rdt20 FSM specification
- rdt20 operation with no errors
- rdt20 error scenario
- rdt20 has a fatal flaw
- rdt21 sender handles garbled ACKNAKs
- rdt21 receiver handles garbled ACKNAKs
- rdt21 discussion
- rdt22 a NAK-free protocol
- rdt22 sender receiver fragments
- rdt30 channels with errors and loss
- rdt30 sender
- rdt30 in action
- rdt30 in action
- Performance of rdt30
- rdt30 stop-and-wait operation
- Pipelined protocols
- Pipelining increased utilization
- Go-Back-N
- GBN sender extended FSM
- GBN receiver extended FSM
- GBN inaction
- Selective Repeat
- Selective repeat sender receiver windows
- Selective repeat
- Selective repeat in action
- Selective repeat dilemma
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- TCP Overview RFCs 793 1122 1323 2018 2581
- TCP segment structure
- TCP seq rsquos and ACKs
- TCP Round Trip Time and Timeout
- TCP Round Trip Time and Timeout
- Example RTT estimation
- TCP Round Trip Time and Timeout
- TCP reliable data transfer
- TCP sender events
- TCP sender(simplified)
- TCP retransmission scenarios
- TCP retransmission scenarios (more)
- TCP ACK generation [RFC 1122 RFC 2581]
- Fast Retransmit
- Fast Retransmit
- Fast retransmit algorithm
- TCP Flow Control
- TCP Flow control how it works
- Sliding Window Flow Control Example
- Principles of Congestion Control
- Causescosts of congestion scenario 1
- Causescosts of congestion scenario 2
- Causescosts of congestion scenario 2
- Causescosts of congestion scenario 3
- Causescosts of congestion scenario 3
- Approaches towards congestion control
- TCP Congestion Control
- TCP congestion control bandwidth probing
- TCP Congestion Control details
- TCP Congestion Control more details
- TCP Slow Start Phase
- Slow Start Example
- TCP Congestion Avoidance Phase
- Congestion Avoidance
- Example Slow StartCongestion Avoidance
- Slow Start Congestion Avoidance
- Responses to Congestion
- Fast Recovery (differentiation btwn two loss events)
- TCP Congestion Control
- Popular ldquoflavorsrdquo of TCP
- Summary TCP Congestion Control
- TCP Congestion Control Summary
- TCP throughput
- TCP Futures TCP over ldquolong fat pipesrdquo
- TCP Fairness
- Why is TCP fair
- Fairness (more)
- TCP Connection Management
- TCP Connection Management (cont)
- TCP Connection Management (cont)
- TCP Connection Management (cont)
- Tuning TCPIP Parameters
- SomeTCP Parameters in Linux Kernel
- SomeTCP Parameters in Linux Kernel
-
Transport Layer 3-50
Sequence Number vs Window SizeSuppose we use k bits to represent SNQuestion Whatrsquos the minimum number of bits k necessary for a window size of N
sender
receiver
Selective Repeat
rcv_base
snd_base=rcv_base-N
Q For a given rcv_base whatrsquos the smallest possible value for snd_baseA If all the last N ACKs sent by the receiver are not received
snd_base = rcv_base-N (same as Go-Back-N)rcv_base-1
senderrsquos window
rcv_base
receiverrsquos window
rcv_base+N-1
Transport Layer 3-51
Sequence Number vs Window Size
sender
receiver
Selective Repeat
snd_base=rcv_base-N
All SNs in the interval [rcv_base-Nrcv_base+N-1] (an interval of size 2N) can be received by the receiver Since the receiver should be able to distinguish between all packets in this interval and take corresponding action there should be no two packets within thisinterval having the same SN Therefore
2k ge 2Nrcv_base+N-1
rcv_basercv_base
receiverrsquos window
rcv_base+N-1
Transport Layer 3-52
TCP Overview RFCs 793 1122 1323 2018 2581
full duplex databi-directional data flow in same connectionMSS maximum segment size
connection-orientedhandshaking (exchange of control msgs) initrsquossender receiver state before data exchange
flow controlledsender will not overwhelm receiver
point-to-pointone sender one receiver
reliable in-order byte stream
no ldquomessage boundariesrdquopipelined
TCP congestion and flow control set window size
send amp receive buffers
socketdoor
TCPsend buffer
TCPreceive buffer
socketdoor
segment
applicationwrites data
applicationreads data
Transport Layer 3-53
TCP segment structure
source port dest port
32 bits
applicationdata
(variable length)
sequence numberacknowledgement number
Receive windowUrg data pnterchecksum
FSRPAUheadlen
notused
Options (variable length)
URG urgent data (generally not used)
ACK ACK valid
PSH push data now(generally not used)
RST SYN FINconnection estab(setup teardown
commands)
bytes rcvr willingto accept
Internetchecksum
(as in UDP)
countingby bytes of data(not segments)
Transport Layer 3-54
TCP seq rsquos and ACKsSeq rsquos
byte stream ldquonumberrdquo of first byte in segmentrsquos dataACKs
seq of next byte expected from other sidecumulative ACK
Q how receiver handles out-of-order segmentsA TCP spec doesnrsquot say - up to implementationWidely used implementations of TCP buffer out-of-order segments
Transport Layer 3-55
TCP Round Trip Time and Timeout
Q how to set TCP timeout valuelonger than RTT
but RTT variestoo short premature timeout
unnecessary retransmissions
too long slow reaction to segment loss
Q how to estimate RTTSampleRTT measured time from segment transmission until ACK receipt
ignore retransmissionsSampleRTT will vary want estimated RTT ldquosmootherrdquo
average several recent measurements not just current SampleRTT
Transport Layer 3-56
TCP Round Trip Time and Timeout
EstimatedRTT = (1- α)EstimatedRTT + αSampleRTT
Exponential weighted moving averageinfluence of past sample decreases exponentially fasttypical value α = 0125
Transport Layer 3-57
Example RTT estimationRTT gaiacsumassedu to fantasiaeurecomfr
100
150
200
250
300
350
1 8 15 22 29 36 43 50 57 64 71 78 85 92 99 106
time (seconnds)
RTT
(mill
iseco
nds)
SampleRTT Estimated RTT
Transport Layer 3-58
TCP Round Trip Time and TimeoutSetting the timeout
EstimatedRTT plus ldquosafety marginrdquolarge variation in EstimatedRTT -gt larger safety margin
first estimate of how much SampleRTT deviates from EstimatedRTT
TimeoutInterval = EstimatedRTT + 4DevRTT
DevRTT = (1-β)DevRTT +β|SampleRTT-EstimatedRTT|
(typically β = 025)
Then set timeout interval
Transport Layer 3-59
TCP reliable data transfer
TCP creates rdtservice on top of IPrsquos unreliable servicePipelined segmentsCumulative acksTCP uses single retransmission timer however it just retransmits the first segment in the window
Retransmissions are triggered by
timeout eventsduplicate acks
Initially consider simplified TCP sender
ignore duplicate acksignore flow control congestion control
Transport Layer 3-60
TCP sender eventsdata rcvd from app
Create segment with seq seq is byte-stream number of first data byte in segmentstart timer if not already running (think of timer as for oldest unacked segment)expiration interval TimeOutInterval
timeoutretransmit segment that caused timeout (first segment in the window)restart timer
Ack rcvdIf acknowledges previously unacked segments
update what is known to be ackedstart timer if there are outstanding segments
Transport Layer 3-61
TCP sender(simplified)
NextSeqNum = InitialSeqNumSendBase = InitialSeqNum
loop (forever) switch(event)
event data received from application above create TCP segment with sequence number NextSeqNumif (timer currently not running)
start timerpass segment to IP NextSeqNum = NextSeqNum + length(data)
event timer timeoutretransmit not-yet-acknowledged segment with
smallest sequence numberstart timer
event ACK received with ACK field value of y if (y gt SendBase)
SendBase = yif (there are currently not-yet-acknowledged segments)
start timer
end of loop forever
Commentbull SendBase-1 last cumulatively ackrsquoed byteExamplebull SendBase-1 = 71y= 73 so the rcvrwants 73+ y gt SendBase sothat new data is acked
Transport Layer 3-62
TCP retransmission scenariosHost A
Seq=100 20 bytes data
ACK=100
timepremature timeout
Host B
Seq=92 8 bytes data
ACK=120
Seq=92 8 bytes data
Seq=
92 t
imeo
ut
ACK=120
Host A
Seq=92 8 bytes data
ACK=100
loss
tim
eout
lost ACK scenario
Host B
X
Seq=92 8 bytes data
ACK=100
time
Seq=
92 t
imeo
utSendBase
= 100
SendBase= 120
SendBase= 120
Sendbase= 100
Transport Layer 3-63
TCP retransmission scenarios (more)Host A
Seq=92 8 bytes data
ACK=100
loss
tim
eout
Cumulative ACK scenario
Host B
X
Seq=100 20 bytes data
ACK=120
time
SendBase= 120
Transport Layer 3-64
TCP ACK generation [RFC 1122 RFC 2581]
Event at Receiver
Arrival of in-order segment withexpected seq All data up toexpected seq already ACKed
Arrival of in-order segment withexpected seq One other segment has ACK pending
Arrival of out-of-order segmenthigher-than-expect seq Gap detected
Arrival of segment that partially or completely fills gap
TCP Receiver action
Delayed ACK Wait up to 500msfor next segment If no next segmentsend ACK
Immediately send single cumulative ACK ACKing both in-order segments
Immediately send duplicate ACK indicating seq of next expected byte
Immediate send ACK provided thatsegment startsat lower end of gap
Transport Layer 3-65
Fast Retransmit
Time-out period often relatively long
long delay before resending lost packet
Detect lost segments via duplicate ACKs
Sender often sends many segments back-to-backIf segment is lost there will likely be many duplicate ACKs
If sender receives 3 ACKs for the same data it supposes that segment after ACKeddata was lost
fast retransmit resend segment before timer expires
Transport Layer 3-66
Fast RetransmitResend a segment after 3 duplicate ACKs since a duplicate ACK means that an out-of sequence segment was receivedduplicate ACKs due to packet reorderingif window is small donrsquot get duplicate ACKs
Host A
tim
eout
Host B
time
X
resend seq X2
seq x1seq x2seq x3seq x4seq x5
ACK x1
ACK x1ACK x1ACK x1
tripleduplicate
ACKs
Transport Layer 3-67
event ACK received with ACK field value of y if (y gt SendBase)
SendBase = yif (there are currently not-yet-acknowledged segments)
start timer
else increment count of dup ACKs received for yif (count of dup ACKs received for y = 3)
resend segment with sequence number y
Fast retransmit algorithm
a duplicate ACK for already ACKed segment
fast retransmit
Transport Layer 3-68
TCP Flow Control
receive side of TCP connection has a receive buffer
speed-matching service matching the send rate to the receiving apprsquos drain rate
app process may be slow at reading from buffer
sender wonrsquot overflowreceiverrsquos buffer by
transmitting too muchtoo fast
flow control
Transport Layer 3-69
TCP Flow control how it works
(Suppose TCP receiver discards out-of-order segments)spare room in buffer
= RcvWin
= RcvBuffer-[LastByteRcvd -LastByteRead]
Rcvr advertises spare room by including value of RcvWin in segmentsSender limits unACKeddata to RcvWin
guarantees receive buffer doesnrsquot overflow
Transport Layer 3-70
Sliding Window Flow Control Example
3K
2K SeqNo=0
ReceiverBuffer
0 4KSendersends 2Kof data
2K
AckNo=2048 RcvWin=2048Sendersends 2Kof data 2K SeqNo=2048
4K
AckNo=4096 RcvWin=0
AckNo=4096 RcvWin=1024
Sender blocked
Transport Layer 3-71
Principles of Congestion Control
Congestioninformally ldquotoo many sources sending too much data too fast for network to handlerdquodifferent from flow controlmanifestations
lost packets (buffer overflow at routers)long delays (queueing in router buffers)
a top-10 problem
Transport Layer 3-72
Causescosts of congestion scenario 1
two senders two receiversone router infinite buffers no retransmission
large delays when congestedmaximum achievable throughput
unlimited shared output link buffers
Host Aλin original data
Host B
λout
Transport Layer 3-73
Causescosts of congestion scenario 2
one router finite buffers sender retransmission of lost packet
finite shared output link buffers
Host A λin original data
Host B
λout
λin original data plus retransmitted data
Transport Layer 3-74
Causescosts of congestion scenario 2always (goodput)ldquoperfectrdquo retransmission only when loss
retransmission of delayed (not lost) packet makes larger(than perfect case) for same
λin
λout=
λin
λoutgtλ
inλout
ldquocostsrdquo of congestionmore work (retrans) for given ldquogoodputrdquounneeded retransmissions link carries multiple copies of pkt
R2
R2λin
λ out
b
R2
R2λin
λ out
a
R2
R2λin
λ out
c
R4
R3
Transport Layer 3-75
Causescosts of congestion scenario 3four sendersmultihop pathstimeoutretransmit
λin
Q what happens as and increase λ
in
finite shared output link buffers
Host Aλin original data
Host B
λout
λin original data plus retransmitted data
Transport Layer 3-76
Causescosts of congestion scenario 3
another ldquocostrdquo of congestionwhen packet dropped any ldquoupstream transmission capacity used for that packet was wasted
Host A
Host B
λou
t
Transport Layer 3-77
Approaches towards congestion control
End-end congestion controlno explicit feedback from networkcongestion inferred from end-system observed loss delayapproach taken by TCP
Network-assisted congestion controlrouters provide feedback to end systems
single bit indicating congestion (SNA DECbit TCPIP ECN ATM)explicit rate sender should send at
Two broad approaches towards congestion control
Transport Layer 3-78
TCP Congestion Control
end-end control (no network assistance)sender limits transmissionLastByteSent-LastByteAcked
le CongWin
CongWin is dynamic function of perceived network congestion
How does sender perceive congestionloss event = timeout or3 duplicate acksTCP sender reduces rate (CongWin) after loss event
two modes of operationSlow Start (SS)Congestion avoidance (CA) or Additive Increase Multiplicative Decrease (AIMD)
Transport Layer 3-79
TCP congestion control bandwidth probing
ldquoprobing for bandwidthrdquo increase transmission rate on receipt of ACK until eventually loss occurs then decrease transmission rate
continue to increase on ACK decrease on loss (since available bandwidth is changing depending on other connections in network)
ACKs being received so increase rate
X
X
XX
X loss so decrease rate
send
ing
rate
time
Q how fast to increasedecreasedetails to follow
TCPrsquosldquosawtoothrdquobehavior
Transport Layer 3-80
TCP Congestion Control details
sender limits rate by limiting number of unACKed bytes ldquoin pipelinerdquo
cwnd differs from rwnd (how why)sender limited by min(cwndrwnd)
roughly
cwnd is dynamic function of perceived network congestion
rate = cwndRTT bytessec
LastByteSent-LastByteAcked le cwnd
cwndbytes
RTT
ACK(s)
Transport Layer 3-81
TCP Congestion Control more details
segment loss event reducing cwndtimeout no response from receiver
cut cwnd to 13 duplicate ACKs at least some segments getting through (recall fast retransmit)
cut cwnd in half less aggressively than on timeout
ACK received increase cwndTwo modes of operation
slowstart phase bull increase exponentially
fast (despite name) at connection start or following timeout
congestion avoidance bull increase linearly
Transport Layer 3-82
TCP Slow Start Phasewhen connection begins cwnd = 1 MSS
example MSS = 500 bytes amp RTT = 200 msecinitial rate = 20 kbps
available bandwidth may be gtgt MSSRTT
desirable to quickly ramp up to respectable rate
increase rate exponentially until first loss event or when threshold reached
double cwnd every RTTdone by incrementing cwnd by 1 for every ACK received
Host A
one segment
RTT
Host B
time
two segments
four segments
Transport Layer 3-83
Slow Start ExampleThe congestion window size grows very rapidly
For every ACK we increase CongWin by 1 irrespective of the number of segments ACKrsquoeddouble CongWinevery RTTinitial rate is slow but ramps up exponentially fast
TCP slows down the increase of CongWinwhen CongWin gt ssthresh
segment 1
ACK for segment 1
cwnd = 1
cwnd = 2 segment 2segment 3
ACK for segments 2
cwnd = 4 segment 4segment 5segment 6
ACK for segments 4
cwnd = 7
ACK for segments 3
ACK for segments 5
ACK for segments 6
cwnd = 3
cwnd = 5
cwnd = 6ACK for segments 7
cwnd = 8
segment 7
Transport Layer 3-84
TCP Congestion Avoidance Phase
when cwnd gt ssthreshgrow cwnd linearly
increase cwnd by 1 MSS per RTT approach possible congestion slower than in slowstartimplementation cwnd= cwnd + MSScwndfor each ACK received
ACKs increase cwndby 1 MSS per RTT additive increaseloss cut cwnd in half (non-timeout-detected loss ) multiplicative decrease
AIMD
AIMD Additive IncreaseMultiplicative Decrease
Transport Layer 3-85
Congestion AvoidanceCongestion avoidance phase is started if CongWin has reached the slow-start threshold value
If CongWin gt= ssthresh then each time an ACK is received increment CongWin as follows
bull CongWin = CongWin + 1CongWin (CongWin in segments)
bull In actual TCP implementation CongWin is in BytesCongWin = CongWin + MSS (MSSCongWin)
So CongWin is increased by one only if all CongWinsegments have been acknowledged
Transport Layer 3-86
Example Slow StartCongestion AvoidanceAssume that
ssthresh = 8
cwnd = 1
cwnd = 2
cwnd = 4
cwnd = 8
cwnd = 9
cwnd = 10
02468
101214
t=0
t=2
t=4
t=6
Roundtrip times
Cw
nd(in
seg
men
ts)
ssthresh
cwnd = 3
cwnd = 5cwnd = 6cwnd = 7
Transport Layer 3-87
Slow Start Congestion AvoidanceA typical plot of CongWin for a TCP connection
(MSS = 1500 bytes) with TCP Tahoe
SS
CA
ssthresh
Transport Layer 3-88
Responses to CongestionTCP assumes there is congestion if it detects a packet lossA TCP sender can detect lost packets via loss events
bull Timeout of a retransmission timerbull Receipt of 3 duplicate ACKs (fast retransmit)
TCP interprets a Timeout as a binary congestion signal When a timeout occurs the sender performs
ssthresh is set to half the current size of the congestion window
ssthresh = CongWin 2CongWin is reset to one
CongWin = 1and slow-start is entered
Transport Layer 3-89
Fast Recovery (differentiation btwn two loss events) After 3 dup ACKs (fast Retransmit)
ssthresh = CongWin2CongWin = CongWin2window then grows linearly
But after timeout eventCongWin = 1 MSS window then grows exponentiallyto the threshold then grows linearly
bull 3 dup ACKs indicates network capable of delivering some segmentsbull timeout before 3 dup ACKs is ldquomore alarmingrdquo
Philosophy
3-90
TCP Congestion ControlInitially
CongWin = 1ssthresh = advertised window size
New Ack receivedif (CongWin lt ssthresh) Slow Start
CongWin = CongWin + 1else Congestion Avoidance
CongWin = CongWin + 1CongWinTimeout
ssthresh = CongWin2CongWin = 1
Fast Retransmissionssthresh = CongWin2CongWin = CongWin2
Slow Start (exponential increase phase) is continued until CongWin reaches half of the level where the loss event occurred last time CongWin is increased slowly after (linear increase in Congestion Avoidance phase)
Transport Layer 3-91
Popular ldquoflavorsrdquo of TCP
ssthresh
ssthresh
TCP Tahoe
TCP Reno
Transmission round
cwnd
win
dow
siz
e (in
seg
men
ts)
Transport Layer 3-92
Summary TCP Congestion ControlWhen CongWin is below Threshold sender in slow-start phase window grows exponentiallyWhen CongWin is above Threshold sender is in congestion-avoidance phase window grows linearlyWhen a triple duplicate ACK occurs Threshold set to CongWin2 and CongWin set to ThresholdWhen timeout occurs Threshold set to CongWin2 and CongWin is set to 1 MSS The actual sender window size is determined based on the congestion and flow control algorithms
SenderWin=min(RcvWinCongWin)
Transport Layer 3-93
TCP Congestion Control SummaryEvent State TCP Sender Action Commentary
ACK receipt for previously unackeddata
Slow Start (SS)
CongWin = CongWin + MSS If (CongWin gt Threshold)
set state to ldquoCongestion Avoidancerdquo
Resulting in a doubling of CongWin every RTT
ACK receipt for previously unackeddata
CongestionAvoidance (CA)
CongWin = CongWin+MSS (MSSCongWin)
Additive increase resulting in increase of CongWin by 1 MSS every RTT
Loss event detected by triple duplicate ACK
SS or CA Threshold = CongWin2 CongWin = ThresholdSet state to ldquoCongestion Avoidancerdquo
Fast recovery implementing multiplicative decrease CongWin will not drop below 1 MSS
Timeout SS or CA Threshold = CongWin2 CongWin = 1 MSSSet state to ldquoSlow Startrdquo
Enter slow start
Duplicate ACK
SS or CA Increment duplicate ACK count for segment being acked
CongWin and Threshold not changed
Transport Layer 3-94
TCP throughput
Q whatrsquos average throughout of TCP as function of window size RTT
ignoring slow startlet W be window size when loss occurs
when window is W throughput is WRTTjust after loss window drops to W2 throughput to W2RTT average throughout 75 WRTT
Transport Layer 3-95
TCP Futures TCP over ldquolong fat pipesrdquo
example 1500 byte segments 100ms RTT want 10 Gbps throughputrequires window size W = 83333 in-flight segmentsthroughput in terms of loss rate
L = 210-10 Wownew versions of TCP for high-speed
LRTTMSSsdot221
Transport Layer 3-96
Fairness goal if K TCP sessions share same bottleneck link of bandwidth R each should have average rate of RK
TCP connection 1
bottleneckrouter
capacity R
TCP connection 2
TCP Fairness
Transport Layer 3-97
Why is TCP fairTwo competing sessions
Additive increase gives slope of 1 as throughout increasesmultiplicative decrease decreases throughput proportionally
R
R
equal bandwidth share
Connection 1 throughput
Conn
ecti
on 2
thr
ough
p ut
congestion avoidance additive increaseloss decrease window by factor of 2
congestion avoidance additive increaseloss decrease window by factor of 2
Transport Layer 3-98
Fairness (more)Fairness and UDP
Multimedia apps often do not use TCP
do not want rate throttled by congestion control
Instead use UDPpump audiovideo at constant rate tolerate packet loss
Research area TCP friendly
Fairness and parallel TCP connectionsnothing prevents app from opening parallel cnctionsbetween 2 hostsWeb browsers do this Example link of rate R supporting 9 cnctions
new app asks for 1 TCP gets rate R10new app asks for 11 TCPs gets R2
Transport Layer 3-99
TCP Connection ManagementRecall TCP sender receiver
establish ldquoconnectionrdquobefore exchanging data segmentsinitialize TCP variables
seq sbuffers flow control info (eg RcvWindow)
client connection initiatorSocket clientSocket = new Socket(hostnameport
number)
server contacted by clientSocket connectionSocket = welcomeSocketaccept()
Three way handshakeStep 1 client host sends TCP
SYN segment to serverspecifies initial seq no data
Step 2 server host receives SYN replies with SYNACK segment
server allocates buffersspecifies server initial seq
Step 3 client receives SYNACK replies with ACK segment which may contain data
Transport Layer 3-100
TCP Connection Management (cont)
Closing a connection
client closes socketclientSocketclose()
Step 1 client end system sends TCP FIN control segment to server
Step 2 server receives FIN replies with ACK Closes connection sends FIN
client
FIN
server
ACK
ACK
FIN
close
close
closed
tim
ed w
ait
Transport Layer 3-101
TCP Connection Management (cont)
Step 3 client receives FIN replies with ACK
Enters ldquotimed waitrdquo -will respond with ACK to received FINs
Step 4 server receives ACK Connection closed
client
FIN
server
ACK
ACK
FIN
closing
closing
closed
tim
ed w
ait
closed
Transport Layer 3-102
TCP Connection Management (cont)
TCP clientlifecycle
TCP serverlifecycle
Transport Layer 3-103
Tuning TCPIP Parameters TCPIP parameters
A set of default values may not be optimal for all applicationsThe network administrator may wish to turn on or off some TCPIP functions for performance or security considerations
Many Unix and Linux systems provide some flexibility in tuning the TCPIP kernelsbinsysctl is used to configure the Linux kernel parameters at runtime
Default kernel configuration file is sbinsysctlconfFrequently used sysctl options
bull sysctl ndasha or sysctl ndashA list all current valuesbull sysctl ndashp file_name load the sysctl setting from a configuration
filebull sysctl ndashw variable=value change the value of the parameter
Transport Layer 3-104
SomeTCP Parameters in Linux Kerneltcp_syn_retries
Number of SYN packets the kernel will send before giving up on the new connection
tcp_synack_retriesnumber of SYN+ACK packets sent before the kernel gives up on the connection
tcp_window_scalingMaximum window size of 65535 bytes not enough for for really fast networks The window scaling options allows for almost gigabyte windows which is good for connections with large delay-bandwidth product
tcp_max_syn_backlogMaximal number of remembered connection requests which still did not receive an acknowledgment from connecting client
tcp_fin_timeoutHow many seconds to wait for a final FIN packet before the socket is closed required to prevent denial-of-service (DoS) attacks Default value is 60 seconds
Transport Layer 3-105
SomeTCP Parameters in Linux Kerneltcp_rmem
This is a vector of 3 integers [min default max] These parameters are used by TCP to dynamically adjust receive buffer sizesmin - minimum size of the receive buffer used by each TCP socket The default value is 4K default - the default size of the receive buffer for a TCP socket The default value is 87380 bytes and is lowered to 43689 in low memory systems If larger receive buffer sizes are desired this value should be increased max - the maximum size of the receive buffer used by each TCP socket The default value of 873802 bytes is lowered to 87380 in low memory systems
tcp_smemSend buffer parameters [min default max] similar to tcp_rmem
- Chapter 3 Transport Layer
- Transport services and protocols
- Transport vs network layer
- Internet transport-layer protocols
- Multiplexingdemultiplexing
- How demultiplexing works
- Connectionless demultiplexing
- Connection-oriented demux
- Connection-oriented demux (cont)
- Connection-oriented demux Threaded Web Server
- UDP User Datagram Protocol [RFC 768]
- UDP more
- UDP checksum
- Principles of Reliable data transfer
- Reliable data transfer getting started
- Reliable data transfer getting started
- Rdt10 reliable transfer over a reliable channel
- Rdt20 channel with bit errors
- rdt20 FSM specification
- rdt20 operation with no errors
- rdt20 error scenario
- rdt20 has a fatal flaw
- rdt21 sender handles garbled ACKNAKs
- rdt21 receiver handles garbled ACKNAKs
- rdt21 discussion
- rdt22 a NAK-free protocol
- rdt22 sender receiver fragments
- rdt30 channels with errors and loss
- rdt30 sender
- rdt30 in action
- rdt30 in action
- Performance of rdt30
- rdt30 stop-and-wait operation
- Pipelined protocols
- Pipelining increased utilization
- Go-Back-N
- GBN sender extended FSM
- GBN receiver extended FSM
- GBN inaction
- Selective Repeat
- Selective repeat sender receiver windows
- Selective repeat
- Selective repeat in action
- Selective repeat dilemma
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- TCP Overview RFCs 793 1122 1323 2018 2581
- TCP segment structure
- TCP seq rsquos and ACKs
- TCP Round Trip Time and Timeout
- TCP Round Trip Time and Timeout
- Example RTT estimation
- TCP Round Trip Time and Timeout
- TCP reliable data transfer
- TCP sender events
- TCP sender(simplified)
- TCP retransmission scenarios
- TCP retransmission scenarios (more)
- TCP ACK generation [RFC 1122 RFC 2581]
- Fast Retransmit
- Fast Retransmit
- Fast retransmit algorithm
- TCP Flow Control
- TCP Flow control how it works
- Sliding Window Flow Control Example
- Principles of Congestion Control
- Causescosts of congestion scenario 1
- Causescosts of congestion scenario 2
- Causescosts of congestion scenario 2
- Causescosts of congestion scenario 3
- Causescosts of congestion scenario 3
- Approaches towards congestion control
- TCP Congestion Control
- TCP congestion control bandwidth probing
- TCP Congestion Control details
- TCP Congestion Control more details
- TCP Slow Start Phase
- Slow Start Example
- TCP Congestion Avoidance Phase
- Congestion Avoidance
- Example Slow StartCongestion Avoidance
- Slow Start Congestion Avoidance
- Responses to Congestion
- Fast Recovery (differentiation btwn two loss events)
- TCP Congestion Control
- Popular ldquoflavorsrdquo of TCP
- Summary TCP Congestion Control
- TCP Congestion Control Summary
- TCP throughput
- TCP Futures TCP over ldquolong fat pipesrdquo
- TCP Fairness
- Why is TCP fair
- Fairness (more)
- TCP Connection Management
- TCP Connection Management (cont)
- TCP Connection Management (cont)
- TCP Connection Management (cont)
- Tuning TCPIP Parameters
- SomeTCP Parameters in Linux Kernel
- SomeTCP Parameters in Linux Kernel
-
Transport Layer 3-51
Sequence Number vs Window Size
sender
receiver
Selective Repeat
snd_base=rcv_base-N
All SNs in the interval [rcv_base-Nrcv_base+N-1] (an interval of size 2N) can be received by the receiver Since the receiver should be able to distinguish between all packets in this interval and take corresponding action there should be no two packets within thisinterval having the same SN Therefore
2k ge 2Nrcv_base+N-1
rcv_basercv_base
receiverrsquos window
rcv_base+N-1
Transport Layer 3-52
TCP Overview RFCs 793 1122 1323 2018 2581
full duplex databi-directional data flow in same connectionMSS maximum segment size
connection-orientedhandshaking (exchange of control msgs) initrsquossender receiver state before data exchange
flow controlledsender will not overwhelm receiver
point-to-pointone sender one receiver
reliable in-order byte stream
no ldquomessage boundariesrdquopipelined
TCP congestion and flow control set window size
send amp receive buffers
socketdoor
TCPsend buffer
TCPreceive buffer
socketdoor
segment
applicationwrites data
applicationreads data
Transport Layer 3-53
TCP segment structure
source port dest port
32 bits
applicationdata
(variable length)
sequence numberacknowledgement number
Receive windowUrg data pnterchecksum
FSRPAUheadlen
notused
Options (variable length)
URG urgent data (generally not used)
ACK ACK valid
PSH push data now(generally not used)
RST SYN FINconnection estab(setup teardown
commands)
bytes rcvr willingto accept
Internetchecksum
(as in UDP)
countingby bytes of data(not segments)
Transport Layer 3-54
TCP seq rsquos and ACKsSeq rsquos
byte stream ldquonumberrdquo of first byte in segmentrsquos dataACKs
seq of next byte expected from other sidecumulative ACK
Q how receiver handles out-of-order segmentsA TCP spec doesnrsquot say - up to implementationWidely used implementations of TCP buffer out-of-order segments
Transport Layer 3-55
TCP Round Trip Time and Timeout
Q how to set TCP timeout valuelonger than RTT
but RTT variestoo short premature timeout
unnecessary retransmissions
too long slow reaction to segment loss
Q how to estimate RTTSampleRTT measured time from segment transmission until ACK receipt
ignore retransmissionsSampleRTT will vary want estimated RTT ldquosmootherrdquo
average several recent measurements not just current SampleRTT
Transport Layer 3-56
TCP Round Trip Time and Timeout
EstimatedRTT = (1- α)EstimatedRTT + αSampleRTT
Exponential weighted moving averageinfluence of past sample decreases exponentially fasttypical value α = 0125
Transport Layer 3-57
Example RTT estimationRTT gaiacsumassedu to fantasiaeurecomfr
100
150
200
250
300
350
1 8 15 22 29 36 43 50 57 64 71 78 85 92 99 106
time (seconnds)
RTT
(mill
iseco
nds)
SampleRTT Estimated RTT
Transport Layer 3-58
TCP Round Trip Time and TimeoutSetting the timeout
EstimatedRTT plus ldquosafety marginrdquolarge variation in EstimatedRTT -gt larger safety margin
first estimate of how much SampleRTT deviates from EstimatedRTT
TimeoutInterval = EstimatedRTT + 4DevRTT
DevRTT = (1-β)DevRTT +β|SampleRTT-EstimatedRTT|
(typically β = 025)
Then set timeout interval
Transport Layer 3-59
TCP reliable data transfer
TCP creates rdtservice on top of IPrsquos unreliable servicePipelined segmentsCumulative acksTCP uses single retransmission timer however it just retransmits the first segment in the window
Retransmissions are triggered by
timeout eventsduplicate acks
Initially consider simplified TCP sender
ignore duplicate acksignore flow control congestion control
Transport Layer 3-60
TCP sender eventsdata rcvd from app
Create segment with seq seq is byte-stream number of first data byte in segmentstart timer if not already running (think of timer as for oldest unacked segment)expiration interval TimeOutInterval
timeoutretransmit segment that caused timeout (first segment in the window)restart timer
Ack rcvdIf acknowledges previously unacked segments
update what is known to be ackedstart timer if there are outstanding segments
Transport Layer 3-61
TCP sender(simplified)
NextSeqNum = InitialSeqNumSendBase = InitialSeqNum
loop (forever) switch(event)
event data received from application above create TCP segment with sequence number NextSeqNumif (timer currently not running)
start timerpass segment to IP NextSeqNum = NextSeqNum + length(data)
event timer timeoutretransmit not-yet-acknowledged segment with
smallest sequence numberstart timer
event ACK received with ACK field value of y if (y gt SendBase)
SendBase = yif (there are currently not-yet-acknowledged segments)
start timer
end of loop forever
Commentbull SendBase-1 last cumulatively ackrsquoed byteExamplebull SendBase-1 = 71y= 73 so the rcvrwants 73+ y gt SendBase sothat new data is acked
Transport Layer 3-62
TCP retransmission scenariosHost A
Seq=100 20 bytes data
ACK=100
timepremature timeout
Host B
Seq=92 8 bytes data
ACK=120
Seq=92 8 bytes data
Seq=
92 t
imeo
ut
ACK=120
Host A
Seq=92 8 bytes data
ACK=100
loss
tim
eout
lost ACK scenario
Host B
X
Seq=92 8 bytes data
ACK=100
time
Seq=
92 t
imeo
utSendBase
= 100
SendBase= 120
SendBase= 120
Sendbase= 100
Transport Layer 3-63
TCP retransmission scenarios (more)Host A
Seq=92 8 bytes data
ACK=100
loss
tim
eout
Cumulative ACK scenario
Host B
X
Seq=100 20 bytes data
ACK=120
time
SendBase= 120
Transport Layer 3-64
TCP ACK generation [RFC 1122 RFC 2581]
Event at Receiver
Arrival of in-order segment withexpected seq All data up toexpected seq already ACKed
Arrival of in-order segment withexpected seq One other segment has ACK pending
Arrival of out-of-order segmenthigher-than-expect seq Gap detected
Arrival of segment that partially or completely fills gap
TCP Receiver action
Delayed ACK Wait up to 500msfor next segment If no next segmentsend ACK
Immediately send single cumulative ACK ACKing both in-order segments
Immediately send duplicate ACK indicating seq of next expected byte
Immediate send ACK provided thatsegment startsat lower end of gap
Transport Layer 3-65
Fast Retransmit
Time-out period often relatively long
long delay before resending lost packet
Detect lost segments via duplicate ACKs
Sender often sends many segments back-to-backIf segment is lost there will likely be many duplicate ACKs
If sender receives 3 ACKs for the same data it supposes that segment after ACKeddata was lost
fast retransmit resend segment before timer expires
Transport Layer 3-66
Fast RetransmitResend a segment after 3 duplicate ACKs since a duplicate ACK means that an out-of sequence segment was receivedduplicate ACKs due to packet reorderingif window is small donrsquot get duplicate ACKs
Host A
tim
eout
Host B
time
X
resend seq X2
seq x1seq x2seq x3seq x4seq x5
ACK x1
ACK x1ACK x1ACK x1
tripleduplicate
ACKs
Transport Layer 3-67
event ACK received with ACK field value of y if (y gt SendBase)
SendBase = yif (there are currently not-yet-acknowledged segments)
start timer
else increment count of dup ACKs received for yif (count of dup ACKs received for y = 3)
resend segment with sequence number y
Fast retransmit algorithm
a duplicate ACK for already ACKed segment
fast retransmit
Transport Layer 3-68
TCP Flow Control
receive side of TCP connection has a receive buffer
speed-matching service matching the send rate to the receiving apprsquos drain rate
app process may be slow at reading from buffer
sender wonrsquot overflowreceiverrsquos buffer by
transmitting too muchtoo fast
flow control
Transport Layer 3-69
TCP Flow control how it works
(Suppose TCP receiver discards out-of-order segments)spare room in buffer
= RcvWin
= RcvBuffer-[LastByteRcvd -LastByteRead]
Rcvr advertises spare room by including value of RcvWin in segmentsSender limits unACKeddata to RcvWin
guarantees receive buffer doesnrsquot overflow
Transport Layer 3-70
Sliding Window Flow Control Example
3K
2K SeqNo=0
ReceiverBuffer
0 4KSendersends 2Kof data
2K
AckNo=2048 RcvWin=2048Sendersends 2Kof data 2K SeqNo=2048
4K
AckNo=4096 RcvWin=0
AckNo=4096 RcvWin=1024
Sender blocked
Transport Layer 3-71
Principles of Congestion Control
Congestioninformally ldquotoo many sources sending too much data too fast for network to handlerdquodifferent from flow controlmanifestations
lost packets (buffer overflow at routers)long delays (queueing in router buffers)
a top-10 problem
Transport Layer 3-72
Causescosts of congestion scenario 1
two senders two receiversone router infinite buffers no retransmission
large delays when congestedmaximum achievable throughput
unlimited shared output link buffers
Host Aλin original data
Host B
λout
Transport Layer 3-73
Causescosts of congestion scenario 2
one router finite buffers sender retransmission of lost packet
finite shared output link buffers
Host A λin original data
Host B
λout
λin original data plus retransmitted data
Transport Layer 3-74
Causescosts of congestion scenario 2always (goodput)ldquoperfectrdquo retransmission only when loss
retransmission of delayed (not lost) packet makes larger(than perfect case) for same
λin
λout=
λin
λoutgtλ
inλout
ldquocostsrdquo of congestionmore work (retrans) for given ldquogoodputrdquounneeded retransmissions link carries multiple copies of pkt
R2
R2λin
λ out
b
R2
R2λin
λ out
a
R2
R2λin
λ out
c
R4
R3
Transport Layer 3-75
Causescosts of congestion scenario 3four sendersmultihop pathstimeoutretransmit
λin
Q what happens as and increase λ
in
finite shared output link buffers
Host Aλin original data
Host B
λout
λin original data plus retransmitted data
Transport Layer 3-76
Causescosts of congestion scenario 3
another ldquocostrdquo of congestionwhen packet dropped any ldquoupstream transmission capacity used for that packet was wasted
Host A
Host B
λou
t
Transport Layer 3-77
Approaches towards congestion control
End-end congestion controlno explicit feedback from networkcongestion inferred from end-system observed loss delayapproach taken by TCP
Network-assisted congestion controlrouters provide feedback to end systems
single bit indicating congestion (SNA DECbit TCPIP ECN ATM)explicit rate sender should send at
Two broad approaches towards congestion control
Transport Layer 3-78
TCP Congestion Control
end-end control (no network assistance)sender limits transmissionLastByteSent-LastByteAcked
le CongWin
CongWin is dynamic function of perceived network congestion
How does sender perceive congestionloss event = timeout or3 duplicate acksTCP sender reduces rate (CongWin) after loss event
two modes of operationSlow Start (SS)Congestion avoidance (CA) or Additive Increase Multiplicative Decrease (AIMD)
Transport Layer 3-79
TCP congestion control bandwidth probing
ldquoprobing for bandwidthrdquo increase transmission rate on receipt of ACK until eventually loss occurs then decrease transmission rate
continue to increase on ACK decrease on loss (since available bandwidth is changing depending on other connections in network)
ACKs being received so increase rate
X
X
XX
X loss so decrease rate
send
ing
rate
time
Q how fast to increasedecreasedetails to follow
TCPrsquosldquosawtoothrdquobehavior
Transport Layer 3-80
TCP Congestion Control details
sender limits rate by limiting number of unACKed bytes ldquoin pipelinerdquo
cwnd differs from rwnd (how why)sender limited by min(cwndrwnd)
roughly
cwnd is dynamic function of perceived network congestion
rate = cwndRTT bytessec
LastByteSent-LastByteAcked le cwnd
cwndbytes
RTT
ACK(s)
Transport Layer 3-81
TCP Congestion Control more details
segment loss event reducing cwndtimeout no response from receiver
cut cwnd to 13 duplicate ACKs at least some segments getting through (recall fast retransmit)
cut cwnd in half less aggressively than on timeout
ACK received increase cwndTwo modes of operation
slowstart phase bull increase exponentially
fast (despite name) at connection start or following timeout
congestion avoidance bull increase linearly
Transport Layer 3-82
TCP Slow Start Phasewhen connection begins cwnd = 1 MSS
example MSS = 500 bytes amp RTT = 200 msecinitial rate = 20 kbps
available bandwidth may be gtgt MSSRTT
desirable to quickly ramp up to respectable rate
increase rate exponentially until first loss event or when threshold reached
double cwnd every RTTdone by incrementing cwnd by 1 for every ACK received
Host A
one segment
RTT
Host B
time
two segments
four segments
Transport Layer 3-83
Slow Start ExampleThe congestion window size grows very rapidly
For every ACK we increase CongWin by 1 irrespective of the number of segments ACKrsquoeddouble CongWinevery RTTinitial rate is slow but ramps up exponentially fast
TCP slows down the increase of CongWinwhen CongWin gt ssthresh
segment 1
ACK for segment 1
cwnd = 1
cwnd = 2 segment 2segment 3
ACK for segments 2
cwnd = 4 segment 4segment 5segment 6
ACK for segments 4
cwnd = 7
ACK for segments 3
ACK for segments 5
ACK for segments 6
cwnd = 3
cwnd = 5
cwnd = 6ACK for segments 7
cwnd = 8
segment 7
Transport Layer 3-84
TCP Congestion Avoidance Phase
when cwnd gt ssthreshgrow cwnd linearly
increase cwnd by 1 MSS per RTT approach possible congestion slower than in slowstartimplementation cwnd= cwnd + MSScwndfor each ACK received
ACKs increase cwndby 1 MSS per RTT additive increaseloss cut cwnd in half (non-timeout-detected loss ) multiplicative decrease
AIMD
AIMD Additive IncreaseMultiplicative Decrease
Transport Layer 3-85
Congestion AvoidanceCongestion avoidance phase is started if CongWin has reached the slow-start threshold value
If CongWin gt= ssthresh then each time an ACK is received increment CongWin as follows
bull CongWin = CongWin + 1CongWin (CongWin in segments)
bull In actual TCP implementation CongWin is in BytesCongWin = CongWin + MSS (MSSCongWin)
So CongWin is increased by one only if all CongWinsegments have been acknowledged
Transport Layer 3-86
Example Slow StartCongestion AvoidanceAssume that
ssthresh = 8
cwnd = 1
cwnd = 2
cwnd = 4
cwnd = 8
cwnd = 9
cwnd = 10
02468
101214
t=0
t=2
t=4
t=6
Roundtrip times
Cw
nd(in
seg
men
ts)
ssthresh
cwnd = 3
cwnd = 5cwnd = 6cwnd = 7
Transport Layer 3-87
Slow Start Congestion AvoidanceA typical plot of CongWin for a TCP connection
(MSS = 1500 bytes) with TCP Tahoe
SS
CA
ssthresh
Transport Layer 3-88
Responses to CongestionTCP assumes there is congestion if it detects a packet lossA TCP sender can detect lost packets via loss events
bull Timeout of a retransmission timerbull Receipt of 3 duplicate ACKs (fast retransmit)
TCP interprets a Timeout as a binary congestion signal When a timeout occurs the sender performs
ssthresh is set to half the current size of the congestion window
ssthresh = CongWin 2CongWin is reset to one
CongWin = 1and slow-start is entered
Transport Layer 3-89
Fast Recovery (differentiation btwn two loss events) After 3 dup ACKs (fast Retransmit)
ssthresh = CongWin2CongWin = CongWin2window then grows linearly
But after timeout eventCongWin = 1 MSS window then grows exponentiallyto the threshold then grows linearly
bull 3 dup ACKs indicates network capable of delivering some segmentsbull timeout before 3 dup ACKs is ldquomore alarmingrdquo
Philosophy
3-90
TCP Congestion ControlInitially
CongWin = 1ssthresh = advertised window size
New Ack receivedif (CongWin lt ssthresh) Slow Start
CongWin = CongWin + 1else Congestion Avoidance
CongWin = CongWin + 1CongWinTimeout
ssthresh = CongWin2CongWin = 1
Fast Retransmissionssthresh = CongWin2CongWin = CongWin2
Slow Start (exponential increase phase) is continued until CongWin reaches half of the level where the loss event occurred last time CongWin is increased slowly after (linear increase in Congestion Avoidance phase)
Transport Layer 3-91
Popular ldquoflavorsrdquo of TCP
ssthresh
ssthresh
TCP Tahoe
TCP Reno
Transmission round
cwnd
win
dow
siz
e (in
seg
men
ts)
Transport Layer 3-92
Summary TCP Congestion ControlWhen CongWin is below Threshold sender in slow-start phase window grows exponentiallyWhen CongWin is above Threshold sender is in congestion-avoidance phase window grows linearlyWhen a triple duplicate ACK occurs Threshold set to CongWin2 and CongWin set to ThresholdWhen timeout occurs Threshold set to CongWin2 and CongWin is set to 1 MSS The actual sender window size is determined based on the congestion and flow control algorithms
SenderWin=min(RcvWinCongWin)
Transport Layer 3-93
TCP Congestion Control SummaryEvent State TCP Sender Action Commentary
ACK receipt for previously unackeddata
Slow Start (SS)
CongWin = CongWin + MSS If (CongWin gt Threshold)
set state to ldquoCongestion Avoidancerdquo
Resulting in a doubling of CongWin every RTT
ACK receipt for previously unackeddata
CongestionAvoidance (CA)
CongWin = CongWin+MSS (MSSCongWin)
Additive increase resulting in increase of CongWin by 1 MSS every RTT
Loss event detected by triple duplicate ACK
SS or CA Threshold = CongWin2 CongWin = ThresholdSet state to ldquoCongestion Avoidancerdquo
Fast recovery implementing multiplicative decrease CongWin will not drop below 1 MSS
Timeout SS or CA Threshold = CongWin2 CongWin = 1 MSSSet state to ldquoSlow Startrdquo
Enter slow start
Duplicate ACK
SS or CA Increment duplicate ACK count for segment being acked
CongWin and Threshold not changed
Transport Layer 3-94
TCP throughput
Q whatrsquos average throughout of TCP as function of window size RTT
ignoring slow startlet W be window size when loss occurs
when window is W throughput is WRTTjust after loss window drops to W2 throughput to W2RTT average throughout 75 WRTT
Transport Layer 3-95
TCP Futures TCP over ldquolong fat pipesrdquo
example 1500 byte segments 100ms RTT want 10 Gbps throughputrequires window size W = 83333 in-flight segmentsthroughput in terms of loss rate
L = 210-10 Wownew versions of TCP for high-speed
LRTTMSSsdot221
Transport Layer 3-96
Fairness goal if K TCP sessions share same bottleneck link of bandwidth R each should have average rate of RK
TCP connection 1
bottleneckrouter
capacity R
TCP connection 2
TCP Fairness
Transport Layer 3-97
Why is TCP fairTwo competing sessions
Additive increase gives slope of 1 as throughout increasesmultiplicative decrease decreases throughput proportionally
R
R
equal bandwidth share
Connection 1 throughput
Conn
ecti
on 2
thr
ough
p ut
congestion avoidance additive increaseloss decrease window by factor of 2
congestion avoidance additive increaseloss decrease window by factor of 2
Transport Layer 3-98
Fairness (more)Fairness and UDP
Multimedia apps often do not use TCP
do not want rate throttled by congestion control
Instead use UDPpump audiovideo at constant rate tolerate packet loss
Research area TCP friendly
Fairness and parallel TCP connectionsnothing prevents app from opening parallel cnctionsbetween 2 hostsWeb browsers do this Example link of rate R supporting 9 cnctions
new app asks for 1 TCP gets rate R10new app asks for 11 TCPs gets R2
Transport Layer 3-99
TCP Connection ManagementRecall TCP sender receiver
establish ldquoconnectionrdquobefore exchanging data segmentsinitialize TCP variables
seq sbuffers flow control info (eg RcvWindow)
client connection initiatorSocket clientSocket = new Socket(hostnameport
number)
server contacted by clientSocket connectionSocket = welcomeSocketaccept()
Three way handshakeStep 1 client host sends TCP
SYN segment to serverspecifies initial seq no data
Step 2 server host receives SYN replies with SYNACK segment
server allocates buffersspecifies server initial seq
Step 3 client receives SYNACK replies with ACK segment which may contain data
Transport Layer 3-100
TCP Connection Management (cont)
Closing a connection
client closes socketclientSocketclose()
Step 1 client end system sends TCP FIN control segment to server
Step 2 server receives FIN replies with ACK Closes connection sends FIN
client
FIN
server
ACK
ACK
FIN
close
close
closed
tim
ed w
ait
Transport Layer 3-101
TCP Connection Management (cont)
Step 3 client receives FIN replies with ACK
Enters ldquotimed waitrdquo -will respond with ACK to received FINs
Step 4 server receives ACK Connection closed
client
FIN
server
ACK
ACK
FIN
closing
closing
closed
tim
ed w
ait
closed
Transport Layer 3-102
TCP Connection Management (cont)
TCP clientlifecycle
TCP serverlifecycle
Transport Layer 3-103
Tuning TCPIP Parameters TCPIP parameters
A set of default values may not be optimal for all applicationsThe network administrator may wish to turn on or off some TCPIP functions for performance or security considerations
Many Unix and Linux systems provide some flexibility in tuning the TCPIP kernelsbinsysctl is used to configure the Linux kernel parameters at runtime
Default kernel configuration file is sbinsysctlconfFrequently used sysctl options
bull sysctl ndasha or sysctl ndashA list all current valuesbull sysctl ndashp file_name load the sysctl setting from a configuration
filebull sysctl ndashw variable=value change the value of the parameter
Transport Layer 3-104
SomeTCP Parameters in Linux Kerneltcp_syn_retries
Number of SYN packets the kernel will send before giving up on the new connection
tcp_synack_retriesnumber of SYN+ACK packets sent before the kernel gives up on the connection
tcp_window_scalingMaximum window size of 65535 bytes not enough for for really fast networks The window scaling options allows for almost gigabyte windows which is good for connections with large delay-bandwidth product
tcp_max_syn_backlogMaximal number of remembered connection requests which still did not receive an acknowledgment from connecting client
tcp_fin_timeoutHow many seconds to wait for a final FIN packet before the socket is closed required to prevent denial-of-service (DoS) attacks Default value is 60 seconds
Transport Layer 3-105
SomeTCP Parameters in Linux Kerneltcp_rmem
This is a vector of 3 integers [min default max] These parameters are used by TCP to dynamically adjust receive buffer sizesmin - minimum size of the receive buffer used by each TCP socket The default value is 4K default - the default size of the receive buffer for a TCP socket The default value is 87380 bytes and is lowered to 43689 in low memory systems If larger receive buffer sizes are desired this value should be increased max - the maximum size of the receive buffer used by each TCP socket The default value of 873802 bytes is lowered to 87380 in low memory systems
tcp_smemSend buffer parameters [min default max] similar to tcp_rmem
- Chapter 3 Transport Layer
- Transport services and protocols
- Transport vs network layer
- Internet transport-layer protocols
- Multiplexingdemultiplexing
- How demultiplexing works
- Connectionless demultiplexing
- Connection-oriented demux
- Connection-oriented demux (cont)
- Connection-oriented demux Threaded Web Server
- UDP User Datagram Protocol [RFC 768]
- UDP more
- UDP checksum
- Principles of Reliable data transfer
- Reliable data transfer getting started
- Reliable data transfer getting started
- Rdt10 reliable transfer over a reliable channel
- Rdt20 channel with bit errors
- rdt20 FSM specification
- rdt20 operation with no errors
- rdt20 error scenario
- rdt20 has a fatal flaw
- rdt21 sender handles garbled ACKNAKs
- rdt21 receiver handles garbled ACKNAKs
- rdt21 discussion
- rdt22 a NAK-free protocol
- rdt22 sender receiver fragments
- rdt30 channels with errors and loss
- rdt30 sender
- rdt30 in action
- rdt30 in action
- Performance of rdt30
- rdt30 stop-and-wait operation
- Pipelined protocols
- Pipelining increased utilization
- Go-Back-N
- GBN sender extended FSM
- GBN receiver extended FSM
- GBN inaction
- Selective Repeat
- Selective repeat sender receiver windows
- Selective repeat
- Selective repeat in action
- Selective repeat dilemma
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- TCP Overview RFCs 793 1122 1323 2018 2581
- TCP segment structure
- TCP seq rsquos and ACKs
- TCP Round Trip Time and Timeout
- TCP Round Trip Time and Timeout
- Example RTT estimation
- TCP Round Trip Time and Timeout
- TCP reliable data transfer
- TCP sender events
- TCP sender(simplified)
- TCP retransmission scenarios
- TCP retransmission scenarios (more)
- TCP ACK generation [RFC 1122 RFC 2581]
- Fast Retransmit
- Fast Retransmit
- Fast retransmit algorithm
- TCP Flow Control
- TCP Flow control how it works
- Sliding Window Flow Control Example
- Principles of Congestion Control
- Causescosts of congestion scenario 1
- Causescosts of congestion scenario 2
- Causescosts of congestion scenario 2
- Causescosts of congestion scenario 3
- Causescosts of congestion scenario 3
- Approaches towards congestion control
- TCP Congestion Control
- TCP congestion control bandwidth probing
- TCP Congestion Control details
- TCP Congestion Control more details
- TCP Slow Start Phase
- Slow Start Example
- TCP Congestion Avoidance Phase
- Congestion Avoidance
- Example Slow StartCongestion Avoidance
- Slow Start Congestion Avoidance
- Responses to Congestion
- Fast Recovery (differentiation btwn two loss events)
- TCP Congestion Control
- Popular ldquoflavorsrdquo of TCP
- Summary TCP Congestion Control
- TCP Congestion Control Summary
- TCP throughput
- TCP Futures TCP over ldquolong fat pipesrdquo
- TCP Fairness
- Why is TCP fair
- Fairness (more)
- TCP Connection Management
- TCP Connection Management (cont)
- TCP Connection Management (cont)
- TCP Connection Management (cont)
- Tuning TCPIP Parameters
- SomeTCP Parameters in Linux Kernel
- SomeTCP Parameters in Linux Kernel
-
Transport Layer 3-52
TCP Overview RFCs 793 1122 1323 2018 2581
full duplex databi-directional data flow in same connectionMSS maximum segment size
connection-orientedhandshaking (exchange of control msgs) initrsquossender receiver state before data exchange
flow controlledsender will not overwhelm receiver
point-to-pointone sender one receiver
reliable in-order byte stream
no ldquomessage boundariesrdquopipelined
TCP congestion and flow control set window size
send amp receive buffers
socketdoor
TCPsend buffer
TCPreceive buffer
socketdoor
segment
applicationwrites data
applicationreads data
Transport Layer 3-53
TCP segment structure
source port dest port
32 bits
applicationdata
(variable length)
sequence numberacknowledgement number
Receive windowUrg data pnterchecksum
FSRPAUheadlen
notused
Options (variable length)
URG urgent data (generally not used)
ACK ACK valid
PSH push data now(generally not used)
RST SYN FINconnection estab(setup teardown
commands)
bytes rcvr willingto accept
Internetchecksum
(as in UDP)
countingby bytes of data(not segments)
Transport Layer 3-54
TCP seq rsquos and ACKsSeq rsquos
byte stream ldquonumberrdquo of first byte in segmentrsquos dataACKs
seq of next byte expected from other sidecumulative ACK
Q how receiver handles out-of-order segmentsA TCP spec doesnrsquot say - up to implementationWidely used implementations of TCP buffer out-of-order segments
Transport Layer 3-55
TCP Round Trip Time and Timeout
Q how to set TCP timeout valuelonger than RTT
but RTT variestoo short premature timeout
unnecessary retransmissions
too long slow reaction to segment loss
Q how to estimate RTTSampleRTT measured time from segment transmission until ACK receipt
ignore retransmissionsSampleRTT will vary want estimated RTT ldquosmootherrdquo
average several recent measurements not just current SampleRTT
Transport Layer 3-56
TCP Round Trip Time and Timeout
EstimatedRTT = (1- α)EstimatedRTT + αSampleRTT
Exponential weighted moving averageinfluence of past sample decreases exponentially fasttypical value α = 0125
Transport Layer 3-57
Example RTT estimationRTT gaiacsumassedu to fantasiaeurecomfr
100
150
200
250
300
350
1 8 15 22 29 36 43 50 57 64 71 78 85 92 99 106
time (seconnds)
RTT
(mill
iseco
nds)
SampleRTT Estimated RTT
Transport Layer 3-58
TCP Round Trip Time and TimeoutSetting the timeout
EstimatedRTT plus ldquosafety marginrdquolarge variation in EstimatedRTT -gt larger safety margin
first estimate of how much SampleRTT deviates from EstimatedRTT
TimeoutInterval = EstimatedRTT + 4DevRTT
DevRTT = (1-β)DevRTT +β|SampleRTT-EstimatedRTT|
(typically β = 025)
Then set timeout interval
Transport Layer 3-59
TCP reliable data transfer
TCP creates rdtservice on top of IPrsquos unreliable servicePipelined segmentsCumulative acksTCP uses single retransmission timer however it just retransmits the first segment in the window
Retransmissions are triggered by
timeout eventsduplicate acks
Initially consider simplified TCP sender
ignore duplicate acksignore flow control congestion control
Transport Layer 3-60
TCP sender eventsdata rcvd from app
Create segment with seq seq is byte-stream number of first data byte in segmentstart timer if not already running (think of timer as for oldest unacked segment)expiration interval TimeOutInterval
timeoutretransmit segment that caused timeout (first segment in the window)restart timer
Ack rcvdIf acknowledges previously unacked segments
update what is known to be ackedstart timer if there are outstanding segments
Transport Layer 3-61
TCP sender(simplified)
NextSeqNum = InitialSeqNumSendBase = InitialSeqNum
loop (forever) switch(event)
event data received from application above create TCP segment with sequence number NextSeqNumif (timer currently not running)
start timerpass segment to IP NextSeqNum = NextSeqNum + length(data)
event timer timeoutretransmit not-yet-acknowledged segment with
smallest sequence numberstart timer
event ACK received with ACK field value of y if (y gt SendBase)
SendBase = yif (there are currently not-yet-acknowledged segments)
start timer
end of loop forever
Commentbull SendBase-1 last cumulatively ackrsquoed byteExamplebull SendBase-1 = 71y= 73 so the rcvrwants 73+ y gt SendBase sothat new data is acked
Transport Layer 3-62
TCP retransmission scenariosHost A
Seq=100 20 bytes data
ACK=100
timepremature timeout
Host B
Seq=92 8 bytes data
ACK=120
Seq=92 8 bytes data
Seq=
92 t
imeo
ut
ACK=120
Host A
Seq=92 8 bytes data
ACK=100
loss
tim
eout
lost ACK scenario
Host B
X
Seq=92 8 bytes data
ACK=100
time
Seq=
92 t
imeo
utSendBase
= 100
SendBase= 120
SendBase= 120
Sendbase= 100
Transport Layer 3-63
TCP retransmission scenarios (more)Host A
Seq=92 8 bytes data
ACK=100
loss
tim
eout
Cumulative ACK scenario
Host B
X
Seq=100 20 bytes data
ACK=120
time
SendBase= 120
Transport Layer 3-64
TCP ACK generation [RFC 1122 RFC 2581]
Event at Receiver
Arrival of in-order segment withexpected seq All data up toexpected seq already ACKed
Arrival of in-order segment withexpected seq One other segment has ACK pending
Arrival of out-of-order segmenthigher-than-expect seq Gap detected
Arrival of segment that partially or completely fills gap
TCP Receiver action
Delayed ACK Wait up to 500msfor next segment If no next segmentsend ACK
Immediately send single cumulative ACK ACKing both in-order segments
Immediately send duplicate ACK indicating seq of next expected byte
Immediate send ACK provided thatsegment startsat lower end of gap
Transport Layer 3-65
Fast Retransmit
Time-out period often relatively long
long delay before resending lost packet
Detect lost segments via duplicate ACKs
Sender often sends many segments back-to-backIf segment is lost there will likely be many duplicate ACKs
If sender receives 3 ACKs for the same data it supposes that segment after ACKeddata was lost
fast retransmit resend segment before timer expires
Transport Layer 3-66
Fast RetransmitResend a segment after 3 duplicate ACKs since a duplicate ACK means that an out-of sequence segment was receivedduplicate ACKs due to packet reorderingif window is small donrsquot get duplicate ACKs
Host A
tim
eout
Host B
time
X
resend seq X2
seq x1seq x2seq x3seq x4seq x5
ACK x1
ACK x1ACK x1ACK x1
tripleduplicate
ACKs
Transport Layer 3-67
event ACK received with ACK field value of y if (y gt SendBase)
SendBase = yif (there are currently not-yet-acknowledged segments)
start timer
else increment count of dup ACKs received for yif (count of dup ACKs received for y = 3)
resend segment with sequence number y
Fast retransmit algorithm
a duplicate ACK for already ACKed segment
fast retransmit
Transport Layer 3-68
TCP Flow Control
receive side of TCP connection has a receive buffer
speed-matching service matching the send rate to the receiving apprsquos drain rate
app process may be slow at reading from buffer
sender wonrsquot overflowreceiverrsquos buffer by
transmitting too muchtoo fast
flow control
Transport Layer 3-69
TCP Flow control how it works
(Suppose TCP receiver discards out-of-order segments)spare room in buffer
= RcvWin
= RcvBuffer-[LastByteRcvd -LastByteRead]
Rcvr advertises spare room by including value of RcvWin in segmentsSender limits unACKeddata to RcvWin
guarantees receive buffer doesnrsquot overflow
Transport Layer 3-70
Sliding Window Flow Control Example
3K
2K SeqNo=0
ReceiverBuffer
0 4KSendersends 2Kof data
2K
AckNo=2048 RcvWin=2048Sendersends 2Kof data 2K SeqNo=2048
4K
AckNo=4096 RcvWin=0
AckNo=4096 RcvWin=1024
Sender blocked
Transport Layer 3-71
Principles of Congestion Control
Congestioninformally ldquotoo many sources sending too much data too fast for network to handlerdquodifferent from flow controlmanifestations
lost packets (buffer overflow at routers)long delays (queueing in router buffers)
a top-10 problem
Transport Layer 3-72
Causescosts of congestion scenario 1
two senders two receiversone router infinite buffers no retransmission
large delays when congestedmaximum achievable throughput
unlimited shared output link buffers
Host Aλin original data
Host B
λout
Transport Layer 3-73
Causescosts of congestion scenario 2
one router finite buffers sender retransmission of lost packet
finite shared output link buffers
Host A λin original data
Host B
λout
λin original data plus retransmitted data
Transport Layer 3-74
Causescosts of congestion scenario 2always (goodput)ldquoperfectrdquo retransmission only when loss
retransmission of delayed (not lost) packet makes larger(than perfect case) for same
λin
λout=
λin
λoutgtλ
inλout
ldquocostsrdquo of congestionmore work (retrans) for given ldquogoodputrdquounneeded retransmissions link carries multiple copies of pkt
R2
R2λin
λ out
b
R2
R2λin
λ out
a
R2
R2λin
λ out
c
R4
R3
Transport Layer 3-75
Causescosts of congestion scenario 3four sendersmultihop pathstimeoutretransmit
λin
Q what happens as and increase λ
in
finite shared output link buffers
Host Aλin original data
Host B
λout
λin original data plus retransmitted data
Transport Layer 3-76
Causescosts of congestion scenario 3
another ldquocostrdquo of congestionwhen packet dropped any ldquoupstream transmission capacity used for that packet was wasted
Host A
Host B
λou
t
Transport Layer 3-77
Approaches towards congestion control
End-end congestion controlno explicit feedback from networkcongestion inferred from end-system observed loss delayapproach taken by TCP
Network-assisted congestion controlrouters provide feedback to end systems
single bit indicating congestion (SNA DECbit TCPIP ECN ATM)explicit rate sender should send at
Two broad approaches towards congestion control
Transport Layer 3-78
TCP Congestion Control
end-end control (no network assistance)sender limits transmissionLastByteSent-LastByteAcked
le CongWin
CongWin is dynamic function of perceived network congestion
How does sender perceive congestionloss event = timeout or3 duplicate acksTCP sender reduces rate (CongWin) after loss event
two modes of operationSlow Start (SS)Congestion avoidance (CA) or Additive Increase Multiplicative Decrease (AIMD)
Transport Layer 3-79
TCP congestion control bandwidth probing
ldquoprobing for bandwidthrdquo increase transmission rate on receipt of ACK until eventually loss occurs then decrease transmission rate
continue to increase on ACK decrease on loss (since available bandwidth is changing depending on other connections in network)
ACKs being received so increase rate
X
X
XX
X loss so decrease rate
send
ing
rate
time
Q how fast to increasedecreasedetails to follow
TCPrsquosldquosawtoothrdquobehavior
Transport Layer 3-80
TCP Congestion Control details
sender limits rate by limiting number of unACKed bytes ldquoin pipelinerdquo
cwnd differs from rwnd (how why)sender limited by min(cwndrwnd)
roughly
cwnd is dynamic function of perceived network congestion
rate = cwndRTT bytessec
LastByteSent-LastByteAcked le cwnd
cwndbytes
RTT
ACK(s)
Transport Layer 3-81
TCP Congestion Control more details
segment loss event reducing cwndtimeout no response from receiver
cut cwnd to 13 duplicate ACKs at least some segments getting through (recall fast retransmit)
cut cwnd in half less aggressively than on timeout
ACK received increase cwndTwo modes of operation
slowstart phase bull increase exponentially
fast (despite name) at connection start or following timeout
congestion avoidance bull increase linearly
Transport Layer 3-82
TCP Slow Start Phasewhen connection begins cwnd = 1 MSS
example MSS = 500 bytes amp RTT = 200 msecinitial rate = 20 kbps
available bandwidth may be gtgt MSSRTT
desirable to quickly ramp up to respectable rate
increase rate exponentially until first loss event or when threshold reached
double cwnd every RTTdone by incrementing cwnd by 1 for every ACK received
Host A
one segment
RTT
Host B
time
two segments
four segments
Transport Layer 3-83
Slow Start ExampleThe congestion window size grows very rapidly
For every ACK we increase CongWin by 1 irrespective of the number of segments ACKrsquoeddouble CongWinevery RTTinitial rate is slow but ramps up exponentially fast
TCP slows down the increase of CongWinwhen CongWin gt ssthresh
segment 1
ACK for segment 1
cwnd = 1
cwnd = 2 segment 2segment 3
ACK for segments 2
cwnd = 4 segment 4segment 5segment 6
ACK for segments 4
cwnd = 7
ACK for segments 3
ACK for segments 5
ACK for segments 6
cwnd = 3
cwnd = 5
cwnd = 6ACK for segments 7
cwnd = 8
segment 7
Transport Layer 3-84
TCP Congestion Avoidance Phase
when cwnd gt ssthreshgrow cwnd linearly
increase cwnd by 1 MSS per RTT approach possible congestion slower than in slowstartimplementation cwnd= cwnd + MSScwndfor each ACK received
ACKs increase cwndby 1 MSS per RTT additive increaseloss cut cwnd in half (non-timeout-detected loss ) multiplicative decrease
AIMD
AIMD Additive IncreaseMultiplicative Decrease
Transport Layer 3-85
Congestion AvoidanceCongestion avoidance phase is started if CongWin has reached the slow-start threshold value
If CongWin gt= ssthresh then each time an ACK is received increment CongWin as follows
bull CongWin = CongWin + 1CongWin (CongWin in segments)
bull In actual TCP implementation CongWin is in BytesCongWin = CongWin + MSS (MSSCongWin)
So CongWin is increased by one only if all CongWinsegments have been acknowledged
Transport Layer 3-86
Example Slow StartCongestion AvoidanceAssume that
ssthresh = 8
cwnd = 1
cwnd = 2
cwnd = 4
cwnd = 8
cwnd = 9
cwnd = 10
02468
101214
t=0
t=2
t=4
t=6
Roundtrip times
Cw
nd(in
seg
men
ts)
ssthresh
cwnd = 3
cwnd = 5cwnd = 6cwnd = 7
Transport Layer 3-87
Slow Start Congestion AvoidanceA typical plot of CongWin for a TCP connection
(MSS = 1500 bytes) with TCP Tahoe
SS
CA
ssthresh
Transport Layer 3-88
Responses to CongestionTCP assumes there is congestion if it detects a packet lossA TCP sender can detect lost packets via loss events
bull Timeout of a retransmission timerbull Receipt of 3 duplicate ACKs (fast retransmit)
TCP interprets a Timeout as a binary congestion signal When a timeout occurs the sender performs
ssthresh is set to half the current size of the congestion window
ssthresh = CongWin 2CongWin is reset to one
CongWin = 1and slow-start is entered
Transport Layer 3-89
Fast Recovery (differentiation btwn two loss events) After 3 dup ACKs (fast Retransmit)
ssthresh = CongWin2CongWin = CongWin2window then grows linearly
But after timeout eventCongWin = 1 MSS window then grows exponentiallyto the threshold then grows linearly
bull 3 dup ACKs indicates network capable of delivering some segmentsbull timeout before 3 dup ACKs is ldquomore alarmingrdquo
Philosophy
3-90
TCP Congestion ControlInitially
CongWin = 1ssthresh = advertised window size
New Ack receivedif (CongWin lt ssthresh) Slow Start
CongWin = CongWin + 1else Congestion Avoidance
CongWin = CongWin + 1CongWinTimeout
ssthresh = CongWin2CongWin = 1
Fast Retransmissionssthresh = CongWin2CongWin = CongWin2
Slow Start (exponential increase phase) is continued until CongWin reaches half of the level where the loss event occurred last time CongWin is increased slowly after (linear increase in Congestion Avoidance phase)
Transport Layer 3-91
Popular ldquoflavorsrdquo of TCP
ssthresh
ssthresh
TCP Tahoe
TCP Reno
Transmission round
cwnd
win
dow
siz
e (in
seg
men
ts)
Transport Layer 3-92
Summary TCP Congestion ControlWhen CongWin is below Threshold sender in slow-start phase window grows exponentiallyWhen CongWin is above Threshold sender is in congestion-avoidance phase window grows linearlyWhen a triple duplicate ACK occurs Threshold set to CongWin2 and CongWin set to ThresholdWhen timeout occurs Threshold set to CongWin2 and CongWin is set to 1 MSS The actual sender window size is determined based on the congestion and flow control algorithms
SenderWin=min(RcvWinCongWin)
Transport Layer 3-93
TCP Congestion Control SummaryEvent State TCP Sender Action Commentary
ACK receipt for previously unackeddata
Slow Start (SS)
CongWin = CongWin + MSS If (CongWin gt Threshold)
set state to ldquoCongestion Avoidancerdquo
Resulting in a doubling of CongWin every RTT
ACK receipt for previously unackeddata
CongestionAvoidance (CA)
CongWin = CongWin+MSS (MSSCongWin)
Additive increase resulting in increase of CongWin by 1 MSS every RTT
Loss event detected by triple duplicate ACK
SS or CA Threshold = CongWin2 CongWin = ThresholdSet state to ldquoCongestion Avoidancerdquo
Fast recovery implementing multiplicative decrease CongWin will not drop below 1 MSS
Timeout SS or CA Threshold = CongWin2 CongWin = 1 MSSSet state to ldquoSlow Startrdquo
Enter slow start
Duplicate ACK
SS or CA Increment duplicate ACK count for segment being acked
CongWin and Threshold not changed
Transport Layer 3-94
TCP throughput
Q whatrsquos average throughout of TCP as function of window size RTT
ignoring slow startlet W be window size when loss occurs
when window is W throughput is WRTTjust after loss window drops to W2 throughput to W2RTT average throughout 75 WRTT
Transport Layer 3-95
TCP Futures TCP over ldquolong fat pipesrdquo
example 1500 byte segments 100ms RTT want 10 Gbps throughputrequires window size W = 83333 in-flight segmentsthroughput in terms of loss rate
L = 210-10 Wownew versions of TCP for high-speed
LRTTMSSsdot221
Transport Layer 3-96
Fairness goal if K TCP sessions share same bottleneck link of bandwidth R each should have average rate of RK
TCP connection 1
bottleneckrouter
capacity R
TCP connection 2
TCP Fairness
Transport Layer 3-97
Why is TCP fairTwo competing sessions
Additive increase gives slope of 1 as throughout increasesmultiplicative decrease decreases throughput proportionally
R
R
equal bandwidth share
Connection 1 throughput
Conn
ecti
on 2
thr
ough
p ut
congestion avoidance additive increaseloss decrease window by factor of 2
congestion avoidance additive increaseloss decrease window by factor of 2
Transport Layer 3-98
Fairness (more)Fairness and UDP
Multimedia apps often do not use TCP
do not want rate throttled by congestion control
Instead use UDPpump audiovideo at constant rate tolerate packet loss
Research area TCP friendly
Fairness and parallel TCP connectionsnothing prevents app from opening parallel cnctionsbetween 2 hostsWeb browsers do this Example link of rate R supporting 9 cnctions
new app asks for 1 TCP gets rate R10new app asks for 11 TCPs gets R2
Transport Layer 3-99
TCP Connection ManagementRecall TCP sender receiver
establish ldquoconnectionrdquobefore exchanging data segmentsinitialize TCP variables
seq sbuffers flow control info (eg RcvWindow)
client connection initiatorSocket clientSocket = new Socket(hostnameport
number)
server contacted by clientSocket connectionSocket = welcomeSocketaccept()
Three way handshakeStep 1 client host sends TCP
SYN segment to serverspecifies initial seq no data
Step 2 server host receives SYN replies with SYNACK segment
server allocates buffersspecifies server initial seq
Step 3 client receives SYNACK replies with ACK segment which may contain data
Transport Layer 3-100
TCP Connection Management (cont)
Closing a connection
client closes socketclientSocketclose()
Step 1 client end system sends TCP FIN control segment to server
Step 2 server receives FIN replies with ACK Closes connection sends FIN
client
FIN
server
ACK
ACK
FIN
close
close
closed
tim
ed w
ait
Transport Layer 3-101
TCP Connection Management (cont)
Step 3 client receives FIN replies with ACK
Enters ldquotimed waitrdquo -will respond with ACK to received FINs
Step 4 server receives ACK Connection closed
client
FIN
server
ACK
ACK
FIN
closing
closing
closed
tim
ed w
ait
closed
Transport Layer 3-102
TCP Connection Management (cont)
TCP clientlifecycle
TCP serverlifecycle
Transport Layer 3-103
Tuning TCPIP Parameters TCPIP parameters
A set of default values may not be optimal for all applicationsThe network administrator may wish to turn on or off some TCPIP functions for performance or security considerations
Many Unix and Linux systems provide some flexibility in tuning the TCPIP kernelsbinsysctl is used to configure the Linux kernel parameters at runtime
Default kernel configuration file is sbinsysctlconfFrequently used sysctl options
bull sysctl ndasha or sysctl ndashA list all current valuesbull sysctl ndashp file_name load the sysctl setting from a configuration
filebull sysctl ndashw variable=value change the value of the parameter
Transport Layer 3-104
SomeTCP Parameters in Linux Kerneltcp_syn_retries
Number of SYN packets the kernel will send before giving up on the new connection
tcp_synack_retriesnumber of SYN+ACK packets sent before the kernel gives up on the connection
tcp_window_scalingMaximum window size of 65535 bytes not enough for for really fast networks The window scaling options allows for almost gigabyte windows which is good for connections with large delay-bandwidth product
tcp_max_syn_backlogMaximal number of remembered connection requests which still did not receive an acknowledgment from connecting client
tcp_fin_timeoutHow many seconds to wait for a final FIN packet before the socket is closed required to prevent denial-of-service (DoS) attacks Default value is 60 seconds
Transport Layer 3-105
SomeTCP Parameters in Linux Kerneltcp_rmem
This is a vector of 3 integers [min default max] These parameters are used by TCP to dynamically adjust receive buffer sizesmin - minimum size of the receive buffer used by each TCP socket The default value is 4K default - the default size of the receive buffer for a TCP socket The default value is 87380 bytes and is lowered to 43689 in low memory systems If larger receive buffer sizes are desired this value should be increased max - the maximum size of the receive buffer used by each TCP socket The default value of 873802 bytes is lowered to 87380 in low memory systems
tcp_smemSend buffer parameters [min default max] similar to tcp_rmem
- Chapter 3 Transport Layer
- Transport services and protocols
- Transport vs network layer
- Internet transport-layer protocols
- Multiplexingdemultiplexing
- How demultiplexing works
- Connectionless demultiplexing
- Connection-oriented demux
- Connection-oriented demux (cont)
- Connection-oriented demux Threaded Web Server
- UDP User Datagram Protocol [RFC 768]
- UDP more
- UDP checksum
- Principles of Reliable data transfer
- Reliable data transfer getting started
- Reliable data transfer getting started
- Rdt10 reliable transfer over a reliable channel
- Rdt20 channel with bit errors
- rdt20 FSM specification
- rdt20 operation with no errors
- rdt20 error scenario
- rdt20 has a fatal flaw
- rdt21 sender handles garbled ACKNAKs
- rdt21 receiver handles garbled ACKNAKs
- rdt21 discussion
- rdt22 a NAK-free protocol
- rdt22 sender receiver fragments
- rdt30 channels with errors and loss
- rdt30 sender
- rdt30 in action
- rdt30 in action
- Performance of rdt30
- rdt30 stop-and-wait operation
- Pipelined protocols
- Pipelining increased utilization
- Go-Back-N
- GBN sender extended FSM
- GBN receiver extended FSM
- GBN inaction
- Selective Repeat
- Selective repeat sender receiver windows
- Selective repeat
- Selective repeat in action
- Selective repeat dilemma
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- TCP Overview RFCs 793 1122 1323 2018 2581
- TCP segment structure
- TCP seq rsquos and ACKs
- TCP Round Trip Time and Timeout
- TCP Round Trip Time and Timeout
- Example RTT estimation
- TCP Round Trip Time and Timeout
- TCP reliable data transfer
- TCP sender events
- TCP sender(simplified)
- TCP retransmission scenarios
- TCP retransmission scenarios (more)
- TCP ACK generation [RFC 1122 RFC 2581]
- Fast Retransmit
- Fast Retransmit
- Fast retransmit algorithm
- TCP Flow Control
- TCP Flow control how it works
- Sliding Window Flow Control Example
- Principles of Congestion Control
- Causescosts of congestion scenario 1
- Causescosts of congestion scenario 2
- Causescosts of congestion scenario 2
- Causescosts of congestion scenario 3
- Causescosts of congestion scenario 3
- Approaches towards congestion control
- TCP Congestion Control
- TCP congestion control bandwidth probing
- TCP Congestion Control details
- TCP Congestion Control more details
- TCP Slow Start Phase
- Slow Start Example
- TCP Congestion Avoidance Phase
- Congestion Avoidance
- Example Slow StartCongestion Avoidance
- Slow Start Congestion Avoidance
- Responses to Congestion
- Fast Recovery (differentiation btwn two loss events)
- TCP Congestion Control
- Popular ldquoflavorsrdquo of TCP
- Summary TCP Congestion Control
- TCP Congestion Control Summary
- TCP throughput
- TCP Futures TCP over ldquolong fat pipesrdquo
- TCP Fairness
- Why is TCP fair
- Fairness (more)
- TCP Connection Management
- TCP Connection Management (cont)
- TCP Connection Management (cont)
- TCP Connection Management (cont)
- Tuning TCPIP Parameters
- SomeTCP Parameters in Linux Kernel
- SomeTCP Parameters in Linux Kernel
-
Transport Layer 3-53
TCP segment structure
source port dest port
32 bits
applicationdata
(variable length)
sequence numberacknowledgement number
Receive windowUrg data pnterchecksum
FSRPAUheadlen
notused
Options (variable length)
URG urgent data (generally not used)
ACK ACK valid
PSH push data now(generally not used)
RST SYN FINconnection estab(setup teardown
commands)
bytes rcvr willingto accept
Internetchecksum
(as in UDP)
countingby bytes of data(not segments)
Transport Layer 3-54
TCP seq rsquos and ACKsSeq rsquos
byte stream ldquonumberrdquo of first byte in segmentrsquos dataACKs
seq of next byte expected from other sidecumulative ACK
Q how receiver handles out-of-order segmentsA TCP spec doesnrsquot say - up to implementationWidely used implementations of TCP buffer out-of-order segments
Transport Layer 3-55
TCP Round Trip Time and Timeout
Q how to set TCP timeout valuelonger than RTT
but RTT variestoo short premature timeout
unnecessary retransmissions
too long slow reaction to segment loss
Q how to estimate RTTSampleRTT measured time from segment transmission until ACK receipt
ignore retransmissionsSampleRTT will vary want estimated RTT ldquosmootherrdquo
average several recent measurements not just current SampleRTT
Transport Layer 3-56
TCP Round Trip Time and Timeout
EstimatedRTT = (1- α)EstimatedRTT + αSampleRTT
Exponential weighted moving averageinfluence of past sample decreases exponentially fasttypical value α = 0125
Transport Layer 3-57
Example RTT estimationRTT gaiacsumassedu to fantasiaeurecomfr
100
150
200
250
300
350
1 8 15 22 29 36 43 50 57 64 71 78 85 92 99 106
time (seconnds)
RTT
(mill
iseco
nds)
SampleRTT Estimated RTT
Transport Layer 3-58
TCP Round Trip Time and TimeoutSetting the timeout
EstimatedRTT plus ldquosafety marginrdquolarge variation in EstimatedRTT -gt larger safety margin
first estimate of how much SampleRTT deviates from EstimatedRTT
TimeoutInterval = EstimatedRTT + 4DevRTT
DevRTT = (1-β)DevRTT +β|SampleRTT-EstimatedRTT|
(typically β = 025)
Then set timeout interval
Transport Layer 3-59
TCP reliable data transfer
TCP creates rdtservice on top of IPrsquos unreliable servicePipelined segmentsCumulative acksTCP uses single retransmission timer however it just retransmits the first segment in the window
Retransmissions are triggered by
timeout eventsduplicate acks
Initially consider simplified TCP sender
ignore duplicate acksignore flow control congestion control
Transport Layer 3-60
TCP sender eventsdata rcvd from app
Create segment with seq seq is byte-stream number of first data byte in segmentstart timer if not already running (think of timer as for oldest unacked segment)expiration interval TimeOutInterval
timeoutretransmit segment that caused timeout (first segment in the window)restart timer
Ack rcvdIf acknowledges previously unacked segments
update what is known to be ackedstart timer if there are outstanding segments
Transport Layer 3-61
TCP sender(simplified)
NextSeqNum = InitialSeqNumSendBase = InitialSeqNum
loop (forever) switch(event)
event data received from application above create TCP segment with sequence number NextSeqNumif (timer currently not running)
start timerpass segment to IP NextSeqNum = NextSeqNum + length(data)
event timer timeoutretransmit not-yet-acknowledged segment with
smallest sequence numberstart timer
event ACK received with ACK field value of y if (y gt SendBase)
SendBase = yif (there are currently not-yet-acknowledged segments)
start timer
end of loop forever
Commentbull SendBase-1 last cumulatively ackrsquoed byteExamplebull SendBase-1 = 71y= 73 so the rcvrwants 73+ y gt SendBase sothat new data is acked
Transport Layer 3-62
TCP retransmission scenariosHost A
Seq=100 20 bytes data
ACK=100
timepremature timeout
Host B
Seq=92 8 bytes data
ACK=120
Seq=92 8 bytes data
Seq=
92 t
imeo
ut
ACK=120
Host A
Seq=92 8 bytes data
ACK=100
loss
tim
eout
lost ACK scenario
Host B
X
Seq=92 8 bytes data
ACK=100
time
Seq=
92 t
imeo
utSendBase
= 100
SendBase= 120
SendBase= 120
Sendbase= 100
Transport Layer 3-63
TCP retransmission scenarios (more)Host A
Seq=92 8 bytes data
ACK=100
loss
tim
eout
Cumulative ACK scenario
Host B
X
Seq=100 20 bytes data
ACK=120
time
SendBase= 120
Transport Layer 3-64
TCP ACK generation [RFC 1122 RFC 2581]
Event at Receiver
Arrival of in-order segment withexpected seq All data up toexpected seq already ACKed
Arrival of in-order segment withexpected seq One other segment has ACK pending
Arrival of out-of-order segmenthigher-than-expect seq Gap detected
Arrival of segment that partially or completely fills gap
TCP Receiver action
Delayed ACK Wait up to 500msfor next segment If no next segmentsend ACK
Immediately send single cumulative ACK ACKing both in-order segments
Immediately send duplicate ACK indicating seq of next expected byte
Immediate send ACK provided thatsegment startsat lower end of gap
Transport Layer 3-65
Fast Retransmit
Time-out period often relatively long
long delay before resending lost packet
Detect lost segments via duplicate ACKs
Sender often sends many segments back-to-backIf segment is lost there will likely be many duplicate ACKs
If sender receives 3 ACKs for the same data it supposes that segment after ACKeddata was lost
fast retransmit resend segment before timer expires
Transport Layer 3-66
Fast RetransmitResend a segment after 3 duplicate ACKs since a duplicate ACK means that an out-of sequence segment was receivedduplicate ACKs due to packet reorderingif window is small donrsquot get duplicate ACKs
Host A
tim
eout
Host B
time
X
resend seq X2
seq x1seq x2seq x3seq x4seq x5
ACK x1
ACK x1ACK x1ACK x1
tripleduplicate
ACKs
Transport Layer 3-67
event ACK received with ACK field value of y if (y gt SendBase)
SendBase = yif (there are currently not-yet-acknowledged segments)
start timer
else increment count of dup ACKs received for yif (count of dup ACKs received for y = 3)
resend segment with sequence number y
Fast retransmit algorithm
a duplicate ACK for already ACKed segment
fast retransmit
Transport Layer 3-68
TCP Flow Control
receive side of TCP connection has a receive buffer
speed-matching service matching the send rate to the receiving apprsquos drain rate
app process may be slow at reading from buffer
sender wonrsquot overflowreceiverrsquos buffer by
transmitting too muchtoo fast
flow control
Transport Layer 3-69
TCP Flow control how it works
(Suppose TCP receiver discards out-of-order segments)spare room in buffer
= RcvWin
= RcvBuffer-[LastByteRcvd -LastByteRead]
Rcvr advertises spare room by including value of RcvWin in segmentsSender limits unACKeddata to RcvWin
guarantees receive buffer doesnrsquot overflow
Transport Layer 3-70
Sliding Window Flow Control Example
3K
2K SeqNo=0
ReceiverBuffer
0 4KSendersends 2Kof data
2K
AckNo=2048 RcvWin=2048Sendersends 2Kof data 2K SeqNo=2048
4K
AckNo=4096 RcvWin=0
AckNo=4096 RcvWin=1024
Sender blocked
Transport Layer 3-71
Principles of Congestion Control
Congestioninformally ldquotoo many sources sending too much data too fast for network to handlerdquodifferent from flow controlmanifestations
lost packets (buffer overflow at routers)long delays (queueing in router buffers)
a top-10 problem
Transport Layer 3-72
Causescosts of congestion scenario 1
two senders two receiversone router infinite buffers no retransmission
large delays when congestedmaximum achievable throughput
unlimited shared output link buffers
Host Aλin original data
Host B
λout
Transport Layer 3-73
Causescosts of congestion scenario 2
one router finite buffers sender retransmission of lost packet
finite shared output link buffers
Host A λin original data
Host B
λout
λin original data plus retransmitted data
Transport Layer 3-74
Causescosts of congestion scenario 2always (goodput)ldquoperfectrdquo retransmission only when loss
retransmission of delayed (not lost) packet makes larger(than perfect case) for same
λin
λout=
λin
λoutgtλ
inλout
ldquocostsrdquo of congestionmore work (retrans) for given ldquogoodputrdquounneeded retransmissions link carries multiple copies of pkt
R2
R2λin
λ out
b
R2
R2λin
λ out
a
R2
R2λin
λ out
c
R4
R3
Transport Layer 3-75
Causescosts of congestion scenario 3four sendersmultihop pathstimeoutretransmit
λin
Q what happens as and increase λ
in
finite shared output link buffers
Host Aλin original data
Host B
λout
λin original data plus retransmitted data
Transport Layer 3-76
Causescosts of congestion scenario 3
another ldquocostrdquo of congestionwhen packet dropped any ldquoupstream transmission capacity used for that packet was wasted
Host A
Host B
λou
t
Transport Layer 3-77
Approaches towards congestion control
End-end congestion controlno explicit feedback from networkcongestion inferred from end-system observed loss delayapproach taken by TCP
Network-assisted congestion controlrouters provide feedback to end systems
single bit indicating congestion (SNA DECbit TCPIP ECN ATM)explicit rate sender should send at
Two broad approaches towards congestion control
Transport Layer 3-78
TCP Congestion Control
end-end control (no network assistance)sender limits transmissionLastByteSent-LastByteAcked
le CongWin
CongWin is dynamic function of perceived network congestion
How does sender perceive congestionloss event = timeout or3 duplicate acksTCP sender reduces rate (CongWin) after loss event
two modes of operationSlow Start (SS)Congestion avoidance (CA) or Additive Increase Multiplicative Decrease (AIMD)
Transport Layer 3-79
TCP congestion control bandwidth probing
ldquoprobing for bandwidthrdquo increase transmission rate on receipt of ACK until eventually loss occurs then decrease transmission rate
continue to increase on ACK decrease on loss (since available bandwidth is changing depending on other connections in network)
ACKs being received so increase rate
X
X
XX
X loss so decrease rate
send
ing
rate
time
Q how fast to increasedecreasedetails to follow
TCPrsquosldquosawtoothrdquobehavior
Transport Layer 3-80
TCP Congestion Control details
sender limits rate by limiting number of unACKed bytes ldquoin pipelinerdquo
cwnd differs from rwnd (how why)sender limited by min(cwndrwnd)
roughly
cwnd is dynamic function of perceived network congestion
rate = cwndRTT bytessec
LastByteSent-LastByteAcked le cwnd
cwndbytes
RTT
ACK(s)
Transport Layer 3-81
TCP Congestion Control more details
segment loss event reducing cwndtimeout no response from receiver
cut cwnd to 13 duplicate ACKs at least some segments getting through (recall fast retransmit)
cut cwnd in half less aggressively than on timeout
ACK received increase cwndTwo modes of operation
slowstart phase bull increase exponentially
fast (despite name) at connection start or following timeout
congestion avoidance bull increase linearly
Transport Layer 3-82
TCP Slow Start Phasewhen connection begins cwnd = 1 MSS
example MSS = 500 bytes amp RTT = 200 msecinitial rate = 20 kbps
available bandwidth may be gtgt MSSRTT
desirable to quickly ramp up to respectable rate
increase rate exponentially until first loss event or when threshold reached
double cwnd every RTTdone by incrementing cwnd by 1 for every ACK received
Host A
one segment
RTT
Host B
time
two segments
four segments
Transport Layer 3-83
Slow Start ExampleThe congestion window size grows very rapidly
For every ACK we increase CongWin by 1 irrespective of the number of segments ACKrsquoeddouble CongWinevery RTTinitial rate is slow but ramps up exponentially fast
TCP slows down the increase of CongWinwhen CongWin gt ssthresh
segment 1
ACK for segment 1
cwnd = 1
cwnd = 2 segment 2segment 3
ACK for segments 2
cwnd = 4 segment 4segment 5segment 6
ACK for segments 4
cwnd = 7
ACK for segments 3
ACK for segments 5
ACK for segments 6
cwnd = 3
cwnd = 5
cwnd = 6ACK for segments 7
cwnd = 8
segment 7
Transport Layer 3-84
TCP Congestion Avoidance Phase
when cwnd gt ssthreshgrow cwnd linearly
increase cwnd by 1 MSS per RTT approach possible congestion slower than in slowstartimplementation cwnd= cwnd + MSScwndfor each ACK received
ACKs increase cwndby 1 MSS per RTT additive increaseloss cut cwnd in half (non-timeout-detected loss ) multiplicative decrease
AIMD
AIMD Additive IncreaseMultiplicative Decrease
Transport Layer 3-85
Congestion AvoidanceCongestion avoidance phase is started if CongWin has reached the slow-start threshold value
If CongWin gt= ssthresh then each time an ACK is received increment CongWin as follows
bull CongWin = CongWin + 1CongWin (CongWin in segments)
bull In actual TCP implementation CongWin is in BytesCongWin = CongWin + MSS (MSSCongWin)
So CongWin is increased by one only if all CongWinsegments have been acknowledged
Transport Layer 3-86
Example Slow StartCongestion AvoidanceAssume that
ssthresh = 8
cwnd = 1
cwnd = 2
cwnd = 4
cwnd = 8
cwnd = 9
cwnd = 10
02468
101214
t=0
t=2
t=4
t=6
Roundtrip times
Cw
nd(in
seg
men
ts)
ssthresh
cwnd = 3
cwnd = 5cwnd = 6cwnd = 7
Transport Layer 3-87
Slow Start Congestion AvoidanceA typical plot of CongWin for a TCP connection
(MSS = 1500 bytes) with TCP Tahoe
SS
CA
ssthresh
Transport Layer 3-88
Responses to CongestionTCP assumes there is congestion if it detects a packet lossA TCP sender can detect lost packets via loss events
bull Timeout of a retransmission timerbull Receipt of 3 duplicate ACKs (fast retransmit)
TCP interprets a Timeout as a binary congestion signal When a timeout occurs the sender performs
ssthresh is set to half the current size of the congestion window
ssthresh = CongWin 2CongWin is reset to one
CongWin = 1and slow-start is entered
Transport Layer 3-89
Fast Recovery (differentiation btwn two loss events) After 3 dup ACKs (fast Retransmit)
ssthresh = CongWin2CongWin = CongWin2window then grows linearly
But after timeout eventCongWin = 1 MSS window then grows exponentiallyto the threshold then grows linearly
bull 3 dup ACKs indicates network capable of delivering some segmentsbull timeout before 3 dup ACKs is ldquomore alarmingrdquo
Philosophy
3-90
TCP Congestion ControlInitially
CongWin = 1ssthresh = advertised window size
New Ack receivedif (CongWin lt ssthresh) Slow Start
CongWin = CongWin + 1else Congestion Avoidance
CongWin = CongWin + 1CongWinTimeout
ssthresh = CongWin2CongWin = 1
Fast Retransmissionssthresh = CongWin2CongWin = CongWin2
Slow Start (exponential increase phase) is continued until CongWin reaches half of the level where the loss event occurred last time CongWin is increased slowly after (linear increase in Congestion Avoidance phase)
Transport Layer 3-91
Popular ldquoflavorsrdquo of TCP
ssthresh
ssthresh
TCP Tahoe
TCP Reno
Transmission round
cwnd
win
dow
siz
e (in
seg
men
ts)
Transport Layer 3-92
Summary TCP Congestion ControlWhen CongWin is below Threshold sender in slow-start phase window grows exponentiallyWhen CongWin is above Threshold sender is in congestion-avoidance phase window grows linearlyWhen a triple duplicate ACK occurs Threshold set to CongWin2 and CongWin set to ThresholdWhen timeout occurs Threshold set to CongWin2 and CongWin is set to 1 MSS The actual sender window size is determined based on the congestion and flow control algorithms
SenderWin=min(RcvWinCongWin)
Transport Layer 3-93
TCP Congestion Control SummaryEvent State TCP Sender Action Commentary
ACK receipt for previously unackeddata
Slow Start (SS)
CongWin = CongWin + MSS If (CongWin gt Threshold)
set state to ldquoCongestion Avoidancerdquo
Resulting in a doubling of CongWin every RTT
ACK receipt for previously unackeddata
CongestionAvoidance (CA)
CongWin = CongWin+MSS (MSSCongWin)
Additive increase resulting in increase of CongWin by 1 MSS every RTT
Loss event detected by triple duplicate ACK
SS or CA Threshold = CongWin2 CongWin = ThresholdSet state to ldquoCongestion Avoidancerdquo
Fast recovery implementing multiplicative decrease CongWin will not drop below 1 MSS
Timeout SS or CA Threshold = CongWin2 CongWin = 1 MSSSet state to ldquoSlow Startrdquo
Enter slow start
Duplicate ACK
SS or CA Increment duplicate ACK count for segment being acked
CongWin and Threshold not changed
Transport Layer 3-94
TCP throughput
Q whatrsquos average throughout of TCP as function of window size RTT
ignoring slow startlet W be window size when loss occurs
when window is W throughput is WRTTjust after loss window drops to W2 throughput to W2RTT average throughout 75 WRTT
Transport Layer 3-95
TCP Futures TCP over ldquolong fat pipesrdquo
example 1500 byte segments 100ms RTT want 10 Gbps throughputrequires window size W = 83333 in-flight segmentsthroughput in terms of loss rate
L = 210-10 Wownew versions of TCP for high-speed
LRTTMSSsdot221
Transport Layer 3-96
Fairness goal if K TCP sessions share same bottleneck link of bandwidth R each should have average rate of RK
TCP connection 1
bottleneckrouter
capacity R
TCP connection 2
TCP Fairness
Transport Layer 3-97
Why is TCP fairTwo competing sessions
Additive increase gives slope of 1 as throughout increasesmultiplicative decrease decreases throughput proportionally
R
R
equal bandwidth share
Connection 1 throughput
Conn
ecti
on 2
thr
ough
p ut
congestion avoidance additive increaseloss decrease window by factor of 2
congestion avoidance additive increaseloss decrease window by factor of 2
Transport Layer 3-98
Fairness (more)Fairness and UDP
Multimedia apps often do not use TCP
do not want rate throttled by congestion control
Instead use UDPpump audiovideo at constant rate tolerate packet loss
Research area TCP friendly
Fairness and parallel TCP connectionsnothing prevents app from opening parallel cnctionsbetween 2 hostsWeb browsers do this Example link of rate R supporting 9 cnctions
new app asks for 1 TCP gets rate R10new app asks for 11 TCPs gets R2
Transport Layer 3-99
TCP Connection ManagementRecall TCP sender receiver
establish ldquoconnectionrdquobefore exchanging data segmentsinitialize TCP variables
seq sbuffers flow control info (eg RcvWindow)
client connection initiatorSocket clientSocket = new Socket(hostnameport
number)
server contacted by clientSocket connectionSocket = welcomeSocketaccept()
Three way handshakeStep 1 client host sends TCP
SYN segment to serverspecifies initial seq no data
Step 2 server host receives SYN replies with SYNACK segment
server allocates buffersspecifies server initial seq
Step 3 client receives SYNACK replies with ACK segment which may contain data
Transport Layer 3-100
TCP Connection Management (cont)
Closing a connection
client closes socketclientSocketclose()
Step 1 client end system sends TCP FIN control segment to server
Step 2 server receives FIN replies with ACK Closes connection sends FIN
client
FIN
server
ACK
ACK
FIN
close
close
closed
tim
ed w
ait
Transport Layer 3-101
TCP Connection Management (cont)
Step 3 client receives FIN replies with ACK
Enters ldquotimed waitrdquo -will respond with ACK to received FINs
Step 4 server receives ACK Connection closed
client
FIN
server
ACK
ACK
FIN
closing
closing
closed
tim
ed w
ait
closed
Transport Layer 3-102
TCP Connection Management (cont)
TCP clientlifecycle
TCP serverlifecycle
Transport Layer 3-103
Tuning TCPIP Parameters TCPIP parameters
A set of default values may not be optimal for all applicationsThe network administrator may wish to turn on or off some TCPIP functions for performance or security considerations
Many Unix and Linux systems provide some flexibility in tuning the TCPIP kernelsbinsysctl is used to configure the Linux kernel parameters at runtime
Default kernel configuration file is sbinsysctlconfFrequently used sysctl options
bull sysctl ndasha or sysctl ndashA list all current valuesbull sysctl ndashp file_name load the sysctl setting from a configuration
filebull sysctl ndashw variable=value change the value of the parameter
Transport Layer 3-104
SomeTCP Parameters in Linux Kerneltcp_syn_retries
Number of SYN packets the kernel will send before giving up on the new connection
tcp_synack_retriesnumber of SYN+ACK packets sent before the kernel gives up on the connection
tcp_window_scalingMaximum window size of 65535 bytes not enough for for really fast networks The window scaling options allows for almost gigabyte windows which is good for connections with large delay-bandwidth product
tcp_max_syn_backlogMaximal number of remembered connection requests which still did not receive an acknowledgment from connecting client
tcp_fin_timeoutHow many seconds to wait for a final FIN packet before the socket is closed required to prevent denial-of-service (DoS) attacks Default value is 60 seconds
Transport Layer 3-105
SomeTCP Parameters in Linux Kerneltcp_rmem
This is a vector of 3 integers [min default max] These parameters are used by TCP to dynamically adjust receive buffer sizesmin - minimum size of the receive buffer used by each TCP socket The default value is 4K default - the default size of the receive buffer for a TCP socket The default value is 87380 bytes and is lowered to 43689 in low memory systems If larger receive buffer sizes are desired this value should be increased max - the maximum size of the receive buffer used by each TCP socket The default value of 873802 bytes is lowered to 87380 in low memory systems
tcp_smemSend buffer parameters [min default max] similar to tcp_rmem
- Chapter 3 Transport Layer
- Transport services and protocols
- Transport vs network layer
- Internet transport-layer protocols
- Multiplexingdemultiplexing
- How demultiplexing works
- Connectionless demultiplexing
- Connection-oriented demux
- Connection-oriented demux (cont)
- Connection-oriented demux Threaded Web Server
- UDP User Datagram Protocol [RFC 768]
- UDP more
- UDP checksum
- Principles of Reliable data transfer
- Reliable data transfer getting started
- Reliable data transfer getting started
- Rdt10 reliable transfer over a reliable channel
- Rdt20 channel with bit errors
- rdt20 FSM specification
- rdt20 operation with no errors
- rdt20 error scenario
- rdt20 has a fatal flaw
- rdt21 sender handles garbled ACKNAKs
- rdt21 receiver handles garbled ACKNAKs
- rdt21 discussion
- rdt22 a NAK-free protocol
- rdt22 sender receiver fragments
- rdt30 channels with errors and loss
- rdt30 sender
- rdt30 in action
- rdt30 in action
- Performance of rdt30
- rdt30 stop-and-wait operation
- Pipelined protocols
- Pipelining increased utilization
- Go-Back-N
- GBN sender extended FSM
- GBN receiver extended FSM
- GBN inaction
- Selective Repeat
- Selective repeat sender receiver windows
- Selective repeat
- Selective repeat in action
- Selective repeat dilemma
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- TCP Overview RFCs 793 1122 1323 2018 2581
- TCP segment structure
- TCP seq rsquos and ACKs
- TCP Round Trip Time and Timeout
- TCP Round Trip Time and Timeout
- Example RTT estimation
- TCP Round Trip Time and Timeout
- TCP reliable data transfer
- TCP sender events
- TCP sender(simplified)
- TCP retransmission scenarios
- TCP retransmission scenarios (more)
- TCP ACK generation [RFC 1122 RFC 2581]
- Fast Retransmit
- Fast Retransmit
- Fast retransmit algorithm
- TCP Flow Control
- TCP Flow control how it works
- Sliding Window Flow Control Example
- Principles of Congestion Control
- Causescosts of congestion scenario 1
- Causescosts of congestion scenario 2
- Causescosts of congestion scenario 2
- Causescosts of congestion scenario 3
- Causescosts of congestion scenario 3
- Approaches towards congestion control
- TCP Congestion Control
- TCP congestion control bandwidth probing
- TCP Congestion Control details
- TCP Congestion Control more details
- TCP Slow Start Phase
- Slow Start Example
- TCP Congestion Avoidance Phase
- Congestion Avoidance
- Example Slow StartCongestion Avoidance
- Slow Start Congestion Avoidance
- Responses to Congestion
- Fast Recovery (differentiation btwn two loss events)
- TCP Congestion Control
- Popular ldquoflavorsrdquo of TCP
- Summary TCP Congestion Control
- TCP Congestion Control Summary
- TCP throughput
- TCP Futures TCP over ldquolong fat pipesrdquo
- TCP Fairness
- Why is TCP fair
- Fairness (more)
- TCP Connection Management
- TCP Connection Management (cont)
- TCP Connection Management (cont)
- TCP Connection Management (cont)
- Tuning TCPIP Parameters
- SomeTCP Parameters in Linux Kernel
- SomeTCP Parameters in Linux Kernel
-
Transport Layer 3-54
TCP seq rsquos and ACKsSeq rsquos
byte stream ldquonumberrdquo of first byte in segmentrsquos dataACKs
seq of next byte expected from other sidecumulative ACK
Q how receiver handles out-of-order segmentsA TCP spec doesnrsquot say - up to implementationWidely used implementations of TCP buffer out-of-order segments
Transport Layer 3-55
TCP Round Trip Time and Timeout
Q how to set TCP timeout valuelonger than RTT
but RTT variestoo short premature timeout
unnecessary retransmissions
too long slow reaction to segment loss
Q how to estimate RTTSampleRTT measured time from segment transmission until ACK receipt
ignore retransmissionsSampleRTT will vary want estimated RTT ldquosmootherrdquo
average several recent measurements not just current SampleRTT
Transport Layer 3-56
TCP Round Trip Time and Timeout
EstimatedRTT = (1- α)EstimatedRTT + αSampleRTT
Exponential weighted moving averageinfluence of past sample decreases exponentially fasttypical value α = 0125
Transport Layer 3-57
Example RTT estimationRTT gaiacsumassedu to fantasiaeurecomfr
100
150
200
250
300
350
1 8 15 22 29 36 43 50 57 64 71 78 85 92 99 106
time (seconnds)
RTT
(mill
iseco
nds)
SampleRTT Estimated RTT
Transport Layer 3-58
TCP Round Trip Time and TimeoutSetting the timeout
EstimatedRTT plus ldquosafety marginrdquolarge variation in EstimatedRTT -gt larger safety margin
first estimate of how much SampleRTT deviates from EstimatedRTT
TimeoutInterval = EstimatedRTT + 4DevRTT
DevRTT = (1-β)DevRTT +β|SampleRTT-EstimatedRTT|
(typically β = 025)
Then set timeout interval
Transport Layer 3-59
TCP reliable data transfer
TCP creates rdtservice on top of IPrsquos unreliable servicePipelined segmentsCumulative acksTCP uses single retransmission timer however it just retransmits the first segment in the window
Retransmissions are triggered by
timeout eventsduplicate acks
Initially consider simplified TCP sender
ignore duplicate acksignore flow control congestion control
Transport Layer 3-60
TCP sender eventsdata rcvd from app
Create segment with seq seq is byte-stream number of first data byte in segmentstart timer if not already running (think of timer as for oldest unacked segment)expiration interval TimeOutInterval
timeoutretransmit segment that caused timeout (first segment in the window)restart timer
Ack rcvdIf acknowledges previously unacked segments
update what is known to be ackedstart timer if there are outstanding segments
Transport Layer 3-61
TCP sender(simplified)
NextSeqNum = InitialSeqNumSendBase = InitialSeqNum
loop (forever) switch(event)
event data received from application above create TCP segment with sequence number NextSeqNumif (timer currently not running)
start timerpass segment to IP NextSeqNum = NextSeqNum + length(data)
event timer timeoutretransmit not-yet-acknowledged segment with
smallest sequence numberstart timer
event ACK received with ACK field value of y if (y gt SendBase)
SendBase = yif (there are currently not-yet-acknowledged segments)
start timer
end of loop forever
Commentbull SendBase-1 last cumulatively ackrsquoed byteExamplebull SendBase-1 = 71y= 73 so the rcvrwants 73+ y gt SendBase sothat new data is acked
Transport Layer 3-62
TCP retransmission scenariosHost A
Seq=100 20 bytes data
ACK=100
timepremature timeout
Host B
Seq=92 8 bytes data
ACK=120
Seq=92 8 bytes data
Seq=
92 t
imeo
ut
ACK=120
Host A
Seq=92 8 bytes data
ACK=100
loss
tim
eout
lost ACK scenario
Host B
X
Seq=92 8 bytes data
ACK=100
time
Seq=
92 t
imeo
utSendBase
= 100
SendBase= 120
SendBase= 120
Sendbase= 100
Transport Layer 3-63
TCP retransmission scenarios (more)Host A
Seq=92 8 bytes data
ACK=100
loss
tim
eout
Cumulative ACK scenario
Host B
X
Seq=100 20 bytes data
ACK=120
time
SendBase= 120
Transport Layer 3-64
TCP ACK generation [RFC 1122 RFC 2581]
Event at Receiver
Arrival of in-order segment withexpected seq All data up toexpected seq already ACKed
Arrival of in-order segment withexpected seq One other segment has ACK pending
Arrival of out-of-order segmenthigher-than-expect seq Gap detected
Arrival of segment that partially or completely fills gap
TCP Receiver action
Delayed ACK Wait up to 500msfor next segment If no next segmentsend ACK
Immediately send single cumulative ACK ACKing both in-order segments
Immediately send duplicate ACK indicating seq of next expected byte
Immediate send ACK provided thatsegment startsat lower end of gap
Transport Layer 3-65
Fast Retransmit
Time-out period often relatively long
long delay before resending lost packet
Detect lost segments via duplicate ACKs
Sender often sends many segments back-to-backIf segment is lost there will likely be many duplicate ACKs
If sender receives 3 ACKs for the same data it supposes that segment after ACKeddata was lost
fast retransmit resend segment before timer expires
Transport Layer 3-66
Fast RetransmitResend a segment after 3 duplicate ACKs since a duplicate ACK means that an out-of sequence segment was receivedduplicate ACKs due to packet reorderingif window is small donrsquot get duplicate ACKs
Host A
tim
eout
Host B
time
X
resend seq X2
seq x1seq x2seq x3seq x4seq x5
ACK x1
ACK x1ACK x1ACK x1
tripleduplicate
ACKs
Transport Layer 3-67
event ACK received with ACK field value of y if (y gt SendBase)
SendBase = yif (there are currently not-yet-acknowledged segments)
start timer
else increment count of dup ACKs received for yif (count of dup ACKs received for y = 3)
resend segment with sequence number y
Fast retransmit algorithm
a duplicate ACK for already ACKed segment
fast retransmit
Transport Layer 3-68
TCP Flow Control
receive side of TCP connection has a receive buffer
speed-matching service matching the send rate to the receiving apprsquos drain rate
app process may be slow at reading from buffer
sender wonrsquot overflowreceiverrsquos buffer by
transmitting too muchtoo fast
flow control
Transport Layer 3-69
TCP Flow control how it works
(Suppose TCP receiver discards out-of-order segments)spare room in buffer
= RcvWin
= RcvBuffer-[LastByteRcvd -LastByteRead]
Rcvr advertises spare room by including value of RcvWin in segmentsSender limits unACKeddata to RcvWin
guarantees receive buffer doesnrsquot overflow
Transport Layer 3-70
Sliding Window Flow Control Example
3K
2K SeqNo=0
ReceiverBuffer
0 4KSendersends 2Kof data
2K
AckNo=2048 RcvWin=2048Sendersends 2Kof data 2K SeqNo=2048
4K
AckNo=4096 RcvWin=0
AckNo=4096 RcvWin=1024
Sender blocked
Transport Layer 3-71
Principles of Congestion Control
Congestioninformally ldquotoo many sources sending too much data too fast for network to handlerdquodifferent from flow controlmanifestations
lost packets (buffer overflow at routers)long delays (queueing in router buffers)
a top-10 problem
Transport Layer 3-72
Causescosts of congestion scenario 1
two senders two receiversone router infinite buffers no retransmission
large delays when congestedmaximum achievable throughput
unlimited shared output link buffers
Host Aλin original data
Host B
λout
Transport Layer 3-73
Causescosts of congestion scenario 2
one router finite buffers sender retransmission of lost packet
finite shared output link buffers
Host A λin original data
Host B
λout
λin original data plus retransmitted data
Transport Layer 3-74
Causescosts of congestion scenario 2always (goodput)ldquoperfectrdquo retransmission only when loss
retransmission of delayed (not lost) packet makes larger(than perfect case) for same
λin
λout=
λin
λoutgtλ
inλout
ldquocostsrdquo of congestionmore work (retrans) for given ldquogoodputrdquounneeded retransmissions link carries multiple copies of pkt
R2
R2λin
λ out
b
R2
R2λin
λ out
a
R2
R2λin
λ out
c
R4
R3
Transport Layer 3-75
Causescosts of congestion scenario 3four sendersmultihop pathstimeoutretransmit
λin
Q what happens as and increase λ
in
finite shared output link buffers
Host Aλin original data
Host B
λout
λin original data plus retransmitted data
Transport Layer 3-76
Causescosts of congestion scenario 3
another ldquocostrdquo of congestionwhen packet dropped any ldquoupstream transmission capacity used for that packet was wasted
Host A
Host B
λou
t
Transport Layer 3-77
Approaches towards congestion control
End-end congestion controlno explicit feedback from networkcongestion inferred from end-system observed loss delayapproach taken by TCP
Network-assisted congestion controlrouters provide feedback to end systems
single bit indicating congestion (SNA DECbit TCPIP ECN ATM)explicit rate sender should send at
Two broad approaches towards congestion control
Transport Layer 3-78
TCP Congestion Control
end-end control (no network assistance)sender limits transmissionLastByteSent-LastByteAcked
le CongWin
CongWin is dynamic function of perceived network congestion
How does sender perceive congestionloss event = timeout or3 duplicate acksTCP sender reduces rate (CongWin) after loss event
two modes of operationSlow Start (SS)Congestion avoidance (CA) or Additive Increase Multiplicative Decrease (AIMD)
Transport Layer 3-79
TCP congestion control bandwidth probing
ldquoprobing for bandwidthrdquo increase transmission rate on receipt of ACK until eventually loss occurs then decrease transmission rate
continue to increase on ACK decrease on loss (since available bandwidth is changing depending on other connections in network)
ACKs being received so increase rate
X
X
XX
X loss so decrease rate
send
ing
rate
time
Q how fast to increasedecreasedetails to follow
TCPrsquosldquosawtoothrdquobehavior
Transport Layer 3-80
TCP Congestion Control details
sender limits rate by limiting number of unACKed bytes ldquoin pipelinerdquo
cwnd differs from rwnd (how why)sender limited by min(cwndrwnd)
roughly
cwnd is dynamic function of perceived network congestion
rate = cwndRTT bytessec
LastByteSent-LastByteAcked le cwnd
cwndbytes
RTT
ACK(s)
Transport Layer 3-81
TCP Congestion Control more details
segment loss event reducing cwndtimeout no response from receiver
cut cwnd to 13 duplicate ACKs at least some segments getting through (recall fast retransmit)
cut cwnd in half less aggressively than on timeout
ACK received increase cwndTwo modes of operation
slowstart phase bull increase exponentially
fast (despite name) at connection start or following timeout
congestion avoidance bull increase linearly
Transport Layer 3-82
TCP Slow Start Phasewhen connection begins cwnd = 1 MSS
example MSS = 500 bytes amp RTT = 200 msecinitial rate = 20 kbps
available bandwidth may be gtgt MSSRTT
desirable to quickly ramp up to respectable rate
increase rate exponentially until first loss event or when threshold reached
double cwnd every RTTdone by incrementing cwnd by 1 for every ACK received
Host A
one segment
RTT
Host B
time
two segments
four segments
Transport Layer 3-83
Slow Start ExampleThe congestion window size grows very rapidly
For every ACK we increase CongWin by 1 irrespective of the number of segments ACKrsquoeddouble CongWinevery RTTinitial rate is slow but ramps up exponentially fast
TCP slows down the increase of CongWinwhen CongWin gt ssthresh
segment 1
ACK for segment 1
cwnd = 1
cwnd = 2 segment 2segment 3
ACK for segments 2
cwnd = 4 segment 4segment 5segment 6
ACK for segments 4
cwnd = 7
ACK for segments 3
ACK for segments 5
ACK for segments 6
cwnd = 3
cwnd = 5
cwnd = 6ACK for segments 7
cwnd = 8
segment 7
Transport Layer 3-84
TCP Congestion Avoidance Phase
when cwnd gt ssthreshgrow cwnd linearly
increase cwnd by 1 MSS per RTT approach possible congestion slower than in slowstartimplementation cwnd= cwnd + MSScwndfor each ACK received
ACKs increase cwndby 1 MSS per RTT additive increaseloss cut cwnd in half (non-timeout-detected loss ) multiplicative decrease
AIMD
AIMD Additive IncreaseMultiplicative Decrease
Transport Layer 3-85
Congestion AvoidanceCongestion avoidance phase is started if CongWin has reached the slow-start threshold value
If CongWin gt= ssthresh then each time an ACK is received increment CongWin as follows
bull CongWin = CongWin + 1CongWin (CongWin in segments)
bull In actual TCP implementation CongWin is in BytesCongWin = CongWin + MSS (MSSCongWin)
So CongWin is increased by one only if all CongWinsegments have been acknowledged
Transport Layer 3-86
Example Slow StartCongestion AvoidanceAssume that
ssthresh = 8
cwnd = 1
cwnd = 2
cwnd = 4
cwnd = 8
cwnd = 9
cwnd = 10
02468
101214
t=0
t=2
t=4
t=6
Roundtrip times
Cw
nd(in
seg
men
ts)
ssthresh
cwnd = 3
cwnd = 5cwnd = 6cwnd = 7
Transport Layer 3-87
Slow Start Congestion AvoidanceA typical plot of CongWin for a TCP connection
(MSS = 1500 bytes) with TCP Tahoe
SS
CA
ssthresh
Transport Layer 3-88
Responses to CongestionTCP assumes there is congestion if it detects a packet lossA TCP sender can detect lost packets via loss events
bull Timeout of a retransmission timerbull Receipt of 3 duplicate ACKs (fast retransmit)
TCP interprets a Timeout as a binary congestion signal When a timeout occurs the sender performs
ssthresh is set to half the current size of the congestion window
ssthresh = CongWin 2CongWin is reset to one
CongWin = 1and slow-start is entered
Transport Layer 3-89
Fast Recovery (differentiation btwn two loss events) After 3 dup ACKs (fast Retransmit)
ssthresh = CongWin2CongWin = CongWin2window then grows linearly
But after timeout eventCongWin = 1 MSS window then grows exponentiallyto the threshold then grows linearly
bull 3 dup ACKs indicates network capable of delivering some segmentsbull timeout before 3 dup ACKs is ldquomore alarmingrdquo
Philosophy
3-90
TCP Congestion ControlInitially
CongWin = 1ssthresh = advertised window size
New Ack receivedif (CongWin lt ssthresh) Slow Start
CongWin = CongWin + 1else Congestion Avoidance
CongWin = CongWin + 1CongWinTimeout
ssthresh = CongWin2CongWin = 1
Fast Retransmissionssthresh = CongWin2CongWin = CongWin2
Slow Start (exponential increase phase) is continued until CongWin reaches half of the level where the loss event occurred last time CongWin is increased slowly after (linear increase in Congestion Avoidance phase)
Transport Layer 3-91
Popular ldquoflavorsrdquo of TCP
ssthresh
ssthresh
TCP Tahoe
TCP Reno
Transmission round
cwnd
win
dow
siz
e (in
seg
men
ts)
Transport Layer 3-92
Summary TCP Congestion ControlWhen CongWin is below Threshold sender in slow-start phase window grows exponentiallyWhen CongWin is above Threshold sender is in congestion-avoidance phase window grows linearlyWhen a triple duplicate ACK occurs Threshold set to CongWin2 and CongWin set to ThresholdWhen timeout occurs Threshold set to CongWin2 and CongWin is set to 1 MSS The actual sender window size is determined based on the congestion and flow control algorithms
SenderWin=min(RcvWinCongWin)
Transport Layer 3-93
TCP Congestion Control SummaryEvent State TCP Sender Action Commentary
ACK receipt for previously unackeddata
Slow Start (SS)
CongWin = CongWin + MSS If (CongWin gt Threshold)
set state to ldquoCongestion Avoidancerdquo
Resulting in a doubling of CongWin every RTT
ACK receipt for previously unackeddata
CongestionAvoidance (CA)
CongWin = CongWin+MSS (MSSCongWin)
Additive increase resulting in increase of CongWin by 1 MSS every RTT
Loss event detected by triple duplicate ACK
SS or CA Threshold = CongWin2 CongWin = ThresholdSet state to ldquoCongestion Avoidancerdquo
Fast recovery implementing multiplicative decrease CongWin will not drop below 1 MSS
Timeout SS or CA Threshold = CongWin2 CongWin = 1 MSSSet state to ldquoSlow Startrdquo
Enter slow start
Duplicate ACK
SS or CA Increment duplicate ACK count for segment being acked
CongWin and Threshold not changed
Transport Layer 3-94
TCP throughput
Q whatrsquos average throughout of TCP as function of window size RTT
ignoring slow startlet W be window size when loss occurs
when window is W throughput is WRTTjust after loss window drops to W2 throughput to W2RTT average throughout 75 WRTT
Transport Layer 3-95
TCP Futures TCP over ldquolong fat pipesrdquo
example 1500 byte segments 100ms RTT want 10 Gbps throughputrequires window size W = 83333 in-flight segmentsthroughput in terms of loss rate
L = 210-10 Wownew versions of TCP for high-speed
LRTTMSSsdot221
Transport Layer 3-96
Fairness goal if K TCP sessions share same bottleneck link of bandwidth R each should have average rate of RK
TCP connection 1
bottleneckrouter
capacity R
TCP connection 2
TCP Fairness
Transport Layer 3-97
Why is TCP fairTwo competing sessions
Additive increase gives slope of 1 as throughout increasesmultiplicative decrease decreases throughput proportionally
R
R
equal bandwidth share
Connection 1 throughput
Conn
ecti
on 2
thr
ough
p ut
congestion avoidance additive increaseloss decrease window by factor of 2
congestion avoidance additive increaseloss decrease window by factor of 2
Transport Layer 3-98
Fairness (more)Fairness and UDP
Multimedia apps often do not use TCP
do not want rate throttled by congestion control
Instead use UDPpump audiovideo at constant rate tolerate packet loss
Research area TCP friendly
Fairness and parallel TCP connectionsnothing prevents app from opening parallel cnctionsbetween 2 hostsWeb browsers do this Example link of rate R supporting 9 cnctions
new app asks for 1 TCP gets rate R10new app asks for 11 TCPs gets R2
Transport Layer 3-99
TCP Connection ManagementRecall TCP sender receiver
establish ldquoconnectionrdquobefore exchanging data segmentsinitialize TCP variables
seq sbuffers flow control info (eg RcvWindow)
client connection initiatorSocket clientSocket = new Socket(hostnameport
number)
server contacted by clientSocket connectionSocket = welcomeSocketaccept()
Three way handshakeStep 1 client host sends TCP
SYN segment to serverspecifies initial seq no data
Step 2 server host receives SYN replies with SYNACK segment
server allocates buffersspecifies server initial seq
Step 3 client receives SYNACK replies with ACK segment which may contain data
Transport Layer 3-100
TCP Connection Management (cont)
Closing a connection
client closes socketclientSocketclose()
Step 1 client end system sends TCP FIN control segment to server
Step 2 server receives FIN replies with ACK Closes connection sends FIN
client
FIN
server
ACK
ACK
FIN
close
close
closed
tim
ed w
ait
Transport Layer 3-101
TCP Connection Management (cont)
Step 3 client receives FIN replies with ACK
Enters ldquotimed waitrdquo -will respond with ACK to received FINs
Step 4 server receives ACK Connection closed
client
FIN
server
ACK
ACK
FIN
closing
closing
closed
tim
ed w
ait
closed
Transport Layer 3-102
TCP Connection Management (cont)
TCP clientlifecycle
TCP serverlifecycle
Transport Layer 3-103
Tuning TCPIP Parameters TCPIP parameters
A set of default values may not be optimal for all applicationsThe network administrator may wish to turn on or off some TCPIP functions for performance or security considerations
Many Unix and Linux systems provide some flexibility in tuning the TCPIP kernelsbinsysctl is used to configure the Linux kernel parameters at runtime
Default kernel configuration file is sbinsysctlconfFrequently used sysctl options
bull sysctl ndasha or sysctl ndashA list all current valuesbull sysctl ndashp file_name load the sysctl setting from a configuration
filebull sysctl ndashw variable=value change the value of the parameter
Transport Layer 3-104
SomeTCP Parameters in Linux Kerneltcp_syn_retries
Number of SYN packets the kernel will send before giving up on the new connection
tcp_synack_retriesnumber of SYN+ACK packets sent before the kernel gives up on the connection
tcp_window_scalingMaximum window size of 65535 bytes not enough for for really fast networks The window scaling options allows for almost gigabyte windows which is good for connections with large delay-bandwidth product
tcp_max_syn_backlogMaximal number of remembered connection requests which still did not receive an acknowledgment from connecting client
tcp_fin_timeoutHow many seconds to wait for a final FIN packet before the socket is closed required to prevent denial-of-service (DoS) attacks Default value is 60 seconds
Transport Layer 3-105
SomeTCP Parameters in Linux Kerneltcp_rmem
This is a vector of 3 integers [min default max] These parameters are used by TCP to dynamically adjust receive buffer sizesmin - minimum size of the receive buffer used by each TCP socket The default value is 4K default - the default size of the receive buffer for a TCP socket The default value is 87380 bytes and is lowered to 43689 in low memory systems If larger receive buffer sizes are desired this value should be increased max - the maximum size of the receive buffer used by each TCP socket The default value of 873802 bytes is lowered to 87380 in low memory systems
tcp_smemSend buffer parameters [min default max] similar to tcp_rmem
- Chapter 3 Transport Layer
- Transport services and protocols
- Transport vs network layer
- Internet transport-layer protocols
- Multiplexingdemultiplexing
- How demultiplexing works
- Connectionless demultiplexing
- Connection-oriented demux
- Connection-oriented demux (cont)
- Connection-oriented demux Threaded Web Server
- UDP User Datagram Protocol [RFC 768]
- UDP more
- UDP checksum
- Principles of Reliable data transfer
- Reliable data transfer getting started
- Reliable data transfer getting started
- Rdt10 reliable transfer over a reliable channel
- Rdt20 channel with bit errors
- rdt20 FSM specification
- rdt20 operation with no errors
- rdt20 error scenario
- rdt20 has a fatal flaw
- rdt21 sender handles garbled ACKNAKs
- rdt21 receiver handles garbled ACKNAKs
- rdt21 discussion
- rdt22 a NAK-free protocol
- rdt22 sender receiver fragments
- rdt30 channels with errors and loss
- rdt30 sender
- rdt30 in action
- rdt30 in action
- Performance of rdt30
- rdt30 stop-and-wait operation
- Pipelined protocols
- Pipelining increased utilization
- Go-Back-N
- GBN sender extended FSM
- GBN receiver extended FSM
- GBN inaction
- Selective Repeat
- Selective repeat sender receiver windows
- Selective repeat
- Selective repeat in action
- Selective repeat dilemma
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- TCP Overview RFCs 793 1122 1323 2018 2581
- TCP segment structure
- TCP seq rsquos and ACKs
- TCP Round Trip Time and Timeout
- TCP Round Trip Time and Timeout
- Example RTT estimation
- TCP Round Trip Time and Timeout
- TCP reliable data transfer
- TCP sender events
- TCP sender(simplified)
- TCP retransmission scenarios
- TCP retransmission scenarios (more)
- TCP ACK generation [RFC 1122 RFC 2581]
- Fast Retransmit
- Fast Retransmit
- Fast retransmit algorithm
- TCP Flow Control
- TCP Flow control how it works
- Sliding Window Flow Control Example
- Principles of Congestion Control
- Causescosts of congestion scenario 1
- Causescosts of congestion scenario 2
- Causescosts of congestion scenario 2
- Causescosts of congestion scenario 3
- Causescosts of congestion scenario 3
- Approaches towards congestion control
- TCP Congestion Control
- TCP congestion control bandwidth probing
- TCP Congestion Control details
- TCP Congestion Control more details
- TCP Slow Start Phase
- Slow Start Example
- TCP Congestion Avoidance Phase
- Congestion Avoidance
- Example Slow StartCongestion Avoidance
- Slow Start Congestion Avoidance
- Responses to Congestion
- Fast Recovery (differentiation btwn two loss events)
- TCP Congestion Control
- Popular ldquoflavorsrdquo of TCP
- Summary TCP Congestion Control
- TCP Congestion Control Summary
- TCP throughput
- TCP Futures TCP over ldquolong fat pipesrdquo
- TCP Fairness
- Why is TCP fair
- Fairness (more)
- TCP Connection Management
- TCP Connection Management (cont)
- TCP Connection Management (cont)
- TCP Connection Management (cont)
- Tuning TCPIP Parameters
- SomeTCP Parameters in Linux Kernel
- SomeTCP Parameters in Linux Kernel
-
Transport Layer 3-55
TCP Round Trip Time and Timeout
Q how to set TCP timeout valuelonger than RTT
but RTT variestoo short premature timeout
unnecessary retransmissions
too long slow reaction to segment loss
Q how to estimate RTTSampleRTT measured time from segment transmission until ACK receipt
ignore retransmissionsSampleRTT will vary want estimated RTT ldquosmootherrdquo
average several recent measurements not just current SampleRTT
Transport Layer 3-56
TCP Round Trip Time and Timeout
EstimatedRTT = (1- α)EstimatedRTT + αSampleRTT
Exponential weighted moving averageinfluence of past sample decreases exponentially fasttypical value α = 0125
Transport Layer 3-57
Example RTT estimationRTT gaiacsumassedu to fantasiaeurecomfr
100
150
200
250
300
350
1 8 15 22 29 36 43 50 57 64 71 78 85 92 99 106
time (seconnds)
RTT
(mill
iseco
nds)
SampleRTT Estimated RTT
Transport Layer 3-58
TCP Round Trip Time and TimeoutSetting the timeout
EstimatedRTT plus ldquosafety marginrdquolarge variation in EstimatedRTT -gt larger safety margin
first estimate of how much SampleRTT deviates from EstimatedRTT
TimeoutInterval = EstimatedRTT + 4DevRTT
DevRTT = (1-β)DevRTT +β|SampleRTT-EstimatedRTT|
(typically β = 025)
Then set timeout interval
Transport Layer 3-59
TCP reliable data transfer
TCP creates rdtservice on top of IPrsquos unreliable servicePipelined segmentsCumulative acksTCP uses single retransmission timer however it just retransmits the first segment in the window
Retransmissions are triggered by
timeout eventsduplicate acks
Initially consider simplified TCP sender
ignore duplicate acksignore flow control congestion control
Transport Layer 3-60
TCP sender eventsdata rcvd from app
Create segment with seq seq is byte-stream number of first data byte in segmentstart timer if not already running (think of timer as for oldest unacked segment)expiration interval TimeOutInterval
timeoutretransmit segment that caused timeout (first segment in the window)restart timer
Ack rcvdIf acknowledges previously unacked segments
update what is known to be ackedstart timer if there are outstanding segments
Transport Layer 3-61
TCP sender(simplified)
NextSeqNum = InitialSeqNumSendBase = InitialSeqNum
loop (forever) switch(event)
event data received from application above create TCP segment with sequence number NextSeqNumif (timer currently not running)
start timerpass segment to IP NextSeqNum = NextSeqNum + length(data)
event timer timeoutretransmit not-yet-acknowledged segment with
smallest sequence numberstart timer
event ACK received with ACK field value of y if (y gt SendBase)
SendBase = yif (there are currently not-yet-acknowledged segments)
start timer
end of loop forever
Commentbull SendBase-1 last cumulatively ackrsquoed byteExamplebull SendBase-1 = 71y= 73 so the rcvrwants 73+ y gt SendBase sothat new data is acked
Transport Layer 3-62
TCP retransmission scenariosHost A
Seq=100 20 bytes data
ACK=100
timepremature timeout
Host B
Seq=92 8 bytes data
ACK=120
Seq=92 8 bytes data
Seq=
92 t
imeo
ut
ACK=120
Host A
Seq=92 8 bytes data
ACK=100
loss
tim
eout
lost ACK scenario
Host B
X
Seq=92 8 bytes data
ACK=100
time
Seq=
92 t
imeo
utSendBase
= 100
SendBase= 120
SendBase= 120
Sendbase= 100
Transport Layer 3-63
TCP retransmission scenarios (more)Host A
Seq=92 8 bytes data
ACK=100
loss
tim
eout
Cumulative ACK scenario
Host B
X
Seq=100 20 bytes data
ACK=120
time
SendBase= 120
Transport Layer 3-64
TCP ACK generation [RFC 1122 RFC 2581]
Event at Receiver
Arrival of in-order segment withexpected seq All data up toexpected seq already ACKed
Arrival of in-order segment withexpected seq One other segment has ACK pending
Arrival of out-of-order segmenthigher-than-expect seq Gap detected
Arrival of segment that partially or completely fills gap
TCP Receiver action
Delayed ACK Wait up to 500msfor next segment If no next segmentsend ACK
Immediately send single cumulative ACK ACKing both in-order segments
Immediately send duplicate ACK indicating seq of next expected byte
Immediate send ACK provided thatsegment startsat lower end of gap
Transport Layer 3-65
Fast Retransmit
Time-out period often relatively long
long delay before resending lost packet
Detect lost segments via duplicate ACKs
Sender often sends many segments back-to-backIf segment is lost there will likely be many duplicate ACKs
If sender receives 3 ACKs for the same data it supposes that segment after ACKeddata was lost
fast retransmit resend segment before timer expires
Transport Layer 3-66
Fast RetransmitResend a segment after 3 duplicate ACKs since a duplicate ACK means that an out-of sequence segment was receivedduplicate ACKs due to packet reorderingif window is small donrsquot get duplicate ACKs
Host A
tim
eout
Host B
time
X
resend seq X2
seq x1seq x2seq x3seq x4seq x5
ACK x1
ACK x1ACK x1ACK x1
tripleduplicate
ACKs
Transport Layer 3-67
event ACK received with ACK field value of y if (y gt SendBase)
SendBase = yif (there are currently not-yet-acknowledged segments)
start timer
else increment count of dup ACKs received for yif (count of dup ACKs received for y = 3)
resend segment with sequence number y
Fast retransmit algorithm
a duplicate ACK for already ACKed segment
fast retransmit
Transport Layer 3-68
TCP Flow Control
receive side of TCP connection has a receive buffer
speed-matching service matching the send rate to the receiving apprsquos drain rate
app process may be slow at reading from buffer
sender wonrsquot overflowreceiverrsquos buffer by
transmitting too muchtoo fast
flow control
Transport Layer 3-69
TCP Flow control how it works
(Suppose TCP receiver discards out-of-order segments)spare room in buffer
= RcvWin
= RcvBuffer-[LastByteRcvd -LastByteRead]
Rcvr advertises spare room by including value of RcvWin in segmentsSender limits unACKeddata to RcvWin
guarantees receive buffer doesnrsquot overflow
Transport Layer 3-70
Sliding Window Flow Control Example
3K
2K SeqNo=0
ReceiverBuffer
0 4KSendersends 2Kof data
2K
AckNo=2048 RcvWin=2048Sendersends 2Kof data 2K SeqNo=2048
4K
AckNo=4096 RcvWin=0
AckNo=4096 RcvWin=1024
Sender blocked
Transport Layer 3-71
Principles of Congestion Control
Congestioninformally ldquotoo many sources sending too much data too fast for network to handlerdquodifferent from flow controlmanifestations
lost packets (buffer overflow at routers)long delays (queueing in router buffers)
a top-10 problem
Transport Layer 3-72
Causescosts of congestion scenario 1
two senders two receiversone router infinite buffers no retransmission
large delays when congestedmaximum achievable throughput
unlimited shared output link buffers
Host Aλin original data
Host B
λout
Transport Layer 3-73
Causescosts of congestion scenario 2
one router finite buffers sender retransmission of lost packet
finite shared output link buffers
Host A λin original data
Host B
λout
λin original data plus retransmitted data
Transport Layer 3-74
Causescosts of congestion scenario 2always (goodput)ldquoperfectrdquo retransmission only when loss
retransmission of delayed (not lost) packet makes larger(than perfect case) for same
λin
λout=
λin
λoutgtλ
inλout
ldquocostsrdquo of congestionmore work (retrans) for given ldquogoodputrdquounneeded retransmissions link carries multiple copies of pkt
R2
R2λin
λ out
b
R2
R2λin
λ out
a
R2
R2λin
λ out
c
R4
R3
Transport Layer 3-75
Causescosts of congestion scenario 3four sendersmultihop pathstimeoutretransmit
λin
Q what happens as and increase λ
in
finite shared output link buffers
Host Aλin original data
Host B
λout
λin original data plus retransmitted data
Transport Layer 3-76
Causescosts of congestion scenario 3
another ldquocostrdquo of congestionwhen packet dropped any ldquoupstream transmission capacity used for that packet was wasted
Host A
Host B
λou
t
Transport Layer 3-77
Approaches towards congestion control
End-end congestion controlno explicit feedback from networkcongestion inferred from end-system observed loss delayapproach taken by TCP
Network-assisted congestion controlrouters provide feedback to end systems
single bit indicating congestion (SNA DECbit TCPIP ECN ATM)explicit rate sender should send at
Two broad approaches towards congestion control
Transport Layer 3-78
TCP Congestion Control
end-end control (no network assistance)sender limits transmissionLastByteSent-LastByteAcked
le CongWin
CongWin is dynamic function of perceived network congestion
How does sender perceive congestionloss event = timeout or3 duplicate acksTCP sender reduces rate (CongWin) after loss event
two modes of operationSlow Start (SS)Congestion avoidance (CA) or Additive Increase Multiplicative Decrease (AIMD)
Transport Layer 3-79
TCP congestion control bandwidth probing
ldquoprobing for bandwidthrdquo increase transmission rate on receipt of ACK until eventually loss occurs then decrease transmission rate
continue to increase on ACK decrease on loss (since available bandwidth is changing depending on other connections in network)
ACKs being received so increase rate
X
X
XX
X loss so decrease rate
send
ing
rate
time
Q how fast to increasedecreasedetails to follow
TCPrsquosldquosawtoothrdquobehavior
Transport Layer 3-80
TCP Congestion Control details
sender limits rate by limiting number of unACKed bytes ldquoin pipelinerdquo
cwnd differs from rwnd (how why)sender limited by min(cwndrwnd)
roughly
cwnd is dynamic function of perceived network congestion
rate = cwndRTT bytessec
LastByteSent-LastByteAcked le cwnd
cwndbytes
RTT
ACK(s)
Transport Layer 3-81
TCP Congestion Control more details
segment loss event reducing cwndtimeout no response from receiver
cut cwnd to 13 duplicate ACKs at least some segments getting through (recall fast retransmit)
cut cwnd in half less aggressively than on timeout
ACK received increase cwndTwo modes of operation
slowstart phase bull increase exponentially
fast (despite name) at connection start or following timeout
congestion avoidance bull increase linearly
Transport Layer 3-82
TCP Slow Start Phasewhen connection begins cwnd = 1 MSS
example MSS = 500 bytes amp RTT = 200 msecinitial rate = 20 kbps
available bandwidth may be gtgt MSSRTT
desirable to quickly ramp up to respectable rate
increase rate exponentially until first loss event or when threshold reached
double cwnd every RTTdone by incrementing cwnd by 1 for every ACK received
Host A
one segment
RTT
Host B
time
two segments
four segments
Transport Layer 3-83
Slow Start ExampleThe congestion window size grows very rapidly
For every ACK we increase CongWin by 1 irrespective of the number of segments ACKrsquoeddouble CongWinevery RTTinitial rate is slow but ramps up exponentially fast
TCP slows down the increase of CongWinwhen CongWin gt ssthresh
segment 1
ACK for segment 1
cwnd = 1
cwnd = 2 segment 2segment 3
ACK for segments 2
cwnd = 4 segment 4segment 5segment 6
ACK for segments 4
cwnd = 7
ACK for segments 3
ACK for segments 5
ACK for segments 6
cwnd = 3
cwnd = 5
cwnd = 6ACK for segments 7
cwnd = 8
segment 7
Transport Layer 3-84
TCP Congestion Avoidance Phase
when cwnd gt ssthreshgrow cwnd linearly
increase cwnd by 1 MSS per RTT approach possible congestion slower than in slowstartimplementation cwnd= cwnd + MSScwndfor each ACK received
ACKs increase cwndby 1 MSS per RTT additive increaseloss cut cwnd in half (non-timeout-detected loss ) multiplicative decrease
AIMD
AIMD Additive IncreaseMultiplicative Decrease
Transport Layer 3-85
Congestion AvoidanceCongestion avoidance phase is started if CongWin has reached the slow-start threshold value
If CongWin gt= ssthresh then each time an ACK is received increment CongWin as follows
bull CongWin = CongWin + 1CongWin (CongWin in segments)
bull In actual TCP implementation CongWin is in BytesCongWin = CongWin + MSS (MSSCongWin)
So CongWin is increased by one only if all CongWinsegments have been acknowledged
Transport Layer 3-86
Example Slow StartCongestion AvoidanceAssume that
ssthresh = 8
cwnd = 1
cwnd = 2
cwnd = 4
cwnd = 8
cwnd = 9
cwnd = 10
02468
101214
t=0
t=2
t=4
t=6
Roundtrip times
Cw
nd(in
seg
men
ts)
ssthresh
cwnd = 3
cwnd = 5cwnd = 6cwnd = 7
Transport Layer 3-87
Slow Start Congestion AvoidanceA typical plot of CongWin for a TCP connection
(MSS = 1500 bytes) with TCP Tahoe
SS
CA
ssthresh
Transport Layer 3-88
Responses to CongestionTCP assumes there is congestion if it detects a packet lossA TCP sender can detect lost packets via loss events
bull Timeout of a retransmission timerbull Receipt of 3 duplicate ACKs (fast retransmit)
TCP interprets a Timeout as a binary congestion signal When a timeout occurs the sender performs
ssthresh is set to half the current size of the congestion window
ssthresh = CongWin 2CongWin is reset to one
CongWin = 1and slow-start is entered
Transport Layer 3-89
Fast Recovery (differentiation btwn two loss events) After 3 dup ACKs (fast Retransmit)
ssthresh = CongWin2CongWin = CongWin2window then grows linearly
But after timeout eventCongWin = 1 MSS window then grows exponentiallyto the threshold then grows linearly
bull 3 dup ACKs indicates network capable of delivering some segmentsbull timeout before 3 dup ACKs is ldquomore alarmingrdquo
Philosophy
3-90
TCP Congestion ControlInitially
CongWin = 1ssthresh = advertised window size
New Ack receivedif (CongWin lt ssthresh) Slow Start
CongWin = CongWin + 1else Congestion Avoidance
CongWin = CongWin + 1CongWinTimeout
ssthresh = CongWin2CongWin = 1
Fast Retransmissionssthresh = CongWin2CongWin = CongWin2
Slow Start (exponential increase phase) is continued until CongWin reaches half of the level where the loss event occurred last time CongWin is increased slowly after (linear increase in Congestion Avoidance phase)
Transport Layer 3-91
Popular ldquoflavorsrdquo of TCP
ssthresh
ssthresh
TCP Tahoe
TCP Reno
Transmission round
cwnd
win
dow
siz
e (in
seg
men
ts)
Transport Layer 3-92
Summary TCP Congestion ControlWhen CongWin is below Threshold sender in slow-start phase window grows exponentiallyWhen CongWin is above Threshold sender is in congestion-avoidance phase window grows linearlyWhen a triple duplicate ACK occurs Threshold set to CongWin2 and CongWin set to ThresholdWhen timeout occurs Threshold set to CongWin2 and CongWin is set to 1 MSS The actual sender window size is determined based on the congestion and flow control algorithms
SenderWin=min(RcvWinCongWin)
Transport Layer 3-93
TCP Congestion Control SummaryEvent State TCP Sender Action Commentary
ACK receipt for previously unackeddata
Slow Start (SS)
CongWin = CongWin + MSS If (CongWin gt Threshold)
set state to ldquoCongestion Avoidancerdquo
Resulting in a doubling of CongWin every RTT
ACK receipt for previously unackeddata
CongestionAvoidance (CA)
CongWin = CongWin+MSS (MSSCongWin)
Additive increase resulting in increase of CongWin by 1 MSS every RTT
Loss event detected by triple duplicate ACK
SS or CA Threshold = CongWin2 CongWin = ThresholdSet state to ldquoCongestion Avoidancerdquo
Fast recovery implementing multiplicative decrease CongWin will not drop below 1 MSS
Timeout SS or CA Threshold = CongWin2 CongWin = 1 MSSSet state to ldquoSlow Startrdquo
Enter slow start
Duplicate ACK
SS or CA Increment duplicate ACK count for segment being acked
CongWin and Threshold not changed
Transport Layer 3-94
TCP throughput
Q whatrsquos average throughout of TCP as function of window size RTT
ignoring slow startlet W be window size when loss occurs
when window is W throughput is WRTTjust after loss window drops to W2 throughput to W2RTT average throughout 75 WRTT
Transport Layer 3-95
TCP Futures TCP over ldquolong fat pipesrdquo
example 1500 byte segments 100ms RTT want 10 Gbps throughputrequires window size W = 83333 in-flight segmentsthroughput in terms of loss rate
L = 210-10 Wownew versions of TCP for high-speed
LRTTMSSsdot221
Transport Layer 3-96
Fairness goal if K TCP sessions share same bottleneck link of bandwidth R each should have average rate of RK
TCP connection 1
bottleneckrouter
capacity R
TCP connection 2
TCP Fairness
Transport Layer 3-97
Why is TCP fairTwo competing sessions
Additive increase gives slope of 1 as throughout increasesmultiplicative decrease decreases throughput proportionally
R
R
equal bandwidth share
Connection 1 throughput
Conn
ecti
on 2
thr
ough
p ut
congestion avoidance additive increaseloss decrease window by factor of 2
congestion avoidance additive increaseloss decrease window by factor of 2
Transport Layer 3-98
Fairness (more)Fairness and UDP
Multimedia apps often do not use TCP
do not want rate throttled by congestion control
Instead use UDPpump audiovideo at constant rate tolerate packet loss
Research area TCP friendly
Fairness and parallel TCP connectionsnothing prevents app from opening parallel cnctionsbetween 2 hostsWeb browsers do this Example link of rate R supporting 9 cnctions
new app asks for 1 TCP gets rate R10new app asks for 11 TCPs gets R2
Transport Layer 3-99
TCP Connection ManagementRecall TCP sender receiver
establish ldquoconnectionrdquobefore exchanging data segmentsinitialize TCP variables
seq sbuffers flow control info (eg RcvWindow)
client connection initiatorSocket clientSocket = new Socket(hostnameport
number)
server contacted by clientSocket connectionSocket = welcomeSocketaccept()
Three way handshakeStep 1 client host sends TCP
SYN segment to serverspecifies initial seq no data
Step 2 server host receives SYN replies with SYNACK segment
server allocates buffersspecifies server initial seq
Step 3 client receives SYNACK replies with ACK segment which may contain data
Transport Layer 3-100
TCP Connection Management (cont)
Closing a connection
client closes socketclientSocketclose()
Step 1 client end system sends TCP FIN control segment to server
Step 2 server receives FIN replies with ACK Closes connection sends FIN
client
FIN
server
ACK
ACK
FIN
close
close
closed
tim
ed w
ait
Transport Layer 3-101
TCP Connection Management (cont)
Step 3 client receives FIN replies with ACK
Enters ldquotimed waitrdquo -will respond with ACK to received FINs
Step 4 server receives ACK Connection closed
client
FIN
server
ACK
ACK
FIN
closing
closing
closed
tim
ed w
ait
closed
Transport Layer 3-102
TCP Connection Management (cont)
TCP clientlifecycle
TCP serverlifecycle
Transport Layer 3-103
Tuning TCPIP Parameters TCPIP parameters
A set of default values may not be optimal for all applicationsThe network administrator may wish to turn on or off some TCPIP functions for performance or security considerations
Many Unix and Linux systems provide some flexibility in tuning the TCPIP kernelsbinsysctl is used to configure the Linux kernel parameters at runtime
Default kernel configuration file is sbinsysctlconfFrequently used sysctl options
bull sysctl ndasha or sysctl ndashA list all current valuesbull sysctl ndashp file_name load the sysctl setting from a configuration
filebull sysctl ndashw variable=value change the value of the parameter
Transport Layer 3-104
SomeTCP Parameters in Linux Kerneltcp_syn_retries
Number of SYN packets the kernel will send before giving up on the new connection
tcp_synack_retriesnumber of SYN+ACK packets sent before the kernel gives up on the connection
tcp_window_scalingMaximum window size of 65535 bytes not enough for for really fast networks The window scaling options allows for almost gigabyte windows which is good for connections with large delay-bandwidth product
tcp_max_syn_backlogMaximal number of remembered connection requests which still did not receive an acknowledgment from connecting client
tcp_fin_timeoutHow many seconds to wait for a final FIN packet before the socket is closed required to prevent denial-of-service (DoS) attacks Default value is 60 seconds
Transport Layer 3-105
SomeTCP Parameters in Linux Kerneltcp_rmem
This is a vector of 3 integers [min default max] These parameters are used by TCP to dynamically adjust receive buffer sizesmin - minimum size of the receive buffer used by each TCP socket The default value is 4K default - the default size of the receive buffer for a TCP socket The default value is 87380 bytes and is lowered to 43689 in low memory systems If larger receive buffer sizes are desired this value should be increased max - the maximum size of the receive buffer used by each TCP socket The default value of 873802 bytes is lowered to 87380 in low memory systems
tcp_smemSend buffer parameters [min default max] similar to tcp_rmem
- Chapter 3 Transport Layer
- Transport services and protocols
- Transport vs network layer
- Internet transport-layer protocols
- Multiplexingdemultiplexing
- How demultiplexing works
- Connectionless demultiplexing
- Connection-oriented demux
- Connection-oriented demux (cont)
- Connection-oriented demux Threaded Web Server
- UDP User Datagram Protocol [RFC 768]
- UDP more
- UDP checksum
- Principles of Reliable data transfer
- Reliable data transfer getting started
- Reliable data transfer getting started
- Rdt10 reliable transfer over a reliable channel
- Rdt20 channel with bit errors
- rdt20 FSM specification
- rdt20 operation with no errors
- rdt20 error scenario
- rdt20 has a fatal flaw
- rdt21 sender handles garbled ACKNAKs
- rdt21 receiver handles garbled ACKNAKs
- rdt21 discussion
- rdt22 a NAK-free protocol
- rdt22 sender receiver fragments
- rdt30 channels with errors and loss
- rdt30 sender
- rdt30 in action
- rdt30 in action
- Performance of rdt30
- rdt30 stop-and-wait operation
- Pipelined protocols
- Pipelining increased utilization
- Go-Back-N
- GBN sender extended FSM
- GBN receiver extended FSM
- GBN inaction
- Selective Repeat
- Selective repeat sender receiver windows
- Selective repeat
- Selective repeat in action
- Selective repeat dilemma
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- TCP Overview RFCs 793 1122 1323 2018 2581
- TCP segment structure
- TCP seq rsquos and ACKs
- TCP Round Trip Time and Timeout
- TCP Round Trip Time and Timeout
- Example RTT estimation
- TCP Round Trip Time and Timeout
- TCP reliable data transfer
- TCP sender events
- TCP sender(simplified)
- TCP retransmission scenarios
- TCP retransmission scenarios (more)
- TCP ACK generation [RFC 1122 RFC 2581]
- Fast Retransmit
- Fast Retransmit
- Fast retransmit algorithm
- TCP Flow Control
- TCP Flow control how it works
- Sliding Window Flow Control Example
- Principles of Congestion Control
- Causescosts of congestion scenario 1
- Causescosts of congestion scenario 2
- Causescosts of congestion scenario 2
- Causescosts of congestion scenario 3
- Causescosts of congestion scenario 3
- Approaches towards congestion control
- TCP Congestion Control
- TCP congestion control bandwidth probing
- TCP Congestion Control details
- TCP Congestion Control more details
- TCP Slow Start Phase
- Slow Start Example
- TCP Congestion Avoidance Phase
- Congestion Avoidance
- Example Slow StartCongestion Avoidance
- Slow Start Congestion Avoidance
- Responses to Congestion
- Fast Recovery (differentiation btwn two loss events)
- TCP Congestion Control
- Popular ldquoflavorsrdquo of TCP
- Summary TCP Congestion Control
- TCP Congestion Control Summary
- TCP throughput
- TCP Futures TCP over ldquolong fat pipesrdquo
- TCP Fairness
- Why is TCP fair
- Fairness (more)
- TCP Connection Management
- TCP Connection Management (cont)
- TCP Connection Management (cont)
- TCP Connection Management (cont)
- Tuning TCPIP Parameters
- SomeTCP Parameters in Linux Kernel
- SomeTCP Parameters in Linux Kernel
-
Transport Layer 3-56
TCP Round Trip Time and Timeout
EstimatedRTT = (1- α)EstimatedRTT + αSampleRTT
Exponential weighted moving averageinfluence of past sample decreases exponentially fasttypical value α = 0125
Transport Layer 3-57
Example RTT estimationRTT gaiacsumassedu to fantasiaeurecomfr
100
150
200
250
300
350
1 8 15 22 29 36 43 50 57 64 71 78 85 92 99 106
time (seconnds)
RTT
(mill
iseco
nds)
SampleRTT Estimated RTT
Transport Layer 3-58
TCP Round Trip Time and TimeoutSetting the timeout
EstimatedRTT plus ldquosafety marginrdquolarge variation in EstimatedRTT -gt larger safety margin
first estimate of how much SampleRTT deviates from EstimatedRTT
TimeoutInterval = EstimatedRTT + 4DevRTT
DevRTT = (1-β)DevRTT +β|SampleRTT-EstimatedRTT|
(typically β = 025)
Then set timeout interval
Transport Layer 3-59
TCP reliable data transfer
TCP creates rdtservice on top of IPrsquos unreliable servicePipelined segmentsCumulative acksTCP uses single retransmission timer however it just retransmits the first segment in the window
Retransmissions are triggered by
timeout eventsduplicate acks
Initially consider simplified TCP sender
ignore duplicate acksignore flow control congestion control
Transport Layer 3-60
TCP sender eventsdata rcvd from app
Create segment with seq seq is byte-stream number of first data byte in segmentstart timer if not already running (think of timer as for oldest unacked segment)expiration interval TimeOutInterval
timeoutretransmit segment that caused timeout (first segment in the window)restart timer
Ack rcvdIf acknowledges previously unacked segments
update what is known to be ackedstart timer if there are outstanding segments
Transport Layer 3-61
TCP sender(simplified)
NextSeqNum = InitialSeqNumSendBase = InitialSeqNum
loop (forever) switch(event)
event data received from application above create TCP segment with sequence number NextSeqNumif (timer currently not running)
start timerpass segment to IP NextSeqNum = NextSeqNum + length(data)
event timer timeoutretransmit not-yet-acknowledged segment with
smallest sequence numberstart timer
event ACK received with ACK field value of y if (y gt SendBase)
SendBase = yif (there are currently not-yet-acknowledged segments)
start timer
end of loop forever
Commentbull SendBase-1 last cumulatively ackrsquoed byteExamplebull SendBase-1 = 71y= 73 so the rcvrwants 73+ y gt SendBase sothat new data is acked
Transport Layer 3-62
TCP retransmission scenariosHost A
Seq=100 20 bytes data
ACK=100
timepremature timeout
Host B
Seq=92 8 bytes data
ACK=120
Seq=92 8 bytes data
Seq=
92 t
imeo
ut
ACK=120
Host A
Seq=92 8 bytes data
ACK=100
loss
tim
eout
lost ACK scenario
Host B
X
Seq=92 8 bytes data
ACK=100
time
Seq=
92 t
imeo
utSendBase
= 100
SendBase= 120
SendBase= 120
Sendbase= 100
Transport Layer 3-63
TCP retransmission scenarios (more)Host A
Seq=92 8 bytes data
ACK=100
loss
tim
eout
Cumulative ACK scenario
Host B
X
Seq=100 20 bytes data
ACK=120
time
SendBase= 120
Transport Layer 3-64
TCP ACK generation [RFC 1122 RFC 2581]
Event at Receiver
Arrival of in-order segment withexpected seq All data up toexpected seq already ACKed
Arrival of in-order segment withexpected seq One other segment has ACK pending
Arrival of out-of-order segmenthigher-than-expect seq Gap detected
Arrival of segment that partially or completely fills gap
TCP Receiver action
Delayed ACK Wait up to 500msfor next segment If no next segmentsend ACK
Immediately send single cumulative ACK ACKing both in-order segments
Immediately send duplicate ACK indicating seq of next expected byte
Immediate send ACK provided thatsegment startsat lower end of gap
Transport Layer 3-65
Fast Retransmit
Time-out period often relatively long
long delay before resending lost packet
Detect lost segments via duplicate ACKs
Sender often sends many segments back-to-backIf segment is lost there will likely be many duplicate ACKs
If sender receives 3 ACKs for the same data it supposes that segment after ACKeddata was lost
fast retransmit resend segment before timer expires
Transport Layer 3-66
Fast RetransmitResend a segment after 3 duplicate ACKs since a duplicate ACK means that an out-of sequence segment was receivedduplicate ACKs due to packet reorderingif window is small donrsquot get duplicate ACKs
Host A
tim
eout
Host B
time
X
resend seq X2
seq x1seq x2seq x3seq x4seq x5
ACK x1
ACK x1ACK x1ACK x1
tripleduplicate
ACKs
Transport Layer 3-67
event ACK received with ACK field value of y if (y gt SendBase)
SendBase = yif (there are currently not-yet-acknowledged segments)
start timer
else increment count of dup ACKs received for yif (count of dup ACKs received for y = 3)
resend segment with sequence number y
Fast retransmit algorithm
a duplicate ACK for already ACKed segment
fast retransmit
Transport Layer 3-68
TCP Flow Control
receive side of TCP connection has a receive buffer
speed-matching service matching the send rate to the receiving apprsquos drain rate
app process may be slow at reading from buffer
sender wonrsquot overflowreceiverrsquos buffer by
transmitting too muchtoo fast
flow control
Transport Layer 3-69
TCP Flow control how it works
(Suppose TCP receiver discards out-of-order segments)spare room in buffer
= RcvWin
= RcvBuffer-[LastByteRcvd -LastByteRead]
Rcvr advertises spare room by including value of RcvWin in segmentsSender limits unACKeddata to RcvWin
guarantees receive buffer doesnrsquot overflow
Transport Layer 3-70
Sliding Window Flow Control Example
3K
2K SeqNo=0
ReceiverBuffer
0 4KSendersends 2Kof data
2K
AckNo=2048 RcvWin=2048Sendersends 2Kof data 2K SeqNo=2048
4K
AckNo=4096 RcvWin=0
AckNo=4096 RcvWin=1024
Sender blocked
Transport Layer 3-71
Principles of Congestion Control
Congestioninformally ldquotoo many sources sending too much data too fast for network to handlerdquodifferent from flow controlmanifestations
lost packets (buffer overflow at routers)long delays (queueing in router buffers)
a top-10 problem
Transport Layer 3-72
Causescosts of congestion scenario 1
two senders two receiversone router infinite buffers no retransmission
large delays when congestedmaximum achievable throughput
unlimited shared output link buffers
Host Aλin original data
Host B
λout
Transport Layer 3-73
Causescosts of congestion scenario 2
one router finite buffers sender retransmission of lost packet
finite shared output link buffers
Host A λin original data
Host B
λout
λin original data plus retransmitted data
Transport Layer 3-74
Causescosts of congestion scenario 2always (goodput)ldquoperfectrdquo retransmission only when loss
retransmission of delayed (not lost) packet makes larger(than perfect case) for same
λin
λout=
λin
λoutgtλ
inλout
ldquocostsrdquo of congestionmore work (retrans) for given ldquogoodputrdquounneeded retransmissions link carries multiple copies of pkt
R2
R2λin
λ out
b
R2
R2λin
λ out
a
R2
R2λin
λ out
c
R4
R3
Transport Layer 3-75
Causescosts of congestion scenario 3four sendersmultihop pathstimeoutretransmit
λin
Q what happens as and increase λ
in
finite shared output link buffers
Host Aλin original data
Host B
λout
λin original data plus retransmitted data
Transport Layer 3-76
Causescosts of congestion scenario 3
another ldquocostrdquo of congestionwhen packet dropped any ldquoupstream transmission capacity used for that packet was wasted
Host A
Host B
λou
t
Transport Layer 3-77
Approaches towards congestion control
End-end congestion controlno explicit feedback from networkcongestion inferred from end-system observed loss delayapproach taken by TCP
Network-assisted congestion controlrouters provide feedback to end systems
single bit indicating congestion (SNA DECbit TCPIP ECN ATM)explicit rate sender should send at
Two broad approaches towards congestion control
Transport Layer 3-78
TCP Congestion Control
end-end control (no network assistance)sender limits transmissionLastByteSent-LastByteAcked
le CongWin
CongWin is dynamic function of perceived network congestion
How does sender perceive congestionloss event = timeout or3 duplicate acksTCP sender reduces rate (CongWin) after loss event
two modes of operationSlow Start (SS)Congestion avoidance (CA) or Additive Increase Multiplicative Decrease (AIMD)
Transport Layer 3-79
TCP congestion control bandwidth probing
ldquoprobing for bandwidthrdquo increase transmission rate on receipt of ACK until eventually loss occurs then decrease transmission rate
continue to increase on ACK decrease on loss (since available bandwidth is changing depending on other connections in network)
ACKs being received so increase rate
X
X
XX
X loss so decrease rate
send
ing
rate
time
Q how fast to increasedecreasedetails to follow
TCPrsquosldquosawtoothrdquobehavior
Transport Layer 3-80
TCP Congestion Control details
sender limits rate by limiting number of unACKed bytes ldquoin pipelinerdquo
cwnd differs from rwnd (how why)sender limited by min(cwndrwnd)
roughly
cwnd is dynamic function of perceived network congestion
rate = cwndRTT bytessec
LastByteSent-LastByteAcked le cwnd
cwndbytes
RTT
ACK(s)
Transport Layer 3-81
TCP Congestion Control more details
segment loss event reducing cwndtimeout no response from receiver
cut cwnd to 13 duplicate ACKs at least some segments getting through (recall fast retransmit)
cut cwnd in half less aggressively than on timeout
ACK received increase cwndTwo modes of operation
slowstart phase bull increase exponentially
fast (despite name) at connection start or following timeout
congestion avoidance bull increase linearly
Transport Layer 3-82
TCP Slow Start Phasewhen connection begins cwnd = 1 MSS
example MSS = 500 bytes amp RTT = 200 msecinitial rate = 20 kbps
available bandwidth may be gtgt MSSRTT
desirable to quickly ramp up to respectable rate
increase rate exponentially until first loss event or when threshold reached
double cwnd every RTTdone by incrementing cwnd by 1 for every ACK received
Host A
one segment
RTT
Host B
time
two segments
four segments
Transport Layer 3-83
Slow Start ExampleThe congestion window size grows very rapidly
For every ACK we increase CongWin by 1 irrespective of the number of segments ACKrsquoeddouble CongWinevery RTTinitial rate is slow but ramps up exponentially fast
TCP slows down the increase of CongWinwhen CongWin gt ssthresh
segment 1
ACK for segment 1
cwnd = 1
cwnd = 2 segment 2segment 3
ACK for segments 2
cwnd = 4 segment 4segment 5segment 6
ACK for segments 4
cwnd = 7
ACK for segments 3
ACK for segments 5
ACK for segments 6
cwnd = 3
cwnd = 5
cwnd = 6ACK for segments 7
cwnd = 8
segment 7
Transport Layer 3-84
TCP Congestion Avoidance Phase
when cwnd gt ssthreshgrow cwnd linearly
increase cwnd by 1 MSS per RTT approach possible congestion slower than in slowstartimplementation cwnd= cwnd + MSScwndfor each ACK received
ACKs increase cwndby 1 MSS per RTT additive increaseloss cut cwnd in half (non-timeout-detected loss ) multiplicative decrease
AIMD
AIMD Additive IncreaseMultiplicative Decrease
Transport Layer 3-85
Congestion AvoidanceCongestion avoidance phase is started if CongWin has reached the slow-start threshold value
If CongWin gt= ssthresh then each time an ACK is received increment CongWin as follows
bull CongWin = CongWin + 1CongWin (CongWin in segments)
bull In actual TCP implementation CongWin is in BytesCongWin = CongWin + MSS (MSSCongWin)
So CongWin is increased by one only if all CongWinsegments have been acknowledged
Transport Layer 3-86
Example Slow StartCongestion AvoidanceAssume that
ssthresh = 8
cwnd = 1
cwnd = 2
cwnd = 4
cwnd = 8
cwnd = 9
cwnd = 10
02468
101214
t=0
t=2
t=4
t=6
Roundtrip times
Cw
nd(in
seg
men
ts)
ssthresh
cwnd = 3
cwnd = 5cwnd = 6cwnd = 7
Transport Layer 3-87
Slow Start Congestion AvoidanceA typical plot of CongWin for a TCP connection
(MSS = 1500 bytes) with TCP Tahoe
SS
CA
ssthresh
Transport Layer 3-88
Responses to CongestionTCP assumes there is congestion if it detects a packet lossA TCP sender can detect lost packets via loss events
bull Timeout of a retransmission timerbull Receipt of 3 duplicate ACKs (fast retransmit)
TCP interprets a Timeout as a binary congestion signal When a timeout occurs the sender performs
ssthresh is set to half the current size of the congestion window
ssthresh = CongWin 2CongWin is reset to one
CongWin = 1and slow-start is entered
Transport Layer 3-89
Fast Recovery (differentiation btwn two loss events) After 3 dup ACKs (fast Retransmit)
ssthresh = CongWin2CongWin = CongWin2window then grows linearly
But after timeout eventCongWin = 1 MSS window then grows exponentiallyto the threshold then grows linearly
bull 3 dup ACKs indicates network capable of delivering some segmentsbull timeout before 3 dup ACKs is ldquomore alarmingrdquo
Philosophy
3-90
TCP Congestion ControlInitially
CongWin = 1ssthresh = advertised window size
New Ack receivedif (CongWin lt ssthresh) Slow Start
CongWin = CongWin + 1else Congestion Avoidance
CongWin = CongWin + 1CongWinTimeout
ssthresh = CongWin2CongWin = 1
Fast Retransmissionssthresh = CongWin2CongWin = CongWin2
Slow Start (exponential increase phase) is continued until CongWin reaches half of the level where the loss event occurred last time CongWin is increased slowly after (linear increase in Congestion Avoidance phase)
Transport Layer 3-91
Popular ldquoflavorsrdquo of TCP
ssthresh
ssthresh
TCP Tahoe
TCP Reno
Transmission round
cwnd
win
dow
siz
e (in
seg
men
ts)
Transport Layer 3-92
Summary TCP Congestion ControlWhen CongWin is below Threshold sender in slow-start phase window grows exponentiallyWhen CongWin is above Threshold sender is in congestion-avoidance phase window grows linearlyWhen a triple duplicate ACK occurs Threshold set to CongWin2 and CongWin set to ThresholdWhen timeout occurs Threshold set to CongWin2 and CongWin is set to 1 MSS The actual sender window size is determined based on the congestion and flow control algorithms
SenderWin=min(RcvWinCongWin)
Transport Layer 3-93
TCP Congestion Control SummaryEvent State TCP Sender Action Commentary
ACK receipt for previously unackeddata
Slow Start (SS)
CongWin = CongWin + MSS If (CongWin gt Threshold)
set state to ldquoCongestion Avoidancerdquo
Resulting in a doubling of CongWin every RTT
ACK receipt for previously unackeddata
CongestionAvoidance (CA)
CongWin = CongWin+MSS (MSSCongWin)
Additive increase resulting in increase of CongWin by 1 MSS every RTT
Loss event detected by triple duplicate ACK
SS or CA Threshold = CongWin2 CongWin = ThresholdSet state to ldquoCongestion Avoidancerdquo
Fast recovery implementing multiplicative decrease CongWin will not drop below 1 MSS
Timeout SS or CA Threshold = CongWin2 CongWin = 1 MSSSet state to ldquoSlow Startrdquo
Enter slow start
Duplicate ACK
SS or CA Increment duplicate ACK count for segment being acked
CongWin and Threshold not changed
Transport Layer 3-94
TCP throughput
Q whatrsquos average throughout of TCP as function of window size RTT
ignoring slow startlet W be window size when loss occurs
when window is W throughput is WRTTjust after loss window drops to W2 throughput to W2RTT average throughout 75 WRTT
Transport Layer 3-95
TCP Futures TCP over ldquolong fat pipesrdquo
example 1500 byte segments 100ms RTT want 10 Gbps throughputrequires window size W = 83333 in-flight segmentsthroughput in terms of loss rate
L = 210-10 Wownew versions of TCP for high-speed
LRTTMSSsdot221
Transport Layer 3-96
Fairness goal if K TCP sessions share same bottleneck link of bandwidth R each should have average rate of RK
TCP connection 1
bottleneckrouter
capacity R
TCP connection 2
TCP Fairness
Transport Layer 3-97
Why is TCP fairTwo competing sessions
Additive increase gives slope of 1 as throughout increasesmultiplicative decrease decreases throughput proportionally
R
R
equal bandwidth share
Connection 1 throughput
Conn
ecti
on 2
thr
ough
p ut
congestion avoidance additive increaseloss decrease window by factor of 2
congestion avoidance additive increaseloss decrease window by factor of 2
Transport Layer 3-98
Fairness (more)Fairness and UDP
Multimedia apps often do not use TCP
do not want rate throttled by congestion control
Instead use UDPpump audiovideo at constant rate tolerate packet loss
Research area TCP friendly
Fairness and parallel TCP connectionsnothing prevents app from opening parallel cnctionsbetween 2 hostsWeb browsers do this Example link of rate R supporting 9 cnctions
new app asks for 1 TCP gets rate R10new app asks for 11 TCPs gets R2
Transport Layer 3-99
TCP Connection ManagementRecall TCP sender receiver
establish ldquoconnectionrdquobefore exchanging data segmentsinitialize TCP variables
seq sbuffers flow control info (eg RcvWindow)
client connection initiatorSocket clientSocket = new Socket(hostnameport
number)
server contacted by clientSocket connectionSocket = welcomeSocketaccept()
Three way handshakeStep 1 client host sends TCP
SYN segment to serverspecifies initial seq no data
Step 2 server host receives SYN replies with SYNACK segment
server allocates buffersspecifies server initial seq
Step 3 client receives SYNACK replies with ACK segment which may contain data
Transport Layer 3-100
TCP Connection Management (cont)
Closing a connection
client closes socketclientSocketclose()
Step 1 client end system sends TCP FIN control segment to server
Step 2 server receives FIN replies with ACK Closes connection sends FIN
client
FIN
server
ACK
ACK
FIN
close
close
closed
tim
ed w
ait
Transport Layer 3-101
TCP Connection Management (cont)
Step 3 client receives FIN replies with ACK
Enters ldquotimed waitrdquo -will respond with ACK to received FINs
Step 4 server receives ACK Connection closed
client
FIN
server
ACK
ACK
FIN
closing
closing
closed
tim
ed w
ait
closed
Transport Layer 3-102
TCP Connection Management (cont)
TCP clientlifecycle
TCP serverlifecycle
Transport Layer 3-103
Tuning TCPIP Parameters TCPIP parameters
A set of default values may not be optimal for all applicationsThe network administrator may wish to turn on or off some TCPIP functions for performance or security considerations
Many Unix and Linux systems provide some flexibility in tuning the TCPIP kernelsbinsysctl is used to configure the Linux kernel parameters at runtime
Default kernel configuration file is sbinsysctlconfFrequently used sysctl options
bull sysctl ndasha or sysctl ndashA list all current valuesbull sysctl ndashp file_name load the sysctl setting from a configuration
filebull sysctl ndashw variable=value change the value of the parameter
Transport Layer 3-104
SomeTCP Parameters in Linux Kerneltcp_syn_retries
Number of SYN packets the kernel will send before giving up on the new connection
tcp_synack_retriesnumber of SYN+ACK packets sent before the kernel gives up on the connection
tcp_window_scalingMaximum window size of 65535 bytes not enough for for really fast networks The window scaling options allows for almost gigabyte windows which is good for connections with large delay-bandwidth product
tcp_max_syn_backlogMaximal number of remembered connection requests which still did not receive an acknowledgment from connecting client
tcp_fin_timeoutHow many seconds to wait for a final FIN packet before the socket is closed required to prevent denial-of-service (DoS) attacks Default value is 60 seconds
Transport Layer 3-105
SomeTCP Parameters in Linux Kerneltcp_rmem
This is a vector of 3 integers [min default max] These parameters are used by TCP to dynamically adjust receive buffer sizesmin - minimum size of the receive buffer used by each TCP socket The default value is 4K default - the default size of the receive buffer for a TCP socket The default value is 87380 bytes and is lowered to 43689 in low memory systems If larger receive buffer sizes are desired this value should be increased max - the maximum size of the receive buffer used by each TCP socket The default value of 873802 bytes is lowered to 87380 in low memory systems
tcp_smemSend buffer parameters [min default max] similar to tcp_rmem
- Chapter 3 Transport Layer
- Transport services and protocols
- Transport vs network layer
- Internet transport-layer protocols
- Multiplexingdemultiplexing
- How demultiplexing works
- Connectionless demultiplexing
- Connection-oriented demux
- Connection-oriented demux (cont)
- Connection-oriented demux Threaded Web Server
- UDP User Datagram Protocol [RFC 768]
- UDP more
- UDP checksum
- Principles of Reliable data transfer
- Reliable data transfer getting started
- Reliable data transfer getting started
- Rdt10 reliable transfer over a reliable channel
- Rdt20 channel with bit errors
- rdt20 FSM specification
- rdt20 operation with no errors
- rdt20 error scenario
- rdt20 has a fatal flaw
- rdt21 sender handles garbled ACKNAKs
- rdt21 receiver handles garbled ACKNAKs
- rdt21 discussion
- rdt22 a NAK-free protocol
- rdt22 sender receiver fragments
- rdt30 channels with errors and loss
- rdt30 sender
- rdt30 in action
- rdt30 in action
- Performance of rdt30
- rdt30 stop-and-wait operation
- Pipelined protocols
- Pipelining increased utilization
- Go-Back-N
- GBN sender extended FSM
- GBN receiver extended FSM
- GBN inaction
- Selective Repeat
- Selective repeat sender receiver windows
- Selective repeat
- Selective repeat in action
- Selective repeat dilemma
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- TCP Overview RFCs 793 1122 1323 2018 2581
- TCP segment structure
- TCP seq rsquos and ACKs
- TCP Round Trip Time and Timeout
- TCP Round Trip Time and Timeout
- Example RTT estimation
- TCP Round Trip Time and Timeout
- TCP reliable data transfer
- TCP sender events
- TCP sender(simplified)
- TCP retransmission scenarios
- TCP retransmission scenarios (more)
- TCP ACK generation [RFC 1122 RFC 2581]
- Fast Retransmit
- Fast Retransmit
- Fast retransmit algorithm
- TCP Flow Control
- TCP Flow control how it works
- Sliding Window Flow Control Example
- Principles of Congestion Control
- Causescosts of congestion scenario 1
- Causescosts of congestion scenario 2
- Causescosts of congestion scenario 2
- Causescosts of congestion scenario 3
- Causescosts of congestion scenario 3
- Approaches towards congestion control
- TCP Congestion Control
- TCP congestion control bandwidth probing
- TCP Congestion Control details
- TCP Congestion Control more details
- TCP Slow Start Phase
- Slow Start Example
- TCP Congestion Avoidance Phase
- Congestion Avoidance
- Example Slow StartCongestion Avoidance
- Slow Start Congestion Avoidance
- Responses to Congestion
- Fast Recovery (differentiation btwn two loss events)
- TCP Congestion Control
- Popular ldquoflavorsrdquo of TCP
- Summary TCP Congestion Control
- TCP Congestion Control Summary
- TCP throughput
- TCP Futures TCP over ldquolong fat pipesrdquo
- TCP Fairness
- Why is TCP fair
- Fairness (more)
- TCP Connection Management
- TCP Connection Management (cont)
- TCP Connection Management (cont)
- TCP Connection Management (cont)
- Tuning TCPIP Parameters
- SomeTCP Parameters in Linux Kernel
- SomeTCP Parameters in Linux Kernel
-
Transport Layer 3-57
Example RTT estimationRTT gaiacsumassedu to fantasiaeurecomfr
100
150
200
250
300
350
1 8 15 22 29 36 43 50 57 64 71 78 85 92 99 106
time (seconnds)
RTT
(mill
iseco
nds)
SampleRTT Estimated RTT
Transport Layer 3-58
TCP Round Trip Time and TimeoutSetting the timeout
EstimatedRTT plus ldquosafety marginrdquolarge variation in EstimatedRTT -gt larger safety margin
first estimate of how much SampleRTT deviates from EstimatedRTT
TimeoutInterval = EstimatedRTT + 4DevRTT
DevRTT = (1-β)DevRTT +β|SampleRTT-EstimatedRTT|
(typically β = 025)
Then set timeout interval
Transport Layer 3-59
TCP reliable data transfer
TCP creates rdtservice on top of IPrsquos unreliable servicePipelined segmentsCumulative acksTCP uses single retransmission timer however it just retransmits the first segment in the window
Retransmissions are triggered by
timeout eventsduplicate acks
Initially consider simplified TCP sender
ignore duplicate acksignore flow control congestion control
Transport Layer 3-60
TCP sender eventsdata rcvd from app
Create segment with seq seq is byte-stream number of first data byte in segmentstart timer if not already running (think of timer as for oldest unacked segment)expiration interval TimeOutInterval
timeoutretransmit segment that caused timeout (first segment in the window)restart timer
Ack rcvdIf acknowledges previously unacked segments
update what is known to be ackedstart timer if there are outstanding segments
Transport Layer 3-61
TCP sender(simplified)
NextSeqNum = InitialSeqNumSendBase = InitialSeqNum
loop (forever) switch(event)
event data received from application above create TCP segment with sequence number NextSeqNumif (timer currently not running)
start timerpass segment to IP NextSeqNum = NextSeqNum + length(data)
event timer timeoutretransmit not-yet-acknowledged segment with
smallest sequence numberstart timer
event ACK received with ACK field value of y if (y gt SendBase)
SendBase = yif (there are currently not-yet-acknowledged segments)
start timer
end of loop forever
Commentbull SendBase-1 last cumulatively ackrsquoed byteExamplebull SendBase-1 = 71y= 73 so the rcvrwants 73+ y gt SendBase sothat new data is acked
Transport Layer 3-62
TCP retransmission scenariosHost A
Seq=100 20 bytes data
ACK=100
timepremature timeout
Host B
Seq=92 8 bytes data
ACK=120
Seq=92 8 bytes data
Seq=
92 t
imeo
ut
ACK=120
Host A
Seq=92 8 bytes data
ACK=100
loss
tim
eout
lost ACK scenario
Host B
X
Seq=92 8 bytes data
ACK=100
time
Seq=
92 t
imeo
utSendBase
= 100
SendBase= 120
SendBase= 120
Sendbase= 100
Transport Layer 3-63
TCP retransmission scenarios (more)Host A
Seq=92 8 bytes data
ACK=100
loss
tim
eout
Cumulative ACK scenario
Host B
X
Seq=100 20 bytes data
ACK=120
time
SendBase= 120
Transport Layer 3-64
TCP ACK generation [RFC 1122 RFC 2581]
Event at Receiver
Arrival of in-order segment withexpected seq All data up toexpected seq already ACKed
Arrival of in-order segment withexpected seq One other segment has ACK pending
Arrival of out-of-order segmenthigher-than-expect seq Gap detected
Arrival of segment that partially or completely fills gap
TCP Receiver action
Delayed ACK Wait up to 500msfor next segment If no next segmentsend ACK
Immediately send single cumulative ACK ACKing both in-order segments
Immediately send duplicate ACK indicating seq of next expected byte
Immediate send ACK provided thatsegment startsat lower end of gap
Transport Layer 3-65
Fast Retransmit
Time-out period often relatively long
long delay before resending lost packet
Detect lost segments via duplicate ACKs
Sender often sends many segments back-to-backIf segment is lost there will likely be many duplicate ACKs
If sender receives 3 ACKs for the same data it supposes that segment after ACKeddata was lost
fast retransmit resend segment before timer expires
Transport Layer 3-66
Fast RetransmitResend a segment after 3 duplicate ACKs since a duplicate ACK means that an out-of sequence segment was receivedduplicate ACKs due to packet reorderingif window is small donrsquot get duplicate ACKs
Host A
tim
eout
Host B
time
X
resend seq X2
seq x1seq x2seq x3seq x4seq x5
ACK x1
ACK x1ACK x1ACK x1
tripleduplicate
ACKs
Transport Layer 3-67
event ACK received with ACK field value of y if (y gt SendBase)
SendBase = yif (there are currently not-yet-acknowledged segments)
start timer
else increment count of dup ACKs received for yif (count of dup ACKs received for y = 3)
resend segment with sequence number y
Fast retransmit algorithm
a duplicate ACK for already ACKed segment
fast retransmit
Transport Layer 3-68
TCP Flow Control
receive side of TCP connection has a receive buffer
speed-matching service matching the send rate to the receiving apprsquos drain rate
app process may be slow at reading from buffer
sender wonrsquot overflowreceiverrsquos buffer by
transmitting too muchtoo fast
flow control
Transport Layer 3-69
TCP Flow control how it works
(Suppose TCP receiver discards out-of-order segments)spare room in buffer
= RcvWin
= RcvBuffer-[LastByteRcvd -LastByteRead]
Rcvr advertises spare room by including value of RcvWin in segmentsSender limits unACKeddata to RcvWin
guarantees receive buffer doesnrsquot overflow
Transport Layer 3-70
Sliding Window Flow Control Example
3K
2K SeqNo=0
ReceiverBuffer
0 4KSendersends 2Kof data
2K
AckNo=2048 RcvWin=2048Sendersends 2Kof data 2K SeqNo=2048
4K
AckNo=4096 RcvWin=0
AckNo=4096 RcvWin=1024
Sender blocked
Transport Layer 3-71
Principles of Congestion Control
Congestioninformally ldquotoo many sources sending too much data too fast for network to handlerdquodifferent from flow controlmanifestations
lost packets (buffer overflow at routers)long delays (queueing in router buffers)
a top-10 problem
Transport Layer 3-72
Causescosts of congestion scenario 1
two senders two receiversone router infinite buffers no retransmission
large delays when congestedmaximum achievable throughput
unlimited shared output link buffers
Host Aλin original data
Host B
λout
Transport Layer 3-73
Causescosts of congestion scenario 2
one router finite buffers sender retransmission of lost packet
finite shared output link buffers
Host A λin original data
Host B
λout
λin original data plus retransmitted data
Transport Layer 3-74
Causescosts of congestion scenario 2always (goodput)ldquoperfectrdquo retransmission only when loss
retransmission of delayed (not lost) packet makes larger(than perfect case) for same
λin
λout=
λin
λoutgtλ
inλout
ldquocostsrdquo of congestionmore work (retrans) for given ldquogoodputrdquounneeded retransmissions link carries multiple copies of pkt
R2
R2λin
λ out
b
R2
R2λin
λ out
a
R2
R2λin
λ out
c
R4
R3
Transport Layer 3-75
Causescosts of congestion scenario 3four sendersmultihop pathstimeoutretransmit
λin
Q what happens as and increase λ
in
finite shared output link buffers
Host Aλin original data
Host B
λout
λin original data plus retransmitted data
Transport Layer 3-76
Causescosts of congestion scenario 3
another ldquocostrdquo of congestionwhen packet dropped any ldquoupstream transmission capacity used for that packet was wasted
Host A
Host B
λou
t
Transport Layer 3-77
Approaches towards congestion control
End-end congestion controlno explicit feedback from networkcongestion inferred from end-system observed loss delayapproach taken by TCP
Network-assisted congestion controlrouters provide feedback to end systems
single bit indicating congestion (SNA DECbit TCPIP ECN ATM)explicit rate sender should send at
Two broad approaches towards congestion control
Transport Layer 3-78
TCP Congestion Control
end-end control (no network assistance)sender limits transmissionLastByteSent-LastByteAcked
le CongWin
CongWin is dynamic function of perceived network congestion
How does sender perceive congestionloss event = timeout or3 duplicate acksTCP sender reduces rate (CongWin) after loss event
two modes of operationSlow Start (SS)Congestion avoidance (CA) or Additive Increase Multiplicative Decrease (AIMD)
Transport Layer 3-79
TCP congestion control bandwidth probing
ldquoprobing for bandwidthrdquo increase transmission rate on receipt of ACK until eventually loss occurs then decrease transmission rate
continue to increase on ACK decrease on loss (since available bandwidth is changing depending on other connections in network)
ACKs being received so increase rate
X
X
XX
X loss so decrease rate
send
ing
rate
time
Q how fast to increasedecreasedetails to follow
TCPrsquosldquosawtoothrdquobehavior
Transport Layer 3-80
TCP Congestion Control details
sender limits rate by limiting number of unACKed bytes ldquoin pipelinerdquo
cwnd differs from rwnd (how why)sender limited by min(cwndrwnd)
roughly
cwnd is dynamic function of perceived network congestion
rate = cwndRTT bytessec
LastByteSent-LastByteAcked le cwnd
cwndbytes
RTT
ACK(s)
Transport Layer 3-81
TCP Congestion Control more details
segment loss event reducing cwndtimeout no response from receiver
cut cwnd to 13 duplicate ACKs at least some segments getting through (recall fast retransmit)
cut cwnd in half less aggressively than on timeout
ACK received increase cwndTwo modes of operation
slowstart phase bull increase exponentially
fast (despite name) at connection start or following timeout
congestion avoidance bull increase linearly
Transport Layer 3-82
TCP Slow Start Phasewhen connection begins cwnd = 1 MSS
example MSS = 500 bytes amp RTT = 200 msecinitial rate = 20 kbps
available bandwidth may be gtgt MSSRTT
desirable to quickly ramp up to respectable rate
increase rate exponentially until first loss event or when threshold reached
double cwnd every RTTdone by incrementing cwnd by 1 for every ACK received
Host A
one segment
RTT
Host B
time
two segments
four segments
Transport Layer 3-83
Slow Start ExampleThe congestion window size grows very rapidly
For every ACK we increase CongWin by 1 irrespective of the number of segments ACKrsquoeddouble CongWinevery RTTinitial rate is slow but ramps up exponentially fast
TCP slows down the increase of CongWinwhen CongWin gt ssthresh
segment 1
ACK for segment 1
cwnd = 1
cwnd = 2 segment 2segment 3
ACK for segments 2
cwnd = 4 segment 4segment 5segment 6
ACK for segments 4
cwnd = 7
ACK for segments 3
ACK for segments 5
ACK for segments 6
cwnd = 3
cwnd = 5
cwnd = 6ACK for segments 7
cwnd = 8
segment 7
Transport Layer 3-84
TCP Congestion Avoidance Phase
when cwnd gt ssthreshgrow cwnd linearly
increase cwnd by 1 MSS per RTT approach possible congestion slower than in slowstartimplementation cwnd= cwnd + MSScwndfor each ACK received
ACKs increase cwndby 1 MSS per RTT additive increaseloss cut cwnd in half (non-timeout-detected loss ) multiplicative decrease
AIMD
AIMD Additive IncreaseMultiplicative Decrease
Transport Layer 3-85
Congestion AvoidanceCongestion avoidance phase is started if CongWin has reached the slow-start threshold value
If CongWin gt= ssthresh then each time an ACK is received increment CongWin as follows
bull CongWin = CongWin + 1CongWin (CongWin in segments)
bull In actual TCP implementation CongWin is in BytesCongWin = CongWin + MSS (MSSCongWin)
So CongWin is increased by one only if all CongWinsegments have been acknowledged
Transport Layer 3-86
Example Slow StartCongestion AvoidanceAssume that
ssthresh = 8
cwnd = 1
cwnd = 2
cwnd = 4
cwnd = 8
cwnd = 9
cwnd = 10
02468
101214
t=0
t=2
t=4
t=6
Roundtrip times
Cw
nd(in
seg
men
ts)
ssthresh
cwnd = 3
cwnd = 5cwnd = 6cwnd = 7
Transport Layer 3-87
Slow Start Congestion AvoidanceA typical plot of CongWin for a TCP connection
(MSS = 1500 bytes) with TCP Tahoe
SS
CA
ssthresh
Transport Layer 3-88
Responses to CongestionTCP assumes there is congestion if it detects a packet lossA TCP sender can detect lost packets via loss events
bull Timeout of a retransmission timerbull Receipt of 3 duplicate ACKs (fast retransmit)
TCP interprets a Timeout as a binary congestion signal When a timeout occurs the sender performs
ssthresh is set to half the current size of the congestion window
ssthresh = CongWin 2CongWin is reset to one
CongWin = 1and slow-start is entered
Transport Layer 3-89
Fast Recovery (differentiation btwn two loss events) After 3 dup ACKs (fast Retransmit)
ssthresh = CongWin2CongWin = CongWin2window then grows linearly
But after timeout eventCongWin = 1 MSS window then grows exponentiallyto the threshold then grows linearly
bull 3 dup ACKs indicates network capable of delivering some segmentsbull timeout before 3 dup ACKs is ldquomore alarmingrdquo
Philosophy
3-90
TCP Congestion ControlInitially
CongWin = 1ssthresh = advertised window size
New Ack receivedif (CongWin lt ssthresh) Slow Start
CongWin = CongWin + 1else Congestion Avoidance
CongWin = CongWin + 1CongWinTimeout
ssthresh = CongWin2CongWin = 1
Fast Retransmissionssthresh = CongWin2CongWin = CongWin2
Slow Start (exponential increase phase) is continued until CongWin reaches half of the level where the loss event occurred last time CongWin is increased slowly after (linear increase in Congestion Avoidance phase)
Transport Layer 3-91
Popular ldquoflavorsrdquo of TCP
ssthresh
ssthresh
TCP Tahoe
TCP Reno
Transmission round
cwnd
win
dow
siz
e (in
seg
men
ts)
Transport Layer 3-92
Summary TCP Congestion ControlWhen CongWin is below Threshold sender in slow-start phase window grows exponentiallyWhen CongWin is above Threshold sender is in congestion-avoidance phase window grows linearlyWhen a triple duplicate ACK occurs Threshold set to CongWin2 and CongWin set to ThresholdWhen timeout occurs Threshold set to CongWin2 and CongWin is set to 1 MSS The actual sender window size is determined based on the congestion and flow control algorithms
SenderWin=min(RcvWinCongWin)
Transport Layer 3-93
TCP Congestion Control SummaryEvent State TCP Sender Action Commentary
ACK receipt for previously unackeddata
Slow Start (SS)
CongWin = CongWin + MSS If (CongWin gt Threshold)
set state to ldquoCongestion Avoidancerdquo
Resulting in a doubling of CongWin every RTT
ACK receipt for previously unackeddata
CongestionAvoidance (CA)
CongWin = CongWin+MSS (MSSCongWin)
Additive increase resulting in increase of CongWin by 1 MSS every RTT
Loss event detected by triple duplicate ACK
SS or CA Threshold = CongWin2 CongWin = ThresholdSet state to ldquoCongestion Avoidancerdquo
Fast recovery implementing multiplicative decrease CongWin will not drop below 1 MSS
Timeout SS or CA Threshold = CongWin2 CongWin = 1 MSSSet state to ldquoSlow Startrdquo
Enter slow start
Duplicate ACK
SS or CA Increment duplicate ACK count for segment being acked
CongWin and Threshold not changed
Transport Layer 3-94
TCP throughput
Q whatrsquos average throughout of TCP as function of window size RTT
ignoring slow startlet W be window size when loss occurs
when window is W throughput is WRTTjust after loss window drops to W2 throughput to W2RTT average throughout 75 WRTT
Transport Layer 3-95
TCP Futures TCP over ldquolong fat pipesrdquo
example 1500 byte segments 100ms RTT want 10 Gbps throughputrequires window size W = 83333 in-flight segmentsthroughput in terms of loss rate
L = 210-10 Wownew versions of TCP for high-speed
LRTTMSSsdot221
Transport Layer 3-96
Fairness goal if K TCP sessions share same bottleneck link of bandwidth R each should have average rate of RK
TCP connection 1
bottleneckrouter
capacity R
TCP connection 2
TCP Fairness
Transport Layer 3-97
Why is TCP fairTwo competing sessions
Additive increase gives slope of 1 as throughout increasesmultiplicative decrease decreases throughput proportionally
R
R
equal bandwidth share
Connection 1 throughput
Conn
ecti
on 2
thr
ough
p ut
congestion avoidance additive increaseloss decrease window by factor of 2
congestion avoidance additive increaseloss decrease window by factor of 2
Transport Layer 3-98
Fairness (more)Fairness and UDP
Multimedia apps often do not use TCP
do not want rate throttled by congestion control
Instead use UDPpump audiovideo at constant rate tolerate packet loss
Research area TCP friendly
Fairness and parallel TCP connectionsnothing prevents app from opening parallel cnctionsbetween 2 hostsWeb browsers do this Example link of rate R supporting 9 cnctions
new app asks for 1 TCP gets rate R10new app asks for 11 TCPs gets R2
Transport Layer 3-99
TCP Connection ManagementRecall TCP sender receiver
establish ldquoconnectionrdquobefore exchanging data segmentsinitialize TCP variables
seq sbuffers flow control info (eg RcvWindow)
client connection initiatorSocket clientSocket = new Socket(hostnameport
number)
server contacted by clientSocket connectionSocket = welcomeSocketaccept()
Three way handshakeStep 1 client host sends TCP
SYN segment to serverspecifies initial seq no data
Step 2 server host receives SYN replies with SYNACK segment
server allocates buffersspecifies server initial seq
Step 3 client receives SYNACK replies with ACK segment which may contain data
Transport Layer 3-100
TCP Connection Management (cont)
Closing a connection
client closes socketclientSocketclose()
Step 1 client end system sends TCP FIN control segment to server
Step 2 server receives FIN replies with ACK Closes connection sends FIN
client
FIN
server
ACK
ACK
FIN
close
close
closed
tim
ed w
ait
Transport Layer 3-101
TCP Connection Management (cont)
Step 3 client receives FIN replies with ACK
Enters ldquotimed waitrdquo -will respond with ACK to received FINs
Step 4 server receives ACK Connection closed
client
FIN
server
ACK
ACK
FIN
closing
closing
closed
tim
ed w
ait
closed
Transport Layer 3-102
TCP Connection Management (cont)
TCP clientlifecycle
TCP serverlifecycle
Transport Layer 3-103
Tuning TCPIP Parameters TCPIP parameters
A set of default values may not be optimal for all applicationsThe network administrator may wish to turn on or off some TCPIP functions for performance or security considerations
Many Unix and Linux systems provide some flexibility in tuning the TCPIP kernelsbinsysctl is used to configure the Linux kernel parameters at runtime
Default kernel configuration file is sbinsysctlconfFrequently used sysctl options
bull sysctl ndasha or sysctl ndashA list all current valuesbull sysctl ndashp file_name load the sysctl setting from a configuration
filebull sysctl ndashw variable=value change the value of the parameter
Transport Layer 3-104
SomeTCP Parameters in Linux Kerneltcp_syn_retries
Number of SYN packets the kernel will send before giving up on the new connection
tcp_synack_retriesnumber of SYN+ACK packets sent before the kernel gives up on the connection
tcp_window_scalingMaximum window size of 65535 bytes not enough for for really fast networks The window scaling options allows for almost gigabyte windows which is good for connections with large delay-bandwidth product
tcp_max_syn_backlogMaximal number of remembered connection requests which still did not receive an acknowledgment from connecting client
tcp_fin_timeoutHow many seconds to wait for a final FIN packet before the socket is closed required to prevent denial-of-service (DoS) attacks Default value is 60 seconds
Transport Layer 3-105
SomeTCP Parameters in Linux Kerneltcp_rmem
This is a vector of 3 integers [min default max] These parameters are used by TCP to dynamically adjust receive buffer sizesmin - minimum size of the receive buffer used by each TCP socket The default value is 4K default - the default size of the receive buffer for a TCP socket The default value is 87380 bytes and is lowered to 43689 in low memory systems If larger receive buffer sizes are desired this value should be increased max - the maximum size of the receive buffer used by each TCP socket The default value of 873802 bytes is lowered to 87380 in low memory systems
tcp_smemSend buffer parameters [min default max] similar to tcp_rmem
- Chapter 3 Transport Layer
- Transport services and protocols
- Transport vs network layer
- Internet transport-layer protocols
- Multiplexingdemultiplexing
- How demultiplexing works
- Connectionless demultiplexing
- Connection-oriented demux
- Connection-oriented demux (cont)
- Connection-oriented demux Threaded Web Server
- UDP User Datagram Protocol [RFC 768]
- UDP more
- UDP checksum
- Principles of Reliable data transfer
- Reliable data transfer getting started
- Reliable data transfer getting started
- Rdt10 reliable transfer over a reliable channel
- Rdt20 channel with bit errors
- rdt20 FSM specification
- rdt20 operation with no errors
- rdt20 error scenario
- rdt20 has a fatal flaw
- rdt21 sender handles garbled ACKNAKs
- rdt21 receiver handles garbled ACKNAKs
- rdt21 discussion
- rdt22 a NAK-free protocol
- rdt22 sender receiver fragments
- rdt30 channels with errors and loss
- rdt30 sender
- rdt30 in action
- rdt30 in action
- Performance of rdt30
- rdt30 stop-and-wait operation
- Pipelined protocols
- Pipelining increased utilization
- Go-Back-N
- GBN sender extended FSM
- GBN receiver extended FSM
- GBN inaction
- Selective Repeat
- Selective repeat sender receiver windows
- Selective repeat
- Selective repeat in action
- Selective repeat dilemma
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- TCP Overview RFCs 793 1122 1323 2018 2581
- TCP segment structure
- TCP seq rsquos and ACKs
- TCP Round Trip Time and Timeout
- TCP Round Trip Time and Timeout
- Example RTT estimation
- TCP Round Trip Time and Timeout
- TCP reliable data transfer
- TCP sender events
- TCP sender(simplified)
- TCP retransmission scenarios
- TCP retransmission scenarios (more)
- TCP ACK generation [RFC 1122 RFC 2581]
- Fast Retransmit
- Fast Retransmit
- Fast retransmit algorithm
- TCP Flow Control
- TCP Flow control how it works
- Sliding Window Flow Control Example
- Principles of Congestion Control
- Causescosts of congestion scenario 1
- Causescosts of congestion scenario 2
- Causescosts of congestion scenario 2
- Causescosts of congestion scenario 3
- Causescosts of congestion scenario 3
- Approaches towards congestion control
- TCP Congestion Control
- TCP congestion control bandwidth probing
- TCP Congestion Control details
- TCP Congestion Control more details
- TCP Slow Start Phase
- Slow Start Example
- TCP Congestion Avoidance Phase
- Congestion Avoidance
- Example Slow StartCongestion Avoidance
- Slow Start Congestion Avoidance
- Responses to Congestion
- Fast Recovery (differentiation btwn two loss events)
- TCP Congestion Control
- Popular ldquoflavorsrdquo of TCP
- Summary TCP Congestion Control
- TCP Congestion Control Summary
- TCP throughput
- TCP Futures TCP over ldquolong fat pipesrdquo
- TCP Fairness
- Why is TCP fair
- Fairness (more)
- TCP Connection Management
- TCP Connection Management (cont)
- TCP Connection Management (cont)
- TCP Connection Management (cont)
- Tuning TCPIP Parameters
- SomeTCP Parameters in Linux Kernel
- SomeTCP Parameters in Linux Kernel
-
Transport Layer 3-58
TCP Round Trip Time and TimeoutSetting the timeout
EstimatedRTT plus ldquosafety marginrdquolarge variation in EstimatedRTT -gt larger safety margin
first estimate of how much SampleRTT deviates from EstimatedRTT
TimeoutInterval = EstimatedRTT + 4DevRTT
DevRTT = (1-β)DevRTT +β|SampleRTT-EstimatedRTT|
(typically β = 025)
Then set timeout interval
Transport Layer 3-59
TCP reliable data transfer
TCP creates rdtservice on top of IPrsquos unreliable servicePipelined segmentsCumulative acksTCP uses single retransmission timer however it just retransmits the first segment in the window
Retransmissions are triggered by
timeout eventsduplicate acks
Initially consider simplified TCP sender
ignore duplicate acksignore flow control congestion control
Transport Layer 3-60
TCP sender eventsdata rcvd from app
Create segment with seq seq is byte-stream number of first data byte in segmentstart timer if not already running (think of timer as for oldest unacked segment)expiration interval TimeOutInterval
timeoutretransmit segment that caused timeout (first segment in the window)restart timer
Ack rcvdIf acknowledges previously unacked segments
update what is known to be ackedstart timer if there are outstanding segments
Transport Layer 3-61
TCP sender(simplified)
NextSeqNum = InitialSeqNumSendBase = InitialSeqNum
loop (forever) switch(event)
event data received from application above create TCP segment with sequence number NextSeqNumif (timer currently not running)
start timerpass segment to IP NextSeqNum = NextSeqNum + length(data)
event timer timeoutretransmit not-yet-acknowledged segment with
smallest sequence numberstart timer
event ACK received with ACK field value of y if (y gt SendBase)
SendBase = yif (there are currently not-yet-acknowledged segments)
start timer
end of loop forever
Commentbull SendBase-1 last cumulatively ackrsquoed byteExamplebull SendBase-1 = 71y= 73 so the rcvrwants 73+ y gt SendBase sothat new data is acked
Transport Layer 3-62
TCP retransmission scenariosHost A
Seq=100 20 bytes data
ACK=100
timepremature timeout
Host B
Seq=92 8 bytes data
ACK=120
Seq=92 8 bytes data
Seq=
92 t
imeo
ut
ACK=120
Host A
Seq=92 8 bytes data
ACK=100
loss
tim
eout
lost ACK scenario
Host B
X
Seq=92 8 bytes data
ACK=100
time
Seq=
92 t
imeo
utSendBase
= 100
SendBase= 120
SendBase= 120
Sendbase= 100
Transport Layer 3-63
TCP retransmission scenarios (more)Host A
Seq=92 8 bytes data
ACK=100
loss
tim
eout
Cumulative ACK scenario
Host B
X
Seq=100 20 bytes data
ACK=120
time
SendBase= 120
Transport Layer 3-64
TCP ACK generation [RFC 1122 RFC 2581]
Event at Receiver
Arrival of in-order segment withexpected seq All data up toexpected seq already ACKed
Arrival of in-order segment withexpected seq One other segment has ACK pending
Arrival of out-of-order segmenthigher-than-expect seq Gap detected
Arrival of segment that partially or completely fills gap
TCP Receiver action
Delayed ACK Wait up to 500msfor next segment If no next segmentsend ACK
Immediately send single cumulative ACK ACKing both in-order segments
Immediately send duplicate ACK indicating seq of next expected byte
Immediate send ACK provided thatsegment startsat lower end of gap
Transport Layer 3-65
Fast Retransmit
Time-out period often relatively long
long delay before resending lost packet
Detect lost segments via duplicate ACKs
Sender often sends many segments back-to-backIf segment is lost there will likely be many duplicate ACKs
If sender receives 3 ACKs for the same data it supposes that segment after ACKeddata was lost
fast retransmit resend segment before timer expires
Transport Layer 3-66
Fast RetransmitResend a segment after 3 duplicate ACKs since a duplicate ACK means that an out-of sequence segment was receivedduplicate ACKs due to packet reorderingif window is small donrsquot get duplicate ACKs
Host A
tim
eout
Host B
time
X
resend seq X2
seq x1seq x2seq x3seq x4seq x5
ACK x1
ACK x1ACK x1ACK x1
tripleduplicate
ACKs
Transport Layer 3-67
event ACK received with ACK field value of y if (y gt SendBase)
SendBase = yif (there are currently not-yet-acknowledged segments)
start timer
else increment count of dup ACKs received for yif (count of dup ACKs received for y = 3)
resend segment with sequence number y
Fast retransmit algorithm
a duplicate ACK for already ACKed segment
fast retransmit
Transport Layer 3-68
TCP Flow Control
receive side of TCP connection has a receive buffer
speed-matching service matching the send rate to the receiving apprsquos drain rate
app process may be slow at reading from buffer
sender wonrsquot overflowreceiverrsquos buffer by
transmitting too muchtoo fast
flow control
Transport Layer 3-69
TCP Flow control how it works
(Suppose TCP receiver discards out-of-order segments)spare room in buffer
= RcvWin
= RcvBuffer-[LastByteRcvd -LastByteRead]
Rcvr advertises spare room by including value of RcvWin in segmentsSender limits unACKeddata to RcvWin
guarantees receive buffer doesnrsquot overflow
Transport Layer 3-70
Sliding Window Flow Control Example
3K
2K SeqNo=0
ReceiverBuffer
0 4KSendersends 2Kof data
2K
AckNo=2048 RcvWin=2048Sendersends 2Kof data 2K SeqNo=2048
4K
AckNo=4096 RcvWin=0
AckNo=4096 RcvWin=1024
Sender blocked
Transport Layer 3-71
Principles of Congestion Control
Congestioninformally ldquotoo many sources sending too much data too fast for network to handlerdquodifferent from flow controlmanifestations
lost packets (buffer overflow at routers)long delays (queueing in router buffers)
a top-10 problem
Transport Layer 3-72
Causescosts of congestion scenario 1
two senders two receiversone router infinite buffers no retransmission
large delays when congestedmaximum achievable throughput
unlimited shared output link buffers
Host Aλin original data
Host B
λout
Transport Layer 3-73
Causescosts of congestion scenario 2
one router finite buffers sender retransmission of lost packet
finite shared output link buffers
Host A λin original data
Host B
λout
λin original data plus retransmitted data
Transport Layer 3-74
Causescosts of congestion scenario 2always (goodput)ldquoperfectrdquo retransmission only when loss
retransmission of delayed (not lost) packet makes larger(than perfect case) for same
λin
λout=
λin
λoutgtλ
inλout
ldquocostsrdquo of congestionmore work (retrans) for given ldquogoodputrdquounneeded retransmissions link carries multiple copies of pkt
R2
R2λin
λ out
b
R2
R2λin
λ out
a
R2
R2λin
λ out
c
R4
R3
Transport Layer 3-75
Causescosts of congestion scenario 3four sendersmultihop pathstimeoutretransmit
λin
Q what happens as and increase λ
in
finite shared output link buffers
Host Aλin original data
Host B
λout
λin original data plus retransmitted data
Transport Layer 3-76
Causescosts of congestion scenario 3
another ldquocostrdquo of congestionwhen packet dropped any ldquoupstream transmission capacity used for that packet was wasted
Host A
Host B
λou
t
Transport Layer 3-77
Approaches towards congestion control
End-end congestion controlno explicit feedback from networkcongestion inferred from end-system observed loss delayapproach taken by TCP
Network-assisted congestion controlrouters provide feedback to end systems
single bit indicating congestion (SNA DECbit TCPIP ECN ATM)explicit rate sender should send at
Two broad approaches towards congestion control
Transport Layer 3-78
TCP Congestion Control
end-end control (no network assistance)sender limits transmissionLastByteSent-LastByteAcked
le CongWin
CongWin is dynamic function of perceived network congestion
How does sender perceive congestionloss event = timeout or3 duplicate acksTCP sender reduces rate (CongWin) after loss event
two modes of operationSlow Start (SS)Congestion avoidance (CA) or Additive Increase Multiplicative Decrease (AIMD)
Transport Layer 3-79
TCP congestion control bandwidth probing
ldquoprobing for bandwidthrdquo increase transmission rate on receipt of ACK until eventually loss occurs then decrease transmission rate
continue to increase on ACK decrease on loss (since available bandwidth is changing depending on other connections in network)
ACKs being received so increase rate
X
X
XX
X loss so decrease rate
send
ing
rate
time
Q how fast to increasedecreasedetails to follow
TCPrsquosldquosawtoothrdquobehavior
Transport Layer 3-80
TCP Congestion Control details
sender limits rate by limiting number of unACKed bytes ldquoin pipelinerdquo
cwnd differs from rwnd (how why)sender limited by min(cwndrwnd)
roughly
cwnd is dynamic function of perceived network congestion
rate = cwndRTT bytessec
LastByteSent-LastByteAcked le cwnd
cwndbytes
RTT
ACK(s)
Transport Layer 3-81
TCP Congestion Control more details
segment loss event reducing cwndtimeout no response from receiver
cut cwnd to 13 duplicate ACKs at least some segments getting through (recall fast retransmit)
cut cwnd in half less aggressively than on timeout
ACK received increase cwndTwo modes of operation
slowstart phase bull increase exponentially
fast (despite name) at connection start or following timeout
congestion avoidance bull increase linearly
Transport Layer 3-82
TCP Slow Start Phasewhen connection begins cwnd = 1 MSS
example MSS = 500 bytes amp RTT = 200 msecinitial rate = 20 kbps
available bandwidth may be gtgt MSSRTT
desirable to quickly ramp up to respectable rate
increase rate exponentially until first loss event or when threshold reached
double cwnd every RTTdone by incrementing cwnd by 1 for every ACK received
Host A
one segment
RTT
Host B
time
two segments
four segments
Transport Layer 3-83
Slow Start ExampleThe congestion window size grows very rapidly
For every ACK we increase CongWin by 1 irrespective of the number of segments ACKrsquoeddouble CongWinevery RTTinitial rate is slow but ramps up exponentially fast
TCP slows down the increase of CongWinwhen CongWin gt ssthresh
segment 1
ACK for segment 1
cwnd = 1
cwnd = 2 segment 2segment 3
ACK for segments 2
cwnd = 4 segment 4segment 5segment 6
ACK for segments 4
cwnd = 7
ACK for segments 3
ACK for segments 5
ACK for segments 6
cwnd = 3
cwnd = 5
cwnd = 6ACK for segments 7
cwnd = 8
segment 7
Transport Layer 3-84
TCP Congestion Avoidance Phase
when cwnd gt ssthreshgrow cwnd linearly
increase cwnd by 1 MSS per RTT approach possible congestion slower than in slowstartimplementation cwnd= cwnd + MSScwndfor each ACK received
ACKs increase cwndby 1 MSS per RTT additive increaseloss cut cwnd in half (non-timeout-detected loss ) multiplicative decrease
AIMD
AIMD Additive IncreaseMultiplicative Decrease
Transport Layer 3-85
Congestion AvoidanceCongestion avoidance phase is started if CongWin has reached the slow-start threshold value
If CongWin gt= ssthresh then each time an ACK is received increment CongWin as follows
bull CongWin = CongWin + 1CongWin (CongWin in segments)
bull In actual TCP implementation CongWin is in BytesCongWin = CongWin + MSS (MSSCongWin)
So CongWin is increased by one only if all CongWinsegments have been acknowledged
Transport Layer 3-86
Example Slow StartCongestion AvoidanceAssume that
ssthresh = 8
cwnd = 1
cwnd = 2
cwnd = 4
cwnd = 8
cwnd = 9
cwnd = 10
02468
101214
t=0
t=2
t=4
t=6
Roundtrip times
Cw
nd(in
seg
men
ts)
ssthresh
cwnd = 3
cwnd = 5cwnd = 6cwnd = 7
Transport Layer 3-87
Slow Start Congestion AvoidanceA typical plot of CongWin for a TCP connection
(MSS = 1500 bytes) with TCP Tahoe
SS
CA
ssthresh
Transport Layer 3-88
Responses to CongestionTCP assumes there is congestion if it detects a packet lossA TCP sender can detect lost packets via loss events
bull Timeout of a retransmission timerbull Receipt of 3 duplicate ACKs (fast retransmit)
TCP interprets a Timeout as a binary congestion signal When a timeout occurs the sender performs
ssthresh is set to half the current size of the congestion window
ssthresh = CongWin 2CongWin is reset to one
CongWin = 1and slow-start is entered
Transport Layer 3-89
Fast Recovery (differentiation btwn two loss events) After 3 dup ACKs (fast Retransmit)
ssthresh = CongWin2CongWin = CongWin2window then grows linearly
But after timeout eventCongWin = 1 MSS window then grows exponentiallyto the threshold then grows linearly
bull 3 dup ACKs indicates network capable of delivering some segmentsbull timeout before 3 dup ACKs is ldquomore alarmingrdquo
Philosophy
3-90
TCP Congestion ControlInitially
CongWin = 1ssthresh = advertised window size
New Ack receivedif (CongWin lt ssthresh) Slow Start
CongWin = CongWin + 1else Congestion Avoidance
CongWin = CongWin + 1CongWinTimeout
ssthresh = CongWin2CongWin = 1
Fast Retransmissionssthresh = CongWin2CongWin = CongWin2
Slow Start (exponential increase phase) is continued until CongWin reaches half of the level where the loss event occurred last time CongWin is increased slowly after (linear increase in Congestion Avoidance phase)
Transport Layer 3-91
Popular ldquoflavorsrdquo of TCP
ssthresh
ssthresh
TCP Tahoe
TCP Reno
Transmission round
cwnd
win
dow
siz
e (in
seg
men
ts)
Transport Layer 3-92
Summary TCP Congestion ControlWhen CongWin is below Threshold sender in slow-start phase window grows exponentiallyWhen CongWin is above Threshold sender is in congestion-avoidance phase window grows linearlyWhen a triple duplicate ACK occurs Threshold set to CongWin2 and CongWin set to ThresholdWhen timeout occurs Threshold set to CongWin2 and CongWin is set to 1 MSS The actual sender window size is determined based on the congestion and flow control algorithms
SenderWin=min(RcvWinCongWin)
Transport Layer 3-93
TCP Congestion Control SummaryEvent State TCP Sender Action Commentary
ACK receipt for previously unackeddata
Slow Start (SS)
CongWin = CongWin + MSS If (CongWin gt Threshold)
set state to ldquoCongestion Avoidancerdquo
Resulting in a doubling of CongWin every RTT
ACK receipt for previously unackeddata
CongestionAvoidance (CA)
CongWin = CongWin+MSS (MSSCongWin)
Additive increase resulting in increase of CongWin by 1 MSS every RTT
Loss event detected by triple duplicate ACK
SS or CA Threshold = CongWin2 CongWin = ThresholdSet state to ldquoCongestion Avoidancerdquo
Fast recovery implementing multiplicative decrease CongWin will not drop below 1 MSS
Timeout SS or CA Threshold = CongWin2 CongWin = 1 MSSSet state to ldquoSlow Startrdquo
Enter slow start
Duplicate ACK
SS or CA Increment duplicate ACK count for segment being acked
CongWin and Threshold not changed
Transport Layer 3-94
TCP throughput
Q whatrsquos average throughout of TCP as function of window size RTT
ignoring slow startlet W be window size when loss occurs
when window is W throughput is WRTTjust after loss window drops to W2 throughput to W2RTT average throughout 75 WRTT
Transport Layer 3-95
TCP Futures TCP over ldquolong fat pipesrdquo
example 1500 byte segments 100ms RTT want 10 Gbps throughputrequires window size W = 83333 in-flight segmentsthroughput in terms of loss rate
L = 210-10 Wownew versions of TCP for high-speed
LRTTMSSsdot221
Transport Layer 3-96
Fairness goal if K TCP sessions share same bottleneck link of bandwidth R each should have average rate of RK
TCP connection 1
bottleneckrouter
capacity R
TCP connection 2
TCP Fairness
Transport Layer 3-97
Why is TCP fairTwo competing sessions
Additive increase gives slope of 1 as throughout increasesmultiplicative decrease decreases throughput proportionally
R
R
equal bandwidth share
Connection 1 throughput
Conn
ecti
on 2
thr
ough
p ut
congestion avoidance additive increaseloss decrease window by factor of 2
congestion avoidance additive increaseloss decrease window by factor of 2
Transport Layer 3-98
Fairness (more)Fairness and UDP
Multimedia apps often do not use TCP
do not want rate throttled by congestion control
Instead use UDPpump audiovideo at constant rate tolerate packet loss
Research area TCP friendly
Fairness and parallel TCP connectionsnothing prevents app from opening parallel cnctionsbetween 2 hostsWeb browsers do this Example link of rate R supporting 9 cnctions
new app asks for 1 TCP gets rate R10new app asks for 11 TCPs gets R2
Transport Layer 3-99
TCP Connection ManagementRecall TCP sender receiver
establish ldquoconnectionrdquobefore exchanging data segmentsinitialize TCP variables
seq sbuffers flow control info (eg RcvWindow)
client connection initiatorSocket clientSocket = new Socket(hostnameport
number)
server contacted by clientSocket connectionSocket = welcomeSocketaccept()
Three way handshakeStep 1 client host sends TCP
SYN segment to serverspecifies initial seq no data
Step 2 server host receives SYN replies with SYNACK segment
server allocates buffersspecifies server initial seq
Step 3 client receives SYNACK replies with ACK segment which may contain data
Transport Layer 3-100
TCP Connection Management (cont)
Closing a connection
client closes socketclientSocketclose()
Step 1 client end system sends TCP FIN control segment to server
Step 2 server receives FIN replies with ACK Closes connection sends FIN
client
FIN
server
ACK
ACK
FIN
close
close
closed
tim
ed w
ait
Transport Layer 3-101
TCP Connection Management (cont)
Step 3 client receives FIN replies with ACK
Enters ldquotimed waitrdquo -will respond with ACK to received FINs
Step 4 server receives ACK Connection closed
client
FIN
server
ACK
ACK
FIN
closing
closing
closed
tim
ed w
ait
closed
Transport Layer 3-102
TCP Connection Management (cont)
TCP clientlifecycle
TCP serverlifecycle
Transport Layer 3-103
Tuning TCPIP Parameters TCPIP parameters
A set of default values may not be optimal for all applicationsThe network administrator may wish to turn on or off some TCPIP functions for performance or security considerations
Many Unix and Linux systems provide some flexibility in tuning the TCPIP kernelsbinsysctl is used to configure the Linux kernel parameters at runtime
Default kernel configuration file is sbinsysctlconfFrequently used sysctl options
bull sysctl ndasha or sysctl ndashA list all current valuesbull sysctl ndashp file_name load the sysctl setting from a configuration
filebull sysctl ndashw variable=value change the value of the parameter
Transport Layer 3-104
SomeTCP Parameters in Linux Kerneltcp_syn_retries
Number of SYN packets the kernel will send before giving up on the new connection
tcp_synack_retriesnumber of SYN+ACK packets sent before the kernel gives up on the connection
tcp_window_scalingMaximum window size of 65535 bytes not enough for for really fast networks The window scaling options allows for almost gigabyte windows which is good for connections with large delay-bandwidth product
tcp_max_syn_backlogMaximal number of remembered connection requests which still did not receive an acknowledgment from connecting client
tcp_fin_timeoutHow many seconds to wait for a final FIN packet before the socket is closed required to prevent denial-of-service (DoS) attacks Default value is 60 seconds
Transport Layer 3-105
SomeTCP Parameters in Linux Kerneltcp_rmem
This is a vector of 3 integers [min default max] These parameters are used by TCP to dynamically adjust receive buffer sizesmin - minimum size of the receive buffer used by each TCP socket The default value is 4K default - the default size of the receive buffer for a TCP socket The default value is 87380 bytes and is lowered to 43689 in low memory systems If larger receive buffer sizes are desired this value should be increased max - the maximum size of the receive buffer used by each TCP socket The default value of 873802 bytes is lowered to 87380 in low memory systems
tcp_smemSend buffer parameters [min default max] similar to tcp_rmem
- Chapter 3 Transport Layer
- Transport services and protocols
- Transport vs network layer
- Internet transport-layer protocols
- Multiplexingdemultiplexing
- How demultiplexing works
- Connectionless demultiplexing
- Connection-oriented demux
- Connection-oriented demux (cont)
- Connection-oriented demux Threaded Web Server
- UDP User Datagram Protocol [RFC 768]
- UDP more
- UDP checksum
- Principles of Reliable data transfer
- Reliable data transfer getting started
- Reliable data transfer getting started
- Rdt10 reliable transfer over a reliable channel
- Rdt20 channel with bit errors
- rdt20 FSM specification
- rdt20 operation with no errors
- rdt20 error scenario
- rdt20 has a fatal flaw
- rdt21 sender handles garbled ACKNAKs
- rdt21 receiver handles garbled ACKNAKs
- rdt21 discussion
- rdt22 a NAK-free protocol
- rdt22 sender receiver fragments
- rdt30 channels with errors and loss
- rdt30 sender
- rdt30 in action
- rdt30 in action
- Performance of rdt30
- rdt30 stop-and-wait operation
- Pipelined protocols
- Pipelining increased utilization
- Go-Back-N
- GBN sender extended FSM
- GBN receiver extended FSM
- GBN inaction
- Selective Repeat
- Selective repeat sender receiver windows
- Selective repeat
- Selective repeat in action
- Selective repeat dilemma
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- TCP Overview RFCs 793 1122 1323 2018 2581
- TCP segment structure
- TCP seq rsquos and ACKs
- TCP Round Trip Time and Timeout
- TCP Round Trip Time and Timeout
- Example RTT estimation
- TCP Round Trip Time and Timeout
- TCP reliable data transfer
- TCP sender events
- TCP sender(simplified)
- TCP retransmission scenarios
- TCP retransmission scenarios (more)
- TCP ACK generation [RFC 1122 RFC 2581]
- Fast Retransmit
- Fast Retransmit
- Fast retransmit algorithm
- TCP Flow Control
- TCP Flow control how it works
- Sliding Window Flow Control Example
- Principles of Congestion Control
- Causescosts of congestion scenario 1
- Causescosts of congestion scenario 2
- Causescosts of congestion scenario 2
- Causescosts of congestion scenario 3
- Causescosts of congestion scenario 3
- Approaches towards congestion control
- TCP Congestion Control
- TCP congestion control bandwidth probing
- TCP Congestion Control details
- TCP Congestion Control more details
- TCP Slow Start Phase
- Slow Start Example
- TCP Congestion Avoidance Phase
- Congestion Avoidance
- Example Slow StartCongestion Avoidance
- Slow Start Congestion Avoidance
- Responses to Congestion
- Fast Recovery (differentiation btwn two loss events)
- TCP Congestion Control
- Popular ldquoflavorsrdquo of TCP
- Summary TCP Congestion Control
- TCP Congestion Control Summary
- TCP throughput
- TCP Futures TCP over ldquolong fat pipesrdquo
- TCP Fairness
- Why is TCP fair
- Fairness (more)
- TCP Connection Management
- TCP Connection Management (cont)
- TCP Connection Management (cont)
- TCP Connection Management (cont)
- Tuning TCPIP Parameters
- SomeTCP Parameters in Linux Kernel
- SomeTCP Parameters in Linux Kernel
-
Transport Layer 3-59
TCP reliable data transfer
TCP creates rdtservice on top of IPrsquos unreliable servicePipelined segmentsCumulative acksTCP uses single retransmission timer however it just retransmits the first segment in the window
Retransmissions are triggered by
timeout eventsduplicate acks
Initially consider simplified TCP sender
ignore duplicate acksignore flow control congestion control
Transport Layer 3-60
TCP sender eventsdata rcvd from app
Create segment with seq seq is byte-stream number of first data byte in segmentstart timer if not already running (think of timer as for oldest unacked segment)expiration interval TimeOutInterval
timeoutretransmit segment that caused timeout (first segment in the window)restart timer
Ack rcvdIf acknowledges previously unacked segments
update what is known to be ackedstart timer if there are outstanding segments
Transport Layer 3-61
TCP sender(simplified)
NextSeqNum = InitialSeqNumSendBase = InitialSeqNum
loop (forever) switch(event)
event data received from application above create TCP segment with sequence number NextSeqNumif (timer currently not running)
start timerpass segment to IP NextSeqNum = NextSeqNum + length(data)
event timer timeoutretransmit not-yet-acknowledged segment with
smallest sequence numberstart timer
event ACK received with ACK field value of y if (y gt SendBase)
SendBase = yif (there are currently not-yet-acknowledged segments)
start timer
end of loop forever
Commentbull SendBase-1 last cumulatively ackrsquoed byteExamplebull SendBase-1 = 71y= 73 so the rcvrwants 73+ y gt SendBase sothat new data is acked
Transport Layer 3-62
TCP retransmission scenariosHost A
Seq=100 20 bytes data
ACK=100
timepremature timeout
Host B
Seq=92 8 bytes data
ACK=120
Seq=92 8 bytes data
Seq=
92 t
imeo
ut
ACK=120
Host A
Seq=92 8 bytes data
ACK=100
loss
tim
eout
lost ACK scenario
Host B
X
Seq=92 8 bytes data
ACK=100
time
Seq=
92 t
imeo
utSendBase
= 100
SendBase= 120
SendBase= 120
Sendbase= 100
Transport Layer 3-63
TCP retransmission scenarios (more)Host A
Seq=92 8 bytes data
ACK=100
loss
tim
eout
Cumulative ACK scenario
Host B
X
Seq=100 20 bytes data
ACK=120
time
SendBase= 120
Transport Layer 3-64
TCP ACK generation [RFC 1122 RFC 2581]
Event at Receiver
Arrival of in-order segment withexpected seq All data up toexpected seq already ACKed
Arrival of in-order segment withexpected seq One other segment has ACK pending
Arrival of out-of-order segmenthigher-than-expect seq Gap detected
Arrival of segment that partially or completely fills gap
TCP Receiver action
Delayed ACK Wait up to 500msfor next segment If no next segmentsend ACK
Immediately send single cumulative ACK ACKing both in-order segments
Immediately send duplicate ACK indicating seq of next expected byte
Immediate send ACK provided thatsegment startsat lower end of gap
Transport Layer 3-65
Fast Retransmit
Time-out period often relatively long
long delay before resending lost packet
Detect lost segments via duplicate ACKs
Sender often sends many segments back-to-backIf segment is lost there will likely be many duplicate ACKs
If sender receives 3 ACKs for the same data it supposes that segment after ACKeddata was lost
fast retransmit resend segment before timer expires
Transport Layer 3-66
Fast RetransmitResend a segment after 3 duplicate ACKs since a duplicate ACK means that an out-of sequence segment was receivedduplicate ACKs due to packet reorderingif window is small donrsquot get duplicate ACKs
Host A
tim
eout
Host B
time
X
resend seq X2
seq x1seq x2seq x3seq x4seq x5
ACK x1
ACK x1ACK x1ACK x1
tripleduplicate
ACKs
Transport Layer 3-67
event ACK received with ACK field value of y if (y gt SendBase)
SendBase = yif (there are currently not-yet-acknowledged segments)
start timer
else increment count of dup ACKs received for yif (count of dup ACKs received for y = 3)
resend segment with sequence number y
Fast retransmit algorithm
a duplicate ACK for already ACKed segment
fast retransmit
Transport Layer 3-68
TCP Flow Control
receive side of TCP connection has a receive buffer
speed-matching service matching the send rate to the receiving apprsquos drain rate
app process may be slow at reading from buffer
sender wonrsquot overflowreceiverrsquos buffer by
transmitting too muchtoo fast
flow control
Transport Layer 3-69
TCP Flow control how it works
(Suppose TCP receiver discards out-of-order segments)spare room in buffer
= RcvWin
= RcvBuffer-[LastByteRcvd -LastByteRead]
Rcvr advertises spare room by including value of RcvWin in segmentsSender limits unACKeddata to RcvWin
guarantees receive buffer doesnrsquot overflow
Transport Layer 3-70
Sliding Window Flow Control Example
3K
2K SeqNo=0
ReceiverBuffer
0 4KSendersends 2Kof data
2K
AckNo=2048 RcvWin=2048Sendersends 2Kof data 2K SeqNo=2048
4K
AckNo=4096 RcvWin=0
AckNo=4096 RcvWin=1024
Sender blocked
Transport Layer 3-71
Principles of Congestion Control
Congestioninformally ldquotoo many sources sending too much data too fast for network to handlerdquodifferent from flow controlmanifestations
lost packets (buffer overflow at routers)long delays (queueing in router buffers)
a top-10 problem
Transport Layer 3-72
Causescosts of congestion scenario 1
two senders two receiversone router infinite buffers no retransmission
large delays when congestedmaximum achievable throughput
unlimited shared output link buffers
Host Aλin original data
Host B
λout
Transport Layer 3-73
Causescosts of congestion scenario 2
one router finite buffers sender retransmission of lost packet
finite shared output link buffers
Host A λin original data
Host B
λout
λin original data plus retransmitted data
Transport Layer 3-74
Causescosts of congestion scenario 2always (goodput)ldquoperfectrdquo retransmission only when loss
retransmission of delayed (not lost) packet makes larger(than perfect case) for same
λin
λout=
λin
λoutgtλ
inλout
ldquocostsrdquo of congestionmore work (retrans) for given ldquogoodputrdquounneeded retransmissions link carries multiple copies of pkt
R2
R2λin
λ out
b
R2
R2λin
λ out
a
R2
R2λin
λ out
c
R4
R3
Transport Layer 3-75
Causescosts of congestion scenario 3four sendersmultihop pathstimeoutretransmit
λin
Q what happens as and increase λ
in
finite shared output link buffers
Host Aλin original data
Host B
λout
λin original data plus retransmitted data
Transport Layer 3-76
Causescosts of congestion scenario 3
another ldquocostrdquo of congestionwhen packet dropped any ldquoupstream transmission capacity used for that packet was wasted
Host A
Host B
λou
t
Transport Layer 3-77
Approaches towards congestion control
End-end congestion controlno explicit feedback from networkcongestion inferred from end-system observed loss delayapproach taken by TCP
Network-assisted congestion controlrouters provide feedback to end systems
single bit indicating congestion (SNA DECbit TCPIP ECN ATM)explicit rate sender should send at
Two broad approaches towards congestion control
Transport Layer 3-78
TCP Congestion Control
end-end control (no network assistance)sender limits transmissionLastByteSent-LastByteAcked
le CongWin
CongWin is dynamic function of perceived network congestion
How does sender perceive congestionloss event = timeout or3 duplicate acksTCP sender reduces rate (CongWin) after loss event
two modes of operationSlow Start (SS)Congestion avoidance (CA) or Additive Increase Multiplicative Decrease (AIMD)
Transport Layer 3-79
TCP congestion control bandwidth probing
ldquoprobing for bandwidthrdquo increase transmission rate on receipt of ACK until eventually loss occurs then decrease transmission rate
continue to increase on ACK decrease on loss (since available bandwidth is changing depending on other connections in network)
ACKs being received so increase rate
X
X
XX
X loss so decrease rate
send
ing
rate
time
Q how fast to increasedecreasedetails to follow
TCPrsquosldquosawtoothrdquobehavior
Transport Layer 3-80
TCP Congestion Control details
sender limits rate by limiting number of unACKed bytes ldquoin pipelinerdquo
cwnd differs from rwnd (how why)sender limited by min(cwndrwnd)
roughly
cwnd is dynamic function of perceived network congestion
rate = cwndRTT bytessec
LastByteSent-LastByteAcked le cwnd
cwndbytes
RTT
ACK(s)
Transport Layer 3-81
TCP Congestion Control more details
segment loss event reducing cwndtimeout no response from receiver
cut cwnd to 13 duplicate ACKs at least some segments getting through (recall fast retransmit)
cut cwnd in half less aggressively than on timeout
ACK received increase cwndTwo modes of operation
slowstart phase bull increase exponentially
fast (despite name) at connection start or following timeout
congestion avoidance bull increase linearly
Transport Layer 3-82
TCP Slow Start Phasewhen connection begins cwnd = 1 MSS
example MSS = 500 bytes amp RTT = 200 msecinitial rate = 20 kbps
available bandwidth may be gtgt MSSRTT
desirable to quickly ramp up to respectable rate
increase rate exponentially until first loss event or when threshold reached
double cwnd every RTTdone by incrementing cwnd by 1 for every ACK received
Host A
one segment
RTT
Host B
time
two segments
four segments
Transport Layer 3-83
Slow Start ExampleThe congestion window size grows very rapidly
For every ACK we increase CongWin by 1 irrespective of the number of segments ACKrsquoeddouble CongWinevery RTTinitial rate is slow but ramps up exponentially fast
TCP slows down the increase of CongWinwhen CongWin gt ssthresh
segment 1
ACK for segment 1
cwnd = 1
cwnd = 2 segment 2segment 3
ACK for segments 2
cwnd = 4 segment 4segment 5segment 6
ACK for segments 4
cwnd = 7
ACK for segments 3
ACK for segments 5
ACK for segments 6
cwnd = 3
cwnd = 5
cwnd = 6ACK for segments 7
cwnd = 8
segment 7
Transport Layer 3-84
TCP Congestion Avoidance Phase
when cwnd gt ssthreshgrow cwnd linearly
increase cwnd by 1 MSS per RTT approach possible congestion slower than in slowstartimplementation cwnd= cwnd + MSScwndfor each ACK received
ACKs increase cwndby 1 MSS per RTT additive increaseloss cut cwnd in half (non-timeout-detected loss ) multiplicative decrease
AIMD
AIMD Additive IncreaseMultiplicative Decrease
Transport Layer 3-85
Congestion AvoidanceCongestion avoidance phase is started if CongWin has reached the slow-start threshold value
If CongWin gt= ssthresh then each time an ACK is received increment CongWin as follows
bull CongWin = CongWin + 1CongWin (CongWin in segments)
bull In actual TCP implementation CongWin is in BytesCongWin = CongWin + MSS (MSSCongWin)
So CongWin is increased by one only if all CongWinsegments have been acknowledged
Transport Layer 3-86
Example Slow StartCongestion AvoidanceAssume that
ssthresh = 8
cwnd = 1
cwnd = 2
cwnd = 4
cwnd = 8
cwnd = 9
cwnd = 10
02468
101214
t=0
t=2
t=4
t=6
Roundtrip times
Cw
nd(in
seg
men
ts)
ssthresh
cwnd = 3
cwnd = 5cwnd = 6cwnd = 7
Transport Layer 3-87
Slow Start Congestion AvoidanceA typical plot of CongWin for a TCP connection
(MSS = 1500 bytes) with TCP Tahoe
SS
CA
ssthresh
Transport Layer 3-88
Responses to CongestionTCP assumes there is congestion if it detects a packet lossA TCP sender can detect lost packets via loss events
bull Timeout of a retransmission timerbull Receipt of 3 duplicate ACKs (fast retransmit)
TCP interprets a Timeout as a binary congestion signal When a timeout occurs the sender performs
ssthresh is set to half the current size of the congestion window
ssthresh = CongWin 2CongWin is reset to one
CongWin = 1and slow-start is entered
Transport Layer 3-89
Fast Recovery (differentiation btwn two loss events) After 3 dup ACKs (fast Retransmit)
ssthresh = CongWin2CongWin = CongWin2window then grows linearly
But after timeout eventCongWin = 1 MSS window then grows exponentiallyto the threshold then grows linearly
bull 3 dup ACKs indicates network capable of delivering some segmentsbull timeout before 3 dup ACKs is ldquomore alarmingrdquo
Philosophy
3-90
TCP Congestion ControlInitially
CongWin = 1ssthresh = advertised window size
New Ack receivedif (CongWin lt ssthresh) Slow Start
CongWin = CongWin + 1else Congestion Avoidance
CongWin = CongWin + 1CongWinTimeout
ssthresh = CongWin2CongWin = 1
Fast Retransmissionssthresh = CongWin2CongWin = CongWin2
Slow Start (exponential increase phase) is continued until CongWin reaches half of the level where the loss event occurred last time CongWin is increased slowly after (linear increase in Congestion Avoidance phase)
Transport Layer 3-91
Popular ldquoflavorsrdquo of TCP
ssthresh
ssthresh
TCP Tahoe
TCP Reno
Transmission round
cwnd
win
dow
siz
e (in
seg
men
ts)
Transport Layer 3-92
Summary TCP Congestion ControlWhen CongWin is below Threshold sender in slow-start phase window grows exponentiallyWhen CongWin is above Threshold sender is in congestion-avoidance phase window grows linearlyWhen a triple duplicate ACK occurs Threshold set to CongWin2 and CongWin set to ThresholdWhen timeout occurs Threshold set to CongWin2 and CongWin is set to 1 MSS The actual sender window size is determined based on the congestion and flow control algorithms
SenderWin=min(RcvWinCongWin)
Transport Layer 3-93
TCP Congestion Control SummaryEvent State TCP Sender Action Commentary
ACK receipt for previously unackeddata
Slow Start (SS)
CongWin = CongWin + MSS If (CongWin gt Threshold)
set state to ldquoCongestion Avoidancerdquo
Resulting in a doubling of CongWin every RTT
ACK receipt for previously unackeddata
CongestionAvoidance (CA)
CongWin = CongWin+MSS (MSSCongWin)
Additive increase resulting in increase of CongWin by 1 MSS every RTT
Loss event detected by triple duplicate ACK
SS or CA Threshold = CongWin2 CongWin = ThresholdSet state to ldquoCongestion Avoidancerdquo
Fast recovery implementing multiplicative decrease CongWin will not drop below 1 MSS
Timeout SS or CA Threshold = CongWin2 CongWin = 1 MSSSet state to ldquoSlow Startrdquo
Enter slow start
Duplicate ACK
SS or CA Increment duplicate ACK count for segment being acked
CongWin and Threshold not changed
Transport Layer 3-94
TCP throughput
Q whatrsquos average throughout of TCP as function of window size RTT
ignoring slow startlet W be window size when loss occurs
when window is W throughput is WRTTjust after loss window drops to W2 throughput to W2RTT average throughout 75 WRTT
Transport Layer 3-95
TCP Futures TCP over ldquolong fat pipesrdquo
example 1500 byte segments 100ms RTT want 10 Gbps throughputrequires window size W = 83333 in-flight segmentsthroughput in terms of loss rate
L = 210-10 Wownew versions of TCP for high-speed
LRTTMSSsdot221
Transport Layer 3-96
Fairness goal if K TCP sessions share same bottleneck link of bandwidth R each should have average rate of RK
TCP connection 1
bottleneckrouter
capacity R
TCP connection 2
TCP Fairness
Transport Layer 3-97
Why is TCP fairTwo competing sessions
Additive increase gives slope of 1 as throughout increasesmultiplicative decrease decreases throughput proportionally
R
R
equal bandwidth share
Connection 1 throughput
Conn
ecti
on 2
thr
ough
p ut
congestion avoidance additive increaseloss decrease window by factor of 2
congestion avoidance additive increaseloss decrease window by factor of 2
Transport Layer 3-98
Fairness (more)Fairness and UDP
Multimedia apps often do not use TCP
do not want rate throttled by congestion control
Instead use UDPpump audiovideo at constant rate tolerate packet loss
Research area TCP friendly
Fairness and parallel TCP connectionsnothing prevents app from opening parallel cnctionsbetween 2 hostsWeb browsers do this Example link of rate R supporting 9 cnctions
new app asks for 1 TCP gets rate R10new app asks for 11 TCPs gets R2
Transport Layer 3-99
TCP Connection ManagementRecall TCP sender receiver
establish ldquoconnectionrdquobefore exchanging data segmentsinitialize TCP variables
seq sbuffers flow control info (eg RcvWindow)
client connection initiatorSocket clientSocket = new Socket(hostnameport
number)
server contacted by clientSocket connectionSocket = welcomeSocketaccept()
Three way handshakeStep 1 client host sends TCP
SYN segment to serverspecifies initial seq no data
Step 2 server host receives SYN replies with SYNACK segment
server allocates buffersspecifies server initial seq
Step 3 client receives SYNACK replies with ACK segment which may contain data
Transport Layer 3-100
TCP Connection Management (cont)
Closing a connection
client closes socketclientSocketclose()
Step 1 client end system sends TCP FIN control segment to server
Step 2 server receives FIN replies with ACK Closes connection sends FIN
client
FIN
server
ACK
ACK
FIN
close
close
closed
tim
ed w
ait
Transport Layer 3-101
TCP Connection Management (cont)
Step 3 client receives FIN replies with ACK
Enters ldquotimed waitrdquo -will respond with ACK to received FINs
Step 4 server receives ACK Connection closed
client
FIN
server
ACK
ACK
FIN
closing
closing
closed
tim
ed w
ait
closed
Transport Layer 3-102
TCP Connection Management (cont)
TCP clientlifecycle
TCP serverlifecycle
Transport Layer 3-103
Tuning TCPIP Parameters TCPIP parameters
A set of default values may not be optimal for all applicationsThe network administrator may wish to turn on or off some TCPIP functions for performance or security considerations
Many Unix and Linux systems provide some flexibility in tuning the TCPIP kernelsbinsysctl is used to configure the Linux kernel parameters at runtime
Default kernel configuration file is sbinsysctlconfFrequently used sysctl options
bull sysctl ndasha or sysctl ndashA list all current valuesbull sysctl ndashp file_name load the sysctl setting from a configuration
filebull sysctl ndashw variable=value change the value of the parameter
Transport Layer 3-104
SomeTCP Parameters in Linux Kerneltcp_syn_retries
Number of SYN packets the kernel will send before giving up on the new connection
tcp_synack_retriesnumber of SYN+ACK packets sent before the kernel gives up on the connection
tcp_window_scalingMaximum window size of 65535 bytes not enough for for really fast networks The window scaling options allows for almost gigabyte windows which is good for connections with large delay-bandwidth product
tcp_max_syn_backlogMaximal number of remembered connection requests which still did not receive an acknowledgment from connecting client
tcp_fin_timeoutHow many seconds to wait for a final FIN packet before the socket is closed required to prevent denial-of-service (DoS) attacks Default value is 60 seconds
Transport Layer 3-105
SomeTCP Parameters in Linux Kerneltcp_rmem
This is a vector of 3 integers [min default max] These parameters are used by TCP to dynamically adjust receive buffer sizesmin - minimum size of the receive buffer used by each TCP socket The default value is 4K default - the default size of the receive buffer for a TCP socket The default value is 87380 bytes and is lowered to 43689 in low memory systems If larger receive buffer sizes are desired this value should be increased max - the maximum size of the receive buffer used by each TCP socket The default value of 873802 bytes is lowered to 87380 in low memory systems
tcp_smemSend buffer parameters [min default max] similar to tcp_rmem
- Chapter 3 Transport Layer
- Transport services and protocols
- Transport vs network layer
- Internet transport-layer protocols
- Multiplexingdemultiplexing
- How demultiplexing works
- Connectionless demultiplexing
- Connection-oriented demux
- Connection-oriented demux (cont)
- Connection-oriented demux Threaded Web Server
- UDP User Datagram Protocol [RFC 768]
- UDP more
- UDP checksum
- Principles of Reliable data transfer
- Reliable data transfer getting started
- Reliable data transfer getting started
- Rdt10 reliable transfer over a reliable channel
- Rdt20 channel with bit errors
- rdt20 FSM specification
- rdt20 operation with no errors
- rdt20 error scenario
- rdt20 has a fatal flaw
- rdt21 sender handles garbled ACKNAKs
- rdt21 receiver handles garbled ACKNAKs
- rdt21 discussion
- rdt22 a NAK-free protocol
- rdt22 sender receiver fragments
- rdt30 channels with errors and loss
- rdt30 sender
- rdt30 in action
- rdt30 in action
- Performance of rdt30
- rdt30 stop-and-wait operation
- Pipelined protocols
- Pipelining increased utilization
- Go-Back-N
- GBN sender extended FSM
- GBN receiver extended FSM
- GBN inaction
- Selective Repeat
- Selective repeat sender receiver windows
- Selective repeat
- Selective repeat in action
- Selective repeat dilemma
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- TCP Overview RFCs 793 1122 1323 2018 2581
- TCP segment structure
- TCP seq rsquos and ACKs
- TCP Round Trip Time and Timeout
- TCP Round Trip Time and Timeout
- Example RTT estimation
- TCP Round Trip Time and Timeout
- TCP reliable data transfer
- TCP sender events
- TCP sender(simplified)
- TCP retransmission scenarios
- TCP retransmission scenarios (more)
- TCP ACK generation [RFC 1122 RFC 2581]
- Fast Retransmit
- Fast Retransmit
- Fast retransmit algorithm
- TCP Flow Control
- TCP Flow control how it works
- Sliding Window Flow Control Example
- Principles of Congestion Control
- Causescosts of congestion scenario 1
- Causescosts of congestion scenario 2
- Causescosts of congestion scenario 2
- Causescosts of congestion scenario 3
- Causescosts of congestion scenario 3
- Approaches towards congestion control
- TCP Congestion Control
- TCP congestion control bandwidth probing
- TCP Congestion Control details
- TCP Congestion Control more details
- TCP Slow Start Phase
- Slow Start Example
- TCP Congestion Avoidance Phase
- Congestion Avoidance
- Example Slow StartCongestion Avoidance
- Slow Start Congestion Avoidance
- Responses to Congestion
- Fast Recovery (differentiation btwn two loss events)
- TCP Congestion Control
- Popular ldquoflavorsrdquo of TCP
- Summary TCP Congestion Control
- TCP Congestion Control Summary
- TCP throughput
- TCP Futures TCP over ldquolong fat pipesrdquo
- TCP Fairness
- Why is TCP fair
- Fairness (more)
- TCP Connection Management
- TCP Connection Management (cont)
- TCP Connection Management (cont)
- TCP Connection Management (cont)
- Tuning TCPIP Parameters
- SomeTCP Parameters in Linux Kernel
- SomeTCP Parameters in Linux Kernel
-
Transport Layer 3-60
TCP sender eventsdata rcvd from app
Create segment with seq seq is byte-stream number of first data byte in segmentstart timer if not already running (think of timer as for oldest unacked segment)expiration interval TimeOutInterval
timeoutretransmit segment that caused timeout (first segment in the window)restart timer
Ack rcvdIf acknowledges previously unacked segments
update what is known to be ackedstart timer if there are outstanding segments
Transport Layer 3-61
TCP sender(simplified)
NextSeqNum = InitialSeqNumSendBase = InitialSeqNum
loop (forever) switch(event)
event data received from application above create TCP segment with sequence number NextSeqNumif (timer currently not running)
start timerpass segment to IP NextSeqNum = NextSeqNum + length(data)
event timer timeoutretransmit not-yet-acknowledged segment with
smallest sequence numberstart timer
event ACK received with ACK field value of y if (y gt SendBase)
SendBase = yif (there are currently not-yet-acknowledged segments)
start timer
end of loop forever
Commentbull SendBase-1 last cumulatively ackrsquoed byteExamplebull SendBase-1 = 71y= 73 so the rcvrwants 73+ y gt SendBase sothat new data is acked
Transport Layer 3-62
TCP retransmission scenariosHost A
Seq=100 20 bytes data
ACK=100
timepremature timeout
Host B
Seq=92 8 bytes data
ACK=120
Seq=92 8 bytes data
Seq=
92 t
imeo
ut
ACK=120
Host A
Seq=92 8 bytes data
ACK=100
loss
tim
eout
lost ACK scenario
Host B
X
Seq=92 8 bytes data
ACK=100
time
Seq=
92 t
imeo
utSendBase
= 100
SendBase= 120
SendBase= 120
Sendbase= 100
Transport Layer 3-63
TCP retransmission scenarios (more)Host A
Seq=92 8 bytes data
ACK=100
loss
tim
eout
Cumulative ACK scenario
Host B
X
Seq=100 20 bytes data
ACK=120
time
SendBase= 120
Transport Layer 3-64
TCP ACK generation [RFC 1122 RFC 2581]
Event at Receiver
Arrival of in-order segment withexpected seq All data up toexpected seq already ACKed
Arrival of in-order segment withexpected seq One other segment has ACK pending
Arrival of out-of-order segmenthigher-than-expect seq Gap detected
Arrival of segment that partially or completely fills gap
TCP Receiver action
Delayed ACK Wait up to 500msfor next segment If no next segmentsend ACK
Immediately send single cumulative ACK ACKing both in-order segments
Immediately send duplicate ACK indicating seq of next expected byte
Immediate send ACK provided thatsegment startsat lower end of gap
Transport Layer 3-65
Fast Retransmit
Time-out period often relatively long
long delay before resending lost packet
Detect lost segments via duplicate ACKs
Sender often sends many segments back-to-backIf segment is lost there will likely be many duplicate ACKs
If sender receives 3 ACKs for the same data it supposes that segment after ACKeddata was lost
fast retransmit resend segment before timer expires
Transport Layer 3-66
Fast RetransmitResend a segment after 3 duplicate ACKs since a duplicate ACK means that an out-of sequence segment was receivedduplicate ACKs due to packet reorderingif window is small donrsquot get duplicate ACKs
Host A
tim
eout
Host B
time
X
resend seq X2
seq x1seq x2seq x3seq x4seq x5
ACK x1
ACK x1ACK x1ACK x1
tripleduplicate
ACKs
Transport Layer 3-67
event ACK received with ACK field value of y if (y gt SendBase)
SendBase = yif (there are currently not-yet-acknowledged segments)
start timer
else increment count of dup ACKs received for yif (count of dup ACKs received for y = 3)
resend segment with sequence number y
Fast retransmit algorithm
a duplicate ACK for already ACKed segment
fast retransmit
Transport Layer 3-68
TCP Flow Control
receive side of TCP connection has a receive buffer
speed-matching service matching the send rate to the receiving apprsquos drain rate
app process may be slow at reading from buffer
sender wonrsquot overflowreceiverrsquos buffer by
transmitting too muchtoo fast
flow control
Transport Layer 3-69
TCP Flow control how it works
(Suppose TCP receiver discards out-of-order segments)spare room in buffer
= RcvWin
= RcvBuffer-[LastByteRcvd -LastByteRead]
Rcvr advertises spare room by including value of RcvWin in segmentsSender limits unACKeddata to RcvWin
guarantees receive buffer doesnrsquot overflow
Transport Layer 3-70
Sliding Window Flow Control Example
3K
2K SeqNo=0
ReceiverBuffer
0 4KSendersends 2Kof data
2K
AckNo=2048 RcvWin=2048Sendersends 2Kof data 2K SeqNo=2048
4K
AckNo=4096 RcvWin=0
AckNo=4096 RcvWin=1024
Sender blocked
Transport Layer 3-71
Principles of Congestion Control
Congestioninformally ldquotoo many sources sending too much data too fast for network to handlerdquodifferent from flow controlmanifestations
lost packets (buffer overflow at routers)long delays (queueing in router buffers)
a top-10 problem
Transport Layer 3-72
Causescosts of congestion scenario 1
two senders two receiversone router infinite buffers no retransmission
large delays when congestedmaximum achievable throughput
unlimited shared output link buffers
Host Aλin original data
Host B
λout
Transport Layer 3-73
Causescosts of congestion scenario 2
one router finite buffers sender retransmission of lost packet
finite shared output link buffers
Host A λin original data
Host B
λout
λin original data plus retransmitted data
Transport Layer 3-74
Causescosts of congestion scenario 2always (goodput)ldquoperfectrdquo retransmission only when loss
retransmission of delayed (not lost) packet makes larger(than perfect case) for same
λin
λout=
λin
λoutgtλ
inλout
ldquocostsrdquo of congestionmore work (retrans) for given ldquogoodputrdquounneeded retransmissions link carries multiple copies of pkt
R2
R2λin
λ out
b
R2
R2λin
λ out
a
R2
R2λin
λ out
c
R4
R3
Transport Layer 3-75
Causescosts of congestion scenario 3four sendersmultihop pathstimeoutretransmit
λin
Q what happens as and increase λ
in
finite shared output link buffers
Host Aλin original data
Host B
λout
λin original data plus retransmitted data
Transport Layer 3-76
Causescosts of congestion scenario 3
another ldquocostrdquo of congestionwhen packet dropped any ldquoupstream transmission capacity used for that packet was wasted
Host A
Host B
λou
t
Transport Layer 3-77
Approaches towards congestion control
End-end congestion controlno explicit feedback from networkcongestion inferred from end-system observed loss delayapproach taken by TCP
Network-assisted congestion controlrouters provide feedback to end systems
single bit indicating congestion (SNA DECbit TCPIP ECN ATM)explicit rate sender should send at
Two broad approaches towards congestion control
Transport Layer 3-78
TCP Congestion Control
end-end control (no network assistance)sender limits transmissionLastByteSent-LastByteAcked
le CongWin
CongWin is dynamic function of perceived network congestion
How does sender perceive congestionloss event = timeout or3 duplicate acksTCP sender reduces rate (CongWin) after loss event
two modes of operationSlow Start (SS)Congestion avoidance (CA) or Additive Increase Multiplicative Decrease (AIMD)
Transport Layer 3-79
TCP congestion control bandwidth probing
ldquoprobing for bandwidthrdquo increase transmission rate on receipt of ACK until eventually loss occurs then decrease transmission rate
continue to increase on ACK decrease on loss (since available bandwidth is changing depending on other connections in network)
ACKs being received so increase rate
X
X
XX
X loss so decrease rate
send
ing
rate
time
Q how fast to increasedecreasedetails to follow
TCPrsquosldquosawtoothrdquobehavior
Transport Layer 3-80
TCP Congestion Control details
sender limits rate by limiting number of unACKed bytes ldquoin pipelinerdquo
cwnd differs from rwnd (how why)sender limited by min(cwndrwnd)
roughly
cwnd is dynamic function of perceived network congestion
rate = cwndRTT bytessec
LastByteSent-LastByteAcked le cwnd
cwndbytes
RTT
ACK(s)
Transport Layer 3-81
TCP Congestion Control more details
segment loss event reducing cwndtimeout no response from receiver
cut cwnd to 13 duplicate ACKs at least some segments getting through (recall fast retransmit)
cut cwnd in half less aggressively than on timeout
ACK received increase cwndTwo modes of operation
slowstart phase bull increase exponentially
fast (despite name) at connection start or following timeout
congestion avoidance bull increase linearly
Transport Layer 3-82
TCP Slow Start Phasewhen connection begins cwnd = 1 MSS
example MSS = 500 bytes amp RTT = 200 msecinitial rate = 20 kbps
available bandwidth may be gtgt MSSRTT
desirable to quickly ramp up to respectable rate
increase rate exponentially until first loss event or when threshold reached
double cwnd every RTTdone by incrementing cwnd by 1 for every ACK received
Host A
one segment
RTT
Host B
time
two segments
four segments
Transport Layer 3-83
Slow Start ExampleThe congestion window size grows very rapidly
For every ACK we increase CongWin by 1 irrespective of the number of segments ACKrsquoeddouble CongWinevery RTTinitial rate is slow but ramps up exponentially fast
TCP slows down the increase of CongWinwhen CongWin gt ssthresh
segment 1
ACK for segment 1
cwnd = 1
cwnd = 2 segment 2segment 3
ACK for segments 2
cwnd = 4 segment 4segment 5segment 6
ACK for segments 4
cwnd = 7
ACK for segments 3
ACK for segments 5
ACK for segments 6
cwnd = 3
cwnd = 5
cwnd = 6ACK for segments 7
cwnd = 8
segment 7
Transport Layer 3-84
TCP Congestion Avoidance Phase
when cwnd gt ssthreshgrow cwnd linearly
increase cwnd by 1 MSS per RTT approach possible congestion slower than in slowstartimplementation cwnd= cwnd + MSScwndfor each ACK received
ACKs increase cwndby 1 MSS per RTT additive increaseloss cut cwnd in half (non-timeout-detected loss ) multiplicative decrease
AIMD
AIMD Additive IncreaseMultiplicative Decrease
Transport Layer 3-85
Congestion AvoidanceCongestion avoidance phase is started if CongWin has reached the slow-start threshold value
If CongWin gt= ssthresh then each time an ACK is received increment CongWin as follows
bull CongWin = CongWin + 1CongWin (CongWin in segments)
bull In actual TCP implementation CongWin is in BytesCongWin = CongWin + MSS (MSSCongWin)
So CongWin is increased by one only if all CongWinsegments have been acknowledged
Transport Layer 3-86
Example Slow StartCongestion AvoidanceAssume that
ssthresh = 8
cwnd = 1
cwnd = 2
cwnd = 4
cwnd = 8
cwnd = 9
cwnd = 10
02468
101214
t=0
t=2
t=4
t=6
Roundtrip times
Cw
nd(in
seg
men
ts)
ssthresh
cwnd = 3
cwnd = 5cwnd = 6cwnd = 7
Transport Layer 3-87
Slow Start Congestion AvoidanceA typical plot of CongWin for a TCP connection
(MSS = 1500 bytes) with TCP Tahoe
SS
CA
ssthresh
Transport Layer 3-88
Responses to CongestionTCP assumes there is congestion if it detects a packet lossA TCP sender can detect lost packets via loss events
bull Timeout of a retransmission timerbull Receipt of 3 duplicate ACKs (fast retransmit)
TCP interprets a Timeout as a binary congestion signal When a timeout occurs the sender performs
ssthresh is set to half the current size of the congestion window
ssthresh = CongWin 2CongWin is reset to one
CongWin = 1and slow-start is entered
Transport Layer 3-89
Fast Recovery (differentiation btwn two loss events) After 3 dup ACKs (fast Retransmit)
ssthresh = CongWin2CongWin = CongWin2window then grows linearly
But after timeout eventCongWin = 1 MSS window then grows exponentiallyto the threshold then grows linearly
bull 3 dup ACKs indicates network capable of delivering some segmentsbull timeout before 3 dup ACKs is ldquomore alarmingrdquo
Philosophy
3-90
TCP Congestion ControlInitially
CongWin = 1ssthresh = advertised window size
New Ack receivedif (CongWin lt ssthresh) Slow Start
CongWin = CongWin + 1else Congestion Avoidance
CongWin = CongWin + 1CongWinTimeout
ssthresh = CongWin2CongWin = 1
Fast Retransmissionssthresh = CongWin2CongWin = CongWin2
Slow Start (exponential increase phase) is continued until CongWin reaches half of the level where the loss event occurred last time CongWin is increased slowly after (linear increase in Congestion Avoidance phase)
Transport Layer 3-91
Popular ldquoflavorsrdquo of TCP
ssthresh
ssthresh
TCP Tahoe
TCP Reno
Transmission round
cwnd
win
dow
siz
e (in
seg
men
ts)
Transport Layer 3-92
Summary TCP Congestion ControlWhen CongWin is below Threshold sender in slow-start phase window grows exponentiallyWhen CongWin is above Threshold sender is in congestion-avoidance phase window grows linearlyWhen a triple duplicate ACK occurs Threshold set to CongWin2 and CongWin set to ThresholdWhen timeout occurs Threshold set to CongWin2 and CongWin is set to 1 MSS The actual sender window size is determined based on the congestion and flow control algorithms
SenderWin=min(RcvWinCongWin)
Transport Layer 3-93
TCP Congestion Control SummaryEvent State TCP Sender Action Commentary
ACK receipt for previously unackeddata
Slow Start (SS)
CongWin = CongWin + MSS If (CongWin gt Threshold)
set state to ldquoCongestion Avoidancerdquo
Resulting in a doubling of CongWin every RTT
ACK receipt for previously unackeddata
CongestionAvoidance (CA)
CongWin = CongWin+MSS (MSSCongWin)
Additive increase resulting in increase of CongWin by 1 MSS every RTT
Loss event detected by triple duplicate ACK
SS or CA Threshold = CongWin2 CongWin = ThresholdSet state to ldquoCongestion Avoidancerdquo
Fast recovery implementing multiplicative decrease CongWin will not drop below 1 MSS
Timeout SS or CA Threshold = CongWin2 CongWin = 1 MSSSet state to ldquoSlow Startrdquo
Enter slow start
Duplicate ACK
SS or CA Increment duplicate ACK count for segment being acked
CongWin and Threshold not changed
Transport Layer 3-94
TCP throughput
Q whatrsquos average throughout of TCP as function of window size RTT
ignoring slow startlet W be window size when loss occurs
when window is W throughput is WRTTjust after loss window drops to W2 throughput to W2RTT average throughout 75 WRTT
Transport Layer 3-95
TCP Futures TCP over ldquolong fat pipesrdquo
example 1500 byte segments 100ms RTT want 10 Gbps throughputrequires window size W = 83333 in-flight segmentsthroughput in terms of loss rate
L = 210-10 Wownew versions of TCP for high-speed
LRTTMSSsdot221
Transport Layer 3-96
Fairness goal if K TCP sessions share same bottleneck link of bandwidth R each should have average rate of RK
TCP connection 1
bottleneckrouter
capacity R
TCP connection 2
TCP Fairness
Transport Layer 3-97
Why is TCP fairTwo competing sessions
Additive increase gives slope of 1 as throughout increasesmultiplicative decrease decreases throughput proportionally
R
R
equal bandwidth share
Connection 1 throughput
Conn
ecti
on 2
thr
ough
p ut
congestion avoidance additive increaseloss decrease window by factor of 2
congestion avoidance additive increaseloss decrease window by factor of 2
Transport Layer 3-98
Fairness (more)Fairness and UDP
Multimedia apps often do not use TCP
do not want rate throttled by congestion control
Instead use UDPpump audiovideo at constant rate tolerate packet loss
Research area TCP friendly
Fairness and parallel TCP connectionsnothing prevents app from opening parallel cnctionsbetween 2 hostsWeb browsers do this Example link of rate R supporting 9 cnctions
new app asks for 1 TCP gets rate R10new app asks for 11 TCPs gets R2
Transport Layer 3-99
TCP Connection ManagementRecall TCP sender receiver
establish ldquoconnectionrdquobefore exchanging data segmentsinitialize TCP variables
seq sbuffers flow control info (eg RcvWindow)
client connection initiatorSocket clientSocket = new Socket(hostnameport
number)
server contacted by clientSocket connectionSocket = welcomeSocketaccept()
Three way handshakeStep 1 client host sends TCP
SYN segment to serverspecifies initial seq no data
Step 2 server host receives SYN replies with SYNACK segment
server allocates buffersspecifies server initial seq
Step 3 client receives SYNACK replies with ACK segment which may contain data
Transport Layer 3-100
TCP Connection Management (cont)
Closing a connection
client closes socketclientSocketclose()
Step 1 client end system sends TCP FIN control segment to server
Step 2 server receives FIN replies with ACK Closes connection sends FIN
client
FIN
server
ACK
ACK
FIN
close
close
closed
tim
ed w
ait
Transport Layer 3-101
TCP Connection Management (cont)
Step 3 client receives FIN replies with ACK
Enters ldquotimed waitrdquo -will respond with ACK to received FINs
Step 4 server receives ACK Connection closed
client
FIN
server
ACK
ACK
FIN
closing
closing
closed
tim
ed w
ait
closed
Transport Layer 3-102
TCP Connection Management (cont)
TCP clientlifecycle
TCP serverlifecycle
Transport Layer 3-103
Tuning TCPIP Parameters TCPIP parameters
A set of default values may not be optimal for all applicationsThe network administrator may wish to turn on or off some TCPIP functions for performance or security considerations
Many Unix and Linux systems provide some flexibility in tuning the TCPIP kernelsbinsysctl is used to configure the Linux kernel parameters at runtime
Default kernel configuration file is sbinsysctlconfFrequently used sysctl options
bull sysctl ndasha or sysctl ndashA list all current valuesbull sysctl ndashp file_name load the sysctl setting from a configuration
filebull sysctl ndashw variable=value change the value of the parameter
Transport Layer 3-104
SomeTCP Parameters in Linux Kerneltcp_syn_retries
Number of SYN packets the kernel will send before giving up on the new connection
tcp_synack_retriesnumber of SYN+ACK packets sent before the kernel gives up on the connection
tcp_window_scalingMaximum window size of 65535 bytes not enough for for really fast networks The window scaling options allows for almost gigabyte windows which is good for connections with large delay-bandwidth product
tcp_max_syn_backlogMaximal number of remembered connection requests which still did not receive an acknowledgment from connecting client
tcp_fin_timeoutHow many seconds to wait for a final FIN packet before the socket is closed required to prevent denial-of-service (DoS) attacks Default value is 60 seconds
Transport Layer 3-105
SomeTCP Parameters in Linux Kerneltcp_rmem
This is a vector of 3 integers [min default max] These parameters are used by TCP to dynamically adjust receive buffer sizesmin - minimum size of the receive buffer used by each TCP socket The default value is 4K default - the default size of the receive buffer for a TCP socket The default value is 87380 bytes and is lowered to 43689 in low memory systems If larger receive buffer sizes are desired this value should be increased max - the maximum size of the receive buffer used by each TCP socket The default value of 873802 bytes is lowered to 87380 in low memory systems
tcp_smemSend buffer parameters [min default max] similar to tcp_rmem
- Chapter 3 Transport Layer
- Transport services and protocols
- Transport vs network layer
- Internet transport-layer protocols
- Multiplexingdemultiplexing
- How demultiplexing works
- Connectionless demultiplexing
- Connection-oriented demux
- Connection-oriented demux (cont)
- Connection-oriented demux Threaded Web Server
- UDP User Datagram Protocol [RFC 768]
- UDP more
- UDP checksum
- Principles of Reliable data transfer
- Reliable data transfer getting started
- Reliable data transfer getting started
- Rdt10 reliable transfer over a reliable channel
- Rdt20 channel with bit errors
- rdt20 FSM specification
- rdt20 operation with no errors
- rdt20 error scenario
- rdt20 has a fatal flaw
- rdt21 sender handles garbled ACKNAKs
- rdt21 receiver handles garbled ACKNAKs
- rdt21 discussion
- rdt22 a NAK-free protocol
- rdt22 sender receiver fragments
- rdt30 channels with errors and loss
- rdt30 sender
- rdt30 in action
- rdt30 in action
- Performance of rdt30
- rdt30 stop-and-wait operation
- Pipelined protocols
- Pipelining increased utilization
- Go-Back-N
- GBN sender extended FSM
- GBN receiver extended FSM
- GBN inaction
- Selective Repeat
- Selective repeat sender receiver windows
- Selective repeat
- Selective repeat in action
- Selective repeat dilemma
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- TCP Overview RFCs 793 1122 1323 2018 2581
- TCP segment structure
- TCP seq rsquos and ACKs
- TCP Round Trip Time and Timeout
- TCP Round Trip Time and Timeout
- Example RTT estimation
- TCP Round Trip Time and Timeout
- TCP reliable data transfer
- TCP sender events
- TCP sender(simplified)
- TCP retransmission scenarios
- TCP retransmission scenarios (more)
- TCP ACK generation [RFC 1122 RFC 2581]
- Fast Retransmit
- Fast Retransmit
- Fast retransmit algorithm
- TCP Flow Control
- TCP Flow control how it works
- Sliding Window Flow Control Example
- Principles of Congestion Control
- Causescosts of congestion scenario 1
- Causescosts of congestion scenario 2
- Causescosts of congestion scenario 2
- Causescosts of congestion scenario 3
- Causescosts of congestion scenario 3
- Approaches towards congestion control
- TCP Congestion Control
- TCP congestion control bandwidth probing
- TCP Congestion Control details
- TCP Congestion Control more details
- TCP Slow Start Phase
- Slow Start Example
- TCP Congestion Avoidance Phase
- Congestion Avoidance
- Example Slow StartCongestion Avoidance
- Slow Start Congestion Avoidance
- Responses to Congestion
- Fast Recovery (differentiation btwn two loss events)
- TCP Congestion Control
- Popular ldquoflavorsrdquo of TCP
- Summary TCP Congestion Control
- TCP Congestion Control Summary
- TCP throughput
- TCP Futures TCP over ldquolong fat pipesrdquo
- TCP Fairness
- Why is TCP fair
- Fairness (more)
- TCP Connection Management
- TCP Connection Management (cont)
- TCP Connection Management (cont)
- TCP Connection Management (cont)
- Tuning TCPIP Parameters
- SomeTCP Parameters in Linux Kernel
- SomeTCP Parameters in Linux Kernel
-
Transport Layer 3-61
TCP sender(simplified)
NextSeqNum = InitialSeqNumSendBase = InitialSeqNum
loop (forever) switch(event)
event data received from application above create TCP segment with sequence number NextSeqNumif (timer currently not running)
start timerpass segment to IP NextSeqNum = NextSeqNum + length(data)
event timer timeoutretransmit not-yet-acknowledged segment with
smallest sequence numberstart timer
event ACK received with ACK field value of y if (y gt SendBase)
SendBase = yif (there are currently not-yet-acknowledged segments)
start timer
end of loop forever
Commentbull SendBase-1 last cumulatively ackrsquoed byteExamplebull SendBase-1 = 71y= 73 so the rcvrwants 73+ y gt SendBase sothat new data is acked
Transport Layer 3-62
TCP retransmission scenariosHost A
Seq=100 20 bytes data
ACK=100
timepremature timeout
Host B
Seq=92 8 bytes data
ACK=120
Seq=92 8 bytes data
Seq=
92 t
imeo
ut
ACK=120
Host A
Seq=92 8 bytes data
ACK=100
loss
tim
eout
lost ACK scenario
Host B
X
Seq=92 8 bytes data
ACK=100
time
Seq=
92 t
imeo
utSendBase
= 100
SendBase= 120
SendBase= 120
Sendbase= 100
Transport Layer 3-63
TCP retransmission scenarios (more)Host A
Seq=92 8 bytes data
ACK=100
loss
tim
eout
Cumulative ACK scenario
Host B
X
Seq=100 20 bytes data
ACK=120
time
SendBase= 120
Transport Layer 3-64
TCP ACK generation [RFC 1122 RFC 2581]
Event at Receiver
Arrival of in-order segment withexpected seq All data up toexpected seq already ACKed
Arrival of in-order segment withexpected seq One other segment has ACK pending
Arrival of out-of-order segmenthigher-than-expect seq Gap detected
Arrival of segment that partially or completely fills gap
TCP Receiver action
Delayed ACK Wait up to 500msfor next segment If no next segmentsend ACK
Immediately send single cumulative ACK ACKing both in-order segments
Immediately send duplicate ACK indicating seq of next expected byte
Immediate send ACK provided thatsegment startsat lower end of gap
Transport Layer 3-65
Fast Retransmit
Time-out period often relatively long
long delay before resending lost packet
Detect lost segments via duplicate ACKs
Sender often sends many segments back-to-backIf segment is lost there will likely be many duplicate ACKs
If sender receives 3 ACKs for the same data it supposes that segment after ACKeddata was lost
fast retransmit resend segment before timer expires
Transport Layer 3-66
Fast RetransmitResend a segment after 3 duplicate ACKs since a duplicate ACK means that an out-of sequence segment was receivedduplicate ACKs due to packet reorderingif window is small donrsquot get duplicate ACKs
Host A
tim
eout
Host B
time
X
resend seq X2
seq x1seq x2seq x3seq x4seq x5
ACK x1
ACK x1ACK x1ACK x1
tripleduplicate
ACKs
Transport Layer 3-67
event ACK received with ACK field value of y if (y gt SendBase)
SendBase = yif (there are currently not-yet-acknowledged segments)
start timer
else increment count of dup ACKs received for yif (count of dup ACKs received for y = 3)
resend segment with sequence number y
Fast retransmit algorithm
a duplicate ACK for already ACKed segment
fast retransmit
Transport Layer 3-68
TCP Flow Control
receive side of TCP connection has a receive buffer
speed-matching service matching the send rate to the receiving apprsquos drain rate
app process may be slow at reading from buffer
sender wonrsquot overflowreceiverrsquos buffer by
transmitting too muchtoo fast
flow control
Transport Layer 3-69
TCP Flow control how it works
(Suppose TCP receiver discards out-of-order segments)spare room in buffer
= RcvWin
= RcvBuffer-[LastByteRcvd -LastByteRead]
Rcvr advertises spare room by including value of RcvWin in segmentsSender limits unACKeddata to RcvWin
guarantees receive buffer doesnrsquot overflow
Transport Layer 3-70
Sliding Window Flow Control Example
3K
2K SeqNo=0
ReceiverBuffer
0 4KSendersends 2Kof data
2K
AckNo=2048 RcvWin=2048Sendersends 2Kof data 2K SeqNo=2048
4K
AckNo=4096 RcvWin=0
AckNo=4096 RcvWin=1024
Sender blocked
Transport Layer 3-71
Principles of Congestion Control
Congestioninformally ldquotoo many sources sending too much data too fast for network to handlerdquodifferent from flow controlmanifestations
lost packets (buffer overflow at routers)long delays (queueing in router buffers)
a top-10 problem
Transport Layer 3-72
Causescosts of congestion scenario 1
two senders two receiversone router infinite buffers no retransmission
large delays when congestedmaximum achievable throughput
unlimited shared output link buffers
Host Aλin original data
Host B
λout
Transport Layer 3-73
Causescosts of congestion scenario 2
one router finite buffers sender retransmission of lost packet
finite shared output link buffers
Host A λin original data
Host B
λout
λin original data plus retransmitted data
Transport Layer 3-74
Causescosts of congestion scenario 2always (goodput)ldquoperfectrdquo retransmission only when loss
retransmission of delayed (not lost) packet makes larger(than perfect case) for same
λin
λout=
λin
λoutgtλ
inλout
ldquocostsrdquo of congestionmore work (retrans) for given ldquogoodputrdquounneeded retransmissions link carries multiple copies of pkt
R2
R2λin
λ out
b
R2
R2λin
λ out
a
R2
R2λin
λ out
c
R4
R3
Transport Layer 3-75
Causescosts of congestion scenario 3four sendersmultihop pathstimeoutretransmit
λin
Q what happens as and increase λ
in
finite shared output link buffers
Host Aλin original data
Host B
λout
λin original data plus retransmitted data
Transport Layer 3-76
Causescosts of congestion scenario 3
another ldquocostrdquo of congestionwhen packet dropped any ldquoupstream transmission capacity used for that packet was wasted
Host A
Host B
λou
t
Transport Layer 3-77
Approaches towards congestion control
End-end congestion controlno explicit feedback from networkcongestion inferred from end-system observed loss delayapproach taken by TCP
Network-assisted congestion controlrouters provide feedback to end systems
single bit indicating congestion (SNA DECbit TCPIP ECN ATM)explicit rate sender should send at
Two broad approaches towards congestion control
Transport Layer 3-78
TCP Congestion Control
end-end control (no network assistance)sender limits transmissionLastByteSent-LastByteAcked
le CongWin
CongWin is dynamic function of perceived network congestion
How does sender perceive congestionloss event = timeout or3 duplicate acksTCP sender reduces rate (CongWin) after loss event
two modes of operationSlow Start (SS)Congestion avoidance (CA) or Additive Increase Multiplicative Decrease (AIMD)
Transport Layer 3-79
TCP congestion control bandwidth probing
ldquoprobing for bandwidthrdquo increase transmission rate on receipt of ACK until eventually loss occurs then decrease transmission rate
continue to increase on ACK decrease on loss (since available bandwidth is changing depending on other connections in network)
ACKs being received so increase rate
X
X
XX
X loss so decrease rate
send
ing
rate
time
Q how fast to increasedecreasedetails to follow
TCPrsquosldquosawtoothrdquobehavior
Transport Layer 3-80
TCP Congestion Control details
sender limits rate by limiting number of unACKed bytes ldquoin pipelinerdquo
cwnd differs from rwnd (how why)sender limited by min(cwndrwnd)
roughly
cwnd is dynamic function of perceived network congestion
rate = cwndRTT bytessec
LastByteSent-LastByteAcked le cwnd
cwndbytes
RTT
ACK(s)
Transport Layer 3-81
TCP Congestion Control more details
segment loss event reducing cwndtimeout no response from receiver
cut cwnd to 13 duplicate ACKs at least some segments getting through (recall fast retransmit)
cut cwnd in half less aggressively than on timeout
ACK received increase cwndTwo modes of operation
slowstart phase bull increase exponentially
fast (despite name) at connection start or following timeout
congestion avoidance bull increase linearly
Transport Layer 3-82
TCP Slow Start Phasewhen connection begins cwnd = 1 MSS
example MSS = 500 bytes amp RTT = 200 msecinitial rate = 20 kbps
available bandwidth may be gtgt MSSRTT
desirable to quickly ramp up to respectable rate
increase rate exponentially until first loss event or when threshold reached
double cwnd every RTTdone by incrementing cwnd by 1 for every ACK received
Host A
one segment
RTT
Host B
time
two segments
four segments
Transport Layer 3-83
Slow Start ExampleThe congestion window size grows very rapidly
For every ACK we increase CongWin by 1 irrespective of the number of segments ACKrsquoeddouble CongWinevery RTTinitial rate is slow but ramps up exponentially fast
TCP slows down the increase of CongWinwhen CongWin gt ssthresh
segment 1
ACK for segment 1
cwnd = 1
cwnd = 2 segment 2segment 3
ACK for segments 2
cwnd = 4 segment 4segment 5segment 6
ACK for segments 4
cwnd = 7
ACK for segments 3
ACK for segments 5
ACK for segments 6
cwnd = 3
cwnd = 5
cwnd = 6ACK for segments 7
cwnd = 8
segment 7
Transport Layer 3-84
TCP Congestion Avoidance Phase
when cwnd gt ssthreshgrow cwnd linearly
increase cwnd by 1 MSS per RTT approach possible congestion slower than in slowstartimplementation cwnd= cwnd + MSScwndfor each ACK received
ACKs increase cwndby 1 MSS per RTT additive increaseloss cut cwnd in half (non-timeout-detected loss ) multiplicative decrease
AIMD
AIMD Additive IncreaseMultiplicative Decrease
Transport Layer 3-85
Congestion AvoidanceCongestion avoidance phase is started if CongWin has reached the slow-start threshold value
If CongWin gt= ssthresh then each time an ACK is received increment CongWin as follows
bull CongWin = CongWin + 1CongWin (CongWin in segments)
bull In actual TCP implementation CongWin is in BytesCongWin = CongWin + MSS (MSSCongWin)
So CongWin is increased by one only if all CongWinsegments have been acknowledged
Transport Layer 3-86
Example Slow StartCongestion AvoidanceAssume that
ssthresh = 8
cwnd = 1
cwnd = 2
cwnd = 4
cwnd = 8
cwnd = 9
cwnd = 10
02468
101214
t=0
t=2
t=4
t=6
Roundtrip times
Cw
nd(in
seg
men
ts)
ssthresh
cwnd = 3
cwnd = 5cwnd = 6cwnd = 7
Transport Layer 3-87
Slow Start Congestion AvoidanceA typical plot of CongWin for a TCP connection
(MSS = 1500 bytes) with TCP Tahoe
SS
CA
ssthresh
Transport Layer 3-88
Responses to CongestionTCP assumes there is congestion if it detects a packet lossA TCP sender can detect lost packets via loss events
bull Timeout of a retransmission timerbull Receipt of 3 duplicate ACKs (fast retransmit)
TCP interprets a Timeout as a binary congestion signal When a timeout occurs the sender performs
ssthresh is set to half the current size of the congestion window
ssthresh = CongWin 2CongWin is reset to one
CongWin = 1and slow-start is entered
Transport Layer 3-89
Fast Recovery (differentiation btwn two loss events) After 3 dup ACKs (fast Retransmit)
ssthresh = CongWin2CongWin = CongWin2window then grows linearly
But after timeout eventCongWin = 1 MSS window then grows exponentiallyto the threshold then grows linearly
bull 3 dup ACKs indicates network capable of delivering some segmentsbull timeout before 3 dup ACKs is ldquomore alarmingrdquo
Philosophy
3-90
TCP Congestion ControlInitially
CongWin = 1ssthresh = advertised window size
New Ack receivedif (CongWin lt ssthresh) Slow Start
CongWin = CongWin + 1else Congestion Avoidance
CongWin = CongWin + 1CongWinTimeout
ssthresh = CongWin2CongWin = 1
Fast Retransmissionssthresh = CongWin2CongWin = CongWin2
Slow Start (exponential increase phase) is continued until CongWin reaches half of the level where the loss event occurred last time CongWin is increased slowly after (linear increase in Congestion Avoidance phase)
Transport Layer 3-91
Popular ldquoflavorsrdquo of TCP
ssthresh
ssthresh
TCP Tahoe
TCP Reno
Transmission round
cwnd
win
dow
siz
e (in
seg
men
ts)
Transport Layer 3-92
Summary TCP Congestion ControlWhen CongWin is below Threshold sender in slow-start phase window grows exponentiallyWhen CongWin is above Threshold sender is in congestion-avoidance phase window grows linearlyWhen a triple duplicate ACK occurs Threshold set to CongWin2 and CongWin set to ThresholdWhen timeout occurs Threshold set to CongWin2 and CongWin is set to 1 MSS The actual sender window size is determined based on the congestion and flow control algorithms
SenderWin=min(RcvWinCongWin)
Transport Layer 3-93
TCP Congestion Control SummaryEvent State TCP Sender Action Commentary
ACK receipt for previously unackeddata
Slow Start (SS)
CongWin = CongWin + MSS If (CongWin gt Threshold)
set state to ldquoCongestion Avoidancerdquo
Resulting in a doubling of CongWin every RTT
ACK receipt for previously unackeddata
CongestionAvoidance (CA)
CongWin = CongWin+MSS (MSSCongWin)
Additive increase resulting in increase of CongWin by 1 MSS every RTT
Loss event detected by triple duplicate ACK
SS or CA Threshold = CongWin2 CongWin = ThresholdSet state to ldquoCongestion Avoidancerdquo
Fast recovery implementing multiplicative decrease CongWin will not drop below 1 MSS
Timeout SS or CA Threshold = CongWin2 CongWin = 1 MSSSet state to ldquoSlow Startrdquo
Enter slow start
Duplicate ACK
SS or CA Increment duplicate ACK count for segment being acked
CongWin and Threshold not changed
Transport Layer 3-94
TCP throughput
Q whatrsquos average throughout of TCP as function of window size RTT
ignoring slow startlet W be window size when loss occurs
when window is W throughput is WRTTjust after loss window drops to W2 throughput to W2RTT average throughout 75 WRTT
Transport Layer 3-95
TCP Futures TCP over ldquolong fat pipesrdquo
example 1500 byte segments 100ms RTT want 10 Gbps throughputrequires window size W = 83333 in-flight segmentsthroughput in terms of loss rate
L = 210-10 Wownew versions of TCP for high-speed
LRTTMSSsdot221
Transport Layer 3-96
Fairness goal if K TCP sessions share same bottleneck link of bandwidth R each should have average rate of RK
TCP connection 1
bottleneckrouter
capacity R
TCP connection 2
TCP Fairness
Transport Layer 3-97
Why is TCP fairTwo competing sessions
Additive increase gives slope of 1 as throughout increasesmultiplicative decrease decreases throughput proportionally
R
R
equal bandwidth share
Connection 1 throughput
Conn
ecti
on 2
thr
ough
p ut
congestion avoidance additive increaseloss decrease window by factor of 2
congestion avoidance additive increaseloss decrease window by factor of 2
Transport Layer 3-98
Fairness (more)Fairness and UDP
Multimedia apps often do not use TCP
do not want rate throttled by congestion control
Instead use UDPpump audiovideo at constant rate tolerate packet loss
Research area TCP friendly
Fairness and parallel TCP connectionsnothing prevents app from opening parallel cnctionsbetween 2 hostsWeb browsers do this Example link of rate R supporting 9 cnctions
new app asks for 1 TCP gets rate R10new app asks for 11 TCPs gets R2
Transport Layer 3-99
TCP Connection ManagementRecall TCP sender receiver
establish ldquoconnectionrdquobefore exchanging data segmentsinitialize TCP variables
seq sbuffers flow control info (eg RcvWindow)
client connection initiatorSocket clientSocket = new Socket(hostnameport
number)
server contacted by clientSocket connectionSocket = welcomeSocketaccept()
Three way handshakeStep 1 client host sends TCP
SYN segment to serverspecifies initial seq no data
Step 2 server host receives SYN replies with SYNACK segment
server allocates buffersspecifies server initial seq
Step 3 client receives SYNACK replies with ACK segment which may contain data
Transport Layer 3-100
TCP Connection Management (cont)
Closing a connection
client closes socketclientSocketclose()
Step 1 client end system sends TCP FIN control segment to server
Step 2 server receives FIN replies with ACK Closes connection sends FIN
client
FIN
server
ACK
ACK
FIN
close
close
closed
tim
ed w
ait
Transport Layer 3-101
TCP Connection Management (cont)
Step 3 client receives FIN replies with ACK
Enters ldquotimed waitrdquo -will respond with ACK to received FINs
Step 4 server receives ACK Connection closed
client
FIN
server
ACK
ACK
FIN
closing
closing
closed
tim
ed w
ait
closed
Transport Layer 3-102
TCP Connection Management (cont)
TCP clientlifecycle
TCP serverlifecycle
Transport Layer 3-103
Tuning TCPIP Parameters TCPIP parameters
A set of default values may not be optimal for all applicationsThe network administrator may wish to turn on or off some TCPIP functions for performance or security considerations
Many Unix and Linux systems provide some flexibility in tuning the TCPIP kernelsbinsysctl is used to configure the Linux kernel parameters at runtime
Default kernel configuration file is sbinsysctlconfFrequently used sysctl options
bull sysctl ndasha or sysctl ndashA list all current valuesbull sysctl ndashp file_name load the sysctl setting from a configuration
filebull sysctl ndashw variable=value change the value of the parameter
Transport Layer 3-104
SomeTCP Parameters in Linux Kerneltcp_syn_retries
Number of SYN packets the kernel will send before giving up on the new connection
tcp_synack_retriesnumber of SYN+ACK packets sent before the kernel gives up on the connection
tcp_window_scalingMaximum window size of 65535 bytes not enough for for really fast networks The window scaling options allows for almost gigabyte windows which is good for connections with large delay-bandwidth product
tcp_max_syn_backlogMaximal number of remembered connection requests which still did not receive an acknowledgment from connecting client
tcp_fin_timeoutHow many seconds to wait for a final FIN packet before the socket is closed required to prevent denial-of-service (DoS) attacks Default value is 60 seconds
Transport Layer 3-105
SomeTCP Parameters in Linux Kerneltcp_rmem
This is a vector of 3 integers [min default max] These parameters are used by TCP to dynamically adjust receive buffer sizesmin - minimum size of the receive buffer used by each TCP socket The default value is 4K default - the default size of the receive buffer for a TCP socket The default value is 87380 bytes and is lowered to 43689 in low memory systems If larger receive buffer sizes are desired this value should be increased max - the maximum size of the receive buffer used by each TCP socket The default value of 873802 bytes is lowered to 87380 in low memory systems
tcp_smemSend buffer parameters [min default max] similar to tcp_rmem
- Chapter 3 Transport Layer
- Transport services and protocols
- Transport vs network layer
- Internet transport-layer protocols
- Multiplexingdemultiplexing
- How demultiplexing works
- Connectionless demultiplexing
- Connection-oriented demux
- Connection-oriented demux (cont)
- Connection-oriented demux Threaded Web Server
- UDP User Datagram Protocol [RFC 768]
- UDP more
- UDP checksum
- Principles of Reliable data transfer
- Reliable data transfer getting started
- Reliable data transfer getting started
- Rdt10 reliable transfer over a reliable channel
- Rdt20 channel with bit errors
- rdt20 FSM specification
- rdt20 operation with no errors
- rdt20 error scenario
- rdt20 has a fatal flaw
- rdt21 sender handles garbled ACKNAKs
- rdt21 receiver handles garbled ACKNAKs
- rdt21 discussion
- rdt22 a NAK-free protocol
- rdt22 sender receiver fragments
- rdt30 channels with errors and loss
- rdt30 sender
- rdt30 in action
- rdt30 in action
- Performance of rdt30
- rdt30 stop-and-wait operation
- Pipelined protocols
- Pipelining increased utilization
- Go-Back-N
- GBN sender extended FSM
- GBN receiver extended FSM
- GBN inaction
- Selective Repeat
- Selective repeat sender receiver windows
- Selective repeat
- Selective repeat in action
- Selective repeat dilemma
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- TCP Overview RFCs 793 1122 1323 2018 2581
- TCP segment structure
- TCP seq rsquos and ACKs
- TCP Round Trip Time and Timeout
- TCP Round Trip Time and Timeout
- Example RTT estimation
- TCP Round Trip Time and Timeout
- TCP reliable data transfer
- TCP sender events
- TCP sender(simplified)
- TCP retransmission scenarios
- TCP retransmission scenarios (more)
- TCP ACK generation [RFC 1122 RFC 2581]
- Fast Retransmit
- Fast Retransmit
- Fast retransmit algorithm
- TCP Flow Control
- TCP Flow control how it works
- Sliding Window Flow Control Example
- Principles of Congestion Control
- Causescosts of congestion scenario 1
- Causescosts of congestion scenario 2
- Causescosts of congestion scenario 2
- Causescosts of congestion scenario 3
- Causescosts of congestion scenario 3
- Approaches towards congestion control
- TCP Congestion Control
- TCP congestion control bandwidth probing
- TCP Congestion Control details
- TCP Congestion Control more details
- TCP Slow Start Phase
- Slow Start Example
- TCP Congestion Avoidance Phase
- Congestion Avoidance
- Example Slow StartCongestion Avoidance
- Slow Start Congestion Avoidance
- Responses to Congestion
- Fast Recovery (differentiation btwn two loss events)
- TCP Congestion Control
- Popular ldquoflavorsrdquo of TCP
- Summary TCP Congestion Control
- TCP Congestion Control Summary
- TCP throughput
- TCP Futures TCP over ldquolong fat pipesrdquo
- TCP Fairness
- Why is TCP fair
- Fairness (more)
- TCP Connection Management
- TCP Connection Management (cont)
- TCP Connection Management (cont)
- TCP Connection Management (cont)
- Tuning TCPIP Parameters
- SomeTCP Parameters in Linux Kernel
- SomeTCP Parameters in Linux Kernel
-
Transport Layer 3-62
TCP retransmission scenariosHost A
Seq=100 20 bytes data
ACK=100
timepremature timeout
Host B
Seq=92 8 bytes data
ACK=120
Seq=92 8 bytes data
Seq=
92 t
imeo
ut
ACK=120
Host A
Seq=92 8 bytes data
ACK=100
loss
tim
eout
lost ACK scenario
Host B
X
Seq=92 8 bytes data
ACK=100
time
Seq=
92 t
imeo
utSendBase
= 100
SendBase= 120
SendBase= 120
Sendbase= 100
Transport Layer 3-63
TCP retransmission scenarios (more)Host A
Seq=92 8 bytes data
ACK=100
loss
tim
eout
Cumulative ACK scenario
Host B
X
Seq=100 20 bytes data
ACK=120
time
SendBase= 120
Transport Layer 3-64
TCP ACK generation [RFC 1122 RFC 2581]
Event at Receiver
Arrival of in-order segment withexpected seq All data up toexpected seq already ACKed
Arrival of in-order segment withexpected seq One other segment has ACK pending
Arrival of out-of-order segmenthigher-than-expect seq Gap detected
Arrival of segment that partially or completely fills gap
TCP Receiver action
Delayed ACK Wait up to 500msfor next segment If no next segmentsend ACK
Immediately send single cumulative ACK ACKing both in-order segments
Immediately send duplicate ACK indicating seq of next expected byte
Immediate send ACK provided thatsegment startsat lower end of gap
Transport Layer 3-65
Fast Retransmit
Time-out period often relatively long
long delay before resending lost packet
Detect lost segments via duplicate ACKs
Sender often sends many segments back-to-backIf segment is lost there will likely be many duplicate ACKs
If sender receives 3 ACKs for the same data it supposes that segment after ACKeddata was lost
fast retransmit resend segment before timer expires
Transport Layer 3-66
Fast RetransmitResend a segment after 3 duplicate ACKs since a duplicate ACK means that an out-of sequence segment was receivedduplicate ACKs due to packet reorderingif window is small donrsquot get duplicate ACKs
Host A
tim
eout
Host B
time
X
resend seq X2
seq x1seq x2seq x3seq x4seq x5
ACK x1
ACK x1ACK x1ACK x1
tripleduplicate
ACKs
Transport Layer 3-67
event ACK received with ACK field value of y if (y gt SendBase)
SendBase = yif (there are currently not-yet-acknowledged segments)
start timer
else increment count of dup ACKs received for yif (count of dup ACKs received for y = 3)
resend segment with sequence number y
Fast retransmit algorithm
a duplicate ACK for already ACKed segment
fast retransmit
Transport Layer 3-68
TCP Flow Control
receive side of TCP connection has a receive buffer
speed-matching service matching the send rate to the receiving apprsquos drain rate
app process may be slow at reading from buffer
sender wonrsquot overflowreceiverrsquos buffer by
transmitting too muchtoo fast
flow control
Transport Layer 3-69
TCP Flow control how it works
(Suppose TCP receiver discards out-of-order segments)spare room in buffer
= RcvWin
= RcvBuffer-[LastByteRcvd -LastByteRead]
Rcvr advertises spare room by including value of RcvWin in segmentsSender limits unACKeddata to RcvWin
guarantees receive buffer doesnrsquot overflow
Transport Layer 3-70
Sliding Window Flow Control Example
3K
2K SeqNo=0
ReceiverBuffer
0 4KSendersends 2Kof data
2K
AckNo=2048 RcvWin=2048Sendersends 2Kof data 2K SeqNo=2048
4K
AckNo=4096 RcvWin=0
AckNo=4096 RcvWin=1024
Sender blocked
Transport Layer 3-71
Principles of Congestion Control
Congestioninformally ldquotoo many sources sending too much data too fast for network to handlerdquodifferent from flow controlmanifestations
lost packets (buffer overflow at routers)long delays (queueing in router buffers)
a top-10 problem
Transport Layer 3-72
Causescosts of congestion scenario 1
two senders two receiversone router infinite buffers no retransmission
large delays when congestedmaximum achievable throughput
unlimited shared output link buffers
Host Aλin original data
Host B
λout
Transport Layer 3-73
Causescosts of congestion scenario 2
one router finite buffers sender retransmission of lost packet
finite shared output link buffers
Host A λin original data
Host B
λout
λin original data plus retransmitted data
Transport Layer 3-74
Causescosts of congestion scenario 2always (goodput)ldquoperfectrdquo retransmission only when loss
retransmission of delayed (not lost) packet makes larger(than perfect case) for same
λin
λout=
λin
λoutgtλ
inλout
ldquocostsrdquo of congestionmore work (retrans) for given ldquogoodputrdquounneeded retransmissions link carries multiple copies of pkt
R2
R2λin
λ out
b
R2
R2λin
λ out
a
R2
R2λin
λ out
c
R4
R3
Transport Layer 3-75
Causescosts of congestion scenario 3four sendersmultihop pathstimeoutretransmit
λin
Q what happens as and increase λ
in
finite shared output link buffers
Host Aλin original data
Host B
λout
λin original data plus retransmitted data
Transport Layer 3-76
Causescosts of congestion scenario 3
another ldquocostrdquo of congestionwhen packet dropped any ldquoupstream transmission capacity used for that packet was wasted
Host A
Host B
λou
t
Transport Layer 3-77
Approaches towards congestion control
End-end congestion controlno explicit feedback from networkcongestion inferred from end-system observed loss delayapproach taken by TCP
Network-assisted congestion controlrouters provide feedback to end systems
single bit indicating congestion (SNA DECbit TCPIP ECN ATM)explicit rate sender should send at
Two broad approaches towards congestion control
Transport Layer 3-78
TCP Congestion Control
end-end control (no network assistance)sender limits transmissionLastByteSent-LastByteAcked
le CongWin
CongWin is dynamic function of perceived network congestion
How does sender perceive congestionloss event = timeout or3 duplicate acksTCP sender reduces rate (CongWin) after loss event
two modes of operationSlow Start (SS)Congestion avoidance (CA) or Additive Increase Multiplicative Decrease (AIMD)
Transport Layer 3-79
TCP congestion control bandwidth probing
ldquoprobing for bandwidthrdquo increase transmission rate on receipt of ACK until eventually loss occurs then decrease transmission rate
continue to increase on ACK decrease on loss (since available bandwidth is changing depending on other connections in network)
ACKs being received so increase rate
X
X
XX
X loss so decrease rate
send
ing
rate
time
Q how fast to increasedecreasedetails to follow
TCPrsquosldquosawtoothrdquobehavior
Transport Layer 3-80
TCP Congestion Control details
sender limits rate by limiting number of unACKed bytes ldquoin pipelinerdquo
cwnd differs from rwnd (how why)sender limited by min(cwndrwnd)
roughly
cwnd is dynamic function of perceived network congestion
rate = cwndRTT bytessec
LastByteSent-LastByteAcked le cwnd
cwndbytes
RTT
ACK(s)
Transport Layer 3-81
TCP Congestion Control more details
segment loss event reducing cwndtimeout no response from receiver
cut cwnd to 13 duplicate ACKs at least some segments getting through (recall fast retransmit)
cut cwnd in half less aggressively than on timeout
ACK received increase cwndTwo modes of operation
slowstart phase bull increase exponentially
fast (despite name) at connection start or following timeout
congestion avoidance bull increase linearly
Transport Layer 3-82
TCP Slow Start Phasewhen connection begins cwnd = 1 MSS
example MSS = 500 bytes amp RTT = 200 msecinitial rate = 20 kbps
available bandwidth may be gtgt MSSRTT
desirable to quickly ramp up to respectable rate
increase rate exponentially until first loss event or when threshold reached
double cwnd every RTTdone by incrementing cwnd by 1 for every ACK received
Host A
one segment
RTT
Host B
time
two segments
four segments
Transport Layer 3-83
Slow Start ExampleThe congestion window size grows very rapidly
For every ACK we increase CongWin by 1 irrespective of the number of segments ACKrsquoeddouble CongWinevery RTTinitial rate is slow but ramps up exponentially fast
TCP slows down the increase of CongWinwhen CongWin gt ssthresh
segment 1
ACK for segment 1
cwnd = 1
cwnd = 2 segment 2segment 3
ACK for segments 2
cwnd = 4 segment 4segment 5segment 6
ACK for segments 4
cwnd = 7
ACK for segments 3
ACK for segments 5
ACK for segments 6
cwnd = 3
cwnd = 5
cwnd = 6ACK for segments 7
cwnd = 8
segment 7
Transport Layer 3-84
TCP Congestion Avoidance Phase
when cwnd gt ssthreshgrow cwnd linearly
increase cwnd by 1 MSS per RTT approach possible congestion slower than in slowstartimplementation cwnd= cwnd + MSScwndfor each ACK received
ACKs increase cwndby 1 MSS per RTT additive increaseloss cut cwnd in half (non-timeout-detected loss ) multiplicative decrease
AIMD
AIMD Additive IncreaseMultiplicative Decrease
Transport Layer 3-85
Congestion AvoidanceCongestion avoidance phase is started if CongWin has reached the slow-start threshold value
If CongWin gt= ssthresh then each time an ACK is received increment CongWin as follows
bull CongWin = CongWin + 1CongWin (CongWin in segments)
bull In actual TCP implementation CongWin is in BytesCongWin = CongWin + MSS (MSSCongWin)
So CongWin is increased by one only if all CongWinsegments have been acknowledged
Transport Layer 3-86
Example Slow StartCongestion AvoidanceAssume that
ssthresh = 8
cwnd = 1
cwnd = 2
cwnd = 4
cwnd = 8
cwnd = 9
cwnd = 10
02468
101214
t=0
t=2
t=4
t=6
Roundtrip times
Cw
nd(in
seg
men
ts)
ssthresh
cwnd = 3
cwnd = 5cwnd = 6cwnd = 7
Transport Layer 3-87
Slow Start Congestion AvoidanceA typical plot of CongWin for a TCP connection
(MSS = 1500 bytes) with TCP Tahoe
SS
CA
ssthresh
Transport Layer 3-88
Responses to CongestionTCP assumes there is congestion if it detects a packet lossA TCP sender can detect lost packets via loss events
bull Timeout of a retransmission timerbull Receipt of 3 duplicate ACKs (fast retransmit)
TCP interprets a Timeout as a binary congestion signal When a timeout occurs the sender performs
ssthresh is set to half the current size of the congestion window
ssthresh = CongWin 2CongWin is reset to one
CongWin = 1and slow-start is entered
Transport Layer 3-89
Fast Recovery (differentiation btwn two loss events) After 3 dup ACKs (fast Retransmit)
ssthresh = CongWin2CongWin = CongWin2window then grows linearly
But after timeout eventCongWin = 1 MSS window then grows exponentiallyto the threshold then grows linearly
bull 3 dup ACKs indicates network capable of delivering some segmentsbull timeout before 3 dup ACKs is ldquomore alarmingrdquo
Philosophy
3-90
TCP Congestion ControlInitially
CongWin = 1ssthresh = advertised window size
New Ack receivedif (CongWin lt ssthresh) Slow Start
CongWin = CongWin + 1else Congestion Avoidance
CongWin = CongWin + 1CongWinTimeout
ssthresh = CongWin2CongWin = 1
Fast Retransmissionssthresh = CongWin2CongWin = CongWin2
Slow Start (exponential increase phase) is continued until CongWin reaches half of the level where the loss event occurred last time CongWin is increased slowly after (linear increase in Congestion Avoidance phase)
Transport Layer 3-91
Popular ldquoflavorsrdquo of TCP
ssthresh
ssthresh
TCP Tahoe
TCP Reno
Transmission round
cwnd
win
dow
siz
e (in
seg
men
ts)
Transport Layer 3-92
Summary TCP Congestion ControlWhen CongWin is below Threshold sender in slow-start phase window grows exponentiallyWhen CongWin is above Threshold sender is in congestion-avoidance phase window grows linearlyWhen a triple duplicate ACK occurs Threshold set to CongWin2 and CongWin set to ThresholdWhen timeout occurs Threshold set to CongWin2 and CongWin is set to 1 MSS The actual sender window size is determined based on the congestion and flow control algorithms
SenderWin=min(RcvWinCongWin)
Transport Layer 3-93
TCP Congestion Control SummaryEvent State TCP Sender Action Commentary
ACK receipt for previously unackeddata
Slow Start (SS)
CongWin = CongWin + MSS If (CongWin gt Threshold)
set state to ldquoCongestion Avoidancerdquo
Resulting in a doubling of CongWin every RTT
ACK receipt for previously unackeddata
CongestionAvoidance (CA)
CongWin = CongWin+MSS (MSSCongWin)
Additive increase resulting in increase of CongWin by 1 MSS every RTT
Loss event detected by triple duplicate ACK
SS or CA Threshold = CongWin2 CongWin = ThresholdSet state to ldquoCongestion Avoidancerdquo
Fast recovery implementing multiplicative decrease CongWin will not drop below 1 MSS
Timeout SS or CA Threshold = CongWin2 CongWin = 1 MSSSet state to ldquoSlow Startrdquo
Enter slow start
Duplicate ACK
SS or CA Increment duplicate ACK count for segment being acked
CongWin and Threshold not changed
Transport Layer 3-94
TCP throughput
Q whatrsquos average throughout of TCP as function of window size RTT
ignoring slow startlet W be window size when loss occurs
when window is W throughput is WRTTjust after loss window drops to W2 throughput to W2RTT average throughout 75 WRTT
Transport Layer 3-95
TCP Futures TCP over ldquolong fat pipesrdquo
example 1500 byte segments 100ms RTT want 10 Gbps throughputrequires window size W = 83333 in-flight segmentsthroughput in terms of loss rate
L = 210-10 Wownew versions of TCP for high-speed
LRTTMSSsdot221
Transport Layer 3-96
Fairness goal if K TCP sessions share same bottleneck link of bandwidth R each should have average rate of RK
TCP connection 1
bottleneckrouter
capacity R
TCP connection 2
TCP Fairness
Transport Layer 3-97
Why is TCP fairTwo competing sessions
Additive increase gives slope of 1 as throughout increasesmultiplicative decrease decreases throughput proportionally
R
R
equal bandwidth share
Connection 1 throughput
Conn
ecti
on 2
thr
ough
p ut
congestion avoidance additive increaseloss decrease window by factor of 2
congestion avoidance additive increaseloss decrease window by factor of 2
Transport Layer 3-98
Fairness (more)Fairness and UDP
Multimedia apps often do not use TCP
do not want rate throttled by congestion control
Instead use UDPpump audiovideo at constant rate tolerate packet loss
Research area TCP friendly
Fairness and parallel TCP connectionsnothing prevents app from opening parallel cnctionsbetween 2 hostsWeb browsers do this Example link of rate R supporting 9 cnctions
new app asks for 1 TCP gets rate R10new app asks for 11 TCPs gets R2
Transport Layer 3-99
TCP Connection ManagementRecall TCP sender receiver
establish ldquoconnectionrdquobefore exchanging data segmentsinitialize TCP variables
seq sbuffers flow control info (eg RcvWindow)
client connection initiatorSocket clientSocket = new Socket(hostnameport
number)
server contacted by clientSocket connectionSocket = welcomeSocketaccept()
Three way handshakeStep 1 client host sends TCP
SYN segment to serverspecifies initial seq no data
Step 2 server host receives SYN replies with SYNACK segment
server allocates buffersspecifies server initial seq
Step 3 client receives SYNACK replies with ACK segment which may contain data
Transport Layer 3-100
TCP Connection Management (cont)
Closing a connection
client closes socketclientSocketclose()
Step 1 client end system sends TCP FIN control segment to server
Step 2 server receives FIN replies with ACK Closes connection sends FIN
client
FIN
server
ACK
ACK
FIN
close
close
closed
tim
ed w
ait
Transport Layer 3-101
TCP Connection Management (cont)
Step 3 client receives FIN replies with ACK
Enters ldquotimed waitrdquo -will respond with ACK to received FINs
Step 4 server receives ACK Connection closed
client
FIN
server
ACK
ACK
FIN
closing
closing
closed
tim
ed w
ait
closed
Transport Layer 3-102
TCP Connection Management (cont)
TCP clientlifecycle
TCP serverlifecycle
Transport Layer 3-103
Tuning TCPIP Parameters TCPIP parameters
A set of default values may not be optimal for all applicationsThe network administrator may wish to turn on or off some TCPIP functions for performance or security considerations
Many Unix and Linux systems provide some flexibility in tuning the TCPIP kernelsbinsysctl is used to configure the Linux kernel parameters at runtime
Default kernel configuration file is sbinsysctlconfFrequently used sysctl options
bull sysctl ndasha or sysctl ndashA list all current valuesbull sysctl ndashp file_name load the sysctl setting from a configuration
filebull sysctl ndashw variable=value change the value of the parameter
Transport Layer 3-104
SomeTCP Parameters in Linux Kerneltcp_syn_retries
Number of SYN packets the kernel will send before giving up on the new connection
tcp_synack_retriesnumber of SYN+ACK packets sent before the kernel gives up on the connection
tcp_window_scalingMaximum window size of 65535 bytes not enough for for really fast networks The window scaling options allows for almost gigabyte windows which is good for connections with large delay-bandwidth product
tcp_max_syn_backlogMaximal number of remembered connection requests which still did not receive an acknowledgment from connecting client
tcp_fin_timeoutHow many seconds to wait for a final FIN packet before the socket is closed required to prevent denial-of-service (DoS) attacks Default value is 60 seconds
Transport Layer 3-105
SomeTCP Parameters in Linux Kerneltcp_rmem
This is a vector of 3 integers [min default max] These parameters are used by TCP to dynamically adjust receive buffer sizesmin - minimum size of the receive buffer used by each TCP socket The default value is 4K default - the default size of the receive buffer for a TCP socket The default value is 87380 bytes and is lowered to 43689 in low memory systems If larger receive buffer sizes are desired this value should be increased max - the maximum size of the receive buffer used by each TCP socket The default value of 873802 bytes is lowered to 87380 in low memory systems
tcp_smemSend buffer parameters [min default max] similar to tcp_rmem
- Chapter 3 Transport Layer
- Transport services and protocols
- Transport vs network layer
- Internet transport-layer protocols
- Multiplexingdemultiplexing
- How demultiplexing works
- Connectionless demultiplexing
- Connection-oriented demux
- Connection-oriented demux (cont)
- Connection-oriented demux Threaded Web Server
- UDP User Datagram Protocol [RFC 768]
- UDP more
- UDP checksum
- Principles of Reliable data transfer
- Reliable data transfer getting started
- Reliable data transfer getting started
- Rdt10 reliable transfer over a reliable channel
- Rdt20 channel with bit errors
- rdt20 FSM specification
- rdt20 operation with no errors
- rdt20 error scenario
- rdt20 has a fatal flaw
- rdt21 sender handles garbled ACKNAKs
- rdt21 receiver handles garbled ACKNAKs
- rdt21 discussion
- rdt22 a NAK-free protocol
- rdt22 sender receiver fragments
- rdt30 channels with errors and loss
- rdt30 sender
- rdt30 in action
- rdt30 in action
- Performance of rdt30
- rdt30 stop-and-wait operation
- Pipelined protocols
- Pipelining increased utilization
- Go-Back-N
- GBN sender extended FSM
- GBN receiver extended FSM
- GBN inaction
- Selective Repeat
- Selective repeat sender receiver windows
- Selective repeat
- Selective repeat in action
- Selective repeat dilemma
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- TCP Overview RFCs 793 1122 1323 2018 2581
- TCP segment structure
- TCP seq rsquos and ACKs
- TCP Round Trip Time and Timeout
- TCP Round Trip Time and Timeout
- Example RTT estimation
- TCP Round Trip Time and Timeout
- TCP reliable data transfer
- TCP sender events
- TCP sender(simplified)
- TCP retransmission scenarios
- TCP retransmission scenarios (more)
- TCP ACK generation [RFC 1122 RFC 2581]
- Fast Retransmit
- Fast Retransmit
- Fast retransmit algorithm
- TCP Flow Control
- TCP Flow control how it works
- Sliding Window Flow Control Example
- Principles of Congestion Control
- Causescosts of congestion scenario 1
- Causescosts of congestion scenario 2
- Causescosts of congestion scenario 2
- Causescosts of congestion scenario 3
- Causescosts of congestion scenario 3
- Approaches towards congestion control
- TCP Congestion Control
- TCP congestion control bandwidth probing
- TCP Congestion Control details
- TCP Congestion Control more details
- TCP Slow Start Phase
- Slow Start Example
- TCP Congestion Avoidance Phase
- Congestion Avoidance
- Example Slow StartCongestion Avoidance
- Slow Start Congestion Avoidance
- Responses to Congestion
- Fast Recovery (differentiation btwn two loss events)
- TCP Congestion Control
- Popular ldquoflavorsrdquo of TCP
- Summary TCP Congestion Control
- TCP Congestion Control Summary
- TCP throughput
- TCP Futures TCP over ldquolong fat pipesrdquo
- TCP Fairness
- Why is TCP fair
- Fairness (more)
- TCP Connection Management
- TCP Connection Management (cont)
- TCP Connection Management (cont)
- TCP Connection Management (cont)
- Tuning TCPIP Parameters
- SomeTCP Parameters in Linux Kernel
- SomeTCP Parameters in Linux Kernel
-
Transport Layer 3-63
TCP retransmission scenarios (more)Host A
Seq=92 8 bytes data
ACK=100
loss
tim
eout
Cumulative ACK scenario
Host B
X
Seq=100 20 bytes data
ACK=120
time
SendBase= 120
Transport Layer 3-64
TCP ACK generation [RFC 1122 RFC 2581]
Event at Receiver
Arrival of in-order segment withexpected seq All data up toexpected seq already ACKed
Arrival of in-order segment withexpected seq One other segment has ACK pending
Arrival of out-of-order segmenthigher-than-expect seq Gap detected
Arrival of segment that partially or completely fills gap
TCP Receiver action
Delayed ACK Wait up to 500msfor next segment If no next segmentsend ACK
Immediately send single cumulative ACK ACKing both in-order segments
Immediately send duplicate ACK indicating seq of next expected byte
Immediate send ACK provided thatsegment startsat lower end of gap
Transport Layer 3-65
Fast Retransmit
Time-out period often relatively long
long delay before resending lost packet
Detect lost segments via duplicate ACKs
Sender often sends many segments back-to-backIf segment is lost there will likely be many duplicate ACKs
If sender receives 3 ACKs for the same data it supposes that segment after ACKeddata was lost
fast retransmit resend segment before timer expires
Transport Layer 3-66
Fast RetransmitResend a segment after 3 duplicate ACKs since a duplicate ACK means that an out-of sequence segment was receivedduplicate ACKs due to packet reorderingif window is small donrsquot get duplicate ACKs
Host A
tim
eout
Host B
time
X
resend seq X2
seq x1seq x2seq x3seq x4seq x5
ACK x1
ACK x1ACK x1ACK x1
tripleduplicate
ACKs
Transport Layer 3-67
event ACK received with ACK field value of y if (y gt SendBase)
SendBase = yif (there are currently not-yet-acknowledged segments)
start timer
else increment count of dup ACKs received for yif (count of dup ACKs received for y = 3)
resend segment with sequence number y
Fast retransmit algorithm
a duplicate ACK for already ACKed segment
fast retransmit
Transport Layer 3-68
TCP Flow Control
receive side of TCP connection has a receive buffer
speed-matching service matching the send rate to the receiving apprsquos drain rate
app process may be slow at reading from buffer
sender wonrsquot overflowreceiverrsquos buffer by
transmitting too muchtoo fast
flow control
Transport Layer 3-69
TCP Flow control how it works
(Suppose TCP receiver discards out-of-order segments)spare room in buffer
= RcvWin
= RcvBuffer-[LastByteRcvd -LastByteRead]
Rcvr advertises spare room by including value of RcvWin in segmentsSender limits unACKeddata to RcvWin
guarantees receive buffer doesnrsquot overflow
Transport Layer 3-70
Sliding Window Flow Control Example
3K
2K SeqNo=0
ReceiverBuffer
0 4KSendersends 2Kof data
2K
AckNo=2048 RcvWin=2048Sendersends 2Kof data 2K SeqNo=2048
4K
AckNo=4096 RcvWin=0
AckNo=4096 RcvWin=1024
Sender blocked
Transport Layer 3-71
Principles of Congestion Control
Congestioninformally ldquotoo many sources sending too much data too fast for network to handlerdquodifferent from flow controlmanifestations
lost packets (buffer overflow at routers)long delays (queueing in router buffers)
a top-10 problem
Transport Layer 3-72
Causescosts of congestion scenario 1
two senders two receiversone router infinite buffers no retransmission
large delays when congestedmaximum achievable throughput
unlimited shared output link buffers
Host Aλin original data
Host B
λout
Transport Layer 3-73
Causescosts of congestion scenario 2
one router finite buffers sender retransmission of lost packet
finite shared output link buffers
Host A λin original data
Host B
λout
λin original data plus retransmitted data
Transport Layer 3-74
Causescosts of congestion scenario 2always (goodput)ldquoperfectrdquo retransmission only when loss
retransmission of delayed (not lost) packet makes larger(than perfect case) for same
λin
λout=
λin
λoutgtλ
inλout
ldquocostsrdquo of congestionmore work (retrans) for given ldquogoodputrdquounneeded retransmissions link carries multiple copies of pkt
R2
R2λin
λ out
b
R2
R2λin
λ out
a
R2
R2λin
λ out
c
R4
R3
Transport Layer 3-75
Causescosts of congestion scenario 3four sendersmultihop pathstimeoutretransmit
λin
Q what happens as and increase λ
in
finite shared output link buffers
Host Aλin original data
Host B
λout
λin original data plus retransmitted data
Transport Layer 3-76
Causescosts of congestion scenario 3
another ldquocostrdquo of congestionwhen packet dropped any ldquoupstream transmission capacity used for that packet was wasted
Host A
Host B
λou
t
Transport Layer 3-77
Approaches towards congestion control
End-end congestion controlno explicit feedback from networkcongestion inferred from end-system observed loss delayapproach taken by TCP
Network-assisted congestion controlrouters provide feedback to end systems
single bit indicating congestion (SNA DECbit TCPIP ECN ATM)explicit rate sender should send at
Two broad approaches towards congestion control
Transport Layer 3-78
TCP Congestion Control
end-end control (no network assistance)sender limits transmissionLastByteSent-LastByteAcked
le CongWin
CongWin is dynamic function of perceived network congestion
How does sender perceive congestionloss event = timeout or3 duplicate acksTCP sender reduces rate (CongWin) after loss event
two modes of operationSlow Start (SS)Congestion avoidance (CA) or Additive Increase Multiplicative Decrease (AIMD)
Transport Layer 3-79
TCP congestion control bandwidth probing
ldquoprobing for bandwidthrdquo increase transmission rate on receipt of ACK until eventually loss occurs then decrease transmission rate
continue to increase on ACK decrease on loss (since available bandwidth is changing depending on other connections in network)
ACKs being received so increase rate
X
X
XX
X loss so decrease rate
send
ing
rate
time
Q how fast to increasedecreasedetails to follow
TCPrsquosldquosawtoothrdquobehavior
Transport Layer 3-80
TCP Congestion Control details
sender limits rate by limiting number of unACKed bytes ldquoin pipelinerdquo
cwnd differs from rwnd (how why)sender limited by min(cwndrwnd)
roughly
cwnd is dynamic function of perceived network congestion
rate = cwndRTT bytessec
LastByteSent-LastByteAcked le cwnd
cwndbytes
RTT
ACK(s)
Transport Layer 3-81
TCP Congestion Control more details
segment loss event reducing cwndtimeout no response from receiver
cut cwnd to 13 duplicate ACKs at least some segments getting through (recall fast retransmit)
cut cwnd in half less aggressively than on timeout
ACK received increase cwndTwo modes of operation
slowstart phase bull increase exponentially
fast (despite name) at connection start or following timeout
congestion avoidance bull increase linearly
Transport Layer 3-82
TCP Slow Start Phasewhen connection begins cwnd = 1 MSS
example MSS = 500 bytes amp RTT = 200 msecinitial rate = 20 kbps
available bandwidth may be gtgt MSSRTT
desirable to quickly ramp up to respectable rate
increase rate exponentially until first loss event or when threshold reached
double cwnd every RTTdone by incrementing cwnd by 1 for every ACK received
Host A
one segment
RTT
Host B
time
two segments
four segments
Transport Layer 3-83
Slow Start ExampleThe congestion window size grows very rapidly
For every ACK we increase CongWin by 1 irrespective of the number of segments ACKrsquoeddouble CongWinevery RTTinitial rate is slow but ramps up exponentially fast
TCP slows down the increase of CongWinwhen CongWin gt ssthresh
segment 1
ACK for segment 1
cwnd = 1
cwnd = 2 segment 2segment 3
ACK for segments 2
cwnd = 4 segment 4segment 5segment 6
ACK for segments 4
cwnd = 7
ACK for segments 3
ACK for segments 5
ACK for segments 6
cwnd = 3
cwnd = 5
cwnd = 6ACK for segments 7
cwnd = 8
segment 7
Transport Layer 3-84
TCP Congestion Avoidance Phase
when cwnd gt ssthreshgrow cwnd linearly
increase cwnd by 1 MSS per RTT approach possible congestion slower than in slowstartimplementation cwnd= cwnd + MSScwndfor each ACK received
ACKs increase cwndby 1 MSS per RTT additive increaseloss cut cwnd in half (non-timeout-detected loss ) multiplicative decrease
AIMD
AIMD Additive IncreaseMultiplicative Decrease
Transport Layer 3-85
Congestion AvoidanceCongestion avoidance phase is started if CongWin has reached the slow-start threshold value
If CongWin gt= ssthresh then each time an ACK is received increment CongWin as follows
bull CongWin = CongWin + 1CongWin (CongWin in segments)
bull In actual TCP implementation CongWin is in BytesCongWin = CongWin + MSS (MSSCongWin)
So CongWin is increased by one only if all CongWinsegments have been acknowledged
Transport Layer 3-86
Example Slow StartCongestion AvoidanceAssume that
ssthresh = 8
cwnd = 1
cwnd = 2
cwnd = 4
cwnd = 8
cwnd = 9
cwnd = 10
02468
101214
t=0
t=2
t=4
t=6
Roundtrip times
Cw
nd(in
seg
men
ts)
ssthresh
cwnd = 3
cwnd = 5cwnd = 6cwnd = 7
Transport Layer 3-87
Slow Start Congestion AvoidanceA typical plot of CongWin for a TCP connection
(MSS = 1500 bytes) with TCP Tahoe
SS
CA
ssthresh
Transport Layer 3-88
Responses to CongestionTCP assumes there is congestion if it detects a packet lossA TCP sender can detect lost packets via loss events
bull Timeout of a retransmission timerbull Receipt of 3 duplicate ACKs (fast retransmit)
TCP interprets a Timeout as a binary congestion signal When a timeout occurs the sender performs
ssthresh is set to half the current size of the congestion window
ssthresh = CongWin 2CongWin is reset to one
CongWin = 1and slow-start is entered
Transport Layer 3-89
Fast Recovery (differentiation btwn two loss events) After 3 dup ACKs (fast Retransmit)
ssthresh = CongWin2CongWin = CongWin2window then grows linearly
But after timeout eventCongWin = 1 MSS window then grows exponentiallyto the threshold then grows linearly
bull 3 dup ACKs indicates network capable of delivering some segmentsbull timeout before 3 dup ACKs is ldquomore alarmingrdquo
Philosophy
3-90
TCP Congestion ControlInitially
CongWin = 1ssthresh = advertised window size
New Ack receivedif (CongWin lt ssthresh) Slow Start
CongWin = CongWin + 1else Congestion Avoidance
CongWin = CongWin + 1CongWinTimeout
ssthresh = CongWin2CongWin = 1
Fast Retransmissionssthresh = CongWin2CongWin = CongWin2
Slow Start (exponential increase phase) is continued until CongWin reaches half of the level where the loss event occurred last time CongWin is increased slowly after (linear increase in Congestion Avoidance phase)
Transport Layer 3-91
Popular ldquoflavorsrdquo of TCP
ssthresh
ssthresh
TCP Tahoe
TCP Reno
Transmission round
cwnd
win
dow
siz
e (in
seg
men
ts)
Transport Layer 3-92
Summary TCP Congestion ControlWhen CongWin is below Threshold sender in slow-start phase window grows exponentiallyWhen CongWin is above Threshold sender is in congestion-avoidance phase window grows linearlyWhen a triple duplicate ACK occurs Threshold set to CongWin2 and CongWin set to ThresholdWhen timeout occurs Threshold set to CongWin2 and CongWin is set to 1 MSS The actual sender window size is determined based on the congestion and flow control algorithms
SenderWin=min(RcvWinCongWin)
Transport Layer 3-93
TCP Congestion Control SummaryEvent State TCP Sender Action Commentary
ACK receipt for previously unackeddata
Slow Start (SS)
CongWin = CongWin + MSS If (CongWin gt Threshold)
set state to ldquoCongestion Avoidancerdquo
Resulting in a doubling of CongWin every RTT
ACK receipt for previously unackeddata
CongestionAvoidance (CA)
CongWin = CongWin+MSS (MSSCongWin)
Additive increase resulting in increase of CongWin by 1 MSS every RTT
Loss event detected by triple duplicate ACK
SS or CA Threshold = CongWin2 CongWin = ThresholdSet state to ldquoCongestion Avoidancerdquo
Fast recovery implementing multiplicative decrease CongWin will not drop below 1 MSS
Timeout SS or CA Threshold = CongWin2 CongWin = 1 MSSSet state to ldquoSlow Startrdquo
Enter slow start
Duplicate ACK
SS or CA Increment duplicate ACK count for segment being acked
CongWin and Threshold not changed
Transport Layer 3-94
TCP throughput
Q whatrsquos average throughout of TCP as function of window size RTT
ignoring slow startlet W be window size when loss occurs
when window is W throughput is WRTTjust after loss window drops to W2 throughput to W2RTT average throughout 75 WRTT
Transport Layer 3-95
TCP Futures TCP over ldquolong fat pipesrdquo
example 1500 byte segments 100ms RTT want 10 Gbps throughputrequires window size W = 83333 in-flight segmentsthroughput in terms of loss rate
L = 210-10 Wownew versions of TCP for high-speed
LRTTMSSsdot221
Transport Layer 3-96
Fairness goal if K TCP sessions share same bottleneck link of bandwidth R each should have average rate of RK
TCP connection 1
bottleneckrouter
capacity R
TCP connection 2
TCP Fairness
Transport Layer 3-97
Why is TCP fairTwo competing sessions
Additive increase gives slope of 1 as throughout increasesmultiplicative decrease decreases throughput proportionally
R
R
equal bandwidth share
Connection 1 throughput
Conn
ecti
on 2
thr
ough
p ut
congestion avoidance additive increaseloss decrease window by factor of 2
congestion avoidance additive increaseloss decrease window by factor of 2
Transport Layer 3-98
Fairness (more)Fairness and UDP
Multimedia apps often do not use TCP
do not want rate throttled by congestion control
Instead use UDPpump audiovideo at constant rate tolerate packet loss
Research area TCP friendly
Fairness and parallel TCP connectionsnothing prevents app from opening parallel cnctionsbetween 2 hostsWeb browsers do this Example link of rate R supporting 9 cnctions
new app asks for 1 TCP gets rate R10new app asks for 11 TCPs gets R2
Transport Layer 3-99
TCP Connection ManagementRecall TCP sender receiver
establish ldquoconnectionrdquobefore exchanging data segmentsinitialize TCP variables
seq sbuffers flow control info (eg RcvWindow)
client connection initiatorSocket clientSocket = new Socket(hostnameport
number)
server contacted by clientSocket connectionSocket = welcomeSocketaccept()
Three way handshakeStep 1 client host sends TCP
SYN segment to serverspecifies initial seq no data
Step 2 server host receives SYN replies with SYNACK segment
server allocates buffersspecifies server initial seq
Step 3 client receives SYNACK replies with ACK segment which may contain data
Transport Layer 3-100
TCP Connection Management (cont)
Closing a connection
client closes socketclientSocketclose()
Step 1 client end system sends TCP FIN control segment to server
Step 2 server receives FIN replies with ACK Closes connection sends FIN
client
FIN
server
ACK
ACK
FIN
close
close
closed
tim
ed w
ait
Transport Layer 3-101
TCP Connection Management (cont)
Step 3 client receives FIN replies with ACK
Enters ldquotimed waitrdquo -will respond with ACK to received FINs
Step 4 server receives ACK Connection closed
client
FIN
server
ACK
ACK
FIN
closing
closing
closed
tim
ed w
ait
closed
Transport Layer 3-102
TCP Connection Management (cont)
TCP clientlifecycle
TCP serverlifecycle
Transport Layer 3-103
Tuning TCPIP Parameters TCPIP parameters
A set of default values may not be optimal for all applicationsThe network administrator may wish to turn on or off some TCPIP functions for performance or security considerations
Many Unix and Linux systems provide some flexibility in tuning the TCPIP kernelsbinsysctl is used to configure the Linux kernel parameters at runtime
Default kernel configuration file is sbinsysctlconfFrequently used sysctl options
bull sysctl ndasha or sysctl ndashA list all current valuesbull sysctl ndashp file_name load the sysctl setting from a configuration
filebull sysctl ndashw variable=value change the value of the parameter
Transport Layer 3-104
SomeTCP Parameters in Linux Kerneltcp_syn_retries
Number of SYN packets the kernel will send before giving up on the new connection
tcp_synack_retriesnumber of SYN+ACK packets sent before the kernel gives up on the connection
tcp_window_scalingMaximum window size of 65535 bytes not enough for for really fast networks The window scaling options allows for almost gigabyte windows which is good for connections with large delay-bandwidth product
tcp_max_syn_backlogMaximal number of remembered connection requests which still did not receive an acknowledgment from connecting client
tcp_fin_timeoutHow many seconds to wait for a final FIN packet before the socket is closed required to prevent denial-of-service (DoS) attacks Default value is 60 seconds
Transport Layer 3-105
SomeTCP Parameters in Linux Kerneltcp_rmem
This is a vector of 3 integers [min default max] These parameters are used by TCP to dynamically adjust receive buffer sizesmin - minimum size of the receive buffer used by each TCP socket The default value is 4K default - the default size of the receive buffer for a TCP socket The default value is 87380 bytes and is lowered to 43689 in low memory systems If larger receive buffer sizes are desired this value should be increased max - the maximum size of the receive buffer used by each TCP socket The default value of 873802 bytes is lowered to 87380 in low memory systems
tcp_smemSend buffer parameters [min default max] similar to tcp_rmem
- Chapter 3 Transport Layer
- Transport services and protocols
- Transport vs network layer
- Internet transport-layer protocols
- Multiplexingdemultiplexing
- How demultiplexing works
- Connectionless demultiplexing
- Connection-oriented demux
- Connection-oriented demux (cont)
- Connection-oriented demux Threaded Web Server
- UDP User Datagram Protocol [RFC 768]
- UDP more
- UDP checksum
- Principles of Reliable data transfer
- Reliable data transfer getting started
- Reliable data transfer getting started
- Rdt10 reliable transfer over a reliable channel
- Rdt20 channel with bit errors
- rdt20 FSM specification
- rdt20 operation with no errors
- rdt20 error scenario
- rdt20 has a fatal flaw
- rdt21 sender handles garbled ACKNAKs
- rdt21 receiver handles garbled ACKNAKs
- rdt21 discussion
- rdt22 a NAK-free protocol
- rdt22 sender receiver fragments
- rdt30 channels with errors and loss
- rdt30 sender
- rdt30 in action
- rdt30 in action
- Performance of rdt30
- rdt30 stop-and-wait operation
- Pipelined protocols
- Pipelining increased utilization
- Go-Back-N
- GBN sender extended FSM
- GBN receiver extended FSM
- GBN inaction
- Selective Repeat
- Selective repeat sender receiver windows
- Selective repeat
- Selective repeat in action
- Selective repeat dilemma
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- TCP Overview RFCs 793 1122 1323 2018 2581
- TCP segment structure
- TCP seq rsquos and ACKs
- TCP Round Trip Time and Timeout
- TCP Round Trip Time and Timeout
- Example RTT estimation
- TCP Round Trip Time and Timeout
- TCP reliable data transfer
- TCP sender events
- TCP sender(simplified)
- TCP retransmission scenarios
- TCP retransmission scenarios (more)
- TCP ACK generation [RFC 1122 RFC 2581]
- Fast Retransmit
- Fast Retransmit
- Fast retransmit algorithm
- TCP Flow Control
- TCP Flow control how it works
- Sliding Window Flow Control Example
- Principles of Congestion Control
- Causescosts of congestion scenario 1
- Causescosts of congestion scenario 2
- Causescosts of congestion scenario 2
- Causescosts of congestion scenario 3
- Causescosts of congestion scenario 3
- Approaches towards congestion control
- TCP Congestion Control
- TCP congestion control bandwidth probing
- TCP Congestion Control details
- TCP Congestion Control more details
- TCP Slow Start Phase
- Slow Start Example
- TCP Congestion Avoidance Phase
- Congestion Avoidance
- Example Slow StartCongestion Avoidance
- Slow Start Congestion Avoidance
- Responses to Congestion
- Fast Recovery (differentiation btwn two loss events)
- TCP Congestion Control
- Popular ldquoflavorsrdquo of TCP
- Summary TCP Congestion Control
- TCP Congestion Control Summary
- TCP throughput
- TCP Futures TCP over ldquolong fat pipesrdquo
- TCP Fairness
- Why is TCP fair
- Fairness (more)
- TCP Connection Management
- TCP Connection Management (cont)
- TCP Connection Management (cont)
- TCP Connection Management (cont)
- Tuning TCPIP Parameters
- SomeTCP Parameters in Linux Kernel
- SomeTCP Parameters in Linux Kernel
-
Transport Layer 3-64
TCP ACK generation [RFC 1122 RFC 2581]
Event at Receiver
Arrival of in-order segment withexpected seq All data up toexpected seq already ACKed
Arrival of in-order segment withexpected seq One other segment has ACK pending
Arrival of out-of-order segmenthigher-than-expect seq Gap detected
Arrival of segment that partially or completely fills gap
TCP Receiver action
Delayed ACK Wait up to 500msfor next segment If no next segmentsend ACK
Immediately send single cumulative ACK ACKing both in-order segments
Immediately send duplicate ACK indicating seq of next expected byte
Immediate send ACK provided thatsegment startsat lower end of gap
Transport Layer 3-65
Fast Retransmit
Time-out period often relatively long
long delay before resending lost packet
Detect lost segments via duplicate ACKs
Sender often sends many segments back-to-backIf segment is lost there will likely be many duplicate ACKs
If sender receives 3 ACKs for the same data it supposes that segment after ACKeddata was lost
fast retransmit resend segment before timer expires
Transport Layer 3-66
Fast RetransmitResend a segment after 3 duplicate ACKs since a duplicate ACK means that an out-of sequence segment was receivedduplicate ACKs due to packet reorderingif window is small donrsquot get duplicate ACKs
Host A
tim
eout
Host B
time
X
resend seq X2
seq x1seq x2seq x3seq x4seq x5
ACK x1
ACK x1ACK x1ACK x1
tripleduplicate
ACKs
Transport Layer 3-67
event ACK received with ACK field value of y if (y gt SendBase)
SendBase = yif (there are currently not-yet-acknowledged segments)
start timer
else increment count of dup ACKs received for yif (count of dup ACKs received for y = 3)
resend segment with sequence number y
Fast retransmit algorithm
a duplicate ACK for already ACKed segment
fast retransmit
Transport Layer 3-68
TCP Flow Control
receive side of TCP connection has a receive buffer
speed-matching service matching the send rate to the receiving apprsquos drain rate
app process may be slow at reading from buffer
sender wonrsquot overflowreceiverrsquos buffer by
transmitting too muchtoo fast
flow control
Transport Layer 3-69
TCP Flow control how it works
(Suppose TCP receiver discards out-of-order segments)spare room in buffer
= RcvWin
= RcvBuffer-[LastByteRcvd -LastByteRead]
Rcvr advertises spare room by including value of RcvWin in segmentsSender limits unACKeddata to RcvWin
guarantees receive buffer doesnrsquot overflow
Transport Layer 3-70
Sliding Window Flow Control Example
3K
2K SeqNo=0
ReceiverBuffer
0 4KSendersends 2Kof data
2K
AckNo=2048 RcvWin=2048Sendersends 2Kof data 2K SeqNo=2048
4K
AckNo=4096 RcvWin=0
AckNo=4096 RcvWin=1024
Sender blocked
Transport Layer 3-71
Principles of Congestion Control
Congestioninformally ldquotoo many sources sending too much data too fast for network to handlerdquodifferent from flow controlmanifestations
lost packets (buffer overflow at routers)long delays (queueing in router buffers)
a top-10 problem
Transport Layer 3-72
Causescosts of congestion scenario 1
two senders two receiversone router infinite buffers no retransmission
large delays when congestedmaximum achievable throughput
unlimited shared output link buffers
Host Aλin original data
Host B
λout
Transport Layer 3-73
Causescosts of congestion scenario 2
one router finite buffers sender retransmission of lost packet
finite shared output link buffers
Host A λin original data
Host B
λout
λin original data plus retransmitted data
Transport Layer 3-74
Causescosts of congestion scenario 2always (goodput)ldquoperfectrdquo retransmission only when loss
retransmission of delayed (not lost) packet makes larger(than perfect case) for same
λin
λout=
λin
λoutgtλ
inλout
ldquocostsrdquo of congestionmore work (retrans) for given ldquogoodputrdquounneeded retransmissions link carries multiple copies of pkt
R2
R2λin
λ out
b
R2
R2λin
λ out
a
R2
R2λin
λ out
c
R4
R3
Transport Layer 3-75
Causescosts of congestion scenario 3four sendersmultihop pathstimeoutretransmit
λin
Q what happens as and increase λ
in
finite shared output link buffers
Host Aλin original data
Host B
λout
λin original data plus retransmitted data
Transport Layer 3-76
Causescosts of congestion scenario 3
another ldquocostrdquo of congestionwhen packet dropped any ldquoupstream transmission capacity used for that packet was wasted
Host A
Host B
λou
t
Transport Layer 3-77
Approaches towards congestion control
End-end congestion controlno explicit feedback from networkcongestion inferred from end-system observed loss delayapproach taken by TCP
Network-assisted congestion controlrouters provide feedback to end systems
single bit indicating congestion (SNA DECbit TCPIP ECN ATM)explicit rate sender should send at
Two broad approaches towards congestion control
Transport Layer 3-78
TCP Congestion Control
end-end control (no network assistance)sender limits transmissionLastByteSent-LastByteAcked
le CongWin
CongWin is dynamic function of perceived network congestion
How does sender perceive congestionloss event = timeout or3 duplicate acksTCP sender reduces rate (CongWin) after loss event
two modes of operationSlow Start (SS)Congestion avoidance (CA) or Additive Increase Multiplicative Decrease (AIMD)
Transport Layer 3-79
TCP congestion control bandwidth probing
ldquoprobing for bandwidthrdquo increase transmission rate on receipt of ACK until eventually loss occurs then decrease transmission rate
continue to increase on ACK decrease on loss (since available bandwidth is changing depending on other connections in network)
ACKs being received so increase rate
X
X
XX
X loss so decrease rate
send
ing
rate
time
Q how fast to increasedecreasedetails to follow
TCPrsquosldquosawtoothrdquobehavior
Transport Layer 3-80
TCP Congestion Control details
sender limits rate by limiting number of unACKed bytes ldquoin pipelinerdquo
cwnd differs from rwnd (how why)sender limited by min(cwndrwnd)
roughly
cwnd is dynamic function of perceived network congestion
rate = cwndRTT bytessec
LastByteSent-LastByteAcked le cwnd
cwndbytes
RTT
ACK(s)
Transport Layer 3-81
TCP Congestion Control more details
segment loss event reducing cwndtimeout no response from receiver
cut cwnd to 13 duplicate ACKs at least some segments getting through (recall fast retransmit)
cut cwnd in half less aggressively than on timeout
ACK received increase cwndTwo modes of operation
slowstart phase bull increase exponentially
fast (despite name) at connection start or following timeout
congestion avoidance bull increase linearly
Transport Layer 3-82
TCP Slow Start Phasewhen connection begins cwnd = 1 MSS
example MSS = 500 bytes amp RTT = 200 msecinitial rate = 20 kbps
available bandwidth may be gtgt MSSRTT
desirable to quickly ramp up to respectable rate
increase rate exponentially until first loss event or when threshold reached
double cwnd every RTTdone by incrementing cwnd by 1 for every ACK received
Host A
one segment
RTT
Host B
time
two segments
four segments
Transport Layer 3-83
Slow Start ExampleThe congestion window size grows very rapidly
For every ACK we increase CongWin by 1 irrespective of the number of segments ACKrsquoeddouble CongWinevery RTTinitial rate is slow but ramps up exponentially fast
TCP slows down the increase of CongWinwhen CongWin gt ssthresh
segment 1
ACK for segment 1
cwnd = 1
cwnd = 2 segment 2segment 3
ACK for segments 2
cwnd = 4 segment 4segment 5segment 6
ACK for segments 4
cwnd = 7
ACK for segments 3
ACK for segments 5
ACK for segments 6
cwnd = 3
cwnd = 5
cwnd = 6ACK for segments 7
cwnd = 8
segment 7
Transport Layer 3-84
TCP Congestion Avoidance Phase
when cwnd gt ssthreshgrow cwnd linearly
increase cwnd by 1 MSS per RTT approach possible congestion slower than in slowstartimplementation cwnd= cwnd + MSScwndfor each ACK received
ACKs increase cwndby 1 MSS per RTT additive increaseloss cut cwnd in half (non-timeout-detected loss ) multiplicative decrease
AIMD
AIMD Additive IncreaseMultiplicative Decrease
Transport Layer 3-85
Congestion AvoidanceCongestion avoidance phase is started if CongWin has reached the slow-start threshold value
If CongWin gt= ssthresh then each time an ACK is received increment CongWin as follows
bull CongWin = CongWin + 1CongWin (CongWin in segments)
bull In actual TCP implementation CongWin is in BytesCongWin = CongWin + MSS (MSSCongWin)
So CongWin is increased by one only if all CongWinsegments have been acknowledged
Transport Layer 3-86
Example Slow StartCongestion AvoidanceAssume that
ssthresh = 8
cwnd = 1
cwnd = 2
cwnd = 4
cwnd = 8
cwnd = 9
cwnd = 10
02468
101214
t=0
t=2
t=4
t=6
Roundtrip times
Cw
nd(in
seg
men
ts)
ssthresh
cwnd = 3
cwnd = 5cwnd = 6cwnd = 7
Transport Layer 3-87
Slow Start Congestion AvoidanceA typical plot of CongWin for a TCP connection
(MSS = 1500 bytes) with TCP Tahoe
SS
CA
ssthresh
Transport Layer 3-88
Responses to CongestionTCP assumes there is congestion if it detects a packet lossA TCP sender can detect lost packets via loss events
bull Timeout of a retransmission timerbull Receipt of 3 duplicate ACKs (fast retransmit)
TCP interprets a Timeout as a binary congestion signal When a timeout occurs the sender performs
ssthresh is set to half the current size of the congestion window
ssthresh = CongWin 2CongWin is reset to one
CongWin = 1and slow-start is entered
Transport Layer 3-89
Fast Recovery (differentiation btwn two loss events) After 3 dup ACKs (fast Retransmit)
ssthresh = CongWin2CongWin = CongWin2window then grows linearly
But after timeout eventCongWin = 1 MSS window then grows exponentiallyto the threshold then grows linearly
bull 3 dup ACKs indicates network capable of delivering some segmentsbull timeout before 3 dup ACKs is ldquomore alarmingrdquo
Philosophy
3-90
TCP Congestion ControlInitially
CongWin = 1ssthresh = advertised window size
New Ack receivedif (CongWin lt ssthresh) Slow Start
CongWin = CongWin + 1else Congestion Avoidance
CongWin = CongWin + 1CongWinTimeout
ssthresh = CongWin2CongWin = 1
Fast Retransmissionssthresh = CongWin2CongWin = CongWin2
Slow Start (exponential increase phase) is continued until CongWin reaches half of the level where the loss event occurred last time CongWin is increased slowly after (linear increase in Congestion Avoidance phase)
Transport Layer 3-91
Popular ldquoflavorsrdquo of TCP
ssthresh
ssthresh
TCP Tahoe
TCP Reno
Transmission round
cwnd
win
dow
siz
e (in
seg
men
ts)
Transport Layer 3-92
Summary TCP Congestion ControlWhen CongWin is below Threshold sender in slow-start phase window grows exponentiallyWhen CongWin is above Threshold sender is in congestion-avoidance phase window grows linearlyWhen a triple duplicate ACK occurs Threshold set to CongWin2 and CongWin set to ThresholdWhen timeout occurs Threshold set to CongWin2 and CongWin is set to 1 MSS The actual sender window size is determined based on the congestion and flow control algorithms
SenderWin=min(RcvWinCongWin)
Transport Layer 3-93
TCP Congestion Control SummaryEvent State TCP Sender Action Commentary
ACK receipt for previously unackeddata
Slow Start (SS)
CongWin = CongWin + MSS If (CongWin gt Threshold)
set state to ldquoCongestion Avoidancerdquo
Resulting in a doubling of CongWin every RTT
ACK receipt for previously unackeddata
CongestionAvoidance (CA)
CongWin = CongWin+MSS (MSSCongWin)
Additive increase resulting in increase of CongWin by 1 MSS every RTT
Loss event detected by triple duplicate ACK
SS or CA Threshold = CongWin2 CongWin = ThresholdSet state to ldquoCongestion Avoidancerdquo
Fast recovery implementing multiplicative decrease CongWin will not drop below 1 MSS
Timeout SS or CA Threshold = CongWin2 CongWin = 1 MSSSet state to ldquoSlow Startrdquo
Enter slow start
Duplicate ACK
SS or CA Increment duplicate ACK count for segment being acked
CongWin and Threshold not changed
Transport Layer 3-94
TCP throughput
Q whatrsquos average throughout of TCP as function of window size RTT
ignoring slow startlet W be window size when loss occurs
when window is W throughput is WRTTjust after loss window drops to W2 throughput to W2RTT average throughout 75 WRTT
Transport Layer 3-95
TCP Futures TCP over ldquolong fat pipesrdquo
example 1500 byte segments 100ms RTT want 10 Gbps throughputrequires window size W = 83333 in-flight segmentsthroughput in terms of loss rate
L = 210-10 Wownew versions of TCP for high-speed
LRTTMSSsdot221
Transport Layer 3-96
Fairness goal if K TCP sessions share same bottleneck link of bandwidth R each should have average rate of RK
TCP connection 1
bottleneckrouter
capacity R
TCP connection 2
TCP Fairness
Transport Layer 3-97
Why is TCP fairTwo competing sessions
Additive increase gives slope of 1 as throughout increasesmultiplicative decrease decreases throughput proportionally
R
R
equal bandwidth share
Connection 1 throughput
Conn
ecti
on 2
thr
ough
p ut
congestion avoidance additive increaseloss decrease window by factor of 2
congestion avoidance additive increaseloss decrease window by factor of 2
Transport Layer 3-98
Fairness (more)Fairness and UDP
Multimedia apps often do not use TCP
do not want rate throttled by congestion control
Instead use UDPpump audiovideo at constant rate tolerate packet loss
Research area TCP friendly
Fairness and parallel TCP connectionsnothing prevents app from opening parallel cnctionsbetween 2 hostsWeb browsers do this Example link of rate R supporting 9 cnctions
new app asks for 1 TCP gets rate R10new app asks for 11 TCPs gets R2
Transport Layer 3-99
TCP Connection ManagementRecall TCP sender receiver
establish ldquoconnectionrdquobefore exchanging data segmentsinitialize TCP variables
seq sbuffers flow control info (eg RcvWindow)
client connection initiatorSocket clientSocket = new Socket(hostnameport
number)
server contacted by clientSocket connectionSocket = welcomeSocketaccept()
Three way handshakeStep 1 client host sends TCP
SYN segment to serverspecifies initial seq no data
Step 2 server host receives SYN replies with SYNACK segment
server allocates buffersspecifies server initial seq
Step 3 client receives SYNACK replies with ACK segment which may contain data
Transport Layer 3-100
TCP Connection Management (cont)
Closing a connection
client closes socketclientSocketclose()
Step 1 client end system sends TCP FIN control segment to server
Step 2 server receives FIN replies with ACK Closes connection sends FIN
client
FIN
server
ACK
ACK
FIN
close
close
closed
tim
ed w
ait
Transport Layer 3-101
TCP Connection Management (cont)
Step 3 client receives FIN replies with ACK
Enters ldquotimed waitrdquo -will respond with ACK to received FINs
Step 4 server receives ACK Connection closed
client
FIN
server
ACK
ACK
FIN
closing
closing
closed
tim
ed w
ait
closed
Transport Layer 3-102
TCP Connection Management (cont)
TCP clientlifecycle
TCP serverlifecycle
Transport Layer 3-103
Tuning TCPIP Parameters TCPIP parameters
A set of default values may not be optimal for all applicationsThe network administrator may wish to turn on or off some TCPIP functions for performance or security considerations
Many Unix and Linux systems provide some flexibility in tuning the TCPIP kernelsbinsysctl is used to configure the Linux kernel parameters at runtime
Default kernel configuration file is sbinsysctlconfFrequently used sysctl options
bull sysctl ndasha or sysctl ndashA list all current valuesbull sysctl ndashp file_name load the sysctl setting from a configuration
filebull sysctl ndashw variable=value change the value of the parameter
Transport Layer 3-104
SomeTCP Parameters in Linux Kerneltcp_syn_retries
Number of SYN packets the kernel will send before giving up on the new connection
tcp_synack_retriesnumber of SYN+ACK packets sent before the kernel gives up on the connection
tcp_window_scalingMaximum window size of 65535 bytes not enough for for really fast networks The window scaling options allows for almost gigabyte windows which is good for connections with large delay-bandwidth product
tcp_max_syn_backlogMaximal number of remembered connection requests which still did not receive an acknowledgment from connecting client
tcp_fin_timeoutHow many seconds to wait for a final FIN packet before the socket is closed required to prevent denial-of-service (DoS) attacks Default value is 60 seconds
Transport Layer 3-105
SomeTCP Parameters in Linux Kerneltcp_rmem
This is a vector of 3 integers [min default max] These parameters are used by TCP to dynamically adjust receive buffer sizesmin - minimum size of the receive buffer used by each TCP socket The default value is 4K default - the default size of the receive buffer for a TCP socket The default value is 87380 bytes and is lowered to 43689 in low memory systems If larger receive buffer sizes are desired this value should be increased max - the maximum size of the receive buffer used by each TCP socket The default value of 873802 bytes is lowered to 87380 in low memory systems
tcp_smemSend buffer parameters [min default max] similar to tcp_rmem
- Chapter 3 Transport Layer
- Transport services and protocols
- Transport vs network layer
- Internet transport-layer protocols
- Multiplexingdemultiplexing
- How demultiplexing works
- Connectionless demultiplexing
- Connection-oriented demux
- Connection-oriented demux (cont)
- Connection-oriented demux Threaded Web Server
- UDP User Datagram Protocol [RFC 768]
- UDP more
- UDP checksum
- Principles of Reliable data transfer
- Reliable data transfer getting started
- Reliable data transfer getting started
- Rdt10 reliable transfer over a reliable channel
- Rdt20 channel with bit errors
- rdt20 FSM specification
- rdt20 operation with no errors
- rdt20 error scenario
- rdt20 has a fatal flaw
- rdt21 sender handles garbled ACKNAKs
- rdt21 receiver handles garbled ACKNAKs
- rdt21 discussion
- rdt22 a NAK-free protocol
- rdt22 sender receiver fragments
- rdt30 channels with errors and loss
- rdt30 sender
- rdt30 in action
- rdt30 in action
- Performance of rdt30
- rdt30 stop-and-wait operation
- Pipelined protocols
- Pipelining increased utilization
- Go-Back-N
- GBN sender extended FSM
- GBN receiver extended FSM
- GBN inaction
- Selective Repeat
- Selective repeat sender receiver windows
- Selective repeat
- Selective repeat in action
- Selective repeat dilemma
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- TCP Overview RFCs 793 1122 1323 2018 2581
- TCP segment structure
- TCP seq rsquos and ACKs
- TCP Round Trip Time and Timeout
- TCP Round Trip Time and Timeout
- Example RTT estimation
- TCP Round Trip Time and Timeout
- TCP reliable data transfer
- TCP sender events
- TCP sender(simplified)
- TCP retransmission scenarios
- TCP retransmission scenarios (more)
- TCP ACK generation [RFC 1122 RFC 2581]
- Fast Retransmit
- Fast Retransmit
- Fast retransmit algorithm
- TCP Flow Control
- TCP Flow control how it works
- Sliding Window Flow Control Example
- Principles of Congestion Control
- Causescosts of congestion scenario 1
- Causescosts of congestion scenario 2
- Causescosts of congestion scenario 2
- Causescosts of congestion scenario 3
- Causescosts of congestion scenario 3
- Approaches towards congestion control
- TCP Congestion Control
- TCP congestion control bandwidth probing
- TCP Congestion Control details
- TCP Congestion Control more details
- TCP Slow Start Phase
- Slow Start Example
- TCP Congestion Avoidance Phase
- Congestion Avoidance
- Example Slow StartCongestion Avoidance
- Slow Start Congestion Avoidance
- Responses to Congestion
- Fast Recovery (differentiation btwn two loss events)
- TCP Congestion Control
- Popular ldquoflavorsrdquo of TCP
- Summary TCP Congestion Control
- TCP Congestion Control Summary
- TCP throughput
- TCP Futures TCP over ldquolong fat pipesrdquo
- TCP Fairness
- Why is TCP fair
- Fairness (more)
- TCP Connection Management
- TCP Connection Management (cont)
- TCP Connection Management (cont)
- TCP Connection Management (cont)
- Tuning TCPIP Parameters
- SomeTCP Parameters in Linux Kernel
- SomeTCP Parameters in Linux Kernel
-
Transport Layer 3-65
Fast Retransmit
Time-out period often relatively long
long delay before resending lost packet
Detect lost segments via duplicate ACKs
Sender often sends many segments back-to-backIf segment is lost there will likely be many duplicate ACKs
If sender receives 3 ACKs for the same data it supposes that segment after ACKeddata was lost
fast retransmit resend segment before timer expires
Transport Layer 3-66
Fast RetransmitResend a segment after 3 duplicate ACKs since a duplicate ACK means that an out-of sequence segment was receivedduplicate ACKs due to packet reorderingif window is small donrsquot get duplicate ACKs
Host A
tim
eout
Host B
time
X
resend seq X2
seq x1seq x2seq x3seq x4seq x5
ACK x1
ACK x1ACK x1ACK x1
tripleduplicate
ACKs
Transport Layer 3-67
event ACK received with ACK field value of y if (y gt SendBase)
SendBase = yif (there are currently not-yet-acknowledged segments)
start timer
else increment count of dup ACKs received for yif (count of dup ACKs received for y = 3)
resend segment with sequence number y
Fast retransmit algorithm
a duplicate ACK for already ACKed segment
fast retransmit
Transport Layer 3-68
TCP Flow Control
receive side of TCP connection has a receive buffer
speed-matching service matching the send rate to the receiving apprsquos drain rate
app process may be slow at reading from buffer
sender wonrsquot overflowreceiverrsquos buffer by
transmitting too muchtoo fast
flow control
Transport Layer 3-69
TCP Flow control how it works
(Suppose TCP receiver discards out-of-order segments)spare room in buffer
= RcvWin
= RcvBuffer-[LastByteRcvd -LastByteRead]
Rcvr advertises spare room by including value of RcvWin in segmentsSender limits unACKeddata to RcvWin
guarantees receive buffer doesnrsquot overflow
Transport Layer 3-70
Sliding Window Flow Control Example
3K
2K SeqNo=0
ReceiverBuffer
0 4KSendersends 2Kof data
2K
AckNo=2048 RcvWin=2048Sendersends 2Kof data 2K SeqNo=2048
4K
AckNo=4096 RcvWin=0
AckNo=4096 RcvWin=1024
Sender blocked
Transport Layer 3-71
Principles of Congestion Control
Congestioninformally ldquotoo many sources sending too much data too fast for network to handlerdquodifferent from flow controlmanifestations
lost packets (buffer overflow at routers)long delays (queueing in router buffers)
a top-10 problem
Transport Layer 3-72
Causescosts of congestion scenario 1
two senders two receiversone router infinite buffers no retransmission
large delays when congestedmaximum achievable throughput
unlimited shared output link buffers
Host Aλin original data
Host B
λout
Transport Layer 3-73
Causescosts of congestion scenario 2
one router finite buffers sender retransmission of lost packet
finite shared output link buffers
Host A λin original data
Host B
λout
λin original data plus retransmitted data
Transport Layer 3-74
Causescosts of congestion scenario 2always (goodput)ldquoperfectrdquo retransmission only when loss
retransmission of delayed (not lost) packet makes larger(than perfect case) for same
λin
λout=
λin
λoutgtλ
inλout
ldquocostsrdquo of congestionmore work (retrans) for given ldquogoodputrdquounneeded retransmissions link carries multiple copies of pkt
R2
R2λin
λ out
b
R2
R2λin
λ out
a
R2
R2λin
λ out
c
R4
R3
Transport Layer 3-75
Causescosts of congestion scenario 3four sendersmultihop pathstimeoutretransmit
λin
Q what happens as and increase λ
in
finite shared output link buffers
Host Aλin original data
Host B
λout
λin original data plus retransmitted data
Transport Layer 3-76
Causescosts of congestion scenario 3
another ldquocostrdquo of congestionwhen packet dropped any ldquoupstream transmission capacity used for that packet was wasted
Host A
Host B
λou
t
Transport Layer 3-77
Approaches towards congestion control
End-end congestion controlno explicit feedback from networkcongestion inferred from end-system observed loss delayapproach taken by TCP
Network-assisted congestion controlrouters provide feedback to end systems
single bit indicating congestion (SNA DECbit TCPIP ECN ATM)explicit rate sender should send at
Two broad approaches towards congestion control
Transport Layer 3-78
TCP Congestion Control
end-end control (no network assistance)sender limits transmissionLastByteSent-LastByteAcked
le CongWin
CongWin is dynamic function of perceived network congestion
How does sender perceive congestionloss event = timeout or3 duplicate acksTCP sender reduces rate (CongWin) after loss event
two modes of operationSlow Start (SS)Congestion avoidance (CA) or Additive Increase Multiplicative Decrease (AIMD)
Transport Layer 3-79
TCP congestion control bandwidth probing
ldquoprobing for bandwidthrdquo increase transmission rate on receipt of ACK until eventually loss occurs then decrease transmission rate
continue to increase on ACK decrease on loss (since available bandwidth is changing depending on other connections in network)
ACKs being received so increase rate
X
X
XX
X loss so decrease rate
send
ing
rate
time
Q how fast to increasedecreasedetails to follow
TCPrsquosldquosawtoothrdquobehavior
Transport Layer 3-80
TCP Congestion Control details
sender limits rate by limiting number of unACKed bytes ldquoin pipelinerdquo
cwnd differs from rwnd (how why)sender limited by min(cwndrwnd)
roughly
cwnd is dynamic function of perceived network congestion
rate = cwndRTT bytessec
LastByteSent-LastByteAcked le cwnd
cwndbytes
RTT
ACK(s)
Transport Layer 3-81
TCP Congestion Control more details
segment loss event reducing cwndtimeout no response from receiver
cut cwnd to 13 duplicate ACKs at least some segments getting through (recall fast retransmit)
cut cwnd in half less aggressively than on timeout
ACK received increase cwndTwo modes of operation
slowstart phase bull increase exponentially
fast (despite name) at connection start or following timeout
congestion avoidance bull increase linearly
Transport Layer 3-82
TCP Slow Start Phasewhen connection begins cwnd = 1 MSS
example MSS = 500 bytes amp RTT = 200 msecinitial rate = 20 kbps
available bandwidth may be gtgt MSSRTT
desirable to quickly ramp up to respectable rate
increase rate exponentially until first loss event or when threshold reached
double cwnd every RTTdone by incrementing cwnd by 1 for every ACK received
Host A
one segment
RTT
Host B
time
two segments
four segments
Transport Layer 3-83
Slow Start ExampleThe congestion window size grows very rapidly
For every ACK we increase CongWin by 1 irrespective of the number of segments ACKrsquoeddouble CongWinevery RTTinitial rate is slow but ramps up exponentially fast
TCP slows down the increase of CongWinwhen CongWin gt ssthresh
segment 1
ACK for segment 1
cwnd = 1
cwnd = 2 segment 2segment 3
ACK for segments 2
cwnd = 4 segment 4segment 5segment 6
ACK for segments 4
cwnd = 7
ACK for segments 3
ACK for segments 5
ACK for segments 6
cwnd = 3
cwnd = 5
cwnd = 6ACK for segments 7
cwnd = 8
segment 7
Transport Layer 3-84
TCP Congestion Avoidance Phase
when cwnd gt ssthreshgrow cwnd linearly
increase cwnd by 1 MSS per RTT approach possible congestion slower than in slowstartimplementation cwnd= cwnd + MSScwndfor each ACK received
ACKs increase cwndby 1 MSS per RTT additive increaseloss cut cwnd in half (non-timeout-detected loss ) multiplicative decrease
AIMD
AIMD Additive IncreaseMultiplicative Decrease
Transport Layer 3-85
Congestion AvoidanceCongestion avoidance phase is started if CongWin has reached the slow-start threshold value
If CongWin gt= ssthresh then each time an ACK is received increment CongWin as follows
bull CongWin = CongWin + 1CongWin (CongWin in segments)
bull In actual TCP implementation CongWin is in BytesCongWin = CongWin + MSS (MSSCongWin)
So CongWin is increased by one only if all CongWinsegments have been acknowledged
Transport Layer 3-86
Example Slow StartCongestion AvoidanceAssume that
ssthresh = 8
cwnd = 1
cwnd = 2
cwnd = 4
cwnd = 8
cwnd = 9
cwnd = 10
02468
101214
t=0
t=2
t=4
t=6
Roundtrip times
Cw
nd(in
seg
men
ts)
ssthresh
cwnd = 3
cwnd = 5cwnd = 6cwnd = 7
Transport Layer 3-87
Slow Start Congestion AvoidanceA typical plot of CongWin for a TCP connection
(MSS = 1500 bytes) with TCP Tahoe
SS
CA
ssthresh
Transport Layer 3-88
Responses to CongestionTCP assumes there is congestion if it detects a packet lossA TCP sender can detect lost packets via loss events
bull Timeout of a retransmission timerbull Receipt of 3 duplicate ACKs (fast retransmit)
TCP interprets a Timeout as a binary congestion signal When a timeout occurs the sender performs
ssthresh is set to half the current size of the congestion window
ssthresh = CongWin 2CongWin is reset to one
CongWin = 1and slow-start is entered
Transport Layer 3-89
Fast Recovery (differentiation btwn two loss events) After 3 dup ACKs (fast Retransmit)
ssthresh = CongWin2CongWin = CongWin2window then grows linearly
But after timeout eventCongWin = 1 MSS window then grows exponentiallyto the threshold then grows linearly
bull 3 dup ACKs indicates network capable of delivering some segmentsbull timeout before 3 dup ACKs is ldquomore alarmingrdquo
Philosophy
3-90
TCP Congestion ControlInitially
CongWin = 1ssthresh = advertised window size
New Ack receivedif (CongWin lt ssthresh) Slow Start
CongWin = CongWin + 1else Congestion Avoidance
CongWin = CongWin + 1CongWinTimeout
ssthresh = CongWin2CongWin = 1
Fast Retransmissionssthresh = CongWin2CongWin = CongWin2
Slow Start (exponential increase phase) is continued until CongWin reaches half of the level where the loss event occurred last time CongWin is increased slowly after (linear increase in Congestion Avoidance phase)
Transport Layer 3-91
Popular ldquoflavorsrdquo of TCP
ssthresh
ssthresh
TCP Tahoe
TCP Reno
Transmission round
cwnd
win
dow
siz
e (in
seg
men
ts)
Transport Layer 3-92
Summary TCP Congestion ControlWhen CongWin is below Threshold sender in slow-start phase window grows exponentiallyWhen CongWin is above Threshold sender is in congestion-avoidance phase window grows linearlyWhen a triple duplicate ACK occurs Threshold set to CongWin2 and CongWin set to ThresholdWhen timeout occurs Threshold set to CongWin2 and CongWin is set to 1 MSS The actual sender window size is determined based on the congestion and flow control algorithms
SenderWin=min(RcvWinCongWin)
Transport Layer 3-93
TCP Congestion Control SummaryEvent State TCP Sender Action Commentary
ACK receipt for previously unackeddata
Slow Start (SS)
CongWin = CongWin + MSS If (CongWin gt Threshold)
set state to ldquoCongestion Avoidancerdquo
Resulting in a doubling of CongWin every RTT
ACK receipt for previously unackeddata
CongestionAvoidance (CA)
CongWin = CongWin+MSS (MSSCongWin)
Additive increase resulting in increase of CongWin by 1 MSS every RTT
Loss event detected by triple duplicate ACK
SS or CA Threshold = CongWin2 CongWin = ThresholdSet state to ldquoCongestion Avoidancerdquo
Fast recovery implementing multiplicative decrease CongWin will not drop below 1 MSS
Timeout SS or CA Threshold = CongWin2 CongWin = 1 MSSSet state to ldquoSlow Startrdquo
Enter slow start
Duplicate ACK
SS or CA Increment duplicate ACK count for segment being acked
CongWin and Threshold not changed
Transport Layer 3-94
TCP throughput
Q whatrsquos average throughout of TCP as function of window size RTT
ignoring slow startlet W be window size when loss occurs
when window is W throughput is WRTTjust after loss window drops to W2 throughput to W2RTT average throughout 75 WRTT
Transport Layer 3-95
TCP Futures TCP over ldquolong fat pipesrdquo
example 1500 byte segments 100ms RTT want 10 Gbps throughputrequires window size W = 83333 in-flight segmentsthroughput in terms of loss rate
L = 210-10 Wownew versions of TCP for high-speed
LRTTMSSsdot221
Transport Layer 3-96
Fairness goal if K TCP sessions share same bottleneck link of bandwidth R each should have average rate of RK
TCP connection 1
bottleneckrouter
capacity R
TCP connection 2
TCP Fairness
Transport Layer 3-97
Why is TCP fairTwo competing sessions
Additive increase gives slope of 1 as throughout increasesmultiplicative decrease decreases throughput proportionally
R
R
equal bandwidth share
Connection 1 throughput
Conn
ecti
on 2
thr
ough
p ut
congestion avoidance additive increaseloss decrease window by factor of 2
congestion avoidance additive increaseloss decrease window by factor of 2
Transport Layer 3-98
Fairness (more)Fairness and UDP
Multimedia apps often do not use TCP
do not want rate throttled by congestion control
Instead use UDPpump audiovideo at constant rate tolerate packet loss
Research area TCP friendly
Fairness and parallel TCP connectionsnothing prevents app from opening parallel cnctionsbetween 2 hostsWeb browsers do this Example link of rate R supporting 9 cnctions
new app asks for 1 TCP gets rate R10new app asks for 11 TCPs gets R2
Transport Layer 3-99
TCP Connection ManagementRecall TCP sender receiver
establish ldquoconnectionrdquobefore exchanging data segmentsinitialize TCP variables
seq sbuffers flow control info (eg RcvWindow)
client connection initiatorSocket clientSocket = new Socket(hostnameport
number)
server contacted by clientSocket connectionSocket = welcomeSocketaccept()
Three way handshakeStep 1 client host sends TCP
SYN segment to serverspecifies initial seq no data
Step 2 server host receives SYN replies with SYNACK segment
server allocates buffersspecifies server initial seq
Step 3 client receives SYNACK replies with ACK segment which may contain data
Transport Layer 3-100
TCP Connection Management (cont)
Closing a connection
client closes socketclientSocketclose()
Step 1 client end system sends TCP FIN control segment to server
Step 2 server receives FIN replies with ACK Closes connection sends FIN
client
FIN
server
ACK
ACK
FIN
close
close
closed
tim
ed w
ait
Transport Layer 3-101
TCP Connection Management (cont)
Step 3 client receives FIN replies with ACK
Enters ldquotimed waitrdquo -will respond with ACK to received FINs
Step 4 server receives ACK Connection closed
client
FIN
server
ACK
ACK
FIN
closing
closing
closed
tim
ed w
ait
closed
Transport Layer 3-102
TCP Connection Management (cont)
TCP clientlifecycle
TCP serverlifecycle
Transport Layer 3-103
Tuning TCPIP Parameters TCPIP parameters
A set of default values may not be optimal for all applicationsThe network administrator may wish to turn on or off some TCPIP functions for performance or security considerations
Many Unix and Linux systems provide some flexibility in tuning the TCPIP kernelsbinsysctl is used to configure the Linux kernel parameters at runtime
Default kernel configuration file is sbinsysctlconfFrequently used sysctl options
bull sysctl ndasha or sysctl ndashA list all current valuesbull sysctl ndashp file_name load the sysctl setting from a configuration
filebull sysctl ndashw variable=value change the value of the parameter
Transport Layer 3-104
SomeTCP Parameters in Linux Kerneltcp_syn_retries
Number of SYN packets the kernel will send before giving up on the new connection
tcp_synack_retriesnumber of SYN+ACK packets sent before the kernel gives up on the connection
tcp_window_scalingMaximum window size of 65535 bytes not enough for for really fast networks The window scaling options allows for almost gigabyte windows which is good for connections with large delay-bandwidth product
tcp_max_syn_backlogMaximal number of remembered connection requests which still did not receive an acknowledgment from connecting client
tcp_fin_timeoutHow many seconds to wait for a final FIN packet before the socket is closed required to prevent denial-of-service (DoS) attacks Default value is 60 seconds
Transport Layer 3-105
SomeTCP Parameters in Linux Kerneltcp_rmem
This is a vector of 3 integers [min default max] These parameters are used by TCP to dynamically adjust receive buffer sizesmin - minimum size of the receive buffer used by each TCP socket The default value is 4K default - the default size of the receive buffer for a TCP socket The default value is 87380 bytes and is lowered to 43689 in low memory systems If larger receive buffer sizes are desired this value should be increased max - the maximum size of the receive buffer used by each TCP socket The default value of 873802 bytes is lowered to 87380 in low memory systems
tcp_smemSend buffer parameters [min default max] similar to tcp_rmem
- Chapter 3 Transport Layer
- Transport services and protocols
- Transport vs network layer
- Internet transport-layer protocols
- Multiplexingdemultiplexing
- How demultiplexing works
- Connectionless demultiplexing
- Connection-oriented demux
- Connection-oriented demux (cont)
- Connection-oriented demux Threaded Web Server
- UDP User Datagram Protocol [RFC 768]
- UDP more
- UDP checksum
- Principles of Reliable data transfer
- Reliable data transfer getting started
- Reliable data transfer getting started
- Rdt10 reliable transfer over a reliable channel
- Rdt20 channel with bit errors
- rdt20 FSM specification
- rdt20 operation with no errors
- rdt20 error scenario
- rdt20 has a fatal flaw
- rdt21 sender handles garbled ACKNAKs
- rdt21 receiver handles garbled ACKNAKs
- rdt21 discussion
- rdt22 a NAK-free protocol
- rdt22 sender receiver fragments
- rdt30 channels with errors and loss
- rdt30 sender
- rdt30 in action
- rdt30 in action
- Performance of rdt30
- rdt30 stop-and-wait operation
- Pipelined protocols
- Pipelining increased utilization
- Go-Back-N
- GBN sender extended FSM
- GBN receiver extended FSM
- GBN inaction
- Selective Repeat
- Selective repeat sender receiver windows
- Selective repeat
- Selective repeat in action
- Selective repeat dilemma
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- TCP Overview RFCs 793 1122 1323 2018 2581
- TCP segment structure
- TCP seq rsquos and ACKs
- TCP Round Trip Time and Timeout
- TCP Round Trip Time and Timeout
- Example RTT estimation
- TCP Round Trip Time and Timeout
- TCP reliable data transfer
- TCP sender events
- TCP sender(simplified)
- TCP retransmission scenarios
- TCP retransmission scenarios (more)
- TCP ACK generation [RFC 1122 RFC 2581]
- Fast Retransmit
- Fast Retransmit
- Fast retransmit algorithm
- TCP Flow Control
- TCP Flow control how it works
- Sliding Window Flow Control Example
- Principles of Congestion Control
- Causescosts of congestion scenario 1
- Causescosts of congestion scenario 2
- Causescosts of congestion scenario 2
- Causescosts of congestion scenario 3
- Causescosts of congestion scenario 3
- Approaches towards congestion control
- TCP Congestion Control
- TCP congestion control bandwidth probing
- TCP Congestion Control details
- TCP Congestion Control more details
- TCP Slow Start Phase
- Slow Start Example
- TCP Congestion Avoidance Phase
- Congestion Avoidance
- Example Slow StartCongestion Avoidance
- Slow Start Congestion Avoidance
- Responses to Congestion
- Fast Recovery (differentiation btwn two loss events)
- TCP Congestion Control
- Popular ldquoflavorsrdquo of TCP
- Summary TCP Congestion Control
- TCP Congestion Control Summary
- TCP throughput
- TCP Futures TCP over ldquolong fat pipesrdquo
- TCP Fairness
- Why is TCP fair
- Fairness (more)
- TCP Connection Management
- TCP Connection Management (cont)
- TCP Connection Management (cont)
- TCP Connection Management (cont)
- Tuning TCPIP Parameters
- SomeTCP Parameters in Linux Kernel
- SomeTCP Parameters in Linux Kernel
-
Transport Layer 3-66
Fast RetransmitResend a segment after 3 duplicate ACKs since a duplicate ACK means that an out-of sequence segment was receivedduplicate ACKs due to packet reorderingif window is small donrsquot get duplicate ACKs
Host A
tim
eout
Host B
time
X
resend seq X2
seq x1seq x2seq x3seq x4seq x5
ACK x1
ACK x1ACK x1ACK x1
tripleduplicate
ACKs
Transport Layer 3-67
event ACK received with ACK field value of y if (y gt SendBase)
SendBase = yif (there are currently not-yet-acknowledged segments)
start timer
else increment count of dup ACKs received for yif (count of dup ACKs received for y = 3)
resend segment with sequence number y
Fast retransmit algorithm
a duplicate ACK for already ACKed segment
fast retransmit
Transport Layer 3-68
TCP Flow Control
receive side of TCP connection has a receive buffer
speed-matching service matching the send rate to the receiving apprsquos drain rate
app process may be slow at reading from buffer
sender wonrsquot overflowreceiverrsquos buffer by
transmitting too muchtoo fast
flow control
Transport Layer 3-69
TCP Flow control how it works
(Suppose TCP receiver discards out-of-order segments)spare room in buffer
= RcvWin
= RcvBuffer-[LastByteRcvd -LastByteRead]
Rcvr advertises spare room by including value of RcvWin in segmentsSender limits unACKeddata to RcvWin
guarantees receive buffer doesnrsquot overflow
Transport Layer 3-70
Sliding Window Flow Control Example
3K
2K SeqNo=0
ReceiverBuffer
0 4KSendersends 2Kof data
2K
AckNo=2048 RcvWin=2048Sendersends 2Kof data 2K SeqNo=2048
4K
AckNo=4096 RcvWin=0
AckNo=4096 RcvWin=1024
Sender blocked
Transport Layer 3-71
Principles of Congestion Control
Congestioninformally ldquotoo many sources sending too much data too fast for network to handlerdquodifferent from flow controlmanifestations
lost packets (buffer overflow at routers)long delays (queueing in router buffers)
a top-10 problem
Transport Layer 3-72
Causescosts of congestion scenario 1
two senders two receiversone router infinite buffers no retransmission
large delays when congestedmaximum achievable throughput
unlimited shared output link buffers
Host Aλin original data
Host B
λout
Transport Layer 3-73
Causescosts of congestion scenario 2
one router finite buffers sender retransmission of lost packet
finite shared output link buffers
Host A λin original data
Host B
λout
λin original data plus retransmitted data
Transport Layer 3-74
Causescosts of congestion scenario 2always (goodput)ldquoperfectrdquo retransmission only when loss
retransmission of delayed (not lost) packet makes larger(than perfect case) for same
λin
λout=
λin
λoutgtλ
inλout
ldquocostsrdquo of congestionmore work (retrans) for given ldquogoodputrdquounneeded retransmissions link carries multiple copies of pkt
R2
R2λin
λ out
b
R2
R2λin
λ out
a
R2
R2λin
λ out
c
R4
R3
Transport Layer 3-75
Causescosts of congestion scenario 3four sendersmultihop pathstimeoutretransmit
λin
Q what happens as and increase λ
in
finite shared output link buffers
Host Aλin original data
Host B
λout
λin original data plus retransmitted data
Transport Layer 3-76
Causescosts of congestion scenario 3
another ldquocostrdquo of congestionwhen packet dropped any ldquoupstream transmission capacity used for that packet was wasted
Host A
Host B
λou
t
Transport Layer 3-77
Approaches towards congestion control
End-end congestion controlno explicit feedback from networkcongestion inferred from end-system observed loss delayapproach taken by TCP
Network-assisted congestion controlrouters provide feedback to end systems
single bit indicating congestion (SNA DECbit TCPIP ECN ATM)explicit rate sender should send at
Two broad approaches towards congestion control
Transport Layer 3-78
TCP Congestion Control
end-end control (no network assistance)sender limits transmissionLastByteSent-LastByteAcked
le CongWin
CongWin is dynamic function of perceived network congestion
How does sender perceive congestionloss event = timeout or3 duplicate acksTCP sender reduces rate (CongWin) after loss event
two modes of operationSlow Start (SS)Congestion avoidance (CA) or Additive Increase Multiplicative Decrease (AIMD)
Transport Layer 3-79
TCP congestion control bandwidth probing
ldquoprobing for bandwidthrdquo increase transmission rate on receipt of ACK until eventually loss occurs then decrease transmission rate
continue to increase on ACK decrease on loss (since available bandwidth is changing depending on other connections in network)
ACKs being received so increase rate
X
X
XX
X loss so decrease rate
send
ing
rate
time
Q how fast to increasedecreasedetails to follow
TCPrsquosldquosawtoothrdquobehavior
Transport Layer 3-80
TCP Congestion Control details
sender limits rate by limiting number of unACKed bytes ldquoin pipelinerdquo
cwnd differs from rwnd (how why)sender limited by min(cwndrwnd)
roughly
cwnd is dynamic function of perceived network congestion
rate = cwndRTT bytessec
LastByteSent-LastByteAcked le cwnd
cwndbytes
RTT
ACK(s)
Transport Layer 3-81
TCP Congestion Control more details
segment loss event reducing cwndtimeout no response from receiver
cut cwnd to 13 duplicate ACKs at least some segments getting through (recall fast retransmit)
cut cwnd in half less aggressively than on timeout
ACK received increase cwndTwo modes of operation
slowstart phase bull increase exponentially
fast (despite name) at connection start or following timeout
congestion avoidance bull increase linearly
Transport Layer 3-82
TCP Slow Start Phasewhen connection begins cwnd = 1 MSS
example MSS = 500 bytes amp RTT = 200 msecinitial rate = 20 kbps
available bandwidth may be gtgt MSSRTT
desirable to quickly ramp up to respectable rate
increase rate exponentially until first loss event or when threshold reached
double cwnd every RTTdone by incrementing cwnd by 1 for every ACK received
Host A
one segment
RTT
Host B
time
two segments
four segments
Transport Layer 3-83
Slow Start ExampleThe congestion window size grows very rapidly
For every ACK we increase CongWin by 1 irrespective of the number of segments ACKrsquoeddouble CongWinevery RTTinitial rate is slow but ramps up exponentially fast
TCP slows down the increase of CongWinwhen CongWin gt ssthresh
segment 1
ACK for segment 1
cwnd = 1
cwnd = 2 segment 2segment 3
ACK for segments 2
cwnd = 4 segment 4segment 5segment 6
ACK for segments 4
cwnd = 7
ACK for segments 3
ACK for segments 5
ACK for segments 6
cwnd = 3
cwnd = 5
cwnd = 6ACK for segments 7
cwnd = 8
segment 7
Transport Layer 3-84
TCP Congestion Avoidance Phase
when cwnd gt ssthreshgrow cwnd linearly
increase cwnd by 1 MSS per RTT approach possible congestion slower than in slowstartimplementation cwnd= cwnd + MSScwndfor each ACK received
ACKs increase cwndby 1 MSS per RTT additive increaseloss cut cwnd in half (non-timeout-detected loss ) multiplicative decrease
AIMD
AIMD Additive IncreaseMultiplicative Decrease
Transport Layer 3-85
Congestion AvoidanceCongestion avoidance phase is started if CongWin has reached the slow-start threshold value
If CongWin gt= ssthresh then each time an ACK is received increment CongWin as follows
bull CongWin = CongWin + 1CongWin (CongWin in segments)
bull In actual TCP implementation CongWin is in BytesCongWin = CongWin + MSS (MSSCongWin)
So CongWin is increased by one only if all CongWinsegments have been acknowledged
Transport Layer 3-86
Example Slow StartCongestion AvoidanceAssume that
ssthresh = 8
cwnd = 1
cwnd = 2
cwnd = 4
cwnd = 8
cwnd = 9
cwnd = 10
02468
101214
t=0
t=2
t=4
t=6
Roundtrip times
Cw
nd(in
seg
men
ts)
ssthresh
cwnd = 3
cwnd = 5cwnd = 6cwnd = 7
Transport Layer 3-87
Slow Start Congestion AvoidanceA typical plot of CongWin for a TCP connection
(MSS = 1500 bytes) with TCP Tahoe
SS
CA
ssthresh
Transport Layer 3-88
Responses to CongestionTCP assumes there is congestion if it detects a packet lossA TCP sender can detect lost packets via loss events
bull Timeout of a retransmission timerbull Receipt of 3 duplicate ACKs (fast retransmit)
TCP interprets a Timeout as a binary congestion signal When a timeout occurs the sender performs
ssthresh is set to half the current size of the congestion window
ssthresh = CongWin 2CongWin is reset to one
CongWin = 1and slow-start is entered
Transport Layer 3-89
Fast Recovery (differentiation btwn two loss events) After 3 dup ACKs (fast Retransmit)
ssthresh = CongWin2CongWin = CongWin2window then grows linearly
But after timeout eventCongWin = 1 MSS window then grows exponentiallyto the threshold then grows linearly
bull 3 dup ACKs indicates network capable of delivering some segmentsbull timeout before 3 dup ACKs is ldquomore alarmingrdquo
Philosophy
3-90
TCP Congestion ControlInitially
CongWin = 1ssthresh = advertised window size
New Ack receivedif (CongWin lt ssthresh) Slow Start
CongWin = CongWin + 1else Congestion Avoidance
CongWin = CongWin + 1CongWinTimeout
ssthresh = CongWin2CongWin = 1
Fast Retransmissionssthresh = CongWin2CongWin = CongWin2
Slow Start (exponential increase phase) is continued until CongWin reaches half of the level where the loss event occurred last time CongWin is increased slowly after (linear increase in Congestion Avoidance phase)
Transport Layer 3-91
Popular ldquoflavorsrdquo of TCP
ssthresh
ssthresh
TCP Tahoe
TCP Reno
Transmission round
cwnd
win
dow
siz
e (in
seg
men
ts)
Transport Layer 3-92
Summary TCP Congestion ControlWhen CongWin is below Threshold sender in slow-start phase window grows exponentiallyWhen CongWin is above Threshold sender is in congestion-avoidance phase window grows linearlyWhen a triple duplicate ACK occurs Threshold set to CongWin2 and CongWin set to ThresholdWhen timeout occurs Threshold set to CongWin2 and CongWin is set to 1 MSS The actual sender window size is determined based on the congestion and flow control algorithms
SenderWin=min(RcvWinCongWin)
Transport Layer 3-93
TCP Congestion Control SummaryEvent State TCP Sender Action Commentary
ACK receipt for previously unackeddata
Slow Start (SS)
CongWin = CongWin + MSS If (CongWin gt Threshold)
set state to ldquoCongestion Avoidancerdquo
Resulting in a doubling of CongWin every RTT
ACK receipt for previously unackeddata
CongestionAvoidance (CA)
CongWin = CongWin+MSS (MSSCongWin)
Additive increase resulting in increase of CongWin by 1 MSS every RTT
Loss event detected by triple duplicate ACK
SS or CA Threshold = CongWin2 CongWin = ThresholdSet state to ldquoCongestion Avoidancerdquo
Fast recovery implementing multiplicative decrease CongWin will not drop below 1 MSS
Timeout SS or CA Threshold = CongWin2 CongWin = 1 MSSSet state to ldquoSlow Startrdquo
Enter slow start
Duplicate ACK
SS or CA Increment duplicate ACK count for segment being acked
CongWin and Threshold not changed
Transport Layer 3-94
TCP throughput
Q whatrsquos average throughout of TCP as function of window size RTT
ignoring slow startlet W be window size when loss occurs
when window is W throughput is WRTTjust after loss window drops to W2 throughput to W2RTT average throughout 75 WRTT
Transport Layer 3-95
TCP Futures TCP over ldquolong fat pipesrdquo
example 1500 byte segments 100ms RTT want 10 Gbps throughputrequires window size W = 83333 in-flight segmentsthroughput in terms of loss rate
L = 210-10 Wownew versions of TCP for high-speed
LRTTMSSsdot221
Transport Layer 3-96
Fairness goal if K TCP sessions share same bottleneck link of bandwidth R each should have average rate of RK
TCP connection 1
bottleneckrouter
capacity R
TCP connection 2
TCP Fairness
Transport Layer 3-97
Why is TCP fairTwo competing sessions
Additive increase gives slope of 1 as throughout increasesmultiplicative decrease decreases throughput proportionally
R
R
equal bandwidth share
Connection 1 throughput
Conn
ecti
on 2
thr
ough
p ut
congestion avoidance additive increaseloss decrease window by factor of 2
congestion avoidance additive increaseloss decrease window by factor of 2
Transport Layer 3-98
Fairness (more)Fairness and UDP
Multimedia apps often do not use TCP
do not want rate throttled by congestion control
Instead use UDPpump audiovideo at constant rate tolerate packet loss
Research area TCP friendly
Fairness and parallel TCP connectionsnothing prevents app from opening parallel cnctionsbetween 2 hostsWeb browsers do this Example link of rate R supporting 9 cnctions
new app asks for 1 TCP gets rate R10new app asks for 11 TCPs gets R2
Transport Layer 3-99
TCP Connection ManagementRecall TCP sender receiver
establish ldquoconnectionrdquobefore exchanging data segmentsinitialize TCP variables
seq sbuffers flow control info (eg RcvWindow)
client connection initiatorSocket clientSocket = new Socket(hostnameport
number)
server contacted by clientSocket connectionSocket = welcomeSocketaccept()
Three way handshakeStep 1 client host sends TCP
SYN segment to serverspecifies initial seq no data
Step 2 server host receives SYN replies with SYNACK segment
server allocates buffersspecifies server initial seq
Step 3 client receives SYNACK replies with ACK segment which may contain data
Transport Layer 3-100
TCP Connection Management (cont)
Closing a connection
client closes socketclientSocketclose()
Step 1 client end system sends TCP FIN control segment to server
Step 2 server receives FIN replies with ACK Closes connection sends FIN
client
FIN
server
ACK
ACK
FIN
close
close
closed
tim
ed w
ait
Transport Layer 3-101
TCP Connection Management (cont)
Step 3 client receives FIN replies with ACK
Enters ldquotimed waitrdquo -will respond with ACK to received FINs
Step 4 server receives ACK Connection closed
client
FIN
server
ACK
ACK
FIN
closing
closing
closed
tim
ed w
ait
closed
Transport Layer 3-102
TCP Connection Management (cont)
TCP clientlifecycle
TCP serverlifecycle
Transport Layer 3-103
Tuning TCPIP Parameters TCPIP parameters
A set of default values may not be optimal for all applicationsThe network administrator may wish to turn on or off some TCPIP functions for performance or security considerations
Many Unix and Linux systems provide some flexibility in tuning the TCPIP kernelsbinsysctl is used to configure the Linux kernel parameters at runtime
Default kernel configuration file is sbinsysctlconfFrequently used sysctl options
bull sysctl ndasha or sysctl ndashA list all current valuesbull sysctl ndashp file_name load the sysctl setting from a configuration
filebull sysctl ndashw variable=value change the value of the parameter
Transport Layer 3-104
SomeTCP Parameters in Linux Kerneltcp_syn_retries
Number of SYN packets the kernel will send before giving up on the new connection
tcp_synack_retriesnumber of SYN+ACK packets sent before the kernel gives up on the connection
tcp_window_scalingMaximum window size of 65535 bytes not enough for for really fast networks The window scaling options allows for almost gigabyte windows which is good for connections with large delay-bandwidth product
tcp_max_syn_backlogMaximal number of remembered connection requests which still did not receive an acknowledgment from connecting client
tcp_fin_timeoutHow many seconds to wait for a final FIN packet before the socket is closed required to prevent denial-of-service (DoS) attacks Default value is 60 seconds
Transport Layer 3-105
SomeTCP Parameters in Linux Kerneltcp_rmem
This is a vector of 3 integers [min default max] These parameters are used by TCP to dynamically adjust receive buffer sizesmin - minimum size of the receive buffer used by each TCP socket The default value is 4K default - the default size of the receive buffer for a TCP socket The default value is 87380 bytes and is lowered to 43689 in low memory systems If larger receive buffer sizes are desired this value should be increased max - the maximum size of the receive buffer used by each TCP socket The default value of 873802 bytes is lowered to 87380 in low memory systems
tcp_smemSend buffer parameters [min default max] similar to tcp_rmem
- Chapter 3 Transport Layer
- Transport services and protocols
- Transport vs network layer
- Internet transport-layer protocols
- Multiplexingdemultiplexing
- How demultiplexing works
- Connectionless demultiplexing
- Connection-oriented demux
- Connection-oriented demux (cont)
- Connection-oriented demux Threaded Web Server
- UDP User Datagram Protocol [RFC 768]
- UDP more
- UDP checksum
- Principles of Reliable data transfer
- Reliable data transfer getting started
- Reliable data transfer getting started
- Rdt10 reliable transfer over a reliable channel
- Rdt20 channel with bit errors
- rdt20 FSM specification
- rdt20 operation with no errors
- rdt20 error scenario
- rdt20 has a fatal flaw
- rdt21 sender handles garbled ACKNAKs
- rdt21 receiver handles garbled ACKNAKs
- rdt21 discussion
- rdt22 a NAK-free protocol
- rdt22 sender receiver fragments
- rdt30 channels with errors and loss
- rdt30 sender
- rdt30 in action
- rdt30 in action
- Performance of rdt30
- rdt30 stop-and-wait operation
- Pipelined protocols
- Pipelining increased utilization
- Go-Back-N
- GBN sender extended FSM
- GBN receiver extended FSM
- GBN inaction
- Selective Repeat
- Selective repeat sender receiver windows
- Selective repeat
- Selective repeat in action
- Selective repeat dilemma
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- TCP Overview RFCs 793 1122 1323 2018 2581
- TCP segment structure
- TCP seq rsquos and ACKs
- TCP Round Trip Time and Timeout
- TCP Round Trip Time and Timeout
- Example RTT estimation
- TCP Round Trip Time and Timeout
- TCP reliable data transfer
- TCP sender events
- TCP sender(simplified)
- TCP retransmission scenarios
- TCP retransmission scenarios (more)
- TCP ACK generation [RFC 1122 RFC 2581]
- Fast Retransmit
- Fast Retransmit
- Fast retransmit algorithm
- TCP Flow Control
- TCP Flow control how it works
- Sliding Window Flow Control Example
- Principles of Congestion Control
- Causescosts of congestion scenario 1
- Causescosts of congestion scenario 2
- Causescosts of congestion scenario 2
- Causescosts of congestion scenario 3
- Causescosts of congestion scenario 3
- Approaches towards congestion control
- TCP Congestion Control
- TCP congestion control bandwidth probing
- TCP Congestion Control details
- TCP Congestion Control more details
- TCP Slow Start Phase
- Slow Start Example
- TCP Congestion Avoidance Phase
- Congestion Avoidance
- Example Slow StartCongestion Avoidance
- Slow Start Congestion Avoidance
- Responses to Congestion
- Fast Recovery (differentiation btwn two loss events)
- TCP Congestion Control
- Popular ldquoflavorsrdquo of TCP
- Summary TCP Congestion Control
- TCP Congestion Control Summary
- TCP throughput
- TCP Futures TCP over ldquolong fat pipesrdquo
- TCP Fairness
- Why is TCP fair
- Fairness (more)
- TCP Connection Management
- TCP Connection Management (cont)
- TCP Connection Management (cont)
- TCP Connection Management (cont)
- Tuning TCPIP Parameters
- SomeTCP Parameters in Linux Kernel
- SomeTCP Parameters in Linux Kernel
-
Transport Layer 3-67
event ACK received with ACK field value of y if (y gt SendBase)
SendBase = yif (there are currently not-yet-acknowledged segments)
start timer
else increment count of dup ACKs received for yif (count of dup ACKs received for y = 3)
resend segment with sequence number y
Fast retransmit algorithm
a duplicate ACK for already ACKed segment
fast retransmit
Transport Layer 3-68
TCP Flow Control
receive side of TCP connection has a receive buffer
speed-matching service matching the send rate to the receiving apprsquos drain rate
app process may be slow at reading from buffer
sender wonrsquot overflowreceiverrsquos buffer by
transmitting too muchtoo fast
flow control
Transport Layer 3-69
TCP Flow control how it works
(Suppose TCP receiver discards out-of-order segments)spare room in buffer
= RcvWin
= RcvBuffer-[LastByteRcvd -LastByteRead]
Rcvr advertises spare room by including value of RcvWin in segmentsSender limits unACKeddata to RcvWin
guarantees receive buffer doesnrsquot overflow
Transport Layer 3-70
Sliding Window Flow Control Example
3K
2K SeqNo=0
ReceiverBuffer
0 4KSendersends 2Kof data
2K
AckNo=2048 RcvWin=2048Sendersends 2Kof data 2K SeqNo=2048
4K
AckNo=4096 RcvWin=0
AckNo=4096 RcvWin=1024
Sender blocked
Transport Layer 3-71
Principles of Congestion Control
Congestioninformally ldquotoo many sources sending too much data too fast for network to handlerdquodifferent from flow controlmanifestations
lost packets (buffer overflow at routers)long delays (queueing in router buffers)
a top-10 problem
Transport Layer 3-72
Causescosts of congestion scenario 1
two senders two receiversone router infinite buffers no retransmission
large delays when congestedmaximum achievable throughput
unlimited shared output link buffers
Host Aλin original data
Host B
λout
Transport Layer 3-73
Causescosts of congestion scenario 2
one router finite buffers sender retransmission of lost packet
finite shared output link buffers
Host A λin original data
Host B
λout
λin original data plus retransmitted data
Transport Layer 3-74
Causescosts of congestion scenario 2always (goodput)ldquoperfectrdquo retransmission only when loss
retransmission of delayed (not lost) packet makes larger(than perfect case) for same
λin
λout=
λin
λoutgtλ
inλout
ldquocostsrdquo of congestionmore work (retrans) for given ldquogoodputrdquounneeded retransmissions link carries multiple copies of pkt
R2
R2λin
λ out
b
R2
R2λin
λ out
a
R2
R2λin
λ out
c
R4
R3
Transport Layer 3-75
Causescosts of congestion scenario 3four sendersmultihop pathstimeoutretransmit
λin
Q what happens as and increase λ
in
finite shared output link buffers
Host Aλin original data
Host B
λout
λin original data plus retransmitted data
Transport Layer 3-76
Causescosts of congestion scenario 3
another ldquocostrdquo of congestionwhen packet dropped any ldquoupstream transmission capacity used for that packet was wasted
Host A
Host B
λou
t
Transport Layer 3-77
Approaches towards congestion control
End-end congestion controlno explicit feedback from networkcongestion inferred from end-system observed loss delayapproach taken by TCP
Network-assisted congestion controlrouters provide feedback to end systems
single bit indicating congestion (SNA DECbit TCPIP ECN ATM)explicit rate sender should send at
Two broad approaches towards congestion control
Transport Layer 3-78
TCP Congestion Control
end-end control (no network assistance)sender limits transmissionLastByteSent-LastByteAcked
le CongWin
CongWin is dynamic function of perceived network congestion
How does sender perceive congestionloss event = timeout or3 duplicate acksTCP sender reduces rate (CongWin) after loss event
two modes of operationSlow Start (SS)Congestion avoidance (CA) or Additive Increase Multiplicative Decrease (AIMD)
Transport Layer 3-79
TCP congestion control bandwidth probing
ldquoprobing for bandwidthrdquo increase transmission rate on receipt of ACK until eventually loss occurs then decrease transmission rate
continue to increase on ACK decrease on loss (since available bandwidth is changing depending on other connections in network)
ACKs being received so increase rate
X
X
XX
X loss so decrease rate
send
ing
rate
time
Q how fast to increasedecreasedetails to follow
TCPrsquosldquosawtoothrdquobehavior
Transport Layer 3-80
TCP Congestion Control details
sender limits rate by limiting number of unACKed bytes ldquoin pipelinerdquo
cwnd differs from rwnd (how why)sender limited by min(cwndrwnd)
roughly
cwnd is dynamic function of perceived network congestion
rate = cwndRTT bytessec
LastByteSent-LastByteAcked le cwnd
cwndbytes
RTT
ACK(s)
Transport Layer 3-81
TCP Congestion Control more details
segment loss event reducing cwndtimeout no response from receiver
cut cwnd to 13 duplicate ACKs at least some segments getting through (recall fast retransmit)
cut cwnd in half less aggressively than on timeout
ACK received increase cwndTwo modes of operation
slowstart phase bull increase exponentially
fast (despite name) at connection start or following timeout
congestion avoidance bull increase linearly
Transport Layer 3-82
TCP Slow Start Phasewhen connection begins cwnd = 1 MSS
example MSS = 500 bytes amp RTT = 200 msecinitial rate = 20 kbps
available bandwidth may be gtgt MSSRTT
desirable to quickly ramp up to respectable rate
increase rate exponentially until first loss event or when threshold reached
double cwnd every RTTdone by incrementing cwnd by 1 for every ACK received
Host A
one segment
RTT
Host B
time
two segments
four segments
Transport Layer 3-83
Slow Start ExampleThe congestion window size grows very rapidly
For every ACK we increase CongWin by 1 irrespective of the number of segments ACKrsquoeddouble CongWinevery RTTinitial rate is slow but ramps up exponentially fast
TCP slows down the increase of CongWinwhen CongWin gt ssthresh
segment 1
ACK for segment 1
cwnd = 1
cwnd = 2 segment 2segment 3
ACK for segments 2
cwnd = 4 segment 4segment 5segment 6
ACK for segments 4
cwnd = 7
ACK for segments 3
ACK for segments 5
ACK for segments 6
cwnd = 3
cwnd = 5
cwnd = 6ACK for segments 7
cwnd = 8
segment 7
Transport Layer 3-84
TCP Congestion Avoidance Phase
when cwnd gt ssthreshgrow cwnd linearly
increase cwnd by 1 MSS per RTT approach possible congestion slower than in slowstartimplementation cwnd= cwnd + MSScwndfor each ACK received
ACKs increase cwndby 1 MSS per RTT additive increaseloss cut cwnd in half (non-timeout-detected loss ) multiplicative decrease
AIMD
AIMD Additive IncreaseMultiplicative Decrease
Transport Layer 3-85
Congestion AvoidanceCongestion avoidance phase is started if CongWin has reached the slow-start threshold value
If CongWin gt= ssthresh then each time an ACK is received increment CongWin as follows
bull CongWin = CongWin + 1CongWin (CongWin in segments)
bull In actual TCP implementation CongWin is in BytesCongWin = CongWin + MSS (MSSCongWin)
So CongWin is increased by one only if all CongWinsegments have been acknowledged
Transport Layer 3-86
Example Slow StartCongestion AvoidanceAssume that
ssthresh = 8
cwnd = 1
cwnd = 2
cwnd = 4
cwnd = 8
cwnd = 9
cwnd = 10
02468
101214
t=0
t=2
t=4
t=6
Roundtrip times
Cw
nd(in
seg
men
ts)
ssthresh
cwnd = 3
cwnd = 5cwnd = 6cwnd = 7
Transport Layer 3-87
Slow Start Congestion AvoidanceA typical plot of CongWin for a TCP connection
(MSS = 1500 bytes) with TCP Tahoe
SS
CA
ssthresh
Transport Layer 3-88
Responses to CongestionTCP assumes there is congestion if it detects a packet lossA TCP sender can detect lost packets via loss events
bull Timeout of a retransmission timerbull Receipt of 3 duplicate ACKs (fast retransmit)
TCP interprets a Timeout as a binary congestion signal When a timeout occurs the sender performs
ssthresh is set to half the current size of the congestion window
ssthresh = CongWin 2CongWin is reset to one
CongWin = 1and slow-start is entered
Transport Layer 3-89
Fast Recovery (differentiation btwn two loss events) After 3 dup ACKs (fast Retransmit)
ssthresh = CongWin2CongWin = CongWin2window then grows linearly
But after timeout eventCongWin = 1 MSS window then grows exponentiallyto the threshold then grows linearly
bull 3 dup ACKs indicates network capable of delivering some segmentsbull timeout before 3 dup ACKs is ldquomore alarmingrdquo
Philosophy
3-90
TCP Congestion ControlInitially
CongWin = 1ssthresh = advertised window size
New Ack receivedif (CongWin lt ssthresh) Slow Start
CongWin = CongWin + 1else Congestion Avoidance
CongWin = CongWin + 1CongWinTimeout
ssthresh = CongWin2CongWin = 1
Fast Retransmissionssthresh = CongWin2CongWin = CongWin2
Slow Start (exponential increase phase) is continued until CongWin reaches half of the level where the loss event occurred last time CongWin is increased slowly after (linear increase in Congestion Avoidance phase)
Transport Layer 3-91
Popular ldquoflavorsrdquo of TCP
ssthresh
ssthresh
TCP Tahoe
TCP Reno
Transmission round
cwnd
win
dow
siz
e (in
seg
men
ts)
Transport Layer 3-92
Summary TCP Congestion ControlWhen CongWin is below Threshold sender in slow-start phase window grows exponentiallyWhen CongWin is above Threshold sender is in congestion-avoidance phase window grows linearlyWhen a triple duplicate ACK occurs Threshold set to CongWin2 and CongWin set to ThresholdWhen timeout occurs Threshold set to CongWin2 and CongWin is set to 1 MSS The actual sender window size is determined based on the congestion and flow control algorithms
SenderWin=min(RcvWinCongWin)
Transport Layer 3-93
TCP Congestion Control SummaryEvent State TCP Sender Action Commentary
ACK receipt for previously unackeddata
Slow Start (SS)
CongWin = CongWin + MSS If (CongWin gt Threshold)
set state to ldquoCongestion Avoidancerdquo
Resulting in a doubling of CongWin every RTT
ACK receipt for previously unackeddata
CongestionAvoidance (CA)
CongWin = CongWin+MSS (MSSCongWin)
Additive increase resulting in increase of CongWin by 1 MSS every RTT
Loss event detected by triple duplicate ACK
SS or CA Threshold = CongWin2 CongWin = ThresholdSet state to ldquoCongestion Avoidancerdquo
Fast recovery implementing multiplicative decrease CongWin will not drop below 1 MSS
Timeout SS or CA Threshold = CongWin2 CongWin = 1 MSSSet state to ldquoSlow Startrdquo
Enter slow start
Duplicate ACK
SS or CA Increment duplicate ACK count for segment being acked
CongWin and Threshold not changed
Transport Layer 3-94
TCP throughput
Q whatrsquos average throughout of TCP as function of window size RTT
ignoring slow startlet W be window size when loss occurs
when window is W throughput is WRTTjust after loss window drops to W2 throughput to W2RTT average throughout 75 WRTT
Transport Layer 3-95
TCP Futures TCP over ldquolong fat pipesrdquo
example 1500 byte segments 100ms RTT want 10 Gbps throughputrequires window size W = 83333 in-flight segmentsthroughput in terms of loss rate
L = 210-10 Wownew versions of TCP for high-speed
LRTTMSSsdot221
Transport Layer 3-96
Fairness goal if K TCP sessions share same bottleneck link of bandwidth R each should have average rate of RK
TCP connection 1
bottleneckrouter
capacity R
TCP connection 2
TCP Fairness
Transport Layer 3-97
Why is TCP fairTwo competing sessions
Additive increase gives slope of 1 as throughout increasesmultiplicative decrease decreases throughput proportionally
R
R
equal bandwidth share
Connection 1 throughput
Conn
ecti
on 2
thr
ough
p ut
congestion avoidance additive increaseloss decrease window by factor of 2
congestion avoidance additive increaseloss decrease window by factor of 2
Transport Layer 3-98
Fairness (more)Fairness and UDP
Multimedia apps often do not use TCP
do not want rate throttled by congestion control
Instead use UDPpump audiovideo at constant rate tolerate packet loss
Research area TCP friendly
Fairness and parallel TCP connectionsnothing prevents app from opening parallel cnctionsbetween 2 hostsWeb browsers do this Example link of rate R supporting 9 cnctions
new app asks for 1 TCP gets rate R10new app asks for 11 TCPs gets R2
Transport Layer 3-99
TCP Connection ManagementRecall TCP sender receiver
establish ldquoconnectionrdquobefore exchanging data segmentsinitialize TCP variables
seq sbuffers flow control info (eg RcvWindow)
client connection initiatorSocket clientSocket = new Socket(hostnameport
number)
server contacted by clientSocket connectionSocket = welcomeSocketaccept()
Three way handshakeStep 1 client host sends TCP
SYN segment to serverspecifies initial seq no data
Step 2 server host receives SYN replies with SYNACK segment
server allocates buffersspecifies server initial seq
Step 3 client receives SYNACK replies with ACK segment which may contain data
Transport Layer 3-100
TCP Connection Management (cont)
Closing a connection
client closes socketclientSocketclose()
Step 1 client end system sends TCP FIN control segment to server
Step 2 server receives FIN replies with ACK Closes connection sends FIN
client
FIN
server
ACK
ACK
FIN
close
close
closed
tim
ed w
ait
Transport Layer 3-101
TCP Connection Management (cont)
Step 3 client receives FIN replies with ACK
Enters ldquotimed waitrdquo -will respond with ACK to received FINs
Step 4 server receives ACK Connection closed
client
FIN
server
ACK
ACK
FIN
closing
closing
closed
tim
ed w
ait
closed
Transport Layer 3-102
TCP Connection Management (cont)
TCP clientlifecycle
TCP serverlifecycle
Transport Layer 3-103
Tuning TCPIP Parameters TCPIP parameters
A set of default values may not be optimal for all applicationsThe network administrator may wish to turn on or off some TCPIP functions for performance or security considerations
Many Unix and Linux systems provide some flexibility in tuning the TCPIP kernelsbinsysctl is used to configure the Linux kernel parameters at runtime
Default kernel configuration file is sbinsysctlconfFrequently used sysctl options
bull sysctl ndasha or sysctl ndashA list all current valuesbull sysctl ndashp file_name load the sysctl setting from a configuration
filebull sysctl ndashw variable=value change the value of the parameter
Transport Layer 3-104
SomeTCP Parameters in Linux Kerneltcp_syn_retries
Number of SYN packets the kernel will send before giving up on the new connection
tcp_synack_retriesnumber of SYN+ACK packets sent before the kernel gives up on the connection
tcp_window_scalingMaximum window size of 65535 bytes not enough for for really fast networks The window scaling options allows for almost gigabyte windows which is good for connections with large delay-bandwidth product
tcp_max_syn_backlogMaximal number of remembered connection requests which still did not receive an acknowledgment from connecting client
tcp_fin_timeoutHow many seconds to wait for a final FIN packet before the socket is closed required to prevent denial-of-service (DoS) attacks Default value is 60 seconds
Transport Layer 3-105
SomeTCP Parameters in Linux Kerneltcp_rmem
This is a vector of 3 integers [min default max] These parameters are used by TCP to dynamically adjust receive buffer sizesmin - minimum size of the receive buffer used by each TCP socket The default value is 4K default - the default size of the receive buffer for a TCP socket The default value is 87380 bytes and is lowered to 43689 in low memory systems If larger receive buffer sizes are desired this value should be increased max - the maximum size of the receive buffer used by each TCP socket The default value of 873802 bytes is lowered to 87380 in low memory systems
tcp_smemSend buffer parameters [min default max] similar to tcp_rmem
- Chapter 3 Transport Layer
- Transport services and protocols
- Transport vs network layer
- Internet transport-layer protocols
- Multiplexingdemultiplexing
- How demultiplexing works
- Connectionless demultiplexing
- Connection-oriented demux
- Connection-oriented demux (cont)
- Connection-oriented demux Threaded Web Server
- UDP User Datagram Protocol [RFC 768]
- UDP more
- UDP checksum
- Principles of Reliable data transfer
- Reliable data transfer getting started
- Reliable data transfer getting started
- Rdt10 reliable transfer over a reliable channel
- Rdt20 channel with bit errors
- rdt20 FSM specification
- rdt20 operation with no errors
- rdt20 error scenario
- rdt20 has a fatal flaw
- rdt21 sender handles garbled ACKNAKs
- rdt21 receiver handles garbled ACKNAKs
- rdt21 discussion
- rdt22 a NAK-free protocol
- rdt22 sender receiver fragments
- rdt30 channels with errors and loss
- rdt30 sender
- rdt30 in action
- rdt30 in action
- Performance of rdt30
- rdt30 stop-and-wait operation
- Pipelined protocols
- Pipelining increased utilization
- Go-Back-N
- GBN sender extended FSM
- GBN receiver extended FSM
- GBN inaction
- Selective Repeat
- Selective repeat sender receiver windows
- Selective repeat
- Selective repeat in action
- Selective repeat dilemma
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- TCP Overview RFCs 793 1122 1323 2018 2581
- TCP segment structure
- TCP seq rsquos and ACKs
- TCP Round Trip Time and Timeout
- TCP Round Trip Time and Timeout
- Example RTT estimation
- TCP Round Trip Time and Timeout
- TCP reliable data transfer
- TCP sender events
- TCP sender(simplified)
- TCP retransmission scenarios
- TCP retransmission scenarios (more)
- TCP ACK generation [RFC 1122 RFC 2581]
- Fast Retransmit
- Fast Retransmit
- Fast retransmit algorithm
- TCP Flow Control
- TCP Flow control how it works
- Sliding Window Flow Control Example
- Principles of Congestion Control
- Causescosts of congestion scenario 1
- Causescosts of congestion scenario 2
- Causescosts of congestion scenario 2
- Causescosts of congestion scenario 3
- Causescosts of congestion scenario 3
- Approaches towards congestion control
- TCP Congestion Control
- TCP congestion control bandwidth probing
- TCP Congestion Control details
- TCP Congestion Control more details
- TCP Slow Start Phase
- Slow Start Example
- TCP Congestion Avoidance Phase
- Congestion Avoidance
- Example Slow StartCongestion Avoidance
- Slow Start Congestion Avoidance
- Responses to Congestion
- Fast Recovery (differentiation btwn two loss events)
- TCP Congestion Control
- Popular ldquoflavorsrdquo of TCP
- Summary TCP Congestion Control
- TCP Congestion Control Summary
- TCP throughput
- TCP Futures TCP over ldquolong fat pipesrdquo
- TCP Fairness
- Why is TCP fair
- Fairness (more)
- TCP Connection Management
- TCP Connection Management (cont)
- TCP Connection Management (cont)
- TCP Connection Management (cont)
- Tuning TCPIP Parameters
- SomeTCP Parameters in Linux Kernel
- SomeTCP Parameters in Linux Kernel
-
Transport Layer 3-68
TCP Flow Control
receive side of TCP connection has a receive buffer
speed-matching service matching the send rate to the receiving apprsquos drain rate
app process may be slow at reading from buffer
sender wonrsquot overflowreceiverrsquos buffer by
transmitting too muchtoo fast
flow control
Transport Layer 3-69
TCP Flow control how it works
(Suppose TCP receiver discards out-of-order segments)spare room in buffer
= RcvWin
= RcvBuffer-[LastByteRcvd -LastByteRead]
Rcvr advertises spare room by including value of RcvWin in segmentsSender limits unACKeddata to RcvWin
guarantees receive buffer doesnrsquot overflow
Transport Layer 3-70
Sliding Window Flow Control Example
3K
2K SeqNo=0
ReceiverBuffer
0 4KSendersends 2Kof data
2K
AckNo=2048 RcvWin=2048Sendersends 2Kof data 2K SeqNo=2048
4K
AckNo=4096 RcvWin=0
AckNo=4096 RcvWin=1024
Sender blocked
Transport Layer 3-71
Principles of Congestion Control
Congestioninformally ldquotoo many sources sending too much data too fast for network to handlerdquodifferent from flow controlmanifestations
lost packets (buffer overflow at routers)long delays (queueing in router buffers)
a top-10 problem
Transport Layer 3-72
Causescosts of congestion scenario 1
two senders two receiversone router infinite buffers no retransmission
large delays when congestedmaximum achievable throughput
unlimited shared output link buffers
Host Aλin original data
Host B
λout
Transport Layer 3-73
Causescosts of congestion scenario 2
one router finite buffers sender retransmission of lost packet
finite shared output link buffers
Host A λin original data
Host B
λout
λin original data plus retransmitted data
Transport Layer 3-74
Causescosts of congestion scenario 2always (goodput)ldquoperfectrdquo retransmission only when loss
retransmission of delayed (not lost) packet makes larger(than perfect case) for same
λin
λout=
λin
λoutgtλ
inλout
ldquocostsrdquo of congestionmore work (retrans) for given ldquogoodputrdquounneeded retransmissions link carries multiple copies of pkt
R2
R2λin
λ out
b
R2
R2λin
λ out
a
R2
R2λin
λ out
c
R4
R3
Transport Layer 3-75
Causescosts of congestion scenario 3four sendersmultihop pathstimeoutretransmit
λin
Q what happens as and increase λ
in
finite shared output link buffers
Host Aλin original data
Host B
λout
λin original data plus retransmitted data
Transport Layer 3-76
Causescosts of congestion scenario 3
another ldquocostrdquo of congestionwhen packet dropped any ldquoupstream transmission capacity used for that packet was wasted
Host A
Host B
λou
t
Transport Layer 3-77
Approaches towards congestion control
End-end congestion controlno explicit feedback from networkcongestion inferred from end-system observed loss delayapproach taken by TCP
Network-assisted congestion controlrouters provide feedback to end systems
single bit indicating congestion (SNA DECbit TCPIP ECN ATM)explicit rate sender should send at
Two broad approaches towards congestion control
Transport Layer 3-78
TCP Congestion Control
end-end control (no network assistance)sender limits transmissionLastByteSent-LastByteAcked
le CongWin
CongWin is dynamic function of perceived network congestion
How does sender perceive congestionloss event = timeout or3 duplicate acksTCP sender reduces rate (CongWin) after loss event
two modes of operationSlow Start (SS)Congestion avoidance (CA) or Additive Increase Multiplicative Decrease (AIMD)
Transport Layer 3-79
TCP congestion control bandwidth probing
ldquoprobing for bandwidthrdquo increase transmission rate on receipt of ACK until eventually loss occurs then decrease transmission rate
continue to increase on ACK decrease on loss (since available bandwidth is changing depending on other connections in network)
ACKs being received so increase rate
X
X
XX
X loss so decrease rate
send
ing
rate
time
Q how fast to increasedecreasedetails to follow
TCPrsquosldquosawtoothrdquobehavior
Transport Layer 3-80
TCP Congestion Control details
sender limits rate by limiting number of unACKed bytes ldquoin pipelinerdquo
cwnd differs from rwnd (how why)sender limited by min(cwndrwnd)
roughly
cwnd is dynamic function of perceived network congestion
rate = cwndRTT bytessec
LastByteSent-LastByteAcked le cwnd
cwndbytes
RTT
ACK(s)
Transport Layer 3-81
TCP Congestion Control more details
segment loss event reducing cwndtimeout no response from receiver
cut cwnd to 13 duplicate ACKs at least some segments getting through (recall fast retransmit)
cut cwnd in half less aggressively than on timeout
ACK received increase cwndTwo modes of operation
slowstart phase bull increase exponentially
fast (despite name) at connection start or following timeout
congestion avoidance bull increase linearly
Transport Layer 3-82
TCP Slow Start Phasewhen connection begins cwnd = 1 MSS
example MSS = 500 bytes amp RTT = 200 msecinitial rate = 20 kbps
available bandwidth may be gtgt MSSRTT
desirable to quickly ramp up to respectable rate
increase rate exponentially until first loss event or when threshold reached
double cwnd every RTTdone by incrementing cwnd by 1 for every ACK received
Host A
one segment
RTT
Host B
time
two segments
four segments
Transport Layer 3-83
Slow Start ExampleThe congestion window size grows very rapidly
For every ACK we increase CongWin by 1 irrespective of the number of segments ACKrsquoeddouble CongWinevery RTTinitial rate is slow but ramps up exponentially fast
TCP slows down the increase of CongWinwhen CongWin gt ssthresh
segment 1
ACK for segment 1
cwnd = 1
cwnd = 2 segment 2segment 3
ACK for segments 2
cwnd = 4 segment 4segment 5segment 6
ACK for segments 4
cwnd = 7
ACK for segments 3
ACK for segments 5
ACK for segments 6
cwnd = 3
cwnd = 5
cwnd = 6ACK for segments 7
cwnd = 8
segment 7
Transport Layer 3-84
TCP Congestion Avoidance Phase
when cwnd gt ssthreshgrow cwnd linearly
increase cwnd by 1 MSS per RTT approach possible congestion slower than in slowstartimplementation cwnd= cwnd + MSScwndfor each ACK received
ACKs increase cwndby 1 MSS per RTT additive increaseloss cut cwnd in half (non-timeout-detected loss ) multiplicative decrease
AIMD
AIMD Additive IncreaseMultiplicative Decrease
Transport Layer 3-85
Congestion AvoidanceCongestion avoidance phase is started if CongWin has reached the slow-start threshold value
If CongWin gt= ssthresh then each time an ACK is received increment CongWin as follows
bull CongWin = CongWin + 1CongWin (CongWin in segments)
bull In actual TCP implementation CongWin is in BytesCongWin = CongWin + MSS (MSSCongWin)
So CongWin is increased by one only if all CongWinsegments have been acknowledged
Transport Layer 3-86
Example Slow StartCongestion AvoidanceAssume that
ssthresh = 8
cwnd = 1
cwnd = 2
cwnd = 4
cwnd = 8
cwnd = 9
cwnd = 10
02468
101214
t=0
t=2
t=4
t=6
Roundtrip times
Cw
nd(in
seg
men
ts)
ssthresh
cwnd = 3
cwnd = 5cwnd = 6cwnd = 7
Transport Layer 3-87
Slow Start Congestion AvoidanceA typical plot of CongWin for a TCP connection
(MSS = 1500 bytes) with TCP Tahoe
SS
CA
ssthresh
Transport Layer 3-88
Responses to CongestionTCP assumes there is congestion if it detects a packet lossA TCP sender can detect lost packets via loss events
bull Timeout of a retransmission timerbull Receipt of 3 duplicate ACKs (fast retransmit)
TCP interprets a Timeout as a binary congestion signal When a timeout occurs the sender performs
ssthresh is set to half the current size of the congestion window
ssthresh = CongWin 2CongWin is reset to one
CongWin = 1and slow-start is entered
Transport Layer 3-89
Fast Recovery (differentiation btwn two loss events) After 3 dup ACKs (fast Retransmit)
ssthresh = CongWin2CongWin = CongWin2window then grows linearly
But after timeout eventCongWin = 1 MSS window then grows exponentiallyto the threshold then grows linearly
bull 3 dup ACKs indicates network capable of delivering some segmentsbull timeout before 3 dup ACKs is ldquomore alarmingrdquo
Philosophy
3-90
TCP Congestion ControlInitially
CongWin = 1ssthresh = advertised window size
New Ack receivedif (CongWin lt ssthresh) Slow Start
CongWin = CongWin + 1else Congestion Avoidance
CongWin = CongWin + 1CongWinTimeout
ssthresh = CongWin2CongWin = 1
Fast Retransmissionssthresh = CongWin2CongWin = CongWin2
Slow Start (exponential increase phase) is continued until CongWin reaches half of the level where the loss event occurred last time CongWin is increased slowly after (linear increase in Congestion Avoidance phase)
Transport Layer 3-91
Popular ldquoflavorsrdquo of TCP
ssthresh
ssthresh
TCP Tahoe
TCP Reno
Transmission round
cwnd
win
dow
siz
e (in
seg
men
ts)
Transport Layer 3-92
Summary TCP Congestion ControlWhen CongWin is below Threshold sender in slow-start phase window grows exponentiallyWhen CongWin is above Threshold sender is in congestion-avoidance phase window grows linearlyWhen a triple duplicate ACK occurs Threshold set to CongWin2 and CongWin set to ThresholdWhen timeout occurs Threshold set to CongWin2 and CongWin is set to 1 MSS The actual sender window size is determined based on the congestion and flow control algorithms
SenderWin=min(RcvWinCongWin)
Transport Layer 3-93
TCP Congestion Control SummaryEvent State TCP Sender Action Commentary
ACK receipt for previously unackeddata
Slow Start (SS)
CongWin = CongWin + MSS If (CongWin gt Threshold)
set state to ldquoCongestion Avoidancerdquo
Resulting in a doubling of CongWin every RTT
ACK receipt for previously unackeddata
CongestionAvoidance (CA)
CongWin = CongWin+MSS (MSSCongWin)
Additive increase resulting in increase of CongWin by 1 MSS every RTT
Loss event detected by triple duplicate ACK
SS or CA Threshold = CongWin2 CongWin = ThresholdSet state to ldquoCongestion Avoidancerdquo
Fast recovery implementing multiplicative decrease CongWin will not drop below 1 MSS
Timeout SS or CA Threshold = CongWin2 CongWin = 1 MSSSet state to ldquoSlow Startrdquo
Enter slow start
Duplicate ACK
SS or CA Increment duplicate ACK count for segment being acked
CongWin and Threshold not changed
Transport Layer 3-94
TCP throughput
Q whatrsquos average throughout of TCP as function of window size RTT
ignoring slow startlet W be window size when loss occurs
when window is W throughput is WRTTjust after loss window drops to W2 throughput to W2RTT average throughout 75 WRTT
Transport Layer 3-95
TCP Futures TCP over ldquolong fat pipesrdquo
example 1500 byte segments 100ms RTT want 10 Gbps throughputrequires window size W = 83333 in-flight segmentsthroughput in terms of loss rate
L = 210-10 Wownew versions of TCP for high-speed
LRTTMSSsdot221
Transport Layer 3-96
Fairness goal if K TCP sessions share same bottleneck link of bandwidth R each should have average rate of RK
TCP connection 1
bottleneckrouter
capacity R
TCP connection 2
TCP Fairness
Transport Layer 3-97
Why is TCP fairTwo competing sessions
Additive increase gives slope of 1 as throughout increasesmultiplicative decrease decreases throughput proportionally
R
R
equal bandwidth share
Connection 1 throughput
Conn
ecti
on 2
thr
ough
p ut
congestion avoidance additive increaseloss decrease window by factor of 2
congestion avoidance additive increaseloss decrease window by factor of 2
Transport Layer 3-98
Fairness (more)Fairness and UDP
Multimedia apps often do not use TCP
do not want rate throttled by congestion control
Instead use UDPpump audiovideo at constant rate tolerate packet loss
Research area TCP friendly
Fairness and parallel TCP connectionsnothing prevents app from opening parallel cnctionsbetween 2 hostsWeb browsers do this Example link of rate R supporting 9 cnctions
new app asks for 1 TCP gets rate R10new app asks for 11 TCPs gets R2
Transport Layer 3-99
TCP Connection ManagementRecall TCP sender receiver
establish ldquoconnectionrdquobefore exchanging data segmentsinitialize TCP variables
seq sbuffers flow control info (eg RcvWindow)
client connection initiatorSocket clientSocket = new Socket(hostnameport
number)
server contacted by clientSocket connectionSocket = welcomeSocketaccept()
Three way handshakeStep 1 client host sends TCP
SYN segment to serverspecifies initial seq no data
Step 2 server host receives SYN replies with SYNACK segment
server allocates buffersspecifies server initial seq
Step 3 client receives SYNACK replies with ACK segment which may contain data
Transport Layer 3-100
TCP Connection Management (cont)
Closing a connection
client closes socketclientSocketclose()
Step 1 client end system sends TCP FIN control segment to server
Step 2 server receives FIN replies with ACK Closes connection sends FIN
client
FIN
server
ACK
ACK
FIN
close
close
closed
tim
ed w
ait
Transport Layer 3-101
TCP Connection Management (cont)
Step 3 client receives FIN replies with ACK
Enters ldquotimed waitrdquo -will respond with ACK to received FINs
Step 4 server receives ACK Connection closed
client
FIN
server
ACK
ACK
FIN
closing
closing
closed
tim
ed w
ait
closed
Transport Layer 3-102
TCP Connection Management (cont)
TCP clientlifecycle
TCP serverlifecycle
Transport Layer 3-103
Tuning TCPIP Parameters TCPIP parameters
A set of default values may not be optimal for all applicationsThe network administrator may wish to turn on or off some TCPIP functions for performance or security considerations
Many Unix and Linux systems provide some flexibility in tuning the TCPIP kernelsbinsysctl is used to configure the Linux kernel parameters at runtime
Default kernel configuration file is sbinsysctlconfFrequently used sysctl options
bull sysctl ndasha or sysctl ndashA list all current valuesbull sysctl ndashp file_name load the sysctl setting from a configuration
filebull sysctl ndashw variable=value change the value of the parameter
Transport Layer 3-104
SomeTCP Parameters in Linux Kerneltcp_syn_retries
Number of SYN packets the kernel will send before giving up on the new connection
tcp_synack_retriesnumber of SYN+ACK packets sent before the kernel gives up on the connection
tcp_window_scalingMaximum window size of 65535 bytes not enough for for really fast networks The window scaling options allows for almost gigabyte windows which is good for connections with large delay-bandwidth product
tcp_max_syn_backlogMaximal number of remembered connection requests which still did not receive an acknowledgment from connecting client
tcp_fin_timeoutHow many seconds to wait for a final FIN packet before the socket is closed required to prevent denial-of-service (DoS) attacks Default value is 60 seconds
Transport Layer 3-105
SomeTCP Parameters in Linux Kerneltcp_rmem
This is a vector of 3 integers [min default max] These parameters are used by TCP to dynamically adjust receive buffer sizesmin - minimum size of the receive buffer used by each TCP socket The default value is 4K default - the default size of the receive buffer for a TCP socket The default value is 87380 bytes and is lowered to 43689 in low memory systems If larger receive buffer sizes are desired this value should be increased max - the maximum size of the receive buffer used by each TCP socket The default value of 873802 bytes is lowered to 87380 in low memory systems
tcp_smemSend buffer parameters [min default max] similar to tcp_rmem
- Chapter 3 Transport Layer
- Transport services and protocols
- Transport vs network layer
- Internet transport-layer protocols
- Multiplexingdemultiplexing
- How demultiplexing works
- Connectionless demultiplexing
- Connection-oriented demux
- Connection-oriented demux (cont)
- Connection-oriented demux Threaded Web Server
- UDP User Datagram Protocol [RFC 768]
- UDP more
- UDP checksum
- Principles of Reliable data transfer
- Reliable data transfer getting started
- Reliable data transfer getting started
- Rdt10 reliable transfer over a reliable channel
- Rdt20 channel with bit errors
- rdt20 FSM specification
- rdt20 operation with no errors
- rdt20 error scenario
- rdt20 has a fatal flaw
- rdt21 sender handles garbled ACKNAKs
- rdt21 receiver handles garbled ACKNAKs
- rdt21 discussion
- rdt22 a NAK-free protocol
- rdt22 sender receiver fragments
- rdt30 channels with errors and loss
- rdt30 sender
- rdt30 in action
- rdt30 in action
- Performance of rdt30
- rdt30 stop-and-wait operation
- Pipelined protocols
- Pipelining increased utilization
- Go-Back-N
- GBN sender extended FSM
- GBN receiver extended FSM
- GBN inaction
- Selective Repeat
- Selective repeat sender receiver windows
- Selective repeat
- Selective repeat in action
- Selective repeat dilemma
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- TCP Overview RFCs 793 1122 1323 2018 2581
- TCP segment structure
- TCP seq rsquos and ACKs
- TCP Round Trip Time and Timeout
- TCP Round Trip Time and Timeout
- Example RTT estimation
- TCP Round Trip Time and Timeout
- TCP reliable data transfer
- TCP sender events
- TCP sender(simplified)
- TCP retransmission scenarios
- TCP retransmission scenarios (more)
- TCP ACK generation [RFC 1122 RFC 2581]
- Fast Retransmit
- Fast Retransmit
- Fast retransmit algorithm
- TCP Flow Control
- TCP Flow control how it works
- Sliding Window Flow Control Example
- Principles of Congestion Control
- Causescosts of congestion scenario 1
- Causescosts of congestion scenario 2
- Causescosts of congestion scenario 2
- Causescosts of congestion scenario 3
- Causescosts of congestion scenario 3
- Approaches towards congestion control
- TCP Congestion Control
- TCP congestion control bandwidth probing
- TCP Congestion Control details
- TCP Congestion Control more details
- TCP Slow Start Phase
- Slow Start Example
- TCP Congestion Avoidance Phase
- Congestion Avoidance
- Example Slow StartCongestion Avoidance
- Slow Start Congestion Avoidance
- Responses to Congestion
- Fast Recovery (differentiation btwn two loss events)
- TCP Congestion Control
- Popular ldquoflavorsrdquo of TCP
- Summary TCP Congestion Control
- TCP Congestion Control Summary
- TCP throughput
- TCP Futures TCP over ldquolong fat pipesrdquo
- TCP Fairness
- Why is TCP fair
- Fairness (more)
- TCP Connection Management
- TCP Connection Management (cont)
- TCP Connection Management (cont)
- TCP Connection Management (cont)
- Tuning TCPIP Parameters
- SomeTCP Parameters in Linux Kernel
- SomeTCP Parameters in Linux Kernel
-
Transport Layer 3-69
TCP Flow control how it works
(Suppose TCP receiver discards out-of-order segments)spare room in buffer
= RcvWin
= RcvBuffer-[LastByteRcvd -LastByteRead]
Rcvr advertises spare room by including value of RcvWin in segmentsSender limits unACKeddata to RcvWin
guarantees receive buffer doesnrsquot overflow
Transport Layer 3-70
Sliding Window Flow Control Example
3K
2K SeqNo=0
ReceiverBuffer
0 4KSendersends 2Kof data
2K
AckNo=2048 RcvWin=2048Sendersends 2Kof data 2K SeqNo=2048
4K
AckNo=4096 RcvWin=0
AckNo=4096 RcvWin=1024
Sender blocked
Transport Layer 3-71
Principles of Congestion Control
Congestioninformally ldquotoo many sources sending too much data too fast for network to handlerdquodifferent from flow controlmanifestations
lost packets (buffer overflow at routers)long delays (queueing in router buffers)
a top-10 problem
Transport Layer 3-72
Causescosts of congestion scenario 1
two senders two receiversone router infinite buffers no retransmission
large delays when congestedmaximum achievable throughput
unlimited shared output link buffers
Host Aλin original data
Host B
λout
Transport Layer 3-73
Causescosts of congestion scenario 2
one router finite buffers sender retransmission of lost packet
finite shared output link buffers
Host A λin original data
Host B
λout
λin original data plus retransmitted data
Transport Layer 3-74
Causescosts of congestion scenario 2always (goodput)ldquoperfectrdquo retransmission only when loss
retransmission of delayed (not lost) packet makes larger(than perfect case) for same
λin
λout=
λin
λoutgtλ
inλout
ldquocostsrdquo of congestionmore work (retrans) for given ldquogoodputrdquounneeded retransmissions link carries multiple copies of pkt
R2
R2λin
λ out
b
R2
R2λin
λ out
a
R2
R2λin
λ out
c
R4
R3
Transport Layer 3-75
Causescosts of congestion scenario 3four sendersmultihop pathstimeoutretransmit
λin
Q what happens as and increase λ
in
finite shared output link buffers
Host Aλin original data
Host B
λout
λin original data plus retransmitted data
Transport Layer 3-76
Causescosts of congestion scenario 3
another ldquocostrdquo of congestionwhen packet dropped any ldquoupstream transmission capacity used for that packet was wasted
Host A
Host B
λou
t
Transport Layer 3-77
Approaches towards congestion control
End-end congestion controlno explicit feedback from networkcongestion inferred from end-system observed loss delayapproach taken by TCP
Network-assisted congestion controlrouters provide feedback to end systems
single bit indicating congestion (SNA DECbit TCPIP ECN ATM)explicit rate sender should send at
Two broad approaches towards congestion control
Transport Layer 3-78
TCP Congestion Control
end-end control (no network assistance)sender limits transmissionLastByteSent-LastByteAcked
le CongWin
CongWin is dynamic function of perceived network congestion
How does sender perceive congestionloss event = timeout or3 duplicate acksTCP sender reduces rate (CongWin) after loss event
two modes of operationSlow Start (SS)Congestion avoidance (CA) or Additive Increase Multiplicative Decrease (AIMD)
Transport Layer 3-79
TCP congestion control bandwidth probing
ldquoprobing for bandwidthrdquo increase transmission rate on receipt of ACK until eventually loss occurs then decrease transmission rate
continue to increase on ACK decrease on loss (since available bandwidth is changing depending on other connections in network)
ACKs being received so increase rate
X
X
XX
X loss so decrease rate
send
ing
rate
time
Q how fast to increasedecreasedetails to follow
TCPrsquosldquosawtoothrdquobehavior
Transport Layer 3-80
TCP Congestion Control details
sender limits rate by limiting number of unACKed bytes ldquoin pipelinerdquo
cwnd differs from rwnd (how why)sender limited by min(cwndrwnd)
roughly
cwnd is dynamic function of perceived network congestion
rate = cwndRTT bytessec
LastByteSent-LastByteAcked le cwnd
cwndbytes
RTT
ACK(s)
Transport Layer 3-81
TCP Congestion Control more details
segment loss event reducing cwndtimeout no response from receiver
cut cwnd to 13 duplicate ACKs at least some segments getting through (recall fast retransmit)
cut cwnd in half less aggressively than on timeout
ACK received increase cwndTwo modes of operation
slowstart phase bull increase exponentially
fast (despite name) at connection start or following timeout
congestion avoidance bull increase linearly
Transport Layer 3-82
TCP Slow Start Phasewhen connection begins cwnd = 1 MSS
example MSS = 500 bytes amp RTT = 200 msecinitial rate = 20 kbps
available bandwidth may be gtgt MSSRTT
desirable to quickly ramp up to respectable rate
increase rate exponentially until first loss event or when threshold reached
double cwnd every RTTdone by incrementing cwnd by 1 for every ACK received
Host A
one segment
RTT
Host B
time
two segments
four segments
Transport Layer 3-83
Slow Start ExampleThe congestion window size grows very rapidly
For every ACK we increase CongWin by 1 irrespective of the number of segments ACKrsquoeddouble CongWinevery RTTinitial rate is slow but ramps up exponentially fast
TCP slows down the increase of CongWinwhen CongWin gt ssthresh
segment 1
ACK for segment 1
cwnd = 1
cwnd = 2 segment 2segment 3
ACK for segments 2
cwnd = 4 segment 4segment 5segment 6
ACK for segments 4
cwnd = 7
ACK for segments 3
ACK for segments 5
ACK for segments 6
cwnd = 3
cwnd = 5
cwnd = 6ACK for segments 7
cwnd = 8
segment 7
Transport Layer 3-84
TCP Congestion Avoidance Phase
when cwnd gt ssthreshgrow cwnd linearly
increase cwnd by 1 MSS per RTT approach possible congestion slower than in slowstartimplementation cwnd= cwnd + MSScwndfor each ACK received
ACKs increase cwndby 1 MSS per RTT additive increaseloss cut cwnd in half (non-timeout-detected loss ) multiplicative decrease
AIMD
AIMD Additive IncreaseMultiplicative Decrease
Transport Layer 3-85
Congestion AvoidanceCongestion avoidance phase is started if CongWin has reached the slow-start threshold value
If CongWin gt= ssthresh then each time an ACK is received increment CongWin as follows
bull CongWin = CongWin + 1CongWin (CongWin in segments)
bull In actual TCP implementation CongWin is in BytesCongWin = CongWin + MSS (MSSCongWin)
So CongWin is increased by one only if all CongWinsegments have been acknowledged
Transport Layer 3-86
Example Slow StartCongestion AvoidanceAssume that
ssthresh = 8
cwnd = 1
cwnd = 2
cwnd = 4
cwnd = 8
cwnd = 9
cwnd = 10
02468
101214
t=0
t=2
t=4
t=6
Roundtrip times
Cw
nd(in
seg
men
ts)
ssthresh
cwnd = 3
cwnd = 5cwnd = 6cwnd = 7
Transport Layer 3-87
Slow Start Congestion AvoidanceA typical plot of CongWin for a TCP connection
(MSS = 1500 bytes) with TCP Tahoe
SS
CA
ssthresh
Transport Layer 3-88
Responses to CongestionTCP assumes there is congestion if it detects a packet lossA TCP sender can detect lost packets via loss events
bull Timeout of a retransmission timerbull Receipt of 3 duplicate ACKs (fast retransmit)
TCP interprets a Timeout as a binary congestion signal When a timeout occurs the sender performs
ssthresh is set to half the current size of the congestion window
ssthresh = CongWin 2CongWin is reset to one
CongWin = 1and slow-start is entered
Transport Layer 3-89
Fast Recovery (differentiation btwn two loss events) After 3 dup ACKs (fast Retransmit)
ssthresh = CongWin2CongWin = CongWin2window then grows linearly
But after timeout eventCongWin = 1 MSS window then grows exponentiallyto the threshold then grows linearly
bull 3 dup ACKs indicates network capable of delivering some segmentsbull timeout before 3 dup ACKs is ldquomore alarmingrdquo
Philosophy
3-90
TCP Congestion ControlInitially
CongWin = 1ssthresh = advertised window size
New Ack receivedif (CongWin lt ssthresh) Slow Start
CongWin = CongWin + 1else Congestion Avoidance
CongWin = CongWin + 1CongWinTimeout
ssthresh = CongWin2CongWin = 1
Fast Retransmissionssthresh = CongWin2CongWin = CongWin2
Slow Start (exponential increase phase) is continued until CongWin reaches half of the level where the loss event occurred last time CongWin is increased slowly after (linear increase in Congestion Avoidance phase)
Transport Layer 3-91
Popular ldquoflavorsrdquo of TCP
ssthresh
ssthresh
TCP Tahoe
TCP Reno
Transmission round
cwnd
win
dow
siz
e (in
seg
men
ts)
Transport Layer 3-92
Summary TCP Congestion ControlWhen CongWin is below Threshold sender in slow-start phase window grows exponentiallyWhen CongWin is above Threshold sender is in congestion-avoidance phase window grows linearlyWhen a triple duplicate ACK occurs Threshold set to CongWin2 and CongWin set to ThresholdWhen timeout occurs Threshold set to CongWin2 and CongWin is set to 1 MSS The actual sender window size is determined based on the congestion and flow control algorithms
SenderWin=min(RcvWinCongWin)
Transport Layer 3-93
TCP Congestion Control SummaryEvent State TCP Sender Action Commentary
ACK receipt for previously unackeddata
Slow Start (SS)
CongWin = CongWin + MSS If (CongWin gt Threshold)
set state to ldquoCongestion Avoidancerdquo
Resulting in a doubling of CongWin every RTT
ACK receipt for previously unackeddata
CongestionAvoidance (CA)
CongWin = CongWin+MSS (MSSCongWin)
Additive increase resulting in increase of CongWin by 1 MSS every RTT
Loss event detected by triple duplicate ACK
SS or CA Threshold = CongWin2 CongWin = ThresholdSet state to ldquoCongestion Avoidancerdquo
Fast recovery implementing multiplicative decrease CongWin will not drop below 1 MSS
Timeout SS or CA Threshold = CongWin2 CongWin = 1 MSSSet state to ldquoSlow Startrdquo
Enter slow start
Duplicate ACK
SS or CA Increment duplicate ACK count for segment being acked
CongWin and Threshold not changed
Transport Layer 3-94
TCP throughput
Q whatrsquos average throughout of TCP as function of window size RTT
ignoring slow startlet W be window size when loss occurs
when window is W throughput is WRTTjust after loss window drops to W2 throughput to W2RTT average throughout 75 WRTT
Transport Layer 3-95
TCP Futures TCP over ldquolong fat pipesrdquo
example 1500 byte segments 100ms RTT want 10 Gbps throughputrequires window size W = 83333 in-flight segmentsthroughput in terms of loss rate
L = 210-10 Wownew versions of TCP for high-speed
LRTTMSSsdot221
Transport Layer 3-96
Fairness goal if K TCP sessions share same bottleneck link of bandwidth R each should have average rate of RK
TCP connection 1
bottleneckrouter
capacity R
TCP connection 2
TCP Fairness
Transport Layer 3-97
Why is TCP fairTwo competing sessions
Additive increase gives slope of 1 as throughout increasesmultiplicative decrease decreases throughput proportionally
R
R
equal bandwidth share
Connection 1 throughput
Conn
ecti
on 2
thr
ough
p ut
congestion avoidance additive increaseloss decrease window by factor of 2
congestion avoidance additive increaseloss decrease window by factor of 2
Transport Layer 3-98
Fairness (more)Fairness and UDP
Multimedia apps often do not use TCP
do not want rate throttled by congestion control
Instead use UDPpump audiovideo at constant rate tolerate packet loss
Research area TCP friendly
Fairness and parallel TCP connectionsnothing prevents app from opening parallel cnctionsbetween 2 hostsWeb browsers do this Example link of rate R supporting 9 cnctions
new app asks for 1 TCP gets rate R10new app asks for 11 TCPs gets R2
Transport Layer 3-99
TCP Connection ManagementRecall TCP sender receiver
establish ldquoconnectionrdquobefore exchanging data segmentsinitialize TCP variables
seq sbuffers flow control info (eg RcvWindow)
client connection initiatorSocket clientSocket = new Socket(hostnameport
number)
server contacted by clientSocket connectionSocket = welcomeSocketaccept()
Three way handshakeStep 1 client host sends TCP
SYN segment to serverspecifies initial seq no data
Step 2 server host receives SYN replies with SYNACK segment
server allocates buffersspecifies server initial seq
Step 3 client receives SYNACK replies with ACK segment which may contain data
Transport Layer 3-100
TCP Connection Management (cont)
Closing a connection
client closes socketclientSocketclose()
Step 1 client end system sends TCP FIN control segment to server
Step 2 server receives FIN replies with ACK Closes connection sends FIN
client
FIN
server
ACK
ACK
FIN
close
close
closed
tim
ed w
ait
Transport Layer 3-101
TCP Connection Management (cont)
Step 3 client receives FIN replies with ACK
Enters ldquotimed waitrdquo -will respond with ACK to received FINs
Step 4 server receives ACK Connection closed
client
FIN
server
ACK
ACK
FIN
closing
closing
closed
tim
ed w
ait
closed
Transport Layer 3-102
TCP Connection Management (cont)
TCP clientlifecycle
TCP serverlifecycle
Transport Layer 3-103
Tuning TCPIP Parameters TCPIP parameters
A set of default values may not be optimal for all applicationsThe network administrator may wish to turn on or off some TCPIP functions for performance or security considerations
Many Unix and Linux systems provide some flexibility in tuning the TCPIP kernelsbinsysctl is used to configure the Linux kernel parameters at runtime
Default kernel configuration file is sbinsysctlconfFrequently used sysctl options
bull sysctl ndasha or sysctl ndashA list all current valuesbull sysctl ndashp file_name load the sysctl setting from a configuration
filebull sysctl ndashw variable=value change the value of the parameter
Transport Layer 3-104
SomeTCP Parameters in Linux Kerneltcp_syn_retries
Number of SYN packets the kernel will send before giving up on the new connection
tcp_synack_retriesnumber of SYN+ACK packets sent before the kernel gives up on the connection
tcp_window_scalingMaximum window size of 65535 bytes not enough for for really fast networks The window scaling options allows for almost gigabyte windows which is good for connections with large delay-bandwidth product
tcp_max_syn_backlogMaximal number of remembered connection requests which still did not receive an acknowledgment from connecting client
tcp_fin_timeoutHow many seconds to wait for a final FIN packet before the socket is closed required to prevent denial-of-service (DoS) attacks Default value is 60 seconds
Transport Layer 3-105
SomeTCP Parameters in Linux Kerneltcp_rmem
This is a vector of 3 integers [min default max] These parameters are used by TCP to dynamically adjust receive buffer sizesmin - minimum size of the receive buffer used by each TCP socket The default value is 4K default - the default size of the receive buffer for a TCP socket The default value is 87380 bytes and is lowered to 43689 in low memory systems If larger receive buffer sizes are desired this value should be increased max - the maximum size of the receive buffer used by each TCP socket The default value of 873802 bytes is lowered to 87380 in low memory systems
tcp_smemSend buffer parameters [min default max] similar to tcp_rmem
- Chapter 3 Transport Layer
- Transport services and protocols
- Transport vs network layer
- Internet transport-layer protocols
- Multiplexingdemultiplexing
- How demultiplexing works
- Connectionless demultiplexing
- Connection-oriented demux
- Connection-oriented demux (cont)
- Connection-oriented demux Threaded Web Server
- UDP User Datagram Protocol [RFC 768]
- UDP more
- UDP checksum
- Principles of Reliable data transfer
- Reliable data transfer getting started
- Reliable data transfer getting started
- Rdt10 reliable transfer over a reliable channel
- Rdt20 channel with bit errors
- rdt20 FSM specification
- rdt20 operation with no errors
- rdt20 error scenario
- rdt20 has a fatal flaw
- rdt21 sender handles garbled ACKNAKs
- rdt21 receiver handles garbled ACKNAKs
- rdt21 discussion
- rdt22 a NAK-free protocol
- rdt22 sender receiver fragments
- rdt30 channels with errors and loss
- rdt30 sender
- rdt30 in action
- rdt30 in action
- Performance of rdt30
- rdt30 stop-and-wait operation
- Pipelined protocols
- Pipelining increased utilization
- Go-Back-N
- GBN sender extended FSM
- GBN receiver extended FSM
- GBN inaction
- Selective Repeat
- Selective repeat sender receiver windows
- Selective repeat
- Selective repeat in action
- Selective repeat dilemma
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- TCP Overview RFCs 793 1122 1323 2018 2581
- TCP segment structure
- TCP seq rsquos and ACKs
- TCP Round Trip Time and Timeout
- TCP Round Trip Time and Timeout
- Example RTT estimation
- TCP Round Trip Time and Timeout
- TCP reliable data transfer
- TCP sender events
- TCP sender(simplified)
- TCP retransmission scenarios
- TCP retransmission scenarios (more)
- TCP ACK generation [RFC 1122 RFC 2581]
- Fast Retransmit
- Fast Retransmit
- Fast retransmit algorithm
- TCP Flow Control
- TCP Flow control how it works
- Sliding Window Flow Control Example
- Principles of Congestion Control
- Causescosts of congestion scenario 1
- Causescosts of congestion scenario 2
- Causescosts of congestion scenario 2
- Causescosts of congestion scenario 3
- Causescosts of congestion scenario 3
- Approaches towards congestion control
- TCP Congestion Control
- TCP congestion control bandwidth probing
- TCP Congestion Control details
- TCP Congestion Control more details
- TCP Slow Start Phase
- Slow Start Example
- TCP Congestion Avoidance Phase
- Congestion Avoidance
- Example Slow StartCongestion Avoidance
- Slow Start Congestion Avoidance
- Responses to Congestion
- Fast Recovery (differentiation btwn two loss events)
- TCP Congestion Control
- Popular ldquoflavorsrdquo of TCP
- Summary TCP Congestion Control
- TCP Congestion Control Summary
- TCP throughput
- TCP Futures TCP over ldquolong fat pipesrdquo
- TCP Fairness
- Why is TCP fair
- Fairness (more)
- TCP Connection Management
- TCP Connection Management (cont)
- TCP Connection Management (cont)
- TCP Connection Management (cont)
- Tuning TCPIP Parameters
- SomeTCP Parameters in Linux Kernel
- SomeTCP Parameters in Linux Kernel
-
Transport Layer 3-70
Sliding Window Flow Control Example
3K
2K SeqNo=0
ReceiverBuffer
0 4KSendersends 2Kof data
2K
AckNo=2048 RcvWin=2048Sendersends 2Kof data 2K SeqNo=2048
4K
AckNo=4096 RcvWin=0
AckNo=4096 RcvWin=1024
Sender blocked
Transport Layer 3-71
Principles of Congestion Control
Congestioninformally ldquotoo many sources sending too much data too fast for network to handlerdquodifferent from flow controlmanifestations
lost packets (buffer overflow at routers)long delays (queueing in router buffers)
a top-10 problem
Transport Layer 3-72
Causescosts of congestion scenario 1
two senders two receiversone router infinite buffers no retransmission
large delays when congestedmaximum achievable throughput
unlimited shared output link buffers
Host Aλin original data
Host B
λout
Transport Layer 3-73
Causescosts of congestion scenario 2
one router finite buffers sender retransmission of lost packet
finite shared output link buffers
Host A λin original data
Host B
λout
λin original data plus retransmitted data
Transport Layer 3-74
Causescosts of congestion scenario 2always (goodput)ldquoperfectrdquo retransmission only when loss
retransmission of delayed (not lost) packet makes larger(than perfect case) for same
λin
λout=
λin
λoutgtλ
inλout
ldquocostsrdquo of congestionmore work (retrans) for given ldquogoodputrdquounneeded retransmissions link carries multiple copies of pkt
R2
R2λin
λ out
b
R2
R2λin
λ out
a
R2
R2λin
λ out
c
R4
R3
Transport Layer 3-75
Causescosts of congestion scenario 3four sendersmultihop pathstimeoutretransmit
λin
Q what happens as and increase λ
in
finite shared output link buffers
Host Aλin original data
Host B
λout
λin original data plus retransmitted data
Transport Layer 3-76
Causescosts of congestion scenario 3
another ldquocostrdquo of congestionwhen packet dropped any ldquoupstream transmission capacity used for that packet was wasted
Host A
Host B
λou
t
Transport Layer 3-77
Approaches towards congestion control
End-end congestion controlno explicit feedback from networkcongestion inferred from end-system observed loss delayapproach taken by TCP
Network-assisted congestion controlrouters provide feedback to end systems
single bit indicating congestion (SNA DECbit TCPIP ECN ATM)explicit rate sender should send at
Two broad approaches towards congestion control
Transport Layer 3-78
TCP Congestion Control
end-end control (no network assistance)sender limits transmissionLastByteSent-LastByteAcked
le CongWin
CongWin is dynamic function of perceived network congestion
How does sender perceive congestionloss event = timeout or3 duplicate acksTCP sender reduces rate (CongWin) after loss event
two modes of operationSlow Start (SS)Congestion avoidance (CA) or Additive Increase Multiplicative Decrease (AIMD)
Transport Layer 3-79
TCP congestion control bandwidth probing
ldquoprobing for bandwidthrdquo increase transmission rate on receipt of ACK until eventually loss occurs then decrease transmission rate
continue to increase on ACK decrease on loss (since available bandwidth is changing depending on other connections in network)
ACKs being received so increase rate
X
X
XX
X loss so decrease rate
send
ing
rate
time
Q how fast to increasedecreasedetails to follow
TCPrsquosldquosawtoothrdquobehavior
Transport Layer 3-80
TCP Congestion Control details
sender limits rate by limiting number of unACKed bytes ldquoin pipelinerdquo
cwnd differs from rwnd (how why)sender limited by min(cwndrwnd)
roughly
cwnd is dynamic function of perceived network congestion
rate = cwndRTT bytessec
LastByteSent-LastByteAcked le cwnd
cwndbytes
RTT
ACK(s)
Transport Layer 3-81
TCP Congestion Control more details
segment loss event reducing cwndtimeout no response from receiver
cut cwnd to 13 duplicate ACKs at least some segments getting through (recall fast retransmit)
cut cwnd in half less aggressively than on timeout
ACK received increase cwndTwo modes of operation
slowstart phase bull increase exponentially
fast (despite name) at connection start or following timeout
congestion avoidance bull increase linearly
Transport Layer 3-82
TCP Slow Start Phasewhen connection begins cwnd = 1 MSS
example MSS = 500 bytes amp RTT = 200 msecinitial rate = 20 kbps
available bandwidth may be gtgt MSSRTT
desirable to quickly ramp up to respectable rate
increase rate exponentially until first loss event or when threshold reached
double cwnd every RTTdone by incrementing cwnd by 1 for every ACK received
Host A
one segment
RTT
Host B
time
two segments
four segments
Transport Layer 3-83
Slow Start ExampleThe congestion window size grows very rapidly
For every ACK we increase CongWin by 1 irrespective of the number of segments ACKrsquoeddouble CongWinevery RTTinitial rate is slow but ramps up exponentially fast
TCP slows down the increase of CongWinwhen CongWin gt ssthresh
segment 1
ACK for segment 1
cwnd = 1
cwnd = 2 segment 2segment 3
ACK for segments 2
cwnd = 4 segment 4segment 5segment 6
ACK for segments 4
cwnd = 7
ACK for segments 3
ACK for segments 5
ACK for segments 6
cwnd = 3
cwnd = 5
cwnd = 6ACK for segments 7
cwnd = 8
segment 7
Transport Layer 3-84
TCP Congestion Avoidance Phase
when cwnd gt ssthreshgrow cwnd linearly
increase cwnd by 1 MSS per RTT approach possible congestion slower than in slowstartimplementation cwnd= cwnd + MSScwndfor each ACK received
ACKs increase cwndby 1 MSS per RTT additive increaseloss cut cwnd in half (non-timeout-detected loss ) multiplicative decrease
AIMD
AIMD Additive IncreaseMultiplicative Decrease
Transport Layer 3-85
Congestion AvoidanceCongestion avoidance phase is started if CongWin has reached the slow-start threshold value
If CongWin gt= ssthresh then each time an ACK is received increment CongWin as follows
bull CongWin = CongWin + 1CongWin (CongWin in segments)
bull In actual TCP implementation CongWin is in BytesCongWin = CongWin + MSS (MSSCongWin)
So CongWin is increased by one only if all CongWinsegments have been acknowledged
Transport Layer 3-86
Example Slow StartCongestion AvoidanceAssume that
ssthresh = 8
cwnd = 1
cwnd = 2
cwnd = 4
cwnd = 8
cwnd = 9
cwnd = 10
02468
101214
t=0
t=2
t=4
t=6
Roundtrip times
Cw
nd(in
seg
men
ts)
ssthresh
cwnd = 3
cwnd = 5cwnd = 6cwnd = 7
Transport Layer 3-87
Slow Start Congestion AvoidanceA typical plot of CongWin for a TCP connection
(MSS = 1500 bytes) with TCP Tahoe
SS
CA
ssthresh
Transport Layer 3-88
Responses to CongestionTCP assumes there is congestion if it detects a packet lossA TCP sender can detect lost packets via loss events
bull Timeout of a retransmission timerbull Receipt of 3 duplicate ACKs (fast retransmit)
TCP interprets a Timeout as a binary congestion signal When a timeout occurs the sender performs
ssthresh is set to half the current size of the congestion window
ssthresh = CongWin 2CongWin is reset to one
CongWin = 1and slow-start is entered
Transport Layer 3-89
Fast Recovery (differentiation btwn two loss events) After 3 dup ACKs (fast Retransmit)
ssthresh = CongWin2CongWin = CongWin2window then grows linearly
But after timeout eventCongWin = 1 MSS window then grows exponentiallyto the threshold then grows linearly
bull 3 dup ACKs indicates network capable of delivering some segmentsbull timeout before 3 dup ACKs is ldquomore alarmingrdquo
Philosophy
3-90
TCP Congestion ControlInitially
CongWin = 1ssthresh = advertised window size
New Ack receivedif (CongWin lt ssthresh) Slow Start
CongWin = CongWin + 1else Congestion Avoidance
CongWin = CongWin + 1CongWinTimeout
ssthresh = CongWin2CongWin = 1
Fast Retransmissionssthresh = CongWin2CongWin = CongWin2
Slow Start (exponential increase phase) is continued until CongWin reaches half of the level where the loss event occurred last time CongWin is increased slowly after (linear increase in Congestion Avoidance phase)
Transport Layer 3-91
Popular ldquoflavorsrdquo of TCP
ssthresh
ssthresh
TCP Tahoe
TCP Reno
Transmission round
cwnd
win
dow
siz
e (in
seg
men
ts)
Transport Layer 3-92
Summary TCP Congestion ControlWhen CongWin is below Threshold sender in slow-start phase window grows exponentiallyWhen CongWin is above Threshold sender is in congestion-avoidance phase window grows linearlyWhen a triple duplicate ACK occurs Threshold set to CongWin2 and CongWin set to ThresholdWhen timeout occurs Threshold set to CongWin2 and CongWin is set to 1 MSS The actual sender window size is determined based on the congestion and flow control algorithms
SenderWin=min(RcvWinCongWin)
Transport Layer 3-93
TCP Congestion Control SummaryEvent State TCP Sender Action Commentary
ACK receipt for previously unackeddata
Slow Start (SS)
CongWin = CongWin + MSS If (CongWin gt Threshold)
set state to ldquoCongestion Avoidancerdquo
Resulting in a doubling of CongWin every RTT
ACK receipt for previously unackeddata
CongestionAvoidance (CA)
CongWin = CongWin+MSS (MSSCongWin)
Additive increase resulting in increase of CongWin by 1 MSS every RTT
Loss event detected by triple duplicate ACK
SS or CA Threshold = CongWin2 CongWin = ThresholdSet state to ldquoCongestion Avoidancerdquo
Fast recovery implementing multiplicative decrease CongWin will not drop below 1 MSS
Timeout SS or CA Threshold = CongWin2 CongWin = 1 MSSSet state to ldquoSlow Startrdquo
Enter slow start
Duplicate ACK
SS or CA Increment duplicate ACK count for segment being acked
CongWin and Threshold not changed
Transport Layer 3-94
TCP throughput
Q whatrsquos average throughout of TCP as function of window size RTT
ignoring slow startlet W be window size when loss occurs
when window is W throughput is WRTTjust after loss window drops to W2 throughput to W2RTT average throughout 75 WRTT
Transport Layer 3-95
TCP Futures TCP over ldquolong fat pipesrdquo
example 1500 byte segments 100ms RTT want 10 Gbps throughputrequires window size W = 83333 in-flight segmentsthroughput in terms of loss rate
L = 210-10 Wownew versions of TCP for high-speed
LRTTMSSsdot221
Transport Layer 3-96
Fairness goal if K TCP sessions share same bottleneck link of bandwidth R each should have average rate of RK
TCP connection 1
bottleneckrouter
capacity R
TCP connection 2
TCP Fairness
Transport Layer 3-97
Why is TCP fairTwo competing sessions
Additive increase gives slope of 1 as throughout increasesmultiplicative decrease decreases throughput proportionally
R
R
equal bandwidth share
Connection 1 throughput
Conn
ecti
on 2
thr
ough
p ut
congestion avoidance additive increaseloss decrease window by factor of 2
congestion avoidance additive increaseloss decrease window by factor of 2
Transport Layer 3-98
Fairness (more)Fairness and UDP
Multimedia apps often do not use TCP
do not want rate throttled by congestion control
Instead use UDPpump audiovideo at constant rate tolerate packet loss
Research area TCP friendly
Fairness and parallel TCP connectionsnothing prevents app from opening parallel cnctionsbetween 2 hostsWeb browsers do this Example link of rate R supporting 9 cnctions
new app asks for 1 TCP gets rate R10new app asks for 11 TCPs gets R2
Transport Layer 3-99
TCP Connection ManagementRecall TCP sender receiver
establish ldquoconnectionrdquobefore exchanging data segmentsinitialize TCP variables
seq sbuffers flow control info (eg RcvWindow)
client connection initiatorSocket clientSocket = new Socket(hostnameport
number)
server contacted by clientSocket connectionSocket = welcomeSocketaccept()
Three way handshakeStep 1 client host sends TCP
SYN segment to serverspecifies initial seq no data
Step 2 server host receives SYN replies with SYNACK segment
server allocates buffersspecifies server initial seq
Step 3 client receives SYNACK replies with ACK segment which may contain data
Transport Layer 3-100
TCP Connection Management (cont)
Closing a connection
client closes socketclientSocketclose()
Step 1 client end system sends TCP FIN control segment to server
Step 2 server receives FIN replies with ACK Closes connection sends FIN
client
FIN
server
ACK
ACK
FIN
close
close
closed
tim
ed w
ait
Transport Layer 3-101
TCP Connection Management (cont)
Step 3 client receives FIN replies with ACK
Enters ldquotimed waitrdquo -will respond with ACK to received FINs
Step 4 server receives ACK Connection closed
client
FIN
server
ACK
ACK
FIN
closing
closing
closed
tim
ed w
ait
closed
Transport Layer 3-102
TCP Connection Management (cont)
TCP clientlifecycle
TCP serverlifecycle
Transport Layer 3-103
Tuning TCPIP Parameters TCPIP parameters
A set of default values may not be optimal for all applicationsThe network administrator may wish to turn on or off some TCPIP functions for performance or security considerations
Many Unix and Linux systems provide some flexibility in tuning the TCPIP kernelsbinsysctl is used to configure the Linux kernel parameters at runtime
Default kernel configuration file is sbinsysctlconfFrequently used sysctl options
bull sysctl ndasha or sysctl ndashA list all current valuesbull sysctl ndashp file_name load the sysctl setting from a configuration
filebull sysctl ndashw variable=value change the value of the parameter
Transport Layer 3-104
SomeTCP Parameters in Linux Kerneltcp_syn_retries
Number of SYN packets the kernel will send before giving up on the new connection
tcp_synack_retriesnumber of SYN+ACK packets sent before the kernel gives up on the connection
tcp_window_scalingMaximum window size of 65535 bytes not enough for for really fast networks The window scaling options allows for almost gigabyte windows which is good for connections with large delay-bandwidth product
tcp_max_syn_backlogMaximal number of remembered connection requests which still did not receive an acknowledgment from connecting client
tcp_fin_timeoutHow many seconds to wait for a final FIN packet before the socket is closed required to prevent denial-of-service (DoS) attacks Default value is 60 seconds
Transport Layer 3-105
SomeTCP Parameters in Linux Kerneltcp_rmem
This is a vector of 3 integers [min default max] These parameters are used by TCP to dynamically adjust receive buffer sizesmin - minimum size of the receive buffer used by each TCP socket The default value is 4K default - the default size of the receive buffer for a TCP socket The default value is 87380 bytes and is lowered to 43689 in low memory systems If larger receive buffer sizes are desired this value should be increased max - the maximum size of the receive buffer used by each TCP socket The default value of 873802 bytes is lowered to 87380 in low memory systems
tcp_smemSend buffer parameters [min default max] similar to tcp_rmem
- Chapter 3 Transport Layer
- Transport services and protocols
- Transport vs network layer
- Internet transport-layer protocols
- Multiplexingdemultiplexing
- How demultiplexing works
- Connectionless demultiplexing
- Connection-oriented demux
- Connection-oriented demux (cont)
- Connection-oriented demux Threaded Web Server
- UDP User Datagram Protocol [RFC 768]
- UDP more
- UDP checksum
- Principles of Reliable data transfer
- Reliable data transfer getting started
- Reliable data transfer getting started
- Rdt10 reliable transfer over a reliable channel
- Rdt20 channel with bit errors
- rdt20 FSM specification
- rdt20 operation with no errors
- rdt20 error scenario
- rdt20 has a fatal flaw
- rdt21 sender handles garbled ACKNAKs
- rdt21 receiver handles garbled ACKNAKs
- rdt21 discussion
- rdt22 a NAK-free protocol
- rdt22 sender receiver fragments
- rdt30 channels with errors and loss
- rdt30 sender
- rdt30 in action
- rdt30 in action
- Performance of rdt30
- rdt30 stop-and-wait operation
- Pipelined protocols
- Pipelining increased utilization
- Go-Back-N
- GBN sender extended FSM
- GBN receiver extended FSM
- GBN inaction
- Selective Repeat
- Selective repeat sender receiver windows
- Selective repeat
- Selective repeat in action
- Selective repeat dilemma
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- TCP Overview RFCs 793 1122 1323 2018 2581
- TCP segment structure
- TCP seq rsquos and ACKs
- TCP Round Trip Time and Timeout
- TCP Round Trip Time and Timeout
- Example RTT estimation
- TCP Round Trip Time and Timeout
- TCP reliable data transfer
- TCP sender events
- TCP sender(simplified)
- TCP retransmission scenarios
- TCP retransmission scenarios (more)
- TCP ACK generation [RFC 1122 RFC 2581]
- Fast Retransmit
- Fast Retransmit
- Fast retransmit algorithm
- TCP Flow Control
- TCP Flow control how it works
- Sliding Window Flow Control Example
- Principles of Congestion Control
- Causescosts of congestion scenario 1
- Causescosts of congestion scenario 2
- Causescosts of congestion scenario 2
- Causescosts of congestion scenario 3
- Causescosts of congestion scenario 3
- Approaches towards congestion control
- TCP Congestion Control
- TCP congestion control bandwidth probing
- TCP Congestion Control details
- TCP Congestion Control more details
- TCP Slow Start Phase
- Slow Start Example
- TCP Congestion Avoidance Phase
- Congestion Avoidance
- Example Slow StartCongestion Avoidance
- Slow Start Congestion Avoidance
- Responses to Congestion
- Fast Recovery (differentiation btwn two loss events)
- TCP Congestion Control
- Popular ldquoflavorsrdquo of TCP
- Summary TCP Congestion Control
- TCP Congestion Control Summary
- TCP throughput
- TCP Futures TCP over ldquolong fat pipesrdquo
- TCP Fairness
- Why is TCP fair
- Fairness (more)
- TCP Connection Management
- TCP Connection Management (cont)
- TCP Connection Management (cont)
- TCP Connection Management (cont)
- Tuning TCPIP Parameters
- SomeTCP Parameters in Linux Kernel
- SomeTCP Parameters in Linux Kernel
-
Transport Layer 3-71
Principles of Congestion Control
Congestioninformally ldquotoo many sources sending too much data too fast for network to handlerdquodifferent from flow controlmanifestations
lost packets (buffer overflow at routers)long delays (queueing in router buffers)
a top-10 problem
Transport Layer 3-72
Causescosts of congestion scenario 1
two senders two receiversone router infinite buffers no retransmission
large delays when congestedmaximum achievable throughput
unlimited shared output link buffers
Host Aλin original data
Host B
λout
Transport Layer 3-73
Causescosts of congestion scenario 2
one router finite buffers sender retransmission of lost packet
finite shared output link buffers
Host A λin original data
Host B
λout
λin original data plus retransmitted data
Transport Layer 3-74
Causescosts of congestion scenario 2always (goodput)ldquoperfectrdquo retransmission only when loss
retransmission of delayed (not lost) packet makes larger(than perfect case) for same
λin
λout=
λin
λoutgtλ
inλout
ldquocostsrdquo of congestionmore work (retrans) for given ldquogoodputrdquounneeded retransmissions link carries multiple copies of pkt
R2
R2λin
λ out
b
R2
R2λin
λ out
a
R2
R2λin
λ out
c
R4
R3
Transport Layer 3-75
Causescosts of congestion scenario 3four sendersmultihop pathstimeoutretransmit
λin
Q what happens as and increase λ
in
finite shared output link buffers
Host Aλin original data
Host B
λout
λin original data plus retransmitted data
Transport Layer 3-76
Causescosts of congestion scenario 3
another ldquocostrdquo of congestionwhen packet dropped any ldquoupstream transmission capacity used for that packet was wasted
Host A
Host B
λou
t
Transport Layer 3-77
Approaches towards congestion control
End-end congestion controlno explicit feedback from networkcongestion inferred from end-system observed loss delayapproach taken by TCP
Network-assisted congestion controlrouters provide feedback to end systems
single bit indicating congestion (SNA DECbit TCPIP ECN ATM)explicit rate sender should send at
Two broad approaches towards congestion control
Transport Layer 3-78
TCP Congestion Control
end-end control (no network assistance)sender limits transmissionLastByteSent-LastByteAcked
le CongWin
CongWin is dynamic function of perceived network congestion
How does sender perceive congestionloss event = timeout or3 duplicate acksTCP sender reduces rate (CongWin) after loss event
two modes of operationSlow Start (SS)Congestion avoidance (CA) or Additive Increase Multiplicative Decrease (AIMD)
Transport Layer 3-79
TCP congestion control bandwidth probing
ldquoprobing for bandwidthrdquo increase transmission rate on receipt of ACK until eventually loss occurs then decrease transmission rate
continue to increase on ACK decrease on loss (since available bandwidth is changing depending on other connections in network)
ACKs being received so increase rate
X
X
XX
X loss so decrease rate
send
ing
rate
time
Q how fast to increasedecreasedetails to follow
TCPrsquosldquosawtoothrdquobehavior
Transport Layer 3-80
TCP Congestion Control details
sender limits rate by limiting number of unACKed bytes ldquoin pipelinerdquo
cwnd differs from rwnd (how why)sender limited by min(cwndrwnd)
roughly
cwnd is dynamic function of perceived network congestion
rate = cwndRTT bytessec
LastByteSent-LastByteAcked le cwnd
cwndbytes
RTT
ACK(s)
Transport Layer 3-81
TCP Congestion Control more details
segment loss event reducing cwndtimeout no response from receiver
cut cwnd to 13 duplicate ACKs at least some segments getting through (recall fast retransmit)
cut cwnd in half less aggressively than on timeout
ACK received increase cwndTwo modes of operation
slowstart phase bull increase exponentially
fast (despite name) at connection start or following timeout
congestion avoidance bull increase linearly
Transport Layer 3-82
TCP Slow Start Phasewhen connection begins cwnd = 1 MSS
example MSS = 500 bytes amp RTT = 200 msecinitial rate = 20 kbps
available bandwidth may be gtgt MSSRTT
desirable to quickly ramp up to respectable rate
increase rate exponentially until first loss event or when threshold reached
double cwnd every RTTdone by incrementing cwnd by 1 for every ACK received
Host A
one segment
RTT
Host B
time
two segments
four segments
Transport Layer 3-83
Slow Start ExampleThe congestion window size grows very rapidly
For every ACK we increase CongWin by 1 irrespective of the number of segments ACKrsquoeddouble CongWinevery RTTinitial rate is slow but ramps up exponentially fast
TCP slows down the increase of CongWinwhen CongWin gt ssthresh
segment 1
ACK for segment 1
cwnd = 1
cwnd = 2 segment 2segment 3
ACK for segments 2
cwnd = 4 segment 4segment 5segment 6
ACK for segments 4
cwnd = 7
ACK for segments 3
ACK for segments 5
ACK for segments 6
cwnd = 3
cwnd = 5
cwnd = 6ACK for segments 7
cwnd = 8
segment 7
Transport Layer 3-84
TCP Congestion Avoidance Phase
when cwnd gt ssthreshgrow cwnd linearly
increase cwnd by 1 MSS per RTT approach possible congestion slower than in slowstartimplementation cwnd= cwnd + MSScwndfor each ACK received
ACKs increase cwndby 1 MSS per RTT additive increaseloss cut cwnd in half (non-timeout-detected loss ) multiplicative decrease
AIMD
AIMD Additive IncreaseMultiplicative Decrease
Transport Layer 3-85
Congestion AvoidanceCongestion avoidance phase is started if CongWin has reached the slow-start threshold value
If CongWin gt= ssthresh then each time an ACK is received increment CongWin as follows
bull CongWin = CongWin + 1CongWin (CongWin in segments)
bull In actual TCP implementation CongWin is in BytesCongWin = CongWin + MSS (MSSCongWin)
So CongWin is increased by one only if all CongWinsegments have been acknowledged
Transport Layer 3-86
Example Slow StartCongestion AvoidanceAssume that
ssthresh = 8
cwnd = 1
cwnd = 2
cwnd = 4
cwnd = 8
cwnd = 9
cwnd = 10
02468
101214
t=0
t=2
t=4
t=6
Roundtrip times
Cw
nd(in
seg
men
ts)
ssthresh
cwnd = 3
cwnd = 5cwnd = 6cwnd = 7
Transport Layer 3-87
Slow Start Congestion AvoidanceA typical plot of CongWin for a TCP connection
(MSS = 1500 bytes) with TCP Tahoe
SS
CA
ssthresh
Transport Layer 3-88
Responses to CongestionTCP assumes there is congestion if it detects a packet lossA TCP sender can detect lost packets via loss events
bull Timeout of a retransmission timerbull Receipt of 3 duplicate ACKs (fast retransmit)
TCP interprets a Timeout as a binary congestion signal When a timeout occurs the sender performs
ssthresh is set to half the current size of the congestion window
ssthresh = CongWin 2CongWin is reset to one
CongWin = 1and slow-start is entered
Transport Layer 3-89
Fast Recovery (differentiation btwn two loss events) After 3 dup ACKs (fast Retransmit)
ssthresh = CongWin2CongWin = CongWin2window then grows linearly
But after timeout eventCongWin = 1 MSS window then grows exponentiallyto the threshold then grows linearly
bull 3 dup ACKs indicates network capable of delivering some segmentsbull timeout before 3 dup ACKs is ldquomore alarmingrdquo
Philosophy
3-90
TCP Congestion ControlInitially
CongWin = 1ssthresh = advertised window size
New Ack receivedif (CongWin lt ssthresh) Slow Start
CongWin = CongWin + 1else Congestion Avoidance
CongWin = CongWin + 1CongWinTimeout
ssthresh = CongWin2CongWin = 1
Fast Retransmissionssthresh = CongWin2CongWin = CongWin2
Slow Start (exponential increase phase) is continued until CongWin reaches half of the level where the loss event occurred last time CongWin is increased slowly after (linear increase in Congestion Avoidance phase)
Transport Layer 3-91
Popular ldquoflavorsrdquo of TCP
ssthresh
ssthresh
TCP Tahoe
TCP Reno
Transmission round
cwnd
win
dow
siz
e (in
seg
men
ts)
Transport Layer 3-92
Summary TCP Congestion ControlWhen CongWin is below Threshold sender in slow-start phase window grows exponentiallyWhen CongWin is above Threshold sender is in congestion-avoidance phase window grows linearlyWhen a triple duplicate ACK occurs Threshold set to CongWin2 and CongWin set to ThresholdWhen timeout occurs Threshold set to CongWin2 and CongWin is set to 1 MSS The actual sender window size is determined based on the congestion and flow control algorithms
SenderWin=min(RcvWinCongWin)
Transport Layer 3-93
TCP Congestion Control SummaryEvent State TCP Sender Action Commentary
ACK receipt for previously unackeddata
Slow Start (SS)
CongWin = CongWin + MSS If (CongWin gt Threshold)
set state to ldquoCongestion Avoidancerdquo
Resulting in a doubling of CongWin every RTT
ACK receipt for previously unackeddata
CongestionAvoidance (CA)
CongWin = CongWin+MSS (MSSCongWin)
Additive increase resulting in increase of CongWin by 1 MSS every RTT
Loss event detected by triple duplicate ACK
SS or CA Threshold = CongWin2 CongWin = ThresholdSet state to ldquoCongestion Avoidancerdquo
Fast recovery implementing multiplicative decrease CongWin will not drop below 1 MSS
Timeout SS or CA Threshold = CongWin2 CongWin = 1 MSSSet state to ldquoSlow Startrdquo
Enter slow start
Duplicate ACK
SS or CA Increment duplicate ACK count for segment being acked
CongWin and Threshold not changed
Transport Layer 3-94
TCP throughput
Q whatrsquos average throughout of TCP as function of window size RTT
ignoring slow startlet W be window size when loss occurs
when window is W throughput is WRTTjust after loss window drops to W2 throughput to W2RTT average throughout 75 WRTT
Transport Layer 3-95
TCP Futures TCP over ldquolong fat pipesrdquo
example 1500 byte segments 100ms RTT want 10 Gbps throughputrequires window size W = 83333 in-flight segmentsthroughput in terms of loss rate
L = 210-10 Wownew versions of TCP for high-speed
LRTTMSSsdot221
Transport Layer 3-96
Fairness goal if K TCP sessions share same bottleneck link of bandwidth R each should have average rate of RK
TCP connection 1
bottleneckrouter
capacity R
TCP connection 2
TCP Fairness
Transport Layer 3-97
Why is TCP fairTwo competing sessions
Additive increase gives slope of 1 as throughout increasesmultiplicative decrease decreases throughput proportionally
R
R
equal bandwidth share
Connection 1 throughput
Conn
ecti
on 2
thr
ough
p ut
congestion avoidance additive increaseloss decrease window by factor of 2
congestion avoidance additive increaseloss decrease window by factor of 2
Transport Layer 3-98
Fairness (more)Fairness and UDP
Multimedia apps often do not use TCP
do not want rate throttled by congestion control
Instead use UDPpump audiovideo at constant rate tolerate packet loss
Research area TCP friendly
Fairness and parallel TCP connectionsnothing prevents app from opening parallel cnctionsbetween 2 hostsWeb browsers do this Example link of rate R supporting 9 cnctions
new app asks for 1 TCP gets rate R10new app asks for 11 TCPs gets R2
Transport Layer 3-99
TCP Connection ManagementRecall TCP sender receiver
establish ldquoconnectionrdquobefore exchanging data segmentsinitialize TCP variables
seq sbuffers flow control info (eg RcvWindow)
client connection initiatorSocket clientSocket = new Socket(hostnameport
number)
server contacted by clientSocket connectionSocket = welcomeSocketaccept()
Three way handshakeStep 1 client host sends TCP
SYN segment to serverspecifies initial seq no data
Step 2 server host receives SYN replies with SYNACK segment
server allocates buffersspecifies server initial seq
Step 3 client receives SYNACK replies with ACK segment which may contain data
Transport Layer 3-100
TCP Connection Management (cont)
Closing a connection
client closes socketclientSocketclose()
Step 1 client end system sends TCP FIN control segment to server
Step 2 server receives FIN replies with ACK Closes connection sends FIN
client
FIN
server
ACK
ACK
FIN
close
close
closed
tim
ed w
ait
Transport Layer 3-101
TCP Connection Management (cont)
Step 3 client receives FIN replies with ACK
Enters ldquotimed waitrdquo -will respond with ACK to received FINs
Step 4 server receives ACK Connection closed
client
FIN
server
ACK
ACK
FIN
closing
closing
closed
tim
ed w
ait
closed
Transport Layer 3-102
TCP Connection Management (cont)
TCP clientlifecycle
TCP serverlifecycle
Transport Layer 3-103
Tuning TCPIP Parameters TCPIP parameters
A set of default values may not be optimal for all applicationsThe network administrator may wish to turn on or off some TCPIP functions for performance or security considerations
Many Unix and Linux systems provide some flexibility in tuning the TCPIP kernelsbinsysctl is used to configure the Linux kernel parameters at runtime
Default kernel configuration file is sbinsysctlconfFrequently used sysctl options
bull sysctl ndasha or sysctl ndashA list all current valuesbull sysctl ndashp file_name load the sysctl setting from a configuration
filebull sysctl ndashw variable=value change the value of the parameter
Transport Layer 3-104
SomeTCP Parameters in Linux Kerneltcp_syn_retries
Number of SYN packets the kernel will send before giving up on the new connection
tcp_synack_retriesnumber of SYN+ACK packets sent before the kernel gives up on the connection
tcp_window_scalingMaximum window size of 65535 bytes not enough for for really fast networks The window scaling options allows for almost gigabyte windows which is good for connections with large delay-bandwidth product
tcp_max_syn_backlogMaximal number of remembered connection requests which still did not receive an acknowledgment from connecting client
tcp_fin_timeoutHow many seconds to wait for a final FIN packet before the socket is closed required to prevent denial-of-service (DoS) attacks Default value is 60 seconds
Transport Layer 3-105
SomeTCP Parameters in Linux Kerneltcp_rmem
This is a vector of 3 integers [min default max] These parameters are used by TCP to dynamically adjust receive buffer sizesmin - minimum size of the receive buffer used by each TCP socket The default value is 4K default - the default size of the receive buffer for a TCP socket The default value is 87380 bytes and is lowered to 43689 in low memory systems If larger receive buffer sizes are desired this value should be increased max - the maximum size of the receive buffer used by each TCP socket The default value of 873802 bytes is lowered to 87380 in low memory systems
tcp_smemSend buffer parameters [min default max] similar to tcp_rmem
- Chapter 3 Transport Layer
- Transport services and protocols
- Transport vs network layer
- Internet transport-layer protocols
- Multiplexingdemultiplexing
- How demultiplexing works
- Connectionless demultiplexing
- Connection-oriented demux
- Connection-oriented demux (cont)
- Connection-oriented demux Threaded Web Server
- UDP User Datagram Protocol [RFC 768]
- UDP more
- UDP checksum
- Principles of Reliable data transfer
- Reliable data transfer getting started
- Reliable data transfer getting started
- Rdt10 reliable transfer over a reliable channel
- Rdt20 channel with bit errors
- rdt20 FSM specification
- rdt20 operation with no errors
- rdt20 error scenario
- rdt20 has a fatal flaw
- rdt21 sender handles garbled ACKNAKs
- rdt21 receiver handles garbled ACKNAKs
- rdt21 discussion
- rdt22 a NAK-free protocol
- rdt22 sender receiver fragments
- rdt30 channels with errors and loss
- rdt30 sender
- rdt30 in action
- rdt30 in action
- Performance of rdt30
- rdt30 stop-and-wait operation
- Pipelined protocols
- Pipelining increased utilization
- Go-Back-N
- GBN sender extended FSM
- GBN receiver extended FSM
- GBN inaction
- Selective Repeat
- Selective repeat sender receiver windows
- Selective repeat
- Selective repeat in action
- Selective repeat dilemma
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- TCP Overview RFCs 793 1122 1323 2018 2581
- TCP segment structure
- TCP seq rsquos and ACKs
- TCP Round Trip Time and Timeout
- TCP Round Trip Time and Timeout
- Example RTT estimation
- TCP Round Trip Time and Timeout
- TCP reliable data transfer
- TCP sender events
- TCP sender(simplified)
- TCP retransmission scenarios
- TCP retransmission scenarios (more)
- TCP ACK generation [RFC 1122 RFC 2581]
- Fast Retransmit
- Fast Retransmit
- Fast retransmit algorithm
- TCP Flow Control
- TCP Flow control how it works
- Sliding Window Flow Control Example
- Principles of Congestion Control
- Causescosts of congestion scenario 1
- Causescosts of congestion scenario 2
- Causescosts of congestion scenario 2
- Causescosts of congestion scenario 3
- Causescosts of congestion scenario 3
- Approaches towards congestion control
- TCP Congestion Control
- TCP congestion control bandwidth probing
- TCP Congestion Control details
- TCP Congestion Control more details
- TCP Slow Start Phase
- Slow Start Example
- TCP Congestion Avoidance Phase
- Congestion Avoidance
- Example Slow StartCongestion Avoidance
- Slow Start Congestion Avoidance
- Responses to Congestion
- Fast Recovery (differentiation btwn two loss events)
- TCP Congestion Control
- Popular ldquoflavorsrdquo of TCP
- Summary TCP Congestion Control
- TCP Congestion Control Summary
- TCP throughput
- TCP Futures TCP over ldquolong fat pipesrdquo
- TCP Fairness
- Why is TCP fair
- Fairness (more)
- TCP Connection Management
- TCP Connection Management (cont)
- TCP Connection Management (cont)
- TCP Connection Management (cont)
- Tuning TCPIP Parameters
- SomeTCP Parameters in Linux Kernel
- SomeTCP Parameters in Linux Kernel
-
Transport Layer 3-72
Causescosts of congestion scenario 1
two senders two receiversone router infinite buffers no retransmission
large delays when congestedmaximum achievable throughput
unlimited shared output link buffers
Host Aλin original data
Host B
λout
Transport Layer 3-73
Causescosts of congestion scenario 2
one router finite buffers sender retransmission of lost packet
finite shared output link buffers
Host A λin original data
Host B
λout
λin original data plus retransmitted data
Transport Layer 3-74
Causescosts of congestion scenario 2always (goodput)ldquoperfectrdquo retransmission only when loss
retransmission of delayed (not lost) packet makes larger(than perfect case) for same
λin
λout=
λin
λoutgtλ
inλout
ldquocostsrdquo of congestionmore work (retrans) for given ldquogoodputrdquounneeded retransmissions link carries multiple copies of pkt
R2
R2λin
λ out
b
R2
R2λin
λ out
a
R2
R2λin
λ out
c
R4
R3
Transport Layer 3-75
Causescosts of congestion scenario 3four sendersmultihop pathstimeoutretransmit
λin
Q what happens as and increase λ
in
finite shared output link buffers
Host Aλin original data
Host B
λout
λin original data plus retransmitted data
Transport Layer 3-76
Causescosts of congestion scenario 3
another ldquocostrdquo of congestionwhen packet dropped any ldquoupstream transmission capacity used for that packet was wasted
Host A
Host B
λou
t
Transport Layer 3-77
Approaches towards congestion control
End-end congestion controlno explicit feedback from networkcongestion inferred from end-system observed loss delayapproach taken by TCP
Network-assisted congestion controlrouters provide feedback to end systems
single bit indicating congestion (SNA DECbit TCPIP ECN ATM)explicit rate sender should send at
Two broad approaches towards congestion control
Transport Layer 3-78
TCP Congestion Control
end-end control (no network assistance)sender limits transmissionLastByteSent-LastByteAcked
le CongWin
CongWin is dynamic function of perceived network congestion
How does sender perceive congestionloss event = timeout or3 duplicate acksTCP sender reduces rate (CongWin) after loss event
two modes of operationSlow Start (SS)Congestion avoidance (CA) or Additive Increase Multiplicative Decrease (AIMD)
Transport Layer 3-79
TCP congestion control bandwidth probing
ldquoprobing for bandwidthrdquo increase transmission rate on receipt of ACK until eventually loss occurs then decrease transmission rate
continue to increase on ACK decrease on loss (since available bandwidth is changing depending on other connections in network)
ACKs being received so increase rate
X
X
XX
X loss so decrease rate
send
ing
rate
time
Q how fast to increasedecreasedetails to follow
TCPrsquosldquosawtoothrdquobehavior
Transport Layer 3-80
TCP Congestion Control details
sender limits rate by limiting number of unACKed bytes ldquoin pipelinerdquo
cwnd differs from rwnd (how why)sender limited by min(cwndrwnd)
roughly
cwnd is dynamic function of perceived network congestion
rate = cwndRTT bytessec
LastByteSent-LastByteAcked le cwnd
cwndbytes
RTT
ACK(s)
Transport Layer 3-81
TCP Congestion Control more details
segment loss event reducing cwndtimeout no response from receiver
cut cwnd to 13 duplicate ACKs at least some segments getting through (recall fast retransmit)
cut cwnd in half less aggressively than on timeout
ACK received increase cwndTwo modes of operation
slowstart phase bull increase exponentially
fast (despite name) at connection start or following timeout
congestion avoidance bull increase linearly
Transport Layer 3-82
TCP Slow Start Phasewhen connection begins cwnd = 1 MSS
example MSS = 500 bytes amp RTT = 200 msecinitial rate = 20 kbps
available bandwidth may be gtgt MSSRTT
desirable to quickly ramp up to respectable rate
increase rate exponentially until first loss event or when threshold reached
double cwnd every RTTdone by incrementing cwnd by 1 for every ACK received
Host A
one segment
RTT
Host B
time
two segments
four segments
Transport Layer 3-83
Slow Start ExampleThe congestion window size grows very rapidly
For every ACK we increase CongWin by 1 irrespective of the number of segments ACKrsquoeddouble CongWinevery RTTinitial rate is slow but ramps up exponentially fast
TCP slows down the increase of CongWinwhen CongWin gt ssthresh
segment 1
ACK for segment 1
cwnd = 1
cwnd = 2 segment 2segment 3
ACK for segments 2
cwnd = 4 segment 4segment 5segment 6
ACK for segments 4
cwnd = 7
ACK for segments 3
ACK for segments 5
ACK for segments 6
cwnd = 3
cwnd = 5
cwnd = 6ACK for segments 7
cwnd = 8
segment 7
Transport Layer 3-84
TCP Congestion Avoidance Phase
when cwnd gt ssthreshgrow cwnd linearly
increase cwnd by 1 MSS per RTT approach possible congestion slower than in slowstartimplementation cwnd= cwnd + MSScwndfor each ACK received
ACKs increase cwndby 1 MSS per RTT additive increaseloss cut cwnd in half (non-timeout-detected loss ) multiplicative decrease
AIMD
AIMD Additive IncreaseMultiplicative Decrease
Transport Layer 3-85
Congestion AvoidanceCongestion avoidance phase is started if CongWin has reached the slow-start threshold value
If CongWin gt= ssthresh then each time an ACK is received increment CongWin as follows
bull CongWin = CongWin + 1CongWin (CongWin in segments)
bull In actual TCP implementation CongWin is in BytesCongWin = CongWin + MSS (MSSCongWin)
So CongWin is increased by one only if all CongWinsegments have been acknowledged
Transport Layer 3-86
Example Slow StartCongestion AvoidanceAssume that
ssthresh = 8
cwnd = 1
cwnd = 2
cwnd = 4
cwnd = 8
cwnd = 9
cwnd = 10
02468
101214
t=0
t=2
t=4
t=6
Roundtrip times
Cw
nd(in
seg
men
ts)
ssthresh
cwnd = 3
cwnd = 5cwnd = 6cwnd = 7
Transport Layer 3-87
Slow Start Congestion AvoidanceA typical plot of CongWin for a TCP connection
(MSS = 1500 bytes) with TCP Tahoe
SS
CA
ssthresh
Transport Layer 3-88
Responses to CongestionTCP assumes there is congestion if it detects a packet lossA TCP sender can detect lost packets via loss events
bull Timeout of a retransmission timerbull Receipt of 3 duplicate ACKs (fast retransmit)
TCP interprets a Timeout as a binary congestion signal When a timeout occurs the sender performs
ssthresh is set to half the current size of the congestion window
ssthresh = CongWin 2CongWin is reset to one
CongWin = 1and slow-start is entered
Transport Layer 3-89
Fast Recovery (differentiation btwn two loss events) After 3 dup ACKs (fast Retransmit)
ssthresh = CongWin2CongWin = CongWin2window then grows linearly
But after timeout eventCongWin = 1 MSS window then grows exponentiallyto the threshold then grows linearly
bull 3 dup ACKs indicates network capable of delivering some segmentsbull timeout before 3 dup ACKs is ldquomore alarmingrdquo
Philosophy
3-90
TCP Congestion ControlInitially
CongWin = 1ssthresh = advertised window size
New Ack receivedif (CongWin lt ssthresh) Slow Start
CongWin = CongWin + 1else Congestion Avoidance
CongWin = CongWin + 1CongWinTimeout
ssthresh = CongWin2CongWin = 1
Fast Retransmissionssthresh = CongWin2CongWin = CongWin2
Slow Start (exponential increase phase) is continued until CongWin reaches half of the level where the loss event occurred last time CongWin is increased slowly after (linear increase in Congestion Avoidance phase)
Transport Layer 3-91
Popular ldquoflavorsrdquo of TCP
ssthresh
ssthresh
TCP Tahoe
TCP Reno
Transmission round
cwnd
win
dow
siz
e (in
seg
men
ts)
Transport Layer 3-92
Summary TCP Congestion ControlWhen CongWin is below Threshold sender in slow-start phase window grows exponentiallyWhen CongWin is above Threshold sender is in congestion-avoidance phase window grows linearlyWhen a triple duplicate ACK occurs Threshold set to CongWin2 and CongWin set to ThresholdWhen timeout occurs Threshold set to CongWin2 and CongWin is set to 1 MSS The actual sender window size is determined based on the congestion and flow control algorithms
SenderWin=min(RcvWinCongWin)
Transport Layer 3-93
TCP Congestion Control SummaryEvent State TCP Sender Action Commentary
ACK receipt for previously unackeddata
Slow Start (SS)
CongWin = CongWin + MSS If (CongWin gt Threshold)
set state to ldquoCongestion Avoidancerdquo
Resulting in a doubling of CongWin every RTT
ACK receipt for previously unackeddata
CongestionAvoidance (CA)
CongWin = CongWin+MSS (MSSCongWin)
Additive increase resulting in increase of CongWin by 1 MSS every RTT
Loss event detected by triple duplicate ACK
SS or CA Threshold = CongWin2 CongWin = ThresholdSet state to ldquoCongestion Avoidancerdquo
Fast recovery implementing multiplicative decrease CongWin will not drop below 1 MSS
Timeout SS or CA Threshold = CongWin2 CongWin = 1 MSSSet state to ldquoSlow Startrdquo
Enter slow start
Duplicate ACK
SS or CA Increment duplicate ACK count for segment being acked
CongWin and Threshold not changed
Transport Layer 3-94
TCP throughput
Q whatrsquos average throughout of TCP as function of window size RTT
ignoring slow startlet W be window size when loss occurs
when window is W throughput is WRTTjust after loss window drops to W2 throughput to W2RTT average throughout 75 WRTT
Transport Layer 3-95
TCP Futures TCP over ldquolong fat pipesrdquo
example 1500 byte segments 100ms RTT want 10 Gbps throughputrequires window size W = 83333 in-flight segmentsthroughput in terms of loss rate
L = 210-10 Wownew versions of TCP for high-speed
LRTTMSSsdot221
Transport Layer 3-96
Fairness goal if K TCP sessions share same bottleneck link of bandwidth R each should have average rate of RK
TCP connection 1
bottleneckrouter
capacity R
TCP connection 2
TCP Fairness
Transport Layer 3-97
Why is TCP fairTwo competing sessions
Additive increase gives slope of 1 as throughout increasesmultiplicative decrease decreases throughput proportionally
R
R
equal bandwidth share
Connection 1 throughput
Conn
ecti
on 2
thr
ough
p ut
congestion avoidance additive increaseloss decrease window by factor of 2
congestion avoidance additive increaseloss decrease window by factor of 2
Transport Layer 3-98
Fairness (more)Fairness and UDP
Multimedia apps often do not use TCP
do not want rate throttled by congestion control
Instead use UDPpump audiovideo at constant rate tolerate packet loss
Research area TCP friendly
Fairness and parallel TCP connectionsnothing prevents app from opening parallel cnctionsbetween 2 hostsWeb browsers do this Example link of rate R supporting 9 cnctions
new app asks for 1 TCP gets rate R10new app asks for 11 TCPs gets R2
Transport Layer 3-99
TCP Connection ManagementRecall TCP sender receiver
establish ldquoconnectionrdquobefore exchanging data segmentsinitialize TCP variables
seq sbuffers flow control info (eg RcvWindow)
client connection initiatorSocket clientSocket = new Socket(hostnameport
number)
server contacted by clientSocket connectionSocket = welcomeSocketaccept()
Three way handshakeStep 1 client host sends TCP
SYN segment to serverspecifies initial seq no data
Step 2 server host receives SYN replies with SYNACK segment
server allocates buffersspecifies server initial seq
Step 3 client receives SYNACK replies with ACK segment which may contain data
Transport Layer 3-100
TCP Connection Management (cont)
Closing a connection
client closes socketclientSocketclose()
Step 1 client end system sends TCP FIN control segment to server
Step 2 server receives FIN replies with ACK Closes connection sends FIN
client
FIN
server
ACK
ACK
FIN
close
close
closed
tim
ed w
ait
Transport Layer 3-101
TCP Connection Management (cont)
Step 3 client receives FIN replies with ACK
Enters ldquotimed waitrdquo -will respond with ACK to received FINs
Step 4 server receives ACK Connection closed
client
FIN
server
ACK
ACK
FIN
closing
closing
closed
tim
ed w
ait
closed
Transport Layer 3-102
TCP Connection Management (cont)
TCP clientlifecycle
TCP serverlifecycle
Transport Layer 3-103
Tuning TCPIP Parameters TCPIP parameters
A set of default values may not be optimal for all applicationsThe network administrator may wish to turn on or off some TCPIP functions for performance or security considerations
Many Unix and Linux systems provide some flexibility in tuning the TCPIP kernelsbinsysctl is used to configure the Linux kernel parameters at runtime
Default kernel configuration file is sbinsysctlconfFrequently used sysctl options
bull sysctl ndasha or sysctl ndashA list all current valuesbull sysctl ndashp file_name load the sysctl setting from a configuration
filebull sysctl ndashw variable=value change the value of the parameter
Transport Layer 3-104
SomeTCP Parameters in Linux Kerneltcp_syn_retries
Number of SYN packets the kernel will send before giving up on the new connection
tcp_synack_retriesnumber of SYN+ACK packets sent before the kernel gives up on the connection
tcp_window_scalingMaximum window size of 65535 bytes not enough for for really fast networks The window scaling options allows for almost gigabyte windows which is good for connections with large delay-bandwidth product
tcp_max_syn_backlogMaximal number of remembered connection requests which still did not receive an acknowledgment from connecting client
tcp_fin_timeoutHow many seconds to wait for a final FIN packet before the socket is closed required to prevent denial-of-service (DoS) attacks Default value is 60 seconds
Transport Layer 3-105
SomeTCP Parameters in Linux Kerneltcp_rmem
This is a vector of 3 integers [min default max] These parameters are used by TCP to dynamically adjust receive buffer sizesmin - minimum size of the receive buffer used by each TCP socket The default value is 4K default - the default size of the receive buffer for a TCP socket The default value is 87380 bytes and is lowered to 43689 in low memory systems If larger receive buffer sizes are desired this value should be increased max - the maximum size of the receive buffer used by each TCP socket The default value of 873802 bytes is lowered to 87380 in low memory systems
tcp_smemSend buffer parameters [min default max] similar to tcp_rmem
- Chapter 3 Transport Layer
- Transport services and protocols
- Transport vs network layer
- Internet transport-layer protocols
- Multiplexingdemultiplexing
- How demultiplexing works
- Connectionless demultiplexing
- Connection-oriented demux
- Connection-oriented demux (cont)
- Connection-oriented demux Threaded Web Server
- UDP User Datagram Protocol [RFC 768]
- UDP more
- UDP checksum
- Principles of Reliable data transfer
- Reliable data transfer getting started
- Reliable data transfer getting started
- Rdt10 reliable transfer over a reliable channel
- Rdt20 channel with bit errors
- rdt20 FSM specification
- rdt20 operation with no errors
- rdt20 error scenario
- rdt20 has a fatal flaw
- rdt21 sender handles garbled ACKNAKs
- rdt21 receiver handles garbled ACKNAKs
- rdt21 discussion
- rdt22 a NAK-free protocol
- rdt22 sender receiver fragments
- rdt30 channels with errors and loss
- rdt30 sender
- rdt30 in action
- rdt30 in action
- Performance of rdt30
- rdt30 stop-and-wait operation
- Pipelined protocols
- Pipelining increased utilization
- Go-Back-N
- GBN sender extended FSM
- GBN receiver extended FSM
- GBN inaction
- Selective Repeat
- Selective repeat sender receiver windows
- Selective repeat
- Selective repeat in action
- Selective repeat dilemma
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- TCP Overview RFCs 793 1122 1323 2018 2581
- TCP segment structure
- TCP seq rsquos and ACKs
- TCP Round Trip Time and Timeout
- TCP Round Trip Time and Timeout
- Example RTT estimation
- TCP Round Trip Time and Timeout
- TCP reliable data transfer
- TCP sender events
- TCP sender(simplified)
- TCP retransmission scenarios
- TCP retransmission scenarios (more)
- TCP ACK generation [RFC 1122 RFC 2581]
- Fast Retransmit
- Fast Retransmit
- Fast retransmit algorithm
- TCP Flow Control
- TCP Flow control how it works
- Sliding Window Flow Control Example
- Principles of Congestion Control
- Causescosts of congestion scenario 1
- Causescosts of congestion scenario 2
- Causescosts of congestion scenario 2
- Causescosts of congestion scenario 3
- Causescosts of congestion scenario 3
- Approaches towards congestion control
- TCP Congestion Control
- TCP congestion control bandwidth probing
- TCP Congestion Control details
- TCP Congestion Control more details
- TCP Slow Start Phase
- Slow Start Example
- TCP Congestion Avoidance Phase
- Congestion Avoidance
- Example Slow StartCongestion Avoidance
- Slow Start Congestion Avoidance
- Responses to Congestion
- Fast Recovery (differentiation btwn two loss events)
- TCP Congestion Control
- Popular ldquoflavorsrdquo of TCP
- Summary TCP Congestion Control
- TCP Congestion Control Summary
- TCP throughput
- TCP Futures TCP over ldquolong fat pipesrdquo
- TCP Fairness
- Why is TCP fair
- Fairness (more)
- TCP Connection Management
- TCP Connection Management (cont)
- TCP Connection Management (cont)
- TCP Connection Management (cont)
- Tuning TCPIP Parameters
- SomeTCP Parameters in Linux Kernel
- SomeTCP Parameters in Linux Kernel
-
Transport Layer 3-73
Causescosts of congestion scenario 2
one router finite buffers sender retransmission of lost packet
finite shared output link buffers
Host A λin original data
Host B
λout
λin original data plus retransmitted data
Transport Layer 3-74
Causescosts of congestion scenario 2always (goodput)ldquoperfectrdquo retransmission only when loss
retransmission of delayed (not lost) packet makes larger(than perfect case) for same
λin
λout=
λin
λoutgtλ
inλout
ldquocostsrdquo of congestionmore work (retrans) for given ldquogoodputrdquounneeded retransmissions link carries multiple copies of pkt
R2
R2λin
λ out
b
R2
R2λin
λ out
a
R2
R2λin
λ out
c
R4
R3
Transport Layer 3-75
Causescosts of congestion scenario 3four sendersmultihop pathstimeoutretransmit
λin
Q what happens as and increase λ
in
finite shared output link buffers
Host Aλin original data
Host B
λout
λin original data plus retransmitted data
Transport Layer 3-76
Causescosts of congestion scenario 3
another ldquocostrdquo of congestionwhen packet dropped any ldquoupstream transmission capacity used for that packet was wasted
Host A
Host B
λou
t
Transport Layer 3-77
Approaches towards congestion control
End-end congestion controlno explicit feedback from networkcongestion inferred from end-system observed loss delayapproach taken by TCP
Network-assisted congestion controlrouters provide feedback to end systems
single bit indicating congestion (SNA DECbit TCPIP ECN ATM)explicit rate sender should send at
Two broad approaches towards congestion control
Transport Layer 3-78
TCP Congestion Control
end-end control (no network assistance)sender limits transmissionLastByteSent-LastByteAcked
le CongWin
CongWin is dynamic function of perceived network congestion
How does sender perceive congestionloss event = timeout or3 duplicate acksTCP sender reduces rate (CongWin) after loss event
two modes of operationSlow Start (SS)Congestion avoidance (CA) or Additive Increase Multiplicative Decrease (AIMD)
Transport Layer 3-79
TCP congestion control bandwidth probing
ldquoprobing for bandwidthrdquo increase transmission rate on receipt of ACK until eventually loss occurs then decrease transmission rate
continue to increase on ACK decrease on loss (since available bandwidth is changing depending on other connections in network)
ACKs being received so increase rate
X
X
XX
X loss so decrease rate
send
ing
rate
time
Q how fast to increasedecreasedetails to follow
TCPrsquosldquosawtoothrdquobehavior
Transport Layer 3-80
TCP Congestion Control details
sender limits rate by limiting number of unACKed bytes ldquoin pipelinerdquo
cwnd differs from rwnd (how why)sender limited by min(cwndrwnd)
roughly
cwnd is dynamic function of perceived network congestion
rate = cwndRTT bytessec
LastByteSent-LastByteAcked le cwnd
cwndbytes
RTT
ACK(s)
Transport Layer 3-81
TCP Congestion Control more details
segment loss event reducing cwndtimeout no response from receiver
cut cwnd to 13 duplicate ACKs at least some segments getting through (recall fast retransmit)
cut cwnd in half less aggressively than on timeout
ACK received increase cwndTwo modes of operation
slowstart phase bull increase exponentially
fast (despite name) at connection start or following timeout
congestion avoidance bull increase linearly
Transport Layer 3-82
TCP Slow Start Phasewhen connection begins cwnd = 1 MSS
example MSS = 500 bytes amp RTT = 200 msecinitial rate = 20 kbps
available bandwidth may be gtgt MSSRTT
desirable to quickly ramp up to respectable rate
increase rate exponentially until first loss event or when threshold reached
double cwnd every RTTdone by incrementing cwnd by 1 for every ACK received
Host A
one segment
RTT
Host B
time
two segments
four segments
Transport Layer 3-83
Slow Start ExampleThe congestion window size grows very rapidly
For every ACK we increase CongWin by 1 irrespective of the number of segments ACKrsquoeddouble CongWinevery RTTinitial rate is slow but ramps up exponentially fast
TCP slows down the increase of CongWinwhen CongWin gt ssthresh
segment 1
ACK for segment 1
cwnd = 1
cwnd = 2 segment 2segment 3
ACK for segments 2
cwnd = 4 segment 4segment 5segment 6
ACK for segments 4
cwnd = 7
ACK for segments 3
ACK for segments 5
ACK for segments 6
cwnd = 3
cwnd = 5
cwnd = 6ACK for segments 7
cwnd = 8
segment 7
Transport Layer 3-84
TCP Congestion Avoidance Phase
when cwnd gt ssthreshgrow cwnd linearly
increase cwnd by 1 MSS per RTT approach possible congestion slower than in slowstartimplementation cwnd= cwnd + MSScwndfor each ACK received
ACKs increase cwndby 1 MSS per RTT additive increaseloss cut cwnd in half (non-timeout-detected loss ) multiplicative decrease
AIMD
AIMD Additive IncreaseMultiplicative Decrease
Transport Layer 3-85
Congestion AvoidanceCongestion avoidance phase is started if CongWin has reached the slow-start threshold value
If CongWin gt= ssthresh then each time an ACK is received increment CongWin as follows
bull CongWin = CongWin + 1CongWin (CongWin in segments)
bull In actual TCP implementation CongWin is in BytesCongWin = CongWin + MSS (MSSCongWin)
So CongWin is increased by one only if all CongWinsegments have been acknowledged
Transport Layer 3-86
Example Slow StartCongestion AvoidanceAssume that
ssthresh = 8
cwnd = 1
cwnd = 2
cwnd = 4
cwnd = 8
cwnd = 9
cwnd = 10
02468
101214
t=0
t=2
t=4
t=6
Roundtrip times
Cw
nd(in
seg
men
ts)
ssthresh
cwnd = 3
cwnd = 5cwnd = 6cwnd = 7
Transport Layer 3-87
Slow Start Congestion AvoidanceA typical plot of CongWin for a TCP connection
(MSS = 1500 bytes) with TCP Tahoe
SS
CA
ssthresh
Transport Layer 3-88
Responses to CongestionTCP assumes there is congestion if it detects a packet lossA TCP sender can detect lost packets via loss events
bull Timeout of a retransmission timerbull Receipt of 3 duplicate ACKs (fast retransmit)
TCP interprets a Timeout as a binary congestion signal When a timeout occurs the sender performs
ssthresh is set to half the current size of the congestion window
ssthresh = CongWin 2CongWin is reset to one
CongWin = 1and slow-start is entered
Transport Layer 3-89
Fast Recovery (differentiation btwn two loss events) After 3 dup ACKs (fast Retransmit)
ssthresh = CongWin2CongWin = CongWin2window then grows linearly
But after timeout eventCongWin = 1 MSS window then grows exponentiallyto the threshold then grows linearly
bull 3 dup ACKs indicates network capable of delivering some segmentsbull timeout before 3 dup ACKs is ldquomore alarmingrdquo
Philosophy
3-90
TCP Congestion ControlInitially
CongWin = 1ssthresh = advertised window size
New Ack receivedif (CongWin lt ssthresh) Slow Start
CongWin = CongWin + 1else Congestion Avoidance
CongWin = CongWin + 1CongWinTimeout
ssthresh = CongWin2CongWin = 1
Fast Retransmissionssthresh = CongWin2CongWin = CongWin2
Slow Start (exponential increase phase) is continued until CongWin reaches half of the level where the loss event occurred last time CongWin is increased slowly after (linear increase in Congestion Avoidance phase)
Transport Layer 3-91
Popular ldquoflavorsrdquo of TCP
ssthresh
ssthresh
TCP Tahoe
TCP Reno
Transmission round
cwnd
win
dow
siz
e (in
seg
men
ts)
Transport Layer 3-92
Summary TCP Congestion ControlWhen CongWin is below Threshold sender in slow-start phase window grows exponentiallyWhen CongWin is above Threshold sender is in congestion-avoidance phase window grows linearlyWhen a triple duplicate ACK occurs Threshold set to CongWin2 and CongWin set to ThresholdWhen timeout occurs Threshold set to CongWin2 and CongWin is set to 1 MSS The actual sender window size is determined based on the congestion and flow control algorithms
SenderWin=min(RcvWinCongWin)
Transport Layer 3-93
TCP Congestion Control SummaryEvent State TCP Sender Action Commentary
ACK receipt for previously unackeddata
Slow Start (SS)
CongWin = CongWin + MSS If (CongWin gt Threshold)
set state to ldquoCongestion Avoidancerdquo
Resulting in a doubling of CongWin every RTT
ACK receipt for previously unackeddata
CongestionAvoidance (CA)
CongWin = CongWin+MSS (MSSCongWin)
Additive increase resulting in increase of CongWin by 1 MSS every RTT
Loss event detected by triple duplicate ACK
SS or CA Threshold = CongWin2 CongWin = ThresholdSet state to ldquoCongestion Avoidancerdquo
Fast recovery implementing multiplicative decrease CongWin will not drop below 1 MSS
Timeout SS or CA Threshold = CongWin2 CongWin = 1 MSSSet state to ldquoSlow Startrdquo
Enter slow start
Duplicate ACK
SS or CA Increment duplicate ACK count for segment being acked
CongWin and Threshold not changed
Transport Layer 3-94
TCP throughput
Q whatrsquos average throughout of TCP as function of window size RTT
ignoring slow startlet W be window size when loss occurs
when window is W throughput is WRTTjust after loss window drops to W2 throughput to W2RTT average throughout 75 WRTT
Transport Layer 3-95
TCP Futures TCP over ldquolong fat pipesrdquo
example 1500 byte segments 100ms RTT want 10 Gbps throughputrequires window size W = 83333 in-flight segmentsthroughput in terms of loss rate
L = 210-10 Wownew versions of TCP for high-speed
LRTTMSSsdot221
Transport Layer 3-96
Fairness goal if K TCP sessions share same bottleneck link of bandwidth R each should have average rate of RK
TCP connection 1
bottleneckrouter
capacity R
TCP connection 2
TCP Fairness
Transport Layer 3-97
Why is TCP fairTwo competing sessions
Additive increase gives slope of 1 as throughout increasesmultiplicative decrease decreases throughput proportionally
R
R
equal bandwidth share
Connection 1 throughput
Conn
ecti
on 2
thr
ough
p ut
congestion avoidance additive increaseloss decrease window by factor of 2
congestion avoidance additive increaseloss decrease window by factor of 2
Transport Layer 3-98
Fairness (more)Fairness and UDP
Multimedia apps often do not use TCP
do not want rate throttled by congestion control
Instead use UDPpump audiovideo at constant rate tolerate packet loss
Research area TCP friendly
Fairness and parallel TCP connectionsnothing prevents app from opening parallel cnctionsbetween 2 hostsWeb browsers do this Example link of rate R supporting 9 cnctions
new app asks for 1 TCP gets rate R10new app asks for 11 TCPs gets R2
Transport Layer 3-99
TCP Connection ManagementRecall TCP sender receiver
establish ldquoconnectionrdquobefore exchanging data segmentsinitialize TCP variables
seq sbuffers flow control info (eg RcvWindow)
client connection initiatorSocket clientSocket = new Socket(hostnameport
number)
server contacted by clientSocket connectionSocket = welcomeSocketaccept()
Three way handshakeStep 1 client host sends TCP
SYN segment to serverspecifies initial seq no data
Step 2 server host receives SYN replies with SYNACK segment
server allocates buffersspecifies server initial seq
Step 3 client receives SYNACK replies with ACK segment which may contain data
Transport Layer 3-100
TCP Connection Management (cont)
Closing a connection
client closes socketclientSocketclose()
Step 1 client end system sends TCP FIN control segment to server
Step 2 server receives FIN replies with ACK Closes connection sends FIN
client
FIN
server
ACK
ACK
FIN
close
close
closed
tim
ed w
ait
Transport Layer 3-101
TCP Connection Management (cont)
Step 3 client receives FIN replies with ACK
Enters ldquotimed waitrdquo -will respond with ACK to received FINs
Step 4 server receives ACK Connection closed
client
FIN
server
ACK
ACK
FIN
closing
closing
closed
tim
ed w
ait
closed
Transport Layer 3-102
TCP Connection Management (cont)
TCP clientlifecycle
TCP serverlifecycle
Transport Layer 3-103
Tuning TCPIP Parameters TCPIP parameters
A set of default values may not be optimal for all applicationsThe network administrator may wish to turn on or off some TCPIP functions for performance or security considerations
Many Unix and Linux systems provide some flexibility in tuning the TCPIP kernelsbinsysctl is used to configure the Linux kernel parameters at runtime
Default kernel configuration file is sbinsysctlconfFrequently used sysctl options
bull sysctl ndasha or sysctl ndashA list all current valuesbull sysctl ndashp file_name load the sysctl setting from a configuration
filebull sysctl ndashw variable=value change the value of the parameter
Transport Layer 3-104
SomeTCP Parameters in Linux Kerneltcp_syn_retries
Number of SYN packets the kernel will send before giving up on the new connection
tcp_synack_retriesnumber of SYN+ACK packets sent before the kernel gives up on the connection
tcp_window_scalingMaximum window size of 65535 bytes not enough for for really fast networks The window scaling options allows for almost gigabyte windows which is good for connections with large delay-bandwidth product
tcp_max_syn_backlogMaximal number of remembered connection requests which still did not receive an acknowledgment from connecting client
tcp_fin_timeoutHow many seconds to wait for a final FIN packet before the socket is closed required to prevent denial-of-service (DoS) attacks Default value is 60 seconds
Transport Layer 3-105
SomeTCP Parameters in Linux Kerneltcp_rmem
This is a vector of 3 integers [min default max] These parameters are used by TCP to dynamically adjust receive buffer sizesmin - minimum size of the receive buffer used by each TCP socket The default value is 4K default - the default size of the receive buffer for a TCP socket The default value is 87380 bytes and is lowered to 43689 in low memory systems If larger receive buffer sizes are desired this value should be increased max - the maximum size of the receive buffer used by each TCP socket The default value of 873802 bytes is lowered to 87380 in low memory systems
tcp_smemSend buffer parameters [min default max] similar to tcp_rmem
- Chapter 3 Transport Layer
- Transport services and protocols
- Transport vs network layer
- Internet transport-layer protocols
- Multiplexingdemultiplexing
- How demultiplexing works
- Connectionless demultiplexing
- Connection-oriented demux
- Connection-oriented demux (cont)
- Connection-oriented demux Threaded Web Server
- UDP User Datagram Protocol [RFC 768]
- UDP more
- UDP checksum
- Principles of Reliable data transfer
- Reliable data transfer getting started
- Reliable data transfer getting started
- Rdt10 reliable transfer over a reliable channel
- Rdt20 channel with bit errors
- rdt20 FSM specification
- rdt20 operation with no errors
- rdt20 error scenario
- rdt20 has a fatal flaw
- rdt21 sender handles garbled ACKNAKs
- rdt21 receiver handles garbled ACKNAKs
- rdt21 discussion
- rdt22 a NAK-free protocol
- rdt22 sender receiver fragments
- rdt30 channels with errors and loss
- rdt30 sender
- rdt30 in action
- rdt30 in action
- Performance of rdt30
- rdt30 stop-and-wait operation
- Pipelined protocols
- Pipelining increased utilization
- Go-Back-N
- GBN sender extended FSM
- GBN receiver extended FSM
- GBN inaction
- Selective Repeat
- Selective repeat sender receiver windows
- Selective repeat
- Selective repeat in action
- Selective repeat dilemma
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- TCP Overview RFCs 793 1122 1323 2018 2581
- TCP segment structure
- TCP seq rsquos and ACKs
- TCP Round Trip Time and Timeout
- TCP Round Trip Time and Timeout
- Example RTT estimation
- TCP Round Trip Time and Timeout
- TCP reliable data transfer
- TCP sender events
- TCP sender(simplified)
- TCP retransmission scenarios
- TCP retransmission scenarios (more)
- TCP ACK generation [RFC 1122 RFC 2581]
- Fast Retransmit
- Fast Retransmit
- Fast retransmit algorithm
- TCP Flow Control
- TCP Flow control how it works
- Sliding Window Flow Control Example
- Principles of Congestion Control
- Causescosts of congestion scenario 1
- Causescosts of congestion scenario 2
- Causescosts of congestion scenario 2
- Causescosts of congestion scenario 3
- Causescosts of congestion scenario 3
- Approaches towards congestion control
- TCP Congestion Control
- TCP congestion control bandwidth probing
- TCP Congestion Control details
- TCP Congestion Control more details
- TCP Slow Start Phase
- Slow Start Example
- TCP Congestion Avoidance Phase
- Congestion Avoidance
- Example Slow StartCongestion Avoidance
- Slow Start Congestion Avoidance
- Responses to Congestion
- Fast Recovery (differentiation btwn two loss events)
- TCP Congestion Control
- Popular ldquoflavorsrdquo of TCP
- Summary TCP Congestion Control
- TCP Congestion Control Summary
- TCP throughput
- TCP Futures TCP over ldquolong fat pipesrdquo
- TCP Fairness
- Why is TCP fair
- Fairness (more)
- TCP Connection Management
- TCP Connection Management (cont)
- TCP Connection Management (cont)
- TCP Connection Management (cont)
- Tuning TCPIP Parameters
- SomeTCP Parameters in Linux Kernel
- SomeTCP Parameters in Linux Kernel
-
Transport Layer 3-74
Causescosts of congestion scenario 2always (goodput)ldquoperfectrdquo retransmission only when loss
retransmission of delayed (not lost) packet makes larger(than perfect case) for same
λin
λout=
λin
λoutgtλ
inλout
ldquocostsrdquo of congestionmore work (retrans) for given ldquogoodputrdquounneeded retransmissions link carries multiple copies of pkt
R2
R2λin
λ out
b
R2
R2λin
λ out
a
R2
R2λin
λ out
c
R4
R3
Transport Layer 3-75
Causescosts of congestion scenario 3four sendersmultihop pathstimeoutretransmit
λin
Q what happens as and increase λ
in
finite shared output link buffers
Host Aλin original data
Host B
λout
λin original data plus retransmitted data
Transport Layer 3-76
Causescosts of congestion scenario 3
another ldquocostrdquo of congestionwhen packet dropped any ldquoupstream transmission capacity used for that packet was wasted
Host A
Host B
λou
t
Transport Layer 3-77
Approaches towards congestion control
End-end congestion controlno explicit feedback from networkcongestion inferred from end-system observed loss delayapproach taken by TCP
Network-assisted congestion controlrouters provide feedback to end systems
single bit indicating congestion (SNA DECbit TCPIP ECN ATM)explicit rate sender should send at
Two broad approaches towards congestion control
Transport Layer 3-78
TCP Congestion Control
end-end control (no network assistance)sender limits transmissionLastByteSent-LastByteAcked
le CongWin
CongWin is dynamic function of perceived network congestion
How does sender perceive congestionloss event = timeout or3 duplicate acksTCP sender reduces rate (CongWin) after loss event
two modes of operationSlow Start (SS)Congestion avoidance (CA) or Additive Increase Multiplicative Decrease (AIMD)
Transport Layer 3-79
TCP congestion control bandwidth probing
ldquoprobing for bandwidthrdquo increase transmission rate on receipt of ACK until eventually loss occurs then decrease transmission rate
continue to increase on ACK decrease on loss (since available bandwidth is changing depending on other connections in network)
ACKs being received so increase rate
X
X
XX
X loss so decrease rate
send
ing
rate
time
Q how fast to increasedecreasedetails to follow
TCPrsquosldquosawtoothrdquobehavior
Transport Layer 3-80
TCP Congestion Control details
sender limits rate by limiting number of unACKed bytes ldquoin pipelinerdquo
cwnd differs from rwnd (how why)sender limited by min(cwndrwnd)
roughly
cwnd is dynamic function of perceived network congestion
rate = cwndRTT bytessec
LastByteSent-LastByteAcked le cwnd
cwndbytes
RTT
ACK(s)
Transport Layer 3-81
TCP Congestion Control more details
segment loss event reducing cwndtimeout no response from receiver
cut cwnd to 13 duplicate ACKs at least some segments getting through (recall fast retransmit)
cut cwnd in half less aggressively than on timeout
ACK received increase cwndTwo modes of operation
slowstart phase bull increase exponentially
fast (despite name) at connection start or following timeout
congestion avoidance bull increase linearly
Transport Layer 3-82
TCP Slow Start Phasewhen connection begins cwnd = 1 MSS
example MSS = 500 bytes amp RTT = 200 msecinitial rate = 20 kbps
available bandwidth may be gtgt MSSRTT
desirable to quickly ramp up to respectable rate
increase rate exponentially until first loss event or when threshold reached
double cwnd every RTTdone by incrementing cwnd by 1 for every ACK received
Host A
one segment
RTT
Host B
time
two segments
four segments
Transport Layer 3-83
Slow Start ExampleThe congestion window size grows very rapidly
For every ACK we increase CongWin by 1 irrespective of the number of segments ACKrsquoeddouble CongWinevery RTTinitial rate is slow but ramps up exponentially fast
TCP slows down the increase of CongWinwhen CongWin gt ssthresh
segment 1
ACK for segment 1
cwnd = 1
cwnd = 2 segment 2segment 3
ACK for segments 2
cwnd = 4 segment 4segment 5segment 6
ACK for segments 4
cwnd = 7
ACK for segments 3
ACK for segments 5
ACK for segments 6
cwnd = 3
cwnd = 5
cwnd = 6ACK for segments 7
cwnd = 8
segment 7
Transport Layer 3-84
TCP Congestion Avoidance Phase
when cwnd gt ssthreshgrow cwnd linearly
increase cwnd by 1 MSS per RTT approach possible congestion slower than in slowstartimplementation cwnd= cwnd + MSScwndfor each ACK received
ACKs increase cwndby 1 MSS per RTT additive increaseloss cut cwnd in half (non-timeout-detected loss ) multiplicative decrease
AIMD
AIMD Additive IncreaseMultiplicative Decrease
Transport Layer 3-85
Congestion AvoidanceCongestion avoidance phase is started if CongWin has reached the slow-start threshold value
If CongWin gt= ssthresh then each time an ACK is received increment CongWin as follows
bull CongWin = CongWin + 1CongWin (CongWin in segments)
bull In actual TCP implementation CongWin is in BytesCongWin = CongWin + MSS (MSSCongWin)
So CongWin is increased by one only if all CongWinsegments have been acknowledged
Transport Layer 3-86
Example Slow StartCongestion AvoidanceAssume that
ssthresh = 8
cwnd = 1
cwnd = 2
cwnd = 4
cwnd = 8
cwnd = 9
cwnd = 10
02468
101214
t=0
t=2
t=4
t=6
Roundtrip times
Cw
nd(in
seg
men
ts)
ssthresh
cwnd = 3
cwnd = 5cwnd = 6cwnd = 7
Transport Layer 3-87
Slow Start Congestion AvoidanceA typical plot of CongWin for a TCP connection
(MSS = 1500 bytes) with TCP Tahoe
SS
CA
ssthresh
Transport Layer 3-88
Responses to CongestionTCP assumes there is congestion if it detects a packet lossA TCP sender can detect lost packets via loss events
bull Timeout of a retransmission timerbull Receipt of 3 duplicate ACKs (fast retransmit)
TCP interprets a Timeout as a binary congestion signal When a timeout occurs the sender performs
ssthresh is set to half the current size of the congestion window
ssthresh = CongWin 2CongWin is reset to one
CongWin = 1and slow-start is entered
Transport Layer 3-89
Fast Recovery (differentiation btwn two loss events) After 3 dup ACKs (fast Retransmit)
ssthresh = CongWin2CongWin = CongWin2window then grows linearly
But after timeout eventCongWin = 1 MSS window then grows exponentiallyto the threshold then grows linearly
bull 3 dup ACKs indicates network capable of delivering some segmentsbull timeout before 3 dup ACKs is ldquomore alarmingrdquo
Philosophy
3-90
TCP Congestion ControlInitially
CongWin = 1ssthresh = advertised window size
New Ack receivedif (CongWin lt ssthresh) Slow Start
CongWin = CongWin + 1else Congestion Avoidance
CongWin = CongWin + 1CongWinTimeout
ssthresh = CongWin2CongWin = 1
Fast Retransmissionssthresh = CongWin2CongWin = CongWin2
Slow Start (exponential increase phase) is continued until CongWin reaches half of the level where the loss event occurred last time CongWin is increased slowly after (linear increase in Congestion Avoidance phase)
Transport Layer 3-91
Popular ldquoflavorsrdquo of TCP
ssthresh
ssthresh
TCP Tahoe
TCP Reno
Transmission round
cwnd
win
dow
siz
e (in
seg
men
ts)
Transport Layer 3-92
Summary TCP Congestion ControlWhen CongWin is below Threshold sender in slow-start phase window grows exponentiallyWhen CongWin is above Threshold sender is in congestion-avoidance phase window grows linearlyWhen a triple duplicate ACK occurs Threshold set to CongWin2 and CongWin set to ThresholdWhen timeout occurs Threshold set to CongWin2 and CongWin is set to 1 MSS The actual sender window size is determined based on the congestion and flow control algorithms
SenderWin=min(RcvWinCongWin)
Transport Layer 3-93
TCP Congestion Control SummaryEvent State TCP Sender Action Commentary
ACK receipt for previously unackeddata
Slow Start (SS)
CongWin = CongWin + MSS If (CongWin gt Threshold)
set state to ldquoCongestion Avoidancerdquo
Resulting in a doubling of CongWin every RTT
ACK receipt for previously unackeddata
CongestionAvoidance (CA)
CongWin = CongWin+MSS (MSSCongWin)
Additive increase resulting in increase of CongWin by 1 MSS every RTT
Loss event detected by triple duplicate ACK
SS or CA Threshold = CongWin2 CongWin = ThresholdSet state to ldquoCongestion Avoidancerdquo
Fast recovery implementing multiplicative decrease CongWin will not drop below 1 MSS
Timeout SS or CA Threshold = CongWin2 CongWin = 1 MSSSet state to ldquoSlow Startrdquo
Enter slow start
Duplicate ACK
SS or CA Increment duplicate ACK count for segment being acked
CongWin and Threshold not changed
Transport Layer 3-94
TCP throughput
Q whatrsquos average throughout of TCP as function of window size RTT
ignoring slow startlet W be window size when loss occurs
when window is W throughput is WRTTjust after loss window drops to W2 throughput to W2RTT average throughout 75 WRTT
Transport Layer 3-95
TCP Futures TCP over ldquolong fat pipesrdquo
example 1500 byte segments 100ms RTT want 10 Gbps throughputrequires window size W = 83333 in-flight segmentsthroughput in terms of loss rate
L = 210-10 Wownew versions of TCP for high-speed
LRTTMSSsdot221
Transport Layer 3-96
Fairness goal if K TCP sessions share same bottleneck link of bandwidth R each should have average rate of RK
TCP connection 1
bottleneckrouter
capacity R
TCP connection 2
TCP Fairness
Transport Layer 3-97
Why is TCP fairTwo competing sessions
Additive increase gives slope of 1 as throughout increasesmultiplicative decrease decreases throughput proportionally
R
R
equal bandwidth share
Connection 1 throughput
Conn
ecti
on 2
thr
ough
p ut
congestion avoidance additive increaseloss decrease window by factor of 2
congestion avoidance additive increaseloss decrease window by factor of 2
Transport Layer 3-98
Fairness (more)Fairness and UDP
Multimedia apps often do not use TCP
do not want rate throttled by congestion control
Instead use UDPpump audiovideo at constant rate tolerate packet loss
Research area TCP friendly
Fairness and parallel TCP connectionsnothing prevents app from opening parallel cnctionsbetween 2 hostsWeb browsers do this Example link of rate R supporting 9 cnctions
new app asks for 1 TCP gets rate R10new app asks for 11 TCPs gets R2
Transport Layer 3-99
TCP Connection ManagementRecall TCP sender receiver
establish ldquoconnectionrdquobefore exchanging data segmentsinitialize TCP variables
seq sbuffers flow control info (eg RcvWindow)
client connection initiatorSocket clientSocket = new Socket(hostnameport
number)
server contacted by clientSocket connectionSocket = welcomeSocketaccept()
Three way handshakeStep 1 client host sends TCP
SYN segment to serverspecifies initial seq no data
Step 2 server host receives SYN replies with SYNACK segment
server allocates buffersspecifies server initial seq
Step 3 client receives SYNACK replies with ACK segment which may contain data
Transport Layer 3-100
TCP Connection Management (cont)
Closing a connection
client closes socketclientSocketclose()
Step 1 client end system sends TCP FIN control segment to server
Step 2 server receives FIN replies with ACK Closes connection sends FIN
client
FIN
server
ACK
ACK
FIN
close
close
closed
tim
ed w
ait
Transport Layer 3-101
TCP Connection Management (cont)
Step 3 client receives FIN replies with ACK
Enters ldquotimed waitrdquo -will respond with ACK to received FINs
Step 4 server receives ACK Connection closed
client
FIN
server
ACK
ACK
FIN
closing
closing
closed
tim
ed w
ait
closed
Transport Layer 3-102
TCP Connection Management (cont)
TCP clientlifecycle
TCP serverlifecycle
Transport Layer 3-103
Tuning TCPIP Parameters TCPIP parameters
A set of default values may not be optimal for all applicationsThe network administrator may wish to turn on or off some TCPIP functions for performance or security considerations
Many Unix and Linux systems provide some flexibility in tuning the TCPIP kernelsbinsysctl is used to configure the Linux kernel parameters at runtime
Default kernel configuration file is sbinsysctlconfFrequently used sysctl options
bull sysctl ndasha or sysctl ndashA list all current valuesbull sysctl ndashp file_name load the sysctl setting from a configuration
filebull sysctl ndashw variable=value change the value of the parameter
Transport Layer 3-104
SomeTCP Parameters in Linux Kerneltcp_syn_retries
Number of SYN packets the kernel will send before giving up on the new connection
tcp_synack_retriesnumber of SYN+ACK packets sent before the kernel gives up on the connection
tcp_window_scalingMaximum window size of 65535 bytes not enough for for really fast networks The window scaling options allows for almost gigabyte windows which is good for connections with large delay-bandwidth product
tcp_max_syn_backlogMaximal number of remembered connection requests which still did not receive an acknowledgment from connecting client
tcp_fin_timeoutHow many seconds to wait for a final FIN packet before the socket is closed required to prevent denial-of-service (DoS) attacks Default value is 60 seconds
Transport Layer 3-105
SomeTCP Parameters in Linux Kerneltcp_rmem
This is a vector of 3 integers [min default max] These parameters are used by TCP to dynamically adjust receive buffer sizesmin - minimum size of the receive buffer used by each TCP socket The default value is 4K default - the default size of the receive buffer for a TCP socket The default value is 87380 bytes and is lowered to 43689 in low memory systems If larger receive buffer sizes are desired this value should be increased max - the maximum size of the receive buffer used by each TCP socket The default value of 873802 bytes is lowered to 87380 in low memory systems
tcp_smemSend buffer parameters [min default max] similar to tcp_rmem
- Chapter 3 Transport Layer
- Transport services and protocols
- Transport vs network layer
- Internet transport-layer protocols
- Multiplexingdemultiplexing
- How demultiplexing works
- Connectionless demultiplexing
- Connection-oriented demux
- Connection-oriented demux (cont)
- Connection-oriented demux Threaded Web Server
- UDP User Datagram Protocol [RFC 768]
- UDP more
- UDP checksum
- Principles of Reliable data transfer
- Reliable data transfer getting started
- Reliable data transfer getting started
- Rdt10 reliable transfer over a reliable channel
- Rdt20 channel with bit errors
- rdt20 FSM specification
- rdt20 operation with no errors
- rdt20 error scenario
- rdt20 has a fatal flaw
- rdt21 sender handles garbled ACKNAKs
- rdt21 receiver handles garbled ACKNAKs
- rdt21 discussion
- rdt22 a NAK-free protocol
- rdt22 sender receiver fragments
- rdt30 channels with errors and loss
- rdt30 sender
- rdt30 in action
- rdt30 in action
- Performance of rdt30
- rdt30 stop-and-wait operation
- Pipelined protocols
- Pipelining increased utilization
- Go-Back-N
- GBN sender extended FSM
- GBN receiver extended FSM
- GBN inaction
- Selective Repeat
- Selective repeat sender receiver windows
- Selective repeat
- Selective repeat in action
- Selective repeat dilemma
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- TCP Overview RFCs 793 1122 1323 2018 2581
- TCP segment structure
- TCP seq rsquos and ACKs
- TCP Round Trip Time and Timeout
- TCP Round Trip Time and Timeout
- Example RTT estimation
- TCP Round Trip Time and Timeout
- TCP reliable data transfer
- TCP sender events
- TCP sender(simplified)
- TCP retransmission scenarios
- TCP retransmission scenarios (more)
- TCP ACK generation [RFC 1122 RFC 2581]
- Fast Retransmit
- Fast Retransmit
- Fast retransmit algorithm
- TCP Flow Control
- TCP Flow control how it works
- Sliding Window Flow Control Example
- Principles of Congestion Control
- Causescosts of congestion scenario 1
- Causescosts of congestion scenario 2
- Causescosts of congestion scenario 2
- Causescosts of congestion scenario 3
- Causescosts of congestion scenario 3
- Approaches towards congestion control
- TCP Congestion Control
- TCP congestion control bandwidth probing
- TCP Congestion Control details
- TCP Congestion Control more details
- TCP Slow Start Phase
- Slow Start Example
- TCP Congestion Avoidance Phase
- Congestion Avoidance
- Example Slow StartCongestion Avoidance
- Slow Start Congestion Avoidance
- Responses to Congestion
- Fast Recovery (differentiation btwn two loss events)
- TCP Congestion Control
- Popular ldquoflavorsrdquo of TCP
- Summary TCP Congestion Control
- TCP Congestion Control Summary
- TCP throughput
- TCP Futures TCP over ldquolong fat pipesrdquo
- TCP Fairness
- Why is TCP fair
- Fairness (more)
- TCP Connection Management
- TCP Connection Management (cont)
- TCP Connection Management (cont)
- TCP Connection Management (cont)
- Tuning TCPIP Parameters
- SomeTCP Parameters in Linux Kernel
- SomeTCP Parameters in Linux Kernel
-
Transport Layer 3-75
Causescosts of congestion scenario 3four sendersmultihop pathstimeoutretransmit
λin
Q what happens as and increase λ
in
finite shared output link buffers
Host Aλin original data
Host B
λout
λin original data plus retransmitted data
Transport Layer 3-76
Causescosts of congestion scenario 3
another ldquocostrdquo of congestionwhen packet dropped any ldquoupstream transmission capacity used for that packet was wasted
Host A
Host B
λou
t
Transport Layer 3-77
Approaches towards congestion control
End-end congestion controlno explicit feedback from networkcongestion inferred from end-system observed loss delayapproach taken by TCP
Network-assisted congestion controlrouters provide feedback to end systems
single bit indicating congestion (SNA DECbit TCPIP ECN ATM)explicit rate sender should send at
Two broad approaches towards congestion control
Transport Layer 3-78
TCP Congestion Control
end-end control (no network assistance)sender limits transmissionLastByteSent-LastByteAcked
le CongWin
CongWin is dynamic function of perceived network congestion
How does sender perceive congestionloss event = timeout or3 duplicate acksTCP sender reduces rate (CongWin) after loss event
two modes of operationSlow Start (SS)Congestion avoidance (CA) or Additive Increase Multiplicative Decrease (AIMD)
Transport Layer 3-79
TCP congestion control bandwidth probing
ldquoprobing for bandwidthrdquo increase transmission rate on receipt of ACK until eventually loss occurs then decrease transmission rate
continue to increase on ACK decrease on loss (since available bandwidth is changing depending on other connections in network)
ACKs being received so increase rate
X
X
XX
X loss so decrease rate
send
ing
rate
time
Q how fast to increasedecreasedetails to follow
TCPrsquosldquosawtoothrdquobehavior
Transport Layer 3-80
TCP Congestion Control details
sender limits rate by limiting number of unACKed bytes ldquoin pipelinerdquo
cwnd differs from rwnd (how why)sender limited by min(cwndrwnd)
roughly
cwnd is dynamic function of perceived network congestion
rate = cwndRTT bytessec
LastByteSent-LastByteAcked le cwnd
cwndbytes
RTT
ACK(s)
Transport Layer 3-81
TCP Congestion Control more details
segment loss event reducing cwndtimeout no response from receiver
cut cwnd to 13 duplicate ACKs at least some segments getting through (recall fast retransmit)
cut cwnd in half less aggressively than on timeout
ACK received increase cwndTwo modes of operation
slowstart phase bull increase exponentially
fast (despite name) at connection start or following timeout
congestion avoidance bull increase linearly
Transport Layer 3-82
TCP Slow Start Phasewhen connection begins cwnd = 1 MSS
example MSS = 500 bytes amp RTT = 200 msecinitial rate = 20 kbps
available bandwidth may be gtgt MSSRTT
desirable to quickly ramp up to respectable rate
increase rate exponentially until first loss event or when threshold reached
double cwnd every RTTdone by incrementing cwnd by 1 for every ACK received
Host A
one segment
RTT
Host B
time
two segments
four segments
Transport Layer 3-83
Slow Start ExampleThe congestion window size grows very rapidly
For every ACK we increase CongWin by 1 irrespective of the number of segments ACKrsquoeddouble CongWinevery RTTinitial rate is slow but ramps up exponentially fast
TCP slows down the increase of CongWinwhen CongWin gt ssthresh
segment 1
ACK for segment 1
cwnd = 1
cwnd = 2 segment 2segment 3
ACK for segments 2
cwnd = 4 segment 4segment 5segment 6
ACK for segments 4
cwnd = 7
ACK for segments 3
ACK for segments 5
ACK for segments 6
cwnd = 3
cwnd = 5
cwnd = 6ACK for segments 7
cwnd = 8
segment 7
Transport Layer 3-84
TCP Congestion Avoidance Phase
when cwnd gt ssthreshgrow cwnd linearly
increase cwnd by 1 MSS per RTT approach possible congestion slower than in slowstartimplementation cwnd= cwnd + MSScwndfor each ACK received
ACKs increase cwndby 1 MSS per RTT additive increaseloss cut cwnd in half (non-timeout-detected loss ) multiplicative decrease
AIMD
AIMD Additive IncreaseMultiplicative Decrease
Transport Layer 3-85
Congestion AvoidanceCongestion avoidance phase is started if CongWin has reached the slow-start threshold value
If CongWin gt= ssthresh then each time an ACK is received increment CongWin as follows
bull CongWin = CongWin + 1CongWin (CongWin in segments)
bull In actual TCP implementation CongWin is in BytesCongWin = CongWin + MSS (MSSCongWin)
So CongWin is increased by one only if all CongWinsegments have been acknowledged
Transport Layer 3-86
Example Slow StartCongestion AvoidanceAssume that
ssthresh = 8
cwnd = 1
cwnd = 2
cwnd = 4
cwnd = 8
cwnd = 9
cwnd = 10
02468
101214
t=0
t=2
t=4
t=6
Roundtrip times
Cw
nd(in
seg
men
ts)
ssthresh
cwnd = 3
cwnd = 5cwnd = 6cwnd = 7
Transport Layer 3-87
Slow Start Congestion AvoidanceA typical plot of CongWin for a TCP connection
(MSS = 1500 bytes) with TCP Tahoe
SS
CA
ssthresh
Transport Layer 3-88
Responses to CongestionTCP assumes there is congestion if it detects a packet lossA TCP sender can detect lost packets via loss events
bull Timeout of a retransmission timerbull Receipt of 3 duplicate ACKs (fast retransmit)
TCP interprets a Timeout as a binary congestion signal When a timeout occurs the sender performs
ssthresh is set to half the current size of the congestion window
ssthresh = CongWin 2CongWin is reset to one
CongWin = 1and slow-start is entered
Transport Layer 3-89
Fast Recovery (differentiation btwn two loss events) After 3 dup ACKs (fast Retransmit)
ssthresh = CongWin2CongWin = CongWin2window then grows linearly
But after timeout eventCongWin = 1 MSS window then grows exponentiallyto the threshold then grows linearly
bull 3 dup ACKs indicates network capable of delivering some segmentsbull timeout before 3 dup ACKs is ldquomore alarmingrdquo
Philosophy
3-90
TCP Congestion ControlInitially
CongWin = 1ssthresh = advertised window size
New Ack receivedif (CongWin lt ssthresh) Slow Start
CongWin = CongWin + 1else Congestion Avoidance
CongWin = CongWin + 1CongWinTimeout
ssthresh = CongWin2CongWin = 1
Fast Retransmissionssthresh = CongWin2CongWin = CongWin2
Slow Start (exponential increase phase) is continued until CongWin reaches half of the level where the loss event occurred last time CongWin is increased slowly after (linear increase in Congestion Avoidance phase)
Transport Layer 3-91
Popular ldquoflavorsrdquo of TCP
ssthresh
ssthresh
TCP Tahoe
TCP Reno
Transmission round
cwnd
win
dow
siz
e (in
seg
men
ts)
Transport Layer 3-92
Summary TCP Congestion ControlWhen CongWin is below Threshold sender in slow-start phase window grows exponentiallyWhen CongWin is above Threshold sender is in congestion-avoidance phase window grows linearlyWhen a triple duplicate ACK occurs Threshold set to CongWin2 and CongWin set to ThresholdWhen timeout occurs Threshold set to CongWin2 and CongWin is set to 1 MSS The actual sender window size is determined based on the congestion and flow control algorithms
SenderWin=min(RcvWinCongWin)
Transport Layer 3-93
TCP Congestion Control SummaryEvent State TCP Sender Action Commentary
ACK receipt for previously unackeddata
Slow Start (SS)
CongWin = CongWin + MSS If (CongWin gt Threshold)
set state to ldquoCongestion Avoidancerdquo
Resulting in a doubling of CongWin every RTT
ACK receipt for previously unackeddata
CongestionAvoidance (CA)
CongWin = CongWin+MSS (MSSCongWin)
Additive increase resulting in increase of CongWin by 1 MSS every RTT
Loss event detected by triple duplicate ACK
SS or CA Threshold = CongWin2 CongWin = ThresholdSet state to ldquoCongestion Avoidancerdquo
Fast recovery implementing multiplicative decrease CongWin will not drop below 1 MSS
Timeout SS or CA Threshold = CongWin2 CongWin = 1 MSSSet state to ldquoSlow Startrdquo
Enter slow start
Duplicate ACK
SS or CA Increment duplicate ACK count for segment being acked
CongWin and Threshold not changed
Transport Layer 3-94
TCP throughput
Q whatrsquos average throughout of TCP as function of window size RTT
ignoring slow startlet W be window size when loss occurs
when window is W throughput is WRTTjust after loss window drops to W2 throughput to W2RTT average throughout 75 WRTT
Transport Layer 3-95
TCP Futures TCP over ldquolong fat pipesrdquo
example 1500 byte segments 100ms RTT want 10 Gbps throughputrequires window size W = 83333 in-flight segmentsthroughput in terms of loss rate
L = 210-10 Wownew versions of TCP for high-speed
LRTTMSSsdot221
Transport Layer 3-96
Fairness goal if K TCP sessions share same bottleneck link of bandwidth R each should have average rate of RK
TCP connection 1
bottleneckrouter
capacity R
TCP connection 2
TCP Fairness
Transport Layer 3-97
Why is TCP fairTwo competing sessions
Additive increase gives slope of 1 as throughout increasesmultiplicative decrease decreases throughput proportionally
R
R
equal bandwidth share
Connection 1 throughput
Conn
ecti
on 2
thr
ough
p ut
congestion avoidance additive increaseloss decrease window by factor of 2
congestion avoidance additive increaseloss decrease window by factor of 2
Transport Layer 3-98
Fairness (more)Fairness and UDP
Multimedia apps often do not use TCP
do not want rate throttled by congestion control
Instead use UDPpump audiovideo at constant rate tolerate packet loss
Research area TCP friendly
Fairness and parallel TCP connectionsnothing prevents app from opening parallel cnctionsbetween 2 hostsWeb browsers do this Example link of rate R supporting 9 cnctions
new app asks for 1 TCP gets rate R10new app asks for 11 TCPs gets R2
Transport Layer 3-99
TCP Connection ManagementRecall TCP sender receiver
establish ldquoconnectionrdquobefore exchanging data segmentsinitialize TCP variables
seq sbuffers flow control info (eg RcvWindow)
client connection initiatorSocket clientSocket = new Socket(hostnameport
number)
server contacted by clientSocket connectionSocket = welcomeSocketaccept()
Three way handshakeStep 1 client host sends TCP
SYN segment to serverspecifies initial seq no data
Step 2 server host receives SYN replies with SYNACK segment
server allocates buffersspecifies server initial seq
Step 3 client receives SYNACK replies with ACK segment which may contain data
Transport Layer 3-100
TCP Connection Management (cont)
Closing a connection
client closes socketclientSocketclose()
Step 1 client end system sends TCP FIN control segment to server
Step 2 server receives FIN replies with ACK Closes connection sends FIN
client
FIN
server
ACK
ACK
FIN
close
close
closed
tim
ed w
ait
Transport Layer 3-101
TCP Connection Management (cont)
Step 3 client receives FIN replies with ACK
Enters ldquotimed waitrdquo -will respond with ACK to received FINs
Step 4 server receives ACK Connection closed
client
FIN
server
ACK
ACK
FIN
closing
closing
closed
tim
ed w
ait
closed
Transport Layer 3-102
TCP Connection Management (cont)
TCP clientlifecycle
TCP serverlifecycle
Transport Layer 3-103
Tuning TCPIP Parameters TCPIP parameters
A set of default values may not be optimal for all applicationsThe network administrator may wish to turn on or off some TCPIP functions for performance or security considerations
Many Unix and Linux systems provide some flexibility in tuning the TCPIP kernelsbinsysctl is used to configure the Linux kernel parameters at runtime
Default kernel configuration file is sbinsysctlconfFrequently used sysctl options
bull sysctl ndasha or sysctl ndashA list all current valuesbull sysctl ndashp file_name load the sysctl setting from a configuration
filebull sysctl ndashw variable=value change the value of the parameter
Transport Layer 3-104
SomeTCP Parameters in Linux Kerneltcp_syn_retries
Number of SYN packets the kernel will send before giving up on the new connection
tcp_synack_retriesnumber of SYN+ACK packets sent before the kernel gives up on the connection
tcp_window_scalingMaximum window size of 65535 bytes not enough for for really fast networks The window scaling options allows for almost gigabyte windows which is good for connections with large delay-bandwidth product
tcp_max_syn_backlogMaximal number of remembered connection requests which still did not receive an acknowledgment from connecting client
tcp_fin_timeoutHow many seconds to wait for a final FIN packet before the socket is closed required to prevent denial-of-service (DoS) attacks Default value is 60 seconds
Transport Layer 3-105
SomeTCP Parameters in Linux Kerneltcp_rmem
This is a vector of 3 integers [min default max] These parameters are used by TCP to dynamically adjust receive buffer sizesmin - minimum size of the receive buffer used by each TCP socket The default value is 4K default - the default size of the receive buffer for a TCP socket The default value is 87380 bytes and is lowered to 43689 in low memory systems If larger receive buffer sizes are desired this value should be increased max - the maximum size of the receive buffer used by each TCP socket The default value of 873802 bytes is lowered to 87380 in low memory systems
tcp_smemSend buffer parameters [min default max] similar to tcp_rmem
- Chapter 3 Transport Layer
- Transport services and protocols
- Transport vs network layer
- Internet transport-layer protocols
- Multiplexingdemultiplexing
- How demultiplexing works
- Connectionless demultiplexing
- Connection-oriented demux
- Connection-oriented demux (cont)
- Connection-oriented demux Threaded Web Server
- UDP User Datagram Protocol [RFC 768]
- UDP more
- UDP checksum
- Principles of Reliable data transfer
- Reliable data transfer getting started
- Reliable data transfer getting started
- Rdt10 reliable transfer over a reliable channel
- Rdt20 channel with bit errors
- rdt20 FSM specification
- rdt20 operation with no errors
- rdt20 error scenario
- rdt20 has a fatal flaw
- rdt21 sender handles garbled ACKNAKs
- rdt21 receiver handles garbled ACKNAKs
- rdt21 discussion
- rdt22 a NAK-free protocol
- rdt22 sender receiver fragments
- rdt30 channels with errors and loss
- rdt30 sender
- rdt30 in action
- rdt30 in action
- Performance of rdt30
- rdt30 stop-and-wait operation
- Pipelined protocols
- Pipelining increased utilization
- Go-Back-N
- GBN sender extended FSM
- GBN receiver extended FSM
- GBN inaction
- Selective Repeat
- Selective repeat sender receiver windows
- Selective repeat
- Selective repeat in action
- Selective repeat dilemma
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- TCP Overview RFCs 793 1122 1323 2018 2581
- TCP segment structure
- TCP seq rsquos and ACKs
- TCP Round Trip Time and Timeout
- TCP Round Trip Time and Timeout
- Example RTT estimation
- TCP Round Trip Time and Timeout
- TCP reliable data transfer
- TCP sender events
- TCP sender(simplified)
- TCP retransmission scenarios
- TCP retransmission scenarios (more)
- TCP ACK generation [RFC 1122 RFC 2581]
- Fast Retransmit
- Fast Retransmit
- Fast retransmit algorithm
- TCP Flow Control
- TCP Flow control how it works
- Sliding Window Flow Control Example
- Principles of Congestion Control
- Causescosts of congestion scenario 1
- Causescosts of congestion scenario 2
- Causescosts of congestion scenario 2
- Causescosts of congestion scenario 3
- Causescosts of congestion scenario 3
- Approaches towards congestion control
- TCP Congestion Control
- TCP congestion control bandwidth probing
- TCP Congestion Control details
- TCP Congestion Control more details
- TCP Slow Start Phase
- Slow Start Example
- TCP Congestion Avoidance Phase
- Congestion Avoidance
- Example Slow StartCongestion Avoidance
- Slow Start Congestion Avoidance
- Responses to Congestion
- Fast Recovery (differentiation btwn two loss events)
- TCP Congestion Control
- Popular ldquoflavorsrdquo of TCP
- Summary TCP Congestion Control
- TCP Congestion Control Summary
- TCP throughput
- TCP Futures TCP over ldquolong fat pipesrdquo
- TCP Fairness
- Why is TCP fair
- Fairness (more)
- TCP Connection Management
- TCP Connection Management (cont)
- TCP Connection Management (cont)
- TCP Connection Management (cont)
- Tuning TCPIP Parameters
- SomeTCP Parameters in Linux Kernel
- SomeTCP Parameters in Linux Kernel
-
Transport Layer 3-76
Causescosts of congestion scenario 3
another ldquocostrdquo of congestionwhen packet dropped any ldquoupstream transmission capacity used for that packet was wasted
Host A
Host B
λou
t
Transport Layer 3-77
Approaches towards congestion control
End-end congestion controlno explicit feedback from networkcongestion inferred from end-system observed loss delayapproach taken by TCP
Network-assisted congestion controlrouters provide feedback to end systems
single bit indicating congestion (SNA DECbit TCPIP ECN ATM)explicit rate sender should send at
Two broad approaches towards congestion control
Transport Layer 3-78
TCP Congestion Control
end-end control (no network assistance)sender limits transmissionLastByteSent-LastByteAcked
le CongWin
CongWin is dynamic function of perceived network congestion
How does sender perceive congestionloss event = timeout or3 duplicate acksTCP sender reduces rate (CongWin) after loss event
two modes of operationSlow Start (SS)Congestion avoidance (CA) or Additive Increase Multiplicative Decrease (AIMD)
Transport Layer 3-79
TCP congestion control bandwidth probing
ldquoprobing for bandwidthrdquo increase transmission rate on receipt of ACK until eventually loss occurs then decrease transmission rate
continue to increase on ACK decrease on loss (since available bandwidth is changing depending on other connections in network)
ACKs being received so increase rate
X
X
XX
X loss so decrease rate
send
ing
rate
time
Q how fast to increasedecreasedetails to follow
TCPrsquosldquosawtoothrdquobehavior
Transport Layer 3-80
TCP Congestion Control details
sender limits rate by limiting number of unACKed bytes ldquoin pipelinerdquo
cwnd differs from rwnd (how why)sender limited by min(cwndrwnd)
roughly
cwnd is dynamic function of perceived network congestion
rate = cwndRTT bytessec
LastByteSent-LastByteAcked le cwnd
cwndbytes
RTT
ACK(s)
Transport Layer 3-81
TCP Congestion Control more details
segment loss event reducing cwndtimeout no response from receiver
cut cwnd to 13 duplicate ACKs at least some segments getting through (recall fast retransmit)
cut cwnd in half less aggressively than on timeout
ACK received increase cwndTwo modes of operation
slowstart phase bull increase exponentially
fast (despite name) at connection start or following timeout
congestion avoidance bull increase linearly
Transport Layer 3-82
TCP Slow Start Phasewhen connection begins cwnd = 1 MSS
example MSS = 500 bytes amp RTT = 200 msecinitial rate = 20 kbps
available bandwidth may be gtgt MSSRTT
desirable to quickly ramp up to respectable rate
increase rate exponentially until first loss event or when threshold reached
double cwnd every RTTdone by incrementing cwnd by 1 for every ACK received
Host A
one segment
RTT
Host B
time
two segments
four segments
Transport Layer 3-83
Slow Start ExampleThe congestion window size grows very rapidly
For every ACK we increase CongWin by 1 irrespective of the number of segments ACKrsquoeddouble CongWinevery RTTinitial rate is slow but ramps up exponentially fast
TCP slows down the increase of CongWinwhen CongWin gt ssthresh
segment 1
ACK for segment 1
cwnd = 1
cwnd = 2 segment 2segment 3
ACK for segments 2
cwnd = 4 segment 4segment 5segment 6
ACK for segments 4
cwnd = 7
ACK for segments 3
ACK for segments 5
ACK for segments 6
cwnd = 3
cwnd = 5
cwnd = 6ACK for segments 7
cwnd = 8
segment 7
Transport Layer 3-84
TCP Congestion Avoidance Phase
when cwnd gt ssthreshgrow cwnd linearly
increase cwnd by 1 MSS per RTT approach possible congestion slower than in slowstartimplementation cwnd= cwnd + MSScwndfor each ACK received
ACKs increase cwndby 1 MSS per RTT additive increaseloss cut cwnd in half (non-timeout-detected loss ) multiplicative decrease
AIMD
AIMD Additive IncreaseMultiplicative Decrease
Transport Layer 3-85
Congestion AvoidanceCongestion avoidance phase is started if CongWin has reached the slow-start threshold value
If CongWin gt= ssthresh then each time an ACK is received increment CongWin as follows
bull CongWin = CongWin + 1CongWin (CongWin in segments)
bull In actual TCP implementation CongWin is in BytesCongWin = CongWin + MSS (MSSCongWin)
So CongWin is increased by one only if all CongWinsegments have been acknowledged
Transport Layer 3-86
Example Slow StartCongestion AvoidanceAssume that
ssthresh = 8
cwnd = 1
cwnd = 2
cwnd = 4
cwnd = 8
cwnd = 9
cwnd = 10
02468
101214
t=0
t=2
t=4
t=6
Roundtrip times
Cw
nd(in
seg
men
ts)
ssthresh
cwnd = 3
cwnd = 5cwnd = 6cwnd = 7
Transport Layer 3-87
Slow Start Congestion AvoidanceA typical plot of CongWin for a TCP connection
(MSS = 1500 bytes) with TCP Tahoe
SS
CA
ssthresh
Transport Layer 3-88
Responses to CongestionTCP assumes there is congestion if it detects a packet lossA TCP sender can detect lost packets via loss events
bull Timeout of a retransmission timerbull Receipt of 3 duplicate ACKs (fast retransmit)
TCP interprets a Timeout as a binary congestion signal When a timeout occurs the sender performs
ssthresh is set to half the current size of the congestion window
ssthresh = CongWin 2CongWin is reset to one
CongWin = 1and slow-start is entered
Transport Layer 3-89
Fast Recovery (differentiation btwn two loss events) After 3 dup ACKs (fast Retransmit)
ssthresh = CongWin2CongWin = CongWin2window then grows linearly
But after timeout eventCongWin = 1 MSS window then grows exponentiallyto the threshold then grows linearly
bull 3 dup ACKs indicates network capable of delivering some segmentsbull timeout before 3 dup ACKs is ldquomore alarmingrdquo
Philosophy
3-90
TCP Congestion ControlInitially
CongWin = 1ssthresh = advertised window size
New Ack receivedif (CongWin lt ssthresh) Slow Start
CongWin = CongWin + 1else Congestion Avoidance
CongWin = CongWin + 1CongWinTimeout
ssthresh = CongWin2CongWin = 1
Fast Retransmissionssthresh = CongWin2CongWin = CongWin2
Slow Start (exponential increase phase) is continued until CongWin reaches half of the level where the loss event occurred last time CongWin is increased slowly after (linear increase in Congestion Avoidance phase)
Transport Layer 3-91
Popular ldquoflavorsrdquo of TCP
ssthresh
ssthresh
TCP Tahoe
TCP Reno
Transmission round
cwnd
win
dow
siz
e (in
seg
men
ts)
Transport Layer 3-92
Summary TCP Congestion ControlWhen CongWin is below Threshold sender in slow-start phase window grows exponentiallyWhen CongWin is above Threshold sender is in congestion-avoidance phase window grows linearlyWhen a triple duplicate ACK occurs Threshold set to CongWin2 and CongWin set to ThresholdWhen timeout occurs Threshold set to CongWin2 and CongWin is set to 1 MSS The actual sender window size is determined based on the congestion and flow control algorithms
SenderWin=min(RcvWinCongWin)
Transport Layer 3-93
TCP Congestion Control SummaryEvent State TCP Sender Action Commentary
ACK receipt for previously unackeddata
Slow Start (SS)
CongWin = CongWin + MSS If (CongWin gt Threshold)
set state to ldquoCongestion Avoidancerdquo
Resulting in a doubling of CongWin every RTT
ACK receipt for previously unackeddata
CongestionAvoidance (CA)
CongWin = CongWin+MSS (MSSCongWin)
Additive increase resulting in increase of CongWin by 1 MSS every RTT
Loss event detected by triple duplicate ACK
SS or CA Threshold = CongWin2 CongWin = ThresholdSet state to ldquoCongestion Avoidancerdquo
Fast recovery implementing multiplicative decrease CongWin will not drop below 1 MSS
Timeout SS or CA Threshold = CongWin2 CongWin = 1 MSSSet state to ldquoSlow Startrdquo
Enter slow start
Duplicate ACK
SS or CA Increment duplicate ACK count for segment being acked
CongWin and Threshold not changed
Transport Layer 3-94
TCP throughput
Q whatrsquos average throughout of TCP as function of window size RTT
ignoring slow startlet W be window size when loss occurs
when window is W throughput is WRTTjust after loss window drops to W2 throughput to W2RTT average throughout 75 WRTT
Transport Layer 3-95
TCP Futures TCP over ldquolong fat pipesrdquo
example 1500 byte segments 100ms RTT want 10 Gbps throughputrequires window size W = 83333 in-flight segmentsthroughput in terms of loss rate
L = 210-10 Wownew versions of TCP for high-speed
LRTTMSSsdot221
Transport Layer 3-96
Fairness goal if K TCP sessions share same bottleneck link of bandwidth R each should have average rate of RK
TCP connection 1
bottleneckrouter
capacity R
TCP connection 2
TCP Fairness
Transport Layer 3-97
Why is TCP fairTwo competing sessions
Additive increase gives slope of 1 as throughout increasesmultiplicative decrease decreases throughput proportionally
R
R
equal bandwidth share
Connection 1 throughput
Conn
ecti
on 2
thr
ough
p ut
congestion avoidance additive increaseloss decrease window by factor of 2
congestion avoidance additive increaseloss decrease window by factor of 2
Transport Layer 3-98
Fairness (more)Fairness and UDP
Multimedia apps often do not use TCP
do not want rate throttled by congestion control
Instead use UDPpump audiovideo at constant rate tolerate packet loss
Research area TCP friendly
Fairness and parallel TCP connectionsnothing prevents app from opening parallel cnctionsbetween 2 hostsWeb browsers do this Example link of rate R supporting 9 cnctions
new app asks for 1 TCP gets rate R10new app asks for 11 TCPs gets R2
Transport Layer 3-99
TCP Connection ManagementRecall TCP sender receiver
establish ldquoconnectionrdquobefore exchanging data segmentsinitialize TCP variables
seq sbuffers flow control info (eg RcvWindow)
client connection initiatorSocket clientSocket = new Socket(hostnameport
number)
server contacted by clientSocket connectionSocket = welcomeSocketaccept()
Three way handshakeStep 1 client host sends TCP
SYN segment to serverspecifies initial seq no data
Step 2 server host receives SYN replies with SYNACK segment
server allocates buffersspecifies server initial seq
Step 3 client receives SYNACK replies with ACK segment which may contain data
Transport Layer 3-100
TCP Connection Management (cont)
Closing a connection
client closes socketclientSocketclose()
Step 1 client end system sends TCP FIN control segment to server
Step 2 server receives FIN replies with ACK Closes connection sends FIN
client
FIN
server
ACK
ACK
FIN
close
close
closed
tim
ed w
ait
Transport Layer 3-101
TCP Connection Management (cont)
Step 3 client receives FIN replies with ACK
Enters ldquotimed waitrdquo -will respond with ACK to received FINs
Step 4 server receives ACK Connection closed
client
FIN
server
ACK
ACK
FIN
closing
closing
closed
tim
ed w
ait
closed
Transport Layer 3-102
TCP Connection Management (cont)
TCP clientlifecycle
TCP serverlifecycle
Transport Layer 3-103
Tuning TCPIP Parameters TCPIP parameters
A set of default values may not be optimal for all applicationsThe network administrator may wish to turn on or off some TCPIP functions for performance or security considerations
Many Unix and Linux systems provide some flexibility in tuning the TCPIP kernelsbinsysctl is used to configure the Linux kernel parameters at runtime
Default kernel configuration file is sbinsysctlconfFrequently used sysctl options
bull sysctl ndasha or sysctl ndashA list all current valuesbull sysctl ndashp file_name load the sysctl setting from a configuration
filebull sysctl ndashw variable=value change the value of the parameter
Transport Layer 3-104
SomeTCP Parameters in Linux Kerneltcp_syn_retries
Number of SYN packets the kernel will send before giving up on the new connection
tcp_synack_retriesnumber of SYN+ACK packets sent before the kernel gives up on the connection
tcp_window_scalingMaximum window size of 65535 bytes not enough for for really fast networks The window scaling options allows for almost gigabyte windows which is good for connections with large delay-bandwidth product
tcp_max_syn_backlogMaximal number of remembered connection requests which still did not receive an acknowledgment from connecting client
tcp_fin_timeoutHow many seconds to wait for a final FIN packet before the socket is closed required to prevent denial-of-service (DoS) attacks Default value is 60 seconds
Transport Layer 3-105
SomeTCP Parameters in Linux Kerneltcp_rmem
This is a vector of 3 integers [min default max] These parameters are used by TCP to dynamically adjust receive buffer sizesmin - minimum size of the receive buffer used by each TCP socket The default value is 4K default - the default size of the receive buffer for a TCP socket The default value is 87380 bytes and is lowered to 43689 in low memory systems If larger receive buffer sizes are desired this value should be increased max - the maximum size of the receive buffer used by each TCP socket The default value of 873802 bytes is lowered to 87380 in low memory systems
tcp_smemSend buffer parameters [min default max] similar to tcp_rmem
- Chapter 3 Transport Layer
- Transport services and protocols
- Transport vs network layer
- Internet transport-layer protocols
- Multiplexingdemultiplexing
- How demultiplexing works
- Connectionless demultiplexing
- Connection-oriented demux
- Connection-oriented demux (cont)
- Connection-oriented demux Threaded Web Server
- UDP User Datagram Protocol [RFC 768]
- UDP more
- UDP checksum
- Principles of Reliable data transfer
- Reliable data transfer getting started
- Reliable data transfer getting started
- Rdt10 reliable transfer over a reliable channel
- Rdt20 channel with bit errors
- rdt20 FSM specification
- rdt20 operation with no errors
- rdt20 error scenario
- rdt20 has a fatal flaw
- rdt21 sender handles garbled ACKNAKs
- rdt21 receiver handles garbled ACKNAKs
- rdt21 discussion
- rdt22 a NAK-free protocol
- rdt22 sender receiver fragments
- rdt30 channels with errors and loss
- rdt30 sender
- rdt30 in action
- rdt30 in action
- Performance of rdt30
- rdt30 stop-and-wait operation
- Pipelined protocols
- Pipelining increased utilization
- Go-Back-N
- GBN sender extended FSM
- GBN receiver extended FSM
- GBN inaction
- Selective Repeat
- Selective repeat sender receiver windows
- Selective repeat
- Selective repeat in action
- Selective repeat dilemma
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- TCP Overview RFCs 793 1122 1323 2018 2581
- TCP segment structure
- TCP seq rsquos and ACKs
- TCP Round Trip Time and Timeout
- TCP Round Trip Time and Timeout
- Example RTT estimation
- TCP Round Trip Time and Timeout
- TCP reliable data transfer
- TCP sender events
- TCP sender(simplified)
- TCP retransmission scenarios
- TCP retransmission scenarios (more)
- TCP ACK generation [RFC 1122 RFC 2581]
- Fast Retransmit
- Fast Retransmit
- Fast retransmit algorithm
- TCP Flow Control
- TCP Flow control how it works
- Sliding Window Flow Control Example
- Principles of Congestion Control
- Causescosts of congestion scenario 1
- Causescosts of congestion scenario 2
- Causescosts of congestion scenario 2
- Causescosts of congestion scenario 3
- Causescosts of congestion scenario 3
- Approaches towards congestion control
- TCP Congestion Control
- TCP congestion control bandwidth probing
- TCP Congestion Control details
- TCP Congestion Control more details
- TCP Slow Start Phase
- Slow Start Example
- TCP Congestion Avoidance Phase
- Congestion Avoidance
- Example Slow StartCongestion Avoidance
- Slow Start Congestion Avoidance
- Responses to Congestion
- Fast Recovery (differentiation btwn two loss events)
- TCP Congestion Control
- Popular ldquoflavorsrdquo of TCP
- Summary TCP Congestion Control
- TCP Congestion Control Summary
- TCP throughput
- TCP Futures TCP over ldquolong fat pipesrdquo
- TCP Fairness
- Why is TCP fair
- Fairness (more)
- TCP Connection Management
- TCP Connection Management (cont)
- TCP Connection Management (cont)
- TCP Connection Management (cont)
- Tuning TCPIP Parameters
- SomeTCP Parameters in Linux Kernel
- SomeTCP Parameters in Linux Kernel
-
Transport Layer 3-77
Approaches towards congestion control
End-end congestion controlno explicit feedback from networkcongestion inferred from end-system observed loss delayapproach taken by TCP
Network-assisted congestion controlrouters provide feedback to end systems
single bit indicating congestion (SNA DECbit TCPIP ECN ATM)explicit rate sender should send at
Two broad approaches towards congestion control
Transport Layer 3-78
TCP Congestion Control
end-end control (no network assistance)sender limits transmissionLastByteSent-LastByteAcked
le CongWin
CongWin is dynamic function of perceived network congestion
How does sender perceive congestionloss event = timeout or3 duplicate acksTCP sender reduces rate (CongWin) after loss event
two modes of operationSlow Start (SS)Congestion avoidance (CA) or Additive Increase Multiplicative Decrease (AIMD)
Transport Layer 3-79
TCP congestion control bandwidth probing
ldquoprobing for bandwidthrdquo increase transmission rate on receipt of ACK until eventually loss occurs then decrease transmission rate
continue to increase on ACK decrease on loss (since available bandwidth is changing depending on other connections in network)
ACKs being received so increase rate
X
X
XX
X loss so decrease rate
send
ing
rate
time
Q how fast to increasedecreasedetails to follow
TCPrsquosldquosawtoothrdquobehavior
Transport Layer 3-80
TCP Congestion Control details
sender limits rate by limiting number of unACKed bytes ldquoin pipelinerdquo
cwnd differs from rwnd (how why)sender limited by min(cwndrwnd)
roughly
cwnd is dynamic function of perceived network congestion
rate = cwndRTT bytessec
LastByteSent-LastByteAcked le cwnd
cwndbytes
RTT
ACK(s)
Transport Layer 3-81
TCP Congestion Control more details
segment loss event reducing cwndtimeout no response from receiver
cut cwnd to 13 duplicate ACKs at least some segments getting through (recall fast retransmit)
cut cwnd in half less aggressively than on timeout
ACK received increase cwndTwo modes of operation
slowstart phase bull increase exponentially
fast (despite name) at connection start or following timeout
congestion avoidance bull increase linearly
Transport Layer 3-82
TCP Slow Start Phasewhen connection begins cwnd = 1 MSS
example MSS = 500 bytes amp RTT = 200 msecinitial rate = 20 kbps
available bandwidth may be gtgt MSSRTT
desirable to quickly ramp up to respectable rate
increase rate exponentially until first loss event or when threshold reached
double cwnd every RTTdone by incrementing cwnd by 1 for every ACK received
Host A
one segment
RTT
Host B
time
two segments
four segments
Transport Layer 3-83
Slow Start ExampleThe congestion window size grows very rapidly
For every ACK we increase CongWin by 1 irrespective of the number of segments ACKrsquoeddouble CongWinevery RTTinitial rate is slow but ramps up exponentially fast
TCP slows down the increase of CongWinwhen CongWin gt ssthresh
segment 1
ACK for segment 1
cwnd = 1
cwnd = 2 segment 2segment 3
ACK for segments 2
cwnd = 4 segment 4segment 5segment 6
ACK for segments 4
cwnd = 7
ACK for segments 3
ACK for segments 5
ACK for segments 6
cwnd = 3
cwnd = 5
cwnd = 6ACK for segments 7
cwnd = 8
segment 7
Transport Layer 3-84
TCP Congestion Avoidance Phase
when cwnd gt ssthreshgrow cwnd linearly
increase cwnd by 1 MSS per RTT approach possible congestion slower than in slowstartimplementation cwnd= cwnd + MSScwndfor each ACK received
ACKs increase cwndby 1 MSS per RTT additive increaseloss cut cwnd in half (non-timeout-detected loss ) multiplicative decrease
AIMD
AIMD Additive IncreaseMultiplicative Decrease
Transport Layer 3-85
Congestion AvoidanceCongestion avoidance phase is started if CongWin has reached the slow-start threshold value
If CongWin gt= ssthresh then each time an ACK is received increment CongWin as follows
bull CongWin = CongWin + 1CongWin (CongWin in segments)
bull In actual TCP implementation CongWin is in BytesCongWin = CongWin + MSS (MSSCongWin)
So CongWin is increased by one only if all CongWinsegments have been acknowledged
Transport Layer 3-86
Example Slow StartCongestion AvoidanceAssume that
ssthresh = 8
cwnd = 1
cwnd = 2
cwnd = 4
cwnd = 8
cwnd = 9
cwnd = 10
02468
101214
t=0
t=2
t=4
t=6
Roundtrip times
Cw
nd(in
seg
men
ts)
ssthresh
cwnd = 3
cwnd = 5cwnd = 6cwnd = 7
Transport Layer 3-87
Slow Start Congestion AvoidanceA typical plot of CongWin for a TCP connection
(MSS = 1500 bytes) with TCP Tahoe
SS
CA
ssthresh
Transport Layer 3-88
Responses to CongestionTCP assumes there is congestion if it detects a packet lossA TCP sender can detect lost packets via loss events
bull Timeout of a retransmission timerbull Receipt of 3 duplicate ACKs (fast retransmit)
TCP interprets a Timeout as a binary congestion signal When a timeout occurs the sender performs
ssthresh is set to half the current size of the congestion window
ssthresh = CongWin 2CongWin is reset to one
CongWin = 1and slow-start is entered
Transport Layer 3-89
Fast Recovery (differentiation btwn two loss events) After 3 dup ACKs (fast Retransmit)
ssthresh = CongWin2CongWin = CongWin2window then grows linearly
But after timeout eventCongWin = 1 MSS window then grows exponentiallyto the threshold then grows linearly
bull 3 dup ACKs indicates network capable of delivering some segmentsbull timeout before 3 dup ACKs is ldquomore alarmingrdquo
Philosophy
3-90
TCP Congestion ControlInitially
CongWin = 1ssthresh = advertised window size
New Ack receivedif (CongWin lt ssthresh) Slow Start
CongWin = CongWin + 1else Congestion Avoidance
CongWin = CongWin + 1CongWinTimeout
ssthresh = CongWin2CongWin = 1
Fast Retransmissionssthresh = CongWin2CongWin = CongWin2
Slow Start (exponential increase phase) is continued until CongWin reaches half of the level where the loss event occurred last time CongWin is increased slowly after (linear increase in Congestion Avoidance phase)
Transport Layer 3-91
Popular ldquoflavorsrdquo of TCP
ssthresh
ssthresh
TCP Tahoe
TCP Reno
Transmission round
cwnd
win
dow
siz
e (in
seg
men
ts)
Transport Layer 3-92
Summary TCP Congestion ControlWhen CongWin is below Threshold sender in slow-start phase window grows exponentiallyWhen CongWin is above Threshold sender is in congestion-avoidance phase window grows linearlyWhen a triple duplicate ACK occurs Threshold set to CongWin2 and CongWin set to ThresholdWhen timeout occurs Threshold set to CongWin2 and CongWin is set to 1 MSS The actual sender window size is determined based on the congestion and flow control algorithms
SenderWin=min(RcvWinCongWin)
Transport Layer 3-93
TCP Congestion Control SummaryEvent State TCP Sender Action Commentary
ACK receipt for previously unackeddata
Slow Start (SS)
CongWin = CongWin + MSS If (CongWin gt Threshold)
set state to ldquoCongestion Avoidancerdquo
Resulting in a doubling of CongWin every RTT
ACK receipt for previously unackeddata
CongestionAvoidance (CA)
CongWin = CongWin+MSS (MSSCongWin)
Additive increase resulting in increase of CongWin by 1 MSS every RTT
Loss event detected by triple duplicate ACK
SS or CA Threshold = CongWin2 CongWin = ThresholdSet state to ldquoCongestion Avoidancerdquo
Fast recovery implementing multiplicative decrease CongWin will not drop below 1 MSS
Timeout SS or CA Threshold = CongWin2 CongWin = 1 MSSSet state to ldquoSlow Startrdquo
Enter slow start
Duplicate ACK
SS or CA Increment duplicate ACK count for segment being acked
CongWin and Threshold not changed
Transport Layer 3-94
TCP throughput
Q whatrsquos average throughout of TCP as function of window size RTT
ignoring slow startlet W be window size when loss occurs
when window is W throughput is WRTTjust after loss window drops to W2 throughput to W2RTT average throughout 75 WRTT
Transport Layer 3-95
TCP Futures TCP over ldquolong fat pipesrdquo
example 1500 byte segments 100ms RTT want 10 Gbps throughputrequires window size W = 83333 in-flight segmentsthroughput in terms of loss rate
L = 210-10 Wownew versions of TCP for high-speed
LRTTMSSsdot221
Transport Layer 3-96
Fairness goal if K TCP sessions share same bottleneck link of bandwidth R each should have average rate of RK
TCP connection 1
bottleneckrouter
capacity R
TCP connection 2
TCP Fairness
Transport Layer 3-97
Why is TCP fairTwo competing sessions
Additive increase gives slope of 1 as throughout increasesmultiplicative decrease decreases throughput proportionally
R
R
equal bandwidth share
Connection 1 throughput
Conn
ecti
on 2
thr
ough
p ut
congestion avoidance additive increaseloss decrease window by factor of 2
congestion avoidance additive increaseloss decrease window by factor of 2
Transport Layer 3-98
Fairness (more)Fairness and UDP
Multimedia apps often do not use TCP
do not want rate throttled by congestion control
Instead use UDPpump audiovideo at constant rate tolerate packet loss
Research area TCP friendly
Fairness and parallel TCP connectionsnothing prevents app from opening parallel cnctionsbetween 2 hostsWeb browsers do this Example link of rate R supporting 9 cnctions
new app asks for 1 TCP gets rate R10new app asks for 11 TCPs gets R2
Transport Layer 3-99
TCP Connection ManagementRecall TCP sender receiver
establish ldquoconnectionrdquobefore exchanging data segmentsinitialize TCP variables
seq sbuffers flow control info (eg RcvWindow)
client connection initiatorSocket clientSocket = new Socket(hostnameport
number)
server contacted by clientSocket connectionSocket = welcomeSocketaccept()
Three way handshakeStep 1 client host sends TCP
SYN segment to serverspecifies initial seq no data
Step 2 server host receives SYN replies with SYNACK segment
server allocates buffersspecifies server initial seq
Step 3 client receives SYNACK replies with ACK segment which may contain data
Transport Layer 3-100
TCP Connection Management (cont)
Closing a connection
client closes socketclientSocketclose()
Step 1 client end system sends TCP FIN control segment to server
Step 2 server receives FIN replies with ACK Closes connection sends FIN
client
FIN
server
ACK
ACK
FIN
close
close
closed
tim
ed w
ait
Transport Layer 3-101
TCP Connection Management (cont)
Step 3 client receives FIN replies with ACK
Enters ldquotimed waitrdquo -will respond with ACK to received FINs
Step 4 server receives ACK Connection closed
client
FIN
server
ACK
ACK
FIN
closing
closing
closed
tim
ed w
ait
closed
Transport Layer 3-102
TCP Connection Management (cont)
TCP clientlifecycle
TCP serverlifecycle
Transport Layer 3-103
Tuning TCPIP Parameters TCPIP parameters
A set of default values may not be optimal for all applicationsThe network administrator may wish to turn on or off some TCPIP functions for performance or security considerations
Many Unix and Linux systems provide some flexibility in tuning the TCPIP kernelsbinsysctl is used to configure the Linux kernel parameters at runtime
Default kernel configuration file is sbinsysctlconfFrequently used sysctl options
bull sysctl ndasha or sysctl ndashA list all current valuesbull sysctl ndashp file_name load the sysctl setting from a configuration
filebull sysctl ndashw variable=value change the value of the parameter
Transport Layer 3-104
SomeTCP Parameters in Linux Kerneltcp_syn_retries
Number of SYN packets the kernel will send before giving up on the new connection
tcp_synack_retriesnumber of SYN+ACK packets sent before the kernel gives up on the connection
tcp_window_scalingMaximum window size of 65535 bytes not enough for for really fast networks The window scaling options allows for almost gigabyte windows which is good for connections with large delay-bandwidth product
tcp_max_syn_backlogMaximal number of remembered connection requests which still did not receive an acknowledgment from connecting client
tcp_fin_timeoutHow many seconds to wait for a final FIN packet before the socket is closed required to prevent denial-of-service (DoS) attacks Default value is 60 seconds
Transport Layer 3-105
SomeTCP Parameters in Linux Kerneltcp_rmem
This is a vector of 3 integers [min default max] These parameters are used by TCP to dynamically adjust receive buffer sizesmin - minimum size of the receive buffer used by each TCP socket The default value is 4K default - the default size of the receive buffer for a TCP socket The default value is 87380 bytes and is lowered to 43689 in low memory systems If larger receive buffer sizes are desired this value should be increased max - the maximum size of the receive buffer used by each TCP socket The default value of 873802 bytes is lowered to 87380 in low memory systems
tcp_smemSend buffer parameters [min default max] similar to tcp_rmem
- Chapter 3 Transport Layer
- Transport services and protocols
- Transport vs network layer
- Internet transport-layer protocols
- Multiplexingdemultiplexing
- How demultiplexing works
- Connectionless demultiplexing
- Connection-oriented demux
- Connection-oriented demux (cont)
- Connection-oriented demux Threaded Web Server
- UDP User Datagram Protocol [RFC 768]
- UDP more
- UDP checksum
- Principles of Reliable data transfer
- Reliable data transfer getting started
- Reliable data transfer getting started
- Rdt10 reliable transfer over a reliable channel
- Rdt20 channel with bit errors
- rdt20 FSM specification
- rdt20 operation with no errors
- rdt20 error scenario
- rdt20 has a fatal flaw
- rdt21 sender handles garbled ACKNAKs
- rdt21 receiver handles garbled ACKNAKs
- rdt21 discussion
- rdt22 a NAK-free protocol
- rdt22 sender receiver fragments
- rdt30 channels with errors and loss
- rdt30 sender
- rdt30 in action
- rdt30 in action
- Performance of rdt30
- rdt30 stop-and-wait operation
- Pipelined protocols
- Pipelining increased utilization
- Go-Back-N
- GBN sender extended FSM
- GBN receiver extended FSM
- GBN inaction
- Selective Repeat
- Selective repeat sender receiver windows
- Selective repeat
- Selective repeat in action
- Selective repeat dilemma
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- TCP Overview RFCs 793 1122 1323 2018 2581
- TCP segment structure
- TCP seq rsquos and ACKs
- TCP Round Trip Time and Timeout
- TCP Round Trip Time and Timeout
- Example RTT estimation
- TCP Round Trip Time and Timeout
- TCP reliable data transfer
- TCP sender events
- TCP sender(simplified)
- TCP retransmission scenarios
- TCP retransmission scenarios (more)
- TCP ACK generation [RFC 1122 RFC 2581]
- Fast Retransmit
- Fast Retransmit
- Fast retransmit algorithm
- TCP Flow Control
- TCP Flow control how it works
- Sliding Window Flow Control Example
- Principles of Congestion Control
- Causescosts of congestion scenario 1
- Causescosts of congestion scenario 2
- Causescosts of congestion scenario 2
- Causescosts of congestion scenario 3
- Causescosts of congestion scenario 3
- Approaches towards congestion control
- TCP Congestion Control
- TCP congestion control bandwidth probing
- TCP Congestion Control details
- TCP Congestion Control more details
- TCP Slow Start Phase
- Slow Start Example
- TCP Congestion Avoidance Phase
- Congestion Avoidance
- Example Slow StartCongestion Avoidance
- Slow Start Congestion Avoidance
- Responses to Congestion
- Fast Recovery (differentiation btwn two loss events)
- TCP Congestion Control
- Popular ldquoflavorsrdquo of TCP
- Summary TCP Congestion Control
- TCP Congestion Control Summary
- TCP throughput
- TCP Futures TCP over ldquolong fat pipesrdquo
- TCP Fairness
- Why is TCP fair
- Fairness (more)
- TCP Connection Management
- TCP Connection Management (cont)
- TCP Connection Management (cont)
- TCP Connection Management (cont)
- Tuning TCPIP Parameters
- SomeTCP Parameters in Linux Kernel
- SomeTCP Parameters in Linux Kernel
-
Transport Layer 3-78
TCP Congestion Control
end-end control (no network assistance)sender limits transmissionLastByteSent-LastByteAcked
le CongWin
CongWin is dynamic function of perceived network congestion
How does sender perceive congestionloss event = timeout or3 duplicate acksTCP sender reduces rate (CongWin) after loss event
two modes of operationSlow Start (SS)Congestion avoidance (CA) or Additive Increase Multiplicative Decrease (AIMD)
Transport Layer 3-79
TCP congestion control bandwidth probing
ldquoprobing for bandwidthrdquo increase transmission rate on receipt of ACK until eventually loss occurs then decrease transmission rate
continue to increase on ACK decrease on loss (since available bandwidth is changing depending on other connections in network)
ACKs being received so increase rate
X
X
XX
X loss so decrease rate
send
ing
rate
time
Q how fast to increasedecreasedetails to follow
TCPrsquosldquosawtoothrdquobehavior
Transport Layer 3-80
TCP Congestion Control details
sender limits rate by limiting number of unACKed bytes ldquoin pipelinerdquo
cwnd differs from rwnd (how why)sender limited by min(cwndrwnd)
roughly
cwnd is dynamic function of perceived network congestion
rate = cwndRTT bytessec
LastByteSent-LastByteAcked le cwnd
cwndbytes
RTT
ACK(s)
Transport Layer 3-81
TCP Congestion Control more details
segment loss event reducing cwndtimeout no response from receiver
cut cwnd to 13 duplicate ACKs at least some segments getting through (recall fast retransmit)
cut cwnd in half less aggressively than on timeout
ACK received increase cwndTwo modes of operation
slowstart phase bull increase exponentially
fast (despite name) at connection start or following timeout
congestion avoidance bull increase linearly
Transport Layer 3-82
TCP Slow Start Phasewhen connection begins cwnd = 1 MSS
example MSS = 500 bytes amp RTT = 200 msecinitial rate = 20 kbps
available bandwidth may be gtgt MSSRTT
desirable to quickly ramp up to respectable rate
increase rate exponentially until first loss event or when threshold reached
double cwnd every RTTdone by incrementing cwnd by 1 for every ACK received
Host A
one segment
RTT
Host B
time
two segments
four segments
Transport Layer 3-83
Slow Start ExampleThe congestion window size grows very rapidly
For every ACK we increase CongWin by 1 irrespective of the number of segments ACKrsquoeddouble CongWinevery RTTinitial rate is slow but ramps up exponentially fast
TCP slows down the increase of CongWinwhen CongWin gt ssthresh
segment 1
ACK for segment 1
cwnd = 1
cwnd = 2 segment 2segment 3
ACK for segments 2
cwnd = 4 segment 4segment 5segment 6
ACK for segments 4
cwnd = 7
ACK for segments 3
ACK for segments 5
ACK for segments 6
cwnd = 3
cwnd = 5
cwnd = 6ACK for segments 7
cwnd = 8
segment 7
Transport Layer 3-84
TCP Congestion Avoidance Phase
when cwnd gt ssthreshgrow cwnd linearly
increase cwnd by 1 MSS per RTT approach possible congestion slower than in slowstartimplementation cwnd= cwnd + MSScwndfor each ACK received
ACKs increase cwndby 1 MSS per RTT additive increaseloss cut cwnd in half (non-timeout-detected loss ) multiplicative decrease
AIMD
AIMD Additive IncreaseMultiplicative Decrease
Transport Layer 3-85
Congestion AvoidanceCongestion avoidance phase is started if CongWin has reached the slow-start threshold value
If CongWin gt= ssthresh then each time an ACK is received increment CongWin as follows
bull CongWin = CongWin + 1CongWin (CongWin in segments)
bull In actual TCP implementation CongWin is in BytesCongWin = CongWin + MSS (MSSCongWin)
So CongWin is increased by one only if all CongWinsegments have been acknowledged
Transport Layer 3-86
Example Slow StartCongestion AvoidanceAssume that
ssthresh = 8
cwnd = 1
cwnd = 2
cwnd = 4
cwnd = 8
cwnd = 9
cwnd = 10
02468
101214
t=0
t=2
t=4
t=6
Roundtrip times
Cw
nd(in
seg
men
ts)
ssthresh
cwnd = 3
cwnd = 5cwnd = 6cwnd = 7
Transport Layer 3-87
Slow Start Congestion AvoidanceA typical plot of CongWin for a TCP connection
(MSS = 1500 bytes) with TCP Tahoe
SS
CA
ssthresh
Transport Layer 3-88
Responses to CongestionTCP assumes there is congestion if it detects a packet lossA TCP sender can detect lost packets via loss events
bull Timeout of a retransmission timerbull Receipt of 3 duplicate ACKs (fast retransmit)
TCP interprets a Timeout as a binary congestion signal When a timeout occurs the sender performs
ssthresh is set to half the current size of the congestion window
ssthresh = CongWin 2CongWin is reset to one
CongWin = 1and slow-start is entered
Transport Layer 3-89
Fast Recovery (differentiation btwn two loss events) After 3 dup ACKs (fast Retransmit)
ssthresh = CongWin2CongWin = CongWin2window then grows linearly
But after timeout eventCongWin = 1 MSS window then grows exponentiallyto the threshold then grows linearly
bull 3 dup ACKs indicates network capable of delivering some segmentsbull timeout before 3 dup ACKs is ldquomore alarmingrdquo
Philosophy
3-90
TCP Congestion ControlInitially
CongWin = 1ssthresh = advertised window size
New Ack receivedif (CongWin lt ssthresh) Slow Start
CongWin = CongWin + 1else Congestion Avoidance
CongWin = CongWin + 1CongWinTimeout
ssthresh = CongWin2CongWin = 1
Fast Retransmissionssthresh = CongWin2CongWin = CongWin2
Slow Start (exponential increase phase) is continued until CongWin reaches half of the level where the loss event occurred last time CongWin is increased slowly after (linear increase in Congestion Avoidance phase)
Transport Layer 3-91
Popular ldquoflavorsrdquo of TCP
ssthresh
ssthresh
TCP Tahoe
TCP Reno
Transmission round
cwnd
win
dow
siz
e (in
seg
men
ts)
Transport Layer 3-92
Summary TCP Congestion ControlWhen CongWin is below Threshold sender in slow-start phase window grows exponentiallyWhen CongWin is above Threshold sender is in congestion-avoidance phase window grows linearlyWhen a triple duplicate ACK occurs Threshold set to CongWin2 and CongWin set to ThresholdWhen timeout occurs Threshold set to CongWin2 and CongWin is set to 1 MSS The actual sender window size is determined based on the congestion and flow control algorithms
SenderWin=min(RcvWinCongWin)
Transport Layer 3-93
TCP Congestion Control SummaryEvent State TCP Sender Action Commentary
ACK receipt for previously unackeddata
Slow Start (SS)
CongWin = CongWin + MSS If (CongWin gt Threshold)
set state to ldquoCongestion Avoidancerdquo
Resulting in a doubling of CongWin every RTT
ACK receipt for previously unackeddata
CongestionAvoidance (CA)
CongWin = CongWin+MSS (MSSCongWin)
Additive increase resulting in increase of CongWin by 1 MSS every RTT
Loss event detected by triple duplicate ACK
SS or CA Threshold = CongWin2 CongWin = ThresholdSet state to ldquoCongestion Avoidancerdquo
Fast recovery implementing multiplicative decrease CongWin will not drop below 1 MSS
Timeout SS or CA Threshold = CongWin2 CongWin = 1 MSSSet state to ldquoSlow Startrdquo
Enter slow start
Duplicate ACK
SS or CA Increment duplicate ACK count for segment being acked
CongWin and Threshold not changed
Transport Layer 3-94
TCP throughput
Q whatrsquos average throughout of TCP as function of window size RTT
ignoring slow startlet W be window size when loss occurs
when window is W throughput is WRTTjust after loss window drops to W2 throughput to W2RTT average throughout 75 WRTT
Transport Layer 3-95
TCP Futures TCP over ldquolong fat pipesrdquo
example 1500 byte segments 100ms RTT want 10 Gbps throughputrequires window size W = 83333 in-flight segmentsthroughput in terms of loss rate
L = 210-10 Wownew versions of TCP for high-speed
LRTTMSSsdot221
Transport Layer 3-96
Fairness goal if K TCP sessions share same bottleneck link of bandwidth R each should have average rate of RK
TCP connection 1
bottleneckrouter
capacity R
TCP connection 2
TCP Fairness
Transport Layer 3-97
Why is TCP fairTwo competing sessions
Additive increase gives slope of 1 as throughout increasesmultiplicative decrease decreases throughput proportionally
R
R
equal bandwidth share
Connection 1 throughput
Conn
ecti
on 2
thr
ough
p ut
congestion avoidance additive increaseloss decrease window by factor of 2
congestion avoidance additive increaseloss decrease window by factor of 2
Transport Layer 3-98
Fairness (more)Fairness and UDP
Multimedia apps often do not use TCP
do not want rate throttled by congestion control
Instead use UDPpump audiovideo at constant rate tolerate packet loss
Research area TCP friendly
Fairness and parallel TCP connectionsnothing prevents app from opening parallel cnctionsbetween 2 hostsWeb browsers do this Example link of rate R supporting 9 cnctions
new app asks for 1 TCP gets rate R10new app asks for 11 TCPs gets R2
Transport Layer 3-99
TCP Connection ManagementRecall TCP sender receiver
establish ldquoconnectionrdquobefore exchanging data segmentsinitialize TCP variables
seq sbuffers flow control info (eg RcvWindow)
client connection initiatorSocket clientSocket = new Socket(hostnameport
number)
server contacted by clientSocket connectionSocket = welcomeSocketaccept()
Three way handshakeStep 1 client host sends TCP
SYN segment to serverspecifies initial seq no data
Step 2 server host receives SYN replies with SYNACK segment
server allocates buffersspecifies server initial seq
Step 3 client receives SYNACK replies with ACK segment which may contain data
Transport Layer 3-100
TCP Connection Management (cont)
Closing a connection
client closes socketclientSocketclose()
Step 1 client end system sends TCP FIN control segment to server
Step 2 server receives FIN replies with ACK Closes connection sends FIN
client
FIN
server
ACK
ACK
FIN
close
close
closed
tim
ed w
ait
Transport Layer 3-101
TCP Connection Management (cont)
Step 3 client receives FIN replies with ACK
Enters ldquotimed waitrdquo -will respond with ACK to received FINs
Step 4 server receives ACK Connection closed
client
FIN
server
ACK
ACK
FIN
closing
closing
closed
tim
ed w
ait
closed
Transport Layer 3-102
TCP Connection Management (cont)
TCP clientlifecycle
TCP serverlifecycle
Transport Layer 3-103
Tuning TCPIP Parameters TCPIP parameters
A set of default values may not be optimal for all applicationsThe network administrator may wish to turn on or off some TCPIP functions for performance or security considerations
Many Unix and Linux systems provide some flexibility in tuning the TCPIP kernelsbinsysctl is used to configure the Linux kernel parameters at runtime
Default kernel configuration file is sbinsysctlconfFrequently used sysctl options
bull sysctl ndasha or sysctl ndashA list all current valuesbull sysctl ndashp file_name load the sysctl setting from a configuration
filebull sysctl ndashw variable=value change the value of the parameter
Transport Layer 3-104
SomeTCP Parameters in Linux Kerneltcp_syn_retries
Number of SYN packets the kernel will send before giving up on the new connection
tcp_synack_retriesnumber of SYN+ACK packets sent before the kernel gives up on the connection
tcp_window_scalingMaximum window size of 65535 bytes not enough for for really fast networks The window scaling options allows for almost gigabyte windows which is good for connections with large delay-bandwidth product
tcp_max_syn_backlogMaximal number of remembered connection requests which still did not receive an acknowledgment from connecting client
tcp_fin_timeoutHow many seconds to wait for a final FIN packet before the socket is closed required to prevent denial-of-service (DoS) attacks Default value is 60 seconds
Transport Layer 3-105
SomeTCP Parameters in Linux Kerneltcp_rmem
This is a vector of 3 integers [min default max] These parameters are used by TCP to dynamically adjust receive buffer sizesmin - minimum size of the receive buffer used by each TCP socket The default value is 4K default - the default size of the receive buffer for a TCP socket The default value is 87380 bytes and is lowered to 43689 in low memory systems If larger receive buffer sizes are desired this value should be increased max - the maximum size of the receive buffer used by each TCP socket The default value of 873802 bytes is lowered to 87380 in low memory systems
tcp_smemSend buffer parameters [min default max] similar to tcp_rmem
- Chapter 3 Transport Layer
- Transport services and protocols
- Transport vs network layer
- Internet transport-layer protocols
- Multiplexingdemultiplexing
- How demultiplexing works
- Connectionless demultiplexing
- Connection-oriented demux
- Connection-oriented demux (cont)
- Connection-oriented demux Threaded Web Server
- UDP User Datagram Protocol [RFC 768]
- UDP more
- UDP checksum
- Principles of Reliable data transfer
- Reliable data transfer getting started
- Reliable data transfer getting started
- Rdt10 reliable transfer over a reliable channel
- Rdt20 channel with bit errors
- rdt20 FSM specification
- rdt20 operation with no errors
- rdt20 error scenario
- rdt20 has a fatal flaw
- rdt21 sender handles garbled ACKNAKs
- rdt21 receiver handles garbled ACKNAKs
- rdt21 discussion
- rdt22 a NAK-free protocol
- rdt22 sender receiver fragments
- rdt30 channels with errors and loss
- rdt30 sender
- rdt30 in action
- rdt30 in action
- Performance of rdt30
- rdt30 stop-and-wait operation
- Pipelined protocols
- Pipelining increased utilization
- Go-Back-N
- GBN sender extended FSM
- GBN receiver extended FSM
- GBN inaction
- Selective Repeat
- Selective repeat sender receiver windows
- Selective repeat
- Selective repeat in action
- Selective repeat dilemma
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- TCP Overview RFCs 793 1122 1323 2018 2581
- TCP segment structure
- TCP seq rsquos and ACKs
- TCP Round Trip Time and Timeout
- TCP Round Trip Time and Timeout
- Example RTT estimation
- TCP Round Trip Time and Timeout
- TCP reliable data transfer
- TCP sender events
- TCP sender(simplified)
- TCP retransmission scenarios
- TCP retransmission scenarios (more)
- TCP ACK generation [RFC 1122 RFC 2581]
- Fast Retransmit
- Fast Retransmit
- Fast retransmit algorithm
- TCP Flow Control
- TCP Flow control how it works
- Sliding Window Flow Control Example
- Principles of Congestion Control
- Causescosts of congestion scenario 1
- Causescosts of congestion scenario 2
- Causescosts of congestion scenario 2
- Causescosts of congestion scenario 3
- Causescosts of congestion scenario 3
- Approaches towards congestion control
- TCP Congestion Control
- TCP congestion control bandwidth probing
- TCP Congestion Control details
- TCP Congestion Control more details
- TCP Slow Start Phase
- Slow Start Example
- TCP Congestion Avoidance Phase
- Congestion Avoidance
- Example Slow StartCongestion Avoidance
- Slow Start Congestion Avoidance
- Responses to Congestion
- Fast Recovery (differentiation btwn two loss events)
- TCP Congestion Control
- Popular ldquoflavorsrdquo of TCP
- Summary TCP Congestion Control
- TCP Congestion Control Summary
- TCP throughput
- TCP Futures TCP over ldquolong fat pipesrdquo
- TCP Fairness
- Why is TCP fair
- Fairness (more)
- TCP Connection Management
- TCP Connection Management (cont)
- TCP Connection Management (cont)
- TCP Connection Management (cont)
- Tuning TCPIP Parameters
- SomeTCP Parameters in Linux Kernel
- SomeTCP Parameters in Linux Kernel
-
Transport Layer 3-79
TCP congestion control bandwidth probing
ldquoprobing for bandwidthrdquo increase transmission rate on receipt of ACK until eventually loss occurs then decrease transmission rate
continue to increase on ACK decrease on loss (since available bandwidth is changing depending on other connections in network)
ACKs being received so increase rate
X
X
XX
X loss so decrease rate
send
ing
rate
time
Q how fast to increasedecreasedetails to follow
TCPrsquosldquosawtoothrdquobehavior
Transport Layer 3-80
TCP Congestion Control details
sender limits rate by limiting number of unACKed bytes ldquoin pipelinerdquo
cwnd differs from rwnd (how why)sender limited by min(cwndrwnd)
roughly
cwnd is dynamic function of perceived network congestion
rate = cwndRTT bytessec
LastByteSent-LastByteAcked le cwnd
cwndbytes
RTT
ACK(s)
Transport Layer 3-81
TCP Congestion Control more details
segment loss event reducing cwndtimeout no response from receiver
cut cwnd to 13 duplicate ACKs at least some segments getting through (recall fast retransmit)
cut cwnd in half less aggressively than on timeout
ACK received increase cwndTwo modes of operation
slowstart phase bull increase exponentially
fast (despite name) at connection start or following timeout
congestion avoidance bull increase linearly
Transport Layer 3-82
TCP Slow Start Phasewhen connection begins cwnd = 1 MSS
example MSS = 500 bytes amp RTT = 200 msecinitial rate = 20 kbps
available bandwidth may be gtgt MSSRTT
desirable to quickly ramp up to respectable rate
increase rate exponentially until first loss event or when threshold reached
double cwnd every RTTdone by incrementing cwnd by 1 for every ACK received
Host A
one segment
RTT
Host B
time
two segments
four segments
Transport Layer 3-83
Slow Start ExampleThe congestion window size grows very rapidly
For every ACK we increase CongWin by 1 irrespective of the number of segments ACKrsquoeddouble CongWinevery RTTinitial rate is slow but ramps up exponentially fast
TCP slows down the increase of CongWinwhen CongWin gt ssthresh
segment 1
ACK for segment 1
cwnd = 1
cwnd = 2 segment 2segment 3
ACK for segments 2
cwnd = 4 segment 4segment 5segment 6
ACK for segments 4
cwnd = 7
ACK for segments 3
ACK for segments 5
ACK for segments 6
cwnd = 3
cwnd = 5
cwnd = 6ACK for segments 7
cwnd = 8
segment 7
Transport Layer 3-84
TCP Congestion Avoidance Phase
when cwnd gt ssthreshgrow cwnd linearly
increase cwnd by 1 MSS per RTT approach possible congestion slower than in slowstartimplementation cwnd= cwnd + MSScwndfor each ACK received
ACKs increase cwndby 1 MSS per RTT additive increaseloss cut cwnd in half (non-timeout-detected loss ) multiplicative decrease
AIMD
AIMD Additive IncreaseMultiplicative Decrease
Transport Layer 3-85
Congestion AvoidanceCongestion avoidance phase is started if CongWin has reached the slow-start threshold value
If CongWin gt= ssthresh then each time an ACK is received increment CongWin as follows
bull CongWin = CongWin + 1CongWin (CongWin in segments)
bull In actual TCP implementation CongWin is in BytesCongWin = CongWin + MSS (MSSCongWin)
So CongWin is increased by one only if all CongWinsegments have been acknowledged
Transport Layer 3-86
Example Slow StartCongestion AvoidanceAssume that
ssthresh = 8
cwnd = 1
cwnd = 2
cwnd = 4
cwnd = 8
cwnd = 9
cwnd = 10
02468
101214
t=0
t=2
t=4
t=6
Roundtrip times
Cw
nd(in
seg
men
ts)
ssthresh
cwnd = 3
cwnd = 5cwnd = 6cwnd = 7
Transport Layer 3-87
Slow Start Congestion AvoidanceA typical plot of CongWin for a TCP connection
(MSS = 1500 bytes) with TCP Tahoe
SS
CA
ssthresh
Transport Layer 3-88
Responses to CongestionTCP assumes there is congestion if it detects a packet lossA TCP sender can detect lost packets via loss events
bull Timeout of a retransmission timerbull Receipt of 3 duplicate ACKs (fast retransmit)
TCP interprets a Timeout as a binary congestion signal When a timeout occurs the sender performs
ssthresh is set to half the current size of the congestion window
ssthresh = CongWin 2CongWin is reset to one
CongWin = 1and slow-start is entered
Transport Layer 3-89
Fast Recovery (differentiation btwn two loss events) After 3 dup ACKs (fast Retransmit)
ssthresh = CongWin2CongWin = CongWin2window then grows linearly
But after timeout eventCongWin = 1 MSS window then grows exponentiallyto the threshold then grows linearly
bull 3 dup ACKs indicates network capable of delivering some segmentsbull timeout before 3 dup ACKs is ldquomore alarmingrdquo
Philosophy
3-90
TCP Congestion ControlInitially
CongWin = 1ssthresh = advertised window size
New Ack receivedif (CongWin lt ssthresh) Slow Start
CongWin = CongWin + 1else Congestion Avoidance
CongWin = CongWin + 1CongWinTimeout
ssthresh = CongWin2CongWin = 1
Fast Retransmissionssthresh = CongWin2CongWin = CongWin2
Slow Start (exponential increase phase) is continued until CongWin reaches half of the level where the loss event occurred last time CongWin is increased slowly after (linear increase in Congestion Avoidance phase)
Transport Layer 3-91
Popular ldquoflavorsrdquo of TCP
ssthresh
ssthresh
TCP Tahoe
TCP Reno
Transmission round
cwnd
win
dow
siz
e (in
seg
men
ts)
Transport Layer 3-92
Summary TCP Congestion ControlWhen CongWin is below Threshold sender in slow-start phase window grows exponentiallyWhen CongWin is above Threshold sender is in congestion-avoidance phase window grows linearlyWhen a triple duplicate ACK occurs Threshold set to CongWin2 and CongWin set to ThresholdWhen timeout occurs Threshold set to CongWin2 and CongWin is set to 1 MSS The actual sender window size is determined based on the congestion and flow control algorithms
SenderWin=min(RcvWinCongWin)
Transport Layer 3-93
TCP Congestion Control SummaryEvent State TCP Sender Action Commentary
ACK receipt for previously unackeddata
Slow Start (SS)
CongWin = CongWin + MSS If (CongWin gt Threshold)
set state to ldquoCongestion Avoidancerdquo
Resulting in a doubling of CongWin every RTT
ACK receipt for previously unackeddata
CongestionAvoidance (CA)
CongWin = CongWin+MSS (MSSCongWin)
Additive increase resulting in increase of CongWin by 1 MSS every RTT
Loss event detected by triple duplicate ACK
SS or CA Threshold = CongWin2 CongWin = ThresholdSet state to ldquoCongestion Avoidancerdquo
Fast recovery implementing multiplicative decrease CongWin will not drop below 1 MSS
Timeout SS or CA Threshold = CongWin2 CongWin = 1 MSSSet state to ldquoSlow Startrdquo
Enter slow start
Duplicate ACK
SS or CA Increment duplicate ACK count for segment being acked
CongWin and Threshold not changed
Transport Layer 3-94
TCP throughput
Q whatrsquos average throughout of TCP as function of window size RTT
ignoring slow startlet W be window size when loss occurs
when window is W throughput is WRTTjust after loss window drops to W2 throughput to W2RTT average throughout 75 WRTT
Transport Layer 3-95
TCP Futures TCP over ldquolong fat pipesrdquo
example 1500 byte segments 100ms RTT want 10 Gbps throughputrequires window size W = 83333 in-flight segmentsthroughput in terms of loss rate
L = 210-10 Wownew versions of TCP for high-speed
LRTTMSSsdot221
Transport Layer 3-96
Fairness goal if K TCP sessions share same bottleneck link of bandwidth R each should have average rate of RK
TCP connection 1
bottleneckrouter
capacity R
TCP connection 2
TCP Fairness
Transport Layer 3-97
Why is TCP fairTwo competing sessions
Additive increase gives slope of 1 as throughout increasesmultiplicative decrease decreases throughput proportionally
R
R
equal bandwidth share
Connection 1 throughput
Conn
ecti
on 2
thr
ough
p ut
congestion avoidance additive increaseloss decrease window by factor of 2
congestion avoidance additive increaseloss decrease window by factor of 2
Transport Layer 3-98
Fairness (more)Fairness and UDP
Multimedia apps often do not use TCP
do not want rate throttled by congestion control
Instead use UDPpump audiovideo at constant rate tolerate packet loss
Research area TCP friendly
Fairness and parallel TCP connectionsnothing prevents app from opening parallel cnctionsbetween 2 hostsWeb browsers do this Example link of rate R supporting 9 cnctions
new app asks for 1 TCP gets rate R10new app asks for 11 TCPs gets R2
Transport Layer 3-99
TCP Connection ManagementRecall TCP sender receiver
establish ldquoconnectionrdquobefore exchanging data segmentsinitialize TCP variables
seq sbuffers flow control info (eg RcvWindow)
client connection initiatorSocket clientSocket = new Socket(hostnameport
number)
server contacted by clientSocket connectionSocket = welcomeSocketaccept()
Three way handshakeStep 1 client host sends TCP
SYN segment to serverspecifies initial seq no data
Step 2 server host receives SYN replies with SYNACK segment
server allocates buffersspecifies server initial seq
Step 3 client receives SYNACK replies with ACK segment which may contain data
Transport Layer 3-100
TCP Connection Management (cont)
Closing a connection
client closes socketclientSocketclose()
Step 1 client end system sends TCP FIN control segment to server
Step 2 server receives FIN replies with ACK Closes connection sends FIN
client
FIN
server
ACK
ACK
FIN
close
close
closed
tim
ed w
ait
Transport Layer 3-101
TCP Connection Management (cont)
Step 3 client receives FIN replies with ACK
Enters ldquotimed waitrdquo -will respond with ACK to received FINs
Step 4 server receives ACK Connection closed
client
FIN
server
ACK
ACK
FIN
closing
closing
closed
tim
ed w
ait
closed
Transport Layer 3-102
TCP Connection Management (cont)
TCP clientlifecycle
TCP serverlifecycle
Transport Layer 3-103
Tuning TCPIP Parameters TCPIP parameters
A set of default values may not be optimal for all applicationsThe network administrator may wish to turn on or off some TCPIP functions for performance or security considerations
Many Unix and Linux systems provide some flexibility in tuning the TCPIP kernelsbinsysctl is used to configure the Linux kernel parameters at runtime
Default kernel configuration file is sbinsysctlconfFrequently used sysctl options
bull sysctl ndasha or sysctl ndashA list all current valuesbull sysctl ndashp file_name load the sysctl setting from a configuration
filebull sysctl ndashw variable=value change the value of the parameter
Transport Layer 3-104
SomeTCP Parameters in Linux Kerneltcp_syn_retries
Number of SYN packets the kernel will send before giving up on the new connection
tcp_synack_retriesnumber of SYN+ACK packets sent before the kernel gives up on the connection
tcp_window_scalingMaximum window size of 65535 bytes not enough for for really fast networks The window scaling options allows for almost gigabyte windows which is good for connections with large delay-bandwidth product
tcp_max_syn_backlogMaximal number of remembered connection requests which still did not receive an acknowledgment from connecting client
tcp_fin_timeoutHow many seconds to wait for a final FIN packet before the socket is closed required to prevent denial-of-service (DoS) attacks Default value is 60 seconds
Transport Layer 3-105
SomeTCP Parameters in Linux Kerneltcp_rmem
This is a vector of 3 integers [min default max] These parameters are used by TCP to dynamically adjust receive buffer sizesmin - minimum size of the receive buffer used by each TCP socket The default value is 4K default - the default size of the receive buffer for a TCP socket The default value is 87380 bytes and is lowered to 43689 in low memory systems If larger receive buffer sizes are desired this value should be increased max - the maximum size of the receive buffer used by each TCP socket The default value of 873802 bytes is lowered to 87380 in low memory systems
tcp_smemSend buffer parameters [min default max] similar to tcp_rmem
- Chapter 3 Transport Layer
- Transport services and protocols
- Transport vs network layer
- Internet transport-layer protocols
- Multiplexingdemultiplexing
- How demultiplexing works
- Connectionless demultiplexing
- Connection-oriented demux
- Connection-oriented demux (cont)
- Connection-oriented demux Threaded Web Server
- UDP User Datagram Protocol [RFC 768]
- UDP more
- UDP checksum
- Principles of Reliable data transfer
- Reliable data transfer getting started
- Reliable data transfer getting started
- Rdt10 reliable transfer over a reliable channel
- Rdt20 channel with bit errors
- rdt20 FSM specification
- rdt20 operation with no errors
- rdt20 error scenario
- rdt20 has a fatal flaw
- rdt21 sender handles garbled ACKNAKs
- rdt21 receiver handles garbled ACKNAKs
- rdt21 discussion
- rdt22 a NAK-free protocol
- rdt22 sender receiver fragments
- rdt30 channels with errors and loss
- rdt30 sender
- rdt30 in action
- rdt30 in action
- Performance of rdt30
- rdt30 stop-and-wait operation
- Pipelined protocols
- Pipelining increased utilization
- Go-Back-N
- GBN sender extended FSM
- GBN receiver extended FSM
- GBN inaction
- Selective Repeat
- Selective repeat sender receiver windows
- Selective repeat
- Selective repeat in action
- Selective repeat dilemma
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- TCP Overview RFCs 793 1122 1323 2018 2581
- TCP segment structure
- TCP seq rsquos and ACKs
- TCP Round Trip Time and Timeout
- TCP Round Trip Time and Timeout
- Example RTT estimation
- TCP Round Trip Time and Timeout
- TCP reliable data transfer
- TCP sender events
- TCP sender(simplified)
- TCP retransmission scenarios
- TCP retransmission scenarios (more)
- TCP ACK generation [RFC 1122 RFC 2581]
- Fast Retransmit
- Fast Retransmit
- Fast retransmit algorithm
- TCP Flow Control
- TCP Flow control how it works
- Sliding Window Flow Control Example
- Principles of Congestion Control
- Causescosts of congestion scenario 1
- Causescosts of congestion scenario 2
- Causescosts of congestion scenario 2
- Causescosts of congestion scenario 3
- Causescosts of congestion scenario 3
- Approaches towards congestion control
- TCP Congestion Control
- TCP congestion control bandwidth probing
- TCP Congestion Control details
- TCP Congestion Control more details
- TCP Slow Start Phase
- Slow Start Example
- TCP Congestion Avoidance Phase
- Congestion Avoidance
- Example Slow StartCongestion Avoidance
- Slow Start Congestion Avoidance
- Responses to Congestion
- Fast Recovery (differentiation btwn two loss events)
- TCP Congestion Control
- Popular ldquoflavorsrdquo of TCP
- Summary TCP Congestion Control
- TCP Congestion Control Summary
- TCP throughput
- TCP Futures TCP over ldquolong fat pipesrdquo
- TCP Fairness
- Why is TCP fair
- Fairness (more)
- TCP Connection Management
- TCP Connection Management (cont)
- TCP Connection Management (cont)
- TCP Connection Management (cont)
- Tuning TCPIP Parameters
- SomeTCP Parameters in Linux Kernel
- SomeTCP Parameters in Linux Kernel
-
Transport Layer 3-80
TCP Congestion Control details
sender limits rate by limiting number of unACKed bytes ldquoin pipelinerdquo
cwnd differs from rwnd (how why)sender limited by min(cwndrwnd)
roughly
cwnd is dynamic function of perceived network congestion
rate = cwndRTT bytessec
LastByteSent-LastByteAcked le cwnd
cwndbytes
RTT
ACK(s)
Transport Layer 3-81
TCP Congestion Control more details
segment loss event reducing cwndtimeout no response from receiver
cut cwnd to 13 duplicate ACKs at least some segments getting through (recall fast retransmit)
cut cwnd in half less aggressively than on timeout
ACK received increase cwndTwo modes of operation
slowstart phase bull increase exponentially
fast (despite name) at connection start or following timeout
congestion avoidance bull increase linearly
Transport Layer 3-82
TCP Slow Start Phasewhen connection begins cwnd = 1 MSS
example MSS = 500 bytes amp RTT = 200 msecinitial rate = 20 kbps
available bandwidth may be gtgt MSSRTT
desirable to quickly ramp up to respectable rate
increase rate exponentially until first loss event or when threshold reached
double cwnd every RTTdone by incrementing cwnd by 1 for every ACK received
Host A
one segment
RTT
Host B
time
two segments
four segments
Transport Layer 3-83
Slow Start ExampleThe congestion window size grows very rapidly
For every ACK we increase CongWin by 1 irrespective of the number of segments ACKrsquoeddouble CongWinevery RTTinitial rate is slow but ramps up exponentially fast
TCP slows down the increase of CongWinwhen CongWin gt ssthresh
segment 1
ACK for segment 1
cwnd = 1
cwnd = 2 segment 2segment 3
ACK for segments 2
cwnd = 4 segment 4segment 5segment 6
ACK for segments 4
cwnd = 7
ACK for segments 3
ACK for segments 5
ACK for segments 6
cwnd = 3
cwnd = 5
cwnd = 6ACK for segments 7
cwnd = 8
segment 7
Transport Layer 3-84
TCP Congestion Avoidance Phase
when cwnd gt ssthreshgrow cwnd linearly
increase cwnd by 1 MSS per RTT approach possible congestion slower than in slowstartimplementation cwnd= cwnd + MSScwndfor each ACK received
ACKs increase cwndby 1 MSS per RTT additive increaseloss cut cwnd in half (non-timeout-detected loss ) multiplicative decrease
AIMD
AIMD Additive IncreaseMultiplicative Decrease
Transport Layer 3-85
Congestion AvoidanceCongestion avoidance phase is started if CongWin has reached the slow-start threshold value
If CongWin gt= ssthresh then each time an ACK is received increment CongWin as follows
bull CongWin = CongWin + 1CongWin (CongWin in segments)
bull In actual TCP implementation CongWin is in BytesCongWin = CongWin + MSS (MSSCongWin)
So CongWin is increased by one only if all CongWinsegments have been acknowledged
Transport Layer 3-86
Example Slow StartCongestion AvoidanceAssume that
ssthresh = 8
cwnd = 1
cwnd = 2
cwnd = 4
cwnd = 8
cwnd = 9
cwnd = 10
02468
101214
t=0
t=2
t=4
t=6
Roundtrip times
Cw
nd(in
seg
men
ts)
ssthresh
cwnd = 3
cwnd = 5cwnd = 6cwnd = 7
Transport Layer 3-87
Slow Start Congestion AvoidanceA typical plot of CongWin for a TCP connection
(MSS = 1500 bytes) with TCP Tahoe
SS
CA
ssthresh
Transport Layer 3-88
Responses to CongestionTCP assumes there is congestion if it detects a packet lossA TCP sender can detect lost packets via loss events
bull Timeout of a retransmission timerbull Receipt of 3 duplicate ACKs (fast retransmit)
TCP interprets a Timeout as a binary congestion signal When a timeout occurs the sender performs
ssthresh is set to half the current size of the congestion window
ssthresh = CongWin 2CongWin is reset to one
CongWin = 1and slow-start is entered
Transport Layer 3-89
Fast Recovery (differentiation btwn two loss events) After 3 dup ACKs (fast Retransmit)
ssthresh = CongWin2CongWin = CongWin2window then grows linearly
But after timeout eventCongWin = 1 MSS window then grows exponentiallyto the threshold then grows linearly
bull 3 dup ACKs indicates network capable of delivering some segmentsbull timeout before 3 dup ACKs is ldquomore alarmingrdquo
Philosophy
3-90
TCP Congestion ControlInitially
CongWin = 1ssthresh = advertised window size
New Ack receivedif (CongWin lt ssthresh) Slow Start
CongWin = CongWin + 1else Congestion Avoidance
CongWin = CongWin + 1CongWinTimeout
ssthresh = CongWin2CongWin = 1
Fast Retransmissionssthresh = CongWin2CongWin = CongWin2
Slow Start (exponential increase phase) is continued until CongWin reaches half of the level where the loss event occurred last time CongWin is increased slowly after (linear increase in Congestion Avoidance phase)
Transport Layer 3-91
Popular ldquoflavorsrdquo of TCP
ssthresh
ssthresh
TCP Tahoe
TCP Reno
Transmission round
cwnd
win
dow
siz
e (in
seg
men
ts)
Transport Layer 3-92
Summary TCP Congestion ControlWhen CongWin is below Threshold sender in slow-start phase window grows exponentiallyWhen CongWin is above Threshold sender is in congestion-avoidance phase window grows linearlyWhen a triple duplicate ACK occurs Threshold set to CongWin2 and CongWin set to ThresholdWhen timeout occurs Threshold set to CongWin2 and CongWin is set to 1 MSS The actual sender window size is determined based on the congestion and flow control algorithms
SenderWin=min(RcvWinCongWin)
Transport Layer 3-93
TCP Congestion Control SummaryEvent State TCP Sender Action Commentary
ACK receipt for previously unackeddata
Slow Start (SS)
CongWin = CongWin + MSS If (CongWin gt Threshold)
set state to ldquoCongestion Avoidancerdquo
Resulting in a doubling of CongWin every RTT
ACK receipt for previously unackeddata
CongestionAvoidance (CA)
CongWin = CongWin+MSS (MSSCongWin)
Additive increase resulting in increase of CongWin by 1 MSS every RTT
Loss event detected by triple duplicate ACK
SS or CA Threshold = CongWin2 CongWin = ThresholdSet state to ldquoCongestion Avoidancerdquo
Fast recovery implementing multiplicative decrease CongWin will not drop below 1 MSS
Timeout SS or CA Threshold = CongWin2 CongWin = 1 MSSSet state to ldquoSlow Startrdquo
Enter slow start
Duplicate ACK
SS or CA Increment duplicate ACK count for segment being acked
CongWin and Threshold not changed
Transport Layer 3-94
TCP throughput
Q whatrsquos average throughout of TCP as function of window size RTT
ignoring slow startlet W be window size when loss occurs
when window is W throughput is WRTTjust after loss window drops to W2 throughput to W2RTT average throughout 75 WRTT
Transport Layer 3-95
TCP Futures TCP over ldquolong fat pipesrdquo
example 1500 byte segments 100ms RTT want 10 Gbps throughputrequires window size W = 83333 in-flight segmentsthroughput in terms of loss rate
L = 210-10 Wownew versions of TCP for high-speed
LRTTMSSsdot221
Transport Layer 3-96
Fairness goal if K TCP sessions share same bottleneck link of bandwidth R each should have average rate of RK
TCP connection 1
bottleneckrouter
capacity R
TCP connection 2
TCP Fairness
Transport Layer 3-97
Why is TCP fairTwo competing sessions
Additive increase gives slope of 1 as throughout increasesmultiplicative decrease decreases throughput proportionally
R
R
equal bandwidth share
Connection 1 throughput
Conn
ecti
on 2
thr
ough
p ut
congestion avoidance additive increaseloss decrease window by factor of 2
congestion avoidance additive increaseloss decrease window by factor of 2
Transport Layer 3-98
Fairness (more)Fairness and UDP
Multimedia apps often do not use TCP
do not want rate throttled by congestion control
Instead use UDPpump audiovideo at constant rate tolerate packet loss
Research area TCP friendly
Fairness and parallel TCP connectionsnothing prevents app from opening parallel cnctionsbetween 2 hostsWeb browsers do this Example link of rate R supporting 9 cnctions
new app asks for 1 TCP gets rate R10new app asks for 11 TCPs gets R2
Transport Layer 3-99
TCP Connection ManagementRecall TCP sender receiver
establish ldquoconnectionrdquobefore exchanging data segmentsinitialize TCP variables
seq sbuffers flow control info (eg RcvWindow)
client connection initiatorSocket clientSocket = new Socket(hostnameport
number)
server contacted by clientSocket connectionSocket = welcomeSocketaccept()
Three way handshakeStep 1 client host sends TCP
SYN segment to serverspecifies initial seq no data
Step 2 server host receives SYN replies with SYNACK segment
server allocates buffersspecifies server initial seq
Step 3 client receives SYNACK replies with ACK segment which may contain data
Transport Layer 3-100
TCP Connection Management (cont)
Closing a connection
client closes socketclientSocketclose()
Step 1 client end system sends TCP FIN control segment to server
Step 2 server receives FIN replies with ACK Closes connection sends FIN
client
FIN
server
ACK
ACK
FIN
close
close
closed
tim
ed w
ait
Transport Layer 3-101
TCP Connection Management (cont)
Step 3 client receives FIN replies with ACK
Enters ldquotimed waitrdquo -will respond with ACK to received FINs
Step 4 server receives ACK Connection closed
client
FIN
server
ACK
ACK
FIN
closing
closing
closed
tim
ed w
ait
closed
Transport Layer 3-102
TCP Connection Management (cont)
TCP clientlifecycle
TCP serverlifecycle
Transport Layer 3-103
Tuning TCPIP Parameters TCPIP parameters
A set of default values may not be optimal for all applicationsThe network administrator may wish to turn on or off some TCPIP functions for performance or security considerations
Many Unix and Linux systems provide some flexibility in tuning the TCPIP kernelsbinsysctl is used to configure the Linux kernel parameters at runtime
Default kernel configuration file is sbinsysctlconfFrequently used sysctl options
bull sysctl ndasha or sysctl ndashA list all current valuesbull sysctl ndashp file_name load the sysctl setting from a configuration
filebull sysctl ndashw variable=value change the value of the parameter
Transport Layer 3-104
SomeTCP Parameters in Linux Kerneltcp_syn_retries
Number of SYN packets the kernel will send before giving up on the new connection
tcp_synack_retriesnumber of SYN+ACK packets sent before the kernel gives up on the connection
tcp_window_scalingMaximum window size of 65535 bytes not enough for for really fast networks The window scaling options allows for almost gigabyte windows which is good for connections with large delay-bandwidth product
tcp_max_syn_backlogMaximal number of remembered connection requests which still did not receive an acknowledgment from connecting client
tcp_fin_timeoutHow many seconds to wait for a final FIN packet before the socket is closed required to prevent denial-of-service (DoS) attacks Default value is 60 seconds
Transport Layer 3-105
SomeTCP Parameters in Linux Kerneltcp_rmem
This is a vector of 3 integers [min default max] These parameters are used by TCP to dynamically adjust receive buffer sizesmin - minimum size of the receive buffer used by each TCP socket The default value is 4K default - the default size of the receive buffer for a TCP socket The default value is 87380 bytes and is lowered to 43689 in low memory systems If larger receive buffer sizes are desired this value should be increased max - the maximum size of the receive buffer used by each TCP socket The default value of 873802 bytes is lowered to 87380 in low memory systems
tcp_smemSend buffer parameters [min default max] similar to tcp_rmem
- Chapter 3 Transport Layer
- Transport services and protocols
- Transport vs network layer
- Internet transport-layer protocols
- Multiplexingdemultiplexing
- How demultiplexing works
- Connectionless demultiplexing
- Connection-oriented demux
- Connection-oriented demux (cont)
- Connection-oriented demux Threaded Web Server
- UDP User Datagram Protocol [RFC 768]
- UDP more
- UDP checksum
- Principles of Reliable data transfer
- Reliable data transfer getting started
- Reliable data transfer getting started
- Rdt10 reliable transfer over a reliable channel
- Rdt20 channel with bit errors
- rdt20 FSM specification
- rdt20 operation with no errors
- rdt20 error scenario
- rdt20 has a fatal flaw
- rdt21 sender handles garbled ACKNAKs
- rdt21 receiver handles garbled ACKNAKs
- rdt21 discussion
- rdt22 a NAK-free protocol
- rdt22 sender receiver fragments
- rdt30 channels with errors and loss
- rdt30 sender
- rdt30 in action
- rdt30 in action
- Performance of rdt30
- rdt30 stop-and-wait operation
- Pipelined protocols
- Pipelining increased utilization
- Go-Back-N
- GBN sender extended FSM
- GBN receiver extended FSM
- GBN inaction
- Selective Repeat
- Selective repeat sender receiver windows
- Selective repeat
- Selective repeat in action
- Selective repeat dilemma
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- TCP Overview RFCs 793 1122 1323 2018 2581
- TCP segment structure
- TCP seq rsquos and ACKs
- TCP Round Trip Time and Timeout
- TCP Round Trip Time and Timeout
- Example RTT estimation
- TCP Round Trip Time and Timeout
- TCP reliable data transfer
- TCP sender events
- TCP sender(simplified)
- TCP retransmission scenarios
- TCP retransmission scenarios (more)
- TCP ACK generation [RFC 1122 RFC 2581]
- Fast Retransmit
- Fast Retransmit
- Fast retransmit algorithm
- TCP Flow Control
- TCP Flow control how it works
- Sliding Window Flow Control Example
- Principles of Congestion Control
- Causescosts of congestion scenario 1
- Causescosts of congestion scenario 2
- Causescosts of congestion scenario 2
- Causescosts of congestion scenario 3
- Causescosts of congestion scenario 3
- Approaches towards congestion control
- TCP Congestion Control
- TCP congestion control bandwidth probing
- TCP Congestion Control details
- TCP Congestion Control more details
- TCP Slow Start Phase
- Slow Start Example
- TCP Congestion Avoidance Phase
- Congestion Avoidance
- Example Slow StartCongestion Avoidance
- Slow Start Congestion Avoidance
- Responses to Congestion
- Fast Recovery (differentiation btwn two loss events)
- TCP Congestion Control
- Popular ldquoflavorsrdquo of TCP
- Summary TCP Congestion Control
- TCP Congestion Control Summary
- TCP throughput
- TCP Futures TCP over ldquolong fat pipesrdquo
- TCP Fairness
- Why is TCP fair
- Fairness (more)
- TCP Connection Management
- TCP Connection Management (cont)
- TCP Connection Management (cont)
- TCP Connection Management (cont)
- Tuning TCPIP Parameters
- SomeTCP Parameters in Linux Kernel
- SomeTCP Parameters in Linux Kernel
-
Transport Layer 3-81
TCP Congestion Control more details
segment loss event reducing cwndtimeout no response from receiver
cut cwnd to 13 duplicate ACKs at least some segments getting through (recall fast retransmit)
cut cwnd in half less aggressively than on timeout
ACK received increase cwndTwo modes of operation
slowstart phase bull increase exponentially
fast (despite name) at connection start or following timeout
congestion avoidance bull increase linearly
Transport Layer 3-82
TCP Slow Start Phasewhen connection begins cwnd = 1 MSS
example MSS = 500 bytes amp RTT = 200 msecinitial rate = 20 kbps
available bandwidth may be gtgt MSSRTT
desirable to quickly ramp up to respectable rate
increase rate exponentially until first loss event or when threshold reached
double cwnd every RTTdone by incrementing cwnd by 1 for every ACK received
Host A
one segment
RTT
Host B
time
two segments
four segments
Transport Layer 3-83
Slow Start ExampleThe congestion window size grows very rapidly
For every ACK we increase CongWin by 1 irrespective of the number of segments ACKrsquoeddouble CongWinevery RTTinitial rate is slow but ramps up exponentially fast
TCP slows down the increase of CongWinwhen CongWin gt ssthresh
segment 1
ACK for segment 1
cwnd = 1
cwnd = 2 segment 2segment 3
ACK for segments 2
cwnd = 4 segment 4segment 5segment 6
ACK for segments 4
cwnd = 7
ACK for segments 3
ACK for segments 5
ACK for segments 6
cwnd = 3
cwnd = 5
cwnd = 6ACK for segments 7
cwnd = 8
segment 7
Transport Layer 3-84
TCP Congestion Avoidance Phase
when cwnd gt ssthreshgrow cwnd linearly
increase cwnd by 1 MSS per RTT approach possible congestion slower than in slowstartimplementation cwnd= cwnd + MSScwndfor each ACK received
ACKs increase cwndby 1 MSS per RTT additive increaseloss cut cwnd in half (non-timeout-detected loss ) multiplicative decrease
AIMD
AIMD Additive IncreaseMultiplicative Decrease
Transport Layer 3-85
Congestion AvoidanceCongestion avoidance phase is started if CongWin has reached the slow-start threshold value
If CongWin gt= ssthresh then each time an ACK is received increment CongWin as follows
bull CongWin = CongWin + 1CongWin (CongWin in segments)
bull In actual TCP implementation CongWin is in BytesCongWin = CongWin + MSS (MSSCongWin)
So CongWin is increased by one only if all CongWinsegments have been acknowledged
Transport Layer 3-86
Example Slow StartCongestion AvoidanceAssume that
ssthresh = 8
cwnd = 1
cwnd = 2
cwnd = 4
cwnd = 8
cwnd = 9
cwnd = 10
02468
101214
t=0
t=2
t=4
t=6
Roundtrip times
Cw
nd(in
seg
men
ts)
ssthresh
cwnd = 3
cwnd = 5cwnd = 6cwnd = 7
Transport Layer 3-87
Slow Start Congestion AvoidanceA typical plot of CongWin for a TCP connection
(MSS = 1500 bytes) with TCP Tahoe
SS
CA
ssthresh
Transport Layer 3-88
Responses to CongestionTCP assumes there is congestion if it detects a packet lossA TCP sender can detect lost packets via loss events
bull Timeout of a retransmission timerbull Receipt of 3 duplicate ACKs (fast retransmit)
TCP interprets a Timeout as a binary congestion signal When a timeout occurs the sender performs
ssthresh is set to half the current size of the congestion window
ssthresh = CongWin 2CongWin is reset to one
CongWin = 1and slow-start is entered
Transport Layer 3-89
Fast Recovery (differentiation btwn two loss events) After 3 dup ACKs (fast Retransmit)
ssthresh = CongWin2CongWin = CongWin2window then grows linearly
But after timeout eventCongWin = 1 MSS window then grows exponentiallyto the threshold then grows linearly
bull 3 dup ACKs indicates network capable of delivering some segmentsbull timeout before 3 dup ACKs is ldquomore alarmingrdquo
Philosophy
3-90
TCP Congestion ControlInitially
CongWin = 1ssthresh = advertised window size
New Ack receivedif (CongWin lt ssthresh) Slow Start
CongWin = CongWin + 1else Congestion Avoidance
CongWin = CongWin + 1CongWinTimeout
ssthresh = CongWin2CongWin = 1
Fast Retransmissionssthresh = CongWin2CongWin = CongWin2
Slow Start (exponential increase phase) is continued until CongWin reaches half of the level where the loss event occurred last time CongWin is increased slowly after (linear increase in Congestion Avoidance phase)
Transport Layer 3-91
Popular ldquoflavorsrdquo of TCP
ssthresh
ssthresh
TCP Tahoe
TCP Reno
Transmission round
cwnd
win
dow
siz
e (in
seg
men
ts)
Transport Layer 3-92
Summary TCP Congestion ControlWhen CongWin is below Threshold sender in slow-start phase window grows exponentiallyWhen CongWin is above Threshold sender is in congestion-avoidance phase window grows linearlyWhen a triple duplicate ACK occurs Threshold set to CongWin2 and CongWin set to ThresholdWhen timeout occurs Threshold set to CongWin2 and CongWin is set to 1 MSS The actual sender window size is determined based on the congestion and flow control algorithms
SenderWin=min(RcvWinCongWin)
Transport Layer 3-93
TCP Congestion Control SummaryEvent State TCP Sender Action Commentary
ACK receipt for previously unackeddata
Slow Start (SS)
CongWin = CongWin + MSS If (CongWin gt Threshold)
set state to ldquoCongestion Avoidancerdquo
Resulting in a doubling of CongWin every RTT
ACK receipt for previously unackeddata
CongestionAvoidance (CA)
CongWin = CongWin+MSS (MSSCongWin)
Additive increase resulting in increase of CongWin by 1 MSS every RTT
Loss event detected by triple duplicate ACK
SS or CA Threshold = CongWin2 CongWin = ThresholdSet state to ldquoCongestion Avoidancerdquo
Fast recovery implementing multiplicative decrease CongWin will not drop below 1 MSS
Timeout SS or CA Threshold = CongWin2 CongWin = 1 MSSSet state to ldquoSlow Startrdquo
Enter slow start
Duplicate ACK
SS or CA Increment duplicate ACK count for segment being acked
CongWin and Threshold not changed
Transport Layer 3-94
TCP throughput
Q whatrsquos average throughout of TCP as function of window size RTT
ignoring slow startlet W be window size when loss occurs
when window is W throughput is WRTTjust after loss window drops to W2 throughput to W2RTT average throughout 75 WRTT
Transport Layer 3-95
TCP Futures TCP over ldquolong fat pipesrdquo
example 1500 byte segments 100ms RTT want 10 Gbps throughputrequires window size W = 83333 in-flight segmentsthroughput in terms of loss rate
L = 210-10 Wownew versions of TCP for high-speed
LRTTMSSsdot221
Transport Layer 3-96
Fairness goal if K TCP sessions share same bottleneck link of bandwidth R each should have average rate of RK
TCP connection 1
bottleneckrouter
capacity R
TCP connection 2
TCP Fairness
Transport Layer 3-97
Why is TCP fairTwo competing sessions
Additive increase gives slope of 1 as throughout increasesmultiplicative decrease decreases throughput proportionally
R
R
equal bandwidth share
Connection 1 throughput
Conn
ecti
on 2
thr
ough
p ut
congestion avoidance additive increaseloss decrease window by factor of 2
congestion avoidance additive increaseloss decrease window by factor of 2
Transport Layer 3-98
Fairness (more)Fairness and UDP
Multimedia apps often do not use TCP
do not want rate throttled by congestion control
Instead use UDPpump audiovideo at constant rate tolerate packet loss
Research area TCP friendly
Fairness and parallel TCP connectionsnothing prevents app from opening parallel cnctionsbetween 2 hostsWeb browsers do this Example link of rate R supporting 9 cnctions
new app asks for 1 TCP gets rate R10new app asks for 11 TCPs gets R2
Transport Layer 3-99
TCP Connection ManagementRecall TCP sender receiver
establish ldquoconnectionrdquobefore exchanging data segmentsinitialize TCP variables
seq sbuffers flow control info (eg RcvWindow)
client connection initiatorSocket clientSocket = new Socket(hostnameport
number)
server contacted by clientSocket connectionSocket = welcomeSocketaccept()
Three way handshakeStep 1 client host sends TCP
SYN segment to serverspecifies initial seq no data
Step 2 server host receives SYN replies with SYNACK segment
server allocates buffersspecifies server initial seq
Step 3 client receives SYNACK replies with ACK segment which may contain data
Transport Layer 3-100
TCP Connection Management (cont)
Closing a connection
client closes socketclientSocketclose()
Step 1 client end system sends TCP FIN control segment to server
Step 2 server receives FIN replies with ACK Closes connection sends FIN
client
FIN
server
ACK
ACK
FIN
close
close
closed
tim
ed w
ait
Transport Layer 3-101
TCP Connection Management (cont)
Step 3 client receives FIN replies with ACK
Enters ldquotimed waitrdquo -will respond with ACK to received FINs
Step 4 server receives ACK Connection closed
client
FIN
server
ACK
ACK
FIN
closing
closing
closed
tim
ed w
ait
closed
Transport Layer 3-102
TCP Connection Management (cont)
TCP clientlifecycle
TCP serverlifecycle
Transport Layer 3-103
Tuning TCPIP Parameters TCPIP parameters
A set of default values may not be optimal for all applicationsThe network administrator may wish to turn on or off some TCPIP functions for performance or security considerations
Many Unix and Linux systems provide some flexibility in tuning the TCPIP kernelsbinsysctl is used to configure the Linux kernel parameters at runtime
Default kernel configuration file is sbinsysctlconfFrequently used sysctl options
bull sysctl ndasha or sysctl ndashA list all current valuesbull sysctl ndashp file_name load the sysctl setting from a configuration
filebull sysctl ndashw variable=value change the value of the parameter
Transport Layer 3-104
SomeTCP Parameters in Linux Kerneltcp_syn_retries
Number of SYN packets the kernel will send before giving up on the new connection
tcp_synack_retriesnumber of SYN+ACK packets sent before the kernel gives up on the connection
tcp_window_scalingMaximum window size of 65535 bytes not enough for for really fast networks The window scaling options allows for almost gigabyte windows which is good for connections with large delay-bandwidth product
tcp_max_syn_backlogMaximal number of remembered connection requests which still did not receive an acknowledgment from connecting client
tcp_fin_timeoutHow many seconds to wait for a final FIN packet before the socket is closed required to prevent denial-of-service (DoS) attacks Default value is 60 seconds
Transport Layer 3-105
SomeTCP Parameters in Linux Kerneltcp_rmem
This is a vector of 3 integers [min default max] These parameters are used by TCP to dynamically adjust receive buffer sizesmin - minimum size of the receive buffer used by each TCP socket The default value is 4K default - the default size of the receive buffer for a TCP socket The default value is 87380 bytes and is lowered to 43689 in low memory systems If larger receive buffer sizes are desired this value should be increased max - the maximum size of the receive buffer used by each TCP socket The default value of 873802 bytes is lowered to 87380 in low memory systems
tcp_smemSend buffer parameters [min default max] similar to tcp_rmem
- Chapter 3 Transport Layer
- Transport services and protocols
- Transport vs network layer
- Internet transport-layer protocols
- Multiplexingdemultiplexing
- How demultiplexing works
- Connectionless demultiplexing
- Connection-oriented demux
- Connection-oriented demux (cont)
- Connection-oriented demux Threaded Web Server
- UDP User Datagram Protocol [RFC 768]
- UDP more
- UDP checksum
- Principles of Reliable data transfer
- Reliable data transfer getting started
- Reliable data transfer getting started
- Rdt10 reliable transfer over a reliable channel
- Rdt20 channel with bit errors
- rdt20 FSM specification
- rdt20 operation with no errors
- rdt20 error scenario
- rdt20 has a fatal flaw
- rdt21 sender handles garbled ACKNAKs
- rdt21 receiver handles garbled ACKNAKs
- rdt21 discussion
- rdt22 a NAK-free protocol
- rdt22 sender receiver fragments
- rdt30 channels with errors and loss
- rdt30 sender
- rdt30 in action
- rdt30 in action
- Performance of rdt30
- rdt30 stop-and-wait operation
- Pipelined protocols
- Pipelining increased utilization
- Go-Back-N
- GBN sender extended FSM
- GBN receiver extended FSM
- GBN inaction
- Selective Repeat
- Selective repeat sender receiver windows
- Selective repeat
- Selective repeat in action
- Selective repeat dilemma
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- TCP Overview RFCs 793 1122 1323 2018 2581
- TCP segment structure
- TCP seq rsquos and ACKs
- TCP Round Trip Time and Timeout
- TCP Round Trip Time and Timeout
- Example RTT estimation
- TCP Round Trip Time and Timeout
- TCP reliable data transfer
- TCP sender events
- TCP sender(simplified)
- TCP retransmission scenarios
- TCP retransmission scenarios (more)
- TCP ACK generation [RFC 1122 RFC 2581]
- Fast Retransmit
- Fast Retransmit
- Fast retransmit algorithm
- TCP Flow Control
- TCP Flow control how it works
- Sliding Window Flow Control Example
- Principles of Congestion Control
- Causescosts of congestion scenario 1
- Causescosts of congestion scenario 2
- Causescosts of congestion scenario 2
- Causescosts of congestion scenario 3
- Causescosts of congestion scenario 3
- Approaches towards congestion control
- TCP Congestion Control
- TCP congestion control bandwidth probing
- TCP Congestion Control details
- TCP Congestion Control more details
- TCP Slow Start Phase
- Slow Start Example
- TCP Congestion Avoidance Phase
- Congestion Avoidance
- Example Slow StartCongestion Avoidance
- Slow Start Congestion Avoidance
- Responses to Congestion
- Fast Recovery (differentiation btwn two loss events)
- TCP Congestion Control
- Popular ldquoflavorsrdquo of TCP
- Summary TCP Congestion Control
- TCP Congestion Control Summary
- TCP throughput
- TCP Futures TCP over ldquolong fat pipesrdquo
- TCP Fairness
- Why is TCP fair
- Fairness (more)
- TCP Connection Management
- TCP Connection Management (cont)
- TCP Connection Management (cont)
- TCP Connection Management (cont)
- Tuning TCPIP Parameters
- SomeTCP Parameters in Linux Kernel
- SomeTCP Parameters in Linux Kernel
-
Transport Layer 3-82
TCP Slow Start Phasewhen connection begins cwnd = 1 MSS
example MSS = 500 bytes amp RTT = 200 msecinitial rate = 20 kbps
available bandwidth may be gtgt MSSRTT
desirable to quickly ramp up to respectable rate
increase rate exponentially until first loss event or when threshold reached
double cwnd every RTTdone by incrementing cwnd by 1 for every ACK received
Host A
one segment
RTT
Host B
time
two segments
four segments
Transport Layer 3-83
Slow Start ExampleThe congestion window size grows very rapidly
For every ACK we increase CongWin by 1 irrespective of the number of segments ACKrsquoeddouble CongWinevery RTTinitial rate is slow but ramps up exponentially fast
TCP slows down the increase of CongWinwhen CongWin gt ssthresh
segment 1
ACK for segment 1
cwnd = 1
cwnd = 2 segment 2segment 3
ACK for segments 2
cwnd = 4 segment 4segment 5segment 6
ACK for segments 4
cwnd = 7
ACK for segments 3
ACK for segments 5
ACK for segments 6
cwnd = 3
cwnd = 5
cwnd = 6ACK for segments 7
cwnd = 8
segment 7
Transport Layer 3-84
TCP Congestion Avoidance Phase
when cwnd gt ssthreshgrow cwnd linearly
increase cwnd by 1 MSS per RTT approach possible congestion slower than in slowstartimplementation cwnd= cwnd + MSScwndfor each ACK received
ACKs increase cwndby 1 MSS per RTT additive increaseloss cut cwnd in half (non-timeout-detected loss ) multiplicative decrease
AIMD
AIMD Additive IncreaseMultiplicative Decrease
Transport Layer 3-85
Congestion AvoidanceCongestion avoidance phase is started if CongWin has reached the slow-start threshold value
If CongWin gt= ssthresh then each time an ACK is received increment CongWin as follows
bull CongWin = CongWin + 1CongWin (CongWin in segments)
bull In actual TCP implementation CongWin is in BytesCongWin = CongWin + MSS (MSSCongWin)
So CongWin is increased by one only if all CongWinsegments have been acknowledged
Transport Layer 3-86
Example Slow StartCongestion AvoidanceAssume that
ssthresh = 8
cwnd = 1
cwnd = 2
cwnd = 4
cwnd = 8
cwnd = 9
cwnd = 10
02468
101214
t=0
t=2
t=4
t=6
Roundtrip times
Cw
nd(in
seg
men
ts)
ssthresh
cwnd = 3
cwnd = 5cwnd = 6cwnd = 7
Transport Layer 3-87
Slow Start Congestion AvoidanceA typical plot of CongWin for a TCP connection
(MSS = 1500 bytes) with TCP Tahoe
SS
CA
ssthresh
Transport Layer 3-88
Responses to CongestionTCP assumes there is congestion if it detects a packet lossA TCP sender can detect lost packets via loss events
bull Timeout of a retransmission timerbull Receipt of 3 duplicate ACKs (fast retransmit)
TCP interprets a Timeout as a binary congestion signal When a timeout occurs the sender performs
ssthresh is set to half the current size of the congestion window
ssthresh = CongWin 2CongWin is reset to one
CongWin = 1and slow-start is entered
Transport Layer 3-89
Fast Recovery (differentiation btwn two loss events) After 3 dup ACKs (fast Retransmit)
ssthresh = CongWin2CongWin = CongWin2window then grows linearly
But after timeout eventCongWin = 1 MSS window then grows exponentiallyto the threshold then grows linearly
bull 3 dup ACKs indicates network capable of delivering some segmentsbull timeout before 3 dup ACKs is ldquomore alarmingrdquo
Philosophy
3-90
TCP Congestion ControlInitially
CongWin = 1ssthresh = advertised window size
New Ack receivedif (CongWin lt ssthresh) Slow Start
CongWin = CongWin + 1else Congestion Avoidance
CongWin = CongWin + 1CongWinTimeout
ssthresh = CongWin2CongWin = 1
Fast Retransmissionssthresh = CongWin2CongWin = CongWin2
Slow Start (exponential increase phase) is continued until CongWin reaches half of the level where the loss event occurred last time CongWin is increased slowly after (linear increase in Congestion Avoidance phase)
Transport Layer 3-91
Popular ldquoflavorsrdquo of TCP
ssthresh
ssthresh
TCP Tahoe
TCP Reno
Transmission round
cwnd
win
dow
siz
e (in
seg
men
ts)
Transport Layer 3-92
Summary TCP Congestion ControlWhen CongWin is below Threshold sender in slow-start phase window grows exponentiallyWhen CongWin is above Threshold sender is in congestion-avoidance phase window grows linearlyWhen a triple duplicate ACK occurs Threshold set to CongWin2 and CongWin set to ThresholdWhen timeout occurs Threshold set to CongWin2 and CongWin is set to 1 MSS The actual sender window size is determined based on the congestion and flow control algorithms
SenderWin=min(RcvWinCongWin)
Transport Layer 3-93
TCP Congestion Control SummaryEvent State TCP Sender Action Commentary
ACK receipt for previously unackeddata
Slow Start (SS)
CongWin = CongWin + MSS If (CongWin gt Threshold)
set state to ldquoCongestion Avoidancerdquo
Resulting in a doubling of CongWin every RTT
ACK receipt for previously unackeddata
CongestionAvoidance (CA)
CongWin = CongWin+MSS (MSSCongWin)
Additive increase resulting in increase of CongWin by 1 MSS every RTT
Loss event detected by triple duplicate ACK
SS or CA Threshold = CongWin2 CongWin = ThresholdSet state to ldquoCongestion Avoidancerdquo
Fast recovery implementing multiplicative decrease CongWin will not drop below 1 MSS
Timeout SS or CA Threshold = CongWin2 CongWin = 1 MSSSet state to ldquoSlow Startrdquo
Enter slow start
Duplicate ACK
SS or CA Increment duplicate ACK count for segment being acked
CongWin and Threshold not changed
Transport Layer 3-94
TCP throughput
Q whatrsquos average throughout of TCP as function of window size RTT
ignoring slow startlet W be window size when loss occurs
when window is W throughput is WRTTjust after loss window drops to W2 throughput to W2RTT average throughout 75 WRTT
Transport Layer 3-95
TCP Futures TCP over ldquolong fat pipesrdquo
example 1500 byte segments 100ms RTT want 10 Gbps throughputrequires window size W = 83333 in-flight segmentsthroughput in terms of loss rate
L = 210-10 Wownew versions of TCP for high-speed
LRTTMSSsdot221
Transport Layer 3-96
Fairness goal if K TCP sessions share same bottleneck link of bandwidth R each should have average rate of RK
TCP connection 1
bottleneckrouter
capacity R
TCP connection 2
TCP Fairness
Transport Layer 3-97
Why is TCP fairTwo competing sessions
Additive increase gives slope of 1 as throughout increasesmultiplicative decrease decreases throughput proportionally
R
R
equal bandwidth share
Connection 1 throughput
Conn
ecti
on 2
thr
ough
p ut
congestion avoidance additive increaseloss decrease window by factor of 2
congestion avoidance additive increaseloss decrease window by factor of 2
Transport Layer 3-98
Fairness (more)Fairness and UDP
Multimedia apps often do not use TCP
do not want rate throttled by congestion control
Instead use UDPpump audiovideo at constant rate tolerate packet loss
Research area TCP friendly
Fairness and parallel TCP connectionsnothing prevents app from opening parallel cnctionsbetween 2 hostsWeb browsers do this Example link of rate R supporting 9 cnctions
new app asks for 1 TCP gets rate R10new app asks for 11 TCPs gets R2
Transport Layer 3-99
TCP Connection ManagementRecall TCP sender receiver
establish ldquoconnectionrdquobefore exchanging data segmentsinitialize TCP variables
seq sbuffers flow control info (eg RcvWindow)
client connection initiatorSocket clientSocket = new Socket(hostnameport
number)
server contacted by clientSocket connectionSocket = welcomeSocketaccept()
Three way handshakeStep 1 client host sends TCP
SYN segment to serverspecifies initial seq no data
Step 2 server host receives SYN replies with SYNACK segment
server allocates buffersspecifies server initial seq
Step 3 client receives SYNACK replies with ACK segment which may contain data
Transport Layer 3-100
TCP Connection Management (cont)
Closing a connection
client closes socketclientSocketclose()
Step 1 client end system sends TCP FIN control segment to server
Step 2 server receives FIN replies with ACK Closes connection sends FIN
client
FIN
server
ACK
ACK
FIN
close
close
closed
tim
ed w
ait
Transport Layer 3-101
TCP Connection Management (cont)
Step 3 client receives FIN replies with ACK
Enters ldquotimed waitrdquo -will respond with ACK to received FINs
Step 4 server receives ACK Connection closed
client
FIN
server
ACK
ACK
FIN
closing
closing
closed
tim
ed w
ait
closed
Transport Layer 3-102
TCP Connection Management (cont)
TCP clientlifecycle
TCP serverlifecycle
Transport Layer 3-103
Tuning TCPIP Parameters TCPIP parameters
A set of default values may not be optimal for all applicationsThe network administrator may wish to turn on or off some TCPIP functions for performance or security considerations
Many Unix and Linux systems provide some flexibility in tuning the TCPIP kernelsbinsysctl is used to configure the Linux kernel parameters at runtime
Default kernel configuration file is sbinsysctlconfFrequently used sysctl options
bull sysctl ndasha or sysctl ndashA list all current valuesbull sysctl ndashp file_name load the sysctl setting from a configuration
filebull sysctl ndashw variable=value change the value of the parameter
Transport Layer 3-104
SomeTCP Parameters in Linux Kerneltcp_syn_retries
Number of SYN packets the kernel will send before giving up on the new connection
tcp_synack_retriesnumber of SYN+ACK packets sent before the kernel gives up on the connection
tcp_window_scalingMaximum window size of 65535 bytes not enough for for really fast networks The window scaling options allows for almost gigabyte windows which is good for connections with large delay-bandwidth product
tcp_max_syn_backlogMaximal number of remembered connection requests which still did not receive an acknowledgment from connecting client
tcp_fin_timeoutHow many seconds to wait for a final FIN packet before the socket is closed required to prevent denial-of-service (DoS) attacks Default value is 60 seconds
Transport Layer 3-105
SomeTCP Parameters in Linux Kerneltcp_rmem
This is a vector of 3 integers [min default max] These parameters are used by TCP to dynamically adjust receive buffer sizesmin - minimum size of the receive buffer used by each TCP socket The default value is 4K default - the default size of the receive buffer for a TCP socket The default value is 87380 bytes and is lowered to 43689 in low memory systems If larger receive buffer sizes are desired this value should be increased max - the maximum size of the receive buffer used by each TCP socket The default value of 873802 bytes is lowered to 87380 in low memory systems
tcp_smemSend buffer parameters [min default max] similar to tcp_rmem
- Chapter 3 Transport Layer
- Transport services and protocols
- Transport vs network layer
- Internet transport-layer protocols
- Multiplexingdemultiplexing
- How demultiplexing works
- Connectionless demultiplexing
- Connection-oriented demux
- Connection-oriented demux (cont)
- Connection-oriented demux Threaded Web Server
- UDP User Datagram Protocol [RFC 768]
- UDP more
- UDP checksum
- Principles of Reliable data transfer
- Reliable data transfer getting started
- Reliable data transfer getting started
- Rdt10 reliable transfer over a reliable channel
- Rdt20 channel with bit errors
- rdt20 FSM specification
- rdt20 operation with no errors
- rdt20 error scenario
- rdt20 has a fatal flaw
- rdt21 sender handles garbled ACKNAKs
- rdt21 receiver handles garbled ACKNAKs
- rdt21 discussion
- rdt22 a NAK-free protocol
- rdt22 sender receiver fragments
- rdt30 channels with errors and loss
- rdt30 sender
- rdt30 in action
- rdt30 in action
- Performance of rdt30
- rdt30 stop-and-wait operation
- Pipelined protocols
- Pipelining increased utilization
- Go-Back-N
- GBN sender extended FSM
- GBN receiver extended FSM
- GBN inaction
- Selective Repeat
- Selective repeat sender receiver windows
- Selective repeat
- Selective repeat in action
- Selective repeat dilemma
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- TCP Overview RFCs 793 1122 1323 2018 2581
- TCP segment structure
- TCP seq rsquos and ACKs
- TCP Round Trip Time and Timeout
- TCP Round Trip Time and Timeout
- Example RTT estimation
- TCP Round Trip Time and Timeout
- TCP reliable data transfer
- TCP sender events
- TCP sender(simplified)
- TCP retransmission scenarios
- TCP retransmission scenarios (more)
- TCP ACK generation [RFC 1122 RFC 2581]
- Fast Retransmit
- Fast Retransmit
- Fast retransmit algorithm
- TCP Flow Control
- TCP Flow control how it works
- Sliding Window Flow Control Example
- Principles of Congestion Control
- Causescosts of congestion scenario 1
- Causescosts of congestion scenario 2
- Causescosts of congestion scenario 2
- Causescosts of congestion scenario 3
- Causescosts of congestion scenario 3
- Approaches towards congestion control
- TCP Congestion Control
- TCP congestion control bandwidth probing
- TCP Congestion Control details
- TCP Congestion Control more details
- TCP Slow Start Phase
- Slow Start Example
- TCP Congestion Avoidance Phase
- Congestion Avoidance
- Example Slow StartCongestion Avoidance
- Slow Start Congestion Avoidance
- Responses to Congestion
- Fast Recovery (differentiation btwn two loss events)
- TCP Congestion Control
- Popular ldquoflavorsrdquo of TCP
- Summary TCP Congestion Control
- TCP Congestion Control Summary
- TCP throughput
- TCP Futures TCP over ldquolong fat pipesrdquo
- TCP Fairness
- Why is TCP fair
- Fairness (more)
- TCP Connection Management
- TCP Connection Management (cont)
- TCP Connection Management (cont)
- TCP Connection Management (cont)
- Tuning TCPIP Parameters
- SomeTCP Parameters in Linux Kernel
- SomeTCP Parameters in Linux Kernel
-
Transport Layer 3-83
Slow Start ExampleThe congestion window size grows very rapidly
For every ACK we increase CongWin by 1 irrespective of the number of segments ACKrsquoeddouble CongWinevery RTTinitial rate is slow but ramps up exponentially fast
TCP slows down the increase of CongWinwhen CongWin gt ssthresh
segment 1
ACK for segment 1
cwnd = 1
cwnd = 2 segment 2segment 3
ACK for segments 2
cwnd = 4 segment 4segment 5segment 6
ACK for segments 4
cwnd = 7
ACK for segments 3
ACK for segments 5
ACK for segments 6
cwnd = 3
cwnd = 5
cwnd = 6ACK for segments 7
cwnd = 8
segment 7
Transport Layer 3-84
TCP Congestion Avoidance Phase
when cwnd gt ssthreshgrow cwnd linearly
increase cwnd by 1 MSS per RTT approach possible congestion slower than in slowstartimplementation cwnd= cwnd + MSScwndfor each ACK received
ACKs increase cwndby 1 MSS per RTT additive increaseloss cut cwnd in half (non-timeout-detected loss ) multiplicative decrease
AIMD
AIMD Additive IncreaseMultiplicative Decrease
Transport Layer 3-85
Congestion AvoidanceCongestion avoidance phase is started if CongWin has reached the slow-start threshold value
If CongWin gt= ssthresh then each time an ACK is received increment CongWin as follows
bull CongWin = CongWin + 1CongWin (CongWin in segments)
bull In actual TCP implementation CongWin is in BytesCongWin = CongWin + MSS (MSSCongWin)
So CongWin is increased by one only if all CongWinsegments have been acknowledged
Transport Layer 3-86
Example Slow StartCongestion AvoidanceAssume that
ssthresh = 8
cwnd = 1
cwnd = 2
cwnd = 4
cwnd = 8
cwnd = 9
cwnd = 10
02468
101214
t=0
t=2
t=4
t=6
Roundtrip times
Cw
nd(in
seg
men
ts)
ssthresh
cwnd = 3
cwnd = 5cwnd = 6cwnd = 7
Transport Layer 3-87
Slow Start Congestion AvoidanceA typical plot of CongWin for a TCP connection
(MSS = 1500 bytes) with TCP Tahoe
SS
CA
ssthresh
Transport Layer 3-88
Responses to CongestionTCP assumes there is congestion if it detects a packet lossA TCP sender can detect lost packets via loss events
bull Timeout of a retransmission timerbull Receipt of 3 duplicate ACKs (fast retransmit)
TCP interprets a Timeout as a binary congestion signal When a timeout occurs the sender performs
ssthresh is set to half the current size of the congestion window
ssthresh = CongWin 2CongWin is reset to one
CongWin = 1and slow-start is entered
Transport Layer 3-89
Fast Recovery (differentiation btwn two loss events) After 3 dup ACKs (fast Retransmit)
ssthresh = CongWin2CongWin = CongWin2window then grows linearly
But after timeout eventCongWin = 1 MSS window then grows exponentiallyto the threshold then grows linearly
bull 3 dup ACKs indicates network capable of delivering some segmentsbull timeout before 3 dup ACKs is ldquomore alarmingrdquo
Philosophy
3-90
TCP Congestion ControlInitially
CongWin = 1ssthresh = advertised window size
New Ack receivedif (CongWin lt ssthresh) Slow Start
CongWin = CongWin + 1else Congestion Avoidance
CongWin = CongWin + 1CongWinTimeout
ssthresh = CongWin2CongWin = 1
Fast Retransmissionssthresh = CongWin2CongWin = CongWin2
Slow Start (exponential increase phase) is continued until CongWin reaches half of the level where the loss event occurred last time CongWin is increased slowly after (linear increase in Congestion Avoidance phase)
Transport Layer 3-91
Popular ldquoflavorsrdquo of TCP
ssthresh
ssthresh
TCP Tahoe
TCP Reno
Transmission round
cwnd
win
dow
siz
e (in
seg
men
ts)
Transport Layer 3-92
Summary TCP Congestion ControlWhen CongWin is below Threshold sender in slow-start phase window grows exponentiallyWhen CongWin is above Threshold sender is in congestion-avoidance phase window grows linearlyWhen a triple duplicate ACK occurs Threshold set to CongWin2 and CongWin set to ThresholdWhen timeout occurs Threshold set to CongWin2 and CongWin is set to 1 MSS The actual sender window size is determined based on the congestion and flow control algorithms
SenderWin=min(RcvWinCongWin)
Transport Layer 3-93
TCP Congestion Control SummaryEvent State TCP Sender Action Commentary
ACK receipt for previously unackeddata
Slow Start (SS)
CongWin = CongWin + MSS If (CongWin gt Threshold)
set state to ldquoCongestion Avoidancerdquo
Resulting in a doubling of CongWin every RTT
ACK receipt for previously unackeddata
CongestionAvoidance (CA)
CongWin = CongWin+MSS (MSSCongWin)
Additive increase resulting in increase of CongWin by 1 MSS every RTT
Loss event detected by triple duplicate ACK
SS or CA Threshold = CongWin2 CongWin = ThresholdSet state to ldquoCongestion Avoidancerdquo
Fast recovery implementing multiplicative decrease CongWin will not drop below 1 MSS
Timeout SS or CA Threshold = CongWin2 CongWin = 1 MSSSet state to ldquoSlow Startrdquo
Enter slow start
Duplicate ACK
SS or CA Increment duplicate ACK count for segment being acked
CongWin and Threshold not changed
Transport Layer 3-94
TCP throughput
Q whatrsquos average throughout of TCP as function of window size RTT
ignoring slow startlet W be window size when loss occurs
when window is W throughput is WRTTjust after loss window drops to W2 throughput to W2RTT average throughout 75 WRTT
Transport Layer 3-95
TCP Futures TCP over ldquolong fat pipesrdquo
example 1500 byte segments 100ms RTT want 10 Gbps throughputrequires window size W = 83333 in-flight segmentsthroughput in terms of loss rate
L = 210-10 Wownew versions of TCP for high-speed
LRTTMSSsdot221
Transport Layer 3-96
Fairness goal if K TCP sessions share same bottleneck link of bandwidth R each should have average rate of RK
TCP connection 1
bottleneckrouter
capacity R
TCP connection 2
TCP Fairness
Transport Layer 3-97
Why is TCP fairTwo competing sessions
Additive increase gives slope of 1 as throughout increasesmultiplicative decrease decreases throughput proportionally
R
R
equal bandwidth share
Connection 1 throughput
Conn
ecti
on 2
thr
ough
p ut
congestion avoidance additive increaseloss decrease window by factor of 2
congestion avoidance additive increaseloss decrease window by factor of 2
Transport Layer 3-98
Fairness (more)Fairness and UDP
Multimedia apps often do not use TCP
do not want rate throttled by congestion control
Instead use UDPpump audiovideo at constant rate tolerate packet loss
Research area TCP friendly
Fairness and parallel TCP connectionsnothing prevents app from opening parallel cnctionsbetween 2 hostsWeb browsers do this Example link of rate R supporting 9 cnctions
new app asks for 1 TCP gets rate R10new app asks for 11 TCPs gets R2
Transport Layer 3-99
TCP Connection ManagementRecall TCP sender receiver
establish ldquoconnectionrdquobefore exchanging data segmentsinitialize TCP variables
seq sbuffers flow control info (eg RcvWindow)
client connection initiatorSocket clientSocket = new Socket(hostnameport
number)
server contacted by clientSocket connectionSocket = welcomeSocketaccept()
Three way handshakeStep 1 client host sends TCP
SYN segment to serverspecifies initial seq no data
Step 2 server host receives SYN replies with SYNACK segment
server allocates buffersspecifies server initial seq
Step 3 client receives SYNACK replies with ACK segment which may contain data
Transport Layer 3-100
TCP Connection Management (cont)
Closing a connection
client closes socketclientSocketclose()
Step 1 client end system sends TCP FIN control segment to server
Step 2 server receives FIN replies with ACK Closes connection sends FIN
client
FIN
server
ACK
ACK
FIN
close
close
closed
tim
ed w
ait
Transport Layer 3-101
TCP Connection Management (cont)
Step 3 client receives FIN replies with ACK
Enters ldquotimed waitrdquo -will respond with ACK to received FINs
Step 4 server receives ACK Connection closed
client
FIN
server
ACK
ACK
FIN
closing
closing
closed
tim
ed w
ait
closed
Transport Layer 3-102
TCP Connection Management (cont)
TCP clientlifecycle
TCP serverlifecycle
Transport Layer 3-103
Tuning TCPIP Parameters TCPIP parameters
A set of default values may not be optimal for all applicationsThe network administrator may wish to turn on or off some TCPIP functions for performance or security considerations
Many Unix and Linux systems provide some flexibility in tuning the TCPIP kernelsbinsysctl is used to configure the Linux kernel parameters at runtime
Default kernel configuration file is sbinsysctlconfFrequently used sysctl options
bull sysctl ndasha or sysctl ndashA list all current valuesbull sysctl ndashp file_name load the sysctl setting from a configuration
filebull sysctl ndashw variable=value change the value of the parameter
Transport Layer 3-104
SomeTCP Parameters in Linux Kerneltcp_syn_retries
Number of SYN packets the kernel will send before giving up on the new connection
tcp_synack_retriesnumber of SYN+ACK packets sent before the kernel gives up on the connection
tcp_window_scalingMaximum window size of 65535 bytes not enough for for really fast networks The window scaling options allows for almost gigabyte windows which is good for connections with large delay-bandwidth product
tcp_max_syn_backlogMaximal number of remembered connection requests which still did not receive an acknowledgment from connecting client
tcp_fin_timeoutHow many seconds to wait for a final FIN packet before the socket is closed required to prevent denial-of-service (DoS) attacks Default value is 60 seconds
Transport Layer 3-105
SomeTCP Parameters in Linux Kerneltcp_rmem
This is a vector of 3 integers [min default max] These parameters are used by TCP to dynamically adjust receive buffer sizesmin - minimum size of the receive buffer used by each TCP socket The default value is 4K default - the default size of the receive buffer for a TCP socket The default value is 87380 bytes and is lowered to 43689 in low memory systems If larger receive buffer sizes are desired this value should be increased max - the maximum size of the receive buffer used by each TCP socket The default value of 873802 bytes is lowered to 87380 in low memory systems
tcp_smemSend buffer parameters [min default max] similar to tcp_rmem
- Chapter 3 Transport Layer
- Transport services and protocols
- Transport vs network layer
- Internet transport-layer protocols
- Multiplexingdemultiplexing
- How demultiplexing works
- Connectionless demultiplexing
- Connection-oriented demux
- Connection-oriented demux (cont)
- Connection-oriented demux Threaded Web Server
- UDP User Datagram Protocol [RFC 768]
- UDP more
- UDP checksum
- Principles of Reliable data transfer
- Reliable data transfer getting started
- Reliable data transfer getting started
- Rdt10 reliable transfer over a reliable channel
- Rdt20 channel with bit errors
- rdt20 FSM specification
- rdt20 operation with no errors
- rdt20 error scenario
- rdt20 has a fatal flaw
- rdt21 sender handles garbled ACKNAKs
- rdt21 receiver handles garbled ACKNAKs
- rdt21 discussion
- rdt22 a NAK-free protocol
- rdt22 sender receiver fragments
- rdt30 channels with errors and loss
- rdt30 sender
- rdt30 in action
- rdt30 in action
- Performance of rdt30
- rdt30 stop-and-wait operation
- Pipelined protocols
- Pipelining increased utilization
- Go-Back-N
- GBN sender extended FSM
- GBN receiver extended FSM
- GBN inaction
- Selective Repeat
- Selective repeat sender receiver windows
- Selective repeat
- Selective repeat in action
- Selective repeat dilemma
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- TCP Overview RFCs 793 1122 1323 2018 2581
- TCP segment structure
- TCP seq rsquos and ACKs
- TCP Round Trip Time and Timeout
- TCP Round Trip Time and Timeout
- Example RTT estimation
- TCP Round Trip Time and Timeout
- TCP reliable data transfer
- TCP sender events
- TCP sender(simplified)
- TCP retransmission scenarios
- TCP retransmission scenarios (more)
- TCP ACK generation [RFC 1122 RFC 2581]
- Fast Retransmit
- Fast Retransmit
- Fast retransmit algorithm
- TCP Flow Control
- TCP Flow control how it works
- Sliding Window Flow Control Example
- Principles of Congestion Control
- Causescosts of congestion scenario 1
- Causescosts of congestion scenario 2
- Causescosts of congestion scenario 2
- Causescosts of congestion scenario 3
- Causescosts of congestion scenario 3
- Approaches towards congestion control
- TCP Congestion Control
- TCP congestion control bandwidth probing
- TCP Congestion Control details
- TCP Congestion Control more details
- TCP Slow Start Phase
- Slow Start Example
- TCP Congestion Avoidance Phase
- Congestion Avoidance
- Example Slow StartCongestion Avoidance
- Slow Start Congestion Avoidance
- Responses to Congestion
- Fast Recovery (differentiation btwn two loss events)
- TCP Congestion Control
- Popular ldquoflavorsrdquo of TCP
- Summary TCP Congestion Control
- TCP Congestion Control Summary
- TCP throughput
- TCP Futures TCP over ldquolong fat pipesrdquo
- TCP Fairness
- Why is TCP fair
- Fairness (more)
- TCP Connection Management
- TCP Connection Management (cont)
- TCP Connection Management (cont)
- TCP Connection Management (cont)
- Tuning TCPIP Parameters
- SomeTCP Parameters in Linux Kernel
- SomeTCP Parameters in Linux Kernel
-
Transport Layer 3-84
TCP Congestion Avoidance Phase
when cwnd gt ssthreshgrow cwnd linearly
increase cwnd by 1 MSS per RTT approach possible congestion slower than in slowstartimplementation cwnd= cwnd + MSScwndfor each ACK received
ACKs increase cwndby 1 MSS per RTT additive increaseloss cut cwnd in half (non-timeout-detected loss ) multiplicative decrease
AIMD
AIMD Additive IncreaseMultiplicative Decrease
Transport Layer 3-85
Congestion AvoidanceCongestion avoidance phase is started if CongWin has reached the slow-start threshold value
If CongWin gt= ssthresh then each time an ACK is received increment CongWin as follows
bull CongWin = CongWin + 1CongWin (CongWin in segments)
bull In actual TCP implementation CongWin is in BytesCongWin = CongWin + MSS (MSSCongWin)
So CongWin is increased by one only if all CongWinsegments have been acknowledged
Transport Layer 3-86
Example Slow StartCongestion AvoidanceAssume that
ssthresh = 8
cwnd = 1
cwnd = 2
cwnd = 4
cwnd = 8
cwnd = 9
cwnd = 10
02468
101214
t=0
t=2
t=4
t=6
Roundtrip times
Cw
nd(in
seg
men
ts)
ssthresh
cwnd = 3
cwnd = 5cwnd = 6cwnd = 7
Transport Layer 3-87
Slow Start Congestion AvoidanceA typical plot of CongWin for a TCP connection
(MSS = 1500 bytes) with TCP Tahoe
SS
CA
ssthresh
Transport Layer 3-88
Responses to CongestionTCP assumes there is congestion if it detects a packet lossA TCP sender can detect lost packets via loss events
bull Timeout of a retransmission timerbull Receipt of 3 duplicate ACKs (fast retransmit)
TCP interprets a Timeout as a binary congestion signal When a timeout occurs the sender performs
ssthresh is set to half the current size of the congestion window
ssthresh = CongWin 2CongWin is reset to one
CongWin = 1and slow-start is entered
Transport Layer 3-89
Fast Recovery (differentiation btwn two loss events) After 3 dup ACKs (fast Retransmit)
ssthresh = CongWin2CongWin = CongWin2window then grows linearly
But after timeout eventCongWin = 1 MSS window then grows exponentiallyto the threshold then grows linearly
bull 3 dup ACKs indicates network capable of delivering some segmentsbull timeout before 3 dup ACKs is ldquomore alarmingrdquo
Philosophy
3-90
TCP Congestion ControlInitially
CongWin = 1ssthresh = advertised window size
New Ack receivedif (CongWin lt ssthresh) Slow Start
CongWin = CongWin + 1else Congestion Avoidance
CongWin = CongWin + 1CongWinTimeout
ssthresh = CongWin2CongWin = 1
Fast Retransmissionssthresh = CongWin2CongWin = CongWin2
Slow Start (exponential increase phase) is continued until CongWin reaches half of the level where the loss event occurred last time CongWin is increased slowly after (linear increase in Congestion Avoidance phase)
Transport Layer 3-91
Popular ldquoflavorsrdquo of TCP
ssthresh
ssthresh
TCP Tahoe
TCP Reno
Transmission round
cwnd
win
dow
siz
e (in
seg
men
ts)
Transport Layer 3-92
Summary TCP Congestion ControlWhen CongWin is below Threshold sender in slow-start phase window grows exponentiallyWhen CongWin is above Threshold sender is in congestion-avoidance phase window grows linearlyWhen a triple duplicate ACK occurs Threshold set to CongWin2 and CongWin set to ThresholdWhen timeout occurs Threshold set to CongWin2 and CongWin is set to 1 MSS The actual sender window size is determined based on the congestion and flow control algorithms
SenderWin=min(RcvWinCongWin)
Transport Layer 3-93
TCP Congestion Control SummaryEvent State TCP Sender Action Commentary
ACK receipt for previously unackeddata
Slow Start (SS)
CongWin = CongWin + MSS If (CongWin gt Threshold)
set state to ldquoCongestion Avoidancerdquo
Resulting in a doubling of CongWin every RTT
ACK receipt for previously unackeddata
CongestionAvoidance (CA)
CongWin = CongWin+MSS (MSSCongWin)
Additive increase resulting in increase of CongWin by 1 MSS every RTT
Loss event detected by triple duplicate ACK
SS or CA Threshold = CongWin2 CongWin = ThresholdSet state to ldquoCongestion Avoidancerdquo
Fast recovery implementing multiplicative decrease CongWin will not drop below 1 MSS
Timeout SS or CA Threshold = CongWin2 CongWin = 1 MSSSet state to ldquoSlow Startrdquo
Enter slow start
Duplicate ACK
SS or CA Increment duplicate ACK count for segment being acked
CongWin and Threshold not changed
Transport Layer 3-94
TCP throughput
Q whatrsquos average throughout of TCP as function of window size RTT
ignoring slow startlet W be window size when loss occurs
when window is W throughput is WRTTjust after loss window drops to W2 throughput to W2RTT average throughout 75 WRTT
Transport Layer 3-95
TCP Futures TCP over ldquolong fat pipesrdquo
example 1500 byte segments 100ms RTT want 10 Gbps throughputrequires window size W = 83333 in-flight segmentsthroughput in terms of loss rate
L = 210-10 Wownew versions of TCP for high-speed
LRTTMSSsdot221
Transport Layer 3-96
Fairness goal if K TCP sessions share same bottleneck link of bandwidth R each should have average rate of RK
TCP connection 1
bottleneckrouter
capacity R
TCP connection 2
TCP Fairness
Transport Layer 3-97
Why is TCP fairTwo competing sessions
Additive increase gives slope of 1 as throughout increasesmultiplicative decrease decreases throughput proportionally
R
R
equal bandwidth share
Connection 1 throughput
Conn
ecti
on 2
thr
ough
p ut
congestion avoidance additive increaseloss decrease window by factor of 2
congestion avoidance additive increaseloss decrease window by factor of 2
Transport Layer 3-98
Fairness (more)Fairness and UDP
Multimedia apps often do not use TCP
do not want rate throttled by congestion control
Instead use UDPpump audiovideo at constant rate tolerate packet loss
Research area TCP friendly
Fairness and parallel TCP connectionsnothing prevents app from opening parallel cnctionsbetween 2 hostsWeb browsers do this Example link of rate R supporting 9 cnctions
new app asks for 1 TCP gets rate R10new app asks for 11 TCPs gets R2
Transport Layer 3-99
TCP Connection ManagementRecall TCP sender receiver
establish ldquoconnectionrdquobefore exchanging data segmentsinitialize TCP variables
seq sbuffers flow control info (eg RcvWindow)
client connection initiatorSocket clientSocket = new Socket(hostnameport
number)
server contacted by clientSocket connectionSocket = welcomeSocketaccept()
Three way handshakeStep 1 client host sends TCP
SYN segment to serverspecifies initial seq no data
Step 2 server host receives SYN replies with SYNACK segment
server allocates buffersspecifies server initial seq
Step 3 client receives SYNACK replies with ACK segment which may contain data
Transport Layer 3-100
TCP Connection Management (cont)
Closing a connection
client closes socketclientSocketclose()
Step 1 client end system sends TCP FIN control segment to server
Step 2 server receives FIN replies with ACK Closes connection sends FIN
client
FIN
server
ACK
ACK
FIN
close
close
closed
tim
ed w
ait
Transport Layer 3-101
TCP Connection Management (cont)
Step 3 client receives FIN replies with ACK
Enters ldquotimed waitrdquo -will respond with ACK to received FINs
Step 4 server receives ACK Connection closed
client
FIN
server
ACK
ACK
FIN
closing
closing
closed
tim
ed w
ait
closed
Transport Layer 3-102
TCP Connection Management (cont)
TCP clientlifecycle
TCP serverlifecycle
Transport Layer 3-103
Tuning TCPIP Parameters TCPIP parameters
A set of default values may not be optimal for all applicationsThe network administrator may wish to turn on or off some TCPIP functions for performance or security considerations
Many Unix and Linux systems provide some flexibility in tuning the TCPIP kernelsbinsysctl is used to configure the Linux kernel parameters at runtime
Default kernel configuration file is sbinsysctlconfFrequently used sysctl options
bull sysctl ndasha or sysctl ndashA list all current valuesbull sysctl ndashp file_name load the sysctl setting from a configuration
filebull sysctl ndashw variable=value change the value of the parameter
Transport Layer 3-104
SomeTCP Parameters in Linux Kerneltcp_syn_retries
Number of SYN packets the kernel will send before giving up on the new connection
tcp_synack_retriesnumber of SYN+ACK packets sent before the kernel gives up on the connection
tcp_window_scalingMaximum window size of 65535 bytes not enough for for really fast networks The window scaling options allows for almost gigabyte windows which is good for connections with large delay-bandwidth product
tcp_max_syn_backlogMaximal number of remembered connection requests which still did not receive an acknowledgment from connecting client
tcp_fin_timeoutHow many seconds to wait for a final FIN packet before the socket is closed required to prevent denial-of-service (DoS) attacks Default value is 60 seconds
Transport Layer 3-105
SomeTCP Parameters in Linux Kerneltcp_rmem
This is a vector of 3 integers [min default max] These parameters are used by TCP to dynamically adjust receive buffer sizesmin - minimum size of the receive buffer used by each TCP socket The default value is 4K default - the default size of the receive buffer for a TCP socket The default value is 87380 bytes and is lowered to 43689 in low memory systems If larger receive buffer sizes are desired this value should be increased max - the maximum size of the receive buffer used by each TCP socket The default value of 873802 bytes is lowered to 87380 in low memory systems
tcp_smemSend buffer parameters [min default max] similar to tcp_rmem
- Chapter 3 Transport Layer
- Transport services and protocols
- Transport vs network layer
- Internet transport-layer protocols
- Multiplexingdemultiplexing
- How demultiplexing works
- Connectionless demultiplexing
- Connection-oriented demux
- Connection-oriented demux (cont)
- Connection-oriented demux Threaded Web Server
- UDP User Datagram Protocol [RFC 768]
- UDP more
- UDP checksum
- Principles of Reliable data transfer
- Reliable data transfer getting started
- Reliable data transfer getting started
- Rdt10 reliable transfer over a reliable channel
- Rdt20 channel with bit errors
- rdt20 FSM specification
- rdt20 operation with no errors
- rdt20 error scenario
- rdt20 has a fatal flaw
- rdt21 sender handles garbled ACKNAKs
- rdt21 receiver handles garbled ACKNAKs
- rdt21 discussion
- rdt22 a NAK-free protocol
- rdt22 sender receiver fragments
- rdt30 channels with errors and loss
- rdt30 sender
- rdt30 in action
- rdt30 in action
- Performance of rdt30
- rdt30 stop-and-wait operation
- Pipelined protocols
- Pipelining increased utilization
- Go-Back-N
- GBN sender extended FSM
- GBN receiver extended FSM
- GBN inaction
- Selective Repeat
- Selective repeat sender receiver windows
- Selective repeat
- Selective repeat in action
- Selective repeat dilemma
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- TCP Overview RFCs 793 1122 1323 2018 2581
- TCP segment structure
- TCP seq rsquos and ACKs
- TCP Round Trip Time and Timeout
- TCP Round Trip Time and Timeout
- Example RTT estimation
- TCP Round Trip Time and Timeout
- TCP reliable data transfer
- TCP sender events
- TCP sender(simplified)
- TCP retransmission scenarios
- TCP retransmission scenarios (more)
- TCP ACK generation [RFC 1122 RFC 2581]
- Fast Retransmit
- Fast Retransmit
- Fast retransmit algorithm
- TCP Flow Control
- TCP Flow control how it works
- Sliding Window Flow Control Example
- Principles of Congestion Control
- Causescosts of congestion scenario 1
- Causescosts of congestion scenario 2
- Causescosts of congestion scenario 2
- Causescosts of congestion scenario 3
- Causescosts of congestion scenario 3
- Approaches towards congestion control
- TCP Congestion Control
- TCP congestion control bandwidth probing
- TCP Congestion Control details
- TCP Congestion Control more details
- TCP Slow Start Phase
- Slow Start Example
- TCP Congestion Avoidance Phase
- Congestion Avoidance
- Example Slow StartCongestion Avoidance
- Slow Start Congestion Avoidance
- Responses to Congestion
- Fast Recovery (differentiation btwn two loss events)
- TCP Congestion Control
- Popular ldquoflavorsrdquo of TCP
- Summary TCP Congestion Control
- TCP Congestion Control Summary
- TCP throughput
- TCP Futures TCP over ldquolong fat pipesrdquo
- TCP Fairness
- Why is TCP fair
- Fairness (more)
- TCP Connection Management
- TCP Connection Management (cont)
- TCP Connection Management (cont)
- TCP Connection Management (cont)
- Tuning TCPIP Parameters
- SomeTCP Parameters in Linux Kernel
- SomeTCP Parameters in Linux Kernel
-
Transport Layer 3-85
Congestion AvoidanceCongestion avoidance phase is started if CongWin has reached the slow-start threshold value
If CongWin gt= ssthresh then each time an ACK is received increment CongWin as follows
bull CongWin = CongWin + 1CongWin (CongWin in segments)
bull In actual TCP implementation CongWin is in BytesCongWin = CongWin + MSS (MSSCongWin)
So CongWin is increased by one only if all CongWinsegments have been acknowledged
Transport Layer 3-86
Example Slow StartCongestion AvoidanceAssume that
ssthresh = 8
cwnd = 1
cwnd = 2
cwnd = 4
cwnd = 8
cwnd = 9
cwnd = 10
02468
101214
t=0
t=2
t=4
t=6
Roundtrip times
Cw
nd(in
seg
men
ts)
ssthresh
cwnd = 3
cwnd = 5cwnd = 6cwnd = 7
Transport Layer 3-87
Slow Start Congestion AvoidanceA typical plot of CongWin for a TCP connection
(MSS = 1500 bytes) with TCP Tahoe
SS
CA
ssthresh
Transport Layer 3-88
Responses to CongestionTCP assumes there is congestion if it detects a packet lossA TCP sender can detect lost packets via loss events
bull Timeout of a retransmission timerbull Receipt of 3 duplicate ACKs (fast retransmit)
TCP interprets a Timeout as a binary congestion signal When a timeout occurs the sender performs
ssthresh is set to half the current size of the congestion window
ssthresh = CongWin 2CongWin is reset to one
CongWin = 1and slow-start is entered
Transport Layer 3-89
Fast Recovery (differentiation btwn two loss events) After 3 dup ACKs (fast Retransmit)
ssthresh = CongWin2CongWin = CongWin2window then grows linearly
But after timeout eventCongWin = 1 MSS window then grows exponentiallyto the threshold then grows linearly
bull 3 dup ACKs indicates network capable of delivering some segmentsbull timeout before 3 dup ACKs is ldquomore alarmingrdquo
Philosophy
3-90
TCP Congestion ControlInitially
CongWin = 1ssthresh = advertised window size
New Ack receivedif (CongWin lt ssthresh) Slow Start
CongWin = CongWin + 1else Congestion Avoidance
CongWin = CongWin + 1CongWinTimeout
ssthresh = CongWin2CongWin = 1
Fast Retransmissionssthresh = CongWin2CongWin = CongWin2
Slow Start (exponential increase phase) is continued until CongWin reaches half of the level where the loss event occurred last time CongWin is increased slowly after (linear increase in Congestion Avoidance phase)
Transport Layer 3-91
Popular ldquoflavorsrdquo of TCP
ssthresh
ssthresh
TCP Tahoe
TCP Reno
Transmission round
cwnd
win
dow
siz
e (in
seg
men
ts)
Transport Layer 3-92
Summary TCP Congestion ControlWhen CongWin is below Threshold sender in slow-start phase window grows exponentiallyWhen CongWin is above Threshold sender is in congestion-avoidance phase window grows linearlyWhen a triple duplicate ACK occurs Threshold set to CongWin2 and CongWin set to ThresholdWhen timeout occurs Threshold set to CongWin2 and CongWin is set to 1 MSS The actual sender window size is determined based on the congestion and flow control algorithms
SenderWin=min(RcvWinCongWin)
Transport Layer 3-93
TCP Congestion Control SummaryEvent State TCP Sender Action Commentary
ACK receipt for previously unackeddata
Slow Start (SS)
CongWin = CongWin + MSS If (CongWin gt Threshold)
set state to ldquoCongestion Avoidancerdquo
Resulting in a doubling of CongWin every RTT
ACK receipt for previously unackeddata
CongestionAvoidance (CA)
CongWin = CongWin+MSS (MSSCongWin)
Additive increase resulting in increase of CongWin by 1 MSS every RTT
Loss event detected by triple duplicate ACK
SS or CA Threshold = CongWin2 CongWin = ThresholdSet state to ldquoCongestion Avoidancerdquo
Fast recovery implementing multiplicative decrease CongWin will not drop below 1 MSS
Timeout SS or CA Threshold = CongWin2 CongWin = 1 MSSSet state to ldquoSlow Startrdquo
Enter slow start
Duplicate ACK
SS or CA Increment duplicate ACK count for segment being acked
CongWin and Threshold not changed
Transport Layer 3-94
TCP throughput
Q whatrsquos average throughout of TCP as function of window size RTT
ignoring slow startlet W be window size when loss occurs
when window is W throughput is WRTTjust after loss window drops to W2 throughput to W2RTT average throughout 75 WRTT
Transport Layer 3-95
TCP Futures TCP over ldquolong fat pipesrdquo
example 1500 byte segments 100ms RTT want 10 Gbps throughputrequires window size W = 83333 in-flight segmentsthroughput in terms of loss rate
L = 210-10 Wownew versions of TCP for high-speed
LRTTMSSsdot221
Transport Layer 3-96
Fairness goal if K TCP sessions share same bottleneck link of bandwidth R each should have average rate of RK
TCP connection 1
bottleneckrouter
capacity R
TCP connection 2
TCP Fairness
Transport Layer 3-97
Why is TCP fairTwo competing sessions
Additive increase gives slope of 1 as throughout increasesmultiplicative decrease decreases throughput proportionally
R
R
equal bandwidth share
Connection 1 throughput
Conn
ecti
on 2
thr
ough
p ut
congestion avoidance additive increaseloss decrease window by factor of 2
congestion avoidance additive increaseloss decrease window by factor of 2
Transport Layer 3-98
Fairness (more)Fairness and UDP
Multimedia apps often do not use TCP
do not want rate throttled by congestion control
Instead use UDPpump audiovideo at constant rate tolerate packet loss
Research area TCP friendly
Fairness and parallel TCP connectionsnothing prevents app from opening parallel cnctionsbetween 2 hostsWeb browsers do this Example link of rate R supporting 9 cnctions
new app asks for 1 TCP gets rate R10new app asks for 11 TCPs gets R2
Transport Layer 3-99
TCP Connection ManagementRecall TCP sender receiver
establish ldquoconnectionrdquobefore exchanging data segmentsinitialize TCP variables
seq sbuffers flow control info (eg RcvWindow)
client connection initiatorSocket clientSocket = new Socket(hostnameport
number)
server contacted by clientSocket connectionSocket = welcomeSocketaccept()
Three way handshakeStep 1 client host sends TCP
SYN segment to serverspecifies initial seq no data
Step 2 server host receives SYN replies with SYNACK segment
server allocates buffersspecifies server initial seq
Step 3 client receives SYNACK replies with ACK segment which may contain data
Transport Layer 3-100
TCP Connection Management (cont)
Closing a connection
client closes socketclientSocketclose()
Step 1 client end system sends TCP FIN control segment to server
Step 2 server receives FIN replies with ACK Closes connection sends FIN
client
FIN
server
ACK
ACK
FIN
close
close
closed
tim
ed w
ait
Transport Layer 3-101
TCP Connection Management (cont)
Step 3 client receives FIN replies with ACK
Enters ldquotimed waitrdquo -will respond with ACK to received FINs
Step 4 server receives ACK Connection closed
client
FIN
server
ACK
ACK
FIN
closing
closing
closed
tim
ed w
ait
closed
Transport Layer 3-102
TCP Connection Management (cont)
TCP clientlifecycle
TCP serverlifecycle
Transport Layer 3-103
Tuning TCPIP Parameters TCPIP parameters
A set of default values may not be optimal for all applicationsThe network administrator may wish to turn on or off some TCPIP functions for performance or security considerations
Many Unix and Linux systems provide some flexibility in tuning the TCPIP kernelsbinsysctl is used to configure the Linux kernel parameters at runtime
Default kernel configuration file is sbinsysctlconfFrequently used sysctl options
bull sysctl ndasha or sysctl ndashA list all current valuesbull sysctl ndashp file_name load the sysctl setting from a configuration
filebull sysctl ndashw variable=value change the value of the parameter
Transport Layer 3-104
SomeTCP Parameters in Linux Kerneltcp_syn_retries
Number of SYN packets the kernel will send before giving up on the new connection
tcp_synack_retriesnumber of SYN+ACK packets sent before the kernel gives up on the connection
tcp_window_scalingMaximum window size of 65535 bytes not enough for for really fast networks The window scaling options allows for almost gigabyte windows which is good for connections with large delay-bandwidth product
tcp_max_syn_backlogMaximal number of remembered connection requests which still did not receive an acknowledgment from connecting client
tcp_fin_timeoutHow many seconds to wait for a final FIN packet before the socket is closed required to prevent denial-of-service (DoS) attacks Default value is 60 seconds
Transport Layer 3-105
SomeTCP Parameters in Linux Kerneltcp_rmem
This is a vector of 3 integers [min default max] These parameters are used by TCP to dynamically adjust receive buffer sizesmin - minimum size of the receive buffer used by each TCP socket The default value is 4K default - the default size of the receive buffer for a TCP socket The default value is 87380 bytes and is lowered to 43689 in low memory systems If larger receive buffer sizes are desired this value should be increased max - the maximum size of the receive buffer used by each TCP socket The default value of 873802 bytes is lowered to 87380 in low memory systems
tcp_smemSend buffer parameters [min default max] similar to tcp_rmem
- Chapter 3 Transport Layer
- Transport services and protocols
- Transport vs network layer
- Internet transport-layer protocols
- Multiplexingdemultiplexing
- How demultiplexing works
- Connectionless demultiplexing
- Connection-oriented demux
- Connection-oriented demux (cont)
- Connection-oriented demux Threaded Web Server
- UDP User Datagram Protocol [RFC 768]
- UDP more
- UDP checksum
- Principles of Reliable data transfer
- Reliable data transfer getting started
- Reliable data transfer getting started
- Rdt10 reliable transfer over a reliable channel
- Rdt20 channel with bit errors
- rdt20 FSM specification
- rdt20 operation with no errors
- rdt20 error scenario
- rdt20 has a fatal flaw
- rdt21 sender handles garbled ACKNAKs
- rdt21 receiver handles garbled ACKNAKs
- rdt21 discussion
- rdt22 a NAK-free protocol
- rdt22 sender receiver fragments
- rdt30 channels with errors and loss
- rdt30 sender
- rdt30 in action
- rdt30 in action
- Performance of rdt30
- rdt30 stop-and-wait operation
- Pipelined protocols
- Pipelining increased utilization
- Go-Back-N
- GBN sender extended FSM
- GBN receiver extended FSM
- GBN inaction
- Selective Repeat
- Selective repeat sender receiver windows
- Selective repeat
- Selective repeat in action
- Selective repeat dilemma
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- TCP Overview RFCs 793 1122 1323 2018 2581
- TCP segment structure
- TCP seq rsquos and ACKs
- TCP Round Trip Time and Timeout
- TCP Round Trip Time and Timeout
- Example RTT estimation
- TCP Round Trip Time and Timeout
- TCP reliable data transfer
- TCP sender events
- TCP sender(simplified)
- TCP retransmission scenarios
- TCP retransmission scenarios (more)
- TCP ACK generation [RFC 1122 RFC 2581]
- Fast Retransmit
- Fast Retransmit
- Fast retransmit algorithm
- TCP Flow Control
- TCP Flow control how it works
- Sliding Window Flow Control Example
- Principles of Congestion Control
- Causescosts of congestion scenario 1
- Causescosts of congestion scenario 2
- Causescosts of congestion scenario 2
- Causescosts of congestion scenario 3
- Causescosts of congestion scenario 3
- Approaches towards congestion control
- TCP Congestion Control
- TCP congestion control bandwidth probing
- TCP Congestion Control details
- TCP Congestion Control more details
- TCP Slow Start Phase
- Slow Start Example
- TCP Congestion Avoidance Phase
- Congestion Avoidance
- Example Slow StartCongestion Avoidance
- Slow Start Congestion Avoidance
- Responses to Congestion
- Fast Recovery (differentiation btwn two loss events)
- TCP Congestion Control
- Popular ldquoflavorsrdquo of TCP
- Summary TCP Congestion Control
- TCP Congestion Control Summary
- TCP throughput
- TCP Futures TCP over ldquolong fat pipesrdquo
- TCP Fairness
- Why is TCP fair
- Fairness (more)
- TCP Connection Management
- TCP Connection Management (cont)
- TCP Connection Management (cont)
- TCP Connection Management (cont)
- Tuning TCPIP Parameters
- SomeTCP Parameters in Linux Kernel
- SomeTCP Parameters in Linux Kernel
-
Transport Layer 3-86
Example Slow StartCongestion AvoidanceAssume that
ssthresh = 8
cwnd = 1
cwnd = 2
cwnd = 4
cwnd = 8
cwnd = 9
cwnd = 10
02468
101214
t=0
t=2
t=4
t=6
Roundtrip times
Cw
nd(in
seg
men
ts)
ssthresh
cwnd = 3
cwnd = 5cwnd = 6cwnd = 7
Transport Layer 3-87
Slow Start Congestion AvoidanceA typical plot of CongWin for a TCP connection
(MSS = 1500 bytes) with TCP Tahoe
SS
CA
ssthresh
Transport Layer 3-88
Responses to CongestionTCP assumes there is congestion if it detects a packet lossA TCP sender can detect lost packets via loss events
bull Timeout of a retransmission timerbull Receipt of 3 duplicate ACKs (fast retransmit)
TCP interprets a Timeout as a binary congestion signal When a timeout occurs the sender performs
ssthresh is set to half the current size of the congestion window
ssthresh = CongWin 2CongWin is reset to one
CongWin = 1and slow-start is entered
Transport Layer 3-89
Fast Recovery (differentiation btwn two loss events) After 3 dup ACKs (fast Retransmit)
ssthresh = CongWin2CongWin = CongWin2window then grows linearly
But after timeout eventCongWin = 1 MSS window then grows exponentiallyto the threshold then grows linearly
bull 3 dup ACKs indicates network capable of delivering some segmentsbull timeout before 3 dup ACKs is ldquomore alarmingrdquo
Philosophy
3-90
TCP Congestion ControlInitially
CongWin = 1ssthresh = advertised window size
New Ack receivedif (CongWin lt ssthresh) Slow Start
CongWin = CongWin + 1else Congestion Avoidance
CongWin = CongWin + 1CongWinTimeout
ssthresh = CongWin2CongWin = 1
Fast Retransmissionssthresh = CongWin2CongWin = CongWin2
Slow Start (exponential increase phase) is continued until CongWin reaches half of the level where the loss event occurred last time CongWin is increased slowly after (linear increase in Congestion Avoidance phase)
Transport Layer 3-91
Popular ldquoflavorsrdquo of TCP
ssthresh
ssthresh
TCP Tahoe
TCP Reno
Transmission round
cwnd
win
dow
siz
e (in
seg
men
ts)
Transport Layer 3-92
Summary TCP Congestion ControlWhen CongWin is below Threshold sender in slow-start phase window grows exponentiallyWhen CongWin is above Threshold sender is in congestion-avoidance phase window grows linearlyWhen a triple duplicate ACK occurs Threshold set to CongWin2 and CongWin set to ThresholdWhen timeout occurs Threshold set to CongWin2 and CongWin is set to 1 MSS The actual sender window size is determined based on the congestion and flow control algorithms
SenderWin=min(RcvWinCongWin)
Transport Layer 3-93
TCP Congestion Control SummaryEvent State TCP Sender Action Commentary
ACK receipt for previously unackeddata
Slow Start (SS)
CongWin = CongWin + MSS If (CongWin gt Threshold)
set state to ldquoCongestion Avoidancerdquo
Resulting in a doubling of CongWin every RTT
ACK receipt for previously unackeddata
CongestionAvoidance (CA)
CongWin = CongWin+MSS (MSSCongWin)
Additive increase resulting in increase of CongWin by 1 MSS every RTT
Loss event detected by triple duplicate ACK
SS or CA Threshold = CongWin2 CongWin = ThresholdSet state to ldquoCongestion Avoidancerdquo
Fast recovery implementing multiplicative decrease CongWin will not drop below 1 MSS
Timeout SS or CA Threshold = CongWin2 CongWin = 1 MSSSet state to ldquoSlow Startrdquo
Enter slow start
Duplicate ACK
SS or CA Increment duplicate ACK count for segment being acked
CongWin and Threshold not changed
Transport Layer 3-94
TCP throughput
Q whatrsquos average throughout of TCP as function of window size RTT
ignoring slow startlet W be window size when loss occurs
when window is W throughput is WRTTjust after loss window drops to W2 throughput to W2RTT average throughout 75 WRTT
Transport Layer 3-95
TCP Futures TCP over ldquolong fat pipesrdquo
example 1500 byte segments 100ms RTT want 10 Gbps throughputrequires window size W = 83333 in-flight segmentsthroughput in terms of loss rate
L = 210-10 Wownew versions of TCP for high-speed
LRTTMSSsdot221
Transport Layer 3-96
Fairness goal if K TCP sessions share same bottleneck link of bandwidth R each should have average rate of RK
TCP connection 1
bottleneckrouter
capacity R
TCP connection 2
TCP Fairness
Transport Layer 3-97
Why is TCP fairTwo competing sessions
Additive increase gives slope of 1 as throughout increasesmultiplicative decrease decreases throughput proportionally
R
R
equal bandwidth share
Connection 1 throughput
Conn
ecti
on 2
thr
ough
p ut
congestion avoidance additive increaseloss decrease window by factor of 2
congestion avoidance additive increaseloss decrease window by factor of 2
Transport Layer 3-98
Fairness (more)Fairness and UDP
Multimedia apps often do not use TCP
do not want rate throttled by congestion control
Instead use UDPpump audiovideo at constant rate tolerate packet loss
Research area TCP friendly
Fairness and parallel TCP connectionsnothing prevents app from opening parallel cnctionsbetween 2 hostsWeb browsers do this Example link of rate R supporting 9 cnctions
new app asks for 1 TCP gets rate R10new app asks for 11 TCPs gets R2
Transport Layer 3-99
TCP Connection ManagementRecall TCP sender receiver
establish ldquoconnectionrdquobefore exchanging data segmentsinitialize TCP variables
seq sbuffers flow control info (eg RcvWindow)
client connection initiatorSocket clientSocket = new Socket(hostnameport
number)
server contacted by clientSocket connectionSocket = welcomeSocketaccept()
Three way handshakeStep 1 client host sends TCP
SYN segment to serverspecifies initial seq no data
Step 2 server host receives SYN replies with SYNACK segment
server allocates buffersspecifies server initial seq
Step 3 client receives SYNACK replies with ACK segment which may contain data
Transport Layer 3-100
TCP Connection Management (cont)
Closing a connection
client closes socketclientSocketclose()
Step 1 client end system sends TCP FIN control segment to server
Step 2 server receives FIN replies with ACK Closes connection sends FIN
client
FIN
server
ACK
ACK
FIN
close
close
closed
tim
ed w
ait
Transport Layer 3-101
TCP Connection Management (cont)
Step 3 client receives FIN replies with ACK
Enters ldquotimed waitrdquo -will respond with ACK to received FINs
Step 4 server receives ACK Connection closed
client
FIN
server
ACK
ACK
FIN
closing
closing
closed
tim
ed w
ait
closed
Transport Layer 3-102
TCP Connection Management (cont)
TCP clientlifecycle
TCP serverlifecycle
Transport Layer 3-103
Tuning TCPIP Parameters TCPIP parameters
A set of default values may not be optimal for all applicationsThe network administrator may wish to turn on or off some TCPIP functions for performance or security considerations
Many Unix and Linux systems provide some flexibility in tuning the TCPIP kernelsbinsysctl is used to configure the Linux kernel parameters at runtime
Default kernel configuration file is sbinsysctlconfFrequently used sysctl options
bull sysctl ndasha or sysctl ndashA list all current valuesbull sysctl ndashp file_name load the sysctl setting from a configuration
filebull sysctl ndashw variable=value change the value of the parameter
Transport Layer 3-104
SomeTCP Parameters in Linux Kerneltcp_syn_retries
Number of SYN packets the kernel will send before giving up on the new connection
tcp_synack_retriesnumber of SYN+ACK packets sent before the kernel gives up on the connection
tcp_window_scalingMaximum window size of 65535 bytes not enough for for really fast networks The window scaling options allows for almost gigabyte windows which is good for connections with large delay-bandwidth product
tcp_max_syn_backlogMaximal number of remembered connection requests which still did not receive an acknowledgment from connecting client
tcp_fin_timeoutHow many seconds to wait for a final FIN packet before the socket is closed required to prevent denial-of-service (DoS) attacks Default value is 60 seconds
Transport Layer 3-105
SomeTCP Parameters in Linux Kerneltcp_rmem
This is a vector of 3 integers [min default max] These parameters are used by TCP to dynamically adjust receive buffer sizesmin - minimum size of the receive buffer used by each TCP socket The default value is 4K default - the default size of the receive buffer for a TCP socket The default value is 87380 bytes and is lowered to 43689 in low memory systems If larger receive buffer sizes are desired this value should be increased max - the maximum size of the receive buffer used by each TCP socket The default value of 873802 bytes is lowered to 87380 in low memory systems
tcp_smemSend buffer parameters [min default max] similar to tcp_rmem
- Chapter 3 Transport Layer
- Transport services and protocols
- Transport vs network layer
- Internet transport-layer protocols
- Multiplexingdemultiplexing
- How demultiplexing works
- Connectionless demultiplexing
- Connection-oriented demux
- Connection-oriented demux (cont)
- Connection-oriented demux Threaded Web Server
- UDP User Datagram Protocol [RFC 768]
- UDP more
- UDP checksum
- Principles of Reliable data transfer
- Reliable data transfer getting started
- Reliable data transfer getting started
- Rdt10 reliable transfer over a reliable channel
- Rdt20 channel with bit errors
- rdt20 FSM specification
- rdt20 operation with no errors
- rdt20 error scenario
- rdt20 has a fatal flaw
- rdt21 sender handles garbled ACKNAKs
- rdt21 receiver handles garbled ACKNAKs
- rdt21 discussion
- rdt22 a NAK-free protocol
- rdt22 sender receiver fragments
- rdt30 channels with errors and loss
- rdt30 sender
- rdt30 in action
- rdt30 in action
- Performance of rdt30
- rdt30 stop-and-wait operation
- Pipelined protocols
- Pipelining increased utilization
- Go-Back-N
- GBN sender extended FSM
- GBN receiver extended FSM
- GBN inaction
- Selective Repeat
- Selective repeat sender receiver windows
- Selective repeat
- Selective repeat in action
- Selective repeat dilemma
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- TCP Overview RFCs 793 1122 1323 2018 2581
- TCP segment structure
- TCP seq rsquos and ACKs
- TCP Round Trip Time and Timeout
- TCP Round Trip Time and Timeout
- Example RTT estimation
- TCP Round Trip Time and Timeout
- TCP reliable data transfer
- TCP sender events
- TCP sender(simplified)
- TCP retransmission scenarios
- TCP retransmission scenarios (more)
- TCP ACK generation [RFC 1122 RFC 2581]
- Fast Retransmit
- Fast Retransmit
- Fast retransmit algorithm
- TCP Flow Control
- TCP Flow control how it works
- Sliding Window Flow Control Example
- Principles of Congestion Control
- Causescosts of congestion scenario 1
- Causescosts of congestion scenario 2
- Causescosts of congestion scenario 2
- Causescosts of congestion scenario 3
- Causescosts of congestion scenario 3
- Approaches towards congestion control
- TCP Congestion Control
- TCP congestion control bandwidth probing
- TCP Congestion Control details
- TCP Congestion Control more details
- TCP Slow Start Phase
- Slow Start Example
- TCP Congestion Avoidance Phase
- Congestion Avoidance
- Example Slow StartCongestion Avoidance
- Slow Start Congestion Avoidance
- Responses to Congestion
- Fast Recovery (differentiation btwn two loss events)
- TCP Congestion Control
- Popular ldquoflavorsrdquo of TCP
- Summary TCP Congestion Control
- TCP Congestion Control Summary
- TCP throughput
- TCP Futures TCP over ldquolong fat pipesrdquo
- TCP Fairness
- Why is TCP fair
- Fairness (more)
- TCP Connection Management
- TCP Connection Management (cont)
- TCP Connection Management (cont)
- TCP Connection Management (cont)
- Tuning TCPIP Parameters
- SomeTCP Parameters in Linux Kernel
- SomeTCP Parameters in Linux Kernel
-
Transport Layer 3-87
Slow Start Congestion AvoidanceA typical plot of CongWin for a TCP connection
(MSS = 1500 bytes) with TCP Tahoe
SS
CA
ssthresh
Transport Layer 3-88
Responses to CongestionTCP assumes there is congestion if it detects a packet lossA TCP sender can detect lost packets via loss events
bull Timeout of a retransmission timerbull Receipt of 3 duplicate ACKs (fast retransmit)
TCP interprets a Timeout as a binary congestion signal When a timeout occurs the sender performs
ssthresh is set to half the current size of the congestion window
ssthresh = CongWin 2CongWin is reset to one
CongWin = 1and slow-start is entered
Transport Layer 3-89
Fast Recovery (differentiation btwn two loss events) After 3 dup ACKs (fast Retransmit)
ssthresh = CongWin2CongWin = CongWin2window then grows linearly
But after timeout eventCongWin = 1 MSS window then grows exponentiallyto the threshold then grows linearly
bull 3 dup ACKs indicates network capable of delivering some segmentsbull timeout before 3 dup ACKs is ldquomore alarmingrdquo
Philosophy
3-90
TCP Congestion ControlInitially
CongWin = 1ssthresh = advertised window size
New Ack receivedif (CongWin lt ssthresh) Slow Start
CongWin = CongWin + 1else Congestion Avoidance
CongWin = CongWin + 1CongWinTimeout
ssthresh = CongWin2CongWin = 1
Fast Retransmissionssthresh = CongWin2CongWin = CongWin2
Slow Start (exponential increase phase) is continued until CongWin reaches half of the level where the loss event occurred last time CongWin is increased slowly after (linear increase in Congestion Avoidance phase)
Transport Layer 3-91
Popular ldquoflavorsrdquo of TCP
ssthresh
ssthresh
TCP Tahoe
TCP Reno
Transmission round
cwnd
win
dow
siz
e (in
seg
men
ts)
Transport Layer 3-92
Summary TCP Congestion ControlWhen CongWin is below Threshold sender in slow-start phase window grows exponentiallyWhen CongWin is above Threshold sender is in congestion-avoidance phase window grows linearlyWhen a triple duplicate ACK occurs Threshold set to CongWin2 and CongWin set to ThresholdWhen timeout occurs Threshold set to CongWin2 and CongWin is set to 1 MSS The actual sender window size is determined based on the congestion and flow control algorithms
SenderWin=min(RcvWinCongWin)
Transport Layer 3-93
TCP Congestion Control SummaryEvent State TCP Sender Action Commentary
ACK receipt for previously unackeddata
Slow Start (SS)
CongWin = CongWin + MSS If (CongWin gt Threshold)
set state to ldquoCongestion Avoidancerdquo
Resulting in a doubling of CongWin every RTT
ACK receipt for previously unackeddata
CongestionAvoidance (CA)
CongWin = CongWin+MSS (MSSCongWin)
Additive increase resulting in increase of CongWin by 1 MSS every RTT
Loss event detected by triple duplicate ACK
SS or CA Threshold = CongWin2 CongWin = ThresholdSet state to ldquoCongestion Avoidancerdquo
Fast recovery implementing multiplicative decrease CongWin will not drop below 1 MSS
Timeout SS or CA Threshold = CongWin2 CongWin = 1 MSSSet state to ldquoSlow Startrdquo
Enter slow start
Duplicate ACK
SS or CA Increment duplicate ACK count for segment being acked
CongWin and Threshold not changed
Transport Layer 3-94
TCP throughput
Q whatrsquos average throughout of TCP as function of window size RTT
ignoring slow startlet W be window size when loss occurs
when window is W throughput is WRTTjust after loss window drops to W2 throughput to W2RTT average throughout 75 WRTT
Transport Layer 3-95
TCP Futures TCP over ldquolong fat pipesrdquo
example 1500 byte segments 100ms RTT want 10 Gbps throughputrequires window size W = 83333 in-flight segmentsthroughput in terms of loss rate
L = 210-10 Wownew versions of TCP for high-speed
LRTTMSSsdot221
Transport Layer 3-96
Fairness goal if K TCP sessions share same bottleneck link of bandwidth R each should have average rate of RK
TCP connection 1
bottleneckrouter
capacity R
TCP connection 2
TCP Fairness
Transport Layer 3-97
Why is TCP fairTwo competing sessions
Additive increase gives slope of 1 as throughout increasesmultiplicative decrease decreases throughput proportionally
R
R
equal bandwidth share
Connection 1 throughput
Conn
ecti
on 2
thr
ough
p ut
congestion avoidance additive increaseloss decrease window by factor of 2
congestion avoidance additive increaseloss decrease window by factor of 2
Transport Layer 3-98
Fairness (more)Fairness and UDP
Multimedia apps often do not use TCP
do not want rate throttled by congestion control
Instead use UDPpump audiovideo at constant rate tolerate packet loss
Research area TCP friendly
Fairness and parallel TCP connectionsnothing prevents app from opening parallel cnctionsbetween 2 hostsWeb browsers do this Example link of rate R supporting 9 cnctions
new app asks for 1 TCP gets rate R10new app asks for 11 TCPs gets R2
Transport Layer 3-99
TCP Connection ManagementRecall TCP sender receiver
establish ldquoconnectionrdquobefore exchanging data segmentsinitialize TCP variables
seq sbuffers flow control info (eg RcvWindow)
client connection initiatorSocket clientSocket = new Socket(hostnameport
number)
server contacted by clientSocket connectionSocket = welcomeSocketaccept()
Three way handshakeStep 1 client host sends TCP
SYN segment to serverspecifies initial seq no data
Step 2 server host receives SYN replies with SYNACK segment
server allocates buffersspecifies server initial seq
Step 3 client receives SYNACK replies with ACK segment which may contain data
Transport Layer 3-100
TCP Connection Management (cont)
Closing a connection
client closes socketclientSocketclose()
Step 1 client end system sends TCP FIN control segment to server
Step 2 server receives FIN replies with ACK Closes connection sends FIN
client
FIN
server
ACK
ACK
FIN
close
close
closed
tim
ed w
ait
Transport Layer 3-101
TCP Connection Management (cont)
Step 3 client receives FIN replies with ACK
Enters ldquotimed waitrdquo -will respond with ACK to received FINs
Step 4 server receives ACK Connection closed
client
FIN
server
ACK
ACK
FIN
closing
closing
closed
tim
ed w
ait
closed
Transport Layer 3-102
TCP Connection Management (cont)
TCP clientlifecycle
TCP serverlifecycle
Transport Layer 3-103
Tuning TCPIP Parameters TCPIP parameters
A set of default values may not be optimal for all applicationsThe network administrator may wish to turn on or off some TCPIP functions for performance or security considerations
Many Unix and Linux systems provide some flexibility in tuning the TCPIP kernelsbinsysctl is used to configure the Linux kernel parameters at runtime
Default kernel configuration file is sbinsysctlconfFrequently used sysctl options
bull sysctl ndasha or sysctl ndashA list all current valuesbull sysctl ndashp file_name load the sysctl setting from a configuration
filebull sysctl ndashw variable=value change the value of the parameter
Transport Layer 3-104
SomeTCP Parameters in Linux Kerneltcp_syn_retries
Number of SYN packets the kernel will send before giving up on the new connection
tcp_synack_retriesnumber of SYN+ACK packets sent before the kernel gives up on the connection
tcp_window_scalingMaximum window size of 65535 bytes not enough for for really fast networks The window scaling options allows for almost gigabyte windows which is good for connections with large delay-bandwidth product
tcp_max_syn_backlogMaximal number of remembered connection requests which still did not receive an acknowledgment from connecting client
tcp_fin_timeoutHow many seconds to wait for a final FIN packet before the socket is closed required to prevent denial-of-service (DoS) attacks Default value is 60 seconds
Transport Layer 3-105
SomeTCP Parameters in Linux Kerneltcp_rmem
This is a vector of 3 integers [min default max] These parameters are used by TCP to dynamically adjust receive buffer sizesmin - minimum size of the receive buffer used by each TCP socket The default value is 4K default - the default size of the receive buffer for a TCP socket The default value is 87380 bytes and is lowered to 43689 in low memory systems If larger receive buffer sizes are desired this value should be increased max - the maximum size of the receive buffer used by each TCP socket The default value of 873802 bytes is lowered to 87380 in low memory systems
tcp_smemSend buffer parameters [min default max] similar to tcp_rmem
- Chapter 3 Transport Layer
- Transport services and protocols
- Transport vs network layer
- Internet transport-layer protocols
- Multiplexingdemultiplexing
- How demultiplexing works
- Connectionless demultiplexing
- Connection-oriented demux
- Connection-oriented demux (cont)
- Connection-oriented demux Threaded Web Server
- UDP User Datagram Protocol [RFC 768]
- UDP more
- UDP checksum
- Principles of Reliable data transfer
- Reliable data transfer getting started
- Reliable data transfer getting started
- Rdt10 reliable transfer over a reliable channel
- Rdt20 channel with bit errors
- rdt20 FSM specification
- rdt20 operation with no errors
- rdt20 error scenario
- rdt20 has a fatal flaw
- rdt21 sender handles garbled ACKNAKs
- rdt21 receiver handles garbled ACKNAKs
- rdt21 discussion
- rdt22 a NAK-free protocol
- rdt22 sender receiver fragments
- rdt30 channels with errors and loss
- rdt30 sender
- rdt30 in action
- rdt30 in action
- Performance of rdt30
- rdt30 stop-and-wait operation
- Pipelined protocols
- Pipelining increased utilization
- Go-Back-N
- GBN sender extended FSM
- GBN receiver extended FSM
- GBN inaction
- Selective Repeat
- Selective repeat sender receiver windows
- Selective repeat
- Selective repeat in action
- Selective repeat dilemma
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- TCP Overview RFCs 793 1122 1323 2018 2581
- TCP segment structure
- TCP seq rsquos and ACKs
- TCP Round Trip Time and Timeout
- TCP Round Trip Time and Timeout
- Example RTT estimation
- TCP Round Trip Time and Timeout
- TCP reliable data transfer
- TCP sender events
- TCP sender(simplified)
- TCP retransmission scenarios
- TCP retransmission scenarios (more)
- TCP ACK generation [RFC 1122 RFC 2581]
- Fast Retransmit
- Fast Retransmit
- Fast retransmit algorithm
- TCP Flow Control
- TCP Flow control how it works
- Sliding Window Flow Control Example
- Principles of Congestion Control
- Causescosts of congestion scenario 1
- Causescosts of congestion scenario 2
- Causescosts of congestion scenario 2
- Causescosts of congestion scenario 3
- Causescosts of congestion scenario 3
- Approaches towards congestion control
- TCP Congestion Control
- TCP congestion control bandwidth probing
- TCP Congestion Control details
- TCP Congestion Control more details
- TCP Slow Start Phase
- Slow Start Example
- TCP Congestion Avoidance Phase
- Congestion Avoidance
- Example Slow StartCongestion Avoidance
- Slow Start Congestion Avoidance
- Responses to Congestion
- Fast Recovery (differentiation btwn two loss events)
- TCP Congestion Control
- Popular ldquoflavorsrdquo of TCP
- Summary TCP Congestion Control
- TCP Congestion Control Summary
- TCP throughput
- TCP Futures TCP over ldquolong fat pipesrdquo
- TCP Fairness
- Why is TCP fair
- Fairness (more)
- TCP Connection Management
- TCP Connection Management (cont)
- TCP Connection Management (cont)
- TCP Connection Management (cont)
- Tuning TCPIP Parameters
- SomeTCP Parameters in Linux Kernel
- SomeTCP Parameters in Linux Kernel
-
Transport Layer 3-88
Responses to CongestionTCP assumes there is congestion if it detects a packet lossA TCP sender can detect lost packets via loss events
bull Timeout of a retransmission timerbull Receipt of 3 duplicate ACKs (fast retransmit)
TCP interprets a Timeout as a binary congestion signal When a timeout occurs the sender performs
ssthresh is set to half the current size of the congestion window
ssthresh = CongWin 2CongWin is reset to one
CongWin = 1and slow-start is entered
Transport Layer 3-89
Fast Recovery (differentiation btwn two loss events) After 3 dup ACKs (fast Retransmit)
ssthresh = CongWin2CongWin = CongWin2window then grows linearly
But after timeout eventCongWin = 1 MSS window then grows exponentiallyto the threshold then grows linearly
bull 3 dup ACKs indicates network capable of delivering some segmentsbull timeout before 3 dup ACKs is ldquomore alarmingrdquo
Philosophy
3-90
TCP Congestion ControlInitially
CongWin = 1ssthresh = advertised window size
New Ack receivedif (CongWin lt ssthresh) Slow Start
CongWin = CongWin + 1else Congestion Avoidance
CongWin = CongWin + 1CongWinTimeout
ssthresh = CongWin2CongWin = 1
Fast Retransmissionssthresh = CongWin2CongWin = CongWin2
Slow Start (exponential increase phase) is continued until CongWin reaches half of the level where the loss event occurred last time CongWin is increased slowly after (linear increase in Congestion Avoidance phase)
Transport Layer 3-91
Popular ldquoflavorsrdquo of TCP
ssthresh
ssthresh
TCP Tahoe
TCP Reno
Transmission round
cwnd
win
dow
siz
e (in
seg
men
ts)
Transport Layer 3-92
Summary TCP Congestion ControlWhen CongWin is below Threshold sender in slow-start phase window grows exponentiallyWhen CongWin is above Threshold sender is in congestion-avoidance phase window grows linearlyWhen a triple duplicate ACK occurs Threshold set to CongWin2 and CongWin set to ThresholdWhen timeout occurs Threshold set to CongWin2 and CongWin is set to 1 MSS The actual sender window size is determined based on the congestion and flow control algorithms
SenderWin=min(RcvWinCongWin)
Transport Layer 3-93
TCP Congestion Control SummaryEvent State TCP Sender Action Commentary
ACK receipt for previously unackeddata
Slow Start (SS)
CongWin = CongWin + MSS If (CongWin gt Threshold)
set state to ldquoCongestion Avoidancerdquo
Resulting in a doubling of CongWin every RTT
ACK receipt for previously unackeddata
CongestionAvoidance (CA)
CongWin = CongWin+MSS (MSSCongWin)
Additive increase resulting in increase of CongWin by 1 MSS every RTT
Loss event detected by triple duplicate ACK
SS or CA Threshold = CongWin2 CongWin = ThresholdSet state to ldquoCongestion Avoidancerdquo
Fast recovery implementing multiplicative decrease CongWin will not drop below 1 MSS
Timeout SS or CA Threshold = CongWin2 CongWin = 1 MSSSet state to ldquoSlow Startrdquo
Enter slow start
Duplicate ACK
SS or CA Increment duplicate ACK count for segment being acked
CongWin and Threshold not changed
Transport Layer 3-94
TCP throughput
Q whatrsquos average throughout of TCP as function of window size RTT
ignoring slow startlet W be window size when loss occurs
when window is W throughput is WRTTjust after loss window drops to W2 throughput to W2RTT average throughout 75 WRTT
Transport Layer 3-95
TCP Futures TCP over ldquolong fat pipesrdquo
example 1500 byte segments 100ms RTT want 10 Gbps throughputrequires window size W = 83333 in-flight segmentsthroughput in terms of loss rate
L = 210-10 Wownew versions of TCP for high-speed
LRTTMSSsdot221
Transport Layer 3-96
Fairness goal if K TCP sessions share same bottleneck link of bandwidth R each should have average rate of RK
TCP connection 1
bottleneckrouter
capacity R
TCP connection 2
TCP Fairness
Transport Layer 3-97
Why is TCP fairTwo competing sessions
Additive increase gives slope of 1 as throughout increasesmultiplicative decrease decreases throughput proportionally
R
R
equal bandwidth share
Connection 1 throughput
Conn
ecti
on 2
thr
ough
p ut
congestion avoidance additive increaseloss decrease window by factor of 2
congestion avoidance additive increaseloss decrease window by factor of 2
Transport Layer 3-98
Fairness (more)Fairness and UDP
Multimedia apps often do not use TCP
do not want rate throttled by congestion control
Instead use UDPpump audiovideo at constant rate tolerate packet loss
Research area TCP friendly
Fairness and parallel TCP connectionsnothing prevents app from opening parallel cnctionsbetween 2 hostsWeb browsers do this Example link of rate R supporting 9 cnctions
new app asks for 1 TCP gets rate R10new app asks for 11 TCPs gets R2
Transport Layer 3-99
TCP Connection ManagementRecall TCP sender receiver
establish ldquoconnectionrdquobefore exchanging data segmentsinitialize TCP variables
seq sbuffers flow control info (eg RcvWindow)
client connection initiatorSocket clientSocket = new Socket(hostnameport
number)
server contacted by clientSocket connectionSocket = welcomeSocketaccept()
Three way handshakeStep 1 client host sends TCP
SYN segment to serverspecifies initial seq no data
Step 2 server host receives SYN replies with SYNACK segment
server allocates buffersspecifies server initial seq
Step 3 client receives SYNACK replies with ACK segment which may contain data
Transport Layer 3-100
TCP Connection Management (cont)
Closing a connection
client closes socketclientSocketclose()
Step 1 client end system sends TCP FIN control segment to server
Step 2 server receives FIN replies with ACK Closes connection sends FIN
client
FIN
server
ACK
ACK
FIN
close
close
closed
tim
ed w
ait
Transport Layer 3-101
TCP Connection Management (cont)
Step 3 client receives FIN replies with ACK
Enters ldquotimed waitrdquo -will respond with ACK to received FINs
Step 4 server receives ACK Connection closed
client
FIN
server
ACK
ACK
FIN
closing
closing
closed
tim
ed w
ait
closed
Transport Layer 3-102
TCP Connection Management (cont)
TCP clientlifecycle
TCP serverlifecycle
Transport Layer 3-103
Tuning TCPIP Parameters TCPIP parameters
A set of default values may not be optimal for all applicationsThe network administrator may wish to turn on or off some TCPIP functions for performance or security considerations
Many Unix and Linux systems provide some flexibility in tuning the TCPIP kernelsbinsysctl is used to configure the Linux kernel parameters at runtime
Default kernel configuration file is sbinsysctlconfFrequently used sysctl options
bull sysctl ndasha or sysctl ndashA list all current valuesbull sysctl ndashp file_name load the sysctl setting from a configuration
filebull sysctl ndashw variable=value change the value of the parameter
Transport Layer 3-104
SomeTCP Parameters in Linux Kerneltcp_syn_retries
Number of SYN packets the kernel will send before giving up on the new connection
tcp_synack_retriesnumber of SYN+ACK packets sent before the kernel gives up on the connection
tcp_window_scalingMaximum window size of 65535 bytes not enough for for really fast networks The window scaling options allows for almost gigabyte windows which is good for connections with large delay-bandwidth product
tcp_max_syn_backlogMaximal number of remembered connection requests which still did not receive an acknowledgment from connecting client
tcp_fin_timeoutHow many seconds to wait for a final FIN packet before the socket is closed required to prevent denial-of-service (DoS) attacks Default value is 60 seconds
Transport Layer 3-105
SomeTCP Parameters in Linux Kerneltcp_rmem
This is a vector of 3 integers [min default max] These parameters are used by TCP to dynamically adjust receive buffer sizesmin - minimum size of the receive buffer used by each TCP socket The default value is 4K default - the default size of the receive buffer for a TCP socket The default value is 87380 bytes and is lowered to 43689 in low memory systems If larger receive buffer sizes are desired this value should be increased max - the maximum size of the receive buffer used by each TCP socket The default value of 873802 bytes is lowered to 87380 in low memory systems
tcp_smemSend buffer parameters [min default max] similar to tcp_rmem
- Chapter 3 Transport Layer
- Transport services and protocols
- Transport vs network layer
- Internet transport-layer protocols
- Multiplexingdemultiplexing
- How demultiplexing works
- Connectionless demultiplexing
- Connection-oriented demux
- Connection-oriented demux (cont)
- Connection-oriented demux Threaded Web Server
- UDP User Datagram Protocol [RFC 768]
- UDP more
- UDP checksum
- Principles of Reliable data transfer
- Reliable data transfer getting started
- Reliable data transfer getting started
- Rdt10 reliable transfer over a reliable channel
- Rdt20 channel with bit errors
- rdt20 FSM specification
- rdt20 operation with no errors
- rdt20 error scenario
- rdt20 has a fatal flaw
- rdt21 sender handles garbled ACKNAKs
- rdt21 receiver handles garbled ACKNAKs
- rdt21 discussion
- rdt22 a NAK-free protocol
- rdt22 sender receiver fragments
- rdt30 channels with errors and loss
- rdt30 sender
- rdt30 in action
- rdt30 in action
- Performance of rdt30
- rdt30 stop-and-wait operation
- Pipelined protocols
- Pipelining increased utilization
- Go-Back-N
- GBN sender extended FSM
- GBN receiver extended FSM
- GBN inaction
- Selective Repeat
- Selective repeat sender receiver windows
- Selective repeat
- Selective repeat in action
- Selective repeat dilemma
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- TCP Overview RFCs 793 1122 1323 2018 2581
- TCP segment structure
- TCP seq rsquos and ACKs
- TCP Round Trip Time and Timeout
- TCP Round Trip Time and Timeout
- Example RTT estimation
- TCP Round Trip Time and Timeout
- TCP reliable data transfer
- TCP sender events
- TCP sender(simplified)
- TCP retransmission scenarios
- TCP retransmission scenarios (more)
- TCP ACK generation [RFC 1122 RFC 2581]
- Fast Retransmit
- Fast Retransmit
- Fast retransmit algorithm
- TCP Flow Control
- TCP Flow control how it works
- Sliding Window Flow Control Example
- Principles of Congestion Control
- Causescosts of congestion scenario 1
- Causescosts of congestion scenario 2
- Causescosts of congestion scenario 2
- Causescosts of congestion scenario 3
- Causescosts of congestion scenario 3
- Approaches towards congestion control
- TCP Congestion Control
- TCP congestion control bandwidth probing
- TCP Congestion Control details
- TCP Congestion Control more details
- TCP Slow Start Phase
- Slow Start Example
- TCP Congestion Avoidance Phase
- Congestion Avoidance
- Example Slow StartCongestion Avoidance
- Slow Start Congestion Avoidance
- Responses to Congestion
- Fast Recovery (differentiation btwn two loss events)
- TCP Congestion Control
- Popular ldquoflavorsrdquo of TCP
- Summary TCP Congestion Control
- TCP Congestion Control Summary
- TCP throughput
- TCP Futures TCP over ldquolong fat pipesrdquo
- TCP Fairness
- Why is TCP fair
- Fairness (more)
- TCP Connection Management
- TCP Connection Management (cont)
- TCP Connection Management (cont)
- TCP Connection Management (cont)
- Tuning TCPIP Parameters
- SomeTCP Parameters in Linux Kernel
- SomeTCP Parameters in Linux Kernel
-
Transport Layer 3-89
Fast Recovery (differentiation btwn two loss events) After 3 dup ACKs (fast Retransmit)
ssthresh = CongWin2CongWin = CongWin2window then grows linearly
But after timeout eventCongWin = 1 MSS window then grows exponentiallyto the threshold then grows linearly
bull 3 dup ACKs indicates network capable of delivering some segmentsbull timeout before 3 dup ACKs is ldquomore alarmingrdquo
Philosophy
3-90
TCP Congestion ControlInitially
CongWin = 1ssthresh = advertised window size
New Ack receivedif (CongWin lt ssthresh) Slow Start
CongWin = CongWin + 1else Congestion Avoidance
CongWin = CongWin + 1CongWinTimeout
ssthresh = CongWin2CongWin = 1
Fast Retransmissionssthresh = CongWin2CongWin = CongWin2
Slow Start (exponential increase phase) is continued until CongWin reaches half of the level where the loss event occurred last time CongWin is increased slowly after (linear increase in Congestion Avoidance phase)
Transport Layer 3-91
Popular ldquoflavorsrdquo of TCP
ssthresh
ssthresh
TCP Tahoe
TCP Reno
Transmission round
cwnd
win
dow
siz
e (in
seg
men
ts)
Transport Layer 3-92
Summary TCP Congestion ControlWhen CongWin is below Threshold sender in slow-start phase window grows exponentiallyWhen CongWin is above Threshold sender is in congestion-avoidance phase window grows linearlyWhen a triple duplicate ACK occurs Threshold set to CongWin2 and CongWin set to ThresholdWhen timeout occurs Threshold set to CongWin2 and CongWin is set to 1 MSS The actual sender window size is determined based on the congestion and flow control algorithms
SenderWin=min(RcvWinCongWin)
Transport Layer 3-93
TCP Congestion Control SummaryEvent State TCP Sender Action Commentary
ACK receipt for previously unackeddata
Slow Start (SS)
CongWin = CongWin + MSS If (CongWin gt Threshold)
set state to ldquoCongestion Avoidancerdquo
Resulting in a doubling of CongWin every RTT
ACK receipt for previously unackeddata
CongestionAvoidance (CA)
CongWin = CongWin+MSS (MSSCongWin)
Additive increase resulting in increase of CongWin by 1 MSS every RTT
Loss event detected by triple duplicate ACK
SS or CA Threshold = CongWin2 CongWin = ThresholdSet state to ldquoCongestion Avoidancerdquo
Fast recovery implementing multiplicative decrease CongWin will not drop below 1 MSS
Timeout SS or CA Threshold = CongWin2 CongWin = 1 MSSSet state to ldquoSlow Startrdquo
Enter slow start
Duplicate ACK
SS or CA Increment duplicate ACK count for segment being acked
CongWin and Threshold not changed
Transport Layer 3-94
TCP throughput
Q whatrsquos average throughout of TCP as function of window size RTT
ignoring slow startlet W be window size when loss occurs
when window is W throughput is WRTTjust after loss window drops to W2 throughput to W2RTT average throughout 75 WRTT
Transport Layer 3-95
TCP Futures TCP over ldquolong fat pipesrdquo
example 1500 byte segments 100ms RTT want 10 Gbps throughputrequires window size W = 83333 in-flight segmentsthroughput in terms of loss rate
L = 210-10 Wownew versions of TCP for high-speed
LRTTMSSsdot221
Transport Layer 3-96
Fairness goal if K TCP sessions share same bottleneck link of bandwidth R each should have average rate of RK
TCP connection 1
bottleneckrouter
capacity R
TCP connection 2
TCP Fairness
Transport Layer 3-97
Why is TCP fairTwo competing sessions
Additive increase gives slope of 1 as throughout increasesmultiplicative decrease decreases throughput proportionally
R
R
equal bandwidth share
Connection 1 throughput
Conn
ecti
on 2
thr
ough
p ut
congestion avoidance additive increaseloss decrease window by factor of 2
congestion avoidance additive increaseloss decrease window by factor of 2
Transport Layer 3-98
Fairness (more)Fairness and UDP
Multimedia apps often do not use TCP
do not want rate throttled by congestion control
Instead use UDPpump audiovideo at constant rate tolerate packet loss
Research area TCP friendly
Fairness and parallel TCP connectionsnothing prevents app from opening parallel cnctionsbetween 2 hostsWeb browsers do this Example link of rate R supporting 9 cnctions
new app asks for 1 TCP gets rate R10new app asks for 11 TCPs gets R2
Transport Layer 3-99
TCP Connection ManagementRecall TCP sender receiver
establish ldquoconnectionrdquobefore exchanging data segmentsinitialize TCP variables
seq sbuffers flow control info (eg RcvWindow)
client connection initiatorSocket clientSocket = new Socket(hostnameport
number)
server contacted by clientSocket connectionSocket = welcomeSocketaccept()
Three way handshakeStep 1 client host sends TCP
SYN segment to serverspecifies initial seq no data
Step 2 server host receives SYN replies with SYNACK segment
server allocates buffersspecifies server initial seq
Step 3 client receives SYNACK replies with ACK segment which may contain data
Transport Layer 3-100
TCP Connection Management (cont)
Closing a connection
client closes socketclientSocketclose()
Step 1 client end system sends TCP FIN control segment to server
Step 2 server receives FIN replies with ACK Closes connection sends FIN
client
FIN
server
ACK
ACK
FIN
close
close
closed
tim
ed w
ait
Transport Layer 3-101
TCP Connection Management (cont)
Step 3 client receives FIN replies with ACK
Enters ldquotimed waitrdquo -will respond with ACK to received FINs
Step 4 server receives ACK Connection closed
client
FIN
server
ACK
ACK
FIN
closing
closing
closed
tim
ed w
ait
closed
Transport Layer 3-102
TCP Connection Management (cont)
TCP clientlifecycle
TCP serverlifecycle
Transport Layer 3-103
Tuning TCPIP Parameters TCPIP parameters
A set of default values may not be optimal for all applicationsThe network administrator may wish to turn on or off some TCPIP functions for performance or security considerations
Many Unix and Linux systems provide some flexibility in tuning the TCPIP kernelsbinsysctl is used to configure the Linux kernel parameters at runtime
Default kernel configuration file is sbinsysctlconfFrequently used sysctl options
bull sysctl ndasha or sysctl ndashA list all current valuesbull sysctl ndashp file_name load the sysctl setting from a configuration
filebull sysctl ndashw variable=value change the value of the parameter
Transport Layer 3-104
SomeTCP Parameters in Linux Kerneltcp_syn_retries
Number of SYN packets the kernel will send before giving up on the new connection
tcp_synack_retriesnumber of SYN+ACK packets sent before the kernel gives up on the connection
tcp_window_scalingMaximum window size of 65535 bytes not enough for for really fast networks The window scaling options allows for almost gigabyte windows which is good for connections with large delay-bandwidth product
tcp_max_syn_backlogMaximal number of remembered connection requests which still did not receive an acknowledgment from connecting client
tcp_fin_timeoutHow many seconds to wait for a final FIN packet before the socket is closed required to prevent denial-of-service (DoS) attacks Default value is 60 seconds
Transport Layer 3-105
SomeTCP Parameters in Linux Kerneltcp_rmem
This is a vector of 3 integers [min default max] These parameters are used by TCP to dynamically adjust receive buffer sizesmin - minimum size of the receive buffer used by each TCP socket The default value is 4K default - the default size of the receive buffer for a TCP socket The default value is 87380 bytes and is lowered to 43689 in low memory systems If larger receive buffer sizes are desired this value should be increased max - the maximum size of the receive buffer used by each TCP socket The default value of 873802 bytes is lowered to 87380 in low memory systems
tcp_smemSend buffer parameters [min default max] similar to tcp_rmem
- Chapter 3 Transport Layer
- Transport services and protocols
- Transport vs network layer
- Internet transport-layer protocols
- Multiplexingdemultiplexing
- How demultiplexing works
- Connectionless demultiplexing
- Connection-oriented demux
- Connection-oriented demux (cont)
- Connection-oriented demux Threaded Web Server
- UDP User Datagram Protocol [RFC 768]
- UDP more
- UDP checksum
- Principles of Reliable data transfer
- Reliable data transfer getting started
- Reliable data transfer getting started
- Rdt10 reliable transfer over a reliable channel
- Rdt20 channel with bit errors
- rdt20 FSM specification
- rdt20 operation with no errors
- rdt20 error scenario
- rdt20 has a fatal flaw
- rdt21 sender handles garbled ACKNAKs
- rdt21 receiver handles garbled ACKNAKs
- rdt21 discussion
- rdt22 a NAK-free protocol
- rdt22 sender receiver fragments
- rdt30 channels with errors and loss
- rdt30 sender
- rdt30 in action
- rdt30 in action
- Performance of rdt30
- rdt30 stop-and-wait operation
- Pipelined protocols
- Pipelining increased utilization
- Go-Back-N
- GBN sender extended FSM
- GBN receiver extended FSM
- GBN inaction
- Selective Repeat
- Selective repeat sender receiver windows
- Selective repeat
- Selective repeat in action
- Selective repeat dilemma
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- TCP Overview RFCs 793 1122 1323 2018 2581
- TCP segment structure
- TCP seq rsquos and ACKs
- TCP Round Trip Time and Timeout
- TCP Round Trip Time and Timeout
- Example RTT estimation
- TCP Round Trip Time and Timeout
- TCP reliable data transfer
- TCP sender events
- TCP sender(simplified)
- TCP retransmission scenarios
- TCP retransmission scenarios (more)
- TCP ACK generation [RFC 1122 RFC 2581]
- Fast Retransmit
- Fast Retransmit
- Fast retransmit algorithm
- TCP Flow Control
- TCP Flow control how it works
- Sliding Window Flow Control Example
- Principles of Congestion Control
- Causescosts of congestion scenario 1
- Causescosts of congestion scenario 2
- Causescosts of congestion scenario 2
- Causescosts of congestion scenario 3
- Causescosts of congestion scenario 3
- Approaches towards congestion control
- TCP Congestion Control
- TCP congestion control bandwidth probing
- TCP Congestion Control details
- TCP Congestion Control more details
- TCP Slow Start Phase
- Slow Start Example
- TCP Congestion Avoidance Phase
- Congestion Avoidance
- Example Slow StartCongestion Avoidance
- Slow Start Congestion Avoidance
- Responses to Congestion
- Fast Recovery (differentiation btwn two loss events)
- TCP Congestion Control
- Popular ldquoflavorsrdquo of TCP
- Summary TCP Congestion Control
- TCP Congestion Control Summary
- TCP throughput
- TCP Futures TCP over ldquolong fat pipesrdquo
- TCP Fairness
- Why is TCP fair
- Fairness (more)
- TCP Connection Management
- TCP Connection Management (cont)
- TCP Connection Management (cont)
- TCP Connection Management (cont)
- Tuning TCPIP Parameters
- SomeTCP Parameters in Linux Kernel
- SomeTCP Parameters in Linux Kernel
-
3-90
TCP Congestion ControlInitially
CongWin = 1ssthresh = advertised window size
New Ack receivedif (CongWin lt ssthresh) Slow Start
CongWin = CongWin + 1else Congestion Avoidance
CongWin = CongWin + 1CongWinTimeout
ssthresh = CongWin2CongWin = 1
Fast Retransmissionssthresh = CongWin2CongWin = CongWin2
Slow Start (exponential increase phase) is continued until CongWin reaches half of the level where the loss event occurred last time CongWin is increased slowly after (linear increase in Congestion Avoidance phase)
Transport Layer 3-91
Popular ldquoflavorsrdquo of TCP
ssthresh
ssthresh
TCP Tahoe
TCP Reno
Transmission round
cwnd
win
dow
siz
e (in
seg
men
ts)
Transport Layer 3-92
Summary TCP Congestion ControlWhen CongWin is below Threshold sender in slow-start phase window grows exponentiallyWhen CongWin is above Threshold sender is in congestion-avoidance phase window grows linearlyWhen a triple duplicate ACK occurs Threshold set to CongWin2 and CongWin set to ThresholdWhen timeout occurs Threshold set to CongWin2 and CongWin is set to 1 MSS The actual sender window size is determined based on the congestion and flow control algorithms
SenderWin=min(RcvWinCongWin)
Transport Layer 3-93
TCP Congestion Control SummaryEvent State TCP Sender Action Commentary
ACK receipt for previously unackeddata
Slow Start (SS)
CongWin = CongWin + MSS If (CongWin gt Threshold)
set state to ldquoCongestion Avoidancerdquo
Resulting in a doubling of CongWin every RTT
ACK receipt for previously unackeddata
CongestionAvoidance (CA)
CongWin = CongWin+MSS (MSSCongWin)
Additive increase resulting in increase of CongWin by 1 MSS every RTT
Loss event detected by triple duplicate ACK
SS or CA Threshold = CongWin2 CongWin = ThresholdSet state to ldquoCongestion Avoidancerdquo
Fast recovery implementing multiplicative decrease CongWin will not drop below 1 MSS
Timeout SS or CA Threshold = CongWin2 CongWin = 1 MSSSet state to ldquoSlow Startrdquo
Enter slow start
Duplicate ACK
SS or CA Increment duplicate ACK count for segment being acked
CongWin and Threshold not changed
Transport Layer 3-94
TCP throughput
Q whatrsquos average throughout of TCP as function of window size RTT
ignoring slow startlet W be window size when loss occurs
when window is W throughput is WRTTjust after loss window drops to W2 throughput to W2RTT average throughout 75 WRTT
Transport Layer 3-95
TCP Futures TCP over ldquolong fat pipesrdquo
example 1500 byte segments 100ms RTT want 10 Gbps throughputrequires window size W = 83333 in-flight segmentsthroughput in terms of loss rate
L = 210-10 Wownew versions of TCP for high-speed
LRTTMSSsdot221
Transport Layer 3-96
Fairness goal if K TCP sessions share same bottleneck link of bandwidth R each should have average rate of RK
TCP connection 1
bottleneckrouter
capacity R
TCP connection 2
TCP Fairness
Transport Layer 3-97
Why is TCP fairTwo competing sessions
Additive increase gives slope of 1 as throughout increasesmultiplicative decrease decreases throughput proportionally
R
R
equal bandwidth share
Connection 1 throughput
Conn
ecti
on 2
thr
ough
p ut
congestion avoidance additive increaseloss decrease window by factor of 2
congestion avoidance additive increaseloss decrease window by factor of 2
Transport Layer 3-98
Fairness (more)Fairness and UDP
Multimedia apps often do not use TCP
do not want rate throttled by congestion control
Instead use UDPpump audiovideo at constant rate tolerate packet loss
Research area TCP friendly
Fairness and parallel TCP connectionsnothing prevents app from opening parallel cnctionsbetween 2 hostsWeb browsers do this Example link of rate R supporting 9 cnctions
new app asks for 1 TCP gets rate R10new app asks for 11 TCPs gets R2
Transport Layer 3-99
TCP Connection ManagementRecall TCP sender receiver
establish ldquoconnectionrdquobefore exchanging data segmentsinitialize TCP variables
seq sbuffers flow control info (eg RcvWindow)
client connection initiatorSocket clientSocket = new Socket(hostnameport
number)
server contacted by clientSocket connectionSocket = welcomeSocketaccept()
Three way handshakeStep 1 client host sends TCP
SYN segment to serverspecifies initial seq no data
Step 2 server host receives SYN replies with SYNACK segment
server allocates buffersspecifies server initial seq
Step 3 client receives SYNACK replies with ACK segment which may contain data
Transport Layer 3-100
TCP Connection Management (cont)
Closing a connection
client closes socketclientSocketclose()
Step 1 client end system sends TCP FIN control segment to server
Step 2 server receives FIN replies with ACK Closes connection sends FIN
client
FIN
server
ACK
ACK
FIN
close
close
closed
tim
ed w
ait
Transport Layer 3-101
TCP Connection Management (cont)
Step 3 client receives FIN replies with ACK
Enters ldquotimed waitrdquo -will respond with ACK to received FINs
Step 4 server receives ACK Connection closed
client
FIN
server
ACK
ACK
FIN
closing
closing
closed
tim
ed w
ait
closed
Transport Layer 3-102
TCP Connection Management (cont)
TCP clientlifecycle
TCP serverlifecycle
Transport Layer 3-103
Tuning TCPIP Parameters TCPIP parameters
A set of default values may not be optimal for all applicationsThe network administrator may wish to turn on or off some TCPIP functions for performance or security considerations
Many Unix and Linux systems provide some flexibility in tuning the TCPIP kernelsbinsysctl is used to configure the Linux kernel parameters at runtime
Default kernel configuration file is sbinsysctlconfFrequently used sysctl options
bull sysctl ndasha or sysctl ndashA list all current valuesbull sysctl ndashp file_name load the sysctl setting from a configuration
filebull sysctl ndashw variable=value change the value of the parameter
Transport Layer 3-104
SomeTCP Parameters in Linux Kerneltcp_syn_retries
Number of SYN packets the kernel will send before giving up on the new connection
tcp_synack_retriesnumber of SYN+ACK packets sent before the kernel gives up on the connection
tcp_window_scalingMaximum window size of 65535 bytes not enough for for really fast networks The window scaling options allows for almost gigabyte windows which is good for connections with large delay-bandwidth product
tcp_max_syn_backlogMaximal number of remembered connection requests which still did not receive an acknowledgment from connecting client
tcp_fin_timeoutHow many seconds to wait for a final FIN packet before the socket is closed required to prevent denial-of-service (DoS) attacks Default value is 60 seconds
Transport Layer 3-105
SomeTCP Parameters in Linux Kerneltcp_rmem
This is a vector of 3 integers [min default max] These parameters are used by TCP to dynamically adjust receive buffer sizesmin - minimum size of the receive buffer used by each TCP socket The default value is 4K default - the default size of the receive buffer for a TCP socket The default value is 87380 bytes and is lowered to 43689 in low memory systems If larger receive buffer sizes are desired this value should be increased max - the maximum size of the receive buffer used by each TCP socket The default value of 873802 bytes is lowered to 87380 in low memory systems
tcp_smemSend buffer parameters [min default max] similar to tcp_rmem
- Chapter 3 Transport Layer
- Transport services and protocols
- Transport vs network layer
- Internet transport-layer protocols
- Multiplexingdemultiplexing
- How demultiplexing works
- Connectionless demultiplexing
- Connection-oriented demux
- Connection-oriented demux (cont)
- Connection-oriented demux Threaded Web Server
- UDP User Datagram Protocol [RFC 768]
- UDP more
- UDP checksum
- Principles of Reliable data transfer
- Reliable data transfer getting started
- Reliable data transfer getting started
- Rdt10 reliable transfer over a reliable channel
- Rdt20 channel with bit errors
- rdt20 FSM specification
- rdt20 operation with no errors
- rdt20 error scenario
- rdt20 has a fatal flaw
- rdt21 sender handles garbled ACKNAKs
- rdt21 receiver handles garbled ACKNAKs
- rdt21 discussion
- rdt22 a NAK-free protocol
- rdt22 sender receiver fragments
- rdt30 channels with errors and loss
- rdt30 sender
- rdt30 in action
- rdt30 in action
- Performance of rdt30
- rdt30 stop-and-wait operation
- Pipelined protocols
- Pipelining increased utilization
- Go-Back-N
- GBN sender extended FSM
- GBN receiver extended FSM
- GBN inaction
- Selective Repeat
- Selective repeat sender receiver windows
- Selective repeat
- Selective repeat in action
- Selective repeat dilemma
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- TCP Overview RFCs 793 1122 1323 2018 2581
- TCP segment structure
- TCP seq rsquos and ACKs
- TCP Round Trip Time and Timeout
- TCP Round Trip Time and Timeout
- Example RTT estimation
- TCP Round Trip Time and Timeout
- TCP reliable data transfer
- TCP sender events
- TCP sender(simplified)
- TCP retransmission scenarios
- TCP retransmission scenarios (more)
- TCP ACK generation [RFC 1122 RFC 2581]
- Fast Retransmit
- Fast Retransmit
- Fast retransmit algorithm
- TCP Flow Control
- TCP Flow control how it works
- Sliding Window Flow Control Example
- Principles of Congestion Control
- Causescosts of congestion scenario 1
- Causescosts of congestion scenario 2
- Causescosts of congestion scenario 2
- Causescosts of congestion scenario 3
- Causescosts of congestion scenario 3
- Approaches towards congestion control
- TCP Congestion Control
- TCP congestion control bandwidth probing
- TCP Congestion Control details
- TCP Congestion Control more details
- TCP Slow Start Phase
- Slow Start Example
- TCP Congestion Avoidance Phase
- Congestion Avoidance
- Example Slow StartCongestion Avoidance
- Slow Start Congestion Avoidance
- Responses to Congestion
- Fast Recovery (differentiation btwn two loss events)
- TCP Congestion Control
- Popular ldquoflavorsrdquo of TCP
- Summary TCP Congestion Control
- TCP Congestion Control Summary
- TCP throughput
- TCP Futures TCP over ldquolong fat pipesrdquo
- TCP Fairness
- Why is TCP fair
- Fairness (more)
- TCP Connection Management
- TCP Connection Management (cont)
- TCP Connection Management (cont)
- TCP Connection Management (cont)
- Tuning TCPIP Parameters
- SomeTCP Parameters in Linux Kernel
- SomeTCP Parameters in Linux Kernel
-
Transport Layer 3-91
Popular ldquoflavorsrdquo of TCP
ssthresh
ssthresh
TCP Tahoe
TCP Reno
Transmission round
cwnd
win
dow
siz
e (in
seg
men
ts)
Transport Layer 3-92
Summary TCP Congestion ControlWhen CongWin is below Threshold sender in slow-start phase window grows exponentiallyWhen CongWin is above Threshold sender is in congestion-avoidance phase window grows linearlyWhen a triple duplicate ACK occurs Threshold set to CongWin2 and CongWin set to ThresholdWhen timeout occurs Threshold set to CongWin2 and CongWin is set to 1 MSS The actual sender window size is determined based on the congestion and flow control algorithms
SenderWin=min(RcvWinCongWin)
Transport Layer 3-93
TCP Congestion Control SummaryEvent State TCP Sender Action Commentary
ACK receipt for previously unackeddata
Slow Start (SS)
CongWin = CongWin + MSS If (CongWin gt Threshold)
set state to ldquoCongestion Avoidancerdquo
Resulting in a doubling of CongWin every RTT
ACK receipt for previously unackeddata
CongestionAvoidance (CA)
CongWin = CongWin+MSS (MSSCongWin)
Additive increase resulting in increase of CongWin by 1 MSS every RTT
Loss event detected by triple duplicate ACK
SS or CA Threshold = CongWin2 CongWin = ThresholdSet state to ldquoCongestion Avoidancerdquo
Fast recovery implementing multiplicative decrease CongWin will not drop below 1 MSS
Timeout SS or CA Threshold = CongWin2 CongWin = 1 MSSSet state to ldquoSlow Startrdquo
Enter slow start
Duplicate ACK
SS or CA Increment duplicate ACK count for segment being acked
CongWin and Threshold not changed
Transport Layer 3-94
TCP throughput
Q whatrsquos average throughout of TCP as function of window size RTT
ignoring slow startlet W be window size when loss occurs
when window is W throughput is WRTTjust after loss window drops to W2 throughput to W2RTT average throughout 75 WRTT
Transport Layer 3-95
TCP Futures TCP over ldquolong fat pipesrdquo
example 1500 byte segments 100ms RTT want 10 Gbps throughputrequires window size W = 83333 in-flight segmentsthroughput in terms of loss rate
L = 210-10 Wownew versions of TCP for high-speed
LRTTMSSsdot221
Transport Layer 3-96
Fairness goal if K TCP sessions share same bottleneck link of bandwidth R each should have average rate of RK
TCP connection 1
bottleneckrouter
capacity R
TCP connection 2
TCP Fairness
Transport Layer 3-97
Why is TCP fairTwo competing sessions
Additive increase gives slope of 1 as throughout increasesmultiplicative decrease decreases throughput proportionally
R
R
equal bandwidth share
Connection 1 throughput
Conn
ecti
on 2
thr
ough
p ut
congestion avoidance additive increaseloss decrease window by factor of 2
congestion avoidance additive increaseloss decrease window by factor of 2
Transport Layer 3-98
Fairness (more)Fairness and UDP
Multimedia apps often do not use TCP
do not want rate throttled by congestion control
Instead use UDPpump audiovideo at constant rate tolerate packet loss
Research area TCP friendly
Fairness and parallel TCP connectionsnothing prevents app from opening parallel cnctionsbetween 2 hostsWeb browsers do this Example link of rate R supporting 9 cnctions
new app asks for 1 TCP gets rate R10new app asks for 11 TCPs gets R2
Transport Layer 3-99
TCP Connection ManagementRecall TCP sender receiver
establish ldquoconnectionrdquobefore exchanging data segmentsinitialize TCP variables
seq sbuffers flow control info (eg RcvWindow)
client connection initiatorSocket clientSocket = new Socket(hostnameport
number)
server contacted by clientSocket connectionSocket = welcomeSocketaccept()
Three way handshakeStep 1 client host sends TCP
SYN segment to serverspecifies initial seq no data
Step 2 server host receives SYN replies with SYNACK segment
server allocates buffersspecifies server initial seq
Step 3 client receives SYNACK replies with ACK segment which may contain data
Transport Layer 3-100
TCP Connection Management (cont)
Closing a connection
client closes socketclientSocketclose()
Step 1 client end system sends TCP FIN control segment to server
Step 2 server receives FIN replies with ACK Closes connection sends FIN
client
FIN
server
ACK
ACK
FIN
close
close
closed
tim
ed w
ait
Transport Layer 3-101
TCP Connection Management (cont)
Step 3 client receives FIN replies with ACK
Enters ldquotimed waitrdquo -will respond with ACK to received FINs
Step 4 server receives ACK Connection closed
client
FIN
server
ACK
ACK
FIN
closing
closing
closed
tim
ed w
ait
closed
Transport Layer 3-102
TCP Connection Management (cont)
TCP clientlifecycle
TCP serverlifecycle
Transport Layer 3-103
Tuning TCPIP Parameters TCPIP parameters
A set of default values may not be optimal for all applicationsThe network administrator may wish to turn on or off some TCPIP functions for performance or security considerations
Many Unix and Linux systems provide some flexibility in tuning the TCPIP kernelsbinsysctl is used to configure the Linux kernel parameters at runtime
Default kernel configuration file is sbinsysctlconfFrequently used sysctl options
bull sysctl ndasha or sysctl ndashA list all current valuesbull sysctl ndashp file_name load the sysctl setting from a configuration
filebull sysctl ndashw variable=value change the value of the parameter
Transport Layer 3-104
SomeTCP Parameters in Linux Kerneltcp_syn_retries
Number of SYN packets the kernel will send before giving up on the new connection
tcp_synack_retriesnumber of SYN+ACK packets sent before the kernel gives up on the connection
tcp_window_scalingMaximum window size of 65535 bytes not enough for for really fast networks The window scaling options allows for almost gigabyte windows which is good for connections with large delay-bandwidth product
tcp_max_syn_backlogMaximal number of remembered connection requests which still did not receive an acknowledgment from connecting client
tcp_fin_timeoutHow many seconds to wait for a final FIN packet before the socket is closed required to prevent denial-of-service (DoS) attacks Default value is 60 seconds
Transport Layer 3-105
SomeTCP Parameters in Linux Kerneltcp_rmem
This is a vector of 3 integers [min default max] These parameters are used by TCP to dynamically adjust receive buffer sizesmin - minimum size of the receive buffer used by each TCP socket The default value is 4K default - the default size of the receive buffer for a TCP socket The default value is 87380 bytes and is lowered to 43689 in low memory systems If larger receive buffer sizes are desired this value should be increased max - the maximum size of the receive buffer used by each TCP socket The default value of 873802 bytes is lowered to 87380 in low memory systems
tcp_smemSend buffer parameters [min default max] similar to tcp_rmem
- Chapter 3 Transport Layer
- Transport services and protocols
- Transport vs network layer
- Internet transport-layer protocols
- Multiplexingdemultiplexing
- How demultiplexing works
- Connectionless demultiplexing
- Connection-oriented demux
- Connection-oriented demux (cont)
- Connection-oriented demux Threaded Web Server
- UDP User Datagram Protocol [RFC 768]
- UDP more
- UDP checksum
- Principles of Reliable data transfer
- Reliable data transfer getting started
- Reliable data transfer getting started
- Rdt10 reliable transfer over a reliable channel
- Rdt20 channel with bit errors
- rdt20 FSM specification
- rdt20 operation with no errors
- rdt20 error scenario
- rdt20 has a fatal flaw
- rdt21 sender handles garbled ACKNAKs
- rdt21 receiver handles garbled ACKNAKs
- rdt21 discussion
- rdt22 a NAK-free protocol
- rdt22 sender receiver fragments
- rdt30 channels with errors and loss
- rdt30 sender
- rdt30 in action
- rdt30 in action
- Performance of rdt30
- rdt30 stop-and-wait operation
- Pipelined protocols
- Pipelining increased utilization
- Go-Back-N
- GBN sender extended FSM
- GBN receiver extended FSM
- GBN inaction
- Selective Repeat
- Selective repeat sender receiver windows
- Selective repeat
- Selective repeat in action
- Selective repeat dilemma
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- TCP Overview RFCs 793 1122 1323 2018 2581
- TCP segment structure
- TCP seq rsquos and ACKs
- TCP Round Trip Time and Timeout
- TCP Round Trip Time and Timeout
- Example RTT estimation
- TCP Round Trip Time and Timeout
- TCP reliable data transfer
- TCP sender events
- TCP sender(simplified)
- TCP retransmission scenarios
- TCP retransmission scenarios (more)
- TCP ACK generation [RFC 1122 RFC 2581]
- Fast Retransmit
- Fast Retransmit
- Fast retransmit algorithm
- TCP Flow Control
- TCP Flow control how it works
- Sliding Window Flow Control Example
- Principles of Congestion Control
- Causescosts of congestion scenario 1
- Causescosts of congestion scenario 2
- Causescosts of congestion scenario 2
- Causescosts of congestion scenario 3
- Causescosts of congestion scenario 3
- Approaches towards congestion control
- TCP Congestion Control
- TCP congestion control bandwidth probing
- TCP Congestion Control details
- TCP Congestion Control more details
- TCP Slow Start Phase
- Slow Start Example
- TCP Congestion Avoidance Phase
- Congestion Avoidance
- Example Slow StartCongestion Avoidance
- Slow Start Congestion Avoidance
- Responses to Congestion
- Fast Recovery (differentiation btwn two loss events)
- TCP Congestion Control
- Popular ldquoflavorsrdquo of TCP
- Summary TCP Congestion Control
- TCP Congestion Control Summary
- TCP throughput
- TCP Futures TCP over ldquolong fat pipesrdquo
- TCP Fairness
- Why is TCP fair
- Fairness (more)
- TCP Connection Management
- TCP Connection Management (cont)
- TCP Connection Management (cont)
- TCP Connection Management (cont)
- Tuning TCPIP Parameters
- SomeTCP Parameters in Linux Kernel
- SomeTCP Parameters in Linux Kernel
-
Transport Layer 3-92
Summary TCP Congestion ControlWhen CongWin is below Threshold sender in slow-start phase window grows exponentiallyWhen CongWin is above Threshold sender is in congestion-avoidance phase window grows linearlyWhen a triple duplicate ACK occurs Threshold set to CongWin2 and CongWin set to ThresholdWhen timeout occurs Threshold set to CongWin2 and CongWin is set to 1 MSS The actual sender window size is determined based on the congestion and flow control algorithms
SenderWin=min(RcvWinCongWin)
Transport Layer 3-93
TCP Congestion Control SummaryEvent State TCP Sender Action Commentary
ACK receipt for previously unackeddata
Slow Start (SS)
CongWin = CongWin + MSS If (CongWin gt Threshold)
set state to ldquoCongestion Avoidancerdquo
Resulting in a doubling of CongWin every RTT
ACK receipt for previously unackeddata
CongestionAvoidance (CA)
CongWin = CongWin+MSS (MSSCongWin)
Additive increase resulting in increase of CongWin by 1 MSS every RTT
Loss event detected by triple duplicate ACK
SS or CA Threshold = CongWin2 CongWin = ThresholdSet state to ldquoCongestion Avoidancerdquo
Fast recovery implementing multiplicative decrease CongWin will not drop below 1 MSS
Timeout SS or CA Threshold = CongWin2 CongWin = 1 MSSSet state to ldquoSlow Startrdquo
Enter slow start
Duplicate ACK
SS or CA Increment duplicate ACK count for segment being acked
CongWin and Threshold not changed
Transport Layer 3-94
TCP throughput
Q whatrsquos average throughout of TCP as function of window size RTT
ignoring slow startlet W be window size when loss occurs
when window is W throughput is WRTTjust after loss window drops to W2 throughput to W2RTT average throughout 75 WRTT
Transport Layer 3-95
TCP Futures TCP over ldquolong fat pipesrdquo
example 1500 byte segments 100ms RTT want 10 Gbps throughputrequires window size W = 83333 in-flight segmentsthroughput in terms of loss rate
L = 210-10 Wownew versions of TCP for high-speed
LRTTMSSsdot221
Transport Layer 3-96
Fairness goal if K TCP sessions share same bottleneck link of bandwidth R each should have average rate of RK
TCP connection 1
bottleneckrouter
capacity R
TCP connection 2
TCP Fairness
Transport Layer 3-97
Why is TCP fairTwo competing sessions
Additive increase gives slope of 1 as throughout increasesmultiplicative decrease decreases throughput proportionally
R
R
equal bandwidth share
Connection 1 throughput
Conn
ecti
on 2
thr
ough
p ut
congestion avoidance additive increaseloss decrease window by factor of 2
congestion avoidance additive increaseloss decrease window by factor of 2
Transport Layer 3-98
Fairness (more)Fairness and UDP
Multimedia apps often do not use TCP
do not want rate throttled by congestion control
Instead use UDPpump audiovideo at constant rate tolerate packet loss
Research area TCP friendly
Fairness and parallel TCP connectionsnothing prevents app from opening parallel cnctionsbetween 2 hostsWeb browsers do this Example link of rate R supporting 9 cnctions
new app asks for 1 TCP gets rate R10new app asks for 11 TCPs gets R2
Transport Layer 3-99
TCP Connection ManagementRecall TCP sender receiver
establish ldquoconnectionrdquobefore exchanging data segmentsinitialize TCP variables
seq sbuffers flow control info (eg RcvWindow)
client connection initiatorSocket clientSocket = new Socket(hostnameport
number)
server contacted by clientSocket connectionSocket = welcomeSocketaccept()
Three way handshakeStep 1 client host sends TCP
SYN segment to serverspecifies initial seq no data
Step 2 server host receives SYN replies with SYNACK segment
server allocates buffersspecifies server initial seq
Step 3 client receives SYNACK replies with ACK segment which may contain data
Transport Layer 3-100
TCP Connection Management (cont)
Closing a connection
client closes socketclientSocketclose()
Step 1 client end system sends TCP FIN control segment to server
Step 2 server receives FIN replies with ACK Closes connection sends FIN
client
FIN
server
ACK
ACK
FIN
close
close
closed
tim
ed w
ait
Transport Layer 3-101
TCP Connection Management (cont)
Step 3 client receives FIN replies with ACK
Enters ldquotimed waitrdquo -will respond with ACK to received FINs
Step 4 server receives ACK Connection closed
client
FIN
server
ACK
ACK
FIN
closing
closing
closed
tim
ed w
ait
closed
Transport Layer 3-102
TCP Connection Management (cont)
TCP clientlifecycle
TCP serverlifecycle
Transport Layer 3-103
Tuning TCPIP Parameters TCPIP parameters
A set of default values may not be optimal for all applicationsThe network administrator may wish to turn on or off some TCPIP functions for performance or security considerations
Many Unix and Linux systems provide some flexibility in tuning the TCPIP kernelsbinsysctl is used to configure the Linux kernel parameters at runtime
Default kernel configuration file is sbinsysctlconfFrequently used sysctl options
bull sysctl ndasha or sysctl ndashA list all current valuesbull sysctl ndashp file_name load the sysctl setting from a configuration
filebull sysctl ndashw variable=value change the value of the parameter
Transport Layer 3-104
SomeTCP Parameters in Linux Kerneltcp_syn_retries
Number of SYN packets the kernel will send before giving up on the new connection
tcp_synack_retriesnumber of SYN+ACK packets sent before the kernel gives up on the connection
tcp_window_scalingMaximum window size of 65535 bytes not enough for for really fast networks The window scaling options allows for almost gigabyte windows which is good for connections with large delay-bandwidth product
tcp_max_syn_backlogMaximal number of remembered connection requests which still did not receive an acknowledgment from connecting client
tcp_fin_timeoutHow many seconds to wait for a final FIN packet before the socket is closed required to prevent denial-of-service (DoS) attacks Default value is 60 seconds
Transport Layer 3-105
SomeTCP Parameters in Linux Kerneltcp_rmem
This is a vector of 3 integers [min default max] These parameters are used by TCP to dynamically adjust receive buffer sizesmin - minimum size of the receive buffer used by each TCP socket The default value is 4K default - the default size of the receive buffer for a TCP socket The default value is 87380 bytes and is lowered to 43689 in low memory systems If larger receive buffer sizes are desired this value should be increased max - the maximum size of the receive buffer used by each TCP socket The default value of 873802 bytes is lowered to 87380 in low memory systems
tcp_smemSend buffer parameters [min default max] similar to tcp_rmem
- Chapter 3 Transport Layer
- Transport services and protocols
- Transport vs network layer
- Internet transport-layer protocols
- Multiplexingdemultiplexing
- How demultiplexing works
- Connectionless demultiplexing
- Connection-oriented demux
- Connection-oriented demux (cont)
- Connection-oriented demux Threaded Web Server
- UDP User Datagram Protocol [RFC 768]
- UDP more
- UDP checksum
- Principles of Reliable data transfer
- Reliable data transfer getting started
- Reliable data transfer getting started
- Rdt10 reliable transfer over a reliable channel
- Rdt20 channel with bit errors
- rdt20 FSM specification
- rdt20 operation with no errors
- rdt20 error scenario
- rdt20 has a fatal flaw
- rdt21 sender handles garbled ACKNAKs
- rdt21 receiver handles garbled ACKNAKs
- rdt21 discussion
- rdt22 a NAK-free protocol
- rdt22 sender receiver fragments
- rdt30 channels with errors and loss
- rdt30 sender
- rdt30 in action
- rdt30 in action
- Performance of rdt30
- rdt30 stop-and-wait operation
- Pipelined protocols
- Pipelining increased utilization
- Go-Back-N
- GBN sender extended FSM
- GBN receiver extended FSM
- GBN inaction
- Selective Repeat
- Selective repeat sender receiver windows
- Selective repeat
- Selective repeat in action
- Selective repeat dilemma
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- TCP Overview RFCs 793 1122 1323 2018 2581
- TCP segment structure
- TCP seq rsquos and ACKs
- TCP Round Trip Time and Timeout
- TCP Round Trip Time and Timeout
- Example RTT estimation
- TCP Round Trip Time and Timeout
- TCP reliable data transfer
- TCP sender events
- TCP sender(simplified)
- TCP retransmission scenarios
- TCP retransmission scenarios (more)
- TCP ACK generation [RFC 1122 RFC 2581]
- Fast Retransmit
- Fast Retransmit
- Fast retransmit algorithm
- TCP Flow Control
- TCP Flow control how it works
- Sliding Window Flow Control Example
- Principles of Congestion Control
- Causescosts of congestion scenario 1
- Causescosts of congestion scenario 2
- Causescosts of congestion scenario 2
- Causescosts of congestion scenario 3
- Causescosts of congestion scenario 3
- Approaches towards congestion control
- TCP Congestion Control
- TCP congestion control bandwidth probing
- TCP Congestion Control details
- TCP Congestion Control more details
- TCP Slow Start Phase
- Slow Start Example
- TCP Congestion Avoidance Phase
- Congestion Avoidance
- Example Slow StartCongestion Avoidance
- Slow Start Congestion Avoidance
- Responses to Congestion
- Fast Recovery (differentiation btwn two loss events)
- TCP Congestion Control
- Popular ldquoflavorsrdquo of TCP
- Summary TCP Congestion Control
- TCP Congestion Control Summary
- TCP throughput
- TCP Futures TCP over ldquolong fat pipesrdquo
- TCP Fairness
- Why is TCP fair
- Fairness (more)
- TCP Connection Management
- TCP Connection Management (cont)
- TCP Connection Management (cont)
- TCP Connection Management (cont)
- Tuning TCPIP Parameters
- SomeTCP Parameters in Linux Kernel
- SomeTCP Parameters in Linux Kernel
-
Transport Layer 3-93
TCP Congestion Control SummaryEvent State TCP Sender Action Commentary
ACK receipt for previously unackeddata
Slow Start (SS)
CongWin = CongWin + MSS If (CongWin gt Threshold)
set state to ldquoCongestion Avoidancerdquo
Resulting in a doubling of CongWin every RTT
ACK receipt for previously unackeddata
CongestionAvoidance (CA)
CongWin = CongWin+MSS (MSSCongWin)
Additive increase resulting in increase of CongWin by 1 MSS every RTT
Loss event detected by triple duplicate ACK
SS or CA Threshold = CongWin2 CongWin = ThresholdSet state to ldquoCongestion Avoidancerdquo
Fast recovery implementing multiplicative decrease CongWin will not drop below 1 MSS
Timeout SS or CA Threshold = CongWin2 CongWin = 1 MSSSet state to ldquoSlow Startrdquo
Enter slow start
Duplicate ACK
SS or CA Increment duplicate ACK count for segment being acked
CongWin and Threshold not changed
Transport Layer 3-94
TCP throughput
Q whatrsquos average throughout of TCP as function of window size RTT
ignoring slow startlet W be window size when loss occurs
when window is W throughput is WRTTjust after loss window drops to W2 throughput to W2RTT average throughout 75 WRTT
Transport Layer 3-95
TCP Futures TCP over ldquolong fat pipesrdquo
example 1500 byte segments 100ms RTT want 10 Gbps throughputrequires window size W = 83333 in-flight segmentsthroughput in terms of loss rate
L = 210-10 Wownew versions of TCP for high-speed
LRTTMSSsdot221
Transport Layer 3-96
Fairness goal if K TCP sessions share same bottleneck link of bandwidth R each should have average rate of RK
TCP connection 1
bottleneckrouter
capacity R
TCP connection 2
TCP Fairness
Transport Layer 3-97
Why is TCP fairTwo competing sessions
Additive increase gives slope of 1 as throughout increasesmultiplicative decrease decreases throughput proportionally
R
R
equal bandwidth share
Connection 1 throughput
Conn
ecti
on 2
thr
ough
p ut
congestion avoidance additive increaseloss decrease window by factor of 2
congestion avoidance additive increaseloss decrease window by factor of 2
Transport Layer 3-98
Fairness (more)Fairness and UDP
Multimedia apps often do not use TCP
do not want rate throttled by congestion control
Instead use UDPpump audiovideo at constant rate tolerate packet loss
Research area TCP friendly
Fairness and parallel TCP connectionsnothing prevents app from opening parallel cnctionsbetween 2 hostsWeb browsers do this Example link of rate R supporting 9 cnctions
new app asks for 1 TCP gets rate R10new app asks for 11 TCPs gets R2
Transport Layer 3-99
TCP Connection ManagementRecall TCP sender receiver
establish ldquoconnectionrdquobefore exchanging data segmentsinitialize TCP variables
seq sbuffers flow control info (eg RcvWindow)
client connection initiatorSocket clientSocket = new Socket(hostnameport
number)
server contacted by clientSocket connectionSocket = welcomeSocketaccept()
Three way handshakeStep 1 client host sends TCP
SYN segment to serverspecifies initial seq no data
Step 2 server host receives SYN replies with SYNACK segment
server allocates buffersspecifies server initial seq
Step 3 client receives SYNACK replies with ACK segment which may contain data
Transport Layer 3-100
TCP Connection Management (cont)
Closing a connection
client closes socketclientSocketclose()
Step 1 client end system sends TCP FIN control segment to server
Step 2 server receives FIN replies with ACK Closes connection sends FIN
client
FIN
server
ACK
ACK
FIN
close
close
closed
tim
ed w
ait
Transport Layer 3-101
TCP Connection Management (cont)
Step 3 client receives FIN replies with ACK
Enters ldquotimed waitrdquo -will respond with ACK to received FINs
Step 4 server receives ACK Connection closed
client
FIN
server
ACK
ACK
FIN
closing
closing
closed
tim
ed w
ait
closed
Transport Layer 3-102
TCP Connection Management (cont)
TCP clientlifecycle
TCP serverlifecycle
Transport Layer 3-103
Tuning TCPIP Parameters TCPIP parameters
A set of default values may not be optimal for all applicationsThe network administrator may wish to turn on or off some TCPIP functions for performance or security considerations
Many Unix and Linux systems provide some flexibility in tuning the TCPIP kernelsbinsysctl is used to configure the Linux kernel parameters at runtime
Default kernel configuration file is sbinsysctlconfFrequently used sysctl options
bull sysctl ndasha or sysctl ndashA list all current valuesbull sysctl ndashp file_name load the sysctl setting from a configuration
filebull sysctl ndashw variable=value change the value of the parameter
Transport Layer 3-104
SomeTCP Parameters in Linux Kerneltcp_syn_retries
Number of SYN packets the kernel will send before giving up on the new connection
tcp_synack_retriesnumber of SYN+ACK packets sent before the kernel gives up on the connection
tcp_window_scalingMaximum window size of 65535 bytes not enough for for really fast networks The window scaling options allows for almost gigabyte windows which is good for connections with large delay-bandwidth product
tcp_max_syn_backlogMaximal number of remembered connection requests which still did not receive an acknowledgment from connecting client
tcp_fin_timeoutHow many seconds to wait for a final FIN packet before the socket is closed required to prevent denial-of-service (DoS) attacks Default value is 60 seconds
Transport Layer 3-105
SomeTCP Parameters in Linux Kerneltcp_rmem
This is a vector of 3 integers [min default max] These parameters are used by TCP to dynamically adjust receive buffer sizesmin - minimum size of the receive buffer used by each TCP socket The default value is 4K default - the default size of the receive buffer for a TCP socket The default value is 87380 bytes and is lowered to 43689 in low memory systems If larger receive buffer sizes are desired this value should be increased max - the maximum size of the receive buffer used by each TCP socket The default value of 873802 bytes is lowered to 87380 in low memory systems
tcp_smemSend buffer parameters [min default max] similar to tcp_rmem
- Chapter 3 Transport Layer
- Transport services and protocols
- Transport vs network layer
- Internet transport-layer protocols
- Multiplexingdemultiplexing
- How demultiplexing works
- Connectionless demultiplexing
- Connection-oriented demux
- Connection-oriented demux (cont)
- Connection-oriented demux Threaded Web Server
- UDP User Datagram Protocol [RFC 768]
- UDP more
- UDP checksum
- Principles of Reliable data transfer
- Reliable data transfer getting started
- Reliable data transfer getting started
- Rdt10 reliable transfer over a reliable channel
- Rdt20 channel with bit errors
- rdt20 FSM specification
- rdt20 operation with no errors
- rdt20 error scenario
- rdt20 has a fatal flaw
- rdt21 sender handles garbled ACKNAKs
- rdt21 receiver handles garbled ACKNAKs
- rdt21 discussion
- rdt22 a NAK-free protocol
- rdt22 sender receiver fragments
- rdt30 channels with errors and loss
- rdt30 sender
- rdt30 in action
- rdt30 in action
- Performance of rdt30
- rdt30 stop-and-wait operation
- Pipelined protocols
- Pipelining increased utilization
- Go-Back-N
- GBN sender extended FSM
- GBN receiver extended FSM
- GBN inaction
- Selective Repeat
- Selective repeat sender receiver windows
- Selective repeat
- Selective repeat in action
- Selective repeat dilemma
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- TCP Overview RFCs 793 1122 1323 2018 2581
- TCP segment structure
- TCP seq rsquos and ACKs
- TCP Round Trip Time and Timeout
- TCP Round Trip Time and Timeout
- Example RTT estimation
- TCP Round Trip Time and Timeout
- TCP reliable data transfer
- TCP sender events
- TCP sender(simplified)
- TCP retransmission scenarios
- TCP retransmission scenarios (more)
- TCP ACK generation [RFC 1122 RFC 2581]
- Fast Retransmit
- Fast Retransmit
- Fast retransmit algorithm
- TCP Flow Control
- TCP Flow control how it works
- Sliding Window Flow Control Example
- Principles of Congestion Control
- Causescosts of congestion scenario 1
- Causescosts of congestion scenario 2
- Causescosts of congestion scenario 2
- Causescosts of congestion scenario 3
- Causescosts of congestion scenario 3
- Approaches towards congestion control
- TCP Congestion Control
- TCP congestion control bandwidth probing
- TCP Congestion Control details
- TCP Congestion Control more details
- TCP Slow Start Phase
- Slow Start Example
- TCP Congestion Avoidance Phase
- Congestion Avoidance
- Example Slow StartCongestion Avoidance
- Slow Start Congestion Avoidance
- Responses to Congestion
- Fast Recovery (differentiation btwn two loss events)
- TCP Congestion Control
- Popular ldquoflavorsrdquo of TCP
- Summary TCP Congestion Control
- TCP Congestion Control Summary
- TCP throughput
- TCP Futures TCP over ldquolong fat pipesrdquo
- TCP Fairness
- Why is TCP fair
- Fairness (more)
- TCP Connection Management
- TCP Connection Management (cont)
- TCP Connection Management (cont)
- TCP Connection Management (cont)
- Tuning TCPIP Parameters
- SomeTCP Parameters in Linux Kernel
- SomeTCP Parameters in Linux Kernel
-
Transport Layer 3-94
TCP throughput
Q whatrsquos average throughout of TCP as function of window size RTT
ignoring slow startlet W be window size when loss occurs
when window is W throughput is WRTTjust after loss window drops to W2 throughput to W2RTT average throughout 75 WRTT
Transport Layer 3-95
TCP Futures TCP over ldquolong fat pipesrdquo
example 1500 byte segments 100ms RTT want 10 Gbps throughputrequires window size W = 83333 in-flight segmentsthroughput in terms of loss rate
L = 210-10 Wownew versions of TCP for high-speed
LRTTMSSsdot221
Transport Layer 3-96
Fairness goal if K TCP sessions share same bottleneck link of bandwidth R each should have average rate of RK
TCP connection 1
bottleneckrouter
capacity R
TCP connection 2
TCP Fairness
Transport Layer 3-97
Why is TCP fairTwo competing sessions
Additive increase gives slope of 1 as throughout increasesmultiplicative decrease decreases throughput proportionally
R
R
equal bandwidth share
Connection 1 throughput
Conn
ecti
on 2
thr
ough
p ut
congestion avoidance additive increaseloss decrease window by factor of 2
congestion avoidance additive increaseloss decrease window by factor of 2
Transport Layer 3-98
Fairness (more)Fairness and UDP
Multimedia apps often do not use TCP
do not want rate throttled by congestion control
Instead use UDPpump audiovideo at constant rate tolerate packet loss
Research area TCP friendly
Fairness and parallel TCP connectionsnothing prevents app from opening parallel cnctionsbetween 2 hostsWeb browsers do this Example link of rate R supporting 9 cnctions
new app asks for 1 TCP gets rate R10new app asks for 11 TCPs gets R2
Transport Layer 3-99
TCP Connection ManagementRecall TCP sender receiver
establish ldquoconnectionrdquobefore exchanging data segmentsinitialize TCP variables
seq sbuffers flow control info (eg RcvWindow)
client connection initiatorSocket clientSocket = new Socket(hostnameport
number)
server contacted by clientSocket connectionSocket = welcomeSocketaccept()
Three way handshakeStep 1 client host sends TCP
SYN segment to serverspecifies initial seq no data
Step 2 server host receives SYN replies with SYNACK segment
server allocates buffersspecifies server initial seq
Step 3 client receives SYNACK replies with ACK segment which may contain data
Transport Layer 3-100
TCP Connection Management (cont)
Closing a connection
client closes socketclientSocketclose()
Step 1 client end system sends TCP FIN control segment to server
Step 2 server receives FIN replies with ACK Closes connection sends FIN
client
FIN
server
ACK
ACK
FIN
close
close
closed
tim
ed w
ait
Transport Layer 3-101
TCP Connection Management (cont)
Step 3 client receives FIN replies with ACK
Enters ldquotimed waitrdquo -will respond with ACK to received FINs
Step 4 server receives ACK Connection closed
client
FIN
server
ACK
ACK
FIN
closing
closing
closed
tim
ed w
ait
closed
Transport Layer 3-102
TCP Connection Management (cont)
TCP clientlifecycle
TCP serverlifecycle
Transport Layer 3-103
Tuning TCPIP Parameters TCPIP parameters
A set of default values may not be optimal for all applicationsThe network administrator may wish to turn on or off some TCPIP functions for performance or security considerations
Many Unix and Linux systems provide some flexibility in tuning the TCPIP kernelsbinsysctl is used to configure the Linux kernel parameters at runtime
Default kernel configuration file is sbinsysctlconfFrequently used sysctl options
bull sysctl ndasha or sysctl ndashA list all current valuesbull sysctl ndashp file_name load the sysctl setting from a configuration
filebull sysctl ndashw variable=value change the value of the parameter
Transport Layer 3-104
SomeTCP Parameters in Linux Kerneltcp_syn_retries
Number of SYN packets the kernel will send before giving up on the new connection
tcp_synack_retriesnumber of SYN+ACK packets sent before the kernel gives up on the connection
tcp_window_scalingMaximum window size of 65535 bytes not enough for for really fast networks The window scaling options allows for almost gigabyte windows which is good for connections with large delay-bandwidth product
tcp_max_syn_backlogMaximal number of remembered connection requests which still did not receive an acknowledgment from connecting client
tcp_fin_timeoutHow many seconds to wait for a final FIN packet before the socket is closed required to prevent denial-of-service (DoS) attacks Default value is 60 seconds
Transport Layer 3-105
SomeTCP Parameters in Linux Kerneltcp_rmem
This is a vector of 3 integers [min default max] These parameters are used by TCP to dynamically adjust receive buffer sizesmin - minimum size of the receive buffer used by each TCP socket The default value is 4K default - the default size of the receive buffer for a TCP socket The default value is 87380 bytes and is lowered to 43689 in low memory systems If larger receive buffer sizes are desired this value should be increased max - the maximum size of the receive buffer used by each TCP socket The default value of 873802 bytes is lowered to 87380 in low memory systems
tcp_smemSend buffer parameters [min default max] similar to tcp_rmem
- Chapter 3 Transport Layer
- Transport services and protocols
- Transport vs network layer
- Internet transport-layer protocols
- Multiplexingdemultiplexing
- How demultiplexing works
- Connectionless demultiplexing
- Connection-oriented demux
- Connection-oriented demux (cont)
- Connection-oriented demux Threaded Web Server
- UDP User Datagram Protocol [RFC 768]
- UDP more
- UDP checksum
- Principles of Reliable data transfer
- Reliable data transfer getting started
- Reliable data transfer getting started
- Rdt10 reliable transfer over a reliable channel
- Rdt20 channel with bit errors
- rdt20 FSM specification
- rdt20 operation with no errors
- rdt20 error scenario
- rdt20 has a fatal flaw
- rdt21 sender handles garbled ACKNAKs
- rdt21 receiver handles garbled ACKNAKs
- rdt21 discussion
- rdt22 a NAK-free protocol
- rdt22 sender receiver fragments
- rdt30 channels with errors and loss
- rdt30 sender
- rdt30 in action
- rdt30 in action
- Performance of rdt30
- rdt30 stop-and-wait operation
- Pipelined protocols
- Pipelining increased utilization
- Go-Back-N
- GBN sender extended FSM
- GBN receiver extended FSM
- GBN inaction
- Selective Repeat
- Selective repeat sender receiver windows
- Selective repeat
- Selective repeat in action
- Selective repeat dilemma
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- TCP Overview RFCs 793 1122 1323 2018 2581
- TCP segment structure
- TCP seq rsquos and ACKs
- TCP Round Trip Time and Timeout
- TCP Round Trip Time and Timeout
- Example RTT estimation
- TCP Round Trip Time and Timeout
- TCP reliable data transfer
- TCP sender events
- TCP sender(simplified)
- TCP retransmission scenarios
- TCP retransmission scenarios (more)
- TCP ACK generation [RFC 1122 RFC 2581]
- Fast Retransmit
- Fast Retransmit
- Fast retransmit algorithm
- TCP Flow Control
- TCP Flow control how it works
- Sliding Window Flow Control Example
- Principles of Congestion Control
- Causescosts of congestion scenario 1
- Causescosts of congestion scenario 2
- Causescosts of congestion scenario 2
- Causescosts of congestion scenario 3
- Causescosts of congestion scenario 3
- Approaches towards congestion control
- TCP Congestion Control
- TCP congestion control bandwidth probing
- TCP Congestion Control details
- TCP Congestion Control more details
- TCP Slow Start Phase
- Slow Start Example
- TCP Congestion Avoidance Phase
- Congestion Avoidance
- Example Slow StartCongestion Avoidance
- Slow Start Congestion Avoidance
- Responses to Congestion
- Fast Recovery (differentiation btwn two loss events)
- TCP Congestion Control
- Popular ldquoflavorsrdquo of TCP
- Summary TCP Congestion Control
- TCP Congestion Control Summary
- TCP throughput
- TCP Futures TCP over ldquolong fat pipesrdquo
- TCP Fairness
- Why is TCP fair
- Fairness (more)
- TCP Connection Management
- TCP Connection Management (cont)
- TCP Connection Management (cont)
- TCP Connection Management (cont)
- Tuning TCPIP Parameters
- SomeTCP Parameters in Linux Kernel
- SomeTCP Parameters in Linux Kernel
-
Transport Layer 3-95
TCP Futures TCP over ldquolong fat pipesrdquo
example 1500 byte segments 100ms RTT want 10 Gbps throughputrequires window size W = 83333 in-flight segmentsthroughput in terms of loss rate
L = 210-10 Wownew versions of TCP for high-speed
LRTTMSSsdot221
Transport Layer 3-96
Fairness goal if K TCP sessions share same bottleneck link of bandwidth R each should have average rate of RK
TCP connection 1
bottleneckrouter
capacity R
TCP connection 2
TCP Fairness
Transport Layer 3-97
Why is TCP fairTwo competing sessions
Additive increase gives slope of 1 as throughout increasesmultiplicative decrease decreases throughput proportionally
R
R
equal bandwidth share
Connection 1 throughput
Conn
ecti
on 2
thr
ough
p ut
congestion avoidance additive increaseloss decrease window by factor of 2
congestion avoidance additive increaseloss decrease window by factor of 2
Transport Layer 3-98
Fairness (more)Fairness and UDP
Multimedia apps often do not use TCP
do not want rate throttled by congestion control
Instead use UDPpump audiovideo at constant rate tolerate packet loss
Research area TCP friendly
Fairness and parallel TCP connectionsnothing prevents app from opening parallel cnctionsbetween 2 hostsWeb browsers do this Example link of rate R supporting 9 cnctions
new app asks for 1 TCP gets rate R10new app asks for 11 TCPs gets R2
Transport Layer 3-99
TCP Connection ManagementRecall TCP sender receiver
establish ldquoconnectionrdquobefore exchanging data segmentsinitialize TCP variables
seq sbuffers flow control info (eg RcvWindow)
client connection initiatorSocket clientSocket = new Socket(hostnameport
number)
server contacted by clientSocket connectionSocket = welcomeSocketaccept()
Three way handshakeStep 1 client host sends TCP
SYN segment to serverspecifies initial seq no data
Step 2 server host receives SYN replies with SYNACK segment
server allocates buffersspecifies server initial seq
Step 3 client receives SYNACK replies with ACK segment which may contain data
Transport Layer 3-100
TCP Connection Management (cont)
Closing a connection
client closes socketclientSocketclose()
Step 1 client end system sends TCP FIN control segment to server
Step 2 server receives FIN replies with ACK Closes connection sends FIN
client
FIN
server
ACK
ACK
FIN
close
close
closed
tim
ed w
ait
Transport Layer 3-101
TCP Connection Management (cont)
Step 3 client receives FIN replies with ACK
Enters ldquotimed waitrdquo -will respond with ACK to received FINs
Step 4 server receives ACK Connection closed
client
FIN
server
ACK
ACK
FIN
closing
closing
closed
tim
ed w
ait
closed
Transport Layer 3-102
TCP Connection Management (cont)
TCP clientlifecycle
TCP serverlifecycle
Transport Layer 3-103
Tuning TCPIP Parameters TCPIP parameters
A set of default values may not be optimal for all applicationsThe network administrator may wish to turn on or off some TCPIP functions for performance or security considerations
Many Unix and Linux systems provide some flexibility in tuning the TCPIP kernelsbinsysctl is used to configure the Linux kernel parameters at runtime
Default kernel configuration file is sbinsysctlconfFrequently used sysctl options
bull sysctl ndasha or sysctl ndashA list all current valuesbull sysctl ndashp file_name load the sysctl setting from a configuration
filebull sysctl ndashw variable=value change the value of the parameter
Transport Layer 3-104
SomeTCP Parameters in Linux Kerneltcp_syn_retries
Number of SYN packets the kernel will send before giving up on the new connection
tcp_synack_retriesnumber of SYN+ACK packets sent before the kernel gives up on the connection
tcp_window_scalingMaximum window size of 65535 bytes not enough for for really fast networks The window scaling options allows for almost gigabyte windows which is good for connections with large delay-bandwidth product
tcp_max_syn_backlogMaximal number of remembered connection requests which still did not receive an acknowledgment from connecting client
tcp_fin_timeoutHow many seconds to wait for a final FIN packet before the socket is closed required to prevent denial-of-service (DoS) attacks Default value is 60 seconds
Transport Layer 3-105
SomeTCP Parameters in Linux Kerneltcp_rmem
This is a vector of 3 integers [min default max] These parameters are used by TCP to dynamically adjust receive buffer sizesmin - minimum size of the receive buffer used by each TCP socket The default value is 4K default - the default size of the receive buffer for a TCP socket The default value is 87380 bytes and is lowered to 43689 in low memory systems If larger receive buffer sizes are desired this value should be increased max - the maximum size of the receive buffer used by each TCP socket The default value of 873802 bytes is lowered to 87380 in low memory systems
tcp_smemSend buffer parameters [min default max] similar to tcp_rmem
- Chapter 3 Transport Layer
- Transport services and protocols
- Transport vs network layer
- Internet transport-layer protocols
- Multiplexingdemultiplexing
- How demultiplexing works
- Connectionless demultiplexing
- Connection-oriented demux
- Connection-oriented demux (cont)
- Connection-oriented demux Threaded Web Server
- UDP User Datagram Protocol [RFC 768]
- UDP more
- UDP checksum
- Principles of Reliable data transfer
- Reliable data transfer getting started
- Reliable data transfer getting started
- Rdt10 reliable transfer over a reliable channel
- Rdt20 channel with bit errors
- rdt20 FSM specification
- rdt20 operation with no errors
- rdt20 error scenario
- rdt20 has a fatal flaw
- rdt21 sender handles garbled ACKNAKs
- rdt21 receiver handles garbled ACKNAKs
- rdt21 discussion
- rdt22 a NAK-free protocol
- rdt22 sender receiver fragments
- rdt30 channels with errors and loss
- rdt30 sender
- rdt30 in action
- rdt30 in action
- Performance of rdt30
- rdt30 stop-and-wait operation
- Pipelined protocols
- Pipelining increased utilization
- Go-Back-N
- GBN sender extended FSM
- GBN receiver extended FSM
- GBN inaction
- Selective Repeat
- Selective repeat sender receiver windows
- Selective repeat
- Selective repeat in action
- Selective repeat dilemma
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- TCP Overview RFCs 793 1122 1323 2018 2581
- TCP segment structure
- TCP seq rsquos and ACKs
- TCP Round Trip Time and Timeout
- TCP Round Trip Time and Timeout
- Example RTT estimation
- TCP Round Trip Time and Timeout
- TCP reliable data transfer
- TCP sender events
- TCP sender(simplified)
- TCP retransmission scenarios
- TCP retransmission scenarios (more)
- TCP ACK generation [RFC 1122 RFC 2581]
- Fast Retransmit
- Fast Retransmit
- Fast retransmit algorithm
- TCP Flow Control
- TCP Flow control how it works
- Sliding Window Flow Control Example
- Principles of Congestion Control
- Causescosts of congestion scenario 1
- Causescosts of congestion scenario 2
- Causescosts of congestion scenario 2
- Causescosts of congestion scenario 3
- Causescosts of congestion scenario 3
- Approaches towards congestion control
- TCP Congestion Control
- TCP congestion control bandwidth probing
- TCP Congestion Control details
- TCP Congestion Control more details
- TCP Slow Start Phase
- Slow Start Example
- TCP Congestion Avoidance Phase
- Congestion Avoidance
- Example Slow StartCongestion Avoidance
- Slow Start Congestion Avoidance
- Responses to Congestion
- Fast Recovery (differentiation btwn two loss events)
- TCP Congestion Control
- Popular ldquoflavorsrdquo of TCP
- Summary TCP Congestion Control
- TCP Congestion Control Summary
- TCP throughput
- TCP Futures TCP over ldquolong fat pipesrdquo
- TCP Fairness
- Why is TCP fair
- Fairness (more)
- TCP Connection Management
- TCP Connection Management (cont)
- TCP Connection Management (cont)
- TCP Connection Management (cont)
- Tuning TCPIP Parameters
- SomeTCP Parameters in Linux Kernel
- SomeTCP Parameters in Linux Kernel
-
Transport Layer 3-96
Fairness goal if K TCP sessions share same bottleneck link of bandwidth R each should have average rate of RK
TCP connection 1
bottleneckrouter
capacity R
TCP connection 2
TCP Fairness
Transport Layer 3-97
Why is TCP fairTwo competing sessions
Additive increase gives slope of 1 as throughout increasesmultiplicative decrease decreases throughput proportionally
R
R
equal bandwidth share
Connection 1 throughput
Conn
ecti
on 2
thr
ough
p ut
congestion avoidance additive increaseloss decrease window by factor of 2
congestion avoidance additive increaseloss decrease window by factor of 2
Transport Layer 3-98
Fairness (more)Fairness and UDP
Multimedia apps often do not use TCP
do not want rate throttled by congestion control
Instead use UDPpump audiovideo at constant rate tolerate packet loss
Research area TCP friendly
Fairness and parallel TCP connectionsnothing prevents app from opening parallel cnctionsbetween 2 hostsWeb browsers do this Example link of rate R supporting 9 cnctions
new app asks for 1 TCP gets rate R10new app asks for 11 TCPs gets R2
Transport Layer 3-99
TCP Connection ManagementRecall TCP sender receiver
establish ldquoconnectionrdquobefore exchanging data segmentsinitialize TCP variables
seq sbuffers flow control info (eg RcvWindow)
client connection initiatorSocket clientSocket = new Socket(hostnameport
number)
server contacted by clientSocket connectionSocket = welcomeSocketaccept()
Three way handshakeStep 1 client host sends TCP
SYN segment to serverspecifies initial seq no data
Step 2 server host receives SYN replies with SYNACK segment
server allocates buffersspecifies server initial seq
Step 3 client receives SYNACK replies with ACK segment which may contain data
Transport Layer 3-100
TCP Connection Management (cont)
Closing a connection
client closes socketclientSocketclose()
Step 1 client end system sends TCP FIN control segment to server
Step 2 server receives FIN replies with ACK Closes connection sends FIN
client
FIN
server
ACK
ACK
FIN
close
close
closed
tim
ed w
ait
Transport Layer 3-101
TCP Connection Management (cont)
Step 3 client receives FIN replies with ACK
Enters ldquotimed waitrdquo -will respond with ACK to received FINs
Step 4 server receives ACK Connection closed
client
FIN
server
ACK
ACK
FIN
closing
closing
closed
tim
ed w
ait
closed
Transport Layer 3-102
TCP Connection Management (cont)
TCP clientlifecycle
TCP serverlifecycle
Transport Layer 3-103
Tuning TCPIP Parameters TCPIP parameters
A set of default values may not be optimal for all applicationsThe network administrator may wish to turn on or off some TCPIP functions for performance or security considerations
Many Unix and Linux systems provide some flexibility in tuning the TCPIP kernelsbinsysctl is used to configure the Linux kernel parameters at runtime
Default kernel configuration file is sbinsysctlconfFrequently used sysctl options
bull sysctl ndasha or sysctl ndashA list all current valuesbull sysctl ndashp file_name load the sysctl setting from a configuration
filebull sysctl ndashw variable=value change the value of the parameter
Transport Layer 3-104
SomeTCP Parameters in Linux Kerneltcp_syn_retries
Number of SYN packets the kernel will send before giving up on the new connection
tcp_synack_retriesnumber of SYN+ACK packets sent before the kernel gives up on the connection
tcp_window_scalingMaximum window size of 65535 bytes not enough for for really fast networks The window scaling options allows for almost gigabyte windows which is good for connections with large delay-bandwidth product
tcp_max_syn_backlogMaximal number of remembered connection requests which still did not receive an acknowledgment from connecting client
tcp_fin_timeoutHow many seconds to wait for a final FIN packet before the socket is closed required to prevent denial-of-service (DoS) attacks Default value is 60 seconds
Transport Layer 3-105
SomeTCP Parameters in Linux Kerneltcp_rmem
This is a vector of 3 integers [min default max] These parameters are used by TCP to dynamically adjust receive buffer sizesmin - minimum size of the receive buffer used by each TCP socket The default value is 4K default - the default size of the receive buffer for a TCP socket The default value is 87380 bytes and is lowered to 43689 in low memory systems If larger receive buffer sizes are desired this value should be increased max - the maximum size of the receive buffer used by each TCP socket The default value of 873802 bytes is lowered to 87380 in low memory systems
tcp_smemSend buffer parameters [min default max] similar to tcp_rmem
- Chapter 3 Transport Layer
- Transport services and protocols
- Transport vs network layer
- Internet transport-layer protocols
- Multiplexingdemultiplexing
- How demultiplexing works
- Connectionless demultiplexing
- Connection-oriented demux
- Connection-oriented demux (cont)
- Connection-oriented demux Threaded Web Server
- UDP User Datagram Protocol [RFC 768]
- UDP more
- UDP checksum
- Principles of Reliable data transfer
- Reliable data transfer getting started
- Reliable data transfer getting started
- Rdt10 reliable transfer over a reliable channel
- Rdt20 channel with bit errors
- rdt20 FSM specification
- rdt20 operation with no errors
- rdt20 error scenario
- rdt20 has a fatal flaw
- rdt21 sender handles garbled ACKNAKs
- rdt21 receiver handles garbled ACKNAKs
- rdt21 discussion
- rdt22 a NAK-free protocol
- rdt22 sender receiver fragments
- rdt30 channels with errors and loss
- rdt30 sender
- rdt30 in action
- rdt30 in action
- Performance of rdt30
- rdt30 stop-and-wait operation
- Pipelined protocols
- Pipelining increased utilization
- Go-Back-N
- GBN sender extended FSM
- GBN receiver extended FSM
- GBN inaction
- Selective Repeat
- Selective repeat sender receiver windows
- Selective repeat
- Selective repeat in action
- Selective repeat dilemma
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- TCP Overview RFCs 793 1122 1323 2018 2581
- TCP segment structure
- TCP seq rsquos and ACKs
- TCP Round Trip Time and Timeout
- TCP Round Trip Time and Timeout
- Example RTT estimation
- TCP Round Trip Time and Timeout
- TCP reliable data transfer
- TCP sender events
- TCP sender(simplified)
- TCP retransmission scenarios
- TCP retransmission scenarios (more)
- TCP ACK generation [RFC 1122 RFC 2581]
- Fast Retransmit
- Fast Retransmit
- Fast retransmit algorithm
- TCP Flow Control
- TCP Flow control how it works
- Sliding Window Flow Control Example
- Principles of Congestion Control
- Causescosts of congestion scenario 1
- Causescosts of congestion scenario 2
- Causescosts of congestion scenario 2
- Causescosts of congestion scenario 3
- Causescosts of congestion scenario 3
- Approaches towards congestion control
- TCP Congestion Control
- TCP congestion control bandwidth probing
- TCP Congestion Control details
- TCP Congestion Control more details
- TCP Slow Start Phase
- Slow Start Example
- TCP Congestion Avoidance Phase
- Congestion Avoidance
- Example Slow StartCongestion Avoidance
- Slow Start Congestion Avoidance
- Responses to Congestion
- Fast Recovery (differentiation btwn two loss events)
- TCP Congestion Control
- Popular ldquoflavorsrdquo of TCP
- Summary TCP Congestion Control
- TCP Congestion Control Summary
- TCP throughput
- TCP Futures TCP over ldquolong fat pipesrdquo
- TCP Fairness
- Why is TCP fair
- Fairness (more)
- TCP Connection Management
- TCP Connection Management (cont)
- TCP Connection Management (cont)
- TCP Connection Management (cont)
- Tuning TCPIP Parameters
- SomeTCP Parameters in Linux Kernel
- SomeTCP Parameters in Linux Kernel
-
Transport Layer 3-97
Why is TCP fairTwo competing sessions
Additive increase gives slope of 1 as throughout increasesmultiplicative decrease decreases throughput proportionally
R
R
equal bandwidth share
Connection 1 throughput
Conn
ecti
on 2
thr
ough
p ut
congestion avoidance additive increaseloss decrease window by factor of 2
congestion avoidance additive increaseloss decrease window by factor of 2
Transport Layer 3-98
Fairness (more)Fairness and UDP
Multimedia apps often do not use TCP
do not want rate throttled by congestion control
Instead use UDPpump audiovideo at constant rate tolerate packet loss
Research area TCP friendly
Fairness and parallel TCP connectionsnothing prevents app from opening parallel cnctionsbetween 2 hostsWeb browsers do this Example link of rate R supporting 9 cnctions
new app asks for 1 TCP gets rate R10new app asks for 11 TCPs gets R2
Transport Layer 3-99
TCP Connection ManagementRecall TCP sender receiver
establish ldquoconnectionrdquobefore exchanging data segmentsinitialize TCP variables
seq sbuffers flow control info (eg RcvWindow)
client connection initiatorSocket clientSocket = new Socket(hostnameport
number)
server contacted by clientSocket connectionSocket = welcomeSocketaccept()
Three way handshakeStep 1 client host sends TCP
SYN segment to serverspecifies initial seq no data
Step 2 server host receives SYN replies with SYNACK segment
server allocates buffersspecifies server initial seq
Step 3 client receives SYNACK replies with ACK segment which may contain data
Transport Layer 3-100
TCP Connection Management (cont)
Closing a connection
client closes socketclientSocketclose()
Step 1 client end system sends TCP FIN control segment to server
Step 2 server receives FIN replies with ACK Closes connection sends FIN
client
FIN
server
ACK
ACK
FIN
close
close
closed
tim
ed w
ait
Transport Layer 3-101
TCP Connection Management (cont)
Step 3 client receives FIN replies with ACK
Enters ldquotimed waitrdquo -will respond with ACK to received FINs
Step 4 server receives ACK Connection closed
client
FIN
server
ACK
ACK
FIN
closing
closing
closed
tim
ed w
ait
closed
Transport Layer 3-102
TCP Connection Management (cont)
TCP clientlifecycle
TCP serverlifecycle
Transport Layer 3-103
Tuning TCPIP Parameters TCPIP parameters
A set of default values may not be optimal for all applicationsThe network administrator may wish to turn on or off some TCPIP functions for performance or security considerations
Many Unix and Linux systems provide some flexibility in tuning the TCPIP kernelsbinsysctl is used to configure the Linux kernel parameters at runtime
Default kernel configuration file is sbinsysctlconfFrequently used sysctl options
bull sysctl ndasha or sysctl ndashA list all current valuesbull sysctl ndashp file_name load the sysctl setting from a configuration
filebull sysctl ndashw variable=value change the value of the parameter
Transport Layer 3-104
SomeTCP Parameters in Linux Kerneltcp_syn_retries
Number of SYN packets the kernel will send before giving up on the new connection
tcp_synack_retriesnumber of SYN+ACK packets sent before the kernel gives up on the connection
tcp_window_scalingMaximum window size of 65535 bytes not enough for for really fast networks The window scaling options allows for almost gigabyte windows which is good for connections with large delay-bandwidth product
tcp_max_syn_backlogMaximal number of remembered connection requests which still did not receive an acknowledgment from connecting client
tcp_fin_timeoutHow many seconds to wait for a final FIN packet before the socket is closed required to prevent denial-of-service (DoS) attacks Default value is 60 seconds
Transport Layer 3-105
SomeTCP Parameters in Linux Kerneltcp_rmem
This is a vector of 3 integers [min default max] These parameters are used by TCP to dynamically adjust receive buffer sizesmin - minimum size of the receive buffer used by each TCP socket The default value is 4K default - the default size of the receive buffer for a TCP socket The default value is 87380 bytes and is lowered to 43689 in low memory systems If larger receive buffer sizes are desired this value should be increased max - the maximum size of the receive buffer used by each TCP socket The default value of 873802 bytes is lowered to 87380 in low memory systems
tcp_smemSend buffer parameters [min default max] similar to tcp_rmem
- Chapter 3 Transport Layer
- Transport services and protocols
- Transport vs network layer
- Internet transport-layer protocols
- Multiplexingdemultiplexing
- How demultiplexing works
- Connectionless demultiplexing
- Connection-oriented demux
- Connection-oriented demux (cont)
- Connection-oriented demux Threaded Web Server
- UDP User Datagram Protocol [RFC 768]
- UDP more
- UDP checksum
- Principles of Reliable data transfer
- Reliable data transfer getting started
- Reliable data transfer getting started
- Rdt10 reliable transfer over a reliable channel
- Rdt20 channel with bit errors
- rdt20 FSM specification
- rdt20 operation with no errors
- rdt20 error scenario
- rdt20 has a fatal flaw
- rdt21 sender handles garbled ACKNAKs
- rdt21 receiver handles garbled ACKNAKs
- rdt21 discussion
- rdt22 a NAK-free protocol
- rdt22 sender receiver fragments
- rdt30 channels with errors and loss
- rdt30 sender
- rdt30 in action
- rdt30 in action
- Performance of rdt30
- rdt30 stop-and-wait operation
- Pipelined protocols
- Pipelining increased utilization
- Go-Back-N
- GBN sender extended FSM
- GBN receiver extended FSM
- GBN inaction
- Selective Repeat
- Selective repeat sender receiver windows
- Selective repeat
- Selective repeat in action
- Selective repeat dilemma
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- TCP Overview RFCs 793 1122 1323 2018 2581
- TCP segment structure
- TCP seq rsquos and ACKs
- TCP Round Trip Time and Timeout
- TCP Round Trip Time and Timeout
- Example RTT estimation
- TCP Round Trip Time and Timeout
- TCP reliable data transfer
- TCP sender events
- TCP sender(simplified)
- TCP retransmission scenarios
- TCP retransmission scenarios (more)
- TCP ACK generation [RFC 1122 RFC 2581]
- Fast Retransmit
- Fast Retransmit
- Fast retransmit algorithm
- TCP Flow Control
- TCP Flow control how it works
- Sliding Window Flow Control Example
- Principles of Congestion Control
- Causescosts of congestion scenario 1
- Causescosts of congestion scenario 2
- Causescosts of congestion scenario 2
- Causescosts of congestion scenario 3
- Causescosts of congestion scenario 3
- Approaches towards congestion control
- TCP Congestion Control
- TCP congestion control bandwidth probing
- TCP Congestion Control details
- TCP Congestion Control more details
- TCP Slow Start Phase
- Slow Start Example
- TCP Congestion Avoidance Phase
- Congestion Avoidance
- Example Slow StartCongestion Avoidance
- Slow Start Congestion Avoidance
- Responses to Congestion
- Fast Recovery (differentiation btwn two loss events)
- TCP Congestion Control
- Popular ldquoflavorsrdquo of TCP
- Summary TCP Congestion Control
- TCP Congestion Control Summary
- TCP throughput
- TCP Futures TCP over ldquolong fat pipesrdquo
- TCP Fairness
- Why is TCP fair
- Fairness (more)
- TCP Connection Management
- TCP Connection Management (cont)
- TCP Connection Management (cont)
- TCP Connection Management (cont)
- Tuning TCPIP Parameters
- SomeTCP Parameters in Linux Kernel
- SomeTCP Parameters in Linux Kernel
-
Transport Layer 3-98
Fairness (more)Fairness and UDP
Multimedia apps often do not use TCP
do not want rate throttled by congestion control
Instead use UDPpump audiovideo at constant rate tolerate packet loss
Research area TCP friendly
Fairness and parallel TCP connectionsnothing prevents app from opening parallel cnctionsbetween 2 hostsWeb browsers do this Example link of rate R supporting 9 cnctions
new app asks for 1 TCP gets rate R10new app asks for 11 TCPs gets R2
Transport Layer 3-99
TCP Connection ManagementRecall TCP sender receiver
establish ldquoconnectionrdquobefore exchanging data segmentsinitialize TCP variables
seq sbuffers flow control info (eg RcvWindow)
client connection initiatorSocket clientSocket = new Socket(hostnameport
number)
server contacted by clientSocket connectionSocket = welcomeSocketaccept()
Three way handshakeStep 1 client host sends TCP
SYN segment to serverspecifies initial seq no data
Step 2 server host receives SYN replies with SYNACK segment
server allocates buffersspecifies server initial seq
Step 3 client receives SYNACK replies with ACK segment which may contain data
Transport Layer 3-100
TCP Connection Management (cont)
Closing a connection
client closes socketclientSocketclose()
Step 1 client end system sends TCP FIN control segment to server
Step 2 server receives FIN replies with ACK Closes connection sends FIN
client
FIN
server
ACK
ACK
FIN
close
close
closed
tim
ed w
ait
Transport Layer 3-101
TCP Connection Management (cont)
Step 3 client receives FIN replies with ACK
Enters ldquotimed waitrdquo -will respond with ACK to received FINs
Step 4 server receives ACK Connection closed
client
FIN
server
ACK
ACK
FIN
closing
closing
closed
tim
ed w
ait
closed
Transport Layer 3-102
TCP Connection Management (cont)
TCP clientlifecycle
TCP serverlifecycle
Transport Layer 3-103
Tuning TCPIP Parameters TCPIP parameters
A set of default values may not be optimal for all applicationsThe network administrator may wish to turn on or off some TCPIP functions for performance or security considerations
Many Unix and Linux systems provide some flexibility in tuning the TCPIP kernelsbinsysctl is used to configure the Linux kernel parameters at runtime
Default kernel configuration file is sbinsysctlconfFrequently used sysctl options
bull sysctl ndasha or sysctl ndashA list all current valuesbull sysctl ndashp file_name load the sysctl setting from a configuration
filebull sysctl ndashw variable=value change the value of the parameter
Transport Layer 3-104
SomeTCP Parameters in Linux Kerneltcp_syn_retries
Number of SYN packets the kernel will send before giving up on the new connection
tcp_synack_retriesnumber of SYN+ACK packets sent before the kernel gives up on the connection
tcp_window_scalingMaximum window size of 65535 bytes not enough for for really fast networks The window scaling options allows for almost gigabyte windows which is good for connections with large delay-bandwidth product
tcp_max_syn_backlogMaximal number of remembered connection requests which still did not receive an acknowledgment from connecting client
tcp_fin_timeoutHow many seconds to wait for a final FIN packet before the socket is closed required to prevent denial-of-service (DoS) attacks Default value is 60 seconds
Transport Layer 3-105
SomeTCP Parameters in Linux Kerneltcp_rmem
This is a vector of 3 integers [min default max] These parameters are used by TCP to dynamically adjust receive buffer sizesmin - minimum size of the receive buffer used by each TCP socket The default value is 4K default - the default size of the receive buffer for a TCP socket The default value is 87380 bytes and is lowered to 43689 in low memory systems If larger receive buffer sizes are desired this value should be increased max - the maximum size of the receive buffer used by each TCP socket The default value of 873802 bytes is lowered to 87380 in low memory systems
tcp_smemSend buffer parameters [min default max] similar to tcp_rmem
- Chapter 3 Transport Layer
- Transport services and protocols
- Transport vs network layer
- Internet transport-layer protocols
- Multiplexingdemultiplexing
- How demultiplexing works
- Connectionless demultiplexing
- Connection-oriented demux
- Connection-oriented demux (cont)
- Connection-oriented demux Threaded Web Server
- UDP User Datagram Protocol [RFC 768]
- UDP more
- UDP checksum
- Principles of Reliable data transfer
- Reliable data transfer getting started
- Reliable data transfer getting started
- Rdt10 reliable transfer over a reliable channel
- Rdt20 channel with bit errors
- rdt20 FSM specification
- rdt20 operation with no errors
- rdt20 error scenario
- rdt20 has a fatal flaw
- rdt21 sender handles garbled ACKNAKs
- rdt21 receiver handles garbled ACKNAKs
- rdt21 discussion
- rdt22 a NAK-free protocol
- rdt22 sender receiver fragments
- rdt30 channels with errors and loss
- rdt30 sender
- rdt30 in action
- rdt30 in action
- Performance of rdt30
- rdt30 stop-and-wait operation
- Pipelined protocols
- Pipelining increased utilization
- Go-Back-N
- GBN sender extended FSM
- GBN receiver extended FSM
- GBN inaction
- Selective Repeat
- Selective repeat sender receiver windows
- Selective repeat
- Selective repeat in action
- Selective repeat dilemma
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- TCP Overview RFCs 793 1122 1323 2018 2581
- TCP segment structure
- TCP seq rsquos and ACKs
- TCP Round Trip Time and Timeout
- TCP Round Trip Time and Timeout
- Example RTT estimation
- TCP Round Trip Time and Timeout
- TCP reliable data transfer
- TCP sender events
- TCP sender(simplified)
- TCP retransmission scenarios
- TCP retransmission scenarios (more)
- TCP ACK generation [RFC 1122 RFC 2581]
- Fast Retransmit
- Fast Retransmit
- Fast retransmit algorithm
- TCP Flow Control
- TCP Flow control how it works
- Sliding Window Flow Control Example
- Principles of Congestion Control
- Causescosts of congestion scenario 1
- Causescosts of congestion scenario 2
- Causescosts of congestion scenario 2
- Causescosts of congestion scenario 3
- Causescosts of congestion scenario 3
- Approaches towards congestion control
- TCP Congestion Control
- TCP congestion control bandwidth probing
- TCP Congestion Control details
- TCP Congestion Control more details
- TCP Slow Start Phase
- Slow Start Example
- TCP Congestion Avoidance Phase
- Congestion Avoidance
- Example Slow StartCongestion Avoidance
- Slow Start Congestion Avoidance
- Responses to Congestion
- Fast Recovery (differentiation btwn two loss events)
- TCP Congestion Control
- Popular ldquoflavorsrdquo of TCP
- Summary TCP Congestion Control
- TCP Congestion Control Summary
- TCP throughput
- TCP Futures TCP over ldquolong fat pipesrdquo
- TCP Fairness
- Why is TCP fair
- Fairness (more)
- TCP Connection Management
- TCP Connection Management (cont)
- TCP Connection Management (cont)
- TCP Connection Management (cont)
- Tuning TCPIP Parameters
- SomeTCP Parameters in Linux Kernel
- SomeTCP Parameters in Linux Kernel
-
Transport Layer 3-99
TCP Connection ManagementRecall TCP sender receiver
establish ldquoconnectionrdquobefore exchanging data segmentsinitialize TCP variables
seq sbuffers flow control info (eg RcvWindow)
client connection initiatorSocket clientSocket = new Socket(hostnameport
number)
server contacted by clientSocket connectionSocket = welcomeSocketaccept()
Three way handshakeStep 1 client host sends TCP
SYN segment to serverspecifies initial seq no data
Step 2 server host receives SYN replies with SYNACK segment
server allocates buffersspecifies server initial seq
Step 3 client receives SYNACK replies with ACK segment which may contain data
Transport Layer 3-100
TCP Connection Management (cont)
Closing a connection
client closes socketclientSocketclose()
Step 1 client end system sends TCP FIN control segment to server
Step 2 server receives FIN replies with ACK Closes connection sends FIN
client
FIN
server
ACK
ACK
FIN
close
close
closed
tim
ed w
ait
Transport Layer 3-101
TCP Connection Management (cont)
Step 3 client receives FIN replies with ACK
Enters ldquotimed waitrdquo -will respond with ACK to received FINs
Step 4 server receives ACK Connection closed
client
FIN
server
ACK
ACK
FIN
closing
closing
closed
tim
ed w
ait
closed
Transport Layer 3-102
TCP Connection Management (cont)
TCP clientlifecycle
TCP serverlifecycle
Transport Layer 3-103
Tuning TCPIP Parameters TCPIP parameters
A set of default values may not be optimal for all applicationsThe network administrator may wish to turn on or off some TCPIP functions for performance or security considerations
Many Unix and Linux systems provide some flexibility in tuning the TCPIP kernelsbinsysctl is used to configure the Linux kernel parameters at runtime
Default kernel configuration file is sbinsysctlconfFrequently used sysctl options
bull sysctl ndasha or sysctl ndashA list all current valuesbull sysctl ndashp file_name load the sysctl setting from a configuration
filebull sysctl ndashw variable=value change the value of the parameter
Transport Layer 3-104
SomeTCP Parameters in Linux Kerneltcp_syn_retries
Number of SYN packets the kernel will send before giving up on the new connection
tcp_synack_retriesnumber of SYN+ACK packets sent before the kernel gives up on the connection
tcp_window_scalingMaximum window size of 65535 bytes not enough for for really fast networks The window scaling options allows for almost gigabyte windows which is good for connections with large delay-bandwidth product
tcp_max_syn_backlogMaximal number of remembered connection requests which still did not receive an acknowledgment from connecting client
tcp_fin_timeoutHow many seconds to wait for a final FIN packet before the socket is closed required to prevent denial-of-service (DoS) attacks Default value is 60 seconds
Transport Layer 3-105
SomeTCP Parameters in Linux Kerneltcp_rmem
This is a vector of 3 integers [min default max] These parameters are used by TCP to dynamically adjust receive buffer sizesmin - minimum size of the receive buffer used by each TCP socket The default value is 4K default - the default size of the receive buffer for a TCP socket The default value is 87380 bytes and is lowered to 43689 in low memory systems If larger receive buffer sizes are desired this value should be increased max - the maximum size of the receive buffer used by each TCP socket The default value of 873802 bytes is lowered to 87380 in low memory systems
tcp_smemSend buffer parameters [min default max] similar to tcp_rmem
- Chapter 3 Transport Layer
- Transport services and protocols
- Transport vs network layer
- Internet transport-layer protocols
- Multiplexingdemultiplexing
- How demultiplexing works
- Connectionless demultiplexing
- Connection-oriented demux
- Connection-oriented demux (cont)
- Connection-oriented demux Threaded Web Server
- UDP User Datagram Protocol [RFC 768]
- UDP more
- UDP checksum
- Principles of Reliable data transfer
- Reliable data transfer getting started
- Reliable data transfer getting started
- Rdt10 reliable transfer over a reliable channel
- Rdt20 channel with bit errors
- rdt20 FSM specification
- rdt20 operation with no errors
- rdt20 error scenario
- rdt20 has a fatal flaw
- rdt21 sender handles garbled ACKNAKs
- rdt21 receiver handles garbled ACKNAKs
- rdt21 discussion
- rdt22 a NAK-free protocol
- rdt22 sender receiver fragments
- rdt30 channels with errors and loss
- rdt30 sender
- rdt30 in action
- rdt30 in action
- Performance of rdt30
- rdt30 stop-and-wait operation
- Pipelined protocols
- Pipelining increased utilization
- Go-Back-N
- GBN sender extended FSM
- GBN receiver extended FSM
- GBN inaction
- Selective Repeat
- Selective repeat sender receiver windows
- Selective repeat
- Selective repeat in action
- Selective repeat dilemma
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- TCP Overview RFCs 793 1122 1323 2018 2581
- TCP segment structure
- TCP seq rsquos and ACKs
- TCP Round Trip Time and Timeout
- TCP Round Trip Time and Timeout
- Example RTT estimation
- TCP Round Trip Time and Timeout
- TCP reliable data transfer
- TCP sender events
- TCP sender(simplified)
- TCP retransmission scenarios
- TCP retransmission scenarios (more)
- TCP ACK generation [RFC 1122 RFC 2581]
- Fast Retransmit
- Fast Retransmit
- Fast retransmit algorithm
- TCP Flow Control
- TCP Flow control how it works
- Sliding Window Flow Control Example
- Principles of Congestion Control
- Causescosts of congestion scenario 1
- Causescosts of congestion scenario 2
- Causescosts of congestion scenario 2
- Causescosts of congestion scenario 3
- Causescosts of congestion scenario 3
- Approaches towards congestion control
- TCP Congestion Control
- TCP congestion control bandwidth probing
- TCP Congestion Control details
- TCP Congestion Control more details
- TCP Slow Start Phase
- Slow Start Example
- TCP Congestion Avoidance Phase
- Congestion Avoidance
- Example Slow StartCongestion Avoidance
- Slow Start Congestion Avoidance
- Responses to Congestion
- Fast Recovery (differentiation btwn two loss events)
- TCP Congestion Control
- Popular ldquoflavorsrdquo of TCP
- Summary TCP Congestion Control
- TCP Congestion Control Summary
- TCP throughput
- TCP Futures TCP over ldquolong fat pipesrdquo
- TCP Fairness
- Why is TCP fair
- Fairness (more)
- TCP Connection Management
- TCP Connection Management (cont)
- TCP Connection Management (cont)
- TCP Connection Management (cont)
- Tuning TCPIP Parameters
- SomeTCP Parameters in Linux Kernel
- SomeTCP Parameters in Linux Kernel
-
Transport Layer 3-100
TCP Connection Management (cont)
Closing a connection
client closes socketclientSocketclose()
Step 1 client end system sends TCP FIN control segment to server
Step 2 server receives FIN replies with ACK Closes connection sends FIN
client
FIN
server
ACK
ACK
FIN
close
close
closed
tim
ed w
ait
Transport Layer 3-101
TCP Connection Management (cont)
Step 3 client receives FIN replies with ACK
Enters ldquotimed waitrdquo -will respond with ACK to received FINs
Step 4 server receives ACK Connection closed
client
FIN
server
ACK
ACK
FIN
closing
closing
closed
tim
ed w
ait
closed
Transport Layer 3-102
TCP Connection Management (cont)
TCP clientlifecycle
TCP serverlifecycle
Transport Layer 3-103
Tuning TCPIP Parameters TCPIP parameters
A set of default values may not be optimal for all applicationsThe network administrator may wish to turn on or off some TCPIP functions for performance or security considerations
Many Unix and Linux systems provide some flexibility in tuning the TCPIP kernelsbinsysctl is used to configure the Linux kernel parameters at runtime
Default kernel configuration file is sbinsysctlconfFrequently used sysctl options
bull sysctl ndasha or sysctl ndashA list all current valuesbull sysctl ndashp file_name load the sysctl setting from a configuration
filebull sysctl ndashw variable=value change the value of the parameter
Transport Layer 3-104
SomeTCP Parameters in Linux Kerneltcp_syn_retries
Number of SYN packets the kernel will send before giving up on the new connection
tcp_synack_retriesnumber of SYN+ACK packets sent before the kernel gives up on the connection
tcp_window_scalingMaximum window size of 65535 bytes not enough for for really fast networks The window scaling options allows for almost gigabyte windows which is good for connections with large delay-bandwidth product
tcp_max_syn_backlogMaximal number of remembered connection requests which still did not receive an acknowledgment from connecting client
tcp_fin_timeoutHow many seconds to wait for a final FIN packet before the socket is closed required to prevent denial-of-service (DoS) attacks Default value is 60 seconds
Transport Layer 3-105
SomeTCP Parameters in Linux Kerneltcp_rmem
This is a vector of 3 integers [min default max] These parameters are used by TCP to dynamically adjust receive buffer sizesmin - minimum size of the receive buffer used by each TCP socket The default value is 4K default - the default size of the receive buffer for a TCP socket The default value is 87380 bytes and is lowered to 43689 in low memory systems If larger receive buffer sizes are desired this value should be increased max - the maximum size of the receive buffer used by each TCP socket The default value of 873802 bytes is lowered to 87380 in low memory systems
tcp_smemSend buffer parameters [min default max] similar to tcp_rmem
- Chapter 3 Transport Layer
- Transport services and protocols
- Transport vs network layer
- Internet transport-layer protocols
- Multiplexingdemultiplexing
- How demultiplexing works
- Connectionless demultiplexing
- Connection-oriented demux
- Connection-oriented demux (cont)
- Connection-oriented demux Threaded Web Server
- UDP User Datagram Protocol [RFC 768]
- UDP more
- UDP checksum
- Principles of Reliable data transfer
- Reliable data transfer getting started
- Reliable data transfer getting started
- Rdt10 reliable transfer over a reliable channel
- Rdt20 channel with bit errors
- rdt20 FSM specification
- rdt20 operation with no errors
- rdt20 error scenario
- rdt20 has a fatal flaw
- rdt21 sender handles garbled ACKNAKs
- rdt21 receiver handles garbled ACKNAKs
- rdt21 discussion
- rdt22 a NAK-free protocol
- rdt22 sender receiver fragments
- rdt30 channels with errors and loss
- rdt30 sender
- rdt30 in action
- rdt30 in action
- Performance of rdt30
- rdt30 stop-and-wait operation
- Pipelined protocols
- Pipelining increased utilization
- Go-Back-N
- GBN sender extended FSM
- GBN receiver extended FSM
- GBN inaction
- Selective Repeat
- Selective repeat sender receiver windows
- Selective repeat
- Selective repeat in action
- Selective repeat dilemma
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- TCP Overview RFCs 793 1122 1323 2018 2581
- TCP segment structure
- TCP seq rsquos and ACKs
- TCP Round Trip Time and Timeout
- TCP Round Trip Time and Timeout
- Example RTT estimation
- TCP Round Trip Time and Timeout
- TCP reliable data transfer
- TCP sender events
- TCP sender(simplified)
- TCP retransmission scenarios
- TCP retransmission scenarios (more)
- TCP ACK generation [RFC 1122 RFC 2581]
- Fast Retransmit
- Fast Retransmit
- Fast retransmit algorithm
- TCP Flow Control
- TCP Flow control how it works
- Sliding Window Flow Control Example
- Principles of Congestion Control
- Causescosts of congestion scenario 1
- Causescosts of congestion scenario 2
- Causescosts of congestion scenario 2
- Causescosts of congestion scenario 3
- Causescosts of congestion scenario 3
- Approaches towards congestion control
- TCP Congestion Control
- TCP congestion control bandwidth probing
- TCP Congestion Control details
- TCP Congestion Control more details
- TCP Slow Start Phase
- Slow Start Example
- TCP Congestion Avoidance Phase
- Congestion Avoidance
- Example Slow StartCongestion Avoidance
- Slow Start Congestion Avoidance
- Responses to Congestion
- Fast Recovery (differentiation btwn two loss events)
- TCP Congestion Control
- Popular ldquoflavorsrdquo of TCP
- Summary TCP Congestion Control
- TCP Congestion Control Summary
- TCP throughput
- TCP Futures TCP over ldquolong fat pipesrdquo
- TCP Fairness
- Why is TCP fair
- Fairness (more)
- TCP Connection Management
- TCP Connection Management (cont)
- TCP Connection Management (cont)
- TCP Connection Management (cont)
- Tuning TCPIP Parameters
- SomeTCP Parameters in Linux Kernel
- SomeTCP Parameters in Linux Kernel
-
Transport Layer 3-101
TCP Connection Management (cont)
Step 3 client receives FIN replies with ACK
Enters ldquotimed waitrdquo -will respond with ACK to received FINs
Step 4 server receives ACK Connection closed
client
FIN
server
ACK
ACK
FIN
closing
closing
closed
tim
ed w
ait
closed
Transport Layer 3-102
TCP Connection Management (cont)
TCP clientlifecycle
TCP serverlifecycle
Transport Layer 3-103
Tuning TCPIP Parameters TCPIP parameters
A set of default values may not be optimal for all applicationsThe network administrator may wish to turn on or off some TCPIP functions for performance or security considerations
Many Unix and Linux systems provide some flexibility in tuning the TCPIP kernelsbinsysctl is used to configure the Linux kernel parameters at runtime
Default kernel configuration file is sbinsysctlconfFrequently used sysctl options
bull sysctl ndasha or sysctl ndashA list all current valuesbull sysctl ndashp file_name load the sysctl setting from a configuration
filebull sysctl ndashw variable=value change the value of the parameter
Transport Layer 3-104
SomeTCP Parameters in Linux Kerneltcp_syn_retries
Number of SYN packets the kernel will send before giving up on the new connection
tcp_synack_retriesnumber of SYN+ACK packets sent before the kernel gives up on the connection
tcp_window_scalingMaximum window size of 65535 bytes not enough for for really fast networks The window scaling options allows for almost gigabyte windows which is good for connections with large delay-bandwidth product
tcp_max_syn_backlogMaximal number of remembered connection requests which still did not receive an acknowledgment from connecting client
tcp_fin_timeoutHow many seconds to wait for a final FIN packet before the socket is closed required to prevent denial-of-service (DoS) attacks Default value is 60 seconds
Transport Layer 3-105
SomeTCP Parameters in Linux Kerneltcp_rmem
This is a vector of 3 integers [min default max] These parameters are used by TCP to dynamically adjust receive buffer sizesmin - minimum size of the receive buffer used by each TCP socket The default value is 4K default - the default size of the receive buffer for a TCP socket The default value is 87380 bytes and is lowered to 43689 in low memory systems If larger receive buffer sizes are desired this value should be increased max - the maximum size of the receive buffer used by each TCP socket The default value of 873802 bytes is lowered to 87380 in low memory systems
tcp_smemSend buffer parameters [min default max] similar to tcp_rmem
- Chapter 3 Transport Layer
- Transport services and protocols
- Transport vs network layer
- Internet transport-layer protocols
- Multiplexingdemultiplexing
- How demultiplexing works
- Connectionless demultiplexing
- Connection-oriented demux
- Connection-oriented demux (cont)
- Connection-oriented demux Threaded Web Server
- UDP User Datagram Protocol [RFC 768]
- UDP more
- UDP checksum
- Principles of Reliable data transfer
- Reliable data transfer getting started
- Reliable data transfer getting started
- Rdt10 reliable transfer over a reliable channel
- Rdt20 channel with bit errors
- rdt20 FSM specification
- rdt20 operation with no errors
- rdt20 error scenario
- rdt20 has a fatal flaw
- rdt21 sender handles garbled ACKNAKs
- rdt21 receiver handles garbled ACKNAKs
- rdt21 discussion
- rdt22 a NAK-free protocol
- rdt22 sender receiver fragments
- rdt30 channels with errors and loss
- rdt30 sender
- rdt30 in action
- rdt30 in action
- Performance of rdt30
- rdt30 stop-and-wait operation
- Pipelined protocols
- Pipelining increased utilization
- Go-Back-N
- GBN sender extended FSM
- GBN receiver extended FSM
- GBN inaction
- Selective Repeat
- Selective repeat sender receiver windows
- Selective repeat
- Selective repeat in action
- Selective repeat dilemma
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- TCP Overview RFCs 793 1122 1323 2018 2581
- TCP segment structure
- TCP seq rsquos and ACKs
- TCP Round Trip Time and Timeout
- TCP Round Trip Time and Timeout
- Example RTT estimation
- TCP Round Trip Time and Timeout
- TCP reliable data transfer
- TCP sender events
- TCP sender(simplified)
- TCP retransmission scenarios
- TCP retransmission scenarios (more)
- TCP ACK generation [RFC 1122 RFC 2581]
- Fast Retransmit
- Fast Retransmit
- Fast retransmit algorithm
- TCP Flow Control
- TCP Flow control how it works
- Sliding Window Flow Control Example
- Principles of Congestion Control
- Causescosts of congestion scenario 1
- Causescosts of congestion scenario 2
- Causescosts of congestion scenario 2
- Causescosts of congestion scenario 3
- Causescosts of congestion scenario 3
- Approaches towards congestion control
- TCP Congestion Control
- TCP congestion control bandwidth probing
- TCP Congestion Control details
- TCP Congestion Control more details
- TCP Slow Start Phase
- Slow Start Example
- TCP Congestion Avoidance Phase
- Congestion Avoidance
- Example Slow StartCongestion Avoidance
- Slow Start Congestion Avoidance
- Responses to Congestion
- Fast Recovery (differentiation btwn two loss events)
- TCP Congestion Control
- Popular ldquoflavorsrdquo of TCP
- Summary TCP Congestion Control
- TCP Congestion Control Summary
- TCP throughput
- TCP Futures TCP over ldquolong fat pipesrdquo
- TCP Fairness
- Why is TCP fair
- Fairness (more)
- TCP Connection Management
- TCP Connection Management (cont)
- TCP Connection Management (cont)
- TCP Connection Management (cont)
- Tuning TCPIP Parameters
- SomeTCP Parameters in Linux Kernel
- SomeTCP Parameters in Linux Kernel
-
Transport Layer 3-102
TCP Connection Management (cont)
TCP clientlifecycle
TCP serverlifecycle
Transport Layer 3-103
Tuning TCPIP Parameters TCPIP parameters
A set of default values may not be optimal for all applicationsThe network administrator may wish to turn on or off some TCPIP functions for performance or security considerations
Many Unix and Linux systems provide some flexibility in tuning the TCPIP kernelsbinsysctl is used to configure the Linux kernel parameters at runtime
Default kernel configuration file is sbinsysctlconfFrequently used sysctl options
bull sysctl ndasha or sysctl ndashA list all current valuesbull sysctl ndashp file_name load the sysctl setting from a configuration
filebull sysctl ndashw variable=value change the value of the parameter
Transport Layer 3-104
SomeTCP Parameters in Linux Kerneltcp_syn_retries
Number of SYN packets the kernel will send before giving up on the new connection
tcp_synack_retriesnumber of SYN+ACK packets sent before the kernel gives up on the connection
tcp_window_scalingMaximum window size of 65535 bytes not enough for for really fast networks The window scaling options allows for almost gigabyte windows which is good for connections with large delay-bandwidth product
tcp_max_syn_backlogMaximal number of remembered connection requests which still did not receive an acknowledgment from connecting client
tcp_fin_timeoutHow many seconds to wait for a final FIN packet before the socket is closed required to prevent denial-of-service (DoS) attacks Default value is 60 seconds
Transport Layer 3-105
SomeTCP Parameters in Linux Kerneltcp_rmem
This is a vector of 3 integers [min default max] These parameters are used by TCP to dynamically adjust receive buffer sizesmin - minimum size of the receive buffer used by each TCP socket The default value is 4K default - the default size of the receive buffer for a TCP socket The default value is 87380 bytes and is lowered to 43689 in low memory systems If larger receive buffer sizes are desired this value should be increased max - the maximum size of the receive buffer used by each TCP socket The default value of 873802 bytes is lowered to 87380 in low memory systems
tcp_smemSend buffer parameters [min default max] similar to tcp_rmem
- Chapter 3 Transport Layer
- Transport services and protocols
- Transport vs network layer
- Internet transport-layer protocols
- Multiplexingdemultiplexing
- How demultiplexing works
- Connectionless demultiplexing
- Connection-oriented demux
- Connection-oriented demux (cont)
- Connection-oriented demux Threaded Web Server
- UDP User Datagram Protocol [RFC 768]
- UDP more
- UDP checksum
- Principles of Reliable data transfer
- Reliable data transfer getting started
- Reliable data transfer getting started
- Rdt10 reliable transfer over a reliable channel
- Rdt20 channel with bit errors
- rdt20 FSM specification
- rdt20 operation with no errors
- rdt20 error scenario
- rdt20 has a fatal flaw
- rdt21 sender handles garbled ACKNAKs
- rdt21 receiver handles garbled ACKNAKs
- rdt21 discussion
- rdt22 a NAK-free protocol
- rdt22 sender receiver fragments
- rdt30 channels with errors and loss
- rdt30 sender
- rdt30 in action
- rdt30 in action
- Performance of rdt30
- rdt30 stop-and-wait operation
- Pipelined protocols
- Pipelining increased utilization
- Go-Back-N
- GBN sender extended FSM
- GBN receiver extended FSM
- GBN inaction
- Selective Repeat
- Selective repeat sender receiver windows
- Selective repeat
- Selective repeat in action
- Selective repeat dilemma
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- TCP Overview RFCs 793 1122 1323 2018 2581
- TCP segment structure
- TCP seq rsquos and ACKs
- TCP Round Trip Time and Timeout
- TCP Round Trip Time and Timeout
- Example RTT estimation
- TCP Round Trip Time and Timeout
- TCP reliable data transfer
- TCP sender events
- TCP sender(simplified)
- TCP retransmission scenarios
- TCP retransmission scenarios (more)
- TCP ACK generation [RFC 1122 RFC 2581]
- Fast Retransmit
- Fast Retransmit
- Fast retransmit algorithm
- TCP Flow Control
- TCP Flow control how it works
- Sliding Window Flow Control Example
- Principles of Congestion Control
- Causescosts of congestion scenario 1
- Causescosts of congestion scenario 2
- Causescosts of congestion scenario 2
- Causescosts of congestion scenario 3
- Causescosts of congestion scenario 3
- Approaches towards congestion control
- TCP Congestion Control
- TCP congestion control bandwidth probing
- TCP Congestion Control details
- TCP Congestion Control more details
- TCP Slow Start Phase
- Slow Start Example
- TCP Congestion Avoidance Phase
- Congestion Avoidance
- Example Slow StartCongestion Avoidance
- Slow Start Congestion Avoidance
- Responses to Congestion
- Fast Recovery (differentiation btwn two loss events)
- TCP Congestion Control
- Popular ldquoflavorsrdquo of TCP
- Summary TCP Congestion Control
- TCP Congestion Control Summary
- TCP throughput
- TCP Futures TCP over ldquolong fat pipesrdquo
- TCP Fairness
- Why is TCP fair
- Fairness (more)
- TCP Connection Management
- TCP Connection Management (cont)
- TCP Connection Management (cont)
- TCP Connection Management (cont)
- Tuning TCPIP Parameters
- SomeTCP Parameters in Linux Kernel
- SomeTCP Parameters in Linux Kernel
-
Transport Layer 3-103
Tuning TCPIP Parameters TCPIP parameters
A set of default values may not be optimal for all applicationsThe network administrator may wish to turn on or off some TCPIP functions for performance or security considerations
Many Unix and Linux systems provide some flexibility in tuning the TCPIP kernelsbinsysctl is used to configure the Linux kernel parameters at runtime
Default kernel configuration file is sbinsysctlconfFrequently used sysctl options
bull sysctl ndasha or sysctl ndashA list all current valuesbull sysctl ndashp file_name load the sysctl setting from a configuration
filebull sysctl ndashw variable=value change the value of the parameter
Transport Layer 3-104
SomeTCP Parameters in Linux Kerneltcp_syn_retries
Number of SYN packets the kernel will send before giving up on the new connection
tcp_synack_retriesnumber of SYN+ACK packets sent before the kernel gives up on the connection
tcp_window_scalingMaximum window size of 65535 bytes not enough for for really fast networks The window scaling options allows for almost gigabyte windows which is good for connections with large delay-bandwidth product
tcp_max_syn_backlogMaximal number of remembered connection requests which still did not receive an acknowledgment from connecting client
tcp_fin_timeoutHow many seconds to wait for a final FIN packet before the socket is closed required to prevent denial-of-service (DoS) attacks Default value is 60 seconds
Transport Layer 3-105
SomeTCP Parameters in Linux Kerneltcp_rmem
This is a vector of 3 integers [min default max] These parameters are used by TCP to dynamically adjust receive buffer sizesmin - minimum size of the receive buffer used by each TCP socket The default value is 4K default - the default size of the receive buffer for a TCP socket The default value is 87380 bytes and is lowered to 43689 in low memory systems If larger receive buffer sizes are desired this value should be increased max - the maximum size of the receive buffer used by each TCP socket The default value of 873802 bytes is lowered to 87380 in low memory systems
tcp_smemSend buffer parameters [min default max] similar to tcp_rmem
- Chapter 3 Transport Layer
- Transport services and protocols
- Transport vs network layer
- Internet transport-layer protocols
- Multiplexingdemultiplexing
- How demultiplexing works
- Connectionless demultiplexing
- Connection-oriented demux
- Connection-oriented demux (cont)
- Connection-oriented demux Threaded Web Server
- UDP User Datagram Protocol [RFC 768]
- UDP more
- UDP checksum
- Principles of Reliable data transfer
- Reliable data transfer getting started
- Reliable data transfer getting started
- Rdt10 reliable transfer over a reliable channel
- Rdt20 channel with bit errors
- rdt20 FSM specification
- rdt20 operation with no errors
- rdt20 error scenario
- rdt20 has a fatal flaw
- rdt21 sender handles garbled ACKNAKs
- rdt21 receiver handles garbled ACKNAKs
- rdt21 discussion
- rdt22 a NAK-free protocol
- rdt22 sender receiver fragments
- rdt30 channels with errors and loss
- rdt30 sender
- rdt30 in action
- rdt30 in action
- Performance of rdt30
- rdt30 stop-and-wait operation
- Pipelined protocols
- Pipelining increased utilization
- Go-Back-N
- GBN sender extended FSM
- GBN receiver extended FSM
- GBN inaction
- Selective Repeat
- Selective repeat sender receiver windows
- Selective repeat
- Selective repeat in action
- Selective repeat dilemma
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- TCP Overview RFCs 793 1122 1323 2018 2581
- TCP segment structure
- TCP seq rsquos and ACKs
- TCP Round Trip Time and Timeout
- TCP Round Trip Time and Timeout
- Example RTT estimation
- TCP Round Trip Time and Timeout
- TCP reliable data transfer
- TCP sender events
- TCP sender(simplified)
- TCP retransmission scenarios
- TCP retransmission scenarios (more)
- TCP ACK generation [RFC 1122 RFC 2581]
- Fast Retransmit
- Fast Retransmit
- Fast retransmit algorithm
- TCP Flow Control
- TCP Flow control how it works
- Sliding Window Flow Control Example
- Principles of Congestion Control
- Causescosts of congestion scenario 1
- Causescosts of congestion scenario 2
- Causescosts of congestion scenario 2
- Causescosts of congestion scenario 3
- Causescosts of congestion scenario 3
- Approaches towards congestion control
- TCP Congestion Control
- TCP congestion control bandwidth probing
- TCP Congestion Control details
- TCP Congestion Control more details
- TCP Slow Start Phase
- Slow Start Example
- TCP Congestion Avoidance Phase
- Congestion Avoidance
- Example Slow StartCongestion Avoidance
- Slow Start Congestion Avoidance
- Responses to Congestion
- Fast Recovery (differentiation btwn two loss events)
- TCP Congestion Control
- Popular ldquoflavorsrdquo of TCP
- Summary TCP Congestion Control
- TCP Congestion Control Summary
- TCP throughput
- TCP Futures TCP over ldquolong fat pipesrdquo
- TCP Fairness
- Why is TCP fair
- Fairness (more)
- TCP Connection Management
- TCP Connection Management (cont)
- TCP Connection Management (cont)
- TCP Connection Management (cont)
- Tuning TCPIP Parameters
- SomeTCP Parameters in Linux Kernel
- SomeTCP Parameters in Linux Kernel
-
Transport Layer 3-104
SomeTCP Parameters in Linux Kerneltcp_syn_retries
Number of SYN packets the kernel will send before giving up on the new connection
tcp_synack_retriesnumber of SYN+ACK packets sent before the kernel gives up on the connection
tcp_window_scalingMaximum window size of 65535 bytes not enough for for really fast networks The window scaling options allows for almost gigabyte windows which is good for connections with large delay-bandwidth product
tcp_max_syn_backlogMaximal number of remembered connection requests which still did not receive an acknowledgment from connecting client
tcp_fin_timeoutHow many seconds to wait for a final FIN packet before the socket is closed required to prevent denial-of-service (DoS) attacks Default value is 60 seconds
Transport Layer 3-105
SomeTCP Parameters in Linux Kerneltcp_rmem
This is a vector of 3 integers [min default max] These parameters are used by TCP to dynamically adjust receive buffer sizesmin - minimum size of the receive buffer used by each TCP socket The default value is 4K default - the default size of the receive buffer for a TCP socket The default value is 87380 bytes and is lowered to 43689 in low memory systems If larger receive buffer sizes are desired this value should be increased max - the maximum size of the receive buffer used by each TCP socket The default value of 873802 bytes is lowered to 87380 in low memory systems
tcp_smemSend buffer parameters [min default max] similar to tcp_rmem
- Chapter 3 Transport Layer
- Transport services and protocols
- Transport vs network layer
- Internet transport-layer protocols
- Multiplexingdemultiplexing
- How demultiplexing works
- Connectionless demultiplexing
- Connection-oriented demux
- Connection-oriented demux (cont)
- Connection-oriented demux Threaded Web Server
- UDP User Datagram Protocol [RFC 768]
- UDP more
- UDP checksum
- Principles of Reliable data transfer
- Reliable data transfer getting started
- Reliable data transfer getting started
- Rdt10 reliable transfer over a reliable channel
- Rdt20 channel with bit errors
- rdt20 FSM specification
- rdt20 operation with no errors
- rdt20 error scenario
- rdt20 has a fatal flaw
- rdt21 sender handles garbled ACKNAKs
- rdt21 receiver handles garbled ACKNAKs
- rdt21 discussion
- rdt22 a NAK-free protocol
- rdt22 sender receiver fragments
- rdt30 channels with errors and loss
- rdt30 sender
- rdt30 in action
- rdt30 in action
- Performance of rdt30
- rdt30 stop-and-wait operation
- Pipelined protocols
- Pipelining increased utilization
- Go-Back-N
- GBN sender extended FSM
- GBN receiver extended FSM
- GBN inaction
- Selective Repeat
- Selective repeat sender receiver windows
- Selective repeat
- Selective repeat in action
- Selective repeat dilemma
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- TCP Overview RFCs 793 1122 1323 2018 2581
- TCP segment structure
- TCP seq rsquos and ACKs
- TCP Round Trip Time and Timeout
- TCP Round Trip Time and Timeout
- Example RTT estimation
- TCP Round Trip Time and Timeout
- TCP reliable data transfer
- TCP sender events
- TCP sender(simplified)
- TCP retransmission scenarios
- TCP retransmission scenarios (more)
- TCP ACK generation [RFC 1122 RFC 2581]
- Fast Retransmit
- Fast Retransmit
- Fast retransmit algorithm
- TCP Flow Control
- TCP Flow control how it works
- Sliding Window Flow Control Example
- Principles of Congestion Control
- Causescosts of congestion scenario 1
- Causescosts of congestion scenario 2
- Causescosts of congestion scenario 2
- Causescosts of congestion scenario 3
- Causescosts of congestion scenario 3
- Approaches towards congestion control
- TCP Congestion Control
- TCP congestion control bandwidth probing
- TCP Congestion Control details
- TCP Congestion Control more details
- TCP Slow Start Phase
- Slow Start Example
- TCP Congestion Avoidance Phase
- Congestion Avoidance
- Example Slow StartCongestion Avoidance
- Slow Start Congestion Avoidance
- Responses to Congestion
- Fast Recovery (differentiation btwn two loss events)
- TCP Congestion Control
- Popular ldquoflavorsrdquo of TCP
- Summary TCP Congestion Control
- TCP Congestion Control Summary
- TCP throughput
- TCP Futures TCP over ldquolong fat pipesrdquo
- TCP Fairness
- Why is TCP fair
- Fairness (more)
- TCP Connection Management
- TCP Connection Management (cont)
- TCP Connection Management (cont)
- TCP Connection Management (cont)
- Tuning TCPIP Parameters
- SomeTCP Parameters in Linux Kernel
- SomeTCP Parameters in Linux Kernel
-
Transport Layer 3-105
SomeTCP Parameters in Linux Kerneltcp_rmem
This is a vector of 3 integers [min default max] These parameters are used by TCP to dynamically adjust receive buffer sizesmin - minimum size of the receive buffer used by each TCP socket The default value is 4K default - the default size of the receive buffer for a TCP socket The default value is 87380 bytes and is lowered to 43689 in low memory systems If larger receive buffer sizes are desired this value should be increased max - the maximum size of the receive buffer used by each TCP socket The default value of 873802 bytes is lowered to 87380 in low memory systems
tcp_smemSend buffer parameters [min default max] similar to tcp_rmem
- Chapter 3 Transport Layer
- Transport services and protocols
- Transport vs network layer
- Internet transport-layer protocols
- Multiplexingdemultiplexing
- How demultiplexing works
- Connectionless demultiplexing
- Connection-oriented demux
- Connection-oriented demux (cont)
- Connection-oriented demux Threaded Web Server
- UDP User Datagram Protocol [RFC 768]
- UDP more
- UDP checksum
- Principles of Reliable data transfer
- Reliable data transfer getting started
- Reliable data transfer getting started
- Rdt10 reliable transfer over a reliable channel
- Rdt20 channel with bit errors
- rdt20 FSM specification
- rdt20 operation with no errors
- rdt20 error scenario
- rdt20 has a fatal flaw
- rdt21 sender handles garbled ACKNAKs
- rdt21 receiver handles garbled ACKNAKs
- rdt21 discussion
- rdt22 a NAK-free protocol
- rdt22 sender receiver fragments
- rdt30 channels with errors and loss
- rdt30 sender
- rdt30 in action
- rdt30 in action
- Performance of rdt30
- rdt30 stop-and-wait operation
- Pipelined protocols
- Pipelining increased utilization
- Go-Back-N
- GBN sender extended FSM
- GBN receiver extended FSM
- GBN inaction
- Selective Repeat
- Selective repeat sender receiver windows
- Selective repeat
- Selective repeat in action
- Selective repeat dilemma
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- Sequence Number vs Window Size
- TCP Overview RFCs 793 1122 1323 2018 2581
- TCP segment structure
- TCP seq rsquos and ACKs
- TCP Round Trip Time and Timeout
- TCP Round Trip Time and Timeout
- Example RTT estimation
- TCP Round Trip Time and Timeout
- TCP reliable data transfer
- TCP sender events
- TCP sender(simplified)
- TCP retransmission scenarios
- TCP retransmission scenarios (more)
- TCP ACK generation [RFC 1122 RFC 2581]
- Fast Retransmit
- Fast Retransmit
- Fast retransmit algorithm
- TCP Flow Control
- TCP Flow control how it works
- Sliding Window Flow Control Example
- Principles of Congestion Control
- Causescosts of congestion scenario 1
- Causescosts of congestion scenario 2
- Causescosts of congestion scenario 2
- Causescosts of congestion scenario 3
- Causescosts of congestion scenario 3
- Approaches towards congestion control
- TCP Congestion Control
- TCP congestion control bandwidth probing
- TCP Congestion Control details
- TCP Congestion Control more details
- TCP Slow Start Phase
- Slow Start Example
- TCP Congestion Avoidance Phase
- Congestion Avoidance
- Example Slow StartCongestion Avoidance
- Slow Start Congestion Avoidance
- Responses to Congestion
- Fast Recovery (differentiation btwn two loss events)
- TCP Congestion Control
- Popular ldquoflavorsrdquo of TCP
- Summary TCP Congestion Control
- TCP Congestion Control Summary
- TCP throughput
- TCP Futures TCP over ldquolong fat pipesrdquo
- TCP Fairness
- Why is TCP fair
- Fairness (more)
- TCP Connection Management
- TCP Connection Management (cont)
- TCP Connection Management (cont)
- TCP Connection Management (cont)
- Tuning TCPIP Parameters
- SomeTCP Parameters in Linux Kernel
- SomeTCP Parameters in Linux Kernel
-