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

tcp1

TCP (Transmission Control Protocol) is a reliable, connection-oriented protocol that provides full duplex data transmission and ensures in-order delivery of byte streams. It uses a three-way handshake for connection establishment and employs flow control mechanisms like sliding windows to manage data transmission rates. TCP also includes error control features to detect and manage lost, corrupted, or out-of-order segments.

Uploaded by

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

tcp1

TCP (Transmission Control Protocol) is a reliable, connection-oriented protocol that provides full duplex data transmission and ensures in-order delivery of byte streams. It uses a three-way handshake for connection establishment and employs flow control mechanisms like sliding windows to manage data transmission rates. TCP also includes error control features to detect and manage lost, corrupted, or out-of-order segments.

Uploaded by

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

TCP: Overview RFCs: 793, 1122, 1323,

2018, 2581

 point-to-point:  full duplex data:


 one sender, one  bi-directional data flow
receiver in same connection
 reliable, in-order byte  MSS: maximum

steam: segment size


 no “message  connection-oriented:
boundaries”  handshaking (exchange
 pipelined: of control msgs) init’s
sender, receiver state
 TCP congestion and flow
before data exchange
control set window size
 flow controlled:
 send
application & receive buffers
w rites data
application
reads data
 sender will not
sock et sock et
door
TCP TCP
door overwhelm receiver
send buffer receive buffer
segm ent

Transport Layer 3-1


Stream delivery service
 TCP is a stream
oriented protocol
 TCP allows the
sending process to
deliver data as a
stream of bytes
and the receiving
process to obtain
data as a stream
of bytes
 Imaginary tube
Transport Layer 3-2
Sending and Receiving
Buffers
 Sending & Receiving Process may
not produce and consume data at
the same speed, TCP needs
buffer, for each direction

Transport Layer 3-3


Bytes and Segments
 TCP groups a number of bytes together
into a packet called segment
 TCP add header to each segment and
delivers the segment to the IP layer for
transmission.

Transport Layer 3-4


Full Duplex and Connection
Oriented
 Data can flow in  Establishment of
both directions at Connection
the same time.  Exchange Data
 Connection
termination

Transport Layer 3-5


Reliable Service
 TCP uses
acknowledgment
mechanism to
check the safe
and sound arrival
of data

Transport Layer 3-6


Numbering Bytes
 Although TCP  It has two fields
software keeps  Sequence
track of the Number
segment being  Acknowledgemen
transmitted or t Number
received, there is
no field for a
segment number
value

Transport Layer 3-7


Byte Numbers
 TCP numbers all data
bytes that are transmitted
in a connection.
 The bytes of data being
transferred in each
connection are numbered
by TCP. The numbering
starts with a randomly
generated number.

Transport Layer 3-8


Sequence number
 The value of the
sequence number
field in a segment
defines the
number of the
first data byte
contained in that
segment.

Transport Layer 3-9


Example
 The following shows the
 Imagine a TCP
sequence number for each
connection is segment:
transferring a file of  Segment 1 ==>
6000 bytes. The first sequence number: 10,010
byte is numbered (range: 10,010 to 11,009)
10,010. What are the  Segment 2 ==>
sequence numbers for sequence number: 11,010
(range: 11,010 to 12,009)
each segment if data  Segment 3 ==>
are sent in five sequence number: 12,010
segments with the first (range: 12,010 to 13,009)
four segments carrying  Segment 4 ==>
1000 bytes and the sequence number: 13,010
last segment carrying (range: 13,010 to 14,009)
 Segment 5 ==>
2000 bytes?
sequence number: 14,010
(range: 14,010 to 16,009)
Transport Layer 3-10
Acknowledgment Number
 Each party numbers the  The value of the
byte, usually with a
different starting byte
acknowledgment
number. field in a segment
 Sequence no. in each defines the number
direction shows the number of the next byte a
of the 1st byte that the
party expects to receive.
party expects to
 Acknowledgment is
receive.
cumulative, which means The acknowledgment
that the receiver takes the number is
number of the last byte
that it has received, safe cumulative.
and adds 1 to it, and
announces this sum as the
acknowledgement number.
Transport Layer 3-11
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 (not segments!)
U A Pnumber
head not
PSH: push data now len used
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)

Transport Layer 3-12


 Header length (4 bit)
 Urgent pointer
 Indicates the number  Valid only if urg flag is
of 4 byte word in the set, is used when
TCP header segment contains urgent
 Length of a header can data.
be between 20 and 60  No. is added to the
bytes sequence number to
 Window size (16 bit) obtain the number of the
last urgent byte in the
(receive window) data section of the
 Size of the window, segment.
that the other party  Options
must maintain  Can be upto 40 bytes of
optional information in
the TCP header
Transport Layer 3-13
Connection Establishment
 3 Way Handshake
 Client sends the 1st segment, a SYN segment
 Segment includes the s/c & d/n port no.
 Segment also contains the client Initialization
sequencee no. used for numbering the bytes
of data sent from client to server.
 Server respond with 2nd segment, a SYN and
ACK segment
 Client sends the 3rd segment. Which is an
ACK Segment, which is receipt of 2nd
segment. Data can be sent with 3rd packet.

Transport Layer 3-14


Transport Layer 3-15
Connection Termination
 Any of the two parties involved in exchanging
data can close the connection.
 Client sends the first segment, a FIN segment
 Server TCP sends the second segment, an ACK
segment, to confirm the receipt of the FIN
segment from client.
 Server TCP can continue sending data in the
server – client direction. When it does not have
any more data to send, it sends 3rd segment.
Segment is FIN segment
 Client TCP sends 4th segment, an ACK segment,
to confirm the receipt of FIN segment from the
TCP server.
Transport Layer 3-16
Transport Layer 3-17
Connection Resetting
 Resetting means the current connection is
destroyed.
 3 cases
 TCP on one sided has requested a connection
to a nonexistent port. TCP on the other side
may send a segment with its RST bit set to
annul the request
 One TCP may want to abort the connection
due to abnormal situation. It can send RST
segment to close the connection.
 TCP on one side may discover that the TCP
on the other side has been idle for a long
time. Transport Layer 3-18
State Transition Diagram

Transport Layer 3-19


TCP States
 During the life of TCP connection, TCP protocol makes
transitions through various TCP states
 Client TCP begins in the closed state.
 Application on the client side initiates a new TCP
connection
 This causes the client to send a SYN segment to TCP in
the server.
 After having sent the SYN segment, the client enters
the SYN_SENT State, the client TCP waits for a segment
from the server TCP that includes an
acknowledgement for the client previous segment and
SYN bit set to 1
 Having received such a segment, the client TCP enters
the ESTABLISHED state.
 While in the ESTABLISHED state the client TCP can
send and receive TCP segments containing application
Transport Layer 3-20
generated data.
Transport Layer 3-21
 Client TCP to send a TCP segment with the FIN bit set
to 1 and to enter the FIN_WAIT_1 state.
 While in FIN_WAIT_1 state, the client TCP waits for a
TCP segment from the serer with an
acknowledgement.
 When it receives this segment , the client enters the
FIN_WAIT_2 state.
 While in FIN_WAIT_2 state, the client waits for another
segment from the server with the FIN bit set to 1; after
receiving the segment, the client TCP acknowledges
the server’s segment and enters the TIME_WAIT state
 The TIME_WAIT state lets the TCP client resend the
final acknowledgment in case the ACK is lost.
 The time spent in the TIME_WAIT state is
implementation dependent, but typical values are 30
sec, 1 min and 2 min.
Transport Layer 3-22
 After the wait, connection formally closes and all
Transport Layer 3-23
FLOW CONTROL
 Flow control defines  Solution
the amount of data a  It defines a window
source can send before
receiving an that is imposed on
acknowledgment from buffer of data
the destination. delivered from the
 Extreme cases application program
 1 byte of data and wait and is ready to be
for ack before sending sent.
the next byte  TCP send as many
 Can send all the data it data as are defined
has without worrying by the sliding
about ack. window protocol
Transport Layer 3-24
Sliding window protocol
 Both host use a  Window is called
window for each a sliding window
new connection. because it can
 Window spans a
slide over the
portion of the buffer buffer as data and
containing bytes acknowledgments
that a host can send
are sent and
before worrying
about an received
acknowledgement
from the other host.

Transport Layer 3-25


A sliding window is used to make
transmission more
efficient as well as to control the flow of
data so that the destination
does not become overwhelmed with data.
TCP’s sliding windows are byte oriented.
Sender buffer
Receiver window

Total size of receiving buffer is N and M locations are


already occupied, then only N-M bytes can be
received
Sender buffer and sender window
Sliding the sender window
Expanding the sender window
In TCP, the sender window
size is totally controlled
by the receiver window value.
However, the actual window size
can be smaller if there is
congestion in the network.
Some Points about TCP’s Sliding Windows:
1. The source does not have to send a
full window’s worth of data.
2.The size of the window can be
Increase or decreased by the destination.
3. The destination can send an
acknowledgment at any time.
Silly Window Syndrome
(created by sender)
 For a 1 byte of data  Solution is Naggle
segment of 41 Algorithm
bytes are created
that travels
through.
 Huge Overhead
 Soln
 TCP must be forced
to wait.
 How long?

Transport Layer 3-34


Naggle Algorithm
 Step 2 is repeated
 Sending TCP sends the 1 st

piece of data it recieves for the rest of the


from the sending transmission.
application program even  Elegance of Naggle
if it is of 1 byte
 After sending 1st segment
algo lies in its
TCP must accumulate
simplicity and in fact
data in the output buffer that it takes into
and waits until either the account the speed of
receiving TCP sends application program
acknowledgement or
that creates the data
enough data have
accumulated to fill and speed of the
Maximum size segment. network that
At this time TCP can send transports the data
next segment
Transport Layer 3-35
Syndrome created by
reciever
 Silly window
syndrome is
created if an
application
program consumes
data slowly, for eg
1 byte at a time

Transport Layer 3-36


Clark’s Solution
 Clark solution is to
send an
acknowledgement as
soon as data arrive,
but to announce a
window of size zero
until there is enough
space to
accommodate a
segment of a
maximum size or
until one half of the
buffer is empty
Transport Layer 3-37
Delayed Acknowledgement
 Another solution is to  Delayed ack
delay sending the prevents the sending
acknowledgement TCP from sliding its
 That is if segment window.
arrives, it is not  After it has sent the
acknowledgment
data in the window,
immediately.
it stops. This kill
 Receiver waits until
syndrome
there is a decent
 It reduces traffic
amount of space in its
incoming buffer before  Ack should not be
acknowledging the delayed by more
arrived segments than 500ms.
Transport Layer 3-38
Normal Data Flow

Transport Layer 3-39


Transport Layer 3-40
Error Control
 Error control in  Tools used
TCP includes  Checksum,
mechanism for acknowledgement
detecting and time out.
corrupted
segment, lost
 No Negative
segment, out of
order segments, acknowledgement
and duplicated in TCP
segments

Transport Layer 3-41


Figure 12-
13 Corrupted segment
Figure 12-14
Lost segment
Duplicate segment
 Packet arrives
that contains the
same sequence
no. as another
receieved
segment, the
destination TCP
simply discards it

Transport Layer 3-44


Out of Order segment
 TCP does not
acknowledge an out of
 Duplicates will be
order segment until it
receives all segments discarded by
that precede it. destination TCP
 If the
acknowledgement is
delayed, the time of
the out or order
segment may mature
at the source TCP and
the segment may be
resent.
Transport Layer 3-45
Figure 12-15
Lost acknowledgment
TCP Congestion Control
Congestion:  manifestations:
 informally: “too  lostpackets
many sources (buffer overflow at
sending too much routers)
data too fast for  long delays
network to handle” (queueing in
 different from flow router buffers)
control!

Transport Layer 3-47


Approaches towards congestion
control
Two broad approaches towards congestion
control:
End-end congestion Network-assisted
control: congestion control:
 no explicit feedback from  routers provide feedback
network to end systems
 congestion inferred from  single bit indicating
end-system observed congestion
loss, delay
 approach taken by TCP

Transport Layer 3-48


TCP assumes that the cause of
a lost segment is due to
congestion in the network.
If the cause of the lost segment
is congestion,
retransmission of the segment
not only does not remove the cause,
it aggravates it.
Slow Start
 Some intermediate  TCP is now required
router must queue to support an
the packets, and it's algorithm called slow
possible for that start.
router to run out of  It operates by
space. observing that the
rate at which new
packets should be
injected into the
network is the rate
at which the
acknowledgments
are returned by the
other end.

Transport Layer 3-51


 Slow start adds  Each time an ACK is
another window to received, the congestion
the sender's TCP: the window is increased by
congestion window, one segment, (cwnd is
called cwnd. maintained in bytes, but
slow start always
 When a new increments it by the
connection is segment size.)
established with a  The sender can transmit
host on another up to the minimum of
network, the the congestion window
congestion window is and the advertised
window.
initialized to one  The congestion window
segment. is flow control imposed
by the sender, while the
advertised window is
flow control imposed by
the receiver.

Transport Layer 3-52


 The sender starts by
transmitting one  At some point the
segment and waiting capacity of the
for its ACK. When that internet can be
ACK is received, the
congestion window is
reached, and an
incremented from one intermediate
to two, and two router will start
segments can be discarding
sent. When each of packets.
those two segments is
acknowledged, the  This tells the
congestion window is sender that its
increased to four. This congestion
provides an
exponential increase.
window has
gotten too large.
Transport Layer 3-53
TCP Slow Start (more)
 When connection Host A Host B
begins, increase rate
one s e gm
exponentially until ent

RTT
first loss event:
two segm
 double CWin every en ts
RTT
 done by incrementing
four segm
CWin for every ACK ents
received
 Summary: initial rate
is slow but ramps up
exponentially fast time

Transport Layer 3-54


Congestion Avoidance Algo
 Congestion avoidance  There are two
is a way to deal with indications of
lost packets. packet loss:
 The assumption of a timeout
the algorithm is that occurring and
packet loss caused by  the
damage is very small receipt of
(much less than 1%), duplicate ACKs.
therefore the loss of a
packet signals
congestion
somewhere in the
network between the
source and
destination.
Transport Layer 3-55
 Congestion avoidance  Congestion avoidance
and slow start are and slow start require
independent
algorithms with that two variables be
different objectives. maintained for each
 But when congestion connection:
occurs we want to slow  a congestion window,
down the transmission
rate of packets into the cwnd,
network, and then  and a slow start
invoke slow start to threshold size,
get things going again.
In practice they are ssthresh.
implemented together.  The combined
algorithm operates as
follows:
Transport Layer 3-56
 Initialization for a  Congestion
given connection Avoidance is based
sets cwnd to one on the sender's
segment and
ssthresh to 65535 assessment of
bytes. perceived network
 The TCP output congestion; the
routine never advertised window
sends more than is related to the
the minimum of amount of available
cwnd and the buffer space at the
receiver's receiver for this
advertised
window. connection.
Transport Layer 3-57
 When congestion  Additionally, if the
occurs (indicated by congestion is
a timeout or the
reception of duplicate
indicated by a
ACKs), one-half of the timeout, cwnd is
current window size set to one
(the minimum of segment (i.e.,
cwnd and the slow start).
receiver's advertised
window, but at least
two segments) is
saved in ssthresh.

Transport Layer 3-58


 When new data is  Slow start continues
acknowledged by the until we're halfway to
other end, we where we were when
increase cwnd, but congestion occurred
the way it increases (since we recorded
depends on whether half of the window
we're performing size that got us into
slow start or trouble in step 2), and
congestion then congestion
avoidance. avoidance takes over.
 If cwnd is less than or  Slow start has cwnd
equal to ssthresh, start at one segment,
we're doing slow and be incremented
start; otherwise we're by one segment every
doing congestion time an ACK is
avoidance. received.
Transport Layer 3-59
 Congestion  We want to increase
avoidance dictates cwnd by at most one
that cwnd be segment each round-
incremented by trip time (regardless
1/cwnd each time
an ACK is how many ACKs are
received. received in that
 This is an additive RTT), whereas slow
increase, start will increment
compared to slow cwnd by the number
start's exponential of ACKs received in a
increase. round-trip time

Transport Layer 3-60


AIMD
 On detecting congestion, set cwnd to
half the
 window size (multiplicative decrease)
 On each ack of new data, increase cwnd
by
 1/cwnd (additive increase)
Summary: TCP Congestion Control
 When CongWin is below Threshold, sender in
slow-start phase, window grows exponentially.
 When CongWin is above Threshold, sender is
in congestion-avoidance phase, window grows
linearly.
 When a triple duplicate ACK occurs, Threshold
set to CongWin/2 and CongWin set to
Threshold.
 When timeout occurs, Threshold set to
CongWin/2 and CongWin is set to 1 MSS.
Transport Layer 3-64
TCP congestion control: additive
increase, multiplicative decrease
 Approach: increase transmission rate (window
size), probing for usable bandwidth, until loss
occurs
 additive increase: increase CongWin by 1
MSS every RTT until loss detected
 multiplicative decrease: cut CongWin in halfcongestion
window

after loss
congestion window size

24 K bytes

Saw tooth
16 K bytes
behavior: probing
for bandwidth
8 K bytes

time
time

Transport Layer 3-65

You might also like