CSC 257/457 – Computer Networks

Fall 2017 MW 4:50 pm – 6:05 pm CSB 601 Announcement

Project 3 is out

CSC 457 seminar/survey paper Proposed topic write-up: due on October 28th

Transport Layer 3-2 CHAPTER 3 (TRANSPORT LAYER) Chapter 3 Transport Layer

A note on the use of these Powerpoint slides: We’re making these slides freely available to all (faculty, students, readers). They’re in PowerPoint form so you see the animations; and can add, modify, and delete slides (including this one) and slide content to suit your needs. They obviously represent a lot of work on our part. In return for use, we only ask the following: Computer § If you use these slides (e.g., in a class) that you mention their source (after all, we’d like people to use our book!) Networking: A Top § If you post any slides on a www site, that you note that they are adapted from (or perhaps identical to) our slides, and note our copyright of this Down Approach material. 7th edition Thanks and enjoy! JFK/KWR Jim Kurose, Keith Ross All material copyright 1996-2016 Pearson/Addison Wesley J.F Kurose and K.W. Ross, All Rights Reserved April 2016 Transport Layer 2-4 TCP round trip , timeout

Q: how to set TCP timeout value?

• longer than RTT • but RTT varies • too short: – premature timeout, unnecessary retransmissions • too long: –slow reaction to segment loss

Transport Layer 3-5 TCP round trip time, timeout

Q: how to estimate RTT? • SampleRTT: measured time from segment transmission until ACK receipt – ignore retransmissions • SampleRTT will vary --- we want estimated RTT “smoother” – average several recent measurements, not just current SampleRTT

Transport Layer 3-6 TCP round trip time, timeout

EstimatedRTT = (1- a)*EstimatedRTT + a*SampleRTT § exponential weighted moving average § influence of past sample decreases exponentially fast

§ typical value: a = 0.125RTT: gaia.cs.umass.edu to fantasia.eurecom.fr

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

300

250

RTT (milliseconds) 200 RTT (milliseconds) sampleRTT 150 EstimatedRTT

100 1 8 15 22 29 36 43 50 57 64 71 78 85 92 99 106 time (seconnds) Transporttime (seconds)Layer 3-7 SampleRTT Estimated RTT TCP round trip time, timeout

• timeout interval: EstimatedRTT +“safety margin” – large variation in EstimatedRTT -> larger safety margin

TimeoutInterval = EstimatedRTT + 4*DevRTT

estimated RTT “safety margin”

* Check out the online interactive exercises for examples: http://gaia.cs.umass.edu/kurose_ross/interactive/Transport Layer 3-8 TCP round trip time, timeout

• timeout interval: EstimatedRTT plus “safety margin” – large variation in EstimatedRTT -> larger safety margin • estimate SampleRTT deviation from EstimatedRTT: DevRTT = (1-b)*DevRTT + b*|SampleRTT-EstimatedRTT| (typically, b = 0.25)

TimeoutInterval = EstimatedRTT + 4*DevRTT

estimated RTT “safety margin”

* Check out the online interactive exercises for more examples: http://gaia.cs.umass.edu/kurose_ross/interactive/Transport Layer 3-9 Chapter 3 outline

3.1 transport-layer services 3.5 connection-oriented 3.2 multiplexing and transport: TCP demultiplexing • segment structure 3.3 connectionless transport: • reliable data transfer UDP • flow control • connection management 3.4 principles of reliable data transfer 3.6 principles of congestion control 3.7 TCP congestion control

Transport Layer 3-10 TCP reliable data transfer

• TCP creates rdt service on top of IP’s unreliable service – pipelined segments let’s initially consider – cumulative acks simplified TCP sender: – single retransmission timer – ignore duplicate acks • retransmissions triggered by: – ignore flow control, congestion control – timeout events – duplicate acks

Transport Layer 3-11 TCP sender events: data rcvd from app: • create segment with # • seq # is byte-stream number of first data byte in segment • timer if not already running • think of timer as for oldest unacked segment • expiration interval: TimeOutInterval

Transport Layer 3-12 TCP sender events: timeout: • retransmit segment that caused timeout • restart timer ack rcvd: • if ack acknowledges previously unacked segments • update what is known to be ACKed • start timer if there are still unacked segments

Transport Layer 3-13 TCP sender (simplified)

data received from application above create segment, seq. #: NextSeqNum pass segment to IP (i.e., “send”) NextSeqNum = NextSeqNum + length(data) if (timer currently not running) L start timer NextSeqNum = InitialSeqNum wait SendBase = InitialSeqNum for event timeout retransmit not-yet-acked segment with smallest seq. # start timer ACK received, with ACK field value y if (y > SendBase) { SendBase = y /* SendBase–1: last cumulatively ACKed byte */ if (there are currently not-yet-acked segments) start timer else stop timer } Transport Layer 3-14 TCP: retransmission scenarios

Host A Host B Host A Host B

SendBase=92 Seq=92, 8 bytes of data Seq=92, 8 bytes of data

Seq=100, 20 bytes of data ACK=100 timeout X timeout ACK=100 ACK=120

Seq=92, 8 bytes of data Seq=92, 8 SendBase=100 bytes of data SendBase=120 ACK=100 ACK=120

SendBase=120

lost ACK scenario premature timeout

Transport Layer 3-15 TCP: retransmission scenarios

Host A Host B

Seq=92, 8 bytes of data

Seq=100, 20 bytes of data ACK=100 X timeout ACK=120

Seq=120, 15 bytes of data

cumulative ACK

Transport Layer 3-16 TCP ACK generation [RFC 1122, RFC 2581] event receiver TCP receiver action arrival of in-order segment with delayed ACK. Wait up to 500ms expected seq #. All data up to for next segment. If no next segment, expected seq # already ACKed send ACK arrival of in-order segment with immediately send single cumulative expected seq #. One other ACK, ACKing both in-order segments segment has ACK pending arrival of out-of-order segment immediately send duplicate ACK, higher-than-expect seq. # . indicating seq. # of next expected byte Gap detected arrival of segment that immediate send ACK, provided that partially or completely fills gap segment starts at lower end of gap

Transport Layer 3-17 TCP fast retransmit

if sender receives 3 ACKs for same data (“triple duplicate ACKs”), resend unacked segment with smallest seq(“triple# duplicate ACKs”), § likely that unacked segment lost, so don’t wait for timeout

Transport Layer 3-18 TCP fast retransmit

Host A Host B

Seq=92, 8 bytes of data Seq=100, 20 bytes of data X

ACK=100 ACK=100

timeout ACK=100 ACK=100 Seq=100, 20 bytes of data

fast retransmit after sender

receipt of tripleTransport duplicateLayer ACK 3-19 Chapter 3 outline

3.1 transport-layer services 3.5 connection-oriented 3.2 multiplexing and transport: TCP demultiplexing • segment structure 3.3 connectionless transport: • reliable data transfer UDP • flow control • connection management 3.4 principles of reliable data transfer 3.6 principles of congestion control 3.7 TCP congestion control

Transport Layer 3-20 http://cpham.perso.univ-pau.fr/Paper/TUTORIAL/HOTI- 06/HOTI-tutorial-Part2.pdf TCP flow control

application application may process remove data from application TCP socket buffers …. TCP socket OS receiver buffers … slower than TCP receiver is delivering (sender is sending) TCP code

IP flow control code receiver controls sender, so sender won’t overflow receiver’s buffer by transmitting from sender too much, too fast receiver protocol stack

Transport Layer 3-22 http://cpham.perso.univ-pau.fr/Paper/TUTORIAL/HOTI- 06/HOTI-tutorial-Part2.pdf TCP flow control

to application process

RcvBuffer buffered data

rwnd free buffer space

TCP segment payloads

receiver-side buffering

Transport Layer 3-24 Chapter 3 outline

3.1 transport-layer services 3.5 connection-oriented 3.2 multiplexing and transport: TCP demultiplexing • segment structure 3.3 connectionless transport: • reliable data transfer UDP • flow control • connection management 3.4 principles of reliable data transfer 3.6 principles of congestion control 3.7 TCP congestion control

Transport Layer 3-25 TCP congestion control: additive increase multiplicative decrease § approach: sender increases transmission rate (window size), probing for usable bandwidth, until loss occurs • additive increase: increase cwnd by 1 MSS every RTT until loss detected • multiplicative decrease: cwnd in half after loss

additively increase window size … …. until loss occurs (then cut window in half)

AIMD saw tooth behavior: probing

for bandwidth sender TCP cwnd: congestion window size window congestion

time Transport Layer 3-26 TCP Congestion Control: details

sender sequence number space cwnd TCP sending rate: • roughly: send cwnd bytes, wait RTT for ACKS, then send more bytes last byte last byte ACKed sent, not- sent yet ACKed (“in- flight”) cwnd rate ~ bytes/sec • sender limits transmission: RTT LastByteSent- < cwnd LastByteAcked

• cwnd is dynamic, function of perceived network congestion

Transport Layer 3-27 TCP Slow Start

Host A Host B • when connection begins, increase rate exponentially until first loss event: • initially cwnd = 1 MSS • double cwnd every RTT RTT • done by incrementing cwnd for every ACK received • summary: initial rate is slow but ramps up exponentially fast

time

Transport Layer 3-28 TCP: detecting, reacting to loss

• loss indicated by timeout: • cwnd set to 1 MSS; • window then grows exponentially (as in slow start) to threshold, then grows linearly • loss indicated by 3 duplicate ACKs: TCP Reno • dup ACKs indicate network capable of delivering some segments • cwnd is cut in half window then grows linearly • TCP Tahoe always sets cwnd to 1 (timeout or 3 duplicate acks)

Transport Layer 3-29 TCP: switching from slow start to CA

Q: when should the exponential increase switch to linear? A: when cwnd gets to 1/2 of its value before timeout.

Implementation: • variable ssthresh • on loss event, ssthresh is set to 1/2 of cwnd just before loss event

* Check out the online interactive exercises for more examples: http://gaia.cs.umass.edu/kurose_ross/interactive/Transport Layer 3-30 Summary: TCP Congestion Control

New New new ACK ACK! duplicate ACK ACK! cwnd = cwnd + MSS . (MSS/cwnd) dupACKcount++ new ACK dupACKcount = 0 cwnd = cwnd+MSS transmit new segment(s), as allowed dupACKcount = 0 L transmit new segment(s), as allowed cwnd = 1 MSS ssthresh = 64 KB cwnd > ssthresh dupACKcount = 0 slow L congestion

start timeout avoidance ssthresh = cwnd/2 cwnd = 1 MSS duplicate ACK timeout dupACKcount = 0 dupACKcount++ ssthresh = cwnd/2 retransmit missing segment cwnd = 1 MSS dupACKcount = 0 retransmit missing segment timeout New ACK! ssthresh = cwnd/2 cwnd = 1 New ACK dupACKcount = 0 cwnd = ssthresh dupACKcount == 3 dupACKcount == 3 retransmit missing segment dupACKcount = 0 ssthresh= cwnd/2 ssthresh= cwnd/2 cwnd = ssthresh + 3 cwnd = ssthresh + 3 retransmit missing segment retransmit missing segment fast recovery

duplicate ACK cwnd = cwnd + MSS transmit new segment(s), as allowed Transport Layer 3-31 TCP throughput

• avg. TCP thruput as function of window size, RTT? – ignore slow start, assume always data to send

• W: window size (measured in bytes) where loss occurs – avg. window size (# in-flight bytes) is ¾ W 3 W avg TCP thruput = bytes/sec 4 RTT – avg. throughput is 3/4W per RTT

W

W/2

Transport Layer 3-32 TCP Futures: TCP over “long, fat pipes”

• example: 1500 byte segments, 100ms RTT, want 10 Gbps throughput • requires W = 83,333 in-flight segments • throughput in terms of segment loss probability, L [Mathis 1997]: 1.22 . TCP throughput = MSS RTT L

➜ to achieve 10 Gbps throughput, need a loss rate of L = 2·10-10 – a very small loss rate! • new versions of TCP for high-speed (RFC 3649)

Transport Layer 3-33 TCP Fairness fairness goal: if K TCP sessions share same bottleneck of bandwidth R, each should have average rate of R/K

TCP connection 1

bottleneck router capacity R TCP connection 2

Transport Layer 3-34 Why is TCP fair? two competing sessions: • additive increase gives slope of 1, as throughout increases • multiplicative decrease decreases throughput proportionally R equal bandwidth share

loss: decrease window by of 2 congestion avoidance: additive increase loss: decrease window by factor of 2 congestion avoidance: additive increase

Connection 1 throughput R

Transport Layer 3-35 Fairness (more)

Fairness and UDP Fairness, parallel TCP connections • multimedia apps often do • application can open not use TCP multiple parallel connections between two hosts • do not want rate throttled by congestion control • web browsers do this • instead use UDP: • e.g., link of rate R with 9 existing connections: • send audio/video at constant rate, tolerate packet loss • new app asks for 1 TCP, gets rate R/10 • new app asks for 11 TCPs, gets R/2

Transport Layer 3-36 Explicit Congestion Notification (ECN) network-assisted congestion control: • two bits in IP header (ToS field) marked by network router to indicate congestion • congestion indication carried to receiving host • receiver (seeing congestion indication in IP datagram) ) sets ECE bit on receiver-to-sender ACK segment to notify sender of congestion

TCP ACK segment source destination application application ECE=1 transport transport network network link link physical physical

ECN=00 ECN=11

IP datagram Transport Layer 3-37 Chapter 3 outline

3.1 transport-layer services 3.5 connection-oriented 3.2 multiplexing and transport: TCP demultiplexing • segment structure 3.3 connectionless transport: • reliable data transfer UDP • flow control • connection management 3.4 principles of reliable data transfer 3.6 principles of congestion control 3.7 TCP congestion control

Transport Layer 3-38 TCP 3-way handshake: FSM

closed

Socket connectionSocket = welcomeSocket.accept(); L Socket clientSocket = SYN(x) newSocket("hostname","port number"); SYNACK(seq=y,ACKnum=x+1) create new socket for SYN(seq=x) communication back to client listen

SYN SYN rcvd sent

SYNACK(seq=y,ACKnum=x+1) ESTAB ACK(ACKnum=y+1) ACK(ACKnum=y+1) L

Transport Layer 3-39 TCP: closing a connection

• client, server each close their side of connection • send TCP segment with FIN bit = 1 • respond to received FIN with ACK • on receiving FIN, ACK can be combined with own FIN • simultaneous FIN exchanges can be handled

Transport Layer 3-40 TCP: closing a connection

client state server state ESTAB ESTAB clientSocket.close() FIN_WAIT_1 can no longer FINbit=1, seq=x send but can receive data CLOSE_WAIT ACKbit=1; ACKnum=x+1 can still FIN_WAIT_2 wait for server send data close

LAST_ACK FINbit=1, seq=y TIMED_WAIT can no longer send data ACKbit=1; ACKnum=y+1 timed wait for 2*max CLOSED segment lifetime

CLOSED

Transport Layer 3-41 Acknowledgement

• Most of the slides in this presentation are taken from the slides provided by the authors of the textbook.

• Thanks to YouTube for providing many useful videos.

§ If you use these slides (e.g., in a class) that you mention their source (after all, we’d like people to use our book!) § If you post any slides on a www site, that you note that they are adapted from (or perhaps identical to) our slides, and note our copyright of this material.

Thanks and enjoy! JFK/KWR

All material copyright 1996-2016 J.F Kurose and K.W. Ross, All Rights Reserved