TCP provides a completely reliable

TCP: Reliable Transport Service
1
Transmission Control Protocol (TCP)
• Major transport protocol used in Internet
• Heavily used
• Completely reliable transfer
2
TCP Features
•
•
•
•
•
•
•
Connection-oriented service
Point-to-point
Full-duplex communication
Stream interface
Stream divided into segments for transmission
Each segment encapsulated in IP datagram
Uses protocol ports to identify applications
3
TCP Feature Summary
• TCP provides a completely reliable (no data
duplication or loss), connection-oriented, fullduplex stream transport service that allows
two application programs to form a
connection, send data in either direction, and
then terminate the connection.
4
End-to-End Protocol
5
Apparent Contradiction
•
•
•
•
IP offers best-effort (unreliable) delivery
TCP uses IP
TCP provides completely reliable transfer
How is this possible?
6
Achieving Reliability
• Reliable connection startup
• Reliable data transmission
• Graceful connection shutdown
7
Reliable Data Transmission
• Positive acknowledgment
– Receiver returns short message when data arrives
– Called acknowledgment
• Retransmission
– Sender starts timer whenever message is
transmitted
– If timer expires before acknowledgment arrives,
sender retransmits message
8
Illustration Of Retransmission
9
How Long Should TCP Wait
Before Retransmitting?
• Time for acknowledgment to arrive depends
on
– Distance to destination
– Current traffic conditions
• Multiple connections can be open
simultaneously
• Traffic conditions change rapidly
10
Important Point
• The delay required for data to reach a
destination and an acknowledgment to return
depends on traffic in the internet as well as the
distance to the destination. Because it allows
multiple application programs to communicate
with multiple destinations concurrently, TCP
must handle a variety of delays that can
change rapidly.
11
Solving The Retransmission Problem
• Keep estimate of round trip time on each
connection
• Use current estimate to set retransmission
timer
• Known as adaptive retransmission
• Key to TCP’s success
12
Illustration Of Adaptive
Retransmission
• Timeout depends on current round-trip estimate
13
TCP Flow Control
• Receiver
– Advertises available buffer space
– Called window
• Sender
– Can send up to entire window before ack arrives
14
Window Advertisement
• Each acknowledgment carries new window
information
– Called window advertisement
– Can be zero (called closed window)
• Interpretation: have received up through X, and
can take Y more octets
15
Illustration Of Window Advertisement
A TCP acknowledgement specifies the sequence number of the next
octet that the receiver expects to receive
16
Startup And Shutdown
• Connection startup
– Must be reliable
• Connection shutdown
– Must be graceful
• Difficult
17
Why Startup And Shutdown Are Difficult
• Segments can be
–
–
–
–
–
–
Lost
Duplicated
Delayed
Delivered out of order
Either side can crash
Either side can reboot
• Need to avoid duplicate shutdown message
from affecting later connection
18
TCP’s Solution For Startup/Shutdown
• Uses three-message exchange
• Known as 3-way handshake
• Necessary and sufficient for
– Unambiguous, reliable startup
– Unambiguous, graceful shutdown
• SYN used for startup
• FIN used for shutdown
19
Connection Establishment – Threeway Handshake
Active participant
(client)
Passive participant
(server)
20
Closing a TCP Connection
21
TCP Segment Format
• All TCP segments have same format
–
–
–
–
Data
Acknowledgment
SYN (startup)
FIN (shutdown)
• Segment divided into two parts
– Header
– Payload area (zero or more bytes of data)
22
TCP Segment Format
(continued)
• Header contains
– Protocol port numbers to identify
• Sending application
• Receiving application
– Code bits to specify items such as
• SYN
• FIN
• ACK
– Fields for window advertisement,
acknowledgment, etc.
23
Illustration Of TCP Segment
• Sequence number specifies where in stream outgoing data
belongs
• Acknowledgment number refers to incoming data
• Few segments contain options
24
Checksum - One Example
Checksum = 1s complement sum of the 1s complement of 4-bit
quantities.
1s complement of 1111, 0000, 1100, 0101, 1000
is 0000, 1111, 0011, 1010, 0111.
1s complement sum: 0000 + 1111 = 1111.
1111 + 0011 = 0010 + 1 (carry) = 0011
0011 + 1010 = 1101
1101 + 0111 = 0100 + 1 (carry) = 0101
Ans: Checksum = 0101
25
Flow Control And Congestion
• Receiver advertises window that specifies how many
additional bytes it can accept
• Window size of zero means sender must not send
normal data (ACKs and urgent data allowed)
• Sender chooses effective window smaller than
receiver’s advertised window if congestion detected
– Allowed_window = min(receiver_advertisement,
congestion_window)
– Congestion window is reduced by half for every loss –
multiplicative decrease
26
TCP Congestion Control
• When CongWin is below Threshold, sender in slowstart phase, window grows exponentially.
• When CongWin is above Threshold, sender is in
congestion-avoidance phase, window grows linearly.
• When timeout occurs, Threshold set to CongWin/2
and CongWin is set to 1 MSS (Maximum Segment
Size).
• When a triple duplicate ACK occurs, Threshold set to
CongWin/2 and CongWin set to Threshold.
• Additive Increase Multiplicative Decrease (AIMD)
27
TCP Congestion Control
Q: When should the
exponential increase
switch to linear?
A: When
CongestionWindow
gets to 1/2 of its value
before timeout.
Implementation:
• Variable Threshold
• At loss event, Threshold is
set to 1/2 of CongWin just
before loss event
From Tanenbaum’s book, fourth edition, pp. 550
28