📄 voip_stress_test.c
字号:
/*---------------------------------------------------------------------------------------------------------------------------
| Cleanup section
*--------------------------------------------------------------------------------------------------------------------------*/
CLEANUP
{
}
RETURN;
}
/*-------------------------------------------------------------------------------------------------------------------------------
|
| VoipStopStressTest : Handles the stop stress test message.
|
| in_pAdapterContext : Context of the adapter to stop stress test
|
| Note : ~
|
| Return : ~
|
*------------------------------------------------------------------------------------------------------------------------------*/
TBX_RESULT VoipStressTestStop(
IN PVOIP_ADAPTER_CONTEXT in_pAdapterContext )
{
TBX_RESULT Result;
PVOIP_CLI_CONTEXT pCliContext;
PVOIP_ADAPTER_CONTEXT pAdapterContext;
PVOIP_ADAPTER_CONTEXT_NODE pAdapterContextNode;
/*---------------------------------------------------------------------------------------------------------------------------
| Code section
*--------------------------------------------------------------------------------------------------------------------------*/
CODE
{
/* Initialize local variables */
pCliContext = &g_pContext->CliContext;
if( in_pAdapterContext->StressTest.fStopPending == TBX_FALSE )
{
if( in_pAdapterContext->StressTest.fCleanupPending == TBX_TRUE )
{
TBX_EXIT_ERROR(TBX_RESULT_ACCESS_DENIED, 0, "There is already a pending stress test cleanup. Try later..." );
}
/* Disable stress test */
in_pAdapterContext->StressTest.fStopPending = TBX_TRUE;
in_pAdapterContext->StressTest.Stats.fStatsActivated = TBX_FALSE;
in_pAdapterContext->StressTest.Stats.un32EndTimestamp = g_pContext->un32TimerCurrentTime;
/* Disconnect all resources created by this stress test */
Result = VoipStressTestCleanup( in_pAdapterContext );
if( TBX_RESULT_FAILURE( Result ) == TBX_TRUE )
{
TBX_EXIT_ERROR( Result, 0, "Failed to disconnect all resources" );
}
/* Print stress test stats */
{
TBX_CHAR aszTmpBuffer[ VOIP_CLI_STRESS_TEST_MAX_NB_LINES ][ TBX_CLI_TOOLS_CLI_SCREEN_WIDTH_MAX ];
TBX_UINT32 un32NbLines;
TBX_UINT32 un32Line;
/* Print stress test stats */
VoipCliPrintStressTestStats( aszTmpBuffer, &un32NbLines );
for( un32Line = 0; un32Line < un32NbLines; un32Line++ )
{
TbxCliToolsLogPrint
(
pCliContext->hCliTools,
TRACE_LEVEL_ALWAYS, FCYAN,
aszTmpBuffer[ un32Line ]
);
}
}
}
else
{
in_pAdapterContext->StressTest.fActive = TBX_FALSE;
in_pAdapterContext->StressTest.fStopPending = TBX_FALSE;
/* Check if there is a stress test running on, at least, one adapter */
g_pContext->fStressTestRunning = TBX_FALSE;
pAdapterContextNode = TBXPoolOfBuffersFirst( g_pContext->hPoolOfAdapters );
while( pAdapterContextNode )
{
pAdapterContext = pAdapterContextNode->pAdapterContext;
if( pAdapterContext->StressTest.fActive == TBX_TRUE )
{
g_pContext->fStressTestRunning = TBX_TRUE;
break;
}
pAdapterContextNode = TBXPoolOfBuffersNext( g_pContext->hPoolOfAdapters, pAdapterContextNode );
}
}
/* End of the code (skip to cleanup) */
TBX_EXIT_SUCCESS (TBX_RESULT_OK);
}
/*---------------------------------------------------------------------------------------------------------------------------
| Error handling section
*--------------------------------------------------------------------------------------------------------------------------*/
ERROR_HANDLING
{
TbxCliToolsLogPrint(
pCliContext->hCliTools,
TRACE_LEVEL_ERROR, NULL,
"VoipStressTestStop: %s (Result 0x%08X, %s, line %d)\n",
TBX_ERROR_DESCRIPTION,
(int)TBX_ERROR_RESULT,
__FILE__,
TBX_ERROR_LINE);
}
/*---------------------------------------------------------------------------------------------------------------------------
| Cleanup section
*--------------------------------------------------------------------------------------------------------------------------*/
CLEANUP
{
}
RETURN;
}
/*-------------------------------------------------------------------------------------------------------------------------------
|
| VoipStressTestContinue : Determines if the stress test must continue
| to try to make more connections
|
| Note : ~
|
| Return : The number of allowed connections in loop
|
*------------------------------------------------------------------------------------------------------------------------------*/
TBX_UINT32 VoipStressTestContinue(
IN PVOIP_ADAPTER_CONTEXT in_pAdapterContext )
{
TBX_UINT32 un32CurrentTime;
TBX_UINT32 un32ElapsedSinceBeginMs;
TBX_UINT64 un64NbConnectionsAttemptCps;
TBX_UINT64 un64NbConnectionsCompletedCps;
TBX_UINT32 un32ElapsedSinceLastTestMs;
TBX_UINT32 un32NbConnectionsAllowed = 0;
un32CurrentTime = g_pContext->un32TimerCurrentTime;
/* Compute stress-test stats */
un32ElapsedSinceBeginMs =
(
un32CurrentTime -
in_pAdapterContext->StressTest.Stats.un32StartTimestamp
) * TBX_MSEC_PER_TICKS;
un32ElapsedSinceLastTestMs =
(
un32CurrentTime -
in_pAdapterContext->StressTest.un32LastConnectionsPerSecondTimestamp
) * TBX_MSEC_PER_TICKS;
/* Avoid potential divisions by zero */
if( un32ElapsedSinceBeginMs == 0 )
un32ElapsedSinceBeginMs = 1;
un64NbConnectionsAttemptCps = (TBX_UINT32)
(
in_pAdapterContext->StressTest.Stats.un64NbConnectionsAttempt *
(TBX_UINT64)1000 /
(TBX_UINT64)un32ElapsedSinceBeginMs
);
un64NbConnectionsCompletedCps = (TBX_UINT32)
(
in_pAdapterContext->StressTest.Stats.un64NbConnectionsCompleted *
(TBX_UINT64)1000 /
(TBX_UINT64)un32ElapsedSinceBeginMs
);
/* Update the average number of connections per second */
if( un32ElapsedSinceLastTestMs >= VOIP_STRESS_TEST_CPS_CHECK_DELAY_MS )
{
TBX_UINT32 un32ConnectionsPerSecondLastPeriod;
/* Compute the corresponding number of connections per second */
un32ConnectionsPerSecondLastPeriod = (TBX_UINT32)
(
in_pAdapterContext->StressTest.Stats.un64NbConnectionsAttempt -
in_pAdapterContext->StressTest.un64LastNbConnections
);
un32ConnectionsPerSecondLastPeriod = un32ConnectionsPerSecondLastPeriod * 1000 / un32ElapsedSinceLastTestMs;
/* Compute exponential average */
in_pAdapterContext->StressTest.dNbConnectionsPerSecondAverage =
(double)
(
(in_pAdapterContext->StressTest.dNbConnectionsPerSecondAverage * (VOIP_STRESS_TEST_CONNECTIONS_PER_SEC_AVERAGE_TIME-1)) +
un32ConnectionsPerSecondLastPeriod
) / VOIP_STRESS_TEST_CONNECTIONS_PER_SEC_AVERAGE_TIME;
/* Estimate the number of connections allowed in current loop */
if( in_pAdapterContext->StressTest.dNbConnectionsPerSecondAverage < in_pAdapterContext->StressTest.un32NbConnectionsPerSecond )
{
/* Compute the number of connections per loop required to keep the connection rate */
TBX_UINT32 un32Fraction;
double dNbConnectionsPerLoop =
(double)in_pAdapterContext->StressTest.un32NbConnectionsPerSecond
* VOIP_STRESS_TEST_CPS_CHECK_DELAY_MS
/ 1000;
dNbConnectionsPerLoop *= 2;
un32NbConnectionsAllowed = (TBX_UINT32)dNbConnectionsPerLoop;
dNbConnectionsPerLoop -= un32NbConnectionsAllowed;
un32Fraction = (TBX_UINT32)(100 * dNbConnectionsPerLoop);
if( (TBX_UINT32)(rand() % 100) < un32Fraction )
{
un32NbConnectionsAllowed++;
}
}
/* Update variables for next loop */
in_pAdapterContext->StressTest.un64LastNbConnections = in_pAdapterContext->StressTest.Stats.un64NbConnectionsAttempt;
in_pAdapterContext->StressTest.un32LastConnectionsPerSecondTimestamp = g_pContext->un32TimerCurrentTime;
}
else
{
/* Use same value as previous loop */
un32NbConnectionsAllowed = in_pAdapterContext->StressTest.un32LastNbConnectionsPerLoop;
}
/* Adjust if we're globally late or "in forward" compared to target */
if( un64NbConnectionsAttemptCps > (in_pAdapterContext->StressTest.un32NbConnectionsPerSecond+10) )
{
un32NbConnectionsAllowed = 0;
}
else if( un64NbConnectionsAttemptCps > in_pAdapterContext->StressTest.un32NbConnectionsPerSecond )
{
if( un32NbConnectionsAllowed )
un32NbConnectionsAllowed--;
}
else if( (un64NbConnectionsAttemptCps+10) < in_pAdapterContext->StressTest.un32NbConnectionsPerSecond )
{
un32NbConnectionsAllowed+=5;
}
else if( un64NbConnectionsAttemptCps < in_pAdapterContext->StressTest.un32NbConnectionsPerSecond )
{
un32NbConnectionsAllowed += 2;
}
in_pAdapterContext->StressTest.un32LastNbConnectionsPerLoop = un32NbConnectionsAllowed;
return un32NbConnectionsAllowed;
}
/*-------------------------------------------------------------------------------------------------------------------------------
|
| VoipStressTestDisconnectResourcesTimedOut : Disconnect resources that timed out.
|
| Note : ~
|
| Return : ~
|
*------------------------------------------------------------------------------------------------------------------------------*/
TBX_VOID VoipStressTestDisconnectResourcesTimedOut(
IN PVOIP_ADAPTER_CONTEXT in_pAdapterContext )
{
PVOIP_CONNECTION_CONTEXT pConnectionContext;
TBX_UINT32 un32TimeoutTimestamp;
/* Scan connection */
pConnectionContext = TBXPoolOfBuffersFirst( in_pAdapterContext->CurrentConfig.hPoolOfConnections );
while( pConnectionContext )
{
if( (pConnectionContext->Params.Type == VOIP_CONNECTION_TYPE_1) && (pConnectionContext->fAllocated == TBX_TRUE) &&
(pConnectionContext->Params.Type1.un32DurationMs != (TBX_UINT32)-1) )
{
un32TimeoutTimestamp = (pConnectionContext->un32AllocatedTimestamp + pConnectionContext->Params.Type1.un32DurationMs);
if( g_pContext->un32LastLoopTimestamp > un32TimeoutTimestamp )
{
PVOIP_EVT_OP_CLEAR_CONNECTION pEvt;
TBX_MSG_HANDLE hMsg;
/* Disconnect resources */
hMsg = VoipFormatPrivateMsg
(
VOIP_MSG_ID_OP_CLEAR_CONNECTION,
sizeof( VOIP_MSG_OP_CLEAR_CONNECTION ),
in_pAdapterContext->AdapterInfo.hAdapter,
0
);
/* Fill the request */
pEvt = (PVOIP_EVT_OP_CLEAR_CONNECTION)TBX_MSG_PAYLOAD_POINTER (hMsg);
pEvt->un32MsgVersion = 1;
pEvt->fAll = TBX_FALSE;
pEvt->fIncludeInfiniteDurCall = TBX_FALSE;
pEvt->un32ConnectionId = pConnectionContext->un32ConnectionId;
if( hMsg != (TBX_MSG_HANDLE)TBX_HANDLE_INVALID )
{
in_pAdapterContext->pFctStateHandler( in_pAdapterContext, hMsg );
TBXReleaseMsg (g_pContext->hTbxLib, hMsg);
}
if (pConnectionContext->Params.Type1.FirstRes.Type == VOIP_RESOURCE_TYPE_BERT)
{
PTB640_BERT_STATES pBertResStates;
/* BERT connection is no more active */
in_pAdapterContext->StressTest.fBertConnectionActive = TBX_FALSE;
/* Update the stats */
in_pAdapterContext->StressTest.Stats.un64NbBertConnectionClosed++;
/* Check the Max BERT error found */
pBertResStates = &in_pAdapterContext->Status.aBertRes[ 0 ];
if ((pBertResStates->un32ErrCounts > in_pAdapterContext->StressTest.Stats.un64MaxBertErrorFound) ||
(!pBertResStates->fSync))
{
if (!pBertResStates->fSync)
{
in_pAdapterContext->StressTest.Stats.un64MaxBertErrorFound = (TBX_UINT64)-1;
}
else
{
in_pAdapterContext->StressTest.Stats.un64MaxBertErrorFound = pBertResStates->un32ErrCounts;
}
}
/* Log a stats */
if (pBertResStates->un32ErrCounts > VOIP_STRESS_TEST_MAX_BER_ERROR_ACCEPTED)
{
in_pAdapterContext->StressTest.Stats.un64NbBertConnectionInErr++;
}
/* Should we stop the tests */
if ((in_pAdapterContext->StressTest.fAutoAbort) &&
(pBertResStates->un32ErrCounts > VOIP_STRESS_TEST_MAX_BER_ERROR_ACCEPTED))
{
/* Stop stress-testing */
if (g_pContext->TestModeContext.fTestMode)
{
VoipStopStressTest01ByItself (in_pAdapterContext->szAdapterName, TBX_RESULT_FAIL);
}
else
{
VoipStressTestStop( in_pAdapterContext );
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -