Lecture - 6 UDP TCP (Final)
Lecture - 6 UDP TCP (Final)
Transport Layer
lo
gi
ca
transport protocols run in
le
nd
end systems
-e
nd
send side: breaks app
tr
an
messages into segments,
pos
passes to network layer
rt
rcv side: reassembles application
transport
segments into messages, network
data link
passes to app layer physical
lo
physical network
gi
data link
flow control
ca
physical
le
connection setup
nd
-e
nd
unreliable, unordered network
tr
data link
an
physicalnetwork
delivery: UDP
s
data link
po
physical
r
t
no-frills extension of network
data link
application
“best-effort” IP physical network
data link
transport
network
services not available: physical data link
physical
delay guarantees
bandwidth guarantees
P3 P1
P1 P2 P4 application
application application
host 2 host 3
host 1
Transport Layer 3-8
How demultiplexing works
host receives IP datagrams
each datagram has source IP
address, destination IP address 32 bits
each datagram carries 1
source port # dest port #
transport-layer segment
each segment has source,
destination port number other header fields
host uses IP addresses & port
numbers to direct segment to
appropriate socket
application
data
(message)
P2 P1
P1
P3
P1 P4 P5 P6 P2 P1P3
SP: 5775
DP: 80
S-IP: B
D-IP:C
P1 P4 P2 P1P3
SP: 5775
DP: 80
S-IP: B
D-IP:C
If the data link layer is reliable and has flow and error control, do we need
this at the transport layer, too? Yes
User Datagram Protocol (UDP )
o UDP is a connectionless, unreliable transport protocol.
Sender: o Receiver:
o treat segment contents o compute checksum of received
as sequence of 16-bit segment
integers o check if computed checksum
o checksum: addition (1’s equals checksum field value:
complement sum) of o NO - error detected
segment contents o YES - no error detected.
o sender puts checksum But maybe errors
value into UDP checksum nonetheless? More later ….
field
1 1 1 1 0 0 1 1 0 0 1 1 0 0 1 1 0
1 1 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1
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
Transport Layer 3-29
Checksum
o characteristics of unreliable channel will determine complexity of reliable data transfer protocol
(rdt)
o characteristics of unreliable channel will determine complexity of reliable data transfer protocol
(rdt)
o characteristics of unreliable channel will determine complexity of reliable data transfer protocol
(rdt)
send receive
side side
sender receiver
rdt_rcv(rcvpkt) &&
isNAK(rcvpkt)
Wait for call Wait for rdt_rcv(rcvpkt) &&
corrupt(rcvpkt)
from above ACK or NAK
udt_send(sndpkt)
udt_send(NAK)
sender
rdt_rcv(rcvpkt) &&
notcorrupt(rcvpkt)
extract(rcvpkt,data)
deliver_data(data)
udt_send(ACK)
rdt_rcv(rcvpkt) &&
isNAK(rcvpkt)
Wait for call Wait for rdt_rcv(rcvpkt) &&
corrupt(rcvpkt)
from above ACK or NAK
udt_send(sndpkt)
udt_send(NAK)
rdt_rcv(rcvpkt) &&
notcorrupt(rcvpkt)
extract(rcvpkt,data)
deliver_data(data)
udt_send(ACK)
rdt_rcv(rcvpkt) &&
isNAK(rcvpkt)
Wait for call Wait for rdt_rcv(rcvpkt) &&
corrupt(rcvpkt)
from above ACK or NAK
udt_send(sndpkt)
udt_send(NAK)
rdt_rcv(rcvpkt) &&
notcorrupt(rcvpkt)
extract(rcvpkt,data)
deliver_data(data)
udt_send(ACK)
Wait for ACK Wait for
or NAK 1 call 1 from
rdt_rcv(rcvpkt) && above
( corrupt(rcvpkt) ||
isNAK(rcvpkt) )
rdt_send(data)
sndpkt = make_pkt(1, data, checksum)
udt_send(sndpkt) udt_send(sndpkt)
extract(rcvpkt,data)
deliver_data(data)
sndpkt = make_pkt(ACK, chksum)
udt_send(sndpkt)
L 8000bits
d trans 9
8 microseconds
R 10 bps
o U sender : utilization – fraction of time sender busy sending
U L/R .008
= = = 0.00027
sender 30.008
RTT + L / R microsec
o 1KB pkt every 30 msec -> 33kB/sec thruput over 1 Gbps link onds
o network protocol limits use of physical resources!
U L/R .008
= = = 0.00027
sender 30.008
RTT + L / R microsec
onds
Increase utilization
by a factor of 3!
U 3*L/R .024
= = = 0.0008
sender 30.008
RTT + L / R microsecon
ds
Transport Layer 3-60
Pipelining Protocols
Go-back-N: overview Selective Repeat: overview
o sender: up to N o sender: up to N unACKed
unACKed pkts in packets in pipeline
pipeline o receiver: ACKs individual
o receiver: only sends pkts
cumulative ACKs o sender: maintains timer
o doesn’t ACK pkt if for each unACKed pkt
there’s a gap o if timer expires: retransmit
o sender: has timer for only unACKed packet
oldest unACKed pkt
o if timer expires:
retransmit all unACKed
packets
base=1
nextseqnum=1
timeout
start_timer
Wait
udt_send(sndpkt[base])
udt_send(sndpkt[base+1])
rdt_rcv(rcvpkt) …
udt_send(sndpkt[nextseqnum-1])
&& corrupt(rcvpkt)
rdt_rcv(rcvpkt) &&
notcorrupt(rcvpkt)
base = getacknum(rcvpkt)+1
If (base == nextseqnum)
stop_timer
else
start_timer
udt_send(sndpkt) rdt_rcv(rcvpkt)
&& notcurrupt(rcvpkt)
&& hasseqnum(rcvpkt,expectedseqnum)
Wait
extract(rcvpkt,data)
expectedseqnum=1 deliver_data(data)
sndpkt = sndpkt = make_pkt(expectedseqnum,ACK,chksum)
make_pkt(expectedseqnum,ACK,chksum) udt_send(sndpkt)
expectedseqnum++
o receiver sees no
difference in two
scenarios!
o incorrectly passes
duplicate data as new in
(a)
o Q: what relationship
between seq # size and
window size?
Transport Layer 3-70
Chapter 3 outline
o 3.1 Transport-layer o 3.5 Connection-oriented
services transport: TCP
o 3.2 Multiplexing and o segment structure
demultiplexing o reliable data transfer
o 3.3 Connectionless
o flow control
o connection management
transport: UDP
o 3.6 Principles of
o 3.4 Principles of
reliable data transfer congestion control
o 3.7 TCP congestion
control
When the receiving TCP receives a segment with the URG bit
set, it extracts the urgent data from the segment using
the value of the urgent pointer, and delivers them, out of
order, to the receiving application program.
TCP Connection
A Connection-oriented transport protocol
establishes a virtual path between the source
and destination.
In TCP, connection-oriented transmission
requires three phases:
1. connection establishment
2. data transfer
3. connection termination
Connection Establishment
TCP transmits data in full-duplex mode. When two TCPs in two
machines are connected, they are able to send segments to each
other simultaneously.
Each party must initialize communication and get approval from
the other party before any data are transferred.
The connection establishment in TCP is called three way
handshaking.
Example:
After connection is established, the client sends 2000 bytes of
data in two segments.
The server then sends 2000 bytes in one segment.
The client sends one more acknowledgment segment.
The first three segments carry both data and acknowledgment,
but the last segment carries only an acknowledgment because
there are no more data to be sent.
Data transfer
TCP opens a connections using an initial sequence number (ISN) of
14534. The other party opens the connection with an ISN of 21732. Show
the three TCP segment during the connection establishment.
Connection Termination Using
Three-way Handshaking
Any of the two parties involved in exchanging data (client or server) can close the
connection using three-Way Handshaking
Three-way Handshaking steps
1. The client TCP, after receiving a close command from the client process,
sends the first segment, a FIN segment in which the FIN flag is set.
A FIN segment can include the last chunk of data sent by the client, or it
can be just a control segment
If it is only a control segment, it consumes only one sequence number.
2. The server TCP, after receiving the FIN segment, sends the second segment,
a FIN +ACK segment, to confirm the receipt of the FIN segment from the
client and at the same time to announce the closing of the connection in the
other direction.
This segment can also contain the last chunk of data from the server.
If it does not carry data, it consumes only one sequence number.
3. The client TCP sends the last segment, an ACK segment, to confirm the
receipt of the FIN segment from the TCP server.
This segment contains the acknowledgment number, which is 1 plus the
sequence number received in the FIN segment from the server.
This segment cannot carry data and consumes no sequence numbers.
NOTE
side
cumulative ACK host ACKs
receipt Seq=4
Q: how receiver handles of echoed 3, ACK
=80
out-of-order segments ‘C’
A: TCP spec doesn’t
say, - up to
time
implementer
simple telnet scenario
350
300
250
RTT (milliseconds)
200
150
100
1 8 15 22 29 36 43 50 57 64 71 78 85 92 99 106
time (seconnds)
Seq=9 Seq=9
2, 8 b 2, 8 b
y t es d y t es d
at a Seq= at a
Seq=92 timeout
100,
20 b y
t es d
ata
timeout
=100
ACK 0
10
X CK
A AC
=
K =120
loss
Seq=9 Seq=9
2, 8 b
2, 8 b
y t es d Sendbase y t es d
at a
at a
= 100
Seq=92 timeout
SendBase
= 120 =1 20
K
CK =100 AC
A
SendBase
= 100 SendBase
= 120 premature timeout
time time
lost ACK scenario
Transport Layer 3-106
TCP retransmission scenarios (more)
Host A Host B
Seq=9
2, 8 b
y t es d
at a
=100
timeout
Seq=1 A CK
00 , 2 0
b y t es
dat a
X
loss
SendBase CK =120
A
= 120
time
Cumulative ACK scenario
seq # x1
seq # x2
seq # x3
ACK x1
seq # x4 X
seq # x5
ACK x1
ACK x1
ACK x1
triple
duplicate
ACKs re s e n
d s eq
X2
timeout
time
IP
(currently)
TCP data application
o speed-matching
unused buffer
datagrams space
(in buffer) process service: matching
send rate to receiving
application’s drain rate
o app process may be
slow at reading from
buffer
Transport Layer 3-112
TCP Flow control: how it works
(currently) o receiver: advertises
IP TCP data application
unused buffer
datagrams space
(in buffer) process unused buffer space by
including rwnd value in
rwnd segment header
RcvBuffer
o sender: limits # of
o (suppose TCP receiver unACKed bytes to rwnd
discards out-of-order o guarantees receiver’s
segments) buffer doesn’t overflow
o unused buffer space:
o = rwnd
o = RcvBuffer-[LastByteRcvd
- LastByteRead]
timed wait
ACK
replies with ACK. Closes
connection, sends FIN.
closed
timed wait
ACK
modification, can handle
simultaneous FINs. closed
closed
TCP server
lifecycle
TCP client
lifecycle
o Congestion:
o informally: “too many sources sending too much
data too fast for network to handle”
o different from flow control!
o manifestations:
o lost packets (buffer overflow at routers)
o long delays (queueing in router buffers)
o a top-10 problem!
receivers
unlimited shared
one router,
Host B
output link buffers
infinite buffers
no retransmission
large delays
when congested
maximum
achievable
throughput
Transport Layer 3-121
Causes/costs of congestion: scenario 2
o one router, finite buffers
o sender retransmission of lost packet
R/3
out
out
out
R/4
a. b. c.
o “costs” of congestion:
o more work (retrans) for given “goodput”
o unneeded retransmissions: link carries multiple copies of pkt
Host B
Host B
TCP’s
X “sawtooth”
behavior
time
cwnd
rate = bytes/sec
RTT
o cwnd is dynamic, function of perceived
RTT
network congestion
ACK(s)
RTT
o initial rate = 20 kbps
o available bandwidth may be >>
two segm
en ts
MSS/RTT
o desirable to quickly ramp up to
respectable rate
four segm
o increase rate exponentially until ents