Commit Graph
42 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 22df8f6147 fix the tests 2023-08-14 21:01:29 +02:00
muellerr 5ff464252f added some user checks 2023-08-14 13:40:25 +02:00
muellerr 0f208ec75a seems to work well 2023-07-27 14:55:46 +02:00
muellerr e00e198ff1 this seems to work 2023-07-21 16:09:52 +02:00
muellerr 1561b9a247 implemented fle data PDUs 2023-07-19 13:44:52 +02:00
muellerr f44110a7f5 share the FSFW Param block 2023-07-17 10:25:09 +02:00
muellerr cf927ecee7 added bare structure of FSM 2023-07-14 15:56:38 +02:00
muellerr 7d713219c5 continue source handler 2023-06-30 11:59:22 +02:00
muellerr c38088c64b adaptions for enum renaming 2022-09-15 18:44:00 +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 ac7dc55fc1 fix unittest 2022-09-14 19:07:17 +02:00
muellerr 11a4b27642 allow deferred init 2022-09-07 18:20:38 +02:00
muellerr c54caf134a segmented file transfer working 2022-09-06 16:33:38 +02:00
muellerr aebd401d5b start segmentes file unittest 2022-09-06 16:14:39 +02:00
muellerr 67439b4285 refactor away some duplication 2022-09-06 16:03:26 +02:00
muellerr af851165b4 continue basic small file transfer unittest 2022-09-06 15:45:51 +02:00
muellerr 94c9800fae refactored out generic metadata part 2022-09-06 14:33:01 +02:00
muellerr ba046cebd9 empty file unittest complete 2022-09-06 14:06:22 +02:00
muellerr 428da017ba empty file transfer unittest almost done 2022-09-06 13:45:43 +02:00
muellerr 806ae9b41a check that indication was called 2022-09-06 13:16:00 +02:00
muellerr 7b97c8a182 continue tests 2022-09-06 11:56:05 +02:00
muellerr 2e4cdb7366 additional filesystem abstractions 2022-09-05 17:42:56 +02:00
muellerr 5a3f05fa79 return struct ref instead of code 2022-09-05 17:20:29 +02:00
muellerr afc48726b9 comment out check 2022-09-05 16:23:13 +02:00
muellerr 5ce1e76723 init dest handler unittests 2022-09-05 14:20:01 +02:00
muellerr 52802f127b basic test stubs 2022-09-05 11:40:22 +02:00
muellerr d2c4d546c3 first dest handler unittests
- Add new mock class for event reporting proxies
- Add basic setup for unittesting the CFDP destination handler
2022-09-05 11:37:41 +02:00
muellerr 0dd2b5ddd4 need an event reporter proxy 2022-09-05 11:19:23 +02:00
muellerr 11a699c3ce a list should do the job 2022-08-17 18:49:51 +02:00
muellerr 6930656d4e added some more basic tests 2022-08-17 17:09:39 +02:00
muellerr 3df1161560 this should do the job 2022-08-10 15:03:53 +02:00
muellerr 28c8248f26 add FS mock and improve HasFilesystemIF 2022-08-10 11:09:07 +02:00
muellerr 3e1fd15613 completed all indication parameters 2022-08-10 10:34:02 +02:00
muellerr 96dfe46e25 added string LV tests 2022-08-10 09:39:57 +02:00
muellerr 0cb15e901e new cfdp mock folder, added additional cfdp mocks 2022-08-09 19:00:47 +02:00
muellerr 8c059f8f32 new filesystem module 2022-08-09 16:36:35 +02:00
muellerr dce1ebcf65 add CFDP user base 2022-08-09 15:46:42 +02:00
muellerr dba3f9960e add CFDP fault handler mock 2022-08-09 14:55:08 +02:00