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

ACCSE CSC2B10-Chapter 3 4

Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views

ACCSE CSC2B10-Chapter 3 4

Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 27

CSC2B10/CSC02B2

Data Communications

Chapter 3.4
Chapter 3 outline

3.1 Transport-layer services 3.5 Connection-oriented


3.2 Multiplexing and demultiplexing transport: TCP
3.3 Connectionless transport: UDP • segment structure
• reliable data transfer
3.4 Principles of reliable data
• flow control
transfer
• connection management
3.6 Principles of congestion
control
3.7 TCP congestion control

2
TCP: Overview RFCs: 793, 1122, 1323, 2018, 2581
• point-to-point: • full duplex data:
• one sender, one receiver • bi-directional data flow in same
• reliable, in-order byte steam: connection
• no “message boundaries” • MSS: maximum segment size
• pipelined: • connection-oriented:
• TCP congestion and flow control • handshaking (exchange of control
set window size msgs) inits sender, receiver state
• send & receive buffers before data exchange
application
writes data
application
reads data
• flow controlled:
socket socket
door
TCP
send buffer
TCP
receive buffer
door
• sender will not overwhelm receiver
segment

3
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
UA P R S F Receive window
(generally not used) # bytes
checksum Urg data pnter
rcvr willing
RST, SYN, FIN: to accept
Options (variable length)
connection estab
(setup, teardown
commands)
application
Internet data
checksum (variable length)
(as in UDP)

4
TCP seq. #’s and ACKs

Seq. #’s: Host A Host B


• byte stream “number” of
User
first byte in segment’s types
data ‘C’
host ACKs
ACKs: receipt of
‘C’, echoes
• seq # of next byte back ‘C’
expected from other side
• cumulative ACK host ACKs
receipt
Q: how receiver handles of echoed
out-of-order segments ‘C’

• A: TCP spec doesn’t say,


- up to implementor time
simple telnet scenario

5
TCP Round Trip Time and Timeout
Q: how to set TCP Q: how to estimate RTT?
• SampleRTT: measured time from
timeout value?
segment transmission until ACK
• longer than RTT receipt
• but RTT varies • ignore retransmissions
• too short: premature • SampleRTT will vary, want estimated
timeout RTT “smoother”
• average several recent
• unnecessary
measurements, not just current
retransmissions SampleRTT
• too long: slow reaction
to segment loss
6
TCP Round Trip Time and Timeout
EstimatedRTT = (1- α)*EstimatedRTT + α*SampleRTT

 Exponential weighted moving average


 influence of past sample decreases exponentially fast
 typical value: α = 0.125

7
Example RTT estimation:
RTT: gaia.cs.umass.edu to fantasia.eurecom.fr

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)

SampleRTT Estimated RTT

8
TCP Round Trip Time and Timeout
Setting the timeout
• EstimatedRTT plus “safety margin”
• large variation in EstimatedRTT -> larger safety margin
• first estimate of how much SampleRTT deviates from
EstimatedRTT:
DevRTT = (1-β)*DevRTT +
β*|SampleRTT-EstimatedRTT|

(typically, β = 0.25)

Then set timeout interval:

TimeoutInterval = EstimatedRTT + 4*DevRTT

9
Chapter 3 outline

3.1 Transport-layer services 3.5 Connection-oriented


3.2 Multiplexing and demultiplexing transport: TCP
3.3 Connectionless transport: UDP • segment structure
• reliable data transfer
3.4 Principles of reliable data
• flow control
transfer
• connection management
3.6 Principles of congestion
control
3.7 TCP congestion control

10
TCP reliable data transfer

• TCP creates rdt service on top of • retransmissions are triggered by:


IP’s unreliable service • timeout events
• pipelined segments • duplicate acks

• cumulative acks • initially consider simplified TCP


• TCP uses single retransmission sender:
• ignore duplicate acks
timer
• ignore flow control, congestion control

11
TCP sender events:
data rcvd from app: timeout:
• Create segment with seq • retransmit segment that
# caused timeout
• seq # is byte-stream • restart timer
number of first data byte Ack rcvd:
in segment • If acknowledges
• start timer if not already previously unacked
running (think of timer as segments
for oldest unacked • update what is known to be
segment) acked

• expiration interval: • start timer if there are


outstanding segments
TimeOutInterval
12
NextSeqNum = InitialSeqNum
SendBase = InitialSeqNum

loop (forever) { TCP


switch(event)
sender
event: data received from application above (simplified)
create TCP segment with sequence number NextSeqNum
if (timer currently not running)
start timer
pass segment to IP Comment:
NextSeqNum = NextSeqNum + length(data)
• SendBase-1: last
event: timer timeout cumulatively
retransmit not-yet-acknowledged segment with acked byte
smallest sequence number Example:
start timer • SendBase-1 = 71;
y= 73, so the rcvr
event: ACK received, with ACK field value of y wants 73+ ;
if (y > SendBase) { y > SendBase, so
SendBase = y
that new data is
if (there are currently not-yet-acknowledged segments)
start timer acked
}

} /* end of loop forever */ 13


TCP: retransmission scenarios
Host A Host B Host A Host B

Seq=92 timeout
timeout
X
loss

SendBase
= 100

Seq=92 timeout
SendBase
= 120

SendBase
= 100 SendBase
= 120 premature timeout
time time
lost ACK scenario
14
TCP retransmission scenarios (more)
Host A Host B

timeout
X
loss

SendBase
= 120

time
Cumulative ACK scenario

15
TCP ACK generation [RFC 1122, RFC 2581]

Event at Receiver TCP Receiver action


Arrival of in-order segment with Delayed ACK. Wait up to 500ms
expected seq #. All data up to for next segment. If no next segment,
expected seq # already ACKed send ACK

Arrival of in-order segment with Immediately send single cumulative


expected seq #. One other ACK, ACKing both in-order segments
segment has ACK pending

Arrival of out-of-order segment Immediately send duplicate ACK,


higher-than-expect seq. # . indicating seq. # of next expected byte
Gap detected

Arrival of segment that Immediate send ACK, provided that


partially or completely fills gap segment starts at lower end of gap

16
Host A Host B

timeout

time
Figure 3.37 Resending a segment after triple duplicate ACK
17
Fast Retransmit

• time-out period often relatively • if sender receives 3 ACKs


long: for the same data, it
• long delay before resending lost packet supposes that segment
• detect lost segments via duplicate after ACKed data was lost:
ACKs. • fast retransmit: resend
• sender often sends many segments segment before timer expires
back-to-back
• if segment is lost, there will likely be
many duplicate ACKs.

18
Fast retransmit algorithm:

event: ACK received, with ACK field value of y


if (y > SendBase) {
SendBase = y
if (there are currently not-yet-acknowledged segments)
start timer
}
else {
increment count of dup ACKs received for y
if (count of dup ACKs received for y = 3) {
resend segment with sequence number y
}

a duplicate ACK for fast retransmit


already ACKed segment

19
Chapter 3 outline

3.1 Transport-layer services • 3.5 Connection-oriented


3.2 Multiplexing and demultiplexing transport: TCP
3.3 Connectionless transport: UDP • segment structure
• reliable data transfer
3.4 Principles of reliable data
• flow control
transfer
• connection management
3.6 Principles of congestion
control
3.7 TCP congestion control

20
TCP Flow Control
flow control
sender won’t overflow
• receive side of TCP receiver’s buffer by
connection has a receive transmitting too much,
too fast
buffer:

• speed-matching service:
matching the send rate to
the receiving app’s drain
rate
 app process may be
slow at reading from
buffer
21
TCP Flow control: how it works

• rcvr advertises spare room


by including value of
RcvWindow in segments
• sender limits unACKed
(suppose TCP receiver data to RcvWindow
discards out-of-order • guarantees receive buffer
segments) doesn’t overflow
• spare room in buffer
= RcvWindow
= RcvBuffer-[LastByteRcvd -
LastByteRead]
22
Chapter 3 outline

3.1 Transport-layer services 3.5 Connection-oriented


3.2 Multiplexing and demultiplexing transport: TCP
3.3 Connectionless transport: UDP • segment structure
• reliable data transfer
3.4 Principles of reliable data
• flow control
transfer
• connection management
3.6 Principles of congestion
control
3.7 TCP congestion control

23
TCP Connection Management
Recall: TCP sender, receiver Three way handshake:
establish “connection” before
exchanging data segments Step 1: client host sends TCP SYN
• initialize TCP variables: segment to server

• seq. #s • specifies initial seq #

• buffers, flow control info (e.g. • no data


RcvWindow) Step 2: server host receives SYN,
• client: connection initiator replies with SYNACK segment
Socket clientSocket = new • server allocates buffers
Socket("hostname","port
• specifies server initial seq. #
number");
Step 3: client receives SYNACK,
• server: contacted by client
replies with ACK segment, which
Socket connectionSocket =
welcomeSocket.accept();
may contain data

24
TCP Connection Management (cont.)
Closing a connection: client server

close
client closes socket:
clientSocket.close();
close
Step 1: client end system
sends TCP FIN control
segment to server

timed wait
Step 2: server receives FIN,
replies with ACK. Closes
closed
connection, sends FIN.

25
TCP Connection Management (cont.)
Step 3: client receives FIN, client server

replies with ACK. closing

• Enters “timed wait” - will


respond with ACK to received
closing
FINs

Step 4: server, receives ACK.

timed wait
Connection closed.
closed
Note: with small modification,
can handle simultaneous FINs. closed

26
TCP Connection Management (cont)

TCP server
lifecycle

TCP client
lifecycle

27

You might also like