Lec 11

Download as pdf or txt
Download as pdf or txt
You are on page 1of 8

TCP

• Reliable byte-stream service


• More complex transmitter & receiver
– Connection-oriented: full-duplex unicast connection
between client & server processes
– Connection setup, connection state, connection release
– Higher header overhead
– Error control, flow control, and congestion control
– Higher delay than UDP
• Most applications use TCP
– HTTP, SMTP, FTP, TELNET, POP3, …

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

1 2 ... m 1 2 ... n 1 2 ... k

TCP TCP TCP

IP IP IP

(A, 6234, B, 80) B C


A
(A, 5234, B, 80) (C, 5234, B, 80)

1
TCP Segment Format
0 4 10 16 24 31

Source port Destination port

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

Checksum Urgent pointer

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

Maximum Segment Size


• Maximum Segment Size
– largest block of data that TCP sends to other
end
• Each end can announce its MSS during
connection establishment
• Default is 576 bytes including 20 bytes for
IP header and 20 bytes for TCP header
• Ethernet implies MSS of 1460 bytes
• IEEE 802.3 implies 1452

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

Transport segments buffer used

buffer buffer available = B


advertised
window size < B

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

TCP Congestion Control


• Advertised window size is used to ensure that receiver’s buffer
will not overflow
• However, buffers at intermediate routers between source and
destination may overflow
Router

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

TCP Congestion Control:


Slow Start
• Slow start: increase congestion window size by one
segment upon receiving an ACK from receiver
– initialized at ≤ 2 segments
– used at (re)start of data transfer
– congestion window increases exponentially

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

TCP Congestion Control:


Congestion
• Congestion is detected
Congestion
avoidance
upon timeout or receipt of
20 duplicate ACKs
Time-out • Assume current cwnd
corresponds to available
Congestion window

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

TCP Congestion Control:


Fast Retransmit & Fast Recovery
Congestion
avoidance
20
Time-out
Congestion window

15

Threshold
10

Slow
start
5

Round-trip times

You might also like