58
1 Outline The Transport Layer The TCP Protocol (RFC 793, 1122, 1323,...) TCP Characteristics TCP Connection setup TCP Segments TCP Sequence Numbers TCP Sliding Window Timeouts and Retransmission (Congestion Control and Avoidance) The UDP Protocol (RFC 768)

1 Outline The Transport Layer The TCP Protocol (RFC 793, 1122, 1323,...) TCP Characteristics TCP Connection setup TCP Segments TCP Sequence

Embed Size (px)

Citation preview

Page 1: 1 Outline  The Transport Layer  The TCP Protocol (RFC 793, 1122, 1323,...)  TCP Characteristics  TCP Connection setup  TCP Segments  TCP Sequence

1

Outline

The Transport Layer The TCP Protocol (RFC 793, 1122, 1323,...)

TCP Characteristics TCP Connection setup TCP Segments TCP Sequence Numbers TCP Sliding Window Timeouts and Retransmission (Congestion Control and Avoidance)

The UDP Protocol (RFC 768)

Page 2: 1 Outline  The Transport Layer  The TCP Protocol (RFC 793, 1122, 1323,...)  TCP Characteristics  TCP Connection setup  TCP Segments  TCP Sequence

2

Well known port numbers

• 0-1023 is managed by IANA, e.g.:

Page 3: 1 Outline  The Transport Layer  The TCP Protocol (RFC 793, 1122, 1323,...)  TCP Characteristics  TCP Connection setup  TCP Segments  TCP Sequence

3

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 4: 1 Outline  The Transport Layer  The TCP Protocol (RFC 793, 1122, 1323,...)  TCP Characteristics  TCP Connection setup  TCP Segments  TCP Sequence

4

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 5: 1 Outline  The Transport Layer  The TCP Protocol (RFC 793, 1122, 1323,...)  TCP Characteristics  TCP Connection setup  TCP Segments  TCP Sequence

5

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

Ethernetor HDLC+V.35

Page 6: 1 Outline  The Transport Layer  The TCP Protocol (RFC 793, 1122, 1323,...)  TCP Characteristics  TCP Connection setup  TCP Segments  TCP Sequence

6

UDP, TCP, SCTP

Page 7: 1 Outline  The Transport Layer  The TCP Protocol (RFC 793, 1122, 1323,...)  TCP Characteristics  TCP Connection setup  TCP Segments  TCP Sequence

7

TCP Characteristics TCP is connection-oriented.

3-way handshake used for connection setup/teardown. 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.

Page 8: 1 Outline  The Transport Layer  The TCP Protocol (RFC 793, 1122, 1323,...)  TCP Characteristics  TCP Connection setup  TCP Segments  TCP Sequence

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

(Data)

Page 9: 1 Outline  The Transport Layer  The TCP Protocol (RFC 793, 1122, 1323,...)  TCP Characteristics  TCP Connection setup  TCP Segments  TCP Sequence

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: 1 Outline  The Transport Layer  The TCP Protocol (RFC 793, 1122, 1323,...)  TCP Characteristics  TCP Connection setup  TCP Segments  TCP Sequence

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: 1 Outline  The Transport Layer  The TCP Protocol (RFC 793, 1122, 1323,...)  TCP Characteristics  TCP Connection setup  TCP Segments  TCP Sequence

11

TCP segment format

Page 12: 1 Outline  The Transport Layer  The TCP Protocol (RFC 793, 1122, 1323,...)  TCP Characteristics  TCP Connection setup  TCP Segments  TCP Sequence

12

Pseudo header used in checksum

IP header

Page 13: 1 Outline  The Transport Layer  The TCP Protocol (RFC 793, 1122, 1323,...)  TCP Characteristics  TCP Connection setup  TCP Segments  TCP Sequence

13

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 14: 1 Outline  The Transport Layer  The TCP Protocol (RFC 793, 1122, 1323,...)  TCP Characteristics  TCP Connection setup  TCP Segments  TCP Sequence

14

TCP segment structure

source port # dest. port #

32 bits

applicationdata

(variable length)

sequence number

acknowledgement numberrcvr window size

ptr urgent datachecksum

FSRPAUheadlen

notused

Options (variable length)

URG: urgent data (generally not used)

ACK: ACK #valid

PSH: push data now(generally not used)

RST, SYN, FIN:connection established

(setup, tear downcommands)

# bytes rcvr willingto accept

countingby bytes of data(not segments!)

Internetchecksum

(as in UDP)

typically:maximum TCP payload(default is536bytes);window scale,selective repeat

Page 15: 1 Outline  The Transport Layer  The TCP Protocol (RFC 793, 1122, 1323,...)  TCP Characteristics  TCP Connection setup  TCP Segments  TCP Sequence

15

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 16: 1 Outline  The Transport Layer  The TCP Protocol (RFC 793, 1122, 1323,...)  TCP Characteristics  TCP Connection setup  TCP Segments  TCP Sequence

16

Initial Sequence Numbers

Connection Setup3-way handshake

(Active)Client

(Passive)Server

Syn +ISNA

Syn + Ack +ISNB

Ack

Page 17: 1 Outline  The Transport Layer  The TCP Protocol (RFC 793, 1122, 1323,...)  TCP Characteristics  TCP Connection setup  TCP Segments  TCP Sequence

17

Host A Host B

SYN, Seq_no = x

SYN, Seq_no = y, ACK, Ack_no = x+1

Seq_no = x+1, ACK, Ack_no = y+1

3-way Handshake for connection establishment

Page 18: 1 Outline  The Transport Layer  The TCP Protocol (RFC 793, 1122, 1323,...)  TCP Characteristics  TCP Connection setup  TCP Segments  TCP Sequence

18

Host A (Client) Host B (Server)

SYN, Seq_no = x

SYN, Seq_no = y, ACK, Ack_no = x+1

Seq_no = x+1, ACK, Ack_no = y+1

socketbindlistenaccept (blocks)

socketconnect (blocks)

connect returns

accept returnsread (blocks)

writeread (blocks)

read returns

writeread (blocks)

read returns

request message

reply message

TCP application example

Page 19: 1 Outline  The Transport Layer  The TCP Protocol (RFC 793, 1122, 1323,...)  TCP Characteristics  TCP Connection setup  TCP Segments  TCP Sequence

19

Host A Host B

Seq_no = 2000, Ack_no = 1, Win = 1024, Data = 2000-3023

Seq_no = 1, Ack_no = 4048, Win = 512, Data = 1-128

Seq_no = 3024, Ack_no = 1, Win = 1024, Data = 3024-4047

Seq_no = 4048, Ack_no = 129, Win = 1024, Data = 4048-4559

t1

t2

t3

t4

Seq_no = 1, Ack_no = 2000, Win = 2048, No Data t0

TCP Window control

Page 20: 1 Outline  The Transport Layer  The TCP Protocol (RFC 793, 1122, 1323,...)  TCP Characteristics  TCP Connection setup  TCP Segments  TCP Sequence

20

FIN, seq = 5086

ACK = 5087

Data, seq. = 303, ACK = 5087Deliver 150 bytes

FIN, seq. =453, ACK = 5087

ACK = 454

Host A Host B

ACK = 453

Connection Termination

Page 21: 1 Outline  The Transport Layer  The TCP Protocol (RFC 793, 1122, 1323,...)  TCP Characteristics  TCP Connection setup  TCP Segments  TCP Sequence

21

TCP states

Page 22: 1 Outline  The Transport Layer  The TCP Protocol (RFC 793, 1122, 1323,...)  TCP Characteristics  TCP Connection setup  TCP Segments  TCP Sequence

22

TCP finite state machine

Page 23: 1 Outline  The Transport Layer  The TCP Protocol (RFC 793, 1122, 1323,...)  TCP Characteristics  TCP Connection setup  TCP Segments  TCP Sequence

23

Flow control problems

Page 24: 1 Outline  The Transport Layer  The TCP Protocol (RFC 793, 1122, 1323,...)  TCP Characteristics  TCP Connection setup  TCP Segments  TCP Sequence

24

TCP window management

Page 25: 1 Outline  The Transport Layer  The TCP Protocol (RFC 793, 1122, 1323,...)  TCP Characteristics  TCP Connection setup  TCP Segments  TCP Sequence

25

TCP flow control

• Window based• Sender cannot send more data than a

window without acknowledgements.• Window is a minimum of receiver’s

buffer and ‘congestion window’.• After a window of data is transmitted, in

steady state, acks control sending rate.

Page 26: 1 Outline  The Transport Layer  The TCP Protocol (RFC 793, 1122, 1323,...)  TCP Characteristics  TCP Connection setup  TCP Segments  TCP Sequence

26

TCP Flow control

• Congestion window is increased gradually

• At the beginning, set cwnd = 1 (TCP segm)

• At the beginning, set treshold = 64K• For each ack, double the cwnd until a

threshold (slow start)• Increase by 1 for a window of acks after

that (additive increase)

Page 27: 1 Outline  The Transport Layer  The TCP Protocol (RFC 793, 1122, 1323,...)  TCP Characteristics  TCP Connection setup  TCP Segments  TCP Sequence

27

Slow Start

Page 28: 1 Outline  The Transport Layer  The TCP Protocol (RFC 793, 1122, 1323,...)  TCP Characteristics  TCP Connection setup  TCP Segments  TCP Sequence

28

Additive Increase

Page 29: 1 Outline  The Transport Layer  The TCP Protocol (RFC 793, 1122, 1323,...)  TCP Characteristics  TCP Connection setup  TCP Segments  TCP Sequence

29

Basic Control Model

• Reduce speed when congestion is perceived– How is congestion signaled?

• Either mark or drop packets

– How much to reduce?

• Increase speed otherwise– Probe for available bandwidth – how?

Page 30: 1 Outline  The Transport Layer  The TCP Protocol (RFC 793, 1122, 1323,...)  TCP Characteristics  TCP Connection setup  TCP Segments  TCP Sequence

30

Phase Plots

• Simple way to visualize behavior of competing connections over time

User 1’s Allocation x1

User 2’s Allocation

x2

Page 31: 1 Outline  The Transport Layer  The TCP Protocol (RFC 793, 1122, 1323,...)  TCP Characteristics  TCP Connection setup  TCP Segments  TCP Sequence

31

Phase Plots

• What are desirable properties?

• What if flows are not equal?

Efficiency Line

Fairness Line

User 1’s Allocation x1

User 2’s Allocation

x2Optimal point

Overload

Underutilization

Page 32: 1 Outline  The Transport Layer  The TCP Protocol (RFC 793, 1122, 1323,...)  TCP Characteristics  TCP Connection setup  TCP Segments  TCP Sequence

32

Additive Increase/Decrease

T0

T1

Efficiency Line

Fairness Line

User 1’s Allocation x1

User 2’s Allocation

x2

• Both X1 and X2 increase/ decrease by the same amount over time– Additive increase

improves fairness and additive decrease reduces fairness

Page 33: 1 Outline  The Transport Layer  The TCP Protocol (RFC 793, 1122, 1323,...)  TCP Characteristics  TCP Connection setup  TCP Segments  TCP Sequence

33

Muliplicative Increase/Decrease

• Both X1 and X2 increase by the same factor over time– Extension from

origin – constant fairness

T0

T1

Efficiency Line

Fairness Line

User 1’s Allocation x1

User 2’s Allocation

x2

Page 34: 1 Outline  The Transport Layer  The TCP Protocol (RFC 793, 1122, 1323,...)  TCP Characteristics  TCP Connection setup  TCP Segments  TCP Sequence

34

What is the Right Choice?

• Constraints limit us to AIMD– Can have

multiplicative term in increase

– AIMD moves towards optimal point

x0

x1

x2

Efficiency Line

Fairness Line

User 1’s Allocation x1

User 2’s Allocation

x2

Page 35: 1 Outline  The Transport Layer  The TCP Protocol (RFC 793, 1122, 1323,...)  TCP Characteristics  TCP Connection setup  TCP Segments  TCP Sequence

35

TCP Congestion Avoidance

/* slowstart is over */ /* Congwin > threshold */Until (loss event) { every w segments ACKed: Congwin++ }threshold = Congwin/2Congwin = 1perform slowstart

Congestion avoidance

1

Page 36: 1 Outline  The Transport Layer  The TCP Protocol (RFC 793, 1122, 1323,...)  TCP Characteristics  TCP Connection setup  TCP Segments  TCP Sequence

36

TCP Congestion Control

• When TCP sender sees loss in the network, TCP window is reduced (sending rate slowed)

• In fact, TCP cuts the window size in half whenever a loss occurs and then slowly builds it back up

Page 37: 1 Outline  The Transport Layer  The TCP Protocol (RFC 793, 1122, 1323,...)  TCP Characteristics  TCP Connection setup  TCP Segments  TCP Sequence

37

TCP Window Dynamics

Page 38: 1 Outline  The Transport Layer  The TCP Protocol (RFC 793, 1122, 1323,...)  TCP Characteristics  TCP Connection setup  TCP Segments  TCP Sequence

38

TCP Sliding WindowWindow Size

OutstandingUn-ack’d data

Data OK to send

Data not OK to send yet

Data ACK’d

Retransmission policy is “Go Back N”. Current window size is “advertised” by receiver (usually 4k – 8k Bytes when connection set-up).

Page 39: 1 Outline  The Transport Layer  The TCP Protocol (RFC 793, 1122, 1323,...)  TCP Characteristics  TCP Connection setup  TCP Segments  TCP Sequence

39

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 40: 1 Outline  The Transport Layer  The TCP Protocol (RFC 793, 1122, 1323,...)  TCP Characteristics  TCP Connection setup  TCP Segments  TCP Sequence

40

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 41: 1 Outline  The Transport Layer  The TCP Protocol (RFC 793, 1122, 1323,...)  TCP Characteristics  TCP Connection setup  TCP Segments  TCP Sequence

41

RTT probability density

small network large network

Page 42: 1 Outline  The Transport Layer  The TCP Protocol (RFC 793, 1122, 1323,...)  TCP Characteristics  TCP Connection setup  TCP Segments  TCP Sequence

42

TCP Timeout

Q: how to set TCP timeout value?

• too short: premature timeout– unnecessary

retransmissions

• too long: slow reaction to segment loss

• even worse: RTT fluctuates

Q: how to estimate RTT?• SampleRTT: measured time

from segment transmission until ACK receipt– ignore retransmissions,

cumulatively ACKed segments• SampleRTT will vary, want a

“smoother” estimated RTT– use several recent

measurements, not just current SampleRTT

• Using the average of SampleRTT will generate many timeouts due to network variations– consider variance as well

RTT

RTT

freq.

Page 43: 1 Outline  The Transport Layer  The TCP Protocol (RFC 793, 1122, 1323,...)  TCP Characteristics  TCP Connection setup  TCP Segments  TCP Sequence

43

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. EstimatedRTT = EstimatedRTT + (1 - ) SampleRTT2. RTO = 2 * EstimatedRTT

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

increases.

Page 44: 1 Outline  The Transport Layer  The TCP Protocol (RFC 793, 1122, 1323,...)  TCP Characteristics  TCP Connection setup  TCP Segments  TCP Sequence

44

TCP: Retransmission and Timeouts

Newer Algorithm includes estimate of variance in RTT:

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

RTO = * EstimatedRTT + * Deviation 1 4

Page 45: 1 Outline  The Transport Layer  The TCP Protocol (RFC 793, 1122, 1323,...)  TCP Characteristics  TCP Connection setup  TCP Segments  TCP Sequence

45

TCP Timeout: Initial Timeout

EstimatedRTT = (1-x)*EstimatedRTT + x*SampleRTT• exponential weighted moving average• influence of given sample decreases exponentially fast• typical value of x: 0.125

• Estimate the variance of RTT

Timeout = EstimatedRTT + 4*Deviation

Deviation = (1-x)*Deviation + x*|SampleRTT-EstimatedRTT|

• Estimate the average of RTT

• Set initial timeout value

Page 46: 1 Outline  The Transport Layer  The TCP Protocol (RFC 793, 1122, 1323,...)  TCP Characteristics  TCP Connection setup  TCP Segments  TCP Sequence

46

An Example of Initial Timeout

timeout value

per packet round-trip time

Page 47: 1 Outline  The Transport Layer  The TCP Protocol (RFC 793, 1122, 1323,...)  TCP Characteristics  TCP Connection setup  TCP Segments  TCP Sequence

47

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 48: 1 Outline  The Transport Layer  The TCP Protocol (RFC 793, 1122, 1323,...)  TCP Characteristics  TCP Connection setup  TCP Segments  TCP Sequence

48

TL: TCP flow control enhancements

• Solutions to silly window syndrome– Problem: sender sends in large blocks, but

receiving application reads data 1 byte at the time

• Clark (1982)– receiver avoidance– prevent receiver from advertising small windows– increase advertised receiver window by min(MSS,

RecvBuffer/2)

Page 49: 1 Outline  The Transport Layer  The TCP Protocol (RFC 793, 1122, 1323,...)  TCP Characteristics  TCP Connection setup  TCP Segments  TCP Sequence

49

TL: TCP flow control enhancements

• Nagle’s algorithm (1984)– sender avoidance– prevent sender from unnecessarily sending small packets– http://www.rfc-editor.org/rfc/rfc896.txt

• “Inhibit the sending of new TCP segments when new outgoing data arrives from the user if any previously transmitted data on the connection remains unacknowledged”

• Allow only one outstanding small (not full sized) segment that has not yet been acknowledged

• Works for idle connections (no deadlock)• Works for telnet (send one-byte packets immediately)• Works for bulk data transfer (delay sending)

Page 50: 1 Outline  The Transport Layer  The TCP Protocol (RFC 793, 1122, 1323,...)  TCP Characteristics  TCP Connection setup  TCP Segments  TCP Sequence

50

TCP MSS

• Earlier– 576 bytes for non-local destinations (other network)– 1460 bytes for local destinations (same network)

• Now– 1460 butes and DF bit in IP header set– ICMP message “fragmentation required, but not

permitted” triggers reduction of MSS

• Workaround now– Restet DF bit to “0”

Page 51: 1 Outline  The Transport Layer  The TCP Protocol (RFC 793, 1122, 1323,...)  TCP Characteristics  TCP Connection setup  TCP Segments  TCP Sequence

51

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 52: 1 Outline  The Transport Layer  The TCP Protocol (RFC 793, 1122, 1323,...)  TCP Characteristics  TCP Connection setup  TCP Segments  TCP Sequence

52

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 53: 1 Outline  The Transport Layer  The TCP Protocol (RFC 793, 1122, 1323,...)  TCP Characteristics  TCP Connection setup  TCP Segments  TCP Sequence

53

UDP header

UDP Checksum is optional (all-0 permitted)

Page 54: 1 Outline  The Transport Layer  The TCP Protocol (RFC 793, 1122, 1323,...)  TCP Characteristics  TCP Connection setup  TCP Segments  TCP Sequence

54

User-Datagram Protocol (UDP)

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/videoConnection-less: no time needed to set up connection, each packet (datagram) is independent

Page 55: 1 Outline  The Transport Layer  The TCP Protocol (RFC 793, 1122, 1323,...)  TCP Characteristics  TCP Connection setup  TCP Segments  TCP Sequence

55

Stream ControlTransmission Protocol

SCTP

Page 56: 1 Outline  The Transport Layer  The TCP Protocol (RFC 793, 1122, 1323,...)  TCP Characteristics  TCP Connection setup  TCP Segments  TCP Sequence

56

SCTP open and close

Page 57: 1 Outline  The Transport Layer  The TCP Protocol (RFC 793, 1122, 1323,...)  TCP Characteristics  TCP Connection setup  TCP Segments  TCP Sequence

57

Multiple interfaces

Page 58: 1 Outline  The Transport Layer  The TCP Protocol (RFC 793, 1122, 1323,...)  TCP Characteristics  TCP Connection setup  TCP Segments  TCP Sequence

58

Stream v.s. Message based