OneM2M_Functions.ttcn 96.9 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 32
		function f_cf01Up() runs on AeSimu {
			
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
			// Connect
44
						
45
			//Initialze the IUT
46
							
47
		} // end f_cf01Up
48
		
49 50 51
		/**
		 * @desc Ports mapping and default behaviour activation for Config 02
		 */
52
		function f_cf02Up() runs on AeSimu {
53
				
54
			// Variables
55
			vc_config := e_cf02;
56
			vc_cseSimu := CseSimu.create("CSE1") alive;
57
				
58 59
			// Map
			map(self:mcaPort, system:mcaPort);
60
			map(vc_cseSimu:mccPort, system:mccPort);
61 62
			map(self:acPort, system:acPort);
			activate(a_default());
63
			activate(a_cse_aeSimu());
64
				
65
			// Connect
66
			f_connectInfoPort(vc_cseSimu);
67
			//Initialze the IUT
68
							
69
		} // end f_cf02Up
70
		
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92
		/**
		 * @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
			map(self:mccPort, system:mcaPort);
			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
		
93 94 95
		/**
		 * @desc Ports mapping and default behaviour activation for Config 03
		 */
96
		function f_cf03Up() runs on CseSimu {
97 98
		
			// Variables
99 100
			vc_config := e_cf03;
			
101 102 103 104
			// Map
			map(self:mcaPort, system:mcaPort);
			map(self:acPort, system:acPort);
			activate(a_default());
105
			activate(a_ae_cf03());
106 107 108 109 110 111 112
		
			// Connect
					
			//Initialze the IUT
					
		} // end f_cf03Up
		
113 114 115
		/**
		 * @desc Ports mapping and default behaviour activation for Config 04
		 */
116
		function f_cf04Up() runs on CseSimu {
117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136

			// 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 
		 */
137
		/*function f_cfCseTesterDown() runs on Tester {
138 139 140 141 142 143 144 145 146 147 148
		
			if(vc_config == e_cf01) {
				f_cf01Down()
			} else if (vc_config == e_cf02){
				f_cf02Down()
			} 
		}
		/**
		 * @desc Ports unmapping
		 * @verdict 
		 */
149
		/*function f_cfAeTesterDown() runs on AeSimu {
150 151 152 153
		
			if(vc_config == e_cf03) {
				f_cf03Down()
			} 
154
		}	
155 156 157
		/**
		 * @desc Ports unmapping
		 * @verdict 
158
		 */
159
		function f_cf01Down() runs on AeSimu {
160
		
161
			unmap(self:mcaPort, system:mcaPort);
162 163
			unmap(self:acPort, system:acPort);
		}	
164 165 166 167
		/**
		 * @desc Ports unmapping
		 * @verdict 
		 */
168
		function f_cf02Down() runs on AeSimu {
169
		
170
			unmap(self:mcaPort, system:mcaPort);
171 172 173 174 175 176 177 178 179 180
			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 {
				
181
			unmap(self:mccPort, system:mccPort);
182
			unmap(vc_aeSimu:mcaPort, system:mcaPort);
183
			unmap(self:acPort, system:acPort);
184
			unmap(vc_aeSimu:acPort, system:acPort);
185
		}		
186 187 188
		/**
		 * @desc Ports unmapping for Config 03
		 */
189
		function f_cf03Down() runs on CseSimu {
190 191 192 193 194 195 196 197
			
			unmap(self:mcaPort, system:mcaPort);
			unmap(self:acPort, system:acPort);
		}
		
		/**
		 * @desc Ports unmapping for Config 04
		 */
198
		function f_cf04Down() runs on CseSimu {
199 200 201 202 203
	
			unmap(self:mccPort, system:mccPort);
			unmap(self:acPort, system:acPort);
		}
		
204 205 206 207 208 209 210 211 212 213
		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);		
		} 
		
214
	}//end group configFunctions
215
	
216
	group CseFunctions {
217
	
218
		group PreambleFunctions {
219 220 221 222 223 224 225

			/**
			 * @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 
			 */
226
			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
227
			
228
				return f_cse_createAccessControlPolicyAux(p_acpName, -, p_allowedOperations);
229
			
230 231
			}

232
	
233 234 235 236 237 238
			/**
			 * @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 
			 */
239
			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
240
			
241 242 243
				var RequestPrimitive v_request;
				var MsgIn v_response;
				var integer v_aeAuxIndex := -1;
244
								
245
				v_request := valueof(m_createAeAux(p_accessControlPolicyIDs, p_poaList));
246 247
				
				v_request := f_getCreateRequestPrimitive(int2, v_request, -1);
248 249
				
				mcaPort.send(m_request(v_request));
250
				
251 252 253 254
				tc_ac.start;
				alt {
					[] mcaPort.receive(mw_response(mw_responsePrimitiveOK)) -> value v_response {
						tc_ac.stop;
255 256 257 258 259
						setverdict(pass,__SCOPE__&":INFO: Application registered successfuly");
						if(ischosen(v_response.primitive.responsePrimitive.primitiveContent.aE)) {
							
							f_checkAttributesToBeSaved(int2, v_request, v_response.primitive.responsePrimitive);
							
260
							vc_aeAuxIndex := f_setResource(v_response.primitive.responsePrimitive.primitiveContent, int2);
261
							
262 263
							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)));
264 265
							} else {
								f_sendAcPrimitive("AE-ID_changed", "0");
266 267
							}
						}
268 269 270
					}
					[] mcaPort.receive(mw_response(mw_responsePrimitiveKO)) {
						tc_ac.stop;
271
						setverdict(inconc, __SCOPE__&":INFO: Error while registering application");
272 273 274 275
						stop;
					}
					[] mcaPort.receive {
						tc_ac.stop;
276
						setverdict(inconc, __SCOPE__&":INFO: Unexpected message received");
277
						stop;
278
					};
279
					[] tc_ac.timeout {
280
						setverdict(inconc, __SCOPE__&":INFO: No answer while registering resource");
281 282 283
						stop;
					}
				}	
284
				
285
				f_checkAeSimuStatus();
286
				return vc_aeAuxIndex;
287
			
288
			}
289
			
290 291 292 293 294 295
			/**
			 * @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 
			 */
296
			function f_cse_preamble_registerAeWithId(XSD.ID p_appId, in template (value) AccessControlOperations p_allowedOperations := int63) runs on AeSimu return integer {//c_CRUDNDi
297
			
298 299 300
				var RequestPrimitive v_request;
				var integer v_aeAuxIndex := -1;
				var integer v_acpAuxIndex := -1;
301
			
302 303 304 305
				if(PICS_ACP_SUPPORT){
					v_acpAuxIndex := f_cse_createAccessControlPolicyAux(p_allowedOperations := p_allowedOperations);
					vc_acpAuxIndex := v_acpAuxIndex;
				}
306
				
307 308 309
				if(v_acpAuxIndex != -1) {
					vc_resourcesIndexToBeDeleted := {v_acpAuxIndex};
					v_request := valueof(m_createAe(p_appId, {f_getResourceId(vc_resourcesList[v_acpAuxIndex].resource)}, -));
310
					
311 312
					//TODO Test, to be removed
					v_request.to_ := f_getResourceAddress();
313
					
314 315 316 317 318 319 320
					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 {
321
					[] mcaPort.receive(mw_response(mw_responsePrimitiveOK)) -> value vc_response {
322
						tc_ac.stop;
323
						setverdict(pass, __SCOPE__&": INFO: Application registered successfuly");
324
						if(ischosen(vc_response.primitive.responsePrimitive.primitiveContent.aE)) {
325
							
326
							vc_aeAuxIndex := f_setResource(vc_response.primitive.responsePrimitive.primitiveContent, int2);
327
							
328 329
							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)));
330 331 332 333 334
							} else {
								f_sendAcPrimitive("AE-ID_changed", "0");
							}	
						}
					}
335 336
					[] mcaPort.receive(mw_response(mw_responsePrimitiveKO))
					{
337
						tc_ac.stop;
338
						setverdict(inconc, __SCOPE__&":INFO: Error while registering application");
339 340 341 342
						stop;
					}
					[] mcaPort.receive {
						tc_ac.stop;
343
						setverdict(inconc, __SCOPE__&":INFO: Unexpected message received");
344 345 346
						stop;
					}
					[] tc_ac.timeout {
347
						setverdict(inconc, __SCOPE__&":INFO: No answer while registering resource");
348 349 350
						stop;
					}
				}	
351
				
352
				f_checkAeSimuStatus();
353
				return vc_aeAuxIndex;
354
			
355
			}
356
			
357
			function f_cse_preamble_createServiceSubscribedAppRule(in template ListOfM2MID p_allowedAEs := {""}) runs on AeSimu return integer {//c_CRUDNDi
358
			
359
				var integer v_serviceSubscribedAppRuleIndex := -1;
360
	
361
				v_serviceSubscribedAppRuleIndex := f_cse_createResource(int19, m_createServiceSubscribedAppRule({"None"}, {PX_APP_ID}, valueof(p_allowedAEs)));
362
				
363
				return v_serviceSubscribedAppRuleIndex;
364
			
365
			}
366
			
367
			function f_cse_preamble_subscriptionVerification(out AeSimu p_notifyHandler,in integer p_aeIndex, inout integer p_ae2Index, inout template RequestPrimitive p_createRequestPrimitive,in ResourceType p_resourceType, in ResponseStatusCode p_responseStatusCode := int2001) runs on AeSimu {
368
				if(p_resourceType == int23){
369 370 371
					p_notifyHandler := AeSimu.create("NotifyHandler") alive;
					p_notifyHandler.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
					p_ae2Index := f_getResource(p_notifyHandler);
372 373
					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)}; 
374
					}
375
					p_notifyHandler.start(f_cse_notifyProcedure_subscriptionVerificationHandler(p_aeIndex, p_responseStatusCode));
376 377
				}
			}
378
		
379
		}//end group preambleFunctions
380 381 382
		
		group PostambleFunctions {
	
383 384 385 386
			/**
			 * @desc Deletion of all resources created during the test case execution. IUT gets clean and ready for next execution
			 * @verdict 
			 */
387
			function f_cse_postamble_deleteResources() runs on AeSimu {
388 389 390
				var integer i;
				var XSD.ID v_resourceAddress;
				var RequestPrimitive v_request;
391
				
392
				if (PX_RUN_POSTAMBLE) {
393
					
394 395 396 397
					for(i := lengthof(vc_resourcesIndexToBeDeleted) -1; i >=0; i := i - 1) {
						
						v_resourceAddress := f_getResourceAddress(vc_resourcesIndexToBeDeleted[i]); 
						
398
						v_request := valueof(m_delete(v_resourceAddress, f_getOriginator(vc_resourcesIndexToBeDeleted[i])));
399 400
						
						v_request.from_ := f_getOriginator(vc_resourcesIndexToBeDeleted[i]);
401

402
						mcaPort.send(m_request(v_request));
403
						
404 405 406 407
						tc_ac.start;
						alt {
							[] mcaPort.receive(mw_response(mw_responsePrimitiveOK)) {
								tc_ac.stop;
408
								log(__SCOPE__&" INFO: Resource " & v_request.to_ & " deleted");
409 410 411
							}
							[] mcaPort.receive(mw_response(mw_responsePrimitiveKO)) {
								tc_ac.stop;
412
								log(__SCOPE__&" INFO: Error while deleting resource " & v_request.to_);
413 414
							}
							[] tc_ac.timeout {
415
								log(__SCOPE__&" INFO: No answer while deleting resource " & v_request.to_);
416 417
							}	
						}	
418
						
419 420
					}
				}
421
						
422
			}
423
			
424 425 426 427
			/**
			 * @desc Deletion of all resources created during the test case execution. IUT gets clean and ready for next execution
			 * @verdict 
			 */
428
			function f_cse_postamble_deleteResourcesCSE() runs on CseSimu {
429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462
				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_);
							}	
						}	
			
					}
				}
			
463
			}
464
			
465
			function f_is_component_done(in Tester p_notifyHandler) runs on Tester {
466
			
467 468 469 470 471 472
				tc_ac.start(10.0);
				alt {
					[] p_notifyHandler.done {
					tc_ac.stop;
					}
					[] tc_ac.timeout {
473
						setverdict(inconc, __SCOPE__ & "INFO: Notify verification not received");
474 475 476
					}
				}
			} //end f_is_component_done
477
			
478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496
			/**
				@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;
					
			}
497
			
498 499 500 501 502 503 504 505 506 507 508 509 510 511
						
			/**
				@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 {
					}
				}
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 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555
				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 {
						v_resourceIndex := f_setResource(v_resource.resource, v_resource.resourceType, v_resource.parentIndex);
					}
				}
		
				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 {
						v_resourceIndex := f_setResource(v_resource.resource, v_resource.resourceType, v_resource.parentIndex);
					}
				}
556
	
557 558
				f_disconnectInfoPort(p_ae);
				
559 560
				p_ae.done;
				
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 596 597
				return v_resourceIndex;
				
			}		
		
			function f_sendResponsePrimitive() runs on AeSimu {
		
				infoPort.send(vc_response.primitive.responsePrimitive);
					
			} 
			
			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 {
			
598 599 600 601 602 603 604 605
			/**
			 * @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 
			 */
606
			function f_cse_createResource(in ResourceType p_resourceType, template RequestPrimitive p_requestPrimitive := m_create, integer p_parentIndex := -1) runs on AeSimu return integer {
607
			
608 609
				var RequestPrimitive v_request;
				var integer v_resourceIndex := -1;
610
				
611
				v_request := f_getCreateRequestPrimitive(p_resourceType, p_requestPrimitive, p_parentIndex);
612
			
613 614 615
				mcaPort.send(m_request(v_request));
				tc_ac.start;
				alt {
616
					[] mcaPort.receive(mw_response(mw_responsePrimitiveOK)) -> value vc_response {
617
						tc_ac.stop;
618
						setverdict(pass, __SCOPE__&":INFO: Resource type " & int2str(enum2int(p_resourceType)) & " created successfuly");
619 620 621 622 623
						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;
						}
624 625 626
					}
					[] mcaPort.receive(mw_response(mw_responsePrimitiveKO)) {
						tc_ac.stop;
627
						setverdict(inconc, __SCOPE__&":INFO: Error while creating resource type " & int2str(enum2int(p_resourceType)));
628 629 630
					}
					[] mcaPort.receive {
						tc_ac.stop;
631
						setverdict(inconc, __SCOPE__&":INFO: Unexpected message received");
632 633
					}
					[] tc_ac.timeout {
634
						setverdict(inconc, __SCOPE__&":INFO: No answer while creating resource type " & int2str(enum2int(p_resourceType)));
635 636
					}
				}	
637
				
638
				f_checkAeSimuStatus();
639
				
640
				return v_resourceIndex;
641
		
642
			}
643
		
644 645 646 647 648 649 650
			/**
			 * @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 
			 */
651
			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;
652
				var integer v_acpAuxIndex := -1;
653
				
654
				v_request := valueof(m_createAcpAux(p_acpName := p_acpName, p_allowedOperations := p_allowedOperations));
655
				
656 657
				v_request := f_getCreateRequestPrimitive(int1, v_request, -1);
								
658 659 660
				mcaPort.send(m_request(v_request));
				tc_ac.start;
				alt {
661
					[] mcaPort.receive(mw_response(mw_responsePrimitiveOK)) -> value vc_response {
662
						tc_ac.stop;
663
						setverdict(pass, __SCOPE__&":INFO: Resource type " & int2str(1) & " created successfuly");
664 665
						f_checkAttributesToBeSaved(int1, v_request, vc_response.primitive.responsePrimitive);
						v_acpAuxIndex := f_setResource(vc_response.primitive.responsePrimitive.primitiveContent, int1);
666 667 668 669
						vc_acpAuxIndex := v_acpAuxIndex;
					}
					[] mcaPort.receive(mw_response(mw_responsePrimitiveKO)) {
						tc_ac.stop;
670
						setverdict(inconc, __SCOPE__&":INFO: Error while creating resource type " & int2str(1));
671 672 673
					}
					[] mcaPort.receive {
						tc_ac.stop;
674
						setverdict(inconc, __SCOPE__&":INFO: Unexpected message received");
675 676
					}
					[] tc_ac.timeout {
677
						setverdict(inconc, __SCOPE__&":INFO: No answer while creating resource type " & int2str(1));
678 679
					}
				}	
680
				
681
				f_checkAeSimuStatus();
682
			
683
				return v_acpAuxIndex;
684
	
685
			}
686 687
				
				
688 689 690 691 692 693
			/**
			 * @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 
			 */
694
			function f_cse_createContainerResourceAux (integer p_parentIndex := -1) runs on AeSimu return integer {
695
			
696 697 698
				var RequestPrimitive v_request;
				var integer v_acpAuxIndex := -1;
				var integer v_containerResourceIndex := -1;
699
				
700
				v_acpAuxIndex := f_cse_createAccessControlPolicyAux(p_acpName := c_acpAuxName);//"MyAcp_2"
701
				
702
				v_request := valueof(m_createContainerBase);
703 704 705
				v_request.primitiveContent.container.accessControlPolicyIDs := {f_getResourceId(vc_resourcesList[v_acpAuxIndex].resource)};
				v_request.primitiveContent.container.resourceName := "MyContainerAux";
				
706
				v_containerResourceIndex := f_cse_createResource(int3, v_request, p_parentIndex);
707
				
708
				return v_containerResourceIndex;		
709
		
710
			}
711
			
712 713 714 715 716
			/**
			 * @desc 
			 * @param p_requestPrimitive
			 * @verdict 
			 */
717
			function f_cse_updateResource(in RequestPrimitive p_requestPrimitive) runs on AeSimu {
718 719 720 721

				mcaPort.send(m_request(p_requestPrimitive));
				tc_ac.start;
				alt {
722
					[] mcaPort.receive(mw_response(mw_responsePrimitiveOK)) -> value vc_response {
723
						tc_ac.stop;
724
						setverdict(pass, __SCOPE__&":INFO: Attribute of resource updated successfuly");
725
					}
726
					[] mcaPort.receive(mw_response(mw_responsePrimitiveKO)) -> value vc_response {
727
						tc_ac.stop;
728
						setverdict(inconc, __SCOPE__&":INFO: Error while updating resource");
729 730 731
					}
					[] mcaPort.receive{
						tc_ac.stop;
732
						setverdict(inconc, __SCOPE__&":INFO: Unexpected message received");
733 734
					}
					[] tc_ac.timeout {
735
						setverdict(inconc, __SCOPE__&":INFO: No answer while updating resource");
736 737
					}
				}	
738
				
739
				f_checkAeSimuStatus();
740
				
741
			}// end f_cse_updateResource
742
			
743
			/**
744 745
			 * @desc 
			 * @param p_resourceIndex
746 747
			 * @verdict 
			 */
748
			function f_cse_retrieveResource(integer p_resourceIndex) runs on AeSimu return PrimitiveContent{
749 750

				mcaPort.send(m_request(m_retrieveResource(f_getResourceAddress(p_resourceIndex), f_getOriginator(p_resourceIndex))));
751 752
				tc_ac.start;
				alt {
753
					[] mcaPort.receive(mw_response(mw_responsePrimitiveOK)) -> value vc_response {
754
						tc_ac.stop;
755
						setverdict(pass, __SCOPE__&":INFO: Resource retrieved successfuly");
756
					}
757
					[] mcaPort.receive(mw_response(mw_responsePrimitiveKO)) -> value vc_response {
758 759 760 761
						tc_ac.stop;
						setverdict(inconc, __SCOPE__&":INFO: Error while retrieving resource");
					}
					[] mcaPort.receive{
762
						tc_ac.stop;
763
						setverdict(inconc, __SCOPE__&":INFO: Unexpected message received");
764 765
					}
					[] tc_ac.timeout {
766
						setverdict(inconc, __SCOPE__&":INFO: No answer while retrieving resource");
767
					}
768 769
				}	
				
770
				f_checkAeSimuStatus();
771
				
772
				return vc_response.primitive.responsePrimitive.primitiveContent;
773 774
				
			}// end f_cse_retrievingResource
775
			
776 777 778 779 780
			/**
			 * @desc 
			 * @param p_requestPrimitive
			 * @verdict 
			 */
781
			function f_cse_deleteResource(in integer p_index, in template (omit) RequestPrimitive p_requestPrimitive := omit) runs on AeSimu {
782 783 784
				var RequestPrimitive v_request;
				
				if(not isvalue(p_requestPrimitive)) {
785
					v_request := valueof(m_delete(f_getResourceAddress(p_index), f_getOriginator(p_index)));
786 787
				} else {
					v_request := valueof(p_requestPrimitive);
788
				}
789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808
				
				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_);
					}	
				}	
				
809
				f_checkAeSimuStatus();
810 811 812 813 814 815 816 817
				
			}// end f_cse_deleteResource
			
			/**
			 * @desc Check that a resource is present in the IUT (resourceId is known)
			 * @param p_resourceIndex Resource index 
			 * @return boolean
			 */
818
			function f_isResourcePresent (integer p_resourceIndex) runs on AeSimu return boolean {
819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839
			
				//Check to see if the resource is present or not
				mcaPort.send(m_request(m_retrieveResource(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(?, -))) {
						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;
840
			}
841 842 843 844 845 846 847
			
			/**
			 * @desc Check that a resource is not present in the IUT (resourceId is NOT known)
			 * @param p_parentIndex Index of the parent resource
			 * @param p_resourceName Resource name (Hierarchical method is used)
			 * @return boolean
			 */
848
			function f_isResourceNotPresent (integer p_parentIndex, XSD.String p_resourceName) runs on AeSimu return boolean {
849
			
850 851
				log(testcasename() & ":INFO: Hierarchical addressing method is required to check the non presence of the resource");
				
852
				//Check to see if the resource has NOT been created
853
				mcaPort.send(m_request(m_retrieveResource(f_getResourceAddress(p_parentIndex, e_hierarchical) & "/" & p_resourceName, f_getOriginator(p_parentIndex))));
854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878
				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 Update of the auxiliar ACP resource
			 * @param p_allowedOperations New allowed operations
			 * @verdict 
			 */
879
			function f_cse_updateAcpAuxResource (in template (value) AccessControlOperations p_allowedOperations) runs on AeSimu {
880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903
				var RequestPrimitive v_request;
				
				v_request := valueof(m_updateAcpBase);
				
				v_request.to_ := f_getResourceAddress(vc_acpAuxIndex);
				v_request.from_ := f_getOriginator(vc_acpAuxIndex);
				v_request.primitiveContent.accessControlPolicy.privileges.accessControlRule_list := {valueof(m_createAcr(PX_ACOR, p_allowedOperations))};
							
				mcaPort.send(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");
					}
					[] 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" );
					}
				}		
				
904
				f_checkAeSimuStatus();
905 906 907 908 909 910 911 912 913
			}   
			
			/**
			 * @desc Function to handle announcement of resources
			 * @param p_from
			 * @param p_to
			 * @verdict 
			 */
			 //TODO To finalize this function
914
			function f_cse_resourceAnnouncementHandler(template XSD.ID p_from := *, template XSD.ID p_to := ?) runs on CseSimu {
915 916 917 918 919 920
				// Local variables
				var MsgIn v_request;
				var ResponsePrimitive v_responsePrimitive;
				
				tc_ac.start;
				alt {
921
					[] mccPort.receive(mw_request(mw_create(p_from, p_to))) -> value v_request {