Upload
abhijeet-thakur
View
232
Download
1
Embed Size (px)
DESCRIPTION
TCP Overview nice overview
Citation preview
31 January 2014 1
TCP Overview
31 January 2014 2
TCP/IP Protocol Stack
Application
Presentation
Session
Transport
Network
Data Link
Physical
7
6
5
4
3
2
1
Application
Transport
Internet
Network Interface
OSI Reference Model
4
3
2
Ethernet, 802.3, 802.5, FDDI, and so on.
TCP/IP Conceptual Layers
31 January 2014 3
Transport Layer Overview
Transmission ControlProtocol (TCP)
User Datagram Protocol (UDP)
Transmission ControlProtocol (TCP)
User Datagram Protocol (UDP)
Application
Transport
Internet
Network Interface
Hardware
31 January 2014 4
TCP
Defined in RFC 793
Reliable
- Acknowledgments
- Guarantee of packet delivery
- Delayed Ack – Piggybacking
- Reassembly of out of order data
- Discards duplicates caused by IP
- Provided end-to-end flow control
- finite buffer size
31 January 2014 5
TCP
Connection oriented
- Segments are dependent
- Maintain state information of segments
- Segments can take different routes
- Segments are delivered in order to the application
layer
Full Duplex
31 January 2014 6
TCP Segment Format
# Bits 616 32 416 6 32
SourcePort
Dest.Port
SequenceNumber
AcknowledgementNumber
HLEN ReservedCodeBits
16
Window
16
Check-sum
16
Urgent Pointer
0 or 32
Options Data...
31 January 2014 7
Port Numbers
TCP
Port Numbers
FTP
TransportLayer
TELNET
DNS
SNMP
TFTP
SMTP
UDP
ApplicationLayer
21 23 25 53 69 161
31 January 2014 8
TCP Port Numbers
SourcePort
Dest.Port
…
Host A
Dest. port = 23.Send packet to my
Telnet application.
1028 23 …
SP DP
Host ZTelnet Z
Ephemeral Ports
31 January 2014 9
TCP Handshake/Open Connection
Send SYN (seq=100 ctl=SYN)
SYN received
Host A Host B
1
31 January 2014 10
TCP Handshake/Open Connection
Send SYN (seq=100 ctl=SYN)
SYN received
Send SYN (seq=300 ack=101 ctl=syn,ack)
Host A Host B
1
2SYN received
31 January 2014 11
TCP Handshake/Open Connection
Send SYN (seq=100 ctl=SYN)
SYN received
Send SYN (seq=300 ack=101 ctl=syn,ack)
Established(seq=101 ack=301 ctl=ack)
Host A Host B
1
2
3
SYN received
31 January 2014 12
TCP Handshake/Open Connection
Send SYN (seq=100 ctl=SYN)
SYN received
Send SYN (seq=300 ack=101 ctl=syn,ack)
Established(seq=101 ack=301 ctl=ack)
Host A Host B
Data Segment(seq=101 ack=301 ctl=ack Data)
1
2
3
4
SYN received
31 January 2014 13
Window size = 1
Sender Receiver
TCP Simple Acknowledgment
31 January 2014 14
Window size = 1
Sender Receiver
Send 1Receive 1
TCP Simple Acknowledgment
31 January 2014 15
Window size = 1
Sender Receiver
Send 1Receive 1
Receive ACK 2 Send ACK 2
TCP Simple Acknowledgment
31 January 2014 16
Window size = 1
Sender Receiver
Send 1Receive 1
Receive ACK 2 Send ACK 2
Send 2Receive 2
TCP Simple Acknowledgment
31 January 2014 17
Window size = 1
Sender Receiver
Send 1Receive 1
Receive ACK 2 Send ACK 2
Send 2Receive 2
Receive ACK 3 Send ACK 3
TCP Simple Acknowledgment
31 January 2014 18
Window size = 1
Sender Receiver
Send 1Receive 1
Receive ACK 2 Send ACK 2
Send 2Receive 2
Receive ACK 3Send ACK 3
Send 3Receive 3
TCP Simple Acknowledgment
31 January 2014 19
Window size = 1
Sender Receiver
Send 1Receive 1
Receive ACK 2 Send ACK 2
Send 2Receive 2
Receive ACK 3Send ACK 3
Send 3Receive 3
Receive ACK 4 Send ACK 4
TCP Simple Acknowledgment
31 January 2014 20
TCP Windowing
SenderReceiver
31 January 2014 21
Window size = 3Send 2
TCP Windowing
Sender ReceiverWindow size = 3Send 1
Window size = 3Send 3
31 January 2014 22
Window size = 3Send 2
TCP Windowing
Sender ReceiverWindow size = 3Send 1
Window size = 3Send 3
ACK 1Window size = 2
ACK 2Window size = 2
ACK 3Window size = 2
31 January 2014 23
Window size = 3Send 5
Window size = 3Send 2
TCP Windowing
Sender ReceiverWindow size = 3Send 1
Window size = 3Send 4
Window size = 3Send 3
ACK 1Window size = 2
ACK 2Window size = 2
ACK 3Window size = 2
31 January 2014 24
Window size = 3Send 5
Window size = 3Send 2
TCP Windowing
Sender ReceiverWindow size = 3Send 1
Window size = 3Send 4
Window size = 3Send 3
ACK 1Window size = 2
ACK 2Window size = 2
ACK 3Window size = 2
ACK 4Window size = 2
ACK 5Window size = 2
31 January 2014 25
TCP Sequence and Ack Numbers
I justsent #10.
SourcePort
Dest.Port
…Sequence
#Acknowledgement
#
1028 23
Source Dest.
1010
Seq.
1
Ack.
…
31 January 2014 26
TCP Sequence and Ack Numbers
I justsent #10.
I just got #10,now I need #11.
SourcePort
Dest.Port
…Sequence
#Acknowledgement
#
1028 23
Source Dest.
1010
Seq.
1
Ack.
…
102823
Source Dest.
1111
Seq.
1
Ack.
…
31 January 2014 27
TCP Sequence and Ack Numbers
I justsent #10.
I just got #10,now I need #11.
SourcePort
Dest.Port
…Sequence
#Acknowledgement
#
1028 23
Source Dest.
1010
Seq.
1
Ack.
…
1028 23
Source Dest.
1111
Seq.
2
Ack.
…
102823
Source Dest.
1111
Seq.
1
Ack.
…
31 January 2014 28
TCP Connection Closure
Send FIN FIN received
Host A Host B
1
31 January 2014 29
TCP Connection Closure
Send FIN FIN received
Send ACK
Host A Host B
1
2ACK received
31 January 2014 30
TCP Connection Closure
Send FIN FIN received
Send ACK
Host A Host B
1
2ACK received
Send FIN FIN received
3
31 January 2014 31
TCP Connection Closure
Send FIN FIN received
Send ACK
Host A Host B
1
2ACK received
Send FIN FIN received
Send ACK ACK received
3
4
31 January 2014 32
TCP Connection Closure
Since TCP is full-duplex, connection must be
shut down from both sides independently
- it takes 4 segments to close the connection
completely
Active close – initiation of first FIN request
Passive close – initiation of second FIN
request
31 January 2014 33
Connection closure sequence
Application closes the session
TCP sends FIN to the server
Server TCP sends ACK to client
Server TCP informs application
Server application closes the session
Server TCP sends FIN
Client TCP sends ACK to server
31 January 2014 34
TCP Connection Closure
Half-close is also possible
- Only one side discontinue transmission
- Most of the present applications do not use half-
close
31 January 2014 35
Half-Close
Send FIN FIN received
Host A Host B
1
31 January 2014 36
Half Close
Send FIN FIN received
Send ACK
Host A Host B
1
2ACK received
31 January 2014 37
Half Close
Send FIN FIN received
Send ACK
Host A Host B
1
2ACK received
Send Data Segment
3
5
31 January 2014 38
Timeout during Connection Setup
When initiator does not receive SYN-ACK
- Resends SYN after some time
- First retry after 6 sec
- Second retry after 24 sec
- Stops retrying after 75 seconds (Unix system)
- These times are implementation dependent
31 January 2014 39
MSS
Maximum Segment Size
- Exchanged with the initial SYN packets as an
optional field
- MSS does not appear in other packets
- If MSS value is not received default value
assumed is 536 bytes
- 536+20IPhdr+20TCPHdr = 576byte IP datagram
31 January 2014 40
MSS
Larger the MSS, better it is for the protocol
efficiency, provided it is not fragmented
MSS may be at the most
= MTU – 20 – 20 byte
- For Ethernet = 1500-20-20 = 1460
If destination is non-local, MSS normally
defaults to 536
MSS is configurable value
31 January 2014 41
MSS
When two sides announce different MSS,
they normally settle down to the lower value.
- This is not mandatory
- Avoids fragmentations
- Not necessarily eliminate fragmentations if
intermediate links have even lower MTU
- Use MTU discovery mechanism to avoid this
31 January 2014 42
Non-delivery of TCP Segments
Non delivery is indicated by non-receipt of
ACK at sender side
This may be caused by
- Loss of packet
Due to congestion
Due to error in header
Due to error in data
- Loss of ACK
- Delayed delivery by IP
31 January 2014 43
Non-delivery of TCP Segments
Non-receipt of ACK is decided by
- Retransmission timer
- Receipt of duplicate ack
TCP assumes that the non-delivery is
because of congestion
Reduces the window size when the packet is
declared as undelivered
- Not an efficient way if loss of packet is due to a
transmission error
31 January 2014 44
Types of Connection Closure
Orderly release – graceful shutdown
- When closure initiated by applications
- No loss of data
- Using FIN segment
Abortive release
- Abrupt termination
- Using reset (RST)
31 January 2014 45
Variation in Connection Open and Close
Simultaneous Opening
- Both sides send SYN
- Both sides respond with SYN-ACK
Simultaneous Closure
- Both sides send FIN
- Both sides send ACK
31 January 2014 46
RST
Generated on receipt of an incorrect TCP segment- Packet does not belong to the referenced
connection, determined byIPPort numberSequence number
Generated on receipt of connection request to an nonexistent port
Generated by application when it aborts the application
31 January 2014 47
RST
At sender side, any queued data is thrown
away
At the receiver side, APIs used should be
able to inform application about the abortive
release
31 January 2014 48
PSH
PUSH Flag
Indicates to the receiver to send the data to
the application without further delay
Used in the interactive applications or during
interactive operations
Also used when last portion of the data is
sent by sender stack
31 January 2014 49
Half-open Connections
One side abruptly terminates the session
May be caused by
- System crash
- Machine powered off without graceful shutdown
Server will not know the closure and will be in
wait state
Security risk
31 January 2014 50
Interactive Data Flow
Tinygrams- Small data flow during interactive applications - Example: Rlogin
Nagle Algorithm (RFC 896)- TCP connection can have only one outstanding
small segment that is not yet acknowledged- Small data is collected by TCP and sent together
when Ack is received for previous small segment- Might cause problem when ASCII escape
character is involved (special function keys)
31 January 2014 51
Interactive Data Flow
Repacketisation
- Sending retransmission and next segment in the
same segment
TCP protocol spoofing
- Used when delay is high, bandwidth is sufficent
- Improves user experience and application
performance
- Used in VSATs
31 January 2014 52
Sliding Window
Start small – slow start
Grow exponentially
Bound by upper limit of window size
Reduces window size when encounter
segment loss
Increases window size again
- Offered window size
- Usable window size
31 January 2014 53
Sliding Window
Slow Start
- Rate of transmission depends on rate of receipt of
acknowledgments
- A flow control imposed by sender based on its
assessment of congestion in the network
31 January 2014 54
Congestion Avoidance
Indication of loss of packet
- Timeout
- Duplicate ACK
On receiving duplicate ACK reduce usable
window size to half
If congestion is indicated by timeout, reduce
usable window size to one, initiate slow start
31 January 2014 55
Fast Retransmit
When three or more duplicate ACK received,
retransmit the un-ACKed packets without
waiting for timeout of retransmission timer
31 January 2014 56
Reading Assignment
Congestion Avoidance
Slow Start
Fast Retransmit
Fast Recovery
31 January 2014 57
Congestion Avoidance
Indication of loss of packet
- Timeout
- Duplicate ACK
Two variables
- cwnd (congestion window)
- ssthresh(slow start threshold)
On congestion, ssthresh = cwnd/2
If congestion is indicated by timeout, cwnd is
set to one, slow start
31 January 2014 58
Thank you!