TCP uses several timers to ensure that excessive delays are not encountered during communications. Several of these timers are elegant, handling problems that are not immediately obvious at first analysis. Each of the timers used by TCP is examined in the following sections, which reveal its role in ensuring data is properly sent from one connection to another.
TCP implementation uses four timers –
Retransmission Timer – To retransmit lost segments, TCP uses retransmission timeout (RTO). When TCP sends a segment the timer starts and stops when the acknowledgment is received. If the timer expires timeout occurs and the segment is retransmitted. RTO (retransmission timeout is for 1 RTT) to calculate retransmission timeout we first need to calculate the RTT(round trip time).
RTT three types –
Measured RTT(RTTm) – The measured round-trip time for a segment is the time required for the segment to reach the destination and be acknowledged, although the acknowledgement may include other segments.
Smoothed RTT(RTTs) – It is the weighted average of RTTm. RTTm is likely to change and its fluctuation is so high that a single measurement cannot be used to calculate RTO.
2. Retransmission timer
• For lost or discarded segment, TCP employs a retransmission timer
• Measures waiting time for an ack of a segment
• When TCP sends a segment, time is created for that segment
• If an ack is received for the segment before timer expires, timer is destroyed
• If timer expires before ack arrives, the segment is retransmitted and timer is
reset
3. Retransmission timer
● Different connections require different retransmission time settings
● If the retransmission time is set too short, acks will not have time to return &
segments will be prematurely retransmitted
● If the retransmission time is set too long, sending process will wait
unnecessarily for retransmissions to occur
● Retransmission timers should not be fixed even for one connection due to
changing traffic levels
4. Persistence timer
• Addresses zero (0) window size advertisement
• Sender will stop sending until ack received from destination TCP
• If ack gets lost, destination TCP will wait indefinitely for more data from the
sender
• This deadlock situation must be avoided
• After persistence timer elapses, sender sends a probe segment (only 1 byte)
• Probe alerts destination TCP that ack was lost and must be resent
5. Keep Alive timer
• Implemented in some TCP servers
• Prevents a long idle connection between two connected TCP implementations
• Timer is typically set at 2 hours
• After timer elapses, 10 “probe” segments are rapidly sent
• If no response after 10 probes, it is assumed that the client is down so
connection is terminated
6. Time-waited timer
• Used during connection termination
• Keeps connection alive long enough for any remaining FIN segments to arrive
(which are then discarded)
• The MSL is the maximum time a segment can exist in the Internet before it is
dropped.The common value for MSL is between 30 seconds and 1 minute.
Persistence Timer To deal with a zero-window-size advertisement, TCP needs another timer. If the receiving TCP announces a window size of zero, the sending TCP stops transmitting segments until the receiving TCP sends an ACK segment announcing a nonzero window size. This ACK segment can be lost. Remember that ACK segments are not acknowledged nor retransmitted in TCP. If this acknowledgment is lost, the receiving TCP thinks that it has done its job and waits for the sending TCP to send more segments. There is no retransmission timer for a segment containing only an acknowledgment. The sending TCP has not received an acknowledgment and waits for the other TCP to send an acknowledgment advertising the size of the window. Both TCPs might continue to wait for each other forever (a deadlock). To correct this deadlock, TCP uses a persistence timer for each connection. When the sending TCP receives an acknowledgment with a window size of zero, it starts a persistence timer. When the persistence timer goes off, the sending TCP sends a special segment called a probe. This segment contains only 1 byte of new data. It has a sequence number, but its sequence number is never acknowledged; it is even ignored in calculating the sequence number for the rest of the data. The probe causes the receiving TCP to resend the acknowledgment. The value of the persistence timer is set to the value of the retransmission time. However, if a response is not received from the receiver, another probe segment is sent and the value of the persistence timer is doubled and reset. The sender continues sending the probe segments and doubling and resetting the value of the persistence timer until the value reaches a threshold (usually 60 s). After that the sender sends one probe segment every 60 s until the window is reopened.
A keepalive timer is used in some implementations to prevent a long idle connection between two TCPs. Suppose that a client opens a TCP connection to a server, transfers some data, and becomes silent. Perhaps the client has crashed. In this case, the connection remains open forever. To remedy this situation, most implementations equip a server with a keepalive timer. Each time the server hears from a client, it resets this timer. The time-out is usually 2 hours. If the server does not hear from the client after 2 hours, it sends a probe segment. If there is no response after 10 probes, each of which is 75 s apart, it assumes that the client is down and terminates the connection.
The TIME-WAIT (2MSL) timer is used during connection termination. The MSL is the maximum time a segment can exist in the Internet before it is dropped.The common value for MSL is between 30 seconds and 1 minute.
There are two reasons for the existence of the TIME-WAIT state and the 2SML timer:
1. If the last ACK segment is lost, the server TCP, which sets a timer for the last FIN, assumes that its FIN is lost and resends it. If the client goes to the CLOSED state and closes the connection before the 2MSL timer expires, it never receives this resent FIN segment, and consequently, the server never receives the final ACK. The server cannot close the connection. The 2MSL timer makes the client wait for a duration that is enough time for an ACK to be lost (one SML) and a FIN to arrive (another SML). If during the TIME-WAIT state, a new FIN arrives, the client sends a new ACK and restarts the 2SML timer.
2. A duplicate segment from one connection might appear in the next one. Assume a client and a server have closed a connection. After a short period of time, they open a connection with the same socket addresses (same source and destination IP addresses and same source and destination port numbers). This new connection is called an incarnation of the old one. A duplicated segment from the previous connection may arrive in this new connection and be interpreted as belonging to the new connection if there is not enough time between the two connections. To prevent this problem, TCP requires that an incarnation cannot occur unless 2MSL amount of time has elapsed.