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  this->configure(saMap);
21 }
22 
24 
26  this->m_saMap.clear();
27  for (SdlsCfg::SaMap::SizeType i = 0; i < SdlsCfg::SaMap::SIZE; i++) {
28  const Fw::Success status =
29  this->m_saMap.insert(saMap[i].get_securityAssociationIndex(), saMap[i].get_portIndex());
30  FW_ASSERT(status == Fw::Success::SUCCESS, static_cast<FwAssertArgType>(i));
31  }
32 }
33 
34 // ----------------------------------------------------------------------
35 // Handler implementations for typed input ports
36 // ----------------------------------------------------------------------
37 
38 void SdlsSaRouter ::dataIn_handler(FwIndexType portNum,
39  U16 securityAssociationIndex,
40  Fw::Buffer& data,
41  const ComCfg::FrameContext& context) {
42  FwIndexType outputPort = 0;
43  const Fw::Success found = this->m_saMap.find(securityAssociationIndex, outputPort);
45  if (found == Fw::Success::SUCCESS) {
46  if ((outputPort >= 0) && (outputPort < this->getNum_saDataOut_OutputPorts()) &&
47  (this->isConnected_saDataOut_OutputPort(outputPort))) {
48  this->saDataOut_out(outputPort, securityAssociationIndex, data, context);
49  return;
50  }
52  }
53  // Routing failed: pass the error status forward with the untouched buffer, tracking it
54  // so the eventual ownership return routes back upstream via bufferReturnOut
55  this->m_outstandingLock.lock();
56  const Fw::Success inserted =
57  this->m_outstanding.insert(data.getContext(), static_cast<FwIndexType>(ROUTER_ERROR_PORT));
58  this->m_outstandingLock.unlock();
59  if (inserted != Fw::Success::SUCCESS) {
60  // Tracking table full: drop the request and return the buffer upstream immediately
61  this->log_WARNING_HI_TrackingTableFull();
62  this->bufferReturnOut_out(0, data, context);
63  return;
64  }
65  this->dataOut_out(0, errorStatus, data, context);
66 }
67 
68 void SdlsSaRouter ::dataReturnIn_handler(FwIndexType portNum, Fw::Buffer& data, const ComCfg::FrameContext& context) {
69  FwIndexType outputPort = 0;
70  this->m_outstandingLock.lock();
71  const Fw::Success found = this->m_outstanding.find(data.getContext(), outputPort);
72  if (found == Fw::Success::SUCCESS) {
73  (void)this->m_outstanding.remove(data.getContext(), outputPort);
74  }
75  this->m_outstandingLock.unlock();
76 
77  if (found != Fw::Success::SUCCESS) {
78  // Untracked buffer (e.g. lost to a context-key collision): return it upstream
79  this->log_WARNING_HI_UntrackedBufferReturned();
80  this->bufferReturnOut_out(0, data, context);
81  } else if (outputPort == ROUTER_ERROR_PORT) {
82  // Buffer was forwarded by the router itself on a routing error: return it upstream
83  this->bufferReturnOut_out(0, data, context);
84  } else {
85  this->saDataReturnOut_out(outputPort, data, context);
86  }
87 }
88 
89 void SdlsSaRouter ::saBufferReturnIn_handler(FwIndexType portNum,
90  Fw::Buffer& data,
91  const ComCfg::FrameContext& context) {
92  this->bufferReturnOut_out(0, data, context);
93 }
94 
95 void SdlsSaRouter ::saDataIn_handler(FwIndexType portNum,
96  const Svc::Ccsds::SdlsStatus& status,
97  Fw::Buffer& data,
98  const ComCfg::FrameContext& context) {
99  this->m_outstandingLock.lock();
100  const Fw::Success inserted = this->m_outstanding.insert(data.getContext(), portNum);
101  this->m_outstandingLock.unlock();
102  if (inserted != Fw::Success::SUCCESS) {
103  // Tracking table full: drop the data and return ownership to the downstream component
104  this->log_WARNING_HI_TrackingTableFull();
105  this->saDataReturnOut_out(portNum, data, context);
106  return;
107  }
108  this->dataOut_out(0, status, data, context);
109 }
110 
111 } // namespace Ccsds
112 
113 } // 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.
void configure(const SdlsCfg::SaMap &saMap)
Success remove(const K &key, V &value) override
Definition: ArrayMap.hpp:105
void clear() override
Clear the map.
Definition: ArrayMap.hpp:73
FwSizeType SizeType
~SdlsSaRouter()
Destroy SdlsSaRouter object.
SdlsSaRouter(const char *const compName)
Construct SdlsSaRouter object.
void lock()
lock the mutex and assert success
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.
void unlock()
alias for unLock to meet BasicLockable requirements
RateGroupDivider component implementation.
The size of the array.
#define FW_ASSERT(...)
Definition: Assert.hpp:14
Success/Failure.