F´ Flight Software - C/C++ Documentation
A framework for building embedded system applications to NASA flight quality standards.
SdlsSaRouter.cpp
Go to the documentation of this file.
1 // ======================================================================
2 // \title SdlsSaRouter.cpp
3 // \author lestarch-autobot
4 // \brief cpp file for SdlsSaRouter component implementation class
5 // ======================================================================
6 
8 
9 namespace Svc {
10 
11 namespace Ccsds {
12 
13 // ----------------------------------------------------------------------
14 // Component construction and destruction
15 // ----------------------------------------------------------------------
16 
17 SdlsSaRouter ::SdlsSaRouter(const char* const compName) : SdlsSaRouterComponentBase(compName) {
18  // Load the compile-time SA-to-port map from configuration
19  const SdlsCfg::SaMap saMap;
20  for (SdlsCfg::SaMap::SizeType i = 0; i < SdlsCfg::SaMap::SIZE; i++) {
21  const Fw::Success status =
22  this->m_saMap.insert(saMap[i].get_securityAssociationIndex(), saMap[i].get_portIndex());
23  FW_ASSERT(status == Fw::Success::SUCCESS, static_cast<FwAssertArgType>(i));
24  }
25 }
26 
28 
29 // ----------------------------------------------------------------------
30 // Handler implementations for typed input ports
31 // ----------------------------------------------------------------------
32 
33 void SdlsSaRouter ::dataIn_handler(FwIndexType portNum,
34  U16 securityAssociationIndex,
35  Fw::Buffer& data,
36  const ComCfg::FrameContext& context) {
37  FwIndexType outputPort = 0;
38  const Fw::Success found = this->m_saMap.find(securityAssociationIndex, outputPort);
40  if (found == Fw::Success::SUCCESS) {
41  if ((outputPort >= 0) && (outputPort < this->getNum_saDataOut_OutputPorts()) &&
42  (this->isConnected_saDataOut_OutputPort(outputPort))) {
43  this->saDataOut_out(outputPort, securityAssociationIndex, data, context);
44  return;
45  }
47  }
48  // Routing failed: pass the error status forward with the untouched buffer, tracking it
49  // so the eventual ownership return routes back upstream via bufferReturnOut
50  const Fw::Success inserted =
51  this->m_outstanding.insert(data.getContext(), static_cast<FwIndexType>(ROUTER_ERROR_PORT));
52  if (inserted != Fw::Success::SUCCESS) {
53  // Tracking table full: drop the request and return the buffer upstream immediately
54  this->log_WARNING_HI_TrackingTableFull();
55  this->bufferReturnOut_out(0, data, context);
56  return;
57  }
58  this->dataOut_out(0, errorStatus, data, context);
59 }
60 
61 void SdlsSaRouter ::dataReturnIn_handler(FwIndexType portNum, Fw::Buffer& data, const ComCfg::FrameContext& context) {
62  FwIndexType outputPort = 0;
63  const Fw::Success found = this->m_outstanding.find(data.getContext(), outputPort);
64  if (found != Fw::Success::SUCCESS) {
65  // Untracked buffer (e.g. lost to a context-key collision): return it upstream
66  this->log_WARNING_HI_UntrackedBufferReturned();
67  this->bufferReturnOut_out(0, data, context);
68  return;
69  }
70  (void)this->m_outstanding.remove(data.getContext(), outputPort);
71  if (outputPort == ROUTER_ERROR_PORT) {
72  // Buffer was forwarded by the router itself on a routing error: return it upstream
73  this->bufferReturnOut_out(0, data, context);
74  } else {
75  this->saDataReturnOut_out(outputPort, data, context);
76  }
77 }
78 
79 void SdlsSaRouter ::saBufferReturnIn_handler(FwIndexType portNum,
80  Fw::Buffer& data,
81  const ComCfg::FrameContext& context) {
82  this->bufferReturnOut_out(0, data, context);
83 }
84 
85 void SdlsSaRouter ::saDataIn_handler(FwIndexType portNum,
86  const Svc::Ccsds::SdlsStatus& status,
87  Fw::Buffer& data,
88  const ComCfg::FrameContext& context) {
89  const Fw::Success inserted = this->m_outstanding.insert(data.getContext(), portNum);
90  if (inserted != Fw::Success::SUCCESS) {
91  // Tracking table full: drop the data and return ownership to the downstream component
92  this->log_WARNING_HI_TrackingTableFull();
93  this->saDataReturnOut_out(portNum, data, context);
94  return;
95  }
96  this->dataOut_out(0, status, data, context);
97 }
98 
99 } // namespace Ccsds
100 
101 } // namespace Svc
Security association index has no known mapping.
Representing success.
U32 getContext() const
Definition: Buffer.cpp:102
Status of an SDLS (Space Data Link Security) encryption/decryption request.
Success insert(const K &key, const V &value) override
Definition: ArrayMap.hpp:97
Mapped port index is out of range or unconnected.
Success remove(const K &key, V &value) override
Definition: ArrayMap.hpp:105
FwSizeType SizeType
~SdlsSaRouter()
Destroy SdlsSaRouter object.
SdlsSaRouter(const char *const compName)
Construct SdlsSaRouter object.
Success find(const K &key, V &value) const override
Definition: ArrayMap.hpp:81
PlatformIndexType FwIndexType
Type used to pass context info between components during framing/deframing.
RateGroupDivider component implementation.
The size of the array.
#define FW_ASSERT(...)
Definition: Assert.hpp:14
Success/Failure.