Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update/framing deframing context #2150

Draft
wants to merge 4 commits into
base: devel
Choose a base branch
from

Conversation

LeStarch
Copy link
Collaborator

@LeStarch LeStarch commented Jul 22, 2023

Originating Project/Creator
Affected Component
Affected Architectures(s)
Related Issue(s)
Has Unit Tests (y/n)
Builds Without Errors (y/n)
Unit Tests Pass (y/n)
Documentation Included (y/n)

Change Description

This pull-request makes several changes to Framer and Deframer.

  1. Framer now accepts buffers w/ context. This allows for frame protocols that need to metadata to assist in framing. For example: an APID may be passed-in alongside the data.
  2. Framer file buffer type adjustments are handled through context rather than side-band data
  3. Deframer may now create context
  4. Deframer routing functionality has been moved to a new component as only projects using F´  protocol require this routing functionality.

Work:

  • Framer changes
  • File buffer refactor
  • Deframer changes
  • Protocol changes
  • FprimeRouter implementation
  • Topology update (Ref)
  • Topology update (RPI)
  • Existing UTs
  • Router UTs
  • Framer documentation update
  • Deframer documentation update
  • New router documentation
  • Update "new deployment" and tutorials

Rationale

Many projects need additional contextual metadata when framing, but wish to leverage existing Framer and Deframer code. This PR allows this. Many projects also handle routing and don't need routing code commingled with Deframer.

@LeStarch LeStarch marked this pull request as draft July 22, 2023 00:25
@LeStarch
Copy link
Collaborator Author

@LMPS97 @arizvi786 here are the changes you were interested in for Framer/Deframer. You can leverage this work immediately as:

  • Documentation is not required for you to leverage the implementation
  • UTs pass for the components that concern you
  • FprimeRouter is not needed in your project.

@LeStarch
Copy link
Collaborator Author

@pcrosemurgy this PR breaks out routing from Deframer. It is possible that you could use these updates as you were specifically disrupted by the combined deframing and routing.

// Specifically does nothing
}

void FprimeRouter ::deframedIn_handler(const NATIVE_INT_TYPE portNum, Fw::Buffer& packetBuffer, Fw::Buffer& context) {

Check notice

Code scanning / CodeQL

Use of basic integral type Note

portNum uses the basic integral type int rather than a typedef with size and signedness.
// Handler implementations for user-defined typed input ports
// ----------------------------------------------------------------------

void FprimeRouter ::cmdResponseIn_handler(const NATIVE_INT_TYPE portNum,

Check notice

Code scanning / CodeQL

Use of basic integral type Note

portNum uses the basic integral type int rather than a typedef with size and signedness.
// Construction, initialization, and destruction
// ----------------------------------------------------------------------

FprimeRouter ::FprimeRouter(const char* const compName) : FprimeRouterComponentBase(compName) {}

Check notice

Code scanning / CodeQL

Use of basic integral type Note

compName uses the basic integral type char rather than a typedef with size and signedness.
}

// Whether to deallocate the packet buffer
bool deallocate = true;

Check notice

Code scanning / CodeQL

Use of basic integral type Note

deallocate uses the basic integral type bool rather than a typedef with size and signedness.
this->handle_framing(buffer, Fw::Buffer());
}

void Framer ::bufferAndContextIn_handler(const NATIVE_INT_TYPE portNum, Fw::Buffer& data, Fw::Buffer& context) {

Check notice

Code scanning / CodeQL

Use of basic integral type Note

portNum uses the basic integral type int rather than a typedef with size and signedness.
Copy link

@github-advanced-security github-advanced-security bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CodeQL found more than 10 potential problems in the proposed changes. Check the Files changed tab for more details.

@pcrosemurgy
Copy link
Contributor

pcrosemurgy commented Jul 22, 2023

@pcrosemurgy this PR breaks out routing from Deframer. It is possible that you could use these updates as you were specifically disrupted by the combined deframing and routing.

@LeStarch Thank you! I'll take a closer look at this!

@LMPS97
Copy link
Collaborator

LMPS97 commented Jul 25, 2023

I am getting an error compiling FprimeProtocol.cpp. Please add #include <limits> to it.

@@ -39,11 +39,6 @@ class Framer : public FramerComponentBase, public FramingProtocolInterface {
Framer(const char* const compName /*!< The component name*/
);

//! Initialize object Framer
//!
void init(const NATIVE_INT_TYPE instance = 0 /*!< The instance number*/
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why was the init function deleted on framer? Also, why only on framer and not deframer?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

init functions are provided by the component base class and are, in older component implementations, improperly shadowed. Thus, we are removing them.

Why not deframer? Oversight. We will remove it there too before merging.

@LMPS97
Copy link
Collaborator

LMPS97 commented Aug 16, 2023

I ran into a slight issue with the Framer. Sometimes, I need to send a package out with an empty data buffer. This is because the information is carried out by the header which is created from the context buffer instead. Because of that, the empty buffer is deallocated to the buffer manager which throws an EVR that the buffer size is 0. A solution would be to add a check on the Framer before deallocating the buffer to see if it is a valid buffer in the first place.

@LMPS97
Copy link
Collaborator

LMPS97 commented Aug 16, 2023

I just ran into an other issue when unit testing my code. Apparently, if you try to create a Fw::Buffer from a non valid Fw::Buffer using the following constructor causes an assert:

Buffer::Buffer(const Buffer& src) : Serializable(),
    m_serialize_repr(src.m_bufferData, src.m_size),
    m_bufferData(src.m_bufferData),
    m_size(src.m_size),
    m_context(src.m_context)
{}

I encountered this issue when a function of mine returns a non-valid Fw::Buffer.

FW_ASSERT(m_interface != nullptr);
// Use of I32 size is explicit as ComPacketType will be specifically serialized as an I32
FpFrameHeader::TokenType real_data_size = size + ((packet_type != Fw::ComPacket::FW_PACKET_UNKNOWN) ? sizeof(I32) : 0);
FpFrameHeader::TokenType real_data_size = context.getSize() + data.getSize();
FpFrameHeader::TokenType total = real_data_size + FpFrameHeader::SIZE + HASH_DIGEST_LENGTH;
Fw::Buffer buffer = m_interface->allocate(total);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There should be a check here to see if the buffer is empty since the buffer manager can run out of buffers. I don't think the check should be an assert since it wouldn't be appropriate to assert flight software on a lack of buffer manager buffers. Therefore, I think it should do an early return with an error code. This error code could be use by the framer and an evr could be outputted.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed wholeheartedly. Although we should check for .isValid() in the latest F´  because when buffer manager has no buffers, an invalid buffer is returned.

@@ -128,7 +128,8 @@ DeframingProtocol::DeframingStatus FprimeDeframing::deframe(Types::CircularBuffe
buffer.setSize(size);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similar to the frame function, this check should be a assert but a early return with an error code.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed!

@LeStarch
Copy link
Collaborator Author

LeStarch commented Jan 8, 2024

is deallocated to the buffer manager which throws an EVR that the buffer size is 0. A solution would be to add a check on the Framer before deallocating the buffer to see if it is a valid buffer in the first place.

We should deallocate it when the buffer isValid() and not dealocate otherwise. While the "zero length" EVR is annoying, it would be worse to never return a buffer to buffer manager even when it is zero length. Make sure the "i don''t use this buffers" are invalid and I agree, we should guard the deallocation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants