Tag: Sequence Number in Networking

TCP Sequence Number | Wrap Around Time

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 continuously receives data from the application layer.
  • It divides the data into chunks where each chunk is a collection of bytes.
  • It then creates TCP segments by adding a TCP header to the data chunks.

 

TCP segment = TCP header + Data chunk

 

Also Read- TCP Header

 

In this article, we will discuss about TCP Sequence Number.

 

TCP Sequence Number-

 

  • Each TCP segment sent by the sender contains some bytes of data.
  • TCP assigns a unique number to each data byte for its identification.
  • This unique number is called as TCP Sequence Number.

 

Purpose-

 

Sequence number serves the following purposes-

  • It helps to identify each data byte uniquely.
  • It helps in the segmentation of data into TCP segments and reassemble them later.
  • It helps to keep track of how much data has been transferred and received.
  • It helps to put the data back into the correct order if it is received in the wrong order.
  • It helps to request data when it has been lost in transit.

 

Maximum Number of Sequence Numbers-

 

  • In TCP header, sequence number is a 32 bit field.
  • So, maximum number of possible sequence numbers = 232.
  • These sequence numbers lie in the range [0 , 232 – 1].

 

NOTE-

 

  • Maximum number of possible sequence numbers = 232.
  • This does not imply that only 232 bytes = 4 GB data can be sent using TCP.
  • The concept of wrap around allows to send unlimited data using TCP.

 

Concept Of Wrap Around-

 

The concept of wrap around states-

 

After all the 232 sequence numbers are used up and more data is to be sent,

the sequence numbers can be wrapped around and used again from the starting.

 

In general,

  • If the initial sequence number chosen is X.
  • Then sequence numbers are used from X to 232 – 1 and then from to 0 to X-1.
  • Then, sequence numbers are wrapped around to send more data.

 

Example-

 

  • Consider the initial sequence number used is 0.
  • Then after sending 4 GB data, all the sequence numbers would get used up.
  • To send more data, sequence numbers are reused from the starting.
  • Wrapping around can be done again and again to send more and more data.

 

Wrap Around Time-

 

  • Time taken to use up all the 232 sequence numbers is called as wrap around time.
  • It depends on the bandwidth of the network i.e. the rate at which the bytes go out.
  • More the bandwidth, lesser the wrap around time and vice versa.

 

Wrap Around Time ∝ 1 / Bandwidth

 

Formula-

 

If bandwidth of the network = x bytes/sec, then-

 

 

Life Time Of TCP Segment-

 

In modern computers,

  • Life time of a TCP segment is 180 seconds or 3 minutes.
  • It means after sending a TCP segment, it might reach the receiver taking 3 minutes in the worst case.

 

How Wrap Around Is Possible?

 

It is possible to wrap around the sequence numbers because-

  • The life time of a TCP segment is just 180 seconds.
  • Wrap around time is much greater than life time of a TCP segment.
  • So, by the time the sequence numbers wrap around, there is no probability of existing any segment having the same sequence number.
  • Thus, even after wrapping around, the sequence number of all the bytes will be unique at any given time.

 

Reducing Wrap Around Time-

 

Wrap around time can be reduced to the life time of a TCP segment.

 

This is because-

  • After the life time of a segment completes, it is considered that the segment no longer exists.
  • So, sequence numbers used by the segment frees up and can be reused.

 

To reduce the wrap around time to the life time of segment,

  • There must exist as many sequence numbers as there are number of data bytes sent in time equal to life time of segment.

 

Formula-

 

Number of bits required in the sequence number field

so that wrap around time becomes equal to lifetime of TCP segment

= log2 (lifetime of TCP segment x Bandwidth)

 

  • The number of bits will be greater than 32 bits.
  • The extra bits are appended in the Options field of TCP header.

 

PRACTICE PROBLEMS BASED ON WRAP AROUND TIME IN TCP-

 

Problem-01:

 

Given the bandwidth of a network is 1 MB / sec. Calculate the wrap around time.

 

Solution-

 

We know,

  • Wrap around time = Time taken to use all the 232 sequence numbers.
  • TCP assigns 1 sequence number to each byte of data.

 

To calculate wrap around time, we just need to calculate how much time will be taken to send 232 bytes of data.

 

Now,

  • Given bandwidth = 1 MB / sec = 106 bytes / sec.
  • It means 106 bytes of data is sent in time = 1 sec.
  • So, 232 bytes of data will be sent in time = ( 1 / 106 ) x 232 sec.
  • On solving, we get 1.19 hours.

 

Thus,

  • It will take 1.19 hours to consume all the 232 sequence numbers if bandwidth = 1 MB / sec.
  • Wrap Around Time = 1.19 hours.

 

Alternatively,

Using the formula, we have-

Wrap Around Time

= 232 / 106 sec

= 1.19 hours

 

Problem-02:

 

If bandwidth of the network is 1 GBps, how many extra bits will have to be appended in the Options field so that wrap around time becomes equal to the life time of segment?

 

Solution-

 

For wrap around time to become equal to the life time of TCP segment,

Number of sequence numbers required = Number of bytes sent in life time of TCP segment

 

We know-

  • Life time of TCP segment = 180 sec.
  • Bandwidth of the network = 1 GBps (Given)

 

Now,

  • Number of bytes transferred in 1 sec = 1 GB
  • So, number of bytes transferred in 180 sec = 180 GB = 180 x 230 bytes
  • So, number of sequence numbers required = 180 x 230

 

Suppose y number of bits in the sequence number field are required to represent the value 180 x 230.

 

So, we have-

2y = 180 x 230

ylog2 = log(180 x 230)

y = log2(180 x 230)

y = log2180 + log2230

y = 7.49 + 30

y ≅ 38

 

From here,

  • Total number of bits required for sequence numbers = 38 bits.
  • In TCP header, sequence number field is a 32 bit field.
  • So, extra bits required to be appended in the Options field = 38 – 32 = 6 bits.

 

Alternatively,

Using the formula, we have-

Total bits required

= log2 (life time of TCP segment x bandwidth)

= log2 ( 180 x 230)

= log2180 + log2230

= 7.49 + 30

= 38

 

From here,

  • Total number of bits required for sequence numbers = 38 bits.
  • In TCP header, sequence number field is a 32 bit field.
  • So, extra bits required to be appended in the Options field = 38 – 32 = 6 bits.

 

Problem-03:

 

In a network that has a maximum TPDU size of 128 bytes, a maximum TPDU lifetime of 30 sec and 8 bit sequence number, what is the maximum data rate per connection?

(TPDU is Transport layer protocol data unit which is the segment.)

 

Solution-

 

Given-

  • Maximum segment size (MSS) = 128 bytes
  • Segment lifetime = 30 sec
  • Bits in sequence number = 8

 

Now,

  • Maximum number of possible sequence numbers using 8 bits = 28 = 256.
  • So, maximum number of bytes that can be uniquely identified = 256 bytes.
  • Lifetime of a segment = 30 seconds.
  • So, maximum amount of data that can be sent in 30 seconds = 256 bytes.

 

Thus,

Maximum data rate per connection

= 256 bytes / 30 seconds

≈ 68 bits/sec

 

Problem-04:

 

Suppose that the advertised window 1 MB long. If a sequence number is selected at random from the entire sequence number space, what is the probability that the sequence number falls inside the advertised window?

 

Solution-

 

We know,

  • Number of bits in sequence number field = 32 bits.
  • So, Maximum number of sequence numbers possible = 232.
  • 232 bytes of data can be labeled uniquely with these sequence numbers.
  • Advertised window size = 1 MB = 220 bytes which uses 220 sequence numbers.

 

Therefore,

Required probability

= 220 / 232

= 1 / 212

 

Next Article- Three Way Handshake

 

Get more notes and other study material of Computer Networks.

Watch video lectures by visiting our YouTube channel LearnVidFun.