this seems to work
This commit is contained in:
parent
6c9c4ee047
commit
e00e198ff1
@ -1,2 +1,4 @@
|
||||
target_sources(${LIB_FSFW_NAME} PRIVATE SourceHandler.cpp DestHandler.cpp
|
||||
FaultHandlerBase.cpp UserBase.cpp)
|
||||
target_sources(
|
||||
${LIB_FSFW_NAME}
|
||||
PRIVATE SourceHandler.cpp DestHandler.cpp MetadataParser.cpp
|
||||
PutRequestReader.cpp FaultHandlerBase.cpp UserBase.cpp)
|
||||
|
@ -136,10 +136,8 @@ ReturnValue_t cfdp::DestHandler::handleMetadataPdu(const PacketInfo& info) {
|
||||
cfdp::StringLv sourceFileName;
|
||||
cfdp::StringLv destFileName;
|
||||
MetadataInfo metadataInfo(transactionParams.fileSize, sourceFileName, destFileName);
|
||||
cfdp::Tlv* tlvArrayAsPtr = tlvVec.data();
|
||||
metadataInfo.setOptionsArray(&tlvArrayAsPtr, std::nullopt, tlvVec.size());
|
||||
MetadataPduReader reader(constAccessorPair.second.data(), constAccessorPair.second.size(),
|
||||
metadataInfo);
|
||||
metadataInfo, nullptr, 0);
|
||||
ReturnValue_t result = reader.parseData();
|
||||
// TODO: The standard does not really specify what happens if this kind of error happens
|
||||
// I think it might be a good idea to cache some sort of error code, which
|
||||
@ -357,8 +355,9 @@ ReturnValue_t cfdp::DestHandler::startTransaction(MetadataPduReader& reader, Met
|
||||
params.fileSize = transactionParams.fileSize.getSize();
|
||||
params.destFileName = transactionParams.destName.data();
|
||||
params.sourceFileName = transactionParams.sourceName.data();
|
||||
params.msgsToUserArray = dynamic_cast<MessageToUserTlv*>(userTlvVec.data());
|
||||
params.msgsToUserLen = info.getOptionsLen();
|
||||
// TODO: Is this really correct? Implement this correctly..
|
||||
// params.msgsToUserArray = dynamic_cast<MessageToUserTlv*>(userTlvVec.data());
|
||||
// params.msgsToUserLen = reader.getNumberOfParsedOptions();
|
||||
destParams.user.metadataRecvdIndication(params);
|
||||
return result;
|
||||
}
|
||||
|
1
src/fsfw/cfdp/handler/MetadataParser.cpp
Normal file
1
src/fsfw/cfdp/handler/MetadataParser.cpp
Normal file
@ -0,0 +1 @@
|
||||
#include "MetadataParser.h"
|
12
src/fsfw/cfdp/handler/MetadataParser.h
Normal file
12
src/fsfw/cfdp/handler/MetadataParser.h
Normal file
@ -0,0 +1,12 @@
|
||||
#pragma once
|
||||
|
||||
namespace cfdp {
|
||||
|
||||
class MetadataParser {
|
||||
public:
|
||||
MetadataParser();
|
||||
|
||||
private:
|
||||
};
|
||||
|
||||
} // namespace cfdp
|
1
src/fsfw/cfdp/handler/PutRequestReader.cpp
Normal file
1
src/fsfw/cfdp/handler/PutRequestReader.cpp
Normal file
@ -0,0 +1 @@
|
||||
#include "PutRequestReader.h"
|
29
src/fsfw/cfdp/handler/PutRequestReader.h
Normal file
29
src/fsfw/cfdp/handler/PutRequestReader.h
Normal file
@ -0,0 +1,29 @@
|
||||
#pragma once
|
||||
|
||||
#include <optional>
|
||||
#include <vector>
|
||||
|
||||
#include "fsfw/cfdp/VarLenFields.h"
|
||||
#include "fsfw/cfdp/tlv/FilestoreRequestTlv.h"
|
||||
#include "fsfw/cfdp/tlv/MessageToUserTlv.h"
|
||||
|
||||
namespace cfdp {
|
||||
|
||||
class PutRequest {
|
||||
public:
|
||||
EntityId destId;
|
||||
std::optional<TransmissionMode> transmissionMode;
|
||||
char destName[524]{};
|
||||
std::optional<size_t> destNameSize;
|
||||
char sourceName[524]{};
|
||||
std::optional<size_t> sourceNameSize;
|
||||
std::optional<bool> closureRequested;
|
||||
std::vector<MessageToUserTlv> messagesToUser;
|
||||
std::vector<FilestoreRequestTlv> fsRequest;
|
||||
|
||||
[[nodiscard]] bool isMetadataOnly() const {
|
||||
return !destNameSize.has_value() and !sourceNameSize.has_value();
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace cfdp
|
@ -157,7 +157,7 @@ ReturnValue_t cfdp::SourceHandler::prepareAndSendMetadataPdu() {
|
||||
cfdp::StringLv sourceName(transactionParams.sourceName.data(), transactionParams.sourceNameSize);
|
||||
cfdp::StringLv destName(transactionParams.destName.data(), transactionParams.destNameSize);
|
||||
auto metadataInfo = MetadataInfo(transactionParams.fileSize, sourceName, destName);
|
||||
auto metadataPdu = MetadataPduCreator(transactionParams.pduConf, metadataInfo);
|
||||
auto metadataPdu = MetadataPduCreator(transactionParams.pduConf, metadataInfo, nullptr, 0);
|
||||
ReturnValue_t result = sendGenericPdu(metadataPdu);
|
||||
if (result != OK) {
|
||||
return result;
|
||||
|
@ -57,6 +57,7 @@ struct PutRequestFull {
|
||||
char sourceName[524]{};
|
||||
size_t sourceNameSize = 0;
|
||||
bool closureRequested = true;
|
||||
// MessageToUserTlv
|
||||
};
|
||||
|
||||
enum class CallStatus { DONE, CALL_AFTER_DELAY, CALL_AGAIN };
|
||||
|
@ -12,17 +12,6 @@ MetadataInfo::MetadataInfo(cfdp::Fss& fileSize, cfdp::StringLv& sourceFileName,
|
||||
cfdp::StringLv& destFileName)
|
||||
: fileSize(fileSize), sourceFileName(sourceFileName), destFileName(destFileName) {}
|
||||
|
||||
void MetadataInfo::setOptionsArray(cfdp::Tlv** optionsArray_, std::optional<size_t> optionsLen_,
|
||||
std::optional<size_t> maxOptionsLen_) {
|
||||
this->optionsArray = optionsArray_;
|
||||
if (maxOptionsLen_) {
|
||||
this->maxOptionsLen = maxOptionsLen_.value();
|
||||
}
|
||||
if (optionsLen_) {
|
||||
this->optionsLen = optionsLen_.value();
|
||||
}
|
||||
}
|
||||
|
||||
cfdp::ChecksumType MetadataInfo::getChecksumType() const { return checksumType; }
|
||||
|
||||
void MetadataInfo::setChecksumType(cfdp::ChecksumType checksumType_) {
|
||||
@ -39,35 +28,6 @@ cfdp::StringLv& MetadataInfo::getDestFileName() { return destFileName; }
|
||||
|
||||
cfdp::Fss& MetadataInfo::getFileSize() { return fileSize; }
|
||||
|
||||
ReturnValue_t MetadataInfo::getOptions(cfdp::Tlv*** optionsArray_, size_t* optionsLen_,
|
||||
size_t* maxOptsLen) {
|
||||
if (optionsArray_ == nullptr or optionsArray == nullptr) {
|
||||
return returnvalue::FAILED;
|
||||
}
|
||||
*optionsArray_ = optionsArray;
|
||||
if (optionsLen_ != nullptr) {
|
||||
*optionsLen_ = this->optionsLen;
|
||||
}
|
||||
if (maxOptsLen != nullptr) {
|
||||
*maxOptsLen = this->maxOptionsLen;
|
||||
}
|
||||
return returnvalue::OK;
|
||||
}
|
||||
|
||||
bool MetadataInfo::hasOptions() const {
|
||||
if (optionsArray != nullptr and optionsLen > 0) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool MetadataInfo::canHoldOptions() const {
|
||||
if (optionsArray != nullptr and maxOptionsLen > 0) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
size_t MetadataInfo::getSerializedSize(bool fssLarge) {
|
||||
// 1 byte + minimal FSS 4 bytes
|
||||
size_t size = 5;
|
||||
@ -76,11 +36,6 @@ size_t MetadataInfo::getSerializedSize(bool fssLarge) {
|
||||
}
|
||||
size += sourceFileName.getSerializedSize();
|
||||
size += destFileName.getSerializedSize();
|
||||
if (hasOptions()) {
|
||||
for (size_t idx = 0; idx < optionsLen; idx++) {
|
||||
size += optionsArray[idx]->getSerializedSize();
|
||||
}
|
||||
}
|
||||
return size;
|
||||
}
|
||||
|
||||
@ -92,12 +47,4 @@ void MetadataInfo::setSourceFileName(cfdp::StringLv& sourceFileName_) {
|
||||
this->sourceFileName = sourceFileName_;
|
||||
}
|
||||
|
||||
size_t MetadataInfo::getMaxOptionsLen() const { return maxOptionsLen; }
|
||||
|
||||
void MetadataInfo::setMaxOptionsLen(size_t maxOptionsLen_) { this->maxOptionsLen = maxOptionsLen_; }
|
||||
|
||||
size_t MetadataInfo::getOptionsLen() const { return optionsLen; }
|
||||
|
||||
void MetadataInfo::setOptionsLen(size_t optionsLen_) { this->optionsLen = optionsLen_; }
|
||||
|
||||
cfdp::StringLv& MetadataInfo::getSourceFileName() { return sourceFileName; }
|
||||
|
@ -17,8 +17,6 @@ class MetadataInfo {
|
||||
|
||||
size_t getSerializedSize(bool fssLarge = false);
|
||||
|
||||
void setOptionsArray(cfdp::Tlv** optionsArray, std::optional<size_t> optionsLen,
|
||||
std::optional<size_t> maxOptionsLen);
|
||||
[[nodiscard]] cfdp::ChecksumType getChecksumType() const;
|
||||
void setChecksumType(cfdp::ChecksumType checksumType);
|
||||
[[nodiscard]] bool isClosureRequested() const;
|
||||
@ -31,24 +29,12 @@ class MetadataInfo {
|
||||
cfdp::StringLv& getSourceFileName();
|
||||
cfdp::Fss& getFileSize();
|
||||
|
||||
[[nodiscard]] bool hasOptions() const;
|
||||
[[nodiscard]] bool canHoldOptions() const;
|
||||
ReturnValue_t getOptions(cfdp::Tlv*** optionsArray, size_t* optionsLen, size_t* maxOptsLen);
|
||||
void setOptionsLen(size_t optionsLen);
|
||||
[[nodiscard]] size_t getOptionsLen() const;
|
||||
void setMaxOptionsLen(size_t maxOptionsLen);
|
||||
[[nodiscard]] size_t getMaxOptionsLen() const;
|
||||
|
||||
private:
|
||||
bool closureRequested = false;
|
||||
cfdp::ChecksumType checksumType = cfdp::ChecksumType::NULL_CHECKSUM;
|
||||
cfdp::Fss& fileSize;
|
||||
cfdp::StringLv& sourceFileName;
|
||||
cfdp::StringLv& destFileName;
|
||||
|
||||
cfdp::Tlv** optionsArray = nullptr;
|
||||
size_t optionsLen = 0;
|
||||
size_t maxOptionsLen = 0;
|
||||
};
|
||||
|
||||
#endif /* FSFW_SRC_FSFW_CFDP_PDU_METADATAINFO_H_ */
|
||||
|
@ -1,12 +1,22 @@
|
||||
#include "MetadataPduCreator.h"
|
||||
|
||||
MetadataPduCreator::MetadataPduCreator(PduConfig &conf, MetadataInfo &info)
|
||||
: FileDirectiveCreator(conf, cfdp::FileDirective::METADATA, 5), info(info) {
|
||||
MetadataPduCreator::MetadataPduCreator(PduConfig &conf, MetadataInfo &info,
|
||||
cfdp::Tlv **optionsArray, size_t optionsLen)
|
||||
: FileDirectiveCreator(conf, cfdp::FileDirective::METADATA, 5),
|
||||
info(info),
|
||||
optionsArray(optionsArray),
|
||||
optionsLen(optionsLen) {
|
||||
updateDirectiveFieldLen();
|
||||
}
|
||||
|
||||
void MetadataPduCreator::updateDirectiveFieldLen() {
|
||||
setDirectiveDataFieldLen(info.getSerializedSize(getLargeFileFlag()));
|
||||
size_t dirFieldLen = info.getSerializedSize(HeaderCreator::getLargeFileFlag());
|
||||
if (optionsLen > 0 and optionsArray != nullptr) {
|
||||
for (size_t idx = 0; idx < optionsLen; idx++) {
|
||||
dirFieldLen += optionsArray[idx]->getSerializedSize();
|
||||
}
|
||||
}
|
||||
setDirectiveDataFieldLen(dirFieldLen);
|
||||
}
|
||||
|
||||
size_t MetadataPduCreator::getSerializedSize() const {
|
||||
@ -38,12 +48,9 @@ ReturnValue_t MetadataPduCreator::serialize(uint8_t **buffer, size_t *size, size
|
||||
return result;
|
||||
}
|
||||
|
||||
if (info.hasOptions()) {
|
||||
cfdp::Tlv **optsArray = nullptr;
|
||||
size_t optsLen = 0;
|
||||
info.getOptions(&optsArray, &optsLen, nullptr);
|
||||
for (size_t idx = 0; idx < optsLen; idx++) {
|
||||
result = optsArray[idx]->serialize(buffer, size, maxSize, streamEndianness);
|
||||
if (optionsLen > 0 and optionsArray != nullptr) {
|
||||
for (size_t idx = 0; idx < optionsLen; idx++) {
|
||||
result = optionsArray[idx]->serialize(buffer, size, maxSize, streamEndianness);
|
||||
if (result != returnvalue::OK) {
|
||||
return result;
|
||||
}
|
||||
|
@ -6,7 +6,8 @@
|
||||
|
||||
class MetadataPduCreator : public FileDirectiveCreator {
|
||||
public:
|
||||
MetadataPduCreator(PduConfig& conf, MetadataInfo& info);
|
||||
MetadataPduCreator(PduConfig& conf, MetadataInfo& info, cfdp::Tlv** optionsArray,
|
||||
size_t optionsLen);
|
||||
|
||||
void updateDirectiveFieldLen();
|
||||
|
||||
@ -18,6 +19,8 @@ class MetadataPduCreator : public FileDirectiveCreator {
|
||||
|
||||
private:
|
||||
MetadataInfo& info;
|
||||
cfdp::Tlv** optionsArray;
|
||||
size_t optionsLen;
|
||||
};
|
||||
|
||||
#endif /* FSFW_CFDP_PDU_METADATAPDUCREATOR_H_ */
|
||||
|
@ -1,9 +1,14 @@
|
||||
#include "MetadataPduReader.h"
|
||||
|
||||
MetadataPduReader::MetadataPduReader(const uint8_t* pduBuf, size_t maxSize, MetadataInfo& info)
|
||||
: FileDirectiveReader(pduBuf, maxSize), info(info) {}
|
||||
MetadataPduReader::MetadataPduReader(const uint8_t* pduBuf, size_t maxSize, MetadataInfo& info,
|
||||
cfdp::Tlv* optionsArray, size_t optArrayMaxSize)
|
||||
: FileDirectiveReader(pduBuf, maxSize),
|
||||
info(info),
|
||||
optionArray(optionsArray),
|
||||
optionArrayMaxSize(optArrayMaxSize) {}
|
||||
|
||||
ReturnValue_t MetadataPduReader::parseData() {
|
||||
parsedOptions = 0;
|
||||
ReturnValue_t result = FileDirectiveReader::parseData();
|
||||
if (result != returnvalue::OK) {
|
||||
return result;
|
||||
@ -32,26 +37,24 @@ ReturnValue_t MetadataPduReader::parseData() {
|
||||
return result;
|
||||
}
|
||||
|
||||
info.setOptionsLen(0);
|
||||
if (remSize > 0) {
|
||||
if (not info.canHoldOptions()) {
|
||||
if (optionArrayMaxSize == 0 or optionArray == nullptr) {
|
||||
return cfdp::METADATA_CANT_PARSE_OPTIONS;
|
||||
}
|
||||
cfdp::Tlv** optionsArray = nullptr;
|
||||
size_t optsMaxLen = 0;
|
||||
size_t optsIdx = 0;
|
||||
info.getOptions(&optionsArray, nullptr, &optsMaxLen);
|
||||
while (remSize > 0) {
|
||||
if (optsIdx > optsMaxLen) {
|
||||
if (optsIdx > optionArrayMaxSize) {
|
||||
return cfdp::METADATA_CANT_PARSE_OPTIONS;
|
||||
}
|
||||
result = optionsArray[optsIdx]->deSerialize(&buf, &remSize, endianness);
|
||||
result = optionArray[optsIdx].deSerialize(&buf, &remSize, endianness);
|
||||
if (result != returnvalue::OK) {
|
||||
return result;
|
||||
}
|
||||
optsIdx++;
|
||||
}
|
||||
info.setOptionsLen(optsIdx);
|
||||
parsedOptions = optsIdx;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
size_t MetadataPduReader::getNumberOfParsedOptions() const { return parsedOptions; }
|
||||
|
@ -6,12 +6,17 @@
|
||||
|
||||
class MetadataPduReader : public FileDirectiveReader {
|
||||
public:
|
||||
MetadataPduReader(const uint8_t* pduBuf, size_t maxSize, MetadataInfo& info);
|
||||
MetadataPduReader(const uint8_t* pduBuf, size_t maxSize, MetadataInfo& info,
|
||||
cfdp::Tlv* optionsArray, size_t optArrayMaxSize);
|
||||
|
||||
ReturnValue_t parseData() override;
|
||||
[[nodiscard]] size_t getNumberOfParsedOptions() const;
|
||||
|
||||
private:
|
||||
MetadataInfo& info;
|
||||
cfdp::Tlv* optionArray;
|
||||
size_t optionArrayMaxSize;
|
||||
size_t parsedOptions = 0;
|
||||
};
|
||||
|
||||
#endif /* FSFW_CFDP_PDU_METADATAPDUREADER_H_ */
|
||||
|
@ -61,7 +61,7 @@ TEST_CASE("CFDP Dest Handler", "[cfdp]") {
|
||||
conf.destId = localId;
|
||||
conf.mode = TransmissionMode::UNACKNOWLEDGED;
|
||||
conf.seqNum = seqNum;
|
||||
MetadataPduCreator metadataCreator(conf, info);
|
||||
MetadataPduCreator metadataCreator(conf, info, nullptr, 0);
|
||||
REQUIRE(tcStore.getFreeElement(&storeId, metadataCreator.getSerializedSize(), &buf) == OK);
|
||||
REQUIRE(metadataCreator.serialize(buf, serLen, metadataCreator.getSerializedSize()) == OK);
|
||||
PacketInfo packetInfo(metadataCreator.getPduType(), storeId,
|
||||
|
@ -32,7 +32,7 @@ TEST_CASE("CFDP Distributor", "[cfdp][distributor]") {
|
||||
cfdp::StringLv destFileName(destFileString);
|
||||
MetadataInfo metadataInfo(false, cfdp::ChecksumType::CRC_32, fileSize, sourceFileName,
|
||||
destFileName);
|
||||
MetadataPduCreator creator(pduConf, metadataInfo);
|
||||
MetadataPduCreator creator(pduConf, metadataInfo, nullptr, 0);
|
||||
uint8_t* dataPtr = nullptr;
|
||||
|
||||
SECTION("State") {
|
||||
|
@ -6,11 +6,10 @@
|
||||
#include "fsfw/cfdp/pdu/MetadataPduReader.h"
|
||||
#include "fsfw/cfdp/tlv/FilestoreResponseTlv.h"
|
||||
#include "fsfw/cfdp/tlv/MessageToUserTlv.h"
|
||||
#include "fsfw/globalfunctions/arrayprinter.h"
|
||||
|
||||
TEST_CASE("Metadata PDU", "[cfdp][pdu]") {
|
||||
using namespace cfdp;
|
||||
ReturnValue_t result = returnvalue::OK;
|
||||
ReturnValue_t result;
|
||||
std::array<uint8_t, 256> mdBuffer = {};
|
||||
uint8_t* buffer = mdBuffer.data();
|
||||
size_t sz = 0;
|
||||
@ -30,15 +29,15 @@ TEST_CASE("Metadata PDU", "[cfdp][pdu]") {
|
||||
std::array<uint8_t, 3> msg = {0x41, 0x42, 0x43};
|
||||
cfdp::Tlv responseTlv;
|
||||
std::array<uint8_t, 64> responseBuf = {};
|
||||
uint8_t* responseBufPtr = responseBuf.data();
|
||||
response.convertToTlv(responseTlv, buffer, responseBuf.size(), SerializeIF::Endianness::MACHINE);
|
||||
MessageToUserTlv msgToUser(msg.data(), msg.size());
|
||||
std::array<Tlv*, 2> options{&responseTlv, &msgToUser};
|
||||
std::array<Tlv, 5> tlvDeser{};
|
||||
REQUIRE(options[0]->getSerializedSize() == 2 + 1 + 10 + 1);
|
||||
REQUIRE(options[1]->getSerializedSize() == 5);
|
||||
|
||||
SECTION("Serialize") {
|
||||
MetadataPduCreator serializer(pduConf, info);
|
||||
MetadataPduCreator serializer(pduConf, info, nullptr, 0);
|
||||
result = serializer.serialize(&buffer, &sz, mdBuffer.size(), SerializeIF::Endianness::NETWORK);
|
||||
REQUIRE(result == returnvalue::OK);
|
||||
REQUIRE(serializer.getWholePduSize() == 27);
|
||||
@ -65,19 +64,15 @@ TEST_CASE("Metadata PDU", "[cfdp][pdu]") {
|
||||
REQUIRE(mdBuffer[24] == 'x');
|
||||
REQUIRE(mdBuffer[25] == 't');
|
||||
REQUIRE(mdBuffer[26] == 0);
|
||||
}
|
||||
|
||||
SECTION("Serialize with 2 options") {
|
||||
std::string otherFileName = "hello2.txt";
|
||||
cfdp::StringLv otherFileNameLv(otherFileName.data(), otherFileName.size());
|
||||
info.setSourceFileName(otherFileNameLv);
|
||||
size_t sizeOfOptions = options.size();
|
||||
info.setOptionsArray(options.data(), sizeOfOptions, sizeOfOptions);
|
||||
REQUIRE(info.getMaxOptionsLen() == 2);
|
||||
info.setMaxOptionsLen(3);
|
||||
REQUIRE(info.getMaxOptionsLen() == 3);
|
||||
MetadataPduCreator serializer(pduConf, info, options.data(), options.size());
|
||||
info.setChecksumType(cfdp::ChecksumType::CRC_32C);
|
||||
info.setClosureRequested(true);
|
||||
uint8_t* buffer = mdBuffer.data();
|
||||
size_t sz = 0;
|
||||
serializer.updateDirectiveFieldLen();
|
||||
|
||||
result = serializer.serialize(&buffer, &sz, mdBuffer.size(), SerializeIF::Endianness::NETWORK);
|
||||
@ -98,14 +93,14 @@ TEST_CASE("Metadata PDU", "[cfdp][pdu]") {
|
||||
// TLV unittests
|
||||
REQUIRE(sz == 10 + 37);
|
||||
for (size_t maxSz = 0; maxSz < sz; maxSz++) {
|
||||
uint8_t* buffer = mdBuffer.data();
|
||||
size_t sz = 0;
|
||||
buffer = mdBuffer.data();
|
||||
sz = 0;
|
||||
result = serializer.serialize(&buffer, &sz, maxSz, SerializeIF::Endianness::NETWORK);
|
||||
REQUIRE(result == SerializeIF::BUFFER_TOO_SHORT);
|
||||
}
|
||||
for (size_t initSz = 1; initSz < 47; initSz++) {
|
||||
uint8_t* buffer = mdBuffer.data();
|
||||
size_t sz = initSz;
|
||||
buffer = mdBuffer.data();
|
||||
sz = initSz;
|
||||
result = serializer.serialize(&buffer, &sz, 46, SerializeIF::Endianness::NETWORK);
|
||||
REQUIRE(result == SerializeIF::BUFFER_TOO_SHORT);
|
||||
}
|
||||
@ -113,34 +108,33 @@ TEST_CASE("Metadata PDU", "[cfdp][pdu]") {
|
||||
}
|
||||
|
||||
SECTION("Deserialize") {
|
||||
MetadataPduCreator serializer(pduConf, info);
|
||||
MetadataPduCreator serializer(pduConf, info, nullptr, 0);
|
||||
result = serializer.serialize(&buffer, &sz, mdBuffer.size(), SerializeIF::Endianness::NETWORK);
|
||||
REQUIRE(result == returnvalue::OK);
|
||||
|
||||
MetadataPduReader deserializer(mdBuffer.data(), mdBuffer.size(), info);
|
||||
MetadataPduReader deserializer(mdBuffer.data(), mdBuffer.size(), info, nullptr, 0);
|
||||
result = deserializer.parseData();
|
||||
REQUIRE(result == returnvalue::OK);
|
||||
size_t fullSize = deserializer.getWholePduSize();
|
||||
for (size_t maxSz = 0; maxSz < fullSize; maxSz++) {
|
||||
MetadataPduReader invalidSzDeser(mdBuffer.data(), maxSz, info);
|
||||
MetadataPduReader invalidSzDeser(mdBuffer.data(), maxSz, info, nullptr, 0);
|
||||
result = invalidSzDeser.parseData();
|
||||
REQUIRE(result != returnvalue::OK);
|
||||
}
|
||||
size_t sizeOfOptions = options.size();
|
||||
size_t maxSize = 4;
|
||||
info.setOptionsArray(options.data(), sizeOfOptions, maxSize);
|
||||
REQUIRE(info.getOptionsLen() == 2);
|
||||
}
|
||||
|
||||
SECTION("Deserialize with 2 options") {
|
||||
MetadataPduCreator serializer(pduConf, info, options.data(), options.size());
|
||||
info.setChecksumType(cfdp::ChecksumType::CRC_32C);
|
||||
info.setClosureRequested(true);
|
||||
uint8_t* buffer = mdBuffer.data();
|
||||
size_t sz = 0;
|
||||
serializer.updateDirectiveFieldLen();
|
||||
|
||||
info.setSourceFileName(sourceFileName);
|
||||
result = serializer.serialize(&buffer, &sz, mdBuffer.size(), SerializeIF::Endianness::NETWORK);
|
||||
REQUIRE(result == returnvalue::OK);
|
||||
|
||||
MetadataPduReader deserializer2(mdBuffer.data(), mdBuffer.size(), info);
|
||||
MetadataPduReader deserializer2(mdBuffer.data(), mdBuffer.size(), info, tlvDeser.data(),
|
||||
tlvDeser.max_size());
|
||||
result = deserializer2.parseData();
|
||||
REQUIRE(result == returnvalue::OK);
|
||||
REQUIRE(options[0]->getType() == cfdp::TlvType::FILESTORE_RESPONSE);
|
||||
@ -151,12 +145,15 @@ TEST_CASE("Metadata PDU", "[cfdp][pdu]") {
|
||||
for (size_t invalidFieldLen = 0; invalidFieldLen < 36; invalidFieldLen++) {
|
||||
mdBuffer[1] = (invalidFieldLen >> 8) & 0xff;
|
||||
mdBuffer[2] = invalidFieldLen & 0xff;
|
||||
if (invalidFieldLen == 17) {
|
||||
volatile uint32_t dummy = 0;
|
||||
}
|
||||
result = deserializer2.parseData();
|
||||
if (invalidFieldLen == 17) {
|
||||
REQUIRE(info.getOptionsLen() == 0);
|
||||
REQUIRE(deserializer2.getNumberOfParsedOptions() == 0);
|
||||
}
|
||||
if (invalidFieldLen == 31) {
|
||||
REQUIRE(info.getOptionsLen() == 1);
|
||||
REQUIRE(deserializer2.getNumberOfParsedOptions() == 1);
|
||||
}
|
||||
// This is the precise length where there are no options or one option
|
||||
if (invalidFieldLen != 17 and invalidFieldLen != 31) {
|
||||
@ -165,11 +162,24 @@ TEST_CASE("Metadata PDU", "[cfdp][pdu]") {
|
||||
}
|
||||
mdBuffer[1] = (36 >> 8) & 0xff;
|
||||
mdBuffer[2] = 36 & 0xff;
|
||||
info.setOptionsArray(nullptr, std::nullopt, std::nullopt);
|
||||
}
|
||||
|
||||
SECTION("Can not parse options") {
|
||||
MetadataPduCreator serializer(pduConf, info, options.data(), options.size());
|
||||
info.setChecksumType(cfdp::ChecksumType::CRC_32C);
|
||||
info.setClosureRequested(true);
|
||||
buffer = mdBuffer.data();
|
||||
sz = 0;
|
||||
serializer.updateDirectiveFieldLen();
|
||||
|
||||
info.setSourceFileName(sourceFileName);
|
||||
result = serializer.serialize(&buffer, &sz, mdBuffer.size(), SerializeIF::Endianness::NETWORK);
|
||||
REQUIRE(result == returnvalue::OK);
|
||||
|
||||
MetadataPduReader deserializer2(mdBuffer.data(), mdBuffer.size(), info, nullptr, 0);
|
||||
REQUIRE(deserializer2.parseData() == cfdp::METADATA_CANT_PARSE_OPTIONS);
|
||||
info.setOptionsArray(options.data(), sizeOfOptions, std::nullopt);
|
||||
for (size_t maxSz = 0; maxSz < 46; maxSz++) {
|
||||
MetadataPduReader invalidSzDeser(mdBuffer.data(), maxSz, info);
|
||||
MetadataPduReader invalidSzDeser(mdBuffer.data(), maxSz, info, nullptr, 0);
|
||||
if (not invalidSzDeser.isNull()) {
|
||||
result = invalidSzDeser.parseData();
|
||||
REQUIRE(result == SerializeIF::STREAM_TOO_SHORT);
|
||||
|
Loading…
Reference in New Issue
Block a user