use distributor instead of router

This commit is contained in:
Robin Müller 2022-08-03 18:14:49 +02:00
parent acf5c2a56d
commit c6a7a0fec8
No known key found for this signature in database
GPG Key ID: 11D4952C8CCEF814
6 changed files with 67 additions and 256 deletions

View File

@ -1,4 +1,4 @@
target_sources(${LIB_FSFW_NAME} PRIVATE CfdpMessage.cpp CfdpRouter.cpp) target_sources(${LIB_FSFW_NAME} PRIVATE CfdpMessage.cpp CfdpDistributor.cpp)
# CfdpDistributor.cpp CfdpHandler.cpp # CfdpDistributor.cpp CfdpHandler.cpp
add_subdirectory(pdu) add_subdirectory(pdu)

View File

@ -1,144 +1,53 @@
//#include "CfdpRouter.h" #include "CfdpDistributor.h"
//#include "fsfw/tcdistribution/CcsdsDistributorIF.h"
//#include "fsfw/tmtcpacket/cfdp/CfdpPacketStored.h" #include "fsfw/tcdistribution/definitions.h"
//
//#ifndef FSFW_CFDP_DISTRIBUTOR_DEBUGGING CfdpDistributor::CfdpDistributor(CfdpRouterCfg cfg) : TcDistributorBase(cfg.objectId), cfg(cfg) {}
//#define FSFW_CFDP_DISTRIBUTOR_DEBUGGING 1
//#endif ReturnValue_t CfdpDistributor::registerTcDestination(const cfdp::EntityId& address,
// AcceptsTelecommandsIF& tcDest) {
// CfdpHandler::CfdpHandler(uint16_t setApid, object_id_t setObjectId, for (const auto& dest : tcDestinations) {
// object_id_t setPacketSource) if (dest.id == address) {
// : TcDistributorBase(setObjectId), return HasReturnvaluesIF::RETURN_FAILED;
// apid(setApid), }
// checker(setApid), }
// tcStatus(RETURN_FAILED), tcDestinations.emplace_back(address, tcDest.getName(), tcDest.getRequestQueue());
// packetSource(setPacketSource) {} return HasReturnvaluesIF::RETURN_OK;
// }
// CfdpHandler::~CfdpHandler() = default;
// ReturnValue_t CfdpDistributor::selectDestination(MessageQueueId_t& destId) {
// ReturnValue_t CfdpHandler::selectDestination(MessageQueueId_t& destId) { auto accessorPair = cfg.tcStore.getData(currentMessage.getStorageId());
// //#if FSFW_CFDP_DISTRIBUTOR_DEBUGGING == 1 if (accessorPair.first != HasReturnvaluesIF::RETURN_OK) {
// // store_address_t storeId = this->currentMessage.getStorageId(); return accessorPair.first;
// //#if FSFW_CPP_OSTREAM_ENABLED == 1 }
// // sif::debug << "CFDPDistributor::handlePacket received: " << storeId.poolIndex << ", " ReturnValue_t result = pduReader.setData(accessorPair.second.data(), accessorPair.second.size());
// // << storeId.packetIndex << std::endl; if (result != HasReturnvaluesIF::RETURN_OK) {
// //#else return result;
// // sif::printDebug("CFDPDistributor::handlePacket received: %d, %d\n", storeId.poolIndex, }
// // storeId.packetIndex); result = pduReader.parseData();
// //#endif if (result != HasReturnvaluesIF::RETURN_OK) {
// //#endif return result;
// // auto queueMapIt = this->queueMap.end(); }
// // if (this->currentPacket == nullptr) { cfdp::EntityId foundId;
// // return queueMapIt; pduReader.getDestId(foundId);
// // } bool destFound = false;
// // this->currentPacket->setStoreAddress(this->currentMessage.getStorageId()); for (const auto& dest : tcDestinations) {
// // if (currentPacket->getFullData() != nullptr) { if (dest.id == foundId) {
// // tcStatus = checker.checkPacket(*currentPacket, currentPacket->getFullPacketLen()); destId = dest.queueId;
// // if (tcStatus != HasReturnvaluesIF::RETURN_OK) { destFound = true;
// //#if FSFW_VERBOSE_LEVEL >= 1 }
// //#if FSFW_CPP_OSTREAM_ENABLED == 1 }
// // sif::debug << "CFDPDistributor::handlePacket: Packet format invalid, code " if (not destFound) {
// // << static_cast<int>(tcStatus) << std::endl; // TODO: Warning and event?
// //#else return HasReturnvaluesIF::RETURN_FAILED;
// // sif::printDebug("CFDPDistributor::handlePacket: Packet format invalid, code %d\n", }
// // static_cast<int>(tcStatus)); // Packet was forwarded successfully, so do not delete it.
// //#endif accessorPair.second.release();
// //#endif return HasReturnvaluesIF::RETURN_OK;
// // } }
// // queueMapIt = this->queueMap.find(0);
// // } else { const char* CfdpDistributor::getName() const { return "CFDP Router"; }
// // tcStatus = PACKET_LOST;
// // } uint32_t CfdpDistributor::getIdentifier() const { return 0; }
// //
// // if (queueMapIt == this->queueMap.end()) { MessageQueueId_t CfdpDistributor::getRequestQueue() const { return tcQueue->getId(); }
// // tcStatus = DESTINATION_NOT_FOUND;
// //#if FSFW_VERBOSE_LEVEL >= 1
// //#if FSFW_CPP_OSTREAM_ENABLED == 1
// // sif::debug << "CFDPDistributor::handlePacket: Destination not found" << std::endl;
// //#else
// // sif::printDebug("CFDPDistributor::handlePacket: Destination not found\n");
// //#endif /* !FSFW_CPP_OSTREAM_ENABLED == 1 */
// //#endif
// // }
// //
// // if (tcStatus != RETURN_OK) {
// // return this->queueMap.end();
// // } else {
// // return queueMapIt;
// // }
// return HasReturnvaluesIF::RETURN_OK;
//}
//
// ReturnValue_t CfdpHandler::registerHandler(AcceptsTelecommandsIF* handler) {
// // uint16_t handlerId =
// // handler->getIdentifier(); // should be 0, because CfdpHandler does not set a set a
// // service-ID
// //#if FSFW_CFDP_DISTRIBUTOR_DEBUGGING == 1
// //#if FSFW_CPP_OSTREAM_ENABLED == 1
// // sif::info << "CFDPDistributor::registerHandler: Handler ID: " << static_cast<int>(handlerId)
// // << std::endl;
// //#else
// // sif::printInfo("CFDPDistributor::registerHandler: Handler ID: %d\n",
// // static_cast<int>(handlerId));
// //#endif
// //#endif
// // MessageQueueId_t queue = handler->getRequestQueue();
// // auto returnPair = queueMap.emplace(handlerId, queue);
// // if (not returnPair.second) {
// //#if FSFW_VERBOSE_LEVEL >= 1
// //#if FSFW_CPP_OSTREAM_ENABLED == 1
// // sif::error << "CFDPDistributor::registerHandler: Service ID already"
// // " exists in map"
// // << std::endl;
// //#else
// // sif::printError("CFDPDistributor::registerHandler: Service ID already exists in map\n");
// //#endif
// //#endif
// // return SERVICE_ID_ALREADY_EXISTS;
// // }
// return HasReturnvaluesIF::RETURN_OK;
//}
//
// MessageQueueId_t CfdpHandler::getRequestQueue() const { return tcQueue->getId(); }
//
//// ReturnValue_t CFDPDistributor::callbackAfterSending(ReturnValue_t queueStatus) {
//// if (queueStatus != RETURN_OK) {
//// tcStatus = queueStatus;
//// }
//// if (tcStatus != RETURN_OK) {
//// this->verifyChannel.sendFailureReport(tc_verification::ACCEPTANCE_FAILURE,
//// currentPacket, tcStatus);
//// // A failed packet is deleted immediately after reporting,
//// // otherwise it will block memory.
//// currentPacket->deletePacket();
//// return RETURN_FAILED;
//// } else {
//// this->verifyChannel.sendSuccessReport(tc_verification::ACCEPTANCE_SUCCESS,
//// currentPacket);
//// return RETURN_OK;
//// }
//// }
//
// uint32_t CfdpHandler::getIdentifier() const { return this->apid; }
//
// ReturnValue_t CfdpHandler::initialize() {
// // currentPacket = new CfdpPacketStored();
// // if (currentPacket == nullptr) {
// // // Should not happen, memory allocation failed!
// // return ObjectManagerIF::CHILD_INIT_FAILED;
// // }
// //
// // auto* ccsdsDistributor = ObjectManager::instance()->get<CcsdsDistributorIF>(packetSource);
// // if (ccsdsDistributor == nullptr) {
// //#if FSFW_CPP_OSTREAM_ENABLED == 1
// // sif::error << "CFDPDistributor::initialize: Packet source invalid" << std::endl;
// // sif::error << " Make sure it exists and implements CCSDSDistributorIF!" << std::endl;
// //#else
// // sif::printError("CFDPDistributor::initialize: Packet source invalid\n");
// // sif::printError("Make sure it exists and implements CcsdsDistributorIF\n");
// //#endif
// // return RETURN_FAILED;
// // }
// // return ccsdsDistributor->registerApplication(this);
// return HasReturnvaluesIF::RETURN_OK;
//}

View File

@ -4,7 +4,7 @@
#include <utility> #include <utility>
#include <vector> #include <vector>
#include "CfdpRouterIF.h" #include "fsfw/cfdp/pdu/HeaderReader.h"
#include "fsfw/returnvalues/HasReturnvaluesIF.h" #include "fsfw/returnvalues/HasReturnvaluesIF.h"
#include "fsfw/tcdistribution/CfdpPacketChecker.h" #include "fsfw/tcdistribution/CfdpPacketChecker.h"
#include "fsfw/tcdistribution/TcDistributorBase.h" #include "fsfw/tcdistribution/TcDistributorBase.h"
@ -13,22 +13,23 @@
#include "fsfw/tmtcservices/VerificationReporter.h" #include "fsfw/tmtcservices/VerificationReporter.h"
struct CfdpRouterCfg { struct CfdpRouterCfg {
CfdpRouterCfg(object_id_t objectId, MessageQueueIF& tmQueue) CfdpRouterCfg(object_id_t objectId, MessageQueueIF& tmQueue, StorageManagerIF& tcStore,
: objectId(objectId), tmQueue(tmQueue) {} StorageManagerIF& tmStore)
: objectId(objectId), tmQueue(tmQueue), tcStore(tcStore), tmStore(tmStore) {}
object_id_t objectId; object_id_t objectId;
MessageQueueIF& tmQueue; MessageQueueIF& tmQueue;
StorageManagerIF& tcStore;
StorageManagerIF& tmStore;
}; };
/** /**
* This will be the primary component to perform PDU forwading procedures. This includes forwarding * This will be the primary component to perform PDU forwading procedures. This includes forwarding
* CFDP TC packets to registered source or destination handlers, and forwarding all telemetry * CFDP TC packets to registered source or destination handlers, and forwarding all telemetry
* generated by them to registered TM sinks. * generated by them to registered TM sinks.
* @ingroup tc_distribution * @ingroup tc_distribution
*/ */
class CfdpRouter : public TcDistributorBase, class CfdpDistributor : public TcDistributorBase, public AcceptsTelecommandsIF {
public CfdpRouterIF,
public AcceptsTelecommandsIF,
public AcceptsTelemetryIF {
public: public:
/** /**
* The ctor passes @c set_apid to the checker class and calls the * The ctor passes @c set_apid to the checker class and calls the
@ -38,17 +39,12 @@ class CfdpRouter : public TcDistributorBase,
* @param setPacketSource Object ID of the source of TC packets. * @param setPacketSource Object ID of the source of TC packets.
* Must implement CcsdsDistributorIF. * Must implement CcsdsDistributorIF.
*/ */
explicit CfdpRouter(CfdpRouterCfg cfg); explicit CfdpDistributor(CfdpRouterCfg cfg);
ReturnValue_t performOperation(uint8_t opCode) override;
ReturnValue_t performTmHandling();
[[nodiscard]] const char* getName() const override; [[nodiscard]] const char* getName() const override;
[[nodiscard]] uint32_t getIdentifier() const override; [[nodiscard]] uint32_t getIdentifier() const override;
[[nodiscard]] MessageQueueId_t getRequestQueue() const override; [[nodiscard]] MessageQueueId_t getRequestQueue() const override;
MessageQueueId_t getReportReceptionQueue(uint8_t virtualChannel) override; ReturnValue_t registerTcDestination(const cfdp::EntityId& address, AcceptsTelecommandsIF& tcDest);
ReturnValue_t registerTmSink(cfdp::EntityId address, AcceptsTelemetryIF& tmDest) override;
ReturnValue_t registerTcDestination(cfdp::EntityId address,
AcceptsTelecommandsIF& tcDest) override;
protected: protected:
struct EntityInfo { struct EntityInfo {
@ -58,13 +54,13 @@ class CfdpRouter : public TcDistributorBase,
const char* name; const char* name;
MessageQueueId_t queueId; MessageQueueId_t queueId;
}; };
HeaderReader pduReader;
ReturnValue_t lastTcError = HasReturnvaluesIF::RETURN_OK; ReturnValue_t lastTcError = HasReturnvaluesIF::RETURN_OK;
ReturnValue_t lastTmError = HasReturnvaluesIF::RETURN_OK; ReturnValue_t lastTmError = HasReturnvaluesIF::RETURN_OK;
// I don't think a regular OBSW will have more than 1 or 2 of these destinations, so I think // I don't think a regular OBSW will have more than 1 or 2 of these destinations, so I think
// it is okay to accept the overhead here // it is okay to accept the overhead here
std::vector<EntityInfo> tmDestinations;
std::vector<EntityInfo> tcDestinations; std::vector<EntityInfo> tcDestinations;
MessageQueueIF& tmQueue; CfdpRouterCfg cfg;
ReturnValue_t selectDestination(MessageQueueId_t& destId) override; ReturnValue_t selectDestination(MessageQueueId_t& destId) override;

View File

@ -1,63 +0,0 @@
#include "CfdpRouter.h"
#include "fsfw/tcdistribution/definitions.h"
CfdpRouter::CfdpRouter(CfdpRouterCfg cfg) : TcDistributorBase(cfg.objectId), tmQueue(cfg.tmQueue) {}
ReturnValue_t CfdpRouter::registerTmSink(cfdp::EntityId address, AcceptsTelemetryIF& tmDest) {
for (const auto& dest : tmDestinations) {
if (dest.id == address) {
return HasReturnvaluesIF::RETURN_FAILED;
}
}
tmDestinations.emplace_back(address, tmDest.getName(), tmDest.getReportReceptionQueue());
return HasReturnvaluesIF::RETURN_OK;
}
ReturnValue_t CfdpRouter::registerTcDestination(cfdp::EntityId address,
AcceptsTelecommandsIF& tcDest) {
for (const auto& dest : tcDestinations) {
if (dest.id == address) {
return HasReturnvaluesIF::RETURN_FAILED;
}
}
tcDestinations.emplace_back(address, tcDest.getName(), tcDest.getRequestQueue());
return HasReturnvaluesIF::RETURN_OK;
}
ReturnValue_t CfdpRouter::selectDestination(MessageQueueId_t& destId) { return 0; }
const char* CfdpRouter::getName() const { return "CFDP Router"; }
uint32_t CfdpRouter::getIdentifier() const { return 0; }
MessageQueueId_t CfdpRouter::getRequestQueue() const { return tcQueue->getId(); }
MessageQueueId_t CfdpRouter::getReportReceptionQueue(uint8_t virtualChannel) {
return tmQueue.getId();
}
ReturnValue_t CfdpRouter::performOperation(uint8_t opCode) {
lastTcError = TcDistributorBase::performOperation(opCode);
lastTmError = performTmHandling();
if (lastTcError != HasReturnvaluesIF::RETURN_OK or lastTmError != HasReturnvaluesIF::RETURN_OK) {
return HasReturnvaluesIF::RETURN_FAILED;
}
return HasReturnvaluesIF::RETURN_OK;
}
ReturnValue_t CfdpRouter::performTmHandling() {
ReturnValue_t status;
ReturnValue_t result = HasReturnvaluesIF::RETURN_OK;
for (status = tmQueue.receiveMessage(&currentMessage); status == RETURN_OK;
status = tmQueue.receiveMessage(&currentMessage)) {
ReturnValue_t packetResult = handlePacket();
if (packetResult != HasReturnvaluesIF::RETURN_OK) {
result = packetResult;
triggerEvent(tmtcdistrib::HANDLE_PACKET_FAILED, packetResult, ccsds::PacketType::TM);
}
}
if (status == MessageQueueIF::EMPTY) {
return result;
}
return result;
}

View File

@ -1,32 +0,0 @@
#ifndef FSFW_TCDISTRIBUTION_CFDPDISTRIBUTORIF_H_
#define FSFW_TCDISTRIBUTION_CFDPDISTRIBUTORIF_H_
#include "fsfw/cfdp/definitions.h"
#include "fsfw/cfdp/pdu/PduHeaderIF.h"
#include "fsfw/ipc/MessageQueueSenderIF.h"
#include "fsfw/tmtcservices/AcceptsTelecommandsIF.h"
#include "fsfw/tmtcservices/AcceptsTelemetryIF.h"
/**
* This interface allows CFDP Services to register themselves at a CFDP Distributor.
* @ingroup tc_distribution
*/
class CfdpRouterIF {
public:
/**
* The empty virtual destructor.
*/
virtual ~CfdpRouterIF() = default;
virtual ReturnValue_t registerTmSink(cfdp::EntityId address, AcceptsTelemetryIF& tmDest) = 0;
/**
* With this method, Handlers can register themselves at the CFDP Distributor.
* @param handler A pointer to the registering Handler.
* @return - @c RETURN_OK on success,
* - @c RETURN_FAILED on failure.
*/
virtual ReturnValue_t registerTcDestination(cfdp::EntityId address,
AcceptsTelecommandsIF& tcDest) = 0;
};
#endif /* FSFW_TCDISTRIBUTION_CFDPDISTRIBUTORIF_H_ */

View File

@ -25,6 +25,7 @@ struct PduHeaderFixedStruct {
*/ */
class HeaderReader : public RedirectableDataPointerIF, public PduHeaderIF { class HeaderReader : public RedirectableDataPointerIF, public PduHeaderIF {
public: public:
HeaderReader() = default;
/** /**
* Initialize a PDU header from raw data. This is a zero-copy implementation and #parseData * Initialize a PDU header from raw data. This is a zero-copy implementation and #parseData
* needs to be called to ensure the data is valid * needs to be called to ensure the data is valid