CSIE,NTUT,TAIWAN 1
Transmission
Control Protocol
(TCP)
Chuan-Ming Liu
CSIE,NTUT
Spring ’04,TAIWAN
CSIE,NTUT,TAIWAN 2
CONTENTS
TCP SERVICES
NUMBERING BYTES
FLOW CONTROL
SILLY WINDOW SYNDROME
ERROR CONTROL
TCP TIMERS
CONGESTION CONTROL
SEGMENT
OPTIONS
CHECKSUM
CONNECTION
TCP OERATION
CSIE,NTUT,TAIWAN 3Figure 12-1
Position of TCP in TCP/IP protocol suite
CSIE,NTUT,TAIWAN 4
TCP
SERVICES
12.2
CSIE,NTUT,TAIWAN 5
TCP Services
Stream Delivery Service
– TCP is a stream-oriented protocol
– Uses imaginary,tube” to communicate
– Uses sending and receiving buffers to synchronize
– Group a number of bytes into a packet called segment
Full-duplex Service
Connection-oriented Service
Reliable Service
CSIE,NTUT,TAIWAN 9
NUMBERING
BYTES
12.3
CSIE,NTUT,TAIWAN 10
Numbering Bytes
TCP uses the following two fields to track the
segments
– Sequence number
– Acknowledgment number
These two fields use byte number,not the
segment number
CSIE,NTUT,TAIWAN 11
Byte Numbers
TCP numbers all the data transmitted in a
connection
Numbering is independent in each direction
The numbering does not necessarily start from
0; it starts randomly
The random number is between 0 and 232-1
For flow and error control
CSIE,NTUT,TAIWAN 12
Sequence Number
After bytes numbered,TCP assigns a sequence
number to each segment
The sequence number for each sequence is the
number of the first byte in that segment
CSIE,NTUT,TAIWAN 13
Example 1
Imagine a TCP connection is transferring
a file of 6000 bytes,The first byte is
numbered 10010,What are the sequence
numbers for each segment if data is sent
in five segments with the first four
segments carrying 1,000 bytes and the
last segment carrying 2,000 bytes?
CSIE,NTUT,TAIWAN 14
Solution
The following shows the sequence number for
each segment:
Segment 1? 10,010 (10,010to 11,009)
Segment 2? 11,010 (11,010to 12,009)
Segment 3? 12,010 (12,010to 13,009)
Segment 4? 13,010 (13,010to 14,009)
Segment 5? 14,010 (14,010to 16,009)
CSIE,NTUT,TAIWAN 15
Acknowledgment Number
The number of the next byte that the party
expects to receive
The acknowledgment number is cumulative
CSIE,NTUT,TAIWAN 16
FLOW
CONTROL
12.4
CSIE,NTUT,TAIWAN 17
Flow Control
Define the amount of data a source can send
before receiving an acknowledgment
One extreme case is an extremely slow process
The other extreme case is the source sends
data to fast
TCP has a solution in between these two
extreme cases – imposing a window on the
buffer
CSIE,NTUT,TAIWAN 18
Sliding Window Protocol
TCP uses sliding window protocol to control
the flow
A sliding window is used to make transmission
more efficient as well as to control the flow so
that the destination does not become
overwhelmed
TCP sliding windows are byte oriented
CSIE,NTUT,TAIWAN 19Figure 12-7
Sender Buffer
CSIE,NTUT,TAIWAN 20Figure 12-8
Receiver Window
Receiver window = the size of the receiver buffer
– the number of occupied locations
CSIE,NTUT,TAIWAN 21Figure 12-9
Sender Buffer and Sender Window
CSIE,NTUT,TAIWAN 22Figure 12-10
Sliding the Sender Window
CSIE,NTUT,TAIWAN 23Figure 12-11
Expanding the Sender Window
CSIE,NTUT,TAIWAN 24Figure 12-12
Shrinking the Sender Window
CSIE,NTUT,TAIWAN 25
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.
CSIE,NTUT,TAIWAN 26
SILLY
WINDOW
SYNDROME
12.5
CSIE,NTUT,TAIWAN 27
Silly Window Syndrome
Either the sending application creates data too
slow or the receiving process consumes data
slowly
Both situations make the segment small;
therefore,lead to inefficient network capacity
CSIE,NTUT,TAIWAN 28
ERROR
CONTROL
12.6
CSIE,NTUT,TAIWAN 29
Error Control
TCP is reliable
Using error control to achieve reliability
Error control includes:
– Detecting corrupted segments
– Lost segments
– Out-of-order segments
– Duplicated segments
– Correcting errors
CSIE,NTUT,TAIWAN 30
Error Detection and Correction
Detection is achieved by three tools:
– Checksum
– Acknowledgment
– Time-out
Error-correction in TCP is simple –
retransmission
CSIE,NTUT,TAIWAN 31Figure 12-13
Corrupted Segment
CSIE,NTUT,TAIWAN 32Figure 12-14
Lost Segment
CSIE,NTUT,TAIWAN 33
Duplicated Segment
Generated by retransmission
The solution is to discard the packet having the
same sequence number
CSIE,NTUT,TAIWAN 34
Out-of-Order Segment
TCP segment is encapsulated in an IP
datagram
Each IP datagram is independently transmitted
IP datagrams can arrive out of order
To handle the out-of-order segment,the
receiver does not acknowledge an out-of-order
segment until it receives all the segments that
precede it
CSIE,NTUT,TAIWAN 35Figure 12-15
Lost Acknowledgment
CSIE,NTUT,TAIWAN 36
TCP
TIMERS
12.7
CSIE,NTUT,TAIWAN 37Figure 12-16
TCP Timers
CSIE,NTUT,TAIWAN 38
Retransmission Timer
To control a lost or discarded segment
If an acknowledgment is received before the
timer goes off,the timer is destroyed
If the times goes off before the
acknowledgment arrives,the segment is
retransmitted and the timer is reset
CSIE,NTUT,TAIWAN 39
Persistence Timer
To deal with the zero window-size
advertisement
When the sender receives an acknowledgment
with a window size of zero,TCP starts a
persistence timer
When the persistence timer goes off,sender
sends a probe to alter the receiver
CSIE,NTUT,TAIWAN 40
Keepalive Timer
To be used during connection termination
Time-Waited Timer
To prevent a long idle connection between two TCPs
CSIE,NTUT,TAIWAN 41
CONGESTION
CONTROL
12.8
CSIE,NTUT,TAIWAN 42
Congestion Control
arrival rate is too fast
congestion occurs
packets dropped
sender receiver
retransmission
CSIE,NTUT,TAIWAN 43
Congestion Control
TCP assumes that the cause of a lost segment
is due to the 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 the
congestion
TCP uses two strategies to avoid congestion
– Slow start and additive increase
– Multiplication Decrease
CSIE,NTUT,TAIWAN 44Figure 12-17
Multiplicative decrease
CSIE,NTUT,TAIWAN 45
SEGMENT
12.9
CSIE,NTUT,TAIWAN 46
Segment
The unit of data transfer between two device
using TCP is a segment
Consists of header (20-60 bytes) and data
CSIE,NTUT,TAIWAN 47Figure 12-19
TCP Segment Format
CSIE,NTUT,TAIWAN 48Figure 12-20
Control field
CSIE,NTUT,TAIWAN 49
OPTIONS
12.10
CSIE,NTUT,TAIWAN 50
Options
Up to 40 bytes
Can be classified
– End of option
– No Option
– Maximum Segment Size (MSS)
– Window Scale Factor
– Timestamp
CSIE,NTUT,TAIWAN 51Figure 12-21
Options
CSIE,NTUT,TAIWAN 52Figure 12-22
End of option
CSIE,NTUT,TAIWAN 53Figure 12-23
No operation
CSIE,NTUT,TAIWAN 54Figure 12-24
Maximum segment size
The size of the biggest chunk of data that can be
received by the destination of the TCP segment
The default size is 536
Define the maximum size of data,not segment
CSIE,NTUT,TAIWAN 55Figure 12-25
Window scale factor
CSIE,NTUT,TAIWAN 56
Figure 12-26
Timestamp
CSIE,NTUT,TAIWAN 57
CHECKSUM
12.11
CSIE,NTUT,TAIWAN 58Figure 12-12
CSIE,NTUT,TAIWAN 59
CONNECTION
12.12
CSIE,NTUT,TAIWAN 60
Connection
TCP is a connection-oriented protocol
Requires two procedures:
– Connection establishment
(Three-way Handshaking)
– Connection termination
(Four-way Handshaking)
CSIE,NTUT,TAIWAN 61Figure 12-28
Three-way handshaking
CSIE,NTUT,TAIWAN 62Figure 12-29
Four-way handshaking
CSIE,NTUT,TAIWAN 63
Connecting Resetting
Resetting means the current connection is
destroyed
Three cases
– TCP on one side has requested a connection to a
nonexistent port
– One TCP may want to abort the connection due to
an abnormal situation
– One side may realizes the connection is idle for a
while
CSIE,NTUT,TAIWAN 64
TCP
OPERATION
12.14
CSIE,NTUT,TAIWAN 65Figure 12-33
Encapsulation and Decapsulation
CSIE,NTUT,TAIWAN 66
Pushing Data
Some applications may not be comfortable
when TCP uses buffers
One of the application is TELNET
TCP handles this by allowing the applications
to push the segment containing the data to IP
layer immediately
This is done by setting the push bit (PSH)
CSIE,NTUT,TAIWAN 67
Urgent Data
TCP is a stream-oriented protocol
Data is presented as a stream of characters
Each byte of data has a position in the sream
Sometimes,the applications need to send
urgent byte,such as Control + C
CSIE,NTUT,TAIWAN 68Figure 12-34
Multiplexing and Demultiplexing