winter 2008cs244a handout #61 cs244a: an introduction to computer networks handout 6: the transport...

24
Winter 2008 CS244a Handout #6 1 CS244a: An Introduction to Computer Networks Handout 6: The Transport Layer, Transmission Control Protocol (TCP), and User Datagram Protocol (UDP) Nick McKeown Professor of Electrical Engineering and Computer Science, Stanford University [email protected] http://www.stanford.edu/~nickm

Upload: taya-ide

Post on 16-Dec-2015

218 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Winter 2008CS244a Handout #61 CS244a: An Introduction to Computer Networks Handout 6: The Transport Layer, Transmission Control Protocol (TCP), and User

Winter 2008 CS244a Handout #6 1

CS244a: An Introduction to Computer Networks

Handout 6: The Transport Layer, Transmission Control Protocol

(TCP), and User Datagram Protocol (UDP)

Nick McKeownProfessor of Electrical Engineering and Computer Science, Stanford University

[email protected]://www.stanford.edu/~nickm

Page 2: Winter 2008CS244a Handout #61 CS244a: An Introduction to Computer Networks Handout 6: The Transport Layer, Transmission Control Protocol (TCP), and User

Winter 2008 CS244a Handout #6 2

Outline

The Transport Layer 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

Page 3: Winter 2008CS244a Handout #61 CS244a: An Introduction to Computer Networks Handout 6: The Transport Layer, Transmission Control Protocol (TCP), and User

Winter 2008 CS244a Handout #6 3

The Transport Layer

What is the transport layer for? What characteristics might it have?

Reliable delivery Flow control …

Page 4: Winter 2008CS244a Handout #61 CS244a: An Introduction to Computer Networks Handout 6: The Transport Layer, Transmission Control Protocol (TCP), and User

Winter 2008 CS244a Handout #6 4

Review of the transport layer

Nick Dave

Leland.Stanford.edu Athena.MIT.edu

Network Layer

Link Layer

Application Layer

Transport Layer

O.S. O.S.HeaderData HeaderData

HD

HD

HD

HD HD

HD

Page 5: Winter 2008CS244a Handout #61 CS244a: An Introduction to Computer Networks Handout 6: The Transport Layer, Transmission Control Protocol (TCP), and User

Winter 2008 CS244a Handout #6 5

Layering: The OSI Model

Session

Network

Link

PhysicalPhysicalPhysical

Application

Presentation

Transport

Network

Link Link

Network

Transport

Session

Presentation

Application

Network

Link

Physical

Peer-layer communication

layer-to-layer communication

Router Router

1

2

3

4

5

6

7

1

2

3

4

5

6

7

Page 6: Winter 2008CS244a Handout #61 CS244a: An Introduction to Computer Networks Handout 6: The Transport Layer, Transmission Control Protocol (TCP), and User

Winter 2008 CS244a Handout #6 6

Layering: Our FTP Example

Network

Link

Transport

Application

Presentation

Session

Transport

Network

Link

Physical

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

ApplicationFTP

ASCII/Binary

IP

TCP

Ethernet

Page 7: Winter 2008CS244a Handout #61 CS244a: An Introduction to Computer Networks Handout 6: The Transport Layer, Transmission Control Protocol (TCP), and User

Winter 2008 CS244a Handout #6 7

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 data is re-sequenced. (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.

Page 8: Winter 2008CS244a Handout #61 CS244a: An Introduction to Computer Networks Handout 6: The Transport Layer, Transmission Control Protocol (TCP), and User

Winter 2008 CS244a Handout #6 8

TCP is connection-oriented

Connection Setup3-way handshake

(Active)Client

(Passive)Server

Syn

Syn + Ack

Ack

Connection Close/Teardown2 x 2-way handshake

(Active)Client

(Passive)Server

Fin

(Data +) Ack

Fin

Ack

Page 9: Winter 2008CS244a Handout #61 CS244a: An Introduction to Computer Networks Handout 6: The Transport Layer, Transmission Control Protocol (TCP), and User

Winter 2008 CS244a Handout #6 9

TCP supports a “stream of bytes” service

By te 0

By te 1

By te 2

By te 3

By te 0

By te 1

By te 2

By te 3

Host A

Host B

By te 8 0

By te 8 0

Page 10: Winter 2008CS244a Handout #61 CS244a: An Introduction to Computer Networks Handout 6: The Transport Layer, Transmission Control Protocol (TCP), and User

Winter 2008 CS244a Handout #6 10

…which is emulated using TCP “segments”

By te 0

By te 1

By te 2

By te 3

By te 0

By te 1

By te 2

By te 3

Host A

Host B

By te 8 0

TCP Data

TCP Data

By te 8 0

Segment sent when:1. Segment full (MSS

bytes),2. Not full, but times out, or3. “Pushed” by application.

Page 11: Winter 2008CS244a Handout #61 CS244a: An Introduction to Computer Networks Handout 6: The Transport Layer, Transmission Control Protocol (TCP), and User

Winter 2008 CS244a Handout #6 11

The TCP Segment Format

IP HdrIP Data

TCP HdrTCP Data

Src port Dst port

Sequence #

Ack Sequence #

HLEN4

RSVD6

UR

GA

CK

PS

HR

ST

SYN

FIN

FlagsWindow Size

Checksum Urg Pointer

(TCP Options)

0 15 31

TCP Data

TCP Header and Data + IP

Addresses

Src/dst port numbersand IP addresses uniquely identify

socket

Page 12: Winter 2008CS244a Handout #61 CS244a: An Introduction to Computer Networks Handout 6: The Transport Layer, Transmission Control Protocol (TCP), and User

Winter 2008 CS244a Handout #6 12

Sequence NumbersHost A

Host B

TCP Data

TCP Data

TCP HDR

TCP HDR

ISN (initial sequence number)

Sequence number = 1st

byte Ack sequence number =

next expected byte

Page 13: Winter 2008CS244a Handout #61 CS244a: An Introduction to Computer Networks Handout 6: The Transport Layer, Transmission Control Protocol (TCP), and User

Winter 2008 CS244a Handout #6 13

Initial Sequence Numbers

Connection Setup3-way handshake

(Active)Client

(Passive)Server

Syn +ISNA

Syn + Ack +ISNB

Ack

Page 14: Winter 2008CS244a Handout #61 CS244a: An Introduction to Computer Networks Handout 6: The Transport Layer, Transmission Control Protocol (TCP), and User

Winter 2008 CS244a Handout #6 14

TCP Sliding Window How much data can a TCP sender have

outstanding in the network? 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?

Page 15: Winter 2008CS244a Handout #61 CS244a: An Introduction to Computer Networks Handout 6: The Transport Layer, Transmission Control Protocol (TCP), and User

Winter 2008 CS244a Handout #6 15

TCP Sliding WindowWindow Size

OutstandingUn-ack’d data

Data OK to send

Data not OK to send yet

Data ACK’d

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”.

Page 16: Winter 2008CS244a Handout #61 CS244a: An Introduction to Computer Networks Handout 6: The Transport Layer, Transmission Control Protocol (TCP), and User

Winter 2008 CS244a Handout #6 16

TCP Sliding Window

Host A

Host BACK

Window Size

Round-trip time

(1) RTT > Window size

ACK

Window Size

Round-trip time

(2) RTT = Window sizeACK

Window Size???

Page 17: Winter 2008CS244a Handout #61 CS244a: An Introduction to Computer Networks Handout 6: The Transport Layer, Transmission Control Protocol (TCP), and User

Winter 2008 CS244a Handout #6 17

TCP: Retransmission and Timeouts

Host A

Host B

ACK

Round-trip time (RTT)

ACK

Retransmission TimeOut (RTO)

Estimated RTT

Data1 Data2

Guard

Band

TCP uses an adaptive retransmission timeout value:

CongestionChanges in Routing

RTT changes frequently

Page 18: Winter 2008CS244a Handout #61 CS244a: An Introduction to Computer Networks Handout 6: The Transport Layer, Transmission Control Protocol (TCP), and User

Winter 2008 CS244a Handout #6 18

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 - )

SampleRTT2. RTO = 2 * EstimatedRTT

Characteristics of the original algorithm: Variance is assumed to be fixed. But in practice, variance increases as congestion

increases.

Determined empirically

Page 19: Winter 2008CS244a Handout #61 CS244a: An Introduction to Computer Networks Handout 6: The Transport Layer, Transmission Control Protocol (TCP), and User

Winter 2008 CS244a Handout #6 19

TCP: Retransmission and Timeouts

There will be some (unknown) distribution of RTTs. We are trying to estimate an RTO to minimize the probability of a false timeout.

RTT

Pro

babi

lity

mean

variance

Load(Amount of trafficarriving to router)

Ave

rage

Que

uein

g D

elay

Variance grows

rapidly with load

Router queues grow when there is more traffic, until they become unstable. As load grows, variance of delay grows rapidly.

Page 20: Winter 2008CS244a Handout #61 CS244a: An Introduction to Computer Networks Handout 6: The Transport Layer, Transmission Control Protocol (TCP), and User

Winter 2008 CS244a Handout #6 20

TCP: Retransmission and Timeouts

Newer Algorithm includes estimate of variance in RTT:

Difference = SampleRTT - EstimatedRTT EstimatedRTTk = EstimatedRTTk-1 + (*Difference) Deviation = Deviation + *( |Difference| - Deviation )

RTO = * EstimatedRTT + * Deviation 1 4

Same as before

Page 21: Winter 2008CS244a Handout #61 CS244a: An Introduction to Computer Networks Handout 6: The Transport Layer, Transmission Control Protocol (TCP), and User

Winter 2008 CS244a Handout #6 21

TCP: Retransmission and TimeoutsKarn’s Algorithm

Retransmission

Wrong RTT Sample

Host A Host B

Retransmission

Wrong RTT Sample

Host A Host B

Problem: How can we estimate RTT when packets are retransmitted?Solution: On retransmission, don’t update estimated RTT (and double RTO).

Page 22: Winter 2008CS244a Handout #61 CS244a: An Introduction to Computer Networks Handout 6: The Transport Layer, Transmission Control Protocol (TCP), and User

Winter 2008 CS244a Handout #6 22

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.

Page 23: Winter 2008CS244a Handout #61 CS244a: An Introduction to Computer Networks Handout 6: The Transport Layer, Transmission Control Protocol (TCP), and User

Winter 2008 CS244a Handout #6 23

User-Datagram Protocol (UDP)

App App

A1 A2

App App

B1 B2

UDP

OS

IP

Like TCP, UDP uses port number to demultiplex packets

Page 24: Winter 2008CS244a Handout #61 CS244a: An Introduction to Computer Networks Handout 6: The Transport Layer, Transmission Control Protocol (TCP), and User

Winter 2008 CS244a Handout #6 24

SRC port DST port

checksum

length

DATA

User-Datagram Protocol (UDP)

Packet format

Why do we have UDP? 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.

By default, only covers the

header.