OneM2M_Functions.ttcn 8.44 KB
Newer Older
1 2 3 4 5 6 7 8 9
/**
 *  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     ETSI
 *  @version    $URL: https://forge.etsi.org/svn/oneM2M/trunk/ttcn/OneM2M_Functions.ttcn $
10
 *              $Id: OneM2M_Functions.ttcn 43 2016-04-13 12:16:12Z reinaortega $
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
 *  @desc       Module containing functions for oneM2M
 *
 */
module OneM2M_Functions {
	
	import from LibCommon_Time {modulepar all;}
	import from XSD all;
	import from OneM2M_Templates all;
	import from OneM2M_Types all;//{type XSD.ID};
	import from OneM2M_TypesAndValues all;
	import from OneM2M_TestSystem all;
	import from OneM2M_Pixits all;
//	import from OneM2M_AdditionalTypes all;
	
	
	group configFunctions {
    	/**
    		@desc 
    	*/
    	function f_cf01Up() runs on M2M {
    			
    		// Variables
    			
    		// Map
    		map(self:mcaPort, system:mcaPort);
    		activate(a_default());
    			
    		// Connect
    						
    		//Initialze the IUT
    						
    	} // end f_cf01Up
    	
	}//end group configFunctions
	
	group preambleFunctions {

		function f_preamble_registerAe(in template (value) XSD.String p_name, in template (value) AccessControlOperations p_allowedOperations) runs on M2M {
		
			var RequestPrimitive v_request;
			var M2MResponsePrimitive v_response;
			var XSD.ID v_acpId;
		
		
55
			v_acpId := f_createAccessControlPolicyAux(p_allowedOperations);
56 57 58 59 60 61 62
			
			mcaPort.send(m_request(m_createAeAux(p_name, {v_acpId})));
			tc_ac.start;
			alt {
				[] mcaPort.receive(mw_responseOK) -> value v_response {
					tc_ac.stop;
					log("Preamble: Application registered successfuly");
63 64
					if(ischosen(v_response.responsePrimitive_.primitiveContent.any_1[0].AE)) {
						vc_ae := v_response.responsePrimitive_.primitiveContent.any_1[0].AE;
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159
					}
				}
				[] mcaPort.receive(mw_responseKO) {
					tc_ac.stop;
					setverdict(inconc, "Preamble: Error while registering application");
					stop;
				}
				[] mcaPort.receive {
					tc_ac.stop;
					setverdict(inconc, "Preamble: Unexpected message received");
					stop;
				}
				[] tc_ac.timeout {
					setverdict(inconc, "Preamble: No answer while registering resource");
					stop;
				}
			}	
		
		}
	
	}//end group preambleFunctions
	
	group postambleFunctions {

		function f_postamble_deleteResources(in template (value) XSD.String p_aeName) runs on M2M {
		
			var M2MResponsePrimitive v_response;
			
			if (PX_RUN_POSTAMBLE) {
				mcaPort.send(m_request(m_deleteAe("/" & PX_CSE_NAME & "/" & valueof(p_aeName))));
				tc_ac.start;
				alt {
					[] mcaPort.receive(mw_responseOK) {
						tc_ac.stop;
						log("Postamble: AE Resource deleted");
					}
					[] mcaPort.receive(mw_responseKO) {
						tc_ac.stop;
						log("Postamble: Error while deleting resource");
					}
					[] tc_ac.timeout {
						log("Postamble: No answer while deleting resource");
					}	
				}	
    		
				mcaPort.send(m_request(m_deleteAcp("/" & PX_CSE_NAME & "/MyAcp")));
				tc_ac.start;
				alt {
					[] mcaPort.receive(mw_responseOK) {
						tc_ac.stop;
						log("Postamble: ACP Resource deleted");
					}
					[] mcaPort.receive(mw_responseKO) {
						tc_ac.stop;
						log("Postamble: Error while deleting resource");
					}
					[] tc_ac.timeout {
						log("Postamble: No answer while deleting resource");
					}	
				}
			}
		
			f_postamble_default();
		}
			
		function f_postamble_default() runs on M2M {
	
			unmap(self:mcaPort, system:mcaPort); 
			stop;
		}		
		
	}//end group postambleFunctions
	
	group altstepFunctions {

		/**
		  * @desc	Default altstep
		  */
		 altstep a_default() runs on M2M {
			
			[] mcaPort.receive {
				log("a_default: WARNING: Unexpected message received");
				repeat;
			}
			[] tc_wait.timeout {
				 setverdict(inconc,"a_default: ERROR: Timeout while awaiting reaction of the IUT prior to Upper Tester action");
			}
			[] tc_ac.timeout {
				setverdict(inconc,"a_default: ERROR: Timeout while awaiting the reception of a message");
			}
		 }		
	}//end group altstepFunctions
	
	group getSetFunctions {

160
		function f_getCreateRequestPrimitive(in ResourceType p_resourceType, XSD.ID p_aeResourceAddress, in template (omit) AccessControlOperations p_allowedOperations, template RequestPrimitive p_request) runs on M2M return RequestPrimitive {
161 162
		
			p_request.to_ := p_aeResourceAddress;
163
			//p_request.name := p_name;
164 165 166 167
		
			if (p_resourceType == int1) {//AccessControlPolicy
			
				if(isvalue(p_allowedOperations)){
168
					p_request.primitiveContent.any_1[0].ACP_create := valueof(m_contentCreateAcp (c_defaultResourceName, p_allowedOperations));
169 170 171
				}		
			} 
			if (p_resourceType == int9) {//group
172
				p_request.primitiveContent.any_1[0].Group_create := m_contentCreateGroup (1, {"/" & PX_CSE_NAME & "/" & vc_ae.resourceID}, omit);
173 174 175 176 177 178 179 180 181
			}
		
			if (p_resourceType == int15) {//pollingChannel
				p_request.from_ := vc_ae.aE_ID;
			} 
		
			return valueof(p_request);
		}
	
182
		function f_getUpdateRequestPrimitive(in ResourceType p_resourceType, XSD.ID p_resourceAddress, template RequestPrimitive p_request) runs on M2M return RequestPrimitive {
183 184
		
			p_request.to_ := p_resourceAddress;
185
			//p_request.name := p_name;
186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225
		
			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);
		}

		function f_getResourceId(PrimitiveContent p_contentResource) return XSD.ID {
				
			if(ischosen(p_contentResource.any_1[0].AccessControlPolicy)) {
				return p_contentResource.any_1[0].AccessControlPolicy.resourceID;
			}
			return "1";
  
		}
				
	}//end group getSetFunctions
	
	group helpingFunctions {

226
		function f_createResource(in ResourceType p_resourceType, XSD.ID p_parentResourceAddress, template RequestPrimitive p_requestPrimitive) runs on M2M {
227 228 229 230
		
			var M2MResponsePrimitive v_response;
			var RequestPrimitive v_request;
			
231
			v_request := f_getCreateRequestPrimitive(p_resourceType,p_parentResourceAddress, omit, p_requestPrimitive);
232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254
		
			mcaPort.send(m_request(v_request));
			tc_ac.start;
			alt {
				[] mcaPort.receive(mw_responseOK) -> value v_response {
					tc_ac.stop;
					setverdict(pass, "f_createResource: Resource type " & int2str(enum2int(p_resourceType)) & " created successfuly");
				}
				[] mcaPort.receive(mw_responseKO) {
					tc_ac.stop;
					setverdict(inconc, "f_createResource: Error while creating resource type " & int2str(enum2int(p_resourceType)));
				}
				[] mcaPort.receive {
					tc_ac.stop;
					setverdict(inconc, "f_createResource: Unexpected message received");
				}
				[] tc_ac.timeout {
					setverdict(inconc, "f_createResource: No answer while creating resource type " & int2str(enum2int(p_resourceType)));
				}
			}	
	
		}
	
255
		function f_createAccessControlPolicyAux(in template (value) AccessControlOperations p_allowedOperations) runs on M2M return XSD.ID{
256 257 258 259
		
				var M2MResponsePrimitive v_response;
				var XSD.ID v_acpId;
			
260
				mcaPort.send(m_request(m_createAcpAux(p_allowedOperations)));
261 262 263 264 265
				tc_ac.start;
				alt {
					[] mcaPort.receive(mw_responseOK) -> value v_response {
						tc_ac.stop;
						setverdict(pass, "f_createAccessControlPolicy: Resource type " & int2str(1) & " created successfuly");
266 267
						v_acpId := f_getResourceId(v_response.responsePrimitive_.primitiveContent);
						return v_acpId;
268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302
					}
					[] mcaPort.receive(mw_responseKO) {
						tc_ac.stop;
						setverdict(inconc, "f_createAccessControlPolicy: Error while creating resource type " & int2str(1));
					}
					[] mcaPort.receive {
						tc_ac.stop;
						setverdict(inconc, "f_createAccessControlPolicy: Unexpected message received");
					}
					[] tc_ac.timeout {
						setverdict(inconc, "f_createAccessControlPolicy: No answer while creating resource type " & int2str(1));
					}
				}	
			
				return "0";
	
			}
		
	}//end group helpingFunctions	


	

		

	

		

		

	

	
}  // end of module