Timer in TCP

Types of timer:
To perform its operation smoothly, most TCP implementation uses at least four timers.

1.      Retransmission Timer
2.      Persistence Timer
3.      Keep-alive Timer
4.      TIME-WAIT Timer

1. Retransmission Timeer:
Sender sends a segment of 8 bytes data segment number will be the 1st byte of the data. So if sender sends segment 92 and it reached and receiver send ACK for next segment 100. But the ACK lost. It will be timeout and sender will send again segment 92. So this will make duplicate of segment 92.

In the another case can be happen. Sender sends two segments 92 (8 bytes) and 100 (20 bytes) and receiver get both segment and ACK for 100 when get 92 and ACK for 120 when get 100 but ACK 100 reached after timeout and sender sends again segment 92. So this will also make duplicate of segment 92

This is a big problem. But if it can change its timer’s duration long then it will get the ACK of segment 100 in time and sender will not retransmit segment 92. TCP solve this problem by making the timeout time longer than Round Trip Time (RTT).  And save the unnecessary retransmission.
But the question is how much larger than RTT?
So we calculate RTT first. What is RTT? The time between a segment send from sender to receiver and receiver ACK for this segment and it reached to sender from receiver is called RTT. (we will learn in timestamp option details on RTT)
If we called this RTT as NewRTT then the final timeout measured if we called it TotalRTT then the equation is

TotalRTT  = (1-a) * TotalRTT + a * NewRTT

The recommended value of a = 1/8=0.125 then

TotalRTT = (1-0.125) * TotalRTT + 0.125 * NewRTT
Such an avarage is called Exponential Weighted Moving Average (EWMA)

But most TCP is not happy to make the timeout equal to the TotalRTT. It adds some extra margin with it. The margin should be large when there is a lot of fluctuation in the NewRTT values and small for little fluctuation. So the another value is calculate for RTT variation. It estimates how much NewRTT typically deviates from TotalRTT. Which we can call DevRTT. So

DevRTT = (1-b) * DevRTT + b * | NewRTT – TotalRTT |
The value of b=0.25

TCP consider for determine the Retransmission timeout interval is

TimeoutInterval = TotalRTT + 4 * DevRTT

            If data send but data but not gets no ACK during the retransmission period and is retransmitted. When the sending TCP receives an ACK for this segment, it does not know if the ACK is for the original segment or for retransmitted one. The value of the new RTT is based on the departure of the retransmitted segment. If the ACK is actually for the original segment then the calculation will be wrong. This is the dilemma that was solved by Karn’s solution.

Karn’s Algorithm:
This is very simple. In this algorithm, RTT is not calculated or consider when retransmission needed for a segment. So, do not update the value of RTT until send a segment and receive an acknowledgement without retransmission.

What is the value of RTO (retransmission time-out) if a retransmission occurs? Most TCP implementations use an exponential backoff strategy.

Exponential Backoff:
RTO means sender TCP start timer for the segment sends each time. In exponential backoff strategy if it needs to retransmit the segment for the first time value of RTO is set double of the original RTO. If it needs to retransmit the segment for the 2nd time value of RTO is set 4 times.

2. Persistence Timer:
We learn the deadlock situation. When receiving TCP sends a non-zero window size ACK, and the ACK is lost the sender waits for the ACK and the receiver thinks that sender will start to send data. Both TCP can continue to wait forever.
            To correct this deadlock, TCP uses a persistence timer for each connection. When the sending TCP receives an ACK with window size of 0, it starts a persistence timer. When the timers time out then sender sends a special segment called a probe. This segment contains only 1 byte of data. It has a sequence number but never gets ACK. The probe alerts the receiver that the ACK was lost and must be resent.
            The value of the persistence timer is set to the value of the retransmission time. If no response from receiver another probe is sent and the value of the persistence timer is set doubled. The sender sends the probe and each time set the value double. If the value reaches the threshold (usually 60 s), after that the sender sends probe every 60 seconds until the receiver responed.

3. Keepalive Timer:
A keepalive timer is used in some implementations to prevent a long idle connection between two TCPs. For example server connected with clients but client crash. In this case the connection remains open forever.
            To avoid this situation, each time the server hears from a client, it resets this timer. The time-out is usually 2 hours. If no response from client, server sends a probe. If there is no response, after each 75seconds from 1st probe, server sends probe. After 10 probes server terminates the connection.

4. TIME-WAIT Timer: 
This timer set during the connection termination of a client with the server. Client TCP sends a segment FIN segment and server sends ACK then server sends FIN segment and then client sends ACK. After that connection is not closed and client waits for a time. TIME-WAIT timer calculates this time. The value of the timer is the twice of the maximum segment lifetime (MSL). We know IP datagram encapsulated in an IP datagram, which has a TTL value. When IP datagram dropped, the encapsulated TCP segment is also dropped. 
We will see this timer in Connection Life Cycle at client TCP




Click image to go:
http://nadimall.blogspot.com/2013/10/turorial-list.html

http://www.facebook.com/nadimallblog?ref=aymt_homepage_panel

to share this page with your friends, select below

No comments:

Post a Comment