OneM2M_Functions.ttcn 117 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
 *  @desc       Module containing functions for oneM2M
 *
 */
module OneM2M_Functions {
	
	import from XSD all;
	import from OneM2M_Templates all;
18
	import from OneM2M_Types all;
19 20 21
	import from OneM2M_TypesAndValues all;
	import from OneM2M_TestSystem all;
	import from OneM2M_Pixits all;
22
	import from OneM2M_Pics all;
23
	
24 25
	group ConfigFunctions {
		
26 27 28
		/**
			@desc Ports mapping and default behaviour activation for Config 1
		*/
29
		function f_cf01Up(in boolean p_auxiliaryAe2Required := false) runs on AeSimu {
30
			
31
			// Variables
32 33
			vc_config := e_cf01;
			vc_testSystemRole := e_ae;	
34
			
35 36 37
			// Map
			map(self:mcaPort, system:mcaPort);
			map(self:acPort, system:acPort);
38
			
39
			activate(a_default());
40
			activate(a_cse_cf01());
41
				
42 43 44 45 46
			// Initialize AE2
			if(p_auxiliaryAe2Required) {
				vc_auxiliaryAe2Up := p_auxiliaryAe2Required;
				vc_ae2 := AeSimu.create("AE2") alive;
				vc_ae2.start(f_cf01UpAe2());
47
				vc_ae2.done;
48 49 50 51 52 53 54 55 56 57 58 59
			}
				
			//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
60 61
			vc_config := e_cf01;
			vc_testSystemRole := e_ae;		
62 63 64 65 66 67 68 69 70 71
			
			// 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
	
72
			//Initialze the IUT
73
							
74
		} // end f_cf01Up
75
		
76 77 78
		/**
		 * @desc Ports mapping and default behaviour activation for Config 02
		 */
79
		function f_cf02Up() runs on AeSimu {
80
				
81
			// Variables
82
			vc_config := e_cf02;
83
			vc_testSystemRole := e_ae;	
84
			vc_cse1 := CseSimu.create("CSE1") alive;
85
				
86 87 88 89
			// Map
			map(self:mcaPort, system:mcaPort);
			map(self:acPort, system:acPort);
			activate(a_default());
90 91 92
			activate(a_cse_cf02_ae1());
			vc_cse1.start(f_cf02UpCse1());
			vc_cse1.done;
93
				
94
			// Connect
95
			
96
			//Initialze the IUT
97
							
98
		} // end f_cf02Up
99 100 101 102 103 104 105
		
		/**
			@desc Ports mapping and default behaviour activation for Config 2 on the CSE1
		*/
		function f_cf02UpCse1() runs on CseSimu {
			
			// Variables
106 107
			vc_config := e_cf02;
			vc_testSystemRole := e_cse;		
108 109 110 111 112 113 114 115 116 117 118 119
			
			// Map
			map(self:mccPort, system:mccPort);
			map(self:mccPortIn, system:mccPortIn);
			map(self:acPort, system:acPort);
			
			activate(a_default());
			activate(a_cse_cf02_cse1());
			
			//Initialze the IUT
							
		} // end f_cf02UpCse1
120

121 122 123 124 125 126 127
		/**
		 * @desc Ports mapping and default behaviour activation for Config 02
		 */
		function f_cf02UpCseSimuMaster() runs on CseSimu {
				
			// Variables
			vc_config := e_cf02;
128
			vc_testSystemRole := e_cse;		
129
			vc_ae1 := AeSimu.create("AE1") alive;
130 131
				
			// Map
132
			map(self:mccPort, system:mccPort);
133
			map(self:mccPortIn, system:mccPortIn);
134 135
			map(self:acPort, system:acPort);
			activate(a_default());
136 137 138
			activate(a_cse_cf02_cse1());
			vc_ae1.start(f_cf02UpAe1());
			vc_ae1.done;
139 140
				
			// Connect
141
			
142 143 144 145
			//Initialze the IUT
							
		} // end f_cf02UpCseSimuMaster
		
146 147 148 149 150 151 152
		/**
			@desc Ports mapping and default behaviour activation for Config 2 on the AE1
		*/
		function f_cf02UpAe1() runs on AeSimu {
			
			// Variables
			vc_config := e_cf02;	
153
			vc_testSystemRole := e_ae;		
154 155 156 157 158 159 160 161 162 163 164 165
			
			// Map
			map(self:mcaPort, system:mcaPort);
			map(self:acPort, system:acPort);
			
			activate(a_default());
			activate(a_cse_cf02_ae1());
			
			//Initialze the IUT
							
		} // end f_cf02UpAe1
		
166 167 168
		/**
		 * @desc Ports mapping and default behaviour activation for Config 03
		 */
169
		function f_cf03Up() runs on CseSimu {
170 171
		
			// Variables
172
			vc_config := e_cf03;
173
			vc_testSystemRole := e_cse;		
174
			
175
			// Map
176
			map(self:mcaPort, system:mcaPort);//TODO To be consistent, we should use mcaPortIn for AE testing
177
			map(self:acPort, system:acPort);
178
			map(self:utPort, system:utPort);
179
			activate(a_default());
180
			activate(a_ae_cf03());
181 182 183 184 185 186 187
		
			// Connect
					
			//Initialze the IUT
					
		} // end f_cf03Up
		
188 189 190
		/**
		 * @desc Ports mapping and default behaviour activation for Config 04
		 */
191
		function f_cf04Up() runs on CseSimu {
192 193 194

			// Variables
			vc_config := e_cf04;
195
			vc_testSystemRole := e_cse;		
196 197 198
	
			// Map
			map(self:mccPort, system:mccPort);
199
			map(self:mccPortIn, system:mccPortIn);
200 201 202 203 204 205 206 207 208 209 210 211
			map(self:acPort, system:acPort);
			activate(a_default());
			activate(a_cse_cf04());

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

		/**
		 * @desc Ports unmapping
212
		 */
213
		function f_cf01Down() runs on AeSimu {
214
		
215
			unmap(self:mcaPort, system:mcaPort);
216
			unmap(self:acPort, system:acPort);
217 218 219
			if(vc_auxiliaryAe2Up) {
				vc_ae2.start(f_cf01DownAe2());
			}
220 221 222 223 224
		}
		
		/**
		 * @desc Ports unmapping
		 */
225 226 227
		function f_cf01DownAe2() runs on AeSimu {
				
			unmap(self:mcaPort, system:mcaPort);
228
			unmap(self:acPort, system:acPort);
229
			unmap(self:mcaPortIn, system:mcaPortIn);
230 231
		}
		
232 233 234
		/**
		 * @desc Ports unmapping
		 */
235
		function f_cf02Down() runs on AeSimu {
236
		
237
			unmap(self:mcaPort, system:mcaPort);
238
			unmap(self:acPort, system:acPort);
239 240 241
			unmap(vc_cse1:mccPort, system:mccPort);
			unmap(vc_cse1:mccPortIn, system:mccPortIn);
			unmap(vc_cse1:acPort, system:acPort);
242 243 244 245 246 247
		}		
		/**
		 * @desc Ports unmapping
		 */
		function f_cf02DownCseSimuMaster() runs on CseSimu {
				
248
			unmap(self:mccPort, system:mccPort);
249
			unmap(self:mccPortIn, system:mccPortIn);
250
			unmap(self:acPort, system:acPort);
251 252
			unmap(vc_ae1:mcaPort, system:mcaPort);
			unmap(vc_ae1:acPort, system:acPort);
253
		}		
254 255 256
		/**
		 * @desc Ports unmapping for Config 03
		 */
257
		function f_cf03Down() runs on CseSimu {
258 259
			
			unmap(self:mcaPort, system:mcaPort);
260
			unmap(self:utPort, system:utPort);
261 262 263 264 265 266
			unmap(self:acPort, system:acPort);
		}
		
		/**
		 * @desc Ports unmapping for Config 04
		 */
267
		function f_cf04Down() runs on CseSimu {
268 269
	
			unmap(self:mccPort, system:mccPort);
270
			unmap(self:mccPortIn, system:mccPortIn);
271 272
			unmap(self:acPort, system:acPort);
		}
273 274 275 276 277 278 279 280 281

	}//end group configFunctions
	
	group InfoPortCommunication {
	
		/**
		 * @desc Connection of InfoPort of two components
		 * @param p_tester PTC where InfoPort is to be connected
		 */
282 283 284 285 286
		function f_connectInfoPort(in Tester p_tester) runs on Tester {
			// Connect
			connect(self:infoPort, p_tester:infoPort);		
		} 
	
287 288 289 290
		/**
		 * @desc Disconnection of InfoPort of two components
		 * @param p_tester PTC where InfoPort is to be connected
		 */
291 292 293 294
		function f_disconnectInfoPort(in Tester p_tester) runs on Tester {
			// Disconnect
			disconnect(self:infoPort, p_tester:infoPort);		
		} 
295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315
	
		/**
		 * @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 {
				}
			}
	
			f_disconnectInfoPort(p_component);
				
			return v_response;
				
		}
316
		
317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 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 463 464 465
		/**
		 * @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 {
				}
			}

			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 {
				}
			}
	
			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;
			
			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, false);
				}
			}
	
			f_disconnectInfoPort(p_cse);
				
			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_getResource(in Tester p_component, in integer p_resourceIndex := -1) runs on Tester return integer {
			var MyResource v_resource;
			var integer v_resourceIndex := -1;
		
			f_connectInfoPort(p_component);

			p_component.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, false);
				}
			}

			f_disconnectInfoPort(p_component);
			
			return v_resourceIndex;
			
		}		

		/**
		 * @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_aeAuxIndex]);
				
		} 		
		
		/**
		 * @desc Sending of a specific resource through InfoPort
		 * @param p_resourceIndex Index of resource to be sent
		 */	
		function f_sendResource(in integer p_resourceIndex) runs on Tester {
	
			if(p_resourceIndex == -1) {
				infoPort.send(vc_resourcesList[vc_aeAuxIndex]);  //TODO To send Ae or RemoteCSE depending on the component type
			} else {
				infoPort.send(vc_resourcesList[p_resourceIndex]);
			}
				
		} 	
	
	}// end of gropu InfoPortCommunication	
466
	
467
	group CseFunctions {
468
	
469
		group PreambleFunctions {
470 471 472 473 474 475 476

			/**
			 * @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 
			 */
477
			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
478
			
479
				return f_cse_createAccessControlPolicyAux(p_acpName, -, p_allowedOperations);
480
			
481 482
			}

483
	
484
			/**
485 486 487
			 * @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
488 489 490
			 * @return Internal AE resource index
			 * @verdict 
			 */
491
			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
492
			
493 494 495
				var RequestPrimitive v_request;
				var MsgIn v_response;
				var integer v_aeAuxIndex := -1;
496
								
497
				v_request := valueof(m_createAeAux(p_accessControlPolicyIDs, p_poaList));
498 499
				
				v_request := f_getCreateRequestPrimitive(int2, v_request, -1);
500 501
				
				mcaPort.send(m_request(v_request));
502
				
503 504 505 506
				tc_ac.start;
				alt {
					[] mcaPort.receive(mw_response(mw_responsePrimitiveOK)) -> value v_response {
						tc_ac.stop;
507 508 509 510 511
						setverdict(pass,__SCOPE__&":INFO: Application registered successfuly");
						if(ischosen(v_response.primitive.responsePrimitive.primitiveContent.aE)) {
							
							f_checkAttributesToBeSaved(int2, v_request, v_response.primitive.responsePrimitive);
							
512
							vc_aeAuxIndex := f_setResource(v_response.primitive.responsePrimitive.primitiveContent, int2);
513
							
514 515
							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)));
516 517
							} else {
								f_sendAcPrimitive("AE-ID_changed", "0");
518 519
							}
						}
520 521 522
					}
					[] mcaPort.receive(mw_response(mw_responsePrimitiveKO)) {
						tc_ac.stop;
523
						setverdict(inconc, __SCOPE__&":INFO: Error while registering application");
524 525 526 527
						stop;
					}
					[] mcaPort.receive {
						tc_ac.stop;
528
						setverdict(inconc, __SCOPE__&":INFO: Unexpected message received");
529
						stop;
530
					};
531
					[] tc_ac.timeout {
532
						setverdict(inconc, __SCOPE__&":INFO: No answer while registering resource");
533 534 535
						stop;
					}
				}	
536
				
537
				f_checkAeSimuStatus();
538
				return vc_aeAuxIndex;
539
			}
540
			
541 542 543
			/**
			 * @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
544
			 * @param p_appId AppID of the AE resource to be created
545 546 547
			 * @return Internal AE resource index
			 * @verdict 
			 */
548
			function f_cse_preamble_registerAeWithId(XSD.ID p_appId, in template (value) AccessControlOperations p_allowedOperations := int63) runs on AeSimu return integer {//c_CRUDNDi
549
			
550 551 552
				var RequestPrimitive v_request;
				var integer v_aeAuxIndex := -1;
				var integer v_acpAuxIndex := -1;
553
			
554 555 556 557
				if(PICS_ACP_SUPPORT){
					v_acpAuxIndex := f_cse_createAccessControlPolicyAux(p_allowedOperations := p_allowedOperations);
					vc_acpAuxIndex := v_acpAuxIndex;
				}
558
				
559 560 561
				if(v_acpAuxIndex != -1) {
					vc_resourcesIndexToBeDeleted := {v_acpAuxIndex};
					v_request := valueof(m_createAe(p_appId, {f_getResourceId(vc_resourcesList[v_acpAuxIndex].resource)}, -));
562
					
563 564
					//TODO Test, to be removed
					v_request.to_ := f_getResourceAddress();
565
					
566 567 568 569 570 571 572
					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 {
573
					[] mcaPort.receive(mw_response(mw_responsePrimitiveOK)) -> value vc_response {
574
						tc_ac.stop;
575
						setverdict(pass, __SCOPE__&": INFO: Application registered successfuly");
576
						if(ischosen(vc_response.primitive.responsePrimitive.primitiveContent.aE)) {
577
							
578
							vc_aeAuxIndex := f_setResource(vc_response.primitive.responsePrimitive.primitiveContent, int2);
579
							
580 581
							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)));
582 583 584 585 586
							} else {
								f_sendAcPrimitive("AE-ID_changed", "0");
							}	
						}
					}
587 588
					[] mcaPort.receive(mw_response(mw_responsePrimitiveKO))
					{
589
						tc_ac.stop;
590
						setverdict(inconc, __SCOPE__&":INFO: Error while registering application");
591 592 593 594
						stop;
					}
					[] mcaPort.receive {
						tc_ac.stop;
595
						setverdict(inconc, __SCOPE__&":INFO: Unexpected message received");
596 597 598
						stop;
					}
					[] tc_ac.timeout {
599
						setverdict(inconc, __SCOPE__&":INFO: No answer while registering resource");
600 601 602
						stop;
					}
				}	
603
				
604
				f_checkAeSimuStatus();
605
				return vc_aeAuxIndex;
606
			
607
			}
608
			
609 610 611 612 613 614
			/**
			 * @desc Creation of ServiceSubscribedAppRule resource
			 * @param p_allowedAEs Allowed AEs
			 * @return Internal resource index
			 * @verdict 
			 */
615
			function f_cse_preamble_createServiceSubscribedAppRule(in template ListOfM2MID p_allowedAEs := {""}) runs on AeSimu return integer {//c_CRUDNDi
616
			
617
				var integer v_serviceSubscribedAppRuleIndex := -1;
618
	
619
				v_serviceSubscribedAppRuleIndex := f_cse_createResource(int19, m_createServiceSubscribedAppRule({"None"}, {PX_APP_ID}, valueof(p_allowedAEs)));
620
				
621
				return v_serviceSubscribedAppRuleIndex;
622
			
623
			}
624
			
625 626 627 628 629 630
			/**
			 * @desc Creation of SubscribedProfile resource
			 * @param p_allowedAEs Allowed AEs
			 * @return Internal resource index
			 * @verdict 
			 */
631 632 633 634 635 636
			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;
				
637
				//TODO Create/Update serviceSubscribedNode //m_request.primitiveContent.m2mServiceSubscriptionProfile.choice.choice_list[0].serviceSubscribedNode := m_contentServiceSubscribedNode;
638 639 640 641 642 643 644 645
				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;
	
			}
			
646 647 648 649 650 651 652 653
			/**
			 * @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 
			 */
654
			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 {
655
				if(p_resourceType == int23){
656 657 658 659 660 661
					
					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);
662 663
					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)}; 
664
					}
665
					vc_ae2.start(f_cse_notifyProcedure_subscriptionVerificationHandler(p_responseStatusCode));
666 667
				}
			}
668
		
669
		}//end group preambleFunctions
670 671 672
		
		group PostambleFunctions {
	
673
			/**
674
			 * @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
675 676
			 * @verdict 
			 */
677
			function f_cse_postamble_deleteResources() runs on AeSimu {
678 679 680
				var integer i;
				var XSD.ID v_resourceAddress;
				var RequestPrimitive v_request;
681
				
682
				if (PX_RUN_POSTAMBLE) {
683
					
684 685 686 687
					if(vc_auxiliaryAe2Up) {
						f_cse_postamble_aeSimu(vc_ae2);
					}
					
688 689 690 691
					for(i := lengthof(vc_resourcesIndexToBeDeleted) -1; i >=0; i := i - 1) {
						
						v_resourceAddress := f_getResourceAddress(vc_resourcesIndexToBeDeleted[i]); 
						
692
						v_request := valueof(m_delete(v_resourceAddress, f_getOriginator(vc_resourcesIndexToBeDeleted[i])));
693 694
						
						v_request.from_ := f_getOriginator(vc_resourcesIndexToBeDeleted[i]);
695

696
						mcaPort.send(m_request(v_request));
697
						
698 699 700 701
						tc_ac.start;
						alt {
							[] mcaPort.receive(mw_response(mw_responsePrimitiveOK)) {
								tc_ac.stop;
702
								log(__SCOPE__&" INFO: Resource " & v_request.to_ & " deleted");
703 704 705
							}
							[] mcaPort.receive(mw_response(mw_responsePrimitiveKO)) {
								tc_ac.stop;
706
								log(__SCOPE__&" INFO: Error while deleting resource " & v_request.to_);
707 708
							}
							[] tc_ac.timeout {
709
								log(__SCOPE__&" INFO: No answer while deleting resource " & v_request.to_);
710 711
							}	
						}	
712
						
713 714
					}
				}
715
						
716
			}
717
			
718
			/**
719
			 * @desc Calls to postamble for AeSimu components (i.e. AE2)
720 721 722 723 724 725 726 727 728
			 * @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());
			}
			
729 730 731 732
			/**
			 * @desc Deletion of all resources created during the test case execution. IUT gets clean and ready for next execution
			 * @verdict 
			 */
733
			function f_cse_postamble_deleteResourcesCSE() runs on CseSimu {
734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767
				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_);
							}	
						}	
			
					}
				}
			
768
			}			
769 770 771 772 773
			
		}//end group postambleFunctions
		
		group AeSimuFunctions {
			
774 775 776
			/**
			 * @desc Creation of a resource
			 * @param p_resourceType Resource type of the resource to be created
777
			 * @param p_requestPrimitive CREATE request primitive for the resource to be created
778 779 780 781
			 * @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 
			 */
782
			function f_cse_createResource(in ResourceType p_resourceType, template RequestPrimitive p_requestPrimitive := m_create, integer p_parentIndex := -1) runs on AeSimu return integer {
783
			
784 785
				var RequestPrimitive v_request;
				var integer v_resourceIndex := -1;
786
				
787
				v_request := f_getCreateRequestPrimitive(p_resourceType, p_requestPrimitive, p_parentIndex);
788
			
789 790 791
				mcaPort.send(m_request(v_request));
				tc_ac.start;
				alt {
792
					[] mcaPort.receive(mw_response(mw_responsePrimitiveOK)) -> value vc_response {
793
						tc_ac.stop;
794
						setverdict(pass, __SCOPE__&":INFO: Resource type " & int2str(enum2int(p_resourceType)) & " created successfuly");
795 796 797 798 799
						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;
						}
800 801 802
					}
					[] mcaPort.receive(mw_response(mw_responsePrimitiveKO)) {
						tc_ac.stop;
803
						setverdict(inconc, __SCOPE__&":INFO: Error while creating resource type " & int2str(enum2int(p_resourceType)));
804 805 806
					}
					[] mcaPort.receive {
						tc_ac.stop;
807
						setverdict(inconc, __SCOPE__&":INFO: Unexpected message received");
808 809
					}
					[] tc_ac.timeout {
810
						setverdict(inconc, __SCOPE__&":INFO: No answer while creating resource type " & int2str(enum2int(p_resourceType)));
811 812
					}
				}	
813
				
814
				f_checkAeSimuStatus();
815
				
816
				return v_resourceIndex;
817
		
818
			}
819
		
820 821 822 823 824 825 826
			/**
			 * @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 
			 */
827
			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;
828
				var integer v_acpAuxIndex := -1;
829
				
830
				v_request := valueof(m_createAcpAux(p_acpName := p_acpName, p_allowedOperations := p_allowedOperations));
831
				
832 833
				v_request := f_getCreateRequestPrimitive(int1, v_request, -1);
								
834 835 836
				mcaPort.send(m_request(v_request));
				tc_ac.start;
				alt {
837
					[] mcaPort.receive(mw_response(mw_responsePrimitiveOK)) -> value vc_response {
838
						tc_ac.stop;
839
						setverdict(pass, __SCOPE__&":INFO: Resource type " & int2str(1) & " created successfuly");
840 841
						f_checkAttributesToBeSaved(int1, v_request, vc_response.primitive.responsePrimitive);
						v_acpAuxIndex := f_setResource(vc_response.primitive.responsePrimitive.primitiveContent, int1);
842 843 844 845
						vc_acpAuxIndex := v_acpAuxIndex;
					}
					[] mcaPort.receive(mw_response(mw_responsePrimitiveKO)) {
						tc_ac.stop;
846
						setverdict(inconc, __SCOPE__&":INFO: Error while creating resource type " & int2str(1));
847 848 849
					}
					[] mcaPort.receive {
						tc_ac.stop;
850
						setverdict(inconc, __SCOPE__&":INFO: Unexpected message received");
851 852
					}
					[] tc_ac.timeout {
853
						setverdict(inconc, __SCOPE__&":INFO: No answer while creating resource type " & int2str(1));
854 855
					}
				}	
856
				
857
				f_checkAeSimuStatus();
858
			
859
				return v_acpAuxIndex;
860
	
861
			}
862
							
863
			/**
864 865
			 * @desc Message exchange for the update of a resource
			 * @param p_requestPrimitive UPDATE request primitive to be used
866 867
			 * @verdict 
			 */
868
			function f_cse_updateResource(in RequestPrimitive p_requestPrimitive) runs on AeSimu {
869 870 871 872

				mcaPort.send(m_request(p_requestPrimitive));
				tc_ac.start;
				alt {
873
					[] mcaPort.receive(mw_response(mw_responsePrimitiveOK)) -> value vc_response {
874
						tc_ac.stop;
875
						setverdict(pass, __SCOPE__&":INFO: Attribute of resource updated successfuly");
876
					}
877
					[] mcaPort.receive(mw_response(mw_responsePrimitiveKO)) -> value vc_response {
878
						tc_ac.stop;
879
						setverdict(inconc, __SCOPE__&":INFO: Error while updating resource");
880 881 882
					}
					[] mcaPort.receive{
						tc_ac.stop;
883
						setverdict(inconc, __SCOPE__&":INFO: Unexpected message received");
884 885
					}
					[] tc_ac.timeout {
886
						setverdict(inconc, __SCOPE__&":INFO: No answer while updating resource");
887 888
					}
				}	
889
				
890
				f_checkAeSimuStatus();
891
				
892
			}// end f_cse_updateResource
893
			
894
			/**
895 896 897
			 * @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
898 899
			 * @verdict 
			 */
900
			function f_cse_retrieveResource(integer p_resourceIndex) runs on AeSimu return PrimitiveContent{
901 902

				mcaPort.send(m_request(m_retrieveResource(f_getResourceAddress(p_resourceIndex), f_getOriginator(p_resourceIndex))));
903 904
				tc_ac.start;
				alt {
905
					[] mcaPort.receive(mw_response(mw_responsePrimitiveOK)) -> value vc_response {
906
						tc_ac.stop;
907
						setverdict(pass, __SCOPE__&":INFO: Resource retrieved successfuly");
908
					}
909
					[] mcaPort.receive(mw_response(mw_responsePrimitiveKO)) -> value vc_response {
910 911 912 913
						tc_ac.stop;
						setverdict(inconc, __SCOPE__&":INFO: Error while retrieving resource");
					}
					[] mcaPort.receive{
914
						tc_ac.stop;
915
						setverdict(inconc, __SCOPE__&":INFO: Unexpected message received");
916 917
					}
					[] tc_ac.timeout {
918
						setverdict(inconc, __SCOPE__&":INFO: No answer while retrieving resource");
919
					}
920 921
				}	
				
922
				f_checkAeSimuStatus();
923
				
924
				return vc_response.primitive.responsePrimitive.primitiveContent;
925
				
Miguel Angel Reina Ortega's avatar