TRANSPORT LAYER
Process-to-Process Delivery:
UDP & TCP
23.1 Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
23-3 TCP
TCP is a connection-oriented protocol; it creates a virtual connection between two TCPs to
send data. In addition, TCP uses flow and error control mechanisms at the transport level.
Topics discussed in this section:
TCP Services
TCP Features
Segment
A TCP Connection
Flow Control
Error Control
23.2
Table 23.2 Well-known ports used by TCP
23.3
Figure 23.13 Stream delivery
23.4
Figure 23.14 Sending and receiving buffers
23.5
Figure 23.15 TCP segments
23.6
Note
The bytes of data being transferred in each connection are numbered
by TCP.
The numbering starts with a randomly generated number.
23.7
Example 23.3
The following shows the sequence number for each segment:
23.8
Note
The value in the sequence number field of a segment defines the
number of the first data byte
contained in that segment.
23.9
Note
The value of the acknowledgment field in a segment defines
the number of the next byte a party expects to receive.
The acknowledgment number is cumulative.
23.10
Figure 23.16 TCP segment format
23.11
Figure 23.17 Control field
23.12
Table 23.3 Description of flags in the control field
23.13
Figure 23.18 Connection establishment using three-way handshaking
23.14
Note
A SYN segment cannot carry data, but it consumes one sequence
number.
23.15
Note
A SYN + ACK segment cannot
carry data, but does consume one
sequence number.
23.16
Note
An ACK segment, if carrying no data, consumes no sequence number.
23.17
Figure 23.19 Data transfer
23.18
Figure 23.20 Connection termination using three-way handshaking
23.19
Note
The FIN segment consumes one sequence number if it does
not carry data.
23.20
Note
The FIN + ACK segment consumes
one sequence number if it
does not carry data.
23.21
Figure 23.21 Half-close
23.22
Figure 23.22 Sliding window
23.23
Note
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 sliding windows are byte-oriented.
23.24
Example 23.4
What is the value of the receiver window (rwnd) for host A if the receiver, host B, has a buffer size
of 5000 bytes and 1000 bytes of received and unprocessed data?
Solution
The value of rwnd = 5000 − 1000 = 4000. Host B can receive only 4000 bytes of data before
overflowing its buffer. Host B advertises this value in its next segment to A.
23.25
Example 23.5
What is the size of the window for host A if the value of rwnd is 3000 bytes and the value of cwnd is
3500 bytes?
Solution
The size of the window is the smaller of rwnd and cwnd, which is 3000 bytes.
23.26
Example 23.6
Figure 23.23 shows an unrealistic example of a sliding window. The sender has sent bytes up to
202. We assume that cwnd is 20 (in reality this value is thousands of bytes). The receiver has sent
an acknowledgment number of 200 with an rwnd of 9 bytes (in reality this value is thousands of
bytes). The size of the sender window is the minimum of rwnd and cwnd, or 9 bytes. Bytes 200 to
202 are sent, but not acknowledged. Bytes 203 to 208 can be sent without worrying about
acknowledgment. Bytes 209 and above cannot be sent.
23.27
Figure 23.23 Example 23.6
23.28
Note
Some points about TCP sliding windows:
❏ The size of the window is the lesser of rwnd and
cwnd.
❏ The source does not have to send a full window’s
worth of data.
❏ The window can be opened or closed by the
receiver, but should not be shrunk.
❏ The destination can send an acknowledgment at
any time as long as it does not result in a shrinking
window.
❏ The receiver can temporarily shut down the
window; the sender, however, can always send a
segment of 1 byte after the window is shut down.
23.29
Note
ACK segments do not consume sequence numbers and are not
acknowledged.
23.30
Note
In modern implementations, a retransmission occurs if the
retransmission timer expires or three duplicate ACK segments have
arrived.
23.31
Note
No retransmission timer is set for an ACK segment.
23.32
Note
Data may arrive out of order and be temporarily stored by the
receiving TCP,
but TCP guarantees that no out-of-order segment is delivered to the
process.
23.33
Figure 23.24 Normal operation
23.34
Figure 23.25 Lost segment
23.35
Note
The receiver TCP delivers only ordered data to the process.
23.36
Figure 23.26 Fast retransmission
23.37