Skip to content

Commit

Permalink
Fix nasa#101, Always increment sequence counter
Browse files Browse the repository at this point in the history
Maintains a sequential counter on SB messages
even when there is no subscribers.

Behavior changes:
Routes will never be deleted and pipes will never
receive an "unsubscribe" notification
  • Loading branch information
CDKnightNASA authored and skliper committed Jan 14, 2020
1 parent c3f799a commit 4e32599
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 125 deletions.
25 changes: 0 additions & 25 deletions fsw/cfe-core/src/sb/cfe_sb_api.c
Original file line number Diff line number Diff line change
Expand Up @@ -1081,31 +1081,6 @@ int32 CFE_SB_UnsubscribeFull(CFE_SB_MsgId_t MsgId,CFE_SB_PipeId_t PipeId,

}while((MatchFound == false)&&(DestPtr != NULL));

/* if 'Destinations' was decremented to zero above... */
if(RoutePtr->Destinations==0){
CFE_SB.StatTlmMsg.Payload.MsgIdsInUse--;
CFE_SB_RouteIdxPush_Unsync(RouteIdx); /* Return the idx to the available list (stack) for reuse */
CFE_SB_SetRoutingTblIdx(MsgKey,CFE_SB_INVALID_ROUTE_IDX);

/* Send unsubscribe report only if there are zero requests for this pkt */
if((CFE_SB.SubscriptionReporting == CFE_SB_ENABLE)&&
(Scope == CFE_SB_GLOBAL))
{
CFE_SB.SubRprtMsg.Payload.MsgId = MsgId;
CFE_SB.SubRprtMsg.Payload.Pipe = PipeId;
CFE_SB.SubRprtMsg.Payload.Qos.Priority = 0;
CFE_SB.SubRprtMsg.Payload.Qos.Reliability = 0;
CFE_SB.SubRprtMsg.Payload.SubType = CFE_SB_UNSUBSCRIPTION;
CFE_SB_UnlockSharedData(__func__,__LINE__);
Stat = CFE_SB_SendMsg((CFE_SB_Msg_t *)&CFE_SB.SubRprtMsg);
CFE_EVS_SendEventWithAppID(CFE_SB_UNSUBSCRIPTION_RPT_EID,CFE_EVS_EventType_DEBUG,CFE_SB.AppId,
"Sending Unsubscription Report Msg=0x%x,Pipe=%d,Stat=0x%x",
(unsigned int)MsgId,(int)PipeId,(unsigned int)Stat);
CFE_SB_LockSharedData(__func__,__LINE__);
}/* end if */

}/* end if */

CFE_SB_UnlockSharedData(__func__,__LINE__);

CFE_EVS_SendEventWithAppID(CFE_SB_SUBSCRIPTION_REMOVED_EID,CFE_EVS_EventType_DEBUG,CFE_SB.AppId,
Expand Down
104 changes: 4 additions & 100 deletions fsw/cfe-core/unit-test/sb_UT.c
Original file line number Diff line number Diff line change
Expand Up @@ -4485,6 +4485,8 @@ void Test_Subscribe_MaxMsgIdCount(void)
UT_Text("Begin Test for Maximum Message ID Count");
#endif

SB_ResetUnitTest();

CFE_SB_CreatePipe(&PipeId0, PipeDepth, "TestPipe0");
CFE_SB_CreatePipe(&PipeId1, PipeDepth, "TestPipe1");
CFE_SB_CreatePipe(&PipeId2, PipeDepth, "TestPipe2");
Expand Down Expand Up @@ -4739,6 +4741,7 @@ void Test_Subscribe_SubscriptionReporting(void)
#endif

SB_ResetUnitTest();

ActRtn = CFE_SB_CreatePipe(&PipeId, PipeDepth, "TestPipe");
ExpRtn = CFE_SUCCESS;

Expand Down Expand Up @@ -4816,7 +4819,7 @@ void Test_Subscribe_SubscriptionReporting(void)
}
else
{
ExpRtn = 8;
ExpRtn = 6;
ActRtn = UT_GetNumEventsSent();

if (ActRtn != ExpRtn)
Expand Down Expand Up @@ -4923,7 +4926,6 @@ void Test_Unsubscribe_API(void)
Test_Unsubscribe_Local();
Test_Unsubscribe_InvalParam();
Test_Unsubscribe_NoMatch();
Test_Unsubscribe_SubscriptionReporting();
Test_Unsubscribe_InvalidPipe();
Test_Unsubscribe_InvalidPipeOwner();
Test_Unsubscribe_FirstDestWithMany();
Expand Down Expand Up @@ -5235,104 +5237,6 @@ void Test_Unsubscribe_NoMatch(void)
TestStat, "Test_Unsubscribe_API", "No match test");
} /* end Test_Unsubscribe_NoMatch */

/*
** Test message unsubscription response to enabling/disabling subscription
** reporting
*/
void Test_Unsubscribe_SubscriptionReporting(void)
{
CFE_SB_PipeId_t TestPipe;
CFE_SB_MsgId_t MsgId = SB_UT_TLM_MID;
uint32 CallerId = 0xFFFFFFFF;
uint16 PipeDepth = 50;
int32 ExpRtn;
int32 ActRtn;
int32 TestStat = CFE_PASS;

#ifdef UT_VERBOSE
UT_Text("Begin Test Unsubscribe Subscription Reporting");
#endif

SB_ResetUnitTest();
CFE_SB_CreatePipe(&TestPipe, PipeDepth, "TestPipe");
CFE_SB_Subscribe(MsgId, TestPipe);
CFE_SB_SetSubscriptionReporting(CFE_SB_ENABLE);
CFE_SB_Unsubscribe(MsgId, TestPipe);
ExpRtn = CFE_SB_UNSUBSCRIPTION;
ActRtn = CFE_SB.SubRprtMsg.Payload.SubType;

if (ActRtn != ExpRtn)
{
snprintf(cMsg, UT_MAX_MESSAGE_LENGTH,
"Unsubscribe not enabled as expected in CFE_SB_Unsubscribe, "
"exp=%ld, act=%ld",
(long) ExpRtn, (long) ActRtn);
UT_Text(cMsg);
TestStat = CFE_FAIL;
}
else
{
CFE_SB_Subscribe(MsgId, TestPipe);

/* Get the caller's Application ID */
ExpRtn = CFE_SUCCESS;
ActRtn = CFE_ES_GetAppID(&CallerId);

if (ActRtn != ExpRtn)
{
snprintf(cMsg, UT_MAX_MESSAGE_LENGTH,
"Unexpected return from GetAppID in unsubscribe test, "
"exp=0x%lx, act=0x%lx",
(unsigned long) ExpRtn, (unsigned long) ActRtn);
UT_Text(cMsg);
TestStat = CFE_FAIL;
}
else
{
/* Subscribe to message: LOCAL */
ExpRtn = CFE_SUCCESS;
ActRtn = CFE_SB_UnsubscribeFull(MsgId, TestPipe, CFE_SB_LOCAL,
CallerId);

if (ActRtn != ExpRtn)
{
snprintf(cMsg, UT_MAX_MESSAGE_LENGTH,
"Unexpected return from UnsubscribeFull in "
"subscription reporting test, exp=0x%lx, act=0x%lx",
(unsigned long) ExpRtn, (unsigned long) ActRtn);
UT_Text(cMsg);
TestStat = CFE_FAIL;
}
else
{
ExpRtn = 9;
ActRtn = UT_GetNumEventsSent();

if (ActRtn != ExpRtn)
{
snprintf(cMsg, UT_MAX_MESSAGE_LENGTH,
"Unexpected rtn from UT_GetNumEventsSent, "
"exp=%lx, act=%lx",
(unsigned long) ExpRtn, (unsigned long) ActRtn);
UT_Text(cMsg);
TestStat = CFE_FAIL;
}
else if (UT_EventIsInHistory(CFE_SB_UNSUBSCRIPTION_RPT_EID) == false)
{
UT_Text("CFE_SB_UNSUBSCRIPTION_RPT_EID not sent");
TestStat = CFE_FAIL;
}
}
}
}

CFE_SB_SetSubscriptionReporting(CFE_SB_DISABLE);
CFE_SB_DeletePipe(TestPipe);
UT_Report(__FILE__, __LINE__,
TestStat, "Test_Unsubscribe_API",
"Subscription reporting test");
} /* end Test_Unsubscribe_SubscriptionReporting */

/*
** Test message unsubscription response to an invalid pipe ID
*/
Expand Down

0 comments on commit 4e32599

Please sign in to comment.