SlideShare a Scribd company logo
1
Transmission Control Protocol
K. PALANIVEL
Systems Analyst, Computer Centre
Pondicherry University, Puducherry – 605014.
LECTURE 8
COMS 525: TCPIP
COURSE
TOPIC
Part - I
Overview
TCP = Transmission Control Protocol
Connection-oriented protocol
Provides a reliable unicast end-to-end byte stream
over an unreliable internetwork.
TCP
IP Internetwork
Byte
Stream
Byte
Stream
TCP
Connection-Oriented
Before any data transfer, TCP establishes a connection:
 One TCP entity is waiting for a connection (“server”)
The other TCP entity (“client”) contacts the server
The actual procedure for setting up connections is more complex.
Each connection is full duplex
CLIENT SERVER
waiting for
connection
request
Data Transer
Reliable
• Byte stream is broken up into chunks which are called
seg-ments
• Receiver sends acknowledgements (ACKs) for
segments
• TCP maintains a timer. If an ACK is not received in
time, the segment is retransmitted
• Detecting errors
• TCP has checksums for header and data. Segments
with invalid checksums are discarded
• Each byte that is transmitted has a sequence number
Byte Stream Service
 To the lower layers, TCP handles data in blocks, the segments.
 To the higher layers TCP handles data as a sequence of bytes
and does not identify boundaries between bytes
 So: Higher layers do not know about the beginning and end of
segments !
TCP
Application
1. write 100 bytes
2. write 20 bytes
queue of
bytes to be
transmitted TCP
queue of
bytes that
have been
received
Application
1. read 40 bytes
2. read 40 bytes
3. read 40 bytes
Segments
TCP Format
IP header TCP header TCP data
Sequence number (32 bits)
DATA
20 bytes 20 bytes
0 15 16 31
Source Port Number Destination Port Number
Acknowledgement number (32 bits)
window size
header
length
0 Flags
Options (if any)
TCP checksum urgent pointer
20
bytes
• TCP segments have a 20 byte header with >= 0 bytes of data.
TCP header fields
Port Number:
◦ A port number identifies the endpoint of a connection.
◦ A pair <IP address, port number> identifies one endpoint
of a connection.
◦ Two pairs <client IP address, server port number> and
<server IP address, server port number> identify a TCP
connection.
TCP
IP
Applications
23 104
80
Ports:
TCP
IP
Applications
7 16
80 Ports:
TCP header fields
Sequence Number (SeqNo):
 Sequence number is 32 bits long.
 So the range of SeqNo is
0 <= SeqNo <= 232
-1  4.3 Gbyte
 Each sequence number identifies a byte in the byte
stream
 Initial Sequence Number (ISN) of a connection is set
during connection establishment for ISN ?
TCP header fields
 Acknowledgement Number (AckNo):
 Acknowledgements are piggybacked, i.e., a segment
from A -> B can contain an acknowledgement for a data
sent in the B -> A direction
 Q: Why is piggA hosts uses the AckNo field to send
acknowledgements. (If a host sends an AckNo in a
segment it sets the “ACK flag”)
 The AckNo contains the next SeqNo that a hosts wants to
receive .
Example: The acknowledgement for a segment with
sequence numbers 0-1500 is AckNo=1501y backing good ?
TCP header fields
Acknowledge Number (cont’d)
TCP uses the sliding window flow protocol to regulate
the flow of traffic from sender to receiver
TCP uses the following variation of sliding window:
no NACKs (Negative ACKnowledgement)
only cumulative ACKs
Example:
Assume: Sender sends two segments with “1..1500” and
“1501..3000”, but receiver only gets the second
segment.
In this case, the receiver cannot acknowledge the second
packet. It can only send AckNo=1
TCP header fields
• Header Length ( 4bits):
– Length of header in 32-bit words
– Note that TCP header has variable length (with
minimum 20 bytes)
TCP header fields
Flag bits:
◦ URG: Urgent pointer is valid
 If the bit is set, the following bytes contain an urgent
message in the range:
SeqNo <= urgent message <= SeqNo+urgent pointer
◦ ACK: Acknowledgement Number is valid
◦ PSH: PUSH Flag
 Notification from sender to the receiver that the receiver
should pass all data that it has to the application.
 Normally set by sender when the sender’s buffer is empty
TCP header fields
 Flag bits:
◦ RST: Reset the connection
 The flag causes the receiver to reset the connection
 Receiver of a RST terminates the connection and
indicates higher layer application about the reset
◦ SYN: Synchronize sequence numbers
 Sent in the first packet when initiating a connection
◦ FIN: Sender is finished with sending
 Used for closing a connection
 Both sides of a connection must send a FIN
TCP Header Fields
Window Size:
Each side of the connection advertises the window
size
Window size is the maximum number of bytes that a
receiver can accept.
Maximum window size is 216
-1= 65535 bytes
TCP Checksum:
TCP checksum covers over both TCP header and TCP
data (also covers some parts of the IP header)
Urgent Pointer:
Only valid if URG flag is set
TCP Header Fields
• Options
End of
Options kind=0
1 byte
NOP
(no operation) kind=1
1 byte
Maximum
Segment Size
kind=2
1 byte
len=4
1 byte
maximum
segment size
2 bytes
Window Scale
Factor
kind=3
1 byte
len=3
1 byte
shift count
1 byte
Timestamp kind=8
1 byte
len=10
1 byte
timestamp value
4 bytes
timestamp echo reply
4 bytes
TCP Header Fields
Options:
NOP is used to pad TCP header to multiples of 4 bytes
Maximum Segment Size
Window Scale Options
Increases the TCP window from 16 to 32 bits, I.e., the
window size is interpreted differently: What is the different
interpretation ?
This option can only be used in the SYN segment (first
segment) during connection establishment time
Timestamp Option
Can be used for roundtrip measurements
Connection Management in TCP
• Opening a TCP Connection
• Closing a TCP Connection
• Special Scenarios
• State Diagram
TCP Connection Establishment
TCP uses a three-way handshake to open a connection:
(1) ACTIVE OPEN: Client sends a segment with
SYN bit set *
port number of client
initial sequence number (ISN) of client
(2) PASSIVE OPEN: Server responds with a segment with
SYN bit set *
initial sequence number of server
ACK for ISN of client
(3) Client acknowledges by sending a segment with:
 ACK ISN of server (* counts as one byte)
Three-Way Handshake
aida.poly.edu mng.poly.edu
TCP Connection Termination
 Each end of the data flow must be shut down
independently (“half-close”)
 If one end is done it sends a FIN segment. This means
that no more data will be sent
 Four steps involved:
(1) X sends a FIN to Y (active close)
(2) Y ACKs the FIN,
(at this time: Y can still send data to X)
(3) and Y sends a FIN to X (passive close)
(4) X ACKs the FIN.
TCP States
State Description
CLOSED No connection is active or pending
LISTEN The server is waiting for an incoming call
SYN RCVD A connection request has arrived; wait for Ack
SYN SENT The client has started to open a connection
ESTABLISHED Normal data transfer state
FIN WAIT 1 Client has said it is finished
FIN WAIT 2 Server has agreed to release
TIMED WAIT Wait for pending packets (“2MSL wait state”)
CLOSING Both Sides have tried to close simultanesously
CLOSE WAIT Server has initiated a release
LAST ACK Wait for pending packets
TCP States in “Normal” Connection Lifetime
SYN (SeqNo = x)
SYN (SeqNo = y, AckNo = x + 1 )
(AckNo = y + 1 )
SYN_SENT
(active open)
SYN_RCVD
ESTABLISHED
ESTABLISHED
FIN_WAIT_1
(active close)
LISTEN
(passive open)
FIN (SeqNo = m)
CLOSE_WAIT
(passive close)
(AckNo = m+ 1 )
FIN (SeqNo = n )
(AckNo = n+1)
LAST_ACK
FIN_WAIT_2
TIME_WAIT
CLOSED
TCP State Transition Diagram: Opening A Connection
CLOSED
LISTEN
SYN RCVD SYN SENT
ESTABLISHED
active open
send: SYN
recv: SYN, ACK
send: ACK
recv: SYN
send: SYN, ACK
recvd: ACK
send: . / .
recv:
RST
Application sends data
send: SYN
simultaneous open
recv: SYN
send: SYN, ACK
close or
timeout
passive open
send: . / .
recvd: FIN send: FIN
send:
FIN
TCP State Transition Diagram: Closing A Connection
FIN_WAIT_1
FIN_WAIT_2
ESTABLISHED
recv: FIN
send: ACK
recv: ACK
send: . / .
recvd: ACK
send: . / .
recv:
FIN, ACK
send: ACK
active close
send: FIN
TIME_WAIT
CLOSING
recv: FIN
send: ACK
CLOSED
Timeout
(2 MSL)
CLOSE_WAIT
LAST_ACK
passive close
recv: FIN
send: ACK
application
closes
send: FIN
recv: ACK
send: . / .
2MSL(Maximum Segment Lifetime) Wait State
2MSL Wait State = TIME_WAIT
When TCP does an active close, and sends the final ACK,
the connection must stay in in the TIME_WAIT state for
twice the maximum segment lifetime.
2MSL= 2 * Maximum Segment Lifetime
Why?
TCP is given a chance to resent the final ACK. (Server
will timeout after sending the FIN segment and resend the
FIN)
The MSL is set to 2 minutes or 1 minute or 30 seconds.
Resetting Connections
• Resetting connections is done by setting the RST flag
• When is the RST flag set?
– Connection request arrives and no server process is
waiting on the destination port
– Abort (Terminate) a connection
Causes the receiver to throw away buffered data.
Receiver does not acknowledge the RST segment
QUESTIONS ???

More Related Content

PPT
TCP Part I How does it work - module13-tcp1.ppt
PPT
Transmission Control Protocol (TCP) connection oriented
PPT
Eshcol tech solutions pvt ltd
PPT
Olumide pidan b
PDF
Web and internet technology notes for BCA students
PPTX
Working of TCP
PPTX
Transmission control protocol
TCP Part I How does it work - module13-tcp1.ppt
Transmission Control Protocol (TCP) connection oriented
Eshcol tech solutions pvt ltd
Olumide pidan b
Web and internet technology notes for BCA students
Working of TCP
Transmission control protocol

Similar to 08 - COMS 525 Internet Protocols and TCPIP - TCP 1.pptx (20)

PDF
TCP - Transmission Control Protocol
PPTX
Transport_Layer_Protocols.pptx
PPT
4. tcp header.ppt
PPT
Transmission control protocol ...............................
PPT
the transport layer
DOCX
transport layer
PPT
PPT
Transmission control protocol _
PPTX
Transmission Control Protocol_ Computer Networks
PPTX
Unit V computer network notes for study.
PPTX
Tcp3 wayhandshakeprocess
PPT
TCPIP in brief and working operation.ppt
PDF
Internet technology unit 3
PPTX
Part5-tcp-improvements.pptx
PDF
Networking problem help Consider the following TCP session between h.pdf
PPTX
13_TCP_Attack.pptx
PPT
Adhoc and Sensor Networks - Chapter 07
PPTX
DOCX
TCP.docx
PPTX
Part4-reliable-tcp.pptx
TCP - Transmission Control Protocol
Transport_Layer_Protocols.pptx
4. tcp header.ppt
Transmission control protocol ...............................
the transport layer
transport layer
Transmission control protocol _
Transmission Control Protocol_ Computer Networks
Unit V computer network notes for study.
Tcp3 wayhandshakeprocess
TCPIP in brief and working operation.ppt
Internet technology unit 3
Part5-tcp-improvements.pptx
Networking problem help Consider the following TCP session between h.pdf
13_TCP_Attack.pptx
Adhoc and Sensor Networks - Chapter 07
TCP.docx
Part4-reliable-tcp.pptx
Ad

Recently uploaded (20)

PPTX
Module 1 - Cyber Law and Ethics 101.pptx
PDF
The New Creative Director: How AI Tools for Social Media Content Creation Are...
PPTX
international classification of diseases ICD-10 review PPT.pptx
PPTX
Introduction to Information and Communication Technology
PPTX
introduction about ICD -10 & ICD-11 ppt.pptx
PDF
Vigrab.top – Online Tool for Downloading and Converting Social Media Videos a...
PPTX
PptxGenJS_Demo_Chart_20250317130215833.pptx
PPTX
Digital Literacy And Online Safety on internet
PDF
APNIC Update, presented at PHNOG 2025 by Shane Hermoso
PDF
Unit-1 introduction to cyber security discuss about how to secure a system
PDF
Sims 4 Historia para lo sims 4 para jugar
PDF
RPKI Status Update, presented by Makito Lay at IDNOG 10
PDF
WebRTC in SignalWire - troubleshooting media negotiation
PPT
tcp ip networks nd ip layering assotred slides
PDF
The Internet -By the Numbers, Sri Lanka Edition
PPTX
artificial intelligence overview of it and more
PPTX
CHE NAA, , b,mn,mblblblbljb jb jlb ,j , ,C PPT.pptx
PDF
Cloud-Scale Log Monitoring _ Datadog.pdf
PDF
Triggering QUIC, presented by Geoff Huston at IETF 123
PDF
Decoding a Decade: 10 Years of Applied CTI Discipline
Module 1 - Cyber Law and Ethics 101.pptx
The New Creative Director: How AI Tools for Social Media Content Creation Are...
international classification of diseases ICD-10 review PPT.pptx
Introduction to Information and Communication Technology
introduction about ICD -10 & ICD-11 ppt.pptx
Vigrab.top – Online Tool for Downloading and Converting Social Media Videos a...
PptxGenJS_Demo_Chart_20250317130215833.pptx
Digital Literacy And Online Safety on internet
APNIC Update, presented at PHNOG 2025 by Shane Hermoso
Unit-1 introduction to cyber security discuss about how to secure a system
Sims 4 Historia para lo sims 4 para jugar
RPKI Status Update, presented by Makito Lay at IDNOG 10
WebRTC in SignalWire - troubleshooting media negotiation
tcp ip networks nd ip layering assotred slides
The Internet -By the Numbers, Sri Lanka Edition
artificial intelligence overview of it and more
CHE NAA, , b,mn,mblblblbljb jb jlb ,j , ,C PPT.pptx
Cloud-Scale Log Monitoring _ Datadog.pdf
Triggering QUIC, presented by Geoff Huston at IETF 123
Decoding a Decade: 10 Years of Applied CTI Discipline
Ad

08 - COMS 525 Internet Protocols and TCPIP - TCP 1.pptx

  • 1. 1 Transmission Control Protocol K. PALANIVEL Systems Analyst, Computer Centre Pondicherry University, Puducherry – 605014. LECTURE 8 COMS 525: TCPIP COURSE TOPIC Part - I
  • 2. Overview TCP = Transmission Control Protocol Connection-oriented protocol Provides a reliable unicast end-to-end byte stream over an unreliable internetwork. TCP IP Internetwork Byte Stream Byte Stream TCP
  • 3. Connection-Oriented Before any data transfer, TCP establishes a connection:  One TCP entity is waiting for a connection (“server”) The other TCP entity (“client”) contacts the server The actual procedure for setting up connections is more complex. Each connection is full duplex CLIENT SERVER waiting for connection request Data Transer
  • 4. Reliable • Byte stream is broken up into chunks which are called seg-ments • Receiver sends acknowledgements (ACKs) for segments • TCP maintains a timer. If an ACK is not received in time, the segment is retransmitted • Detecting errors • TCP has checksums for header and data. Segments with invalid checksums are discarded • Each byte that is transmitted has a sequence number
  • 5. Byte Stream Service  To the lower layers, TCP handles data in blocks, the segments.  To the higher layers TCP handles data as a sequence of bytes and does not identify boundaries between bytes  So: Higher layers do not know about the beginning and end of segments ! TCP Application 1. write 100 bytes 2. write 20 bytes queue of bytes to be transmitted TCP queue of bytes that have been received Application 1. read 40 bytes 2. read 40 bytes 3. read 40 bytes Segments
  • 6. TCP Format IP header TCP header TCP data Sequence number (32 bits) DATA 20 bytes 20 bytes 0 15 16 31 Source Port Number Destination Port Number Acknowledgement number (32 bits) window size header length 0 Flags Options (if any) TCP checksum urgent pointer 20 bytes • TCP segments have a 20 byte header with >= 0 bytes of data.
  • 7. TCP header fields Port Number: ◦ A port number identifies the endpoint of a connection. ◦ A pair <IP address, port number> identifies one endpoint of a connection. ◦ Two pairs <client IP address, server port number> and <server IP address, server port number> identify a TCP connection. TCP IP Applications 23 104 80 Ports: TCP IP Applications 7 16 80 Ports:
  • 8. TCP header fields Sequence Number (SeqNo):  Sequence number is 32 bits long.  So the range of SeqNo is 0 <= SeqNo <= 232 -1  4.3 Gbyte  Each sequence number identifies a byte in the byte stream  Initial Sequence Number (ISN) of a connection is set during connection establishment for ISN ?
  • 9. TCP header fields  Acknowledgement Number (AckNo):  Acknowledgements are piggybacked, i.e., a segment from A -> B can contain an acknowledgement for a data sent in the B -> A direction  Q: Why is piggA hosts uses the AckNo field to send acknowledgements. (If a host sends an AckNo in a segment it sets the “ACK flag”)  The AckNo contains the next SeqNo that a hosts wants to receive . Example: The acknowledgement for a segment with sequence numbers 0-1500 is AckNo=1501y backing good ?
  • 10. TCP header fields Acknowledge Number (cont’d) TCP uses the sliding window flow protocol to regulate the flow of traffic from sender to receiver TCP uses the following variation of sliding window: no NACKs (Negative ACKnowledgement) only cumulative ACKs Example: Assume: Sender sends two segments with “1..1500” and “1501..3000”, but receiver only gets the second segment. In this case, the receiver cannot acknowledge the second packet. It can only send AckNo=1
  • 11. TCP header fields • Header Length ( 4bits): – Length of header in 32-bit words – Note that TCP header has variable length (with minimum 20 bytes)
  • 12. TCP header fields Flag bits: ◦ URG: Urgent pointer is valid  If the bit is set, the following bytes contain an urgent message in the range: SeqNo <= urgent message <= SeqNo+urgent pointer ◦ ACK: Acknowledgement Number is valid ◦ PSH: PUSH Flag  Notification from sender to the receiver that the receiver should pass all data that it has to the application.  Normally set by sender when the sender’s buffer is empty
  • 13. TCP header fields  Flag bits: ◦ RST: Reset the connection  The flag causes the receiver to reset the connection  Receiver of a RST terminates the connection and indicates higher layer application about the reset ◦ SYN: Synchronize sequence numbers  Sent in the first packet when initiating a connection ◦ FIN: Sender is finished with sending  Used for closing a connection  Both sides of a connection must send a FIN
  • 14. TCP Header Fields Window Size: Each side of the connection advertises the window size Window size is the maximum number of bytes that a receiver can accept. Maximum window size is 216 -1= 65535 bytes TCP Checksum: TCP checksum covers over both TCP header and TCP data (also covers some parts of the IP header) Urgent Pointer: Only valid if URG flag is set
  • 15. TCP Header Fields • Options End of Options kind=0 1 byte NOP (no operation) kind=1 1 byte Maximum Segment Size kind=2 1 byte len=4 1 byte maximum segment size 2 bytes Window Scale Factor kind=3 1 byte len=3 1 byte shift count 1 byte Timestamp kind=8 1 byte len=10 1 byte timestamp value 4 bytes timestamp echo reply 4 bytes
  • 16. TCP Header Fields Options: NOP is used to pad TCP header to multiples of 4 bytes Maximum Segment Size Window Scale Options Increases the TCP window from 16 to 32 bits, I.e., the window size is interpreted differently: What is the different interpretation ? This option can only be used in the SYN segment (first segment) during connection establishment time Timestamp Option Can be used for roundtrip measurements
  • 17. Connection Management in TCP • Opening a TCP Connection • Closing a TCP Connection • Special Scenarios • State Diagram
  • 18. TCP Connection Establishment TCP uses a three-way handshake to open a connection: (1) ACTIVE OPEN: Client sends a segment with SYN bit set * port number of client initial sequence number (ISN) of client (2) PASSIVE OPEN: Server responds with a segment with SYN bit set * initial sequence number of server ACK for ISN of client (3) Client acknowledges by sending a segment with:  ACK ISN of server (* counts as one byte)
  • 20. TCP Connection Termination  Each end of the data flow must be shut down independently (“half-close”)  If one end is done it sends a FIN segment. This means that no more data will be sent  Four steps involved: (1) X sends a FIN to Y (active close) (2) Y ACKs the FIN, (at this time: Y can still send data to X) (3) and Y sends a FIN to X (passive close) (4) X ACKs the FIN.
  • 21. TCP States State Description CLOSED No connection is active or pending LISTEN The server is waiting for an incoming call SYN RCVD A connection request has arrived; wait for Ack SYN SENT The client has started to open a connection ESTABLISHED Normal data transfer state FIN WAIT 1 Client has said it is finished FIN WAIT 2 Server has agreed to release TIMED WAIT Wait for pending packets (“2MSL wait state”) CLOSING Both Sides have tried to close simultanesously CLOSE WAIT Server has initiated a release LAST ACK Wait for pending packets
  • 22. TCP States in “Normal” Connection Lifetime SYN (SeqNo = x) SYN (SeqNo = y, AckNo = x + 1 ) (AckNo = y + 1 ) SYN_SENT (active open) SYN_RCVD ESTABLISHED ESTABLISHED FIN_WAIT_1 (active close) LISTEN (passive open) FIN (SeqNo = m) CLOSE_WAIT (passive close) (AckNo = m+ 1 ) FIN (SeqNo = n ) (AckNo = n+1) LAST_ACK FIN_WAIT_2 TIME_WAIT CLOSED
  • 23. TCP State Transition Diagram: Opening A Connection CLOSED LISTEN SYN RCVD SYN SENT ESTABLISHED active open send: SYN recv: SYN, ACK send: ACK recv: SYN send: SYN, ACK recvd: ACK send: . / . recv: RST Application sends data send: SYN simultaneous open recv: SYN send: SYN, ACK close or timeout passive open send: . / . recvd: FIN send: FIN send: FIN
  • 24. TCP State Transition Diagram: Closing A Connection FIN_WAIT_1 FIN_WAIT_2 ESTABLISHED recv: FIN send: ACK recv: ACK send: . / . recvd: ACK send: . / . recv: FIN, ACK send: ACK active close send: FIN TIME_WAIT CLOSING recv: FIN send: ACK CLOSED Timeout (2 MSL) CLOSE_WAIT LAST_ACK passive close recv: FIN send: ACK application closes send: FIN recv: ACK send: . / .
  • 25. 2MSL(Maximum Segment Lifetime) Wait State 2MSL Wait State = TIME_WAIT When TCP does an active close, and sends the final ACK, the connection must stay in in the TIME_WAIT state for twice the maximum segment lifetime. 2MSL= 2 * Maximum Segment Lifetime Why? TCP is given a chance to resent the final ACK. (Server will timeout after sending the FIN segment and resend the FIN) The MSL is set to 2 minutes or 1 minute or 30 seconds.
  • 26. Resetting Connections • Resetting connections is done by setting the RST flag • When is the RST flag set? – Connection request arrives and no server process is waiting on the destination port – Abort (Terminate) a connection Causes the receiver to throw away buffered data. Receiver does not acknowledge the RST segment