Advanced Computer Networks Lecture 5 The Transport Layer, Transmission Control Protocol (TCP), and User Datagram Protocol (UDP)
1
Outline The Transport p Layer y The TCP Protocol
¾ ¾ ¾ ¾ ¾ ¾ ¾
TCP Characteristics TCP Connection setup TCP Segments TCP Sequence Numbers TCP Sliding Window Timeouts and Retransmission (Congestion Control and Avoidance)
The UDP Protocol 2
1
The Transport Layer What is the transport layer for? What characteristics might it have?
¾ Reliable delivery ¾ Flow control ¾…
3
Review of the transport layer Leland.Stanford.edu
Athena.MIT.edu
Application Layer
Nick
Dave Transport Layer
O.S. D
Data
Header
Data
O.S.
Header
Network Layer y
H
D
H
D
D
H
H
D
D
H
H
Link Layer 4
2
Layering: The OSI Model layer-to-layer communication Application
Application
Presentation
Presentation
7 6 5 4 3 2 1
7 6
Session
Session
Peer-layer communication
Transport
Transport
Router
Router
Network
Network
Network
Network
Link
Link
Link
Link
Physical
Physical
Physical
Physical
5 4 3 2 1
5
Layering: Our FTP Example Application Presentation
FTP ASCII/Binary
Session TCP
Transport
IP
Network
Ethernet
Link
Transport Network Li k Link Physical
Application
The 7-layer OSI Model
The 4-layer Internet Model 6
3
TCP Characteristics
TCP is connection-oriented. ¾
TCP provides a stream-of-bytes service. TCP is reliable: ¾ ¾ ¾ ¾ ¾ ¾
3-way handshake used for connection setup.
Acknowledgements indicate delivery of data. Checksums are used to detect corrupted data. Sequence numbers detect missing, or mis-sequenced data. Corrupted data is retransmitted after a timeout. Mis-sequenced q data is re-sequenced. q (Window-based) Flow control prevents over-run of receiver.
TCP uses congestion control to share network capacity among users. We’ll study this in the next lecture. 7
TCP is connection-oriented (Active) Client
Syn
(Passive) Server
Syn + Ack Ack
(Active) Client
Fin
(Passive) Server
(Data +) Ack Fin Ack
Connection Setup 3-way handshake
Connection Close/Teardown 2 x 2-way handshake 8
4
TCP supports a “stream of bytes” service Host A
Host B
9
…which is emulated using TCP “segments” Host A
Segment sent when:
TCP Data
Host B
1. Segment full (MSS bytes), 2. Not full, but times out, or 3. “Pushed” by application. TCP Data
10
5
The TCP Segment Format IP Data TCP Data
0
TCP Hdr
15 Src port
31 Dst port
Sequence # Ack Sequence # HLEN 4
RSVD 6
Flags
URG ACK PSH RST SYN FIN
TCP Header and Data + IP Addresses
IP Hdr
Checksum
Window Size
Src/dst port numbers and IP addresses uniquely identify socket
Urg Pointer
(TCP Options)
TCP Data 11
Sequence Numbers Host A
ISN (initial sequence number)
Sequence number = 1st byte
Host B
TCP Data
TCP HDR
TCP Data
Ack sequence number = next expected byte TCP P HDR
12
6
Initial Sequence Numbers (Active) Client
(Passive) Server
Syn +ISNA
Syn + Ack +ISNB Ack
Connection Setup 3-way handshake 13
TCP Sliding Window How much data can a TCP sender have outstanding d in the h network? k How much data should TCP retransmit when an error occurs? Just selectively repeat the missing data? How does the TCP sender avoid overrunning the receiver’s buffers?
14
7
TCP Sliding Window Window Size
Data ACK’d
Outstanding Un-ack’d data
Data OK to send
Data not OK to send yet
Window is meaningful to the sender. Current window size is “advertised” by receiver (usually 4k – 8k Bytes when connection set-up). TCP’s Retransmission policy is “Go Back N”.
15
TCP Sliding Window Round-trip time
Round-trip time Window Size
Host A
Host B
???
Window Size
ACK (1) RTT > Window size
Window Size
ACK ACK (2) RTT = Window size
16
8
TCP: Retransmission and Timeouts Round-trip time (RTT)
Retransmission TimeOut (RTO) Guard Band
Host A
Estimated RTT
Data1
Data2
ACK
ACK
Host B TCP uses an adaptive retransmission timeout value: Congestion RTT changes Changes in Routing frequently 17
TCP: Retransmission and Timeouts Picking the RTO is important:
Pick a values that’s too big and it will wait too long to retransmit a packet, Pick a value too small, and it will unnecessarily retransmit packets.
The original algorithm for picking RTO: 1. EstimatedRTTk= α EstimatedRTTk-1 + (1 - α) SampleRTT 2. RTO = 2 * EstimatedRTT Determined empirically
Characteristics of the original algorithm:
Variance is assumed to be fixed. But in practice, variance increases as congestion increases.
18
9
TCP: Retransmission and Timeouts
Router queues grow when there is more traffic, until they become unstable. As load grows, variance of delay grows rapidly. idl
Average Queueing Delay
There will be some (unknown) distribution of RTTs. We are trying to estimate an RTO to minimize i i i th the probability b bilit of f a false f l timeout. ti t Probability
Variance grows rapidly with load
variance
mean
RTT
Load (Amount of traffic arriving to router) 19
TCP: Retransmission and Timeouts Newer Algorithm includes estimate of variance in RTT:
Same as
Difference = SampleRTT - EstimatedRTT before EstimatedRTTk = EstimatedRTTk-1 + (δ*Difference) Deviation = Deviation + δ*( |Difference| - Deviation )
RTO = μ * EstimatedRTT + φ * Deviation μ≈1 φ≈4
20
10
TCP: Retransmission and Timeouts Karn’s Algorithm
Host A
Host B
Host A
Retransmission Wrong RTT Sample
Host B
Retransmission Wrong RTT Sample
Problem:
How can we estimate RTT when packets are retransmitted?
Solution:
On retransmission, don’t update estimated RTT (and double RTO). 21
User Datagram Protocol (UDP) Characteristics
UDP is a connectionless datagram service.
¾ There is no connection establishment: packets may show up at any time.
UDP packets are self-contained. UDP is unreliable:
¾ No acknowledgements to indicate delivery of data. ¾ Checksums cover the header, and only optionally cover the data. ¾ Contains no mechanism to detect missing or mis-sequenced packets. ¾ No mechanism for automatic retransmission. ¾ No mechanism for flow control, and so can over-run the receiver.
22
11
User-Datagram Protocol (UDP) A1
A2
B1
B2
App
App
App
App
OS UDP
Like TCP, UDP uses port number to demultiplex packets
IP
23
User-Datagram Protocol (UDP) Packet format
By default, default only covers the header.
SRC port
DST port
checksum
length DATA
Why do we have ha e UDP? D ?
¾ It is used by applications that don’t need reliable delivery, or ¾ Applications that have their own special needs, such as streaming of real-time audio/video.
24
12