CS F303 (Computer Networks) : Vishal Gupta

Download as pdf or txt
Download as pdf or txt
You are on page 1of 26

CS F303

(Computer Networks)
Vishal Gupta
Department of Computer Science and Information Systems
BITS Pilani Birla Institute of Technology and Science
Pilani|Dubai|Goa|Hyderabad
Pilani Campus, Pilani
BITS Pilani
Pilani|Dubai|Goa|Hyderabad

Agenda: TCP
TCP: Overview RFCs: 793,1122,1323, 2018, 2581

• point-to-point:  full duplex data:


– one sender, one receiver  bi-directional data flow in
same connection
• reliable, in-order byte  MSS: maximum segment
steam: size
– no “message  connection-oriented:
boundaries”  handshaking (exchange of
control msgs) inits sender,
• pipelined: receiver state before data
– TCP congestion and flow exchange
control set window size  flow controlled:
 sender will not
overwhelm receiver

Transport Layer 3-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
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)

Transport Layer 3-4


BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
TCP seq. numbers, ACKs
outgoing segment from sender
sequence numbers: source port # dest port #
sequence number
–byte stream “number” of acknowledgement number
rwnd
first byte in segment’s checksum urg pointer
data window size
N
acknowledgements:
–seq # of next byte
expected from other side sender sequence number space

–cumulative ACK sent sent, not- usable not


ACKed yet ACKed but not usable
Q: how receiver handles out- (“in- yet sent
of-order segments flight”)
incoming segment to sender
–A: TCP spec doesn’t say, - source port # dest port #

up to implementor sequence number


acknowledgement number
A rwnd
checksum urg pointer

Transport Layer 3-5


TCP seq. numbers, ACKs
Host A Host B

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

simple telnet scenario

Transport Layer 3-6


Chapter 3 outline
3.1 transport-layer 3.5 connection-oriented
services transport: TCP
3.2 multiplexing and  segment structure
demultiplexing  reliable data transfer
3.3 connectionless  flow control
transport: UDP  connection management

3.4 principles of reliable 3.6 principles of congestion


data transfer control
3.7 TCP congestion control

Transport Layer 3-7


Connection Management
before exchanging data, sender/receiver “handshake”:
• agree to establish connection (each knowing the other willing
to establish connection)
• agree on connection parameters
application application

connection state: ESTAB connection state: ESTAB


connection variables: connection Variables:
seq # client-to-server seq # client-to-server
server-to-client server-to-client
rcvBuffer size rcvBuffer size
at server,client at server,client

network network

Socket clientSocket = Socket connectionSocket =


newSocket("hostname","port welcomeSocket.accept();
number");

Transport Layer 3-8 BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
TCP 3-way handshake

client state server state


LISTEN LISTEN
choose init seq num, x
send TCP SYN msg
SYNSENT SYNbit=1, Seq=x
choose init seq num, y
send TCP SYNACK
msg, acking SYN SYN RCVD
SYNbit=1, Seq=y
ACKbit=1; ACKnum=x+1
received SYNACK(x)
ESTAB indicates server is live;
send ACK for SYNACK;
this segment may contain ACKbit=1, ACKnum=y+1
client-to-server data
received ACK(y)
indicates client is live
ESTAB

Transport Layer 3-9


TCP: closing a connection
client, server each close their side of connection
 send TCP segment with FIN bit = 1
respond to received FIN with ACK
 on receiving FIN, ACK can be combined with own FIN
simultaneous FIN exchanges can be handled

Transport Layer 3-10


TCP: closing a connection
client state server state
ESTAB ESTAB
clientSocket.close()
FIN_WAIT_1 can no longer FINbit=1, seq=x
send but can
receive data CLOSE_WAIT
ACKbit=1; ACKnum=x+1
can still
FIN_WAIT_2 wait for server send data
close

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

Transport Layer 3-11


Chapter 3 outline
3.1 transport-layer 3.5 connection-oriented
services transport: TCP
3.2 multiplexing and  segment structure
demultiplexing  reliable data transfer
3.3 connectionless  flow control
transport: UDP  connection management

3.4 principles of reliable 3.6 principles of congestion


data transfer control
3.7 TCP congestion control

Transport Layer 3-12


TCP reliable data transfer
• TCP creates rdt service
on top of IP’s unreliable
service
– pipelined segments
– cumulative acks
let’s initially consider
simplified TCP sender:
– single retransmission
timer – ignore duplicate acks
– ignore flow control,
• retransmissions congestion control
triggered by:
– timeout events
– duplicate acks

Transport Layer 3-13


TCP sender events:
data rcvd from app: timeout:
 create segment with  retransmit segment that
seq # caused timeout
 seq # is byte-stream  restart timer
number of first data ack rcvd:
byte in segment  if ack acknowledges
 start timer if not already previously unacked
running segments
 think of timer as for  update what is known to
oldest unacked segment be ACKed
 expiration interval:  start timer if there are
TimeOutInterval still unacked segments

Transport Layer 3-14


TCP sender (simplified)
data received from application above
create segment, seq. #: NextSeqNum
pass segment to IP (i.e., “send”)
NextSeqNum = NextSeqNum + length(data)
if (timer currently not running)
L start timer
NextSeqNum = InitialSeqNum wait
SendBase = InitialSeqNum for
event timeout
retransmit not-yet-acked segment
with smallest seq. #
start timer
ACK received, with ACK field value y
if (y > SendBase) {
SendBase = y
/* SendBase–1: last cumulatively ACKed byte */
if (there are currently not-yet-acked segments)
start timer
else stop timer
} Transport Layer 3-15
TCP: retransmission scenarios
Host A Host B Host A Host B

SendBase=92
Seq=92, 8 bytes of data Seq=92, 8 bytes of data

Seq=100, 20 bytes of data


timeout

timeout
ACK=100
X
ACK=100
ACK=120

Seq=92, 8 bytes of data Seq=92, 8


SendBase=100 bytes of data
SendBase=120
ACK=100
ACK=120

SendBase=120

lost ACK scenario premature timeout


Transport Layer 3-16
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
TCP: retransmission scenarios
Host A Host B

Seq=92, 8 bytes of data

Seq=100, 20 bytes of data


timeout

ACK=100
X
ACK=120

Seq=120, 15 bytes of data

cumulative ACK
Transport Layer 3-17
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
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

Transport Layer 3-18


BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
TCP fast retransmit
time-out period often
relatively long: TCP fast retransmit
 long delay before if sender receives 3
resending lost packet ACKs for same data
detect lost segments (“triple
(“triple duplicate
duplicate ACKs”),
ACKs”),
via duplicate ACKs. resend unacked
 sender often sends segment with smallest
many segments back- seq #
to-back  likely that unacked
 if segment is lost, segment lost, so don’t
there will likely be wait for timeout
many duplicate ACKs.

Transport Layer 3-19


TCP fast retransmit
Host A Host B

Seq=92, 8 bytes of data


Seq=100, 20 bytes of data
X

ACK=100
timeout

ACK=100
ACK=100
ACK=100
Seq=100, 20 bytes of data

fast retransmit after sender


receipt of triple duplicate
Transport Layer ACK 3-20
BITS Pilani, Deemed to be University under Section 3 of UGC Act, 1956
TCP round trip time, timeout
Q: how to set TCP Q: how to estimate RTT?
timeout value? • SampleRTT: measured
longer than RTT time from segment
transmission until ACK
 but RTT varies
receipt
too short: premature – ignore retransmissions
timeout, unnecessary
• SampleRTT will vary, want
retransmissions
estimated RTT “smoother”
too long: slow – average several recent
reaction to segment measurements, not just
loss current SampleRTT

Transport Layer 3-21


TCP round trip time, timeout
EstimatedRTT = (1- )*EstimatedRTT + *SampleRTT
 exponential weighted moving average
 influence of past sample decreases exponentially fast
 typical value:  = 0.125 RTT: gaia.cs.umass.edu to fantasia.eurecom.fr

350

RTT: gaia.cs.umass.edu to fantasia.eurecom.fr


RTT (milliseconds)

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-22
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)

TimeoutInterval = EstimatedRTT + 4*DevRTT

estimated RTT “safety margin”

Transport Layer 3-23


TCP flow control
application
application may process
remove data from application
TCP socket buffers ….
TCP socket OS
receiver buffers
… slower than TCP
receiver is delivering
(sender is sending) TCP
code

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

Transport Layer 3-24


TCP flow control
• receiver “advertises” free
buffer space by including to application process
rwnd value in TCP header of
receiver-to-sender segments RcvBuffer buffered data
– RcvBuffer size set via
socket options (typical default
is 4096 bytes)
rwnd free buffer space
– many operating systems
autoadjust RcvBuffer
TCP segment payloads
• sender limits amount of
unacked (“in-flight”) data to
receiver-side buffering
receiver’s rwnd value
• guarantees receive buffer will
not overflow
Transport Layer 3-25
BITS Pilani
Pilani|Dubai|Goa|Hyderabad

You might also like