transport protocols reading: sections 5.1 and 5.2

37
Transport Protocols Reading: Sections 5.1 and 5.2 COS 461: Computer Networks Spring 2011 Mike Freedman http://www.cs.princeton.edu/courses/archive/ spring11/cos461/ 1

Upload: ashanti

Post on 05-Jan-2016

19 views

Category:

Documents


2 download

DESCRIPTION

Transport Protocols Reading: Sections 5.1 and 5.2. COS 461: Computer Networks Spring 2011 Mike Freedman http://www.cs.princeton.edu/courses/archive/spring11/cos461/. Goals for Today’s Lecture. Principles underlying transport-layer services (De)multiplexing Detecting corruption - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: Transport Protocols Reading: Sections 5.1 and 5.2

Transport ProtocolsReading: Sections 5.1 and 5.2

COS 461: Computer NetworksSpring 2011

Mike Freedman

http://www.cs.princeton.edu/courses/archive/spring11/cos461/

1

Page 2: Transport Protocols Reading: Sections 5.1 and 5.2

Goals for Today’s Lecture• Principles underlying transport-layer services

– (De)multiplexing– Detecting corruption– Reliable delivery– Flow control

• Transport-layer protocols in the Internet– User Datagram Protocol (UDP)

• Simple (unreliable) message delivery– Transmission Control Protocol (TCP)

• Reliable bidirectional stream of bytes

2

Page 3: Transport Protocols Reading: Sections 5.1 and 5.2

Recall the Internet layering model3

HTTP

TCP

Ethernetinterface

HTTP

TCP

IP

Ethernetinterface

Ethernetinterface

Ethernetinterface

SONETinterface

SONETinterface

host host

router router

HTTP message

TCP segment

IP packet IP packetIP packet

Page 4: Transport Protocols Reading: Sections 5.1 and 5.2

Two Basic Transport Features• Demultiplexing: port numbers

• Error detection: checksums

4

Web server(port 80)

Client host5.6.7.8

Server host 1.2.3.4

Echo server(port 7)

Service request to1.2.3.4:80

OSClient

IP payload

detect corruption

Request from5.6.7.8:3456 Demux table (“5 tuple”) Socket

<*, *, 1.2.3.4, 80, TCP> 5

<5.6.7.8, 3456, 1.2.3.4, 80, TCP> 6

Page 5: Transport Protocols Reading: Sections 5.1 and 5.2

User Datagram Protocol (UDP)• Datagram messaging service

– Demultiplexing of messages: port numbers– Detecting corrupted messages: checksum

• Lightweight communication between processes– Send messages to and receive them from a socket– Avoid overhead and delays of ordered, reliable delivery

5

SRC port DST port

checksum

length

DATA

Page 6: Transport Protocols Reading: Sections 5.1 and 5.2

Why Would Anyone Use UDP?• Fine control over what data is sent and when

– As soon as app process writes into socket– … UDP will package data and send packet

• No delay for connection establishment – UDP blasts away without any formal preliminaries– … avoids introducing unnecessary delays

• No connection state (no buffers, sequence #’s, etc.)– Can scale to more active clients at once

• Small packet header overhead (header only 8B long)

6

Page 7: Transport Protocols Reading: Sections 5.1 and 5.2

Popular Applications That Use UDP

• Simple query protocols like DNS– Overhead of connection establishment is overkill– Easier to have the application retransmit if needed

• Multimedia streaming (VoIP, video conferencing, …)– Retransmitting lost/corrupted packets is not worthwhile– By time packet is retransmitted, it’s too late

”www.cnn.com?”

“12.3.4.15”

7

Page 8: Transport Protocols Reading: Sections 5.1 and 5.2

Transmission Control Protocol (TCP)• Stream-of-bytes service: Send/recv streams, not msgs

• Reliable, in-order delivery– Checksums to detect corrupted data– Sequence numbers to detect losses and reorder data– Acknowledgments & retransmissions for reliable delivery

• Connection oriented: Explicit set-up and tear-down

• Flow control: Prevent overload of receiver’s buffer

• Congestion control (next class!): Adapt for greater good

8

Page 9: Transport Protocols Reading: Sections 5.1 and 5.2

Breaking a Stream of Bytes into TCP Segments

9

Page 10: Transport Protocols Reading: Sections 5.1 and 5.2

TCP “Stream of Bytes” Service10

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 11: Transport Protocols Reading: Sections 5.1 and 5.2

… Emulated Using TCP “Segments”11

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 (Max Segment

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

Page 12: Transport Protocols Reading: Sections 5.1 and 5.2

Sequence Number13

Host A

Host B

TCP Data

TCP Data

ISN (initial sequence number)

Sequence number = 1st

byte

By te 8 1

• Why not ISN of 0?

• Traditionally: Clock-based- What if port realloc’d and

old packet in flight?- ISN based on clock, wraps

around every 4.55 hr

• Now: Randomized- Hard to guess, thus harder

to “hijack” TCP connection

• Why not ISN of 0?

• Traditionally: Clock-based- What if port realloc’d and

old packet in flight?- ISN based on clock, wraps

around every 4.55 hr

• Now: Randomized- Hard to guess, thus harder

to “hijack” TCP connection

Page 13: Transport Protocols Reading: Sections 5.1 and 5.2

Reliable Delivery on a Lossy Channel With Bit Errors

14

Page 14: Transport Protocols Reading: Sections 5.1 and 5.2

An Analogy: Talking on a Cell Phone• Alice and Bob talking on cell phones

– If Bob couldn’t understand? Ask Alice to repeat– If Bob hasn’t heard for a while?

• Acknowledgments from receiver– Positive: “okay” or “uh huh” or “ACK”– Negative: “please repeat that” or “NACK”

• Timeout by the sender (“stop and wait”)– Don’t wait indefinitely w/o a response, whether ACK or NACK

• Retransmission by the sender– After receiving “NACK” from receiver– After receiving no feedback from receiver

15

Page 15: Transport Protocols Reading: Sections 5.1 and 5.2

Challenges of Reliable Data Transfer• Over a perfectly reliable channel

– All data arrives in order, just as sent. Simple.

• Over a channel with bit errors– All data arrives in order, but some bits corrupted– Receiver detects errors and says “please repeat that”– Sender retransmits corrupted data

• Over a lossy channel with bit errors– Some data is missing, and some bits are corrupted– Receiver detects errors but cannot always detect loss– Sender must wait for acknowledgment (“ACK” or “OK”)– … and retransmit data after some time if no ACK arrives

16

Page 16: Transport Protocols Reading: Sections 5.1 and 5.2

TCP Support for Reliable Delivery

• Detect bit errors: checksum– Used to detect corrupted data at the receiver– …leading the receiver to drop the packet

• Detect missing data: sequence number– Used to detect a gap in the stream of bytes– ... and for putting the data back in order

• Recover from lost data: retransmission– Sender retransmits lost or corrupted data– Two main ways to detect lost packets

17

Page 17: Transport Protocols Reading: Sections 5.1 and 5.2

TCP Acknowledgments18

Host A

Host B

TCP Data

TCP Data

TCP HDR

TCP HDR

ISN (initial sequence number)

Sequence number = 1st

byteACK sequence # = next expected

byte

Page 18: Transport Protocols Reading: Sections 5.1 and 5.2

Automatic Repeat reQuest (ARQ)19

Time

Packet

ACKTim

eou

t

• Automatic Repeat reQuest– Receiver sends ACK when it

receives packet

– Sender waits for ACK.

– If ACK not received within some timeout period, resend packet

• Simplest: “stop and wait”– One packet at a time…

Sender Receiver

Page 19: Transport Protocols Reading: Sections 5.1 and 5.2

Reasons for Retransmission20

Packet

ACK

Tim

eou

t

Packet

ACK

Tim

eou

t

Packet

Tim

eou

t

Packet

ACK

Tim

eou

t

Packet

ACK

Tim

eou

tPacket

ACK

Tim

eou

t

ACK lostDUPLICATE

PACKET

Packet lost Early timeoutDUPLICATEPACKETS

Page 20: Transport Protocols Reading: Sections 5.1 and 5.2

How Long Should Sender Wait?• Too short? Wasted retransmissions• Too long? Excessive delays when packet lost

• TCP sets timeout as function of Round Trip Time– ACK should arrive after RTT + fudge factor for queuing

• How does sender know RTT?– Can estimate RTT by watching the ACKs– Smooth estimate: Exponentially-weighted moving avg (EWMA)

• EstimatedRTT = a * EstimatedRTT + (1–a) * SampleRTT– Compute timeout: TimeOut = 2 * EstimatedRTT

21

Page 21: Transport Protocols Reading: Sections 5.1 and 5.2

Example RTT Estimation22

RTT: gaia.cs.umass.edu to fantasia.eurecom.fr

100

150

200

250

300

350

1 8 15 22 29 36 43 50 57 64 71 78 85 92 99 106

time (seconnds)

RTT

(mill

isec

onds

)

SampleRTT Estimated RTT

Page 22: Transport Protocols Reading: Sections 5.1 and 5.2

A Flaw in This Approach• ACK acknowledges receipt to data, not transmission

• Consider a retransmission of a lost packet– If assume ACK with 1st transmission, SampleRTT too large

• Consider a duplicate packet – If assume ACK with 2nd transmission, SampleRTT too small

• Simple solution in the Karn/Partridge algorithm– Only collect samples for segments sent one single time

23

Page 23: Transport Protocols Reading: Sections 5.1 and 5.2

Increasing TCP throughput• Problem: Stop-and-wait + timeouts are inefficient

– Only one TCP segment “in flight” at time

• Solution: Send multiple packets at once

• Problem: How many w/o overwhelming receiver?

• Solution: Determine “window size” dynamically

Flow Control via TCP Sliding Window

24

Page 24: Transport Protocols Reading: Sections 5.1 and 5.2

Sliding Window• Allow a larger amount of data “in flight”

– Sender can get ahead of receiver, though not too far

26

Sending process Receiving process

Last byte ACKed

Last byte sent

TCP TCP

Next byte expected

Last byte written Last byte read

Last byte received

Page 25: Transport Protocols Reading: Sections 5.1 and 5.2

Receiver Buffering• Window size

– Amount that can be sent w/o ACK, because receiver can buffer

• Receiver advertises window to receiver– Tells amount of free space left (in bytes)– Sender agrees not to exceed this amount

27

Window Size

OutstandingUn-ack’d data

Data OK to send

Data not OK to send yet

Data ACK’d

Sender

Page 26: Transport Protocols Reading: Sections 5.1 and 5.2

Solution to timeout inefficiency:Fast Retransmission

• Better solution possible under sliding window– Although packet n might have been lost– … packets n+1, n+2, and so on might get through

• Idea: “Duplicate ACKs” suggest loss– ACK says receiver is awaiting nth packet– Repeated ACKs suggest later packets have arrived– Sender use “duplicate ACKs” as early hint of loss

• Fast retransmission– Sender retransmits data after the triple duplicate ACK

28

Page 27: Transport Protocols Reading: Sections 5.1 and 5.2

Effectiveness of Fast Retransmit• When does Fast Retransmit work best?

– Long transfers: High likelihood of many pkts in flight– Large window: High likelihood of many packets in flight– Low loss burstiness: Higher likelihood that later pkts arrive

• Implications for Web traffic– Most Web objects are short (e.g., 10 packets)– So, often aren’t many packets in flight– … making fast retransmit less likely to “kick in”– … another reason for persistent connections!

29

Page 28: Transport Protocols Reading: Sections 5.1 and 5.2

Starting and Ending a Connection:TCP Handshakes

30

Page 29: Transport Protocols Reading: Sections 5.1 and 5.2

Establishing a TCP Connection

• Three-way handshake to establish connection– Host A sends a SYNchronize (open) to the host B– Host B returns a SYN ACKnowledgment (SYN ACK)– Host A sends an ACK to acknowledge the SYN ACK

31

SYN

SYN ACK

ACKData

A B

Data

Each host tells its ISN to other hostEach host tells its ISN to other host

Page 30: Transport Protocols Reading: Sections 5.1 and 5.2

TCP Header32

Source port Destination port

Sequence number

Acknowledgment

Advertised windowHdrLen Flags0

Checksum Urgent pointer

Options (variable)

Data

Flags: SYNFINRSTPSHURGACK

Page 31: Transport Protocols Reading: Sections 5.1 and 5.2

Step 1: A’s Initial SYN Packet33

A’s Initial Sequence Number

Acknowledgment

Advertised window20 Flags0

Checksum Urgent pointer

Options (variable)

A tells B it wants to open a connection…

Flags: SYNFINRSTPSHURGACK

B’s port A’s port

Page 32: Transport Protocols Reading: Sections 5.1 and 5.2

Step 2: B’s SYN-ACK Packet34

B’s port A’s port

B’s Initial Sequence Number

A’s ISN plus 1

Advertised window20 Flags0

Checksum Urgent pointer

Options (variable)

B tells A it accepts, and is ready to hear the next byte…

… upon receiving this packet, A can start sending data

Flags: SYNFINRSTPSHURGACK

Page 33: Transport Protocols Reading: Sections 5.1 and 5.2

Step 3: A’s ACK of the SYN-ACK35

B’s ISN plus 1

Advertised window20 Flags0

Checksum Urgent pointer

Options (variable)

A tells B it is okay to start sending…

Sequence numberFlags: SYN

FINRSTPSHURGACK

B’s port A’s port

… upon receiving this packet, B can start sending data

Page 34: Transport Protocols Reading: Sections 5.1 and 5.2

What if the SYN Packet Gets Lost?• Suppose SYN packet gets lost

– Packet lost inside network, or– Server rejects packet (e.g., listen queue is full)

• Eventually, no SYN-ACK arrives– Sender sets timer and waits, retransmitting if needed

• How should TCP sender set timer?– Sender has no estimate of RTT– Some TCP stacks use default of 3 or 6 seconds

• Why reload button in your browser is useful: Opens new connection and “retransmits” SYN in < 3-6 sec

36

Page 35: Transport Protocols Reading: Sections 5.1 and 5.2

Tearing Down the Connection37

SYN

SYN ACK

ACK

Data

A B

Data

ACKACK

FIN

ACK

ACK

FIN

Setup

DataTransfer

Teardown

• Closing a connection– Process done writing: invokes close()– Once TCP sends all outstanding byte,

TCP sends a FINish message

• Receiving a FINish– Process reading data from socket– Eventually, read attempt returns EOF

• Tear-down is two-way– FIN to close, but receive remaining– Other host ACKs the FIN– Rest (RST) to close and not receive

remaining: error condition

Page 36: Transport Protocols Reading: Sections 5.1 and 5.2

38

Page 37: Transport Protocols Reading: Sections 5.1 and 5.2

Conclusions• Transport protocols

– Multiplexing and demultiplexing– Checksum-based error detection– Sequence numbers– Retransmission– Window-based flow control

• Next lecture– Congestion control

39