From eb40619f49ac2e019c3d30d9e4b94f76d482bae3 Mon Sep 17 00:00:00 2001
From: reinaortega <miguelangel.reinaortega@etsi.org>
Date: Tue, 21 Aug 2018 14:45:11 +0200
Subject: [PATCH] CSE deregistration handling on postamble

Signed-off-by: reinaortega <miguelangel.reinaortega@etsi.org>
---
 LibOneM2M/OneM2M_Functions.ttcn | 254 ++++++++++++++++++--------------
 LibOneM2M/OneM2M_Templates.ttcn |   5 +-
 2 files changed, 144 insertions(+), 115 deletions(-)

diff --git a/LibOneM2M/OneM2M_Functions.ttcn b/LibOneM2M/OneM2M_Functions.ttcn
index 4f0bead..bd250dd 100644
--- a/LibOneM2M/OneM2M_Functions.ttcn
+++ b/LibOneM2M/OneM2M_Functions.ttcn
@@ -803,6 +803,8 @@ module OneM2M_Functions {
 			 */
 			function f_cse_postamble_deleteResourcesCSE() runs on CseSimu {
 				var integer i;
+				var integer v_resourceIndex := -1;
+				var URIList v_childResourceRefs;
 				var XSD.ID v_resourceAddress;
 				var RequestPrimitive v_request;
 				var boolean v_deregistrationPerformed := false;
@@ -818,15 +820,16 @@ module OneM2M_Functions {
 					};
 		
 					for(i := lengthof(vc_resourcesIndexToBeDeleted) -1; i >=0; i := i - 1) {
-			
-						if(ischosen(vc_resourcesList[vc_resourcesIndexToBeDeleted[i]].resource.remoteCSE)) {
-							v_resourceAddress := f_getResourceAddress(vc_resourcesIndexToBeDeleted[i], e_nonHierarchical, e_spRelative);
+						
+						v_resourceIndex := vc_resourcesIndexToBeDeleted[i];
+						if(ischosen(vc_resourcesList[v_resourceIndex].resource.remoteCSE)) {
+							v_resourceAddress := f_getResourceAddress(v_resourceIndex, e_nonHierarchical, e_spRelative);
 							v_deregistrationPerformed := true;
 						} else {
-							v_resourceAddress := f_getResourceAddress(vc_resourcesIndexToBeDeleted[i]);
+							v_resourceAddress := f_getResourceAddress(v_resourceIndex);
 						} 
 			
-						v_request := valueof(m_delete(v_resourceAddress, f_getOriginator(vc_resourcesIndexToBeDeleted[i], vc_testSystemRole)));
+						v_request := valueof(m_delete(v_resourceAddress, f_getOriginator(v_resourceIndex, vc_testSystemRole)));
 
 						mccPort.send(f_getMsgOutPrimitive(m_request(v_request)));
 			
@@ -846,62 +849,53 @@ module OneM2M_Functions {
 						}	
 					}
 					
+					//CSE Registration initiated by IUT - Test System to start CSE deregistration by:
+					//1) Started by Registrar (Test System)
+					//2) Started by Registree (IUT) by sending an UT message
 					if(not(v_deregistrationPerformed)) {
 						if(vc_localRemoteCseIndex != -1) {
-							//Deregistration by Registrar (Test System)
-							mccPort.send(f_getMsgOutPrimitive(m_request(m_retrieveChildReferences(f_getResourceAddress(), f_getOriginator(vc_remoteCseIndex), {int16}))));
-							tc_ac.start;
-							alt {
-								[] mccPort.receive(mw_response(mw_responsePrimitiveOK)) -> value vc_response {
-									tc_ac.stop;
-									log(__SCOPE__&":INFO: Resource retrieved successfuly");
-									v_resourceAddress := vc_response.primitive.responsePrimitive.primitiveContent.cSEBase.choice.childResource_list[0].base;
-									v_request := valueof(m_delete(v_resourceAddress, PX_CSE1_ID));
-
-									mccPort.send(f_getMsgOutPrimitive(m_request(v_request)));
-
-									tc_ac.start;
-									alt {
-										[] mccPort.receive(mw_response(mw_responsePrimitiveOK)) {
-											tc_ac.stop;
-											log(__SCOPE__&" INFO: Resource " & v_request.to_ & " deleted");
-											v_deregistrationPerformed := true;
-										}
-										[] mccPort.receive(mw_response(mw_responsePrimitiveKO)) {
-											tc_ac.stop;
-											log(__SCOPE__&" INFO: Error while deleting resource " & v_request.to_);
-										}
-										[] tc_ac.timeout {
-											log(__SCOPE__&" INFO: No answer while deleting resource " & v_request.to_);
-										}	
-									}		
-								}
-								[] mccPort.receive(mw_response(mw_responsePrimitiveKO)) -> value vc_response {
-									tc_ac.stop;
-									log(__SCOPE__&":INFO: Error while retrieving resource");
-								}
-								[] tc_ac.timeout {
-									log(__SCOPE__&":INFO: No answer while retrieving resource");
-								}
-							}
+							//1) Deregistration by Registrar (Test System)
+							v_childResourceRefs := f_cse_retrieveChildResourceRefs({int16}, -, f_getOriginator(vc_remoteCseIndex));
 							
-							if(not(v_deregistrationPerformed)) {
-								//Deregistration by Registree (IUT)
-								//Send trigger message for deregistration
-								v_utRequest.requestPrimitive.to_ := f_getLocalResourceAddress(vc_localRemoteCseIndex);
-								f_sendUtPrimitive(v_utRequest, v_action & f_getLocalResourceAddress(vc_localRemoteCseIndex));	
+							if(v_childResourceRefs != {}) {
+								//v_request := valueof(m_delete(v_childResourceRefs[0], f_getOriginator(vc_remoteCseIndex)));
+								v_request := valueof(m_delete(v_childResourceRefs[0]));//TODO Originator super user to be replaced by CSE1_ID (line above)
 								
+								mccPort.send(f_getMsgOutPrimitive(m_request(v_request)));
+	
 								tc_ac.start;
 								alt {
-									[] mccPortIn.receive(mw_request(mw_delete(f_getLocalResourceAddress(vc_localRemoteCseIndex)))) -> value vc_request {
+									[] mccPort.receive(mw_response(mw_responsePrimitiveOK)) {
 										tc_ac.stop;
-										f_processDeleteRequestPrimitive(vc_request.primitive.requestPrimitive);
-										mccPortIn.send(f_getMsgOutPrimitive(m_response(vc_response.primitive.responsePrimitive)));
-										log(__SCOPE__&": INFO: Deregistration performed successfully");
+										log(__SCOPE__&" INFO: Resource " & v_request.to_ & " deleted");
+										v_deregistrationPerformed := true;
 									}
-									[] tc_ac.timeout {
-										log(__SCOPE__&": INFO: No deregistration performed");
+									[] mccPort.receive(mw_response(mw_responsePrimitiveKO)) {
+										tc_ac.stop;
+										log(__SCOPE__&" INFO: Error while deleting resource " & v_request.to_);
 									}
+									[] tc_ac.timeout {
+										log(__SCOPE__&" INFO: No answer while deleting resource " & v_request.to_);
+									}	
+								}	
+							}	
+						}
+							
+						if(not(v_deregistrationPerformed)) {
+							//Deregistration by Registree (IUT) - Send trigger message for deregistration
+							v_utRequest.requestPrimitive.to_ := f_getLocalResourceAddress(vc_localRemoteCseIndex);
+							f_sendUtPrimitive(v_utRequest, v_action & f_getLocalResourceAddress(vc_localRemoteCseIndex));	
+							
+							tc_ac.start;
+							alt {
+								[] mccPortIn.receive(mw_request(mw_delete(f_getLocalResourceAddress(vc_localRemoteCseIndex)))) -> value vc_request {
+									tc_ac.stop;
+									f_processDeleteRequestPrimitive(vc_request.primitive.requestPrimitive);
+									mccPortIn.send(f_getMsgOutPrimitive(m_response(vc_response.primitive.responsePrimitive)));
+									log(__SCOPE__&": INFO: Deregistration performed successfully");
+								}
+								[] tc_ac.timeout {
+									log(__SCOPE__&": INFO: No deregistration performed");
 								}
 							}
 						}
@@ -1402,12 +1396,11 @@ module OneM2M_Functions {
 			 */
 			function f_cse_sendCreateRequestPrimitive(in ResourceType p_resourceType, template RequestPrimitive p_requestPrimitive := m_create, integer p_parentIndex := -1) runs on AeSimu{
 
-				var RequestPrimitive v_request;
 				var integer v_resourceIndex := -1;
 	
-				v_request := f_getCreateRequestPrimitive(p_resourceType, p_requestPrimitive, p_parentIndex);
+				vc_request.primitive.requestPrimitive := f_getCreateRequestPrimitive(p_resourceType, p_requestPrimitive, p_parentIndex);
 
-				mcaPort.send(f_getMsgOutPrimitive(m_request(v_request)));
+				mcaPort.send(f_getMsgOutPrimitive(m_request(vc_request.primitive.requestPrimitive)));
 
 			}
 			
@@ -1853,6 +1846,38 @@ module OneM2M_Functions {
 				
 			}//end of group AnnouncementFunctions
 			
+			/**
+			 * @desc Message exchange for the retrieval of a child resource refs
+			 * @param p_resourceType ResourceType of children of the resource to be retrieved
+			 * @param p_resourceIndex Resource index of the resource to be retrieved
+			 * @return PrimitiveContent parameter of the RETRIEVE response
+			 * @verdict 
+			 */
+			function f_cse_retrieveChildResourceRefs(template(omit) ResourceTypeList p_resourceTypeList := omit, integer p_targetResourceIndex := -1, XSD.ID p_originator := PX_SUPER_CSE_ID) runs on CseSimu return URIList {
+				var RequestPrimitive v_requestPrimitive;
+				var URIList v_uriList := {};
+				v_requestPrimitive := valueof(m_retrieveChildResourceRefs(f_getResourceAddress(p_targetResourceIndex), p_originator));
+				mccPort.send(f_getMsgOutPrimitive(m_request(v_requestPrimitive)));
+				tc_ac.start;
+				alt {
+					[] mccPort.receive(mw_response(mw_responsePrimitiveOK)) -> value vc_response {
+						tc_ac.stop;
+						setverdict(pass, __SCOPE__&":INFO: Resource retrieved successfuly");
+						v_uriList := vc_response.primitive.responsePrimitive.primitiveContent.uRIList;
+					}
+					[] mccPort.receive(mw_response(mw_responsePrimitiveKO)) {
+						tc_ac.stop;
+						setverdict(inconc, __SCOPE__&":INFO: Error while retrieving resource");
+					}
+					[] tc_ac.timeout {
+						setverdict(inconc, __SCOPE__&":INFO: No answer while retrieving resource");
+					}
+				}	
+				
+				return v_uriList;
+				
+ 			}// end f_cse_retrieveResourceChildren
+			
 			/**
 			 * @desc Check that a resource is present in the IUT (resourceId is known)
 			 * @param p_resourceIndex Resource index 
@@ -2097,7 +2122,6 @@ module OneM2M_Functions {
 						}
 						v_myResource.remoteCSE.resourceType := p_resourceType;
 						v_myResource.remoteCSE.resourceID := f_resourceIdCleaner(v_myResource.remoteCSE.cSE_ID);
-						//v_myResource.remoteCSE.resourceID := "remoteCSE-ID" & int2str(v_resourceIndex);
 						v_myResource.remoteCSE.parentID := f_getResourceId(vc_localResourcesList[p_parentIndex].resource);
 						v_myResource.remoteCSE.creationTime := fx_generateTimestamp();
 						v_myResource.remoteCSE.creationTime := "20171231T012345";
@@ -2122,11 +2146,11 @@ module OneM2M_Functions {
 				} else if (p_resourceType == int10002 and ispresent (p_resource)) { //AE Annc
 					if(ischosen(p_resource.aEAnnc)) {
 						v_myResource.aEAnnc := valueof(p_resource.aEAnnc);
-						
-						
-						v_myResource.aEAnnc.resourceName := "aEAnnc" & int2str(v_resourceIndex);
+						if(not(ispresent(p_resource.aEAnnc.resourceName))) {
+							v_myResource.aEAnnc.resourceName := "aEAnnc" & int2str(v_resourceIndex);
+						}
 						v_myResource.aEAnnc.resourceType := p_resourceType;
-						v_myResource.aEAnnc.resourceID := f_resourceIdCleaner(v_myResource.aEAnnc.aE_ID);
+						v_myResource.aEAnnc.resourceID := "aEA" & int2str(v_resourceIndex);
 						v_myResource.aEAnnc.parentID := f_getResourceId(vc_localResourcesList[p_parentIndex].resource);
 						v_myResource.aEAnnc.creationTime := fx_generateTimestamp();
 						v_myResource.aEAnnc.lastModifiedTime := v_myResource.aEAnnc.creationTime;
@@ -2134,10 +2158,11 @@ module OneM2M_Functions {
 				} else if (p_resourceType == int10001 and ispresent (p_resource)) { //Acp Annc
 					if(ischosen(p_resource.accessControlPolicyAnnc)) {
 						v_myResource.accessControlPolicyAnnc := valueof(p_resource.accessControlPolicyAnnc);
-						
-						v_myResource.accessControlPolicyAnnc.resourceName := "accessControlPolicyAnnc" & int2str(v_resourceIndex);
+						if(not(ispresent(p_resource.accessControlPolicyAnnc.resourceName))) {
+							v_myResource.accessControlPolicyAnnc.resourceName := "accessControlPolicyAnnc" & int2str(v_resourceIndex);
+						}
 						v_myResource.accessControlPolicyAnnc.resourceType := p_resourceType;
-						v_myResource.accessControlPolicyAnnc.resourceID := f_resourceIdCleaner(v_myResource.accessControlPolicyAnnc.resourceID);
+						v_myResource.accessControlPolicyAnnc.resourceID := "acpA" & int2str(v_resourceIndex);
 						v_myResource.accessControlPolicyAnnc.parentID := f_getResourceId(vc_localResourcesList[p_parentIndex].resource);
 						v_myResource.accessControlPolicyAnnc.creationTime := fx_generateTimestamp();
 						v_myResource.accessControlPolicyAnnc.lastModifiedTime := v_myResource.accessControlPolicyAnnc.creationTime;	
@@ -2145,10 +2170,11 @@ module OneM2M_Functions {
 				} else if (p_resourceType == int10003 and ispresent (p_resource)) { //Container Annc
 					if(ischosen(p_resource.containerAnnc)) {
 						v_myResource.containerAnnc := valueof(p_resource.containerAnnc);
-						
-						v_myResource.containerAnnc.resourceName := "containerAnnc" & int2str(v_resourceIndex);
+						if(not(ispresent(p_resource.containerAnnc.resourceName))) {
+							v_myResource.containerAnnc.resourceName := "containerAnnc" & int2str(v_resourceIndex);
+						}
 						v_myResource.containerAnnc.resourceType := p_resourceType;
-						v_myResource.containerAnnc.resourceID := f_resourceIdCleaner(v_myResource.containerAnnc.resourceID);
+						v_myResource.containerAnnc.resourceID := "cntA" & int2str(v_resourceIndex);
 						v_myResource.containerAnnc.parentID := f_getResourceId(vc_localResourcesList[p_parentIndex].resource);
 						v_myResource.containerAnnc.creationTime := fx_generateTimestamp();
 						v_myResource.containerAnnc.lastModifiedTime := v_myResource.containerAnnc.creationTime;
@@ -2156,10 +2182,11 @@ module OneM2M_Functions {
 				} else if (p_resourceType == int10009 and ispresent (p_resource)) { //Group Annc
 					if(ischosen(p_resource.groupAnnc)) {
 						v_myResource.groupAnnc := valueof(p_resource.groupAnnc);
-						
-						v_myResource.groupAnnc.resourceName := "groupAnnc" & int2str(v_resourceIndex);
+						if(not(ispresent(p_resource.groupAnnc.resourceName))) {
+							v_myResource.groupAnnc.resourceName := "groupAnnc" & int2str(v_resourceIndex);
+						}
 						v_myResource.groupAnnc.resourceType := p_resourceType;
-						v_myResource.groupAnnc.resourceID := f_resourceIdCleaner(v_myResource.groupAnnc.resourceID);
+						v_myResource.groupAnnc.resourceID := "grpA" & int2str(v_resourceIndex);
 						v_myResource.groupAnnc.parentID := f_getResourceId(vc_localResourcesList[p_parentIndex].resource);
 						v_myResource.groupAnnc.creationTime := fx_generateTimestamp();
 						v_myResource.groupAnnc.lastModifiedTime := v_myResource.groupAnnc.creationTime;
@@ -2167,10 +2194,11 @@ module OneM2M_Functions {
 				} else if (p_resourceType == int10014 and ispresent (p_resource)) { //ContentInstance Annc
 					if(ischosen(p_resource.contentInstanceAnnc)) {
 						v_myResource.contentInstanceAnnc := valueof(p_resource.contentInstanceAnnc);
-						
-						v_myResource.contentInstanceAnnc.resourceName := "contentInstanceAnnc" & int2str(v_resourceIndex);
+						if(not(ispresent(p_resource.contentInstanceAnnc.resourceName))) {
+							v_myResource.contentInstanceAnnc.resourceName := "contentInstanceAnnc" & int2str(v_resourceIndex);
+						}
 						v_myResource.contentInstanceAnnc.resourceType := p_resourceType;
-						v_myResource.contentInstanceAnnc.resourceID := f_resourceIdCleaner(v_myResource.contentInstanceAnnc.resourceID);
+						v_myResource.contentInstanceAnnc.resourceID := "cinA" & int2str(v_resourceIndex);
 						v_myResource.contentInstanceAnnc.parentID := f_getResourceId(vc_localResourcesList[p_parentIndex].resource);
 						v_myResource.contentInstanceAnnc.creationTime := fx_generateTimestamp();
 						v_myResource.contentInstanceAnnc.lastModifiedTime := v_myResource.contentInstanceAnnc.creationTime;
@@ -2178,19 +2206,19 @@ module OneM2M_Functions {
 				} else if (p_resourceType == int1 and ispresent (p_resource)) { //Acp Resource
 				   if(ischosen (p_resource.accessControlPolicy)){
 						v_myResource.accessControlPolicy := valueof(p_resource.accessControlPolicy);
-					
-					v_myResource.accessControlPolicy.resourceName := "accessControlPolicy" & int2str(v_resourceIndex);
-					v_myResource.accessControlPolicy.resourceType := p_resourceType;
-					v_myResource.accessControlPolicy.resourceID := "accessControlPolicy" & int2str(v_resourceIndex);
-					v_myResource.accessControlPolicy.parentID := f_getResourceId(vc_localResourcesList[p_parentIndex].resource);
-					v_myResource.accessControlPolicy.creationTime := fx_generateTimestamp();
-					if(not(ispresent(p_resource.accessControlPolicy.expirationTime))) {
-						v_myResource.accessControlPolicy.expirationTime := "20301231T012345";
-					}
-					v_myResource.accessControlPolicy.lastModifiedTime := v_myResource.accessControlPolicy.creationTime;											
-					v_myResource.accessControlPolicy.announceTo := omit;	
-					v_myResource.accessControlPolicy.announcedAttribute := omit;
-					
+						if(not(ispresent(p_resource.accessControlPolicy.resourceName))) {
+							v_myResource.accessControlPolicy.resourceName := "accessControlPolicy" & int2str(v_resourceIndex);
+						}
+						v_myResource.accessControlPolicy.resourceType := p_resourceType;
+						v_myResource.accessControlPolicy.resourceID := "acp" & int2str(v_resourceIndex);
+						v_myResource.accessControlPolicy.parentID := f_getResourceId(vc_localResourcesList[p_parentIndex].resource);
+						v_myResource.accessControlPolicy.creationTime := fx_generateTimestamp();
+						if(not(ispresent(p_resource.accessControlPolicy.expirationTime))) {
+							v_myResource.accessControlPolicy.expirationTime := "20301231T012345";
+						}
+						v_myResource.accessControlPolicy.lastModifiedTime := v_myResource.accessControlPolicy.creationTime;											
+						v_myResource.accessControlPolicy.announceTo := omit;	
+						v_myResource.accessControlPolicy.announcedAttribute := omit;
 				   }
 				} else if(p_resourceType == int2 and ispresent(p_resource)) {//AE
 					if(ischosen(p_resource.aE)){
@@ -2205,7 +2233,9 @@ module OneM2M_Functions {
 						}
 						v_myResource.aE.resourceID := "ae" & int2str(v_resourceIndex);
 						v_myResource.aE.aE_ID := v_myResource.aE.resourceID;
-						v_myResource.aE.resourceName := "ae" & int2str(v_resourceIndex);
+						if(not(ispresent(p_resource.aE.resourceName))) {
+							v_myResource.aE.resourceName := "ae" & int2str(v_resourceIndex);
+						}
 					}
 				} else if(p_resourceType == int3 and ispresent(p_resource)) {
 					if(ischosen(p_resource.container)){
@@ -2219,14 +2249,17 @@ module OneM2M_Functions {
 							v_myResource.container.expirationTime := "20301231T012345";
 						}
 						v_myResource.container.resourceID := "cnt" & int2str(v_resourceIndex);
-						v_myResource.container.resourceName := "cnt" & int2str(v_resourceIndex);
+						if(not(ispresent(p_resource.container.resourceName))) {
+							v_myResource.container.resourceName := "container" & int2str(v_resourceIndex);
+						}
 					}
-										
 				} else if(p_resourceType == int4 and ispresent(p_resource)) {
 					if(ischosen(p_resource.contentInstance)){
 						v_myResource.contentInstance := valueof(p_resource.contentInstance);
-						v_myResource.contentInstance.resourceID := "cnt" & int2str(v_resourceIndex);
-						v_myResource.contentInstance.resourceName := "cnt" & int2str(v_resourceIndex);
+						v_myResource.contentInstance.resourceID := "cin" & int2str(v_resourceIndex);
+						if(not(ispresent(p_resource.contentInstance.resourceName))) {
+							v_myResource.contentInstance.resourceName := "contentInstance" & int2str(v_resourceIndex);
+						}
 						v_myResource.contentInstance.resourceType := p_resourceType;
       					v_myResource.contentInstance.parentID := f_getResourceId(vc_localResourcesList[p_parentIndex].resource);
 						v_myResource.contentInstance.creationTime := fx_generateTimestamp();
@@ -2296,26 +2329,10 @@ module OneM2M_Functions {
 			 */
 			function f_cse_sendResponse(in MsgIn p_requestPrimitive) runs on CseSimu {
 				
-				var integer v_parentResourceIndex := -1;
-				var integer v_localResourceIndex := -1;
-				var ResponsePrimitive v_response;
-				var PrimitiveContent v_localResource;
 				
-				v_parentResourceIndex := f_getResourceIndex(p_requestPrimitive.primitive.requestPrimitive.to_);
-				if(v_parentResourceIndex == -1) {
-					log(__SCOPE__&": ERROR: Target resource not found");
-					v_response := valueof(m_responsePrimitive(int4004,p_requestPrimitive.primitive.requestPrimitive.requestIdentifier));
+				f_processCreateRequestPrimitive(p_requestPrimitive.primitive.requestPrimitive);
 				
-				} else {
-					v_localResource := f_generateLocalResource(p_requestPrimitive.primitive.requestPrimitive.primitiveContent, v_parentResourceIndex, p_requestPrimitive.primitive.requestPrimitive.resourceType);
-					v_localResourceIndex := f_setLocalResource(v_localResource, p_requestPrimitive.primitive.requestPrimitive.resourceType, v_parentResourceIndex);
-
-					v_response := valueof(m_responsePrimitive(int2001,p_requestPrimitive.primitive.requestPrimitive.requestIdentifier));
-					v_response.primitiveContent := vc_localResourcesList[v_localResourceIndex].resource;
-				}
-				v_response.from_ := PX_CSE1_ID;
-				v_response.to_ := p_requestPrimitive.primitive.requestPrimitive.from_;
-				mccPortIn.send(f_getMsgOutPrimitive(m_response(v_response)));
+				mccPortIn.send(f_getMsgOutPrimitive(m_response(vc_response.primitive.responsePrimitive)));
 			
 			}
 			
@@ -2323,15 +2340,20 @@ module OneM2M_Functions {
 			 * @desc   Receive response from the IUT
 			 * @param  p_requestPrimtive	Received request primitive
 			 */
-			function f_cse_receiveResponse() runs on AeSimu {
+			function f_cse_receiveResponse(in RequestPrimitive p_request) runs on AeSimu {
 				
-				var integer v_localResourceIndex := -1;
+				var integer v_resourceIndex := -1;
 				
+				//Activate defaults when running on a PTC
+			    f_cse_activateDefaults_ae(); 
+			    
 				tc_ac.start;
 				alt {
 					[] mcaPort.receive(mw_response(mw_responsePrimitiveOK)) -> value vc_response {
 						tc_ac.stop;
 						setverdict(pass, __SCOPE__&":INFO: Response received with positive response status code");
+						f_checkAttributesToBeSaved(p_request.resourceType, p_request, vc_response.primitive.responsePrimitive);
+						v_resourceIndex := f_setResource(vc_response.primitive.responsePrimitive.primitiveContent, p_request.resourceType);
 					}
 					[] mcaPort.receive(mw_response(mw_responsePrimitiveKO)) -> value vc_response {
 						tc_ac.stop;
@@ -3056,7 +3078,11 @@ module OneM2M_Functions {
 			
 			if(vc_resourcesList[p_targetResourceIndex].parentIndex == -1) {
 				if(ischosen(vc_resourcesList[p_targetResourceIndex].resource.aE)) {
-					return vc_resourcesList[p_targetResourceIndex].resource.aE.aE_ID;
+					if(isvalue(vc_resourcesList[p_targetResourceIndex].resource.aE.aE_ID)) {
+						return vc_resourcesList[p_targetResourceIndex].resource.aE.aE_ID;
+					} else {
+						return PX_SUPER_AE_ID;
+ 					}	
 				} else if (ischosen(vc_resourcesList[p_targetResourceIndex].resource.remoteCSE)) {
 					return vc_resourcesList[p_targetResourceIndex].resource.remoteCSE.cSE_ID; 
 				} else {
@@ -3322,7 +3348,7 @@ module OneM2M_Functions {
 			
 			v_newIndex := lengthof(vc_resourcesList)-1;
 			if(p_resourceToBeDeleted) {
-				if(match(int2, p_resourceType) or match(-1, p_parentIndex)) {//If created resource is an AE or created under CSEBase, it needs to be added to the resourceToBeDeleted list
+				if(p_resourceType == int2 or p_parentIndex == -1) {//If created resource is an AE or created under CSEBase, it needs to be added to the resourceToBeDeleted list
 					vc_resourcesIndexToBeDeleted := vc_resourcesIndexToBeDeleted & {v_newIndex};
 				}
 			}
@@ -3652,6 +3678,8 @@ module OneM2M_Functions {
 				 	f_cf02Down();
 				 }
 				 kill;
+			} else {
+				log(__SCOPE__, ":INFO: AeSimu status OK");
 			}
 		}
 		
@@ -3751,6 +3779,8 @@ module OneM2M_Functions {
 					f_cf02DownCseSimuMaster();
 				}
 				kill;
+			} else {
+				log(__SCOPE__, ":INFO: CseSimu status OK");
 			}
 		}
 		
diff --git a/LibOneM2M/OneM2M_Templates.ttcn b/LibOneM2M/OneM2M_Templates.ttcn
index 7d79c38..1c9b39e 100644
--- a/LibOneM2M/OneM2M_Templates.ttcn
+++ b/LibOneM2M/OneM2M_Templates.ttcn
@@ -128,8 +128,7 @@ module OneM2M_Templates {
 			 * @param p_targetResourceAddress Target resource address
 			 * @param p_originator Originator (from)
 			 */
-			template (value) RequestPrimitive m_retrieveChildReferences(XSD.ID p_targetResourceAddress, in XSD.ID p_originator, template (omit) ResourceTypeList p_resourceTypeList := omit) modifies m_retrieve := {
-				resultContent := int6, 
+			template (value) RequestPrimitive m_retrieveChildResourceRefs(XSD.ID p_targetResourceAddress, in XSD.ID p_originator, template (omit) ResourceTypeList p_resourceTypeList := omit) modifies m_retrieve := {
 				filterCriteria := {
 					createdBefore := omit,
 					createdAfter := omit,
@@ -145,7 +144,7 @@ module OneM2M_Templates {
 					sizeBelow := omit,
 					contentType_list := {},
 					attribute_list := {},
-					filterUsage := omit,
+					filterUsage := int1,
 					limit := omit
 				}
 			};
-- 
GitLab