You are on page 1of 75

Reliable & Connection-Oriented

Protocol in Transport Layer


Transmission Control Protocol (TCP)

Computer Networks
IT3001
Prof. Ayaskanta Mishra
Overview
• What is TCP?
• Services provided by TCP
– TCP Bytes, Sequence and ACK Numbering
• TCP Segment Format
– Header , Control Fields
– Pseudo header for Checksum
• TCP Connection Management
1. 3-way handshaking for connection establishment
 SYN flooding Attack
2. Data transfer
3. 3-way /4-way connection teardown (termination)
What is TCP?
• Connection Oriented
• Reliable
• Acknowledgement
• Handshaking ( 3 Phase)
• Common Transport layer protocol in Internet
Services provided by TCP
1. Process to Process Communication
2. Stream delivery service
3. Sending and Receiving Buffer
4. Segments
5. Full duplex communication
6. Multiplexing and De-multiplexing
7. Connection Oriented Service
8. Reliable Service
Services provided by TCP (Cont.)
1.Process to Process Communication
Services provided by TCP (Cont.)
2. Stream delivery service
Services provided by TCP (Cont.)
3. Sending and Receiving Buffer
Services provided by TCP (Cont.)
4. Segments
Services provided by TCP (Cont.)
5. Full duplex communication
Services provided by TCP (Cont.)
6. Multiplexing and De-multiplexing
Services provided by TCP (Cont.)
7. Connection Oriented Service
Services provided by TCP (Cont.)
8. Reliable Service
TCP Numbering System
(Byte Number, Sequence Number, ACK Number)

1. Byte Number

1. Sequence Number : ISN  1st Byte of data


2. ACK Number
Sequence Number & ISN
Example Numerical of Sequence Number
TCP Segment
Format
TCP Connection
1. Connection Establishment
2. Data Transfer
3. Connection Termination
1. Connection Establishment
(3 way handshaking)
3 –Way Handshaking for Connection
Establishment
Network Security & Vulnerability
SYNC flood Attack
• Connection establishment has severe
vulnerability for SYNC flood Attack.
• Malicious Sender sends large numbers of SYN
Segments to server
• Pretending each coming from different clients
• Server presumes clients are Active Open and
allocate resources ( Transfer Control Block- TCB)
and send SYN+ACK  Start Timer to fake clients
 Eventually not Reply
• Hence the resources run out
• DoS Attack  Denial of Service Attack
• Overloads the Server
2. Data Transfer
Pushing Data and Urgent Data
Pushing: Sending data with appropriate (Bytes of
data) and with proper sequence number.
• As per the rwnd- Window Size

Urgent: URG data has to be treated special way


• Inserting Urgent data in beginning of Segment 
Rest of Segment content regular data  Urgent
Pointer Header ( Last byte of Urgent data)
• Sequence #15000 Urgent Pointer 200 then
15000 – 15200 byte Urgent data and rest is
normal data
3. Connection Termination
(3 way handshaking)
3 –Way Handshaking for Connection
Termination/ Teardown

FIN segment does not carry any data and consume no sequence Number
Half-close ( 4-Way Handshaking)
TCP – State Machine
Overview:
• Illustration of the TCP State Transition Diagram
• Significance of TIME, WAIT state and 2MSL
timeout
• MSL – Maximum Segment Life time
– The time for which a Segment will be alive in a
network after that it shall be destroyed.
– Common value is 30 seconds, it can be 1 minute
even 2 minutes
• Demonstration of various state change in a TCP
client/server program through “netstat” command
Time-line diagram for a Common Scenario
TCP State Transition Diagram
Half-Close Scenario
Transition diagram with half-close connection termination
TCP – Flow & Error Control
Overview:
• Significance of send and receive window in
TCP
• What is Flow Control?
– How it works in TCP with Examples.
• What is Error Control?
– How it works in TCP with Examples.
TCP Windows
• There are a pair of window each side 1. Send
Window, 2. Receive window for each
direction of data flow
• In a bi-directional communication scenario
there would be 4 windows a pair both side of
client-server
• A bidirectional scenario is nothing but two
unidirectional communication with
piggybacking implemented
Windows in TCP
1. Send Window
Send Window important points
• Send window opens, closes or shrinks
• Selective Repeat Protocol is implemented with
following key differences:
1. In SR number of packets are in Sliding Window,
however in TCP its bytes of data. Though TCP sends
Segments by Segments, variable is expressed in
bytes
2. In real world implementation TCP can store data
received from the process and send them later,
Assume that TCP sends immediately as soon as
Segment is received from process.
3. Timer: SR has multiple timers for each segments
but in TCP one timer cumulatively for all sent
segments. (restart the same timer when needed)
Windows in TCP
2. Receive Window
Receive Window important points
• TCP used SR protocol for Receive Window with
following key differences:
1. TCP allow process to PULL data in its own pace. Part of
allocated buffer might be occupied by bytes which are
successfully received and ACKNOWLEDGED already.
Receive Window <= Buffer
rwnd = buffer size – number of waiting bytes to be pulled by process
2. In SR the ACK is selective , however in TCP ACK is
cumulative hence do not support out of order bytes. In
this way TCP Rn appear like GBN.
 New version of TCP support both selective as well as
cumulative ACKNOWLEDGEMENT strategy
Flow Control
Data flow and flow control feedback in TCP
Flow control Mechanism in TCP

1. Opening and Closing Windows


– A Scenario for Flow Control
2. Shrinking of Windows
 Window Shutdown
3. Silly Window Syndrome
i. Syndrome created by the Sender
ii. Syndrome created by the Receiver
Flow Control in TCP
• The opening, closing or shrinking of Send
window is controlled by receive window.
1. Send Window Closes : Moves left wall towards
right  New ACK allows it to happen
2. Send Window Opens: Moves right wall towards
right  when rwnd advertisement by receiver
want more allow it to do so
New ackNo + new rwnd > last ackNO + last rwnd
3. Send Window Shrinks in the event this situation
doesn’t occur.
A Scenario – flow control in TCP
Shirking of Windows
• Some TCP flow control implementation does not
allow shrinking of right wall to move left (Send
Window)
• The relation is kept between receiver and send
window as per equation of. inequality

• Inequality Mandate: The right wall should not


move left
• Mandate Receiver to check its advertisement.
Inequality is valid only if Sf < Sn . Calculations are
modulo 232
Shirking of Windows - Example
Discussion on Mandate – Shirking
Window Example (Previous Slide)
Window Shutdown
• Shrinking right wall towards left is strongly
discouraged
• Receiver can temporarily shutdown the
window by sending rwnd = 0
• This can happen for certain reason receiver
don’t want any data for a duration of time.
• Sender does not shrink the window rather
stops sending any data until new
advertisement arrives
• Sender can always send 1 byte of data this is
called probing , done to avoid dead-lock.
Silly Window Syndrome
• Is data is to small 1 byte then the TCP protocol
efficiency drastically goes down Header 20
byte TCP header + 20 bytes IP header) :
Efficiency = 1/41
• Problem even worse if we consider data link
and physical layer overheads
• This problem is called Silly Window Syndrome
1. Syndrome created by the Sender
Problem: If application of sender generates data slowly
Solution: Nagle’s Algorithm

Algorithm:
Step-1: TCP sender sends first data even if its 1 byte
Step-2: Wait and Accumulate all data from application
till its enough to encapsulate the data inside a segment
(Maximum Segment Size-MSS)  Sends Segment
Step-3: Step-2 is repeated for rest of the transmission,
Segment 3 is sent immediately is ACK for Segment 2 is
received. Send next segment based on which ever is
first, either filling up MSS Segment or ACK received
2. Syndrome created by the Receiver
Problem: If application of Receiver Application
consume data slowly
Solution: Clark’s Solution
Untill the receiver buffer is full the receiver TCP
stores then send rwnd=0 to stop sending more
segment as it can not handle. (Receiver App is
consuming data slowly.
Clark’s Solution
Solution 1: Send ACK but don’t advertise the rwnd
Solution 2: Delay in sending ACK
Error Control in TCP
1. Checksum  Error Detection
2. Acknowledgement
i. Cumulative Acknowledgement (ACK)
ii. Selective Acknowledgement (SACK)
3. Retransmission
i. Retransmission after RTO ( Retransmission Time-
Out) – RTO is dynamic and set based on RTT
Ascension: Sf < Sn
ii. Retransmission after Three duplicate ACK
Segments – Fast Retransmission
Error Control
Error Control - Scenarios
1. Normal Operation
2. Lost Segment
3. Fast Retransmission
4. Delayed Segment
5. Duplicate Segment
6. Automatic Corrected Lost ACK
7. Lost Acknowledgement corrected by resending
a Segment
8. Dead lock created by lost Acknowledgement
1. Normal Operation
2. Lost Segment
3. Fast Retransmission
4. Delayed Segment
• TCP uses IP to be encapsulated
• IP is a connection less protocol in Network
layer
• For some reason is the packet takes longer
path and get received at the receiver after
Time-out. This Scenario is quite possible.
• If the data takes more time than time out the
as per ARQ it will be retransmitted. In some
occasion if the original data packet get
received after the retransmitted packet then it
will be discarded at the receiver (Duplicate
data)
5. Duplicate Segment
• As discussed prior, A duplicate Segment can
be created under the Scenario of Time-out.
• If ACK is not received due to delay before
Time-out , duplicate Segment is created and
retransmitted.
• When the receiver receives a duplicate
Segment with the same SEQUENCE NUMBER,
then it simply discard the Segment.
6. Automatic Corrected Lost ACK
7. Lost Acknowledgement corrected by resending a
Segment
8. Dead lock created by lost Acknowledgement
Lost ACKNOWLEDGEMENT can create deadlock if
they are not properly handled.
• When receiver sends a ACK with rwnd=0
• Sender shutdown the window temporaryly
•After a while the receiver wants to remove that
restriction , if it has no data to be send it simply
send a ACK Segment with Non-Zero value of rwnd.
•If that ACK is lost it can lead to a dead-lock, each
end waiting indefinitely and a Retransmission timer
is not set. To avoid this a persistence timer is
designed. And Probing technique is used.
TCP – Congestion Control
Overview:
• What is Congestion and why it occurs?
• How to handle this Congestion?
• Congestion Control – Window Method
1. Slow Start: Exponential Increase (SS: EI)
2. Congestion Avoidance: Additive Increase (CA: AI)
3. Congestion Detection: Multiplicative Decrease (CD:MD)
• Congestion Control in TCP
• What is Congestion and why it occurs?
When there is more traffic in the network
Congestion Occurs.

• How to handle this Congestion?


Congestion Control Mechanism
Window Method  Congestion Window (cwnd)
 Adaptive SS:EI, CA:AI and CD:MD phases based
on the event of congestion (Time-out or 3 ACK
received)
 Different variants TCP Taho, Reno, New Reno &
Window Method of Congestion Control
Actual Window Size = min (rwnd, cwnd)
rwnd: Receiver Window
Cwnd: Congestion Window

ssthreshold = 32 (Example)
SS:EI continue up to “ssthreshold” value is
reached it will go to CA:AI

MSS: Maximum Segment Size


Slow Start: Exponential Increase (SS: EI)
Congestion Avoidance: Additive Increase (CA: AI)
Congestion Detection: Multiplicative Decrease (CD:MD)

• Under following TWO scenario CD: MD occurs:


1. Time-out
2. 3 duplicate ACK received
 Under CD:MD
 Cwnd =1 MSS and ssthreshold= ½ (Current cwnd)
TCP Taho Congestion Control Mechanism
FSM for Taho TCP
TCP Taho: RTT Vs. cwnd
Thank You…
End of TCP

You might also like