Lecture CCN Fawad 05
Lecture CCN Fawad 05
Networks
Lecture # 01
Transport Layer
our goals:
understand learn about Internet
principles behind transport layer protocols:
transport layer UDP: connectionless
services: transport
multiplexing, TCP: connection-oriented
demultiplexing reliable transport
reliable data transfer TCP congestion control
flow control
congestion control
lo
hosts
gi
ca
l
transport protocols run in end
en
d-
en
systems
d
tra
send side: breaks app
ns
po
messages into segments,
rt
passes to network layer application
transport
rcv side: reassembles network
data link
segments into messages, physical
lo
data link physical
gi
physical
ca
• flow control network
l
data link
en
physical
d-
• connection setup
en
network
d
data link
tra
• unreliable, unordered physical
ns
po
network
delivery: UDP
rt
data link
physical
network
application
Transport
Lecture #Layer
01 3-14
Week based roadmap
3.5 connection-oriented
3.1 transport-layer services transport: TCP
3.2 multiplexing and demultiplexing segment structure
3.3 connectionless transport: UDP reliable data transfer
flow control
3.4 principles of reliable data transfer
connection management
3.6 principles of congestion
control
3.7 TCP congestion control
length checksum
why is there a UDP?
no connection establishment
application (which can add delay)
data
simple: no connection state
(payload)
at sender, receiver
small header size
no congestion control: UDP
UDP segment format can blast away as fast as
desired
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
Lecture #Layer
01 3-19
Week based roadmap
3.5 connection-oriented
3.1 transport-layer services transport: TCP
3.2 multiplexing and demultiplexing segment structure
3.3 connectionless transport: UDP reliable data transfer
flow control
3.4 principles of reliable data transfer
connection management
3.6 principles of congestion
control
3.7 TCP congestion control
characteristics of unreliable channel will determine complexity of reliable data transfer protocol (rdt)
characteristics of unreliable channel will determine complexity of reliable data transfer protocol (rdt)
characteristics of unreliable channel will determine complexity of reliable data transfer protocol (rdt)
send receive
side side
sender receiver
rdt_rcv(rcvpkt) &&
notcorrupt(rcvpkt)
extract(rcvpkt,data)
deliver_data(data)
udt_send(ACK)
rdt_rcv(rcvpkt) &&
notcorrupt(rcvpkt)
extract(rcvpkt,data)
deliver_data(data)
udt_send(ACK)
rdt_rcv(rcvpkt) &&
notcorrupt(rcvpkt)
extract(rcvpkt,data)
deliver_data(data)
udt_send(ACK)
extract(rcvpkt,data)
deliver_data(data)
sndpkt = make_pkt(ACK, chksum)
udt_send(sndpkt)
receiver:
sender:
• seq
must# added
check iftoreceived
pkt packet is duplicate
state
• two seq.indicates
#’s (0,1)whether 0 or 1 isWhy?
will suffice. expected pkt seq #
note:check
• must receiver can not ACK/NAK
if received know if itscorrupted
last ACK/NAK received OK at sender
• twice as many states
• state must “remember” whether “expected” pkt should have seq # of 0 or 1
U L/R .008
sender = = = 0.00027
RTT + L / R 30.008
Transport
Lecture #Layer
01 3-43
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
U 3L / R .0024
sender = = = 0.00081
RTT + L / R 30.008
Transport
Lecture #Layer
01 3-45
Pipelined protocols: overview
Go-back-N: Selective Repeat:
• sender can have up to N • sender can have up to N
unacked packets in unack’ed packets in
pipeline pipeline
• receiver only sends • rcvr sends individual ack
cumulative ack for each packet
• doesn’t ack packet if
there’s a gap
• sender has timer for • sender maintains timer for
oldest unacked packet each unacked packet
• when timer expires, • when timer expires,
retransmit all unacked retransmit only that
packets unacked packet
Transport Layer 3-46
Go-Back-N: sender
• k-bit seq # in pkt header
• “window” of up to N, consecutive unack’ed pkts allowed
User
types
‘C’
Seq=42, ACK=79, data = ‘C’
host ACKs
receipt of
‘C’, echoes
Seq=79, ACK=43, data = ‘C’ back ‘C’
host ACKs
receipt
of echoed
‘C’ Seq=43, ACK=80
350
RTT (milliseconds) RTT: gaia.cs.umass.edu to fantasia.eurecom.fr
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-62
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)
SendBase=92
Seq=92, 8 bytes of data Seq=92, 8 bytes of data
timeout
timeout
Seq=100, 20 bytes of data
ACK=100
X
ACK=100
ACK=120
SendBase=120
ACK=100
X
ACK=120
cumulative ACK
Transport Layer 3-69
TCP ACK generation [RFC 1122, RFC 2581]
ACK=100
timeout
ACK=100
ACK=100
ACK=100
Seq=100, 20 bytes of data
IP
flow control code
receiver controls sender, so
sender won’t overflow receiver’s
buffer by transmitting too much, from sender
too fast
receiver protocol stack
application application
network network
2-way handshake:
Q: will 2-way handshake always
work in network?
• variable delays
Let’s talk
ESTAB • retransmitted messages (e.g.
OK req_conn(x)) due to message loss
ESTAB
• message reordering
• can’t “see” other side
choose x
req_conn(x)
ESTAB
acc_conn(x)
ESTAB
choose x choose x
req_conn(x) req_conn(x)
ESTAB ESTAB
retransmit acc_conn(x) retransmit acc_conn(x)
req_conn(x) req_conn(x)
ESTAB ESTAB
data(x+1) accept
req_conn(x)
retransmit data(x+1)
data(x+1)
connection connection
client x completes server x completes server
client
terminates forgets x terminates forgets x
req_conn(x)
ESTAB ESTAB
data(x+1) accept
half open connection! data(x+1)
(no client!)
Transport Layer 3-79
TCP 3-way handshake
Socket connectionSocket =
welcomeSocket.accept();
L Socket clientSocket =
SYN(x) newSocket("hostname","port
number");
SYNACK(seq=y,ACKnum=x+1)
create new socket for listen SYN(seq=x)
communication back to client
SYN SYN
rcvd sent
SYNACK(seq=y,ACKnum=x+1)
ESTAB ACK(ACKnum=y+1)
ACK(ACKnum=y+1)
L
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
R/2
delay
lout
Host A
lout
sender sends only when
router buffers available lin R/2
A no buffer space!
Host B
Transport Layer 3-89
Causes/costs of congestion: scenario 2
Idealization: known loss R/2
packets can be lost, dropped
at router due to full buffers when sending at R/2,
some packets are
lout
sender only resends if retransmissions but
packet known to be lost asymptotic goodput
is still R/2 (why?)
lin R/2
Host B
Transport Layer 3-90
Causes/costs of congestion: scenario 2
Realistic: duplicates R/2
packets can be lost, dropped at
router due to full buffers when sending at R/2,
some packets are
lout
sender times out prematurely, retransmissions
including duplicated
sending two copies, both of that are delivered!
which are delivered R/2
lin
lin
timeout
copy lout
l'in
Host B
Transport Layer 3-91
Causes/costs of congestion: scenario 2
Realistic: duplicates R/2
packets can be lost, dropped at
router due to full buffers when sending at R/2,
some packets are
lout
sender times out prematurely, retransmissions
including duplicated
sending two copies, both of that are delivered!
which are delivered R/2
lin
“costs” of congestion:
more work (retrans) for given “goodput”
unneeded retransmissions: link carries multiple copies of pkt
decreasing goodput
Host D
Host C
C/2
lout
lin’ C/2
time
Transport
Lecture #Layer
01 3-99
TCP Congestion Control: details
sender sequence number space
cwnd TCP sending rate:
roughly: send cwnd
bytes, wait RTT for
last byte
ACKed sent, not-
last byte
sent
ACKS, then send more
yet ACKed
(“in-flight”)
bytes
cwnd
sender limits transmission: ~
rate~ bytes/sec
RTT
LastByteSent- < cwnd
LastByteAcked
cwnd is dynamic, function of perceived
network congestion
RTT
loss event:
initially cwnd = 1 MSS two segm
en ts
double cwnd every RTT
done by incrementing
four segm
cwnd for every ACK ents
received
summary: initial rate is
slow but ramps up time
exponentially fast
Transport Layer 3-101
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)
Implementation:
variable ssthresh
on loss event, ssthresh is
set to 1/2 of cwnd just
before loss event
Transport
Lecture #Layer
01 3-104
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
Lecture #Layer
01 3-105
TCP Futures: TCP over “long, fat pipes”
TCP connection 1
bottleneck
router
capacity R
TCP connection 2
Connection 2 throughput
loss: decrease window by factor of 2
congestion avoidance: additive increase
loss: decrease window by factor of 2
congestion avoidance: additive increase
Connection 1 throughput R
Transport Layer 3-108
Fairness (more)
Fairness and UDP Fairness, parallel TCP
multimedia apps often connections
do not use TCP application can open
do not want rate multiple parallel connections
throttled by congestion between two hosts
control
web browsers do this
instead use UDP:
e.g., link of rate R with 9
send audio/video at
constant rate, tolerate existing connections:
packet loss new app asks for 1 TCP, gets rate
R/10
new app asks for 11 TCPs, gets R/2