Passa al contenuto principale

Funzionamento del protocollo: arrivo dei segmenti ed eventi di timeout

3.7.2 Eventi di arrivo dei segmenti​

Gli scenari seguenti descrivono l'elaborazione dell'evento causato dall'arrivo di un segmento RDP da un host remoto. Si assume che il segmento fosse indirizzato alla porta locale associata al record di connessione.

If State = CLOSED

  If RST set
    Discard segment
    Return
  Endif

  If ACK or NUL set
     Send <SEQ=SEG.ACK + 1><RST>
     Discard segment
     Return
   else
     Send <SEQ=0><RST><ACK=RCV.CUR><ACK>
     Discard segment
     Return
  Endif

Endif

If State = CLOSE-WAIT
  If RST set
     Set State = CLOSED
     Discard segment
     Cancel TIMWAIT timer
     Deallocate connection record
   else
     Discard segment
  Endif
  Return
Endif

If State = LISTEN

  If RST set
    Discard the segment
    Return
  Endif

  If ACK or NUL set
    Send <SEQ=SEG.ACK + 1><RST>
    Return
  Endif

  If SYN set
    Set RCV.CUR = SEG.SEQ
        RCV.IRS = SEG.SEQ
        SND.MAX = SEG.MAX
        SBUF.MAX = SEG.BMAX
    Send <SEQ=SND.ISS><ACK=RCV.CUR><MAX=RCV.MAX><BUFMAX=RBUF.MAX>
         <ACK><SYN>
    Set State = SYN-RCVD
    Return
  Endif

  If anything else (should never get here)
    Discard segment
    Return
  Endif
Endif

If State = SYN-SENT

  If ACK set
    If RST clear and SEG.ACK != SND.ISS
      Send <SEQ=SEG.ACK + 1><RST>
    Endif
    Discard segment; Return
  Endif

  If RST set
    If ACK set
      Signal "Connection Refused"
      Set State =  CLOSED
      Deallocate connection record
    Endif
    Discard segment
    Return
  Endif

  If SYN set
    Set RCV.CUR = SEG.SEQ
        RCV.IRS = SEG.SEQ
        SND.MAX = SEG.MAX
        RBUF.MAX = SEG.BMAX
    If ACK set
      Set SND.UNA = SEG.ACK
      State = OPEN
      Send <SEQ=SND.NXT><ACK=RCV.CUR><ACK>
     else
      Set State = SYN-RCVD
      Send <SEQ=SND.ISS><ACK=RCV.CUR><MAX=RCV.MAX><BUFMAX=RBUF.MAX>
             <SYN><ACK>
    Endif
    Return
  Endif

  If anything else
    Discard segment
    Return
  Endif
Endif

If State = SYN-RCVD

  If RCV.IRS < SEG.SEQ =< RCV.CUR + (RCV.MAX * 2)
    Segment sequence number acceptable
   else
    Send <SEQ=SND.NXT><ACK=RCV.CUR><ACK>
    Discard segment
    Return
  Endif

  If RST set
    If passive Open
       Set State = LISTEN
    else
       Set State = CLOSED
       Signal "Connection Refused"
       Discard segment
       Deallocate connection record
    Endif
    Return
  Endif

  If SYN set
    Send <SEQ=SEG.ACK + 1><RST>
    Set State = CLOSED
    Signal "Connection Reset"
    Discard segment
    Deallocate connection record
    Return
  Endif

  If EACK set
     Send <SEQ=SEG.ACK + 1><RST>
     Discard segment
     Return
  Endif

  If ACK set
    If SEG.ACK = SND.ISS
       Set State = OPEN
     else
       Send <SEQ=SEG.ACK + 1><RST>
       Discard segment
       Return
    Endif
   else
    Discard segment
    Return
  Endif

  If Data in segment or NUL set
    If the received segment is in sequence
       Copy the data (if any) to user buffers
       Set RCV.CUR=SEG.SEQ
       Send <SEQ=SND.NXT><ACK=RCV.CUR><ACK>
     else
       If out-of-sequence delivery permitted
          Copy the data (if any) to user buffers
       Endif
       Send <SEQ=SND.NXT><ACK=RCV.CUR><ACK><EACK><RCVDSEQNO1>
                 ...<RCVDSEQNOn>
    Endif
  Endif

Endif

If State = OPEN

  If RCV.CUR < SEG.SEQ =< RCV.CUR + (RCV.MAX * 2)
    Segment sequence number acceptable
   else
    Send <SEQ=SND.NXT><ACK=RCV.CUR><ACK>
    Discard segment and return
  Endif

  If RST set
    Set State = CLOSE-WAIT
    Signal "Connection Reset"
    Return
  Endif

  If NUL set
    Set RCV.CUR=SEG.SEQ
    Send <SEQ=SND.NXT><ACK=RCV.CUR><ACK>
    Discard segment
    Return
  Endif

  If SYN set
    Send <SEQ=SEG.ACK + 1><RST>
    Set State = CLOSED
    Signal "Connection Reset"
    Discard segment
    Deallocate connection record
    Return
  Endif

  If ACK set
    If SND.UNA =< SEG.ACK < SND.NXT
      Set SND.UNA = SEG.ACK
      Flush acknowledged segments
    Endif
  Endif

  If EACK set
    Flush acknowledged segments
  Endif

  If Data in segment
   If the received segment is in sequence
     Copy the data to user buffers
     Set RCV.CUR=SEG.SEQ
     Send <SEQ=SND.NXT><ACK=RCV.CUR><ACK>
    else
     If out-of-sequence delivery permitted
        Copy the data to user buffers
     Endif
     Send <SEQ=SND.NXT><ACK=RCV.CUR><ACK><EACK><RCVDSEQNO1>
                 ...<RCVDSEQNOn>
   Endif
  Endif
Endif

3.7.3 Eventi di timeout​

Gli eventi di timeout si verificano quando un timer scade e lo segnala a RDP. Possono verificarsi due tipi di eventi di timeout, descritti di seguito:

TIMEOUT DI RITRASMISSIONE

  If timeout on segment at head of retransmission queue
Resend the segment at head of queue
Restart the retransmission timer for the segment
Requeue the segment on retransmission queue
Return
Endif

TIMEOUT DI CLOSE-WAIT

  Set State = CLOSED
Deallocate connection record
Return