Tag: TCP 3 Way Handshake

TCP Retransmission | TCP Duplicate ACK

Three Way Handshake-

 

Before you go through this article, make sure that you have gone through the previous article on Three Way Handshake.

 

We have discussed-

  • TCP uses Three Way Handshake to establish a connection between the sender and receiver.
  • Connection establishment using Three Way Handshake involves the steps as shown-

 

 

In this article, we will discuss how a lost TCP segment is retransmitted.

 

TCP Retransmission-

 

After establishing the connection,

  • Sender starts transmitting TCP segments to the receiver.
  • A TCP segment sent by the sender may get lost on the way before reaching the receiver.
  • This causes the receiver to send the acknowledgement with same ACK number to the sender.
  • As a result, sender retransmits the same segment to the receiver.
  • This is called as TCP retransmission.

 

When TCP Retransmission Occurs?

 

When sender discovers that the segment sent by it is lost,

it retransmits the same segment to the receiver.

 

Sender discovers that the TCP segment is lost when-

  1. Either Time Out Timer expires
  2. Or it receives three duplicate acknowledgements

 

1. Retransmission After Time Out Timer Expiry-

 

Each time sender transmits a TCP segment to the receiver, it starts a Time Out Timer.

Now, following two cases are possible-

 

Case-01:

 

  • Sender receives an acknowledgement for the sent segment before the timer goes off.
  • In this case, sender stops the timer.

 

Case-02:

 

  • Sender does not receives any acknowledgement for the sent segment and the timer goes off.
  • In this case, sender assumes that the sent segment is lost.
  • Sender retransmits the same segment to the receiver and resets the timer.

 

Also Read- Time Out Timer

 

Example-

 

 

2. Retransmission After Receiving 3 Duplicate Acknowledgements-

 

  • Consider sender receives three duplicate acknowledgements for a TCP segment sent by it.
  • Then, sender assumes that the corresponding segment is lost.
  • So, sender retransmits the same segment without waiting for its time out timer to expire.
  • This is known as Early retransmission or Fast retransmission.

 

Example-

 

Consider-

  • Sender sends 5 TCP segments to the receiver.
  • The second TCP segment gets lost before reaching the receiver.

 

The sequence of steps taking place are-

 

  • On receiving segment-1, receiver sends acknowledgement asking for segment-2 next.

(Original ACK)

  • On receiving segment-3, receiver sends acknowledgement asking for segment-2 next.

(1st duplicate ACK)

  • On receiving segment-4, receiver sends acknowledgement asking for segment-2 next.

(2nd duplicate ACK)

  • On receiving segment-5, receiver sends acknowledgement asking for segment-2 next.

(3rd duplicate ACK)

 

Now,

  • Sender receives 3 duplicate acknowledgements for segment-2 in total.
  • So, sender assumes that the segment-2 is lost.
  • So, it retransmits segment-2 without waiting for its timer to go off.

 

 

NOTE

After receiving the retransmitted segment-2,

  • Receiver does not send the acknowledgement asking for segment-3 or 4 or 5.
  • Receiver sends the acknowledgement asking for segment-6 directly from the sender.
  • This is because previous segments have been already received and acknowledgements for them have been already sent (although wasted in asking for segment-2).

 

Important Points-

 

Point-01:

 

  • Consider time out timer expires before receiving the acknowledgement for a TCP segment.
  • This case suggests the stronger possibility of congestion in the network.

 

Point-02:

 

  • Consider sender receives 3 duplicate acknowledgements for the same TCP segment.
  • This case suggests the weaker possibility of congestion in the network.

 

Point-03:

 

  • Consider receiver does not receives 3 duplicate acknowledgements for the lost TCP segment.
  • In such a case, retransmission occurs only after time out timer goes off.

 

Point-04:

 

  • Retransmission on receiving 3 duplicate acknowledgements is a way to improve the performance over retransmission on time out.

 

Also Read- TCP Congestion Control

 

PRACTICE PROBLEM BASED ON TCP RETRANSMISSION-

 

Problem-

 

Consider a TCP connection in a state where there are no outstanding ACKs. The sender sends two segments back to back. The sequence numbers of the first and second segments are 230 and 290 respectively. The first segment was lost but the second segment was received correctly by the receiver.

Let X be the amount of data carried in the first segment (in bytes) and Y be the ACK number sent by the receiver.

The values of X and Y are-

  1. 60 and 290
  2. 230 and 291
  3. 60 and 231
  4. 60 and 230

 

Solution-

 

It is given that sender sends two segments where-

  • 1st segment contains the sequence number 230 and gets lost.
  • 2nd segment contains the sequence number 290 and is received correctly.

 

Amount Of Data Sent In First Segment-

 

Given-

  • Sequence number of 1st segment = 230
  • Sequence number of 2nd segment = 290

 

From here, range of sequence numbers contained in the 1st segment = [230,289].

 

Now,

  • Total number of sequence numbers contained in the 1st segment = 289 – 230 + 1 = 60.
  • TCP assigns one sequence number to each byte of data.
  • Thus, Amount of data contained in the first segment = 60 bytes.

 

ACK Number Sent By Receiver-

 

On receiving the 2nd segment,

  • Receiver sends the acknowledgement asking for the first segment only.
  • This is because it expects the 1st segment first.
  • Receiver keeps sending this ACK number until it receives the first segment correctly.
  • Thus, Acknowledgement number = Sequence number of the 1st segment = 230.

 

Thus, Option (D) is correct.

 

Next Article- TCP Connection Termination

 

Get more notes and other study material of Computer Networks.

Watch video lectures by visiting our YouTube channel LearnVidFun.

3 Way Handshake | TCP Connection

Transmission Control Protocol-

 

Before you go through this article, make sure that you have gone through the previous article on TCP in Networking.

 

We have discussed-

  • TCP establishes an end to end connection between the sender and receiver.
  • This connection is established before exchanging the data.
  • TCP connection is reliable and ensures in order delivery.

 

Also Read- TCP Header

 

In this article, we will discuss how a TCP connection is established.

 

3 Way Handshake-

 

Three Way Handshake is a process used for establishing a TCP connection.

 

Consider-

  • Client wants to establish a connection with the server.
  • Before Three Way Handshake, both client and server are in closed state.

 

TCP Handshake involves the following steps in establishing the connection-

 

Step-01: SYN-

 

For establishing a connection,

  • Client sends a request segment to the server.
  • Request segment consists only of TCP Header with an empty payload.
  • Then, it waits for a reply segment from the server.

 

 

Request segment contains the following information in TCP header-

  1. Initial sequence number
  2. SYN bit set to 1
  3. Maximum segment size
  4. Receiving window size

 

1. Initial Sequence Number-

 

  • Client sends the initial sequence number to the server.
  • It is contained in the sequence number field.
  • It is a randomly chosen 32 bit value.

 

2. SYN Bit Set To 1-

 

Client sets SYN bit to 1 which indicates the server-

  • This segment contains the initial sequence number used by the client.
  • It has been sent for synchronizing the sequence numbers.

 

Also Read- TCP Sequence Number

 

3. Maximum Segment Size (MSS)-

 

  • Client sends its MSS to the server.
  • It dictates the size of the largest data chunk that client can send and receive from the server.
  • It is contained in the Options field.

 

4. Receiving Window Size-

 

  • Client sends its receiving window size to the server.
  • It dictates the limit of unacknowledged data that can be sent to the client.
  • It is contained in the window size field.

 

Step-02: SYN + ACK-

 

After receiving the request segment,

  • Server responds to the client by sending the reply segment.
  • It informs the client of the parameters at the server side.

 

 

Reply segment contains the following information in TCP header-

  1. Initial sequence number
  2. SYN bit set to 1
  3. Maximum segment size
  4. Receiving window size
  5. Acknowledgment number
  6. ACK bit set to 1

 

1. Initial Sequence Number-

 

  • Server sends the initial sequence number to the client.
  • It is contained in the sequence number field.
  • It is a randomly chosen 32 bit value.

 

2. SYN Bit Set To 1-

 

Server sets SYN bit to 1 which indicates the client-

  • This segment contains the initial sequence number used by the server.
  • It has been sent for synchronizing the sequence numbers.

 

3. Maximum Segment Size (MSS)-

 

  • Server sends its MSS to the client.
  • It dictates the size of the largest data chunk that server can send and receive from the client.
  • It is contained in the Options field.

 

4. Receiving Window Size-

 

  • Server sends its receiving window size to the client.
  • It dictates the limit of unacknowledged data that can be sent to the server.
  • It is contained in the window size field.

 

5. Acknowledgement Number-

 

  • Server sends the initial sequence number incremented by 1 as an acknowledgement number.
  • It dictates the sequence number of the next data byte that server expects to receive from the client.

 

6. ACK Bit Set To 1-

 

  • Server sets ACK bit to 1.
  • It indicates the client that the acknowledgement number field in the current segment is valid.

 

Step-03: ACK-

 

After receiving the reply segment,

  • Client acknowledges the response of server.
  • It acknowledges the server by sending a pure acknowledgement.

 

 

With these, a Full Duplex connection is established.

 

Important Points-

 

Point-01:

 

In step-01 and step-02-

  • The connection parameters are established for the first side.
  • They are acknowledged by the second side.

 

In step-02 and step-03-

  • The connection parameters are established for the second side.
  • They are acknowledged by the first side.

 

Point-02:

 

Connection establishment phase consume 1 sequence number of both the sides.

 

  • Request segment consumes 1 sequence number of the requester.
  • Reply segment consumes 1 sequence number of the respondent.
  • Pure acknowledgements do not consume any sequence number.

 

Point-03:

 

Pure acknowledgement for the reply segment is not necessary.

 

This is because-

  • If client sends the data packet immediately, then it will be considered as an acknowledgement.
  • It means that in the first two steps only, the full duplex connection is established.

 

Point-04:

 

For all the segments except the request segment, ACK bit is always set to 1.

 

This is because-

  • For the request segment, acknowledgement number field will always be invalid.
  • For all other segments, acknowledgement number field will always be valid.

 

Point-05:

 

Certain parameters are negotiated during connection establishment.

 

The negotiation can be on setting the values of following parameters-

  1. Window size
  2. Maximum segment size
  3. Timer values

 

Point-06:

 

In any TCP segment,

  • If SYN bit = 1 and ACK bit = 0, then it must be the request segment.
  • If SYN bit = 1 and ACK bit = 1, then it must be the reply segment.
  • If SYN bit = 0 and ACK bit = 1, then it can be the pure ACK or segment meant for data transfer.
  • If SYN bit = 0 and ACK bit = 0, then this combination is not possible.

 

Point-07:

 

  • The combination SYN bit = 0 and ACK bit = 0 is not possible.
  • It is because SYN bit = 0 signifies it is not the request segment and reply segment.
  • For all other segments, ACK bit is always set to 1.

 

Point-08:

 

  • Consider sender sends the segments of size greater than MSS of receiver.
  • Then, they are first fragmented first at the receiver side.
  • It causes an extra overhead.

 

Point-09:

 

  • There is no dedicated field for sending MSS in TCP header.
  • This is because MSS has to informed only once.
  • So, if dedicated field would be present, then sending it each time would not be required.
  • For this reason, MSS is informed once using Options field.

 

Also Read- TCP Connection Termination

 

PRACTICE PROBLEMS BASED ON THREE WAY HANDSHAKE-

 

Problem-01:

 

SYN = 0 and ACK = 1 indicates-

  1. Open connection packet
  2. Open connection ACK
  3. Data packet
  4. ACK packet

 

Solution-

 

Options (C) and (D) are correct.

 

Problem-02:

 

An acknowledgement by TCP sender guarantees-

  1. Data has been delivered to the application
  2. Data has been received by TCP module
  3. Data has been received by application interface
  4. None of the above

 

Solution-

 

Option (A) is correct.

 

To gain better understanding about Three Way Handshake,

Watch this Video Lecture

 

Next Article- TCP Retransmission

 

Get more notes and other study material of Computer Networks.

Watch video lectures by visiting our YouTube channel LearnVidFun.

TCP Connection Termination | FIN Segment

Three Way Handshake-

 

Before you go through this article, make sure that you have gone through the previous article on Three Way Handshake.

 

We have discussed-

  • TCP uses Three Way Handshake to establish a connection between the sender and receiver.
  • Connection establishment using Three Way Handshake involves the steps as shown-

 

 

Also Read- TCP Retransmission

 

In this article, we will discuss how a TCP connection is terminated.

 

TCP Connection Termination-

 

A TCP connection is terminated using FIN segment where FIN bit is set to 1.

 

Consider-

  • There is a well established TCP connection between the client and server.
  • Client wants to terminate the connection.

 

The following steps are followed in terminating the connection-

 

Step-01:

 

For terminating the connection,

  • Client sends a FIN segment to the server with FIN bit set to 1.
  • Client enters the FIN_WAIT_1 state.
  • Client waits for an acknowledgement from the server.

 

 

Step-02:

 

After receiving the FIN segment,

  • Server frees up its buffers.
  • Server sends an acknowledgement to the client.
  • Server enters the CLOSE_WAIT state.

 

 

Step-03:

 

After receiving the acknowledgement, client enters the FIN_WAIT_2 state.

 

Now,

  • The connection from client to server is terminated i.e. one way connection is closed.
  • Client can not send any data to the server since server has released its buffers.
  • Pure acknowledgements can still be sent from the client to server.
  • The connection from server to client is still open i.e. one way connection is still open.
  • Server can send both data and acknowledgements to the client.

 

 

Step-04:

 

Now, suppose server wants to close the connection with the client.

 

For terminating the connection,

  • Server sends a FIN segment to the client with FIN bit set to 1.
  • Server waits for an acknowledgement from the client.

 

 

NOTE

If server wanted,

It could have sent the FIN segment along with the previous acknowledgment that it sent to the client.

 

Step-05:

 

After receiving the FIN segment,

  • Client frees up its buffers.
  • Client sends an acknowledgement to the server (not mandatory).
  • Client enters the TIME_WAIT state.

 

 

TIME_WAIT State-

 

  • The TIME_WAIT state allows the client to resend the final acknowledgement if it gets lost.
  • The time spent by the client in TIME_WAIT state depends on the implementation.
  • The typical values are 30 seconds, 1 minute and 2 minutes.
  • After the wait, the connection gets formally closed.

 

Next Article- Practice Problems On TCP

 

Get more notes and other study material of Computer Networks.

Watch video lectures by visiting our YouTube channel LearnVidFun.