Skip to content

Svc::ComQueue (Active Component)

1. Introduction

Svc::ComQueue is an F´ active component that functions as a priority queue of buffer types. Messages are dequeued and forwarded in order of priority when a Fw::Success::SUCCESS signal is received on the comStatusIn port. Fw::Success::SUCCESS is accepted in three contexts: (1) at start-up to initiate data flow, (2) in response to a previously sent message, and (3) after a previous Fw::Success::FAILURE to indicate recovery. Receiving a Fw::Success::FAILURE results in the queues being paused until a subsequent Fw::Success::SUCCESS is received.

Svc::ComQueue is configured with a queue depth and queue priority for each incoming Fw::Com and Fw::Buffer port by passing in a configuration table at initialization. A depth of 0 disables the queue for that port: no storage is allocated for it and any message received on that port is treated as an overflow. At least one port must have a non-zero depth; an all-zero table (the default-constructed table) is rejected with an assertion at configuration. Queued messages from the highest priority source port are serviced first and a round-robin algorithm is used to balance between ports of shared priority.

Svc::ComQueue is designed to act alongside instances of the communication adapter interface and implements the communication queue protocol.

2. Assumptions

  1. Incoming buffers to a given port are in priority order
  2. Data is considered to be successfully sent when a Fw::Success::SUCCESS signal is received in response to that data
  3. The communication adapter is responsible for any retransmission of failed data and for emitting a recovery Fw::Success::SUCCESS after a failure
  4. The system includes downstream components implementing the communications adapter
  5. An initial Fw::Success::SUCCESS will be received on comStatusIn to initiate data flow (typically at start-up or driver connection)

3. Requirements

Requirement Description Rationale Verification Method
SVC-COMQUEUE-001 Svc::ComQueue shall queue Fw::Buffer and Fw::ComBuffer received on incoming ports. The purpose of the queue is to store messages. Unit Test
SVC-COMQUEUE-002 Svc::ComQueue shall output exactly one Fw::Buffer (wrapping the queued data units) on a received Fw::Success::SUCCESS signal. Fw::Success::SUCCESS is valid at start-up (to initiate flow), in response to a sent message, or after a previous Fw::Success::FAILURE (to indicate recovery). Svc::ComQueue obeys the communication adapter interface protocol. Unit Test
SVC-COMQUEUE-003 Svc::ComQueue shall pause sending on Fw::Success::FAILURE and resume on the next Fw::Success::SUCCESS signal. Svc::ComQueue should not send to a failing communication adapter. Unit Test
SVC-COMQUEUE-004 Svc::ComQueue shall have a configurable number of Fw::Com and Fw::Buffer input ports. Svc::ComQueue should be adaptable for a number of projects. Inspection
SVC-COMQUEUE-005 Svc::ComQueue shall select and send the next priority Fw::Buffer and Fw::ComBuffer message in response to Fw::Success::SUCCESS. Svc::ComQueue obeys the communication adapter interface protocol. Unit test
SVC-COMQUEUE-006 Svc::ComQueue shall periodically telemeter the number of queued messages per-port in response to a run port invocation. Svc::ComQueue should provide useful telemetry. Unit Test
SVC-COMQUEUE-007 Svc::ComQueue shall emit a queue overflow event for a given port when the configured depth is exceeded. Messages shall be discarded. Svc::ComQueue needs to indicate off-nominal events. Unit Test
SVC-COMQUEUE-008 Svc::ComQueue shall implement a round robin approach to balance between ports of the same priority. Allows projects to balance between a set of queues of similar priority. Unit Test
SVC-COMQUEUE-009 Svc::ComQueue shall keep track and throttle queue overflow events per port. Prevents a flood of queue overflow events. Unit test
SVC-COMQUEUE-010 Svc::ComQueue shall return ownership of incoming buffers once they have been enqueued. Memory management Unit test
SVC-COMQUEUE-011 Svc::ComQueue shall provide a command to flush queued items. Queue management Unit test
SVC-COMQUEUE-012 Svc::ComQueue shall accept a configured depth of 0 for a port, allocating no storage for that queue and treating any message received on that port as an overflow. Deployments may leave a port unused (e.g. no file downlink) without allocating memory or crashing. Unit test
SVC-COMQUEUE-013 Svc::ComQueue shall report cumulative, per-port message drops caused by async ingress and managed queue overflow separately, including both overflow policies and disabled queues. Provide observability without generating additional messages during ingress saturation. Unit test

4. Design

The diagram below shows the Svc::ComQueue component.

Svc::ComQueue

4.1. Ports

Svc::ComQueue has the following ports:

Kind Name Port Type Usage
output dataOut Svc.ComDataWithContext Port emitting queued messages
sync input dataReturnIn Svc.ComDataWithContext Port retrieving back ownership buffers sent on dataOut
async input comStatusIn Fw.SuccessCondition Port for receiving the status signal
async input comPacketQueueIn [ComQueueComPorts] Fw.Com Port array for receiving Fw::ComBuffers
async input bufferQueueIn [ComQueueBufferPorts] Fw.BufferSend Port array for receiving Fw::Buffers
output bufferReturnOut [ComQueueBufferPorts] Fw.BufferSend Port array returning ownership of buffers received on bufferQueueIn

Note

ComQueue also has the port instances for autocoded functionality for events, telemetry and time.

4.2. State

Svc::ComQueue maintains the following state:

  1. m_queues: An array of Types::Queue used to queue per-port messages.
  2. m_prioritizedList: An instance of Svc::ComQueue::QueueMetadata storing the priority-order queue metadata.
  3. m_state: Instance of Svc::ComQueue::SendState representing the state of the component. See: 4.3.1 State Machine
  4. m_throttle: An array of flags that throttle the per-port queue overflow messages.
  5. m_comIngressDrops and m_buffIngressDrops: atomic per-port async ingress loss counters, updated in the caller's thread.
  6. m_managedDrops: per-port managed queue loss counter, updated in the component dispatch thread.

4.2.1 State Machine

The Svc::ComQueue component runs the following state machine. It has two states:

State Description
WAITING Svc::ComQueue is waiting on SUCCESS before attempting to send an available buffer
READY Svc::ComQueue had no queued buffers and will send the next buffer immediately when received

The state machine will transition between states when a status is received and will transition from READY when a new buffer is received. FAILURE statuses keep the Svc::ComQueue in WAITING state whereas a SUCCESS status will either send a buffer and transition to WAITING or will have no buffers to send and will transition into READY state. Buffers are queued when in WAITING state.

Fw::Success::SUCCESS triggers a transition from WAITING to either WAITING (if a buffer was sent) or READY (if no buffers are queued). This SUCCESS is valid in three contexts per the Communication Queue Protocol: at start-up, in response to a sent message, or after a previous FAILURE indicating recovery.

Svc::ComQueue Functional State Machine

4.3 Model Configuration

Svc::ComQueue has the following constants, that are configured in AcConstants.fpp:

  1. ComQueueComPorts: number of ports of Fw.Com type in the comPacketQueueIn port array.
  2. ComQueueBufferPorts: number of ports of Fw.BufferSend type in the bufferQueueIn port array.

4.4 Runtime Setup

To set up an instance of ComQueue, the following needs to be done: 1. Call the constructor and the init method in the usual way for an F Prime active component. 2. Call the configure method, passing in an array of QueueConfiguration type, the size of the array, and an allocator of Fw::MemAllocator. The configure method foes the following:

  1. Ensures that the total size and config size are the same value
  2. Ensures that priority values range from 0 to the total size value
  3. Ensures that every entry in the queue containing the prioritized order of the com buffer and buffer data have been initialized.
  4. Ensures that there is enough memory for the com buffer and buffer data we want to process
  5. Skips storage setup for any entry with a depth of 0; such a queue is disabled and always overflows
  6. Asserts that at least one entry has a non-zero depth

4.5 Port Handlers

4.5.1 bufferQueueIn

The bufferQueueIn port handler receives an Fw::Buffer data type and a port number. It does the following:

  1. Ensures that the port number is between zero and the value of the buffer size
  2. Enqueue the buffer onto the m_queues instance
  3. Returns a warning if m_queues is full

In the case where the component is already in READY state, this will process the queue immediately after the buffer is added to the queue.

4.5.2 comPacketQueueIn

The comPacketQueueIn port handler receives an Fw::ComBuffer data type and a port number. It does the following:

  1. Ensures that the port number is between zero and the value of the com buffer size
  2. Enqueue the com buffer onto the m_queues instance
  3. Returns a warning if m_queues is full

In the case where the component is already in READY state, this will process the queue immediately after the buffer is added to the queue.

4.5.3 comStatusIn

The comStatusIn port handler receives a Fw::Success status. This triggers the component's state machine to change state. For a full description see 4.2.1 State Machine.

4.5.4 run

The run port handler does the following: 1. Report the high-water mark for each queue since last run invocation via telemetry 2. Clear each queue's high-water mark 3. Report cumulative per-port ingress and managed queue drop counters; counters are not reset by run

4.6 Telemetry

Name Type Description
comQueueDepth Svc.ComQueueDepth High-water mark depths of queues handling Fw::ComBuffer
buffQueueDepth Svc.BuffQueueDepth High-water mark depths of queues handling Fw::Buffer
comIngressDropped Svc.ComQueueIngressDrops Cumulative drops at the async Fw::ComBuffer ingress, by port
buffIngressDropped Svc.BuffQueueIngressDrops Cumulative drops at the async Fw::Buffer ingress, by port
comManagedDropped Svc.ComQueueManagedDrops Cumulative drops in managed Fw::ComBuffer queues, by port
buffManagedDropped Svc.BuffQueueManagedDrops Cumulative drops in managed Fw::Buffer queues, by port

The loss counters are unsigned 32-bit cumulative counts since component construction; they wrap modulo 2^32. They count drops caused by queue overflow only. Explicit FLUSH_QUEUE and FLUSH_ALL_QUEUES operations are excluded; returning a buffer during a commanded flush does not increment any drop counter. A managed queue DROP_OLDEST replacement counts as one lost message even though the new input is accepted. A configured managed queue depth of zero counts each rejected input as one managed queue loss.

The ingress counters reflect overflow of the component instance's single shared asynchronous message queue, configured by the FPP instance queue size (for example, ComCcsdsConfig.QueueSizes.comQueue). This queue is shared by the async input ports, including run, and is distinct from the per-port managed queues. The managed drop counters reflect the corresponding QueueConfigurationTable entry's depth and overflowMode (for example, ComCcsdsConfig.QueueDepths.events and .tlm). Increasing a managed queue depth does not resolve saturation of the shared async queue.

Deployments with an FPP telemetry packet set must include or explicitly omit the four drop channels. The Ref deployment includes them in its CDHErrors packet.

The run input is itself asynchronous with drop overflow behavior. If the async message queue is full, that telemetry invocation may be dropped too; the cumulative counters are retained and will be reported upon a subsequent successfully dispatched run. The async ingress overflow hooks intentionally do not emit events or enqueue messages. A returned Fw::Buffer signals ownership return, not successful transmission.

4.7 Events

Name Description
QueueOverflow WARNING_HI event triggered when a queue discards data
QueuePriorityChanged ACTIVITY_HI event triggered when a user changes a queue's priority

4.8 Commands

Name Description
FLUSH_QUEUE Flushes all queued items from the specified queue type and index, returning ownership of any buffers.
FLUSH_ALL_QUEUES Flushes all queued items from all queues, returning ownership of any buffers.
SET_QUEUE_PRIORITY Changes a queue's priority and re-sorts all queues

4.9 Helper Functions

4.9.1 sendComBuffer

Stores the com buffer message, sends the com buffer message on the output port, and then sets the send state to waiting.

4.9.2 sendBuffer

Stores the buffer message, sends the buffer message on the output port, and then sets the send state to waiting.

4.9.3 processQueue

In a bounded loop that is constrained by the total size of the queue that contains both buffer and com buffer data, do:

  1. Check if there are any items on the queue, and continue with the loop if there are none.
  2. Store the entry point of the queue based on the index of the array that contains the prioritized data.
  3. Compare the entry index with the value of the size of the queue that contains com buffer data.
    1. If it is less than the size value, then invoke the sendComBuffer function.
    2. If it is greater than the size value, then invoke the sendBuffer function.
  4. Break out of the loop, but enter a new loop that starts at the next entry and linearly swap the remaining items in the prioritized list.

4.9.4 enqueue

Attempts to enqueue a buffer into its per-port managed queue. A rejected input, including one sent to a disabled (depth 0) queue, increments the managed drop counter; a DROP_OLDEST replacement counts the displaced item as one drop even when the new input is accepted. The overflow warning is throttled per port. If the state is READY, processing resumes immediately. A disabled queue never drains, so its overflow warning remains throttled after the first rejection.

4.9.5 drainQueue

Pops all messages out of the queue at queueIndex, index. A disabled (depth 0) queue has nothing to drain and is skipped.

4.9.6 getQueueNum

Converts a queueType & portNum into an index into the m_queues array--translates between user facing index system & internal one. portNum is validated against the port count of queueType (COM_PORT_COUNT or BUFFER_PORT_COUNT) before folding; an out-of-range portNum yields -1, which FLUSH_QUEUE and SET_QUEUE_PRIORITY reject with VALIDATION_ERROR so a COM_QUEUE index can never address a buffer queue (or vice versa).

4.9.7 getQueueDepth

Looks up the configured depth of the queue at a given m_queues index from the prioritized metadata list; a depth of 0 identifies a disabled queue.