⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 voip_stress_test.c

📁 telcobridges voip develop
💻 C
📖 第 1 页 / 共 5 页
字号:
/*--------------------------------------------------------------------------------------------------------------------------------
 |
 |	Project:    	VOIP sample
 |
 |	Filename:   	voip_stress_test.c
 |
 |	Copyright:  	TelcoBridges 2002-2004, All Rights Reserved
 |
 |	Description:	This file contains functions for stress testing operation.
 |
 |	Notes:      	Tabs = 4
 |
 *-------------------------------------------------------------------------------------------------------------------------------
 |
 |	Revision:   	$Revision: 1.34 $
 |
 *------------------------------------------------------------------------------------------------------------------------------*/

/*--------------------------------------------------------------------------------------------------------------------------------
 |  Includes
 *------------------------------------------------------------------------------------------------------------------------------*/

#include "voip_includes.h"


/*--------------------------------------------------------------------------------------------------------------------------------
 |  Versioning
 *------------------------------------------------------------------------------------------------------------------------------*/

#ifdef WIN32
	/*@unused@*/ static char g_szFileVersion [] = "$Revision: 1.34 $";
#endif



/*--------------------------------------------------------------------------------------------------------------------------------
 |  Global variables
 *------------------------------------------------------------------------------------------------------------------------------*/


/*--------------------------------------------------------------------------------------------------------------------------------
 |  Function Prototypes
 *------------------------------------------------------------------------------------------------------------------------------*/


/*--------------------------------------------------------------------------------------------------------------------------------
 |  Implementation
 *------------------------------------------------------------------------------------------------------------------------------*/

/*-------------------------------------------------------------------------------------------------------------------------------
 |
 |  VoipStressTestCleanup	:	Stress test cleanup function.
 |
 |	in_pAdapterContext		:	Context of the adapter to disconnect all resources.
 |
 |  Note					:	~
 |
 |  Return					:	~
 |
 *------------------------------------------------------------------------------------------------------------------------------*/
TBX_RESULT VoipStressTestCleanup(
	IN		PVOIP_ADAPTER_CONTEXT	in_pAdapterContext )
{
	PVOIP_CLI_CONTEXT				pCliContext;
	TBX_MSG_HANDLE					hMsg;
	PVOIP_EVT_OP_CLEAR_CONNECTION	pEvt;

	/*---------------------------------------------------------------------------------------------------------------------------
	 |  Code section
	 *--------------------------------------------------------------------------------------------------------------------------*/
	CODE
	{
		/* Initialize local variables */
		pCliContext = &g_pContext->CliContext;

		/* Disconnect all 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_TRUE;
		pEvt->fIncludeInfiniteDurCall	= TBX_FALSE;

		if( hMsg != (TBX_MSG_HANDLE)TBX_HANDLE_INVALID )
		{
			in_pAdapterContext->pFctStateHandler( in_pAdapterContext, hMsg );
			TBXReleaseMsg (g_pContext->hTbxLib, hMsg);
		}

		/* Connections cleanup pending */
		in_pAdapterContext->StressTest.fCleanupPending = TBX_TRUE;
		in_pAdapterContext->StressTest.un32CleanupRetryCount = 0;

		/* 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,
			"VoipStressTestCleanup: %s (Result 0x%08X, %s, line %d)\n",
			TBX_ERROR_DESCRIPTION,
			(int)TBX_ERROR_RESULT,
			__FILE__,
			TBX_ERROR_LINE);
	}

	/*---------------------------------------------------------------------------------------------------------------------------
	 |  Cleanup section
	 *--------------------------------------------------------------------------------------------------------------------------*/
	CLEANUP
	{
	}

	RETURN;
}

/*-------------------------------------------------------------------------------------------------------------------------------
 |
 |  VoipStressTestStart	:	Handles the start stress test message.
 |
 |	in_pAdapterContext	:	Context of the adapter to begin stress test.
 |	in_pEvt				:	Message to handle
 |
 |  Note				:	~
 |
 |  Return				:	~
 |
 *------------------------------------------------------------------------------------------------------------------------------*/
TBX_RESULT VoipStressTestStart(
	IN		PVOIP_ADAPTER_CONTEXT			in_pAdapterContext,
	IN		PVOIP_EVT_OP_START_STRESS_TEST	in_pEvt )
{
	TBX_RESULT				Result;
	PVOIP_CLI_CONTEXT		pCliContext;
	TBX_UINT32				un32Index;
	PVOIP_PROMPT_CONTEXT	pPromptContext;
	TBX_BOOL				fNeedGroup0;
	TBX_BOOL				fNeedGroup1;

	/*---------------------------------------------------------------------------------------------------------------------------
	 |  Code section
	 *--------------------------------------------------------------------------------------------------------------------------*/
	CODE
	{
		/* Initialize local variables */
		pCliContext	= &g_pContext->CliContext;
		fNeedGroup0	= TBX_FALSE;
		fNeedGroup1	= TBX_FALSE;

		if( in_pAdapterContext->StressTest.fStartPending == TBX_FALSE )
		{
			if( in_pAdapterContext->StressTest.un32PacketTypeCount == 0 )
			{
				TBX_EXIT_ERROR( TBX_RESULT_INVALID_OPERATION, 0, "Missing stress-test parameters in configuration file" );
			}

			for( un32Index = 0; un32Index < in_pAdapterContext->StressTest.un32PacketTypeCount; un32Index++ )
			{
				if( in_pAdapterContext->StressTest.aPacketTypeInfo[un32Index].GroupType == TB640_VP_GROUP_TYPE_0 )
				{
					fNeedGroup0 = TBX_TRUE;
				}
				else if( in_pAdapterContext->StressTest.aPacketTypeInfo[un32Index].GroupType == TB640_VP_GROUP_TYPE_1 )
				{
					fNeedGroup1 = TBX_TRUE;
				}
			}

			if( (fNeedGroup0 == TBX_TRUE) && (in_pAdapterContext->CurrentConfig.fVpGroup0Available == TBX_FALSE) )
			{
				TBX_EXIT_ERROR( TBX_RESULT_INVALID_OPERATION, 0, "Voice processing group 0 is not available!" );
			}

			if( (fNeedGroup1 == TBX_TRUE) && (in_pAdapterContext->CurrentConfig.fVpGroup1Available == TBX_FALSE) )
			{
				TBX_EXIT_ERROR( TBX_RESULT_INVALID_OPERATION, 0, "Voice processing group 1 is not available!" );
			}

			/* Enable stress test */
			in_pAdapterContext->StressTest.fActive = TBX_TRUE;

			/* Associate prompt to packet type */
			if( in_pEvt->FirstResType == VOIP_RESOURCE_TYPE_PROMPT )
			{
				pPromptContext = TBXPoolOfBuffersFirst( in_pAdapterContext->CurrentConfig.hPoolOfPrompts );
				if( pPromptContext == NULL )
				{
					TBX_EXIT_ERROR( TBX_RESULT_NOT_FOUND, 0, "Failed to get prompt context!" );
				}

				for( un32Index = 0; un32Index < in_pAdapterContext->StressTest.un32PacketTypeCount; un32Index++ )
				{
					strcpy( in_pAdapterContext->StressTest.aPacketTypeInfo[un32Index].szPromptName, pPromptContext->Params.szPromptName );

					pPromptContext = TBXPoolOfBuffersNext( in_pAdapterContext->CurrentConfig.hPoolOfPrompts, pPromptContext );
					if( pPromptContext == NULL )
					{
						pPromptContext = TBXPoolOfBuffersFirst( in_pAdapterContext->CurrentConfig.hPoolOfPrompts );
					}
				}
			}

			/* Save initial config parameters */
			strcpy( in_pAdapterContext->StressTest.szStreamSocketIP, in_pEvt->szStreamSocketIP );
			in_pAdapterContext->StressTest.FirstResType								= in_pEvt->FirstResType;
			in_pAdapterContext->StressTest.un32NbConnectionsPerSecond				= in_pEvt->un32ConnectionsPerSecond;
			in_pAdapterContext->StressTest.un32NbMinConnectionDurationSecond		= in_pEvt->un32MinConnectionDuration;
			in_pAdapterContext->StressTest.un32NbMaxConnectionDurationSecond		= in_pEvt->un32MaxConnectionDuration;
			in_pAdapterContext->StressTest.fAutoAbort								= in_pEvt->fAutoAbort;
			in_pAdapterContext->StressTest.fDoBertTests								= in_pEvt->fDoBertTests;
			in_pAdapterContext->StressTest.un32TestDurationInSec					= in_pEvt->un32TestDurationInSec;

			/* Initialize run-time variables */
			in_pAdapterContext->StressTest.dNbConnectionsPerSecondAverage			= 0;
			in_pAdapterContext->StressTest.un32LastConnectionsPerSecondTimestamp	= g_pContext->un32TimerCurrentTime;
			in_pAdapterContext->StressTest.un64LastNbConnections					= 0;
			in_pAdapterContext->StressTest.un32Elapsed								= 0;
			in_pAdapterContext->StressTest.fBertConnectionActive					= TBX_FALSE;

			/* Reset the map of reserved IP ports */
			for( un32Index = 0; un32Index < VOIP_STRESS_TEST_IP_PORT_COUNT; un32Index++)
			{
				in_pAdapterContext->StressTest.afIpPortReserved[un32Index] = TBX_FALSE;
			}

			/* Reset the packet type counters */
			for( un32Index = 0; un32Index < VOIP_MAX_STRESS_TEST_PACKET_TYPE; un32Index++)
			{
				in_pAdapterContext->StressTest.aPacketTypeInfo[un32Index].un32CurrentCount = 0;
			}

			/* Reset stress test stats */
			memset (&in_pAdapterContext->StressTest.Stats, 0, sizeof(in_pAdapterContext->StressTest.Stats));
			in_pAdapterContext->StressTest.Stats.un32StartTimestamp				= g_pContext->un32TimerCurrentTime;
			in_pAdapterContext->StressTest.Stats.un32CurrentTimestamp			= g_pContext->un32TimerCurrentTime;

			TbxCliToolsLogPrint( pCliContext->hCliTools, TRACE_LEVEL_ALWAYS, FCYAN, "Disconnect all resources before starting the stress test...\n" );

			/* Disconnect all resources before starting the stress test */
			if (in_pEvt->fClearOpenedConnectionUponStartup)
			{
				Result = VoipStressTestCleanup( in_pAdapterContext );
				if( TBX_RESULT_FAILURE( Result ) == TBX_TRUE )
				{
					TBX_EXIT_ERROR( Result, 0, "Failed to disconnect all resources" );
				}

				/* Stress test start pending */
				in_pAdapterContext->StressTest.fStartPending = TBX_TRUE;
			}
			else
			{
				in_pAdapterContext->StressTest.fStartPending = TBX_FALSE;
			}

			in_pAdapterContext->StressTest.fStopPending = TBX_FALSE;

			/* Stress test is running on, at least, one adapter */
			g_pContext->fStressTestRunning = TBX_TRUE;
		}
		else
		{
			/* Reset stress test stats */
			VoipStressTestResetStats( in_pAdapterContext );

			TbxCliToolsLogPrintLock( pCliContext->hCliTools );
			{
				TbxCliToolsLogPrintWithinLock
				( 
					pCliContext->hCliTools, TRACE_LEVEL_ALWAYS, FCYAN,
					"\n"
				);
				TbxCliToolsLogPrintWithinLock
				( 
					pCliContext->hCliTools, TRACE_LEVEL_ALWAYS, FCYAN,
					"******************************************************************************\n"
				);
				if (in_pAdapterContext->StressTest.un32TestDurationInSec == (TBX_UINT32)-1)
				{
					TbxCliToolsLogPrintWithinLock
					( 
						pCliContext->hCliTools, TRACE_LEVEL_ALWAYS, FCYAN,
						"* Stress test started: duration [infinite], %u cps, call duration %u-%u\n",
						(unsigned int)in_pAdapterContext->StressTest.un32NbConnectionsPerSecond,
						(unsigned int)in_pAdapterContext->StressTest.un32NbMinConnectionDurationSecond,
						(unsigned int)in_pAdapterContext->StressTest.un32NbMaxConnectionDurationSecond
					);
				}
				else
				{
					TbxCliToolsLogPrintWithinLock
					( 
						pCliContext->hCliTools, TRACE_LEVEL_ALWAYS, FCYAN,
						"* Stress test started: duration %u sec, %u cps, call duration %u-%u\n",
						(unsigned int)in_pAdapterContext->StressTest.un32TestDurationInSec,
						(unsigned int)in_pAdapterContext->StressTest.un32NbConnectionsPerSecond,
						(unsigned int)in_pAdapterContext->StressTest.un32NbMinConnectionDurationSecond,
						(unsigned int)in_pAdapterContext->StressTest.un32NbMaxConnectionDurationSecond
					);
				}
				TbxCliToolsLogPrintWithinLock
				( 
					pCliContext->hCliTools, TRACE_LEVEL_ALWAYS, FCYAN,
					"******************************************************************************\n"
				);
				TbxCliToolsLogPrintWithinLock
				( 
					pCliContext->hCliTools, TRACE_LEVEL_ALWAYS, FCYAN,
					"\n"
				);
			}
			TbxCliToolsLogPrintUnlock( pCliContext->hCliTools );

			/* Stress test start no more pending */
			in_pAdapterContext->StressTest.fStartPending = TBX_FALSE;
		}

		/* 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,
			"VoipStressTestStart: %s (Result 0x%08X, %s, line %d)\n",
			TBX_ERROR_DESCRIPTION,
			(int)TBX_ERROR_RESULT,
			__FILE__,
			TBX_ERROR_LINE);
	}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -