0% found this document useful (0 votes)
25 views9 pages

Connection Connection - Oriented Oriented Transport: TCP Transport: TCP

TCP provides reliable, in-order byte stream delivery between two endpoints using connection-oriented transport with handshaking, acknowledgments, and retransmissions to ensure all data is received correctly; it uses sequence numbers, acknowledgment numbers, timeouts, and duplicate acknowledgments to track packet delivery and trigger retransmissions when needed to maintain reliability. TCP is implemented on top of the unreliable IP layer to provide reliable end-to-end data transfer for applications.

Uploaded by

Mona Ali
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
25 views9 pages

Connection Connection - Oriented Oriented Transport: TCP Transport: TCP

TCP provides reliable, in-order byte stream delivery between two endpoints using connection-oriented transport with handshaking, acknowledgments, and retransmissions to ensure all data is received correctly; it uses sequence numbers, acknowledgment numbers, timeouts, and duplicate acknowledgments to track packet delivery and trigger retransmissions when needed to maintain reliability. TCP is implemented on top of the unreliable IP layer to provide reliable end-to-end data transfer for applications.

Uploaded by

Mona Ali
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 9

Computer Networks

Connection-Oriented
Connection-
Transport: TCP

Based on Computer Networking, 4th Edition by Kurose and Ross

Stan Kurkovsky

TCP: Overview
point
point--to-
to-point: full duplex data:
one sender, one receiver bi
bi--directional data flow in same
in-order byte steam:
reliable, in- connection
no message boundaries MSS: maximum segment size
pipelined: connection
connection--oriented:
TCP congestion and flow control handshaking (exchange of
set window size control msgs) inits sender,
receiver state before data
send & receive buffers: exchange
flow controlled:
sender will not overwhelm
receiver

application application
writes data reads data
socket socket
door door
TCP TCP
send buffer receive buffer
segment

Stan Kurkovsky

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

Stan Kurkovsky

TCP seq. #s and ACKs


Seq. #s:
byte stream number
of first byte in
segments data Host A Host B

ACKs: User
types
seq # of next byte C
expected from other host ACKs
side receipt of
C, echoes
cumulative ACK back C
Q: how receiver handles out-
out-
of-
of-order segments host ACKs
A: TCP spec doesnt receipt
say, - up to of echoed
C
implementor

time
simple telnet scenario

Stan Kurkovsky

2
TCP Round Trip Time and Timeout
Q: how to set TCP timeout value?
longer than RTT
but RTT varies
too short: premature timeout
unnecessary retransmissions
too long: slow reaction to segment loss

Q: how to estimate RTT?


SampleRTT:: measured time from segment transmission until ACK receipt
SampleRTT
ignore retransmissions
SampleRTT will vary, want estimated RTT smoother
average several recent measurements, not just current SampleRTT
EstimatedRTT = (1-
(1- )*EstimatedRTT + *SampleRTT
Exponential weighted moving average
influence of past sample decreases exponentially fast
typical value: = 0.125

Stan Kurkovsky

TCP Round Trip Time and Timeout


Setting the timeout
EstimtedRTT plus safety margin
large variation in EstimatedRTT -> larger safety margin
first estimate of how much SampleRTT deviates from EstimatedRTT:
DevRTT = (1-(1-)*DevRTT + *|SampleRTT
*|SampleRTT--EstimatedRTT|
(typically, = 0.25)
Then set timeout interval:
TimeoutInterval = EstimatedRTT + 4*DevRTT

Stan Kurkovsky

3
TCP reliable data transfer
TCP creates rdt service on top of IPs unreliable service
Pipelined segments
Cumulative acks
TCP uses single retransmission timer

Retransmissions are triggered by:


timeout events
duplicate acks
Initially consider simplified TCP sender:
ignore duplicate acks
ignore flow control, congestion control

Stan Kurkovsky

TCP sender events:


data rcvd from app:
Create segment with seq #
seq # is byte-
byte-stream number of first data byte in segment
start timer if not already running (think of timer as for oldest unacked
segment)
expiration interval: TimeOutInterval

timeout:
retransmit segment that caused timeout
restart timer

Ack rcvd:
If acknowledges previously unacked segments
update what is known to be acked
start timer if there are outstanding segments

Stan Kurkovsky

4
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

time time
lost ACK scenario premature timeout

Stan Kurkovsky

TCP retransmission scenarios

Host A Host B
timeout

X
loss

SendBase
= 120

time
Cumulative ACK scenario

Stan Kurkovsky

5
TCP ACK generation

Event at Receiver TCP Receiver action


Arrival of in-
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-
in-order segment with Immediately send single cumulative
expected seq #. One other ACK, ACKing both in-
in-order segments
segment has ACK pending

Arrival of out-
out-of
of--order segment Immediately send duplicate ACK,
ACK,
higher--than
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 startsat lower end of gap

Stan Kurkovsky

Fast Retransmit
Time-
Time-out period often relatively long:
long delay before resending lost packet
Detect lost segments via duplicate ACKs.
Sender often sends many segments back- back-to-
to-back
If segment is lost, there will likely be many duplicate ACKs.

If sender receives 3 ACKs for the same data, it supposes that segment
after ACKed data was lost:
fast retransmit: resend segment before timer expires

Stan Kurkovsky

6
TCP Flow Control
sender wont overflow receivers buffer by transmitting too much, too fast
receive side of TCP connection has a receive buffer:

app process may be slow at reading from buffer


speed-
speed-matching service: matching the send rate to the receiving apps
drain rate

Stan Kurkovsky

TCP Flow control: how it works


(Suppose TCP receiver discards out-
out-of-
of-order segments)
spare room in buffer = RcvWindow
= RcvBuffer
RcvBuffer--[LastByteRcvd - LastByteRead
LastByteRead]]
Rcvr advertises spare room by including value of RcvWindow in
segments
Sender limits unACKed data to RcvWindow
guarantees receive buffer doesnt overflow

Stan Kurkovsky

7
TCP Connection Management

Recall: TCP sender, receiver establish connection before exchanging data


segments
initialize TCP variables: seq. #s buffers, flow control info (e.g.
RcvWindow))
RcvWindow
client: connection initiator
Socket clientSocket = new Socket("hostname","port number");
server: contacted by client
Socket connectionSocket = welcomeSocket.accept();
Three way handshake:
Step 1: client host sends TCP SYN segment to server
specifies initial seq #
no data
Step 2: server host receives SYN, replies with SYNACK segment
server allocates buffers
specifies server initial seq. #
Step 3: client receives SYNACK, replies with ACK segment, which may
contain data
Stan Kurkovsky

TCP Connection Management (cont.)

Closing a connection:
client server
client closes socket:
clientSocket.close(); close

Step 1: client end system sends


TCP FIN control segment to
close
server

Step 2: server receives FIN,


timed wait

replies with ACK. Closes


connection, sends FIN.

closed

Stan Kurkovsky

8
TCP Connection Management (cont.)

Step 3: client receives FIN,


replies with ACK. client server

Enters timed wait - will closing


respond with ACK to
received FINs

Step 4: server
server,, receives ACK. closing
Connection closed.

Note: with small modification, can

timed wait
handle simultaneous FINs.
closed

closed

Stan Kurkovsky

TCP Connection Management (cont)

TCP server
lifecycle

TCP client
lifecycle

Stan Kurkovsky

You might also like