Lec 11
Lec 11
Lec 11
TCP Multiplexing
• A TCP connection is specified by a 4-tuple
– (source IP address, source port, destination IP address,
destination port)
• TCP allows multiplexing of multiple connections between end
systems to support multiple applications simultaneously
• Arriving segment directed according to connection 4-tuple
IP IP IP
1
TCP Segment Format
0 4 10 16 24 31
Sequence number
Acknowledgment number
U A P R S F
Header
Reserved R C S S Y I Window size
length G K H T N N
Options Padding
Data
• Each TCP segment has header of 20 or more bytes + 0 or more bytes of data
TCP Header
Port Numbers Sequence Number
• A socket identifies a • Byte count
connection endpoint • First byte in segment
– IP address + port • 32 bits long
• A connection specified by a • 0 ≤ SN ≤ 232-1
socket pair • Initial sequence number
• Well-known ports selected during connection
– FTP 20 setup
– Telnet 23
– DNS 53
– HTTP 80
2
TCP Header
Acknowledgement Window Size
Number • 16 bits to advertise
• SN of next byte window size
expected by receiver • Used for flow control
• Acknowledges that all • Sender will accept
prior bytes in stream bytes with SN from
have been received ACK to ACK +
correctly window
• Valid if ACK flag is set • Maximum window
size is 65535 bytes
3
Reliable Byte-Stream Service
• Reliability
– TCP uses Selective Repeat ARQ protocol
– Acknowledgement + Time-out
– Sliding-window mechanism
Flow Control
• Buffer limitations & speed mismatch can
result in loss of data that arrives at
destination
• Receiver controls rate at which sender
transmits to prevent buffer overflow
Application
4
Congestion Control
• Available bandwidth to destination varies with
activity of other users
• Transmitter dynamically adjusts transmission
rate according to network congestion as
indicated by RTT (round trip time) & ACKs
• Elastic utilization of network bandwidth
Packet R bps
flows from
many
sources
• Congestion occurs when total arrival rate from all packet flows
exceeds R over a sustained period of time
• Buffers at multiplexer will fill and packets will be lost
5
Window Congestion Control
• TCP sender maintains a congestion window
cwnd to control congestion at intermediate
routers
• Effective window is minimum of congestion
window and advertised window
• Problem: source does not know what its “fair”
share of available bandwidth should be
• Solution: adapt dynamically to available BW
– Sources probe the network by increasing cwnd
– When congestion detected, sources reduce rate
– Ideally, sources sending rate stabilizes near ideal
point
cwnd
Seg 8
4
2
1
ACK RTTs
6
TCP Congestion Control:
Congestion Avoidance
• Algorithm progressively sets
a congestion threshold cwnd
– When cwnd > threshold,
slow down rate at which
cwnd is increased
8 threshold
• Increase congestion window
size by one segment per
round-trip-time (RTT)
– Each time an ACK
arrives, cwnd is 4
increased by 1/cwnd
– In one RTT, cwnd 2
segments are sent, so
total increase in cwnd is 1
cwnd x 1/cwnd = 1 RTTs
– cwnd grows linearly with
time
15 bandwidth
• Adjust congestion threshold
Threshold = ½ x current cwnd
10 • Reset cwnd to 1
• Go back to slow-start
Slow
start • Over several cycles expect
5 to converge to congestion
threshold equal to about ½
the available bandwidth
0
Round-trip times
7
Fast Retransmit & Fast Recovery
• Congestion causes many segments to be
dropped
• If only a single segment is dropped, then
subsequent segments trigger duplicate ACKs
before timeout SN=1
• Can avoid large decrease in cwnd as follows: SN=2 ACK=2
– When three duplicate ACKs arrive, SN=3
retransmit lost segment immediately SN=4 ACK=2
SN=5 ACK=2
– Reset congestion threshold to ½ cwnd ACK=2
– Reset cwnd to congestion threshold + 3 to
account for the three segments that
triggered duplicate ACKs
– Remain in congestion avoidance phase
– However if timeout expires, reset cwnd to
1
– In absence of timeouts, cwnd will oscillate
around optimal value
15
Threshold
10
Slow
start
5
Round-trip times