From e0393c76ee57fb1d1da10cb63b315c9111663e18 Mon Sep 17 00:00:00 2001
From: reinaortega <miguelangel.reinaortega@etsi.org>
Date: Mon, 1 Nov 2021 13:27:36 +0100
Subject: [PATCH] Adding CSE-ID_changed event for acPrimitive

Signed-off-by: reinaortega <miguelangel.reinaortega@etsi.org>
---
 LibOneM2M/OneM2M_Functions.ttcn | 28 ++++++++++++++++++++++------
 1 file changed, 22 insertions(+), 6 deletions(-)

diff --git a/LibOneM2M/OneM2M_Functions.ttcn b/LibOneM2M/OneM2M_Functions.ttcn
index b5464ce..90ea0d6 100644
--- a/LibOneM2M/OneM2M_Functions.ttcn
+++ b/LibOneM2M/OneM2M_Functions.ttcn
@@ -2810,6 +2810,9 @@ module OneM2M_Functions {
 						f_checkAttributesToBeSaved(int16, v_request, v_response.primitive.responsePrimitive);
 						vc_remoteCseIndex := f_setResource(v_response.primitive.responsePrimitive.primitiveContent, int16, -1);
 						vc_componentRegistered := true;
+						if(ispresent(v_response.primitive.responsePrimitive.primitiveContent.remoteCSE.cSE_ID)){
+							f_sendAcPrimitive("CSE-ID_changed", vc_remoteCseIndex);
+						}
 						v_localRemoteCSEResource := f_generateLocalResource(valueof(m_primitiveContentRemoteCSE(m_contentLocalRemoteCSEResource(f_getLocalPoA(PX_TS_CSE1.mccPortIn, "")))), vc_cSEBaseIndex, int16); // FIXME To be review not sure we have to use CSE1
 						vc_localRemoteCseIndex := f_setLocalResource(v_localRemoteCSEResource, int16, vc_cSEBaseIndex);
 					}
@@ -5626,7 +5629,7 @@ module OneM2M_Functions {
 			 * @param data Corresponding information for the correct execution of the given action
 			 * @verdict 
 			 */
-			function f_sendAcPrimitive(in charstring p_event, in integer p_aeIndex) runs on Tester {
+			function f_sendAcPrimitive(in charstring p_event, in integer p_resourceIndex) runs on Tester {
 				var XSD.ID v_aeResourceAddress;
 				var charstring v_spRelativeAeIdForMqtt;
 				
@@ -5634,8 +5637,8 @@ module OneM2M_Functions {
 				
 					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_aeResourceAddress := f_getResourceAddress(p_resourceIndex, e_nonHierarchical, e_spRelative);
+						if(vc_resourcesList[p_resourceIndex].resource.aE.aE_ID[0] == "S") {
 							v_spRelativeAeIdForMqtt := oct2char(unichar2oct(f_resourceIdCleaner(v_aeResourceAddress)));
 						} else {
 							v_spRelativeAeIdForMqtt := f_getSpRelativeAeIdForMqtt(v_aeResourceAddress);
@@ -5658,11 +5661,24 @@ module OneM2M_Functions {
 							}
 						}
 					}
+					case ("CSE-ID_changed") {
+						//TODO Check for other resource address formats
+						v_spRelativeAeIdForMqtt := oct2char(unichar2oct(f_resourceIdCleaner(vc_resourcesList[p_resourceIndex].resource.remoteCSE.cSE_ID)));
+						
+						if((((vc_config == e_cf02) or (vc_config == e_cf02CseSimuMaster)) and (vc_testSystemRole == e_cse)) or (vc_config == e_cf04)) {
+							if(vc_myInterfaces[enum2int(valueof(InterfaceIds:e_mcc_in_port))].myProtocolBinding == "MQTT") {
+								acPort.send(AcRequestPrimitive:{p_event & "_mccPort", {charstring := v_spRelativeAeIdForMqtt}});	
+							}
+							if(vc_myInterfaces[enum2int(valueof(InterfaceIds:e_mcc_in_port))].myProtocolBinding == "MQTT") {
+								acPort.send(AcRequestPrimitive:{p_event  & "_mccPortIn", {charstring := v_spRelativeAeIdForMqtt}});	
+							}
+						}
+					}
 					case ("MqttSetDefaultTopicToNotRegistration") {
-						acPort.send(AcRequestPrimitive:{p_event, {charstring := int2str(p_aeIndex)}});
+						acPort.send(AcRequestPrimitive:{p_event, {charstring := int2str(p_resourceIndex)}});
 					}
 					case ("MqttSetDefaultTopicToRegistration") {
-						acPort.send(AcRequestPrimitive:{p_event, {charstring := int2str(p_aeIndex)}});
+						acPort.send(AcRequestPrimitive:{p_event, {charstring := int2str(p_resourceIndex)}});
 					}
 				} 
 			}
@@ -5992,7 +6008,7 @@ module OneM2M_Functions {
 				if(valueof(p_msgOut.protocolBinding) == "MQTT") {
 					if(ischosen(p_msgOut.primitive.requestPrimitive)) {
 						if(ispresent(p_msgOut.primitive.requestPrimitive.resourceType))	{
-							if(valueof(p_msgOut.primitive.requestPrimitive.resourceType) != int2){
+							if((valueof(p_msgOut.primitive.requestPrimitive.resourceType) != int2) and (valueof(p_msgOut.primitive.requestPrimitive.resourceType) != int16)){
 								//Modify default topic to publish a non-registration message
 								f_sendAcPrimitive("MqttSetDefaultTopicToNotRegistration", -1);
 								vc_myInterfaces[enum2int(p_interfaceIds)].myPort.send(p_msgOut);
-- 
GitLab