6

I would like to know if two segments of same sequence number arrive at the destination, which segment will get accepted ?

For eg:

A clients sends a packet to a server and wait for an acknowledgement . But it didnt received the ack(due to some network problem , this segment takes time to reach the server) within the timeline so starts sending the same segment again. Now at server side, what happens if the both the packets reach at the same time.

3 Answers3

8

One packet gets marked as a duplicate and discarded. Since they're identical, it doesn't matter which one that is. See https://stackoverflow.com/questions/12871760/packet-loss-and-packet-duplication

Mike Scott
  • 8,053
  • 1
    They may not be identical, particularly if there's a malicious agent in between the endpoints. – Russell Borogove Jun 19 '15 at 22:50
  • @RussellBorogove Yes, you're correct about the malicious agent -- I was going by the example in the question of a normal delayed packet and resend. – Mike Scott Jun 20 '15 at 05:35
6

The premise that both segments arrive at the same time does not make sense. One will always arrive before the other. But that data may not have been delivered to the application before the next arrives.

According to RFC 793 the data from the first segment is to be used.

Segments are processed in sequence. Initial tests on arrival are used to discard old duplicates, but further processing is done in SEG.SEQ order. If a segment's contents straddle the boundary between old and new, only the new parts should be processed.

That said, it isn't hard to imagine implementations in reality behaving differently. In particular partially overlapping segments can be quite interesting.

kasperd
  • 30,696
4

Basically whichever is processed first will be accepted, subsequent duplicates will be dropped.

From https://www.rfc-editor.org/rfc/rfc793.txt

...first check sequence number

  SYN-RECEIVED STATE
  ESTABLISHED STATE
  FIN-WAIT-1 STATE
  FIN-WAIT-2 STATE
  CLOSE-WAIT STATE
  CLOSING STATE
  LAST-ACK STATE
  TIME-WAIT STATE

    Segments are processed in sequence.  Initial tests on arrival
    are used to discard old duplicates, but further processing is
    done in SEG.SEQ order.  If a segment's contents straddle the
    boundary between old and new, only the new parts should be
    processed.

    There are four cases for the acceptability test for an incoming
    segment:

    Segment Receive  Test
    Length  Window
    ------- -------  -------------------------------------------

       0       0     SEG.SEQ = RCV.NXT

       0      >0     RCV.NXT =< SEG.SEQ < RCV.NXT+RCV.WND

      >0       0     not acceptable

      >0      >0     RCV.NXT =< SEG.SEQ < RCV.NXT+RCV.WND
                  or RCV.NXT =< SEG.SEQ+SEG.LEN-1 < RCV.NXT+RCV.WND

    If the RCV.WND is zero, no segments will be acceptable, but
    special allowance should be made to accept valid ACKs, URGs and
    RSTs.

    If an incoming segment is not acceptable, an acknowledgment
    should be sent in reply (unless the RST bit is set, if so drop
    the segment and return):

      <SEQ=SND.NXT><ACK=RCV.NXT><CTL=ACK>

    After sending the acknowledgment, drop the unacceptable segment
    and return...