metadata PDU seems to be correct

This commit is contained in:
Robin Müller 2023-08-03 15:30:38 +02:00
parent daf75547a4
commit dffce43e6b
Signed by: muellerr
GPG Key ID: 407F9B00F858F270
7 changed files with 44 additions and 33 deletions

View File

@ -156,8 +156,8 @@ ReturnValue_t cfdp::SourceHandler::transactionStart(PutRequest& putRequest, Remo
if (putRequest.getDestName().getValueLen() == 0) { if (putRequest.getDestName().getValueLen() == 0) {
return DEST_NAME_EMPTY; return DEST_NAME_EMPTY;
} }
const char* srcNamePtr = putRequest.getSourceName().getString(transactionParams.sourceNameSize); const char* srcNamePtr = putRequest.getSourceName().getCString(transactionParams.sourceNameSize);
const char* destNamePtr = putRequest.getDestName().getString(transactionParams.destNameSize); const char* destNamePtr = putRequest.getDestName().getCString(transactionParams.destNameSize);
std::strncpy(transactionParams.sourceName.data(), srcNamePtr, transactionParams.sourceNameSize); std::strncpy(transactionParams.sourceName.data(), srcNamePtr, transactionParams.sourceNameSize);
std::strncpy(transactionParams.destName.data(), destNamePtr, transactionParams.destNameSize); std::strncpy(transactionParams.destName.data(), destNamePtr, transactionParams.destNameSize);
FilesystemParams params(transactionParams.sourceName.data()); FilesystemParams params(transactionParams.sourceName.data());
@ -176,10 +176,15 @@ ReturnValue_t cfdp::SourceHandler::transactionStart(PutRequest& putRequest, Remo
transactionParams.closureRequested = cfg.closureRequested; transactionParams.closureRequested = cfg.closureRequested;
} }
const EntityId& destId = putRequest.getDestId(); const EntityId& destId = putRequest.getDestId();
transactionParams.pduConf.destId = destId; // The width of the source and destination ID must be the same. Use the larger ID value to
// Adapt source ID width to necessary width. The width of the source and destination ID must be // ensure the width is large enough for both IDs
// the same. if (destId.getWidth() > transactionParams.pduConf.sourceId.getWidth()) {
transactionParams.pduConf.sourceId.setWidth(destId.getWidth()); transactionParams.pduConf.destId = destId;
transactionParams.pduConf.sourceId.setWidth(destId.getWidth());
} else {
transactionParams.pduConf.destId.setValueAndWidth(transactionParams.pduConf.sourceId.getWidth(),
destId.getValue());
}
// Only used for PDU forwarding, file is sent to file receiver regularly here. // Only used for PDU forwarding, file is sent to file receiver regularly here.
transactionParams.pduConf.direction = Direction::TOWARDS_RECEIVER; transactionParams.pduConf.direction = Direction::TOWARDS_RECEIVER;
transactionParams.id.seqNum.setValue(sourceParams.seqCountProvider.getAndIncrement()); transactionParams.id.seqNum.setValue(sourceParams.seqCountProvider.getAndIncrement());
@ -301,7 +306,6 @@ ReturnValue_t cfdp::SourceHandler::sendGenericPdu(const SerializeIF& pdu) const
if (result != OK) { if (result != OK) {
return result; return result;
} }
arrayprinter::print(dataPtr, serializedLen);
TmTcMessage tmMsg(storeId); TmTcMessage tmMsg(storeId);
return fsfwParams.msgQueue->sendMessage(fsfwParams.packetDest.getReportReceptionQueue(), &tmMsg); return fsfwParams.msgQueue->sendMessage(fsfwParams.packetDest.getReportReceptionQueue(), &tmMsg);
} }

View File

@ -76,7 +76,6 @@ class SourceHandler {
RemoteEntityCfg remoteCfg; RemoteEntityCfg remoteCfg;
PduConfig pduConf; PduConfig pduConf;
cfdp::TransactionId id{}; cfdp::TransactionId id{};
// cfdp::WidthInBytes seqCountWidth{};
void reset() { void reset() {
sourceNameSize = 0; sourceNameSize = 0;

View File

@ -11,8 +11,8 @@ class MetadataPduReader : public FileDirectiveReader {
ReturnValue_t parseData() override; ReturnValue_t parseData() override;
const cfdp::StringLv& getSourceFileName() const; [[nodiscard]] const cfdp::StringLv& getSourceFileName() const;
const cfdp::StringLv& getDestFileName() const; [[nodiscard]] const cfdp::StringLv& getDestFileName() const;
[[nodiscard]] size_t getNumberOfParsedOptions() const; [[nodiscard]] size_t getNumberOfParsedOptions() const;

View File

@ -8,6 +8,11 @@ cfdp::StringLv::StringLv(const char* filename, size_t len)
cfdp::StringLv::StringLv() : Lv() {} cfdp::StringLv::StringLv() : Lv() {}
const char* cfdp::StringLv::getString(size_t& fileSize) const { const char* cfdp::StringLv::getCString(size_t& fileSize) const {
return reinterpret_cast<const char*>(getValue(&fileSize)); return reinterpret_cast<const char*>(getValue(&fileSize));
} }
std::string cfdp::StringLv::getString() const {
size_t fileSize;
return {getCString(fileSize), fileSize};
}

View File

@ -13,7 +13,8 @@ class StringLv : public Lv {
explicit StringLv(const std::string& fileName); explicit StringLv(const std::string& fileName);
explicit StringLv(const char* filename, size_t len); explicit StringLv(const char* filename, size_t len);
const char* getString(size_t& fileSize) const; const char* getCString(size_t& fileSize) const;
std::string getString() const;
// Delete the move constructor to avoid passing in a temporary // Delete the move constructor to avoid passing in a temporary
StringLv(const std::string&&) = delete; StringLv(const std::string&&) = delete;
}; };

View File

@ -58,14 +58,10 @@ TEST_CASE("Reserved Message Parser", "[cfdp]") {
REQUIRE(putRequest.deSerialize(&data, &dummy, SerializeIF::Endianness::MACHINE) == OK); REQUIRE(putRequest.deSerialize(&data, &dummy, SerializeIF::Endianness::MACHINE) == OK);
CHECK(putRequest.getDestId().getValue() == entityId.getValue()); CHECK(putRequest.getDestId().getValue() == entityId.getValue());
CHECK(putRequest.getDestId().getWidth() == entityId.getWidth()); CHECK(putRequest.getDestId().getWidth() == entityId.getWidth());
size_t sourceNameSize = 0;
auto& sourceNameLv = putRequest.getSourceName(); auto& sourceNameLv = putRequest.getSourceName();
const char* sourceString = sourceNameLv.getString(sourceNameSize); std::string srcNameRead = sourceNameLv.getString();
CHECK(sourceNameSize == srcFileName.size()); CHECK(srcNameRead == srcFileName);
CHECK(std::strncmp(sourceString, srcFileName.c_str(), sourceNameSize) == 0);
size_t destNameSize = 0;
auto& destNameLv = putRequest.getDestName(); auto& destNameLv = putRequest.getDestName();
const char* destString = destNameLv.getString(destNameSize); std::string destNameRead = destNameLv.getString();
CHECK(destNameSize == destFileName.size()); CHECK(destNameRead == destFileName);
CHECK(std::strncmp(destString, destFileName.c_str(), destNameSize) == 0);
} }

View File

@ -54,18 +54,21 @@ TEST_CASE("CFDP Source Handler", "[cfdp]") {
} }
SECTION("Transfer empty file") { SECTION("Transfer empty file") {
// using StorageManagerIF::getData;
RemoteEntityCfg cfg; RemoteEntityCfg cfg;
EntityId id(cfdp::WidthInBytes::ONE_BYTE, 5); EntityId id(cfdp::WidthInBytes::TWO_BYTES, 5);
cfg.remoteId = id; cfg.remoteId = id;
FilesystemParams srcFileName("/tmp/cfdp-test.txt"); std::string srcFileName = "/tmp/cfdp-test.txt";
fsMock.createFile(srcFileName); std::string destFileName = "/tmp/cfdp-test2.txt";
cfdp::StringLv srcNameLv(srcFileName.path, std::strlen(srcFileName.path)); FilesystemParams srcFileNameFs(srcFileName.c_str());
FilesystemParams destFileName("/tmp/cfdp-test2.txt"); fsMock.createFile(srcFileNameFs);
cfdp::StringLv destNameLv(destFileName.path, std::strlen(destFileName.path)); cfdp::StringLv srcNameLv(srcFileNameFs.path, std::strlen(srcFileNameFs.path));
FilesystemParams destFileNameFs(destFileName.c_str());
cfdp::StringLv destNameLv(destFileNameFs.path, std::strlen(destFileNameFs.path));
PutRequest putRequest(id, srcNameLv, destNameLv); PutRequest putRequest(id, srcNameLv, destNameLv);
CHECK(sourceHandler.transactionStart(putRequest, cfg) == OK); CHECK(sourceHandler.transactionStart(putRequest, cfg) == OK);
SourceHandler::FsmResult& fsmResult = sourceHandler.stateMachine(); SourceHandler::FsmResult& fsmResult = sourceHandler.stateMachine();
// Verify metadata PDU was sent.
CHECK(fsmResult.packetsSent == 1); CHECK(fsmResult.packetsSent == 1);
CHECK(mqMock.numberOfSentMessages() == 1); CHECK(mqMock.numberOfSentMessages() == 1);
TmTcMessage tmtcMessage; TmTcMessage tmtcMessage;
@ -76,12 +79,15 @@ TEST_CASE("CFDP Source Handler", "[cfdp]") {
CHECK(accessor.second.size() == 55); CHECK(accessor.second.size() == 55);
MetadataGenericInfo metadataInfo; MetadataGenericInfo metadataInfo;
MetadataPduReader metadataReader(pduPtr, accessor.second.size(), metadataInfo, nullptr, 0); MetadataPduReader metadataReader(pduPtr, accessor.second.size(), metadataInfo, nullptr, 0);
size_t srcFileSize = 0;
arrayprinter::print(pduPtr, accessor.second.size());
REQUIRE(metadataReader.parseData() == OK); REQUIRE(metadataReader.parseData() == OK);
const char* srcNameRead = metadataReader.getSourceFileName().getString(srcFileSize); std::string srcNameRead = metadataReader.getSourceFileName().getString();
REQUIRE(srcNameRead != nullptr); CHECK(srcNameRead == srcFileName);
std::string srcNameReadStr(srcNameRead, srcFileSize); std::string destNameRead = metadataReader.getDestFileName().getString();
CHECK(std::string(srcFileName.path) == srcNameReadStr); CHECK(destNameRead == destFileName);
CHECK(metadataInfo.getChecksumType() == ChecksumType::NULL_CHECKSUM);
CHECK(metadataInfo.getFileSize().value() == 0);
CHECK(!metadataInfo.isClosureRequested());
// Verify EOF PDU was sent. No file data PDU is sent for an empty file.
} }
} }