From 5cde928858eb60715fc00930c8b55467742fb842 Mon Sep 17 00:00:00 2001 From: reinaortega <miguelangel.reinaortega@etsi.org> Date: Wed, 11 Sep 2019 17:12:44 +0200 Subject: [PATCH] Sending the "AE-ID_changed" acPrimitive only when MQTT is used Signed-off-by: reinaortega <miguelangel.reinaortega@etsi.org> --- LibOneM2M/OneM2M_Functions.ttcn | 116 ++++++++++++++++++++++++++------ 1 file changed, 96 insertions(+), 20 deletions(-) diff --git a/LibOneM2M/OneM2M_Functions.ttcn b/LibOneM2M/OneM2M_Functions.ttcn index 2208403..fd6c82d 100644 --- a/LibOneM2M/OneM2M_Functions.ttcn +++ b/LibOneM2M/OneM2M_Functions.ttcn @@ -140,6 +140,7 @@ module OneM2M_Functions { // Variables var charstring v_binding; + var charstring v_binding_in; var charstring v_host; //Initialization of component variables @@ -149,6 +150,7 @@ module OneM2M_Functions { // Map map(self:mcaPort, system:mcaPort) param (PX_TS_AE1.mcaPort); + map(self:mcaPortIn, system:mcaPortIn) param (PX_TS_AE1.mcaPortIn); map(self:acPort, system:acPort); if(PX_UT_IMPLEMENTED) { map(self:utPort, system:utPort) param (PX_TS_UT); @@ -167,8 +169,19 @@ module OneM2M_Functions { v_binding := "WSCK"; v_host := PX_TS_AE1.mcaPort.binding.wsBindingDesc.bindingDesc.sutAddress & ":" & int2str(PX_TS_AE1.mcaPort.binding.wsBindingDesc.bindingDesc.remotePort); } + + if (ischosen(PX_TS_AE1.mcaPortIn.binding.httpBindingDesc)) { + v_binding_in := "HTTP"; + } else if (ischosen(PX_TS_AE1.mcaPortIn.binding.coapBindingDesc)) { + v_binding_in := "COAP"; + } else if (ischosen(PX_TS_AE1.mcaPortIn.binding.mqttBindingDesc)) { + v_binding_in := "MQTT"; + } else { + v_binding_in := "WSCK"; + } vc_myInterfaces[enum2int(valueof(InterfaceIds:e_mca_port))] := { mcaPort, v_host, v_binding, c_serializationLabel[enum2int(PX_TS_AE1.mcaPort.serialization)] }; + vc_myInterfaces[enum2int(valueof(InterfaceIds:e_mca_in_port))] := { mcaPortIn, v_host, v_binding_in, c_serializationLabel[enum2int(PX_TS_AE1.mcaPortIn.serialization)] }; activate(a_default()); vc_aeSimu := activate(a_cse_cf02_ae1()); @@ -356,6 +369,7 @@ module OneM2M_Functions { // Variables var charstring v_binding; + var charstring v_binding_in; var PrimitiveContent v_cSEBaseResource; var charstring v_host; @@ -369,24 +383,36 @@ module OneM2M_Functions { vc_cSEBaseIndex := f_setLocalResource(v_cSEBaseResource, int5, -1); // Map + map(self:mcaPort, system:mcaPort) param (PX_TS_CSE1.mcaPort);//TODO To be consistent, we should use mcaPortIn for AE testing map(self:mcaPortIn, system:mcaPortIn) param (PX_TS_CSE1.mcaPortIn);//TODO To be consistent, we should use mcaPortIn for AE testing map(self:acPort, system:acPort); - if (ischosen(PX_TS_CSE1.mcaPortIn.binding.httpBindingDesc)) { + if (ischosen(PX_TS_CSE1.mcaPort.binding.httpBindingDesc)) { v_binding := "HTTP"; - v_host := PX_TS_CSE1.mcaPortIn.binding.httpBindingDesc.bindingDesc.sutAddress & ":" & int2str(PX_TS_CSE1.mcaPortIn.binding.httpBindingDesc.bindingDesc.remotePort); - } else if (ischosen(PX_TS_CSE1.mcaPortIn.binding.coapBindingDesc)) { + v_host := PX_TS_CSE1.mcaPort.binding.httpBindingDesc.bindingDesc.sutAddress & ":" & int2str(PX_TS_CSE1.mcaPort.binding.httpBindingDesc.bindingDesc.remotePort); + } else if (ischosen(PX_TS_CSE1.mcaPort.binding.coapBindingDesc)) { v_binding := "COAP"; - v_host := PX_TS_CSE1.mcaPortIn.binding.coapBindingDesc.bindingDesc.sutAddress & ":" & int2str(PX_TS_CSE1.mcaPortIn.binding.coapBindingDesc.bindingDesc.remotePort); - } else if (ischosen(PX_TS_CSE1.mcaPortIn.binding.mqttBindingDesc)) { + v_host := PX_TS_CSE1.mcaPort.binding.coapBindingDesc.bindingDesc.sutAddress & ":" & int2str(PX_TS_CSE1.mcaPort.binding.coapBindingDesc.bindingDesc.remotePort); + } else if (ischosen(PX_TS_CSE1.mcaPort.binding.mqttBindingDesc)) { v_binding := "MQTT"; - v_host := PX_TS_CSE1.mcaPortIn.binding.mqttBindingDesc.bindingDesc.sutAddress & ":" & int2str(PX_TS_CSE1.mcaPortIn.binding.mqttBindingDesc.bindingDesc.remotePort); + v_host := PX_TS_CSE1.mcaPort.binding.mqttBindingDesc.bindingDesc.sutAddress & ":" & int2str(PX_TS_CSE1.mcaPort.binding.mqttBindingDesc.bindingDesc.remotePort); } else { v_binding := "WSCK"; - v_host := PX_TS_CSE1.mcaPortIn.binding.wsBindingDesc.bindingDesc.sutAddress & ":" & int2str(PX_TS_CSE1.mcaPortIn.binding.wsBindingDesc.bindingDesc.remotePort); + v_host := PX_TS_CSE1.mcaPort.binding.wsBindingDesc.bindingDesc.sutAddress & ":" & int2str(PX_TS_CSE1.mcaPort.binding.wsBindingDesc.bindingDesc.remotePort); } - - vc_myInterfaces[enum2int(valueof(InterfaceIds:e_mca_in_port))] := { mcaPortIn, v_host, v_binding, c_serializationLabel[enum2int(PX_TS_CSE1.mcaPortIn.serialization)] }; + + if (ischosen(PX_TS_CSE1.mcaPortIn.binding.httpBindingDesc)) { + v_binding_in := "HTTP"; + } else if (ischosen(PX_TS_CSE1.mcaPortIn.binding.coapBindingDesc)) { + v_binding_in := "COAP"; + } else if (ischosen(PX_TS_CSE1.mcaPortIn.binding.mqttBindingDesc)) { + v_binding_in := "MQTT"; + } else { + v_binding_in := "WSCK"; + } + + vc_myInterfaces[enum2int(valueof(InterfaceIds:e_mca_port))] := { mcaPort, v_host, v_binding, c_serializationLabel[enum2int(PX_TS_CSE1.mcaPort.serialization)] }; + vc_myInterfaces[enum2int(valueof(InterfaceIds:e_mca_in_port))] := { mcaPortIn, v_host, v_binding_in, c_serializationLabel[enum2int(PX_TS_CSE1.mcaPortIn.serialization)] }; if(PX_UT_IMPLEMENTED) { map(self:utPort, system:utPort) param (PX_TS_UT); @@ -1007,9 +1033,7 @@ module OneM2M_Functions { vc_aeAuxIndex := f_setResource(v_response.primitive.responsePrimitive.primitiveContent, int2); if(ispresent(v_response.primitive.responsePrimitive.primitiveContent.aE.aE_ID)){ - f_sendAcPrimitive("AE-ID_changed", oct2char(unichar2oct(v_response.primitive.responsePrimitive.primitiveContent.aE.aE_ID))); - } else { - f_sendAcPrimitive("AE-ID_changed", "0"); + f_sendAcPrimitive("AE-ID_changed", vc_aeAuxIndex); } } } @@ -1073,10 +1097,8 @@ module OneM2M_Functions { vc_aeAuxIndex := f_setResource(vc_response.primitive.responsePrimitive.primitiveContent, int2); if(ispresent(vc_response.primitive.responsePrimitive.primitiveContent.aE.aE_ID)){ - f_sendAcPrimitive("AE-ID_changed", oct2char(unichar2oct(vc_response.primitive.responsePrimitive.primitiveContent.aE.aE_ID))); - } else { - f_sendAcPrimitive("AE-ID_changed", "0"); - } + f_sendAcPrimitive("AE-ID_changed", vc_aeAuxIndex); + } } } [] mcaPort.receive(mw_response(mw_responsePrimitiveKO)) @@ -1397,6 +1419,9 @@ module OneM2M_Functions { v_resourceIndex := f_setResource(vc_response.primitive.responsePrimitive.primitiveContent, p_resourceType, p_parentIndex); if(p_resourceType == int2) { vc_aeAuxIndex := v_resourceIndex; + if(ispresent(vc_response.primitive.responsePrimitive.primitiveContent.aE.aE_ID)){ + f_sendAcPrimitive("AE-ID_changed", vc_aeAuxIndex); + } } else if (p_resourceType == int9) { //Check that group members are correctly in the group if(not(match(v_request.primitiveContent.group_.memberIDs, vc_response.primitive.responsePrimitive.primitiveContent.group_.memberIDs))) { @@ -5469,12 +5494,39 @@ module OneM2M_Functions { * @param data Corresponding information for the correct execution of the given action * @verdict */ - function f_sendAcPrimitive(in charstring p_event, in charstring p_data) runs on Tester { + function f_sendAcPrimitive(in charstring p_event, in integer p_aeIndex) runs on Tester { + var XSD.ID v_aeResourceAddress; + var charstring v_spRelativeAeIdForMqtt; - - var charstring v_data := "" & p_data; // clear encoding rules (ttwb issue ?) - acPort.send(AcRequestPrimitive:{p_event, {charstring := v_data}}); + select (p_event) { + case ("AE-ID_changed") { + //Calculate the SP-Relative-AE-ID following format defined in TS-0010 MQTT + v_aeResourceAddress := f_getResourceAddress(p_aeIndex, e_nonHierarchical, e_spRelative); + if(vc_resourcesList[p_aeIndex].resource.aE.aE_ID[0] == "S") { + v_spRelativeAeIdForMqtt := f_resourceIdCleaner(v_aeResourceAddress); + } else { + v_spRelativeAeIdForMqtt := f_getSpRelativeAeIdForMqtt(v_aeResourceAddress); + } + + if((vc_config == e_cf01) or ((vc_config == e_cf02) and (vc_testSystemRole == e_ae)) or (vc_config == e_cf03)) { + if(vc_myInterfaces[enum2int(valueof(InterfaceIds:e_mca_port))].myProtocolBinding == "MQTT") { + acPort.send(AcRequestPrimitive:{p_event, {charstring := v_spRelativeAeIdForMqtt}}); + } + if(vc_myInterfaces[enum2int(valueof(InterfaceIds:e_mca_in_port))].myProtocolBinding == "MQTT") { + acPort.send(AcRequestPrimitive:{p_event, {charstring := v_spRelativeAeIdForMqtt}}); + } + } + if(((vc_config == e_cf02) and (vc_testSystemRole == e_cse)) or (vc_config == e_cf04)) { + if(vc_myInterfaces[enum2int(valueof(InterfaceIds:e_mcc_port))].myProtocolBinding == "MQTT") { + acPort.send(AcRequestPrimitive:{p_event, {charstring := v_spRelativeAeIdForMqtt}}); + } + if(vc_myInterfaces[enum2int(valueof(InterfaceIds:e_mcc_in_port))].myProtocolBinding == "MQTT") { + acPort.send(AcRequestPrimitive:{p_event, {charstring := v_spRelativeAeIdForMqtt}}); + } + } + } + } } }//end of group AcFunctions @@ -5671,6 +5723,30 @@ module OneM2M_Functions { //log("result: " & result); return result; } + + /** + * @desc Get the SP-Relative-AE-ID for MQTT + * @param p_aeResourceAddress AE resource address in SP-Relative-Resource-ID format + * @return SP-Relative-AE-ID for MQTT + */ + function f_getSpRelativeAeIdForMqtt(in XSD.ID p_aeResourceAddress) return charstring { + var integer v_length := lengthof(p_aeResourceAddress); + var integer i; + var XSD.ID v_aeId := p_aeResourceAddress; + var charstring v_result; + + //log("p_resourceID: " & p_resourceID); + for (i := v_length - 1; i>=0; i := i-1){ + if(p_aeResourceAddress[i]=="/"){ + //log("result: " & result); + v_aeId[i] := ":"; + break; + } + } + v_result := oct2char(unichar2oct(f_resourceIdCleaner(v_aeId))); + //log("result: " & result); + return v_result; + } /** * @desc Replace the CSE-Name by the shortcut ("-") in a structured resource id format -- GitLab