Prerequisite – TCP | Services and Segment structure

Transmission Control Protocol (TCP) is one of the most important protocols of internet protocol. It provides full transport layer service to applications and generates a virtual circuit between sender and receiver that is active for the duration of transmission. Its segment consists of a TCP header, TCP options and the data that the segment transports.

**Sequence Numbers –**

The 32 bit sequence number field defines the number assigned to the first byte of data contained in this segment. TCP is a stream transport protocol. To ensure connectivity, each byte to be transmitted is numbered. During connection establishment each party uses a Random number generator to create initial sequence number (ISN), which is usually different in each direction. We know that a TCP sequence number is 32 bit. So it has finite (from 0 to (2^{32}-1) = 4 Giga sequence numbers) and it means we will be able to send only 4GB of data with unique sequence number not more than that. It helps with the allocation of a sequence number that does not conflict with other data bytes transmitted over a TCP connection. An ISN is unique to each connection and separated by each device.

** Wrap Around Concept –**

It can happen at high rate of traffic, all the sequence number got used up. Sequence number for every packet has to be unique, but since it is finite (4 Giga) at some point of time the Sequence number is completely consumed up. The sequence numbers which were used, when available can be used again as per requirement and this reusing of sequence numbers is known as **Wrap around concept**.

In simple words “Using the sequence numbers again and again once all of them got used up, in order to maintain the continuity of data transfer ” is called Wrap around concept. This helps to send more and more data without worrying about how much data is to be sent.As the sequence numbers can be used again and again, so there is no limit on quantity of data.

**When and how wrap around is implemented? **

For example if I am downloading a software of size 4GB+ 2 byte, but the sequence number available is only 4GB the rest two byte won’t get any sequence number. In these kind of cases the sequence numbers are wrapped, i.e., they are used again and again as per the requirement. This wrapping is affected by the random initial sequence number. We may get lesser number of sequence number in the beginning but after all sequence number is consumed again the sequence number will start from 0.

From wherever we start using sequence number we will get 2^{32} sequence number. Hence we can say that reusing a sequence number as per the requirement is the wrap concept of the TCP sequence number. Now if we have wrap concept then a new concept comes, i.e., *Wrap Around Time* which depends on wrap around of sequence numbers.

**Wrap Around Time –**

Time taken to wrap around is called wrap around time. It means if we start from sequence number 0 (or it may be anything), after how much time we are going to again use this same sequence number. Wrap around time is the time taken to start reusing the same sequence number also it can be said that the time taken to repeat the sequence number as per the requirement. Wrap around time depends on the number of sequence number and bandwidth. As the bandwidth is the rate of bits at which bits (sequence number) are consumed. The faster is the consumption rate, the faster is the consumption of sequence number.

Wrap Around Time = (Total sequence number) / (Bandwidth) = (2^{32}) / (Bandwidth)

**Why is Wrap Around possible?**

There is a concept termed as **Life Time**, in worst case a packet will require 3 minutes (180sec) to reach the destination (i.e., the life time of the packet). In today’s technology the same sequence number will be available after 180 sec but we are not going to use it before wrap around time. As long as *Wrap Around Time > Life Time* of a packet there will be no problem in using the same sequence number. After wrap around time the life time of the segments finishes, it means in that very time, timeout occurs. After all sequence numbers are used and their life time finishes there is no harm in using the same sequence number again.

**Reducing Wrap Around Time –**

If the total number of bits to be consumed is equal to the sequence number then there will be no need to wrap around the sequence number. But this is not possible and we are going to use wrap around concept. Since wrap around time is directly dependent on number of Sequence number and inversely dependent on Bandwidth (Rate at which data will flow).

More the Sequence numbers available, higher will be wrap around time.Lesser the bandwidth, higher the wrap around time. So in order to reduce the wrap around time we need to:

- Reduce the sequence numbers or
- Increase the bandwidth (possible)

**Example-1:** Given n bits how many sequence numbers are possible?

**Explanation –**

For 1 bit, 2 numbers are possible, i.e., 0 and 1

For 2 bits, 4 numbers are possible, i.e., 00, 01, 10, 11

for 3 bits 8 numbers are possible, i.e., 000, 001, 010, 011, 100, 101, 110, 111 .. and so on

for n bits 2^n numbers are possible i.e., from 0 to 2^{n}-1 (in binary).

**Example-2:** Given n number of sequence numbers how many bits are required to represent the set?

**Explanation –**

Let we need x number of bits, we know that 2^{x} = n

=> x log(2) = log(n)

We will have,

=> x = log(n)

Taking base 2 of given logs.

**Example-3:** Bandwidth of channel is given as 1 Gbps. How long can a packet stay in link without worrying about problem of having 2 packets with same sequence numbers?

**Explanation –**

Bandwidth = 1 GBps = 2^{30}Sequence numbers = 2^{32}So, Wrap around time: = Sequence number/Bandwidth =2^{32}/ 2^{30}=2^{2}=4 seconds

**Example-4:** GATE-CS-2014-(Set-3) | Question 65

**Example-5:** GATE CS 2018 | Question 32

## leave a comment

## 0 Comments