CFDP SOURCE handler #157
@ -204,6 +204,11 @@ ReturnValue_t cfdp::SourceHandler::transactionStart(PutRequest& putRequest, Remo
|
|||||||
if (fileSize > UINT32_MAX) {
|
if (fileSize > UINT32_MAX) {
|
||||||
transactionParams.pduConf.largeFile = true;
|
transactionParams.pduConf.largeFile = true;
|
||||||
}
|
}
|
||||||
|
if (fileSize == 0) {
|
||||||
|
transactionParams.checksumType = ChecksumType::NULL_CHECKSUM;
|
||||||
|
} else {
|
||||||
|
transactionParams.checksumType = ChecksumType::CRC_32;
|
||||||
|
}
|
||||||
transactionParams.fileSize.setFileSize(fileSize, transactionParams.pduConf.largeFile);
|
transactionParams.fileSize.setFileSize(fileSize, transactionParams.pduConf.largeFile);
|
||||||
transactionParams.remoteCfg = cfg;
|
transactionParams.remoteCfg = cfg;
|
||||||
return OK;
|
return OK;
|
||||||
@ -212,7 +217,9 @@ ReturnValue_t cfdp::SourceHandler::transactionStart(PutRequest& putRequest, Remo
|
|||||||
ReturnValue_t cfdp::SourceHandler::prepareAndSendMetadataPdu() {
|
ReturnValue_t cfdp::SourceHandler::prepareAndSendMetadataPdu() {
|
||||||
cfdp::StringLv sourceName(transactionParams.sourceName.data(), transactionParams.sourceNameSize);
|
cfdp::StringLv sourceName(transactionParams.sourceName.data(), transactionParams.sourceNameSize);
|
||||||
cfdp::StringLv destName(transactionParams.destName.data(), transactionParams.destNameSize);
|
cfdp::StringLv destName(transactionParams.destName.data(), transactionParams.destNameSize);
|
||||||
auto metadataInfo = MetadataGenericInfo(transactionParams.fileSize);
|
auto metadataInfo =
|
||||||
|
MetadataGenericInfo(transactionParams.closureRequested, transactionParams.checksumType,
|
||||||
|
transactionParams.fileSize);
|
||||||
auto metadataPdu =
|
auto metadataPdu =
|
||||||
MetadataPduCreator(transactionParams.pduConf, metadataInfo, sourceName, destName, nullptr, 0);
|
MetadataPduCreator(transactionParams.pduConf, metadataInfo, sourceName, destName, nullptr, 0);
|
||||||
ReturnValue_t result = sendGenericPdu(metadataPdu);
|
ReturnValue_t result = sendGenericPdu(metadataPdu);
|
||||||
|
@ -73,6 +73,7 @@ class SourceHandler {
|
|||||||
cfdp::Fss fileSize;
|
cfdp::Fss fileSize;
|
||||||
size_t progress = 0;
|
size_t progress = 0;
|
||||||
bool closureRequested = false;
|
bool closureRequested = false;
|
||||||
|
ChecksumType checksumType = ChecksumType::NULL_CHECKSUM;
|
||||||
RemoteEntityCfg remoteCfg;
|
RemoteEntityCfg remoteCfg;
|
||||||
PduConfig pduConf;
|
PduConfig pduConf;
|
||||||
cfdp::TransactionId id{};
|
cfdp::TransactionId id{};
|
||||||
|
@ -17,7 +17,7 @@ struct FilesystemParams {
|
|||||||
};
|
};
|
||||||
|
|
||||||
struct FileOpParams {
|
struct FileOpParams {
|
||||||
FileOpParams(const char* path, size_t size) : fsParams(path), size(size) {}
|
FileOpParams(const char* path, size_t opSize) : fsParams(path), size(opSize) {}
|
||||||
|
|
||||||
[[nodiscard]] const char* path() const { return fsParams.path; }
|
[[nodiscard]] const char* path() const { return fsParams.path; }
|
||||||
|
|
||||||
|
@ -43,14 +43,7 @@ TEST_CASE("CFDP Source Handler", "[cfdp]") {
|
|||||||
fp.tcStore = &tcStore;
|
fp.tcStore = &tcStore;
|
||||||
fp.tmStore = &tmStore;
|
fp.tmStore = &tmStore;
|
||||||
auto sourceHandler = SourceHandler(dp, fp);
|
auto sourceHandler = SourceHandler(dp, fp);
|
||||||
CHECK(sourceHandler.initialize() == OK);
|
|
||||||
|
|
||||||
SECTION("Test Basic") {
|
|
||||||
CHECK(sourceHandler.getState() == CfdpState::IDLE);
|
|
||||||
CHECK(sourceHandler.getStep() == SourceHandler::TransactionStep::IDLE);
|
|
||||||
}
|
|
||||||
|
|
||||||
SECTION("Transfer empty file") {
|
|
||||||
RemoteEntityCfg cfg;
|
RemoteEntityCfg cfg;
|
||||||
EntityId id(cfdp::WidthInBytes::TWO_BYTES, 5);
|
EntityId id(cfdp::WidthInBytes::TWO_BYTES, 5);
|
||||||
cfg.remoteId = id;
|
cfg.remoteId = id;
|
||||||
@ -62,13 +55,11 @@ TEST_CASE("CFDP Source Handler", "[cfdp]") {
|
|||||||
FilesystemParams destFileNameFs(destFileName.c_str());
|
FilesystemParams destFileNameFs(destFileName.c_str());
|
||||||
cfdp::StringLv destNameLv(destFileNameFs.path, std::strlen(destFileNameFs.path));
|
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.initialize() == OK);
|
||||||
SourceHandler::FsmResult& fsmResult = sourceHandler.stateMachine();
|
|
||||||
|
|
||||||
|
auto genericMetadataCheck = [&](SourceHandler::FsmResult& fsmResult, size_t expectedFileSize) {
|
||||||
TmTcMessage tmtcMessage;
|
TmTcMessage tmtcMessage;
|
||||||
const uint8_t* pduPtr;
|
const uint8_t* pduPtr;
|
||||||
// Verify metadata PDU was sent.
|
|
||||||
{
|
|
||||||
CHECK(fsmResult.packetsSent == 1);
|
CHECK(fsmResult.packetsSent == 1);
|
||||||
CHECK(mqMock.numberOfSentMessages() == 1);
|
CHECK(mqMock.numberOfSentMessages() == 1);
|
||||||
REQUIRE(mqMock.getNextSentMessage(destQueueId, tmtcMessage) == OK);
|
REQUIRE(mqMock.getNextSentMessage(destQueueId, tmtcMessage) == OK);
|
||||||
@ -83,15 +74,19 @@ TEST_CASE("CFDP Source Handler", "[cfdp]") {
|
|||||||
CHECK(srcNameRead == srcFileName);
|
CHECK(srcNameRead == srcFileName);
|
||||||
std::string destNameRead = metadataReader.getDestFileName().getString();
|
std::string destNameRead = metadataReader.getDestFileName().getString();
|
||||||
CHECK(destNameRead == destFileName);
|
CHECK(destNameRead == destFileName);
|
||||||
|
if (expectedFileSize == 0) {
|
||||||
CHECK(metadataInfo.getChecksumType() == ChecksumType::NULL_CHECKSUM);
|
CHECK(metadataInfo.getChecksumType() == ChecksumType::NULL_CHECKSUM);
|
||||||
CHECK(metadataInfo.getFileSize().value() == 0);
|
} else {
|
||||||
CHECK(!metadataInfo.isClosureRequested());
|
CHECK(metadataInfo.getChecksumType() == ChecksumType::CRC_32);
|
||||||
}
|
}
|
||||||
|
CHECK(metadataInfo.getFileSize().value() == expectedFileSize);
|
||||||
// Verify EOF PDU was sent. No file data PDU is sent for an empty file.
|
CHECK(!metadataInfo.isClosureRequested());
|
||||||
{
|
|
||||||
mqMock.clearMessages();
|
mqMock.clearMessages();
|
||||||
fsmResult = sourceHandler.stateMachine();
|
};
|
||||||
|
auto genericEofCheck = [&](SourceHandler::FsmResult& fsmResult, size_t expectedFileSize,
|
||||||
|
uint32_t expectedChecksum) {
|
||||||
|
TmTcMessage tmtcMessage;
|
||||||
|
const uint8_t* pduPtr;
|
||||||
CHECK(fsmResult.packetsSent == 1);
|
CHECK(fsmResult.packetsSent == 1);
|
||||||
CHECK(mqMock.numberOfSentMessages() == 1);
|
CHECK(mqMock.numberOfSentMessages() == 1);
|
||||||
REQUIRE(mqMock.getNextSentMessage(destQueueId, tmtcMessage) == OK);
|
REQUIRE(mqMock.getNextSentMessage(destQueueId, tmtcMessage) == OK);
|
||||||
@ -104,14 +99,46 @@ TEST_CASE("CFDP Source Handler", "[cfdp]") {
|
|||||||
EofInfo eofInfo;
|
EofInfo eofInfo;
|
||||||
EofPduReader eofReader(pduPtr, accessor.second.size(), eofInfo);
|
EofPduReader eofReader(pduPtr, accessor.second.size(), eofInfo);
|
||||||
REQUIRE(eofReader.parseData() == OK);
|
REQUIRE(eofReader.parseData() == OK);
|
||||||
CHECK(eofInfo.getChecksum() == 0);
|
CHECK(eofInfo.getChecksum() == expectedChecksum);
|
||||||
CHECK(eofInfo.getConditionCode() == ConditionCode::NO_ERROR);
|
CHECK(eofInfo.getConditionCode() == ConditionCode::NO_ERROR);
|
||||||
CHECK(eofInfo.getFileSize().value() == 0);
|
CHECK(eofInfo.getFileSize().value() == expectedFileSize);
|
||||||
|
};
|
||||||
|
SECTION("Test Basic") {
|
||||||
|
CHECK(sourceHandler.getState() == CfdpState::IDLE);
|
||||||
|
CHECK(sourceHandler.getStep() == SourceHandler::TransactionStep::IDLE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SECTION("Transfer empty file") {
|
||||||
|
CHECK(sourceHandler.transactionStart(putRequest, cfg) == OK);
|
||||||
|
|
||||||
|
SourceHandler::FsmResult& fsmResult = sourceHandler.stateMachine();
|
||||||
|
// Verify metadata PDU was sent.
|
||||||
|
genericMetadataCheck(fsmResult, 0);
|
||||||
|
|
||||||
|
fsmResult = sourceHandler.stateMachine();
|
||||||
|
// Verify EOF PDU was sent. No file data PDU is sent for an empty file.
|
||||||
|
genericEofCheck(fsmResult, 0, 0);
|
||||||
|
|
||||||
CHECK(sourceHandler.getStep() == SourceHandler::TransactionStep::IDLE);
|
CHECK(sourceHandler.getStep() == SourceHandler::TransactionStep::IDLE);
|
||||||
CHECK(sourceHandler.getState() == CfdpState::IDLE);
|
CHECK(sourceHandler.getState() == CfdpState::IDLE);
|
||||||
}
|
}
|
||||||
|
|
||||||
SECTION("Transfer small file") {}
|
SECTION("Transfer small file") {
|
||||||
|
fsMock.createFile(srcFileNameFs);
|
||||||
|
std::string fileContent = "hello world\n";
|
||||||
|
size_t expectedFileSize = fileContent.size();
|
||||||
|
FileOpParams params(srcFileName.c_str(), expectedFileSize);
|
||||||
|
fsMock.writeToFile(params, reinterpret_cast<const uint8_t*>(fileContent.data()));
|
||||||
|
CHECK(sourceHandler.transactionStart(putRequest, cfg) == OK);
|
||||||
|
SourceHandler::FsmResult& fsmResult = sourceHandler.stateMachine();
|
||||||
|
|
||||||
|
// Verify metadata PDU was sent.
|
||||||
|
genericMetadataCheck(fsmResult, expectedFileSize);
|
||||||
|
fsmResult = sourceHandler.stateMachine();
|
||||||
|
// TODO: Verify one file data PDU was sent.
|
||||||
|
|
||||||
|
// TODO: Verify one EOF PDU was sent.
|
||||||
|
}
|
||||||
|
|
||||||
SECTION("Transfer two segment file") {}
|
SECTION("Transfer two segment file") {}
|
||||||
}
|
}
|
@ -80,7 +80,7 @@ ReturnValue_t FilesystemMock::removeDirectory(FilesystemParams params, bool dele
|
|||||||
|
|
||||||
ReturnValue_t FilesystemMock::rename(const char *oldPath, const char *newPath,
|
ReturnValue_t FilesystemMock::rename(const char *oldPath, const char *newPath,
|
||||||
FileSystemArgsIF *args) {
|
FileSystemArgsIF *args) {
|
||||||
renameQueue.push(RenameInfo(oldPath, newPath));
|
renameQueue.emplace(oldPath, newPath);
|
||||||
return returnvalue::OK;
|
return returnvalue::OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -90,7 +90,7 @@ void FilesystemMock::createOrAddToFile(FileOpParams params, const uint8_t *data)
|
|||||||
if (iter == fileMap.end()) {
|
if (iter == fileMap.end()) {
|
||||||
FileSegmentQueue queue;
|
FileSegmentQueue queue;
|
||||||
if (params.size > 0) {
|
if (params.size > 0) {
|
||||||
queue.push(FileWriteInfo(filename, params.offset, data, params.size));
|
queue.emplace(filename, params.offset, data, params.size);
|
||||||
}
|
}
|
||||||
FileInfo info;
|
FileInfo info;
|
||||||
info.fileSegQueue = queue;
|
info.fileSegQueue = queue;
|
||||||
@ -100,7 +100,7 @@ void FilesystemMock::createOrAddToFile(FileOpParams params, const uint8_t *data)
|
|||||||
fileMap.emplace(filename, info);
|
fileMap.emplace(filename, info);
|
||||||
} else {
|
} else {
|
||||||
FileInfo &info = iter->second;
|
FileInfo &info = iter->second;
|
||||||
info.fileSegQueue.push(FileWriteInfo(filename, params.offset, data, params.size));
|
info.fileSegQueue.emplace(filename, params.offset, data, params.size);
|
||||||
if (data == nullptr) {
|
if (data == nullptr) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -149,7 +149,7 @@ bool FilesystemMock::isDirectory(const char *path) { return false; }
|
|||||||
bool FilesystemMock::getFileSize(FilesystemParams params, size_t &fileSize) {
|
bool FilesystemMock::getFileSize(FilesystemParams params, size_t &fileSize) {
|
||||||
std::string filename(params.path);
|
std::string filename(params.path);
|
||||||
auto iter = fileMap.find(filename);
|
auto iter = fileMap.find(filename);
|
||||||
if (iter == fileMap.end()) {
|
if (iter != fileMap.end()) {
|
||||||
fileSize = iter->second.fileRaw.size();
|
fileSize = iter->second.fileRaw.size();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user