toc: transport protocols

36
TOC : Transport Protocols Why? Overview UDP TCP Summary TOC Transport

Upload: others

Post on 22-May-2022

4 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: TOC: Transport Protocols

TOC: Transport Protocols� Why?� Overview� UDP� TCP� Summary

TOC – Transport

Page 2: TOC: Transport Protocols

Why?

� IP provides a weak, but efficient service model (best-effort)�Packets can be delayed, dropped, reordered, duplicated�Packets have limited size (why?)

� IP packets are addressed to a host�How to decide which application gets which packets?

� How should hosts send into the network?� Too fast is bad; too slow is not efficient

TOC – Transport – Why?

Page 3: TOC: Transport Protocols

Overview

� Basic Features� Illustration� Ports� UDP� TCP� Headers

TOC – Transport – Overview

Page 4: TOC: Transport Protocols

Basic Features� Can provide more reliability, in order delivery, at most

once delivery� Supports messages of arbitrary length� Provide a way to decide which packets go to which

applications (multiplexing/demultiplexing)� Govern when hosts should send data

TOC – Transport – Overview – Basic Features

Page 5: TOC: Transport Protocols

Illustration

IP

Transport

A B C

[A | B | p1 | p2 | …]

p1 p2 p1 p2 p3 p1 p2

portsApplication

HTTP DNSRA

UDP: Not reliableTCP: Ordered, reliable, well-paced

TOC – Transport – Overview – Illustration

Page 6: TOC: Transport Protocols

Ports� Need to decide which application gets which packets� Solution: map each socket to a port� Client must know server’s port� Separate 16-bit port address space for UDP and TCP

� (src IP, src port, dst IP, dst port) uniquely identifies TCP connection

� Well known ports (0-1023): everyone agrees which services run on these ports� e.g., ssh:22, http:80� on UNIX, must be root to gain access to these ports (why?)

� ephemeral ports(most 1024-65535): given to clients� e.g. chatclient gets one of these

TOC – Transport – Overview – Ports

Page 7: TOC: Transport Protocols

UDP

� User Datagram Protocol� minimalist transport protocol� same best-effort service model as IP� messages of up to 64KB� provides multiplexing/demultiplexing to IP� does not provide congestion control� advantage over TCP: does not increase end-to-end

delay over IP� application example: video/audio streaming

TOC – Transport – Overview – UDP

Page 8: TOC: Transport Protocols

TCP

� Transmission Control Protocol� reliable, in-order, and at most once delivery� messages can be of arbitrary length� provides multiplexing/demultiplexing to IP� provides congestion control and avoidance� increases end-to-end delay over IP� e.g., file transfer, chat

TOC – Transport – Overview – TCP

Page 9: TOC: Transport Protocols

Headers

� IP header � used for IP routing, fragmentation, error detection… (we study that when we explore IP)

� UDP header � used for multiplexing/demultiplexing, error detection� TCP header � used for multiplexing/demultiplexing, flow and congestion

control

IP

TCP UDPdataTCP/UDP

dataTCP/UDPIP

Application

Sender

data

IP

TCP UDP

Application

Receiver

dataTCP/UDP

dataTCP/UDPIP

data

TOC – Transport – Overview – Headers

Page 10: TOC: Transport Protocols

UDP� Service:

� Send datagram from (IPa, Port 1) to (IPb, Port 2)� Service is unreliable, but error detection possible

� Header:

Source port Destination port0 16 31

UDP length UDP checksumPayload (variable)

•UDP length is UDP packet length (including UDP header and payload, but not IP header)•Optional UDP checksum is over UDP packet

� Why have UDP checksum in addition to IP checksum?� Why not have just the UDP checksum?� Why is the UDP checksum optional?

TOC – Transport – UDP

Page 11: TOC: Transport Protocols

TCP� Service� Steps� 3-Way Handshake� State Diagram: 1� State Diagram: 2� Header� Sliding Window Protocol

TOC – Transport – TCP

Page 12: TOC: Transport Protocols

Service� Start a connection

� Reliable byte stream delivery

from (IPa, TCP Port 1) to (IPb, TCP Port 2)

� Indication if connection fails: Reset

� Terminate connection

TOC – Transport – TCP – Service

Page 13: TOC: Transport Protocols

SYN k

SYN n; ACK k+1

DATA k+1; ACK n+1

ACK k+n+1data exchange

FIN

FIN ACK

½ close

FIN

FIN ACK½ close

Steps

3-way handshake

TOC – Transport – TCP – Steps

Page 14: TOC: Transport Protocols

3WH

� Description� Rationale

TOC – Transport – TCP – 3WH

Page 15: TOC: Transport Protocols

DescriptionGoal: agree on a set of parameters: the start

sequence number for each side�Starting sequence numbers are random.

Client (initiator) Server

SYN, SeqNum = x

SYN and ACK, SeqNum = y and Ack = x + 1

ACK, Ack = y + 1

ActiveOpen

PassiveOpen

connect() listen()

accept()

allocatebuffer space

TOC – Transport – TCP – 3WH - Description

Page 16: TOC: Transport Protocols

Rationale

� Three-way handshake adds 1 RTT delay � Why?

�congestion control: SYN (40 byte) acts as cheap probe

�Protects against delayed packets from other connection (would confuse receiver)

TOC – Transport – TCP – 3WH - Rationale

Page 17: TOC: Transport Protocols

State Diagram 1

A

B

SYN

SYN + ACK

Data + ACK

ACK…

FIN

FIN.ack FIN FIN.ack

Listen

SYN received

Established

Close Wait

Last Ack

Closed

Closed

SYN sent

EstablishedFIN Wait-1

FIN Wait-2

Timed WaitClosed

(1)

(1): A waits in case B retransmits FIN and A must ack again

TOC – Transport – TCP – State Diagram 1

Page 18: TOC: Transport Protocols

State Diagram 2

TOC – Transport – TCP – State Diagram 2

Page 19: TOC: Transport Protocols

Header

� Sequence number, acknowledgement, and advertised window – used by sliding-window based flow control

� Flags:� SYN, FIN – establishing/terminating a TCP connection� ACK – set when Acknowledgement field is valid� URG – urgent data; Urgent Pointer says where non-urgent data starts� PUSH – don’t wait to fill segment� RESET – abort connection

Source port Destination port

Options (variable)

Sequence numberAcknowledgement

Advertised windowChecksum Urgent pointer

FlagsHdrLen

0 4 10 16 31

Payload (variable)

TOC – Transport – TCP – Header

Page 20: TOC: Transport Protocols

Sliding Window Protocol

� Objectives� Stop & Wait� Go-Back-n

TOC – Transport – TCP – SWP

Page 21: TOC: Transport Protocols

Objectives

� Retransmit missing packets� Numbering of packets and ACKs

� Do this efficiently� Keep transmitting whenever possible� Detect missing ACKs and retransmit quickly

TOC – Transport – TCP – SWP – Objectives

Page 22: TOC: Transport Protocols

Stop & Wait

ACK

DATA

Time

Sender

Receiver

RTT

� Send; wait for ack� If timeout, retransmit; else repeat

Inefficient if

TRANS << RTT

Inefficient if

TRANS << RTT

TRANS

TOC – Transport – TCP – SWP – S&W

Page 23: TOC: Transport Protocols

Go-Back-n (GBN)

� Definition� Illustration without errors� Illustration with errors� Sliding window rules� Sliding window example� Observations� Round-Trip Timing� The question of ACKs

TOC – Transport – TCP – SWP – GBN

Page 24: TOC: Transport Protocols

Definition

� Transmit up to n unacknowledged packets� If timeout for ACK(k), retransmit k, k+1, …

TOC – Transport – TCP – SWP – GBN – Definition

Page 25: TOC: Transport Protocols

Example without errors

Time

n = 9 packets in one RTT instead of 1

� Fully efficient

TOC – Transport – TCP – SWP – GBN – No Errors

Page 26: TOC: Transport Protocols

Example with errors

Time

Window size = 3 packetsWindow size = 3 packets

Sender Receiver

12

3

456

7

Timeout

Packet 5

567

TOC – Transport – TCP – SWP – GBN –Errors

Page 27: TOC: Transport Protocols

Sliding Window Rules� window = collection of adjacent sequence numbers� the size of the collection is the window size

� Let A be the last ack’d packet of sender without gap; then window of sender = {A+1, A+2, …, A+n}

� Sender can send packets in its window

� Let B be the last received packet without gap by receiver, then window of receiver = {B+1,…, B+n}

� Receiver can accept out of sequence, if in window

TOC – Transport – TCP – SWP – GBN –Rules

Page 28: TOC: Transport Protocols

Sliding Window Example

1

2

3

1 2 3 4 5 6 7 8 1 2 3 4 5 6 7 8

4

56

5

67

Last ACKed (without gap) Last received (without gap)

7

TOC – Transport – TCP – SWP – GBN –SW Ex.

Page 29: TOC: Transport Protocols

Observations

� With sliding windows, it is possible to fully utilize a link, provided the window size is large enough. Throughput is ~ (w/RTT); Stop & Wait is like w = 1.

� Sender has to buffer all unacknowledged packets, because they may require retransmission

� Receiver may be able to accept out-of-order packets, but only up to its buffer limits

TOC – Transport – TCP – SWP – GBN – Observations

Page 30: TOC: Transport Protocols

Timing

� Objective� Illustration� Adaptation� Algorithm

TOC – Transport – TCP – SWP – GBN –Timing

Page 31: TOC: Transport Protocols

Objective

� So, the sender needs to set timers in order to know when to retransmit a packet the may have been lost

� How long to set the timer for?� Too short: may retransmit before data or ACK

has arrived, creating duplicates� Too long: if a packet is lost, will take a long time

to recover (inefficient)

TOC – Transport – TCP – SWP – GBN – Timing – Objective

Page 32: TOC: Transport Protocols

Illustrations

1

1

Timer too long

1

1

Timer too short

1

RTT

TOC – Transport – TCP – SWP – GBN – Timing – Illustrations

Page 33: TOC: Transport Protocols

Adaptation

� The amount of time the sender should wait is about the round-trip time (RTT) between the sender and receiver

� For link-layer networks (LANs), this value is essentially known

� For multi-hop WANS, rarely known� Must work in both environments, so protocol should

adapt to the path behavior� Measure successive ack delays T(n)

Set timeout = average + 4 deviations

TOC – Transport – TCP – SWP – GBN – Timing – Adaptation

Page 34: TOC: Transport Protocols

Algorithm� Use exponential averaging:

A(n) = bA(n- 1) + (1 – b)T(n)

D(n) = bD(n-1) + (1 – b)|T(n) – A(n)|

Timeout(n) = A(n) +4D(n)

Notes: 1. Measure T(n) only for original transmissions2. Double Timeout after timeout …

Justification: timeout indicates likely congestion;Further retransmissions would make things worse

3. Reset Timeout = A + 4D for new packet and when receive ACK

TOC – Transport – TCP – SWP – GBN – Timing – Algorithm

Page 35: TOC: Transport Protocols

The question of ACKs

� What exactly should the receiver ACK?� Some possibilities:

� ACK every packet, giving its sequence number� use cumulative ACK, where an ACK for number n implies

ACKS for all k < n� use negative ACKs (NACKs), indicating which packet did

not arrive� use selective ACKs (SACKs), indicating those that did

arrive, even if not in order

TOC – Transport – TCP – SWP – GBN – Timing – ACKs

Page 36: TOC: Transport Protocols

Summary

� UDP: Multiplex, detect errors� TCP: Reliable Byte Stream

� 3WH; Exchange; Close� Reliable transmissions: ACKs…� S&W not efficient � Go-Back-n� What to ACK? (cumulative, …)� Timer Value: based on measured RTT

� Next: Congestion and Flow Control

TOC – Transport – Summary