OneM2M_Functions.ttcn 112 KB
Newer Older
1 2 3 4 5 6 7 8
/**
 *  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
9 10
 *  @version    $URL: https://oldforge.etsi.org/svn/oneM2M/branches/Release1/ttcn/LibOneM2M/OneM2M_Functions.ttcn $
 *              $Id: OneM2M_Functions.ttcn 347 2017-08-11 08:48:20Z reinaortega $
11 12 13 14 15 16 17 18 19 20 21
 *  @desc       Module containing functions for oneM2M
 *
 */
module OneM2M_Functions {
	
	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;
22
	import from OneM2M_Pics all;
23 24 25
//	import from OneM2M_AdditionalTypes all;
	
	
26 27
	group ConfigFunctions {
		
28 29 30
		/**
			@desc Ports mapping and default behaviour activation for Config 1
		*/
31
		function f_cf01Up(in boolean p_auxiliaryAe2Required := false) runs on AeSimu {
32
			
33
			// Variables
34 35
			vc_config := e_cf01;	
			
36 37 38
			// Map
			map(self:mcaPort, system:mcaPort);
			map(self:acPort, system:acPort);
39
			
40
			activate(a_default());
41
			activate(a_cse_cf01());
42
				
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70
			// Initialize AE2
			if(p_auxiliaryAe2Required) {
				vc_auxiliaryAe2Up := p_auxiliaryAe2Required;
				vc_ae2 := AeSimu.create("AE2") alive;
				vc_ae2.start(f_cf01UpAe2());
			}
				
			//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 {
			
			// Variables
			vc_config := e_cf01;	
			
			// Map
			map(self:mcaPort, system:mcaPort);
			map(self:mcaPortIn, system:mcaPortIn);
			map(self:acPort, system:acPort);
			
			activate(a_default());
			activate(a_cse_cf01());
			activate(a_cse_cf01_ae2()); //For mcaPortIn
	
71
			//Initialze the IUT
72
							
73
		} // end f_cf01Up
74
		
75 76 77
		/**
		 * @desc Ports mapping and default behaviour activation for Config 02
		 */
78
		function f_cf02Up() runs on AeSimu {
79
				
80
			// Variables
81
			vc_config := e_cf02;
82
			vc_cseSimu := CseSimu.create("CSE1") alive;
83
				
84 85
			// Map
			map(self:mcaPort, system:mcaPort);
86
			map(vc_cseSimu:mccPort, system:mccPort);
87 88
			map(self:acPort, system:acPort);
			activate(a_default());
89
			activate(a_cse_aeSimu());
90
				
91
			// Connect
92
			f_connectInfoPort(vc_cseSimu);
93
			//Initialze the IUT
94
							
95
		} // end f_cf02Up
96

97 98 99 100 101 102 103 104 105 106
		/**
		 * @desc Ports mapping and default behaviour activation for Config 02
		 */
		function f_cf02UpCseSimuMaster() runs on CseSimu {
				
			// Variables
			vc_config := e_cf02;
			vc_aeSimu := AeSimu.create("AE1") alive;
				
			// Map
107
			map(self:mccPort, system:mccPort);
108 109 110 111 112 113 114 115 116 117 118
			map(vc_aeSimu:mcaPort, system:mcaPort);
			map(self:acPort, system:acPort);
			activate(a_default());
			activate(a_cse_cseSimu());
				
			// Connect
			f_connectInfoPort(vc_aeSimu);
			//Initialze the IUT
							
		} // end f_cf02UpCseSimuMaster
		
119 120 121
		/**
		 * @desc Ports mapping and default behaviour activation for Config 03
		 */
122
		function f_cf03Up() runs on CseSimu {
123 124
		
			// Variables
125 126
			vc_config := e_cf03;
			
127 128 129 130
			// Map
			map(self:mcaPort, system:mcaPort);
			map(self:acPort, system:acPort);
			activate(a_default());
131
			activate(a_ae_cf03());
132 133 134 135 136 137 138
		
			// Connect
					
			//Initialze the IUT
					
		} // end f_cf03Up
		
139 140 141
		/**
		 * @desc Ports mapping and default behaviour activation for Config 04
		 */
142
		function f_cf04Up() runs on CseSimu {
143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162

			// Variables
			vc_config := e_cf04;
	
			// Map
			map(self:mccPort, system:mccPort);
			map(self:acPort, system:acPort);
			activate(a_default());
			activate(a_cse_cf04());

			// Connect
			
			//Initialze the IUT
			
		} // end f_cf03Up

		/**
		 * @desc Ports unmapping
		 * @verdict 
		 */
163
		/*function f_cfCseTesterDown() runs on Tester {
164 165 166 167 168 169 170 171 172 173 174
		
			if(vc_config == e_cf01) {
				f_cf01Down()
			} else if (vc_config == e_cf02){
				f_cf02Down()
			} 
		}
		/**
		 * @desc Ports unmapping
		 * @verdict 
		 */
175
		/*function f_cfAeTesterDown() runs on AeSimu {
176 177 178 179
		
			if(vc_config == e_cf03) {
				f_cf03Down()
			} 
180
		}	
181 182 183
		/**
		 * @desc Ports unmapping
		 * @verdict 
184
		 */
185
		function f_cf01Down() runs on AeSimu {
186
		
187
			unmap(self:mcaPort, system:mcaPort);
188
			unmap(self:acPort, system:acPort);
189 190 191
			if(vc_auxiliaryAe2Up) {
				vc_ae2.start(f_cf01DownAe2());
			}
192 193 194 195 196 197
		}
		
		/**
		 * @desc Ports unmapping
		 * @verdict 
		 */
198 199 200
		function f_cf01DownAe2() runs on AeSimu {
				
			unmap(self:mcaPort, system:mcaPort);
201
			unmap(self:acPort, system:acPort);
202
			unmap(self:mcaPortIn, system:mcaPortIn);
203 204
		}
		
205 206 207 208
		/**
		 * @desc Ports unmapping
		 * @verdict 
		 */
209
		function f_cf02Down() runs on AeSimu {
210
		
211
			unmap(self:mcaPort, system:mcaPort);
212 213 214 215 216 217 218 219 220 221
			unmap(vc_cseSimu:mccPort, system:mccPort);
			unmap(self:acPort, system:acPort);
			unmap(vc_cseSimu:acPort, system:acPort);
		}		
		/**
		 * @desc Ports unmapping
		 * @verdict 
		 */
		function f_cf02DownCseSimuMaster() runs on CseSimu {
				
222
			unmap(self:mccPort, system:mccPort);
223
			unmap(vc_aeSimu:mcaPort, system:mcaPort);
224
			unmap(self:acPort, system:acPort);
225
			unmap(vc_aeSimu:acPort, system:acPort);
226
		}		
227 228 229
		/**
		 * @desc Ports unmapping for Config 03
		 */
230
		function f_cf03Down() runs on CseSimu {
231 232 233 234 235 236 237 238
			
			unmap(self:mcaPort, system:mcaPort);
			unmap(self:acPort, system:acPort);
		}
		
		/**
		 * @desc Ports unmapping for Config 04
		 */
239
		function f_cf04Down() runs on CseSimu {
240 241 242 243 244
	
			unmap(self:mccPort, system:mccPort);
			unmap(self:acPort, system:acPort);
		}
		
245 246 247 248 249 250 251 252 253 254
		function f_connectInfoPort(in Tester p_tester) runs on Tester {
			// Connect
			connect(self:infoPort, p_tester:infoPort);		
		} 
	
		function f_disconnectInfoPort(in Tester p_tester) runs on Tester {
			// Disconnect
			disconnect(self:infoPort, p_tester:infoPort);		
		} 
		
255
	}//end group configFunctions
256
	
257
	group CseFunctions {
258
	
259
		group PreambleFunctions {
260 261 262 263 264 265 266

			/**
			 * @desc Creation of auxiliar resources ACP for correct execution of the test case
			 * @param p_allowedOperations Allowed operations for the auxiliar AE resource
			 * @return Internal ACP resource index
			 * @verdict 
			 */
267
			function f_cse_preamble_createAcpAux(in template (value) XSD.String p_acpName := c_acpAuxName, in template (value) AccessControlOperations p_allowedOperations := int63) runs on AeSimu return integer {//c_CRUDNDi
268
			
269
				return f_cse_createAccessControlPolicyAux(p_acpName, -, p_allowedOperations);
270
			
271 272
			}

273
	
274 275 276 277 278 279
			/**
			 * @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
			 * @return Internal AE resource index
			 * @verdict 
			 */
280
			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
281
			
282 283 284
				var RequestPrimitive v_request;
				var MsgIn v_response;
				var integer v_aeAuxIndex := -1;
285
								
286
				v_request := valueof(m_createAeAux(p_accessControlPolicyIDs, p_poaList));
287 288
				
				v_request := f_getCreateRequestPrimitive(int2, v_request, -1);
289 290
				
				mcaPort.send(m_request(v_request));
291
				
292 293 294 295
				tc_ac.start;
				alt {
					[] mcaPort.receive(mw_response(mw_responsePrimitiveOK)) -> value v_response {
						tc_ac.stop;
296 297 298 299 300
						setverdict(pass,__SCOPE__&":INFO: Application registered successfuly");
						if(ischosen(v_response.primitive.responsePrimitive.primitiveContent.aE)) {
							
							f_checkAttributesToBeSaved(int2, v_request, v_response.primitive.responsePrimitive);
							
301
							vc_aeAuxIndex := f_setResource(v_response.primitive.responsePrimitive.primitiveContent, int2);
302
							
303 304
							if(ispresent(v_response.primitive.responsePrimitive.primitiveContent.aE.aE_ID)){
								f_sendAcPrimitive("AE-ID_changed", oct2char(unichar2oct(v_response.primitive.responsePrimitive.primitiveContent.aE.aE_ID)));
305 306
							} else {
								f_sendAcPrimitive("AE-ID_changed", "0");
307 308
							}
						}
309 310 311
					}
					[] mcaPort.receive(mw_response(mw_responsePrimitiveKO)) {
						tc_ac.stop;
312
						setverdict(inconc, __SCOPE__&":INFO: Error while registering application");
313 314 315 316
						stop;
					}
					[] mcaPort.receive {
						tc_ac.stop;
317
						setverdict(inconc, __SCOPE__&":INFO: Unexpected message received");
318
						stop;
319
					};
320
					[] tc_ac.timeout {
321
						setverdict(inconc, __SCOPE__&":INFO: No answer while registering resource");
322 323 324
						stop;
					}
				}	
325
				
326
				f_checkAeSimuStatus();
327
				return vc_aeAuxIndex;
328
			
329
			}
330
			
331 332 333 334 335 336
			/**
			 * @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
			 * @return Internal AE resource index
			 * @verdict 
			 */
337
			function f_cse_preamble_registerAeWithId(XSD.ID p_appId, in template (value) AccessControlOperations p_allowedOperations := int63) runs on AeSimu return integer {//c_CRUDNDi
338
			
339 340 341
				var RequestPrimitive v_request;
				var integer v_aeAuxIndex := -1;
				var integer v_acpAuxIndex := -1;
342
			
343 344 345 346
				if(PICS_ACP_SUPPORT){
					v_acpAuxIndex := f_cse_createAccessControlPolicyAux(p_allowedOperations := p_allowedOperations);
					vc_acpAuxIndex := v_acpAuxIndex;
				}
347
				
348 349 350
				if(v_acpAuxIndex != -1) {
					vc_resourcesIndexToBeDeleted := {v_acpAuxIndex};
					v_request := valueof(m_createAe(p_appId, {f_getResourceId(vc_resourcesList[v_acpAuxIndex].resource)}, -));
351
					
352 353
					//TODO Test, to be removed
					v_request.to_ := f_getResourceAddress();
354
					
355 356 357 358 359 360 361
					mcaPort.send(m_request(v_request));
					//mcaPort.send(m_request(m_createAeAux(p_name, {PX_URI_CSE & PX_CSE_NAME & "/" & PX_ACPAUX_NAME})));
				} else {
					mcaPort.send(m_request(m_createAe(p_appId)));
				}
				tc_ac.start;
				alt {
362
					[] mcaPort.receive(mw_response(mw_responsePrimitiveOK)) -> value vc_response {
363
						tc_ac.stop;
364
						setverdict(pass, __SCOPE__&": INFO: Application registered successfuly");
365
						if(ischosen(vc_response.primitive.responsePrimitive.primitiveContent.aE)) {
366
							
367
							vc_aeAuxIndex := f_setResource(vc_response.primitive.responsePrimitive.primitiveContent, int2);
368
							
369 370
							if(ispresent(vc_response.primitive.responsePrimitive.primitiveContent.aE.aE_ID)){
								f_sendAcPrimitive("AE-ID_changed", oct2char(unichar2oct(vc_response.primitive.responsePrimitive.primitiveContent.aE.aE_ID)));
371 372 373 374 375
							} else {
								f_sendAcPrimitive("AE-ID_changed", "0");
							}	
						}
					}
376 377
					[] mcaPort.receive(mw_response(mw_responsePrimitiveKO))
					{
378
						tc_ac.stop;
379
						setverdict(inconc, __SCOPE__&":INFO: Error while registering application");
380 381 382 383
						stop;
					}
					[] mcaPort.receive {
						tc_ac.stop;
384
						setverdict(inconc, __SCOPE__&":INFO: Unexpected message received");
385 386 387
						stop;
					}
					[] tc_ac.timeout {
388
						setverdict(inconc, __SCOPE__&":INFO: No answer while registering resource");
389 390 391
						stop;
					}
				}	
392
				
393
				f_checkAeSimuStatus();
394
				return vc_aeAuxIndex;
395
			
396
			}
397
			
398
			function f_cse_preamble_createServiceSubscribedAppRule(in template ListOfM2MID p_allowedAEs := {""}) runs on AeSimu return integer {//c_CRUDNDi
399
			
400
				var integer v_serviceSubscribedAppRuleIndex := -1;
401
	
402
				v_serviceSubscribedAppRuleIndex := f_cse_createResource(int19, m_createServiceSubscribedAppRule({"None"}, {PX_APP_ID}, valueof(p_allowedAEs)));
403
				
404
				return v_serviceSubscribedAppRuleIndex;
405
			
406
			}
407
			
408 409 410 411 412 413
			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;
				
414
				//TODO Create/Update serviceSubscribedNode //m_request.primitiveContent.m2mServiceSubscriptionProfile.choice.choice_list[0].serviceSubscribedNode := m_contentServiceSubscribedNode;
415 416 417 418 419 420 421 422
				v_serviceSubscribedAppRuleIndex := f_cse_createResource(int19, m_createServiceSubscribedAppRule({"None"}, {PX_APP_ID}, 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;
	
			}
			
423
			function f_cse_preamble_subscriptionVerification(inout integer p_ae2Index, inout template RequestPrimitive p_createRequestPrimitive,in ResourceType p_resourceType, in ResponseStatusCode p_responseStatusCode := int2001) runs on AeSimu {
424
				if(p_resourceType == int23){
425 426 427 428 429 430
					
					vc_ae2.start(f_cse_createResource(int2, m_createAe(PX_APP_ID, -, PX_AE2_ID_STEM, "MyAe2", {f_getAnnouncementTargetPoA("HTTP", PX_AE2_ADDRESS, "")}), -1)); // AE2 is registred
					
					f_checkComponentDoneAndGetVerdict(vc_ae2);
					
					p_ae2Index := f_getResource(vc_ae2);
431 432
					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)}; 
433
					}
434
					vc_ae2.start(f_cse_notifyProcedure_subscriptionVerificationHandler(p_responseStatusCode));
435 436
				}
			}
437
		
438
		}//end group preambleFunctions
439 440 441
		
		group PostambleFunctions {
	
442 443 444 445
			/**
			 * @desc Deletion of all resources created during the test case execution. IUT gets clean and ready for next execution
			 * @verdict 
			 */
446
			function f_cse_postamble_deleteResources() runs on AeSimu {
447 448 449
				var integer i;
				var XSD.ID v_resourceAddress;
				var RequestPrimitive v_request;
450
				
451
				if (PX_RUN_POSTAMBLE) {
452
					
453 454 455 456
					if(vc_auxiliaryAe2Up) {
						f_cse_postamble_aeSimu(vc_ae2);
					}
					
457 458 459 460
					for(i := lengthof(vc_resourcesIndexToBeDeleted) -1; i >=0; i := i - 1) {
						
						v_resourceAddress := f_getResourceAddress(vc_resourcesIndexToBeDeleted[i]); 
						
461
						v_request := valueof(m_delete(v_resourceAddress, f_getOriginator(vc_resourcesIndexToBeDeleted[i])));
462 463
						
						v_request.from_ := f_getOriginator(vc_resourcesIndexToBeDeleted[i]);
464

465
						mcaPort.send(m_request(v_request));
466
						
467 468 469 470
						tc_ac.start;
						alt {
							[] mcaPort.receive(mw_response(mw_responsePrimitiveOK)) {
								tc_ac.stop;
471
								log(__SCOPE__&" INFO: Resource " & v_request.to_ & " deleted");
472 473 474
							}
							[] mcaPort.receive(mw_response(mw_responsePrimitiveKO)) {
								tc_ac.stop;
475
								log(__SCOPE__&" INFO: Error while deleting resource " & v_request.to_);
476 477
							}
							[] tc_ac.timeout {
478
								log(__SCOPE__&" INFO: No answer while deleting resource " & v_request.to_);
479 480
							}	
						}	
481
						
482 483
					}
				}
484
						
485
			}
486
			
487 488 489 490 491 492 493 494 495 496 497
			/**
			 * @desc Calls to postamble for AE2 entity
			 * @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());
			}
			
498 499 500 501
			/**
			 * @desc Deletion of all resources created during the test case execution. IUT gets clean and ready for next execution
			 * @verdict 
			 */
502
			function f_cse_postamble_deleteResourcesCSE() runs on CseSimu {
503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536
				var integer i;
				var XSD.ID v_resourceAddress;
				var RequestPrimitive v_request;
	
				if (PX_RUN_POSTAMBLE) {
		
					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],false)));
			
						v_request.from_ := PX_SUPER_CSE_ID;

						mccPort.send(m_request(v_request));
			
						tc_ac.start;
						alt {
							[] mccPort.receive(mw_response(mw_responsePrimitiveOK)) {
								tc_ac.stop;
								log(__SCOPE__&" INFO: Resource " & v_request.to_ & " deleted");
							}
							[] 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_);
							}	
						}	
			
					}
				}
			
537
			}
538
			
539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557
			/**
				@desc 
			*/
			function f_getResponsePrimitive(in AeSimu p_ae) runs on Tester return ResponsePrimitive {
				var ResponsePrimitive v_response;
				
				f_connectInfoPort(p_ae);
		
				p_ae.start(f_sendResponsePrimitive());
				alt {
					[]infoPort.receive(mw_responsePrimitiveforInfoPort) -> value v_response {
					}
				}
		
				f_disconnectInfoPort(p_ae);
					
				return v_response;
					
			}
558
			
559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595
			/**
				@desc 
			*/
			function f_getRequestPrimitive(in AeSimu p_ae) runs on Tester return RequestPrimitive {
				var RequestPrimitive v_request;
	
				f_connectInfoPort(p_ae);

				p_ae.start(f_sendRequestPrimitive());
				alt {
					[]infoPort.receive(mw_requestPrimitiveforInfoPort) -> value v_request {
					}
				}

				f_disconnectInfoPort(p_ae);
		
				return v_request;
		
			}
			
			function f_getRemoteCseRequestPrimitive(in CseSimu p_cse) runs on Tester return RequestPrimitive {
				var RequestPrimitive v_request;

				f_connectInfoPort(p_cse);

				p_cse.start(f_sendRemoteCseRequestPrimitive());
				alt {
					[]infoPort.receive(mw_requestPrimitiveforInfoPort) -> value v_request {
					}
				}

				f_disconnectInfoPort(p_cse);

				return v_request;

			}
			
596 597 598 599 600 601 602 603 604 605 606 607 608 609
						
			/**
				@desc 
			*/
			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 {
					}
				}
610
		
611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628
				f_disconnectInfoPort(p_ae);
					
				return v_primitiveContent;
					
			}
			
			/**
				@desc 
			*/
			function f_getRemoteCseResource(in CseSimu p_cse) runs on AeSimu return integer {
				var MyResource v_resource;
				var integer v_resourceIndex := -1;
				
				f_connectInfoPort(p_cse);
		
				p_cse.start(f_sendRemoteCseResource());
				alt {
					[]infoPort.receive(mw_resource) -> value v_resource {
629
						v_resourceIndex := f_setResource(v_resource.resource, v_resource.resourceType, v_resource.parentIndex, false);
630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650
					}
				}
		
				f_disconnectInfoPort(p_cse);
					
				return v_resourceIndex;
					
			}
			
			/**
				@desc 
			*/
			function f_getResource(in AeSimu p_ae, in integer p_resourceIndex := -1) runs on AeSimu return integer {
				var MyResource v_resource;
				var integer v_resourceIndex := -1;
			
				f_connectInfoPort(p_ae);
	
				p_ae.start(f_sendResource(p_resourceIndex));
				alt {
					[]infoPort.receive(mw_resource) -> value v_resource {
651
						v_resourceIndex := f_setResource(v_resource.resource, v_resource.resourceType, v_resource.parentIndex, false);
652 653
					}
				}
654
	
655 656
				f_disconnectInfoPort(p_ae);
				
657 658
				p_ae.done;
				
659 660 661 662 663 664 665 666 667 668
				return v_resourceIndex;
				
			}		
		
			function f_sendResponsePrimitive() runs on AeSimu {
		
				infoPort.send(vc_response.primitive.responsePrimitive);
					
			} 
			
669 670 671 672 673 674 675 676 677 678 679 680
			function f_sendRequestPrimitive() runs on AeSimu {
		
				infoPort.send(vc_request.primitive.requestPrimitive);
		
			} 
			
			function f_sendRemoteCseRequestPrimitive() runs on CseSimu {
		
				infoPort.send(vc_request.primitive.requestPrimitive);

			}
			
681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707
			function f_sendPrimitiveContentRetrievedResource() runs on AeSimu {
		
				infoPort.send(vc_primitiveContentRetrievedResource);
					
			} 
			
			function f_sendRemoteCseResource() runs on CseSimu {
		
				infoPort.send(vc_resourcesList[vc_remoteCseIndex]);
					
			} 
			
			function f_sendResource(in integer p_resourceIndex) runs on AeSimu {
		
				if(p_resourceIndex == -1) {
					infoPort.send(vc_resourcesList[vc_aeAuxIndex]);
				} else {
					infoPort.send(vc_resourcesList[p_resourceIndex]);
				}
					
			} 
			
			
		}//end group postambleFunctions
		
		group AeSimuFunctions {
			
708 709 710 711 712 713 714 715
			/**
			 * @desc Creation of a resource
			 * @param p_resourceType Resource type of the resource to be created
			 * @param p_requestPrimitive Template request primitive
			 * @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 
			 */
716
			function f_cse_createResource(in ResourceType p_resourceType, template RequestPrimitive p_requestPrimitive := m_create, integer p_parentIndex := -1) runs on AeSimu return integer {
717
			
718 719
				var RequestPrimitive v_request;
				var integer v_resourceIndex := -1;
720
				
721
				v_request := f_getCreateRequestPrimitive(p_resourceType, p_requestPrimitive, p_parentIndex);
722
			
723 724 725
				mcaPort.send(m_request(v_request));
				tc_ac.start;
				alt {
726
					[] mcaPort.receive(mw_response(mw_responsePrimitiveOK)) -> value vc_response {
727
						tc_ac.stop;
728
						setverdict(pass, __SCOPE__&":INFO: Resource type " & int2str(enum2int(p_resourceType)) & " created successfuly");
729 730 731 732 733
						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_aeAuxIndex := v_resourceIndex;
						}
734 735 736
					}
					[] mcaPort.receive(mw_response(mw_responsePrimitiveKO)) {
						tc_ac.stop;
737
						setverdict(inconc, __SCOPE__&":INFO: Error while creating resource type " & int2str(enum2int(p_resourceType)));
738 739 740
					}
					[] mcaPort.receive {
						tc_ac.stop;
741
						setverdict(inconc, __SCOPE__&":INFO: Unexpected message received");
742 743
					}
					[] tc_ac.timeout {
744
						setverdict(inconc, __SCOPE__&":INFO: No answer while creating resource type " & int2str(enum2int(p_resourceType)));
745 746
					}
				}	
747
				
748
				f_checkAeSimuStatus();
749
				
750
				return v_resourceIndex;
751
		
752
			}
753
		
754 755 756 757 758 759 760
			/**
			 * @desc Creation of the auxiliar ACP resource
			 * @param p_acpName ACP name
			 * @param p_allowedOperations Allowed operations
			 * @return Internal resource index of the created auxiliar ACP resource
			 * @verdict 
			 */
761
			function f_cse_createAccessControlPolicyAux(in template (value) XSD.String p_acpName := c_acpAuxName, in template (value) ListOfURIs p_acor := PX_ACOR, in template (value) AccessControlOperations p_allowedOperations := int63) runs on AeSimu return integer{				var RequestPrimitive v_request;
762
				var integer v_acpAuxIndex := -1;
763
				
764
				v_request := valueof(m_createAcpAux(p_acpName := p_acpName, p_allowedOperations := p_allowedOperations));
765
				
766 767
				v_request := f_getCreateRequestPrimitive(int1, v_request, -1);
								
768 769 770
				mcaPort.send(m_request(v_request));
				tc_ac.start;
				alt {
771
					[] mcaPort.receive(mw_response(mw_responsePrimitiveOK)) -> value vc_response {
772
						tc_ac.stop;
773
						setverdict(pass, __SCOPE__&":INFO: Resource type " & int2str(1) & " created successfuly");
774 775
						f_checkAttributesToBeSaved(int1, v_request, vc_response.primitive.responsePrimitive);
						v_acpAuxIndex := f_setResource(vc_response.primitive.responsePrimitive.primitiveContent, int1);
776 777 778 779
						vc_acpAuxIndex := v_acpAuxIndex;
					}
					[] mcaPort.receive(mw_response(mw_responsePrimitiveKO)) {
						tc_ac.stop;
780
						setverdict(inconc, __SCOPE__&":INFO: Error while creating resource type " & int2str(1));
781 782 783
					}
					[] mcaPort.receive {
						tc_ac.stop;
784
						setverdict(inconc, __SCOPE__&":INFO: Unexpected message received");
785 786
					}
					[] tc_ac.timeout {
787
						setverdict(inconc, __SCOPE__&":INFO: No answer while creating resource type " & int2str(1));
788 789
					}
				}	
790
				
791
				f_checkAeSimuStatus();
792
			
793
				return v_acpAuxIndex;
794
	
795
			}
796 797
				
				
798 799 800 801 802 803
			/**
			 * @desc Creation of the auxiliar Container resource
			 * @param p_parentIndex Internal resource index which indicates the parent of the Container resource to be created
			 * @return Internal resource index of the created Container resource
			 * @verdict 
			 */
804
			function f_cse_createContainerResourceAux (integer p_parentIndex := -1) runs on AeSimu return integer {
805
			
806 807 808
				var RequestPrimitive v_request;
				var integer v_acpAuxIndex := -1;
				var integer v_containerResourceIndex := -1;
809
				
810
				v_acpAuxIndex := f_cse_createAccessControlPolicyAux(p_acpName := c_acpAuxName);//"MyAcp_2"
811
				
812
				v_request := valueof(m_createContainerBase);
813 814 815
				v_request.primitiveContent.container.accessControlPolicyIDs := {f_getResourceId(vc_resourcesList[v_acpAuxIndex].resource)};
				v_request.primitiveContent.container.resourceName := "MyContainerAux";
				
816
				v_containerResourceIndex := f_cse_createResource(int3, v_request, p_parentIndex);
817
				
818
				return v_containerResourceIndex;		
819
		
820
			}
821
			
822 823 824 825 826
			/**
			 * @desc 
			 * @param p_requestPrimitive
			 * @verdict 
			 */
827
			function f_cse_updateResource(in RequestPrimitive p_requestPrimitive) runs on AeSimu {
828 829 830 831

				mcaPort.send(m_request(p_requestPrimitive));
				tc_ac.start;
				alt {
832
					[] mcaPort.receive(mw_response(mw_responsePrimitiveOK)) -> value vc_response {
833
						tc_ac.stop;
834
						setverdict(pass, __SCOPE__&":INFO: Attribute of resource updated successfuly");
835
					}
836
					[] mcaPort.receive(mw_response(mw_responsePrimitiveKO)) -> value vc_response {
837
						tc_ac.stop;
838
						setverdict(inconc, __SCOPE__&":INFO: Error while updating resource");
839 840 841
					}
					[] mcaPort.receive{
						tc_ac.stop;
842
						setverdict(inconc, __SCOPE__&":INFO: Unexpected message received");
843 844
					}
					[] tc_ac.timeout {
845
						setverdict(inconc, __SCOPE__&":INFO: No answer while updating resource");
846 847
					}
				}	
848
				
849
				f_checkAeSimuStatus();
850
				
851
			}// end f_cse_updateResource
852
			
853
			/**
854 855
			 * @desc 
			 * @param p_resourceIndex
856 857
			 * @verdict 
			 */
858
			function f_cse_retrieveResource(integer p_resourceIndex) runs on AeSimu return PrimitiveContent{
859 860

				mcaPort.send(m_request(m_retrieveResource(f_getResourceAddress(p_resourceIndex), f_getOriginator(p_resourceIndex))));
861 862
				tc_ac.start;
				alt {
863
					[] mcaPort.receive(mw_response(mw_responsePrimitiveOK)) -> value vc_response {
864
						tc_ac.stop;
865
						setverdict(pass, __SCOPE__&":INFO: Resource retrieved successfuly");
866
					}
867
					[] mcaPort.receive(mw_response(mw_responsePrimitiveKO)) -> value vc_response {
868 869 870 871
						tc_ac.stop;
						setverdict(inconc, __SCOPE__&":INFO: Error while retrieving resource");
					}
					[] mcaPort.receive{
872
						tc_ac.stop;
873
						setverdict(inconc, __SCOPE__&":INFO: Unexpected message received");
874 875
					}
					[] tc_ac.timeout {
876
						setverdict(inconc, __SCOPE__&":INFO: No answer while retrieving resource");
877
					}
878 879
				}	
				
880
				f_checkAeSimuStatus();
881
				
882
				return vc_response.primitive.responsePrimitive.primitiveContent;
883 884
				
			}// end f_cse_retrievingResource
885
			
886 887 888 889 890
			/**
			 * @desc 
			 * @param p_requestPrimitive
			 * @verdict 
			 */
891
			function f_cse_deleteResource(in integer p_index, in template (omit) RequestPrimitive p_requestPrimitive := omit) runs on AeSimu {
892 893 894
				var RequestPrimitive v_request;
				
				if(not isvalue(p_requestPrimitive)) {
895
					v_request := valueof(m_delete(f_getResourceAddress(p_index), f_getOriginator(p_index)));
896 897
				} else {
					v_request := valueof(p_requestPrimitive);
898
				}
899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918
				
				mcaPort.send(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_);
					}	
				}	
				
919
				f_checkAeSimuStatus();
920 921 922 923 924 925 926 927
				
			}// end f_cse_deleteResource
			
			/**
			 * @desc Check that a resource is present in the IUT (resourceId is known)
			 * @param p_resourceIndex Resource index 
			 * @return boolean
			 */
928
			function f_isResourcePresent (integer p_resourceIndex) runs on AeSimu return boolean {
929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947