Professional Documents
Culture Documents
Layer
Transport Layer 2
1
Outline
Transport-layer Connection-oriented
services transport: TCP
Multiplexing and segment structure
demultiplexing reliable data transfer
flow control
Connectionless
connection management
transport: UDP
Principles of congestion
Principles of reliable
data transfer control
TCP congestion control
Transport Layer 3
Transport Layer 4
2
Transport vs. network layer
network layer: logical Household analogy:
communication 12 kids sending letters to
between hosts 12 kids
transport layer: logical processes = kids
communication app messages = letters
between processes in envelopes
relies on, enhances, hosts = houses
network layer services
transport protocol =
Ann and Bill
network-layer protocol
= postal service
Transport Layer 5
connection setup
unreliable, unordered
network
data link
physicalnetwork
delivery: UDP data link
physical
no-frills extension of network
data link
“best-effort” IP
application
physical network transport
data link network
services not available: physical data link
physical
delay guarantees
bandwidth guarantees
Transport Layer 6
3
Multiplexing/demultiplexing
Demultiplexing at rcv host: Multiplexing at send host:
gathering data from multiple
delivering received segments
sockets, enveloping data with
to correct socket
header (later used for
demultiplexing)
= socket = process
P3 P1
P1 P2 P4 application
application application
host 2 host 3
host 1
Transport Layer 7
application
data
(message)
Transport Layer 8
4
Connectionless demultiplexing
When host receives UDP
Create sockets with port
segment:
numbers:
DatagramSocket mySocket1 = new checks destination port
DatagramSocket(12534); number in segment
DatagramSocket mySocket2 = new directs UDP segment to
DatagramSocket(12535); socket with that port
number
UDP socket identified by
two-tuple: IP datagrams with
different source IP
(dest IP address, dest port number)
addresses and/or source
port numbers directed
to same socket
Transport Layer 9
P2 P1
P1
P3
Transport Layer 10
5
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
receiving host 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
Transport Layer 11
Connection-oriented demux
(cont)
P1 P4 P5 P6 P2 P1P3
SP: 5775
DP: 80
S-IP: B
D-IP:C
Transport Layer 12
6
Connection-oriented demux:
Threaded Web Server
P1 P4 P2 P1P3
SP: 5775
DP: 80
S-IP: B
D-IP:C
Transport Layer 13
Transport Layer 14
7
UDP: more
often used for streaming
multimedia apps 32 bits
Transport Layer 15
UDP checksum
Goal: detect “errors” (e.g., flipped bits) in transmitted
segment
Sender: Receiver:
treat segment contents compute checksum of
as sequence of 16-bit received segment
integers check if computed checksum
checksum: addition (1‟s equals checksum field value:
complement sum) of NO - error detected
segment contents YES - no error detected.
sender puts checksum But maybe errors
value into UDP checksum nonetheless? More later
field ….
Transport Layer 16
8
Bitwise Operations
Transport Layer 17
9
Left and right shift example
#include <stdio.h>
int main(void){
unsigned int a=16;
printf("%d\t",a>>3); /* prints 16 divided by 8 */
printf("%d\n",a<<3); /* prints 16 multiplied by 8 */
return 0;
}
output: 2 128
10
AND
The & operator performs a bitwise AND on
two integers. Each bit in the result is 1 only
if both corresponding bits in the two input
operands are 1.
For example, 0x56 & 0x32 is 0x12, because
(in binary):
01010110
&00110010
---------------
00010010
OR
The & operator performs a bitwise AND on
two integers. Each bit in the result is 1 only
if both corresponding bits in the two input
operands are 1.
For example, 0x56 & 0x32 is 0x12, because
(in binary):
01010110
&00110010
---------------
00010010
Transport Layer 22
11
Bitwise exclusive OR operator
Symbol: ^
XOR
The ^ (caret) operator performs a bitwise
exclusive-OR on two integers. Each bit in
the result is 1 if one, but not both, of the
corresponding bits in the two input
operands is 1.
For example, 0x56 ^ 0x32 is 0x64:
01010110
^00110010
---------------
01100100
12
One's complement operator
Symbol: ~
Complement
The ~ (tilde) operator performs a bitwise
complement on its single integer operand. (The
~ operator is therefore a unary operator, like !
and the unary -, &, and * operators.)
Complementing a number means to change all
the 0 bits to 1 and all the 1s to 0s.
For example, assuming 16-bit integers, ~0x56
is 0xffa9:
~0000000001010110
-------------------------------
1111111110101001
13
Internet Checksum Example
Note
When adding numbers, a carryout from the
most significant bit needs to be added to the
result
Example: add two 16-bit integers
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
27
14
Principles of Reliable data transfer
important in app., transport, link layers
top-10 list of important networking topics!
15
Reliable data transfer: getting started
rdt_send(): called from above, deliver_data(): called by
(e.g., by app.). Passed data to rdt to deliver data to upper
deliver to receiver upper layer
send receive
side side
16
Rdt2.0: channel with bit errors
underlying channel may flip bits in packet
checksum to detect bit errors
the question: how to recover from errors:
acknowledgements (ACKs): receiver explicitly tells sender
that pkt received OK
negative acknowledgements (NAKs): receiver explicitly
tells sender that pkt had errors
sender retransmits pkt on receipt of NAK
new mechanisms in rdt2.0 (beyond rdt1.0):
error detection
receiver feedback: control msgs (ACK,NAK) rcvr->sender
17
rdt2.1: discussion
Sender: Receiver:
seq # added to pkt must check if received
two seq. #‟s (0,1) will packet is duplicate
suffice. Why? state indicates whether
0 or 1 is expected pkt
must check if received seq #
ACK/NAK corrupted
note: receiver can not
twice as many states know if its last
state must “remember” ACK/NAK received OK
whether “current” pkt
at sender
has 0 or 1 seq. #
18
rdt3.0: channels with errors and loss
rdt3.0 in action
19
rdt3.0 in action
U L/R .008
= = = 0.00027
sender 30.008
RTT + L / R microsec
onds
20
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
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-42
21
Pipelining Protocols
Go-back-N: overview Selective Repeat: overview
sender: up to N sender: up to N unACKed
unACKed pkts in packets in pipeline
pipeline receiver: ACKs individual
receiver: only sends pkts
cumulative ACKs sender: maintains timer
doesn‟t ACK pkt if for each unACKed pkt
there‟s a gap
if timer expires: retransmit
sender: has timer for only unACKed packet
oldest unACKed pkt
if timer expires:
retransmit all unACKed
packets
Go-Back-N
Sender:
k-bit seq # in pkt header
“window” of up to N, consecutive unACKed pkts allowed
22
GBN in
action
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
again limits seq #s of sent, unACKed pkts
23
Selective repeat: sender, receiver windows
Selective repeat
sender receiver
data from above : pkt n in [rcvbase, rcvbase+N-1]
if next available seq # in send ACK(n)
window, send pkt out-of-order: buffer
timeout(n): in-order: deliver (also
resend pkt n, restart timer deliver buffered, in-order
pkts), advance window to
ACK(n) in [sendbase,sendbase+N]: next not-yet-received pkt
mark pkt n as received
pkt n in [rcvbase-N,rcvbase-1]
if n smallest unACKed pkt,
ACK(n)
advance window base to
next unACKed seq # otherwise:
ignore
24
Selective repeat in action
Selective repeat:
dilemma
Example:
seq #‟s: 0, 1, 2, 3
window size=3
receiver sees no
difference in two
scenarios!
incorrectly passes
duplicate data as new
in (a)
Q: what relationship
between seq # size
and window size?
Transport Layer 3-50
25
TCP: Overview RFCs: 793, 1122, 1323, 2018, 2581
overwhelm receiver
door door
TCP TCP
send buffer receive buffer
segment
26
TCP seq. #‟s and ACKs
Seq. #‟s:
Host A Host B
byte stream
“number” of first User
types
byte in segment‟s „C‟
data host ACKs
receipt of
ACKs: „C‟, echoes
seq # of next byte back „C‟
expected from
other side host ACKs
cumulative ACK receipt
of echoed
Q: how receiver handles „C‟
out-of-order segments
A: TCP spec doesn‟t
time
say, - up to
simple telnet scenario
implementer
Transport Layer 3-53
27
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 acknowledges
start timer if not previously unACKed
already running (think segments
of timer as for oldest update what is known to
unACKed segment) be ACKed
expiration interval: start timer if there are
TimeOutInterval outstanding segments
X
loss
Sendbase
= 100
Seq=92 timeout
SendBase
= 120
SendBase
= 100 SendBase
= 120 premature timeout
time time
lost ACK scenario
Transport Layer 3-56
28
TCP retransmission scenarios (more)
Host A Host B
timeout
X
loss
SendBase
= 120
time
Cumulative ACK scenario
Fast Retransmit
time-out period often If sender receives 3
relatively long: ACKs for same data, it
long delay before assumes that segment
resending lost packet after ACKed data was
detect lost segments lost:
via duplicate ACKs. fast retransmit: resend
sender often sends segment before timer
many segments back-to- expires
back
if segment is lost, there
will likely be many
duplicate ACKs for that
segment
29
Host A Host B
seq # x1
seq # x2
seq # x3
ACK x1
seq # x4 X
seq # x5
ACK x1
ACK x1
ACK x1
triple
duplicate
ACKs
timeout
time
IP
(currently)
TCP data application
speed-matching
unused buffer
datagrams space
(in buffer) process service: matching
send rate to receiving
application‟s drain rate
app process may be
slow at reading from
buffer
Transport Layer 3-60
30
TCP Connection Management
Recall: TCP sender, receiver Three way handshake:
establish “connection”
before exchanging data Step 1: client host sends TCP
segments SYN segment to server
initialize TCP variables: specifies initial seq #
seq. #s no data
close
client closes socket:
clientSocket.close();
31
TCP Connection Management (cont.)
timed wait
Note: with small
closed
modification, can handle
simultaneous FINs.
closed
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!
32
Approaches towards congestion control
two broad approaches towards congestion control:
33
Case study: ATM ABR congestion control
34
TCP congestion control: bandwidth probing
“probing for bandwidth”: increase transmission rate
on receipt of ACK, until eventually loss occurs, then
decrease transmission rate
continue to increase on ACK, decrease on loss (since available
bandwidth is changing, depending on other connections in
network)
ACKs being received,
X loss, so decrease rate
so increase rate
X
X
X
sending rate
TCP‟s
X “sawtooth”
behavior
time
cwnd
roughly, bytes
cwnd
rate = bytes/sec
RTT
RTT
cwnd is dynamic, function of
perceived network congestion ACK(s)
35
TCP Congestion Control: more details
36
Transitioning into/out of slowstart
ssthresh: cwnd threshold maintained by TCP
on loss event: set ssthresh to cwnd/2
remember (half of) TCP rate when congestion last occurred
when cwnd >= ssthresh: transition from slowstart to congestion
avoidance phase
duplicate ACK
dupACKcount++ new ACK
cwnd = cwnd+MSS
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
timeout dupACKcount = 0
retransmit missing segment
ssthresh = cwnd/2
cwnd = 1 MSS
dupACKcount = 0
retransmit missing segment
37
Summary: TCP Congestion Control
Summary
principles behind transport
layer services:
multiplexing,
demultiplexing
reliable data transfer
flow control Next:
congestion control leaving the network
instantiation and “edge” (application,
implementation in the transport layers)
Internet into the network
UDP “core”
TCP
Transport Layer 3-76
38