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

📄 cli.c

📁 telcobridges cas develop
💻 C
📖 第 1 页 / 共 5 页
字号:
			if (++un32Timeslot >= TB640_CAS_MAX_TIMESLOT_IN_TRUNK)
			{
				/* Increment to the next trunk */
				un32Timeslot = 0;
				if (++un32Trunk >= TB640_CAS_MAX_SUPPORTED_TRUNKS_PER_ADAPTER)
				{
					/* Increment to the next adapter */
					un32Trunk = 0;
					if (++un32Adapter >= g_AppContext->un32NbAdapter)
					{
						/* Wrap around to the first adapter */
						un32Adapter = 0;
					}
				}
			}

		} while ((fFound == TBX_FALSE) &&
				 !((un32StartingAdapter == un32Adapter) && (un32StartingTrunk == un32Trunk) && (un32StartingTimeslot == un32Timeslot)));

		/* Was there a free resource to use ? */
		if (!fFound)
		{
			TBX_EXIT_ERROR(TBX_RESULT_FAIL, 0, "No more free resource");
		}

		/* End of the code (skip to cleanup) */
		TBX_EXIT_SUCCESS (TBX_RESULT_OK);
	}

	/*---------------------------------------------------------------------------------------------------------------------------
	 |  Error handling section
	 *--------------------------------------------------------------------------------------------------------------------------*/
	ERROR_HANDLING
	{
	}

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

	}

	RETURN;
}


/*-------------------------------------------------------------------------------------------------------------------------------
 |
 |  TB640CasParseTrunkSelection:	This function parses the trunk selection line
 |
 |  in_pAdapterInfo:	Pointer to adapter information
 |  in_pszArguments:	Poitner to trunk argument string
 |	out_pfDone	   :	Pointer to a variable that will contain the success or not of the parsing
 |
 |  Note			:	Trunk selection is reset when calling this function
 |
 |  Return          :	TBX_RESULT_OK
 |						TBX_RESULT_FAIL
 |
 *------------------------------------------------------------------------------------------------------------------------------*/
TBX_RESULT
TB640CasParseTrunkSelection (
  IN		PTB640_CAS_ADAPTER_INFO			in_pAdapterInfo,
  IN		PTBX_CHAR						in_pszArguments,
  OUT		PTBX_BOOL						out_pfDone)
{
	TBX_BOOL					fContinue;
	TBX_UINT32					un32Trunk;
	TBX_UINT32					un32Adapter;
	PTBX_CHAR					pToken;
	PTB640_CAS_TRUNK_INFO		pTrunkInfo;
	PTB640_CAS_ADAPTER_INFO		pAdapterInfo;	

	/*---------------------------------------------------------------------------------------------------------------------------
	 |  Code section
	 *--------------------------------------------------------------------------------------------------------------------------*/
	CODE
	{
		/* Initialize variables */
		*out_pfDone = TBX_FALSE;

		/* Reset all adapters not to be included in stress testing */
		for (un32Adapter=0; un32Adapter<g_AppContext->un32NbAdapter; un32Adapter++)
		{
			pAdapterInfo = &(g_AppContext->ahAdapterInfo [un32Adapter]);

			/* Reset all trunks of the adapter not to be included in stress testing */
			for (un32Trunk = 0; un32Trunk<TB640_CAS_MAX_SUPPORTED_TRUNKS_PER_ADAPTER; un32Trunk++)
			{
				pTrunkInfo = &(pAdapterInfo->aTrunkInfo [un32Trunk]);

				pTrunkInfo->fIncludedInStressTesting = TBX_FALSE;
			}
		}

		/* Parse the string */
		pToken = strtok (in_pszArguments, ",");
		fContinue = TBX_TRUE;
		while ((pToken != NULL) && fContinue)
		{
			TBX_UINT32		un32TrunkTop = 0;
			PTBX_CHAR		pSubToken;

			/* Check which trunk has been selected */
			un32Trunk = atoi (pToken);

			/* Parse the next token */
			pSubToken = strchr (pToken, '-');
			if( pSubToken++ )
				un32TrunkTop = atoi (pSubToken);

			do
			{
				/* Validate the trunk number */
				if (un32Trunk >= TB640_CAS_MAX_SUPPORTED_TRUNKS_PER_ADAPTER)
				{
					TB640_CAS_DISPLAY_PRINT ("Invalid selected trunk (%d)\n",un32Trunk);
					fContinue = TBX_FALSE;
					continue;
				}

				/* Check if the trunk is active */
				pTrunkInfo = &(in_pAdapterInfo->aTrunkInfo [un32Trunk]);
				if (pTrunkInfo->hTrunk == (TB640_TRUNK_HANDLE)NULL)
				{
					TB640_CAS_DISPLAY_PRINT ("Invalid selected trunk (%d)\n",un32Trunk);
					fContinue = TBX_FALSE;
					continue;
				}

				/* Include the trunk in the stress testing */
				pTrunkInfo->fIncludedInStressTesting = TBX_TRUE;
			}
			while( ++un32Trunk <= un32TrunkTop );

			/* Parse the next token */
			pToken = strtok (NULL, ",");
		}

		/* Has the parsing been completed */
		if (pToken == NULL)
		{
			*out_pfDone = TBX_TRUE;
		}
		else
		{
			*out_pfDone = TBX_FALSE;
		}

		/* End of the code (skip to cleanup) */
		TBX_EXIT_SUCCESS (TBX_RESULT_OK);
	}

	/*---------------------------------------------------------------------------------------------------------------------------
	 |  Error handling section
	 *--------------------------------------------------------------------------------------------------------------------------*/
	ERROR_HANDLING
	{
	}

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

	}

	RETURN;
}


/*-------------------------------------------------------------------------------------------------------------------------------
 |
 |  TB640CasSelectStressParameters:	This function makes the user to select parameters for stress testing
 |
 |  out_pun32StressDelayBetweenCalls:	Delay in msec between calls
 |	out_pun32StressCallMinDuration:	Minimum call duration in msec
 |	out_pun32StressCallMaxDuration:	Maximum call duration in msec
 |	out_pun32StressDelayBetweenRestart:	Delay in msec between timeslot restart
 |  out_pun32StressOutgoingTimeslotMinIdleMsec:	Minimum time an outgoing timeslot needs to stay idle
 |
 |  Note			:	~
 |
 |  Return          :	TBX_RESULT_OK
 |						TBX_RESULT_FAIL
 |
 *------------------------------------------------------------------------------------------------------------------------------*/
TBX_RESULT
TB640CasSelectStressParameters (
  OUT		PTBX_UINT32				out_pun32StressDelayBetweenCalls,
  OUT		PTBX_UINT32				out_pun32StressCallMinDuration,
  OUT		PTBX_UINT32				out_pun32StressCallMaxDuration,
  OUT		PTBX_UINT32				out_pun32StressDelayBetweenRestart,
  OUT		PTBX_UINT32				out_pun32StressOutgoingTimeslotMinIdleMsec)
{
	TBX_BOOL										fContinue;
	TBX_BOOL										fTrunkSelectionOk;
	TBX_CHAR										szLine [TB640_CAS_CLI_MAX_LINE_SIZE_GET];
	TBX_UINT32										un32NbToken;
	TBX_UINT32										un32Adapter;
	TBX_UINT32										un32Trunk;
	PTB640_CAS_ADAPTER_INFO							pAdapterInfo;
	PTB640_CAS_TRUNK_INFO							pTrunkInfo;

	/*---------------------------------------------------------------------------------------------------------------------------
	 |  Code section
	 *--------------------------------------------------------------------------------------------------------------------------*/
	CODE
	{
		/* Initialize local variable */
		*out_pun32StressDelayBetweenCalls = 0;
		*out_pun32StressCallMinDuration = 0;
		*out_pun32StressCallMaxDuration = 0;
		*out_pun32StressOutgoingTimeslotMinIdleMsec = 0;
		un32NbToken = 0;

		/* Display prompt */
		TB640_CAS_DISPLAY_PRINT ("Enter the delay between each call attempt (%d to ... msec): ", TB640_CAS_CLI_MIN_TIME_BETWEEN_STRESS_CALLS);

		/* Get the input from the user */
		szLine[0] = 0;
		fgets (szLine, TB640_CAS_CLI_MAX_LINE_SIZE_GET, stdin);
		*out_pun32StressDelayBetweenCalls = atoi (szLine);
		if (*out_pun32StressDelayBetweenCalls < TB640_CAS_CLI_MIN_TIME_BETWEEN_STRESS_CALLS)
		{
			*out_pun32StressDelayBetweenCalls = TB640_CAS_CLI_MIN_TIME_BETWEEN_STRESS_CALLS;
		}

		/* Display prompt */
		TB640_CAS_DISPLAY_PRINT ("Enter the call duration to use (0 to ... seconds, -1 for random): ");

		/* Get the input from the user */
		szLine[0] = 0;
		fgets (szLine, TB640_CAS_CLI_MAX_LINE_SIZE_GET, stdin);
		*out_pun32StressCallMinDuration = atoi (szLine);
		if (*out_pun32StressCallMinDuration == (TBX_UINT32)-1)
		{
			TB640_CAS_DISPLAY_PRINT ("Enter the minimum call duration to use (0 to %d seconds): ", TBX_ASYNC_MAX_TIMEOUT_SEC);
			szLine[0] = 0;
			fgets (szLine, TB640_CAS_CLI_MAX_LINE_SIZE_GET, stdin);
			*out_pun32StressCallMinDuration = atoi (szLine);
			if (*out_pun32StressCallMinDuration >= TBX_ASYNC_MAX_TIMEOUT_SEC)
			{
				*out_pun32StressCallMinDuration = TBX_ASYNC_MAX_TIMEOUT_SEC;
			}

			TB640_CAS_DISPLAY_PRINT ("Enter the maximum call duration to use (0 to %d seconds): ", TBX_ASYNC_MAX_TIMEOUT_SEC);
			szLine[0] = 0;
			fgets (szLine, TB640_CAS_CLI_MAX_LINE_SIZE_GET, stdin);
			*out_pun32StressCallMaxDuration = atoi (szLine);
			if (*out_pun32StressCallMaxDuration >= TBX_ASYNC_MAX_TIMEOUT_SEC)
			{
				*out_pun32StressCallMaxDuration = TBX_ASYNC_MAX_TIMEOUT_SEC;
			}

			/* Make sure MAX is greater or equal than MIN */
			if (*out_pun32StressCallMaxDuration < *out_pun32StressCallMinDuration)
			{
				*out_pun32StressCallMinDuration = *out_pun32StressCallMinDuration;
			}
		}
		else
		{
			/* Both values are the same - fixed call duration */
			*out_pun32StressCallMaxDuration = *out_pun32StressCallMinDuration;
		}

		/* Display prompt */
		TB640_CAS_DISPLAY_PRINT ("Enter the delay between each restart attempt (1 to ... msec, 0 to disable): ");

		/* Get the input from the user */
		szLine[0] = 0;
		fgets (szLine, TB640_CAS_CLI_MAX_LINE_SIZE_GET, stdin);
		*out_pun32StressDelayBetweenRestart = atoi (szLine);

		/* Display prompt */
		TB640_CAS_DISPLAY_PRINT ("Enter the minimum delay for an outgoing timeslot to stay idle (0 to ... msec): ");

		/* Get the input from the user */
		szLine[0] = 0;
		fgets (szLine, TB640_CAS_CLI_MAX_LINE_SIZE_GET, stdin);
		*out_pun32StressOutgoingTimeslotMinIdleMsec = atoi (szLine);

		/* Reset all adapters not to be included in stress testing */
		for (un32Adapter=0; un32Adapter<g_AppContext->un32NbAdapter; un32Adapter++)
		{
			pAdapterInfo = &(g_AppContext->ahAdapterInfo [un32Adapter]);

			/* Reset all trunks of the adapter not to be included in stress testing */
			for (un32Trunk = 0; un32Trunk<TB640_CAS_MAX_SUPPORTED_TRUNKS_PER_ADAPTER; un32Trunk++)
			{
				pTrunkInfo = &(pAdapterInfo->aTrunkInfo [un32Trunk]);

				pTrunkInfo->fIncludedInStressTesting = TBX_FALSE;
			}
		}

		/* Continue to select trunks until the user decides to stop*/
		while (TBX_TRUE)
		{
			/* Make the user to select the adapter number */
			TB640_CAS_DISPLAY_PRINT ("Select adapter for which to specify trunks (-1 to exit): ");
			fgets (szLine, TB640_CAS_CLI_MAX_LINE_SIZE_GET, stdin);
			un32Adapter = atoi (szLine);

			/* Has the user finished ? */
			if (un32Adapter == (TBX_UINT32)-1)
			{
				break;
			}

			/* Validate the adapter number */
			if (un32Adapter >= g_AppContext->un32NbAdapter)
			{
				TB640_CAS_DISPLAY_PRINT ("Invalid selected adapter (%d)\n",un32Adapter);
				continue;
			}
			pAdapterInfo = &(g_AppContext->ahAdapterInfo [un32Adapter]);
			fTrunkSelectionOk = TBX_FALSE;
			while (fTrunkSelectionOk == TBX_FALSE)
			{
				TB640_CAS_DISPLAY_PRINT ("Select trunks in adapter %d to be included in stress (0-3,7...): ", un32Adapter);
				szLine[0] = '\0';
				fgets (szLine, TB640_CAS_CLI_MAX_LINE_SIZE_GET, stdin);

				/* Reset all trunks of the adapter not to be included in stress testing */
				for (un32Trunk = 0; un32Trunk<TB640_CAS_MAX_SUPPORTED_TRUNKS_PER_ADAPTER; un32Trunk++)
				{
					pTrunkInfo = &(pAdapterInfo->aTrunkInfo [un32Trunk]);

					pTrunkInfo->fIncludedInStressTesting = TBX_FALSE;
				}
				/* Parse trunk selection */
				TB640CasParseTrunkSelection (pAdapterInfo, szLine, &fTrunkSelectionOk);
			}
		}

		/* Refresh the display */
		g_fRefreshDisplay |= (TB640_CAS_CLI_REFRESH_DISPLAY);

		/* End of the code (skip to cleanup) */
		TBX_EXIT_SUCCESS (TBX_RESULT_OK);
	}

	/*--------------------------

⌨️ 快捷键说明

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