blob: 70f91a8a93fb73a96502ec83fd364cd45a787a2e [file] [log] [blame]
///////////////////////////////////////////////////////////////////////////////
//
// Copyright (c) 2000-2019 Ericsson Telecom AB
//
// All rights reserved. This program and the accompanying materials
// are made available under the terms of the Eclipse Public License v2.0
// which accompanies this distribution, and is available at
// https://www.eclipse.org/org/documents/epl-2.0/EPL-2.0.html
///////////////////////////////////////////////////////////////////////////////
// File: IOT_LGen_Steps.ttcn
// Description:
// Rev: R1A
// Prodnr: LPA 108 661
// Updated: 2017-09-01
// Contact: http://ttcn.ericsson.se
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////
// Module: IOT_LGen_Steps
//
// Purpose:
// This module contains test step functions for RIoT's load generator component
//
// See also:
// <IOT_LGen_Definitions>
//
// Module depends on:
// - <IOT_LGen_Definitions>
// - <EPTF_MQTT_LGen_Functions>
// - <EPTF_COAP_LGen_Definitions>
// - <EPTF_COAP_LGen_Functions>
// - <EPTF_LwM2M_LGen_Functions>
// - <EPTF_LwM2M_Object_Definitions>
// - <EPTF_LwM2M_Object_Functions>
// - <EPTF_HTTP_Functions>
// - <EPTF_HTTP_Transport_Functions>
// - <EPTF_CLL_Common_Definitions>
// - <EPTF_CLL_ExecCtrlClient_Functions>
// - <EPTF_CLL_LGenBase_Definitions>
// - <EPTF_CLL_LGenBase_StepFunctions>
// - <EPTF_CLL_LGenBase_ConfigFunctions>
// - <EPTF_CLL_Variable_Definitions>
// - <EPTF_CLL_Variable_Functions>
//
// Test Steps [Generic]:
// testcase finished - <f_IOT_LGen_step_tcFinished_withVerdict>, <c_IOT_stepName_tcFinished_withVerdict>
// print - <f_IOT_LGen_step_print_stringParam>, <c_IOT_stepName_print_stringParam>
// RND generator - <f_IOT_LGen_step_genRndValue_varParams>, <c_IOT_stepName_genRndValue_varParams>
//
// Test Steps [COAP]:
// set local address - <f_IOT_LGen_step_COAP_setLocalAddress_byVars>, <c_IOT_stepName_COAP_setLocalAddress_byVars>
//
// Test Steps [LwM2M]:
// set client name - <f_IOT_LGen_step_LwM2M_setClientNameInRegister>, <c_IOT_stepName_LwM2M_setClientNameInRegister>
// <f_IOT_LGen_step_LwM2M_setClientNameInRegister_stringVar>, <c_IOT_stepName_LwM2M_setClientNameInRegister_stringVar>
//
// Test Steps [MQTT]:
// set local address - <f_IOT_LGen_step_MQTT_setLocalAddress_byVars>, <c_IOT_stepName_MQTT_setLocalAddress_byVars>
// <f_IOT_LGen_step_MQTT_setClientId_stringParam>, <c_IOT_stepName_MQTT_setClientId_stringParam>
//
// Test Steps [HTTP]:
// init entity context - <f_IOT_LGen_step_HTTP_initEntityContext>, <c_IOT_stepName_HTTP_initEntityContext>
// open connection - <f_IOT_LGen_step_HTTP_openConnection_byVars>, <c_IOT_stepName_HTTP_openConnection_byVars>
// close connection - <f_IOT_LGen_step_HTTP_closeConnection>, <c_IOT_stepName_HTTP_closeConnection>
// set HTTP method - <f_IOT_LGen_step_HTTP_setMethod_stringParam>, <c_IOT_stepName_HTTP_setMethod_stringParam>
// set HTTP URI - <f_IOT_LGen_step_HTTP_setUri_stringParam>, <c_IOT_stepName_HTTP_addToUri_stringParam>
// <f_IOT_LGen_step_HTTP_addToUri_byVars>, <c_IOT_stepName_HTTP_addToUri_byVars>
// add HTTP Host header - <f_IOT_LGen_step_HTTP_addHostHeader_byVars>, <c_IOT_stepName_HTTP_addHostHeader_byVars>
//
// Test Steps [Leshan]:
// get client name - <f_IOT_LGen_step_Leshan_getClientFromResponse_intoVar>, <c_IOT_stepName_Leshan_getClientFromResponse_intoVar>
//
// Test Steps [RegDereg FSM]:
// init resource values - <f_IOT_LGen_step_FSM_RegDereg_initResourceValues>, <c_IOT_stepName_FSM_RegDereg_initResourceValues>
//
// Test Steps [SimDev FSM]:
// create resources - <f_IOT_LGen_step_FSM_SimDevice_createResources>, <c_IOT_stepName_FSM_SimDevice_createResources>
// init resource values - <f_IOT_LGen_step_FSM_SimDevice_initResourceValues>, <c_IOT_stepName_FSM_SimDevice_initResourceValues>
// init transport - <f_IOT_LGen_step_FSM_SimDevice_initTransport_boolVar>, <c_IOT_stepName_FSM_SimDevice_initTransport_boolVar>
// update resource values - <f_IOT_LGen_step_FSM_SimDevice_updateResourceValues>, <c_IOT_stepName_FSM_SimDevice_updateResourceValues>
// handle EXECUTE - <f_IOT_LGen_step_FSM_SimDevice_handleExecute>, <c_IOT_stepName_FSM_SimDevice_handleExecute>
///////////////////////////////////////////////////////////////
module IOT_LGen_Steps {
import from JSON_Types all;
import from IOT_LGen_Definitions all;
import from EPTF_COAP_LGen_Definitions all;
import from EPTF_COAP_LGen_Functions all;
import from EPTF_MQTT_LGen_Functions all;
import from EPTF_LwM2M_LGen_Functions all;
import from EPTF_LwM2M_Object_Definitions all;
import from EPTF_LwM2M_Object_Functions all;
import from LightweightM2M_Types all;
import from EPTF_HTTP_Functions all;
import from EPTF_HTTP_Transport_Functions all;
import from EPTF_CLL_Common_Definitions all;
import from EPTF_CLL_Variable_Definitions all;
import from EPTF_CLL_Variable_Functions all;
import from EPTF_CLL_LGenBase_Definitions all;
import from EPTF_CLL_LGenBase_StepFunctions all;
import from EPTF_CLL_LGenBase_ConfigFunctions all;
import from EPTF_CLL_ExecCtrlClient_Functions all;
//////////////////////
// Generic
//////////////////////
///////////////////////////////////////////////////////////
// const: c_IOT_stepName_tcFinished_withVerdict
//
// Purpose:
// Charstring constant for the RIoT test case finished test step
//
// Related Function:
// - <f_IOT_LGen_step_tcFinished_withVerdict>
///////////////////////////////////////////////////////////
const charstring c_IOT_stepName_tcFinished_withVerdict := "IOT App: tcFinished_withVerdict";
///////////////////////////////////////////////////////////
// const: c_IOT_stepName_print_stringParam
//
// Purpose:
// Charstring constant for the RIoT print string test step
//
// Related Function:
// - <f_IOT_LGen_step_print_stringParam>
///////////////////////////////////////////////////////////
const charstring c_IOT_stepName_print_stringParam := "IOT App: print_stringParam";
///////////////////////////////////////////////////////////
// const: c_IOT_stepName_genRndValue_varParams
//
// Purpose:
// Charstring constant for the RIoT random number generator test step
//
// Related Function:
// - <f_IOT_LGen_step_genRndValue_varParams>
///////////////////////////////////////////////////////////
const charstring c_IOT_stepName_genRndValue_varParams := "IOT App: genRndValue_varParams";
//////////////////////
// COAP
//////////////////////
///////////////////////////////////////////////////////////
// const: c_IOT_stepName_COAP_setLocalAddress_byVars
//
// Purpose:
// Charstring constant for setting the COAP local address test step
//
// Related Function:
// - <f_IOT_LGen_step_COAP_setLocalAddress_byVars>
///////////////////////////////////////////////////////////
const charstring c_IOT_stepName_COAP_setLocalAddress_byVars := "IOT App COAP: setLocalAddress_byVars";
//////////////////////
// MQTT
//////////////////////
///////////////////////////////////////////////////////////
// const: c_IOT_stepName_MQTT_setLocalAddress_byVars
//
// Purpose:
// Charstring constant for setting the MQTT local address test step
//
// Related Function:
// - <f_IOT_LGen_step_MQTT_setLocalAddress_byVars>
///////////////////////////////////////////////////////////
const charstring c_IOT_stepName_MQTT_setLocalAddress_byVars := "IOT App MQTT: setLocalAddress_byVars";
///////////////////////////////////////////////////////////
// const: c_IOT_stepName_MQTT_setClientId_stringParam
//
// Purpose:
// Charstring constant for the test step that sets the MQTT client id
//
// Related Function:
// - <f_IOT_LGen_step_MQTT_setClientId_stringParam>
///////////////////////////////////////////////////////////
const charstring c_IOT_stepName_MQTT_setClientId_stringParam := "IOT App MQTT: setClientId_stringParam";
//////////////////////
// LwM2M
//////////////////////
///////////////////////////////////////////////////////////
// const: c_IOT_stepName_LwM2M_setClientNameInRegister
//
// Purpose:
// Charstring constant for the test step that sets the LwM2M endpoint name in the Register message
//
// Related Function:
// - <f_IOT_LGen_step_LwM2M_setClientNameInRegister>
///////////////////////////////////////////////////////////
const charstring c_IOT_stepName_LwM2M_setClientNameInRegister := "IOT App LwM2M: setClientNameInRegister";
///////////////////////////////////////////////////////////
// const: c_IOT_stepName_LwM2M_setClientNameInRegister_stringVar
//
// Purpose:
// Charstring constant for the test step that sets the LwM2M endpoint name in the Register message
//
// Related Function:
// - <f_IOT_LGen_step_LwM2M_setClientNameInRegister_stringVar>
///////////////////////////////////////////////////////////
const charstring c_IOT_stepName_LwM2M_setClientNameInRegister_stringVar := "IOT App LwM2M: setClientNameInRegister_stringVar";
//////////////////////
// HTTP
//////////////////////
///////////////////////////////////////////////////////////
// const: c_IOT_stepName_HTTP_initEntityContext
//
// Purpose:
// Charstring constant for the test step that initializes the HTTP entity context
//
// Related Function:
// - <f_IOT_LGen_step_HTTP_initEntityContext>
///////////////////////////////////////////////////////////
const charstring c_IOT_stepName_HTTP_initEntityContext := "IOT App HTTP: initEntityContext";
///////////////////////////////////////////////////////////
// const: c_IOT_stepName_HTTP_openConnection_byVars
//
// Purpose:
// Charstring constant for the test step that opens an HTTP connection
//
// Related Function:
// - <f_IOT_LGen_step_HTTP_openConnection_byVars>
///////////////////////////////////////////////////////////
const charstring c_IOT_stepName_HTTP_openConnection_byVars := "IOT App HTTP: openConnection_byVars";
///////////////////////////////////////////////////////////
// const: c_IOT_stepName_HTTP_closeConnection
//
// Purpose:
// Charstring constant for the test step that closes the opened HTTP connection
//
// Related Function:
// - <f_IOT_LGen_step_HTTP_closeConnection>
///////////////////////////////////////////////////////////
const charstring c_IOT_stepName_HTTP_closeConnection := "IOT App HTTP: closeConnection";
///////////////////////////////////////////////////////////
// const: c_IOT_stepName_HTTP_setMethod_stringParam
//
// Purpose:
// Charstring constant for the test step that sets the HTTP method for the HTTP message to be sent
//
// Related Function:
// - <f_IOT_LGen_step_HTTP_setMethod_stringParam>
///////////////////////////////////////////////////////////
const charstring c_IOT_stepName_HTTP_setMethod_stringParam := "IOT App HTTP: setMethod_stringParam";
///////////////////////////////////////////////////////////
// const: c_IOT_stepName_HTTP_setUri_stringParam
//
// Purpose:
// Charstring constant for the test step that sets the HTTP request URI for the HTTP message to be sent
//
// Related Function:
// - <f_IOT_LGen_step_HTTP_setUri_stringParam>
///////////////////////////////////////////////////////////
const charstring c_IOT_stepName_HTTP_setUri_stringParam := "IOT App HTTP: setUri_stringParam";
///////////////////////////////////////////////////////////
// const: c_IOT_stepName_HTTP_addToUri_stringParam
//
// Purpose:
// Charstring constant for the test step that concatenates a string to the HTTP request URI for the HTTP message to be sent
//
// Related Function:
// - <f_IOT_LGen_step_HTTP_addToUri_stringParam>
///////////////////////////////////////////////////////////
const charstring c_IOT_stepName_HTTP_addToUri_stringParam := "IOT App HTTP: addToUri_stringParam";
///////////////////////////////////////////////////////////
// const: c_IOT_stepName_HTTP_addToUri_byVars
//
// Purpose:
// Charstring constant for the test step that concatenates a string to the HTTP request URI for the HTTP message to be sent
//
// Related Function:
// - <f_IOT_LGen_step_HTTP_addToUri_byVars>
///////////////////////////////////////////////////////////
const charstring c_IOT_stepName_HTTP_addToUri_byVars := "IOT App HTTP: addToUri_byVars";
///////////////////////////////////////////////////////////
// const: c_IOT_stepName_HTTP_addHostHeader_byVars
//
// Purpose:
// Charstring constant for the test step that adds a Host header to the HTTP message to be sent
//
// Related Function:
// - <f_IOT_LGen_step_HTTP_addHostHeader_byVars>
///////////////////////////////////////////////////////////
const charstring c_IOT_stepName_HTTP_addHostHeader_byVars := "IOT App HTTP: addHostHeader_byVars";
//////////////////////
// Leshan
//////////////////////
///////////////////////////////////////////////////////////
// const: c_IOT_stepName_Leshan_getClientFromResponse_intoVar
//
// Purpose:
// Charstring constant for the test step that loads the client name into a variable from an HTTP response
//
// Related Function:
// - <f_IOT_LGen_step_Leshan_getClientFromResponse_intoVar>
///////////////////////////////////////////////////////////
const charstring c_IOT_stepName_Leshan_getClientFromResponse_intoVar := "IOT App Leshan: getClientFromResponse_intoVar";
//////////////////////
// FSM_RegDereg
//////////////////////
///////////////////////////////////////////////////////////
// const: c_IOT_stepName_FSM_RegDereg_initResourceValues
//
// Purpose:
// Charstring constant for the test step that inits the resources of the RegDereg FSM
//
// Related Function:
// - <f_IOT_LGen_step_FSM_RegDereg_initResourceValues>
///////////////////////////////////////////////////////////
const charstring c_IOT_stepName_FSM_RegDereg_initResourceValues := "IOT Fsm LWM2M_RegDereg: initResourceValues";
//////////////////////
// FSM SimDevice
//////////////////////
///////////////////////////////////////////////////////////
// const: c_IOT_stepName_FSM_SimDevice_createResources
//
// Purpose:
// Charstring constant for the test step that creates the resources of the SimDevice FSM
//
// Related Function:
// - <f_IOT_LGen_step_FSM_SimDevice_createResources>
///////////////////////////////////////////////////////////
const charstring c_IOT_stepName_FSM_SimDevice_createResources := "IOT Fsm LWM2M_SimDevice: createResources";
///////////////////////////////////////////////////////////
// const: c_IOT_stepName_FSM_SimDevice_initResourceValues
//
// Purpose:
// Charstring constant for the test step that inits the resources of the SimDevice FSM
//
// Related Function:
// - <f_IOT_LGen_step_FSM_SimDevice_initResourceValues>
///////////////////////////////////////////////////////////
const charstring c_IOT_stepName_FSM_SimDevice_initResourceValues := "IOT Fsm LWM2M_SimDevice: initResourceValues";
///////////////////////////////////////////////////////////
// const: c_IOT_stepName_FSM_SimDevice_initTransport_boolVar
//
// Purpose:
// Charstring constant for the test step that inits the transport (UDP, or DTLS-PSK) for the SimDev FSM's LwM2M protocol
//
// Related Function:
// - <f_IOT_LGen_step_FSM_SimDevice_initTransport_boolVar>
///////////////////////////////////////////////////////////
const charstring c_IOT_stepName_FSM_SimDevice_initTransport_boolVar := "IOT Fsm LWM2M_SimDevice: initTransport_boolVar";
///////////////////////////////////////////////////////////
// const: c_IOT_stepName_FSM_SimDevice_updateResourceValues
//
// Purpose:
// Charstring constant for the test step that updates the resource values of the SimDevice FSM
//
// Related Function:
// - <f_IOT_LGen_step_FSM_SimDevice_updateResourceValues>
///////////////////////////////////////////////////////////
const charstring c_IOT_stepName_FSM_SimDevice_updateResourceValues := "IOT Fsm LWM2M_SimDevice: updateResourceValues";
///////////////////////////////////////////////////////////
// const: c_IOT_stepName_FSM_SimDevice_handleExecute
//
// Purpose:
// Charstring constant for the test step that handles LwM2M EXECUTE requests on the SimDevice FSM
//
// Related Function:
// - <f_IOT_LGen_step_FSM_SimDevice_handleExecute>
///////////////////////////////////////////////////////////
const charstring c_IOT_stepName_FSM_SimDevice_handleExecute := "IOT Fsm LWM2M_SimDevice: handleExecute";
///////////////////////////////////////////////////////////
// Function: f_IOT_LGen_declareSteps
//
// Purpose:
// Function to declare all the RIoT application related test steps
//
// Related Types:
// <IOT_LGen_CT>
///////////////////////////////////////////////////////////
function f_IOT_LGen_declareSteps()
runs on IOT_LGen_CT
{
// COAP
f_EPTF_LGenBase_declareStep(c_IOT_behaviorType, {c_IOT_stepName_COAP_setLocalAddress_byVars, refers(f_IOT_LGen_step_COAP_setLocalAddress_byVars)});
// MQTT
f_EPTF_LGenBase_declareStep(c_IOT_behaviorType, {c_IOT_stepName_MQTT_setLocalAddress_byVars, refers(f_IOT_LGen_step_MQTT_setLocalAddress_byVars)});
f_EPTF_LGenBase_declareStep(c_IOT_behaviorType, {c_IOT_stepName_MQTT_setClientId_stringParam, refers(f_IOT_LGen_step_MQTT_setClientId_stringParam)});
// LwM2M
f_EPTF_LGenBase_declareStep(c_IOT_behaviorType, {c_IOT_stepName_FSM_RegDereg_initResourceValues, refers(f_IOT_LGen_step_FSM_RegDereg_initResourceValues)});
f_EPTF_LGenBase_declareStep(c_IOT_behaviorType, {c_IOT_stepName_FSM_SimDevice_createResources, refers(f_IOT_LGen_step_FSM_SimDevice_createResources)});
f_EPTF_LGenBase_declareStep(c_IOT_behaviorType, {c_IOT_stepName_FSM_SimDevice_initResourceValues, refers(f_IOT_LGen_step_FSM_SimDevice_initResourceValues)});
f_EPTF_LGenBase_declareStep(c_IOT_behaviorType, {c_IOT_stepName_FSM_SimDevice_initTransport_boolVar, refers(f_IOT_LGen_step_FSM_SimDevice_initTransport_boolVar)});
f_EPTF_LGenBase_declareStep(c_IOT_behaviorType, {c_IOT_stepName_FSM_SimDevice_updateResourceValues, refers(f_IOT_LGen_step_FSM_SimDevice_updateResourceValues)});
f_EPTF_LGenBase_declareStep(c_IOT_behaviorType, {c_IOT_stepName_FSM_SimDevice_handleExecute, refers(f_IOT_LGen_step_FSM_SimDevice_handleExecute)});
f_EPTF_LGenBase_declareStep(c_IOT_behaviorType, {c_IOT_stepName_LwM2M_setClientNameInRegister, refers(f_IOT_LGen_step_LwM2M_setClientNameInRegister)});
f_EPTF_LGenBase_declareStep(c_IOT_behaviorType, {c_IOT_stepName_LwM2M_setClientNameInRegister_stringVar, refers(f_IOT_LGen_step_LwM2M_setClientNameInRegister_stringVar)});
// HTTP
f_EPTF_LGenBase_declareStep(c_IOT_behaviorType, {c_IOT_stepName_HTTP_initEntityContext, refers(f_IOT_LGen_step_HTTP_initEntityContext)});
f_EPTF_LGenBase_declareStep(c_IOT_behaviorType, {c_IOT_stepName_HTTP_openConnection_byVars, refers(f_IOT_LGen_step_HTTP_openConnection_byVars)});
f_EPTF_LGenBase_declareStep(c_IOT_behaviorType, {c_IOT_stepName_HTTP_closeConnection, refers(f_IOT_LGen_step_HTTP_closeConnection)});
f_EPTF_LGenBase_declareStep(c_IOT_behaviorType, {c_IOT_stepName_HTTP_setMethod_stringParam, refers(f_IOT_LGen_step_HTTP_setMethod_stringParam)});
f_EPTF_LGenBase_declareStep(c_IOT_behaviorType, {c_IOT_stepName_HTTP_setUri_stringParam, refers(f_IOT_LGen_step_HTTP_setUri_stringParam)});
f_EPTF_LGenBase_declareStep(c_IOT_behaviorType, {c_IOT_stepName_HTTP_addToUri_stringParam, refers(f_IOT_LGen_step_HTTP_addToUri_stringParam)});
f_EPTF_LGenBase_declareStep(c_IOT_behaviorType, {c_IOT_stepName_HTTP_addToUri_byVars, refers(f_IOT_LGen_step_HTTP_addToUri_byVars)});
f_EPTF_LGenBase_declareStep(c_IOT_behaviorType, {c_IOT_stepName_HTTP_addHostHeader_byVars, refers(f_IOT_LGen_step_HTTP_addHostHeader_byVars)});
// Leshan
f_EPTF_LGenBase_declareStep(c_IOT_behaviorType, {c_IOT_stepName_Leshan_getClientFromResponse_intoVar, refers(f_IOT_LGen_step_Leshan_getClientFromResponse_intoVar)});
// Common
f_EPTF_LGenBase_declareStep(c_IOT_behaviorType, {c_IOT_stepName_tcFinished_withVerdict, refers(f_IOT_LGen_step_tcFinished_withVerdict)});
f_EPTF_LGenBase_declareStep(c_IOT_behaviorType, {c_IOT_stepName_print_stringParam, refers(f_IOT_LGen_step_print_stringParam)});
f_EPTF_LGenBase_declareStep(c_IOT_behaviorType, {c_IOT_stepName_genRndValue_varParams, refers(f_IOT_LGen_step_genRndValue_varParams)});
}
///////////////////////////////////////////////////////////
// Function: f_IOT_LGen_getEntityIdxinEntityGroup
//
// Purpose:
// Calculates the index of the entity inside its entity group
//
// Parameters:
// pl_ptr - *in* <EPTF_LGenBase_TestStepArgs> - test step parameters
///////////////////////////////////////////////////////////
function f_IOT_LGen_getEntityIdxinEntityGroup(in EPTF_LGenBase_TestStepArgs pl_ptr)
runs on IOT_LGen_CT
return integer
{
var integer vl_eGrpIdx := f_EPTF_LGenBase_getEGrpOfEntity(pl_ptr.eIdx);
var charstring vl_eGrpName := f_EPTF_LGenBase_entityGroupName(vl_eGrpIdx);
var integer vl_eRelIdxInEGrp :=
f_EPTF_ExecCtrlClient_getFirstEntityOffsetInEGrp(vl_eGrpName) +
f_EPTF_LGenBase_getERelIdx(pl_ptr.eIdx);
//action("========================");
//action("f_EPTF_ExecCtrlClient_getEntityGroupSize: ", f_EPTF_ExecCtrlClient_getEntityGroupSize(eGrpName));
//action("f_EPTF_ExecCtrlClient_getFirstEntityGlobalOffset: ", f_EPTF_ExecCtrlClient_getFirstEntityGlobalOffset(eGrpName));
//action("f_EPTF_ExecCtrlClient_getEntityGroupGlobalOffset: ", f_EPTF_ExecCtrlClient_getEntityGroupGlobalOffset(eGrpName));
//action("f_EPTF_ExecCtrlClient_getFirstEntityOffsetInEGrp: ", f_EPTF_ExecCtrlClient_getFirstEntityOffsetInEGrp(eGrpName));
//action("f_EPTF_LGenBase_getERelIdx(pl_ptr.eIdx): ", f_EPTF_LGenBase_getERelIdx(pl_ptr.eIdx));
//action("eIdx: ", pl_ptr.eIdx);
return vl_eRelIdxInEGrp;
}
///////////////////////////////////////////////////////////
// Function: f_IOT_LGen_step_COAP_setLocalAddress_byVars
//
// Purpose:
// Test step to set the local address in the COAP entity context <COAP_EntityCtx>. Parameters are required.
// The function will take the base port number from the parameters and adds the entity's offset
// inside its entity group (or in case the 3rd parameter is present, then the value found there)
// to get its assigned port number.
//
// Parameters:
// pl_ptr - *in* <EPTF_LGenBase_TestStepArgs> - test step args
// contextArgs.varNames[0] - *charstring variable* - local host
// contextArgs.varNames[1] - *integer variable* - local port
// contextArgs.varNames[2] - *integer variable* - offset [optional]
//
// Related Constants:
// - <c_IOT_stepName_COAP_setLocalAddress_byVars>
///////////////////////////////////////////////////////////
function f_IOT_LGen_step_COAP_setLocalAddress_byVars(in EPTF_LGenBase_TestStepArgs pl_ptr)
runs on IOT_LGen_CT
{
// 1st param: localHost: charstring
// 2nd param: localPort: integer
// 3rd param: offset: integer
f_EPTF_COAP_Logging_DEBUG(log2str(%definitionId, pl_ptr));
if (not f_EPTF_COAP_setStepCtx(pl_ptr, v_COAP_ctx)) { return; }
var integer vl_eRelIdxInEGrp := f_IOT_LGen_getEntityIdxinEntityGroup(pl_ptr);
var EPTF_IntegerList vl_varIds := {};
f_EPTF_LGenBase_fsmVarIdListFromStep(pl_ptr, vl_varIds);
if (sizeof(vl_varIds)>=2)
{
var EPTF_Var_DirectContent vl_host, vl_port, vl_offset;
f_EPTF_Var_getContent(vl_varIds[0], vl_host);
f_EPTF_Var_getContent(vl_varIds[1], vl_port);
if (sizeof(vl_varIds)==3) { f_EPTF_Var_getContent(vl_varIds[2], vl_offset); }
else { vl_offset.intVal := vl_eRelIdxInEGrp; }
if (not ischosen(vl_host.charstringVal)) {
f_EPTF_COAP_Logging_WARNING(log2str(%definitionId, " first param is not charstring variable!"));
return;
}
if (not ischosen(vl_port.intVal)) {
f_EPTF_COAP_Logging_WARNING(log2str(%definitionId, " second param is not integer variable!"));
return;
}
if (not ischosen(vl_offset.intVal)) {
f_EPTF_COAP_Logging_WARNING(log2str(%definitionId, " third param is not integer variable!"));
return;
}
var integer vl_localPort := vl_port.intVal + vl_offset.intVal;
f_EPTF_COAP_Logging_VERBOSE(log2str(%definitionId, " calculated local port ",vl_localPort));
if (vl_localPort < 65535)
{
f_EPTF_COAP_transportEndpointDB_add(
{
socket := {
hostName := vl_host.charstringVal,
portNumber := vl_localPort
},
proto := { udp := {} }
},
v_COAP_EntityCtxDB.data[v_COAP_ctx.eCtxIdx].localAddressIdx
);
}
else {
f_EPTF_COAP_Logging_WARNING(log2str(%definitionId, " calculated local port ",vl_localPort," would be larger than 65536! step aborted."));
}
}
else {
f_EPTF_COAP_Logging_WARNING(log2str(%definitionId, " at least two variables are needed as params!"));
}
}
///////////////////////////////////////////////////////////
// Function: f_IOT_LGen_step_MQTT_setLocalAddress_byVars
//
// Purpose:
// Test step to set the local address in the MQTT entity context. Parameters are required.
// The function will take the base port number from the parameters and adds the entity's offset
// inside its entity group (or in case the 3rd parameter is present, then the value found there)
// to get its assigned port number.
//
// Parameters:
// pl_ptr - *in* <EPTF_LGenBase_TestStepArgs> - test step args
// contextArgs.varNames[0] - *charstring variable* - local host
// contextArgs.varNames[1] - *integer variable* - local port
// contextArgs.varNames[2] - *integer variable* - offset [optional]
//
// Related Constants:
// - <c_IOT_stepName_MQTT_setLocalAddress_byVars>
///////////////////////////////////////////////////////////
function f_IOT_LGen_step_MQTT_setLocalAddress_byVars(in EPTF_LGenBase_TestStepArgs pl_ptr)
runs on IOT_LGen_CT
{
// 1st param: localHost: charstring
// 2nd param: localPort: integer
// 3rd param: offset: integer
f_EPTF_MQTT_Logging_DEBUG(log2str(%definitionId, pl_ptr));
if (not f_EPTF_MQTT_setStepCtx(pl_ptr, v_MQTT_ctx)) { return; }
var integer vl_eRelIdxInEGrp := f_IOT_LGen_getEntityIdxinEntityGroup(pl_ptr);
var EPTF_IntegerList vl_varIds := {};
f_EPTF_LGenBase_fsmVarIdListFromStep(pl_ptr, vl_varIds);
if (sizeof(vl_varIds)>=2)
{
var EPTF_Var_DirectContent vl_host, vl_port, vl_offset;
f_EPTF_Var_getContent(vl_varIds[0], vl_host);
f_EPTF_Var_getContent(vl_varIds[1], vl_port);
if (sizeof(vl_varIds)==3) { f_EPTF_Var_getContent(vl_varIds[2], vl_offset); }
else { vl_offset.intVal := vl_eRelIdxInEGrp; }
if (not ischosen(vl_host.charstringVal)) {
f_EPTF_MQTT_Logging_WARNING(log2str(%definitionId, " first param is not charstring variable!"));
return;
}
if (not ischosen(vl_port.intVal)) {
f_EPTF_MQTT_Logging_WARNING(log2str(%definitionId, " second param is not integer variable!"));
return;
}
if (not ischosen(vl_offset.intVal)) {
f_EPTF_MQTT_Logging_WARNING(log2str(%definitionId, " third param is not integer variable!"));
return;
}
var integer vl_localPort := vl_port.intVal + vl_offset.intVal;
f_EPTF_MQTT_Logging_VERBOSE(log2str(%definitionId, " calculated local port ",vl_localPort));
if (vl_localPort < 65535)
{
f_EPTF_MQTT_addressDB_add(
{
hostName := vl_host.charstringVal,
portNumber := vl_localPort
},
v_MQTT_sessionDB.data[v_MQTT_ctx.sessionIdx].localAddrIdx
);
}
else {
f_EPTF_MQTT_Logging_WARNING(log2str(%definitionId, " calculated local port ",vl_localPort," would be larger than 65536! step aborted."));
}
}
else {
f_EPTF_MQTT_Logging_WARNING(log2str(%definitionId, " at least two variables are needed as params!"));
}
}
///////////////////////////////////////////////////////////
// Function: f_IOT_LGen_step_MQTT_setClientId_stringParam
//
// Purpose:
// Test step to set the client id the MQTT entity context. Parameters are required.
// The function will take the entity's offset inside its entity group and concatenate it
// to the string parameter of the test step
//
// Parameters:
// pl_ptr - *in* <EPTF_LGenBase_TestStepArgs> - test step args
// contextArgs.charstringVal - *charstring* - base client id
//
// Related Constants:
// - <c_IOT_stepName_MQTT_setClientId_stringParam>
///////////////////////////////////////////////////////////
function f_IOT_LGen_step_MQTT_setClientId_stringParam(in EPTF_LGenBase_TestStepArgs pl_ptr)
runs on IOT_LGen_CT
{
f_EPTF_MQTT_Logging_DEBUG(log2str(%definitionId));
if (not f_EPTF_MQTT_setStepCtx(pl_ptr, v_MQTT_ctx)) { return; }
var charstring vl_clientId := f_EPTF_LGenBase_charstringValOfStep(pl_ptr);
var integer vl_eRelIdxInEGrp := f_IOT_LGen_getEntityIdxinEntityGroup(pl_ptr);
v_MQTT_sessionDB.data[v_MQTT_ctx.sessionIdx].clientId := vl_clientId & int2str(vl_eRelIdxInEGrp);
}
///////////////////////////////////////////////////////////
// Function: f_IOT_LGen_step_LwM2M_setClientNameInRegister
//
// Purpose:
// Test step to set the endpoint client name in the LWM2M Register message
// that must be previously loaded into *v_LwM2M_msgToSend*. The test step
// currently hard codes the base name to "eantwuhDev_" and concatenates the entity's index
// inside its entity group
//
// Parameters:
// pl_ptr - *in* <EPTF_LGenBase_TestStepArgs> - test step args
//
// Related Constants:
// - <c_IOT_stepName_LwM2M_setClientNameInRegister>
//
// Related test steps:
// - <f_COAP_step_loadTemplate_byStringId>
///////////////////////////////////////////////////////////
function f_IOT_LGen_step_LwM2M_setClientNameInRegister(in EPTF_LGenBase_TestStepArgs pl_ptr)
runs on IOT_LGen_CT
{
f_EPTF_LwM2M_Logging_DEBUG(log2str(%definitionId));
var integer vl_eRelIdxInEGrp := f_IOT_LGen_getEntityIdxinEntityGroup(pl_ptr);
v_LwM2M_msgToSend.pdu.Register.endpointClientName := "eantwuhDev_" & int2str(vl_eRelIdxInEGrp);
}
///////////////////////////////////////////////////////////
// Function: f_IOT_LGen_step_LwM2M_setClientNameInRegister_stringVar
//
// Purpose:
// Test step to set the endpoint client name in the LWM2M Register message
// that must be previously loaded into *v_LwM2M_msgToSend*. The test step
// expects the base name to be passed as a string parameter and concatenates the entity's index
// inside its entity group
//
// Parameters:
// pl_ptr - *in* <EPTF_LGenBase_TestStepArgs> - test step args
// contextArgs.varNames[0] - *charstring variable* - base name
//
// Related Constants:
// - <c_IOT_stepName_LwM2M_setClientNameInRegister_stringVar>
//
// Related test steps:
// - <f_COAP_step_loadTemplate_byStringId>
///////////////////////////////////////////////////////////
function f_IOT_LGen_step_LwM2M_setClientNameInRegister_stringVar(in EPTF_LGenBase_TestStepArgs pl_ptr)
runs on IOT_LGen_CT
{
f_EPTF_LwM2M_Logging_DEBUG(log2str(%definitionId));
var EPTF_IntegerList vl_varIds := {};
f_EPTF_LGenBase_fsmVarIdListFromStep(pl_ptr, vl_varIds);
if (sizeof(vl_varIds)==1)
{
var EPTF_Var_DirectContent vl_endpoint;
f_EPTF_Var_getContent(vl_varIds[0], vl_endpoint);
if (not ischosen(vl_endpoint.charstringVal)) {
f_EPTF_COAP_Logging_WARNING(log2str(%definitionId, " first param is not charstring variable!"));
return;
}
var integer vl_eRelIdxInEGrp := f_IOT_LGen_getEntityIdxinEntityGroup(pl_ptr);
v_LwM2M_msgToSend.pdu.Register.endpointClientName := vl_endpoint.charstringVal & int2str(vl_eRelIdxInEGrp);
}
else {
f_EPTF_COAP_Logging_WARNING(log2str(%definitionId, " one variable (base name) is needed as parameter!"));
}
}
///////////////////////////////////////////////////////////
// Function: f_IOT_LGen_step_HTTP_initEntityContext
//
// Purpose:
// Test step to initialize the HTTP entity context by calling
// <f_EPTF_HTTP_setEntityContext>.
//
// Parameters:
// pl_ptr - *in* <EPTF_LGenBase_TestStepArgs> - test step args
//
// Related Constants:
// - <c_IOT_stepName_HTTP_initEntityContext>
///////////////////////////////////////////////////////////
function f_IOT_LGen_step_HTTP_initEntityContext(in EPTF_LGenBase_TestStepArgs pl_ptr)
runs on IOT_LGen_CT
{
f_EPTF_HTTP_setEntityContext(
pl_eIdx := pl_ptr.eIdx,
pl_method := "GET", pl_uri := "",
pl_version_major := 1, pl_version_minor := 1,
pl_headerlines := {{"Connection","Keep-Alive"}},
pl_connId := -1, //v_HTTP_portGroupConnectionHandle,
pl_authDetails := -,
pl_body := { charVal := "" });
}
///////////////////////////////////////////////////////////
// Function: f_IOT_LGen_step_HTTP_openConnection_byVars
//
// Purpose:
// Test step to open a TCP connection for HTTP. Requires parameters
//
// Parameters:
// pl_ptr - *in* <EPTF_LGenBase_TestStepArgs> - test step args
// contextArgs.varNames[0] - *charstring variable* - local host
// contextArgs.varNames[1] - *integer variable* - local port
// contextArgs.varNames[2] - *charstring variable* - remote host
// contextArgs.varNames[3] - *integer variable* - remote port
//
// Related Constants:
// - <c_IOT_stepName_HTTP_openConnection_byVars>
///////////////////////////////////////////////////////////
function f_IOT_LGen_step_HTTP_openConnection_byVars(in EPTF_LGenBase_TestStepArgs pl_ptr)
runs on IOT_LGen_CT
{
// 1st param: localHost: charstring
// 2nd param: localPort: integer
// 3rd param: remoteHost: charstring
// 4th param: remotePort: integer
f_EPTF_COAP_Logging_DEBUG(log2str(%definitionId, pl_ptr));
var integer vl_eRelIdxInEGrp := f_IOT_LGen_getEntityIdxinEntityGroup(pl_ptr);
var EPTF_IntegerList vl_varIds := {};
f_EPTF_LGenBase_fsmVarIdListFromStep(pl_ptr, vl_varIds);
if (sizeof(vl_varIds)==4)
{
var EPTF_Var_DirectContent vl_localHost, vl_localPort, vl_remoteHost, vl_remotePort;
f_EPTF_Var_getContent(vl_varIds[0], vl_localHost);
f_EPTF_Var_getContent(vl_varIds[1], vl_localPort);
f_EPTF_Var_getContent(vl_varIds[2], vl_remoteHost);
f_EPTF_Var_getContent(vl_varIds[3], vl_remotePort);
if (not ischosen(vl_localHost.charstringVal)) {
f_EPTF_COAP_Logging_WARNING(log2str(%definitionId, " first param is not charstring variable!"));
return;
}
if (not ischosen(vl_localPort.intVal)) {
f_EPTF_COAP_Logging_WARNING(log2str(%definitionId, " second param is not integer variable!"));
return;
}
if (not ischosen(vl_remoteHost.charstringVal)) {
f_EPTF_COAP_Logging_WARNING(log2str(%definitionId, " third param is not charstring variable!"));
return;
}
if (not ischosen(vl_remotePort.intVal)) {
f_EPTF_COAP_Logging_WARNING(log2str(%definitionId, " fourth param is not integer variable!"));
return;
}
var integer vl_clientPort := vl_localPort.intVal + vl_eRelIdxInEGrp;
f_EPTF_COAP_Logging_VERBOSE(log2str(%definitionId, " calculated local port ", vl_clientPort));
if (vl_clientPort < 65535)
{
var integer vl_portGroupId := f_EPTF_HTTP_LocalTransport_newPort({
name := "httpPort_"&int2str(vl_eRelIdxInEGrp),
localHostInformation := { vl_localHost.charstringVal, vl_clientPort},
remoteHostInformation := { vl_remoteHost.charstringVal, vl_remotePort.intVal},
instantConnOpen := true,
instantConnClose := false,
useSSL := false,
userFunctions := omit
});
f_EPTF_HTTP_setEntityContextConnectionId(pl_ptr.eIdx, vl_portGroupId);
}
else {
f_EPTF_COAP_Logging_WARNING(log2str(%definitionId, " calculated local port ",vl_clientPort," would be larger than 65536! step aborted."));
}
}
else {
f_EPTF_COAP_Logging_WARNING(log2str(%definitionId, " exactly 4 variables are needed as params!"));
}
}
///////////////////////////////////////////////////////////
// Function: f_IOT_LGen_step_HTTP_closeConnection
//
// Purpose:
// Test step to close an already opened TCP connection for HTTP
//
// Parameters:
// pl_ptr - *in* <EPTF_LGenBase_TestStepArgs> - test step args
//
// Related Constants:
// - <c_IOT_stepName_HTTP_closeConnection>
///////////////////////////////////////////////////////////
function f_IOT_LGen_step_HTTP_closeConnection(in EPTF_LGenBase_TestStepArgs pl_ptr)
runs on IOT_LGen_CT
{
f_EPTF_COAP_Logging_DEBUG(log2str(%definitionId, pl_ptr));
var integer vl_portGroupId := f_EPTF_HTTP_getEntityContextConnectionId(pl_ptr.eIdx);
f_EPTF_HTTP_LocalTransport_deletePort(vl_portGroupId);
}
///////////////////////////////////////////////////////////
// Function: f_IOT_LGen_step_HTTP_setUri_stringParam
//
// Purpose:
// Test step to set a string - specified as a parameter - to the HTTP request URI
// of the message to be sent
//
// Parameters:
// pl_ptr - *in* <EPTF_LGenBase_TestStepArgs> - test step args
// contextArgs.charstringVal - *charstring* - URI to be set
//
// Related Constants:
// - <c_IOT_stepName_HTTP_setUri_stringParam>
///////////////////////////////////////////////////////////
function f_IOT_LGen_step_HTTP_setUri_stringParam(in EPTF_LGenBase_TestStepArgs pl_ptr)
runs on IOT_LGen_CT
{
var charstring vl_param := f_EPTF_LGenBase_charstringValOfStep(pl_ptr);
f_EPTF_HTTP_setEntityContextURI(pl_ptr.eIdx, vl_param);
}
///////////////////////////////////////////////////////////
// Function: f_IOT_LGen_step_HTTP_addToUri_stringParam
//
// Purpose:
// Test step to add a string - specified as a parameter - to the HTTP request URI
// of the message to be sent
//
// Parameters:
// pl_ptr - *in* <EPTF_LGenBase_TestStepArgs> - test step args
// contextArgs.charstringVal - *charstring* - URI part to be concatenated
//
// Related Constants:
// - <c_IOT_stepName_HTTP_addToUri_stringParam>
///////////////////////////////////////////////////////////
function f_IOT_LGen_step_HTTP_addToUri_stringParam(in EPTF_LGenBase_TestStepArgs pl_ptr)
runs on IOT_LGen_CT
{
var charstring vl_param := f_EPTF_LGenBase_charstringValOfStep(pl_ptr);
var charstring vl_uri := f_EPTF_HTTP_getEntityContextURI(pl_ptr.eIdx);
f_EPTF_HTTP_setEntityContextURI(pl_ptr.eIdx, vl_uri & vl_param);
}
///////////////////////////////////////////////////////////
// Function: f_IOT_LGen_step_HTTP_addToUri_byVars
//
// Purpose:
// Test step to add a string - specified as variadic parameter - to the HTTP request URI
// of the message to be sent
//
// Parameters:
// pl_ptr - *in* <EPTF_LGenBase_TestStepArgs> - test step args
// contextArgs.varNames[*] - *charstring variable* - string to be added
//
// Related Constants:
// - <c_IOT_stepName_HTTP_addToUri_stringParam>
///////////////////////////////////////////////////////////
function f_IOT_LGen_step_HTTP_addToUri_byVars(in EPTF_LGenBase_TestStepArgs pl_ptr)
runs on IOT_LGen_CT
{
var EPTF_IntegerList vl_varIds := {};
f_EPTF_LGenBase_fsmVarIdListFromStep(pl_ptr, vl_varIds);
var EPTF_Var_DirectContent vl_var;
var charstring vl_vars := ""
for (var integer i:=0; i<sizeof(vl_varIds); i:=i+1) {
f_EPTF_Var_getContent(vl_varIds[i], vl_var);
if (ischosen(vl_var.charstringVal)) {
vl_vars := vl_vars & vl_var.charstringVal;
}
// Could handle charstring list as well
}
var charstring vl_uri := f_EPTF_HTTP_getEntityContextURI(pl_ptr.eIdx);
f_EPTF_HTTP_setEntityContextURI(pl_ptr.eIdx, vl_uri & vl_vars);
}
///////////////////////////////////////////////////////////
// Function: f_IOT_LGen_step_HTTP_setMethod_stringParam
//
// Purpose:
// Test step to set the method - specified as a string parameter - of the
// HTTP request to be sent
//
// Parameters:
// pl_ptr - *in* <EPTF_LGenBase_TestStepArgs> - test step args
// contextArgs.charstringVal - *charstring* - method to be set
//
// Related Constants:
// - <c_IOT_stepName_HTTP_setMethod_stringParam>
///////////////////////////////////////////////////////////
function f_IOT_LGen_step_HTTP_setMethod_stringParam(in EPTF_LGenBase_TestStepArgs pl_ptr)
runs on IOT_LGen_CT
{
var charstring vl_param := f_EPTF_LGenBase_charstringValOfStep(pl_ptr);
f_EPTF_HTTP_setEntityContextMethod(pl_ptr.eIdx, vl_param);
}
///////////////////////////////////////////////////////////
// Function: f_IOT_LGen_step_HTTP_addHostHeader_byVars
//
// Purpose:
// Test step to add a Host header to the HTTP messager to be sent. Requires parameters.
//
// Parameters:
// pl_ptr - *in* <EPTF_LGenBase_TestStepArgs> - test step args
// contextArgs.varNames[0] - *charstring variable* - host name
// contextArgs.varNames[1] - *integer variable* - port name
//
// Related Constants:
// - <c_IOT_stepName_HTTP_addHostHeader_byVars>
///////////////////////////////////////////////////////////
function f_IOT_LGen_step_HTTP_addHostHeader_byVars(in EPTF_LGenBase_TestStepArgs pl_ptr)
runs on IOT_LGen_CT
{
// 1st param: remoteHost: charstring
// 2nd param: remotePort: integer
//f_EPTF_HTTP_setEntityContextMethod(pl_ptr.eIdx, vl_param);
var EPTF_IntegerList vl_varIds := {};
f_EPTF_LGenBase_fsmVarIdListFromStep(pl_ptr, vl_varIds);
if (sizeof(vl_varIds)==2)
{
var EPTF_Var_DirectContent vl_host, vl_port;
f_EPTF_Var_getContent(vl_varIds[0], vl_host);
f_EPTF_Var_getContent(vl_varIds[1], vl_port);
if (not ischosen(vl_host.charstringVal)) {
f_EPTF_COAP_Logging_WARNING(log2str(%definitionId, " first param is not charstring variable!"));
return;
}
if (not ischosen(vl_port.intVal)) {
f_EPTF_COAP_Logging_WARNING(log2str(%definitionId, " second param is not integer variable!"));
return;
}
f_EPTF_HTTP_setEntityContextAddCustomHeader(pl_ptr.eIdx,
"Host",
vl_host.charstringVal & ":" & int2str(vl_port.intVal)
)
}
else {
f_EPTF_COAP_Logging_WARNING(log2str(%definitionId, " two variables are needed as params!"));
}
}
///////////////////////////////////////////////////////////
// Function: f_IOT_LGen_step_Leshan_getClientFromResponse_intoVar
//
// Purpose:
// Test step to fetch the client name of an HTTP response sent by Leshan
// into a variable
//
// Parameters:
// pl_ptr - *in* <EPTF_LGenBase_TestStepArgs> - test step args
// contextArgs.varNames[0] - *charstring variable* - client name will be loaded here
//
// Related Constants:
// - <c_IOT_stepName_Leshan_getClientFromResponse_intoVar>
///////////////////////////////////////////////////////////
function f_IOT_LGen_step_Leshan_getClientFromResponse_intoVar(in EPTF_LGenBase_TestStepArgs pl_ptr)
runs on IOT_LGen_CT
{
var EPTF_IntegerList vl_varIds := {};
f_EPTF_LGenBase_fsmVarIdListFromStep(pl_ptr, vl_varIds);
if (sizeof(vl_varIds)!=1) {
f_EPTF_COAP_Logging_WARNING(log2str(%definitionId, " one variable is needed!"));
return;
}
//action("HTTP resp: ", v_EPTF_HTTP_incomingMessage,"\n");
var JSON_PDU vl_json := dec_JSON(char2oct(v_EPTF_HTTP_incomingMessage.response.body));
//action("JSON resp:" , vl_json,"\n");
var EPTF_CharstringList vl_clients := {};
// Let's fetch the first
if (ischosen(vl_json.json_array) and sizeof(vl_json.json_array)>0) {
if (ischosen(vl_json.json_array[0].json_object)) {
for (var integer valIdx :=0; valIdx<sizeof(vl_json.json_array[0].json_object); valIdx:=valIdx+1) {
if (vl_json.json_array[0].json_object[valIdx].json_name == "endpoint") {
vl_clients[sizeof(vl_clients)] := unichar2char(vl_json.json_array[0].json_object[valIdx].json_value.json_string);
break;
}
}
}
}
/*
if (ischosen(vl_json.json_array)) {
for (var integer objIdx:=0; objIdx<sizeof(vl_json.json_array); objIdx:=objIdx+1) {
if (ischosen(vl_json.json_array[objIdx].json_object)) {
for (var integer valIdx :=0; valIdx<sizeof(vl_json.json_array[objIdx].json_object); valIdx:=valIdx+1) {
if (vl_json.json_array[objIdx].json_object[valIdx].json_name == "endpoint") {
vl_clients[sizeof(vl_clients)] := vl_json.json_array[objIdx].json_object[valIdx].json_value.json_string;
break;
}
}
}
}
}
*/
/*
JSON resp:=
{
json_array :=
{
{
json_object :=
{
{ json_name := "endpoint", json_value := { json_string := "client_0" } },
{ json_name := "registrationId", json_value := { json_string := "V18qVv4RL8" } },
{ json_name := "registrationDate", json_value := { json_string := "2017-02-01T14:20:39+01:00" } },
{ json_name := "lastUpdate", json_value := { json_string := "2017-02-01T14:20:39+01:00" } },
{ json_name := "address", json_value := { json_string := "127.0.0.1:30000" } },
{ json_name := "lwM2mVersion", json_value := { json_string := "1.0" } },
{ json_name := "lifetime", json_value := { json_number := 30 } },
{ json_name := "bindingMode", json_value := { json_string := "U" } },
{ json_name := "rootPath", json_value := { json_string := "/" } },
{ json_name := "objectLinks", json_value := {
json_array := {
{ json_object := {
{ json_name := "url", json_value := { json_string := "/3/0" } },
{ json_name := "attributes", json_value := { json_object := { } } }
} } }
}
},
{ json_name := "secure", json_value := { json_false := { } } },
{ json_name := "additionalRegistrationAttributes", json_value := { json_object := { } } }
}
}
}
}
*/
//action("clients: ", vl_clients,"\n");
if (sizeof(vl_clients)>0)
{
// Selecting and loading the last one:
//action("selected client: ", vl_clients[sizeof(vl_clients)-1],"\n");
f_EPTF_Var_setContent(vl_varIds[0], { charstringVal := vl_clients[0]});
}
}
///////////////////////////////////////////////////////////
// Function: f_IOT_LGen_step_tcFinished_withVerdict
//
// Purpose:
// Test step to set the final verdict reported by the FSM using a verdict variable as parameter.
//
// Parameters:
// pl_ptr - *in* <EPTF_LGenBase_TestStepArgs> - test step args
// contextArgs.verdict - *verdicttype* - verdict to be reported
//
// Related Constants:
// - <c_IOT_stepName_tcFinished_withVerdict>
///////////////////////////////////////////////////////////
function f_IOT_LGen_step_tcFinished_withVerdict(in EPTF_LGenBase_TestStepArgs pl_ptr)
runs on IOT_LGen_CT
{
var charstring vl_reason := "";
var verdicttype vl_verdict := pass;
var charstring vl_behavior := "behavior ["&f_EPTF_LGenBase_bIdx2Str(pl_ptr.reportedEvent.event.bIdx)&"]";
var charstring vl_event := "event ["&
f_EPTF_LGenBase_iIdx2Str(
pl_ptr.reportedEvent.event.bIdx,
pl_ptr.reportedEvent.event.iIdx,
f_EPTF_LGenBase_getFsmIndexByCtxIdx(pl_ptr.eIdx, pl_ptr.refContext.fCtxIdx)
)&"]";
f_EPTF_LGenBase_verdictOfStep(pl_ptr, vl_verdict, vl_reason);
var charstring vl_state := "state ["&f_EPTF_LGenBase_getFsmStateNameByStepArgs(pl_ptr)&"]";
f_EPTF_LGenBase_step_cancelAllTimers(pl_ptr);
f_COAP_step_cleanUp(pl_ptr);
f_MQTT_step_cleanUp(pl_ptr);
f_LwM2M_step_cleanupDevice(pl_ptr);
if (vl_verdict == pass)
{
action("=> pass");
f_EPTF_LGenBase_step_trafficSuccess(pl_ptr);
}
else if (vl_verdict == fail)
{
action(vl_state); action(vl_behavior); action(vl_event);
action("=> fail");
f_EPTF_LGenBase_step_trafficFailed(pl_ptr);
}
else if (vl_verdict == inconc)
{
action(vl_state); action(vl_behavior); action(vl_event);
action("=> inconc");
f_EPTF_LGenBase_step_trafficTimeout(pl_ptr);
}
else if (vl_verdict == error)
{
action(vl_state); action(vl_behavior); action(vl_event);
action("=> error");
f_EPTF_LGenBase_step_trafficError(pl_ptr);
}
}
///////////////////////////////////////////////////////////
// Function: f_IOT_LGen_step_print_stringParam
//
// Purpose:
// Test step to print a string parameter as a TTCN-3 action() statement
//
// Parameters:
// pl_ptr - *in* <EPTF_LGenBase_TestStepArgs> - test step args
// contextArgs.charstringVal - *charstring* - the string to be printed
//
// Related Constants:
// - <c_IOT_stepName_print_stringParam>
///////////////////////////////////////////////////////////
function f_IOT_LGen_step_print_stringParam(in EPTF_LGenBase_TestStepArgs pl_ptr)
runs on IOT_LGen_CT
{
f_EPTF_MQTT_Logging_DEBUG(log2str(%definitionId));
var charstring vl_toPrint := f_EPTF_LGenBase_charstringValOfStep(pl_ptr);
action(vl_toPrint);
}
///////////////////////////////////////////////////////////
// Function: f_IOT_LGen_step_FSM_RegDereg_initResourceValues
//
// Purpose:
// Test step to init resources of the RegDereg FSM
//
// Parameters:
// pl_ptr - *in* <EPTF_LGenBase_TestStepArgs> - test step args
//
// Related Constants:
// - <c_IOT_stepName_FSM_RegDereg_initResourceValues>
///////////////////////////////////////////////////////////
function f_IOT_LGen_step_FSM_RegDereg_initResourceValues(in EPTF_LGenBase_TestStepArgs pl_ptr)
runs on IOT_LGen_CT
{
f_EPTF_LwM2M_Logging_DEBUG(log2str(%definitionId));
f_EPTF_LwM2M_setStepCtx(pl_ptr, v_LwM2M_ctx);
if (v_LwM2M_ctx.deviceIdx >= 0)
{
f_LwM2M_ObjectDB_setResourceValue(
p_db := v_LwM2M_DeviceDB.data[v_LwM2M_ctx.deviceIdx].objects,
p_objId := c_LwM2M_Device_obj_id, p_objInstId := 0, p_resourceId := c_LwM2M_Device_Manufacturer,
p_value := { strValue := "TitanSim" }
);
}
}
///////////////////////////////////////////////////////////
// Function: f_IOT_LGen_step_FSM_SimDevice_createResources
//
// Purpose:
// Test step to create resources of the SimDevice FSM
//
// Parameters:
// pl_ptr - *in* <EPTF_LGenBase_TestStepArgs> - test step args
//
// Related Constants:
// - <c_IOT_stepName_FSM_SimDevice_createResources>
///////////////////////////////////////////////////////////
function f_IOT_LGen_step_FSM_SimDevice_createResources(in EPTF_LGenBase_TestStepArgs pl_ptr)
runs on IOT_LGen_CT
{
}
///////////////////////////////////////////////////////////
// Function: f_IOT_LGen_step_FSM_SimDevice_initTransport_boolVar
//
// Purpose:
// Test step to initialize the COAP transport (either UDP, or DTLS-PSK)
// of the SimDevice FSM. Requires parameter.
//
// Parameters:
// pl_ptr - *in* <EPTF_LGenBase_TestStepArgs> - test step args
// contextArgs.varNames[0] - *boolean variable* - will use DTLS-PSK when true, UDP otherwise
//
// Related Constants:
// - <c_IOT_stepName_FSM_SimDevice_initTransport_boolVar>
///////////////////////////////////////////////////////////
function f_IOT_LGen_step_FSM_SimDevice_initTransport_boolVar(in EPTF_LGenBase_TestStepArgs pl_ptr)
runs on IOT_LGen_CT
{
f_EPTF_COAP_Logging_DEBUG(log2str(%definitionId));
if (not f_EPTF_COAP_setStepCtx(pl_ptr, v_COAP_ctx)) { return; }
var EPTF_IntegerList vl_varIds := {};
f_EPTF_LGenBase_fsmVarIdListFromStep(pl_ptr, vl_varIds);
if (sizeof(vl_varIds)==1)
{
var EPTF_Var_DirectContent vl_dtlsOn;
f_EPTF_Var_getContent(vl_varIds[0], vl_dtlsOn);
if (not ischosen(vl_dtlsOn.boolVal)) {
f_EPTF_COAP_Logging_WARNING(log2str(%definitionId, " first param is not boolean variable!"));
return;
}
// If we have to use DTLS
if (vl_dtlsOn.boolVal == true)
{
// We need to adjust the local and remote protocol to dtls
if (v_COAP_FsmCtxDB.data[v_COAP_ctx.fsmCtxIdx].remoteAddressIdx >= 0)
{
v_COAP_transportEndpointDB.data[v_COAP_EntityCtxDB.data[v_COAP_ctx.eCtxIdx].localAddressIdx].proto :=
{ dtls := { udp := {} }};
v_COAP_transportEndpointDB.data[v_COAP_FsmCtxDB.data[v_COAP_ctx.fsmCtxIdx].remoteAddressIdx].proto :=
{ dtls := { udp := {} }};
}
// We also need to initialize the DTLS connection:
// - we need to set the identity and the keys first into the fsmCtx
// we will use the tsp_EPTF_COAP_LGen_psks module par as a base and add the entity index inside the group to create the identity
if (sizeof(tsp_EPTF_COAP_LGen_psks) >= 1)
{
var integer vl_eRelIdxInEGrp := f_IOT_LGen_getEntityIdxinEntityGroup(pl_ptr);
v_COAP_FsmCtxDB.data[v_COAP_ctx.fsmCtxIdx].psk.identity := tsp_EPTF_COAP_LGen_psks[0].identity & int2str(vl_eRelIdxInEGrp);
v_COAP_FsmCtxDB.data[v_COAP_ctx.fsmCtxIdx].psk.key := tsp_EPTF_COAP_LGen_psks[0].key;
f_COAP_step_startDTLS(pl_ptr);
}
else {
f_EPTF_COAP_Logging_WARNING(log2str(%definitionId, " we want to use the first item in tsp_EPTF_COAP_LGen_psks to generate the identity and key!"));
}
}
// If we use plain UDP
else
{
f_COAP_step_startListening(pl_ptr);
}
}
else {
f_EPTF_COAP_Logging_WARNING(log2str(%definitionId, " one variable (useDTLS) is needed as parameter!"));
}
}
///////////////////////////////////////////////////////////
// Function: f_IOT_LGen_step_FSM_SimDevice_initResourceValues
//
// Purpose:
// Test step to init the resource values of the SimDevice FSM
//
// Parameters:
// pl_ptr - *in* <EPTF_LGenBase_TestStepArgs> - test step args
//
// Related Constants:
// - <c_IOT_stepName_FSM_SimDevice_initResourceValues>
///////////////////////////////////////////////////////////
function f_IOT_LGen_step_FSM_SimDevice_initResourceValues(in EPTF_LGenBase_TestStepArgs pl_ptr)
runs on IOT_LGen_CT
{
f_EPTF_LwM2M_Logging_DEBUG(log2str(%definitionId));
f_EPTF_LwM2M_setStepCtx(pl_ptr, v_LwM2M_ctx);
if (v_LwM2M_ctx.deviceIdx >= 0)
{
var LwM2M_Resource v_res;
// Manufacturer
f_LwM2M_ObjectDB_setResourceValue(
p_db := v_LwM2M_DeviceDB.data[v_LwM2M_ctx.deviceIdx].objects,
p_objId := c_LwM2M_Device_obj_id, p_objInstId := 0, p_resourceId := c_LwM2M_Device_Manufacturer,
p_value := { strValue := "RIoT" }
);
// Latitude
f_LwM2M_ObjectDB_getResource(
p_db := v_LwM2M_DeviceDB.data[v_LwM2M_ctx.deviceIdx].objects,
p_objId := 6, p_objInstId := 0, p_resourceId := 0,
p_resource := v_res
);
v_res.dataSample := {
samplesName := "Latitude",
samplesPointer := -1,
valuePointer := -1
}
f_LwM2M_Resource_setNextDataSample(v_res, v_IOT_LGen_DataSamples_DB);
f_LwM2M_ObjectDB_setResource(
p_db := v_LwM2M_DeviceDB.data[v_LwM2M_ctx.deviceIdx].objects,
p_objId := 6, p_objInstId := 0, p_resourceId := 0,
p_resource := v_res
);
/* f_LwM2M_ObjectDB_setResourceValue(
p_db := v_LwM2M_DeviceDB.data[v_LwM2M_ctx.deviceIdx].objects,
p_objId := 6, p_objInstId := 0, p_resourceId := 0,
p_value := { floatValue := 47.475096 }
);*/
//Longitude
f_LwM2M_ObjectDB_getResource(
p_db := v_LwM2M_DeviceDB.data[v_LwM2M_ctx.deviceIdx].objects,
p_objId := 6, p_objInstId := 0, p_resourceId := 1,
p_resource := v_res
);
v_res.dataSample := {
samplesName := "Longitude",
samplesPointer := -1,
valuePointer := -1
}
f_LwM2M_Resource_setNextDataSample(v_res, v_IOT_LGen_DataSamples_DB);
f_LwM2M_ObjectDB_setResource(
p_db := v_LwM2M_DeviceDB.data[v_LwM2M_ctx.deviceIdx].objects,
p_objId := 6, p_objInstId := 0, p_resourceId := 1,
p_resource := v_res
);
/*f_LwM2M_ObjectDB_setResourceValue(
p_db := v_LwM2M_DeviceDB.data[v_LwM2M_ctx.deviceIdx].objects,
p_objId := 6, p_objInstId := 0, p_resourceId := 1,
p_value := { floatValue := 19.057871 }
);*/
// Altitude
f_LwM2M_ObjectDB_setResourceValue(
p_db := v_LwM2M_DeviceDB.data[v_LwM2M_ctx.deviceIdx].objects,
p_objId := 6, p_objInstId := 0, p_resourceId := 2,
p_value := { floatValue := 12.0 }
);
// Temperature
f_LwM2M_ObjectDB_setResourceValue(
p_db := v_LwM2M_DeviceDB.data[v_LwM2M_ctx.deviceIdx].objects,
p_objId := 3303, p_objInstId := 0, p_resourceId := 5700,
p_value := { floatValue := 34.35 }
);
// Dropped
f_LwM2M_ObjectDB_setResourceValue(
p_db := v_LwM2M_DeviceDB.data[v_LwM2M_ctx.deviceIdx].objects,
p_objId := 3400, p_objInstId := 0, p_resourceId := 1,
p_value := { boolValue := false }
);
}
}
///////////////////////////////////////////////////////////
// Function: f_IOT_LGen_step_FSM_SimDevice_updateResourceValues
//
// Purpose:
// Test step to update the resource values of the SimDevice FSM
//
// Parameters:
// pl_ptr - *in* <EPTF_LGenBase_TestStepArgs> - test step args
//
// Related Constants:
// - <c_IOT_stepName_FSM_SimDevice_updateResourceValues>
///////////////////////////////////////////////////////////
function f_IOT_LGen_step_FSM_SimDevice_updateResourceValues(in EPTF_LGenBase_TestStepArgs pl_ptr)
runs on IOT_LGen_CT
{
f_EPTF_LwM2M_Logging_DEBUG(log2str(%definitionId));
f_EPTF_LwM2M_setStepCtx(pl_ptr, v_LwM2M_ctx);
var LwM2M_Resource v_res;
//////////////////
// Dropped
if(
f_LwM2M_ObjectDB_getResource(
p_db := v_LwM2M_DeviceDB.data[v_LwM2M_ctx.deviceIdx].objects,
p_objId := 3400, p_objInstId := 0, p_resourceId := 1,
p_resource := v_res
)
){
var boolean droppableChanged := false;
if (v_res.val.boolValue) {
v_res.val.boolValue := false;
droppableChanged := true;
action("Drop cleared")
}
else {
var float v_rnd := rnd();
if (v_rnd>=0.5) {
v_res.val.boolValue := true;
droppableChanged := true;
action("Dropped: ",v_rnd);
}
}
if (droppableChanged)
{
f_LwM2M_ObjectDB_setResource(
p_db := v_LwM2M_DeviceDB.data[v_LwM2M_ctx.deviceIdx].objects,
p_objId := 3400, p_objInstId := 0, p_resourceId := 1,
p_resource := v_res
);
f_EPTF_LwM2M_sendNotificationForResource(pl_ptr, v_res);
}
}
//////////////////
// Temperature
if (
f_LwM2M_ObjectDB_getResource(
p_db := v_LwM2M_DeviceDB.data[v_LwM2M_ctx.deviceIdx].objects,
p_objId := 3303, p_objInstId := 0, p_resourceId := 5700,
p_resource := v_res //{ floatValue := int2float(vl_randomVal) }
)
){
v_res.val.floatValue := int2float(32 - 10 +1)*rnd() + 10.0;
f_LwM2M_ObjectDB_setResource(
p_db := v_LwM2M_DeviceDB.data[v_LwM2M_ctx.deviceIdx].objects,
p_objId := 3303, p_objInstId := 0, p_resourceId := 5700,
p_resource := v_res
);
f_EPTF_LwM2M_sendNotificationForResource(pl_ptr, v_res);
}
//////////////////
// Latitude
if (
f_LwM2M_ObjectDB_getResource(
p_db := v_LwM2M_DeviceDB.data[v_LwM2M_ctx.deviceIdx].objects,
p_objId := 6, p_objInstId := 0, p_resourceId := 0,
p_resource := v_res
)
){
f_LwM2M_Resource_setNextDataSample(v_res, v_IOT_LGen_DataSamples_DB);
f_LwM2M_ObjectDB_setResource(
p_db := v_LwM2M_DeviceDB.data[v_LwM2M_ctx.deviceIdx].objects,
p_objId := 6, p_objInstId := 0, p_resourceId := 0,
p_resource := v_res
);
f_EPTF_LwM2M_sendNotificationForResource(pl_ptr, v_res);
}
//////////////////
// Longitude
if (
f_LwM2M_ObjectDB_getResource(
p_db := v_LwM2M_DeviceDB.data[v_LwM2M_ctx.deviceIdx].objects,
p_objId := 6, p_objInstId := 0, p_resourceId := 1,
p_resource := v_res
)
){
f_LwM2M_Resource_setNextDataSample(v_res, v_IOT_LGen_DataSamples_DB);
f_LwM2M_ObjectDB_setResource(
p_db := v_LwM2M_DeviceDB.data[v_LwM2M_ctx.deviceIdx].objects,
p_objId := 6, p_objInstId := 0, p_resourceId := 1,
p_resource := v_res
);
f_EPTF_LwM2M_sendNotificationForResource(pl_ptr, v_res);
}
}
///////////////////////////////////////////////////////////
// Function: f_IOT_LGen_step_FSM_SimDevice_handleExecute
//
// Purpose:
// Test step to handle incoming LwM2M EXECUTE request in
// the SimDevice FSM
//
// Parameters:
// pl_ptr - *in* <EPTF_LGenBase_TestStepArgs> - test step args
//
// Related Constants:
// - <c_IOT_stepName_FSM_SimDevice_handleExecute>
///////////////////////////////////////////////////////////
function f_IOT_LGen_step_FSM_SimDevice_handleExecute(in EPTF_LGenBase_TestStepArgs pl_ptr)
runs on IOT_LGen_CT
{
f_EPTF_LwM2M_Logging_DEBUG(log2str(%definitionId));
f_EPTF_LwM2M_setStepCtx(pl_ptr, v_LwM2M_ctx);
if (ischosen(v_LwM2M_msgToProcess.pdu.Execute) and v_LwM2M_ctx.deviceIdx >= 0)
{
var LwM2M_Resource v_res;
var boolean vl_found := false;
if (f_LwM2M_ObjectPath_isResource(v_LwM2M_msgToProcess.pdu.Execute.path))
{
f_EPTF_LwM2M_Logging_DEBUG(log2str(%definitionId, " Looking up resource"));
vl_found := f_LwM2M_ObjectDB_getResource(
v_LwM2M_DeviceDB.data[v_LwM2M_ctx.deviceIdx].objects,
v_LwM2M_msgToProcess.pdu.Execute.path.objectId,
v_LwM2M_msgToProcess.pdu.Execute.path.objectInstanceId,
v_LwM2M_msgToProcess.pdu.Execute.path.resourceId,
v_res
);
f_EPTF_LwM2M_Logging_DEBUG(log2str(%definitionId, " resource found: ", v_res));
action("executed: ", v_res);
v_LwM2M_msgToSend.eIdx := v_LwM2M_ctx.eIdx;
v_LwM2M_msgToSend.fsmIdx := v_LwM2M_ctx.fsmIdx;
v_LwM2M_msgToSend.pdu :=
{
Response := {
location := {},
code := 204,
contentFormat := omit,
resources := {}
}
}
vf_EPTF_LwM2M_Transport_send.apply(v_LwM2M_msgToSend);
}
else { f_EPTF_LwM2M_Logging_DEBUG(log2str(%definitionId, " Only resource can be executed, ignoring request")); }
}
else { f_EPTF_LwM2M_Logging_DEBUG(log2str(%definitionId, " not execute pdu, or no device available, returning")); }
}
///////////////////////////////////////////////////////////
// Function: f_IOT_LGen_step_genRndValue_varParams
//
// Purpose:
// Test step to generate a random number and load it into an integer variable.
// The generated random number will be between two integers provided as parameters
// to set the limits for RNG.
//
// Parameters:
// pl_ptr - *in* <EPTF_LGenBase_TestStepArgs> - test step args
// contextArgs.varNames[0] - *in integer variable* - min value
// contextArgs.varNames[1] - *in integer variable* - max value
// contextArgs.varNames[2] - *out integer variable* - generated value
//
// Related Constants:
// - <c_IOT_stepName_FSM_SimDevice_genRndValue_varParams>
///////////////////////////////////////////////////////////
function f_IOT_LGen_step_genRndValue_varParams(in EPTF_LGenBase_TestStepArgs pl_ptr)
runs on IOT_LGen_CT
{
// 1st param: min value (in): integer
// 2nd param: max value (in): integer
// 3rd param: rnd value (out): integer
f_EPTF_COAP_Logging_DEBUG(log2str(%definitionId, pl_ptr));
var EPTF_IntegerList vl_varIds := {};
f_EPTF_LGenBase_fsmVarIdListFromStep(pl_ptr, vl_varIds);
if (sizeof(vl_varIds)==3)
{
var EPTF_Var_DirectContent vl_min, vl_max, vl_rnd;
f_EPTF_Var_getContent(vl_varIds[0], vl_min);
f_EPTF_Var_getContent(vl_varIds[1], vl_max);
f_EPTF_Var_getContent(vl_varIds[2], vl_rnd);
if (not ischosen(vl_min.intVal)) {
f_EPTF_COAP_Logging_WARNING(log2str(%definitionId, " first param is not integer variable!"));
return;
}
if (not ischosen(vl_max.intVal)) {
f_EPTF_COAP_Logging_WARNING(log2str(%definitionId, " second param is not integer variable!"));
return;
}
var integer vl_randomVal := float2int(int2float(vl_max.intVal - vl_min.intVal +1)*rnd()) + vl_min.intVal;
f_EPTF_COAP_Logging_VERBOSE(log2str(%definitionId, " calculated random value ",vl_randomVal));
f_EPTF_Var_setContent(vl_varIds[2], { intVal := vl_randomVal });
}
else {
f_EPTF_COAP_Logging_WARNING(log2str(%definitionId, " at least three variables are needed as params!"));
}
}
}
// contextArgs.varNames[0] - *in variable* - min value