Commit Graph
30 Commits
Author SHA1 Message Date
tbaumgartlandTobias Baumgartl 8f938a0e13 cfdp: implement acknowledged mode (class 2) (#73)
# CFDP acknowledged mode (class 2)

## Summary

Both CFDP handlers implement class 2. Before this, `BUSY_CLASS_2_ACKED` was a stub on the
destination side and the source handler ignored every incoming PDU.

Destination handler:

```diff
 RECEIVING_FILE_DATA_PDUS        track gaps per received segment
   EOF
+  SENDING_ACK_PDU               ACK(EOF) before the checksum pass
+  WAITING_FOR_MISSING_DATA      deferred NAK sequence, NAK timer, check timer
   TRANSFER_COMPLETION
   SENDING_FINISHED_PDU
+  WAITING_FOR_FINISHED_ACK      positive ACK timer, retransmit Finished
```

Source handler:

```diff
 SENDING_FILE_DATA
 SENDING_EOF
+WAIT_FOR_ACK                    positive ACK timer, answer NAKs with retransmissions
 WAIT_FOR_FINISH                 now actually parses the Finished PDU
+  send ACK(Finished)
 NOTICE_OF_COMPLETION            reports the received condition and delivery codes
```

Behaviour worth knowing:

- Lost metadata is recovered: the transaction starts from the first file data or EOF PDU and
  requests the metadata with a NAK of scope 0..0.
- An EOF for a transaction that is already finished is still acknowledged.
- The NAK and check limits count expirations without progress. Missing data arriving resets them
  (CFDP 4.6.4.7).
- A class 2 metadata only transaction (a proxy put request) waits for its EOF, so the Finished PDU
  never overtakes the EOF ACK.
- NAK segment requests that do not fit one PDU are carried into the next PDU of the sequence.

Fixes found along the way, all of them also affect class 1:

- Metadata, NAK and Finished readers take the PDU CRC out of the parsed range. Before, any PDU
  with a CRC and options, segment requests or filestore responses failed with
  `INVALID_TLV_TYPE`.
- A Cancel EOF is parsed and ends the transaction. It was dropped as unparseable.
- `PduSenderIF::sendPdu()` failures are no longer treated as sent. Both handlers retry, the
  Finished PDU with a bounded number of attempts.
- PDUs are filtered by transaction ID, so a late PDU from an earlier transaction cannot drive the
  current one.
- A metadata only transaction reports `DATA_COMPLETE` instead of the "Data Incomplete" defaults.
- `arrayprinter` prints in fixed chunks instead of a stack buffer sized from the input. Dumping a
  12 KB buffer overflowed an 8 KB task.
- Metadata options beyond the option array are rejected instead of written past it.

New configuration, all with defaults:

```text
RemoteEntityCfg      positiveAckTimerIntervalMs, positiveAckTimerExpirationLimit,
                     nakTimerIntervalMs, nakTimerExpirationLimit, immediateNakMode,
                     checkLimit, checkTimerIntervalMs
DestHandlerParams    maxSegmentRequestsPerNakPdu, maxFinishedPduSendAttempts
returnvalue          cfdp::TRANSMISSION_MODE_NOT_SUPPORTED
```

## Evidence

- **Before:** an acknowledged uplink failed after about 40 s. The sender retransmitted EOF to
  `POSITIVE_ACK_LIMIT_REACHED` because the destination never sent an ACK. An acknowledged put
  request left the source handler busy for good.
  **After:** `fsfw-tests "[cfdp]"` passes, 26 test cases. New sections include:

  ```text
  CFDP Dest Handler Acknowledged
    Nominal acknowledged transfer
    Dropped file data PDU is recovered via NAK
    Dropped metadata PDU is requested with a scope 0 to 0 NAK
    Finished PDU is retransmitted on positive ACK timeout
    NAK limit reached cancels the transaction
    Retransmitted data resets the NAK and check limits
    Metadata only transaction sends Finished after the EOF ACK
    EOF PDU for an inactive transaction is acknowledged
    Cancel EOF is parsed, acknowledged and ends the transaction
    A Finished ACK for a different transaction is ignored
  CFDP Source Handler Acknowledged
    Nominal acknowledged transfer
    EOF PDU is retransmitted on positive ACK timeout
    NAK PDU drives segment retransmission
    NAK PDU of scope 0 to 0 retransmits the metadata PDU
    A NAK keeps the inactivity guard from firing during recovery
    Finished PDU condition code is reported instead of a hardcoded success
  Finished / Metadata / NAK PDU with CRC
  ```

  Plus class 1 sections for send failures, Cancel EOF and metadata only transfers. The last two
  destination fixes were checked with their tests failing before the fix.

- **Hardware:** SOURCE flatsat, iOBC, over the maintenance port with a proxy dropping 15 % of the
  packets in each direction. A 200 kB uplink and the downlink of the same file both completed
  with `NO_ERROR`, and the downlinked file was byte identical to the original.

## Merge Danger

**Door:** two-way

Plain code changes, no stored data or formats change. A revert restores the old behaviour.

**Blast Radius:** CFDP users

Every mission using the CFDP handlers gets the class 1 fixes too: send failures are retried
instead of dropped, a Cancel EOF ends the transaction, and CRC-bearing PDUs with variable length
tails now parse. Existing `RemoteEntityCfg` setups compile unchanged, the new fields default to
values that leave class 1 alone. Not covered: the PDU creators still cannot size a CRC-bearing PDU,
so `crcOnTransmission` has to stay false as before.

---------

Co-authored-by: Tobias Baumgartl <tobias.baumgartl@ksat-stuttgart.de>
Reviewed-on: #73
2026-10-27 09:03:13 +01:00
muellerr 33f3ae2434 Update and clean up HK and Local Pool Modules 2025-01-07 10:50:37 +01:00
muellerr 20819dd99a Filesystem and CFDP updates 2024-10-25 18:29:22 +02:00
muellerr cb1aaea6cd add more checks 2023-08-14 21:04:22 +02:00
muellerr 22df8f6147 fix the tests 2023-08-14 21:01:29 +02:00
muellerr e1816ed230 that should be all indications 2023-08-14 13:45:13 +02:00
muellerr 5ff464252f added some user checks 2023-08-14 13:40:25 +02:00
muellerr cd8d64830c more checks 2023-08-14 13:33:47 +02:00
muellerr b7056a7467 additional checks 2023-08-14 13:24:22 +02:00
muellerr e4aae75747 more checks 2023-08-14 12:19:55 +02:00
muellerr b094ba145f multi file segment works 2023-08-14 12:15:35 +02:00
muellerr 15629abf19 the joys of UB or whatever that crap was 2023-08-14 12:13:29 +02:00
muellerr 7aeb25e064 unittest for transfer with 2 segments 2023-08-14 11:26:57 +02:00
muellerr 7c875f1067 unittest for small file transfer done 2023-08-04 15:17:53 +02:00
muellerr e8451cac31 add one test condition 2023-08-04 14:21:36 +02:00
muellerr 8ddd6eb18d some improvements for test 2023-08-03 17:44:30 +02:00
muellerr 6c6b552059 start small file transfer test 2023-08-03 17:43:03 +02:00
muellerr 9a1437980f add empty stubs 2023-08-03 15:50:27 +02:00
muellerr 12e52a92f2 empty file transfer test done 2023-08-03 15:49:23 +02:00
muellerr dffce43e6b metadata PDU seems to be correct 2023-08-03 15:30:38 +02:00
muellerr daf75547a4 insidious bug 2023-08-03 15:13:26 +02:00
muellerr 0cccf26021 should not be problematic but somehow is.. 2023-08-03 14:34:21 +02:00
muellerr c075f27e20 start verifying metadata PDU 2023-08-03 13:57:55 +02:00
muellerr 3167988951 continue source handler 2023-08-03 13:03:58 +02:00
muellerr a856f91c67 nice 2023-07-27 17:15:01 +02:00
muellerr 273fd3ebfd added sequence count provider abstraction 2023-07-19 23:22:55 +02:00
muellerr 3b1da85229 start setting up source handler 2023-07-17 11:37:20 +02:00
muellerr 385a0ffd73 add CFDP handlers manually 2022-09-14 19:29:43 +02:00
muellerr 3a52454949 removed handlers 2022-09-14 19:15:52 +02:00
muellerr 7f9401cf63 some bugfixes 2022-08-09 15:09:43 +02:00