0% found this document useful (0 votes)
14 views

Lecture_09_CN214 TCP_Flow & Congestion Control

Uploaded by

hashimalmusalam
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views

Lecture_09_CN214 TCP_Flow & Congestion Control

Uploaded by

hashimalmusalam
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 37

TCP

CN214 Flow & Congestion


Ch. 3

Control
Lecture 09
M.M. Hafizur Rahman

Office: 1186, CCSIT, KFU


Email: [email protected]
Transport Layer Goals
Understand principles behind transport layer
services:
Multiplexing & Demultiplexing
Forwarding versus routing
Transport Layer Protocols
UDP: connectionless transport
TCP: connection-oriented reliable transport
Flow Control
Congestion Control

CCSIT/KFU Transport Layer 2


TCP Retransmission Scenario
Lost Acknowledgement (Both PKT & ACK)
Premature Timeout (ACK Delayed)
Cumulative ACK Covers for earlier lost ACK
Host A Host B Host A Host B Host A Host B

SendBase=92
Seq=92, 8 bytes of data Seq=92, 8 bytes of data Seq=92, 8 bytes of data
timeout

timeout

Seq=100, 20 bytes of data Seq=100, 20 bytes of data


ACK=100
ACK=100
X
ACK=100 X
ACK=120 ACK=120

Seq=92, 8 bytes of data Seq=92, 8


SendBase=100 bytes of data send cumulative Seq=120, 15 bytes of
SendBase=120 ACK for 120 data
ACK=100
ACK=120

SendBase=120
cumulative ACK
lost ACK scenario premature timeout covers for earlier
lost ACK
CCSIT/KFU Transport Layer 3
TCP Fast Retransmit
Host A Host B
TCP fast retransmit
if sender receives 3 additional Se q= 9
ACKs for same data (“triple 2, 8 by
Seq= data tes of
duplicate ACKs”), resend unACKed 100, 2
data
0 b yt e
s of
segment with smallest seq # X
 likely that unACKed segment
lost, so don’t wait for timeout ACK
=100

timeout
=100
ACK
CK =100
A
= 10 0
Receipt of three duplicate ACKs ACK

indicates 3 segments received Seq=100, 20 bytes of data

after a missing segment – lost


segment is likely. So retransmit!

CCSIT/KFU Transport Layer 4


Flow Control

Flow Control: Sender too fast for Receiver


CCSIT/KFU Transport Layer 5
TCP Flow Control
Q: What happens
application
if network layer

receiver side of TCP


Application removing process

connection has a
receive buffer:
delivers data faster data from TCP socket
than application buffers
TCP socket
layer removes App process may receiver buffers
data from socket be slow at reading
buffers? from buffer
TCP
flow control Network layer code
delivering IP datagram
receiver controls sen- payload into TCP
der, so sender won’t socket buffers IP
code
overflow receiver’s Net layer may be
buffer by transmitting fast to reading to
too much, too fast
receive buffer from sender
speed-matching service: Receiver Protocol Stack
matching the send rate to
the receiving app’s drain rate Transport Layer
CCSIT/KFU 6
TCP Segment Structure
32 bits

source port # dest port # segment seq #: counting


ACK: seq # of next expected sequence number bytes of data into bytestream
byte; A bit: this is an ACK (not segments!)
acknowledgement number
length (of TCP header) head not
len used C E U A P R S F receive window Flow Control:
Internet checksum checksum Urg data pointer # bytes receiver
options (variable willing to accept
C, E: congestion notification length)
TCP options
application data sent by
RST, SYN, FIN: connection data application into
management (variable length) TCP socket

CCSIT/KFU Transport Layer 7


TCP Flow Control
TCP receiver advertises free to application process
buffer space in rwnd field in
TCP header RcvBuffer buffered data
RcvBuffer size set via socket
options (typical default is 4096 rwnd free buffer space
bytes)
Many operating systems auto- TCP segment payloads
adjust RcvBuffer
Sender limits amount of TCP receiver-side buffering
unACKed (“in-flight”) data to
spare room in buffer
received rwnd = RcvWindow
Guarantees receive buffer will = RcvBuffer-[LastByteRcvd
not overflow - LastByteRead]
CCSIT/KFU Transport Layer 8
TCP Connection Management
Before exchanging data, sender/receiver handshake:
Agree to establish connection (each knowing the other willing to
establish connection)
Agree on connection parameters (e.g., starting seq #)
application application

connection state: connection state:


ESTAB ESTAB
connection variables: connection Variables:
seq # client-to- seq # client-to-
server server
server-to-client server-to-client
rcvBuffer size rcvBuffer size
network
at server,client at network
server,client

Socket clientSocket = Socket connectionSocket =


newSocket("hostname","port welcomeSocket.accept();
number");
CCSIT/KFU Transport Layer 9
Congestion Control

congestion control: too many senders, sending too fast


Normally: “too many sources sending too much data too
fast for network to handle”
Manifestations:
Long delays (queueing in router buffers)
Packet loss (buffer overflow at routers)
Different from flow control!
CCSIT/KFU &Layer
Transport a top-10 problem! 10
Congestion Control
We assumed that it is only the receiver that can
dictate to the sender the size of the sender’s
window.
We totally ignored another entity here, the network.
In addition to the receiver, the network is a second
entity that determines the size of the sender’s
window.

CCSIT/KFU Transport Layer 11


Queue
A queue consists of a number of packets. These
packets are bound to be routed over the network, lined
up in a sequential way with a changing header and
trailer and taken out of the queue for transmission by a
network device.
If the router is unable to send a packet immediately,
the packet is queued. If the queue is full, the packet is
dropped.
Packets are typically processed on a first-come, first-
served (or FIFO, First In First Out) basis. This adds up
to best-effort forwarding.
CCSIT/KFU Transport Layer 12
Router Queue
Congestion occurs because routers and switches
have queues, and they forward all packets it
receives to the best of its ability. It happens when:
Rate of packet arrival may be higher than packet processing rate
Packet departure rate may be less than packet processing rate

CCSIT/KFU Transport Layer 13


Delay & Throughput
Delay – time taken for a packet from sender to receiver
Throughput – number of packets passing through the
network in one unit time

Packet delay vs. network Throughput vs. network


load load

Queuing delay adds up Load ≥ capacity


when there is Load < capacity - Throughput
congestion - Throughput reduces as packets
proportional to get discarded by
load routers
Minimum delay = propagation delay
+ processing delay

CCSIT/KFU Transport Layer 14


Congestion Window
We introduce new window called cwnd
If the network cannot deliver the data as fast as it is
created by the sender, it must tell the sender to slow
down
This is in addition to rwnd for flow control
Actual window size

CCSIT/KFU Transport Layer 15


Congestion Control Approaches
End-end Congestion Control:
No explicit feedback from network
Congestion inferred from observed loss, delay

data data
ACKs
ACKs

CCSIT/KFU Transport Layer 16


Congestion Control Approaches
Network-assisted congestion control:
Routers provide direct feedback to sending/receiving hosts with
flows passing through congested router
May indicate congestion level or explicitly set sending rate
TCP Explicit Congestion Notification (ECN), ATM, Destination
Echoes Bit (DECbit) protocols

explicit congestion info

data data
ACKs
ACKs

CCSIT/KFU Transport Layer 17


TCP Congestion Policy
TCP’s general policy for handling congestion is
based on three phases:
Slow Start
Congestion avoidance
Congestion detection

CCSIT/KFU Transport Layer 18


Slow Start: Exponential Increase
 Nothing slow about it!
 Size of cwnd starts with one
maximum segment size
(MSS)
- determined as a TCP
option during
connection
establishment
 After receiving each ACK,
cwnd grows exponentially
- 1 -> 2 -> 4 -> 8 …
 Till it reaches slow start
threshold (ssthresh)
 In most implementations the
value of ssthresh is 65535
bytes
Assumption: rwnd > cwnd

CCSIT/KFU Transport Layer 19


Congestion Avoidance: Additive Increase
After reaching
ssthresh, one must
slow down the
exponential
growth
Size of the
congestion
window increases
additively until
congestion is
detected
Increase by one:
1 -> 2 -> 3 -> 4 …
Assumption: rwnd > cwnd
CCSIT/KFU Transport Layer 20
TCP Congest Policy Summary

CCSIT/KFU Transport Layer 21


TCP Retransmission Scenario
Lost Acknowledgement (Both PKT & ACK)
Premature Timeout (ACK Delayed)
Cumulative ACK Covers for earlier lost ACK
Host A Host B Host A Host B Host A Host B

SendBase=92
Seq=92, 8 bytes of data Seq=92, 8 bytes of data Seq=92, 8 bytes of data
timeout

timeout

Seq=100, 20 bytes of data Seq=100, 20 bytes of data


ACK=100
ACK=100
X
ACK=100 X
ACK=120 ACK=120

Seq=92, 8 bytes of data Seq=92, 8


SendBase=100 bytes of data send cumulative Seq=120, 15 bytes of
SendBase=120 ACK for 120 data
ACK=100
ACK=120

SendBase=120
cumulative ACK
lost ACK scenario premature timeout covers for earlier
lost ACK
CCSIT/KFU Transport Layer 22
TCP Fast Retransmit
Host A Host B
TCP fast retransmit
if sender receives 3 additional Se q= 9
ACKs for same data (“triple 2, 8 by
Seq= data tes of
duplicate ACKs”), resend unACKed 100, 2
data
0 b yt e
s of
segment with smallest seq # X
 likely that unACKed segment
lost, so don’t wait for timeout ACK
=100

timeout
=100
ACK
CK =100
A
= 10 0
Receipt of three duplicate ACKs ACK

indicates 3 segments received Seq=100, 20 bytes of data

after a missing segment – lost


segment is likely. So retransmit!

CCSIT/KFU Transport Layer 23


Congestion Detection: MD
Cwnd must be decreased if congestion occurs
Congestion is detected by either RTO timeout or 3 ACKs
If detection is by time-out, a new slow start phase starts
Stronger possibility of congestion
Segment probably lost, no news of following sent segments
TCP must react strongly
If detection is by three ACKs, a new congestion
avoidance phase starts.
Weaker possibility of congestion
Segment may be lost, but following sent segments might have
reached
TCP has a weaker reaction
CCSIT/KFU Transport Layer 24
Congestion Control Example

at cwnd=20

at cwnd=12
at cwnd=12

ssthresh=20/2 = 10 ssthresh=12/2 = 6
cwnd=1 cwnd=ssthresh=6

CCSIT/KFU Transport Layer 25


Congestion Control Example 2
A TCP sender starts sending segments. The initial
ssthresh is set to 32 MSS. It receives 3 duplicate
ACKs at cwnd =40. Later, there is an RTO timeout
at 30.
Show the different phases (slow start, additive increase,
multiplicative decrease), the ssthresh and the cwnd at
various points.
Show the relevant calculations as well.

CCSIT/KFU Transport Layer 26


Congestion Control Example 2

CCSIT/KFU Transport Layer 27


2 Way Handshake
Will 2-way handshake 2-Way Handshake:
always work in network?
Variable delays Let’s talk
ESTAB
Retransmitted messages OK
ESTAB
(e.g. req_conn(x)) due to
message loss
Message reordering
choose x
req_conn(x)
Can’t see other side ESTAB
acc_conn(x)
ESTAB

CCSIT/KFU Transport Layer 28


2 Way Handshake Scenarios

choose x choose x
req_conn(x) req_conn(x)
ESTAB ESTAB
acc_conn(x) retransmit acc_conn(x)
req_conn(
x)
ESTAB ESTAB
data(x+1) accept
data(x+1 req_conn(x)
ACK(x+1)
)
connection connection
x completes client x completes server
terminat forgets x
es

No problem! ESTAB
acc_conn(x)
Problem: half open
connection! (no client)
CCSIT/KFU Transport Layer 29
2 Way Handshake Scenarios
choose x
req_conn(x)
ESTAB
retransmit acc_conn(x)
req_conn(
x)
ESTAB
data(x+1) accept
data(x+1
retransmit )
data(x+1)
connection
x completes server
client
terminat forgets x
es req_conn(x)
ESTAB
data(x+1) accept
data(x+1
)
Problem: dup data
accepted!
CCSIT/KFU Transport Layer 30
TCP: 3 Way Handshaking

Server state
Client state
clientSocket = socket(AF_INET, SOCK_STREAM)
LISTEN
clientSocket.connect((serverName,serverPort)) LISTEN
choose init seq num, x
send TCP SYN msg
SYNSENT SYNbit=1, Seq=x
choose init seq num, y
send TCP SYNACK
msg, acking SYN SYN RCVD
SYNbit=1, Seq=y
ACKbit=1; ACKnum=x+1
received SYNACK(x)
ESTAB indicates server is live;
send ACK for SYNACK;
this segment may contain ACKbit=1, ACKnum=y+1
client-to-server data
received ACK(y)
indicates client is live
ESTAB

CCSIT/KFU Transport Layer 31


Human: 3 Way Handshaking

1. On belay?

2. Belay on.
3. Climbing.

CCSIT/KFU Transport Layer 32


Closing a TCP Connection
Client, server each close their side of
connection
Send TCP segment with FIN bit = 1
Respond to received FIN with ACK
On receiving FIN, ACK can be combined with own FIN
Simultaneous FIN exchanges can be handled

CCSIT/KFU Transport Layer 33


Closing a TCP Connection
client state server state
ESTAB ESTAB
clientSocket.close()
FIN_WAIT_1 can no longer FINbit=1, seq=x
send but can
receive data CLOSE_WAIT
ACKbit=1; ACKnum=x+1
can still
FIN_WAIT_2 wait for server send data
close

LAST_ACK
FINbit=1, seq=y
TIMED_WAIT can no longer
send data
ACKbit=1; ACKnum=y+1
timed wait
for 2*max CLOSED
segment lifetime

CLOSED

CCSIT/KFU Transport Layer 34


TCP RTT and Time Out
How to set TCP timeout value?
Longer than RTT, but RTT varies!
Too short: premature timeout, unnecessary retransmissions
Too long: slow reaction to segment loss
How to estimate RTT?
SampleRTT: Measured time from segment transmission
until ACK receipt
 Ignore retransmissions
SampleRTT will vary, want estimated RTT “smoother”
 Average several recent measurements, not just current
SampleRTT

CCSIT/KFU Transport Layer 35


TCP RTT and Time Out
Exponential weighted moving average (EWMA)
Influence of past sample decreases exponentially fast
Typical value:  = 0.125
EstimatedRTT = (1- )*EstimatedRTT + *SampleRTT RTT: gaia.cs.umass.edu to fantasia.eurecom.fr

350

RTT: gaia.cs.umass.edu to fantasia.eurecom.fr

300
RTT (milliseconds)

RTT (milliseconds)

250

200

sampleRTT
150
EstimatedRTT

100
1 8 15 22 29 36 43 50 57 64 71 78 85 92 99 106
time (seconnds)
time (seconds)
SampleRTT Estimated RTT

CCSIT/KFU Transport Layer 36


Example
Suppose the current TCP round-trip time (RTT) is
30 and the first acknowledgement come in after
32 , what is the new estimated RTT? Assume the
value of  = 0.125.

Ans:
EstimatedRTT = (1- )*EstimatedRTT + *SampleRTT
EstimatedRTT =

CCSIT/KFU Transport Layer 37

You might also like