GeeksforGeeks App
Open App
Browser
Continue

# Wrap Around Concept and TCP Sequence Number

Prerequisite – TCP | Services and Segment structure
Transmission Control Protocol (TCP) is one of the most important protocols of the 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 the 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 an 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 (232-1) = 4 Giga sequence numbers) and it means we will be able to send only 4GB of data with a 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 a high rate of traffic, all the sequence numbers got used up. The sequence number for every packet has to be unique, but since it is finite (4 Giga) at some point in 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 Wraparound 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 the 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 the quantity of data.

When and how wrap around is implemented?
For example, if I am downloading software of size 4GB+ 2 bytes, but the sequence number available is only 4GB the rest two-byte won’t get any sequence number. In this 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 a lesser number of the 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 numbers we will get 232 sequence numbers. 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 a wrap concept then a new concept comes, i.e., Wrap Around Time which depends on wrap-around 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 is as per the requirement. Wrap-around time depends on the sequence numbers 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 numbers.

```Wrap Around Time
= (Total sequence number) / (Bandwidth)
= (232) / (Bandwidth) ```

Why is Wrap Around possible?
There is a concept termed as Life Time, in the worst case a packet will require 3 minutes (180sec) to reach the destination (i.e., the lifetime 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 the time the lifetime of the segments finishes, which means in that very time, a timeout occurs. After all sequence numbers are used and their lifetime 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 a number of the Sequence numbers 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, the higher the wrap-around time. So in order to reduce the wrap-around time, we need to:

1. Reduce the sequence numbers or

2. 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 2n-1 (in binary).

Example-2: Given n number of sequence numbers how many bits are required to represent the set?
Explanation –
Let us need x number of bits, we know that 2x = 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 the link without worrying about the problem of having 2 packets with the same sequence numbers?
Explanation –

```Bandwidth = 1 GBps = 109
Sequence numbers = 232

So, Wrap around time:
= Sequence number/Bandwidth
=232 / 109
=4294967296/109
=4.294 seconds ```

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

Example-5: GATE CS 2018 | Question 32

My Personal Notes arrow_drop_up