You are on page 1of 12

Advanced Computer Networks

Lecture 5
The Transport Layer, Transmission
Control Protocol (TCP), and User
Datagram Protocol (UDP)

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
¾…

Review of the transport layer


Leland.Stanford.edu Athena.MIT.edu
Application Layer

Nick Dave

Transport Layer

O.S. Data Header Data Header


O.S.
Network Layer
y D H
D H

D H D H D H

D H Link Layer

2
Layering: The OSI Model
layer-to-layer communication
Application Application
7 7
Presentation Presentation
6 6
Session Session
5 5
Peer-layer communication
Transport Transport
4 Router Router 4
Network Network Network Network
3 3
Link Link Link Link
2 2
Physical Physical Physical Physical
1 1

Layering: Our FTP Example


Application
FTP Application
Presentation ASCII/Binary
Session
TCP Transport
Transport
Network IP Network
Li k
Link
Ethernet Link
Physical

The 7-layer OSI Model The 4-layer Internet Model


6

3
TCP Characteristics
™ TCP is connection-oriented.
¾ 3-way handshake used for connection setup.
™ TCP provides a stream-of-bytes service.
™ TCP is reliable:
¾ 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) (Passive) (Active) (Passive)
Client Server Client Server
Syn Fin

Syn + Ack (Data +) Ack

Ack
Fin

Ack

Connection Setup Connection Close/Teardown


3-way handshake 2 x 2-way handshake

4
TCP supports a “stream of
bytes” service
Host A

Host B

…which is emulated using TCP


“segments”
Host A

Segment sent when:


TCP Data 1. Segment full (MSS bytes),
2. Not full, but times out, or
3. “Pushed” by application.

TCP Data
Host B

10

5
The TCP Segment Format
IP Data
TCP Data TCP Hdr IP Hdr

0 15 31
Src port Dst port

Sequence #
Src/dst port numbers
Ack Sequence # and IP addresses
TCP Header HLEN RSVD
Flags
SYN Window Size uniquely identify socket
URG

PSH
RST

FIN
ACK

6
and Data + IP
4

Addresses Checksum Urg Pointer

(TCP Options)

TCP Data

11

Sequence Numbers
Host A
ISN (initial sequence number)

Sequence TCP
TCP Data
number = 1st HDR

byte Ack sequence


number = next
expected byte
TCP
P
TCP Data HDR
Host B

12

6
Initial Sequence Numbers
(Active) (Passive)
Client 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 over-
running the receiver’s buffers?

14

7
TCP Sliding Window
Window Size

Data ACK’d Outstanding Data OK Data not OK


Un-ack’d data to send 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 Window Size Window Size
???
Host A

Host B
ACK ACK ACK
(1) RTT > Window size (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
™ There will be some (unknown) distribution ™ Router queues grow when there is more
of RTTs. traffic, until they become unstable.
™ We are trying to estimate an RTO to ™ As load grows, variance of delay grows
minimize
i i i ththe probability
b bilit of
f a false
f l timeout.
ti t rapidly.
idl

Average Queueing Delay


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 Host B

Retransmission Retransmission

Wrong RTT Wrong RTT


Sample 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


IP port number to
demultiplex packets

23

User-Datagram Protocol (UDP)


Packet format

SRC port DST port


By default,
default only
covers the header. 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

You might also like