Transport Layer Schemes

 
Scheme #1:Just transmit the data
Algorithm for sender:  Just send the data.  Don't worry about overflowing the receiver or transmission errors
Algorithm for receiver:  Read all the data as fast as you can.   Buffer as needed.
When does this work:  Only if the underlying network handles errors for you, or errors are SO rare you don't care
Example:  Streaming Media
Speed:   Best posible
Scheme #2:  Automatic Repeat Request
Algorithm for sender:  
While there is data to send ...
           Start the timer
           Send the packet
           If you get an ack
               Move the pointe to the next packet
               Goto 1
            If the timer goes off
                Don't move the pointer
                Goto 1
Algorithm for Receiver:
Repeat
    Wait for a packet
    If checksum OK
        Send ACK
        If pointer OK
            Accept data
Until Last packet accepted
When does this work:  When Latency is low compared to bandwidth and there are few errors
Example: Human conversation
Speed: Very bad if latency is high compared to bandwidth or if there are lots of errors
Scheme #3:  Automatic Repeat Request with NAK
Algorithm for sender:
While there is data to send ...
           Start the timer
           Send the packet
           If you get an ack
               Move the pointe to the next packet
               Goto 1
            If the timer goes off or you get a NAK
               Don't move the pointer
               Goto 1
Algorithm for Receiver:
Repeat
    Wait for a packet
    If checksum OK
        Send ACK
     Else 
        Send NAK
        If pointer OK
            Accept data
Until Last packet accepted
When does this work: When Latency is low compared to bandwidth 
Example: Human conversation
Speed: Very bad if latency is high compared to bandwidth
Scheme #4:  Go Back N
Algorithm for sender:
Function Sendpacket
    Start timer[packetnumber]
    Send packet

While there is data to send
    While there are packets yet to send and within N of the last ack'ed packet
        SendPacket for all the unset packets
     If a Timer goes off
        Sendpacket for all packets within the window and >= the timer that went off
     If an ACK arrives
         Cancel the associated timer

Algorithm for Receiver:
Repeat
    Get a packet
    If checksum OK send ACK
    If this is a new packet and contigous with already accepted data
        Accept the data
Until the last packet is accepted
When does this work: There are few errors 
                                        Packets are rarely reordered.
                                       There is enough RAM to buffer latency * bandwidth amount of data
Example:
Speed:  Fine if there are only a few errors
Scheme #5:  Selective Repeat
Algorithm for sender:
Function Sendpacket
    Start timer[packetnumber]
    Send packet

While there is data to send
     While there are packets within the senders window and not yet sent
        SendPacket the packet
    If a Timer goes off
        Sendpacket for all that packet
     If an ACK arrives
         Cancel the associated timer

Algorithm for Receiver:
Repeat
    Get a packet
    If checksum OK send ACK
    If this is a new packet 
        Store the data into a buffer
     Accept any data from the buffer contigious with the already acepted data 
Until the last packet is accepted
When does this work: Always, if you have time to code it
Example:  TCP, except that TCP does byte numbers instead of packet numbers
Speed: Great
Scheme #5:  Checksum 'till Finished
Algorithm for sender:
Function Sendpacket
      Repeat
          r = random()
          c = checksum(all_the_data, r)
          send r and c
      Until (receiver tells you to stop)
Algorithm for Receiver:
Repeat
    Get a packet containing r and c
Until sizeof(all the 'c's) > sizeof(data)
Send stop command to the server
Decode the data
When does this work: Always, if you have time to code it and love math
Example:  None that I know of
Speed: Great for long datas and lossy or corrupting networks