fsfw/tests/src/fsfw_tests/unit/cfdp/testKeepAlivePdu.cpp
Robin Mueller 5907f8ee9d
Added CFDP packet stack
This PR adds the packet stack for the CCSDS File Delivery Protocol.
It also refactors the existing TMTC infastructure to allow sending
of CFDP packets to the CCSDS handlers.

This includes the whole PDU (Protocol Data Unit) stack:

- File Data PDUs

and all file directive PDUs

- ACK PDU
- NAK PDU
- Metadata PDU
- Finished PDU
- Prompt PDU
- Keep Alive PDU
- EOF PDU

The PR includes a full set of unittests for the packet stack
with a coverage of 90+ %.

The refactoring of the existing TMTC infastructure includes non-ideal
solutions like diamond inheritance.
Avoiding this solution would require refactoring the packet stack.
This would be a good idea anyway because the existing stack is tightly
coupled to the FSFW, making reuse more difficult if only the stack is
planned to be used without the store functionalities etc.

The PDU implementation provided here is only weakly coupled to the FSFW,
only using components like returnvalues or the Serialization modules.
There are dedicated serializers and deserializers, which also helps in
creating small focused modules which are easy to test.

Some of the modules here were provied by Matthias Tompert.
2021-12-03 15:37:49 +01:00

85 lines
3.4 KiB
C++

#include <catch2/catch_test_macros.hpp>
#include "fsfw/cfdp/pdu/KeepAlivePduDeserializer.h"
#include "fsfw/cfdp/pdu/KeepAlivePduSerializer.h"
#include "fsfw/globalfunctions/arrayprinter.h"
#include <array>
TEST_CASE( "Keep Alive PDU" , "[KeepAlivePdu]") {
using namespace cfdp;
ReturnValue_t result = HasReturnvaluesIF::RETURN_OK;
std::array<uint8_t, 256> kaBuffer = {};
uint8_t* buffer = kaBuffer.data();
size_t sz = 0;
EntityId destId(WidthInBytes::TWO_BYTES, 2);
TransactionSeqNum seqNum(WidthInBytes::TWO_BYTES, 15);
EntityId sourceId(WidthInBytes::TWO_BYTES, 1);
PduConfig pduConf(TransmissionModes::ACKNOWLEDGED, seqNum, sourceId, destId);
FileSize progress(0x50);
SECTION("Serialize") {
KeepAlivePduSerializer serializer(pduConf, progress);
result = serializer.serialize(&buffer, &sz, kaBuffer.size(),
SerializeIF::Endianness::NETWORK);
REQUIRE(result == HasReturnvaluesIF::RETURN_OK);
REQUIRE(kaBuffer[10] == cfdp::FileDirectives::KEEP_ALIVE);
uint32_t fsRaw = 0;
result = SerializeAdapter::deSerialize(&fsRaw, kaBuffer.data() + 11, nullptr,
SerializeIF::Endianness::NETWORK);
REQUIRE(result == HasReturnvaluesIF::RETURN_OK);
REQUIRE(fsRaw == 0x50);
REQUIRE(sz == 15);
REQUIRE(serializer.getWholePduSize() == 15);
REQUIRE(serializer.getPduDataFieldLen() == 5);
pduConf.largeFile = true;
serializer.updateDirectiveFieldLen();
buffer = kaBuffer.data();
sz = 0;
result = serializer.serialize(&buffer, &sz, kaBuffer.size(),
SerializeIF::Endianness::NETWORK);
REQUIRE(result == HasReturnvaluesIF::RETURN_OK);
REQUIRE(serializer.getWholePduSize() == 19);
REQUIRE(serializer.getPduDataFieldLen() == 9);
uint64_t fsRawLarge = 0;
result = SerializeAdapter::deSerialize(&fsRawLarge, kaBuffer.data() + 11, nullptr,
SerializeIF::Endianness::NETWORK);
REQUIRE(result == HasReturnvaluesIF::RETURN_OK);
REQUIRE(fsRawLarge == 0x50);
for(size_t invalidMaxSz = 0; invalidMaxSz < sz; invalidMaxSz++) {
buffer = kaBuffer.data();
sz = 0;
result = serializer.serialize(&buffer, &sz, invalidMaxSz,
SerializeIF::Endianness::NETWORK);
REQUIRE(result != HasReturnvaluesIF::RETURN_OK);
}
}
SECTION("Deserialize") {
KeepAlivePduSerializer serializer(pduConf, progress);
result = serializer.serialize(&buffer, &sz, kaBuffer.size(),
SerializeIF::Endianness::NETWORK);
REQUIRE(result == HasReturnvaluesIF::RETURN_OK);
// Set another file size
progress.setFileSize(200, false);
KeepAlivePduDeserializer deserializer(kaBuffer.data(), kaBuffer.size(), progress);
result = deserializer.parseData();
REQUIRE(result == HasReturnvaluesIF::RETURN_OK);
auto& progRef = deserializer.getProgress();
// Should have been overwritten
REQUIRE(progRef.getSize() == 0x50);
sz = deserializer.getWholePduSize();
// invalid max size
for(size_t invalidMaxSz = 0; invalidMaxSz < sz; invalidMaxSz++) {
deserializer.setData(kaBuffer.data(), invalidMaxSz);
result = deserializer.parseData();
REQUIRE(result != HasReturnvaluesIF::RETURN_OK);
}
}
}