Transmit Protocol Handler Design Pattern

Intent

Provide a common framework for transmit direction sliding window protocol implementation.

Also Known As

  • Send Protocol Design Pattern
  • Sender Pattern
  • Sliding Window Transmitter Pattern

Motivation

Different sliding window protocols have a lot of similarity. This similarity can be captured in a common design pattern for their implementation. Here we will focus on the transmit side of the protocol. 

Applicability

Transmit Protocol Handler Pattern can be used to implement protocols at any layer.

Structure

This pattern provides a framework for implementing a sliding window protocol. The Transmit Protocol Handler receives a packet from the higher layer and transmits it to the lower layer after assigning a sequence number. The packet is also stored in an internal retransmission buffer. The packet is removed from the retransmission queue if the remote end acknowledges the packet. The Transmit Protocol Handler retransmits the packet if it times out for an acknowledgement.

Participants

The key actors of this design pattern:

  • Transmit_Protocol_Handler: Class that manages the transmit end of the protocol. This class interfaces with the receive end and the retransmission queue.
  • Transmit_Queue: Enqueues messages that wait for transmission when the window is full.
  • Retransmission_Buffer: Manages buffers until an acknowledgement is received from the other end. The messages are retransmitted If no ack is received, .

Collaboration

The following diagram shows the relationship and collaboration between various classes involved in the Transmit Protocol Handler Pattern. 

Transmit Protocol Handler

Consequences

Using this pattern simplifies the implementation of transmit end point of a sliding window protocol. The design is flexible enough to adjust to any protocol.

Implementation

The following scenarios are supported by the Transmit Protocol Handler:

Packet added to queue when window has room

  1. Handle Transmit Request method of the Transmit Protocol Handler is invoked.
  2. Since the transmit window is not full, packet transmission is initiated.
  3. Protocol processing is performed on the packet. This involves the following steps:
    1. Protocol header is added to the packet
    2. Transmit sequence number is assigned to the packet and then incremented for the next time
    3. Receive sequence number is initialized to the last transmit sequence number of the last received packet (from the other end)
  4. Packet is added to the Retransmission Buffer at the transmit sequence number in the packet.
  5. Retransmission Buffer restarts AwaitAck timer.
  6. Packet is passed to the serial port transmit queue 

Packet added when window is full

  1. Handle Transmit Request method of the Transmit Protocol Handler is invoked.
  2. Since the transmit window is full, no further action is needed, unless the transmit window opens.

"Send Ack" request from Receive Protocol Handler

  1. Receive Protocol Handler detects a change in the received transmit sequence number, it requests Transmit Protocol Handler to acknowledge the received packets. (The new received transmit sequence number is passed)
  2. Transmit Protocol Handler takes the following action:
    • If the transmission queue is empty or the transmit window is full, explicit acknowledgement is scheduled.
    • If transmission is pending, the acknowledgement will be piggybacked in the data packet.

"Received Ack" Notification from Receive Protocol Handler

  1. Whenever the Receive Protocol Handler detects a change in the received receive sequence number, it informs Transmit Protocol Handler so that it can process the sequence number change as acknowledgements from the other end.
  2. Transmit Protocol Handler takes the following action:
    1. Retransmission Buffer is informed about the acknowledged sequence numbers.
    2. Retransmission Buffer loops through from the last acknowledged sequence number to the new sequence number and frees up the buffers as they have been acknowledged.
    3. If no more packets are present in the retransmit buffer, AwaitAck timer is stopped.
    4. If the window was full and has now been opened up, check the Transmit Queue for any messages that might be waiting for the window to open up.  

Timeout for acknowledgement

  1. Await Ack timer times out.
  2. Retransmission Buffer loops through all the packets that are still pending acknowledgement and initiates retransmission.

Sample Code and Usage

Here we present the code for a typical implementation of this pattern. Code is provided for the Transmit Protocol Handler and the Retransmission Buffer classes. Transmit Queue can be implemented using the message queue pattern.

Transmit Protocol Handler

Retransmission Buffer

Known Uses

  • Datalink layer sliding window protocol implementation
  • Higher layer sliding window protocol implementation

Related Patterns