OneM2M_Functions.ttcn 138 KB
Newer Older
1 2 3 4 5 6 7
/**
 *  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.
 *  
8 9 10
 *  @author     ETSI
 *  @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
 *  @desc       Module containing functions for oneM2M
 *
 */
module OneM2M_Functions {
	
	import from XSD all;
17
	import from LibCommon_Time all;
18
	import from OneM2M_Templates all;
19
	import from OneM2M_Types all;
20 21 22
	import from OneM2M_TypesAndValues all;
	import from OneM2M_TestSystem all;
	import from OneM2M_Pixits all;
23
	import from OneM2M_Pics all;
24
	
25
	group ConfigFunctions {
26
		
27 28 29
		/**
			@desc Ports mapping and default behaviour activation for Config 1
		*/
30 31
		function f_cf01Up(in boolean p_auxiliaryAe2Required := false) runs on AeSimu {
			
32
			// Variables
33 34
			vc_config := e_cf01;
			vc_testSystemRole := e_ae;	
35
			
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
			// Initialize AE2
			if(p_auxiliaryAe2Required) {
				vc_auxiliaryAe2Up := p_auxiliaryAe2Required;
				vc_ae2 := AeSimu.create("AE2") alive;
				vc_ae2.start(f_cf01UpAe2());
48
				vc_ae2.done;
49 50 51 52 53 54 55 56 57 58 59 60
			}
				
			//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
61 62
			vc_config := e_cf01;
			vc_testSystemRole := e_ae;		
63 64 65 66 67 68 69 70 71 72
			
			// 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
	
73
			//Initialze the IUT
74
							
75
		} // end f_cf01Up
76
		
77 78 79
		/**
		 * @desc Ports mapping and default behaviour activation for Config 02
		 */
80
		function f_cf02Up() runs on AeSimu {
81
				
82
			// Variables
83
			vc_config := e_cf02;
84
			vc_testSystemRole := e_ae;	
85
			vc_cse1 := CseSimu.create("CSE1") alive;
86
				
87 88 89
			// Map
			map(self:mcaPort, system:mcaPort);
			map(self:acPort, system:acPort);
90 91 92
			if(PX_UT_IMPLEMENTED) {
				map(self:utPort, system:utPort);
			}
93
			activate(a_default());
94 95 96
			activate(a_cse_cf02_ae1());
			vc_cse1.start(f_cf02UpCse1());
			vc_cse1.done;
97
				
98
			// Connect
99
			
100
			//Initialze the IUT
101
							
102
		} // end f_cf02Up
103 104 105 106 107 108 109
		
		/**
			@desc Ports mapping and default behaviour activation for Config 2 on the CSE1
		*/
		function f_cf02UpCse1() runs on CseSimu {
			
			// Variables
110
			var PrimitiveContent v_cSEBaseResource;
111 112
			vc_config := e_cf02;
			vc_testSystemRole := e_cse;		
113 114 115 116 117 118 119 120 121
			
			// Map
			map(self:mccPort, system:mccPort);
			map(self:mccPortIn, system:mccPortIn);
			map(self:acPort, system:acPort);
			
			activate(a_default());
			activate(a_cse_cf02_cse1());
			
122 123 124
			v_cSEBaseResource := f_cse_generateLocalResource(-, -1, int5);
			vc_cSEBaseIndex := f_setLocalResource(v_cSEBaseResource, int5, -1);
			
125 126 127
			//Initialze the IUT
							
		} // end f_cf02UpCse1
128 129 130 131 132 133 134

		/**
		 * @desc Ports mapping and default behaviour activation for Config 02
		 */
		function f_cf02UpCseSimuMaster() runs on CseSimu {
				
			// Variables
135 136
			var PrimitiveContent v_cSEBaseResource;
			vc_config := e_cf02CseSimuMaster;
137
			vc_testSystemRole := e_cse;		
138
			vc_ae1 := AeSimu.create("AE1") alive;
139 140 141
				
			// Map
			map(self:mccPort, system:mccPort);
142
			map(self:mccPortIn, system:mccPortIn);
143 144
			map(self:acPort, system:acPort);
			activate(a_default());
145 146 147
			activate(a_cse_cf02_cse1());
			vc_ae1.start(f_cf02UpAe1());
			vc_ae1.done;
148 149 150
			
			v_cSEBaseResource := f_cse_generateLocalResource(-, -1, int5);
			vc_cSEBaseIndex := f_setLocalResource(v_cSEBaseResource, int5, -1);
151 152
				
			// Connect
153
			
154 155 156
			//Initialze the IUT
							
		} // end f_cf02UpCseSimuMaster
157
		
158 159 160 161 162 163
		/**
			@desc Ports mapping and default behaviour activation for Config 2 on the AE1
		*/
		function f_cf02UpAe1() runs on AeSimu {
			
			// Variables
164
			vc_config := e_cf02CseSimuMaster;	
165
			vc_testSystemRole := e_ae;		
166 167 168
			
			// Map
			map(self:mcaPort, system:mcaPort);
169
			map(self:mcaPortIn, system:mcaPortIn);
170 171 172 173 174 175 176 177 178
			map(self:acPort, system:acPort);
			
			activate(a_default());
			activate(a_cse_cf02_ae1());
			
			//Initialze the IUT
							
		} // end f_cf02UpAe1
		
179 180 181
		/**
		 * @desc Ports mapping and default behaviour activation for Config 03
		 */
182
		function f_cf03Up() runs on CseSimu {
183 184
		
			// Variables
185
			var PrimitiveContent v_cSEBaseResource;
186
			vc_config := e_cf03;
187
			vc_testSystemRole := e_cse;		
188
			
189
			// Map
190
			map(self:mcaPortIn, system:mcaPortIn);//TODO To be consistent, we should use mcaPortIn for AE testing
191
			map(self:acPort, system:acPort);
192 193 194
			if(PX_UT_IMPLEMENTED) {
				map(self:utPort, system:utPort);
			}
195
			activate(a_default());
196
			activate(a_ae_cf03());
197 198 199 200 201
			
			//Creation of CSEBase
			
			v_cSEBaseResource := f_cse_generateLocalResource(-, -1, int5);
			vc_cSEBaseIndex := f_setLocalResource(v_cSEBaseResource, int5, -1);
202 203 204 205 206 207
		
			// Connect
					
			//Initialze the IUT
					
		} // end f_cf03Up
208 209 210 211
		
		/**
		 * @desc Ports mapping and default behaviour activation for Config 04
		 */
212
		function f_cf04Up() runs on CseSimu {
213 214

			// Variables
215
			var PrimitiveContent v_cSEBaseResource;
216
			vc_config := e_cf04;
217 218
			vc_testSystemRole := e_cse;	
			
219 220 221
	
			// Map
			map(self:mccPort, system:mccPort);
222
			map(self:mccPortIn, system:mccPortIn);
223 224 225
			map(self:acPort, system:acPort);
			activate(a_default());
			activate(a_cse_cf04());
226 227 228 229 230
			
			//Creation of CSEBase
			
			v_cSEBaseResource := f_cse_generateLocalResource(-, -1, int5);
			vc_cSEBaseIndex := f_setLocalResource(v_cSEBaseResource, int5, -1);
231 232 233

			// Connect
			
234
			//Initialize the IUT
235 236
			
		} // end f_cf03Up
237 238

		/**
239
		 * @desc Ports unmapping
240
		 */
241
		function f_cf01Down() runs on AeSimu {
242
		
243
			unmap(self:mcaPort, system:mcaPort);
244
			unmap(self:acPort, system:acPort);
245 246
			if(vc_auxiliaryAe2Up) {
				vc_ae2.start(f_cf01DownAe2());
247
				vc_ae2.done;
248 249 250 251 252 253 254 255 256 257 258 259 260
			}
		}
		
		/**
		 * @desc Ports unmapping
		 */
		function f_cf01DownAe2() runs on AeSimu {
				
			unmap(self:mcaPort, system:mcaPort);
			unmap(self:acPort, system:acPort);
			unmap(self:mcaPortIn, system:mcaPortIn);
		}
		
261 262 263
		/**
		 * @desc Ports unmapping
		 */
264
		function f_cf02Down() runs on AeSimu {
265
		
266
			unmap(self:mcaPort, system:mcaPort);
267
			unmap(self:acPort, system:acPort);
268 269 270
			if(PX_UT_IMPLEMENTED){
				unmap(self:utPort, system:utPort);
			}
271 272 273
			unmap(vc_cse1:mccPort, system:mccPort);
			unmap(vc_cse1:mccPortIn, system:mccPortIn);
			unmap(vc_cse1:acPort, system:acPort);
274 275 276 277 278 279
		}		
		/**
		 * @desc Ports unmapping
		 */
		function f_cf02DownCseSimuMaster() runs on CseSimu {
				
280
			unmap(self:mccPort, system:mccPort);
281
			unmap(self:mccPortIn, system:mccPortIn);
282
			unmap(self:acPort, system:acPort);
283 284
			unmap(vc_ae1:mcaPort, system:mcaPort);
			unmap(vc_ae1:acPort, system:acPort);
285
		}		
286 287 288
		/**
		 * @desc Ports unmapping for Config 03
		 */
289
		function f_cf03Down() runs on CseSimu {
290
			
291
			unmap(self:mcaPortIn, system:mcaPortIn);
292 293 294
			if(PX_UT_IMPLEMENTED){
				unmap(self:utPort, system:utPort);
			}
295 296
			unmap(self:acPort, system:acPort);
		}
297
		
298 299 300
		/**
		 * @desc Ports unmapping for Config 04
		 */
301
		function f_cf04Down() runs on CseSimu {
302 303
	
			unmap(self:mccPort, system:mccPort);
304
			unmap(self:mccPortIn, system:mccPortIn);
305 306
			unmap(self:acPort, system:acPort);
		}
307 308 309 310 311 312 313 314 315

	}//end group configFunctions
	
	group InfoPortCommunication {
	
		/**
		 * @desc Connection of InfoPort of two components
		 * @param p_tester PTC where InfoPort is to be connected
		 */
316 317 318 319 320
		function f_connectInfoPort(in Tester p_tester) runs on Tester {
			// Connect
			connect(self:infoPort, p_tester:infoPort);		
		} 
	
321 322 323 324
		/**
		 * @desc Disconnection of InfoPort of two components
		 * @param p_tester PTC where InfoPort is to be connected
		 */
325 326 327 328
		function f_disconnectInfoPort(in Tester p_tester) runs on Tester {
			// Disconnect
			disconnect(self:infoPort, p_tester:infoPort);		
		} 
329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349
	
		/**
		 * @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;
				
		}
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 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499
		/**
		 * @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	
500
	
501
	group CseFunctions {
502
	
503
		group PreambleFunctions {
504

505 506 507 508 509 510
			/**
			 * @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 
			 */
511
			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
512
			
513
				return f_cse_createAccessControlPolicyAux(p_acpName, -, p_allowedOperations);
514 515
			
			}
516

517 518
	
			/**
519 520 521
			 * @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
522 523 524
			 * @return Internal AE resource index
			 * @verdict 
			 */
525
			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
526 527 528 529 530
			
				var RequestPrimitive v_request;
				var MsgIn v_response;
								
				v_request := valueof(m_createAeAux(p_accessControlPolicyIDs, p_poaList));
531 532
				
				v_request := f_getCreateRequestPrimitive(int2, v_request, -1);
533
				
534
				mcaPort.send(m_request(v_request));
535 536 537 538 539
				
				tc_ac.start;
				alt {
					[] mcaPort.receive(mw_response(mw_responsePrimitiveOK)) -> value v_response {
						tc_ac.stop;
540
						setverdict(pass,__SCOPE__&":INFO: Application registered successfuly");
541
						if(ischosen(v_response.primitive.responsePrimitive.primitiveContent.aE)) {
542
							
543 544
							f_checkAttributesToBeSaved(int2, v_request, v_response.primitive.responsePrimitive);
							
545
							vc_aeAuxIndex := f_setResource(v_response.primitive.responsePrimitive.primitiveContent, int2);
546
							
547 548
							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)));
549 550 551 552 553 554 555
							} else {
								f_sendAcPrimitive("AE-ID_changed", "0");
							}
						}
					}
					[] mcaPort.receive(mw_response(mw_responsePrimitiveKO)) {
						tc_ac.stop;
556
						setverdict(inconc, __SCOPE__&":INFO: Error while registering application");
557 558 559 560
						stop;
					}
					[] mcaPort.receive {
						tc_ac.stop;
561
						setverdict(inconc, __SCOPE__&":INFO: Unexpected message received");
562 563 564
						stop;
					};
					[] tc_ac.timeout {
565
						setverdict(inconc, __SCOPE__&":INFO: No answer while registering resource");
566 567 568 569
						stop;
					}
				}	
				
570
				f_checkAeSimuStatus();
571
				return vc_aeAuxIndex;
572 573 574 575 576
			}
			
			/**
			 * @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
577
			 * @param p_appId AppID of the AE resource to be created
578 579 580
			 * @return Internal AE resource index
			 * @verdict 
			 */
581
			function f_cse_preamble_registerAeWithId(XSD.ID p_appId, in template (value) AccessControlOperations p_allowedOperations := int63) runs on AeSimu return integer {//c_CRUDNDi
582 583
			
				var RequestPrimitive v_request;
584
				
585
				if(PICS_ACP_SUPPORT){
586
					vc_acpAuxIndex := f_cse_createAccessControlPolicyAux(p_allowedOperations := p_allowedOperations);
587 588
				}
				
589 590 591
				if(vc_acpAuxIndex != -1) {
					vc_resourcesIndexToBeDeleted := {vc_acpAuxIndex};
					v_request := valueof(m_createAe(p_appId, {f_getResourceId(vc_resourcesList[vc_acpAuxIndex].resource)}, -));
592 593 594 595 596 597 598 599 600 601 602
					
					//TODO Test, to be removed
					v_request.to_ := f_getResourceAddress();
					
					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 {
603
					[] mcaPort.receive(mw_response(mw_responsePrimitiveOK)) -> value vc_response {
604
						tc_ac.stop;
605
						setverdict(pass, __SCOPE__&": INFO: Application registered successfuly");
606
						if(ischosen(vc_response.primitive.responsePrimitive.primitiveContent.aE)) {
607
							
608
							vc_aeAuxIndex := f_setResource(vc_response.primitive.responsePrimitive.primitiveContent, int2);
609
							
610 611
							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)));
612 613 614 615 616 617 618 619
							} else {
								f_sendAcPrimitive("AE-ID_changed", "0");
							}	
						}
					}
					[] mcaPort.receive(mw_response(mw_responsePrimitiveKO))
					{
						tc_ac.stop;
620
						setverdict(inconc, __SCOPE__&":INFO: Error while registering application");
621 622 623 624
						stop;
					}
					[] mcaPort.receive {
						tc_ac.stop;
625
						setverdict(inconc, __SCOPE__&":INFO: Unexpected message received");
626 627 628
						stop;
					}
					[] tc_ac.timeout {
629
						setverdict(inconc, __SCOPE__&":INFO: No answer while registering resource");
630 631 632 633
						stop;
					}
				}	
				
634
				f_checkAeSimuStatus();
635
				return vc_aeAuxIndex;
636 637 638
			
			}
			
639 640 641 642 643 644
			/**
			 * @desc Creation of ServiceSubscribedAppRule resource
			 * @param p_allowedAEs Allowed AEs
			 * @return Internal resource index
			 * @verdict 
			 */
645
			function f_cse_preamble_createServiceSubscribedAppRule(in template ListOfM2MID p_allowedAEs := {""}) runs on AeSimu return integer {//c_CRUDNDi
646 647 648 649 650 651 652 653 654
			
				var integer v_serviceSubscribedAppRuleIndex := -1;
	
				v_serviceSubscribedAppRuleIndex := f_cse_createResource(int19, m_createServiceSubscribedAppRule({"None"}, {PX_APP_ID}, valueof(p_allowedAEs)));
				
				return v_serviceSubscribedAppRuleIndex;
			
			}
			
655 656 657 658 659 660
			/**
			 * @desc Creation of SubscribedProfile resource
			 * @param p_allowedAEs Allowed AEs
			 * @return Internal resource index
			 * @verdict 
			 */
661 662 663 664 665 666 667 668 669 670 671 672 673 674 675
			function f_cse_preamble_createServiceSubscribedProfile(in template ListOfM2MID p_allowedAEs := {""}) runs on AeSimu return integer {//c_CRUDNDi
			
				var integer v_serviceSubscribedAppRuleIndex := -1;
				var integer v_serviceSubscribedProfileIndex := -1;
				var template RequestPrimitive m_request := m_createM2mServiceSubscriptionProfileBase;
				
				//TODO Create/Update serviceSubscribedNode //m_request.primitiveContent.m2mServiceSubscriptionProfile.choice.choice_list[0].serviceSubscribedNode := m_contentServiceSubscribedNode;
				v_serviceSubscribedAppRuleIndex := f_cse_createResource(int19, m_createServiceSubscribedAppRule({"None"}, {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;
	
			}
			
676 677 678 679 680 681 682 683
			/**
			 * @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 
			 */
Naum Spaseski's avatar
Naum Spaseski committed
684
			function f_cse_preamble_subscriptionVerification(inout integer p_ae2Index, inout template RequestPrimitive p_createRequestPrimitive,in ResourceType p_resourceType, in ResponseStatusCode p_responseStatusCode := int2000) runs on AeSimu {
685
				if(p_resourceType == int23){
686
					
687
					vc_ae2.start(f_cse_createResource(int2, m_createAe(PX_APP_ID, -, PX_AE2_ID_STEM, c_defaultAE2Name, {f_getAnnouncementTargetPoA("HTTP", PX_AE2_ADDRESS, "")}), -1)); // AE2 is registred
688 689 690 691
					
					f_checkComponentDoneAndGetVerdict(vc_ae2);
					
					p_ae2Index := f_getResource(vc_ae2);
692
					if(ischosen(p_createRequestPrimitive.primitiveContent.subscription)){		//this condition is necessary for Subscription TCs where notification URI is set in m_createSubscriptionAdvanced
693
						p_createRequestPrimitive.primitiveContent.subscription.notificationURI := {f_getResourceAddress(p_ae2Index)};
694
					}
695
					vc_ae2.start(f_cse_notifyProcedure_subscriptionVerificationHandler(p_responseStatusCode));
696
				}
697
			}
698 699 700 701 702 703
		
		}//end group preambleFunctions
		
		group PostambleFunctions {
	
			/**
704
			 * @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
705 706
			 * @verdict 
			 */
707
			function f_cse_postamble_deleteResources() runs on AeSimu {
708 709 710 711 712 713
				var integer i;
				var XSD.ID v_resourceAddress;
				var RequestPrimitive v_request;
				
				if (PX_RUN_POSTAMBLE) {
					
714 715 716 717
					if(vc_auxiliaryAe2Up) {
						f_cse_postamble_aeSimu(vc_ae2);
					}
					
718
					for(i := lengthof(vc_resourcesIndexToBeDeleted) -1; i >=0; i := i - 1) {
719
						
720
						v_resourceAddress := f_getResourceAddress(vc_resourcesIndexToBeDeleted[i]); 
721
						
722
						v_request := valueof(m_delete(v_resourceAddress, f_getOriginator(vc_resourcesIndexToBeDeleted[i])));
723
						
724
						v_request.from_ := f_getOriginator(vc_resourcesIndexToBeDeleted[i]);
725

726 727 728 729 730 731
						mcaPort.send(m_request(v_request));
						
						tc_ac.start;
						alt {
							[] mcaPort.receive(mw_response(mw_responsePrimitiveOK)) {
								tc_ac.stop;
732
								log(__SCOPE__&" INFO: Resource " & v_request.to_ & " deleted");
733 734 735 736 737 738 739 740 741
							}
							[] mcaPort.receive(mw_response(mw_responsePrimitiveKO)) {
								tc_ac.stop;
								log(__SCOPE__&" INFO: Error while deleting resource " & v_request.to_);
							}
							[] tc_ac.timeout {
								log(__SCOPE__&" INFO: No answer while deleting resource " & v_request.to_);
							}	
						}	
742
						
743 744
					}
				}
745 746 747 748
						
			}
			
			/**
749
			 * @desc Calls to postamble for AeSimu components (i.e. AE2)
750 751 752 753 754 755
			 * @verdict 
			 */
			function f_cse_postamble_aeSimu(in AeSimu p_ae) runs on AeSimu {
				if(p_ae.running) {
					p_ae.stop;
				}
756 757
				p_ae.start(f_cse_postamble_deleteResources());
				p_ae.done;
758 759
			}
			
760 761 762 763 764 765 766 767 768 769
			/**
			 * @desc Calls to postamble for AeSimu component (i.e. AE1) on CseSimu 
			 * @verdict 
			 */
			function f_cse_postamble_ae1() runs on CseSimu {
				if(vc_ae1.running) {
					vc_ae1.stop;
				}
				vc_ae1.start(f_cse_postamble_deleteResources());
				vc_ae1.done;
770 771
			}
			
772 773 774 775
			/**
			 * @desc Deletion of all resources created during the test case execution. IUT gets clean and ready for next execution
			 * @verdict 
			 */
776
			function f_cse_postamble_deleteResourcesCSE() runs on CseSimu {
777 778 779
				var integer i;
				var XSD.ID v_resourceAddress;
				var RequestPrimitive v_request;
780
	
781
				if (PX_RUN_POSTAMBLE) {
782 783 784 785
					
					if(vc_config == e_cf02CseSimuMaster) {
						f_cse_postamble_ae1();
					};
786
		
787
					for(i := lengthof(vc_resourcesIndexToBeDeleted) -1; i >=0; i := i - 1) {
788
			
789
						v_resourceAddress := f_getResourceAddress(vc_resourcesIndexToBeDeleted[i]); 
790
			
791 792 793
						v_request := valueof(m_delete(v_resourceAddress, f_getOriginator(vc_resourcesIndexToBeDeleted[i],false)));

						mccPort.send(m_request(v_request));
794
			
795 796 797 798 799 800
						tc_ac.start;
						alt {
							[] mccPort.receive(mw_response(mw_responsePrimitiveOK)) {
								tc_ac.stop;
								log(__SCOPE__&" INFO: Resource " & v_request.to_ & " deleted");
							}
801 802 803 804 805 806 807 808
							[] 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_);
							}	
						}	
809
			
810
					}
811
				}
812
			
813
			}			
814 815 816
			
		}//end group postambleFunctions
		
817 818
		group AeSimuFunctions {
			
819 820 821
			/**
			 * @desc Creation of a resource
			 * @param p_resourceType Resource type of the resource to be created
822
			 * @param p_requestPrimitive CREATE request primitive for the resource to be created
823 824 825 826
			 * @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 
			 */
827
			function f_cse_createResource(in ResourceType p_resourceType, template RequestPrimitive p_requestPrimitive := m_create, integer p_parentIndex := -1) runs on AeSimu return integer {
828 829 830 831 832 833 834 835 836
			
				var RequestPrimitive v_request;
				var integer v_resourceIndex := -1;
				
				v_request := f_getCreateRequestPrimitive(p_resourceType, p_requestPrimitive, p_parentIndex);
			
				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(enum2int(p_resourceType)) & " created successfuly");
840 841 842 843 844
						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;
						}
845 846 847
					}
					[] mcaPort.receive(mw_response(mw_responsePrimitiveKO)) {
						tc_ac.stop;
848
						setverdict(inconc, __SCOPE__&":INFO: Error while creating resource type " & int2str(enum2int(p_resourceType)));
849 850 851
					}
					[] mcaPort.receive {
						tc_ac.stop;
852
						setverdict(inconc, __SCOPE__&":INFO: Unexpected message received");
853 854
					}
					[] tc_ac.timeout {
855
						setverdict(inconc, __SCOPE__&":INFO: No answer while creating resource type " & int2str(enum2int(p_resourceType)));
856 857 858
					}
				}	
				
859
				f_checkAeSimuStatus();
860
				
861 862 863
				return v_resourceIndex;
		
			}
864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894
			
			/**
			 * @desc Message exchange for the update of an announced resource
			 * @param p_requestPrimitive UPDATE request primitive to be used
			 * @verdict 
			 */
			function f_cse_updateAnnouncedResource(in RequestPrimitive p_requestPrimitive) runs on CseSimu {

				mccPort.send(m_request(p_requestPrimitive));
				tc_ac.start;
				alt {
					[] mccPort.receive(mw_response(mw_responsePrimitiveOK)) -> value vc_response {
						tc_ac.stop;
						setverdict(pass, __SCOPE__&":INFO: Attribute of announced resource updated successfuly");
					}
					[] mccPort.receive(mw_response(mw_responsePrimitiveKO)) -> value vc_response {
						tc_ac.stop;
						setverdict(inconc, __SCOPE__&":INFO: Error while updating announced resource");
					}
					[] mccPort.receive{
						tc_ac.stop;
						setverdict(inconc, __SCOPE__&":INFO: Unexpected message received");
					}
					[] tc_ac.timeout {
						setverdict(inconc, __SCOPE__&":INFO: No answer while updating announced resource");
					}
				}	
				
				f_checkCseSimuStatus();
				
			}// end f_cse_updateAnnouncedResource
895 896 897 898 899 900 901 902
		
			/**
			 * @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 
			 */
903
			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;
904 905 906 907
				var integer v_acpAuxIndex := -1;
				
				v_request := valueof(m_createAcpAux(p_acpName := p_acpName, p_allowedOperations := p_allowedOperations));
				
908
				v_request := f_getCreateRequestPrimitive(int1, v_request, -1);
909
								
910 911 912
				mcaPort.send(m_request(v_request));
				tc_ac.start;
				alt {
913
					[] mcaPort.receive(mw_response(mw_responsePrimitiveOK)) -> value vc_response {
914
						tc_ac.stop;
915
						setverdict(pass, __SCOPE__&":INFO: Resource type " & int2str(1) & " created successfuly");
916 917
						f_checkAttributesToBeSaved(int1, v_request, vc_response.primitive.responsePrimitive);
						v_acpAuxIndex := f_setResource(vc_response.primitive.responsePrimitive.primitiveContent, int1);
918
						vc_acpAuxIndex := v_acpAuxIndex;
919
					}
920 921
					[] mcaPort.receive(mw_response(mw_responsePrimitiveKO)) {
						tc_ac.stop;
922
						setverdict(inconc, __SCOPE__&":INFO: Error while creating resource type " & int2str(1));
923 924 925
					}
					[] mcaPort.receive {
						tc_ac.stop;
926
						setverdict(inconc, __SCOPE__&":INFO: Unexpected message received");
927 928
					}
					[] tc_ac.timeout {
929
						setverdict(inconc, __SCOPE__&":INFO: No answer while creating resource type " & int2str(1));
930 931
					}
				}	
932
				
933
				f_checkAeSimuStatus();
934 935 936 937
			
				return v_acpAuxIndex;
	
			}
938
							
939
			/**
940 941
			 * @desc Message exchange for the update of a resource
			 * @param p_requestPrimitive UPDATE request primitive to be used
942 943
			 * @verdict 
			 */
944
			function f_cse_updateResource(in RequestPrimitive p_requestPrimitive) runs on AeSimu {
945 946 947 948

				mcaPort.send(m_request(p_requestPrimitive));
				tc_ac.start;
				alt {
949
					[] mcaPort.receive(mw_response(mw_responsePrimitiveOK)) -> value vc_response {
950
						tc_ac.stop;
951
						setverdict(pass, __SCOPE__&":INFO: Attribute of resource updated successfuly");
952
					}
953
					[] mcaPort.receive(mw_response(mw_responsePrimitiveKO)) -> value vc_response {
954
						tc_ac.stop;
955
						setverdict(inconc, __SCOPE__&":INFO: Error while updating resource");
956 957 958
					}
					[] mcaPort.receive{
						tc_ac.stop;
959
						setverdict(inconc, __SCOPE__&":INFO: Unexpected message received");
960 961
					}
					[] tc_ac.timeout {
962
						setverdict(inconc, __SCOPE__&":INFO: No answer while updating resource");
963 964
					}
				}	
965
				
966
				f_checkAeSimuStatus();
967
				
968
			}// end f_cse_updateResource
969
			
970
			/**
971 972 973
			 * @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
974 975
			 * @verdict 
			 */
976
			function f_cse_retrieveResource(integer p_resourceIndex) runs on AeSimu return PrimitiveContent{
977

978
				mcaPort.send(m_request(m_retrieve(f_getResourceAddress(p_resourceIndex), f_getOriginator(p_resourceIndex))));
979 980
				tc_ac.start;
				alt {
981
					[] mcaPort.receive(mw_response(mw_responsePrimitiveOK)) -> value vc_response {
982 983 984
						tc_ac.stop;
						setverdict(pass, __SCOPE__&":INFO: Resource retrieved successfuly");
					}
985
					[] mcaPort.receive(mw_response(mw_responsePrimitiveKO)) -> value vc_response {