blob: 399b3326fbe07f86bb73218da79e986fc61c80e0 [file] [log] [blame]
///////////////////////////////////////////////////////////////////////////////
//
// Copyright (c) 2000-2017 Ericsson Telecom AB
//
// All rights reserved. This program and the accompanying materials
// are made available under the terms of the Eclipse Public License v1.0
// which accompanies this distribution, and is available at
// http://www.eclipse.org/legal/epl-v10.html
///////////////////////////////////////////////////////////////////////////////
// File: EPTF_LwM2M_LGen_Functions.ttcn
// Description:
// Rev: R1A
// Prodnr: CNL 113 859
// Updated: 2017-09-01
// Contact: http://ttcn.ericsson.se
///////////////////////////////////////////////////////////////////////////////
module EPTF_LwM2M_LGen_Functions
{
import from EPTF_LwM2M_LGen_Definitions all;
import from EPTF_LwM2M_Object_Definitions all;
import from EPTF_LwM2M_Object_Functions all;
import from EPTF_LwM2M_Transport_Definitions all;
import from LightweightM2M_Types all;
import from EPTF_CLL_Base_Functions all;
import from EPTF_CLL_Common_Definitions all;
import from EPTF_CLL_LGenBase_Definitions all;
import from EPTF_CLL_LGenBase_ConfigFunctions all;
import from EPTF_CLL_LGenBase_Functions all;
import from EPTF_CLL_LGenBase_EventHandlingFunctions all;
import from EPTF_CLL_Logging_Definitions all;
import from EPTF_CLL_Logging_Functions all;
import from EPTF_CLL_FBQ_Functions all;
import from EPTF_CLL_HashMapStr2Int_Functions all;
import from EPTF_CLL_HashMapOct2Int_Functions all;
import from EPTF_CLL_RBTScheduler_Functions all;
function f_EPTF_LwM2M_LGen_init(in charstring pl_name)
runs on EPTF_LwM2M_LGen_CT
{
if (v_LwM2M_initialized){return;}
f_EPTF_LGenBase_init(pl_name, 0, pl_name);
f_EPTF_Logging_init_CT(pl_name);
f_EPTF_str2int_HashMap_Init();
f_EPTF_oct2int_HashMap_Init();
v_LwM2M_bIdx := f_EPTF_LGenBase_declareBehaviorType(
c_LwM2M_behaviorType,
tsp_EPTF_LwM2M_LGen_maxBindableCtx,
refers(f_LwM2M_eCtxReset),
refers(f_LwM2M_eCtxBind),
refers(f_LwM2M_eCtxUnbind)
);
v_LwM2M_loggingMaskId :=
f_EPTF_Logging_registerComponentMasks(
"LwM2M_Logging",
{"WARNING", "DEBUG", "3xx", "4xx", "5xx", "6xx", "3xxTo6xx"},
EPTF_Logging_CLL);
f_EPTF_LwM2M_Logging_DEBUG(log2str(%definitionId,": my behavior idx is ", v_LwM2M_bIdx));
f_LwM2M_ObjectSpecificationDB_init(v_LwM2M_ObjectSpecificationDB, 0);
f_EPTF_LwM2M_EntityCtxDB_init();
f_EPTF_LwM2M_DeviceDB_init();
f_EPTF_LwM2M_TemplateDB_init();
f_EPTF_LwM2M_declareSteps();
f_EPTF_LwM2M_declareEvents();
f_LwM2M_ObjectSpecificationDB_fillInOmaSpecs(v_LwM2M_ObjectSpecificationDB);
f_EPTF_Base_registerCleanup(refers(f_LwM2M_cleanUp));
v_LwM2M_initialized := true;
}
function f_EPTF_LwM2M_LGen_initLogging()
runs on EPTF_LwM2M_LGen_CT
{
f_EPTF_Logging_init_CT("LwM2M_LGen");
v_LwM2M_loggingMaskId :=
f_EPTF_Logging_registerComponentMasks(
"LwM2M_LGen_Logging",
{"WARNING", "DEBUG", "DEBUGV", "ERROR"},
EPTF_Logging_CLL
);
if(tsp_EPTF_LwM2M_LGen_debug){
f_EPTF_Logging_enableLocalMask(v_LwM2M_loggingMaskId, c_LwM2M_LGen_Logging_DEBUG);
}
else {
f_EPTF_Logging_disableLocalMask(v_LwM2M_loggingMaskId, c_LwM2M_LGen_Logging_DEBUG);
}
if(tsp_EPTF_LwM2M_LGen_debugVerbose) {
f_EPTF_Logging_enableLocalMask(v_LwM2M_loggingMaskId, c_LwM2M_LGen_Logging_DEBUGV);
}
else {
f_EPTF_Logging_disableLocalMask(v_LwM2M_loggingMaskId, c_LwM2M_LGen_Logging_DEBUGV);
}
}
function f_LwM2M_cleanUp()
runs on EPTF_LwM2M_LGen_CT
{
f_EPTF_LwM2M_EntityCtxDB_cleanUp();
f_EPTF_LwM2M_DeviceDB_cleanUp();
f_LwM2M_ObjectSpecificationDB_cleanUp(v_LwM2M_ObjectSpecificationDB);
f_EPTF_LwM2M_TemplateDB_cleanUp();
v_LwM2M_initialized := false;
}
function f_LwM2M_eCtxBind(in integer pl_eIdx)
runs on EPTF_LwM2M_LGen_CT
return EPTF_IntegerList
{
var integer vl_eCtxIdx := f_EPTF_FBQ_getOrCreateFreeSlot(v_LwM2M_EntityCtxDB.queue);
f_EPTF_FBQ_moveFromFreeHeadToBusyTail(v_LwM2M_EntityCtxDB.queue);
v_LwM2M_EntityCtxDB.data[vl_eCtxIdx] := c_LwM2M_EntityCtx_init;
v_LwM2M_EntityCtxDB.data[vl_eCtxIdx].eIdx := pl_eIdx;
return {vl_eCtxIdx};
}
function f_LwM2M_eCtxUnbind(in integer pl_eIdx)
runs on EPTF_LwM2M_LGen_CT
{
if (not v_LwM2M_initialized) {return;}
var integer vl_eCtxIdx:= f_EPTF_LGenBase_getBehaviorCtxItem(pl_eIdx, v_LwM2M_bIdx, 0);
f_EPTF_FBQ_moveFromBusyToFreeTail(vl_eCtxIdx, v_LwM2M_EntityCtxDB.queue);
}
function f_LwM2M_eCtxReset(in integer pl_eIdx)
runs on EPTF_LwM2M_LGen_CT
{
var integer vl_eCtxIdx:= f_EPTF_LGenBase_getBehaviorCtxItem(pl_eIdx, v_LwM2M_bIdx, 0);
v_LwM2M_EntityCtxDB.data[vl_eCtxIdx] := c_LwM2M_EntityCtx_init;
}
function f_EPTF_LwM2M_EntityCtxDB_init()
runs on EPTF_LwM2M_LGen_CT
{
f_EPTF_FBQ_initFreeBusyQueue(v_LwM2M_EntityCtxDB.queue);
v_LwM2M_EntityCtxDB.data := {};
v_LwM2M_EntityCtxDB.hashRef := f_EPTF_str2int_HashMap_New("EPTF_LwM2M_EnityCtxDB_Hash");
}
function f_EPTF_LwM2M_EntityCtxDB_cleanUp()
runs on EPTF_LwM2M_LGen_CT
{
f_EPTF_FBQ_initFreeBusyQueue(v_LwM2M_EntityCtxDB.queue);
v_LwM2M_EntityCtxDB.data :={}
f_EPTF_str2int_HashMap_Delete("EPTF_LwM2M_EnityCtxDB_Hash");
}
function f_EPTF_LwM2M_DeviceDB_init()
runs on EPTF_LwM2M_LGen_CT
{
f_EPTF_FBQ_initFreeBusyQueue(v_LwM2M_DeviceDB.queue);
v_LwM2M_DeviceDB.data := {};
v_LwM2M_DeviceDB.hashRef := f_EPTF_oct2int_HashMap_New("EPTF_LwM2M_DeviceDB_Hash");
}
function f_EPTF_LwM2M_DeviceDB_add(in LwM2M_Device p_device)
runs on EPTF_LwM2M_LGen_CT
return integer
{
var integer v_idx := f_EPTF_FBQ_getOrCreateFreeSlot(v_LwM2M_DeviceDB.queue);
f_EPTF_FBQ_moveFromFreeHeadToBusyTail(v_LwM2M_DeviceDB.queue);
f_EPTF_LwM2M_Logging_DEBUG(log2str(": "," adding device ", v_idx, " ", p_device));
if (sizeof(p_device.registeredLocation) > 0) {
f_EPTF_LwM2M_DeviceDB_setLocationKey(p_device.registeredLocation, v_idx);
}
v_LwM2M_DeviceDB.data[v_idx] := p_device;
return v_idx;
}
function f_EPTF_LwM2M_DeviceDB_remove(in integer p_idx)
runs on EPTF_LwM2M_LGen_CT
{
v_LwM2M_DeviceDB.data[p_idx] := c_LwM2M_Device_init;
f_EPTF_FBQ_moveFromBusyToFreeTail(p_idx, v_LwM2M_DeviceDB.queue);
}
function f_EPTF_LwM2M_DeviceDB_setLocationKey(in Location p_location, in integer p_idx)
runs on EPTF_LwM2M_LGen_CT
{
f_EPTF_oct2int_HashMap_Insert(v_LwM2M_DeviceDB.hashRef, f_EPTF_LwM2M_DeviceDB_locationHash(p_location), p_idx);
}
function f_EPTF_LwM2M_DeviceDB_locationHash(in Location p_location)
return octetstring
{
var octetstring v_loc := ''O;
for (var integer i:=0; i<sizeof(p_location); i:=i+1) {
v_loc := v_loc & unichar2oct(p_location[i]);
}
return v_loc;
}
function f_EPTF_LwM2M_DeviceDB_cleanUp()
runs on EPTF_LwM2M_LGen_CT
{
// for each device: clean up object db if initialized
for (var integer i:=0; i < f_EPTF_FBQ_getLengthOfQueue(v_LwM2M_DeviceDB.queue); i:=i+1) {
if(f_EPTF_FBQ_itemIsBusy(i, v_LwM2M_DeviceDB.queue)) {
if (v_LwM2M_DeviceDB.data[i].objects.id >= 0) {
f_LwM2M_ObjectDB_cleanUp(v_LwM2M_DeviceDB.data[i].objects);
}
}
}
f_EPTF_FBQ_initFreeBusyQueue(v_LwM2M_DeviceDB.queue);
v_LwM2M_DeviceDB.data :={}
f_EPTF_oct2int_HashMap_Delete("EPTF_LwM2M_DeviceDB_Hash");
}
function f_EPTF_LwM2M_TemplateDB_init()
runs on EPTF_LwM2M_LGen_CT
{
v_LwM2M_templateDB.data := {};
v_LwM2M_templateDB.hashRef := f_EPTF_str2int_HashMap_New("EPTF_LwM2M_templateDB_Hash");
for (var integer i:=0; i<sizeof(tsp_EPTF_LwM2M_LGen_templates); i:=i+1) {
f_EPTF_LwM2M_TemplateDB_add(tsp_EPTF_LwM2M_LGen_templates[i]);
}
}
function f_EPTF_LwM2M_TemplateDB_add(in LwM2M_Template p_template)
runs on EPTF_LwM2M_LGen_CT
return integer
{
if (f_EPTF_LwM2M_TemplateDB_lookUp(p_template.id)!=-1)
{
f_EPTF_LwM2M_Logging_WARNING(log2str(%definitionId, " template is already added with id: ", p_template.id));
return -1;
}
var integer v_idx := sizeof(v_LwM2M_templateDB.data);
v_LwM2M_templateDB.data[v_idx] := p_template;
f_EPTF_str2int_HashMap_Insert(v_LwM2M_templateDB.hashRef, p_template.id, v_idx);
f_EPTF_LwM2M_Logging_VERBOSE(log2str(%definitionId, " template was added with id: ", p_template.id, " at idx: ",v_idx));
return v_idx;
}
function f_EPTF_LwM2M_TemplateDB_lookUp(in charstring p_id)
runs on EPTF_LwM2M_LGen_CT
return integer
{
var integer vl_idx := -1;
if (not f_EPTF_str2int_HashMap_Find(v_LwM2M_templateDB.hashRef, p_id, vl_idx))
{
vl_idx := -1;
}
return vl_idx;
}
function f_EPTF_LwM2M_TemplateDB_get(in integer p_idx, inout LWM2M_PDU p_pdu)
runs on EPTF_LwM2M_LGen_CT
{
if (p_idx < sizeof(v_LwM2M_templateDB.data) and p_idx >= 0)
{
f_EPTF_LwM2M_Logging_VERBOSE(log2str(%definitionId, " template is fetched with idx: ", p_idx));
p_pdu := v_LwM2M_templateDB.data[p_idx].msg;
}
}
function f_EPTF_LwM2M_TemplateDB_cleanUp()
runs on EPTF_LwM2M_LGen_CT
{
v_LwM2M_templateDB.data := {};
f_EPTF_str2int_HashMap_Delete("EPTF_LwM2M_templateDB_Hash");
}
function f_EPTF_LwM2M_Logging_VERBOSE(in @lazy charstring pl_message)
runs on EPTF_LwM2M_LGen_CT
{
if (c_EPTF_Common_debugSwitch) {
f_EPTF_Logging_debugV2(pl_message, v_LwM2M_loggingMaskId, {c_LwM2M_LGen_Logging_DEBUGV});
}
}
function f_EPTF_LwM2M_Logging_DEBUG(in @lazy charstring pl_message)
runs on EPTF_LwM2M_LGen_CT
{
if (c_EPTF_Common_debugSwitch) {
f_EPTF_Logging_debugV2(pl_message, v_LwM2M_loggingMaskId, {c_LwM2M_LGen_Logging_DEBUG});
}
}
function f_EPTF_LwM2M_Logging_WARNING(in @lazy charstring pl_message)
runs on EPTF_LwM2M_LGen_CT
{
if (c_EPTF_Common_debugSwitch) {
f_EPTF_Logging_debugV2(pl_message, v_LwM2M_loggingMaskId, {c_LwM2M_LGen_Logging_WARNING});
}
}
function f_EPTF_LwM2M_Logging_ERROR(in @lazy charstring pl_message)
runs on EPTF_LwM2M_LGen_CT
{
if (c_EPTF_Common_debugSwitch) {
f_EPTF_Logging_debugV2(pl_message, v_LwM2M_loggingMaskId, {c_LwM2M_LGen_Logging_ERROR});
}
}
function f_EPTF_LwM2M_LGen_receiveMessage(in EPTF_LwM2M_PDU pl_message)
runs on EPTF_LwM2M_LGen_CT
{
f_EPTF_LwM2M_Logging_VERBOSE(log2str(%definitionId, " ", pl_message));
v_LwM2M_msgToProcess := pl_message;
f_EPTF_LwM2M_stack_fromEnv(v_LwM2M_msgToProcess);
}
function f_EPTF_LwM2M_declareEvents()
runs on EPTF_LwM2M_LGen_CT
{
var integer vl_dummy;
if (
c_LwM2M_eventIdx_Register != f_EPTF_LGenBase_declareFsmEvent(c_LwM2M_behaviorType, c_LwM2M_eventName_Register) or
c_LwM2M_eventIdx_Update != f_EPTF_LGenBase_declareFsmEvent(c_LwM2M_behaviorType, c_LwM2M_eventName_Update) or
c_LwM2M_eventIdx_Deregister != f_EPTF_LGenBase_declareFsmEvent(c_LwM2M_behaviorType, c_LwM2M_eventName_Deregister) or
c_LwM2M_eventIdx_Read != f_EPTF_LGenBase_declareFsmEvent(c_LwM2M_behaviorType, c_LwM2M_eventName_Read) or
c_LwM2M_eventIdx_Write != f_EPTF_LGenBase_declareFsmEvent(c_LwM2M_behaviorType, c_LwM2M_eventName_Write) or
c_LwM2M_eventIdx_Execute != f_EPTF_LGenBase_declareFsmEvent(c_LwM2M_behaviorType, c_LwM2M_eventName_Execute) or
c_LwM2M_eventIdx_Create != f_EPTF_LGenBase_declareFsmEvent(c_LwM2M_behaviorType, c_LwM2M_eventName_Create) or
c_LwM2M_eventIdx_Delete != f_EPTF_LGenBase_declareFsmEvent(c_LwM2M_behaviorType, c_LwM2M_eventName_Delete)
){
f_EPTF_LGenBase_log();
log("error"); mtc.stop
}
for (var integer i:=8; i<700; i:=i+1)
{
vl_dummy := f_EPTF_LGenBase_declareFsmEvent(c_LwM2M_behaviorType, "LWM2M rsp: "&int2str(i));
}
if (
c_LwM2M_eventIdx_1xx != f_EPTF_LGenBase_declareFsmEvent(c_LwM2M_behaviorType, c_LwM2M_eventName_1xx) or
c_LwM2M_eventIdx_2xx != f_EPTF_LGenBase_declareFsmEvent(c_LwM2M_behaviorType, c_LwM2M_eventName_2xx) or
c_LwM2M_eventIdx_3xx != f_EPTF_LGenBase_declareFsmEvent(c_LwM2M_behaviorType, c_LwM2M_eventName_3xx) or
c_LwM2M_eventIdx_4xx != f_EPTF_LGenBase_declareFsmEvent(c_LwM2M_behaviorType, c_LwM2M_eventName_4xx) or
c_LwM2M_eventIdx_5xx != f_EPTF_LGenBase_declareFsmEvent(c_LwM2M_behaviorType, c_LwM2M_eventName_5xx) or
c_LwM2M_eventIdx_6xx != f_EPTF_LGenBase_declareFsmEvent(c_LwM2M_behaviorType, c_LwM2M_eventName_6xx) or
c_LwM2M_eventIdx_3xxto6xx != f_EPTF_LGenBase_declareFsmEvent(c_LwM2M_behaviorType, c_LwM2M_eventName_3xxto6xx)
){
f_EPTF_LGenBase_log();
log("error"); mtc.stop
}
}
function f_EPTF_LwM2M_declareSteps()
runs on EPTF_LwM2M_LGen_CT
{
if (
c_LwM2M_stepIdx_loadTemplate_byIntIdx != f_EPTF_LGenBase_declareStep(c_LwM2M_behaviorType,{c_LwM2M_stepName_loadTemplate_byIntIdx, refers(f_LwM2M_step_loadTemplate_byIntIdx)}) or
c_LwM2M_stepIdx_send != f_EPTF_LGenBase_declareStep(c_LwM2M_behaviorType,{c_LwM2M_stepName_send, refers(f_LwM2M_step_send)}) or
c_LwM2M_stepIdx_createDevice != f_EPTF_LGenBase_declareStep(c_LwM2M_behaviorType,{c_LwM2M_stepName_createDevice, refers(f_LwM2M_step_createDevice)}) or
c_LwM2M_stepIdx_cleanupDevice != f_EPTF_LGenBase_declareStep(c_LwM2M_behaviorType,{c_LwM2M_stepName_cleanupDevice, refers(f_LwM2M_step_cleanupDevice)}) or
c_LwM2M_stepIdx_logDevice != f_EPTF_LGenBase_declareStep(c_LwM2M_behaviorType,{c_LwM2M_stepName_logDevice, refers(f_LwM2M_step_logDevice)}) or
c_LwM2M_stepIdx_createObject != f_EPTF_LGenBase_declareStep(c_LwM2M_behaviorType,{c_LwM2M_stepName_createObject, refers(f_LwM2M_step_createObject)}) or
c_LwM2M_stepIdx_createObjectInstance != f_EPTF_LGenBase_declareStep(c_LwM2M_behaviorType,{c_LwM2M_stepName_createObjectInstance, refers(f_LwM2M_step_createObjectInstance)}) or
c_LwM2M_stepIdx_handleReadRequest != f_EPTF_LGenBase_declareStep(c_LwM2M_behaviorType,{c_LwM2M_stepName_handleReadRequest, refers(f_LwM2M_step_handleReadRequest)}) or
c_LwM2M_stepIdx_handleWriteRequest != f_EPTF_LGenBase_declareStep(c_LwM2M_behaviorType,{c_LwM2M_stepName_handleWriteRequest, refers(f_LwM2M_step_handleWriteRequest)}) or
c_LwM2M_stepIdx_handleExecuteRequest != f_EPTF_LGenBase_declareStep(c_LwM2M_behaviorType,{c_LwM2M_stepName_handleExecuteRequest, refers(f_LwM2M_step_handleExecuteRequest)}) or
c_LwM2M_stepIdx_loadTemplate_byStringId != f_EPTF_LGenBase_declareStep(c_LwM2M_behaviorType,{c_LwM2M_stepName_loadTemplate_byStringId, refers(f_LwM2M_step_loadTemplate_byStringId)})
)
{
f_EPTF_LGenBase_log();
log("EPTF_LwM2M_LGen declaration error"); mtc.stop
}
}
function f_LwM2M_step_loadTemplate_byIntIdx(in EPTF_LGenBase_TestStepArgs pl_ptr)
runs on EPTF_LwM2M_LGen_CT
{
f_EPTF_LwM2M_Logging_DEBUG(log2str(%definitionId));
var integer vl_templateIdx := -1;
f_EPTF_LwM2M_getIntValue(pl_ptr.refContext.fRefArgs, 0, vl_templateIdx);
f_EPTF_LwM2M_TemplateDB_get(vl_templateIdx, v_LwM2M_msgToSend.pdu);
}
function f_LwM2M_step_loadTemplate_byStringId(in EPTF_LGenBase_TestStepArgs pl_ptr)
runs on EPTF_LwM2M_LGen_CT
{
f_EPTF_LwM2M_Logging_DEBUG(log2str(%definitionId));
var charstring vl_templateId := f_EPTF_LGenBase_charstringValOfStep(pl_ptr);
var integer vl_templateIdx := f_EPTF_LwM2M_TemplateDB_lookUp(vl_templateId);
if (vl_templateIdx >= 0)
{
f_EPTF_LwM2M_TemplateDB_get(vl_templateIdx, v_LwM2M_msgToSend.pdu);
}
else
{
f_EPTF_LwM2M_Logging_WARNING(log2str(%definitionId," Couldn't find template with id: ", vl_templateId));
}
}
function f_LwM2M_step_send(in EPTF_LGenBase_TestStepArgs pl_ptr)
runs on EPTF_LwM2M_LGen_CT
{
f_EPTF_LwM2M_Logging_DEBUG(log2str(%definitionId));
f_EPTF_LwM2M_setStepCtx(pl_ptr, v_LwM2M_ctx);
v_LwM2M_msgToSend.eIdx := v_LwM2M_ctx.eIdx;
v_LwM2M_msgToSend.fsmIdx := v_LwM2M_ctx.fsmIdx;
f_EPTF_LwM2M_stack_fromApp(v_LwM2M_msgToSend, v_LwM2M_ctx);
//action(v_LwM2M_msgToSend);
f_EPTF_SchedulerComp_refreshSnapshotTime();
}
function f_LwM2M_step_createDevice(in EPTF_LGenBase_TestStepArgs pl_ptr)
runs on EPTF_LwM2M_LGen_CT
{
f_EPTF_LwM2M_Logging_DEBUG(log2str(%definitionId));
f_EPTF_LwM2M_setStepCtx(pl_ptr, v_LwM2M_ctx);
var LwM2M_Device vl_device := c_LwM2M_Device_init;
var integer vl_idx := f_EPTF_LwM2M_DeviceDB_add(vl_device);
f_LwM2M_ObjectDB_init(v_LwM2M_DeviceDB.data[vl_idx].objects, vl_idx);
v_LwM2M_EntityCtxDB.data[v_LwM2M_ctx.eCtxIdx].currentDevice := vl_idx;
}
function f_LwM2M_step_cleanupDevice(in EPTF_LGenBase_TestStepArgs pl_ptr)
runs on EPTF_LwM2M_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_cleanUp(v_LwM2M_DeviceDB.data[v_LwM2M_ctx.deviceIdx].objects);
f_EPTF_LwM2M_DeviceDB_remove(v_LwM2M_ctx.deviceIdx);
v_LwM2M_EntityCtxDB.data[v_LwM2M_ctx.eCtxIdx].currentDevice := -1;
}
}
function f_LwM2M_step_logDevice(in EPTF_LGenBase_TestStepArgs pl_ptr)
runs on EPTF_LwM2M_LGen_CT
{
f_EPTF_LwM2M_Logging_DEBUG(log2str(%definitionId));
f_EPTF_LwM2M_setStepCtx(pl_ptr, v_LwM2M_ctx);
if (v_LwM2M_ctx.deviceIdx >= 0)
{
if (tsp_EPTF_LwM2M_LGen_debug) { action("device: \n", v_LwM2M_DeviceDB.data[v_LwM2M_ctx.deviceIdx]); }
}
}
function f_LwM2M_step_createObject(in EPTF_LGenBase_TestStepArgs pl_ptr)
runs on EPTF_LwM2M_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 integer vl_objectId := -1;
if (f_EPTF_LwM2M_getIntValue(pl_ptr.refContext.fRefArgs, 0, vl_objectId) and v_LwM2M_ctx.deviceIdx >= 0)
{
var integer vl_specIdx := f_LwM2M_ObjectSpecificationDB_lookUp(v_LwM2M_ObjectSpecificationDB, vl_objectId);
if (vl_specIdx >= 0)
{
var integer v_ret := f_LwM2M_ObjectDB_createObject(
v_LwM2M_DeviceDB.data[v_LwM2M_ctx.deviceIdx].objects,
v_LwM2M_ObjectSpecificationDB.specs[vl_specIdx]
);
if (v_ret < 0) { f_EPTF_LwM2M_Logging_VERBOSE(log2str("couldn't create object for id: ", vl_objectId)); }
}
else { f_EPTF_LwM2M_Logging_VERBOSE(log2str("specification is not for for id ", vl_objectId)); }
}
else { f_EPTF_LwM2M_Logging_VERBOSE(log2str("parameter is not set for test step")); }
}
}
function f_LwM2M_step_createObjectInstance(in EPTF_LGenBase_TestStepArgs pl_ptr)
runs on EPTF_LwM2M_LGen_CT
{
f_EPTF_LwM2M_Logging_DEBUG(log2str(%definitionId));
f_EPTF_LwM2M_setStepCtx(pl_ptr, v_LwM2M_ctx);
var integer vl_objectId := -1;
if (f_EPTF_LwM2M_getIntValue(pl_ptr.refContext.fRefArgs, 0, vl_objectId) and v_LwM2M_ctx.deviceIdx >= 0)
{
var boolean vl_addResources := true;
var integer vl_secondParam := -1;
if (f_EPTF_LwM2M_getIntValue(pl_ptr.refContext.fRefArgs, 1, vl_secondParam) and v_LwM2M_ctx.deviceIdx >= 0) {
vl_addResources := vl_secondParam != c_LwM2M_stepParam_createObjectInstance_DoNotAddResources;
}
var integer v_ret := f_LwM2M_ObjectDB_createObjectInstance(
v_LwM2M_DeviceDB.data[v_LwM2M_ctx.deviceIdx].objects,
v_LwM2M_ObjectSpecificationDB,
vl_objectId,
vl_addResources
);
if (v_ret < 0) { f_EPTF_LwM2M_Logging_VERBOSE(log2str("couldn't create object instance for id: ", vl_objectId)); }
}
else { f_EPTF_LwM2M_Logging_VERBOSE(log2str("parameter is not set for test step")); }
}
function f_LwM2M_step_handleReadRequest(in EPTF_LGenBase_TestStepArgs pl_ptr)
runs on EPTF_LwM2M_LGen_CT
{
f_EPTF_LwM2M_Logging_DEBUG(log2str(%definitionId));
f_EPTF_LwM2M_setStepCtx(pl_ptr, v_LwM2M_ctx);
if (ischosen(v_LwM2M_msgToProcess.pdu.Read_) and v_LwM2M_ctx.deviceIdx >= 0)
{
var LwM2M_Resource_List v_resources := {};
var boolean vl_found := false;
// Resource
if (f_LwM2M_ObjectPath_isResource(v_LwM2M_msgToProcess.pdu.Read_.path))
{
var LwM2M_Resource v_res;
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.Read_.path.objectId,
v_LwM2M_msgToProcess.pdu.Read_.path.objectInstanceId,
v_LwM2M_msgToProcess.pdu.Read_.path.resourceId,
v_res
);
if (vl_found)
{
if (ispresent(v_LwM2M_msgToProcess.pdu.Read_.observe)) {
v_res.observe := v_LwM2M_msgToProcess.pdu.Read_.observe;
f_LwM2M_ObjectDB_setResource(
v_LwM2M_DeviceDB.data[v_LwM2M_ctx.deviceIdx].objects,
v_LwM2M_msgToProcess.pdu.Read_.path.objectId,
v_LwM2M_msgToProcess.pdu.Read_.path.objectInstanceId,
v_LwM2M_msgToProcess.pdu.Read_.path.resourceId,
v_res
);
}
}
v_resources[sizeof(v_resources)] := v_res;
f_EPTF_LwM2M_Logging_DEBUG(log2str(%definitionId, " resource found: ", v_resources));
}
// Object instance
else if (f_LwM2M_ObjectPath_isObjectInstance(v_LwM2M_msgToProcess.pdu.Read_.path))
{
var LwM2M_ObjectInstance v_objInst;
vl_found := f_LwM2M_ObjectDB_getObjectInstance(
v_LwM2M_DeviceDB.data[v_LwM2M_ctx.deviceIdx].objects,
v_LwM2M_msgToProcess.pdu.Read_.path.objectId,
v_LwM2M_msgToProcess.pdu.Read_.path.objectInstanceId,
v_objInst
);
for (var integer i:=0; i<sizeof(v_objInst.resources); i:=i+1) {
v_resources[sizeof(v_resources)] := v_LwM2M_DeviceDB.data[v_LwM2M_ctx.deviceIdx].objects.resources[v_objInst.resources[i]];
}
}
// Object
else if (f_LwM2M_ObjectPath_isObject(v_LwM2M_msgToProcess.pdu.Read_.path))
{
var LwM2M_ObjectInstance v_objInst;
vl_found := f_LwM2M_ObjectDB_getObjectInstance(
v_LwM2M_DeviceDB.data[v_LwM2M_ctx.deviceIdx].objects,
v_LwM2M_msgToProcess.pdu.Read_.path.objectId,
0, // TODO: only for 0 object instance
v_objInst
);
for (var integer i:=0; i<sizeof(v_objInst.resources); i:=i+1) {
v_resources[sizeof(v_resources)] := v_LwM2M_DeviceDB.data[v_LwM2M_ctx.deviceIdx].objects.resources[v_objInst.resources[i]];
}
}
v_LwM2M_msgToSend.eIdx := v_LwM2M_ctx.eIdx;
v_LwM2M_msgToSend.fsmIdx := v_LwM2M_ctx.fsmIdx;
if (vl_found)
{
//v_res.objId := -1; v_res.objInstId := -1; v_res.id := -1;
v_LwM2M_msgToSend.pdu :=
{
Response := {
location := {},
code := 205,
contentFormat := 1543, // JSON format
observe := omit,
resources := v_resources
}
}
}
else
{
v_LwM2M_msgToSend.pdu :=
{
Response := {
location := {},
code := 404,
contentFormat := omit,
observe := omit,
resources := {}
}
}
}
if (ispresent(v_LwM2M_msgToProcess.pdu.Read_.observe)) {
v_LwM2M_msgToSend.pdu.Response.observe := v_LwM2M_msgToProcess.pdu.Read_.observe;
}
vf_EPTF_LwM2M_Transport_send.apply(v_LwM2M_msgToSend);
}
else { f_EPTF_LwM2M_Logging_DEBUG(log2str(%definitionId, " not read pdu, or no device available, returning")); }
}
function f_LwM2M_step_handleWriteRequest(in EPTF_LGenBase_TestStepArgs pl_ptr)
runs on EPTF_LwM2M_LGen_CT
{
f_EPTF_LwM2M_Logging_DEBUG(log2str(%definitionId));
f_EPTF_LwM2M_setStepCtx(pl_ptr, v_LwM2M_ctx);
var boolean vl_found := false;
var boolean vl_typeMatched := false;
if (ischosen(v_LwM2M_msgToProcess.pdu.Write) and v_LwM2M_ctx.deviceIdx >= 0)
{
var LwM2M_Resource v_res;
if (f_LwM2M_ObjectPath_isResource(v_LwM2M_msgToProcess.pdu.Write.path) and
sizeof(v_LwM2M_msgToProcess.pdu.Write.resources) == 1
)
{
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.Write.path.objectId,
v_LwM2M_msgToProcess.pdu.Write.path.objectInstanceId,
v_LwM2M_msgToProcess.pdu.Write.path.resourceId,
v_res
);
f_EPTF_LwM2M_Logging_DEBUG(log2str(%definitionId, " resource found: ", v_res));
if (vl_found)
{
// Value type matching
if (ischosen(v_res.val.boolValue) and ispresent(v_LwM2M_msgToProcess.pdu.Write.resources[0].val.boolValue))
{ v_res.val := v_LwM2M_msgToProcess.pdu.Write.resources[0].val; vl_typeMatched := true; }
else if (ischosen(v_res.val.strValue) and ispresent(v_LwM2M_msgToProcess.pdu.Write.resources[0].val.strValue))
{ v_res.val := v_LwM2M_msgToProcess.pdu.Write.resources[0].val; vl_typeMatched := true; }
else if (ischosen(v_res.val.floatValue) and ispresent(v_LwM2M_msgToProcess.pdu.Write.resources[0].val.floatValue))
{ v_res.val := v_LwM2M_msgToProcess.pdu.Write.resources[0].val; vl_typeMatched := true; }
else if (ischosen(v_res.val.intValue) and ispresent(v_LwM2M_msgToProcess.pdu.Write.resources[0].val.floatValue))
{ v_res.val.intValue := float2int(v_LwM2M_msgToProcess.pdu.Write.resources[0].val.floatValue); vl_typeMatched := true; }
if (vl_typeMatched)
{
f_LwM2M_ObjectDB_setResourceValue(
v_LwM2M_DeviceDB.data[v_LwM2M_ctx.deviceIdx].objects,
v_LwM2M_msgToProcess.pdu.Write.path.objectId,
v_LwM2M_msgToProcess.pdu.Write.path.objectInstanceId,
v_LwM2M_msgToProcess.pdu.Write.path.resourceId,
v_res.val
);
}
}
}
v_LwM2M_msgToSend.eIdx := v_LwM2M_ctx.eIdx;
v_LwM2M_msgToSend.fsmIdx := v_LwM2M_ctx.fsmIdx;
if (vl_found and vl_typeMatched)
{
v_LwM2M_msgToSend.pdu :=
{
Response := {
location := {},
code := 204,
contentFormat := omit, // JSON format
resources := {}
}
}
}
else
{
v_LwM2M_msgToSend.pdu :=
{
Response := {
location := {},
code := 404,
contentFormat := omit,
resources := {}
}
}
}
vf_EPTF_LwM2M_Transport_send.apply(v_LwM2M_msgToSend);
}
else { f_EPTF_LwM2M_Logging_DEBUG(log2str(%definitionId, " not write pdu, or no device available, returning")); }
}
function f_LwM2M_step_handleExecuteRequest(in EPTF_LGenBase_TestStepArgs pl_ptr)
runs on EPTF_LwM2M_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_EPTF_LwM2M_setStepCtx(in EPTF_LGenBase_TestStepArgs pl_ptr, inout LwM2M_StepCtx p_ctx)
runs on EPTF_LwM2M_LGen_CT
{
p_ctx.eIdx := pl_ptr.eIdx;
p_ctx.fsmIdx := pl_ptr.refContext.fCtxIdx;
p_ctx.eCtxIdx := f_EPTF_LGenBase_getBehaviorCtxItem(pl_ptr.eIdx, v_LwM2M_bIdx, 0);
p_ctx.deviceIdx := v_LwM2M_EntityCtxDB.data[v_LwM2M_ctx.eCtxIdx].currentDevice;
}
function f_EPTF_LwM2M_setCtx(in integer p_eIdx, in integer p_fsmIdx, inout LwM2M_StepCtx p_ctx)
runs on EPTF_LwM2M_LGen_CT
{
p_ctx.eIdx := p_eIdx;
p_ctx.fsmIdx := p_fsmIdx;
p_ctx.eCtxIdx := f_EPTF_LGenBase_getBehaviorCtxItem(p_eIdx, v_LwM2M_bIdx, 0);
p_ctx.deviceIdx := v_LwM2M_EntityCtxDB.data[v_LwM2M_ctx.eCtxIdx].currentDevice;
}
function f_EPTF_LwM2M_hasDevice(in LwM2M_StepCtx p_ctx)
return boolean
{
return p_ctx.deviceIdx >= 0;
}
function f_EPTF_LwM2M_stack_fromApp(inout EPTF_LwM2M_PDU p_pdu, in LwM2M_StepCtx p_ctx)
runs on EPTF_LwM2M_LGen_CT
{
if (p_ctx.deviceIdx >= 0)
{
// State: NOT_REGISTERED
if (v_LwM2M_DeviceDB.data[p_ctx.deviceIdx].state == NOT_REGISTERED)
{
// Register available objects
if (ischosen(p_pdu.pdu.Register) and
v_LwM2M_DeviceDB.data[p_ctx.deviceIdx].objects.id != -1) {
f_LwM2M_ObjectDB_getObjectPaths(v_LwM2M_DeviceDB.data[p_ctx.deviceIdx].objects, p_pdu.pdu.Register.objectsAndObjectInstances);
}
}
// State: REGISTERED
else if (v_LwM2M_DeviceDB.data[p_ctx.deviceIdx].state == REGISTERED)
{
// Include registered location in the outgoing message
if (sizeof(v_LwM2M_DeviceDB.data[p_ctx.deviceIdx].registeredLocation) > 0) {
if (ischosen(p_pdu.pdu.Update)) {
p_pdu.pdu.Update.location := v_LwM2M_DeviceDB.data[p_ctx.deviceIdx].registeredLocation;
}
else if (ischosen(p_pdu.pdu.Deregister)) {
p_pdu.pdu.Deregister.location := v_LwM2M_DeviceDB.data[p_ctx.deviceIdx].registeredLocation;
v_LwM2M_DeviceDB.data[p_ctx.deviceIdx].state := NOT_REGISTERED;
}
}
}
}
vf_EPTF_LwM2M_Transport_send.apply(p_pdu);
}
function f_EPTF_LwM2M_stack_fromEnv(in EPTF_LwM2M_PDU p_pdu)
runs on EPTF_LwM2M_LGen_CT
{
f_EPTF_LwM2M_setCtx(p_pdu.eIdx, p_pdu.fsmIdx, v_LwM2M_ctx);
if (v_LwM2M_ctx.deviceIdx >= 0)
{
// State: NOT_REGISTERED
if (v_LwM2M_DeviceDB.data[v_LwM2M_ctx.deviceIdx].state == NOT_REGISTERED)
{
// Save registered location
if (ischosen(p_pdu.pdu.Response) and p_pdu.pdu.Response.code == 201) {
v_LwM2M_DeviceDB.data[v_LwM2M_ctx.deviceIdx].registeredLocation := p_pdu.pdu.Response.location;
v_LwM2M_DeviceDB.data[v_LwM2M_ctx.deviceIdx].state := REGISTERED;
}
}
}
f_EPTF_LwM2M_dispatchEventsForPDU(p_pdu.pdu, p_pdu.eIdx, p_pdu.fsmIdx, {});
}
function f_EPTF_LwM2M_dispatchEventsForPDU(in LWM2M_PDU pl_pdu, in integer pl_eIdx, in integer pl_fsmCtx, in EPTF_IntegerList pl_reportedArgs)
runs on EPTF_LwM2M_LGen_CT
{
var integer vl_eventIdx := f_EPTF_LwM2M_PduToEventIdx(pl_pdu);
if (vl_eventIdx == -1) {
f_EPTF_LwM2M_Logging_ERROR(log2str(%definitionId," Couldn't find eventIdx for PDU: ", pl_pdu));
return;
}
f_EPTF_LwM2M_dispatchEvent(vl_eventIdx, pl_eIdx, pl_fsmCtx, {});
if (100 <= vl_eventIdx and vl_eventIdx <= 199)
{
f_EPTF_LwM2M_dispatchEvent(c_LwM2M_eventIdx_1xx, pl_eIdx, pl_fsmCtx, {});
}
else if (200 <= vl_eventIdx and vl_eventIdx <= 299)
{
f_EPTF_LwM2M_dispatchEvent(c_LwM2M_eventIdx_2xx, pl_eIdx, pl_fsmCtx, {});
}
else if (300 <= vl_eventIdx and vl_eventIdx <= 699)
{
if (300 <= vl_eventIdx and vl_eventIdx <= 399)
{
f_EPTF_LwM2M_dispatchEvent(c_LwM2M_eventIdx_3xx, pl_eIdx, pl_fsmCtx, {});
}
else if (400 <= vl_eventIdx and vl_eventIdx <= 499)
{
f_EPTF_LwM2M_dispatchEvent(c_LwM2M_eventIdx_4xx, pl_eIdx, pl_fsmCtx, {});
}
else if (500 <= vl_eventIdx and vl_eventIdx <= 599)
{
f_EPTF_LwM2M_dispatchEvent(c_LwM2M_eventIdx_4xx, pl_eIdx, pl_fsmCtx, {});
}
f_EPTF_LwM2M_dispatchEvent(c_LwM2M_eventIdx_3xxto6xx, pl_eIdx, pl_fsmCtx, {});
}
}
function f_EPTF_LwM2M_sendNotificationForResource(in EPTF_LGenBase_TestStepArgs pl_ptr, LwM2M_Resource v_res)
runs on EPTF_LwM2M_LGen_CT
{
if (ispresent(v_res.observe)) {
//v_res.objId := -1; v_res.objInstId := -1; v_res.id := -1;
v_LwM2M_msgToSend.pdu :=
{
Response := {
location := {},
code := 205,
contentFormat := 1543, // JSON format
observe := v_res.observe,
resources := { v_res }
}
}
f_LwM2M_step_send(pl_ptr);
}
}
function f_EPTF_LwM2M_incObserveForResource(inout LwM2M_Resource v_res) {
if (ispresent(v_res.observe)) { v_res.observe.observe := v_res.observe.observe + 1 }
}
function f_EPTF_LwM2M_PduToEventIdx(in LWM2M_PDU p_pdu)
return integer
{
if (ischosen(p_pdu.Register)) { return c_LwM2M_eventIdx_Register; }
else if (ischosen(p_pdu.Update)) { return c_LwM2M_eventIdx_Update; }
else if (ischosen(p_pdu.Deregister)) { return c_LwM2M_eventIdx_Deregister; }
else if (ischosen(p_pdu.Read_)) { return c_LwM2M_eventIdx_Read; }
else if (ischosen(p_pdu.Write)) { return c_LwM2M_eventIdx_Write; }
else if (ischosen(p_pdu.Execute)) { return c_LwM2M_eventIdx_Execute; }
else if (ischosen(p_pdu.Create)) { return c_LwM2M_eventIdx_Create; }
else if (ischosen(p_pdu.Delete)) { return c_LwM2M_eventIdx_Delete; }
else if (ischosen(p_pdu.Response)) { return p_pdu.Response.code; }
else {
return -1;
}
}
function f_EPTF_LwM2M_dispatchEvent(in integer pl_eventIdx, in integer pl_eIdx, in integer pl_fsmCtx, in EPTF_IntegerList pl_reportedArgs)
runs on EPTF_LwM2M_LGen_CT
{
if (pl_eIdx < 0)
{
f_EPTF_LGenBase_postEvent(
{
{
v_LwM2M_bIdx,
pl_eventIdx,
omit,
omit
},
pl_reportedArgs
});
}
else
{
if (pl_fsmCtx < 0)
{
f_EPTF_LGenBase_postEvent(
{
{
v_LwM2M_bIdx,
pl_eventIdx,
{
pl_eIdx,
omit
}, omit
},
pl_reportedArgs
});
}
else
{
f_EPTF_LGenBase_postEvent(
{
{
v_LwM2M_bIdx,
pl_eventIdx,
{
pl_eIdx,
pl_fsmCtx
}, omit
},
pl_reportedArgs
});
}
}
}
function f_EPTF_LwM2M_getIntValue(
in EPTF_IntegerList pl_intList,
in integer pl_number,
inout integer pl_value)
return boolean
{
if (sizeof(pl_intList) > pl_number)
{
pl_value := pl_intList[pl_number];
return true;
}
return false;
}
}