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

CFE_MSG_InitMsg does not always set secondary header bit #973

Closed
johnphamngc opened this issue Oct 27, 2020 · 6 comments · Fixed by #980 or #1008
Closed

CFE_MSG_InitMsg does not always set secondary header bit #973

johnphamngc opened this issue Oct 27, 2020 · 6 comments · Fixed by #980 or #1008
Labels
enhancement Priority: Mission Feature or bug related to stakeholder needs
Milestone

Comments

@johnphamngc
Copy link

Describe the bug

The behavior of CFE_MSG_InitMsg seems to be a regression from the old 6.7 CFE_SB_InitMsg, which always set the secondary header flag regardless of the Clear/InitMsg parameter. There's always a CCSDS secondary header, so this bit should always be set.

To Reproduce
Call CFE_MSG_InitMsg with the Clear parameter set to false

Expected behavior
Secondary header flag on message is set to 1

Code snips

if (Clear)
{
memset(MsgPtr, 0, Size);
CFE_MSG_InitDefaultHdr(MsgPtr);
}

CFE_MSG_InitDefaultHdr should always be called.

System observed on:

  • SP0
  • OS: VxWorks
  • Versions: cFE 6.8

Additional context
Discovered when SBNg did not properly set the command code due to missing secondary header flag. This was worked around by calling CFE_SB_InitMsg w/ the InitMsg parameter set to true.

Reporter Info
John N Pham, Northrop Grumman

@johnphamngc johnphamngc changed the title CFE_MSG_InitMsg does not set secondary header bit CFE_MSG_InitMsg does not always set secondary header bit Oct 27, 2020
@skliper
Copy link
Contributor

skliper commented Oct 27, 2020

What was your use case for initializing a message with clear=false? Was it just to avoid the overhead of clearing the payload section or was there something in the header you wanted to retain? The previous implementation for clear=false was somewhat inconsistent in the interpretation of what "clear" meant, in that the length and message ID bits were set, the sequence counter was retained, and everything else in the "header" was set to zero. This mixed behavior was difficult to abstract into an API that's implementation independent (and still does what apps expect).

In an effort to simplify the abstraction, the current implementation just sets the information that is passed in - length and msgid bits (which you can do with CFE_MSG_SetSize and CFE_MSG_SetMsgId). The expected use was the message was initialized at least once with clear=true (sets the entire message to known values), and the only the passed in values needed to change. Would it make more sense for clear=false to set the entire header (zero header, set defaults, then set length and msgid), and just not touch the payload? Alternatively if some things need to be retained and others not, it may be easier to just use the individual APIs.

EDIT - Or should clear=false not zero anything, and just set defaults/length/msgid? If not previously cleared this could lead to random values...

@johnphamngc
Copy link
Author

I did see this on the gateway version of SBN, and the bugfix was to simply set clear = true, I assume the original thought was just avoiding the overhead of clearing the payload section that would be filled in and updated elsewhere anyway, and was concerned the behavior change might break things elsewhere.

It's not clear from the comments that the intent was to initialize at least once w/ Clear=true, and that initializing a new packet w/ 'Clear=false` results in an invalid packet w/o the secondary header bit set. Intuitively to me it'd make sense to set the header and not touch the payload and use the individual APIs to set things if necessary, but I guess if it makes the abstraction messy could just leave things as is and update the header comments.

@skliper
Copy link
Contributor

skliper commented Oct 28, 2020

Oh, I see the old CFE_SB_InitMsg still has the old comments... that API will be removed as part of #777. I'll update CFE_MSG_Init (the new/preferred API) comments and implementation to clear/set the entire header and not touch the payload.

@skliper
Copy link
Contributor

skliper commented Oct 28, 2020

Digging into implementation, is it really worth supporting the clear flag going forward? To just clear the header there's additional logic to determine the message type, adds paths, etc. I haven't done a performance check to compare the two, but I wouldn't expect a significant benefit compared to just clearing the entire message. Seems sensible to just clear the entire message all the time (just make it what CFE_MSG_Init does).

@skliper skliper added the CCB:Ready Ready for discussion at the Configuration Control Board (CCB) label Oct 28, 2020
@skliper skliper added this to the 7.0.0 milestone Oct 28, 2020
@skliper skliper added the Priority: Mission Feature or bug related to stakeholder needs label Oct 28, 2020
@johnphamngc
Copy link
Author

Yeah, the overhead of memset is probably negligible. If CFE_SB_InitMsg will be deprecated, I don't think much will be lost if support for the clear flag is removed, since all the code has to be updated anyway.

@astrogeco astrogeco removed the CCB:Ready Ready for discussion at the Configuration Control Board (CCB) label Oct 28, 2020
@astrogeco
Copy link
Contributor

CCB 2020-10-28 APPROVED

  • Use in the real world is inconsistent and possibly unnecessary
  • Behavior is unclear
  • PROPOSAL: outright remove the clear flag

skliper added a commit to skliper/cFE that referenced this issue Oct 28, 2020
skliper added a commit to skliper/cFE that referenced this issue Nov 4, 2020
astrogeco added a commit that referenced this issue Nov 10, 2020
Fix #973, CFE_MSG_Init clear option removed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Priority: Mission Feature or bug related to stakeholder needs
Projects
None yet
3 participants