0% found this document useful (0 votes)
39 views

Transport Layer: Computer Networking: A Top Down Approach

Uploaded by

Lâm Quỳnh
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
39 views

Transport Layer: Computer Networking: A Top Down Approach

Uploaded by

Lâm Quỳnh
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 40

Chapter 3

Transport Layer
Adapted by [email protected]
27 August 2019

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.

Computer
They obviously represent a lot of work on our part. In return for use, we only
ask the following:

 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-1
Chapter 3 outline
3.1 transport-layer 3.5 connection-oriented
services transport: TCP
3.2 multiplexing and • segment structure
demultiplexing • reliable data transfer
3.3 connectionless • flow control
transport: UDP • connection management
3.4 principles of reliable 3.6 principles of congestion
data transfer control
3.7 TCP congestion control

Transport Layer 3-2


TCP: Overview RFCs: 793,1122,1323, 2018, 2581

 point-to-point:  full duplex data:


• one sender, one receiver • bi-directional data flow
 reliable, in-order byte in same connection
steam: • MSS: maximum segment
size
• no “message
boundaries”  connection-oriented:
 pipelined: • handshaking (exchange
of control msgs) inits
• TCP congestion and sender, receiver state
flow control set window before data exchange
size
 flow controlled:
• sender will not
overwhelm receiver
Transport Layer 3-3
TCP segment structure
32 bits

source port # dest port #


sequence number
ACK: ACK # header length
valid acknowledgement number 20 bytes
head not
len used
UAP R S F receive window
checksum Urg data pointer

RST, SYN, FIN: options (variable length) rwnd


connection estab
(setup, teardown
commands)
application
Internet data
checksum (variable length)
(as in UDP)

Transport Layer 3-4


TCP: seq. ACKs - one way: AB
Host A has 8 bytes to send Host B has 0 bytes to send
92 93 94 95 96 97 98 99 100

Host B
Host A
Send Seq
SendBase=92 SendBase=50

Seq=92, 8 bytes of data,


ACK 50

Seq=50, 0 byte of data,


ACK=100
ACKed=100
SendBase=100 Seq=100, 20 bytes of data,
ACK 50

Seq=?, 0 byte of data,


ACK=?

SendBase=?
Transport Layer 3-5
TCP: seq. Nr, ACK - bidirectional
Host A has 8 bytes to send Host B has 5 bytes to send
92 93 94 95 96 97 98 99 100

Host B
Host A
Send Seq
SendBase=92 SendBase=50

50 51 52 53 54 55
Seq=92, 8 bytes of data,
ACK 50
Send Seq

Seq=50, 5 byte of data,


ACK=100
ACKed=100
SendBase=100 Seq=100, 20 bytes of data,
ACK 55 ACKed=55
SendBase=55

Transport Layer 3-6


TCP seq. numbers, ACKs
Client send ‘test’ (5Bytes) to Server, Server echo ‘TEST’ back

Client Server
SendBase=42 SendBase=79

Client
types‘test’
Seq=42,
? ACK=79,
? data = ‘test’
Server ACKs
receipt of‘test’;
Echoes back ‘TEST’
Seq=79, ? data = ‘TEST’
? ACK=47,

Client ACKs receipt


of echoed‘TEST’
? ACK=84
Seq=47, ?

simple TCP client / server Python Socket Programming

Transport Layer 3-7


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

Transport Layer 3-8


TCP flow control
application
application may process
retrieve data from application
TCP socket buffers ….
TCP socket OS
… slower than
receiver buffers
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-9


TCP flow control
 receiver “advertises” free
buffer space by including to application process
rwnd value in TCP header
of receiver-to-sender
segments RcvBuffer buffered data
• RcvBuffer size set via
socket options (typical default rwnd free buffer space
is 4096 bytes)
• many operating systems
autoadjust RcvBuffer TCP segment payloads
 sender limits amount of
unacked (“in-flight”) data to receiver-side buffering
receiver’s rwnd value
 guarantees receive buffer
will not overflow
Transport Layer 3-10
TCP window flow control
Host A Host B outgoing segment from sender
source port # dest port #
sequence number
SendBase=0000 acknowledgement number
MSS=1024 rwnd
Window=5120 Seq=0000, segment=0-1023 checksum urg pointer
Seq=1024
window size
Seq=2048 N
Seq=3072
Seq=4096

ACKed=1024 sender sequence number space


ACKed=2048
Seq=5120
Seq=6144 sent sent, not- usable not
ACKed yet ACKed but not usable
Seq=?
(“in- yet sent
Seq=? flight”)
incoming segment to sender
source port # dest port #
sequence number
acknowledgement number
A rwnd
fast retransmit after sender checksum urg pointer

receipt of triple duplicate ACK


Transport Layer 3-11
TCP window flow control
Host A Host B outgoing segment from sender
source port # dest port #
sequence number
SendBase=50000 acknowledgement number
MSS=1024 rwnd
Window=5120 Seq=0000, segment=0-1023 checksum urg pointer
Seq=1024
window size
Seq=2048 N
Seq=3072
Seq=4096

ACKed=1024 sender sequence number space


ACKed=2048
Seq=5120
Seq=6144 sent sent, not- not
ACKed yet ACKed usable
Seq=?
(“in-
Seq=? flight”)
incoming segment to send
source port # dest port #
sequence number
acknowledgement number
A rwnd
fast retransmit after sender checksum urg pointer

receipt of triple duplicate ACK


Transport Layer 3-12
TCP seq. numbers, ACKs
outgoing segment from sender
sequence numbers: source port # dest port #
sequence number
• byte stream “number” of acknowledgement number

first byte in segment’s rwnd

data
checksum urg pointer

window size
acknowledgements: N

• seq # of next byte


expected from other side sender sequence number space
• cumulative ACK
sent sent, not- usable not
Q: how receiver handles ACKed yet ACKed but not usable
out-of-order segments (“in-
flight”)
yet sent
incoming segment to sender
• A: TCP spec doesn’t say, source port # dest port #
- up to implementor sequence number
acknowledgement number
A rwnd
checksum urg pointer

Transport Layer 3-13


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

Transport Layer 3-14


TCP reliable data transfer
 TCP creates rdt service
on top of IP’s unreliable
service
• pipelined segments
• cumulative acks
• single retransmission
timer
 retransmissions
triggered by:
• timeout events
• duplicate acks

Transport Layer 3-15


TCP round trip time, timeout
Q: how to set TCP Q: how to estimate RTT?
timeout value?  SampleRTT: measured
time from segment
 longer than RTT transmission until ACK
• but RTT varies receipt
 too short: premature • ignore retransmissions
timeout, unnecessary  SampleRTT will vary, want
retransmissions estimated RTT “smoother”
• average several recent
 too long: slow reaction measurements, not just
to segment loss current SampleRTT

TCP throughput = rwnd / RTT (in theory!)


< rwnd / RTT (in practice … discuss later)
Transport Layer 3-16
TCP round trip time, timeout
EstimatedRTT = (1- )*EstimatedRTT + *SampleRTT
 exponential weighted moving average
 influence of past sample decreases exponentially fast
 typical value:  = 0.125 RTT: gaia.cs.umass.edu to fantasia.eurecom.fr

350

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


RTT (milliseconds)

300

250
RTT (milliseconds)

200

sampleRTT
150

EstimatedRTT

100
1 8 15 22 29 36 43 50 57 64 71 78 85 92 99 106
time (seconnds)
time (seconds) Transport Layer 3-17
SampleRTT Estimated RTT
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-)*DevRTT +
*|SampleRTT-EstimatedRTT|
(typically,  = 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-18
TCP sender events:
data rcvd from app: timeout:
 create segment with  retransmit segment
seq # that caused timeout
 seq # is byte-stream  restart timer
number of first data ack rcvd:
byte in segment  if ack acknowledges
 start timer if not previously unacked
already running segments
• think of timer as for • update what is known
oldest unacked to be ACKed
segment
• start timer if there are
• expiration interval: still unacked segments
TimeOutInterval

Transport Layer 3-19


TCP: retransmission scenarios
92 93 94 95 96 97 98 99 100
Host A Host B

Send Seq
Host A Host B
SendBase=92
Seq=92, 8 bytes of data

Seq=100, 20 bytes of data

timeout
Seq=92, 8 bytes of data
timeout

ACK=100 ACK=100
X ACK=120

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

lost ACK scenario premature timeout


Transport Layer 3-20
TCP: retransmission scenarios
Host A Host B

Seq=92, 8 bytes of data


92 93 94 95 96 97 98 99 100
Seq=100, 20 bytes of data
timeout

ACK=100
Send Seq
X
ACK=120 100 101 102 103 104 … 119 120

Send Seq
Seq=120, 15 bytes of data

cumulative ACK
Transport Layer 3-21
TCP fast retransmit
 time-out period often
relatively long: TCP fast retransmit
• long delay before if sender receives 3
resending lost packet ACKs for same data
 detect lost segments (“triple duplicate ACKs”),
via duplicate ACKs. resend unacked
• sender often sends segment with smallest
many segments back- seq #
to-back
 likely that unacked
• if segment is lost, there segment lost, so don’t
will likely be many wait for timeout
duplicate ACKs.

Transport Layer 3-22


TCP fast retransmit
Host A Host B

Seq=92, 8 bytes of data


Seq=100, 20 bytes of data
Seq=120
X 92 93 94 95 96 97 98 99 100
Seq=140
Seq=160
Send Seq
ACK=100
X
timeout

100 101 102 103 104 … 119 120


ACK=100
ACK=100
ACK=100 Send Seq

Seq=100, 20 bytes of data


120 121 122 123 124 … 139 140
Seq=120
Seq=140 140 141 142 143 144 … 159 160
Seq=160
Seq=180 160 161 162 163 164 … 179 180

fast retransmit after sender


receipt of triple duplicate ACK
Transport Layer 3-23
Chapter 3 outline
3.1 transport-layer 3.5 connection-oriented
services transport: TCP
3.2 multiplexing and • segment structure
demultiplexing • reliable data transfer
3.3 connectionless • flow control
transport: UDP • connection management
3.4 principles of reliable 3.6 principles of congestion
data transfer control
3.7 TCP congestion control

Transport Layer 3-24


Connection Management
before exchanging data, sender/receiver “handshake”:
 agree to establish connection (each knowing the other willing
to establish connection)
 agree on connection parameters

application application

connection state: ESTAB connection state: ESTAB


connection variables: connection Variables:
seq # client-to-server seq # client-to-server
server-to-client server-to-client
rcvBuffer size rcvBuffer size
at server,client at server,client

network network

clientSocket.connect connectionSocket, addr =


("servername","port number"); serverSocket.accept();
... ...
clientSocket.send(…) connectionSocket.recv(…)
Transport Layer 3-25
Agreeing to establish a connection

2-way handshake:
Q: will 2-way handshake
always work in
network?
Let’s talk
ESTAB  unreliable channel
OK
ESTAB  retransmitted messages (e.g.
req_conn(x)) due to loss

Byzantine Generals Problem


choose x
req_conn(x)
ESTAB
acc_conn(x)
ESTAB

Transport Layer 3-26


TCP 3-way handshake

client state server state


LISTEN LISTEN
choose init seq num, x
send TCP SYN msg
SYNSENT SYNbit=1, Seq=x
choose init seq num, y
send TCP SYNACK
msg, acking SYN SYN RCVD
SYNbit=1, Seq=y
ACKbit=1; ACKnum=x+1
received SYNACK(x)
ESTAB indicates server is live;
send ACK for SYNACK;
this segment may contain ACKbit=1, ACKnum=y+1
client-to-server data received ACK(y)
indicates client is live
ESTAB
remember
HTTP request?

Transport Layer 3-27


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


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
Why not 3-way closing?
Transport Layer 3-29
TCP segment structure
32 bits

source port # dest port #


sequence number
ACK: ACK # header length
valid acknowledgement number 20 bytes
head not
len used
UAP R S F receive window
checksum Urg data pointer

RST, SYN, FIN: options (variable length) rwnd


connection estab
(setup, teardown
commands)
application
Internet data
checksum (variable length)
(as in UDP)

Transport Layer 3-30


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

Transport Layer 3-31


Principles of congestion control
congestion:
 informally: “too many sources sending too much
data too fast for network to handle”
 different from flow control!
 manifestations:
• long delays (queueing in router buffers)
• lost packets (buffer overflow at routers)
 a top-10 problem!

Transport Layer 3-32


Causes/costs of congestion: scenario 1
original data: lin throughput: lout
 two senders, two
receivers Host A

 one router unlimited shared


 output link capacity: R output link buffers

 As traffic increase:
❌ Delay increase
❌Packet loss Host B
maximum per-connection
throughput: R/2

 How can we?


 Avoid congestion

delay
loss

 Resolve congestion
lin R/2
 large delays as arrival rate, lin,
approaches capacity
Transport Layer 3-33
Chapter 3 outline
3.1 transport-layer 3.5 connection-oriented
services transport: TCP
3.2 multiplexing and • segment structure
demultiplexing • reliable data transfer
3.3 connectionless • flow control
transport: UDP • connection management
3.4 principles of reliable 3.6 principles of congestion
data transfer control
3.7 TCP congestion control

Transport Layer 3-34


TCP Slow Start many hops

Host A Host B
 when connection begins,
increase rate
exponentially until first
loss event:

RTT
• initially cwnd = 1 MSS
• double cwnd every RTT
• done by incrementing
cwnd by 1 MSS (linear) for
every ACK received
 summary: initial rate is
slow but ramps up
exponentially fast time

Transport Layer 3-35


TCP: switching from slow start to CA
Q: when should the
exponential
increase switch to
linear?
A: when
cwnd ≥ ssthresh

Implementation:
 variable ssthresh
 on loss event, ssthresh is set to 1/2 of cwnd
 CA (Congestion Avoidance):
• when cwnd ≥ ssthresh, cwnd++ (add 1 MSS every RTT)

* Check out the online interactive exercises for more


examples: http://gaia.cs.umass.edu/kurose_ross/interactive/ Transport Layer 3-36
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: cut cwnd in half after loss
additively increase window size …
…. until loss occurs (then cut window in half)
congestion window size
cwnd: TCP sender

AIMD saw tooth


behavior: probing
for bandwidth

time
Transport Layer 3-37
TCP Congestion Control: details
sender sequence number space
cwnd TCP sending rate:
 roughly: send cwnd
bytes, wait RTT for
last byte last byte
ACKS, then send
ACKed sent, not-
yet ACKed
sent more bytes
(“in-
flight”) cwnd
 sender limits transmission: rate ~
~
RTT
bytes/sec

LastByteSent- < cwnd


LastByteAcked

 cwnd is dynamic, function


of perceived network
congestion
Transport Layer 3-38
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
• avg. thruput is 3/4W per RTT
3 W
avg TCP thruput = bytes/sec
4 RTT

W/2

Transport Layer 3-39


Chapter 3: summary
 principles behind transport
layer services: next:
• multiplexing,  leaving the network
demultiplexing “edge” (application,
• reliable data transfer transport layers)
• flow control  into the network
• congestion control “core”
 instantiation,  two network layer
implementation in the chapters:
Internet • data plane
• UDP • control plane
• TCP
Transport Layer 3-40

You might also like