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

📄 voip_stress_test.c

📁 telcobridges voip develop
💻 C
📖 第 1 页 / 共 5 页
字号:
	 *--------------------------------------------------------------------------------------------------------------------------*/
	CLEANUP
	{
	}

	RETURN;
}

/*-------------------------------------------------------------------------------------------------------------------------------
 |
 |  VoipStressTestReleaseIpPort	:	Release Rx/Tx IP ports
 |
 |  Note						:	~
 |
 |  Return						:	~
 |
 *------------------------------------------------------------------------------------------------------------------------------*/
TBX_RESULT VoipStressTestReleaseIpPort(
	IN			PVOIP_ADAPTER_CONTEXT	in_pAdapterContext,
	IN			TBX_UINT16				in_pun16RxIPPort,
	IN			TBX_UINT16				in_pun16TxIPPort )
{
	PVOIP_CLI_CONTEXT	pCliContext;
	TBX_UINT32			un32Index;

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

		(TBX_VOID)in_pun16TxIPPort;

		un32Index = (in_pun16RxIPPort - VOIP_STRESS_TEST_FIRST_IP_PORT);
		in_pAdapterContext->StressTest.afIpPortReserved[un32Index]	= 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,
			"VoipStressTestReleaseIpPort: %s (Result 0x%08X, %s, line %d)\n",
			TBX_ERROR_DESCRIPTION,
			(int)TBX_ERROR_RESULT,
			__FILE__,
			TBX_ERROR_LINE);
	}

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

	RETURN;
}

/*-------------------------------------------------------------------------------------------------------------------------------
 |
 |  VoipStressTestGetPromptRes	:	Get prompt resource.
 |
 |  Note						:	~
 |
 |  Return						:	~
 |
 *------------------------------------------------------------------------------------------------------------------------------*/
TBX_RESULT VoipStressTestGetPromptRes(
	IN			PVOIP_ADAPTER_CONTEXT	in_pAdapterContext,
	IN			TBX_STREAM_PACKET_TYPE	in_PacketType,
	IN OUT		PTBX_CHAR*				io_pszPromptName )
{
	PVOIP_CLI_CONTEXT	pCliContext;
	TBX_UINT32			un32Index;

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

		for( un32Index = 0; un32Index < in_pAdapterContext->StressTest.un32PacketTypeCount; un32Index++ )
		{
			if( in_pAdapterContext->StressTest.aPacketTypeInfo[un32Index].PacketType == in_PacketType)
			{
				break;
			}
		}

		if(un32Index == in_pAdapterContext->StressTest.un32PacketTypeCount )
		{
			TBX_EXIT_ERROR( TBX_RESULT_NOT_FOUND, 0, "Failed to found packet type!" );
		}

		/* Return name of the selected prompt */
		*io_pszPromptName = in_pAdapterContext->StressTest.aPacketTypeInfo[un32Index].szPromptName;

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

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

	RETURN;
}

/*-------------------------------------------------------------------------------------------------------------------------------
 |
 |  VoipStressTestGetPacketType	:	Get packet type.
 |
 |  Note							:	~
 |
 |  Return							:	~
 |
 *------------------------------------------------------------------------------------------------------------------------------*/
TBX_RESULT VoipStressTestGetPacketType(
	IN		PVOIP_ADAPTER_CONTEXT		in_pAdapterContext,
	IN OUT	PTBX_STREAM_PACKET_TYPE		io_pPacketType,
	IN OUT	PTB640_VP_GROUP_TYPE		io_pGroupType )
{
	PVOIP_CLI_CONTEXT	pCliContext;
	TBX_UINT32			un32Index;
	TBX_UINT32			un32PacketTypeIndex;

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

		/* Randomly select packet type, check maximum packet type limit */
		un32PacketTypeIndex = (rand() % in_pAdapterContext->StressTest.un32PacketTypeCount);
		for( un32Index = 0; un32Index < in_pAdapterContext->StressTest.un32PacketTypeCount; un32Index++ )
		{
			if( in_pAdapterContext->StressTest.aPacketTypeInfo[un32PacketTypeIndex].un32CurrentCount <
				in_pAdapterContext->StressTest.aPacketTypeInfo[un32PacketTypeIndex].un32MaxCount )
			{
				break;
			}

			un32PacketTypeIndex++;
			un32PacketTypeIndex %= in_pAdapterContext->StressTest.un32PacketTypeCount;
		}

		if( un32Index >= in_pAdapterContext->StressTest.un32PacketTypeCount )
		{
			TbxCliToolsLogPrint( pCliContext->hCliTools, TRACE_LEVEL_1, NULL, "Reached packet type count limits" );

			TBX_EXIT_SUCCESS( TBX_RESULT_NOT_FOUND );
		}

		/* Update current packet type counter */
		in_pAdapterContext->StressTest.aPacketTypeInfo[un32PacketTypeIndex].un32CurrentCount++;

		/* Return packet type and group type */
		*io_pPacketType	= in_pAdapterContext->StressTest.aPacketTypeInfo[un32PacketTypeIndex].PacketType;
		*io_pGroupType	= in_pAdapterContext->StressTest.aPacketTypeInfo[un32PacketTypeIndex].GroupType;

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

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

	RETURN;
}

/*-------------------------------------------------------------------------------------------------------------------------------
 |
 |  VoipStressTestReleasePacketType	:	Release packet type.
 |
 |  Note							:	~
 |
 |  Return							:	~
 |
 *------------------------------------------------------------------------------------------------------------------------------*/
TBX_RESULT VoipStressTestReleasePacketType(
	IN		PVOIP_ADAPTER_CONTEXT	in_pAdapterContext,
	IN		TBX_STREAM_PACKET_TYPE	in_PacketType,
	IN		TB640_VP_GROUP_TYPE		in_GroupType )
{
	PVOIP_CLI_CONTEXT	pCliContext;
	TBX_UINT32			un32Index;

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

		/* Randomly select packet type, check maximum packet type limit */
		for( un32Index = 0; un32Index < in_pAdapterContext->StressTest.un32PacketTypeCount; un32Index++ )
		{
			if( (in_pAdapterContext->StressTest.aPacketTypeInfo[un32Index].PacketType == in_PacketType) &&
				(in_pAdapterContext->StressTest.aPacketTypeInfo[un32Index].GroupType == in_GroupType) )
			{
				break;
			}
		}

		if( un32Index >= in_pAdapterContext->StressTest.un32PacketTypeCount )
		{
			TBX_EXIT_ERROR( TBX_RESULT_NOT_FOUND, 0, "Failed to release packet type!" );
		}

		if( in_pAdapterContext->StressTest.aPacketTypeInfo[un32Index].un32CurrentCount > 0 )
		{
			/* Update current packet type counter */
			in_pAdapterContext->StressTest.aPacketTypeInfo[un32Index].un32CurrentCount--;
		}

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

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

	RETURN;
}

/*-------------------------------------------------------------------------------------------------------------------------------
 |
 |  VoipStressTestProcess	:	Process the stress test
 |
 |  Note					:	~
 |
 |  Return					:	~
 |
 *------------------------------------------------------------------------------------------------------------------------------*/
TBX_VOID VoipStressTestProcess()
{
	TBX_RESULT					Result;
	PVOIP_CLI_CONTEXT			pCliContext = &g_pContext->CliContext;
	PVOIP_ADAPTER_CONTEXT		pAdapterContext;
	PVOIP_ADAPTER_CONTEXT_NODE	pAdapterContextNode;
	TBX_UINT32					un32Loops;
	PVOIP_CONNECTION_CONTEXT	pConnectionContext;
	TBX_UINT32					un32ConnectionDurationMs;
	TBX_UINT32					un32NbConnectionsInLoop;
	PTBX_CHAR					pszPromptName;
	TBX_STREAM_PACKET_TYPE		PacketType;
	TB640_VP_GROUP_TYPE			GroupType;
	VOIP_RESOURCE_TYPE			FirstResType;
	TBX_UINT32					un32TrunkNb;
	TBX_UINT32					un32TimeSlot;
	TBX_UINT32					un32MblPortNb;
	TBX_UINT32					un32MblStreamNb;
	TBX_UINT32					un32MblTimeSlot;
	TBX_UINT16					un16RxIPPort;
	TBX_UINT16					un16TxIPPort;
	TBX_UINT32					un32ElapsedMs;

	/*---------------------------------------------------------------------------------------------------------------------------
	 |  Code section
	 *--------------------------------------------------------------------------------------------------------------------------*/
	CODE
	{
		/* Initialize local variables */
		Result				= TBX_RESULT_OK;
		pCliContext			= &g_pContext->CliContext;
		pConnectionContext	= NULL;
		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;
		pszPromptName		= NULL;

		un32ElapsedMs = (g_pContext->un32TimerCurrentTime - g_pContext->un32LastLoopTimestamp) * TBX_MSEC_PER_TICKS;
		g_pContext->un32LastLoopTimestamp = g_pContext->un32TimerCurrentTime;

		pAdapterContextNode = TBXPoolOfBuffersFirst( g_pContext->hPoolOfAdapters );

⌨️ 快捷键说明

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