📄 voip_cli_cmd.c
字号:
case 1: /* Validate first resource type */
{
TBX_UINT32 un32FirstResTypeIndex = strtoul( pszUserInput, NULL, 10 );
VOIP_RESOURCE_TYPE FirstResType;
if( !VoipCliIsValidNumericValue( pszUserInput ) )
{
/* Restore a valid value */
sprintf( pszUserInput, "%u", (int)g_DefaultPrompts.StartStressTest.un32FirstResTypeIndex );
return TBX_FALSE;
}
/* Retrieve first resource class */
FirstResType = VoipCliIntegerToFirstResType( un32FirstResTypeIndex );
if( FirstResType == VOIP_RESOURCE_TYPE_INVALID )
{
TbxCliToolsLogPrint
(
pCliContext->hCliTools, TRACE_LEVEL_ERROR, NULL,
"Invalid first resource type.\n"
);
/* Restore a valid value */
sprintf( pszUserInput, "%u", (int)g_DefaultPrompts.StartStressTest.un32FirstResTypeIndex );
return TBX_FALSE;
}
} break;
case 2: /* Validate connections by second */
{
if( !VoipCliIsValidNumericValue( pszUserInput ) )
{
/* Restore a valid value */
sprintf( pszUserInput, "%u", (int)g_DefaultPrompts.StartStressTest.un32NbConnectionsPerSecond );
return TBX_FALSE;
}
} break;
case 3: /* Validate minimum connection duration */
{
if( !VoipCliIsValidNumericValue( pszUserInput ) )
{
/* Restore a valid value */
sprintf( pszUserInput, "%u", (int)g_DefaultPrompts.StartStressTest.un32MinConnectionDuration );
return TBX_FALSE;
}
} break;
case 4: /* Validate maximum connection duration */
{
if( !VoipCliIsValidNumericValue( pszUserInput ) )
{
/* Restore a valid value */
sprintf( pszUserInput, "%u", (int)g_DefaultPrompts.StartStressTest.un32MaxConnectionDuration );
return TBX_FALSE;
}
} break;
case 5: /* Validate automatically abort stress test on failure indication */
{
if( !VoipCliIsValidBoolValue( pszUserInput ) )
{
/* Restore a valid value */
sprintf( pszUserInput, "%s", (g_DefaultPrompts.StartStressTest.fAutoAbort == TBX_TRUE) ? "YES":"NO" );
return TBX_FALSE;
}
} break;
case 6: /* Validate disconnect all resource before starting stress-test */
{
if( !VoipCliIsValidBoolValue( pszUserInput ) )
{
/* Restore a valid value */
sprintf( pszUserInput, "%s", (g_DefaultPrompts.StartStressTest.fDisconnectAllRes == TBX_TRUE) ? "YES":"NO" );
return TBX_FALSE;
}
} break;
case 7: /* Validate 'do BERT test' */
{
if( !VoipCliIsValidBoolValue( pszUserInput ) )
{
/* Restore a valid value */
sprintf( pszUserInput, "%s", (g_DefaultPrompts.StartStressTest.fDoBertTests == TBX_TRUE) ? "YES":"NO" );
return TBX_FALSE;
}
} break;
case 8: /* Validate test duration by second */
{
if( !VoipCliIsValidNumericValue( pszUserInput ) )
{
/* Restore a valid value */
sprintf( pszUserInput, "%d", (int)g_DefaultPrompts.StartStressTest.un32TestDurationSec );
return TBX_FALSE;
}
} break;
}
return TBX_TRUE;
}
TBX_VOID VoipCliCmdStartStressTestApply(
IN OUT PTBX_CLI_TOOLS_CMD io_pCmdContext )
{
TBX_RESULT Result;
PVOIP_CLI_CONTEXT pCliContext = &g_pContext->CliContext;
VOIP_RESOURCE_TYPE FirstResType;
TBX_UINT32 un32NbConnectionsPerSecond;
TBX_UINT32 un32MinConnectionDuration;
TBX_UINT32 un32MaxConnectionDuration;
TBX_UINT32 un32TestDurationSec;
PTBX_CHAR pszStreamSocketIP;
TBX_BOOL fAutoAbort;
TBX_BOOL fDisconnectAllRes;
TBX_BOOL fDoBertTests;
fAutoAbort = VoipCliStringToBool( io_pCmdContext->paszUserInput[ 5 ].szLine );
fDisconnectAllRes = VoipCliStringToBool( io_pCmdContext->paszUserInput[ 6 ].szLine );
fDoBertTests = VoipCliStringToBool( io_pCmdContext->paszUserInput[ 7 ].szLine );
/* Save new default prompt values */
strcpy( g_DefaultPrompts.StartStressTest.szStreamSocketIP,
io_pCmdContext->paszUserInput[0].szLine );
g_DefaultPrompts.StartStressTest.un32FirstResTypeIndex =
(TBX_UINT32)strtoul( io_pCmdContext->paszUserInput[ 1 ].szLine, NULL, 0 );
g_DefaultPrompts.StartStressTest.un32NbConnectionsPerSecond =
(TBX_UINT32)strtoul( io_pCmdContext->paszUserInput[ 2 ].szLine, NULL, 0 );
g_DefaultPrompts.StartStressTest.un32MinConnectionDuration =
(TBX_UINT32)strtoul( io_pCmdContext->paszUserInput[ 3 ].szLine, NULL, 0 );
g_DefaultPrompts.StartStressTest.un32MaxConnectionDuration =
(TBX_UINT32)strtoul( io_pCmdContext->paszUserInput[ 4 ].szLine, NULL, 0 );
g_DefaultPrompts.StartStressTest.fAutoAbort = fAutoAbort;
g_DefaultPrompts.StartStressTest.fDisconnectAllRes = fDisconnectAllRes;
g_DefaultPrompts.StartStressTest.fDoBertTests = fDoBertTests;
g_DefaultPrompts.StartStressTest.un32TestDurationSec =
(TBX_UINT32)strtoul( io_pCmdContext->paszUserInput[ 8 ].szLine, NULL, 0 );
/* Stream socket IP address */
pszStreamSocketIP = g_DefaultPrompts.StartStressTest.szStreamSocketIP;
/* Retrieve first resource class */
FirstResType = VoipCliIntegerToFirstResType( g_DefaultPrompts.StartStressTest.un32FirstResTypeIndex );
un32NbConnectionsPerSecond = g_DefaultPrompts.StartStressTest.un32NbConnectionsPerSecond;
un32MinConnectionDuration = g_DefaultPrompts.StartStressTest.un32MinConnectionDuration;
un32MaxConnectionDuration = g_DefaultPrompts.StartStressTest.un32MaxConnectionDuration;
un32TestDurationSec = g_DefaultPrompts.StartStressTest.un32TestDurationSec;
Result = VoipCliSendStartStressTest(
pCliContext, pszStreamSocketIP, FirstResType,
un32NbConnectionsPerSecond, un32MinConnectionDuration, un32MaxConnectionDuration, fAutoAbort, fDisconnectAllRes, fDoBertTests, un32TestDurationSec );
if( TBX_RESULT_FAILURE( Result ) == TBX_TRUE )
{
TbxCliToolsLogPrint( pCliContext->hCliTools, TRACE_LEVEL_ERROR, NULL, "Failed to start stress test!\n" );
}
/* No more input to take. Return to main menu input. */
io_pCmdContext->CmdType = VOIP_CLI_CMD_TYPE_NONE;
}
/*-------------------------------------------------------------------------------------------------------------------------------
|
| VoipCliCmdStopStressTestInit : Prepare user prompts for the 'Stop Stress Test' command
| VoipCliCmdStopStressTestValidate : Validate each user's input (called once per prompt)
| VoipCliCmdStopStressTestApply : Apply the command
|
| in_pCmdContext : Context of the command-line.
|
| Note : ~
|
| Return : TBX_RESULT_OK
| TBX_RESULT_FAIL
|
*------------------------------------------------------------------------------------------------------------------------------*/
TBX_VOID VoipCliCmdStopStressTestInit(
IN OUT PTBX_CLI_TOOLS_CMD io_pCmdContext )
{
PVOIP_CLI_CONTEXT pCliContext = &g_pContext->CliContext;
PVOIP_ADAPTER_CONTEXT pAdapterContext = pCliContext->pActiveAdapterContext;
if( pAdapterContext->StressTest.fActive == TBX_FALSE )
{
TbxCliToolsLogPrint(
pCliContext->hCliTools, TRACE_LEVEL_ERROR, NULL,
"Stress-test already stopped.\n" );
return;
}
/* Start gathering input for 'launch stress test' */
io_pCmdContext->CmdType = VOIP_CLI_CMD_TYPE_STOP_STRESS_TEST;
/* Set prompt command */
strcpy( io_pCmdContext->paszPrompt[0].szLine, "Are you sure? " );
/* Save new default prompt values */
g_DefaultPrompts.StopStressTest.fConfirm = TBX_FALSE;
/* Set default user input value */
sprintf( io_pCmdContext->paszUserInput[0].szLine, "%s", (g_DefaultPrompts.StopStressTest.fConfirm == TBX_TRUE) ? "YES":"NO" );
}
TBX_BOOL VoipCliCmdStopStressTestValidate(
IN OUT PTBX_CLI_TOOLS_CMD io_pCmdContext )
{
PTBX_CHAR pszUserInput = io_pCmdContext->paszUserInput[ io_pCmdContext->un32CurrentPromptIdx ].szLine;
/* Make uppercase */
ToUpper( pszUserInput );
switch( io_pCmdContext->un32CurrentPromptIdx )
{
case 0: /* Validate stress test confirm */
{
if( !VoipCliIsValidBoolValue( pszUserInput ) )
{
/* Restore a valid value */
sprintf( pszUserInput, "%s", (g_DefaultPrompts.StopStressTest.fConfirm == TBX_TRUE) ? "YES":"NO" );
return TBX_FALSE;
}
} break;
}
return TBX_TRUE;
}
TBX_VOID VoipCliCmdStopStressTestApply(
IN OUT PTBX_CLI_TOOLS_CMD io_pCmdContext )
{
TBX_RESULT Result;
PVOIP_CLI_CONTEXT pCliContext = &g_pContext->CliContext;
TBX_BOOL fConfirm;
fConfirm = VoipCliStringToBool( io_pCmdContext->paszUserInput[ 0 ].szLine );
if( fConfirm == TBX_TRUE )
{
Result = VoipCliSendStopStressTest( pCliContext );
if( TBX_RESULT_FAILURE( Result ) == TBX_TRUE )
{
TbxCliToolsLogPrint( pCliContext->hCliTools, TRACE_LEVEL_ERROR, NULL, "Failed to stop stress test!\n" );
}
}
/* No more input to take. Return to main menu input. */
io_pCmdContext->CmdType = VOIP_CLI_CMD_TYPE_NONE;
}
/*-------------------------------------------------------------------------------------------------------------------------------
|
| VoipCliCmdResetStressTestStatsInit : Prepare user prompts for the 'Stop Stress Test' command
| VoipCliCmdResetStressTestStatsValidate : Validate each user's input (called once per prompt)
| VoipCliCmdResetStressTestStatsApply : Apply the command
|
| in_pCmdContext : Context of the command-line.
|
| Note : ~
|
| Return : TBX_RESULT_OK
| TBX_RESULT_FAIL
|
*------------------------------------------------------------------------------------------------------------------------------*/
TBX_VOID VoipCliCmdResetStressTestStatsInit(
IN OUT PTBX_CLI_TOOLS_CMD io_pCmdContext )
{
PVOIP_CLI_CONTEXT pCliContext = &g_pContext->CliContext;
PVOIP_ADAPTER_CONTEXT pAdapterContext = pCliContext->pActiveAdapterContext;
if( pAdapterContext->StressTest.fActive == TBX_FALSE )
{
TbxCliToolsLogPrint(
pCliContext->hCliTools, TRACE_LEVEL_ERROR, NULL,
"Stress-test is not active.\n" );
return;
}
/* Start gathering input for 'Reset stress test stats' */
io_pCmdContext->CmdType = VOIP_CLI_CMD_TYPE_RESET_STRESS_TEST_STATS;
/* Set prompt command */
strcpy( io_pCmdContext->paszPrompt[0].szLine, "Are you sure? " );
/* Save new default prompt values */
g_DefaultPrompts.ResetStressTestStats.fConfirm = TBX_FALSE;
/* Set default user input value */
sprintf( io_pCmdContext->paszUserInput[0].szLine, "%s", (g_DefaultPrompts.ResetStressTestStats.fConfirm == TBX_TRUE) ? "YES":"NO" );
}
TBX_BOOL VoipCliCmdResetStressTestStatsValidate(
IN OUT PTBX_CLI_TOOLS_CMD io_pCmdContext )
{
PTBX_CHAR pszUserInput = io_pCmdContext->paszUserInput[ io_pCmdContext->un32CurrentPromptIdx ].szLine;
/* Make uppercase */
ToUpper( pszUserInput );
switch( io_pCmdContext->un32CurrentPromptIdx )
{
case 0: /* Validate reset stress test confirm */
{
if( !VoipCliIsValidBoolValue( pszUserInput ) )
{
/* Restore a valid value */
sprintf( pszUserInput, "%s", (g_DefaultPrompts.ResetStressTestStats.fConfirm == TBX_TRUE) ? "YES":"NO" );
return TBX_FALSE;
}
} break;
}
return TBX_TRUE;
}
TBX_VOID VoipCliCmdResetStressTestStatsApply(
IN OUT PTBX_CLI_TOOLS_CMD io_pCmdContext )
{
TBX_RESULT Result;
PVOIP_CLI_CONTEXT pCliContext = &g_pContext->CliContext;
TBX_BOOL fConfirm;
fConfirm = VoipCliStringToBool( io_pCmdContext->paszUserInput[ 0 ].szLine );
if( fConfirm == TBX_TRUE )
{
Result = VoipCliSendResetStressTestStats( pCliContext );
if( TBX_RESULT_FAILURE( Result ) == TBX_TRUE )
{
TbxCliToolsLogPrint( pCliContext->hCliTools, TRACE_LEVEL_ERROR, NULL, "Failed to reset stress test stats!\n" );
}
}
/* No more input to take. Return to main menu input. */
io_pCmdContext->CmdType = VOIP_CLI_CMD_TYPE_NONE;
}
/*-------------------------------------------------------------------------------------------------------------------------------
|
| VoipCliCmdStartDemoInit : Prepare user prompts for the 'Start demo' command
| VoipCliCmdStartDemoValidate : Validate each user's input (called once per prompt)
| VoipCliCmdStartDemoApply : Apply the command
|
| in_pCmdContext : Context of the command-line.
|
| Note : ~
|
| Return : TBX_RESULT_OK
| TBX_RESULT_FAIL
|
*------------------------------------------------------------------------------------------------------------------------------*/
TBX_VOID VoipCliCmdStartDemoInit(
IN OUT PTBX_CLI_TOOLS_CMD io_pCmdContext )
{
PVOIP_CLI_CONTEXT pCliContext = &g_pContext->CliContext;
PVOIP_ADAPTER_CONTEXT pAdapterContext = pCliContext->pActiveAdapterContext;
if( pAdapterContext->Demo.fActive == TBX_TRUE )
{
TbxCliToolsLogPrint(
pCliContext->hCliTools, TRACE_LEVEL_ERROR, NULL,
"Demo already running.\n" );
return;
}
/* Start gathering input for 'launch demo' */
io_pCmdContext->CmdType = VOIP_CLI_CMD_TYPE_START_DEMO;
/* Set prompt command */
strcpy( io_pCmdContext->paszPrompt[0].szLine, "Skip pauses? " );
strcpy( io_pCmdContext->paszPrompt[1].szLine, "Abort on failure? " );
/* Set default user input value */
sprintf( io_pCmdContext->paszUserInput[0].szLine, "%s", (g_DefaultPrompts.StartDemo.fSkipPauses == TBX_TRUE) ? "YES":"NO" );
sprintf( io_pCmdContext->paszUserInput[1].szLine, "%s", (g_DefaultPrompts.StartDemo.fAutoAbort == TBX_TRUE) ? "YES":"NO" );
}
TBX_BOOL VoipCliCmdStartDemoValidate(
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -