Chapter 3
Chapter 3
Transport Layer
2-1
1
Transport vs. network layer
network layer: logical household analogy:
communication
between hosts 12 kids in Ali’s house sending
letters to 12 kids in Ahmed’s
transport layer: house:
logical hosts = houses
communication processes = kids
between processes app messages = letters in
envelopes
• relies on, enhances, transport protocol = Ali
network layer and Ahmed who demux to
services in-house siblings
network-layer protocol =
postal service
3-3
network
• delay guarantees
• bandwidth guarantees
3-4
2
Multiplexing/demultiplexing
multiplexing at sender:
handle data from multiple demultiplexing at receiver:
sockets, add transport header use header info to deliver
(later used for demultiplexing) received segments to correct
socket
application
3-5
3-6
3
Connectionless demux: example
DatagramSocket
DatagramSocket serverSocket = new
DatagramSocket DatagramSocket
mySocket2 = new mySocket1 = new
DatagramSocket (6428); DatagramSocket
(9157); application (5775);
application application
P1
P3 P4
transport
transport transport
network
network link network
link physical link
physical physical
Connection-oriented demux
TCP socket identified server host may support
by 4-tuple: many simultaneous TCP
• source IP address sockets:
• source port number • each socket identified by
• dest IP address its own 4-tuple
• dest port number web servers have
demux: receiver uses all different sockets for
four values to direct each connecting client
segment to appropriate • non-persistent HTTP will
socket have different socket for
each request
3-8
4
Connection-oriented demux: example
application
application P4 P5 P6 application
P3 P2 P3
transport
transport transport
network
network link network
link physical link
physical server: IP physical
address B
3-10
10
5
UDP: User Datagram Protocol [RFC 768]
“no frills,” “bare bones” UDP use:
Internet transport streaming multimedia
protocol apps (loss tolerant, rate
“best effort” service, UDP sensitive)
segments may be: DNS
• lost SNMP
• delivered out-of-order reliable transfer over
to app
UDP:
connectionless:
add reliability at
• no handshaking application layer
between UDP sender,
receiver application-specific error
recovery!
• each UDP segment
handled independently
of others
3-11
11
length checksum
why is there a UDP?
no connection
application establishment (which can
data add delay)
(payload) simple: no connection
state at sender, receiver
small header size
UDP segment format no congestion control:
UDP can blast away as fast
as desired
3-12
12
6
UDP checksum
Goal: detect “errors” (e.g., flipped bits) in transmitted
segment
sender: receiver:
treat segment contents, compute checksum of
including header fields, received segment
as sequence of 16-bit check if computed checksum
integers
equals checksum field value:
checksum: addition
(one’s complement sum) • NO - error detected
of segment contents • YES - no error detected.
sender puts checksum But maybe errors
value into UDP checksum nonetheless? More later
field ….
3-13
13
wraparound 1 1 0 1 1 1 0 1 1 1 0 1 1 1 0 1 1
sum 1 1 0 1 1 1 0 1 1 1 0 1 1 1 1 0 0
checksum 1 0 1 0 0 0 1 0 0 0 1 0 0 0 0 1 1
3-14
14
7
rdt3.0 in action
sender receiver sender receiver
send pkt0 pkt0 send pkt0 pkt0
rcv pkt0 rcv pkt0
ack0 send ack0 ack0 send ack0
rcv ack0 rcv ack0
send pkt1 pkt1 send pkt1 pkt1
rcv pkt1 X
ack1 send ack1 loss
rcv ack1
send pkt0 pkt0
rcv pkt0 timeout
ack0 send ack0 resend pkt1 pkt1
rcv pkt1
ack1 send ack1
rcv ack1
send pkt0 pkt0
(a) no loss rcv pkt0
ack0 send ack0
15
rdt3.0 in action
sender receiver
sender receiver send pkt0 pkt0
send pkt0 pkt0 rcv pkt0
ack0 send ack0
rcv pkt0
send ack0 rcv ack0
ack0 send pkt1 pkt1
rcv ack0 rcv pkt1
send pkt1 pkt1
rcv pkt1 send ack1
ack1 ack1
send ack1
X
loss timeout
resend pkt1 pkt1
rcv pkt1
timeout
resend pkt1 pkt1 rcv ack1 pkt0 (detect duplicate)
rcv pkt1 send pkt0 send ack1
(detect duplicate) ack1
ack1 send ack1 rcv ack1 rcv pkt0
rcv ack1 ack0 send ack0
pkt0 send pkt0 pkt0
send pkt0 rcv pkt0
rcv pkt0 ack0 (detect duplicate)
ack0 send ack0 send ack0
3-16
16
8
Pipelined protocols
pipelining: sender allows multiple, “in-flight”, yet-
to-be-acknowledged pkts
• range of sequence numbers must be increased
• buffering at sender and/or receiver
17
3-18
18
9
GBN in action
sender window (N=4) sender receiver
012345678 send pkt0
012345678 send pkt1
012345678 send pkt2 receive pkt0, send ack0
012345678 send pkt3 Xloss receive pkt1, send ack1
(wait)
receive pkt3, discard,
012345678 rcv ack0, send pkt4 (re)send ack1
012345678 rcv ack1, send pkt5 receive pkt4, discard,
(re)send ack1
ignore duplicate ACK receive pkt5, discard,
(re)send ack1
pkt 2 timeout
012345678 send pkt2
012345678 send pkt3
012345678 send pkt4 rcv pkt2, deliver, send ack2
012345678 send pkt5 rcv pkt3, deliver, send ack3
rcv pkt4, deliver, send ack4
rcv pkt5, deliver, send ack5
3-19
19
Selective repeat
receiver individually acknowledges all correctly
received pkts
• buffers pkts, as needed, for eventual in-order delivery
to upper layer
sender only resends pkts for which ACK not
received
• sender timer for each unACKed pkt
sender window
• N consecutive seq #’s
• limits seq #s of sent, unACKed pkts
3-20
20
10
Selective repeat in action
sender window (N=4) sender receiver
012345678 send pkt0
012345678 send pkt1
012345678 send pkt2 receive pkt0, send ack0
012345678 send pkt3 Xloss receive pkt1, send ack1
(wait)
receive pkt3, buffer,
012345678 rcv ack0, send pkt4 send ack3
012345678 rcv ack1, send pkt5 receive pkt4, buffer,
send ack4
record ack3 arrived receive pkt5, buffer,
send ack5
pkt 2 timeout
012345678 send pkt2
012345678 record ack4 arrived
012345678 rcv pkt2; deliver pkt2,
record ack5 arrived
012345678 pkt3, pkt4, pkt5; send ack2
3-21
21
22
11
TCP segment structure
32 bits
URG: urgent data counting
(generally, not used) source port # dest port #
by bytes
sequence number of data
ACK: ACK #
valid acknowledgement number (not segments!)
head not
PSH: push data now len used
UAP R S F receive window
(generally, not used) # bytes
checksum Urg data pointer
rcvr willing
RST, SYN, FIN: to accept
options (variable length)
connection estab
(setup, teardown
commands)
application
Internet data
checksum (variable length)
(as in UDP)
3-23
23
3-24
24
12
TCP round trip time, timeout
EstimatedRTT = (1- )*EstimatedRTT + *SampleRTT
3-25
25
3-26
26
13
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
3-27
27
SendBase=92
Seq=92, 8 bytes of data Seq=92, 8 bytes of data
timeout
ACK=100
X
ACK=100
ACK=120
SendBase=120
28
14
TCP: retransmission scenarios
Host A Host B
X
ACK=120
cumulative ACK
3-29
29
3-30
30
15
TCP fast retransmit
Host A Host B
ACK=100
timeout
ACK=100
ACK=100
ACK=100
Seq=100, 20 bytes of data
31
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
3-32
32
16
TCP 3-way handshake
3-33
33
3-34
34
17
Principles of congestion control
congestion:
informally: “too many sources sending too much
data too fast for network to handle”
different from flow control!
manifestations:
• lost packets (buffer overflow at routers)
• long delays (queueing in router buffers)
a top-10 problem!
3-35
35
Causes/costs of congestion
R/2
idealization: perfect
knowledge
out
36
18
Causes/costs of congestion
Idealization: known loss
packets can be lost,
dropped at router due
to full buffers
sender only resends if
packet known to be lost
A
no buffer space!
Host B
3-37
37
Causes/costs of congestion
Idealization: known loss R/2
packets can be lost,
dropped at router due when sending at R/2,
some packets are
out
A
free buffer space!
Host B
3-38
38
19
Causes/costs of congestion
Realistic: duplicates R/2
packets can be lost, dropped at
router due to full buffers when sending at R/2,
some packets are
out
sender times out prematurely, retransmissions
including duplicated
sending two copies, both of that are delivered!
which are delivered in R/2
in
timeout
copy 'in out
A
free buffer space!
Host B
3-39
39
Causes/costs of congestion
Realistic: duplicates R/2
packets can be lost, dropped at
router due to full buffers when sending at R/2,
some packets are
out
“costs” of congestion:
more work (retrans) for given “goodput”
unneeded retransmissions: link carries multiple copies of pkt
• decreasing goodput
3-40
40
20
TCP congestion control: additive increase
multiplicative decrease(AIMD)
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
time
3-41
41
3-42
42
21
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)
3-43
43
Implementation:
variable ssthresh
on loss event, ssthresh
is set to 1/2 of cwnd just
before loss event
3-44
44
22
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
3-45
45
TCP Fairness
fairness goal: if K TCP sessions share same
bottleneck link of bandwidth R, each should have
average rate of R/K
TCP connection 1
bottleneck
router
capacity R
TCP connection 2
3-46
46
23