Skip to content
Snippets Groups Projects
OneM2M_Functions.ttcn 312.65 KiB
/**
 *  Copyright Notification
 *  No part of this document may be reproduced, in an electronic retrieval system or otherwise, except as authorized by written permission.
 *  The copyright and the foregoing restriction extend to reproduction in all media.
 *  © 2016, oneM2M Partners Type 1 (ARIB, ATIS, CCSA, ETSI, TIA, TSDSI, TTA, TTC).
 *  All rights reserved.
 *  
 *  @author     oneM2M/ETSI
 *  @desc       Module containing functions for oneM2M
 *
 */
module OneM2M_Functions {
	
	import from XSD all;
	import from OneM2M_Templates all;
	import from OneM2M_Types all;
  import from OneM2M_Ports all;
	import from OneM2M_TypesAndValues all;
	import from OneM2M_TestSystem all;
	import from OneM2M_Pixits all;
	import from OneM2M_Pics all;
	import from LibCommon_Time all;
	
	group ConfigFunctions {
		
		/**
			@desc Ports mapping and default behaviour activation for Config 1
		*/
		function f_cf01Up(in boolean p_auxiliaryAe2Required := false) runs on AeSimu system CseSystem {
			
			// Variables
      		var charstring v_binding;
      		var charstring v_binding_in;
      		var charstring v_host;
			
			//Initialization of component variables
			vc_config := e_cf01;
			vc_testSystemRole := e_ae;	
			vc_aeSimuDesc := PX_TS_AE1;	
			
			// Map
			map(self:mcaPort, system:mcaPort) param (vc_aeSimuDesc.mcaPort);
			map(self:mcaPortIn, system:mcaPortIn) param (vc_aeSimuDesc.mcaPortIn);
			map(self:acPort, system:acPort);
			
			f_setProtocolBinding(vc_aeSimuDesc.mcaPort, vc_aeSimuDesc.mcaPortIn, v_binding, v_host, v_binding_in);
     	 	
			vc_myInterfaces[enum2int(valueof(InterfaceIds:e_mcaPort))] := { e_mcaPort, v_host, v_binding, vc_aeSimuDesc.mcaPort.serialization };
      		vc_myInterfaces[enum2int(valueof(InterfaceIds:e_mcaPortIn))] := { e_mcaPortIn, v_host, v_binding_in, vc_aeSimuDesc.mcaPortIn.serialization };
			
			activate(a_default());
			vc_aeSimu := activate(a_cse_cf01());
				
			// Initialize AE2
			if(p_auxiliaryAe2Required) {
				vc_auxiliaryAe2Up := p_auxiliaryAe2Required;
				vc_ae2 := AeSimu.create("AE2") alive;
				vc_ae2.start(f_cf01UpAe2());
				vc_ae2.done;
				f_connectInfoPort(vc_ae2);
			}
				
			//Initialze the IUT
							
		} // end f_cf01Up
		
		/**
			@desc Ports mapping and default behaviour activation for Config 1 on the auxiliary AE2
		*/
		function f_cf01UpAe2() runs on AeSimu system CseSystem {
			
			// Variables
			var charstring v_binding;
			var charstring v_binding_in;
      		var charstring v_host;
			
			//Initialization of component variables
			vc_config := e_cf01;
			vc_testSystemRole := e_ae;		
			vc_aeSimuDesc := PX_TS_AE2;	
			
			// Map
			map(self:mcaPort, system:mcaPort) param (vc_aeSimuDesc.mcaPort);
			map(self:mcaPortIn, system:mcaPortIn) param (vc_aeSimuDesc.mcaPortIn);
			map(self:acPort, system:acPort);
	
			f_setProtocolBinding(vc_aeSimuDesc.mcaPort, vc_aeSimuDesc.mcaPortIn, v_binding, v_host, v_binding_in);
		    
      		vc_myInterfaces[enum2int(valueof(InterfaceIds:e_mcaPort))] := { e_mcaPort, v_host, v_binding, vc_aeSimuDesc.mcaPort.serialization };
      		vc_myInterfaces[enum2int(valueof(InterfaceIds:e_mcaPortIn))] := { e_mcaPortIn, v_host, v_binding_in, vc_aeSimuDesc.mcaPortIn.serialization };
      
			//Initialze the IUT
							
		} // end f_cf01UpAe2
		
		/**
		 * @desc Ports mapping and default behaviour activation for Config 02
		 */
		function f_cf02Up(in CseTypeID p_cseType := int2, in boolean p_auxiliaryAe2Required := false) runs on AeSimu system CseSystem {
				
			// Variables
			var charstring v_binding;
			var charstring v_binding_in;
      		var charstring v_host;
			
			//Initialization of component variables
			vc_config := e_cf02;
			vc_testSystemRole := e_ae;	
			vc_cse1 := CseSimu.create("CSE1") alive;
			vc_aeSimuDesc := PX_TS_AE1;	
				
			// Map
			map(self:mcaPort, system:mcaPort) param (vc_aeSimuDesc.mcaPort);
			map(self:mcaPortIn, system:mcaPortIn) param (vc_aeSimuDesc.mcaPortIn);
			map(self:acPort, system:acPort);
			if(PX_UT_IMPLEMENTED) {
				map(self:utPort, system:utPort) param (PX_TS_UT);
			}

			f_setProtocolBinding(vc_aeSimuDesc.mcaPort, vc_aeSimuDesc.mcaPortIn, v_binding, v_host, v_binding_in);
		    
			vc_myInterfaces[enum2int(valueof(InterfaceIds:e_mcaPort))] := { e_mcaPort, v_host, v_binding, vc_aeSimuDesc.mcaPort.serialization };
			vc_myInterfaces[enum2int(valueof(InterfaceIds:e_mcaPortIn))] := { e_mcaPortIn, v_host, v_binding_in, vc_aeSimuDesc.mcaPortIn.serialization };
		      
			activate(a_default());
			vc_aeSimu := activate(a_cse_cf02_ae1());
			vc_cse1.start(f_cf02UpCse1(p_cseType));
			vc_cse1.done;
			
			// Initialize AE2
			if(p_auxiliaryAe2Required) {
				vc_auxiliaryAe2Up := p_auxiliaryAe2Required;
				vc_ae2 := AeSimu.create("AE2") alive;
				vc_ae2.start(f_cf02UpAe2());
				vc_ae2.done;
				f_connectInfoPort(vc_ae2);
			}
				
			// Connect
			f_connectInfoPort(vc_cse1);
			
			//Initialze the IUT
							
		} // end f_cf02Up
		
		/**
			@desc Ports mapping and default behaviour activation for Config 2 on the CSE1
		*/
		function f_cf02UpCse1(in CseTypeID p_cseType := int2) runs on CseSimu system CseSystem {
			
			// Variables
      		var charstring v_binding;
      		var charstring v_binding_in;
      		var charstring v_host;
			var PrimitiveContent v_cSEBaseResource;
			
			//Initialization of component variables
			vc_config := e_cf02;
			vc_testSystemRole := e_cse;		
			vc_cseType := p_cseType;
			vc_cseSimuDesc := PX_TS_CSE1;
			
			// Map
			map(self:mccPort, system:mccPort) param (vc_cseSimuDesc.mccPort);
			map(self:mccPortIn, system:mccPortIn) param (vc_cseSimuDesc.mccPortIn);
			map(self:acPort, system:acPort);
			
			f_setProtocolBinding(vc_cseSimuDesc.mccPort, vc_cseSimuDesc.mccPortIn, v_binding, v_host, v_binding_in);
		    
		    vc_myInterfaces[enum2int(valueof(InterfaceIds:e_mccPort))] := { e_mccPort, v_host, v_binding, vc_cseSimuDesc.mccPort.serialization };
		    vc_myInterfaces[enum2int(valueof(InterfaceIds:e_mccPortIn))] := { e_mccPortIn, v_host, v_binding, vc_cseSimuDesc.mccPortIn.serialization };
		      
			v_cSEBaseResource := f_generateLocalResource(m_primitiveContentCSEBase(m_contentCSEBase(vc_cseSimuDesc)), -1, int5);
			vc_cSEBaseIndex := f_setLocalResource(v_cSEBaseResource, int5, -1);
			
			//Initialze the IUT
							
		} // end f_cf02UpCse1

		/**
		 * @desc Ports mapping and default behaviour activation for Config 02
		 */
		function f_cf02UpCseSimuMaster(in CseTypeID p_cseType := int2, in boolean p_auxiliaryCse2Required := false) runs on CseSimu system CseSystem {
				
			// Variables
      		var charstring v_binding;
      		var charstring v_binding_in;
      		var charstring v_host;
			var PrimitiveContent v_cSEBaseResource;
			
			//Initialization of component variables
			vc_config := e_cf02CseSimuMaster;
			vc_testSystemRole := e_cse;	
			vc_cseType := p_cseType;
			vc_ae1 := AeSimu.create("AE1") alive;
			vc_cseSimuDesc := PX_TS_CSE1;
			
			//Initialization of local CSEBase
			v_cSEBaseResource := f_generateLocalResource(m_primitiveContentCSEBase(m_contentCSEBase(vc_cseSimuDesc)), -1, int5);
			vc_cSEBaseIndex := f_setLocalResource(v_cSEBaseResource, int5, -1);
				
			// Map
			map(self:mccPort, system:mccPort) param (vc_cseSimuDesc.mccPort);
			map(self:mccPortIn, system:mccPortIn) param (vc_cseSimuDesc.mccPortIn);
			map(self:acPort, system:acPort);
			if(PX_UT_IMPLEMENTED) {
				map(self:utPort, system:utPort) param (PX_TS_UT);
			}
			
			f_setProtocolBinding(vc_cseSimuDesc.mccPort, vc_cseSimuDesc.mccPortIn, v_binding, v_host, v_binding_in);
      
			vc_myInterfaces[enum2int(valueof(InterfaceIds:e_mccPort))] := { e_mccPort, v_host, v_binding, vc_cseSimuDesc.mccPort.serialization };
			vc_myInterfaces[enum2int(valueof(InterfaceIds:e_mccPortIn))] := { e_mccPortIn, v_host, v_binding_in, vc_cseSimuDesc.mccPortIn.serialization };
			
			activate(a_default());
			vc_cseSimu := activate(a_cse_cf02_cse1());
			vc_ae1.start(f_cf02UpAe1());
			vc_ae1.done;
			f_connectInfoPort(vc_ae1);
				
			//Initialize CSE2
			 if(p_auxiliaryCse2Required) {
				 vc_auxiliaryCse2Up := p_auxiliaryCse2Required;
				 vc_cse2 := CseSimu.create("CSE2") alive;
				 vc_cse2.start(f_cf02UpCse2());
				 vc_cse2.done;
				 connect(self:mccPortInternal, vc_cse2:mccPortInternal);
				 f_connectInfoPort(vc_cse2);
			 }	
			
			//Initialze the IUT
							
		} // end f_cf02UpCseSimuMaster
		
		function f_cf02UpCse2(in CseTypeID p_cseType := int2) runs on CseSimu system CseSystem {
				
			// Variables
      		var charstring v_binding;
      		var charstring v_binding_in;
      		var charstring v_host;
			var PrimitiveContent v_cSEBaseResource;
			
			//Initialization of component variables
			vc_config := e_cf02CseSimuMaster;
			vc_testSystemRole := e_cse;	
			vc_cseType := p_cseType;
			vc_cseSimuDesc := PX_TS_CSE2;
			
			//Initialization of local CSEBase
			v_cSEBaseResource := f_generateLocalResource(m_primitiveContentCSEBase(m_contentCSEBase(vc_cseSimuDesc)), -1, int5);
			vc_cSEBaseIndex := f_setLocalResource(v_cSEBaseResource, int5, -1);
				
			// Map
			map(self:mccPort, system:mccPort) param (vc_cseSimuDesc.mccPort);
			map(self:mccPortIn, system:mccPortIn) param (vc_cseSimuDesc.mccPortIn);
			map(self:acPort, system:acPort);
			if(PX_UT_IMPLEMENTED) {
				map(self:utPort, system:utPort) param (PX_TS_UT);
			}
			
			f_setProtocolBinding(vc_cseSimuDesc.mccPort, vc_cseSimuDesc.mccPortIn, v_binding, v_host, v_binding_in);
      
			vc_myInterfaces[enum2int(valueof(InterfaceIds:e_mccPort))] := { e_mccPort, v_host, v_binding, vc_cseSimuDesc.mccPort.serialization };
			vc_myInterfaces[enum2int(valueof(InterfaceIds:e_mccPortIn))] := { e_mccPortIn, v_host, v_binding_in, vc_cseSimuDesc.mccPortIn.serialization };
				 
			activate(a_default());
			vc_cseSimu := activate(a_cse_cf02_cse1());
							
			//Initialze the IUT
							
		} // end f_cf02UpCse2

		/**
			@desc Ports mapping and default behaviour activation for Config 2 on the AE1
		*/
		function f_cf02UpAe1(in CseTypeID p_cseType := int2) runs on AeSimu system CseSystem {
			
			// Variables
      		var charstring v_binding;
      		var charstring v_binding_in;
     		var charstring v_host;
			vc_config := e_cf02CseSimuMaster;	
			vc_testSystemRole := e_ae;	
			vc_aeSimuDesc := PX_TS_AE1;	
			
			// Map
			map(self:mcaPort, system:mcaPort) param (vc_aeSimuDesc.mcaPort);
			map(self:mcaPortIn, system:mcaPortIn) param (vc_aeSimuDesc.mcaPortIn);
			map(self:acPort, system:acPort);
			
			f_setProtocolBinding(vc_aeSimuDesc.mcaPort, vc_aeSimuDesc.mcaPortIn, v_binding, v_host, v_binding_in);
      
			vc_myInterfaces[enum2int(valueof(InterfaceIds:e_mcaPort))] := { e_mcaPort, v_host, v_binding, vc_aeSimuDesc.mcaPort.serialization };
			vc_myInterfaces[enum2int(valueof(InterfaceIds:e_mcaPortIn))] := { e_mcaPortIn, v_host, v_binding_in, vc_aeSimuDesc.mcaPortIn.serialization };
      
			//Initialze the IUT
							
		} // end f_cf02UpAe1
		
		/**
			@desc Ports mapping and default behaviour activation for Config 2 on the auxiliary AE2
		*/
		function f_cf02UpAe2() runs on AeSimu system CseSystem {
			
			// Variables
			var charstring v_binding;
			var charstring v_binding_in;
			var charstring v_host;
			
			//Initialization of component variables
			vc_config := e_cf02;
			vc_testSystemRole := e_ae;		
			vc_aeSimuDesc := PX_TS_AE2;	
			
			// Map
			map(self:mcaPort, system:mcaPort) param (vc_aeSimuDesc.mcaPort);
			map(self:mcaPortIn, system:mcaPortIn) param (vc_aeSimuDesc.mcaPortIn);
			map(self:acPort, system:acPort);
	
			f_setProtocolBinding(vc_aeSimuDesc.mcaPort, vc_aeSimuDesc.mcaPortIn, v_binding, v_host, v_binding_in);
		    
			vc_myInterfaces[enum2int(valueof(InterfaceIds:e_mcaPort))] := { e_mcaPort, v_host, v_binding, vc_aeSimuDesc.mcaPort.serialization };
			vc_myInterfaces[enum2int(valueof(InterfaceIds:e_mcaPortIn))] := { e_mcaPortIn, v_host, v_binding_in, vc_aeSimuDesc.mcaPortIn.serialization };
      
			//Initialze the IUT
							
		} // end f_cf02UpAe2
		
		/**
		 * @desc Ports mapping and default behaviour activation for Config 03
		 */
		function f_cf03Up(in CseTypeID p_cseType := int2, in boolean p_auxiliaryCse2Required := false) runs on CseSimu system AeSystem {
		
			// Variables
      		var charstring v_binding;
			var charstring v_binding_in;
			var PrimitiveContent v_cSEBaseResource;
      		var charstring v_host;
			
			//Initialization of component variables
			vc_config := e_cf03;
			vc_testSystemRole := e_cse;	
			vc_cseType := p_cseType;	
			vc_cseSimuDesc := PX_TS_CSE1;	
			
			//Creation of CSEBase
			v_cSEBaseResource := f_generateLocalResource(m_primitiveContentCSEBase(m_contentCSEBase(vc_cseSimuDesc)), -1, int5);
			vc_cSEBaseIndex := f_setLocalResource(v_cSEBaseResource, int5, -1);
			
			// Map
			map(self:mcaPort, system:mcaPort) param (vc_cseSimuDesc.mcaPort);//TODO To be consistent, we should use mcaPortIn for AE testing
			map(self:mcaPortIn, system:mcaPortIn) param (vc_cseSimuDesc.mcaPortIn);//TODO To be consistent, we should use mcaPortIn for AE testing
			map(self:acPort, system:acPort);
			
			f_setProtocolBinding(vc_cseSimuDesc.mcaPort, vc_cseSimuDesc.mcaPortIn, v_binding, v_host, v_binding_in);
      		
			vc_myInterfaces[enum2int(valueof(InterfaceIds:e_mcaPort))] := { e_mcaPort, v_host, v_binding, vc_cseSimuDesc.mcaPort.serialization };
			vc_myInterfaces[enum2int(valueof(InterfaceIds:e_mcaPortIn))] := { e_mcaPortIn, v_host, v_binding_in, vc_cseSimuDesc.mcaPortIn.serialization };
			
			if(PX_UT_IMPLEMENTED) {
				map(self:utPort, system:utPort) param (PX_TS_UT);
			}
			activate(a_default());
			vc_cseSimu := activate(a_cse_cf03());
		
			// Initialize CSE2
			if(p_auxiliaryCse2Required) {
				vc_auxiliaryCse2Up := p_auxiliaryCse2Required;
				vc_cse2 := CseSimu.create("CSE2") alive;
				vc_cse2.start(f_cf03UpCse2());
				vc_cse2.done;
				f_connectInfoPort(vc_cse2);
			}
					
			//Initialze the IUT
					
		} // end f_cf03Up
		
		
		/**
			@desc Ports mapping and default behaviour activation for Config 3 on the auxiliary CSE2
		*/
		function f_cf03UpCse2(in CseTypeID p_cseType := int2) runs on CseSimu system AeSystem {
			
			// Variables
			var charstring v_binding;
			var charstring v_binding_in;
			var charstring v_host;
			var PrimitiveContent v_cSEBaseResource;
			
			//Initialization of component variables	
			vc_config := e_cf03;
			vc_testSystemRole := e_cse;	
			vc_cseType := p_cseType;	
			vc_cseSimuDesc := PX_TS_CSE2;	
			
			// Map
			map(self:mcaPort, system:mcaPort) param (vc_cseSimuDesc.mcaPort);
			map(self:mcaPortIn, system:mcaPortIn) param (vc_cseSimuDesc.mcaPortIn);
			map(self:acPort, system:acPort);
	
			f_setProtocolBinding(vc_cseSimuDesc.mcaPort, vc_cseSimuDesc.mcaPortIn, v_binding, v_host, v_binding_in);
		    
			vc_myInterfaces[enum2int(valueof(InterfaceIds:e_mcaPort))] := { e_mcaPort, v_host, v_binding, vc_cseSimuDesc.mcaPort.serialization };
			vc_myInterfaces[enum2int(valueof(InterfaceIds:e_mcaPortIn))] := { e_mcaPortIn, v_host, v_binding, vc_cseSimuDesc.mcaPortIn.serialization };
      
			v_cSEBaseResource := f_generateLocalResource(m_primitiveContentCSEBase(m_contentCSEBase(vc_cseSimuDesc)), -1, int5);
			vc_cSEBaseIndex := f_setLocalResource(v_cSEBaseResource, int5, -1);
							
		} // end f_cf03UpCse2
		
		/**
		 * @desc Ports mapping and default behaviour activation for Config 04
		 */
		function f_cf04Up(in CseTypeID p_cseType := int2, in boolean p_auxiliaryCse2Required := false) runs on CseSimu system CseSystem {

			// Variables
			var charstring v_binding;
			var charstring v_binding_in;
			var PrimitiveContent v_cSEBaseResource;
	  		var charstring v_host;
			
			//Initialization of component variables
			vc_config := e_cf04;
			vc_testSystemRole := e_cse;	
			vc_cseType := p_cseType;			
			vc_cseSimuDesc := PX_TS_CSE1;
			
			////Initialization of local CSEBase
			v_cSEBaseResource := f_generateLocalResource(m_primitiveContentCSEBase(m_contentCSEBase(vc_cseSimuDesc)), -1, int5);
			vc_cSEBaseIndex := f_setLocalResource(v_cSEBaseResource, int5, -1);
			
			// Map
			map(self:mccPort, system:mccPort) param (vc_cseSimuDesc.mccPort);
			map(self:mccPortIn, system:mccPortIn) param (vc_cseSimuDesc.mccPortIn);
			map(self:acPort, system:acPort);
			if(PX_UT_IMPLEMENTED) {
				map(self:utPort, system:utPort) param (PX_TS_UT);
			}
			
			f_setProtocolBinding(vc_cseSimuDesc.mccPort, vc_cseSimuDesc.mccPortIn, v_binding, v_host, v_binding_in);
      
      		vc_myInterfaces[enum2int(valueof(InterfaceIds:e_mccPort))] := { e_mccPort, v_host, v_binding, vc_cseSimuDesc.mccPort.serialization };
      		vc_myInterfaces[enum2int(valueof(InterfaceIds:e_mccPortIn))] := { e_mccPortIn, v_host, v_binding_in, vc_cseSimuDesc.mccPortIn.serialization };
      
      		activate(a_default());
			vc_cseSimu := activate(a_cse_cf04());

			//Initialize CSE2
			if(p_auxiliaryCse2Required) {
				vc_auxiliaryCse2Up := p_auxiliaryCse2Required;
				vc_cse2 := CseSimu.create("CSE2") alive;
				vc_cse2.start(f_cf04UpCse2());
				vc_cse2.done;
				f_connectInfoPort(vc_cse2);
			}
			
			// Connect
			
			//Initialize the IUT
			
		} // end f_cf04Up
		
		
		/**
			@desc Ports mapping and default behaviour activation for Config 4 on the CSE2
		*/
		function f_cf04UpCse2(in CseTypeID p_cseType := int2) runs on CseSimu system CseSystem {
			
			// Variables
			var charstring v_binding;
			var charstring v_binding_in;
			var charstring v_host;
			var PrimitiveContent v_cSEBaseResource;
			
			//Initialization of component variables
			vc_config := e_cf04;
			vc_testSystemRole := e_cse;		
			vc_cseType := p_cseType;
			vc_cseSimuDesc := PX_TS_CSE2;
			
			// Map
			map(self:mccPort, system:mccPort) param (vc_cseSimuDesc.mccPort);
			map(self:mccPortIn, system:mccPortIn) param (vc_cseSimuDesc.mccPortIn);
			map(self:acPort, system:acPort);
						
			f_setProtocolBinding(vc_cseSimuDesc.mccPort, vc_cseSimuDesc.mccPortIn, v_binding, v_host, v_binding_in);
            
			vc_myInterfaces[enum2int(valueof(InterfaceIds:e_mccPort))] := { e_mccPort, v_host, v_binding, vc_cseSimuDesc.mccPort.serialization };
			vc_myInterfaces[enum2int(valueof(InterfaceIds:e_mccPortIn))] := { e_mccPortIn, v_host, v_binding, vc_cseSimuDesc.mccPortIn.serialization };
      
			v_cSEBaseResource := f_generateLocalResource(m_primitiveContentCSEBase(m_contentCSEBase(vc_cseSimuDesc)), -1, int5);
			vc_cSEBaseIndex := f_setLocalResource(v_cSEBaseResource, int5, -1);
			
			//Initialze the IUT
							
		} // end f_cf04UpCse2		
		
		/**
			@desc Ports mapping and default behaviour activation for Config 5
		*/
		function f_cf05Up() runs on ScefSimu system ScefSystem {
			
			// Variables
			
			//Initialization of component variables
			vc_config := e_cf05;
			vc_testSystemRole := e_t8;	
			vc_aeSimuDesc := PX_TS_AE1;	
			vc_scefSimuDesc := PX_T8_SCEF;
			
			// Map
			map(self:mcnPort, system:mcnPort) param (vc_scefSimuDesc.mcnPort);
			map(self:mcnPortIn, system:mcnPortIn) param (vc_scefSimuDesc.mcnPortIn);
			map(self:acPort, system:acPort);
			
			activate(a_default());
			
			vc_ae1 := AeSimu.create("AE1") alive;
			vc_ae1.start(f_cf01Up());
			vc_ae1.done;
			f_connectInfoPort(vc_ae1);
			
		} // end f_cf05Up
		
		/**
		 * @desc Ports mapping and default behaviour activation for Config 06
		 */
		function f_cf06Up() runs on AeSimu system CseSystem {
				
			// Variables
			var charstring v_binding;
			var charstring v_binding_in;
			var charstring v_host;
			vc_config := e_cf06;
			vc_testSystemRole := e_ae;	
			vc_aeSimuDesc := PX_TS_AE1;	
			
			// Map
			map(self:mcaPort, system:mcaPort) param (vc_aeSimuDesc.mcaPort);
			map(self:mcaPortIn, system:mcaPortIn) param (vc_aeSimuDesc.mcaPortIn);
			map(self:acPort, system:acPort);
			if(PX_UT_IMPLEMENTED) {
				map(self:utPort, system:utPort);
			}
			
			f_setProtocolBinding(vc_aeSimuDesc.mcaPort, vc_aeSimuDesc.mcaPortIn, v_binding, v_host, v_binding_in);
			
			vc_myInterfaces[enum2int(valueof(InterfaceIds:e_mcaPort))] := { e_mcaPort, v_host, v_binding, vc_aeSimuDesc.mcaPort.serialization };
      		vc_myInterfaces[enum2int(valueof(InterfaceIds:e_mcaPortIn))] := { e_mcaPortIn, v_host, v_binding_in, vc_aeSimuDesc.mcaPortIn.serialization };
			
			activate(a_default());
			vc_aeSimu := activate(a_cse_cf06_ae1()); 
			
			//Create DAS
			vc_das := AeSimu.create("DAS") alive;
			vc_das.start(f_cf06UpDas());
			vc_das.done;
			f_connectInfoPort(vc_das);
			
								
		} // end f_cf06Up		

		/**
			@desc Ports mapping and default behaviour activation for Config 06 on the DAS
		*/
		function f_cf06UpDas() runs on AeSimu system CseSystem {
			
			// Variables
			var charstring v_binding;
			var charstring v_binding_in;
			var charstring v_host;
			vc_config := e_cf06;
			vc_testSystemRole := e_das;		
			vc_dasSimuDesc := PX_TS_DAS;	
			
			// Map
			map(self:mcaPort, system:mcaPort) param (vc_dasSimuDesc.mcaPort);
			map(self:mcaPortIn, system:mcaPortIn) param (vc_dasSimuDesc.mcaPortIn);
			map(self:acPort, system:acPort);
			
			f_setProtocolBinding(vc_dasSimuDesc.mcaPort, vc_dasSimuDesc.mcaPortIn, v_binding, v_host, v_binding_in);

			vc_myInterfaces[enum2int(valueof(InterfaceIds:e_mcaPort))] := { e_mcaPort, v_host, v_binding, vc_dasSimuDesc.mcaPort.serialization };
      		vc_myInterfaces[enum2int(valueof(InterfaceIds:e_mcaPortIn))] := { e_mcaPortIn, v_host, v_binding_in, vc_dasSimuDesc.mcaPortIn.serialization };
			
			activate(a_default());
			vc_aeSimu := activate(a_cse_cf06_das()); 
							
		} // end f_cf02UpCse1

		/**
		 * @desc Ports mapping and default behaviour activation for Config 06 (reversed)
		 */
		function f_cf06UpDasSimuMaster() runs on AeSimu system CseSystem {
				
			// Variables
			var charstring v_binding;
			var charstring v_binding_in;
			var charstring v_host;
			vc_config := e_cf06DasSimuMaster;
			vc_testSystemRole := e_das;	
			vc_dasSimuDesc := PX_TS_DAS;	
			
			// Map
			map(self:mcaPort, system:mcaPort) param (vc_dasSimuDesc.mcaPort);
			map(self:mcaPortIn, system:mcaPortIn) param (vc_dasSimuDesc.mcaPortIn);
			map(self:acPort, system:acPort);
			
			f_setProtocolBinding(vc_dasSimuDesc.mcaPort, vc_dasSimuDesc.mcaPortIn, v_binding, v_host, v_binding_in);

			vc_myInterfaces[enum2int(valueof(InterfaceIds:e_mcaPort))] := { e_mcaPort, v_host, v_binding, vc_dasSimuDesc.mcaPort.serialization };
      		vc_myInterfaces[enum2int(valueof(InterfaceIds:e_mcaPortIn))] := { e_mcaPortIn, v_host, v_binding_in, vc_dasSimuDesc.mcaPortIn.serialization };
			
			activate(a_default());
			vc_aeSimu := activate(a_cse_cf06_das()); 

			//Create AE
			vc_ae1 := AeSimu.create("AE1") alive;
			vc_ae1.start(f_cf06UpAe1());
			vc_ae1.done;
			f_connectInfoPort(vc_ae1);
			
										
		} // end f_cf06UpDasSimuMaster

		/**
			@desc Ports mapping and default behaviour activation for Config 06 (reversed) on the AE1
		*/
		function f_cf06UpAe1() runs on AeSimu system CseSystem {
			
			// Variables
			var charstring v_binding;
			var charstring v_binding_in;
			var charstring v_host;
			vc_config := e_cf06DasSimuMaster;	
			vc_testSystemRole := e_ae;	
			vc_aeSimuDesc := PX_TS_AE1;	
			
			// Map
			map(self:mcaPort, system:mcaPort) param (vc_aeSimuDesc.mcaPort);
			map(self:mcaPortIn, system:mcaPortIn) param (vc_aeSimuDesc.mcaPortIn);
			map(self:acPort, system:acPort);
			if(PX_UT_IMPLEMENTED) {
				map(self:utPort, system:utPort);
			}
		
			f_setProtocolBinding(vc_aeSimuDesc.mcaPort, vc_aeSimuDesc.mcaPortIn, v_binding, v_host, v_binding_in);
     	 	
			vc_myInterfaces[enum2int(valueof(InterfaceIds:e_mcaPort))] := { e_mcaPort, v_host, v_binding, vc_aeSimuDesc.mcaPort.serialization };
      		vc_myInterfaces[enum2int(valueof(InterfaceIds:e_mcaPortIn))] := { e_mcaPortIn, v_host, v_binding_in, vc_aeSimuDesc.mcaPortIn.serialization };
      
			activate(a_default());
			vc_aeSimu := activate(a_cse_cf06_ae1()); 

			// Connect
		}			

		function f_cf07Up(in CseTypeID p_cseType := int2)  runs on CseSimu system AeSystem {
    
			// Variables
			var charstring v_binding;
			var charstring v_binding_in;
			var PrimitiveContent v_cSEBaseResource;
			var charstring v_host;
			vc_cseSimuDesc := PX_TS_CSE1;	
		
			//Initialization of component variables
			vc_config := e_cf07;
			vc_testSystemRole := e_cse; 
			vc_cseType := p_cseType;
			
			//Creation of CSEBase
			v_cSEBaseResource := f_generateLocalResource(-, -1, int5);
			vc_cSEBaseIndex := f_setLocalResource(v_cSEBaseResource, int5, -1);
			
			// Map
			map(self:mcaPort, system:mcaPort) param (vc_cseSimuDesc.mcaPort);//TODO To be consistent, we should use mcaPortIn for AE testing
			map(self:mcaPortIn, system:mcaPortIn) param (vc_cseSimuDesc.mcaPortIn);//TODO To be consistent, we should use mcaPortIn for AE testing
			map(self:acPort, system:acPort);
			

			f_setProtocolBinding(vc_cseSimuDesc.mcaPort, vc_cseSimuDesc.mcaPortIn, v_binding, v_host, v_binding_in);
     	 	
			vc_myInterfaces[enum2int(valueof(InterfaceIds:e_mcaPort))] := { e_mcaPort, v_host, v_binding, vc_cseSimuDesc.mcaPort.serialization };
      		vc_myInterfaces[enum2int(valueof(InterfaceIds:e_mcaPortIn))] := { e_mcaPortIn, v_host, v_binding_in, vc_cseSimuDesc.mcaPortIn.serialization };

			if(PX_UT_IMPLEMENTED) {
			  map(self:utPort, system:utPort) param (PX_TS_UT);
			}
			activate(a_default());
			vc_cseSimu := activate(a_cse_cf07());
			
			// Connect
          
			//Initialze the IUT
          
		} // End of function f_cf07Up
		
		/**
		 * @desc Ports unmapping
		 */
		function f_cf01Down() runs on AeSimu {
		
			unmap(self:mcaPort, system:mcaPort);
			unmap(self:acPort, system:acPort);
			if(vc_auxiliaryAe2Up) {
				if(vc_ae2.alive) {
					vc_ae2.start(f_cf01DownAe2());
					vc_ae2.done;
					f_disconnectInfoPort(vc_ae2);
				}
			}
		
		}// end f_cf01Down
		
		/**
		 * @desc Ports unmapping
		 */
		function f_cf01DownAe2() runs on AeSimu {
				
			unmap(self:mcaPort, system:mcaPort);
			unmap(self:acPort, system:acPort);
			unmap(self:mcaPortIn, system:mcaPortIn);
		
		}// end f_cf01DownAe2
		
		/**
		 * @desc Ports unmapping
		 */
		function f_cf02Down() runs on AeSimu {
		
			unmap(self:mcaPort, system:mcaPort);
			unmap(self:acPort, system:acPort);
			if(PX_UT_IMPLEMENTED){
				unmap(self:utPort, system:utPort);
			}
			
			if(vc_cse1.alive) {
				vc_cse1.start(f_cf02DownCse());
				vc_cse1.done;
				f_disconnectInfoPort(vc_cse1);
			}
		
		}// end f_cf02Down
		
		/**
		 * @desc Ports unmapping
		 */
		function f_cf02DownCseSimuMaster() runs on CseSimu {
				
			unmap(self:mccPort, system:mccPort);
			unmap(self:mccPortIn, system:mccPortIn);
			unmap(self:acPort, system:acPort);
			if(PX_UT_IMPLEMENTED){
				unmap(self:utPort, system:utPort);
			}
			if (vc_cseSimuDesc.cseName != "CSE2_NAME") {
				if(vc_ae1.alive) {
					vc_ae1.start(f_cf02DownAe());
					vc_ae1.done;
					f_disconnectInfoPort(vc_ae1);
				}
				if(vc_auxiliaryCse2Up) {
					if(vc_cse2.alive) {
						vc_cse2.start(f_cf02DownCse());
						vc_cse2.done;
						disconnect(self:mccPortInternal, vc_cse2:mccPortInternal);
						f_disconnectInfoPort(vc_cse2);
					}
				}
			}
		
		}// end f_cf02DownCseSimuMaster
		
		/**
		 * @desc Ports unmapping
		 */
		function f_cf02DownCse() runs on CseSimu {
				
			unmap(self:mccPort, system:mccPort);
			unmap(self:mccPortIn, system:mccPortIn);
			unmap(self:acPort, system:acPort);
			if(PX_UT_IMPLEMENTED){
				unmap(self:utPort, system:utPort);
			}
			
		
		}// end f_cf02DownCse
		
		/**
		 * @desc Ports unmapping
		 */
		function f_cf02DownAe() runs on AeSimu {
				
			unmap(self:mcaPort, system:mcaPort);
			unmap(self:mcaPortIn, system:mcaPortIn);
			unmap(self:acPort, system:acPort);
			if(PX_UT_IMPLEMENTED){
				unmap(self:utPort, system:utPort);
			}
			
		
		}// end f_cf02DownCse
		
		/**
		 * @desc Ports unmapping for Config 03
		 */
		function f_cf03Down() runs on CseSimu {
			
			unmap(self:mcaPortIn, system:mcaPortIn);
			unmap(self:acPort, system:acPort);
			if(PX_UT_IMPLEMENTED){
				unmap(self:utPort, system:utPort);
			}
			if(vc_auxiliaryCse2Up) {
				if(vc_cse2.alive) {
					vc_cse2.start(f_cf03DownCse2());
					vc_cse2.done;
					disconnect(self:mccPortInternal, vc_cse2:mccPortInternal);
					f_disconnectInfoPort(vc_cse2);
				}
			}
		}// end f_cf03Down
		
		/**
		 * @desc Ports unmapping
		 */
		function f_cf03DownCse2() runs on CseSimu {
				
			unmap(self:mccPort, system:mccPort);
			unmap(self:acPort, system:acPort);
			unmap(self:mccPortIn, system:mccPortIn);
		
		}// end f_cf03DownCse2
		
		/**
		 * @desc Ports unmapping for Config 04
		 */
		function f_cf04Down() runs on CseSimu {
	
			unmap(self:mccPort, system:mccPort);
			unmap(self:mccPortIn, system:mccPortIn);
			unmap(self:acPort, system:acPort);
			if(PX_UT_IMPLEMENTED){
				unmap(self:utPort, system:utPort);
			}
			if(vc_auxiliaryCse2Up) {
				if(vc_cse2.alive) {
					vc_cse2.start(f_cf04DownCse2());
					vc_cse2.done;
					disconnect(self:mccPortInternal, vc_cse2:mccPortInternal);
					f_disconnectInfoPort(vc_cse2);
				}
			}
		}// end f_cf04Down

		/**
		 * @desc Ports unmapping
		 */
		function f_cf04DownCse2() runs on CseSimu {
				
			unmap(self:mccPort, system:mccPort);
			unmap(self:acPort, system:acPort);
			unmap(self:mccPortIn, system:mccPortIn);
		
		}// end f_cf04DownCse2

		function f_cf05Down() runs on ScefSimu system ScefSystem {
			
			unmap(self:mcnPort, system:mcnPort);
			unmap(self:mcnPortIn, system:mcnPortIn);
			unmap(self:acPort, system:acPort);
			
			if(vc_ae1.alive) {
				vc_ae1.start(f_cf01Down());
				vc_ae1.done;
				f_disconnectInfoPort(vc_ae1);
			}
			
			
		} // end f_cf05Down
		
		/**
		 * @desc Ports unmapping for Config 06
		 */
		function f_cf06Down() runs on AeSimu {
		
			unmap(self:mcaPort, system:mcaPort);
			unmap(self:mcaPortIn, system:mcaPortIn);
			unmap(self:acPort, system:acPort);
			if(PX_UT_IMPLEMENTED){
				unmap(self:utPort, system:utPort);
			}
			if(vc_das.alive) {
				vc_das.start(f_cf01Down());
				vc_das.done;
				f_disconnectInfoPort(vc_das);
			}
			
		}// end f_cf06Down
		
		/**
		* @desc Ports unmapping for Config 06
		*/
		function f_cf06DownDasSimuMaster() runs on AeSimu {
				
			unmap(self:mcaPort, system:mcaPort);
			unmap(self:mcaPortIn, system:mcaPortIn);
			unmap(self:acPort, system:acPort);
			if(PX_UT_IMPLEMENTED) {
				unmap(self:utPort, system:utPort);
			}
			
			if(vc_ae1.alive) {
				vc_ae1.start(f_cf01Down());
				vc_ae1.done;
				f_disconnectInfoPort(vc_ae1);
			}
			
		}// end f_cf06DownCseSimuMaster
		
		
		function f_cf07Down()  runs on CseSimu system AeSystem {
			
			unmap(self:mcaPort, system:mcaPort);
			unmap(self:mcaPortIn, system:mcaPortIn);
			unmap(self:acPort, system:acPort);
			if(PX_UT_IMPLEMENTED){
			  unmap(self:utPort, system:utPort);
			}
			
		} // End of function f_cfDown
		
	}//end group configFunctions
	
	group InfoPortCommunication {
	
		/**
		 * @desc Connection of InfoPort of two components
		 * @param p_tester PTC where InfoPort is to be connected
		 */
		function f_connectInfoPort(in Tester p_tester) runs on Tester {
			// Connect
			connect(self:infoPort, p_tester:infoPort);		
		} 
	
		/**
		 * @desc Disconnection of InfoPort of two components
		 * @param p_tester PTC where InfoPort is to be connected
		 */
		function f_disconnectInfoPort(in Tester p_tester) runs on Tester {
			// Disconnect
			disconnect(self:infoPort, p_tester:infoPort);		
		} 
		
		group getFunctions {
			/**
			 * @desc Getting last responsePrimitive saved in a component
			 * @param p_tester Given component
			 */
			function f_getResponsePrimitive(in Tester p_component) runs on Tester return ResponsePrimitive {
				var ResponsePrimitive v_response;
				
				f_connectInfoPort(p_component);
				
				p_component.start(f_sendResponsePrimitive());
				alt {
					[]infoPort.receive(mw_responsePrimitiveforInfoPort) -> value v_response {
					}
				}
				
				p_component.done;
				
				f_disconnectInfoPort(p_component);
				
				return v_response;
					
			}
			
			/**
			 * @desc Getting last requestPrimitive saved in an AeSimu component
			 * @param p_tester Given component
			 */
			function f_getRequestPrimitive(in Tester p_component) runs on Tester return RequestPrimitive {
				var RequestPrimitive v_request;
	
				f_connectInfoPort(p_component);
				
				p_component.start(f_sendRequestPrimitive());
				alt {
					[]infoPort.receive(mw_requestPrimitiveforInfoPort) -> value v_request {
					}
				}
	
				p_component.done;
				
				f_disconnectInfoPort(p_component);
				
				return v_request;
		
			}
								
			/**
			 * @desc Getting primitiveContent retrieved in an AeSimu component
			 * @param p_tester AeSimu component
			 */
			function f_getPrimitiveContentRetrievedResource(in AeSimu p_ae) runs on Tester return PrimitiveContent {
				var PrimitiveContent v_primitiveContent;
				
				f_connectInfoPort(p_ae);
				p_ae.start(f_sendPrimitiveContentRetrievedResource());
				alt {
					[]infoPort.receive(mw_primitiveContent) -> value v_primitiveContent {
					}
				}
		
				p_ae.done;
				f_disconnectInfoPort(p_ae);
					
				return v_primitiveContent;
					
			}
			
			/**
			 * @desc Getting remoteCSE resource from a CseSimu component
			 * @param p_tester CseSimu component
			 */
			function f_getRemoteCseResource(in CseSimu p_cse) runs on Tester return integer {
				var MyResource v_resource;
				var integer v_resourceIndex := -1;
				
				p_cse.start(f_sendRemoteCseResource());
				alt {
					[]infoPort.receive(mw_resource) -> value v_resource {
						v_resourceIndex := f_setResource(v_resource.resource, v_resource.resourceType, v_resource.parentIndex, false);
					}
				}
		
				p_cse.done;
				
				return v_resourceIndex;
					
			}
			
			/**
			 * @desc Getting a specific resource from an AeSimu component
			 * @param p_tester AeSimu component
			 * @param p_resourceIndex Index of resource to be retrieved
			 */
			function f_getResourceFromAeSimu(in AeSimu p_component, in integer p_resourceIndex := -1) runs on Tester return integer {
				var MyResource v_resource;
				var integer v_resourceIndex := -1;
			
				p_component.start(f_sendResourceAeSimu(p_resourceIndex));
				
				alt {
					[]infoPort.receive(mw_resource) -> value v_resource {
						v_resourceIndex := f_setResource(v_resource.resource, v_resource.resourceType, v_resource.parentIndex, false);
					}
				}
	
				p_component.done;
				
				return v_resourceIndex;
				
			}	

			
			/**
			 * @desc Getting a specific resource from an CseSimu component
			 * @param p_tester AeSimu component
			 * @param p_resourceIndex Index of resource to be retrieved
			 */
			function f_getResourceFromCseSimu(in CseSimu p_component, in integer p_resourceIndex := -1) runs on Tester return integer {
				var MyResource v_resource;
				var integer v_resourceIndex := -1;
			
				p_component.start(f_sendResourceCseSimu(p_resourceIndex));
				
				alt {
					[]infoPort.receive(mw_resource) -> value v_resource {
						v_resourceIndex := f_setResource(v_resource.resource, v_resource.resourceType, v_resource.parentIndex, false);
					}
				}
	
				p_component.done;
				
				return v_resourceIndex;
				
			}	

			/**
			 * @desc Getting the latest resource from an AeSimu component
			 * @param p_tester AeSimu component
			 * @param p_resourceIndex Index of resource to be retrieved
			 */
			function f_getLatestResource(in Tester p_component) runs on Tester return integer {
				var MyResource v_resource;
				var integer v_resourceIndex := -1;
		
				p_component.start(f_sendLatestResource());
				alt {
					[]infoPort.receive(mw_resource) -> value v_resource {
						v_resourceIndex := f_setResource(v_resource.resource, v_resource.resourceType, v_resource.parentIndex, false);
					}
				}

				p_component.done;
				
				return v_resourceIndex;
			
			}
						
			/**
			 * @desc Getting last resourceIndex saved in the vc_resourcesList
			 * @param p_tester Given component
			 */
			function f_getLatestResourceIndex(in Tester p_component) runs on Tester return integer {
				var integer v_resourceIndex;

				p_component.start(f_sendLatestResourceIndex());
				alt {
					[]infoPort.receive(mw_resourceIndex) -> value v_resourceIndex{
					}
				}

				p_component.done;
				
				return v_resourceIndex;

			}
			
			/**
			 * @desc Getting the address of the last resource saved in the vc_resourcesList
			 * @param p_tester Given component
			 */
			function f_getLatestResourceAddress(in Tester p_component, AddressingMethod p_addressingMethod := PX_ADDRESSING_METHOD, PrimitiveScope p_primitiveScope := PX_PRIMITIVE_SCOPE) runs on Tester return XSD.ID {
				var XSD.ID v_resourceAddress;

				p_component.start(f_sendLatestResourceAddress(p_addressingMethod, p_primitiveScope));
				alt {
					[]infoPort.receive(mw_resourceAddress) -> value v_resourceAddress{
					}
				}

				p_component.done;
				
				return v_resourceAddress;

			}
			
			/**
			 * @desc Getting the latest local resource from an CseSimu component
			 * @param p_component CseSimu component
			 * @param p_resourceIndex Index of resource to be retrieved
			 */
			function f_getLatestLocalResource(in CseSimu p_component) runs on Tester return integer {
				var MyResource v_resource;
				var integer v_resourceIndex := -1;
		
				p_component.start(f_sendLatestLocalResource());
				alt {
					[]infoPort.receive(mw_resource) -> value v_resource {
						v_resourceIndex := f_setResource(v_resource.resource, v_resource.resourceType, v_resource.parentIndex, false);//TODO To set correctly parentIndex
					}
				}

				p_component.done;
				
				return v_resourceIndex;
			
			}
						
			/**
			 * @desc Getting last local resourceIndex saved in the vc_localResourcesList
			 * @param p_tester Given component
			 */
			function f_getLatestLocalResourceIndex(in CseSimu p_component) runs on Tester return integer {
				var integer v_resourceIndex;

				p_component.start(f_sendLatestLocalResourceIndex());
				alt {
					[]infoPort.receive(mw_resourceIndex) -> value v_resourceIndex{
					}
				}

				p_component.done;
				
				return v_resourceIndex;

			}
		
			/**
			 * @desc Getting the address of the last local resource saved in the vc_localResourcesList
			 * @param p_tester Given component
			 */
			function f_getLatestLocalResourceAddress(in CseSimu p_component, AddressingMethod p_addressingMethod := PX_ADDRESSING_METHOD, PrimitiveScope p_primitiveScope := PX_PRIMITIVE_SCOPE) runs on Tester return XSD.ID {
				var XSD.ID v_localResourceAddress;

				p_component.start(f_sendLatestLocalResourceAddress(p_addressingMethod, p_primitiveScope));
				alt {
					[]infoPort.receive(mw_resourceAddress) -> value v_localResourceAddress{
					}
				}

				p_component.done;
				
				return v_localResourceAddress;

			}
		}//end of group getFunctions
		
		group sendFunctions {	
	
			/**
			 * @desc Sending of last responsePrimitive (vc_response) through InfoPort
			 */	
			function f_sendResponsePrimitive() runs on Tester {
		
				infoPort.send(vc_response.primitive.responsePrimitive);
					
			} 
	
			/**
			 * @desc Sending of last requestPrimitive (vc_request) through InfoPort
			 */			
			function f_sendRequestPrimitive() runs on Tester {
		
				infoPort.send(vc_request.primitive.requestPrimitive);
		
			} 
			
			/**
			 * @desc Sending of last primitiveContent retrieved (vc_primitiveContentRetrievedResource) through InfoPort
			 */	
			function f_sendPrimitiveContentRetrievedResource() runs on AeSimu {
		
				infoPort.send(vc_primitiveContentRetrievedResource);
					
			} 	
			
			/**
			 * @desc Sending of remoteCSE resource through InfoPort
			 */	
			function f_sendRemoteCseResource() runs on CseSimu {
		
				infoPort.send(vc_resourcesList[vc_remoteCseIndex]);
					
			} 
			
			/**
			 * @desc Sending of Ae resource through InfoPort
			 */	
			function f_sendAeResource() runs on AeSimu {
		
				infoPort.send(vc_resourcesList[vc_aeIndex]);
					
			} 		
			
			/**
			 * @desc Sending of a specific resource through InfoPort
			 * @param p_resourceIndex Index of resource to be sent
			 */	
			function f_sendResourceAeSimu(in integer p_resourceIndex) runs on AeSimu {
		
				if(p_resourceIndex == -1) {
					infoPort.send(vc_resourcesList[vc_aeIndex]); 
				} else {
					infoPort.send(vc_resourcesList[p_resourceIndex]);
				}
					
			} 	
			
			/**
			 * @desc Sending of a specific resource through InfoPort
			 * @param p_resourceIndex Index of resource to be sent
			 */	
			function f_sendResourceCseSimu(in integer p_resourceIndex) runs on CseSimu {
		
				if(p_resourceIndex == -1) {
					infoPort.send(vc_resourcesList[vc_remoteCseIndex]);
				} else {
					infoPort.send(vc_resourcesList[p_resourceIndex]);
				}
					
			}
			
			/**
			 * @desc Sending the address of the last resource saved in the vc_resourcesList
			 */	
			function f_sendLatestResourceAddress(AddressingMethod p_addressingMethod := PX_ADDRESSING_METHOD, PrimitiveScope p_primitiveScope := PX_PRIMITIVE_SCOPE) runs on Tester {
			
				infoPort.send(f_getResourceAddress(lengthof(vc_resourcesList)-1, p_addressingMethod, p_primitiveScope));
		
			} 
			
			
			/**
			 * @desc Sending of the latest resource through InfoPort
			 */	
			function f_sendLatestResource() runs on Tester {

				infoPort.send(vc_resourcesList[lengthof(vc_resourcesList)-1]);
				
			} 	
			
			/**
			 * @desc Sending of last resourceIndex saved in the vc_resourcesList
			 */	
			function f_sendLatestResourceIndex() runs on Tester {

				infoPort.send(lengthof(vc_resourcesList)-1);
		
			} 
						
			/**
			 * @desc Sending of the latest local resource through InfoPort
			 */	
			function f_sendLatestLocalResource() runs on CseSimu {

				infoPort.send(vc_localResourcesList[lengthof(vc_localResourcesList)-1]);
				
			} 	
					
			/**
			 * @desc Sending the address of the last resource saved in the vc_localresourcesList
			 */	
			function f_sendLatestLocalResourceAddress(AddressingMethod p_addressingMethod := PX_ADDRESSING_METHOD, PrimitiveScope p_primitiveScope := PX_PRIMITIVE_SCOPE) runs on CseSimu {

				infoPort.send(f_getLocalResourceAddress(lengthof(vc_localResourcesList)-1, p_addressingMethod, p_primitiveScope));
		
			} 
		
			/**
			 * @desc Sending of last local resourceIndex saved in the vc_localResourcesList
			 */	
			function f_sendLatestLocalResourceIndex() runs on CseSimu {

				infoPort.send(lengthof(vc_localResourcesList)-1);
		
			} 
			
			/**
			 * @desc Sending of sync point
			 */	
			function f_sendSyncPoint(SyncPoints p_syncPoint, in Tester p_component) runs on Tester {

				f_connectInfoPort(p_component);
				
				infoPort.send(p_syncPoint);
		
				f_disconnectInfoPort(p_component);
			} 
			
		}//end of group sendFunctions
			
	}// end of group InfoPortCommunication	
	
	group CseFunctions {
	
		group PreambleFunctions {

			/**
			 * @desc Creation of auxiliar resource AE for correct execution of the test case
			 * @param p_accessControlPolicyIDs AccessControlPolicyIDs for the auxiliar AE resource
			 * @param p_poaList Point of contact of the auxiliar AE resource
			 * @return Internal AE resource index
			 * @verdict 
			 */
			function f_cse_preamble_registerAe(template (omit) AcpType p_accessControlPolicyIDs := omit, in template (omit) PoaList p_poaList := omit) runs on AeSimu return integer {//c_CRUDNDi
			
				var RequestPrimitive v_request;
				var MsgIn v_response;

				//Activate defaults when running on a PTC
				f_cse_activateDefaults_ae();		
												
				v_request := valueof(m_createAe(vc_aeSimuDesc.appId, p_accessControlPolicyIDs, vc_aeSimuDesc.aeIdStem, c_defaultAe1ResourceName, p_poaList));
				
				v_request := f_getCreateRequestPrimitive(int2, v_request, -1);
				
				f_send(e_mcaPort, m_request(v_request));
				
				tc_ac.start;
				alt {
					[] mcaPort.receive(mw_response(mw_responsePrimitiveOK)) -> value v_response {
						tc_ac.stop;
						setverdict(pass,__SCOPE__&":INFO: Application registered successfuly");
						if(ischosen(v_response.primitive.responsePrimitive.primitiveContent.aE)) {
							
							f_checkAttributesToBeSaved(int2, v_request, v_response.primitive.responsePrimitive);
							
							vc_aeIndex := f_setResource(v_response.primitive.responsePrimitive.primitiveContent, int2);
							vc_componentRegistered := true;
							
							if(ispresent(v_response.primitive.responsePrimitive.primitiveContent.aE.aE_ID)){
								f_sendAcPrimitive("AE-ID_changed", vc_aeIndex);
							}
						}
					}
					[] mcaPort.receive(mw_response(mw_responsePrimitiveKO)) {
						tc_ac.stop;
						setverdict(inconc, __SCOPE__&":INFO: Error while registering application");
					}
					[] tc_ac.timeout {
						setverdict(inconc, __SCOPE__&":INFO: No answer while registering resource");
					}
				}	
				
				f_checkAeSimuStatus();
				return vc_aeIndex;
			}
            
			/**
			 * @desc   Creation of auxiliar resource AE for correct execution of the test case containing POINT_OF_ACCESS attribute and REQUEST_REACHABILITY set to true
			 * @param  p_accessControlPolicyIDs AccessControlPolicyIDs for the auxiliar AE resource
			 * @param  p_poaList Point of contact of the auxiliar AE resource
			 * @return Internal AE resource index
			 * @verdict 
			 */
			function f_cse_preamble_registerAeWithRequestReachability(template (omit) AcpType p_accessControlPolicyIDs := omit, in template (omit) PoaList p_poaList := omit) runs on AeSimu return integer {//c_CRUDNDi
			
				var RequestPrimitive v_request;
				var MsgIn v_response;

				//Activate defaults when running on a PTC
				f_cse_activateDefaults_ae();		
			
				v_request := valueof(m_createAe(vc_aeSimuDesc.appId, p_accessControlPolicyIDs, vc_aeSimuDesc.aeIdStem, c_defaultAe1ResourceName, p_poaList));
                v_request.primitiveContent.aE.requestReachability := true;
				
				v_request := f_getCreateRequestPrimitive(int2, v_request, -1);
				
				f_send(e_mcaPort, m_request(v_request));
				
				tc_ac.start;
				alt {
					[] mcaPort.receive(mw_response(mw_responsePrimitiveOK)) -> value v_response {
						tc_ac.stop;
						setverdict(pass,__SCOPE__&":INFO: Application registered successfuly");
						if(ischosen(v_response.primitive.responsePrimitive.primitiveContent.aE)) {
							
							f_checkAttributesToBeSaved(int2, v_request, v_response.primitive.responsePrimitive);
							
							vc_aeIndex := f_setResource(v_response.primitive.responsePrimitive.primitiveContent, int2);
							
							if(ispresent(v_response.primitive.responsePrimitive.primitiveContent.aE.aE_ID)){
								f_sendAcPrimitive("AE-ID_changed", vc_aeIndex);
							}
						}
					}
					[] mcaPort.receive(mw_response(mw_responsePrimitiveKO)) {
						tc_ac.stop;
						setverdict(inconc, __SCOPE__&":INFO: Error while registering application");
						stop;
					}
					[] tc_ac.timeout {
						setverdict(inconc, __SCOPE__&":INFO: No answer while registering resource");
						stop;
					}
				}	
				
				f_checkAeSimuStatus();
				return vc_aeIndex;
			}            
			
			/**
			 * @desc Creation of auxiliar resources ACP and AE for correct execution of the test case
			 * @param p_allowedOperations Allowed operations for the auxiliar AE resource
			 * @param p_appId AppID of the AE resource to be created
			 * @return Internal AE resource index
			 * @verdict 
			 */
			function f_cse_preamble_registerAeWithId(XSD.ID p_appId, in template (value) AccessControlOperations p_allowedOperations := int63) runs on AeSimu return integer {//c_CRUDNDi
			
				var RequestPrimitive v_request;
				
				//Activate defaults when running on a PTC
				f_cse_activateDefaults_ae();		
				
				if(PICS_ACP_SUPPORT){
					f_cse_createAccessControlPolicyAux(p_allowedOperations := p_allowedOperations);
				}
				
				if(vc_acpIndex != -1) {
					vc_resourcesIndexToBeDeleted := {vc_acpIndex};//TODO Not needed
					v_request := valueof(m_createAe(p_appId, {f_getResourceAddress(vc_acpIndex)}, -));
					
					//Set CSEBase IUT as target
					v_request.to_ := f_getResourceAddress();
					
					f_send(e_mcaPort, m_request(v_request));
				} else {
					f_send(e_mcaPort, m_request(m_createAe(p_appId)));
				}
				tc_ac.start;
				alt {
					[] mcaPort.receive(mw_response(mw_responsePrimitiveOK)) -> value vc_response {
						tc_ac.stop;
						setverdict(pass, __SCOPE__&": INFO: Application registered successfuly");
						if(ischosen(vc_response.primitive.responsePrimitive.primitiveContent.aE)) {
							
							vc_aeIndex := f_setResource(vc_response.primitive.responsePrimitive.primitiveContent, int2);
							vc_componentRegistered := true;
							
							if(ispresent(vc_response.primitive.responsePrimitive.primitiveContent.aE.aE_ID)){
								f_sendAcPrimitive("AE-ID_changed", vc_aeIndex);
							} 
						}
					}
					[] mcaPort.receive(mw_response(mw_responsePrimitiveKO))
					{
						tc_ac.stop;
						setverdict(inconc, __SCOPE__&":INFO: Error while registering application");
					}
					[] mcaPort.receive {
						tc_ac.stop;
						setverdict(inconc, __SCOPE__&":INFO: Unexpected message received");
					}
					[] tc_ac.timeout {
						setverdict(inconc, __SCOPE__&":INFO: No answer while registering resource");
					}
				}	
				
				f_checkAeSimuStatus();
				return vc_aeIndex;
			
			}
			
			/**
			 * @desc Creation of ServiceSubscribedAppRule resource
			 * @param p_allowedAEs Allowed AEs
			 * @return Internal resource index
			 * @verdict 
			 */
			function f_cse_preamble_createServiceSubscribedAppRule(in template ListOfM2MID p_allowedAEs := {""}) runs on AeSimu return integer {//c_CRUDNDi
			
				var integer v_serviceSubscribedAppRuleIndex := -1;
	
				v_serviceSubscribedAppRuleIndex := f_cse_createResource(int19, m_createServiceSubscribedAppRule({"None"}, {vc_aeSimuDesc.appId}, valueof(p_allowedAEs)));
				
				return v_serviceSubscribedAppRuleIndex;
			
			}
			
			/**
			 * @desc Creation of SubscribedProfile resource
			 * @param p_allowedAEs Allowed AEs
			 * @return Internal resource index
			 * @verdict 
			 */
			function f_cse_preamble_createServiceSubscribedProfile(in template ListOfM2MID p_allowedAEs := {""}) runs on AeSimu return integer {//c_CRUDNDi
			
				var integer v_serviceSubscribedAppRuleIndex := -1;
				var integer v_serviceSubscribedProfileIndex := -1;
				var template RequestPrimitive m_request := m_createM2mServiceSubscriptionProfileBase;
				
				//TODO Create/Update serviceSubscribedNode //m_request.primitiveContent.m2mServiceSubscriptionProfile.choice.choice_list[0].serviceSubscribedNode := m_contentServiceSubscribedNode;
				v_serviceSubscribedAppRuleIndex := f_cse_createResource(int19, m_createServiceSubscribedAppRule({"None"}, {vc_aeSimuDesc.appId}, valueof(p_allowedAEs)));
				m_request.primitiveContent.m2mServiceSubscriptionProfile.choice.choice_list[0].serviceSubscribedNode.ruleLinks := {f_getResourceAddress(v_serviceSubscribedAppRuleIndex)};
				v_serviceSubscribedProfileIndex := f_cse_createResource(int11, m_request);
			
				return v_serviceSubscribedProfileIndex;
	
			}
			
			/**
			 * @desc Registration of AE2 for handling of notifications and handling of subscription verification started if subscription resource is to be created
			 * @param p_ae2Index Internal AE2 resource index
			 * @param p_createRequestPrimitive CREATE Request for the resource to be created
			 * @param p_resourceType ResourceType of the resource to be created
			 * @param p_responseStatusCode Response Status Code to be sent in response to the subscription verification request
			 * @verdict 
			 */
			function f_cse_preamble_subscriptionVerification(inout integer p_ae2Index, inout template RequestPrimitive p_createRequestPrimitive,in ResourceType p_resourceType, in ResponseStatusCode p_responseStatusCode := int2000) runs on AeSimu {
				if(p_resourceType == int23){
					
					vc_ae2.start(f_cse_createAccessControlPolicyAux("SubscriptionVerificationAcp",{"all"}, int63));
					f_aeSimu_checkComponentDoneAndGetVerdict(vc_ae2);
					
					vc_ae2.start(f_cse_createResource_withAcpAux(int2, m_createAe(PX_TS_AE2.appId, -, PX_TS_AE2.aeIdStem, c_defaultAe2ResourceName, {f_getLocalPoA(PX_TS_AE2.mcaPortIn, "")}), -1)); // AE2 is registred
					f_aeSimu_checkComponentDoneAndGetVerdict(vc_ae2);
					
					p_ae2Index := f_getResourceFromAeSimu(vc_ae2);
					if(ischosen(p_createRequestPrimitive.primitiveContent.subscription)){		//this condition is necessary for Subscription TCs where notification URI is set in m_createSubscriptionAdvanced
						p_createRequestPrimitive.primitiveContent.subscription.notificationURI := {f_getResourceAddress(p_ae2Index)};
					}
					if(PICS_SUBSCRIPTION_VERIFICATION) {
						vc_ae2.start(f_cse_notifyProcedure_subscriptionVerificationHandler(p_responseStatusCode));
					}
				}
			}
		
			/**
			 * @desc Registration of aux AE1 for dynamic authorization
			 * @param p_ae2Index Internal AE1 resource index
			 * @param p_acpIndex Internal ACP resource index
			 * @verdict 
			 */
			function f_cse_preamble_dau_master(inout integer p_ae1Index, inout integer p_acpIndex) runs on AeSimu {
				vc_ae1.start(f_cse_preamble_registerAe());
				f_aeSimu_checkComponentDoneAndGetVerdict(vc_ae1);
				p_ae1Index := f_getLatestResourceIndex(vc_ae1);
					
				vc_ae1.start(f_cse_createAccessControlPolicyAux(-, -, int61)); //c_CUDNDi), no resource retrieval privilege 				
				f_aeSimu_checkComponentDoneAndGetVerdict(vc_ae1);
				p_acpIndex := f_getLatestResourceIndex(vc_ae1);
			}
			

			/**
			 * @desc Registration of DAS for dynamic authorization
			 * @param p_dasIndex Internal DAS resource index
			 * @param p_dauConsultationIndex Internal dynamicAuthorizationConsultation resource index
			 * @param p_containerIndex Internal container resource index
			 * @param p_acpIndex External ACP resource index
			 * @param p_createRequestPrimitiveDac CREATE Request for the dynamicAuthorizationConsultation resource to be created
			 * @param p_createRequestPrimitiveCont CREATE Request for the container resource to be created
			 * @verdict 
			 */
			function f_cse_preamble_dau(inout integer p_dasIndex, inout integer p_dauConsultationIndex, inout integer p_containerIndex, in integer p_acpIndex, in template RequestPrimitive p_createRequestPrimitiveDac, in template RequestPrimitive p_createRequestPrimitiveCont) runs on AeSimu {
				vc_das.start(f_cse_preamble_registerAe());
				f_aeSimu_checkComponentDoneAndGetVerdict(vc_das);
				p_dasIndex := f_getLatestResourceIndex(vc_das);

				p_createRequestPrimitiveDac.primitiveContent.dynamicAuthorizationConsultation.dynamicAuthorizationPoA := {f_getResourceAddress(p_dasIndex)};
				vc_das.start(f_cse_createResource(int34, p_createRequestPrimitiveDac, -1));
				f_aeSimu_checkComponentDoneAndGetVerdict(vc_das);
				p_dauConsultationIndex := f_getLatestResourceIndex(vc_das);
					
				p_createRequestPrimitiveCont.primitiveContent.container.dynamicAuthorizationConsultationIDs := {vc_resourcesList[p_dauConsultationIndex].resource.dynamicAuthorizationConsultation.resourceID}; 
				p_createRequestPrimitiveCont.primitiveContent.container.accessControlPolicyIDs := {vc_resourcesList[p_acpIndex].resource.accessControlPolicy.resourceID}; 	
				vc_das.start(f_cse_createResource(int3, p_createRequestPrimitiveCont, -1));
				f_aeSimu_checkComponentDoneAndGetVerdict(vc_das);
				p_containerIndex := f_getLatestResourceIndex(vc_das);		

			}
		
		}//end group preambleFunctions
		
		group PostambleFunctions {
	
			/**
			 * @desc Deletion of all resources created during the test case execution. It deals also with AE2 created resources if any. IUT gets clean and ready for next execution
			 * @verdict 
			 */
			function f_cse_postamble_deleteResources() runs on AeSimu {
				var integer i;
				var XSD.ID v_resourceAddress;
				var RequestPrimitive v_request;
				
				if (PX_RUN_POSTAMBLE) {
					
					if(vc_auxiliaryAe2Up) {
						if (vc_ae2.alive) {
							f_cse_postamble_aeSimu(vc_ae2);
							f_cse_defaultHandler_aeSimu();
							f_disconnectInfoPort(vc_ae2);
							vc_ae2.start(f_cf01DownAe2());
							vc_ae2.kill;
						}
					}
					
					if(vc_config == e_cf02) {
						if(vc_cse1.running) {
							vc_cse1.stop;
						}
						if(vc_cse1.alive) {
							f_cse_postamble_cse1();
							f_cse_defaultHandler_aeSimu();
							f_disconnectInfoPort(vc_cse1);
							vc_cse1.start(f_cf02DownCse());
							vc_cse1.kill;
							
						}
					}
					
					for(i := lengthof(vc_resourcesIndexToBeDeleted) -1; i >=0; i := i - 1) {
						
						v_resourceAddress := f_getResourceAddress(vc_resourcesIndexToBeDeleted[i]); 
						
						v_request := valueof(m_delete(v_resourceAddress, f_getOriginator(vc_resourcesIndexToBeDeleted[i])));
						
						v_request.from_ := f_getOriginator(vc_resourcesIndexToBeDeleted[i]);

						f_send(e_mcaPort, m_request(v_request), false);
						
						tc_ac.start;
						alt {
							[] mcaPort.receive(mw_response(mw_responsePrimitiveOK)) {
								tc_ac.stop;
								log(__SCOPE__&" INFO: Resource " & v_request.to_ & " deleted");
							}
							[] mcaPort.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 a reset of the IUT is required (for instance, to remove IUT internal variables such as CSEBaseAnnc registry)
					if(vc_resetRequired) {
						//Reset IUT required as CSEBaseAnnc is internally stored in IUT for further announcements
						f_cse_sendUtPrimitive(m_utCommand_reset, __SCOPE__ & ": Please, reset IUT");
					}
				}
				if((vc_config == e_cf02CseSimuMaster) or ((vc_config == e_cf01) and (vc_aeSimuDesc.appId == "NMyApp2Id"))){
					if(infoPort.checkstate("Connected")) {
						infoPort.send(SyncPoints:e_done);
					}
				}
			}
			
			/**
			 * @desc Calls to postamble for AeSimu components (i.e. AE2)
			 * @verdict 
			 */
			function f_cse_postamble_aeSimu(in AeSimu p_ae) runs on AeSimu {
				if(p_ae.running) {
					p_ae.stop;
				}
				p_ae.start(f_cse_postamble_deleteResources());
				p_ae.done;
			}
			
			/**
			 * @desc Calls to postamble for AeSimu component (i.e. AE1) on CseSimu 
			 * @verdict 
			 */
			function f_cse_postamble_ae1() runs on CseSimu {
				if(vc_ae1.running) {
					vc_ae1.stop;
				}
				vc_ae1.start(f_cse_postamble_deleteResources());
				vc_ae1.done;
			}
			
			/**
			 * @desc Calls to postamble for CseSimu component (i.e. CSE1) on AeSimu 
			 * @verdict 
			 */
			function f_cse_postamble_cse1() runs on AeSimu {
				if(vc_cse1.running) {
					vc_cse1.stop;
				}
				vc_cse1.start(f_cse_postamble_deleteResourcesCSE());
				vc_cse1.done;
			}
			
			/**
			 * @desc Calls to postamble for CseSimu component (i.e. CSE2) on CseSimu 
			 * @verdict 
			 */
			function f_cse_postamble_cse2() runs on CseSimu {
				if(vc_cse2.running) {
					vc_cse2.stop;
				}
				vc_cse2.start(f_cse_postamble_deleteResourcesCSE());
				vc_cse2.done;
			}
			
			/**
			 * @desc Deletion of all resources created during the test case execution. IUT gets clean and ready for next execution
			 * @verdict 
			 */
			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 MsgIn v_msgIn;
				var RequestPrimitive v_request;
				var boolean v_deregistrationPerformed := false;
				var template UtTriggerPrimitive v_utRequest := m_utDelete;
				var universal charstring v_action := __SCOPE__ & ": Please, perform deregistration by sending a valid DELETE Request for remoteCSE to ";
					
				if (PX_RUN_POSTAMBLE) {
		
					if((vc_config == e_cf02CseSimuMaster) and (vc_cseSimuDesc.cseName != "CSE2_NAME")) {
						if(vc_ae1.running) {
							vc_ae1.stop;
						}
						if(vc_ae1.alive) {
							if(vc_auxiliaryCse2Up) {
								if(vc_cse2.running) {
									vc_cse2.stop;
								}
								vc_cse2.start(f_cse_defaultHandler());
							}
							f_cse_postamble_ae1();
							f_cse_defaultHandler();
							f_disconnectInfoPort(vc_ae1);
							vc_ae1.start(f_cf02DownAe());
							vc_ae1.kill;
							
						}
						if(vc_auxiliaryCse2Up) {
							if(vc_cse2.running) {
								vc_cse2.stop;
							}
							if(vc_cse2.alive) {
								f_cse_postamble_cse2();
								f_cse_defaultHandler();
								f_disconnectInfoPort(vc_cse2);
								vc_cse2.start(f_cf02DownCse());
								vc_cse2.kill;
							}
						}
					};
		
					for(i := lengthof(vc_resourcesIndexToBeDeleted) -1; i >=0; i := i - 1) {
						
						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(v_resourceIndex);
						} 
			
						v_request := valueof(m_delete(v_resourceAddress, f_getOriginator(v_resourceIndex, vc_testSystemRole)));

						f_send(e_mccPort, m_request(v_request), false);
			
						tc_ac.start;
						alt {
							[] mccPort.receive(mw_response(mw_responsePrimitiveOK)) {
								tc_ac.stop;
								log(__SCOPE__&" INFO: Resource " & v_request.to_ & " deleted");
							}
							[] 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_);
							}	
						}	
					}
					
					//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) {
							//1) Deregistration by Registrar (Test System)
							v_childResourceRefs := f_cse_retrieveChildResourceRefs_cseSimu({int16}, -, f_getOriginator(vc_remoteCseIndex));
							
							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)
								
								f_send(e_mccPort, m_request(v_request), false);
	
								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_);
									}	
								}	
							}	
						}
							
						if(not(v_deregistrationPerformed)) {
							if(vc_localRemoteCseIndex != -1) {
								//Deregistration by Registree (IUT) - Send trigger message for deregistration
								v_utRequest.requestPrimitive.to_ := f_getLocalResourceAddress(vc_localRemoteCseIndex);
								f_cse_sendUtPrimitive_cseSimu(v_utRequest, v_action & f_getLocalResourceAddress(vc_localRemoteCseIndex));	
								
								tc_ac.start;
								alt {
									[] mccPortIn.receive(mw_request(mw_delete(f_getLocalResourceAddress(vc_localRemoteCseIndex)))) -> value v_msgIn {
										tc_ac.stop;
										f_processDeleteRequestPrimitive(v_msgIn.primitive.requestPrimitive);
										f_send(e_mccPortIn, m_response(vc_response.primitive.responsePrimitive));
										log(__SCOPE__&": INFO: Deregistration performed successfully");
									}
									[] tc_ac.timeout {
										log(__SCOPE__&": INFO: No deregistration performed");
									}
								}
							}
						}
					}
					//If a reset of the IUT is required (for instance, to remove IUT internal variables such as CSEBaseAnnc registry)
					if(vc_resetRequired) {
						//Reset IUT required as CSEBaseAnnc is internally stored in IUT for further announcements
						f_cse_sendUtPrimitive_cseSimu(m_utCommand_reset, __SCOPE__ & ": Please, reset IUT");
					}					
				}
				
				if((vc_config == e_cf02) or ((vc_config == e_cf02CseSimuMaster) and (vc_cseSimuDesc.cseName == "CSE2_NAME"))) {
					if(infoPort.checkstate("Connected")) {
						infoPort.send(SyncPoints:e_done);
					}
				}
			}			
			
		}//end group postambleFunctions
		
		group AeSimuFunctions {
			
			/**
			 * @desc Creation of a resource
			 * @param p_resourceType Resource type of the resource to be created
			 * @param p_requestPrimitive CREATE request primitive for the resource to be created
			 * @param p_parentIndex Internal resource index which indicates the parent of the resource to be created
			 * @return Internal resource index of the created resource
			 * @verdict 
			 */
			function f_cse_createResource(in ResourceType p_resourceType, template RequestPrimitive p_requestPrimitive := m_create, integer p_parentIndex := -1) runs on AeSimu return integer {
			
				var RequestPrimitive v_request;
				var integer v_resourceIndex := -1;
			
				//Activate defaults when running on a PTC
				f_cse_activateDefaults_ae();		
								
				v_request := f_getCreateRequestPrimitive(p_resourceType, p_requestPrimitive, p_parentIndex);
			
				f_send(e_mcaPort, m_request(v_request));
				tc_ac.start;
				alt {
					[] mcaPort.receive(mw_response(mw_responsePrimitiveOK)) -> value vc_response {
						tc_ac.stop;
						setverdict(pass, __SCOPE__&":INFO: Resource type " & int2str(enum2int(p_resourceType)) & " created successfuly");
						f_checkAttributesToBeSaved(p_resourceType, v_request, vc_response.primitive.responsePrimitive);
						v_resourceIndex := f_setResource(vc_response.primitive.responsePrimitive.primitiveContent, p_resourceType, p_parentIndex);
						if(p_resourceType == int2) {
							vc_aeIndex := v_resourceIndex;
							vc_componentRegistered := true;
							if(ispresent(vc_response.primitive.responsePrimitive.primitiveContent.aE.aE_ID)){
								f_sendAcPrimitive("AE-ID_changed", vc_aeIndex);
							}
						} else if (p_resourceType == int9) {
							//Check that group members are correctly in the group
							if(lengthof(v_request.primitiveContent.group_.memberIDs) != vc_response.primitive.responsePrimitive.primitiveContent.group_.currentNrOfMembers) {
								setverdict(inconc, __SCOPE__&":INFO: Wrong number of members in group");
							}
						}
					}
					[] mcaPort.receive(mw_response(mw_responsePrimitiveKO)) {
						tc_ac.stop;
						setverdict(inconc, __SCOPE__&":INFO: Error while creating resource type " & int2str(enum2int(p_resourceType)));
					}
					[] mcaPort.receive {
						tc_ac.stop;
						setverdict(inconc, __SCOPE__&":INFO: Unexpected message received");
					}
					[] tc_ac.timeout {
						setverdict(inconc, __SCOPE__&":INFO: No answer while creating resource type " & int2str(enum2int(p_resourceType)));
					}
				}	
				
				f_checkAeSimuStatus();
				
				return v_resourceIndex;
		
			}
					
			/**
			 * @desc Creation of a resource
			 * @param p_resourceType Resource type of the resource to be created
			 * @param p_requestPrimitive CREATE request primitive for the resource to be created
			 * @param p_parentIndex Internal resource index which indicates the parent of the resource to be created
			 * @return Internal resource index of the created resource
			 * @verdict 
			 */
			function f_cse_createResource_withAcpAux(in ResourceType p_resourceType, template RequestPrimitive p_requestPrimitive := m_create, integer p_parentIndex := -1) runs on AeSimu return integer {
			
				var RequestPrimitive v_request;
				var integer v_resourceIndex := -1;
			
				//Activate defaults when running on a PTC
				f_cse_activateDefaults_ae();
				
				if(vc_acpIndex != -1) {
					p_requestPrimitive := f_setAcpId(p_requestPrimitive, {vc_resourcesList[vc_acpIndex].resource.accessControlPolicy.resourceID});
				}		
				
				v_resourceIndex := f_cse_createResource(p_resourceType, p_requestPrimitive, p_parentIndex);
								
				return v_resourceIndex;
	
			}
		
			/**
			 * @desc Creation of the auxiliar ACP resource
			 * @param p_acpName ACP name
			 * @param p_allowedOperations Allowed operations
			 * @verdict 
			 */
			function f_cse_createAccessControlPolicyAux(in template (value) XSD.String p_acpName := c_defaultAcpResourceName, in template (value) ListOfURIs p_acor := PX_ACOR, in template (value) AccessControlOperations p_allowedOperations := int63) runs on AeSimu {				
				var RequestPrimitive v_request;
				
				//Activate defaults when running on a PTC
				f_cse_activateDefaults_ae();
				
				v_request := valueof(m_createAcp(p_acpName, p_acor, p_allowedOperations));
				
				v_request := f_getCreateRequestPrimitive(int1, v_request, -1);
								
				f_send(e_mcaPort, m_request(v_request));
				tc_ac.start;
				alt {
					[] mcaPort.receive(mw_response(mw_responsePrimitiveOK)) -> value vc_response {
						tc_ac.stop;
						setverdict(pass, __SCOPE__&":INFO: Resource type " & int2str(1) & " created successfuly");
						f_checkAttributesToBeSaved(int1, v_request, vc_response.primitive.responsePrimitive);
						vc_acpIndex := f_setResource(vc_response.primitive.responsePrimitive.primitiveContent, int1);
					}
					[] mcaPort.receive(mw_response(mw_responsePrimitiveKO)) {
						tc_ac.stop;
						setverdict(inconc, __SCOPE__&":INFO: Error while creating resource type " & int2str(1));
					}
					[] mcaPort.receive {
						tc_ac.stop;
						setverdict(inconc, __SCOPE__&":INFO: Unexpected message received");
					}
					[] tc_ac.timeout {
						setverdict(inconc, __SCOPE__&":INFO: No answer while creating resource type " & int2str(1));
					}
				}	
				
				f_checkAeSimuStatus();
			
			}
							
			/**
			 * @desc Message exchange for the update of a resource
			 * @param p_resourceType Resource type of the resource to be created
			 * @param p_requestPrimitive UPDATE request primitive to be used
			 * @param p_resourceIndex Internal resource index which indicates the resource to be updated	 
			 * @verdict 
			 */
			function f_cse_updateResource(in ResourceType p_resourceType, integer p_resourceIndex, template RequestPrimitive p_request, template (omit) AttributeAux_list p_nullFields := omit) runs on AeSimu {

				var RequestPrimitive v_request;
				
				//Activate defaults when running on a PTC
				f_cse_activateDefaults_ae();	
				
				v_request := f_getUpdateRequestPrimitive(p_resourceType, p_resourceIndex, p_request);
				
				f_send(e_mcaPort, m_request(valueof(v_request), p_nullFields));
				tc_ac.start;
				alt {
					[] mcaPort.receive(mw_response(mw_responsePrimitiveOK)) -> value vc_response {
						tc_ac.stop;
						setverdict(pass, __SCOPE__&":INFO: Attribute of resource updated successfuly");
					}
					[] mcaPort.receive(mw_response(mw_responsePrimitiveKO)) -> value vc_response {
						tc_ac.stop;
						setverdict(inconc, __SCOPE__&":INFO: Error while updating resource");
					}
					[] mcaPort.receive{
						tc_ac.stop;
						setverdict(inconc, __SCOPE__&":INFO: Unexpected message received");
					}
					[] tc_ac.timeout {
						setverdict(inconc, __SCOPE__&":INFO: No answer while updating resource");
					}
				}	
				
				f_checkAeSimuStatus();
				
			}// end f_cse_updateResource			
			
			/**
			 * @desc Message exchange for the retrieval of a resource
			 * @param p_resourceIndex Resource index of the resource to be retrieved
			 * @return PrimitiveContent parameter of the RETRIEVE response
			 * @verdict 
			 */
			function f_cse_retrieveResource(integer p_resourceIndex, in template(omit) XSD.ID p_virtualResource := omit) runs on AeSimu return PrimitiveContent{
				
				var XSD.ID v_resourceAddress;
				var MsgIn v_retrievedResponse;
				
				if(isvalue(p_virtualResource)) {
					v_resourceAddress := f_getResourceAddress(p_resourceIndex) & "/" & valueof(p_virtualResource);
				} else {
					v_resourceAddress := f_getResourceAddress(p_resourceIndex);
				}

				f_send(e_mcaPort, m_request(m_retrieve(v_resourceAddress, f_getOriginator(p_resourceIndex))), false);
				tc_ac.start;
				alt {
					[] mcaPort.receive(mw_response(mw_responsePrimitiveOK)) -> value v_retrievedResponse {
						tc_ac.stop;
						setverdict(pass, __SCOPE__&":INFO: Resource retrieved successfuly");
					}
					[] mcaPort.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");
					}
				}	
				
				f_checkAeSimuStatus();
				
				vc_primitiveContentRetrievedResource := v_retrievedResponse.primitive.responsePrimitive.primitiveContent;
				
				return vc_primitiveContentRetrievedResource;
				
			}// end f_cse_retrieveResource	
			
			/**
			 * @desc Message exchange for the retrieval of a resource protected by role/token based access control
			 * @param p_resourceIndex Resource index of the resource to be retrieved
			 * @param p_roleResourceID Applicable Role ID for the originator
			 * @param p_tokenResourceID Applicable Token ID for the originator
			 * @return PrimitiveContent parameter of the RETRIEVE response
			 * @verdict 
			 */
			function f_cse_retrieveResourceWithRoleToken(integer p_resourceIndex, template (omit) XSD.ID p_roleResourceID := omit, template (omit) XSD.ID p_tokenResourceID := omit) runs on AeSimu return PrimitiveContent{

				var template RequestPrimitive v_retrieveRequest;
				var MsgIn v_retrievedResponse;
				v_retrieveRequest := m_retrieve(f_getResourceAddress(p_resourceIndex), f_getOriginator(p_resourceIndex));
				if (ispresent(p_roleResourceID)) {v_retrieveRequest.roleIDs := {p_roleResourceID};}
				if (ispresent(p_tokenResourceID)) {v_retrieveRequest.tokenIDs := {p_tokenResourceID};}
				f_send(e_mcaPort, m_request(valueof(v_retrieveRequest)));
				
				tc_ac.start;
				alt {
					[] mcaPort.receive(mw_response(mw_responsePrimitiveOK)) -> value v_retrievedResponse {
						tc_ac.stop;
						setverdict(pass, __SCOPE__&":INFO: Resource retrieved successfuly");
					}
					[] mcaPort.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");
					}
				}	
				
				f_checkAeSimuStatus();
				
				return v_retrievedResponse.primitive.responsePrimitive.primitiveContent;
				
			}// end f_cse_retrieveResourceWithRole	
			
			/**
			 * @desc Message exchange for the deletion of a resource
			 * @param p_index Resource index of the resource to be deleted
			 * @param p_requestPrimitive DELETE request to be used. If not present default DELETE request will be used
			 * @verdict 
			 */
			function f_cse_deleteResource(in integer p_index, in template (omit) RequestPrimitive p_requestPrimitive := omit) runs on AeSimu {
				var RequestPrimitive v_request;
				
				if(not isvalue(p_requestPrimitive)) {
					v_request := valueof(m_delete(f_getResourceAddress(p_index), f_getOriginator(p_index)));
				} else {
					v_request := valueof(p_requestPrimitive);
				}
				
				f_send(e_mcaPort, m_request(v_request));
				
				tc_ac.start;
				alt {
					[] mcaPort.receive(mw_response(mw_responsePrimitiveOK)) {
						tc_ac.stop;
						setverdict(pass, __SCOPE__&"INFO: Resource " & v_request.to_ & " deleted");
						
						f_removeElementFromList(vc_resourcesIndexToBeDeleted, p_index);
					}
					[] mcaPort.receive(mw_response(mw_responsePrimitiveKO)) {
						tc_ac.stop;
						setverdict(inconc, __SCOPE__&"INFO: Error while deleting resource " & v_request.to_);
					}
					[] tc_ac.timeout {
						setverdict(inconc, __SCOPE__&"INFO: No answer while deleting resource " & v_request.to_);
					}	
				}	
				
				f_checkAeSimuStatus();
				
			}// end f_cse_deleteResource
						
			/**
			 * @desc Message exchange for any operation on a resource
			 * @param p_requestPrimitive Request primitive to be sent
			 * @return PrimitiveContent parameter of the operation response
			 * @verdict 
			 */
			function f_cse_operationResource(template RequestPrimitive p_requestPrimitive) runs on AeSimu return PrimitiveContent{

				f_send(e_mcaPort, m_request(valueof(p_requestPrimitive)));
				
				tc_ac.start;
				alt {
					[] mcaPort.receive(mw_response(mw_responsePrimitiveOK)) -> value vc_response {
						tc_ac.stop;
						setverdict(pass, __SCOPE__&":INFO: Success operation on resource");
					}
					[] mcaPort.receive(mw_response(mw_responsePrimitiveKO)) -> value vc_response {
						tc_ac.stop;
						setverdict(inconc, __SCOPE__&":INFO: Error on the operation on resource");
					}
					[] tc_ac.timeout {
						setverdict(inconc, __SCOPE__&":INFO: No answer while operation on resource");
					}
				}	
				
				f_checkAeSimuStatus();
				
				return vc_response.primitive.responsePrimitive.primitiveContent;
				
			}// end f_cse_operationResource
			
			/**
			 * @desc Check that a resource is present in the IUT (resourceId is known) by using RETRIEVE operation
			 * @param p_resourceIndex Resource index of the resource to be checked
			 * @return boolean
			 */
			function f_cse_isResourcePresent (integer p_resourceIndex) runs on AeSimu return boolean {
			
				//Check to see if the resource is present or not
				f_send(e_mcaPort, m_request(m_retrieve(f_getResourceAddress(p_resourceIndex), f_getOriginator(p_resourceIndex))));
				tc_ac.start;
				alt {
					[] mcaPort.receive(mw_response(mw_responsePrimitive(int2000))) {
						tc_ac.stop;
						setverdict(pass, testcasename() & ": Resource present: " & f_getResourceAddress(p_resourceIndex));
						return true;
					}
					[] mcaPort.receive(mw_response(mw_responsePrimitive(int4004))) {
						tc_ac.stop;
						setverdict(pass, testcasename() & ": Resource: " & f_getResourceAddress(p_resourceIndex) & " not found");
						return false;
					}
					[] mcaPort.receive(mw_response(mw_responsePrimitive(?, -))) {
						tc_ac.stop;
						setverdict(inconc, testcasename() & ": Wrong response status code in the response");
						return false;
					}
					[] tc_ac.timeout {
						setverdict(inconc, testcasename() & ": No answer while retrieving resource");
						return false;
					}
				}	
				return false;
			}
						
			/**
			 * @desc Check that a resource is not present in the IUT (resourceId is NOT known)
			 * @param p_parentIndex Index of the parent resource of the resource to be checked
			 * @param p_resourceName Resource name (Hierarchical method is used) of the resource to be checked
			 * @return boolean
			 */
			function f_cse_isResourceNotPresent (integer p_parentIndex, XSD.String p_resourceName) runs on AeSimu return boolean {
			
				log(testcasename() & ":INFO: Hierarchical addressing method is required to check the non presence of the resource");
				
				//Check to see if the resource has NOT been created
				f_send(e_mcaPort, m_request(m_retrieve(f_getResourceAddress(p_parentIndex, e_hierarchical) & "/" & p_resourceName, f_getOriginator(p_parentIndex))));
				tc_ac.start;
				alt {
					[] mcaPort.receive(mw_response(mw_responsePrimitive(int4004))) {
						tc_ac.stop;
						setverdict(pass, testcasename() & ": Resource not present");
						return true;
					}
					[] mcaPort.receive(mw_response(mw_responsePrimitive(?))) {
						tc_ac.stop;
						setverdict(inconc, testcasename() & ": Wrong response status code in the response");
						return false;
					}
					[] tc_ac.timeout {
						setverdict(inconc, testcasename() & ": No answer while retrieving resource");
						return false;
					}
				}	
				return false;
			}
			
			/**
			 * @desc Message exchange for the update of the auxiliar ACP resource
			 * @param p_allowedOperations New allowed operations
			 * @verdict 
			 */
			function f_cse_updateAcpAuxResource (in template (value) AccessControlOperations p_allowedOperations) runs on AeSimu {
				var RequestPrimitive v_request;
				
				v_request := valueof(m_updateAcpBase);
				
				v_request.requestIdentifier := valueof(v_request.requestIdentifier) & f_rnd(1, 1000000);
				
				v_request.to_ := f_getResourceAddress(vc_acpIndex);
				v_request.from_ := f_getOriginator(vc_acpIndex);
				v_request.primitiveContent.accessControlPolicy.privileges.accessControlRule_list := {valueof(m_createAcr(PX_ACOR, p_allowedOperations))};
							
				f_send(e_mcaPort, m_request(v_request));
				tc_ac.start;
				alt {
					[] mcaPort.receive(mw_response(mw_responsePrimitiveOK))  {
						tc_ac.stop;
						setverdict(pass, __SCOPE__&":INFO: " & v_request.to_ & " resource updated successfuly");
						//TODO To save new values
					}
					[] mcaPort.receive(mw_response(mw_responsePrimitiveKO)) {
						tc_ac.stop;
						setverdict(inconc, __SCOPE__&":INFO: Error while updating " & v_request.to_ & " resource");
					}
					[] tc_ac.timeout {
						setverdict(inconc, __SCOPE__&":INFO: No answer while updating " & v_request.to_ & " resource" );
					}
				}		
				
				f_checkAeSimuStatus();
			}   
						
			/**
			 * @desc Sending of a request primitive over mca port
			 * @param p_resourceType Resource type of the resource to be created
			 * @param p_requestPrimitive CREATE request primitive for the resource to be created
			 * @param p_parentIndex Internal resource index which indicates the parent of the resource to be created
			 * @return Internal resource index of the created resource
			 * @verdict 
			 */
			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;
			
				v_request := f_getCreateRequestPrimitive(p_resourceType, p_requestPrimitive, p_parentIndex);
		
				f_send(e_mcaPort, m_request(v_request));
					
			}
			
			/**
			 * @desc Sending of a request primitive over mca port
			 * @param p_resourceType Resource type of the resource to be created
			 * @param p_requestPrimitive UPDATE request primitive for the resource to be created
			 * @param p_parentIndex Internal resource index which indicates the parent of the resource to be created
			 * @return Internal resource index of the created resource
			 * @verdict 
			 */
			function f_cse_sendUpdateRequestPrimitive(in ResourceType p_resourceType, template RequestPrimitive p_requestUpdatePrimitive := m_update, integer p_targetIndex := -1) runs on AeSimu {

				var RequestPrimitive v_request;
				
				v_request := f_getUpdateRequestPrimitive(p_resourceType, p_targetIndex, p_requestUpdatePrimitive);

				f_send(e_mcaPort, m_request(v_request));
		
			}
			
			/**
			 * @desc   Receive response from the IUT
			 * @param  p_requestPrimtive	Received request primitive
			 */
			function f_cse_receiveResponse(in RequestPrimitive p_request) runs on AeSimu {
				
				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;
						setverdict(pass, __SCOPE__&":INFO: Response received with negative response status code");
					}
					[] tc_ac.timeout {
						setverdict(inconc, __SCOPE__&":INFO: No response received");
					}
				}	
				
			}

			
			function f_cse_generateMissingDataPoint(in integer p_timeSeriesResourceIndex, in integer p_timeSeriesInstanceNumber := 0) runs on AeSimu{
			
				var RequestPrimitive v_request;
				var integer v_resourceIndex := -1;
				var integer i;
				var XSD.NonNegativeInteger v_periodicInterval := vc_resourcesList[p_timeSeriesResourceIndex].resource.timeSeries.periodicInterval;
				var XSD.NonNegativeInteger v_missingDataDetectTimer := vc_resourcesList[p_timeSeriesResourceIndex].resource.timeSeries.missingDataDetectTimer;
				timer t_noAction;
			
				//Activate defaults when running on a PTC
				f_cse_activateDefaults_ae();		
				i := 0;
				while (i < 1) {			
					v_request := valueof(m_createTimeSeriesInstanceBase);
					v_request.primitiveContent.timeSeriesInstance.resourceName := "MyTimeSeriesInstance" & int2str(p_timeSeriesInstanceNumber);
					v_request.primitiveContent.timeSeriesInstance.dataGenerationTime := {alt_ := fx_generateTimestamp()};
					
					v_resourceIndex := f_cse_createResource(int30, v_request, p_timeSeriesResourceIndex);
					i := i + 1;
					t_noAction.start(int2float(v_periodicInterval/1000+v_missingDataDetectTimer/1000));
					t_noAction.timeout;
				}
				
				//f_sleep(int2float(v_periodicInterval/1000));
				//After missingDataTimerDetect, a missing data point should have been detected
				//t_noAction.start(int2float(v_missingDataDetectTimer));
		
			}
			
		}//end group AeSimu
			
		group CseSimuFunctions {

			group NotificationFunctions { 
				
				/**
				 * @desc Handling message exchange for the subscription verification
				 * @param p_responseStatusCode Response Status Code to be used for the response to the verification request
				 * @verdict 
				 */
				function f_cse_notifyProcedure_subscriptionVerificationHandler(in ResponseStatusCode p_responseStatusCode := int2000) runs on AeSimu {
					// Local variables
					var ResponsePrimitive v_responsePrimitive;
					var boolean v_notificationReceived := false;
					var template Notification v_notificationRequest := mw_contentNotificationVerification;
					
					//Activate defaults when running on a PTC
					f_cse_activateDefaults_ae();		
					
					//Preparation of expected Notification verification
					//TODO To add checks for creator and subscription reference
					//v_notificationRequest.creator := p_creator;(which format?)
					//v_notificationRequest.subscriptionReference := "I Don't know which URI is expected";
    			
					tc_ac.start;
					alt {
						[] mcaPortIn.receive(mw_request(mw_notifyNotification(v_notificationRequest))) -> value vc_request {
							tc_ac.stop;
							v_notificationReceived := true;
							setverdict(pass, __SCOPE__ & ":INFO: Subscription Verification Notification received");
						}
						[] mcaPortIn.receive(mw_request(mw_notifyNotification(mw_contentNotification(?)))) -> value vc_request {
							tc_ac.stop;
							v_notificationReceived := true;
							setverdict(inconc, __SCOPE__ & ":ERROR: Notification received but verificationRequest isn't set to TRUE");							
						}
						[] tc_ac.timeout {
							setverdict(inconc, __SCOPE__ & ":ERROR:  No subscriptionVerification notification received");
							stop;
						}
					}
					
					if(v_notificationReceived) {
						//Sending response to the notification received	
						//Preparation of Notification response to be sent
						v_responsePrimitive := valueof(m_responseNotification(p_responseStatusCode, omit));
	    				v_responsePrimitive.requestIdentifier := vc_request.primitive.requestPrimitive.requestIdentifier;
						
						if(getverdict != pass) {
							v_responsePrimitive.responseStatusCode := int4000; 
						}
						f_send(e_mcaPortIn, m_response(v_responsePrimitive));
					}

				} //end f_cse_notifyProcedure_subscriptionVerificationHandler
				
				/**
				 * @desc Default handling message exchange for the notification procedure
				 * @verdict 
				 */
				function f_cse_notifyProcedure_defaultHandler() runs on AeSimu {
					// Local variables
					var ResponsePrimitive v_responsePrimitive;
					
					//Activate defaults when running on a PTC
					f_cse_activateDefaults_ae();							
					
					tc_ac.start;
					alt {
						[] mcaPortIn.receive(mw_request(mw_notifyNotification(mw_contentNotification(?)))) -> value vc_request {
							tc_ac.stop;
							
							setverdict(pass, __SCOPE__ & ":INFO: Notification received");
							
							//Send response in any case
							v_responsePrimitive := valueof(m_responseNotification(int2000, omit));
							v_responsePrimitive.requestIdentifier := vc_request.primitive.requestPrimitive.requestIdentifier;
							f_send(e_mcaPortIn, m_response(v_responsePrimitive));
							tc_ac.start;
							repeat;
						}
						[] mcaPortIn.receive{
							tc_ac.stop;
							setverdict(inconc, __SCOPE__ & ":ERROR: unexpected message received");
							tc_ac.start;
							repeat;
						}
					}
	    		    	
				} //end f_cse_notifyProcedure_defaultHandler
    		
				/**
				 * @desc Handling message exchange for the notification procedure
				 * @param p_primitiveContent Expected primitiveContent in the notification
				 * @verdict 
				 */
				function f_cse_notifyProcedure_representationHandler(template PrimitiveContent p_primitiveContent) runs on AeSimu {
					// Local variables
					var ResponsePrimitive v_responsePrimitive;
					
					//Activate defaults when running on a PTC
					f_cse_activateDefaults_ae();							
					
					tc_ac.start;
					alt {
						[] mcaPortIn.receive(mw_request(mw_notifyNotification(mw_contentNotification(?)))) -> value vc_request {
							tc_ac.stop;
							if(f_check_notificationContent(vc_request.primitive.requestPrimitive, p_primitiveContent)){
								setverdict(pass, __SCOPE__ & ":INFO: Notification received");
							}
							else{
								setverdict(fail, __SCOPE__ & ":ERROR: Notification received but the content doesn't match");
							}
							//Send response in any case
							v_responsePrimitive := valueof(m_responseNotification(int2000, omit));
							v_responsePrimitive.requestIdentifier := vc_request.primitive.requestPrimitive.requestIdentifier;
							f_send(e_mcaPortIn, m_response(v_responsePrimitive));
						}
						[] mcaPortIn.receive(mw_request(mw_notifyNotification(?))) -> value vc_request {
							tc_ac.stop;
							setverdict(fail, __SCOPE__ & ":ERROR: Notification received but the content doesn't match");
						}	
						[] tc_ac.timeout {
							setverdict(fail, __SCOPE__ & ":ERROR: No notification received");
						}
					}
	    		    	
				} //end f_cse_notifyProcedure_representationHandler

				/**
				 * @desc Handling message exchange for the notification procedure for timeSeries
				 * @param p_timeSeriesNotification Expected timeSeriesNotification in the notification
				 * @verdict 
				 */
				function f_cse_notifyProcedure_timeSeriesNotificationHandler(template TimeSeriesNotification p_timeSeriesNotification) runs on AeSimu {
					// Local variables
					var ResponsePrimitive v_responsePrimitive;
					
					//Activate defaults when running on a PTC
					f_cse_activateDefaults_ae();							
					
					tc_ac.start;
					alt {
						[] mcaPortIn.receive(mw_request(mw_notifyNotification(mw_contentNotification({timeSeriesNotification := p_timeSeriesNotification})))) -> value vc_request {
							tc_ac.stop;
							setverdict(pass, __SCOPE__ & ":INFO: Notification received");
							//Send response in any case
							v_responsePrimitive := valueof(m_responseNotification(int2000, omit));
							v_responsePrimitive.requestIdentifier := vc_request.primitive.requestPrimitive.requestIdentifier;
							f_send(e_mcaPortIn, m_response(v_responsePrimitive));
						}
						[] mcaPortIn.receive(mw_request(mw_notifyNotification(?))) -> value vc_request {
							tc_ac.stop;
							setverdict(fail, __SCOPE__ & ":ERROR: Notification received but the content doesn't match");
						}	
						[] tc_ac.timeout {
							setverdict(fail, __SCOPE__ & ":ERROR: No notification received");
						}
					}
	    		    	
				} //end f_cse_notifyProcedure_timeSeriesNotificationHandler
				
				/**
				 * @desc Handling message exchange for the notification procedure
				 * @param p_responsePrimitive Expected responsePrimitive in the notification
				 * @verdict 
				 */
				function f_cse_notifyProcedure_responsePrimitiveHandler(template  ResponsePrimitive p_responsePrimitive) runs on AeSimu {
					// Local variables
					var ResponsePrimitive v_responsePrimitive;
	
					//Activate defaults when running on a PTC
					f_cse_activateDefaults_ae();							
	
					tc_ac.start;
					alt {
						[] mcaPortIn.receive(mw_request(mw_notifyResponsePrimitive(p_responsePrimitive))) -> value vc_request {
							tc_ac.stop;
							setverdict(pass, __SCOPE__ & ":INFO: Notification received with the expected content");
							v_responsePrimitive := valueof(m_responseNotification(int2000, omit));
							v_responsePrimitive.requestIdentifier := vc_request.primitive.requestPrimitive.requestIdentifier;
						}
						[] mcaPortIn.receive(mw_request(mw_notifyResponsePrimitive(?))) -> value vc_request {
							tc_ac.stop;
							setverdict(fail, __SCOPE__ & ":ERROR: Notification received but the content doesn't match");
							v_responsePrimitive := valueof(m_responseNotification(int2000, omit));
							v_responsePrimitive.requestIdentifier := vc_request.primitive.requestPrimitive.requestIdentifier;
						}
						[] tc_ac.timeout {
							setverdict(fail, __SCOPE__ & ":ERROR: No notification received");
						}
					}
					
					if(isvalue(v_responsePrimitive)) {
						f_send(e_mcaPortIn, m_response(v_responsePrimitive));
					}
					
    	
				} //end f_cse_notifyProcedure_representationHandler
	    		
				/**
				 * @desc Handling message exchange for the notification procedure (aggregatedNotification)
				 * @param p_primitiveContent Expected primitiveContent in the notification
				 * @verdict 
				 */
				function f_cse_notifyProcedure_aggregatedNoficationHandler(template PrimitiveContent p_primitiveContent,in integer p_numberOfAggregatedNotification) runs on AeSimu {
					// Local variables
					var ResponsePrimitive v_responsePrimitive;
					var integer v_notificationsReceived := 0;
 
					//Activate defaults when running on a PTC
					f_cse_activateDefaults_ae();		
					   
					tc_ac.start;
					alt {
						[] mcaPortIn.receive(mw_request(mw_notifyAggregatedNotification)) -> value vc_request {
							tc_ac.stop;
							v_notificationsReceived := lengthof(vc_request.primitive.requestPrimitive.primitiveContent.aggregatedNotification.notification_list);
							if(p_numberOfAggregatedNotification == v_notificationsReceived){
								if(f_check_notificationContent(vc_request.primitive.requestPrimitive, p_primitiveContent)){
									setverdict(pass, __SCOPE__ & ": Notification received");
								}
								else{
									setverdict(fail, __SCOPE__ & ": Notification received but the content doesn't match");
								}
							}
							else {
								setverdict(fail, __SCOPE__ & ": Number of Notification in Aggregatednotification isn't right");
							}
							//Send response in any case
							v_responsePrimitive := valueof(m_responseNotification(int2000, omit));
							v_responsePrimitive.requestIdentifier := vc_request.primitive.requestPrimitive.requestIdentifier;
							f_send(e_mcaPortIn, m_response(v_responsePrimitive));
						}
						[] mcaPortIn.receive(mw_request(mw_notifyNotification(mw_contentNotification(?)))) -> value vc_request {
							tc_ac.stop;
							if(f_check_notificationContent(vc_request.primitive.requestPrimitive, p_primitiveContent)){
								setverdict(pass, __SCOPE__ & ":INFO: Notification received");
							}
							else{
								setverdict(fail, __SCOPE__ & ":ERROR: Notification received but the content doesn't match");
							}
							//Send response in any case
							v_responsePrimitive := valueof(m_responseNotification(int2000, omit));
							v_responsePrimitive.requestIdentifier := vc_request.primitive.requestPrimitive.requestIdentifier;
							f_send(e_mcaPortIn, m_response(v_responsePrimitive));
							v_notificationsReceived := v_notificationsReceived + 1;
							if(v_notificationsReceived < p_numberOfAggregatedNotification) {
								tc_ac.start;
								repeat;
							}
						}
						[] tc_ac.timeout {
							if(v_notificationsReceived == 0) {
								setverdict(fail, __SCOPE__ & ": No notification received");
							} else {
								setverdict(fail, __SCOPE__ & ": Not received the expected number of notifications");
							}
						}
					}
					
				} //end f_cse_notifyProcedure_aggregatedNotificationHandler
	    		
				/**
				 * @desc Handling message exchange for the notification procedure (deletion of subscription resource)
				 * @param p_notification Expected notification
				 * @verdict 
				 */
				function f_cse_notifyProcedure_subscriptionDeletionHandler( template  Notification p_notification) runs on AeSimu {
					var ResponsePrimitive v_responsePrimitive;
					
					//Activate defaults when running on a PTC
					f_cse_activateDefaults_ae();		
					
					tc_ac.start;
					alt {
						[] mcaPortIn.receive(mw_request(mw_notifyNotification(p_notification))) -> value vc_request {
							tc_ac.stop;
							setverdict(pass, __SCOPE__ & ":INFO: Expected deletion notification received");
							v_responsePrimitive := valueof(m_responseNotification(int2000, omit));
							v_responsePrimitive.requestIdentifier := vc_request.primitive.requestPrimitive.requestIdentifier;
							f_send(e_mcaPortIn, m_response(v_responsePrimitive));
							if(not(match(vc_request.primitive.requestPrimitive.primitiveContent.notification.subscriptionDeletion, true))) {
								setverdict(fail, __SCOPE__ & ":ERROR: subscriptionDeletion attribute have to be set to TRUE");
							}
						}
						[] tc_ac.timeout {
							setverdict(fail, __SCOPE__ & ":ERROR: No notification received");
						}
					}
						
				} //end f_cse_notifyProcedure_subscriptionDeletionHandler  
				
				/**
				 * @desc Handling message exchange for the notification procedure (no notification expected)
				 * @verdict 
				 */
				function f_cse_notifyProcedure_noNotificationHandler(float p_waitingTime := 10.0) runs on AeSimu {
					// Local variables
					var ResponsePrimitive v_responsePrimitive;
					
					//Activate defaults when running on a PTC
					f_cse_activateDefaults_ae();		
							
					tc_ac.start(p_waitingTime);
					alt {
						[] mcaPortIn.receive(mw_request(mw_notifyNotification(mw_contentNotification(?)))) -> value vc_request {
							tc_ac.stop;
							setverdict(fail, __SCOPE__ & ": Error, Non expected notification received");
							//Send response in any case
							v_responsePrimitive := valueof(m_responseNotification(int2000, omit));
							v_responsePrimitive.requestIdentifier := vc_request.primitive.requestPrimitive.requestIdentifier;
							f_send(e_mcaPortIn, m_response(v_responsePrimitive));
						}
						[] mcaPortIn.receive(mw_request(mw_notifyResponsePrimitive(?))) -> value vc_request {
							tc_ac.stop;
							setverdict(fail, __SCOPE__ & ": Error, Non expected notification received");
							//Send response in any case
							v_responsePrimitive := valueof(m_responseNotification(int2000, omit));
							v_responsePrimitive.requestIdentifier := vc_request.primitive.requestPrimitive.requestIdentifier;
							f_send(e_mcaPortIn, m_response(v_responsePrimitive));
						}
						[] tc_ac.timeout {
							setverdict(pass, __SCOPE__ & ": No notification received");
						}
					}
		
				} //end f_cse_notifyProcedure_noNotification Handler
				
				/**
				 * @desc Message exchange for notification
				 * @param p_requestPrimitive Notify request to be used for the notification
				 * @verdict 
				 */
				 function f_cse_notifyProcedure_notify(template RequestPrimitive p_requestPrimitive) runs on CseSimu {
					// Local variables
					var ResponsePrimitive v_responsePrimitive;
					var integer v_resourceIndex := -1;
				
					//p_requestPrimitive.from_ := PX_CSE1_ID;
					p_requestPrimitive.from_ := f_getOriginator(vc_remoteCseIndex, e_cse);
					
					f_send(e_mccPort, m_request(valueof(p_requestPrimitive)));
					tc_ac.start;
					alt {
						[] mccPort.receive(mw_response(mw_responseNotify(int2000))) -> value vc_response {
							tc_ac.stop;
						}
						[] mccPort.receive(mw_response(mw_responsePrimitiveKO)) {
							tc_ac.stop;
							setverdict(inconc, __SCOPE__&":INFO: Error while performing notification");
						}
						[] mccPort.receive {
							tc_ac.stop;
							setverdict(inconc, __SCOPE__&":INFO: Unexpected message received");
						}
						[] tc_ac.timeout {
							setverdict(inconc, __SCOPE__&":INFO: No answer while performing notification");
						}
					}	
				
					f_checkCseSimuStatus();
				
				} //end f_cse_notifyProcedure_notify
				
				/**
				 * @desc Handling message exchange for the dynamic authorization procedure
				 * @desc Processing details are out of scope of oneM2M
				 * @verdict 
				 */
				function f_cse_dauProcedure_securityInfoHandler(in boolean p_notification_verdict) runs on AeSimu {
					// Local variables
					var ResponsePrimitive v_responsePrimitive;
					
					//Activate defaults when running on a PTC
					f_cse_activateDefaults_ae();							
					
					tc_ac.start;
					alt {
						[] mcaPortIn.receive(mw_request(mw_notifyNotification(mw_contentNotification(?)))) -> value vc_request {
							tc_ac.stop;
							setverdict(pass, __SCOPE__ & ":INFO: Notification received");
							
							tc_ac.stop;
							//send response notification to DAU Request
							v_responsePrimitive := valueof(m_responseNotification(int2000, omit));
							v_responsePrimitive.primitiveContent.securityInfo.securityInfoType:=int2; //Dynamic Authorization Response
							v_responsePrimitive.requestIdentifier := vc_request.primitive.requestPrimitive.requestIdentifier;
							f_send(e_mcaPortIn, m_response(v_responsePrimitive));
						}
						[] mcaPortIn.receive{
							tc_ac.stop;
							setverdict(inconc, __SCOPE__ & ":ERROR: unexpected message received");
							tc_ac.start;
							repeat;
						}
						[] tc_ac.timeout {
							if (p_notification_verdict)
							{
								setverdict(fail, __SCOPE__ & ": No notification received");
							}
							else
							{
								setverdict(inconc, __SCOPE__ & ": No notification received");
							}
						}
					}
	    		    	
				} //end f_cse_notifyProcedure_representationHandler				
				
				/**
				 * @desc Handling message exchange for the dynamic authorization
				 * @param p_responseStatusCode Response Status Code to be used for the response to the verification request
				 * @verdict 
				 */
				function f_cse_notifyProcedure_dynamicAuthorizationHandler(in integer p_secInfoType, template (omit) DynAuthJWT p_token := omit, in AccessControlOperations p_grantedPrivileges := int61, in Timestamp p_privilegesLifetime := "21001231T012345") runs on AeSimu {
					// Local variables
					var boolean v_response :=false;
					var ResponsePrimitive v_responsePrimitive;
					var template Notification v_notificationRequest := mw_contentNotificationVerification;
					
					//Activate defaults when running on a PTC
					f_cse_activateDefaults_ae();		
    			
					//Preparation of Notification response to be sent
					v_responsePrimitive := valueof(m_responseNotification(int2000, omit));

					tc_ac.start;
					alt {
						[] mcaPortIn.receive(mw_request(mw_notifyNotification(v_notificationRequest))) -> value vc_request {
							tc_ac.stop;
							//setverdict(pass, __SCOPE__ & ": DAU notification received");
							v_response:=true;
						}
						[] tc_ac.timeout {
							//setverdict(inconc, __SCOPE__ & ": No DAU notification received");
							stop;
						}
					}
						
					v_responsePrimitive.requestIdentifier := vc_request.primitive.requestPrimitive.requestIdentifier;

					if (v_response) {
						if (p_secInfoType==2)
						{
							v_responsePrimitive.primitiveContent.securityInfo.securityInfoType:=int2; //DynamicAuthorizationResponse
							v_responsePrimitive.primitiveContent.securityInfo.dasResponse.dynamicACPInfo.grantedPrivileges.accessControlRule_list[0].accessControlOperations := p_grantedPrivileges;
							v_responsePrimitive.primitiveContent.securityInfo.dasResponse.dynamicACPInfo.privilegesLifetime.alt_ := p_privilegesLifetime;
							if (isvalue(p_token))
							{
								v_responsePrimitive.primitiveContent.securityInfo.dasResponse.tokens[0] := valueof(p_token);
							}
						}
						else if (p_secInfoType==1)
						{
							v_responsePrimitive.primitiveContent.securityInfo.securityInfoType:=int1; //DynamicAuthorizationRequest
						}
						f_send(e_mcaPortIn, m_response(v_responsePrimitive));
					}

				} //end f_cse_notifyProcedure_dynamicAuthorizationHandler



			}// end of group NotificationFunctions 	
			
			group AnnouncementFunctions {
				
				/**
				 * @desc Handling of announcement of resources
				 * @param p_requestPrimitive Expected announcement primitive
				 * @param p_responseStatusCode Response Status code to be sent as response
				 * @param p_expectedResourceIndex Expected target parent resource of the announcemnet
				 * @verdict 
				 */
				function f_cse_announcementProcedure_createHandler(template RequestPrimitive p_requestPrimitive := mw_createAnnc, in ResponseStatusCode p_responseStatusCode := int2001, template (omit) integer p_expectedParentResourceIndex := omit) runs on CseSimu return integer{
					// Local variables
					var integer v_announcedResourceIndex;
					var RequestPrimitive v_request;
					var ResponsePrimitive v_response;
					var XSD.ID v_cseIdPattern := vc_cseSimuDesc.cseId;
					template XSD.AnyURI v_announcedResourceAddress := pattern "{v_cseIdPattern}*";
					
					
					//Activate defaults when running on a PTC
					f_cse_activateDefaults_cse1();		
				
					p_requestPrimitive.to_ := v_announcedResourceAddress;
					tc_ac.start;
					alt {
						[] mccPortIn.receive(mw_request(p_requestPrimitive)) -> value vc_request {
							tc_ac.stop;
							setverdict(pass, __SCOPE__ & ":INFO: Expected Announcement received");
							v_announcedResourceIndex := f_processCreateRequestPrimitive(vc_request.primitive.requestPrimitive, p_responseStatusCode, p_expectedParentResourceIndex);
							f_send(e_mccPortIn, m_response(vc_response.primitive.responsePrimitive));
							if(getverdict == inconc) {
								setverdict(fail, __SCOPE__ & ":ERROR: Wrong target resource address");
							}	
						}
						[] mccPortIn.receive(mw_request(mw_createAnnc)) -> value vc_request {
							tc_ac.stop;
							if(f_getTargetCseId(vc_request.primitive.requestPrimitive.to_) ==  PX_TS_CSE2.cseId) {
								setverdict(pass, __SCOPE__ & ":INFO: Announcement received targeting CSE2");
								mccPortInternal.send(vc_request.primitive.requestPrimitive);
								alt {
									[]mccPortInternal.receive(mw_responsePrimitive(?)) -> value v_response {
									}
								}
							
								f_send(e_mccPortIn, m_response(v_response));
								if(vc_request.primitive.requestPrimitive.resourceType == int10005){
									tc_ac.start;
									repeat;
								} else {
									break;
								};
							}
							if((vc_request.primitive.requestPrimitive.resourceType == int10005) and (not(isvalue(p_expectedParentResourceIndex)))) {
								setverdict(pass, __SCOPE__ & ":INFO:  Request received for CSEBaseAnnc");
								p_expectedParentResourceIndex := f_processCreateRequestPrimitive(vc_request.primitive.requestPrimitive, -, vc_cSEBaseIndex);
								f_send(e_mccPortIn, m_response(vc_response.primitive.responsePrimitive));
								tc_ac.start;
								repeat;
							} else {
								setverdict(fail, __SCOPE__ & ":ERROR:  Request received with unexpected parameters");
								v_announcedResourceIndex := f_processCreateRequestPrimitive(vc_request.primitive.requestPrimitive, int4000);
								f_send(e_mccPortIn, m_response(vc_response.primitive.responsePrimitive));
							}	
						}
						[vc_cseSimuDesc.cseName == "CSE2_NAME"] mccPortInternal.receive(p_requestPrimitive) -> value v_request {
							tc_ac.stop;
							setverdict(pass, __SCOPE__ & ":INFO: Expected Announcement received");
							v_announcedResourceIndex := f_processCreateRequestPrimitive(v_request, p_responseStatusCode, p_expectedParentResourceIndex);
							mccPortInternal.send(vc_response.primitive.responsePrimitive);
							if(getverdict == inconc) {
								setverdict(fail, __SCOPE__ & ":ERROR: Wrong target resource address");
							}	
						}
						[vc_cseSimuDesc.cseName == "CSE2_NAME"] mccPortInternal.receive(mw_createAnnc) -> value v_request {
							tc_ac.stop;
							if(v_request.resourceType == int10005) {
								setverdict(pass, __SCOPE__ & ":INFO:  Request received for CSEBaseAnnc");
								p_expectedParentResourceIndex := f_processCreateRequestPrimitive(v_request, -, vc_cSEBaseIndex);
								mccPortInternal.send(vc_response.primitive.responsePrimitive);
								tc_ac.start;
								repeat;
							} else {
								setverdict(fail, __SCOPE__ & ":ERROR:  Request received with unexpected parameters");
								v_announcedResourceIndex := f_processCreateRequestPrimitive(v_request, int4000);
								mccPortInternal.send(vc_response.primitive.responsePrimitive);
							}	
						}
						[] tc_ac.timeout {
							setverdict(fail, __SCOPE__ & ":ERROR:  No announcement received");
						}
					}
				
					f_checkCseSimuStatus();
					
					return v_announcedResourceIndex;
	
				} //end f_cse_announcementProcedure_createHandler
			
				/**
				 * @desc Message exchange for the announcement of resources
				 * @param p_resourceType ResourceType of the resource to be announced 
				 * @param p_requestPrimitive CREATE request to be used for the announcement
				 * @verdict 
				 */
				 //TODO To finalize this function
				function f_cse_announcementProcedure_announceResource(in ResourceType p_resourceType, template RequestPrimitive p_requestPrimitive := m_create) runs on CseSimu return integer {
					// Local variables
					var RequestPrimitive v_request;
					var integer v_resourceIndex := -1;
					var integer v_originalResourceIndex := -1;
					var template PrimitiveContent v_originalResource;
				
					//Create original resource locally if resource type is an announced variant
					if(p_resourceType == int10002) {
						if(ischosen(p_requestPrimitive.primitiveContent.aEAnnc)) {
							if(valueof(p_requestPrimitive.primitiveContent.aEAnnc.link) == "S") {
								p_requestPrimitive.primitiveContent.aEAnnc.link := f_getLocalResourceAddress() & "/" & "S"; 
							} else {
								v_originalResourceIndex := f_generateAndSetLocalResource(m_primitiveContentAe(m_contentCreateAe(omit, -, PX_TS_AE1.appId,omit)), -, int2);
								p_requestPrimitive.primitiveContent := f_setLink(valueof(p_requestPrimitive.primitiveContent), f_getLocalResourceAddress(v_originalResourceIndex));
							}
						}
					} else if (p_resourceType == int10003) {
						v_originalResourceIndex := f_generateAndSetLocalResource(m_primitiveContentContainer(m_contentCreateContainer), -, int3);
						p_requestPrimitive.primitiveContent := f_setLink(valueof(p_requestPrimitive.primitiveContent), f_getLocalResourceAddress(v_originalResourceIndex));
					}
					//TODO Add other resource types		
					
					v_request := f_getCreateRequestPrimitive(f_getAnnouncedResourceType(p_resourceType), p_requestPrimitive, vc_remoteCseIndex);
			
					f_send(e_mccPort, m_request(v_request));
					tc_ac.start;
					alt {
						[] mccPort.receive(mw_response(mw_responsePrimitiveOK)) -> value vc_response {
							tc_ac.stop;
							setverdict(pass, __SCOPE__&":INFO: Resource type " & int2str(enum2int(p_resourceType)) & " created successfuly");
							f_checkAttributesToBeSaved(p_resourceType, v_request, vc_response.primitive.responsePrimitive);
							v_resourceIndex := f_setResource(vc_response.primitive.responsePrimitive.primitiveContent, f_getAnnouncedResourceType(p_resourceType), vc_remoteCseIndex);
							if(p_resourceType == int10002) {
								if(valueof(p_requestPrimitive.primitiveContent.aEAnnc.link) == "S") {
									v_originalResource.aE := m_contentCreateAe(omit, -, PX_TS_AE1.appId, omit);
									v_originalResource.aE.aE_ID := vc_response.primitive.responsePrimitive.primitiveContent.aEAnnc.aE_ID; 
									v_resourceIndex := f_generateAndSetLocalResource(valueof(v_originalResource), -, int2);
								}
							}
						}
						[] mccPort.receive(mw_response(mw_responsePrimitiveKO)) {
							tc_ac.stop;
							setverdict(inconc, __SCOPE__&":INFO: Error while creating resource type " & int2str(enum2int(p_resourceType)));
						}
						[] mccPort.receive {
							tc_ac.stop;
							setverdict(inconc, __SCOPE__&":INFO: Unexpected message received");
						}
						[] tc_ac.timeout {
							setverdict(inconc, __SCOPE__&":INFO: No answer while creating resource type " & int2str(enum2int(p_resourceType)));
						}
					}	
				
					f_checkCseSimuStatus();
				
					return v_resourceIndex;
	
				} //end f_cse_announcementProcedure_announceResource	
				
				/**
				 * @desc Handling message exchange for the AE Annc update
				 * @verdict 
				 */
				//TODO TO BE FINALIZED
				function f_cse_announcementProcedure_updateHandler(template  RequestPrimitive p_requestprimitive := mw_update, in ResponseStatusCode p_responseStatusCode := int2004, template(omit) integer p_expectedResourceIndex := omit) runs on CseSimu {

					// Local variables
					var integer v_parentIndex := vc_localRemoteCseIndex;
					var integer v_announcedResourceIndex;
					var ResponsePrimitive v_responsePrimitive;
					var PrimitiveContent v_announcedResource;

					//Activate defaults when running on a PTC
					f_cse_activateDefaults_cse1();		
				
					tc_ac.start;
					alt {
						[] mccPortIn.receive(mw_request(p_requestprimitive)) -> value vc_request {
							tc_ac.stop;
							setverdict(pass, __SCOPE__ & ":INFO: Expected UPDATE Announcement received");
	
							f_processUpdateRequestPrimitive(vc_request.primitive.requestPrimitive, -, -, vc_request.nullFields);
							f_send(e_mccPortIn, m_response(vc_response.primitive.responsePrimitive));
						}
						[] mccPortIn.receive(mw_request(mw_update)) -> value vc_request {
							setverdict(fail, __SCOPE__ & ":ERROR:  Request received with unexpected parameters");
							v_responsePrimitive := valueof(m_responsePrimitive(int4000,vc_request.primitive.requestPrimitive.requestIdentifier));
							f_send(e_mccPortIn, m_response(v_responsePrimitive));
						}
						[] tc_ac.timeout {
							setverdict(fail, __SCOPE__ & ":ERROR:  No announcement received");
						}
					}
				
					f_checkCseSimuStatus();

				} //end f_cse_announcementProcedure_updateHandler	
				
				/**
				 * @desc Handling of announcement of resources
				 * @param p_from Expected originator of the request primitive
				 * @param p_to Expected receiver of the request primitive
				 * @verdict 
				 */
				 //TODO To finalize this function
				function f_cse_announcementProcedure_deleteHandler(template  RequestPrimitive p_requestprimitive := mw_delete, in ResponseStatusCode p_responseStatusCode := int2002, template(omit) integer p_expectedResourceIndex := omit) runs on CseSimu {
					// Local variables
					var MsgIn v_request;
					var integer v_parentIndex := vc_localRemoteCseIndex;
					var integer v_announcedResourceIndex;
					var ResponsePrimitive v_responsePrimitive;
					var PrimitiveContent v_announcedResource;

					//Activate defaults when running on a PTC
					f_cse_activateDefaults_cse1();		
				
					tc_ac.start;
					alt {
						[] mccPortIn.receive(mw_request(p_requestprimitive)) -> value v_request {
							tc_ac.stop;
							setverdict(pass, __SCOPE__ & ":INFO: Expected DELETE Announcement received");
	
							f_processDeleteRequestPrimitive(v_request.primitive.requestPrimitive);
							f_send(e_mccPortIn, m_response(vc_response.primitive.responsePrimitive));
						}
						[] mccPortIn.receive(mw_request(mw_delete())) -> value v_request {
							setverdict(fail, __SCOPE__ & ":ERROR:  Request received with unexpected parameters");
							v_responsePrimitive := valueof(m_responsePrimitive(int4000,v_request.primitive.requestPrimitive.requestIdentifier));
							f_send(e_mccPortIn, m_response(v_responsePrimitive));
						}
						[] tc_ac.timeout {
							setverdict(fail, __SCOPE__ & ":ERROR:  No announcement received");
						}
					}
				
					f_checkCseSimuStatus();

				} //end f_cse_announcementProcedure_deleteHandler
				
			}//end of group AnnouncementFunctions
			
			/**
			 * @desc Message exchange for the creation of a resource
			 * @param p_resourceType Resource type of the resource to be created
			 * @param p_requestPrimitive UPDATE request primitive to be used
			 * @param p_resourceIndex Internal resource index which indicates the resource to be updated	 
			 * @verdict 
			 */
			function f_cse_createResourceHandler(template RequestPrimitive p_request := mw_create,  in ResponseStatusCode p_responseStatusCode := int2001) runs on CseSimu return integer{
				
				var integer v_localResourceIndex;
				
				//Activate defaults when running on a PTC
				f_cse_activateDefaults_cse1();	
			
				tc_ac.start;
				alt {
					[] mccPortIn.receive(mw_request(p_request)) -> value vc_request {
						tc_ac.stop;
						v_localResourceIndex := f_processCreateRequestPrimitive(vc_request.primitive.requestPrimitive, p_responseStatusCode);
						f_send(e_mccPortIn, m_response(vc_response.primitive.responsePrimitive));
					}
					[] mccPortIn.receive(mw_request(mw_create)) -> value vc_request {
						tc_ac.stop;
						v_localResourceIndex := f_processCreateRequestPrimitive(vc_request.primitive.requestPrimitive, int4000);
						f_send(e_mccPortIn, m_response(vc_response.primitive.responsePrimitive));
						setverdict(inconc, __SCOPE__&":INFO: Wrong expected create request");
					}
					[] tc_ac.timeout {
						setverdict(inconc, __SCOPE__&":INFO: No creation for resource received");
					}
				}	
			
				f_checkCseSimuStatus();
				
				return v_localResourceIndex;
			
			}// end f_cse_createResourceHandler
			
			/**
			 * @desc Activate default for CseSimu
			 */
			function f_cse_defaultHandler() runs on CseSimu {
				
					//Activate defaults when running on a PTC
					f_cse_activateDefaults_cse1();	
					
					tc_ac.start;
					alt {
						[] infoPort.receive(OneM2M_TypesAndValues.SyncPoints:e_done) {
							log(__SCOPE__, "Peer component done")
						}
						[] tc_ac.timeout {
						}
					}
			
				}// end f_cse_defaultHandler
			
			/**
			 * @desc Activate default for AeSimu
			 */
			function f_cse_defaultHandler_aeSimu() runs on AeSimu {
				
					//Activate defaults when running on a PTC
					f_cse_activateDefaults_ae();	
					
					tc_ac.start;
					alt {
						[] infoPort.receive(OneM2M_TypesAndValues.SyncPoints:e_done) {
							log(__SCOPE__, "Peer component done")
						}
						[] tc_ac.timeout {
						}
					}
			
				}// end f_cse_defaultHandler_aeSimu
			
			/**
			 * @desc Creation of a local resource
			 * @param p_resourceType Resource type of the resource to be created
			 * @param p_requestPrimitive CREATE request primitive for the resource to be created
			 * @param p_parentIndex Internal resource index which indicates the parent of the resource to be created
			 * @return Internal resource index of the created resource
			 * @verdict 
			 */
			function f_cse_createLocalResource(template UtTriggerPrimitive p_utRequest := m_utCreate,  charstring p_action) runs on CseSimu return integer {
			
				var ResponsePrimitive v_response;
				var integer v_parentResourceIndex := -1;
				var integer v_localResourceIndex := -1;
				var PrimitiveContent v_localResource;
			
				//Activate defaults when running on a PTC
				f_cse_activateDefaults_cse1();		
								
				p_utRequest.requestPrimitive.to_ := f_getResourceAddress();				
				f_cse_sendUtPrimitive_cseSimu(p_utRequest, p_action);
				
				tc_ac.start;
				alt {    				
					[] mccPortIn.receive(mw_request(mw_create(?,?))) -> value vc_request {
						tc_ac.stop;
    					
						v_parentResourceIndex := f_getLocalResourceIndex(vc_request.primitive.requestPrimitive.to_);
						if(v_parentResourceIndex == -1) {
							log(__SCOPE__&": ERROR: Target resource not found");
							v_response := valueof(m_responsePrimitive(int4004,vc_request.primitive.requestPrimitive.requestIdentifier));
	
						} else {
							v_localResource := f_generateLocalResource(vc_request.primitive.requestPrimitive.primitiveContent, v_parentResourceIndex, vc_request.primitive.requestPrimitive.resourceType);
							v_localResourceIndex := f_setLocalResource(v_localResource, vc_request.primitive.requestPrimitive.resourceType, v_parentResourceIndex);

							v_response := valueof(m_responsePrimitive(int2001,vc_request.primitive.requestPrimitive.requestIdentifier));
							v_response.primitiveContent := vc_localResourcesList[v_localResourceIndex].resource;
						}
						v_response.from_ := vc_cseSimuDesc.cseId;
						v_response.to_ := vc_request.primitive.requestPrimitive.from_;
            			f_send(e_mccPortIn, m_response(v_response));
					}
    					
					[] tc_ac.timeout {
						setverdict(inconc, __SCOPE__&":INFO: Create request not received");
					}	     				   	
				}    
				
				f_checkCseSimuStatus();	
				
				return v_localResourceIndex;
		
			}	

			/**
			 * @desc Message exchange for the update of an announced resource
			 * @param p_requestPrimitive UPDATE request primitive to be used
			 * @verdict 
			 */
			function f_cse_updateAnnouncedResource(in RequestPrimitive p_requestPrimitive) runs on CseSimu {

        f_send(e_mccPort, m_request(p_requestPrimitive));
				tc_ac.start;
				alt {
					[] mccPort.receive(mw_response(mw_responsePrimitiveOK)) -> value vc_response {
						tc_ac.stop;
						setverdict(pass, __SCOPE__&":INFO: Attribute of announced resource updated successfuly");
					}
					[] mccPort.receive(mw_response(mw_responsePrimitiveKO)) -> value vc_response {
						tc_ac.stop;
						setverdict(inconc, __SCOPE__&":INFO: Error while updating announced resource");
					}
					[] mccPort.receive{
						tc_ac.stop;
						setverdict(inconc, __SCOPE__&":INFO: Unexpected message received");
					}
					[] tc_ac.timeout {
						setverdict(inconc, __SCOPE__&":INFO: No answer while updating announced resource");
					}
				}	
				
				f_checkCseSimuStatus();
				
			}// end f_cse_updateAnnouncedResource
			
			/**
			 * @desc Message exchange for the update of a resource
			 * @param p_resourceIndex Internal resource index which indicates the resource to be updated	 
			 * @param p_requestPrimitive UPDATE request primitive to be used
			 * @verdict 
			 */
			function f_cse_updateResourceHandler(integer p_resourceIndex, template RequestPrimitive p_request := mw_update,  in ResponseStatusCode p_responseStatusCode := int2004) runs on CseSimu {
				
				var integer v_targetResourceIndex := -1;
				
				//Activate defaults when running on a PTC
				f_cse_activateDefaults_cse1();	
				
				tc_ac.start;
				alt {
					[] mccPortIn.receive(mw_request(p_request)) -> value vc_request {
						tc_ac.stop;
						
						v_targetResourceIndex := f_processUpdateRequestPrimitive(vc_request.primitive.requestPrimitive, p_responseStatusCode);
						if(v_targetResourceIndex == p_resourceIndex) {
							setverdict(pass, __SCOPE__&":INFO: Resource updated successfuly");
						} else {
							setverdict(inconc, __SCOPE__&":INFO: Unexpected resource update");
						}
						f_send(e_mccPortIn, m_response(vc_response.primitive.responsePrimitive));
						
					}
					[] mccPortIn.receive(mw_request(mw_update)) -> value vc_request {
						tc_ac.stop;
						v_targetResourceIndex := f_processUpdateRequestPrimitive(vc_request.primitive.requestPrimitive, int4000);
						f_send(e_mccPortIn, m_response(vc_response.primitive.responsePrimitive));
						setverdict(inconc, __SCOPE__&":INFO: Wrong expected update request");
					}
					[] tc_ac.timeout {
						setverdict(inconc, __SCOPE__&":INFO: No answer while updating resource");
					}
				}	
				
				f_checkCseSimuStatus();
				
			}// end f_cse_updateResourceHandler
			
			/**
			 * @desc Message exchange for the retrieve of a resource
			 * @param p_resourceIndex Internal resource index which indicates the expected resource to be retrieved	 
			 * @param p_requestPrimitive RETRIEVE request primitive to be used
			 * @verdict 
			 */
			function f_cse_retrieveResourceHandler(integer p_resourceIndex, template RequestPrimitive p_request := mw_retrieve(?), in ResponseStatusCode p_responseStatusCode := int2000) runs on CseSimu {
				
				var integer v_targetResourceIndex := -1;
				
				//Activate defaults when running on a PTC
				f_cse_activateDefaults_cse1();	
				
				tc_ac.start;
				alt {
					[] mccPortIn.receive(mw_request(p_request)) -> value vc_request {
						tc_ac.stop;
						v_targetResourceIndex := f_processRetrieveRequestPrimitive(vc_request.primitive.requestPrimitive, p_responseStatusCode);
						if(v_targetResourceIndex == p_resourceIndex) {
							setverdict(pass, __SCOPE__&":INFO: Resource retrieved successfuly");
						} else {
							setverdict(inconc, __SCOPE__&":INFO: Unexpected resource retrieval");
						}
						f_send(e_mccPortIn, m_response(vc_response.primitive.responsePrimitive));
						
					}
					[] mccPortIn.receive(mw_request(mw_retrieve(?))) -> value vc_request {
						tc_ac.stop;
						v_targetResourceIndex := f_processRetrieveRequestPrimitive(vc_request.primitive.requestPrimitive, int4000);
						f_send(e_mccPortIn, m_response(vc_response.primitive.responsePrimitive));
						setverdict(inconc, __SCOPE__&":INFO: Wrong expected retrieve request");
					}
					[] tc_ac.timeout {
						setverdict(inconc, __SCOPE__&":INFO: No answer while retrieving resource");
					}
				}	
				
				f_checkCseSimuStatus();
				
			}// end f_cse_retrieveResourceHandler
			
			/**
			 * @desc Message exchange for the memberType validation of group members
			 * @param p_resourceIndex Internal resource index which indicates the expected resource to be retrieved	 
			 * @param p_requestPrimitive RETRIEVE request primitive to be used
			 * @param p_responseStatusCode Response Status code to be returned
			 * @verdict 
			 */
			function f_cse_memberTypeValidationHandler(integer p_resourceIndex, in ResponseStatusCode p_responseStatusCode := int2000) runs on CseSimu {
		
				var integer v_targetResourceIndex := -1;
				var integer v_localResourceIndex := -1;
				
				//Activate defaults when running on a PTC
				f_cse_activateDefaults_cse1();	
		
				tc_ac.start;
				alt {
					[] mccPortIn.receive(mw_request(mw_retrieve(?))) -> value vc_request {
						tc_ac.stop;
						v_targetResourceIndex := f_processRetrieveRequestPrimitive(vc_request.primitive.requestPrimitive, p_responseStatusCode);
						if(v_targetResourceIndex == p_resourceIndex) {
							setverdict(pass, __SCOPE__&":INFO: Resource retrieved successfuly");
						} else {
							setverdict(inconc, __SCOPE__&":INFO: Unexpected resource retrieval");
						}
						f_send(e_mccPortIn, m_response(vc_response.primitive.responsePrimitive));
				
					}
					[] mccPortIn.receive(mw_request(mw_create())) -> value vc_request {
						tc_ac.stop;
									
						v_localResourceIndex := f_processCreateRequestPrimitive(vc_request.primitive.requestPrimitive, p_responseStatusCode);
						
						setverdict(pass, __SCOPE__&":INFO: Subgroup creation received");
						
						f_send(e_mccPortIn, m_response(vc_response.primitive.responsePrimitive));
					}
					[] tc_ac.timeout {
						setverdict(inconc, __SCOPE__&":INFO: No answer while retrieving resource");
					}
				}	
		
				f_checkCseSimuStatus();
		
			}// end f_cse_memberTypeValidationHandler
		
			/**
			 * @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_cseSimu(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, p_resourceTypeList));
				f_send(e_mccPort, 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 Message exchange for the delete of a resource
			 * @param p_resourceIndex Internal resource index which indicates the expected resource to be deleted	 
			 * @param p_requestPrimitive DELETE request primitive to be used
			 * @verdict 
			 */
			function f_cse_deleteResourceHandler(integer p_resourceIndex, template RequestPrimitive p_request := mw_delete,  in ResponseStatusCode p_responseStatusCode := int2002) runs on CseSimu {
				
				var integer v_targetResourceIndex := -1;
				
				//Activate defaults when running on a PTC
				f_cse_activateDefaults_cse1();	
				
				tc_ac.start;
				alt {
					[] mccPortIn.receive(mw_request(p_request)) -> value vc_request {
						tc_ac.stop;
						v_targetResourceIndex := f_processDeleteRequestPrimitive(vc_request.primitive.requestPrimitive, p_responseStatusCode);
						if(v_targetResourceIndex == p_resourceIndex) {
							setverdict(pass, __SCOPE__&":INFO: Resource deleted successfuly");
						} else {
							setverdict(inconc, __SCOPE__&":INFO: Unexpected resource retrieval");
						}
						f_send(e_mccPortIn, m_response(vc_response.primitive.responsePrimitive));
						
					}
					[] mccPortIn.receive(mw_request(mw_delete)) -> value vc_request {
						tc_ac.stop;
						v_targetResourceIndex := f_processDeleteRequestPrimitive(vc_request.primitive.requestPrimitive, int4000);
						f_send(e_mccPortIn, m_response(vc_response.primitive.responsePrimitive));
						setverdict(inconc, __SCOPE__&":INFO: Wrong expected delete request");
					}
					[] tc_ac.timeout {
						setverdict(inconc, __SCOPE__&":INFO: No answer while retrieving resource");
					}
				}	
				
				f_checkCseSimuStatus();
				
			}// end f_cse_deleteResourceHandler
			
			/**
			 * @desc Check that a resource is present in the IUT (resourceId is known)
			 * @param p_resourceIndex Resource index 
			 * @return boolean
			 */
			function f_cse_isResourcePresent_cseSimu (integer p_resourceIndex) runs on CseSimu return boolean {

				//Check to see if the resource is present or not
				f_send(e_mccPort, m_request(m_retrieve(f_getResourceAddress(p_resourceIndex), f_getOriginator(p_resourceIndex))));
				
				tc_ac.start;
				alt {
					[] mccPort.receive(mw_response(mw_responsePrimitive(int2000))) {
						tc_ac.stop;
						setverdict(pass, testcasename() & ": Resource present: " & f_getResourceAddress(p_resourceIndex));
						return true;
					}
					[] mccPort.receive(mw_response(mw_responsePrimitive(int4004))) {
						tc_ac.stop;
						setverdict(pass, testcasename() & ": Resource: " & f_getResourceAddress(p_resourceIndex) & " not found");
						return false;
					}
					[] mccPort.receive(mw_response(mw_responsePrimitive(?, -))) {
						tc_ac.stop;
						setverdict(inconc, testcasename() & ": Wrong response status code in the response");
						return false;
					}
					[] tc_ac.timeout {
						setverdict(inconc, testcasename() & ": No answer while retrieving resource");
						return false;
					}
				}	
				return false;
			}	
	    		
			/**
			 * @desc Check that a resource is not present in the IUT (resourceId is NOT known)
			 * @param p_parentIndex Index of the parent resource of the resource to be checked
			 * @param p_resourceName Resource name (Hierarchical method is used) of the resource to be checked
			 * @return boolean
			 */
			function f_cse_isResourceNotPresent_cseSimu (integer p_parentIndex, XSD.String p_resourceName) runs on CseSimu return boolean {
			
				log(testcasename() & ":INFO: Hierarchical addressing method is required to check the non presence of the resource");
				
				//Check to see if the resource has NOT been created
				f_send(e_mccPort, m_request(m_retrieve(f_getResourceAddress(p_parentIndex, e_hierarchical) & "/" & p_resourceName, f_getOriginator(p_parentIndex))));
				
				tc_ac.start;
				alt {
					[] mccPort.receive(mw_response(mw_responsePrimitive(int4004))) {
						tc_ac.stop;
						setverdict(pass, testcasename() & ": Resource not present");
						return true;
					}
					[] mccPort.receive(mw_response(mw_responsePrimitive(int2000))) {
						tc_ac.stop;
						setverdict(pass, testcasename() & ": Resource " & p_resourceName & " present");
						return false;
					}
					[] mccPort.receive(mw_response(mw_responsePrimitive(?))) {
						tc_ac.stop;
						setverdict(inconc, testcasename() & ": Wrong response status code in the response");
						return false;
					}
					[] tc_ac.timeout {
						setverdict(inconc, testcasename() & ": No answer while retrieving resource");
						return false;
					}
				}	
				return false;
			}			
	    		
			/**
			 * @desc Registration of Test System (simulating a CSE) to the CSE IUT (creation of remoteCSE)
			 * @param p_requestPrimitive Template request primitive
			 * @param p_primitiveContent Expected primitiveContent in the CREATE response primitive
			 * @return Internal resource index of the created resource
			 */
			function f_cse_registerRemoteCse(in template RequestPrimitive p_requestPrimitive, in template PrimitiveContent p_contentResponse := ?) runs on CseSimu return integer {
    			
				var MsgIn v_response;
				var RequestPrimitive v_request;
				var PrimitiveContent v_localRemoteCSEResource;
				
				//Activate defaults when running on a PTC
				f_cse_activateDefaults_cse1();

				v_request := f_getCreateRequestPrimitive(int16, p_requestPrimitive, -1);

				f_send(e_mccPort, m_request(v_request));
				tc_ac.start;
				alt {
					[] mccPort.receive(mw_response(mw_responsePrimitiveOK(p_contentResponse))) -> value v_response {
						tc_ac.stop;
						setverdict(pass, __SCOPE__&":INFO: Resource type remoteCSE created successfuly");
						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(vc_myInterfaces[enum2int(valueof(InterfaceIds:e_mccPort))].myHost))), vc_cSEBaseIndex, int16);
						vc_localRemoteCseIndex := f_setLocalResource(v_localRemoteCSEResource, int16, vc_cSEBaseIndex);
					}
					[] mccPort.receive(mw_response(mw_responsePrimitiveKO)) {
						tc_ac.stop;
						setverdict(inconc, __SCOPE__&":INFO: Error while creating resource type remoteCSE");
					}
					[] tc_ac.timeout {
						setverdict(inconc, __SCOPE__&":INFO: No answer while creating resource type remoteCSE");
					}
				}	

				f_checkCseSimuStatus();

				return vc_remoteCseIndex;
    		
			}
			
			/**
			 * @desc Registration of the CSE IUT to the Test System (simulating a CSE) 
			 * @param p_requestPrimitive Template request primitive
			 * @return Internal resource index of the created resource
			 */
			function f_cse_registrationRemoteCse(in template (present) RequestPrimitive p_requestPrimitive := ?) runs on CseSimu return integer {
    			
				var MsgIn v_request;
				var ResponsePrimitive v_response;
				var PrimitiveContent v_localRemoteCSEResource;
				var integer v_resourceIndex := -1;
				var template UtTriggerPrimitive v_utRequest := m_utCreateRemoteCSE;
				var charstring v_action := "Please, send a CSE registration request";
				var ResponsePrimitive v_responsePrimitive;
				var boolean v_remoteCSERegistered:=false;
				
				//Activate defaults when running on a PTC
				f_cse_activateDefaults_cse1();			
				
				//send triggering primitive to SUT
			  f_cse_sendUtPrimitive_cseSimu(v_utRequest,v_action);

				tc_ac.start;
				alt {
					[not v_remoteCSERegistered] mccPortIn.receive(mw_request(p_requestPrimitive)) -> value v_request {
						tc_ac.stop;
						setverdict(pass, __SCOPE__&":INFO: Resource type remoteCSE created successfuly");
						v_localRemoteCSEResource := f_generateLocalResource(v_request.primitive.requestPrimitive.primitiveContent, vc_cSEBaseIndex, int16);//TODO Get index from v_request.primitive.requestPrimitive.to_
						v_localRemoteCSEResource.remoteCSE.cSE_ID := v_request.primitive.requestPrimitive.from_;
						vc_localRemoteCseIndex := f_setLocalResource(v_localRemoteCSEResource, int16, vc_cSEBaseIndex);
						
						v_response := valueof(m_responsePrimitive(int2001,v_request.primitive.requestPrimitive.requestIdentifier));
						v_response.from_ := vc_cseSimuDesc.cseId;
						v_response.to_ := v_request.primitive.requestPrimitive.from_;
						v_response.primitiveContent.remoteCSE := vc_localResourcesList[vc_localRemoteCseIndex].resource.remoteCSE;
						f_send(e_mccPortIn, m_response(v_response));
						
						vc_remoteCseIndex := f_setResource(valueof(m_primitiveContentRemoteCSE(m_contentMyRemoteCSEResource(f_getLocalPoA(vc_cseSimuDesc.mcaPortIn, "")))), int16, -1, true);
						vc_componentRegistered := true;
						v_resourceIndex := vc_remoteCseIndex;
						v_remoteCSERegistered:=true;
						tc_ac.start(10.0);
						repeat;
					}
					[] tc_ac.timeout {
						if(not (v_remoteCSERegistered)){
							setverdict(inconc, __SCOPE__&":INFO: No request received for creating resource type remoteCSE");
						}
					}
				}

				f_checkCseSimuStatus();

				return v_resourceIndex;
    		
			}
						
			/**
			 * @desc Receive a request from the CSE IUT to the Test System (simulating a CSE) 
			 * @param p_requestPrimitive Expected CREATE request primitive
			 */
			function f_cse_receiveCreateRequest_cseSimu(in template RequestPrimitive p_requestPrimitive := ?) runs on CseSimu {
				var ResponsePrimitive v_responsePrimitive;
    			
    			//Activate defaults when running on a PTC
				f_cse_activateDefaults_cse1();
			
				tc_ac.start;
				alt {
					[] mccPortIn.receive(mw_request(p_requestPrimitive)) -> value vc_request {
						tc_ac.stop;
						setverdict(pass, __SCOPE__&":INFO: CREATE Request received successfuly");
						v_responsePrimitive := f_getCreateResponsePrimitive(vc_request.primitive.requestPrimitive.resourceType, vc_request.primitive.requestPrimitive);
						v_responsePrimitive.responseStatusCode := int2001;
						f_send(e_mccPortIn, m_response(v_responsePrimitive));
					}
					[] mccPortIn.receive(mw_request(?)) {
						tc_ac.stop;
						setverdict(fail, __SCOPE__&":INFO: Unexpected CREATE Request received");
					}
					[] mccPortIn.receive {
						tc_ac.stop;
						setverdict(fail, __SCOPE__&":INFO: Unexpected message received");
					}
					[] tc_ac.timeout {
						setverdict(fail, __SCOPE__&":INFO: No answer while creating resource type RemoteCSE");
					}
				}	

				f_checkCseSimuStatus();
				    		
			}

			/**
			 * @desc   Creation  and save a local resource (Test System simulating a CSE)
			 * @param  p_resource          Resource to be created
			 * @param  p_parentIndex       Parent resource index of resource to be saved
			 * @param  p_resourceType      Type of the resource to be created
			 * @return Index of internal created resource
			 */
			function f_generateAndSetLocalResource(in template(omit) PrimitiveContent p_resource := omit, in integer p_parentIndex := 0, in ResourceType p_resourceType) runs on CseSimu return Integer { //vc_cSEBaseIndex, in ResourceType p_resourceType) runs on CseSimu return Integer {

				var PrimitiveContent v_localResource;
				var integer v_localResourceIndex;
				
				v_localResource := f_generateLocalResource(p_resource, p_parentIndex, p_resourceType);
				
				v_localResourceIndex := f_setLocalResource(v_localResource, p_resourceType, p_parentIndex);
				
				return v_localResourceIndex;
				
			}//End of function		
			
			/**
			 * @desc   Creation of a local resource (Test System simulating a CSE)
			 * @param  p_resource          Resource to be created
			 * @param  p_parentIndex       Parent resource index of resource to be saved
			 * @param  p_resourceType      Type of the resource to be created
			 * @return Internal created resource
			 */
			function f_generateLocalResource(in template(omit) PrimitiveContent p_resource := omit, in integer p_parentIndex := 0, in ResourceType p_resourceType) runs on CseSimu return PrimitiveContent { //vc_cSEBaseIndex, in ResourceType p_resourceType) runs on CseSimu return PrimitiveContent {

				var integer v_resourceIndex := lengthof(vc_localResourcesList);
				var PrimitiveContent v_myResource;
				
				// TODO To review the code (use of indexes, generation of value for certain attributes, etc..)
				if(p_resourceType == int5 and ispresent(p_resource)) {	//CSEBase
					if(ischosen(p_resource.cSEBase)){
						v_myResource.cSEBase:= valueof(p_resource.cSEBase);
					v_myResource.cSEBase.creationTime := fx_generateTimestamp();
					v_myResource.cSEBase.creationTime := "20171231T012345";
					v_myResource.cSEBase.lastModifiedTime := v_myResource.cSEBase.creationTime;		
					v_myResource.cSEBase.cseType := vc_cseType;
					v_myResource.cSEBase.resourceID := f_resourceIdCleaner(v_myResource.cSEBase.resourceID);
					v_myResource.cSEBase.pointOfAccess := {f_getLocalPoA(vc_cseSimuDesc.mccPortIn, "")};
					}	    
				}else if(p_resourceType == int16 and ispresent(p_resource)) {			//RemoteCSE
					if(ischosen(p_resource.remoteCSE)){
						v_myResource.remoteCSE := valueof(p_resource.remoteCSE);
						
						if(not(ispresent(p_resource.remoteCSE.resourceName))) {
							v_myResource.remoteCSE.resourceName := "remoteCSE" & int2str(v_resourceIndex);
						}
						v_myResource.remoteCSE.resourceType := p_resourceType;
						v_myResource.remoteCSE.resourceID := f_resourceIdCleaner(v_myResource.remoteCSE.cSE_ID);
						v_myResource.remoteCSE.parentID := f_getResourceId(vc_localResourcesList[p_parentIndex].resource);
						v_myResource.remoteCSE.creationTime := fx_generateTimestamp();
						v_myResource.remoteCSE.creationTime := "20171231T012345";
						if(not(ispresent(p_resource.remoteCSE.expirationTime))) {
							v_myResource.remoteCSE.expirationTime := "20301231T012345";
						}
						v_myResource.remoteCSE.lastModifiedTime := v_myResource.remoteCSE. creationTime;											
						v_myResource.remoteCSE.announceTo := omit;	
						v_myResource.remoteCSE.announcedAttribute := omit;	
						
						if(not(ispresent(p_resource.remoteCSE.pointOfAccess))) {
							//TODO Create a pollingChannel resource
							v_myResource.remoteCSE.pointOfAccess := omit;
						}	
						/*if(vc_localResourcesList[v_resourceIndex].resourceType == int5) {
							v_myResource.remoteCSE.m2M_Ext_ID := omit;	
							v_myResource.remoteCSE.trigger_Recipient_ID:= omit;
						}*/
						v_myResource.remoteCSE.nodeLink := omit;
					}
				} 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);
						v_myResource.aEAnnc.resourceType := p_resourceType;
						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;
						
						if(v_myResource.aEAnnc.link[lengthof(v_myResource.aEAnnc.link)-1] == "S"){
							v_myResource.aEAnnc.resourceID := "SaeA" & int2str(v_resourceIndex);
							v_myResource.aEAnnc.aE_ID := v_myResource.aEAnnc.resourceID;
							v_myResource.aEAnnc.link := substr(v_myResource.aEAnnc.link, 0, lengthof(v_myResource.aEAnnc.link)-1) & v_myResource.aEAnnc.resourceID;
						} else {
							v_myResource.aEAnnc.resourceID := "aeA" & int2str(v_resourceIndex);
						}
					}
				} 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);
						v_myResource.accessControlPolicyAnnc.resourceType := p_resourceType;
						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;	
					}
				} 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);
						v_myResource.containerAnnc.resourceType := p_resourceType;
						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;
					}
				} 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);
						v_myResource.groupAnnc.resourceType := p_resourceType;
						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;
					}
				} else if (p_resourceType == int10004 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);
						v_myResource.contentInstanceAnnc.resourceType := p_resourceType;
						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;
					}
				} else if (p_resourceType == int10005 and ispresent (p_resource)) { //CSEBaseAnnc
					if(ischosen(p_resource.cSEBaseAnnc)) {
						v_myResource.cSEBaseAnnc := valueof(p_resource.cSEBaseAnnc);
						v_myResource.cSEBaseAnnc.resourceName := "cSEBaseAnnc" & int2str(v_resourceIndex);
						v_myResource.cSEBaseAnnc.resourceType := p_resourceType;
						v_myResource.cSEBaseAnnc.resourceID := "cbA" & int2str(v_resourceIndex);
						v_myResource.cSEBaseAnnc.parentID := f_getResourceId(vc_localResourcesList[p_parentIndex].resource);
						v_myResource.cSEBaseAnnc.creationTime := fx_generateTimestamp();
						v_myResource.cSEBaseAnnc.lastModifiedTime := v_myResource.cSEBaseAnnc.creationTime;
					}
				} else if (p_resourceType == int10016 and ispresent (p_resource)) { //RemoteCSEAnnc
					if(ischosen(p_resource.remoteCSEAnnc)) {
						v_myResource.remoteCSEAnnc := valueof(p_resource.remoteCSEAnnc);
						v_myResource.remoteCSEAnnc.resourceName := "remoteCSEAnnc" & int2str(v_resourceIndex);
						v_myResource.remoteCSEAnnc.resourceType := p_resourceType;
						v_myResource.remoteCSEAnnc.resourceID := "csrA" & int2str(v_resourceIndex);
						v_myResource.remoteCSEAnnc.parentID := f_getResourceId(vc_localResourcesList[p_parentIndex].resource);
						v_myResource.remoteCSEAnnc.creationTime := fx_generateTimestamp();
						v_myResource.remoteCSEAnnc.lastModifiedTime := v_myResource.remoteCSEAnnc.creationTime;
					}
				} else if(p_resourceType == int10029 and ispresent(p_resource)) { //TimeSeriesAnnc
					if(ischosen(p_resource.timeSeriesAnnc)){
						v_myResource.timeSeriesAnnc := valueof(p_resource.timeSeriesAnnc);
						v_myResource.timeSeriesAnnc.resourceID := "tsA" & int2str(v_resourceIndex);
						v_myResource.timeSeriesAnnc.resourceName := "timeSeriesAnnc" & int2str(v_resourceIndex);
						v_myResource.timeSeriesAnnc.resourceType := p_resourceType;
						v_myResource.timeSeriesAnnc.parentID := f_getResourceId(vc_localResourcesList[p_parentIndex].resource);
						v_myResource.timeSeriesAnnc.creationTime := fx_generateTimestamp();
						v_myResource.timeSeriesAnnc.lastModifiedTime := v_myResource.timeSeriesAnnc.creationTime;											
					}				
				} else if(p_resourceType == int10030 and ispresent(p_resource)) { //TimeSeriesInstanceAnnc
					if(ischosen(p_resource.timeSeriesInstanceAnnc)){
						v_myResource.timeSeriesInstanceAnnc := valueof(p_resource.timeSeriesInstanceAnnc);
						v_myResource.timeSeriesInstanceAnnc.resourceID := "tsiA" & int2str(v_resourceIndex);
						v_myResource.timeSeriesInstanceAnnc.resourceName := "timeSeriesInstanceAnnc" & int2str(v_resourceIndex);
						v_myResource.timeSeriesInstanceAnnc.resourceType := p_resourceType;
						v_myResource.timeSeriesInstanceAnnc.parentID := f_getResourceId(vc_localResourcesList[p_parentIndex].resource);
						v_myResource.timeSeriesInstanceAnnc.creationTime := fx_generateTimestamp();
						v_myResource.timeSeriesInstanceAnnc.lastModifiedTime := v_myResource.timeSeriesInstanceAnnc.creationTime;											
						v_myResource.timeSeriesInstanceAnnc.contentSize := lengthof(v_myResource.timeSeriesInstanceAnnc.content);
						if(not(ispresent(p_resource.timeSeriesInstanceAnnc.sequenceNr))) {
							v_myResource.timeSeriesInstanceAnnc.sequenceNr := 1;
						}
					}				
				} else if (p_resourceType == int1 and ispresent (p_resource)) { //Acp Resource
				   if(ischosen (p_resource.accessControlPolicy)){
						v_myResource.accessControlPolicy := valueof(p_resource.accessControlPolicy);
						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;
						v_myResource.accessControlPolicy.privileges := valueof(p_resource.accessControlPolicy.privileges);
						v_myResource.accessControlPolicy.selfPrivileges := valueof(p_resource.accessControlPolicy.selfPrivileges);
				   }
				} else if(p_resourceType == int2 and ispresent(p_resource)) {//AE
					if(ischosen(p_resource.aE)){
						v_myResource.aE := valueof(p_resource.aE);
					
						v_myResource.aE.resourceType := p_resourceType;
						v_myResource.aE.parentID := f_getResourceId(vc_localResourcesList[p_parentIndex].resource);
						v_myResource.aE.creationTime := fx_generateTimestamp();
						v_myResource.aE.lastModifiedTime := v_myResource.aE.creationTime;											
						if(not(ispresent(p_resource.aE.expirationTime))) {
							v_myResource.aE.expirationTime := "20301231T012345";
						}
						if(not(ispresent(v_myResource.aE.aE_ID))) {
							v_myResource.aE.aE_ID := "Cae" & int2str(v_resourceIndex);
						} 
						v_myResource.aE.resourceID := v_myResource.aE.aE_ID;
						if(not(ispresent(p_resource.aE.resourceName))) {
							v_myResource.aE.resourceName := "ae" & int2str(v_resourceIndex);
						}
						v_myResource.aE.app_ID := valueof(p_resource.aE.app_ID);
						v_myResource.aE.requestReachability := valueof(p_resource.aE.requestReachability);
					}
				} else if(p_resourceType == int3 and ispresent(p_resource)) { //Container
					if(ischosen(p_resource.container)){
						if(isvalue(p_resource.container)) {
						v_myResource.container := valueof(p_resource.container);
						}
						v_myResource.container.resourceType := p_resourceType;
      					
						v_myResource.container.parentID := f_getResourceId(vc_localResourcesList[p_parentIndex].resource);
						v_myResource.container.creationTime := fx_generateTimestamp();
						v_myResource.container.lastModifiedTime := v_myResource.container.creationTime;											
						if(not(ispresent(p_resource.container.expirationTime))) {
							v_myResource.container.expirationTime := "20301231T012345";
						}
						v_myResource.container.resourceID := "cnt" & int2str(v_resourceIndex);
						if(not(ispresent(p_resource.container.resourceName))) {
							v_myResource.container.resourceName := "container" & int2str(v_resourceIndex);
						}
						v_myResource.container.stateTag := 0;
						v_myResource.container.currentNrOfInstances := 0;
						v_myResource.container.currentByteSize := 0;
						if(not(ispresent(p_resource.container.maxByteSize))) {
							v_myResource.container.maxByteSize := 10000;
						}
						if(not(ispresent(p_resource.container.maxNrOfInstances))) {
							v_myResource.container.maxNrOfInstances := 10;
						}
					}
										
				} else if(p_resourceType == int4 and ispresent(p_resource)) { //ContentInstance
					if(ischosen(p_resource.contentInstance)){
						v_myResource.contentInstance := valueof(p_resource.contentInstance);
						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();
						v_myResource.contentInstance.lastModifiedTime := v_myResource.contentInstance.creationTime;											
						if(not(ispresent(p_resource.contentInstance.expirationTime))) {
							v_myResource.contentInstance.expirationTime := "20301231T012345";
						}
						v_myResource.contentInstance.stateTag := 0;
						if(not(ispresent(p_resource.contentInstance.content))) {
							v_myResource.contentInstance.contentSize := 0;
							v_myResource.contentInstance.content := omit;
						} else {
							v_myResource.contentInstance.contentSize := lengthof(v_myResource.contentInstance.content);
							v_myResource.contentInstance.content := valueof(p_resource.contentInstance.content);
						}
					}
				} else if(p_resourceType == int18 and ispresent(p_resource)) { //Schedule
					if(ischosen(p_resource.schedule)){
						v_myResource.schedule := valueof(p_resource.schedule);
						v_myResource.schedule.resourceID := "sch" & int2str(v_resourceIndex);
						if(not(ispresent(p_resource.schedule.resourceName))) {
							v_myResource.schedule.resourceName := "schedule" & int2str(v_resourceIndex);
						}
						v_myResource.schedule.resourceType := p_resourceType;
						v_myResource.schedule.parentID := f_getResourceId(vc_localResourcesList[p_parentIndex].resource);
						v_myResource.schedule.creationTime := fx_generateTimestamp();
						v_myResource.schedule.lastModifiedTime := v_myResource.schedule.creationTime;											
						if(not(ispresent(p_resource.schedule.expirationTime))) {
							v_myResource.schedule.expirationTime := "20301231T012345";
						}
					}														
				} else if(p_resourceType == int23 and ispresent(p_resource)) {//Subscription
					if(ischosen(p_resource.subscription)){
						v_myResource.subscription := valueof(p_resource.subscription);
						v_myResource.subscription.resourceID := "sub" & int2str(v_resourceIndex);
						if(not(ispresent(p_resource.subscription.resourceName))) {
							v_myResource.subscription.resourceName := "subscription" & int2str(v_resourceIndex);
						}
						v_myResource.subscription.resourceType := p_resourceType;
						v_myResource.subscription.parentID := f_getResourceId(vc_localResourcesList[p_parentIndex].resource);
						v_myResource.subscription.creationTime := fx_generateTimestamp();
						v_myResource.subscription.lastModifiedTime := v_myResource.subscription.creationTime;											
						if(not(ispresent(p_resource.subscription.expirationTime))) {
							v_myResource.subscription.expirationTime := "20301231T012345";
						}
					}
										
				} else if(p_resourceType == int9 and ispresent(p_resource)) { //Group
					if(ischosen(p_resource.group_)){
						v_myResource.group_ := valueof(p_resource.group_);
						v_myResource.group_.resourceID := "grp" & int2str(v_resourceIndex);
						if(not(ispresent(p_resource.group_.resourceName))) {
							v_myResource.group_.resourceName := "group" & int2str(v_resourceIndex);
						}
						v_myResource.group_.resourceType := p_resourceType;
						v_myResource.group_.parentID := f_getResourceId(vc_localResourcesList[p_parentIndex].resource);
						v_myResource.group_.creationTime := fx_generateTimestamp();
						v_myResource.group_.lastModifiedTime := v_myResource.group_.creationTime;											
						if(not(ispresent(p_resource.group_.expirationTime))) {
							v_myResource.group_.expirationTime := "20301231T012345";
						}
						if(not(ispresent(p_resource.group_.memberType))) {
							v_myResource.group_.memberType := int0;
						}
						if(not(ispresent(p_resource.group_.consistencyStrategy))) {
							v_myResource.group_.consistencyStrategy := int1;
						}
						if(v_myResource.group_.memberType != int0) {
							v_myResource.group_.memberTypeValidated := true;//Set initially to TRUE
						}
						if(v_myResource.group_.memberIDs == {"NotInitialized"}) {
							v_myResource.group_.memberIDs := {};
					}
						v_myResource.group_.currentNrOfMembers := lengthof(v_myResource.group_.memberIDs);
						if(lengthof(v_myResource.group_.memberIDs) == 0) {
							v_myResource.group_.memberTypeValidated := false;
						}
						if(not(ispresent(p_resource.group_.semanticSupportIndicator))) {
							v_myResource.group_.semanticSupportIndicator := false;//Set initially to TRUE
						}
					}
				} else if(p_resourceType == int15 and ispresent(p_resource)) { //PollingChannel
					if(ischosen(p_resource.pollingChannel)){
						v_myResource.pollingChannel := valueof(p_resource.pollingChannel);
						v_myResource.pollingChannel.resourceID := "pch" & int2str(v_resourceIndex);
						if(not(ispresent(p_resource.pollingChannel.resourceName))) {
							v_myResource.pollingChannel.resourceName := "pollingChannel" & int2str(v_resourceIndex);
						}
						v_myResource.pollingChannel.resourceType := p_resourceType;
						v_myResource.pollingChannel.parentID := f_getResourceId(vc_localResourcesList[p_parentIndex].resource);
						v_myResource.pollingChannel.creationTime := fx_generateTimestamp();
						v_myResource.pollingChannel.lastModifiedTime := v_myResource.pollingChannel.creationTime;											
						if(not(ispresent(p_resource.pollingChannel.expirationTime))) {
							v_myResource.pollingChannel.expirationTime := "20301231T012345";
						}
					}				
				} else if(p_resourceType == int29 and ispresent(p_resource)) { //TimeSeries
					if(ischosen(p_resource.timeSeries)){
						v_myResource.timeSeries := valueof(p_resource.timeSeries);
						v_myResource.timeSeries.resourceID := "ts" & int2str(v_resourceIndex);
						if(not(ispresent(p_resource.timeSeries.resourceName))) {
							v_myResource.timeSeries.resourceName := "timeSeries" & int2str(v_resourceIndex);
				}
						v_myResource.timeSeries.resourceType := p_resourceType;
						v_myResource.timeSeries.parentID := f_getResourceId(vc_localResourcesList[p_parentIndex].resource);
						v_myResource.timeSeries.creationTime := fx_generateTimestamp();
						v_myResource.timeSeries.lastModifiedTime := v_myResource.timeSeries.creationTime;											
						if(not(ispresent(p_resource.timeSeries.expirationTime))) {
							v_myResource.timeSeries.expirationTime := "20301231T012345";
						};
						v_myResource.timeSeries.currentNrOfInstances := 0;
						v_myResource.timeSeries.currentByteSize := 0;
						v_myResource.timeSeries.missingDataDetect := false;
					}				
				} else if(p_resourceType == int30 and ispresent(p_resource)) { //TimeSeriesInstance
					if(ischosen(p_resource.timeSeriesInstance)){
						v_myResource.timeSeriesInstance := valueof(p_resource.timeSeriesInstance);
						v_myResource.timeSeriesInstance.resourceID := "ts" & int2str(v_resourceIndex);
						if(not(ispresent(p_resource.timeSeriesInstance.resourceName))) {
							v_myResource.timeSeriesInstance.resourceName := "timeSeriesInstance" & int2str(v_resourceIndex);
						}
						v_myResource.timeSeriesInstance.resourceType := p_resourceType;
						v_myResource.timeSeriesInstance.parentID := f_getResourceId(vc_localResourcesList[p_parentIndex].resource);
						v_myResource.timeSeriesInstance.creationTime := fx_generateTimestamp();
						v_myResource.timeSeriesInstance.lastModifiedTime := v_myResource.timeSeriesInstance.creationTime;											
						if(not(ispresent(p_resource.timeSeriesInstance.expirationTime))) {
							v_myResource.timeSeriesInstance.expirationTime := "20301231T012345";
						}
						v_myResource.timeSeriesInstance.contentSize := lengthof(v_myResource.timeSeriesInstance.content);
						if(not(ispresent(p_resource.timeSeriesInstance.sequenceNr))) {
							v_myResource.timeSeriesInstance.sequenceNr := 1;
						}
					}				
				}
				return v_myResource;
				
			}//End of function		
			
			/**
			 * @desc   Update of a local resource (Test System simulating a CSE)
			 * @param  p_localResourceIndex	Resource index of resource to be updated
			 * @param  p_resource          	Resource update
			 */
			function f_updateLocalResource(in integer p_localResourceIndex, in PrimitiveContent p_resource, template (omit) AttributeList_1 p_nullFields := omit) runs on CseSimu {
				var XSD.AnyURI v_remoteCSEAnncAddress;
				var PrimitiveContent v_primitiveContent;
				
				// TODO To review the code (use of indexes, generation of value for certain attributes, etc..)
				if(ischosen(vc_localResourcesList[p_localResourceIndex].resource.remoteCSE) and ischosen(p_resource.remoteCSE)) {//RemoteCSE
					
					if(ispresent(p_resource.remoteCSE.accessControlPolicyIDs)) {
						vc_localResourcesList[p_localResourceIndex].resource.remoteCSE.accessControlPolicyIDs := p_resource.remoteCSE.accessControlPolicyIDs;
					}
					if(ispresent(p_resource.remoteCSE.expirationTime)) {
						vc_localResourcesList[p_localResourceIndex].resource.remoteCSE.expirationTime := p_resource.remoteCSE.expirationTime;
					}
					if(ispresent(p_resource.remoteCSE.labels)) {
						vc_localResourcesList[p_localResourceIndex].resource.remoteCSE.labels := p_resource.remoteCSE.labels;
					}
					if(ispresent(p_resource.remoteCSE.announceTo)) {
						v_primitiveContent := {remoteCSEAnnc := valueof(m_contentCreateRemoteCSEAnnc)};
						v_primitiveContent := f_setLink(v_primitiveContent, f_getLocalResourceAddress(p_localResourceIndex));
						vc_cse2.start(f_generateAndSetLocalResource(m_primitiveContentRemoteCSEAnnc(v_primitiveContent.remoteCSEAnnc), -, int10016));
						f_cseSimu_checkComponentDoneAndGetVerdict(vc_cse2);
						v_remoteCSEAnncAddress := f_getLatestLocalResourceAddress(vc_cse2);
						vc_localResourcesList[p_localResourceIndex].resource.remoteCSE.announceTo := {v_remoteCSEAnncAddress};
					}
					if(ispresent(p_resource.remoteCSE.announcedAttribute)) {
						vc_localResourcesList[p_localResourceIndex].resource.remoteCSE.announcedAttribute := p_resource.remoteCSE.announcedAttribute;
					}
					if(ispresent(p_resource.remoteCSE.dynamicAuthorizationConsultationIDs)) {
						vc_localResourcesList[p_localResourceIndex].resource.remoteCSE.dynamicAuthorizationConsultationIDs := p_resource.remoteCSE.dynamicAuthorizationConsultationIDs;
					}
					if(ispresent(p_resource.remoteCSE.pointOfAccess)) {
						vc_localResourcesList[p_localResourceIndex].resource.remoteCSE.pointOfAccess := p_resource.remoteCSE.pointOfAccess;
					}
					if(ispresent(p_resource.remoteCSE.m2M_Ext_ID)) {
						vc_localResourcesList[p_localResourceIndex].resource.remoteCSE.m2M_Ext_ID := p_resource.remoteCSE.m2M_Ext_ID;
					}
					if(ispresent(p_resource.remoteCSE.trigger_Recipient_ID)) {
						vc_localResourcesList[p_localResourceIndex].resource.remoteCSE.trigger_Recipient_ID := p_resource.remoteCSE.trigger_Recipient_ID;
					}
					if(ispresent(p_resource.remoteCSE.requestReachability)) {
						vc_localResourcesList[p_localResourceIndex].resource.remoteCSE.requestReachability := p_resource.remoteCSE.requestReachability;
					}
					if(ispresent(p_resource.remoteCSE.nodeLink)) {
						vc_localResourcesList[p_localResourceIndex].resource.remoteCSE.nodeLink := p_resource.remoteCSE.nodeLink;
					}
					if(ispresent(p_resource.remoteCSE.triggerReferenceNumber)) {
						vc_localResourcesList[p_localResourceIndex].resource.remoteCSE.triggerReferenceNumber := p_resource.remoteCSE.triggerReferenceNumber;
					}
					if(ispresent(p_resource.remoteCSE.e2eSecInfo)) {
						vc_localResourcesList[p_localResourceIndex].resource.remoteCSE.e2eSecInfo := p_resource.remoteCSE.e2eSecInfo;
					}
					if(ispresent(p_resource.remoteCSE.supportedReleaseVersions)) {
						vc_localResourcesList[p_localResourceIndex].resource.remoteCSE.supportedReleaseVersions := p_resource.remoteCSE.supportedReleaseVersions;
					}
				} else if(ischosen(vc_localResourcesList[p_localResourceIndex].resource.container) and (ischosen(p_resource.container))) {//Container
					if(ispresent(p_resource.container.expirationTime)) {
						vc_localResourcesList[p_localResourceIndex].resource.container.expirationTime := p_resource.container.expirationTime;
					}
					if(ispresent(p_resource.container.labels)) {
						vc_localResourcesList[p_localResourceIndex].resource.container.labels := p_resource.container.labels;
					}
					if(ispresent(p_resource.container.announceTo)) {
						vc_localResourcesList[p_localResourceIndex].resource.container.announceTo := p_resource.container.announceTo;
					}
					if(ispresent(p_resource.container.announcedAttribute)) {
						vc_localResourcesList[p_localResourceIndex].resource.container.announcedAttribute := p_resource.container.announcedAttribute;
					}
					if(ispresent(p_resource.container.accessControlPolicyIDs)) {
						vc_localResourcesList[p_localResourceIndex].resource.container.accessControlPolicyIDs := p_resource.container.accessControlPolicyIDs;
					}
					if(ispresent(p_resource.container.dynamicAuthorizationConsultationIDs)) {
						vc_localResourcesList[p_localResourceIndex].resource.container.dynamicAuthorizationConsultationIDs := p_resource.container.dynamicAuthorizationConsultationIDs;
					}
				}  else if(ischosen(vc_localResourcesList[p_localResourceIndex].resource.contentInstance) and (ischosen(p_resource.contentInstance))) {//ContentInstance
					if(ispresent(p_resource.contentInstance.expirationTime)) {
						vc_localResourcesList[p_localResourceIndex].resource.contentInstance.expirationTime := p_resource.contentInstance.expirationTime;
					}
					if(ispresent(p_resource.contentInstance.labels)) {
						vc_localResourcesList[p_localResourceIndex].resource.contentInstance.labels := p_resource.contentInstance.labels;
					}
					if(ispresent(p_resource.contentInstance.announceTo)) {
						vc_localResourcesList[p_localResourceIndex].resource.contentInstance.announceTo := p_resource.contentInstance.announceTo;
					}
					if(ispresent(p_resource.contentInstance.announcedAttribute)) {
						vc_localResourcesList[p_localResourceIndex].resource.contentInstance.announcedAttribute := p_resource.contentInstance.announcedAttribute;
					}
				} else if(ischosen(vc_localResourcesList[p_localResourceIndex].resource.subscription) and (ischosen(p_resource.subscription))) {//Subscription
					if(ispresent(p_resource.subscription.expirationTime)) {
						vc_localResourcesList[p_localResourceIndex].resource.subscription.expirationTime := p_resource.subscription.expirationTime;
					}
					if(ispresent(p_resource.subscription.labels)) {
						vc_localResourcesList[p_localResourceIndex].resource.subscription.labels := p_resource.subscription.labels;
					}
					if(ispresent(p_resource.subscription.accessControlPolicyIDs)) {
						vc_localResourcesList[p_localResourceIndex].resource.subscription.accessControlPolicyIDs := p_resource.subscription.accessControlPolicyIDs;
					}
					if(ispresent(p_resource.subscription.dynamicAuthorizationConsultationIDs)) {
						vc_localResourcesList[p_localResourceIndex].resource.subscription.dynamicAuthorizationConsultationIDs := p_resource.subscription.dynamicAuthorizationConsultationIDs;
					}
				} else if(ischosen(vc_localResourcesList[p_localResourceIndex].resource.pollingChannel) and (ischosen(p_resource.pollingChannel))) {//pollingChannel
					if(ispresent(p_resource.pollingChannel.expirationTime)) {
						vc_localResourcesList[p_localResourceIndex].resource.pollingChannel.expirationTime := p_resource.pollingChannel.expirationTime;
					}
					if(ispresent(p_resource.pollingChannel.labels)) {
						vc_localResourcesList[p_localResourceIndex].resource.pollingChannel.labels := p_resource.pollingChannel.labels;
					}
				} else if(ischosen(vc_localResourcesList[p_localResourceIndex].resource.aE) and (ischosen(p_resource.aE))) {//AE
					if(ispresent(p_resource.aE.accessControlPolicyIDs)) {
						vc_localResourcesList[p_localResourceIndex].resource.aE.accessControlPolicyIDs := p_resource.aE.accessControlPolicyIDs;
					}
					if(ispresent(p_resource.aE.expirationTime)) {
						vc_localResourcesList[p_localResourceIndex].resource.aE.expirationTime := p_resource.aE.expirationTime;
					}
					if(ispresent(p_resource.aE.labels)) {
						vc_localResourcesList[p_localResourceIndex].resource.aE.labels := p_resource.aE.labels;
					}
					if(ispresent(p_resource.aE.announceTo)) {
						vc_localResourcesList[p_localResourceIndex].resource.aE.announceTo := p_resource.aE.announceTo;
					}
					if(ispresent(p_resource.aE.announcedAttribute)) {
						vc_localResourcesList[p_localResourceIndex].resource.aE.announcedAttribute := p_resource.aE.announcedAttribute;
					}
					if(ispresent(p_resource.aE.dynamicAuthorizationConsultationIDs)) {
						vc_localResourcesList[p_localResourceIndex].resource.aE.dynamicAuthorizationConsultationIDs := p_resource.aE.dynamicAuthorizationConsultationIDs;
					}
					if(ispresent(p_resource.aE.appName)) {
						vc_localResourcesList[p_localResourceIndex].resource.aE.appName := p_resource.aE.appName;
					}
					if(ispresent(p_resource.aE.pointOfAccess)) {
						vc_localResourcesList[p_localResourceIndex].resource.aE.pointOfAccess := p_resource.aE.pointOfAccess;
					}
					if(ispresent(p_resource.aE.ontologyRef)) {
						vc_localResourcesList[p_localResourceIndex].resource.aE.ontologyRef := p_resource.aE.ontologyRef;
					}
					if(ispresent(p_resource.aE.nodeLink)) {
						vc_localResourcesList[p_localResourceIndex].resource.aE.nodeLink := p_resource.aE.nodeLink;
					}
					if(ispresent(p_resource.aE.requestReachability)) {
						vc_localResourcesList[p_localResourceIndex].resource.aE.requestReachability := p_resource.aE.requestReachability;
					}
					if(ispresent(p_resource.aE.contentSerialization)) {
						vc_localResourcesList[p_localResourceIndex].resource.aE.contentSerialization := p_resource.aE.contentSerialization;
					}
					if(ispresent(p_resource.aE.e2eSecInfo)) {
						vc_localResourcesList[p_localResourceIndex].resource.aE.e2eSecInfo := p_resource.aE.e2eSecInfo;
					}
					if(ispresent(p_resource.aE.supportedReleaseVersions)) {
						vc_localResourcesList[p_localResourceIndex].resource.aE.supportedReleaseVersions := p_resource.aE.supportedReleaseVersions;
					}
				} else if(ischosen(vc_localResourcesList[p_localResourceIndex].resource.aEAnnc) and (ischosen(p_resource.aEAnnc))) {//AEAnnc
					if(ispresent(p_resource.aEAnnc.accessControlPolicyIDs)) {
						vc_localResourcesList[p_localResourceIndex].resource.aEAnnc.accessControlPolicyIDs := p_resource.aEAnnc.accessControlPolicyIDs;
					}
					if(ispresent(p_resource.aEAnnc.expirationTime)) {
						vc_localResourcesList[p_localResourceIndex].resource.aEAnnc.expirationTime := p_resource.aEAnnc.expirationTime;
					}
					if(ispresent(p_resource.aEAnnc.labels)) {
						vc_localResourcesList[p_localResourceIndex].resource.aEAnnc.labels := p_resource.aEAnnc.labels;
					}
					if(ispresent(p_resource.aEAnnc.link)) {
						vc_localResourcesList[p_localResourceIndex].resource.aEAnnc.link := p_resource.aEAnnc.link;
					}
					if(ispresent(p_resource.aEAnnc.dynamicAuthorizationConsultationIDs)) {
						vc_localResourcesList[p_localResourceIndex].resource.aEAnnc.dynamicAuthorizationConsultationIDs := p_resource.aEAnnc.dynamicAuthorizationConsultationIDs;
					}
					if(ispresent(p_resource.aEAnnc.appName)) {
						vc_localResourcesList[p_localResourceIndex].resource.aEAnnc.appName := p_resource.aEAnnc.appName;
					}
					if(ispresent(p_resource.aEAnnc.pointOfAccess)) {
						vc_localResourcesList[p_localResourceIndex].resource.aEAnnc.pointOfAccess := p_resource.aEAnnc.pointOfAccess;
					}
					if(ispresent(p_resource.aEAnnc.ontologyRef)) {
						vc_localResourcesList[p_localResourceIndex].resource.aEAnnc.ontologyRef := p_resource.aEAnnc.ontologyRef;
					}
					if(ispresent(p_resource.aEAnnc.nodeLink)) {
						vc_localResourcesList[p_localResourceIndex].resource.aEAnnc.nodeLink := p_resource.aEAnnc.nodeLink;
					}
					if(ispresent(p_resource.aEAnnc.requestReachability)) {
						vc_localResourcesList[p_localResourceIndex].resource.aEAnnc.requestReachability := p_resource.aEAnnc.requestReachability;
					}
					if(ispresent(p_resource.aEAnnc.contentSerialization)) {
						vc_localResourcesList[p_localResourceIndex].resource.aEAnnc.contentSerialization := p_resource.aEAnnc.contentSerialization;
					}
					if(ispresent(p_resource.aEAnnc.e2eSecInfo)) {
						vc_localResourcesList[p_localResourceIndex].resource.aEAnnc.e2eSecInfo := p_resource.aEAnnc.e2eSecInfo;
					}
					if(ispresent(p_resource.aEAnnc.supportedReleaseVersions)) {
						vc_localResourcesList[p_localResourceIndex].resource.aEAnnc.supportedReleaseVersions := p_resource.aEAnnc.supportedReleaseVersions;
					}
				} else if(ischosen(vc_localResourcesList[p_localResourceIndex].resource.accessControlPolicy) and (ischosen(p_resource.accessControlPolicy))) { //AccessControlPolicy
					if(ispresent(p_resource.accessControlPolicy.expirationTime)) {
						vc_localResourcesList[p_localResourceIndex].resource.accessControlPolicy.expirationTime := p_resource.accessControlPolicy.expirationTime;
					}
					if(ispresent(p_resource.accessControlPolicy.labels)) {
						vc_localResourcesList[p_localResourceIndex].resource.accessControlPolicy.labels := p_resource.accessControlPolicy.labels;
					}
					if(ispresent(p_resource.accessControlPolicy.announceTo)) {
						vc_localResourcesList[p_localResourceIndex].resource.accessControlPolicy.announceTo := p_resource.accessControlPolicy.announceTo;
					}
					if(ispresent(p_resource.accessControlPolicy.announcedAttribute)) {
						vc_localResourcesList[p_localResourceIndex].resource.accessControlPolicy.announcedAttribute := p_resource.accessControlPolicy.announcedAttribute;
					}
				} else if(ischosen(vc_localResourcesList[p_localResourceIndex].resource.containerAnnc) and (ischosen(p_resource.containerAnnc))) {//ContainerAnnc
					if(ispresent(p_resource.containerAnnc.expirationTime)) {
						vc_localResourcesList[p_localResourceIndex].resource.containerAnnc.expirationTime := p_resource.containerAnnc.expirationTime;
					}
					if(ispresent(p_resource.containerAnnc.labels)) {
						vc_localResourcesList[p_localResourceIndex].resource.containerAnnc.labels := p_resource.containerAnnc.labels;
					}
					if(ispresent(p_resource.containerAnnc.dynamicAuthorizationConsultationIDs)) {
						vc_localResourcesList[p_localResourceIndex].resource.containerAnnc.dynamicAuthorizationConsultationIDs := p_resource.containerAnnc.dynamicAuthorizationConsultationIDs;
					}
					if(ispresent(p_resource.containerAnnc.maxNrOfInstances)) {
						vc_localResourcesList[p_localResourceIndex].resource.containerAnnc.maxNrOfInstances := p_resource.containerAnnc.maxNrOfInstances;
					}
					if(ispresent(p_resource.containerAnnc.maxByteSize)) {
						vc_localResourcesList[p_localResourceIndex].resource.containerAnnc.maxByteSize := p_resource.containerAnnc.maxByteSize;
					}
					if(ispresent(p_resource.containerAnnc.maxInstanceAge)) {
						vc_localResourcesList[p_localResourceIndex].resource.containerAnnc.maxInstanceAge := p_resource.containerAnnc.maxInstanceAge;
					}
					if(isvalue(p_nullFields)) {
						if (valueof(p_nullFields[0]) == "maxByteSize") {
							vc_localResourcesList[p_localResourceIndex].resource.containerAnnc.maxByteSize := omit;
						}
					}
				} else if(ischosen(vc_localResourcesList[p_localResourceIndex].resource.timeSeriesAnnc) and (ischosen(p_resource.timeSeriesAnnc))) {//timeSeriesAnnc
					if(ispresent(p_resource.containerAnnc.expirationTime)) {
						vc_localResourcesList[p_localResourceIndex].resource.timeSeriesAnnc.expirationTime := p_resource.timeSeriesAnnc.expirationTime;
					}
					if(ispresent(p_resource.containerAnnc.labels)) {
						vc_localResourcesList[p_localResourceIndex].resource.timeSeriesAnnc.labels := p_resource.timeSeriesAnnc.labels;
					}
					if(ispresent(p_resource.containerAnnc.dynamicAuthorizationConsultationIDs)) {
						vc_localResourcesList[p_localResourceIndex].resource.timeSeriesAnnc.dynamicAuthorizationConsultationIDs := p_resource.timeSeriesAnnc.dynamicAuthorizationConsultationIDs;
					}
					if(ispresent(p_resource.containerAnnc.maxNrOfInstances)) {
						vc_localResourcesList[p_localResourceIndex].resource.timeSeriesAnnc.maxNrOfInstances := p_resource.timeSeriesAnnc.maxNrOfInstances;
					}
					if(ispresent(p_resource.containerAnnc.maxByteSize)) {
						vc_localResourcesList[p_localResourceIndex].resource.timeSeriesAnnc.maxByteSize := p_resource.timeSeriesAnnc.maxByteSize;
					}
					if(ispresent(p_resource.containerAnnc.maxInstanceAge)) {
						vc_localResourcesList[p_localResourceIndex].resource.timeSeriesAnnc.maxInstanceAge := p_resource.timeSeriesAnnc.maxInstanceAge;
					}
					if(isvalue(p_nullFields)) {
						if (valueof(p_nullFields[0]) == "maxByteSize") {
							vc_localResourcesList[p_localResourceIndex].resource.timeSeriesAnnc.maxByteSize := omit;
						}
					}

				} else if(ischosen(vc_localResourcesList[p_localResourceIndex].resource.groupAnnc) and (ischosen(p_resource.groupAnnc))) {//groupAnnc
					if(ispresent(p_resource.containerAnnc.expirationTime)) {
						vc_localResourcesList[p_localResourceIndex].resource.groupAnnc.expirationTime := p_resource.groupAnnc.expirationTime;
					}
					if(ispresent(p_resource.containerAnnc.labels)) {
						vc_localResourcesList[p_localResourceIndex].resource.groupAnnc.labels := p_resource.groupAnnc.labels;
					}
					if(ispresent(p_resource.containerAnnc.dynamicAuthorizationConsultationIDs)) {
						vc_localResourcesList[p_localResourceIndex].resource.groupAnnc.dynamicAuthorizationConsultationIDs := p_resource.groupAnnc.dynamicAuthorizationConsultationIDs;
					}
					if(isvalue(p_nullFields)) {
						if (valueof(p_nullFields[0]) == "maxNrOfMembers") {
							vc_localResourcesList[p_localResourceIndex].resource.groupAnnc.maxNrOfMembers := omit;
						}
					}

				}
			  } //End of function	
			
			/**
			 * @desc Creation of a resource using CseSimu. In case of announced resource, the original resource is created locally first.
			 * @param p_resourceType Resource type of the resource to be created
			 * @param p_requestPrimitive CREATE request primitive for the resource to be created
			 * @param p_parentIndex Internal resource index which indicates the parent of the resource to be created
			 * @return Internal resource index of the created resource
			 * @verdict 
			 */
			function f_cse_createResource_cseSimu(in ResourceType p_resourceType, template RequestPrimitive p_requestPrimitive := m_create, integer p_parentIndex := -1) runs on CseSimu return integer {

				var RequestPrimitive v_request;
				var integer v_resourceIndex := -1;
				var integer v_originalResourceIndex := -1;

				//Activate defaults when running on a PTC
				f_cse_activateDefaults_cse1();		
					
				//Create original resource locally if resource type is an announced variant
				if (p_resourceType == int10001) {
					v_originalResourceIndex := f_generateAndSetLocalResource(m_primitiveContentAccessControlPolicy(m_contentCreateAcp), -, int1);
				} else if(p_resourceType == int10002) {
					v_originalResourceIndex := f_generateAndSetLocalResource(m_primitiveContentAe(m_contentCreateAe(omit, -, PX_TS_AE1.appId, omit)), -, int2);
				} else if (p_resourceType == int10003) {
					v_originalResourceIndex := f_generateAndSetLocalResource(m_primitiveContentContainer(m_contentCreateContainer), -, int3);
				} else if (p_resourceType == int10004) {
					v_originalResourceIndex := f_generateAndSetLocalResource(m_primitiveContentContentInstance(m_contentCreateContentInstance), -, int4);
				} else if (p_resourceType == int10009) {
					v_originalResourceIndex := f_generateAndSetLocalResource(m_primitiveContentGroup(m_contentCreateGroup(1, {"NotInitialized"}, omit, -, -, -, -, -)), -, int9);
				} else if (p_resourceType == int10029) {
					v_originalResourceIndex := f_generateAndSetLocalResource(m_primitiveContentTimeSeries(m_contentCreateTimeSeries), -, int29);
				} else if (p_resourceType == int10030) {
					v_originalResourceIndex := f_generateAndSetLocalResource(m_primitiveContentTimeSeriesInstance(m_contentCreateTimeSeriesInstance), -, int30);
				}
				if(v_originalResourceIndex != -1) {
					p_requestPrimitive.primitiveContent := f_setLink(valueof(p_requestPrimitive.primitiveContent), f_getLocalResourceAddress(v_originalResourceIndex, -, e_spRelative));
					p_requestPrimitive.primitiveContent := f_setExpirationTime(valueof(p_requestPrimitive.primitiveContent), vc_localResourcesList[v_originalResourceIndex].resource);
				} 
				//TODO Add other resource types		
				
					
				v_request := f_getCreateRequestPrimitive(p_resourceType, p_requestPrimitive, p_parentIndex);

				f_send(e_mccPort, m_request(v_request));
				tc_ac.start;
				alt {
					[] mccPort.receive(mw_response(mw_responsePrimitiveOK)) -> value vc_response {
						tc_ac.stop;
						setverdict(pass, __SCOPE__&":INFO: Resource type " & int2str(enum2int(p_resourceType)) & " created successfuly");
						f_checkAttributesToBeSaved(p_resourceType, v_request, vc_response.primitive.responsePrimitive);
						v_resourceIndex := f_setResource(vc_response.primitive.responsePrimitive.primitiveContent, p_resourceType, p_parentIndex);
						if(p_resourceType == int16) {	//remoteCSE
							vc_remoteCseIndex := v_resourceIndex;
							vc_componentRegistered := true;
						}
					}
					[] mccPort.receive(mw_response(mw_responsePrimitiveKO)) {
						tc_ac.stop;
						setverdict(inconc, __SCOPE__&":INFO: Error while creating resource type " & int2str(enum2int(p_resourceType)));
					}
					[] mccPort.receive {
						tc_ac.stop;
						setverdict(inconc, __SCOPE__&":INFO: Unexpected message received");
					}
					[] tc_ac.timeout {
						setverdict(inconc, __SCOPE__&":INFO: No answer while creating resource type " & int2str(enum2int(p_resourceType)));
					}
				}	
	
				f_checkCseSimuStatus();
	
				return v_resourceIndex;

			}

			/**
			 * @desc   Send response to the IUT (Test System simulating a CSE)
			 * @param  p_requestPrimtive	Received request primitive
			 */
			function f_cse_sendResponse_cseSimu(in MsgIn p_requestPrimitive) runs on CseSimu {
				
				
				f_processCreateRequestPrimitive(p_requestPrimitive.primitive.requestPrimitive);
				
				f_send(e_mccPortIn, m_response(vc_response.primitive.responsePrimitive));
			
			}
									
		}//end group CseSimuFunctions
		
		group CseAltstepFunctions {
			 
			/**
			  * @desc	Cse altstep for config 01
			  */
			 altstep a_cse_cf01() runs on AeSimu {
				[] a_cse_aeSimu();
			 }	
			 
			 /**
			  * @desc	Cse altstep for config 02
			  */
			 altstep a_cse_cf02_ae1() runs on AeSimu {
				[] a_cse_aeSimu();
			 }		
			 
			 /**
			 * @desc	Cse altstep for config 02
			 */
			 altstep a_cse_cf02_cse1() runs on CseSimu {
			   [] a_cse_cseSimu();
			 }	
						 
			 /**
			 * @desc	Cse altstep for config 03
			 */
			 altstep a_cse_cf03() runs on CseSimu {
			   [] a_ae_cseSimu();
			 }	
			
			/**
			  * @desc	Cse altstep for config 04
			  */
			 altstep a_cse_cf04() runs on CseSimu {
			 	[] a_cse_cseSimu();
			 }		
 
			/**
			 * @desc    Cse altstep for config 06
			 */
			altstep a_cse_cf06_ae1() runs on AeSimu {
			   [] a_cse_aeSimu();
			}		
 
 			/**
			 * @desc    Cse altstep for config 06
			 */
			altstep a_cse_cf06_das() runs on AeSimu {
			   [] a_cse_aeSimu();
			}
			
			 /**
			 * @desc	Cse altstep for config 07
			 */
			 altstep a_cse_cf07() runs on CseSimu {
			   [] a_ae_cseSimu();
			 }	
			
			/**
			  * @desc	Altstep for CseSimu
			  */
			 altstep a_cse_cseSimu() runs on CseSimu {
			
				var PrimitiveContent v_localResource;
				var integer v_localResourceIndex := -1;
				var integer v_parentResourceIndex := -1;
				var MsgIn v_request;
				var ResponsePrimitive v_response;
				var RequestPrimitive v_requestPrimitive;
				var XSD.ID v_cseIdPattern := PX_TS_CSE2.cseId;
				var template XSD.AnyURI v_retargetingToCse2 := pattern "{v_cseIdPattern}*";
				
				//Retargeting
				[vc_auxiliaryCse2Up] mccPortIn.receive(mw_request(mw_requestPrimitive(-, v_retargetingToCse2))) -> value v_request {
					log(__SCOPE__&": WARNING: Unexpected REQUEST message received targeting CSE2");
					mccPortInternal.send(v_request.primitive.requestPrimitive);
					alt {
						[]mccPortInternal.receive(mw_responsePrimitive(?)) -> value v_response {
						}
					}
							
					f_send(e_mccPortIn, m_response(v_response));
					repeat;
				}
				[] mccPortIn.receive(mw_request(mw_create())) -> value v_request {
					log(__SCOPE__&": WARNING: Unexpected CREATE message received");
					
					v_localResourceIndex := f_processCreateRequestPrimitive(v_request.primitive.requestPrimitive);
	
					f_send(e_mccPortIn, m_response(vc_response.primitive.responsePrimitive));
					repeat;
				}
				[] mccPortIn.receive(mw_request(mw_retrieve(?))) -> value v_request {
					log(__SCOPE__&": WARNING: Unexpected RETRIEVE message received");
					
					f_processRetrieveRequestPrimitive(v_request.primitive.requestPrimitive);
					if(ischosen(vc_response.primitive.responsePrimitive.primitiveContent.cSEBase)) {
						f_send(e_mccPortIn, m_response(vc_response.primitive.responsePrimitive)); 
					} else {
						f_send(e_mccPortIn, m_response(vc_response.primitive.responsePrimitive));
					}
					repeat;
				}
				[] mccPortIn.receive(mw_request(mw_update())) -> value v_request {
					log(__SCOPE__&": WARNING: Unexpected UPDATE message received");

					f_processUpdateRequestPrimitive(v_request.primitive.requestPrimitive);
					f_send(e_mccPortIn, m_response(vc_response.primitive.responsePrimitive));
					repeat;
				}
				[] mccPortIn.receive(mw_request(mw_delete())) -> value v_request {
					log(__SCOPE__&": WARNING: Unexpected DELETE message received");

					f_processDeleteRequestPrimitive(v_request.primitive.requestPrimitive);
					f_send(e_mccPortIn, m_response(vc_response.primitive.responsePrimitive));
					repeat;
				}
				[] mccPortIn.receive(mw_request(mw_notify)) -> value v_request {
					log(__SCOPE__&": WARNING: Unexpected NOTIFY message received");

					//Send response in any case
					v_response := valueof(m_responseNotification(int2000, omit));
					v_response.requestIdentifier := vc_request.primitive.requestPrimitive.requestIdentifier;
					f_send(e_mccPortIn, m_response(v_response));
					repeat;
				}
				[] mccPortIn.receive (mw_request(?)){
					log(__SCOPE__&": WARNING: Unexpected message received");
					repeat;
				}
				[] mccPort.receive {
					log(__SCOPE__&": WARNING: Unexpected message received");
					repeat;
				}
				[] mccPortInternal.receive(mw_retrieve(?)) -> value v_requestPrimitive {
					log(__SCOPE__&": WARNING: Unexpected RETRIEVE message received");
					
					f_processRetrieveRequestPrimitive(v_requestPrimitive);
					mccPortInternal.send(vc_response.primitive.responsePrimitive);
					repeat;
				}
				[] mccPortInternal.receive(mw_delete()) -> value v_requestPrimitive {
					log(__SCOPE__&": WARNING: Unexpected DELETE message received");

					f_processDeleteRequestPrimitive(v_requestPrimitive);
					mccPortInternal.send(vc_response.primitive.responsePrimitive);
					repeat;
				}
				[vc_auxiliaryCse2Up] infoPort.receive(SyncPoints:e_error) from vc_cse2 {
					log(__SCOPE__&": ERROR: Component CSE2 failed");
					f_cse_postamble_deleteResourcesCSE();
					// Tear down
					if(vc_config == e_cf02CseSimuMaster) {
						f_cf02DownCseSimuMaster();
						kill;
					} else if (vc_config == e_cf03) {
						f_cf03Down();
						kill;
					} else if (vc_config == e_cf04) {
						f_cf04Down();
						kill;
					} 
				}
				[vc_config == e_cf02CseSimuMaster] infoPort.receive(SyncPoints:e_error) from vc_ae1 {
					log(__SCOPE__&": ERROR: Component AE1 failed");
					f_cse_postamble_deleteResourcesCSE();
					// Tear down
					f_cf02DownCseSimuMaster();
					kill;
				}
			 }
			 
			/**
			  * @desc	Altstep for AeSimu
			  */
			 altstep a_cse_aeSimu() runs on AeSimu {
				var MsgIn v_request;
				var ResponsePrimitive v_response;
				
			 	[] mcaPortIn.receive(mw_request(mw_notify)) -> value v_request {
					log(__SCOPE__&": WARNING: Unexpected NOTIFY (single notification) message received");

					//Send response in any case
					v_response := valueof(m_responseNotification(int2000, omit));
					v_response.requestIdentifier := v_request.primitive.requestPrimitive.requestIdentifier;
					f_send(e_mcaPortIn, m_response(v_response));
					repeat;
				}
				[] mcaPortIn.receive(mw_request(mw_notifyAggregatedNotification)) -> value v_request {
					log(__SCOPE__&": WARNING: Unexpected NOTIFY (aggregated notification) message received");

					//Send response in any case
					v_response := valueof(m_responseNotification(int2000, omit));
					v_response.requestIdentifier := v_request.primitive.requestPrimitive.requestIdentifier;
					f_send(e_mcaPortIn, m_response(v_response));
					repeat;
				}
			 	[] mcaPortIn.receive {
					log(__SCOPE__&": WARNING: Unexpected message received");
					repeat;
				}
				[] mcaPort.receive {
					log(__SCOPE__&": WARNING: Unexpected message received");
					repeat;
				}
				[vc_config == e_cf02] infoPort.receive(SyncPoints:e_error) from vc_cse1 {
					log(__SCOPE__&": ERROR: Component CSE1 failed");
					f_cse_postamble_deleteResources();
					// Tear down
					f_cf02Down();
					kill;
				}
				[vc_auxiliaryAe2Up] infoPort.receive(SyncPoints:e_error) from vc_ae2 {
					log(__SCOPE__&": ERROR: Component AE2 failed");
					f_cse_postamble_deleteResources();
					// Tear down
					f_cf01Down();
					kill;
				}
			 }
			
			/**
			  * @desc	Activation of the corresponding default altstep depending on config for CseSimu
			  */
			function f_cse_activateDefaults_cse1() runs on CseSimu {
				deactivate;
					activate(a_default());
					if(vc_config == e_cf02) {
						activate(a_cse_cf02_cse1());
						log(__SCOPE__&": INFO: Default cf02_cse1 activated");
				} else if(vc_config == e_cf02CseSimuMaster) {
					activate(a_cse_cf02_cse1());
					log(__SCOPE__&": INFO: Default cf02_cse1 activated");
				} else if(vc_config == e_cf03) {
					activate(a_cse_cf03());
					log(__SCOPE__&": INFO: Default cf03 activated");
					} else if(vc_config == e_cf04) {
						activate(a_cse_cf04());
						log(__SCOPE__&": INFO: Default cf04 activated");
					}
				}	
	
			/**
			  * @desc	Activation of the corresponding default altstep depending on config for AeSimu
			  */
			function f_cse_activateDefaults_ae() runs on AeSimu {
				deactivate;
					activate(a_default());
					if(vc_config == e_cf01) {
						activate(a_cse_cf01());
					log(__SCOPE__&": INFO: Default cf01 activated");
				} else if(vc_config == e_cf02) {
					activate(a_cse_cf02_ae1());
					log(__SCOPE__&": INFO: Default cf02_ae1 activated");
					} else if(vc_config == e_cf02CseSimuMaster) {
						activate(a_cse_cf02_ae1());
						log(__SCOPE__&": INFO: Default cf02_ae1 activated");
					}
				}	
		}//end group CseAltstepFunctions
		
		group UtFunctions {

			/**
			 * @desc Sending of an Upper Tester primitive
			 * @param p_utRequest Action to be performed by IUT
			 * @param p_action Description of the given action to be performed by the IUT
			 * @verdict 
			 */
			function f_cse_sendUtPrimitive(template UtTriggerPrimitive p_utRequest, in universal charstring p_action, in boolean fromPostamble := true) runs on AeSimu {
				
				if (PX_UT_IMPLEMENTED){
					
					if(not(ispresent(p_utRequest.utCommand))) {
						p_utRequest.requestPrimitive.requestIdentifier := "m_uttriggerPrimitive" & f_rnd(1, 1000000);
					}
					deactivate;
					
					f_sendUtPrimitive(p_utRequest);
									
					if(not(fromPostamble)) {
						f_checkAeSimuStatus();
						
						activate(a_default());
						if(vc_config == e_cf01) {
							vc_aeSimu := activate(a_cse_cf01());
						} else if ((vc_config == e_cf02) or (vc_config == e_cf02CseSimuMaster)) {
							if(vc_testSystemRole == e_ae) {
								vc_aeSimu := activate(a_cse_cf02_ae1());
							}
						}
					}
				} else {
					action(p_action);
				}
			}
		
			/**
			 * @desc Sending of an Upper Tester primitive
			 * @param p_utRequest Action to be performed by IUT
			 * @param p_action Description of the given action to be performed by the IUT
			 * @verdict 
			 */
			function f_cse_sendUtPrimitive_cseSimu(template UtTriggerPrimitive p_utRequest, in universal charstring p_action, in boolean fromPostamble := true) runs on CseSimu {
				
				if (PX_UT_IMPLEMENTED){
					
					if(not(ispresent(p_utRequest.utCommand))) {
						p_utRequest.requestPrimitive.requestIdentifier := "m_uttriggerPrimitive" & f_rnd(1, 1000000);
					}
					deactivate;
					
					f_sendUtPrimitive(p_utRequest);
					
					if(not(fromPostamble)) {				
						f_checkCseSimuStatus();
						
						activate(a_default());
						if ((vc_config == e_cf02) or (vc_config == e_cf02CseSimuMaster)) {
							if (vc_testSystemRole == e_cse) {
								vc_cseSimu := activate(a_cse_cf02_cse1());
							}
						}
					}
				} else {
					action(p_action);
				}
			}
		
		}//end group UtFunctions
		
	}//end cseFunctions
	
	group AeFunctions {
		
		group PreambleFunctions {
		
			/**
			 * @desc	Waits for AE registration request and process it
			 * @param 	p_utRequest UpperTester request primitive to be sent to the IUT		
			 * @return 	Internal resource index of AE or -1 in case of failure		
			 * @verdict	inconc if no AE registration request is received 
			 */
	 		function f_ae_preamble_registerAe(template UtTriggerPrimitive p_utRequest := m_utCreateAe) runs on CseSimu return integer {
    		
				var MsgIn v_request;
				var integer v_localResourceIndex, v_parentIndex;
				var charstring v_action := "Please, register the AE on the Tester";
				
				p_utRequest.requestPrimitive.to_ := f_getLocalResourceAddress(-,-,-);
				if(not(ispresent(p_utRequest.requestPrimitive.primitiveContent))) {
					p_utRequest := m_utCreateAe;
				}
  
				f_ae_sendUtPrimitive(p_utRequest, v_action);
     		
				tc_ac.start;
				alt {    				
					[] mcaPortIn.receive(mw_request(mw_createAe)) -> value v_request {
						tc_ac.stop;
    					
						v_localResourceIndex := f_processCreateRequestPrimitive(v_request.primitive.requestPrimitive);
						
						f_send(e_mcaPortIn, m_response(vc_response.primitive.responsePrimitive));
							
					}
    					
					[] tc_ac.timeout {
						setverdict(inconc, __SCOPE__&":INFO: AE registration request not received");
						stop;
					}	     				   	
				}    
				
				f_checkCseSimuStatus();	
    			
				return v_localResourceIndex;	
			}//end function f_ae_preamble_register
			
			            
            /**
			 * @desc	Waits for Container create request and process it
			 * @param 	p_utRequest UpperTester request primitive to be sent to the IUT		
			 * @return 	Internal resource index of Container or -1 in case of failure		
			 * @verdict	inconc if no Container create request is received 
			 */
			function f_ae_preamble_createContainer(template UtTriggerPrimitive p_utRequest := m_utCreateAe) runs on CseSimu return integer {
    		
				var MsgIn v_request;
				var PrimitiveContent v_modifiedResource;
				var integer v_resourceIndex, v_parentIndex;
				var RequestPrimitive v_rp;
				var charstring v_action := "Please, create a Container resource on the Tester";
				
				if(not(ispresent(p_utRequest.requestPrimitive.primitiveContent))) {
					p_utRequest.requestPrimitive.primitiveContent.container := m_contentCreateContainer;
				}
    		
				f_ae_sendUtPrimitive(p_utRequest, v_action);
				
				tc_ac.start;
				alt {    				
					[] mcaPortIn.receive(mw_request(mw_createContainer(?,?))) -> value v_request {
						tc_ac.stop;
    					
						v_rp := v_request.primitive.requestPrimitive;		
						v_parentIndex := f_getLocalResourceIndex(v_rp.to_);
						v_modifiedResource := f_generateLocalResource(v_rp.primitiveContent, v_parentIndex, v_rp.resourceType);
						v_resourceIndex := f_setLocalResource(v_modifiedResource, int2, v_parentIndex);
						if(v_resourceIndex != -1) {
							f_send(e_mcaPortIn, m_response(m_responsePrimitive_content(int2001, v_rp.requestIdentifier, v_modifiedResource)));
							setverdict(pass, __SCOPE__&":INFO: Container created successfuly");
						}
						else {
							f_send(e_mcaPortIn, m_response(m_responsePrimitive(int5000, v_request.primitive.requestPrimitive.requestIdentifier)));
							setverdict(inconc, __SCOPE__&":INFO: Container creation failed");
						}					
					}
    					
					[] tc_ac.timeout {
						setverdict(inconc, __SCOPE__&":INFO: Container create request not received");
						stop;
					}	     				   	
				}    
				
				f_checkCseSimuStatus();	
    			
				return v_resourceIndex;	
 			} //end function f_ae_preamble_createContainer	
						
		} // end PreambleFunctions
		
		group CseSimuFunctions {

			function f_ae_createPollingChannel(template UtTriggerPrimitive p_utRequest := m_utCreateAe, integer p_parentIndex := 0) runs on CseSimu return integer { //vc_cSEBaseIndex) runs on CseSimu return integer {
				var MsgIn v_request;
				var PrimitiveContent v_modifiedResource;
				var integer v_resourceIndex, v_parentIndex;
				var RequestPrimitive v_rp;
				var charstring v_action := "Please, create a Polling Channel resource on the Tester";
	
				if(not(ispresent(p_utRequest.requestPrimitive.primitiveContent))) {
					p_utRequest.requestPrimitive.primitiveContent.pollingChannel := m_contentCreatePollingChannel;
				}

				p_utRequest.requestPrimitive.to_ := f_getLocalResourceAddress(p_parentIndex);

				f_ae_sendUtPrimitive(p_utRequest, v_action);
	
				tc_ac.start;
				alt {    				
					[] mcaPortIn.receive(mw_request(mw_createPollingChannel(?,?))) -> value v_request {
						tc_ac.stop;
			
						v_rp := v_request.primitive.requestPrimitive;		
						v_parentIndex := f_getLocalResourceIndex(v_rp.to_);
						v_modifiedResource := f_generateLocalResource(v_rp.primitiveContent, v_parentIndex, v_rp.resourceType);
						v_resourceIndex := f_setLocalResource(v_modifiedResource, int2, v_parentIndex);
						if(v_resourceIndex != -1) {
							f_send(e_mcaPortIn, m_response(m_responsePrimitive_content(int2001, v_rp.requestIdentifier, v_modifiedResource)));
							setverdict(pass, __SCOPE__&":INFO: Polling Channel created successfuly");
						}
						else {
							f_send(e_mcaPortIn, m_response(m_responsePrimitive(int5000, v_request.primitive.requestPrimitive.requestIdentifier)));
							setverdict(inconc, __SCOPE__&":INFO: Polling Channel creation failed");
						}					
					}
			
					[] tc_ac.timeout {
						setverdict(inconc, __SCOPE__&":INFO: Polling Channel create request not received");
						stop;
					}	     				   	
				}    
	
				f_checkCseSimuStatus();	
	
				return v_resourceIndex;	
			} //end function f_ae_createPollingChannel

			/**
			 * @desc Message exchange for the creation of a resource
			 * @param p_request CREATE request primitive expected
			 * @verdict 
			 */
			function f_ae_createResourceHandler(template RequestPrimitive p_request := mw_create) runs on CseSimu return integer{
				
				var integer v_localResourceIndex;
				
				//Activate defaults when running on a PTC
				f_cse_activateDefaults_cse1();	
			
				tc_ac.start;
				alt {
					[] mcaPortIn.receive(mw_request(p_request)) -> value vc_request {
						tc_ac.stop;
						v_localResourceIndex := f_processCreateRequestPrimitive(vc_request.primitive.requestPrimitive);
						f_send(e_mcaPortIn, m_response(vc_response.primitive.responsePrimitive));
					}
					[] tc_ac.timeout {
						setverdict(inconc, __SCOPE__&":INFO: No creation for resource received");
					}
				}	
			
				f_checkCseSimuStatus();
				
				return v_localResourceIndex;
			
			}// end f_cse_createResourceHandler

		} // end CseSimuFunctions

		group AeAltstepFunctions {
    
			/**
			 * @desc    Waits for CREATE request, stores resource and replies to request 
			 * @remark  This altstep includes a_ae_default
			 * @see		a_ae_default
			 */
			altstep a_ae_cf03() runs on CseSimu {
				
				[] a_ae_cseSimu();				
			}
			
			/**
			  * @desc	Altstep for AeSimu
			  */
			 altstep a_ae_cseSimu() runs on CseSimu {
				var ResponsePrimitive v_response;
				var MsgIn v_request;			
				var integer v_localResourceIndex := -1;
								
				[] mcaPortIn.receive(mw_request(mw_notify)) -> value v_request {
					tc_ac.stop;
					log(__SCOPE__&": WARNING: Unexpected NOTIFY message received");

					//Send response in any case
					v_response := valueof(m_responseNotification(int2000, omit));
					v_response.requestIdentifier := vc_request.primitive.requestPrimitive.requestIdentifier;
					f_send(e_mcaPortIn, m_response(v_response));
					tc_ac.start(10.0);
					repeat;
				}
				[] mcaPortIn.receive(mw_request(mw_create)) -> value v_request {	
					
					v_localResourceIndex := f_processCreateRequestPrimitive(v_request.primitive.requestPrimitive);
	
					f_send(e_mccPortIn, m_response(vc_response.primitive.responsePrimitive));
					tc_ac.start(10.0);
					repeat;
				}
				[] mcaPortIn.receive {
					log(__SCOPE__&": WARNING: Unexpected message received");
					repeat;
				}
				[] mcaPort.receive {
					log(__SCOPE__&": WARNING: Unexpected message received");
					repeat;
				}
			 }
 
 			/**
			  * @desc	Activation of the corresponding default altstep depending on config for CseSimu
			  */  		 		
			function f_ae_activateDefaults_cse1() runs on CseSimu {
				if(not(self == mtc)) {
					activate(a_default());
					if(vc_config == e_cf03) {
						activate(a_ae_cf03());
						log(__SCOPE__&": INFO: Default cf03 activated");
					}
				}	
			}
		}//end group AeAltstepFunctions
		
		group UtFunctions {

			/**
			 * @desc Sending of an Upper Tester primitive
			 * @param p_utRequest Action to be performed by IUT
			 * @param p_action Description of the given action to be performed by the IUT
			 * @verdict 
			 */
			function f_ae_sendUtPrimitive(template UtTriggerPrimitive p_utRequest, in universal charstring p_action) runs on CseSimu {
				
				if (PX_UT_IMPLEMENTED){
					
					p_utRequest.requestPrimitive.requestIdentifier := "m_uttriggerPrimitive" & f_rnd(1, 1000000);
	
					deactivate;
					
					f_sendUtPrimitive(p_utRequest);
									
					f_checkCseSimuStatus();
					
					activate(a_default());
					if (vc_config == e_cf03) {
						vc_cseSimu := activate(a_ae_cf03());
					} else if (vc_config == e_cf04) {
						vc_cseSimu := activate(a_cse_cf04());
					}
				}else{
					action(p_action);
				}
			}
		
		
		}//end group UtFunctions
		
	}//end of aeFunctions


	group GetSetFunctions {
		
		/**
		 * @desc Build a reception template from the primitiveContent sent in previous request primitive
		 * @param p_primitiveContent PrimitiveContent from previous request primitive
		 * @return Built reception template
		 * @verdict 
		 */
		function f_getTemplateFromPrimitiveContent (in template PrimitiveContent p_primitiveContent) return template PrimitiveContent{
			var template PrimitiveContent v_primitiveContent := omit;
			
			if(ischosen(p_primitiveContent.container)){ // Container
				v_primitiveContent := {container := mw_contentContainerBase};
				
				if(ispresent(p_primitiveContent.container.labels)){
					v_primitiveContent.container.labels := ?;
				}
				if(ispresent(p_primitiveContent.container.accessControlPolicyIDs)){
					v_primitiveContent.container.accessControlPolicyIDs := ?;
				}
				if(ispresent(p_primitiveContent.container.announceTo)){
					v_primitiveContent.container.announceTo := ?;
				}
				if(ispresent(p_primitiveContent.container.announcedAttribute)){
					v_primitiveContent.container.announcedAttribute := ?;
				}
				if(ispresent(p_primitiveContent.container.creator)){
					v_primitiveContent.container.creator := ?;
				}
				if(ispresent(p_primitiveContent.container.maxNrOfInstances)){
					v_primitiveContent.container.maxNrOfInstances := ?;
				}
				if(ispresent(p_primitiveContent.container.maxByteSize)){
					v_primitiveContent.container.maxByteSize := ?;
				}
				if(ispresent(p_primitiveContent.container.maxInstanceAge)){
					v_primitiveContent.container.maxInstanceAge := ?;
				}
				if(ispresent(p_primitiveContent.container.locationID)){
					v_primitiveContent.container.locationID := ?;
				}
				if(ispresent(p_primitiveContent.container.ontologyRef)){
					v_primitiveContent.container.ontologyRef := ?;
				}
			}
			
			else if(ischosen(p_primitiveContent.aE)){ // AE
				v_primitiveContent := {aE := mw_contentAeBase};
				
				if(ispresent(p_primitiveContent.aE.labels)){
					v_primitiveContent.aE.labels := ?;
				}
				if(ispresent(p_primitiveContent.aE.accessControlPolicyIDs)){
					v_primitiveContent.aE.accessControlPolicyIDs := ?;
				}
				if(ispresent(p_primitiveContent.aE.announceTo)){
					v_primitiveContent.aE.announceTo := ?;
				}
				if(ispresent(p_primitiveContent.aE.announcedAttribute)){
					v_primitiveContent.aE.announcedAttribute := ?;
				}
				if(ispresent(p_primitiveContent.aE.appName)){
					v_primitiveContent.aE.appName := ?;
				}
				if(ispresent(p_primitiveContent.aE.pointOfAccess)){
					v_primitiveContent.aE.pointOfAccess := ?;
				}
				if(ispresent(p_primitiveContent.aE.ontologyRef)){
					v_primitiveContent.aE.ontologyRef := ?;
				}
				if(ispresent(p_primitiveContent.aE.nodeLink)){
					v_primitiveContent.aE.nodeLink := ?;
				}
				if(ispresent(p_primitiveContent.aE.contentSerialization)){
					v_primitiveContent.aE.contentSerialization := ?;
				}
			}
			
			else if(ischosen(p_primitiveContent.accessControlPolicy)){ // ACP
				v_primitiveContent := {accessControlPolicy := mw_contentAcpBase};
	
				if(ispresent(p_primitiveContent.accessControlPolicy.labels)){
					v_primitiveContent.accessControlPolicy.labels := ?;
				}
				if(ispresent(p_primitiveContent.accessControlPolicy.announceTo)){
					v_primitiveContent.accessControlPolicy.announceTo := ?;
				}
			}
			
			else if(ischosen(p_primitiveContent.contentInstance)){ // ContentInstance
				v_primitiveContent := {contentInstance := mw_contentContentInstanceBase};

				if(ispresent(p_primitiveContent.contentInstance.labels)){
					v_primitiveContent.contentInstance.labels := ?;
				}
				if(ispresent(p_primitiveContent.contentInstance.announceTo)){
					v_primitiveContent.contentInstance.announceTo := ?;
				}
				if(ispresent(p_primitiveContent.contentInstance.announcedAttribute)){
					v_primitiveContent.contentInstance.announcedAttribute := ?;
				}
				if(ispresent(p_primitiveContent.contentInstance.creator)){
					v_primitiveContent.contentInstance.creator := ?;
				}
				if(ispresent(p_primitiveContent.contentInstance.contentInfo)){
					v_primitiveContent.contentInstance.contentInfo := ?;
				}
				if(ispresent(p_primitiveContent.contentInstance.ontologyRef)){
					v_primitiveContent.contentInstance.ontologyRef := ?;
				}
			}
			
			else if(ischosen(p_primitiveContent.group_)){ // Group
				v_primitiveContent := {group_ := mw_contentGroupBase};

				if(ispresent(p_primitiveContent.group_.labels)){
					v_primitiveContent.group_.labels := ?;
				}
				if(ispresent(p_primitiveContent.group_.accessControlPolicyIDs)){
					v_primitiveContent.group_.accessControlPolicyIDs := ?;
				}
				if(ispresent(p_primitiveContent.group_.announceTo)){
					v_primitiveContent.group_.announceTo := ?;
				}
				if(ispresent(p_primitiveContent.group_.announcedAttribute)){
					v_primitiveContent.group_.announcedAttribute := ?;
				}
				if(ispresent(p_primitiveContent.group_.creator)){
					v_primitiveContent.group_.creator := ?;
				}
				if(ispresent(p_primitiveContent.group_.membersAccessControlPolicyIDs)){
					v_primitiveContent.group_.membersAccessControlPolicyIDs := ?;
				}
				if(ispresent(p_primitiveContent.group_.memberTypeValidated)){
					v_primitiveContent.group_.memberTypeValidated := ?;
				}
				if(ispresent(p_primitiveContent.group_.consistencyStrategy)){
					v_primitiveContent.group_.consistencyStrategy := ?;
				}
				if(ispresent(p_primitiveContent.group_.groupName)){
					v_primitiveContent.group_.groupName := ?;
				}
			}
			
			else if(ischosen(p_primitiveContent.pollingChannel)){ // PollingChannel
				v_primitiveContent := {pollingChannel := mw_contentPollingChannelBase};

				if(ispresent(p_primitiveContent.pollingChannel.labels)){
					v_primitiveContent.pollingChannel.labels := ?;
				}
			}
			
			else if(ischosen(p_primitiveContent.schedule)){ // Schedule
				v_primitiveContent := {schedule := mw_contentScheduleBase};

				if(ispresent(p_primitiveContent.schedule.labels)){
					v_primitiveContent.schedule.labels := ?;
				}
				if(ispresent(p_primitiveContent.schedule.announceTo)){
					v_primitiveContent.schedule.announceTo := ?;
				}
				if(ispresent(p_primitiveContent.schedule.announcedAttribute)){
					v_primitiveContent.schedule.announcedAttribute := ?;
				}
			}
			
			else if(ischosen(p_primitiveContent.subscription)){ // Subscription
				v_primitiveContent := {subscription := mw_contentSubscriptionBase};

				if(ispresent(p_primitiveContent.subscription.labels)){
					v_primitiveContent.subscription.labels := ?;
				}
				if(ispresent(p_primitiveContent.subscription.accessControlPolicyIDs)){
					v_primitiveContent.subscription.accessControlPolicyIDs := ?;
				}
				if(ispresent(p_primitiveContent.subscription.creator)){
					v_primitiveContent.subscription.creator := ?;
				}
				if(ispresent(p_primitiveContent.subscription.eventNotificationCriteria)){
					v_primitiveContent.subscription.eventNotificationCriteria := ?;
				}
				if(ispresent(p_primitiveContent.subscription.expirationCounter)){
					v_primitiveContent.subscription.expirationCounter := ?;
				}
				if(ispresent(p_primitiveContent.subscription.groupID)){
					v_primitiveContent.subscription.groupID := ?;
				}
				if(ispresent(p_primitiveContent.subscription.notificationForwardingURI)){
					v_primitiveContent.subscription.notificationForwardingURI := ?;
				}
				if(ispresent(p_primitiveContent.subscription.batchNotify)){
					v_primitiveContent.subscription.batchNotify := ?;
				}
				if(ispresent(p_primitiveContent.subscription.rateLimit)){
					v_primitiveContent.subscription.rateLimit := ?;
				}
				if(ispresent(p_primitiveContent.subscription.preSubscriptionNotify)){
					v_primitiveContent.subscription.preSubscriptionNotify := ?;
				}
				if(ispresent(p_primitiveContent.subscription.pendingNotification)){
					v_primitiveContent.subscription.pendingNotification := ?;
				}
				if(ispresent(p_primitiveContent.subscription.notificationStoragePriority)){
					v_primitiveContent.subscription.notificationStoragePriority := ?;
				}
				if(ispresent(p_primitiveContent.subscription.latestNotify)){
					v_primitiveContent.subscription.latestNotify := ?;
				}
				if(ispresent(p_primitiveContent.subscription.notificationContentType)){
					v_primitiveContent.subscription.notificationContentType := ?;
				}
				if(ispresent(p_primitiveContent.subscription.notificationEventCat)){
					v_primitiveContent.subscription.notificationEventCat := ?;
				}
				if(ispresent(p_primitiveContent.subscription.subscriberURI)){
					v_primitiveContent.subscription.subscriberURI := ?;
				}
			}
			else if(ischosen(p_primitiveContent.remoteCSE)){ //remoteCSE
				v_primitiveContent := {remoteCSE := mw_contentRemoteCSEBase};
				  
				if(ispresent(p_primitiveContent.remoteCSE.labels)){
					v_primitiveContent.remoteCSE.labels := ?;			    
				}
				  
				if(ispresent(p_primitiveContent.remoteCSE.accessControlPolicyIDs)){
					v_primitiveContent.remoteCSE.accessControlPolicyIDs := ?;			    
				}
				 				
				if(ispresent(p_primitiveContent.remoteCSE.announceTo)){
					v_primitiveContent.remoteCSE.announceTo := ?;			    
				}
				 
				if(ispresent(p_primitiveContent.remoteCSE.announcedAttribute)){
					v_primitiveContent.remoteCSE.announcedAttribute := ?;			    
				}
				
				if(ispresent(p_primitiveContent.remoteCSE.cseType)){
					v_primitiveContent.remoteCSE.cseType := ?;			    
				}
				  
				if(ispresent(p_primitiveContent.remoteCSE.pointOfAccess)){
					v_primitiveContent.remoteCSE.pointOfAccess := ?;			    
				}
				  
				if(ispresent(p_primitiveContent.remoteCSE.m2M_Ext_ID)){
					v_primitiveContent.remoteCSE.m2M_Ext_ID := ?;			    
				}
				  
				if(ispresent(p_primitiveContent.remoteCSE.trigger_Recipient_ID)){
					v_primitiveContent.remoteCSE.trigger_Recipient_ID := ?;			    
				}
				  
				if(ispresent(p_primitiveContent.remoteCSE.nodeLink)){
					v_primitiveContent.remoteCSE.nodeLink := ?;			    
				}
			}			
			else if(ischosen(p_primitiveContent.timeSeries)){ // timeSeries
				v_primitiveContent := {timeSeries := mw_contentTimeSeriesBase};
				
				if(ispresent(p_primitiveContent.timeSeries.labels)){
					v_primitiveContent.timeSeries.labels := ?;
				}
				if(ispresent(p_primitiveContent.timeSeries.accessControlPolicyIDs)){
					v_primitiveContent.timeSeries.accessControlPolicyIDs := ?;
				}
				if(ispresent(p_primitiveContent.timeSeries.announceTo)){
					v_primitiveContent.timeSeries.announceTo := ?;
				}
				if(ispresent(p_primitiveContent.timeSeries.announcedAttribute)){
					v_primitiveContent.timeSeries.announcedAttribute := ?;
				}
				if(ispresent(p_primitiveContent.timeSeries.creator)){
					v_primitiveContent.timeSeries.creator := ?;
				}
				if(ispresent(p_primitiveContent.timeSeries.maxNrOfInstances)){
					v_primitiveContent.timeSeries.maxNrOfInstances := ?;
				}
				if(ispresent(p_primitiveContent.timeSeries.maxByteSize)){
					v_primitiveContent.timeSeries.maxByteSize := ?;
				}
				if(ispresent(p_primitiveContent.timeSeries.maxInstanceAge)){
					v_primitiveContent.timeSeries.maxInstanceAge := ?;
				}
				if(ispresent(p_primitiveContent.timeSeries.periodicInterval)){
					v_primitiveContent.timeSeries.periodicInterval := ?;
				}
				if(ispresent(p_primitiveContent.timeSeries.missingDataDetect)){
					v_primitiveContent.timeSeries.missingDataDetect := ?;
				}
				if(ispresent(p_primitiveContent.timeSeries.missingDataMaxNr)){
					v_primitiveContent.timeSeries.missingDataMaxNr := ?;
				}
				if(ispresent(p_primitiveContent.timeSeries.missingDataList)){
					v_primitiveContent.timeSeries.missingDataList := ?;
				}
				if(ispresent(p_primitiveContent.timeSeries.missingDataCurrentNr)){
					v_primitiveContent.timeSeries.missingDataCurrentNr := ?;
				}
				if(ispresent(p_primitiveContent.timeSeries.missingDataDetectTimer)){
					v_primitiveContent.timeSeries.missingDataDetectTimer := ?;
				}
				if(ispresent(p_primitiveContent.timeSeries.ontologyRef)){
					v_primitiveContent.timeSeries.ontologyRef := ?;
				}
				if(ispresent(p_primitiveContent.timeSeries.contentInfo)){
					v_primitiveContent.timeSeries.contentInfo := ?;
				}
			}			
			else if(ischosen(p_primitiveContent.timeSeriesInstance)){ // timeSeriesInstance
				v_primitiveContent := {timeSeriesInstance := mw_contentTimeSeriesInstanceBase};
				
				if(ispresent(p_primitiveContent.timeSeriesInstance.labels)){
					v_primitiveContent.timeSeriesInstance.labels := ?;
				}
				if(ispresent(p_primitiveContent.timeSeriesInstance.announceTo)){
					v_primitiveContent.timeSeriesInstance.announceTo := ?;
				}
				if(ispresent(p_primitiveContent.timeSeriesInstance.announcedAttribute)){
					v_primitiveContent.timeSeriesInstance.announcedAttribute := ?;
				}
				if(ispresent(p_primitiveContent.timeSeriesInstance.sequenceNr)){
					v_primitiveContent.timeSeriesInstance.sequenceNr := ?;
				}
			}			
			return v_primitiveContent;
		}

		/**
		 * @desc Creation of a CREATE request primitive from a template request primitive
		 * @param p_resourceType Type of resource to be created
		 * @param p_request Template request primitive 
		 * @param p_parentIndex Internal resource index which indicates the parent of the resource to be created
		 * @return Created CREATE request primitive
		 * @verdict 
		 */
		function f_getCreateRequestPrimitive(in ResourceType p_resourceType, template RequestPrimitive p_request := m_create, integer p_parentIndex) runs on Tester return RequestPrimitive {
			var template ListOfURIs v_defaultListOfURIs := {"NotInitialized"};
			var template AcpType v_defaultAcpIDs := {"NotInitialized"};
			var template Timestamp v_defaultTimestamp := "00000101T000000";
			var template AbsRelTimestamp v_defaultAbsRelTimestamp := {alt_ := v_defaultTimestamp};
			var template DynAuthJWT v_defaultDynAuthJWT := {alt_ := "oneM2M.oneM2M.oneM2M"};

			p_request.requestIdentifier := valueof(p_request.requestIdentifier) & f_rnd(1, 1000000);
			
			if((p_resourceType != int2) and (p_resourceType != int16) and (p_resourceType != int10005)) {
					p_request.from_ := f_getOriginator(p_parentIndex, vc_testSystemRole);
				}
			//Only set To parameter if it has not been set yet 
			if(valueof(p_request.to_) == "NotInitialized") {
				p_request.to_ := f_getResourceAddress(p_parentIndex);
			}

			//Specific actions for eac reasoure type
			if (p_resourceType == int1) {//AccessControlPolicy
				
			} else if (p_resourceType == int2) {//AE
				if(ispresent(p_request.primitiveContent.aE.pointOfAccess)) {
					p_request.primitiveContent.aE.requestReachability := true;
				}
			} else if(p_resourceType == int3){//container
				//when a container is created by hosting cse for storing location information, the container is seen as a location container
				if(PX_IS_LOC_CONTAINER){
					p_request.primitiveContent.container.locationID := f_getResourceId(vc_resourcesList[p_parentIndex].resource);//resourceID of the locationPolicy
				}	
				if(ispresent(p_request.primitiveContent.container.accessControlPolicyIDs)) {
					if((match(valueof(p_request.primitiveContent.container.accessControlPolicyIDs), v_defaultAcpIDs )) and (isbound(vc_acpIndex))){
						p_request.primitiveContent.container.accessControlPolicyIDs := {f_getResourceAddress(vc_acpIndex)};
					}	
				}  
			} else if (p_resourceType == int4) {//contentInstance
			} else if (p_resourceType == int9) {//group
				if(match(valueof(p_request.primitiveContent.group_.memberIDs), v_defaultListOfURIs )){
					if (p_parentIndex == -1){
						p_request.primitiveContent.group_.memberIDs := {};
					}else{
						p_request.primitiveContent.group_.memberIDs := {f_getResourceId(vc_resourcesList[p_parentIndex].resource)};
					}
				}
			} else if (p_resourceType == int15) {//pollingChannel
				if(ischosen(vc_resourcesList[p_parentIndex].resource.aE)) {	
					p_request.from_ := vc_resourcesList[p_parentIndex].resource.aE.aE_ID;
				}
			} else if (p_resourceType == int16) {//remoteCSE
				if(ispresent(p_request.primitiveContent.remoteCSE.pointOfAccess)) {
					p_request.primitiveContent.remoteCSE.requestReachability := true;
				}
			} else if (p_resourceType == int18) {//schedule
			} else if (p_resourceType == int23) {//subscription
				//notificationURI
				if(match(valueof(p_request.primitiveContent.subscription.notificationURI), v_defaultListOfURIs )){
					p_request.primitiveContent.subscription.notificationURI := {f_getResourceAddress(f_getResourceIndex(f_getOriginator(p_parentIndex)))};
				}
				//notificationForwardingURI
				if(ispresent(p_request.primitiveContent.subscription.notificationForwardingURI)) {
					if(match(valueof(p_request.primitiveContent.subscription.notificationForwardingURI), "NotInitialized" )){
						p_request.primitiveContent.subscription.notificationForwardingURI := p_request.primitiveContent.subscription.notificationURI[0];
					}
				}
				//subscriberURI
				if(ispresent(p_request.primitiveContent.subscription.subscriberURI)) {
					if(match(valueof(p_request.primitiveContent.subscription.subscriberURI), "NotInitialized" )){
						p_request.primitiveContent.subscription.subscriberURI := valueof(p_request.from_);
					}
				}
				//accessControlPolicyIds
				if(ispresent(p_request.primitiveContent.subscription.accessControlPolicyIDs)) {
					if(match(valueof(p_request.primitiveContent.subscription.accessControlPolicyIDs), v_defaultAcpIDs )){
						p_request.primitiveContent.subscription.accessControlPolicyIDs := {f_getResourceAddress(vc_acpIndex)};
					}	
				}  
			} else if(p_resourceType == int29){//timeSeries
				if(ispresent(p_request.primitiveContent.timeSeries.accessControlPolicyIDs)) {
					if((match(valueof(p_request.primitiveContent.timeSeries.accessControlPolicyIDs), v_defaultAcpIDs )) and (isbound(vc_acpIndex))){
						p_request.primitiveContent.timeSeries.accessControlPolicyIDs := {f_getResourceId(vc_resourcesList[vc_acpIndex].resource)};
					}
                }
			} else if(p_resourceType == int30){//timeSeriesInstance
				if(ispresent(p_request.primitiveContent.timeSeriesInstance.dataGenerationTime)) {
					if((match(valueof(p_request.primitiveContent.timeSeriesInstance.dataGenerationTime), v_defaultAbsRelTimestamp))){
						p_request.primitiveContent.timeSeriesInstance.dataGenerationTime := {alt_ := fx_generateTimestamp()};
					}
				}
			} else if(p_resourceType == int31){//role
				if(ispresent(p_request.primitiveContent.role.notBefore)) {
					if((match(valueof(p_request.primitiveContent.role.notBefore), v_defaultTimestamp))){
						p_request.primitiveContent.role.notBefore := fx_generateTimestamp();
					}
				} else if(ispresent(p_request.primitiveContent.role.notAfter)) {
					if((match(valueof(p_request.primitiveContent.role.notAfter), v_defaultTimestamp))){
						p_request.primitiveContent.role.notAfter := fx_generateTimestamp();
					}
				}
			} else if(p_resourceType == int32){//token
				if(ispresent(p_request.primitiveContent.token.tokenObject)) {
					if((match(valueof(p_request.primitiveContent.token.tokenObject), v_defaultDynAuthJWT))){
						p_request.primitiveContent.token.tokenObject := fx_generateJWT();
					}
				}
			} 
			
			return valueof(p_request);
		}
		
		/**
		 * @desc Creation of a CREATE response primitive from a template request primitive
		 * @param p_resourceType Type of resource to be created
		 * @param p_request Template request primitive 
		 * @return Created CREATE response primitive
		 * @verdict 
		 */
		//TODO To be completed
		function f_getCreateResponsePrimitive(in ResourceType p_resourceType, template RequestPrimitive p_request := m_create) runs on Tester return ResponsePrimitive {
			var template ResponsePrimitive v_responsePrimitive;

			if(p_resourceType != int2) {
				v_responsePrimitive.from_ := p_request.to_;
			}
			p_request.to_ := p_request.from_;

			if (p_resourceType == int1) {//AccessControlPolicy
				
			} 
			
			if (p_resourceType == int9) {//group
				
			}
			
			if(p_resourceType == int3){//container
					  
			}
			
			if (p_resourceType == int15) {//pollingChannel
				
			} 
			
			if (p_resourceType == int18) {//schedule
			} 

			if (p_resourceType == int23) {//subscription
				
				
			}

			return valueof(v_responsePrimitive);
		}

		/**
		 * @desc Creation of an UPDATE request primitive from a template request primitive
		 * @param p_resourceType Type of resource to be created
		 * @param p_resourceIndex Internal resource index which indicates the resource to be updated
		 * @param p_request Template request primitive
		 * @return Created UPDATE request primitive
		 * @verdict 
		 */
		function f_getUpdateRequestPrimitive(in ResourceType p_resourceType, integer p_resourceIndex, template RequestPrimitive p_request) runs on Tester return RequestPrimitive {
		
			p_request.requestIdentifier := valueof(p_request.requestIdentifier) & f_rnd(1, 1000000);
			
			p_request.from_ := f_getOriginator(p_resourceIndex);
			
			if(p_resourceType != int10002) {
				//Only set To parameter if it has not been set yet
				if(valueof(p_request.to_) == "NotInitialized") {
					p_request.to_ := f_getResourceAddress(p_resourceIndex);
				}
			} else {
				//p_request.from_ := PX_CSE1_ID & "/" & f_getResourceId(vc_resourcesList[p_resourceIndex].resource); 
				
				p_request.to_ := f_getResourceAddress(p_resourceIndex, -, e_spRelative);
			}

			if (p_resourceType == int3) {//Container

			//TODO
			} 

			if (p_resourceType == int9) {//group
				//TODO	

			}

			if (p_resourceType == int18) {//schedule
				//TODO			

			} 

			if (p_resourceType == int15) {//pollingChannel
				//TODO

			}

			if (p_resourceType == int23) {//subscription
				//TODO		
			} 

			return 	valueof(p_request);
		}

		/**
		 * @desc Extraction from a primitiveContent field the resourceID attribute
		 * @param p_contentResource primitiveContent field
		 * @return resourceID attribute
		 * @verdict 
		 */
		function f_getResourceId(PrimitiveContent p_contentResource) return XSD.ID {
					
			if(ischosen(p_contentResource.accessControlPolicy)) {
				return f_resourceIdCleaner(p_contentResource.accessControlPolicy.resourceID);
			}
			if(ischosen(p_contentResource.container)) {
				return f_resourceIdCleaner(p_contentResource.container.resourceID);
			}
			if(ischosen(p_contentResource.contentInstance)) {
				return f_resourceIdCleaner(p_contentResource.contentInstance.resourceID);
			}
			if(ischosen(p_contentResource.schedule)) {
				return f_resourceIdCleaner(p_contentResource.schedule.resourceID);
			}
			if(ischosen(p_contentResource.pollingChannel)) {
				return f_resourceIdCleaner(p_contentResource.pollingChannel.resourceID);
			}
			if(ischosen(p_contentResource.subscription)) {
				return f_resourceIdCleaner(p_contentResource.subscription.resourceID);
			}
			if(ischosen(p_contentResource.group_)) {
				return f_resourceIdCleaner(p_contentResource.group_.resourceID);
			}
			if(ischosen(p_contentResource.aE)) {
				return f_resourceIdCleaner(p_contentResource.aE.resourceID);
			}
			if(ischosen(p_contentResource.serviceSubscribedAppRule)) {
				return f_resourceIdCleaner(p_contentResource.serviceSubscribedAppRule.resourceID);
			}
			if(ischosen(p_contentResource.remoteCSE)) {
				return f_resourceIdCleaner(p_contentResource.remoteCSE.resourceID);
			}
			if(ischosen(p_contentResource.cSEBase)) {
				return f_resourceIdCleaner(p_contentResource.cSEBase.resourceID);
			}
			if(ischosen(p_contentResource.m2mServiceSubscriptionProfile)) {
				return f_resourceIdCleaner(p_contentResource.m2mServiceSubscriptionProfile.resourceID);
			}
			if(ischosen(p_contentResource.node)) {
				return f_resourceIdCleaner(p_contentResource.node.resourceID);
			}
			if(ischosen(p_contentResource.statsConfig)) {
				return f_resourceIdCleaner(p_contentResource.statsConfig.resourceID);
			}
			if(ischosen(p_contentResource.statsCollect)) {
				return f_resourceIdCleaner(p_contentResource.statsCollect.resourceID);
			}
			if(ischosen(p_contentResource.timeSeries)) {
				return p_contentResource.timeSeries.resourceID;
			}	
			if(ischosen(p_contentResource.timeSeriesInstance)) {
				return p_contentResource.timeSeriesInstance.resourceID;
			}
			if(ischosen(p_contentResource.semanticDescriptor)) {
				return p_contentResource.semanticDescriptor.resourceID;
			}
			if(ischosen(p_contentResource.ontologyRepository)) {
				return p_contentResource.ontologyRepository.resourceID;
			}
			if(ischosen(p_contentResource.ontology)) {
				return p_contentResource.ontology.resourceID;
			}
			if(ischosen(p_contentResource.semanticMashupInstance)) {
				return p_contentResource.semanticMashupInstance.resourceID;
			}
			if(ischosen(p_contentResource.semanticMashupJobProfile)) {
				return p_contentResource.semanticMashupJobProfile.resourceID;
			}
			//Announced resources
			if(ischosen(p_contentResource.accessControlPolicyAnnc)) {
				return f_resourceIdCleaner(p_contentResource.accessControlPolicyAnnc.resourceID);
			}
			if(ischosen(p_contentResource.aEAnnc)) {
				return f_resourceIdCleaner(p_contentResource.aEAnnc.resourceID);
			}
			if(ischosen(p_contentResource.containerAnnc)) {
				return f_resourceIdCleaner(p_contentResource.containerAnnc.resourceID);
			}
			if(ischosen(p_contentResource.contentInstanceAnnc)) {
				return f_resourceIdCleaner(p_contentResource.contentInstanceAnnc.resourceID);
			}
			if(ischosen(p_contentResource.cSEBaseAnnc)) {
				return f_resourceIdCleaner(p_contentResource.cSEBaseAnnc.resourceID);
			}
			if(ischosen(p_contentResource.groupAnnc)) {
				return f_resourceIdCleaner(p_contentResource.groupAnnc.resourceID);
			}
			if(ischosen(p_contentResource.scheduleAnnc)) {
				return f_resourceIdCleaner(p_contentResource.scheduleAnnc.resourceID);
			}
			if(ischosen(p_contentResource.remoteCSEAnnc)) {
				return f_resourceIdCleaner(p_contentResource.remoteCSEAnnc.resourceID);
			}
			if(ischosen(p_contentResource.timeSeriesAnnc)) {
				return p_contentResource.timeSeriesAnnc.resourceID;
			}	
			if(ischosen(p_contentResource.timeSeriesInstanceAnnc)) {
				return p_contentResource.timeSeriesInstanceAnnc.resourceID;
			}

			log(__SCOPE__&":WARNING: Primitive Content Kind not implemented");
			
			return "resourceIDNotFound";
			
		}
			
		/**
		 * @desc Extraction from a primitiveContent field the resourceName attribute
		 * @param p_contentResource primitiveContent field
		 * @return resourceName attribute
		 * @verdict 
		 */
		function f_getResourceName(PrimitiveContent p_contentResource) return XSD.ID {
					
			if(ischosen(p_contentResource.accessControlPolicy)) {
				return p_contentResource.accessControlPolicy.resourceName;
			}
			if(ischosen(p_contentResource.container)) {
				return p_contentResource.container.resourceName;
			}
			if(ischosen(p_contentResource.contentInstance)) {
				return p_contentResource.contentInstance.resourceName;
			}
			if(ischosen(p_contentResource.schedule)) {
				return p_contentResource.schedule.resourceName;
			}
			if(ischosen(p_contentResource.pollingChannel)) {
				return p_contentResource.pollingChannel.resourceName;
			}
			if(ischosen(p_contentResource.subscription)) {
				return p_contentResource.subscription.resourceName;
			}
			if(ischosen(p_contentResource.group_)) {
				return p_contentResource.group_.resourceName;
			}
			if(ischosen(p_contentResource.aE)) {
				return p_contentResource.aE.resourceName;
			}
			if(ischosen(p_contentResource.serviceSubscribedAppRule)) {
				return p_contentResource.serviceSubscribedAppRule.resourceName;
			}
			if(ischosen(p_contentResource.remoteCSE)) {
				return p_contentResource.remoteCSE.resourceName;
			}
			if(ischosen(p_contentResource.cSEBase)) {
				return p_contentResource.cSEBase.resourceName;
			}
			if(ischosen(p_contentResource.m2mServiceSubscriptionProfile)) {
				return p_contentResource.m2mServiceSubscriptionProfile.resourceName;
			}
			if(ischosen(p_contentResource.node)) {
				return p_contentResource.node.resourceName;
			}
			if(ischosen(p_contentResource.statsConfig)) {
				return p_contentResource.statsConfig.resourceName;
			}
			if(ischosen(p_contentResource.statsCollect)) {
				return p_contentResource.statsCollect.resourceName;
			}
			if(ischosen(p_contentResource.genericInterworkingService)) {
				return p_contentResource.genericInterworkingService.resourceName;
			}
			if(ischosen(p_contentResource.genericInterworkingService_invalid)) {
				return p_contentResource.genericInterworkingService_invalid.resourceName;
			}			
			if(ischosen(p_contentResource.timeSeries)) {
				return p_contentResource.timeSeries.resourceName;
			}	
			if(ischosen(p_contentResource.timeSeriesInstance)) {
				return p_contentResource.timeSeriesInstance.resourceName;
			}
			if(ischosen(p_contentResource.semanticDescriptor)) {
				return p_contentResource.semanticDescriptor.resourceName;
			}
			if(ischosen(p_contentResource.ontologyRepository)) {
				return p_contentResource.ontologyRepository.resourceName;
			}
			if(ischosen(p_contentResource.ontology)) {
				return p_contentResource.ontology.resourceName;
			}
			if(ischosen(p_contentResource.semanticMashupInstance)) {
				return p_contentResource.semanticMashupInstance.resourceName;
			}
			if(ischosen(p_contentResource.semanticMashupJobProfile)) {
				return p_contentResource.semanticMashupJobProfile.resourceName;
			}
			//Announced resources
			if(ischosen(p_contentResource.accessControlPolicyAnnc)) {
				return p_contentResource.accessControlPolicyAnnc.resourceName;
			}
			if(ischosen(p_contentResource.aEAnnc)) {
				return p_contentResource.aEAnnc.resourceName;
			}
			if(ischosen(p_contentResource.containerAnnc)) {
				return p_contentResource.containerAnnc.resourceName;
			}
			if(ischosen(p_contentResource.contentInstanceAnnc)) {
				return p_contentResource.contentInstanceAnnc.resourceName;
			}
			if(ischosen(p_contentResource.cSEBaseAnnc)) {
				return p_contentResource.cSEBaseAnnc.resourceName;
			}
			if(ischosen(p_contentResource.groupAnnc)) {
				return p_contentResource.groupAnnc.resourceName;
			}
			if(ischosen(p_contentResource.remoteCSEAnnc)) {
				return p_contentResource.remoteCSEAnnc.resourceName;
			}
			if(ischosen(p_contentResource.timeSeriesAnnc)) {
				return p_contentResource.timeSeriesAnnc.resourceName;
			}	
			if(ischosen(p_contentResource.timeSeriesInstanceAnnc)) {
				return p_contentResource.timeSeriesInstanceAnnc.resourceName;
			}
		
			log(__SCOPE__&":WARNING: Primitive Content Kind not implemented");
			
			return "resourceNameNotFound";
			
		}
			
		/**
		 * @desc Resolution of the originator field (from) for a given resource
		 * @param p_targetResourceIndex Internal resource index of the given resource
		 * @param p_testSystemRole TS acting as an AE or a CSE
		 * @return Originator for a given resource
		 * @verdict 
		 */
		function f_getOriginator(integer  p_targetResourceIndex := -1, TestSystemRole p_testSystemRole := e_ae) runs on Tester return XSD.AnyURI {
				
			if(p_targetResourceIndex == -1) {
				if(p_testSystemRole == e_ae) {
					return PX_SUPER_AE_ID;
				} else if (p_testSystemRole == e_cse) {
					return PX_SUPER_CSE_ID;
				}
			}	
			
			if(vc_resourcesList[p_targetResourceIndex].parentIndex == -1) {
				if(ischosen(vc_resourcesList[p_targetResourceIndex].resource.aE)) {
					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 if (ischosen(vc_resourcesList[p_targetResourceIndex].resource.cSEBaseAnnc)) {
					return PX_TS_CSE1.cseId; 
				} else {
					return f_getOriginator(vc_resourcesList[p_targetResourceIndex].parentIndex, p_testSystemRole);
				}
			} else {
				return f_getOriginator(vc_resourcesList[p_targetResourceIndex].parentIndex, p_testSystemRole);
			}
		}
		
		/**
		 * @desc Return of a index of a specific attribute from an attributeList by attributeName
		 * @param p_attributeList Target attributeList
		 * @param p_attributeName attributeName to be searched
		 * @return Index of the attribute in the attributeList
		 * @verdict 
		 */
		function f_getAttribute(in AttributeList p_attributeList, in XSD.NCName p_attributeName) return integer {
		var integer i;
			
		for (i:=0; i < lengthof(p_attributeList); i := i + 1){
			if(p_attributeList[i] == p_attributeName){
				return i;
			}	
		}
				
		return -1;
			
		}
		
		/**
		 * @desc Return of an attributeList from an attributeAux list
		 * @param p_attributeAuxList Source attributeAuxList
		 * @return AttributeList
		 */
		function f_getAttributeList(in AttributeAux_list p_attributeAuxList) return AttributeList_1 {
			var AttributeList_1 v_attributeList;
			var integer i;
			
			for (i:=0; i < lengthof(p_attributeAuxList); i := i + 1){
				v_attributeList[i] := p_attributeAuxList[i].name; 	
			}
					
			return v_attributeList;
			
		}
		
		/**
		 * @desc Resolution of the test system PoA for a given port
		 * @param p_portDesc			Description of port from where PoA will be built
		 * @param p_additionalContext	Additional context
		 * @return PoA for the given port
		 */
		function f_getLocalPoA(in PortDesc p_portDesc := PX_TS_CSE1.mccPortIn, charstring p_additionalContext := "") return charstring {
			var charstring v_poa;
  
  			log(">>> f_getLocalPoA: ", p_portDesc);
  
			if (ischosen(p_portDesc.binding.httpBindingDesc)) {
				if (ispresent(p_portDesc.binding.httpBindingDesc.bindingDesc.useTls) and (p_portDesc.binding.httpBindingDesc.bindingDesc.useTls == true)) {
					v_poa := "https://" & p_portDesc.binding.httpBindingDesc.bindingDesc.tsAddress;
				} else {
					v_poa := "http://" & p_portDesc.binding.httpBindingDesc.bindingDesc.tsAddress;
				}
				if (ispresent(p_portDesc.binding.httpBindingDesc.bindingDesc.localPort)) {
					v_poa := v_poa & ":" & int2str(p_portDesc.binding.httpBindingDesc.bindingDesc.localPort);
				}
			} else if (ischosen(p_portDesc.binding.coapBindingDesc)) {
				if (ispresent(p_portDesc.binding.coapBindingDesc.bindingDesc.useTls) and (p_portDesc.binding.coapBindingDesc.bindingDesc.useTls == true)) {
					v_poa := "coaps://" & p_portDesc.binding.coapBindingDesc.bindingDesc.tsAddress;
				} else {
					v_poa := "coap://" & p_portDesc.binding.coapBindingDesc.bindingDesc.tsAddress;
				}
   				if (ispresent(p_portDesc.binding.coapBindingDesc.bindingDesc.localPort)) {
   					v_poa := v_poa & ":" & int2str(p_portDesc.binding.coapBindingDesc.bindingDesc.localPort);
				}
			} else if (ischosen(p_portDesc.binding.mqttBindingDesc)) {
			    v_poa := "mqtt://" & p_portDesc.binding.mqttBindingDesc.bindingDesc.tsAddress;
			    if (ispresent(p_portDesc.binding.mqttBindingDesc.bindingDesc.localPort)) {
			        v_poa := v_poa & ":" & int2str(p_portDesc.binding.mqttBindingDesc.bindingDesc.localPort);
			    }
			} else {
			    v_poa := "ws://" & p_portDesc.binding.wsBindingDesc.bindingDesc.tsAddress;
			    if (ispresent(p_portDesc.binding.wsBindingDesc.bindingDesc.localPort)) {
			        v_poa := v_poa & ":" & int2str(p_portDesc.binding.wsBindingDesc.bindingDesc.localPort);
			    }
			}
			if(p_additionalContext != ""){
				v_poa := v_poa & "/" & p_additionalContext;
			}
			
            return v_poa;
		}
		
		/**
		 * @desc Resolution of the IUT PoA for a given port
		 * @param p_portDesc			Description of port from where PoA will be built
		 * @param p_additionalContext	Additional context
		 * @return PoA for the given port
		 */
		function f_getPoA(in PortDesc p_portDesc := PX_TS_AE1.mcaPort, charstring p_additionalContext := "") return charstring {
			var charstring v_poa;
  
  			log(">>> f_getPoA: ", p_portDesc);
  
			if (ischosen(p_portDesc.binding.httpBindingDesc)) {
				v_poa := "http://" & p_portDesc.binding.httpBindingDesc.bindingDesc.sutAddress;
				if (ispresent(p_portDesc.binding.httpBindingDesc.bindingDesc.remotePort)) {
			    	v_poa := v_poa & ":" & int2str(p_portDesc.binding.httpBindingDesc.bindingDesc.remotePort);
			    }
			} else if (ischosen(p_portDesc.binding.coapBindingDesc)) {
			    v_poa := "coap://" & p_portDesc.binding.coapBindingDesc.bindingDesc.sutAddress;
			    if (ispresent(p_portDesc.binding.coapBindingDesc.bindingDesc.remotePort)) {
			        v_poa := v_poa & ":" & int2str(p_portDesc.binding.coapBindingDesc.bindingDesc.remotePort);
			    }
			} else if (ischosen(p_portDesc.binding.mqttBindingDesc)) {
			    v_poa := "mqtt://" & p_portDesc.binding.mqttBindingDesc.bindingDesc.sutAddress;
			    if (ispresent(p_portDesc.binding.mqttBindingDesc.bindingDesc.remotePort)) {
			        v_poa := v_poa & ":" & int2str(p_portDesc.binding.mqttBindingDesc.bindingDesc.remotePort);
			    }
			} else {
			    v_poa := "ws://" & p_portDesc.binding.wsBindingDesc.bindingDesc.sutAddress;
			    if (ispresent(p_portDesc.binding.wsBindingDesc.bindingDesc.remotePort)) {
			        v_poa := v_poa & ":" & int2str(p_portDesc.binding.wsBindingDesc.bindingDesc.remotePort);
			    }
			}
			if(p_additionalContext != ""){
				v_poa := v_poa & "/" & p_additionalContext;
			}
			
			return v_poa;
		}

		/**
		 * @desc Resolution of the local resource index for a given resource address (URI)
		 * @param p_address	Resource URI (can be structured/unstructured cseRelative/spRelative/absolute)
		 * @return Internal resource index of the given resource or -1 in case of error
		 */
		function f_getLocalResourceIndex(in XSD.ID p_receivedURI) runs on CseSimu return integer {
			var integer v_resourceIndex := -1;
			var integer i;
			var XSD.ID v_cleanedURI;
			
			v_cleanedURI := f_resourceIdCleaner(p_receivedURI);
			
			if (v_cleanedURI == "-") {
				v_cleanedURI := f_getResourceName(vc_localResourcesList[vc_cSEBaseIndex].resource);
			}
			
			if (f_isHierarchical(p_receivedURI)) {
				
				log("Hierarchical method: " & v_cleanedURI);
				for(i:=0; i < lengthof(vc_localResourcesList); i := i+1){
					
					if(v_cleanedURI == f_getResourceName(vc_localResourcesList[i].resource)){
						v_resourceIndex := i;
						break;
					}		
				}
    		
			} else {
				
				for(i:=0; i < lengthof(vc_localResourcesList); i := i+1){
					if(v_cleanedURI == f_getResourceId(vc_localResourcesList[i].resource)){
						v_resourceIndex := i;
						log("Non Hierarchical method: " & v_cleanedURI);
						break;
					} 
				}
			}
			log("Resource index found: " & int2str(v_resourceIndex));
			//Try CSEBase
			if(v_resourceIndex == -1) {
				if(v_cleanedURI == f_getResourceName(vc_localResourcesList[vc_cSEBaseIndex].resource)) {
					log("Hierarchical method: " & v_cleanedURI);
					v_resourceIndex := vc_cSEBaseIndex;
				} else if (v_cleanedURI == f_getResourceId(vc_localResourcesList[vc_cSEBaseIndex].resource)) {
					log("Non Hierarchical method: " & v_cleanedURI);
					v_resourceIndex := vc_cSEBaseIndex;
				} else if (p_receivedURI == vc_localResourcesList[vc_cSEBaseIndex].resource.cSEBase.cSE_ID) {
					log("Non Hierarchical method: " & p_receivedURI);
					v_resourceIndex := vc_cSEBaseIndex;
				}
			}
			log("Resource index found: " & int2str(v_resourceIndex));
			return v_resourceIndex;
		}
    		
		/**
		 * @desc Resolution of the resource index for a given resource address (URI)
		 * @param p_address	Resource URI (can be structured/unstructured cseRelative/spRelative/absolute)
		 * @return Internal resource index of the given resource or -1 in case of error
		 */
		function f_getResourceIndex(in XSD.ID p_receivedURI) runs on Tester return integer {
			var integer v_resourceIndex := -1;
			var integer i;
			var XSD.ID v_cleanedURI;
			
			v_cleanedURI := f_resourceIdCleaner(p_receivedURI);
			
			if (f_isHierarchical(p_receivedURI)) {
				
				log("Hierarchical method: " & v_cleanedURI);
				for(i:=0; i < lengthof(vc_resourcesList); i := i+1){
					
					if(v_cleanedURI == f_getResourceName(vc_resourcesList[i].resource)){
						v_resourceIndex := i;
						break;
					}		
				}
    		
			} else {
				
				for(i:=0; i < lengthof(vc_resourcesList); i := i+1){
					if(v_cleanedURI == f_getResourceId(vc_resourcesList[i].resource)){
						v_resourceIndex := i;
						log("Non Hierarchical method: " & v_cleanedURI);
						break;
					} 
				}
			}
			log("Resource index found: " & int2str(v_resourceIndex));
			return v_resourceIndex;
		}

		/**
		 * @desc Resolution of the resource address field (to) for a given resource depending on addressing and hierarchical format 
		 * @param p_targetResourceIndex Internal resource index of the given resource
		 * @return Resource address for the given resource
		 * @verdict 
		 */
		function f_getResourceAddress(integer  p_targetResourceIndex := -1, AddressingMethod p_addressingMethod := PX_ADDRESSING_METHOD, PrimitiveScope p_primitiveScope := PX_PRIMITIVE_SCOPE) runs on Tester return XSD.ID {
			var XSD.ID v_resourceAddress;
			
			if(p_primitiveScope == e_cseRelative) {
					
				if(p_addressingMethod == e_nonHierarchical) {
					if(p_targetResourceIndex == -1) {
						return PX_CSE_RESOURCE_ID;
					} else {
						return f_getResourceId(vc_resourcesList[p_targetResourceIndex].resource);
					}
				} else if (p_addressingMethod == e_hierarchical){
					if(p_targetResourceIndex == -1) {
						return PX_CSE_NAME;
					} else {
						v_resourceAddress := f_getResourceAddress(vc_resourcesList[p_targetResourceIndex].parentIndex, p_addressingMethod, p_primitiveScope) & "/" & f_getResourceName(vc_resourcesList[p_targetResourceIndex].resource);
						return v_resourceAddress;
					}	
				} else {
					if(p_targetResourceIndex == -1) {
						return PX_CSE_RESOURCE_ID;
					} else {
						v_resourceAddress := f_getResourceAddress(vc_resourcesList[p_targetResourceIndex].parentIndex, e_nonHierarchical, p_primitiveScope) & "/" & f_getResourceName(vc_resourcesList[p_targetResourceIndex].resource);
						return v_resourceAddress;
					}	
				}
					
			} else if (p_primitiveScope == e_spRelative) {
				if(p_addressingMethod == e_nonHierarchical) {
					if(p_targetResourceIndex == -1) {
						return PX_CSE_ID & "/" & PX_CSE_RESOURCE_ID;
					} else {
						v_resourceAddress := PX_CSE_ID & "/" & f_getResourceId(vc_resourcesList[p_targetResourceIndex].resource);
						return v_resourceAddress;
					}
				} else if (p_addressingMethod == e_hierarchical){
					if(p_targetResourceIndex == -1) {
						return PX_CSE_ID & "/" & PX_CSE_NAME;
					} else {
						v_resourceAddress := f_getResourceAddress(vc_resourcesList[p_targetResourceIndex].parentIndex, p_addressingMethod, p_primitiveScope) & "/" & f_getResourceName(vc_resourcesList[p_targetResourceIndex].resource);
						return v_resourceAddress;
					}
				} else {
					if(p_targetResourceIndex == -1) {
						return PX_CSE_ID & "/" & PX_CSE_RESOURCE_ID;
					} else {
						v_resourceAddress := f_getResourceAddress(vc_resourcesList[p_targetResourceIndex].parentIndex, e_nonHierarchical, p_primitiveScope) & "/" & f_getResourceName(vc_resourcesList[p_targetResourceIndex].resource);
						return v_resourceAddress;
					}	
				}
			} else if (p_primitiveScope ==  e_absolute) {
				if(p_addressingMethod == e_nonHierarchical) {
					if(p_targetResourceIndex == -1) {
						return PX_SP_ID & PX_CSE_ID & "/" & PX_CSE_RESOURCE_ID;
					} else {
						v_resourceAddress := PX_SP_ID & PX_CSE_ID & "/" & f_getResourceId(vc_resourcesList[p_targetResourceIndex].resource);
						return v_resourceAddress;
					}
				} else if (p_addressingMethod == e_hierarchical){
					if(p_targetResourceIndex == -1) {
						return PX_SP_ID & PX_CSE_ID & "/" & PX_CSE_NAME;
					} else {
						v_resourceAddress := f_getResourceAddress(vc_resourcesList[p_targetResourceIndex].parentIndex, p_addressingMethod, p_primitiveScope) & "/" & f_getResourceName(vc_resourcesList[p_targetResourceIndex].resource);
						return v_resourceAddress;
					}	
				} else {
					if(p_targetResourceIndex == -1) {
						return PX_SP_ID & PX_CSE_ID & "/" & PX_CSE_RESOURCE_ID;
					} else {
						v_resourceAddress := f_getResourceAddress(vc_resourcesList[p_targetResourceIndex].parentIndex, e_nonHierarchical, p_primitiveScope) & "/" & f_getResourceName(vc_resourcesList[p_targetResourceIndex].resource);
						return v_resourceAddress;
					}	
				}
			} else {
				return "";
			}
				
		}
		
		/**
		 * @desc Resolution of the resource address field (to) for a given resource depending on addressing and hierarchical format 
		 * @param p_targetResourceIndex Internal resource index of the given resource
		 * @return Resource address for the given resource
		 * @verdict 
		 */
		function f_getLocalResourceAddress(integer  p_targetResourceIndex := 0, AddressingMethod p_addressingMethod := PX_ADDRESSING_METHOD, PrimitiveScope p_primitiveScope := PX_PRIMITIVE_SCOPE) runs on CseSimu return XSD.ID { //TODO vc_cSEBaseIndex, AddressingMethod p_addressingMethod := PX_ADDRESSING_METHOD, PrimitiveScope p_primitiveScope := PX_PRIMITIVE_SCOPE) runs on CseSimu return XSD.ID {
			var XSD.ID v_resourceAddress;
			
			if(p_primitiveScope == e_cseRelative) {
					
				if(p_addressingMethod == e_nonHierarchical) {
					if(p_targetResourceIndex == 0) {
						return vc_cseSimuDesc.cseResourceId;
					} else {
						return f_getResourceId(vc_localResourcesList[p_targetResourceIndex].resource);
					}
				} else {
					if(p_targetResourceIndex == 0) {
						return vc_cseSimuDesc.cseName;
					} else {
						v_resourceAddress := f_getLocalResourceAddress(vc_localResourcesList[p_targetResourceIndex].parentIndex, p_addressingMethod, p_primitiveScope) & "/" & f_getResourceName(vc_localResourcesList[p_targetResourceIndex].resource);
						return v_resourceAddress;
					}	
				}
					
			} else if (p_primitiveScope == e_spRelative) {
				if(p_addressingMethod == e_nonHierarchical) {
					if(p_targetResourceIndex == 0) {
						return vc_cseSimuDesc.cseId & "/" & vc_cseSimuDesc.cseResourceId;
					} else {
						v_resourceAddress := vc_cseSimuDesc.cseId & "/" & f_getResourceId(vc_localResourcesList[p_targetResourceIndex].resource);
						return v_resourceAddress;
					}
				} else {
					if(p_targetResourceIndex == 0) {
						return vc_cseSimuDesc.cseId & "/" & vc_cseSimuDesc.cseName;
					} else {
						v_resourceAddress := f_getLocalResourceAddress(vc_localResourcesList[p_targetResourceIndex].parentIndex, p_addressingMethod, p_primitiveScope) & "/" & f_getResourceName(vc_localResourcesList[p_targetResourceIndex].resource);
						return v_resourceAddress;
					}
				}
			} else if (p_primitiveScope ==  e_absolute) {
				if(p_addressingMethod == e_nonHierarchical) {
					if(p_targetResourceIndex == 0) {
						return vc_cseSimuDesc.spId & vc_cseSimuDesc.cseId & "/" & vc_cseSimuDesc.cseResourceId;
					} else {
						v_resourceAddress := vc_cseSimuDesc.spId & vc_cseSimuDesc.cseId & "/" & f_getResourceId(vc_localResourcesList[p_targetResourceIndex].resource);
						return v_resourceAddress;
					}
				} else {
					if(p_targetResourceIndex == 0) {
						return vc_cseSimuDesc.spId & vc_cseSimuDesc.cseId & "/" & vc_cseSimuDesc.cseName;
					} else {
						v_resourceAddress := f_getLocalResourceAddress(vc_localResourcesList[p_targetResourceIndex].parentIndex, p_addressingMethod, p_primitiveScope) & "/" & f_getResourceName(vc_localResourcesList[p_targetResourceIndex].resource);
						return v_resourceAddress;
					}	
				}				
			} else {
				return "";
			}
				
		}

		/**
		 * @desc Retrieve Announced Resource Type from the given resource type
		 * @param p_targetResourceIndex Internal resource index of the given resource
		 * @return AE_ID of the given resource
		 */
		function f_getAnnouncedResourceType(in ResourceType p_resourceType) runs on Tester return ResourceType {
			
			if(p_resourceType == int1) {
				return int10001;
			}
			else if(p_resourceType == int2) {
				return int10002;
			}
			else if(p_resourceType == int3) {
				return int10003;
			}
			else if(p_resourceType == int4) {
				return int10004;
			}
			else if(p_resourceType == int5) {
				return int10005;
			}
			else if(p_resourceType == int9) {
				return int10009;
			}
			else if(p_resourceType == int29) {
				return int10029;
			}
			else if(p_resourceType == int30) {
				return int10030;
			}
			
			return p_resourceType;
			
		} // end f_getAnnouncedResourceType		
		
		/**
		 * @desc Retrieve Time from a given timestamp
		 * @param p_timestamp Given timestamp
		 * @return Time
		 */
		function f_getTime(charstring p_timestamp) runs on Tester return integer {
			
			var charstring v_time := "";
			var integer i;
			
			for(i := 9; i <= 14; i := i+1){
					v_time := v_time & p_timestamp[i];
			}
			return str2int(v_time);
			
		} // end f_getTime
		
		/**
		 * @desc Retrieve Year from a given timestamp
		 * @param p_timestamp Given timestamp
		 * @return Year
		 */
		function f_getYear(charstring p_timestamp) runs on Tester return integer {
			
			var charstring v_year := "";
			var integer i;
			
			for(i := 0; i <= 3; i := i+1){
				v_year := v_year & p_timestamp[i];
			}
			return str2int(v_year);
			
		} // end f_getYear
		
		/**
		 * @desc Retrieve Month from a given timestamp
		 * @param p_timestamp Given timestamp
		 * @return Year
		 */
		function f_getMonth(charstring p_timestamp) runs on Tester return integer {
			
			var charstring v_month := "";
			var integer i;
			
			for(i := 4; i <= 5; i := i+1){
					v_month := v_month & p_timestamp[i];
				}
			return str2int(v_month);
			
		} // end f_getYear
		
		/**
		 * @desc Retrieve IP address from a given address which includes port information separated by :
		 * @param p_portDesc Given address
		 * @return IPv4 Address
		 */
		function f_getIpv4Address(in PortDesc p_portDesc) runs on Tester return charstring {
			var charstring v_ipv4Address := "";
			
      if (ischosen(p_portDesc.binding.httpBindingDesc)) {
        v_ipv4Address := p_portDesc.binding.httpBindingDesc.bindingDesc.tsAddress;
      } else if (ischosen(p_portDesc.binding.coapBindingDesc)) {
        v_ipv4Address := p_portDesc.binding.coapBindingDesc.bindingDesc.tsAddress;
      } else if (ischosen(p_portDesc.binding.mqttBindingDesc)) {
        v_ipv4Address := p_portDesc.binding.mqttBindingDesc.bindingDesc.tsAddress;
      } else {
        v_ipv4Address := p_portDesc.binding.wsBindingDesc.bindingDesc.tsAddress;
      }
			
			return v_ipv4Address;
			
		} // end f_getIpv4Address
		
		/**
		  * @desc	Get the CSE-ID of the target CSE 
		  * @return	CSE-ID
		  */
		function f_getTargetCseId(in XSD.ID p_resourceID) runs on Tester return XSD.ID {
			var integer v_length := lengthof(p_resourceID);
			var integer i;
			var XSD.ID result := "";
			
			if(f_isScopeSpRelative(p_resourceID)) {
				//log("p_resourceID: " & p_resourceID);
				for (i := 0; i < v_length; i := i + 1 ){
					if ((p_resourceID[i]=="/") and (i != 0)){
						//log("result: " & result);
						return result;
					}
					else{
						result := result & p_resourceID[i];
					}	
				}
			} //TODO Extend to absolute scope
			//log("result: " & result);
			return result;
		}

		/**
		 * @desc Saving of a resource and its parent index in the internal resource list
		 * @param p_resource Resource to be saved
		 * @param p_parentIndex Parent index of resource to be saved
		 * @return Internal resource index of the saved resource
		 * @verdict 
		 */
		function f_setResource(PrimitiveContent p_resource, ResourceType p_resourceType, integer  p_parentIndex := -1, in boolean p_resourceToBeDeleted := true) runs on Tester return integer {
			var integer v_newIndex := -1;	
			if(isbound(vc_resourcesList)) {
				vc_resourcesList[lengthof(vc_resourcesList)] := {p_parentIndex, p_resourceType, p_resource};
			} else {
				vc_resourcesList[0] := {p_parentIndex, p_resourceType, p_resource};
			}
			
			v_newIndex := lengthof(vc_resourcesList)-1;
			if(p_resourceToBeDeleted) {
				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};
				}
			}
			
			return v_newIndex;
						
		}
		
		/**
		 * @desc Saving of a local resource and its parent index in the internal resource list
		 * @param p_resource Resource to be saved
		 * @param p_parentIndex Parent index of resource to be saved
		 * @return Internal resource index of the saved resource
		 * @verdict 
		 */
		function f_setLocalResource(PrimitiveContent p_resource, ResourceType p_resourceType, integer  p_parentIndex := 0) runs on CseSimu return integer { //vc_cSEBaseIndex) runs on CseSimu return integer {
			var integer v_newIndex := -1;	
			if(isbound(vc_localResourcesList)) {
				vc_localResourcesList[lengthof(vc_localResourcesList)] := {p_parentIndex, p_resourceType, p_resource};
			} else {
				vc_localResourcesList[0] := {p_parentIndex, p_resourceType, p_resource};
			}
	
			v_newIndex := lengthof(vc_localResourcesList)-1;
	
			return v_newIndex;
				
		}
		
		/**
		 * @desc Set Acpid into the requestPrimitive
		 * @param p_requestPrimitive RequestPrimitive to be modified
		 * @param p_accessControlPolicyIDs AcpId to be set
		 * @return 
		 * @verdict 
		 */
		function f_setAcpId(template RequestPrimitive p_requestPrimitive, template AcpType p_accessControlPolicyIDs) runs on Tester return RequestPrimitive{
	
			if (ischosen(p_requestPrimitive.primitiveContent.aE)){
				p_requestPrimitive.primitiveContent.aE.accessControlPolicyIDs := p_accessControlPolicyIDs;
			}
			else if (ischosen(p_requestPrimitive.primitiveContent.container)){
				p_requestPrimitive.primitiveContent.container.accessControlPolicyIDs := p_accessControlPolicyIDs;
			}
			else if (ischosen(p_requestPrimitive.primitiveContent.containerAnnc)){
				p_requestPrimitive.primitiveContent.containerAnnc.accessControlPolicyIDs := p_accessControlPolicyIDs;
			}
			else if (ischosen(p_requestPrimitive.primitiveContent.group_)){
				p_requestPrimitive.primitiveContent.group_.accessControlPolicyIDs := p_accessControlPolicyIDs;
			}
			else if (ischosen(p_requestPrimitive.primitiveContent.groupAnnc)){
				p_requestPrimitive.primitiveContent.groupAnnc.accessControlPolicyIDs := p_accessControlPolicyIDs;
			}
			else if (ischosen(p_requestPrimitive.primitiveContent.serviceSubscribedAppRule)){
				p_requestPrimitive.primitiveContent.serviceSubscribedAppRule.accessControlPolicyIDs := p_accessControlPolicyIDs;
			}
			else if (ischosen(p_requestPrimitive.primitiveContent.subscription)){
				p_requestPrimitive.primitiveContent.subscription.accessControlPolicyIDs := p_accessControlPolicyIDs;
			}
			else if (ischosen(p_requestPrimitive.primitiveContent.locationPolicy)){
				p_requestPrimitive.primitiveContent.locationPolicy.accessControlPolicyIDs := p_accessControlPolicyIDs;
			}
			else if (ischosen(p_requestPrimitive.primitiveContent.delivery)){
				p_requestPrimitive.primitiveContent.delivery.accessControlPolicyIDs := p_accessControlPolicyIDs;
			}
			else if (ischosen(p_requestPrimitive.primitiveContent.mgmtCmd)){
				p_requestPrimitive.primitiveContent.mgmtCmd.accessControlPolicyIDs := p_accessControlPolicyIDs;
			}	
			else if (ischosen(p_requestPrimitive.primitiveContent.node)){
				p_requestPrimitive.primitiveContent.node.accessControlPolicyIDs := p_accessControlPolicyIDs;
			}	
			else if (ischosen(p_requestPrimitive.primitiveContent.remoteCSE)){
				p_requestPrimitive.primitiveContent.remoteCSE.accessControlPolicyIDs := p_accessControlPolicyIDs;
			}
			else if (ischosen(p_requestPrimitive.primitiveContent.request)){
				p_requestPrimitive.primitiveContent.request.accessControlPolicyIDs := p_accessControlPolicyIDs;
			}
			else if (ischosen(p_requestPrimitive.primitiveContent.statsCollect)){
				p_requestPrimitive.primitiveContent.statsCollect.accessControlPolicyIDs := p_accessControlPolicyIDs;
			}
			else if (ischosen(p_requestPrimitive.primitiveContent.statsConfig)){
				p_requestPrimitive.primitiveContent.statsConfig.accessControlPolicyIDs := p_accessControlPolicyIDs;
			} 
			else if (ischosen(p_requestPrimitive.primitiveContent.timeSeries)){
				p_requestPrimitive.primitiveContent.timeSeries.accessControlPolicyIDs := p_accessControlPolicyIDs;
			}
			else if (ischosen(p_requestPrimitive.primitiveContent.timeSeriesAnnc)){
				p_requestPrimitive.primitiveContent.timeSeriesAnnc.accessControlPolicyIDs := p_accessControlPolicyIDs;
			}
			else {
				log( __SCOPE__ & ":INFO: Resource not having acpi attribute. Not possible to set acpi")
			}
			return valueof(p_requestPrimitive);					
		}

		/**
		 * @desc Set parentID into the resource
		 * @param p_resource Resource to be modified
		 * @param p_parentID ParentID to be set
		 * @return 
		 * @verdict 
		 */
		function f_setParentID(PrimitiveContent p_resource, XSD.ID p_parentID) runs on Tester return PrimitiveContent {
	
			if (ischosen(p_resource.aE)){
				p_resource.aE.parentID := p_parentID;
			}
			else if (ischosen(p_resource.accessControlPolicy)){
				p_resource.accessControlPolicy.parentID := p_parentID;
			}
			else if (ischosen(p_resource.accessControlPolicyAnnc)){
				p_resource.accessControlPolicyAnnc.parentID := p_parentID;
			}
			else if (ischosen(p_resource.container)){
				p_resource.container.parentID := p_parentID;
			}
			else if (ischosen(p_resource.containerAnnc)){
				p_resource.containerAnnc.parentID := p_parentID;
			}
			else if (ischosen(p_resource.group_)){
				p_resource.group_.parentID := p_parentID;
			}
			else if (ischosen(p_resource.groupAnnc)){
				p_resource.groupAnnc.parentID := p_parentID;
			}
			else if (ischosen(p_resource.serviceSubscribedAppRule)){
				p_resource.serviceSubscribedAppRule.parentID := p_parentID;
			}
			else if (ischosen(p_resource.subscription)){
				p_resource.subscription.parentID := p_parentID;
			}
			else if (ischosen(p_resource.locationPolicy)){
				p_resource.locationPolicy.parentID := p_parentID;
			}
			else if (ischosen(p_resource.delivery)){
				p_resource.delivery.parentID := p_parentID;
			}
			else if (ischosen(p_resource.mgmtCmd)){
				p_resource.mgmtCmd.parentID := p_parentID;
			}	
			else if (ischosen(p_resource.node)){
				p_resource.node.parentID := p_parentID;
			}	
			else if (ischosen(p_resource.remoteCSE)){
				p_resource.remoteCSE.parentID := p_parentID;
			}
			else if (ischosen(p_resource.remoteCSE)){
				p_resource.remoteCSE.parentID := p_parentID;
			}
			else if (ischosen(p_resource.request)){
				p_resource.request.parentID := p_parentID;
			}
			else if (ischosen(p_resource.statsCollect)){
				p_resource.statsCollect.parentID := p_parentID;
			}
			else if (ischosen(p_resource.statsConfig)){
				p_resource.statsConfig.parentID := p_parentID;
			}
			else if (ischosen(p_resource.timeSeries)){
				p_resource.timeSeries.parentID := p_parentID;
			}
			else if (ischosen(p_resource.timeSeriesAnnc)){
				p_resource.timeSeriesAnnc.parentID := p_parentID;
			} 
			else {
				log( __SCOPE__, ":INFO: Resource not having acpi attribute. Not possible to set acpi")
			}
			return valueof(p_resource);					
		}
 
		/**
			@desc Set protocol binding and host for the given ports
			@param p_sendingPort Config parameters of sending port
			@param p_receivingPort Config parameters of receiving port
			@param p_protocolBindingOut Protocol binding for sending port
			@param p_targetIutAddress Target IUT address
			@param p_protocolBindingIn	Protocol binding for receiving port
		*/
		function f_setProtocolBinding(in PortDesc p_sendingPort, in PortDesc p_receivingPort, out charstring p_protocolBindingOut, out charstring p_targetIutAddress, out charstring p_protocolBindingIn) runs on Tester {

	
	
			if (ischosen(p_sendingPort.binding.httpBindingDesc)) { // FIXME Create a function to initialize vc_myInterfaces
				p_protocolBindingOut := "HTTP";
				p_targetIutAddress := p_sendingPort.binding.httpBindingDesc.bindingDesc.sutAddress & ":" & int2str(p_sendingPort.binding.httpBindingDesc.bindingDesc.remotePort); 
			} else if (ischosen(p_sendingPort.binding.coapBindingDesc)) {
				p_protocolBindingOut := "COAP";
				p_targetIutAddress := p_sendingPort.binding.coapBindingDesc.bindingDesc.sutAddress & ":" & int2str(p_sendingPort.binding.coapBindingDesc.bindingDesc.remotePort);
			} else if (ischosen(p_sendingPort.binding.mqttBindingDesc)) {
				p_protocolBindingOut := "MQTT";
				p_targetIutAddress := p_sendingPort.binding.mqttBindingDesc.bindingDesc.sutAddress & ":" & int2str(p_sendingPort.binding.mqttBindingDesc.bindingDesc.remotePort);
			} else {
				p_protocolBindingOut := "WSCK";
				p_targetIutAddress := p_sendingPort.binding.wsBindingDesc.bindingDesc.sutAddress & ":" & int2str(p_sendingPort.binding.wsBindingDesc.bindingDesc.remotePort);
			}
     	 	
     	 	if (ischosen(p_receivingPort.binding.httpBindingDesc)) {
				p_protocolBindingIn := "HTTP";
		    } else if (ischosen(p_receivingPort.binding.coapBindingDesc)) {
				p_protocolBindingIn := "COAP";
		    } else if (ischosen(p_receivingPort.binding.mqttBindingDesc)) {
				p_protocolBindingIn := "MQTT";
		    } else {
				p_protocolBindingIn := "WSCK";
		    }
								
		} // end f_setProtocolBinding

		/**
		 * @desc Set link into the aanounced resource
		 * @param p_resource Resource to be modified
		 * @param p_link Resource address to be set
		 * @return 
		 * @verdict 
		 */
		function f_setLink(PrimitiveContent p_resource, XSD.ID p_link) runs on Tester return PrimitiveContent {
			
			if (ischosen(p_resource.aEAnnc)){
				p_resource.aEAnnc.link := p_link;
			}
			else if (ischosen(p_resource.accessControlPolicyAnnc)){
				p_resource.accessControlPolicyAnnc.link := p_link;
			}
			else if (ischosen(p_resource.containerAnnc)){
				p_resource.containerAnnc.link := p_link;
			}
			else if (ischosen(p_resource.contentInstanceAnnc)){
				p_resource.contentInstanceAnnc.link := p_link;
			}
			else if (ischosen(p_resource.cSEBaseAnnc)){
				p_resource.cSEBaseAnnc.link := p_link;
			}
			else if (ischosen(p_resource.groupAnnc)){
				p_resource.groupAnnc.link := p_link;
			}
			else if (ischosen(p_resource.remoteCSEAnnc)){
				p_resource.remoteCSEAnnc.link := p_link;
			}
			else if (ischosen(p_resource.scheduleAnnc)){
				p_resource.scheduleAnnc.link := p_link;
			} 
			else if (ischosen(p_resource.timeSeriesAnnc)){
				p_resource.timeSeriesAnnc.link := p_link;
			} 
			else if (ischosen(p_resource.timeSeriesInstanceAnnc)){
				p_resource.timeSeriesInstanceAnnc.link := p_link;
			} 
			else {
				log( __SCOPE__, ":INFO: Resource not having link attribute. Not possible to set link")
			}
			return valueof(p_resource);					
		}

		/**
		 * @desc Set expirationTime into the aanounced resource
		 * @param p_resource Resource to be modified
		 * @param p_originalResource Original resource from where to get the expirationTime
		 * @return 
		 * @verdict 
		 */
		function f_setExpirationTime(PrimitiveContent p_resource, PrimitiveContent p_originalResource) runs on Tester return PrimitiveContent {
	
			if (ischosen(p_resource.aEAnnc)){
				p_resource.aEAnnc.expirationTime := p_originalResource.aE.expirationTime;
			}
			else if (ischosen(p_resource.accessControlPolicyAnnc)){
				p_resource.accessControlPolicyAnnc.expirationTime := p_originalResource.accessControlPolicy.expirationTime;
			}
			else if (ischosen(p_resource.containerAnnc)){
				p_resource.containerAnnc.expirationTime := p_originalResource.container.expirationTime;
			}
			else if (ischosen(p_resource.groupAnnc)){
				p_resource.groupAnnc.expirationTime := p_originalResource.group_.expirationTime;
			}
			else if (ischosen(p_resource.remoteCSEAnnc)){
				p_resource.remoteCSEAnnc.expirationTime := p_originalResource.remoteCSE.expirationTime;
			}
			else if (ischosen(p_resource.scheduleAnnc)){
				p_resource.scheduleAnnc.expirationTime := p_originalResource.schedule.expirationTime;
			} 
			else if (ischosen(p_resource.timeSeriesAnnc)){
				p_resource.timeSeriesAnnc.expirationTime := p_originalResource.timeSeries.expirationTime;
			} 
			else {
				log( __SCOPE__, ":INFO: Resource not having expirationTime attribute. Not possible to set expirationTime")
			}
			return valueof(p_resource);					
		}

		/**
		 * @desc Checks the nodeLink attribute of a Device Model
		 */
		function f_checkNodeLink(PrimitiveContent p_resource, XSD.AnyURI p_nodeLink) runs on Tester return boolean {
			var boolean v_matchResult := false;
			
			if (ischosen(p_resource.deviceAirConditioner)){
				if (match(valueof(p_resource.deviceAirConditioner.nodeLink), p_nodeLink))
				{
					v_matchResult := true;
				}
			}
			else if (ischosen(p_resource.deviceClothesWasherDryer)){
				if (match(valueof(p_resource.deviceClothesWasherDryer.nodeLink), p_nodeLink))
				{
					v_matchResult := true;
				}
			}
			else if (ischosen(p_resource.deviceElectricVehicleCharger)){
				if (match(valueof(p_resource.deviceElectricVehicleCharger.nodeLink), p_nodeLink))
				{
					v_matchResult := true;
				}
			}
			else if (ischosen(p_resource.deviceLight)){
				if (match(valueof(p_resource.deviceLight.nodeLink), p_nodeLink))
				{
					v_matchResult := true;
				}
			}
			else if (ischosen(p_resource.deviceMicrogeneration)){
				if (match(valueof(p_resource.deviceMicrogeneration.nodeLink), p_nodeLink))
				{
					v_matchResult := true;
				}
			}
			else if (ischosen(p_resource.deviceOven)){
				if (match(valueof(p_resource.deviceOven.nodeLink), p_nodeLink))
				{
					v_matchResult := true;
				}
			}
			else if (ischosen(p_resource.deviceRefrigerator)){
				if (match(valueof(p_resource.deviceRefrigerator.nodeLink), p_nodeLink))
				{
					v_matchResult := true;
				}
			}
			else if (ischosen(p_resource.deviceRobotCleaner)){
				if (match(valueof(p_resource.deviceRobotCleaner.nodeLink), p_nodeLink))
				{
					v_matchResult := true;
				}
			}
			else if (ischosen(p_resource.deviceSmartElectricMeter)){
				if (match(valueof(p_resource.deviceSmartElectricMeter.nodeLink), p_nodeLink))
				{
					v_matchResult := true;
				}
			}
			else if (ischosen(p_resource.deviceStorageBattery)){
				if (match(valueof(p_resource.deviceStorageBattery.nodeLink), p_nodeLink))
				{
					v_matchResult := true;
				}
			}
			else if (ischosen(p_resource.deviceTelevision)){
				if (match(valueof(p_resource.deviceTelevision.nodeLink), p_nodeLink))
				{
					v_matchResult := true;
				}
			}
			else if (ischosen(p_resource.deviceThermostat)){
				if (match(valueof(p_resource.deviceThermostat.nodeLink), p_nodeLink))
				{
					v_matchResult := true;
				}
			}	
			else if (ischosen(p_resource.deviceWaterHeater)){
				if (match(valueof(p_resource.deviceWaterHeater.nodeLink), p_nodeLink))
				{
					v_matchResult := true;
				}
			}	
			else {
				log( __SCOPE__, ":INFO: Resource not having nodeLink attribute.")
			}
			return v_matchResult;	
		}


	}//end group getSetFunctions
	
	group CheckingFunctions {
	
		group ComponentStatus {
		
			/**
			 * @desc Boolean to charstring
			 * @param p_bool
			 * @verdict 
			 */
			function f_checkAeSimuStatus() runs on AeSimu {
				
				if (getverdict != pass) {
					 if ((vc_config == e_cf02CseSimuMaster) or (vc_aeSimuDesc.appId == "NMyApp2Id")) {
						infoPort.send(SyncPoints:e_error);
					 } else {
					 	f_cse_postamble_deleteResources();
						f_cf02DownAe();
					 	kill;
					 }
					 
				/*	 // Tear down
					 if(vc_config == e_cf01) {
					 	f_cf01Down();
					 } else if (vc_config ==e_cf02) {
					 	f_cf02Down();
					 }
					 kill;*/
				} else {
					log(__SCOPE__, ":INFO: AeSimu status OK");
				}
			}
			
			
			/**
			 * @desc Sending of an Adapter Control primitive
			 * @param event Action to be performed by TA
			 * @param data Corresponding information for the correct execution of the given action
			 * @verdict 
			 */
			function f_checkCseSimuStatus() runs on CseSimu {
		
				if (getverdict != pass) {
					if((vc_config == e_cf02) or (vc_cseSimuDesc.cseName == "CSE2_NAME")) {
						infoPort.send(SyncPoints:e_error);
					} else {
						f_cse_postamble_deleteResourcesCSE();
						f_cf02DownCse();
						kill;
					}/*
					// Tear down
					if(vc_config == e_cf03) {
					  f_cf03Down();
					} else if (vc_config ==e_cf04) {
					  f_cf04Down();
					} else if (vc_config == e_cf02CseSimuMaster) {
						f_cf02DownCseSimuMaster();
					}
					kill;*/
				} else {
					log(__SCOPE__, ":INFO: CseSimu status OK");
				}
			}
			
			/**
			 * @desc Sending of an Adapter Control primitive
			 * @param event Action to be performed by TA
			 * @param data Corresponding information for the correct execution of the given action
			 * @verdict 
			 */
			function f_aeSimu_checkComponentDoneAndGetVerdict(Tester p_component) runs on AeSimu {
				
				var verdicttype v_verdict := none;
	
				tc_done.start;
				alt {
					[] p_component.done -> value v_verdict {
						tc_done.stop;
					}
					[] tc_done.timeout {
						setverdict(inconc, __SCOPE__ & "INFO: Component did not finish");
						f_checkAeSimuStatus();
					}
				}			 
				
				if(v_verdict != none) {//Component started at least once (except config)
					if(v_verdict == pass) {         // Component was successfully completed and got stopped state
						setverdict(pass);
					} else {
						setverdict(inconc);            // Component was not completed successfully 
					}
				}
				
				f_checkAeSimuStatus();
			} 
					
			/**
			 * @desc Sending of an Adapter Control primitive
			 * @param event Action to be performed by TA
			 * @param data Corresponding information for the correct execution of the given action
			 * @verdict 
			 */
			function f_cseSimu_checkComponentDoneAndGetVerdict(Tester p_component) runs on CseSimu {
				
				var verdicttype v_verdict := none;
	
				tc_done.start;
				alt {
					[] p_component.done -> value v_verdict {
						tc_done.stop;
					}
					[] tc_done.timeout {
						setverdict(inconc, __SCOPE__ & "INFO: Component did not finish");
					}
				}			 
				
				if(v_verdict == pass) {         // Component was successfully completed and got stopped state
					setverdict(pass);
				} else {
					setverdict(inconc);            // Component was not completed successfully 
				}
				
				f_checkCseSimuStatus();
			} 
			
			/**
			 * @desc Sending of an Adapter Control primitive
			 * @param event Action to be performed by TA
			 * @param data Corresponding information for the correct execution of the given action
			 * @verdict 
			 */
			function f_scefSimu_checkComponentDoneAndGetVerdict(Tester p_component) runs on ScefSimu {
				
				var verdicttype v_verdict := none;
	
				tc_done.start;
				alt {
					[] p_component.done -> value v_verdict {
						tc_done.stop;
					}
					[] tc_done.timeout {
						setverdict(inconc, __SCOPE__ & "INFO: Component did not finish");
					}
				}			 
				
				if(v_verdict == pass) {         // Component was successfully completed and got stopped state
					setverdict(pass);
				} else {
					setverdict(inconc);            // Component was not completed successfully 
				}
				
			} 

		}//end of group ComponentStatus
		
		/**
		 * @desc It determines whether the addressing method of the given address is non-hierarchical. Not valid for CSE-Base as target
		 * @param p_resourceAddress
		 * @return boolean
		 */
		function f_isNonHierarchical(XSD.ID p_resourceAddress) runs on Tester return boolean {	
			var integer i;
			var integer v_nbOfSlashes:= 0;
    			
			for (i := 0; i < lengthof(p_resourceAddress); i:= i+1){
				if(p_resourceAddress[i] == "/"){
					v_nbOfSlashes:= v_nbOfSlashes+1;
				}
			}
				
			if(f_isScopeCseRelative(p_resourceAddress)) {
				if(v_nbOfSlashes == 0 ) {
					return true;
				} else {
					return false;
				}
    				
			} else if (f_isScopeSpRelative(p_resourceAddress)){	
				if((v_nbOfSlashes == 2 ) or (v_nbOfSlashes == 1 )) {
					return true;
				} else {
					return false;
				}
			} else if (f_isScopeAbsolute(p_resourceAddress)){
				if((v_nbOfSlashes == 4 ) or (v_nbOfSlashes == 3 )){
					return true;
				} else {
					return false;
				}
			} else {
			   return false;
			}
		}
			  		
		/**
		 * @desc It determines whether the addressing method of the given address is hierarchical. Not valid for CSE-Base as target
		 * @param p_resourceAddress
		 * @return boolean
		 */
		 function f_isHierarchical(XSD.ID p_resourceAddress) runs on Tester return boolean {
			if(f_isNonHierarchical(p_resourceAddress)) {
				return false;
			} else {
				return true;
			}	
		} 
			
		/**
		 * @desc It determines whether the primitive scope of the given address is CSE-Relative
		 * @param p_resourceAddress
		 * @return boolean
		 */
		function f_isScopeCseRelative(XSD.ID p_resourceAddress) runs on Tester return boolean { 
		  if (p_resourceAddress[0] != "/") {
			return true;
		  } else {
			return false;
		  }
		}
			
		/**
		 * @desc It determines whether the primitive scope of the given address is SP-Relative
		 * @param p_resourceAddress
		 * @return boolean
		 */
		function f_isScopeSpRelative(XSD.ID p_resourceAddress) runs on Tester return boolean {	
			if ((p_resourceAddress[0] == "/") and (p_resourceAddress[1] != "/")){
			  return true;
			} else {
			  return false;
			}
		}
			
		/**
		 * @desc It determines whether the primitive scope of the given address is Absolute
		 * @param p_resourceAddress
		 * @return boolean
		 */
		function f_isScopeAbsolute(XSD.ID p_resourceAddress) runs on Tester return boolean {
			if ((p_resourceAddress[0] == "/") and (p_resourceAddress[1] == "/")) {
			  return true;
			} else {
			  return false;
			}
		}
	
    		
			/**
			 * @desc Checking of returned important attributed (in response) in order to save properly internally
			 * @param p_resourceType ResourceType of the resource to be checked
			 * @param p_request Request primitive used for the CRU operation
			 * @param p_response Response primitive received
			 * @verdict 
			 */
			 //Note: This function will be continously extended with necessary attributes/resources
			function f_checkAttributesToBeSaved (ResourceType p_resourceType, RequestPrimitive p_request, inout ResponsePrimitive p_response) {
				select (p_resourceType) {
					case (int1) {
						if(isvalue(p_response.primitiveContent.accessControlPolicy) and
								not(ispresent(p_response.primitiveContent.accessControlPolicy.resourceName))) {
							p_response.primitiveContent.accessControlPolicy.resourceName :=  p_request.primitiveContent.accessControlPolicy.resourceName;
							log(__SCOPE__ & ":INFO: resourceName not returned. Using the one provided in the request: " & p_request.primitiveContent.accessControlPolicy.resourceName)
						}
					}
					case (int2) {
						if(isvalue(p_response.primitiveContent.aE) and
								not(ispresent(p_response.primitiveContent.aE.resourceName))) {
							p_response.primitiveContent.aE.resourceName :=  p_request.primitiveContent.aE.resourceName;
							log(__SCOPE__ & ":INFO: resourceName not returned. Using the one provided in the request: " & p_request.primitiveContent.aE.resourceName)
						}
					}
					case (int3) {
						if(isvalue(p_response.primitiveContent.container) and
								not(ispresent(p_response.primitiveContent.container.resourceName))) {
							p_response.primitiveContent.container.resourceName :=  p_request.primitiveContent.container.resourceName;
							log(__SCOPE__ & ":INFO: resourceName not returned. Using the one provided in the request: " & p_request.primitiveContent.container.resourceName)
						}
					}
					case (int4) {
						if(isvalue(p_response.primitiveContent.contentInstance) and
								not(ispresent(p_response.primitiveContent.contentInstance.resourceName))) {
							p_response.primitiveContent.contentInstance.resourceName :=  p_request.primitiveContent.contentInstance.resourceName;
							log(__SCOPE__ & ":INFO: resourceName not returned. Using the one provided in the request: " & p_request.primitiveContent.contentInstance.resourceName)
						}
					}
					case (int15) {
						if (isvalue(p_response.primitiveContent.pollingChannel) and
								not(ispresent(p_response.primitiveContent.pollingChannel.resourceName))) {
							p_response.primitiveContent.pollingChannel.resourceName :=  p_request.primitiveContent.pollingChannel.resourceName;
							log(__SCOPE__ & ":INFO: resourceName not returned. Using the one provided in the request: " & p_request.primitiveContent.pollingChannel.resourceName)
						}
					}
					case (int16) {
						if (isvalue(p_response.primitiveContent.remoteCSE) and
								not(ispresent(p_response.primitiveContent.remoteCSE.resourceName))) {
							p_response.primitiveContent.remoteCSE.resourceName :=  p_request.primitiveContent.remoteCSE.resourceName;
							log(__SCOPE__ & ":INFO: resourceName not returned. Using the one provided in the request: " & p_request.primitiveContent.remoteCSE.resourceName)
						}
					}
					case (int18) {
						if (isvalue(p_response.primitiveContent.schedule) and
								not(ispresent(p_response.primitiveContent.schedule.resourceName))) {
							p_response.primitiveContent.schedule.resourceName :=  p_request.primitiveContent.schedule.resourceName;
							log(__SCOPE__ & ":INFO: resourceName not returned. Using the one provided in the request: " & p_request.primitiveContent.schedule.resourceName)
						}
					}
					case (int23) {
						if (isvalue(p_response.primitiveContent.subscription) and
								not(ispresent(p_response.primitiveContent.subscription.resourceName))) {
							p_response.primitiveContent.subscription.resourceName :=  p_request.primitiveContent.subscription.resourceName;
							log(__SCOPE__ & ":INFO: resourceName not returned. Using the one provided in the request: " & p_request.primitiveContent.subscription.resourceName)
						}
					}
					case (int9) {
						if (isvalue(p_response.primitiveContent.group_) and
								not(ispresent(p_response.primitiveContent.group_.resourceName))) {
							p_response.primitiveContent.group_.resourceName :=  p_request.primitiveContent.group_.resourceName;
							log(__SCOPE__ & ":INFO: resourceName not returned. Using the one provided in the request: " & p_request.primitiveContent.group_.resourceName)
						}
					}
					case else {
						log(__SCOPE__&":WARNING: Resource Type "&int2str(enum2int(p_resourceType))&" not implemented");
					}
				}
    
				// TODO test that if the resource name is returned is the same resource name as used in the create message
			}
		
			/**
			 * @desc Comparison of two URIs
			 * @param p_expectedURIIndex Resource index of the resource for which its URI is to be compared
			 * @param p_receivedURI URI to be compared
			 * @param p_response Response primitive received
			 * @verdict 
			 */
			function f_compareURIs(in integer p_expectedURIIndex, in XSD.ID p_receivedURI) runs on Tester return boolean{
				// Local variables
				var boolean v_matchResult := false;
				var AddressingMethod v_addressingMethod;
				var PrimitiveScope v_primitiveScope;
    			
				if (f_isNonHierarchical(p_receivedURI)) {
					v_addressingMethod := e_nonHierarchical;
				} else if (f_isHierarchical(p_receivedURI)) {
					v_addressingMethod := e_hierarchical;
				}
				if (f_isScopeCseRelative(p_receivedURI)) {
					v_primitiveScope := e_cseRelative;
				}
				if (f_isScopeSpRelative(p_receivedURI)) {
					v_primitiveScope := e_spRelative;
				}
				if (f_isScopeAbsolute(p_receivedURI)) {
					v_primitiveScope := e_absolute;
				}
    			
				if(match(f_getResourceAddress(p_expectedURIIndex, v_addressingMethod, v_primitiveScope), p_receivedURI)) {
					v_matchResult := true;
				} else {
					v_matchResult := false;
				}
							
				return v_matchResult;
    
			} //end f_compareURIs	
	
			/**
			 * @desc Checking of notification primitiveContent
			 * @param p_requestPrimitive Received Notification request
			 * @param p_primitiveContent Expected primitiveContent in the notification
			 * @verdict 
			 */
			function f_check_notificationContent(in RequestPrimitive p_requestPrimitive, template PrimitiveContent p_primitiveContent) runs on Tester return boolean{
				// Local variables
				var boolean v_matchResult := false;
				var integer i;
				var integer v_numberOfAggregatedNotification;
	    	
				if (ischosen(p_primitiveContent.aE)){
					
					if(isvalue(p_requestPrimitive.primitiveContent.notification.notificationEvent.representation.resource.aE)) {
						log("Representation contains AE resource representation");
						v_matchResult := match(p_requestPrimitive.primitiveContent.notification.notificationEvent.representation.resource.aE, p_primitiveContent.aE);
					}
					//TODO Probably to be removed these alternatives. Function is checking notification content
					else if(isvalue(p_requestPrimitive.primitiveContent.responsePrimitive.primitiveContent.aE)) {
						log("Request contains a response primitive as content");
						v_matchResult :=match(p_requestPrimitive.primitiveContent.responsePrimitive.primitiveContent.aE, p_primitiveContent.aE);
					}
					else if (isvalue(p_requestPrimitive.primitiveContent.aggregatedNotification.notification_list)) {
						v_matchResult := true;
						v_numberOfAggregatedNotification := lengthof(p_requestPrimitive.primitiveContent.aggregatedNotification.notification_list);
						for(i := 0; i< v_numberOfAggregatedNotification; i := i + 1){
							if(isvalue(p_requestPrimitive.primitiveContent.aggregatedNotification.notification_list[i].notificationEvent.representation.resource.aE)) {
								if(not (match(p_requestPrimitive.primitiveContent.aggregatedNotification.notification_list[i].notificationEvent.representation.resource.aE, p_primitiveContent.aE))){
									v_matchResult := false;
								}
							}						
						}
						if (i == 0){
							v_matchResult := false;
						}
					}
	    
				}
	    	
				if (ischosen(p_primitiveContent.container)){
					if(isvalue(p_requestPrimitive.primitiveContent.notification.notificationEvent.representation.resource.container)) {
						log("Representation contains container resource representation");
						v_matchResult := match(p_requestPrimitive.primitiveContent.notification.notificationEvent.representation.resource.container, p_primitiveContent.container)
					}
					//TODO Probably to be removed these alternatives. Function is checking notification content
					else if(isvalue(p_requestPrimitive.primitiveContent.responsePrimitive.primitiveContent.container)) {
						log("Request contains a response primitive as content");
						v_matchResult := match(p_requestPrimitive.primitiveContent.responsePrimitive.primitiveContent.container, p_primitiveContent.container)
					}
				}
						
				if (ischosen(p_primitiveContent.timeSeries)){
					if(isvalue(p_requestPrimitive.primitiveContent.notification.notificationEvent.representation.resource.timeSeries)) {
						log("Representation contains timeSeries resource representation");
						v_matchResult := match(p_requestPrimitive.primitiveContent.notification.notificationEvent.representation.resource.timeSeries, p_primitiveContent.timeSeries)
					}
					//TODO Probably to be removed these alternatives. Function is checking notification content
					else if(isvalue(p_requestPrimitive.primitiveContent.responsePrimitive.primitiveContent.timeSeries)) {
						log("Request contains a response primitive as content");
						v_matchResult := match(p_requestPrimitive.primitiveContent.responsePrimitive.primitiveContent.timeSeries, p_primitiveContent.timeSeries)
					}
				}
				
				if (ischosen(p_primitiveContent.uRI)){
					if(isvalue(p_requestPrimitive.primitiveContent.notification.notificationEvent.representation.uRI)) {
						log("Representation contains URI element");
						v_matchResult := match(p_requestPrimitive.primitiveContent.notification.notificationEvent.representation.uRI, p_primitiveContent.uRI)
					}
				}
	    	
				return v_matchResult;
	    
			} //end f_check_notificationContent
	
	}//end group CheckingFunctions
	
	group SecurityFunctions {
		
		/**
		 * @desc Establishes a pairwiseESPrimKey between Receiver and Originator
		 */	
		function f_establish_pairwiseESPrimKey() return octetstring {
		
			select (PX_PAIRWISEKEY_METHOD) {
				case (e_establish)
				{
					return f_establish();
				}
				case else 
				{
					return ''O;
				}
			}
		}
		

		function f_establish() return octetstring {
		
			select (PX_KEY_PROVISION) {
				case (e_preProvisioning)
				{
					return PICS_PAIRWISEESPRIMKEY;
				}
				case (e_ESCertKE)
				{
					return f_esCertKE();
				}
				case else 
				{
					return ''O;
				}
			}
		}
		
		function f_esCertKE() return octetstring 
		{
				return ''O;
		}
	
	
		
	}//end group SecurityFunctions
	
	group CommonFunctions {
		
		group AltstepFunctions {

			/**
			  * @desc	Default altstep
			  */
			 altstep a_default() runs on Tester {
			
				[] tc_wait.timeout {
					 setverdict(inconc, __SCOPE__&":INFO: Timeout while awaiting reaction of the IUT prior to Upper Tester action");
				}
				[] tc_ac.timeout {
					setverdict(inconc, __SCOPE__&":INFO: Timeout while awaiting the reception of a message");
				}
			 }				 

		}//end group altstepFunctions
		
		group AcFunctions {
		
			/**
			 * @desc Sending of an Adapter Control primitive
			 * @param event Action to be performed by TA
			 * @param data Corresponding information for the correct execution of the given action
			 * @verdict 
			 */
			function f_sendAcPrimitive(in charstring p_event, in integer p_resourceIndex, template (omit) XSD.ID p_originator := omit) runs on Tester {
				var XSD.ID v_aeResourceAddress;
				var charstring v_spRelativeAeIdForMqtt;
				
				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_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);
						}
						
						if((vc_config == e_cf01) or (((vc_config == e_cf02) or (vc_config == e_cf02CseSimuMaster)) and (vc_testSystemRole == e_ae)) or (vc_config == e_cf03)) {
							if(vc_myInterfaces[enum2int(valueof(InterfaceIds:e_mcaPort))].myProtocolBinding == "MQTT") {
								acPort.send(AcRequestPrimitive:{p_event & "_mcaPort", {charstring := v_spRelativeAeIdForMqtt}});
							}
							if(vc_myInterfaces[enum2int(valueof(InterfaceIds:e_mcaPortIn))].myProtocolBinding == "MQTT") {
								acPort.send(AcRequestPrimitive:{p_event & "_mcaPortIn", {charstring := v_spRelativeAeIdForMqtt}});	
							}
						}
						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_mccPort))].myProtocolBinding == "MQTT") {
								acPort.send(AcRequestPrimitive:{p_event & "_mccPort", {charstring := v_spRelativeAeIdForMqtt}});	
							}
							if(vc_myInterfaces[enum2int(valueof(InterfaceIds:e_mccPortIn))].myProtocolBinding == "MQTT") {
								acPort.send(AcRequestPrimitive:{p_event  & "_mccPortIn", {charstring := v_spRelativeAeIdForMqtt}});	
							}
						}
					}
					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_mccPortIn))].myProtocolBinding == "MQTT") {
								acPort.send(AcRequestPrimitive:{p_event & "_mccPort", {charstring := v_spRelativeAeIdForMqtt}});	
							}
							if(vc_myInterfaces[enum2int(valueof(InterfaceIds:e_mccPortIn))].myProtocolBinding == "MQTT") {
								acPort.send(AcRequestPrimitive:{p_event  & "_mccPortIn", {charstring := v_spRelativeAeIdForMqtt}});	
							}
						}
					}
					case ("MqttSetDefaultTopicToNotRegistration") {
						acPort.send(AcRequestPrimitive:{p_event, {charstring := oct2char(unichar2oct(valueof(p_originator)))}});
					}
					case ("MqttSetDefaultTopicToRegistration") {
						acPort.send(AcRequestPrimitive:{p_event, {charstring := int2str(p_resourceIndex)}});
					}
				} 
			}
		}//end of group AcFunctions
		
		group UtFunctions {
		
			/**
			 * @desc Sending of an Upper Tester primitive
			 * @param p_utRequest Action to be performed by IUT
			 * @param p_action Description of the given action to be performed by the IUT
			 * @verdict 
			 */
			function f_sendUtPrimitive(template UtTriggerPrimitive p_utRequest) runs on Tester {
				
				utPort.send(valueof(p_utRequest));

				tc_wait.start;
				alt{
					[] utPort.receive(mw_utResponseOK) {
						tc_wait.stop;
						setverdict(pass, __SCOPE__ & " : Triggering message is successfully received!");
					}
					[] utPort.receive(mw_utResponseKO) {
						tc_wait.stop;
						setverdict(inconc, __SCOPE__ & " : Error while receiving Triggering message!");
					}
					[] tc_wait.timeout{
						setverdict(inconc, __SCOPE__ & " : Timeout due to no response received from requested SUT!");
					}
				}
			}

		}//end of group UtFunctions
		
		
		/**
		 * @desc   Proccessing of the CREATE request primitive
		 * @param  p_request          Request primitive to be processed
		 * @return Local resource index
		 */
		function f_processCreateRequestPrimitive(in RequestPrimitive p_request, in ResponseStatusCode p_responseStatusCode := int2001, template(omit) integer p_expectedParentResourceIndex := omit) runs on CseSimu return integer {			
			var integer v_parentIndex := -1;
			var integer v_localResourceIndex := -1;
			var PrimitiveContent v_localResource;
				
			v_parentIndex := f_getLocalResourceIndex(p_request.to_);
			vc_response.primitive.responsePrimitive := valueof(m_responsePrimitive(p_responseStatusCode,p_request.requestIdentifier));
			if(v_parentIndex == -1) {
				log(__SCOPE__&": ERROR: Target resource not found");
				vc_response.primitive.responsePrimitive.responseStatusCode := int4004;
		
			} else {
				if(isvalue(p_expectedParentResourceIndex)){
					if(valueof(p_expectedParentResourceIndex) != v_parentIndex){
						setverdict(inconc, __SCOPE__ & ":ERROR: Unexpected Parent Resource Address");
						vc_response.primitive.responsePrimitive.responseStatusCode := int4000;
						return v_localResourceIndex;
					} else {
						setverdict(pass, __SCOPE__ & ":INFO: Expected Parent Resource Address");
					}	
				}
				if(p_responseStatusCode == int2001) {
					setverdict(pass, __SCOPE__&":INFO: Resource created successfuly");
					v_localResource := f_generateLocalResource(p_request.primitiveContent, v_parentIndex, p_request.resourceType);
					if(p_request.resourceType == int16){
						v_localResource.remoteCSE.cSE_ID := p_request.from_;
					}
					v_localResourceIndex := f_setLocalResource(v_localResource, p_request.resourceType, v_parentIndex);
					vc_response.primitive.responsePrimitive.primitiveContent := vc_localResourcesList[v_localResourceIndex].resource;
				} else {
					setverdict(pass, __SCOPE__&":INFO: Resource creation rejected");
				}
			}
			vc_response.primitive.responsePrimitive.from_ := vc_cseSimuDesc.cseId;
			vc_response.primitive.responsePrimitive.to_ := p_request.from_;
				
			return v_localResourceIndex;
		}
		
		/**
		 * @desc   Proccessing of the UPDATE request primitive
		 * @param  p_request          Request primitive to be processed
		 */
		function f_processUpdateRequestPrimitive(in RequestPrimitive p_request, in ResponseStatusCode p_responseStatusCode := int2004, template(omit) integer p_expectedTargetResourceIndex := omit, template (omit) AttributeList_1 p_nullFields := omit) runs on CseSimu return integer {			
			var integer v_targetLocalResourceIndex := -1;
				
			v_targetLocalResourceIndex := f_getLocalResourceIndex(p_request.to_);
			vc_response.primitive.responsePrimitive := valueof(m_responsePrimitive(p_responseStatusCode,p_request.requestIdentifier));
			if(v_targetLocalResourceIndex == -1) {
				log(__SCOPE__&": ERROR: Target resource not found");
				vc_response.primitive.responsePrimitive.responseStatusCode := int4004;
			} else {
				if(isvalue(p_expectedTargetResourceIndex)){
					if(valueof(p_expectedTargetResourceIndex) != v_targetLocalResourceIndex){
						setverdict(inconc, __SCOPE__ & ":ERROR: Unexpected Target Resource Address");
						vc_response.primitive.responsePrimitive.responseStatusCode := int4000;
						return v_targetLocalResourceIndex;
					} else {
						setverdict(pass, __SCOPE__ & ":INFO: Expected Target Resource Address");
					}	
				}
				if(p_responseStatusCode == int2004) {
					setverdict(pass, __SCOPE__&":INFO: Resource updated successfuly");
					f_updateLocalResource(v_targetLocalResourceIndex, p_request.primitiveContent, p_nullFields);
					vc_response.primitive.responsePrimitive.primitiveContent := vc_localResourcesList[v_targetLocalResourceIndex].resource;
				} else {
					setverdict(pass, __SCOPE__&":INFO: Resource update rejected");
				}
			}
			vc_response.primitive.responsePrimitive.from_ := vc_cseSimuDesc.cseId;
			vc_response.primitive.responsePrimitive.to_ := p_request.from_;
		
			return v_targetLocalResourceIndex;
		}
	
		/**
		 * @desc   Proccessing of the RETRIEVE request primitive
		 * @param  p_request          Request primitive to be processed
		 */
		function f_processRetrieveRequestPrimitive(in RequestPrimitive p_request, in ResponseStatusCode p_responseStatusCode := int2000, template(omit) integer p_expectedTargetResourceIndex := omit) runs on CseSimu return integer {			
			var integer v_targetLocalResourceIndex := -1;
				
			v_targetLocalResourceIndex := f_getLocalResourceIndex(p_request.to_);
			vc_response.primitive.responsePrimitive := valueof(m_responsePrimitive(p_responseStatusCode,p_request.requestIdentifier));
			if(v_targetLocalResourceIndex == -1) {
				log(__SCOPE__&": ERROR: Target resource not found");
				vc_response.primitive.responsePrimitive.responseStatusCode := int4004;
			} else {
				if(isvalue(p_expectedTargetResourceIndex)){
					if(valueof(p_expectedTargetResourceIndex) != v_targetLocalResourceIndex){
						setverdict(inconc, __SCOPE__ & ":ERROR: Unexpected Target Resource Address");
						vc_response.primitive.responsePrimitive.responseStatusCode := int4000;
						return v_targetLocalResourceIndex;
					} else {
						setverdict(pass, __SCOPE__ & ":INFO: Expected Target Resource Address");
					}	
				}
				if(p_responseStatusCode == int2000) {
				setverdict(pass, __SCOPE__&":INFO: Resource retrieved successfuly");
					vc_response.primitive.responsePrimitive.primitiveContent := vc_localResourcesList[v_targetLocalResourceIndex].resource;
				} else {
					setverdict(pass, __SCOPE__&":INFO: Resource retrieve rejected");
				}
			}
			vc_response.primitive.responsePrimitive.from_ := vc_cseSimuDesc.cseId;
			vc_response.primitive.responsePrimitive.to_ := p_request.from_;
		
			return v_targetLocalResourceIndex;
		}
    				
		/**
		 * @desc   Proccessing of the DELETE request primitive
		 * @param  p_request          Request primitive to be processed
		 */
		function f_processDeleteRequestPrimitive(in RequestPrimitive p_request, in ResponseStatusCode p_responseStatusCode := int2002, template(omit) integer p_expectedTargetResourceIndex := omit) runs on CseSimu return integer {			
			var integer v_targetLocalResourceIndex := -1;
				
			v_targetLocalResourceIndex := f_getLocalResourceIndex(p_request.to_);
			vc_response.primitive.responsePrimitive := valueof(m_responsePrimitive(p_responseStatusCode,p_request.requestIdentifier));
			if(v_targetLocalResourceIndex == -1) {
				log(__SCOPE__&": ERROR: Target resource not found");
				vc_response.primitive.responsePrimitive.responseStatusCode := int4004;
			} else {
				if(isvalue(p_expectedTargetResourceIndex)){
					if(valueof(p_expectedTargetResourceIndex) != v_targetLocalResourceIndex){
						setverdict(inconc, __SCOPE__ & ":ERROR: Unexpected Target Resource Address");
						vc_response.primitive.responsePrimitive.responseStatusCode := int4000;
						return v_targetLocalResourceIndex;
					} else {
						setverdict(pass, __SCOPE__ & ":INFO: Expected Target Resource Address");
					}	
				}
				if(p_responseStatusCode == int2002) {
					setverdict(pass, __SCOPE__&":INFO: Resource deleted successfuly");
				} else {
					setverdict(pass, __SCOPE__&":INFO: Resource deletion rejected");
				}
			}
			vc_response.primitive.responsePrimitive.from_ := vc_cseSimuDesc.cseId;
			vc_response.primitive.responsePrimitive.to_ := p_request.from_;
		
			return v_targetLocalResourceIndex;
		}
		
		/**
		  * @desc	Get the Resource Identifier with Unstructured-CSE-relative -Resource-ID format
		  * @return	Cleaned-up resourceID
		  */
		function f_resourceIdCleaner(in XSD.ID p_resourceID) return XSD.ID {
			var integer v_length := lengthof(p_resourceID);
			var integer i;
			var XSD.ID result := "";
			
			//log("p_resourceID: " & p_resourceID);
			for (i := v_length - 1; i>=0; i := i-1){
				if(p_resourceID[i]=="/"){
					//log("result: " & result);
						return result;
						}
				else{
					result := p_resourceID[i] & result;
				}	
			}
			//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
		  * @return	Cleaned-up resourceID
		  */
		function f_useShortcutInResourceId(in XSD.ID p_resourceID) return XSD.ID {
			var integer v_length := lengthof(p_resourceID);
			var integer i;
			var integer v_numberOfSlashes := 0;
			var XSD.ID v_modifiedResourceId:= "";
			var XSD.ID v_cseName := "";
			
			if(p_resourceID[0] == "/") {
				if(p_resourceID[1] == "/") {
					v_numberOfSlashes := 4;
			 	} else {
					v_numberOfSlashes := 2;
			 	}
			}
			//log("p_resourceID: " & p_resourceID);
			for (i := 0; i < v_length ; i := i+1){
				if(v_numberOfSlashes != 0) {
					if(p_resourceID[i]=="/"){
						v_numberOfSlashes := v_numberOfSlashes - 1;
					}
					v_modifiedResourceId := v_modifiedResourceId & p_resourceID[i];
				} else if (v_numberOfSlashes == 0){
					if(p_resourceID[i]=="/"){
						v_numberOfSlashes := v_numberOfSlashes - 1;
						v_modifiedResourceId := v_modifiedResourceId & "-/";
						log(__SCOPE__, "INFO: CSE Name to be removed from resource ID: " & v_cseName);
					}
					v_cseName := v_cseName & p_resourceID[i];
				} else if (v_numberOfSlashes == -1){
					v_modifiedResourceId := v_modifiedResourceId & p_resourceID[i];	
				}	
			}
			return v_modifiedResourceId;
		}
		
		/**
		 * @desc It removes the poa from a given url
		 * @param p_url URL
		 * @return Resource Identifier
		 * NOT USED FOR THE TIME BEING
		 */
		function f_removePoa(in XSD.ID p_url) return XSD.ID {
			var integer v_length := lengthof(p_url);
			var integer i;
			var integer v_numberOfColons := 0;
			var boolean v_lookForSlash := false;
			var boolean v_getURI := false;
			var XSD.ID v_uri := "";
			
			//TODO Process when FQDN is used in the URL
			for (i := 0; i<v_length; i := i + 1){
				if(v_getURI) {
					v_uri := v_uri & p_url[i];
				} else {
					if(p_url[i]==":"){
						v_numberOfColons := v_numberOfColons + 1;
					}
					if(v_numberOfColons >= 2) {
						v_lookForSlash := true;
					}
					if(v_lookForSlash) {
						if(p_url[i]=="/") {
							v_getURI := true;
						}
					}
				}
			}
			
			
			if(v_uri == "") {
				return p_url;
			} else {
				return v_uri;
			}
		}
		
		/**
		 * @desc Removal of an element from a given integer list
		 * @param p_list Given integer list
		 * @param p_valueToBeDeleted Element value to be removed
		 * @verdict 
		 */
		function f_removeElementFromList (inout IntegerList p_list, in integer p_valueToBeDeleted) {
			var IntegerList result := {};
			var integer i;
			for(i := 0; i < lengthof(p_list); i := i+1){
				if(p_list[i] != p_valueToBeDeleted){
					result := result & {p_list[i]};
				}
			}
			p_list := result;
		}
				
		/**
		 * @desc Comparison of two primitiveContent parameters
		 * @param p_responsePrimitiveContent Received primitiveContent
		 * @param p_requestPrimitiveContent Sent primitiveContent
		 * @verdict 
		 */
		function f_match2PrimitiveContent (in PrimitiveContent p_responsePrimitiveContent, in template PrimitiveContent p_requestPrimitiveContent) runs on Tester {
			var template PrimitiveContent v_primitiveContent;
			var PrimitiveContent v_response;
			v_response := p_responsePrimitiveContent;
			v_primitiveContent := f_getTemplateFromPrimitiveContent(p_requestPrimitiveContent);
			if(not(match(v_response, v_primitiveContent))){
				setverdict(inconc, __SCOPE__&":INFO: Resource incomplete, some attribute missing ");
			}

		}		
		
		function f_send(
		                in InterfaceIds p_interfaceIds, 
		                in template MsgOut p_msgOut,
		                in boolean p_storingRequest := true
		) runs on Tester {
            log(">>> f_send: ", p_interfaceIds);
			
			p_msgOut.host := vc_myInterfaces[enum2int(p_interfaceIds)].myHost;
			p_msgOut.protocolBinding := vc_myInterfaces[enum2int(p_interfaceIds)].myProtocolBinding;
			p_msgOut.serialization := vc_myInterfaces[enum2int(p_interfaceIds)].mySerialization;
			log("f_send: protocolBinding=", p_msgOut.protocolBinding);
			if(ischosen(p_msgOut.primitive.requestPrimitive)){
				p_msgOut.primitive.requestPrimitive.requestIdentifier := valueof(p_msgOut.primitive.requestPrimitive.requestIdentifier) & f_rnd(1, 1000000);
				if(p_storingRequest){
					vc_request.primitive.requestPrimitive := valueof(p_msgOut.primitive.requestPrimitive);
				}
			}
			if(not(vc_componentRegistered)) {
				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) and (valueof(p_msgOut.primitive.requestPrimitive.resourceType) != int16)){
								//Modify default topic to publish a non-registration message
								f_sendAcPrimitive("MqttSetDefaultTopicToNotRegistration", -1, valueof(p_msgOut.primitive.requestPrimitive.from_));
								f_sendWrapper(p_interfaceIds, p_msgOut);
								f_sendAcPrimitive("MqttSetDefaultTopicToRegistration", -1);
								return;
							}
						} else {//RETRIEVE - UPDATE - DELETE - NOTIFY
							//Modify default topic to publish a non-registration message
							f_sendAcPrimitive("MqttSetDefaultTopicToNotRegistration", -1, valueof(p_msgOut.primitive.requestPrimitive.from_));
							f_sendWrapper(p_interfaceIds, p_msgOut);
							f_sendAcPrimitive("MqttSetDefaultTopicToRegistration", -1);
							return;
						}
					}
				} 
			}
			//TODO: Handle response to normal messages before CSE registration occurs
			f_sendWrapper(p_interfaceIds, p_msgOut);
		}
		
		function f_sendWrapper(in InterfaceIds p_interfaceIds,in template MsgOut p_msgOut) runs on Tester {
		
			select (p_interfaceIds) {
			  
			  	case (e_mcaPort) {
					mcaPort.send(p_msgOut);	  		
			  	}
			  	case (e_mcaPortIn) {
					mcaPortIn.send(p_msgOut);	  		
			  	}
				case (e_mccPort) {
					mccPort.send(p_msgOut);	  		
			  	}
				case (e_mccPortIn) {
					mccPortIn.send(p_msgOut);	  		
			  	}
			}
		
		}
		
		/**
		 * @desc Get a converted to string random number 
		 * @param p_lower Lower limit 
		 * @param p_upper Upper limit
		 * @return Random number converted to string
		 * @verdict 
		 */
		function f_rnd(in integer p_lower, in integer p_upper) return charstring {
			
			return int2str(float2int(rnd() * int2float(p_upper - p_lower + 1)) + p_lower);	
		}
		
	}//end of commonFunctions
	
	group externalFunctions {
		
		/**
		 * @desc Generates a oneM2M timestamp based on current time. 
		 * 		 Format shall be YYYYMMDDTHHMMSS 
		 */		
		external function fx_generateTimestamp() return charstring;

		/**
		 * @desc Generates a ESPrimObject (E2eCompactJWE) containing an inner request primitive
		 */		
		external function fx_generate_ESPrim_object(in RequestPrimitive p_requestPrimitive) return charstring;
		
		/**
		 * @desc Creates and assigns a role resource to the Originator in the Role Repository
		 */		
		external function fx_assign_originatorRole() return charstring;
		
		/**
		 * @desc Creates and assigns a token resource to the Originator in the Token Repository
		 */		
		external function fx_assign_originatorToken() return charstring;
		
		/**
		 * @desc Generates a oneM2M JSON Web Token. 
		 */		
		external function fx_generateJWT() return DynAuthJWT;	
		
		/**
		 * @desc Provides private key and certificates to ESCertKE endpoints 
		 */		
		external function fx_certificateProvision(charstring certificatePath, charstring certificateName);	
		
		/**
		 * @desc Configures Terminating End-Point and Initiating End-Point 
		 */		
		type enumerated endpointRole {
			e_ini,
			e_end
		};
		external function fx_initEndPointsConfiguration(endpointRole p_role);	
		
		/**
		 * @desc Generates base64 representation of ESCertKE messages
		 */		
		external function fx_generateESCertKEMessage(XSD.Base64Binary incomingMessage) return XSD.Base64Binary;	
		
		/**
		 * @desc Validates incoming ESCertKE message
		 */		
		external function fx_validateESCertKEMessage(XSD.Base64Binary incomingMessage, integer stage) return boolean;			

		/**
		 * @desc Retrieve the specified ontology description. 
		 * @param p_ontology_description The ontology description (e.g. /saref).
		 */
		external function fx_retrieve_formal_ontology(in charstring p_ontology_description) return charstring;

	} // end externalFunctions
	
}  // end of module