📄 voip_stress_test.c
字号:
while( pAdapterContextNode )
{
pAdapterContext = pAdapterContextNode->pAdapterContext;
if( (pAdapterContext->State == VOIP_ADAPTER_STATE_READY) && (pAdapterContext->StressTest.fActive == TBX_TRUE) )
{
pAdapterContext->StressTest.un32Elapsed += un32ElapsedMs;
/* Proceed with pending stress test cleanup */
if( pAdapterContext->StressTest.fCleanupPending == TBX_TRUE )
{
if( pAdapterContext->StressTest.un32Elapsed > VOIP_STRESS_TEST_CLEANUP_DELAY_MS )
{
pAdapterContext->StressTest.un32CleanupRetryCount++;
if( (pAdapterContext->un32NbResponsesExpected == 0) ||
(pAdapterContext->StressTest.un32CleanupRetryCount >= VOIP_STRESS_TEST_CLEANUP_RETRY_COUNT) )
{
TbxCliToolsLogPrint( pCliContext->hCliTools, TRACE_LEVEL_ALWAYS, FCYAN, "Stress Test cleanup done\n" );
/* Stress test cleanup done */
pAdapterContext->StressTest.fCleanupPending = TBX_FALSE;
}
else
{
TbxCliToolsLogPrint( pCliContext->hCliTools, TRACE_LEVEL_ALWAYS, FCYAN, "Stress test cleanup pending...\n" );
}
/* Reset elapsed time accumulator */
pAdapterContext->StressTest.un32Elapsed = 0;
}
}
/* Proceed with pending stress test start */
else if( pAdapterContext->StressTest.fStartPending == TBX_TRUE )
{
/* Start stress test */
VoipStressTestStart( pAdapterContext, NULL );
}
/* Proceed with pending stress test stop */
else if( pAdapterContext->StressTest.fStopPending == TBX_TRUE )
{
/* Stop stress test */
VoipStressTestStop(pAdapterContext);
}
/* Proceed with stress test running */
else
{
/* Check if the maximum duration has been reached */
if ((pAdapterContext->StressTest.un32Elapsed / 1000) >= pAdapterContext->StressTest.un32TestDurationInSec)
{
TbxCliToolsLogPrint( pCliContext->hCliTools, TRACE_LEVEL_ALWAYS, FCYAN, "Stress-test maximum duration reached...\n" );
/* Stop stress-testing */
if (g_pContext->TestModeContext.fTestMode)
{
VoipStopStressTest01ByItself (pAdapterContext->szAdapterName, TBX_RESULT_OK);
}
else
{
VoipStressTestStop( pAdapterContext );
}
}
/* Disconnect resources that timed out */
VoipStressTestDisconnectResourcesTimedOut( pAdapterContext );
/* Check if we reached the target number of connections per second */
un32NbConnectionsInLoop = VoipStressTestContinue( pAdapterContext );
if( un32NbConnectionsInLoop > VOIP_STRESS_TEST_MAX_CONNECTIONS_PER_LOOP)
un32NbConnectionsInLoop = VOIP_STRESS_TEST_MAX_CONNECTIONS_PER_LOOP;
/* Update BERT connection time */
if (pAdapterContext->StressTest.fBertConnectionActive)
{
pAdapterContext->StressTest.un32TimeSinceBertStart += un32ElapsedMs;
/* Toggle a stats reset */
if ((!pAdapterContext->StressTest.fBertStatsReset) &&
(pAdapterContext->StressTest.un32TimeSinceBertStart > VOIP_STRESS_TEST_BER_RESET_TMO_MSEC))
{
/* Reset BERT stats */
pAdapterContext->Stats.fBertResetStats = TBX_TRUE;
pAdapterContext->StressTest.fBertStatsReset = TBX_TRUE;
}
}
/*
* Connect resources to reach connections per second target
*/
for( un32Loops = 0; un32Loops < un32NbConnectionsInLoop; un32Loops++ )
{
PVOIP_EVT_OP_ALLOCATE_CONNECTION pEvt;
TBX_MSG_HANDLE hMsg;
PacketType = TBX_STREAM_PACKET_TYPE_UNKNOWN;
GroupType = TB640_VP_GROUP_TYPE_FIRST;
un32TrunkNb = (TBX_UINT32)-1;
un32TimeSlot = (TBX_UINT32)-1;
un16RxIPPort = (TBX_UINT16)-1;
un16TxIPPort = (TBX_UINT16)-1;
/* Should we do a BERT connection ? */
if (pAdapterContext->StressTest.fDoBertTests && !pAdapterContext->StressTest.fBertConnectionActive)
{
/* Overwrite the res type with BERT */
FirstResType = VOIP_RESOURCE_TYPE_BERT;
/* 4 sec BERT duration */
un32ConnectionDurationMs = VOIP_STRESS_TEST_BER_CONN_DUR_MSEC;
TbxCliToolsLogPrint
(
pCliContext->hCliTools, TRACE_LEVEL_0, NULL,
"Stress-test making connection, duration %dms.\n",
un32ConnectionDurationMs
);
/* Select BERT as second connection */
PacketType = TBX_STREAM_PACKET_TYPE_CLEAR_CHANNEL;
GroupType = TB640_VP_GROUP_TYPE_1;
/* Reset the time of start of BERT connection */
pAdapterContext->StressTest.un32TimeSinceBertStart = 0;
pAdapterContext->StressTest.fBertStatsReset = TBX_FALSE;
/* Update the stats */
pAdapterContext->StressTest.Stats.un64NbBertConnectionOpened++;
}
else
{
/* Cache the res type */
FirstResType = pAdapterContext->StressTest.FirstResType;
/* Choose random connection duration */
un32ConnectionDurationMs = 1000 * pAdapterContext->StressTest.un32NbMinConnectionDurationSecond;
if( pAdapterContext->StressTest.un32NbMaxConnectionDurationSecond != pAdapterContext->StressTest.un32NbMinConnectionDurationSecond )
{
un32ConnectionDurationMs +=
rand() %
(
(1000 * pAdapterContext->StressTest.un32NbMaxConnectionDurationSecond) -
(1000 * pAdapterContext->StressTest.un32NbMinConnectionDurationSecond)
);
}
TbxCliToolsLogPrint
(
pCliContext->hCliTools, TRACE_LEVEL_0, NULL,
"Stress-test making connection, duration %dms.\n",
un32ConnectionDurationMs
);
/* Get stream packet type */
Result = VoipStressTestGetPacketType( pAdapterContext, &PacketType, &GroupType );
if( TBX_RESULT_FAILURE( Result) == TBX_TRUE )
{
TbxCliToolsLogPrint( pCliContext->hCliTools, TRACE_LEVEL_1, NULL, "Failed to get packet type" );
TBX_EXIT_SUCCESS( TBX_RESULT_NOT_FOUND );
}
if( pAdapterContext->StressTest.FirstResType == VOIP_RESOURCE_TYPE_TRUNK )
{
/* Get free trunk resource */
Result = VoipStressTestGetFreeTrunkRes( pAdapterContext, &un32TrunkNb, &un32TimeSlot );
if( TBX_RESULT_FAILURE( Result) == TBX_TRUE )
{
TbxCliToolsLogPrint( pCliContext->hCliTools, TRACE_LEVEL_1, NULL, "Failed to get free trunk resource" );
TBX_EXIT_SUCCESS( TBX_RESULT_NOT_FOUND );
}
}
else if( pAdapterContext->StressTest.FirstResType == VOIP_RESOURCE_TYPE_MBL_PORT )
{
/* Get free trunk resource */
Result = VoipStressTestGetFreeMblPortRes( pAdapterContext, &un32MblPortNb, &un32MblStreamNb, &un32MblTimeSlot );
if( TBX_RESULT_FAILURE( Result) == TBX_TRUE )
{
TbxCliToolsLogPrint( pCliContext->hCliTools, TRACE_LEVEL_1, NULL, "Failed to get free MBL port resource" );
TBX_EXIT_SUCCESS( TBX_RESULT_NOT_FOUND );
}
}
else if( pAdapterContext->StressTest.FirstResType == VOIP_RESOURCE_TYPE_PROMPT )
{
/* Get prompt resource */
Result = VoipStressTestGetPromptRes( pAdapterContext, PacketType, &pszPromptName );
if( TBX_RESULT_FAILURE( Result) == TBX_TRUE )
{
TBX_EXIT_ERROR( TBX_RESULT_NOT_FOUND, 0, "Failed to get prompt resource resource" );
}
}
}
/* Get next IP ports values */
Result = VoipStressTestGetFreeIpPort( pAdapterContext, GroupType, &un16RxIPPort, &un16TxIPPort );
if( TBX_RESULT_FAILURE( Result) == TBX_TRUE )
{
TBX_EXIT_ERROR( TBX_RESULT_NOT_FOUND, 0, "Failed to get free stream Rx/Tx IP ports" );
}
/* Connect resources */
hMsg = VoipFormatPrivateMsg
(
VOIP_MSG_ID_OP_ALLOCATE_CONNECTION,
sizeof( VOIP_MSG_OP_ALLOCATE_CONNECTION ),
pAdapterContext->AdapterInfo.hAdapter,
0
);
/* Fill the request */
pEvt = (PVOIP_EVT_OP_ALLOCATE_CONNECTION)TBX_MSG_PAYLOAD_POINTER (hMsg);
pEvt->un32MsgVersion = 1;
pEvt->un32NbConnections = 1;
pEvt->un16IPPortIncrement = 0;
pEvt->Params.Type = VOIP_CONNECTION_TYPE_1;
if( FirstResType == VOIP_RESOURCE_TYPE_TRUNK )
{
pEvt->Params.Type1.FirstRes.Type = VOIP_RESOURCE_TYPE_TRUNK;
pEvt->Params.Type1.FirstRes.Class = TB640_RESOURCE_CLASS_TRUNK;
pEvt->Params.Type1.FirstRes.un32TrunkNb = un32TrunkNb;
pEvt->Params.Type1.FirstRes.un32TimeSlot = un32TimeSlot;
}
else if( FirstResType == VOIP_RESOURCE_TYPE_MBL_PORT )
{
pEvt->Params.Type1.FirstRes.Type = VOIP_RESOURCE_TYPE_MBL_PORT;
pEvt->Params.Type1.FirstRes.Class = TB640_RESOURCE_CLASS_MBL_PORT;
pEvt->Params.Type1.FirstRes.un32MblPortNb = un32MblPortNb;
pEvt->Params.Type1.FirstRes.un32MblStreamNb = un32MblStreamNb;
pEvt->Params.Type1.FirstRes.un32MblTimeSlot = un32MblTimeSlot;
}
else if( FirstResType == VOIP_RESOURCE_TYPE_PROMPT )
{
pEvt->Params.Type1.FirstRes.Type = VOIP_RESOURCE_TYPE_PROMPT;
pEvt->Params.Type1.FirstRes.Class = TB640_RESOURCE_CLASS_TDM_DSP;
strcpy( pEvt->Params.Type1.FirstRes.szPromptName, pszPromptName );
}
else if( FirstResType == VOIP_RESOURCE_TYPE_BERT )
{
pEvt->Params.Type1.FirstRes.Type = VOIP_RESOURCE_TYPE_BERT;
pEvt->Params.Type1.FirstRes.Class = TB640_RESOURCE_CLASS_BERT;
pAdapterContext->StressTest.fBertConnectionActive = TBX_TRUE;
}
pEvt->Params.Type1.SecondRes.Type = VOIP_RESOURCE_TYPE_STREAM_SOCKET;
pEvt->Params.Type1.SecondRes.Class = TB640_RESOURCE_CLASS_STREAM_SOCKET;
pEvt->Params.Type1.SecondRes.un16RxIPPort = un16RxIPPort;
pEvt->Params.Type1.SecondRes.un16TxIPPort = un16TxIPPort;
pEvt->Params.Type1.SecondRes.PacketType = PacketType;
pEvt->Params.Type1.SecondRes.GroupType = GroupType;
strncpy( pEvt->Params.Type1.SecondRes.szStreamSocketIP, pAdapterContext->StressTest.szStreamSocketIP, sizeof(pEvt->Params.Type1.SecondRes.szStreamSocketIP) );
pEvt->Params.Type1.SecondRes.szStreamSocketIP[sizeof(pEvt->Params.Type1.SecondRes.szStreamSocketIP) - 1] = '\0';
pEvt->Params.Type1.un32DurationMs = un32ConnectionDurationMs;
if( hMsg != (TBX_MSG_HANDLE)TBX_HANDLE_INVALID )
{
pAdapterContext->pFctStateHandler( pAdapterContext, hMsg );
TBXReleaseMsg (g_pContext->hTbxLib, hMsg);
}
}
}
}
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,
"VoipStressTestProcess: %s (Result 0x%08X, %s, line %d)\n",
TBX_ERROR_DESCRIPTION,
(int)TBX_ERROR_RESULT,
__FILE__,
TBX_ERROR_LINE);
}
/*---------------------------------------------------------------------------------------------------------------------------
| Cleanup section
*--------------------------------------------------------------------------------------------------------------------------*/
CLEANUP
{
if( TBX_RESULT_FAILURE( TBX_ERROR_RESULT ) != TBX_FALSE )
{
if( pAdapterContext )
{
/* Release reserved packet type */
if( (PacketType != TBX_STREAM_PACKET_TYPE_UNKNOWN) &&
(PacketType != TBX_STREAM_PACKET_TYPE_CLEAR_CHANNEL) &&
(GroupType != TB640_VP_GROUP_TYPE_FIRST) )
{
VoipStressTestReleasePacketType( pAdapterContext, PacketType, GroupType );
}
/* Release reserved trunk timeslot */
if( (un32TrunkNb != (TBX_UINT32)-1) && (un32TimeSlot != (TBX_UINT32)-1) )
{
VoipStressTestReleaseTrunkRes( pAdapterContext, un32TrunkNb, un32TimeSlot );
}
/* Release reserved IP port */
if( (un16RxIPPort != (TBX_UINT16)-1) && (un16TxIPPort != (TBX_UINT16)-1) )
{
VoipStressTestReleaseIpPort( pAdapterContext, un16RxIPPort, un16TxIPPort );
}
}
}
}
return;
}
/*-------------------------------------------------------------------------------------------------------------------------------
|
| VoipStressTestResetStats : Reset the stress test stats
|
| Note : ~
|
| Return : ~
|
*------------------------------------------------------------------------------------------------------------------------------*/
TBX_VOID VoipStressTestResetStats(
IN PVOIP_ADAPTER_CONTEXT in_pAdapterContext )
{
in_pAdapterContext->StressTest.Stats.un32StartTimestamp = g_pContext->un32TimerCurrentTime;
in_pAdapterContext->StressTest.Stats.un32CurrentTimestamp = g_pContext->un32TimerCurrentTime;
in_pAdapterContext->StressTest.Stats.un64NbConnectionsAttempt = 0;
in_pAdapterContext->StressTest.Stats.un64NbConnectionsCompleted = 0;
in_pAdapterContext->StressTest.Stats.un64NbConnectionsFailed = 0;
in_pAdapterContext->StressTest.Stats.un64NbConnectionsClosed = 0;
in_pAdapterContext->StressTest.un64LastNbConnections = 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -