Search code examples
tcp

Why do tcp implementation use byte sequence number and not segment number for flow control?


For the flow control TCP uses Sequence number and acknowledgement number which are the starting byte number in the segment.

While the segment is sent or received it goes as a whole. So from the socket perspective, either a segment as a whole is received or the complete packet containing the segment was lost.

example: If the segments are created as follows:

Segment 1: seq 1 to seq 1000

Segment 2: seq 1001 to seq 2000

Segment 3: seq 2001 to seq 3000

If the packet containing segment 2 (seq 1001 to 2000) is dropped, the receiving end does not receive seq 1000 to 2000. There isn't a way that it will receive part of the segment. So the receiver sends ack for 1001.

While implementing TCP why did the creators not use segment numbers? Like in the above example sender could send sequence number as segment 1,2 and 3 and the receiver could use acknowledgement number as segment 1,2 and 3. If there is a drop receiver could send ack for the next expected segment (Segment 2 in our example)

This is could have saved space in each TCP header.


Solution

  • Because the window size can vary based on the congestion of the network. Therefore, the segment size can also vary. So using the sequence number for byte is more appropriate than for segment.

    If one of your segments is lost, you have to retransmit it but maybe with another segment size (maybe a smaller size if the network is congested). So, if you use sequence number for segment then it exists a case as below:

    1. You transmit 3 segments segment 1, 2, and 3, each with size 100 bytes
    2. Segment 2 is somehow lost and you need to retransmit segment 2 and segment 3 but with different sizes. Now let's assume you will retransmit segment 2' with size 50 bytes, segment 3' with size 50 bytes, segment 4' with size 50 bytes, and segment 5' with size 50 bytes due to the congestion of the network.
    3. Now the segment 2' arrives first, then the old segment 3 arrives (maybe due to some congestion or long buffer or propagation delay or something).
    4. At the receiving host, it will receive segment 1, segment 2' and segment 3 and later when it receives segment 3', it will discard it.
    5. The receiving host will also receive segment 4' and segment 5.

    Now, you have no clue to determine what has gone wrong and you have to retransmit the whole message again.